libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-ota.h
Go to the documentation of this file.
1/*
2 * lws OTA updates
3 *
4 * Copyright (C) 2019 - 2022 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * This is the platform interface that lws_ota uses to flash new firmware.
25 * The platform implementation for these ops is set via lws_system and consists
26 * of user code.
27 *
28 * All the update-related calls have async interfaces with a callback and opaque
29 * callback context that is called on completion. This allows us to, eg,
30 * download the next buffer while flashing the previous one.
31 *
32 * If the platform implementation is actually synchronous, then just call the
33 * callback before returning.
34 *
35 * If it is async, because eg, erase is slow, in the platform ota op
36 * implementation spawn a thread to do the platform operation, return
37 * immediately with LWSOTARET_ONGOING, and call the callback from the spawned
38 * thread context with the real return before terminating the thread.
39 */
40
41typedef void * lws_ota_process_t;
42
54
61
62struct lws_ota;
63
64typedef void (*lws_ota_cb_t)(void *ctx, lws_ota_ret_t r);
65
66typedef struct {
67
68 /* asynchronous (completions via lws_cancel_service) */
69
70 int (*ota_start)(struct lws_ota *g);
72
73 void (*ota_queue)(struct lws_ota *g, lws_ota_async_t a);
75
76 /* synchronous */
77
78 int (*ota_report_current)(struct lws_ota *g, int bad);
84
85 int (*ota_progress)(lws_ota_ret_t state, int percent);
88
89 int (*ota_get_last_fw_unixtime)(uint64_t *fw_unixtime);
93
97
104
105LWS_VISIBLE LWS_EXTERN const char *
107
109lws_plat_ota_start(struct lws_ota *g);
110
111
112#define LWSOTAFIN_OK 0
113#define LWSOTAFIN_BAD 1
114
117
119lws_plat_ota_report_current(struct lws_ota *g, int bad);
120
#define LWS_EXTERN
#define LWS_VISIBLE
void(* ota_queue)(struct lws_ota *g, lws_ota_async_t a)
Definition lws-ota.h:73
LWS_VISIBLE LWS_EXTERN const char * lws_ota_variant_name(void)
LWS_VISIBLE LWS_EXTERN int lws_plat_ota_get_last_fw_unixtime(uint64_t *fw_unixtime)
LWS_VISIBLE LWS_EXTERN int lws_plat_ota_start(struct lws_ota *g)
LWS_VISIBLE LWS_EXTERN int lws_plat_ota_report_current(struct lws_ota *g, int bad)
int(* ota_get_last_fw_unixtime)(uint64_t *fw_unixtime)
Definition lws-ota.h:89
int ota_periodic_check_secs
Definition lws-ota.h:94
LWS_VISIBLE LWS_EXTERN void lws_plat_ota_queue(struct lws_ota *g, lws_ota_async_t a)
int(* ota_report_current)(struct lws_ota *g, int bad)
Definition lws-ota.h:78
lws_ota_async_t
Definition lws-ota.h:55
@ LWS_OTA_ASYNC_START
Definition lws-ota.h:56
@ LWS_OTA_ASYNC_WRITE
Definition lws-ota.h:57
@ LWS_OTA_ASYNC_ABORT
Definition lws-ota.h:58
@ LWS_OTA_ASYNC_FINALIZE
Definition lws-ota.h:59
lws_ota_ret_t
Definition lws-ota.h:43
@ LWSOTARET_UPDATE_AVAILABLE
Definition lws-ota.h:49
@ LWSOTARET_REJECTED
Definition lws-ota.h:46
@ LWSOTARET_OK
Definition lws-ota.h:44
@ LWSOTARET_PROGRESS
Definition lws-ota.h:50
@ LWSOTARET_NOSLOT
Definition lws-ota.h:47
@ LWSOTARET_FAILED
Definition lws-ota.h:51
@ LWSOTARET_ONGOING
Definition lws-ota.h:45
@ LWSOTARET_COMPLETED
Definition lws-ota.h:52
int(* ota_start)(struct lws_ota *g)
Definition lws-ota.h:70
void * lws_ota_process_t
Definition lws-ota.h:41
int(* ota_progress)(lws_ota_ret_t state, int percent)
Definition lws-ota.h:85
void(* lws_ota_cb_t)(void *ctx, lws_ota_ret_t r)
Definition lws-ota.h:64