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/04/05 04:15:39 UTC
[2/3] incubator-mynewt-core git commit: ble host: reduce code size.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_fsm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_fsm.c b/net/nimble/host/src/ble_fsm.c
index b380216..e6edd28 100644
--- a/net/nimble/host/src/ble_fsm.c
+++ b/net/nimble/host/src/ble_fsm.c
@@ -40,11 +40,11 @@ ble_fsm_lock(struct ble_fsm *fsm)
owner = fsm->mutex.mu_owner;
if (owner != NULL) {
- assert(owner != os_sched_get_current_task());
+ BLE_HS_DBG_ASSERT_EVAL(owner != os_sched_get_current_task());
}
rc = os_mutex_pend(&fsm->mutex, 0xffffffff);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
void
@@ -53,7 +53,7 @@ ble_fsm_unlock(struct ble_fsm *fsm)
int rc;
rc = os_mutex_release(&fsm->mutex);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
int
@@ -97,7 +97,7 @@ ble_fsm_assert_sanity(struct ble_fsm *fsm)
mask <<= 1;
}
- assert(num_set == 1);
+ BLE_HS_DBG_ASSERT(num_set == 1);
}
}
@@ -122,10 +122,10 @@ ble_fsm_proc_remove(struct ble_fsm_proc_list *src_list,
struct ble_fsm_proc *prev)
{
if (prev == NULL) {
- assert(STAILQ_FIRST(src_list) == proc);
+ BLE_HS_DBG_ASSERT(STAILQ_FIRST(src_list) == proc);
STAILQ_REMOVE_HEAD(src_list, next);
} else {
- assert(STAILQ_NEXT(prev, next) == proc);
+ BLE_HS_DBG_ASSERT(STAILQ_NEXT(prev, next) == proc);
STAILQ_NEXT(prev, next) = STAILQ_NEXT(proc, next);
}
}
@@ -179,7 +179,7 @@ ble_fsm_proc_can_pend(struct ble_fsm_proc *proc)
void
ble_fsm_proc_set_pending(struct ble_fsm_proc *proc)
{
- assert(!(proc->flags & BLE_FSM_PROC_F_PENDING));
+ BLE_HS_DBG_ASSERT(!(proc->flags & BLE_FSM_PROC_F_PENDING));
proc->flags &= ~BLE_FSM_PROC_F_EXPECTING;
proc->flags |= BLE_FSM_PROC_F_PENDING;
@@ -194,7 +194,7 @@ ble_fsm_proc_set_pending(struct ble_fsm_proc *proc)
static void
ble_fsm_proc_set_expecting(struct ble_fsm_proc *proc)
{
- assert(!(proc->flags & BLE_FSM_PROC_F_EXPECTING));
+ BLE_HS_DBG_ASSERT(!(proc->flags & BLE_FSM_PROC_F_EXPECTING));
proc->flags &= ~BLE_FSM_PROC_F_PENDING;
proc->flags |= BLE_FSM_PROC_F_EXPECTING;
@@ -306,7 +306,7 @@ ble_fsm_proc_extract(struct ble_fsm *fsm,
goto done;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
rc = 1;
goto done;
}
@@ -387,7 +387,7 @@ ble_fsm_proc_extract_list(struct ble_fsm *fsm,
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
move = 0;
done = 1;
break;
@@ -487,7 +487,7 @@ ble_fsm_wakeup(struct ble_fsm *fsm)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
break;
}
@@ -511,8 +511,8 @@ ble_fsm_new(struct ble_fsm *fsm, ble_fsm_kick_fn *kick_cb,
{
int rc;
- assert(kick_cb != NULL);
- assert(free_cb != NULL);
+ BLE_HS_DBG_ASSERT(kick_cb != NULL);
+ BLE_HS_DBG_ASSERT(free_cb != NULL);
memset(fsm, 0, sizeof *fsm);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_fsm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_fsm_priv.h b/net/nimble/host/src/ble_fsm_priv.h
index 062f37d..cc874c4 100644
--- a/net/nimble/host/src/ble_fsm_priv.h
+++ b/net/nimble/host/src/ble_fsm_priv.h
@@ -20,6 +20,8 @@
#ifndef H_BLE_FSM_PRIV_
#define H_BLE_FSM_PRIV_
+#include "os/os_mutex.h"
+
struct ble_fsm_proc {
STAILQ_ENTRY(ble_fsm_proc) next;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index da72b9c..b5cb973 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -255,11 +255,11 @@ ble_gap_lock(void)
owner = ble_gap_mutex.mu_owner;
if (owner != NULL) {
- assert(owner != os_sched_get_current_task());
+ BLE_HS_DBG_ASSERT_EVAL(owner != os_sched_get_current_task());
}
rc = os_mutex_pend(&ble_gap_mutex, 0xffffffff);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
static void
@@ -268,7 +268,7 @@ ble_gap_unlock(void)
int rc;
rc = os_mutex_release(&ble_gap_mutex);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
int
@@ -643,7 +643,7 @@ ble_gap_update_entry_alloc(uint16_t conn_handle,
#ifdef BLE_HS_DEBUG
ble_gap_lock();
- assert(ble_gap_update_find(conn_handle) == NULL);
+ BLE_HS_DBG_ASSERT(ble_gap_update_find(conn_handle) == NULL);
ble_gap_unlock();
#endif
@@ -669,7 +669,7 @@ ble_gap_update_entry_free(struct ble_gap_update_entry *entry)
int rc;
rc = os_memblock_put(&ble_gap_update_pool, entry);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
/**
@@ -1017,7 +1017,7 @@ ble_gap_currently_advertising(void)
return ble_gap_slave.state == BLE_GAP_STATE_S_DIR_ADV;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
return 0;
}
}
@@ -1092,7 +1092,7 @@ ble_gap_accept_master_conn(uint8_t addr_type, uint8_t *addr)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
rc = BLE_HS_ENOENT;
break;
}
@@ -1151,7 +1151,7 @@ ble_gap_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
rc = BLE_HS_ENOENT;
break;
}
@@ -1295,13 +1295,13 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
break;
}
/* We verified that there is a free connection when the procedure began. */
conn = ble_hs_conn_alloc();
- assert(conn != NULL);
+ BLE_HS_DBG_ASSERT(conn != NULL);
conn->bhc_handle = evt->connection_handle;
memcpy(conn->bhc_addr, evt->peer_addr, sizeof conn->bhc_addr);
@@ -1370,7 +1370,7 @@ ble_gap_master_timer_exp(void *arg)
{
ble_hs_misc_assert_no_locks();
- assert(ble_gap_master_in_progress());
+ BLE_HS_DBG_ASSERT(ble_gap_master_in_progress());
switch (ble_gap_master.op) {
case BLE_GAP_OP_M_DISC:
@@ -1395,7 +1395,7 @@ ble_gap_slave_timer_exp(void *arg)
{
ble_hs_misc_assert_no_locks();
- assert(ble_gap_slave_in_progress());
+ BLE_HS_DBG_ASSERT(ble_gap_slave_in_progress());
ble_gap_call_slave_cb(BLE_GAP_EVENT_ADV_FINISHED, 0, 1);
}
@@ -1464,9 +1464,9 @@ ble_gap_wl_enqueue(uint8_t state, int in_progress,
static void
ble_gap_wl_ack_add(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_wl.op == BLE_GAP_OP_W_SET);
- assert(ble_gap_wl.state == BLE_GAP_STATE_W_ADD);
- assert(ble_gap_wl.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.op == BLE_GAP_OP_W_SET);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.state == BLE_GAP_STATE_W_ADD);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.hci_handle == ack->bha_hci_handle);
ble_gap_wl.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -1494,10 +1494,10 @@ ble_gap_wl_tx_add(void *arg)
struct ble_gap_white_entry *white_entry;
int rc;
- assert(ble_gap_wl.op == BLE_GAP_OP_W_SET);
- assert(ble_gap_wl.state == BLE_GAP_STATE_W_ADD);
- assert(ble_gap_wl.entries != NULL);
- assert(ble_gap_wl.cur < ble_gap_wl.count);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.op == BLE_GAP_OP_W_SET);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.state == BLE_GAP_STATE_W_ADD);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.entries != NULL);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.cur < ble_gap_wl.count);
ble_hci_sched_set_ack_cb(ble_gap_wl_ack_add, NULL);
@@ -1519,9 +1519,9 @@ ble_gap_wl_tx_add(void *arg)
static void
ble_gap_wl_ack_clear(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_wl.op == BLE_GAP_OP_W_SET);
- assert(ble_gap_wl.state == BLE_GAP_STATE_W_CLEAR);
- assert(ble_gap_wl.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.op == BLE_GAP_OP_W_SET);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.state == BLE_GAP_STATE_W_CLEAR);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.hci_handle == ack->bha_hci_handle);
ble_gap_wl.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -1542,8 +1542,8 @@ ble_gap_wl_tx_clear(void *arg)
{
int rc;
- assert(ble_gap_wl.op == BLE_GAP_OP_W_SET);
- assert(ble_gap_wl.state == BLE_GAP_STATE_W_CLEAR);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.op == BLE_GAP_OP_W_SET);
+ BLE_HS_DBG_ASSERT(ble_gap_wl.state == BLE_GAP_STATE_W_CLEAR);
ble_hci_sched_set_ack_cb(ble_gap_wl_ack_clear, NULL);
@@ -1627,7 +1627,7 @@ done:
static void
ble_gap_adv_ack_disable(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_slave.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_slave.hci_handle == ack->bha_hci_handle);
ble_gap_slave.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -1728,7 +1728,7 @@ ble_gap_adv_itvls(uint8_t disc_mode, uint8_t conn_mode,
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
*out_itvl_min = BLE_GAP_ADV_FAST_INTERVAL2_MIN;
*out_itvl_max = BLE_GAP_ADV_FAST_INTERVAL2_MAX;
break;
@@ -1752,7 +1752,7 @@ ble_gap_adv_get_dispatch(void)
return ble_gap_dispatch_adv_dir[ble_gap_slave.state];
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
return NULL;
}
}
@@ -1787,7 +1787,7 @@ ble_gap_adv_next_state(void)
static void
ble_gap_adv_ack(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_slave.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_slave.hci_handle == ack->bha_hci_handle);
ble_gap_slave.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -1848,7 +1848,7 @@ ble_gap_adv_data_tx(void *arg)
uint8_t flags;
int rc;
- assert(ble_gap_slave.op != BLE_GAP_OP_NULL);
+ BLE_HS_DBG_ASSERT(ble_gap_slave.op != BLE_GAP_OP_NULL);
/* Calculate the value of the flags field from the discoverable mode. */
flags = 0;
@@ -1865,7 +1865,7 @@ ble_gap_adv_data_tx(void *arg)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
break;
}
@@ -1877,7 +1877,7 @@ ble_gap_adv_data_tx(void *arg)
rc = ble_hs_adv_set_flat(BLE_HS_ADV_TYPE_FLAGS, 1, &flags,
ble_gap_slave.adv_data, &adv_data_len,
BLE_HCI_MAX_ADV_DATA_LEN);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT(rc == 0);
}
/* Encode the transmit power AD field. */
@@ -1885,7 +1885,7 @@ ble_gap_adv_data_tx(void *arg)
&ble_gap_slave.tx_pwr_lvl,
ble_gap_slave.adv_data,
&adv_data_len, BLE_HCI_MAX_ADV_DATA_LEN);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT(rc == 0);
ble_hci_sched_set_ack_cb(ble_gap_adv_ack, NULL);
rc = host_hci_cmd_le_set_adv_data(ble_gap_slave.adv_data,
@@ -1907,7 +1907,7 @@ ble_gap_adv_power_ack(struct ble_hci_ack *ack, void *arg)
{
int8_t power_level;
- assert(ble_gap_slave.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_slave.hci_handle == ack->bha_hci_handle);
ble_gap_slave.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -1984,7 +1984,7 @@ ble_gap_adv_params_tx(void *arg)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
break;
}
@@ -2087,7 +2087,7 @@ ble_gap_adv_start(uint8_t discoverable_mode, uint8_t connectable_mode,
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
break;
}
@@ -2194,9 +2194,9 @@ ble_gap_adv_rsp_set_fields(struct ble_hs_adv_fields *rsp_fields)
static void
ble_gap_disc_ack_disable(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_master.op == BLE_GAP_OP_M_DISC);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_DISC_DISABLE);
- assert(ble_gap_master.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_DISC);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_DISC_DISABLE);
+ BLE_HS_DBG_ASSERT(ble_gap_master.hci_handle == ack->bha_hci_handle);
ble_gap_master.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -2217,8 +2217,8 @@ ble_gap_disc_tx_disable(void *arg)
{
int rc;
- assert(ble_gap_master.op == BLE_GAP_OP_M_DISC);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_DISC_DISABLE);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_DISC);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_DISC_DISABLE);
ble_hci_sched_set_ack_cb(ble_gap_disc_ack_disable, NULL);
rc = host_hci_cmd_le_set_scan_enable(0, 0);
@@ -2238,9 +2238,9 @@ ble_gap_disc_tx_disable(void *arg)
static void
ble_gap_disc_ack_enable(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_master.op == BLE_GAP_OP_M_DISC);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_DISC_ENABLE);
- assert(ble_gap_master.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_DISC);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_DISC_ENABLE);
+ BLE_HS_DBG_ASSERT(ble_gap_master.hci_handle == ack->bha_hci_handle);
ble_gap_master.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -2260,8 +2260,8 @@ ble_gap_disc_tx_enable(void *arg)
{
int rc;
- assert(ble_gap_master.op == BLE_GAP_OP_M_DISC);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_DISC_ENABLE);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_DISC);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_DISC_ENABLE);
ble_hci_sched_set_ack_cb(ble_gap_disc_ack_enable, NULL);
rc = host_hci_cmd_le_set_scan_enable(1, 0);
@@ -2280,9 +2280,9 @@ ble_gap_disc_tx_enable(void *arg)
static void
ble_gap_disc_ack_params(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_master.op == BLE_GAP_OP_M_DISC);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_DISC_PARAMS);
- assert(ble_gap_master.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_DISC);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_DISC_PARAMS);
+ BLE_HS_DBG_ASSERT(ble_gap_master.hci_handle == ack->bha_hci_handle);
ble_gap_master.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -2304,8 +2304,8 @@ ble_gap_disc_tx_params(void *arg)
{
int rc;
- assert(ble_gap_master.op == BLE_GAP_OP_M_DISC);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_DISC_PARAMS);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_DISC);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_DISC_PARAMS);
ble_hci_sched_set_ack_cb(ble_gap_disc_ack_params, NULL);
rc = host_hci_cmd_le_set_scan_params(
@@ -2412,9 +2412,9 @@ done:
static void
ble_gap_conn_create_ack(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_gap_master.op == BLE_GAP_OP_M_CONN);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_UNACKED);
- assert(ble_gap_master.hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_CONN);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_UNACKED);
+ BLE_HS_DBG_ASSERT(ble_gap_master.hci_handle == ack->bha_hci_handle);
ble_gap_master.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -2436,8 +2436,8 @@ ble_gap_conn_create_tx(void *arg)
struct hci_create_conn hcc;
int rc;
- assert(ble_gap_master.op == BLE_GAP_OP_M_CONN);
- assert(ble_gap_master.state == BLE_GAP_STATE_M_PENDING);
+ BLE_HS_DBG_ASSERT(ble_gap_master.op == BLE_GAP_OP_M_CONN);
+ BLE_HS_DBG_ASSERT(ble_gap_master.state == BLE_GAP_STATE_M_PENDING);
hcc.scan_itvl = ble_gap_master.conn.params.scan_itvl;
hcc.scan_window = ble_gap_master.conn.params.scan_window;
@@ -2733,8 +2733,8 @@ ble_gap_param_neg_reply_ack(struct ble_hci_ack *ack, void *arg)
ble_gap_lock();
entry = arg;
- assert(entry->state == BLE_GAP_STATE_U_NEG_REPLY);
- assert(entry->hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(entry->state == BLE_GAP_STATE_U_NEG_REPLY);
+ BLE_HS_DBG_ASSERT(entry->hci_handle == ack->bha_hci_handle);
SLIST_REMOVE(&ble_gap_update_entries, entry,
ble_gap_update_entry, next);
@@ -2756,8 +2756,8 @@ ble_gap_param_reply_ack(struct ble_hci_ack *ack, void *arg)
ble_gap_lock();
entry = arg;
- assert(entry->state == BLE_GAP_STATE_U_REPLY);
- assert(entry->hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(entry->state == BLE_GAP_STATE_U_REPLY);
+ BLE_HS_DBG_ASSERT(entry->hci_handle == ack->bha_hci_handle);
entry->hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -2941,8 +2941,8 @@ ble_gap_update_ack(struct ble_hci_ack *ack, void *arg)
ble_gap_lock();
entry = arg;
- assert(entry->state == BLE_GAP_STATE_U_UPDATE);
- assert(entry->hci_handle == ack->bha_hci_handle);
+ BLE_HS_DBG_ASSERT(entry->state == BLE_GAP_STATE_U_UPDATE);
+ BLE_HS_DBG_ASSERT(entry->hci_handle == ack->bha_hci_handle);
ble_gap_master.hci_handle = BLE_HCI_SCHED_HANDLE_NONE;
@@ -2974,7 +2974,7 @@ ble_gap_update_tx(void *arg)
ble_gap_lock();
entry = arg;
- assert(entry->state == BLE_GAP_STATE_U_UPDATE);
+ BLE_HS_DBG_ASSERT(entry->state == BLE_GAP_STATE_U_UPDATE);
cmd.handle = entry->conn_handle;
cmd.conn_itvl_min = entry->params.itvl_min;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index aab4684..385fd0a 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -18,7 +18,6 @@
*/
#include <stddef.h>
-#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
@@ -707,7 +706,7 @@ ble_gattc_proc_free(struct ble_fsm_proc *proc)
if (proc != NULL) {
rc = os_memblock_put(&ble_gattc_proc_pool, proc);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
}
@@ -812,7 +811,7 @@ ble_gattc_new_proc(uint16_t conn_handle, uint8_t op,
static const struct ble_gattc_dispatch_entry *
ble_gattc_dispatch_get(uint8_t op)
{
- assert(op < BLE_GATT_OP_MAX);
+ BLE_HS_DBG_ASSERT(op < BLE_GATT_OP_MAX);
return ble_gattc_dispatch + op;
}
@@ -888,7 +887,7 @@ ble_gattc_heartbeat(void *unused)
rc = os_callout_reset(&ble_gattc_heartbeat_timer.cf_c,
BLE_GATT_HEARTBEAT_PERIOD * OS_TICKS_PER_SEC / 1000);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
/**
@@ -1110,7 +1109,7 @@ ble_gattc_disc_all_svcs_kick(struct ble_gattc_proc *proc)
int rc;
rc = ble_uuid_16_to_128(BLE_ATT_UUID_PRIMARY_SERVICE, uuid128);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
req.bagq_start_handle = proc->disc_all_svcs.prev_handle + 1;
req.bagq_end_handle = 0xffff;
@@ -1515,7 +1514,7 @@ ble_gattc_find_inc_svcs_kick(struct ble_gattc_proc *proc)
read_type_req.batq_end_handle = proc->find_inc_svcs.end_handle;
rc = ble_uuid_16_to_128(BLE_ATT_UUID_INCLUDE, uuid128);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
rc = ble_att_clt_tx_read_type(proc->fsm_proc.conn_handle,
&read_type_req, uuid128);
@@ -1801,7 +1800,7 @@ ble_gattc_disc_all_chrs_kick(struct ble_gattc_proc *proc)
int rc;
rc = ble_uuid_16_to_128(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
req.batq_start_handle = proc->disc_all_chrs.prev_handle + 1;
req.batq_end_handle = proc->disc_all_chrs.end_handle;
@@ -2023,7 +2022,7 @@ ble_gattc_disc_chr_uuid_kick(struct ble_gattc_proc *proc)
int rc;
rc = ble_uuid_16_to_128(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
req.batq_start_handle = proc->disc_chr_uuid.prev_handle + 1;
req.batq_end_handle = proc->disc_chr_uuid.end_handle;
@@ -4042,7 +4041,7 @@ ble_gattc_rx_extract_cb(struct ble_fsm_proc *proc, void *arg)
rx_entry = ble_gattc_rx_entry_find(proc->op,
extract_arg->rx_entries,
extract_arg->num_rx_entries);
- assert(rx_entry != NULL);
+ BLE_HS_DBG_ASSERT(rx_entry != NULL);
if (rx_entry != NULL) {
extract_arg->out_rx_entry = rx_entry;
return BLE_FSM_EXTRACT_EMOVE_STOP;
@@ -4720,7 +4719,7 @@ ble_gattc_started(void)
rc = os_callout_reset(&ble_gattc_heartbeat_timer.cf_c,
BLE_GATT_HEARTBEAT_PERIOD * OS_TICKS_PER_SEC / 1000);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index 257e1ff..b6bd522 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -18,7 +18,6 @@
*/
#include <stddef.h>
-#include <assert.h>
#include <string.h>
#include "console/console.h"
#include "nimble/ble.h"
@@ -78,7 +77,7 @@ ble_gatts_svc_access(uint16_t conn_handle, uint16_t attr_handle,
STATS_INC(ble_gatts_stats, svc_def_reads);
- assert(op == BLE_ATT_ACCESS_OP_READ);
+ BLE_HS_DBG_ASSERT(op == BLE_ATT_ACCESS_OP_READ);
svc = arg;
@@ -110,7 +109,7 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
STATS_INC(ble_gatts_stats, svc_inc_reads);
- assert(op == BLE_ATT_ACCESS_OP_READ);
+ BLE_HS_DBG_ASSERT(op == BLE_ATT_ACCESS_OP_READ);
entry = arg;
@@ -222,7 +221,7 @@ ble_gatts_chr_def_access(uint16_t conn_handle, uint16_t attr_handle,
STATS_INC(ble_gatts_stats, chr_def_reads);
- assert(op == BLE_ATT_ACCESS_OP_READ);
+ BLE_HS_DBG_ASSERT(op == BLE_ATT_ACCESS_OP_READ);
chr = arg;
@@ -277,7 +276,7 @@ ble_gatts_chr_op(uint8_t att_op)
return BLE_GATT_ACCESS_OP_WRITE_CHR;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
return BLE_GATT_ACCESS_OP_READ_CHR;
}
}
@@ -313,7 +312,7 @@ ble_gatts_chr_val_access(uint16_t conn_handle, uint16_t attr_handle,
int rc;
chr = arg;
- assert(chr != NULL && chr->access_cb != NULL);
+ BLE_HS_DBG_ASSERT(chr != NULL && chr->access_cb != NULL);
gatt_op = ble_gatts_chr_op(att_op);
gatt_ctxt.chr_access.chr = chr;
@@ -390,8 +389,8 @@ ble_gatts_register_inc(struct ble_gatts_svc_entry *entry)
uint16_t handle;
int rc;
- assert(entry->handle != 0);
- assert(entry->end_group_handle != 0xffff);
+ BLE_HS_DBG_ASSERT(entry->handle != 0);
+ BLE_HS_DBG_ASSERT(entry->end_group_handle != 0xffff);
rc = ble_att_svr_register_uuid16(BLE_ATT_UUID_INCLUDE, HA_FLAG_PERM_READ,
&handle, ble_gatts_inc_access, entry);
@@ -416,7 +415,7 @@ ble_gatts_dsc_op(uint8_t att_op)
return BLE_GATT_ACCESS_OP_WRITE_DSC;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
return BLE_GATT_ACCESS_OP_READ_DSC;
}
}
@@ -452,7 +451,7 @@ ble_gatts_dsc_access(uint16_t conn_handle, uint16_t attr_handle,
int rc;
dsc = arg;
- assert(dsc != NULL && dsc->access_cb != NULL);
+ BLE_HS_DBG_ASSERT(dsc != NULL && dsc->access_cb != NULL);
gatt_op = ble_gatts_dsc_op(att_op);
gatt_ctxt.dsc_access.dsc = dsc;
@@ -621,7 +620,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
return BLE_ATT_ERR_UNLIKELY;
}
@@ -718,7 +717,7 @@ ble_gatts_register_chr(const struct ble_gatt_chr_def *chr,
if (rc != 0) {
return rc;
}
- assert(val_handle == def_handle + 1);
+ BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
if (register_cb != NULL) {
register_ctxt.chr_reg.def_handle = def_handle;
@@ -732,7 +731,7 @@ ble_gatts_register_chr(const struct ble_gatt_chr_def *chr,
if (rc != 0) {
return rc;
}
- assert(dsc_handle == def_handle + 2);
+ BLE_HS_DBG_ASSERT(dsc_handle == def_handle + 2);
}
/* Register each descriptor. */
@@ -814,7 +813,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
}
rc = ble_gatts_svc_type_to_uuid(svc->type, &uuid16);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
/* Register service definition attribute (cast away const on callback
* arg).
@@ -835,7 +834,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
if (svc->includes != NULL) {
for (i = 0; svc->includes[i] != NULL; i++) {
idx = ble_gatts_find_svc(svc->includes[i]);
- assert(idx != -1);
+ BLE_HS_DBG_ASSERT_EVAL(idx != -1);
rc = ble_gatts_register_inc(ble_gatts_svc_entries + idx);
if (rc != 0) {
@@ -950,7 +949,7 @@ ble_gatts_conn_deinit(struct ble_gatts_conn *gatts_conn)
if (gatts_conn->clt_cfgs != NULL) {
rc = os_memblock_put(&ble_gatts_clt_cfg_pool, gatts_conn->clt_cfgs);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
gatts_conn->clt_cfgs = NULL;
}
@@ -980,12 +979,12 @@ ble_gatts_clt_cfg_init(void)
int rc;
rc = ble_uuid_16_to_128(BLE_ATT_UUID_CHARACTERISTIC, uuid128);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
/* Count the number of client-configurable characteristics. */
ble_gatts_num_cfgable_chrs = 0;
ha = NULL;
- while (ble_att_svr_find_by_uuid(uuid128, &ha) == 0) {
+ while ((ha = ble_att_svr_find_by_uuid(ha, uuid128)) != NULL) {
chr = ha->ha_cb_arg;
if (ble_gatts_chr_clt_cfg_allowed(chr) != 0) {
ble_gatts_num_cfgable_chrs++;
@@ -1019,11 +1018,11 @@ ble_gatts_clt_cfg_init(void)
/* Fill the cache. */
idx = 0;
ha = NULL;
- while (ble_att_svr_find_by_uuid(uuid128, &ha) == 0) {
+ while ((ha = ble_att_svr_find_by_uuid(ha, uuid128)) != NULL) {
chr = ha->ha_cb_arg;
allowed_flags = ble_gatts_chr_clt_cfg_allowed(chr);
if (allowed_flags != 0) {
- assert(idx < ble_gatts_num_cfgable_chrs);
+ BLE_HS_DBG_ASSERT_EVAL(idx < ble_gatts_num_cfgable_chrs);
ble_gatts_clt_cfgs[idx].chr_def_handle = ha->ha_handle_id;
ble_gatts_clt_cfgs[idx].allowed = allowed_flags;
@@ -1133,9 +1132,9 @@ ble_gatts_chr_updated(uint16_t chr_def_handle)
conn != NULL;
conn = SLIST_NEXT(conn, bhc_next)) {
- assert(conn->bhc_gatt_svr.num_clt_cfgs > idx);
+ BLE_HS_DBG_ASSERT_EVAL(conn->bhc_gatt_svr.num_clt_cfgs > idx);
clt_cfg = conn->bhc_gatt_svr.clt_cfgs + idx;
- assert(clt_cfg->chr_def_handle == chr_def_handle);
+ BLE_HS_DBG_ASSERT_EVAL(clt_cfg->chr_def_handle == chr_def_handle);
if (clt_cfg->flags &
(BLE_GATTS_CLT_CFG_F_NOTIFY | BLE_GATTS_CLT_CFG_F_INDICATE)) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hci_sched.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_sched.c b/net/nimble/host/src/ble_hci_sched.c
index 2178eea..8b2f51a 100644
--- a/net/nimble/host/src/ble_hci_sched.c
+++ b/net/nimble/host/src/ble_hci_sched.c
@@ -19,7 +19,6 @@
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include "os/queue.h"
#include "os/os_mempool.h"
#include "ble_hs_priv.h"
@@ -52,12 +51,11 @@ ble_hci_sched_lock(void)
int rc;
owner = ble_hci_sched_mutex.mu_owner;
- if (owner != NULL) {
- assert(owner != os_sched_get_current_task());
- }
+ BLE_HS_DBG_ASSERT_EVAL(owner == NULL ||
+ owner != os_sched_get_current_task());
rc = os_mutex_pend(&ble_hci_sched_mutex, 0xffffffff);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
static void
@@ -66,7 +64,7 @@ ble_hci_sched_unlock(void)
int rc;
rc = os_mutex_release(&ble_hci_sched_mutex);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
int
@@ -103,7 +101,7 @@ ble_hci_sched_entry_free(struct ble_hci_sched_entry *entry)
int rc;
rc = os_memblock_put(&ble_hci_sched_entry_pool, entry);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
/**
@@ -117,14 +115,14 @@ ble_hci_sched_entry_remove(struct ble_hci_sched_entry *entry,
struct ble_hci_sched_entry *prev)
{
if (os_started()) {
- assert(ble_hci_sched_locked_by_cur_task());
+ BLE_HS_DBG_ASSERT(ble_hci_sched_locked_by_cur_task());
}
if (prev == NULL) {
- assert(STAILQ_FIRST(&ble_hci_sched_list) == entry);
+ BLE_HS_DBG_ASSERT(STAILQ_FIRST(&ble_hci_sched_list) == entry);
STAILQ_REMOVE_HEAD(&ble_hci_sched_list, next);
} else {
- assert(STAILQ_NEXT(prev, next) == prev);
+ BLE_HS_DBG_ASSERT(STAILQ_NEXT(prev, next) == prev);
STAILQ_NEXT(prev, next) = STAILQ_NEXT(prev, next);
}
}
@@ -306,7 +304,7 @@ ble_hci_sched_process_next(void)
struct ble_hci_sched_entry *entry;
int rc;
- assert(ble_hci_sched_cur_entry == NULL);
+ BLE_HS_DBG_ASSERT(ble_hci_sched_cur_entry == NULL);
ble_hci_sched_lock();
@@ -400,7 +398,7 @@ void
ble_hci_sched_set_ack_cb(ble_hci_sched_ack_fn *cb, void *arg)
{
/* Don't allow the current callback to be replaced with another. */
- assert(ble_hci_sched_ack_cb == NULL || cb == NULL);
+ BLE_HS_DBG_ASSERT(ble_hci_sched_ack_cb == NULL || cb == NULL);
ble_hci_sched_ack_cb = cb;
ble_hci_sched_ack_arg = arg;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/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 1299fb1..d646962 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -145,7 +145,7 @@ ble_hs_task_handler(void *arg)
break;
default:
- assert(0);
+ BLE_HS_DBG_ASSERT(0);
break;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index 29a8e1e..faf63b0 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -17,7 +17,6 @@
* under the License.
*/
-#include <assert.h>
#include <string.h>
#include <errno.h>
#include "nimble/ble.h"
@@ -49,7 +48,7 @@ ble_hs_adv_set_flat(uint8_t type, int data_len, void *data,
int rc;
- assert(data_len > 0);
+ BLE_HS_DBG_ASSERT(data_len > 0);
rc = ble_hs_adv_set_hdr(type, data_len, max_len, dst, dst_len);
if (rc != 0) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index aa1c6da..4d04a24 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -17,7 +17,6 @@
* under the License.
*/
-#include <assert.h>
#include <string.h>
#include <errno.h>
#include "os/os.h"
@@ -39,11 +38,11 @@ ble_hs_conn_lock(void)
owner = ble_hs_conn_mutex.mu_owner;
if (owner != NULL) {
- assert(owner != os_sched_get_current_task());
+ BLE_HS_DBG_ASSERT_EVAL(owner != os_sched_get_current_task());
}
rc = os_mutex_pend(&ble_hs_conn_mutex, 0xffffffff);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
void
@@ -52,7 +51,7 @@ ble_hs_conn_unlock(void)
int rc;
rc = os_mutex_release(&ble_hs_conn_mutex);
- assert(rc == 0 || rc == OS_NOT_STARTED);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
}
int
@@ -241,7 +240,7 @@ ble_hs_conn_free(struct ble_hs_conn *conn)
}
rc = os_memblock_put(&ble_hs_conn_pool, conn);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
STATS_INC(ble_hs_stats, conn_delete);
}
@@ -258,7 +257,7 @@ ble_hs_conn_insert(struct ble_hs_conn *conn)
ble_hs_conn_lock();
- assert(ble_hs_conn_find(conn->bhc_handle) == NULL);
+ BLE_HS_DBG_ASSERT_EVAL(ble_hs_conn_find(conn->bhc_handle) == NULL);
SLIST_INSERT_HEAD(&ble_hs_conns, conn, bhc_next);
ble_hs_conn_unlock();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hs_endian.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_endian.h b/net/nimble/host/src/ble_hs_endian.h
new file mode 100644
index 0000000..c2342ff
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_endian.h
@@ -0,0 +1,57 @@
+/**
+ * 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.
+ */
+
+#ifndef H_BLE_HS_ENDIAN_
+#define H_BLE_HS_ENDIAN_
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
+#define TOFROMLE16(x) ((uint16_t) (x))
+#define TOFROMLE32(x) ((uint32_t) (x))
+#define TOFROMLE64(x) ((uint64_t) (x))
+
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+
+#define TOFROMLE16(x) ((uint16_t) \
+ ((((x) & 0xff00) >> 8) | \
+ (((x) & 0x00ff) << 8)))
+
+#define TOFROMLE32(x) ((uint32_t) \
+ ((((x) & 0xff000000) >> 24) | \
+ (((x) & 0x00ff0000) >> 8) | \
+ (((x) & 0x0000ff00) << 8) | \
+ (((x) & 0x000000ff) << 24)))
+
+#define TOFROMLE64(x) ((uint64_t) \
+ ((((x) & 0xff00000000000000ull) >> 56) | \
+ (((x) & 0x00ff000000000000ull) >> 40) | \
+ (((x) & 0x0000ff0000000000ull) >> 24) | \
+ (((x) & 0x000000ff00000000ull) >> 8) | \
+ (((x) & 0x00000000ff000000ull) << 8) | \
+ (((x) & 0x0000000000ff0000ull) << 24) | \
+ (((x) & 0x000000000000ff00ull) << 40) | \
+ (((x) & 0x00000000000000ffull) << 56)))
+
+#else
+
+#error Unsupported endianness.
+
+#endif
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 5c3e8f0..a02e456 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -71,11 +71,11 @@ void
ble_hs_misc_assert_no_locks(void)
{
if (os_started()) {
- assert(!ble_hs_conn_locked_by_cur_task());
- assert(!ble_gattc_locked_by_cur_task());
- assert(!ble_gap_locked_by_cur_task());
- assert(!ble_hci_sched_locked_by_cur_task());
- assert(!ble_l2cap_sm_locked_by_cur_task());
+ assert(!ble_hs_conn_locked_by_cur_task() &&
+ !ble_gattc_locked_by_cur_task() &&
+ !ble_gap_locked_by_cur_task() &&
+ !ble_hci_sched_locked_by_cur_task() &&
+ !ble_l2cap_sm_locked_by_cur_task());
}
}
@@ -157,7 +157,7 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
int rc;
rc = ble_hs_misc_conn_chan_find(conn_handle, cid, &conn, &chan);
- assert(conn == NULL || chan != NULL);
+ BLE_HS_DBG_ASSERT(conn == NULL || chan != NULL);
if (out_conn != NULL) {
*out_conn = conn;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 2e5a664..9ecffe2 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -20,11 +20,8 @@
#ifndef H_BLE_HS_PRIV_
#define H_BLE_HS_PRIV_
+#include <assert.h>
#include <inttypes.h>
-#include "stats/stats.h"
-#include "log/log.h"
-#include "nimble/nimble_opt.h"
-#include "host/ble_hs.h"
#include "ble_att_cmd.h"
#include "ble_att_priv.h"
#include "ble_fsm_priv.h"
@@ -33,14 +30,19 @@
#include "ble_hci_sched.h"
#include "ble_hs_adv_priv.h"
#include "ble_hs_conn.h"
+#include "ble_hs_endian.h"
#include "ble_hs_startup.h"
#include "ble_l2cap_priv.h"
#include "ble_l2cap_sig.h"
#include "ble_l2cap_sm.h"
-struct os_mbuf;
-struct os_mempool;
+#include "host/ble_hs.h"
+#include "log/log.h"
+#include "nimble/nimble_opt.h"
+#include "stats/stats.h"
struct ble_hs_conn;
struct ble_l2cap_chan;
+struct os_mbuf;
+struct os_mempool;
#define BLE_HOST_HCI_EVENT_CTLR_EVENT (OS_EVENT_T_PERUSER + 0)
#define BLE_HS_KICK_HCI_EVENT (OS_EVENT_T_PERUSER + 1)
@@ -108,4 +110,16 @@ int ble_hs_misc_pullup_base(struct os_mbuf **om, int base_len);
(addr)[0], (addr)[1], (addr)[2], \
(addr)[3], (addr)[4], (addr)[5])
+#if BLE_HS_DEBUG
+#define BLE_HS_DBG_ASSERT(x) assert(x)
+#else
+#define BLE_HS_DBG_ASSERT(x)
+#endif
+
+#if BLE_HS_DEBUG
+#define BLE_HS_DBG_ASSERT_EVAL(x) assert(x)
+#else
+#define BLE_HS_DBG_ASSERT_EVAL(x) ((void)(x))
+#endif
+
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index 6b505dc..c2d27f6 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -19,7 +19,6 @@
#include <stddef.h>
#include <string.h>
-#include <assert.h>
#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "ble_hs_priv.h"
@@ -73,7 +72,7 @@ ble_hs_startup_enqueue_tx(void)
}
tx_fn = ble_hs_startup_dispatch[ble_hs_startup_state];
- assert(tx_fn != NULL);
+ BLE_HS_DBG_ASSERT(tx_fn != NULL);
rc = ble_hci_sched_enqueue(tx_fn, NULL, NULL);
if (rc != 0) {
@@ -87,7 +86,7 @@ ble_hs_startup_enqueue_tx(void)
static void
ble_hs_startup_gen_ack(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_hs_startup_state < BLE_HS_STARTUP_STATE_MAX);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state < BLE_HS_STARTUP_STATE_MAX);
if (ack->bha_status != 0) {
ble_hs_startup_failure(ack->bha_status);
@@ -101,7 +100,8 @@ ble_hs_startup_gen_ack(struct ble_hci_ack *ack, void *arg)
static void
ble_hs_startup_le_read_sup_f_ack(struct ble_hci_ack *ack, void *arg)
{
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_LE_READ_SUP_F);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_LE_READ_SUP_F);
if (ack->bha_status != 0) {
ble_hs_startup_failure(ack->bha_status);
@@ -121,7 +121,8 @@ ble_hs_startup_le_read_sup_f_tx(void *arg)
{
int rc;
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_LE_READ_SUP_F);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_LE_READ_SUP_F);
ble_hci_sched_set_ack_cb(ble_hs_startup_le_read_sup_f_ack, NULL);
rc = host_hci_cmd_le_read_loc_supp_feat();
@@ -139,7 +140,8 @@ ble_hs_startup_le_read_buf_size_ack(struct ble_hci_ack *ack, void *arg)
uint8_t max_pkts;
int rc;
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_LE_READ_BUF_SZ);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_LE_READ_BUF_SZ);
if (ack->bha_status != 0) {
ble_hs_startup_failure(ack->bha_status);
@@ -169,7 +171,8 @@ ble_hs_startup_le_read_buf_sz_tx(void *arg)
{
int rc;
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_LE_READ_BUF_SZ);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_LE_READ_BUF_SZ);
ble_hci_sched_set_ack_cb(ble_hs_startup_le_read_buf_size_ack, NULL);
rc = host_hci_cmd_le_read_buffer_size();
@@ -185,7 +188,8 @@ ble_hs_startup_le_set_evmask_tx(void *arg)
{
int rc;
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_LE_SET_EVMASK);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_LE_SET_EVMASK);
ble_hci_sched_set_ack_cb(ble_hs_startup_gen_ack, NULL);
rc = host_hci_cmd_le_set_event_mask(0x000000000000001f);
@@ -201,7 +205,8 @@ ble_hs_startup_set_evmask_tx(void *arg)
{
int rc;
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_SET_EVMASK);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_SET_EVMASK);
ble_hci_sched_set_ack_cb(ble_hs_startup_gen_ack, NULL);
rc = host_hci_cmd_set_event_mask(0x20001fffffffffff);
@@ -217,7 +222,8 @@ ble_hs_startup_reset_tx(void *arg)
{
int rc;
- assert(ble_hs_startup_state == BLE_HS_STARTUP_STATE_RESET);
+ BLE_HS_DBG_ASSERT(ble_hs_startup_state ==
+ BLE_HS_STARTUP_STATE_RESET);
ble_hci_sched_set_ack_cb(ble_hs_startup_gen_ack, NULL);
rc = host_hci_cmd_reset();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/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 96aca5c..c7a29af 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -19,7 +19,6 @@
#include <string.h>
#include <errno.h>
-#include <assert.h>
#include "os/os.h"
#include "nimble/ble.h"
#include "nimble/hci_common.h"
@@ -80,7 +79,7 @@ ble_l2cap_chan_free(struct ble_l2cap_chan *chan)
}
rc = os_memblock_put(&ble_l2cap_chan_pool, chan);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
STATS_INC(ble_l2cap_stats, chan_delete);
}
@@ -105,7 +104,7 @@ ble_l2cap_chan_mtu(struct ble_l2cap_chan *chan)
mtu = min(chan->blc_my_mtu, chan->blc_peer_mtu);
}
- assert(mtu >= chan->blc_default_mtu);
+ BLE_HS_DBG_ASSERT(mtu >= chan->blc_default_mtu);
return mtu;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 6f6438a..9db54ea 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -47,12 +47,12 @@ struct ble_l2cap_sig_hdr {
uint8_t op;
uint8_t identifier;
uint16_t length;
-};
+} __attribute__((packed));
#define BLE_L2CAP_SIG_REJECT_MIN_SZ 2
struct ble_l2cap_sig_reject {
uint16_t reason;
-};
+} __attribute__((packed));
#define BLE_L2CAP_SIG_UPDATE_REQ_SZ 8
struct ble_l2cap_sig_update_req {
@@ -60,12 +60,12 @@ struct ble_l2cap_sig_update_req {
uint16_t itvl_max;
uint16_t slave_latency;
uint16_t timeout_multiplier;
-};
+} __attribute__((packed));
#define BLE_L2CAP_SIG_UPDATE_RSP_SZ 2
struct ble_l2cap_sig_update_rsp {
uint16_t result;
-};
+} __attribute__((packed));
#define BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT 0x0000
#define BLE_L2CAP_SIG_UPDATE_RSP_RESULT_REJECT 0x0001
@@ -117,30 +117,26 @@ int ble_l2cap_parse_hdr(struct os_mbuf *om, int off,
struct os_mbuf *ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid,
uint16_t len);
-int ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
- struct ble_l2cap_sig_hdr *hdr);
-int ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
- struct ble_l2cap_sig_hdr *hdr);
-int ble_l2cap_sig_reject_write(void *payload, uint16_t len,
- struct ble_l2cap_sig_hdr *hdr,
- struct ble_l2cap_sig_reject *cmd);
+int ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
+ struct os_mbuf **out_om, void **out_payload_buf);
+void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
+ struct ble_l2cap_sig_hdr *hdr);
+void ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
+ struct ble_l2cap_sig_hdr *hdr);
int ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason);
-int ble_l2cap_sig_update_req_parse(void *payload, int len,
- struct ble_l2cap_sig_update_req *req);
-int ble_l2cap_sig_update_req_write(void *payload, int len,
- struct ble_l2cap_sig_hdr *hdr,
- struct ble_l2cap_sig_update_req *req);
+void ble_l2cap_sig_update_req_parse(void *payload, int len,
+ struct ble_l2cap_sig_update_req *req);
+void ble_l2cap_sig_update_req_write(void *payload, int len,
+ struct ble_l2cap_sig_update_req *src);
int ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
struct ble_l2cap_sig_update_req *req);
-int ble_l2cap_sig_update_rsp_parse(void *payload, int len,
- struct ble_l2cap_sig_update_rsp *cmd);
-int ble_l2cap_sig_update_rsp_write(void *payload, int len,
- struct ble_l2cap_sig_hdr *hdr,
- struct ble_l2cap_sig_update_rsp *cmd);
+void ble_l2cap_sig_update_rsp_parse(void *payload, int len,
+ struct ble_l2cap_sig_update_rsp *cmd);
+void ble_l2cap_sig_update_rsp_write(void *payload, int len,
+ struct ble_l2cap_sig_update_rsp *src);
int ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id,
uint16_t result);
-
struct ble_l2cap_chan *ble_l2cap_chan_alloc(void);
void ble_l2cap_chan_free(struct ble_l2cap_chan *chan);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/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 f0e3098..e4a20b5 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -19,7 +19,6 @@
#include <string.h>
#include <errno.h>
-#include <assert.h>
#include "console/console.h"
#include "nimble/ble.h"
#include "ble_hs_priv.h"
@@ -224,7 +223,7 @@ ble_l2cap_sig_proc_free(struct ble_fsm_proc *proc)
if (proc != NULL) {
rc = os_memblock_put(&ble_l2cap_sig_proc_pool, proc);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
}
@@ -383,7 +382,7 @@ ble_l2cap_sig_rx_noop(uint16_t conn_handle,
static void
ble_l2cap_sig_update_call_cb(struct ble_l2cap_sig_proc *proc, int status)
{
- assert(!ble_hs_conn_locked_by_cur_task());
+ BLE_HS_DBG_ASSERT(!ble_hs_conn_locked_by_cur_task());
if (status != 0) {
STATS_INC(ble_l2cap_stats, update_fail);
@@ -434,8 +433,7 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
return BLE_HS_ENOTSUP;
}
- rc = ble_l2cap_sig_update_req_parse((*om)->om_data, (*om)->om_len, &req);
- assert(rc == 0);
+ ble_l2cap_sig_update_req_parse((*om)->om_data, (*om)->om_len, &req);
params.itvl_min = req.itvl_min;
params.itvl_max = req.itvl_max;
@@ -492,8 +490,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
goto done;
}
- rc = ble_l2cap_sig_update_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
- assert(rc == 0);
+ ble_l2cap_sig_update_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
switch (rsp.result) {
case BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT:
@@ -607,8 +604,7 @@ ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
return rc;
}
- rc = ble_l2cap_sig_hdr_parse((*om)->om_data, (*om)->om_len, &hdr);
- assert(rc == 0);
+ ble_l2cap_sig_hdr_parse((*om)->om_data, (*om)->om_len, &hdr);
/* Strip L2CAP sig header from the front of the mbuf. */
os_mbuf_adj(*om, BLE_L2CAP_SIG_HDR_SZ);
@@ -723,7 +719,7 @@ ble_l2cap_sig_heartbeat(void *unused)
ticks = BLE_L2CAP_SIG_HEARTBEAT_PERIOD * OS_TICKS_PER_SEC / 1000;
rc = os_callout_reset(&ble_l2cap_sig_heartbeat_timer.cf_c, ticks);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index 34fc5cd..f5f6fa1 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -17,67 +17,37 @@
* under the License.
*/
-#include <assert.h>
#include "ble_hs_priv.h"
int
-ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
- struct ble_l2cap_sig_hdr *hdr)
+ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
+ struct os_mbuf **out_om, void **out_payload_buf)
{
- uint8_t *u8ptr;
-
- if (len < BLE_L2CAP_SIG_HDR_SZ) {
- return BLE_HS_EBADDATA;
- }
-
- u8ptr = payload;
- hdr->op = u8ptr[0];
- hdr->identifier = u8ptr[1];
- hdr->length = le16toh(u8ptr + 2);
-
- return 0;
-}
+ struct ble_l2cap_sig_hdr hdr;
+ struct os_mbuf *txom;
+ void *v;
-int
-ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
- struct ble_l2cap_sig_hdr *hdr)
-{
- uint8_t *u8ptr;
+ *out_om = NULL;
+ *out_payload_buf = NULL;
- if (len < BLE_L2CAP_SIG_HDR_SZ) {
- return BLE_HS_EBADDATA;
+ txom = ble_hs_misc_pkthdr();
+ if (txom == NULL) {
+ return BLE_HS_ENOMEM;
}
- u8ptr = payload;
- u8ptr[0] = hdr->op;
- u8ptr[1] = hdr->identifier;
- htole16(u8ptr + 2, hdr->length);
-
- return 0;
-}
-
-int
-ble_l2cap_sig_reject_write(void *payload, uint16_t len,
- struct ble_l2cap_sig_hdr *hdr,
- struct ble_l2cap_sig_reject *cmd)
-{
- uint8_t *u8ptr;
- int rc;
-
- u8ptr = payload;
- rc = ble_l2cap_sig_hdr_write(u8ptr, len, hdr);
- if (rc != 0) {
- return rc;
+ v = os_mbuf_extend(txom, BLE_L2CAP_SIG_HDR_SZ + payload_len);
+ if (v == NULL) {
+ return BLE_HS_ENOMEM;
}
- u8ptr += BLE_L2CAP_SIG_HDR_SZ;
- len -= BLE_L2CAP_SIG_HDR_SZ;
+ hdr.op = op;
+ hdr.identifier = id;
+ hdr.length = TOFROMLE16(payload_len);
- if (len < BLE_L2CAP_SIG_REJECT_MIN_SZ) {
- return BLE_HS_EMSGSIZE;
- }
+ ble_l2cap_sig_hdr_write(v, BLE_L2CAP_SIG_HDR_SZ, &hdr);
- htole16(u8ptr, cmd->reason);
+ *out_om = txom;
+ *out_payload_buf = (uint8_t *)v + BLE_L2CAP_SIG_HDR_SZ;
return 0;
}
@@ -108,209 +78,165 @@ ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
return rc;
}
+static void
+ble_l2cap_sig_hdr_swap(struct ble_l2cap_sig_hdr *dst,
+ struct ble_l2cap_sig_hdr *src)
+{
+ dst->op = src->op;
+ dst->identifier = src->identifier;
+ dst->length = TOFROMLE16(src->length);
+}
+
+void
+ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
+ struct ble_l2cap_sig_hdr *dst)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
+ ble_l2cap_sig_hdr_swap(dst, payload);
+}
+
+void
+ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
+ struct ble_l2cap_sig_hdr *src)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
+ ble_l2cap_sig_hdr_swap(payload, src);
+}
+static void
+ble_l2cap_sig_reject_swap(struct ble_l2cap_sig_reject *dst,
+ struct ble_l2cap_sig_reject *src)
+{
+ dst->reason = TOFROMLE16(src->reason);
+}
+
+static void
+ble_l2cap_sig_reject_write(void *payload, uint16_t len,
+ struct ble_l2cap_sig_reject *src)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_REJECT_MIN_SZ);
+ ble_l2cap_sig_reject_swap(payload, src);
+}
+
int
ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason)
{
/* XXX: Add support for optional data field. */
struct ble_l2cap_sig_reject cmd;
- struct ble_l2cap_sig_hdr hdr;
struct os_mbuf *txom;
- void *v;
+ void *payload_buf;
int rc;
- txom = ble_hs_misc_pkthdr();
- if (txom == NULL) {
- return BLE_HS_ENOMEM;
- }
-
- v = os_mbuf_extend(txom,
- BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_REJECT_MIN_SZ);
- if (v == NULL) {
- return BLE_HS_ENOMEM;
- }
+ rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_REJECT, id,
+ BLE_L2CAP_SIG_REJECT_MIN_SZ, &txom,
+ &payload_buf);
- hdr.op = BLE_L2CAP_SIG_OP_REJECT;
- hdr.identifier = id;
- hdr.length = BLE_L2CAP_SIG_REJECT_MIN_SZ;
cmd.reason = reason;
-
- rc = ble_l2cap_sig_reject_write(
- v, BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_REJECT_MIN_SZ, &hdr, &cmd);
- if (rc != 0) {
- return rc;
- }
+ ble_l2cap_sig_reject_write(payload_buf, BLE_L2CAP_SIG_REJECT_MIN_SZ, &cmd);
STATS_INC(ble_l2cap_stats, sig_rx);
rc = ble_l2cap_sig_tx(conn_handle, txom);
return rc;
}
-int
-ble_l2cap_sig_update_req_parse(void *payload, int len,
- struct ble_l2cap_sig_update_req *req)
+static void
+ble_l2cap_sig_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+ struct ble_l2cap_sig_update_req *src)
{
- uint8_t *u8ptr;
-
- if (len < BLE_L2CAP_SIG_UPDATE_REQ_SZ) {
- return BLE_HS_EBADDATA;
- }
-
- u8ptr = payload;
-
- req->itvl_min = le16toh(u8ptr + 0);
- req->itvl_max = le16toh(u8ptr + 2);
- req->slave_latency = le16toh(u8ptr + 4);
- req->timeout_multiplier = le16toh(u8ptr + 6);
-
- return 0;
+ dst->itvl_min = TOFROMLE16(src->itvl_min);
+ dst->itvl_max = TOFROMLE16(src->itvl_max);
+ dst->slave_latency = TOFROMLE16(src->slave_latency);
+ dst->timeout_multiplier = TOFROMLE16(src->timeout_multiplier);
}
-int
-ble_l2cap_sig_update_req_write(void *payload, int len,
- struct ble_l2cap_sig_hdr *hdr,
- struct ble_l2cap_sig_update_req *req)
+void
+ble_l2cap_sig_update_req_parse(void *payload, int len,
+ struct ble_l2cap_sig_update_req *dst)
{
- uint8_t *u8ptr;
- int rc;
-
- u8ptr = payload;
- rc = ble_l2cap_sig_hdr_write(u8ptr, len, hdr);
- if (rc != 0) {
- return rc;
- }
-
- u8ptr += BLE_L2CAP_SIG_HDR_SZ;
- len -= BLE_L2CAP_SIG_HDR_SZ;
-
- if (len < BLE_L2CAP_SIG_UPDATE_REQ_SZ) {
- return BLE_HS_EINVAL;
- }
-
- htole16(u8ptr + 0, req->itvl_min);
- htole16(u8ptr + 2, req->itvl_max);
- htole16(u8ptr + 4, req->slave_latency);
- htole16(u8ptr + 6, req->timeout_multiplier);
-
- return 0;
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+ ble_l2cap_sig_update_req_swap(dst, payload);
}
-int
-ble_l2cap_sig_update_rsp_parse(void *payload, int len,
- struct ble_l2cap_sig_update_rsp *cmd)
+void
+ble_l2cap_sig_update_req_write(void *payload, int len,
+ struct ble_l2cap_sig_update_req *src)
{
- uint8_t *u8ptr;
-
- u8ptr = payload;
-
- if (len < BLE_L2CAP_SIG_UPDATE_RSP_SZ) {
- return BLE_HS_EMSGSIZE;
- }
-
- cmd->result = le16toh(u8ptr);
-
- return 0;
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+ ble_l2cap_sig_update_req_swap(payload, src);
}
int
-ble_l2cap_sig_update_rsp_write(void *payload, int len,
- struct ble_l2cap_sig_hdr *hdr,
- struct ble_l2cap_sig_update_rsp *cmd)
+ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
+ struct ble_l2cap_sig_update_req *req)
{
- uint8_t *u8ptr;
+ struct os_mbuf *txom;
+ void *payload_buf;
int rc;
- u8ptr = payload;
- rc = ble_l2cap_sig_hdr_write(u8ptr, len, hdr);
+ rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
+ BLE_L2CAP_SIG_UPDATE_REQ_SZ, &txom,
+ &payload_buf);
if (rc != 0) {
return rc;
}
- u8ptr += BLE_L2CAP_SIG_HDR_SZ;
- len -= BLE_L2CAP_SIG_HDR_SZ;
+ ble_l2cap_sig_update_req_write(payload_buf, BLE_L2CAP_SIG_UPDATE_REQ_SZ,
+ req);
- if (len < BLE_L2CAP_SIG_UPDATE_RSP_SZ) {
- return BLE_HS_EMSGSIZE;
+ rc = ble_l2cap_sig_tx(conn_handle, txom);
+ if (rc != 0) {
+ return rc;
}
- htole16(u8ptr, cmd->result);
-
return 0;
}
-int
-ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
- struct ble_l2cap_sig_update_req *req)
+static void
+ble_l2cap_sig_update_rsp_swap(struct ble_l2cap_sig_update_rsp *dst,
+ struct ble_l2cap_sig_update_rsp *src)
{
- struct ble_l2cap_sig_hdr hdr;
- struct os_mbuf *txom;
- void *v;
- int rc;
-
- txom = ble_hs_misc_pkthdr();
- if (txom == NULL) {
- rc = BLE_HS_ENOMEM;
- goto done;
- }
-
- v = os_mbuf_extend(txom,
- BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_REQ_SZ);
- if (v == NULL) {
- rc = BLE_HS_ENOMEM;
- goto done;
- }
-
- hdr.op = BLE_L2CAP_SIG_OP_UPDATE_REQ;
- hdr.identifier = id;
- hdr.length = BLE_L2CAP_SIG_UPDATE_REQ_SZ;
-
- rc = ble_l2cap_sig_update_req_write(
- v, BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_REQ_SZ, &hdr, req);
- assert(rc == 0);
+ dst->result = TOFROMLE16(src->result);
+}
- rc = ble_l2cap_sig_tx(conn_handle, txom);
- txom = NULL;
+void
+ble_l2cap_sig_update_rsp_parse(void *payload, int len,
+ struct ble_l2cap_sig_update_rsp *dst)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+ ble_l2cap_sig_update_rsp_swap(dst, payload);
+}
-done:
- os_mbuf_free_chain(txom);
- return rc;
+void
+ble_l2cap_sig_update_rsp_write(void *payload, int len,
+ struct ble_l2cap_sig_update_rsp *src)
+{
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+ ble_l2cap_sig_update_rsp_swap(payload, src);
}
int
ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id, uint16_t result)
{
struct ble_l2cap_sig_update_rsp rsp;
- struct ble_l2cap_sig_hdr hdr;
struct os_mbuf *txom;
- void *v;
+ void *payload_buf;
int rc;
- txom = ble_hs_misc_pkthdr();
- if (txom == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- v = os_mbuf_extend(txom,
- BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_RSP_SZ);
- if (v == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
+ rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
+ BLE_L2CAP_SIG_UPDATE_RSP_SZ, &txom,
+ &payload_buf);
+ if (rc != 0) {
+ return rc;
}
- hdr.op = BLE_L2CAP_SIG_OP_UPDATE_RSP;
- hdr.identifier = id;
- hdr.length = BLE_L2CAP_SIG_UPDATE_RSP_SZ;
rsp.result = result;
-
- rc = ble_l2cap_sig_update_rsp_write(
- v, BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_RSP_SZ, &hdr, &rsp);
- assert(rc == 0);
+ ble_l2cap_sig_update_rsp_write(payload_buf, BLE_L2CAP_SIG_UPDATE_RSP_SZ,
+ &rsp);
rc = ble_l2cap_sig_tx(conn_handle, txom);
- return rc;
+ if (rc != 0) {
+ return rc;
+ }
-err:
- os_mbuf_free_chain(txom);
- return rc;
+ return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c b/net/nimble/host/src/ble_l2cap_sm.c
index 8c2cf6e..3c8b0f6 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -19,7 +19,6 @@
#include <string.h>
#include <errno.h>
-#include <assert.h>
#include "console/console.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
@@ -216,7 +215,7 @@ ble_l2cap_sm_gen_pair_rand(uint8_t *pair_rand)
#endif
/* XXX: Generate random value rather than zeros. */
- memset(pair_rand, 0, sizeof ble_l2cap_sm_dbg_next_pair_rand);
+ memset(pair_rand, 0, 16);
}
static uint16_t
@@ -253,9 +252,9 @@ ble_l2cap_sm_proc_kick(struct ble_fsm_proc *proc)
ble_l2cap_sm_kick_fn *kick_cb;
int rc;
- assert(proc->op < BLE_L2CAP_SM_PROC_OP_CNT);
+ BLE_HS_DBG_ASSERT(proc->op < BLE_L2CAP_SM_PROC_OP_CNT);
kick_cb = ble_l2cap_sm_kick[proc->op];
- assert(kick_cb != NULL);
+ BLE_HS_DBG_ASSERT(kick_cb != NULL);
rc = kick_cb((struct ble_l2cap_sm_proc *)proc);
return rc;
@@ -306,7 +305,7 @@ ble_l2cap_sm_proc_free(struct ble_fsm_proc *proc)
if (proc != NULL) {
rc = os_memblock_put(&ble_l2cap_sm_proc_pool, proc);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
}
@@ -540,7 +539,6 @@ ble_l2cap_sm_confirm_prepare_args(struct ble_l2cap_sm_proc *proc,
uint8_t *ia, uint8_t *ra)
{
struct ble_hs_conn *conn;
- int rc;
ble_hs_conn_lock();
conn = ble_hs_conn_find(proc->fsm_proc.conn_handle);
@@ -567,15 +565,13 @@ ble_l2cap_sm_confirm_prepare_args(struct ble_l2cap_sm_proc *proc,
memcpy(k, proc->phase_1_2.tk, sizeof proc->phase_1_2.tk);
- rc = ble_l2cap_sm_pair_cmd_write(
+ ble_l2cap_sm_pair_cmd_write(
preq, BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_CMD_SZ, 1,
&proc->phase_1_2.pair_req);
- assert(rc == 0);
- rc = ble_l2cap_sm_pair_cmd_write(
+ ble_l2cap_sm_pair_cmd_write(
pres, BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_CMD_SZ, 0,
&proc->phase_1_2.pair_rsp);
- assert(rc == 0);
return 0;
}
@@ -754,7 +750,7 @@ ble_l2cap_sm_lt_key_req_reply_tx(void *arg)
proc = arg;
- assert(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_LTK_TXED);
+ BLE_HS_DBG_ASSERT(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_LTK_TXED);
cmd.conn_handle = proc->fsm_proc.conn_handle;
memcpy(cmd.long_term_key, proc->hci.key, 16);
@@ -812,7 +808,7 @@ ble_l2cap_sm_start_encrypt_tx(void *arg)
proc = arg;
- assert(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_START_ENCRYPT_TXED);
+ BLE_HS_DBG_ASSERT(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_START_ENCRYPT_TXED);
cmd.connection_handle = proc->fsm_proc.conn_handle;
cmd.encrypted_diversifier = ble_l2cap_sm_gen_ediv();
@@ -858,8 +854,7 @@ ble_l2cap_sm_rx_pair_req(uint16_t conn_handle, uint8_t op, struct os_mbuf **om)
return rc;
}
- rc = ble_l2cap_sm_pair_cmd_parse((*om)->om_data, (*om)->om_len, &req);
- assert(rc == 0);
+ ble_l2cap_sm_pair_cmd_parse((*om)->om_data, (*om)->om_len, &req);
BLE_HS_LOG(DEBUG, "rxed sm pair req; io_cap=0x%02x oob_data_flag=%d "
"authreq=0x%02x max_enc_key_size=%d "
@@ -906,8 +901,7 @@ ble_l2cap_sm_rx_pair_rsp(uint16_t conn_handle, uint8_t op, struct os_mbuf **om)
return rc;
}
- rc = ble_l2cap_sm_pair_cmd_parse((*om)->om_data, (*om)->om_len, &rsp);
- assert(rc == 0);
+ ble_l2cap_sm_pair_cmd_parse((*om)->om_data, (*om)->om_len, &rsp);
BLE_HS_LOG(DEBUG, "rxed sm pair rsp; io_cap=0x%02x oob_data_flag=%d "
"authreq=0x%02x max_enc_key_size=%d "
@@ -945,8 +939,7 @@ ble_l2cap_sm_rx_pair_confirm(uint16_t conn_handle, uint8_t op,
return rc;
}
- rc = ble_l2cap_sm_pair_confirm_parse((*om)->om_data, (*om)->om_len, &cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_confirm_parse((*om)->om_data, (*om)->om_len, &cmd);
BLE_HS_LOG(DEBUG, "rxed sm confirm cmd\n");
@@ -980,8 +973,7 @@ ble_l2cap_sm_rx_pair_random(uint16_t conn_handle, uint8_t op,
return rc;
}
- rc = ble_l2cap_sm_pair_random_parse((*om)->om_data, (*om)->om_len, &cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_random_parse((*om)->om_data, (*om)->om_len, &cmd);
BLE_HS_LOG(DEBUG, "rxed sm random cmd\n");
@@ -1015,8 +1007,7 @@ ble_l2cap_sm_rx_pair_fail(uint16_t conn_handle, uint8_t op,
return rc;
}
- rc = ble_l2cap_sm_pair_fail_parse((*om)->om_data, (*om)->om_len, &cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_fail_parse((*om)->om_data, (*om)->om_len, &cmd);
BLE_HS_LOG(DEBUG, "rxed sm fail cmd; reason=%d\n", cmd.reason);
@@ -1069,7 +1060,7 @@ ble_l2cap_sm_rx_lt_key_req_reply_ack(struct ble_hci_ack *ack, void *arg)
proc = arg;
- assert(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_LTK_TXED);
+ BLE_HS_DBG_ASSERT(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_LTK_TXED);
/* Extract the procedure from the state machine while we mess with it. */
ble_fsm_lock(&ble_l2cap_sm_fsm);
@@ -1114,7 +1105,7 @@ ble_l2cap_sm_rx_start_encrypt_ack(struct ble_hci_ack *ack, void *arg)
proc = arg;
- assert(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_START_ENCRYPT_TXED);
+ BLE_HS_DBG_ASSERT(proc->fsm_proc.op == BLE_L2CAP_SM_PROC_OP_START_ENCRYPT_TXED);
/* Extract the procedure from the state machine while we mess with it. */
ble_fsm_lock(&ble_l2cap_sm_fsm);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_l2cap_sm.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.h b/net/nimble/host/src/ble_l2cap_sm.h
index e7b0d0b..b1328aa 100644
--- a/net/nimble/host/src/ble_l2cap_sm.h
+++ b/net/nimble/host/src/ble_l2cap_sm.h
@@ -94,28 +94,28 @@ int ble_l2cap_sm_locked_by_cur_task(void);
struct ble_l2cap_chan *ble_l2cap_sm_create_chan(void);
-int ble_l2cap_sm_pair_cmd_parse(void *payload, int len,
- struct ble_l2cap_sm_pair_cmd *cmd);
-int ble_l2cap_sm_pair_cmd_write(void *payload, int len, int is_req,
- struct ble_l2cap_sm_pair_cmd *cmd);
+void ble_l2cap_sm_pair_cmd_parse(void *payload, int len,
+ struct ble_l2cap_sm_pair_cmd *cmd);
+void ble_l2cap_sm_pair_cmd_write(void *payload, int len, int is_req,
+ struct ble_l2cap_sm_pair_cmd *cmd);
int ble_l2cap_sm_pair_cmd_tx(uint16_t conn_handle, int is_req,
struct ble_l2cap_sm_pair_cmd *cmd);
-int ble_l2cap_sm_pair_confirm_parse(void *payload, int len,
- struct ble_l2cap_sm_pair_confirm *cmd);
-int ble_l2cap_sm_pair_confirm_write(void *payload, int len,
- struct ble_l2cap_sm_pair_confirm *cmd);
+void ble_l2cap_sm_pair_confirm_parse(void *payload, int len,
+ struct ble_l2cap_sm_pair_confirm *cmd);
+void ble_l2cap_sm_pair_confirm_write(void *payload, int len,
+ struct ble_l2cap_sm_pair_confirm *cmd);
int ble_l2cap_sm_pair_confirm_tx(uint16_t conn_handle,
struct ble_l2cap_sm_pair_confirm *cmd);
-int ble_l2cap_sm_pair_random_parse(void *payload, int len,
- struct ble_l2cap_sm_pair_random *cmd);
-int ble_l2cap_sm_pair_random_write(void *payload, int len,
- struct ble_l2cap_sm_pair_random *cmd);
+void ble_l2cap_sm_pair_random_parse(void *payload, int len,
+ struct ble_l2cap_sm_pair_random *cmd);
+void ble_l2cap_sm_pair_random_write(void *payload, int len,
+ struct ble_l2cap_sm_pair_random *cmd);
int ble_l2cap_sm_pair_random_tx(uint16_t conn_handle,
struct ble_l2cap_sm_pair_random *cmd);
-int ble_l2cap_sm_pair_fail_parse(void *payload, int len,
- struct ble_l2cap_sm_pair_fail *cmd);
-int ble_l2cap_sm_pair_fail_write(void *payload, int len,
- struct ble_l2cap_sm_pair_fail *cmd);
+void ble_l2cap_sm_pair_fail_parse(void *payload, int len,
+ struct ble_l2cap_sm_pair_fail *cmd);
+void ble_l2cap_sm_pair_fail_write(void *payload, int len,
+ struct ble_l2cap_sm_pair_fail *cmd);
int ble_l2cap_sm_pair_fail_tx(uint16_t conn_handle,
struct ble_l2cap_sm_pair_fail *cmd);
@@ -144,17 +144,9 @@ int ble_l2cap_sm_init(void);
#define ble_l2cap_sm_create_chan() NULL
-#define ble_l2cap_sm_pair_cmd_parse(payload, len, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_cmd_write(payload, len, is_req, cmd) BLE_HS_ENOTSUP
#define ble_l2cap_sm_pair_cmd_tx(conn_handle, is_req, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_confirm_parse(payload, len, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_confirm_write(payload, len, cmd) BLE_HS_ENOTSUP
#define ble_l2cap_sm_pair_confirm_tx(conn_handle, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_random_parse(payload, len, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_random_write(payload, len, cmd) BLE_HS_ENOTSUP
#define ble_l2cap_sm_pair_random_tx(conn_handle, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_fail_parse(payload, len, cmd) BLE_HS_ENOTSUP
-#define ble_l2cap_sm_pair_fail_write(payload, len, cmd) BLE_HS_ENOTSUP
#define ble_l2cap_sm_pair_fail_tx(conn_handle, cmd) BLE_HS_ENOTSUP
#define ble_l2cap_sm_alg_s1(k, r1, r2, out) BLE_HS_ENOTSUP
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_l2cap_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm_cmd.c b/net/nimble/host/src/ble_l2cap_sm_cmd.c
index 71b6fd6..a83ce72 100644
--- a/net/nimble/host/src/ble_l2cap_sm_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sm_cmd.c
@@ -19,7 +19,6 @@
#include <string.h>
#include <errno.h>
-#include <assert.h>
#include "console/console.h"
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
@@ -75,40 +74,32 @@ err:
return rc;
}
-int
+void
ble_l2cap_sm_pair_cmd_parse(void *payload, int len,
struct ble_l2cap_sm_pair_cmd *cmd)
{
uint8_t *u8ptr;
- if (len < BLE_L2CAP_SM_PAIR_CMD_SZ) {
- return BLE_HS_EBADDATA;
- }
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SM_PAIR_CMD_SZ);
u8ptr = payload;
-
cmd->io_cap = u8ptr[0];
cmd->oob_data_flag = u8ptr[1];
cmd->authreq = u8ptr[2];
cmd->max_enc_key_size = u8ptr[3];
cmd->init_key_dist = u8ptr[4];
cmd->resp_key_dist = u8ptr[5];
-
- return 0;
}
-int
+void
ble_l2cap_sm_pair_cmd_write(void *payload, int len, int is_req,
struct ble_l2cap_sm_pair_cmd *cmd)
{
uint8_t *u8ptr;
- if (len < BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_CMD_SZ) {
- return BLE_HS_EMSGSIZE;
- }
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_CMD_SZ);
u8ptr = payload;
-
u8ptr[0] = is_req ? BLE_L2CAP_SM_OP_PAIR_REQ : BLE_L2CAP_SM_OP_PAIR_RSP;
u8ptr[1] = cmd->io_cap;
u8ptr[2] = cmd->oob_data_flag;
@@ -116,8 +107,6 @@ ble_l2cap_sm_pair_cmd_write(void *payload, int len, int is_req,
u8ptr[4] = cmd->max_enc_key_size;
u8ptr[5] = cmd->init_key_dist;
u8ptr[6] = cmd->resp_key_dist;
-
- return 0;
}
int
@@ -133,8 +122,7 @@ ble_l2cap_sm_pair_cmd_tx(uint16_t conn_handle, int is_req,
goto done;
}
- rc = ble_l2cap_sm_pair_cmd_write(txom->om_data, txom->om_len, is_req, cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_cmd_write(txom->om_data, txom->om_len, is_req, cmd);
rc = ble_l2cap_sm_tx(conn_handle, txom);
txom = NULL;
@@ -144,35 +132,27 @@ done:
return rc;
}
-int
+void
ble_l2cap_sm_pair_confirm_parse(void *payload, int len,
struct ble_l2cap_sm_pair_confirm *cmd)
{
- if (len < BLE_L2CAP_SM_PAIR_CONFIRM_SZ) {
- return BLE_HS_EBADDATA;
- }
-
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SM_PAIR_CONFIRM_SZ);
memcpy(cmd->value, payload, sizeof cmd->value);
-
- return 0;
}
-int
+void
ble_l2cap_sm_pair_confirm_write(void *payload, int len,
struct ble_l2cap_sm_pair_confirm *cmd)
{
uint8_t *u8ptr;
- if (len < BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_CONFIRM_SZ) {
- return BLE_HS_EMSGSIZE;
- }
+ BLE_HS_DBG_ASSERT(len >=
+ BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_CONFIRM_SZ);
u8ptr = payload;
u8ptr[0] = BLE_L2CAP_SM_OP_PAIR_CONFIRM;
memcpy(u8ptr + BLE_L2CAP_SM_HDR_SZ, cmd->value, sizeof cmd->value);
-
- return 0;
}
int
@@ -188,8 +168,7 @@ ble_l2cap_sm_pair_confirm_tx(uint16_t conn_handle,
goto done;
}
- rc = ble_l2cap_sm_pair_confirm_write(txom->om_data, txom->om_len, cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_confirm_write(txom->om_data, txom->om_len, cmd);
rc = ble_l2cap_sm_tx(conn_handle, txom);
txom = NULL;
@@ -199,35 +178,27 @@ done:
return rc;
}
-int
+void
ble_l2cap_sm_pair_random_parse(void *payload, int len,
struct ble_l2cap_sm_pair_random *cmd)
{
- if (len < BLE_L2CAP_SM_PAIR_RANDOM_SZ) {
- return BLE_HS_EBADDATA;
- }
-
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SM_PAIR_RANDOM_SZ);
memcpy(cmd->value, payload, sizeof cmd->value);
-
- return 0;
}
-int
+void
ble_l2cap_sm_pair_random_write(void *payload, int len,
struct ble_l2cap_sm_pair_random *cmd)
{
uint8_t *u8ptr;
- if (len < BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_RANDOM_SZ) {
- return BLE_HS_EMSGSIZE;
- }
+ BLE_HS_DBG_ASSERT(len >=
+ BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_RANDOM_SZ);
u8ptr = payload;
u8ptr[0] = BLE_L2CAP_SM_OP_PAIR_RANDOM;
memcpy(u8ptr + BLE_L2CAP_SM_HDR_SZ, cmd->value, sizeof cmd->value);
-
- return 0;
}
int
@@ -243,8 +214,7 @@ ble_l2cap_sm_pair_random_tx(uint16_t conn_handle,
goto done;
}
- rc = ble_l2cap_sm_pair_random_write(txom->om_data, txom->om_len, cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_random_write(txom->om_data, txom->om_len, cmd);
rc = ble_l2cap_sm_tx(conn_handle, txom);
txom = NULL;
@@ -254,39 +224,30 @@ done:
return rc;
}
-int
+void
ble_l2cap_sm_pair_fail_parse(void *payload, int len,
struct ble_l2cap_sm_pair_fail *cmd)
{
uint8_t *u8ptr;
- if (len < BLE_L2CAP_SM_PAIR_FAIL_SZ) {
- return BLE_HS_EBADDATA;
- }
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SM_PAIR_FAIL_SZ);
u8ptr = payload;
-
cmd->reason = u8ptr[0];
-
- return 0;
}
-int
+void
ble_l2cap_sm_pair_fail_write(void *payload, int len,
struct ble_l2cap_sm_pair_fail *cmd)
{
uint8_t *u8ptr;
- if (len < BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_FAIL_SZ) {
- return BLE_HS_EMSGSIZE;
- }
+ BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SM_HDR_SZ + BLE_L2CAP_SM_PAIR_FAIL_SZ);
u8ptr = payload;
u8ptr[0] = BLE_L2CAP_SM_OP_PAIR_FAIL;
u8ptr[1] = cmd->reason;
-
- return 0;
}
int
@@ -302,8 +263,7 @@ ble_l2cap_sm_pair_fail_tx(uint16_t conn_handle,
goto done;
}
- rc = ble_l2cap_sm_pair_fail_write(txom->om_data, txom->om_len, cmd);
- assert(rc == 0);
+ ble_l2cap_sm_pair_fail_write(txom->om_data, txom->om_len, cmd);
rc = ble_l2cap_sm_tx(conn_handle, txom);
txom = NULL;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/ble_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_uuid.c b/net/nimble/host/src/ble_uuid.c
index ead34da..ec01528 100644
--- a/net/nimble/host/src/ble_uuid.c
+++ b/net/nimble/host/src/ble_uuid.c
@@ -17,7 +17,6 @@
* under the License.
*/
-#include <assert.h>
#include <inttypes.h>
#include <string.h>
#include <errno.h>
@@ -122,7 +121,7 @@ ble_uuid_extract(struct os_mbuf *om, int off, void *uuid128)
switch (remlen) {
case 2:
rc = os_mbuf_copydata(om, off, 2, &uuid16);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
uuid16 = le16toh(&uuid16);
rc = ble_uuid_16_to_128(uuid16, uuid128);
@@ -133,7 +132,7 @@ ble_uuid_extract(struct os_mbuf *om, int off, void *uuid128)
case 16:
rc = os_mbuf_copydata(om, off, 16, uuid128);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
return 0;
default:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index 8bec9ad..a6794fb 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -355,6 +355,10 @@ host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
void
host_hci_dbg_event_disp(uint8_t *evbuf)
{
+#if LOG_LEVEL > LOG_LEVEL_DEBUG
+ return;
+#endif
+
uint8_t *evdata;
uint8_t evcode;
uint8_t len;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/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 47ef3ea..a329684 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -17,7 +17,6 @@
* under the License.
*/
#include <stdint.h>
-#include <assert.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
@@ -141,7 +140,7 @@ host_hci_timer_set(void)
rc = os_callout_reset(&host_hci_timer.cf_c,
HOST_HCI_TIMEOUT * OS_TICKS_PER_SEC / 1000);
- assert(rc == 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
}
static void
@@ -155,7 +154,7 @@ host_hci_timer_exp(void *arg)
{
struct ble_hci_ack ack;
- assert(host_hci_outstanding_opcode != 0);
+ BLE_HS_DBG_ASSERT(host_hci_outstanding_opcode != 0);
ack.bha_opcode = host_hci_outstanding_opcode;
ack.bha_status = BLE_HS_ETIMEOUT;
@@ -629,11 +628,11 @@ host_hci_os_event_proc(struct os_event *ev)
/* Free the command buffer */
err = os_memblock_put(&g_hci_cmd_pool, ev->ev_arg);
- assert(err == OS_OK);
+ BLE_HS_DBG_ASSERT_EVAL(err == OS_OK);
/* Free the event */
err = os_memblock_put(&g_hci_os_event_pool, ev);
- assert(err == OS_OK);
+ BLE_HS_DBG_ASSERT_EVAL(err == OS_OK);
return rc;
}
@@ -645,13 +644,13 @@ ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
os_error_t err;
struct os_event *ev;
- assert(hci_ev != NULL);
+ BLE_HS_DBG_ASSERT(hci_ev != NULL);
/* Get an event structure off the queue */
ev = (struct os_event *)os_memblock_get(&g_hci_os_event_pool);
if (!ev) {
err = os_memblock_put(&g_hci_cmd_pool, hci_ev);
- assert(err == OS_OK);
+ BLE_HS_DBG_ASSERT_EVAL(err == OS_OK);
return -1;
}
@@ -735,8 +734,8 @@ host_hci_data_rx(struct os_mbuf *om)
os_mbuf_free_chain(om);
if (rc == 0) {
- assert(rx_cb != NULL);
- assert(rx_buf != NULL);
+ BLE_HS_DBG_ASSERT(rx_cb != NULL);
+ BLE_HS_DBG_ASSERT(rx_buf != NULL);
rc = rx_cb(handle, &rx_buf);
os_mbuf_free_chain(rx_buf);
} else if (rc == BLE_HS_EAGAIN) {
@@ -750,9 +749,9 @@ host_hci_data_rx(struct os_mbuf *om)
uint16_t
host_hci_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc)
{
- assert(handle <= 0x0fff);
- assert(pb <= 0x03);
- assert(bc <= 0x03);
+ BLE_HS_DBG_ASSERT(handle <= 0x0fff);
+ BLE_HS_DBG_ASSERT(pb <= 0x03);
+ BLE_HS_DBG_ASSERT(bc <= 0x03);
return (handle << 0) |
(pb << 12) |
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index 52c26b5..a4a4b81 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -51,7 +51,7 @@ host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata)
uint16_t opcode;
/* Don't allow multiple commands "in flight." */
- assert(host_hci_outstanding_opcode == 0);
+ BLE_HS_DBG_ASSERT(host_hci_outstanding_opcode == 0);
rc = -1;
cmd = os_memblock_get(&g_hci_cmd_pool);
@@ -120,7 +120,7 @@ host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv)
uint16_t itvl;
uint8_t cmd[BLE_HCI_SET_ADV_PARAM_LEN];
- assert(adv != NULL);
+ BLE_HS_DBG_ASSERT(adv != NULL);
/* Make sure parameters are valid */
rc = -1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2fef21d6/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 3d393dc..54ddb27 100644
--- a/net/nimble/host/src/test/ble_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_att_clt_test.c
@@ -42,7 +42,6 @@ ble_att_clt_test_misc_verify_tx_write(uint16_t handle_id, void *value,
{
struct ble_att_write_req req;
struct os_mbuf *om;
- int rc;
TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
@@ -51,11 +50,10 @@ ble_att_clt_test_misc_verify_tx_write(uint16_t handle_id, void *value,
TEST_ASSERT_FATAL(om != NULL);
if (is_req) {
- rc = ble_att_write_req_parse(om->om_data, om->om_len, &req);
+ ble_att_write_req_parse(om->om_data, om->om_len, &req);
} else {
- rc = ble_att_write_cmd_parse(om->om_data, om->om_len, &req);
+ ble_att_write_cmd_parse(om->om_data, om->om_len, &req);
}
- TEST_ASSERT_FATAL(rc == 0);
TEST_ASSERT(req.bawq_handle == handle_id);
TEST_ASSERT(om->om_len == BLE_ATT_WRITE_REQ_BASE_SZ + value_len);
@@ -128,8 +126,7 @@ TEST_CASE(ble_att_clt_test_rx_find_info)
/* Receive response with attribute mapping. */
off = 0;
rsp.bafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT;
- rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
- TEST_ASSERT(rc == 0);
+ ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
off += BLE_ATT_FIND_INFO_RSP_BASE_SZ;
htole16(buf + off, 1);
@@ -144,8 +141,7 @@ TEST_CASE(ble_att_clt_test_rx_find_info)
/* Receive response with attribute mapping. */
off = 0;
rsp.bafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
- rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
- TEST_ASSERT(rc == 0);
+ ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
off += BLE_ATT_FIND_INFO_RSP_BASE_SZ;
htole16(buf + off, 2);
@@ -160,8 +156,7 @@ TEST_CASE(ble_att_clt_test_rx_find_info)
/* Receive response with attribute mappings. */
off = 0;
rsp.bafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
- rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
- TEST_ASSERT(rc == 0);
+ ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
off += BLE_ATT_FIND_INFO_RSP_BASE_SZ;
htole16(buf + off, 3);
@@ -233,8 +228,7 @@ ble_att_clt_test_misc_prep_good(uint16_t handle, uint16_t offset,
TEST_ASSERT_FATAL(om != NULL);
TEST_ASSERT(om->om_len == BLE_ATT_PREP_WRITE_CMD_BASE_SZ + attr_data_len);
- rc = ble_att_prep_write_req_parse(om->om_data, om->om_len, &req);
- TEST_ASSERT(rc == 0);
+ 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++) {
@@ -266,8 +260,7 @@ ble_att_clt_test_misc_exec_good(uint8_t flags)
TEST_ASSERT_FATAL(om != NULL);
TEST_ASSERT(om->om_len == BLE_ATT_EXEC_WRITE_REQ_SZ);
- rc = ble_att_exec_write_req_parse(om->om_data, om->om_len, &req);
- TEST_ASSERT(rc == 0);
+ ble_att_exec_write_req_parse(om->om_data, om->om_len, &req);
TEST_ASSERT(req.baeq_flags == flags);
}
@@ -407,8 +400,7 @@ TEST_CASE(ble_att_clt_test_tx_read_mult)
TEST_ASSERT_FATAL(om != NULL);
TEST_ASSERT(om->om_len == BLE_ATT_READ_MULT_REQ_BASE_SZ + 4);
- rc = ble_att_read_mult_req_parse(om->om_data, om->om_len);
- TEST_ASSERT(rc == 0);
+ 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);
@@ -427,8 +419,7 @@ TEST_CASE(ble_att_clt_test_rx_read_mult)
ble_att_clt_test_misc_init(&conn, &chan);
/*** Basic success. */
- rc = ble_att_read_mult_rsp_write(buf, sizeof buf);
- TEST_ASSERT(rc == 0);
+ 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(
@@ -493,8 +484,7 @@ TEST_CASE(ble_att_clt_test_rx_prep_write)
/*** Basic success. */
rsp.bapc_handle = 0x1234;
rsp.bapc_offset = 0;
- rc = ble_att_prep_write_rsp_write(buf, sizeof buf, &rsp);
- TEST_ASSERT(rc == 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, chan, buf, BLE_ATT_PREP_WRITE_CMD_BASE_SZ + 5);
@@ -503,8 +493,7 @@ TEST_CASE(ble_att_clt_test_rx_prep_write)
/*** 0-length write. */
rsp.bapc_handle = 0x1234;
rsp.bapc_offset = 0;
- rc = ble_att_prep_write_rsp_write(buf, sizeof buf, &rsp);
- TEST_ASSERT(rc == 0);
+ ble_att_prep_write_rsp_write(buf, sizeof buf, &rsp);
rc = ble_hs_test_util_l2cap_rx_payload_flat(
conn, chan, buf, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
TEST_ASSERT(rc == 0);