mynewt-nimble icon indicating copy to clipboard operation
mynewt-nimble copied to clipboard

nimble: [WIP] Eatt initial implementation

Open rymanluk opened this issue 4 years ago • 1 comments

This is initial implementation and not yet completed. Idea is to hide EATT from the application, but instead allow to Host to choose bearer to use. Code pass some PTS test cases related to EATT and new opcodes.

Posted for early comments: TODO list

  • number of TODOs in the code (error paths)
  • handling read/write Client/Server Supported Features - now it is done in EATT code but should be generic
  • cache client/server supported features values for bonded devices
  • add/fix unit tests
  • how we want to expose to app sending multiple notifications.
  • expose test API to choose different channels to send data (required by PTS)

rymanluk avatar Mar 12 '20 13:03 rymanluk

Style check summary

Our coding style is here!

nimble/host/src/ble_eatt.c

@@ -52,7 +52,7 @@
 
 #define BLE_EATT_DATABUF_SIZE  ( \
         MYNEWT_VAL(BLE_EATT_MTU) + \
-        2 +\
+        2 + \
         sizeof (struct os_mbuf_pkthdr) +   \
         sizeof (struct os_mbuf))
 
@@ -352,7 +352,7 @@
     uint8_t supported_features;
     int rc;
 
-    if (error == NULL ||  (error->status != 0 && error->status != BLE_HS_EDONE)) {
+    if (error == NULL || (error->status != 0 && error->status != BLE_HS_EDONE)) {
         BLE_EATT_LOG_DEBUG("eatt: Cannot find Server Supported features on peer device\n");
         return BLE_HS_EDONE;
     }

nimble/host/src/ble_att.c

@@ -624,7 +624,7 @@
 bool
 ble_att_is_request_op(uint8_t opcode)
 {
-    switch(opcode) {
+    switch (opcode) {
     case BLE_ATT_OP_MTU_REQ:
     case BLE_ATT_OP_FIND_INFO_REQ:
     case BLE_ATT_OP_FIND_TYPE_VALUE_REQ:
@@ -645,8 +645,9 @@
 }
 
 bool
-ble_att_is_response_op(uint8_t opcode) {
-    switch(opcode) {
+ble_att_is_response_op(uint8_t opcode)
+{
+    switch (opcode) {
     case BLE_ATT_OP_MTU_RSP:
     case BLE_ATT_OP_ERROR_RSP:
     case BLE_ATT_OP_FIND_INFO_RSP:

nimble/host/src/ble_att_clt.c

@@ -27,8 +27,8 @@
 #include "ble_hs_priv.h"
 
 /*****************************************************************************
- * $error response                                                           *
- *****************************************************************************/
+* $error response                                                           *
+*****************************************************************************/
 
 int
 ble_att_clt_rx_error(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
@@ -147,8 +147,8 @@
 }
 
 /*****************************************************************************
- * $find information                                                         *
- *****************************************************************************/
+* $find information                                                         *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t cid, uint16_t start_handle,
@@ -355,8 +354,8 @@
 }
 
 /*****************************************************************************
- * $read by type                                                             *
- *****************************************************************************/
+* $read by type                                                             *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t cid, uint16_t start_handle,
@@ -442,8 +441,8 @@
 }
 
 /*****************************************************************************
- * $read                                                                     *
- *****************************************************************************/
+* $read                                                                     *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_read(uint16_t conn_handle, uint16_t cid, uint16_t handle)
@@ -488,8 +487,8 @@
 }
 
 /*****************************************************************************
- * $read blob                                                                *
- *****************************************************************************/
+* $read blob                                                                *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t cid, uint16_t handle, uint16_t offset)
@@ -535,8 +534,8 @@
 }
 
 /*****************************************************************************
- * $read multiple                                                            *
- *****************************************************************************/
+* $read multiple                                                            *
+*****************************************************************************/
 int
 ble_att_clt_tx_read_mult(uint16_t conn_handle, uint16_t cid, const uint16_t *handles,
                          int num_handles, bool variable)
@@ -595,8 +594,8 @@
 }
 
 /*****************************************************************************
- * $read by group type                                                       *
- *****************************************************************************/
+* $read by group type                                                       *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_read_group_type(uint16_t conn_handle, uint16_t cid,
@@ -693,8 +691,8 @@
 }
 
 /*****************************************************************************
- * $write                                                                    *
- *****************************************************************************/
+* $write                                                                    *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t cid, uint16_t handle,
@@ -769,8 +767,8 @@
 }
 
 /*****************************************************************************
- * $prepare write request                                                    *
- *****************************************************************************/
+* $prepare write request                                                    *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t cid, uint16_t handle,
@@ -852,8 +850,8 @@
 }
 
 /*****************************************************************************
- * $execute write request                                                    *
- *****************************************************************************/
+* $execute write request                                                    *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_exec_write(uint16_t conn_handle, uint16_t cid, uint8_t flags)
@@ -933,8 +931,8 @@
 }
 
 /*****************************************************************************
- * $handle value indication                                                  *
- *****************************************************************************/
+* $handle value indication                                                  *
+*****************************************************************************/
 
 int
 ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t cid,

