Skip to content

Commit 11eed84

Browse files
omkar3141nashif
authored andcommitted
Bluetooth: Mesh: Update models metadata API
This commit updates models metadata API to simplify the usage and removes the metadata pointer in health server model context. Signed-off-by: Omkar Kulkarni <[email protected]>
1 parent 435f32d commit 11eed84

File tree

10 files changed

+112
-39
lines changed

10 files changed

+112
-39
lines changed

doc/releases/migration-guide-3.7.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ Bluetooth Mesh
210210
got ``const`` qualifier too. The model's metadata structure and metadata raw value
211211
can be declared as permanent constants in the non-volatile memory. (:github:`69679`)
212212

213+
* The model metadata pointer declaration of :c:struct:`bt_mesh_model` has been changed
214+
to a single ``const *`` and redundant metadata pointer from :c:struct:`bt_mesh_health_srv`
215+
is removed. Consequently, :code:`BT_MESH_MODEL_HEALTH_SRV` definition is changed
216+
to use variable argument notation. (:github:`71281`). Now, when your implementation
217+
supports :kconfig:option:`CONFIG_BT_MESH_LARGE_COMP_DATA_SRV` and when you need to
218+
specify metadata for Health Server model, simply pass metadata as the last argument
219+
to the :code:`BT_MESH_MODEL_HEALTH_SRV` macro, otherwise omit the last argument.
220+
213221
Bluetooth Audio
214222
===============
215223

include/zephyr/bluetooth/mesh/access.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ struct bt_mesh_model_op {
506506
* @param _pub Model publish parameters.
507507
* @param _user_data User data for the model.
508508
* @param _cb Callback structure, or NULL to keep no callbacks.
509-
* @param _metadata Metadata structure.
509+
* @param _metadata Metadata structure. Used if @kconfig{CONFIG_BT_MESH_LARGE_COMP_DATA_SRV}
510+
* is enabled.
510511
*/
511512
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
512513
#define BT_MESH_MODEL_METADATA_CB(_id, _op, _pub, _user_data, _cb, _metadata) \
@@ -560,8 +561,10 @@ struct bt_mesh_model_op {
560561
* @param _pub Model publish parameters.
561562
* @param _user_data User data for the model.
562563
* @param _cb Callback structure, or NULL to keep no callbacks.
563-
* @param _metadata Metadata structure.
564+
* @param _metadata Metadata structure. Used if @kconfig{CONFIG_BT_MESH_LARGE_COMP_DATA_SRV}
565+
* is enabled.
564566
*/
567+
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
565568
#define BT_MESH_MODEL_VND_METADATA_CB(_company, _id, _op, _pub, _user_data, _cb, _metadata) \
566569
{ \
567570
.vnd.company = (_company), \
@@ -577,7 +580,10 @@ struct bt_mesh_model_op {
577580
.cb = _cb, \
578581
.metadata = _metadata, \
579582
}
580-
583+
#else
584+
#define BT_MESH_MODEL_VND_METADATA_CB(_company, _id, _op, _pub, _user_data, _cb, _metadata) \
585+
BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb)
586+
#endif
581587
/**
582588
* @brief Composition data SIG model entry.
583589
*
@@ -924,7 +930,7 @@ struct bt_mesh_model {
924930

925931
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) || defined(__DOXYGEN__)
926932
/* Pointer to the array of model metadata entries. */
927-
const struct bt_mesh_models_metadata_entry * const * const metadata;
933+
const struct bt_mesh_models_metadata_entry * const metadata;
928934
#endif
929935
};
930936

include/zephyr/bluetooth/mesh/health_srv.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ struct bt_mesh_health_srv {
156156

157157
/** Attention Timer state */
158158
struct k_work_delayable attn_timer;
159-
160-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
161-
/** Pointer to the array with Health Test Info Metadata */
162-
const struct bt_mesh_models_metadata_entry *metadata;
163-
#endif
164159
};
165160

166161
/**
@@ -171,18 +166,18 @@ struct bt_mesh_health_srv {
171166
*
172167
* @param srv Pointer to a unique struct bt_mesh_health_srv.
173168
* @param pub Pointer to a unique struct bt_mesh_model_pub.
169+
* @param ... Optional Health Server metadata if application is compiled with
170+
* Large Composition Data Server support, otherwise this parameter
171+
* is ignored.
174172
*
175173
* @return New mesh model instance.
176174
*/
177-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
178-
#define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \
179-
BT_MESH_MODEL_METADATA_CB(BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_op, \
180-
pub, srv, &bt_mesh_health_srv_cb, &(srv)->metadata)
181-
#else
182-
#define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \
183-
BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_op, \
184-
pub, srv, &bt_mesh_health_srv_cb)
185-
#endif
175+
#define BT_MESH_MODEL_HEALTH_SRV(srv, pub, ...) \
176+
BT_MESH_MODEL_METADATA_CB(BT_MESH_MODEL_ID_HEALTH_SRV, \
177+
bt_mesh_health_srv_op, \
178+
pub, \
179+
srv, \
180+
&bt_mesh_health_srv_cb, __VA_ARGS__)
186181

