Skip to content

spp: fix SDP proto list handling for RFCOMM channel#455

Merged
huangyulong3 merged 2 commits intoopen-vela:devfrom
chengkai15:bug_spp_sdp
Feb 12, 2026
Merged

spp: fix SDP proto list handling for RFCOMM channel#455
huangyulong3 merged 2 commits intoopen-vela:devfrom
chengkai15:bug_spp_sdp

Conversation

@chengkai15
Copy link
Contributor

bug: v/85645

rootcause:The SDP PROTO_DESC list was modified in place without copying, so the RFCOMM channel element pointer could become invalid or corrupt, leading to incorrect SDP records.

spp_record->attrs[i].val.data = spp_record->svclass_id_list;
} else if (spp_record->attrs[i].id == BT_SDP_ATTR_PROTO_DESC_LIST) {
struct bt_sdp_data_elem* element = (struct bt_sdp_data_elem*)&spp_record->attrs[i].val;
struct bt_sdp_data_elem* list_tmpl = (struct bt_sdp_data_elem*)spp_record->attrs[i].val.data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a tmpl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abbreviation of template

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Zephyr SPP SDP record construction to avoid mutating shared SDP PROTO_DESC data in-place, preventing RFCOMM channel element pointer corruption and incorrect SDP records.

Changes:

  • Extends spp_sdp_record_t to hold per-record copies of SDP data element arrays (service class list and protocol descriptor lists).
  • Updates spp_sdp_create_record() to repoint SDP attribute val.data to these per-record copies and safely patch the RFCOMM channel element.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

memcpy(spp_record->attrs, spp_attrs_template, sizeof(spp_attrs_template));

sys_memcpy_swap(spp_record->uuid128, uuid->val.u128, BT_UUID_SIZE_128);
memcpy(spp_record->uuid128, uuid->val.u128, BT_UUID_SIZE_128);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UUID128 byte order handling changed from sys_memcpy_swap() to memcpy(). Elsewhere in this file Classic SDP discovery still swaps UUID bytes before passing to Zephyr (sys_memcpy_swap at ~801), so this likely reintroduces an endianness mismatch in the advertised Service Class ID (remote peers may see a different UUID than intended). Keep the byte swap here (or otherwise ensure the SDP record uses the byte order expected by Zephyr SDP).

Suggested change
memcpy(spp_record->uuid128, uuid->val.u128, BT_UUID_SIZE_128);
sys_memcpy_swap(spp_record->uuid128, uuid->val.u128, BT_UUID_SIZE_128);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which was handle it stack open-vela/external_zblue#167

Comment on lines +323 to +326
spp_record->proto_desc_rfcomm[1] = rfcomm_tmpl[1];
spp_record->proto_desc_rfcomm[1].data = &spp_record->channel;

spp_record->proto_desc_list[1].data = spp_record->proto_desc_rfcomm;
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RFCOMM channel SDP element is declared as BT_SDP_UINT8 in the template, but the code points it at spp_record->channel which is a uint16_t. On little-endian targets this often “works by accident” (low byte first), but it can produce an incorrect channel value on big-endian targets and is type-inconsistent with the SDP element size. Store the channel in a uint8_t field (or a dedicated uint8_t temp) and point the SDP element to that.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@chengkai15 chengkai15 Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which was handled in stack

@chengkai15 chengkai15 requested a review from gzh-terry February 11, 2026 03:49
bug: v/85645

rootcause:The SDP PROTO_DESC list was modified in place
without copying, so the RFCOMM channel element pointer
could become invalid or corrupt, leading to incorrect
SDP records.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
bug: v/85645

rootcause: SPP SDP records used the wrong UUID byte order
and reused template data, so later registrations overwrote
previous RFCOMM channel/UUID and triggered false duplicates.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Copy link
Contributor

@chejinxian chejinxian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@huangyulong3 huangyulong3 merged commit 6233530 into open-vela:dev Feb 12, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants