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