Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 1 | /* |
Gopichand Nakkala | 92f07d8 | 2013-01-08 21:16:34 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | /* |
Jeff Johnson | 32d95a3 | 2012-09-10 13:15:23 -0700 | [diff] [blame] | 22 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 23 | * |
| 24 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 25 | * |
| 26 | * |
| 27 | * Permission to use, copy, modify, and/or distribute this software for |
| 28 | * any purpose with or without fee is hereby granted, provided that the |
| 29 | * above copyright notice and this permission notice appear in all |
| 30 | * copies. |
| 31 | * |
| 32 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 33 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 34 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 35 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 36 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 37 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 38 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 39 | * PERFORMANCE OF THIS SOFTWARE. |
| 40 | */ |
| 41 | |
| 42 | /* |
| 43 | * |
| 44 | * |
| 45 | * Airgo Networks, Inc proprietary. All rights reserved. |
| 46 | * Author: Kevin Nguyen |
| 47 | * Date: 02/27/02 |
| 48 | * History:- |
| 49 | * 02/12/02 Created. |
| 50 | * -------------------------------------------------------------------- |
| 51 | * |
| 52 | */ |
| 53 | |
| 54 | #ifndef __UTILSAPI_H |
| 55 | #define __UTILSAPI_H |
| 56 | |
| 57 | #include <stdarg.h> |
| 58 | #include <sirCommon.h> |
| 59 | #include "aniGlobal.h" |
| 60 | #include "utilsGlobal.h" |
| 61 | #if defined VOSS_ENABLED |
| 62 | #include "VossWrapper.h" |
| 63 | #elif defined ANI_OS_TYPE_LINUX |
| 64 | #include "rtaiWrapper.h" |
| 65 | #elif defined ANI_OS_TYPE_OSX |
| 66 | #include "palApiPci.h" |
| 67 | #endif |
| 68 | |
| 69 | |
| 70 | #if defined ANI_OS_TYPE_LINUX |
| 71 | |
| 72 | extern void rt_sched_lock(); |
| 73 | extern void rt_sched_unlock(); |
| 74 | |
Madan Mohan Koyyalamudi | a53c4dc | 2012-11-13 10:35:42 -0800 | [diff] [blame] | 75 | #define SIR_DECLARE_FLAGS (tANI_U32 flags) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 76 | #define SIR_SCHED_LOCK() rt_sched_lock() |
| 77 | #define SIR_SCHED_UNLOCK() rt_sched_unlock() |
| 78 | |
| 79 | #else |
| 80 | |
| 81 | #define SIR_DECLARE_FLAGS |
| 82 | #define SIR_SCHED_LOCK() TX_DISABLE_INTR; |
| 83 | #define SIR_SCHED_UNLOCK() TX_ENABLE_INTR; |
| 84 | |
| 85 | #endif |
| 86 | |
| 87 | #define LOG_INDEX_FOR_MODULE( modId ) ( ( modId ) - LOG_FIRST_MODULE_ID ) |
| 88 | #define GET_MIN_VALUE(__val1, __val2) ((__val1 < __val2) ? __val1 : __val2) |
| 89 | |
| 90 | // The caller must check loglevel. This API assumes loglevel is good |
| 91 | extern void logDebug(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 debugLevel, const char *pStr, va_list marker); |
| 92 | |
| 93 | extern void logDbg(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 debugLevel, const char *pStr,...); |
| 94 | |
| 95 | extern tANI_U32 gPktAllocCnt, gPktFreeCnt; |
| 96 | |
| 97 | /// Debug dumps |
| 98 | extern void logPrintf(tpAniSirGlobal, tANI_U32, tANI_U32 arg1, tANI_U32 arg2, tANI_U32 arg3, tANI_U32 arg4); |
| 99 | |
| 100 | /// RTAI dump |
| 101 | extern int logRtaiDump(tpAniSirGlobal, tANI_U32, tANI_U32, tANI_U32, tANI_U32, tANI_U32, tANI_U8 *); |
| 102 | |
| 103 | /// Log initialization |
| 104 | extern tSirRetStatus logInit (tpAniSirGlobal); |
| 105 | |
| 106 | extern void |
| 107 | logDeinit(tpAniSirGlobal ); |
| 108 | |
| 109 | extern tSirRetStatus cfgInit(tpAniSirGlobal); |
| 110 | extern void cfgDeInit(tpAniSirGlobal); |
| 111 | |
| 112 | // ------------------------------------------------------------------- |
| 113 | /** |
| 114 | * sirDumpBuf() |
| 115 | * |
| 116 | * FUNCTION: |
| 117 | * This function is called to dump a buffer with a certain level |
| 118 | * |
| 119 | * LOGIC: |
| 120 | * |
| 121 | * ASSUMPTIONS: |
| 122 | * None. |
| 123 | * |
| 124 | * NOTE: |
| 125 | * |
| 126 | * @param pBuf: buffer pointer |
| 127 | * @return None. |
| 128 | */ |
| 129 | |
| 130 | void sirDumpBuf(tpAniSirGlobal pMac, tANI_U8 modId, tANI_U32 level, tANI_U8 *buf, tANI_U32 size); |
| 131 | |
| 132 | #if defined ANI_OS_TYPE_LINUX |
| 133 | |
| 134 | |
| 135 | struct rtLibApp; |
| 136 | void* rtaiBufAlloc(struct rtLibApp * rt, tANI_U16 size, tANI_U32 waitOpt); |
| 137 | tSirRetStatus rtaiBufInit(unsigned int radioId, t_mac_block_table* block_table); |
| 138 | tANI_U16 rtaiBufAvail(tANI_U16 size); |
| 139 | |
| 140 | extern void sysSuspendThreads(tpAniSirGlobal pMac); |
| 141 | |
| 142 | #define sharedBufAlloc(pMac, x, y) rtaiBufAlloc(pMac->rt,x,y) |
| 143 | #define bufInit(x) rtaiBufInit(x) |
| 144 | #define bufAvail(x) rtaiBufAvail(x) |
| 145 | |
| 146 | #define BUF_32 32 |
| 147 | #define BUF_64 64 |
| 148 | #define BUF_96 96 |
| 149 | #define BUF_128 128 |
| 150 | #define BUF_160 160 |
| 151 | #define BUF_256 256 |
| 152 | #define BUF_512 512 |
| 153 | #define BUF_1024 1024 |
| 154 | #define BUF_1536 1536 |
| 155 | #define BUF_2048 2048 |
| 156 | #define BUF_8192 8192 |
| 157 | #define RTAI_MAX_BUF_SIZE BUF_8192 |
| 158 | |
| 159 | #endif |
| 160 | |
| 161 | // -------------------------------------------------------------------- |
| 162 | /** |
| 163 | * sirSwapU16() |
| 164 | * |
| 165 | * FUNCTION: |
| 166 | * This function is called to swap two U8s of an tANI_U16 value |
| 167 | * |
| 168 | * LOGIC: |
| 169 | * |
| 170 | * ASSUMPTIONS: |
| 171 | * None. |
| 172 | * |
| 173 | * NOTE: |
| 174 | * |
| 175 | * @param val tANI_U16 value to be tANI_U8 swapped |
| 176 | * @return Swapped tANI_U16 value |
| 177 | */ |
| 178 | |
| 179 | static inline tANI_U16 |
| 180 | sirSwapU16(tANI_U16 val) |
| 181 | { |
| 182 | return(((val & 0x00FF) << 8) | ((val & 0xFF00) >> 8)); |
| 183 | }/*** end sirSwapU16() ***/ |
| 184 | |
| 185 | // -------------------------------------------------------------------- |
| 186 | /** |
| 187 | * sirSwapU16ifNeeded() |
| 188 | * |
| 189 | * FUNCTION: |
| 190 | * This function is called to swap two U8s of an tANI_U16 value depending |
| 191 | * on endiannes of the target processor/compiler the software is |
| 192 | * running on |
| 193 | * |
| 194 | * LOGIC: |
| 195 | * |
| 196 | * ASSUMPTIONS: |
| 197 | * None. |
| 198 | * |
| 199 | * NOTE: |
| 200 | * |
| 201 | * @param val tANI_U16 value to be tANI_U8 swapped |
| 202 | * @return Swapped tANI_U16 value |
| 203 | */ |
| 204 | |
| 205 | static inline tANI_U16 |
| 206 | sirSwapU16ifNeeded(tANI_U16 val) |
| 207 | { |
| 208 | #ifndef ANI_LITTLE_BYTE_ENDIAN |
| 209 | return sirSwapU16(val); |
| 210 | #else |
| 211 | return val; |
| 212 | #endif |
| 213 | }/*** end sirSwapU16ifNeeded() ***/ |
| 214 | |
| 215 | // -------------------------------------------------------------------- |
| 216 | /** |
| 217 | * sirSwapU32() |
| 218 | * |
| 219 | * FUNCTION: |
| 220 | * This function is called to swap four U8s of an tANI_U32 value |
| 221 | * |
| 222 | * LOGIC: |
| 223 | * |
| 224 | * ASSUMPTIONS: |
| 225 | * None. |
| 226 | * |
| 227 | * NOTE: |
| 228 | * |
| 229 | * @param val tANI_U32 value to be tANI_U8 swapped |
| 230 | * @return Swapped tANI_U32 value |
| 231 | */ |
| 232 | |
| 233 | static inline tANI_U32 |
| 234 | sirSwapU32(tANI_U32 val) |
| 235 | { |
| 236 | return((val << 24) | |
| 237 | (val >> 24) | |
| 238 | ((val & 0x0000FF00) << 8) | |
| 239 | ((val & 0x00FF0000) >> 8)); |
| 240 | }/*** end sirSwapU32() ***/ |
| 241 | |
| 242 | // -------------------------------------------------------------------- |
| 243 | /** |
| 244 | * sirSwapU32ifNeeded() |
| 245 | * |
| 246 | * FUNCTION: |
| 247 | * This function is called to swap U8s of an tANI_U32 value depending |
| 248 | * on endiannes of the target processor/compiler the software is |
| 249 | * running on |
| 250 | * |
| 251 | * LOGIC: |
| 252 | * |
| 253 | * ASSUMPTIONS: |
| 254 | * None. |
| 255 | * |
| 256 | * NOTE: |
| 257 | * |
| 258 | * @param val tANI_U32 value to be tANI_U8 swapped |
| 259 | * @return Swapped tANI_U32 value |
| 260 | */ |
| 261 | |
| 262 | static inline tANI_U32 |
| 263 | sirSwapU32ifNeeded(tANI_U32 val) |
| 264 | { |
| 265 | #ifndef ANI_LITTLE_BYTE_ENDIAN |
| 266 | return sirSwapU32(val); |
| 267 | #else |
| 268 | return val; |
| 269 | #endif |
| 270 | }/*** end sirSwapU32ifNeeded() ***/ |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | // ------------------------------------------------------------------- |
| 276 | /** |
| 277 | * sirSwapU32Buf |
| 278 | * |
| 279 | * FUNCTION: |
| 280 | * It swaps N dwords into the same buffer |
| 281 | * |
| 282 | * LOGIC: |
| 283 | * |
| 284 | * ASSUMPTIONS: |
| 285 | * None. |
| 286 | * |
| 287 | * NOTE: |
| 288 | * |
| 289 | * @param ptr address of tANI_U32 array |
| 290 | * @return void |
| 291 | * |
| 292 | */ |
| 293 | |
| 294 | static inline void |
| 295 | sirSwapU32Buf(tANI_U32 *ptr, tANI_U32 nWords) |
| 296 | { |
| 297 | tANI_U32 i; |
| 298 | |
| 299 | for (i=0; i < nWords; i++) |
| 300 | ptr[i] = sirSwapU32(ptr[i]); |
| 301 | } |
| 302 | |
| 303 | // -------------------------------------------------------------------- |
| 304 | /** |
| 305 | * sirSwapU32BufIfNeeded() |
| 306 | * |
| 307 | * FUNCTION: |
| 308 | * This function is called to swap U8s of U32s in the buffer depending |
| 309 | * on endiannes of the target processor/compiler the software is |
| 310 | * running on |
| 311 | * |
| 312 | * LOGIC: |
| 313 | * |
| 314 | * ASSUMPTIONS: |
| 315 | * None. |
| 316 | * |
| 317 | * NOTE: |
| 318 | * |
| 319 | * @param pBuf Buffer that will get swapped |
| 320 | * @param nWords Number DWORDS will be swapped |
| 321 | * @return void |
| 322 | */ |
| 323 | |
| 324 | static inline void |
| 325 | sirSwapU32BufIfNeeded(tANI_U32* pBuf, tANI_U32 nWords) |
| 326 | { |
| 327 | #ifdef ANI_LITTLE_BYTE_ENDIAN |
| 328 | sirSwapU32Buf(pBuf, nWords); |
| 329 | #endif |
| 330 | }/*** end sirSwapU32ifNeeded() ***/ |
| 331 | |
| 332 | |
| 333 | // -------------------------------------------------------------------- |
| 334 | /** |
| 335 | * sirSwapBDIfNeeded |
| 336 | * |
| 337 | * FUNCTION: |
| 338 | * Byte swap all the dwords in the BD, except the PHY/MAC headers |
| 339 | * |
| 340 | * LOGIC: |
| 341 | * |
| 342 | * ASSUMPTIONS: |
| 343 | * None. |
| 344 | * |
| 345 | * NOTE: |
| 346 | * |
| 347 | * @param pBd BD that will get swapped |
| 348 | * @return void |
| 349 | */ |
| 350 | |
| 351 | static inline void |
| 352 | sirSwapBDIfNeeded(tANI_U32 *pBd) |
| 353 | { |
| 354 | sirSwapU32BufIfNeeded(pBd, 6); |
| 355 | sirSwapU32BufIfNeeded(pBd+18, 14); |
| 356 | } |
| 357 | |
| 358 | |
| 359 | // ------------------------------------------------------------------- |
| 360 | /** |
| 361 | * sirStoreU16N |
| 362 | * |
| 363 | * FUNCTION: |
| 364 | * It stores a 16 bit number into the byte array in network byte order |
| 365 | * i.e. the least significant byte first |
| 366 | * |
| 367 | * LOGIC: |
| 368 | * |
| 369 | * ASSUMPTIONS: |
| 370 | * None. |
| 371 | * |
| 372 | * NOTE: |
| 373 | * |
| 374 | * @param ptr address of destination byte array |
| 375 | * @param val value to store |
| 376 | * @return None |
| 377 | */ |
| 378 | |
| 379 | static inline void |
| 380 | sirStoreU16N(tANI_U8 *ptr, tANI_U16 val) |
| 381 | { |
| 382 | *ptr++ = (val >> 8) & 0xff; |
| 383 | *ptr = val & 0xff; |
| 384 | } |
| 385 | |
| 386 | // ------------------------------------------------------------------- |
| 387 | /** |
| 388 | * sirStoreU32N |
| 389 | * |
| 390 | * FUNCTION: |
| 391 | * It stores a 32 bit number into the byte array in network byte order |
| 392 | * i.e. the least significant byte first |
| 393 | * |
| 394 | * LOGIC: |
| 395 | * |
| 396 | * ASSUMPTIONS: |
| 397 | * None. |
| 398 | * |
| 399 | * NOTE: |
| 400 | * |
| 401 | * @param ptr address of destination byte array |
| 402 | * @param val value to store |
| 403 | * @return None |
| 404 | */ |
| 405 | |
| 406 | static inline void |
| 407 | sirStoreU32N(tANI_U8 *ptr, tANI_U32 val) |
| 408 | { |
| 409 | *ptr++ = (tANI_U8) (val >> 24) & 0xff; |
| 410 | *ptr++ = (tANI_U8) (val >> 16) & 0xff; |
| 411 | *ptr++ = (tANI_U8) (val >> 8) & 0xff; |
| 412 | *ptr = (tANI_U8) (val) & 0xff; |
| 413 | } |
| 414 | |
| 415 | // ------------------------------------------------------------------- |
| 416 | /** |
| 417 | * sirStoreU16 |
| 418 | * |
| 419 | * FUNCTION: |
| 420 | * It stores a 16 bit number into the byte array in NON-network byte order |
| 421 | * i.e. the least significant byte first |
| 422 | * |
| 423 | * LOGIC: |
| 424 | * |
| 425 | * ASSUMPTIONS: |
| 426 | * None. |
| 427 | * |
| 428 | * NOTE: |
| 429 | * |
| 430 | * @param ptr address of destination byte array |
| 431 | * @param val value to store |
| 432 | * @return None |
| 433 | */ |
| 434 | |
| 435 | static inline void |
| 436 | sirStoreU16(tANI_U8 *ptr, tANI_U16 val) |
| 437 | { |
| 438 | *ptr++ = val & 0xff; |
| 439 | *ptr = (val >> 8) & 0xff; |
| 440 | } |
| 441 | |
| 442 | // ------------------------------------------------------------------- |
| 443 | /** |
| 444 | * sirStoreU32 |
| 445 | * |
| 446 | * FUNCTION: |
| 447 | * It stores a 32 bit number into the byte array in NON-network byte order |
| 448 | * i.e. the least significant byte first |
| 449 | * |
| 450 | * LOGIC: |
| 451 | * |
| 452 | * ASSUMPTIONS: |
| 453 | * None. |
| 454 | * |
| 455 | * NOTE: |
| 456 | * |
| 457 | * @param ptr address of destination byte array |
| 458 | * @param val value to store |
| 459 | * @return None |
| 460 | */ |
| 461 | |
| 462 | static inline void |
| 463 | sirStoreU32(tANI_U8 *ptr, tANI_U32 val) |
| 464 | { |
| 465 | *ptr++ = (tANI_U8) val & 0xff; |
| 466 | *ptr++ = (tANI_U8) (val >> 8) & 0xff; |
| 467 | *ptr++ = (tANI_U8) (val >> 16) & 0xff; |
| 468 | *ptr = (tANI_U8) (val >> 24) & 0xff; |
| 469 | } |
| 470 | |
| 471 | // ------------------------------------------------------------------- |
| 472 | /** |
| 473 | * sirStoreU32BufN |
| 474 | * |
| 475 | * FUNCTION: |
| 476 | * It stores a 32 bit number into the byte array in network byte order |
| 477 | * i.e. the least significant byte first. It performs the above operation |
| 478 | * on entire buffer and writes to the dst buffer |
| 479 | * |
| 480 | * LOGIC: |
| 481 | * |
| 482 | * ASSUMPTIONS: |
| 483 | * Assumes that the pSrc buffer is of all tANI_U32 data type fields. |
| 484 | * |
| 485 | * NOTE: |
| 486 | * Must be used if all the fields in the buffer must be of tANI_U32 types. |
| 487 | * |
| 488 | * @param pDst address of destination byte array |
| 489 | * @param pSrc address of the source DWORD array |
| 490 | * @param length number of DWORDs |
| 491 | * @return None |
| 492 | */ |
| 493 | |
| 494 | static inline void |
| 495 | sirStoreBufN(tANI_U8* pDst, tANI_U32* pSrc, tANI_U32 length) |
| 496 | { |
| 497 | while (length) |
| 498 | { |
| 499 | sirStoreU32N(pDst, *pSrc); |
| 500 | pDst += 4; |
| 501 | pSrc++; |
| 502 | length--; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | // ------------------------------------------------------------------- |
| 507 | /** |
| 508 | * sirReadU16N |
| 509 | * |
| 510 | * FUNCTION: |
| 511 | * It reads a 16 bit number from the byte array in network byte order |
| 512 | * i.e. the least significant byte first |
| 513 | * |
| 514 | * LOGIC: |
| 515 | * |
| 516 | * ASSUMPTIONS: |
| 517 | * None. |
| 518 | * |
| 519 | * NOTE: |
| 520 | * |
| 521 | * @param ptr address of byte array |
| 522 | * @return 16 bit value |
| 523 | */ |
| 524 | |
| 525 | static inline tANI_U16 |
| 526 | sirReadU16N(tANI_U8 *ptr) |
| 527 | { |
| 528 | return(((*ptr) << 8) | |
| 529 | (*(ptr+1))); |
| 530 | } |
| 531 | /** |
| 532 | * sirSwapU32Buf |
| 533 | * |
| 534 | * FUNCTION: |
| 535 | * It swaps N dwords into the same buffer |
| 536 | * |
| 537 | * LOGIC: |
| 538 | * |
| 539 | * ASSUMPTIONS: |
| 540 | * None. |
| 541 | * |
| 542 | * NOTE: |
| 543 | * |
| 544 | * @param ptr address of tANI_U32 array |
| 545 | * @return void |
| 546 | * |
| 547 | */ |
| 548 | |
| 549 | static inline void |
| 550 | sirSwapNStore(tANI_U32 *src, tANI_U32 *dst, tANI_U32 nWords) |
| 551 | { |
| 552 | tANI_U32 i; |
| 553 | |
| 554 | for (i=0; i < nWords; i++) |
| 555 | dst[i] = sirSwapU32(src[i]); |
| 556 | } |
| 557 | |
| 558 | // ------------------------------------------------------------------- |
| 559 | /** |
| 560 | * sirReadU32N |
| 561 | * |
| 562 | * FUNCTION: |
| 563 | * It reads a 32 bit number from the byte array in network byte order |
| 564 | * i.e. the least significant byte first |
| 565 | * |
| 566 | * LOGIC: |
| 567 | * |
| 568 | * ASSUMPTIONS: |
| 569 | * None. |
| 570 | * |
| 571 | * NOTE: |
| 572 | * |
| 573 | * @param ptr address of byte array |
| 574 | * @return 32 bit value |
| 575 | */ |
| 576 | |
| 577 | static inline tANI_U32 |
| 578 | sirReadU32N(tANI_U8 *ptr) |
| 579 | { |
| 580 | return((*(ptr) << 24) | |
| 581 | (*(ptr+1) << 16) | |
| 582 | (*(ptr+2) << 8) | |
| 583 | (*(ptr+3))); |
| 584 | } |
| 585 | |
| 586 | // ------------------------------------------------------------------- |
| 587 | /** |
| 588 | * sirReadU16 |
| 589 | * |
| 590 | * FUNCTION: |
| 591 | * It reads a 16 bit number from the byte array in NON-network byte order |
| 592 | * i.e. the least significant byte first |
| 593 | * |
| 594 | * LOGIC: |
| 595 | * |
| 596 | * ASSUMPTIONS: |
| 597 | * None. |
| 598 | * |
| 599 | * NOTE: |
| 600 | * |
| 601 | * @param ptr address of byte array |
| 602 | * @return 16 bit value |
| 603 | */ |
| 604 | |
| 605 | static inline tANI_U16 |
| 606 | sirReadU16(tANI_U8 *ptr) |
| 607 | { |
| 608 | return((*ptr) | |
| 609 | (*(ptr+1) << 8)); |
| 610 | } |
| 611 | |
| 612 | // ------------------------------------------------------------------- |
| 613 | /** |
| 614 | * sirReadU32 |
| 615 | * |
| 616 | * FUNCTION: |
| 617 | * It reads a 32 bit number from the byte array in NON-network byte order |
| 618 | * i.e. the least significant byte first |
| 619 | * |
| 620 | * LOGIC: |
| 621 | * |
| 622 | * ASSUMPTIONS: |
| 623 | * None. |
| 624 | * |
| 625 | * NOTE: |
| 626 | * |
| 627 | * @param ptr address of byte array |
| 628 | * @return 32 bit value |
| 629 | */ |
| 630 | |
| 631 | static inline tANI_U32 |
| 632 | sirReadU32(tANI_U8 *ptr) |
| 633 | { |
| 634 | return((*(ptr)) | |
| 635 | (*(ptr+1) << 8) | |
| 636 | (*(ptr+2) << 16) | |
| 637 | (*(ptr+3) << 24)); |
| 638 | } |
| 639 | |
| 640 | // ------------------------------------------------------------------- |
| 641 | |
| 642 | |
| 643 | /// Copy a MAC address from 'from' to 'to' |
| 644 | static inline void |
| 645 | sirCopyMacAddr(tANI_U8 to[], tANI_U8 from[]) |
| 646 | { |
| 647 | #if defined( _X86_ ) |
| 648 | tANI_U32 align = (0x3 & ((tANI_U32) to | (tANI_U32) from )); |
| 649 | if( align ==0){ |
| 650 | *((tANI_U16 *) &(to[4])) = *((tANI_U16 *) &(from[4])); |
| 651 | *((tANI_U32 *) to) = *((tANI_U32 *) from); |
| 652 | }else if (align == 2){ |
| 653 | *((tANI_U16 *) &to[4]) = *((tANI_U16 *) &from[4]); |
| 654 | *((tANI_U16 *) &to[2]) = *((tANI_U16 *) &from[2]); |
| 655 | *((tANI_U16 *) &to[0]) = *((tANI_U16 *) &from[0]); |
| 656 | }else{ |
| 657 | to[5] = from[5]; |
| 658 | to[4] = from[4]; |
| 659 | to[3] = from[3]; |
| 660 | to[2] = from[2]; |
| 661 | to[1] = from[1]; |
| 662 | to[0] = from[0]; |
| 663 | } |
| 664 | #else |
| 665 | to[0] = from[0]; |
| 666 | to[1] = from[1]; |
| 667 | to[2] = from[2]; |
| 668 | to[3] = from[3]; |
| 669 | to[4] = from[4]; |
| 670 | to[5] = from[5]; |
| 671 | #endif |
| 672 | } |
| 673 | |
| 674 | static inline tANI_U8 |
| 675 | sirCompareMacAddr(tANI_U8 addr1[], tANI_U8 addr2[]) |
| 676 | { |
| 677 | #if defined( _X86_ ) |
| 678 | tANI_U32 align = (0x3 & ((tANI_U32) addr1 | (tANI_U32) addr2 )); |
| 679 | |
| 680 | if( align ==0){ |
| 681 | return ((*((tANI_U16 *) &(addr1[4])) == *((tANI_U16 *) &(addr2[4])))&& |
| 682 | (*((tANI_U32 *) addr1) == *((tANI_U32 *) addr2))); |
| 683 | }else if(align == 2){ |
| 684 | return ((*((tANI_U16 *) &addr1[4]) == *((tANI_U16 *) &addr2[4])) && |
| 685 | (*((tANI_U16 *) &addr1[2]) == *((tANI_U16 *) &addr2[2])) && |
| 686 | (*((tANI_U16 *) &addr1[0]) == *((tANI_U16 *) &addr2[0]))); |
| 687 | }else{ |
| 688 | return ( (addr1[5]==addr2[5])&& |
| 689 | (addr1[4]==addr2[4])&& |
| 690 | (addr1[3]==addr2[3])&& |
| 691 | (addr1[2]==addr2[2])&& |
| 692 | (addr1[1]==addr2[1])&& |
| 693 | (addr1[0]==addr2[0])); |
| 694 | } |
| 695 | #else |
| 696 | return ( (addr1[0]==addr2[0])&& |
| 697 | (addr1[1]==addr2[1])&& |
| 698 | (addr1[2]==addr2[2])&& |
| 699 | (addr1[3]==addr2[3])&& |
| 700 | (addr1[4]==addr2[4])&& |
| 701 | (addr1[5]==addr2[5])); |
| 702 | #endif |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /* |
| 707 | * converts tANI_U16 CW value to 4 bit value to be inserted in IE |
| 708 | */ |
| 709 | static inline tANI_U8 convertCW(tANI_U16 cw) |
| 710 | { |
| 711 | tANI_U8 val = 0; |
| 712 | while (cw > 0) |
| 713 | { |
| 714 | val++; |
| 715 | cw >>= 1; |
| 716 | } |
| 717 | if (val > 15) |
| 718 | return 0xF; |
| 719 | return val; |
| 720 | } |
| 721 | |
| 722 | /* The user priority to AC mapping is such: |
| 723 | * UP(1, 2) ---> AC_BK(1) |
| 724 | * UP(0, 3) ---> AC_BE(0) |
| 725 | * UP(4, 5) ---> AC_VI(2) |
| 726 | * UP(6, 7) ---> AC_VO(3) |
| 727 | */ |
| 728 | #define WLAN_UP_TO_AC_MAP 0x33220110 |
| 729 | #define upToAc(up) ((WLAN_UP_TO_AC_MAP >> ((up) << 2)) & 0x03) |
| 730 | |
| 731 | #if defined VOSS_ENABLED |
| 732 | |
| 733 | #define sirBusyWait(microsecond) vos_busy_wait(microsecond / 1000) |
| 734 | #define sirSleepWait(duration) vos_sleep_us(duration) |
| 735 | |
| 736 | #elif defined ANI_OS_TYPE_LINUX |
| 737 | //rt_busy_sleep(duration) |
| 738 | |
| 739 | #define sirBusyWait(duration) tx_busy_wait(duration) |
| 740 | |
| 741 | #define sirSleepWait(duration) sirSleepWaitIntern(duration) |
| 742 | |
| 743 | #elif defined ANI_OS_TYPE_WINDOWS |
| 744 | |
| 745 | #define sirBusyWait(duration) sirBusyWaitIntern(pMac, duration) |
| 746 | |
| 747 | #define sirSleepWait(duration) sirSleepWaitIntern(pMac, duration) |
| 748 | |
| 749 | #elif defined ANI_OS_TYPE_OSX |
| 750 | #define sirBusyWait(duration) palBusyWait(duration) |
| 751 | #define sirSleepWait(duration) palSleepWait(duration) |
| 752 | #endif |
| 753 | |
| 754 | |
| 755 | |
| 756 | /**--------------------------------------------------------------------- |
| 757 | * sirSleepWait |
| 758 | * |
| 759 | * FUNCTION: |
| 760 | * This function is called to yield the CPU for a given duration |
| 761 | * |
| 762 | * LOGIC: |
| 763 | * |
| 764 | * ASSUMPTIONS: |
| 765 | * None. |
| 766 | * |
| 767 | * NOTE: |
| 768 | * |
| 769 | * @param duration Duration to yield (nanoseconds) |
| 770 | * @return None |
| 771 | */ |
| 772 | |
| 773 | #if defined ANI_OS_TYPE_WINDOWS |
| 774 | |
| 775 | static inline void |
| 776 | sirSleepWaitIntern(void *pMac, tANI_U32 duration) |
| 777 | |
| 778 | #else |
| 779 | |
| 780 | static inline void |
| 781 | sirSleepWaitIntern(tANI_U32 duration) |
| 782 | |
| 783 | #endif |
| 784 | { |
| 785 | #if defined ANI_OS_TYPE_LINUX |
| 786 | //temporary measure: not sure we can sleep less than 500usec on rtai |
| 787 | //so sleep at this amount of time so as we are garanteed to yield |
| 788 | if (duration<500000) |
| 789 | duration=500000; |
| 790 | tx_thread_sleep(duration); |
| 791 | // rt_sleep(duration/40/*temporary magic number: clock is 25MHz*/); |
| 792 | #elif defined ANI_OS_TYPE_WINDOWS |
| 793 | // Can't sleep on windows at dispatch level |
| 794 | // what to do here? |
| 795 | if (duration >= 50000) |
| 796 | { |
| 797 | tANI_U32 i; |
| 798 | |
| 799 | for (i = duration / 50000; i; i--) |
| 800 | sirBusyWait(50000); |
| 801 | } |
| 802 | #endif |
| 803 | } // sirSleepWait |
| 804 | |
| 805 | // ------------------------------------------------------------------- |
| 806 | |
| 807 | /// Parse the next IE in a message |
| 808 | extern tSirRetStatus sirParseNextIE(tpAniSirGlobal, tANI_U8 *pPayload, |
| 809 | tANI_U16 payloadLength, tANI_S16 lastType, |
| 810 | tANI_U8 *pType, tANI_U8 *pLength); |
| 811 | |
| 812 | /// Check if the given channel is 11b channel |
| 813 | #define SIR_IS_CHANNEL_11B(chId) (chId <= 14) |
| 814 | |
| 815 | // ------------------------------------------------------------------- |
| 816 | /** |
| 817 | * halRoundS32 |
| 818 | * |
| 819 | * FUNCTION: |
| 820 | * Performs integer rounding like returns 12346 for 123456 or -12346 for -123456 |
| 821 | * Note that a decimal place is lost. |
| 822 | * |
| 823 | * LOGIC: |
| 824 | * |
| 825 | * ASSUMPTIONS: |
| 826 | * None. |
| 827 | * |
| 828 | * NOTE: |
| 829 | * |
| 830 | * @param tANI_S32 input |
| 831 | * @return rounded number |
| 832 | */ |
| 833 | static inline tANI_S32 |
| 834 | halRoundS32(tANI_S32 p) |
| 835 | { |
| 836 | tANI_S32 k, i, j; |
| 837 | |
| 838 | i = p/10; |
| 839 | j = p%10; |
| 840 | if (p > 0) |
| 841 | k = i + (j > 4 ? 1 : 0); |
| 842 | else if (p < 0) |
| 843 | k = i + (j < -5 ? -1 : 0); |
| 844 | else |
| 845 | k = p; |
| 846 | |
| 847 | return(k); |
| 848 | } |
| 849 | |
| 850 | // New functions for endianess conversion |
| 851 | #ifdef ANI_LITTLE_BYTE_ENDIAN |
| 852 | #define ani_cpu_to_be16(x) sirSwapU16((x)) |
| 853 | #define ani_cpu_to_le16(x) (x) |
| 854 | #define ani_cpu_to_be32(x) sirSwapU32((x)) |
| 855 | #define ani_cpu_to_le32(x) (x) |
| 856 | #else // ANI_LITTLE_BYTE_ENDIAN |
| 857 | #define ani_cpu_to_be16(x) (x) |
| 858 | #define ani_cpu_to_le16(x) sirSwapU16((x)) |
| 859 | #define ani_cpu_to_be32(x) (x) |
| 860 | #define ani_cpu_to_le32(x) sirSwapU32((x)) |
| 861 | #endif // ANI_LITTLE_BYTE_ENDIAN |
| 862 | |
| 863 | #define ani_le16_to_cpu(x) ani_cpu_to_le16(x) |
| 864 | #define ani_le32_to_cpu(x) ani_cpu_to_le32(x) |
| 865 | #define ani_be16_to_cpu(x) ani_cpu_to_be16(x) |
| 866 | #define ani_be32_to_cpu(x) ani_cpu_to_be32(x) |
| 867 | |
| 868 | void ConverttoBigEndian(void *ptr, tANI_U16 size); |
| 869 | void CreateScanCtsFrame(tpAniSirGlobal pMac, tSirMacMgmtHdr *macMgmtHdr, tSirMacAddr selfMac); |
| 870 | void CreateScanDataNullFrame(tpAniSirGlobal pMac, tSirMacMgmtHdr *macMgmtHdr, |
| 871 | tANI_U8 pwrMgmt, tSirMacAddr bssid, |
| 872 | tSirMacAddr selfMacAddr); |
| 873 | void CreateInitScanRawFrame(tpAniSirGlobal pMac, tSirMacMgmtHdr *macMgmtHdr, tBssSystemRole role); |
| 874 | void CreateFinishScanRawFrame(tpAniSirGlobal pMac, tSirMacMgmtHdr *macMgmtHdr, tBssSystemRole role); |
| 875 | |
| 876 | #endif /* __UTILSAPI_H */ |
| 877 | |
| 878 | |