ble_mesh: Miscellaneous modifications

1. Add an API to get provisioned node count
2. Update several ble mesh documents
3. Fix some bugs which have been merged
This commit is contained in:
lly
2020-01-19 23:08:25 +08:00
committed by baohongde
parent 3d49e49210
commit 36918e179c
31 changed files with 104 additions and 203 deletions

View File

@@ -1749,7 +1749,7 @@ if BLE_MESH
config BLE_MESH_PROVISIONER_APP_KEY_COUNT
int "Maximum number of application keys that can be owned by Provisioner"
default 9
default 3
range 1 4096
help
This option specifies how many application keys the Provisioner can have.
@@ -2058,7 +2058,7 @@ if BLE_MESH
config BLE_MESH_TX_SEG_MAX
int "Maximum number of segments in outgoing messages"
default 20
default 32
range 2 32
help
Maximum number of segments supported for outgoing messages.

View File

@@ -495,6 +495,11 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx)
return bt_mesh_provisioner_local_net_key_get(net_idx);
}
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void)
{
return btc_ble_mesh_provisioner_get_prov_node_count();
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */
#if (CONFIG_BLE_MESH_FAST_PROV)

View File

@@ -362,6 +362,14 @@ esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16
*/
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
/**
* @brief This function is called by Provisioner to get provisioned node count.
*
* @return Number of the provisioned nodes.
*
*/
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
/**
* @brief This function is called to get fast provisioning application key.
*

View File

@@ -323,7 +323,7 @@ typedef uint8_t esp_ble_mesh_bd_addr_t[BD_ADDR_LEN];
/// BLE device address type
typedef uint8_t esp_ble_mesh_addr_type_t;
/*!< BLE Mesh deinit parameters */
/** BLE Mesh deinit parameters */
typedef struct {
bool erase_flash; /*!< Indicate if erasing flash when deinit mesh stack */
} esp_ble_mesh_deinit_param_t;
@@ -354,17 +354,17 @@ typedef struct {
/** Pointer to the model to which the context belongs. Initialized by the stack. */
esp_ble_mesh_model_t *model;
uint16_t publish_addr; /*!< Publish Address. */
uint16_t app_idx; /*!< Publish AppKey Index. */
uint16_t publish_addr; /*!< Publish Address. */
uint16_t app_idx:12, /*!< Publish AppKey Index. */
cred:1; /*!< Friendship Credentials Flag. */
uint8_t ttl; /*!< Publish Time to Live. */
uint8_t retransmit; /*!< Retransmit Count & Interval Steps. */
uint8_t ttl; /*!< Publish Time to Live. */
uint8_t retransmit; /*!< Retransmit Count & Interval Steps. */
uint8_t period; /*!< Publish Period. */
uint16_t period_div: 4, /*!< Divisor for the Period. */
cred: 1, /*!< Friendship Credentials Flag. */
fast_period: 1, /*!< Use FastPeriodDivisor */
count: 3; /*!< Retransmissions left. */
uint8_t period_div:4, /*!< Divisor for the Period. */
fast_period:1, /*!< Use FastPeriodDivisor */
count:3; /*!< Retransmissions left. */
uint32_t period_start; /*!< Start of the current period. */
@@ -993,7 +993,7 @@ typedef union {
*/
struct ble_mesh_provisioner_prov_dev_with_addr_comp_param {
int err_code; /*!< Indicate the result of Provisioner starting to provision a device */
} provisioner_prov_dev_with_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_PROV_DEV_WITH_ADDR_COMP_EVT */
} provisioner_prov_dev_with_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_PROV_DEV_WITH_ADDR_COMP_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_DELETE_DEV_COMP_EVT
*/

View File

@@ -996,6 +996,11 @@ const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void)
return (const esp_ble_mesh_comp_t *)bt_mesh_comp_get();
}
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void)
{
return bt_mesh_provisioner_get_prov_node_count();
}
/* Configuration Models */
extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];

View File

@@ -290,6 +290,8 @@ esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem,
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);

View File

