CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/cache/sources/wl/shared/wlu_common.h
Views: 3959
1
/*
2
* Common code for wl routines
3
*
4
* $Copyright (C) 2002-2005 Broadcom Corporation$
5
*
6
* $Id: wlu_common.h 370210 2012-11-21 05:35:27Z nisar $
7
*/
8
#include <wlioctl.h>
9
#include <bcmutils.h>
10
#if defined(_CFE_)
11
#include <lib_types.h>
12
#include <lib_string.h>
13
#include <lib_printf.h>
14
#include <lib_malloc.h>
15
#include <cfe_error.h>
16
#elif defined(__IOPOS__)
17
#include <typedefs.h>
18
#include <bcmstdlib.h>
19
#include <bcmutils.h>
20
#else
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <string.h>
24
#include <ctype.h>
25
#include <assert.h>
26
#endif /* defined(_CFE_) */
27
#if defined (__NetBSD__) || defined(linux) || defined(MACOSX) || defined(EFI)
28
#define stricmp strcasecmp
29
#define strnicmp strncasecmp
30
#elif defined(vxworks) || defined(__ECOS)
31
extern int stricmp(const char *s1, const char *s2);
32
extern int strnicmp(const char *s1, const char *s2, size_t len);
33
#elif defined(UNDER_CE) || defined(_CRT_SECURE_NO_DEPRECATE)
34
#define stricmp _stricmp
35
#define strnicmp _strnicmp
36
#elif defined(_HNDRTE_)
37
#define stricmp strcmp
38
#define strnicmp strncmp
39
#elif defined(_CFE_)
40
#include <bcmutils.h>
41
#include <osl.h>
42
#define isalnum(c) bcm_isalnum(c)
43
#define isalpha(c) bcm_isalpha(c)
44
#define iscntrl(c) bcm_iscntrl(c)
45
#define isdigit(c) bcm_isdigit(c)
46
#define isgraph(c) bcm_isgraph(c)
47
#define islower(c) bcm_islower(c)
48
#define isprint(c) bcm_isprint(c)
49
#define ispunct(c) bcm_ispunct(c)
50
#define isspace(c) bcm_isspace(c)
51
#define isupper(c) bcm_isupper(c)
52
#define isxdigit(c) bcm_isxdigit(c)
53
#define stricmp(s1, s2) lib_strcmpi((s1), (s2))
54
#define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
55
#define tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
56
#define fprintf(stream, fmt, args...) xprintf(fmt, ##args)
57
#define fputs(s, stream) puts(s)
58
#define malloc(size) KMALLOC((size), 0)
59
#define free(ptr) KFREE(ptr)
60
/* XXX Buggy implementations */
61
#define strnicmp(s1, s2, len) strncmp((s1), (s2), (len))
62
#define strspn(s, accept) (0)
63
#define strtol(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
64
#elif defined(__IOPOS__)
65
#define fprintf(file, fmt, arg...) jtag_printf(fmt, ##arg)
66
#define fputs(s, stream) jtag_puts(s)
67
#define printf jtag_printf
68
#define stricmp strcmp
69
#define strnicmp strncmp
70
#define strtol(nptr, endptr, base) ((long)strtoul((nptr), (endptr), (base)))
71
#define tolower(c) bcm_tolower(c)
72
#define toupper(c) bcm_toupper(c)
73
#define islower(c) bcm_islower(c)
74
#define isprint(c) bcm_isprint(c)
75
#define isspace(c) bcm_isspace(c)
76
#define isupper(c) bcm_isupper(c)
77
#define isxdigit(c) bcm_isxdigit(c)
78
#define isdigit(c) bcm_isdigit(c)
79
#elif defined(BWL_STRICMP)
80
#define stricmp bcmstricmp
81
#define strnicmp bcmstrnicmp
82
#endif /* __NetBSD__ */
83
84
85
/* IOCTL swapping mode for Big Endian host with Little Endian dongle. Default to off */
86
/* The below macros handle endian mis-matches between wl utility and wl driver. */
87
static bool g_swap = FALSE;
88
#define htod64(i) (g_swap?bcmswap64(i):(uint64)(i))
89
#define htod32(i) (g_swap?bcmswap32(i):(uint32)(i))
90
#define htod16(i) (g_swap?bcmswap16(i):(uint16)(i))
91
#define dtoh64(i) (g_swap?bcmswap64(i):(uint64)(i))
92
#define dtoh32(i) (g_swap?bcmswap32(i):(uint32)(i))
93
#define dtoh16(i) (g_swap?bcmswap16(i):(uint16)(i))
94
#define htodchanspec(i) (g_swap?htod16(i):i)
95
#define dtohchanspec(i) (g_swap?dtoh16(i):i)
96
#define htodenum(i) (g_swap?((sizeof(i) == 4) ? htod32(i) : ((sizeof(i) == 2) ? htod16(i) : i)):i)
97
#define dtohenum(i) (g_swap?((sizeof(i) == 4) ? dtoh32(i) : ((sizeof(i) == 2) ? htod16(i) : i)):i)
98
99
/* command batching data structure */
100
typedef struct wl_seq_cmd_pkt {
101
struct wl_seq_cmd_pkt *next;
102
wl_seq_cmd_ioctl_t cmd_header;
103
char * data; /* user buffer */
104
} wl_seq_cmd_pkt_t;
105
106
typedef struct wl_cmd_list {
107
wl_seq_cmd_pkt_t *head;
108
wl_seq_cmd_pkt_t *tail;
109
} wl_cmd_list_t;
110
111
extern wl_cmd_list_t cmd_list;
112
extern int cmd_pkt_list_num;
113
extern bool cmd_batching_mode;
114
115
extern int wlu_iovar_getbuf(void* wl, const char *iovar,
116
void *param, int paramlen, void *bufptr, int buflen);
117
extern int wlu_iovar_setbuf(void* wl, const char *iovar,
118
void *param, int paramlen, void *bufptr, int buflen);
119
extern int wlu_var_setbuf(void *wl, const char *iovar, void *param, int param_len);
120
extern int wlu_iovar_getint(void *wl, const char *iovar, int *pval);
121
extern void init_cmd_batchingmode(void);
122
extern void clean_up_cmd_list(void);
123
extern int wl_check(void *wl);
124
125
extern int add_one_batched_cmd(int cmd, void *cmdbuf, int len);
126
extern int wlu_get_req_buflen(int cmd, void *cmdbuf, int len);
127
extern int wlu_get(void *wl, int cmd, void *cmdbuf, int len);
128
extern int wlu_set(void *wl, int cmd, void *cmdbuf, int len);
129
extern int wlu_iovar_get(void *wl, const char *iovar, void *outbuf, int len);
130
extern int wlu_iovar_set(void *wl, const char *iovar, void *param, int paramlen);
131
extern int wlu_iovar_getint(void *wl, const char *iovar, int *pval);
132
extern int wlu_iovar_setint(void *wl, const char *iovar, int val);
133
134