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