From dfd0cd5f3ee8f33e1182d21f24132e6573a6830f Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 28 Jun 2020 15:28:22 +0800 Subject: [PATCH] ble_mesh: stack: Update client model msg send --- .../btc/btc_ble_mesh_config_model.c | 138 ++-- .../btc/btc_ble_mesh_health_model.c | 66 +- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 19 +- .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 721 ++++++------------ .../bt/esp_ble_mesh/mesh_core/health_cli.c | 102 +-- .../esp_ble_mesh/mesh_core/include/cfg_cli.h | 149 ++-- .../mesh_core/include/health_cli.h | 16 +- .../mesh_models/client/client_common.c | 42 +- .../mesh_models/client/generic_client.c | 8 +- .../client/include/client_common.h | 10 +- .../mesh_models/client/lighting_client.c | 8 +- .../mesh_models/client/sensor_client.c | 4 +- .../mesh_models/client/time_scene_client.c | 8 +- 13 files changed, 498 insertions(+), 793 deletions(-) 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 c9c48e7138..1d18f4fb65 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 @@ -20,8 +20,6 @@ #include "cfg_cli.h" #include "esp_ble_mesh_config_model_api.h" -extern s32_t config_msg_timeout; - /* Configuration Client Model related functions */ static inline void btc_ble_mesh_config_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event, @@ -383,7 +381,7 @@ void btc_ble_mesh_config_client_publish_callback(u32_t opcode, struct bt_mesh_mo static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_get_state_t *get) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); @@ -410,63 +408,64 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param break; } - ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = BLE_MESH_KEY_DEV; - ctx.addr = params->ctx.addr; - ctx.send_rel = params->ctx.send_rel; - ctx.send_ttl = params->ctx.send_ttl; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = BLE_MESH_KEY_DEV; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - config_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_GET: - return bt_mesh_cfg_beacon_get(&ctx); + return bt_mesh_cfg_beacon_get(¶m); case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET: - return bt_mesh_cfg_ttl_get(&ctx); + return bt_mesh_cfg_ttl_get(¶m); case ESP_BLE_MESH_MODEL_OP_FRIEND_GET: - return bt_mesh_cfg_friend_get(&ctx); + return bt_mesh_cfg_friend_get(¶m); case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET: - return bt_mesh_cfg_gatt_proxy_get(&ctx); + return bt_mesh_cfg_gatt_proxy_get(¶m); case ESP_BLE_MESH_MODEL_OP_RELAY_GET: - return bt_mesh_cfg_relay_get(&ctx); + return bt_mesh_cfg_relay_get(¶m); case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET: - return bt_mesh_cfg_mod_pub_get(&ctx, get->model_pub_get.element_addr, + return bt_mesh_cfg_mod_pub_get(¶m, get->model_pub_get.element_addr, get->model_pub_get.model_id, get->model_pub_get.company_id); case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET: - return bt_mesh_cfg_hb_pub_get(&ctx); + return bt_mesh_cfg_hb_pub_get(¶m); case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET: - return bt_mesh_cfg_hb_sub_get(&ctx); + return bt_mesh_cfg_hb_sub_get(¶m); case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: - return bt_mesh_cfg_comp_data_get(&ctx, get->comp_data_get.page); + return bt_mesh_cfg_comp_data_get(¶m, get->comp_data_get.page); case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET: - return bt_mesh_cfg_mod_sub_get(&ctx, get->sig_model_sub_get.element_addr, + return bt_mesh_cfg_mod_sub_get(¶m, get->sig_model_sub_get.element_addr, get->sig_model_sub_get.model_id); case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET: - return bt_mesh_cfg_mod_sub_get_vnd(&ctx, get->vnd_model_sub_get.element_addr, + return bt_mesh_cfg_mod_sub_get_vnd(¶m, get->vnd_model_sub_get.element_addr, get->vnd_model_sub_get.model_id, get->vnd_model_sub_get.company_id); case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET: - return bt_mesh_cfg_net_key_get(&ctx); + return bt_mesh_cfg_net_key_get(¶m); case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET: - return bt_mesh_cfg_app_key_get(&ctx, get->app_key_get.net_idx); + return bt_mesh_cfg_app_key_get(¶m, get->app_key_get.net_idx); case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET: - return bt_mesh_cfg_node_identity_get(&ctx, get->node_identity_get.net_idx); + return bt_mesh_cfg_node_identity_get(¶m, get->node_identity_get.net_idx); case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET: - return bt_mesh_cfg_mod_app_get(&ctx, get->sig_model_app_get.element_addr, + return bt_mesh_cfg_mod_app_get(¶m, get->sig_model_app_get.element_addr, get->sig_model_app_get.model_id); case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET: - return bt_mesh_cfg_mod_app_get_vnd(&ctx, get->vnd_model_app_get.element_addr, + return bt_mesh_cfg_mod_app_get_vnd(¶m, get->vnd_model_app_get.element_addr, get->vnd_model_app_get.model_id, get->vnd_model_app_get.company_id); case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET: - return bt_mesh_cfg_kr_phase_get(&ctx, get->kr_phase_get.net_idx); + return bt_mesh_cfg_kr_phase_get(¶m, get->kr_phase_get.net_idx); case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET: - return bt_mesh_cfg_lpn_timeout_get(&ctx, get->lpn_pollto_get.lpn_addr); + return bt_mesh_cfg_lpn_timeout_get(¶m, get->lpn_pollto_get.lpn_addr); case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET: - return bt_mesh_cfg_net_transmit_get(&ctx); + return bt_mesh_cfg_net_transmit_get(¶m); default: - BT_ERR("Invalid Configuration Get opcode 0x%04x", params->opcode); + BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode); return -EINVAL; } @@ -476,7 +475,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_set_state_t *set) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); @@ -488,35 +487,36 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param return -EINVAL; } - ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = BLE_MESH_KEY_DEV; - ctx.addr = params->ctx.addr; - ctx.send_rel = params->ctx.send_rel; - ctx.send_ttl = params->ctx.send_ttl; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = BLE_MESH_KEY_DEV; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - config_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_SET: - return bt_mesh_cfg_beacon_set(&ctx, set->beacon_set.beacon); + return bt_mesh_cfg_beacon_set(¶m, set->beacon_set.beacon); case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET: - return bt_mesh_cfg_ttl_set(&ctx, set->default_ttl_set.ttl); + return bt_mesh_cfg_ttl_set(¶m, set->default_ttl_set.ttl); case ESP_BLE_MESH_MODEL_OP_FRIEND_SET: - return bt_mesh_cfg_friend_set(&ctx, set->friend_set.friend_state); + return bt_mesh_cfg_friend_set(¶m, set->friend_set.friend_state); case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET: - return bt_mesh_cfg_gatt_proxy_set(&ctx, set->gatt_proxy_set.gatt_proxy); + return bt_mesh_cfg_gatt_proxy_set(¶m, set->gatt_proxy_set.gatt_proxy); case ESP_BLE_MESH_MODEL_OP_RELAY_SET: - return bt_mesh_cfg_relay_set(&ctx, set->relay_set.relay, + return bt_mesh_cfg_relay_set(¶m, set->relay_set.relay, set->relay_set.relay_retransmit); case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD: - return bt_mesh_cfg_net_key_add(&ctx, set->net_key_add.net_idx, + return bt_mesh_cfg_net_key_add(¶m, set->net_key_add.net_idx, &set->net_key_add.net_key[0]); case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD: - return bt_mesh_cfg_app_key_add(&ctx, set->app_key_add.net_idx, + return bt_mesh_cfg_app_key_add(¶m, set->app_key_add.net_idx, set->app_key_add.app_idx, &set->app_key_add.app_key[0]); case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND: - return bt_mesh_cfg_mod_app_bind(&ctx, set->model_app_bind.element_addr, + return bt_mesh_cfg_mod_app_bind(¶m, set->model_app_bind.element_addr, set->model_app_bind.model_app_idx, set->model_app_bind.model_id, set->model_app_bind.company_id); @@ -529,46 +529,46 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param .period = set->model_pub_set.publish_period, .transmit = set->model_pub_set.publish_retransmit, }; - return bt_mesh_cfg_mod_pub_set(&ctx, set->model_pub_set.element_addr, + return bt_mesh_cfg_mod_pub_set(¶m, set->model_pub_set.element_addr, set->model_pub_set.model_id, set->model_pub_set.company_id, &model_pub); } case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD: - return bt_mesh_cfg_mod_sub_add(&ctx, set->model_sub_add.element_addr, + return bt_mesh_cfg_mod_sub_add(¶m, set->model_sub_add.element_addr, set->model_sub_add.sub_addr, set->model_sub_add.model_id, set->model_sub_add.company_id); case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE: - return bt_mesh_cfg_mod_sub_del(&ctx, set->model_sub_delete.element_addr, + return bt_mesh_cfg_mod_sub_del(¶m, set->model_sub_delete.element_addr, set->model_sub_delete.sub_addr, set->model_sub_delete.model_id, set->model_sub_delete.company_id); case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE: - return bt_mesh_cfg_mod_sub_overwrite(&ctx, set->model_sub_overwrite.element_addr, + return bt_mesh_cfg_mod_sub_overwrite(¶m, set->model_sub_overwrite.element_addr, set->model_sub_overwrite.sub_addr, set->model_sub_overwrite.model_id, set->model_sub_overwrite.company_id); case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD: - return bt_mesh_cfg_mod_sub_va_add(&ctx, set->model_sub_va_add.element_addr, + return bt_mesh_cfg_mod_sub_va_add(¶m, set->model_sub_va_add.element_addr, &set->model_sub_va_add.label_uuid[0], set->model_sub_va_add.model_id, set->model_sub_va_add.company_id); case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE: - return bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set->model_sub_va_overwrite.element_addr, + return bt_mesh_cfg_mod_sub_va_overwrite(¶m, set->model_sub_va_overwrite.element_addr, &set->model_sub_va_overwrite.label_uuid[0], set->model_sub_va_overwrite.model_id, set->model_sub_va_overwrite.company_id); case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE: - return bt_mesh_cfg_mod_sub_va_del(&ctx, set->model_sub_va_delete.element_addr, + return bt_mesh_cfg_mod_sub_va_del(¶m, set->model_sub_va_delete.element_addr, &set->model_sub_va_delete.label_uuid[0], set->model_sub_va_delete.model_id, set->model_sub_va_delete.company_id); case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET: - return bt_mesh_cfg_hb_sub_set(&ctx, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set); + return bt_mesh_cfg_hb_sub_set(¶m, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set); case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET: - return bt_mesh_cfg_hb_pub_set(&ctx, (const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set); + return bt_mesh_cfg_hb_pub_set(¶m, (struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set); case ESP_BLE_MESH_MODEL_OP_NODE_RESET: - return bt_mesh_cfg_node_reset(&ctx); + return bt_mesh_cfg_node_reset(¶m); case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: { struct bt_mesh_cfg_mod_pub model_pub = { .app_idx = set->model_pub_va_set.publish_app_idx, @@ -577,42 +577,42 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param .period = set->model_pub_va_set.publish_period, .transmit = set->model_pub_va_set.publish_retransmit, }; - return bt_mesh_cfg_mod_pub_va_set(&ctx, set->model_pub_va_set.element_addr, + return bt_mesh_cfg_mod_pub_va_set(¶m, set->model_pub_va_set.element_addr, set->model_pub_va_set.model_id, set->model_pub_va_set.company_id, set->model_pub_va_set.label_uuid, &model_pub); } case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL: - return bt_mesh_cfg_mod_sub_del_all(&ctx, set->model_sub_delete_all.element_addr, + return bt_mesh_cfg_mod_sub_del_all(¶m, set->model_sub_delete_all.element_addr, set->model_sub_delete_all.model_id, set->model_sub_delete_all.company_id); case ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE: - return bt_mesh_cfg_net_key_update(&ctx, set->net_key_update.net_idx, + return bt_mesh_cfg_net_key_update(¶m, set->net_key_update.net_idx, set->net_key_update.net_key); case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE: - return bt_mesh_cfg_net_key_delete(&ctx, set->net_key_delete.net_idx); + return bt_mesh_cfg_net_key_delete(¶m, set->net_key_delete.net_idx); case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE: - return bt_mesh_cfg_app_key_update(&ctx, set->app_key_update.net_idx, + return bt_mesh_cfg_app_key_update(¶m, set->app_key_update.net_idx, set->app_key_update.app_idx, set->app_key_update.app_key); case ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE: - return bt_mesh_cfg_app_key_delete(&ctx, set->app_key_delete.net_idx, + return bt_mesh_cfg_app_key_delete(¶m, set->app_key_delete.net_idx, set->app_key_delete.app_idx); case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET: - return bt_mesh_cfg_node_identity_set(&ctx, set->node_identity_set.net_idx, + return bt_mesh_cfg_node_identity_set(¶m, set->node_identity_set.net_idx, set->node_identity_set.identity); case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND: - return bt_mesh_cfg_mod_app_unbind(&ctx, set->model_app_unbind.element_addr, + return bt_mesh_cfg_mod_app_unbind(¶m, set->model_app_unbind.element_addr, set->model_app_unbind.model_app_idx, set->model_app_unbind.model_id, set->model_app_unbind.company_id); case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET: - return bt_mesh_cfg_kr_phase_set(&ctx, set->kr_phase_set.net_idx, + return bt_mesh_cfg_kr_phase_set(¶m, set->kr_phase_set.net_idx, set->kr_phase_set.transition); case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET: - return bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit); + return bt_mesh_cfg_net_transmit_set(¶m, set->net_transmit_set.net_transmit); default: - BT_ERR("Invalid Configuration Set opcode 0x%04x", params->opcode); + BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode); return -EINVAL; } 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 41aa9c9e57..240f318aa1 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 @@ -21,8 +21,6 @@ #include "health_cli.h" #include "esp_ble_mesh_health_model_api.h" -extern s32_t health_msg_timeout; - /* Health Client Model related functions */ static inline void btc_ble_mesh_health_client_cb_to_app(esp_ble_mesh_health_client_cb_event_t event, @@ -317,7 +315,7 @@ void btc_ble_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *mo static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_health_client_get_state_t *get) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); @@ -329,23 +327,24 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param return -EINVAL; } - ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = params->ctx.app_idx; - ctx.addr = params->ctx.addr; - ctx.send_rel = params->ctx.send_rel; - ctx.send_ttl = params->ctx.send_ttl; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = params->ctx.app_idx; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - health_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET: - return bt_mesh_health_attention_get(&ctx); + return bt_mesh_health_attention_get(¶m); case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET: - return bt_mesh_health_period_get(&ctx); + return bt_mesh_health_period_get(¶m); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET: - return bt_mesh_health_fault_get(&ctx, get->fault_get.company_id); + return bt_mesh_health_fault_get(¶m, get->fault_get.company_id); default: - BT_ERR("Invalid Health Get opcode 0x%04x", params->opcode); + BT_ERR("Invalid Health Get opcode 0x%04x", param.opcode); return -EINVAL; } @@ -355,40 +354,41 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_health_client_set_state_t *set) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL || set == NULL) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = params->ctx.app_idx; - ctx.addr = params->ctx.addr; - ctx.send_rel = params->ctx.send_rel; - ctx.send_ttl = params->ctx.send_ttl; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = params->ctx.app_idx; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - health_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET: - return bt_mesh_health_attention_set(&ctx, set->attention_set.attention, true); + return bt_mesh_health_attention_set(¶m, set->attention_set.attention, true); case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK: - return bt_mesh_health_attention_set(&ctx, set->attention_set.attention, false); + return bt_mesh_health_attention_set(¶m, set->attention_set.attention, false); case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET: - return bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, true); + return bt_mesh_health_period_set(¶m, set->period_set.fast_period_divisor, true); case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK: - return bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, false); + return bt_mesh_health_period_set(¶m, set->period_set.fast_period_divisor, false); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST: - return bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, true); + return bt_mesh_health_fault_test(¶m, set->fault_test.company_id, set->fault_test.test_id, true); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK: - return bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, false); + return bt_mesh_health_fault_test(¶m, set->fault_test.company_id, set->fault_test.test_id, false); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR: - return bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, true); + return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, true); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK: - return bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false); + return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, false); default: - BT_ERR("Invalid Health Set opcode 0x%04x", params->opcode); + BT_ERR("Invalid Health Set opcode 0x%04x", param.opcode); return -EINVAL; } 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 ab1aba5877..87026a62e4 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 @@ -2016,18 +2016,25 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) break; } net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length); - arg->model_send.ctx->srv_send = false; common.model = (struct bt_mesh_model *)(arg->model_send.model); common.role = arg->model_send.device_role; if (bt_mesh_set_client_model_role(&common)) { BT_ERR("Failed to set model role"); break; } - err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model, - arg->model_send.opcode, - (struct bt_mesh_msg_ctx *)arg->model_send.ctx, buf, - btc_ble_mesh_client_model_timeout_cb, arg->model_send.msg_timeout, - arg->model_send.need_rsp, NULL, NULL); + bt_mesh_client_common_param_t param = { + .opcode = arg->model_send.opcode, + .model = (struct bt_mesh_model *)arg->model_send.model, + .ctx.net_idx = arg->model_send.ctx->net_idx, + .ctx.app_idx = arg->model_send.ctx->app_idx, + .ctx.addr = arg->model_send.ctx->addr, + .ctx.send_rel = arg->model_send.ctx->send_rel, + .ctx.send_ttl = arg->model_send.ctx->send_ttl, + .ctx.srv_send = false, + .msg_timeout = arg->model_send.msg_timeout, + }; + err = bt_mesh_client_send_msg(¶m, buf, arg->model_send.need_rsp, + btc_ble_mesh_client_model_timeout_cb); bt_mesh_free_buf(buf); btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx, arg->model_send.opcode, err); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 628d501d9b..4e0c9f1dc8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -20,9 +20,6 @@ #include "mesh_common.h" #include "cfg_cli.h" -/* 2 byte dummy opcode for getting compile time buffer sizes. */ -#define DUMMY_2_BYTE_OP BLE_MESH_MODEL_OP_2(0xff, 0xff) - s32_t config_msg_timeout; static bt_mesh_config_client_t *cli; @@ -681,37 +678,14 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page) +static int send_msg_with_none(bt_mesh_client_common_param_t *param, u32_t op) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_DEV_COMP_DATA_GET, 1); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_DEV_COMP_DATA_GET); - net_buf_simple_add_u8(&msg, page); - - err = bt_mesh_client_send_msg(cli->model, OP_DEV_COMP_DATA_GET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; -} - -static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op) -{ - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 0); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 0); int err = 0; bt_mesh_model_msg_init(&msg, op); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -719,16 +693,15 @@ static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op) return err; } -static int set_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op, u8_t new_val) +static int send_msg_with_u8(bt_mesh_client_common_param_t *param, u32_t op, u8_t val) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 1); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 1); int err = 0; bt_mesh_model_msg_init(&msg, op); - net_buf_simple_add_u8(&msg, new_val); + net_buf_simple_add_u8(&msg, val); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -736,84 +709,15 @@ static int set_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op, u8_t new_val) return err; } -int bt_mesh_cfg_beacon_get(struct bt_mesh_msg_ctx *ctx) +static int send_msg_with_le16(bt_mesh_client_common_param_t *param, u32_t op, u16_t val) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_BEACON_GET); -} - -int bt_mesh_cfg_beacon_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_BEACON_SET, val); -} - -int bt_mesh_cfg_ttl_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_DEFAULT_TTL_GET); -} - -int bt_mesh_cfg_ttl_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_DEFAULT_TTL_SET, val); -} - -int bt_mesh_cfg_friend_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_FRIEND_GET); -} - -int bt_mesh_cfg_friend_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_FRIEND_SET, val); -} - -int bt_mesh_cfg_gatt_proxy_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_GATT_PROXY_GET); -} - -int bt_mesh_cfg_gatt_proxy_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_GATT_PROXY_SET, val); -} - -int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx) -{ - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_GET, 0); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 2); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } + bt_mesh_model_msg_init(&msg, op); + net_buf_simple_add_le16(&msg, val); - bt_mesh_model_msg_init(&msg, OP_RELAY_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_RELAY_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -821,23 +725,71 @@ int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx) return err; } -int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, - u8_t new_transmit) +int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page) +{ + return send_msg_with_u8(param, OP_DEV_COMP_DATA_GET, page); +} + +int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_BEACON_GET); +} + +int bt_mesh_cfg_beacon_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + if (val > 0x01) { + BT_ERR("Invalid beacon state 0x%02x", val); + return -EINVAL; + } + return send_msg_with_u8(param, OP_BEACON_SET, val); +} + +int bt_mesh_cfg_ttl_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_DEFAULT_TTL_GET); +} + +int bt_mesh_cfg_ttl_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + return send_msg_with_u8(param, OP_DEFAULT_TTL_SET, val); +} + +int bt_mesh_cfg_friend_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_FRIEND_GET); +} + +int bt_mesh_cfg_friend_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + return send_msg_with_u8(param, OP_FRIEND_SET, val); +} + +int bt_mesh_cfg_gatt_proxy_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_GATT_PROXY_GET); +} + +int bt_mesh_cfg_gatt_proxy_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + return send_msg_with_u8(param, OP_GATT_PROXY_SET, val); +} + +int bt_mesh_cfg_relay_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_RELAY_GET); +} + +int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param, + u8_t relay, u8_t retransmit) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_SET, 2); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_RELAY_SET); - net_buf_simple_add_u8(&msg, new_relay); - net_buf_simple_add_u8(&msg, new_transmit); + net_buf_simple_add_u8(&msg, relay); + net_buf_simple_add_u8(&msg, retransmit); - err = bt_mesh_client_send_msg(cli->model, OP_RELAY_SET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -845,23 +797,22 @@ int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, return err; } -int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - const u8_t net_key[16]) +int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_ADD, 18); int err = 0; - if (!ctx || !ctx->addr || !net_key) { + if (!net_key) { + BT_ERR("Invalid NetKey"); return -EINVAL; } bt_mesh_model_msg_init(&msg, OP_NET_KEY_ADD); - net_buf_simple_add_le16(&msg, key_net_idx); + net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_mem(&msg, net_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_ADD, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -869,23 +820,23 @@ int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, return err; } -int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - u16_t key_app_idx, const u8_t app_key[16]) +int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19); int err = 0; - if (!ctx || !ctx->addr || !app_key) { + if (!app_key) { + BT_ERR("Invalid AppKey"); return -EINVAL; } bt_mesh_model_msg_init(&msg, OP_APP_KEY_ADD); - key_idx_pack(&msg, key_net_idx, key_app_idx); + key_idx_pack(&msg, net_idx, app_idx); net_buf_simple_add_mem(&msg, app_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_ADD, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -893,27 +844,22 @@ int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, return err; } -int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_app_idx, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_BIND, 8); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_APP_BIND); net_buf_simple_add_le16(&msg, elem_addr); - net_buf_simple_add_le16(&msg, mod_app_idx); + net_buf_simple_add_le16(&msg, app_idx); if (cid != BLE_MESH_CID_NVAL) { net_buf_simple_add_le16(&msg, cid); } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_APP_BIND, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -921,10 +867,11 @@ int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 8); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 8); int err = 0; bt_mesh_model_msg_init(&msg, op); @@ -935,8 +882,7 @@ static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -944,41 +890,40 @@ static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_sub_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub(OP_MOD_SUB_ADD, ctx, elem_addr, sub_addr, mod_id, cid); + return mod_sub(param, OP_MOD_SUB_ADD, elem_addr, sub_addr, mod_id, cid); } -int bt_mesh_cfg_mod_sub_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub(OP_MOD_SUB_DEL, ctx, elem_addr, sub_addr, mod_id, cid); + return mod_sub(param, OP_MOD_SUB_DEL, elem_addr, sub_addr, mod_id, cid); } -int bt_mesh_cfg_mod_sub_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub(OP_MOD_SUB_OVERWRITE, ctx, elem_addr, sub_addr, mod_id, cid); + return mod_sub(param, OP_MOD_SUB_OVERWRITE, elem_addr, sub_addr, mod_id, cid); } -static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +static int mod_sub_va(bt_mesh_client_common_param_t *param, u32_t op, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 22); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 22); int err = 0; - BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x label %s", - ctx->net_idx, ctx->addr, elem_addr, label); + if (!label) { + BT_ERR("Invalid label uuid"); + return -EINVAL; + } + + BT_DBG("elem_addr 0x%04x label %s", elem_addr, bt_hex(label, 16)); BT_DBG("mod_id 0x%04x cid 0x%04x", mod_id, cid); bt_mesh_model_msg_init(&msg, op); @@ -989,8 +934,7 @@ static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -998,43 +942,33 @@ static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_sub_va_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || !label) { - return -EINVAL; - } - return mod_sub_va(OP_MOD_SUB_VA_ADD, ctx, elem_addr, label, mod_id, cid); + return mod_sub_va(param, OP_MOD_SUB_VA_ADD, elem_addr, label, mod_id, cid); } -int bt_mesh_cfg_mod_sub_va_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_va_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || !label) { - return -EINVAL; - } - return mod_sub_va(OP_MOD_SUB_VA_DEL, ctx, elem_addr, label, mod_id, cid); + return mod_sub_va(param, OP_MOD_SUB_VA_DEL, elem_addr, label, mod_id, cid); } -int bt_mesh_cfg_mod_sub_va_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_va_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || !label) { - return -EINVAL; - } - return mod_sub_va(OP_MOD_SUB_VA_OVERWRITE, ctx, elem_addr, label, mod_id, cid); + return mod_sub_va(param, OP_MOD_SUB_VA_OVERWRITE, elem_addr, label, mod_id, cid); } -int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_GET, 6); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_PUB_GET); net_buf_simple_add_le16(&msg, elem_addr); if (cid != BLE_MESH_CID_NVAL) { @@ -1042,9 +976,7 @@ int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_PUB_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1052,14 +984,15 @@ int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, +int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid, struct bt_mesh_cfg_mod_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_SET, 13); int err = 0; - if (!ctx || !ctx->addr || !pub) { + if (!pub) { + BT_ERR("Invalid model pub set"); return -EINVAL; } @@ -1075,9 +1008,7 @@ int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_PUB_SET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1085,13 +1016,14 @@ int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_hb_sub *sub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_SET, 5); int err = 0; - if (!ctx || !ctx->addr || !sub) { + if (!sub) { + BT_ERR("Invalid heartbeat sub set"); return -EINVAL; } @@ -1100,9 +1032,7 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, net_buf_simple_add_le16(&msg, sub->dst); net_buf_simple_add_u8(&msg, sub->period); - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_SUB_SET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1110,34 +1040,19 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_GET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_SUB_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_SUB_GET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_HEARTBEAT_SUB_GET); } -int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, - const struct bt_mesh_cfg_hb_pub *pub) +int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param, + struct bt_mesh_cfg_hb_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_SET, 9); int err = 0; - if (!ctx || !ctx->addr || !pub) { + if (!pub) { + BT_ERR("Invalid heartbeat pub set"); return -EINVAL; } @@ -1149,9 +1064,7 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, net_buf_simple_add_le16(&msg, pub->feat); net_buf_simple_add_le16(&msg, pub->net_idx); - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_PUB_SET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1159,56 +1072,26 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_GET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_PUB_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_PUB_GET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_HEARTBEAT_PUB_GET); } -int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_RESET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_NODE_RESET); - - err = bt_mesh_client_send_msg(cli->model, OP_NODE_RESET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_NODE_RESET); } -int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, const u8_t label[16], +int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, + u16_t cid, const u8_t label[16], struct bt_mesh_cfg_mod_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_VA_SET, 27); int err = 0; - if (!ctx || !ctx->addr || !label || !pub) { + if (!label || !pub) { + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -1224,9 +1107,7 @@ int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_PUB_VA_SET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1234,16 +1115,12 @@ int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_DEL_ALL, 6); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_SUB_DEL_ALL); net_buf_simple_add_le16(&msg, elem_addr); if (cid != BLE_MESH_CID_NVAL) { @@ -1251,9 +1128,7 @@ int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_SUB_DEL_ALL, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1261,10 +1136,10 @@ int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, +static int mod_sub_get(bt_mesh_client_common_param_t *param, u32_t op, u16_t elem_addr, u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6); int err = 0; bt_mesh_model_msg_init(&msg, op); @@ -1274,8 +1149,7 @@ static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1283,30 +1157,30 @@ static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_mod_sub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id) +int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub_get(OP_MOD_SUB_GET, ctx, elem_addr, mod_id, BLE_MESH_CID_NVAL); + return mod_sub_get(param, OP_MOD_SUB_GET, elem_addr, mod_id, BLE_MESH_CID_NVAL); } -int bt_mesh_cfg_mod_sub_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || cid == BLE_MESH_CID_NVAL) { + if (cid == BLE_MESH_CID_NVAL) { + BT_ERR("Invalid company id"); return -EINVAL; } - return mod_sub_get(OP_MOD_SUB_GET_VND, ctx, elem_addr, mod_id, cid); + return mod_sub_get(param, OP_MOD_SUB_GET_VND, elem_addr, mod_id, cid); } -int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - const u8_t net_key[16]) +int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_UPDATE, 18); int err = 0; - if (!ctx || !ctx->addr || !net_key) { + if (!net_key) { + BT_ERR("Invalid NetKey"); return -EINVAL; } @@ -1314,9 +1188,7 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_mem(&msg, net_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_UPDATE, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1324,56 +1196,25 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, return err; } -int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) +int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_DEL, 2); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_NET_KEY_DEL); - net_buf_simple_add_le16(&msg, net_idx); - - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_DEL, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_le16(param, OP_NET_KEY_DEL, net_idx); } -int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_net_key_get(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_GET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_NET_KEY_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_NET_KEY_GET); } -int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - u16_t app_idx, const u8_t app_key[16]) +int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_UPDATE, 19); int err = 0; - if (!ctx || !ctx->addr || !app_key) { + if (!app_key) { + BT_ERR("Invalid AppKey"); return -EINVAL; } @@ -1381,9 +1222,7 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, key_idx_pack(&msg, net_idx, app_idx); net_buf_simple_add_mem(&msg, app_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_UPDATE, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1391,21 +1230,16 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, return err; } -int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t app_idx) +int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_DEL, 3); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_APP_KEY_DEL); key_idx_pack(&msg, net_idx, app_idx); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_DEL, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1413,21 +1247,32 @@ int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t return err; } -int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) +int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_GET, 2); + return send_msg_with_le16(param, OP_APP_KEY_GET, net_idx); +} + +int bt_mesh_cfg_node_identity_get(bt_mesh_client_common_param_t *param, u16_t net_idx) +{ + return send_msg_with_le16(param, OP_NODE_IDENTITY_GET, net_idx); +} + +int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t identity) +{ + BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_SET, 3); int err = 0; - if (!ctx || !ctx->addr) { + if (identity > 0x02) { + BT_ERR("Invalid node identity 0x%02x", identity); return -EINVAL; } - bt_mesh_model_msg_init(&msg, OP_APP_KEY_GET); + bt_mesh_model_msg_init(&msg, OP_NODE_IDENTITY_SET); net_buf_simple_add_le16(&msg, net_idx); + net_buf_simple_add_u8(&msg, identity); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1435,53 +1280,13 @@ int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) return err; } -static int node_identity_op(u32_t op, struct bt_mesh_msg_ctx *ctx, - u16_t net_idx, u8_t identity) -{ - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 3); - int err = 0; - - bt_mesh_model_msg_init(&msg, op); - net_buf_simple_add_le16(&msg, net_idx); - if (op == OP_NODE_IDENTITY_SET) { - net_buf_simple_add_u8(&msg, identity); - } - - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; -} - -int bt_mesh_cfg_node_identity_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return node_identity_op(OP_NODE_IDENTITY_GET, ctx, net_idx, 0xFF); -} - -int bt_mesh_cfg_node_identity_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t identity) -{ - if (!ctx || !ctx->addr || identity > 0x01) { - return -EINVAL; - } - return node_identity_op(OP_NODE_IDENTITY_SET, ctx, net_idx, identity); -} - -int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t app_idx, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_UNBIND, 8); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_APP_UNBIND); net_buf_simple_add_le16(&msg, elem_addr); net_buf_simple_add_le16(&msg, app_idx); @@ -1490,9 +1295,7 @@ int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_APP_UNBIND, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1500,10 +1303,10 @@ int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, +static int mod_app_get(bt_mesh_client_common_param_t *param, u32_t op, u16_t elem_addr, u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6); int err = 0; bt_mesh_model_msg_init(&msg, op); @@ -1513,8 +1316,7 @@ static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1522,37 +1324,43 @@ static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_mod_app_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id) +int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_app_get(OP_SIG_MOD_APP_GET, ctx, elem_addr, mod_id, BLE_MESH_CID_NVAL); + return mod_app_get(param, OP_SIG_MOD_APP_GET, elem_addr, mod_id, BLE_MESH_CID_NVAL); } -int bt_mesh_cfg_mod_app_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_app_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || cid == BLE_MESH_CID_NVAL) { + if (cid == BLE_MESH_CID_NVAL) { + BT_ERR("Invalid company id"); return -EINVAL; } - return mod_app_get(OP_VND_MOD_APP_GET, ctx, elem_addr, mod_id, cid); + return mod_app_get(param, OP_VND_MOD_APP_GET, elem_addr, mod_id, cid); } -static int kr_phase_op(u32_t op, struct bt_mesh_msg_ctx *ctx, - u16_t net_idx, u8_t transition) +int bt_mesh_cfg_kr_phase_get(bt_mesh_client_common_param_t *param, u16_t net_idx) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 3); + return send_msg_with_le16(param, OP_KRP_GET, net_idx); +} + +int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t transition) +{ + BLE_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_SET, 3); int err = 0; - bt_mesh_model_msg_init(&msg, op); + if (transition > 0x03) { + BT_ERR("Invalid kr phase transition 0x%02x", transition); + return -EINVAL; + } + + bt_mesh_model_msg_init(&msg, OP_KRP_SET); net_buf_simple_add_le16(&msg, net_idx); - if (op == OP_KRP_SET) { - net_buf_simple_add_u8(&msg, transition); - } + net_buf_simple_add_u8(&msg, transition); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1560,58 +1368,19 @@ static int kr_phase_op(u32_t op, struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_kr_phase_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) +int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return kr_phase_op(OP_KRP_GET, ctx, net_idx, 0xFF); + return send_msg_with_le16(param, OP_LPN_TIMEOUT_GET, lpn_addr); } -int bt_mesh_cfg_kr_phase_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t transition) +int bt_mesh_cfg_net_transmit_get(bt_mesh_client_common_param_t *param) { - if (!ctx || !ctx->addr || transition > 0x03) { - return -EINVAL; - } - return kr_phase_op(OP_KRP_SET, ctx, net_idx, transition);; + return send_msg_with_none(param, OP_NET_TRANSMIT_GET); } -int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr) +int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t transmit) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_GET, 2); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_LPN_TIMEOUT_GET); - net_buf_simple_add_le16(&msg, lpn_addr); - - err = bt_mesh_client_send_msg(cli->model, OP_LPN_TIMEOUT_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; -} - -int bt_mesh_cfg_net_transmit_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_NET_TRANSMIT_GET); -} - -int bt_mesh_cfg_net_transmit_set(struct bt_mesh_msg_ctx *ctx, u8_t transmit) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_NET_TRANSMIT_SET, transmit); + return send_msg_with_u8(param, OP_NET_TRANSMIT_SET, transmit); } s32_t bt_mesh_cfg_cli_timeout_get(void) diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 5ff4f0c778..acf56eef2d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -235,20 +235,14 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_GET, 0); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_ATTENTION_GET); - err = bt_mesh_client_send_msg(health_cli->model, OP_ATTENTION_GET, ctx, - &msg, timeout_handler, health_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -256,28 +250,16 @@ int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx) return err; } -int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param, u8_t attention, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_SET, 1); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_ATTENTION_SET; - } else { - opcode = OP_ATTENTION_SET_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_ATTENTION_SET : OP_ATTENTION_SET_UNREL); net_buf_simple_add_u8(&msg, attention); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -285,20 +267,14 @@ int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_GET, 0); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_GET); - err = bt_mesh_client_send_msg(health_cli->model, OP_HEALTH_PERIOD_GET, - ctx, &msg, timeout_handler, health_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -306,28 +282,16 @@ int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx) return err; } -int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param, u8_t divisor, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_SET, 1); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_HEALTH_PERIOD_SET; - } else { - opcode = OP_HEALTH_PERIOD_SET_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_PERIOD_SET : OP_HEALTH_PERIOD_SET_UNREL); net_buf_simple_add_u8(&msg, divisor); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -335,29 +299,17 @@ int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param, u16_t cid, u8_t test_id, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_TEST, 3); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_HEALTH_FAULT_TEST; - } else { - opcode = OP_HEALTH_FAULT_TEST_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_TEST : OP_HEALTH_FAULT_TEST_UNREL); net_buf_simple_add_u8(&msg, test_id); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -365,28 +317,16 @@ int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param, u16_t cid, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_CLEAR, 2); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_HEALTH_FAULT_CLEAR; - } else { - opcode = OP_HEALTH_FAULT_CLEAR_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_CLEAR : OP_HEALTH_FAULT_CLEAR_UNREL); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -394,21 +334,15 @@ int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid) +int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_GET, 2); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_HEALTH_FAULT_GET); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(health_cli->model, OP_HEALTH_FAULT_GET, ctx, - &msg, timeout_handler, health_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h index 873d989858..c33a7d977f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h @@ -34,36 +34,39 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[]; BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_CLI, \ bt_mesh_cfg_cli_op, NULL, cli_data) -int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page); +int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page); -int bt_mesh_cfg_beacon_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_beacon_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_beacon_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_ttl_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_ttl_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_ttl_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_ttl_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_friend_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_friend_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_friend_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_friend_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_gatt_proxy_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_gatt_proxy_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_gatt_proxy_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_gatt_proxy_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_relay_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, u8_t new_transmit); +int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param, + u8_t relay, u8_t retransmit); -int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - const u8_t net_key[16]); +int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]); -int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - u16_t key_app_idx, const u8_t app_key[16]); +int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]); -int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_app_idx, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid); struct bt_mesh_cfg_mod_pub { u16_t addr; @@ -74,30 +77,36 @@ struct bt_mesh_cfg_mod_pub { u8_t transmit; }; -int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, +int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid, struct bt_mesh_cfg_mod_pub *pub); -int bt_mesh_cfg_mod_sub_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_va_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_va_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_va_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_va_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_va_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid); struct bt_mesh_cfg_hb_sub { u16_t src; @@ -105,10 +114,10 @@ struct bt_mesh_cfg_hb_sub { u8_t period; }; -int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_hb_sub *sub); -int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param); struct bt_mesh_cfg_hb_pub { u16_t dst; @@ -119,12 +128,12 @@ struct bt_mesh_cfg_hb_pub { u16_t net_idx; }; -int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, - const struct bt_mesh_cfg_hb_pub *pub); +int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param, + struct bt_mesh_cfg_hb_pub *pub); -int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param); s32_t bt_mesh_cfg_cli_timeout_get(void); void bt_mesh_cfg_cli_timeout_set(s32_t timeout); @@ -244,53 +253,61 @@ struct bt_mesh_cfg_lpn_pollto_status { s32_t timeout; }; -int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, const u8_t label[16], +int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, + u16_t cid, const u8_t label[16], struct bt_mesh_cfg_mod_pub *pub); -int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id); +int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id); -int bt_mesh_cfg_mod_sub_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - const u8_t net_key[16]); +int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]); -int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_net_key_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - u16_t app_idx, const u8_t app_key[16]); +int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]); -int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t app_idx); +int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx); -int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_node_identity_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_node_identity_get(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_node_identity_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t identity); +int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t identity); -int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t app_idx, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_app_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id); +int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id); -int bt_mesh_cfg_mod_app_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_app_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_kr_phase_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_kr_phase_get(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_kr_phase_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t transition); +int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t transition); -int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr); +int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr); -int bt_mesh_cfg_net_transmit_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_net_transmit_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_net_transmit_set(struct bt_mesh_msg_ctx *ctx, u8_t transmit); +int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t transmit); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h index 52982eced3..8d38cf3d3d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h @@ -36,22 +36,22 @@ extern const struct bt_mesh_model_op bt_mesh_health_cli_op[]; int bt_mesh_health_cli_set(struct bt_mesh_model *model); -int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid); +int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid); -int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, u16_t cid, - bool need_ack); +int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param, + u16_t cid, bool need_ack); -int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param, u16_t cid, u8_t test_id, bool need_ack); -int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param); -int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param, u8_t divisor, bool need_ack); -int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param); -int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param, u8_t attention, bool need_ack); s32_t bt_mesh_health_cli_timeout_get(void); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index 66e128d431..658c3c4a8a 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -251,26 +251,21 @@ static const struct bt_mesh_send_cb send_cb = { .end = NULL, }; -int bt_mesh_client_send_msg(struct bt_mesh_model *model, - u32_t opcode, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *msg, - k_work_handler_t timer_handler, - s32_t timeout, bool need_ack, - const struct bt_mesh_send_cb *cb, - void *cb_data) +int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, + struct net_buf_simple *msg, bool need_ack, + k_work_handler_t timer_handler) { bt_mesh_client_internal_data_t *internal = NULL; bt_mesh_client_user_data_t *client = NULL; bt_mesh_client_node_t *node = NULL; int err = 0; - if (!model || !ctx || !msg) { + if (!param || !param->model || !msg) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - client = (bt_mesh_client_user_data_t *)model->user_data; + client = (bt_mesh_client_user_data_t *)param->model->user_data; if (!client) { BT_ERR("Invalid client user data"); return -EINVAL; @@ -282,23 +277,23 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return -EINVAL; } - if (ctx->addr == BLE_MESH_ADDR_UNASSIGNED) { - BT_ERR("Invalid DST 0x%04x", ctx->addr); + if (param->ctx.addr == BLE_MESH_ADDR_UNASSIGNED) { + BT_ERR("Invalid DST 0x%04x", param->ctx.addr); return -EINVAL; } if (!need_ack) { /* If this is an unack message, send it directly. */ - return bt_mesh_model_send(model, ctx, msg, cb, cb_data); + return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); } - if (!BLE_MESH_ADDR_IS_UNICAST(ctx->addr)) { + if (!BLE_MESH_ADDR_IS_UNICAST(param->ctx.addr)) { /* If an acknowledged message is not sent to a unicast address, * for example to a group/virtual address, then all the * corresponding responses will be treated as publish messages. * And no timeout will be used for the message. */ - return bt_mesh_model_send(model, ctx, msg, cb, cb_data); + return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); } if (!timer_handler) { @@ -306,8 +301,8 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return -EINVAL; } - if (bt_mesh_client_check_node_in_list(&internal->queue, ctx->addr)) { - BT_ERR("Busy sending message to DST 0x%04x", ctx->addr); + if (bt_mesh_client_check_node_in_list(&internal->queue, param->ctx.addr)) { + BT_ERR("Busy sending message to DST 0x%04x", param->ctx.addr); return -EBUSY; } @@ -318,16 +313,17 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return -ENOMEM; } - memcpy(&node->ctx, ctx, sizeof(struct bt_mesh_msg_ctx)); - node->ctx.model = model; - node->opcode = opcode; - node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, opcode); + memcpy(&node->ctx, ¶m->ctx, sizeof(struct bt_mesh_msg_ctx)); + node->ctx.model = param->model; + node->opcode = param->opcode; + node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, param->opcode); if (node->op_pending == 0U) { BT_ERR("Not found the status opcode in op_pair list"); bt_mesh_free(node); return -EINVAL; } - node->timeout = bt_mesh_client_calc_timeout(ctx, msg, opcode, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); + node->timeout = bt_mesh_client_calc_timeout(¶m->ctx, msg, param->opcode, + param->msg_timeout ? param->msg_timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); if (k_delayed_work_init(&node->timer, timer_handler)) { BT_ERR("Failed to create a timer"); @@ -343,7 +339,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, * Due to the higher priority of adv_thread (than btc task), we need to * send the packet after the list item "node" is initialized properly. */ - err = bt_mesh_model_send(model, ctx, msg, &send_cb, node); + err = bt_mesh_model_send(param->model, ¶m->ctx, msg, &send_cb, node); if (err) { BT_ERR("Failed to send client message 0x%08x", node->opcode); k_delayed_work_free(&node->timer); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index bee29cf451..99d13c7912 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -725,9 +725,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value) } } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg, - timeout_handler, common->msg_timeout, true, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); if (err) { BT_ERR("Failed to send Generic Get message (err %d)", err); } @@ -904,9 +902,7 @@ static int gen_set_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Generic Set message (err %d)", err); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h index 78e87a24e1..c6fc892348 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h @@ -104,13 +104,9 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model * struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, bool need_pub); -int bt_mesh_client_send_msg(struct bt_mesh_model *model, - u32_t opcode, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *msg, - k_work_handler_t timer_handler, - s32_t timeout, bool need_ack, - const struct bt_mesh_send_cb *cb, void *cb_data); +int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, + struct net_buf_simple *msg, bool need_ack, + k_work_handler_t timer_handler); int bt_mesh_client_free_node(bt_mesh_client_node_t *node); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index 77ed506213..18e5072e11 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -790,9 +790,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value) } } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg, - timeout_handler, common->msg_timeout, true, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); if (err) { BT_ERR("Failed to send Lighting Get message (err %d)", err); } @@ -1028,9 +1026,7 @@ static int light_set_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Lighting Set message (err %d)", err); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index 860c50a8bc..34a597d853 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -447,9 +447,7 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Sensor client message (err %d)", err); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index 9357cdbc75..b39ed24ffa 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -390,9 +390,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val } } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg, - timeout_handler, common->msg_timeout, true, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); if (err) { BT_ERR("Failed to send Time Scene Get message (err %d)", err); } @@ -485,9 +483,7 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Time Scene Set message (err %d)", err); }