BLE Host - fix bug caused by outdated code. The ble store code used to expect a key and value as arguments to a write operation. Now it just expects a value.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/54a4b7f1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/54a4b7f1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/54a4b7f1 Branch: refs/heads/develop Commit: 54a4b7f17ae444fa67e6a5547642fd8b3b47b4a8 Parents: 6866ef9 Author: Christopher Collins <[email protected]> Authored: Tue May 24 14:23:45 2016 -0700 Committer: Christopher Collins <[email protected]> Committed: Tue May 24 14:24:42 2016 -0700 ---------------------------------------------------------------------- net/nimble/host/include/host/ble_store.h | 3 +++ net/nimble/host/src/ble_gatts.c | 35 ++++++++++++--------------- net/nimble/host/src/ble_store.c | 12 +++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/54a4b7f1/net/nimble/host/include/host/ble_store.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_store.h b/net/nimble/host/include/host/ble_store.h index 1bb27d5..8edbb01 100644 --- a/net/nimble/host/include/host/ble_store.h +++ b/net/nimble/host/include/host/ble_store.h @@ -93,4 +93,7 @@ int ble_store_read_cccd(struct ble_store_key_cccd *key, int ble_store_write_cccd(struct ble_store_value_cccd *value); int ble_store_delete_cccd(struct ble_store_key_cccd *key); +void ble_store_key_from_value_cccd(struct ble_store_key_cccd *out_key, + struct ble_store_value_cccd *value); + #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/54a4b7f1/net/nimble/host/src/ble_gatts.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c index 2464fe8..149b1bc 100644 --- a/net/nimble/host/src/ble_gatts.c +++ b/net/nimble/host/src/ble_gatts.c @@ -527,17 +527,11 @@ ble_gatts_clt_cfg_find(struct ble_gatts_clt_cfg *cfgs, } } -struct ble_gatts_clt_cfg_record { - unsigned write:1; - struct ble_store_key_cccd key; - struct ble_store_value_cccd value; -}; - static int ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle, uint8_t *uuid128, uint8_t att_op, struct ble_att_svr_access_ctxt *ctxt, - struct ble_gatts_clt_cfg_record *out_record) + struct ble_store_value_cccd *out_cccd) { struct ble_gatts_clt_cfg *clt_cfg; uint16_t chr_val_handle; @@ -547,7 +541,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle, static uint8_t buf[2]; /* Assume nothing needs to be persisted. */ - out_record->write = 0; + out_cccd->chr_val_handle = 0; /* We always register the client characteristics descriptor with handle * (chr_val + 1). @@ -590,12 +584,11 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle, /* Successful writes get persisted for bonded connections. */ if (conn->bhc_sec_state.bonded) { - out_record->key.peer_addr_type = conn->bhc_addr_type; - memcpy(out_record->key.peer_addr, conn->bhc_addr, 6); - out_record->value.chr_val_handle = chr_val_handle; - out_record->value.flags = clt_cfg->flags; - out_record->value.value_changed = 0; - out_record->write = 1; + out_cccd->peer_addr_type = conn->bhc_addr_type; + memcpy(out_cccd->peer_addr, conn->bhc_addr, 6); + out_cccd->chr_val_handle = chr_val_handle; + out_cccd->flags = clt_cfg->flags; + out_cccd->value_changed = 0; } break; @@ -613,7 +606,8 @@ ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle, struct ble_att_svr_access_ctxt *ctxt, void *arg) { - struct ble_gatts_clt_cfg_record persist_record; + struct ble_store_value_cccd cccd_value; + struct ble_store_key_cccd cccd_key; struct ble_hs_conn *conn; int rc; @@ -624,16 +618,17 @@ ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle, rc = BLE_ATT_ERR_UNLIKELY; } else { rc = ble_gatts_clt_cfg_access_locked(conn, attr_handle, uuid128, op, - ctxt, &persist_record); + ctxt, &cccd_value); } ble_hs_unlock(); - if (rc == 0 && persist_record.write) { - if (persist_record.value.flags == 0) { - rc = ble_store_delete_cccd(&persist_record.key); + if (rc == 0 && cccd_value.chr_val_handle != 0) { + if (cccd_value.flags == 0) { + ble_store_key_from_value_cccd(&cccd_key, &cccd_value); + rc = ble_store_delete_cccd(&cccd_key); } else { - rc = ble_store_write_cccd(&persist_record.value); + rc = ble_store_write_cccd(&cccd_value); } } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/54a4b7f1/net/nimble/host/src/ble_store.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_store.c b/net/nimble/host/src/ble_store.c index 940a2d0..24480c1 100644 --- a/net/nimble/host/src/ble_store.c +++ b/net/nimble/host/src/ble_store.c @@ -17,6 +17,8 @@ * under the License. */ +#include <string.h> + #include "host/ble_store.h" #include "ble_hs_priv.h" @@ -98,3 +100,13 @@ ble_store_delete_cccd(struct ble_store_key_cccd *key) rc = ble_store_delete(BLE_STORE_OBJ_TYPE_CCCD, store_key); return rc; } + +void +ble_store_key_from_value_cccd(struct ble_store_key_cccd *out_key, + struct ble_store_value_cccd *value) +{ + out_key->peer_addr_type = value->peer_addr_type; + memcpy(out_key->peer_addr, value->peer_addr, 6); + out_key->chr_val_handle = value->chr_val_handle; + out_key->idx = 0; +}