nimble/host/src/ble_gattc.c

@@ -723,9 +723,9 @@
         }
 
 #if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0
-    if (proc->cid != BLE_L2CAP_CID_ATT) {
-        ble_eatt_release_chan(proc->conn_handle, proc->op);
-    }
+        if (proc->cid != BLE_L2CAP_CID_ATT) {
+            ble_eatt_release_chan(proc->conn_handle, proc->op);
+        }
 #endif
 
 #if MYNEWT_VAL(BLE_HS_DEBUG)

nimble/host/test/src/ble_att_svr_test.c

@@ -1204,31 +1200,34 @@
     TEST_ASSERT(rc == 0);
     ble_hs_test_util_verify_tx_find_info_rsp(
         ((struct ble_hs_test_util_att_info_entry[]) { {
-            .handle = handle1,
-            .uuid = BLE_UUID128_DECLARE(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15),
-        }, {
-            .handle = handle2,
-            .uuid = BLE_UUID128_DECLARE(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),
-        }, {
-            .handle = 0,
-        } }));
+                                                          .handle = handle1,
+                                                          .uuid =
+                                                              BLE_UUID128_DECLARE(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
+            15),
+                                                      }, {
+                                                          .handle = handle2,
+                                                          .uuid =
+                                                              BLE_UUID128_DECLARE(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+            16),
+                                                      }, {
+                                                          .handle = 0,
+                                                      } }));
 
     /*** Remaining 16-bit entry requested. */
     rc = ble_hs_test_util_rx_att_find_info_req(conn_handle, BLE_L2CAP_CID_ATT, handle3, handle3);
     TEST_ASSERT(rc == 0);
     ble_hs_test_util_verify_tx_find_info_rsp(
         ((struct ble_hs_test_util_att_info_entry[]) { {
-            .handle = handle3,
-            .uuid = BLE_UUID16_DECLARE(0x000f),
-        }, {
-            .handle = 0,
-        } }));
+                                                          .handle = handle3,
+                                                          .uuid = BLE_UUID16_DECLARE(0x000f),
+                                                      }, {
+                                                          .handle = 0,
+                                                      } }));
 
     ble_att_svr_test_assert_mbufs_freed();
 }
 
-TEST_CASE_SELF(ble_att_svr_test_find_type_value)
-{
+TEST_CASE_SELF(ble_att_svr_test_find_type_value) {
     uint16_t conn_handle;
     uint16_t handle1;
     uint16_t handle2;

nimble/host/test/src/ble_gatt_find_s_test.c

@@ -250,103 +249,113 @@
     }
 }
 
