@@ -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+
12561301static 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