Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 201d5bbc authored by Joshua Stalder's avatar Joshua Stalder
Browse files

Correct SDP data element size descriptor for HIDD report descriptor

The length of the Report descriptor for HIDD is a unit16_t and limited by the API to 2048 bytes, is however written as an SDP data element with SIZE_IN_NEXT_BYTE, which leads to the element size being at most 255 bytes. The descriptor however is written fully to the SDP stream.

By using SIZE_IN_NEXT_WORD, we can accommodate for maximum size of 2048 bytes, which resolves these issues.

Bug: 362791956
Change-Id: Ie65e79d395c9f1db3adc0fef917a6c8db16bbe29
Test: manually
parent a0c9568d
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
    {
      static uint8_t cdt = 0x22;
      uint8_t* p_buf;
      uint8_t seq_len = 4 + desc_len;
      uint16_t seq_len = 5 + desc_len;

      if (desc_len > HIDD_APP_DESCRIPTOR_LEN) {
        log::error("descriptor length = {}, larger than max {}", desc_len, HIDD_APP_DESCRIPTOR_LEN);
@@ -263,10 +263,10 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
        return HID_ERR_NOT_REGISTERED;
      };

      p_buf = (uint8_t*)osi_malloc(HIDD_APP_DESCRIPTOR_LEN + 6);
      p_buf = (uint8_t*)osi_malloc(desc_len + 8);

      if (p_buf == NULL) {
        log::error("Buffer allocation failure for size = 2048");
        log::error("Buffer allocation failure for size = {}", desc_len + 8);
        log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
                                    HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION,
                            1);
@@ -275,15 +275,15 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,

      p = p_buf;

      UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
      UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);

      UINT8_TO_BE_STREAM(p, seq_len);
      UINT16_TO_BE_STREAM(p, seq_len);

      UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
      UINT8_TO_BE_STREAM(p, cdt);

      UINT8_TO_BE_STREAM(p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
      UINT8_TO_BE_STREAM(p, desc_len);
      UINT8_TO_BE_STREAM(p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
      UINT16_TO_BE_STREAM(p, desc_len);
      ARRAY_TO_BE_STREAM(p, p_desc_data, (int)desc_len);

      result &= get_legacy_stack_sdp_api()->handle.SDP_AddAttribute(