cancel
Showing results for 
Search instead for 
Did you mean: 

Can you share some NFC WiFi OOB demo code for ST25R3916 (and STM32F429) please.

toshko
Associate II

I downloaded your last ST25R39xx library examples (about Bluetooth, RW ...); I can write NFC URI tag in Card Emulation mode (without some NDEF_NOT_DETECTED messages during the transfer), but not NFC WiFi message . So I succeed to write tag in CE mode to my Android, but it is empty. I can not initialized it properly for now

1 ACCEPTED SOLUTION

Accepted Solutions
Jasper Preston
ST Employee

Hi Toshko,

To use Wifi pairing, you only need to replace the function demoEncodeBluetoothRecord() with your own, encoding a Wifi record, as shown in this example:

ReturnCode demoEncodeWifiRecord(uint8_t *buffer, uint32_t length)
{
    ndefRecord record;
    ndefType ndefWifi;
    ReturnCode err;
 
    if (buffer == NULL)
    {
        return ERR_PARAM;
    }
 
    uint8_t ssid[] = { 0x01, 0x02, 0x03, 0x04 };
    ndefConstBuffer bufNetworkSSID = { ssid, sizeof(ssid) };
    uint8_t  key[] = { 0x05, 0x06, 0x07, 0x08 };
    ndefConstBuffer bufNetworkKey  = { key, sizeof(key) };
 
    ndefTypeWifi wifiConfig = {
        .bufNetworkSSID = bufNetworkSSID,
        .bufNetworkKey  = bufNetworkKey,
        .authentication = NDEF_WIFI_AUTHENTICATION_WPAPSK,
        .encryption     = NDEF_WIFI_ENCRYPTION_TKIP
    };
 
    err = ndefWifiInit(&ndefWifi, &wifiConfig);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    err = ndefTypeToRecord(&ndefWifi, &record);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    err = ndefRecordDump(&record, true);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    /* Encode the record starting after the first two bytes that are saved
       to store the NDEF file length */
    ndefBuffer bufRecord = { &buffer[2], length - 2 };
    err = ndefRecordEncode(&record, &bufRecord);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    /* Store the NDEF file length on the two first bytes */
    buffer[0] = bufRecord.length >> 8;
    buffer[1] = bufRecord.length & 0xFF;
 
    return err;
}

Let me know if you face any issue.

Best regards,

Jasper

View solution in original post

9 REPLIES 9
Brian TIDAL
ST Employee

Hi

can you confirm my understanding of your use case:

ST25R3916 is used as a Reader/Writer and the NDEF read/write demo is running on it.

Your android phone is running an application that sets the phone in Card Emulation mode and this card emulation supports the NDEF application.

The ST25R3916 is used to write an NDEF (Wifi oob) to the phone being in CE mode.

If my understanding is correct, which Android app do you use?

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
toshko
Associate II

Hi Brian,

Thanks for the answer.

All about your understanding is as you described.

'NFC Tools Pro' application reading empty tag at my Android (Xaomi 9 NFC).

I am not wonder that The tag is empty because most probably incorrect initialization.

I didn't succeed to find NFC WiFi example and I started to integrate my old URI code with the example code about 'NDEF - R/W' and 'Bluetooth-pairing' projects from STSW-ST25R016.

I can't initialize needed data before demoCycle(), because initialization scenario is probably different comparing to my old Card_Emulation_URI_tag.

Because I haven't WiFi demo code I attempted adapt your Bluetooth_pairing like this:

static uint8_t bluetoothNdef[80];   /* Bluetooth NDEF file */

const uint8_t *demoNdefFile = bluetoothNdef; /* Overwrite weak demoNdefFile pointer */

uint32_t demoNdefFileLen = sizeof(bluetoothNdef);

Also I continue with next rows:

    sWifiTokenInfo wps_oob = {

                                    .NetworkSSID       = "my_MAC_SSID",

                                     .AuthenticationType = NDEF_WIFI_AUTHENTICATION_NONE,

                                      .EncryptionType    = NDEF_WIFI_ENCRYPTION_NONE,

                                     .NetworkKey        = "01234567"

           };

     NDEF_WriteWifiToken(&wps_oob);

Here after all above I think I must continue, but I have information how.

After initialization I intend to use your scenario about Card_Emulation_URI :

