Bluetooth: shell: Add sample SDP service registration
This change adds SPP as a sample SDP service during RFCOMM server registration. The SPP channel is now used as the fixed channel for RFCOMM register command. Change-Id: I3b5ad3995725adca55db1497d4a35099f6311f3b Signed-off-by: Kaustav Dey Biswas <kaustav.d.biswas@intel.com>
This commit is contained in:
parent
100890f71c
commit
148b0a2d35
2 changed files with 73 additions and 6 deletions
|
@ -55,6 +55,7 @@ enum {
|
|||
BT_RFCOMM_CHAN_HFP_AG,
|
||||
BT_RFCOMM_CHAN_HSP_AG,
|
||||
BT_RFCOMM_CHAN_HSP_HS,
|
||||
BT_RFCOMM_CHAN_SPP,
|
||||
};
|
||||
|
||||
struct bt_rfcomm_dlc;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <bluetooth/l2cap.h>
|
||||
#include <bluetooth/rfcomm.h>
|
||||
#include <bluetooth/storage.h>
|
||||
#include <bluetooth/sdp.h>
|
||||
|
||||
#include <misc/shell.h>
|
||||
|
||||
|
@ -66,6 +67,74 @@ static NET_BUF_POOL(data_bredr_pool, 1, DATA_BREDR_MTU, &data_bredr_fifo, NULL,
|
|||
|
||||
#endif /* CONFIG_BLUETOOTH_BREDR */
|
||||
|
||||
#if defined(CONFIG_BLUETOOTH_RFCOMM)
|
||||
|
||||
static struct bt_sdp_attribute spp_attrs[] = {
|
||||
BT_SDP_NEW_SERVICE,
|
||||
BT_SDP_LIST(
|
||||
BT_SDP_ATTR_SVCLASS_ID_LIST,
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_SEQ8, 3),
|
||||
BT_SDP_DATA_ELEM_LIST(
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_UUID16),
|
||||
BT_SDP_ARRAY_16(BT_SDP_SERIAL_PORT_SVCLASS_ID)
|
||||
},
|
||||
)
|
||||
),
|
||||
BT_SDP_LIST(
|
||||
BT_SDP_ATTR_PROTO_DESC_LIST,
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_SEQ8, 12),
|
||||
BT_SDP_DATA_ELEM_LIST(
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_SEQ8, 3),
|
||||
BT_SDP_DATA_ELEM_LIST(
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_UUID16),
|
||||
BT_SDP_ARRAY_16(BT_UUID_L2CAP_VAL)
|
||||
},
|
||||
)
|
||||
},
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_SEQ8, 5),
|
||||
BT_SDP_DATA_ELEM_LIST(
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_UUID16),
|
||||
BT_SDP_ARRAY_16(BT_UUID_RFCOMM_VAL)
|
||||
},
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_UINT8),
|
||||
BT_SDP_ARRAY_8(BT_RFCOMM_CHAN_SPP)
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
),
|
||||
BT_SDP_LIST(
|
||||
BT_SDP_ATTR_PFILE_DESC_LIST,
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_SEQ8, 8),
|
||||
BT_SDP_DATA_ELEM_LIST(
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_SEQ8, 6),
|
||||
BT_SDP_DATA_ELEM_LIST(
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_UUID16),
|
||||
BT_SDP_ARRAY_16(BT_SDP_SERIAL_PORT_SVCLASS_ID)
|
||||
},
|
||||
{
|
||||
BT_SDP_TYPE_SIZE(BT_SDP_UINT16),
|
||||
BT_SDP_ARRAY_16(0x0102)
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
),
|
||||
BT_SDP_SERVICE_NAME("Serial Port"),
|
||||
};
|
||||
|
||||
static struct bt_sdp_record spp_rec = BT_SDP_RECORD(spp_attrs);
|
||||
|
||||
#endif /* CONFIG_BLUETOOTH_RFCOMM */
|
||||
|
||||
static const char *current_prompt(void)
|
||||
{
|
||||
static char str[BT_ADDR_LE_STR_LEN + 2];
|
||||
|
@ -1944,16 +2013,12 @@ static int cmd_bredr_rfcomm_register(int argc, char *argv[])
|
|||
{
|
||||
int ret;
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (rfcomm_server.channel) {
|
||||
printk("Already registered\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
rfcomm_server.channel = strtoul(argv[1], NULL, 16);
|
||||
rfcomm_server.channel = BT_RFCOMM_CHAN_SPP;
|
||||
|
||||
ret = bt_rfcomm_server_register(&rfcomm_server);
|
||||
if (ret < 0) {
|
||||
|
@ -1961,6 +2026,7 @@ static int cmd_bredr_rfcomm_register(int argc, char *argv[])
|
|||
rfcomm_server.channel = 0;
|
||||
} else {
|
||||
printk("RFCOMM channel %u registered\n", rfcomm_server.channel);
|
||||
bt_sdp_register_service(&spp_rec);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -2137,7 +2203,7 @@ static const struct shell_cmd commands[] = {
|
|||
{ "br-l2cap-register", cmd_bredr_l2cap_register, "<psm>" },
|
||||
{ "br-oob", cmd_bredr_oob },
|
||||
#if defined(CONFIG_BLUETOOTH_RFCOMM)
|
||||
{ "br-rfcomm-register", cmd_bredr_rfcomm_register, "<channel>" },
|
||||
{ "br-rfcomm-register", cmd_bredr_rfcomm_register },
|
||||
{ "br-rfcomm-send", cmd_rfcomm_send, "<number of packets>"},
|
||||
#endif /* CONFIG_BLUETOOTH_RFCOMM */
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue