Skip to content

Commit 99243af

Browse files
chengkai15henrikbrixandersen
authored andcommitted
Bluetooth: PNP: add pnp product id interface and tool
add pnp product id interface and tool for HID profile Signed-off-by: Kai Cheng <[email protected]>
1 parent 82fd0b8 commit 99243af

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

include/zephyr/bluetooth/classic/sdp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,20 @@ int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features);
716716
*/
717717
int bt_sdp_get_vendor_id(const struct net_buf *buf, uint16_t *vendor_id);
718718

719+
/** @brief Get Product ID
720+
*
721+
* Helper API extracting remote Product ID. To get it proper
722+
* generic profile parameter needs to be selected usually listed in SDP
723+
* Interoperability Requirements section for given profile specification.
724+
*
725+
* @param buf Buffer holding original raw record data from remote.
726+
* @param product_id On success populated by found Product ID.
727+
* mask.
728+
*
729+
* @return 0 on success if product_id found and valid, negative in case any error
730+
*/
731+
int bt_sdp_get_product_id(const struct net_buf *buf, uint16_t *product_id);
732+
719733
#ifdef __cplusplus
720734
}
721735
#endif

subsys/bluetooth/host/classic/sdp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,3 +3110,17 @@ int bt_sdp_get_vendor_id(const struct net_buf *buf, uint16_t *vendor_id)
31103110

31113111
return sdp_get_u16_data(&attr, vendor_id);
31123112
}
3113+
3114+
int bt_sdp_get_product_id(const struct net_buf *buf, uint16_t *product_id)
3115+
{
3116+
struct bt_sdp_attr_item attr;
3117+
int err;
3118+
3119+
err = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_PRODUCT_ID);
3120+
if (err < 0) {
3121+
LOG_WRN("Attribute 0x%04x not found, err %d", BT_SDP_ATTR_PRODUCT_ID, err);
3122+
return err;
3123+
}
3124+
3125+
return sdp_get_u16_data(&attr, product_id);
3126+
}

subsys/bluetooth/host/classic/shell/bredr.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ static uint8_t sdp_pnp_user(struct bt_conn *conn, struct bt_sdp_client_result *r
10001000
const struct bt_sdp_discover_params *params)
10011001
{
10021002
char addr[BT_ADDR_STR_LEN];
1003-
uint16_t vendor_id;
1003+
uint16_t vendor_id, product_id;
10041004
int err;
10051005

10061006
conn_addr_str(conn, addr, sizeof(addr));
@@ -1016,6 +1016,14 @@ static uint8_t sdp_pnp_user(struct bt_conn *conn, struct bt_sdp_client_result *r
10161016
}
10171017

10181018
bt_shell_print("PNP vendor id param 0x%04x", vendor_id);
1019+
1020+
err = bt_sdp_get_product_id(result->resp_buf, &product_id);
1021+
if (err < 0) {
1022+
bt_shell_error("PNP product id not found, err %d", err);
1023+
goto done;
1024+
}
1025+
1026+
bt_shell_print("PNP product id param 0x%04x", product_id);
10191027
} else {
10201028
bt_shell_print("No SDP PNP data from remote %s", addr);
10211029
}

0 commit comments

Comments
 (0)