Changing device's advertising name

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing device's advertising name

Jump to solution
6,745 Views
tero_nikula
Contributor I

Hi,

I am using custom hardware with MCUXpresso SDK 2.2 for MKW41Z512xxx4. The hardware is included by Rigado R41Z chip.

I'm trying to change device's Bluetooth advertising name in my code. Later I'm going to need this because iOS can't show MAC address so I want to add shortened MAC to device name so I can separate the one I want to use from others.

My problem is that I'm not able to get enough long name for that advertising name (gAData). It seems that 8 is the maximum length that is working. When I try 9 or more for length, the device is not advertising itself.

I have used these links as help:

How to update advScanStruct after initialization? 

Hexiwear_v2/app_config.c at master · ErichStyger/Hexiwear_v2 · GitHub 

Hexiwear_v2/app.h at master · ErichStyger/Hexiwear_v2 · GitHub 

Hexiwear_v2/app.c at master · ErichStyger/Hexiwear_v2 · GitHub 

Here is my code:


// app_config.c

/* Scanning and Advertising Data */

uint8_t gAData[8] = "12345678";                    // working
//uint8_t gAData[12] = "123456789012";        // not working

static const uint8_t adData0[1] =  { (gapAdTypeFlags_t)(gLeGeneralDiscoverableMode_c | gBrEdrNotSupported_c) };

const gapAdStructure_t advScanStruct[3] = {
  {
    .length = NumberOfElements(adData0) + 1,
    .adType = gAdFlags_c,
    .aData = (uint8_t *)adData0
  },  
  {
    .length = NumberOfElements(uuid_service_xxxx) + 1,
    .adType = gAdComplete128bitServiceList_c,
    .aData = (uint8_t *)uuid_service_xxxx
  },  
  {
    .length = 9,                                                         // working
    //.length = 13,                                                     // not working
    .adType = gAdShortenedLocalName_c,
    .aData = (uint8_t *)&gAData
  }  
};

// app.h


/* Public memory declarations */

extern gapAdvertisingData_t         gAppAdvertisingData;
extern gapScanResponseData_t        gAppScanRspData;
extern gapAdvertisingParameters_t   gAdvParams;
extern uint8_t                      gAData[];
extern const gapAdStructure_t       advScanStruct[];

// app.c

/*! *********************************************************************************
* \brief        Configures BLE Stack after initialization. Usually used for
*               configuring advertising, scanning, white list, services, et al.
********************************************************************************** */

static void BleApp_Config()
{
    ...

    /* Set device name */
    gAppAdvertisingData.cNumAdStructures = 3;
    gAppAdvertisingData.aAdStructures = (void *)advScanStruct;

    memcpy(&gAData, "TEST1234", 9);                     // working
    //memcpy(&gAData, "TEST12345678", 13);         // not working

    Gap_SetAdvertisingData(&gAppAdvertisingData, &gAppScanRspData);

    ...
}

So my question is how to get that longer name working?

That would be great if anyone could help me with this!

Thanks,

Tero

Labels (1)
1 Solution
6,445 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Tero, I hope you're doing well!

 

Did you try changing the "gBleSig_GapDeviceName_d" value in the gatt_db.h header file? There is a characteristic with that name that determines the device name. This value also needs another number value, which, in this case, is the full length of the name itself.

 pastedImage_1.png

 

Could you try changing that?

 

Please let me know of your results.

 

Best regards,

Sebastian

View solution in original post

5 Replies
6,446 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Tero, I hope you're doing well!

 

Did you try changing the "gBleSig_GapDeviceName_d" value in the gatt_db.h header file? There is a characteristic with that name that determines the device name. This value also needs another number value, which, in this case, is the full length of the name itself.

 pastedImage_1.png

 

Could you try changing that?

 

Please let me know of your results.

 

Best regards,

Sebastian

6,445 Views
tero_nikula
Contributor I

Hi Sebastian,

Thanks for your reply.

I changed that gBleSig_GapDeviceName_d value and that actually solved my problem. I read our iOS app code and it turned out I don't have to change the advertising name for the device, just change gBleSig_GapDeviceName_d for example "TEST123456". That's helping my case so I can now separate the specific device from others. I did this:

/** gatt_db.h **/

