Staging: wilc1000: Assign proper boolean value
[pandora-kernel.git] / drivers / staging / wilc1000 / host_interface.c
1 #include "host_interface.h"
2 #include "coreconfigurator.h"
3
4 extern s32 TransportInit(void);
5 extern s32 TransportDeInit(void);
6 extern u8 connecting;
7
8 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
9 extern WILC_TimerHandle hDuringIpTimer;
10 #endif
11
12 extern bool bEnablePS;
13 /*BugID_5137*/
14 extern u8 g_wilc_initialized;
15 /*****************************************************************************/
16 /*                                                              Macros                                       */
17 /*****************************************************************************/
18
19 /* Message types of the Host IF Message Queue*/
20 #define HOST_IF_MSG_SCAN                                        ((u16)0)
21 #define HOST_IF_MSG_CONNECT                                     ((u16)1)
22 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO        ((u16)2)
23 #define HOST_IF_MSG_KEY                                         ((u16)3)
24 #define HOST_IF_MSG_RCVD_NTWRK_INFO                     ((u16)4)
25 #define HOST_IF_MSG_RCVD_SCAN_COMPLETE          ((u16)5)
26 #define HOST_IF_MSG_CFG_PARAMS                          ((u16)6)
27 #define HOST_IF_MSG_SET_CHANNEL                         ((u16)7)
28 #define HOST_IF_MSG_DISCONNECT                          ((u16)8)
29 #define HOST_IF_MSG_GET_RSSI                            ((u16)9)
30 #define HOST_IF_MSG_GET_CHNL                            ((u16)10)
31 #define HOST_IF_MSG_ADD_BEACON                          ((u16)11)
32 #define HOST_IF_MSG_DEL_BEACON                          ((u16)12)
33 #define HOST_IF_MSG_ADD_STATION                         ((u16)13)
34 #define HOST_IF_MSG_DEL_STATION                         ((u16)14)
35 #define HOST_IF_MSG_EDIT_STATION                        ((u16)15)
36 #define HOST_IF_MSG_SCAN_TIMER_FIRED                    ((u16)16)
37 #define HOST_IF_MSG_CONNECT_TIMER_FIRED         ((u16)17)
38 #define HOST_IF_MSG_POWER_MGMT                          ((u16)18)
39 #define HOST_IF_MSG_GET_INACTIVETIME                    ((u16)19)
40 #define HOST_IF_MSG_REMAIN_ON_CHAN                      ((u16)20)
41 #define  HOST_IF_MSG_REGISTER_FRAME                     ((u16)21)
42 #define HOST_IF_MSG_LISTEN_TIMER_FIRED     ((u16)22)
43 #define HOST_IF_MSG_GET_LINKSPEED                               ((u16)23)
44 #define HOST_IF_MSG_SET_WFIDRV_HANDLER          ((u16)24)
45 #define HOST_IF_MSG_SET_MAC_ADDRESS             ((u16)25)
46 #define HOST_IF_MSG_GET_MAC_ADDRESS             ((u16)26)
47 #define HOST_IF_MSG_SET_OPERATION_MODE          ((u16)27)
48 #define HOST_IF_MSG_SET_IPADDRESS                       ((u16)28)
49 #define HOST_IF_MSG_GET_IPADDRESS                       ((u16)29)
50 #define HOST_IF_MSG_FLUSH_CONNECT                       ((u16)30)
51 #define HOST_IF_MSG_GET_STATISTICS                              ((u16)31)
52 #define HOST_IF_MSG_SET_MULTICAST_FILTER                ((u16)32)
53 #define HOST_IF_MSG_ADD_BA_SESSION              ((u16)33)
54 #define HOST_IF_MSG_DEL_BA_SESSION              ((u16)34)
55 #define HOST_IF_MSG_Q_IDLE              ((u16)35)
56 #define HOST_IF_MSG_DEL_ALL_STA  ((u16)36)
57 #define HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS              ((u16)34)
58
59 #define HOST_IF_MSG_EXIT                                        ((u16)100)
60
61 #define HOST_IF_SCAN_TIMEOUT            4000
62 #define HOST_IF_CONNECT_TIMEOUT 9500
63
64 #define BA_SESSION_DEFAULT_BUFFER_SIZE  16
65 #define BA_SESSION_DEFAULT_TIMEOUT              1000
66 #define BLOCK_ACK_REQ_SIZE 0x14
67 /*****************************************************************************/
68 /*                                                              Type Definitions                                                         */
69 /*****************************************************************************/
70
71 /*!
72  *  @struct             tstrHostIFCfgParamAttr
73  *  @brief              Structure to hold Host IF CFG Params Attributes
74  *  @details
75  *  @todo
76  *  @sa
77  *  @author             Mai Daftedar
78  *  @date               02 April 2012
79  *  @version            1.0
80  */
81 typedef struct _tstrHostIFCfgParamAttr {
82         tstrCfgParamVal pstrCfgParamVal;
83
84 } tstrHostIFCfgParamAttr;
85
86 /*!
87  *  @struct             tstrHostIFwpaAttr
88  *  @brief              Structure to hold Host IF Scan Attributes
89  *  @details
90  *  @todo
91  *  @sa
92  *  @author             Mai Daftedar
93  *  @date               25 March 2012
94  *  @version            1.0
95  */
96 typedef struct _tstrHostIFwpaAttr {
97         u8 *pu8key;
98         const u8 *pu8macaddr;
99         u8 *pu8seq;
100         u8 u8seqlen;
101         u8 u8keyidx;
102         u8 u8Keylen;
103         u8 u8Ciphermode;
104 } tstrHostIFwpaAttr;
105
106
107 /*!
108  *  @struct             tstrHostIFwepAttr
109  *  @brief              Structure to hold Host IF Scan Attributes
110  *  @details
111  *  @todo
112  *  @sa
113  *  @author             Mai Daftedar
114  *  @date               25 March 2012
115  *  @version            1.0
116  */
117 typedef struct _tstrHostIFwepAttr {
118         u8 *pu8WepKey;
119         u8 u8WepKeylen;
120         u8 u8Wepidx;
121         u8 u8mode;
122         AUTHTYPE_T tenuAuth_type;
123
124 } tstrHostIFwepAttr;
125
126 /*!
127  *  @struct             tuniHostIFkeyAttr
128  *  @brief              Structure to hold Host IF Scan Attributes
129  *  @details
130  *  @todo
131  *  @sa
132  *  @author             Mai Daftedar
133  *  @date               25 March 2012
134  *  @version            1.0
135  */
136 typedef union _tuniHostIFkeyAttr {
137         tstrHostIFwepAttr strHostIFwepAttr;
138         tstrHostIFwpaAttr strHostIFwpaAttr;
139         tstrHostIFpmkidAttr strHostIFpmkidAttr;
140 } tuniHostIFkeyAttr;
141
142 /*!
143  *  @struct             tstrHostIFkeyAttr
144  *  @brief              Structure to hold Host IF Scan Attributes
145  *  @details
146  *  @todo
147  *  @sa
148  *  @author             Mai Daftedar
149  *  @date               25 March 2012
150  *  @version            1.0
151  */
152 typedef struct _tstrHostIFkeyAttr {
153         tenuKeyType enuKeyType;
154         u8 u8KeyAction;
155         tuniHostIFkeyAttr uniHostIFkeyAttr;
156 } tstrHostIFkeyAttr;
157
158
159
160
161 /*!
162  *  @struct             tstrHostIFscanAttr
163  *  @brief              Structure to hold Host IF Scan Attributes
164  *  @details
165  *  @todo
166  *  @sa
167  *  @author             Mostafa Abu Bakr
168  *  @date               25 March 2012
169  *  @version            1.0
170  */
171 typedef struct _tstrHostIFscanAttr {
172         u8 u8ScanSource;
173         u8 u8ScanType;
174         u8 *pu8ChnlFreqList;
175         u8 u8ChnlListLen;
176         u8 *pu8IEs;
177         size_t IEsLen;
178         tWILCpfScanResult pfScanResult;
179         void *pvUserArg;
180         /*BugID_4189*/
181         tstrHiddenNetwork strHiddenNetwork;
182
183 } tstrHostIFscanAttr;
184
185 /*!
186  *  @struct             tstrHostIFconnectAttr
187  *  @brief              Structure to hold Host IF Connect Attributes
188  *  @details
189  *  @todo
190  *  @sa
191  *  @author             Mostafa Abu Bakr
192  *  @date               25 March 2012
193  *  @version            1.0
194  */
195 typedef struct _tstrHostIFconnectAttr {
196         u8 *pu8bssid;
197         u8 *pu8ssid;
198         size_t ssidLen;
199         u8 *pu8IEs;
200         size_t IEsLen;
201         u8 u8security;
202         tWILCpfConnectResult pfConnectResult;
203         void *pvUserArg;
204         AUTHTYPE_T tenuAuth_type;
205         u8 u8channel;
206         void *pJoinParams;
207 } tstrHostIFconnectAttr;
208
209 /*!
210  *  @struct             tstrRcvdGnrlAsyncInfo
211  *  @brief              Structure to hold Received General Asynchronous info
212  *  @details
213  *  @todo
214  *  @sa
215  *  @author             Mostafa Abu Bakr
216  *  @date               25 March 2012
217  *  @version            1.0
218  */
219 typedef struct _tstrRcvdGnrlAsyncInfo {
220         u8 *pu8Buffer;
221         u32 u32Length;
222 } tstrRcvdGnrlAsyncInfo;
223
224 /*!
225  *  @struct             tstrHostIFSetChan
226  *  @brief              Set Channel  message body
227  *  @details
228  *  @todo
229  *  @sa
230  *  @author             Mai Daftedar
231  *  @date               25 March 2012
232  *  @version            1.0
233  */
234 typedef struct _tstrHostIFSetChan {
235         u8 u8SetChan;
236 } tstrHostIFSetChan;
237
238 /*!
239  *  @struct             tstrHostIFSetChan
240  *  @brief              Get Channel  message body
241  *  @details
242  *  @todo
243  *  @sa
244  *  @author             Mai Daftedar
245  *  @date               01 Jule 2012
246  *  @version            1.0
247  */
248 typedef struct _tstrHostIFGetChan {
249         u8 u8GetChan;
250 } tstrHostIFGetChan;
251
252 /*bug3819: Add Scan acomplete notification to host*/
253 /*!
254  *  @struct             tstrScanComplete
255  *  @brief                      hold received Async. Scan Complete message body
256  *  @details
257  *  @todo
258  *  @sa
259  *  @author             zsalah
260  *  @date               25 March 2012
261  *  @version            1.0
262  */
263 /*typedef struct _tstrScanComplete
264  * {
265  *      u8* pu8Buffer;
266  *      u32 u32Length;
267  * } tstrScanComplete;*/
268
269 /*!
270  *  @struct             tstrHostIFSetBeacon
271  *  @brief              Set Beacon  message body
272  *  @details
273  *  @todo
274  *  @sa
275  *  @author             Adham Abozaeid
276  *  @date               10 July 2012
277  *  @version            1.0
278  */
279 typedef struct _tstrHostIFSetBeacon {
280         u32 u32Interval;                        /*!< Beacon Interval. Period between two successive beacons on air  */
281         u32 u32DTIMPeriod;              /*!< DTIM Period. Indicates how many Beacon frames
282                                                                                         *                              (including the current frame) appear before the next DTIM                */
283         u32 u32HeadLen;                         /*!< Length of the head buffer in bytes         */
284         u8 *pu8Head;                    /*!< Pointer to the beacon's head buffer. Beacon's head is the part
285                                                                                         *              from the beacon's start till the TIM element, NOT including the TIM              */
286         u32 u32TailLen;                         /*!< Length of the tail buffer in bytes */
287         u8 *pu8Tail;                    /*!< Pointer to the beacon's tail buffer. Beacon's tail starts just
288                                                                                         *                              after the TIM inormation element */
289 } tstrHostIFSetBeacon;
290
291
292
293 /*!
294  *  @struct             tstrHostIFDelBeacon
295  *  @brief              Del Beacon  message body
296  *  @details
297  *  @todo
298  *  @sa
299  *  @author             Adham Abozaeid
300  *  @date               15 July 2012
301  *  @version            1.0
302  */
303 typedef struct _tstrHostIFDelBeacon {
304         u8 u8dummy;
305 } tstrHostIFDelBeacon;
306
307 /*!
308  *  @struct             tstrHostIFSetMulti
309  *  @brief              set Multicast filter Address
310  *  @details
311  *  @todo
312  *  @sa
313  *  @author             Abdelrahman Sobhy
314  *  @date               30 August 2013
315  *  @version            1.0 Description
316  */
317
318 typedef struct {
319         bool bIsEnabled;
320         u32 u32count;
321 } tstrHostIFSetMulti;
322
323 /*!
324  *  @struct             tstrHostIFDelAllSta
325  *  @brief              Deauth station message body
326  *  @details
327  *  @todo
328  *  @sa
329  *  @author             Mai Daftedar
330  *  @date               09 April 2014
331  *  @version            1.0 Description
332  */
333
334 typedef struct {
335         u8 au8Sta_DelAllSta[MAX_NUM_STA][ETH_ALEN];
336         u8 u8Num_AssocSta;
337 } tstrHostIFDelAllSta;
338
339 /*!
340  *  @struct             tstrHostIFDelSta
341  *  @brief              Delete station message body
342  *  @details
343  *  @todo
344  *  @sa
345  *  @author             Adham Abozaeid
346  *  @date               15 July 2012
347  *  @version            1.0 Description
348  */
349
350 typedef struct {
351         u8 au8MacAddr[ETH_ALEN];
352 } tstrHostIFDelSta;
353
354 /*!
355  *  @struct             tstrTimerCb
356  *  @brief              Timer callback message body
357  *  @details
358  *  @todo
359  *  @sa
360  *  @author             Mostafa Abu Bakr
361  *  @date               25 March 2012
362  *  @version            1.0
363  */
364 typedef struct _tstrTimerCb {
365         void *pvUsrArg;                 /*!< Private data passed at timer start */
366 } tstrTimerCb;
367
368 /*!
369  *  @struct     tstrHostIfPowerMgmtParam
370  *  @brief              Power management message body
371  *  @details
372  *  @todo
373  *  @sa
374  *  @author             Adham Abozaeid
375  *  @date               24 November 2012
376  *  @version            1.0
377  */
378 typedef struct {
379
380         bool bIsEnabled;
381         u32 u32Timeout;
382 } tstrHostIfPowerMgmtParam;
383
384 /*!
385  *  @struct             tstrHostIFSetIPAddr
386  *  @brief              set IP Address message body
387  *  @details
388  *  @todo
389  *  @sa
390  *  @author             Abdelrahman Sobhy
391  *  @date               30 August 2013
392  *  @version            1.0 Description
393  */
394
395 typedef struct {
396         u8 *au8IPAddr;
397         u8 idx;
398 } tstrHostIFSetIPAddr;
399
400 /*!
401  *  @struct     tstrHostIfStaInactiveT
402  *  @brief              Get station message body
403  *  @details
404  *  @todo
405  *  @sa
406  *  @author         Mai Daftedar
407  *  @date               16 April 2013
408  *  @version            1.0
409  */
410 typedef struct {
411         u8 mac[6];
412
413 } tstrHostIfStaInactiveT;
414 /**/
415 /*!
416  *  @union              tuniHostIFmsgBody
417  *  @brief              Message body for the Host Interface message_q
418  *  @details
419  *  @todo
420  *  @sa
421  *  @author             Mostafa Abu Bakr
422  *  @date               25 March 2012
423  *  @version            1.0
424  */
425 typedef union _tuniHostIFmsgBody {
426         tstrHostIFscanAttr strHostIFscanAttr;                           /*!< Host IF Scan Request Attributes message body */
427         tstrHostIFconnectAttr strHostIFconnectAttr;     /*!< Host IF Connect Request Attributes message body */
428         tstrRcvdNetworkInfo strRcvdNetworkInfo;                 /*!< Received Asynchronous Network Info message body */
429         tstrRcvdGnrlAsyncInfo strRcvdGnrlAsyncInfo;     /*!< Received General Asynchronous Info message body */
430         tstrHostIFkeyAttr strHostIFkeyAttr;                             /*!<>*/
431         tstrHostIFCfgParamAttr strHostIFCfgParamAttr;            /*! <CFG Parameter message Body> */
432         tstrHostIFSetChan strHostIFSetChan;
433         tstrHostIFGetChan strHostIFGetChan;
434         tstrHostIFSetBeacon strHostIFSetBeacon;                 /*!< Set beacon message body */
435         tstrHostIFDelBeacon strHostIFDelBeacon;                 /*!< Del beacon message body */
436         tstrWILC_AddStaParam strAddStaParam;                    /*!< Add station message body */
437         tstrHostIFDelSta strDelStaParam;                                /*!< Del Station message body */
438         tstrWILC_AddStaParam strEditStaParam;                           /*!< Edit station message body */
439         /* tstrScanComplete             strScanComplete;                / *Received Async. Scan Complete message body* / */
440         tstrTimerCb strTimerCb;                                                 /*!< Timer callback message body */
441         tstrHostIfPowerMgmtParam strPowerMgmtparam;     /*!< Power Management message body */
442         tstrHostIfStaInactiveT strHostIfStaInactiveT;
443         tstrHostIFSetIPAddr strHostIfSetIP;
444         tstrHostIfSetDrvHandler strHostIfSetDrvHandler;
445         tstrHostIFSetMulti strHostIfSetMulti;
446         tstrHostIfSetOperationMode strHostIfSetOperationMode;
447         tstrHostIfSetMacAddress strHostIfSetMacAddress;
448         tstrHostIfGetMacAddress strHostIfGetMacAddress;
449         tstrHostIfBASessionInfo strHostIfBASessionInfo;
450         #ifdef WILC_P2P
451         tstrHostIfRemainOnChan strHostIfRemainOnChan;
452         tstrHostIfRegisterFrame strHostIfRegisterFrame;
453         #endif
454         char *pUserData;
455         tstrHostIFDelAllSta strHostIFDelAllSta;
456 } tuniHostIFmsgBody;
457
458 /*!
459  *  @struct             tstrHostIFmsg
460  *  @brief              Host Interface message
461  *  @details
462  *  @todo
463  *  @sa
464  *  @author             Mostafa Abu Bakr
465  *  @date               25 March 2012
466  *  @version            1.0
467  */
468 typedef struct _tstrHostIFmsg {
469         u16 u16MsgId;                                           /*!< Message ID */
470         tuniHostIFmsgBody uniHostIFmsgBody;             /*!< Message body */
471         void *drvHandler;
472 } tstrHostIFmsg;
473
474 #ifdef CONNECT_DIRECT
475 typedef struct _tstrWidJoinReqExt {
476         char SSID[MAX_SSID_LEN];
477         u8 u8channel;
478         u8 BSSID[6];
479 } tstrWidJoinReqExt;
480 #endif
481
482 /*Bug4218: Parsing Join Param*/
483 #ifdef WILC_PARSE_SCAN_IN_HOST
484 /*Struct containg joinParam of each AP*/
485 typedef struct _tstrJoinBssParam {
486         BSSTYPE_T bss_type;
487         u8 dtim_period;
488         u16 beacon_period;
489         u16 cap_info;
490         u8 au8bssid[6];
491         char ssid[MAX_SSID_LEN];
492         u8 ssidLen;
493         u8 supp_rates[MAX_RATES_SUPPORTED + 1];
494         u8 ht_capable;
495         u8 wmm_cap;
496         u8 uapsd_cap;
497         bool rsn_found;
498         u8 rsn_grp_policy;
499         u8 mode_802_11i;
500         u8 rsn_pcip_policy[3];
501         u8 rsn_auth_policy[3];
502         u8 rsn_cap[2];
503         struct _tstrJoinParam *nextJoinBss;
504         #ifdef WILC_P2P
505         u32 tsf;
506         u8 u8NoaEnbaled;
507         u8 u8OppEnable;
508         u8 u8CtWindow;
509         u8 u8Count;
510         u8 u8Index;
511         u8 au8Duration[4];
512         u8 au8Interval[4];
513         u8 au8StartTime[4];
514         #endif
515 } tstrJoinBssParam;
516 /*Bug4218: Parsing Join Param*/
517 /*a linked list table containing needed join parameters entries for each AP found in most recent scan*/
518 typedef struct _tstrBssTable {
519         u8 u8noBssEntries;
520         tstrJoinBssParam *head;
521         tstrJoinBssParam *tail;
522 } tstrBssTable;
523 #endif /*WILC_PARSE_SCAN_IN_HOST*/
524
525 typedef enum {
526         SCAN_TIMER = 0,
527         CONNECT_TIMER   = 1,
528         SCAN_CONNECT_TIMER_FORCE_32BIT = 0xFFFFFFFF
529 } tenuScanConnTimer;
530
531 /*****************************************************************************/
532 /*                                                                                                                                                       */
533 /*                                                      Global Variabls                                                                  */
534 /*                                                                                                                                                       */
535 /*****************************************************************************/
536
537
538 tstrWILC_WFIDrv *terminated_handle = NULL;
539 tstrWILC_WFIDrv *gWFiDrvHandle = NULL;
540 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
541 bool g_obtainingIP = false;
542 #endif
543 u8 P2P_LISTEN_STATE;
544 static struct task_struct *HostIFthreadHandler;
545 static WILC_MsgQueueHandle gMsgQHostIF;
546 static struct semaphore hSemHostIFthrdEnd;
547
548 struct semaphore hSemDeinitDrvHandle;
549 static struct semaphore hWaitResponse;
550 struct semaphore hSemHostIntDeinit;
551 WILC_TimerHandle g_hPeriodicRSSI;
552
553
554
555 u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
556
557 #ifndef CONNECT_DIRECT
558 static u8 gapu8RcvdSurveyResults[2][MAX_SURVEY_RESULT_FRAG_SIZE];
559 #endif
560
561 static u8 gapu8RcvdAssocResp[MAX_ASSOC_RESP_FRAME_SIZE];
562
563 bool gbScanWhileConnected = false;
564
565 static s8 gs8Rssi;
566 static s8 gs8lnkspd;
567 static u8 gu8Chnl;
568 static u8 gs8SetIP[2][4];
569 static u8 gs8GetIP[2][4];
570 #ifdef WILC_AP_EXTERNAL_MLME
571 static u32 gu32InactiveTime;
572 static u8 gu8DelBcn;
573 #endif
574 #ifndef SIMULATION
575 static u32 gu32WidConnRstHack;
576 #endif
577
578 /*BugID_5137*/
579 u8 *gu8FlushedJoinReq;
580 u8 *gu8FlushedInfoElemAsoc;
581 u8 gu8Flushed11iMode;
582 u8 gu8FlushedAuthType;
583 u32 gu32FlushedJoinReqSize;
584 u32 gu32FlushedInfoElemAsocSize;
585 u32 gu8FlushedJoinReqDrvHandler;
586 #define REAL_JOIN_REQ 0
587 #define FLUSHED_JOIN_REQ 1
588 #define FLUSHED_BYTE_POS 79     /* Position the byte indicating flushing in the flushed request */
589
590 /*Bug4218: Parsing Join Param*/
591 #ifdef WILC_PARSE_SCAN_IN_HOST
592 /*Bug4218: Parsing Join Param*/
593 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo);
594 #endif /*WILC_PARSE_SCAN_IN_HOST*/
595
596 extern void chip_sleep_manually(u32 u32SleepTime);
597 extern int linux_wlan_get_num_conn_ifcs(void);
598
599 /**
600  *  @brief Handle_SetChannel
601  *  @details    Sending config packet to firmware to set channel
602  *  @param[in]   tstrHostIFSetChan* pstrHostIFSetChan
603  *  @return     Error code.
604  *  @author
605  *  @date
606  *  @version    1.0
607  */
608 static s32 Handle_SetChannel(void *drvHandler, tstrHostIFSetChan *pstrHostIFSetChan)
609 {
610
611         s32 s32Error = WILC_SUCCESS;
612         tstrWID strWID;
613         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
614
615         /*prepare configuration packet*/
616         strWID.u16WIDid = (u16)WID_CURRENT_CHANNEL;
617         strWID.enuWIDtype = WID_CHAR;
618         strWID.ps8WidVal = (char *)&(pstrHostIFSetChan->u8SetChan);
619         strWID.s32ValueSize = sizeof(char);
620
621         PRINT_D(HOSTINF_DBG, "Setting channel\n");
622         /*Sending Cfg*/
623         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
624         if (s32Error) {
625                 PRINT_ER("Failed to set channel\n");
626                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
627         }
628         WILC_CATCH(s32Error)
629         {
630
631         }
632
633         return s32Error;
634 }
635 /**
636  *  @brief Handle_SetWfiDrvHandler
637  *  @details    Sending config packet to firmware to set driver handler
638  *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
639  *  @return     Error code.
640  *  @author
641  *  @date
642  *  @version    1.0
643  */
644 static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHandler)
645 {
646
647         s32 s32Error = WILC_SUCCESS;
648         tstrWID strWID;
649         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)((pstrHostIfSetDrvHandler->u32Address));
650
651
652         /*prepare configuration packet*/
653         strWID.u16WIDid = (u16)WID_SET_DRV_HANDLER;
654         strWID.enuWIDtype = WID_INT;
655         strWID.ps8WidVal = (s8 *)&(pstrHostIfSetDrvHandler->u32Address);
656         strWID.s32ValueSize = sizeof(u32);
657
658         /*Sending Cfg*/
659
660         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
661
662
663         if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL) {
664                 up(&hSemDeinitDrvHandle);
665         }
666
667
668         if (s32Error) {
669                 PRINT_ER("Failed to set driver handler\n");
670                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
671         }
672         WILC_CATCH(s32Error)
673         {
674
675         }
676
677         return s32Error;
678 }
679
680 /**
681  *  @brief Handle_SetWfiAPDrvHandler
682  *  @details    Sending config packet to firmware to set driver handler
683  *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
684  *  @return     Error code.
685  *  @author
686  *  @date
687  *  @version    1.0
688  */
689 static s32 Handle_SetOperationMode(void *drvHandler, tstrHostIfSetOperationMode *pstrHostIfSetOperationMode)
690 {
691
692         s32 s32Error = WILC_SUCCESS;
693         tstrWID strWID;
694         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
695
696
697         /*prepare configuration packet*/
698         strWID.u16WIDid = (u16)WID_SET_OPERATION_MODE;
699         strWID.enuWIDtype = WID_INT;
700         strWID.ps8WidVal = (s8 *)&(pstrHostIfSetOperationMode->u32Mode);
701         strWID.s32ValueSize = sizeof(u32);
702
703         /*Sending Cfg*/
704         PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p \n", pstrWFIDrv);
705
706         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
707
708
709         if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL) {
710                 up(&hSemDeinitDrvHandle);
711         }
712
713
714         if (s32Error) {
715                 PRINT_ER("Failed to set driver handler\n");
716                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
717         }
718         WILC_CATCH(s32Error)
719         {
720
721         }
722
723         return s32Error;
724 }
725
726 /**
727  *  @brief host_int_set_IPAddress
728  *  @details       Setting IP address params in message queue
729  *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u8* pu8IPAddr
730  *  @return         Error code.
731  *  @author
732  *  @date
733  *  @version    1.0
734  */
735 s32 Handle_set_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
736 {
737
738         s32 s32Error = WILC_SUCCESS;
739         tstrWID strWID;
740         char firmwareIPAddress[4] = {0};
741         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
742
743         if (pu8IPAddr[0] < 192)
744                 pu8IPAddr[0] = 0;
745
746         PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set  IP = %d.%d.%d.%d \n", idx, pu8IPAddr[0], pu8IPAddr[1], pu8IPAddr[2], pu8IPAddr[3]);
747
748         WILC_memcpy(gs8SetIP[idx], pu8IPAddr, IP_ALEN);
749
750         /*prepare configuration packet*/
751         strWID.u16WIDid = (u16)WID_IP_ADDRESS;
752         strWID.enuWIDtype = WID_STR;
753         strWID.ps8WidVal = (u8 *)pu8IPAddr;
754         strWID.s32ValueSize = IP_ALEN;
755
756         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
757
758
759
760         host_int_get_ipaddress((WILC_WFIDrvHandle)drvHandler, firmwareIPAddress, idx);
761
762         if (s32Error) {
763                 PRINT_D(HOSTINF_DBG, "Failed to set IP address\n");
764                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
765         } else {
766                 PRINT_INFO(HOSTINF_DBG, "IP address set\n");
767         }
768
769         WILC_CATCH(s32Error)
770         {
771
772         }
773
774         return s32Error;
775 }
776
777
778 /**
779  *  @brief Handle_get_IPAddress
780  *  @details       Setting IP address params in message queue
781  *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u8* pu8IPAddr
782  *  @return         Error code.
783  *  @author
784  *  @date
785  *  @version    1.0
786  */
787 s32 Handle_get_IPAddress(void *drvHandler, u8 *pu8IPAddr, u8 idx)
788 {
789
790         s32 s32Error = WILC_SUCCESS;
791         tstrWID strWID;
792         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
793
794         /*prepare configuration packet*/
795         strWID.u16WIDid = (u16)WID_IP_ADDRESS;
796         strWID.enuWIDtype = WID_STR;
797         strWID.ps8WidVal = (u8 *)WILC_MALLOC(IP_ALEN);
798         strWID.s32ValueSize = IP_ALEN;
799
800         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
801
802         PRINT_INFO(HOSTINF_DBG, "%d.%d.%d.%d\n", (u8)(strWID.ps8WidVal[0]), (u8)(strWID.ps8WidVal[1]), (u8)(strWID.ps8WidVal[2]), (u8)(strWID.ps8WidVal[3]));
803
804         WILC_memcpy(gs8GetIP[idx], strWID.ps8WidVal, IP_ALEN);
805
806         /*get the value by searching the local copy*/
807         WILC_FREE(strWID.ps8WidVal);
808
809         if (WILC_memcmp(gs8GetIP[idx], gs8SetIP[idx], IP_ALEN) != 0)
810                 host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, gs8SetIP[idx], idx);
811
812         if (s32Error != WILC_SUCCESS) {
813                 PRINT_ER("Failed to get IP address\n");
814                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
815         } else {
816                 PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d \n", idx);
817                 PRINT_INFO(HOSTINF_DBG, "%d.%d.%d.%d\n", gs8GetIP[idx][0], gs8GetIP[idx][1], gs8GetIP[idx][2], gs8GetIP[idx][3]);
818                 PRINT_INFO(HOSTINF_DBG, "\n");
819         }
820
821         WILC_CATCH(s32Error)
822         {
823
824         }
825
826         return s32Error;
827 }
828
829
830 /*BugId_5077*/
831 /**
832  *  @brief Handle_SetMacAddress
833  *  @details    Setting mac address
834  *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
835  *  @return     Error code.
836  *  @author     Amr Abdel-Moghny
837  *  @date               November 2013
838  *  @version    7.0
839  */
840 static s32 Handle_SetMacAddress(void *drvHandler, tstrHostIfSetMacAddress *pstrHostIfSetMacAddress)
841 {
842
843         s32 s32Error = WILC_SUCCESS;
844         tstrWID strWID;
845         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
846         u8 *mac_buf = (u8 *)WILC_MALLOC(ETH_ALEN);
847         if (mac_buf == NULL) {
848                 PRINT_ER("No buffer to send mac address\n");
849                 return WILC_FAIL;
850         }
851         WILC_memcpy(mac_buf, pstrHostIfSetMacAddress->u8MacAddress, ETH_ALEN);
852
853         /*prepare configuration packet*/
854         strWID.u16WIDid = (u16)WID_MAC_ADDR;
855         strWID.enuWIDtype = WID_STR;
856         strWID.ps8WidVal = mac_buf;
857         strWID.s32ValueSize = ETH_ALEN;
858         PRINT_D(GENERIC_DBG, "mac addr = :%x:%x:%x:%x:%x:%x\n", strWID.ps8WidVal[0], strWID.ps8WidVal[1], strWID.ps8WidVal[2], strWID.ps8WidVal[3], strWID.ps8WidVal[4], strWID.ps8WidVal[5]);
859         /*Sending Cfg*/
860         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
861         if (s32Error) {
862                 PRINT_ER("Failed to set mac address\n");
863                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
864         }
865
866         WILC_CATCH(s32Error)
867         {
868
869         }
870         WILC_FREE(mac_buf);
871         return s32Error;
872 }
873
874
875 /*BugID_5213*/
876 /**
877  *  @brief Handle_GetMacAddress
878  *  @details    Getting mac address
879  *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
880  *  @return     Error code.
881  *  @author     Amr Abdel-Moghny
882  *  @date               JAN 2013
883  *  @version    8.0
884  */
885 static s32 Handle_GetMacAddress(void *drvHandler, tstrHostIfGetMacAddress *pstrHostIfGetMacAddress)
886 {
887
888         s32 s32Error = WILC_SUCCESS;
889         tstrWID strWID;
890
891         /*prepare configuration packet*/
892         strWID.u16WIDid = (u16)WID_MAC_ADDR;
893         strWID.enuWIDtype = WID_STR;
894         strWID.ps8WidVal = pstrHostIfGetMacAddress->u8MacAddress;
895         strWID.s32ValueSize = ETH_ALEN;
896
897         /*Sending Cfg*/
898         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, false, (u32)drvHandler);
899         if (s32Error) {
900                 PRINT_ER("Failed to get mac address\n");
901                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
902         }
903         WILC_CATCH(s32Error)
904         {
905
906         }
907         up(&hWaitResponse);
908
909         return s32Error;
910 }
911
912
913 /**
914  *  @brief Handle_CfgParam
915  *  @details    Sending config packet to firmware to set CFG params
916  *  @param[in]   tstrHostIFCfgParamAttr* strHostIFCfgParamAttr
917  *  @return     Error code.
918  *  @author
919  *  @date
920  *  @version    1.0
921  */
922 static s32 Handle_CfgParam(void *drvHandler, tstrHostIFCfgParamAttr *strHostIFCfgParamAttr)
923 {
924         s32 s32Error = WILC_SUCCESS;
925         tstrWID strWIDList[32];
926         u8 u8WidCnt = 0;
927         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
928
929
930         down(&(pstrWFIDrv->gtOsCfgValuesSem));
931
932
933         PRINT_D(HOSTINF_DBG, "Setting CFG params\n");
934
935         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & BSS_TYPE) {
936                 /*----------------------------------------------------------*/
937                 /*Input Value:  INFRASTRUCTURE = 1,                                                     */
938                 /*                              INDEPENDENT= 2,                                                         */
939                 /*                              ANY_BSS= 3                                                                      */
940                 /*----------------------------------------------------------*/
941                 /* validate input then copy>> need to check value 4 and 5 */
942                 if (strHostIFCfgParamAttr->pstrCfgParamVal.bss_type < 6) {
943                         strWIDList[u8WidCnt].u16WIDid = WID_BSS_TYPE;
944                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.bss_type;
945                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
946                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
947                         pstrWFIDrv->strCfgValues.bss_type = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.bss_type;
948                 } else {
949                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
950                 }
951                 u8WidCnt++;
952         }
953         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & AUTH_TYPE) {
954                 /*------------------------------------------------------*/
955                 /*Input Values: OPEN_SYSTEM     = 0,                                    */
956                 /*                              SHARED_KEY      = 1,                                    */
957                 /*                              ANY             = 2                                             */
958                 /*------------------------------------------------------*/
959                 /*validate Possible values*/
960                 if ((strHostIFCfgParamAttr->pstrCfgParamVal.auth_type) == 1 || (strHostIFCfgParamAttr->pstrCfgParamVal.auth_type) == 2 || (strHostIFCfgParamAttr->pstrCfgParamVal.auth_type) == 5) {
961                         strWIDList[u8WidCnt].u16WIDid = WID_AUTH_TYPE;
962                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.auth_type;
963                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
964                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
965                         pstrWFIDrv->strCfgValues.auth_type = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.auth_type;
966                 } else {
967                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
968                 }
969                 u8WidCnt++;
970         }
971         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & AUTHEN_TIMEOUT) {
972                 /* range is 1 to 65535. */
973                 if (strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout < 65536) {
974                         strWIDList[u8WidCnt].u16WIDid = WID_AUTH_TIMEOUT;
975                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout;
976                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
977                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
978                         pstrWFIDrv->strCfgValues.auth_timeout = strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout;
979                 } else {
980                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
981                 }
982                 u8WidCnt++;
983         }
984         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & POWER_MANAGEMENT) {
985                 /*-----------------------------------------------------------*/
986                 /*Input Values: NO_POWERSAVE     = 0,                                           */
987                 /*                              MIN_FAST_PS      = 1,                                           */
988                 /*                              MAX_FAST_PS      = 2,                                           */
989                 /*                              MIN_PSPOLL_PS    = 3,                                           */
990                 /*                              MAX_PSPOLL_PS    = 4                                            */
991                 /*----------------------------------------------------------*/
992                 if (strHostIFCfgParamAttr->pstrCfgParamVal.power_mgmt_mode < 5) {
993                         strWIDList[u8WidCnt].u16WIDid = WID_POWER_MANAGEMENT;
994                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.power_mgmt_mode;
995                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
996                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
997                         pstrWFIDrv->strCfgValues.power_mgmt_mode = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.power_mgmt_mode;
998                 } else {
999                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1000                 }
1001                 u8WidCnt++;
1002         }
1003         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & RETRY_SHORT) {
1004                 /* range from 1 to 256 */
1005                 if ((strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit > 0) && (strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit < 256)) {
1006                         strWIDList[u8WidCnt].u16WIDid = WID_SHORT_RETRY_LIMIT;
1007                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit;
1008                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1009                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1010                         pstrWFIDrv->strCfgValues.short_retry_limit = strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit;
1011                 } else {
1012                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1013                 }
1014                 u8WidCnt++;
1015         }
1016         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & RETRY_LONG) {
1017                 /* range from 1 to 256 */
1018                 if ((strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit > 0) && (strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit < 256)) {
1019                         strWIDList[u8WidCnt].u16WIDid = WID_LONG_RETRY_LIMIT;
1020                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit;
1021
1022                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1023                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1024                         pstrWFIDrv->strCfgValues.long_retry_limit = strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit;
1025                 } else {
1026                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1027                 }
1028                 u8WidCnt++;
1029         }
1030         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & FRAG_THRESHOLD) {
1031
1032                 if (strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold > 255 && strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold < 7937) {
1033                         strWIDList[u8WidCnt].u16WIDid = WID_FRAG_THRESHOLD;
1034                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold;
1035                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1036                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1037                         pstrWFIDrv->strCfgValues.frag_threshold = strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold;
1038                 } else {
1039                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1040                 }
1041                 u8WidCnt++;
1042         }
1043         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & RTS_THRESHOLD) {
1044                 /* range 256 to 65535 */
1045                 if (strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold > 255 && strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold < 65536) {
1046                         strWIDList[u8WidCnt].u16WIDid = WID_RTS_THRESHOLD;
1047                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold;
1048                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1049                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1050                         pstrWFIDrv->strCfgValues.rts_threshold = strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold;
1051                 } else {
1052                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1053                 }
1054                 u8WidCnt++;
1055         }
1056         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & PREAMBLE) {
1057                 /*-----------------------------------------------------*/
1058                 /*Input Values: Short= 0,                                                               */
1059                 /*                              Long= 1,                                */
1060                 /*                              Auto= 2                                                                 */
1061                 /*------------------------------------------------------*/
1062                 if (strHostIFCfgParamAttr->pstrCfgParamVal.preamble_type < 3) {
1063                         strWIDList[u8WidCnt].u16WIDid = WID_PREAMBLE;
1064                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.preamble_type;
1065                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
1066                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
1067                         pstrWFIDrv->strCfgValues.preamble_type = strHostIFCfgParamAttr->pstrCfgParamVal.preamble_type;
1068                 } else {
1069                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1070                 }
1071                 u8WidCnt++;
1072         }
1073         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & SHORT_SLOT_ALLOWED) {
1074                 if (strHostIFCfgParamAttr->pstrCfgParamVal.short_slot_allowed < 2) {
1075                         strWIDList[u8WidCnt].u16WIDid = WID_SHORT_SLOT_ALLOWED;
1076                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.short_slot_allowed;
1077                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
1078                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
1079                         pstrWFIDrv->strCfgValues.short_slot_allowed = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.short_slot_allowed;
1080                 } else {
1081                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1082                 }
1083                 u8WidCnt++;
1084         }
1085         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & TXOP_PROT_DISABLE) {
1086                 /*Description:  used to Disable RTS-CTS protection for TXOP burst*/
1087                 /*transmission when the acknowledgement policy is No-Ack or Block-Ack   */
1088                 /* this information is useful for external supplicant                                   */
1089                 /*Input Values: 1 for enable and 0 for disable.                                                 */
1090                 if (strHostIFCfgParamAttr->pstrCfgParamVal.txop_prot_disabled < 2) {
1091                         strWIDList[u8WidCnt].u16WIDid = WID_11N_TXOP_PROT_DISABLE;
1092                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.txop_prot_disabled;
1093                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
1094                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
1095                         pstrWFIDrv->strCfgValues.txop_prot_disabled = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.txop_prot_disabled;
1096                 } else {
1097                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1098                 }
1099                 u8WidCnt++;
1100         }
1101         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & BEACON_INTERVAL) {
1102                 /* range is 1 to 65535. */
1103                 if (strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval < 65536) {
1104                         strWIDList[u8WidCnt].u16WIDid = WID_BEACON_INTERVAL;
1105                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval;
1106                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1107                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1108                         pstrWFIDrv->strCfgValues.beacon_interval = strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval;
1109                 } else {
1110                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1111                 }
1112                 u8WidCnt++;
1113         }
1114         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & DTIM_PERIOD) {
1115                 /* range is 1 to 255. */
1116                 if (strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period < 256) {
1117                         strWIDList[u8WidCnt].u16WIDid = WID_DTIM_PERIOD;
1118                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period;
1119                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
1120                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
1121                         pstrWFIDrv->strCfgValues.dtim_period = strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period;
1122                 } else {
1123                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1124                 }
1125                 u8WidCnt++;
1126         }
1127         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & SITE_SURVEY) {
1128                 /*----------------------------------------------------------------------*/
1129                 /*Input Values: SITE_SURVEY_1CH    = 0, i.e.: currently set channel             */
1130                 /*                              SITE_SURVEY_ALL_CH = 1,                                                                 */
1131                 /*                              SITE_SURVEY_OFF    = 2                                                                  */
1132                 /*----------------------------------------------------------------------*/
1133                 if (strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_enabled < 3) {
1134                         strWIDList[u8WidCnt].u16WIDid = WID_SITE_SURVEY;
1135                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_enabled;
1136                         strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
1137                         strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
1138                         pstrWFIDrv->strCfgValues.site_survey_enabled = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_enabled;
1139                 } else {
1140                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1141                 }
1142                 u8WidCnt++;
1143         }
1144         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & SITE_SURVEY_SCAN_TIME) {
1145                 /* range is 1 to 65535. */
1146                 if (strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time < 65536) {
1147                         strWIDList[u8WidCnt].u16WIDid = WID_SITE_SURVEY_SCAN_TIME;
1148                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time;
1149                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1150                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1151                         pstrWFIDrv->strCfgValues.site_survey_scan_time = strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time;
1152                 } else {
1153                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1154                 }
1155                 u8WidCnt++;
1156         }
1157         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & ACTIVE_SCANTIME) {
1158                 /* range is 1 to 65535. */
1159                 if (strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time < 65536) {
1160                         strWIDList[u8WidCnt].u16WIDid = WID_ACTIVE_SCAN_TIME;
1161                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time;
1162                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1163                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1164                         pstrWFIDrv->strCfgValues.active_scan_time = strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time;
1165                 } else {
1166                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1167                 }
1168                 u8WidCnt++;
1169         }
1170         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & PASSIVE_SCANTIME) {
1171                 /* range is 1 to 65535. */
1172                 if (strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time < 65536) {
1173                         strWIDList[u8WidCnt].u16WIDid = WID_PASSIVE_SCAN_TIME;
1174                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time;
1175                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1176                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1177                         pstrWFIDrv->strCfgValues.passive_scan_time = strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time;
1178                 } else {
1179                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1180                 }
1181                 u8WidCnt++;
1182         }
1183         if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & CURRENT_TX_RATE) {
1184                 CURRENT_TX_RATE_T curr_tx_rate = strHostIFCfgParamAttr->pstrCfgParamVal.curr_tx_rate;
1185                 /*----------------------------------------------------------------------*/
1186                 /*Rates:                1   2   5.5   11   6  9  12  18  24  36  48   54  Auto  */
1187                 /*InputValues:  1   2     3    4   5  6   7   8   9  10  11   12  0             */
1188                 /*----------------------------------------------------------------------*/
1189                 /* validate rate */
1190                 if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1
1191                     || curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5
1192                     || curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6
1193                     || curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12
1194                     || curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24
1195                     || curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 || curr_tx_rate == MBPS_54) {
1196                         strWIDList[u8WidCnt].u16WIDid = WID_CURRENT_TX_RATE;
1197                         strWIDList[u8WidCnt].ps8WidVal = (s8 *)&curr_tx_rate;
1198                         strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
1199                         strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
1200                         pstrWFIDrv->strCfgValues.curr_tx_rate = (u8)curr_tx_rate;
1201                 } else {
1202                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
1203                 }
1204                 u8WidCnt++;
1205         }
1206         s32Error = SendConfigPkt(SET_CFG, strWIDList, u8WidCnt, false, (u32)pstrWFIDrv);
1207
1208         if (s32Error) {
1209                 PRINT_ER("Error in setting CFG params\n");
1210
1211         }
1212         WILC_CATCH(s32Error)
1213         {
1214         }
1215         up(&(pstrWFIDrv->gtOsCfgValuesSem));
1216         return s32Error;
1217 }
1218
1219
1220 /**
1221  *  @brief Handle_wait_msg_q_empty
1222  *  @details       this should be the last msg and then the msg Q becomes idle
1223  *  @param[in]    tstrHostIFscanAttr* pstrHostIFscanAttr
1224  *  @return         Error code.
1225  *  @author
1226  *  @date
1227  *  @version    1.0
1228  */
1229 static s32 Handle_wait_msg_q_empty(void)
1230 {
1231         s32 s32Error = WILC_SUCCESS;
1232         g_wilc_initialized = 0;
1233         up(&hWaitResponse);
1234         return s32Error;
1235 }
1236
1237 /**
1238  *  @brief Handle_Scan
1239  *  @details       Sending config packet to firmware to set the scan params
1240  *  @param[in]    tstrHostIFscanAttr* pstrHostIFscanAttr
1241  *  @return         Error code.
1242  *  @author
1243  *  @date
1244  *  @version    1.0
1245  */
1246 static s32 Handle_Scan(void *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
1247 {
1248         s32 s32Error = WILC_SUCCESS;
1249         tstrWID strWIDList[5];
1250         u32 u32WidsCount = 0;
1251         u32 i;
1252         u8 *pu8Buffer;
1253         u8 valuesize = 0;
1254         u8 *pu8HdnNtwrksWidVal = NULL;
1255         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
1256
1257         PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
1258         PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state \n", pstrWFIDrv->enuHostIFstate);
1259
1260         pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = pstrHostIFscanAttr->pfScanResult;
1261         pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid = pstrHostIFscanAttr->pvUserArg;
1262
1263         #ifdef WILC_P2P
1264         #if 0
1265         if (pstrWFIDrv->enuHostIFstate == HOST_IF_P2P_LISTEN || (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED && pstrWFIDrv->u8P2PConnect)) {
1266                 PRINT_INFO(GENERIC_DBG, "Busy: State: %d\n", pstrWFIDrv->enuHostIFstate);
1267                 PRINT_INFO(GENERIC_DBG, "Current Jiffies: %lu Timeout:%llu\n", jiffies, pstrWFIDrv->u64P2p_MgmtTimeout);
1268                 WILC_ERRORREPORT(s32Error, WILC_BUSY);
1269         }
1270         #endif
1271         #endif
1272
1273         if ((pstrWFIDrv->enuHostIFstate >= HOST_IF_SCANNING) && (pstrWFIDrv->enuHostIFstate < HOST_IF_CONNECTED)) {
1274                 /* here we either in HOST_IF_SCANNING, HOST_IF_WAITING_CONN_REQ or HOST_IF_WAITING_CONN_RESP */
1275                 PRINT_D(GENERIC_DBG, "Don't scan we are already in [%d] state\n", pstrWFIDrv->enuHostIFstate);
1276                 WILC_ERRORREPORT(s32Error, WILC_BUSY);
1277         }
1278
1279         #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
1280         if (g_obtainingIP || connecting) {
1281                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
1282                 WILC_ERRORREPORT(s32Error, WILC_BUSY);
1283         }
1284         #endif
1285
1286         PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
1287
1288
1289         pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount = 0;
1290
1291         /*BugID_4189*/
1292         strWIDList[u32WidsCount].u16WIDid = (u16)WID_SSID_PROBE_REQ;
1293         strWIDList[u32WidsCount].enuWIDtype = WID_STR;
1294
1295         for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++) {
1296                 valuesize += ((pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen) + 1);
1297         }
1298         pu8HdnNtwrksWidVal = WILC_MALLOC(valuesize + 1);
1299         strWIDList[u32WidsCount].ps8WidVal = pu8HdnNtwrksWidVal;
1300         if (strWIDList[u32WidsCount].ps8WidVal != NULL) {
1301                 pu8Buffer = strWIDList[u32WidsCount].ps8WidVal;
1302
1303                 *pu8Buffer++ = pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum;
1304
1305                 PRINT_D(HOSTINF_DBG, "In Handle_ProbeRequest number of ssid %d\n", pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum);
1306
1307                 for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++) {
1308                         *pu8Buffer++ = pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen;
1309                         WILC_memcpy(pu8Buffer, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen);
1310                         pu8Buffer += pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen;
1311                 }
1312
1313
1314
1315                 strWIDList[u32WidsCount].s32ValueSize =  (s32)(valuesize + 1);
1316                 u32WidsCount++;
1317         }
1318
1319         /*filling cfg param array*/
1320
1321         /* if((pstrHostIFscanAttr->pu8IEs != NULL) && (pstrHostIFscanAttr->IEsLen != 0)) */
1322         {
1323                 /* IEs to be inserted in Probe Request */
1324                 strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_PROBE;
1325                 strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
1326                 strWIDList[u32WidsCount].ps8WidVal = pstrHostIFscanAttr->pu8IEs;
1327                 strWIDList[u32WidsCount].s32ValueSize = pstrHostIFscanAttr->IEsLen;
1328                 u32WidsCount++;
1329         }
1330
1331         /*Scan Type*/
1332         strWIDList[u32WidsCount].u16WIDid = WID_SCAN_TYPE;
1333         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1334         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1335         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrHostIFscanAttr->u8ScanType));
1336         u32WidsCount++;
1337
1338         /*list of channels to be scanned*/
1339         strWIDList[u32WidsCount].u16WIDid = WID_SCAN_CHANNEL_LIST;
1340         strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
1341
1342         /* Bug 4648: Convert channel numbers to start from 0 not 1. */
1343         if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL && pstrHostIFscanAttr->u8ChnlListLen > 0) {
1344                 int i;
1345
1346                 for (i = 0; i < pstrHostIFscanAttr->u8ChnlListLen; i++) {
1347                         if (pstrHostIFscanAttr->pu8ChnlFreqList[i] > 0) {
1348                                 pstrHostIFscanAttr->pu8ChnlFreqList[i] = pstrHostIFscanAttr->pu8ChnlFreqList[i] - 1;
1349                         }
1350                 }
1351         }
1352
1353         strWIDList[u32WidsCount].ps8WidVal = pstrHostIFscanAttr->pu8ChnlFreqList;
1354         strWIDList[u32WidsCount].s32ValueSize = pstrHostIFscanAttr->u8ChnlListLen;
1355         u32WidsCount++;
1356
1357         /*Scan Request*/
1358         strWIDList[u32WidsCount].u16WIDid = WID_START_SCAN_REQ;
1359         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1360         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1361         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrHostIFscanAttr->u8ScanSource));
1362         u32WidsCount++;
1363
1364         /*keep the state as is , no need to change it*/
1365         /* gWFiDrvHandle->enuHostIFstate = HOST_IF_SCANNING; */
1366
1367         if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) {
1368                 gbScanWhileConnected = true;
1369         } else if (pstrWFIDrv->enuHostIFstate == HOST_IF_IDLE)    {
1370                 gbScanWhileConnected = false;
1371         }
1372
1373         s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
1374
1375         if (s32Error) {
1376                 PRINT_ER("Failed to send scan paramters config packet\n");
1377                 WILC_ERRORREPORT(s32Error, s32Error);
1378         } else {
1379                 PRINT_D(HOSTINF_DBG, "Successfully sent SCAN params config packet\n");
1380         }
1381
1382         WILC_CATCH(s32Error)
1383         {
1384                 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL);
1385                 /*if there is an ongoing scan request*/
1386                 Handle_ScanDone(drvHandler, SCAN_EVENT_ABORTED);
1387         }
1388
1389         /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */
1390         if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) {
1391                 WILC_FREE(pstrHostIFscanAttr->pu8ChnlFreqList);
1392                 pstrHostIFscanAttr->pu8ChnlFreqList = NULL;
1393         }
1394
1395         /* Deallocate pstrHostIFscanAttr->pu8IEs which was previously allocated by the sending thread */
1396         if (pstrHostIFscanAttr->pu8IEs != NULL) {
1397                 WILC_FREE(pstrHostIFscanAttr->pu8IEs);
1398                 pstrHostIFscanAttr->pu8IEs = NULL;
1399         }
1400         if (pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo != NULL) {
1401                 WILC_FREE(pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo);
1402                 pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo = NULL;
1403         }
1404
1405         /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */
1406         if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) {
1407                 WILC_FREE(pstrHostIFscanAttr->pu8ChnlFreqList);
1408                 pstrHostIFscanAttr->pu8ChnlFreqList = NULL;
1409         }
1410
1411         if (pu8HdnNtwrksWidVal != NULL) {
1412                 WILC_FREE(pu8HdnNtwrksWidVal);
1413         }
1414
1415         return s32Error;
1416 }
1417
1418 /**
1419  *  @brief Handle_ScanDone
1420  *  @details       Call scan notification callback function
1421  *  @param[in]    NONE
1422  *  @return         Error code.
1423  *  @author
1424  *  @date
1425  *  @version    1.0
1426  */
1427 static s32 Handle_ScanDone(void *drvHandler, tenuScanEvent enuEvent)
1428 {
1429         s32 s32Error = WILC_SUCCESS;
1430
1431         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
1432
1433
1434         u8 u8abort_running_scan;
1435         tstrWID strWID;
1436
1437
1438         PRINT_D(HOSTINF_DBG, "in Handle_ScanDone()\n");
1439
1440         /*BugID_4978*/
1441         /*Ask FW to abort the running scan, if any*/
1442         if (enuEvent == SCAN_EVENT_ABORTED) {
1443                 PRINT_D(GENERIC_DBG, "Abort running scan\n");
1444                 u8abort_running_scan = 1;
1445                 strWID.u16WIDid = (u16)WID_ABORT_RUNNING_SCAN;
1446                 strWID.enuWIDtype       = WID_CHAR;
1447                 strWID.ps8WidVal = (s8 *)&u8abort_running_scan;
1448                 strWID.s32ValueSize = sizeof(char);
1449
1450                 /*Sending Cfg*/
1451                 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
1452                 if (s32Error != WILC_SUCCESS) {
1453                         PRINT_ER("Failed to set abort running scan\n");
1454                         WILC_ERRORREPORT(s32Error, WILC_FAIL);
1455                 }
1456                 WILC_CATCH(s32Error)
1457                 {
1458                 }
1459         }
1460
1461         if (pstrWFIDrv == NULL) {
1462                 PRINT_ER("Driver handler is NULL\n");
1463                 return s32Error;
1464         }
1465
1466         /*if there is an ongoing scan request*/
1467         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
1468                 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(enuEvent, NULL,
1469                                                                 pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
1470                 /*delete current scan request*/
1471                 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
1472         }
1473
1474         return s32Error;
1475 }
1476
1477 /**
1478  *  @brief Handle_Connect
1479  *  @details       Sending config packet to firmware to starting connection
1480  *  @param[in]    tstrHostIFconnectAttr* pstrHostIFconnectAttr
1481  *  @return         Error code.
1482  *  @author
1483  *  @date
1484  *  @version    1.0
1485  */
1486 u8 u8ConnectedSSID[6] = {0};
1487 static s32 Handle_Connect(void *drvHandler, tstrHostIFconnectAttr *pstrHostIFconnectAttr)
1488 {
1489         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
1490         s32 s32Error = WILC_SUCCESS;
1491         tstrWID strWIDList[8];
1492         u32 u32WidsCount = 0, dummyval = 0;
1493         /* char passphrase[] = "12345678"; */
1494         #ifndef CONNECT_DIRECT
1495         s32 s32Err = WILC_SUCCESS;
1496         u32 i;
1497         u8 u8bssDscListIndex;
1498         wid_site_survey_reslts_s *pstrSurveyResults = NULL;
1499         #else
1500         u8 *pu8CurrByte = NULL;
1501         /*Bug4218: Parsing Join Param*/
1502         #ifdef WILC_PARSE_SCAN_IN_HOST
1503         tstrJoinBssParam *ptstrJoinBssParam;
1504         #endif /*WILC_PARSE_SCAN_IN_HOST*/
1505
1506         #endif
1507
1508         PRINT_D(GENERIC_DBG, "Handling connect request\n");
1509
1510         #ifndef CONNECT_DIRECT
1511         WILC_memset(gapu8RcvdSurveyResults[0], 0, MAX_SURVEY_RESULT_FRAG_SIZE);
1512         WILC_memset(gapu8RcvdSurveyResults[1], 0, MAX_SURVEY_RESULT_FRAG_SIZE);
1513
1514
1515         PRINT_D(HOSTINF_DBG, "Getting site survey results\n");
1516         s32Err = host_int_get_site_survey_results((WILC_WFIDrvHandle)pstrWFIDrv,
1517                                                   gapu8RcvdSurveyResults,
1518                                                   MAX_SURVEY_RESULT_FRAG_SIZE);
1519         if (s32Err) {
1520                 PRINT_ER("Failed to get site survey results\n");
1521                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
1522
1523         }
1524         s32Err = ParseSurveyResults(gapu8RcvdSurveyResults, &pstrSurveyResults,
1525                                     &pstrWFIDrv->u32SurveyResultsCount);
1526
1527
1528         if (s32Err == WILC_SUCCESS) {
1529                 /* use the parsed info in pstrSurveyResults, then deallocate it */
1530                 PRINT_D(HOSTINF_DBG, "Copying site survey results in global structure, then deallocate\n");
1531                 for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) {
1532                         WILC_memcpy(&pstrWFIDrv->astrSurveyResults[i], &pstrSurveyResults[i],
1533                                     sizeof(wid_site_survey_reslts_s));
1534                 }
1535
1536                 DeallocateSurveyResults(pstrSurveyResults);
1537         } else {
1538                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
1539                 PRINT_ER("ParseSurveyResults() Error(%d) \n", s32Err);
1540         }
1541
1542
1543         for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) {
1544                 if (WILC_memcmp(pstrWFIDrv->astrSurveyResults[i].SSID,
1545                                 pstrHostIFconnectAttr->pu8ssid,
1546                                 pstrHostIFconnectAttr->ssidLen) == 0) {
1547                         PRINT_INFO(HOSTINF_DBG, "Network with required SSID is found %s\n", pstrHostIFconnectAttr->pu8ssid);
1548                         if (pstrHostIFconnectAttr->pu8bssid == NULL) {
1549                                 /* BSSID is not passed from the user, so decision of matching
1550                                  * is done by SSID only */
1551                                 PRINT_INFO(HOSTINF_DBG, "BSSID is not passed from the user\n");
1552                                 break;
1553                         } else {
1554                                 /* BSSID is also passed from the user, so decision of matching
1555                                  * should consider also this passed BSSID */
1556
1557                                 if (WILC_memcmp(pstrWFIDrv->astrSurveyResults[i].BSSID,
1558                                                 pstrHostIFconnectAttr->pu8bssid,
1559                                                 6) == 0) {
1560                                         PRINT_INFO(HOSTINF_DBG, "BSSID is passed from the user and matched\n");
1561                                         break;
1562                                 }
1563                         }
1564                 }
1565         }
1566
1567         if (i < pstrWFIDrv->u32SurveyResultsCount) {
1568                 u8bssDscListIndex = i;
1569
1570                 PRINT_INFO(HOSTINF_DBG, "Connecting to network of Bss Idx %d and SSID %s and channel %d \n",
1571                            u8bssDscListIndex, pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].SSID,
1572                            pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].Channel);
1573
1574                 PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
1575
1576                 if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1577                         pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = (u8 *)WILC_MALLOC(6);
1578                         WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1579                 }
1580
1581                 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
1582                 if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1583                         pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1);
1584                         WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
1585                                     pstrHostIFconnectAttr->ssidLen);
1586                         pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
1587                 }
1588
1589                 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1590                 if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1591                         pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
1592                         WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
1593                                     pstrHostIFconnectAttr->IEsLen);
1594                 }
1595
1596                 pstrWFIDrv->strWILC_UsrConnReq.u8security = pstrHostIFconnectAttr->u8security;
1597                 pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type = pstrHostIFconnectAttr->tenuAuth_type;
1598                 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult = pstrHostIFconnectAttr->pfConnectResult;
1599                 pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid = pstrHostIFconnectAttr->pvUserArg;
1600
1601
1602                 /* if((gWFiDrvHandle->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) && */
1603                 /* (gWFiDrvHandle->strWILC_UsrConnReq.ConnReqIEsLen != 0)) */
1604                 {
1605                         /* IEs to be inserted in Association Request */
1606                         strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_ASSOCIATE;
1607                         strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
1608                         strWIDList[u32WidsCount].ps8WidVal = pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs;
1609                         strWIDList[u32WidsCount].s32ValueSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
1610                         u32WidsCount++;
1611                 }
1612                 strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_MODE;
1613                 strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1614                 strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1615                 strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrWFIDrv->strWILC_UsrConnReq.u8security));
1616                 u32WidsCount++;
1617
1618                 PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", pstrWFIDrv->strWILC_UsrConnReq.u8security);
1619
1620                 strWIDList[u32WidsCount].u16WIDid = (u16)WID_AUTH_TYPE;
1621                 strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1622                 strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1623                 strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
1624                 u32WidsCount++;
1625
1626                 PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
1627                 /*
1628                  * strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_PSK;
1629                  * strWIDList[u32WidsCount].enuWIDtype = WID_STR;
1630                  * strWIDList[u32WidsCount].s32ValueSize = sizeof(passphrase);
1631                  * strWIDList[u32WidsCount].ps8WidVal = (s8*)(passphrase);
1632                  * u32WidsCount++;
1633                  */
1634
1635                 strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ;
1636                 strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1637                 strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1638                 strWIDList[u32WidsCount].ps8WidVal = (s8 *)&u8bssDscListIndex;
1639                 u32WidsCount++;
1640
1641                 #ifndef SIMULATION
1642                 /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the
1643                  *   firmware at chip reset when processing the WIDs of the Connect Request.
1644                  *   (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */
1645                 /* ////////////////////// */
1646                 gu32WidConnRstHack = 0;
1647                 /* ////////////////////// */
1648                 #endif
1649
1650                 s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
1651                 if (s32Error) {
1652                         PRINT_ER("Handle_Connect()] failed to send config packet\n");
1653                         WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
1654                 } else {
1655                         pstrWFIDrv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
1656                 }
1657
1658         } else {
1659                 PRINT_ER("Required BSSID not found\n");
1660                 WILC_ERRORREPORT(s32Error, WILC_NOT_FOUND);
1661         }
1662
1663         #else
1664
1665         /* if we try to connect to an already connected AP then discard the request */
1666
1667         if (WILC_memcmp(pstrHostIFconnectAttr->pu8bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
1668
1669                 s32Error = WILC_SUCCESS;
1670                 PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n");
1671                 return s32Error;
1672         }
1673
1674         PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
1675
1676         /*Bug4218: Parsing Join Param*/
1677         #ifdef WILC_PARSE_SCAN_IN_HOST
1678         ptstrJoinBssParam = (tstrJoinBssParam *)pstrHostIFconnectAttr->pJoinParams;
1679         if (ptstrJoinBssParam == NULL) {
1680                 PRINT_ER("Required BSSID not found\n");
1681                 WILC_ERRORREPORT(s32Error, WILC_NOT_FOUND);
1682         }
1683         #endif /*WILC_PARSE_SCAN_IN_HOST*/
1684
1685 #if 0
1686         /* if we try to connect to an already connected AP then discard the request */
1687         PRINT_D(GENERIC_DBG, "Bssid = %x:%x:%x:%x:%x:%x\n", (pstrHostIFconnectAttr->pu8bssid[0]), (pstrHostIFconnectAttr->pu8bssid[1]), (pstrHostIFconnectAttr->pu8bssid[2]), (pstrHostIFconnectAttr->pu8bssid[3]), (pstrHostIFconnectAttr->pu8bssid[4]), (pstrHostIFconnectAttr->pu8bssid[5]));
1688         PRINT_D(GENERIC_DBG, "bssid = %x:%x:%x:%x:%x:%x\n", (u8ConnectedSSID[0]), (u8ConnectedSSID[1]), (u8ConnectedSSID[2]), (u8ConnectedSSID[3]), (u8ConnectedSSID[4]), (u8ConnectedSSID[5]));
1689         if (WILC_memcmp(pstrHostIFconnectAttr->pu8bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
1690                 PRINT_ER("Discard connect request\n");
1691                 s32Error = WILC_FAIL;
1692                 return s32Error;
1693         }
1694 #endif
1695
1696         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1697                 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = (u8 *)WILC_MALLOC(6);
1698                 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1699         }
1700
1701         pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
1702         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1703                 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1);
1704                 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
1705                             pstrHostIFconnectAttr->ssidLen);
1706                 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
1707         }
1708
1709         pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1710         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1711                 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
1712                 WILC_memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
1713                             pstrHostIFconnectAttr->IEsLen);
1714         }
1715
1716         pstrWFIDrv->strWILC_UsrConnReq.u8security = pstrHostIFconnectAttr->u8security;
1717         pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type = pstrHostIFconnectAttr->tenuAuth_type;
1718         pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult = pstrHostIFconnectAttr->pfConnectResult;
1719         pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid = pstrHostIFconnectAttr->pvUserArg;
1720
1721         strWIDList[u32WidsCount].u16WIDid = WID_SUCCESS_FRAME_COUNT;
1722         strWIDList[u32WidsCount].enuWIDtype = WID_INT;
1723         strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
1724         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(dummyval));
1725         u32WidsCount++;
1726
1727         strWIDList[u32WidsCount].u16WIDid = WID_RECEIVED_FRAGMENT_COUNT;
1728         strWIDList[u32WidsCount].enuWIDtype = WID_INT;
1729         strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
1730         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(dummyval));
1731         u32WidsCount++;
1732
1733         strWIDList[u32WidsCount].u16WIDid = WID_FAILED_COUNT;
1734         strWIDList[u32WidsCount].enuWIDtype = WID_INT;
1735         strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
1736         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(dummyval));
1737         u32WidsCount++;
1738
1739         /* if((gWFiDrvHandle->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) && */
1740         /* (gWFiDrvHandle->strWILC_UsrConnReq.ConnReqIEsLen != 0)) */
1741         {
1742                 /* IEs to be inserted in Association Request */
1743                 strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_ASSOCIATE;
1744                 strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
1745                 strWIDList[u32WidsCount].ps8WidVal = pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs;
1746                 strWIDList[u32WidsCount].s32ValueSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
1747                 u32WidsCount++;
1748
1749                 /*BugID_5137*/
1750                 if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1751
1752                         gu32FlushedInfoElemAsocSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
1753                         gu8FlushedInfoElemAsoc =  WILC_MALLOC(gu32FlushedInfoElemAsocSize);
1754                         memcpy(gu8FlushedInfoElemAsoc, pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
1755                                gu32FlushedInfoElemAsocSize);
1756                 }
1757         }
1758         strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_MODE;
1759         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1760         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1761         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrWFIDrv->strWILC_UsrConnReq.u8security));
1762         u32WidsCount++;
1763
1764         /*BugID_5137*/
1765         if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
1766                 gu8Flushed11iMode = pstrWFIDrv->strWILC_UsrConnReq.u8security;
1767
1768         PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", pstrWFIDrv->strWILC_UsrConnReq.u8security);
1769
1770
1771         strWIDList[u32WidsCount].u16WIDid = (u16)WID_AUTH_TYPE;
1772         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
1773         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
1774         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
1775         u32WidsCount++;
1776
1777         /*BugID_5137*/
1778         if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
1779                 gu8FlushedAuthType = (u8)pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type;
1780
1781         PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
1782         /*
1783          * strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_PSK;
1784          * strWIDList[u32WidsCount].enuWIDtype = WID_STR;
1785          * strWIDList[u32WidsCount].s32ValueSize = sizeof(passphrase);
1786          * strWIDList[u32WidsCount].ps8WidVal = (s8*)(passphrase);
1787          * u32WidsCount++;
1788          */
1789
1790         PRINT_D(HOSTINF_DBG, "Connecting to network of SSID %s on channel %d\n",
1791                 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->u8channel);
1792
1793
1794 #ifndef WILC_PARSE_SCAN_IN_HOST
1795         strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ_EXTENDED;
1796         strWIDList[u32WidsCount].enuWIDtype = WID_STR;
1797         strWIDList[u32WidsCount].s32ValueSize = MAX_SSID_LEN + 7;
1798         strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize);
1799
1800         if (strWIDList[u32WidsCount].ps8WidVal == NULL) {
1801                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
1802         }
1803
1804         pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
1805
1806         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1807                 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
1808                 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
1809         }
1810         pu8CurrByte += MAX_SSID_LEN;
1811         if ((pstrHostIFconnectAttr->u8channel >= 1) && (pstrHostIFconnectAttr->u8channel <= 14)) {
1812                 *(pu8CurrByte++) = pstrHostIFconnectAttr->u8channel;
1813         } else {
1814                 PRINT_ER("Channel out of range\n");
1815                 *(pu8CurrByte++) = 0xFF;
1816         }
1817         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1818                 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1819         }
1820         pu8CurrByte += 6;
1821
1822         /* keep the buffer at the start of the allocated pointer to use it with the free*/
1823         pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
1824
1825         #else
1826
1827         strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ_EXTENDED;
1828         strWIDList[u32WidsCount].enuWIDtype = WID_STR;
1829
1830         /*Sending NoA attributes during connection*/
1831         strWIDList[u32WidsCount].s32ValueSize = 112; /* 79; */
1832         strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize);
1833
1834         /*BugID_5137*/
1835         if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1836                 gu32FlushedJoinReqSize = strWIDList[u32WidsCount].s32ValueSize;
1837                 gu8FlushedJoinReq = WILC_MALLOC(gu32FlushedJoinReqSize);
1838         }
1839         if (strWIDList[u32WidsCount].ps8WidVal == NULL) {
1840                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
1841         }
1842
1843         pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
1844
1845
1846         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1847                 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
1848                 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
1849         }
1850         pu8CurrByte += MAX_SSID_LEN;
1851
1852         /* BSS type*/
1853         *(pu8CurrByte++) = INFRASTRUCTURE;
1854         /* Channel*/
1855         if ((pstrHostIFconnectAttr->u8channel >= 1) && (pstrHostIFconnectAttr->u8channel <= 14)) {
1856                 *(pu8CurrByte++) = pstrHostIFconnectAttr->u8channel;
1857         } else {
1858                 PRINT_ER("Channel out of range\n");
1859                 *(pu8CurrByte++) = 0xFF;
1860         }
1861         /* Cap Info*/
1862         *(pu8CurrByte++)  = (ptstrJoinBssParam->cap_info) & 0xFF;
1863         *(pu8CurrByte++)  = ((ptstrJoinBssParam->cap_info) >> 8) & 0xFF;
1864         PRINT_D(HOSTINF_DBG, "* Cap Info %0x*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1865
1866         /* sa*/
1867         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1868                 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1869         }
1870         pu8CurrByte += 6;
1871
1872         /* bssid*/
1873         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1874                 WILC_memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1875         }
1876         pu8CurrByte += 6;
1877
1878         /* Beacon Period*/
1879         *(pu8CurrByte++)  = (ptstrJoinBssParam->beacon_period) & 0xFF;
1880         *(pu8CurrByte++)  = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
1881         PRINT_D(HOSTINF_DBG, "* Beacon Period %d*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1882         /* DTIM Period*/
1883         *(pu8CurrByte++)  =  ptstrJoinBssParam->dtim_period;
1884         PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1)));
1885         /* Supported rates*/
1886         WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1887         pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1888
1889         /* wmm cap*/
1890         *(pu8CurrByte++)  =  ptstrJoinBssParam->wmm_cap;
1891         PRINT_D(HOSTINF_DBG, "* wmm cap%d*\n", (*(pu8CurrByte - 1)));
1892         /* uapsd cap*/
1893         *(pu8CurrByte++)  = ptstrJoinBssParam->uapsd_cap;
1894
1895         /* ht cap*/
1896         *(pu8CurrByte++)  = ptstrJoinBssParam->ht_capable;
1897         /* copy this information to the user request */
1898         pstrWFIDrv->strWILC_UsrConnReq.IsHTCapable = ptstrJoinBssParam->ht_capable;
1899
1900         /* rsn found*/
1901         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_found;
1902         PRINT_D(HOSTINF_DBG, "* rsn found %d*\n", *(pu8CurrByte - 1));
1903         /* rsn group policy*/
1904         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_grp_policy;
1905         PRINT_D(HOSTINF_DBG, "* rsn group policy %0x*\n", (*(pu8CurrByte - 1)));
1906         /* mode_802_11i*/
1907         *(pu8CurrByte++) =  ptstrJoinBssParam->mode_802_11i;
1908         PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1)));
1909         /* rsn pcip policy*/
1910         WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1911         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1912
1913         /* rsn auth policy*/
1914         WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1915         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1916
1917         /* rsn auth policy*/
1918         WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1919         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1920
1921         /*BugID_5137*/
1922         *(pu8CurrByte++) = REAL_JOIN_REQ;
1923
1924                 #ifdef WILC_P2P
1925         *(pu8CurrByte++) = ptstrJoinBssParam->u8NoaEnbaled;
1926         if (ptstrJoinBssParam->u8NoaEnbaled) {
1927                 PRINT_D(HOSTINF_DBG, "NOA present\n");
1928
1929                 *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
1930                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 8) & 0xFF;
1931                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
1932                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
1933
1934                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Index;
1935
1936                 *(pu8CurrByte++) = ptstrJoinBssParam->u8OppEnable;
1937
1938                 if (ptstrJoinBssParam->u8OppEnable)
1939                         *(pu8CurrByte++) = ptstrJoinBssParam->u8CtWindow;
1940
1941                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Count;
1942
1943                 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration));
1944
1945                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration);
1946
1947                 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval));
1948
1949                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval);
1950
1951                 WILC_memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime));
1952
1953                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime);
1954
1955         } else
1956                 PRINT_D(HOSTINF_DBG, "NOA not present\n");
1957         #endif
1958
1959
1960         /* keep the buffer at the start of the allocated pointer to use it with the free*/
1961         pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
1962
1963
1964         #endif /* #ifdef WILC_PARSE_SCAN_IN_HOST*/
1965         u32WidsCount++;
1966
1967         #ifndef SIMULATION
1968         /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the
1969          *   firmware at chip reset when processing the WIDs of the Connect Request.
1970          *   (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */
1971         /* ////////////////////// */
1972         gu32WidConnRstHack = 0;
1973         /* ////////////////////// */
1974         #endif
1975
1976         /*BugID_5137*/
1977         if (WILC_memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1978                 memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize);
1979                 gu8FlushedJoinReqDrvHandler = (u32)pstrWFIDrv;
1980         }
1981
1982         PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
1983
1984         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1985                 WILC_memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->pu8bssid, ETH_ALEN);
1986
1987                 PRINT_D(GENERIC_DBG, "save Bssid = %x:%x:%x:%x:%x:%x\n", (pstrHostIFconnectAttr->pu8bssid[0]), (pstrHostIFconnectAttr->pu8bssid[1]), (pstrHostIFconnectAttr->pu8bssid[2]), (pstrHostIFconnectAttr->pu8bssid[3]), (pstrHostIFconnectAttr->pu8bssid[4]), (pstrHostIFconnectAttr->pu8bssid[5]));
1988                 PRINT_D(GENERIC_DBG, "save bssid = %x:%x:%x:%x:%x:%x\n", (u8ConnectedSSID[0]), (u8ConnectedSSID[1]), (u8ConnectedSSID[2]), (u8ConnectedSSID[3]), (u8ConnectedSSID[4]), (u8ConnectedSSID[5]));
1989         }
1990
1991         s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
1992         if (s32Error) {
1993                 PRINT_ER("Handle_Connect()] failed to send config packet\n");
1994                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
1995         } else {
1996                 PRINT_D(GENERIC_DBG, "set HOST_IF_WAITING_CONN_RESP\n");
1997                 pstrWFIDrv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
1998         }
1999         #endif
2000
2001         WILC_CATCH(s32Error)
2002         {
2003                 tstrConnectInfo strConnectInfo;
2004
2005                 WILC_TimerStop(&(pstrWFIDrv->hConnectTimer), NULL);
2006
2007                 PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n");
2008
2009                 WILC_memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
2010
2011                 if (pstrHostIFconnectAttr->pfConnectResult != NULL) {
2012                         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
2013                                 WILC_memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
2014                         }
2015
2016                         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
2017                                 strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->IEsLen;
2018                                 strConnectInfo.pu8ReqIEs = (u8 *)WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
2019                                 WILC_memcpy(strConnectInfo.pu8ReqIEs,
2020                                             pstrHostIFconnectAttr->pu8IEs,
2021                                             pstrHostIFconnectAttr->IEsLen);
2022                         }
2023
2024                         pstrHostIFconnectAttr->pfConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
2025                                                                &strConnectInfo,
2026                                                                MAC_DISCONNECTED,
2027                                                                NULL,
2028                                                                pstrHostIFconnectAttr->pvUserArg);
2029                         /*Change state to idle*/
2030                         pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
2031                         /* Deallocation */
2032                         if (strConnectInfo.pu8ReqIEs != NULL) {
2033                                 WILC_FREE(strConnectInfo.pu8ReqIEs);
2034                                 strConnectInfo.pu8ReqIEs = NULL;
2035                         }
2036
2037                 } else {
2038                         PRINT_ER("Connect callback function pointer is NULL \n");
2039                 }
2040         }
2041
2042         PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n");
2043         /* Deallocate pstrHostIFconnectAttr->pu8bssid which was prevoisuly allocated by the sending thread */
2044         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
2045                 WILC_FREE(pstrHostIFconnectAttr->pu8bssid);
2046                 pstrHostIFconnectAttr->pu8bssid = NULL;
2047         }
2048
2049         /* Deallocate pstrHostIFconnectAttr->pu8ssid which was prevoisuly allocated by the sending thread */
2050         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
2051                 WILC_FREE(pstrHostIFconnectAttr->pu8ssid);
2052                 pstrHostIFconnectAttr->pu8ssid = NULL;
2053         }
2054
2055         /* Deallocate pstrHostIFconnectAttr->pu8IEs which was prevoisuly allocated by the sending thread */
2056         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
2057                 WILC_FREE(pstrHostIFconnectAttr->pu8IEs);
2058                 pstrHostIFconnectAttr->pu8IEs = NULL;
2059         }
2060
2061         if (pu8CurrByte != NULL) {
2062                 WILC_FREE(pu8CurrByte);
2063         }
2064         return s32Error;
2065 }
2066
2067 /**
2068  *  @brief                      Handle_FlushConnect
2069  *  @details            Sending config packet to firmware to flush an old connection
2070  *                              after switching FW from station one to hybrid one
2071  *  @param[in]          void * drvHandler
2072  *  @return             Error code.
2073  *  @author             Amr Abdel-Moghny
2074  *  @date                       19 DEC 2013
2075  *  @version            8.0
2076  */
2077
2078 static s32 Handle_FlushConnect(void *drvHandler)
2079 {
2080         s32 s32Error = WILC_SUCCESS;
2081         tstrWID strWIDList[5];
2082         u32 u32WidsCount = 0;
2083         u8 *pu8CurrByte = NULL;
2084
2085
2086         /* IEs to be inserted in Association Request */
2087         strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_ASSOCIATE;
2088         strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
2089         strWIDList[u32WidsCount].ps8WidVal = gu8FlushedInfoElemAsoc;
2090         strWIDList[u32WidsCount].s32ValueSize = gu32FlushedInfoElemAsocSize;
2091         u32WidsCount++;
2092
2093         strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_MODE;
2094         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
2095         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
2096         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(gu8Flushed11iMode));
2097         u32WidsCount++;
2098
2099
2100
2101         strWIDList[u32WidsCount].u16WIDid = (u16)WID_AUTH_TYPE;
2102         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
2103         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
2104         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&gu8FlushedAuthType);
2105         u32WidsCount++;
2106
2107
2108         #ifdef WILC_PARSE_SCAN_IN_HOST
2109         strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ_EXTENDED;
2110         strWIDList[u32WidsCount].enuWIDtype = WID_STR;
2111         strWIDList[u32WidsCount].s32ValueSize = gu32FlushedJoinReqSize;
2112         strWIDList[u32WidsCount].ps8WidVal = (s8 *)gu8FlushedJoinReq;
2113         pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
2114
2115         pu8CurrByte += FLUSHED_BYTE_POS;
2116         *(pu8CurrByte) = FLUSHED_JOIN_REQ;
2117
2118         u32WidsCount++;
2119
2120         #endif
2121
2122         s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, gu8FlushedJoinReqDrvHandler);
2123         if (s32Error) {
2124                 PRINT_ER("Handle_Flush_Connect()] failed to send config packet\n");
2125                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
2126         }
2127
2128         WILC_CATCH(s32Error)
2129         {
2130
2131         }
2132
2133         return s32Error;
2134 }
2135
2136 /**
2137  *  @brief                 Handle_ConnectTimeout
2138  *  @details       Call connect notification callback function indicating connection failure
2139  *  @param[in]    NONE
2140  *  @return         Error code.
2141  *  @author
2142  *  @date
2143  *  @version    1.0
2144  */
2145 static s32 Handle_ConnectTimeout(void *drvHandler)
2146 {
2147         s32 s32Error = WILC_SUCCESS;
2148         tstrConnectInfo strConnectInfo;
2149         tstrWID strWID;
2150         u16 u16DummyReasonCode = 0;
2151         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
2152
2153         if (pstrWFIDrv == NULL) {
2154                 PRINT_ER("Driver handler is NULL\n");
2155                 return s32Error;
2156         }
2157
2158         pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
2159
2160         gbScanWhileConnected = false;
2161
2162
2163         WILC_memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
2164
2165
2166         /* First, we will notify the upper layer with the Connection failure {through the Connect Callback function},
2167          *   then we will notify our firmware also with the Connection failure {through sending to it Cfg packet carrying
2168          *   WID_DISCONNECT} */
2169         if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
2170                 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2171                         WILC_memcpy(strConnectInfo.au8bssid,
2172                                     pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6);
2173                 }
2174
2175                 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2176                         strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
2177                         strConnectInfo.pu8ReqIEs = (u8 *)WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2178                         WILC_memcpy(strConnectInfo.pu8ReqIEs,
2179                                     pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
2180                                     pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2181                 }
2182
2183                 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
2184                                                                    &strConnectInfo,
2185                                                                    MAC_DISCONNECTED,
2186                                                                    NULL,
2187                                                                    pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
2188
2189                 /* Deallocation of strConnectInfo.pu8ReqIEs */
2190                 if (strConnectInfo.pu8ReqIEs != NULL) {
2191                         WILC_FREE(strConnectInfo.pu8ReqIEs);
2192                         strConnectInfo.pu8ReqIEs = NULL;
2193                 }
2194         } else {
2195                 PRINT_ER("Connect callback function pointer is NULL \n");
2196         }
2197
2198         /* Here we will notify our firmware also with the Connection failure {through sending to it Cfg packet carrying
2199          *   WID_DISCONNECT} */
2200         strWID.u16WIDid = (u16)WID_DISCONNECT;
2201         strWID.enuWIDtype = WID_CHAR;
2202         strWID.ps8WidVal = (s8 *)&u16DummyReasonCode;
2203         strWID.s32ValueSize = sizeof(char);
2204
2205         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
2206
2207         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
2208         if (s32Error) {
2209                 PRINT_ER("Failed to send dissconect config packet\n");
2210         }
2211
2212         /* Deallocation of the Saved Connect Request in the global Handle */
2213         pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
2214         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
2215                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
2216                 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
2217         }
2218
2219         if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2220                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
2221                 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
2222         }
2223
2224         pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2225         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2226                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
2227                 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
2228         }
2229
2230         WILC_memset(u8ConnectedSSID, 0, ETH_ALEN);
2231         /*BugID_5213*/
2232         /*Freeing flushed join request params on connect timeout*/
2233         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2234                 WILC_FREE(gu8FlushedJoinReq);
2235                 gu8FlushedJoinReq = NULL;
2236         }
2237         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2238                 WILC_FREE(gu8FlushedInfoElemAsoc);
2239                 gu8FlushedInfoElemAsoc = NULL;
2240         }
2241
2242         return s32Error;
2243 }
2244
2245 /**
2246  *  @brief Handle_RcvdNtwrkInfo
2247  *  @details       Handling received network information
2248  *  @param[in]    tstrRcvdNetworkInfo* pstrRcvdNetworkInfo
2249  *  @return         Error code.
2250  *  @author
2251  *  @date
2252  *  @version    1.0
2253  */
2254 static s32 Handle_RcvdNtwrkInfo(void *drvHandler, tstrRcvdNetworkInfo *pstrRcvdNetworkInfo)
2255 {
2256         u32 i;
2257         bool bNewNtwrkFound;
2258
2259
2260
2261         s32 s32Error = WILC_SUCCESS;
2262         tstrNetworkInfo *pstrNetworkInfo = NULL;
2263         void *pJoinParams = NULL;
2264
2265         tstrWILC_WFIDrv *pstrWFIDrv  = (tstrWILC_WFIDrv *)drvHandler;
2266
2267
2268
2269         bNewNtwrkFound = true;
2270         PRINT_INFO(HOSTINF_DBG, "Handling received network info\n");
2271
2272         /*if there is a an ongoing scan request*/
2273         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
2274                 PRINT_D(HOSTINF_DBG, "State: Scanning, parsing network information received\n");
2275                 ParseNetworkInfo(pstrRcvdNetworkInfo->pu8Buffer, &pstrNetworkInfo);
2276                 if ((pstrNetworkInfo == NULL)
2277                     || (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult == NULL)) {
2278                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
2279                 }
2280
2281                 /* check whether this network is discovered before */
2282                 for (i = 0; i < pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount; i++) {
2283
2284                         if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) &&
2285                             (pstrNetworkInfo->au8bssid != NULL)) {
2286                                 if (WILC_memcmp(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid,
2287                                                 pstrNetworkInfo->au8bssid, 6) == 0) {
2288                                         if (pstrNetworkInfo->s8rssi <= pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) {
2289                                                 /*we have already found this network with better rssi, so keep the old cached one and don't
2290                                                  *  send anything to the upper layer */
2291                                                 PRINT_D(HOSTINF_DBG, "Network previously discovered\n");
2292                                                 goto done;
2293                                         } else {
2294                                                 /* here the same already found network is found again but with a better rssi, so just update
2295                                                  *   the rssi for this cached network and send this updated network to the upper layer but
2296                                                  *   don't add a new record for it */
2297                                                 pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi;
2298                                                 bNewNtwrkFound = false;
2299                                                 break;
2300                                         }
2301                                 }
2302                         }
2303                 }
2304
2305                 if (bNewNtwrkFound == true) {
2306                         /* here it is confirmed that it is a new discovered network,
2307                          * so add its record then call the User CallBack function */
2308
2309                         PRINT_D(HOSTINF_DBG, "New network found\n");
2310
2311                         if (pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) {
2312                                 pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi;
2313
2314                                 if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL)
2315                                     && (pstrNetworkInfo->au8bssid != NULL)) {
2316                                         WILC_memcpy(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid,
2317                                                     pstrNetworkInfo->au8bssid, 6);
2318
2319                                         pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount++;
2320
2321                                         pstrNetworkInfo->bNewNetwork = true;
2322                                         /*Bug4218: Parsing Join Param*/
2323                                         /* add new BSS to JoinBssTable */
2324                                 #ifdef WILC_PARSE_SCAN_IN_HOST
2325                                         pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
2326                                 #endif /*WILC_PARSE_SCAN_IN_HOST*/
2327
2328                                         pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
2329                                                                                         pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid,
2330                                                                                         pJoinParams);
2331
2332
2333                                 }
2334                         } else {
2335                                 PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit \n");
2336                         }
2337                 } else {
2338                         pstrNetworkInfo->bNewNetwork = false;
2339                         /* just call the User CallBack function to send the same discovered network with its updated RSSI */
2340                         pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
2341                                                                         pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
2342                 }
2343         }
2344
2345
2346         WILC_CATCH(s32Error)
2347         {
2348
2349         }
2350
2351 done:
2352         /* Deallocate pstrRcvdNetworkInfo->pu8Buffer which was prevoisuly allocated by the sending thread */
2353         if (pstrRcvdNetworkInfo->pu8Buffer != NULL) {
2354                 WILC_FREE(pstrRcvdNetworkInfo->pu8Buffer);
2355                 pstrRcvdNetworkInfo->pu8Buffer = NULL;
2356         }
2357
2358         /*free structure allocated*/
2359         if (pstrNetworkInfo != NULL) {
2360                 DeallocateNetworkInfo(pstrNetworkInfo);
2361                 pstrNetworkInfo = NULL;
2362         }
2363
2364         return s32Error;
2365 }
2366
2367 /**
2368  *  @brief Handle_RcvdGnrlAsyncInfo
2369  *  @details       Handling received asynchrous general network information
2370  *  @param[in]    tstrRcvdGnrlAsyncInfo* pstrRcvdGnrlAsyncInfo
2371  *  @return         Error code.
2372  *  @author
2373  *  @date
2374  *  @version    1.0
2375  */
2376 static s32 Handle_RcvdGnrlAsyncInfo(void *drvHandler, tstrRcvdGnrlAsyncInfo *pstrRcvdGnrlAsyncInfo)
2377 {
2378         /* TODO: mostafa: till now, this function just handles only the received mac status msg, */
2379         /*                               which carries only 1 WID which have WID ID = WID_STATUS */
2380         s32 s32Error = WILC_SUCCESS;
2381         u8 u8MsgType = 0;
2382         u8 u8MsgID = 0;
2383         u16 u16MsgLen = 0;
2384         u16 u16WidID = (u16)WID_NIL;
2385         u8 u8WidLen  = 0;
2386         u8 u8MacStatus;
2387         u8 u8MacStatusReasonCode;
2388         u8 u8MacStatusAdditionalInfo;
2389         tstrConnectInfo strConnectInfo;
2390         tstrDisconnectNotifInfo strDisconnectNotifInfo;
2391         s32 s32Err = WILC_SUCCESS;
2392         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
2393         if (pstrWFIDrv == NULL) {
2394                 PRINT_ER("Driver handler is NULL\n");
2395         }
2396         PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", pstrWFIDrv->enuHostIFstate,
2397                 pstrRcvdGnrlAsyncInfo->pu8Buffer[7]);
2398
2399         if ((pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) ||
2400             (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) ||
2401             pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
2402                 if ((pstrRcvdGnrlAsyncInfo->pu8Buffer == NULL) ||
2403                     (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult == NULL)) {
2404                         WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
2405                 }
2406
2407                 u8MsgType = pstrRcvdGnrlAsyncInfo->pu8Buffer[0];
2408
2409                 /* Check whether the received message type is 'I' */
2410                 if ('I' != u8MsgType) {
2411                         PRINT_ER("Received Message format incorrect.\n");
2412                         WILC_ERRORREPORT(s32Error, WILC_FAIL);
2413                 }
2414
2415                 /* Extract message ID */
2416                 u8MsgID = pstrRcvdGnrlAsyncInfo->pu8Buffer[1];
2417
2418                 /* Extract message Length */
2419                 u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[2], pstrRcvdGnrlAsyncInfo->pu8Buffer[3]);
2420
2421                 /* Extract WID ID [expected to be = WID_STATUS] */
2422                 u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[4], pstrRcvdGnrlAsyncInfo->pu8Buffer[5]);
2423
2424                 /* Extract WID Length [expected to be = 1] */
2425                 u8WidLen = pstrRcvdGnrlAsyncInfo->pu8Buffer[6];
2426
2427                 /* get the WID value [expected to be one of two values: either MAC_CONNECTED = (1) or MAC_DISCONNECTED = (0)] */
2428                 u8MacStatus  = pstrRcvdGnrlAsyncInfo->pu8Buffer[7];
2429                 u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->pu8Buffer[8];
2430                 u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->pu8Buffer[9];
2431                 PRINT_INFO(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Info = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
2432                 if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2433                         /* our station had sent Association Request frame, so here it will get the Association Response frame then parse it */
2434                         u32 u32RcvdAssocRespInfoLen;
2435                         tstrConnectRespInfo *pstrConnectRespInfo = NULL;
2436
2437                         PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
2438
2439                         WILC_memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
2440
2441                         if (u8MacStatus == MAC_CONNECTED) {
2442                                 WILC_memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
2443
2444                                 host_int_get_assoc_res_info((WILC_WFIDrvHandle)pstrWFIDrv,
2445                                                             gapu8RcvdAssocResp,
2446                                                             MAX_ASSOC_RESP_FRAME_SIZE,
2447                                                             &u32RcvdAssocRespInfoLen);
2448
2449                                 PRINT_INFO(HOSTINF_DBG, "Received association response with length = %d\n", u32RcvdAssocRespInfoLen);
2450
2451                                 if (u32RcvdAssocRespInfoLen != 0) {
2452
2453                                         PRINT_D(HOSTINF_DBG, "Parsing association response\n");
2454                                         s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen,
2455                                                                     &pstrConnectRespInfo);
2456                                         if (s32Err) {
2457                                                 PRINT_ER("ParseAssocRespInfo() returned error %d \n", s32Err);
2458                                         } else {
2459                                                 /* use the necessary parsed Info from the Received Association Response */
2460                                                 strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus;
2461
2462                                                 if (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
2463                                                         PRINT_INFO(HOSTINF_DBG, "Association response received : Successful connection status\n");
2464                                                         if (pstrConnectRespInfo->pu8RespIEs != NULL) {
2465                                                                 strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen;
2466
2467
2468                                                                 strConnectInfo.pu8RespIEs = (u8 *)WILC_MALLOC(pstrConnectRespInfo->u16RespIEsLen);
2469                                                                 WILC_memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs,
2470                                                                             pstrConnectRespInfo->u16RespIEsLen);
2471                                                         }
2472                                                 }
2473
2474                                                 /* deallocate the Assoc. Resp. parsed structure as it is not needed anymore */
2475                                                 if (pstrConnectRespInfo != NULL) {
2476                                                         DeallocateAssocRespInfo(pstrConnectRespInfo);
2477                                                         pstrConnectRespInfo = NULL;
2478                                                 }
2479                                         }
2480                                 }
2481                         }
2482
2483                         /* The station has just received mac status and it also received assoc. response which
2484                          *   it was waiting for.
2485                          *   So check first the matching between the received mac status and the received status code in Asoc Resp */
2486                         if ((u8MacStatus == MAC_CONNECTED) &&
2487                             (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) {
2488                                 PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE \n");
2489                                 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN);
2490
2491                         } else if (u8MacStatus == MAC_DISCONNECTED)    {
2492                                 PRINT_ER("Received MAC status is MAC_DISCONNECTED\n");
2493                                 WILC_memset(u8ConnectedSSID, 0, ETH_ALEN);
2494                         }
2495
2496                         /* TODO: mostafa: correct BSSID should be retrieved from actual BSSID received from AP */
2497                         /*               through a structure of type tstrConnectRespInfo */
2498                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2499                                 PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n");
2500                                 WILC_memcpy(strConnectInfo.au8bssid, pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6);
2501
2502                                 if ((u8MacStatus == MAC_CONNECTED) &&
2503                                     (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
2504                                         WILC_memcpy(pstrWFIDrv->au8AssociatedBSSID,
2505                                                     pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN);
2506                                 }
2507                         }
2508
2509
2510                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2511                                 strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
2512                                 strConnectInfo.pu8ReqIEs = (u8 *)WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2513                                 WILC_memcpy(strConnectInfo.pu8ReqIEs,
2514                                             pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
2515                                             pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
2516                         }
2517
2518
2519                         WILC_TimerStop(&(pstrWFIDrv->hConnectTimer), NULL);
2520                         pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
2521                                                                            &strConnectInfo,
2522                                                                            u8MacStatus,
2523                                                                            NULL,
2524                                                                            pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
2525
2526
2527                         /* if received mac status is MAC_CONNECTED and
2528                          *  received status code in Asoc Resp is SUCCESSFUL_STATUSCODE, change state to CONNECTED
2529                          *  else change state to IDLE */
2530                         if ((u8MacStatus == MAC_CONNECTED) &&
2531                             (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
2532                                 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2533
2534                                 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0);
2535                                 #endif
2536
2537                                 PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n");
2538                                 pstrWFIDrv->enuHostIFstate = HOST_IF_CONNECTED;
2539
2540                                 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2541                                 PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n");
2542                                 g_obtainingIP = true;
2543                                 WILC_TimerStart(&hDuringIpTimer, 10000, NULL, NULL);
2544                                 #endif
2545
2546                                 #ifdef WILC_PARSE_SCAN_IN_HOST
2547                                 /* open a BA session if possible */
2548                                 /* if(pstrWFIDrv->strWILC_UsrConnReq.IsHTCapable) */
2549
2550                                 #endif
2551
2552                                 /* host_int_addBASession(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid,0, */
2553                                 /* BA_SESSION_DEFAULT_BUFFER_SIZE,BA_SESSION_DEFAULT_TIMEOUT); */
2554                         } else {
2555                                 PRINT_D(HOSTINF_DBG, "MAC status : %d and Connect Status : %d\n", u8MacStatus, strConnectInfo.u16ConnectStatus);
2556                                 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
2557                                 gbScanWhileConnected = false;
2558                         }
2559
2560                         /* Deallocation */
2561                         if (strConnectInfo.pu8RespIEs != NULL) {
2562                                 WILC_FREE(strConnectInfo.pu8RespIEs);
2563                                 strConnectInfo.pu8RespIEs = NULL;
2564                         }
2565
2566                         if (strConnectInfo.pu8ReqIEs != NULL) {
2567                                 WILC_FREE(strConnectInfo.pu8ReqIEs);
2568                                 strConnectInfo.pu8ReqIEs = NULL;
2569                         }
2570
2571
2572                         pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
2573                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
2574                                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
2575                                 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
2576                         }
2577
2578                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2579                                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
2580                                 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
2581                         }
2582
2583                         pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2584                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2585                                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
2586                                 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
2587                         }
2588
2589                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
2590                            (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED)) {
2591                         /* Disassociation or Deauthentication frame has been received */
2592                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n");
2593
2594                         WILC_memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
2595
2596                         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
2597                                 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >> \n\n");
2598                                 WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL);
2599                                 Handle_ScanDone((void *)pstrWFIDrv, SCAN_EVENT_ABORTED);
2600                         }
2601
2602                         strDisconnectNotifInfo.u16reason = 0;
2603                         strDisconnectNotifInfo.ie = NULL;
2604                         strDisconnectNotifInfo.ie_len = 0;
2605
2606                         if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
2607                                 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2608
2609                                 g_obtainingIP = false;
2610                                 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0);
2611                                 #endif
2612
2613                                 pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
2614                                                                                    NULL,
2615                                                                                    0,
2616                                                                                    &strDisconnectNotifInfo,
2617                                                                                    pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
2618
2619                         } else {
2620                                 PRINT_ER("Connect result callback function is NULL \n");
2621                         }
2622
2623                         WILC_memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN);
2624
2625
2626                         /* Deallocation */
2627
2628                         /* if Information Elements were retrieved from the Received deauth/disassoc frame, then they
2629                          *  should be deallocated here */
2630                         /*
2631                          * if(strDisconnectNotifInfo.ie != NULL)
2632                          * {
2633                          *      WILC_FREE(strDisconnectNotifInfo.ie);
2634                          *      strDisconnectNotifInfo.ie = NULL;
2635                          * }
2636                          */
2637
2638                         pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
2639                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
2640                                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
2641                                 pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
2642                         }
2643
2644                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
2645                                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
2646                                 pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
2647                         }
2648
2649                         pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2650                         if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
2651                                 WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
2652                                 pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
2653                         }
2654
2655                         /*BugID_5213*/
2656                         /*Freeing flushed join request params on receiving*/
2657                         /*MAC_DISCONNECTED while connected*/
2658                         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2659                                 WILC_FREE(gu8FlushedJoinReq);
2660                                 gu8FlushedJoinReq = NULL;
2661                         }
2662                         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
2663                                 WILC_FREE(gu8FlushedInfoElemAsoc);
2664                                 gu8FlushedInfoElemAsoc = NULL;
2665                         }
2666
2667                         pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
2668                         gbScanWhileConnected = false;
2669
2670                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
2671                            (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL)) {
2672                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n");
2673                         PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >> \n\n");
2674                         /*Abort the running scan*/
2675                         WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL);
2676                         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
2677                                 Handle_ScanDone((void *)pstrWFIDrv, SCAN_EVENT_ABORTED);
2678
2679                         }
2680                 }
2681
2682         }
2683
2684         WILC_CATCH(s32Error)
2685         {
2686
2687         }
2688
2689         /* Deallocate pstrRcvdGnrlAsyncInfo->pu8Buffer which was prevoisuly allocated by the sending thread */
2690         if (pstrRcvdGnrlAsyncInfo->pu8Buffer != NULL) {
2691                 WILC_FREE(pstrRcvdGnrlAsyncInfo->pu8Buffer);
2692                 pstrRcvdGnrlAsyncInfo->pu8Buffer = NULL;
2693         }
2694
2695         return s32Error;
2696 }
2697
2698 /**
2699  *  @brief Handle_Key
2700  *  @details       Sending config packet to firmware to set key
2701  *  @param[in]    tstrHostIFkeyAttr* pstrHostIFkeyAttr
2702  *  @return         Error code.
2703  *  @author
2704  *  @date
2705  *  @version    1.0
2706  */
2707 static int Handle_Key(void *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
2708 {
2709         s32 s32Error = WILC_SUCCESS;
2710         tstrWID strWID;
2711         #ifdef WILC_AP_EXTERNAL_MLME
2712         tstrWID strWIDList[5];
2713         #endif
2714         u8 i;
2715         u8 *pu8keybuf;
2716         s8 s8idxarray[1];
2717         s8 ret = 0;
2718         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
2719
2720
2721         switch (pstrHostIFkeyAttr->enuKeyType) {
2722
2723
2724         case WEP:
2725
2726 #ifdef WILC_AP_EXTERNAL_MLME
2727                 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
2728
2729                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
2730                         PRINT_D(GENERIC_DBG, "ID Hostint is %d\n", (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx));
2731                         strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
2732                         strWIDList[0].enuWIDtype = WID_CHAR;
2733                         strWIDList[0].s32ValueSize = sizeof(char);
2734                         strWIDList[0].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8mode));
2735
2736                         strWIDList[1].u16WIDid     = WID_AUTH_TYPE;
2737                         strWIDList[1].enuWIDtype  = WID_CHAR;
2738                         strWIDList[1].s32ValueSize = sizeof(char);
2739                         strWIDList[1].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.tenuAuth_type));
2740
2741                         strWIDList[2].u16WIDid  = (u16)WID_KEY_ID;
2742                         strWIDList[2].enuWIDtype        = WID_CHAR;
2743
2744                         strWIDList[2].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx));
2745                         strWIDList[2].s32ValueSize = sizeof(char);
2746
2747
2748                         pu8keybuf = (u8 *)WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
2749
2750
2751                         if (pu8keybuf == NULL) {
2752                                 PRINT_ER("No buffer to send Key\n");
2753                                 return -1;
2754                         }
2755
2756                         WILC_memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
2757                                     pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
2758
2759
2760                         WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
2761
2762                         strWIDList[3].u16WIDid = (u16)WID_WEP_KEY_VALUE;
2763                         strWIDList[3].enuWIDtype = WID_STR;
2764                         strWIDList[3].s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen;
2765                         strWIDList[3].ps8WidVal = (s8 *)pu8keybuf;
2766
2767
2768                         s32Error = SendConfigPkt(SET_CFG, strWIDList, 4, true, (u32)pstrWFIDrv);
2769                         WILC_FREE(pu8keybuf);
2770
2771
2772                 }
2773 #endif
2774
2775                 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
2776                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
2777                         pu8keybuf = (u8 *)WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2);
2778                         if (pu8keybuf == NULL) {
2779                                 PRINT_ER("No buffer to send Key\n");
2780                                 return -1;
2781                         }
2782                         pu8keybuf[0] = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx;
2783
2784                         WILC_memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen, 1);
2785
2786                         WILC_memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
2787                                     pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
2788
2789                         WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
2790
2791                         strWID.u16WIDid = (u16)WID_ADD_WEP_KEY;
2792                         strWID.enuWIDtype       = WID_STR;
2793                         strWID.ps8WidVal        = (s8 *)pu8keybuf;
2794                         strWID.s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2;
2795
2796                         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2797                         WILC_FREE(pu8keybuf);
2798                 } else if (pstrHostIFkeyAttr->u8KeyAction & REMOVEKEY)    {
2799
2800                         PRINT_D(HOSTINF_DBG, "Removing key\n");
2801                         strWID.u16WIDid = (u16)WID_REMOVE_WEP_KEY;
2802                         strWID.enuWIDtype       = WID_STR;
2803
2804                         s8idxarray[0] = (s8)pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx;
2805                         strWID.ps8WidVal = s8idxarray;
2806                         strWID.s32ValueSize = 1;
2807
2808                         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2809                 } else {
2810                         strWID.u16WIDid = (u16)WID_KEY_ID;
2811                         strWID.enuWIDtype       = WID_CHAR;
2812                         strWID.ps8WidVal        = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx));
2813                         strWID.s32ValueSize = sizeof(char);
2814
2815                         PRINT_D(HOSTINF_DBG, "Setting default key index\n");
2816
2817                         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2818                 }
2819                 up(&(pstrWFIDrv->hSemTestKeyBlock));
2820                 break;
2821
2822         case WPARxGtk:
2823                         #ifdef WILC_AP_EXTERNAL_MLME
2824                 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
2825                         pu8keybuf = (u8 *)WILC_MALLOC(RX_MIC_KEY_MSG_LEN);
2826                         if (pu8keybuf == NULL) {
2827                                 PRINT_ER("No buffer to send RxGTK Key\n");
2828                                 ret = -1;
2829                                 goto _WPARxGtk_end_case_;
2830                         }
2831
2832                         WILC_memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
2833
2834
2835                         /*|----------------------------------------------------------------------------|
2836                          * |Sta Address | Key RSC | KeyID | Key Length | Temporal Key   | Rx Michael Key |
2837                          * |------------|---------|-------|------------|---------------|----------------|
2838                          |      6 bytes  | 8 byte  |1 byte |  1 byte    |   16 bytes    |         8 bytes        |*/
2839
2840
2841
2842                         if (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq != NULL)
2843                                 WILC_memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8);
2844
2845
2846                         WILC_memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
2847
2848                         WILC_memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2849
2850                         WILC_memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2851                                     pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2852                         /* pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode =  0X51; */
2853                         strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
2854                         strWIDList[0].enuWIDtype = WID_CHAR;
2855                         strWIDList[0].s32ValueSize = sizeof(char);
2856                         strWIDList[0].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode));
2857
2858                         strWIDList[1].u16WIDid  = (u16)WID_ADD_RX_GTK;
2859                         strWIDList[1].enuWIDtype        = WID_STR;
2860                         strWIDList[1].ps8WidVal = (s8 *)pu8keybuf;
2861                         strWIDList[1].s32ValueSize = RX_MIC_KEY_MSG_LEN;
2862
2863                         s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
2864
2865                         WILC_FREE(pu8keybuf);
2866
2867                         /* ////////////////////////// */
2868                         up(&(pstrWFIDrv->hSemTestKeyBlock));
2869                         /* ///////////////////////// */
2870                 }
2871
2872                         #endif
2873                 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
2874                         PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n");
2875
2876                         pu8keybuf = (u8 *)WILC_MALLOC(RX_MIC_KEY_MSG_LEN);
2877                         if (pu8keybuf == NULL) {
2878                                 PRINT_ER("No buffer to send RxGTK Key\n");
2879                                 ret = -1;
2880                                 goto _WPARxGtk_end_case_;
2881                         }
2882
2883                         WILC_memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
2884
2885
2886                         /*|----------------------------------------------------------------------------|
2887                          * |Sta Address | Key RSC | KeyID | Key Length | Temporal Key   | Rx Michael Key |
2888                          * |------------|---------|-------|------------|---------------|----------------|
2889                          |      6 bytes  | 8 byte  |1 byte |  1 byte    |   16 bytes    |         8 bytes        |*/
2890
2891                         if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) {
2892                                 WILC_memcpy(pu8keybuf, pstrWFIDrv->au8AssociatedBSSID, ETH_ALEN);
2893                         } else {
2894                                 PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED \n");
2895                         }
2896
2897                         WILC_memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8);
2898
2899                         WILC_memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
2900
2901                         WILC_memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2902                         WILC_memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2903                                     pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2904
2905                         strWID.u16WIDid = (u16)WID_ADD_RX_GTK;
2906                         strWID.enuWIDtype       = WID_STR;
2907                         strWID.ps8WidVal        = (s8 *)pu8keybuf;
2908                         strWID.s32ValueSize = RX_MIC_KEY_MSG_LEN;
2909
2910                         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
2911
2912                         WILC_FREE(pu8keybuf);
2913
2914                         /* ////////////////////////// */
2915                         up(&(pstrWFIDrv->hSemTestKeyBlock));
2916                         /* ///////////////////////// */
2917                 }
2918 _WPARxGtk_end_case_:
2919                 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key);
2920                 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq);
2921                 if (ret == -1)
2922                         return ret;
2923
2924                 break;
2925
2926         case WPAPtk:
2927                 #ifdef WILC_AP_EXTERNAL_MLME
2928                 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
2929
2930
2931                         pu8keybuf = (u8 *)WILC_MALLOC(PTK_KEY_MSG_LEN + 1);
2932
2933
2934
2935                         if (pu8keybuf == NULL) {
2936                                 PRINT_ER("No buffer to send PTK Key\n");
2937                                 ret = -1;
2938                                 goto _WPAPtk_end_case_;
2939
2940                         }
2941
2942                         /*|-----------------------------------------------------------------------------|
2943                          * |Station address |   keyidx     |Key Length    |Temporal Key  | Rx Michael Key |Tx Michael Key |
2944                          * |----------------|------------  |--------------|----------------|---------------|
2945                          |      6 bytes    |    1 byte    |   1byte      |   16 bytes    |        8 bytes         |        8 bytes        |
2946                          |-----------------------------------------------------------------------------|*/
2947
2948                         WILC_memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6);  /*1 bytes Key Length */
2949
2950                         WILC_memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
2951                         WILC_memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2952                         /*16 byte TK*/
2953                         WILC_memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
2954                                     pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
2955
2956
2957                         strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
2958                         strWIDList[0].enuWIDtype = WID_CHAR;
2959                         strWIDList[0].s32ValueSize = sizeof(char);
2960                         strWIDList[0].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode));
2961
2962                         strWIDList[1].u16WIDid  = (u16)WID_ADD_PTK;
2963                         strWIDList[1].enuWIDtype        = WID_STR;
2964                         strWIDList[1].ps8WidVal = (s8 *)pu8keybuf;
2965                         strWIDList[1].s32ValueSize = PTK_KEY_MSG_LEN + 1;
2966
2967                         s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
2968                         WILC_FREE(pu8keybuf);
2969
2970                         /* ////////////////////////// */
2971                         up(&(pstrWFIDrv->hSemTestKeyBlock));
2972                         /* ///////////////////////// */
2973                 }
2974                 #endif
2975                 if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
2976
2977
2978                         pu8keybuf = (u8 *)WILC_MALLOC(PTK_KEY_MSG_LEN);
2979
2980
2981
2982                         if (pu8keybuf == NULL) {
2983                                 PRINT_ER("No buffer to send PTK Key\n");
2984                                 ret = -1;
2985                                 goto _WPAPtk_end_case_;
2986
2987                         }
2988
2989                         /*|-----------------------------------------------------------------------------|
2990                          * |Station address | Key Length |      Temporal Key | Rx Michael Key |Tx Michael Key |
2991                          * |----------------|------------|--------------|----------------|---------------|
2992                          |      6 bytes          |      1byte     |   16 bytes   |        8 bytes         |        8 bytes        |
2993                          |-----------------------------------------------------------------------------|*/
2994
2995                         WILC_memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6);  /*1 bytes Key Length */
2996
2997                         WILC_memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
2998                         /*16 byte TK*/
2999                         WILC_memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
3000                                     pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
3001
3002
3003                         strWID.u16WIDid = (u16)WID_ADD_PTK;
3004                         strWID.enuWIDtype       = WID_STR;
3005                         strWID.ps8WidVal        = (s8 *)pu8keybuf;
3006                         strWID.s32ValueSize = PTK_KEY_MSG_LEN;
3007
3008                         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3009                         WILC_FREE(pu8keybuf);
3010
3011                         /* ////////////////////////// */
3012                         up(&(pstrWFIDrv->hSemTestKeyBlock));
3013                         /* ///////////////////////// */
3014                 }
3015
3016 _WPAPtk_end_case_:
3017                 WILC_FREE(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key);
3018                 if (ret == -1)
3019                         return ret;
3020
3021                 break;
3022
3023
3024         case PMKSA:
3025
3026                 PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n");
3027
3028                 pu8keybuf = (u8 *)WILC_MALLOC((pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1);
3029                 if (pu8keybuf == NULL) {
3030                         PRINT_ER("No buffer to send PMKSA Key\n");
3031                         return -1;
3032                 }
3033
3034                 pu8keybuf[0] = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid;
3035
3036                 for (i = 0; i < pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid; i++) {
3037
3038                         WILC_memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, ETH_ALEN);
3039                         WILC_memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, PMKID_LEN);
3040                 }
3041
3042                 strWID.u16WIDid = (u16)WID_PMKID_INFO;
3043                 strWID.enuWIDtype = WID_STR;
3044                 strWID.ps8WidVal = (s8 *)pu8keybuf;
3045                 strWID.s32ValueSize = (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1;
3046
3047                 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3048
3049                 WILC_FREE(pu8keybuf);
3050                 break;
3051         }
3052
3053         if (s32Error)
3054                 PRINT_ER("Failed to send key config packet\n");
3055
3056
3057         return s32Error;
3058 }
3059
3060
3061 /**
3062  *  @brief Handle_Disconnect
3063  *  @details       Sending config packet to firmware to disconnect
3064  *  @param[in]    NONE
3065  *  @return         NONE
3066  *  @author
3067  *  @date
3068  *  @version    1.0
3069  */
3070 static void Handle_Disconnect(void *drvHandler)
3071 {
3072         tstrWID strWID;
3073
3074         s32 s32Error = WILC_SUCCESS;
3075         u16 u16DummyReasonCode = 0;
3076         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3077
3078
3079         strWID.u16WIDid = (u16)WID_DISCONNECT;
3080         strWID.enuWIDtype = WID_CHAR;
3081         strWID.ps8WidVal = (s8 *)&u16DummyReasonCode;
3082         strWID.s32ValueSize = sizeof(char);
3083
3084
3085
3086         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
3087
3088         #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3089
3090         g_obtainingIP = false;
3091         host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0);
3092         #endif
3093
3094         WILC_memset(u8ConnectedSSID, 0, ETH_ALEN);
3095
3096         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3097
3098         if (s32Error) {
3099                 PRINT_ER("Failed to send dissconect config packet\n");
3100                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3101         } else {
3102                 tstrDisconnectNotifInfo strDisconnectNotifInfo;
3103
3104                 WILC_memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
3105
3106                 strDisconnectNotifInfo.u16reason = 0;
3107                 strDisconnectNotifInfo.ie = NULL;
3108                 strDisconnectNotifInfo.ie_len = 0;
3109
3110                 if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
3111                         WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL);
3112                         pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
3113                                                                         pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
3114
3115                         pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
3116                 }
3117
3118                 if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
3119
3120                         /*BugID_5193*/
3121                         /*Stop connect timer, if connection in progress*/
3122                         if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
3123                                 PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n");
3124                                 WILC_TimerStop(&(pstrWFIDrv->hConnectTimer), NULL);
3125                         }
3126
3127                         pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
3128                                                                            0, &strDisconnectNotifInfo, pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
3129                 } else {
3130                         PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL \n");
3131                 }
3132
3133                 gbScanWhileConnected = false;
3134
3135                 pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
3136
3137                 WILC_memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN);
3138
3139
3140                 /* Deallocation */
3141                 pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
3142                 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
3143                         WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
3144                         pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
3145                 }
3146
3147                 if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
3148                         WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
3149                         pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
3150                 }
3151
3152                 pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
3153                 if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
3154                         WILC_FREE(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
3155                         pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
3156                 }
3157
3158
3159                 /*BugID_5137*/
3160                 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
3161                         WILC_FREE(gu8FlushedJoinReq);
3162                         gu8FlushedJoinReq = NULL;
3163                 }
3164                 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
3165                         WILC_FREE(gu8FlushedInfoElemAsoc);
3166                         gu8FlushedInfoElemAsoc = NULL;
3167                 }
3168
3169         }
3170
3171         WILC_CATCH(s32Error)
3172         {
3173
3174         }
3175
3176         /* ////////////////////////// */
3177         up(&(pstrWFIDrv->hSemTestDisconnectBlock));
3178         /* ///////////////////////// */
3179
3180 }
3181
3182
3183 void resolve_disconnect_aberration(void *drvHandler)
3184 {
3185         tstrWILC_WFIDrv *pstrWFIDrv;
3186
3187         pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3188         if (pstrWFIDrv  == NULL)
3189                 return;
3190         if ((pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTING)) {
3191                 PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n");
3192                 host_int_disconnect((WILC_WFIDrvHandle)pstrWFIDrv, 1);
3193         }
3194 }
3195 static s32 Switch_Log_Terminal(void *drvHandler)
3196 {
3197
3198
3199         s32 s32Error = WILC_SUCCESS;
3200         tstrWID strWID;
3201         static char dummy = 9;
3202         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3203
3204         strWID.u16WIDid = (u16)WID_LOGTerminal_Switch;
3205         strWID.enuWIDtype = WID_CHAR;
3206         strWID.ps8WidVal = &dummy;
3207         strWID.s32ValueSize = sizeof(char);
3208
3209         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3210
3211
3212         if (s32Error) {
3213                 PRINT_D(HOSTINF_DBG, "Failed to switch log terminal\n");
3214                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
3215         } else {
3216                 PRINT_INFO(HOSTINF_DBG, "MAC address set :: \n");
3217
3218
3219         }
3220
3221         WILC_CATCH(s32Error)
3222         {
3223
3224         }
3225
3226         return s32Error;
3227 }
3228
3229 /**
3230  *  @brief Handle_GetChnl
3231  *  @details       Sending config packet to get channel
3232  *  @param[in]    NONE
3233  *  @return         NONE
3234  *
3235  *  @author
3236  *  @date
3237  *  @version    1.0
3238  */
3239 static s32 Handle_GetChnl(void *drvHandler)
3240 {
3241
3242         s32 s32Error = WILC_SUCCESS;
3243         tstrWID strWID;
3244         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
3245         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3246         strWID.u16WIDid = (u16)WID_CURRENT_CHANNEL;
3247         strWID.enuWIDtype = WID_CHAR;
3248         strWID.ps8WidVal = (s8 *)&gu8Chnl;
3249         strWID.s32ValueSize = sizeof(char);
3250
3251         PRINT_D(HOSTINF_DBG, "Getting channel value\n");
3252
3253         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3254         /*get the value by searching the local copy*/
3255         if (s32Error) {
3256                 PRINT_ER("Failed to get channel number\n");
3257                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3258         }
3259
3260
3261         WILC_CATCH(s32Error)
3262         {
3263
3264         }
3265         up(&(pstrWFIDrv->hSemGetCHNL));
3266
3267         return s32Error;
3268
3269
3270
3271 }
3272
3273
3274 /**
3275  *  @brief Handle_GetRssi
3276  *  @details       Sending config packet to get RSSI
3277  *  @param[in]    NONE
3278  *  @return         NONE
3279  *  @author
3280  *  @date
3281  *  @version    1.0
3282  */
3283 static void Handle_GetRssi(void *drvHandler)
3284 {
3285         s32 s32Error = WILC_SUCCESS;
3286         tstrWID strWID;
3287         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3288
3289         strWID.u16WIDid = (u16)WID_RSSI;
3290         strWID.enuWIDtype = WID_CHAR;
3291         strWID.ps8WidVal = &gs8Rssi;
3292         strWID.s32ValueSize = sizeof(char);
3293
3294         /*Sending Cfg*/
3295         PRINT_D(HOSTINF_DBG, "Getting RSSI value\n");
3296
3297         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3298         if (s32Error) {
3299                 PRINT_ER("Failed to get RSSI value\n");
3300                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3301         }
3302
3303         WILC_CATCH(s32Error)
3304         {
3305
3306         }
3307         up(&(pstrWFIDrv->hSemGetRSSI));
3308
3309
3310 }
3311
3312
3313 static void Handle_GetLinkspeed(void *drvHandler)
3314 {
3315         s32 s32Error = WILC_SUCCESS;
3316         tstrWID strWID;
3317         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3318
3319         gs8lnkspd = 0;
3320
3321         strWID.u16WIDid = (u16)WID_LINKSPEED;
3322         strWID.enuWIDtype = WID_CHAR;
3323         strWID.ps8WidVal = &gs8lnkspd;
3324         strWID.s32ValueSize = sizeof(char);
3325         /*Sending Cfg*/
3326         PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n");
3327
3328         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3329         if (s32Error) {
3330                 PRINT_ER("Failed to get LINKSPEED value\n");
3331                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3332         }
3333
3334         WILC_CATCH(s32Error)
3335         {
3336
3337         }
3338         up(&(pstrWFIDrv->hSemGetLINKSPEED));
3339
3340
3341 }
3342
3343 s32 Handle_GetStatistics(void *drvHandler, tstrStatistics *pstrStatistics)
3344 {
3345         tstrWID strWIDList[5];
3346         uint32_t u32WidsCount = 0, s32Error = 0;
3347
3348         strWIDList[u32WidsCount].u16WIDid = WID_LINKSPEED;
3349         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
3350         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
3351         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u8LinkSpeed));
3352         u32WidsCount++;
3353
3354         strWIDList[u32WidsCount].u16WIDid = WID_RSSI;
3355         strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
3356         strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
3357         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->s8RSSI));
3358         u32WidsCount++;
3359
3360         strWIDList[u32WidsCount].u16WIDid = WID_SUCCESS_FRAME_COUNT;
3361         strWIDList[u32WidsCount].enuWIDtype = WID_INT;
3362         strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
3363         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32TxCount));
3364         u32WidsCount++;
3365
3366         strWIDList[u32WidsCount].u16WIDid = WID_RECEIVED_FRAGMENT_COUNT;
3367         strWIDList[u32WidsCount].enuWIDtype = WID_INT;
3368         strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
3369         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32RxCount));
3370         u32WidsCount++;
3371
3372         strWIDList[u32WidsCount].u16WIDid = WID_FAILED_COUNT;
3373         strWIDList[u32WidsCount].enuWIDtype = WID_INT;
3374         strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
3375         strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32TxFailureCount));
3376         u32WidsCount++;
3377
3378         s32Error = SendConfigPkt(GET_CFG, strWIDList, u32WidsCount, false, (u32)drvHandler);
3379
3380         if (s32Error) {
3381                 PRINT_ER("Failed to send scan paramters config packet\n");
3382                 /* WILC_ERRORREPORT(s32Error, s32Error); */
3383         }
3384         up(&hWaitResponse);
3385         return 0;
3386
3387 }
3388
3389
3390 #ifdef WILC_AP_EXTERNAL_MLME
3391
3392
3393 /**
3394  *  @brief Handle_Get_InActiveTime
3395  *  @details       Sending config packet to set mac adddress for station and
3396  *                 get inactive time
3397  *  @param[in]    NONE
3398  *  @return         NONE
3399  *
3400  *  @author
3401  *  @date
3402  *  @version    1.0
3403  */
3404 static s32 Handle_Get_InActiveTime(void *drvHandler, tstrHostIfStaInactiveT *strHostIfStaInactiveT)
3405 {
3406
3407         s32 s32Error = WILC_SUCCESS;
3408         u8 *stamac;
3409         tstrWID strWID;
3410         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3411
3412
3413         strWID.u16WIDid = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
3414         strWID.enuWIDtype = WID_STR;
3415         strWID.s32ValueSize = ETH_ALEN;
3416         strWID.ps8WidVal = (u8 *)WILC_MALLOC(strWID.s32ValueSize);
3417
3418
3419         stamac = strWID.ps8WidVal;
3420         WILC_memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
3421
3422
3423         PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
3424
3425
3426         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3427         /*get the value by searching the local copy*/
3428         if (s32Error) {
3429                 PRINT_ER("Failed to SET incative time\n");
3430                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3431         }
3432
3433
3434         strWID.u16WIDid = (u16)WID_GET_INACTIVE_TIME;
3435         strWID.enuWIDtype = WID_INT;
3436         strWID.ps8WidVal = (s8 *)&gu32InactiveTime;
3437         strWID.s32ValueSize = sizeof(u32);
3438
3439
3440         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3441         /*get the value by searching the local copy*/
3442         if (s32Error) {
3443                 PRINT_ER("Failed to get incative time\n");
3444                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3445         }
3446
3447
3448         PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", gu32InactiveTime);
3449
3450         up(&(pstrWFIDrv->hSemInactiveTime));
3451         WILC_CATCH(s32Error)
3452         {
3453
3454         }
3455
3456
3457         return s32Error;
3458
3459
3460
3461 }
3462
3463
3464 /**
3465  *  @brief Handle_AddBeacon
3466  *  @details       Sending config packet to add beacon
3467  *  @param[in]    tstrHostIFSetBeacon* pstrSetBeaconParam
3468  *  @return         NONE
3469  *  @author
3470  *  @date
3471  *  @version    1.0
3472  */
3473 static void Handle_AddBeacon(void *drvHandler, tstrHostIFSetBeacon *pstrSetBeaconParam)
3474 {
3475         s32 s32Error = WILC_SUCCESS;
3476         tstrWID strWID;
3477         u8 *pu8CurrByte;
3478         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3479         PRINT_D(HOSTINF_DBG, "Adding BEACON\n");
3480
3481         strWID.u16WIDid = (u16)WID_ADD_BEACON;
3482         strWID.enuWIDtype = WID_BIN;
3483         strWID.s32ValueSize = pstrSetBeaconParam->u32HeadLen + pstrSetBeaconParam->u32TailLen + 16;
3484         strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3485         if (strWID.ps8WidVal == NULL) {
3486                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3487         }
3488
3489         pu8CurrByte = strWID.ps8WidVal;
3490         *pu8CurrByte++ = (pstrSetBeaconParam->u32Interval & 0xFF);
3491         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 8) & 0xFF);
3492         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 16) & 0xFF);
3493         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 24) & 0xFF);
3494
3495         *pu8CurrByte++ = (pstrSetBeaconParam->u32DTIMPeriod & 0xFF);
3496         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 8) & 0xFF);
3497         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 16) & 0xFF);
3498         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 24) & 0xFF);
3499
3500         *pu8CurrByte++ = (pstrSetBeaconParam->u32HeadLen & 0xFF);
3501         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 8) & 0xFF);
3502         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 16) & 0xFF);
3503         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 24) & 0xFF);
3504
3505         memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Head, pstrSetBeaconParam->u32HeadLen);
3506         pu8CurrByte += pstrSetBeaconParam->u32HeadLen;
3507
3508         *pu8CurrByte++ = (pstrSetBeaconParam->u32TailLen & 0xFF);
3509         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 8) & 0xFF);
3510         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 16) & 0xFF);
3511         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 24) & 0xFF);
3512
3513         /* Bug 4599 : if tail length = 0 skip copying */
3514         if (pstrSetBeaconParam->pu8Tail > 0)
3515                 memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Tail, pstrSetBeaconParam->u32TailLen);
3516         pu8CurrByte += pstrSetBeaconParam->u32TailLen;
3517
3518
3519
3520         /*Sending Cfg*/
3521         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3522         if (s32Error) {
3523                 PRINT_ER("Failed to send add beacon config packet\n");
3524                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3525         }
3526
3527         WILC_CATCH(s32Error)
3528         {
3529         }
3530         WILC_FREE_IF_TRUE(strWID.ps8WidVal);
3531         WILC_FREE_IF_TRUE(pstrSetBeaconParam->pu8Head);
3532         WILC_FREE_IF_TRUE(pstrSetBeaconParam->pu8Tail);
3533 }
3534
3535
3536 /**
3537  *  @brief Handle_AddBeacon
3538  *  @details       Sending config packet to delete beacon
3539  *  @param[in]   tstrHostIFDelBeacon* pstrDelBeacon
3540  *  @return         NONE
3541  *  @author
3542  *  @date
3543  *  @version    1.0
3544  */
3545 static void Handle_DelBeacon(void *drvHandler, tstrHostIFDelBeacon *pstrDelBeacon)
3546 {
3547         s32 s32Error = WILC_SUCCESS;
3548         tstrWID strWID;
3549         u8 *pu8CurrByte;
3550         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3551         strWID.u16WIDid = (u16)WID_DEL_BEACON;
3552         strWID.enuWIDtype = WID_CHAR;
3553         strWID.s32ValueSize = sizeof(char);
3554         strWID.ps8WidVal = &gu8DelBcn;
3555
3556         if (strWID.ps8WidVal == NULL) {
3557                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3558         }
3559
3560         pu8CurrByte = strWID.ps8WidVal;
3561
3562         PRINT_D(HOSTINF_DBG, "Deleting BEACON\n");
3563         /* TODO: build del beacon message*/
3564
3565         /*Sending Cfg*/
3566         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3567         if (s32Error) {
3568
3569                 PRINT_ER("Failed to send delete beacon config packet\n");
3570                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3571         }
3572
3573         WILC_CATCH(s32Error)
3574         {
3575         }
3576 }
3577
3578
3579 /**
3580  *  @brief WILC_HostIf_PackStaParam
3581  *  @details       Handling packing of the station params in a buffer
3582  *  @param[in]   u8* pu8Buffer, tstrWILC_AddStaParam* pstrStationParam
3583  *  @return         NONE
3584  *  @author
3585  *  @date
3586  *  @version    1.0
3587  */
3588 static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, tstrWILC_AddStaParam *pstrStationParam)
3589 {
3590         u8 *pu8CurrByte;
3591
3592         pu8CurrByte = pu8Buffer;
3593
3594         PRINT_D(HOSTINF_DBG, "Packing STA params\n");
3595         WILC_memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN);
3596         pu8CurrByte +=  ETH_ALEN;
3597
3598         *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF;
3599         *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF;
3600
3601         *pu8CurrByte++ = pstrStationParam->u8NumRates;
3602         if (pstrStationParam->u8NumRates > 0) {
3603                 WILC_memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates);
3604         }
3605         pu8CurrByte += pstrStationParam->u8NumRates;
3606
3607         *pu8CurrByte++ = pstrStationParam->bIsHTSupported;
3608         *pu8CurrByte++ = pstrStationParam->u16HTCapInfo & 0xFF;
3609         *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF;
3610
3611         *pu8CurrByte++ = pstrStationParam->u8AmpduParams;
3612         WILC_memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE);
3613         pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
3614
3615         *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF;
3616         *pu8CurrByte++ = (pstrStationParam->u16HTExtParams >> 8) & 0xFF;
3617
3618         *pu8CurrByte++ = pstrStationParam->u32TxBeamformingCap & 0xFF;
3619         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 8) & 0xFF;
3620         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 16) & 0xFF;
3621         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 24) & 0xFF;
3622
3623         *pu8CurrByte++ = pstrStationParam->u8ASELCap;
3624
3625         *pu8CurrByte++ = pstrStationParam->u16FlagsMask & 0xFF;
3626         *pu8CurrByte++ = (pstrStationParam->u16FlagsMask >> 8) & 0xFF;
3627
3628         *pu8CurrByte++ = pstrStationParam->u16FlagsSet & 0xFF;
3629         *pu8CurrByte++ = (pstrStationParam->u16FlagsSet >> 8) & 0xFF;
3630
3631         return pu8CurrByte - pu8Buffer;
3632 }
3633
3634 /**
3635  *  @brief Handle_AddStation
3636  *  @details       Sending config packet to add station
3637  *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
3638  *  @return         NONE
3639  *  @author
3640  *  @date
3641  *  @version    1.0
3642  */
3643 static void Handle_AddStation(void *drvHandler, tstrWILC_AddStaParam *pstrStationParam)
3644 {
3645         s32 s32Error = WILC_SUCCESS;
3646         tstrWID strWID;
3647         u8 *pu8CurrByte;
3648         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3649         PRINT_D(HOSTINF_DBG, "Handling add station\n");
3650         strWID.u16WIDid = (u16)WID_ADD_STA;
3651         strWID.enuWIDtype = WID_BIN;
3652         strWID.s32ValueSize = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
3653
3654         strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3655         if (strWID.ps8WidVal == NULL) {
3656                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3657         }
3658
3659         pu8CurrByte = strWID.ps8WidVal;
3660         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
3661
3662         /*Sending Cfg*/
3663         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3664         if (s32Error != WILC_SUCCESS) {
3665
3666                 PRINT_ER("Failed to send add station config packet\n");
3667                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3668         }
3669
3670         WILC_CATCH(s32Error)
3671         {
3672         }
3673         WILC_FREE_IF_TRUE(pstrStationParam->pu8Rates);
3674         WILC_FREE_IF_TRUE(strWID.ps8WidVal);
3675 }
3676
3677 /**
3678  *  @brief Handle_DelAllSta
3679  *  @details        Sending config packet to delete station
3680  *  @param[in]   tstrHostIFDelSta* pstrDelStaParam
3681  *  @return         NONE
3682  *  @author
3683  *  @date
3684  *  @version    1.0
3685  */
3686 static void Handle_DelAllSta(void *drvHandler, tstrHostIFDelAllSta *pstrDelAllStaParam)
3687 {
3688         s32 s32Error = WILC_SUCCESS;
3689         tstrWID strWID;
3690         u8 *pu8CurrByte;
3691         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3692         u8 i;
3693         u8 au8Zero_Buff[6] = {0};
3694         strWID.u16WIDid = (u16)WID_DEL_ALL_STA;
3695         strWID.enuWIDtype = WID_STR;
3696         strWID.s32ValueSize = (pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1;
3697
3698         PRINT_D(HOSTINF_DBG, "Handling delete station \n");
3699
3700         strWID.ps8WidVal = WILC_MALLOC((pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1);
3701         if (strWID.ps8WidVal == NULL) {
3702                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3703         }
3704
3705         pu8CurrByte = strWID.ps8WidVal;
3706
3707         *(pu8CurrByte++) = pstrDelAllStaParam->u8Num_AssocSta;
3708
3709         for (i = 0; i < MAX_NUM_STA; i++) {
3710                 if (memcmp(pstrDelAllStaParam->au8Sta_DelAllSta[i], au8Zero_Buff, ETH_ALEN))
3711                         WILC_memcpy(pu8CurrByte, pstrDelAllStaParam->au8Sta_DelAllSta[i], ETH_ALEN);
3712                 else
3713                         continue;
3714
3715                 pu8CurrByte += ETH_ALEN;
3716         }
3717
3718         /*Sending Cfg*/
3719         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3720         if (s32Error) {
3721
3722                 PRINT_ER("Failed to send add station config packe\n");
3723                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3724         }
3725
3726         WILC_CATCH(s32Error)
3727         {
3728         }
3729         WILC_FREE_IF_TRUE(strWID.ps8WidVal);
3730
3731         up(&hWaitResponse);
3732 }
3733
3734
3735 /**
3736  *  @brief Handle_DelStation
3737  *  @details        Sending config packet to delete station
3738  *  @param[in]   tstrHostIFDelSta* pstrDelStaParam
3739  *  @return         NONE
3740  *  @author
3741  *  @date
3742  *  @version    1.0
3743  */
3744 static void Handle_DelStation(void *drvHandler, tstrHostIFDelSta *pstrDelStaParam)
3745 {
3746         s32 s32Error = WILC_SUCCESS;
3747         tstrWID strWID;
3748         u8 *pu8CurrByte;
3749         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3750
3751         strWID.u16WIDid = (u16)WID_REMOVE_STA;
3752         strWID.enuWIDtype = WID_BIN;
3753         strWID.s32ValueSize = ETH_ALEN;
3754
3755         PRINT_D(HOSTINF_DBG, "Handling delete station \n");
3756
3757         strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3758         if (strWID.ps8WidVal == NULL) {
3759                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3760         }
3761
3762         pu8CurrByte = strWID.ps8WidVal;
3763
3764         WILC_memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN);
3765
3766         /*Sending Cfg*/
3767         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3768         if (s32Error) {
3769
3770                 PRINT_ER("Failed to send add station config packe\n");
3771                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3772         }
3773
3774         WILC_CATCH(s32Error)
3775         {
3776         }
3777         WILC_FREE_IF_TRUE(strWID.ps8WidVal);
3778 }
3779
3780
3781 /**
3782  *  @brief Handle_EditStation
3783  *  @details        Sending config packet to edit station
3784  *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
3785  *  @return         NONE
3786  *  @author
3787  *  @date
3788  *  @version    1.0
3789  */
3790 static void Handle_EditStation(void *drvHandler, tstrWILC_AddStaParam *pstrStationParam)
3791 {
3792         s32 s32Error = WILC_SUCCESS;
3793         tstrWID strWID;
3794         u8 *pu8CurrByte;
3795         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3796
3797         strWID.u16WIDid = (u16)WID_EDIT_STA;
3798         strWID.enuWIDtype = WID_BIN;
3799         strWID.s32ValueSize = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
3800
3801         PRINT_D(HOSTINF_DBG, "Handling edit station\n");
3802         strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3803         if (strWID.ps8WidVal == NULL) {
3804                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3805         }
3806
3807         pu8CurrByte = strWID.ps8WidVal;
3808         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
3809
3810         /*Sending Cfg*/
3811         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
3812         if (s32Error) {
3813
3814                 PRINT_ER("Failed to send edit station config packet\n");
3815                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
3816         }
3817
3818         WILC_CATCH(s32Error)
3819         {
3820         }
3821         WILC_FREE_IF_TRUE(pstrStationParam->pu8Rates);
3822         WILC_FREE_IF_TRUE(strWID.ps8WidVal);
3823 }
3824 #endif /*WILC_AP_EXTERNAL_MLME*/
3825
3826 #ifdef WILC_P2P
3827 /**
3828  *  @brief Handle_RemainOnChan
3829  *  @details        Sending config packet to edit station
3830  *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
3831  *  @return         NONE
3832  *  @author
3833  *  @date
3834  *  @version    1.0
3835  */
3836 static int Handle_RemainOnChan(void *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan)
3837 {
3838         s32 s32Error = WILC_SUCCESS;
3839         u8 u8remain_on_chan_flag;
3840         tstrWID strWID;
3841         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
3842
3843         /*If it's a pendig remain-on-channel, don't overwrite gWFiDrvHandle values (since incoming msg is garbbage)*/
3844         if (!pstrWFIDrv->u8RemainOnChan_pendingreq) {
3845                 pstrWFIDrv->strHostIfRemainOnChan.pVoid = pstrHostIfRemainOnChan->pVoid;
3846                 pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired;
3847                 pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady;
3848                 pstrWFIDrv->strHostIfRemainOnChan.u16Channel = pstrHostIfRemainOnChan->u16Channel;
3849                 pstrWFIDrv->strHostIfRemainOnChan.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID;
3850         } else {
3851                 /*Set the channel to use it as a wid val*/
3852                 pstrHostIfRemainOnChan->u16Channel = pstrWFIDrv->strHostIfRemainOnChan.u16Channel;
3853         }
3854
3855         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
3856                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while scanning return\n");
3857                 pstrWFIDrv->u8RemainOnChan_pendingreq = 1;
3858                 WILC_ERRORREPORT(s32Error, WILC_BUSY);
3859         }
3860         if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
3861                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while connecting return\n");
3862                 WILC_ERRORREPORT(s32Error, WILC_BUSY);
3863         }
3864
3865         #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
3866         if (g_obtainingIP || connecting) {
3867                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
3868                 WILC_ERRORREPORT(s32Error, WILC_BUSY);
3869         }
3870         #endif
3871
3872         PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", pstrHostIfRemainOnChan->u16Channel);
3873
3874         u8remain_on_chan_flag = true;
3875         strWID.u16WIDid = (u16)WID_REMAIN_ON_CHAN;
3876         strWID.enuWIDtype       = WID_STR;
3877         strWID.s32ValueSize = 2;
3878         strWID.ps8WidVal = (s8 *)WILC_MALLOC(strWID.s32ValueSize);
3879
3880         if (strWID.ps8WidVal == NULL) {
3881                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3882         }
3883
3884         strWID.ps8WidVal[0] = u8remain_on_chan_flag;
3885         strWID.ps8WidVal[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
3886
3887         /*Sending Cfg*/
3888         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3889         if (s32Error != WILC_SUCCESS) {
3890                 PRINT_ER("Failed to set remain on channel\n");
3891         }
3892
3893         WILC_CATCH(-1)
3894         {
3895                 P2P_LISTEN_STATE = 1;
3896                 WILC_TimerStart(&(pstrWFIDrv->hRemainOnChannel), pstrHostIfRemainOnChan->u32duration, (void *)pstrWFIDrv, NULL);
3897
3898                 /*Calling CFG ready_on_channel*/
3899                 if (pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady) {
3900                         pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady(pstrWFIDrv->strHostIfRemainOnChan.pVoid);
3901                 }
3902
3903                 if (pstrWFIDrv->u8RemainOnChan_pendingreq)
3904                         pstrWFIDrv->u8RemainOnChan_pendingreq = 0;
3905         }
3906         return s32Error;
3907 }
3908
3909 /**
3910  *  @brief Handle_RegisterFrame
3911  *  @details
3912  *  @param[in]
3913  *  @return         NONE
3914  *  @author
3915  *  @date
3916  *  @version    1.0
3917  */
3918 static int Handle_RegisterFrame(void *drvHandler, tstrHostIfRegisterFrame *pstrHostIfRegisterFrame)
3919 {
3920         s32 s32Error = WILC_SUCCESS;
3921         tstrWID strWID;
3922         u8 *pu8CurrByte;
3923         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
3924
3925         PRINT_D(HOSTINF_DBG, "Handling frame register Flag : %d FrameType: %d\n", pstrHostIfRegisterFrame->bReg, pstrHostIfRegisterFrame->u16FrameType);
3926
3927         /*prepare configuration packet*/
3928         strWID.u16WIDid = (u16)WID_REGISTER_FRAME;
3929         strWID.enuWIDtype = WID_STR;
3930         strWID.ps8WidVal = WILC_MALLOC(sizeof(u16) + 2);
3931         if (strWID.ps8WidVal == NULL) {
3932                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
3933         }
3934
3935         pu8CurrByte = strWID.ps8WidVal;
3936
3937         *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg;
3938         *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid;
3939         WILC_memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16));
3940
3941
3942         strWID.s32ValueSize = sizeof(u16) + 2;
3943
3944
3945         /*Sending Cfg*/
3946         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3947         if (s32Error) {
3948                 PRINT_ER("Failed to frame register config packet\n");
3949                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
3950         }
3951
3952
3953         WILC_CATCH(s32Error)
3954         {
3955         }
3956
3957         return s32Error;
3958
3959 }
3960
3961 /**
3962  *  @brief                      Handle_ListenStateExpired
3963  *  @details            Handle of listen state expiration
3964  *  @param[in]          NONE
3965  *  @return             Error code.
3966  *  @author
3967  *  @date
3968  *  @version            1.0
3969  */
3970 #define FALSE_FRMWR_CHANNEL 100
3971 static u32 Handle_ListenStateExpired(void *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan)
3972 {
3973         u8 u8remain_on_chan_flag;
3974         tstrWID strWID;
3975         s32 s32Error = WILC_SUCCESS;
3976         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
3977
3978         PRINT_D(HOSTINF_DBG, "CANCEL REMAIN ON CHAN\n");
3979
3980         /*BugID_5477*/
3981         /*Make sure we are already in listen state*/
3982         /*This is to handle duplicate expiry messages (listen timer fired and supplicant called cancel_remain_on_channel())*/
3983         if (P2P_LISTEN_STATE) {
3984                 u8remain_on_chan_flag = false;
3985                 strWID.u16WIDid = (u16)WID_REMAIN_ON_CHAN;
3986                 strWID.enuWIDtype       = WID_STR;
3987                 strWID.s32ValueSize = 2;
3988                 strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
3989
3990                 if (strWID.ps8WidVal == NULL) {
3991                         PRINT_ER("Failed to allocate memory\n");
3992                 }
3993
3994                 strWID.ps8WidVal[0] = u8remain_on_chan_flag;
3995                 strWID.ps8WidVal[1] = FALSE_FRMWR_CHANNEL;
3996
3997                 /*Sending Cfg*/
3998                 s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
3999                 if (s32Error != WILC_SUCCESS) {
4000                         PRINT_ER("Failed to set remain on channel\n");
4001                         goto _done_;
4002                 }
4003
4004                 if (pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanExpired) {
4005                         pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanExpired(pstrWFIDrv->strHostIfRemainOnChan.pVoid
4006                                                                                , pstrHostIfRemainOnChan->u32ListenSessionID);
4007                 }
4008                 P2P_LISTEN_STATE = 0;
4009         } else {
4010                 PRINT_D(GENERIC_DBG, "Not in listen state\n");
4011                 s32Error = WILC_FAIL;
4012         }
4013
4014 _done_:
4015         return s32Error;
4016 }
4017
4018
4019 /**
4020  *  @brief                      ListenTimerCB
4021  *  @details            Callback function of remain-on-channel timer
4022  *  @param[in]          NONE
4023  *  @return             Error code.
4024  *  @author
4025  *  @date
4026  *  @version            1.0
4027  */
4028 static void ListenTimerCB(void *pvArg)
4029 {
4030         s32 s32Error = WILC_SUCCESS;
4031         tstrHostIFmsg strHostIFmsg;
4032         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)pvArg;
4033         /*Stopping remain-on-channel timer*/
4034         WILC_TimerStop(&(pstrWFIDrv->hRemainOnChannel), NULL);
4035
4036         /* prepare the Timer Callback message */
4037         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4038         strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED;
4039         strHostIFmsg.drvHandler = pstrWFIDrv;
4040         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = pstrWFIDrv->strHostIfRemainOnChan.u32ListenSessionID;
4041
4042         /* send the message */
4043         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4044         if (s32Error) {
4045                 WILC_ERRORREPORT(s32Error, s32Error);
4046         }
4047         WILC_CATCH(s32Error)
4048         {
4049
4050         }
4051 }
4052 #endif
4053
4054
4055 /**
4056  *  @brief Handle_EditStation
4057  *  @details        Sending config packet to edit station
4058  *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
4059  *  @return         NONE
4060  *  @author
4061  *  @date
4062  *  @version    1.0
4063  */
4064 static void Handle_PowerManagement(void *drvHandler, tstrHostIfPowerMgmtParam *strPowerMgmtParam)
4065 {
4066         s32 s32Error = WILC_SUCCESS;
4067         tstrWID strWID;
4068         s8 s8PowerMode;
4069         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4070         strWID.u16WIDid = (u16)WID_POWER_MANAGEMENT;
4071
4072         if (strPowerMgmtParam->bIsEnabled == true)      {
4073                 s8PowerMode = MIN_FAST_PS;
4074         } else {
4075                 s8PowerMode = NO_POWERSAVE;
4076         }
4077         PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode);
4078         strWID.ps8WidVal = &s8PowerMode;
4079         strWID.s32ValueSize = sizeof(char);
4080
4081         PRINT_D(HOSTINF_DBG, "Handling Power Management\n");
4082
4083         /*Sending Cfg*/
4084         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4085         if (s32Error) {
4086                 PRINT_ER("Failed to send power management config packet\n");
4087                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
4088         }
4089
4090         WILC_CATCH(s32Error)
4091         {
4092
4093         }
4094 }
4095
4096 /**
4097  *  @brief Handle_SetMulticastFilter
4098  *  @details        Set Multicast filter in firmware
4099  *  @param[in]   tstrHostIFSetMulti* strHostIfSetMulti
4100  *  @return         NONE
4101  *  @author             asobhy
4102  *  @date
4103  *  @version    1.0
4104  */
4105 static void Handle_SetMulticastFilter(void *drvHandler, tstrHostIFSetMulti *strHostIfSetMulti)
4106 {
4107         s32 s32Error = WILC_SUCCESS;
4108         tstrWID strWID;
4109         u8 *pu8CurrByte;
4110
4111         PRINT_D(HOSTINF_DBG, "Setup Multicast Filter\n");
4112
4113         strWID.u16WIDid = (u16)WID_SETUP_MULTICAST_FILTER;
4114         strWID.enuWIDtype = WID_BIN;
4115         strWID.s32ValueSize = sizeof(tstrHostIFSetMulti) + ((strHostIfSetMulti->u32count) * ETH_ALEN);
4116         strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
4117         if (strWID.ps8WidVal == NULL) {
4118                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
4119         }
4120
4121         pu8CurrByte = strWID.ps8WidVal;
4122         *pu8CurrByte++ = (strHostIfSetMulti->bIsEnabled & 0xFF);
4123         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 8) & 0xFF);
4124         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 16) & 0xFF);
4125         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 24) & 0xFF);
4126
4127         *pu8CurrByte++ = (strHostIfSetMulti->u32count & 0xFF);
4128         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 8) & 0xFF);
4129         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 16) & 0xFF);
4130         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 24) & 0xFF);
4131
4132         if ((strHostIfSetMulti->u32count) > 0)
4133                 memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->u32count) * ETH_ALEN));
4134
4135         /*Sending Cfg*/
4136         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)drvHandler);
4137         if (s32Error) {
4138                 PRINT_ER("Failed to send setup multicast config packet\n");
4139                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
4140         }
4141
4142         WILC_CATCH(s32Error)
4143         {
4144         }
4145         WILC_FREE_IF_TRUE(strWID.ps8WidVal);
4146
4147 }
4148
4149
4150 /*BugID_5222*/
4151 /**
4152  *  @brief                      Handle_AddBASession
4153  *  @details            Add block ack session
4154  *  @param[in]          tstrHostIFSetMulti* strHostIfSetMulti
4155  *  @return             NONE
4156  *  @author             Amr Abdel-Moghny
4157  *  @date                       Feb. 2014
4158  *  @version            9.0
4159  */
4160 static s32 Handle_AddBASession(void *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
4161 {
4162         s32 s32Error = WILC_SUCCESS;
4163         tstrWID strWID;
4164         int AddbaTimeout = 100;
4165         char *ptr = NULL;
4166         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4167
4168         PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x \nTID=%d \nBufferSize == %d \nSessionTimeOut = %d\n",
4169                 strHostIfBASessionInfo->au8Bssid[0],
4170                 strHostIfBASessionInfo->au8Bssid[1],
4171                 strHostIfBASessionInfo->au8Bssid[2],
4172                 strHostIfBASessionInfo->u16BufferSize,
4173                 strHostIfBASessionInfo->u16SessionTimeout,
4174                 strHostIfBASessionInfo->u8Ted);
4175
4176         strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
4177         strWID.enuWIDtype = WID_STR;
4178         strWID.ps8WidVal = (u8 *)WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
4179         strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
4180         ptr = strWID.ps8WidVal;
4181         /* *ptr++ = 0x14; */
4182         *ptr++ = 0x14;
4183         *ptr++ = 0x3;
4184         *ptr++ = 0x0;
4185         WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4186         ptr += ETH_ALEN;
4187         *ptr++ = strHostIfBASessionInfo->u8Ted;
4188         /* BA Policy*/
4189         *ptr++ = 1;
4190         /* Buffer size*/
4191         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
4192         *ptr++ = ((strHostIfBASessionInfo->u16BufferSize >> 16) & 0xFF);
4193         /* BA timeout*/
4194         *ptr++ = (strHostIfBASessionInfo->u16SessionTimeout & 0xFF);
4195         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
4196         /* ADDBA timeout*/
4197         *ptr++ = (AddbaTimeout & 0xFF);
4198         *ptr++ = ((AddbaTimeout >> 16) & 0xFF);
4199         /* Group Buffer Max Frames*/
4200         *ptr++ = 8;
4201         /* Group Buffer Timeout */
4202         *ptr++ = 0;
4203
4204         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4205         if (s32Error)
4206                 PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n");
4207
4208
4209         strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
4210         strWID.enuWIDtype = WID_STR;
4211         strWID.s32ValueSize = 15;
4212         ptr = strWID.ps8WidVal;
4213         /* *ptr++ = 0x14; */
4214         *ptr++ = 15;
4215         *ptr++ = 7;
4216         *ptr++ = 0x2;
4217         WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4218         ptr += ETH_ALEN;
4219         /* TID*/
4220         *ptr++ = strHostIfBASessionInfo->u8Ted;
4221         /* Max Num MSDU */
4222         *ptr++ = 8;
4223         /* BA timeout*/
4224         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
4225         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
4226         /*Ack-Policy */
4227         *ptr++ = 3;
4228         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4229
4230         if (strWID.ps8WidVal != NULL)
4231                 WILC_FREE(strWID.ps8WidVal);
4232
4233         return s32Error;
4234
4235 }
4236
4237
4238 /*BugID_5222*/
4239 /**
4240  *  @brief                      Handle_DelBASession
4241  *  @details            Delete block ack session
4242  *  @param[in]          tstrHostIFSetMulti* strHostIfSetMulti
4243  *  @return             NONE
4244  *  @author             Amr Abdel-Moghny
4245  *  @date                       Feb. 2013
4246  *  @version            9.0
4247  */
4248 static s32 Handle_DelBASession(void *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
4249 {
4250         s32 s32Error = WILC_SUCCESS;
4251         tstrWID strWID;
4252         char *ptr = NULL;
4253         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4254
4255         PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x \nTID=%d\n",
4256                 strHostIfBASessionInfo->au8Bssid[0],
4257                 strHostIfBASessionInfo->au8Bssid[1],
4258                 strHostIfBASessionInfo->au8Bssid[2],
4259                 strHostIfBASessionInfo->u8Ted);
4260
4261         strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
4262         strWID.enuWIDtype = WID_STR;
4263         strWID.ps8WidVal = (u8 *)WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
4264         strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
4265         ptr = strWID.ps8WidVal;
4266         /* *ptr++ = 0x14; */
4267         *ptr++ = 0x14;
4268         *ptr++ = 0x3;
4269         *ptr++ = 0x2;
4270         WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4271         ptr += ETH_ALEN;
4272         *ptr++ = strHostIfBASessionInfo->u8Ted;
4273         /* BA direction = recipent*/
4274         *ptr++ = 0;
4275         /* Delba Reason */
4276         *ptr++ = 32; /* Unspecific QOS reason */
4277
4278         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4279         if (s32Error)
4280                 PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
4281
4282
4283         strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
4284         strWID.enuWIDtype = WID_STR;
4285         strWID.s32ValueSize = 15;
4286         ptr = strWID.ps8WidVal;
4287         /* *ptr++ = 0x14; */
4288         *ptr++ = 15;
4289         *ptr++ = 7;
4290         *ptr++ = 0x3;
4291         WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4292         ptr += ETH_ALEN;
4293         /* TID*/
4294         *ptr++ = strHostIfBASessionInfo->u8Ted;
4295
4296         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4297
4298         if (strWID.ps8WidVal != NULL)
4299                 WILC_FREE(strWID.ps8WidVal);
4300
4301         /*BugID_5222*/
4302         up(&hWaitResponse);
4303
4304         return s32Error;
4305
4306 }
4307
4308
4309 /**
4310  *  @brief                      Handle_DelAllRxBASessions
4311  *  @details            Delete all Rx BA sessions
4312  *  @param[in]          tstrHostIFSetMulti* strHostIfSetMulti
4313  *  @return             NONE
4314  *  @author             Abdelrahman Sobhy
4315  *  @date                       Feb. 2013
4316  *  @version            9.0
4317  */
4318 static s32 Handle_DelAllRxBASessions(void *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
4319 {
4320         s32 s32Error = WILC_SUCCESS;
4321         tstrWID strWID;
4322         char *ptr = NULL;
4323         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
4324
4325         PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x \nTID=%d\n",
4326                 strHostIfBASessionInfo->au8Bssid[0],
4327                 strHostIfBASessionInfo->au8Bssid[1],
4328                 strHostIfBASessionInfo->au8Bssid[2],
4329                 strHostIfBASessionInfo->u8Ted);
4330
4331         strWID.u16WIDid = (u16)WID_DEL_ALL_RX_BA;
4332         strWID.enuWIDtype = WID_STR;
4333         strWID.ps8WidVal = (u8 *)WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
4334         strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
4335         ptr = strWID.ps8WidVal;
4336         *ptr++ = 0x14;
4337         *ptr++ = 0x3;
4338         *ptr++ = 0x2;
4339         WILC_memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
4340         ptr += ETH_ALEN;
4341         *ptr++ = strHostIfBASessionInfo->u8Ted;
4342         /* BA direction = recipent*/
4343         *ptr++ = 0;
4344         /* Delba Reason */
4345         *ptr++ = 32; /* Unspecific QOS reason */
4346
4347         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
4348         if (s32Error)
4349                 PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
4350
4351
4352         if (strWID.ps8WidVal != NULL)
4353                 WILC_FREE(strWID.ps8WidVal);
4354
4355         /*BugID_5222*/
4356         up(&hWaitResponse);
4357
4358         return s32Error;
4359
4360 }
4361
4362 /**
4363  *  @brief hostIFthread
4364  *  @details        Main thread to handle message queue requests
4365  *  @param[in]   void* pvArg
4366  *  @return         NONE
4367  *  @author
4368  *  @date
4369  *  @version    1.0
4370  */
4371 static int hostIFthread(void *pvArg)
4372 {
4373         u32 u32Ret;
4374         tstrHostIFmsg strHostIFmsg;
4375         tstrWILC_WFIDrv *pstrWFIDrv;
4376
4377         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4378
4379         while (1) {
4380                 WILC_MsgQueueRecv(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), &u32Ret, NULL);
4381                 pstrWFIDrv = (tstrWILC_WFIDrv *)strHostIFmsg.drvHandler;
4382                 if (strHostIFmsg.u16MsgId == HOST_IF_MSG_EXIT) {
4383                         PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n");
4384                         break;
4385                 }
4386
4387
4388                 /*Re-Queue HIF message*/
4389                 if ((!g_wilc_initialized)) {
4390                         PRINT_D(GENERIC_DBG, "--WAIT--");
4391                         WILC_Sleep(200);
4392                         WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4393                         continue;
4394                 }
4395
4396                 if (strHostIFmsg.u16MsgId == HOST_IF_MSG_CONNECT && pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
4397                         PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n");
4398                         WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4399                         WILC_Sleep(2);
4400                         continue;
4401                 }
4402
4403                 switch (strHostIFmsg.u16MsgId) {
4404                 case HOST_IF_MSG_Q_IDLE:
4405                         Handle_wait_msg_q_empty();
4406                         break;
4407
4408                 case HOST_IF_MSG_SCAN:
4409                         Handle_Scan(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr);
4410                         break;
4411
4412                 case HOST_IF_MSG_CONNECT:
4413                         Handle_Connect(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr);
4414                         break;
4415
4416                 /*BugID_5137*/
4417                 case HOST_IF_MSG_FLUSH_CONNECT:
4418                         Handle_FlushConnect(strHostIFmsg.drvHandler);
4419                         break;
4420
4421                 case HOST_IF_MSG_RCVD_NTWRK_INFO:
4422                         Handle_RcvdNtwrkInfo(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo);
4423                         break;
4424
4425                 case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
4426                         Handle_RcvdGnrlAsyncInfo(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo);
4427                         break;
4428
4429                 case HOST_IF_MSG_KEY:
4430                         Handle_Key(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr);
4431                         break;
4432
4433                 case HOST_IF_MSG_CFG_PARAMS:
4434
4435                         Handle_CfgParam(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFCfgParamAttr);
4436                         break;
4437
4438                 case HOST_IF_MSG_SET_CHANNEL:
4439                         Handle_SetChannel(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFSetChan);
4440                         break;
4441
4442                 case HOST_IF_MSG_DISCONNECT:
4443                         Handle_Disconnect(strHostIFmsg.drvHandler);
4444                         break;
4445
4446                 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
4447                         WILC_TimerStop(&(pstrWFIDrv->hScanTimer), NULL);
4448                         PRINT_D(HOSTINF_DBG, "scan completed successfully\n");
4449
4450                         /*BugID_5213*/
4451                         /*Allow chip sleep, only if both interfaces are not connected*/
4452                         if (!linux_wlan_get_num_conn_ifcs()) {
4453                                 chip_sleep_manually(INFINITE_SLEEP_TIME);
4454                         }
4455
4456                         Handle_ScanDone(strHostIFmsg.drvHandler, SCAN_EVENT_DONE);
4457
4458                                 #ifdef WILC_P2P
4459                         if (pstrWFIDrv->u8RemainOnChan_pendingreq)
4460                                 Handle_RemainOnChan(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan);
4461                                 #endif
4462
4463                         break;
4464
4465                 case HOST_IF_MSG_GET_RSSI:
4466                         Handle_GetRssi(strHostIFmsg.drvHandler);
4467                         break;
4468
4469                 case HOST_IF_MSG_GET_LINKSPEED:
4470                         Handle_GetLinkspeed(strHostIFmsg.drvHandler);
4471                         break;
4472
4473                 case HOST_IF_MSG_GET_STATISTICS:
4474                         Handle_GetStatistics(strHostIFmsg.drvHandler, (tstrStatistics *)strHostIFmsg.uniHostIFmsgBody.pUserData);
4475                         break;
4476
4477                 case HOST_IF_MSG_GET_CHNL:
4478                         Handle_GetChnl(strHostIFmsg.drvHandler);
4479                         break;
4480
4481 #ifdef WILC_AP_EXTERNAL_MLME
4482                 case HOST_IF_MSG_ADD_BEACON:
4483                         Handle_AddBeacon(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFSetBeacon);
4484                         break;
4485
4486                 case HOST_IF_MSG_DEL_BEACON:
4487                         Handle_DelBeacon(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFDelBeacon);
4488                         break;
4489
4490                 case HOST_IF_MSG_ADD_STATION:
4491                         Handle_AddStation(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strAddStaParam);
4492                         break;
4493
4494                 case HOST_IF_MSG_DEL_STATION:
4495                         Handle_DelStation(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strDelStaParam);
4496                         break;
4497
4498                 case HOST_IF_MSG_EDIT_STATION:
4499                         Handle_EditStation(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strEditStaParam);
4500                         break;
4501
4502                 case HOST_IF_MSG_GET_INACTIVETIME:
4503                         Handle_Get_InActiveTime(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfStaInactiveT);
4504                         break;
4505
4506 #endif /*WILC_AP_EXTERNAL_MLME*/
4507                 case HOST_IF_MSG_SCAN_TIMER_FIRED:
4508                         PRINT_D(HOSTINF_DBG, "Scan Timeout\n");
4509
4510                         Handle_ScanDone(strHostIFmsg.drvHandler, SCAN_EVENT_ABORTED);
4511                         break;
4512
4513                 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
4514                         PRINT_D(HOSTINF_DBG, "Connect Timeout \n");
4515                         Handle_ConnectTimeout(strHostIFmsg.drvHandler);
4516                         break;
4517
4518                 case HOST_IF_MSG_POWER_MGMT:
4519                         Handle_PowerManagement(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strPowerMgmtparam);
4520                         break;
4521
4522                 case HOST_IF_MSG_SET_WFIDRV_HANDLER:
4523                         Handle_SetWfiDrvHandler(&strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler);
4524                         break;
4525
4526                 case HOST_IF_MSG_SET_OPERATION_MODE:
4527                         Handle_SetOperationMode(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfSetOperationMode);
4528                         break;
4529
4530                 case HOST_IF_MSG_SET_IPADDRESS:
4531                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
4532                         Handle_set_IPAddress(strHostIFmsg.drvHandler, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx);
4533                         break;
4534
4535                 case HOST_IF_MSG_GET_IPADDRESS:
4536                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
4537                         Handle_get_IPAddress(strHostIFmsg.drvHandler, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx);
4538                         break;
4539
4540                 /*BugID_5077*/
4541                 case HOST_IF_MSG_SET_MAC_ADDRESS:
4542                         Handle_SetMacAddress(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMacAddress);
4543                         break;
4544
4545                 /*BugID_5213*/
4546                 case HOST_IF_MSG_GET_MAC_ADDRESS:
4547                         Handle_GetMacAddress(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfGetMacAddress);
4548                         break;
4549
4550 #ifdef WILC_P2P
4551                 case HOST_IF_MSG_REMAIN_ON_CHAN:
4552                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REMAIN_ON_CHAN\n");
4553                         Handle_RemainOnChan(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan);
4554                         break;
4555
4556                 case HOST_IF_MSG_REGISTER_FRAME:
4557                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REGISTER_FRAME\n");
4558                         Handle_RegisterFrame(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame);
4559                         break;
4560
4561                 case HOST_IF_MSG_LISTEN_TIMER_FIRED:
4562                         Handle_ListenStateExpired(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan);
4563                         break;
4564
4565                         #endif
4566                 case HOST_IF_MSG_SET_MULTICAST_FILTER:
4567                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_MULTICAST_FILTER\n");
4568                         Handle_SetMulticastFilter(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMulti);
4569                         break;
4570
4571                 /*BugID_5222*/
4572                 case HOST_IF_MSG_ADD_BA_SESSION:
4573                         Handle_AddBASession(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo);
4574                         break;
4575
4576                 case HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS:
4577                         Handle_DelAllRxBASessions(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo);
4578                         break;
4579
4580                 case HOST_IF_MSG_DEL_ALL_STA:
4581                         Handle_DelAllSta(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFDelAllSta);
4582                         break;
4583
4584                 default:
4585                         PRINT_ER("[Host Interface] undefined Received Msg ID  \n");
4586                         break;
4587                 }
4588         }
4589
4590         PRINT_D(HOSTINF_DBG, "Releasing thread exit semaphore\n");
4591         up(&hSemHostIFthrdEnd);
4592         return 0;
4593 }
4594
4595 static void TimerCB_Scan(void *pvArg)
4596 {
4597         tstrHostIFmsg strHostIFmsg;
4598
4599         /* prepare the Timer Callback message */
4600         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4601         strHostIFmsg.drvHandler = pvArg;
4602         strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN_TIMER_FIRED;
4603
4604         /* send the message */
4605         WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4606 }
4607
4608 static void TimerCB_Connect(void *pvArg)
4609 {
4610         tstrHostIFmsg strHostIFmsg;
4611
4612         /* prepare the Timer Callback message */
4613         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4614         strHostIFmsg.drvHandler = pvArg;
4615         strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT_TIMER_FIRED;
4616
4617         /* send the message */
4618         WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4619 }
4620
4621
4622 /**
4623  *  @brief              removes wpa/wpa2 keys
4624  *  @details    only in BSS STA mode if External Supplicant support is enabled.
4625  *                              removes all WPA/WPA2 station key entries from MAC hardware.
4626  *  @param[in,out] handle to the wifi driver
4627  *  @param[in]  6 bytes of Station Adress in the station entry table
4628  *  @return             Error code indicating success/failure
4629  *  @note
4630  *  @author             zsalah
4631  *  @date               8 March 2012
4632  *  @version            1.0
4633  */
4634 /* Check implementation in core adding 9 bytes to the input! */
4635 s32 host_int_remove_key(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8StaAddress)
4636 {
4637         s32 s32Error = WILC_SUCCESS;
4638         tstrWID strWID;
4639         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
4640
4641         strWID.u16WIDid = (u16)WID_REMOVE_KEY;
4642         strWID.enuWIDtype       = WID_STR;
4643         strWID.ps8WidVal        = (s8 *)pu8StaAddress;
4644         strWID.s32ValueSize = 6;
4645
4646         return s32Error;
4647
4648 }
4649
4650 /**
4651  *  @brief              removes WEP key
4652  *  @details    valid only in BSS STA mode if External Supplicant support is enabled.
4653  *                              remove a WEP key entry from MAC HW.
4654  *                              The BSS Station automatically finds the index of the entry using its
4655  *                              BSS ID and removes that entry from the MAC hardware.
4656  *  @param[in,out] handle to the wifi driver
4657  *  @param[in]  6 bytes of Station Adress in the station entry table
4658  *  @return             Error code indicating success/failure
4659  *  @note               NO need for the STA add since it is not used for processing
4660  *  @author             zsalah
4661  *  @date               8 March 2012
4662  *  @version            1.0
4663  */
4664 s32 host_int_remove_wep_key(WILC_WFIDrvHandle hWFIDrv, u8 u8keyIdx)
4665 {
4666         s32 s32Error = WILC_SUCCESS;
4667         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4668         tstrHostIFmsg strHostIFmsg;
4669
4670
4671         if (pstrWFIDrv == NULL) {
4672                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4673         }
4674
4675         /* prepare the Remove Wep Key Message */
4676         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4677
4678
4679         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
4680         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
4681         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = REMOVEKEY;
4682         strHostIFmsg.drvHandler = hWFIDrv;
4683
4684
4685
4686         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4687         uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8keyIdx;
4688
4689         /* send the message */
4690         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4691         if (s32Error)
4692                 PRINT_ER("Error in sending message queue : Request to remove WEP key \n");
4693         down(&(pstrWFIDrv->hSemTestKeyBlock));
4694
4695         WILC_CATCH(s32Error)
4696         {
4697
4698         }
4699         return s32Error;
4700 }
4701
4702 /**
4703  *  @brief              sets WEP default key
4704  *  @details    Sets the index of the WEP encryption key in use,
4705  *                              in the key table
4706  *  @param[in,out] handle to the wifi driver
4707  *  @param[in]  key index ( 0, 1, 2, 3)
4708  *  @return             Error code indicating success/failure
4709  *  @note
4710  *  @author             zsalah
4711  *  @date               8 March 2012
4712  *  @version            1.0
4713  */
4714 s32 host_int_set_WEPDefaultKeyID(WILC_WFIDrvHandle hWFIDrv, u8 u8Index)
4715 {
4716         s32 s32Error = WILC_SUCCESS;
4717         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4718         tstrHostIFmsg strHostIFmsg;
4719
4720
4721         if (pstrWFIDrv == NULL) {
4722                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4723         }
4724
4725         /* prepare the Key Message */
4726         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4727
4728
4729         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
4730         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
4731         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = DEFAULTKEY;
4732         strHostIFmsg.drvHandler = hWFIDrv;
4733
4734
4735         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4736         uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Index;
4737
4738         /* send the message */
4739         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4740         if (s32Error)
4741                 PRINT_ER("Error in sending message queue : Default key index\n");
4742         down(&(pstrWFIDrv->hSemTestKeyBlock));
4743
4744         WILC_CATCH(s32Error)
4745         {
4746
4747         }
4748
4749         return s32Error;
4750 }
4751
4752 /**
4753  *  @brief              sets WEP deafault key
4754  *  @details    valid only in BSS STA mode if External Supplicant support is enabled.
4755  *                              sets WEP key entry into MAC hardware when it receives the
4756  *                              corresponding request from NDIS.
4757  *  @param[in,out] handle to the wifi driver
4758  *  @param[in]  message containing WEP Key in the following format
4759  *|---------------------------------------|
4760  *|Key ID Value | Key Length |  Key             |
4761  *|-------------|------------|------------|
4762  |      1byte     |             1byte  | Key Length     |
4763  ||---------------------------------------|
4764  |
4765  *  @return             Error code indicating success/failure
4766  *  @note
4767  *  @author             zsalah
4768  *  @date               8 March 2012
4769  *  @version            1.0
4770  */
4771 s32 host_int_add_wep_key_bss_sta(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx)
4772 {
4773
4774         s32 s32Error = WILC_SUCCESS;
4775         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4776         tstrHostIFmsg strHostIFmsg;
4777
4778         if (pstrWFIDrv == NULL) {
4779                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4780
4781         }
4782
4783         /* prepare the Key Message */
4784         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4785
4786
4787         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
4788         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
4789         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
4790         strHostIFmsg.drvHandler = hWFIDrv;
4791
4792
4793         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4794         uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = (u8 *)WILC_MALLOC(u8WepKeylen);
4795
4796         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
4797                     pu8WepKey, u8WepKeylen);
4798
4799
4800         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4801         uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen = (u8WepKeylen);
4802
4803         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4804         uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Keyidx;
4805
4806         /* send the message */
4807         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4808         if (s32Error)
4809                 PRINT_ER("Error in sending message queue :WEP Key\n");
4810         down(&(pstrWFIDrv->hSemTestKeyBlock));
4811
4812         WILC_CATCH(s32Error)
4813         {
4814
4815         }
4816         return s32Error;
4817
4818 }
4819
4820 #ifdef WILC_AP_EXTERNAL_MLME
4821 /**
4822  *
4823  *  @brief              host_int_add_wep_key_bss_ap
4824  *  @details    valid only in BSS AP mode if External Supplicant support is enabled.
4825  *                              sets WEP key entry into MAC hardware when it receives the
4826  *
4827  *                              corresponding request from NDIS.
4828  *  @param[in,out] handle to the wifi driver
4829  *
4830  *
4831  *  @return             Error code indicating success/failure
4832  *  @note
4833  *  @author             mdaftedar
4834  *  @date               28 FEB 2013
4835  *  @version            1.0
4836  */
4837 s32 host_int_add_wep_key_bss_ap(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type)
4838 {
4839
4840         s32 s32Error = WILC_SUCCESS;
4841         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4842         tstrHostIFmsg strHostIFmsg;
4843         u8 i;
4844
4845         if (pstrWFIDrv == NULL) {
4846                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4847
4848         }
4849
4850         /* prepare the Key Message */
4851         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4852
4853         if (INFO) {
4854                 for (i = 0; i < u8WepKeylen; i++)
4855                         PRINT_INFO(HOSTAPD_DBG, "KEY is %x\n", pu8WepKey[i]);
4856         }
4857         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
4858         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
4859         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY_AP;
4860         strHostIFmsg.drvHandler = hWFIDrv;
4861
4862
4863         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4864         uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = (u8 *)WILC_MALLOC((u8WepKeylen));
4865
4866
4867         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
4868                     pu8WepKey, (u8WepKeylen));
4869
4870
4871         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4872         uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen = (u8WepKeylen);
4873
4874         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4875         uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Keyidx;
4876
4877         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4878         uniHostIFkeyAttr.strHostIFwepAttr.u8mode = u8mode;
4879
4880         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4881         uniHostIFkeyAttr.strHostIFwepAttr.tenuAuth_type = tenuAuth_type;
4882         /* send the message */
4883         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4884
4885         if (s32Error)
4886                 PRINT_ER("Error in sending message queue :WEP Key\n");
4887         down(&(pstrWFIDrv->hSemTestKeyBlock));
4888
4889         WILC_CATCH(s32Error)
4890         {
4891
4892         }
4893         return s32Error;
4894
4895 }
4896 #endif
4897 /**
4898  *  @brief              adds ptk Key
4899  *  @details
4900  *  @param[in,out] handle to the wifi driver
4901  *  @param[in]  message containing PTK Key in the following format
4902  *|-----------------------------------------------------------------------------|
4903  *|Station address | Key Length |       Temporal Key | Rx Michael Key |Tx Michael Key |
4904  *|----------------|------------|--------------|----------------|---------------|
4905  |      6 bytes          |      1byte     |   16 bytes   |        8 bytes         |        8 bytes        |
4906  ||-----------------------------------------------------------------------------|
4907  *  @return             Error code indicating success/failure
4908  *  @note
4909  *  @author             zsalah
4910  *  @date               8 March 2012
4911  *  @version            1.0
4912  */
4913 s32 host_int_add_ptk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
4914                              const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx)
4915 {
4916         s32 s32Error = WILC_SUCCESS;
4917         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
4918         tstrHostIFmsg strHostIFmsg;
4919         u8 u8KeyLen = u8PtkKeylen;
4920         u32 i;
4921         if (pstrWFIDrv == NULL) {
4922                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
4923         }
4924         if (pu8RxMic != NULL) {
4925                 u8KeyLen += RX_MIC_KEY_LEN;
4926         }
4927         if (pu8TxMic != NULL) {
4928                 u8KeyLen += TX_MIC_KEY_LEN;
4929         }
4930
4931         /* prepare the Key Message */
4932         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
4933
4934
4935         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
4936         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WPAPtk;
4937         #ifdef WILC_AP_EXTERNAL_MLME
4938         if (mode == AP_MODE) {
4939                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY_AP;
4940                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4941                 uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx = u8Idx;
4942         }
4943         #endif
4944         if (mode == STATION_MODE)
4945                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
4946
4947
4948         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4949         uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = (u8 *)WILC_MALLOC(u8PtkKeylen);
4950
4951
4952         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
4953                     pu8Ptk, u8PtkKeylen);
4954
4955         if (pu8RxMic != NULL) {
4956
4957                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16,
4958                             pu8RxMic, RX_MIC_KEY_LEN);
4959                 if (INFO) {
4960                         for (i = 0; i < RX_MIC_KEY_LEN; i++)
4961                                 PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, pu8RxMic[i]);
4962                 }
4963         }
4964         if (pu8TxMic != NULL) {
4965
4966                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24,
4967                             pu8TxMic, TX_MIC_KEY_LEN);
4968                 if (INFO) {
4969                         for (i = 0; i < TX_MIC_KEY_LEN; i++)
4970                                 PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, pu8TxMic[i]);
4971                 }
4972         }
4973
4974         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4975         uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen = u8KeyLen;
4976
4977         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4978         uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode = u8Ciphermode;
4979         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
4980         uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr = mac_addr;
4981         strHostIFmsg.drvHandler = hWFIDrv;
4982
4983         /* send the message */
4984         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
4985
4986         if (s32Error)
4987                 PRINT_ER("Error in sending message queue:  PTK Key\n");
4988
4989         /* ////////////// */
4990         down(&(pstrWFIDrv->hSemTestKeyBlock));
4991         /* WILC_Sleep(100); */
4992         /* /////// */
4993
4994         WILC_CATCH(s32Error)
4995         {
4996
4997         }
4998
4999         return s32Error;
5000 }
5001
5002 /**
5003  *  @brief              adds Rx GTk Key
5004  *  @details
5005  *  @param[in,out] handle to the wifi driver
5006  *  @param[in]  pu8RxGtk : contains temporal key | Rx Mic | Tx Mic
5007  *                              u8GtkKeylen :The total key length
5008  *
5009  *  @return             Error code indicating success/failure
5010  *  @note
5011  *  @author             zsalah
5012  *  @date               8 March 2012
5013  *  @version            1.0
5014  */
5015 s32 host_int_add_rx_gtk(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen,
5016                                 u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC,
5017                                 const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode)
5018 {
5019         s32 s32Error = WILC_SUCCESS;
5020         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5021         tstrHostIFmsg strHostIFmsg;
5022         u8 u8KeyLen = u8GtkKeylen;
5023
5024         if (pstrWFIDrv == NULL) {
5025                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5026         }
5027         /* prepare the Key Message */
5028         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5029
5030
5031         if (pu8RxMic != NULL) {
5032                 u8KeyLen += RX_MIC_KEY_LEN;
5033         }
5034         if (pu8TxMic != NULL) {
5035                 u8KeyLen += TX_MIC_KEY_LEN;
5036         }
5037         if (KeyRSC != NULL) {
5038                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5039                 uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq = (u8 *)WILC_MALLOC(u32KeyRSClen);
5040
5041                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq,
5042                             KeyRSC, u32KeyRSClen);
5043         }
5044
5045
5046         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
5047         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WPARxGtk;
5048         strHostIFmsg.drvHandler = hWFIDrv;
5049
5050     #ifdef WILC_AP_EXTERNAL_MLME
5051         if (mode == AP_MODE) {
5052                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY_AP;
5053                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode = u8Ciphermode;
5054         }
5055     #endif
5056         if (mode == STATION_MODE)
5057                 strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
5058
5059
5060         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5061         uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = (u8 *)WILC_MALLOC(u8KeyLen);
5062
5063         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
5064                     pu8RxGtk, u8GtkKeylen);
5065
5066         if (pu8RxMic != NULL) {
5067
5068                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16,
5069                             pu8RxMic, RX_MIC_KEY_LEN);
5070
5071         }
5072         if (pu8TxMic != NULL) {
5073
5074                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24,
5075                             pu8TxMic, TX_MIC_KEY_LEN);
5076
5077         }
5078
5079         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5080         uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx = u8KeyIdx;
5081         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5082         uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen = u8KeyLen;
5083
5084         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5085         uniHostIFkeyAttr.strHostIFwpaAttr.u8seqlen = u32KeyRSClen;
5086
5087
5088
5089         /* send the message */
5090         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5091         if (s32Error)
5092                 PRINT_ER("Error in sending message queue:  RX GTK\n");
5093         /* ////////////// */
5094         down(&(pstrWFIDrv->hSemTestKeyBlock));
5095         /* WILC_Sleep(100); */
5096         /* /////// */
5097
5098         WILC_CATCH(s32Error)
5099         {
5100
5101         }
5102         return s32Error;
5103 }
5104 #if 0
5105 /**
5106  *  @brief                      host_int_add_tx_gtk
5107  *  @details            adds Tx GTk Key
5108  *  @param[in,out] handle to the wifi driver
5109  *  @param[in]  message containing Tx GTK Key in the following format
5110  *|----------------------------------------------------|
5111  | KeyID | Key Length | Temporal Key    | Tx Michael Key |
5112  ||-------|------------|--------------|----------------|
5113  ||1 byte |  1 byte      |   16 bytes   |         8 bytes        |
5114  ||----------------------------------------------------|
5115  *  @return             Error code indicating success/failure
5116  *  @note
5117  *  @author             zsalah
5118  *  @date               8 March 2012
5119  *  @version            1.0
5120  */
5121 s32 host_int_add_tx_gtk(WILC_WFIDrvHandle hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8 u8KeyIdx)
5122 {
5123         s32 s32Error = WILC_SUCCESS;
5124         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5125         tstrHostIFmsg strHostIFmsg;
5126
5127         if (pstrWFIDrv == NULL) {
5128                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5129         }
5130
5131         /* prepare the Key Message */
5132         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5133
5134         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
5135         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WPATxGtk;
5136         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
5137
5138         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
5139         uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = (u8 *)WILC_MALLOC(u8KeyLen);
5140
5141         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
5142                     pu8TxGtk, u8KeyLen);
5143
5144         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen = u8KeyLen;
5145
5146         /* send the message */
5147         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5148         if (s32Error)
5149                 PRINT_ER("Error in sending message queue: TX GTK\n");
5150
5151         /* ////////////// */
5152         down(&hSemTestKeyBlock);
5153         WILC_Sleep(100);
5154         /* /////// */
5155
5156         WILC_CATCH(s32Error)
5157         {
5158
5159         }
5160         return s32Error;
5161 }
5162 #endif
5163 /**
5164  *  @brief              host_int_set_pmkid_info
5165  *  @details    caches the pmkid valid only in BSS STA mode if External Supplicant
5166  *                              support is enabled. This Function sets the PMKID in firmware
5167  *                              when host drivr receives the corresponding request from NDIS.
5168  *                              The firmware then includes theset PMKID in the appropriate
5169  *                              management frames
5170  *  @param[in,out] handle to the wifi driver
5171  *  @param[in]  message containing PMKID Info in the following format
5172  *|-----------------------------------------------------------------|
5173  *|NumEntries | BSSID[1] | PMKID[1] |  ...      | BSSID[K] | PMKID[K] |
5174  *|-----------|------------|----------|-------|----------|----------|
5175  |         1    |               6        |   16         |  ...  |        6         |    16        |
5176  ||-----------------------------------------------------------------|
5177  *  @return             Error code indicating success/failure
5178  *  @note
5179  *  @author             zsalah
5180  *  @date               8 March 2012
5181  *  @version            1.0
5182  */
5183 s32 host_int_set_pmkid_info(WILC_WFIDrvHandle hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray)
5184 {
5185         s32 s32Error = WILC_SUCCESS;
5186         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5187         tstrHostIFmsg strHostIFmsg;
5188         u32 i;
5189
5190
5191         if (pstrWFIDrv == NULL) {
5192                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5193         }
5194
5195         /* prepare the Key Message */
5196         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5197
5198         strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
5199         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = PMKSA;
5200         strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
5201         strHostIFmsg.drvHandler = hWFIDrv;
5202
5203         for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) {
5204
5205                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid,
5206                             ETH_ALEN);
5207
5208                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid,
5209                             PMKID_LEN);
5210         }
5211
5212         /* send the message */
5213         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5214         if (s32Error)
5215                 PRINT_ER(" Error in sending messagequeue: PMKID Info\n");
5216
5217         WILC_CATCH(s32Error)
5218         {
5219
5220         }
5221
5222         return s32Error;
5223 }
5224
5225 /**
5226  *  @brief              gets the cached the pmkid info
5227  *  @details    valid only in BSS STA mode if External Supplicant
5228  *                              support is enabled. This Function sets the PMKID in firmware
5229  *                              when host drivr receives the corresponding request from NDIS.
5230  *                              The firmware then includes theset PMKID in the appropriate
5231  *                              management frames
5232  *  @param[in,out] handle to the wifi driver,
5233  *                                message containing PMKID Info in the following format
5234  *|-----------------------------------------------------------------|
5235  *|NumEntries | BSSID[1] | PMKID[1] |  ...      | BSSID[K] | PMKID[K] |
5236  *|-----------|------------|----------|-------|----------|----------|
5237  |         1    |               6        |   16         |  ...  |        6         |    16        |
5238  ||-----------------------------------------------------------------|
5239  *  @param[in]
5240  *  @return             Error code indicating success/failure
5241  *  @note
5242  *  @author             zsalah
5243  *  @date               8 March 2012
5244  *  @version            1.0
5245  */
5246 s32 host_int_get_pmkid_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PmkidInfoArray,
5247                                     u32 u32PmkidInfoLen)
5248 {
5249         s32 s32Error = WILC_SUCCESS;
5250         tstrWID strWID;
5251         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5252
5253         strWID.u16WIDid = (u16)WID_PMKID_INFO;
5254         strWID.enuWIDtype       = WID_STR;
5255         strWID.s32ValueSize = u32PmkidInfoLen;
5256         strWID.ps8WidVal = pu8PmkidInfoArray;
5257
5258         return s32Error;
5259 }
5260
5261 /**
5262  *  @brief              sets the pass phrase
5263  *  @details    AP/STA mode. This function gives the pass phrase used to
5264  *                              generate the Pre-Shared Key when WPA/WPA2 is enabled
5265  *                              The length of the field can vary from 8 to 64 bytes,
5266  *                              the lower layer should get the
5267  *  @param[in,out] handle to the wifi driver,
5268  *  @param[in]   String containing PSK
5269  *  @return             Error code indicating success/failure
5270  *  @note
5271  *  @author             zsalah
5272  *  @date               8 March 2012
5273  *  @version            1.0
5274  */
5275 s32 host_int_set_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv, u8 *pu8PassPhrase,
5276                                                  u8 u8Psklength)
5277 {
5278         s32 s32Error = WILC_SUCCESS;
5279         tstrWID strWID;
5280         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5281
5282         /* u8 u8Psklength = WILC_strlen(pu8PassPhrase); */
5283         /*validating psk length*/
5284         if ((u8Psklength > 7) && (u8Psklength < 65)) {
5285                 strWID.u16WIDid = (u16)WID_11I_PSK;
5286                 strWID.enuWIDtype       = WID_STR;
5287                 strWID.ps8WidVal        = pu8PassPhrase;
5288                 strWID.s32ValueSize = u8Psklength;
5289         }
5290
5291         return s32Error;
5292 }
5293 /**
5294  *  @brief              host_int_get_MacAddress
5295  *  @details    gets mac address
5296  *  @param[in,out] handle to the wifi driver,
5297  *
5298  *  @return             Error code indicating success/failure
5299  *  @note
5300  *  @author             mdaftedar
5301  *  @date               19 April 2012
5302  *  @version            1.0
5303  */
5304 s32 host_int_get_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress)
5305 {
5306         s32 s32Error = WILC_SUCCESS;
5307         tstrHostIFmsg strHostIFmsg;
5308
5309
5310         /* prepare the Message */
5311         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5312
5313         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_MAC_ADDRESS;
5314         strHostIFmsg.uniHostIFmsgBody.strHostIfGetMacAddress.u8MacAddress = pu8MacAddress;
5315         strHostIFmsg.drvHandler = hWFIDrv;
5316         /* send the message */
5317         s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5318         if (s32Error) {
5319                 PRINT_ER("Failed to send get mac address\n");
5320                 return WILC_FAIL;
5321         }
5322
5323         down(&hWaitResponse);
5324         return s32Error;
5325 }
5326
5327 /**
5328  *  @brief              host_int_set_MacAddress
5329  *  @details    sets mac address
5330  *  @param[in,out] handle to the wifi driver,
5331  *
5332  *  @return             Error code indicating success/failure
5333  *  @note
5334  *  @author             mabubakr
5335  *  @date               16 July 2012
5336  *  @version            1.0
5337  */
5338 s32 host_int_set_MacAddress(WILC_WFIDrvHandle hWFIDrv, u8 *pu8MacAddress)
5339 {
5340         s32 s32Error = WILC_SUCCESS;
5341         tstrHostIFmsg strHostIFmsg;
5342
5343         PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]);
5344
5345         /* prepare setting mac address message */
5346         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5347         strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_MAC_ADDRESS;
5348         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfSetMacAddress.u8MacAddress, pu8MacAddress, ETH_ALEN);
5349         strHostIFmsg.drvHandler = hWFIDrv;
5350
5351         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5352         if (s32Error) {
5353                 PRINT_ER("Failed to send message queue: Set mac address\n");
5354                 WILC_ERRORREPORT(s32Error, s32Error);
5355         }
5356         WILC_CATCH(s32Error)
5357         {
5358
5359         }
5360
5361         return s32Error;
5362
5363 }
5364
5365 /**
5366  *  @brief              host_int_get_RSNAConfigPSKPassPhrase
5367  *  @details    gets the pass phrase:AP/STA mode. This function gets the pass phrase used to
5368  *                              generate the Pre-Shared Key when WPA/WPA2 is enabled
5369  *                              The length of the field can vary from 8 to 64 bytes,
5370  *                              the lower layer should get the
5371  *  @param[in,out] handle to the wifi driver,
5372  *                                String containing PSK
5373  *  @return             Error code indicating success/failure
5374  *  @note
5375  *  @author             zsalah
5376  *  @date               8 March 2012
5377  *  @version            1.0
5378  */
5379 s32 host_int_get_RSNAConfigPSKPassPhrase(WILC_WFIDrvHandle hWFIDrv,
5380                                                  u8 *pu8PassPhrase, u8 u8Psklength)
5381 {
5382         s32 s32Error = WILC_SUCCESS;
5383         tstrWID strWID;
5384         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5385
5386         strWID.u16WIDid = (u16)WID_11I_PSK;
5387         strWID.enuWIDtype       = WID_STR;
5388         strWID.s32ValueSize = u8Psklength;
5389         strWID.ps8WidVal        = pu8PassPhrase;
5390
5391         return s32Error;
5392 }
5393
5394 /**
5395  *  @brief                      host_int_get_site_survey_results
5396  *  @details            gets the site survey results
5397  *  @param[in,out] handle to the wifi driver,
5398  *                                Message containing  site survey results in the
5399  *                                following format
5400  *|---------------------------------------------------|
5401  | MsgLength | fragNo.  | MsgBodyLength | MsgBody       |
5402  ||-----------|-----------|---------------|-----------|
5403  |       1              |         1             |               1               |        1              |
5404  | -----------------------------------------     |  ----------------
5405  |
5406  ||---------------------------------------|
5407  | Network1 | Netweork2 | ... | Network5 |
5408  ||---------------------------------------|
5409  |      44         |    44         | ... |       44             |
5410  | -------------------------- | ---------------------------------------
5411  |
5412  ||---------------------------------------------------------------------|
5413  | SSID | BSS Type | Channel | Security Status| BSSID | RSSI |Reserved |
5414  |
5415  |
5416  ||------|----------|---------|----------------|-------|------|---------|
5417  |  33  |        1        |       1             |               1                |        6      |       1      |        1        |
5418  ||---------------------------------------------------------------------|
5419  *  @return             Error code indicating success/failure
5420  *  @note
5421  *  @author             zsalah
5422  *  @date               8 March 2012
5423  *  @version            1.0
5424  */
5425 #ifndef CONNECT_DIRECT
5426 s32 host_int_get_site_survey_results(WILC_WFIDrvHandle hWFIDrv,
5427                                              u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
5428                                              u32 u32MaxSiteSrvyFragLen)
5429 {
5430         s32 s32Error = WILC_SUCCESS;
5431         tstrWID astrWIDList[2];
5432         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5433
5434         astrWIDList[0].u16WIDid = (u16)WID_SITE_SURVEY_RESULTS;
5435         astrWIDList[0].enuWIDtype = WID_STR;
5436         astrWIDList[0].ps8WidVal = ppu8RcvdSiteSurveyResults[0];
5437         astrWIDList[0].s32ValueSize = u32MaxSiteSrvyFragLen;
5438
5439         astrWIDList[1].u16WIDid = (u16)WID_SITE_SURVEY_RESULTS;
5440         astrWIDList[1].enuWIDtype = WID_STR;
5441         astrWIDList[1].ps8WidVal = ppu8RcvdSiteSurveyResults[1];
5442         astrWIDList[1].s32ValueSize = u32MaxSiteSrvyFragLen;
5443
5444         s32Error = SendConfigPkt(GET_CFG, astrWIDList, 2, true, (u32)pstrWFIDrv);
5445
5446         /*get the value by searching the local copy*/
5447         if (s32Error) {
5448                 PRINT_ER("Failed to send config packet to get survey results\n");
5449                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
5450         }
5451
5452         WILC_CATCH(s32Error)
5453         {
5454
5455         }
5456
5457         return s32Error;
5458 }
5459 #endif
5460
5461 /**
5462  *  @brief              sets a start scan request
5463  *  @details
5464  *  @param[in,out] handle to the wifi driver,
5465  *  @param[in]  Scan Source one of the following values
5466  *                              DEFAULT_SCAN        0
5467  *                              USER_SCAN           BIT0
5468  *                              OBSS_PERIODIC_SCAN  BIT1
5469  *                              OBSS_ONETIME_SCAN   BIT2
5470  *  @return             Error code indicating success/failure
5471  *  @note
5472  *  @author             zsalah
5473  *  @date               8 March 2012
5474  *  @version            1.0
5475  */
5476 s32 host_int_set_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 scanSource)
5477 {
5478         s32 s32Error = WILC_SUCCESS;
5479         tstrWID strWID;
5480         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5481
5482         strWID.u16WIDid = (u16)WID_START_SCAN_REQ;
5483         strWID.enuWIDtype = WID_CHAR;
5484         strWID.ps8WidVal = (s8 *)&scanSource;
5485         strWID.s32ValueSize = sizeof(char);
5486
5487         return s32Error;
5488 }
5489
5490 /**
5491  *  @brief                      host_int_get_start_scan_req
5492  *  @details            gets a start scan request
5493  *  @param[in,out] handle to the wifi driver,
5494  *  @param[in]  Scan Source one of the following values
5495  *                              DEFAULT_SCAN        0
5496  *                              USER_SCAN           BIT0
5497  *                              OBSS_PERIODIC_SCAN  BIT1
5498  *                              OBSS_ONETIME_SCAN   BIT2
5499  *  @return             Error code indicating success/failure
5500  *  @note
5501  *  @author             zsalah
5502  *  @date               8 March 2012
5503  *  @version            1.0
5504  */
5505
5506 s32 host_int_get_start_scan_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ScanSource)
5507 {
5508         s32 s32Error = WILC_SUCCESS;
5509         tstrWID strWID;
5510         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5511
5512         strWID.u16WIDid = (u16)WID_START_SCAN_REQ;
5513         strWID.enuWIDtype = WID_CHAR;
5514         strWID.ps8WidVal = (s8 *)pu8ScanSource;
5515         strWID.s32ValueSize = sizeof(char);
5516
5517         return s32Error;
5518 }
5519
5520 /**
5521  *  @brief                      host_int_set_join_req
5522  *  @details            sets a join request
5523  *  @param[in,out] handle to the wifi driver,
5524  *  @param[in]  Index of the bss descriptor
5525  *  @return             Error code indicating success/failure
5526  *  @note
5527  *  @author             zsalah
5528  *  @date               8 March 2012
5529  *  @version            1.0
5530  */
5531 s32 host_int_set_join_req(WILC_WFIDrvHandle hWFIDrv, u8 *pu8bssid,
5532                                   const u8 *pu8ssid, size_t ssidLen,
5533                                   const u8 *pu8IEs, size_t IEsLen,
5534                                   tWILCpfConnectResult pfConnectResult, void *pvUserArg,
5535                                   u8 u8security, AUTHTYPE_T tenuAuth_type,
5536                                   u8 u8channel,
5537                                   void *pJoinParams)
5538 {
5539         s32 s32Error = WILC_SUCCESS;
5540         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5541         tstrHostIFmsg strHostIFmsg;
5542         tenuScanConnTimer enuScanConnTimer;
5543
5544         if (pstrWFIDrv == NULL || pfConnectResult == NULL) {
5545                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5546         }
5547
5548         if (hWFIDrv == NULL) {
5549                 PRINT_ER("Driver not initialized: gWFiDrvHandle = NULL\n");
5550                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
5551         }
5552
5553         if (pJoinParams == NULL) {
5554                 PRINT_ER("Unable to Join - JoinParams is NULL\n");
5555                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
5556
5557         }
5558 /*
5559  *      if(gWFiDrvHandle->strWILC_UsrScanReq.u32RcvdChCount == 0)
5560  *      {
5561  *              PRINT_ER("No scan results exist: Scanning should be done\n");
5562  *              WILC_ERRORREPORT(s32Error, WILC_FAIL);
5563  *      }
5564  */
5565         /* prepare the Connect Message */
5566         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5567
5568         strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT;
5569
5570         strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.u8security = u8security;
5571         strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.tenuAuth_type = tenuAuth_type;
5572         strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.u8channel = u8channel;
5573         strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pfConnectResult = pfConnectResult;
5574         strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pvUserArg = pvUserArg;
5575         strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pJoinParams = pJoinParams;
5576         strHostIFmsg.drvHandler = hWFIDrv;
5577
5578         if (pu8bssid != NULL) {
5579                 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid = (u8 *)WILC_MALLOC(6); /* will be deallocated by the receiving thread */
5580                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid,
5581                             pu8bssid, 6);
5582         }
5583
5584         if (pu8ssid != NULL) {
5585                 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.ssidLen = ssidLen;
5586                 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid = (u8 *)WILC_MALLOC(ssidLen); /* will be deallocated by the receiving thread */
5587                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid,
5588
5589                             pu8ssid, ssidLen);
5590         }
5591
5592         if (pu8IEs != NULL) {
5593                 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.IEsLen = IEsLen;
5594                 strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs = (u8 *)WILC_MALLOC(IEsLen); /* will be deallocated by the receiving thread */
5595                 WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs,
5596                             pu8IEs, IEsLen);
5597         }
5598         if (pstrWFIDrv->enuHostIFstate < HOST_IF_CONNECTING) {
5599                 pstrWFIDrv->enuHostIFstate = HOST_IF_CONNECTING;
5600         } else
5601                 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", pstrWFIDrv->enuHostIFstate);
5602
5603         /* send the message */
5604         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5605         if (s32Error) {
5606                 PRINT_ER("Failed to send message queue: Set join request\n");
5607                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
5608         }
5609
5610         enuScanConnTimer = CONNECT_TIMER;
5611         WILC_TimerStart(&(pstrWFIDrv->hConnectTimer), HOST_IF_CONNECT_TIMEOUT, (void *) hWFIDrv, NULL);
5612
5613         WILC_CATCH(s32Error)
5614         {
5615
5616         }
5617
5618         return s32Error;
5619 }
5620
5621 /**
5622  *  @brief              Flush a join request parameters to FW, but actual connection
5623  *  @details    The function is called in situation where WILC is connected to AP and
5624  *                      required to switch to hybrid FW for P2P connection
5625  *  @param[in] handle to the wifi driver,
5626  *  @return     Error code indicating success/failure
5627  *  @note
5628  *  @author     Amr Abdel-Moghny
5629  *  @date               19 DEC 2013
5630  *  @version    8.0
5631  */
5632
5633 s32 host_int_flush_join_req(WILC_WFIDrvHandle hWFIDrv)
5634 {
5635         s32 s32Error = WILC_SUCCESS;
5636         tstrHostIFmsg strHostIFmsg;
5637
5638         if (!gu8FlushedJoinReq) {
5639                 s32Error = WILC_FAIL;
5640                 return s32Error;
5641         }
5642
5643
5644         if (hWFIDrv  == NULL) {
5645                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5646         }
5647
5648
5649         strHostIFmsg.u16MsgId = HOST_IF_MSG_FLUSH_CONNECT;
5650         strHostIFmsg.drvHandler = hWFIDrv;
5651
5652         /* send the message */
5653         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5654         if (s32Error) {
5655                 PRINT_ER("Failed to send message queue: Flush join request\n");
5656                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
5657         }
5658
5659         WILC_CATCH(s32Error)
5660         {
5661
5662         }
5663         return s32Error;
5664 }
5665
5666 /**
5667  *  @brief                      host_int_disconnect
5668  *  @details            disconnects from the currently associated network
5669  *  @param[in,out] handle to the wifi driver,
5670  *  @param[in]  Reason Code of the Disconnection
5671  *  @return             Error code indicating success/failure
5672  *  @note
5673  *  @author             zsalah
5674  *  @date               8 March 2012
5675  *  @version            1.0
5676  */
5677 s32 host_int_disconnect(WILC_WFIDrvHandle hWFIDrv, u16 u16ReasonCode)
5678 {
5679         s32 s32Error = WILC_SUCCESS;
5680         tstrHostIFmsg strHostIFmsg;
5681         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5682
5683         if (pstrWFIDrv == NULL) {
5684                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
5685                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5686         }
5687
5688         if (pstrWFIDrv == NULL) {
5689                 PRINT_ER("gWFiDrvHandle = NULL\n");
5690                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
5691         }
5692
5693         /* prepare the Disconnect Message */
5694         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5695
5696         strHostIFmsg.u16MsgId = HOST_IF_MSG_DISCONNECT;
5697         strHostIFmsg.drvHandler = hWFIDrv;
5698
5699         /* send the message */
5700         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5701         if (s32Error)
5702                 PRINT_ER("Failed to send message queue: disconnect\n");
5703         /* ////////////// */
5704         down(&(pstrWFIDrv->hSemTestDisconnectBlock));
5705         /* /////// */
5706
5707         WILC_CATCH(s32Error)
5708         {
5709
5710         }
5711
5712         return s32Error;
5713 }
5714
5715 /**
5716  *  @brief              host_int_disconnect_station
5717  *  @details     disconnects a sta
5718  *  @param[in,out] handle to the wifi driver,
5719  *  @param[in]  Association Id of the station to be disconnected
5720  *  @return             Error code indicating success/failure
5721  *  @note
5722  *  @author             zsalah
5723  *  @date               8 March 2012
5724  *  @version            1.0
5725  */
5726 s32 host_int_disconnect_station(WILC_WFIDrvHandle hWFIDrv, u8 assoc_id)
5727 {
5728         s32 s32Error = WILC_SUCCESS;
5729         tstrWID strWID;
5730         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5731
5732         strWID.u16WIDid = (u16)WID_DISCONNECT;
5733         strWID.enuWIDtype = WID_CHAR;
5734         strWID.ps8WidVal = (s8 *)&assoc_id;
5735         strWID.s32ValueSize = sizeof(char);
5736
5737         return s32Error;
5738 }
5739
5740 /**
5741  *  @brief                      host_int_get_assoc_req_info
5742  *  @details            gets a Association request info
5743  *  @param[in,out] handle to the wifi driver,
5744  *                              Message containg assoc. req info in the following format
5745  * ------------------------------------------------------------------------
5746  |                        Management Frame Format                    |
5747  ||-------------------------------------------------------------------|
5748  ||Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS |
5749  ||-------------|--------|--|--|-----|----------------|----------|----|
5750  | 2           |2       |6 |6 |6    |           2       |0 - 2312  | 4  |
5751  ||-------------------------------------------------------------------|
5752  |                                                                   |
5753  |             Association Request Frame - Frame Body                |
5754  ||-------------------------------------------------------------------|
5755  | Capability Information | Listen Interval | SSID | Supported Rates |
5756  ||------------------------|-----------------|------|-----------------|
5757  |                      2            |           2         | 2-34 |             3-10        |
5758  | ---------------------------------------------------------------------
5759  *  @return             Error code indicating success/failure
5760  *  @note
5761  *  @author             zsalah
5762  *  @date               8 March 2012
5763  *  @version            1.0
5764  */
5765
5766 s32 host_int_get_assoc_req_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocReqInfo,
5767                                         u32 u32AssocReqInfoLen)
5768 {
5769         s32 s32Error = WILC_SUCCESS;
5770         tstrWID strWID;
5771         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5772
5773         strWID.u16WIDid = (u16)WID_ASSOC_REQ_INFO;
5774         strWID.enuWIDtype = WID_STR;
5775         strWID.ps8WidVal = pu8AssocReqInfo;
5776         strWID.s32ValueSize = u32AssocReqInfoLen;
5777
5778
5779         return s32Error;
5780 }
5781
5782 /**
5783  *  @brief              gets a Association Response info
5784  *  @details
5785  *  @param[in,out] handle to the wifi driver,
5786  *                              Message containg assoc. resp info
5787  *  @return             Error code indicating success/failure
5788  *  @note
5789  *  @author             zsalah
5790  *  @date               8 March 2012
5791  *  @version            1.0
5792  */
5793 s32 host_int_get_assoc_res_info(WILC_WFIDrvHandle hWFIDrv, u8 *pu8AssocRespInfo,
5794                                         u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
5795 {
5796         s32 s32Error = WILC_SUCCESS;
5797         tstrWID strWID;
5798         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5799
5800         if (pstrWFIDrv == NULL) {
5801                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
5802                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5803         }
5804
5805         strWID.u16WIDid = (u16)WID_ASSOC_RES_INFO;
5806         strWID.enuWIDtype = WID_STR;
5807         strWID.ps8WidVal = pu8AssocRespInfo;
5808         strWID.s32ValueSize = u32MaxAssocRespInfoLen;
5809
5810
5811         /* Sending Configuration packet */
5812         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
5813         if (s32Error) {
5814                 PRINT_ER("Failed to send association response config packet\n");
5815                 *pu32RcvdAssocRespInfoLen = 0;
5816                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
5817         } else {
5818                 *pu32RcvdAssocRespInfoLen = strWID.s32ValueSize;
5819         }
5820
5821         WILC_CATCH(s32Error)
5822         {
5823
5824         }
5825         return s32Error;
5826 }
5827
5828 /**
5829  *  @brief              gets a Association Response info
5830  *  @details    Valid only in STA mode. This function gives the RSSI
5831  *                              values observed in all the channels at the time of scanning.
5832  *                              The length of the field is 1 greater that the total number of
5833  *                              channels supported. Byte 0 contains the number of channels while
5834  *                              each of Byte N contains the observed RSSI value for the channel index N.
5835  *  @param[in,out] handle to the wifi driver,
5836  *                              array of scanned channels' RSSI
5837  *  @return             Error code indicating success/failure
5838  *  @note
5839  *  @author             zsalah
5840  *  @date               8 March 2012
5841  *  @version            1.0
5842  */
5843 s32 host_int_get_rx_power_level(WILC_WFIDrvHandle hWFIDrv, u8 *pu8RxPowerLevel,
5844                                         u32 u32RxPowerLevelLen)
5845 {
5846         s32 s32Error = WILC_SUCCESS;
5847         tstrWID strWID;
5848         /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
5849
5850         strWID.u16WIDid = (u16)WID_RX_POWER_LEVEL;
5851         strWID.enuWIDtype = WID_STR;
5852         strWID.ps8WidVal = pu8RxPowerLevel;
5853         strWID.s32ValueSize = u32RxPowerLevelLen;
5854
5855
5856         return s32Error;
5857 }
5858
5859 /**
5860  *  @brief              sets a channel
5861  *  @details
5862  *  @param[in,out] handle to the wifi driver,
5863  *  @param[in]  Index of the channel to be set
5864  *|-------------------------------------------------------------------|
5865  |          CHANNEL1      CHANNEL2 ....                      CHANNEL14  |
5866  |  Input:         1             2                                                  14  |
5867  ||-------------------------------------------------------------------|
5868  *  @return             Error code indicating success/failure
5869  *  @note
5870  *  @author             zsalah
5871  *  @date               8 March 2012
5872  *  @version            1.0
5873  */
5874 s32 host_int_set_mac_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 u8ChNum)
5875 {
5876         s32 s32Error = WILC_SUCCESS;
5877         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
5878         tstrHostIFmsg strHostIFmsg;
5879
5880         if (pstrWFIDrv == NULL) {
5881                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
5882         }
5883
5884         /* prepare the set channel message */
5885         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5886         strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_CHANNEL;
5887         strHostIFmsg.uniHostIFmsgBody.strHostIFSetChan.u8SetChan = u8ChNum;
5888         strHostIFmsg.drvHandler = hWFIDrv;
5889
5890         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5891         if (s32Error) {
5892                 WILC_ERRORREPORT(s32Error, s32Error);
5893         }
5894         WILC_CATCH(s32Error)
5895         {
5896
5897         }
5898
5899         return s32Error;
5900 }
5901
5902
5903 s32 host_int_wait_msg_queue_idle(void)
5904 {
5905         s32 s32Error = WILC_SUCCESS;
5906
5907         tstrHostIFmsg strHostIFmsg;
5908
5909         /* prepare the set driver handler message */
5910
5911         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5912         strHostIFmsg.u16MsgId = HOST_IF_MSG_Q_IDLE;
5913         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5914         if (s32Error) {
5915                 WILC_ERRORREPORT(s32Error, s32Error);
5916         }
5917         WILC_CATCH(s32Error)
5918         {
5919
5920         }
5921
5922         /* wait untill MSG Q is empty */
5923         down(&hWaitResponse);
5924
5925         return s32Error;
5926
5927 }
5928
5929 s32 host_int_set_wfi_drv_handler(u32 u32address)
5930 {
5931         s32 s32Error = WILC_SUCCESS;
5932
5933         tstrHostIFmsg strHostIFmsg;
5934
5935
5936         /* prepare the set driver handler message */
5937
5938         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5939         strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_WFIDRV_HANDLER;
5940         strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler.u32Address = u32address;
5941         /* strHostIFmsg.drvHandler=hWFIDrv; */
5942
5943         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5944         if (s32Error) {
5945                 WILC_ERRORREPORT(s32Error, s32Error);
5946         }
5947         WILC_CATCH(s32Error)
5948         {
5949
5950         }
5951
5952         return s32Error;
5953 }
5954
5955
5956
5957 s32 host_int_set_operation_mode(WILC_WFIDrvHandle hWFIDrv, u32 u32mode)
5958 {
5959         s32 s32Error = WILC_SUCCESS;
5960
5961         tstrHostIFmsg strHostIFmsg;
5962
5963
5964         /* prepare the set driver handler message */
5965
5966         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
5967         strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_OPERATION_MODE;
5968         strHostIFmsg.uniHostIFmsgBody.strHostIfSetOperationMode.u32Mode = u32mode;
5969         strHostIFmsg.drvHandler = hWFIDrv;
5970
5971         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
5972         if (s32Error) {
5973                 WILC_ERRORREPORT(s32Error, s32Error);
5974         }
5975         WILC_CATCH(s32Error)
5976         {
5977
5978         }
5979
5980         return s32Error;
5981 }
5982
5983 /**
5984  *  @brief              gets the current channel index
5985  *  @details
5986  *  @param[in,out] handle to the wifi driver,
5987  *                              current channel index
5988  *|-----------------------------------------------------------------------|
5989  |          CHANNEL1      CHANNEL2 ....                     CHANNEL14   |
5990  |  Input:         1             2                                 14   |
5991  ||-----------------------------------------------------------------------|
5992  *  @return             Error code indicating success/failure
5993  *  @note
5994  *  @author             zsalah
5995  *  @date               8 March 2012
5996  *  @version            1.0
5997  */
5998 s32 host_int_get_host_chnl_num(WILC_WFIDrvHandle hWFIDrv, u8 *pu8ChNo)
5999 {
6000         s32 s32Error = WILC_SUCCESS;
6001         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6002         tstrHostIFmsg strHostIFmsg;
6003
6004         if (pstrWFIDrv == NULL) {
6005                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
6006                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6007         }
6008
6009         /* prepare the Get Channel Message */
6010         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6011
6012         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_CHNL;
6013         strHostIFmsg.drvHandler = hWFIDrv;
6014
6015         /* send the message */
6016         s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6017         if (s32Error)
6018                 PRINT_ER("Failed to send get host channel param's message queue ");
6019         down(&(pstrWFIDrv->hSemGetCHNL));
6020         /* gu8Chnl = 11; */
6021
6022         *pu8ChNo = gu8Chnl;
6023
6024         WILC_CATCH(s32Error)
6025         {
6026         }
6027
6028         return s32Error;
6029
6030
6031 }
6032
6033
6034 /**
6035  *  @brief                       host_int_test_set_int_wid
6036  *  @details             Test function for setting wids
6037  *  @param[in,out]   WILC_WFIDrvHandle hWFIDrv, u32 u32TestMemAddr
6038  *  @return              Error code indicating success/failure
6039  *  @note
6040  *  @author             zsalah
6041  *  @date               8 March 2012
6042  *  @version            1.0
6043  */
6044 s32 host_int_test_set_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 u32TestMemAddr)
6045 {
6046         s32 s32Error = WILC_SUCCESS;
6047         tstrWID strWID;
6048         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6049
6050
6051         if (pstrWFIDrv == NULL) {
6052                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
6053                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6054         }
6055
6056         /*prepare configuration packet*/
6057         strWID.u16WIDid = (u16)WID_MEMORY_ADDRESS;
6058         strWID.enuWIDtype = WID_INT;
6059         strWID.ps8WidVal = (char *)&u32TestMemAddr;
6060         strWID.s32ValueSize = sizeof(u32);
6061
6062         /*Sending Cfg*/
6063         s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
6064         if (s32Error) {
6065                 PRINT_ER("Test Function: Failed to set wid value\n");
6066                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
6067         } else {
6068                 PRINT_D(HOSTINF_DBG, "Successfully set wid value\n");
6069
6070         }
6071
6072         WILC_CATCH(s32Error)
6073         {
6074
6075         }
6076         return s32Error;
6077 }
6078
6079 #ifdef WILC_AP_EXTERNAL_MLME
6080 /**
6081  *  @brief              host_int_get_inactive_time
6082  *  @details
6083  *  @param[in,out] handle to the wifi driver,
6084  *                              current sta macaddress, inactive_time
6085  *  @return
6086  *  @note
6087  *  @author
6088  *  @date
6089  *  @version            1.0
6090  */
6091 s32 host_int_get_inactive_time(WILC_WFIDrvHandle hWFIDrv, const u8 *mac, u32 *pu32InactiveTime)
6092 {
6093         s32 s32Error = WILC_SUCCESS;
6094         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6095         tstrHostIFmsg strHostIFmsg;
6096
6097         if (pstrWFIDrv == NULL) {
6098                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
6099                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6100         }
6101
6102         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6103
6104
6105         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfStaInactiveT.mac,
6106                     mac, ETH_ALEN);
6107
6108         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_INACTIVETIME;
6109         strHostIFmsg.drvHandler = hWFIDrv;
6110
6111         /* send the message */
6112         s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6113         if (s32Error)
6114                 PRINT_ER("Failed to send get host channel param's message queue ");
6115
6116         down(&(pstrWFIDrv->hSemInactiveTime));
6117
6118         *pu32InactiveTime = gu32InactiveTime;
6119
6120         WILC_CATCH(s32Error)
6121         {
6122         }
6123
6124         return s32Error;
6125 }
6126 #endif
6127 /**
6128  *  @brief              host_int_test_get_int_wid
6129  *  @details    Test function for getting wids
6130  *  @param[in,out] WILC_WFIDrvHandle hWFIDrv, u32* pu32TestMemAddr
6131  *  @return             Error code indicating success/failure
6132  *  @note
6133  *  @author             zsalah
6134  *  @date               8 March 2012
6135  *  @version            1.0
6136  */
6137 s32 host_int_test_get_int_wid(WILC_WFIDrvHandle hWFIDrv, u32 *pu32TestMemAddr)
6138 {
6139
6140         s32 s32Error = WILC_SUCCESS;
6141         tstrWID strWID;
6142         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6143
6144
6145         if (pstrWFIDrv == NULL) {
6146                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
6147                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6148         }
6149
6150         strWID.u16WIDid = (u16)WID_MEMORY_ADDRESS;
6151         strWID.enuWIDtype = WID_INT;
6152         strWID.ps8WidVal = (s8 *)pu32TestMemAddr;
6153         strWID.s32ValueSize = sizeof(u32);
6154
6155         s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
6156         /*get the value by searching the local copy*/
6157         if (s32Error) {
6158                 PRINT_ER("Test Function: Failed to get wid value\n");
6159                 WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
6160         } else {
6161                 PRINT_D(HOSTINF_DBG, "Successfully got wid value\n");
6162
6163         }
6164
6165         WILC_CATCH(s32Error)
6166         {
6167
6168         }
6169         return s32Error;
6170 }
6171
6172
6173 /**
6174  *  @brief              host_int_get_rssi
6175  *  @details    gets the currently maintained RSSI value for the station.
6176  *                              The received signal strength value in dB.
6177  *                              The range of valid values is -128 to 0.
6178  *  @param[in,out] handle to the wifi driver,
6179  *                              rssi value in dB
6180  *  @return             Error code indicating success/failure
6181  *  @note
6182  *  @author             zsalah
6183  *  @date               8 March 2012
6184  *  @version            1.0
6185  */
6186 s32 host_int_get_rssi(WILC_WFIDrvHandle hWFIDrv, s8 *ps8Rssi)
6187 {
6188         s32 s32Error = WILC_SUCCESS;
6189         tstrHostIFmsg strHostIFmsg;
6190         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6191
6192
6193         /* prepare the Get RSSI Message */
6194         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6195
6196         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI;
6197         strHostIFmsg.drvHandler = hWFIDrv;
6198
6199         /* send the message */
6200         s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6201         if (s32Error) {
6202                 PRINT_ER("Failed to send get host channel param's message queue ");
6203                 return WILC_FAIL;
6204         }
6205
6206         down(&(pstrWFIDrv->hSemGetRSSI));
6207
6208
6209         if (ps8Rssi == NULL) {
6210                 PRINT_ER("RSS pointer value is null");
6211                 return WILC_FAIL;
6212         }
6213
6214
6215         *ps8Rssi = gs8Rssi;
6216
6217
6218         return s32Error;
6219 }
6220
6221 s32 host_int_get_link_speed(WILC_WFIDrvHandle hWFIDrv, s8 *ps8lnkspd)
6222 {
6223         tstrHostIFmsg strHostIFmsg;
6224         s32 s32Error = WILC_SUCCESS;
6225
6226         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6227
6228
6229
6230         /* prepare the Get LINKSPEED Message */
6231         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6232
6233         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_LINKSPEED;
6234         strHostIFmsg.drvHandler = hWFIDrv;
6235
6236         /* send the message */
6237         s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6238         if (s32Error) {
6239                 PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
6240                 return WILC_FAIL;
6241         }
6242
6243         down(&(pstrWFIDrv->hSemGetLINKSPEED));
6244
6245
6246         if (ps8lnkspd == NULL) {
6247                 PRINT_ER("LINKSPEED pointer value is null");
6248                 return WILC_FAIL;
6249         }
6250
6251
6252         *ps8lnkspd = gs8lnkspd;
6253
6254
6255         return s32Error;
6256 }
6257
6258 s32 host_int_get_statistics(WILC_WFIDrvHandle hWFIDrv, tstrStatistics *pstrStatistics)
6259 {
6260         s32 s32Error = WILC_SUCCESS;
6261         tstrHostIFmsg strHostIFmsg;
6262
6263
6264         /* prepare the Get RSSI Message */
6265         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6266
6267         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_STATISTICS;
6268         strHostIFmsg.uniHostIFmsgBody.pUserData = (char *)pstrStatistics;
6269         strHostIFmsg.drvHandler = hWFIDrv;
6270         /* send the message */
6271         s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6272         if (s32Error) {
6273                 PRINT_ER("Failed to send get host channel param's message queue ");
6274                 return WILC_FAIL;
6275         }
6276
6277         down(&hWaitResponse);
6278         return s32Error;
6279 }
6280
6281
6282 /**
6283  *  @brief              host_int_scan
6284  *  @details    scans a set of channels
6285  *  @param[in,out] handle to the wifi driver,
6286  *  @param[in]  Scan source
6287  *                              Scan Type       PASSIVE_SCAN = 0,
6288  *                                                      ACTIVE_SCAN  = 1
6289  *                              Channels Array
6290  *                              Channels Array length
6291  *                              Scan Callback function
6292  *  @return             Error code indicating success/failure
6293  *  @note
6294  *  @author             zsalah
6295  *  @date               8 March 2012
6296  *  @version            1.0
6297  */
6298 s32 host_int_scan(WILC_WFIDrvHandle hWFIDrv, u8 u8ScanSource,
6299                           u8 u8ScanType, u8 *pu8ChnlFreqList,
6300                           u8 u8ChnlListLen, const u8 *pu8IEs,
6301                           size_t IEsLen, tWILCpfScanResult ScanResult,
6302                           void *pvUserArg, tstrHiddenNetwork  *pstrHiddenNetwork)
6303 {
6304         s32 s32Error = WILC_SUCCESS;
6305         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6306         tstrHostIFmsg strHostIFmsg;
6307         tenuScanConnTimer enuScanConnTimer;
6308
6309         if (pstrWFIDrv == NULL || ScanResult == NULL)   {
6310                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6311         }
6312
6313
6314         /* prepare the Scan Message */
6315         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6316
6317         strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN;
6318
6319         if (pstrHiddenNetwork != NULL) {
6320                 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.strHiddenNetwork.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
6321                 strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.strHiddenNetwork.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
6322
6323         } else
6324                 PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n");
6325
6326         strHostIFmsg.drvHandler = hWFIDrv;
6327         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ScanSource = u8ScanSource;
6328         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ScanType = u8ScanType;
6329         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pfScanResult = ScanResult;
6330         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pvUserArg = pvUserArg;
6331
6332         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ChnlListLen = u8ChnlListLen;
6333         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList = (u8 *)WILC_MALLOC(u8ChnlListLen);        /* will be deallocated by the receiving thread */
6334         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList,
6335                     pu8ChnlFreqList, u8ChnlListLen);
6336
6337         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.IEsLen = IEsLen;
6338         strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs = (u8 *)WILC_MALLOC(IEsLen);        /* will be deallocated by the receiving thread */
6339         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs,
6340                     pu8IEs, IEsLen);
6341
6342         /* send the message */
6343         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6344         if (s32Error) {
6345                 PRINT_ER("Error in sending message queue scanning parameters: Error(%d)\n", s32Error);
6346                 WILC_ERRORREPORT(s32Error, WILC_FAIL);
6347         }
6348
6349         enuScanConnTimer = SCAN_TIMER;
6350         PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
6351         WILC_TimerStart(&(pstrWFIDrv->hScanTimer), HOST_IF_SCAN_TIMEOUT, (void *) hWFIDrv, NULL);
6352
6353
6354         WILC_CATCH(s32Error)
6355         {
6356
6357         }
6358         return s32Error;
6359
6360 }
6361 /**
6362  *  @brief                      hif_set_cfg
6363  *  @details            sets configuration wids values
6364  *  @param[in,out] handle to the wifi driver,
6365  *  @param[in]  WID, WID value
6366  *  @return             Error code indicating success/failure
6367  *  @note
6368  *  @author             zsalah
6369  *  @date               8 March 2012
6370  *  @version            1.0
6371  */
6372 s32 hif_set_cfg(WILC_WFIDrvHandle hWFIDrv, tstrCfgParamVal *pstrCfgParamVal)
6373 {
6374
6375         s32 s32Error = WILC_SUCCESS;
6376         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6377
6378         tstrHostIFmsg strHostIFmsg;
6379
6380
6381         if (pstrWFIDrv == NULL) {
6382                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6383         }
6384         /* prepare the WiphyParams Message */
6385         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6386         strHostIFmsg.u16MsgId = HOST_IF_MSG_CFG_PARAMS;
6387         strHostIFmsg.uniHostIFmsgBody.strHostIFCfgParamAttr.pstrCfgParamVal = *pstrCfgParamVal;
6388         strHostIFmsg.drvHandler = hWFIDrv;
6389
6390         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6391
6392         WILC_CATCH(s32Error)
6393         {
6394         }
6395
6396         return s32Error;
6397
6398 }
6399
6400
6401 /**
6402  *  @brief              hif_get_cfg
6403  *  @details    gets configuration wids values
6404  *  @param[in,out] handle to the wifi driver,
6405  *                              WID value
6406  *  @param[in]  WID,
6407  *  @return             Error code indicating success/failure
6408  *  @note
6409  *  @author             zsalah
6410  *
6411  *  @date               8 March 2012
6412  *  @version            1.0
6413  */
6414 s32 hif_get_cfg(WILC_WFIDrvHandle hWFIDrv, u16 u16WID, u16 *pu16WID_Value)
6415 {
6416         s32 s32Error = WILC_SUCCESS;
6417         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6418
6419         down(&(pstrWFIDrv->gtOsCfgValuesSem));
6420
6421         if (pstrWFIDrv == NULL) {
6422                 PRINT_ER("Driver not initialized: pstrWFIDrv = NULL \n");
6423                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
6424         }
6425         PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
6426         switch (u16WID) {
6427
6428         case WID_BSS_TYPE:
6429                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.bss_type;
6430                 break;
6431
6432         case WID_AUTH_TYPE:
6433                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.auth_type;
6434                 break;
6435
6436         case WID_AUTH_TIMEOUT:
6437                 *pu16WID_Value = pstrWFIDrv->strCfgValues.auth_timeout;
6438                 break;
6439
6440         case WID_POWER_MANAGEMENT:
6441                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.power_mgmt_mode;
6442                 break;
6443
6444         case WID_SHORT_RETRY_LIMIT:
6445                 *pu16WID_Value =       pstrWFIDrv->strCfgValues.short_retry_limit;
6446                 break;
6447
6448         case WID_LONG_RETRY_LIMIT:
6449                 *pu16WID_Value = pstrWFIDrv->strCfgValues.long_retry_limit;
6450                 break;
6451
6452         case WID_FRAG_THRESHOLD:
6453                 *pu16WID_Value = pstrWFIDrv->strCfgValues.frag_threshold;
6454                 break;
6455
6456         case WID_RTS_THRESHOLD:
6457                 *pu16WID_Value = pstrWFIDrv->strCfgValues.rts_threshold;
6458                 break;
6459
6460         case WID_PREAMBLE:
6461                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.preamble_type;
6462                 break;
6463
6464         case WID_SHORT_SLOT_ALLOWED:
6465                 *pu16WID_Value = (u16) pstrWFIDrv->strCfgValues.short_slot_allowed;
6466                 break;
6467
6468         case WID_11N_TXOP_PROT_DISABLE:
6469                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.txop_prot_disabled;
6470                 break;
6471
6472         case WID_BEACON_INTERVAL:
6473                 *pu16WID_Value = pstrWFIDrv->strCfgValues.beacon_interval;
6474                 break;
6475
6476         case WID_DTIM_PERIOD:
6477                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.dtim_period;
6478                 break;
6479
6480         case WID_SITE_SURVEY:
6481                 *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.site_survey_enabled;
6482                 break;
6483
6484         case WID_SITE_SURVEY_SCAN_TIME:
6485                 *pu16WID_Value = pstrWFIDrv->strCfgValues.site_survey_scan_time;
6486                 break;
6487
6488         case WID_ACTIVE_SCAN_TIME:
6489                 *pu16WID_Value = pstrWFIDrv->strCfgValues.active_scan_time;
6490                 break;
6491
6492         case WID_PASSIVE_SCAN_TIME:
6493                 *pu16WID_Value = pstrWFIDrv->strCfgValues.passive_scan_time;
6494                 break;
6495
6496         case WID_CURRENT_TX_RATE:
6497                 *pu16WID_Value = pstrWFIDrv->strCfgValues.curr_tx_rate;
6498                 break;
6499
6500         default:
6501                 break;
6502         }
6503
6504         up(&(pstrWFIDrv->gtOsCfgValuesSem));
6505
6506         WILC_CATCH(s32Error)
6507         {
6508         }
6509         return s32Error;
6510
6511 }
6512
6513 /*****************************************************************************/
6514 /*                                                      Notification Functions                                                   */
6515 /*****************************************************************************/
6516 /**
6517  *  @brief              notifies host with join and leave requests
6518  *  @details    This function prepares an Information frame having the
6519  *                              information about a joining/leaving station.
6520  *  @param[in,out] handle to the wifi driver,
6521  *  @param[in]  6 byte Sta Adress
6522  *                              Join or leave flag:
6523  *                              Join = 1,
6524  *                              Leave =0
6525  *  @return             Error code indicating success/failure
6526  *  @note
6527  *  @author             zsalah
6528  *  @date               8 March 2012
6529  *  @version            1.0
6530  */
6531 void host_int_send_join_leave_info_to_host
6532         (u16 assocId, u8 *stationAddr, bool joining)
6533 {
6534 }
6535 /**
6536  *  @brief              notifies host with stations found in scan
6537  *  @details    sends the beacon/probe response from scan
6538  *  @param[in,out] handle to the wifi driver,
6539  *  @param[in]  Sta Address,
6540  *                              Frame length,
6541  *                              Rssi of the Station found
6542  *  @return             Error code indicating success/failure
6543  *  @note
6544  *  @author             zsalah
6545  *  @date               8 March 2012
6546  *  @version            1.0
6547  */
6548
6549 void GetPeriodicRSSI(void *pvArg)
6550 {
6551         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)pvArg;
6552         if (pstrWFIDrv == NULL) {
6553                 PRINT_ER("Driver handler is NULL\n");
6554                 return;
6555         }
6556
6557         if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) {
6558                 s32 s32Error = WILC_SUCCESS;
6559                 tstrHostIFmsg strHostIFmsg;
6560
6561                 /* prepare the Get RSSI Message */
6562                 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6563
6564                 strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI;
6565                 strHostIFmsg.drvHandler = pstrWFIDrv;
6566
6567                 /* send the message */
6568                 s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6569                 if (s32Error) {
6570                         PRINT_ER("Failed to send get host channel param's message queue ");
6571                         return;
6572                 }
6573         }
6574         WILC_TimerStart(&(g_hPeriodicRSSI), 5000, (void *)pstrWFIDrv, NULL);
6575 }
6576
6577
6578 void host_int_send_network_info_to_host
6579         (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi)
6580 {
6581 }
6582 /**
6583  *  @brief              host_int_init
6584  *  @details    host interface initialization function
6585  *  @param[in,out] handle to the wifi driver,
6586  *  @note
6587  *  @author             zsalah
6588  *  @date               8 March 2012
6589  *  @version            1.0
6590  */
6591 static u32 u32Intialized;
6592 static u32 msgQ_created;
6593 static u32 clients_count;
6594
6595 s32 host_int_init(WILC_WFIDrvHandle *phWFIDrv)
6596 {
6597         s32 s32Error = WILC_SUCCESS;
6598         tstrWILC_WFIDrv *pstrWFIDrv;
6599
6600         /*if(u32Intialized == 1)
6601          * {
6602          *      PRINT_D(HOSTINF_DBG,"Host interface is previously initialized\n");
6603          * *phWFIDrv = (WILC_WFIDrvHandle)gWFiDrvHandle; //Will be adjusted later for P2P
6604          *      return 0;
6605          * }    */
6606         PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
6607
6608         gbScanWhileConnected = false;
6609
6610         sema_init(&hWaitResponse, 0);
6611
6612
6613
6614         /*Allocate host interface private structure*/
6615         pstrWFIDrv  = (tstrWILC_WFIDrv *)WILC_MALLOC(sizeof(tstrWILC_WFIDrv));
6616         if (pstrWFIDrv == NULL) {
6617                 /* WILC_ERRORREPORT(s32Error,WILC_NO_MEM); */
6618                 s32Error = WILC_NO_MEM;
6619                 PRINT_ER("Failed to allocate memory\n");
6620                 goto _fail_timer_2;
6621         }
6622         WILC_memset(pstrWFIDrv, 0, sizeof(tstrWILC_WFIDrv));
6623         /*return driver handle to user*/
6624         *phWFIDrv = (WILC_WFIDrvHandle)pstrWFIDrv;
6625         /*save into globl handle*/
6626
6627         #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
6628
6629         g_obtainingIP = false;
6630         #endif
6631
6632         PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", pstrWFIDrv);
6633         /* /////////////////////////////////////// */
6634         if (clients_count == 0) {
6635                 sema_init(&hSemHostIFthrdEnd, 0);
6636                 sema_init(&hSemDeinitDrvHandle, 0);
6637                 /*BugID_5348*/
6638                 sema_init(&hSemHostIntDeinit, 1);
6639         }
6640
6641         sema_init(&(pstrWFIDrv->hSemTestKeyBlock), 0);
6642         sema_init(&(pstrWFIDrv->hSemTestDisconnectBlock), 0);
6643         sema_init(&(pstrWFIDrv->hSemGetRSSI), 0);
6644         sema_init(&(pstrWFIDrv->hSemGetLINKSPEED), 0);
6645         sema_init(&(pstrWFIDrv->hSemGetCHNL), 0);
6646         sema_init(&(pstrWFIDrv->hSemInactiveTime), 0);
6647
6648         /* /////////////////////////////////////// */
6649
6650
6651
6652         PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
6653
6654         if (clients_count == 0) {
6655
6656                 s32Error = WILC_MsgQueueCreate(&gMsgQHostIF, NULL);
6657
6658
6659                 if (s32Error < 0) {
6660                         PRINT_ER("Failed to creat MQ\n");
6661                         goto _fail_;
6662                 }
6663                 msgQ_created = 1;
6664                 HostIFthreadHandler = kthread_run(hostIFthread, NULL, "WILC_kthread");
6665                 if (IS_ERR(HostIFthreadHandler)) {
6666                         PRINT_ER("Failed to creat Thread\n");
6667                         s32Error = WILC_FAIL;
6668                         goto _fail_mq_;
6669                 }
6670                 s32Error = WILC_TimerCreate(&(g_hPeriodicRSSI), GetPeriodicRSSI, NULL);
6671                 if (s32Error < 0) {
6672                         PRINT_ER("Failed to creat Timer\n");
6673                         goto _fail_timer_1;
6674                 }
6675                 WILC_TimerStart(&(g_hPeriodicRSSI), 5000, (void *)pstrWFIDrv, NULL);
6676
6677         }
6678
6679
6680         s32Error = WILC_TimerCreate(&(pstrWFIDrv->hScanTimer), TimerCB_Scan, NULL);
6681         if (s32Error < 0) {
6682                 PRINT_ER("Failed to creat Timer\n");
6683                 goto _fail_thread_;
6684         }
6685
6686         s32Error = WILC_TimerCreate(&(pstrWFIDrv->hConnectTimer), TimerCB_Connect, NULL);
6687         if (s32Error < 0) {
6688                 PRINT_ER("Failed to creat Timer\n");
6689                 goto _fail_timer_1;
6690         }
6691
6692
6693         #ifdef WILC_P2P
6694         /*Remain on channel timer*/
6695         s32Error = WILC_TimerCreate(&(pstrWFIDrv->hRemainOnChannel), ListenTimerCB, NULL);
6696         if (s32Error < 0) {
6697                 PRINT_ER("Failed to creat Remain-on-channel Timer\n");
6698                 goto _fail_timer_3;
6699         }
6700         #endif
6701
6702         sema_init(&(pstrWFIDrv->gtOsCfgValuesSem), 1);
6703         down(&(pstrWFIDrv->gtOsCfgValuesSem));
6704
6705
6706
6707 #ifdef SIMULATION
6708         TransportInit();
6709 #endif
6710
6711         pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
6712         /* gWFiDrvHandle->bPendingConnRequest = false; */
6713
6714         /*Initialize CFG WIDS Defualt Values*/
6715
6716         pstrWFIDrv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
6717         pstrWFIDrv->strCfgValues.scan_source = DEFAULT_SCAN;
6718         pstrWFIDrv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
6719         pstrWFIDrv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
6720         pstrWFIDrv->strCfgValues.curr_tx_rate = AUTORATE;
6721
6722
6723         #ifdef WILC_P2P
6724
6725         pstrWFIDrv->u64P2p_MgmtTimeout = 0;
6726
6727         #endif
6728
6729         PRINT_INFO(HOSTINF_DBG, "Initialization values, Site survey value: %d\n Scan source: %d\n Active scan time: %d\n Passive scan time: %d\nCurrent tx Rate = %d\n",
6730
6731                    pstrWFIDrv->strCfgValues.site_survey_enabled, pstrWFIDrv->strCfgValues.scan_source,
6732                    pstrWFIDrv->strCfgValues.active_scan_time, pstrWFIDrv->strCfgValues.passive_scan_time,
6733                    pstrWFIDrv->strCfgValues.curr_tx_rate);
6734
6735
6736         up(&(pstrWFIDrv->gtOsCfgValuesSem));
6737
6738         /*TODO Code to setup simulation to be removed later*/
6739         /*Intialize configurator module*/
6740         s32Error = CoreConfiguratorInit();
6741         if (s32Error < 0) {
6742                 PRINT_ER("Failed to initialize core configurator\n");
6743                 goto _fail_mem_;
6744         }
6745
6746 #ifdef SIMULATION
6747         /*Initialize Simulaor*/
6748         CoreConfigSimulatorInit();
6749 #endif
6750
6751         u32Intialized = 1;
6752         clients_count++; /* increase number of created entities */
6753
6754         return s32Error;
6755
6756
6757 _fail_mem_:
6758         if (pstrWFIDrv != NULL)
6759                 WILC_FREE(pstrWFIDrv);
6760 #ifdef WILC_P2P
6761 _fail_timer_3:
6762         WILC_TimerDestroy(&(pstrWFIDrv->hRemainOnChannel), NULL);
6763 #endif
6764 _fail_timer_2:
6765         up(&(pstrWFIDrv->gtOsCfgValuesSem));
6766         WILC_TimerDestroy(&(pstrWFIDrv->hConnectTimer), NULL);
6767 _fail_timer_1:
6768         WILC_TimerDestroy(&(pstrWFIDrv->hScanTimer), NULL);
6769 _fail_thread_:
6770         kthread_stop(HostIFthreadHandler);
6771 _fail_mq_:
6772         WILC_MsgQueueDestroy(&gMsgQHostIF, NULL);
6773 _fail_:
6774         return s32Error;
6775
6776
6777 }
6778 /**
6779  *  @brief              host_int_deinit
6780  *  @details    host interface initialization function
6781  *  @param[in,out] handle to the wifi driver,
6782  *  @note
6783  *  @author             zsalah
6784  *  @date               8 March 2012
6785  *  @version            1.0
6786  */
6787
6788 s32 host_int_deinit(WILC_WFIDrvHandle hWFIDrv)
6789 {
6790         s32 s32Error = WILC_SUCCESS;
6791         tstrHostIFmsg strHostIFmsg;
6792
6793
6794         /*obtain driver handle*/
6795         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
6796         /*if(u32Intialized == 0)
6797          * {
6798          *      PRINT_ER("Host Interface is not initialized\n");
6799          *      return 0;
6800          * }*/
6801
6802         /*BugID_5348*/
6803
6804         if (pstrWFIDrv == NULL) {
6805                 PRINT_ER("pstrWFIDrv = NULL\n");
6806                 return 0;
6807         }
6808
6809         down(&hSemHostIntDeinit);
6810
6811         terminated_handle = pstrWFIDrv;
6812         PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count);
6813
6814         /*BugID_5348*/
6815         /*Destroy all timers before acquiring hSemDeinitDrvHandle*/
6816         /*to guarantee handling all messages befor proceeding*/
6817         if (WILC_TimerDestroy(&(pstrWFIDrv->hScanTimer), NULL)) {
6818                 PRINT_D(HOSTINF_DBG, ">> Scan timer is active \n");
6819                 /* msleep(HOST_IF_SCAN_TIMEOUT+1000); */
6820         }
6821
6822         if (WILC_TimerDestroy(&(pstrWFIDrv->hConnectTimer), NULL)) {
6823                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active \n");
6824                 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
6825         }
6826
6827
6828         if (WILC_TimerDestroy(&(g_hPeriodicRSSI), NULL)) {
6829                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active \n");
6830                 /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
6831         }
6832
6833         #ifdef WILC_P2P
6834         /*Destroy Remain-onchannel Timer*/
6835         WILC_TimerDestroy(&(pstrWFIDrv->hRemainOnChannel), NULL);
6836         #endif
6837
6838         host_int_set_wfi_drv_handler((u32)NULL);
6839         down(&hSemDeinitDrvHandle);
6840
6841
6842         /*Calling the CFG80211 scan done function with the abort flag set to true*/
6843         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
6844                 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
6845                                                                 pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
6846
6847                 pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
6848         }
6849         /*deinit configurator and simulator*/
6850 #ifdef SIMULATION
6851         CoreConfigSimulatorDeInit();
6852 #endif
6853         CoreConfiguratorDeInit();
6854 #ifdef SIMULATION
6855         TransportDeInit();
6856 #endif
6857
6858         pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
6859
6860         gbScanWhileConnected = false;
6861
6862         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6863
6864         if (clients_count == 1) {
6865                 if (WILC_TimerDestroy(&g_hPeriodicRSSI, NULL)) {
6866                         PRINT_D(HOSTINF_DBG, ">> Connect timer is active \n");
6867                         /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
6868                 }
6869                 strHostIFmsg.u16MsgId = HOST_IF_MSG_EXIT;
6870                 strHostIFmsg.drvHandler = hWFIDrv;
6871
6872
6873                 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6874                 if (s32Error != WILC_SUCCESS) {
6875                         PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
6876                 }
6877
6878                 down(&hSemHostIFthrdEnd);
6879
6880
6881
6882                 WILC_MsgQueueDestroy(&gMsgQHostIF, NULL);
6883                 msgQ_created = 0;
6884         }
6885
6886         down(&(pstrWFIDrv->gtOsCfgValuesSem));
6887
6888         /*Setting the gloabl driver handler with NULL*/
6889         u32Intialized = 0;
6890         /* gWFiDrvHandle = NULL; */
6891         if (pstrWFIDrv != NULL) {
6892                 WILC_FREE(pstrWFIDrv);
6893                 /* pstrWFIDrv=NULL; */
6894
6895         }
6896
6897         clients_count--; /* Decrease number of created entities */
6898         terminated_handle = NULL;
6899         up(&hSemHostIntDeinit);
6900         return s32Error;
6901 }
6902
6903
6904 /**
6905  *  @brief              NetworkInfoReceived
6906  *  @details    function to to be called when network info packet is received
6907  *  @param[in]  pu8Buffer the received packet
6908  *  @param[in]   u32Length  length of the received packet
6909  *  @return             none
6910  *  @note
6911  *  @author
6912  *  @date               1 Mar 2012
6913  *  @version            1.0
6914  */
6915 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
6916 {
6917         s32 s32Error = WILC_SUCCESS;
6918         tstrHostIFmsg strHostIFmsg;
6919         u32 drvHandler;
6920         tstrWILC_WFIDrv *pstrWFIDrv = NULL;
6921
6922         drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
6923         pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
6924
6925
6926
6927
6928         if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle)      {
6929                 PRINT_ER("NetworkInfo received but driver not init[%p]\n", pstrWFIDrv);
6930                 return;
6931         }
6932
6933         /* prepare the Asynchronous Network Info message */
6934         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6935
6936         strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_NTWRK_INFO;
6937         strHostIFmsg.drvHandler = pstrWFIDrv;
6938
6939         strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.u32Length = u32Length;
6940         strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer = (u8 *)WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */
6941         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer,
6942                     pu8Buffer, u32Length);
6943
6944         /* send the message */
6945         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
6946         if (s32Error) {
6947                 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
6948         }
6949
6950
6951         return;
6952 }
6953
6954 /**
6955  *  @brief              GnrlAsyncInfoReceived
6956  *  @details    function to be called when general Asynchronous info packet is received
6957  *  @param[in]  pu8Buffer the received packet
6958  *  @param[in]   u32Length  length of the received packet
6959  *  @return             none
6960  *  @note
6961  *  @author
6962  *  @date               15 Mar 2012
6963  *  @version            1.0
6964  */
6965 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
6966 {
6967         s32 s32Error = WILC_SUCCESS;
6968         tstrHostIFmsg strHostIFmsg;
6969         u32 drvHandler;
6970         tstrWILC_WFIDrv *pstrWFIDrv = NULL;
6971
6972         /*BugID_5348*/
6973         down(&hSemHostIntDeinit);
6974
6975         drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
6976         pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
6977         PRINT_D(HOSTINF_DBG, "General asynchronous info packet received \n");
6978
6979
6980         if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle) {
6981                 PRINT_D(HOSTINF_DBG, "Wifi driver handler is equal to NULL\n");
6982                 /*BugID_5348*/
6983                 up(&hSemHostIntDeinit);
6984                 return;
6985         }
6986
6987         if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult == NULL) {
6988                 /* received mac status is not needed when there is no current Connect Request */
6989                 PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n");
6990                 /*BugID_5348*/
6991                 up(&hSemHostIntDeinit);
6992                 return;
6993         }
6994
6995         /* prepare the General Asynchronous Info message */
6996         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
6997
6998
6999         strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
7000         strHostIFmsg.drvHandler = pstrWFIDrv;
7001
7002
7003         strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.u32Length = u32Length;
7004         strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer = (u8 *)WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */
7005         WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer,
7006                     pu8Buffer, u32Length);
7007
7008         /* send the message */
7009         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7010         if (s32Error) {
7011                 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
7012         }
7013
7014         /*BugID_5348*/
7015         up(&hSemHostIntDeinit);
7016         return;
7017 }
7018
7019 /**
7020  *  @brief host_int_ScanCompleteReceived
7021  *  @details        Setting scan complete received notifcation in message queue
7022  *  @param[in]     u8* pu8Buffer, u32 u32Length
7023  *  @return         Error code.
7024  *  @author
7025  *  @date
7026  *  @version    1.0
7027  */
7028 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
7029 {
7030         s32 s32Error = WILC_SUCCESS;
7031         tstrHostIFmsg strHostIFmsg;
7032         u32 drvHandler;
7033         tstrWILC_WFIDrv *pstrWFIDrv = NULL;
7034         drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
7035         pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
7036
7037
7038         PRINT_D(GENERIC_DBG, "Scan notification received %p\n", pstrWFIDrv);
7039
7040         if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle) {
7041                 return;
7042         }
7043
7044         /*if there is an ongoing scan request*/
7045         if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
7046                 /* prepare theScan Done message */
7047                 WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7048
7049                 strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
7050                 strHostIFmsg.drvHandler = pstrWFIDrv;
7051
7052
7053                 /* will be deallocated by the receiving thread */
7054                 /*no need to send message body*/
7055
7056                 /*strHostIFmsg.uniHostIFmsgBody.strScanComplete.u32Length = u32Length;
7057                  * strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer  = (u8*)WILC_MALLOC(u32Length);
7058                  * WILC_memcpy(strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer,
7059                  *                        pu8Buffer, u32Length); */
7060
7061                 /* send the message */
7062                 s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7063                 if (s32Error) {
7064                         PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
7065                 }
7066         }
7067
7068
7069         return;
7070
7071 }
7072
7073 #ifdef WILC_P2P
7074 /**
7075  *  @brief              host_int_remain_on_channel
7076  *  @details
7077  *  @param[in]          Handle to wifi driver
7078  *                              Duration to remain on channel
7079  *                              Channel to remain on
7080  *                              Pointer to fn to be called on receive frames in listen state
7081  *                              Pointer to remain-on-channel expired fn
7082  *                              Priv
7083  *  @return             Error code.
7084  *  @author
7085  *  @date
7086  *  @version            1.0
7087  */
7088 s32 host_int_remain_on_channel(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg)
7089 {
7090         s32 s32Error = WILC_SUCCESS;
7091         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7092         tstrHostIFmsg strHostIFmsg;
7093
7094         if (pstrWFIDrv == NULL) {
7095                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7096         }
7097
7098         /* prepare the remainonchan Message */
7099         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7100
7101         /* prepare the WiphyParams Message */
7102         strHostIFmsg.u16MsgId = HOST_IF_MSG_REMAIN_ON_CHAN;
7103         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u16Channel = chan;
7104         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.pRemainOnChanExpired = RemainOnChanExpired;
7105         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.pRemainOnChanReady = RemainOnChanReady;
7106         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.pVoid = pvUserArg;
7107         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32duration = u32duration;
7108         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID;
7109         strHostIFmsg.drvHandler = hWFIDrv;
7110
7111         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7112         if (s32Error) {
7113                 WILC_ERRORREPORT(s32Error, s32Error);
7114         }
7115         WILC_CATCH(s32Error)
7116         {
7117
7118         }
7119
7120         return s32Error;
7121 }
7122
7123 /**
7124  *  @brief              host_int_ListenStateExpired
7125  *  @details
7126  *  @param[in]          Handle to wifi driver
7127  *                              Duration to remain on channel
7128  *                              Channel to remain on
7129  *                              Pointer to fn to be called on receive frames in listen state
7130  *                              Pointer to remain-on-channel expired fn
7131  *                              Priv
7132  *  @return             Error code.
7133  *  @author
7134  *  @date
7135  *  @version            1.0
7136  */
7137 s32 host_int_ListenStateExpired(WILC_WFIDrvHandle hWFIDrv, u32 u32SessionID)
7138 {
7139         s32 s32Error = WILC_SUCCESS;
7140         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7141         tstrHostIFmsg strHostIFmsg;
7142
7143         if (pstrWFIDrv == NULL) {
7144                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7145         }
7146
7147         /*Stopping remain-on-channel timer*/
7148         WILC_TimerStop(&(pstrWFIDrv->hRemainOnChannel), NULL);
7149
7150         /* prepare the timer fire Message */
7151         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7152         strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED;
7153         strHostIFmsg.drvHandler = hWFIDrv;
7154         strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID;
7155
7156         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7157         if (s32Error) {
7158                 WILC_ERRORREPORT(s32Error, s32Error);
7159         }
7160         WILC_CATCH(s32Error)
7161         {
7162
7163         }
7164         return s32Error;
7165 }
7166
7167 /**
7168  *  @brief              host_int_frame_register
7169  *  @details
7170  *  @param[in]          Handle to wifi driver
7171  *  @return             Error code.
7172  *  @author
7173  *  @date
7174  *  @version            1.0*/
7175 s32 host_int_frame_register(WILC_WFIDrvHandle hWFIDrv, u16 u16FrameType, bool bReg)
7176 {
7177         s32 s32Error = WILC_SUCCESS;
7178         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7179         tstrHostIFmsg strHostIFmsg;
7180
7181         if (pstrWFIDrv == NULL) {
7182                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7183         }
7184
7185         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7186
7187         /* prepare the WiphyParams Message */
7188         strHostIFmsg.u16MsgId = HOST_IF_MSG_REGISTER_FRAME;
7189         switch (u16FrameType) {
7190         case ACTION:
7191                 PRINT_D(HOSTINF_DBG, "ACTION\n");
7192                 strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.u8Regid = ACTION_FRM_IDX;
7193                 break;
7194
7195         case PROBE_REQ:
7196                 PRINT_D(HOSTINF_DBG, "PROBE REQ\n");
7197                 strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.u8Regid = PROBE_REQ_IDX;
7198                 break;
7199
7200         default:
7201                 PRINT_D(HOSTINF_DBG, "Not valid frame type\n");
7202                 break;
7203         }
7204         strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.u16FrameType = u16FrameType;
7205         strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.bReg = bReg;
7206         strHostIFmsg.drvHandler = hWFIDrv;
7207
7208         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7209         if (s32Error) {
7210                 WILC_ERRORREPORT(s32Error, s32Error);
7211         }
7212         WILC_CATCH(s32Error)
7213         {
7214
7215         }
7216
7217         return s32Error;
7218
7219
7220 }
7221 #endif
7222
7223 #ifdef WILC_AP_EXTERNAL_MLME
7224 /**
7225  *  @brief host_int_add_beacon
7226  *  @details       Setting add beacon params in message queue
7227  *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
7228  *                         u32 u32DTIMPeriod,u32 u32HeadLen, u8* pu8Head,
7229  *                         u32 u32TailLen, u8* pu8Tail
7230  *  @return         Error code.
7231  *  @author
7232  *  @date
7233  *  @version    1.0
7234  */
7235 s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
7236                                 u32 u32DTIMPeriod,
7237                                 u32 u32HeadLen, u8 *pu8Head,
7238                                 u32 u32TailLen, u8 *pu8Tail)
7239 {
7240         s32 s32Error = WILC_SUCCESS;
7241         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7242         tstrHostIFmsg strHostIFmsg;
7243         tstrHostIFSetBeacon *pstrSetBeaconParam = &strHostIFmsg.uniHostIFmsgBody.strHostIFSetBeacon;
7244
7245         if (pstrWFIDrv == NULL) {
7246                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7247         }
7248
7249         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7250
7251         PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
7252
7253
7254         /* prepare the WiphyParams Message */
7255         strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_BEACON;
7256         strHostIFmsg.drvHandler = hWFIDrv;
7257         pstrSetBeaconParam->u32Interval = u32Interval;
7258         pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
7259         pstrSetBeaconParam->u32HeadLen = u32HeadLen;
7260         pstrSetBeaconParam->pu8Head = (u8 *)WILC_MALLOC(u32HeadLen);
7261         if (pstrSetBeaconParam->pu8Head == NULL) {
7262                 WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
7263         }
7264         WILC_memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
7265         pstrSetBeaconParam->u32TailLen = u32TailLen;
7266
7267         /* Bug 4599 : if tail length = 0 skip allocating & copying */
7268         if (u32TailLen > 0) {
7269                 pstrSetBeaconParam->pu8Tail = (u8 *)WILC_MALLOC(u32TailLen);
7270                 if (pstrSetBeaconParam->pu8Tail == NULL) {
7271                         WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
7272                 }
7273                 WILC_memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
7274         } else {
7275                 pstrSetBeaconParam->pu8Tail = NULL;
7276         }
7277
7278         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7279         if (s32Error) {
7280                 WILC_ERRORREPORT(s32Error, s32Error);
7281         }
7282
7283         WILC_CATCH(s32Error)
7284         {
7285                 if (pstrSetBeaconParam->pu8Head != NULL) {
7286                         WILC_FREE(pstrSetBeaconParam->pu8Head);
7287                 }
7288
7289                 if (pstrSetBeaconParam->pu8Tail != NULL) {
7290                         WILC_FREE(pstrSetBeaconParam->pu8Tail);
7291                 }
7292         }
7293
7294         return s32Error;
7295
7296 }
7297
7298
7299 /**
7300  *  @brief host_int_del_beacon
7301  *  @details       Setting add beacon params in message queue
7302  *  @param[in]    WILC_WFIDrvHandle hWFIDrv
7303  *  @return         Error code.
7304  *  @author
7305  *  @date
7306  *  @version    1.0
7307  */
7308 s32 host_int_del_beacon(WILC_WFIDrvHandle hWFIDrv)
7309 {
7310         s32 s32Error = WILC_SUCCESS;
7311         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7312         tstrHostIFmsg strHostIFmsg;
7313
7314         if (pstrWFIDrv == NULL) {
7315                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7316         }
7317
7318         /* prepare the WiphyParams Message */
7319         strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BEACON;
7320         strHostIFmsg.drvHandler = hWFIDrv;
7321         PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
7322
7323         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7324         WILC_ERRORCHECK(s32Error);
7325
7326         WILC_CATCH(s32Error)
7327         {
7328         }
7329         return s32Error;
7330 }
7331
7332
7333 /**
7334  *  @brief host_int_add_station
7335  *  @details       Setting add station params in message queue
7336  *  @param[in]    WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam* pstrStaParams
7337  *  @return         Error code.
7338  *  @author
7339  *  @date
7340  *  @version    1.0
7341  */
7342 s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrStaParams)
7343 {
7344         s32 s32Error = WILC_SUCCESS;
7345         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7346         tstrHostIFmsg strHostIFmsg;
7347         tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam;
7348
7349
7350         if (pstrWFIDrv == NULL) {
7351                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7352         }
7353
7354         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7355
7356         PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
7357
7358
7359         /* prepare the WiphyParams Message */
7360         strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_STATION;
7361         strHostIFmsg.drvHandler = hWFIDrv;
7362
7363         WILC_memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam));
7364         if (pstrAddStationMsg->u8NumRates > 0) {
7365                 u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates);
7366                 WILC_NULLCHECK(s32Error, rates);
7367
7368                 WILC_memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
7369                 pstrAddStationMsg->pu8Rates = rates;
7370         }
7371
7372
7373         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7374         if (s32Error) {
7375                 WILC_ERRORREPORT(s32Error, s32Error);
7376         }
7377
7378         WILC_CATCH(s32Error)
7379         {
7380         }
7381         return s32Error;
7382 }
7383
7384 /**
7385  *  @brief host_int_del_station
7386  *  @details       Setting delete station params in message queue
7387  *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u8* pu8MacAddr
7388  *  @return         Error code.
7389  *  @author
7390  *  @date
7391  *  @version    1.0
7392  */
7393 s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, const u8 *pu8MacAddr)
7394 {
7395         s32 s32Error = WILC_SUCCESS;
7396         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7397         tstrHostIFmsg strHostIFmsg;
7398         tstrHostIFDelSta *pstrDelStationMsg = &strHostIFmsg.uniHostIFmsgBody.strDelStaParam;
7399
7400         if (pstrWFIDrv == NULL) {
7401                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7402         }
7403
7404         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7405
7406         PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
7407
7408
7409
7410         /* prepare the WiphyParams Message */
7411         strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_STATION;
7412         strHostIFmsg.drvHandler = hWFIDrv;
7413
7414         /*BugID_4795: Handling situation of deleting all stations*/
7415         if (pu8MacAddr == NULL)
7416                 WILC_memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN);
7417         else
7418                 WILC_memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN);
7419
7420         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7421         if (s32Error) {
7422                 WILC_ERRORREPORT(s32Error, s32Error);
7423         }
7424
7425         WILC_CATCH(s32Error)
7426         {
7427         }
7428         return s32Error;
7429 }
7430 /**
7431  *  @brief      host_int_del_allstation
7432  *  @details    Setting del station params in message queue
7433  *  @param[in]  WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]s
7434  *  @return        Error code.
7435  *  @author
7436  *  @date
7437  *  @version    1.0
7438  */
7439 s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN])
7440 {
7441         s32 s32Error = WILC_SUCCESS;
7442         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7443         tstrHostIFmsg strHostIFmsg;
7444         tstrHostIFDelAllSta *pstrDelAllStationMsg = &strHostIFmsg.uniHostIFmsgBody.strHostIFDelAllSta;
7445         u8 au8Zero_Buff[ETH_ALEN] = {0};
7446         u32 i;
7447         u8 u8AssocNumb = 0;
7448
7449
7450         if (pstrWFIDrv == NULL) {
7451                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7452         }
7453
7454         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7455
7456         PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
7457
7458         /* prepare the WiphyParams Message */
7459         strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_ALL_STA;
7460         strHostIFmsg.drvHandler = hWFIDrv;
7461
7462         /* Handling situation of deauthenticing all associated stations*/
7463         for (i = 0; i < MAX_NUM_STA; i++) {
7464                 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
7465                         WILC_memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN);
7466                         PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n", pstrDelAllStationMsg->au8Sta_DelAllSta[i][0], pstrDelAllStationMsg->au8Sta_DelAllSta[i][1], pstrDelAllStationMsg->au8Sta_DelAllSta[i][2], pstrDelAllStationMsg->au8Sta_DelAllSta[i][3], pstrDelAllStationMsg->au8Sta_DelAllSta[i][4],
7467                                 pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]);
7468                         u8AssocNumb++;
7469                 }
7470         }
7471         if (!u8AssocNumb) {
7472                 PRINT_D(CFG80211_DBG, "NO ASSOCIATED STAS\n");
7473                 return s32Error;
7474         }
7475
7476         pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb;
7477         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7478
7479
7480         if (s32Error) {
7481                 WILC_ERRORREPORT(s32Error, s32Error);
7482
7483         }
7484         WILC_CATCH(s32Error)
7485         {
7486
7487         }
7488         down(&hWaitResponse);
7489
7490         return s32Error;
7491
7492 }
7493
7494 /**
7495  *  @brief host_int_edit_station
7496  *  @details       Setting edit station params in message queue
7497  *  @param[in]    WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam* pstrStaParams
7498  *  @return         Error code.
7499  *  @author
7500  *  @date
7501  *  @version    1.0
7502  */
7503 s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam *pstrStaParams)
7504 {
7505         s32 s32Error = WILC_SUCCESS;
7506         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7507         tstrHostIFmsg strHostIFmsg;
7508         tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam;
7509
7510         if (pstrWFIDrv == NULL) {
7511                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7512         }
7513
7514         PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
7515
7516         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7517
7518
7519         /* prepare the WiphyParams Message */
7520         strHostIFmsg.u16MsgId = HOST_IF_MSG_EDIT_STATION;
7521         strHostIFmsg.drvHandler = hWFIDrv;
7522
7523         WILC_memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam));
7524         if (pstrAddStationMsg->u8NumRates > 0) {
7525                 u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates);
7526                 WILC_NULLCHECK(s32Error, rates);
7527                 WILC_memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
7528                 pstrAddStationMsg->pu8Rates = rates;
7529         }
7530
7531         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7532         if (s32Error) {
7533                 WILC_ERRORREPORT(s32Error, s32Error);
7534         }
7535         WILC_CATCH(s32Error)
7536         {
7537         }
7538         return s32Error;
7539 }
7540 #endif /*WILC_AP_EXTERNAL_MLME*/
7541 uint32_t wilc_get_chipid(uint8_t);
7542
7543 s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout)
7544 {
7545         s32 s32Error = WILC_SUCCESS;
7546         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7547         tstrHostIFmsg strHostIFmsg;
7548         tstrHostIfPowerMgmtParam *pstrPowerMgmtParam = &strHostIFmsg.uniHostIFmsgBody.strPowerMgmtparam;
7549
7550         PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d << \n\n", bIsEnabled);
7551
7552         if (pstrWFIDrv == NULL) {
7553                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7554         }
7555
7556         PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
7557
7558         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7559
7560
7561         /* prepare the WiphyParams Message */
7562         strHostIFmsg.u16MsgId = HOST_IF_MSG_POWER_MGMT;
7563         strHostIFmsg.drvHandler = hWFIDrv;
7564
7565         pstrPowerMgmtParam->bIsEnabled = bIsEnabled;
7566         pstrPowerMgmtParam->u32Timeout = u32Timeout;
7567
7568
7569         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7570         if (s32Error) {
7571                 WILC_ERRORREPORT(s32Error, s32Error);
7572         }
7573         WILC_CATCH(s32Error)
7574         {
7575         }
7576         return s32Error;
7577 }
7578
7579 s32 host_int_setup_multicast_filter(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32count)
7580 {
7581         s32 s32Error = WILC_SUCCESS;
7582
7583         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7584         tstrHostIFmsg strHostIFmsg;
7585         tstrHostIFSetMulti *pstrMulticastFilterParam = &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMulti;
7586
7587
7588         if (pstrWFIDrv == NULL) {
7589                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7590         }
7591
7592         PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
7593
7594         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7595
7596
7597         /* prepare the WiphyParams Message */
7598         strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_MULTICAST_FILTER;
7599         strHostIFmsg.drvHandler = hWFIDrv;
7600
7601         pstrMulticastFilterParam->bIsEnabled = bIsEnabled;
7602         pstrMulticastFilterParam->u32count = u32count;
7603
7604         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7605         if (s32Error) {
7606                 WILC_ERRORREPORT(s32Error, s32Error);
7607         }
7608         WILC_CATCH(s32Error)
7609         {
7610         }
7611         return s32Error;
7612 }
7613
7614
7615
7616 /*Bug4218: Parsing Join Param*/
7617 #ifdef WILC_PARSE_SCAN_IN_HOST
7618
7619 /*Bug4218: Parsing Join Param*/
7620 /**
7621  *  @brief              host_int_ParseJoinBssParam
7622  *  @details            Parse Needed Join Parameters and save it in a new JoinBssParam entry
7623  *  @param[in]          tstrNetworkInfo* ptstrNetworkInfo
7624  *  @return
7625  *  @author             zsalah
7626  *  @date
7627  *  @version            1.0**/
7628 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
7629 {
7630         tstrJoinBssParam *pNewJoinBssParam = NULL;
7631         u8 *pu8IEs;
7632         u16 u16IEsLen;
7633         u16 index = 0;
7634         u8 suppRatesNo = 0;
7635         u8 extSuppRatesNo;
7636         u16 jumpOffset;
7637         u8 pcipherCount;
7638         u8 authCount;
7639         u8 pcipherTotalCount = 0;
7640         u8 authTotalCount = 0;
7641         u8 i, j;
7642
7643         pu8IEs = ptstrNetworkInfo->pu8IEs;
7644         u16IEsLen = ptstrNetworkInfo->u16IEsLen;
7645
7646         pNewJoinBssParam = WILC_MALLOC(sizeof(tstrJoinBssParam));
7647         if (pNewJoinBssParam != NULL) {
7648                 WILC_memset(pNewJoinBssParam, 0, sizeof(tstrJoinBssParam));
7649                 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
7650                 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
7651                 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
7652                 WILC_memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
7653                 /*for(i=0; i<6;i++)
7654                  *      PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->au8bssid[i]);*/
7655                 WILC_memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
7656                 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
7657                 WILC_memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
7658                 WILC_memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
7659                 /*for(i=0; i<pNewJoinBssParam->ssidLen;i++)
7660                  *      PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->ssid[i]);*/
7661
7662                 /* parse supported rates: */
7663                 while (index < u16IEsLen) {
7664                         /* supportedRates IE */
7665                         if (pu8IEs[index] == SUPP_RATES_IE) {
7666                                 /* PRINT_D(HOSTINF_DBG, "Supported Rates\n"); */
7667                                 suppRatesNo = pu8IEs[index + 1];
7668                                 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
7669                                 index += 2; /* skipping ID and length bytes; */
7670
7671                                 for (i = 0; i < suppRatesNo; i++) {
7672                                         pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
7673                                         /* PRINT_D(HOSTINF_DBG,"%0x ",pNewJoinBssParam->supp_rates[i+1]); */
7674                                 }
7675                                 index += suppRatesNo;
7676                                 continue;
7677                         }
7678                         /* Ext SupportedRates IE */
7679                         else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
7680                                 /* PRINT_D(HOSTINF_DBG, "Extended Supported Rates\n"); */
7681                                 /* checking if no of ext. supp and supp rates < max limit */
7682                                 extSuppRatesNo = pu8IEs[index + 1];
7683                                 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
7684                                         pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
7685                                 else
7686                                         pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
7687                                 index += 2;
7688                                 /* pNewJoinBssParam.supp_rates[0] contains now old number not the ext. no */
7689                                 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++) {
7690                                         pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
7691                                         /* PRINT_D(HOSTINF_DBG,"%0x ",pNewJoinBssParam->supp_rates[suppRatesNo+i+1]); */
7692                                 }
7693                                 index += extSuppRatesNo;
7694                                 continue;
7695                         }
7696                         /* HT Cap. IE */
7697                         else if (pu8IEs[index] == HT_CAPABILITY_IE) {
7698                                 /* if IE found set the flag */
7699                                 pNewJoinBssParam->ht_capable = true;
7700                                 index += pu8IEs[index + 1] + 2; /* ID,Length bytes and IE body */
7701                                 /* PRINT_D(HOSTINF_DBG,"HT_CAPABALE\n"); */
7702                                 continue;
7703                         } else if ((pu8IEs[index] == WMM_IE) && /* WMM Element ID */
7704                                    (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
7705                                    (pu8IEs[index + 4] == 0xF2) && /* OUI */
7706                                    (pu8IEs[index + 5] == 0x02) && /* OUI Type     */
7707                                    ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) && /* OUI Sub Type */
7708                                    (pu8IEs[index + 7] == 0x01)) {
7709                                 /* Presence of WMM Info/Param element indicates WMM capability */
7710                                 pNewJoinBssParam->wmm_cap = true;
7711
7712                                 /* Check if Bit 7 is set indicating U-APSD capability */
7713                                 if (pu8IEs[index + 8] & (1 << 7)) {
7714                                         pNewJoinBssParam->uapsd_cap = true;
7715                                 }
7716                                 index += pu8IEs[index + 1] + 2;
7717                                 continue;
7718                         }
7719                         #ifdef WILC_P2P
7720                         else if ((pu8IEs[index] == P2P_IE) && /* P2P Element ID */
7721                                  (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
7722                                  (pu8IEs[index + 4] == 0x9a) && /* OUI */
7723                                  (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) { /* OUI Type     */
7724                                 u16 u16P2P_count;
7725                                 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
7726                                 pNewJoinBssParam->u8NoaEnbaled = 1;
7727                                 pNewJoinBssParam->u8Index = pu8IEs[index + 9];
7728
7729                                 /* Check if Bit 7 is set indicating Opss capability */
7730                                 if (pu8IEs[index + 10] & (1 << 7)) {
7731                                         pNewJoinBssParam->u8OppEnable = 1;
7732                                         pNewJoinBssParam->u8CtWindow = pu8IEs[index + 10];
7733                                 } else
7734                                         pNewJoinBssParam->u8OppEnable = 0;
7735                                 /* HOSTINF_DBG */
7736                                 PRINT_D(GENERIC_DBG, "P2P Dump \n");
7737                                 for (i = 0; i < pu8IEs[index + 7]; i++)
7738                                         PRINT_D(GENERIC_DBG, " %x \n", pu8IEs[index + 9 + i]);
7739
7740                                 pNewJoinBssParam->u8Count = pu8IEs[index + 11];
7741                                 u16P2P_count = index + 12;
7742
7743                                 WILC_memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
7744                                 u16P2P_count += 4;
7745
7746                                 WILC_memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
7747                                 u16P2P_count += 4;
7748
7749                                 WILC_memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
7750
7751                                 index += pu8IEs[index + 1] + 2;
7752                                 continue;
7753
7754                         }
7755                         #endif
7756                         else if ((pu8IEs[index] == RSN_IE) ||
7757                                  ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
7758                                   (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
7759                                   (pu8IEs[index + 5] == 0x01))) {
7760                                 u16 rsnIndex = index;
7761                                 /*PRINT_D(HOSTINF_DBG,"RSN IE Length:%d\n",pu8IEs[rsnIndex+1]);
7762                                  * for(i=0; i<pu8IEs[rsnIndex+1]; i++)
7763                                  * {
7764                                  *      PRINT_D(HOSTINF_DBG,"%0x ",pu8IEs[rsnIndex+2+i]);
7765                                  * }*/
7766                                 if (pu8IEs[rsnIndex] == RSN_IE) {
7767                                         pNewJoinBssParam->mode_802_11i = 2;
7768                                         /* PRINT_D(HOSTINF_DBG,"\nRSN_IE\n"); */
7769                                 } else { /* check if rsn was previously parsed */
7770                                         if (pNewJoinBssParam->mode_802_11i == 0)
7771                                                 pNewJoinBssParam->mode_802_11i = 1;
7772                                         /* PRINT_D(HOSTINF_DBG,"\nWPA_IE\n"); */
7773                                         rsnIndex += 4;
7774                                 }
7775                                 rsnIndex += 7; /* skipping id, length, version(2B) and first 3 bytes of gcipher */
7776                                 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
7777                                 rsnIndex++;
7778                                 /* PRINT_D(HOSTINF_DBG,"Group Policy: %0x \n",pNewJoinBssParam->rsn_grp_policy); */
7779                                 /* initialize policies with invalid values */
7780
7781                                 jumpOffset = pu8IEs[rsnIndex] * 4; /* total no.of bytes of pcipher field (count*4) */
7782
7783                                 /*parsing pairwise cipher*/
7784
7785                                 /* saving 3 pcipher max. */
7786                                 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
7787                                 rsnIndex += 2; /* jump 2 bytes of pcipher count */
7788
7789                                 /* PRINT_D(HOSTINF_DBG,"\npcipher:%d \n",pcipherCount); */
7790                                 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
7791                                         /* each count corresponds to 4 bytes, only last byte is saved */
7792                                         pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
7793                                         /* PRINT_D(HOSTINF_DBG,"PAIR policy = [%0x,%0x]\n",pNewJoinBssParam->rsn_pcip_policy[i],i); */
7794                                 }
7795                                 pcipherTotalCount += pcipherCount;
7796                                 rsnIndex += jumpOffset;
7797
7798                                 jumpOffset = pu8IEs[rsnIndex] * 4;
7799
7800                                 /*parsing AKM suite (auth_policy)*/
7801                                 /* saving 3 auth policies max. */
7802                                 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
7803                                 rsnIndex += 2; /* jump 2 bytes of pcipher count */
7804
7805                                 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++) {
7806                                         /* each count corresponds to 4 bytes, only last byte is saved */
7807                                         pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
7808                                 }
7809                                 authTotalCount += authCount;
7810                                 rsnIndex += jumpOffset;
7811                                 /*pasring rsn cap. only if rsn IE*/
7812                                 if (pu8IEs[index] == RSN_IE) {
7813                                         pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
7814                                         pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
7815                                         rsnIndex += 2;
7816                                 }
7817                                 pNewJoinBssParam->rsn_found = true;
7818                                 index += pu8IEs[index + 1] + 2; /* ID,Length bytes and IE body */
7819                                 continue;
7820                         } else
7821                                 index += pu8IEs[index + 1] + 2;  /* ID,Length bytes and IE body */
7822
7823                 }
7824
7825
7826         }
7827
7828         return (void *)pNewJoinBssParam;
7829
7830 }
7831
7832 void host_int_freeJoinParams(void *pJoinParams)
7833 {
7834         if ((tstrJoinBssParam *)pJoinParams != NULL)
7835                 WILC_FREE((tstrJoinBssParam *)pJoinParams);
7836         else
7837                 PRINT_ER("Unable to FREE null pointer\n");
7838 }
7839 #endif  /*WILC_PARSE_SCAN_IN_HOST*/
7840
7841
7842 /**
7843  *  @brief              host_int_addBASession
7844  *  @details            Open a block Ack session with the given parameters
7845  *  @param[in]          tstrNetworkInfo* ptstrNetworkInfo
7846  *  @return
7847  *  @author             anoureldin
7848  *  @date
7849  *  @version            1.0**/
7850
7851 static int host_int_addBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID, short int BufferSize,
7852                                  short int SessionTimeout, void *drvHandler)
7853 {
7854         s32 s32Error = WILC_SUCCESS;
7855         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7856         tstrHostIFmsg strHostIFmsg;
7857         tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
7858
7859         if (pstrWFIDrv == NULL) {
7860                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7861         }
7862
7863         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7864
7865         /* prepare the WiphyParams Message */
7866         strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_BA_SESSION;
7867
7868         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
7869         pBASessionInfo->u8Ted = TID;
7870         pBASessionInfo->u16BufferSize = BufferSize;
7871         pBASessionInfo->u16SessionTimeout = SessionTimeout;
7872         strHostIFmsg.drvHandler = hWFIDrv;
7873
7874         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7875         if (s32Error) {
7876                 WILC_ERRORREPORT(s32Error, s32Error);
7877         }
7878         WILC_CATCH(s32Error)
7879         {
7880
7881         }
7882
7883         return s32Error;
7884 }
7885
7886
7887 s32 host_int_delBASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID)
7888 {
7889         s32 s32Error = WILC_SUCCESS;
7890         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7891         tstrHostIFmsg strHostIFmsg;
7892         tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
7893
7894         if (pstrWFIDrv == NULL) {
7895                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7896         }
7897
7898         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7899
7900         /* prepare the WiphyParams Message */
7901         strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BA_SESSION;
7902
7903         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
7904         pBASessionInfo->u8Ted = TID;
7905         strHostIFmsg.drvHandler = hWFIDrv;
7906
7907         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7908         if (s32Error) {
7909                 WILC_ERRORREPORT(s32Error, s32Error);
7910         }
7911         WILC_CATCH(s32Error)
7912         {
7913
7914         }
7915
7916         /*BugID_5222*/
7917         down(&hWaitResponse);
7918
7919         return s32Error;
7920 }
7921
7922 s32 host_int_del_All_Rx_BASession(WILC_WFIDrvHandle hWFIDrv, char *pBSSID, char TID)
7923 {
7924         s32 s32Error = WILC_SUCCESS;
7925         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7926         tstrHostIFmsg strHostIFmsg;
7927         tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
7928
7929         if (pstrWFIDrv == NULL) {
7930                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7931         }
7932
7933         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7934
7935         /* prepare the WiphyParams Message */
7936         strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
7937
7938         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
7939         pBASessionInfo->u8Ted = TID;
7940         strHostIFmsg.drvHandler = hWFIDrv;
7941
7942         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7943         if (s32Error) {
7944                 WILC_ERRORREPORT(s32Error, s32Error);
7945         }
7946         WILC_CATCH(s32Error)
7947         {
7948
7949         }
7950
7951         /*BugID_5222*/
7952         down(&hWaitResponse);
7953
7954         return s32Error;
7955 }
7956
7957 /**
7958  *  @brief              host_int_setup_ipaddress
7959  *  @details            setup IP in firmware
7960  *  @param[in]          Handle to wifi driver
7961  *  @return             Error code.
7962  *  @author             Abdelrahman Sobhy
7963  *  @date
7964  *  @version            1.0*/
7965 s32 host_int_setup_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx)
7966 {
7967         s32 s32Error = WILC_SUCCESS;
7968         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
7969         tstrHostIFmsg strHostIFmsg;
7970
7971         /* TODO: Enable This feature on softap firmware */
7972         return 0;
7973
7974         if (pstrWFIDrv == NULL) {
7975                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
7976         }
7977
7978         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
7979
7980         /* prepare the WiphyParams Message */
7981         strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_IPADDRESS;
7982
7983         strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr = u16ipadd;
7984         strHostIFmsg.drvHandler = hWFIDrv;
7985         strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx = idx;
7986
7987         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
7988         if (s32Error) {
7989                 WILC_ERRORREPORT(s32Error, s32Error);
7990         }
7991         WILC_CATCH(s32Error)
7992         {
7993
7994         }
7995
7996         return s32Error;
7997
7998
7999 }
8000
8001 /**
8002  *  @brief              host_int_get_ipaddress
8003  *  @details            Get IP from firmware
8004  *  @param[in]          Handle to wifi driver
8005  *  @return             Error code.
8006  *  @author             Abdelrahman Sobhy
8007  *  @date
8008  *  @version            1.0*/
8009 s32 host_int_get_ipaddress(WILC_WFIDrvHandle hWFIDrv, u8 *u16ipadd, u8 idx)
8010 {
8011         s32 s32Error = WILC_SUCCESS;
8012         tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
8013         tstrHostIFmsg strHostIFmsg;
8014
8015         if (pstrWFIDrv == NULL) {
8016                 WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
8017         }
8018
8019         WILC_memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
8020
8021         /* prepare the WiphyParams Message */
8022         strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_IPADDRESS;
8023
8024         strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr = u16ipadd;
8025         strHostIFmsg.drvHandler=hWFIDrv;
8026         strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx= idx;
8027
8028         s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), NULL);
8029         if (s32Error) {
8030                 WILC_ERRORREPORT(s32Error, s32Error);
8031         }
8032         WILC_CATCH(s32Error)
8033         {
8034
8035         }
8036
8037         return s32Error;
8038
8039
8040 }