libwebsockets
Lightweight C library for HTML5 websockets
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 
41 typedef void * lws_ota_process_t;
42 
43 typedef enum {
45  LWSOTARET_ONGOING, /* result not ready to read yet */
48 
54 
55 typedef enum {
61 
62 struct lws_ota;
63 
64 typedef void (*lws_ota_cb_t)(void *ctx, lws_ota_ret_t r);
65 
66 typedef struct {
67 
68  /* asynchronous (completions via lws_cancel_service) */
69 
70  int (*ota_start)(struct lws_ota *g);
73  void (*ota_queue)(struct lws_ota *g, lws_ota_async_t a);
76  /* synchronous */
77 
78  int (*ota_report_current)(struct lws_ota *g, int bad);
85  int (*ota_progress)(lws_ota_ret_t state, int percent);
89  int (*ota_get_last_fw_unixtime)(uint64_t *fw_unixtime);
97 
105 LWS_VISIBLE LWS_EXTERN const char *
107 
109 lws_plat_ota_start(struct lws_ota *g);
110 
111 
112 #define LWSOTAFIN_OK 0
113 #define LWSOTAFIN_BAD 1
114 
116 lws_plat_ota_queue(struct lws_ota *g, lws_ota_async_t a);
117 
119 lws_plat_ota_report_current(struct lws_ota *g, int bad);
120 
122 lws_plat_ota_get_last_fw_unixtime(uint64_t *fw_unixtime);
#define LWS_EXTERN
#define LWS_VISIBLE
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)
LWS_VISIBLE LWS_EXTERN void lws_plat_ota_queue(struct lws_ota *g, lws_ota_async_t a)
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
void * lws_ota_process_t
Definition: lws-ota.h:41
LWS_VISIBLE LWS_EXTERN const char * lws_ota_variant_name(void)
void(* lws_ota_cb_t)(void *ctx, lws_ota_ret_t r)
Definition: lws-ota.h:64
int ota_periodic_check_secs
Definition: lws-ota.h:94