in nimble/host/mesh/src/cfg_srv.c [176:261]
static uint8_t _mod_pub_set(struct bt_mesh_model *model, uint16_t pub_addr,
uint16_t app_idx, uint8_t cred_flag, uint8_t ttl, uint8_t period,
uint8_t retransmit, bool store)
{
if (!model->pub) {
return STATUS_NVAL_PUB_PARAM;
}
if (!(MYNEWT_VAL(BLE_MESH_LOW_POWER)) && cred_flag) {
return STATUS_FEAT_NOT_SUPP;
}
if (!model->pub->update && period) {
return STATUS_NVAL_PUB_PARAM;
}
if (pub_addr == BT_MESH_ADDR_UNASSIGNED) {
if (model->pub->addr == BT_MESH_ADDR_UNASSIGNED) {
return STATUS_SUCCESS;
}
model->pub->addr = BT_MESH_ADDR_UNASSIGNED;
model->pub->key = 0;
model->pub->cred = 0;
model->pub->ttl = 0;
model->pub->period = 0;
model->pub->retransmit = 0;
model->pub->count = 0;
if (model->pub->update) {
/* If this fails, the timer will check pub->addr and
* exit without transmitting.
*/
(void)k_work_cancel_delayable(&model->pub->timer);
}
if (IS_ENABLED(CONFIG_BT_SETTINGS) && store) {
bt_mesh_model_pub_store(model);
}
return STATUS_SUCCESS;
}
if (!bt_mesh_app_key_exists(app_idx) || !bt_mesh_model_has_key(model, app_idx)) {
return STATUS_INVALID_APPKEY;
}
#if CONFIG_BT_MESH_LABEL_COUNT > 0
if (BT_MESH_ADDR_IS_VIRTUAL(model->pub->addr)) {
uint8_t *uuid = bt_mesh_va_label_get(model->pub->addr);
if (uuid) {
bt_mesh_va_del(uuid, NULL);
}
}
#endif
model->pub->addr = pub_addr;
model->pub->key = app_idx;
model->pub->cred = cred_flag;
model->pub->ttl = ttl;
model->pub->period = period;
model->pub->retransmit = retransmit;
if (model->pub->update) {
int32_t period_ms;
period_ms = bt_mesh_model_pub_period_get(model);
BT_DBG("period %u ms", (unsigned) period_ms);
if (period_ms > 0) {
k_work_reschedule(&model->pub->timer, period_ms);
} else {
/* If this fails, publication will stop after the
* ongoing set of retransmits.
*/
k_work_cancel_delayable(&model->pub->timer);
}
}
if (IS_ENABLED(CONFIG_BT_SETTINGS) && store) {
bt_mesh_model_pub_store(model);
}
return STATUS_SUCCESS;
}