Lines Matching refs:srv

28 static void store_state(struct bt_mesh_dfu_srv *srv)  in store_state()  argument
30 bt_mesh_model_data_store(srv->mod, false, NULL, &srv->update, in store_state()
31 sizeof(srv->update)); in store_state()
34 static void erase_state(struct bt_mesh_dfu_srv *srv) in erase_state() argument
36 bt_mesh_model_data_store(srv->mod, false, NULL, NULL, 0); in erase_state()
39 static void xfer_failed(struct bt_mesh_dfu_srv *srv) in xfer_failed() argument
41 if (!bt_mesh_dfu_srv_is_busy(srv) || in xfer_failed()
42 srv->update.idx >= srv->img_count) { in xfer_failed()
46 erase_state(srv); 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()
53 static enum bt_mesh_dfu_status metadata_check(struct bt_mesh_dfu_srv *srv, in metadata_check() argument
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()
78 struct bt_mesh_dfu_srv *srv = cb_params; in apply_rsp_sent() local
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()
91 store_state(srv); in apply_rsp_sent()
96 store_state(srv); 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()
101 store_state(srv); in apply_rsp_sent()
113 static void verify(struct bt_mesh_dfu_srv *srv) in verify() argument
115 srv->update.phase = BT_MESH_DFU_PHASE_VERIFY; in verify()
117 if (srv->update.idx >= srv->img_count) { in verify()
118 bt_mesh_dfu_srv_rejected(srv); in verify()
122 if (!srv->cb->end) { in verify()
123 bt_mesh_dfu_srv_verified(srv); 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()
129 store_state(srv); in verify()
136 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_info_get() local
139 if (srv->update.phase == BT_MESH_DFU_PHASE_APPLYING) { 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()
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() local
207 status = metadata_check(srv, idx, buf, &effect); 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()
223 static void update_status_rsp(struct bt_mesh_dfu_srv *srv, in update_status_rsp() argument
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() local
254 update_status_rsp(srv, ctx, BT_MESH_DFU_SUCCESS, NULL); in handle_get()
259 static inline bool is_active_update(struct bt_mesh_dfu_srv *srv, uint8_t idx, in is_active_update() argument
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() local
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()
298 store_state(srv); in handle_start()
304 if (bt_mesh_dfu_srv_is_busy(srv)) { in handle_start()
305 if (is_active_update(srv, idx, timeout_base, &blob_id, ttl, 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()
319 status = metadata_check(srv, idx, buf, 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()
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()
341 update_status_rsp(srv, ctx, status, NULL); in handle_start()
342 verify(srv); 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()
371 store_state(srv); in handle_start()
374 update_status_rsp(srv, ctx, status, NULL); in handle_start()
382 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_cancel() local
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()
392 xfer_failed(srv); in handle_cancel()
395 update_status_rsp(srv, ctx, BT_MESH_DFU_SUCCESS, NULL); in handle_cancel()
403 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in handle_apply() local
411 if (srv->update.phase == BT_MESH_DFU_PHASE_APPLYING) { in handle_apply()
412 update_status_rsp(srv, ctx, BT_MESH_DFU_SUCCESS, NULL); 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()
418 update_status_rsp(srv, ctx, BT_MESH_DFU_ERR_WRONG_PHASE, NULL); in handle_apply()
425 srv->update.phase = BT_MESH_DFU_PHASE_APPLYING; in handle_apply()
426 update_status_rsp(srv, ctx, BT_MESH_DFU_SUCCESS, &send_cb); in handle_apply()
444 struct bt_mesh_dfu_srv *srv = mod->rt->user_data; in dfu_srv_init() local
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()
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() local
479 if (len_rd < sizeof(srv->update)) { 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()
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() local
505 srv->update.phase = BT_MESH_DFU_PHASE_IDLE; in dfu_srv_reset()
506 erase_state(srv); in dfu_srv_reset()
517 struct bt_mesh_dfu_srv *srv = CONTAINER_OF(b, struct bt_mesh_dfu_srv, blob); in blob_suspended() local
519 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ERR; in blob_suspended()
520 store_state(srv); in blob_suspended()
525 struct bt_mesh_dfu_srv *srv = in blob_end() local
531 srv->update.phase = BT_MESH_DFU_PHASE_TRANSFER_ERR; in blob_end()
532 xfer_failed(srv); in blob_end()
536 verify(srv); in blob_end()
543 struct bt_mesh_dfu_srv *srv = in blob_recover() local
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()
552 return srv->cb->recover(srv, &srv->imgs[srv->update.idx], io); in blob_recover()
561 void bt_mesh_dfu_srv_verified(struct bt_mesh_dfu_srv *srv) in bt_mesh_dfu_srv_verified() argument
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()
571 store_state(srv); in bt_mesh_dfu_srv_verified()
574 void bt_mesh_dfu_srv_rejected(struct bt_mesh_dfu_srv *srv) in bt_mesh_dfu_srv_rejected() argument
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()
584 store_state(srv); in bt_mesh_dfu_srv_rejected()
587 void bt_mesh_dfu_srv_cancel(struct bt_mesh_dfu_srv *srv) in bt_mesh_dfu_srv_cancel() argument
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()
597 void bt_mesh_dfu_srv_applied(struct bt_mesh_dfu_srv *srv) in bt_mesh_dfu_srv_applied() argument
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()
607 store_state(srv); in bt_mesh_dfu_srv_applied()
610 bool bt_mesh_dfu_srv_is_busy(const struct bt_mesh_dfu_srv *srv) in bt_mesh_dfu_srv_is_busy() argument
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()
617 uint8_t bt_mesh_dfu_srv_progress(const struct bt_mesh_dfu_srv *srv) in bt_mesh_dfu_srv_progress() argument
619 if (!bt_mesh_dfu_srv_is_busy(srv)) { in bt_mesh_dfu_srv_progress()
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()