You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2020/03/07 00:09:41 UTC

[mynewt-nimble] 10/11: btshell: Allow to set own L2CAP CoC MTU

This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 8a83364da08a3198b38df0eeaf15b3bb97299215
Author: Ɓukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Mon Jan 27 21:43:28 2020 +0100

    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.
---
 apps/btshell/src/btshell.h   |  4 ++--
 apps/btshell/src/cmd.c       |  2 ++
 apps/btshell/src/cmd_l2cap.c | 18 ++++++++++++++++--
 apps/btshell/src/main.c      | 20 +++++++++++++++-----
 4 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/apps/btshell/src/btshell.h b/apps/btshell/src/btshell.h
index 650888d..b7bb09e 100644
--- a/apps/btshell/src/btshell.h
+++ b/apps/btshell/src/btshell.h
@@ -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,
diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index b91bd82..2713443 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -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}
 };
 
diff --git a/apps/btshell/src/cmd_l2cap.c b/apps/btshell/src/cmd_l2cap.c
index 8f26dc9..e74e3bf 100644
--- a/apps/btshell/src/cmd_l2cap.c
+++ b/apps/btshell/src/cmd_l2cap.c
@@ -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);
 }
 
 /*****************************************************************************
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index 714ce21..c7cfa33 100644
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -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
 }