cancel
Showing results for 
Search instead for 
Did you mean: 

Format for service UUID list when enabling BLE advertising

MD'Si.1
Associate III

I am trying to edit the BLE Sensor Demo app for STM32 micro and BLUENRG-M0 module (using Nucleo boards).

I want to advertise one service in the advertising packet. When I make the call to aci_gap_set_discoverable() I get a response of BLE_STATUS_INVALID_PARAMS( 66 dec ) . The only change I made to the example source code is to add in the HW service UUID as used in the sample code.

void Set_DeviceConnectable(void)
{
  uint8_t ret;
  const char local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,SENSOR_DEMO_NAME};
  uint8_t svc_uuid[] = { 0x07,0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
 
  uint8_t manuf_data[] = {
    2,0x0A,0x00, /* 0 dBm */  // Trasmission Power
    8,0x09,SENSOR_DEMO_NAME,  // Complete Name
    11,0xFF,0xFF, /* SKD version */
    0x52,
    0x41,
    0x4c,
    bdaddr[5], /* BLE MAC start -MSB first- */
    bdaddr[4],
    bdaddr[3],
    bdaddr[2],
    bdaddr[1],
    bdaddr[0]  /* BLE MAC stop */
  };
 
  //manuf_data[18] |= 0x01; /* Sensor Fusion */
  //COPY_HW_SENS_W2ST_SERVICE_UUID(svc_uuid);
 
  hci_le_set_scan_resp_data(0, NULL);
 
  PRINT_INFO("Set General Discoverable Mode.\n");
 
  ret = aci_gap_set_discoverable(ADV_DATA_TYPE,
                                (ADV_INTERVAL_MIN_MS*1000)/625,(ADV_INTERVAL_MAX_MS*1000)/625,
                                 STATIC_RANDOM_ADDR, NO_WHITE_LIST_USE,
				 //sizeof(local_name), local_name, 0, NULL, 0, 0);
                                 sizeof(local_name), local_name, sizeof(svc_uuid), svc_uuid, 0, 0);
 
  aci_gap_update_adv_data(sizeof(manuf_data), manuf_data);
 
  if(ret != BLE_STATUS_SUCCESS)
  {
    PRINT_ERR("aci_gap_set_discoverable() failed: 0x%02x\r\n", ret);
  }
  else
  {
    PRINT_INFO("aci_gap_set_discoverable() --> SUCCESS\r\n");
  }
}

Inside the aci_gap_set_discoverable() the code successfully passes the buffer overrun check so the error value of BLE_STATUS_INVALID_PARAMS comes after calling the hci_send_req(). Something is wrong is how I am formatting the service uuid and I can't find any example code on how to do this from STM.

Thanks

3 REPLIES 3
Sebastien DENOUAL
ST Employee

Hi @MD'Si.1​ ,

I would advise to start from "SensorDemo_BLESensor-App" code example availabel in X-CUBE-BLE1 package.

You will see examples of UUID format for sevrice/charateristics. Always take care of Endianess with BLE<

As well in your code example, UUID looks to be 17bytes .. UUID are 128 bits.

Regards,

Sebastien.

@Sebastien DENOUAL​  ​Thanks for the suggestion. I am using the example you suggested and I still see incorrect behavior. The uuid I am trying to add to the advertising packet is 000000000001-11e1-9ab4-0002a5d5c51b which is the one used in the BLE Sensor APP example code (HW service)

I don't think the aci_gap_set_discoverable() has been verified with a uuid 128 list. The function or some underlying call does not account for the AD Type to be inserted just like the local_name variable. I tried 3 things below and each time the advertising packed was either nor formed or formed incorrectly.

  1. If I add my uuid without an identifier of AD_TYPE_128_BIT_SERV_UUID (0x06) the functional call is successful but the advertising data is not correctly formed. The AD type byte is missing so the packet is identified with type 0x00 (It should be 0x06 which is Incomplete 128bit UUID service list).
  2. If I add the AD_TYPE_128_BIT_SERV_UUID to the uuid array and declare a length of 17 the function call fails.
  3. If I add the AD_TYPE_128_BIT_SERV_UUID to the uuid array and declare a length of 16 the call is successful but the first byte of the uuid is 0x02 which must come from the Tx Power info that is appended to the Advertising packet.

Code for point number 1

void Set_DeviceConnectable(void)
{
  uint8_t ret;
  uint8_t local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,SENSOR_DEMO_NAME};
  uint8_t svc_uuid_list[] = {0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x00};
  //uint8_t svc_uuid_list[] = {AD_TYPE_128_BIT_SERV_UUID,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
 
  uint8_t manuf_data[5] = {
    //2,0x0A,0x00, /* 0 dBm */  // Trasmission Power
    //7,0x09,SENSOR_DEMO_NAME,  // Complete Name
    //17,0x06,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x0,
    4,0xff,0x52,0x41,0x4c
  };
 
  //manuf_data[18] |= 0x01; /* Sensor Fusion */
 
  hci_le_set_scan_response_data(0,NULL);
 
  PRINT_DBG("Set General Discoverable Mode.\r\n");
 
  ret = aci_gap_set_discoverable(ADV_DATA_TYPE,
                                 ADV_INTERV_MIN, ADV_INTERV_MAX,
                                 PUBLIC_ADDR,
                                 NO_WHITE_LIST_USE,
                                 //sizeof(local_name), local_name, 0, NULL, 0, 0);
				 sizeof(local_name), local_name, 16, svc_uuid_list, 0, 0);
 
  aci_gap_update_adv_data(5, manuf_data);
 
  if(ret != BLE_STATUS_SUCCESS) {
    PRINT_DBG("aci_gap_set_discoverable() failed: 0x%02x\r\n", ret);
  }
  else {
    PRINT_DBG("aci_gap_set_discoverable() --> SUCCESS\r\n");
  }
}

