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