From edb088e5db2e53a4833a9cf0a6f7da0ff744a599 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 1 Jul 2020 20:02:26 +0800 Subject: [PATCH 1/2] ble_mesh: stack: Update send_ttl in btc when recv a msg Update send_ttl mainly for server models. When a server model receives a message, and the status is required to be replied by the application, we need to set send_ttl to the msg context. If send_ttl is not updated in btc, and the applcation does not set the TTL either, then the status will be replied with TTL=0, which may cause the client side (e.g. the phone App) failed to receive the status. Closes https://github.com/espressif/esp-idf/issues/5300 --- components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c | 1 + components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c | 2 ++ 6 files changed, 11 insertions(+) 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 c87445407..c66f166ae 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 @@ -352,6 +352,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -753,6 +754,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); 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 4664a83d6..d555268ab 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 @@ -420,6 +420,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -744,6 +745,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); 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 e3be0c34c..fd4125efb 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 @@ -286,6 +286,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; 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 1adaac4f6..4a0a4bf9e 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 @@ -264,6 +264,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -559,6 +560,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); 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 682b4d70f..7b3b3d8d3 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 @@ -502,6 +502,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -876,6 +877,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); 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 68862ac38..66f1311a2 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 @@ -266,6 +266,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -463,6 +464,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); From 8005d07e07c6e98286287af5e907e28a030cb75f Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 1 Jul 2020 20:10:35 +0800 Subject: [PATCH 2/2] ble_mesh: stack: Add two application macros for TTL --- components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index 35916db12..ba07e4e94 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -61,6 +61,12 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN]; /*!< Invalid Company ID */ #define ESP_BLE_MESH_CID_NVAL 0xFFFF +/*!< Special TTL value to request using configured default TTL */ +#define ESP_BLE_MESH_TTL_DEFAULT 0xFF + +/*!< Maximum allowed TTL value */ +#define ESP_BLE_MESH_TTL_MAX 0x7F + #define ESP_BLE_MESH_ADDR_UNASSIGNED 0x0000 #define ESP_BLE_MESH_ADDR_ALL_NODES 0xFFFF #define ESP_BLE_MESH_ADDR_PROXIES 0xFFFC @@ -522,7 +528,7 @@ typedef struct { /** Force sending reliably by using segment acknowledgement */ uint8_t send_rel: 1; - /** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */ + /** TTL, or ESP_BLE_MESH_TTL_DEFAULT for default TTL. */ uint8_t send_ttl; /** Opcode of a received message. Not used for sending message. */