-TEST_CASE_SELF(ble_gatt_find_s_test_1)
-{
+TEST_CASE_SELF(ble_gatt_find_s_test_1) {
     /* Two 16-bit UUID services; one response. */
     ble_gatt_find_s_test_misc_init();
-    ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+    ble_hs_test_util_create_conn(2, ((uint8_t[]) {2,3,4,5,6,7,8,9}),
                                  NULL, NULL);
     ble_gatt_find_s_test_misc_find_inc(2, BLE_L2CAP_CID_ATT, 5, 10,
-        ((struct ble_gatt_find_s_test_entry[]) { {
-            .inc_handle = 6,
-            .start_handle = 35,
-            .end_handle = 49,
-            .uuid = BLE_UUID16_DECLARE(0x5155),
-        }, {
-            .inc_handle = 9,
-            .start_handle = 543,
-            .end_handle = 870,
-            .uuid = BLE_UUID16_DECLARE(0x1122),
-        }, {
-            0,
-        } })
-    );
+                                       ((struct ble_gatt_find_s_test_entry[]) { {
+                                                                                    .inc_handle = 6,
+                                                                                    .start_handle = 35,
+                                                                                    .end_handle = 49,
+                                                                                    .uuid = BLE_UUID16_DECLARE(0x5155),
+                                                                                }, {
+                                                                                    .inc_handle = 9,
+                                                                                    .start_handle = 543,
+                                                                                    .end_handle = 870,
+                                                                                    .uuid = BLE_UUID16_DECLARE(0x1122),
+                                                                                }, {
+                                                                                    0,
+                                                                                } })
+                                       );
 
     /* One 128-bit UUID service; two responses. */
     ble_gatt_find_s_test_misc_init();
-    ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+    ble_hs_test_util_create_conn(2, ((uint8_t[]) {2,3,4,5,6,7,8,9}),
                                  NULL, NULL);
     ble_gatt_find_s_test_misc_find_inc(2, BLE_L2CAP_CID_ATT, 34, 100,
-        ((struct ble_gatt_find_s_test_entry[]) { {
-            .inc_handle = 36,
-            .start_handle = 403,
-            .end_handle = 859,
-            .uuid = BLE_UUID128_DECLARE(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),
-        }, {
-            0,
-        } })
-    );
+                                       ((struct ble_gatt_find_s_test_entry[]) { {
+                                                                                    .inc_handle = 36,
+                                                                                    .start_handle = 403,
+                                                                                    .end_handle = 859,
+                                                                                    .uuid =
+                                                                                        BLE_UUID128_DECLARE(1,2,3,4,5,
+            6,7,8,9,10,11,12,13,14,15,16),
+                                                                                }, {
+                                                                                    0,
+                                                                                } })
+                                       );
 
     /* Two 128-bit UUID service; four responses. */
     ble_gatt_find_s_test_misc_init();
-    ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+    ble_hs_test_util_create_conn(2, ((uint8_t[]) {2,3,4,5,6,7,8,9}),
                                  NULL, NULL);
     ble_gatt_find_s_test_misc_find_inc(2, BLE_L2CAP_CID_ATT, 34, 100,
-        ((struct ble_gatt_find_s_test_entry[]) { {
-            .inc_handle = 36,
-            .start_handle = 403,
-            .end_handle = 859,
-            .uuid = BLE_UUID128_DECLARE(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),
-        }, {
-            .inc_handle = 39,
-            .start_handle = 900,
-            .end_handle = 932,
-            .uuid = BLE_UUID128_DECLARE(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17),
-        }, {
-            0,
-        } })
-    );
+                                       ((struct ble_gatt_find_s_test_entry[]) { {
+                                                                                    .inc_handle = 36,
+                                                                                    .start_handle = 403,
+                                                                                    .end_handle = 859,
+                                                                                    .uuid =
+                                                                                        BLE_UUID128_DECLARE(1,2,3,4,5,
+            6,7,8,9,10,11,12,13,14,15,16),
+                                                                                }, {
+                                                                                    .inc_handle = 39,
+                                                                                    .start_handle = 900,
+                                                                                    .end_handle = 932,
+                                                                                    .uuid =
+                                                                                        BLE_UUID128_DECLARE(2,3,4,5,6,
+            7,8,9,10,11,12,13,14,15,16,17),
+                                                                                }, {
+                                                                                    0,
+                                                                                } })
+                                       );
 
     /* Two 16-bit UUID; three 128-bit UUID; seven responses. */
     ble_gatt_find_s_test_misc_init();
