Skip to content

Commit 5f6f61f

Browse files
llyespressif-bot
authored andcommitted
ble_mesh: stack: Move client role set to the msg function
1 parent ad39479 commit 5f6f61f

File tree

9 files changed

+40
-151
lines changed

9 files changed

+40
-151
lines changed

components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
416416
param.ctx.send_rel = params->ctx.send_rel;
417417
param.ctx.send_ttl = params->ctx.send_ttl;
418418
param.msg_timeout = params->msg_timeout;
419+
param.msg_role = params->msg_role;
419420

420421
switch (param.opcode) {
421422
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
@@ -495,6 +496,7 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
495496
param.ctx.send_rel = params->ctx.send_rel;
496497
param.ctx.send_ttl = params->ctx.send_ttl;
497498
param.msg_timeout = params->msg_timeout;
499+
param.msg_role = params->msg_role;
498500

499501
switch (param.opcode) {
500502
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
@@ -623,7 +625,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
623625
{
624626
btc_ble_mesh_config_client_args_t *arg = NULL;
625627
esp_ble_mesh_cfg_client_cb_param_t cb = {0};
626-
bt_mesh_role_param_t role_param = {0};
627628

628629
if (!msg || !msg->arg) {
629630
BT_ERR("%s, Invalid parameter", __func__);
@@ -635,14 +636,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
635636
switch (msg->act) {
636637
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
637638
cb.params = arg->cfg_client_get_state.params;
638-
639-
role_param.model = (struct bt_mesh_model *)cb.params->model;
640-
role_param.role = cb.params->msg_role;
641-
if (bt_mesh_set_client_model_role(&role_param)) {
642-
BT_ERR("Failed to set model role");
643-
break;
644-
}
645-
646639
cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
647640
arg->cfg_client_get_state.get_state);
648641
if (cb.error_code) {
@@ -652,14 +645,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
652645
}
653646
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
654647
cb.params = arg->cfg_client_set_state.params;
655-
656-
role_param.model = (struct bt_mesh_model *)cb.params->model;
657-
role_param.role = cb.params->msg_role;
658-
if (bt_mesh_set_client_model_role(&role_param)) {
659-
BT_ERR("Failed to set model role");
660-
break;
661-
}
662-
663648
cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
664649
arg->cfg_client_set_state.set_state);
665650
if (cb.error_code) {

components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
454454
btc_ble_mesh_generic_client_args_t *arg = NULL;
455455
esp_ble_mesh_generic_client_cb_param_t cb = {0};
456456
bt_mesh_client_common_param_t common = {0};
457-
bt_mesh_role_param_t role_param = {0};
458457

459458
if (!msg || !msg->arg) {
460459
BT_ERR("%s, Invalid parameter", __func__);
@@ -466,14 +465,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
466465
switch (msg->act) {
467466
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
468467
params = arg->generic_client_get_state.params;
469-
470-
role_param.model = (struct bt_mesh_model *)params->model;
471-
role_param.role = params->msg_role;
472-
if (bt_mesh_set_client_model_role(&role_param)) {
473-
BT_ERR("Failed to set model role");
474-
break;
475-
}
476-
477468
common.opcode = params->opcode;
478469
common.model = (struct bt_mesh_model *)params->model;
479470
common.ctx.net_idx = params->ctx.net_idx;
@@ -482,6 +473,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
482473
common.ctx.send_rel = params->ctx.send_rel;
483474
common.ctx.send_ttl = params->ctx.send_ttl;
484475
common.msg_timeout = params->msg_timeout;
476+
common.msg_role = params->msg_role;
485477

486478
cb.params = arg->generic_client_get_state.params;
487479
cb.error_code = bt_mesh_generic_client_get_state(&common, arg->generic_client_get_state.get_state);
@@ -493,14 +485,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
493485
}
494486
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
495487
params = arg->generic_client_set_state.params;
496-
497-
role_param.model = (struct bt_mesh_model *)params->model;
498-
role_param.role = params->msg_role;
499-
if (bt_mesh_set_client_model_role(&role_param)) {
500-
BT_ERR("Failed to set model role");
501-
break;
502-
}
503-
504488
common.opcode = params->opcode;
505489
common.model = (struct bt_mesh_model *)params->model;
506490
common.ctx.net_idx = params->ctx.net_idx;
@@ -509,6 +493,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
509493
common.ctx.send_rel = params->ctx.send_rel;
510494
common.ctx.send_ttl = params->ctx.send_ttl;
511495
common.msg_timeout = params->msg_timeout;
496+
common.msg_role = params->msg_role;
512497

513498
cb.params = arg->generic_client_set_state.params;
514499
cb.error_code = bt_mesh_generic_client_set_state(&common, arg->generic_client_set_state.set_state);

components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
335335
param.ctx.send_rel = params->ctx.send_rel;
336336
param.ctx.send_ttl = params->ctx.send_ttl;
337337
param.msg_timeout = params->msg_timeout;
338+
param.msg_role = params->msg_role;
338339

339340
switch (param.opcode) {
340341
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
@@ -369,6 +370,7 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param
369370
param.ctx.send_rel = params->ctx.send_rel;
370371
param.ctx.send_ttl = params->ctx.send_ttl;
371372
param.msg_timeout = params->msg_timeout;
373+
param.msg_role = params->msg_role;
372374

373375
switch (param.opcode) {
374376
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
@@ -399,7 +401,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
399401
{
400402
btc_ble_mesh_health_client_args_t *arg = NULL;
401403
esp_ble_mesh_health_client_cb_param_t cb = {0};
402-
bt_mesh_role_param_t role_param = {0};
403404

404405
if (!msg || !msg->arg) {
405406
BT_ERR("%s, Invalid parameter", __func__);
@@ -411,14 +412,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
411412
switch (msg->act) {
412413
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
413414
cb.params = arg->health_client_get_state.params;
414-
415-
role_param.model = (struct bt_mesh_model *)cb.params->model;
416-
role_param.role = cb.params->msg_role;
417-
if (bt_mesh_set_client_model_role(&role_param)) {
418-
BT_ERR("Failed to set model role");
419-
break;
420-
}
421-
422415
cb.error_code = btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
423416
arg->health_client_get_state.get_state);
424417
if (cb.error_code) {
@@ -429,14 +422,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
429422
}
430423
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
431424
cb.params = arg->health_client_set_state.params;
432-
433-
role_param.model = (struct bt_mesh_model *)cb.params->model;
434-
role_param.role = cb.params->msg_role;
435-
if (bt_mesh_set_client_model_role(&role_param)) {
436-
BT_ERR("Failed to set model role");
437-
break;
438-
}
439-
440425
cb.error_code = btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
441426
arg->health_client_set_state.set_state);
442427
if (cb.error_code) {

components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
298298
btc_ble_mesh_lighting_client_args_t *arg = NULL;
299299
esp_ble_mesh_light_client_cb_param_t cb = {0};
300300
bt_mesh_client_common_param_t common = {0};
301-
bt_mesh_role_param_t role_param = {0};
302301

303302
if (!msg || !msg->arg) {
304303
BT_ERR("%s, Invalid parameter", __func__);
@@ -310,14 +309,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
310309
switch (msg->act) {
311310
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
312311
params = arg->light_client_get_state.params;
313-
314-
role_param.model = (struct bt_mesh_model *)params->model;
315-
role_param.role = params->msg_role;
316-
if (bt_mesh_set_client_model_role(&role_param)) {
317-
BT_ERR("Failed to set model role");
318-
break;
319-
}
320-
321312
common.opcode = params->opcode;
322313
common.model = (struct bt_mesh_model *)params->model;
323314
common.ctx.net_idx = params->ctx.net_idx;
@@ -326,6 +317,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
326317
common.ctx.send_rel = params->ctx.send_rel;
327318
common.ctx.send_ttl = params->ctx.send_ttl;
328319
common.msg_timeout = params->msg_timeout;
320+
common.msg_role = params->msg_role;
329321

330322
cb.params = arg->light_client_get_state.params;
331323
cb.error_code = bt_mesh_light_client_get_state(&common, arg->light_client_get_state.get_state);
@@ -337,14 +329,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
337329
}
338330
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
339331
params = arg->light_client_set_state.params;
340-
341-
role_param.model = (struct bt_mesh_model *)params->model;
342-
role_param.role = params->msg_role;
343-
if (bt_mesh_set_client_model_role(&role_param)) {
344-
BT_ERR("Failed to set model role");
345-
break;
346-
}
347-
348332
common.opcode = params->opcode;
349333
common.model = (struct bt_mesh_model *)params->model;
350334
common.ctx.net_idx = params->ctx.net_idx;
@@ -353,6 +337,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
353337
common.ctx.send_rel = params->ctx.send_rel;
354338
common.ctx.send_ttl = params->ctx.send_ttl;
355339
common.msg_timeout = params->msg_timeout;
340+
common.msg_role = params->msg_role;
356341

357342
cb.params = arg->light_client_set_state.params;
358343
cb.error_code = bt_mesh_light_client_set_state(&common, arg->light_client_set_state.set_state);

components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,11 +1978,11 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
19781978
switch (msg->act) {
19791979
case BTC_BLE_MESH_ACT_MODEL_PUBLISH: {
19801980
if (arg->model_publish.device_role == PROVISIONER) {
1981-
bt_mesh_role_param_t common = {0};
1982-
common.model = (struct bt_mesh_model *)(arg->model_publish.model);
1983-
common.role = arg->model_publish.device_role;
1984-
if (bt_mesh_set_client_model_role(&common)) {
1985-
BT_ERR("Failed to set model role");
1981+
/* Currently Provisioner only supports client model */
1982+
err = bt_mesh_set_client_model_role((struct bt_mesh_model *)arg->model_publish.model,
1983+
arg->model_publish.device_role);
1984+
if (err) {
1985+
BT_ERR("Failed to set client role");
19861986
break;
19871987
}
19881988
}
@@ -2008,20 +2008,13 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
20082008
break;
20092009
}
20102010
case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: {
2011-
bt_mesh_role_param_t common = {0};
20122011
/* arg->model_send.length contains opcode & message, plus extra 4-bytes TransMIC */
20132012
struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT);
20142013
if (!buf) {
20152014
BT_ERR("%s, Out of memory", __func__);
20162015
break;
20172016
}
20182017
net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
2019-
common.model = (struct bt_mesh_model *)(arg->model_send.model);
2020-
common.role = arg->model_send.device_role;
2021-
if (bt_mesh_set_client_model_role(&common)) {
2022-
BT_ERR("Failed to set model role");
2023-
break;
2024-
}
20252018
bt_mesh_client_common_param_t param = {
20262019
.opcode = arg->model_send.opcode,
20272020
.model = (struct bt_mesh_model *)arg->model_send.model,
@@ -2032,6 +2025,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
20322025
.ctx.send_ttl = arg->model_send.ctx->send_ttl,
20332026
.ctx.srv_send = false,
20342027
.msg_timeout = arg->model_send.msg_timeout,
2028+
.msg_role = arg->model_send.device_role,
20352029
};
20362030
err = bt_mesh_client_send_msg(&param, buf, arg->model_send.need_rsp,
20372031
btc_ble_mesh_client_model_timeout_cb);

components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
536536
btc_ble_mesh_sensor_client_args_t *arg = NULL;
537537
esp_ble_mesh_sensor_client_cb_param_t cb = {0};
538538
bt_mesh_client_common_param_t common = {0};
539-
bt_mesh_role_param_t role_param = {0};
540539

541540
if (!msg || !msg->arg) {
542541
BT_ERR("%s, Invalid parameter", __func__);
@@ -548,14 +547,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
548547
switch (msg->act) {
549548
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
550549
params = arg->sensor_client_get_state.params;
551-
552-
role_param.model = (struct bt_mesh_model *)params->model;
553-
role_param.role = params->msg_role;
554-
if (bt_mesh_set_client_model_role(&role_param)) {
555-
BT_ERR("Failed to set model role");
556-
break;
557-
}
558-
559550
common.opcode = params->opcode;
560551
common.model = (struct bt_mesh_model *)params->model;
561552
common.ctx.net_idx = params->ctx.net_idx;
@@ -564,6 +555,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
564555
common.ctx.send_rel = params->ctx.send_rel;
565556
common.ctx.send_ttl = params->ctx.send_ttl;
566557
common.msg_timeout = params->msg_timeout;
558+
common.msg_role = params->msg_role;
567559

568560
cb.params = arg->sensor_client_get_state.params;
569561
cb.error_code = bt_mesh_sensor_client_get_state(&common, arg->sensor_client_get_state.get_state);
@@ -575,14 +567,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
575567
}
576568
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
577569
params = arg->sensor_client_set_state.params;
578-
579-
role_param.model = (struct bt_mesh_model *)params->model;
580-
role_param.role = params->msg_role;
581-
if (bt_mesh_set_client_model_role(&role_param)) {
582-
BT_ERR("Failed to set model role");
583-
break;
584-
}
585-
586570
common.opcode = params->opcode;
587571
common.model = (struct bt_mesh_model *)params->model;
588572
common.ctx.net_idx = params->ctx.net_idx;
@@ -591,6 +575,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
591575
common.ctx.send_rel = params->ctx.send_rel;
592576
common.ctx.send_ttl = params->ctx.send_ttl;
593577
common.msg_timeout = params->msg_timeout;
578+
common.msg_role = params->msg_role;
594579

595580
cb.params = arg->sensor_client_set_state.params;
596581
cb.error_code = bt_mesh_sensor_client_set_state(&common, arg->sensor_client_set_state.set_state);

components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
300300
esp_ble_mesh_client_common_param_t *params = NULL;
301301
esp_ble_mesh_time_scene_client_cb_param_t cb = {0};
302302
bt_mesh_client_common_param_t common = {0};
303-
bt_mesh_role_param_t role_param = {0};
304303

305304
if (!msg || !msg->arg) {
306305
BT_ERR("%s, Invalid parameter", __func__);
@@ -312,14 +311,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
312311
switch (msg->act) {
313312
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
314313
params = arg->time_scene_client_get_state.params;
315-
316-
role_param.model = (struct bt_mesh_model *)params->model;
317-
role_param.role = params->msg_role;
318-
if (bt_mesh_set_client_model_role(&role_param)) {
319-
BT_ERR("Failed to set model role");
320-
break;
321-
}
322-
323314
common.opcode = params->opcode;
324315
common.model = (struct bt_mesh_model *)params->model;
325316
common.ctx.net_idx = params->ctx.net_idx;
@@ -328,6 +319,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
328319
common.ctx.send_rel = params->ctx.send_rel;
329320
common.ctx.send_ttl = params->ctx.send_ttl;
330321
common.msg_timeout = params->msg_timeout;
322+
common.msg_role = params->msg_role;
331323

332324
cb.params = arg->time_scene_client_get_state.params;
333325
cb.error_code = bt_mesh_time_scene_client_get_state(&common, arg->time_scene_client_get_state.get_state);
@@ -339,14 +331,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
339331
}
340332
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
341333
params = arg->time_scene_client_set_state.params;
342-
343-
role_param.model = (struct bt_mesh_model *)params->model;
344-
role_param.role = params->msg_role;
345-
if (bt_mesh_set_client_model_role(&role_param)) {
346-
BT_ERR("Failed to set model role");
347-
break;
348-
}
349-
350334
common.opcode = params->opcode;
351335
common.model = (struct bt_mesh_model *)params->model;
352336
common.ctx.net_idx = params->ctx.net_idx;
@@ -355,6 +339,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
355339
common.ctx.send_rel = params->ctx.send_rel;
356340
common.ctx.send_ttl = params->ctx.send_ttl;
357341
common.msg_timeout = params->msg_timeout;
342+
common.msg_role = params->msg_role;
358343

359344
cb.params = arg->time_scene_client_set_state.params;
360345
cb.error_code = bt_mesh_time_scene_client_set_state(&common, arg->time_scene_client_set_state.set_state);

0 commit comments

Comments
 (0)