Search code examples
cstm32bluenrg

STM BlueNRG-MS Max Characteristic length


My general understanding is that the BLE standard supports characteristics with a lenght of up to 512 bytes. I'm using the BlueNRG-MS chip from STM but there the function call to add a characteristic has a uint8_t value for the length parameter

tBleStatus aci_gatt_add_char(uint16_t serviceHandle,
                 uint8_t charUuidType,
                 const uint8_t* charUuid, 
                 uint8_t charValueLen, 
                 uint8_t charProperties,
                 uint8_t secPermissions,
                 uint8_t gattEvtMask,
                 uint8_t encryKeySize,
                 uint8_t isVariable,
                 uint16_t* charHandle);

So this would allow only a maximum characteristic length of 255 bytes. According to this document the stack itself supports 2 bytes with FW 7.2 or higher. I have 7.23 so this should be fine but I cannot find any reference or example of a BlueNRG-MS middleware that would support a call with charValueLen of type uint16_t. I also downloaded the latest STSW-BLUENRG-DK and the examples also only support uint8_t charValueLen.


Solution

  • Yes, it supports charValueLen with uint16_t too. Sample function would be as followed:

    tBleStatus aci_gatt_add_char(uint16_t serviceHandle,
                             uint8_t charUuidType,
                             const uint8_t* charUuid, 
                             uint16_t charValueLen, 
                             uint8_t charProperties,
                             uint8_t secPermissions,
                             uint8_t gattEvtMask,
                             uint8_t encryKeySize,
                             uint8_t isVariable,
                             uint16_t* charHandle)
    {
      struct hci_request rq;
      gatt_add_serv_rp resp;
      uint8_t buffer[26];
      ... // code omitted w/o needing modification
    
      Osal_MemCpy(buffer + indx, charUuid, uuid_len);
      indx +=  uuid_len;
    
      charValueLen = htobs(charValueLen);
      Osal_MemCpy(buffer + indx, &charValueLen, 2);
      indx += 2;
    
      buffer[indx] = charProperties;
      indx++;
      ... // code omitted w/o needing modification
    }