1 /** \file utils.h 2 * \brief utils API 3 * 4 * \see utils.c 5 */ 6 /**************************************************************************** 7 **+-----------------------------------------------------------------------+** 8 **| |** 9 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |** 10 **| All rights reserved. |** 11 **| |** 12 **| Redistribution and use in source and binary forms, with or without |** 13 **| modification, are permitted provided that the following conditions |** 14 **| are met: |** 15 **| |** 16 **| * Redistributions of source code must retain the above copyright |** 17 **| notice, this list of conditions and the following disclaimer. |** 18 **| * Redistributions in binary form must reproduce the above copyright |** 19 **| notice, this list of conditions and the following disclaimer in |** 20 **| the documentation and/or other materials provided with the |** 21 **| distribution. |** 22 **| * Neither the name Texas Instruments nor the names of its |** 23 **| contributors may be used to endorse or promote products derived |** 24 **| from this software without specific prior written permission. |** 25 **| |** 26 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |** 27 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |** 28 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |** 29 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |** 30 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |** 31 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |** 32 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |** 33 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |** 34 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |** 35 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |** 36 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |** 37 **| |** 38 **+-----------------------------------------------------------------------+** 39 ****************************************************************************/ 40 41 /****************************************************************************/ 42 /* */ 43 /* MODULE: utils.h */ 44 /* PURPOSE: utilities API, contains some utilites function to be used */ 45 /* by the COre & HAL */ 46 /* */ 47 /***************************************************************************/ 48 #ifndef __UTILS_H__ 49 #define __UTILS_H__ 50 51 #include "osTIType.h" 52 #include "commonTypes.h" 53 #include "memMngrEx.h" 54 #include "802_11Defs.h" 55 56 /* TODO: replace the following macros with a faster code. */ 57 #define MAC_COPY(pOsContext,pDstMac,pSrcMac) \ 58 os_memoryCopy(pOsContext, (void *)((pDstMac)->addr), (void *)((pSrcMac)->addr), MAC_ADDR_LEN) 59 #define MAC_EQUAL(pDstMac,pSrcMac) \ 60 ((pDstMac)->addr[0] == (pSrcMac)->addr[0] && \ 61 (pDstMac)->addr[1] == (pSrcMac)->addr[1] && \ 62 (pDstMac)->addr[2] == (pSrcMac)->addr[2] && \ 63 (pDstMac)->addr[3] == (pSrcMac)->addr[3] && \ 64 (pDstMac)->addr[4] == (pSrcMac)->addr[4] && \ 65 (pDstMac)->addr[5] == (pSrcMac)->addr[5]) 66 #define MAC_BROADCAST(pMac) \ 67 ((pMac)->addr[0] == 0xFF && \ 68 (pMac)->addr[1] == 0xFF && \ 69 (pMac)->addr[2] == 0xFF && \ 70 (pMac)->addr[3] == 0xFF && \ 71 (pMac)->addr[4] == 0xFF && \ 72 (pMac)->addr[5] == 0xFF) 73 #define MAC_MULTICAST(pMac) ((pMac)->addr[0] & 0x01) 74 #define MAC_NULL(pMac) \ 75 ((pMac)->addr[0] == 0x00 && \ 76 (pMac)->addr[1] == 0x00 && \ 77 (pMac)->addr[2] == 0x00 && \ 78 (pMac)->addr[3] == 0x00 && \ 79 (pMac)->addr[4] == 0x00 && \ 80 (pMac)->addr[5] == 0x00) 81 82 83 #ifndef offsetof 84 #define offsetof(type, field) ((unsigned int) (&(((type *)(0))->field))) 85 #endif 86 87 88 /* NOTE - Network byte order is BIG endian. */ 89 90 static __inline unsigned short int __byte_swap_16 (unsigned short int __bsx) { 91 return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); 92 } 93 94 static __inline unsigned int __byte_swap_32 (unsigned int __bsx) { 95 return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | 96 (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); 97 } 98 99 100 #ifdef __BYTE_ORDER_BIG_ENDIAN 101 102 103 #define wlan_ntohl(x) (x) 104 #define wlan_ntohs(x) (x) 105 #define wlan_htonl(x) (x) 106 #define wlan_htons(x) (x) 107 108 #define ENDIAN_HANDLE_WORD(x) __byte_swap_16 (x) 109 #define ENDIAN_HANDLE_LONG(x) __byte_swap_32 (x) 110 111 /* int64 handling macros */ 112 #define INT64_LOWER(x) *(((UINT32*)&(x))+1) 113 #define INT64_HIGHER(x) *((UINT32*)&(x)) 114 115 #else 116 117 #ifdef __BYTE_ORDER_LITTLE_ENDIAN 118 119 #define wlan_ntohl(x) __byte_swap_32 (x) 120 #define wlan_ntohs(x) __byte_swap_16 (x) 121 #define wlan_htonl(x) __byte_swap_32 (x) 122 #define wlan_htons(x) __byte_swap_16 (x) 123 124 #define ENDIAN_HANDLE_WORD(x) (x) 125 #define ENDIAN_HANDLE_LONG(x) (x) 126 127 /* int64 handling macros */ 128 #define INT64_HIGHER(x) *(((UINT32*)&(x))+1) 129 #define INT64_LOWER(x) *((UINT32*)&(x)) 130 131 /*#define COPY_UNALIGNED_WORD(srcWord, destWord) ((UINT8 *)&destWord)[0] = ((UINT8 *)&srcWord)[0]; ((UINT8 *)&destWord)[1] = ((UINT8 *)&srcWord)[1]; 132 #define COPY_UNALIGNED_LONG(srcLong, destLong) ((UINT8 *)&destWord)[0] = ((UINT8 *)&srcWord)[0]; ((UINT8 *)&destWord)[1] = ((UINT8 *)&srcWord)[1];((UINT8 *)&destWord)[2] = ((UINT8 *)&srcWord)[2]; ((UINT8 *)&destWord)[3] = ((UINT8 *)&srcWord)[3]; 133 */ 134 #else 135 136 #error "MUST define byte order (BIG/LITTLE ENDIAN)" 137 138 #endif 139 #endif 140 141 #define COPY_UNALIGNED_WORD(pDest, pSrc) {((UINT8 *)(pDest))[0] = ((UINT8 *)(pSrc))[0];\ 142 ((UINT8 *)(pDest))[1] = ((UINT8 *)(pSrc))[1];} 143 144 #define COPY_UNALIGNED_LONG(pDest, pSrc) {((UINT8 *)(pDest))[0] = ((UINT8 *)(pSrc))[0];\ 145 ((UINT8 *)(pDest))[1] = ((UINT8 *)(pSrc))[1];\ 146 ((UINT8 *)(pDest))[2] = ((UINT8 *)(pSrc))[2];\ 147 ((UINT8 *)(pDest))[3] = ((UINT8 *)(pSrc))[3];} 148 149 void utils_nullMemoryFree(void* pOsContext, 150 void* pMemPtr, 151 unsigned long size); 152 153 void utils_nullTimerDestroy(void* pOsContext, 154 void* pTimerHandle); 155 156 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 157 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 158 159 #ifndef min 160 # define min MIN 161 #endif 162 163 #ifndef max 164 # define max MAX 165 #endif 166 167 168 #define MAKE_BASIC_RATE(rate) rate |= 0x80 169 170 #define IS_BASIC_RATE(rate) rate & 0x80 171 172 #define IS_ACTIVE_RATE(rate) !(rate & 0x80) 173 174 rate_e networkToHostRate(UINT8 rate); 175 176 UINT8 hostToNetworkRate(rate_e rate); 177 178 179 UINT8 getMaxBasicRatefromString(UINT8 *ratesString, UINT8 len, UINT8 maxRate); 180 181 rate_e getMaxRatefromBitmap(UINT32 ratesBitMap); 182 183 UINT8 getMaxActiveRatefromString(UINT8 *ratesString, UINT8 len, UINT8 maxRate); 184 185 TI_STATUS validateNetworkRate(UINT8 rate); 186 187 UINT8 hostToUtilityRate(rate_e rate); 188 189 rate_e utilityToHostRate(UINT8 rate); 190 191 UINT8 hostRateToNumber(rate_e rate); 192 rate_e RateNumberToHost(UINT8 rateIn); 193 194 void bitMapToNetworkStringRates(UINT32 suppRatesBitMap, UINT32 basicRatesBitMap, 195 UINT8 *string, UINT32 *len, 196 UINT32 *firstOFDMrateLoc); 197 198 void networkStringToBitMapSuppRates(UINT32 *bitMap, UINT8 *string, UINT32 len); 199 void networkStringToBitMapBasicRates(UINT32 *bitMap, UINT8 *string, UINT32 len); 200 201 UINT32 translateBasicRateValueToMask(UINT32 value, BOOL dot11a); 202 UINT32 translateSupportedRateValueToMask(UINT32 value, BOOL dot11a); 203 void validateRates(UINT32 *pBasicRateMask, UINT32 *pSuppRateMask, UINT32 *pTxRate, modulationType_e *modulation, BOOL dot11a); 204 rate_e calculateMaxSupportedRate(UINT32 *pSuppRateMask); 205 rate_e findMaxActiveRate(UINT32 ratesBitMap); 206 void validateRatesVsBand(UINT32 *supportedMask, UINT32 *basicMask, BOOL dot11a); 207 208 BOOL utils_isAnySSID(ssid_t *pSsid); 209 BOOL utils_isJunkSSID(ssid_t *pSsid); 210 BOOL utils_isIESSID_Broadcast(dot11_SSID_t *pIESsid); /* routinte to check for Junk SSID in SSID IE */ 211 void MsduContentDump (mem_MSDU_T* pMsdu, char *str); 212 213 214 void HexDumpData (UINT8 *data, int datalen); 215 void msduContentDump (mem_MSDU_T* pMsdu, char *str); 216 217 218 BOOL parseIeBuffer(TI_HANDLE hOs, UINT8 *pIeBuffer, UINT16 length, UINT8 desiredIeId, UINT8 **pDesiredIe, UINT8 *pMatchBuffer, UINT8 matchBufferLen); 219 void TiWlanIntToStr(UINT8 number , char *string, UINT8 radix); 220 221 UINT32 getBasicRateMaskForSpecialBGchannel(void); 222 UINT32 getSupportedRateMaskForSpecialBGchannel(void); 223 224 int ConvertHwBitRateToAppRate(UINT32 HwRate,rate_e *AppRate); 225 226 227 void getMaxRate(UINT32 ratesBitMap, rate_e *rate, modulationType_e *modulation, dot11mode_e operationMode); 228 void getMinRate(UINT32 ratesBitMap, rate_e *rate, modulationType_e *modulation, dot11mode_e operationMode); 229 230 UINT32 reminder64( UINT64 dividee, UINT32 divider ); 231 int ConvertHwBitRateToAppRate(UINT32 HwRate,rate_e *AppRate); 232 int ConvertAppRatesToBitmap(UINT16 AppRatesBitmap, UINT32 *HwRatesBitmap); 233 int ConvertAppRateToHwBitMapRate(UINT32 AppRate, UINT32 *HwRate); 234 void convert_hex_to_string(tiUINT8 *pBuffer, char *pString, tiUINT8 Size); 235 rate_e ConvertHwRateToDrvRate(UINT8 HwRate, BOOL bOFDMMudulation); 236 UINT8 ConvertDrvRate2HwRate(rate_e eRate); 237 RateIndex_e rateNumberToIndex(UINT8 uRate); 238 239 /* returns TI_STATUS as string */ 240 char* convertTI_STATUS_toString(TI_STATUS status); 241 242 /* 243 ++++++++ Profiling code ++++++++ 244 */ 245 #define UTIL_DEBUG_PROFILE (0) 246 247 void convert_hex_to_string(tiUINT8 *pBuffer, char *pString, tiUINT8 Size); 248 249 /* 250 * Small macro to convert Dbm units into Dbm/10 units. This macro is important 251 * in order to avoid over-flow of Dbm units bigger than 25 252 */ 253 #define DBM2DBMDIV10(uTxPower) \ 254 ((uTxPower) > (MAX_TX_POWER / DBM_TO_TX_POWER_FACTOR) ? \ 255 MAX_TX_POWER : (uTxPower) * DBM_TO_TX_POWER_FACTOR) 256 257 #if UTIL_DEBUG_PROFILE 258 typedef struct 259 { 260 UINT32 TIWlanModuleLogName; 261 UINT32 Event; 262 UINT32 Param_1; 263 UINT32 Param_2; 264 UINT32 timeStamp; 265 } profileInfoElement_t; 266 267 enum 268 { 269 PROFILE_BUFFER_SIZE = 10000 270 }; 271 272 typedef struct 273 { 274 profileInfoElement_t profileInfoElement[PROFILE_BUFFER_SIZE]; 275 UINT32 currentInfoElement; 276 BOOL overlap; 277 } profileInfo_t; 278 279 void util_initProfile(void); 280 281 void util_recordProfile(UINT32 theTIWlanModuleLogName, 282 UINT32 theEvent, 283 UINT32 theParam_1, 284 UINT32 theParam_2); 285 286 void util_printProfile(void); 287 #endif /* UTIL_DEBUG_PROFILE */ 288 289 290 #endif /* __UTILS_H__ */ 291