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