From 7d7bbec5fefb27b18549eeee779416dd929e5ec5 Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 19 Dec 2019 22:13:19 +0800 Subject: [PATCH] ble_mesh: Make model publication struct more compact Previously the FastPeriodDivisor value was introduced to the model publication struct. Based on the way it was grouped it seems the intention was to fit it within the same octet as other bit fields, but it actually makes the octet overflow by one bit. This ends up creating another u8_t variable which in turn adds 24 bits of padding after it. To keep the size of the struct as compact as possible, group the flag together with the key index, since that only requires 12 bits. Some care is needed here, since the mesh stack does have special internal key index values that require more than 12 bits such as BLE_MESH_KEY_UNUSED and BLE_MESH_KEY_DEV. In this case restricting ourselves to 12 bits is fine since the value in the model publication struct follows 1:1 the value received in the Config Model Publication Set message, and there the parameter is defined to be exactly 12 bits. --- components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 10 +++++----- .../bt/esp_ble_mesh/mesh_core/include/mesh_access.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) 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 6263c01248..733c718aa6 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 @@ -356,16 +356,16 @@ typedef struct { esp_ble_mesh_model_t *model; uint16_t publish_addr; /*!< Publish Address. */ - uint16_t app_idx; /*!< Publish AppKey Index. */ + uint16_t app_idx:12, /*!< Publish AppKey Index. */ + cred:1; /*!< Friendship Credentials Flag. */ uint8_t ttl; /*!< Publish Time to Live. */ uint8_t retransmit; /*!< Retransmit Count & Interval Steps. */ uint8_t period; /*!< Publish Period. */ - uint16_t period_div: 4, /*!< Divisor for the Period. */ - cred: 1, /*!< Friendship Credentials Flag. */ - fast_period: 1, /*!< Use FastPeriodDivisor */ - count: 3; /*!< Retransmissions left. */ + uint8_t period_div:4, /*!< Divisor for the Period. */ + fast_period:1, /*!< Use FastPeriodDivisor */ + count:3; /*!< Retransmissions left. */ uint32_t period_start; /*!< Start of the current period. */ diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h index 0d5e4f66fb..8c387a6811 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h @@ -335,15 +335,15 @@ struct bt_mesh_model_pub { struct bt_mesh_model *mod; u16_t addr; /**< Publish Address. */ - u16_t key; /**< Publish AppKey Index. */ + u16_t key:12, /**< Publish AppKey Index. */ + cred:1; /**< Friendship Credentials Flag. */ u8_t ttl; /**< Publish Time to Live. */ u8_t retransmit; /**< Retransmit Count & Interval Steps. */ u8_t period; /**< Publish Period. */ - u16_t period_div: 4, /**< Divisor for the Period. */ - cred: 1, /**< Friendship Credentials Flag. */ - fast_period: 1, /**< Use FastPeriodDivisor */ - count: 3; /**< Retransmissions left. */ + u8_t period_div:4, /**< Divisor for the Period. */ + fast_period:1,/**< Use FastPeriodDivisor */ + count:3; /**< Retransmissions left. */ u32_t period_start; /**< Start of the current period. */