Skip to content

Commit 82fd0b8

Browse files
chengkai15henrikbrixandersen
authored andcommitted
Bluetooth: PNP: add pnp vendor id interface and tool
add pnp vendor id interface for hid feature. Signed-off-by: Kai Cheng <[email protected]>
1 parent ff2503c commit 82fd0b8

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

include/zephyr/bluetooth/classic/sdp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,19 @@ int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile,
703703
*/
704704
int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features);
705705

706+
/** @brief Get Vendor ID
707+
*
708+
* Helper API extracting remote Vendor ID. To get it proper
709+
* generic profile parameter needs to be selected usually listed in SDP
710+
* Interoperability Requirements section for given profile specification.
711+
*
712+
* @param buf Buffer holding original raw record data from remote.
713+
* @param vendor_id On success populated by found Vendor ID.
714+
*
715+
* @return 0 on success if vendor_id found and valid, negative in case any error
716+
*/
717+
int bt_sdp_get_vendor_id(const struct net_buf *buf, uint16_t *vendor_id);
718+
706719
#ifdef __cplusplus
707720
}
708721
#endif

subsys/bluetooth/host/classic/sdp.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,3 +3096,17 @@ int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features)
30963096

30973097
return sdp_get_u16_data(&attr, features);
30983098
}
3099+
3100+
int bt_sdp_get_vendor_id(const struct net_buf *buf, uint16_t *vendor_id)
3101+
{
3102+
struct bt_sdp_attr_item attr;
3103+
int err;
3104+
3105+
err = bt_sdp_get_attr(buf, &attr, BT_SDP_ATTR_VENDOR_ID);
3106+
if (err < 0) {
3107+
LOG_WRN("Attribute 0x%04x not found, err %d", BT_SDP_ATTR_VENDOR_ID, err);
3108+
return err;
3109+
}
3110+
3111+
return sdp_get_u16_data(&attr, vendor_id);
3112+
}

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,33 @@ static uint8_t sdp_a2src_user(struct bt_conn *conn, struct bt_sdp_client_result
996996
return BT_SDP_DISCOVER_UUID_CONTINUE;
997997
}
998998

999+
static uint8_t sdp_pnp_user(struct bt_conn *conn, struct bt_sdp_client_result *result,
1000+
const struct bt_sdp_discover_params *params)
1001+
{
1002+
char addr[BT_ADDR_STR_LEN];
1003+
uint16_t vendor_id;
1004+
int err;
1005+
1006+
conn_addr_str(conn, addr, sizeof(addr));
1007+
1008+
if ((result != NULL) && (result->resp_buf != NULL)) {
1009+
bt_shell_print("SDP PNP data@%p (len %u) hint %u from remote %s", result->resp_buf,
1010+
result->resp_buf->len, result->next_record_hint, addr);
1011+
1012+
err = bt_sdp_get_vendor_id(result->resp_buf, &vendor_id);
1013+
if (err < 0) {
1014+
bt_shell_error("PNP vendor id not found, err %d", err);
1015+
goto done;
1016+
}
1017+
1018+
bt_shell_print("PNP vendor id param 0x%04x", vendor_id);
1019+
} else {
1020+
bt_shell_print("No SDP PNP data from remote %s", addr);
1021+
}
1022+
done:
1023+
return BT_SDP_DISCOVER_UUID_CONTINUE;
1024+
}
1025+
9991026
static struct bt_sdp_discover_params discov_hfpag = {
10001027
.type = BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR,
10011028
.uuid = BT_UUID_DECLARE_16(BT_SDP_HANDSFREE_AGW_SVCLASS),
@@ -1017,6 +1044,13 @@ static struct bt_sdp_discover_params discov_a2src = {
10171044
.pool = &sdp_client_pool,
10181045
};
10191046

1047+
static struct bt_sdp_discover_params discov_pnp = {
1048+
.type = BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR,
1049+
.uuid = BT_UUID_DECLARE_16(BT_SDP_PNP_INFO_SVCLASS),
1050+
.func = sdp_pnp_user,
1051+
.pool = &sdp_client_pool,
1052+
};
1053+
10201054
static struct bt_sdp_discover_params discov;
10211055

10221056
static int cmd_sdp_find_record(const struct shell *sh, size_t argc, char *argv[])
@@ -1037,6 +1071,8 @@ static int cmd_sdp_find_record(const struct shell *sh, size_t argc, char *argv[]
10371071
discov = discov_hfphf;
10381072
} else if (!strcmp(action, "A2SRC")) {
10391073
discov = discov_a2src;
1074+
} else if (!strcmp(action, "PNP")) {
1075+
discov = discov_pnp;
10401076
} else {
10411077
shell_help(sh);
10421078
return SHELL_CMD_HELP_PRINTED;
@@ -1446,7 +1482,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(br_cmds,
14461482
SHELL_CMD(l2cap, &l2cap_cmds, HELP_NONE, cmd_default_handler),
14471483
SHELL_CMD_ARG(oob, NULL, NULL, cmd_oob, 1, 0),
14481484
SHELL_CMD_ARG(pscan, NULL, "<value: on, off>", cmd_connectable, 2, 0),
1449-
SHELL_CMD_ARG(sdp-find, NULL, "<HFPAG, HFPHF>", cmd_sdp_find_record, 2, 0),
1485+
SHELL_CMD_ARG(sdp-find, NULL, "<HFPAG, HFPHF, PNP>", cmd_sdp_find_record, 2, 0),
14501486
SHELL_CMD_ARG(switch-role, NULL, "<value: central, peripheral>", cmd_switch_role, 2, 0),
14511487
SHELL_CMD_ARG(set-role-switchable, NULL, "<value: enable, disable>",
14521488
cmd_set_role_switchable, 2, 0),

0 commit comments

Comments
 (0)