libwebsockets
Lightweight C library for HTML5 websockets
lws-esp32.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 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 only included from libwebsockets.h if LWS_WITH_ESP32
25  */
26 
27 /* ESP32 helper declarations */
28 
29 #include <mdns.h>
30 #include <esp_partition.h>
31 
32 #define LWS_PLUGIN_STATIC
33 #define LWS_MAGIC_REBOOT_TYPE_ADS 0x50001ffc
34 #define LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY 0xb00bcafe
35 #define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY 0xfaceb00b
36 #define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON 0xf0cedfac
37 #define LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY_ERASE_OTA 0xfac0eeee
38 
39 /* user code provides these */
40 
41 extern void
42 lws_esp32_identify_physical_device(void);
43 
44 /* lws-plat-esp32 provides these */
45 
46 typedef void (*lws_cb_scan_done)(uint16_t count, wifi_ap_record_t *recs, void *arg);
47 
48 enum genled_state {
49  LWSESP32_GENLED__INIT,
50  LWSESP32_GENLED__LOST_NETWORK,
51  LWSESP32_GENLED__NO_NETWORK,
52  LWSESP32_GENLED__CONN_AP,
53  LWSESP32_GENLED__GOT_IP,
54  LWSESP32_GENLED__OK,
55 };
56 
58  struct lws_group_member *next;
59  uint64_t last_seen;
60  char model[16];
61  char role[16];
62  char host[32];
63  char mac[20];
64  int width, height;
65  struct ip4_addr addr;
66  struct ip6_addr addrv6;
67  uint8_t flags;
68 };
69 
70 #define LWS_SYSTEM_GROUP_MEMBER_ADD 1
71 #define LWS_SYSTEM_GROUP_MEMBER_CHANGE 2
72 #define LWS_SYSTEM_GROUP_MEMBER_REMOVE 3
73 
74 #define LWS_GROUP_FLAG_SELF 1
75 
76 struct lws_esp32 {
77  char sta_ip[16];
78  char sta_mask[16];
79  char sta_gw[16];
80  char serial[16];
81  char opts[16];
82  char model[16];
83  char group[16];
84  char role[16];
85  char ssid[4][64];
86  char password[4][64];
87  char active_ssid[64];
88  char access_pw[16];
89  char hostname[32];
90  char mac[20];
91  char le_dns[64];
92  char le_email[64];
93  char region;
94  char inet;
95  char conn_ap;
96 
97  enum genled_state genled;
98  uint64_t genled_t;
99 
100  lws_cb_scan_done scan_consumer;
101  void *scan_consumer_arg;
102  struct lws_group_member *first;
103  int extant_group_members;
104 
105  char acme;
106  char upload;
107 
108  volatile char button_is_down;
109 };
110 
112  uint32_t romfs;
113  uint32_t romfs_len;
114  uint32_t json;
115  uint32_t json_len;
116 };
117 
118 extern struct lws_esp32 lws_esp32;
119 struct lws_vhost;
120 
121 extern esp_err_t
122 lws_esp32_event_passthru(void *ctx, system_event_t *event);
123 extern void
124 lws_esp32_wlan_config(void);
125 extern void
126 lws_esp32_wlan_start_ap(void);
127 extern void
128 lws_esp32_wlan_start_station(void);
130 extern void
131 lws_esp32_set_creation_defaults(struct lws_context_creation_info *info);
132 extern struct lws_context *
133 lws_esp32_init(struct lws_context_creation_info *, struct lws_vhost **pvh);
134 extern int
135 lws_esp32_wlan_nvs_get(int retry);
136 extern esp_err_t
137 lws_nvs_set_str(nvs_handle handle, const char* key, const char* value);
138 extern void
139 lws_esp32_restart_guided(uint32_t type);
140 extern const esp_partition_t *
141 lws_esp_ota_get_boot_partition(void);
142 extern int
143 lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i, char *json, int json_len);
144 extern int
145 lws_esp32_leds_network_indication(void);
146 
147 extern uint32_t lws_esp32_get_reboot_type(void);
148 extern uint16_t lws_esp32_sine_interp(int n);
149 
150 /* required in external code by esp32 plat (may just return if no leds) */
151 extern void lws_esp32_leds_timer_cb(TimerHandle_t th);
152 
153 #endif /* LWS_AMAZON_RTOS */
Definition: lws-esp32.h:76
Definition: lws-context-vhost.h:239
Definition: lws-esp32.h:57
Definition: lws-esp32.h:111