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