Merge branch 'bugfix/ble_mesh_check_timer_init' into 'master'

ble_mesh: Check the result of creating timer

Closes BLEMESH-218

See merge request espressif/esp-idf!8932
This commit is contained in:
Island 2020-05-28 10:11:47 +08:00
commit 705fc0f0e5
4 changed files with 32 additions and 18 deletions

View file

@ -244,7 +244,7 @@ int k_delayed_work_cancel(struct k_delayed_work *work);
int k_delayed_work_free(struct k_delayed_work *work); int k_delayed_work_free(struct k_delayed_work *work);
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler); int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler);
/** /**
* @brief Get system uptime. * @brief Get system uptime.

View file

@ -59,13 +59,13 @@ void bt_mesh_timer_deinit(void)
} }
} }
void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
{ {
osi_alarm_t *alarm = NULL; osi_alarm_t *alarm = NULL;
if (!work || !bm_alarm_hash_map) { if (!work || !bm_alarm_hash_map) {
BT_ERR("%s, Invalid parameter", __func__); BT_ERR("%s, Invalid parameter", __func__);
return; return -EINVAL;
} }
k_work_init(&work->work, handler); k_work_init(&work->work, handler);
@ -74,28 +74,28 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) { if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0); alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
if (alarm == NULL) { if (alarm == NULL) {
BT_ERR("%s, Unable to create alarm", __func__); BT_ERR("%s, Alarm not created", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return; return -EIO;
} }
if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) { if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) {
BT_ERR("%s Unable to add the timer to hash map.", __func__); BT_ERR("%s, Alarm not set", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return; return -EIO;
} }
} }
alarm = hash_map_get(bm_alarm_hash_map, work); alarm = hash_map_get(bm_alarm_hash_map, work);
if (alarm == NULL) { if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__); BT_ERR("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return; return -ENODEV;
} }
// Just init the work timer only, don't start it. // Just init the work timer only, don't start it.
osi_alarm_cancel(alarm); osi_alarm_cancel(alarm);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return; return 0;
} }
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay) int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
@ -108,7 +108,7 @@ int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
bt_mesh_alarm_lock(); bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) { if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__); BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return -EINVAL; return -EINVAL;
} }
@ -130,7 +130,7 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period)
bt_mesh_alarm_lock(); bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) { if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__); BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return -EINVAL; return -EINVAL;
} }
@ -152,7 +152,7 @@ int k_delayed_work_cancel(struct k_delayed_work *work)
bt_mesh_alarm_lock(); bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) { if (alarm == NULL) {
BT_WARN("%s, Unable to find expected alarm in hash map", __func__); BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return -EINVAL; return -EINVAL;
} }
@ -173,7 +173,7 @@ int k_delayed_work_free(struct k_delayed_work *work)
bt_mesh_alarm_lock(); bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work);
if (alarm == NULL) { if (alarm == NULL) {
BT_WARN("%s Unable to find expected alarm in hash map", __func__); BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return -EINVAL; return -EINVAL;
} }
@ -196,7 +196,7 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
bt_mesh_alarm_lock(); bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) { if (alarm == NULL) {
BT_WARN("%s Unable to find expected alarm in hash map", __func__); BT_WARN("%s, Alarm not found", __func__);
bt_mesh_alarm_unlock(); bt_mesh_alarm_unlock();
return 0; return 0;
} }

View file

@ -1163,7 +1163,16 @@ int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
front = (tx->param.priority == BLE_MESH_BLE_ADV_PRIO_HIGH) ? true : false; front = (tx->param.priority == BLE_MESH_BLE_ADV_PRIO_HIGH) ? true : false;
bt_mesh_ble_adv_send(buf, &ble_adv_send_cb, tx, front); bt_mesh_ble_adv_send(buf, &ble_adv_send_cb, tx, front);
if (param->count) { if (param->count) {
k_delayed_work_init(&tx->resend, ble_adv_resend); if (k_delayed_work_init(&tx->resend, ble_adv_resend)) {
/* If failed to create a timer, the BLE adv packet will be
* sent only once. Just give a warning here, and since the
* BLE adv packet can be sent, return 0 here.
*/
BT_WARN("Send BLE adv packet only once");
tx->param.count = 0;
net_buf_unref(buf);
return 0;
}
bt_mesh_atomic_set_bit(tx->flags, TIMER_INIT); bt_mesh_atomic_set_bit(tx->flags, TIMER_INIT);
} else { } else {
/* Send the BLE advertising packet only once */ /* Send the BLE advertising packet only once */

View file

@ -324,13 +324,17 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model,
node->opcode = opcode; node->opcode = opcode;
node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, opcode); node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, opcode);
if (node->op_pending == 0U) { if (node->op_pending == 0U) {
BT_ERR("%s, Not found the status opcode in the op_pair list", __func__); BT_ERR("Not found the status opcode in op_pair list");
bt_mesh_free(node); bt_mesh_free(node);
return -EINVAL; return -EINVAL;
} }
node->timeout = bt_mesh_client_calc_timeout(ctx, msg, opcode, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); node->timeout = bt_mesh_client_calc_timeout(ctx, msg, opcode, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT);
k_delayed_work_init(&node->timer, timer_handler); if (k_delayed_work_init(&node->timer, timer_handler)) {
BT_ERR("%s, Failed to create a timer", __func__);
bt_mesh_free(node);
return -EIO;
}
bt_mesh_list_lock(); bt_mesh_list_lock();
sys_slist_append(&internal->queue, &node->client_node); sys_slist_append(&internal->queue, &node->client_node);
@ -492,6 +496,7 @@ int bt_mesh_client_clear_list(void *data)
bt_mesh_list_lock(); bt_mesh_list_lock();
while (!sys_slist_is_empty(&internal->queue)) { while (!sys_slist_is_empty(&internal->queue)) {
node = (void *)sys_slist_get_not_empty(&internal->queue); node = (void *)sys_slist_get_not_empty(&internal->queue);
k_delayed_work_free(&node->timer);
bt_mesh_free(node); bt_mesh_free(node);
} }
bt_mesh_list_unlock(); bt_mesh_list_unlock();