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 | * @file wlan_hdd_wowl.c |
| 44 | * |
| 45 | * Copyright (c) 2009 QUALCOMM Incorporated. |
| 46 | * All Rights Reserved. |
| 47 | * Qualcomm Confidential and Proprietary |
| 48 | * |
| 49 | * ==========================================================================*/ |
| 50 | |
| 51 | /*---------------------------------------------------------------------------- |
| 52 | * Include Files |
| 53 | * -------------------------------------------------------------------------*/ |
| 54 | |
| 55 | #include <wlan_hdd_includes.h> |
| 56 | #include <wlan_hdd_wowl.h> |
| 57 | |
| 58 | /*---------------------------------------------------------------------------- |
| 59 | * Preprocessor Definitions and Constants |
| 60 | * -------------------------------------------------------------------------*/ |
| 61 | |
| 62 | #define WOWL_PTRN_MAX_SIZE 128 |
| 63 | #define WOWL_PTRN_MASK_MAX_SIZE 16 |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame^] | 64 | #define WOWL_MAX_PTRNS_ALLOWED 16 |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 65 | #define WOWL_INTER_PTRN_TOKENIZER ';' |
| 66 | #define WOWL_INTRA_PTRN_TOKENIZER ':' |
| 67 | |
| 68 | /*---------------------------------------------------------------------------- |
| 69 | * Type Declarations |
| 70 | * -------------------------------------------------------------------------*/ |
| 71 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame^] | 72 | static char *g_hdd_wowl_ptrns[WOWL_MAX_PTRNS_ALLOWED]; //Patterns 0-15 |
| 73 | static v_BOOL_t g_hdd_wowl_ptrns_debugfs[WOWL_MAX_PTRNS_ALLOWED] = {0}; |
| 74 | static v_U8_t g_hdd_wowl_ptrns_count = 0; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 75 | |
Srinivas Girigowda | 100eb32 | 2013-03-15 16:48:20 -0700 | [diff] [blame] | 76 | int hdd_parse_hex(unsigned char c) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 77 | { |
| 78 | if (c >= '0' && c <= '9') |
| 79 | return c-'0'; |
| 80 | if (c >= 'a' && c <= 'f') |
| 81 | return c-'a'+10; |
| 82 | if (c >= 'A' && c <= 'F') |
| 83 | return c-'A'+10; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static inline int find_ptrn_len(const char* ptrn) |
| 89 | { |
| 90 | int len = 0; |
| 91 | while (*ptrn != '\0' && *ptrn != WOWL_INTER_PTRN_TOKENIZER) |
| 92 | { |
| 93 | len++; ptrn++; |
| 94 | } |
| 95 | return len; |
| 96 | } |
| 97 | |
| 98 | static void hdd_wowl_callback( void *pContext, eHalStatus halStatus ) |
| 99 | { |
Kumar Anand | aca924e | 2013-07-22 14:35:34 -0700 | [diff] [blame] | 100 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, |
| 101 | "%s: Return code = (%ld)\n", __func__, halStatus ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Kumar Anand | aca924e | 2013-07-22 14:35:34 -0700 | [diff] [blame] | 104 | #ifdef WLAN_WAKEUP_EVENTS |
| 105 | static void hdd_wowl_wakeIndication_callback( void *pContext, |
| 106 | tpSirWakeReasonInd pWakeReasonInd ) |
| 107 | { |
| 108 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Wake Reason %d", |
| 109 | __func__, pWakeReasonInd->ulReason ); |
| 110 | hdd_exit_wowl((hdd_adapter_t *)pContext); |
| 111 | } |
| 112 | #endif |
| 113 | |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 114 | static void dump_hdd_wowl_ptrn(tSirWowlAddBcastPtrn *ptrn) |
| 115 | { |
| 116 | int i; |
| 117 | |
| 118 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatetrnId = 0x%x", __func__, |
| 119 | ptrn->ucPatternId); |
| 120 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatternByteOffset = 0x%x", __func__, |
| 121 | ptrn->ucPatternByteOffset); |
| 122 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatternSize = 0x%x", __func__, |
| 123 | ptrn->ucPatternSize); |
| 124 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatternMaskSize = 0x%x", __func__, |
| 125 | ptrn->ucPatternMaskSize); |
| 126 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Pattern: ", __func__); |
| 127 | for(i = 0; i<ptrn->ucPatternSize; i++) |
| 128 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO," %02X", ptrn->ucPattern[i]); |
| 129 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: PatternMask: ", __func__); |
| 130 | for(i = 0; i<ptrn->ucPatternMaskSize; i++) |
| 131 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%02X", ptrn->ucPatternMask[i]); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | /**============================================================================ |
| 136 | @brief hdd_add_wowl_ptrn() - Function which will add the WoWL pattern to be |
| 137 | used when PBM filtering is enabled |
| 138 | |
| 139 | @param ptrn : [in] pointer to the pattern string to be added |
| 140 | |
| 141 | @return : FALSE if any errors encountered |
| 142 | : TRUE otherwise |
| 143 | ===========================================================================*/ |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 144 | v_BOOL_t hdd_add_wowl_ptrn (hdd_adapter_t *pAdapter, const char * ptrn) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 145 | { |
| 146 | tSirWowlAddBcastPtrn localPattern; |
| 147 | int i, first_empty_slot, len, offset; |
| 148 | eHalStatus halStatus; |
| 149 | const char *temp; |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 150 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 151 | v_U8_t sessionId = pAdapter->sessionId; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 152 | |
| 153 | len = find_ptrn_len(ptrn); |
| 154 | |
| 155 | /* There has to have atleast 1 byte for each field (pattern size, mask size, |
| 156 | * pattern, mask) e.g. PP:QQ:RR:SS ==> 11 chars */ |
| 157 | while ( len >= 11 ) |
| 158 | { |
| 159 | first_empty_slot = -1; |
| 160 | |
| 161 | // Find an empty slot to store the pattern |
| 162 | for (i=0; i<WOWL_MAX_PTRNS_ALLOWED; i++) |
| 163 | { |
| 164 | if(g_hdd_wowl_ptrns[i] == NULL) { |
| 165 | first_empty_slot = i; |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Maximum number of patterns have been configured already |
| 171 | if(first_empty_slot == -1) |
| 172 | { |
| 173 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 174 | "%s: Cannot add anymore patterns. No free slot!", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 175 | return VOS_FALSE; |
| 176 | } |
| 177 | |
| 178 | // Detect duplicate pattern |
| 179 | for (i=0; i<WOWL_MAX_PTRNS_ALLOWED; i++) |
| 180 | { |
| 181 | if(g_hdd_wowl_ptrns[i] == NULL) continue; |
| 182 | |
| 183 | if(!memcmp(ptrn, g_hdd_wowl_ptrns[i], len)) |
| 184 | { |
| 185 | // Pattern Already configured, skip to next pattern |
| 186 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 187 | "Trying to add duplicate WoWL pattern. Skip it!"); |
| 188 | ptrn += len; |
| 189 | goto next_ptrn; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | //Validate the pattern |
| 194 | if(ptrn[2] != WOWL_INTRA_PTRN_TOKENIZER || |
| 195 | ptrn[5] != WOWL_INTRA_PTRN_TOKENIZER) |
| 196 | { |
| 197 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 198 | "%s: Malformed pattern string. Skip!\n", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 199 | ptrn += len; |
| 200 | goto next_ptrn; |
| 201 | } |
| 202 | |
| 203 | // Extract the pattern size |
| 204 | localPattern.ucPatternSize = |
Srinivas Girigowda | 100eb32 | 2013-03-15 16:48:20 -0700 | [diff] [blame] | 205 | ( hdd_parse_hex( ptrn[0] ) * 0x10 ) + hdd_parse_hex( ptrn[1] ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 206 | |
| 207 | // Extract the pattern mask size |
| 208 | localPattern.ucPatternMaskSize = |
Srinivas Girigowda | 100eb32 | 2013-03-15 16:48:20 -0700 | [diff] [blame] | 209 | ( hdd_parse_hex( ptrn[3] ) * 0x10 ) + hdd_parse_hex( ptrn[4] ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 210 | |
| 211 | if(localPattern.ucPatternSize > WOWL_PTRN_MAX_SIZE || |
| 212 | localPattern.ucPatternMaskSize > WOWL_PTRN_MASK_MAX_SIZE) |
| 213 | { |
| 214 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 215 | "%s: Invalid length specified. Skip!\n", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 216 | ptrn += len; |
| 217 | goto next_ptrn; |
| 218 | } |
| 219 | |
| 220 | //compute the offset of tokenizer after the pattern |
| 221 | offset = 5 + 2*localPattern.ucPatternSize + 1; |
| 222 | if(offset >= len || ptrn[offset] != WOWL_INTRA_PTRN_TOKENIZER) |
| 223 | { |
| 224 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 225 | "%s: Malformed pattern string..skip!\n", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 226 | ptrn += len; |
| 227 | goto next_ptrn; |
| 228 | } |
| 229 | |
| 230 | //compute the end of pattern sring |
| 231 | offset = offset + 2*localPattern.ucPatternMaskSize; |
| 232 | if(offset+1 != len) //offset begins with 0 |
| 233 | { |
| 234 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 235 | "%s: Malformed pattern string...skip!\n", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 236 | ptrn += len; |
| 237 | goto next_ptrn; |
| 238 | } |
| 239 | |
| 240 | temp = ptrn; |
| 241 | |
| 242 | // Now advance to where pattern begins |
| 243 | ptrn += 6; |
| 244 | |
| 245 | // Extract the pattern |
| 246 | for(i=0; i < localPattern.ucPatternSize; i++) |
| 247 | { |
| 248 | localPattern.ucPattern[i] = |
Srinivas Girigowda | 100eb32 | 2013-03-15 16:48:20 -0700 | [diff] [blame] | 249 | (hdd_parse_hex( ptrn[0] ) * 0x10 ) + hdd_parse_hex( ptrn[1] ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 250 | ptrn += 2; //skip to next byte |
| 251 | } |
| 252 | |
| 253 | ptrn++; // Skip over the ':' seperator after the pattern |
| 254 | |
| 255 | // Extract the pattern Mask |
| 256 | for(i=0; i < localPattern.ucPatternMaskSize; i++) |
| 257 | { |
| 258 | localPattern.ucPatternMask[i] = |
Srinivas Girigowda | 100eb32 | 2013-03-15 16:48:20 -0700 | [diff] [blame] | 259 | (hdd_parse_hex( ptrn[0] ) * 0x10 ) + hdd_parse_hex( ptrn[1] ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 260 | ptrn += 2; //skip to next byte |
| 261 | } |
| 262 | |
| 263 | //All is good. Store the pattern locally |
| 264 | g_hdd_wowl_ptrns[first_empty_slot] = (char*) kmalloc(len+1, GFP_KERNEL); |
| 265 | if(g_hdd_wowl_ptrns[first_empty_slot] == NULL) |
| 266 | { |
| 267 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Madan Mohan Koyyalamudi | 87054ba | 2012-11-02 13:24:12 -0700 | [diff] [blame] | 268 | "%s: kmalloc failure", __func__); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 269 | return VOS_FALSE; |
| 270 | } |
| 271 | |
| 272 | memcpy(g_hdd_wowl_ptrns[first_empty_slot], temp, len); |
| 273 | g_hdd_wowl_ptrns[first_empty_slot][len] = '\0'; |
| 274 | localPattern.ucPatternId = first_empty_slot; |
| 275 | localPattern.ucPatternByteOffset = 0; |
| 276 | |
| 277 | // Register the pattern downstream |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 278 | halStatus = sme_WowlAddBcastPattern( hHal, &localPattern, sessionId ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 279 | if ( !HAL_STATUS_SUCCESS( halStatus ) ) |
| 280 | { |
| 281 | // Add failed, so invalidate the local storage |
| 282 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 283 | "sme_WowlAddBcastPattern failed with error code (%ld)", halStatus ); |
| 284 | kfree(g_hdd_wowl_ptrns[first_empty_slot]); |
| 285 | g_hdd_wowl_ptrns[first_empty_slot] = NULL; |
| 286 | } |
| 287 | |
| 288 | dump_hdd_wowl_ptrn(&localPattern); |
| 289 | |
| 290 | next_ptrn: |
| 291 | if (*ptrn == WOWL_INTER_PTRN_TOKENIZER) |
| 292 | { |
| 293 | ptrn += 1; // move past the tokenizer |
| 294 | len = find_ptrn_len(ptrn); |
| 295 | continue; |
| 296 | } |
| 297 | else |
| 298 | break; |
| 299 | } |
| 300 | |
| 301 | return VOS_TRUE; |
| 302 | } |
| 303 | |
| 304 | /**============================================================================ |
| 305 | @brief hdd_del_wowl_ptrn() - Function which will remove a WoWL pattern |
| 306 | |
| 307 | @param ptrn : [in] pointer to the pattern string to be removed |
| 308 | |
| 309 | @return : FALSE if any errors encountered |
| 310 | : TRUE otherwise |
| 311 | ===========================================================================*/ |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 312 | v_BOOL_t hdd_del_wowl_ptrn (hdd_adapter_t *pAdapter, const char * ptrn) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 313 | { |
| 314 | tSirWowlDelBcastPtrn delPattern; |
| 315 | unsigned char id; |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 316 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 317 | v_BOOL_t patternFound = VOS_FALSE; |
| 318 | eHalStatus halStatus; |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 319 | v_U8_t sessionId = pAdapter->sessionId; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 320 | |
| 321 | // Detect pattern |
| 322 | for (id=0; id<WOWL_MAX_PTRNS_ALLOWED && g_hdd_wowl_ptrns[id] != NULL; id++) |
| 323 | { |
| 324 | if(!strcmp(ptrn, g_hdd_wowl_ptrns[id])) |
| 325 | { |
| 326 | patternFound = VOS_TRUE; |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // If pattern present, remove it from downstream |
| 332 | if(patternFound) |
| 333 | { |
| 334 | delPattern.ucPatternId = id; |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 335 | halStatus = sme_WowlDelBcastPattern( hHal, &delPattern, sessionId ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 336 | if ( HAL_STATUS_SUCCESS( halStatus ) ) |
| 337 | { |
| 338 | // Remove from local storage as well |
| 339 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 340 | "Deleted pattern with id %d [%s]", id, g_hdd_wowl_ptrns[id]); |
| 341 | |
| 342 | kfree(g_hdd_wowl_ptrns[id]); |
| 343 | g_hdd_wowl_ptrns[id] = NULL; |
| 344 | return VOS_TRUE; |
| 345 | } |
| 346 | } |
| 347 | return VOS_FALSE; |
| 348 | } |
| 349 | |
| 350 | /**============================================================================ |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame^] | 351 | @brief hdd_add_wowl_ptrn_debugfs() - Function which will add a WoW pattern |
| 352 | to be used when PBM filtering is enabled and MP filtering is disabled |
| 353 | |
| 354 | @param pAdapter : [in] pointer to the adapter |
| 355 | pattern_idx : [in] index of the pattern to be added |
| 356 | pattern_offset : [in] offset of the pattern in the frame payload |
| 357 | pattern_buf : [in] pointer to the pattern hex string to be added |
| 358 | |
| 359 | @return : FALSE if any errors encountered |
| 360 | : TRUE otherwise |
| 361 | ===========================================================================*/ |
| 362 | v_BOOL_t hdd_add_wowl_ptrn_debugfs(hdd_adapter_t *pAdapter, v_U8_t pattern_idx, |
| 363 | v_U8_t pattern_offset, char *pattern_buf) |
| 364 | { |
| 365 | tSirWowlAddBcastPtrn localPattern; |
| 366 | eHalStatus halStatus; |
| 367 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 368 | v_U8_t sessionId = pAdapter->sessionId; |
| 369 | v_U16_t pattern_len, i; |
| 370 | |
| 371 | if (pattern_idx > (WOWL_MAX_PTRNS_ALLOWED - 1)) |
| 372 | { |
| 373 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 374 | "%s: WoW pattern index %d is out of range (0 ~ %d).", |
| 375 | __func__, pattern_idx, WOWL_MAX_PTRNS_ALLOWED - 1); |
| 376 | |
| 377 | return VOS_FALSE; |
| 378 | } |
| 379 | |
| 380 | pattern_len = strlen(pattern_buf); |
| 381 | |
| 382 | /* Since the pattern is a hex string, 2 characters represent 1 byte. */ |
| 383 | if (pattern_len % 2) |
| 384 | { |
| 385 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 386 | "%s: Malformed WoW pattern!", __func__); |
| 387 | |
| 388 | return VOS_FALSE; |
| 389 | } |
| 390 | else |
| 391 | pattern_len >>= 1; |
| 392 | |
| 393 | if (!pattern_len || pattern_len > WOWL_PTRN_MAX_SIZE) |
| 394 | { |
| 395 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 396 | "%s: WoW pattern length %d is out of range (1 ~ %d).", |
| 397 | __func__, pattern_len, WOWL_PTRN_MAX_SIZE); |
| 398 | |
| 399 | return VOS_FALSE; |
| 400 | } |
| 401 | |
| 402 | localPattern.ucPatternId = pattern_idx; |
| 403 | localPattern.ucPatternByteOffset = pattern_offset; |
| 404 | localPattern.ucPatternSize = pattern_len; |
| 405 | |
| 406 | /* Extract the pattern */ |
| 407 | for (i = 0; i < localPattern.ucPatternSize; i++) |
| 408 | { |
| 409 | localPattern.ucPattern[i] = |
| 410 | (hdd_parse_hex(pattern_buf[0]) << 4) + hdd_parse_hex(pattern_buf[1]); |
| 411 | |
| 412 | /* Skip to next byte */ |
| 413 | pattern_buf += 2; |
| 414 | } |
| 415 | |
| 416 | /* Generate bytemask by pattern length */ |
| 417 | for (i = 0; i < (pattern_len >> 3); i++) |
| 418 | localPattern.ucPatternMask[i] = 0xFF; |
| 419 | |
| 420 | localPattern.ucPatternMaskSize = i; |
| 421 | |
| 422 | if (pattern_len % 8) |
| 423 | { |
| 424 | localPattern.ucPatternMask[i] = (1 << (pattern_len % 8)) - 1; |
| 425 | localPattern.ucPatternMaskSize += 1; |
| 426 | } |
| 427 | |
| 428 | /* Register the pattern downstream */ |
| 429 | halStatus = sme_WowlAddBcastPattern(hHal, &localPattern, sessionId); |
| 430 | |
| 431 | if (!HAL_STATUS_SUCCESS(halStatus)) |
| 432 | { |
| 433 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 434 | "%s: sme_WowlAddBcastPattern failed with error code (%ld).", |
| 435 | __func__, halStatus); |
| 436 | |
| 437 | return VOS_FALSE; |
| 438 | } |
| 439 | |
| 440 | /* Enable WoW immediately after add a pattern. By default, |
| 441 | * disable magic packet mode and enable pattern byte matching mode. */ |
| 442 | if (!hdd_enter_wowl(pAdapter, 0, 1)) |
| 443 | { |
| 444 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 445 | "%s: hdd_enter_wowl failed!", __func__); |
| 446 | |
| 447 | return VOS_FALSE; |
| 448 | } |
| 449 | |
| 450 | /* All is good. */ |
| 451 | if (!g_hdd_wowl_ptrns_debugfs[pattern_idx]) |
| 452 | { |
| 453 | g_hdd_wowl_ptrns_debugfs[pattern_idx] = 1; |
| 454 | g_hdd_wowl_ptrns_count++; |
| 455 | } |
| 456 | |
| 457 | dump_hdd_wowl_ptrn(&localPattern); |
| 458 | |
| 459 | return VOS_TRUE; |
| 460 | } |
| 461 | |
| 462 | /**============================================================================ |
| 463 | @brief hdd_del_wowl_ptrn_debugfs() - Function which will remove a WoW pattern |
| 464 | |
| 465 | @param pAdapter : [in] pointer to the adapter |
| 466 | pattern_idx : [in] index of the pattern to be removed |
| 467 | |
| 468 | @return : FALSE if any errors encountered |
| 469 | : TRUE otherwise |
| 470 | ===========================================================================*/ |
| 471 | v_BOOL_t hdd_del_wowl_ptrn_debugfs(hdd_adapter_t *pAdapter, v_U8_t pattern_idx) |
| 472 | { |
| 473 | tSirWowlDelBcastPtrn delPattern; |
| 474 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
| 475 | eHalStatus halStatus; |
| 476 | v_U8_t sessionId = pAdapter->sessionId; |
| 477 | |
| 478 | if (pattern_idx > (WOWL_MAX_PTRNS_ALLOWED - 1)) |
| 479 | { |
| 480 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 481 | "%s: WoW pattern index %d is not in the range (0 ~ %d).", |
| 482 | __func__, pattern_idx, WOWL_MAX_PTRNS_ALLOWED - 1); |
| 483 | |
| 484 | return VOS_FALSE; |
| 485 | } |
| 486 | |
| 487 | if (!g_hdd_wowl_ptrns_debugfs[pattern_idx]) |
| 488 | { |
| 489 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 490 | "%s: WoW pattern %d is not in the table.", |
| 491 | __func__, pattern_idx); |
| 492 | |
| 493 | return VOS_FALSE; |
| 494 | } |
| 495 | |
| 496 | delPattern.ucPatternId = pattern_idx; |
| 497 | halStatus = sme_WowlDelBcastPattern(hHal, &delPattern, sessionId); |
| 498 | |
| 499 | if (!HAL_STATUS_SUCCESS(halStatus)) |
| 500 | { |
| 501 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 502 | "%s: sme_WowlDelBcastPattern failed with error code (%ld).", |
| 503 | __func__, halStatus); |
| 504 | |
| 505 | return VOS_FALSE; |
| 506 | } |
| 507 | |
| 508 | g_hdd_wowl_ptrns_debugfs[pattern_idx] = 0; |
| 509 | g_hdd_wowl_ptrns_count--; |
| 510 | |
| 511 | if (g_hdd_wowl_ptrns_count == 0) |
| 512 | { |
| 513 | if (!hdd_exit_wowl(pAdapter)) |
| 514 | { |
| 515 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 516 | "%s: hdd_exit_wowl failed!", __func__); |
| 517 | |
| 518 | return VOS_FALSE; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | return VOS_TRUE; |
| 523 | } |
| 524 | |
| 525 | /**============================================================================ |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 526 | @brief hdd_enter_wowl() - Function which will enable WoWL. Atleast one |
| 527 | of MP and PBM must be enabled |
| 528 | |
| 529 | @param enable_mp : [in] Whether to enable magic packet WoWL mode |
| 530 | @param enable_pbm : [in] Whether to enable pattern byte matching WoWL mode |
| 531 | |
| 532 | @return : FALSE if any errors encountered |
| 533 | : TRUE otherwise |
| 534 | ===========================================================================*/ |
| 535 | v_BOOL_t hdd_enter_wowl (hdd_adapter_t *pAdapter, v_BOOL_t enable_mp, v_BOOL_t enable_pbm) |
| 536 | { |
| 537 | tSirSmeWowlEnterParams wowParams; |
| 538 | eHalStatus halStatus; |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 539 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 540 | |
| 541 | wowParams.ucPatternFilteringEnable = enable_pbm; |
| 542 | wowParams.ucMagicPktEnable = enable_mp; |
| 543 | if(enable_mp) |
| 544 | { |
| 545 | vos_copy_macaddr( (v_MACADDR_t *)&(wowParams.magicPtrn), |
| 546 | &(pAdapter->macAddressCurrent) ); |
| 547 | } |
| 548 | |
| 549 | // Request to put Libra into WoWL |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 550 | halStatus = sme_EnterWowl( hHal, hdd_wowl_callback, |
Kumar Anand | aca924e | 2013-07-22 14:35:34 -0700 | [diff] [blame] | 551 | pAdapter, |
| 552 | #ifdef WLAN_WAKEUP_EVENTS |
| 553 | hdd_wowl_wakeIndication_callback, |
| 554 | pAdapter, |
| 555 | #endif // WLAN_WAKEUP_EVENTS |
| 556 | &wowParams, pAdapter->sessionId); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 557 | |
| 558 | if ( !HAL_STATUS_SUCCESS( halStatus ) ) |
| 559 | { |
| 560 | if ( eHAL_STATUS_PMC_PENDING != halStatus ) |
| 561 | { |
| 562 | // We failed to enter WoWL |
| 563 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 564 | "sme_EnterWowl failed with error code (%ld)", halStatus ); |
| 565 | return VOS_FALSE; |
| 566 | } |
| 567 | } |
| 568 | return VOS_TRUE; |
| 569 | } |
| 570 | |
| 571 | /**============================================================================ |
| 572 | @brief hdd_exit_wowl() - Function which will disable WoWL |
| 573 | |
| 574 | @return : FALSE if any errors encountered |
| 575 | : TRUE otherwise |
| 576 | ===========================================================================*/ |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 577 | v_BOOL_t hdd_exit_wowl (hdd_adapter_t*pAdapter) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 578 | { |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 579 | tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 580 | eHalStatus halStatus; |
| 581 | |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 582 | halStatus = sme_ExitWowl( hHal ); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 583 | if ( !HAL_STATUS_SUCCESS( halStatus ) ) |
| 584 | { |
| 585 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 586 | "sme_ExitWowl failed with error code (%ld)", halStatus ); |
| 587 | return VOS_FALSE; |
| 588 | } |
| 589 | |
| 590 | return VOS_TRUE; |
| 591 | } |
| 592 | |
| 593 | /**============================================================================ |
| 594 | @brief hdd_init_wowl() - Init function which will initialize the WoWL module |
| 595 | and perform any required intial configuration |
| 596 | |
| 597 | @return : FALSE if any errors encountered |
| 598 | : TRUE otherwise |
| 599 | ===========================================================================*/ |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 600 | v_BOOL_t hdd_init_wowl (hdd_adapter_t*pAdapter) |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 601 | { |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 602 | hdd_context_t *pHddCtx = NULL; |
| 603 | pHddCtx = pAdapter->pHddCtx; |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 604 | |
| 605 | memset(g_hdd_wowl_ptrns, 0, sizeof(g_hdd_wowl_ptrns)); |
| 606 | |
| 607 | //Add any statically configured patterns |
Madan Mohan Koyyalamudi | 96dd30d | 2012-10-05 17:24:51 -0700 | [diff] [blame] | 608 | hdd_add_wowl_ptrn(pAdapter, pHddCtx->cfg_ini->wowlPattern); |
Jeff Johnson | 295189b | 2012-06-20 16:38:30 -0700 | [diff] [blame] | 609 | |
| 610 | return VOS_TRUE; |
| 611 | } |