187182
/**
188183
*

include/zephyr/bluetooth/mesh/shell.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct bt_mesh_shell_target {
3838
/** @brief External reference to health server */
3939
extern struct bt_mesh_health_srv bt_mesh_shell_health_srv;
4040

41+
/** @brief External reference to health server metadata */
42+
extern const struct bt_mesh_models_metadata_entry health_srv_meta[];
43+
4144
/** @brief External reference to health client */
4245
extern struct bt_mesh_health_cli bt_mesh_shell_health_cli;
4346

subsys/bluetooth/mesh/access.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static size_t metadata_model_size(const struct bt_mesh_model *mod,
220220

221221
size += sizeof(uint8_t);
222222

223-
for (entry = *mod->metadata; entry && entry->len; ++entry) {
223+
for (entry = mod->metadata; entry && entry->len; ++entry) {
224224
size += sizeof(entry->len) + sizeof(entry->id) + entry->len;
225225
}
226226

@@ -286,7 +286,7 @@ static int metadata_add_model(const struct bt_mesh_model *mod,
286286
count_ptr = data_buf_add_u8_offset(buf, 0, offset);
287287

288288
if (mod->metadata) {
289-
for (entry = *mod->metadata; entry && entry->data != NULL; ++entry) {
289+
for (entry = mod->metadata; entry && entry->data != NULL; ++entry) {
290290
data_buf_add_le16_offset(buf, entry->len, offset);
291291
data_buf_add_le16_offset(buf, entry->id, offset);
292292
data_buf_add_mem_offset(buf, entry->data, entry->len, offset);

subsys/bluetooth/mesh/shell/shell.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ static const struct bt_mesh_health_srv_cb health_srv_cb = {
144144
};
145145
#endif /* CONFIG_BT_MESH_SHELL_HEALTH_SRV_INSTANCE */
146146

147-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
147+
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
148148
static const uint8_t health_tests[] = {
149149
BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x01, 0x02, 0x03, 0x04, 0x34, 0x15),
150150
BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x01, 0x02, 0x03),
151151
};
152152

153-
static const struct bt_mesh_models_metadata_entry health_srv_meta[] = {
153+
const struct bt_mesh_models_metadata_entry health_srv_meta[] = {
154154
BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests),
155155
BT_MESH_MODELS_METADATA_END,
156156
};
@@ -160,9 +160,6 @@ struct bt_mesh_health_srv bt_mesh_shell_health_srv = {
160160
#if defined(CONFIG_BT_MESH_SHELL_HEALTH_SRV_INSTANCE)
161161
.cb = &health_srv_cb,
162162
#endif
163-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
164-
.metadata = health_srv_meta,
165-
#endif
166163
};
167164

168165
#if defined(CONFIG_BT_MESH_SHELL_HEALTH_CLI)

tests/bluetooth/mesh_shell/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub);
4646
static const struct bt_mesh_model root_models[] = {
4747
BT_MESH_MODEL_CFG_SRV,
4848
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
49-
BT_MESH_MODEL_HEALTH_SRV(&bt_mesh_shell_health_srv, &health_pub),
49+
BT_MESH_MODEL_HEALTH_SRV(&bt_mesh_shell_health_srv, &health_pub,
50+
health_srv_meta),
5051
BT_MESH_MODEL_HEALTH_CLI(&bt_mesh_shell_health_cli),
5152
#if defined(CONFIG_BT_MESH_DFD_SRV)
5253
BT_MESH_MODEL_DFD_SRV(&dfd_srv),

tests/bluetooth/tester/src/btp_mesh.c

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ static struct bt_mesh_health_cli health_cli = {
684684
};
685685

686686

687-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
688687
static uint8_t health_tests[] = {
689688
BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x01, 0x02, 0x03, 0x04, 0x34,
690689
0x15),
@@ -718,13 +717,9 @@ static const struct bt_mesh_models_metadata_entry health_srv_meta_alt[] = {
718717
},
719718
BT_MESH_MODELS_METADATA_END,
720719
};
721-
#endif
722720

723721
static struct bt_mesh_health_srv health_srv = {
724722
.cb = &health_srv_cb,
725-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
726-
.metadata = health_srv_meta,
727-
#endif
728723
};
729724

730725
BT_MESH_HEALTH_PUB_DEFINE(health_pub, CUR_FAULTS_MAX);
@@ -1027,7 +1022,63 @@ static uint8_t proxy_solicit(const void *cmd, uint16_t cmd_len,
10271022
static const struct bt_mesh_model root_models[] = {
10281023
BT_MESH_MODEL_CFG_SRV,
10291024
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
1030-
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
1025+
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub, health_srv_meta),
1026+
BT_MESH_MODEL_HEALTH_CLI(&health_cli),
1027+
#if defined(CONFIG_BT_MESH_SAR_CFG_SRV)
1028+
BT_MESH_MODEL_SAR_CFG_SRV,
1029+
#endif
1030+
#if defined(CONFIG_BT_MESH_SAR_CFG_CLI)
1031+
BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli),
1032+
#endif
1033+
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
1034+
BT_MESH_MODEL_LARGE_COMP_DATA_SRV,
1035+
#endif
1036+
#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI)
1037+
BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&lcd_cli),
1038+
#endif
1039+
#if defined(CONFIG_BT_MESH_OP_AGG_SRV)
1040+
BT_MESH_MODEL_OP_AGG_SRV,
1041+
#endif
1042+
#if defined(CONFIG_BT_MESH_OP_AGG_CLI)
1043+
BT_MESH_MODEL_OP_AGG_CLI,
1044+
#endif
1045+
#if defined(CONFIG_BT_MESH_RPR_CLI)
1046+
BT_MESH_MODEL_RPR_CLI(&rpr_cli),
1047+
#endif
1048+
#if defined(CONFIG_BT_MESH_RPR_SRV)
1049+
BT_MESH_MODEL_RPR_SRV,
1050+
#endif
1051+
#if defined(CONFIG_BT_MESH_DFD_SRV)
1052+
BT_MESH_MODEL_DFD_SRV(&dfd_srv),
1053+
#endif
1054+
#if defined(CONFIG_BT_MESH_DFU_SRV)
1055+
BT_MESH_MODEL_DFU_SRV(&dfu_srv),
1056+
#endif
1057+
#if defined(CONFIG_BT_MESH_BLOB_CLI) && !defined(CONFIG_BT_MESH_DFD_SRV)
1058+
BT_MESH_MODEL_BLOB_CLI(&blob_cli),
1059+
#endif
1060+
#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV)
1061+
BT_MESH_MODEL_PRIV_BEACON_SRV,
1062+
#endif
1063+
#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI)
1064+
BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli),
1065+
#endif
1066+
#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI)
1067+
BT_MESH_MODEL_OD_PRIV_PROXY_CLI(&od_priv_proxy_cli),
1068+
#endif
1069+
#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI)
1070+
BT_MESH_MODEL_SOL_PDU_RPL_CLI(&srpl_cli),
1071+
#endif
1072+
#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV)
1073+
BT_MESH_MODEL_OD_PRIV_PROXY_SRV,
1074+
#endif
1075+
1076+
};
1077+
1078+
static const struct bt_mesh_model root_models_alt[] = {
1079+
BT_MESH_MODEL_CFG_SRV,
1080+
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
1081+
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub, health_srv_meta_alt),
10311082
BT_MESH_MODEL_HEALTH_CLI(&health_cli),
10321083
#if defined(CONFIG_BT_MESH_SAR_CFG_SRV)
10331084
BT_MESH_MODEL_SAR_CFG_SRV,
@@ -1100,6 +1151,10 @@ static const struct bt_mesh_elem elements[] = {
11001151
BT_MESH_ELEM(0, root_models, vnd_models),
11011152
};
11021153