@@ -318,7 +318,7 @@ static s32_t next_period(struct bt_mesh_model *mod)
BT_INFO("Publishing took %ums", elapsed);
if (elapsed > period) {
if (elapsed >= period) {
BT_WARN("Publication sending took longer than the period");
/* Return smallest positive number since 0 means disabled */
return K_MSEC(1);

View File

@@ -27,11 +27,7 @@
#if defined(CONFIG_BLE_MESH_FAST_PROV)
#define UNPROVISIONED_INTERVAL K_SECONDS(3)
#else
#if !CONFIG_BLE_MESH_PROV_TEST
#define UNPROVISIONED_INTERVAL K_SECONDS(5)
#else
#define UNPROVISIONED_INTERVAL K_SECONDS(1)
#endif
#endif /* CONFIG_BLE_MESH_FAST_PROV */
#define PROVISIONED_INTERVAL K_SECONDS(10)

View File

@@ -334,15 +334,15 @@ struct bt_mesh_model_pub {
struct bt_mesh_model *mod;
u16_t addr; /**< Publish Address. */
u16_t key; /**< Publish AppKey Index. */
u16_t key:12, /**< Publish AppKey Index. */
cred:1; /**< Friendship Credentials Flag. */
u8_t ttl; /**< Publish Time to Live. */
u8_t retransmit; /**< Retransmit Count & Interval Steps. */
u8_t period; /**< Publish Period. */
u16_t period_div: 4, /**< Divisor for the Period. */
cred: 1, /**< Friendship Credentials Flag. */
fast_period: 1, /**< Use FastPeriodDivisor */
count: 3; /**< Retransmissions left. */
u8_t period_div:4, /**< Divisor for the Period. */
fast_period:1,/**< Use FastPeriodDivisor */
count:3; /**< Retransmissions left. */
u32_t period_start; /**< Start of the current period. */

View File

@@ -8,6 +8,9 @@
#include <errno.h>
#include "btc/btc_task.h"
#include "osi/alarm.h"
#include "mbedtls/aes.h"
#include "mbedtls/ecp.h"
@@ -19,16 +22,9 @@
#include "services/gatt/ble_svc_gatt.h"
#include "mesh_hci.h"
#include "mesh_aes_encrypt.h"
#include "mesh_bearer_adapt.h"
#include "mesh_trace.h"
#include "mesh_buf.h"
#include "mesh_atomic.h"
#include "esp_ble_mesh_defs.h"
#include "provisioner_prov.h"
#include "mesh_common.h"
#include "mesh_aes_encrypt.h"
#include "provisioner_prov.h"
/** @def BT_UUID_MESH_PROV
* @brief Mesh Provisioning Service
@@ -67,7 +63,7 @@ struct bt_mesh_dev bt_mesh_dev;
/* P-256 Variables */
static u8_t bt_mesh_public_key[64];
static BT_OCTET32 bt_mesh_private_key = {
static u8_t bt_mesh_private_key[32] = {
0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38,
0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99,
@@ -85,7 +81,7 @@ static sys_slist_t bt_mesh_gatts_db;
static struct bt_mesh_conn bt_mesh_gatts_conn[BLE_MESH_MAX_CONN];
static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb;
static BD_ADDR bt_mesh_gatts_addr;
static u8_t bt_mesh_gatts_addr[6];
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
@@ -1705,7 +1701,7 @@ int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u
{
uint8_t dhkey[32];
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, BT_OCTET32_LEN));
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, 32));
ble_sm_alg_gen_dhkey((uint8_t *)&remote_pk[0], (uint8_t *)&remote_pk[32], bt_mesh_private_key, dhkey);

View File

@@ -24,11 +24,7 @@
#if CONFIG_BLE_MESH_NODE
/* 3 transmissions, 20ms interval */
#if !CONFIG_BLE_MESH_PROV_TEST
#define PROV_XMIT BLE_MESH_TRANSMIT(2, 20)
#else
#define PROV_XMIT BLE_MESH_TRANSMIT(3, 10)
#endif
#define AUTH_METHOD_NO_OOB 0x00
#define AUTH_METHOD_STATIC 0x01
@@ -178,11 +174,7 @@ struct prov_rx {
#define TRANSACTION_TIMEOUT K_SECONDS(3)
#define PROTOCOL_TIMEOUT K_SECONDS(6)
#else
#if !CONFIG_BLE_MESH_PROV_TEST
#define RETRANSMIT_TIMEOUT K_MSEC(500)
#else
#define RETRANSMIT_TIMEOUT K_MSEC(80)
#endif
#define TRANSACTION_TIMEOUT K_SECONDS(30)
#define PROTOCOL_TIMEOUT K_SECONDS(60)
#endif /* CONFIG_BLE_MESH_FAST_PROV */

View File

@@ -31,11 +31,7 @@ _Static_assert(BLE_MESH_MAX_CONN >= CONFIG_BLE_MESH_PBG_SAME_TIME,
"Too large BLE Mesh PB-GATT count");
/* 3 transmissions, 20ms interval */
#if !CONFIG_BLE_MESH_PROV_TEST
#define PROV_XMIT BLE_MESH_TRANSMIT(2, 20)
#else
#define PROV_XMIT BLE_MESH_TRANSMIT(4, 10)
#endif
#define AUTH_METHOD_NO_OOB 0x00
#define AUTH_METHOD_STATIC 0x01
@@ -315,11 +311,7 @@ static unprov_adv_pkt_cb_t notify_unprov_adv_pkt_cb;
#define TRANSACTION_TIMEOUT K_SECONDS(3)
#define PROVISION_TIMEOUT K_SECONDS(6)
#else
#if !CONFIG_BLE_MESH_PROV_TEST
#define RETRANSMIT_TIMEOUT K_MSEC(500)
#else
#define RETRANSMIT_TIMEOUT K_MSEC(100)
#endif
#define TRANSACTION_TIMEOUT K_SECONDS(30)
#define PROVISION_TIMEOUT K_SECONDS(60)
#endif /* CONFIG_BLE_MESH_FAST_PROV */
@@ -1339,16 +1331,7 @@ static void buf_sent(int err, void *user_data)
return;
}
#if !CONFIG_BLE_MESH_PROV_TEST
k_delayed_work_submit(&link[idx].tx.retransmit, RETRANSMIT_TIMEOUT);
#else
if (link[idx].tx_pdu_type == 0x2) {
BT_DBG("expect_ack_for: %x %x",link[idx].tx_pdu_type,link[idx].expect_ack_for);
k_delayed_work_submit(&link[idx].tx.retransmit, 100 * 3);
} else {
k_delayed_work_submit(&link[idx].tx.retransmit, 100);
}
#endif
}
static struct bt_mesh_send_cb buf_sent_cb = {
@@ -1461,12 +1444,6 @@ static void gen_prov_ack_send(const u8_t idx, u8_t xact_id)
return;
}
#if CONFIG_BLE_MESH_PROV_TEST
if (link[idx].pending_ack < xact_id) {
link[idx].pending_ack = xact_id;
}
#endif
buf = adv_buf_create();
if (!buf) {
return;

View File

@@ -226,10 +226,10 @@ static void seg_tx_reset(struct seg_tx *tx)
tx->seg[i] = NULL;
}
bt_mesh_tx_seg_unlock();
tx->nack_count = 0U;
bt_mesh_tx_seg_unlock();
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_IVU_PENDING)) {
BT_DBG("Proceding with pending IV Update");
/* bt_mesh_net_iv_update() will re-enable the flag if this
@@ -322,8 +322,8 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
&seg_sent_cb, tx);
if (err) {
BT_ERR("%s, Sending segment failed", __func__);
seg_tx_complete(tx, -EIO);
bt_mesh_tx_seg_unlock();
seg_tx_complete(tx, -EIO);
return;
}
}

View File

@@ -210,16 +210,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
sys_slist_append(&internal->queue, &node->client_node);
bt_mesh_list_unlock();
k_delayed_work_init(&node->timer, timer_handler);
#if !CONFIG_BLE_MESH_PROV_TEST
k_delayed_work_submit(&node->timer, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT);
#else
if (node->opcode == 0x8008 || node->opcode == 0x0) {
k_delayed_work_submit(&node->timer, timeout ? timeout : 600 * 4);
} else {
k_delayed_work_submit(&node->timer, timeout ? timeout : 400);
}
#endif
}
}