NFC testing

NFC algorithm

NFC, like RFID, has an initiator and target in the exchange, but the new technology allows for much more than just exchanging an identifier and reading or writing target information. The most significant difference between the two technologies is that NFC targets are often programmable devices such as smartphones. This means that it is possible to exchange not only static data, but also generate a response to the information requested by the initiator each time.

NFC devices have two interaction modes. If the initiator emits radio frequency waves, and the target receives power at the expense of the initiator, then this mode of interaction is called passive. In active mode, the initiator and target have their own power supplies and are independent of each other. These modes are the same as RFID modes.

NFC devices also have three ways of working. They can work in the mode of reading information from the target or writing to it. They can emulate cards by acting like RFID tags when they are in the field of another NFC or RFID device. Or they can work in peer-to-peer (P2P) mode, in which they exchange data in both directions at once.

The first main difference between NFC and RFID is the peer-to-peer interaction method, which is implemented using GOST R ISO / IEC 18092. P2P data exchange is implemented by two protocols – the logical link control protocol (LLCP) and a simple NDEF data exchange protocol (SNEP – simple NDEF exchange format).

How to find out if your phone supports NFC in quick settings

What is NFC in a smartphone (Near field communication in English sounds like “near contactless communication”) – this technology provides wireless data transmission in a short range. Simply put, NFC allows devices to exchange data provided they are within a radius of no more than 10 cm from each other. Near field communication (NFC) technology was introduced in 2004.

что такое nfc в смартфоне
Energy function

But the dawn of NFC technology falls on 2017-218, as it is now actively used when paying in contactless mode. Contactless payment with a smartphone is very convenient and fast – it saves a lot of time.

You can call quick settings by swiping from top to bottom. A menu pops up with icons to configure. If your Android smartphone has an NFC module, there will be a corresponding icon in the quick settings.

NFC architecture

There are several layers in the NFC architecture. The lowest of them is the physical one, which is implemented by the CPU and other hardware complex through which the interaction takes place. In the middle is the packet data and the transport layer, then the layer data format, and finally the software.

At the physical layer, NFC works according to the algorithm described in GOST for RFID (GOST R ISO / IEC 14443-2-2014), which refers to low-power radio signals with a frequency of 13.56 MHz. Then comes the level that describes the breakdown of the data stream into frames (GOST R ISO / IEC 14443-3-2014). Any radio controllers that are used in a phone, tablet, or connected to a computer or microcontroller are separate hardware components.

NFC testing

They communicate with the main processor through one or more standard serial protocols between devices: Universal Asynchronous Transceiver (UART), Serial Peripheral Interface (SPI), Serial Data Bus for Integrated Circuit Communications (I2C), or Universal Serial Bus (USB) .

Above this are several RFID command protocols based on two specifications. N FC tag reading and writing is based on the original RFID GOST R ISO/IEC 14443A. The Philips/NXP Semiconductors Mifare Classic and Mifare Ultralight and NXP DESFire protocols are compliant with GOST R ISO/IEC 14443A. P2P NFC data exchange is based on GOST R ISO/IEC 18092.

They are depicted in the figure above on a par with other control protocols, since they use the same standard.

Which Android smartphones support NFC

что такое nfc в смартфоне
Energy function

To find out if your smartphone supports NFC, you need to look in the settings of your Android device.

  1. Open the Settings app on your Android smartphone.
  2. Next, go to the “Connected Devices” section.
  3. Then check the entire list of items in this section if there is an NFC function, then your device supports NFC technology.
  4. Drag the slider to NFC active mode.
поддерживает ли nfc
how to find out if the phone supports nfc

If after the above steps you did not find an item with NFC, it means that this technology is not in your smartphone. But you can still check its presence in another way.

You can find out if your smartphone supports NFC in the official specifications about this device. This can be done both on the official website and using the additional information that is included with the box of your smartphone.