-    ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+    ble_hs_test_util_create_conn(2, ((uint8_t[]) {2,3,4,5,6,7,8,9}),
                                  NULL, NULL);
     ble_gatt_find_s_test_misc_find_inc(2, BLE_L2CAP_CID_ATT, 1, 100,
-        ((struct ble_gatt_find_s_test_entry[]) { {
-            .inc_handle = 36,
-            .start_handle = 403,
-            .end_handle = 859,
-            .uuid = BLE_UUID128_DECLARE(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),
-        }, {
-            .inc_handle = 37,
-            .start_handle = 35,
-            .end_handle = 49,
-            .uuid = BLE_UUID16_DECLARE(0x5155),
-        }, {
-            .inc_handle = 38,
-            .start_handle = 543,
-            .end_handle = 870,
-            .uuid = BLE_UUID16_DECLARE(0x1122),
-        }, {
-            .inc_handle = 39,
-            .start_handle = 900,
-            .end_handle = 932,
-            .uuid = BLE_UUID128_DECLARE(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17),
-        }, {
-            .inc_handle = 40,
-            .start_handle = 940,
-            .end_handle = 950,
-            .uuid = BLE_UUID128_DECLARE(3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18),
-        }, {
-            0,
-        } })
-    );
+                                       ((struct ble_gatt_find_s_test_entry[]) { {
+                                                                                    .inc_handle = 36,
+                                                                                    .start_handle = 403,
+                                                                                    .end_handle = 859,
+                                                                                    .uuid =
+                                                                                        BLE_UUID128_DECLARE(1,2,3,4,5,
+            6,7,8,9,10,11,12,13,14,15,16),
+                                                                                }, {
+                                                                                    .inc_handle = 37,
+                                                                                    .start_handle = 35,
+                                                                                    .end_handle = 49,
+                                                                                    .uuid = BLE_UUID16_DECLARE(0x5155),
+                                                                                }, {
+                                                                                    .inc_handle = 38,
+                                                                                    .start_handle = 543,
+                                                                                    .end_handle = 870,
+                                                                                    .uuid = BLE_UUID16_DECLARE(0x1122),
+                                                                                }, {
+                                                                                    .inc_handle = 39,
+                                                                                    .start_handle = 900,
+                                                                                    .end_handle = 932,
+                                                                                    .uuid =
+                                                                                        BLE_UUID128_DECLARE(2,3,4,5,6,
+            7,8,9,10,11,12,13,14,15,16,17),
+                                                                                }, {
+                                                                                    .inc_handle = 40,
+                                                                                    .start_handle = 940,
+                                                                                    .end_handle = 950,
+                                                                                    .uuid =
+                                                                                        BLE_UUID128_DECLARE(3,4,5,6,7,
+            8,9,10,11,12,13,14,15,16,17,18),
+                                                                                }, {
+                                                                                    0,
+                                                                                } })
+                                       );
 
     ble_hs_test_util_assert_mbufs_freed(NULL);
 }
 
-TEST_CASE_SELF(ble_gatt_find_s_test_oom)
-{
+TEST_CASE_SELF(ble_gatt_find_s_test_oom) {
 
     struct ble_gatt_find_s_test_entry incs[] = {
         {

apache-mynewt-bot avatar Jun 15 '20 17:06 apache-mynewt-bot

this was superseded by https://github.com/apache/mynewt-nimble/pull/1549

KKopyscinski avatar Aug 04 '23 11:08 KKopyscinski