staging: wilc1000: replace wilc error types with the generic error types
[deliverable/linux.git] / drivers / staging / wilc1000 / coreconfigurator.c
1
2 /*!
3 * @file coreconfigurator.c
4 * @brief
5 * @author
6 * @sa coreconfigurator.h
7 * @date 1 Mar 2012
8 * @version 1.0
9 */
10
11
12 /*****************************************************************************/
13 /* File Includes */
14 /*****************************************************************************/
15 #include "coreconfigurator.h"
16 #include <linux/errno.h>
17 /*****************************************************************************/
18 /* Constants */
19 /*****************************************************************************/
20 #define INLINE static __inline
21 #define TAG_PARAM_OFFSET (MAC_HDR_LEN + TIME_STAMP_LEN + \
22 BEACON_INTERVAL_LEN + CAP_INFO_LEN)
23
24 /*****************************************************************************/
25 /* Function Macros */
26 /*****************************************************************************/
27
28
29 /*****************************************************************************/
30 /* Type Definitions */
31 /*****************************************************************************/
32
33 /* Basic Frame Type Codes (2-bit) */
34 typedef enum {
35 FRAME_TYPE_CONTROL = 0x04,
36 FRAME_TYPE_DATA = 0x08,
37 FRAME_TYPE_MANAGEMENT = 0x00,
38 FRAME_TYPE_RESERVED = 0x0C,
39 FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
40 } tenuBasicFrmType;
41
42 /* Frame Type and Subtype Codes (6-bit) */
43 typedef enum {
44 ASSOC_REQ = 0x00,
45 ASSOC_RSP = 0x10,
46 REASSOC_REQ = 0x20,
47 REASSOC_RSP = 0x30,
48 PROBE_REQ = 0x40,
49 PROBE_RSP = 0x50,
50 BEACON = 0x80,
51 ATIM = 0x90,
52 DISASOC = 0xA0,
53 AUTH = 0xB0,
54 DEAUTH = 0xC0,
55 ACTION = 0xD0,
56 PS_POLL = 0xA4,
57 RTS = 0xB4,
58 CTS = 0xC4,
59 ACK = 0xD4,
60 CFEND = 0xE4,
61 CFEND_ACK = 0xF4,
62 DATA = 0x08,
63 DATA_ACK = 0x18,
64 DATA_POLL = 0x28,
65 DATA_POLL_ACK = 0x38,
66 NULL_FRAME = 0x48,
67 CFACK = 0x58,
68 CFPOLL = 0x68,
69 CFPOLL_ACK = 0x78,
70 QOS_DATA = 0x88,
71 QOS_DATA_ACK = 0x98,
72 QOS_DATA_POLL = 0xA8,
73 QOS_DATA_POLL_ACK = 0xB8,
74 QOS_NULL_FRAME = 0xC8,
75 QOS_CFPOLL = 0xE8,
76 QOS_CFPOLL_ACK = 0xF8,
77 BLOCKACK_REQ = 0x84,
78 BLOCKACK = 0x94,
79 FRAME_SUBTYPE_FORCE_32BIT = 0xFFFFFFFF
80 } tenuFrmSubtype;
81
82 /* Element ID of various Information Elements */
83 typedef enum {
84 ISSID = 0, /* Service Set Identifier */
85 ISUPRATES = 1, /* Supported Rates */
86 IFHPARMS = 2, /* FH parameter set */
87 IDSPARMS = 3, /* DS parameter set */
88 ICFPARMS = 4, /* CF parameter set */
89 ITIM = 5, /* Traffic Information Map */
90 IIBPARMS = 6, /* IBSS parameter set */
91 ICOUNTRY = 7, /* Country element */
92 IEDCAPARAMS = 12, /* EDCA parameter set */
93 ITSPEC = 13, /* Traffic Specification */
94 ITCLAS = 14, /* Traffic Classification */
95 ISCHED = 15, /* Schedule */
96 ICTEXT = 16, /* Challenge Text */
97 IPOWERCONSTRAINT = 32, /* Power Constraint */
98 IPOWERCAPABILITY = 33, /* Power Capability */
99 ITPCREQUEST = 34, /* TPC Request */
100 ITPCREPORT = 35, /* TPC Report */
101 ISUPCHANNEL = 36, /* Supported channel list */
102 ICHSWANNOUNC = 37, /* Channel Switch Announcement */
103 IMEASUREMENTREQUEST = 38, /* Measurement request */
104 IMEASUREMENTREPORT = 39, /* Measurement report */
105 IQUIET = 40, /* Quiet element Info */
106 IIBSSDFS = 41, /* IBSS DFS */
107 IERPINFO = 42, /* ERP Information */
108 ITSDELAY = 43, /* TS Delay */
109 ITCLASPROCESS = 44, /* TCLAS Processing */
110 IHTCAP = 45, /* HT Capabilities */
111 IQOSCAP = 46, /* QoS Capability */
112 IRSNELEMENT = 48, /* RSN Information Element */
113 IEXSUPRATES = 50, /* Extended Supported Rates */
114 IEXCHSWANNOUNC = 60, /* Extended Ch Switch Announcement*/
115 IHTOPERATION = 61, /* HT Information */
116 ISECCHOFF = 62, /* Secondary Channel Offeset */
117 I2040COEX = 72, /* 20/40 Coexistence IE */
118 I2040INTOLCHREPORT = 73, /* 20/40 Intolerant channel report*/
119 IOBSSSCAN = 74, /* OBSS Scan parameters */
120 IEXTCAP = 127, /* Extended capability */
121 IWMM = 221, /* WMM parameters */
122 IWPAELEMENT = 221, /* WPA Information Element */
123 INFOELEM_ID_FORCE_32BIT = 0xFFFFFFFF
124 } tenuInfoElemID;
125
126
127 typedef struct {
128 char *pcRespBuffer;
129 s32 s32MaxRespBuffLen;
130 s32 s32BytesRead;
131 bool bRespRequired;
132 } tstrConfigPktInfo;
133
134
135
136 /*****************************************************************************/
137 /* Extern Variable Declarations */
138 /*****************************************************************************/
139
140 /*****************************************************************************/
141 /* Global Variables */
142 /*****************************************************************************/
143 /*****************************************************************************/
144 /* Static Function Declarations */
145 /*****************************************************************************/
146
147
148
149 /*****************************************************************************/
150 /* Functions */
151 /*****************************************************************************/
152
153 /* This function extracts the beacon period field from the beacon or probe */
154 /* response frame. */
155 INLINE u16 get_beacon_period(u8 *data)
156 {
157 u16 bcn_per = 0;
158
159 bcn_per = data[0];
160 bcn_per |= (data[1] << 8);
161
162 return bcn_per;
163 }
164
165 INLINE u32 get_beacon_timestamp_lo(u8 *data)
166 {
167 u32 time_stamp = 0;
168 u32 index = MAC_HDR_LEN;
169
170 time_stamp |= data[index++];
171 time_stamp |= (data[index++] << 8);
172 time_stamp |= (data[index++] << 16);
173 time_stamp |= (data[index] << 24);
174
175 return time_stamp;
176 }
177
178 INLINE u32 get_beacon_timestamp_hi(u8 *data)
179 {
180 u32 time_stamp = 0;
181 u32 index = (MAC_HDR_LEN + 4);
182
183 time_stamp |= data[index++];
184 time_stamp |= (data[index++] << 8);
185 time_stamp |= (data[index++] << 16);
186 time_stamp |= (data[index] << 24);
187
188 return time_stamp;
189 }
190
191 /* This function extracts the 'frame type and sub type' bits from the MAC */
192 /* header of the input frame. */
193 /* Returns the value in the LSB of the returned value. */
194 INLINE tenuFrmSubtype get_sub_type(u8 *header)
195 {
196 return ((tenuFrmSubtype)(header[0] & 0xFC));
197 }
198
199 /* This function extracts the 'to ds' bit from the MAC header of the input */
200 /* frame. */
201 /* Returns the value in the LSB of the returned value. */
202 INLINE u8 get_to_ds(u8 *header)
203 {
204 return (header[1] & 0x01);
205 }
206
207 /* This function extracts the 'from ds' bit from the MAC header of the input */
208 /* frame. */
209 /* Returns the value in the LSB of the returned value. */
210 INLINE u8 get_from_ds(u8 *header)
211 {
212 return ((header[1] & 0x02) >> 1);
213 }
214
215 /* This function extracts the MAC Address in 'address1' field of the MAC */
216 /* header and updates the MAC Address in the allocated 'addr' variable. */
217 INLINE void get_address1(u8 *pu8msa, u8 *addr)
218 {
219 memcpy(addr, pu8msa + 4, 6);
220 }
221
222 /* This function extracts the MAC Address in 'address2' field of the MAC */
223 /* header and updates the MAC Address in the allocated 'addr' variable. */
224 INLINE void get_address2(u8 *pu8msa, u8 *addr)
225 {
226 memcpy(addr, pu8msa + 10, 6);
227 }
228
229 /* This function extracts the MAC Address in 'address3' field of the MAC */
230 /* header and updates the MAC Address in the allocated 'addr' variable. */
231 INLINE void get_address3(u8 *pu8msa, u8 *addr)
232 {
233 memcpy(addr, pu8msa + 16, 6);
234 }
235
236 /* This function extracts the BSSID from the incoming WLAN packet based on */
237 /* the 'from ds' bit, and updates the MAC Address in the allocated 'addr' */
238 /* variable. */
239 INLINE void get_BSSID(u8 *data, u8 *bssid)
240 {
241 if (get_from_ds(data) == 1)
242 get_address2(data, bssid);
243 else if (get_to_ds(data) == 1)
244 get_address1(data, bssid);
245 else
246 get_address3(data, bssid);
247 }
248
249 /* This function extracts the SSID from a beacon/probe response frame */
250 INLINE void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
251 {
252 u8 len = 0;
253 u8 i = 0;
254 u8 j = 0;
255
256 len = data[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
257 CAP_INFO_LEN + 1];
258 j = MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN +
259 CAP_INFO_LEN + 2;
260
261 /* If the SSID length field is set wrongly to a value greater than the */
262 /* allowed maximum SSID length limit, reset the length to 0 */
263 if (len >= MAX_SSID_LEN)
264 len = 0;
265
266 for (i = 0; i < len; i++, j++)
267 ssid[i] = data[j];
268
269 ssid[len] = '\0';
270
271 *p_ssid_len = len;
272 }
273
274 /* This function extracts the capability info field from the beacon or probe */
275 /* response frame. */
276 INLINE u16 get_cap_info(u8 *data)
277 {
278 u16 cap_info = 0;
279 u16 index = MAC_HDR_LEN;
280 tenuFrmSubtype st;
281
282 st = get_sub_type(data);
283
284 /* Location of the Capability field is different for Beacon and */
285 /* Association frames. */
286 if ((st == BEACON) || (st == PROBE_RSP))
287 index += TIME_STAMP_LEN + BEACON_INTERVAL_LEN;
288
289 cap_info = data[index];
290 cap_info |= (data[index + 1] << 8);
291
292 return cap_info;
293 }
294
295 /* This function extracts the capability info field from the Association */
296 /* response frame. */
297 INLINE u16 get_assoc_resp_cap_info(u8 *data)
298 {
299 u16 cap_info = 0;
300
301 cap_info = data[0];
302 cap_info |= (data[1] << 8);
303
304 return cap_info;
305 }
306
307 /* This funcion extracts the association status code from the incoming */
308 /* association response frame and returns association status code */
309 INLINE u16 get_asoc_status(u8 *data)
310 {
311 u16 asoc_status = 0;
312
313 asoc_status = data[3];
314 asoc_status = (asoc_status << 8) | data[2];
315
316 return asoc_status;
317 }
318
319 /* This function extracts association ID from the incoming association */
320 /* response frame */
321 INLINE u16 get_asoc_id(u8 *data)
322 {
323 u16 asoc_id = 0;
324
325 asoc_id = data[4];
326 asoc_id |= (data[5] << 8);
327
328 return asoc_id;
329 }
330
331 /**
332 * @brief initializes the Core Configurator
333 * @details
334 * @return Error code indicating success/failure
335 * @note
336 * @author mabubakr
337 * @date 1 Mar 2012
338 * @version 1.0
339 */
340
341 s32 CoreConfiguratorInit(void)
342 {
343 s32 s32Error = 0;
344
345 PRINT_D(CORECONFIG_DBG, "CoreConfiguratorInit()\n");
346
347 return s32Error;
348 }
349
350 u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
351 {
352 u16 u16index = 0;
353
354 /*************************************************************************/
355 /* Beacon Frame - Frame Body */
356 /* --------------------------------------------------------------------- */
357 /* |Timestamp |BeaconInt |CapInfo |SSID |SupRates |DSParSet |TIM elm | */
358 /* --------------------------------------------------------------------- */
359 /* |8 |2 |2 |2-34 |3-10 |3 |4-256 | */
360 /* --------------------------------------------------------------------- */
361 /* */
362 /*************************************************************************/
363
364 u16index = u16TagParamOffset;
365
366 /* Search for the TIM Element Field and return if the element is found */
367 while (u16index < (u16RxLen - FCS_LEN)) {
368 if (pu8msa[u16index] == ITIM)
369 return &pu8msa[u16index];
370 else
371 u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
372 }
373
374 return NULL;
375 }
376
377 /* This function gets the current channel information from
378 * the 802.11n beacon/probe response frame */
379 u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
380 {
381 u16 index;
382
383 index = TAG_PARAM_OFFSET;
384 while (index < (u16RxLen - FCS_LEN)) {
385 if (pu8msa[index] == IDSPARMS)
386 return pu8msa[index + 2];
387 else
388 /* Increment index by length information and header */
389 index += pu8msa[index + 1] + IE_HDR_LEN;
390 }
391
392 /* Return current channel information from the MIB, if beacon/probe */
393 /* response frame does not contain the DS parameter set IE */
394 /* return (mget_CurrentChannel() + 1); */
395 return 0; /* no MIB here */
396 }
397
398 u8 get_current_channel(u8 *pu8msa, u16 u16RxLen)
399 {
400 /* Extract current channel information from */
401 /* the beacon/probe response frame */
402 return get_current_channel_802_11n(pu8msa, u16RxLen);
403 }
404
405 /**
406 * @brief parses the received 'N' message
407 * @details
408 * @param[in] pu8MsgBuffer The message to be parsed
409 * @param[out] ppstrNetworkInfo pointer to pointer to the structure containing the parsed Network Info
410 * @return Error code indicating success/failure
411 * @note
412 * @author mabubakr
413 * @date 1 Mar 2012
414 * @version 1.0
415 */
416 s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
417 {
418 s32 s32Error = 0;
419 tstrNetworkInfo *pstrNetworkInfo = NULL;
420 u8 u8MsgType = 0;
421 u8 u8MsgID = 0;
422 u16 u16MsgLen = 0;
423
424 u16 u16WidID = (u16)WID_NIL;
425 u16 u16WidLen = 0;
426 u8 *pu8WidVal = NULL;
427
428 u8MsgType = pu8MsgBuffer[0];
429
430 /* Check whether the received message type is 'N' */
431 if ('N' != u8MsgType) {
432 PRINT_ER("Received Message format incorrect.\n");
433 return -EFAULT;
434 }
435
436 /* Extract message ID */
437 u8MsgID = pu8MsgBuffer[1];
438
439 /* Extract message Length */
440 u16MsgLen = MAKE_WORD16(pu8MsgBuffer[2], pu8MsgBuffer[3]);
441
442 /* Extract WID ID */
443 u16WidID = MAKE_WORD16(pu8MsgBuffer[4], pu8MsgBuffer[5]);
444
445 /* Extract WID Length */
446 u16WidLen = MAKE_WORD16(pu8MsgBuffer[6], pu8MsgBuffer[7]);
447
448 /* Assign a pointer to the WID value */
449 pu8WidVal = &pu8MsgBuffer[8];
450
451 /* parse the WID value of the WID "WID_NEWORK_INFO" */
452 {
453 u8 *pu8msa = NULL;
454 u16 u16RxLen = 0;
455 u8 *pu8TimElm = NULL;
456 u8 *pu8IEs = NULL;
457 u16 u16IEsLen = 0;
458 u8 u8index = 0;
459 u32 u32Tsf_Lo;
460 u32 u32Tsf_Hi;
461
462 pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
463 if (!pstrNetworkInfo)
464 return -ENOMEM;
465
466 memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
467
468 pstrNetworkInfo->s8rssi = pu8WidVal[0];
469
470 /* Assign a pointer to msa "Mac Header Start Address" */
471 pu8msa = &pu8WidVal[1];
472
473 u16RxLen = u16WidLen - 1;
474
475 /* parse msa*/
476
477 /* Get the cap_info */
478 pstrNetworkInfo->u16CapInfo = get_cap_info(pu8msa);
479 #ifdef WILC_P2P
480 /* Get time-stamp [Low only 32 bit] */
481 pstrNetworkInfo->u32Tsf = get_beacon_timestamp_lo(pu8msa);
482 PRINT_D(CORECONFIG_DBG, "TSF :%x\n", pstrNetworkInfo->u32Tsf);
483 #endif
484
485 /* Get full time-stamp [Low and High 64 bit] */
486 u32Tsf_Lo = get_beacon_timestamp_lo(pu8msa);
487 u32Tsf_Hi = get_beacon_timestamp_hi(pu8msa);
488
489 pstrNetworkInfo->u64Tsf = u32Tsf_Lo | ((u64)u32Tsf_Hi << 32);
490
491 /* Get SSID */
492 get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &(pstrNetworkInfo->u8SsidLen));
493
494 /* Get BSSID */
495 get_BSSID(pu8msa, pstrNetworkInfo->au8bssid);
496
497 /* Get the current channel */
498 pstrNetworkInfo->u8channel = get_current_channel(pu8msa, (u16RxLen + FCS_LEN));
499
500 /* Get beacon period */
501 u8index = (MAC_HDR_LEN + TIME_STAMP_LEN);
502
503 pstrNetworkInfo->u16BeaconPeriod = get_beacon_period(pu8msa + u8index);
504
505 u8index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
506
507 /* Get DTIM Period */
508 pu8TimElm = get_tim_elm(pu8msa, (u16RxLen + FCS_LEN), u8index);
509 if (pu8TimElm != NULL)
510 pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
511 pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
512 u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
513
514 if (u16IEsLen > 0) {
515 pstrNetworkInfo->pu8IEs = kmalloc(u16IEsLen, GFP_KERNEL);
516 if (!pstrNetworkInfo->pu8IEs)
517 return -ENOMEM;
518
519 memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
520
521 memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
522 }
523 pstrNetworkInfo->u16IEsLen = u16IEsLen;
524
525 }
526
527 *ppstrNetworkInfo = pstrNetworkInfo;
528
529 return s32Error;
530 }
531
532 /**
533 * @brief Deallocates the parsed Network Info
534 * @details
535 * @param[in] pstrNetworkInfo Network Info to be deallocated
536 * @return Error code indicating success/failure
537 * @note
538 * @author mabubakr
539 * @date 1 Mar 2012
540 * @version 1.0
541 */
542 s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
543 {
544 s32 s32Error = 0;
545
546 if (pstrNetworkInfo != NULL) {
547 if (pstrNetworkInfo->pu8IEs != NULL) {
548 kfree(pstrNetworkInfo->pu8IEs);
549 pstrNetworkInfo->pu8IEs = NULL;
550 } else {
551 s32Error = -EFAULT;
552 }
553
554 kfree(pstrNetworkInfo);
555 pstrNetworkInfo = NULL;
556
557 } else {
558 s32Error = -EFAULT;
559 }
560
561 return s32Error;
562 }
563
564 /**
565 * @brief parses the received Association Response frame
566 * @details
567 * @param[in] pu8Buffer The Association Response frame to be parsed
568 * @param[out] ppstrConnectRespInfo pointer to pointer to the structure containing the parsed Association Response Info
569 * @return Error code indicating success/failure
570 * @note
571 * @author mabubakr
572 * @date 2 Apr 2012
573 * @version 1.0
574 */
575 s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
576 tstrConnectRespInfo **ppstrConnectRespInfo)
577 {
578 s32 s32Error = 0;
579 tstrConnectRespInfo *pstrConnectRespInfo = NULL;
580 u16 u16AssocRespLen = 0;
581 u8 *pu8IEs = NULL;
582 u16 u16IEsLen = 0;
583
584 pstrConnectRespInfo = kmalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
585 if (!pstrConnectRespInfo)
586 return -ENOMEM;
587
588 memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
589
590 /* u16AssocRespLen = pu8Buffer[0]; */
591 u16AssocRespLen = (u16)u32BufferLen;
592
593 /* get the status code */
594 pstrConnectRespInfo->u16ConnectStatus = get_asoc_status(pu8Buffer);
595 if (pstrConnectRespInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
596
597 /* get the capability */
598 pstrConnectRespInfo->u16capability = get_assoc_resp_cap_info(pu8Buffer);
599
600 /* get the Association ID */
601 pstrConnectRespInfo->u16AssocID = get_asoc_id(pu8Buffer);
602
603 /* get the Information Elements */
604 pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
605 u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
606
607 pstrConnectRespInfo->pu8RespIEs = kmalloc(u16IEsLen, GFP_KERNEL);
608 if (!pstrConnectRespInfo->pu8RespIEs)
609 return -ENOMEM;
610
611 memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
612
613 memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);
614 pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
615 }
616
617 *ppstrConnectRespInfo = pstrConnectRespInfo;
618
619
620 return s32Error;
621 }
622
623 /**
624 * @brief Deallocates the parsed Association Response Info
625 * @details
626 * @param[in] pstrNetworkInfo Network Info to be deallocated
627 * @return Error code indicating success/failure
628 * @note
629 * @author mabubakr
630 * @date 2 Apr 2012
631 * @version 1.0
632 */
633 s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo)
634 {
635 s32 s32Error = 0;
636
637 if (pstrConnectRespInfo != NULL) {
638 if (pstrConnectRespInfo->pu8RespIEs != NULL) {
639 kfree(pstrConnectRespInfo->pu8RespIEs);
640 pstrConnectRespInfo->pu8RespIEs = NULL;
641 } else {
642 s32Error = -EFAULT;
643 }
644
645 kfree(pstrConnectRespInfo);
646 pstrConnectRespInfo = NULL;
647
648 } else {
649 s32Error = -EFAULT;
650 }
651
652 return s32Error;
653 }
654
655 #ifndef CONNECT_DIRECT
656 s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
657 wid_site_survey_reslts_s **ppstrSurveyResults,
658 u32 *pu32SurveyResultsCount)
659 {
660 s32 s32Error = 0;
661 wid_site_survey_reslts_s *pstrSurveyResults = NULL;
662 u32 u32SurveyResultsCount = 0;
663 u32 u32SurveyBytesLength = 0;
664 u8 *pu8BufferPtr;
665 u32 u32RcvdSurveyResultsNum = 2;
666 u8 u8ReadSurveyResFragNum;
667 u32 i;
668 u32 j;
669
670 for (i = 0; i < u32RcvdSurveyResultsNum; i++) {
671 u32SurveyBytesLength = ppu8RcvdSiteSurveyResults[i][0];
672
673
674 for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
675 u32SurveyResultsCount++;
676 }
677 }
678
679 pstrSurveyResults = kmalloc_array(u32SurveyResultsCount,
680 sizeof(wid_site_survey_reslts_s), GFP_KERNEL);
681 if (!pstrSurveyResults)
682 return -ENOMEM;
683
684 memset((void *)(pstrSurveyResults), 0, u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
685
686 u32SurveyResultsCount = 0;
687
688 for (i = 0; i < u32RcvdSurveyResultsNum; i++) {
689 pu8BufferPtr = ppu8RcvdSiteSurveyResults[i];
690
691 u32SurveyBytesLength = pu8BufferPtr[0];
692
693 /* TODO: mostafa: pu8BufferPtr[1] contains the fragment num */
694 u8ReadSurveyResFragNum = pu8BufferPtr[1];
695
696 pu8BufferPtr += 2;
697
698 for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
699 memcpy(&pstrSurveyResults[u32SurveyResultsCount], pu8BufferPtr, SURVEY_RESULT_LENGTH);
700 pu8BufferPtr += SURVEY_RESULT_LENGTH;
701 u32SurveyResultsCount++;
702 }
703 }
704
705 ERRORHANDLER:
706 *ppstrSurveyResults = pstrSurveyResults;
707 *pu32SurveyResultsCount = u32SurveyResultsCount;
708
709 return s32Error;
710 }
711
712
713 s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults)
714 {
715 s32 s32Error = 0;
716
717 if (pstrSurveyResults != NULL) {
718 kfree(pstrSurveyResults);
719 }
720
721 return s32Error;
722 }
723 #endif
724
725 /**
726 * @brief Deinitializes the Core Configurator
727 * @details
728 * @return Error code indicating success/failure
729 * @note
730 * @author mabubakr
731 * @date 1 Mar 2012
732 * @version 1.0
733 */
734
735 s32 CoreConfiguratorDeInit(void)
736 {
737 s32 s32Error = 0;
738
739 PRINT_D(CORECONFIG_DBG, "CoreConfiguratorDeInit()\n");
740
741
742 return s32Error;
743 }
744
745 /*Using the global handle of the driver*/
746 extern wilc_wlan_oup_t *gpstrWlanOps;
747 /**
748 * @brief sends certain Configuration Packet based on the input WIDs pstrWIDs
749 * using driver config layer
750 *
751 * @details
752 * @param[in] pstrWIDs WIDs to be sent in the configuration packet
753 * @param[in] u32WIDsCount number of WIDs to be sent in the configuration packet
754 * @param[out] pu8RxResp The received Packet Response
755 * @param[out] ps32RxRespLen Length of the received Packet Response
756 * @return Error code indicating success/failure
757 * @note
758 * @author mabubakr
759 * @date 1 Mar 2012
760 * @version 1.0
761 */
762 s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
763 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler)
764 {
765 s32 counter = 0, ret = 0;
766
767 if (gpstrWlanOps == NULL) {
768 PRINT_D(CORECONFIG_DBG, "Net Dev is still not initialized\n");
769 return 1;
770 } else {
771 PRINT_D(CORECONFIG_DBG, "Net Dev is initialized\n");
772 }
773 if (gpstrWlanOps->wlan_cfg_set == NULL ||
774 gpstrWlanOps->wlan_cfg_get == NULL) {
775 PRINT_D(CORECONFIG_DBG, "Set and Get is still not initialized\n");
776 return 1;
777 } else {
778 PRINT_D(CORECONFIG_DBG, "SET is initialized\n");
779 }
780 if (u8Mode == GET_CFG) {
781 for (counter = 0; counter < u32WIDsCount; counter++) {
782 PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter,
783 (counter == u32WIDsCount - 1));
784 if (!gpstrWlanOps->wlan_cfg_get(!counter,
785 pstrWIDs[counter].u16WIDid,
786 (counter == u32WIDsCount - 1), drvHandler)) {
787 ret = -1;
788 printk("[Sendconfigpkt]Get Timed out\n");
789 break;
790 }
791 }
792 /**
793 * get the value
794 **/
795 counter = 0;
796 for (counter = 0; counter < u32WIDsCount; counter++) {
797 pstrWIDs[counter].s32ValueSize = gpstrWlanOps->wlan_cfg_get_value(
798 pstrWIDs[counter].u16WIDid,
799 pstrWIDs[counter].ps8WidVal, pstrWIDs[counter].s32ValueSize);
800
801 }
802 } else if (u8Mode == SET_CFG) {
803 for (counter = 0; counter < u32WIDsCount; counter++) {
804 PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", pstrWIDs[counter].u16WIDid);
805 if (!gpstrWlanOps->wlan_cfg_set(!counter,
806 pstrWIDs[counter].u16WIDid, pstrWIDs[counter].ps8WidVal,
807 pstrWIDs[counter].s32ValueSize,
808 (counter == u32WIDsCount - 1), drvHandler)) {
809 ret = -1;
810 printk("[Sendconfigpkt]Set Timed out\n");
811 break;
812 }
813 }
814 }
815
816 return ret;
817 }
This page took 0.146157 seconds and 5 git commands to generate.