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/09/13 03:42:18 UTC
[25/41] incubator-mynewt-core git commit: syscfg / sysinit
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 43ccd6f..0dae650 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -19,6 +19,7 @@
#include <string.h>
#include <errno.h>
+#include "syscfg/syscfg.h"
#include "os/os.h"
#include "nimble/ble.h"
#include "nimble/hci_common.h"
@@ -29,7 +30,10 @@ _Static_assert(sizeof (struct ble_l2cap_hdr) == BLE_L2CAP_HDR_SZ,
struct os_mempool ble_l2cap_chan_pool;
-static void *ble_l2cap_chan_mem;
+static os_membuf_t ble_l2cap_chan_mem[
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_L2CAP_MAX_CHANS),
+ sizeof (struct ble_l2cap_chan))
+];
STATS_SECT_DECL(ble_l2cap_stats) ble_l2cap_stats;
STATS_NAME_START(ble_l2cap_stats)
@@ -292,57 +296,34 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
return 0;
}
-static void
-ble_l2cap_free_mem(void)
-{
- free(ble_l2cap_chan_mem);
- ble_l2cap_chan_mem = NULL;
-}
-
int
ble_l2cap_init(void)
{
int rc;
- ble_l2cap_free_mem();
-
- ble_l2cap_chan_mem = malloc(
- OS_MEMPOOL_BYTES(ble_hs_cfg.max_l2cap_chans,
- sizeof (struct ble_l2cap_chan)));
- if (ble_l2cap_chan_mem == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- rc = os_mempool_init(&ble_l2cap_chan_pool, ble_hs_cfg.max_l2cap_chans,
+ rc = os_mempool_init(&ble_l2cap_chan_pool, MYNEWT_VAL(BLE_L2CAP_MAX_CHANS),
sizeof (struct ble_l2cap_chan),
ble_l2cap_chan_mem, "ble_l2cap_chan_pool");
if (rc != 0) {
- rc = BLE_HS_EOS;
- goto err;
+ return BLE_HS_EOS;
}
rc = ble_l2cap_sig_init();
if (rc != 0) {
- goto err;
+ return rc;
}
rc = ble_sm_init();
if (rc != 0) {
- goto err;
+ return rc;
}
rc = stats_init_and_reg(
STATS_HDR(ble_l2cap_stats), STATS_SIZE_INIT_PARMS(ble_l2cap_stats,
STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_l2cap_stats), "ble_l2cap");
if (rc != 0) {
- rc = BLE_HS_EOS;
- goto err;
+ return BLE_HS_EOS;
}
return 0;
-
-err:
- ble_l2cap_free_mem();
- return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 4838067..70a3b1d 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -102,7 +102,11 @@ static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
static uint8_t ble_l2cap_sig_cur_id;
-static void *ble_l2cap_sig_proc_mem;
+static os_membuf_t ble_l2cap_sig_proc_mem[
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_L2CAP_SIG_MAX_PROCS),
+ sizeof (struct ble_l2cap_sig_proc))
+];
+
static struct os_mempool ble_l2cap_sig_proc_pool;
/*****************************************************************************
@@ -112,7 +116,7 @@ static struct os_mempool ble_l2cap_sig_proc_pool;
static void
ble_l2cap_sig_dbg_assert_proc_not_inserted(struct ble_l2cap_sig_proc *proc)
{
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
struct ble_l2cap_sig_proc *cur;
STAILQ_FOREACH(cur, &ble_l2cap_sig_procs, next) {
@@ -607,32 +611,16 @@ ble_l2cap_sig_init(void)
{
int rc;
- free(ble_l2cap_sig_proc_mem);
-
STAILQ_INIT(&ble_l2cap_sig_procs);
- if (ble_hs_cfg.max_l2cap_sig_procs > 0) {
- ble_l2cap_sig_proc_mem = malloc(
- OS_MEMPOOL_BYTES(ble_hs_cfg.max_l2cap_sig_procs,
- sizeof (struct ble_l2cap_sig_proc)));
- if (ble_l2cap_sig_proc_mem == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- rc = os_mempool_init(&ble_l2cap_sig_proc_pool,
- ble_hs_cfg.max_l2cap_sig_procs,
- sizeof (struct ble_l2cap_sig_proc),
- ble_l2cap_sig_proc_mem,
- "ble_l2cap_sig_proc_pool");
- if (rc != 0) {
- goto err;
- }
+ rc = os_mempool_init(&ble_l2cap_sig_proc_pool,
+ MYNEWT_VAL(BLE_L2CAP_SIG_MAX_PROCS),
+ sizeof (struct ble_l2cap_sig_proc),
+ ble_l2cap_sig_proc_mem,
+ "ble_l2cap_sig_proc_pool");
+ if (rc != 0) {
+ return rc;
}
return 0;
-
-err:
- free(ble_l2cap_sig_proc_mem);
- return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index f2a7b5c..edc140a 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -49,7 +49,7 @@
#include "host/ble_sm.h"
#include "ble_hs_priv.h"
-#if NIMBLE_OPT(SM)
+#if MYNEWT_VAL(BLE_SM)
/** Procedure timeout; 30 seconds. */
#define BLE_SM_TIMEOUT_OS_TICKS (30 * OS_TICKS_PER_SEC)
@@ -85,7 +85,7 @@ static ble_sm_rx_fn * const ble_sm_dispatch[] = {
[BLE_SM_OP_SIGN_INFO] = ble_sm_sign_info_rx,
[BLE_SM_OP_SEC_REQ] = ble_sm_sec_req_rx,
[BLE_SM_OP_PAIR_KEYPRESS_NOTIFY] = ble_sm_rx_noop,
-#if NIMBLE_OPT_SM_SC
+#if MYNEWT_VAL(BLE_SM_SC)
[BLE_SM_OP_PAIR_PUBLIC_KEY] = ble_sm_sc_public_key_rx,
[BLE_SM_OP_PAIR_DHKEY_CHECK] = ble_sm_sc_dhkey_check_rx,
#else
@@ -118,7 +118,7 @@ ble_sm_state_dispatch[BLE_SM_PROC_STATE_CNT] = {
[BLE_SM_PROC_STATE_ENC_RESTORE] = ble_sm_enc_restore_exec,
[BLE_SM_PROC_STATE_KEY_EXCH] = ble_sm_key_exch_exec,
[BLE_SM_PROC_STATE_SEC_REQ] = ble_sm_sec_req_exec,
-#if NIMBLE_OPT_SM_SC
+#if MYNEWT_VAL(BLE_SM_SC)
[BLE_SM_PROC_STATE_PUBLIC_KEY] = ble_sm_sc_public_key_exec,
[BLE_SM_PROC_STATE_DHKEY_CHECK] = ble_sm_sc_dhkey_check_exec,
#else
@@ -127,7 +127,11 @@ ble_sm_state_dispatch[BLE_SM_PROC_STATE_CNT] = {
#endif
};
-static void *ble_sm_proc_mem;
+static os_membuf_t ble_sm_proc_mem[
+ OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_SM_MAX_PROCS),
+ sizeof (struct ble_sm_proc))
+];
+
static struct os_mempool ble_sm_proc_pool;
/* Maintains the list of active security manager procedures. */
@@ -140,7 +144,7 @@ static void ble_sm_pair_cfg(struct ble_sm_proc *proc);
* $debug *
*****************************************************************************/
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
static uint8_t ble_sm_dbg_next_pair_rand[16];
static uint8_t ble_sm_dbg_next_pair_rand_set;
@@ -212,7 +216,7 @@ ble_sm_dbg_num_procs(void)
cnt = 0;
STAILQ_FOREACH(proc, &ble_sm_procs, next) {
- BLE_HS_DBG_ASSERT(cnt < ble_hs_cfg.max_l2cap_sm_procs);
+ BLE_HS_DBG_ASSERT(cnt < MYNEWT_VAL(BLE_SM_MAX_PROCS));
cnt++;
}
@@ -224,7 +228,7 @@ ble_sm_dbg_num_procs(void)
static void
ble_sm_dbg_assert_no_cycles(void)
{
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
ble_sm_dbg_num_procs();
#endif
}
@@ -232,7 +236,7 @@ ble_sm_dbg_assert_no_cycles(void)
static void
ble_sm_dbg_assert_not_inserted(struct ble_sm_proc *proc)
{
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
struct ble_sm_proc *cur;
STAILQ_FOREACH(cur, &ble_sm_procs, next) {
@@ -250,7 +254,7 @@ ble_sm_gen_pair_rand(uint8_t *pair_rand)
{
int rc;
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
if (ble_sm_dbg_next_pair_rand_set) {
ble_sm_dbg_next_pair_rand_set = 0;
memcpy(pair_rand, ble_sm_dbg_next_pair_rand,
@@ -272,7 +276,7 @@ ble_sm_gen_ediv(uint16_t *ediv)
{
int rc;
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
if (ble_sm_dbg_next_ediv_set) {
ble_sm_dbg_next_ediv_set = 0;
*ediv = ble_sm_dbg_next_ediv;
@@ -293,7 +297,7 @@ ble_sm_gen_master_id_rand(uint64_t *master_id_rand)
{
int rc;
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
if (ble_sm_dbg_next_master_id_rand_set) {
ble_sm_dbg_next_master_id_rand_set = 0;
*master_id_rand = ble_sm_dbg_next_master_id_rand;
@@ -314,7 +318,7 @@ ble_sm_gen_ltk(struct ble_sm_proc *proc, uint8_t *ltk)
{
int rc;
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
if (ble_sm_dbg_next_ltk_set) {
ble_sm_dbg_next_ltk_set = 0;
memcpy(ltk, ble_sm_dbg_next_ltk,
@@ -336,7 +340,7 @@ ble_sm_gen_csrk(struct ble_sm_proc *proc, uint8_t *csrk)
{
int rc;
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
if (ble_sm_dbg_next_csrk_set) {
ble_sm_dbg_next_csrk_set = 0;
memcpy(csrk, ble_sm_dbg_next_csrk,
@@ -358,7 +362,7 @@ ble_sm_gen_pub_priv(void *pub, uint32_t *priv)
{
int rc;
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
if (ble_sm_dbg_sc_keys_set) {
ble_sm_dbg_sc_keys_set = 0;
memcpy(pub, ble_sm_dbg_sc_pub_key, sizeof ble_sm_dbg_sc_pub_key);
@@ -644,7 +648,7 @@ ble_sm_proc_find(uint16_t conn_handle, uint8_t state, int is_initiator,
static void
ble_sm_insert(struct ble_sm_proc *proc)
{
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
struct ble_sm_proc *cur;
STAILQ_FOREACH(cur, &ble_sm_procs, next) {
@@ -2371,46 +2375,25 @@ ble_sm_connection_broken(uint16_t conn_handle)
ble_sm_process_result(conn_handle, &res);
}
-static void
-ble_sm_free_mem(void)
-{
- free(ble_sm_proc_mem);
-}
-
int
ble_sm_init(void)
{
int rc;
- ble_sm_free_mem();
-
STAILQ_INIT(&ble_sm_procs);
- if (ble_hs_cfg.max_l2cap_sm_procs > 0) {
- ble_sm_proc_mem = malloc(
- OS_MEMPOOL_BYTES(ble_hs_cfg.max_l2cap_sm_procs,
- sizeof (struct ble_sm_proc)));
- if (ble_sm_proc_mem == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
- rc = os_mempool_init(&ble_sm_proc_pool,
- ble_hs_cfg.max_l2cap_sm_procs,
- sizeof (struct ble_sm_proc),
- ble_sm_proc_mem,
- "ble_sm_proc_pool");
- if (rc != 0) {
- goto err;
- }
+ rc = os_mempool_init(&ble_sm_proc_pool,
+ MYNEWT_VAL(BLE_SM_MAX_PROCS),
+ sizeof (struct ble_sm_proc),
+ ble_sm_proc_mem,
+ "ble_sm_proc_pool");
+ if (rc != 0) {
+ return rc;
}
ble_sm_sc_init();
return 0;
-
-err:
- ble_sm_free_mem();
- return rc;
}
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index a2b0fcf..6b30bd8 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -20,62 +20,27 @@
#include <inttypes.h>
#include <string.h>
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(BLE_SM)
+
+#include "nimble/ble.h"
+#include "nimble/nimble_opt.h"
+#include "ble_hs_priv.h"
#include "mbedtls/aes.h"
+
+#if MYNEWT_VAL(BLE_SM_SC)
+
#include "tinycrypt/aes.h"
#include "tinycrypt/constants.h"
#include "tinycrypt/utils.h"
#include "tinycrypt/cmac_mode.h"
#include "tinycrypt/ecc_dh.h"
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "ble_hs_priv.h"
-#if NIMBLE_OPT(SM)
+#endif
static mbedtls_aes_context ble_sm_alg_ctxt;
-/* based on Core Specification 4.2 Vol 3. Part H 2.3.5.6.1 */
-static const uint32_t ble_sm_alg_dbg_priv_key[8] = {
- 0xcd3c1abd, 0x5899b8a6, 0xeb40b799, 0x4aff607b, 0xd2103f50, 0x74c9b3e3,
- 0xa3c55f38, 0x3f49f6d4
-};
-
-static const uint8_t ble_sm_alg_dbg_pub_key[64] = {
- 0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
- 0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
- 0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
- 0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
- 0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
- 0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
- 0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
- 0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc
-};
-
-static const uint8_t ble_sm_alg_dbg_f4[16] = {
- 0x2d, 0x87, 0x74, 0xa9, 0xbe, 0xa1, 0xed, 0xf1,
- 0x1c, 0xbd, 0xa9, 0x07, 0xf1, 0x16, 0xc9, 0xf2,
-};
-
-static const uint8_t ble_sm_alg_dbg_f5[32] = {
- 0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd,
- 0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29,
- 0x38, 0x0a, 0x75, 0x94, 0xb5, 0x22, 0x05, 0x98,
- 0x23, 0xcd, 0xd7, 0x69, 0x11, 0x79, 0x86, 0x69,
-};
-
-static const uint8_t ble_sm_alg_dbg_f6[16] = {
- 0x61, 0x8f, 0x95, 0xda, 0x09, 0x0b, 0x6c, 0xd2,
- 0xc5, 0xe8, 0xd0, 0x9c, 0x98, 0x73, 0xc4, 0xe3,
-};
-
-static void
-ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
-{
- BLE_HS_LOG(DEBUG, " %s=", name);
- ble_hs_log_flat_buf(buf, len);
- BLE_HS_LOG(DEBUG, "\n");
-}
-
static void
ble_sm_alg_xor_128(uint8_t *p, uint8_t *q, uint8_t *r)
{
@@ -113,36 +78,6 @@ ble_sm_alg_encrypt(uint8_t *key, uint8_t *plaintext, uint8_t *enc_data)
return 0;
}
-/**
- * Cypher based Message Authentication Code (CMAC) with AES 128 bit
- *
- * @param key 128-bit key.
- * @param in Message to be authenticated.
- * @param len Length of the message in octets.
- * @param out Output; message authentication code.
- */
-static int
-ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
- uint8_t *out)
-{
- struct tc_aes_key_sched_struct sched;
- struct tc_cmac_struct state;
-
- if (tc_cmac_setup(&state, key, &sched) == TC_FAIL) {
- return BLE_HS_EUNKNOWN;
- }
-
- if (tc_cmac_update(&state, in, len) == TC_FAIL) {
- return BLE_HS_EUNKNOWN;
- }
-
- if (tc_cmac_final(out, &state) == TC_FAIL) {
- return BLE_HS_EUNKNOWN;
- }
-
- return 0;
-}
-
int
ble_sm_alg_s1(uint8_t *k, uint8_t *r1, uint8_t *r2, uint8_t *out)
{
@@ -248,6 +183,46 @@ done:
return rc;
}
+#if MYNEWT_VAL(BLE_SM_SC)
+
+static void
+ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
+{
+ BLE_HS_LOG(DEBUG, " %s=", name);
+ ble_hs_log_flat_buf(buf, len);
+ BLE_HS_LOG(DEBUG, "\n");
+}
+
+/**
+ * Cypher based Message Authentication Code (CMAC) with AES 128 bit
+ *
+ * @param key 128-bit key.
+ * @param in Message to be authenticated.
+ * @param len Length of the message in octets.
+ * @param out Output; message authentication code.
+ */
+static int
+ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
+ uint8_t *out)
+{
+ struct tc_aes_key_sched_struct sched;
+ struct tc_cmac_struct state;
+
+ if (tc_cmac_setup(&state, key, &sched) == TC_FAIL) {
+ return BLE_HS_EUNKNOWN;
+ }
+
+ if (tc_cmac_update(&state, in, len) == TC_FAIL) {
+ return BLE_HS_EUNKNOWN;
+ }
+
+ if (tc_cmac_final(out, &state) == TC_FAIL) {
+ return BLE_HS_EUNKNOWN;
+ }
+
+ return 0;
+}
+
int
ble_sm_alg_f4(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t z,
uint8_t *out_enc_data)
@@ -465,6 +440,12 @@ ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
return 0;
}
+/* based on Core Specification 4.2 Vol 3. Part H 2.3.5.6.1 */
+static const uint32_t ble_sm_alg_dbg_priv_key[8] = {
+ 0xcd3c1abd, 0x5899b8a6, 0xeb40b799, 0x4aff607b, 0xd2103f50, 0x74c9b3e3,
+ 0xa3c55f38, 0x3f49f6d4
+};
+
/**
* pub: 64 bytes
* priv: 32 bytes
@@ -497,3 +478,4 @@ ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv)
}
#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 9854bde..f510b47 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -25,7 +25,7 @@
#include "host/ble_sm.h"
#include "ble_hs_priv.h"
-#if NIMBLE_OPT(SM)
+#if NIMBLE_BLE_SM
static int
ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_sm_lgcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_lgcy.c b/net/nimble/host/src/ble_sm_lgcy.c
index d844a6f..c884fb4 100644
--- a/net/nimble/host/src/ble_sm_lgcy.c
+++ b/net/nimble/host/src/ble_sm_lgcy.c
@@ -25,7 +25,7 @@
#include "host/ble_sm.h"
#include "ble_hs_priv.h"
-#if NIMBLE_OPT(SM)
+#if NIMBLE_BLE_SM
/**
* Create some shortened names for the passkey actions so that the table is
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 80798e1..4c7ab48 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -21,6 +21,7 @@
#define H_BLE_SM_PRIV_
#include <inttypes.h>
+#include "syscfg/syscfg.h"
#include "os/queue.h"
#include "nimble/nimble_opt.h"
@@ -196,7 +197,7 @@ struct ble_sm_dhkey_check {
uint8_t value[16];
};
-#if NIMBLE_OPT(SM)
+#if NIMBLE_BLE_SM
#define BLE_SM_PROC_STATE_NONE ((uint8_t)-1)
@@ -263,7 +264,7 @@ struct ble_sm_proc {
struct ble_sm_keys our_keys;
struct ble_sm_keys peer_keys;
-#if NIMBLE_OPT(SM_SC)
+#if MYNEWT_VAL(BLE_SM_SC)
/* Secure connections. */
uint8_t passkey_bits_exchanged;
uint8_t ri;
@@ -284,7 +285,7 @@ struct ble_sm_result {
unsigned restore:1;
};
-#ifdef BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
void ble_sm_dbg_set_next_pair_rand(uint8_t *next_pair_rand);
void ble_sm_dbg_set_next_ediv(uint16_t next_ediv);
void ble_sm_dbg_set_next_master_id_rand(uint64_t next_master_id_rand);
@@ -406,7 +407,7 @@ void ble_sm_lgcy_random_exec(struct ble_sm_proc *proc,
void ble_sm_lgcy_random_rx(struct ble_sm_proc *proc,
struct ble_sm_result *res);
-#if NIMBLE_OPT(SM_SC)
+#if MYNEWT_VAL(BLE_SM_SC)
int ble_sm_sc_io_action(struct ble_sm_proc *proc);
void ble_sm_sc_confirm_exec(struct ble_sm_proc *proc,
struct ble_sm_result *res);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 539d0f9..6a7d083 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -24,7 +24,7 @@
#include "ble_hs_priv.h"
#include "ble_sm_priv.h"
-#if NIMBLE_OPT(SM_SC)
+#if MYNEWT_VAL(BLE_SM_SC)
#define BLE_SM_SC_PASSKEY_BYTES 4
#define BLE_SM_SC_PASSKEY_BITS 20
@@ -721,4 +721,4 @@ ble_sm_sc_init(void)
ble_sm_sc_keys_generated = 0;
}
-#endif /* NIMBLE_OPT_SM_SC */
+#endif /* MYNEWT_VAL(BLE_SM_SC) */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/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
deleted file mode 100644
index ab89e9d..0000000
--- a/net/nimble/host/src/test/ble_att_clt_test.c
+++ /dev/null
@@ -1,536 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#include <string.h>
-#include <errno.h>
-#include "testutil/testutil.h"
-#include "nimble/ble.h"
-#include "host/ble_hs_test.h"
-#include "ble_hs_test_util.h"
-
-/**
- * @return The handle of the new test connection.
- */
-static uint16_t
-ble_att_clt_test_misc_init(void)
-{
- ble_hs_test_util_init();
- ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}), NULL,
- NULL);
- return 2;
-}
-
-static void
-ble_att_clt_test_misc_verify_tx_write(uint16_t handle_id, void *value,
- int value_len, int is_req)
-{
- struct ble_att_write_req req;
- struct os_mbuf *om;
-
- om = ble_hs_test_util_prev_tx_dequeue_pullup();
- TEST_ASSERT_FATAL(om != NULL);
-
- if (is_req) {
- ble_att_write_req_parse(om->om_data, om->om_len, &req);
- } else {
- ble_att_write_cmd_parse(om->om_data, om->om_len, &req);
- }
-
- TEST_ASSERT(req.bawq_handle == handle_id);
- TEST_ASSERT(om->om_len == BLE_ATT_WRITE_REQ_BASE_SZ + value_len);
- TEST_ASSERT(memcmp(om->om_data + BLE_ATT_WRITE_REQ_BASE_SZ, value,
- value_len) == 0);
-}
-
-static void
-ble_att_clt_test_tx_write_req_or_cmd(uint16_t conn_handle,
- struct ble_att_write_req *req,
- void *value, int value_len, int is_req)
-{
- struct os_mbuf *om;
- int rc;
-
- om = ble_hs_test_util_om_from_flat(value, value_len);
- if (is_req) {
- rc = ble_att_clt_tx_write_req(conn_handle, req, om);
- } else {
- rc = ble_att_clt_tx_write_cmd(conn_handle, req, om);
- }
- TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ble_att_clt_test_tx_find_info)
-{
- struct ble_att_find_info_req req;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Success. */
- req.bafq_start_handle = 1;
- req.bafq_end_handle = 0xffff;
- rc = ble_att_clt_tx_find_info(conn_handle, &req);
- TEST_ASSERT(rc == 0);
-
- /*** Error: start handle of 0. */
- req.bafq_start_handle = 0;
- req.bafq_end_handle = 0xffff;
- rc = ble_att_clt_tx_find_info(conn_handle, &req);
- TEST_ASSERT(rc == BLE_HS_EINVAL);
-
- /*** Error: start handle greater than end handle. */
- req.bafq_start_handle = 500;
- req.bafq_end_handle = 499;
- rc = ble_att_clt_tx_find_info(conn_handle, &req);
- TEST_ASSERT(rc == BLE_HS_EINVAL);
-
- /*** Success; start and end handles equal. */
- req.bafq_start_handle = 500;
- req.bafq_end_handle = 500;
- rc = ble_att_clt_tx_find_info(conn_handle, &req);
- TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ble_att_clt_test_rx_find_info)
-{
- struct ble_att_find_info_rsp rsp;
- uint16_t conn_handle;
- uint8_t buf[1024];
- uint8_t uuid128_1[16] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
- int off;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** One 128-bit UUID. */
- /* Receive response with attribute mapping. */
- off = 0;
- rsp.bafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT;
- ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
- off += BLE_ATT_FIND_INFO_RSP_BASE_SZ;
-
- htole16(buf + off, 1);
- off += 2;
- memcpy(buf + off, uuid128_1, 16);
- off += 16;
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, off);
- TEST_ASSERT(rc == 0);
-
- /*** One 16-bit UUID. */
- /* Receive response with attribute mapping. */
- off = 0;
- rsp.bafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
- ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
- off += BLE_ATT_FIND_INFO_RSP_BASE_SZ;
-
- htole16(buf + off, 2);
- off += 2;
- htole16(buf + off, 0x000f);
- off += 2;
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, off);
- TEST_ASSERT(rc == 0);
-
- /*** Two 16-bit UUIDs. */
- /* Receive response with attribute mappings. */
- off = 0;
- rsp.bafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
- ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
- off += BLE_ATT_FIND_INFO_RSP_BASE_SZ;
-
- htole16(buf + off, 3);
- off += 2;
- htole16(buf + off, 0x0010);
- off += 2;
-
- htole16(buf + off, 4);
- off += 2;
- htole16(buf + off, 0x0011);
- off += 2;
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, off);
- TEST_ASSERT(rc == 0);
-}
-
-static void
-ble_att_clt_test_case_tx_write_req_or_cmd(int is_req)
-{
- struct ble_att_write_req req;
- uint16_t conn_handle;
- uint8_t value300[500] = { 0 };
- uint8_t value5[5] = { 6, 7, 54, 34, 8 };
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** 5-byte write. */
- req.bawq_handle = 0x1234;
- ble_att_clt_test_tx_write_req_or_cmd(conn_handle, &req, value5,
- sizeof value5, is_req);
- ble_hs_test_util_tx_all();
- ble_att_clt_test_misc_verify_tx_write(0x1234, value5, sizeof value5,
- is_req);
-
- /*** Overlong write; verify command truncated to ATT MTU. */
- req.bawq_handle = 0xab83;
- ble_att_clt_test_tx_write_req_or_cmd(conn_handle, &req, value300,
- sizeof value300, is_req);
- ble_hs_test_util_tx_all();
- ble_att_clt_test_misc_verify_tx_write(0xab83, value300,
- BLE_ATT_MTU_DFLT - 3, is_req);
-}
-
-static void
-ble_att_clt_test_misc_prep_good(uint16_t handle, uint16_t offset,
- uint8_t *attr_data, uint16_t attr_data_len)
-{
- struct ble_att_prep_write_cmd req;
- struct os_mbuf *om;
- uint16_t conn_handle;
- int rc;
- int i;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- req.bapc_handle = handle;
- req.bapc_offset = offset;
- om = ble_hs_test_util_om_from_flat(attr_data, attr_data_len);
- rc = ble_att_clt_tx_prep_write(conn_handle, &req, om);
- TEST_ASSERT(rc == 0);
-
- ble_hs_test_util_tx_all();
- om = ble_hs_test_util_prev_tx_dequeue_pullup();
- TEST_ASSERT_FATAL(om != NULL);
- TEST_ASSERT(om->om_len == BLE_ATT_PREP_WRITE_CMD_BASE_SZ + attr_data_len);
-
- ble_att_prep_write_req_parse(om->om_data, om->om_len, &req);
- TEST_ASSERT(req.bapc_handle == handle);
- TEST_ASSERT(req.bapc_offset == offset);
- for (i = 0; i < attr_data_len; i++) {
- TEST_ASSERT(om->om_data[BLE_ATT_PREP_WRITE_CMD_BASE_SZ + i] ==
- attr_data[i]);
- }
-}
-
-static void
-ble_att_clt_test_misc_exec_good(uint8_t flags)
-{
- struct ble_att_exec_write_req req;
- struct os_mbuf *om;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- req.baeq_flags = flags;
- rc = ble_att_clt_tx_exec_write(conn_handle, &req);
- TEST_ASSERT(rc == 0);
-
- ble_hs_test_util_tx_all();
- om = ble_hs_test_util_prev_tx_dequeue_pullup();
- TEST_ASSERT_FATAL(om != NULL);
- TEST_ASSERT(om->om_len == BLE_ATT_EXEC_WRITE_REQ_SZ);
-
- ble_att_exec_write_req_parse(om->om_data, om->om_len, &req);
- TEST_ASSERT(req.baeq_flags == flags);
-}
-
-static void
-ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset,
- uint8_t *attr_data, uint16_t attr_data_len,
- int status)
-{
- struct ble_att_prep_write_cmd req;
- struct os_mbuf *om;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- om = ble_hs_test_util_om_from_flat(attr_data, attr_data_len);
-
- req.bapc_handle = handle;
- req.bapc_offset = offset;
- rc = ble_att_clt_tx_prep_write(conn_handle, &req, om);
- TEST_ASSERT(rc == status);
-}
-
-TEST_CASE(ble_att_clt_test_tx_write)
-{
- ble_att_clt_test_case_tx_write_req_or_cmd(0);
- ble_att_clt_test_case_tx_write_req_or_cmd(1);
-}
-
-TEST_CASE(ble_att_clt_test_tx_read)
-{
- struct ble_att_read_req req;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Success. */
- req.barq_handle = 1;
- rc = ble_att_clt_tx_read(conn_handle, &req);
- TEST_ASSERT(rc == 0);
-
- /*** Error: handle of 0. */
- req.barq_handle = 0;
- rc = ble_att_clt_tx_read(conn_handle, &req);
- TEST_ASSERT(rc == BLE_HS_EINVAL);
-}
-
-TEST_CASE(ble_att_clt_test_rx_read)
-{
- uint16_t conn_handle;
- uint8_t buf[1024];
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Basic success. */
- buf[0] = BLE_ATT_OP_READ_RSP;
- buf[1] = 0;
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, 2);
- TEST_ASSERT(rc == 0);
-
- /*** Larger response. */
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, 20);
- TEST_ASSERT(rc == 0);
-
- /*** Zero-length response. */
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, 1);
- TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ble_att_clt_test_tx_read_blob)
-{
- struct ble_att_read_blob_req req;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Success. */
- req.babq_handle = 1;
- req.babq_offset = 0;
- rc = ble_att_clt_tx_read_blob(conn_handle, &req);
- TEST_ASSERT(rc == 0);
-
- /*** Error: handle of 0. */
- req.babq_handle = 0;
- req.babq_offset = 0;
- rc = ble_att_clt_tx_read_blob(conn_handle, &req);
- TEST_ASSERT(rc == BLE_HS_EINVAL);
-}
-
-TEST_CASE(ble_att_clt_test_rx_read_blob)
-{
- uint16_t conn_handle;
- uint8_t buf[1024];
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Basic success. */
- buf[0] = BLE_ATT_OP_READ_BLOB_RSP;
- buf[1] = 0;
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, 2);
- TEST_ASSERT(rc == 0);
-
- /*** Larger response. */
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, 20);
- TEST_ASSERT(rc == 0);
-
- /*** Zero-length response. */
- rc = ble_hs_test_util_l2cap_rx_payload_flat(conn_handle, BLE_L2CAP_CID_ATT,
- buf, 1);
- TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ble_att_clt_test_tx_read_mult)
-{
- struct os_mbuf *om;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Success. */
- rc = ble_att_clt_tx_read_mult(conn_handle, ((uint16_t[]){ 1, 2 }), 2);
- TEST_ASSERT(rc == 0);
-
- ble_hs_test_util_tx_all();
- om = ble_hs_test_util_prev_tx_dequeue_pullup();
- TEST_ASSERT_FATAL(om != NULL);
- TEST_ASSERT(om->om_len == BLE_ATT_READ_MULT_REQ_BASE_SZ + 4);
-
- ble_att_read_mult_req_parse(om->om_data, om->om_len);
- TEST_ASSERT(le16toh(om->om_data + BLE_ATT_READ_MULT_REQ_BASE_SZ) == 1);
- TEST_ASSERT(le16toh(om->om_data + BLE_ATT_READ_MULT_REQ_BASE_SZ + 2) == 2);
-
- /*** Error: no handles. */
- rc = ble_att_clt_tx_read_mult(conn_handle, NULL, 0);
- TEST_ASSERT(rc == BLE_HS_EINVAL);
-}
-
-TEST_CASE(ble_att_clt_test_rx_read_mult)
-{
- uint16_t conn_handle;
- uint8_t buf[1024];
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Basic success. */
- ble_att_read_mult_rsp_write(buf, sizeof buf);
- htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 0, 12);
-
- rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf,
- BLE_ATT_READ_MULT_RSP_BASE_SZ + 2);
- TEST_ASSERT(rc == 0);
-
- /*** Larger response. */
- htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 0, 12);
- htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 2, 43);
- htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 4, 91);
- rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf,
- BLE_ATT_READ_MULT_RSP_BASE_SZ + 6);
- TEST_ASSERT(rc == 0);
-
- /*** Zero-length response. */
- rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf,
- BLE_ATT_READ_MULT_RSP_BASE_SZ + 0);
- TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ble_att_clt_test_tx_prep_write)
-{
- uint8_t attr_data[512];
- int i;
-
- for (i = 0; i < sizeof attr_data; i++) {
- attr_data[i] = i;
- }
-
- /*** Success. */
- ble_att_clt_test_misc_prep_good(123, 0, attr_data, 16);
- ble_att_clt_test_misc_prep_good(5432, 100, attr_data, 2);
- ble_att_clt_test_misc_prep_good(0x1234, 400, attr_data, 0);
- ble_att_clt_test_misc_prep_good(5432, 0, attr_data,
- BLE_ATT_MTU_DFLT -
- BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
- ble_att_clt_test_misc_prep_good(0x1234, 507, attr_data, 5);
-
- /*** Error: handle of 0. */
- ble_att_clt_test_misc_prep_bad(0, 0, attr_data, 16, BLE_HS_EINVAL);
-
- /*** Error: offset + length greater than maximum attribute size. */
- ble_att_clt_test_misc_prep_bad(1, 507, attr_data, 6, BLE_HS_EINVAL);
-
- /*** Error: packet larger than MTU. */
- ble_att_clt_test_misc_prep_bad(1, 0, attr_data,
- BLE_ATT_MTU_DFLT -
- BLE_ATT_PREP_WRITE_CMD_BASE_SZ + 1,
- BLE_HS_EINVAL);
-}
-
-TEST_CASE(ble_att_clt_test_rx_prep_write)
-{
- struct ble_att_prep_write_cmd rsp;
- uint16_t conn_handle;
- uint8_t buf[1024];
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Basic success. */
- rsp.bapc_handle = 0x1234;
- rsp.bapc_offset = 0;
- ble_att_prep_write_rsp_write(buf, sizeof buf, &rsp);
- memset(buf + BLE_ATT_PREP_WRITE_CMD_BASE_SZ, 1, 5);
- rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf,
- BLE_ATT_PREP_WRITE_CMD_BASE_SZ + 5);
- TEST_ASSERT(rc == 0);
-
- /*** 0-length write. */
- rsp.bapc_handle = 0x1234;
- rsp.bapc_offset = 0;
- ble_att_prep_write_rsp_write(buf, sizeof buf, &rsp);
- rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
- TEST_ASSERT(rc == 0);
-}
-
-TEST_CASE(ble_att_clt_test_tx_exec_write)
-{
- struct ble_att_exec_write_req req;
- uint16_t conn_handle;
- int rc;
-
- conn_handle = ble_att_clt_test_misc_init();
-
- /*** Success. */
- ble_att_clt_test_misc_exec_good(0);
- ble_att_clt_test_misc_exec_good(BLE_ATT_EXEC_WRITE_F_CONFIRM);
-
- /*** Error: invalid flags value. */
- req.baeq_flags = 0x02;
- rc = ble_att_clt_tx_exec_write(conn_handle, &req);
- TEST_ASSERT(rc == BLE_HS_EINVAL);
-}
-
-TEST_SUITE(ble_att_clt_suite)
-{
- tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
-
- ble_att_clt_test_tx_find_info();
- ble_att_clt_test_rx_find_info();
- ble_att_clt_test_tx_read();
- ble_att_clt_test_rx_read();
- ble_att_clt_test_tx_read_blob();
- ble_att_clt_test_rx_read_blob();
- ble_att_clt_test_tx_read_mult();
- ble_att_clt_test_rx_read_mult();
- ble_att_clt_test_tx_write();
- ble_att_clt_test_tx_prep_write();
- ble_att_clt_test_rx_prep_write();
- ble_att_clt_test_tx_exec_write();
-}
-
-int
-ble_att_clt_test_all(void)
-{
- ble_att_clt_suite();
-
- return tu_any_failed;
-}