- demoCycle();

                 case RFAL_NFC_POLL_TYPE_NFCA:

                  case RFAL_NFC_POLL_TYPE_NFCF:

  • demoCE( nfcDevice );
  • demoTransceiveBlocking(...)

So, what I need is how to organize properly scenario to write NFC_WiFi_Pairing message on my Android.

Brian TIDAL
ST Employee

Hi

the Bluetooth-pairing demo is a ST25R3916 Card Emulation demo. In this demo, the ST25R3916 emulates a tag having a Bluetooth paring NDEF message. This message can be then read by any reader.

If I have well understood, you would like to replace the Bluetooth paring NDEF message by a WIFI OOB message inside the ST25R3916 car Emulation demo. For this, you just need to replace the demoEncodeBluetoothRecord by you own encoding for the Wifi record. Note that the buffer follows the structure of a T4T NDEF file (i.e. byte 0 and byte 1 encode the NDEF Length and remaining bytes encode the NDEF message). Make sure the buffer will be large enough to sore the encoded NDEF.

The rest of the demo should not be changed. Feel free to dump the encoded buffer and share with me so that I can check the format/content is correct.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
toshko
Associate II

Thank you Brian.

I will follow the instructions.

Have a nice day.

Best Regards,

Toshko

toshko
Associate II

Hi Brian,

I have ST25R3916 and STM32F429 only and if I start processing the demo for STM32L476 that you posted it is much more time consuming for me. For me it is much more productive if I rework my working project for URL NFC Tag for the purpose of WiFi pairing I started this way. But I don't have an encoding function like Bluetooth_project- (demoEncodeBluetoothRecord). For now, I can't find any demo for WiFi pairing or any document for WiFi encoding. You know I want to pass the 'wps_oob' structure: .NetworkSSID = "my_MAC_SSID", .AuthenticationType = NDEF_WIFI_AUTHENTICATION_NONE, .EncryptionType = NDEF_WIFI_ENCRYPTION_NONE, .NetworkKey = "01234567" Here's the source.

Thank you for your support.

Best Regards,

T

Jasper Preston
ST Employee

Hi Toshko,

To use Wifi pairing, you only need to replace the function demoEncodeBluetoothRecord() with your own, encoding a Wifi record, as shown in this example:

ReturnCode demoEncodeWifiRecord(uint8_t *buffer, uint32_t length)
{
    ndefRecord record;
    ndefType ndefWifi;
    ReturnCode err;
 
    if (buffer == NULL)
    {
        return ERR_PARAM;
    }
 
    uint8_t ssid[] = { 0x01, 0x02, 0x03, 0x04 };
    ndefConstBuffer bufNetworkSSID = { ssid, sizeof(ssid) };
    uint8_t  key[] = { 0x05, 0x06, 0x07, 0x08 };
    ndefConstBuffer bufNetworkKey  = { key, sizeof(key) };
 
    ndefTypeWifi wifiConfig = {
        .bufNetworkSSID = bufNetworkSSID,
        .bufNetworkKey  = bufNetworkKey,
        .authentication = NDEF_WIFI_AUTHENTICATION_WPAPSK,
        .encryption     = NDEF_WIFI_ENCRYPTION_TKIP
    };
 
    err = ndefWifiInit(&ndefWifi, &wifiConfig);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    err = ndefTypeToRecord(&ndefWifi, &record);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    err = ndefRecordDump(&record, true);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    /* Encode the record starting after the first two bytes that are saved
       to store the NDEF file length */
    ndefBuffer bufRecord = { &buffer[2], length - 2 };
    err = ndefRecordEncode(&record, &bufRecord);
    if (err != ERR_NONE)
    {
        return err;
    }
 
    /* Store the NDEF file length on the two first bytes */
    buffer[0] = bufRecord.length >> 8;
    buffer[1] = bufRecord.length & 0xFF;
 
    return err;
}

Let me know if you face any issue.

Best regards,

Jasper

toshko
Associate II

Thank you Jasper.

I will.

Have a nice weekend.

T.

toshko
Associate II

Hi Brian,

Hi Jasper,

Now everything about my NFC emulated tags is OK.

From a few days I can write successfully NFC URI, Bluetooth pairing and WiFi OOB tags in Card Emulation mode.

Thank you and have a nice weekend.

Best Regards,

Toshko

toshko
Associate II

It was an exciting tasks...