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

Commit f42322cd authored by Joshua Stalder's avatar Joshua Stalder
Browse files

Use SDP size in next byte for small Report descriptors

When the length of the Report descriptor for HIDD is below 256 bytes but the length in its SDP attribute is specified with SIZE_IN_NEXT_WORD, MS Windows no longer correctly accepts the HIDD connection.

To retain compatibility with existing apps and Windows releases, we can use SIZE_IN_NEXT_BYTE if possible based on the descriptor size, which works around the issue.

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

      uint16_t seq_len = ((desc_len > 255) ? 5 : 4) + desc_len;
      uint16_t buf_len = seq_len + 3;

      if (desc_len > HIDD_APP_DESCRIPTOR_LEN) {
        log::error("descriptor length = {}, larger than max {}", desc_len, HIDD_APP_DESCRIPTOR_LEN);
@@ -263,10 +265,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(desc_len + 8);
      p_buf = (uint8_t*)osi_malloc(buf_len);

      if (p_buf == NULL) {
        log::error("Buffer allocation failure for size = {}", desc_len + 8);
        log::error("Buffer allocation failure for size = {}", buf_len);
        log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
                                    HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION,
                            1);
@@ -282,8 +284,15 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
      UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
      UINT8_TO_BE_STREAM(p, cdt);

      // small descriptors should be written with SIZE_IN_NEXT_BYTE to preserve compatibility
      if (desc_len > 255) {
        UINT8_TO_BE_STREAM(p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
        UINT16_TO_BE_STREAM(p, desc_len);
      } else {
        UINT8_TO_BE_STREAM(p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
        UINT8_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(