ble_mesh: Use 24-bit functions [Zephyr]

Use 24-bit functions for byteorder and net_buf in order to make the
byteorder used more readable.
This commit is contained in:
lly 2020-03-26 11:16:26 +08:00
parent e3472c1c99
commit 0a41241e10
4 changed files with 12 additions and 33 deletions

View File

@ -2829,9 +2829,7 @@ static void lpn_timeout_get(struct bt_mesh_model *model,
timeout = k_delayed_work_remaining_get(&frnd->timer) / 100;
send_rsp:
net_buf_simple_add_u8(&msg, timeout);
net_buf_simple_add_u8(&msg, timeout >> 8);
net_buf_simple_add_u8(&msg, timeout >> 16);
net_buf_simple_add_le24(&msg, timeout);
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("%s, Unable to send Config LPN PollTimeout Status", __func__);

View File

@ -504,9 +504,8 @@ static int encrypt_friend_pdu(struct bt_mesh_friend *frnd, struct net_buf *buf,
}
seq = bt_mesh_next_seq();
buf->data[2] = seq >> 16;
buf->data[3] = seq >> 8;
buf->data[4] = seq;
sys_put_be24(seq, &buf->data[2]);
iv_index = BLE_MESH_NET_IVI_TX;
FRIEND_ADV(buf)->app_idx = BLE_MESH_KEY_UNUSED;
} else {
@ -972,9 +971,7 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
return -EINVAL;
}
poll_to = (((u32_t)msg->poll_to[0] << 16) |
((u32_t)msg->poll_to[1] << 8) |
((u32_t)msg->poll_to[2]));
poll_to = sys_get_be24(msg->poll_to);
if (poll_to <= 0x000009 || poll_to >= 0x34bc00) {
BT_WARN("%s, Prohibited PollTimeout (0x%06x)", __func__, poll_to);
@ -1381,9 +1378,7 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd,
info.ctl = rx->ctl;
info.seq[0] = (rx->seq >> 16);
info.seq[1] = (rx->seq >> 8);
info.seq[2] = rx->seq;
sys_put_be24(rx->seq, info.seq);
info.iv_index = BLE_MESH_NET_IVI_RX(rx);
@ -1420,9 +1415,7 @@ static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd,
info.ttl = tx->ctx->send_ttl;
info.ctl = (tx->ctx->app_idx == BLE_MESH_KEY_UNUSED);
info.seq[0] = (bt_mesh.seq >> 16);
info.seq[1] = (bt_mesh.seq >> 8);
info.seq[2] = bt_mesh.seq;
sys_put_be24(bt_mesh.seq, info.seq);
info.iv_index = BLE_MESH_NET_IVI_TX;

View File

@ -43,8 +43,7 @@
#define NID(pdu) ((pdu)[0] & 0x7f)
#define CTL(pdu) ((pdu)[1] >> 7)
#define TTL(pdu) ((pdu)[1] & 0x7f)
#define SEQ(pdu) (((u32_t)(pdu)[2] << 16) | \
((u32_t)(pdu)[3] << 8) | (u32_t)(pdu)[4]);
#define SEQ(pdu) (sys_get_be24(&(pdu)[2]))
#define SRC(pdu) (sys_get_be16(&(pdu)[5]))
#define DST(pdu) (sys_get_be16(&(pdu)[7]))
@ -791,9 +790,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
/* Update with a new sequence number */
seq = bt_mesh_next_seq();
buf->data[2] = seq >> 16;
buf->data[3] = seq >> 8;
buf->data[4] = seq;
sys_put_be24(seq, &buf->data[2]);
/* Get destination, in case it's a proxy client */
dst = DST(buf->data);
@ -836,10 +833,8 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
bool proxy)
{
const bool ctl = (tx->ctx->app_idx == BLE_MESH_KEY_UNUSED);
u32_t seq_val = 0U;
u8_t nid = 0U;
const u8_t *enc = NULL, *priv = NULL;
u8_t *seq = NULL;
u8_t nid = 0U;
int err = 0;
if (ctl && net_buf_simple_tailroom(buf) < 8) {
@ -856,11 +851,7 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
net_buf_simple_push_be16(buf, tx->ctx->addr);
net_buf_simple_push_be16(buf, tx->src);
seq = net_buf_simple_push(buf, 3);
seq_val = bt_mesh_next_seq();
seq[0] = seq_val >> 16;
seq[1] = seq_val >> 8;
seq[2] = seq_val;
net_buf_simple_push_be24(buf, bt_mesh_next_seq());
if (ctl) {
net_buf_simple_push_u8(buf, tx->ctx->send_ttl | 0x80);

View File

@ -268,8 +268,7 @@ static int seq_set(const char *name)
return 0;
}
bt_mesh.seq = ((u32_t)seq.val[0] | ((u32_t)seq.val[1] << 8) |
((u32_t)seq.val[2] << 16));
bt_mesh.seq = sys_get_le24(seq.val);
#if CONFIG_BLE_MESH_SEQ_STORE_RATE > 0
/* Make sure we have a large enough sequence number. We
@ -1526,9 +1525,7 @@ static void store_pending_seq(void)
{
struct seq_val seq = {0};
seq.val[0] = bt_mesh.seq;
seq.val[1] = bt_mesh.seq >> 8;
seq.val[2] = bt_mesh.seq >> 16;
sys_put_le24(bt_mesh.seq, seq.val);
bt_mesh_save_core_settings("mesh/seq", (const u8_t *)&seq, sizeof(seq));
}