btshell: Allow to set own L2CAP CoC MTU

We allow it in order to test L2CAP CoC reconfigure.

Note that it is not possible to set more than BTSHELL_COC_MTU.
This commit is contained in:
Łukasz Rymanowski
2020-03-07 01:09:21 +01:00
parent b7849bbbab
commit 8a83364da0
4 changed files with 35 additions and 9 deletions
+2 -2
View File
@@ -170,8 +170,8 @@ int btshell_tx_start(uint16_t conn_handle, uint16_t len, uint16_t rate,
uint16_t num);
void btshell_tx_stop(void);
int btshell_rssi(uint16_t conn_handle, int8_t *out_rssi);
int btshell_l2cap_create_srv(uint16_t psm, int accept_response);
int btshell_l2cap_connect(uint16_t conn, uint16_t psm, uint8_t num);
int btshell_l2cap_create_srv(uint16_t psm, uint16_t mtu, int accept_response);
int btshell_l2cap_connect(uint16_t conn, uint16_t psm, uint16_t mtu, uint8_t num);
int btshell_l2cap_disconnect(uint16_t conn, uint16_t idx);
int btshell_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes);
int btshell_l2cap_reconfig(uint16_t conn_handle, uint16_t mtu,
+2
View File
@@ -3494,6 +3494,7 @@ static const struct shell_cmd_help l2cap_update_help = {
static const struct shell_param l2cap_create_server_params[] = {
{"psm", "usage: =<UINT16>"},
{"mtu", "usage: =<UINT16> not more than BTSHELL_COC_MTU, default BTSHELL_COC_MTU"},
{"error", "usage: used for PTS testing:"},
{"", "0 - always accept"},
{"", "1 - reject with insufficient authentication"},
@@ -3516,6 +3517,7 @@ static const struct shell_param l2cap_connect_params[] = {
{"conn", "connection handle, usage: =<UINT16>"},
{"psm", "usage: =<UINT16>"},
{"num", "usage: number of connection created in a row: [1-5]"},
{"mtu", "usage: =<UINT16> not more than BTSHELL_COC_MTU, default BTSHELL_COC_MTU"},
{NULL, NULL}
};
+16 -2
View File
@@ -96,6 +96,7 @@ int
cmd_l2cap_create_server(int argc, char **argv)
{
uint16_t psm = 0;
uint16_t mtu;
int error;
int accept_response = 0;
int rc;
@@ -117,6 +118,12 @@ cmd_l2cap_create_server(int argc, char **argv)
return rc;
}
mtu = parse_arg_uint16_dflt("mtu", 0, &rc);
if (rc != 0) {
console_printf("invalid 'mtu' parameter\n");
return rc;
}
switch (error) {
case 1:
accept_response = BLE_HS_EAUTHEN;
@@ -129,7 +136,7 @@ cmd_l2cap_create_server(int argc, char **argv)
break;
}
rc = btshell_l2cap_create_srv(psm, accept_response);
rc = btshell_l2cap_create_srv(psm, mtu, accept_response);
if (rc) {
console_printf("Server create error: 0x%02x\n", rc);
return rc;
@@ -148,6 +155,7 @@ cmd_l2cap_connect(int argc, char **argv)
{
uint16_t conn = 0;
uint16_t psm = 0;
uint16_t mtu;
uint8_t num;
int rc;
@@ -168,13 +176,19 @@ cmd_l2cap_connect(int argc, char **argv)
return rc;
}
mtu = parse_arg_uint16_dflt("mtu", 0, &rc);
if (rc != 0) {
console_printf("invalid 'mtu' parameter\n");
return rc;
}
num = parse_arg_uint8_dflt("num", 1, &rc);
if (rc != 0) {
console_printf("invalid 'num' parameter\n");
return rc;
}
return btshell_l2cap_connect(conn, psm, num);
return btshell_l2cap_connect(conn, psm, mtu, num);
}
/*****************************************************************************
+15 -5
View File
@@ -2298,7 +2298,7 @@ btshell_l2cap_event(struct ble_l2cap_event *event, void *arg)
#endif
int
btshell_l2cap_create_srv(uint16_t psm, int accept_response)
btshell_l2cap_create_srv(uint16_t psm, uint16_t mtu, int accept_response)
{
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
console_printf("BLE L2CAP LE COC not supported.");
@@ -2306,13 +2306,17 @@ btshell_l2cap_create_srv(uint16_t psm, int accept_response)
return 0;
#else
return ble_l2cap_create_server(psm, BTSHELL_COC_MTU, btshell_l2cap_event,
if (mtu == 0 || mtu > BTSHELL_COC_MTU) {
mtu = BTSHELL_COC_MTU;
}
return ble_l2cap_create_server(psm, mtu, btshell_l2cap_event,
INT_TO_PTR(accept_response));
#endif
}
int
btshell_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint8_t num)
btshell_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu, uint8_t num)
{
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
console_printf("BLE L2CAP LE COC not supported.");
@@ -2323,17 +2327,23 @@ btshell_l2cap_connect(uint16_t conn_handle, uint16_t psm, uint8_t num)
struct os_mbuf *sdu_rx[num];
int i;
if (mtu == 0 || mtu > BTSHELL_COC_MTU) {
mtu = BTSHELL_COC_MTU;
}
console_printf("L2CAP CoC MTU: %d, max available %d\n", mtu, BTSHELL_COC_MTU);
for (i = 0; i < num; i++) {
sdu_rx[i] = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
assert(sdu_rx != NULL);
}
if (num == 1) {
return ble_l2cap_connect(conn_handle, psm, BTSHELL_COC_MTU, sdu_rx[0],
return ble_l2cap_connect(conn_handle, psm, mtu, sdu_rx[0],
btshell_l2cap_event, NULL);
}
return ble_l2cap_enhanced_connect(conn_handle, psm, BTSHELL_COC_MTU,
return ble_l2cap_enhanced_connect(conn_handle, psm, mtu,
num, sdu_rx,btshell_l2cap_event, NULL);
#endif
}