Repository: incubator-mynewt-larva Updated Branches: refs/heads/master 31f0c10b6 -> bf65252ed
Add calls to os_mbuf_pullup; more GATT. 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/bf65252e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/bf65252e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/bf65252e Branch: refs/heads/master Commit: bf65252ed86acd84ab3f1219ae1fbd2ddbb31c58 Parents: 31f0c10 Author: Christopher Collins <ccollins47...@gmail.com> Authored: Thu Dec 3 14:33:06 2015 -0800 Committer: Christopher Collins <ccollins47...@gmail.com> Committed: Thu Dec 3 14:33:06 2015 -0800 ---------------------------------------------------------------------- net/nimble/host/include/host/ble_gatt.h | 18 ++ net/nimble/host/src/ble_att.c | 8 +- net/nimble/host/src/ble_att.h | 34 ++-- net/nimble/host/src/ble_att_clt.c | 204 ++++---------------- net/nimble/host/src/ble_att_cmd.c | 74 ++++--- net/nimble/host/src/ble_att_cmd.h | 4 +- net/nimble/host/src/ble_att_svr.c | 115 ++++++----- net/nimble/host/src/ble_gatt.c | 110 ++++++++++- net/nimble/host/src/ble_hs.c | 5 - net/nimble/host/src/ble_hs_conn.c | 2 - net/nimble/host/src/ble_l2cap.c | 2 +- net/nimble/host/src/ble_l2cap.h | 2 +- net/nimble/host/src/ble_l2cap_sig.c | 2 +- net/nimble/host/src/test/ble_hs_att_clt_test.c | 32 +-- net/nimble/host/src/test/ble_hs_att_svr_test.c | 2 +- 15 files changed, 277 insertions(+), 337 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/include/host/ble_gatt.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h index d1d6084..de1fc73 100644 --- a/net/nimble/host/include/host/ble_gatt.h +++ b/net/nimble/host/include/host/ble_gatt.h @@ -4,6 +4,21 @@ #include <inttypes.h> struct ble_hs_conn; struct ble_att_error_rsp; +struct ble_att_clt_adata; + +struct ble_gatt_service { + uint16_t start_handle; + uint16_t end_handle; + uint8_t uuid128[16]; +}; + +typedef int ble_gatt_disc_service_fn(uint16_t conn_handle, + struct ble_att_clt_adata *adata, + void *arg); + +int ble_gatt_disc_all_services(uint16_t conn_handle, + ble_gatt_disc_service_fn *cb, + void *cb_arg); void ble_gatt_rx_error(struct ble_hs_conn *conn, struct ble_att_error_rsp *rsp); @@ -12,6 +27,9 @@ void ble_gatt_rx_mtu(struct ble_hs_conn *conn, uint16_t chan_mtu); int ble_gatt_mtu(uint16_t conn_handle); void ble_gatt_rx_find_info(struct ble_hs_conn *conn, int status, uint16_t last_handle_id); +void ble_gatt_rx_read_group_type_adata(struct ble_hs_conn *conn, + struct ble_att_clt_adata *adata); +void ble_gatt_rx_read_group_type_complete(struct ble_hs_conn *conn, int rc); int ble_gatt_find_info(uint16_t conn_handle_id, uint16_t att_start_handle, uint16_t att_end_handle); int ble_gatt_init(void); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_att.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c index 3d2dc7a..1f63ac6 100644 --- a/net/nimble/host/src/ble_att.c +++ b/net/nimble/host/src/ble_att.c @@ -22,8 +22,8 @@ /** Dispatch table for incoming ATT requests. Sorted by op code. */ typedef int ble_att_rx_fn(struct ble_hs_conn *conn, - struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct ble_l2cap_chan *chan, + struct os_mbuf **om); struct ble_att_rx_dispatch_entry { uint8_t bde_op; ble_att_rx_fn *bde_fn; @@ -65,13 +65,13 @@ ble_att_rx_dispatch_entry_find(uint8_t op) static int ble_att_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **om) { struct ble_att_rx_dispatch_entry *entry; uint8_t op; int rc; - rc = os_mbuf_copydata(om, 0, 1, &op); + rc = os_mbuf_copydata(*om, 0, 1, &op); if (rc != 0) { return EMSGSIZE; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_att.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att.h b/net/nimble/host/src/ble_att.h index c14fca0..8a522b5 100644 --- a/net/nimble/host/src/ble_att.h +++ b/net/nimble/host/src/ble_att.h @@ -103,10 +103,10 @@ struct ble_att_svr_entry { #define HA_OPCODE_COMMAND_FLAG (1 << 6) #define HA_OPCODE_AUTH_SIG_FLAG (1 << 7) -struct ble_att_clt_entry { - SLIST_ENTRY(ble_att_clt_entry) bhac_next; - uint16_t bhac_handle_id; - uint8_t bhac_uuid[16]; +struct ble_att_clt_adata { + uint16_t att_handle; + uint16_t end_group_handle; + void *value; }; SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry); @@ -121,46 +121,38 @@ int ble_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id, int ble_att_svr_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_svr_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_svr_rx_find_type_value(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_svr_rx_read_type(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_svr_init(void); /*** @clt */ -void ble_att_clt_entry_list_free(struct ble_att_clt_entry_list *list); -int ble_att_clt_entry_insert(struct ble_hs_conn *conn, uint16_t handle_id, - uint8_t *uuid); -uint16_t ble_att_clt_find_entry_uuid128(struct ble_hs_conn *conn, - void *uuid128); -uint16_t ble_att_clt_find_entry_uuid16(struct ble_hs_conn *conn, - uint16_t uuid16); int ble_att_clt_tx_mtu(struct ble_hs_conn *conn, struct ble_att_mtu_cmd *req); int ble_att_clt_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); int ble_att_clt_tx_read(struct ble_hs_conn *conn, struct ble_att_read_req *req); int ble_att_clt_tx_find_info(struct ble_hs_conn *conn, struct ble_att_find_info_req *req); int ble_att_clt_rx_find_info(struct ble_hs_conn *conn, - struct ble_l2cap_chan *chan, struct os_mbuf *om); + struct ble_l2cap_chan *chan, struct os_mbuf **om); int ble_att_clt_tx_read_group_type(struct ble_hs_conn *conn, struct ble_att_read_group_type_req *req, void *uuid128); int ble_att_clt_rx_read_group_type_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); -int ble_att_clt_init(void); + struct os_mbuf **om); #endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_att_clt.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c index 6fe6a57..7fe36a6 100644 --- a/net/nimble/host/src/ble_att_clt.c +++ b/net/nimble/host/src/ble_att_clt.c @@ -27,98 +27,6 @@ #include "ble_att_cmd.h" #include "ble_att.h" -#define BLE_ATT_CLT_NUM_ENTRIES 128 -static void *ble_att_clt_entry_mem; -static struct os_mempool ble_att_clt_entry_pool; - -static struct ble_att_clt_entry * -ble_att_clt_entry_alloc(void) -{ - struct ble_att_clt_entry *entry; - - entry = os_memblock_get(&ble_att_clt_entry_pool); - if (entry != NULL) { - memset(entry, 0, sizeof *entry); - } - - return entry; -} - -static void -ble_att_clt_entry_free(struct ble_att_clt_entry *entry) -{ - int rc; - - rc = os_memblock_put(&ble_att_clt_entry_pool, entry); - assert(rc == 0); -} - -void -ble_att_clt_entry_list_free(struct ble_att_clt_entry_list *list) -{ - struct ble_att_clt_entry *entry; - - while ((entry = SLIST_FIRST(list)) != NULL) { - SLIST_REMOVE_HEAD(list, bhac_next); - ble_att_clt_entry_free(entry); - } -} - -int -ble_att_clt_entry_insert(struct ble_hs_conn *conn, uint16_t handle_id, - uint8_t *uuid) -{ - struct ble_att_clt_entry *entry; - struct ble_att_clt_entry *prev; - struct ble_att_clt_entry *cur; - - /* XXX: Probably need to lock a semaphore here. */ - - entry = ble_att_clt_entry_alloc(); - if (entry == NULL) { - return ENOMEM; - } - - entry->bhac_handle_id = handle_id; - memcpy(entry->bhac_uuid, uuid, sizeof entry->bhac_uuid); - - prev = NULL; - SLIST_FOREACH(cur, &conn->bhc_att_clt_list, bhac_next) { - if (cur->bhac_handle_id == handle_id) { - return EEXIST; - } - if (cur->bhac_handle_id > handle_id) { - break; - } - - prev = cur; - } - - if (prev == NULL) { - SLIST_INSERT_HEAD(&conn->bhc_att_clt_list, entry, bhac_next); - } else { - SLIST_INSERT_AFTER(prev, entry, bhac_next); - } - - return 0; -} - -uint16_t -ble_att_clt_find_entry_uuid128(struct ble_hs_conn *conn, void *uuid128) -{ - struct ble_att_clt_entry *entry; - int rc; - - SLIST_FOREACH(entry, &conn->bhc_att_clt_list, bhac_next) { - rc = memcmp(entry->bhac_uuid, uuid128, 16); - if (rc == 0) { - return entry->bhac_handle_id; - } - } - - return 0; -} - static int ble_att_clt_prep_req(struct ble_hs_conn *conn, struct ble_l2cap_chan **chan, struct os_mbuf **txom, uint16_t initial_sz) @@ -152,22 +60,6 @@ err: return rc; } -uint16_t -ble_att_clt_find_entry_uuid16(struct ble_hs_conn *conn, uint16_t uuid16) -{ - uint8_t uuid128[16]; - uint16_t handle_id; - int rc; - - rc = ble_hs_uuid_from_16bit(uuid16, uuid128); - if (rc != 0) { - return 0; - } - - handle_id = ble_att_clt_find_entry_uuid128(conn, uuid128); - return handle_id; -} - int ble_att_clt_tx_mtu(struct ble_hs_conn *conn, struct ble_att_mtu_cmd *req) { @@ -207,14 +99,17 @@ err: int ble_att_clt_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **om) { struct ble_att_mtu_cmd rsp; int rc; - /* XXX: Pull up om */ + *om = os_mbuf_pullup(*om, BLE_ATT_MTU_CMD_SZ); + if (*om == NULL) { + return ENOMEM; + } - rc = ble_att_mtu_cmd_parse(om->om_data, om->om_len, &rsp); + rc = ble_att_mtu_cmd_parse((*om)->om_data, (*om)->om_len, &rsp); if (rc != 0) { return rc; } @@ -269,26 +164,31 @@ err: int ble_att_clt_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **om) { struct ble_att_find_info_rsp rsp; + struct os_mbuf *rxom; uint16_t handle_id; uint16_t uuid16; uint8_t uuid128[16]; int off; int rc; - /* XXX: Pull up om */ + *om = os_mbuf_pullup(*om, BLE_ATT_FIND_INFO_RSP_BASE_SZ); + if (*om == NULL) { + return ENOMEM; + } - rc = ble_att_find_info_rsp_parse(om->om_data, om->om_len, &rsp); + rc = ble_att_find_info_rsp_parse((*om)->om_data, (*om)->om_len, &rsp); if (rc != 0) { return rc; } + rxom = *om; handle_id = 0; - off = BLE_ATT_FIND_INFO_RSP_MIN_SZ; - while (off < OS_MBUF_PKTHDR(om)->omp_len) { - rc = os_mbuf_copydata(om, off, 2, &handle_id); + off = BLE_ATT_FIND_INFO_RSP_BASE_SZ; + while (off < OS_MBUF_PKTHDR(rxom)->omp_len) { + rc = os_mbuf_copydata(rxom, off, 2, &handle_id); if (rc != 0) { rc = EINVAL; goto done; @@ -298,7 +198,7 @@ ble_att_clt_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, switch (rsp.bhafp_format) { case BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT: - rc = os_mbuf_copydata(om, off, 2, &uuid16); + rc = os_mbuf_copydata(rxom, off, 2, &uuid16); if (rc != 0) { rc = EINVAL; goto done; @@ -314,7 +214,7 @@ ble_att_clt_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, break; case BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT: - rc = os_mbuf_copydata(om, off, 16, &uuid128); + rc = os_mbuf_copydata(rxom, off, 16, &uuid128); if (rc != 0) { rc = EINVAL; goto done; @@ -326,11 +226,6 @@ ble_att_clt_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, rc = EINVAL; goto done; } - - rc = ble_att_clt_entry_insert(conn, handle_id, uuid128); - if (rc != 0) { - return rc; - } } rc = 0; @@ -425,12 +320,6 @@ err: return rc; } -struct ble_att_clt_adata { - uint16_t att_handle; - uint16_t end_group_handle; - void *value; -}; - static int ble_att_clt_parse_attribute_data(struct os_mbuf *om, int data_len, struct ble_att_clt_adata *adata) @@ -447,65 +336,40 @@ ble_att_clt_parse_attribute_data(struct os_mbuf *om, int data_len, int ble_att_clt_rx_read_group_type_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **rxom) { struct ble_att_read_group_type_rsp rsp; struct ble_att_clt_adata adata; int rc; - /* XXX: Pull up om */ + *rxom = os_mbuf_pullup(*rxom, BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ); + if (*rxom == NULL) { + return ENOMEM; + } - rc = ble_att_read_group_type_rsp_parse(om->om_data, om->om_len, &rsp); + rc = ble_att_read_group_type_rsp_parse((*rxom)->om_data, (*rxom)->om_len, + &rsp); if (rc != 0) { return rc; } + os_mbuf_adj(*rxom, BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ); + /* XXX: Verify group handle is valid. */ - while (OS_MBUF_PKTHDR(om)->omp_len > 0) { - rc = ble_att_clt_parse_attribute_data(om, rsp.bhagp_length, &adata); + while (OS_MBUF_PKTLEN(*rxom) > 0) { + rc = ble_att_clt_parse_attribute_data(*rxom, rsp.bhagp_length, &adata); if (rc != 0) { break; } - /* Save attribute mapping? */ - - /* XXX: Pass adata to GATT callback. */ - - os_mbuf_adj(om, rsp.bhagp_length); - } - - return 0; -} - -int -ble_att_clt_init(void) -{ - int rc; + /* Pass attribute data to GATT callback. */ + ble_gatt_rx_read_group_type_adata(conn, &adata); - free(ble_att_clt_entry_mem); - ble_att_clt_entry_mem = malloc( - OS_MEMPOOL_BYTES(BLE_ATT_CLT_NUM_ENTRIES, - sizeof (struct ble_att_clt_entry))); - if (ble_att_clt_entry_mem == NULL) { - rc = ENOMEM; - goto err; + os_mbuf_adj(*rxom, rsp.bhagp_length); } - rc = os_mempool_init(&ble_att_clt_entry_pool, - BLE_ATT_CLT_NUM_ENTRIES, - sizeof (struct ble_att_clt_entry), - ble_att_clt_entry_mem, - "ble_att_clt_entry_pool"); - if (rc != 0) { - goto err; - } + ble_gatt_rx_read_group_type_complete(conn, rc); return 0; - -err: - free(ble_att_clt_entry_mem); - ble_att_clt_entry_mem = NULL; - - return rc; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_att_cmd.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_cmd.c b/net/nimble/host/src/ble_att_cmd.c index 72306dd..87ade7b 100644 --- a/net/nimble/host/src/ble_att_cmd.c +++ b/net/nimble/host/src/ble_att_cmd.c @@ -23,8 +23,7 @@ #include "ble_att_cmd.h" int -ble_att_error_rsp_parse(void *payload, int len, - struct ble_att_error_rsp *rsp) +ble_att_error_rsp_parse(void *payload, int len, struct ble_att_error_rsp *rsp) { uint8_t *u8ptr; @@ -46,8 +45,7 @@ ble_att_error_rsp_parse(void *payload, int len, } int -ble_att_error_rsp_write(void *payload, int len, - struct ble_att_error_rsp *rsp) +ble_att_error_rsp_write(void *payload, int len, struct ble_att_error_rsp *rsp) { uint8_t *u8ptr; @@ -66,8 +64,7 @@ ble_att_error_rsp_write(void *payload, int len, } int -ble_att_mtu_cmd_parse(void *payload, int len, - struct ble_att_mtu_cmd *cmd) +ble_att_mtu_cmd_parse(void *payload, int len, struct ble_att_mtu_cmd *cmd) { uint8_t *u8ptr; @@ -90,7 +87,7 @@ ble_att_mtu_cmd_parse(void *payload, int len, int ble_att_mtu_req_write(void *payload, int len, - struct ble_att_mtu_cmd *cmd) + struct ble_att_mtu_cmd *cmd) { uint8_t *u8ptr; @@ -107,8 +104,7 @@ ble_att_mtu_req_write(void *payload, int len, } int -ble_att_mtu_rsp_write(void *payload, int len, - struct ble_att_mtu_cmd *cmd) +ble_att_mtu_rsp_write(void *payload, int len, struct ble_att_mtu_cmd *cmd) { uint8_t *u8ptr; @@ -126,7 +122,7 @@ ble_att_mtu_rsp_write(void *payload, int len, int ble_att_find_info_req_parse(void *payload, int len, - struct ble_att_find_info_req *req) + struct ble_att_find_info_req *req) { uint8_t *u8ptr; @@ -148,7 +144,7 @@ ble_att_find_info_req_parse(void *payload, int len, int ble_att_find_info_req_write(void *payload, int len, - struct ble_att_find_info_req *req) + struct ble_att_find_info_req *req) { uint8_t *u8ptr; @@ -167,11 +163,11 @@ ble_att_find_info_req_write(void *payload, int len, int ble_att_find_info_rsp_parse(void *payload, int len, - struct ble_att_find_info_rsp *rsp) + struct ble_att_find_info_rsp *rsp) { uint8_t *u8ptr; - if (len < BLE_ATT_FIND_INFO_RSP_MIN_SZ) { + if (len < BLE_ATT_FIND_INFO_RSP_BASE_SZ) { return EMSGSIZE; } @@ -188,11 +184,11 @@ ble_att_find_info_rsp_parse(void *payload, int len, int ble_att_find_info_rsp_write(void *payload, int len, - struct ble_att_find_info_rsp *rsp) + struct ble_att_find_info_rsp *rsp) { uint8_t *u8ptr; - if (len < BLE_ATT_FIND_INFO_RSP_MIN_SZ) { + if (len < BLE_ATT_FIND_INFO_RSP_BASE_SZ) { return EMSGSIZE; } @@ -205,8 +201,8 @@ ble_att_find_info_rsp_write(void *payload, int len, } int -ble_att_find_type_value_req_parse( - void *payload, int len, struct ble_att_find_type_value_req *req) +ble_att_find_type_value_req_parse(void *payload, int len, + struct ble_att_find_type_value_req *req) { uint8_t *u8ptr; @@ -228,8 +224,8 @@ ble_att_find_type_value_req_parse( } int -ble_att_find_type_value_req_write( - void *payload, int len, struct ble_att_find_type_value_req *req) +ble_att_find_type_value_req_write(void *payload, int len, + struct ble_att_find_type_value_req *req) { uint8_t *u8ptr; @@ -249,11 +245,11 @@ ble_att_find_type_value_req_write( int ble_att_read_type_req_parse(void *payload, int len, - struct ble_att_read_type_req *req) + struct ble_att_read_type_req *req) { uint8_t *u8ptr; - if (len < BLE_ATT_READ_TYPE_REQ_MIN_SZ) { + if (len < BLE_ATT_READ_TYPE_REQ_BASE_SZ) { return EMSGSIZE; } @@ -271,11 +267,11 @@ ble_att_read_type_req_parse(void *payload, int len, int ble_att_read_type_req_write(void *payload, int len, - struct ble_att_read_type_req *req) + struct ble_att_read_type_req *req) { uint8_t *u8ptr; - if (len < BLE_ATT_READ_TYPE_REQ_MIN_SZ) { + if (len < BLE_ATT_READ_TYPE_REQ_BASE_SZ) { return EMSGSIZE; } @@ -290,7 +286,7 @@ ble_att_read_type_req_write(void *payload, int len, int ble_att_read_type_rsp_parse(void *payload, int len, - struct ble_att_read_type_rsp *rsp) + struct ble_att_read_type_rsp *rsp) { uint8_t *u8ptr; @@ -307,7 +303,7 @@ ble_att_read_type_rsp_parse(void *payload, int len, int ble_att_read_type_rsp_write(void *payload, int len, - struct ble_att_read_type_rsp *rsp) + struct ble_att_read_type_rsp *rsp) { uint8_t *u8ptr; @@ -324,8 +320,7 @@ ble_att_read_type_rsp_write(void *payload, int len, } int -ble_att_read_req_parse(void *payload, int len, - struct ble_att_read_req *req) +ble_att_read_req_parse(void *payload, int len, struct ble_att_read_req *req) { uint8_t *u8ptr; @@ -345,8 +340,7 @@ ble_att_read_req_parse(void *payload, int len, } int -ble_att_read_req_write(void *payload, int len, - struct ble_att_read_req *req) +ble_att_read_req_write(void *payload, int len, struct ble_att_read_req *req) { uint8_t *u8ptr; @@ -363,8 +357,8 @@ ble_att_read_req_write(void *payload, int len, } int -ble_att_read_group_type_req_parse( - void *payload, int len, struct ble_att_read_group_type_req *req) +ble_att_read_group_type_req_parse(void *payload, int len, + struct ble_att_read_group_type_req *req) { uint8_t *u8ptr; @@ -385,8 +379,8 @@ ble_att_read_group_type_req_parse( } int -ble_att_read_group_type_req_write( - void *payload, int len, struct ble_att_read_group_type_req *req) +ble_att_read_group_type_req_write(void *payload, int len, + struct ble_att_read_group_type_req *req) { uint8_t *u8ptr; @@ -404,8 +398,8 @@ ble_att_read_group_type_req_write( } int -ble_att_read_group_type_rsp_parse( - void *payload, int len, struct ble_att_read_group_type_rsp *rsp) +ble_att_read_group_type_rsp_parse(void *payload, int len, + struct ble_att_read_group_type_rsp *rsp) { uint8_t *u8ptr; @@ -425,8 +419,8 @@ ble_att_read_group_type_rsp_parse( } int -ble_att_read_group_type_rsp_write( - void *payload, int len, struct ble_att_read_group_type_rsp *rsp) +ble_att_read_group_type_rsp_write(void *payload, int len, + struct ble_att_read_group_type_rsp *rsp) { uint8_t *u8ptr; @@ -443,8 +437,7 @@ ble_att_read_group_type_rsp_write( } int -ble_att_write_req_parse(void *payload, int len, - struct ble_att_write_req *req) +ble_att_write_req_parse(void *payload, int len, struct ble_att_write_req *req) { uint8_t *u8ptr; @@ -464,8 +457,7 @@ ble_att_write_req_parse(void *payload, int len, } int -ble_att_write_req_write(void *payload, int len, - struct ble_att_write_req *req) +ble_att_write_req_write(void *payload, int len, struct ble_att_write_req *req) { uint8_t *u8ptr; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_att_cmd.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_cmd.h b/net/nimble/host/src/ble_att_cmd.h index 062a057..f6ab782 100644 --- a/net/nimble/host/src/ble_att_cmd.h +++ b/net/nimble/host/src/ble_att_cmd.h @@ -79,7 +79,7 @@ struct ble_att_find_info_req { * | Format | 1 | * | Information Data | 4 to (ATT_MTU-2) | */ -#define BLE_ATT_FIND_INFO_RSP_MIN_SZ 2 +#define BLE_ATT_FIND_INFO_RSP_BASE_SZ 2 struct ble_att_find_info_rsp { uint8_t bhafp_format; /* Followed by information data. */ @@ -120,7 +120,7 @@ struct ble_att_find_type_value_req { * | Ending Handle | 2 | * | Attribute Type | 2 or 16 | */ -#define BLE_ATT_READ_TYPE_REQ_MIN_SZ 7 +#define BLE_ATT_READ_TYPE_REQ_BASE_SZ 5 #define BLE_ATT_READ_TYPE_REQ_SZ_16 7 #define BLE_ATT_READ_TYPE_REQ_SZ_128 21 struct ble_att_read_type_req { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_att_svr.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c index 39c8cc2..90d3e3b 100644 --- a/net/nimble/host/src/ble_att_svr.c +++ b/net/nimble/host/src/ble_att_svr.c @@ -351,19 +351,21 @@ err: int ble_att_svr_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **om) { struct ble_att_mtu_cmd cmd; int rc; - /* XXX: Pull up om. */ + *om = os_mbuf_pullup(*om, BLE_ATT_MTU_CMD_SZ); + if (*om == NULL) { + return ENOMEM; + } - rc = ble_att_mtu_cmd_parse(om->om_data, om->om_len, &cmd); + rc = ble_att_mtu_cmd_parse((*om)->om_data, (*om)->om_len, &cmd); assert(rc == 0); ble_att_set_peer_mtu(chan, cmd.bhamc_mtu); - rc = ble_att_svr_tx_mtu_rsp(chan, BLE_ATT_OP_MTU_RSP, - chan->blc_my_mtu); + rc = ble_att_svr_tx_mtu_rsp(chan, BLE_ATT_OP_MTU_RSP, chan->blc_my_mtu); if (rc != 0) { return rc; } @@ -492,7 +494,7 @@ done: int ble_att_svr_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *rxom) + struct os_mbuf **rxom) { struct ble_att_find_info_req req; struct ble_att_find_info_rsp rsp; @@ -502,9 +504,12 @@ ble_att_svr_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, txom = NULL; - /* XXX: Pull up rxom. */ + *rxom = os_mbuf_pullup(*rxom, BLE_ATT_MTU_CMD_SZ); + if (*rxom == NULL) { + return ENOMEM; + } - rc = ble_att_find_info_req_parse(rxom->om_data, rxom->om_len, &req); + rc = ble_att_find_info_req_parse((*rxom)->om_data, (*rxom)->om_len, &req); if (rc != 0) { req.bhafq_start_handle = 0; rc = BLE_ATT_ERR_INVALID_PDU; @@ -530,21 +535,20 @@ ble_att_svr_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, /* Write the response base at the start of the buffer. The format field is * unknown at this point; it will be filled in later. */ - buf = os_mbuf_extend(txom, BLE_ATT_FIND_INFO_RSP_MIN_SZ); + buf = os_mbuf_extend(txom, BLE_ATT_FIND_INFO_RSP_BASE_SZ); if (buf == NULL) { rc = BLE_ATT_ERR_INSUFFICIENT_RES; goto err; } - rc = ble_att_find_info_rsp_write(buf, BLE_ATT_FIND_INFO_RSP_MIN_SZ, - &rsp); + rc = ble_att_find_info_rsp_write(buf, BLE_ATT_FIND_INFO_RSP_BASE_SZ, &rsp); assert(rc == 0); /* Write the variable length Information Data field, populating the format * field as appropriate. */ rc = ble_att_svr_fill_info(&req, txom, ble_l2cap_chan_mtu(chan), - txom->om_data + 1); + txom->om_data + 1); if (rc != 0) { rc = BLE_ATT_ERR_ATTR_NOT_FOUND; goto err; @@ -561,7 +565,7 @@ ble_att_svr_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, err: os_mbuf_free_chain(txom); ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_FIND_INFO_REQ, - req.bhafq_start_handle, rc); + req.bhafq_start_handle, rc); return rc; } @@ -781,7 +785,7 @@ done: int ble_att_svr_rx_find_type_value(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *rxom) + struct os_mbuf **rxom) { struct ble_att_find_type_value_req req; struct os_mbuf *txom; @@ -790,10 +794,13 @@ ble_att_svr_rx_find_type_value(struct ble_hs_conn *conn, txom = NULL; - /* XXX: Pull up rx_om. */ + *rxom = os_mbuf_pullup(*rxom, BLE_ATT_MTU_CMD_SZ); + if (*rxom == NULL) { + return ENOMEM; + } - rc = ble_att_find_type_value_req_parse(rxom->om_data, rxom->om_len, - &req); + rc = ble_att_find_type_value_req_parse((*rxom)->om_data, (*rxom)->om_len, + &req); assert(rc == 0); /* Tx error response if start handle is greater than end handle or is equal @@ -821,8 +828,8 @@ ble_att_svr_rx_find_type_value(struct ble_hs_conn *conn, buf[0] = BLE_ATT_OP_FIND_TYPE_VALUE_RSP; /* Write the variable length Information Data field. */ - rc = ble_att_svr_fill_type_value(&req, rxom, txom, - ble_l2cap_chan_mtu(chan)); + rc = ble_att_svr_fill_type_value(&req, *rxom, txom, + ble_l2cap_chan_mtu(chan)); if (rc != 0) { goto err; } @@ -958,48 +965,46 @@ err: int ble_att_svr_rx_read_type(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *rx_om) + struct os_mbuf **rxom) { struct ble_att_read_type_req req; uint16_t uuid16; uint8_t uuid128[16]; int rc; - /* XXX: Pull up mbuf. */ + *rxom = os_mbuf_pullup(*rxom, OS_MBUF_PKTLEN(*rxom)); + if (*rxom == NULL) { + return ENOMEM; + } - rc = ble_att_read_type_req_parse(rx_om->om_data, rx_om->om_len, &req); + rc = ble_att_read_type_req_parse((*rxom)->om_data, (*rxom)->om_len, &req); if (rc != 0) { - goto done; + return rc; } - switch (rx_om->om_len) { + switch ((*rxom)->om_len) { case BLE_ATT_READ_TYPE_REQ_SZ_16: - uuid16 = le16toh(rx_om->om_data + 5); + uuid16 = le16toh((*rxom)->om_data + 5); rc = ble_hs_uuid_from_16bit(uuid16, uuid128); if (rc != 0) { - goto done; + return rc; } break; case BLE_ATT_READ_TYPE_REQ_SZ_128: - memcpy(uuid128, rx_om->om_data + 5, 16); + memcpy(uuid128, (*rxom)->om_data + 5, 16); break; default: - rc = EMSGSIZE; - goto done; + return EMSGSIZE; } rc = ble_att_svr_tx_read_type_rsp(conn, chan, &req, uuid128); if (rc != 0) { - goto done; + return rc; } - rc = 0; - -done: - os_mbuf_free_chain(rx_om); - return rc; + return 0; } static int @@ -1052,23 +1057,23 @@ err: int ble_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **rxom) { union ble_att_svr_handle_arg arg; struct ble_att_svr_entry *entry; struct ble_att_read_req req; - uint8_t buf[BLE_ATT_READ_REQ_SZ]; int rc; - rc = os_mbuf_copydata(om, 0, sizeof buf, buf); - if (rc != 0) { - req.bharq_handle = 0; - rc = BLE_ATT_ERR_INVALID_PDU; + *rxom = os_mbuf_pullup(*rxom, OS_MBUF_PKTLEN(*rxom)); + if (*rxom == NULL) { + rc = ENOMEM; goto err; } - rc = ble_att_read_req_parse(buf, sizeof buf, &req); - assert(rc == 0); + rc = ble_att_read_req_parse((*rxom)->om_data, (*rxom)->om_len, &req); + if (rc != 0) { + goto err; + } entry = NULL; rc = ble_att_svr_find_by_handle(req.bharq_handle, &entry); @@ -1089,7 +1094,7 @@ ble_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, } rc = ble_att_svr_tx_read_rsp(conn, chan, arg.aha_read.attr_data, - arg.aha_read.attr_len); + arg.aha_read.attr_len); if (rc != 0) { goto err; } @@ -1098,7 +1103,7 @@ ble_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, err: ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_READ_REQ, - req.bharq_handle, rc); + req.bharq_handle, rc); return rc; } @@ -1138,21 +1143,25 @@ err: int ble_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **rxom) { union ble_att_svr_handle_arg arg; struct ble_att_svr_entry *entry; struct ble_att_write_req req; - uint8_t buf[BLE_ATT_WRITE_REQ_MIN_SZ]; int rc; - rc = os_mbuf_copydata(om, 0, sizeof buf, buf); + *rxom = os_mbuf_pullup(*rxom, BLE_ATT_WRITE_REQ_MIN_SZ); + if (*rxom == NULL) { + rc = ENOMEM; + goto send_err; + } + + rc = ble_att_write_req_parse((*rxom)->om_data, (*rxom)->om_len, &req); if (rc != 0) { - return rc; + goto send_err; } - rc = ble_att_write_req_parse(buf, sizeof buf, &req); - assert(rc == 0); + os_mbuf_adj(*rxom, BLE_ATT_WRITE_REQ_MIN_SZ); entry = NULL; rc = ble_att_svr_find_by_handle(req.bhawq_handle, &entry); @@ -1166,8 +1175,8 @@ ble_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, goto send_err; } - arg.aha_write.om = om; - arg.aha_write.attr_len = OS_MBUF_PKTHDR(om)->omp_len; + arg.aha_write.om = *rxom; + arg.aha_write.attr_len = OS_MBUF_PKTLEN(*rxom); rc = entry->ha_fn(entry, BLE_ATT_OP_WRITE_REQ, &arg); if (rc != 0) { goto send_err; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_gatt.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_gatt.c b/net/nimble/host/src/ble_gatt.c index 6b52b96..207d03c 100644 --- a/net/nimble/host/src/ble_gatt.c +++ b/net/nimble/host/src/ble_gatt.c @@ -22,10 +22,13 @@ #include "os/os_mempool.h" #include "host/ble_gatt.h" #include "host/ble_hs.h" +#include "ble_hs_uuid.h" #include "ble_hs_conn.h" #include "ble_att_cmd.h" #include "ble_att.h" +#define BLE_ATT_UUID_PRIMARY_SERVICE 0x2800 + struct ble_gatt_entry { STAILQ_ENTRY(ble_gatt_entry) next; @@ -45,22 +48,31 @@ struct ble_gatt_entry { int (*cb)(int status, uint16_t conn_handle, void *arg); void *cb_arg; } find_info; + + struct { + uint16_t prev_handle; + ble_gatt_disc_service_fn *cb; + void *cb_arg; + } disc_all_services; }; }; -#define BLE_GATT_OP_NONE UINT8_MAX -#define BLE_GATT_OP_MTU 0 -#define BLE_GATT_OP_FIND_INFO 1 -#define BLE_GATT_OP_MAX 2 +#define BLE_GATT_OP_NONE UINT8_MAX +#define BLE_GATT_OP_MTU 0 +#define BLE_GATT_OP_FIND_INFO 1 +#define BLE_GATT_OP_DISC_ALL_SERVICES 2 +#define BLE_GATT_OP_MAX 3 typedef int ble_gatt_kick_fn(struct ble_gatt_entry *entry); static int ble_gatt_kick_mtu(struct ble_gatt_entry *entry); static int ble_gatt_kick_find_info(struct ble_gatt_entry *entry); +static int ble_gatt_kick_disc_all_services(struct ble_gatt_entry *entry); static ble_gatt_kick_fn *ble_gatt_kick_fns[BLE_GATT_OP_MAX] = { - [BLE_GATT_OP_MTU] = ble_gatt_kick_mtu, - [BLE_GATT_OP_FIND_INFO] = ble_gatt_kick_find_info, + [BLE_GATT_OP_MTU] = ble_gatt_kick_mtu, + [BLE_GATT_OP_FIND_INFO] = ble_gatt_kick_find_info, + [BLE_GATT_OP_DISC_ALL_SERVICES] = ble_gatt_kick_disc_all_services, }; #define BLE_GATT_ENTRY_F_PENDING 0x01 @@ -255,6 +267,32 @@ ble_gatt_kick_find_info(struct ble_gatt_entry *entry) return 0; } +static int +ble_gatt_kick_disc_all_services(struct ble_gatt_entry *entry) +{ + struct ble_att_read_group_type_req req; + struct ble_hs_conn *conn; + uint8_t uuid128[16]; + int rc; + + conn = ble_hs_conn_find(entry->conn_handle); + if (conn == NULL) { + return ENOTCONN; + } + + rc = ble_hs_uuid_from_16bit(BLE_ATT_UUID_PRIMARY_SERVICE, uuid128); + assert(rc == 0); + + req.bhagq_start_handle = entry->disc_all_services.prev_handle + 1; + req.bhagq_end_handle = 0xffff; + rc = ble_att_clt_tx_read_group_type(conn, &req, uuid128); + if (rc != 0) { + return rc; + } + + return 0; +} + void ble_gatt_wakeup(void) { @@ -394,6 +432,66 @@ ble_gatt_find_info(uint16_t conn_handle, uint16_t att_start_handle, return 0; } +void +ble_gatt_rx_read_group_type_adata(struct ble_hs_conn *conn, + struct ble_att_clt_adata *adata) +{ + struct ble_gatt_entry *entry; + + entry = ble_gatt_find(conn->bhc_handle, BLE_GATT_OP_MTU, 1, NULL); + if (entry == NULL) { + /* Not expecting a response from this device. */ + return; + } + + entry->disc_all_services.prev_handle = adata->end_group_handle; + + /* XXX: Call success callback. */ +} + +void +ble_gatt_rx_read_group_type_complete(struct ble_hs_conn *conn, int rc) +{ + struct ble_gatt_entry *entry; + struct ble_gatt_entry *prev; + + entry = ble_gatt_find(conn->bhc_handle, BLE_GATT_OP_MTU, 1, &prev); + if (entry == NULL) { + /* Not expecting a response from this device. */ + return; + } + + if (entry->disc_all_services.prev_handle == 0xffff) { + /* All services discovered. */ + entry->disc_all_services.cb(conn->bhc_handle, NULL, + entry->disc_all_services.cb_arg); + ble_gatt_entry_remove_free(entry, prev); + } else { + /* Send follow-up request. */ + ble_gatt_entry_set_pending(entry); + } +} + +int +ble_gatt_disc_all_services(uint16_t conn_handle, ble_gatt_disc_service_fn *cb, + void *cb_arg) +{ + struct ble_gatt_entry *entry; + int rc; + + rc = ble_gatt_new_entry(conn_handle, &entry); + if (rc != 0) { + return rc; + } + entry->op = BLE_GATT_OP_DISC_ALL_SERVICES; + entry->disc_all_services.prev_handle = 0x0000; + entry->disc_all_services.cb = cb; + entry->disc_all_services.cb_arg = cb_arg; + + return 0; +} + + int ble_gatt_init(void) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_hs.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c index 519e3e7..450b678 100644 --- a/net/nimble/host/src/ble_hs.c +++ b/net/nimble/host/src/ble_hs.c @@ -324,11 +324,6 @@ ble_hs_init(uint8_t prio) goto err; } - rc = ble_att_clt_init(); - if (rc != 0) { - goto err; - } - rc = ble_gap_conn_init(); if (rc != 0) { goto err; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_hs_conn.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c index 405a3d7..d72a956 100644 --- a/net/nimble/host/src/ble_hs_conn.c +++ b/net/nimble/host/src/ble_hs_conn.c @@ -85,8 +85,6 @@ ble_hs_conn_free(struct ble_hs_conn *conn) /* XXX: Free contents of rx and tx queues. */ - ble_att_clt_entry_list_free(&conn->bhc_att_clt_list); - rc = os_memblock_put(&ble_hs_conn_pool, conn); assert(rc == 0); } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_l2cap.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c index 2d51f3a..5237222 100644 --- a/net/nimble/host/src/ble_l2cap.c +++ b/net/nimble/host/src/ble_l2cap.c @@ -126,7 +126,7 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, assert(chan->blc_rx_buf == NULL); chan->blc_rx_buf = om; - rc = chan->blc_rx_fn(conn, chan, chan->blc_rx_buf); + rc = chan->blc_rx_fn(conn, chan, &chan->blc_rx_buf); os_mbuf_free_chain(chan->blc_rx_buf); chan->blc_rx_buf = NULL; if (rc != 0) { http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_l2cap.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap.h b/net/nimble/host/src/ble_l2cap.h index 090c95d..7399ea7 100644 --- a/net/nimble/host/src/ble_l2cap.h +++ b/net/nimble/host/src/ble_l2cap.h @@ -38,7 +38,7 @@ struct ble_l2cap_chan; typedef int ble_l2cap_rx_fn(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om); + struct os_mbuf **om); typedef int ble_l2cap_tx_fn(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/ble_l2cap_sig.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c index ffaeb69..9bf8bcc 100644 --- a/net/nimble/host/src/ble_l2cap_sig.c +++ b/net/nimble/host/src/ble_l2cap_sig.c @@ -23,7 +23,7 @@ static int ble_l2cap_sig_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, - struct os_mbuf *om) + struct os_mbuf **om) { return BLE_ERR_UNSUPPORTED; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/test/ble_hs_att_clt_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_att_clt_test.c b/net/nimble/host/src/test/ble_hs_att_clt_test.c index 45a7a14..a2a7c5e 100644 --- a/net/nimble/host/src/test/ble_hs_att_clt_test.c +++ b/net/nimble/host/src/test/ble_hs_att_clt_test.c @@ -77,7 +77,6 @@ TEST_CASE(ble_att_clt_test_rx_find_info) struct ble_att_find_info_rsp rsp; struct ble_l2cap_chan *chan; struct ble_hs_conn *conn; - uint16_t handle_id; uint8_t buf[1024]; uint8_t uuid128_1[16] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }; int off; @@ -86,16 +85,12 @@ TEST_CASE(ble_att_clt_test_rx_find_info) ble_att_clt_test_misc_init(&conn, &chan); /*** One 128-bit UUID. */ - /* Ensure attribute mapping is not initially present. */ - handle_id = ble_att_clt_find_entry_uuid128(conn, uuid128_1); - TEST_ASSERT_FATAL(handle_id == 0); - /* Receive response with attribute mapping. */ off = 0; rsp.bhafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT; rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp); TEST_ASSERT(rc == 0); - off += BLE_ATT_FIND_INFO_RSP_MIN_SZ; + off += BLE_ATT_FIND_INFO_RSP_BASE_SZ; htole16(buf + off, 1); off += 2; @@ -105,20 +100,13 @@ TEST_CASE(ble_att_clt_test_rx_find_info) rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off); TEST_ASSERT(rc == 0); - handle_id = ble_att_clt_find_entry_uuid128(conn, uuid128_1); - TEST_ASSERT_FATAL(handle_id == 1); - /*** One 16-bit UUID. */ - /* Ensure attribute mapping is not initially present. */ - handle_id = ble_att_clt_find_entry_uuid16(conn, 0x000f); - TEST_ASSERT_FATAL(handle_id == 0); - /* Receive response with attribute mapping. */ off = 0; rsp.bhafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT; rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp); TEST_ASSERT(rc == 0); - off += BLE_ATT_FIND_INFO_RSP_MIN_SZ; + off += BLE_ATT_FIND_INFO_RSP_BASE_SZ; htole16(buf + off, 2); off += 2; @@ -128,22 +116,13 @@ TEST_CASE(ble_att_clt_test_rx_find_info) rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off); TEST_ASSERT(rc == 0); - handle_id = ble_att_clt_find_entry_uuid16(conn, 0x000f); - TEST_ASSERT_FATAL(handle_id == 2); - /*** Two 16-bit UUIDs. */ - /* Ensure attribute mappings are not initially present. */ - handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0010); - TEST_ASSERT_FATAL(handle_id == 0); - handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0011); - TEST_ASSERT_FATAL(handle_id == 0); - /* Receive response with attribute mappings. */ off = 0; rsp.bhafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT; rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp); TEST_ASSERT(rc == 0); - off += BLE_ATT_FIND_INFO_RSP_MIN_SZ; + off += BLE_ATT_FIND_INFO_RSP_BASE_SZ; htole16(buf + off, 3); off += 2; @@ -157,11 +136,6 @@ TEST_CASE(ble_att_clt_test_rx_find_info) rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off); TEST_ASSERT(rc == 0); - - handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0010); - TEST_ASSERT_FATAL(handle_id == 3); - handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0011); - TEST_ASSERT_FATAL(handle_id == 4); } TEST_SUITE(ble_att_clt_suite) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bf65252e/net/nimble/host/src/test/ble_hs_att_svr_test.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/test/ble_hs_att_svr_test.c b/net/nimble/host/src/test/ble_hs_att_svr_test.c index c7fff45..a1a8479 100644 --- a/net/nimble/host/src/test/ble_hs_att_svr_test.c +++ b/net/nimble/host/src/test/ble_hs_att_svr_test.c @@ -204,7 +204,7 @@ ble_att_svr_test_misc_verify_tx_find_info_rsp( struct ble_att_find_info_rsp rsp; uint16_t handle; uint16_t uuid16; - uint8_t buf[BLE_ATT_FIND_INFO_RSP_MIN_SZ]; + uint8_t buf[BLE_ATT_FIND_INFO_RSP_BASE_SZ]; uint8_t uuid128[16]; int off; int rc;