Home | History | Annotate | Download | only in include
      1 /*
      2  * Misc useful os-independent macros and functions.
      3  *
      4  * Copyright (C) 1999-2010, 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  * $Id: bcmutils.h,v 13.184.4.6.2.1.18.25 2010/04/26 06:05:24 Exp $
     24  */
     25 
     26 
     27 #ifndef	_bcmutils_h_
     28 #define	_bcmutils_h_
     29 
     30 #ifdef __cplusplus
     31 extern "C" {
     32 #endif
     33 
     34 
     35 #define _BCM_U	0x01
     36 #define _BCM_L	0x02
     37 #define _BCM_D	0x04
     38 #define _BCM_C	0x08
     39 #define _BCM_P	0x10
     40 #define _BCM_S	0x20
     41 #define _BCM_X	0x40
     42 #define _BCM_SP	0x80
     43 
     44 extern const unsigned char bcm_ctype[];
     45 #define bcm_ismask(x)	(bcm_ctype[(int)(unsigned char)(x)])
     46 
     47 #define bcm_isalnum(c)	((bcm_ismask(c)&(_BCM_U|_BCM_L|_BCM_D)) != 0)
     48 #define bcm_isalpha(c)	((bcm_ismask(c)&(_BCM_U|_BCM_L)) != 0)
     49 #define bcm_iscntrl(c)	((bcm_ismask(c)&(_BCM_C)) != 0)
     50 #define bcm_isdigit(c)	((bcm_ismask(c)&(_BCM_D)) != 0)
     51 #define bcm_isgraph(c)	((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D)) != 0)
     52 #define bcm_islower(c)	((bcm_ismask(c)&(_BCM_L)) != 0)
     53 #define bcm_isprint(c)	((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D|_BCM_SP)) != 0)
     54 #define bcm_ispunct(c)	((bcm_ismask(c)&(_BCM_P)) != 0)
     55 #define bcm_isspace(c)	((bcm_ismask(c)&(_BCM_S)) != 0)
     56 #define bcm_isupper(c)	((bcm_ismask(c)&(_BCM_U)) != 0)
     57 #define bcm_isxdigit(c)	((bcm_ismask(c)&(_BCM_D|_BCM_X)) != 0)
     58 #define bcm_tolower(c)	(bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
     59 #define bcm_toupper(c)	(bcm_islower((c)) ? ((c) + 'A' - 'a') : (c))
     60 
     61 
     62 
     63 struct bcmstrbuf {
     64 	char *buf;
     65 	unsigned int size;
     66 	char *origbuf;
     67 	unsigned int origsize;
     68 };
     69 
     70 
     71 #ifdef BCMDRIVER
     72 #include <osl.h>
     73 
     74 #define GPIO_PIN_NOTDEFINED 	0x20
     75 
     76 
     77 #define SPINWAIT(exp, us) { \
     78 	uint countdown = (us) + 9; \
     79 	while ((exp) && (countdown >= 10)) {\
     80 		OSL_DELAY(10); \
     81 		countdown -= 10; \
     82 	} \
     83 }
     84 
     85 
     86 
     87 #ifndef PKTQ_LEN_DEFAULT
     88 #define PKTQ_LEN_DEFAULT        128
     89 #endif
     90 #ifndef PKTQ_MAX_PREC
     91 #define PKTQ_MAX_PREC           16
     92 #endif
     93 
     94 typedef struct pktq_prec {
     95 	void *head;
     96 	void *tail;
     97 	uint16 len;
     98 	uint16 max;
     99 } pktq_prec_t;
    100 
    101 
    102 
    103 struct pktq {
    104 	uint16 num_prec;
    105 	uint16 hi_prec;
    106 	uint16 max;
    107 	uint16 len;
    108 
    109 	struct pktq_prec q[PKTQ_MAX_PREC];
    110 };
    111 
    112 
    113 struct spktq {
    114 	uint16 num_prec;
    115 	uint16 hi_prec;
    116 	uint16 max;
    117 	uint16 len;
    118 
    119 	struct pktq_prec q[1];
    120 };
    121 
    122 #define PKTQ_PREC_ITER(pq, prec)        for (prec = (pq)->num_prec - 1; prec >= 0; prec--)
    123 
    124 
    125 
    126 
    127 struct ether_addr;
    128 
    129 extern int ether_isbcast(const void *ea);
    130 extern int ether_isnulladdr(const void *ea);
    131 
    132 
    133 
    134 #define pktq_psetmax(pq, prec, _max)    ((pq)->q[prec].max = (_max))
    135 #define pktq_plen(pq, prec)             ((pq)->q[prec].len)
    136 #define pktq_pavail(pq, prec)           ((pq)->q[prec].max - (pq)->q[prec].len)
    137 #define pktq_pfull(pq, prec)            ((pq)->q[prec].len >= (pq)->q[prec].max)
    138 #define pktq_pempty(pq, prec)           ((pq)->q[prec].len == 0)
    139 
    140 #define pktq_ppeek(pq, prec)            ((pq)->q[prec].head)
    141 #define pktq_ppeek_tail(pq, prec)       ((pq)->q[prec].tail)
    142 
    143 extern void *pktq_penq(struct pktq *pq, int prec, void *p);
    144 extern void *pktq_penq_head(struct pktq *pq, int prec, void *p);
    145 extern void *pktq_pdeq(struct pktq *pq, int prec);
    146 extern void *pktq_pdeq_tail(struct pktq *pq, int prec);
    147 
    148 extern bool pktq_pdel(struct pktq *pq, void *p, int prec);
    149 
    150 
    151 extern void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir);
    152 
    153 extern void pktq_flush(osl_t *osh, struct pktq *pq, bool dir);
    154 
    155 
    156 
    157 extern int pktq_mlen(struct pktq *pq, uint prec_bmp);
    158 extern void *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out);
    159 
    160 
    161 
    162 #define pktq_len(pq)                    ((int)(pq)->len)
    163 #define pktq_max(pq)                    ((int)(pq)->max)
    164 #define pktq_avail(pq)                  ((int)((pq)->max - (pq)->len))
    165 #define pktq_full(pq)                   ((pq)->len >= (pq)->max)
    166 #define pktq_empty(pq)                  ((pq)->len == 0)
    167 
    168 
    169 #define pktenq(pq, p)		pktq_penq(((struct pktq *)pq), 0, (p))
    170 #define pktenq_head(pq, p)	pktq_penq_head(((struct pktq *)pq), 0, (p))
    171 #define pktdeq(pq)		pktq_pdeq(((struct pktq *)pq), 0)
    172 #define pktdeq_tail(pq)		pktq_pdeq_tail(((struct pktq *)pq), 0)
    173 #define pktqinit(pq, len) pktq_init(((struct pktq *)pq), 1, len)
    174 
    175 extern void pktq_init(struct pktq *pq, int num_prec, int max_len);
    176 
    177 extern void *pktq_deq(struct pktq *pq, int *prec_out);
    178 extern void *pktq_deq_tail(struct pktq *pq, int *prec_out);
    179 extern void *pktq_peek(struct pktq *pq, int *prec_out);
    180 extern void *pktq_peek_tail(struct pktq *pq, int *prec_out);
    181 
    182 
    183 
    184 extern uint pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf);
    185 extern uint pktfrombuf(osl_t *osh, void *p, uint offset, int len, uchar *buf);
    186 extern uint pkttotlen(osl_t *osh, void *p);
    187 extern void *pktlast(osl_t *osh, void *p);
    188 extern uint pktsegcnt(osl_t *osh, void *p);
    189 
    190 
    191 extern uint pktsetprio(void *pkt, bool update_vtag);
    192 #define	PKTPRIO_VDSCP	0x100
    193 #define	PKTPRIO_VLAN	0x200
    194 #define	PKTPRIO_UPD	0x400
    195 #define	PKTPRIO_DSCP	0x800
    196 
    197 
    198 extern int bcm_atoi(char *s);
    199 extern ulong bcm_strtoul(char *cp, char **endp, uint base);
    200 extern char *bcmstrstr(char *haystack, char *needle);
    201 extern char *bcmstrcat(char *dest, const char *src);
    202 extern char *bcmstrncat(char *dest, const char *src, uint size);
    203 extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen);
    204 char* bcmstrtok(char **string, const char *delimiters, char *tokdelim);
    205 int bcmstricmp(const char *s1, const char *s2);
    206 int bcmstrnicmp(const char* s1, const char* s2, int cnt);
    207 
    208 
    209 
    210 extern char *bcm_ether_ntoa(const struct ether_addr *ea, char *buf);
    211 extern int bcm_ether_atoe(char *p, struct ether_addr *ea);
    212 
    213 
    214 struct ipv4_addr;
    215 extern char *bcm_ip_ntoa(struct ipv4_addr *ia, char *buf);
    216 
    217 
    218 extern void bcm_mdelay(uint ms);
    219 
    220 extern char *getvar(char *vars, const char *name);
    221 extern int getintvar(char *vars, const char *name);
    222 extern uint getgpiopin(char *vars, char *pin_name, uint def_pin);
    223 #define bcm_perf_enable()
    224 #define bcmstats(fmt)
    225 #define	bcmlog(fmt, a1, a2)
    226 #define	bcmdumplog(buf, size)	*buf = '\0'
    227 #define	bcmdumplogent(buf, idx)	-1
    228 
    229 #define bcmtslog(tstamp, fmt, a1, a2)
    230 #define bcmprinttslogs()
    231 #define bcmprinttstamp(us)
    232 
    233 
    234 
    235 
    236 typedef struct bcm_iovar {
    237 	const char *name;
    238 	uint16 varid;
    239 	uint16 flags;
    240 	uint16 type;
    241 	uint16 minlen;
    242 } bcm_iovar_t;
    243 
    244 
    245 
    246 
    247 #define IOV_GET 0
    248 #define IOV_SET 1
    249 
    250 
    251 #define IOV_GVAL(id)		((id)*2)
    252 #define IOV_SVAL(id)		(((id)*2)+IOV_SET)
    253 #define IOV_ISSET(actionid)	((actionid & IOV_SET) == IOV_SET)
    254 
    255 
    256 
    257 extern const bcm_iovar_t *bcm_iovar_lookup(const bcm_iovar_t *table, const char *name);
    258 extern int bcm_iovar_lencheck(const bcm_iovar_t *table, void *arg, int len, bool set);
    259 
    260 #endif
    261 
    262 
    263 #define IOVT_VOID	0
    264 #define IOVT_BOOL	1
    265 #define IOVT_INT8	2
    266 #define IOVT_UINT8	3
    267 #define IOVT_INT16	4
    268 #define IOVT_UINT16	5
    269 #define IOVT_INT32	6
    270 #define IOVT_UINT32	7
    271 #define IOVT_BUFFER	8
    272 #define BCM_IOVT_VALID(type) (((unsigned int)(type)) <= IOVT_BUFFER)
    273 
    274 
    275 #define BCM_IOV_TYPE_INIT { \
    276 	"void", \
    277 	"bool", \
    278 	"int8", \
    279 	"uint8", \
    280 	"int16", \
    281 	"uint16", \
    282 	"int32", \
    283 	"uint32", \
    284 	"buffer", \
    285 	"" }
    286 
    287 #define BCM_IOVT_IS_INT(type) (\
    288 	(type == IOVT_BOOL) || \
    289 	(type == IOVT_INT8) || \
    290 	(type == IOVT_UINT8) || \
    291 	(type == IOVT_INT16) || \
    292 	(type == IOVT_UINT16) || \
    293 	(type == IOVT_INT32) || \
    294 	(type == IOVT_UINT32))
    295 
    296 
    297 
    298 #define BCME_STRLEN 		64
    299 #define VALID_BCMERROR(e)  ((e <= 0) && (e >= BCME_LAST))
    300 
    301 
    302 
    303 
    304 #define BCME_OK				0
    305 #define BCME_ERROR			-1
    306 #define BCME_BADARG			-2
    307 #define BCME_BADOPTION			-3
    308 #define BCME_NOTUP			-4
    309 #define BCME_NOTDOWN			-5
    310 #define BCME_NOTAP			-6
    311 #define BCME_NOTSTA			-7
    312 #define BCME_BADKEYIDX			-8
    313 #define BCME_RADIOOFF 			-9
    314 #define BCME_NOTBANDLOCKED		-10
    315 #define BCME_NOCLK			-11
    316 #define BCME_BADRATESET			-12
    317 #define BCME_BADBAND			-13
    318 #define BCME_BUFTOOSHORT		-14
    319 #define BCME_BUFTOOLONG			-15
    320 #define BCME_BUSY			-16
    321 #define BCME_NOTASSOCIATED		-17
    322 #define BCME_BADSSIDLEN			-18
    323 #define BCME_OUTOFRANGECHAN		-19
    324 #define BCME_BADCHAN			-20
    325 #define BCME_BADADDR			-21
    326 #define BCME_NORESOURCE			-22
    327 #define BCME_UNSUPPORTED		-23
    328 #define BCME_BADLEN			-24
    329 #define BCME_NOTREADY			-25
    330 #define BCME_EPERM			-26
    331 #define BCME_NOMEM			-27
    332 #define BCME_ASSOCIATED			-28
    333 #define BCME_RANGE			-29
    334 #define BCME_NOTFOUND			-30
    335 #define BCME_WME_NOT_ENABLED		-31
    336 #define BCME_TSPEC_NOTFOUND		-32
    337 #define BCME_ACM_NOTSUPPORTED		-33
    338 #define BCME_NOT_WME_ASSOCIATION	-34
    339 #define BCME_SDIO_ERROR			-35
    340 #define BCME_DONGLE_DOWN		-36
    341 #define BCME_VERSION			-37
    342 #define BCME_TXFAIL			-38
    343 #define BCME_RXFAIL			-39
    344 #define BCME_NODEVICE			-40
    345 #define BCME_UNFINISHED			-41
    346 #define BCME_LAST			BCME_UNFINISHED
    347 
    348 
    349 #define BCMERRSTRINGTABLE {		\
    350 	"OK",				\
    351 	"Undefined error",		\
    352 	"Bad Argument",			\
    353 	"Bad Option",			\
    354 	"Not up",			\
    355 	"Not down",			\
    356 	"Not AP",			\
    357 	"Not STA",			\
    358 	"Bad Key Index",		\
    359 	"Radio Off",			\
    360 	"Not band locked",		\
    361 	"No clock",			\
    362 	"Bad Rate valueset",		\
    363 	"Bad Band",			\
    364 	"Buffer too short",		\
    365 	"Buffer too long",		\
    366 	"Busy",				\
    367 	"Not Associated",		\
    368 	"Bad SSID len",			\
    369 	"Out of Range Channel",		\
    370 	"Bad Channel",			\
    371 	"Bad Address",			\
    372 	"Not Enough Resources",		\
    373 	"Unsupported",			\
    374 	"Bad length",			\
    375 	"Not Ready",			\
    376 	"Not Permitted",		\
    377 	"No Memory",			\
    378 	"Associated",			\
    379 	"Not In Range",			\
    380 	"Not Found",			\
    381 	"WME Not Enabled",		\
    382 	"TSPEC Not Found",		\
    383 	"ACM Not Supported",		\
    384 	"Not WME Association",		\
    385 	"SDIO Bus Error",		\
    386 	"Dongle Not Accessible",	\
    387 	"Incorrect version",		\
    388 	"TX Failure",			\
    389 	"RX Failure",			\
    390 	"Device Not Present",		\
    391 	"Command not finished",		\
    392 }
    393 
    394 #ifndef ABS
    395 #define	ABS(a)			(((a) < 0)?-(a):(a))
    396 #endif
    397 
    398 #ifndef MIN
    399 #define	MIN(a, b)		(((a) < (b))?(a):(b))
    400 #endif
    401 
    402 #ifndef MAX
    403 #define	MAX(a, b)		(((a) > (b))?(a):(b))
    404 #endif
    405 
    406 #define CEIL(x, y)		(((x) + ((y)-1)) / (y))
    407 #define	ROUNDUP(x, y)		((((x)+((y)-1))/(y))*(y))
    408 #define	ISALIGNED(a, x)		(((a) & ((x)-1)) == 0)
    409 #define ALIGN_ADDR(addr, boundary) (void *)(((uintptr)(addr) + (boundary) - 1) \
    410 	                                         & ~((boundary) - 1))
    411 #define	ISPOWEROF2(x)		((((x)-1)&(x)) == 0)
    412 #define VALID_MASK(mask)	!((mask) & ((mask) + 1))
    413 #ifndef OFFSETOF
    414 #define	OFFSETOF(type, member)	((uint)(uintptr)&((type *)0)->member)
    415 #endif
    416 #ifndef ARRAYSIZE
    417 #define ARRAYSIZE(a)		(sizeof(a)/sizeof(a[0]))
    418 #endif
    419 
    420 
    421 #ifndef setbit
    422 #ifndef NBBY
    423 #define	NBBY	8
    424 #endif
    425 #define	setbit(a, i)	(((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
    426 #define	clrbit(a, i)	(((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
    427 #define	isset(a, i)	(((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
    428 #define	isclr(a, i)	((((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
    429 #endif
    430 
    431 #define	NBITS(type)	(sizeof(type) * 8)
    432 #define NBITVAL(nbits)	(1 << (nbits))
    433 #define MAXBITVAL(nbits)	((1 << (nbits)) - 1)
    434 #define	NBITMASK(nbits)	MAXBITVAL(nbits)
    435 #define MAXNBVAL(nbyte)	MAXBITVAL((nbyte) * 8)
    436 
    437 
    438 #define MUX(pred, true, false) ((pred) ? (true) : (false))
    439 
    440 
    441 #define MODDEC(x, bound) MUX((x) == 0, (bound) - 1, (x) - 1)
    442 #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
    443 
    444 
    445 #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
    446 #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
    447 
    448 
    449 #define MODADD(x, y, bound) \
    450     MUX((x) + (y) >= (bound), (x) + (y) - (bound), (x) + (y))
    451 #define MODSUB(x, y, bound) \
    452     MUX(((int)(x)) - ((int)(y)) < 0, (x) - (y) + (bound), (x) - (y))
    453 
    454 
    455 #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
    456 #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
    457 
    458 
    459 #define CRC8_INIT_VALUE  0xff
    460 #define CRC8_GOOD_VALUE  0x9f
    461 #define CRC16_INIT_VALUE 0xffff
    462 #define CRC16_GOOD_VALUE 0xf0b8
    463 #define CRC32_INIT_VALUE 0xffffffff
    464 #define CRC32_GOOD_VALUE 0xdebb20e3
    465 
    466 
    467 typedef struct bcm_bit_desc {
    468 	uint32	bit;
    469 	const char* name;
    470 } bcm_bit_desc_t;
    471 
    472 
    473 typedef struct bcm_tlv {
    474 	uint8	id;
    475 	uint8	len;
    476 	uint8	data[1];
    477 } bcm_tlv_t;
    478 
    479 
    480 #define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
    481 
    482 
    483 #define ETHER_ADDR_STR_LEN	18
    484 
    485 
    486 #ifdef IL_BIGENDIAN
    487 static INLINE uint32
    488 load32_ua(uint8 *a)
    489 {
    490 	return ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]);
    491 }
    492 
    493 static INLINE void
    494 store32_ua(uint8 *a, uint32 v)
    495 {
    496 	a[0] = (v >> 24) & 0xff;
    497 	a[1] = (v >> 16) & 0xff;
    498 	a[2] = (v >> 8) & 0xff;
    499 	a[3] = v & 0xff;
    500 }
    501 
    502 static INLINE uint16
    503 load16_ua(uint8 *a)
    504 {
    505 	return ((a[0] << 8) | a[1]);
    506 }
    507 
    508 static INLINE void
    509 store16_ua(uint8 *a, uint16 v)
    510 {
    511 	a[0] = (v >> 8) & 0xff;
    512 	a[1] = v & 0xff;
    513 }
    514 
    515 #else
    516 
    517 static INLINE uint32
    518 load32_ua(uint8 *a)
    519 {
    520 	return ((a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]);
    521 }
    522 
    523 static INLINE void
    524 store32_ua(uint8 *a, uint32 v)
    525 {
    526 	a[3] = (v >> 24) & 0xff;
    527 	a[2] = (v >> 16) & 0xff;
    528 	a[1] = (v >> 8) & 0xff;
    529 	a[0] = v & 0xff;
    530 }
    531 
    532 static INLINE uint16
    533 load16_ua(uint8 *a)
    534 {
    535 	return ((a[1] << 8) | a[0]);
    536 }
    537 
    538 static INLINE void
    539 store16_ua(uint8 *a, uint16 v)
    540 {
    541 	a[1] = (v >> 8) & 0xff;
    542 	a[0] = v & 0xff;
    543 }
    544 
    545 #endif
    546 
    547 
    548 
    549 static INLINE void
    550 xor_128bit_block(const uint8 *src1, const uint8 *src2, uint8 *dst)
    551 {
    552 	if (
    553 #ifdef __i386__
    554 	    1 ||
    555 #endif
    556 	    (((uintptr)src1 | (uintptr)src2 | (uintptr)dst) & 3) == 0) {
    557 
    558 
    559 		((uint32 *)dst)[0] = ((uint32 *)src1)[0] ^ ((uint32 *)src2)[0];
    560 		((uint32 *)dst)[1] = ((uint32 *)src1)[1] ^ ((uint32 *)src2)[1];
    561 		((uint32 *)dst)[2] = ((uint32 *)src1)[2] ^ ((uint32 *)src2)[2];
    562 		((uint32 *)dst)[3] = ((uint32 *)src1)[3] ^ ((uint32 *)src2)[3];
    563 	} else {
    564 
    565 		int k;
    566 		for (k = 0; k < 16; k++)
    567 			dst[k] = src1[k] ^ src2[k];
    568 	}
    569 }
    570 
    571 
    572 
    573 extern uint8 hndcrc8(uint8 *p, uint nbytes, uint8 crc);
    574 extern uint16 hndcrc16(uint8 *p, uint nbytes, uint16 crc);
    575 extern uint32 hndcrc32(uint8 *p, uint nbytes, uint32 crc);
    576 
    577 #if defined(DHD_DEBUG) || defined(WLMSG_PRHDRS) || defined(WLMSG_PRPKT) || \
    578 	defined(WLMSG_ASSOC)
    579 extern int bcm_format_flags(const bcm_bit_desc_t *bd, uint32 flags, char* buf, int len);
    580 extern int bcm_format_hex(char *str, const void *bytes, int len);
    581 extern void prhex(const char *msg, uchar *buf, uint len);
    582 #endif
    583 extern char *bcm_brev_str(uint32 brev, char *buf);
    584 extern void printbig(char *buf);
    585 
    586 
    587 extern bcm_tlv_t *bcm_next_tlv(bcm_tlv_t *elt, int *buflen);
    588 extern bcm_tlv_t *bcm_parse_tlvs(void *buf, int buflen, uint key);
    589 extern bcm_tlv_t *bcm_parse_ordered_tlvs(void *buf, int buflen, uint key);
    590 
    591 
    592 extern const char *bcmerrorstr(int bcmerror);
    593 
    594 
    595 typedef uint32 mbool;
    596 #define mboolset(mb, bit)		((mb) |= (bit))
    597 #define mboolclr(mb, bit)		((mb) &= ~(bit))
    598 #define mboolisset(mb, bit)		(((mb) & (bit)) != 0)
    599 #define	mboolmaskset(mb, mask, val)	((mb) = (((mb) & ~(mask)) | (val)))
    600 
    601 
    602 extern uint16 bcm_qdbm_to_mw(uint8 qdbm);
    603 extern uint8 bcm_mw_to_qdbm(uint16 mw);
    604 
    605 
    606 struct fielddesc {
    607 	const char *nameandfmt;
    608 	uint32 	offset;
    609 	uint32 	len;
    610 };
    611 
    612 extern void bcm_binit(struct bcmstrbuf *b, char *buf, uint size);
    613 extern int bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...);
    614 extern void bcm_inc_bytes(uchar *num, int num_bytes, uint8 amount);
    615 extern int bcm_cmp_bytes(uchar *arg1, uchar *arg2, uint8 nbytes);
    616 extern void bcm_print_bytes(char *name, const uchar *cdata, int len);
    617 
    618 typedef  uint32 (*bcmutl_rdreg_rtn)(void *arg0, uint arg1, uint32 offset);
    619 extern uint bcmdumpfields(bcmutl_rdreg_rtn func_ptr, void *arg0, uint arg1, struct fielddesc *str,
    620                           char *buf, uint32 bufsize);
    621 
    622 extern uint bcm_mkiovar(char *name, char *data, uint datalen, char *buf, uint len);
    623 extern uint bcm_bitcount(uint8 *bitmap, uint bytelength);
    624 
    625 #if defined(WLTINYDUMP) || defined(WLMSG_INFORM) || defined(WLMSG_ASSOC) || \
    626 	defined(WLMSG_PRPKT) || defined(WLMSG_WSEC)
    627 extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len);
    628 #endif
    629 
    630 
    631 #define SSID_FMT_BUF_LEN	((4 * DOT11_MAX_SSID_LEN) + 1)
    632 
    633 #ifdef __cplusplus
    634 	}
    635 #endif
    636 
    637 #endif
    638