PRIMARY_SERVICE(service_gap, gBleSig_GenericAccessProfile_d)
    CHARACTERISTIC(char_device_name, gBleSig_GapDeviceName_d, (gGattCharPropRead_c | gGattCharPropWrite_c) )
            VALUE(value_device_name, gBleSig_GapDeviceName_d, (gPermissionFlagReadable_c | gPermissionFlagWritable_c), 10, "TEST123456")

/** app_config.h **/

const gapAdStructure_t advScanStruct[3] = {

...

  {
    .length = 6,
    .adType = gAdShortenedLocalName_c,
    .aData = (uint8_t *)"TEST1"
  }
};

When scanning devices with nRF Connect in Android and iOS, it's showing with advertising name "TEST1" like it should. And when connected I can see the device name on GAP services with the name "TEST123456". And I can also see that "TEST123456" in our iOS app.

Your suggestion didn't actually solve the advertising name change problem but it solved my problem so I want to thank you Sebastian! :smileyhappy:

Regards,
Tero

0 Kudos
Reply
6,445 Views
Xiang_Li
NXP Employee
NXP Employee

To better answer this question:

Why 8 bytes?

Initially BLE standard defines 1 advertising packet or 1 scan response packet can carry max 31 bytes payload. (Now it has increased to 255.)

Within the 31-byte, the user can place multiple so called "AD Structure". 1 AD structure is organized as 1 length byte, 1 AD type byte, and N AD data bytes. As you might realized, 1 advScanStruct in our demo code is exactly this thing.

In most demos, there is advScanStruct[3]. The first element is AD Flags (length 1 + type 1 + data 1 = 3 bytes).

The second is a 128-bit UUID to indicate what service is supported. (length 1 + type 1 + data 16 = 18 bytes.)

This left 31-18-3 = 10 bytes for the third AD struct, which could be device name if you will. Or technically it could something else. See this link for other possibilities:

https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/ 

So the storage for device name is only 10 - 1 length - 1 type = 8 bytes

What if 9 bytes or more?

If we want a device name more than 8 bytes, we could remove the 128-bit UUID advScanStruct to free up 18 bytes space, but then some phones cannot know what service your BLE device can offer.

Alternatively is to put the device name in scan response packet. This packet is the same as adv packets but only exchanged when doing scan request/response. And in most use cases this is not a problem.

So in this way the device name can be max 31 - 1 -1 = 29 bytes.

Shortened or Complete device name?

As it suggests, if your adv data carries full name, then use Complete Local Name (type 0x09 in the link above),

otherwise Shortened Local Name (type 0x08). Complete Local Name is the Bluetooth term, sometimes we just call it full device name.

Shortened name makes the adv packets shorter, but then the phone would have to make a connection to and read your GATT database to find out the Complete Local Name.

This is up to the user.

MAC Address and Privacy

Some company would put complete MAC address in the adv packet as a part of the full device name. This is handy in some ways. But please also be aware that other hackers can track your device, by just listening to the adv packets. As the unique MAC address is in the payload, it is easy to find out the geo location of a certain BLE advertiser device.

The BLE standard has a privacy feature which keeps changing the device address value in the air to avoid tracking. But as adv data is not encrypted, MAC address in advertising payloads can make BLE privacy ineffective.

Device Name in GATT Database

As Sebastian mentioned already, users can also create a GATT database with a primary service (service_gap), and inside the service put a characteristic device name. This value should be treated the same as Local Name in adv packet, but of course it is finally your phone OS to interpret and use these values.

In the phones I've tested (iOS and Android), when scanning device, the name in the list is the Local Name in the adv packets. After a connection, the phone OS would try to read Device Name in GATT database, and if that's successful, the displayed name would be replaced by this value.

5,049 Views
Javad_Baig
Contributor II

Hi @Xiang_Li 

Is it possible to make the wirelessuart_bm example available in frdm-kw38 sdk to support for generic Bluetooth Application apart from IoT Tool Box. As I can see it supports only Iot Toolbox application 

 

Kindly reply at the earliest, Thank you

0 Kudos
Reply
5,166 Views
ab_nxp
Contributor I

I have tried with complete local name in structure but it is not working, Any other parameters need to modify?

0 Kudos
Reply