Below is a list of Android smartphones that support NFC:

  • Alcatel Pop S7 7045Y
  • Alcatel U5 HD and A7
  • Xiaomi Mi6
  • Xiaomi Mi5S
  • Xiaomi Mi Note 3
  • Xiaomi Mi Mix 2
  • Huawei Honor 9
  • Huawei Honor 6X
  • Huawei Honor 5C
  • Huawei P10 Lite
  • Huawei Nova 2
  • LG G6
  • LG V30
  • LG Q6 and Q6
  • LG X Venture
  • Lenovo P2
  • Samsung Galaxy Note 8
  • Samsung Galaxy S8
  • Samsung Galaxy J5 (2016)
  • Samsung Galaxy J7 (2017)
  • Samsung Galaxy A5 2017
  • Sony Xperia L1
  • Sony Xperia E5
  • Sony Xperia XA1
  • Nokia 3
  • Nokia 5
  • Nokia 6
  • Nokia 8
  • Asus ZenFone 4
  • Asus ZenFone 4 Pro.
  • Asus ZenFone 4AR
  • Blackview BV6000S
  • Blackview BV8000 Pro
  • Wileyfox Swift 2X
  • HTC Desire 530
  • HTC U Ultra
  • HTC U11 and U11 Plus
  • Google Pixel 2/2XL.
  • OnePlus 5/5T.
  • ZTE Nubia Z17 and Z17 mini
  • Moto G5s

Of course, this list cannot be complete, at the time when you are watching it, the number of models may have already increased, so if you know an Android smartphone with NFC support, write in the comments.

Rapid testing is done after the completion of a development iteration if the build does not go to release.

To begin with, smoke tests are carried out to understand whether it makes sense to test the build.

Then all completed tasks and fixed bugs for iteration from Jira are taken and the correspondence of the result to the description of the task is meticulously checked. If the task included new interface elements, it is sent to designers for verification with layouts.

Incorrectly completed tasks are reopened. Bugs are submitted to Jira. Logs from a smartphone must be attached to non-UI bugs. To UI bugs screenshots with notes what is wrong.

NFC testing

After that, functional tests of this iteration are performed. If bugs are found that are not covered by test cases, a new test case is created.

Monkey tests are launched for android applications.

 adb shell monkey -p ru.stream.droid --throttle 50 --pct-syskeys 0 --pct-ap
pswitch 0 -v 5000 

At the end of testing, the “bug testing passed” checkbox is ticked in the build server (yes, the name of the checkbox is not very correct :).

NDEF structure

NDEF contains information about the byte representation of messages that can contain multiple entries. Each entry has a header that contains metadata (type, length, etc.) and information to send. If we return to the analogy with the paragraph, then the paragraph is formed from sentences related to the same topic, and in NDEF messages – it’s good when all entries relate to the same topic.

NDEF messages are mostly short, each exchange consists of one message, each label also contains one message. Since the exchange of NFC data occurs when one device is touched by another or by a label, it will be inconvenient to transmit the text of an entire book in one message, so the length of an NDEF message is comparable to the length of a paragraph, but not the entire book.

An NDEF record contains information to forward and metadata on how to interpret this information. Each entry can be of a different type, which is announced in the title of that entry. The header also describes what place the record occupies in the message, after the header information follows. The figure below shows complete information about the location of bits and bytes of information in the NDEF record.

How long can an NDEF message be?

The space for information in an NDEF record is limited to 2^32-1 bytes, but you can chain records within a message to send larger information. In theory, there are no restrictions on NDEF messages, but in practice, the message size is limited by the capabilities of the devices or tags involved in the exchange of information.

If only devices are involved in the exchange, then the length of the message will be limited by the computing power of the weakest of the devices, but it is worth considering that the devices will have to be kept nearby for a long time to send all the data. When the smartphone and the card interact, the length of the message will be limited by the memory size of the card.

In general, data exchange via NFC is quite fast. The person brings the mobile device to the tag, there is a brief exchange of information, and the person moves on. This technology was not designed for long exchanges of information, because the devices literally have to be a couple of centimeters apart.

NFC testing

In order to transmit a large amount of information, the devices will have to be kept next to each other for a long time, this may be inconvenient. If you need a long interaction between devices, then you can use NFC to quickly exchange data about the capabilities of devices and then turn on one of the more suitable data transfer methods (Bluetooth, Wi-Fi, etc.).

Reading NDEF message

