1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
26
27
28
29
34
35
36
40
41
42
43
51
52
57
58
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
102
103
104
108
109
110
116
117
118
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
269
270
271
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
305
306
307
308
309
310
314
315
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
383
387
391
395
399
400
/* ... */
#ifndef OS_H
#define OS_H
#include <sys/types.h>
#include "esp_types.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "esp_err.h"
#include "supplicant_opt.h"
#include "esp_private/esp_wifi_private.h"
#include "esp_wifi.h"9 includes
typedef time_t os_time_t;
/* ... */
void os_sleep(os_time_t sec, os_time_t usec);
struct os_time {
os_time_t sec;
suseconds_t usec;
}{ ... };
#define os_reltime os_time
struct os_tm {
int sec;
int min;
int hour;
int day;
int month;
int year;
}{ ... };
/* ... */
int os_get_time(struct os_time *t);
#define os_get_reltime os_get_time
#define os_time_before(a, b) \
((a)->sec < (b)->sec || \
((a)->sec == (b)->sec && (a)->usec < (b)->usec))...
#define os_reltime_before os_time_before
#define os_time_sub(a, b, res) do { \
(res)->sec = (a)->sec - (b)->sec; \
(res)->usec = (a)->usec - (b)->usec; \
if ((res)->usec < 0) { \
(res)->sec--; \
(res)->usec += 1000000; \
}{...} \
}{...} while (0)...
#define os_reltime_sub os_time_sub5 defines
/* ... */
int os_mktime(int year, int month, int day, int hour, int min, int sec,
os_time_t *t);
int os_gmtime(os_time_t t, struct os_tm *tm);
/* ... */
int os_daemonize(const char *pid_file);
/* ... */
void os_daemonize_terminate(const char *pid_file);
/* ... */
int os_get_random(unsigned char *buf, size_t len);
/* ... */
unsigned long os_random(void);
/* ... */
char * os_rel2abs_path(const char *rel_path);
/* ... */
int os_program_init(void);
/* ... */
void os_program_deinit(void);
/* ... */
int os_setenv(const char *name, const char *value, int overwrite);
/* ... */
int os_unsetenv(const char *name);
/* ... */
static inline char *os_readfile(const char *name, size_t *len)
{
return NULL;
}{ ... }
/* ... */
#ifndef os_malloc
#define os_malloc(s) malloc((s))
#endif
#ifndef os_realloc
#define os_realloc(p, s) realloc((p), (s))
#endif
#ifndef os_zalloc
#define os_zalloc(s) calloc(1, (s))
#endif
#ifndef os_calloc
#define os_calloc(p, s) calloc((p), (s))
#endif
#ifndef os_free
#define os_free(p) free((p))
#endif
#ifndef os_bzero
#define os_bzero(s, n) bzero(s, n)
#endif
#ifndef os_strdup
#ifdef _MSC_VER
#define os_strdup(s) _strdup(s)
#else
#define os_strdup(s) strdup(s)
#endif/* ... */
#endif
char * ets_strdup(const char *s);
#ifndef os_memcpy
#define os_memcpy(d, s, n) memcpy((d), (s), (n))
#endif
#ifndef os_memmove
#define os_memmove(d, s, n) memmove((d), (s), (n))
#endif
#ifndef os_memset
#define os_memset(s, c, n) memset(s, c, n)
#endif
#ifndef os_memcmp
#define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
#endif
#ifndef os_memcmp_const
#define os_memcmp_const(s1, s2, n) memcmp((s1), (s2), (n))
#endif
#ifndef os_strlen
#define os_strlen(s) strlen(s)
#endif
#ifndef os_strcasecmp
#ifdef _MSC_VER
#define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
#else
#define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
#endif/* ... */
#endif
#ifndef os_strncasecmp
#ifdef _MSC_VER
#define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
#else
#define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
#endif/* ... */
#endif
#ifndef os_strchr
#define os_strchr(s, c) strchr((s), (c))
#endif
#ifndef os_strcmp
#define os_strcmp(s1, s2) strcmp((s1), (s2))
#endif
#ifndef os_strncmp
#define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
#endif
#ifndef os_strrchr
#define os_strrchr(s, c) strrchr((s), (c))
#endif
#ifndef os_strstr
#define os_strstr(h, n) strstr((h), (n))
#endif
#ifndef os_strlcpy
#define os_strlcpy(d, s, n) strlcpy((d), (s), (n))
#endif
#ifndef os_strcat
#define os_strcat(d, s) strcat((d), (s))
#endif
#ifndef os_snprintf
#ifdef _MSC_VER
#define os_snprintf _snprintf
#else
#define os_snprintf snprintf
#endif/* ... */
#endif
#ifndef os_sprintf
#define os_sprintf sprintf
#endif
static inline int os_snprintf_error(size_t size, int res)
{
return res < 0 || (unsigned int) res >= size;
}{ ... }
static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
{
if (size && nmemb > (~(size_t) 0) / size)
return NULL;
return os_realloc(ptr, nmemb * size);
}{ ... }
#ifdef CONFIG_CRYPTO_MBEDTLS
void forced_memzero(void *ptr, size_t len);
#else
/* ... */
static void * (* const volatile memset_func)(void *, int, size_t) = memset;
static uint8_t forced_memzero_val;
static inline void forced_memzero(void *ptr, size_t len)
{
memset_func(ptr, 0, len);
if (len) {
forced_memzero_val = ((uint8_t *) ptr)[0];
}{...}
}{ ... }
#endif/* ... */
extern const wifi_osi_funcs_t *wifi_funcs;
#define OS_BLOCK OSI_FUNCS_TIME_BLOCKING
#define os_mutex_lock(a) wifi_funcs->_mutex_lock((a))
#define os_mutex_unlock(a) wifi_funcs->_mutex_unlock((a))
#define os_recursive_mutex_create() wifi_funcs->_recursive_mutex_create()
#define os_mutex_create() wifi_funcs->_mutex_create();
#define os_mutex_delete(a) wifi_funcs->_mutex_delete(a)
#define os_queue_create(a, b) wifi_funcs->_queue_create((a), (b))
#define os_queue_delete(a) wifi_funcs->_queue_delete(a)
#define os_queue_send(a, b, c) wifi_funcs->_queue_send((a), (b), (c))
#define os_queue_send_to_front(a, b, c) wifi_funcs->_queue_send_to_front((a), (b), (c))
#define os_queue_recv(a, b, c) wifi_funcs->_queue_recv((a), (b), (c))
#define os_queue_msg_waiting(a) wifi_funcs->_queue_msg_waiting((a))
#define os_task_create(a,b,c,d,e,f) wifi_funcs->_task_create((a), (b), (c), (d), (e), (f))
#define os_task_delete(a) wifi_funcs->_task_delete((a))
#define os_task_get_current_task() wifi_funcs->_task_get_current_task()
#define os_semphr_create(a, b) wifi_funcs->_semphr_create((a), (b))
#define os_semphr_delete(a) wifi_funcs->_semphr_delete((a))
#define os_semphr_give(a) wifi_funcs->_semphr_give((a))
#define os_semphr_take(a, b) wifi_funcs->_semphr_take((a), (b))
#define os_task_ms_to_tick(a) wifi_funcs->_task_ms_to_tick((a))
#define os_timer_get_time(void) wifi_funcs->_esp_timer_get_time(void)
#define os_event_group_create(void) wifi_funcs->_event_group_create(void)
#define os_event_group_delete(void) wifi_funcs->_event_group_delete(void)
#define os_event_group_wait_bits(a, b, c, d, e) wifi_funcs->_event_group_wait_bits((a), (b), (c), (d), (e))
#define os_event_group_clear_bits(a, b) wifi_funcs->_event_group_clear_bits((a), (b))
#define os_event_group_set_bits(a, b) wifi_funcs->_event_group_set_bits((a), (b))26 defines
static inline void os_timer_setfn(void *ptimer, void *pfunction, void *parg)
{
return wifi_funcs->_timer_setfn(ptimer, pfunction, parg);
}{ ... }
static inline void os_timer_disarm(void *ptimer)
{
return wifi_funcs->_timer_disarm(ptimer);
}{ ... }
static inline void os_timer_arm_us(void *ptimer,uint32_t u_seconds,bool repeat_flag)
{
return wifi_funcs->_timer_arm_us(ptimer, u_seconds, repeat_flag);
}{ ... }
static inline void os_timer_arm(void *ptimer,uint32_t milliseconds,bool repeat_flag)
{
return wifi_funcs->_timer_arm(ptimer, milliseconds, repeat_flag);
}{ ... }
static inline void os_timer_done(void *ptimer)
{
return wifi_funcs->_timer_done(ptimer);
}{ ... }
/* ... */#endif