Bluetooth: Mesh: Add bt_mesh_net_flags() helper function
This reduces code in various places needed to construct a flags value for a given subnet. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
b8e2c9a40f
commit
ae714e4028
3 changed files with 23 additions and 18 deletions
|
@ -87,23 +87,17 @@ static void beacon_complete(struct net_buf *buf, int err)
|
|||
void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t flags = bt_mesh_net_flags(sub);
|
||||
struct bt_mesh_subnet_keys *keys;
|
||||
u8_t flags;
|
||||
|
||||
net_buf_simple_add_u8(buf, BEACON_TYPE_SECURE);
|
||||
|
||||
if (sub->kr_flag) {
|
||||
flags = BT_MESH_NET_FLAG_KR;
|
||||
keys = &sub->keys[1];
|
||||
} else {
|
||||
flags = 0x00;
|
||||
keys = &sub->keys[0];
|
||||
}
|
||||
|
||||
if (bt_mesh.iv_update) {
|
||||
flags |= BT_MESH_NET_FLAG_IVU;
|
||||
}
|
||||
|
||||
net_buf_simple_add_u8(buf, flags);
|
||||
|
||||
/* Network ID */
|
||||
|
|
|
@ -395,25 +395,34 @@ static inline int friend_cred_get(u16_t net_idx, u16_t addr, u8_t idx,
|
|||
}
|
||||
#endif /* FRIEND || LOW_POWER */
|
||||
|
||||
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub)
|
||||
u8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
struct bt_mesh_subnet_keys *keys;
|
||||
u8_t flags;
|
||||
u8_t flags = 0x00;
|
||||
|
||||
if (sub->kr_flag) {
|
||||
BT_DBG("NetIndex %u Using new key", sub->net_idx);
|
||||
flags = BT_MESH_NET_FLAG_KR;
|
||||
keys = &sub->keys[1];
|
||||
} else {
|
||||
BT_DBG("NetIndex %u Using current key", sub->net_idx);
|
||||
flags = 0x00;
|
||||
keys = &sub->keys[0];
|
||||
if (sub && sub->kr_flag) {
|
||||
flags |= BT_MESH_NET_FLAG_KR;
|
||||
}
|
||||
|
||||
if (bt_mesh.iv_update) {
|
||||
flags |= BT_MESH_NET_FLAG_IVU;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub)
|
||||
{
|
||||
u8_t flags = bt_mesh_net_flags(sub);
|
||||
struct bt_mesh_subnet_keys *keys;
|
||||
|
||||
if (sub->kr_flag) {
|
||||
BT_DBG("NetIndex %u Using new key", sub->net_idx);
|
||||
keys = &sub->keys[1];
|
||||
} else {
|
||||
BT_DBG("NetIndex %u Using current key", sub->net_idx);
|
||||
keys = &sub->keys[0];
|
||||
}
|
||||
|
||||
BT_DBG("flags 0x%02x, IVI 0x%08x", flags, bt_mesh.iv_index);
|
||||
|
||||
return bt_mesh_beacon_auth(keys->beacon, flags, keys->net_id,
|
||||
|
|
|
@ -231,6 +231,8 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
|
|||
int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
|
||||
u32_t iv_index);
|
||||
|
||||
u8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub);
|
||||
|
||||
int bt_mesh_friend_cred_set(struct bt_mesh_friend_cred *cred, u8_t idx,
|
||||
const u8_t net_key[16]);
|
||||
void bt_mesh_friend_cred_refresh(u16_t net_idx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue