1 /*
2 * OS specific functions
3 * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #ifndef OS_H
10 #define OS_H
11
12 #ifdef LOS_WPA_PATCH
13 #include "includes.h"
14 #include "wifi_osdep.h"
15 #ifndef EXT_CODE_CROP
16 #include "ctype.h"
17 #endif /* EXT_CODE_CROP */
18 typedef long os_time_t;
19 #ifndef OSS_TICKS_PER_SEC
20 #define OSS_TICKS_PER_SEC 100
21 #endif
22
23 #define TICKS_TO_MSEC(ticks) (((ticks) * 1000) / OSS_TICKS_PER_SEC)
24 #define MSEC_TO_TICKS(ms) (((ms) * OSS_TICKS_PER_SEC) / 1000)
25 #endif /* LOS_WPA_PATCH */
26
27 /**
28 * os_sleep - Sleep (sec, usec)
29 * @sec: Number of seconds to sleep
30 * @usec: Number of microseconds to sleep
31 */
32 void os_sleep(os_time_t sec, os_time_t usec);
33
34 struct os_time {
35 os_time_t sec;
36 os_time_t usec;
37 };
38
39 struct os_reltime {
40 os_time_t sec;
41 os_time_t usec;
42 };
43
44 /**
45 * os_get_time - Get current time (sec, usec)
46 * @t: Pointer to buffer for the time
47 * Returns: 0 on success, -1 on failure
48 */
49 int os_get_time(struct os_time *t);
50
51 /**
52 * os_get_reltime - Get relative time (sec, usec)
53 * @t: Pointer to buffer for the time
54 * Returns: 0 on success, -1 on failure
55 */
56 int os_get_reltime(struct os_reltime *t);
57
58
59 /* Helpers for handling struct os_time */
60
os_time_before(struct os_time * a,struct os_time * b)61 static inline int os_time_before(struct os_time *a, struct os_time *b)
62 {
63 return (a->sec < b->sec) ||
64 (a->sec == b->sec && a->usec < b->usec);
65 }
66
67
os_time_sub(struct os_time * a,struct os_time * b,struct os_time * res)68 static inline void os_time_sub(struct os_time *a, struct os_time *b,
69 struct os_time *res)
70 {
71 res->sec = a->sec - b->sec;
72 res->usec = a->usec - b->usec;
73 if (res->usec < 0) {
74 res->sec--;
75 res->usec += 1000000;
76 }
77 }
78
79
80 /* Helpers for handling struct os_reltime */
81 #ifndef LOS_INLINE_FUNC_CROP
os_reltime_before(struct os_reltime * a,struct os_reltime * b)82 static inline int os_reltime_before(struct os_reltime *a,
83 struct os_reltime *b)
84 {
85 return (a->sec < b->sec) ||
86 (a->sec == b->sec && a->usec < b->usec);
87 }
88
89
os_reltime_sub(struct os_reltime * a,struct os_reltime * b,struct os_reltime * res)90 static inline void os_reltime_sub(struct os_reltime *a, struct os_reltime *b,
91 struct os_reltime *res)
92 {
93 res->sec = a->sec - b->sec;
94 res->usec = a->usec - b->usec;
95 if (res->usec < 0) {
96 res->sec--;
97 res->usec += 1000000;
98 }
99 }
100 #else
101 int os_reltime_before(struct os_reltime *a,
102 struct os_reltime *b);
103
104 void os_reltime_sub(struct os_reltime *a, struct os_reltime *b,
105 struct os_reltime *res);
106 #endif /* LOS_INLINE_FUNC_CROP */
107
os_reltime_age(struct os_reltime * start,struct os_reltime * age)108 static inline void os_reltime_age(struct os_reltime *start,
109 struct os_reltime *age)
110 {
111 struct os_reltime now;
112
113 os_get_reltime(&now);
114 os_reltime_sub(&now, start, age);
115 }
116
117
os_reltime_expired(struct os_reltime * now,struct os_reltime * ts,os_time_t timeout_secs)118 static inline int os_reltime_expired(struct os_reltime *now,
119 struct os_reltime *ts,
120 os_time_t timeout_secs)
121 {
122 struct os_reltime age;
123
124 os_reltime_sub(now, ts, &age);
125 return (age.sec > timeout_secs) ||
126 (age.sec == timeout_secs && age.usec > 0);
127 }
128
129
os_reltime_initialized(struct os_reltime * t)130 static inline int os_reltime_initialized(struct os_reltime *t)
131 {
132 return t->sec != 0 || t->usec != 0;
133 }
134
135
136 /**
137 * os_mktime - Convert broken-down time into seconds since 1970-01-01
138 * @year: Four digit year
139 * @month: Month (1 .. 12)
140 * @day: Day of month (1 .. 31)
141 * @hour: Hour (0 .. 23)
142 * @min: Minute (0 .. 59)
143 * @sec: Second (0 .. 60)
144 * @t: Buffer for returning calendar time representation (seconds since
145 * 1970-01-01 00:00:00)
146 * Returns: 0 on success, -1 on failure
147 *
148 * Note: The result is in seconds from Epoch, i.e., in UTC, not in local time
149 * which is used by POSIX mktime().
150 */
151 int os_mktime(int year, int month, int day, int hour, int min, int sec,
152 os_time_t *t);
153
154 struct os_tm {
155 int sec; /* 0..59 or 60 for leap seconds */
156 int min; /* 0..59 */
157 int hour; /* 0..23 */
158 int day; /* 1..31 */
159 int month; /* 1..12 */
160 int year; /* Four digit year */
161 };
162
163 int os_gmtime(os_time_t t, struct os_tm *tm);
164
165 #ifndef EXT_CODE_CROP
166 /**
167 * os_daemonize - Run in the background (detach from the controlling terminal)
168 * @pid_file: File name to write the process ID to or %NULL to skip this
169 * Returns: 0 on success, -1 on failure
170 */
171 int os_daemonize(const char *pid_file);
172
173 /**
174 * os_daemonize_terminate - Stop running in the background (remove pid file)
175 * @pid_file: File name to write the process ID to or %NULL to skip this
176 */
177 void os_daemonize_terminate(const char *pid_file);
178 #endif /* EXT_CODE_CROP */
179
180 /**
181 * os_get_random - Get cryptographically strong pseudo random data
182 * @buf: Buffer for pseudo random data
183 * @len: Length of the buffer
184 * Returns: 0 on success, -1 on failure
185 */
186 int os_get_random(unsigned char *buf, size_t len);
187
188 /**
189 * os_random - Get pseudo random value (not necessarily very strong)
190 * Returns: Pseudo random value
191 */
192 unsigned long os_random(void);
193
194 /**
195 * os_rel2abs_path - Get an absolute path for a file
196 * @rel_path: Relative path to a file
197 * Returns: Absolute path for the file or %NULL on failure
198 *
199 * This function tries to convert a relative path of a file to an absolute path
200 * in order for the file to be found even if current working directory has
201 * changed. The returned value is allocated and caller is responsible for
202 * freeing it. It is acceptable to just return the same path in an allocated
203 * buffer, e.g., return strdup(rel_path). This function is only used to find
204 * configuration files when os_daemonize() may have changed the current working
205 * directory and relative path would be pointing to a different location.
206 */
207 char * os_rel2abs_path(const char *rel_path);
208
209 /**
210 * os_program_init - Program initialization (called at start)
211 * Returns: 0 on success, -1 on failure
212 *
213 * This function is called when a programs starts. If there are any OS specific
214 * processing that is needed, it can be placed here. It is also acceptable to
215 * just return 0 if not special processing is needed.
216 */
217 int os_program_init(void);
218
219 /**
220 * os_program_deinit - Program deinitialization (called just before exit)
221 *
222 * This function is called just before a program exists. If there are any OS
223 * specific processing, e.g., freeing resourced allocated in os_program_init(),
224 * it should be done here. It is also acceptable for this function to do
225 * nothing.
226 */
227 void os_program_deinit(void);
228
229 /**
230 * os_setenv - Set environment variable
231 * @name: Name of the variable
232 * @value: Value to set to the variable
233 * @overwrite: Whether existing variable should be overwritten
234 * Returns: 0 on success, -1 on error
235 *
236 * This function is only used for wpa_cli action scripts. OS wrapper does not
237 * need to implement this if such functionality is not needed.
238 */
239 int os_setenv(const char *name, const char *value, int overwrite);
240
241 /**
242 * os_unsetenv - Delete environent variable
243 * @name: Name of the variable
244 * Returns: 0 on success, -1 on error
245 *
246 * This function is only used for wpa_cli action scripts. OS wrapper does not
247 * need to implement this if such functionality is not needed.
248 */
249 int os_unsetenv(const char *name);
250
251 /**
252 * os_readfile - Read a file to an allocated memory buffer
253 * @name: Name of the file to read
254 * @len: For returning the length of the allocated buffer
255 * Returns: Pointer to the allocated buffer or %NULL on failure
256 *
257 * This function allocates memory and reads the given file to this buffer. Both
258 * binary and text files can be read with this function. The caller is
259 * responsible for freeing the returned buffer with os_free().
260 */
261 char * os_readfile(const char *name, size_t *len);
262
263 /**
264 * os_file_exists - Check whether the specified file exists
265 * @fname: Path and name of the file
266 * Returns: 1 if the file exists or 0 if not
267 */
268 int os_file_exists(const char *fname);
269
270 /**
271 * os_fdatasync - Sync a file's (for a given stream) state with storage device
272 * @stream: the stream to be flushed
273 * Returns: 0 if the operation succeeded or -1 on failure
274 */
275 int os_fdatasync(FILE *stream);
276
277 /**
278 * os_zalloc - Allocate and zero memory
279 * @size: Number of bytes to allocate
280 * Returns: Pointer to allocated and zeroed memory or %NULL on failure
281 *
282 * Caller is responsible for freeing the returned buffer with os_free().
283 */
284 void * os_zalloc(size_t size);
285
286 /**
287 * os_calloc - Allocate and zero memory for an array
288 * @nmemb: Number of members in the array
289 * @size: Number of bytes in each member
290 * Returns: Pointer to allocated and zeroed memory or %NULL on failure
291 *
292 * This function can be used as a wrapper for os_zalloc(nmemb * size) when an
293 * allocation is used for an array. The main benefit over os_zalloc() is in
294 * having an extra check to catch integer overflows in multiplication.
295 *
296 * Caller is responsible for freeing the returned buffer with os_free().
297 */
298 #ifndef LOS_INLINE_FUNC_CROP
os_calloc(size_t nmemb,size_t size)299 static inline void * os_calloc(size_t nmemb, size_t size)
300 {
301 if (size && nmemb > (~(size_t) 0) / size)
302 return NULL;
303 return os_zalloc(nmemb * size);
304 }
305 #else
306 void * os_calloc(size_t nmemb, size_t size);
307 #endif /* LOS_INLINE_FUNC_CROP */
308
309 /*
310 * The following functions are wrapper for standard ANSI C or POSIX functions.
311 * By default, they are just defined to use the standard function name and no
312 * os_*.c implementation is needed for them. This avoids extra function calls
313 * by allowing the C pre-processor take care of the function name mapping.
314 *
315 * If the target system uses a C library that does not provide these functions,
316 * build_config.h can be used to define the wrappers to use a different
317 * function name. This can be done on function-by-function basis since the
318 * defines here are only used if build_config.h does not define the os_* name.
319 * If needed, os_*.c file can be used to implement the functions that are not
320 * included in the C library on the target system. Alternatively,
321 * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
322 * these functions need to be implemented in os_*.c file for the target system.
323 */
324
325 #ifdef OS_NO_C_LIB_DEFINES
326
327 /**
328 * os_malloc - Allocate dynamic memory
329 * @size: Size of the buffer to allocate
330 * Returns: Allocated buffer or %NULL on failure
331 *
332 * Caller is responsible for freeing the returned buffer with os_free().
333 */
334 void * os_malloc(size_t size);
335
336 /**
337 * os_realloc - Re-allocate dynamic memory
338 * @ptr: Old buffer from os_malloc() or os_realloc()
339 * @size: Size of the new buffer
340 * Returns: Allocated buffer or %NULL on failure
341 *
342 * Caller is responsible for freeing the returned buffer with os_free().
343 * If re-allocation fails, %NULL is returned and the original buffer (ptr) is
344 * not freed and caller is still responsible for freeing it.
345 */
346 void * os_realloc(void *ptr, size_t size);
347
348 /**
349 * os_free - Free dynamic memory
350 * @ptr: Old buffer from os_malloc() or os_realloc(); can be %NULL
351 */
352 void os_free(void *ptr);
353
354 /**
355 * os_memcpy - Copy memory area
356 * @dest: Destination
357 * @src: Source
358 * @n: Number of bytes to copy
359 * Returns: dest
360 *
361 * The memory areas src and dst must not overlap. os_memmove() can be used with
362 * overlapping memory.
363 */
364 void * os_memcpy(void *dest, const void *src, size_t n);
365
366 /**
367 * os_memmove - Copy memory area
368 * @dest: Destination
369 * @src: Source
370 * @n: Number of bytes to copy
371 * Returns: dest
372 *
373 * The memory areas src and dst may overlap.
374 */
375 void * os_memmove(void *dest, const void *src, size_t n);
376
377 /**
378 * os_memset - Fill memory with a constant byte
379 * @s: Memory area to be filled
380 * @c: Constant byte
381 * @n: Number of bytes started from s to fill with c
382 * Returns: s
383 */
384 void * os_memset(void *s, int c, size_t n);
385
386 /**
387 * os_memcmp - Compare memory areas
388 * @s1: First buffer
389 * @s2: Second buffer
390 * @n: Maximum numbers of octets to compare
391 * Returns: An integer less than, equal to, or greater than zero if s1 is
392 * found to be less than, to match, or be greater than s2. Only first n
393 * characters will be compared.
394 */
395 int os_memcmp(const void *s1, const void *s2, size_t n);
396
397 /**
398 * os_strdup - Duplicate a string
399 * @s: Source string
400 * Returns: Allocated buffer with the string copied into it or %NULL on failure
401 *
402 * Caller is responsible for freeing the returned buffer with os_free().
403 */
404 char * os_strdup(const char *s);
405
406 /**
407 * os_strlen - Calculate the length of a string
408 * @s: '\0' terminated string
409 * Returns: Number of characters in s (not counting the '\0' terminator)
410 */
411 size_t os_strlen(const char *s);
412
413 /**
414 * os_strcasecmp - Compare two strings ignoring case
415 * @s1: First string
416 * @s2: Second string
417 * Returns: An integer less than, equal to, or greater than zero if s1 is
418 * found to be less than, to match, or be greatred than s2
419 */
420 int os_strcasecmp(const char *s1, const char *s2);
421
422 /**
423 * os_strncasecmp - Compare two strings ignoring case
424 * @s1: First string
425 * @s2: Second string
426 * @n: Maximum numbers of characters to compare
427 * Returns: An integer less than, equal to, or greater than zero if s1 is
428 * found to be less than, to match, or be greater than s2. Only first n
429 * characters will be compared.
430 */
431 int os_strncasecmp(const char *s1, const char *s2, size_t n);
432
433 /**
434 * os_strchr - Locate the first occurrence of a character in string
435 * @s: String
436 * @c: Character to search for
437 * Returns: Pointer to the matched character or %NULL if not found
438 */
439 char * os_strchr(const char *s, int c);
440
441 /**
442 * os_strrchr - Locate the last occurrence of a character in string
443 * @s: String
444 * @c: Character to search for
445 * Returns: Pointer to the matched character or %NULL if not found
446 */
447 char * os_strrchr(const char *s, int c);
448
449 /**
450 * os_strcmp - Compare two strings
451 * @s1: First string
452 * @s2: Second string
453 * Returns: An integer less than, equal to, or greater than zero if s1 is
454 * found to be less than, to match, or be greatred than s2
455 */
456 int os_strcmp(const char *s1, const char *s2);
457
458 /**
459 * os_strncmp - Compare two strings
460 * @s1: First string
461 * @s2: Second string
462 * @n: Maximum numbers of characters to compare
463 * Returns: An integer less than, equal to, or greater than zero if s1 is
464 * found to be less than, to match, or be greater than s2. Only first n
465 * characters will be compared.
466 */
467 int os_strncmp(const char *s1, const char *s2, size_t n);
468
469 /**
470 * os_strstr - Locate a substring
471 * @haystack: String (haystack) to search from
472 * @needle: Needle to search from haystack
473 * Returns: Pointer to the beginning of the substring or %NULL if not found
474 */
475 char * os_strstr(const char *haystack, const char *needle);
476
477 /**
478 * os_snprintf - Print to a memory buffer
479 * @str: Memory buffer to print into
480 * @size: Maximum length of the str buffer
481 * @format: printf format
482 * Returns: Number of characters printed (not including trailing '\0').
483 *
484 * If the output buffer is truncated, number of characters which would have
485 * been written is returned. Since some C libraries return -1 in such a case,
486 * the caller must be prepared on that value, too, to indicate truncation.
487 *
488 * Note: Some C library implementations of snprintf() may not guarantee null
489 * termination in case the output is truncated. The OS wrapper function of
490 * os_snprintf() should provide this guarantee, i.e., to null terminate the
491 * output buffer if a C library version of the function is used and if that
492 * function does not guarantee null termination.
493 *
494 * If the target system does not include snprintf(), see, e.g.,
495 * http://www.ijs.si/software/snprintf/ for an example of a portable
496 * implementation of snprintf.
497 */
498 #ifndef LOS_WPA_PATCH
499 int os_snprintf(char *str, size_t size, const char *format, ...);
500 #else
501 #ifndef os_snprintf
502 #define os_snprintf snprintf
503 #endif
504 #endif /* LOS_WPA_PATCH */
505 #else /* OS_NO_C_LIB_DEFINES */
506
507 #ifdef WPA_TRACE
508 void * os_malloc(size_t size);
509 void * os_realloc(void *ptr, size_t size);
510 void os_free(void *ptr);
511 char * os_strdup(const char *s);
512 #else /* WPA_TRACE */
513 #ifndef os_malloc
514 #define os_malloc(s) malloc((s))
515 #endif
516 #ifndef os_realloc
517 #define os_realloc(p, s) realloc((p), (s))
518 #endif
519 #ifndef os_free
520 #define os_free(p) free((p))
521 #endif
522 #ifndef os_strdup
523 #ifdef _MSC_VER
524 #define os_strdup(s) _strdup(s)
525 #else
526 #define os_strdup(s) strdup(s)
527 #endif
528 #endif
529 #endif /* WPA_TRACE */
530
531 #ifndef os_memcpy
532 #define os_memcpy(d, s, n) memcpy((d), (s), (n))
533 #endif
534 #ifndef os_memmove
535 #define os_memmove(d, s, n) memmove((d), (s), (n))
536 #endif
537 #ifndef os_memset
538 #define os_memset(s, c, n) memset(s, c, n)
539 #endif
540 #ifndef os_memcmp
541 #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
542 #endif
543
544 #ifndef os_strlen
545 #define os_strlen(s) strlen(s)
546 #endif
547 #ifndef os_strcasecmp
548 #ifdef _MSC_VER
549 #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
550 #else
551 #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
552 #endif
553 #endif
554 #ifndef os_strncasecmp
555 #ifdef _MSC_VER
556 #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
557 #else
558 #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
559 #endif
560 #endif
561 #ifndef os_strchr
562 #define os_strchr(s, c) strchr((s), (c))
563 #endif
564 #ifndef os_strcmp
565 #define os_strcmp(s1, s2) strcmp((s1), (s2))
566 #endif
567 #ifndef os_strncmp
568 #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
569 #endif
570 #ifndef os_strrchr
571 #define os_strrchr(s, c) strrchr((s), (c))
572 #endif
573 #ifndef os_strstr
574 #define os_strstr(h, n) strstr((h), (n))
575 #endif
576
577
578 #endif /* OS_NO_C_LIB_DEFINES */
579
580
os_snprintf_error(size_t size,int res)581 static inline int os_snprintf_error(size_t size, int res)
582 {
583 return res < 0 || (unsigned int) res >= size;
584 }
585
586
os_realloc_array(void * ptr,size_t nmemb,size_t size)587 static inline void * os_realloc_array(void *ptr, size_t nmemb, size_t size)
588 {
589 if (size && nmemb > (~(size_t) 0) / size)
590 return NULL;
591 return os_realloc(ptr, nmemb * size);
592 }
593
594 /**
595 * os_remove_in_array - Remove a member from an array by index
596 * @ptr: Pointer to the array
597 * @nmemb: Current member count of the array
598 * @size: The size per member of the array
599 * @idx: Index of the member to be removed
600 */
os_remove_in_array(void * ptr,size_t nmemb,size_t size,size_t idx)601 static inline void os_remove_in_array(void *ptr, size_t nmemb, size_t size,
602 size_t idx)
603 {
604 if (idx < nmemb - 1)
605 os_memmove(((unsigned char *) ptr) + idx * size,
606 ((unsigned char *) ptr) + (idx + 1) * size,
607 (nmemb - idx - 1) * size);
608 }
609
610 /**
611 * os_strlcpy - Copy a string with size bound and NUL-termination
612 * @dest: Destination
613 * @src: Source
614 * @siz: Size of the target buffer
615 * Returns: Total length of the target string (length of src) (not including
616 * NUL-termination)
617 *
618 * This function matches in behavior with the strlcpy(3) function in OpenBSD.
619 */
620 size_t os_strlcpy(char *dest, const char *src, size_t siz);
621
622 /**
623 * os_memcmp_const - Constant time memory comparison
624 * @a: First buffer to compare
625 * @b: Second buffer to compare
626 * @len: Number of octets to compare
627 * Returns: 0 if buffers are equal, non-zero if not
628 *
629 * This function is meant for comparing passwords or hash values where
630 * difference in execution time could provide external observer information
631 * about the location of the difference in the memory buffers. The return value
632 * does not behave like os_memcmp(), i.e., os_memcmp_const() cannot be used to
633 * sort items into a defined order. Unlike os_memcmp(), execution time of
634 * os_memcmp_const() does not depend on the contents of the compared memory
635 * buffers, but only on the total compared length.
636 */
637 int os_memcmp_const(const void *a, const void *b, size_t len);
638
639
640 /**
641 * os_memdup - Allocate duplicate of passed memory chunk
642 * @src: Source buffer to duplicate
643 * @len: Length of source buffer
644 * Returns: %NULL if allocation failed, copy of src buffer otherwise
645 *
646 * This function allocates a memory block like os_malloc() would, and
647 * copies the given source buffer into it.
648 */
649 void * os_memdup(const void *src, size_t len);
650
651 /**
652 * os_exec - Execute an external program
653 * @program: Path to the program
654 * @arg: Command line argument string
655 * @wait_completion: Whether to wait until the program execution completes
656 * Returns: 0 on success, -1 on error
657 */
658 int os_exec(const char *program, const char *arg, int wait_completion);
659
660
661 #ifdef OS_REJECT_C_LIB_FUNCTIONS
662 #define malloc OS_DO_NOT_USE_malloc
663 #define realloc OS_DO_NOT_USE_realloc
664 #define free OS_DO_NOT_USE_free
665 #define memcpy OS_DO_NOT_USE_memcpy
666 #define memmove OS_DO_NOT_USE_memmove
667 #define memset OS_DO_NOT_USE_memset
668 #define memcmp OS_DO_NOT_USE_memcmp
669 #undef strdup
670 #define strdup OS_DO_NOT_USE_strdup
671 #define strlen OS_DO_NOT_USE_strlen
672 #define strcasecmp OS_DO_NOT_USE_strcasecmp
673 #define strncasecmp OS_DO_NOT_USE_strncasecmp
674 #undef strchr
675 #define strchr OS_DO_NOT_USE_strchr
676 #undef strcmp
677 #define strcmp OS_DO_NOT_USE_strcmp
678 #undef strncmp
679 #define strncmp OS_DO_NOT_USE_strncmp
680 #undef strncpy
681 #define strncpy OS_DO_NOT_USE_strncpy
682 #define strrchr OS_DO_NOT_USE_strrchr
683 #define strstr OS_DO_NOT_USE_strstr
684 #undef snprintf
685 #define snprintf OS_DO_NOT_USE_snprintf
686
687 #define strcpy OS_DO_NOT_USE_strcpy
688 #endif /* OS_REJECT_C_LIB_FUNCTIONS */
689
690
691 #if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
692 #define TEST_FAIL() testing_test_fail()
693 int testing_test_fail(void);
694 extern char wpa_trace_fail_func[256];
695 extern unsigned int wpa_trace_fail_after;
696 extern char wpa_trace_test_fail_func[256];
697 extern unsigned int wpa_trace_test_fail_after;
698 #else
699 #define TEST_FAIL() 0
700 #endif
701
702 #ifdef CONFIG_LITEOS_WPA
703 typedef unsigned short T_U16;
704 typedef unsigned int T_U32;
705 #define os_swab16(x) \
706 ((T_U16)( \
707 (((T_U16)(x) & (T_U16)0x00ffU) << 8) | \
708 (((T_U16)(x) & (T_U16)0xff00U) >> 8) ))
709 #define os_swab32(x) \
710 ((T_U32)( \
711 (((T_U32)(x) & (T_U32)0x000000ffUL) << 24) | \
712 (((T_U32)(x) & (T_U32)0x0000ff00UL) << 8) | \
713 (((T_U32)(x) & (T_U32)0x00ff0000UL) >> 8) | \
714 (((T_U32)(x) & (T_U32)0xff000000UL) >> 24) ))
bswap_16(unsigned short v)715 static inline unsigned short bswap_16(unsigned short v)
716 {
717 return os_swab16(v);
718 }
bswap_32(unsigned int v)719 static inline unsigned int bswap_32(unsigned int v)
720 {
721 return os_swab32(v);
722 }
723 #endif /* CONFIG_LITEOS_WPA */
724 #endif /* OS_H */
725