diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h index b6f04fdf31..14f8318d2c 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h @@ -610,28 +610,135 @@ typedef enum { ESP_BLE_MESH_CFG_CLIENT_EVT_MAX, } esp_ble_mesh_cfg_client_cb_event_t; -/** Parameter of Config AppKey Add */ +/** + * @brief Configuration Server model related context. + */ + typedef struct { - uint16_t app_idx; /*!< AppKey Index of the Config AppKey Add */ -} esp_ble_mesh_cfg_srv_app_key_add_cb_t; + uint16_t element_addr; /*!< Element Address */ + uint16_t pub_addr; /*!< Publish Address */ + uint16_t app_idx; /*!< AppKey Index */ + bool cred_flag; /*!< Friendship Credential Flag */ + uint8_t pub_ttl; /*!< Publish TTL */ + uint8_t pub_period; /*!< Publish Period */ + uint8_t pub_retransmit; /*!< Publish Retransmit */ + uint16_t company_id; /*!< Company ID */ + uint16_t model_id; /*!< Model ID */ +} esp_ble_mesh_state_change_cfg_mod_pub_set_t; + +/** Parameters of Config Model Subscription Add */ +typedef struct { + uint16_t element_addr; /*!< Element Address */ + uint16_t sub_addr; /*!< Subscription Address */ + uint16_t company_id; /*!< Company ID */ + uint16_t model_id; /*!< Model ID */ +} esp_ble_mesh_state_change_cfg_model_sub_add_t; + +/** Parameters of Config Model Subscription Delete */ +typedef struct { + uint16_t element_addr; /*!< Element Address */ + uint16_t sub_addr; /*!< Subscription Address */ + uint16_t company_id; /*!< Company ID */ + uint16_t model_id; /*!< Model ID */ +} esp_ble_mesh_state_change_cfg_model_sub_delete_t; + +/** Parameters of Config NetKey Add */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ + uint8_t net_key[16]; /*!< NetKey */ +} esp_ble_mesh_state_change_cfg_netkey_add_t; + +/** Parameters of Config NetKey Update */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ + uint8_t net_key[16]; /*!< NetKey */ +} esp_ble_mesh_state_change_cfg_netkey_update_t; + +/** Parameter of Config NetKey Delete */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ +} esp_ble_mesh_state_change_cfg_netkey_delete_t; + +/** Parameters of Config AppKey Add */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ + uint16_t app_idx; /*!< AppKey Index */ + uint8_t app_key[16]; /*!< AppKey */ +} esp_ble_mesh_state_change_cfg_appkey_add_t; + +/** Parameters of Config AppKey Update */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ + uint16_t app_idx; /*!< AppKey Index */ + uint8_t app_key[16]; /*!< AppKey */ +} esp_ble_mesh_state_change_cfg_appkey_update_t; + +/** Parameters of Config AppKey Delete */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ + uint16_t app_idx; /*!< AppKey Index */ +} esp_ble_mesh_state_change_cfg_appkey_delete_t; + +/** Parameters of Config Model App Bind */ +typedef struct { + uint16_t element_addr; /*!< Element Address */ + uint16_t app_idx; /*!< AppKey Index */ + uint16_t company_id; /*!< Company ID */ + uint16_t model_id; /*!< Model ID */ +} esp_ble_mesh_state_change_cfg_model_app_bind_t; + +/** Parameters of Config Model App Unbind */ +typedef struct { + uint16_t element_addr; /*!< Element Address */ + uint16_t app_idx; /*!< AppKey Index */ + uint16_t company_id; /*!< Company ID */ + uint16_t model_id; /*!< Model ID */ +} esp_ble_mesh_state_change_cfg_model_app_unbind_t; + +/** Parameters of Config Key Refresh Phase Set */ +typedef struct { + uint16_t net_idx; /*!< NetKey Index */ + uint8_t kr_phase; /*!< New Key Refresh Phase Transition */ +} esp_ble_mesh_state_change_cfg_kr_phase_set_t; /** - * @brief Configuration Server Model received message union + * @brief Configuration Server model state change value union */ typedef union { - esp_ble_mesh_cfg_srv_app_key_add_cb_t app_key_add; /*!< The Config AppKey Add event value */ -} esp_ble_mesh_cfg_server_common_cb_param_t; + /** + * The recv_op in ctx can be used to decide which state is changed. + */ + esp_ble_mesh_state_change_cfg_mod_pub_set_t mod_pub_set; /*!< Config Model Publication Set */ + esp_ble_mesh_state_change_cfg_model_sub_add_t mod_sub_add; /*!< Config Model Subscription Add */ + esp_ble_mesh_state_change_cfg_model_sub_delete_t mod_sub_delete; /*!< Config Model Subscription Delete */ + esp_ble_mesh_state_change_cfg_netkey_add_t netkey_add; /*!< Config NetKey Add */ + esp_ble_mesh_state_change_cfg_netkey_update_t netkey_update; /*!< Config NetKey Update */ + esp_ble_mesh_state_change_cfg_netkey_delete_t netkey_delete; /*!< Config NetKey Delete */ + esp_ble_mesh_state_change_cfg_appkey_add_t appkey_add; /*!< Config AppKey Add */ + esp_ble_mesh_state_change_cfg_appkey_update_t appkey_update; /*!< Config AppKey Update */ + esp_ble_mesh_state_change_cfg_appkey_delete_t appkey_delete; /*!< Config AppKey Delete */ + esp_ble_mesh_state_change_cfg_model_app_bind_t mod_app_bind; /*!< Config Model App Bind */ + esp_ble_mesh_state_change_cfg_model_app_unbind_t mod_app_unbind; /*!< Config Model App Unbind */ + esp_ble_mesh_state_change_cfg_kr_phase_set_t kr_phase_set; /*!< Config Key Refresh Phase Set */ +} esp_ble_mesh_cfg_server_state_change_t; -/** Configuration Server Model callback parameters */ +/** + * @brief Configuration Server model callback value union + */ +typedef union { + esp_ble_mesh_cfg_server_state_change_t state_change; /*!< ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT */ +} esp_ble_mesh_cfg_server_cb_value_t; + +/** Configuration Server model callback parameters */ typedef struct { - esp_ble_mesh_model_t *model; /*!< Pointer to the server model structure */ - esp_ble_mesh_msg_ctx_t ctx; /*!< The context of the received message */ - esp_ble_mesh_cfg_server_common_cb_param_t status_cb; /*!< The received configuration message callback values */ + esp_ble_mesh_model_t *model; /*!< Pointer to the server model structure */ + esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received message */ + esp_ble_mesh_cfg_server_cb_value_t value; /*!< Value of the received configuration messages */ } esp_ble_mesh_cfg_server_cb_param_t; -/** This enum value is the event of Configuration Server Model */ +/** This enum value is the event of Configuration Server model */ typedef enum { - ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT, + ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT, ESP_BLE_MESH_CFG_SERVER_EVT_MAX, } esp_ble_mesh_cfg_server_cb_event_t; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index fe2700e20a..4dd56a48d9 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -288,6 +288,11 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_CONFIG_CLIENT; msg.act = act; @@ -687,6 +692,11 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_CONFIG_SERVER; msg.act = act; @@ -709,8 +719,8 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, } switch (evt_type) { - case BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG: - act = ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT; + case BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE: + act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT; break; default: LOG_ERROR("%s, Unknown config server event type %d", __func__, evt_type); @@ -726,8 +736,8 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_dst = ctx->recv_dst; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); + memcpy(&cb_params.value, val, length); } btc_ble_mesh_config_server_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index bfc8d1978b..d8ed82f68e 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -361,6 +361,11 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_ LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GENERIC_CLIENT; msg.act = act; @@ -684,6 +689,11 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_ LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GENERIC_SERVER; msg.act = act; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index 63cdb863c8..c0db2bcd68 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -229,6 +229,11 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_HEALTH_CLIENT; msg.act = act; @@ -545,6 +550,11 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_HEALTH_SERVER; msg.act = act; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index d409fd9e7c..050d391ca1 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -205,6 +205,11 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_LIGHTING_CLIENT; msg.act = act; @@ -496,6 +501,11 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_LIGHTING_SERVER; msg.act = act; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 44a123ec29..14df733532 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -349,13 +349,35 @@ static void btc_ble_mesh_model_free_req_data(btc_msg_t *msg) } } +static bt_status_t btc_ble_mesh_model_callback(esp_ble_mesh_model_cb_param_t *param, uint8_t act) +{ + btc_msg_t msg = {0}; + bt_status_t ret; + + LOG_DEBUG("%s", __func__); + + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_MODEL)) { + return BT_STATUS_SUCCESS; + } + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_MODEL; + msg.act = act; + + ret = btc_transfer_context(&msg, param, + sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("%s, btc_transfer_context failed", __func__); + } + return ret; +} + static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; mesh_param.model_operation.opcode = ctx->recv_op; mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model; @@ -363,15 +385,7 @@ static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model, mesh_param.model_operation.length = buf->len; mesh_param.model_operation.msg = buf->data; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_MODEL_OPERATION_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_OPERATION_EVT); return; } @@ -381,8 +395,6 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model, { esp_ble_mesh_model_cb_param_t mesh_param = {0}; bt_mesh_client_node_t *node = NULL; - btc_msg_t msg = {0}; - bt_status_t ret; if (!model || !model->user_data || !ctx || !buf) { LOG_ERROR("%s, Invalid parameter", __func__); @@ -391,132 +403,142 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model, bt_mesh_client_model_lock(); - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false); if (node == NULL) { - msg.act = ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT; mesh_param.client_recv_publish_msg.opcode = ctx->recv_op; mesh_param.client_recv_publish_msg.model = (esp_ble_mesh_model_t *)model; mesh_param.client_recv_publish_msg.ctx = (esp_ble_mesh_msg_ctx_t *)ctx; mesh_param.client_recv_publish_msg.length = buf->len; mesh_param.client_recv_publish_msg.msg = buf->data; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT); } else { - msg.act = ESP_BLE_MESH_MODEL_OPERATION_EVT; mesh_param.model_operation.opcode = ctx->recv_op; mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model; mesh_param.model_operation.ctx = (esp_ble_mesh_msg_ctx_t *)ctx; mesh_param.model_operation.length = buf->len; mesh_param.model_operation.msg = buf->data; if (!k_delayed_work_free(&node->timer)) { - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_OPERATION_EVT); // Don't forget to release the node at the end. bt_mesh_client_free_node(node); - } else { - ret = BT_STATUS_SUCCESS; } } bt_mesh_client_model_unlock(); + return; +} - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s, btc_transfer_context failed", __func__); +static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work) +{ + esp_ble_mesh_model_cb_param_t mesh_param = {0}; + struct k_delayed_work *timer = NULL; + bt_mesh_client_node_t *node = NULL; + + bt_mesh_client_model_lock(); + + timer = CONTAINER_OF(work, struct k_delayed_work, work); + + if (timer && !k_delayed_work_free(timer)) { + node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); + if (node) { + mesh_param.client_send_timeout.opcode = node->opcode; + mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model; + mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx; + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT); + // Don't forget to release the node at the end. + bt_mesh_client_free_node(node); + } } + + bt_mesh_client_model_unlock(); return; } static void btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t *model, esp_ble_mesh_msg_ctx_t *ctx, u32_t opcode, int err) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; mesh_param.model_send_comp.err_code = err; mesh_param.model_send_comp.opcode = opcode; mesh_param.model_send_comp.model = model; mesh_param.model_send_comp.ctx = ctx; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_MODEL_SEND_COMP_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_SEND_COMP_EVT); return; } static void btc_ble_mesh_model_publish_comp_cb(esp_ble_mesh_model_t *model, int err) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; mesh_param.model_publish_comp.err_code = err; mesh_param.model_publish_comp.model = model; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT); return; } +static int btc_ble_mesh_model_publish_update(struct bt_mesh_model *mod) +{ + esp_ble_mesh_model_cb_param_t mesh_param = {0}; + bt_status_t ret; + + LOG_DEBUG("%s", __func__); + + mesh_param.model_publish_update.model = (esp_ble_mesh_model_t *)mod; + + ret = btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; +} + static void btc_ble_mesh_server_model_update_state_comp_cb(esp_ble_mesh_model_t *model, esp_ble_mesh_server_state_type_t type, int err) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; mesh_param.server_model_update_state.err_code = err; mesh_param.server_model_update_state.model = model; mesh_param.server_model_update_state.type = type; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_SERVER_MODEL_UPDATE_STATE_COMP_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_SERVER_MODEL_UPDATE_STATE_COMP_EVT); return; } +static bt_status_t btc_ble_mesh_prov_callback(esp_ble_mesh_prov_cb_param_t *param, uint8_t act) +{ + btc_msg_t msg = {0}; + bt_status_t ret; + + LOG_DEBUG("%s", __func__); + + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_PROV)) { + return BT_STATUS_SUCCESS; + } + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_PROV; + msg.act = act; + + ret = btc_transfer_context(&msg, param, sizeof(esp_ble_mesh_prov_cb_param_t), NULL); + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("%s, btc_transfer_context failed", __func__); + } + return ret; +} + #if CONFIG_BLE_MESH_NODE static void btc_ble_mesh_oob_pub_key_cb(void) { - btc_msg_t msg = {0}; - LOG_DEBUG("%s", __func__); - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_OOB_PUB_KEY_EVT; - - if (btc_transfer_context(&msg, NULL, 0, NULL) != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(NULL, ESP_BLE_MESH_NODE_PROV_OOB_PUB_KEY_EVT); return; } static int btc_ble_mesh_output_number_cb(bt_mesh_output_action_t act, u32_t num) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; bt_status_t ret; LOG_DEBUG("%s", __func__); @@ -524,46 +546,26 @@ static int btc_ble_mesh_output_number_cb(bt_mesh_output_action_t act, u32_t num) mesh_param.node_prov_output_num.action = (esp_ble_mesh_output_action_t)act; mesh_param.node_prov_output_num.number = num; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_OUTPUT_NUMBER_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; + ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_OUTPUT_NUMBER_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; } static int btc_ble_mesh_output_string_cb(const char *str) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; bt_status_t ret; LOG_DEBUG("%s", __func__); strncpy(mesh_param.node_prov_output_str.string, str, strlen(str)); - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_OUTPUT_STRING_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; + ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_OUTPUT_STRING_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; } static int btc_ble_mesh_input_cb(bt_mesh_input_action_t act, u8_t size) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; bt_status_t ret; LOG_DEBUG("%s", __func__); @@ -571,68 +573,37 @@ static int btc_ble_mesh_input_cb(bt_mesh_input_action_t act, u8_t size) mesh_param.node_prov_input.action = (esp_ble_mesh_input_action_t)act; mesh_param.node_prov_input.size = size; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_INPUT_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; + ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_INPUT_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; } static void btc_ble_mesh_link_open_cb(bt_mesh_prov_bearer_t bearer) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; LOG_DEBUG("%s", __func__); mesh_param.node_prov_link_open.bearer = (esp_ble_mesh_prov_bearer_t)bearer; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_LINK_OPEN_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_LINK_OPEN_EVT); return; } static void btc_ble_mesh_link_close_cb(bt_mesh_prov_bearer_t bearer) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; LOG_DEBUG("%s", __func__); mesh_param.node_prov_link_close.bearer = (esp_ble_mesh_prov_bearer_t)bearer; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_LINK_CLOSE_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_LINK_CLOSE_EVT); return; } static void btc_ble_mesh_complete_cb(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; LOG_DEBUG("%s", __func__); @@ -642,42 +613,181 @@ static void btc_ble_mesh_complete_cb(u16_t net_idx, const u8_t net_key[16], u16_ mesh_param.node_prov_complete.flags = flags; mesh_param.node_prov_complete.iv_index = iv_index; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_COMPLETE_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_COMPLETE_EVT); return; } static void btc_ble_mesh_reset_cb(void) { - btc_msg_t msg = {0}; + LOG_DEBUG("%s", __func__); + + btc_ble_mesh_prov_callback(NULL, ESP_BLE_MESH_NODE_PROV_RESET_EVT); + return; +} +#endif /* CONFIG_BLE_MESH_NODE */ + +static void btc_ble_mesh_prov_register_complete_cb(int err_code) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + + mesh_param.prov_register_comp.err_code = err_code; + + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROV_REGISTER_COMP_EVT); + return; +} + +static void btc_ble_mesh_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_t act) +{ + LOG_DEBUG("%s", __func__); + + btc_ble_mesh_prov_callback(param, act); + return; +} + +#if CONFIG_BLE_MESH_PROVISIONER +static void btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb( + const u8_t addr[6], const u8_t addr_type, + const u8_t adv_type, const u8_t dev_uuid[16], + u16_t oob_info, bt_mesh_prov_bearer_t bearer) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + + if (addr == NULL || dev_uuid == NULL || + (bearer != BLE_MESH_PROV_ADV && bearer != BLE_MESH_PROV_GATT)) { + LOG_ERROR("%s, Invalid parameter", __func__); + return; + } + + memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.dev_uuid, dev_uuid, 16); + memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.addr, addr, BLE_MESH_ADDR_LEN); + mesh_param.provisioner_recv_unprov_adv_pkt.addr_type = addr_type; + mesh_param.provisioner_recv_unprov_adv_pkt.oob_info = oob_info; + mesh_param.provisioner_recv_unprov_adv_pkt.adv_type = adv_type; + mesh_param.provisioner_recv_unprov_adv_pkt.bearer = bearer; + + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT); + return; +} + +static int btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; bt_status_t ret; LOG_DEBUG("%s", __func__); - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_NODE_PROV_RESET_EVT; - ret = btc_transfer_context(&msg, NULL, 0, NULL); + mesh_param.provisioner_prov_read_oob_pub_key.link_idx = link_idx; - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); + ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_READ_OOB_PUB_KEY_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; +} + +static int btc_ble_mesh_provisioner_prov_input_cb(u8_t method, + bt_mesh_output_action_t act, u8_t size, u8_t link_idx) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + bt_status_t ret; + + LOG_DEBUG("%s", __func__); + + mesh_param.provisioner_prov_input.method = (esp_ble_mesh_oob_method_t)method; + mesh_param.provisioner_prov_input.action = (esp_ble_mesh_output_action_t)act; + mesh_param.provisioner_prov_input.size = size; + mesh_param.provisioner_prov_input.link_idx = link_idx; + + ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_INPUT_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; +} + +static int btc_ble_mesh_provisioner_prov_output_cb(u8_t method, + bt_mesh_input_action_t act, void *data, u8_t size, u8_t link_idx) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + bt_status_t ret; + + LOG_DEBUG("%s", __func__); + + mesh_param.provisioner_prov_output.method = (esp_ble_mesh_oob_method_t)method; + mesh_param.provisioner_prov_output.action = (esp_ble_mesh_input_action_t)act; + mesh_param.provisioner_prov_output.size = size; + mesh_param.provisioner_prov_output.link_idx = link_idx; + if (act == BLE_MESH_ENTER_STRING) { + strncpy(mesh_param.provisioner_prov_output.string, (char *)data, size); + } else { + mesh_param.provisioner_prov_output.number = sys_get_le32((u8_t *)data); } + + ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_OUTPUT_EVT); + return (ret == BT_STATUS_SUCCESS) ? 0 : -1; +} + +static void btc_ble_mesh_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + + mesh_param.provisioner_prov_link_open.bearer = (esp_ble_mesh_prov_bearer_t)bearer; + + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT); return; } +static void btc_ble_mesh_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, u8_t reason) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + + mesh_param.provisioner_prov_link_close.bearer = (esp_ble_mesh_prov_bearer_t)bearer; + mesh_param.provisioner_prov_link_close.reason = reason; + + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT); + return; +} + +static void btc_ble_mesh_provisioner_prov_complete_cb( + int node_idx, const u8_t device_uuid[16], + u16_t unicast_addr, u8_t element_num, + u16_t netkey_idx) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + + mesh_param.provisioner_prov_complete.node_idx = node_idx; + mesh_param.provisioner_prov_complete.unicast_addr = unicast_addr; + mesh_param.provisioner_prov_complete.element_num = element_num; + mesh_param.provisioner_prov_complete.netkey_idx = netkey_idx; + memcpy(mesh_param.provisioner_prov_complete.device_uuid, device_uuid, sizeof(esp_ble_mesh_octet16_t)); + + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT); + return; +} +#endif /* CONFIG_BLE_MESH_PROVISIONER */ + +static void btc_ble_mesh_heartbeat_msg_recv_cb(u8_t hops, u16_t feature) +{ + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + + mesh_param.heartbeat_msg_recv.hops = hops; + mesh_param.heartbeat_msg_recv.feature = feature; + + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT); + return; +} + +#if CONFIG_BLE_MESH_NODE #if CONFIG_BLE_MESH_LOW_POWER static void btc_ble_mesh_lpn_cb(u16_t friend_addr, bool established) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; u8_t act; LOG_DEBUG("%s", __func__); @@ -690,15 +800,7 @@ static void btc_ble_mesh_lpn_cb(u16_t friend_addr, bool established) act = ESP_BLE_MESH_LPN_FRIENDSHIP_TERMINATE_EVT; } - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = act; - - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, act); return; } #endif /* CONFIG_BLE_MESH_LOW_POWER */ @@ -707,8 +809,6 @@ static void btc_ble_mesh_lpn_cb(u16_t friend_addr, bool established) void btc_ble_mesh_friend_cb(bool establish, u16_t lpn_addr, u8_t reason) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; u8_t act; LOG_DEBUG("%s", __func__); @@ -727,348 +827,17 @@ void btc_ble_mesh_friend_cb(bool establish, u16_t lpn_addr, u8_t reason) act = ESP_BLE_MESH_FRIEND_FRIENDSHIP_TERMINATE_EVT; } - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = act; - - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, act); return; } #endif /* CONFIG_BLE_MESH_FRIEND */ - #endif /* CONFIG_BLE_MESH_NODE */ -static void btc_ble_mesh_prov_register_complete_cb(int err_code) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.prov_register_comp.err_code = err_code; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROV_REGISTER_COMP_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} - -static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work) -{ - esp_ble_mesh_model_cb_param_t mesh_param = {0}; - struct k_delayed_work *timer = NULL; - bt_mesh_client_node_t *node = NULL; - btc_msg_t msg = {0}; - bt_status_t ret; - - bt_mesh_client_model_lock(); - - timer = CONTAINER_OF(work, struct k_delayed_work, work); - - if (timer && !k_delayed_work_free(timer)) { - node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); - if (node) { - mesh_param.client_send_timeout.opcode = node->opcode; - mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model; - mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT; - - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - - // Don't forget to release the node at the end. - bt_mesh_client_free_node(node); - } - } - - bt_mesh_client_model_unlock(); - - return; -} - -static int btc_ble_mesh_model_publish_update(struct bt_mesh_model *mod) -{ - esp_ble_mesh_model_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.model_publish_update.model = (esp_ble_mesh_model_t *)mod; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_MODEL; - msg.act = ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_model_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; -} - -static void btc_ble_mesh_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_t act) -{ - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = act; - ret = btc_transfer_context(&msg, param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} - -#if CONFIG_BLE_MESH_PROVISIONER -static void btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb( - const u8_t addr[6], const u8_t addr_type, - const u8_t adv_type, const u8_t dev_uuid[16], - u16_t oob_info, bt_mesh_prov_bearer_t bearer) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - if (addr == NULL || dev_uuid == NULL || - (bearer != BLE_MESH_PROV_ADV && bearer != BLE_MESH_PROV_GATT)) { - LOG_ERROR("%s, Invalid parameter", __func__); - return; - } - - memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.dev_uuid, dev_uuid, 16); - memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.addr, addr, BLE_MESH_ADDR_LEN); - mesh_param.provisioner_recv_unprov_adv_pkt.addr_type = addr_type; - mesh_param.provisioner_recv_unprov_adv_pkt.oob_info = oob_info; - mesh_param.provisioner_recv_unprov_adv_pkt.adv_type = adv_type; - mesh_param.provisioner_recv_unprov_adv_pkt.bearer = bearer; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} - -static int btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.provisioner_prov_read_oob_pub_key.link_idx = link_idx; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_PROV_READ_OOB_PUB_KEY_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; -} - -static int btc_ble_mesh_provisioner_prov_input_cb(u8_t method, - bt_mesh_output_action_t act, u8_t size, u8_t link_idx) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.provisioner_prov_input.method = (esp_ble_mesh_oob_method_t)method; - mesh_param.provisioner_prov_input.action = (esp_ble_mesh_output_action_t)act; - mesh_param.provisioner_prov_input.size = size; - mesh_param.provisioner_prov_input.link_idx = link_idx; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_PROV_INPUT_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; -} - -static int btc_ble_mesh_provisioner_prov_output_cb(u8_t method, - bt_mesh_input_action_t act, void *data, u8_t size, u8_t link_idx) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.provisioner_prov_output.method = (esp_ble_mesh_oob_method_t)method; - mesh_param.provisioner_prov_output.action = (esp_ble_mesh_input_action_t)act; - mesh_param.provisioner_prov_output.size = size; - mesh_param.provisioner_prov_output.link_idx = link_idx; - if (act == BLE_MESH_ENTER_STRING) { - strncpy(mesh_param.provisioner_prov_output.string, (char *)data, size); - } else { - mesh_param.provisioner_prov_output.number = sys_get_le32((u8_t *)data); - } - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_PROV_OUTPUT_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - return -1; - } - return 0; -} - -static void btc_ble_mesh_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.provisioner_prov_link_open.bearer = (esp_ble_mesh_prov_bearer_t)bearer; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} - -static void btc_ble_mesh_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, u8_t reason) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.provisioner_prov_link_close.bearer = (esp_ble_mesh_prov_bearer_t)bearer; - mesh_param.provisioner_prov_link_close.reason = reason; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} - -static void btc_ble_mesh_provisioner_prov_complete_cb( - int node_idx, const u8_t device_uuid[16], - u16_t unicast_addr, u8_t element_num, - u16_t netkey_idx) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.provisioner_prov_complete.node_idx = node_idx; - mesh_param.provisioner_prov_complete.unicast_addr = unicast_addr; - mesh_param.provisioner_prov_complete.element_num = element_num; - mesh_param.provisioner_prov_complete.netkey_idx = netkey_idx; - memcpy(mesh_param.provisioner_prov_complete.device_uuid, device_uuid, sizeof(esp_ble_mesh_octet16_t)); - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} -#endif /* CONFIG_BLE_MESH_PROVISIONER */ - -static void btc_ble_mesh_heartbeat_msg_recv_cb(u8_t hops, u16_t feature) -{ - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; - - LOG_DEBUG("%s", __func__); - - mesh_param.heartbeat_msg_recv.hops = hops; - mesh_param.heartbeat_msg_recv.feature = feature; - - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } - return; -} - #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT static void btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t *addr, u8_t type, bt_mesh_proxy_adv_ctx_t *ctx) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; if (!addr || !ctx || type != BLE_MESH_PROXY_ADV_NET_ID) { LOG_ERROR("%s, Invalid parameter", __func__); @@ -1082,15 +851,7 @@ static void btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t *addr, mesh_param.proxy_client_recv_adv_pkt.net_idx = ctx->net_id.net_idx; memcpy(mesh_param.proxy_client_recv_adv_pkt.net_id, ctx->net_id.net_id, 8); - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROXY_CLIENT_RECV_ADV_PKT_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_RECV_ADV_PKT_EVT); return; } @@ -1098,8 +859,6 @@ static void btc_ble_mesh_proxy_client_connect_cb(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; if (!addr || conn_handle >= BLE_MESH_MAX_CONN) { LOG_ERROR("%s, Invalid parameter", __func__); @@ -1113,15 +872,7 @@ static void btc_ble_mesh_proxy_client_connect_cb(const bt_mesh_addr_t *addr, mesh_param.proxy_client_connected.conn_handle = conn_handle; mesh_param.proxy_client_connected.net_idx = net_idx; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROXY_CLIENT_CONNECTED_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_CONNECTED_EVT); return; } @@ -1129,8 +880,6 @@ static void btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx, u8_t reason) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; if (!addr || conn_handle >= BLE_MESH_MAX_CONN) { LOG_ERROR("%s, Invalid parameter", __func__); @@ -1145,15 +894,7 @@ static void btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t *addr, mesh_param.proxy_client_disconnected.net_idx = net_idx; mesh_param.proxy_client_disconnected.reason = reason; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROXY_CLIENT_DISCONNECTED_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_DISCONNECTED_EVT); return; } @@ -1161,8 +902,6 @@ static void btc_ble_mesh_proxy_client_filter_status_recv_cb(u8_t conn_handle, u16_t src, u16_t net_idx, u8_t filter_type, u16_t list_size) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; - btc_msg_t msg = {0}; - bt_status_t ret; if (conn_handle >= BLE_MESH_MAX_CONN) { LOG_ERROR("%s, Invalid parameter", __func__); @@ -1177,15 +916,7 @@ static void btc_ble_mesh_proxy_client_filter_status_recv_cb(u8_t conn_handle, mesh_param.proxy_client_recv_filter_status.filter_type = filter_type; mesh_param.proxy_client_recv_filter_status.list_size = list_size; - msg.sig = BTC_SIG_API_CB; - msg.pid = BTC_PID_PROV; - msg.act = ESP_BLE_MESH_PROXY_CLIENT_RECV_FILTER_STATUS_EVT; - ret = btc_transfer_context(&msg, &mesh_param, - sizeof(esp_ble_mesh_prov_cb_param_t), NULL); - - if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed", __func__); - } + btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_RECV_FILTER_STATUS_EVT); return; } #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index 2312bc2198..6104365384 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -450,6 +450,11 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_SENSOR_CLIENT; msg.act = act; @@ -823,6 +828,11 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_SENSOR_SERVER; msg.act = act; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index f1f4d7a526..9b39b3b2d6 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -207,6 +207,11 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_TIME_SCENE_CLIENT; msg.act = act; @@ -400,6 +405,11 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv LOG_DEBUG("%s", __func__); + /* If corresponding callback is not registered, event will not be posted. */ + if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) { + return; + } + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_TIME_SCENE_SERVER; msg.act = act; diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h index dc81116efe..6070e76365 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h @@ -63,7 +63,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg); typedef enum { - BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG, + BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX, } btc_ble_mesh_config_server_evt_t; diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c index f210cd5be5..7358d06763 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -472,10 +472,14 @@ static void app_key_add(struct bt_mesh_model *model, return; } -#if defined(CONFIG_BLE_MESH_FAST_PROV) - bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_RECV_MSG, - model, ctx, (u8_t *)&key_app_idx, sizeof(u16_t)); -#endif + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_appkey_add.net_idx = key_net_idx; + change.cfg_appkey_add.app_idx = key_app_idx; + memcpy(change.cfg_appkey_add.app_key, buf->data, 16); + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } static void app_key_update(struct bt_mesh_model *model, @@ -501,6 +505,15 @@ static void app_key_update(struct bt_mesh_model *model, if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("%s, Unable to send Config AppKey Status", __func__); } + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_appkey_update.net_idx = key_net_idx; + change.cfg_appkey_update.app_idx = key_app_idx; + memcpy(change.cfg_appkey_update.app_key, buf->data, 16); + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } struct unbind_data { @@ -577,6 +590,14 @@ send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("%s, Unable to send Config AppKey Status", __func__); } + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_appkey_delete.net_idx = key_net_idx; + change.cfg_appkey_delete.app_idx = key_app_idx; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } /* Index list length: 3 bytes for every pair and 2 bytes for an odd idx */ @@ -1124,6 +1145,21 @@ static void mod_pub_set(struct bt_mesh_model *model, send_status: send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, status, mod_id); + + if (status == STATUS_SUCCESS && mod->pub) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_mod_pub_set.elem_addr = elem_addr; + change.cfg_mod_pub_set.pub_addr = mod->pub->addr; + change.cfg_mod_pub_set.app_idx = mod->pub->key; + change.cfg_mod_pub_set.cred_flag = mod->pub->cred; + change.cfg_mod_pub_set.ttl = mod->pub->ttl; + change.cfg_mod_pub_set.period = mod->pub->period; + change.cfg_mod_pub_set.transmit = mod->pub->retransmit; + change.cfg_mod_pub_set.cid = vnd ? mod->vnd.company : 0xFFFF; + change.cfg_mod_pub_set.mod_id = vnd ? mod->vnd.id : mod->id; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } #if CONFIG_BLE_MESH_LABEL_COUNT > 0 @@ -1447,6 +1483,16 @@ static void mod_sub_add(struct bt_mesh_model *model, send_status: send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, mod_id, vnd); + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_mod_sub_add.elem_addr = elem_addr; + change.cfg_mod_sub_add.sub_addr = sub_addr; + change.cfg_mod_sub_add.cid = vnd ? mod->vnd.company : 0xFFFF; + change.cfg_mod_sub_add.mod_id = vnd ? mod->vnd.id : mod->id; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } static void mod_sub_del(struct bt_mesh_model *model, @@ -1513,6 +1559,16 @@ static void mod_sub_del(struct bt_mesh_model *model, send_status: send_mod_sub_status(model, ctx, status, elem_addr, sub_addr, mod_id, vnd); + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_mod_sub_delete.elem_addr = elem_addr; + change.cfg_mod_sub_delete.sub_addr = sub_addr; + change.cfg_mod_sub_delete.cid = vnd ? mod->vnd.company : 0xFFFF; + change.cfg_mod_sub_delete.mod_id = vnd ? mod->vnd.id : mod->id; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } static void mod_sub_overwrite(struct bt_mesh_model *model, @@ -2177,6 +2233,12 @@ static void net_key_add(struct bt_mesh_model *model, } send_net_key_status(model, ctx, idx, STATUS_SUCCESS); + + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_netkey_add.net_idx = sub->net_idx; + memcpy(change.cfg_netkey_add.net_key, sub->keys[0].net, 16); + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); } static void net_key_update(struct bt_mesh_model *model, @@ -2246,6 +2308,12 @@ static void net_key_update(struct bt_mesh_model *model, bt_mesh_net_beacon_update(sub); send_net_key_status(model, ctx, idx, STATUS_SUCCESS); + + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_netkey_update.net_idx = sub->net_idx; + memcpy(change.cfg_netkey_update.net_key, sub->keys[1].net, 16); + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); } static void hb_pub_disable(struct bt_mesh_cfg_srv *cfg) @@ -2298,6 +2366,13 @@ static void net_key_del(struct bt_mesh_model *model, send_status: send_net_key_status(model, ctx, del_idx, status); + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_netkey_delete.net_idx = sub->net_idx; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } static void net_key_get(struct bt_mesh_model *model, @@ -2503,6 +2578,16 @@ send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("%s, Unable to send Config Model App Bind Status", __func__); } + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_mod_app_bind.elem_addr = elem_addr; + change.cfg_mod_app_bind.app_idx = key_app_idx; + change.cfg_mod_app_bind.cid = vnd ? mod->vnd.company : 0xFFFF; + change.cfg_mod_app_bind.mod_id = vnd ? mod->vnd.id : mod->id; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } static void mod_app_unbind(struct bt_mesh_model *model, @@ -2549,6 +2634,16 @@ send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { BT_ERR("%s, Unable to send Config Model App Unbind Status", __func__); } + + if (status == STATUS_SUCCESS) { + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_mod_app_unbind.elem_addr = elem_addr; + change.cfg_mod_app_unbind.app_idx = key_app_idx; + change.cfg_mod_app_unbind.cid = vnd ? mod->vnd.company : 0xFFFF; + change.cfg_mod_app_unbind.mod_id = vnd ? mod->vnd.id : mod->id; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); + } } #define KEY_LIST_LEN (CONFIG_BLE_MESH_MODEL_KEY_COUNT * 2) @@ -2857,6 +2952,12 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, } send_krp_status(model, ctx, idx, sub->kr_phase, STATUS_SUCCESS); + + bt_mesh_cfg_server_state_change_t change = {0}; + change.cfg_kr_phase_set.net_idx = idx; + change.cfg_kr_phase_set.kr_phase = phase; + bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE, + model, ctx, (const u8_t *)&change, sizeof(change)); } static u8_t hb_log(u16_t val) diff --git a/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h b/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h index d5f77e7b01..91f07fa4b5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h @@ -65,6 +65,149 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_SRV, \ bt_mesh_cfg_srv_op, NULL, srv_data) +typedef union { + struct { + u8_t beacon; + } cfg_beacon_set; + struct { + u8_t ttl; + } cfg_default_ttl_set; + struct { + u8_t gatt_proxy; + } cfg_gatt_proxy_set; + struct { + u8_t relay; + u8_t retransmit; + } cfg_relay_set; + struct { + u16_t elem_addr; + u16_t pub_addr; + u16_t app_idx; + bool cred_flag; + u8_t ttl; + u8_t period; + u8_t transmit; + u16_t cid; + u16_t mod_id; + } cfg_mod_pub_set; + struct { + u16_t elem_addr; + u8_t pub_addr[16]; + u16_t app_idx; + bool cred_flag; + u8_t ttl; + u8_t period; + u8_t transmit; + u16_t cid; + u16_t mod_id; + } cfg_mod_pub_va_set; + struct { + u16_t elem_addr; + u16_t sub_addr; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_add; + struct { + u16_t elem_addr; + u8_t sub_addr[16]; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_va_add; + struct { + u16_t elem_addr; + u16_t sub_addr; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_delete; + struct { + u16_t elem_addr; + u8_t sub_addr[16]; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_va_delete; + struct { + u16_t elem_addr; + u16_t sub_addr; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_overwrite; + struct { + u16_t elem_addr; + u8_t sub_addr[16]; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_va_overwrite; + struct { + u16_t elem_addr; + u16_t cid; + u16_t mod_id; + } cfg_mod_sub_delete_all; + struct { + u16_t net_idx; + u8_t net_key[16]; + } cfg_netkey_add; + struct { + u16_t net_idx; + u8_t net_key[16]; + } cfg_netkey_update; + struct { + u16_t net_idx; + } cfg_netkey_delete; + struct { + u16_t net_idx; + u16_t app_idx; + u8_t app_key[16]; + } cfg_appkey_add; + struct { + u16_t net_idx; + u16_t app_idx; + u8_t app_key[16]; + } cfg_appkey_update; + struct { + u16_t net_idx; + u16_t app_idx; + } cfg_appkey_delete; + struct { + u16_t net_idx; + u8_t identity; + } cfg_node_identity_set; + struct { + u16_t elem_addr; + u16_t app_idx; + u16_t cid; + u16_t mod_id; + } cfg_mod_app_bind; + struct { + u16_t elem_addr; + u16_t app_idx; + u16_t cid; + u16_t mod_id; + } cfg_mod_app_unbind; + struct { + u8_t frnd; + } cfg_friend_set; + struct { + u16_t net_idx; + u8_t kr_phase; + } cfg_kr_phase_set; + struct { + u16_t dst; + u8_t count; + u8_t period; + u8_t ttl; + u16_t feat; + u16_t net_idx; + } cfg_hb_pub_set; + struct { + u16_t src; + u16_t dst; + u8_t period; + } cfg_hb_sub_set; + struct { + u8_t transmit; + } cfg_net_transmit_set; +} bt_mesh_cfg_server_state_change_t; + /** * @} */ diff --git a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c index 3e854344fe..efe0e35fe2 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c @@ -149,7 +149,7 @@ static void gen_onoff_set(struct bt_mesh_model *model, } tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -327,7 +327,7 @@ static void gen_level_set(struct bt_mesh_model *model, level = (s16_t) net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -423,7 +423,7 @@ static void gen_delta_set(struct bt_mesh_model *model, delta = (s32_t)net_buf_simple_pull_le32(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -545,7 +545,7 @@ static void gen_move_set(struct bt_mesh_model *model, delta = (s16_t) net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -1090,7 +1090,7 @@ static void gen_power_level_set(struct bt_mesh_model *model, power = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/include/server_common.h b/components/bt/esp_ble_mesh/mesh_models/server/include/server_common.h index d0e1e452b1..d1a313ee73 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/include/server_common.h +++ b/components/bt/esp_ble_mesh/mesh_models/server/include/server_common.h @@ -110,6 +110,7 @@ u8_t bt_mesh_get_default_trans_time(struct bt_mesh_model *model); int bt_mesh_get_light_lc_trans_time(struct bt_mesh_model *model, u8_t *trans_time); int bt_mesh_server_get_optional(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, u8_t *trans_time, u8_t *delay, bool *optional); diff --git a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c index b3b7ab911f..9551b98773 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c @@ -236,7 +236,7 @@ static void light_lightness_set(struct bt_mesh_model *model, actual = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -348,7 +348,7 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, linear = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -774,7 +774,7 @@ static void light_ctl_set(struct bt_mesh_model *model, return; } - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -1022,7 +1022,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, return; } - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -1377,7 +1377,7 @@ static void light_hsl_set(struct bt_mesh_model *model, saturation = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -1618,7 +1618,7 @@ static void light_hsl_hue_set(struct bt_mesh_model *model, hue = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -1719,7 +1719,7 @@ static void light_hsl_sat_set(struct bt_mesh_model *model, saturation = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -1994,7 +1994,7 @@ static void light_xyl_set(struct bt_mesh_model *model, y = net_buf_simple_pull_le16(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } @@ -2434,7 +2434,7 @@ static void light_lc_light_onoff_set(struct bt_mesh_model *model, onoff = net_buf_simple_pull_u8(buf); tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/server_common.c b/components/bt/esp_ble_mesh/mesh_models/server/server_common.c index e0bf3f8df9..82d1c974da 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/server_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/server_common.c @@ -127,6 +127,7 @@ int bt_mesh_get_light_lc_trans_time(struct bt_mesh_model *model, u8_t *trans_tim } int bt_mesh_server_get_optional(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, u8_t *trans_time, u8_t *delay, bool *optional) @@ -142,6 +143,14 @@ int bt_mesh_server_get_optional(struct bt_mesh_model *model, return -EINVAL; } + /* Currently we only get optional msg info which dst is set to a unicast address */ + if (!BLE_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) { + *trans_time = 0U; + *delay = 0U; + *optional = false; + return 0; + } + /* No optional fields are available */ if (buf->len == 0x00) { if (model->id == BLE_MESH_MODEL_ID_LIGHT_LC_SRV) { @@ -193,6 +202,11 @@ bool bt_mesh_is_server_recv_last_msg(struct bt_mesh_last_msg_info *last, { *now = k_uptime_get(); + /* Currently we only compare msg info which dst is set to a unicast address */ + if (!BLE_MESH_ADDR_IS_UNICAST(dst)) { + return false; + } + if (last->tid == tid && last->src == src && last->dst == dst && (*now - last->timestamp <= K_SECONDS(6))) { return true; @@ -204,6 +218,11 @@ bool bt_mesh_is_server_recv_last_msg(struct bt_mesh_last_msg_info *last, void bt_mesh_server_update_last_msg(struct bt_mesh_last_msg_info *last, u8_t tid, u16_t src, u16_t dst, s64_t *now) { + /* Currently we only update msg info which dst is set to a unicast address */ + if (!BLE_MESH_ADDR_IS_UNICAST(dst)) { + return; + } + last->tid = tid; last->src = src; last->dst = dst; diff --git a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c index dd9ceaf008..58a4850cd9 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c @@ -620,7 +620,7 @@ static void scene_recall(struct bt_mesh_model *model, } tid = net_buf_simple_pull_u8(buf); - if (bt_mesh_server_get_optional(model, buf, &trans_time, &delay, &optional)) { + if (bt_mesh_server_get_optional(model, ctx, buf, &trans_time, &delay, &optional)) { return; } diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c index 5669fed3ca..d701a042bf 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c @@ -704,14 +704,14 @@ static void example_ble_mesh_config_server_cb(esp_ble_mesh_cfg_server_cb_event_t __func__, event, param->ctx.recv_op, param->ctx.addr); switch (event) { - case ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT: + case ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT: switch (param->ctx.recv_op) { case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD: ESP_LOGI(TAG, "Config Server get Config AppKey Add"); - err = example_handle_config_app_key_add_evt(param->status_cb.app_key_add.app_idx); + err = example_handle_config_app_key_add_evt(param->value.state_change.appkey_add.app_idx); if (err != ESP_OK) { ESP_LOGE(TAG, "%s: Failed to bind app_idx 0x%04x with non-config models", - __func__, param->status_cb.app_key_add.app_idx); + __func__, param->value.state_change.appkey_add.app_idx); return; } break; diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c index 9f8d7585d5..eb60947fbb 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c @@ -716,14 +716,14 @@ static void example_ble_mesh_config_server_cb(esp_ble_mesh_cfg_server_cb_event_t __func__, event, param->ctx.recv_op, param->ctx.addr); switch (event) { - case ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT: + case ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT: switch (param->ctx.recv_op) { case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD: ESP_LOGI(TAG, "Config Server get Config AppKey Add"); - err = example_handle_config_app_key_add_evt(param->status_cb.app_key_add.app_idx); + err = example_handle_config_app_key_add_evt(param->value.state_change.appkey_add.app_idx); if (err != ESP_OK) { ESP_LOGE(TAG, "%s: Failed to bind app_idx 0x%04x with non-config models", - __func__, param->status_cb.app_key_add.app_idx); + __func__, param->value.state_change.appkey_add.app_idx); return; } break;