2019-01-07 07:16:47 +00:00
|
|
|
/* Bluetooth Mesh */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
* Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NET_H_
|
|
|
|
#define _NET_H_
|
|
|
|
|
|
|
|
#include "mesh_access.h"
|
|
|
|
|
2020-04-10 03:31:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-01-07 07:16:47 +00:00
|
|
|
#define BLE_MESH_NET_FLAG_KR BIT(0)
|
|
|
|
#define BLE_MESH_NET_FLAG_IVU BIT(1)
|
|
|
|
|
|
|
|
#define BLE_MESH_KR_NORMAL 0x00
|
|
|
|
#define BLE_MESH_KR_PHASE_1 0x01
|
|
|
|
#define BLE_MESH_KR_PHASE_2 0x02
|
|
|
|
#define BLE_MESH_KR_PHASE_3 0x03
|
|
|
|
|
|
|
|
#define BLE_MESH_IV_UPDATE(flags) ((flags >> 1) & 0x01)
|
|
|
|
#define BLE_MESH_KEY_REFRESH(flags) (flags & 0x01)
|
|
|
|
|
|
|
|
/* How many hours in between updating IVU duration */
|
|
|
|
#define BLE_MESH_IVU_MIN_HOURS 96
|
2020-12-07 09:03:11 +00:00
|
|
|
#define BLE_MESH_IVU_HOURS (BLE_MESH_IVU_MIN_HOURS / CONFIG_BLE_MESH_IVU_DIVIDER)
|
2019-01-07 07:16:47 +00:00
|
|
|
#define BLE_MESH_IVU_TIMEOUT K_HOURS(BLE_MESH_IVU_HOURS)
|
|
|
|
|
|
|
|
struct bt_mesh_app_key {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t net_idx;
|
|
|
|
uint16_t app_idx;
|
|
|
|
bool updated;
|
2019-01-07 07:16:47 +00:00
|
|
|
struct bt_mesh_app_keys {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t id;
|
|
|
|
uint8_t val[16];
|
2019-01-07 07:16:47 +00:00
|
|
|
} keys[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_mesh_subnet {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t beacon_sent; /* Timestamp of last sent beacon */
|
|
|
|
uint8_t beacons_last; /* Number of beacons during last observation window. */
|
|
|
|
uint8_t beacons_cur; /* Number of beacons observed during currently ongoing window. */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t beacon_cache[21]; /* Cached last authenticated beacon */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t net_idx; /* NetKeyIndex */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
bool kr_flag; /* Key Refresh Flag */
|
|
|
|
uint8_t kr_phase; /* Key Refresh Phase */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t node_id; /* Node Identity State */
|
|
|
|
uint32_t node_id_start; /* Node Identity started timestamp */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t auth[8]; /* Beacon Authentication Value */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
struct bt_mesh_subnet_keys {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t net[16]; /* NetKey */
|
|
|
|
uint8_t nid; /* NID */
|
|
|
|
uint8_t enc[16]; /* EncKey */
|
|
|
|
uint8_t net_id[8]; /* Network ID */
|
2019-09-27 09:07:05 +00:00
|
|
|
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t identity[16]; /* IdentityKey */
|
2019-01-07 07:16:47 +00:00
|
|
|
#endif
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t privacy[16]; /* PrivacyKey */
|
|
|
|
uint8_t beacon[16]; /* BeaconKey */
|
2019-01-07 07:16:47 +00:00
|
|
|
} keys[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_mesh_rpl {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t src;
|
|
|
|
bool old_iv;
|
2019-01-07 07:16:47 +00:00
|
|
|
#if defined(CONFIG_BLE_MESH_SETTINGS)
|
2020-12-07 09:03:11 +00:00
|
|
|
bool store;
|
2019-01-07 07:16:47 +00:00
|
|
|
#endif
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t seq;
|
2019-01-07 07:16:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_FRIEND)
|
2020-12-07 09:03:11 +00:00
|
|
|
#define FRIEND_SEG_RX CONFIG_BLE_MESH_FRIEND_SEG_RX
|
|
|
|
#define FRIEND_SUB_LIST_SIZE CONFIG_BLE_MESH_FRIEND_SUB_LIST_SIZE
|
2019-01-07 07:16:47 +00:00
|
|
|
#else
|
2020-12-07 09:03:11 +00:00
|
|
|
#define FRIEND_SEG_RX 0
|
|
|
|
#define FRIEND_SUB_LIST_SIZE 0
|
2019-01-07 07:16:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct bt_mesh_friend {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t lpn;
|
|
|
|
uint8_t recv_delay;
|
|
|
|
uint8_t fsn:1,
|
|
|
|
send_last:1,
|
|
|
|
pending_req:1,
|
|
|
|
sec_update:1,
|
|
|
|
pending_buf:1,
|
|
|
|
valid:1,
|
|
|
|
established:1;
|
|
|
|
int32_t poll_to;
|
|
|
|
uint8_t num_elem;
|
|
|
|
uint16_t lpn_counter;
|
|
|
|
uint16_t counter;
|
|
|
|
|
|
|
|
uint16_t net_idx;
|
|
|
|
|
|
|
|
uint16_t sub_list[FRIEND_SUB_LIST_SIZE];
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
struct k_delayed_work timer;
|
|
|
|
|
|
|
|
struct bt_mesh_friend_seg {
|
|
|
|
sys_slist_t queue;
|
2019-09-02 07:30:40 +00:00
|
|
|
|
|
|
|
/* The target number of segments, i.e. not necessarily
|
|
|
|
* the current number of segments, in the queue. This is
|
|
|
|
* used for Friend Queue free space calculations.
|
|
|
|
*/
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t seg_count;
|
2019-01-07 07:16:47 +00:00
|
|
|
} seg[FRIEND_SEG_RX];
|
|
|
|
|
|
|
|
struct net_buf *last;
|
|
|
|
|
|
|
|
sys_slist_t queue;
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t queue_size;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Friend Clear Procedure */
|
|
|
|
struct {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t start; /* Clear Procedure start */
|
|
|
|
uint16_t frnd; /* Previous Friend's address */
|
|
|
|
uint16_t repeat_sec; /* Repeat timeout in seconds */
|
2019-01-07 07:16:47 +00:00
|
|
|
struct k_delayed_work timer; /* Repeat timer */
|
|
|
|
} clear;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_LOW_POWER)
|
|
|
|
#define LPN_GROUPS CONFIG_BLE_MESH_LPN_GROUPS
|
|
|
|
#else
|
|
|
|
#define LPN_GROUPS 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Low Power Node state */
|
|
|
|
struct bt_mesh_lpn {
|
|
|
|
enum __packed {
|
|
|
|
BLE_MESH_LPN_DISABLED, /* LPN feature is disabled */
|
|
|
|
BLE_MESH_LPN_CLEAR, /* Clear in progress */
|
|
|
|
BLE_MESH_LPN_TIMER, /* Waiting for auto timer expiry */
|
|
|
|
BLE_MESH_LPN_ENABLED, /* LPN enabled, but no Friend */
|
|
|
|
BLE_MESH_LPN_REQ_WAIT, /* Wait before scanning for offers */
|
|
|
|
BLE_MESH_LPN_WAIT_OFFER, /* Friend Req sent */
|
|
|
|
BLE_MESH_LPN_ESTABLISHED, /* Friendship established */
|
|
|
|
BLE_MESH_LPN_RECV_DELAY, /* Poll sent, waiting ReceiveDelay */
|
|
|
|
BLE_MESH_LPN_WAIT_UPDATE, /* Waiting for Update or message */
|
|
|
|
BLE_MESH_LPN_OFFER_RECV, /* Friend offer received */
|
|
|
|
} state;
|
|
|
|
|
|
|
|
/* Transaction Number (used for subscription list) */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t xact_next;
|
|
|
|
uint8_t xact_pending;
|
|
|
|
uint8_t sent_req;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Address of our Friend when we're a LPN. Unassigned if we don't
|
|
|
|
* have a friend yet.
|
|
|
|
*/
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t frnd;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Value from the friend offer */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t recv_win;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t req_attempts; /* Number of Request attempts */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
int32_t poll_timeout;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t groups_changed: 1, /* Friend Subscription List needs updating */
|
|
|
|
pending_poll: 1, /* Poll to be sent after subscription */
|
|
|
|
disable: 1, /* Disable LPN after clearing */
|
|
|
|
fsn: 1, /* Friend Sequence Number */
|
|
|
|
established: 1, /* Friendship established */
|
|
|
|
clear_success: 1; /* Friend Clear Confirm received */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Friend Queue Size */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t queue_size;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* LPNCounter */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t counter;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Previous Friend of this LPN */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t old_friend;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Duration reported for last advertising packet */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t adv_duration;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Next LPN related action timer */
|
|
|
|
struct k_delayed_work timer;
|
|
|
|
|
|
|
|
/* Subscribed groups */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t groups[LPN_GROUPS];
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Bit fields for tracking which groups the Friend knows about */
|
|
|
|
BLE_MESH_ATOMIC_DEFINE(added, LPN_GROUPS);
|
|
|
|
BLE_MESH_ATOMIC_DEFINE(pending, LPN_GROUPS);
|
|
|
|
BLE_MESH_ATOMIC_DEFINE(to_remove, LPN_GROUPS);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* bt_mesh_net.flags */
|
|
|
|
enum {
|
2020-01-19 10:57:13 +00:00
|
|
|
BLE_MESH_NODE, /* Device is a node */
|
|
|
|
BLE_MESH_PROVISIONER, /* Device is a Provisioner */
|
2019-01-07 07:16:47 +00:00
|
|
|
BLE_MESH_VALID, /* We have been provisioned */
|
2020-01-19 10:57:13 +00:00
|
|
|
BLE_MESH_VALID_PROV, /* Provisioner has been enabled */
|
2019-01-07 07:16:47 +00:00
|
|
|
BLE_MESH_SUSPENDED, /* Network is temporarily suspended */
|
|
|
|
BLE_MESH_IVU_IN_PROGRESS, /* IV Update in Progress */
|
|
|
|
BLE_MESH_IVU_INITIATOR, /* IV Update initiated by us */
|
|
|
|
BLE_MESH_IVU_TEST, /* IV Update test mode */
|
|
|
|
BLE_MESH_IVU_PENDING, /* Update blocked by SDU in progress */
|
|
|
|
|
2019-09-02 06:16:33 +00:00
|
|
|
/* pending storage actions, must reside within first 32 flags */
|
2019-01-07 07:16:47 +00:00
|
|
|
BLE_MESH_RPL_PENDING,
|
|
|
|
BLE_MESH_KEYS_PENDING,
|
|
|
|
BLE_MESH_NET_PENDING,
|
|
|
|
BLE_MESH_IV_PENDING,
|
|
|
|
BLE_MESH_SEQ_PENDING,
|
|
|
|
BLE_MESH_HB_PUB_PENDING,
|
|
|
|
BLE_MESH_CFG_PENDING,
|
|
|
|
BLE_MESH_MOD_PENDING,
|
2019-11-04 12:04:52 +00:00
|
|
|
BLE_MESH_VA_PENDING,
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Don't touch - intentionally last */
|
|
|
|
BLE_MESH_FLAG_COUNT,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_mesh_net {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t iv_index; /* Current IV Index */
|
|
|
|
uint32_t seq; /* Next outgoing sequence number (24 bits) */
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
BLE_MESH_ATOMIC_DEFINE(flags, BLE_MESH_FLAG_COUNT);
|
|
|
|
|
|
|
|
/* Local network interface */
|
|
|
|
struct k_work local_work;
|
|
|
|
sys_slist_t local_queue;
|
|
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_FRIEND)
|
|
|
|
/* Friend state, unique for each LPN that we're Friends for */
|
|
|
|
struct bt_mesh_friend frnd[CONFIG_BLE_MESH_FRIEND_LPN_COUNT];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_LOW_POWER)
|
|
|
|
struct bt_mesh_lpn lpn; /* Low Power Node state */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Number of hours in current IV Update state */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t ivu_duration;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Timer to track duration in current IV Update state */
|
|
|
|
struct k_delayed_work ivu_timer;
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t dev_key[16];
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
struct bt_mesh_app_key app_keys[CONFIG_BLE_MESH_APP_KEY_COUNT];
|
|
|
|
|
|
|
|
struct bt_mesh_subnet sub[CONFIG_BLE_MESH_SUBNET_COUNT];
|
|
|
|
|
|
|
|
struct bt_mesh_rpl rpl[CONFIG_BLE_MESH_CRPL];
|
|
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_PROVISIONER)
|
|
|
|
/* Application keys stored by provisioner */
|
|
|
|
struct bt_mesh_app_key *p_app_keys[CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT];
|
|
|
|
/* Next app_idx can be assigned */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t p_app_idx_next;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Network keys stored by provisioner */
|
|
|
|
struct bt_mesh_subnet *p_sub[CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT];
|
|
|
|
/* Next net_idx can be assigned */
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t p_net_idx_next;
|
2019-01-07 07:16:47 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Network interface */
|
|
|
|
enum bt_mesh_net_if {
|
|
|
|
BLE_MESH_NET_IF_ADV,
|
|
|
|
BLE_MESH_NET_IF_LOCAL,
|
|
|
|
BLE_MESH_NET_IF_PROXY,
|
|
|
|
BLE_MESH_NET_IF_PROXY_CFG,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Decoding context for Network/Transport data */
|
|
|
|
struct bt_mesh_net_rx {
|
|
|
|
struct bt_mesh_subnet *sub;
|
|
|
|
struct bt_mesh_msg_ctx ctx;
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t seq; /* Sequence Number */
|
|
|
|
uint8_t old_iv:1, /* iv_index - 1 was used */
|
|
|
|
new_key:1, /* Data was encrypted with updated key */
|
|
|
|
friend_cred:1, /* Data was encrypted with friend cred */
|
|
|
|
ctl:1, /* Network Control */
|
|
|
|
net_if:2, /* Network interface */
|
|
|
|
local_match:1, /* Matched a local element */
|
|
|
|
friend_match:1; /* Matched an LPN we're friends for */
|
|
|
|
uint16_t msg_cache_idx; /* Index of entry in message cache */
|
2019-01-07 07:16:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Encoding context for Network/Transport data */
|
|
|
|
struct bt_mesh_net_tx {
|
|
|
|
struct bt_mesh_subnet *sub;
|
|
|
|
struct bt_mesh_msg_ctx *ctx;
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t src;
|
|
|
|
uint8_t xmit;
|
|
|
|
uint8_t friend_cred:1,
|
|
|
|
aszmic:1,
|
|
|
|
aid: 6;
|
2019-01-07 07:16:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct bt_mesh_net bt_mesh;
|
|
|
|
|
|
|
|
#define BLE_MESH_NET_IVI_TX (bt_mesh.iv_index - \
|
2020-12-07 09:03:11 +00:00
|
|
|
bt_mesh_atomic_test_bit(bt_mesh.flags, \
|
|
|
|
BLE_MESH_IVU_IN_PROGRESS))
|
2019-01-07 07:16:47 +00:00
|
|
|
#define BLE_MESH_NET_IVI_RX(rx) (bt_mesh.iv_index - (rx)->old_iv)
|
|
|
|
|
|
|
|
#define BLE_MESH_NET_HDR_LEN 9
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
void bt_mesh_msg_cache_clear(uint16_t unicast_addr, uint8_t elem_num);
|
2020-01-19 10:57:13 +00:00
|
|
|
|
2019-01-07 07:16:47 +00:00
|
|
|
int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
|
2020-12-07 09:03:11 +00:00
|
|
|
const uint8_t key[16]);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
int bt_mesh_net_create(uint16_t idx, uint8_t flags, const uint8_t key[16],
|
|
|
|
uint32_t iv_index);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, uint8_t new_kr, bool new_key);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub);
|
|
|
|
|
|
|
|
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub);
|
|
|
|
|
|
|
|
void bt_mesh_rpl_reset(void);
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub);
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
struct bt_mesh_subnet *bt_mesh_subnet_get(uint16_t net_idx);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
struct bt_mesh_subnet *bt_mesh_subnet_find(const uint8_t net_id[8], uint8_t flags,
|
|
|
|
uint32_t iv_index, const uint8_t auth[8],
|
2020-07-04 10:35:08 +00:00
|
|
|
bool *new_key);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
|
|
|
|
bool proxy);
|
|
|
|
|
|
|
|
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
|
|
|
const struct bt_mesh_send_cb *cb, void *cb_data);
|
|
|
|
|
|
|
|
int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
|
|
|
bool new_key, const struct bt_mesh_send_cb *cb,
|
|
|
|
void *cb_data);
|
|
|
|
|
|
|
|
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
|
|
|
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
2019-01-07 07:16:47 +00:00
|
|
|
enum bt_mesh_net_if net_if);
|
|
|
|
|
2020-01-19 10:57:13 +00:00
|
|
|
bool bt_mesh_primary_subnet_exist(void);
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint32_t bt_mesh_next_seq(void);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
void bt_mesh_net_start(void);
|
|
|
|
|
|
|
|
void bt_mesh_net_init(void);
|
2020-11-24 12:51:09 +00:00
|
|
|
void bt_mesh_net_reset(void);
|
2020-09-17 03:22:49 +00:00
|
|
|
void bt_mesh_net_deinit(void);
|
2020-01-19 10:57:13 +00:00
|
|
|
|
2019-10-24 07:08:33 +00:00
|
|
|
void bt_mesh_net_header_parse(struct net_buf_simple *buf,
|
|
|
|
struct bt_mesh_net_rx *rx);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
/* Friendship Credential Management */
|
|
|
|
struct friend_cred {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t net_idx;
|
|
|
|
uint16_t addr;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
uint16_t lpn_counter;
|
|
|
|
uint16_t frnd_counter;
|
2019-01-07 07:16:47 +00:00
|
|
|
|
|
|
|
struct {
|
2020-12-07 09:03:11 +00:00
|
|
|
uint8_t nid; /* NID */
|
|
|
|
uint8_t enc[16]; /* EncKey */
|
|
|
|
uint8_t privacy[16]; /* PrivacyKey */
|
2019-01-07 07:16:47 +00:00
|
|
|
} cred[2];
|
|
|
|
};
|
|
|
|
|
2020-12-07 09:03:11 +00:00
|
|
|
int friend_cred_get(struct bt_mesh_subnet *sub, uint16_t addr, uint8_t *nid,
|
|
|
|
const uint8_t **enc, const uint8_t **priv);
|
|
|
|
int friend_cred_set(struct friend_cred *cred, uint8_t idx, const uint8_t net_key[16]);
|
|
|
|
void friend_cred_refresh(uint16_t net_idx);
|
2019-01-07 07:16:47 +00:00
|
|
|
int friend_cred_update(struct bt_mesh_subnet *sub);
|
2020-12-07 09:03:11 +00:00
|
|
|
struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, uint16_t addr,
|
|
|
|
uint16_t lpn_counter, uint16_t frnd_counter);
|
2019-01-07 07:16:47 +00:00
|
|
|
void friend_cred_clear(struct friend_cred *cred);
|
2020-12-07 09:03:11 +00:00
|
|
|
int friend_cred_del(uint16_t net_idx, uint16_t addr);
|
2019-01-07 07:16:47 +00:00
|
|
|
|
2019-09-02 07:15:28 +00:00
|
|
|
static inline void send_cb_finalize(const struct bt_mesh_send_cb *cb,
|
2019-10-21 14:53:25 +00:00
|
|
|
void *cb_data)
|
2019-09-02 07:15:28 +00:00
|
|
|
{
|
|
|
|
if (!cb) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cb->start) {
|
|
|
|
cb->start(0, 0, cb_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cb->end) {
|
|
|
|
cb->end(0, cb_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-10 03:31:44 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-01-07 07:16:47 +00:00
|
|
|
#endif /* _NET_H_ */
|