Lines Matching +full:2 +full:- +full:phase

4  * SPDX-License-Identifier: Apache-2.0
30 bt_mesh_model_data_store(srv->mod, false, NULL, &srv->update, in store_state()
31 sizeof(srv->update)); in store_state()
36 bt_mesh_model_data_store(srv->mod, false, NULL, NULL, 0); in erase_state()
42 srv->update.idx >= srv->img_count) { in xfer_failed()
48 if (srv->cb->end) { in xfer_failed()
49 srv->cb->end(srv, &srv->imgs[srv->update.idx], false); in xfer_failed()
60 if (idx >= srv->img_count) { in metadata_check()
64 if (!srv->cb->check) { in metadata_check()
68 if (srv->cb->check(srv, &srv->imgs[idx], buf, effect)) { in metadata_check()
81 /* return phase back to give client one more chance. */ in apply_rsp_sent()
82 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY_OK; in apply_rsp_sent()
89 if (!srv->cb->apply || srv->update.idx == UPDATE_IDX_NONE) { in apply_rsp_sent()
90 srv->update.phase = BT_MESH_DFU_PHASE_IDLE; in apply_rsp_sent()
98 err = srv->cb->apply(srv, &srv->imgs[srv->update.idx]); in apply_rsp_sent()
100 srv->update.phase = BT_MESH_DFU_PHASE_IDLE; in apply_rsp_sent()
115 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY; in verify()
117 if (srv->update.idx >= srv->img_count) { in verify()
122 if (!srv->cb->end) { in verify()
127 srv->cb->end(srv, &srv->imgs[srv->update.idx], true); in verify()
128 if (srv->update.phase == BT_MESH_DFU_PHASE_VERIFY) { in verify()
136 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_info_get()
139 if (srv->update.phase == BT_MESH_DFU_PHASE_APPLYING) { in handle_info_get()
141 return -EBUSY; in handle_info_get()
151 net_buf_simple_add_u8(&rsp, srv->img_count); in handle_info_get()
154 for (; idx < srv->img_count && limit > 0; ++idx) { in handle_info_get()
157 if (!srv->imgs[idx].fwid) { in handle_info_get()
161 entry_len = 2 + srv->imgs[idx].fwid_len; in handle_info_get()
162 if (srv->imgs[idx].uri) { in handle_info_get()
163 entry_len += strlen(srv->imgs[idx].uri); in handle_info_get()
170 net_buf_simple_add_u8(&rsp, srv->imgs[idx].fwid_len); in handle_info_get()
171 net_buf_simple_add_mem(&rsp, srv->imgs[idx].fwid, in handle_info_get()
172 srv->imgs[idx].fwid_len); in handle_info_get()
174 if (srv->imgs[idx].uri) { in handle_info_get()
175 size_t len = strlen(srv->imgs[idx].uri); in handle_info_get()
178 net_buf_simple_add_mem(&rsp, srv->imgs[idx].uri, len); in handle_info_get()
183 limit--; in handle_info_get()
186 if (srv->update.phase != BT_MESH_DFU_PHASE_IDLE) { in handle_info_get()
187 ctx->send_ttl = srv->update.ttl; in handle_info_get()
198 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_metadata_check()
203 BT_MESH_MODEL_BUF_DEFINE(rsp, BT_MESH_DFU_OP_UPDATE_METADATA_STATUS, 2); in handle_metadata_check()
214 if (srv->update.phase != BT_MESH_DFU_PHASE_IDLE) { in handle_metadata_check()
215 ctx->send_ttl = srv->update.ttl; in handle_metadata_check()
232 (srv->update.phase << 5))); in update_status_rsp()
234 if (srv->update.phase != BT_MESH_DFU_PHASE_IDLE) { in update_status_rsp()
235 net_buf_simple_add_u8(&buf, srv->update.ttl); in update_status_rsp()
236 net_buf_simple_add_u8(&buf, srv->update.effect); in update_status_rsp()
237 net_buf_simple_add_le16(&buf, srv->update.timeout_base); in update_status_rsp()
238 net_buf_simple_add_le64(&buf, srv->blob.state.xfer.id); in update_status_rsp()
239 net_buf_simple_add_u8(&buf, srv->update.idx); in update_status_rsp()
241 ctx->send_ttl = srv->update.ttl; in update_status_rsp()
244 bt_mesh_model_send(srv->mod, ctx, &buf, send_cb, srv); in update_status_rsp()
250 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_get()
264 return (srv->update.idx != idx || srv->blob.state.xfer.id != *blob_id || in is_active_update()
265 srv->update.ttl != ttl || in is_active_update()
266 srv->update.timeout_base != timeout_base || in is_active_update()
267 srv->update.meta != meta_checksum); in is_active_update()
273 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_start()
290 if ((!buf->len || meta_checksum == srv->update.meta) && in handle_start()
291 srv->update.phase == BT_MESH_DFU_PHASE_TRANSFER_ERR && in handle_start()
292 srv->update.ttl == ttl && in handle_start()
293 srv->update.timeout_base == timeout_base && in handle_start()
294 srv->update.idx == idx && in handle_start()
295 srv->blob.state.xfer.id == blob_id) { in handle_start()
296 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ACTIVE; in handle_start()
310 srv->update.ttl = ttl; in handle_start()
311 srv->blob.state.xfer.id = blob_id; in handle_start()
314 LOG_WRN("Busy. Phase: %u", srv->update.phase); in handle_start()
320 (enum bt_mesh_dfu_effect *)&srv->update.effect); in handle_start()
326 srv->update.ttl = ttl; in handle_start()
327 srv->update.timeout_base = timeout_base; in handle_start()
328 srv->update.meta = meta_checksum; in handle_start()
331 err = srv->cb->start(srv, &srv->imgs[idx], buf, &io); in handle_start()
332 if (err == -EALREADY || (!err && bt_mesh_has_addr(ctx->addr))) { in handle_start()
334 * self-update. Skip the transfer phase and proceed to in handle_start()
338 srv->update.idx = idx; in handle_start()
339 srv->blob.state.xfer.id = blob_id; in handle_start()
340 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY; in handle_start()
346 if (err == -ENOMEM) { in handle_start()
351 if (err == -EBUSY) { in handle_start()
356 if (err || !io || !io->wr) { in handle_start()
361 err = bt_mesh_blob_srv_recv(&srv->blob, blob_id, io, in handle_start()
368 srv->update.idx = idx; in handle_start()
369 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ACTIVE; in handle_start()
382 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_cancel()
384 if (srv->update.idx == UPDATE_IDX_NONE) { in handle_cancel()
390 bt_mesh_blob_srv_cancel(&srv->blob); in handle_cancel()
391 srv->update.phase = BT_MESH_DFU_PHASE_IDLE; in handle_cancel()
403 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_apply()
411 if (srv->update.phase == BT_MESH_DFU_PHASE_APPLYING) { in handle_apply()
416 if (srv->update.phase != BT_MESH_DFU_PHASE_VERIFY_OK) { in handle_apply()
417 LOG_WRN("Apply: Invalid phase %u", srv->update.phase); in handle_apply()
425 srv->update.phase = BT_MESH_DFU_PHASE_APPLYING; in handle_apply()
432 { BT_MESH_DFU_OP_UPDATE_INFO_GET, BT_MESH_LEN_EXACT(2), handle_info_get },
444 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in dfu_srv_init()
446 srv->mod = mod; in dfu_srv_init()
447 srv->update.idx = UPDATE_IDX_NONE; in dfu_srv_init()
449 if (!srv->cb || !srv->cb->start || !srv->imgs || srv->img_count == 0 || in dfu_srv_init()
450 srv->img_count == UPDATE_IDX_NONE) { in dfu_srv_init()
452 return -EINVAL; in dfu_srv_init()
460 return -EINVAL; in dfu_srv_init()
463 err = bt_mesh_model_extend(mod, srv->blob.mod); in dfu_srv_init()
476 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in dfu_srv_settings_set()
479 if (len_rd < sizeof(srv->update)) { in dfu_srv_settings_set()
480 return -EINVAL; in dfu_srv_settings_set()
483 len = read_cb(cb_arg, &srv->update, sizeof(srv->update)); in dfu_srv_settings_set()
488 LOG_DBG("Recovered transfer (phase: %u, idx: %u)", srv->update.phase, in dfu_srv_settings_set()
489 srv->update.idx); in dfu_srv_settings_set()
490 if (srv->update.phase == BT_MESH_DFU_PHASE_TRANSFER_ACTIVE) { in dfu_srv_settings_set()
491 LOG_DBG("Settings recovered mid-transfer, setting transfer error"); in dfu_srv_settings_set()
492 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ERR; in dfu_srv_settings_set()
493 } else if (srv->update.phase == BT_MESH_DFU_PHASE_VERIFY_OK) { in dfu_srv_settings_set()
495 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY_FAIL; in dfu_srv_settings_set()
503 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in dfu_srv_reset()
505 srv->update.phase = BT_MESH_DFU_PHASE_IDLE; in dfu_srv_reset()
519 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ERR; in blob_suspended()
531 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ERR; in blob_end()
546 if (!srv->cb->recover || in blob_recover()
547 srv->update.phase != BT_MESH_DFU_PHASE_TRANSFER_ERR || in blob_recover()
548 srv->update.idx >= srv->img_count) { in blob_recover()
549 return -ENOTSUP; in blob_recover()
552 return srv->cb->recover(srv, &srv->imgs[srv->update.idx], io); in blob_recover()
563 if (srv->update.phase != BT_MESH_DFU_PHASE_VERIFY) { in bt_mesh_dfu_srv_verified()
570 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY_OK; in bt_mesh_dfu_srv_verified()
576 if (srv->update.phase != BT_MESH_DFU_PHASE_VERIFY) { in bt_mesh_dfu_srv_rejected()
583 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY_FAIL; in bt_mesh_dfu_srv_rejected()
589 if (srv->update.phase == BT_MESH_DFU_PHASE_IDLE) { in bt_mesh_dfu_srv_cancel()
594 (void)bt_mesh_blob_srv_cancel(&srv->blob); in bt_mesh_dfu_srv_cancel()
599 if (srv->update.phase != BT_MESH_DFU_PHASE_APPLYING) { in bt_mesh_dfu_srv_applied()
606 srv->update.phase = BT_MESH_DFU_PHASE_IDLE; in bt_mesh_dfu_srv_applied()
612 return srv->update.phase != BT_MESH_DFU_PHASE_IDLE && in bt_mesh_dfu_srv_is_busy()
613 srv->update.phase != BT_MESH_DFU_PHASE_TRANSFER_ERR && in bt_mesh_dfu_srv_is_busy()
614 srv->update.phase != BT_MESH_DFU_PHASE_VERIFY_FAIL; in bt_mesh_dfu_srv_is_busy()
623 if (srv->update.phase == BT_MESH_DFU_PHASE_TRANSFER_ACTIVE) { in bt_mesh_dfu_srv_progress()
624 return bt_mesh_blob_srv_progress(&srv->blob); in bt_mesh_dfu_srv_progress()