You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/23 13:09:38 UTC

[GitHub] rymanluk closed pull request #949: btshell: Add way to reject LE CoC connection request

rymanluk closed pull request #949: btshell: Add way to reject LE CoC connection request
URL: https://github.com/apache/mynewt-core/pull/949
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apps/btshell/src/btshell.h b/apps/btshell/src/btshell.h
index fb8ca72cb..0abf325fc 100644
--- a/apps/btshell/src/btshell.h
+++ b/apps/btshell/src/btshell.h
@@ -155,7 +155,7 @@ int btshell_sec_restart(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
 int btshell_tx_start(uint16_t handle, uint16_t len, uint16_t rate,
                      uint16_t num);
 int btshell_rssi(uint16_t conn_handle, int8_t *out_rssi);
-int btshell_l2cap_create_srv(uint16_t psm);
+int btshell_l2cap_create_srv(uint16_t psm, int accept_response);
 int btshell_l2cap_connect(uint16_t conn, uint16_t psm);
 int btshell_l2cap_disconnect(uint16_t conn, uint16_t idx);
 int btshell_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes);
diff --git a/apps/btshell/src/cmd.c b/apps/btshell/src/cmd.c
index 86112e286..86fc9cfef 100644
--- a/apps/btshell/src/cmd.c
+++ b/apps/btshell/src/cmd.c
@@ -3251,6 +3251,11 @@ static const struct shell_cmd_help l2cap_update_help = {
 
 static const struct shell_param l2cap_create_server_params[] = {
     {"psm", "usage: =<UINT16>"},
+    {"error", "usage: used for PTS testing:"},
+    {"", "0 - always accept"},
+    {"", "1 - reject with insufficient authentication"},
+    {"", "2 - reject with insufficient authorization"},
+    {"", "3 - reject with insufficient key size"},
     {NULL, NULL}
 };
 
diff --git a/apps/btshell/src/cmd_l2cap.c b/apps/btshell/src/cmd_l2cap.c
index 68237f22f..0fa068188 100644
--- a/apps/btshell/src/cmd_l2cap.c
+++ b/apps/btshell/src/cmd_l2cap.c
@@ -95,6 +95,8 @@ int
 cmd_l2cap_create_server(int argc, char **argv)
 {
     uint16_t psm = 0;
+    int error;
+    int accept_response = 0;
     int rc;
 
     rc = parse_arg_all(argc - 1, argv + 1);
@@ -108,7 +110,25 @@ cmd_l2cap_create_server(int argc, char **argv)
         return rc;
     }
 
-    rc = btshell_l2cap_create_srv(psm);
+    error = parse_arg_uint32_dflt("error", 0, &rc);
+    if (rc != 0) {
+        console_printf("invalid 'error' parameter\n");
+        return rc;
+    }
+
+    switch (error) {
+    case 1:
+        accept_response = BLE_HS_EAUTHEN;
+        break;
+    case 2:
+        accept_response = BLE_HS_EAUTHOR;
+        break;
+    case 3:
+        accept_response = BLE_HS_EENCRYPT_KEY_SZ;
+        break;
+    }
+
+    rc = btshell_l2cap_create_srv(psm, accept_response);
     if (rc) {
         console_printf("Server create error: 0x%02x", rc);
     }
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index 06121620f..415ab91ef 100755
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -71,6 +71,9 @@
 #define BTSHELL_COC_MTU               (256)
 /* We use same pool for incoming and outgoing sdu */
 #define BTSHELL_COC_BUF_COUNT         (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
+
+#define INT_TO_PTR(x)     (void *)((intptr_t)(x))
+#define PTR_TO_INT(x)     (int) ((intptr_t)(x))
 #endif
 
 struct log btshell_log;
@@ -1829,6 +1832,8 @@ btshell_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
 static int
 btshell_l2cap_event(struct ble_l2cap_event *event, void *arg)
 {
+    int accept_response;
+
     switch(event->type) {
         case BLE_L2CAP_EVENT_COC_CONNECTED:
             if (event->connect.status) {
@@ -1852,6 +1857,11 @@ btshell_l2cap_event(struct ble_l2cap_event *event, void *arg)
                                      event->disconnect.chan);
             return 0;
         case BLE_L2CAP_EVENT_COC_ACCEPT:
+            accept_response = PTR_TO_INT(arg);
+            if (accept_response) {
+                return accept_response;
+            }
+
             return btshell_l2cap_coc_accept(event->accept.conn_handle,
                                             event->accept.peer_sdu_size,
                                             event->accept.chan);
@@ -1866,7 +1876,7 @@ btshell_l2cap_event(struct ble_l2cap_event *event, void *arg)
 #endif
 
 int
-btshell_l2cap_create_srv(uint16_t psm)
+btshell_l2cap_create_srv(uint16_t psm, int accept_response)
 {
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
     console_printf("BLE L2CAP LE COC not supported.");
@@ -1875,7 +1885,7 @@ btshell_l2cap_create_srv(uint16_t psm)
 #else
 
     return ble_l2cap_create_server(psm, BTSHELL_COC_MTU, btshell_l2cap_event,
-                                                                       NULL);
+                                   INT_TO_PTR(accept_response));
 #endif
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services