You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/27 07:13:27 UTC

incubator-mynewt-larva git commit: bleshell:Fix some notification / indication issues

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 162c23506 -> 0e324d9e2


bleshell:Fix some notification / indication issues


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/0e324d9e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/0e324d9e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/0e324d9e

Branch: refs/heads/master
Commit: 0e324d9e2879515bfcc9dd31a5e487c5c901915a
Parents: 162c235
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 27 01:08:52 2016 -0500
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 27 01:08:52 2016 -0500

----------------------------------------------------------------------
 project/bleshell/src/periph.c | 169 ++++++++-----------------------------
 1 file changed, 33 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/0e324d9e/project/bleshell/src/periph.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/periph.c b/project/bleshell/src/periph.c
index cf2b3e5..5239c08 100644
--- a/project/bleshell/src/periph.c
+++ b/project/bleshell/src/periph.c
@@ -39,9 +39,6 @@ periph_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
 static int
 periph_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                         union ble_gatt_access_ctxt *ctxt, void *arg);
-static int
-periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-               union ble_gatt_access_ctxt *ctxt, void *arg);
 
 static const struct ble_gatt_svc_def periph_svcs[] = {
     [0] = {
@@ -119,43 +116,6 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
             0, /* No more characteristics in this service. */
         } },
     },
-    [3] = {
-        /*** Service 0x1234. */
-        .type = BLE_GATT_SVC_TYPE_SECONDARY,
-        .uuid128 = BLE_UUID16(PERIPH_SVC1_UUID),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic 0x1111. */
-            .uuid128 = BLE_UUID16(PERIPH_CHR1_UUID),
-            .access_cb = periph_gatt_cb,
-            .flags = CHR_F_FULL_ACCESS,
-        }, {
-            /*** Characteristic 0x1112. */
-            .uuid128 = BLE_UUID16(PERIPH_CHR2_UUID),
-            .access_cb = periph_gatt_cb,
-            .flags = CHR_F_FULL_ACCESS,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
-    [4] = {
-        /*** Service 0x5678. */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid128 = BLE_UUID16(PERIPH_SVC2_UUID),
-        .includes = (const struct ble_gatt_svc_def *[]) {
-            &periph_svcs[3],
-            NULL,
-        },
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic 0x5555. */
-            .uuid128 = BLE_UUID16(PERIPH_CHR3_UUID),
-            .access_cb = periph_gatt_cb,
-            .flags = CHR_F_FULL_ACCESS,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
     {
         0, /* No more services. */
     },
@@ -179,74 +139,6 @@ periph_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
 }
 
 static int
-periph_gatt_read(uint16_t attr_handle, union ble_gatt_access_ctxt *ctxt,
-                 void *arg)
-{
-    uint16_t uuid16;
-    int idx;
-
-    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
-    switch (uuid16) {
-    case PERIPH_CHR1_UUID:
-        idx = 0;
-        break;
-
-    case PERIPH_CHR2_UUID:
-        idx = 1;
-        break;
-
-    case PERIPH_CHR3_UUID:
-        idx = 2;
-        break;
-
-    default:
-        assert(0);
-        break;
-    }
-
-    ctxt->chr_access.data = periph_chr_data[idx];
-    ctxt->chr_access.len = periph_chr_lens[idx];
-
-    return 0;
-}
-
-static int
-periph_gatt_write(uint16_t attr_handle, union ble_gatt_access_ctxt *ctxt,
-                  void *arg)
-{
-    uint16_t uuid16;
-    int idx;
-
-    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
-    switch (uuid16) {
-    case PERIPH_CHR1_UUID:
-        idx = 0;
-        break;
-
-    case PERIPH_CHR2_UUID:
-        idx = 1;
-        break;
-
-    case PERIPH_CHR3_UUID:
-        idx = 2;
-        break;
-
-    default:
-        assert(0);
-        break;
-    }
-
-    if (ctxt->chr_access.len > sizeof periph_chr_data[idx]) {
-        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
-    }
-
-    memcpy(periph_chr_data[idx], ctxt->chr_access.data, ctxt->chr_access.len);
-    periph_chr_lens[idx] = ctxt->chr_access.len;
-
-    return 0;
-}
-
-static int
 periph_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
                       union ble_gatt_access_ctxt *ctxt, void *arg)
 {
@@ -307,13 +199,17 @@ periph_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
     assert(uuid16 != 0);
 
     switch (uuid16) {
-    case BLE_GAP_CHR_UUID16_DEVICE_NAME:
-        assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
-        if (ctxt->chr_access.len != sizeof bleshell_gatt_service_changed) {
-            return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    case BLE_GATT_CHR_SERVICE_CHANGED_UUID16:
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            if (ctxt->chr_access.len != sizeof bleshell_gatt_service_changed) {
+                return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+            }
+            memcpy(bleshell_gatt_service_changed, ctxt->chr_access.data,
+                   sizeof bleshell_gatt_service_changed);
+        } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
+            ctxt->chr_access.data = (void *)&bleshell_gatt_service_changed;
+            ctxt->chr_access.len = sizeof bleshell_gatt_service_changed;
         }
-        memcpy(bleshell_gatt_service_changed, ctxt->chr_access.data,
-               sizeof bleshell_gatt_service_changed);
         break;
 
     default:
@@ -351,9 +247,16 @@ periph_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
         return 0;
 
     case PERIPH_CHR_NEW_ALERT:
-        rc = periph_chr_write(op, ctxt, 0, sizeof periph_new_alert_val,
-                              periph_new_alert_val, &periph_new_alert_val_len);
-        return rc;
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = periph_chr_write(op, ctxt, 0, sizeof periph_new_alert_val,
+                                  periph_new_alert_val,
+                                  &periph_new_alert_val_len);
+            return rc;
+        } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
+            ctxt->chr_access.data = (void *)&periph_new_alert_val;
+            ctxt->chr_access.len = sizeof periph_new_alert_val;
+            return 0;
+        }
 
     case PERIPH_CHR_SUP_UNR_ALERT_CAT_UUID:
         assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
@@ -362,11 +265,22 @@ periph_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
         return 0;
 
     case PERIPH_CHR_UNR_ALERT_STAT_UUID:
-        rc = periph_chr_write(op, ctxt, 2, 2, &periph_unr_alert_stat, NULL);
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = periph_chr_write(op, ctxt, 2, 2, &periph_unr_alert_stat, NULL);
+        } else {
+            ctxt->chr_access.data = (void *)&periph_unr_alert_stat;
+            ctxt->chr_access.len = sizeof periph_unr_alert_stat;
+            rc = 0;
+        }
         return rc;
 
     case PERIPH_CHR_ALERT_NOT_CTRL_PT:
-        rc = periph_chr_write(op, ctxt, 2, 2, &periph_alert_not_ctrl_pt, NULL);
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = periph_chr_write(op, ctxt, 2, 2, &periph_alert_not_ctrl_pt,
+                                  NULL);
+        } else {
+            rc = BLE_ATT_ERR_UNLIKELY;
+        }
         return rc;
 
     default:
@@ -375,23 +289,6 @@ periph_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
     }
 }
 
-static int
-periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
-               union ble_gatt_access_ctxt *ctxt, void *arg)
-{
-    switch (op) {
-    case BLE_GATT_ACCESS_OP_READ_CHR:
-        return periph_gatt_read(attr_handle, ctxt, arg);
-
-    case BLE_GATT_ACCESS_OP_WRITE_CHR:
-        return periph_gatt_write(attr_handle, ctxt, arg);
-
-    default:
-        assert(0);
-        return -1;
-    }
-}
-
 static void
 periph_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
 {