diff options
Diffstat (limited to 'drivers/net/wireless/bcmdhd/include/bcmutils.h')
-rw-r--r-- | drivers/net/wireless/bcmdhd/include/bcmutils.h | 708 |
1 files changed, 708 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcmdhd/include/bcmutils.h b/drivers/net/wireless/bcmdhd/include/bcmutils.h new file mode 100644 index 00000000000..530036f0ba7 --- /dev/null +++ b/drivers/net/wireless/bcmdhd/include/bcmutils.h | |||
@@ -0,0 +1,708 @@ | |||
1 | /* | ||
2 | * Misc useful os-independent macros and functions. | ||
3 | * | ||
4 | * Copyright (C) 1999-2011, Broadcom Corporation | ||
5 | * | ||
6 | * Unless you and Broadcom execute a separate written software license | ||
7 | * agreement governing use of this software, this software is licensed to you | ||
8 | * under the terms of the GNU General Public License version 2 (the "GPL"), | ||
9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the | ||
10 | * following added to such license: | ||
11 | * | ||
12 | * As a special exception, the copyright holders of this software give you | ||
13 | * permission to link this software with independent modules, and to copy and | ||
14 | * distribute the resulting executable under terms of your choice, provided that | ||
15 | * you also meet, for each linked independent module, the terms and conditions of | ||
16 | * the license of that module. An independent module is a module which is not | ||
17 | * derived from this software. The special exception does not apply to any | ||
18 | * modifications of the software. | ||
19 | * | ||
20 | * Notwithstanding the above, under no circumstances may you combine this | ||
21 | * software in any way with any other Broadcom software provided under a license | ||
22 | * other than the GPL, without Broadcom's express prior written consent. | ||
23 | * | ||
24 | * $Id: bcmutils.h,v 13.236.2.16 2011-01-26 00:45:06 Exp $ | ||
25 | */ | ||
26 | |||
27 | |||
28 | #ifndef _bcmutils_h_ | ||
29 | #define _bcmutils_h_ | ||
30 | |||
31 | #define bcm_strcpy_s(dst, noOfElements, src) strcpy((dst), (src)) | ||
32 | #define bcm_strncpy_s(dst, noOfElements, src, count) strncpy((dst), (src), (count)) | ||
33 | #define bcm_strcat_s(dst, noOfElements, src) strcat((dst), (src)) | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" { | ||
37 | #endif | ||
38 | |||
39 | |||
40 | #define _BCM_U 0x01 | ||
41 | #define _BCM_L 0x02 | ||
42 | #define _BCM_D 0x04 | ||
43 | #define _BCM_C 0x08 | ||
44 | #define _BCM_P 0x10 | ||
45 | #define _BCM_S 0x20 | ||
46 | #define _BCM_X 0x40 | ||
47 | #define _BCM_SP 0x80 | ||
48 | |||
49 | extern const unsigned char bcm_ctype[]; | ||
50 | #define bcm_ismask(x) (bcm_ctype[(int)(unsigned char)(x)]) | ||
51 | |||
52 | #define bcm_isalnum(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L|_BCM_D)) != 0) | ||
53 | #define bcm_isalpha(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L)) != 0) | ||
54 | #define bcm_iscntrl(c) ((bcm_ismask(c)&(_BCM_C)) != 0) | ||
55 | #define bcm_isdigit(c) ((bcm_ismask(c)&(_BCM_D)) != 0) | ||
56 | #define bcm_isgraph(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D)) != 0) | ||
57 | #define bcm_islower(c) ((bcm_ismask(c)&(_BCM_L)) != 0) | ||
58 | #define bcm_isprint(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D|_BCM_SP)) != 0) | ||
59 | #define bcm_ispunct(c) ((bcm_ismask(c)&(_BCM_P)) != 0) | ||
60 | #define bcm_isspace(c) ((bcm_ismask(c)&(_BCM_S)) != 0) | ||
61 | #define bcm_isupper(c) ((bcm_ismask(c)&(_BCM_U)) != 0) | ||
62 | #define bcm_isxdigit(c) ((bcm_ismask(c)&(_BCM_D|_BCM_X)) != 0) | ||
63 | #define bcm_tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c)) | ||
64 | #define bcm_toupper(c) (bcm_islower((c)) ? ((c) + 'A' - 'a') : (c)) | ||
65 | |||
66 | |||
67 | |||
68 | struct bcmstrbuf { | ||
69 | char *buf; | ||
70 | unsigned int size; | ||
71 | char *origbuf; | ||
72 | unsigned int origsize; | ||
73 | }; | ||
74 | |||
75 | |||
76 | #ifdef BCMDRIVER | ||
77 | #include <osl.h> | ||
78 | |||
79 | #define GPIO_PIN_NOTDEFINED 0x20 | ||
80 | |||
81 | |||
82 | #define SPINWAIT(exp, us) { \ | ||
83 | uint countdown = (us) + 9; \ | ||
84 | while ((exp) && (countdown >= 10)) {\ | ||
85 | OSL_DELAY(10); \ | ||
86 | countdown -= 10; \ | ||
87 | } \ | ||
88 | } | ||
89 | |||
90 | |||
91 | #ifndef PKTQ_LEN_DEFAULT | ||
92 | #define PKTQ_LEN_DEFAULT 128 | ||
93 | #endif | ||
94 | #ifndef PKTQ_MAX_PREC | ||
95 | #define PKTQ_MAX_PREC 16 | ||
96 | #endif | ||
97 | |||
98 | typedef struct pktq_prec { | ||
99 | void *head; | ||
100 | void *tail; | ||
101 | uint16 len; | ||
102 | uint16 max; | ||
103 | } pktq_prec_t; | ||
104 | |||
105 | |||
106 | |||
107 | struct pktq { | ||
108 | uint16 num_prec; | ||
109 | uint16 hi_prec; | ||
110 | uint16 max; | ||
111 | uint16 len; | ||
112 | |||
113 | struct pktq_prec q[PKTQ_MAX_PREC]; | ||
114 | }; | ||
115 | |||
116 | |||
117 | struct spktq { | ||
118 | uint16 num_prec; | ||
119 | uint16 hi_prec; | ||
120 | uint16 max; | ||
121 | uint16 len; | ||
122 | |||
123 | struct pktq_prec q[1]; | ||
124 | }; | ||
125 | |||
126 | #define PKTQ_PREC_ITER(pq, prec) for (prec = (pq)->num_prec - 1; prec >= 0; prec--) | ||
127 | |||
128 | |||
129 | typedef bool (*ifpkt_cb_t)(void*, int); | ||
130 | |||
131 | #ifdef BCMPKTPOOL | ||
132 | #define POOL_ENAB(pool) ((pool) && (pool)->inited) | ||
133 | #if defined(BCM4329C0) | ||
134 | #define SHARED_POOL (pktpool_shared_ptr) | ||
135 | #else | ||
136 | #define SHARED_POOL (pktpool_shared) | ||
137 | #endif | ||
138 | #else | ||
139 | #define POOL_ENAB(bus) 0 | ||
140 | #define SHARED_POOL ((struct pktpool *)NULL) | ||
141 | #endif | ||
142 | |||
143 | #ifndef PKTPOOL_LEN_MAX | ||
144 | #define PKTPOOL_LEN_MAX 40 | ||
145 | #endif | ||
146 | #define PKTPOOL_CB_MAX 3 | ||
147 | |||
148 | struct pktpool; | ||
149 | typedef void (*pktpool_cb_t)(struct pktpool *pool, void *arg); | ||
150 | typedef struct { | ||
151 | pktpool_cb_t cb; | ||
152 | void *arg; | ||
153 | } pktpool_cbinfo_t; | ||
154 | |||
155 | #ifdef BCMDBG_POOL | ||
156 | |||
157 | #define POOL_IDLE 0 | ||
158 | #define POOL_RXFILL 1 | ||
159 | #define POOL_RXDH 2 | ||
160 | #define POOL_RXD11 3 | ||
161 | #define POOL_TXDH 4 | ||
162 | #define POOL_TXD11 5 | ||
163 | #define POOL_AMPDU 6 | ||
164 | #define POOL_TXENQ 7 | ||
165 | |||
166 | typedef struct { | ||
167 | void *p; | ||
168 | uint32 cycles; | ||
169 | uint32 dur; | ||
170 | } pktpool_dbg_t; | ||
171 | |||
172 | typedef struct { | ||
173 | uint8 txdh; | ||
174 | uint8 txd11; | ||
175 | uint8 enq; | ||
176 | uint8 rxdh; | ||
177 | uint8 rxd11; | ||
178 | uint8 rxfill; | ||
179 | uint8 idle; | ||
180 | } pktpool_stats_t; | ||
181 | #endif | ||
182 | |||
183 | typedef struct pktpool { | ||
184 | bool inited; | ||
185 | uint16 r; | ||
186 | uint16 w; | ||
187 | uint16 len; | ||
188 | uint16 maxlen; | ||
189 | uint16 plen; | ||
190 | bool istx; | ||
191 | bool empty; | ||
192 | uint8 cbtoggle; | ||
193 | uint8 cbcnt; | ||
194 | uint8 ecbcnt; | ||
195 | bool emptycb_disable; | ||
196 | pktpool_cbinfo_t cbs[PKTPOOL_CB_MAX]; | ||
197 | pktpool_cbinfo_t ecbs[PKTPOOL_CB_MAX]; | ||
198 | void *q[PKTPOOL_LEN_MAX + 1]; | ||
199 | |||
200 | #ifdef BCMDBG_POOL | ||
201 | uint8 dbg_cbcnt; | ||
202 | pktpool_cbinfo_t dbg_cbs[PKTPOOL_CB_MAX]; | ||
203 | uint16 dbg_qlen; | ||
204 | pktpool_dbg_t dbg_q[PKTPOOL_LEN_MAX + 1]; | ||
205 | #endif | ||
206 | } pktpool_t; | ||
207 | |||
208 | #if defined(BCM4329C0) | ||
209 | extern pktpool_t *pktpool_shared_ptr; | ||
210 | #else | ||
211 | extern pktpool_t *pktpool_shared; | ||
212 | #endif | ||
213 | |||
214 | extern int pktpool_init(osl_t *osh, pktpool_t *pktp, int *pktplen, int plen, bool istx); | ||
215 | extern int pktpool_deinit(osl_t *osh, pktpool_t *pktp); | ||
216 | extern int pktpool_fill(osl_t *osh, pktpool_t *pktp, bool minimal); | ||
217 | extern void* pktpool_get(pktpool_t *pktp); | ||
218 | extern void pktpool_free(pktpool_t *pktp, void *p); | ||
219 | extern int pktpool_add(pktpool_t *pktp, void *p); | ||
220 | extern uint16 pktpool_avail(pktpool_t *pktp); | ||
221 | extern int pktpool_avail_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg); | ||
222 | extern int pktpool_empty_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg); | ||
223 | extern int pktpool_setmaxlen(pktpool_t *pktp, uint16 maxlen); | ||
224 | extern void pktpool_emptycb_disable(pktpool_t *pktp, bool disable); | ||
225 | |||
226 | #define POOLPTR(pp) ((pktpool_t *)(pp)) | ||
227 | #define pktpool_len(pp) (POOLPTR(pp)->len - 1) | ||
228 | #define pktpool_plen(pp) (POOLPTR(pp)->plen) | ||
229 | #define pktpool_maxlen(pp) (POOLPTR(pp)->maxlen) | ||
230 | |||
231 | #ifdef BCMDBG_POOL | ||
232 | extern int pktpool_dbg_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg); | ||
233 | extern int pktpool_start_trigger(pktpool_t *pktp, void *p); | ||
234 | extern int pktpool_dbg_dump(pktpool_t *pktp); | ||
235 | extern int pktpool_dbg_notify(pktpool_t *pktp); | ||
236 | extern int pktpool_stats_dump(pktpool_t *pktp, pktpool_stats_t *stats); | ||
237 | #endif | ||
238 | |||
239 | |||
240 | |||
241 | struct ether_addr; | ||
242 | |||
243 | extern int ether_isbcast(const void *ea); | ||
244 | extern int ether_isnulladdr(const void *ea); | ||
245 | |||
246 | |||
247 | |||
248 | #define pktq_psetmax(pq, prec, _max) ((pq)->q[prec].max = (_max)) | ||
249 | #define pktq_plen(pq, prec) ((pq)->q[prec].len) | ||
250 | #define pktq_pavail(pq, prec) ((pq)->q[prec].max - (pq)->q[prec].len) | ||
251 | #define pktq_pfull(pq, prec) ((pq)->q[prec].len >= (pq)->q[prec].max) | ||
252 | #define pktq_pempty(pq, prec) ((pq)->q[prec].len == 0) | ||
253 | |||
254 | #define pktq_ppeek(pq, prec) ((pq)->q[prec].head) | ||
255 | #define pktq_ppeek_tail(pq, prec) ((pq)->q[prec].tail) | ||
256 | |||
257 | extern void *pktq_penq(struct pktq *pq, int prec, void *p); | ||
258 | extern void *pktq_penq_head(struct pktq *pq, int prec, void *p); | ||
259 | extern void *pktq_pdeq(struct pktq *pq, int prec); | ||
260 | extern void *pktq_pdeq_tail(struct pktq *pq, int prec); | ||
261 | |||
262 | extern void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir, | ||
263 | ifpkt_cb_t fn, int arg); | ||
264 | |||
265 | extern bool pktq_pdel(struct pktq *pq, void *p, int prec); | ||
266 | |||
267 | |||
268 | |||
269 | extern int pktq_mlen(struct pktq *pq, uint prec_bmp); | ||
270 | extern void *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out); | ||
271 | |||
272 | |||
273 | |||
274 | #define pktq_len(pq) ((int)(pq)->len) | ||
275 | #define pktq_max(pq) ((int)(pq)->max) | ||
276 | #define pktq_avail(pq) ((int)((pq)->max - (pq)->len)) | ||
277 | #define pktq_full(pq) ((pq)->len >= (pq)->max) | ||
278 | #define pktq_empty(pq) ((pq)->len == 0) | ||
279 | |||
280 | |||
281 | #define pktenq(pq, p) pktq_penq(((struct pktq *)pq), 0, (p)) | ||
282 | #define pktenq_head(pq, p) pktq_penq_head(((struct pktq *)pq), 0, (p)) | ||
283 | #define pktdeq(pq) pktq_pdeq(((struct pktq *)pq), 0) | ||
284 | #define pktdeq_tail(pq) pktq_pdeq_tail(((struct pktq *)pq), 0) | ||
285 | #define pktqinit(pq, len) pktq_init(((struct pktq *)pq), 1, len) | ||
286 | |||
287 | extern void pktq_init(struct pktq *pq, int num_prec, int max_len); | ||
288 | |||
289 | extern void *pktq_deq(struct pktq *pq, int *prec_out); | ||
290 | extern void *pktq_deq_tail(struct pktq *pq, int *prec_out); | ||
291 | extern void *pktq_peek(struct pktq *pq, int *prec_out); | ||
292 | extern void *pktq_peek_tail(struct pktq *pq, int *prec_out); | ||
293 | extern void pktq_flush(osl_t *osh, struct pktq *pq, bool dir, ifpkt_cb_t fn, int arg); | ||
294 | |||
295 | |||
296 | |||
297 | extern uint pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf); | ||
298 | extern uint pktfrombuf(osl_t *osh, void *p, uint offset, int len, uchar *buf); | ||
299 | extern uint pkttotlen(osl_t *osh, void *p); | ||
300 | extern void *pktlast(osl_t *osh, void *p); | ||
301 | extern uint pktsegcnt(osl_t *osh, void *p); | ||
302 | |||
303 | |||
304 | extern uint pktsetprio(void *pkt, bool update_vtag); | ||
305 | #define PKTPRIO_VDSCP 0x100 | ||
306 | #define PKTPRIO_VLAN 0x200 | ||
307 | #define PKTPRIO_UPD 0x400 | ||
308 | #define PKTPRIO_DSCP 0x800 | ||
309 | |||
310 | |||
311 | extern int bcm_atoi(char *s); | ||
312 | extern ulong bcm_strtoul(char *cp, char **endp, uint base); | ||
313 | extern char *bcmstrstr(char *haystack, char *needle); | ||
314 | extern char *bcmstrcat(char *dest, const char *src); | ||
315 | extern char *bcmstrncat(char *dest, const char *src, uint size); | ||
316 | extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen); | ||
317 | char* bcmstrtok(char **string, const char *delimiters, char *tokdelim); | ||
318 | int bcmstricmp(const char *s1, const char *s2); | ||
319 | int bcmstrnicmp(const char* s1, const char* s2, int cnt); | ||
320 | |||
321 | |||
322 | |||
323 | extern char *bcm_ether_ntoa(const struct ether_addr *ea, char *buf); | ||
324 | extern int bcm_ether_atoe(char *p, struct ether_addr *ea); | ||
325 | |||
326 | |||
327 | struct ipv4_addr; | ||
328 | extern char *bcm_ip_ntoa(struct ipv4_addr *ia, char *buf); | ||
329 | |||
330 | |||
331 | extern void bcm_mdelay(uint ms); | ||
332 | |||
333 | extern char *getvar(char *vars, const char *name); | ||
334 | extern int getintvar(char *vars, const char *name); | ||
335 | extern int getintvararray(char *vars, const char *name, int index); | ||
336 | extern int getintvararraysize(char *vars, const char *name); | ||
337 | extern uint getgpiopin(char *vars, char *pin_name, uint def_pin); | ||
338 | #define bcm_perf_enable() | ||
339 | #define bcmstats(fmt) | ||
340 | #define bcmlog(fmt, a1, a2) | ||
341 | #define bcmdumplog(buf, size) *buf = '\0' | ||
342 | #define bcmdumplogent(buf, idx) -1 | ||
343 | |||
344 | #define bcmtslog(tstamp, fmt, a1, a2) | ||
345 | #define bcmprinttslogs() | ||
346 | #define bcmprinttstamp(us) | ||
347 | |||
348 | extern char *bcm_nvram_vars(uint *length); | ||
349 | extern int bcm_nvram_cache(void *sih); | ||
350 | |||
351 | |||
352 | |||
353 | |||
354 | typedef struct bcm_iovar { | ||
355 | const char *name; | ||
356 | uint16 varid; | ||
357 | uint16 flags; | ||
358 | uint16 type; | ||
359 | uint16 minlen; | ||
360 | } bcm_iovar_t; | ||
361 | |||
362 | |||
363 | |||
364 | |||
365 | #define IOV_GET 0 | ||
366 | #define IOV_SET 1 | ||
367 | |||
368 | |||
369 | #define IOV_GVAL(id) ((id)*2) | ||
370 | #define IOV_SVAL(id) (((id)*2)+IOV_SET) | ||
371 | #define IOV_ISSET(actionid) ((actionid & IOV_SET) == IOV_SET) | ||
372 | #define IOV_ID(actionid) (actionid >> 1) | ||
373 | |||
374 | |||
375 | |||
376 | extern const bcm_iovar_t *bcm_iovar_lookup(const bcm_iovar_t *table, const char *name); | ||
377 | extern int bcm_iovar_lencheck(const bcm_iovar_t *table, void *arg, int len, bool set); | ||
378 | #if defined(WLTINYDUMP) || defined(WLMSG_INFORM) || defined(WLMSG_ASSOC) || \ | ||
379 | defined(WLMSG_PRPKT) || defined(WLMSG_WSEC) | ||
380 | extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len); | ||
381 | #endif | ||
382 | #endif | ||
383 | |||
384 | |||
385 | #define IOVT_VOID 0 | ||
386 | #define IOVT_BOOL 1 | ||
387 | #define IOVT_INT8 2 | ||
388 | #define IOVT_UINT8 3 | ||
389 | #define IOVT_INT16 4 | ||
390 | #define IOVT_UINT16 5 | ||
391 | #define IOVT_INT32 6 | ||
392 | #define IOVT_UINT32 7 | ||
393 | #define IOVT_BUFFER 8 | ||
394 | #define BCM_IOVT_VALID(type) (((unsigned int)(type)) <= IOVT_BUFFER) | ||
395 | |||
396 | |||
397 | #define BCM_IOV_TYPE_INIT { \ | ||
398 | "void", \ | ||
399 | "bool", \ | ||
400 | "int8", \ | ||
401 | "uint8", \ | ||
402 | "int16", \ | ||
403 | "uint16", \ | ||
404 | "int32", \ | ||
405 | "uint32", \ | ||
406 | "buffer", \ | ||
407 | "" } | ||
408 | |||
409 | #define BCM_IOVT_IS_INT(type) (\ | ||
410 | (type == IOVT_BOOL) || \ | ||
411 | (type == IOVT_INT8) || \ | ||
412 | (type == IOVT_UINT8) || \ | ||
413 | (type == IOVT_INT16) || \ | ||
414 | (type == IOVT_UINT16) || \ | ||
415 | (type == IOVT_INT32) || \ | ||
416 | (type == IOVT_UINT32)) | ||
417 | |||
418 | |||
419 | |||
420 | #define BCME_STRLEN 64 | ||
421 | #define VALID_BCMERROR(e) ((e <= 0) && (e >= BCME_LAST)) | ||
422 | |||
423 | |||
424 | |||
425 | |||
426 | #define BCME_OK 0 | ||
427 | #define BCME_ERROR -1 | ||
428 | #define BCME_BADARG -2 | ||
429 | #define BCME_BADOPTION -3 | ||
430 | #define BCME_NOTUP -4 | ||
431 | #define BCME_NOTDOWN -5 | ||
432 | #define BCME_NOTAP -6 | ||
433 | #define BCME_NOTSTA -7 | ||
434 | #define BCME_BADKEYIDX -8 | ||
435 | #define BCME_RADIOOFF -9 | ||
436 | #define BCME_NOTBANDLOCKED -10 | ||
437 | #define BCME_NOCLK -11 | ||
438 | #define BCME_BADRATESET -12 | ||
439 | #define BCME_BADBAND -13 | ||
440 | #define BCME_BUFTOOSHORT -14 | ||
441 | #define BCME_BUFTOOLONG -15 | ||
442 | #define BCME_BUSY -16 | ||
443 | #define BCME_NOTASSOCIATED -17 | ||
444 | #define BCME_BADSSIDLEN -18 | ||
445 | #define BCME_OUTOFRANGECHAN -19 | ||
446 | #define BCME_BADCHAN -20 | ||
447 | #define BCME_BADADDR -21 | ||
448 | #define BCME_NORESOURCE -22 | ||
449 | #define BCME_UNSUPPORTED -23 | ||
450 | #define BCME_BADLEN -24 | ||
451 | #define BCME_NOTREADY -25 | ||
452 | #define BCME_EPERM -26 | ||
453 | #define BCME_NOMEM -27 | ||
454 | #define BCME_ASSOCIATED -28 | ||
455 | #define BCME_RANGE -29 | ||
456 | #define BCME_NOTFOUND -30 | ||
457 | #define BCME_WME_NOT_ENABLED -31 | ||
458 | #define BCME_TSPEC_NOTFOUND -32 | ||
459 | #define BCME_ACM_NOTSUPPORTED -33 | ||
460 | #define BCME_NOT_WME_ASSOCIATION -34 | ||
461 | #define BCME_SDIO_ERROR -35 | ||
462 | #define BCME_DONGLE_DOWN -36 | ||
463 | #define BCME_VERSION -37 | ||
464 | #define BCME_TXFAIL -38 | ||
465 | #define BCME_RXFAIL -39 | ||
466 | #define BCME_NODEVICE -40 | ||
467 | #define BCME_NMODE_DISABLED -41 | ||
468 | #define BCME_NONRESIDENT -42 | ||
469 | #define BCME_LAST BCME_NONRESIDENT | ||
470 | |||
471 | |||
472 | #define BCMERRSTRINGTABLE { \ | ||
473 | "OK", \ | ||
474 | "Undefined error", \ | ||
475 | "Bad Argument", \ | ||
476 | "Bad Option", \ | ||
477 | "Not up", \ | ||
478 | "Not down", \ | ||
479 | "Not AP", \ | ||
480 | "Not STA", \ | ||
481 | "Bad Key Index", \ | ||
482 | "Radio Off", \ | ||
483 | "Not band locked", \ | ||
484 | "No clock", \ | ||
485 | "Bad Rate valueset", \ | ||
486 | "Bad Band", \ | ||
487 | "Buffer too short", \ | ||
488 | "Buffer too long", \ | ||
489 | "Busy", \ | ||
490 | "Not Associated", \ | ||
491 | "Bad SSID len", \ | ||
492 | "Out of Range Channel", \ | ||
493 | "Bad Channel", \ | ||
494 | "Bad Address", \ | ||
495 | "Not Enough Resources", \ | ||
496 | "Unsupported", \ | ||
497 | "Bad length", \ | ||
498 | "Not Ready", \ | ||
499 | "Not Permitted", \ | ||
500 | "No Memory", \ | ||
501 | "Associated", \ | ||
502 | "Not In Range", \ | ||
503 | "Not Found", \ | ||
504 | "WME Not Enabled", \ | ||
505 | "TSPEC Not Found", \ | ||
506 | "ACM Not Supported", \ | ||
507 | "Not WME Association", \ | ||
508 | "SDIO Bus Error", \ | ||
509 | "Dongle Not Accessible", \ | ||
510 | "Incorrect version", \ | ||
511 | "TX Failure", \ | ||
512 | "RX Failure", \ | ||
513 | "Device Not Present", \ | ||
514 | "NMODE Disabled", \ | ||
515 | "Nonresident overlay access", \ | ||
516 | } | ||
517 | |||
518 | #ifndef ABS | ||
519 | #define ABS(a) (((a) < 0)?-(a):(a)) | ||
520 | #endif | ||
521 | |||
522 | #ifndef MIN | ||
523 | #define MIN(a, b) (((a) < (b))?(a):(b)) | ||
524 | #endif | ||
525 | |||
526 | #ifndef MAX | ||
527 | #define MAX(a, b) (((a) > (b))?(a):(b)) | ||
528 | #endif | ||
529 | |||
530 | #define CEIL(x, y) (((x) + ((y)-1)) / (y)) | ||
531 | #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) | ||
532 | #define ISALIGNED(a, x) (((uintptr)(a) & ((x)-1)) == 0) | ||
533 | #define ALIGN_ADDR(addr, boundary) (void *)(((uintptr)(addr) + (boundary) - 1) \ | ||
534 | & ~((boundary) - 1)) | ||
535 | #define ISPOWEROF2(x) ((((x)-1)&(x)) == 0) | ||
536 | #define VALID_MASK(mask) !((mask) & ((mask) + 1)) | ||
537 | #ifndef OFFSETOF | ||
538 | #define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member) | ||
539 | #endif | ||
540 | #ifndef ARRAYSIZE | ||
541 | #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) | ||
542 | #endif | ||
543 | |||
544 | |||
545 | extern void *_bcmutils_dummy_fn; | ||
546 | #define REFERENCE_FUNCTION(f) (_bcmutils_dummy_fn = (void *)(f)) | ||
547 | |||
548 | |||
549 | #ifndef setbit | ||
550 | #ifndef NBBY | ||
551 | #define NBBY 8 | ||
552 | #endif | ||
553 | #define setbit(a, i) (((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY)) | ||
554 | #define clrbit(a, i) (((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) | ||
555 | #define isset(a, i) (((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) | ||
556 | #define isclr(a, i) ((((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) | ||
557 | #endif | ||
558 | |||
559 | #define NBITS(type) (sizeof(type) * 8) | ||
560 | #define NBITVAL(nbits) (1 << (nbits)) | ||
561 | #define MAXBITVAL(nbits) ((1 << (nbits)) - 1) | ||
562 | #define NBITMASK(nbits) MAXBITVAL(nbits) | ||
563 | #define MAXNBVAL(nbyte) MAXBITVAL((nbyte) * 8) | ||
564 | |||
565 | |||
566 | #define MUX(pred, true, false) ((pred) ? (true) : (false)) | ||
567 | |||
568 | |||
569 | #define MODDEC(x, bound) MUX((x) == 0, (bound) - 1, (x) - 1) | ||
570 | #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1) | ||
571 | |||
572 | |||
573 | #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1)) | ||
574 | #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1)) | ||
575 | |||
576 | |||
577 | #define MODADD(x, y, bound) \ | ||
578 | MUX((x) + (y) >= (bound), (x) + (y) - (bound), (x) + (y)) | ||
579 | #define MODSUB(x, y, bound) \ | ||
580 | MUX(((int)(x)) - ((int)(y)) < 0, (x) - (y) + (bound), (x) - (y)) | ||
581 | |||
582 | |||
583 | #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1)) | ||
584 | #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1)) | ||
585 | |||
586 | |||
587 | #define CRC8_INIT_VALUE 0xff | ||
588 | #define CRC8_GOOD_VALUE 0x9f | ||
589 | #define CRC16_INIT_VALUE 0xffff | ||
590 | #define CRC16_GOOD_VALUE 0xf0b8 | ||
591 | #define CRC32_INIT_VALUE 0xffffffff | ||
592 | #define CRC32_GOOD_VALUE 0xdebb20e3 | ||
593 | |||
594 | |||
595 | typedef struct bcm_bit_desc { | ||
596 | uint32 bit; | ||
597 | const char* name; | ||
598 | } bcm_bit_desc_t; | ||
599 | |||
600 | |||
601 | typedef struct bcm_tlv { | ||
602 | uint8 id; | ||
603 | uint8 len; | ||
604 | uint8 data[1]; | ||
605 | } bcm_tlv_t; | ||
606 | |||
607 | |||
608 | #define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len)) | ||
609 | |||
610 | |||
611 | #define ETHER_ADDR_STR_LEN 18 | ||
612 | |||
613 | |||
614 | |||
615 | static INLINE void | ||
616 | xor_128bit_block(const uint8 *src1, const uint8 *src2, uint8 *dst) | ||
617 | { | ||
618 | if ( | ||
619 | #ifdef __i386__ | ||
620 | 1 || | ||
621 | #endif | ||
622 | (((uintptr)src1 | (uintptr)src2 | (uintptr)dst) & 3) == 0) { | ||
623 | |||
624 | |||
625 | ((uint32 *)dst)[0] = ((const uint32 *)src1)[0] ^ ((const uint32 *)src2)[0]; | ||
626 | ((uint32 *)dst)[1] = ((const uint32 *)src1)[1] ^ ((const uint32 *)src2)[1]; | ||
627 | ((uint32 *)dst)[2] = ((const uint32 *)src1)[2] ^ ((const uint32 *)src2)[2]; | ||
628 | ((uint32 *)dst)[3] = ((const uint32 *)src1)[3] ^ ((const uint32 *)src2)[3]; | ||
629 | } else { | ||
630 | |||
631 | int k; | ||
632 | for (k = 0; k < 16; k++) | ||
633 | dst[k] = src1[k] ^ src2[k]; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | |||
638 | |||
639 | extern uint8 hndcrc8(uint8 *p, uint nbytes, uint8 crc); | ||
640 | extern uint16 hndcrc16(uint8 *p, uint nbytes, uint16 crc); | ||
641 | extern uint32 hndcrc32(uint8 *p, uint nbytes, uint32 crc); | ||
642 | |||
643 | #if defined(DHD_DEBUG) || defined(WLMSG_PRHDRS) || defined(WLMSG_PRPKT) || \ | ||
644 | defined(WLMSG_ASSOC) | ||
645 | extern int bcm_format_flags(const bcm_bit_desc_t *bd, uint32 flags, char* buf, int len); | ||
646 | #endif | ||
647 | |||
648 | #if defined(DHD_DEBUG) || defined(WLMSG_PRHDRS) || defined(WLMSG_PRPKT) || \ | ||
649 | defined(WLMSG_ASSOC) || defined(WLMEDIA_PEAKRATE) | ||
650 | extern int bcm_format_hex(char *str, const void *bytes, int len); | ||
651 | #endif | ||
652 | |||
653 | extern const char *bcm_crypto_algo_name(uint algo); | ||
654 | extern char *bcm_chipname(uint chipid, char *buf, uint len); | ||
655 | extern char *bcm_brev_str(uint32 brev, char *buf); | ||
656 | extern void printbig(char *buf); | ||
657 | extern void prhex(const char *msg, uchar *buf, uint len); | ||
658 | |||
659 | |||
660 | extern bcm_tlv_t *bcm_next_tlv(bcm_tlv_t *elt, int *buflen); | ||
661 | extern bcm_tlv_t *bcm_parse_tlvs(void *buf, int buflen, uint key); | ||
662 | extern bcm_tlv_t *bcm_parse_ordered_tlvs(void *buf, int buflen, uint key); | ||
663 | |||
664 | |||
665 | extern const char *bcmerrorstr(int bcmerror); | ||
666 | |||
667 | |||
668 | typedef uint32 mbool; | ||
669 | #define mboolset(mb, bit) ((mb) |= (bit)) | ||
670 | #define mboolclr(mb, bit) ((mb) &= ~(bit)) | ||
671 | #define mboolisset(mb, bit) (((mb) & (bit)) != 0) | ||
672 | #define mboolmaskset(mb, mask, val) ((mb) = (((mb) & ~(mask)) | (val))) | ||
673 | |||
674 | |||
675 | extern uint16 bcm_qdbm_to_mw(uint8 qdbm); | ||
676 | extern uint8 bcm_mw_to_qdbm(uint16 mw); | ||
677 | |||
678 | |||
679 | struct fielddesc { | ||
680 | const char *nameandfmt; | ||
681 | uint32 offset; | ||
682 | uint32 len; | ||
683 | }; | ||
684 | |||
685 | extern void bcm_binit(struct bcmstrbuf *b, char *buf, uint size); | ||
686 | extern int bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...); | ||
687 | extern void bcm_inc_bytes(uchar *num, int num_bytes, uint8 amount); | ||
688 | extern int bcm_cmp_bytes(uchar *arg1, uchar *arg2, uint8 nbytes); | ||
689 | extern void bcm_print_bytes(char *name, const uchar *cdata, int len); | ||
690 | |||
691 | typedef uint32 (*bcmutl_rdreg_rtn)(void *arg0, uint arg1, uint32 offset); | ||
692 | extern uint bcmdumpfields(bcmutl_rdreg_rtn func_ptr, void *arg0, uint arg1, struct fielddesc *str, | ||
693 | char *buf, uint32 bufsize); | ||
694 | |||
695 | extern uint bcm_mkiovar(char *name, char *data, uint datalen, char *buf, uint len); | ||
696 | extern uint bcm_bitcount(uint8 *bitmap, uint bytelength); | ||
697 | |||
698 | |||
699 | |||
700 | #define SSID_FMT_BUF_LEN ((4 * DOT11_MAX_SSID_LEN) + 1) | ||
701 | |||
702 | unsigned int process_nvram_vars(char *varbuf, unsigned int len); | ||
703 | |||
704 | #ifdef __cplusplus | ||
705 | } | ||
706 | #endif | ||
707 | |||
708 | #endif | ||