You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2015/11/11 07:00:28 UTC
[1/2] incubator-mynewt-larva git commit: Some additional LL
connection related code
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 313f65326 -> 7e35563cf
Some additional LL connection related code
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/7e35563c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/7e35563c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/7e35563c
Branch: refs/heads/master
Commit: 7e35563cfc7cd1889eb27a45e0f08186f825779b
Parents: e50f0dc
Author: wes3 <wi...@micosa.io>
Authored: Tue Nov 10 21:54:33 2015 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Tue Nov 10 21:54:40 2015 -0800
----------------------------------------------------------------------
.../controller/include/controller/ble_ll.h | 28 ++
.../controller/include/controller/ble_ll_adv.h | 28 --
.../controller/include/controller/ble_ll_scan.h | 12 +-
net/nimble/controller/src/ble_ll.c | 53 ---
net/nimble/controller/src/ble_ll_conn.c | 392 +++++++++++++++++--
net/nimble/controller/src/ble_ll_hci.c | 27 +-
net/nimble/controller/src/ble_ll_scan.c | 42 +-
net/nimble/include/nimble/hci_common.h | 9 +
8 files changed, 451 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index 015c753..c93b55f 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -131,6 +131,34 @@ struct ble_dev_addr
/* Access address for advertising channels */
#define BLE_ACCESS_ADDR_ADV (0x8E89BED6)
+/*
+ * Advertising PDU format:
+ * -> 2 byte header
+ * -> LSB contains pdu type, txadd and rxadd bits.
+ * -> MSB contains length (6 bits).
+ * -> Payload
+ */
+#define BLE_ADV_PDU_HDR_TYPE_MASK (0x0F)
+#define BLE_ADV_PDU_HDR_TXADD_MASK (0x40)
+#define BLE_ADV_PDU_HDR_RXADD_MASK (0x80)
+#define BLE_ADV_PDU_HDR_LEN_MASK (0x3F)
+
+/* Advertising channel PDU types */
+#define BLE_ADV_PDU_TYPE_ADV_IND (0)
+#define BLE_ADV_PDU_TYPE_ADV_DIRECT_IND (1)
+#define BLE_ADV_PDU_TYPE_ADV_NONCONN_IND (2)
+#define BLE_ADV_PDU_TYPE_SCAN_REQ (3)
+#define BLE_ADV_PDU_TYPE_SCAN_RSP (4)
+#define BLE_ADV_PDU_TYPE_CONNECT_REQ (5)
+#define BLE_ADV_PDU_TYPE_ADV_SCAN_IND (6)
+
+/*
+ * TxAdd and RxAdd bit definitions. A 0 is a public address; a 1 is a
+ * random address.
+ */
+#define BLE_ADV_PDU_HDR_TXADD_RAND (0x40)
+#define BLE_ADV_PDU_HDR_RXADD_RAND (0x80)
+
/*
* Data Channel format
*
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/include/controller/ble_ll_adv.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_adv.h b/net/nimble/controller/include/controller/ble_ll_adv.h
index f460435..664668a 100644
--- a/net/nimble/controller/include/controller/ble_ll_adv.h
+++ b/net/nimble/controller/include/controller/ble_ll_adv.h
@@ -40,34 +40,6 @@
#define BLE_LL_ADV_PDU_ITVL_HD_MS_MAX (3750) /* usecs */
#define BLE_LL_ADV_STATE_HD_MAX (1280) /* msecs */
-/*
- * Advertising PDU format:
- * -> 2 byte header
- * -> LSB contains pdu type, txadd and rxadd bits.
- * -> MSB contains length (6 bits).
- * -> Payload
- */
-#define BLE_ADV_PDU_HDR_TYPE_MASK (0x0F)
-#define BLE_ADV_PDU_HDR_TXADD_MASK (0x40)
-#define BLE_ADV_PDU_HDR_RXADD_MASK (0x80)
-#define BLE_ADV_PDU_HDR_LEN_MASK (0x3F)
-
-/* Advertising channel PDU types */
-#define BLE_ADV_PDU_TYPE_ADV_IND (0)
-#define BLE_ADV_PDU_TYPE_ADV_DIRECT_IND (1)
-#define BLE_ADV_PDU_TYPE_ADV_NONCONN_IND (2)
-#define BLE_ADV_PDU_TYPE_SCAN_REQ (3)
-#define BLE_ADV_PDU_TYPE_SCAN_RSP (4)
-#define BLE_ADV_PDU_TYPE_CONNECT_REQ (5)
-#define BLE_ADV_PDU_TYPE_ADV_SCAN_IND (6)
-
-/*
- * TxAdd and RxAdd bit definitions. A 0 is a public address; a 1 is a
- * random address.
- */
-#define BLE_ADV_PDU_HDR_TXADD_RAND (0x40)
-#define BLE_ADV_PDU_HDR_RXADD_RAND (0x80)
-
/* Maximum advertisement data length */
#define BLE_ADV_DATA_MAX_LEN (31)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/include/controller/ble_ll_scan.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_scan.h b/net/nimble/controller/include/controller/ble_ll_scan.h
index 4349600..b7ce24f 100644
--- a/net/nimble/controller/include/controller/ble_ll_scan.h
+++ b/net/nimble/controller/include/controller/ble_ll_scan.h
@@ -84,6 +84,16 @@ void ble_ll_scan_rx_pdu_proc(uint8_t pdu_type, uint8_t *rxbuf, int8_t rssi,
uint8_t flags);
/* Boolean function denoting whether or not the whitelist can be changed */
-int ble_ll_scan_can_chg_whitelist(void);
+int ble_ll_scan_can_chg_whitelist(void);
+
+/* Boolean function returning true if scanning enabled */
+int ble_ll_scan_enabled(void);
+
+/* Initialize the scanner when we start initiating */
+struct hci_create_conn;
+void ble_ll_scan_initiator_start(struct hci_create_conn *hcc);
+
+/* Returns the PDU allocated by the scanner */
+struct os_mbuf *ble_ll_scan_get_pdu(void);
#endif /* H_BLE_LL_SCAN_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index f7b8746..be327c3 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -54,11 +54,6 @@ os_stack_t g_ble_ll_stack[BLE_LL_STACK_SIZE];
/* XXX: this is just temporary; used to calculate the channel index */
struct ble_ll_sm_connection
{
- /* Data channel index for connection */
- uint8_t unmapped_chan;
- uint8_t last_unmapped_chan;
- uint8_t num_used_channels;
-
/* Flow control */
uint8_t tx_seq;
uint8_t next_exp_seq;
@@ -81,54 +76,6 @@ struct ble_ll_sm_connection
struct ble_conn_req_data req_data;
};
-uint8_t
-ble_ll_next_data_channel(struct ble_ll_sm_connection *cnxn)
-{
- int i;
- int j;
- uint8_t curchan;
- uint8_t remap_index;
- uint8_t bitpos;
- uint8_t cntr;
- uint8_t mask;
- uint8_t usable_chans;
-
- /* Get next un mapped channel */
- curchan = (cnxn->last_unmapped_chan + cnxn->req_data.hop_inc) %
- BLE_PHY_NUM_DATA_CHANS;
-
- /* Set the current unmapped channel */
- cnxn->unmapped_chan = curchan;
-
- /* Is this a valid channel? */
- bitpos = 1 << (curchan & 0x07);
- if ((cnxn->req_data.chanmap[curchan >> 3] & bitpos) == 0) {
-
- /* Calculate remap index */
- remap_index = curchan % cnxn->num_used_channels;
-
- /* Iterate through channel map to find this channel */
- cntr = 0;
- for (i = 0; i < 5; i++) {
- usable_chans = cnxn->req_data.chanmap[i];
- if (usable_chans != 0) {
- mask = 0x01;
- for (j = 0; j < 8; j++) {
- if (usable_chans & mask) {
- if (cntr == remap_index) {
- return cntr;
- }
- ++cntr;
- }
- mask <<= 1;
- }
- }
- }
- }
-
- return curchan;
-}
-
/* Called when a connection gets initialized */
int
ble_init_conn_sm(struct ble_ll_sm_connection *cnxn)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 93c7bc4..0f1f46c 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -21,77 +21,385 @@
#include "os/os.h"
#include "nimble/ble.h"
#include "nimble/hci_common.h"
+#include "controller/ble_ll.h"
#include "controller/ble_ll_conn.h"
+#include "controller/ble_ll_scan.h"
+#include "controller/ble_phy.h"
-int
-ble_ll_conn_create(uint8_t *cmdbuf)
+/* XXX TODO
+ * 1) Implemement connection supervisor timeout.
+ * 2) Create connection request.
+ * 3) Process rxd connection request.
+ * 4) What about channel map. Where is that set?
+ * 5) Review data channel index selection
+ * 6) Closing the connection: the MD bit.
+ * 7) notifying host about connections: how often do we need to do this? On
+ * creation, establishment and/or loss?
+ * 8) Deal with window widening. Easy...
+ * 9) Close connection if window widening gets too big! 4.5.7
+ * 10) portions of the connect request need to be modified (possibly) based
+ * on the advertiser.
+ */
+
+/* Scanning state machine */
+struct ble_ll_conn_sm
{
- return BLE_ERR_SUCCESS;
+ /* Used to calculate data channel index for connection */
+ uint8_t unmapped_chan;
+ uint8_t last_unmapped_chan;
+ uint8_t num_used_chans;
+ uint8_t chanmap[5];
+ uint8_t hop_inc;
+ uint8_t conn_state;
+ uint8_t own_addr_type;
+ uint8_t peer_addr_type;
+ uint8_t peer_addr[BLE_DEV_ADDR_LEN];
+ uint16_t conn_spvn_tmo;
+ uint16_t conn_slave_latency;
+ uint16_t conn_event_cntr;
+ uint32_t access_addr;
+ struct os_mbuf *conn_req_pdu;
+};
+
+struct ble_ll_conn_sm g_ble_ll_conn_sm;
+
+/* Connection states */
+#define BLE_LL_CONN_STATE_IDLE (0)
+#define BLE_LL_CONN_STATE_CREATED (1)
+#define BLE_LL_CONN_STATE_ESTABLISHED (2)
+
+static uint32_t
+ble_ll_conn_calc_access_addr(void)
+{
+ uint32_t aa;
+ uint16_t aa_low;
+ uint16_t aa_high;
+ uint32_t temp;
+ uint32_t mask;
+ uint32_t prev_bit;
+ uint8_t bits_diff;
+ uint8_t consecutive;
+ uint8_t transitions;
+
+ /* Calculate a random access address */
+ aa = 0;
+ while (1) {
+ /* Get two, 16-bit random numbers */
+ aa_low = rand() & 0xFFFF;
+ aa_high = rand() & 0xFFFF;
+
+ /* All four bytes cannot be equal */
+ if (aa_low == aa_high) {
+ continue;
+ }
+
+ /* Upper 6 bits must have 2 transitions */
+ temp = aa_high & 0xFC00;
+ if ((temp == 0) || (temp == 0xFC00)) {
+ continue;
+ }
+
+ /* Cannot be access address or be 1 bit different */
+ aa = aa_high;
+ aa = (aa_high << 16) | aa_low;
+ bits_diff = 0;
+ mask = 0x00000001;
+ temp = aa ^ BLE_ACCESS_ADDR_ADV;
+ for (mask = 0; mask <= 0x80000000; mask <<= 1) {
+ if (mask & temp) {
+ ++bits_diff;
+ if (bits_diff > 1) {
+ break;
+ }
+ }
+ }
+ if (bits_diff <= 1) {
+ continue;
+ }
+
+ /* Cannot have more than 24 transitions */
+ transitions = 0;
+ consecutive = 0;
+ mask = 0x00000001;
+ prev_bit = aa & mask;
+ while (mask < 0x80000000) {
+ mask <<= 1;
+ if (mask & aa) {
+ if (prev_bit == 0) {
+ ++transitions;
+ consecutive = 0;
+ } else {
+ ++consecutive;
+ }
+ } else {
+ if (prev_bit == 0) {
+ ++consecutive;
+ } else {
+ ++transitions;
+ consecutive = 0;
+ }
+ }
+
+ /* This is invalid! */
+ if (consecutive > 6) {
+ break;
+ }
+ }
+
+ /* Cannot be more than 24 transitions */
+ if ((consecutive > 6) || (transitions > 24)) {
+ continue;
+ }
+ }
+ return aa;
}
-int
-ble_ll_conn_create_cancel(void)
+/**
+ * Determine the next data channel to be used for the connection.
+ *
+ * @param conn
+ *
+ * @return uint8_t
+ */
+uint8_t
+ble_ll_next_data_channel(struct ble_ll_conn_sm *conn)
{
- return BLE_ERR_SUCCESS;
+ int i;
+ int j;
+ uint8_t curchan;
+ uint8_t remap_index;
+ uint8_t bitpos;
+ uint8_t cntr;
+ uint8_t mask;
+ uint8_t usable_chans;
+
+ /* Get next un mapped channel */
+ curchan = (conn->last_unmapped_chan + conn->hop_inc) %
+ BLE_PHY_NUM_DATA_CHANS;
+
+ /* Set the current unmapped channel */
+ conn->unmapped_chan = curchan;
+
+ /* Is this a valid channel? */
+ bitpos = 1 << (curchan & 0x07);
+ if ((conn->chanmap[curchan >> 3] & bitpos) == 0) {
+
+ /* Calculate remap index */
+ remap_index = curchan % conn->num_used_chans;
+
+ /* NOTE: possible to build a map but this would use memory. For now,
+ we just calculate */
+ /* Iterate through channel map to find this channel */
+ cntr = 0;
+ for (i = 0; i < 5; i++) {
+ usable_chans = conn->chanmap[i];
+ if (usable_chans != 0) {
+ mask = 0x01;
+ for (j = 0; j < 8; j++) {
+ if (usable_chans & mask) {
+ if (cntr == remap_index) {
+ return cntr;
+ }
+ ++cntr;
+ }
+ mask <<= 1;
+ }
+ }
+ }
+ }
+
+ return curchan;
+}
+
+/**
+ * Initialize the connection state machine. This is done once per connection
+ * when the HCI command "create connection" is issued to the controller.
+ *
+ * @param connsm
+ */
+void
+ble_ll_conn_sm_init(struct ble_ll_conn_sm *connsm, struct hci_create_conn *hcc)
+{
+ /* Hop increment is a random value between 5 and 16. */
+ connsm->hop_inc = (rand() % 12) + 5;
+
+ /* Reset event counter */
+ connsm->conn_event_cntr = 0;
+
+ /* Set slave latency */
+ connsm->conn_slave_latency = hcc->conn_latency;
+ connsm->conn_spvn_tmo = hcc->supervision_timeout;
+
+ /* Set own address type and peer address if needed */
+ connsm->own_addr_type = hcc->own_addr_type;
+ if (hcc->filter_policy == 0) {
+ memcpy(&connsm->peer_addr, &hcc->peer_addr, BLE_DEV_ADDR_LEN);
+ connsm->peer_addr_type = hcc->peer_addr_type;
+ }
+
+ /* XXX: set connection interval */
+ /* XXX: what to do with min/max connection event? */
+ /* XXX: where does the channel map get set? */
+
+ /* XXX: Calculate random access address */
+ connsm->access_addr = ble_ll_conn_calc_access_addr();
}
+void
+ble_ll_conn_req_make(struct ble_ll_conn_sm *connsm)
+{
+ uint8_t pdu_type;
+ uint8_t *addr;
+ uint8_t *dptr;
+ struct os_mbuf *m;
+
+ m = ble_ll_scan_get_pdu();
+ assert(m != NULL);
+ m->om_len = BLE_CONNECT_REQ_LEN + BLE_LL_PDU_HDR_LEN;
+ OS_MBUF_PKTHDR(m)->omp_len = m->om_len;
+
+ /* Construct first PDU header byte */
+ pdu_type = BLE_ADV_PDU_TYPE_CONNECT_REQ;
+
+ /* Get pointer to our device address */
+ if (connsm->own_addr_type == BLE_HCI_ADV_OWN_ADDR_PUBLIC) {
+ addr = g_dev_addr;
+ } else if (connsm->own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+ pdu_type |= BLE_ADV_PDU_HDR_TXADD_RAND;
+ addr = g_random_addr;
+ } else {
+ /* XXX: unsupported for now */
+ addr = NULL;
+ assert(0);
+ }
+
+ /* Construct the connect request */
+ dptr = m->om_data;
+ dptr[0] = pdu_type; /* XXX: this can change based on advertiser addr */
+ dptr[1] = BLE_CONNECT_REQ_LEN;
+ memcpy(dptr + BLE_LL_PDU_HDR_LEN, addr, BLE_DEV_ADDR_LEN);
+ /* XXX: what about this next address? I cant put this in here yet, right? */
#if 0
+ memcpy(dptr + BLE_LL_PDU_HDR_LEN + BLE_DEV_ADDR_LEN, adv_addr,
+ BLE_DEV_ADDR_LEN);
+#endif
+ dptr += BLE_LL_PDU_HDR_LEN + (2 * BLE_DEV_ADDR_LEN);
+
+ /* Access address */
+}
+
+/**
+ * Process the HCI command to create a connection.
+ *
+ * @param cmdbuf
+ *
+ * @return int
+ */
int
-ble_ll_scan_set_scan_params(uint8_t *cmd)
+ble_ll_conn_create(uint8_t *cmdbuf)
{
- uint8_t scan_type;
- uint8_t own_addr_type;
- uint8_t filter_policy;
- uint16_t scan_itvl;
- uint16_t scan_window;
- struct ble_ll_scan_sm *scansm;
-
- scansm = &g_ble_ll_scan_sm;
+ uint32_t spvn_tmo_msecs;
+ uint32_t min_spvn_tmo_msecs;
+ struct hci_create_conn ccdata;
+ struct hci_create_conn *hcc;
+ struct ble_ll_conn_sm *connsm;
/* If already enabled, we return an error */
- scansm = &g_ble_ll_scan_sm;
- if (scansm->scan_enabled) {
+ connsm = &g_ble_ll_conn_sm;
+ if (ble_ll_scan_enabled() || (connsm->conn_state != BLE_LL_CONN_STATE_IDLE)) {
return BLE_ERR_CMD_DISALLOWED;
}
- /* Get the scan interval and window */
- scan_type = cmd[0];
- scan_itvl = le16toh(cmd + 1);
- scan_window = le16toh(cmd + 3);
- own_addr_type = cmd[5];
- filter_policy = cmd[6];
+ /* Retrieve command data */
+ hcc = &ccdata;
+ hcc->scan_itvl = le16toh(cmdbuf);
+ hcc->scan_window = le16toh(cmdbuf + 2);
- /* Check scan type */
- if ((scan_type != BLE_HCI_SCAN_TYPE_PASSIVE) &&
- (scan_type != BLE_HCI_SCAN_TYPE_ACTIVE)) {
+ /* Check interval and window */
+ if ((hcc->scan_itvl < BLE_HCI_SCAN_ITVL_MIN) ||
+ (hcc->scan_itvl > BLE_HCI_SCAN_ITVL_MAX) ||
+ (hcc->scan_window < BLE_HCI_SCAN_WINDOW_MIN) ||
+ (hcc->scan_window > BLE_HCI_SCAN_WINDOW_MAX) ||
+ (hcc->scan_itvl < hcc->scan_window)) {
return BLE_ERR_INV_HCI_CMD_PARMS;
}
- /* Check interval and window */
- if ((scan_itvl < BLE_HCI_SCAN_ITVL_MIN) ||
- (scan_itvl > BLE_HCI_SCAN_ITVL_MAX) ||
- (scan_window < BLE_HCI_SCAN_WINDOW_MIN) ||
- (scan_window > BLE_HCI_SCAN_WINDOW_MAX) ||
- (scan_itvl < scan_window)) {
+ /* Check filter policy */
+ hcc->filter_policy = cmdbuf[4];
+ if (hcc->filter_policy > BLE_HCI_INITIATOR_FILT_POLICY_MAX) {
return BLE_ERR_INV_HCI_CMD_PARMS;
}
- /* Check own addr type */
- if (own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
+ /* Get peer address type and address only if no whitelist used */
+ if (hcc->filter_policy == 0) {
+ hcc->peer_addr_type = cmdbuf[5];
+ if (hcc->peer_addr_type > BLE_HCI_CONN_PEER_ADDR_MAX) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+ memcpy(&hcc->peer_addr, cmdbuf + 6, BLE_DEV_ADDR_LEN);
+ }
+
+ /* Get own address type (used in connection request) */
+ hcc->own_addr_type = cmdbuf[12];
+ if (hcc->own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
return BLE_ERR_INV_HCI_CMD_PARMS;
}
- /* Check scanner filter policy */
- if (filter_policy > BLE_HCI_SCAN_FILT_MAX) {
+ /* Check connection interval */
+ hcc->conn_itvl_min = le16toh(cmdbuf + 13);
+ hcc->conn_itvl_max = le16toh(cmdbuf + 15);
+ hcc->conn_latency = le16toh(cmdbuf + 17);
+ if ((hcc->conn_itvl_min > hcc->conn_itvl_max) ||
+ (hcc->conn_itvl_min < BLE_HCI_CONN_ITVL_MIN) ||
+ (hcc->conn_itvl_min > BLE_HCI_CONN_ITVL_MAX) ||
+ (hcc->conn_latency > BLE_HCI_CONN_LATENCY_MAX)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ /* Check supervision timeout */
+ hcc->supervision_timeout = le16toh(cmdbuf + 19);
+ if ((hcc->supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN) ||
+ (hcc->supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX))
+ {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ /*
+ * Supervision timeout (in msecs) must be more than:
+ * (1 + connLatency) * connIntervalMax * 1.25 msecs * 2.
+ */
+ spvn_tmo_msecs = hcc->supervision_timeout * BLE_HCI_CONN_SPVN_TMO_UNITS;
+ min_spvn_tmo_msecs = (hcc->conn_itvl_max << 1) + (hcc->conn_itvl_max >> 1);
+ min_spvn_tmo_msecs *= (1 + hcc->conn_latency);
+ if (spvn_tmo_msecs <= min_spvn_tmo_msecs) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ hcc->min_ce_len = le16toh(cmdbuf + 21);
+ hcc->max_ce_len = le16toh(cmdbuf + 23);
+ if (hcc->min_ce_len > hcc->max_ce_len) {
return BLE_ERR_INV_HCI_CMD_PARMS;
}
/* Set state machine parameters */
- scansm->scan_type = scan_type;
- scansm->scan_itvl = scan_itvl;
- scansm->scan_window = scan_window;
- scansm->scan_filt_policy = filter_policy;
+ ble_ll_scan_initiator_start(hcc);
+
+ /* XXX: I have not dealt with lots of the state machine parameters! */
+
+ /* Initialize the connection sm */
+ ble_ll_conn_sm_init(connsm, hcc);
- return 0;
+ /* Create the connection request */
+ ble_ll_conn_req_make(connsm);
+
+ /* XXX: gotta start scanning! */
+
+ return BLE_ERR_SUCCESS;
+}
+
+int
+ble_ll_conn_create_cancel(void)
+{
+ /* XXX: implement this */
+ return BLE_ERR_SUCCESS;
}
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 3c6a3f8..f344d87 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -154,7 +154,9 @@ ble_ll_hci_is_le_event_enabled(int bitpos)
* @param ocf Opcode command field.
* @param *rsplen Pointer to length of response
*
- * @return int
+ * @return int This function returns a BLE error code. If a command status
+ * event should be returned as opposed to command complete,
+ * 256 gets added to the return value.
*/
static int
ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
@@ -241,25 +243,22 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
}
break;
case BLE_HCI_OCF_LE_CREATE_CONN:
- /* Length should be one byte */
if (len == BLE_HCI_CREATE_CONN_LEN) {
rc = ble_ll_conn_create(cmdbuf);
}
+ rc += (BLE_ERR_MAX + 1);
break;
case BLE_HCI_OCF_LE_CREATE_CONN_CANCEL:
- /* Length should be one byte */
if (len == 0) {
rc = ble_ll_conn_create_cancel();
}
break;
case BLE_HCI_OCF_LE_CLEAR_WHITE_LIST:
- /* No params with this command */
if (len == 0) {
rc = ble_ll_whitelist_clear();
}
break;
case BLE_HCI_OCF_LE_RD_WHITE_LIST_SIZE:
- /* No params with this command */
if (len == 0) {
rc = ble_ll_whitelist_read_size(rspbuf, rsplen);
}
@@ -275,7 +274,7 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
}
break;
default:
- /* XXX: deal with unsupported command */
+ rc = BLE_ERR_UNKNOWN_HCI_CMD;
break;
}
@@ -335,17 +334,21 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
if (rc <= BLE_ERR_MAX) {
/* Create a command complete event with status from command */
cmdbuf[0] = BLE_HCI_EVCODE_COMMAND_COMPLETE;
- cmdbuf[1] = 4 + rsplen; /* Length of the data */
+ cmdbuf[1] = 4 + rsplen;
cmdbuf[2] = ble_ll_hci_get_num_cmd_pkts();
htole16(cmdbuf + 3, opcode);
cmdbuf[5] = (uint8_t)rc;
-
- /* Send the event. This event cannot be masked */
- ble_ll_hci_event_send(cmdbuf);
} else {
- /* XXX: placeholder for sending command status or other events */
- assert(0);
+ /* Create a command complete event with status from command */
+ cmdbuf[0] = BLE_HCI_EVCODE_COMMAND_STATUS;
+ cmdbuf[1] = 4;
+ cmdbuf[2] = (uint8_t)(rc - (BLE_ERR_MAX + 1));
+ cmdbuf[3] = ble_ll_hci_get_num_cmd_pkts();
+ htole16(cmdbuf + 4, opcode);
}
+
+ /* Send the event (events cannot be masked) */
+ ble_ll_hci_event_send(cmdbuf);
}
/* XXX: For now, put this here */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 521ec2b..05416a4 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -73,6 +73,11 @@ struct ble_ll_scan_sm
struct os_event scan_win_end_ev;
};
+/* Scan types */
+#define BLE_SCAN_TYPE_PASSIVE (BLE_HCI_SCAN_TYPE_PASSIVE)
+#define BLE_SCAN_TYPE_ACTIVE (BLE_HCI_SCAN_TYPE_ACTIVE)
+#define BLE_SCAN_TYPE_INITIATE (2)
+
/* The scanning state machine global object */
struct ble_ll_scan_sm g_ble_ll_scan_sm;
@@ -756,7 +761,7 @@ ble_ll_scan_rx_pdu_start(uint8_t pdu_type, struct os_mbuf *rxpdu)
*/
rc = 0;
scansm = &g_ble_ll_scan_sm;
- if (scansm->scan_type == BLE_HCI_SCAN_TYPE_ACTIVE) {
+ if (scansm->scan_type == BLE_SCAN_TYPE_ACTIVE) {
if ((pdu_type == BLE_ADV_PDU_TYPE_ADV_IND) ||
(pdu_type == BLE_ADV_PDU_TYPE_ADV_SCAN_IND)) {
rc = 1;
@@ -837,7 +842,7 @@ ble_ll_scan_rx_pdu_end(struct os_mbuf *rxpdu)
switch (pdu_type) {
case BLE_ADV_PDU_TYPE_ADV_IND:
case BLE_ADV_PDU_TYPE_ADV_SCAN_IND:
- if (scansm->scan_type == BLE_HCI_SCAN_TYPE_ACTIVE) {
+ if (scansm->scan_type == BLE_SCAN_TYPE_ACTIVE) {
chk_send_req = 1;
}
chk_whitelist = 1;
@@ -988,8 +993,6 @@ ble_ll_scan_set_scan_params(uint8_t *cmd)
uint16_t scan_window;
struct ble_ll_scan_sm *scansm;
- scansm = &g_ble_ll_scan_sm;
-
/* If already enabled, we return an error */
scansm = &g_ble_ll_scan_sm;
if (scansm->scan_enabled) {
@@ -1033,6 +1036,7 @@ ble_ll_scan_set_scan_params(uint8_t *cmd)
scansm->scan_itvl = scan_itvl;
scansm->scan_window = scan_window;
scansm->scan_filt_policy = filter_policy;
+ scansm->own_addr_type = own_addr_type;
return 0;
}
@@ -1103,6 +1107,36 @@ ble_ll_scan_can_chg_whitelist(void)
return rc;
}
+void
+ble_ll_scan_initiator_start(struct hci_create_conn *hcc)
+{
+ struct ble_ll_scan_sm *scansm;
+
+ scansm = &g_ble_ll_scan_sm;
+ scansm->scan_type = BLE_SCAN_TYPE_INITIATE;
+ scansm->scan_itvl = hcc->scan_itvl;
+ scansm->scan_window = hcc->scan_window;
+ scansm->scan_filt_policy = hcc->filter_policy;
+ scansm->own_addr_type = hcc->own_addr_type;
+}
+
+/**
+ * Checks to see if the scanner is enabled.
+ *
+ * @return int 0: not enabled; enabled otherwise
+ */
+int
+ble_ll_scan_enabled(void)
+{
+ return (int)g_ble_ll_scan_sm.scan_enabled;
+}
+
+/* Returns the PDU allocated by the scanner */
+struct os_mbuf *
+ble_ll_scan_get_pdu(void)
+{
+ return g_ble_ll_scan_sm.scan_req_pdu;
+}
/**
* ble ll scan init
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/7e35563c/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index 41ffef7..3f77d52 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -226,6 +226,15 @@
#define BLE_HCI_CONN_LATENCY_MAX (0x01f3)
#define BLE_HCI_CONN_SPVN_TIMEOUT_MIN (0x000a)
#define BLE_HCI_CONN_SPVN_TIMEOUT_MAX (0x0c80)
+#define BLE_HCI_CONN_SPVN_TMO_UNITS (10) /* msecs */
+#define BLE_HCI_INITIATOR_FILT_POLICY_MAX (1)
+
+/* Peer Address Type */
+#define BLE_HCI_CONN_PEER_ADDR_PUBLIC (0)
+#define BLE_HCI_CONN_PEER_ADDR_RANDOM (1)
+#define BLE_HCI_CONN_PEER_ADDR_PUB_ID (2)
+#define BLE_HCI_CONN_PEER_ADDR_RAND_ID (3)
+#define BLE_HCI_CONN_PEER_ADDR_MAX (3)
/* Event Codes */
#define BLE_HCI_EVCODE_INQUIRY_CMP (0x01)
[2/2] incubator-mynewt-larva git commit: Temporary fix to get
projects building with addition of ble driver dependency
Posted by we...@apache.org.
Temporary fix to get projects building with addition of ble driver dependency
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/e50f0dc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/e50f0dc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/e50f0dc3
Branch: refs/heads/master
Commit: e50f0dc30714f3373cd711582e0b10d31a7aea7b
Parents: 313f653
Author: wes3 <wi...@micosa.io>
Authored: Tue Nov 10 21:53:39 2015 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Tue Nov 10 21:54:40 2015 -0800
----------------------------------------------------------------------
net/nimble/drivers/nrf52/egg.yml | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/e50f0dc3/net/nimble/drivers/nrf52/egg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf52/egg.yml b/net/nimble/drivers/nrf52/egg.yml
index 49eb592..40c77ac 100644
--- a/net/nimble/drivers/nrf52/egg.yml
+++ b/net/nimble/drivers/nrf52/egg.yml
@@ -1,2 +1,5 @@
egg.name: net/nimble/drivers/nrf52
egg.vers: 0.1
+egg.deps:
+ - net/nimble
+ - net/nimble/controller