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/05/20 03:31:29 UTC
[3/3] incubator-mynewt-core git commit: BLE Host - Move status into
GAP ctxt object.
BLE Host - Move status into GAP ctxt object.
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/37d199cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/37d199cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/37d199cd
Branch: refs/heads/develop
Commit: 37d199cd9346b6f04cb966fa23bce9180ebe8c30
Parents: 3e86d59
Author: Christopher Collins <cc...@apache.org>
Authored: Thu May 19 20:29:33 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu May 19 20:31:23 2016 -0700
----------------------------------------------------------------------
apps/bleprph/src/main.c | 41 ++--
apps/bletiny/src/main.c | 73 ++++---
net/nimble/host/include/host/ble_gap.h | 75 +++++---
net/nimble/host/src/ble_gap.c | 220 ++++++++++++++--------
net/nimble/host/src/ble_gap_priv.h | 3 +-
net/nimble/host/src/ble_hs_conn_priv.h | 2 +-
net/nimble/host/src/ble_l2cap_sm.c | 4 +-
net/nimble/host/src/test/ble_att_svr_test.c | 12 +-
net/nimble/host/src/test/ble_gap_test.c | 69 ++++---
net/nimble/host/src/test/ble_hs_test_util.c | 6 +-
net/nimble/host/src/test/ble_hs_test_util.h | 6 +-
net/nimble/host/src/test/ble_l2cap_sm_test.c | 18 +-
net/nimble/host/src/test/ble_l2cap_test.c | 6 +-
net/nimble/host/src/test/ble_os_test.c | 26 +--
14 files changed, 337 insertions(+), 224 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 5037bc8..4cf8aa9 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -84,8 +84,8 @@ uint8_t bleprph_reconnect_addr[6];
uint8_t bleprph_pref_conn_params[8];
uint8_t bleprph_gatt_service_changed[4];
-static int bleprph_gap_event(int event, int status,
- struct ble_gap_conn_ctxt *ctxt, void *arg);
+static int bleprph_gap_event(int event, struct ble_gap_conn_ctxt *ctxt,
+ void *arg);
/**
* Utility function to log an array of bytes.
@@ -170,8 +170,6 @@ bleprph_advertise(void)
* bleprph uses the same callback for all connections.
*
* @param event The type of event being signalled.
- * @param status The error code associated with the event
- * (0 = success).
* @param ctxt Various information pertaining to the event.
* @param arg Application-specified argument; unuesd by
* bleprph.
@@ -182,31 +180,39 @@ bleprph_advertise(void)
* particular GAP event being signalled.
*/
static int
-bleprph_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
- void *arg)
+bleprph_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
{
int authenticated;
int rc;
switch (event) {
- case BLE_GAP_EVENT_CONN:
- /* A new connection has been established or an existing one has been
- * terminated.
- */
+ case BLE_GAP_EVENT_CONNECT:
+ /* A new connection was established or a connection attempt failed. */
BLEPRPH_LOG(INFO, "connection %s; status=%d ",
- status == 0 ? "up" : "down", status);
+ ctxt->connect.status == 0 ? "established" : "failed",
+ ctxt->connect.status);
bleprph_print_conn_desc(ctxt->desc);
BLEPRPH_LOG(INFO, "\n");
- if (status != 0) {
- /* Connection terminated; resume advertising. */
+ if (ctxt->connect.status != 0) {
+ /* Connection failed; resume advertising. */
bleprph_advertise();
}
return 0;
- case BLE_GAP_EVENT_CONN_UPDATED:
+ case BLE_GAP_EVENT_DISCONNECT:
+ BLEPRPH_LOG(INFO, "disconnect; reason=%d ", ctxt->disconnect.reason);
+ bleprph_print_conn_desc(ctxt->desc);
+ BLEPRPH_LOG(INFO, "\n");
+
+ /* Connection terminated; resume advertising. */
+ bleprph_advertise();
+ return 0;
+
+ case BLE_GAP_EVENT_CONN_UPDATE:
/* The central has updated the connection parameters. */
- BLEPRPH_LOG(INFO, "connection updated; status=%d ", status);
+ BLEPRPH_LOG(INFO, "connection updated; status=%d ",
+ ctxt->conn_update.status);
bleprph_print_conn_desc(ctxt->desc);
BLEPRPH_LOG(INFO, "\n");
return 0;
@@ -259,9 +265,10 @@ bleprph_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
}
return 0;
- case BLE_GAP_EVENT_SECURITY:
+ case BLE_GAP_EVENT_ENC_CHANGE:
/* Encryption has been enabled or disabled for this connection. */
- BLEPRPH_LOG(INFO, "security event; status=%d ", status);
+ BLEPRPH_LOG(INFO, "encryption change event; status=%d ",
+ ctxt->enc_change.status);
bleprph_print_conn_desc(ctxt->desc);
BLEPRPH_LOG(INFO, "\n");
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 97e552e..d162d96 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -169,12 +169,6 @@ bletiny_print_conn_desc(struct ble_gap_conn_desc *desc)
}
static void
-bletiny_print_passkey_action_parms(struct ble_gap_passkey_action *pkact)
-{
- console_printf("passkey Action Request %d\n", pkact->action);
-}
-
-static void
bletiny_print_key_exchange_parms(struct ble_gap_key_parms *key_params)
{
if (key_params->is_ours) {
@@ -832,45 +826,51 @@ bletiny_on_write_reliable(uint16_t conn_handle, struct ble_gatt_error *error,
}
static int
-bletiny_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
- void *arg)
+bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
{
int authenticated;
int conn_idx;
int rc;
switch (event) {
- case BLE_GAP_EVENT_CONN:
+ case BLE_GAP_EVENT_CONNECT:
console_printf("connection %s; status=%d ",
- status == 0 ? "up" : "down", status);
+ ctxt->connect.status == 0 ? "established" : "failed",
+ ctxt->connect.status);
bletiny_print_conn_desc(ctxt->desc);
console_printf("\n");
- if (status == 0) {
+ if (ctxt->connect.status == 0) {
bletiny_conn_add(ctxt->desc);
- } else {
- if (ctxt->desc->conn_handle == BLE_HS_CONN_HANDLE_NONE) {
- if (status == BLE_HS_HCI_ERR(BLE_ERR_UNK_CONN_ID)) {
- console_printf("connection procedure cancelled.\n");
- }
- } else {
- conn_idx = bletiny_conn_find_idx(ctxt->desc->conn_handle);
- if (conn_idx != -1) {
- bletiny_conn_delete_idx(conn_idx);
- }
- }
}
return 0;
- case BLE_GAP_EVENT_CONN_UPDATED:
- console_printf("connection updated; status=%d ", status);
+ case BLE_GAP_EVENT_DISCONNECT:
+ console_printf("disconnect; reason=%d ", ctxt->disconnect.reason);
+ bletiny_print_conn_desc(ctxt->desc);
+ console_printf("\n");
+
+ conn_idx = bletiny_conn_find_idx(ctxt->desc->conn_handle);
+ if (conn_idx != -1) {
+ bletiny_conn_delete_idx(conn_idx);
+ }
+ return 0;
+
+ case BLE_GAP_EVENT_CONN_CANCEL:
+ console_printf("connection procedure cancelled.\n");
+ return 0;
+
+ case BLE_GAP_EVENT_CONN_UPDATE:
+ console_printf("connection updated; status=%d ",
+ ctxt->conn_update.status);
bletiny_print_conn_desc(ctxt->desc);
console_printf("\n");
return 0;
case BLE_GAP_EVENT_CONN_UPDATE_REQ:
- console_printf("connection update request; status=%d ", status);
- *ctxt->update.self_params = *ctxt->update.peer_params;
+ console_printf("connection update request\n");
+ *ctxt->conn_update_req.self_params =
+ *ctxt->conn_update_req.peer_params;
return 0;
case BLE_GAP_EVENT_LTK_REQUEST:
@@ -902,7 +902,7 @@ bletiny_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
return rc;
case BLE_GAP_EVENT_KEY_EXCHANGE:
- console_printf("key exchange event; status=%d ", status);
+ console_printf("key exchange event; ");
bletiny_print_key_exchange_parms(ctxt->key_params);
/* The central is sending us key information or vice-versa. If the
@@ -926,12 +926,13 @@ bletiny_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
return 0;
case BLE_GAP_EVENT_PASSKEY_ACTION:
- console_printf("passkey action event; status=%d ", status);
- bletiny_print_passkey_action_parms(ctxt->passkey_action);
+ console_printf("passkey action event; action=%d\n",
+ ctxt->passkey_action.action);
return 0;
- case BLE_GAP_EVENT_SECURITY:
- console_printf("security event; status=%d ", status);
+ case BLE_GAP_EVENT_ENC_CHANGE:
+ console_printf("encryption change event; status=%d ",
+ ctxt->enc_change.status);
bletiny_print_conn_desc(ctxt->desc);
console_printf("\n");
return 0;
@@ -939,12 +940,10 @@ bletiny_gap_event(int event, int status, struct ble_gap_conn_ctxt *ctxt,
case BLE_GAP_EVENT_NOTIFY:
console_printf("notification event; attr_handle=%d indication=%d "
"len=%d data=",
- ctxt->notify_params->attr_handle,
- ctxt->notify_params->indication,
- ctxt->notify_params->attr_len);
+ ctxt->notify.attr_handle, ctxt->notify.indication,
+ ctxt->notify.attr_len);
- bletiny_print_bytes(ctxt->notify_params->attr_data,
- ctxt->notify_params->attr_len);
+ bletiny_print_bytes(ctxt->notify.attr_data, ctxt->notify.attr_len);
console_printf("\n");
return 0;
@@ -976,7 +975,7 @@ bletiny_on_scan(int event, int status, struct ble_gap_disc_desc *desc,
console_printf("\n");
break;
- case BLE_GAP_EVENT_DISC_FINISHED:
+ case BLE_GAP_EVENT_DISC_COMPLETE:
console_printf("scanning finished; status=%d\n", status);
break;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 858de1c..df85a59 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -87,20 +87,21 @@ struct hci_adv_params;
#define BLE_GAP_ADDR_TYPE_WL 0xff
-#define BLE_GAP_EVENT_CONN 0
-#define BLE_GAP_EVENT_CONN_UPDATED 1
-#define BLE_GAP_EVENT_CONN_UPDATE_REQ 2
-#define BLE_GAP_EVENT_L2CAP_UPDATE_REQ 3
-#define BLE_GAP_EVENT_CANCEL 4
-#define BLE_GAP_EVENT_TERM_FAILURE 5
-#define BLE_GAP_EVENT_DISC_SUCCESS 6
-#define BLE_GAP_EVENT_DISC_FINISHED 7
-#define BLE_GAP_EVENT_ADV_FINISHED 8
-#define BLE_GAP_EVENT_SECURITY 9
-#define BLE_GAP_EVENT_PASSKEY_ACTION 10
-#define BLE_GAP_EVENT_LTK_REQUEST 11
-#define BLE_GAP_EVENT_KEY_EXCHANGE 12
-#define BLE_GAP_EVENT_NOTIFY 13
+#define BLE_GAP_EVENT_CONNECT 0
+#define BLE_GAP_EVENT_DISCONNECT 1
+#define BLE_GAP_EVENT_CONN_CANCEL 2
+#define BLE_GAP_EVENT_CONN_UPDATE 3
+#define BLE_GAP_EVENT_CONN_UPDATE_REQ 4
+#define BLE_GAP_EVENT_L2CAP_UPDATE_REQ 5
+#define BLE_GAP_EVENT_TERM_FAILURE 6
+#define BLE_GAP_EVENT_DISC_SUCCESS 7
+#define BLE_GAP_EVENT_DISC_COMPLETE 8
+#define BLE_GAP_EVENT_ADV_COMPLETE 9
+#define BLE_GAP_EVENT_ENC_CHANGE 10
+#define BLE_GAP_EVENT_PASSKEY_ACTION 11
+#define BLE_GAP_EVENT_LTK_REQUEST 12
+#define BLE_GAP_EVENT_KEY_EXCHANGE 13
+#define BLE_GAP_EVENT_NOTIFY 14
struct ble_gap_sec_state {
uint8_t pair_alg;
@@ -193,19 +194,49 @@ struct ble_gap_conn_ctxt {
union {
struct {
+ int status;
+ } connect;
+
+ struct {
+ int reason;
+ } disconnect;
+
+ struct {
+ int status;
+ } conn_update;
+
+ struct {
struct ble_gap_upd_params *self_params;
struct ble_gap_upd_params *peer_params;
- } update;
+ } conn_update_req;
+
+ struct {
+ int status;
+ } term_failure;
+
+ struct {
+ int status;
+ } enc_change;
+
+ struct {
+ uint8_t action;
+ } passkey_action;
+
+ struct {
+ uint16_t attr_handle;
+ void *attr_data;
+ uint16_t attr_len;
+
+ unsigned indication:1;
+ } notify;
- struct ble_gap_passkey_action *passkey_action;
struct ble_gap_ltk_params *ltk_params;
struct ble_gap_key_parms *key_params;
- struct ble_gap_notify_params *notify_params;
};
};
-typedef int ble_gap_conn_fn(int event, int status,
- struct ble_gap_conn_ctxt *ctxt, void *arg);
+typedef int ble_gap_event_fn(int event, struct ble_gap_conn_ctxt *ctxt,
+ void *arg);
struct ble_gap_disc_desc {
uint8_t event_type;
@@ -235,10 +266,12 @@ struct ble_gap_white_entry {
uint8_t addr[6];
};
+int ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc);
+
int ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
uint8_t *peer_addr, uint8_t peer_addr_type,
struct hci_adv_params *adv_params,
- ble_gap_conn_fn *cb, void *cb_arg);
+ ble_gap_event_fn *cb, void *cb_arg);
int ble_gap_adv_stop(void);
int ble_gap_adv_set_fields(struct ble_hs_adv_fields *adv_fields);
int ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields);
@@ -247,7 +280,7 @@ int ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
ble_gap_disc_fn *cb, void *cb_arg);
int ble_gap_conn_initiate(int addr_type, uint8_t *addr,
struct ble_gap_crt_params *params,
- ble_gap_conn_fn *cb, void *cb_arg);
+ ble_gap_event_fn *cb, void *cb_arg);
int ble_gap_terminate(uint16_t handle);
int ble_gap_cancel(void);
int ble_gap_wl_set(struct ble_gap_white_entry *white_list,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index ce4677c..0709430 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -107,7 +107,7 @@ static bssnz_t struct {
union {
struct {
- ble_gap_conn_fn *cb;
+ ble_gap_event_fn *cb;
void *cb_arg;
unsigned using_wl:1;
@@ -130,7 +130,7 @@ static bssnz_t struct {
uint8_t conn_mode;
uint8_t disc_mode;
- ble_gap_conn_fn *cb;
+ ble_gap_event_fn *cb;
void *cb_arg;
uint8_t adv_data[BLE_HCI_MAX_ADV_DATA_LEN];
@@ -146,7 +146,7 @@ static int ble_gap_disc_tx_disable(void);
struct ble_gap_snapshot {
struct ble_gap_conn_desc desc;
- ble_gap_conn_fn *cb;
+ ble_gap_event_fn *cb;
void *cb_arg;
};
@@ -306,24 +306,59 @@ ble_gap_find_snapshot(uint16_t handle, struct ble_gap_snapshot *snap)
}
}
+/**
+ * Searches for a connection with the specified handle. If a matching
+ * connection is found, the supplied connection descriptor is filled
+ * correspondingly.
+ *
+ * @param handle The connection handle to search for.
+ * @param out_desc On success, this is populated with information
+ * relating to the matching connection. Pass
+ * NULL if you don't need this information.
+ *
+ * @return 0 on success; BLE_HS_ENOTCONN if no matching
+ * connection was found.
+ */
+int
+ble_gap_find_conn(uint16_t handle, struct ble_gap_conn_desc *out_desc)
+{
+ struct ble_hs_conn *conn;
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(handle);
+ if (conn != NULL && out_desc != NULL) {
+ ble_gap_fill_conn_desc(conn, out_desc);
+ }
+
+ ble_hs_unlock();
+
+ if (conn == NULL) {
+ return BLE_HS_ENOTCONN;
+ } else {
+ return 0;
+ }
+}
+
/*****************************************************************************
* $misc *
*****************************************************************************/
static int
-ble_gap_call_conn_cb(int event, int status, struct ble_gap_conn_ctxt *ctxt,
- ble_gap_conn_fn *cb, void *cb_arg)
+ble_gap_call_event_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ ble_gap_event_fn *cb, void *cb_arg)
{
int rc;
BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
if (cb != NULL) {
- rc = cb(event, status, ctxt, cb_arg);
+ rc = cb(event, ctxt, cb_arg);
} else {
if (event == BLE_GAP_EVENT_CONN_UPDATE_REQ) {
- /* Just copy peer parameters back into reply. */
- *ctxt->update.self_params = *ctxt->update.peer_params;
+ /* Just copy peer parameters back into the reply. */
+ *ctxt->conn_update_req.self_params =
+ *ctxt->conn_update_req.peer_params;
}
rc = 0;
}
@@ -332,63 +367,90 @@ ble_gap_call_conn_cb(int event, int status, struct ble_gap_conn_ctxt *ctxt,
}
static void
-ble_gap_call_slave_cb(int event, int status, int reset_state)
+ble_gap_slave_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
+{
+ ble_hs_lock();
+
+ *out_cb = ble_gap_slave.cb;
+ *out_cb_arg = ble_gap_slave.cb_arg;
+ ble_gap_slave.op = BLE_GAP_OP_NULL;
+
+ ble_hs_unlock();
+}
+
+static void
+ble_gap_adv_finished(int event)
{
struct ble_gap_conn_ctxt ctxt;
struct ble_gap_conn_desc desc;
- ble_gap_conn_fn *cb;
+ ble_gap_event_fn *cb;
void *cb_arg;
- ble_hs_lock();
+ ble_gap_slave_extract_cb(&cb, &cb_arg);
+ if (cb != NULL) {
+ memset(&ctxt, 0, sizeof ctxt);
+ desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
+ ctxt.desc = &desc;
- desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
+ cb(event, &ctxt, cb_arg);
+ }
+}
- cb = ble_gap_slave.cb;
- cb_arg = ble_gap_slave.cb_arg;
+static void
+ble_gap_master_extract_cb(ble_gap_event_fn **out_cb, void **out_cb_arg)
+{
+ ble_hs_lock();
- if (reset_state) {
- ble_gap_slave.op = BLE_GAP_OP_NULL;
- }
+ *out_cb = ble_gap_master.conn.cb;
+ *out_cb_arg = ble_gap_master.conn.cb_arg;
+ ble_gap_master.op = BLE_GAP_OP_NULL;
ble_hs_unlock();
+}
+static int
+ble_gap_master_connect_failure(int status)
+{
+ struct ble_gap_conn_ctxt ctxt;
+ struct ble_gap_conn_desc desc;
+ ble_gap_event_fn *cb;
+ void *cb_arg;
+ int rc;
+
+ memset(&desc, 0, sizeof ctxt);
+
+ ble_gap_master_extract_cb(&cb, &cb_arg);
if (cb != NULL) {
memset(&ctxt, 0, sizeof ctxt);
+ desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
ctxt.desc = &desc;
+ ctxt.connect.status = status;
- cb(event, status, &ctxt, cb_arg);
+ rc = cb(BLE_GAP_EVENT_CONNECT, &ctxt, cb_arg);
+ } else {
+ rc = 0;
}
+
+ return rc;
}
static int
-ble_gap_call_master_conn_cb(int event, int status, int reset_state)
+ble_gap_master_connect_cancel(void)
{
struct ble_gap_conn_ctxt ctxt;
struct ble_gap_conn_desc desc;
- ble_gap_conn_fn *cb;
+ ble_gap_event_fn *cb;
void *cb_arg;
int rc;
- ble_hs_lock();
-
memset(&desc, 0, sizeof ctxt);
-
desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
- cb = ble_gap_master.conn.cb;
- cb_arg = ble_gap_master.conn.cb_arg;
-
- if (reset_state) {
- ble_gap_master.op = BLE_GAP_OP_NULL;
- }
-
- ble_hs_unlock();
-
+ ble_gap_master_extract_cb(&cb, &cb_arg);
if (cb != NULL) {
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &desc;
-
- rc = cb(event, status, &ctxt, cb_arg);
+ rc = cb(BLE_GAP_EVENT_CONN_CANCEL, &ctxt, cb_arg);
} else {
rc = 0;
}
@@ -446,8 +508,9 @@ ble_gap_update_notify(uint16_t conn_handle, int status)
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_CONN_UPDATED, status, &ctxt,
- snap.cb, snap.cb_arg);
+ ctxt.conn_update.status = status;
+ ble_gap_call_event_cb(BLE_GAP_EVENT_CONN_UPDATE, &ctxt,
+ snap.cb, snap.cb_arg);
}
static void
@@ -469,13 +532,13 @@ ble_gap_master_failed(int status)
switch (ble_gap_master.op) {
case BLE_GAP_OP_M_DISC:
STATS_INC(ble_gap_stats, discover_fail);
- ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_FINISHED, status,
+ ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_COMPLETE, status,
NULL, NULL, 1);
break;
case BLE_GAP_OP_M_CONN:
STATS_INC(ble_gap_stats, initiate_fail);
- ble_gap_call_master_conn_cb(BLE_GAP_EVENT_CONN, status, 1);
+ ble_gap_master_connect_failure(status);
break;
default:
@@ -492,7 +555,7 @@ ble_gap_update_failed(uint16_t conn_handle, int status)
}
static void
-ble_gap_conn_broken(struct ble_gap_snapshot *snap, int status)
+ble_gap_conn_broken(struct ble_gap_snapshot *snap, int reason)
{
struct ble_gap_conn_ctxt ctxt;
@@ -503,8 +566,9 @@ ble_gap_conn_broken(struct ble_gap_snapshot *snap, int status)
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap->desc;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_CONN, status, &ctxt,
- snap->cb, snap->cb_arg);
+ ctxt.disconnect.reason = reason;
+ ble_gap_call_event_cb(BLE_GAP_EVENT_DISCONNECT, &ctxt,
+ snap->cb, snap->cb_arg);
STATS_INC(ble_gap_stats, disconnect);
}
@@ -542,9 +606,9 @@ ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt)
} else {
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_TERM_FAILURE,
- BLE_HS_HCI_ERR(evt->status), &ctxt,
- snap.cb, snap.cb_arg);
+ ctxt.term_failure.status = BLE_HS_HCI_ERR(evt->status);
+ ble_gap_call_event_cb(BLE_GAP_EVENT_TERM_FAILURE, &ctxt,
+ snap.cb, snap.cb_arg);
}
}
@@ -581,9 +645,9 @@ ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
if (conn != NULL) {
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_CONN_UPDATED,
- BLE_HS_HCI_ERR(evt->status), &ctxt,
- snap.cb, snap.cb_arg);
+ ctxt.conn_update.status = BLE_HS_HCI_ERR(evt->status);
+ ble_gap_call_event_cb(BLE_GAP_EVENT_CONN_UPDATE, &ctxt,
+ snap.cb, snap.cb_arg);
}
}
@@ -777,7 +841,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
switch (evt->status) {
case BLE_ERR_DIR_ADV_TMO:
if (ble_gap_slave_in_progress()) {
- ble_gap_call_slave_cb(BLE_GAP_EVENT_ADV_FINISHED, 0, 1);
+ ble_gap_adv_finished(BLE_GAP_EVENT_ADV_COMPLETE);
}
break;
@@ -785,7 +849,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
if (ble_gap_master_in_progress()) {
if (evt->status == BLE_ERR_UNK_CONN_ID) {
/* Connect procedure successfully cancelled. */
- ble_gap_call_master_conn_cb(BLE_GAP_EVENT_CANCEL, 0, 1);
+ ble_gap_master_connect_cancel();
} else {
ble_gap_master_failed(BLE_HS_HCI_ERR(evt->status));
}
@@ -843,7 +907,8 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_CONN, 0, &ctxt, snap.cb, snap.cb_arg);
+ ctxt.connect.status = 0;
+ ble_gap_call_event_cb(BLE_GAP_EVENT_CONNECT, &ctxt, snap.cb, snap.cb_arg);
return 0;
}
@@ -864,8 +929,8 @@ ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
if (snap.cb != NULL) {
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ctxt.update.peer_params = params;
- rc = snap.cb(BLE_GAP_EVENT_L2CAP_UPDATE_REQ, 0, &ctxt, snap.cb_arg);
+ ctxt.conn_update_req.peer_params = params;
+ rc = snap.cb(BLE_GAP_EVENT_L2CAP_UPDATE_REQ, &ctxt, snap.cb_arg);
} else {
rc = 0;
}
@@ -899,7 +964,7 @@ ble_gap_heartbeat(void)
case BLE_GAP_OP_M_DISC:
/* When a discovery procedure times out, it is not a failure. */
rc = ble_gap_disc_tx_disable();
- ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_FINISHED, rc,
+ ble_gap_call_master_disc_cb(BLE_GAP_EVENT_DISC_COMPLETE, rc,
NULL, NULL, 1);
break;
@@ -1272,7 +1337,7 @@ int
ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
uint8_t *peer_addr, uint8_t peer_addr_type,
struct hci_adv_params *adv_params,
- ble_gap_conn_fn *cb, void *cb_arg)
+ ble_gap_event_fn *cb, void *cb_arg)
{
#if !NIMBLE_OPT(ADVERTISE)
return BLE_HS_ENOTSUP;
@@ -1651,7 +1716,7 @@ ble_gap_conn_create_tx(int addr_type, uint8_t *addr,
int
ble_gap_conn_initiate(int addr_type, uint8_t *addr,
struct ble_gap_crt_params *params,
- ble_gap_conn_fn *cb, void *cb_arg)
+ ble_gap_event_fn *cb, void *cb_arg)
{
#if !NIMBLE_OPT(ROLE_CENTRAL)
return BLE_HS_ENOTSUP;
@@ -1874,10 +1939,10 @@ ble_gap_rx_param_req(struct hci_le_conn_param_req *evt)
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ctxt.update.self_params = &self_params;
- ctxt.update.peer_params = &peer_params;
- rc = ble_gap_call_conn_cb(BLE_GAP_EVENT_CONN_UPDATE_REQ, 0, &ctxt,
- snap.cb, snap.cb_arg);
+ ctxt.conn_update_req.self_params = &self_params;
+ ctxt.conn_update_req.peer_params = &peer_params;
+ rc = ble_gap_call_event_cb(BLE_GAP_EVENT_CONN_UPDATE_REQ, &ctxt,
+ snap.cb, snap.cb_arg);
if (rc != 0) {
reject_reason = rc;
}
@@ -2023,13 +2088,11 @@ ble_gap_encryption_initiate(uint16_t conn_handle,
#endif
void
-ble_gap_passkey_event(uint16_t conn_handle, int status,
- uint8_t passkey_action)
+ble_gap_passkey_event(uint16_t conn_handle, uint8_t passkey_action)
{
struct ble_gap_conn_ctxt ctxt;
struct ble_gap_snapshot snap;
struct ble_hs_conn *conn;
- struct ble_gap_passkey_action act;
ble_hs_lock();
@@ -2048,11 +2111,10 @@ ble_gap_passkey_event(uint16_t conn_handle, int status,
BLE_HS_LOG(DEBUG, "send passkey action request %d\n", passkey_action);
memset(&ctxt, 0, sizeof ctxt);
- act.action = passkey_action;
ctxt.desc = &snap.desc;
- ctxt.passkey_action = &act;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_PASSKEY_ACTION, status, &ctxt,
- snap.cb, snap.cb_arg);
+ ctxt.passkey_action.action = passkey_action;
+ ble_gap_call_event_cb(BLE_GAP_EVENT_PASSKEY_ACTION, &ctxt,
+ snap.cb, snap.cb_arg);
}
void
@@ -2072,8 +2134,8 @@ ble_gap_key_exchange_event(uint16_t conn_handle,
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
ctxt.key_params = key_params;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_KEY_EXCHANGE, 0, &ctxt,
- snap.cb, snap.cb_arg);
+ ble_gap_call_event_cb(BLE_GAP_EVENT_KEY_EXCHANGE, &ctxt,
+ snap.cb, snap.cb_arg);
}
void
@@ -2101,8 +2163,9 @@ ble_gap_security_event(uint16_t conn_handle, int status,
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_SECURITY, status, &ctxt,
- snap.cb, snap.cb_arg);
+ ctxt.enc_change.status = status;
+ ble_gap_call_event_cb(BLE_GAP_EVENT_ENC_CHANGE, &ctxt,
+ snap.cb, snap.cb_arg);
}
int
@@ -2121,8 +2184,8 @@ ble_gap_ltk_event(uint16_t conn_handle, struct ble_gap_ltk_params *ltk_params)
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
ctxt.ltk_params = ltk_params;
- rc = ble_gap_call_conn_cb(BLE_GAP_EVENT_LTK_REQUEST, 0, &ctxt,
- snap.cb, snap.cb_arg);
+ rc = ble_gap_call_event_cb(BLE_GAP_EVENT_LTK_REQUEST, &ctxt,
+ snap.cb, snap.cb_arg);
if (rc != 0) {
/* No long-term key that matches the specified ediv and rand. */
return BLE_HS_EREJECT;
@@ -2140,7 +2203,6 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
void *attr_data, uint16_t attr_len, int is_indication)
{
/* XXX: Early return if notifications and indications disabled. */
- struct ble_gap_notify_params params;
struct ble_gap_conn_ctxt ctxt;
struct ble_gap_snapshot snap;
int rc;
@@ -2151,15 +2213,13 @@ ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,
return;
}
- params.attr_handle = attr_handle;
- params.attr_data = attr_data;
- params.attr_len = attr_len;
- params.indication = is_indication;
-
memset(&ctxt, 0, sizeof ctxt);
ctxt.desc = &snap.desc;
- ctxt.notify_params = ¶ms;
- ble_gap_call_conn_cb(BLE_GAP_EVENT_NOTIFY, 0, &ctxt, snap.cb, snap.cb_arg);
+ ctxt.notify.attr_handle = attr_handle;
+ ctxt.notify.attr_data = attr_data;
+ ctxt.notify.attr_len = attr_len;
+ ctxt.notify.indication = is_indication;
+ ble_gap_call_event_cb(BLE_GAP_EVENT_NOTIFY, &ctxt, snap.cb, snap.cb_arg);
}
/*****************************************************************************
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index ffe6bbc..506139f 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -76,8 +76,7 @@ int ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
struct ble_gap_upd_params *params);
void ble_gap_security_event(uint16_t conn_handle, int status,
struct ble_gap_sec_state *sec_state);
-void ble_gap_passkey_event(uint16_t conn_handle, int status,
- uint8_t passkey_action);
+void ble_gap_passkey_event(uint16_t conn_handle, uint8_t passkey_action);
void ble_gap_key_exchange_event(uint16_t conn_handle,
struct ble_gap_key_parms *key_params);
int ble_gap_ltk_event(uint16_t conn_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 12e3fb0..4ccdbab 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -54,7 +54,7 @@ struct ble_hs_conn {
struct ble_gap_sec_state bhc_sec_state;
- ble_gap_conn_fn *bhc_cb;
+ ble_gap_event_fn *bhc_cb;
void *bhc_cb_arg;
};
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c b/net/nimble/host/src/ble_l2cap_sm.c
index adc52d8..4cf2e3f 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -1565,7 +1565,7 @@ ble_l2cap_sm_rx_pair_req(uint16_t conn_handle, uint8_t op,
if (rc == 0) {
if (passkey_action != BLE_GAP_PKACT_NONE) {
- ble_gap_passkey_event(conn_handle, sm_status, passkey_action);
+ ble_gap_passkey_event(conn_handle, passkey_action);
}
} else {
ble_l2cap_sm_proc_free(proc);
@@ -1616,7 +1616,7 @@ ble_l2cap_sm_rx_pair_rsp(uint16_t conn_handle, uint8_t op,
ble_l2cap_sm_gap_event(proc, rc, 0);
ble_l2cap_sm_proc_free(proc);
} else if (passkey_action != BLE_GAP_PKACT_NONE) {
- ble_gap_passkey_event(conn_handle, sm_status, passkey_action);
+ ble_gap_passkey_event(conn_handle, passkey_action);
}
return rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index ebb9ef8..1f54c54 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -42,18 +42,18 @@ static uint8_t ble_att_svr_test_attr_n[1024];
static int ble_att_svr_test_attr_n_len;
static int
-ble_att_svr_test_misc_gap_cb(int event, int status,
+ble_att_svr_test_misc_gap_cb(int event,
struct ble_gap_conn_ctxt *ctxt, void *arg)
{
switch (event) {
case BLE_GAP_EVENT_NOTIFY:
ble_att_svr_test_n_conn_handle = ctxt->desc->conn_handle;
- ble_att_svr_test_n_attr_handle = ctxt->notify_params->attr_handle;
- TEST_ASSERT_FATAL(ctxt->notify_params->attr_len <=
+ ble_att_svr_test_n_attr_handle = ctxt->notify.attr_handle;
+ TEST_ASSERT_FATAL(ctxt->notify.attr_len <=
sizeof ble_att_svr_test_attr_n);
- ble_att_svr_test_attr_n_len = ctxt->notify_params->attr_len;
- memcpy(ble_att_svr_test_attr_n, ctxt->notify_params->attr_data,
- ctxt->notify_params->attr_len);
+ ble_att_svr_test_attr_n_len = ctxt->notify.attr_len;
+ memcpy(ble_att_svr_test_attr_n, ctxt->notify.attr_data,
+ ctxt->notify.attr_len);
break;
default:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 92e7b3a..cf9c4a3 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -83,26 +83,42 @@ ble_gap_test_util_disc_cb(int event, int status,
}
static int
-ble_gap_test_util_connect_cb(int event, int status,
- struct ble_gap_conn_ctxt *ctxt, void *arg)
+ble_gap_test_util_connect_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ void *arg)
{
int *fail_reason;
+ ble_gap_test_conn_event = event;
+ ble_gap_test_conn_desc = *ctxt->desc;
+ ble_gap_test_conn_arg = arg;
+
switch (event) {
- case BLE_GAP_EVENT_CONN:
- case BLE_GAP_EVENT_CONN_UPDATED:
- case BLE_GAP_EVENT_CANCEL:
+ case BLE_GAP_EVENT_CONNECT:
+ ble_gap_test_conn_status = ctxt->connect.status;
+ break;
+
+ case BLE_GAP_EVENT_DISCONNECT:
+ ble_gap_test_conn_status = ctxt->disconnect.reason;
+ break;
+
+ case BLE_GAP_EVENT_CONN_UPDATE:
+ ble_gap_test_conn_status = ctxt->conn_update.status;
+ break;
+
+ case BLE_GAP_EVENT_CONN_CANCEL:
+ break;
+
case BLE_GAP_EVENT_TERM_FAILURE:
- case BLE_GAP_EVENT_ADV_FINISHED:
- ble_gap_test_conn_event = event;
- ble_gap_test_conn_status = status;
- ble_gap_test_conn_desc = *ctxt->desc;
+ ble_gap_test_conn_status = ctxt->term_failure.status;
+ break;
+
+ case BLE_GAP_EVENT_ADV_COMPLETE:
ble_gap_test_conn_arg = arg;
break;
case BLE_GAP_EVENT_CONN_UPDATE_REQ:
- ble_gap_test_conn_peer_params = *ctxt->update.peer_params;
- *ctxt->update.self_params = ble_gap_test_conn_self_params;
+ ble_gap_test_conn_peer_params = *ctxt->conn_update_req.peer_params;
+ *ctxt->conn_update_req.self_params = ble_gap_test_conn_self_params;
fail_reason = arg;
if (fail_reason == NULL) {
@@ -688,7 +704,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -790,8 +806,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_good)
ble_gap_test_util_conn_cancel(peer_addr, 0);
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CANCEL);
- TEST_ASSERT(ble_gap_test_conn_status == 0);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_CANCEL);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == BLE_HS_CONN_HANDLE_NONE);
}
@@ -821,7 +836,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
peer_addr, 6) == 0);
@@ -891,7 +906,7 @@ TEST_CASE(ble_gap_test_case_conn_terminate_good)
ble_gap_test_util_terminate(peer_addr, 0);
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_DISCONNECT);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_ENOTCONN);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(ble_gap_test_conn_desc.peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
@@ -1109,7 +1124,8 @@ TEST_CASE(ble_gap_test_case_conn_adv_good)
if (c != BLE_GAP_CONN_MODE_NON) {
TEST_ASSERT(!ble_gap_slave_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_event ==
+ BLE_GAP_EVENT_CONNECT);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
@@ -1133,8 +1149,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_ctlr_fail)
TEST_ASSERT(!ble_gap_slave_in_progress());
TEST_ASSERT(ble_gap_test_conn_event ==
- BLE_GAP_EVENT_ADV_FINISHED);
- TEST_ASSERT(ble_gap_test_conn_status == 0);
+ BLE_GAP_EVENT_ADV_COMPLETE);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle ==
BLE_HS_CONN_HANDLE_NONE);
TEST_ASSERT(ble_gap_test_conn_arg == NULL);
@@ -1300,7 +1315,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -1314,7 +1329,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
return;
fail:
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == status);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -1345,7 +1360,7 @@ ble_gap_test_util_update_peer(uint8_t status,
TEST_ASSERT(!ble_gap_master_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
@@ -1400,7 +1415,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
TEST_ASSERT(!ble_gap_master_in_progress());
TEST_ASSERT(!ble_gap_test_util_update_in_progress(2));
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -1412,7 +1427,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
return;
hci_fail:
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -1461,7 +1476,7 @@ ble_gap_test_util_update_req_neg(struct ble_gap_upd_params *peer_params,
return;
hci_fail:
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -1536,7 +1551,7 @@ ble_gap_test_util_update_req_concurrent(
TEST_ASSERT(!ble_gap_master_in_progress());
TEST_ASSERT(!ble_gap_test_util_update_in_progress(2));
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
@@ -1548,7 +1563,7 @@ ble_gap_test_util_update_req_concurrent(
return;
hci_fail:
- TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATED);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(fail_status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index bfb4696..17a33d3 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -309,7 +309,7 @@ ble_hs_test_util_set_ack_seq(struct ble_hs_test_util_phony_ack *acks)
void
ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
- ble_gap_conn_fn *cb, void *cb_arg)
+ ble_gap_event_fn *cb, void *cb_arg)
{
struct hci_le_conn_complete evt;
int rc;
@@ -338,7 +338,7 @@ ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
int
ble_hs_test_util_conn_initiate(int addr_type, uint8_t *addr,
struct ble_gap_crt_params *params,
- ble_gap_conn_fn *cb, void *cb_arg,
+ ble_gap_event_fn *cb, void *cb_arg,
uint8_t ack_status)
{
int rc;
@@ -410,7 +410,7 @@ ble_hs_test_util_adv_start(uint8_t discoverable_mode,
uint8_t connectable_mode,
uint8_t *peer_addr, uint8_t peer_addr_type,
struct hci_adv_params *adv_params,
- ble_gap_conn_fn *cb, void *cb_arg,
+ ble_gap_event_fn *cb, void *cb_arg,
int fail_idx, uint8_t fail_status)
{
struct ble_hs_test_util_phony_ack acks[6];
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index cd75452..ab0e412 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -54,10 +54,10 @@ void ble_hs_test_util_build_cmd_status(uint8_t *dst, int len,
uint8_t status, uint8_t num_pkts,
uint16_t opcode);
void ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
- ble_gap_conn_fn *cb, void *cb_arg);
+ ble_gap_event_fn *cb, void *cb_arg);
int ble_hs_test_util_conn_initiate(int addr_type, uint8_t *addr,
struct ble_gap_crt_params *params,
- ble_gap_conn_fn *cb, void *cb_arg,
+ ble_gap_event_fn *cb, void *cb_arg,
uint8_t ack_status);
int ble_hs_test_util_conn_cancel(uint8_t ack_status);
int ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status);
@@ -69,7 +69,7 @@ int ble_hs_test_util_adv_start(uint8_t discoverable_mode,
uint8_t connectable_mode,
uint8_t *peer_addr, uint8_t peer_addr_type,
struct hci_adv_params *adv_params,
- ble_gap_conn_fn *cb, void *cb_arg,
+ ble_gap_event_fn *cb, void *cb_arg,
int fail_idx, uint8_t fail_status);
int ble_hs_test_util_adv_stop(uint8_t hci_status);
int ble_hs_test_util_wl_set(struct ble_gap_white_entry *white_list,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_l2cap_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_sm_test.c b/net/nimble/host/src/test/ble_l2cap_sm_test.c
index 7530144..cd95ad7 100644
--- a/net/nimble/host/src/test/ble_l2cap_sm_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_sm_test.c
@@ -93,15 +93,16 @@ struct ble_l2cap_sm_test_ltk_info {
};
static int
-ble_l2cap_sm_test_util_conn_cb(int event, int status,
- struct ble_gap_conn_ctxt *ctxt, void *arg)
+ble_l2cap_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ void *arg)
{
struct ble_l2cap_sm_passkey *passkey;
struct ble_l2cap_sm_test_ltk_info *ltk_info;
int rc;
switch (event) {
- case BLE_GAP_EVENT_SECURITY:
+ case BLE_GAP_EVENT_ENC_CHANGE:
+ ble_l2cap_sm_test_gap_status = ctxt->enc_change.status;
ble_l2cap_sm_test_sec_state = ctxt->desc->sec_state;
rc = 0;
break;
@@ -137,7 +138,6 @@ ble_l2cap_sm_test_util_conn_cb(int event, int status,
}
ble_l2cap_sm_test_gap_event = event;
- ble_l2cap_sm_test_gap_status = status;
return rc;
}
@@ -763,7 +763,7 @@ ble_l2cap_sm_test_util_peer_lgcy_fail_confirm(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Verify that security callback was executed. */
- TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_SECURITY);
+ TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
TEST_ASSERT(ble_l2cap_sm_test_gap_status ==
BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_CONFIRM_MISMATCH));
TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg ==
@@ -930,7 +930,7 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Verify that security callback was executed. */
- TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_SECURITY);
+ TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg == params->pair_alg);
TEST_ASSERT(ble_l2cap_sm_test_sec_state.enc_enabled);
@@ -1123,7 +1123,6 @@ ble_l2cap_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
/* Ensure the LTK request event got sent to the application. */
TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_LTK_REQUEST);
- TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
TEST_ASSERT(ble_l2cap_sm_test_ltk_params.ediv == ediv);
TEST_ASSERT(ble_l2cap_sm_test_ltk_params.rand_num == rand_num);
TEST_ASSERT(memcmp(ble_l2cap_sm_test_ltk_params.ltk, ltk_info.ltk,
@@ -1145,7 +1144,7 @@ ble_l2cap_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Verify that security callback was executed. */
- TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_SECURITY);
+ TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
TEST_ASSERT(ble_l2cap_sm_test_sec_state.enc_enabled);
TEST_ASSERT(ble_l2cap_sm_test_sec_state.authenticated ==
@@ -1187,7 +1186,6 @@ ble_l2cap_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
/* Ensure the LTK request event got sent to the application. */
TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_LTK_REQUEST);
- TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
TEST_ASSERT(ble_l2cap_sm_test_ltk_params.ediv == ediv);
TEST_ASSERT(ble_l2cap_sm_test_ltk_params.rand_num == rand_num);
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
@@ -1595,7 +1593,7 @@ ble_l2cap_sm_test_util_us_lgcy_good(
TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
/* Verify that security callback was executed. */
- TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_SECURITY);
+ TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg == params->pair_alg);
TEST_ASSERT(ble_l2cap_sm_test_sec_state.enc_enabled);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 23c0167..161bd55 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -204,7 +204,7 @@ ble_l2cap_test_util_dummy_rx(uint16_t conn_handle, struct os_mbuf **om)
static void
ble_l2cap_test_util_create_conn(uint16_t conn_handle, uint8_t *addr,
- ble_gap_conn_fn *cb, void *cb_arg)
+ ble_gap_event_fn *cb, void *cb_arg)
{
struct ble_l2cap_chan *chan;
struct ble_hs_conn *conn;
@@ -480,8 +480,8 @@ TEST_CASE(ble_l2cap_test_case_sig_unsol_rsp)
*****************************************************************************/
static int
-ble_l2cap_test_util_conn_cb(int event, int status,
- struct ble_gap_conn_ctxt *ctxt, void *arg)
+ble_l2cap_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+ void *arg)
{
int *accept;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37d199cd/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index 0bd2a1d..587bd11 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -48,6 +48,8 @@ static uint8_t ble_os_test_peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
static void ble_os_test_app_task_handler(void *arg);
+static int ble_os_test_gap_event;
+
static void
ble_os_test_init_app_task(void)
{
@@ -94,7 +96,7 @@ ble_os_test_misc_conn_exists(uint16_t conn_handle)
}
static int
-ble_gap_direct_connect_test_connect_cb(int event, int status,
+ble_gap_direct_connect_test_connect_cb(int event,
struct ble_gap_conn_ctxt *ctxt,
void *arg)
{
@@ -103,8 +105,8 @@ ble_gap_direct_connect_test_connect_cb(int event, int status,
cb_called = arg;
*cb_called = 1;
- TEST_ASSERT(event == BLE_GAP_EVENT_CONN);
- TEST_ASSERT(status == 0);
+ TEST_ASSERT(event == BLE_GAP_EVENT_CONNECT);
+ TEST_ASSERT(ctxt->connect.status == 0);
TEST_ASSERT(ctxt->desc->conn_handle == 2);
TEST_ASSERT(ctxt->desc->peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
TEST_ASSERT(memcmp(ctxt->desc->peer_addr, ble_os_test_peer_addr, 6) == 0);
@@ -175,7 +177,7 @@ ble_gap_gen_disc_test_connect_cb(int event, int status,
cb_called = arg;
*cb_called = 1;
- TEST_ASSERT(event == BLE_GAP_EVENT_DISC_FINISHED);
+ TEST_ASSERT(event == BLE_GAP_EVENT_DISC_COMPLETE);
TEST_ASSERT(status == 0);
}
@@ -250,18 +252,16 @@ TEST_CASE(ble_gap_gen_disc_test_case)
}
static int
-ble_gap_terminate_cb(int event, int status,
- struct ble_gap_conn_ctxt *ctxt, void *arg)
+ble_gap_terminate_cb(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
{
int *disconn_handle;
- TEST_ASSERT_FATAL(event == BLE_GAP_EVENT_CONN);
- if (status == 0) {
- return 0;
- }
+ ble_os_test_gap_event = event;
- disconn_handle = arg;
- *disconn_handle = ctxt->desc->conn_handle;
+ if (event == BLE_GAP_EVENT_DISCONNECT) {
+ disconn_handle = arg;
+ *disconn_handle = ctxt->desc->conn_handle;
+ }
return 0;
}
@@ -324,6 +324,7 @@ ble_gap_terminate_test_task_handler(void *arg)
disconn_evt.status = 0;
disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
ble_hs_test_util_rx_disconn_complete_event(&disconn_evt);
+ TEST_ASSERT(ble_os_test_gap_event == BLE_GAP_EVENT_DISCONNECT);
TEST_ASSERT(disconn_handle == 1);
TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(1));
TEST_ASSERT_FATAL(ble_os_test_misc_conn_exists(2));
@@ -335,6 +336,7 @@ ble_gap_terminate_test_task_handler(void *arg)
disconn_evt.status = 0;
disconn_evt.reason = BLE_ERR_REM_USER_CONN_TERM;
ble_hs_test_util_rx_disconn_complete_event(&disconn_evt);
+ TEST_ASSERT(ble_os_test_gap_event == BLE_GAP_EVENT_DISCONNECT);
TEST_ASSERT(disconn_handle == 2);
TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(1));
TEST_ASSERT_FATAL(!ble_os_test_misc_conn_exists(2));