When an Android phone reads an NFC tag, it first processes and recognizes it, and then transfers the data about it to the appropriate application for the subsequent creation of an intent. If more than one application can work with NFC, the application selection menu will appear. The recognition system is defined by three intents, which are listed in order of importance from highest to lowest:

  1. ACTION_NDEF_DISCOVERED: This intent is used to start an activity if the label contains an NDEF message. It has the highest priority and the system will run it first.
  2. ACTION_TECH_DISCOVERED: If no activity is registered for an ACTION_NDEF_DISCOVERED intent, then the recognition system will try to launch an application with that intent. Also, this intent will be fired immediately if the found NDEF message does not match the MIME type or URI, or the label does not contain a message at all.
  3. ACTION_TAG_DISCOVERED: This intent will fire if the previous two intents failed.

In general, the recognition system works as shown in the figure below.

When possible, the ACTION_NDEF_DISCOVERED intent is fired because it is the most specific of the three. Moreover, with its help it will be possible to launch your application.

If an activity is launched due to an NFC intent, then you can get information from the scanned NFC tag from this intent. Intent may contain the following additional fields (depending on the type of scanned tag):

  • EXTRA_TAG (mandatory): Tag object describing the scanned tag.
  • EXTRA_NDEF_MESSAGES (optional): Array of NDEF messages calculated from the label. This extra field is specific to the ACTION_NDEF_DISCOVERED intent only.
  • EXTRA_ID (optional): Low-level label ID.

NFC testing

Below is an example that checks the intent ACTION_NDEF_DISCOVERED and gets NDEF messages from the extra field.

Kotlin

 override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) . if (NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action) { intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)?also { rawMessages -{amp}gt; val messages: List = rawMessages.map { it as NdefMessage } // Processing the array of messages. . } }
} 
 @Override
protected void onNewIntent(Intent intent) { super.onNewIntent(intent); . if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) { Parcelable[] rawMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMessages != null) { NdefMessage[] messages = new NdefMessage[rawMessages.length]; for (int i = 0; i {amp}lt; rawMessages.length; i ) { messages[i] = (NdefMessage) rawMessages[i]; } // Processing the array of messages. . } }
} 

Kotlin

val tag: Tag = intent.getParcelableExtra(NfcAdapter. EXTRA_TAG)

Tag tag = intent.getParcelableExtra(NfcAdapter. EXTRA_TAG);

Creating Common NDEF Records

There are several methods for creating an NDEF entry: createUri(), createExternal() and createMime(). It is better to use one of them in order to avoid errors that may occur when creating a record manually. All examples below should be sent as the first message when writing a tag, or by pairing with another device.

Kotlin

Using NFC

NFC testing

There are many ways to use NFC:

  • Card emulation mode allows you to use this technology for contactless payments, such as Google Wallet, or to pay or receive tickets on public transport.
  • There are several mobile applications that allow you to save the settings for the mobile device on the tags and later use them to quickly change any settings of the mobile device (switch to vibrate mode, turn on or turn off Wi-Fi on the mobile device).
  • NFC-enabled devices are gradually appearing on the market – stereo systems, TVs that allow you to pair with a phone or tablet for remote control.
  • NFC is used in the healthcare system to store patient ID and personal records.
  • In the field of inventory management, NDEF records can be used to store information about the place of departure of goods, their passage through various intermediate points, and the like.

In fact, there are a lot of scenarios for using tags. For example, I use tags to store passwords and home automation, someone to automatically unlock a smartphone and automatically launch a navigator in a car. Tags can be glued on a table, on a laptop, on a key chain, inside a book, on a business card, or sewn under clothes. Therefore, the range of their application is huge, and in the end everything depends only on your imagination.

Conclusion

NFC technology adds promising functionality to RFID technology. The most significant innovation is the NFC Data Interchange Format (NDEF), which provides the ability to format regular data into one of four NFC tag technologies. N DEF can be used both for data exchange between a device and a tag, and for exchange between devices. This makes NFC suitable not only as a method of identification, but also as a means of exchanging short blocks of data.

https://www.youtube.com/watch?v=NNhIXoqt3P0

For more information about NFC or NDEF, see Tom Igoe, Don Coleman, and Brian Jepson Beginning NFC. Near Field Communication with Arduino, Android, and PhoneGap.