Skip to content

Commit e7cb176

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: tester: Add command to send connectionless data
Add command `BTP_L2CAP_CONNLESS_SEND` to send connectionless data with specific PSM. Signed-off-by: Lyle Zhu <[email protected]>
1 parent efcbb1f commit e7cb176

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/bluetooth/tester/src/btp/btp_l2cap.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ struct btp_l2cap_listen_v2_cmd {
148148
uint32_t options;
149149
} __packed;
150150

151+
#define BTP_L2CAP_CONNLESS_SEND 0x0d
152+
struct btp_l2cap_connless_send_cmd {
153+
bt_addr_le_t address;
154+
uint16_t psm;
155+
uint32_t options;
156+
uint16_t data_length;
157+
uint8_t data[];
158+
} __packed;
159+
151160
/* events */
152161
#define BTP_L2CAP_EV_CONNECTION_REQ 0x80
153162
struct btp_l2cap_connection_req_ev {

tests/bluetooth/tester/src/btp_l2cap.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,51 @@ static uint8_t send_echo_req(const void *cmd, uint16_t cmd_len, void *rsp, uint1
12531253
}
12541254
#endif /* CONFIG_BT_CLASSIC */
12551255

1256+
#if defined(CONFIG_BT_L2CAP_CONNLESS)
1257+
static uint8_t connless_send(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
1258+
{
1259+
const struct btp_l2cap_connless_send_cmd *cp = cmd;
1260+
struct bt_conn *conn;
1261+
struct net_buf *buf;
1262+
uint16_t psm;
1263+
uint16_t data_len;
1264+
int err;
1265+
1266+
if (cp->address.type != BTP_BR_ADDRESS_TYPE) {
1267+
LOG_ERR("Only support Classic");
1268+
return BTP_STATUS_FAILED;
1269+
}
1270+
1271+
conn = bt_conn_lookup_addr_br(&cp->address.a);
1272+
if (!conn) {
1273+
LOG_ERR("Unknown connection");
1274+
return BTP_STATUS_FAILED;
1275+
}
1276+
1277+
psm = sys_le16_to_cpu(cp->psm);
1278+
data_len = sys_le16_to_cpu(cp->data_length);
1279+
1280+
if (data_len > DATA_MTU) {
1281+
LOG_ERR("Data length exceeds MAX buffer len (%u > %u)", data_len, DATA_MTU);
1282+
return BTP_STATUS_FAILED;
1283+
}
1284+
1285+
buf = net_buf_alloc(&data_pool, K_FOREVER);
1286+
net_buf_reserve(buf, BT_L2CAP_CONNLESS_RESERVE);
1287+
net_buf_add_mem(buf, cp->data, data_len);
1288+
1289+
err = bt_l2cap_br_connless_send(conn, psm, buf);
1290+
bt_conn_unref(conn);
1291+
if (err < 0) {
1292+
LOG_ERR("Unable to send CLS data: %d", -err);
1293+
net_buf_unref(buf);
1294+
return BTP_STATUS_FAILED;
1295+
}
1296+
1297+
return BTP_STATUS_SUCCESS;
1298+
}
1299+
#endif /* CONFIG_BT_L2CAP_CONNLESS */
1300+
12561301
static uint8_t supported_commands(const void *cmd, uint16_t cmd_len,
12571302
void *rsp, uint16_t *rsp_len)
12581303
{
@@ -1325,6 +1370,13 @@ static const struct btp_handler handlers[] = {
13251370
.func = send_echo_req,
13261371
},
13271372
#endif /* CONFIG_BT_CLASSIC */
1373+
#if defined(CONFIG_BT_L2CAP_CONNLESS)
1374+
{
1375+
.opcode = BTP_L2CAP_CONNLESS_SEND,
1376+
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
1377+
.func = connless_send,
1378+
},
1379+
#endif /* CONFIG_BT_L2CAP_CONNLESS*/
13281380
};
13291381

13301382
#if defined(CONFIG_BT_CLASSIC)

0 commit comments

Comments
 (0)