1154+
static const struct bt_mesh_elem elements_alt[] = {
1155+
BT_MESH_ELEM(0, root_models_alt, vnd_models),
1156+
};
1157+
11031158
static void link_open(bt_mesh_prov_bearer_t bearer)
11041159
{
11051160
struct btp_mesh_prov_link_open_ev ev;
@@ -1247,8 +1302,8 @@ static const struct bt_mesh_comp comp = {
12471302

12481303
static const struct bt_mesh_comp comp_alt = {
12491304
.cid = CID_LOCAL,
1250-
.elem = elements,
1251-
.elem_count = ARRAY_SIZE(elements),
1305+
.elem = elements_alt,
1306+
.elem_count = ARRAY_SIZE(elements_alt),
12521307
.vid = 2,
12531308
};
12541309

@@ -1414,9 +1469,6 @@ static uint8_t init(const void *cmd, uint16_t cmd_len,
14141469
err = bt_mesh_init(&prov, &comp);
14151470
} else {
14161471
LOG_WRN("Loading alternative comp data");
1417-
#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV
1418-
health_srv.metadata = health_srv_meta_alt;
1419-
#endif
14201472
err = bt_mesh_init(&prov, &comp_alt);
14211473
}
14221474

tests/bsim/bluetooth/mesh/src/mesh_test.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <zephyr/bluetooth/hci.h>
1111

1212
#define LOG_MODULE_NAME mesh_test
13+
#define COMPANY_ID_LF 0x05F1
14+
#define COMPANY_ID_NORDIC_SEMI 0x05F9
1315

1416
#include <zephyr/logging/log.h>
1517
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
@@ -162,6 +164,15 @@ static struct bt_mesh_health_srv health_srv;
162164
static struct bt_mesh_model_pub health_pub = {
163165
.msg = NET_BUF_SIMPLE(BT_MESH_TX_SDU_MAX),
164166
};
167+
static const uint8_t health_tests[] = {
168+
BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_LF, 6, 0x01, 0x02, 0x03, 0x04, 0x34, 0x15),
169+
BT_MESH_HEALTH_TEST_INFO(COMPANY_ID_NORDIC_SEMI, 3, 0x01, 0x02, 0x03),
170+
};
171+
172+
const struct bt_mesh_models_metadata_entry health_srv_meta[] = {
173+
BT_MESH_HEALTH_TEST_INFO_METADATA(health_tests),
174+
BT_MESH_MODELS_METADATA_END,
175+
};
165176

166177
#if defined(CONFIG_BT_MESH_SAR_CFG)
167178
static struct bt_mesh_sar_cfg_cli sar_cfg_cli;
@@ -179,7 +190,7 @@ static const struct bt_mesh_model models[] = {
179190
BT_MESH_MODEL_CFG_SRV,
180191
BT_MESH_MODEL_CFG_CLI(&cfg_cli),
181192
BT_MESH_MODEL_CB(TEST_MOD_ID, model_op, &pub, NULL, &test_model_cb),
182-
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
193+
BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub, health_srv_meta),
183194
#if defined(CONFIG_BT_MESH_SAR_CFG)
184195
BT_MESH_MODEL_SAR_CFG_SRV,
185196
BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli),

tests/bsim/bluetooth/mesh/src/test_lcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void test_args_parse(int argc, char *argv[])
8686
bs_args_parse_all_cmd_line(argc, argv, args_struct);
8787
}
8888

89-
static const struct bt_mesh_models_metadata_entry *dummy_meta_entry[] = {};
89+
static const struct bt_mesh_models_metadata_entry dummy_meta_entry[1];
9090

9191
/* Empty elements to create large composition/meta data */
9292
#define DUMMY_ELEM(i, _) BT_MESH_ELEM((i) + 2, \

0 commit comments

Comments
 (0)