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