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