|
|
@@ -23,10 +23,18 @@
|
|
|
#include "esp_ble_mesh_common_api.h"
|
|
|
#include "esp_ble_mesh_provisioning_api.h"
|
|
|
#include "esp_ble_mesh_generic_model_api.h"
|
|
|
-
|
|
|
#include "ble_mesh_console_lib.h"
|
|
|
#include "ble_mesh_adapter.h"
|
|
|
|
|
|
+#include "esp_bt_defs.h"
|
|
|
+#include "provisioner_prov.h"
|
|
|
+
|
|
|
+
|
|
|
+#include "esp_ble_mesh_config_model_api.h"
|
|
|
+
|
|
|
+#include "ble_mesh_console_decl.h"
|
|
|
+
|
|
|
+
|
|
|
typedef struct {
|
|
|
struct arg_str *static_val;
|
|
|
struct arg_int *static_val_len;
|
|
|
@@ -34,6 +42,7 @@ typedef struct {
|
|
|
struct arg_int *output_actions;
|
|
|
struct arg_int *input_size;
|
|
|
struct arg_int *input_actions;
|
|
|
+ struct arg_int *prov_start_address;
|
|
|
struct arg_end *end;
|
|
|
} ble_mesh_prov_t;
|
|
|
static ble_mesh_prov_t oob;
|
|
|
@@ -84,10 +93,57 @@ ble_mesh_node_status node_status = {
|
|
|
.previous = 0x0,
|
|
|
.current = 0x0,
|
|
|
};
|
|
|
-
|
|
|
SemaphoreHandle_t ble_mesh_node_sema;
|
|
|
|
|
|
-void ble_mesh_register_node_cmd(void);
|
|
|
+typedef struct {
|
|
|
+ struct arg_str *add_del;
|
|
|
+ struct arg_str *device_addr;
|
|
|
+ struct arg_str *device_uuid;
|
|
|
+ struct arg_int *addr_type;
|
|
|
+ struct arg_int *bearer;
|
|
|
+ struct arg_int *oob_info;
|
|
|
+ struct arg_int *flag;
|
|
|
+ struct arg_end *end;
|
|
|
+} ble_mesh_provisioner_addr_t;
|
|
|
+ble_mesh_provisioner_addr_t provisioner_addr;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ struct arg_str *action_type;
|
|
|
+ struct arg_int *net_idx;
|
|
|
+ struct arg_int *app_idx;
|
|
|
+ struct arg_str *key;
|
|
|
+ struct arg_end *end;
|
|
|
+} ble_mesh_provisioner_add_key_t;
|
|
|
+ble_mesh_provisioner_add_key_t provisioner_add_key;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ struct arg_int *unicast_addr;
|
|
|
+ struct arg_end *end;
|
|
|
+} ble_mesh_provisioner_get_node_t;
|
|
|
+ble_mesh_provisioner_get_node_t provisioner_get_node;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ struct arg_int *oob_info;
|
|
|
+ struct arg_int *unicast_addr;
|
|
|
+ struct arg_int *element_num;
|
|
|
+ struct arg_int *net_idx;
|
|
|
+ struct arg_str *dev_key;
|
|
|
+ struct arg_str *uuid;
|
|
|
+ struct arg_end *end;
|
|
|
+} ble_mesh_provisioner_add_node_t;
|
|
|
+ble_mesh_provisioner_add_node_t provisioner_add_node;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ struct arg_int *appkey_index;
|
|
|
+ struct arg_int *element_address;
|
|
|
+ struct arg_int *network_index;
|
|
|
+ struct arg_int *mod_id;
|
|
|
+ struct arg_int *cid;
|
|
|
+ struct arg_end *end;
|
|
|
+} ble_mesh_provisioner_bind_model_t;
|
|
|
+ble_mesh_provisioner_bind_model_t provisioner_local_bind;
|
|
|
+
|
|
|
+void ble_mesh_register_cmd(void);
|
|
|
// Register callback function
|
|
|
void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param);
|
|
|
void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param);
|
|
|
@@ -97,17 +153,17 @@ void ble_mesh_generic_server_model_cb(esp_ble_mesh_generic_server_cb_event_t eve
|
|
|
|
|
|
void ble_mesh_register_mesh_node(void)
|
|
|
{
|
|
|
- ble_mesh_register_node_cmd();
|
|
|
+ ble_mesh_register_cmd();
|
|
|
}
|
|
|
|
|
|
-int ble_mesh_register_node_cb(int argc, char** argv)
|
|
|
+int ble_mesh_register_cb(int argc, char** argv)
|
|
|
{
|
|
|
- ESP_LOGD(TAG, "enter %s\n", __func__);
|
|
|
+ ESP_LOGE(TAG, "enter %s\n", __func__);
|
|
|
ble_mesh_node_init();
|
|
|
esp_ble_mesh_register_prov_callback(ble_mesh_prov_cb);
|
|
|
esp_ble_mesh_register_custom_model_callback(ble_mesh_model_cb);
|
|
|
esp_ble_mesh_register_generic_server_callback(ble_mesh_generic_server_model_cb);
|
|
|
- ESP_LOGI(TAG, "Node:Reg,OK");
|
|
|
+ ESP_LOGI(TAG, "Bm:Reg,OK");
|
|
|
ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -183,7 +239,7 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
|
|
|
|
|
|
switch (event) {
|
|
|
case ESP_BLE_MESH_PROV_REGISTER_COMP_EVT:
|
|
|
- ble_mesh_callback_check_err_code(param->prov_register_comp.err_code, "Provisioning:Register");
|
|
|
+ ble_mesh_callback_check_err_code(param->prov_register_comp.err_code, "Bm:Init");
|
|
|
break;
|
|
|
case ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT:
|
|
|
ble_mesh_callback_check_err_code(param->node_prov_enable_comp.err_code, "Node:EnBearer");
|
|
|
@@ -211,7 +267,7 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
|
|
|
ble_mesh_set_node_prestore_params(param->node_prov_complete.net_idx, param->node_prov_complete.addr);
|
|
|
break;
|
|
|
case ESP_BLE_MESH_NODE_PROV_RESET_EVT:
|
|
|
- ESP_LOGI(TAG, "Node:Reset");
|
|
|
+ ESP_LOGI(TAG, "Bm:Reset");
|
|
|
break;
|
|
|
case ESP_BLE_MESH_NODE_PROV_INPUT_NUMBER_COMP_EVT:
|
|
|
ble_mesh_callback_check_err_code(param->node_prov_input_num_comp.err_code, "Node:InputNum");
|
|
|
@@ -231,6 +287,56 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p
|
|
|
case ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT:
|
|
|
ble_mesh_callback_check_err_code(param->node_proxy_gatt_disable_comp.err_code, "Node:DisProxyGatt");
|
|
|
break;
|
|
|
+#if (CONFIG_BLE_MESH_PROVISIONER)
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT:
|
|
|
+ ESP_LOGD(TAG, "Provisioner recv unprovisioned device beacon:");
|
|
|
+ ESP_LOG_BUFFER_HEX("Device UUID %s", param->provisioner_recv_unprov_adv_pkt.dev_uuid, 16);
|
|
|
+ ESP_LOG_BUFFER_HEX("Address %s", param->provisioner_recv_unprov_adv_pkt.addr, 6);
|
|
|
+ ESP_LOGD(TAG, "Address type 0x%x, oob_info 0x%04x, adv_type 0x%x, bearer 0x%x",
|
|
|
+ param->provisioner_recv_unprov_adv_pkt.addr_type, param->provisioner_recv_unprov_adv_pkt.oob_info,
|
|
|
+ param->provisioner_recv_unprov_adv_pkt.adv_type, param->provisioner_recv_unprov_adv_pkt.bearer);
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT:
|
|
|
+ ESP_LOGI(TAG, "Provisioner:LinkOpen,OK,%d", param->provisioner_prov_link_open.bearer);
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT:
|
|
|
+ ESP_LOGI(TAG, "Provisioner:LinkClose,OK,%d,%d",
|
|
|
+ param->provisioner_prov_link_close.bearer, param->provisioner_prov_link_close.reason);
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_ADD_UNPROV_DEV_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_add_unprov_dev_comp.err_code, "Provisioner:DevAdd");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_DELETE_DEV_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_delete_dev_comp.err_code, "Provisioner:DevDel");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT:
|
|
|
+ ESP_LOGI(TAG, "Provisioner:OK,%d,%d", param->provisioner_prov_complete.netkey_idx, param->provisioner_prov_complete.unicast_addr);
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_prov_enable_comp.err_code, "Provisioner:EnBearer");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_PROV_DISABLE_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_prov_disable_comp.err_code, "Provisioner:DisBearer");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_SET_DEV_UUID_MATCH_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_set_dev_uuid_match_comp.err_code, "Provisioner:UuidMatch");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_SET_PROV_DATA_INFO_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_set_prov_data_info_comp.err_code, "Provisioner:DataInfo");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_SET_NODE_NAME_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_set_node_name_comp.err_code, "Provisioner:NodeName");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_add_app_key_comp.err_code, "Provisioner:AppKeyAdd");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_BIND_APP_KEY_TO_MODEL_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_bind_app_key_to_model_comp.err_code, "Provisioner:AppKeyBind");
|
|
|
+ break;
|
|
|
+ case ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT:
|
|
|
+ ble_mesh_callback_check_err_code(param->provisioner_add_net_key_comp.err_code, "Provisioner:NetKeyAdd");
|
|
|
+ break;
|
|
|
+#endif
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -253,14 +359,14 @@ void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_c
|
|
|
data[1] = param->model_operation.msg[1];
|
|
|
data[2] = param->model_operation.msg[2];
|
|
|
data[3] = param->model_operation.ctx->recv_ttl;
|
|
|
- result = ble_mesh_node_statistics_accumultate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET);
|
|
|
+ result = ble_mesh_node_statistics_accumulate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET);
|
|
|
if (result == 0) {
|
|
|
esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx,
|
|
|
ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, sizeof(data), data);
|
|
|
}
|
|
|
} else if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_SET_UNACK) {
|
|
|
ESP_LOGI(TAG, "VendorModel:SetUnAck,Success,%d,%d", param->model_operation.ctx->recv_ttl, param->model_operation.length);
|
|
|
- result = ble_mesh_node_statistics_accumultate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK);
|
|
|
+ result = ble_mesh_node_statistics_accumulate(param->model_operation.msg, param->model_operation.length, VENDOR_MODEL_PERF_OPERATION_TYPE_SET_UNACK);
|
|
|
if (result == 0) {
|
|
|
esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx,
|
|
|
ESP_BLE_MESH_VND_MODEL_OP_TEST_PERF_STATUS, param->model_operation.length, param->model_operation.msg);
|
|
|
@@ -326,29 +432,50 @@ int ble_mesh_power_set(int argc, char **argv)
|
|
|
static int ble_mesh_load_oob(int argc, char **argv)
|
|
|
{
|
|
|
uint8_t *static_val;
|
|
|
- int nerrors = arg_parse(argc, argv, (void **) &oob);
|
|
|
|
|
|
ESP_LOGD(TAG, "enter %s \n", __func__);
|
|
|
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &oob);
|
|
|
if (nerrors != 0) {
|
|
|
arg_print_errors(stderr, oob.end, argv[0]);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
//parsing prov
|
|
|
+#if CONFIG_BLE_MESH_NODE
|
|
|
+ prov.uuid = dev_uuid;
|
|
|
+ memcpy(dev_uuid, esp_bt_dev_get_address(), BD_ADDR_LEN);
|
|
|
if (oob.static_val->count != 0) {
|
|
|
static_val = malloc(oob.static_val_len->ival[0] + 1);
|
|
|
+ if (static_val == NULL) {
|
|
|
+ ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
|
|
|
+ }
|
|
|
get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
|
|
|
prov.static_val = static_val;
|
|
|
}
|
|
|
|
|
|
- arg_int_to_value(oob.static_val_len, prov.static_val_len, "static_val_len");
|
|
|
- arg_int_to_value(oob.output_size, prov.output_size, "output_size");
|
|
|
- arg_int_to_value(oob.output_actions, prov.output_actions, "output_actions");
|
|
|
- arg_int_to_value(oob.input_size, prov.input_size, "input_size");
|
|
|
- arg_int_to_value(oob.input_actions, prov.input_actions, "input_action");
|
|
|
+ arg_int_to_value(oob.static_val_len, prov.static_val_len, "static value length");
|
|
|
+ arg_int_to_value(oob.output_size, prov.output_size, "output size");
|
|
|
+ arg_int_to_value(oob.output_actions, prov.output_actions, "output actions");
|
|
|
+ arg_int_to_value(oob.input_size, prov.input_size, "input size");
|
|
|
+ arg_int_to_value(oob.input_actions, prov.input_actions, "input actions");
|
|
|
+#endif
|
|
|
+
|
|
|
+#if CONFIG_BLE_MESH_PROVISIONER
|
|
|
+ if (oob.static_val->count != 0) {
|
|
|
+ static_val = malloc(oob.static_val_len->ival[0] + 1);
|
|
|
+ if (static_val == NULL) {
|
|
|
+ ESP_LOGE(TAG, "malloc fail,%s,%d\n", __func__, __LINE__);
|
|
|
+ }
|
|
|
+ get_value_string((char *)oob.static_val->sval[0], (char *)static_val);
|
|
|
+ prov.prov_static_oob_val = static_val;
|
|
|
+ }
|
|
|
+ arg_int_to_value(oob.prov_start_address, prov.prov_start_address, "provisioner start address");
|
|
|
+ arg_int_to_value(oob.static_val_len, prov.prov_static_oob_len, "provisioner static value length");
|
|
|
+#endif
|
|
|
|
|
|
ESP_LOGI(TAG, "OOB:Load,OK\n");
|
|
|
+
|
|
|
ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -366,7 +493,7 @@ int ble_mesh_init(int argc, char **argv)
|
|
|
}
|
|
|
|
|
|
ESP_LOGD(TAG, "enter %s, module %x\n", __func__, component.model_type->ival[0]);
|
|
|
- local_component = ble_mesh_get_component(component.model_type->ival[0]);
|
|
|
+ local_component = ble_mesh_get_component(component.model_type->ival[0]);
|
|
|
|
|
|
if (component.dev_uuid->count != 0) {
|
|
|
device_uuid = malloc((ESP_BLE_MESH_OCTET16_LEN + 1) * sizeof(uint8_t));
|
|
|
@@ -380,11 +507,13 @@ int ble_mesh_init(int argc, char **argv)
|
|
|
str_2_mac((uint8_t *)component.dev_uuid->sval[0], device_uuid);
|
|
|
memcpy(dev_uuid, device_uuid, BD_ADDR_LEN);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ memcpy(dev_uuid, esp_bt_dev_get_address(), 6);
|
|
|
}
|
|
|
|
|
|
err = esp_ble_mesh_init(&prov, local_component);
|
|
|
if (err) {
|
|
|
- ESP_LOGE(TAG, "Initializing mesh failed (err %d)\n", err);
|
|
|
+ ESP_LOGI(TAG, "Bm:Init,OK\n");
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
@@ -402,6 +531,7 @@ int ble_mesh_node_enable_bearer(int argc, char **argv)
|
|
|
int nerrors = arg_parse(argc, argv, (void **) &bearer);
|
|
|
if (nerrors != 0) {
|
|
|
arg_print_errors(stderr, bearer.end, argv[0]);
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
@@ -420,6 +550,32 @@ int ble_mesh_node_enable_bearer(int argc, char **argv)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
+int ble_mesh_provisioner_enable_bearer(int argc, char **argv)
|
|
|
+{
|
|
|
+ esp_err_t err = 0;
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "enter %s \n", __func__);
|
|
|
+
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &bearer);
|
|
|
+ if (nerrors != 0) {
|
|
|
+ arg_print_errors(stderr, bearer.end, argv[0]);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bearer.enable->count != 0) {
|
|
|
+ if (bearer.enable->ival[0]) {
|
|
|
+ err = esp_ble_mesh_provisioner_prov_enable(bearer.bearer->ival[0]);
|
|
|
+ } else {
|
|
|
+ err = esp_ble_mesh_provisioner_prov_disable(bearer.bearer->ival[0]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
int ble_mesh_node_reset(int argc, char** argv)
|
|
|
{
|
|
|
esp_err_t err;
|
|
|
@@ -493,22 +649,244 @@ int ble_mesh_node_enter_network_auto(int argc, char **argv)
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
-void ble_mesh_register_node_cmd(void)
|
|
|
+int ble_mesh_provision_address(int argc, char **argv)
|
|
|
+{
|
|
|
+ esp_err_t err = ESP_OK;
|
|
|
+ esp_ble_mesh_unprov_dev_add_t device_addr = {0};
|
|
|
+ uint8_t preset_addr_uuid[16] = {0x01, 0x02};
|
|
|
+ esp_ble_mesh_device_delete_t del_dev = {
|
|
|
+ .flag = BIT(0),
|
|
|
+ };
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "enter %s \n", __func__);
|
|
|
+
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &provisioner_addr);
|
|
|
+ if (nerrors != 0) {
|
|
|
+ arg_print_errors(stderr, provisioner_addr.end, argv[0]);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ memcpy(device_addr.uuid, preset_addr_uuid, BD_ADDR_LEN);
|
|
|
+ if (provisioner_addr.device_addr->count != 0) {
|
|
|
+ str_2_mac((uint8_t *)provisioner_addr.device_addr->sval[0], device_addr.addr);
|
|
|
+ str_2_mac((uint8_t *)provisioner_addr.device_addr->sval[0], del_dev.addr);
|
|
|
+ arg_int_to_value(provisioner_addr.addr_type, device_addr.addr_type, "address type");
|
|
|
+ arg_int_to_value(provisioner_addr.addr_type, del_dev.addr_type, "address type");
|
|
|
+ } else if (provisioner_addr.device_uuid->count != 0) {
|
|
|
+ get_value_string((char *)provisioner_addr.device_uuid->sval[0], (char *)device_addr.uuid);
|
|
|
+ get_value_string((char *)provisioner_addr.device_uuid->sval[0], (char *)del_dev.uuid);
|
|
|
+ del_dev.flag = BIT(1);
|
|
|
+ }
|
|
|
+
|
|
|
+#if CONFIG_BLE_MESH_PROVISIONER
|
|
|
+ if (strcmp(provisioner_addr.add_del->sval[0], "add") == 0) {
|
|
|
+ arg_int_to_value(provisioner_addr.bearer, device_addr.bearer, "bearer");
|
|
|
+ arg_int_to_value(provisioner_addr.oob_info, device_addr.oob_info, "oob information");
|
|
|
+ err = esp_ble_mesh_provisioner_add_unprov_dev(&device_addr, provisioner_addr.flag->ival[0]);
|
|
|
+ } else if (strcmp(provisioner_addr.add_del->sval[0], "del") == 0) {
|
|
|
+ err = esp_ble_mesh_provisioner_delete_dev(&del_dev);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+ if (err != ESP_OK) {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:AddDelAddr,Fail,%d", err);
|
|
|
+ } else {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:AddDelAddr,OK");
|
|
|
+ }
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "exit %s \n", __func__);
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+int ble_mesh_provisioner_add_key(int argc, char **argv)
|
|
|
+{
|
|
|
+ esp_err_t err = ESP_OK;
|
|
|
+ uint8_t key[16] = {0};
|
|
|
+ esp_ble_mesh_prov_data_info_t info = {
|
|
|
+ .net_idx = 1,
|
|
|
+ .flag = NET_IDX_FLAG,
|
|
|
+ };
|
|
|
+ ESP_LOGD(TAG, " enter %s\n", __func__);
|
|
|
+
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &provisioner_add_key);
|
|
|
+ if (nerrors != 0) {
|
|
|
+ arg_print_errors(stderr, provisioner_add_key.end, argv[0]);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ err = get_value_string((char *)provisioner_add_key.key->sval[0], (char *) key);
|
|
|
+ if (strcmp(provisioner_add_key.action_type->sval[0], "appkey") == 0) {
|
|
|
+ err = esp_ble_mesh_provisioner_add_local_app_key(key, provisioner_add_key.net_idx->ival[0], provisioner_add_key.app_idx->ival[0]);
|
|
|
+ } else if (strcmp(provisioner_add_key.action_type->sval[0], "netkey") == 0) {
|
|
|
+ // choose network key
|
|
|
+ info.net_idx = provisioner_add_key.net_idx->ival[0];
|
|
|
+ err = esp_ble_mesh_provisioner_add_local_net_key(key, provisioner_add_key.net_idx->ival[0]);
|
|
|
+ err = err | esp_ble_mesh_provisioner_set_prov_data_info(&info);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (err != ESP_OK) {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:KeyAction,Fail,%d", err);
|
|
|
+ } else {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:KeyAction,OK");
|
|
|
+ }
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+int ble_mesh_provisioner_get_node(int argc, char **argv)
|
|
|
+{
|
|
|
+ uint16_t unicast_addr = 0;
|
|
|
+ uint16_t i = 0;
|
|
|
+ esp_ble_mesh_node_t *node_info;
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "enter %s\n", __func__);
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &provisioner_get_node);
|
|
|
+ if (nerrors != 0) {
|
|
|
+ arg_print_errors(stderr, provisioner_get_node.end, argv[0]);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ arg_int_to_value(provisioner_get_node.unicast_addr, unicast_addr, "unicast address");
|
|
|
+ node_info = esp_ble_mesh_provisioner_get_node_with_addr(unicast_addr);
|
|
|
+
|
|
|
+ if (node_info == NULL) {
|
|
|
+ return ESP_FAIL;
|
|
|
+ } else {
|
|
|
+ printf("OobInfo:0x%x,Address:0x%x,EleNum:0x%x,NetIdx:0x%x,DevKey:",
|
|
|
+ node_info->oob_info, node_info->unicast_addr, node_info->element_num, node_info->net_idx);
|
|
|
+ for (i = 0; i < 16; i++) {
|
|
|
+ printf("%02x", node_info->dev_key[i]);
|
|
|
+ }
|
|
|
+ printf(",DevUuid:");
|
|
|
+ for (i = 0; i < 16; i++) {
|
|
|
+ printf("%02x", node_info->dev_uuid[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
+ return ESP_OK;
|
|
|
+}
|
|
|
+
|
|
|
+int ble_mesh_provisioner_add_node(int argc, char **argv)
|
|
|
+{
|
|
|
+ struct bt_mesh_node node_info;
|
|
|
+ esp_err_t result;
|
|
|
+ ESP_LOGD(TAG, " enter %s\n", __func__);
|
|
|
+
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &provisioner_add_node);
|
|
|
+ if (nerrors != 0) {
|
|
|
+ arg_print_errors(stderr, provisioner_add_node.end, argv[0]);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ arg_int_to_value(provisioner_add_node.oob_info, node_info.oob_info, "oob information");
|
|
|
+ arg_int_to_value(provisioner_add_node.unicast_addr, node_info.unicast_addr, "unicast address");
|
|
|
+ arg_int_to_value(provisioner_add_node.element_num, node_info.element_num, "element number");
|
|
|
+ arg_int_to_value(provisioner_add_node.net_idx, node_info.net_idx, "network index");
|
|
|
+ if (provisioner_add_node.dev_key->count != 0) {
|
|
|
+ get_value_string((char *)provisioner_add_node.dev_key->sval[0], (char *)node_info.dev_key);
|
|
|
+ }
|
|
|
+ if (provisioner_add_node.uuid->count != 0) {
|
|
|
+ get_value_string((char *)provisioner_add_node.uuid->sval[0], (char *)node_info.dev_uuid);
|
|
|
+ get_value_string((char *)provisioner_add_node.uuid->sval[0], (char *)node_info.dev_uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+ result = bt_mesh_provisioner_store_node_info(&node_info);
|
|
|
+ if (result == ESP_OK) {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:AddNodeInfo,OK\n");
|
|
|
+ } else {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:AddNodeInfo,ERROR,%d\n", result);
|
|
|
+ }
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+int ble_mesh_provision_bind_local_model(int argc, char **argv)
|
|
|
+{
|
|
|
+ esp_err_t err;
|
|
|
+ uint16_t element_addr = 0;
|
|
|
+ uint16_t app_idx = 0;
|
|
|
+ uint16_t model_id = 0;
|
|
|
+ uint16_t company_id = 0xFFFF;
|
|
|
+
|
|
|
+ ESP_LOGD(TAG, " enter %s\n", __func__);
|
|
|
+
|
|
|
+ int nerrors = arg_parse(argc, argv, (void **) &provisioner_local_bind);
|
|
|
+ if (nerrors != 0) {
|
|
|
+ arg_print_errors(stderr, provisioner_local_bind.end, argv[0]);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ arg_int_to_value(provisioner_local_bind.element_address, element_addr, "element address");
|
|
|
+ arg_int_to_value(provisioner_local_bind.appkey_index, app_idx, "appkey index");
|
|
|
+ arg_int_to_value(provisioner_local_bind.mod_id, model_id, "model id");
|
|
|
+ arg_int_to_value(provisioner_local_bind.cid, company_id, "company id");
|
|
|
+ err = esp_ble_mesh_provisioner_bind_app_key_to_local_model(element_addr, app_idx, model_id, company_id);
|
|
|
+
|
|
|
+ if (err != ESP_OK) {
|
|
|
+ ESP_LOGE(TAG, "Provisioner:BindModel,Fail,%d\n", err);
|
|
|
+ } else {
|
|
|
+ ESP_LOGI(TAG, "Provisioner:BindModel,OK\n");
|
|
|
+ }
|
|
|
+ ESP_LOGD(TAG, "exit %s\n", __func__);
|
|
|
+ return err;
|
|
|
+}
|
|
|
+
|
|
|
+void ble_mesh_register_cmd(void)
|
|
|
{
|
|
|
const esp_console_cmd_t register_cmd = {
|
|
|
.command = "bmreg",
|
|
|
.help = "ble mesh: provisioner/node register callback",
|
|
|
.hint = NULL,
|
|
|
- .func = &ble_mesh_register_node_cb,
|
|
|
+ .func = &ble_mesh_register_cb,
|
|
|
};
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(®ister_cmd));
|
|
|
|
|
|
+ component.model_type = arg_int0("m", NULL, "<model>", "mesh model");
|
|
|
+ component.config_index = arg_int0("c", NULL, "<index>", "mesh model op");
|
|
|
+ component.config_index->ival[0] = 0; // set default value
|
|
|
+ component.pub_config = arg_int0("p", NULL, "<publish>", "publish message buffer");
|
|
|
+ component.dev_uuid = arg_str0("d", NULL, "<uuid>", "device uuid");
|
|
|
+ component.end = arg_end(1);
|
|
|
+
|
|
|
+ const esp_console_cmd_t model_cmd = {
|
|
|
+ .command = "bminit",
|
|
|
+ .help = "ble mesh: provisioner/node init",
|
|
|
+ .hint = NULL,
|
|
|
+ .func = &ble_mesh_init,
|
|
|
+ .argtable = &component,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK( esp_console_cmd_register(&model_cmd) );
|
|
|
+
|
|
|
+ provisioner_addr.add_del = arg_str1("z", NULL, "<add/delete>", "action type");
|
|
|
+ provisioner_addr.device_addr = arg_str0("d", NULL, "<address>", "device address");
|
|
|
+ provisioner_addr.device_uuid = arg_str0("u", NULL, "<uuid>", "device uuid");
|
|
|
+ provisioner_addr.addr_type = arg_int0("a", NULL, "<type>", "address type");
|
|
|
+ provisioner_addr.flag = arg_int0("f", NULL, "<flag>", "address flag");
|
|
|
+ provisioner_addr.flag->ival[0] = ADD_DEV_RM_AFTER_PROV_FLAG | ADD_DEV_FLUSHABLE_DEV_FLAG;
|
|
|
+ provisioner_addr.bearer = arg_int0("b", NULL, "<bearer>", "used bearer");
|
|
|
+ provisioner_addr.oob_info = arg_int0("o", NULL, "<oob info>", "oob information");
|
|
|
+ provisioner_addr.end = arg_end(1);
|
|
|
+
|
|
|
+ const esp_console_cmd_t provisioner_addr_cmd = {
|
|
|
+ .command = "bmpdev",
|
|
|
+ .help = "ble mesh provisioner: add/delete unprovisioned device",
|
|
|
+ .hint = NULL,
|
|
|
+ .func = &ble_mesh_provision_address,
|
|
|
+ .argtable = &provisioner_addr,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_addr_cmd));
|
|
|
+
|
|
|
oob.static_val = arg_str0("s", NULL, "<value>", "Static OOB value");
|
|
|
oob.static_val_len = arg_int0("l", NULL, "<length>", "Static OOB value length");
|
|
|
oob.output_size = arg_int0("x", NULL, "<size>", "Maximum size of Output OOB");
|
|
|
oob.output_actions = arg_int0("o", NULL, "<actions>", "Supported Output OOB Actions");
|
|
|
oob.input_size = arg_int0("y", NULL, "<size>", "Maximum size of Input OOB");
|
|
|
oob.input_actions = arg_int0("i", NULL, "<actions>", "Supported Input OOB Actions");
|
|
|
+ oob.prov_start_address = arg_int0("p", NULL, "<address>", "start address assigned by provisioner");
|
|
|
+ oob.prov_start_address->ival[0] = 0x0005;
|
|
|
oob.end = arg_end(1);
|
|
|
|
|
|
const esp_console_cmd_t oob_cmd = {
|
|
|
@@ -520,34 +898,41 @@ void ble_mesh_register_node_cmd(void)
|
|
|
};
|
|
|
ESP_ERROR_CHECK( esp_console_cmd_register(&oob_cmd) );
|
|
|
|
|
|
- component.model_type = arg_int0("m", NULL, "<model>", "mesh model");
|
|
|
- component.config_index = arg_int0("c", NULL, "<index>", "mesh model op");
|
|
|
- component.config_index->ival[0] = 0; // set default value
|
|
|
- component.pub_config = arg_int0("p", NULL, "<publish>", "publish message buffer");
|
|
|
- component.dev_uuid = arg_str0("d", NULL, "<uuid>", "device uuid");
|
|
|
- component.end = arg_end(1);
|
|
|
-
|
|
|
- const esp_console_cmd_t model_cmd = {
|
|
|
- .command = "bminit",
|
|
|
- .help = "ble mesh: provisioner/node init",
|
|
|
- .hint = NULL,
|
|
|
- .func = &ble_mesh_init,
|
|
|
- .argtable = &component,
|
|
|
- };
|
|
|
- ESP_ERROR_CHECK( esp_console_cmd_register(&model_cmd) );
|
|
|
-
|
|
|
bearer.bearer = arg_int0("b", NULL, "<bearer>", "supported bearer");
|
|
|
bearer.enable = arg_int0("e", NULL, "<enable/disable>", "bearers node supported");
|
|
|
bearer.end = arg_end(1);
|
|
|
|
|
|
- const esp_console_cmd_t bearer_cmd = {
|
|
|
+ const esp_console_cmd_t bearer_node_cmd = {
|
|
|
.command = "bmnbearer",
|
|
|
- .help = "ble mesh node: enable/disable different bearer",
|
|
|
+ .help = "ble mesh node/porvisioner: enable/disable different bearer",
|
|
|
.hint = NULL,
|
|
|
.func = &ble_mesh_node_enable_bearer,
|
|
|
.argtable = &bearer,
|
|
|
};
|
|
|
- ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_cmd));
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_node_cmd));
|
|
|
+
|
|
|
+ const esp_console_cmd_t bearer_provisioner_cmd = {
|
|
|
+ .command = "bmpbearer",
|
|
|
+ .help = "ble mesh provisioner: enable/disable different bearers",
|
|
|
+ .hint = NULL,
|
|
|
+ .func = &ble_mesh_provisioner_enable_bearer,
|
|
|
+ .argtable = &bearer,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&bearer_provisioner_cmd));
|
|
|
+
|
|
|
+ provisioner_add_key.action_type = arg_str1("z", NULL, "<action type>", "add appkey or network key");
|
|
|
+ provisioner_add_key.net_idx = arg_int1("n", NULL, "<net key index>", "network key index");
|
|
|
+ provisioner_add_key.key = arg_str1("k", NULL, "<key>", "appkey or network");
|
|
|
+ provisioner_add_key.app_idx = arg_int0("a", NULL, "<app key index>", "appkey index");
|
|
|
+ provisioner_add_key.end = arg_end(1);
|
|
|
+
|
|
|
+ const esp_console_cmd_t provisioner_add_key_cmd = {
|
|
|
+ .command = "bmpkey",
|
|
|
+ .help = "ble mesh provisioner: key",
|
|
|
+ .func = &ble_mesh_provisioner_add_key,
|
|
|
+ .argtable = &provisioner_add_key,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_add_key_cmd));
|
|
|
|
|
|
const esp_console_cmd_t reset_cmd = {
|
|
|
.command = "bmnreset",
|
|
|
@@ -583,6 +968,48 @@ void ble_mesh_register_node_cmd(void)
|
|
|
};
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&power_set_cmd));
|
|
|
|
|
|
+ provisioner_get_node.unicast_addr = arg_int1("u", NULL, "<address>", "get node by unicast address");
|
|
|
+ provisioner_get_node.end = arg_end(1);
|
|
|
+
|
|
|
+ const esp_console_cmd_t provisioner_get_node_cmd = {
|
|
|
+ .command = "bmpgetn",
|
|
|
+ .help = "ble mesh provisioner: get node",
|
|
|
+ .func = &ble_mesh_provisioner_get_node,
|
|
|
+ .argtable = &provisioner_get_node,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_get_node_cmd));
|
|
|
+
|
|
|
+ provisioner_add_node.oob_info = arg_int0("o", NULL, "<oob info>", "oob information");
|
|
|
+ provisioner_add_node.unicast_addr = arg_int0("a", NULL, "<unicast address>", "unicast address");
|
|
|
+ provisioner_add_node.element_num = arg_int0("e", NULL, "<element num>", "element num");
|
|
|
+ provisioner_add_node.net_idx = arg_int0("n", NULL, "<net index>", "net index");
|
|
|
+ provisioner_add_node.dev_key = arg_str0("d", NULL, "<device key>", "device key");
|
|
|
+ provisioner_add_node.uuid = arg_str0("u", NULL, "<device uuid>", "device uuid");
|
|
|
+ provisioner_add_node.end = arg_end(1);
|
|
|
+
|
|
|
+ const esp_console_cmd_t provisioner_add_node_cmd = {
|
|
|
+ .command = "bmpaddn",
|
|
|
+ .help = "ble mesh provisioner: add node",
|
|
|
+ .func = &ble_mesh_provisioner_add_node,
|
|
|
+ .argtable = &provisioner_add_node,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_add_node_cmd));
|
|
|
+
|
|
|
+ provisioner_local_bind.appkey_index = arg_int1("a", NULL, "<appkey index>", "appkey index");
|
|
|
+ provisioner_local_bind.element_address = arg_int1("e", NULL, "<element address>", "element address");
|
|
|
+ provisioner_local_bind.network_index = arg_int1("n", NULL, "<network index>", "network index");
|
|
|
+ provisioner_local_bind.mod_id = arg_int1("m", NULL, "<model id>", "model id");
|
|
|
+ provisioner_local_bind.cid = arg_int0("c", NULL, "<model id>", "company id");
|
|
|
+ provisioner_local_bind.end = arg_end(1);
|
|
|
+
|
|
|
+ const esp_console_cmd_t provisioner_local_bind_cmd = {
|
|
|
+ .command = "bmpbind",
|
|
|
+ .help = "ble mesh provisioner: bind local model",
|
|
|
+ .func = &ble_mesh_provision_bind_local_model,
|
|
|
+ .argtable = &provisioner_local_bind,
|
|
|
+ };
|
|
|
+ ESP_ERROR_CHECK(esp_console_cmd_register(&provisioner_local_bind_cmd));
|
|
|
+
|
|
|
node_network_info.net_key = arg_str1("k", NULL, "<net key>", "network key");
|
|
|
node_network_info.net_idx = arg_int1("n", NULL, "<net index>", "network key index");
|
|
|
node_network_info.unicast_addr = arg_int1("u", NULL, "<unicast address>", "unicast address");
|
|
|
@@ -600,4 +1027,4 @@ void ble_mesh_register_node_cmd(void)
|
|
|
.argtable = &node_network_info,
|
|
|
};
|
|
|
ESP_ERROR_CHECK(esp_console_cmd_register(&node_network_info_cmd));
|
|
|
-}
|
|
|
+}
|