blob: e783033a3c6d9c9ae61f62c3c4e0df240d98851c [file] [log] [blame]
Jeff Johnson295189b2012-06-20 16:38:30 -07001/*
Gopichand Nakkala92f07d82013-01-08 21:16:34 -08002 * 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 Johnson32d95a32012-09-10 13:15:23 -070022 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Jeff Johnson295189b2012-06-20 16:38:30 -070023 *
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
64#define WOWL_MAX_PTRNS_ALLOWED 8
65#define WOWL_INTER_PTRN_TOKENIZER ';'
66#define WOWL_INTRA_PTRN_TOKENIZER ':'
67
68/*----------------------------------------------------------------------------
69 * Type Declarations
70 * -------------------------------------------------------------------------*/
71
Jeff Johnson295189b2012-06-20 16:38:30 -070072char *g_hdd_wowl_ptrns[WOWL_MAX_PTRNS_ALLOWED]; //Patterns 0-7
73
Srinivas Girigowda100eb322013-03-15 16:48:20 -070074int hdd_parse_hex(unsigned char c)
Jeff Johnson295189b2012-06-20 16:38:30 -070075{
76 if (c >= '0' && c <= '9')
77 return c-'0';
78 if (c >= 'a' && c <= 'f')
79 return c-'a'+10;
80 if (c >= 'A' && c <= 'F')
81 return c-'A'+10;
82
83 return 0;
84}
85
86static inline int find_ptrn_len(const char* ptrn)
87{
88 int len = 0;
89 while (*ptrn != '\0' && *ptrn != WOWL_INTER_PTRN_TOKENIZER)
90 {
91 len++; ptrn++;
92 }
93 return len;
94}
95
96static void hdd_wowl_callback( void *pContext, eHalStatus halStatus )
97{
98 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -070099 "%s: Return code = (%ld)\n", __func__, halStatus );
Jeff Johnson295189b2012-06-20 16:38:30 -0700100}
101
102static void dump_hdd_wowl_ptrn(tSirWowlAddBcastPtrn *ptrn)
103{
104 int i;
105
106 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatetrnId = 0x%x", __func__,
107 ptrn->ucPatternId);
108 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatternByteOffset = 0x%x", __func__,
109 ptrn->ucPatternByteOffset);
110 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatternSize = 0x%x", __func__,
111 ptrn->ucPatternSize);
112 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: ucPatternMaskSize = 0x%x", __func__,
113 ptrn->ucPatternMaskSize);
114 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: Pattern: ", __func__);
115 for(i = 0; i<ptrn->ucPatternSize; i++)
116 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO," %02X", ptrn->ucPattern[i]);
117 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO, "%s: PatternMask: ", __func__);
118 for(i = 0; i<ptrn->ucPatternMaskSize; i++)
119 VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO,"%02X", ptrn->ucPatternMask[i]);
120}
121
122
123/**============================================================================
124 @brief hdd_add_wowl_ptrn() - Function which will add the WoWL pattern to be
125 used when PBM filtering is enabled
126
127 @param ptrn : [in] pointer to the pattern string to be added
128
129 @return : FALSE if any errors encountered
130 : TRUE otherwise
131 ===========================================================================*/
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700132v_BOOL_t hdd_add_wowl_ptrn (hdd_adapter_t *pAdapter, const char * ptrn)
Jeff Johnson295189b2012-06-20 16:38:30 -0700133{
134 tSirWowlAddBcastPtrn localPattern;
135 int i, first_empty_slot, len, offset;
136 eHalStatus halStatus;
137 const char *temp;
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700138 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
139 v_U8_t sessionId = pAdapter->sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -0700140
141 len = find_ptrn_len(ptrn);
142
143 /* There has to have atleast 1 byte for each field (pattern size, mask size,
144 * pattern, mask) e.g. PP:QQ:RR:SS ==> 11 chars */
145 while ( len >= 11 )
146 {
147 first_empty_slot = -1;
148
149 // Find an empty slot to store the pattern
150 for (i=0; i<WOWL_MAX_PTRNS_ALLOWED; i++)
151 {
152 if(g_hdd_wowl_ptrns[i] == NULL) {
153 first_empty_slot = i;
154 break;
155 }
156 }
157
158 // Maximum number of patterns have been configured already
159 if(first_empty_slot == -1)
160 {
161 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700162 "%s: Cannot add anymore patterns. No free slot!", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700163 return VOS_FALSE;
164 }
165
166 // Detect duplicate pattern
167 for (i=0; i<WOWL_MAX_PTRNS_ALLOWED; i++)
168 {
169 if(g_hdd_wowl_ptrns[i] == NULL) continue;
170
171 if(!memcmp(ptrn, g_hdd_wowl_ptrns[i], len))
172 {
173 // Pattern Already configured, skip to next pattern
174 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
175 "Trying to add duplicate WoWL pattern. Skip it!");
176 ptrn += len;
177 goto next_ptrn;
178 }
179 }
180
181 //Validate the pattern
182 if(ptrn[2] != WOWL_INTRA_PTRN_TOKENIZER ||
183 ptrn[5] != WOWL_INTRA_PTRN_TOKENIZER)
184 {
185 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700186 "%s: Malformed pattern string. Skip!\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700187 ptrn += len;
188 goto next_ptrn;
189 }
190
191 // Extract the pattern size
192 localPattern.ucPatternSize =
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700193 ( hdd_parse_hex( ptrn[0] ) * 0x10 ) + hdd_parse_hex( ptrn[1] );
Jeff Johnson295189b2012-06-20 16:38:30 -0700194
195 // Extract the pattern mask size
196 localPattern.ucPatternMaskSize =
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700197 ( hdd_parse_hex( ptrn[3] ) * 0x10 ) + hdd_parse_hex( ptrn[4] );
Jeff Johnson295189b2012-06-20 16:38:30 -0700198
199 if(localPattern.ucPatternSize > WOWL_PTRN_MAX_SIZE ||
200 localPattern.ucPatternMaskSize > WOWL_PTRN_MASK_MAX_SIZE)
201 {
202 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700203 "%s: Invalid length specified. Skip!\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700204 ptrn += len;
205 goto next_ptrn;
206 }
207
208 //compute the offset of tokenizer after the pattern
209 offset = 5 + 2*localPattern.ucPatternSize + 1;
210 if(offset >= len || ptrn[offset] != WOWL_INTRA_PTRN_TOKENIZER)
211 {
212 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700213 "%s: Malformed pattern string..skip!\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700214 ptrn += len;
215 goto next_ptrn;
216 }
217
218 //compute the end of pattern sring
219 offset = offset + 2*localPattern.ucPatternMaskSize;
220 if(offset+1 != len) //offset begins with 0
221 {
222 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700223 "%s: Malformed pattern string...skip!\n", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700224 ptrn += len;
225 goto next_ptrn;
226 }
227
228 temp = ptrn;
229
230 // Now advance to where pattern begins
231 ptrn += 6;
232
233 // Extract the pattern
234 for(i=0; i < localPattern.ucPatternSize; i++)
235 {
236 localPattern.ucPattern[i] =
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700237 (hdd_parse_hex( ptrn[0] ) * 0x10 ) + hdd_parse_hex( ptrn[1] );
Jeff Johnson295189b2012-06-20 16:38:30 -0700238 ptrn += 2; //skip to next byte
239 }
240
241 ptrn++; // Skip over the ':' seperator after the pattern
242
243 // Extract the pattern Mask
244 for(i=0; i < localPattern.ucPatternMaskSize; i++)
245 {
246 localPattern.ucPatternMask[i] =
Srinivas Girigowda100eb322013-03-15 16:48:20 -0700247 (hdd_parse_hex( ptrn[0] ) * 0x10 ) + hdd_parse_hex( ptrn[1] );
Jeff Johnson295189b2012-06-20 16:38:30 -0700248 ptrn += 2; //skip to next byte
249 }
250
251 //All is good. Store the pattern locally
252 g_hdd_wowl_ptrns[first_empty_slot] = (char*) kmalloc(len+1, GFP_KERNEL);
253 if(g_hdd_wowl_ptrns[first_empty_slot] == NULL)
254 {
255 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
Madan Mohan Koyyalamudi87054ba2012-11-02 13:24:12 -0700256 "%s: kmalloc failure", __func__);
Jeff Johnson295189b2012-06-20 16:38:30 -0700257 return VOS_FALSE;
258 }
259
260 memcpy(g_hdd_wowl_ptrns[first_empty_slot], temp, len);
261 g_hdd_wowl_ptrns[first_empty_slot][len] = '\0';
262 localPattern.ucPatternId = first_empty_slot;
263 localPattern.ucPatternByteOffset = 0;
264
265 // Register the pattern downstream
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700266 halStatus = sme_WowlAddBcastPattern( hHal, &localPattern, sessionId );
Jeff Johnson295189b2012-06-20 16:38:30 -0700267 if ( !HAL_STATUS_SUCCESS( halStatus ) )
268 {
269 // Add failed, so invalidate the local storage
270 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
271 "sme_WowlAddBcastPattern failed with error code (%ld)", halStatus );
272 kfree(g_hdd_wowl_ptrns[first_empty_slot]);
273 g_hdd_wowl_ptrns[first_empty_slot] = NULL;
274 }
275
276 dump_hdd_wowl_ptrn(&localPattern);
277
278 next_ptrn:
279 if (*ptrn == WOWL_INTER_PTRN_TOKENIZER)
280 {
281 ptrn += 1; // move past the tokenizer
282 len = find_ptrn_len(ptrn);
283 continue;
284 }
285 else
286 break;
287 }
288
289 return VOS_TRUE;
290}
291
292/**============================================================================
293 @brief hdd_del_wowl_ptrn() - Function which will remove a WoWL pattern
294
295 @param ptrn : [in] pointer to the pattern string to be removed
296
297 @return : FALSE if any errors encountered
298 : TRUE otherwise
299 ===========================================================================*/
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700300v_BOOL_t hdd_del_wowl_ptrn (hdd_adapter_t *pAdapter, const char * ptrn)
Jeff Johnson295189b2012-06-20 16:38:30 -0700301{
302 tSirWowlDelBcastPtrn delPattern;
303 unsigned char id;
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700304 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700305 v_BOOL_t patternFound = VOS_FALSE;
306 eHalStatus halStatus;
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700307 v_U8_t sessionId = pAdapter->sessionId;
Jeff Johnson295189b2012-06-20 16:38:30 -0700308
309 // Detect pattern
310 for (id=0; id<WOWL_MAX_PTRNS_ALLOWED && g_hdd_wowl_ptrns[id] != NULL; id++)
311 {
312 if(!strcmp(ptrn, g_hdd_wowl_ptrns[id]))
313 {
314 patternFound = VOS_TRUE;
315 break;
316 }
317 }
318
319 // If pattern present, remove it from downstream
320 if(patternFound)
321 {
322 delPattern.ucPatternId = id;
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700323 halStatus = sme_WowlDelBcastPattern( hHal, &delPattern, sessionId );
Jeff Johnson295189b2012-06-20 16:38:30 -0700324 if ( HAL_STATUS_SUCCESS( halStatus ) )
325 {
326 // Remove from local storage as well
327 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
328 "Deleted pattern with id %d [%s]", id, g_hdd_wowl_ptrns[id]);
329
330 kfree(g_hdd_wowl_ptrns[id]);
331 g_hdd_wowl_ptrns[id] = NULL;
332 return VOS_TRUE;
333 }
334 }
335 return VOS_FALSE;
336}
337
338/**============================================================================
339 @brief hdd_enter_wowl() - Function which will enable WoWL. Atleast one
340 of MP and PBM must be enabled
341
342 @param enable_mp : [in] Whether to enable magic packet WoWL mode
343 @param enable_pbm : [in] Whether to enable pattern byte matching WoWL mode
344
345 @return : FALSE if any errors encountered
346 : TRUE otherwise
347 ===========================================================================*/
348v_BOOL_t hdd_enter_wowl (hdd_adapter_t *pAdapter, v_BOOL_t enable_mp, v_BOOL_t enable_pbm)
349{
350 tSirSmeWowlEnterParams wowParams;
351 eHalStatus halStatus;
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700352 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700353
354 wowParams.ucPatternFilteringEnable = enable_pbm;
355 wowParams.ucMagicPktEnable = enable_mp;
356 if(enable_mp)
357 {
358 vos_copy_macaddr( (v_MACADDR_t *)&(wowParams.magicPtrn),
359 &(pAdapter->macAddressCurrent) );
360 }
361
362 // Request to put Libra into WoWL
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700363 halStatus = sme_EnterWowl( hHal, hdd_wowl_callback,
364 pAdapter, &wowParams, pAdapter->sessionId);
Jeff Johnson295189b2012-06-20 16:38:30 -0700365
366 if ( !HAL_STATUS_SUCCESS( halStatus ) )
367 {
368 if ( eHAL_STATUS_PMC_PENDING != halStatus )
369 {
370 // We failed to enter WoWL
371 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
372 "sme_EnterWowl failed with error code (%ld)", halStatus );
373 return VOS_FALSE;
374 }
375 }
376 return VOS_TRUE;
377}
378
379/**============================================================================
380 @brief hdd_exit_wowl() - Function which will disable WoWL
381
382 @return : FALSE if any errors encountered
383 : TRUE otherwise
384 ===========================================================================*/
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700385v_BOOL_t hdd_exit_wowl (hdd_adapter_t*pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700386{
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700387 tHalHandle hHal = WLAN_HDD_GET_HAL_CTX(pAdapter);
Jeff Johnson295189b2012-06-20 16:38:30 -0700388 eHalStatus halStatus;
389
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700390 halStatus = sme_ExitWowl( hHal );
Jeff Johnson295189b2012-06-20 16:38:30 -0700391 if ( !HAL_STATUS_SUCCESS( halStatus ) )
392 {
393 VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
394 "sme_ExitWowl failed with error code (%ld)", halStatus );
395 return VOS_FALSE;
396 }
397
398 return VOS_TRUE;
399}
400
401/**============================================================================
402 @brief hdd_init_wowl() - Init function which will initialize the WoWL module
403 and perform any required intial configuration
404
405 @return : FALSE if any errors encountered
406 : TRUE otherwise
407 ===========================================================================*/
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700408v_BOOL_t hdd_init_wowl (hdd_adapter_t*pAdapter)
Jeff Johnson295189b2012-06-20 16:38:30 -0700409{
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700410 hdd_context_t *pHddCtx = NULL;
411 pHddCtx = pAdapter->pHddCtx;
Jeff Johnson295189b2012-06-20 16:38:30 -0700412
413 memset(g_hdd_wowl_ptrns, 0, sizeof(g_hdd_wowl_ptrns));
414
415 //Add any statically configured patterns
Madan Mohan Koyyalamudi96dd30d2012-10-05 17:24:51 -0700416 hdd_add_wowl_ptrn(pAdapter, pHddCtx->cfg_ini->wowlPattern);
Jeff Johnson295189b2012-06-20 16:38:30 -0700417
418 return VOS_TRUE;
419}