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