0693W00000QLnmeQAD.jpg0693W00000QLnmtQAD.jpg 

Code for point number 2

void Set_DeviceConnectable(void)
{
  uint8_t ret;
  uint8_t local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,SENSOR_DEMO_NAME};
  uint8_t svc_uuid_list[] = {AD_TYPE_128_BIT_SERV_UUID,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x00};
  //uint8_t svc_uuid_list[] = {AD_TYPE_128_BIT_SERV_UUID,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
 
  uint8_t manuf_data[5] = {
    //2,0x0A,0x00, /* 0 dBm */  // Trasmission Power
    //7,0x09,SENSOR_DEMO_NAME,  // Complete Name
    //17,0x06,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x0,
    4,0xff,0x52,0x41,0x4c
  };
 
  //manuf_data[18] |= 0x01; /* Sensor Fusion */
 
  hci_le_set_scan_response_data(0,NULL);
 
  PRINT_DBG("Set General Discoverable Mode.\r\n");
 
  ret = aci_gap_set_discoverable(ADV_DATA_TYPE,
                                 ADV_INTERV_MIN, ADV_INTERV_MAX,
                                 PUBLIC_ADDR,
                                 NO_WHITE_LIST_USE,
                                 //sizeof(local_name), local_name, 0, NULL, 0, 0);
				 sizeof(local_name), local_name, 17, svc_uuid_list, 0, 0);
 
  aci_gap_update_adv_data(5, manuf_data);
 
  if(ret != BLE_STATUS_SUCCESS) {
    PRINT_DBG("aci_gap_set_discoverable() failed: 0x%02x\r\n", ret);
  }
  else {
    PRINT_DBG("aci_gap_set_discoverable() --> SUCCESS\r\n");
  }
}

0693W00000QLnm5QAD.jpg 

Code for point number 3.

void Set_DeviceConnectable(void)
{
  uint8_t ret;
  uint8_t local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,SENSOR_DEMO_NAME};
  uint8_t svc_uuid_list[] = {AD_TYPE_128_BIT_SERV_UUID,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00};
  //uint8_t svc_uuid_list[] = {AD_TYPE_128_BIT_SERV_UUID,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b};
 
  uint8_t manuf_data[5] = {
    //2,0x0A,0x00, /* 0 dBm */  // Trasmission Power
    //7,0x09,SENSOR_DEMO_NAME,  // Complete Name
    //17,0x06,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x0,
    4,0xff,0x52,0x41,0x4c
  };
 
  //manuf_data[18] |= 0x01; /* Sensor Fusion */
 
  hci_le_set_scan_response_data(0,NULL);
 
  PRINT_DBG("Set General Discoverable Mode.\r\n");
 
  ret = aci_gap_set_discoverable(ADV_DATA_TYPE,
                                 ADV_INTERV_MIN, ADV_INTERV_MAX,
                                 PUBLIC_ADDR,
                                 NO_WHITE_LIST_USE,
                                 //sizeof(local_name), local_name, 0, NULL, 0, 0);
				 sizeof(local_name), local_name, 16, svc_uuid_list, 0, 0);
 
  aci_gap_update_adv_data(5, manuf_data);
 
  if(ret != BLE_STATUS_SUCCESS) {
    PRINT_DBG("aci_gap_set_discoverable() failed: 0x%02x\r\n", ret);
  }
  else {
    PRINT_DBG("aci_gap_set_discoverable() --> SUCCESS\r\n");
  }
}

0693W00000QLnglQAD.jpg0693W00000QLnggQAD.jpg 

MD'Si.1
Associate III

@Sebastien DENOUAL​ I was able to get the service list to work with a 128 bit uuid and I did have to declare 17 octets for the function to work. To make it work I had to reduce the size of the local advertised name by about half.

Is there a way to increase the size so I can have a longer name and a 128 bit UUID. I have seen other bluetooth 4 chipsets support this feature so is it a configuration issue?

#define SENSOR_DEMO_NAME   'B','l','u','e' //,'N','R','G'
 
void Set_DeviceConnectable(void)
{
  uint8_t ret;
  uint8_t local_name[] = {AD_TYPE_COMPLETE_LOCAL_NAME,SENSOR_DEMO_NAME};
  uint8_t svc_uuid_list[] = {AD_TYPE_128_BIT_SERV_UUID,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x00};
 
  uint8_t manuf_data[23] = {
    //2,0x0A,0x00, /* 0 dBm */  // Trasmission Power
    //7,0x09,SENSOR_DEMO_NAME,  // Complete Name
    //0x11,0x06,0x1b,0xc5,0xd5,0xa5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x0,
    4,0xff,0x52,0x41,0x4c
  };
 
  //manuf_data[18] |= 0x01; /* Sensor Fusion */
 
  hci_le_set_scan_response_data(0,NULL);
 
  PRINT_DBG("Set General Discoverable Mode.\r\n");
 
  ret = aci_gap_set_discoverable(ADV_DATA_TYPE,
                                 ADV_INTERV_MIN, ADV_INTERV_MAX,
                                 PUBLIC_ADDR,
                                 NO_WHITE_LIST_USE,
                                 //sizeof(local_name), local_name, 0, NULL, 0, 0);
				 sizeof(local_name), local_name, 17, svc_uuid_list, 0, 0);
 
  aci_gap_update_adv_data(23, manuf_data);
 
  if(ret != BLE_STATUS_SUCCESS) {
    PRINT_DBG("aci_gap_set_discoverable() failed: 0x%02x\r\n", ret);
  }
  else {
    PRINT_DBG("aci_gap_set_discoverable() --> SUCCESS\r\n");
  }
}