You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/15 04:10:11 UTC
[1/3] incubator-mynewt-larva git commit: Add GAP callback
per-connection, rather than single global.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master a4dd006ed -> 8f2fb6c7e
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 e82c6ff..c2b06ef 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -24,7 +24,7 @@
#include "host/ble_gap.h"
#include "ble_hs_test_util.h"
#include "ble_hs_conn.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#ifdef ARCH_sim
#define BLE_OS_TEST_STACK_SIZE 1024
@@ -64,7 +64,8 @@ ble_os_test_misc_rx_le_ack(uint16_t ocf, uint8_t status)
}
static void
-ble_gap_direct_connect_test_connect_cb(struct ble_gap_conn_event *event,
+ble_gap_direct_connect_test_connect_cb(int event, int status,
+ struct ble_gap_conn_desc *desc,
void *arg)
{
int *cb_called;
@@ -72,11 +73,11 @@ ble_gap_direct_connect_test_connect_cb(struct ble_gap_conn_event *event,
cb_called = arg;
*cb_called = 1;
- TEST_ASSERT(event->type == BLE_GAP_CONN_EVENT_TYPE_CONNECT);
- TEST_ASSERT(event->conn.status == BLE_ERR_SUCCESS);
- TEST_ASSERT(event->conn.handle == 2);
- TEST_ASSERT(memcmp(event->conn.peer_addr, ble_os_test_peer_addr, 6) ==
- 0);
+ TEST_ASSERT(event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(status == 0);
+ TEST_ASSERT(desc->conn_handle == 2);
+ TEST_ASSERT(desc->peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
+ TEST_ASSERT(memcmp(desc->peer_addr, ble_os_test_peer_addr, 6) == 0);
}
static void
@@ -96,7 +97,6 @@ ble_gap_direct_connect_test_task_handler(void *arg)
* proper arguments.
*/
cb_called = 0;
- ble_gap_conn_set_cb(ble_gap_direct_connect_test_connect_cb, &cb_called);
/* Make sure there are no created connections and no connections in
* progress.
@@ -104,7 +104,9 @@ ble_gap_direct_connect_test_task_handler(void *arg)
TEST_ASSERT(ble_hs_conn_first() == NULL);
/* Initiate a direct connection. */
- ble_gap_conn_direct_connect(0, addr);
+ ble_gap_conn_direct_connect(0, addr,
+ ble_gap_direct_connect_test_connect_cb,
+ &cb_called);
TEST_ASSERT(ble_hs_conn_first() == NULL);
TEST_ASSERT(!cb_called);
@@ -145,14 +147,16 @@ TEST_CASE(ble_gap_direct_connect_test_case)
}
static void
-ble_gap_gen_disc_test_connect_cb(struct ble_gap_conn_event *event, void *arg)
+ble_gap_gen_disc_test_connect_cb(int event, int status,
+ struct ble_gap_disc_desc *desc, void *arg)
{
int *cb_called;
cb_called = arg;
*cb_called = 1;
- TEST_ASSERT(event->type == BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE);
+ TEST_ASSERT(event == BLE_GAP_EVENT_DISC_FINISHED);
+ TEST_ASSERT(status == 0);
}
static void
@@ -169,7 +173,6 @@ ble_gap_gen_disc_test_task_handler(void *arg)
* proper arguments.
*/
cb_called = 0;
- ble_gap_conn_set_cb(ble_gap_gen_disc_test_connect_cb, &cb_called);
/* Make sure there are no created connections and no connections in
* progress.
@@ -178,7 +181,8 @@ ble_gap_gen_disc_test_task_handler(void *arg)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
/* Initiate the general discovery procedure with a 200 ms timeout. */
- ble_gap_conn_disc(200, BLE_GAP_DISC_MODE_GEN);
+ ble_gap_conn_disc(200, BLE_GAP_DISC_MODE_GEN,
+ ble_gap_gen_disc_test_connect_cb, &cb_called);
TEST_ASSERT(ble_hs_conn_first() == NULL);
TEST_ASSERT(ble_gap_conn_master_in_progress());
TEST_ASSERT(!cb_called);
@@ -221,20 +225,19 @@ TEST_CASE(ble_gap_gen_disc_test_case)
}
static void
-ble_gap_terminate_cb(struct ble_gap_conn_event *event, void *arg)
+ble_gap_terminate_cb(int event, int status,
+ struct ble_gap_conn_desc *desc, void *arg)
{
int *disconn_handle;
- if (event->type != BLE_GAP_CONN_EVENT_TYPE_TERMINATE) {
+ if (event == BLE_GAP_EVENT_CONN) {
return;
}
+ TEST_ASSERT_FATAL(event == BLE_GAP_EVENT_TERM);
+ TEST_ASSERT_FATAL(status == 0);
disconn_handle = arg;
-
- TEST_ASSERT(event->term.status == 0);
- TEST_ASSERT(event->term.reason == BLE_ERR_REM_USER_CONN_TERM);
-
- *disconn_handle = event->term.handle;
+ *disconn_handle = desc->conn_handle;
}
@@ -245,7 +248,7 @@ ble_gap_terminate_test_task_handler(void *arg)
struct hci_le_conn_complete conn_evt;
uint8_t addr1[6] = { 1, 2, 3, 4, 5, 6 };
uint8_t addr2[6] = { 2, 3, 4, 5, 6, 7 };
- int disconn_handle;;
+ int disconn_handle;
int rc;
/* Receive acknowledgements for the startup sequence. We sent the
@@ -257,7 +260,6 @@ ble_gap_terminate_test_task_handler(void *arg)
* proper arguments.
*/
disconn_handle = 0;
- ble_gap_conn_set_cb(ble_gap_terminate_cb, &disconn_handle);
/* Make sure there are no created connections and no connections in
* progress.
@@ -266,7 +268,8 @@ ble_gap_terminate_test_task_handler(void *arg)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
/* Create two direct connections. */
- ble_gap_conn_direct_connect(0, addr1);
+ ble_gap_conn_direct_connect(0, addr1, ble_gap_terminate_cb,
+ &disconn_handle);
ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
memset(&conn_evt, 0, sizeof conn_evt);
conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
@@ -276,7 +279,8 @@ ble_gap_terminate_test_task_handler(void *arg)
rc = ble_gap_conn_rx_conn_complete(&conn_evt);
TEST_ASSERT(rc == 0);
- ble_gap_conn_direct_connect(0, addr2);
+ ble_gap_conn_direct_connect(0, addr2, ble_gap_terminate_cb,
+ &disconn_handle);
ble_os_test_misc_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
memset(&conn_evt, 0, sizeof conn_evt);
conn_evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
[2/3] incubator-mynewt-larva git commit: Add GAP callback
per-connection, rather than single global.
Posted by cc...@apache.org.
Add GAP callback per-connection, rather than single global.
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/ce53ccfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ce53ccfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ce53ccfd
Branch: refs/heads/master
Commit: ce53ccfd60f65d4e0a8bd93d15aef52598bca98e
Parents: a4dd006
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 14 12:57:17 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 14 19:09:11 2016 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gap.h | 75 ++--
net/nimble/host/src/ble_gap_conn.c | 394 +++++++++++------
net/nimble/host/src/ble_gap_conn.h | 34 --
net/nimble/host/src/ble_gap_priv.h | 35 ++
net/nimble/host/src/ble_hci_ack.c | 2 +-
net/nimble/host/src/ble_hs.c | 2 +-
net/nimble/host/src/ble_hs_adv.h | 1 +
net/nimble/host/src/ble_hs_conn.h | 5 +
net/nimble/host/src/host_hci.c | 2 +-
net/nimble/host/src/test/ble_att_clt_test.c | 3 +-
net/nimble/host/src/test/ble_att_svr_test.c | 3 +-
net/nimble/host/src/test/ble_gap_test.c | 425 +++++++++++++++++--
net/nimble/host/src/test/ble_gatt_conn_test.c | 11 +-
net/nimble/host/src/test/ble_gatt_disc_c_test.c | 6 +-
net/nimble/host/src/test/ble_gatt_disc_d_test.c | 3 +-
net/nimble/host/src/test/ble_gatt_disc_s_test.c | 6 +-
net/nimble/host/src/test/ble_gatt_find_s_test.c | 12 +-
net/nimble/host/src/test/ble_gatt_read_test.c | 33 +-
net/nimble/host/src/test/ble_gatt_write_test.c | 12 +-
.../host/src/test/ble_gatts_notify_test.c | 3 +-
net/nimble/host/src/test/ble_hs_adv_test.c | 5 +-
net/nimble/host/src/test/ble_hs_conn_test.c | 22 +-
net/nimble/host/src/test/ble_hs_test_util.c | 7 +-
net/nimble/host/src/test/ble_hs_test_util.h | 5 +-
net/nimble/host/src/test/ble_l2cap_test.c | 3 +-
net/nimble/host/src/test/ble_os_test.c | 52 +--
26 files changed, 835 insertions(+), 326 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 57cece5..55d1a6b 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -21,62 +21,40 @@
#include "host/ble_hs.h"
struct hci_le_conn_complete;
-/*** XXX: Move to private header. */
-#define BLE_GAP_CONN_EVENT_TYPE_CONNECT 1
-#define BLE_GAP_CONN_EVENT_TYPE_ADV_RPT 2
-#define BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE 3
-#define BLE_GAP_CONN_EVENT_TYPE_TERMINATE 4
-#define BLE_GAP_CONN_EVENT_TYPE_ADV_DONE 5
-#define BLE_GAP_CONN_EVENT_TYPE_WL 6
-int ble_gap_conn_wl_busy(void);
-/**********************************/
-
#define BLE_GAP_ADDR_TYPE_WL 0xff
-struct ble_gap_conn_connect_rpt {
- int status;
- uint16_t handle;
+#define BLE_GAP_EVENT_CONN 0
+#define BLE_GAP_EVENT_CANCEL_FAILURE 1
+#define BLE_GAP_EVENT_TERM 2
+#define BLE_GAP_EVENT_DISC_SUCCESS 3
+#define BLE_GAP_EVENT_DISC_FINISHED 4
+#define BLE_GAP_EVENT_ADV_FINISHED 5
+#define BLE_GAP_EVENT_ADV_FAILURE 6
+#define BLE_GAP_EVENT_ADV_CANCEL_FAILURE 7
+
+struct ble_gap_conn_desc {
+ uint16_t conn_handle;
+ uint8_t peer_addr_type;
uint8_t peer_addr[6];
};
-struct ble_gap_conn_adv_rpt {
+typedef void ble_gap_conn_fn(int event, int status,
+ struct ble_gap_conn_desc *desc, void *arg);
+
+struct ble_gap_disc_desc {
uint8_t event_type;
uint8_t addr_type;
uint8_t length_data;
int8_t rssi;
uint8_t addr[6];
uint8_t *data;
-
- struct ble_hs_adv_fields fields;
+ struct ble_hs_adv_fields *fields;
};
-struct ble_gap_conn_terminate_rpt {
- int status;
- uint16_t handle;
- uint8_t reason;
-};
-
-struct ble_gap_conn_adv_done {
- int status;
-};
-
-struct ble_gap_conn_wl {
- int status;
-};
-
-struct ble_gap_conn_event {
- uint8_t type;
-
- union {
- struct ble_gap_conn_connect_rpt conn;
- struct ble_gap_conn_adv_rpt adv;
- struct ble_gap_conn_terminate_rpt term;
- struct ble_gap_conn_adv_done adv_done;
- struct ble_gap_conn_wl wl;
- };
-};
+typedef void ble_gap_disc_fn(int event, int status,
+ struct ble_gap_disc_desc *desc, void *arg);
-typedef void ble_gap_connect_fn(struct ble_gap_conn_event *event, void *arg);
+typedef void ble_gap_wl_fn(int status, void *arg);
#define BLE_GAP_CONN_MODE_NULL 0
#define BLE_GAP_CONN_MODE_NON 1
@@ -93,15 +71,18 @@ struct ble_gap_white_entry {
uint8_t addr[6];
};
-void ble_gap_conn_set_cb(ble_gap_connect_fn *cb, void *arg);
int ble_gap_conn_advertise(uint8_t discoverable_mode, uint8_t connectable_mode,
- uint8_t *peer_addr, uint8_t peer_addr_type);
+ uint8_t *peer_addr, uint8_t peer_addr_type,
+ ble_gap_conn_fn *cb, void *cb_arg);
int ble_gap_conn_set_adv_fields(struct ble_hs_adv_fields *adv_fields);
-int ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode);
-int ble_gap_conn_direct_connect(int addr_type, uint8_t *addr);
+int ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode,
+ ble_gap_disc_fn *cb, void *cb_arg);
+int ble_gap_conn_direct_connect(int addr_type, uint8_t *addr,
+ ble_gap_conn_fn *cb, void *cb_arg);
int ble_gap_conn_terminate(uint16_t handle);
int ble_gap_conn_cancel(void);
int ble_gap_conn_wl_set(struct ble_gap_white_entry *white_list,
- uint8_t white_list_count);
+ uint8_t white_list_count, ble_gap_wl_fn *cb,
+ void *cb_arg);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/ble_gap_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_conn.c b/net/nimble/host/src/ble_gap_conn.c
index 99e83ef..5229cd3 100644
--- a/net/nimble/host/src/ble_gap_conn.c
+++ b/net/nimble/host/src/ble_gap_conn.c
@@ -26,7 +26,7 @@
#include "ble_hci_ack.h"
#include "ble_hci_sched.h"
#include "ble_gatt_priv.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#define BLE_GAP_CONN_OP_NULL 0
@@ -114,10 +114,14 @@ static struct {
struct {
uint8_t addr_type;
uint8_t addr[6];
+ ble_gap_conn_fn *cb;
+ void *cb_arg;
} conn;
struct {
uint8_t disc_mode;
+ ble_gap_disc_fn *cb;
+ void *cb_arg;
} disc;
};
} ble_gap_conn_master;
@@ -130,6 +134,8 @@ static struct {
uint8_t op;
uint8_t state;
uint8_t disc_mode;
+ ble_gap_conn_fn *cb;
+ void *cb_arg;
uint8_t dir_addr_type;
uint8_t dir_addr[BLE_DEV_ADDR_LEN];
@@ -141,6 +147,9 @@ static struct {
} ble_gap_conn_slave;
static struct {
+ ble_gap_wl_fn *cb;
+ void *cb_arg;
+
struct ble_gap_white_entry *entries;
uint8_t op;
uint8_t state;
@@ -170,9 +179,6 @@ static ble_hci_sched_tx_fn * const ble_gap_conn_dispatch_adv_dir[] = {
[BLE_GAP_CONN_S_STATE_DIR_ADV] = NULL,
};
-static ble_gap_connect_fn *ble_gap_conn_cb;
-static void *ble_gap_conn_arg;
-
static struct os_callout_func ble_gap_conn_master_timer;
static struct os_callout_func ble_gap_conn_slave_timer;
@@ -180,27 +186,48 @@ static struct os_callout_func ble_gap_conn_slave_timer;
* $misc *
*****************************************************************************/
-/**
- * Configures the connection event callback. The callback is executed whenever
- * any of the following events occurs:
- * o Connection creation succeeds.
- * o Connection creation fails.
- * o Connection establishment fails.
- * o Established connection broken.
- */
-void
-ble_gap_conn_set_cb(ble_gap_connect_fn *cb, void *arg)
+static void
+ble_gap_conn_call_conn_cb(struct ble_hs_conn *conn, int event, int status)
{
- ble_gap_conn_cb = cb;
- ble_gap_conn_arg = arg;
+ struct ble_gap_conn_desc desc;
+ ble_gap_conn_fn *cb;
+ void *cb_arg;
+
+ if (conn != NULL) {
+ desc.conn_handle = conn->bhc_handle;
+ desc.peer_addr_type = conn->bhc_addr_type;
+ memcpy(desc.peer_addr, conn->bhc_addr, sizeof desc.peer_addr);
+ cb = conn->bhc_cb;
+ cb_arg = conn->bhc_cb_arg;
+ } else {
+ desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
+ desc.peer_addr_type = ble_gap_conn_master.conn.addr_type;
+ memcpy(desc.peer_addr, ble_gap_conn_master.conn.addr,
+ sizeof desc.peer_addr);
+ cb = ble_gap_conn_master.conn.cb;
+ cb_arg = ble_gap_conn_master.conn.cb_arg;
+ }
+
+ if (cb != NULL) {
+ cb(event, status, &desc, cb_arg);
+ }
}
static void
-ble_gap_conn_call_cb(struct ble_gap_conn_event *event)
+ble_gap_conn_call_slave_cb(int event, int status)
{
- if (ble_gap_conn_cb != NULL) {
- ble_gap_conn_cb(event, ble_gap_conn_arg);
+ struct ble_gap_conn_desc desc;
+
+ if (ble_gap_conn_slave.cb == NULL) {
+ return;
}
+
+ desc.conn_handle = BLE_HS_CONN_HANDLE_NONE;
+ desc.peer_addr_type = ble_gap_conn_slave.dir_addr_type;
+ memcpy(desc.peer_addr, ble_gap_conn_slave.dir_addr,
+ sizeof desc.peer_addr);
+
+ ble_gap_conn_slave.cb(event, status, &desc, ble_gap_conn_slave.cb_arg);
}
/**
@@ -213,66 +240,122 @@ ble_gap_conn_call_cb(struct ble_gap_conn_event *event)
static void
ble_gap_conn_notify_connect(int status, struct ble_hs_conn *conn)
{
- struct ble_gap_conn_event event;
+ ble_gap_conn_call_conn_cb(conn, BLE_GAP_EVENT_CONN, status);
+}
- event.type = BLE_GAP_CONN_EVENT_TYPE_CONNECT;
- event.conn.status = status;
- if (conn != NULL) {
- event.conn.handle = conn->bhc_handle;
- memcpy(event.conn.peer_addr, conn->bhc_addr,
- sizeof event.conn.peer_addr);
- } else {
- event.conn.handle = 0;
- memset(&event.conn.peer_addr, 0, sizeof event.conn.peer_addr);
+static void
+ble_gap_conn_notify_term(int status, struct ble_hs_conn *conn)
+{
+ ble_gap_conn_call_conn_cb(conn, BLE_GAP_EVENT_TERM, status);
+}
+
+static void
+ble_gap_conn_notify_disc(struct ble_hs_adv *adv,
+ struct ble_hs_adv_fields *fields)
+{
+ struct ble_gap_disc_desc desc;
+
+ if (ble_gap_conn_master.disc.cb == NULL) {
+ return;
}
- ble_gap_conn_call_cb(&event);
+ desc.event_type = adv->event_type;
+ desc.addr_type = adv->addr_type;
+ desc.length_data = adv->length_data;
+ desc.rssi = adv->rssi;
+ memcpy(desc.addr, adv->addr, sizeof adv->addr);
+ desc.data = adv->data;
+ desc.fields = fields;
+
+ ble_gap_conn_master.disc.cb(BLE_GAP_EVENT_DISC_SUCCESS, 0, &desc,
+ ble_gap_conn_master.disc.cb_arg);
}
static void
-ble_gap_conn_notify_terminate(uint16_t handle, int status, uint8_t reason)
+ble_gap_conn_notify_master_conn_failure(int status)
{
- struct ble_gap_conn_event event;
+ ble_gap_conn_call_conn_cb(NULL, BLE_GAP_EVENT_CONN, status);
+}
- event.type = BLE_GAP_CONN_EVENT_TYPE_TERMINATE;
- event.term.handle = handle;
- event.term.status = status;
- event.term.reason = reason;
+static void
+ble_gap_conn_notify_master_cancel_failure(int status)
+{
+ ble_gap_conn_call_conn_cb(NULL, BLE_GAP_EVENT_CANCEL_FAILURE, status);
+}
- ble_gap_conn_call_cb(&event);
+static void
+ble_gap_conn_notify_master_disc_failure(int status)
+{
+ struct ble_gap_disc_desc desc;
+
+ if (ble_gap_conn_master.disc.cb == NULL) {
+ return;
+ }
+
+ memset(&desc, 0, sizeof desc);
+ ble_gap_conn_master.disc.cb(BLE_GAP_EVENT_DISC_FINISHED, status, &desc,
+ ble_gap_conn_master.disc.cb_arg);
}
static void
-ble_gap_conn_notify_adv_done(int status)
+ble_gap_conn_notify_master_term_failure(int status, uint16_t conn_handle)
{
- struct ble_gap_conn_event event;
+ struct ble_hs_conn *conn;
- event.type = BLE_GAP_CONN_EVENT_TYPE_ADV_DONE;
- event.adv_done.status = status;
+ conn = ble_hs_conn_find(conn_handle);
+ if (conn == NULL) {
+ /* XXX: Stat. */
+ return;
+ }
- ble_gap_conn_call_cb(&event);
+ ble_gap_conn_notify_term(status, conn);
}
static void
-ble_gap_conn_notify_wl(int status)
+ble_gap_conn_notify_slave_conn_failure(int status)
+{
+ ble_gap_conn_call_slave_cb(BLE_GAP_EVENT_CONN, status);
+}
+
+static void
+ble_gap_conn_notify_slave_adv_failure(int status)
+{
+ ble_gap_conn_call_slave_cb(BLE_GAP_EVENT_ADV_FAILURE, status);
+}
+
+static void
+ble_gap_conn_notify_adv_finished(void)
+{
+ ble_gap_conn_call_slave_cb(BLE_GAP_EVENT_ADV_FINISHED, 0);
+}
+
+static void
+ble_gap_conn_notify_slave_adv_cancel_failure(int status)
{
- struct ble_gap_conn_event event;
+ ble_gap_conn_call_slave_cb(BLE_GAP_EVENT_ADV_CANCEL_FAILURE, status);
+}
- event.type = BLE_GAP_CONN_EVENT_TYPE_WL;
- event.wl.status = status;
+static void
+ble_gap_conn_notify_wl(int status)
+{
+ if (ble_gap_conn_wl.cb == NULL) {
+ return;
+ }
- ble_gap_conn_call_cb(&event);
+ ble_gap_conn_wl.cb(status, ble_gap_conn_wl.cb_arg);
}
static void
ble_gap_conn_master_reset_state(void)
{
+ os_callout_stop(&ble_gap_conn_master_timer.cf_c);
ble_gap_conn_master.op = BLE_GAP_CONN_OP_NULL;
}
static void
ble_gap_conn_slave_reset_state(void)
{
+ os_callout_stop(&ble_gap_conn_slave_timer.cf_c);
ble_gap_conn_slave.op = BLE_GAP_CONN_OP_NULL;
}
@@ -284,9 +367,10 @@ ble_gap_conn_slave_reset_state(void)
static void
ble_gap_conn_master_failed(int status)
{
- struct ble_gap_conn_event event;
uint8_t old_proc;
+ assert(ble_gap_conn_master.op != BLE_GAP_CONN_OP_NULL);
+
os_callout_stop(&ble_gap_conn_master_timer.cf_c);
old_proc = ble_gap_conn_master.op;
@@ -294,12 +378,11 @@ ble_gap_conn_master_failed(int status)
switch (old_proc) {
case BLE_GAP_CONN_OP_M_DISC:
- event.type = BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE;
- ble_gap_conn_call_cb(&event);
+ ble_gap_conn_notify_master_disc_failure(status);
break;
case BLE_GAP_CONN_OP_M_CONN:
- ble_gap_conn_notify_connect(status, NULL);
+ ble_gap_conn_notify_master_conn_failure(status);
break;
default:
@@ -314,10 +397,8 @@ ble_gap_conn_master_failed(int status)
static void
ble_gap_conn_slave_failed(int status)
{
- os_callout_stop(&ble_gap_conn_slave_timer.cf_c);
-
+ ble_gap_conn_notify_slave_conn_failure(status);
ble_gap_conn_slave_reset_state();
- ble_gap_conn_notify_connect(status, NULL);
}
static void
@@ -332,19 +413,20 @@ ble_gap_conn_rx_disconn_complete(struct hci_disconn_complete *evt)
{
struct ble_hs_conn *conn;
- /* Find the connection that this event refers to. */
- conn = ble_hs_conn_find(evt->connection_handle);
- if (conn == NULL) {
- return;
- }
-
if (evt->status == 0) {
+ /* Find the connection that this event refers to. */
+ conn = ble_hs_conn_find(evt->connection_handle);
+ if (conn == NULL) {
+ return;
+ }
+ ble_gap_conn_notify_term(0, conn);
ble_hs_conn_remove(conn);
ble_hs_conn_free(conn);
+ } else {
+ ble_gap_conn_notify_master_term_failure(BLE_HS_HCI_ERR(evt->status),
+ evt->connection_handle);
}
- ble_gap_conn_notify_terminate(evt->connection_handle, evt->status,
- evt->reason);
ble_gattc_connection_broken(evt->connection_handle);
}
@@ -367,6 +449,28 @@ ble_gap_conn_slave_in_progress(void)
}
static int
+ble_gap_conn_currently_advertising(void)
+{
+ switch (ble_gap_conn_slave.op) {
+ case BLE_GAP_CONN_OP_NULL:
+ return 0;
+
+ case BLE_GAP_CONN_S_OP_NON:
+ return ble_gap_conn_slave.state == BLE_GAP_CONN_S_STATE_UND_ADV;
+
+ case BLE_GAP_CONN_S_OP_UND:
+ return ble_gap_conn_slave.state == BLE_GAP_CONN_S_STATE_UND_ADV;
+
+ case BLE_GAP_CONN_S_OP_DIR:
+ return ble_gap_conn_slave.state == BLE_GAP_CONN_S_STATE_DIR_ADV;
+
+ default:
+ assert(0);
+ return 0;
+ }
+}
+
+static int
ble_gap_conn_master_enqueue(uint8_t state, int in_progress,
ble_hci_sched_tx_fn *hci_tx_cb, void *cb_arg)
{
@@ -418,9 +522,6 @@ ble_gap_conn_accept_master_conn(uint8_t addr_type, uint8_t *addr)
(addr_type == ble_gap_conn_master.conn.addr_type &&
memcmp(addr, ble_gap_conn_master.conn.addr,
BLE_DEV_ADDR_LEN) == 0)) {
-
- os_callout_stop(&ble_gap_conn_master_timer.cf_c);
- ble_gap_conn_master_reset_state();
return 0;
} else {
ble_gap_conn_master_failed(BLE_HS_ECONTROLLER);
@@ -452,33 +553,25 @@ ble_gap_conn_accept_master_conn(uint8_t addr_type, uint8_t *addr)
static int
ble_gap_conn_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
{
+ if (!ble_gap_conn_currently_advertising()) {
+ return BLE_HS_ENOENT;
+ }
+
switch (ble_gap_conn_slave.op) {
case BLE_GAP_CONN_OP_NULL:
case BLE_GAP_CONN_S_OP_NON:
return BLE_HS_ENOENT;
case BLE_GAP_CONN_S_OP_UND:
- if (ble_gap_conn_slave.state != BLE_GAP_CONN_S_STATE_UND_ADV) {
- return BLE_HS_ENOENT;
- }
-
- os_callout_stop(&ble_gap_conn_slave_timer.cf_c);
- ble_gap_conn_slave_reset_state();
return 0;
case BLE_GAP_CONN_S_OP_DIR:
- if (ble_gap_conn_slave.state != BLE_GAP_CONN_S_STATE_DIR_ADV) {
- return BLE_HS_ENOENT;
- }
-
- if (ble_gap_conn_slave.dir_addr_type == addr_type &&
- memcmp(ble_gap_conn_slave.dir_addr, addr, BLE_DEV_ADDR_LEN) == 0) {
+ if (ble_gap_conn_slave.dir_addr_type != addr_type ||
+ memcmp(ble_gap_conn_slave.dir_addr, addr, BLE_DEV_ADDR_LEN) != 0) {
- os_callout_stop(&ble_gap_conn_slave_timer.cf_c);
- ble_gap_conn_slave_reset_state();
- return 0;
- } else {
return BLE_HS_ENOENT;
+ } else {
+ return 0;
}
default:
@@ -490,7 +583,7 @@ ble_gap_conn_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
void
ble_gap_conn_rx_adv_report(struct ble_hs_adv *adv)
{
- struct ble_gap_conn_event event;
+ struct ble_hs_adv_fields fields;
int rc;
if (ble_gap_conn_master.op != BLE_GAP_CONN_OP_M_DISC &&
@@ -499,28 +592,19 @@ ble_gap_conn_rx_adv_report(struct ble_hs_adv *adv)
return;
}
- rc = ble_hs_adv_parse_fields(&event.adv.fields, adv->data,
- adv->length_data);
+ rc = ble_hs_adv_parse_fields(&fields, adv->data, adv->length_data);
if (rc != 0) {
/* XXX: Increment stat. */
return;
}
if (ble_gap_conn_master.disc.disc_mode == BLE_GAP_DISC_MODE_LTD &&
- !(event.adv.fields.flags & BLE_HS_ADV_F_DISC_LTD)) {
+ !(fields.flags & BLE_HS_ADV_F_DISC_LTD)) {
return;
}
- event.type = BLE_GAP_CONN_EVENT_TYPE_ADV_RPT;
- event.adv.event_type = adv->event_type;
- event.adv.addr_type = adv->addr_type;
- event.adv.length_data = adv->length_data;
- event.adv.rssi = adv->rssi;
- memcpy(event.adv.addr, adv->addr, sizeof event.adv.addr);
- event.adv.data = adv->data;
-
- ble_gap_conn_call_cb(&event);
+ ble_gap_conn_notify_disc(adv, &fields);
}
/**
@@ -530,6 +614,7 @@ int
ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
{
struct ble_hs_conn *conn;
+ int status;
int rc;
/* Determine if this event refers to a completed connection or a connection
@@ -539,6 +624,7 @@ ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
/* Apply the event to the existing connection if it exists. */
if (conn != NULL) {
+ /* XXX: Does this ever happen? */
if (evt->status != 0) {
ble_hs_conn_remove(conn);
ble_gap_conn_notify_connect(evt->status, conn);
@@ -551,13 +637,15 @@ ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
/* This event refers to a new connection. */
if (evt->status != BLE_ERR_SUCCESS) {
+ status = BLE_HS_HCI_ERR(evt->status);
+
switch (evt->role) {
case BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER:
- ble_gap_conn_master_failed(evt->status);
+ ble_gap_conn_master_failed(status);
break;
case BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE:
- ble_gap_conn_slave_failed(evt->status);
+ ble_gap_conn_notify_slave_conn_failure(status);
break;
default:
@@ -572,9 +660,7 @@ ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
case BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER:
rc = ble_gap_conn_accept_master_conn(evt->peer_addr_type,
evt->peer_addr);
- if (rc == 0) {
- ble_gap_conn_master_reset_state();
- } else {
+ if (rc != 0) {
return rc;
}
break;
@@ -582,9 +668,7 @@ ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
case BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE:
rc = ble_gap_conn_accept_slave_conn(evt->peer_addr_type,
evt->peer_addr);
- if (rc == 0) {
- ble_gap_conn_slave_reset_state();
- } else {
+ if (rc != 0) {
return rc;
}
break;
@@ -600,9 +684,17 @@ ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt)
conn->bhc_handle = evt->connection_handle;
memcpy(conn->bhc_addr, evt->peer_addr, sizeof conn->bhc_addr);
+ if (evt->role == BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER) {
+ conn->bhc_cb = ble_gap_conn_master.conn.cb;
+ conn->bhc_cb_arg = ble_gap_conn_master.conn.cb_arg;
+ ble_gap_conn_master_reset_state();
+ } else {
+ conn->bhc_cb = ble_gap_conn_slave.cb;
+ conn->bhc_cb_arg = ble_gap_conn_slave.cb_arg;
+ ble_gap_conn_slave_reset_state();
+ }
ble_hs_conn_insert(conn);
-
ble_gap_conn_notify_connect(0, conn);
return 0;
@@ -761,7 +853,7 @@ ble_gap_conn_wl_tx_clear(void *arg)
int
ble_gap_conn_wl_set(struct ble_gap_white_entry *white_list,
- uint8_t white_list_count)
+ uint8_t white_list_count, ble_gap_wl_fn *cb, void *cb_arg)
{
int rc;
int i;
@@ -782,13 +874,15 @@ ble_gap_conn_wl_set(struct ble_gap_white_entry *white_list,
return BLE_HS_EBUSY;
}
+ ble_gap_conn_wl.cb = cb;
+ ble_gap_conn_wl.cb_arg = cb_arg;
ble_gap_conn_wl.op = BLE_GAP_CONN_OP_W_SET;
ble_gap_conn_wl.entries = white_list;
ble_gap_conn_wl.count = white_list_count;
ble_gap_conn_wl.cur = 0;
- rc = ble_gap_conn_master_enqueue(BLE_GAP_CONN_STATE_W_CLEAR, 0,
- ble_gap_conn_wl_tx_clear, NULL);
+ rc = ble_gap_conn_wl_enqueue(BLE_GAP_CONN_STATE_W_CLEAR, 0,
+ ble_gap_conn_wl_tx_clear, NULL);
return rc;
}
@@ -799,10 +893,15 @@ ble_gap_conn_wl_set(struct ble_gap_white_entry *white_list,
static void
ble_gap_conn_adv_ack_disable(struct ble_hci_ack *ack, void *arg)
{
+ int status;
+
if (ack->bha_status == 0) {
/* Advertising should now be aborted. */
+ ble_gap_conn_notify_adv_finished();
ble_gap_conn_slave_reset_state();
- ble_gap_conn_notify_adv_done(0);
+ } else {
+ status = BLE_HS_HCI_ERR(ack->bha_status);
+ ble_gap_conn_notify_slave_adv_cancel_failure(status);
}
}
@@ -814,7 +913,7 @@ ble_gap_conn_adv_disable_tx(void *arg)
ble_hci_ack_set_callback(ble_gap_conn_adv_ack_disable, NULL);
rc = host_hci_cmd_le_set_adv_enable(0);
if (rc != BLE_ERR_SUCCESS) {
- ble_gap_conn_notify_adv_done(BLE_HS_ECONTROLLER);
+ ble_gap_conn_notify_slave_adv_cancel_failure(BLE_HS_HCI_ERR(rc));
return 1;
}
@@ -822,15 +921,18 @@ ble_gap_conn_adv_disable_tx(void *arg)
}
static int
-ble_gap_conn_adv_stop(void)
+ble_gap_conn_adv_stop(ble_gap_conn_fn *cb, void *cb_arg)
{
int rc;
/* Do nothing if advertising is already disabled. */
- if (ble_gap_conn_slave.op == BLE_GAP_CONN_OP_NULL) {
+ if (!ble_gap_conn_currently_advertising()) {
return BLE_HS_EALREADY;
}
+ ble_gap_conn_slave.cb = cb;
+ ble_gap_conn_slave.cb_arg = cb_arg;
+
rc = ble_hci_sched_enqueue(ble_gap_conn_adv_disable_tx, NULL);
if (rc != 0) {
return rc;
@@ -873,7 +975,7 @@ ble_gap_conn_adv_next_state(void)
if (tx_fn != NULL) {
rc = ble_hci_sched_enqueue(tx_fn, NULL);
if (rc != 0) {
- ble_gap_conn_slave_failed(rc);
+ ble_gap_conn_notify_slave_adv_failure(rc);
}
}
}
@@ -882,7 +984,7 @@ static void
ble_gap_conn_adv_ack(struct ble_hci_ack *ack, void *arg)
{
if (ack->bha_status != 0) {
- ble_gap_conn_slave_failed(ack->bha_status);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(ack->bha_status));
} else {
ble_gap_conn_adv_next_state();
}
@@ -896,7 +998,7 @@ ble_gap_conn_adv_enable_tx(void *arg)
ble_hci_ack_set_callback(ble_gap_conn_adv_ack, NULL);
rc = host_hci_cmd_le_set_adv_enable(1);
if (rc != BLE_ERR_SUCCESS) {
- ble_gap_conn_slave_failed(rc);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(rc));
return 1;
}
@@ -912,7 +1014,7 @@ ble_gap_conn_adv_rsp_data_tx(void *arg)
ble_hci_ack_set_callback(ble_gap_conn_adv_ack, NULL);
rc = host_hci_cmd_le_set_scan_rsp_data(rsp_data, sizeof rsp_data);
if (rc != 0) {
- ble_gap_conn_slave_failed(rc);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(rc));
return 1;
}
@@ -967,7 +1069,7 @@ ble_gap_conn_adv_data_tx(void *arg)
rc = host_hci_cmd_le_set_adv_data(ble_gap_conn_slave.adv_data,
adv_data_len);
if (rc != 0) {
- ble_gap_conn_slave_failed(rc);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(rc));
return 1;
}
@@ -980,12 +1082,12 @@ ble_gap_conn_adv_power_ack(struct ble_hci_ack *ack, void *arg)
int8_t power_level;
if (ack->bha_status != 0) {
- ble_gap_conn_slave_failed(ack->bha_status);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(ack->bha_status));
return;
}
if (ack->bha_params_len != BLE_HCI_ADV_CHAN_TXPWR_ACK_PARAM_LEN) {
- ble_gap_conn_slave_failed(BLE_HS_ECONTROLLER);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_ECONTROLLER);
return;
}
@@ -996,7 +1098,7 @@ ble_gap_conn_adv_power_ack(struct ble_hci_ack *ack, void *arg)
/* XXX: Probably can do something nicer than abort the entire
* procedure.
*/
- ble_gap_conn_slave_failed(BLE_HS_ECONTROLLER);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_ECONTROLLER);
return;
}
@@ -1014,7 +1116,7 @@ ble_gap_conn_adv_power_tx(void *arg)
ble_hci_ack_set_callback(ble_gap_conn_adv_power_ack, NULL);
rc = host_hci_cmd_read_adv_pwr();
if (rc != 0) {
- ble_gap_conn_slave_failed(rc);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(rc));
return 1;
}
@@ -1052,7 +1154,7 @@ ble_gap_conn_adv_params_tx(void *arg)
ble_hci_ack_set_callback(ble_gap_conn_adv_ack, NULL);
rc = host_hci_cmd_le_set_adv_params(&hap);
if (rc != 0) {
- ble_gap_conn_slave_failed(rc);
+ ble_gap_conn_notify_slave_adv_failure(BLE_HS_HCI_ERR(rc));
return 1;
}
@@ -1108,23 +1210,25 @@ ble_gap_conn_adv_initiate(void)
*/
int
ble_gap_conn_advertise(uint8_t discoverable_mode, uint8_t connectable_mode,
- uint8_t *peer_addr, uint8_t peer_addr_type)
+ uint8_t *peer_addr, uint8_t peer_addr_type,
+ ble_gap_conn_fn *cb, void *cb_arg)
{
int rc;
- if (discoverable_mode == BLE_GAP_DISC_MODE_NULL ||
- connectable_mode == BLE_GAP_DISC_MODE_NULL) {
-
- rc = ble_gap_conn_adv_stop();
- return rc;
- }
-
if (discoverable_mode >= BLE_GAP_DISC_MODE_MAX ||
connectable_mode >= BLE_GAP_CONN_MODE_MAX) {
return BLE_HS_EINVAL;
}
+ /* Process a request to stop advertising separately. */
+ if (discoverable_mode == BLE_GAP_DISC_MODE_NULL ||
+ connectable_mode == BLE_GAP_DISC_MODE_NULL) {
+
+ rc = ble_gap_conn_adv_stop(cb, cb_arg);
+ return rc;
+ }
+
/* Make sure no slave connection attempt is already in progress. */
if (ble_gap_conn_slave_in_progress()) {
return BLE_HS_EALREADY;
@@ -1139,6 +1243,9 @@ ble_gap_conn_advertise(uint8_t discoverable_mode, uint8_t connectable_mode,
return BLE_HS_ENOMEM;
}
+ ble_gap_conn_slave.cb = cb;
+ ble_gap_conn_slave.cb_arg = cb_arg;
+
switch (connectable_mode) {
case BLE_GAP_CONN_MODE_NON:
ble_gap_conn_slave.op = BLE_GAP_CONN_S_OP_NON;
@@ -1264,7 +1371,8 @@ ble_gap_conn_disc_tx_params(void *arg)
* @return 0 on success; nonzero on failure.
*/
int
-ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode)
+ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode,
+ ble_gap_disc_fn *cb, void *cb_arg)
{
int rc;
@@ -1285,6 +1393,8 @@ ble_gap_conn_disc(uint32_t duration_ms, uint8_t discovery_mode)
ble_gap_conn_master.op = BLE_GAP_CONN_OP_M_DISC;
ble_gap_conn_master.disc.disc_mode = discovery_mode;
+ ble_gap_conn_master.disc.cb = cb;
+ ble_gap_conn_master.disc.cb_arg = cb_arg;
rc = ble_gap_conn_master_enqueue(BLE_GAP_CONN_M_STATE_DISC_PARAMS, 0,
ble_gap_conn_disc_tx_params, NULL);
if (rc != 0) {
@@ -1375,7 +1485,8 @@ ble_gap_conn_direct_connect_tx(void *arg)
* @return 0 on success; nonzero on failure.
*/
int
-ble_gap_conn_direct_connect(int addr_type, uint8_t *addr)
+ble_gap_conn_direct_connect(int addr_type, uint8_t *addr,
+ ble_gap_conn_fn *cb, void *cb_arg)
{
int rc;
@@ -1393,6 +1504,8 @@ ble_gap_conn_direct_connect(int addr_type, uint8_t *addr)
ble_gap_conn_master.op = BLE_GAP_CONN_OP_M_CONN;
ble_gap_conn_master.conn.addr_type = addr_type;
+ ble_gap_conn_master.conn.cb = cb;
+ ble_gap_conn_master.conn.cb_arg = cb_arg;
if (addr_type != BLE_GAP_ADDR_TYPE_WL) {
memcpy(ble_gap_conn_master.conn.addr, addr, BLE_DEV_ADDR_LEN);
@@ -1415,11 +1528,12 @@ static void
ble_gap_conn_terminate_ack(struct ble_hci_ack *ack, void *arg)
{
uint16_t handle;
-
- handle = (uintptr_t)arg;
+ int status;
if (ack->bha_status != 0) {
- ble_gap_conn_notify_terminate(handle, ack->bha_status, 0);
+ handle = (uintptr_t)arg;
+ status = BLE_HS_HCI_ERR(ack->bha_status);
+ ble_gap_conn_notify_master_term_failure(status, handle);
}
}
@@ -1435,7 +1549,7 @@ ble_gap_conn_terminate_tx(void *arg)
rc = host_hci_cmd_disconnect(handle, BLE_ERR_REM_USER_CONN_TERM);
if (rc != 0) {
- return rc;
+ ble_gap_conn_notify_master_term_failure(rc, handle);
}
return 0;
@@ -1466,9 +1580,11 @@ ble_gap_conn_terminate(uint16_t handle)
static void
ble_gap_conn_cancel_ack(struct ble_hci_ack *ack, void *arg)
{
+ int status;
+
if (ack->bha_status != 0) {
- /* XXX: This may be ambiguous to the application. */
- ble_gap_conn_notify_connect(BLE_HS_ECONTROLLER, NULL);
+ status = BLE_HS_HCI_ERR(ack->bha_status);
+ ble_gap_conn_notify_master_cancel_failure(status);
}
}
@@ -1481,7 +1597,7 @@ ble_gap_conn_cancel_tx(void *arg)
rc = host_hci_cmd_le_create_conn_cancel();
if (rc != 0) {
- return 1;
+ ble_gap_conn_notify_master_cancel_failure(rc);
}
return 0;
@@ -1493,7 +1609,7 @@ ble_gap_conn_cancel(void)
int rc;
if (!ble_gap_conn_master_in_progress()) {
- return BLE_HS_EALREADY;
+ return BLE_HS_ENOENT;
}
rc = ble_hci_sched_enqueue(ble_gap_conn_cancel_tx, NULL);
@@ -1525,9 +1641,9 @@ ble_gap_conn_init_slave_params(void)
int
ble_gap_conn_init(void)
{
- ble_gap_conn_cb = NULL;
ble_gap_conn_master.op = BLE_GAP_CONN_OP_NULL;
ble_gap_conn_slave.op = BLE_GAP_CONN_OP_NULL;
+ ble_gap_conn_wl.op = BLE_GAP_CONN_OP_NULL;
ble_gap_conn_init_slave_params();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/ble_gap_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_conn.h b/net/nimble/host/src/ble_gap_conn.h
deleted file mode 100644
index cb1b52b..0000000
--- a/net/nimble/host/src/ble_gap_conn.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef H_BLE_GAP_CONN_
-#define H_BLE_GAP_CONN_
-
-#include <inttypes.h>
-#include "host/ble_gap.h"
-struct hci_le_conn_complete;
-struct hci_disconn_complete;
-struct ble_hci_ack;
-struct ble_hs_adv;
-
-void ble_gap_conn_rx_adv_report(struct ble_hs_adv *adv);
-int ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt);
-void ble_gap_conn_rx_disconn_complete(struct hci_disconn_complete *evt);
-int ble_gap_conn_master_in_progress(void);
-int ble_gap_conn_slave_in_progress(void);
-int ble_gap_conn_init(void);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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
new file mode 100644
index 0000000..bd514b9
--- /dev/null
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_BLE_GAP_CONN_
+#define H_BLE_GAP_CONN_
+
+#include <inttypes.h>
+#include "host/ble_gap.h"
+struct hci_le_conn_complete;
+struct hci_disconn_complete;
+struct ble_hci_ack;
+struct ble_hs_adv;
+
+void ble_gap_conn_rx_adv_report(struct ble_hs_adv *adv);
+int ble_gap_conn_rx_conn_complete(struct hci_le_conn_complete *evt);
+void ble_gap_conn_rx_disconn_complete(struct hci_disconn_complete *evt);
+int ble_gap_conn_master_in_progress(void);
+int ble_gap_conn_slave_in_progress(void);
+int ble_gap_conn_wl_busy(void);
+int ble_gap_conn_init(void);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/ble_hci_ack.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_ack.c b/net/nimble/host/src/ble_hci_ack.c
index c1cce92..2bd7d5d 100644
--- a/net/nimble/host/src/ble_hci_ack.c
+++ b/net/nimble/host/src/ble_hci_ack.c
@@ -19,7 +19,7 @@
#include <stddef.h>
#include "nimble/ble.h"
#include "nimble/hci_common.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#include "ble_hs_conn.h"
#include "ble_hci_sched.h"
#include "ble_hci_ack.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 73296b5..4a89200 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -27,7 +27,7 @@
#include "ble_hs_startup.h"
#include "ble_hci_ack.h"
#include "ble_hci_sched.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#ifdef PHONY_TRANSPORT
#include "host/ble_hs_test.h"
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/ble_hs_adv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.h b/net/nimble/host/src/ble_hs_adv.h
index c54632f..376e9a3 100644
--- a/net/nimble/host/src/ble_hs_adv.h
+++ b/net/nimble/host/src/ble_hs_adv.h
@@ -27,6 +27,7 @@ struct ble_hs_adv {
int8_t rssi;
uint8_t addr[6];
uint8_t *data;
+ struct ble_hs_adv_fields *fields;
};
#define BLE_HS_ADV_TYPE_FLAGS 0x01
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/ble_hs_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.h b/net/nimble/host/src/ble_hs_conn.h
index 55a4f96..d08713a 100644
--- a/net/nimble/host/src/ble_hs_conn.h
+++ b/net/nimble/host/src/ble_hs_conn.h
@@ -18,6 +18,7 @@
#define H_BLE_HS_CONN_
#include "os/queue.h"
+#include "host/ble_gap.h"
#include "ble_l2cap.h"
#include "ble_att_priv.h"
#include "ble_gatt_priv.h"
@@ -28,6 +29,7 @@ struct ble_l2cap_chan;
struct ble_hs_conn {
SLIST_ENTRY(ble_hs_conn) bhc_next;
uint16_t bhc_handle;
+ uint8_t bhc_addr_type;
uint8_t bhc_addr[6];
struct ble_l2cap_chan_list bhc_channels;
@@ -35,6 +37,9 @@ struct ble_hs_conn {
struct ble_att_svr_conn bhc_att_svr;
struct ble_gatts_conn bhc_gatt_svr;
+
+ ble_gap_conn_fn *bhc_cb;
+ void *bhc_cb_arg;
};
int ble_hs_conn_can_alloc(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index aff9504..5867311 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -28,7 +28,7 @@
#include "ble_hs_conn.h"
#include "ble_l2cap.h"
#include "ble_hci_ack.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#include "ble_hs_adv.h"
_Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_clt_test.c b/net/nimble/host/src/test/ble_att_clt_test.c
index 13d34d7..4e25b94 100644
--- a/net/nimble/host/src/test/ble_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_att_clt_test.c
@@ -31,7 +31,8 @@ ble_att_clt_test_misc_init(struct ble_hs_conn **conn,
{
ble_hs_test_util_init();
- *conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ *conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
*att_chan = ble_hs_conn_chan_find(*conn, BLE_L2CAP_CID_ATT);
TEST_ASSERT_FATAL(*att_chan != NULL);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 ffe3b0a..13a8ff4 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -49,7 +49,8 @@ ble_att_svr_test_misc_init(struct ble_hs_conn **conn,
{
ble_hs_test_util_init();
- ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
*conn = ble_hs_conn_find(2);
TEST_ASSERT_FATAL(*conn != NULL);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 6f6a211..485b1a8 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -19,27 +19,71 @@
#include "testutil/testutil.h"
#include "nimble/ble.h"
#include "nimble/hci_common.h"
-#include "ble_hs_priv.h"
#include "host/ble_hs_test.h"
+#include "ble_hs_priv.h"
#include "ble_hs_conn.h"
#include "ble_hci_sched.h"
#include "ble_gatt_priv.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#include "ble_hs_test_util.h"
-struct ble_gap_conn_event ble_gap_test_conn_event;
+static int ble_gap_test_conn_event;
+static int ble_gap_test_conn_status;
+static struct ble_gap_conn_desc ble_gap_test_conn_desc;
+static void *ble_gap_test_conn_arg;
+
+static int ble_gap_test_wl_status;
+static void *ble_gap_test_wl_arg;
static void
-ble_gap_test_misc_connect_cb(struct ble_gap_conn_event *event, void *arg)
+ble_gap_test_misc_init(void)
{
- ble_gap_test_conn_event = *event;
+ ble_hs_test_util_init();
+
+ ble_gap_test_conn_event = -1;
+ memset(&ble_gap_test_conn_desc, 0xff, sizeof ble_gap_test_conn_desc);
+ ble_gap_test_conn_arg = (void *)-1;
+
+ ble_gap_test_wl_status = -1;
+ ble_gap_test_wl_arg = (void *)-1;
}
static void
-ble_gap_test_misc_init(void)
+ble_gap_test_misc_connect_cb(int event, int status,
+ struct ble_gap_conn_desc *desc, void *arg)
{
- ble_hs_test_util_init();
- ble_gap_conn_set_cb(ble_gap_test_misc_connect_cb, NULL);
+ ble_gap_test_conn_event = event;
+ ble_gap_test_conn_status = status;
+ ble_gap_test_conn_desc = *desc;
+ ble_gap_test_conn_arg = arg;
+}
+
+static void
+ble_gap_test_misc_wl_cb(int status, void *arg)
+{
+ ble_gap_test_wl_status = status;
+ ble_gap_test_wl_arg = arg;
+}
+
+static int
+ble_gap_test_misc_rx_hci_ack(int *cmd_idx, int cmd_fail_idx,
+ uint8_t ogf, uint16_t ocf, uint8_t fail_status)
+{
+ uint16_t opcode;
+ int cur_idx;
+
+ opcode = (ogf << 10) | ocf;
+
+ cur_idx = *cmd_idx;
+ (*cmd_idx)++;
+
+ if (cur_idx == cmd_fail_idx) {
+ ble_hs_test_util_rx_ack(opcode, fail_status);
+ return 1;
+ } else {
+ ble_hs_test_util_rx_ack(opcode, 0);
+ return 0;
+ }
}
static void
@@ -93,36 +137,119 @@ ble_gap_test_misc_verify_tx_create_conn(uint8_t filter_policy)
}
static void
-ble_gap_test_misc_conn_wl_good_once(struct ble_gap_white_entry *white_list,
- int white_list_count)
+ble_gap_test_misc_verify_tx_create_conn_cancel(void)
+{
+ uint8_t param_len;
+
+ TEST_ASSERT_FATAL(ble_hs_test_util_prev_hci_tx != NULL);
+
+ ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
+ ¶m_len);
+ TEST_ASSERT(param_len == 0);
+}
+
+static void
+ble_gap_test_misc_verify_tx_disconnect(void)
+{
+ uint8_t param_len;
+ uint8_t *param;
+
+ TEST_ASSERT_FATAL(ble_hs_test_util_prev_hci_tx != NULL);
+
+ param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LINK_CTRL,
+ BLE_HCI_OCF_DISCONNECT_CMD,
+ ¶m_len);
+ TEST_ASSERT(param_len == BLE_HCI_DISCONNECT_CMD_LEN);
+ TEST_ASSERT(le16toh(param + 0) == 2);
+ TEST_ASSERT(param[2] == BLE_ERR_REM_USER_CONN_TERM);
+}
+
+static void
+ble_gap_test_misc_wl_set(struct ble_gap_white_entry *white_list,
+ int white_list_count, int cmd_fail_idx,
+ uint8_t hci_status)
{
+ int cmd_idx;
int rc;
int i;
ble_gap_test_misc_init();
+ cmd_idx = 0;
TEST_ASSERT(!ble_gap_conn_wl_busy());
- rc = ble_gap_conn_wl_set(white_list, white_list_count);
+ rc = ble_gap_conn_wl_set(white_list, white_list_count,
+ ble_gap_test_misc_wl_cb, NULL);
TEST_ASSERT(rc == 0);
TEST_ASSERT(ble_gap_conn_wl_busy());
/* Verify tx of clear white list command. */
ble_hci_sched_wakeup();
ble_gap_test_misc_verify_tx_clear_wl();
- ble_hs_test_util_rx_le_ack(BLE_HCI_OCF_LE_CLEAR_WHITE_LIST, 0);
+ rc = ble_gap_test_misc_rx_hci_ack(&cmd_idx, cmd_fail_idx, BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CLEAR_WHITE_LIST,
+ hci_status);
+ if (rc != 0) {
+ return;
+ }
/* Verify tx of add white list commands. */
for (i = 0; i < white_list_count; i++) {
TEST_ASSERT(ble_gap_conn_wl_busy());
ble_hci_sched_wakeup();
ble_gap_test_misc_verify_tx_add_wl(white_list + i);
- ble_hs_test_util_rx_le_ack(BLE_HCI_OCF_LE_ADD_WHITE_LIST, 0);
+ rc = ble_gap_test_misc_rx_hci_ack(&cmd_idx, cmd_fail_idx,
+ BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_ADD_WHITE_LIST,
+ hci_status);
+ if (rc != 0) {
+ return;
+ }
}
+ TEST_ASSERT_FATAL(cmd_fail_idx < 0);
TEST_ASSERT(!ble_gap_conn_wl_busy());
}
+static void
+ble_gap_test_misc_terminate(uint8_t *peer_addr, int cmd_fail_idx,
+ uint8_t hci_status)
+{
+ struct hci_disconn_complete evt;
+ int cmd_idx;
+ int rc;
+
+ ble_gap_test_misc_init();
+ cmd_idx = 0;
+
+ /* Create a connection. */
+ ble_hs_test_util_create_conn(2, peer_addr, ble_gap_test_misc_connect_cb,
+ NULL);
+
+ /* Terminate the connection. */
+ rc = ble_gap_conn_terminate(2);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+
+ /* Verify tx of disconnect command. */
+ ble_hci_sched_wakeup();
+ ble_gap_test_misc_verify_tx_disconnect();
+ rc = ble_gap_test_misc_rx_hci_ack(&cmd_idx, cmd_fail_idx,
+ BLE_HCI_OGF_LINK_CTRL,
+ BLE_HCI_OCF_DISCONNECT_CMD,
+ hci_status);
+ if (rc != 0) {
+ return;
+ }
+
+ /* Receive disconnection complete event. */
+ evt.connection_handle = 2;
+ evt.status = 0;
+ evt.reason = BLE_ERR_CONN_TERM_LOCAL;
+ ble_gap_conn_rx_disconn_complete(&evt);
+}
+
TEST_CASE(ble_gap_test_case_conn_wl_good)
{
struct ble_gap_white_entry white_list[] = {
@@ -133,7 +260,9 @@ TEST_CASE(ble_gap_test_case_conn_wl_good)
};
int white_list_count = sizeof white_list / sizeof white_list[0];
- ble_gap_test_misc_conn_wl_good_once(white_list, white_list_count);
+ ble_gap_test_misc_wl_set(white_list, white_list_count, -1, 0);
+ TEST_ASSERT(ble_gap_test_wl_status == 0);
+ TEST_ASSERT(ble_gap_test_wl_arg == NULL);
}
TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
@@ -145,7 +274,7 @@ TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
TEST_ASSERT(!ble_gap_conn_wl_busy());
/*** 0 white list entries. */
- rc = ble_gap_conn_wl_set(NULL, 0);
+ rc = ble_gap_conn_wl_set(NULL, 0, ble_gap_test_misc_wl_cb, NULL);
TEST_ASSERT(rc == BLE_HS_EINVAL);
TEST_ASSERT(!ble_gap_conn_wl_busy());
@@ -153,23 +282,46 @@ TEST_CASE(ble_gap_test_case_conn_wl_bad_args)
rc = ble_gap_conn_wl_set(
((struct ble_gap_white_entry[]) { {
5, { 1, 2, 3, 4, 5, 6 }
- }, }), 1);
+ }, }),
+ 1, ble_gap_test_misc_wl_cb, NULL);
TEST_ASSERT(rc == BLE_HS_EINVAL);
TEST_ASSERT(!ble_gap_conn_wl_busy());
/*** White-list-using connection in progress. */
- rc = ble_gap_conn_direct_connect(BLE_GAP_ADDR_TYPE_WL, NULL);
+ rc = ble_gap_conn_direct_connect(BLE_GAP_ADDR_TYPE_WL, NULL,
+ ble_gap_test_misc_connect_cb, NULL);
TEST_ASSERT(rc == 0);
TEST_ASSERT(ble_gap_conn_wl_busy());
rc = ble_gap_conn_wl_set(
((struct ble_gap_white_entry[]) { {
BLE_ADDR_TYPE_PUBLIC, { 1, 2, 3, 4, 5, 6 }
- }, }), 1);
+ }, }),
+ 1, ble_gap_test_misc_wl_cb, NULL);
TEST_ASSERT(rc == BLE_HS_EBUSY);
TEST_ASSERT(ble_gap_conn_wl_busy());
}
+TEST_CASE(ble_gap_test_case_conn_wl_ctlr_fail)
+{
+ int i;
+
+ struct ble_gap_white_entry white_list[] = {
+ { BLE_ADDR_TYPE_PUBLIC, { 1, 2, 3, 4, 5, 6 } },
+ { BLE_ADDR_TYPE_PUBLIC, { 2, 3, 4, 5, 6, 7 } },
+ { BLE_ADDR_TYPE_PUBLIC, { 3, 4, 5, 6, 7, 8 } },
+ { BLE_ADDR_TYPE_PUBLIC, { 4, 5, 6, 7, 8, 9 } },
+ };
+ int white_list_count = sizeof white_list / sizeof white_list[0];
+
+ for (i = 0; i < 5; i++) {
+ ble_gap_test_misc_wl_set(white_list, white_list_count, i,
+ BLE_ERR_UNSPECIFIED);
+ TEST_ASSERT(ble_gap_test_wl_status != 0);
+ TEST_ASSERT(ble_gap_test_wl_arg == NULL);
+ }
+}
+
TEST_CASE(ble_gap_test_case_conn_dir_good)
{
struct hci_le_conn_complete evt;
@@ -181,7 +333,8 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
- rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC, peer_addr);
+ rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC, peer_addr,
+ ble_gap_test_misc_connect_cb, NULL);
TEST_ASSERT(rc == 0);
TEST_ASSERT(ble_gap_conn_master_in_progress());
@@ -205,11 +358,9 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event.type ==
- BLE_GAP_CONN_EVENT_TYPE_CONNECT);
- TEST_ASSERT(ble_gap_test_conn_event.conn.status == 0);
- TEST_ASSERT(ble_gap_test_conn_event.conn.handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_event.conn.peer_addr,
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
peer_addr, 6) == 0);
TEST_ASSERT(ble_hs_conn_find(2) != NULL);
@@ -224,18 +375,21 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_args)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
/*** Invalid address type. */
- rc = ble_gap_conn_direct_connect(5, ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }));
+ rc = ble_gap_conn_direct_connect(5, ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }),
+ ble_gap_test_misc_connect_cb, NULL);
TEST_ASSERT(rc == BLE_HS_EINVAL);
TEST_ASSERT(!ble_gap_conn_master_in_progress());
/*** Connection already in progress. */
rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC,
- ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }));
+ ((uint8_t[]){ 1, 2, 3, 4, 5, 6 }),
+ ble_gap_test_misc_connect_cb, NULL);
TEST_ASSERT(rc == 0);
TEST_ASSERT(ble_gap_conn_master_in_progress());
rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC,
- ((uint8_t[]){ 2, 3, 4, 5, 6, 7 }));
+ ((uint8_t[]){ 2, 3, 4, 5, 6, 7 }),
+ ble_gap_test_misc_connect_cb, NULL);
TEST_ASSERT(rc == BLE_HS_EALREADY);
}
@@ -250,7 +404,8 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_addr)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
- rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC, peer_addr);
+ rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC, peer_addr,
+ ble_gap_test_misc_connect_cb, NULL);
TEST_ASSERT(rc == 0);
TEST_ASSERT(ble_gap_conn_master_in_progress());
@@ -274,17 +429,208 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_addr)
TEST_ASSERT(!ble_gap_conn_master_in_progress());
- TEST_ASSERT(ble_gap_test_conn_event.type ==
- BLE_GAP_CONN_EVENT_TYPE_CONNECT);
- TEST_ASSERT(ble_gap_test_conn_event.conn.status == BLE_HS_ECONTROLLER);
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == BLE_HS_CONN_HANDLE_NONE);
TEST_ASSERT(ble_hs_conn_find(2) == NULL);
}
+static void
+ble_gap_test_misc_conn_cancel(uint8_t *peer_addr, int cmd_fail_idx,
+ uint8_t hci_status)
+{
+ struct hci_le_conn_complete evt;
+ int cmd_idx;
+ int rc;
+
+ ble_gap_test_misc_init();
+ cmd_idx = 0;
+
+ /* Begin creating a connection. */
+ rc = ble_gap_conn_direct_connect(BLE_ADDR_TYPE_PUBLIC, peer_addr,
+ ble_gap_test_misc_connect_cb, NULL);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(ble_gap_conn_master_in_progress());
+
+ ble_hci_sched_wakeup();
+ ble_gap_test_misc_verify_tx_create_conn(BLE_HCI_CONN_FILT_NO_WL);
+ ble_hs_test_util_rx_le_ack(BLE_HCI_OCF_LE_CREATE_CONN, 0);
+
+ /* Initiate cancel procedure. */
+ rc = ble_gap_conn_cancel();
+ TEST_ASSERT(rc == 0);
+
+ /* Verify tx of cancel create connection command. */
+ ble_hci_sched_wakeup();
+ ble_gap_test_misc_verify_tx_create_conn_cancel();
+ rc = ble_gap_test_misc_rx_hci_ack(&cmd_idx, cmd_fail_idx, BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
+ hci_status);
+ if (rc != 0) {
+ return;
+ }
+ TEST_ASSERT(ble_gap_conn_master_in_progress());
+
+ TEST_ASSERT_FATAL(cmd_fail_idx == -1);
+
+ /* Receive connection complete event. */
+ memset(&evt, 0, sizeof evt);
+ evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
+ evt.status = BLE_ERR_UNK_CONN_ID;
+ evt.connection_handle = 2;
+ memcpy(evt.peer_addr, peer_addr, 6);
+ rc = ble_gap_conn_rx_conn_complete(&evt);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+ TEST_ASSERT(ble_hs_conn_find(2) == NULL);
+}
+
+TEST_CASE(ble_gap_test_case_conn_cancel_bad_args)
+{
+ int rc;
+
+ ble_gap_test_misc_init();
+
+ /* Initiate cancel procedure with no connection in progress. */
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+ rc = ble_gap_conn_cancel();
+ TEST_ASSERT(rc == BLE_HS_ENOENT);
+}
+
+TEST_CASE(ble_gap_test_case_conn_cancel_good)
+{
+ uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+ ble_gap_test_misc_conn_cancel(peer_addr, -1, 0);
+
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == BLE_HS_CONN_HANDLE_NONE);
+}
+
+TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
+{
+ struct hci_le_conn_complete evt;
+ int rc;
+
+ uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+ ble_gap_test_misc_conn_cancel(peer_addr, 0, BLE_ERR_REPEATED_ATTEMPTS);
+
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CANCEL_FAILURE);
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == BLE_HS_CONN_HANDLE_NONE);
+
+ /* Allow connection complete to succeed. */
+ memset(&evt, 0, sizeof evt);
+ evt.subevent_code = BLE_HCI_LE_SUBEV_CONN_COMPLETE;
+ evt.status = BLE_ERR_SUCCESS;
+ evt.connection_handle = 2;
+ memcpy(evt.peer_addr, peer_addr, 6);
+ rc = ble_gap_conn_rx_conn_complete(&evt);
+ TEST_ASSERT(rc == 0);
+
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN);
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
+ peer_addr, 6) == 0);
+
+ TEST_ASSERT(ble_hs_conn_find(2) != NULL);
+}
+
+TEST_CASE(ble_gap_test_case_conn_terminate_bad_args)
+{
+ int rc;
+
+ ble_gap_test_misc_init();
+
+ /*** Nonexistent connection. */
+ rc = ble_gap_conn_terminate(2);
+ TEST_ASSERT(rc == BLE_HS_ENOENT);
+}
+
+TEST_CASE(ble_gap_test_case_conn_terminate_good)
+{
+ uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+ ble_gap_test_misc_terminate(peer_addr, -1, 0);
+
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_TERM);
+ TEST_ASSERT(ble_gap_test_conn_status == 0);
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
+ TEST_ASSERT(ble_gap_test_conn_desc.peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(ble_gap_test_conn_arg == NULL);
+
+ TEST_ASSERT(ble_hs_conn_find(2) == NULL);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+}
+
+TEST_CASE(ble_gap_test_case_conn_terminate_ctlr_fail)
+{
+ struct hci_disconn_complete evt;
+ int rc;
+
+ uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+ ble_gap_test_misc_init();
+
+ /* Create a connection. */
+ ble_hs_test_util_create_conn(2, peer_addr, ble_gap_test_misc_connect_cb,
+ NULL);
+
+ /* Terminate the connection. */
+ rc = ble_gap_conn_terminate(2);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+
+ /* Verify tx of disconnect command. */
+ ble_hci_sched_wakeup();
+ ble_gap_test_misc_verify_tx_disconnect();
+ ble_hs_test_util_rx_ack((BLE_HCI_OGF_LINK_CTRL << 10) |
+ BLE_HCI_OCF_DISCONNECT_CMD, 0);
+
+ /* Receive failed disconnection complete event. */
+ evt.connection_handle = 2;
+ evt.status = BLE_ERR_UNSUPPORTED;
+ evt.reason = 0;
+ ble_gap_conn_rx_disconn_complete(&evt);
+
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_TERM);
+ TEST_ASSERT(ble_gap_test_conn_status ==
+ BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
+ TEST_ASSERT(ble_gap_test_conn_desc.peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(ble_gap_test_conn_arg == NULL);
+
+ TEST_ASSERT(ble_hs_conn_find(2) != NULL);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+}
+
+TEST_CASE(ble_gap_test_case_conn_terminate_hci_fail)
+{
+ uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+
+ ble_gap_test_misc_terminate(peer_addr, 0, BLE_ERR_REPEATED_ATTEMPTS);
+
+ TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_TERM);
+ TEST_ASSERT(ble_gap_test_conn_status ==
+ BLE_HS_HCI_ERR(BLE_ERR_REPEATED_ATTEMPTS));
+ TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
+ TEST_ASSERT(ble_gap_test_conn_desc.peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(ble_gap_test_conn_arg == NULL);
+
+ TEST_ASSERT(ble_hs_conn_find(2) != NULL);
+ TEST_ASSERT(!ble_gap_conn_master_in_progress());
+}
+
TEST_SUITE(ble_gap_suite_conn_wl)
{
ble_gap_test_case_conn_wl_good();
ble_gap_test_case_conn_wl_bad_args();
+ ble_gap_test_case_conn_wl_ctlr_fail();
}
TEST_SUITE(ble_gap_suite_conn_dir)
@@ -294,11 +640,28 @@ TEST_SUITE(ble_gap_suite_conn_dir)
ble_gap_test_case_conn_dir_bad_addr();
}
+TEST_SUITE(ble_gap_suite_conn_cancel)
+{
+ ble_gap_test_case_conn_cancel_good();
+ ble_gap_test_case_conn_cancel_bad_args();
+ ble_gap_test_case_conn_cancel_ctlr_fail();
+}
+
+TEST_SUITE(ble_gap_suite_conn_terminate)
+{
+ ble_gap_test_case_conn_terminate_bad_args();
+ ble_gap_test_case_conn_terminate_good();
+ ble_gap_test_case_conn_terminate_ctlr_fail();
+ ble_gap_test_case_conn_terminate_hci_fail();
+}
+
int
ble_gap_test_all(void)
{
ble_gap_suite_conn_wl();
ble_gap_suite_conn_dir();
+ ble_gap_suite_conn_cancel();
+ ble_gap_suite_conn_terminate();
return tu_any_failed;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_conn_test.c b/net/nimble/host/src/test/ble_gatt_conn_test.c
index 46672e5..8917035 100644
--- a/net/nimble/host/src/test/ble_gatt_conn_test.c
+++ b/net/nimble/host/src/test/ble_gatt_conn_test.c
@@ -120,13 +120,13 @@ TEST_CASE(ble_gatt_conn_test_disconnect)
/* Create three connections. */
ble_hs_test_util_create_conn(BLE_GATT_BREAK_TEST_DISC_SERVICE_HANDLE,
- ((uint8_t[]){1,2,3,4,5,6,7,8}));
+ ((uint8_t[]){1,2,3,4,5,6,7,8}), NULL, NULL);
ble_hs_test_util_create_conn(BLE_GATT_BREAK_TEST_DISC_CHR_HANDLE,
- ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ ((uint8_t[]){2,3,4,5,6,7,8,9}), NULL, NULL);
ble_hs_test_util_create_conn(BLE_GATT_BREAK_TEST_READ_HANDLE,
- ((uint8_t[]){3,4,5,6,7,8,9,10}));
+ ((uint8_t[]){3,4,5,6,7,8,9,10}), NULL, NULL);
ble_hs_test_util_create_conn(BLE_GATT_BREAK_TEST_WRITE_HANDLE,
- ((uint8_t[]){4,5,6,7,8,9,10,11}));
+ ((uint8_t[]){4,5,6,7,8,9,10,11}), NULL, NULL);
/* Schedule some GATT procedures. */
rc = ble_gattc_disc_all_svcs(BLE_GATT_BREAK_TEST_DISC_SERVICE_HANDLE,
@@ -177,7 +177,8 @@ TEST_CASE(ble_gatt_conn_test_congestion)
ble_hs_cfg.max_outstanding_pkts_per_conn = 1;
/* Create a connection. */
- conn = ble_hs_test_util_create_conn(1, ((uint8_t[]){1,2,3,4,5,6,7,8}));
+ conn = ble_hs_test_util_create_conn(1, ((uint8_t[]){1,2,3,4,5,6,7,8}),
+ NULL, NULL);
/* Try to send two data packets. */
rc = ble_gattc_write(1, 0x1234, ble_gatt_conn_test_write_value,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_disc_c_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_c_test.c b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
index 3880e7c..b9d4fcc 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_c_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_c_test.c
@@ -216,7 +216,8 @@ ble_gatt_disc_c_test_misc_all(uint16_t start_handle, uint16_t end_handle,
ble_gatt_disc_c_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
num_left = stop_after;
rc = ble_gattc_disc_all_chrs(2, start_handle, end_handle,
@@ -238,7 +239,8 @@ ble_gatt_disc_c_test_misc_uuid(uint16_t start_handle, uint16_t end_handle,
ble_gatt_disc_c_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_disc_chrs_by_uuid(2, start_handle, end_handle,
uuid128,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_disc_d_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_d_test.c b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
index 68e65eb..67b65f1 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_d_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_d_test.c
@@ -207,7 +207,8 @@ ble_gatt_disc_d_test_misc_all(uint16_t chr_val_handle, uint16_t end_handle,
ble_gatt_disc_d_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
num_left = stop_after;
rc = ble_gattc_disc_all_dscs(2, chr_val_handle, end_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_disc_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_disc_s_test.c b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
index a7e6e62..ca84eee 100644
--- a/net/nimble/host/src/test/ble_gatt_disc_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_disc_s_test.c
@@ -249,7 +249,8 @@ ble_gatt_disc_s_test_misc_good_all(struct ble_gatt_disc_s_test_svc *services)
ble_gatt_disc_s_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_disc_all_svcs(2, ble_gatt_disc_s_test_misc_disc_cb, NULL);
TEST_ASSERT(rc == 0);
@@ -267,7 +268,8 @@ ble_gatt_disc_s_test_misc_good_uuid(
ble_gatt_disc_s_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
if (services[0].uuid16 != 0) {
rc = ble_uuid_16_to_128(services[0].uuid16, services[0].uuid128);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_find_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_find_s_test.c b/net/nimble/host/src/test/ble_gatt_find_s_test.c
index ed8d3af..062f082 100644
--- a/net/nimble/host/src/test/ble_gatt_find_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_find_s_test.c
@@ -249,7 +249,8 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* Two 16-bit UUID services; one response. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
ble_gatt_find_s_test_misc_find_inc(conn, 5, 10,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 6,
@@ -268,7 +269,8 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* One 128-bit UUID service; two responses. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
ble_gatt_find_s_test_misc_find_inc(conn, 34, 100,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 36,
@@ -282,7 +284,8 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* Two 128-bit UUID service; four responses. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
ble_gatt_find_s_test_misc_find_inc(conn, 34, 100,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 36,
@@ -301,7 +304,8 @@ TEST_CASE(ble_gatt_find_s_test_1)
/* Two 16-bit UUID; three 128-bit UUID; seven responses. */
ble_gatt_find_s_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
ble_gatt_find_s_test_misc_find_inc(conn, 1, 100,
((struct ble_gatt_find_s_test_entry[]) { {
.inc_handle = 36,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c b/net/nimble/host/src/test/ble_gatt_read_test.c
index ec4fe91..9ecaf74 100644
--- a/net/nimble/host/src/test/ble_gatt_read_test.c
+++ b/net/nimble/host/src/test/ble_gatt_read_test.c
@@ -289,7 +289,8 @@ ble_gatt_read_test_misc_verify_good(struct ble_gatt_attr *attr)
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read(conn->bhc_handle, attr->handle, ble_gatt_read_test_cb,
NULL);
@@ -313,7 +314,8 @@ ble_gatt_read_test_misc_verify_bad(uint8_t att_status,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read(conn->bhc_handle, attr->handle, ble_gatt_read_test_cb,
NULL);
@@ -341,7 +343,8 @@ ble_gatt_read_test_misc_uuid_verify_good(uint16_t start_handle,
int i;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read_uuid(conn->bhc_handle, start_handle, end_handle,
uuid128, ble_gatt_read_test_cb, &stop_after);
@@ -389,7 +392,8 @@ ble_gatt_read_test_misc_long_verify_good(int max_reads,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
if (max_reads == 0) {
max_reads = INT_MAX;
@@ -437,7 +441,8 @@ ble_gatt_read_test_misc_long_verify_bad(uint8_t att_status,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read_long(conn->bhc_handle, attr->handle,
ble_gatt_read_test_long_cb, NULL);
@@ -477,7 +482,8 @@ ble_gatt_read_test_misc_mult_verify_good(struct ble_gatt_attr *attrs)
int i;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
num_attrs = ble_gatt_read_test_misc_extract_handles(attrs, handles);
@@ -524,7 +530,8 @@ ble_gatt_read_test_misc_mult_verify_bad(uint8_t att_status,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
num_attrs = ble_gatt_read_test_misc_extract_handles(attrs, handles);
@@ -551,7 +558,8 @@ ble_gatt_read_test_misc_dsc_verify_good(struct ble_gatt_attr *attr)
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read_dsc(conn->bhc_handle, attr->handle,
ble_gatt_read_test_cb, NULL);
@@ -575,7 +583,8 @@ ble_gatt_read_test_misc_dsc_verify_bad(uint8_t att_status,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read_dsc(conn->bhc_handle, attr->handle,
ble_gatt_read_test_cb, NULL);
@@ -603,7 +612,8 @@ ble_gatt_read_test_misc_dsc_long_verify_good(int max_reads,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
if (max_reads == 0) {
max_reads = INT_MAX;
@@ -651,7 +661,8 @@ ble_gatt_read_test_misc_dsc_long_verify_bad(uint8_t att_status,
int rc;
ble_gatt_read_test_misc_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_read_long_dsc(conn->bhc_handle, attr->handle,
ble_gatt_read_test_long_cb, NULL);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index 7b6d6da..7730b4c 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -134,7 +134,8 @@ ble_gatt_write_test_misc_long_good(int attr_len)
ble_gatt_write_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_write_long(conn->bhc_handle, 100,
ble_gatt_write_test_attr_value,
@@ -185,7 +186,8 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
ble_gatt_write_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
rc = ble_gattc_write_long(conn->bhc_handle, 100,
ble_gatt_write_test_attr_value,
@@ -268,7 +270,8 @@ TEST_CASE(ble_gatt_write_test_no_rsp)
ble_gatt_write_test_init();
- ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
attr_len = 4;
rc = ble_gattc_write_no_rsp(2, 100, ble_gatt_write_test_attr_value,
@@ -291,7 +294,8 @@ TEST_CASE(ble_gatt_write_test_rsp)
ble_gatt_write_test_init();
- conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ conn = ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
attr_len = 4;
rc = ble_gattc_write(2, 100, ble_gatt_write_test_attr_value,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index 6efe467..cdc5a3b 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -81,7 +81,8 @@ ble_gatts_notify_test_misc_init(struct ble_hs_conn **conn,
TEST_ASSERT_FATAL(ble_gatts_notify_test_chr_1_def_handle != 0);
TEST_ASSERT_FATAL(ble_gatts_notify_test_chr_2_def_handle != 0);
- ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
*conn = ble_hs_conn_find(2);
TEST_ASSERT_FATAL(*conn != NULL);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index 0c03eca..37bd048 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -27,7 +27,7 @@
#include "ble_hs_adv.h"
#include "ble_hci_ack.h"
#include "ble_hci_sched.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#include "ble_hs_test_util.h"
#include "testutil/testutil.h"
@@ -117,7 +117,8 @@ ble_hs_adv_test_misc_tx_and_verify_data(uint8_t disc_mode,
ble_hs_test_util_init();
- rc = ble_gap_conn_advertise(disc_mode, BLE_GAP_CONN_MODE_UND, NULL, 0);
+ rc = ble_gap_conn_advertise(disc_mode, BLE_GAP_CONN_MODE_UND, NULL, 0,
+ NULL, NULL);
TEST_ASSERT_FATAL(rc == 0);
ble_hs_test_util_rx_und_adv_acks_count(3);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index a84e683..a490446 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -26,7 +26,7 @@
#include "ble_hs_conn.h"
#include "ble_hci_ack.h"
#include "ble_hci_sched.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#include "ble_hs_test_util.h"
#include "testutil/testutil.h"
@@ -45,7 +45,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
TEST_ASSERT(ble_hs_conn_first() == NULL);
/* Initiate connection. */
- rc = ble_gap_conn_direct_connect(0, addr);
+ rc = ble_gap_conn_direct_connect(0, addr, NULL, NULL);
TEST_ASSERT(rc == 0);
ble_hci_sched_wakeup();
@@ -92,7 +92,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_hci_errors)
TEST_ASSERT(ble_hs_conn_first() == NULL);
/* Initiate connection. */
- rc = ble_gap_conn_direct_connect(0, addr);
+ rc = ble_gap_conn_direct_connect(0, addr, NULL, NULL);
TEST_ASSERT(rc == 0);
ble_hci_sched_wakeup();
@@ -139,7 +139,8 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
/* Initiate advertising. */
rc = ble_gap_conn_advertise(BLE_GAP_DISC_MODE_NON, BLE_GAP_CONN_MODE_DIR,
- addr, BLE_HCI_ADV_PEER_ADDR_PUBLIC);
+ addr, BLE_HCI_ADV_PEER_ADDR_PUBLIC,
+ NULL, NULL);
TEST_ASSERT(rc == 0);
ble_hci_sched_wakeup();
@@ -187,7 +188,8 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_hci_errors)
/* Initiate connection. */
rc = ble_gap_conn_advertise(BLE_GAP_DISC_MODE_NON, BLE_GAP_CONN_MODE_DIR,
- addr, BLE_HCI_ADV_PEER_ADDR_PUBLIC);
+ addr, BLE_HCI_ADV_PEER_ADDR_PUBLIC,
+ NULL, NULL);
TEST_ASSERT(rc == 0);
ble_hci_sched_wakeup();
@@ -212,7 +214,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_hci_errors)
evt.status = BLE_ERR_UNSPECIFIED;
rc = ble_gap_conn_rx_conn_complete(&evt);
TEST_ASSERT(rc == 0);
- TEST_ASSERT(!ble_gap_conn_slave_in_progress());
+ TEST_ASSERT(ble_gap_conn_slave_in_progress());
TEST_ASSERT(ble_hs_conn_first() == NULL);
}
@@ -233,7 +235,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
/* Initiate advertising. */
rc = ble_gap_conn_advertise(BLE_GAP_DISC_MODE_NON, BLE_GAP_CONN_MODE_UND,
- NULL, 0);
+ NULL, 0, NULL, NULL);
TEST_ASSERT(rc == 0);
TEST_ASSERT(!ble_gap_conn_master_in_progress());
@@ -271,8 +273,10 @@ TEST_CASE(ble_hs_conn_test_completed_pkts)
ble_hs_test_util_init();
- conn1 = ble_hs_test_util_create_conn(1, ((uint8_t[]){2,3,4,5,6,7,8,9}));
- conn2 = ble_hs_test_util_create_conn(2, ((uint8_t[]){3,4,5,6,7,8,9,10}));
+ conn1 = ble_hs_test_util_create_conn(1, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
+ conn2 = ble_hs_test_util_create_conn(2, ((uint8_t[]){3,4,5,6,7,8,9,10}),
+ NULL, NULL);
conn1->bhc_outstanding_pkts = 5;
conn2->bhc_outstanding_pkts = 5;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 f3c7359..489c171 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -25,7 +25,7 @@
#include "ble_hci_ack.h"
#include "ble_hci_sched.h"
#include "ble_hs_conn.h"
-#include "ble_gap_conn.h"
+#include "ble_gap_priv.h"
#include "ble_l2cap.h"
#include "ble_att_cmd.h"
#include "ble_hs_test_util.h"
@@ -61,13 +61,14 @@ ble_hs_test_util_build_cmd_status(uint8_t *dst, int len,
}
struct ble_hs_conn *
-ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr)
+ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
+ ble_gap_conn_fn *cb, void *cb_arg)
{
struct hci_le_conn_complete evt;
struct ble_hs_conn *conn;
int rc;
- rc = ble_gap_conn_direct_connect(0, addr);
+ rc = ble_gap_conn_direct_connect(0, addr, cb, cb_arg);
TEST_ASSERT(rc == 0);
ble_hci_sched_wakeup();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 c748923..6a11151 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -18,6 +18,7 @@
#define H_BLE_HS_TEST_UTIL_
#include <inttypes.h>
+#include "host/ble_gap.h"
struct ble_hs_conn;
struct ble_l2cap_chan;
@@ -36,7 +37,9 @@ void ble_hs_test_util_build_cmd_status(uint8_t *dst, int len,
uint8_t status, uint8_t num_pkts,
uint16_t opcode);
struct ble_hs_conn *ble_hs_test_util_create_conn(uint16_t handle,
- uint8_t *addr);
+ uint8_t *addr,
+ ble_gap_conn_fn *cb,
+ void *cb_arg);
void ble_hs_test_util_rx_ack(uint16_t opcode, uint8_t status);
void ble_hs_test_util_rx_ack_param(uint16_t opcode, uint8_t status,
void *param, int param_len);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ce53ccfd/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 460da5b..c8025f8 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -34,7 +34,8 @@ TEST_CASE(l2cap_test_bad_header)
ble_hs_test_util_init();
- ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}));
+ ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+ NULL, NULL);
conn = ble_hs_conn_find(2);
TEST_ASSERT_FATAL(conn != NULL);
[3/3] incubator-mynewt-larva git commit: Update host projects to
account for nimble changes
Posted by cc...@apache.org.
Update host projects to account for nimble changes
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/8f2fb6c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/8f2fb6c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/8f2fb6c7
Branch: refs/heads/master
Commit: 8f2fb6c7e26d10281cf49ea532612e2162400d8d
Parents: ce53ccf
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Jan 14 19:08:04 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Jan 14 19:09:39 2016 -0800
----------------------------------------------------------------------
project/centtest/src/main.c | 45 +++++++++++-----------------------------
project/prphtest/src/main.c | 21 +++++++++----------
2 files changed, 22 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8f2fb6c7/project/centtest/src/main.c
----------------------------------------------------------------------
diff --git a/project/centtest/src/main.c b/project/centtest/src/main.c
index cb57c8f..46ff65c 100755
--- a/project/centtest/src/main.c
+++ b/project/centtest/src/main.c
@@ -175,44 +175,24 @@ centtest_on_disc_s(uint16_t conn_handle, struct ble_gatt_error *error,
}
static void
-centtest_print_adv_rpt(struct ble_gap_conn_adv_rpt *adv)
+centtest_on_connect(int event, int status, struct ble_gap_conn_desc *desc,
+ void *arg)
{
- console_printf("Received advertisement report:\n");
- console_printf(" addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
- adv->addr[0], adv->addr[1], adv->addr[2],
- adv->addr[3], adv->addr[4], adv->addr[5]);
- console_printf(" flags=0x%02x\n", adv->fields.flags);
- console_printf(" name=");
- console_write((char *)adv->fields.name, adv->fields.name_len);
- console_printf("\n");
-}
-
-static void
-centtest_on_connect(struct ble_gap_conn_event *event, void *arg)
-{
- switch (event->type) {
- case BLE_GAP_CONN_EVENT_TYPE_CONNECT:
+ switch (event) {
+ case BLE_GAP_EVENT_CONN:
console_printf("connection complete; handle=%d status=%d "
"peer_addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
- event->conn.handle, event->conn.status,
- event->conn.peer_addr[0], event->conn.peer_addr[1],
- event->conn.peer_addr[2], event->conn.peer_addr[3],
- event->conn.peer_addr[4], event->conn.peer_addr[5]);
+ desc->conn_handle, status,
+ desc->peer_addr[0], desc->peer_addr[1],
+ desc->peer_addr[2], desc->peer_addr[3],
+ desc->peer_addr[4], desc->peer_addr[5]);
- if (event->conn.status == 0) {
- ble_gattc_disc_all_svcs(event->conn.handle,
+ if (status == 0) {
+ ble_gattc_disc_all_svcs(desc->conn_handle,
centtest_on_disc_s, NULL);
}
break;
-
- case BLE_GAP_CONN_EVENT_TYPE_ADV_RPT:
- centtest_print_adv_rpt(&event->adv);
- break;
-
- case BLE_GAP_CONN_EVENT_TYPE_SCAN_DONE:
- console_printf("scan complete\n");
- break;
}
}
@@ -238,11 +218,10 @@ centtest_task_handler(void *arg)
g_centtest_state = 0;
g_next_os_time = os_time_get();
- ble_gap_conn_set_cb(centtest_on_connect, NULL);
-
//rc = ble_gap_conn_disc(20000, BLE_GAP_DISC_MODE_GEN);
rc = ble_gap_conn_direct_connect(BLE_HCI_ADV_PEER_ADDR_PUBLIC,
- centtest_slv_addr);
+ centtest_slv_addr,
+ centtest_on_connect, NULL);
assert(rc == 0);
while (1) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8f2fb6c7/project/prphtest/src/main.c
----------------------------------------------------------------------
diff --git a/project/prphtest/src/main.c b/project/prphtest/src/main.c
index 9d40352..df7f4c6 100755
--- a/project/prphtest/src/main.c
+++ b/project/prphtest/src/main.c
@@ -196,20 +196,21 @@ prphtest_register_attrs(void)
}
static void
-prphtest_on_connect(struct ble_gap_conn_event *event, void *arg)
+prphtest_on_connect(int event, int status, struct ble_gap_conn_desc *desc,
+ void *arg)
{
- switch (event->type) {
- case BLE_GAP_CONN_EVENT_TYPE_CONNECT:
+ switch (event) {
+ case BLE_GAP_EVENT_CONN:
console_printf("connection complete; handle=%d status=%d "
"peer_addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
- event->conn.handle, event->conn.status,
- event->conn.peer_addr[0], event->conn.peer_addr[1],
- event->conn.peer_addr[2], event->conn.peer_addr[3],
- event->conn.peer_addr[4], event->conn.peer_addr[5]);
+ desc->conn_handle, status,
+ desc->peer_addr[0], desc->peer_addr[1],
+ desc->peer_addr[2], desc->peer_addr[3],
+ desc->peer_addr[4], desc->peer_addr[5]);
break;
default:
- console_printf("unexpected connection event; type=%d\n", event->type);
+ console_printf("unexpected connection event; type=%d\n", event);
break;
}
}
@@ -237,8 +238,6 @@ prphtest_task_handler(void *arg)
g_prphtest_state = 0;
g_next_os_time = os_time_get();
- ble_gap_conn_set_cb(prphtest_on_connect, NULL);
-
prphtest_register_attrs();
memset(&fields, 0, sizeof fields);
@@ -249,7 +248,7 @@ prphtest_task_handler(void *arg)
assert(rc == 0);
rc = ble_gap_conn_advertise(BLE_GAP_DISC_MODE_NON, BLE_GAP_CONN_MODE_UND,
- NULL, 0);
+ NULL, 0, prphtest_on_connect, NULL);
assert(rc == 0);
while (1) {