staging: wilc1000: fix "ERROR: do not initialise globals to 0 or NULL"
[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 #define HOST_IF_MSG_SCAN                        0
18 #define HOST_IF_MSG_CONNECT                     1
19 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO        2
20 #define HOST_IF_MSG_KEY                         3
21 #define HOST_IF_MSG_RCVD_NTWRK_INFO             4
22 #define HOST_IF_MSG_RCVD_SCAN_COMPLETE          5
23 #define HOST_IF_MSG_CFG_PARAMS                  6
24 #define HOST_IF_MSG_SET_CHANNEL                 7
25 #define HOST_IF_MSG_DISCONNECT                  8
26 #define HOST_IF_MSG_GET_RSSI                    9
27 #define HOST_IF_MSG_GET_CHNL                    10
28 #define HOST_IF_MSG_ADD_BEACON                  11
29 #define HOST_IF_MSG_DEL_BEACON                  12
30 #define HOST_IF_MSG_ADD_STATION                 13
31 #define HOST_IF_MSG_DEL_STATION                 14
32 #define HOST_IF_MSG_EDIT_STATION                15
33 #define HOST_IF_MSG_SCAN_TIMER_FIRED            16
34 #define HOST_IF_MSG_CONNECT_TIMER_FIRED         17
35 #define HOST_IF_MSG_POWER_MGMT                  18
36 #define HOST_IF_MSG_GET_INACTIVETIME            19
37 #define HOST_IF_MSG_REMAIN_ON_CHAN              20
38 #define HOST_IF_MSG_REGISTER_FRAME              21
39 #define HOST_IF_MSG_LISTEN_TIMER_FIRED          22
40 #define HOST_IF_MSG_GET_LINKSPEED               23
41 #define HOST_IF_MSG_SET_WFIDRV_HANDLER          24
42 #define HOST_IF_MSG_SET_MAC_ADDRESS             25
43 #define HOST_IF_MSG_GET_MAC_ADDRESS             26
44 #define HOST_IF_MSG_SET_OPERATION_MODE          27
45 #define HOST_IF_MSG_SET_IPADDRESS               28
46 #define HOST_IF_MSG_GET_IPADDRESS               29
47 #define HOST_IF_MSG_FLUSH_CONNECT               30
48 #define HOST_IF_MSG_GET_STATISTICS              31
49 #define HOST_IF_MSG_SET_MULTICAST_FILTER        32
50 #define HOST_IF_MSG_ADD_BA_SESSION              33
51 #define HOST_IF_MSG_DEL_BA_SESSION              34
52 #define HOST_IF_MSG_Q_IDLE                      35
53 #define HOST_IF_MSG_DEL_ALL_STA                 36
54 #define HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS      34
55 #define HOST_IF_MSG_EXIT                        100
56
57 #define HOST_IF_SCAN_TIMEOUT                    4000
58 #define HOST_IF_CONNECT_TIMEOUT                 9500
59
60 #define BA_SESSION_DEFAULT_BUFFER_SIZE          16
61 #define BA_SESSION_DEFAULT_TIMEOUT              1000
62 #define BLOCK_ACK_REQ_SIZE                      0x14
63
64 struct cfg_param_attr {
65         struct cfg_param_val cfg_attr_info;
66 };
67
68 struct host_if_wpa_attr {
69         u8 *key;
70         const u8 *mac_addr;
71         u8 *seq;
72         u8 seq_len;
73         u8 index;
74         u8 key_len;
75         u8 mode;
76 };
77
78 struct host_if_wep_attr {
79         u8 *key;
80         u8 key_len;
81         u8 index;
82         u8 mode;
83         enum AUTHTYPE auth_type;
84 };
85
86 union host_if_key_attr {
87         struct host_if_wep_attr wep;
88         struct host_if_wpa_attr wpa;
89         struct host_if_pmkid_attr pmkid;
90 };
91
92 struct key_attr {
93         enum KEY_TYPE type;
94         u8 action;
95         union host_if_key_attr attr;
96 };
97
98 struct scan_attr {
99         u8 src;
100         u8 type;
101         u8 *ch_freq_list;
102         u8 ch_list_len;
103         u8 *ies;
104         size_t ies_len;
105         wilc_scan_result result;
106         void *arg;
107         struct hidden_network hidden_network;
108 };
109
110 struct connect_attr {
111         u8 *pu8bssid;
112         u8 *pu8ssid;
113         size_t ssidLen;
114         u8 *pu8IEs;
115         size_t IEsLen;
116         u8 u8security;
117         wilc_connect_result pfConnectResult;
118         void *pvUserArg;
119         enum AUTHTYPE tenuAuth_type;
120         u8 u8channel;
121         void *pJoinParams;
122 };
123
124 struct rcvd_async_info {
125         u8 *pu8Buffer;
126         u32 u32Length;
127 };
128
129 struct channel_attr {
130         u8 u8SetChan;
131 };
132
133 struct beacon_attr {
134         u32 u32Interval;
135         u32 u32DTIMPeriod;
136         u32 u32HeadLen;
137         u8 *pu8Head;
138         u32 u32TailLen;
139         u8 *pu8Tail;
140 };
141
142 struct set_multicast {
143         bool bIsEnabled;
144         u32 u32count;
145 };
146
147 struct del_all_sta {
148         u8 au8Sta_DelAllSta[MAX_NUM_STA][ETH_ALEN];
149         u8 u8Num_AssocSta;
150 };
151
152 struct del_sta {
153         u8 au8MacAddr[ETH_ALEN];
154 };
155
156 struct power_mgmt_param {
157
158         bool bIsEnabled;
159         u32 u32Timeout;
160 };
161
162 struct set_ip_addr {
163         u8 *au8IPAddr;
164         u8 idx;
165 };
166
167 struct sta_inactive_t {
168         u8 mac[6];
169 };
170
171 union message_body {
172         struct scan_attr scan_info;
173         struct connect_attr con_info;
174         struct rcvd_net_info net_info;
175         struct rcvd_async_info async_info;
176         struct key_attr key_info;
177         struct cfg_param_attr cfg_info;
178         struct channel_attr channel_info;
179         struct beacon_attr beacon_info;
180         struct add_sta_param add_sta_info;
181         struct del_sta del_sta_info;
182         struct add_sta_param edit_sta_info;
183         struct power_mgmt_param pwr_mgmt_info;
184         struct sta_inactive_t mac_info;
185         struct set_ip_addr ip_info;
186         struct drv_handler drv;
187         struct set_multicast multicast_info;
188         struct op_mode mode;
189         struct set_mac_addr set_mac_info;
190         struct get_mac_addr get_mac_info;
191         struct ba_session_info session_info;
192         struct remain_ch remain_on_ch;
193         struct reg_frame reg_frame;
194         char *data;
195         struct del_all_sta del_all_sta_info;
196 };
197
198 struct host_if_msg {
199         u16 id;
200         union message_body body;
201         struct host_if_drv *drv;
202 };
203
204 struct join_bss_param {
205         BSSTYPE_T bss_type;
206         u8 dtim_period;
207         u16 beacon_period;
208         u16 cap_info;
209         u8 au8bssid[6];
210         char ssid[MAX_SSID_LEN];
211         u8 ssidLen;
212         u8 supp_rates[MAX_RATES_SUPPORTED + 1];
213         u8 ht_capable;
214         u8 wmm_cap;
215         u8 uapsd_cap;
216         bool rsn_found;
217         u8 rsn_grp_policy;
218         u8 mode_802_11i;
219         u8 rsn_pcip_policy[3];
220         u8 rsn_auth_policy[3];
221         u8 rsn_cap[2];
222         u32 tsf;
223         u8 u8NoaEnbaled;
224         u8 u8OppEnable;
225         u8 u8CtWindow;
226         u8 u8Count;
227         u8 u8Index;
228         u8 au8Duration[4];
229         u8 au8Interval[4];
230         u8 au8StartTime[4];
231 };
232
233 enum scan_conn_timer {
234         SCAN_TIMER = 0,
235         CONNECT_TIMER   = 1,
236         SCAN_CONNECT_TIMER_FORCE_32BIT = 0xFFFFFFFF
237 };
238
239 static struct host_if_drv *wfidrv_list[NUM_CONCURRENT_IFC + 1];
240 struct host_if_drv *terminated_handle;
241 struct host_if_drv *gWFiDrvHandle;
242 bool g_obtainingIP;
243 u8 P2P_LISTEN_STATE;
244 static struct task_struct *HostIFthreadHandler;
245 static WILC_MsgQueueHandle gMsgQHostIF;
246 static struct semaphore hSemHostIFthrdEnd;
247
248 struct semaphore hSemDeinitDrvHandle;
249 static struct semaphore hWaitResponse;
250 struct semaphore hSemHostIntDeinit;
251 struct timer_list g_hPeriodicRSSI;
252
253
254
255 u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
256
257 static u8 gapu8RcvdAssocResp[MAX_ASSOC_RESP_FRAME_SIZE];
258
259 bool gbScanWhileConnected;
260
261 static s8 gs8Rssi;
262 static s8 gs8lnkspd;
263 static u8 gu8Chnl;
264 static u8 gs8SetIP[2][4];
265 static u8 gs8GetIP[2][4];
266 static u32 gu32InactiveTime;
267 static u8 gu8DelBcn;
268 static u32 gu32WidConnRstHack;
269
270 u8 *gu8FlushedJoinReq;
271 u8 *gu8FlushedInfoElemAsoc;
272 u8 gu8Flushed11iMode;
273 u8 gu8FlushedAuthType;
274 u32 gu32FlushedJoinReqSize;
275 u32 gu32FlushedInfoElemAsocSize;
276 struct host_if_drv *gu8FlushedJoinReqDrvHandler;
277 #define REAL_JOIN_REQ 0
278 #define FLUSHED_JOIN_REQ 1
279 #define FLUSHED_BYTE_POS 79
280
281 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo);
282
283 extern void chip_sleep_manually(u32 u32SleepTime);
284 extern int linux_wlan_get_num_conn_ifcs(void);
285
286 static int add_handler_in_list(struct host_if_drv *handler)
287 {
288         int i;
289
290         for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
291                 if (!wfidrv_list[i]) {
292                         wfidrv_list[i] = handler;
293                         return 0;
294                 }
295         }
296
297         return -ENOBUFS;
298 }
299
300 static int remove_handler_in_list(struct host_if_drv *handler)
301 {
302         int i;
303
304         for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
305                 if (wfidrv_list[i] == handler) {
306                         wfidrv_list[i] = NULL;
307                         return 0;
308                 }
309         }
310
311         return -EINVAL;
312 }
313
314 static int get_id_from_handler(struct host_if_drv *handler)
315 {
316         int i;
317
318         if (!handler)
319                 return 0;
320
321         for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
322                 if (wfidrv_list[i] == handler)
323                         return i;
324         }
325
326         return 0;
327 }
328
329 static struct host_if_drv *get_handler_from_id(int id)
330 {
331         if (id <= 0 || id >= ARRAY_SIZE(wfidrv_list))
332                 return NULL;
333         return wfidrv_list[id];
334 }
335
336 static s32 Handle_SetChannel(struct host_if_drv *hif_drv,
337                              struct channel_attr *pstrHostIFSetChan)
338 {
339
340         s32 s32Error = 0;
341         struct wid strWID;
342
343         strWID.id = (u16)WID_CURRENT_CHANNEL;
344         strWID.type = WID_CHAR;
345         strWID.val = (char *)&(pstrHostIFSetChan->u8SetChan);
346         strWID.size = sizeof(char);
347
348         PRINT_D(HOSTINF_DBG, "Setting channel\n");
349
350         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
351                                    get_id_from_handler(hif_drv));
352         if (s32Error) {
353                 PRINT_ER("Failed to set channel\n");
354                 return -EINVAL;
355         }
356
357         return s32Error;
358 }
359
360 static s32 Handle_SetWfiDrvHandler(struct host_if_drv *hif_drv,
361                                    struct drv_handler *pstrHostIfSetDrvHandler)
362 {
363
364         s32 s32Error = 0;
365         struct wid strWID;
366
367         strWID.id = (u16)WID_SET_DRV_HANDLER;
368         strWID.type = WID_INT;
369         strWID.val = (s8 *)&(pstrHostIfSetDrvHandler->u32Address);
370         strWID.size = sizeof(u32);
371
372         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
373                                    pstrHostIfSetDrvHandler->u32Address);
374
375         if (!hif_drv)
376                 up(&hSemDeinitDrvHandle);
377
378
379         if (s32Error) {
380                 PRINT_ER("Failed to set driver handler\n");
381                 return -EINVAL;
382         }
383
384         return s32Error;
385 }
386
387 static s32 Handle_SetOperationMode(struct host_if_drv *hif_drv,
388                                    struct op_mode *pstrHostIfSetOperationMode)
389 {
390
391         s32 s32Error = 0;
392         struct wid strWID;
393
394         strWID.id = (u16)WID_SET_OPERATION_MODE;
395         strWID.type = WID_INT;
396         strWID.val = (s8 *)&(pstrHostIfSetOperationMode->u32Mode);
397         strWID.size = sizeof(u32);
398
399         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
400                                    get_id_from_handler(hif_drv));
401
402
403         if ((pstrHostIfSetOperationMode->u32Mode) == IDLE_MODE)
404                 up(&hSemDeinitDrvHandle);
405
406
407         if (s32Error) {
408                 PRINT_ER("Failed to set driver handler\n");
409                 return -EINVAL;
410         }
411
412         return s32Error;
413 }
414
415 s32 Handle_set_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx)
416 {
417
418         s32 s32Error = 0;
419         struct wid strWID;
420         char firmwareIPAddress[4] = {0};
421
422         if (pu8IPAddr[0] < 192)
423                 pu8IPAddr[0] = 0;
424
425         PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set  IP = %pI4\n", idx, pu8IPAddr);
426
427         memcpy(gs8SetIP[idx], pu8IPAddr, IP_ALEN);
428
429         strWID.id = (u16)WID_IP_ADDRESS;
430         strWID.type = WID_STR;
431         strWID.val = (u8 *)pu8IPAddr;
432         strWID.size = IP_ALEN;
433
434         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
435                                    get_id_from_handler(hif_drv));
436
437
438         host_int_get_ipaddress(hif_drv, firmwareIPAddress, idx);
439
440         if (s32Error) {
441                 PRINT_ER("Failed to set IP address\n");
442                 return -EINVAL;
443         }
444
445         PRINT_INFO(HOSTINF_DBG, "IP address set\n");
446
447         return s32Error;
448 }
449
450 s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx)
451 {
452
453         s32 s32Error = 0;
454         struct wid strWID;
455
456         strWID.id = (u16)WID_IP_ADDRESS;
457         strWID.type = WID_STR;
458         strWID.val = kmalloc(IP_ALEN, GFP_KERNEL);
459         strWID.size = IP_ALEN;
460
461         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
462                                    get_id_from_handler(hif_drv));
463
464         PRINT_INFO(HOSTINF_DBG, "%pI4\n", strWID.val);
465
466         memcpy(gs8GetIP[idx], strWID.val, IP_ALEN);
467
468         kfree(strWID.val);
469
470         if (memcmp(gs8GetIP[idx], gs8SetIP[idx], IP_ALEN) != 0)
471                 host_int_setup_ipaddress(hif_drv, gs8SetIP[idx], idx);
472
473         if (s32Error != 0) {
474                 PRINT_ER("Failed to get IP address\n");
475                 return -EINVAL;
476         }
477
478         PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d\n", idx);
479         PRINT_INFO(HOSTINF_DBG, "%pI4\n", gs8GetIP[idx]);
480         PRINT_INFO(HOSTINF_DBG, "\n");
481
482         return s32Error;
483 }
484
485 static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv,
486                                 struct set_mac_addr *pstrHostIfSetMacAddress)
487 {
488
489         s32 s32Error = 0;
490         struct wid strWID;
491         u8 *mac_buf = kmalloc(ETH_ALEN, GFP_KERNEL);
492
493         if (mac_buf == NULL) {
494                 PRINT_ER("No buffer to send mac address\n");
495                 return -EFAULT;
496         }
497         memcpy(mac_buf, pstrHostIfSetMacAddress->u8MacAddress, ETH_ALEN);
498
499         strWID.id = (u16)WID_MAC_ADDR;
500         strWID.type = WID_STR;
501         strWID.val = mac_buf;
502         strWID.size = ETH_ALEN;
503         PRINT_D(GENERIC_DBG, "mac addr = :%pM\n", strWID.val);
504
505         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
506                                    get_id_from_handler(hif_drv));
507         if (s32Error) {
508                 PRINT_ER("Failed to set mac address\n");
509                 s32Error = -EFAULT;
510         }
511
512         kfree(mac_buf);
513         return s32Error;
514 }
515
516 static s32 Handle_GetMacAddress(struct host_if_drv *hif_drv,
517                                 struct get_mac_addr *pstrHostIfGetMacAddress)
518 {
519
520         s32 s32Error = 0;
521         struct wid strWID;
522
523         strWID.id = (u16)WID_MAC_ADDR;
524         strWID.type = WID_STR;
525         strWID.val = pstrHostIfGetMacAddress->u8MacAddress;
526         strWID.size = ETH_ALEN;
527
528         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
529                                    get_id_from_handler(hif_drv));
530         if (s32Error) {
531                 PRINT_ER("Failed to get mac address\n");
532                 s32Error = -EFAULT;
533         }
534         up(&hWaitResponse);
535
536         return s32Error;
537 }
538
539 static s32 Handle_CfgParam(struct host_if_drv *hif_drv,
540                            struct cfg_param_attr *strHostIFCfgParamAttr)
541 {
542         s32 s32Error = 0;
543         struct wid strWIDList[32];
544         u8 u8WidCnt = 0;
545
546         down(&hif_drv->gtOsCfgValuesSem);
547
548
549         PRINT_D(HOSTINF_DBG, "Setting CFG params\n");
550
551         if (strHostIFCfgParamAttr->cfg_attr_info.flag & BSS_TYPE) {
552                 if (strHostIFCfgParamAttr->cfg_attr_info.bss_type < 6) {
553                         strWIDList[u8WidCnt].id = WID_BSS_TYPE;
554                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.bss_type;
555                         strWIDList[u8WidCnt].type = WID_CHAR;
556                         strWIDList[u8WidCnt].size = sizeof(char);
557                         hif_drv->strCfgValues.bss_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.bss_type;
558                 } else {
559                         PRINT_ER("check value 6 over\n");
560                         s32Error = -EINVAL;
561                         goto ERRORHANDLER;
562                 }
563                 u8WidCnt++;
564         }
565         if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTH_TYPE) {
566                 if ((strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 1 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 2 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 5) {
567                         strWIDList[u8WidCnt].id = WID_AUTH_TYPE;
568                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_type;
569                         strWIDList[u8WidCnt].type = WID_CHAR;
570                         strWIDList[u8WidCnt].size = sizeof(char);
571                         hif_drv->strCfgValues.auth_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.auth_type;
572                 } else {
573                         PRINT_ER("Impossible value \n");
574                         s32Error = -EINVAL;
575                         goto ERRORHANDLER;
576                 }
577                 u8WidCnt++;
578         }
579         if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTHEN_TIMEOUT) {
580                 if (strHostIFCfgParamAttr->cfg_attr_info.auth_timeout > 0 && strHostIFCfgParamAttr->cfg_attr_info.auth_timeout < 65536) {
581                         strWIDList[u8WidCnt].id = WID_AUTH_TIMEOUT;
582                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_timeout;
583                         strWIDList[u8WidCnt].type = WID_SHORT;
584                         strWIDList[u8WidCnt].size = sizeof(u16);
585                         hif_drv->strCfgValues.auth_timeout = strHostIFCfgParamAttr->cfg_attr_info.auth_timeout;
586                 } else {
587                         PRINT_ER("Range(1 ~ 65535) over\n");
588                         s32Error = -EINVAL;
589                         goto ERRORHANDLER;
590                 }
591                 u8WidCnt++;
592         }
593         if (strHostIFCfgParamAttr->cfg_attr_info.flag & POWER_MANAGEMENT) {
594                 if (strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode < 5) {
595                         strWIDList[u8WidCnt].id = WID_POWER_MANAGEMENT;
596                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode;
597                         strWIDList[u8WidCnt].type = WID_CHAR;
598                         strWIDList[u8WidCnt].size = sizeof(char);
599                         hif_drv->strCfgValues.power_mgmt_mode = (u8)strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode;
600                 } else {
601                         PRINT_ER("Invalide power mode\n");
602                         s32Error = -EINVAL;
603                         goto ERRORHANDLER;
604                 }
605                 u8WidCnt++;
606         }
607         if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_SHORT) {
608                 if ((strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit < 256))     {
609                         strWIDList[u8WidCnt].id = WID_SHORT_RETRY_LIMIT;
610                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit;
611                         strWIDList[u8WidCnt].type = WID_SHORT;
612                         strWIDList[u8WidCnt].size = sizeof(u16);
613                         hif_drv->strCfgValues.short_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit;
614                 } else {
615                         PRINT_ER("Range(1~256) over\n");
616                         s32Error = -EINVAL;
617                         goto ERRORHANDLER;
618                 }
619                 u8WidCnt++;
620         }
621         if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_LONG) {
622                 if ((strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit < 256)) {
623                         strWIDList[u8WidCnt].id = WID_LONG_RETRY_LIMIT;
624                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit;
625
626                         strWIDList[u8WidCnt].type = WID_SHORT;
627                         strWIDList[u8WidCnt].size = sizeof(u16);
628                         hif_drv->strCfgValues.long_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit;
629                 } else {
630                         PRINT_ER("Range(1~256) over\n");
631                         s32Error = -EINVAL;
632                         goto ERRORHANDLER;
633                 }
634                 u8WidCnt++;
635         }
636         if (strHostIFCfgParamAttr->cfg_attr_info.flag & FRAG_THRESHOLD) {
637
638                 if (strHostIFCfgParamAttr->cfg_attr_info.frag_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.frag_threshold < 7937) {
639                         strWIDList[u8WidCnt].id = WID_FRAG_THRESHOLD;
640                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.frag_threshold;
641                         strWIDList[u8WidCnt].type = WID_SHORT;
642                         strWIDList[u8WidCnt].size = sizeof(u16);
643                         hif_drv->strCfgValues.frag_threshold = strHostIFCfgParamAttr->cfg_attr_info.frag_threshold;
644                 } else {
645                         PRINT_ER("Threshold Range fail\n");
646                         s32Error = -EINVAL;
647                         goto ERRORHANDLER;
648                 }
649                 u8WidCnt++;
650         }
651         if (strHostIFCfgParamAttr->cfg_attr_info.flag & RTS_THRESHOLD) {
652                 if (strHostIFCfgParamAttr->cfg_attr_info.rts_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.rts_threshold < 65536)     {
653                         strWIDList[u8WidCnt].id = WID_RTS_THRESHOLD;
654                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.rts_threshold;
655                         strWIDList[u8WidCnt].type = WID_SHORT;
656                         strWIDList[u8WidCnt].size = sizeof(u16);
657                         hif_drv->strCfgValues.rts_threshold = strHostIFCfgParamAttr->cfg_attr_info.rts_threshold;
658                 } else {
659                         PRINT_ER("Threshold Range fail\n");
660                         s32Error = -EINVAL;
661                         goto ERRORHANDLER;
662                 }
663                 u8WidCnt++;
664         }
665         if (strHostIFCfgParamAttr->cfg_attr_info.flag & PREAMBLE) {
666                 if (strHostIFCfgParamAttr->cfg_attr_info.preamble_type < 3) {
667                         strWIDList[u8WidCnt].id = WID_PREAMBLE;
668                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.preamble_type;
669                         strWIDList[u8WidCnt].type = WID_CHAR;
670                         strWIDList[u8WidCnt].size = sizeof(char);
671                         hif_drv->strCfgValues.preamble_type = strHostIFCfgParamAttr->cfg_attr_info.preamble_type;
672                 } else {
673                         PRINT_ER("Preamle Range(0~2) over\n");
674                         s32Error = -EINVAL;
675                         goto ERRORHANDLER;
676                 }
677                 u8WidCnt++;
678         }
679         if (strHostIFCfgParamAttr->cfg_attr_info.flag & SHORT_SLOT_ALLOWED) {
680                 if (strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed < 2) {
681                         strWIDList[u8WidCnt].id = WID_SHORT_SLOT_ALLOWED;
682                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed;
683                         strWIDList[u8WidCnt].type = WID_CHAR;
684                         strWIDList[u8WidCnt].size = sizeof(char);
685                         hif_drv->strCfgValues.short_slot_allowed = (u8)strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed;
686                 } else {
687                         PRINT_ER("Short slot(2) over\n");
688                         s32Error = -EINVAL;
689                         goto ERRORHANDLER;
690                 }
691                 u8WidCnt++;
692         }
693         if (strHostIFCfgParamAttr->cfg_attr_info.flag & TXOP_PROT_DISABLE) {
694                 if (strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled < 2) {
695                         strWIDList[u8WidCnt].id = WID_11N_TXOP_PROT_DISABLE;
696                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled;
697                         strWIDList[u8WidCnt].type = WID_CHAR;
698                         strWIDList[u8WidCnt].size = sizeof(char);
699                         hif_drv->strCfgValues.txop_prot_disabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled;
700                 } else {
701                         PRINT_ER("TXOP prot disable\n");
702                         s32Error = -EINVAL;
703                         goto ERRORHANDLER;
704                 }
705                 u8WidCnt++;
706         }
707         if (strHostIFCfgParamAttr->cfg_attr_info.flag & BEACON_INTERVAL) {
708                 if (strHostIFCfgParamAttr->cfg_attr_info.beacon_interval > 0 && strHostIFCfgParamAttr->cfg_attr_info.beacon_interval < 65536) {
709                         strWIDList[u8WidCnt].id = WID_BEACON_INTERVAL;
710                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.beacon_interval;
711                         strWIDList[u8WidCnt].type = WID_SHORT;
712                         strWIDList[u8WidCnt].size = sizeof(u16);
713                         hif_drv->strCfgValues.beacon_interval = strHostIFCfgParamAttr->cfg_attr_info.beacon_interval;
714                 } else {
715                         PRINT_ER("Beacon interval(1~65535) fail\n");
716                         s32Error = -EINVAL;
717                         goto ERRORHANDLER;
718                 }
719                 u8WidCnt++;
720         }
721         if (strHostIFCfgParamAttr->cfg_attr_info.flag & DTIM_PERIOD) {
722                 if (strHostIFCfgParamAttr->cfg_attr_info.dtim_period > 0 && strHostIFCfgParamAttr->cfg_attr_info.dtim_period < 256) {
723                         strWIDList[u8WidCnt].id = WID_DTIM_PERIOD;
724                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.dtim_period;
725                         strWIDList[u8WidCnt].type = WID_CHAR;
726                         strWIDList[u8WidCnt].size = sizeof(char);
727                         hif_drv->strCfgValues.dtim_period = strHostIFCfgParamAttr->cfg_attr_info.dtim_period;
728                 } else {
729                         PRINT_ER("DTIM range(1~255) fail\n");
730                         s32Error = -EINVAL;
731                         goto ERRORHANDLER;
732                 }
733                 u8WidCnt++;
734         }
735         if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY) {
736                 if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled < 3) {
737                         strWIDList[u8WidCnt].id = WID_SITE_SURVEY;
738                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled;
739                         strWIDList[u8WidCnt].type = WID_CHAR;
740                         strWIDList[u8WidCnt].size = sizeof(char);
741                         hif_drv->strCfgValues.site_survey_enabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled;
742                 } else {
743                         PRINT_ER("Site survey disable\n");
744                         s32Error = -EINVAL;
745                         goto ERRORHANDLER;
746                 }
747                 u8WidCnt++;
748         }
749         if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY_SCAN_TIME) {
750                 if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time < 65536) {
751                         strWIDList[u8WidCnt].id = WID_SITE_SURVEY_SCAN_TIME;
752                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time;
753                         strWIDList[u8WidCnt].type = WID_SHORT;
754                         strWIDList[u8WidCnt].size = sizeof(u16);
755                         hif_drv->strCfgValues.site_survey_scan_time = strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time;
756                 } else {
757                         PRINT_ER("Site survey scan time(1~65535) over\n");
758                         s32Error = -EINVAL;
759                         goto ERRORHANDLER;
760                 }
761                 u8WidCnt++;
762         }
763         if (strHostIFCfgParamAttr->cfg_attr_info.flag & ACTIVE_SCANTIME) {
764                 if (strHostIFCfgParamAttr->cfg_attr_info.active_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.active_scan_time < 65536) {
765                         strWIDList[u8WidCnt].id = WID_ACTIVE_SCAN_TIME;
766                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.active_scan_time;
767                         strWIDList[u8WidCnt].type = WID_SHORT;
768                         strWIDList[u8WidCnt].size = sizeof(u16);
769                         hif_drv->strCfgValues.active_scan_time = strHostIFCfgParamAttr->cfg_attr_info.active_scan_time;
770                 } else {
771                         PRINT_ER("Active scan time(1~65535) over\n");
772                         s32Error = -EINVAL;
773                         goto ERRORHANDLER;
774                 }
775                 u8WidCnt++;
776         }
777         if (strHostIFCfgParamAttr->cfg_attr_info.flag & PASSIVE_SCANTIME) {
778                 if (strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time < 65536) {
779                         strWIDList[u8WidCnt].id = WID_PASSIVE_SCAN_TIME;
780                         strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time;
781                         strWIDList[u8WidCnt].type = WID_SHORT;
782                         strWIDList[u8WidCnt].size = sizeof(u16);
783                         hif_drv->strCfgValues.passive_scan_time = strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time;
784                 } else {
785                         PRINT_ER("Passive scan time(1~65535) over\n");
786                         s32Error = -EINVAL;
787                         goto ERRORHANDLER;
788                 }
789                 u8WidCnt++;
790         }
791         if (strHostIFCfgParamAttr->cfg_attr_info.flag & CURRENT_TX_RATE) {
792                 enum CURRENT_TXRATE curr_tx_rate = strHostIFCfgParamAttr->cfg_attr_info.curr_tx_rate;
793                 if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1
794                     || curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5
795                     || curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6
796                     || curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12
797                     || curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24
798                     || curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 || curr_tx_rate == MBPS_54) {
799                         strWIDList[u8WidCnt].id = WID_CURRENT_TX_RATE;
800                         strWIDList[u8WidCnt].val = (s8 *)&curr_tx_rate;
801                         strWIDList[u8WidCnt].type = WID_SHORT;
802                         strWIDList[u8WidCnt].size = sizeof(u16);
803                         hif_drv->strCfgValues.curr_tx_rate = (u8)curr_tx_rate;
804                 } else {
805                         PRINT_ER("out of TX rate\n");
806                         s32Error = -EINVAL;
807                         goto ERRORHANDLER;
808                 }
809                 u8WidCnt++;
810         }
811         s32Error = send_config_pkt(SET_CFG, strWIDList, u8WidCnt,
812                                    get_id_from_handler(hif_drv));
813
814         if (s32Error)
815                 PRINT_ER("Error in setting CFG params\n");
816
817 ERRORHANDLER:
818         up(&hif_drv->gtOsCfgValuesSem);
819         return s32Error;
820 }
821
822 static s32 Handle_wait_msg_q_empty(void)
823 {
824         g_wilc_initialized = 0;
825         up(&hWaitResponse);
826         return 0;
827 }
828
829 static s32 Handle_Scan(struct host_if_drv *hif_drv,
830                        struct scan_attr *pstrHostIFscanAttr)
831 {
832         s32 s32Error = 0;
833         struct wid strWIDList[5];
834         u32 u32WidsCount = 0;
835         u32 i;
836         u8 *pu8Buffer;
837         u8 valuesize = 0;
838         u8 *pu8HdnNtwrksWidVal = NULL;
839
840         PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
841         PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", hif_drv->enuHostIFstate);
842
843         hif_drv->strWILC_UsrScanReq.pfUserScanResult = pstrHostIFscanAttr->result;
844         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid = pstrHostIFscanAttr->arg;
845
846         if ((hif_drv->enuHostIFstate >= HOST_IF_SCANNING) && (hif_drv->enuHostIFstate < HOST_IF_CONNECTED)) {
847                 PRINT_D(GENERIC_DBG, "Don't scan we are already in [%d] state\n", hif_drv->enuHostIFstate);
848                 PRINT_ER("Already scan\n");
849                 s32Error = -EBUSY;
850                 goto ERRORHANDLER;
851         }
852
853         if (g_obtainingIP || connecting) {
854                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
855                 PRINT_ER("Don't do obss scan\n");
856                 s32Error = -EBUSY;
857                 goto ERRORHANDLER;
858         }
859
860         PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
861
862
863         hif_drv->strWILC_UsrScanReq.u32RcvdChCount = 0;
864
865         strWIDList[u32WidsCount].id = (u16)WID_SSID_PROBE_REQ;
866         strWIDList[u32WidsCount].type = WID_STR;
867
868         for (i = 0; i < pstrHostIFscanAttr->hidden_network.u8ssidnum; i++)
869                 valuesize += ((pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen) + 1);
870         pu8HdnNtwrksWidVal = kmalloc(valuesize + 1, GFP_KERNEL);
871         strWIDList[u32WidsCount].val = pu8HdnNtwrksWidVal;
872         if (strWIDList[u32WidsCount].val != NULL) {
873                 pu8Buffer = strWIDList[u32WidsCount].val;
874
875                 *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.u8ssidnum;
876
877                 PRINT_D(HOSTINF_DBG, "In Handle_ProbeRequest number of ssid %d\n", pstrHostIFscanAttr->hidden_network.u8ssidnum);
878
879                 for (i = 0; i < pstrHostIFscanAttr->hidden_network.u8ssidnum; i++) {
880                         *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen;
881                         memcpy(pu8Buffer, pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen);
882                         pu8Buffer += pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen;
883                 }
884
885
886
887                 strWIDList[u32WidsCount].size = (s32)(valuesize + 1);
888                 u32WidsCount++;
889         }
890
891         {
892                 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_PROBE;
893                 strWIDList[u32WidsCount].type = WID_BIN_DATA;
894                 strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ies;
895                 strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ies_len;
896                 u32WidsCount++;
897         }
898
899         strWIDList[u32WidsCount].id = WID_SCAN_TYPE;
900         strWIDList[u32WidsCount].type = WID_CHAR;
901         strWIDList[u32WidsCount].size = sizeof(char);
902         strWIDList[u32WidsCount].val = (s8 *)(&(pstrHostIFscanAttr->type));
903         u32WidsCount++;
904
905         strWIDList[u32WidsCount].id = WID_SCAN_CHANNEL_LIST;
906         strWIDList[u32WidsCount].type = WID_BIN_DATA;
907
908         if (pstrHostIFscanAttr->ch_freq_list != NULL && pstrHostIFscanAttr->ch_list_len > 0) {
909                 int i;
910
911                 for (i = 0; i < pstrHostIFscanAttr->ch_list_len; i++)   {
912                         if (pstrHostIFscanAttr->ch_freq_list[i] > 0)
913                                 pstrHostIFscanAttr->ch_freq_list[i] = pstrHostIFscanAttr->ch_freq_list[i] - 1;
914                 }
915         }
916
917         strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ch_freq_list;
918         strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ch_list_len;
919         u32WidsCount++;
920
921         strWIDList[u32WidsCount].id = WID_START_SCAN_REQ;
922         strWIDList[u32WidsCount].type = WID_CHAR;
923         strWIDList[u32WidsCount].size = sizeof(char);
924         strWIDList[u32WidsCount].val = (s8 *)(&(pstrHostIFscanAttr->src));
925         u32WidsCount++;
926
927         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
928                 gbScanWhileConnected = true;
929         else if (hif_drv->enuHostIFstate == HOST_IF_IDLE)
930                 gbScanWhileConnected = false;
931
932         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
933                                    get_id_from_handler(hif_drv));
934
935         if (s32Error)
936                 PRINT_ER("Failed to send scan paramters config packet\n");
937         else
938                 PRINT_D(HOSTINF_DBG, "Successfully sent SCAN params config packet\n");
939
940 ERRORHANDLER:
941         if (s32Error) {
942                 del_timer(&hif_drv->hScanTimer);
943                 Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
944         }
945
946         if (pstrHostIFscanAttr->ch_freq_list != NULL) {
947                 kfree(pstrHostIFscanAttr->ch_freq_list);
948                 pstrHostIFscanAttr->ch_freq_list = NULL;
949         }
950
951         if (pstrHostIFscanAttr->ies != NULL) {
952                 kfree(pstrHostIFscanAttr->ies);
953                 pstrHostIFscanAttr->ies = NULL;
954         }
955         if (pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo != NULL)   {
956                 kfree(pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo);
957                 pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo = NULL;
958         }
959
960         if (pu8HdnNtwrksWidVal != NULL)
961                 kfree(pu8HdnNtwrksWidVal);
962
963         return s32Error;
964 }
965
966 static s32 Handle_ScanDone(struct host_if_drv *hif_drv,
967                            enum scan_event enuEvent)
968 {
969         s32 s32Error = 0;
970         u8 u8abort_running_scan;
971         struct wid strWID;
972
973
974         PRINT_D(HOSTINF_DBG, "in Handle_ScanDone()\n");
975
976         if (enuEvent == SCAN_EVENT_ABORTED) {
977                 PRINT_D(GENERIC_DBG, "Abort running scan\n");
978                 u8abort_running_scan = 1;
979                 strWID.id = (u16)WID_ABORT_RUNNING_SCAN;
980                 strWID.type = WID_CHAR;
981                 strWID.val = (s8 *)&u8abort_running_scan;
982                 strWID.size = sizeof(char);
983
984                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
985                                            get_id_from_handler(hif_drv));
986                 if (s32Error) {
987                         PRINT_ER("Failed to set abort running scan\n");
988                         s32Error = -EFAULT;
989                 }
990         }
991
992         if (!hif_drv) {
993                 PRINT_ER("Driver handler is NULL\n");
994                 return s32Error;
995         }
996
997         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
998                 hif_drv->strWILC_UsrScanReq.pfUserScanResult(enuEvent, NULL,
999                                                                 hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
1000                 hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
1001         }
1002
1003         return s32Error;
1004 }
1005
1006 u8 u8ConnectedSSID[6] = {0};
1007 static s32 Handle_Connect(struct host_if_drv *hif_drv,
1008                           struct connect_attr *pstrHostIFconnectAttr)
1009 {
1010         s32 s32Error = 0;
1011         struct wid strWIDList[8];
1012         u32 u32WidsCount = 0, dummyval = 0;
1013         u8 *pu8CurrByte = NULL;
1014         struct join_bss_param *ptstrJoinBssParam;
1015
1016         PRINT_D(GENERIC_DBG, "Handling connect request\n");
1017
1018         if (memcmp(pstrHostIFconnectAttr->pu8bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
1019
1020                 s32Error = 0;
1021                 PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n");
1022                 return s32Error;
1023         }
1024
1025         PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
1026
1027         ptstrJoinBssParam = (struct join_bss_param *)pstrHostIFconnectAttr->pJoinParams;
1028         if (ptstrJoinBssParam == NULL) {
1029                 PRINT_ER("Required BSSID not found\n");
1030                 s32Error = -ENOENT;
1031                 goto ERRORHANDLER;
1032         }
1033
1034         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1035                 hif_drv->strWILC_UsrConnReq.pu8bssid = kmalloc(6, GFP_KERNEL);
1036                 memcpy(hif_drv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1037         }
1038
1039         hif_drv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
1040         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1041                 hif_drv->strWILC_UsrConnReq.pu8ssid = kmalloc(pstrHostIFconnectAttr->ssidLen + 1, GFP_KERNEL);
1042                 memcpy(hif_drv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
1043                             pstrHostIFconnectAttr->ssidLen);
1044                 hif_drv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
1045         }
1046
1047         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1048         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1049                 hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs = kmalloc(pstrHostIFconnectAttr->IEsLen, GFP_KERNEL);
1050                 memcpy(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
1051                             pstrHostIFconnectAttr->IEsLen);
1052         }
1053
1054         hif_drv->strWILC_UsrConnReq.u8security = pstrHostIFconnectAttr->u8security;
1055         hif_drv->strWILC_UsrConnReq.tenuAuth_type = pstrHostIFconnectAttr->tenuAuth_type;
1056         hif_drv->strWILC_UsrConnReq.pfUserConnectResult = pstrHostIFconnectAttr->pfConnectResult;
1057         hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid = pstrHostIFconnectAttr->pvUserArg;
1058
1059         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
1060         strWIDList[u32WidsCount].type = WID_INT;
1061         strWIDList[u32WidsCount].size = sizeof(u32);
1062         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
1063         u32WidsCount++;
1064
1065         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
1066         strWIDList[u32WidsCount].type = WID_INT;
1067         strWIDList[u32WidsCount].size = sizeof(u32);
1068         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
1069         u32WidsCount++;
1070
1071         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
1072         strWIDList[u32WidsCount].type = WID_INT;
1073         strWIDList[u32WidsCount].size = sizeof(u32);
1074         strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
1075         u32WidsCount++;
1076
1077         {
1078                 strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
1079                 strWIDList[u32WidsCount].type = WID_BIN_DATA;
1080                 strWIDList[u32WidsCount].val = hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs;
1081                 strWIDList[u32WidsCount].size = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1082                 u32WidsCount++;
1083
1084                 if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1085
1086                         gu32FlushedInfoElemAsocSize = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1087                         gu8FlushedInfoElemAsoc =  kmalloc(gu32FlushedInfoElemAsocSize, GFP_KERNEL);
1088                         memcpy(gu8FlushedInfoElemAsoc, hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1089                                gu32FlushedInfoElemAsocSize);
1090                 }
1091         }
1092         strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
1093         strWIDList[u32WidsCount].type = WID_CHAR;
1094         strWIDList[u32WidsCount].size = sizeof(char);
1095         strWIDList[u32WidsCount].val = (s8 *)(&(hif_drv->strWILC_UsrConnReq.u8security));
1096         u32WidsCount++;
1097
1098         if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
1099                 gu8Flushed11iMode = hif_drv->strWILC_UsrConnReq.u8security;
1100
1101         PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", hif_drv->strWILC_UsrConnReq.u8security);
1102
1103
1104         strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
1105         strWIDList[u32WidsCount].type = WID_CHAR;
1106         strWIDList[u32WidsCount].size = sizeof(char);
1107         strWIDList[u32WidsCount].val = (s8 *)(&hif_drv->strWILC_UsrConnReq.tenuAuth_type);
1108         u32WidsCount++;
1109
1110         if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
1111                 gu8FlushedAuthType = (u8)hif_drv->strWILC_UsrConnReq.tenuAuth_type;
1112
1113         PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", hif_drv->strWILC_UsrConnReq.tenuAuth_type);
1114         PRINT_D(HOSTINF_DBG, "Connecting to network of SSID %s on channel %d\n",
1115                 hif_drv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->u8channel);
1116
1117         strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
1118         strWIDList[u32WidsCount].type = WID_STR;
1119         strWIDList[u32WidsCount].size = 112;
1120         strWIDList[u32WidsCount].val = kmalloc(strWIDList[u32WidsCount].size, GFP_KERNEL);
1121
1122         if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1123                 gu32FlushedJoinReqSize = strWIDList[u32WidsCount].size;
1124                 gu8FlushedJoinReq = kmalloc(gu32FlushedJoinReqSize, GFP_KERNEL);
1125         }
1126         if (strWIDList[u32WidsCount].val == NULL) {
1127                 s32Error = -EFAULT;
1128                 goto ERRORHANDLER;
1129         }
1130
1131         pu8CurrByte = strWIDList[u32WidsCount].val;
1132
1133
1134         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1135                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
1136                 pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
1137         }
1138         pu8CurrByte += MAX_SSID_LEN;
1139         *(pu8CurrByte++) = INFRASTRUCTURE;
1140
1141         if ((pstrHostIFconnectAttr->u8channel >= 1) && (pstrHostIFconnectAttr->u8channel <= 14)) {
1142                 *(pu8CurrByte++) = pstrHostIFconnectAttr->u8channel;
1143         } else {
1144                 PRINT_ER("Channel out of range\n");
1145                 *(pu8CurrByte++) = 0xFF;
1146         }
1147         *(pu8CurrByte++)  = (ptstrJoinBssParam->cap_info) & 0xFF;
1148         *(pu8CurrByte++)  = ((ptstrJoinBssParam->cap_info) >> 8) & 0xFF;
1149         PRINT_D(HOSTINF_DBG, "* Cap Info %0x*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1150
1151         if (pstrHostIFconnectAttr->pu8bssid != NULL)
1152                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1153         pu8CurrByte += 6;
1154
1155         if (pstrHostIFconnectAttr->pu8bssid != NULL)
1156                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
1157         pu8CurrByte += 6;
1158
1159         *(pu8CurrByte++)  = (ptstrJoinBssParam->beacon_period) & 0xFF;
1160         *(pu8CurrByte++)  = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
1161         PRINT_D(HOSTINF_DBG, "* Beacon Period %d*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1162         *(pu8CurrByte++)  =  ptstrJoinBssParam->dtim_period;
1163         PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1)));
1164
1165         memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1166         pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1167
1168         *(pu8CurrByte++)  =  ptstrJoinBssParam->wmm_cap;
1169         PRINT_D(HOSTINF_DBG, "* wmm cap%d*\n", (*(pu8CurrByte - 1)));
1170         *(pu8CurrByte++)  = ptstrJoinBssParam->uapsd_cap;
1171
1172         *(pu8CurrByte++)  = ptstrJoinBssParam->ht_capable;
1173         hif_drv->strWILC_UsrConnReq.IsHTCapable = ptstrJoinBssParam->ht_capable;
1174
1175         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_found;
1176         PRINT_D(HOSTINF_DBG, "* rsn found %d*\n", *(pu8CurrByte - 1));
1177         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_grp_policy;
1178         PRINT_D(HOSTINF_DBG, "* rsn group policy %0x*\n", (*(pu8CurrByte - 1)));
1179         *(pu8CurrByte++) =  ptstrJoinBssParam->mode_802_11i;
1180         PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1)));
1181
1182         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1183         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1184
1185         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1186         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1187
1188         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1189         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1190
1191         *(pu8CurrByte++) = REAL_JOIN_REQ;
1192
1193         *(pu8CurrByte++) = ptstrJoinBssParam->u8NoaEnbaled;
1194         if (ptstrJoinBssParam->u8NoaEnbaled) {
1195                 PRINT_D(HOSTINF_DBG, "NOA present\n");
1196
1197                 *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
1198                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 8) & 0xFF;
1199                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
1200                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
1201
1202                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Index;
1203
1204                 *(pu8CurrByte++) = ptstrJoinBssParam->u8OppEnable;
1205
1206                 if (ptstrJoinBssParam->u8OppEnable)
1207                         *(pu8CurrByte++) = ptstrJoinBssParam->u8CtWindow;
1208
1209                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Count;
1210
1211                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration));
1212
1213                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration);
1214
1215                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval));
1216
1217                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval);
1218
1219                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime));
1220
1221                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime);
1222
1223         } else
1224                 PRINT_D(HOSTINF_DBG, "NOA not present\n");
1225
1226         pu8CurrByte = strWIDList[u32WidsCount].val;
1227         u32WidsCount++;
1228         gu32WidConnRstHack = 0;
1229
1230         if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1231                 memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize);
1232                 gu8FlushedJoinReqDrvHandler = hif_drv;
1233         }
1234
1235         PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
1236
1237         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1238                 memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->pu8bssid, ETH_ALEN);
1239
1240                 PRINT_D(GENERIC_DBG, "save Bssid = %pM\n", pstrHostIFconnectAttr->pu8bssid);
1241                 PRINT_D(GENERIC_DBG, "save bssid = %pM\n", u8ConnectedSSID);
1242         }
1243
1244         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
1245                                    get_id_from_handler(hif_drv));
1246         if (s32Error) {
1247                 PRINT_ER("failed to send config packet\n");
1248                 s32Error = -EFAULT;
1249                 goto ERRORHANDLER;
1250         } else {
1251                 PRINT_D(GENERIC_DBG, "set HOST_IF_WAITING_CONN_RESP\n");
1252                 hif_drv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
1253         }
1254
1255 ERRORHANDLER:
1256         if (s32Error) {
1257                 tstrConnectInfo strConnectInfo;
1258
1259                 del_timer(&hif_drv->hConnectTimer);
1260
1261                 PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n");
1262
1263                 memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1264
1265                 if (pstrHostIFconnectAttr->pfConnectResult != NULL) {
1266                         if (pstrHostIFconnectAttr->pu8bssid != NULL)
1267                                 memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
1268
1269                         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1270                                 strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1271                                 strConnectInfo.pu8ReqIEs = kmalloc(pstrHostIFconnectAttr->IEsLen, GFP_KERNEL);
1272                                 memcpy(strConnectInfo.pu8ReqIEs,
1273                                             pstrHostIFconnectAttr->pu8IEs,
1274                                             pstrHostIFconnectAttr->IEsLen);
1275                         }
1276
1277                         pstrHostIFconnectAttr->pfConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1278                                                                &strConnectInfo,
1279                                                                MAC_DISCONNECTED,
1280                                                                NULL,
1281                                                                pstrHostIFconnectAttr->pvUserArg);
1282                         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1283                         if (strConnectInfo.pu8ReqIEs != NULL) {
1284                                 kfree(strConnectInfo.pu8ReqIEs);
1285                                 strConnectInfo.pu8ReqIEs = NULL;
1286                         }
1287
1288                 } else {
1289                         PRINT_ER("Connect callback function pointer is NULL\n");
1290                 }
1291         }
1292
1293         PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n");
1294         if (pstrHostIFconnectAttr->pu8bssid != NULL) {
1295                 kfree(pstrHostIFconnectAttr->pu8bssid);
1296                 pstrHostIFconnectAttr->pu8bssid = NULL;
1297         }
1298
1299         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1300                 kfree(pstrHostIFconnectAttr->pu8ssid);
1301                 pstrHostIFconnectAttr->pu8ssid = NULL;
1302         }
1303
1304         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1305                 kfree(pstrHostIFconnectAttr->pu8IEs);
1306                 pstrHostIFconnectAttr->pu8IEs = NULL;
1307         }
1308
1309         if (pu8CurrByte != NULL)
1310                 kfree(pu8CurrByte);
1311         return s32Error;
1312 }
1313
1314 static s32 Handle_FlushConnect(struct host_if_drv *hif_drv)
1315 {
1316         s32 s32Error = 0;
1317         struct wid strWIDList[5];
1318         u32 u32WidsCount = 0;
1319         u8 *pu8CurrByte = NULL;
1320
1321         strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
1322         strWIDList[u32WidsCount].type = WID_BIN_DATA;
1323         strWIDList[u32WidsCount].val = gu8FlushedInfoElemAsoc;
1324         strWIDList[u32WidsCount].size = gu32FlushedInfoElemAsocSize;
1325         u32WidsCount++;
1326
1327         strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
1328         strWIDList[u32WidsCount].type = WID_CHAR;
1329         strWIDList[u32WidsCount].size = sizeof(char);
1330         strWIDList[u32WidsCount].val = (s8 *)(&(gu8Flushed11iMode));
1331         u32WidsCount++;
1332
1333
1334
1335         strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
1336         strWIDList[u32WidsCount].type = WID_CHAR;
1337         strWIDList[u32WidsCount].size = sizeof(char);
1338         strWIDList[u32WidsCount].val = (s8 *)(&gu8FlushedAuthType);
1339         u32WidsCount++;
1340
1341         strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
1342         strWIDList[u32WidsCount].type = WID_STR;
1343         strWIDList[u32WidsCount].size = gu32FlushedJoinReqSize;
1344         strWIDList[u32WidsCount].val = (s8 *)gu8FlushedJoinReq;
1345         pu8CurrByte = strWIDList[u32WidsCount].val;
1346
1347         pu8CurrByte += FLUSHED_BYTE_POS;
1348         *(pu8CurrByte) = FLUSHED_JOIN_REQ;
1349
1350         u32WidsCount++;
1351
1352         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
1353                                    get_id_from_handler(gu8FlushedJoinReqDrvHandler));
1354         if (s32Error) {
1355                 PRINT_ER("failed to send config packet\n");
1356                 s32Error = -EINVAL;
1357         }
1358
1359         return s32Error;
1360 }
1361
1362 static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv)
1363 {
1364         s32 s32Error = 0;
1365         tstrConnectInfo strConnectInfo;
1366         struct wid strWID;
1367         u16 u16DummyReasonCode = 0;
1368
1369         if (!hif_drv) {
1370                 PRINT_ER("Driver handler is NULL\n");
1371                 return s32Error;
1372         }
1373
1374         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1375
1376         gbScanWhileConnected = false;
1377
1378
1379         memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1380
1381         if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
1382                 if (hif_drv->strWILC_UsrConnReq.pu8bssid != NULL) {
1383                         memcpy(strConnectInfo.au8bssid,
1384                                     hif_drv->strWILC_UsrConnReq.pu8bssid, 6);
1385                 }
1386
1387                 if (hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
1388                         strConnectInfo.ReqIEsLen = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1389                         strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->strWILC_UsrConnReq.ConnReqIEsLen, GFP_KERNEL);
1390                         memcpy(strConnectInfo.pu8ReqIEs,
1391                                     hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1392                                     hif_drv->strWILC_UsrConnReq.ConnReqIEsLen);
1393                 }
1394
1395                 hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1396                                                                    &strConnectInfo,
1397                                                                    MAC_DISCONNECTED,
1398                                                                    NULL,
1399                                                                    hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1400
1401                 if (strConnectInfo.pu8ReqIEs != NULL) {
1402                         kfree(strConnectInfo.pu8ReqIEs);
1403                         strConnectInfo.pu8ReqIEs = NULL;
1404                 }
1405         } else {
1406                 PRINT_ER("Connect callback function pointer is NULL\n");
1407         }
1408
1409         strWID.id = (u16)WID_DISCONNECT;
1410         strWID.type = WID_CHAR;
1411         strWID.val = (s8 *)&u16DummyReasonCode;
1412         strWID.size = sizeof(char);
1413
1414         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
1415
1416         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1417                                    get_id_from_handler(hif_drv));
1418         if (s32Error)
1419                 PRINT_ER("Failed to send dissconect config packet\n");
1420
1421         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1422         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1423         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1424         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1425         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1426
1427         eth_zero_addr(u8ConnectedSSID);
1428
1429         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1430                 kfree(gu8FlushedJoinReq);
1431                 gu8FlushedJoinReq = NULL;
1432         }
1433         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1434                 kfree(gu8FlushedInfoElemAsoc);
1435                 gu8FlushedInfoElemAsoc = NULL;
1436         }
1437
1438         return s32Error;
1439 }
1440
1441 static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv,
1442                                 struct rcvd_net_info *pstrRcvdNetworkInfo)
1443 {
1444         u32 i;
1445         bool bNewNtwrkFound;
1446
1447
1448
1449         s32 s32Error = 0;
1450         tstrNetworkInfo *pstrNetworkInfo = NULL;
1451         void *pJoinParams = NULL;
1452
1453         bNewNtwrkFound = true;
1454         PRINT_INFO(HOSTINF_DBG, "Handling received network info\n");
1455
1456         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1457                 PRINT_D(HOSTINF_DBG, "State: Scanning, parsing network information received\n");
1458                 parse_network_info(pstrRcvdNetworkInfo->pu8Buffer, &pstrNetworkInfo);
1459                 if ((pstrNetworkInfo == NULL)
1460                     || (hif_drv->strWILC_UsrScanReq.pfUserScanResult == NULL)) {
1461                         PRINT_ER("driver is null\n");
1462                         s32Error = -EINVAL;
1463                         goto done;
1464                 }
1465
1466                 for (i = 0; i < hif_drv->strWILC_UsrScanReq.u32RcvdChCount; i++) {
1467
1468                         if ((hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) &&
1469                             (pstrNetworkInfo->au8bssid != NULL)) {
1470                                 if (memcmp(hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid,
1471                                                 pstrNetworkInfo->au8bssid, 6) == 0) {
1472                                         if (pstrNetworkInfo->s8rssi <= hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) {
1473                                                 PRINT_D(HOSTINF_DBG, "Network previously discovered\n");
1474                                                 goto done;
1475                                         } else {
1476                                                 hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi;
1477                                                 bNewNtwrkFound = false;
1478                                                 break;
1479                                         }
1480                                 }
1481                         }
1482                 }
1483
1484                 if (bNewNtwrkFound == true) {
1485                         PRINT_D(HOSTINF_DBG, "New network found\n");
1486
1487                         if (hif_drv->strWILC_UsrScanReq.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) {
1488                                 hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi;
1489
1490                                 if ((hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL)
1491                                     && (pstrNetworkInfo->au8bssid != NULL)) {
1492                                         memcpy(hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid,
1493                                                     pstrNetworkInfo->au8bssid, 6);
1494
1495                                         hif_drv->strWILC_UsrScanReq.u32RcvdChCount++;
1496
1497                                         pstrNetworkInfo->bNewNetwork = true;
1498                                         pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
1499
1500                                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1501                                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid,
1502                                                                                         pJoinParams);
1503
1504
1505                                 }
1506                         } else {
1507                                 PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit\n");
1508                         }
1509                 } else {
1510                         pstrNetworkInfo->bNewNetwork = false;
1511                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1512                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
1513                 }
1514         }
1515
1516 done:
1517         if (pstrRcvdNetworkInfo->pu8Buffer != NULL) {
1518                 kfree(pstrRcvdNetworkInfo->pu8Buffer);
1519                 pstrRcvdNetworkInfo->pu8Buffer = NULL;
1520         }
1521
1522         if (pstrNetworkInfo != NULL) {
1523                 DeallocateNetworkInfo(pstrNetworkInfo);
1524                 pstrNetworkInfo = NULL;
1525         }
1526
1527         return s32Error;
1528 }
1529
1530 static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv,
1531                                     struct rcvd_async_info *pstrRcvdGnrlAsyncInfo)
1532 {
1533         s32 s32Error = 0;
1534         u8 u8MsgType = 0;
1535         u8 u8MsgID = 0;
1536         u16 u16MsgLen = 0;
1537         u16 u16WidID = (u16)WID_NIL;
1538         u8 u8WidLen  = 0;
1539         u8 u8MacStatus;
1540         u8 u8MacStatusReasonCode;
1541         u8 u8MacStatusAdditionalInfo;
1542         tstrConnectInfo strConnectInfo;
1543         tstrDisconnectNotifInfo strDisconnectNotifInfo;
1544         s32 s32Err = 0;
1545
1546         if (!hif_drv) {
1547                 PRINT_ER("Driver handler is NULL\n");
1548                 return -ENODEV;
1549         }
1550         PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", hif_drv->enuHostIFstate,
1551                 pstrRcvdGnrlAsyncInfo->pu8Buffer[7]);
1552
1553         if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) ||
1554             (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) ||
1555             hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1556                 if ((pstrRcvdGnrlAsyncInfo->pu8Buffer == NULL) ||
1557                     (hif_drv->strWILC_UsrConnReq.pfUserConnectResult == NULL)) {
1558                         PRINT_ER("driver is null\n");
1559                         return -EINVAL;
1560                 }
1561
1562                 u8MsgType = pstrRcvdGnrlAsyncInfo->pu8Buffer[0];
1563
1564                 if ('I' != u8MsgType) {
1565                         PRINT_ER("Received Message format incorrect.\n");
1566                         return -EFAULT;
1567                 }
1568
1569                 u8MsgID = pstrRcvdGnrlAsyncInfo->pu8Buffer[1];
1570                 u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[2], pstrRcvdGnrlAsyncInfo->pu8Buffer[3]);
1571                 u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[4], pstrRcvdGnrlAsyncInfo->pu8Buffer[5]);
1572                 u8WidLen = pstrRcvdGnrlAsyncInfo->pu8Buffer[6];
1573                 u8MacStatus  = pstrRcvdGnrlAsyncInfo->pu8Buffer[7];
1574                 u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->pu8Buffer[8];
1575                 u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->pu8Buffer[9];
1576                 PRINT_INFO(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Info = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
1577                 if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
1578                         u32 u32RcvdAssocRespInfoLen;
1579                         tstrConnectRespInfo *pstrConnectRespInfo = NULL;
1580
1581                         PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
1582
1583                         memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1584
1585                         if (u8MacStatus == MAC_CONNECTED) {
1586                                 memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1587
1588                                 host_int_get_assoc_res_info(hif_drv,
1589                                                             gapu8RcvdAssocResp,
1590                                                             MAX_ASSOC_RESP_FRAME_SIZE,
1591                                                             &u32RcvdAssocRespInfoLen);
1592
1593                                 PRINT_INFO(HOSTINF_DBG, "Received association response with length = %d\n", u32RcvdAssocRespInfoLen);
1594
1595                                 if (u32RcvdAssocRespInfoLen != 0) {
1596
1597                                         PRINT_D(HOSTINF_DBG, "Parsing association response\n");
1598                                         s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen,
1599                                                                     &pstrConnectRespInfo);
1600                                         if (s32Err) {
1601                                                 PRINT_ER("ParseAssocRespInfo() returned error %d\n", s32Err);
1602                                         } else {
1603                                                 strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus;
1604
1605                                                 if (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
1606                                                         PRINT_INFO(HOSTINF_DBG, "Association response received : Successful connection status\n");
1607                                                         if (pstrConnectRespInfo->pu8RespIEs != NULL) {
1608                                                                 strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen;
1609
1610
1611                                                                 strConnectInfo.pu8RespIEs = kmalloc(pstrConnectRespInfo->u16RespIEsLen, GFP_KERNEL);
1612                                                                 memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs,
1613                                                                             pstrConnectRespInfo->u16RespIEsLen);
1614                                                         }
1615                                                 }
1616
1617                                                 if (pstrConnectRespInfo != NULL) {
1618                                                         DeallocateAssocRespInfo(pstrConnectRespInfo);
1619                                                         pstrConnectRespInfo = NULL;
1620                                                 }
1621                                         }
1622                                 }
1623                         }
1624
1625                         if ((u8MacStatus == MAC_CONNECTED) &&
1626                             (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) {
1627                                 PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
1628                                 eth_zero_addr(u8ConnectedSSID);
1629
1630                         } else if (u8MacStatus == MAC_DISCONNECTED)    {
1631                                 PRINT_ER("Received MAC status is MAC_DISCONNECTED\n");
1632                                 eth_zero_addr(u8ConnectedSSID);
1633                         }
1634
1635                         if (hif_drv->strWILC_UsrConnReq.pu8bssid != NULL) {
1636                                 PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n");
1637                                 memcpy(strConnectInfo.au8bssid, hif_drv->strWILC_UsrConnReq.pu8bssid, 6);
1638
1639                                 if ((u8MacStatus == MAC_CONNECTED) &&
1640                                     (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
1641                                         memcpy(hif_drv->au8AssociatedBSSID,
1642                                                     hif_drv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN);
1643                                 }
1644                         }
1645
1646
1647                         if (hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
1648                                 strConnectInfo.ReqIEsLen = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1649                                 strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->strWILC_UsrConnReq.ConnReqIEsLen, GFP_KERNEL);
1650                                 memcpy(strConnectInfo.pu8ReqIEs,
1651                                             hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1652                                             hif_drv->strWILC_UsrConnReq.ConnReqIEsLen);
1653                         }
1654
1655
1656                         del_timer(&hif_drv->hConnectTimer);
1657                         hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1658                                                                            &strConnectInfo,
1659                                                                            u8MacStatus,
1660                                                                            NULL,
1661                                                                            hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1662
1663                         if ((u8MacStatus == MAC_CONNECTED) &&
1664                             (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
1665                                 host_int_set_power_mgmt(hif_drv, 0, 0);
1666
1667                                 PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n");
1668                                 hif_drv->enuHostIFstate = HOST_IF_CONNECTED;
1669
1670                                 PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n");
1671                                 g_obtainingIP = true;
1672                                 mod_timer(&hDuringIpTimer,
1673                                           jiffies + msecs_to_jiffies(10000));
1674                         } else {
1675                                 PRINT_D(HOSTINF_DBG, "MAC status : %d and Connect Status : %d\n", u8MacStatus, strConnectInfo.u16ConnectStatus);
1676                                 hif_drv->enuHostIFstate = HOST_IF_IDLE;
1677                                 gbScanWhileConnected = false;
1678                         }
1679
1680                         if (strConnectInfo.pu8RespIEs != NULL) {
1681                                 kfree(strConnectInfo.pu8RespIEs);
1682                                 strConnectInfo.pu8RespIEs = NULL;
1683                         }
1684
1685                         if (strConnectInfo.pu8ReqIEs != NULL) {
1686                                 kfree(strConnectInfo.pu8ReqIEs);
1687                                 strConnectInfo.pu8ReqIEs = NULL;
1688                         }
1689                         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1690                         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1691                         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1692                         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1693                         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1694                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1695                            (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)) {
1696                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n");
1697
1698                         memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
1699
1700                         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1701                                 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >>\n\n");
1702                                 del_timer(&hif_drv->hScanTimer);
1703                                 Handle_ScanDone((void *)hif_drv, SCAN_EVENT_ABORTED);
1704                         }
1705
1706                         strDisconnectNotifInfo.u16reason = 0;
1707                         strDisconnectNotifInfo.ie = NULL;
1708                         strDisconnectNotifInfo.ie_len = 0;
1709
1710                         if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
1711                                 g_obtainingIP = false;
1712                                 host_int_set_power_mgmt(hif_drv, 0, 0);
1713
1714                                 hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1715                                                                                    NULL,
1716                                                                                    0,
1717                                                                                    &strDisconnectNotifInfo,
1718                                                                                    hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1719
1720                         } else {
1721                                 PRINT_ER("Connect result callback function is NULL\n");
1722                         }
1723
1724                         eth_zero_addr(hif_drv->au8AssociatedBSSID);
1725
1726                         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1727                         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1728                         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1729                         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1730                         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1731
1732                         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1733                                 kfree(gu8FlushedJoinReq);
1734                                 gu8FlushedJoinReq = NULL;
1735                         }
1736                         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1737                                 kfree(gu8FlushedInfoElemAsoc);
1738                                 gu8FlushedInfoElemAsoc = NULL;
1739                         }
1740
1741                         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1742                         gbScanWhileConnected = false;
1743
1744                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1745                            (hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL)) {
1746                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n");
1747                         PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >>\n\n");
1748
1749                         del_timer(&hif_drv->hScanTimer);
1750                         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult)
1751                                 Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
1752
1753                 }
1754
1755         }
1756
1757         if (pstrRcvdGnrlAsyncInfo->pu8Buffer != NULL) {
1758                 kfree(pstrRcvdGnrlAsyncInfo->pu8Buffer);
1759                 pstrRcvdGnrlAsyncInfo->pu8Buffer = NULL;
1760         }
1761
1762         return s32Error;
1763 }
1764
1765 static int Handle_Key(struct host_if_drv *hif_drv,
1766                       struct key_attr *pstrHostIFkeyAttr)
1767 {
1768         s32 s32Error = 0;
1769         struct wid strWID;
1770         struct wid strWIDList[5];
1771         u8 i;
1772         u8 *pu8keybuf;
1773         s8 s8idxarray[1];
1774         s8 ret = 0;
1775
1776         switch (pstrHostIFkeyAttr->type) {
1777
1778
1779         case WEP:
1780
1781                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1782
1783                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
1784                         PRINT_D(GENERIC_DBG, "ID Hostint is %d\n", (pstrHostIFkeyAttr->attr.wep.index));
1785                         strWIDList[0].id = (u16)WID_11I_MODE;
1786                         strWIDList[0].type = WID_CHAR;
1787                         strWIDList[0].size = sizeof(char);
1788                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.mode));
1789
1790                         strWIDList[1].id = WID_AUTH_TYPE;
1791                         strWIDList[1].type = WID_CHAR;
1792                         strWIDList[1].size = sizeof(char);
1793                         strWIDList[1].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.auth_type));
1794
1795                         strWIDList[2].id = (u16)WID_KEY_ID;
1796                         strWIDList[2].type = WID_CHAR;
1797
1798                         strWIDList[2].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
1799                         strWIDList[2].size = sizeof(char);
1800
1801                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len, GFP_KERNEL);
1802
1803                         if (pu8keybuf == NULL) {
1804                                 PRINT_ER("No buffer to send Key\n");
1805                                 return -1;
1806                         }
1807
1808                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wep.key,
1809                                     pstrHostIFkeyAttr->attr.wep.key_len);
1810
1811                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1812
1813                         strWIDList[3].id = (u16)WID_WEP_KEY_VALUE;
1814                         strWIDList[3].type = WID_STR;
1815                         strWIDList[3].size = pstrHostIFkeyAttr->attr.wep.key_len;
1816                         strWIDList[3].val = (s8 *)pu8keybuf;
1817
1818
1819                         s32Error = send_config_pkt(SET_CFG, strWIDList, 4,
1820                                                    get_id_from_handler(hif_drv));
1821                         kfree(pu8keybuf);
1822
1823
1824                 }
1825
1826                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1827                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
1828                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL);
1829                         if (pu8keybuf == NULL) {
1830                                 PRINT_ER("No buffer to send Key\n");
1831                                 return -1;
1832                         }
1833                         pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1834                         memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->attr.wep.key_len, 1);
1835                         memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->attr.wep.key,
1836                                     pstrHostIFkeyAttr->attr.wep.key_len);
1837                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1838
1839                         strWID.id = (u16)WID_ADD_WEP_KEY;
1840                         strWID.type = WID_STR;
1841                         strWID.val = (s8 *)pu8keybuf;
1842                         strWID.size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1843
1844                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1845                                                    get_id_from_handler(hif_drv));
1846                         kfree(pu8keybuf);
1847                 } else if (pstrHostIFkeyAttr->action & REMOVEKEY) {
1848
1849                         PRINT_D(HOSTINF_DBG, "Removing key\n");
1850                         strWID.id = (u16)WID_REMOVE_WEP_KEY;
1851                         strWID.type = WID_STR;
1852
1853                         s8idxarray[0] = (s8)pstrHostIFkeyAttr->attr.wep.index;
1854                         strWID.val = s8idxarray;
1855                         strWID.size = 1;
1856
1857                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1858                                                    get_id_from_handler(hif_drv));
1859                 } else {
1860                         strWID.id = (u16)WID_KEY_ID;
1861                         strWID.type = WID_CHAR;
1862                         strWID.val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
1863                         strWID.size = sizeof(char);
1864
1865                         PRINT_D(HOSTINF_DBG, "Setting default key index\n");
1866
1867                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1868                                                    get_id_from_handler(hif_drv));
1869                 }
1870                 up(&hif_drv->hSemTestKeyBlock);
1871                 break;
1872
1873         case WPARxGtk:
1874                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1875                         pu8keybuf = kmalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1876                         if (pu8keybuf == NULL) {
1877                                 PRINT_ER("No buffer to send RxGTK Key\n");
1878                                 ret = -1;
1879                                 goto _WPARxGtk_end_case_;
1880                         }
1881
1882                         memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
1883
1884                         if (pstrHostIFkeyAttr->attr.wpa.seq != NULL)
1885                                 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1886
1887                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1888                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1889                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1890                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1891
1892                         strWIDList[0].id = (u16)WID_11I_MODE;
1893                         strWIDList[0].type = WID_CHAR;
1894                         strWIDList[0].size = sizeof(char);
1895                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wpa.mode));
1896
1897                         strWIDList[1].id = (u16)WID_ADD_RX_GTK;
1898                         strWIDList[1].type = WID_STR;
1899                         strWIDList[1].val = (s8 *)pu8keybuf;
1900                         strWIDList[1].size = RX_MIC_KEY_MSG_LEN;
1901
1902                         s32Error = send_config_pkt(SET_CFG, strWIDList, 2,
1903                                                    get_id_from_handler(hif_drv));
1904
1905                         kfree(pu8keybuf);
1906                         up(&hif_drv->hSemTestKeyBlock);
1907                 }
1908
1909                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1910                         PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n");
1911
1912                         pu8keybuf = kmalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1913                         if (pu8keybuf == NULL) {
1914                                 PRINT_ER("No buffer to send RxGTK Key\n");
1915                                 ret = -1;
1916                                 goto _WPARxGtk_end_case_;
1917                         }
1918
1919                         memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
1920
1921                         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
1922                                 memcpy(pu8keybuf, hif_drv->au8AssociatedBSSID, ETH_ALEN);
1923                         else
1924                                 PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED\n");
1925
1926                         memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1927                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1928                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1929                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1930                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1931
1932                         strWID.id = (u16)WID_ADD_RX_GTK;
1933                         strWID.type = WID_STR;
1934                         strWID.val = (s8 *)pu8keybuf;
1935                         strWID.size = RX_MIC_KEY_MSG_LEN;
1936
1937                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1938                                                    get_id_from_handler(hif_drv));
1939
1940                         kfree(pu8keybuf);
1941                         up(&hif_drv->hSemTestKeyBlock);
1942                 }
1943 _WPARxGtk_end_case_:
1944                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1945                 kfree(pstrHostIFkeyAttr->attr.wpa.seq);
1946                 if (ret == -1)
1947                         return ret;
1948
1949                 break;
1950
1951         case WPAPtk:
1952                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1953
1954
1955                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
1956
1957
1958
1959                         if (pu8keybuf == NULL) {
1960                                 PRINT_ER("No buffer to send PTK Key\n");
1961                                 ret = -1;
1962                                 goto _WPAPtk_end_case_;
1963
1964                         }
1965
1966                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1967                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1968                         memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1969                         memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->attr.wpa.key,
1970                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1971
1972                         strWIDList[0].id = (u16)WID_11I_MODE;
1973                         strWIDList[0].type = WID_CHAR;
1974                         strWIDList[0].size = sizeof(char);
1975                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wpa.mode));
1976
1977                         strWIDList[1].id = (u16)WID_ADD_PTK;
1978                         strWIDList[1].type = WID_STR;
1979                         strWIDList[1].val = (s8 *)pu8keybuf;
1980                         strWIDList[1].size = PTK_KEY_MSG_LEN + 1;
1981
1982                         s32Error = send_config_pkt(SET_CFG, strWIDList, 2,
1983                                                    get_id_from_handler(hif_drv));
1984                         kfree(pu8keybuf);
1985                         up(&hif_drv->hSemTestKeyBlock);
1986                 }
1987                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1988
1989
1990                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
1991
1992
1993
1994                         if (pu8keybuf == NULL) {
1995                                 PRINT_ER("No buffer to send PTK Key\n");
1996                                 ret = -1;
1997                                 goto _WPAPtk_end_case_;
1998
1999                         }
2000
2001                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
2002                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
2003                         memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->attr.wpa.key,
2004                                     pstrHostIFkeyAttr->attr.wpa.key_len);
2005
2006                         strWID.id = (u16)WID_ADD_PTK;
2007                         strWID.type = WID_STR;
2008                         strWID.val = (s8 *)pu8keybuf;
2009                         strWID.size = PTK_KEY_MSG_LEN;
2010
2011                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2012                                                    get_id_from_handler(hif_drv));
2013                         kfree(pu8keybuf);
2014                         up(&hif_drv->hSemTestKeyBlock);
2015                 }
2016
2017 _WPAPtk_end_case_:
2018                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
2019                 if (ret == -1)
2020                         return ret;
2021
2022                 break;
2023
2024
2025         case PMKSA:
2026
2027                 PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n");
2028
2029                 pu8keybuf = kmalloc((pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1, GFP_KERNEL);
2030                 if (pu8keybuf == NULL) {
2031                         PRINT_ER("No buffer to send PMKSA Key\n");
2032                         return -1;
2033                 }
2034
2035                 pu8keybuf[0] = pstrHostIFkeyAttr->attr.pmkid.numpmkid;
2036
2037                 for (i = 0; i < pstrHostIFkeyAttr->attr.pmkid.numpmkid; i++) {
2038                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
2039                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
2040                 }
2041
2042                 strWID.id = (u16)WID_PMKID_INFO;
2043                 strWID.type = WID_STR;
2044                 strWID.val = (s8 *)pu8keybuf;
2045                 strWID.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
2046
2047                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2048                                            get_id_from_handler(hif_drv));
2049
2050                 kfree(pu8keybuf);
2051                 break;
2052         }
2053
2054         if (s32Error)
2055                 PRINT_ER("Failed to send key config packet\n");
2056
2057
2058         return s32Error;
2059 }
2060
2061 static void Handle_Disconnect(struct host_if_drv *hif_drv)
2062 {
2063         struct wid strWID;
2064
2065         s32 s32Error = 0;
2066         u16 u16DummyReasonCode = 0;
2067
2068         strWID.id = (u16)WID_DISCONNECT;
2069         strWID.type = WID_CHAR;
2070         strWID.val = (s8 *)&u16DummyReasonCode;
2071         strWID.size = sizeof(char);
2072
2073
2074
2075         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
2076
2077         g_obtainingIP = false;
2078         host_int_set_power_mgmt(hif_drv, 0, 0);
2079
2080         eth_zero_addr(u8ConnectedSSID);
2081
2082         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2083                                    get_id_from_handler(hif_drv));
2084
2085         if (s32Error) {
2086                 PRINT_ER("Failed to send dissconect config packet\n");
2087         } else {
2088                 tstrDisconnectNotifInfo strDisconnectNotifInfo;
2089
2090                 memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
2091
2092                 strDisconnectNotifInfo.u16reason = 0;
2093                 strDisconnectNotifInfo.ie = NULL;
2094                 strDisconnectNotifInfo.ie_len = 0;
2095
2096                 if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
2097                         del_timer(&hif_drv->hScanTimer);
2098                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
2099                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
2100
2101                         hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
2102                 }
2103
2104                 if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
2105                         if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2106                                 PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n");
2107                                 del_timer(&hif_drv->hConnectTimer);
2108                         }
2109
2110                         hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
2111                                                                            0, &strDisconnectNotifInfo, hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
2112                 } else {
2113                         PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL\n");
2114                 }
2115
2116                 gbScanWhileConnected = false;
2117
2118                 hif_drv->enuHostIFstate = HOST_IF_IDLE;
2119
2120                 eth_zero_addr(hif_drv->au8AssociatedBSSID);
2121
2122                 hif_drv->strWILC_UsrConnReq.ssidLen = 0;
2123                 kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
2124                 kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
2125                 hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2126                 kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
2127
2128                 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
2129                         kfree(gu8FlushedJoinReq);
2130                         gu8FlushedJoinReq = NULL;
2131                 }
2132                 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
2133                         kfree(gu8FlushedInfoElemAsoc);
2134                         gu8FlushedInfoElemAsoc = NULL;
2135                 }
2136
2137         }
2138
2139         up(&hif_drv->hSemTestDisconnectBlock);
2140 }
2141
2142
2143 void resolve_disconnect_aberration(struct host_if_drv *hif_drv)
2144 {
2145         if (!hif_drv)
2146                 return;
2147         if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (hif_drv->enuHostIFstate == HOST_IF_CONNECTING)) {
2148                 PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n");
2149                 host_int_disconnect(hif_drv, 1);
2150         }
2151 }
2152
2153 static s32 Handle_GetChnl(struct host_if_drv *hif_drv)
2154 {
2155
2156         s32 s32Error = 0;
2157         struct wid strWID;
2158
2159         strWID.id = (u16)WID_CURRENT_CHANNEL;
2160         strWID.type = WID_CHAR;
2161         strWID.val = (s8 *)&gu8Chnl;
2162         strWID.size = sizeof(char);
2163
2164         PRINT_D(HOSTINF_DBG, "Getting channel value\n");
2165
2166         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2167                                    get_id_from_handler(hif_drv));
2168
2169         if (s32Error) {
2170                 PRINT_ER("Failed to get channel number\n");
2171                 s32Error = -EFAULT;
2172         }
2173
2174         up(&hif_drv->hSemGetCHNL);
2175
2176         return s32Error;
2177
2178
2179
2180 }
2181
2182 static void Handle_GetRssi(struct host_if_drv *hif_drv)
2183 {
2184         s32 s32Error = 0;
2185         struct wid strWID;
2186
2187         strWID.id = (u16)WID_RSSI;
2188         strWID.type = WID_CHAR;
2189         strWID.val = &gs8Rssi;
2190         strWID.size = sizeof(char);
2191
2192         PRINT_D(HOSTINF_DBG, "Getting RSSI value\n");
2193
2194         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2195                                    get_id_from_handler(hif_drv));
2196         if (s32Error) {
2197                 PRINT_ER("Failed to get RSSI value\n");
2198                 s32Error = -EFAULT;
2199         }
2200
2201         up(&hif_drv->hSemGetRSSI);
2202
2203
2204 }
2205
2206
2207 static void Handle_GetLinkspeed(struct host_if_drv *hif_drv)
2208 {
2209         s32 s32Error = 0;
2210         struct wid strWID;
2211
2212         gs8lnkspd = 0;
2213
2214         strWID.id = (u16)WID_LINKSPEED;
2215         strWID.type = WID_CHAR;
2216         strWID.val = &gs8lnkspd;
2217         strWID.size = sizeof(char);
2218
2219         PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n");
2220
2221         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2222                                    get_id_from_handler(hif_drv));
2223         if (s32Error) {
2224                 PRINT_ER("Failed to get LINKSPEED value\n");
2225                 s32Error = -EFAULT;
2226         }
2227
2228         up(&(hif_drv->hSemGetLINKSPEED));
2229
2230
2231 }
2232
2233 s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
2234 {
2235         struct wid strWIDList[5];
2236         u32 u32WidsCount = 0, s32Error = 0;
2237
2238         strWIDList[u32WidsCount].id = WID_LINKSPEED;
2239         strWIDList[u32WidsCount].type = WID_CHAR;
2240         strWIDList[u32WidsCount].size = sizeof(char);
2241         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u8LinkSpeed));
2242         u32WidsCount++;
2243
2244         strWIDList[u32WidsCount].id = WID_RSSI;
2245         strWIDList[u32WidsCount].type = WID_CHAR;
2246         strWIDList[u32WidsCount].size = sizeof(char);
2247         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->s8RSSI));
2248         u32WidsCount++;
2249
2250         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
2251         strWIDList[u32WidsCount].type = WID_INT;
2252         strWIDList[u32WidsCount].size = sizeof(u32);
2253         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32TxCount));
2254         u32WidsCount++;
2255
2256         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
2257         strWIDList[u32WidsCount].type = WID_INT;
2258         strWIDList[u32WidsCount].size = sizeof(u32);
2259         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32RxCount));
2260         u32WidsCount++;
2261
2262         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
2263         strWIDList[u32WidsCount].type = WID_INT;
2264         strWIDList[u32WidsCount].size = sizeof(u32);
2265         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32TxFailureCount));
2266         u32WidsCount++;
2267
2268         s32Error = send_config_pkt(GET_CFG, strWIDList, u32WidsCount,
2269                                    get_id_from_handler(hif_drv));
2270
2271         if (s32Error)
2272                 PRINT_ER("Failed to send scan paramters config packet\n");
2273
2274         up(&hWaitResponse);
2275         return 0;
2276
2277 }
2278
2279 static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv,
2280                                    struct sta_inactive_t *strHostIfStaInactiveT)
2281 {
2282
2283         s32 s32Error = 0;
2284         u8 *stamac;
2285         struct wid strWID;
2286
2287         strWID.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
2288         strWID.type = WID_STR;
2289         strWID.size = ETH_ALEN;
2290         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2291
2292
2293         stamac = strWID.val;
2294         memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
2295
2296
2297         PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
2298
2299
2300         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2301                                    get_id_from_handler(hif_drv));
2302
2303         if (s32Error) {
2304                 PRINT_ER("Failed to SET incative time\n");
2305                 return -EFAULT;
2306         }
2307
2308
2309         strWID.id = (u16)WID_GET_INACTIVE_TIME;
2310         strWID.type = WID_INT;
2311         strWID.val = (s8 *)&gu32InactiveTime;
2312         strWID.size = sizeof(u32);
2313
2314
2315         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2316                                    get_id_from_handler(hif_drv));
2317
2318         if (s32Error) {
2319                 PRINT_ER("Failed to get incative time\n");
2320                 return -EFAULT;
2321         }
2322
2323
2324         PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", gu32InactiveTime);
2325
2326         up(&hif_drv->hSemInactiveTime);
2327
2328         return s32Error;
2329
2330
2331
2332 }
2333
2334 static void Handle_AddBeacon(struct host_if_drv *hif_drv,
2335                              struct beacon_attr *pstrSetBeaconParam)
2336 {
2337         s32 s32Error = 0;
2338         struct wid strWID;
2339         u8 *pu8CurrByte;
2340
2341         PRINT_D(HOSTINF_DBG, "Adding BEACON\n");
2342
2343         strWID.id = (u16)WID_ADD_BEACON;
2344         strWID.type = WID_BIN;
2345         strWID.size = pstrSetBeaconParam->u32HeadLen + pstrSetBeaconParam->u32TailLen + 16;
2346         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2347         if (strWID.val == NULL)
2348                 goto ERRORHANDLER;
2349
2350         pu8CurrByte = strWID.val;
2351         *pu8CurrByte++ = (pstrSetBeaconParam->u32Interval & 0xFF);
2352         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 8) & 0xFF);
2353         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 16) & 0xFF);
2354         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 24) & 0xFF);
2355
2356         *pu8CurrByte++ = (pstrSetBeaconParam->u32DTIMPeriod & 0xFF);
2357         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 8) & 0xFF);
2358         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 16) & 0xFF);
2359         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 24) & 0xFF);
2360
2361         *pu8CurrByte++ = (pstrSetBeaconParam->u32HeadLen & 0xFF);
2362         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 8) & 0xFF);
2363         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 16) & 0xFF);
2364         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 24) & 0xFF);
2365
2366         memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Head, pstrSetBeaconParam->u32HeadLen);
2367         pu8CurrByte += pstrSetBeaconParam->u32HeadLen;
2368
2369         *pu8CurrByte++ = (pstrSetBeaconParam->u32TailLen & 0xFF);
2370         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 8) & 0xFF);
2371         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 16) & 0xFF);
2372         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 24) & 0xFF);
2373
2374         if (pstrSetBeaconParam->pu8Tail > 0)
2375                 memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Tail, pstrSetBeaconParam->u32TailLen);
2376         pu8CurrByte += pstrSetBeaconParam->u32TailLen;
2377
2378         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2379                                    get_id_from_handler(hif_drv));
2380         if (s32Error)
2381                 PRINT_ER("Failed to send add beacon config packet\n");
2382
2383 ERRORHANDLER:
2384         kfree(strWID.val);
2385         kfree(pstrSetBeaconParam->pu8Head);
2386         kfree(pstrSetBeaconParam->pu8Tail);
2387 }
2388
2389 static void Handle_DelBeacon(struct host_if_drv *hif_drv)
2390 {
2391         s32 s32Error = 0;
2392         struct wid strWID;
2393         u8 *pu8CurrByte;
2394
2395         strWID.id = (u16)WID_DEL_BEACON;
2396         strWID.type = WID_CHAR;
2397         strWID.size = sizeof(char);
2398         strWID.val = &gu8DelBcn;
2399
2400         if (strWID.val == NULL)
2401                 return;
2402
2403         pu8CurrByte = strWID.val;
2404
2405         PRINT_D(HOSTINF_DBG, "Deleting BEACON\n");
2406
2407         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2408                                    get_id_from_handler(hif_drv));
2409         if (s32Error)
2410                 PRINT_ER("Failed to send delete beacon config packet\n");
2411 }
2412
2413 static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer,
2414                                     struct add_sta_param *pstrStationParam)
2415 {
2416         u8 *pu8CurrByte;
2417
2418         pu8CurrByte = pu8Buffer;
2419
2420         PRINT_D(HOSTINF_DBG, "Packing STA params\n");
2421         memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN);
2422         pu8CurrByte +=  ETH_ALEN;
2423
2424         *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF;
2425         *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF;
2426
2427         *pu8CurrByte++ = pstrStationParam->u8NumRates;
2428         if (pstrStationParam->u8NumRates > 0)
2429                 memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates);
2430         pu8CurrByte += pstrStationParam->u8NumRates;
2431
2432         *pu8CurrByte++ = pstrStationParam->bIsHTSupported;
2433         *pu8CurrByte++ = pstrStationParam->u16HTCapInfo & 0xFF;
2434         *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF;
2435
2436         *pu8CurrByte++ = pstrStationParam->u8AmpduParams;
2437         memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE);
2438         pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
2439
2440         *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF;
2441         *pu8CurrByte++ = (pstrStationParam->u16HTExtParams >> 8) & 0xFF;
2442
2443         *pu8CurrByte++ = pstrStationParam->u32TxBeamformingCap & 0xFF;
2444         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 8) & 0xFF;
2445         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 16) & 0xFF;
2446         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 24) & 0xFF;
2447
2448         *pu8CurrByte++ = pstrStationParam->u8ASELCap;
2449
2450         *pu8CurrByte++ = pstrStationParam->u16FlagsMask & 0xFF;
2451         *pu8CurrByte++ = (pstrStationParam->u16FlagsMask >> 8) & 0xFF;
2452
2453         *pu8CurrByte++ = pstrStationParam->u16FlagsSet & 0xFF;
2454         *pu8CurrByte++ = (pstrStationParam->u16FlagsSet >> 8) & 0xFF;
2455
2456         return pu8CurrByte - pu8Buffer;
2457 }
2458
2459 static void Handle_AddStation(struct host_if_drv *hif_drv,
2460                               struct add_sta_param *pstrStationParam)
2461 {
2462         s32 s32Error = 0;
2463         struct wid strWID;
2464         u8 *pu8CurrByte;
2465
2466         PRINT_D(HOSTINF_DBG, "Handling add station\n");
2467         strWID.id = (u16)WID_ADD_STA;
2468         strWID.type = WID_BIN;
2469         strWID.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
2470
2471         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2472         if (strWID.val == NULL)
2473                 goto ERRORHANDLER;
2474
2475         pu8CurrByte = strWID.val;
2476         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2477
2478         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2479                                    get_id_from_handler(hif_drv));
2480         if (s32Error != 0)
2481                 PRINT_ER("Failed to send add station config packet\n");
2482
2483 ERRORHANDLER:
2484         kfree(pstrStationParam->pu8Rates);
2485         kfree(strWID.val);
2486 }
2487
2488 static void Handle_DelAllSta(struct host_if_drv *hif_drv,
2489                              struct del_all_sta *pstrDelAllStaParam)
2490 {
2491         s32 s32Error = 0;
2492
2493         struct wid strWID;
2494         u8 *pu8CurrByte;
2495         u8 i;
2496         u8 au8Zero_Buff[6] = {0};
2497
2498         strWID.id = (u16)WID_DEL_ALL_STA;
2499         strWID.type = WID_STR;
2500         strWID.size = (pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1;
2501
2502         PRINT_D(HOSTINF_DBG, "Handling delete station\n");
2503
2504         strWID.val = kmalloc((pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1, GFP_KERNEL);
2505         if (strWID.val == NULL)
2506                 goto ERRORHANDLER;
2507
2508         pu8CurrByte = strWID.val;
2509
2510         *(pu8CurrByte++) = pstrDelAllStaParam->u8Num_AssocSta;
2511
2512         for (i = 0; i < MAX_NUM_STA; i++) {
2513                 if (memcmp(pstrDelAllStaParam->au8Sta_DelAllSta[i], au8Zero_Buff, ETH_ALEN))
2514                         memcpy(pu8CurrByte, pstrDelAllStaParam->au8Sta_DelAllSta[i], ETH_ALEN);
2515                 else
2516                         continue;
2517
2518                 pu8CurrByte += ETH_ALEN;
2519         }
2520
2521         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2522                                    get_id_from_handler(hif_drv));
2523         if (s32Error)
2524                 PRINT_ER("Failed to send add station config packet\n");
2525
2526 ERRORHANDLER:
2527         kfree(strWID.val);
2528
2529         up(&hWaitResponse);
2530 }
2531
2532 static void Handle_DelStation(struct host_if_drv *hif_drv,
2533                               struct del_sta *pstrDelStaParam)
2534 {
2535         s32 s32Error = 0;
2536         struct wid strWID;
2537         u8 *pu8CurrByte;
2538
2539         strWID.id = (u16)WID_REMOVE_STA;
2540         strWID.type = WID_BIN;
2541         strWID.size = ETH_ALEN;
2542
2543         PRINT_D(HOSTINF_DBG, "Handling delete station\n");
2544
2545         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2546         if (strWID.val == NULL)
2547                 goto ERRORHANDLER;
2548
2549         pu8CurrByte = strWID.val;
2550
2551         memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN);
2552
2553         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2554                                    get_id_from_handler(hif_drv));
2555         if (s32Error)
2556                 PRINT_ER("Failed to send add station config packet\n");
2557
2558 ERRORHANDLER:
2559         kfree(strWID.val);
2560 }
2561
2562 static void Handle_EditStation(struct host_if_drv *hif_drv,
2563                                struct add_sta_param *pstrStationParam)
2564 {
2565         s32 s32Error = 0;
2566         struct wid strWID;
2567         u8 *pu8CurrByte;
2568
2569         strWID.id = (u16)WID_EDIT_STA;
2570         strWID.type = WID_BIN;
2571         strWID.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
2572
2573         PRINT_D(HOSTINF_DBG, "Handling edit station\n");
2574         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2575         if (strWID.val == NULL)
2576                 goto ERRORHANDLER;
2577
2578         pu8CurrByte = strWID.val;
2579         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2580
2581         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2582                                    get_id_from_handler(hif_drv));
2583         if (s32Error)
2584                 PRINT_ER("Failed to send edit station config packet\n");
2585
2586 ERRORHANDLER:
2587         kfree(pstrStationParam->pu8Rates);
2588         kfree(strWID.val);
2589 }
2590
2591 static int Handle_RemainOnChan(struct host_if_drv *hif_drv,
2592                                struct remain_ch *pstrHostIfRemainOnChan)
2593 {
2594         s32 s32Error = 0;
2595         u8 u8remain_on_chan_flag;
2596         struct wid strWID;
2597
2598         if (!hif_drv->u8RemainOnChan_pendingreq) {
2599                 hif_drv->strHostIfRemainOnChan.pVoid = pstrHostIfRemainOnChan->pVoid;
2600                 hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired;
2601                 hif_drv->strHostIfRemainOnChan.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady;
2602                 hif_drv->strHostIfRemainOnChan.u16Channel = pstrHostIfRemainOnChan->u16Channel;
2603                 hif_drv->strHostIfRemainOnChan.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID;
2604         } else {
2605                 pstrHostIfRemainOnChan->u16Channel = hif_drv->strHostIfRemainOnChan.u16Channel;
2606         }
2607
2608         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
2609                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while scanning return\n");
2610                 hif_drv->u8RemainOnChan_pendingreq = 1;
2611                 s32Error = -EBUSY;
2612                 goto ERRORHANDLER;
2613         }
2614         if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2615                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while connecting return\n");
2616                 s32Error = -EBUSY;
2617                 goto ERRORHANDLER;
2618         }
2619
2620         if (g_obtainingIP || connecting) {
2621                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
2622                 s32Error = -EBUSY;
2623                 goto ERRORHANDLER;
2624         }
2625
2626         PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", pstrHostIfRemainOnChan->u16Channel);
2627
2628         u8remain_on_chan_flag = true;
2629         strWID.id = (u16)WID_REMAIN_ON_CHAN;
2630         strWID.type = WID_STR;
2631         strWID.size = 2;
2632         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2633
2634         if (strWID.val == NULL) {
2635                 s32Error = -ENOMEM;
2636                 goto ERRORHANDLER;
2637         }
2638
2639         strWID.val[0] = u8remain_on_chan_flag;
2640         strWID.val[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
2641
2642         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2643                                    get_id_from_handler(hif_drv));
2644         if (s32Error != 0)
2645                 PRINT_ER("Failed to set remain on channel\n");
2646
2647 ERRORHANDLER:
2648         {
2649                 P2P_LISTEN_STATE = 1;
2650                 hif_drv->hRemainOnChannel.data = (unsigned long)hif_drv;
2651                 mod_timer(&hif_drv->hRemainOnChannel,
2652                           jiffies +
2653                           msecs_to_jiffies(pstrHostIfRemainOnChan->u32duration));
2654
2655                 if (hif_drv->strHostIfRemainOnChan.pRemainOnChanReady)
2656                         hif_drv->strHostIfRemainOnChan.pRemainOnChanReady(hif_drv->strHostIfRemainOnChan.pVoid);
2657
2658                 if (hif_drv->u8RemainOnChan_pendingreq)
2659                         hif_drv->u8RemainOnChan_pendingreq = 0;
2660         }
2661         return s32Error;
2662 }
2663
2664 static int Handle_RegisterFrame(struct host_if_drv *hif_drv,
2665                                 struct reg_frame *pstrHostIfRegisterFrame)
2666 {
2667         s32 s32Error = 0;
2668         struct wid strWID;
2669         u8 *pu8CurrByte;
2670
2671         PRINT_D(HOSTINF_DBG, "Handling frame register Flag : %d FrameType: %d\n", pstrHostIfRegisterFrame->bReg, pstrHostIfRegisterFrame->u16FrameType);
2672
2673         strWID.id = (u16)WID_REGISTER_FRAME;
2674         strWID.type = WID_STR;
2675         strWID.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
2676         if (strWID.val == NULL)
2677                 return -ENOMEM;
2678
2679         pu8CurrByte = strWID.val;
2680
2681         *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg;
2682         *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid;
2683         memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16));
2684
2685
2686         strWID.size = sizeof(u16) + 2;
2687
2688         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2689                                    get_id_from_handler(hif_drv));
2690         if (s32Error) {
2691                 PRINT_ER("Failed to frame register config packet\n");
2692                 s32Error = -EINVAL;
2693         }
2694
2695         return s32Error;
2696
2697 }
2698
2699 #define FALSE_FRMWR_CHANNEL 100
2700 static u32 Handle_ListenStateExpired(struct host_if_drv *hif_drv,
2701                                      struct remain_ch *pstrHostIfRemainOnChan)
2702 {
2703         u8 u8remain_on_chan_flag;
2704         struct wid strWID;
2705         s32 s32Error = 0;
2706
2707         PRINT_D(HOSTINF_DBG, "CANCEL REMAIN ON CHAN\n");
2708
2709         if (P2P_LISTEN_STATE) {
2710                 u8remain_on_chan_flag = false;
2711                 strWID.id = (u16)WID_REMAIN_ON_CHAN;
2712                 strWID.type = WID_STR;
2713                 strWID.size = 2;
2714                 strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2715
2716                 if (strWID.val == NULL)
2717                         PRINT_ER("Failed to allocate memory\n");
2718
2719                 strWID.val[0] = u8remain_on_chan_flag;
2720                 strWID.val[1] = FALSE_FRMWR_CHANNEL;
2721
2722                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2723                                            get_id_from_handler(hif_drv));
2724                 if (s32Error != 0) {
2725                         PRINT_ER("Failed to set remain on channel\n");
2726                         goto _done_;
2727                 }
2728
2729                 if (hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired) {
2730                         hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired(hif_drv->strHostIfRemainOnChan.pVoid
2731                                                                                , pstrHostIfRemainOnChan->u32ListenSessionID);
2732                 }
2733                 P2P_LISTEN_STATE = 0;
2734         } else {
2735                 PRINT_D(GENERIC_DBG, "Not in listen state\n");
2736                 s32Error = -EFAULT;
2737         }
2738
2739 _done_:
2740         return s32Error;
2741 }
2742
2743 static void ListenTimerCB(unsigned long arg)
2744 {
2745         s32 s32Error = 0;
2746         struct host_if_msg msg;
2747         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
2748
2749         del_timer(&hif_drv->hRemainOnChannel);
2750
2751         memset(&msg, 0, sizeof(struct host_if_msg));
2752         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
2753         msg.drv = hif_drv;
2754         msg.body.remain_on_ch.u32ListenSessionID = hif_drv->strHostIfRemainOnChan.u32ListenSessionID;
2755
2756         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2757         if (s32Error)
2758                 PRINT_ER("wilc_mq_send fail\n");
2759 }
2760
2761 static void Handle_PowerManagement(struct host_if_drv *hif_drv,
2762                                    struct power_mgmt_param *strPowerMgmtParam)
2763 {
2764         s32 s32Error = 0;
2765         struct wid strWID;
2766         s8 s8PowerMode;
2767
2768         strWID.id = (u16)WID_POWER_MANAGEMENT;
2769
2770         if (strPowerMgmtParam->bIsEnabled == true)
2771                 s8PowerMode = MIN_FAST_PS;
2772         else
2773                 s8PowerMode = NO_POWERSAVE;
2774         PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode);
2775         strWID.val = &s8PowerMode;
2776         strWID.size = sizeof(char);
2777
2778         PRINT_D(HOSTINF_DBG, "Handling Power Management\n");
2779
2780         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2781                                    get_id_from_handler(hif_drv));
2782         if (s32Error)
2783                 PRINT_ER("Failed to send power management config packet\n");
2784 }
2785
2786 static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv,
2787                                       struct set_multicast *strHostIfSetMulti)
2788 {
2789         s32 s32Error = 0;
2790         struct wid strWID;
2791         u8 *pu8CurrByte;
2792
2793         PRINT_D(HOSTINF_DBG, "Setup Multicast Filter\n");
2794
2795         strWID.id = (u16)WID_SETUP_MULTICAST_FILTER;
2796         strWID.type = WID_BIN;
2797         strWID.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->u32count) * ETH_ALEN);
2798         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2799         if (strWID.val == NULL)
2800                 goto ERRORHANDLER;
2801
2802         pu8CurrByte = strWID.val;
2803         *pu8CurrByte++ = (strHostIfSetMulti->bIsEnabled & 0xFF);
2804         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 8) & 0xFF);
2805         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 16) & 0xFF);
2806         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 24) & 0xFF);
2807
2808         *pu8CurrByte++ = (strHostIfSetMulti->u32count & 0xFF);
2809         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 8) & 0xFF);
2810         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 16) & 0xFF);
2811         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 24) & 0xFF);
2812
2813         if ((strHostIfSetMulti->u32count) > 0)
2814                 memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->u32count) * ETH_ALEN));
2815
2816         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2817                                    get_id_from_handler(hif_drv));
2818         if (s32Error)
2819                 PRINT_ER("Failed to send setup multicast config packet\n");
2820
2821 ERRORHANDLER:
2822         kfree(strWID.val);
2823
2824 }
2825
2826 static s32 Handle_AddBASession(struct host_if_drv *hif_drv,
2827                                struct ba_session_info *strHostIfBASessionInfo)
2828 {
2829         s32 s32Error = 0;
2830         struct wid strWID;
2831         int AddbaTimeout = 100;
2832         char *ptr = NULL;
2833
2834         PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\nBufferSize == %d\nSessionTimeOut = %d\n",
2835                 strHostIfBASessionInfo->au8Bssid[0],
2836                 strHostIfBASessionInfo->au8Bssid[1],
2837                 strHostIfBASessionInfo->au8Bssid[2],
2838                 strHostIfBASessionInfo->u16BufferSize,
2839                 strHostIfBASessionInfo->u16SessionTimeout,
2840                 strHostIfBASessionInfo->u8Ted);
2841
2842         strWID.id = (u16)WID_11E_P_ACTION_REQ;
2843         strWID.type = WID_STR;
2844         strWID.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
2845         strWID.size = BLOCK_ACK_REQ_SIZE;
2846         ptr = strWID.val;
2847         *ptr++ = 0x14;
2848         *ptr++ = 0x3;
2849         *ptr++ = 0x0;
2850         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2851         ptr += ETH_ALEN;
2852         *ptr++ = strHostIfBASessionInfo->u8Ted;
2853         *ptr++ = 1;
2854         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
2855         *ptr++ = ((strHostIfBASessionInfo->u16BufferSize >> 16) & 0xFF);
2856         *ptr++ = (strHostIfBASessionInfo->u16SessionTimeout & 0xFF);
2857         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
2858         *ptr++ = (AddbaTimeout & 0xFF);
2859         *ptr++ = ((AddbaTimeout >> 16) & 0xFF);
2860         *ptr++ = 8;
2861         *ptr++ = 0;
2862
2863         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2864                                    get_id_from_handler(hif_drv));
2865         if (s32Error)
2866                 PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n");
2867
2868
2869         strWID.id = (u16)WID_11E_P_ACTION_REQ;
2870         strWID.type = WID_STR;
2871         strWID.size = 15;
2872         ptr = strWID.val;
2873         *ptr++ = 15;
2874         *ptr++ = 7;
2875         *ptr++ = 0x2;
2876         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2877         ptr += ETH_ALEN;
2878         *ptr++ = strHostIfBASessionInfo->u8Ted;
2879         *ptr++ = 8;
2880         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
2881         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
2882         *ptr++ = 3;
2883         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2884                                    get_id_from_handler(hif_drv));
2885
2886         if (strWID.val != NULL)
2887                 kfree(strWID.val);
2888
2889         return s32Error;
2890
2891 }
2892
2893 static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv,
2894                                      struct ba_session_info *strHostIfBASessionInfo)
2895 {
2896         s32 s32Error = 0;
2897         struct wid strWID;
2898         char *ptr = NULL;
2899
2900         PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
2901                 strHostIfBASessionInfo->au8Bssid[0],
2902                 strHostIfBASessionInfo->au8Bssid[1],
2903                 strHostIfBASessionInfo->au8Bssid[2],
2904                 strHostIfBASessionInfo->u8Ted);
2905
2906         strWID.id = (u16)WID_DEL_ALL_RX_BA;
2907         strWID.type = WID_STR;
2908         strWID.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
2909         strWID.size = BLOCK_ACK_REQ_SIZE;
2910         ptr = strWID.val;
2911         *ptr++ = 0x14;
2912         *ptr++ = 0x3;
2913         *ptr++ = 0x2;
2914         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2915         ptr += ETH_ALEN;
2916         *ptr++ = strHostIfBASessionInfo->u8Ted;
2917         *ptr++ = 0;
2918         *ptr++ = 32;
2919
2920         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2921                                    get_id_from_handler(hif_drv));
2922         if (s32Error)
2923                 PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
2924
2925
2926         if (strWID.val != NULL)
2927                 kfree(strWID.val);
2928
2929         up(&hWaitResponse);
2930
2931         return s32Error;
2932
2933 }
2934
2935 static int hostIFthread(void *pvArg)
2936 {
2937         u32 u32Ret;
2938         struct host_if_msg msg;
2939         struct host_if_drv *hif_drv;
2940
2941         memset(&msg, 0, sizeof(struct host_if_msg));
2942
2943         while (1) {
2944                 wilc_mq_recv(&gMsgQHostIF, &msg, sizeof(struct host_if_msg), &u32Ret);
2945                 hif_drv = (struct host_if_drv *)msg.drv;
2946                 if (msg.id == HOST_IF_MSG_EXIT) {
2947                         PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n");
2948                         break;
2949                 }
2950
2951                 if ((!g_wilc_initialized)) {
2952                         PRINT_D(GENERIC_DBG, "--WAIT--");
2953                         usleep_range(200 * 1000, 200 * 1000);
2954                         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2955                         continue;
2956                 }
2957
2958                 if (msg.id == HOST_IF_MSG_CONNECT && hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
2959                         PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n");
2960                         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2961                         usleep_range(2 * 1000, 2 * 1000);
2962                         continue;
2963                 }
2964
2965                 switch (msg.id) {
2966                 case HOST_IF_MSG_Q_IDLE:
2967                         Handle_wait_msg_q_empty();
2968                         break;
2969
2970                 case HOST_IF_MSG_SCAN:
2971                         Handle_Scan(msg.drv, &msg.body.scan_info);
2972                         break;
2973
2974                 case HOST_IF_MSG_CONNECT:
2975                         Handle_Connect(msg.drv, &msg.body.con_info);
2976                         break;
2977
2978                 case HOST_IF_MSG_FLUSH_CONNECT:
2979                         Handle_FlushConnect(msg.drv);
2980                         break;
2981
2982                 case HOST_IF_MSG_RCVD_NTWRK_INFO:
2983                         Handle_RcvdNtwrkInfo(msg.drv, &msg.body.net_info);
2984                         break;
2985
2986                 case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
2987                         Handle_RcvdGnrlAsyncInfo(msg.drv, &msg.body.async_info);
2988                         break;
2989
2990                 case HOST_IF_MSG_KEY:
2991                         Handle_Key(msg.drv, &msg.body.key_info);
2992                         break;
2993
2994                 case HOST_IF_MSG_CFG_PARAMS:
2995
2996                         Handle_CfgParam(msg.drv, &msg.body.cfg_info);
2997                         break;
2998
2999                 case HOST_IF_MSG_SET_CHANNEL:
3000                         Handle_SetChannel(msg.drv, &msg.body.channel_info);
3001                         break;
3002
3003                 case HOST_IF_MSG_DISCONNECT:
3004                         Handle_Disconnect(msg.drv);
3005                         break;
3006
3007                 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
3008                         del_timer(&hif_drv->hScanTimer);
3009                         PRINT_D(HOSTINF_DBG, "scan completed successfully\n");
3010
3011                         if (!linux_wlan_get_num_conn_ifcs())
3012                                 chip_sleep_manually(INFINITE_SLEEP_TIME);
3013
3014                         Handle_ScanDone(msg.drv, SCAN_EVENT_DONE);
3015
3016                         if (hif_drv->u8RemainOnChan_pendingreq)
3017                                 Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
3018
3019                         break;
3020
3021                 case HOST_IF_MSG_GET_RSSI:
3022                         Handle_GetRssi(msg.drv);
3023                         break;
3024
3025                 case HOST_IF_MSG_GET_LINKSPEED:
3026                         Handle_GetLinkspeed(msg.drv);
3027                         break;
3028
3029                 case HOST_IF_MSG_GET_STATISTICS:
3030                         Handle_GetStatistics(msg.drv, (struct rf_info *)msg.body.data);
3031                         break;
3032
3033                 case HOST_IF_MSG_GET_CHNL:
3034                         Handle_GetChnl(msg.drv);
3035                         break;
3036
3037                 case HOST_IF_MSG_ADD_BEACON:
3038                         Handle_AddBeacon(msg.drv, &msg.body.beacon_info);
3039                         break;
3040
3041                 case HOST_IF_MSG_DEL_BEACON:
3042                         Handle_DelBeacon(msg.drv);
3043                         break;
3044
3045                 case HOST_IF_MSG_ADD_STATION:
3046                         Handle_AddStation(msg.drv, &msg.body.add_sta_info);
3047                         break;
3048
3049                 case HOST_IF_MSG_DEL_STATION:
3050                         Handle_DelStation(msg.drv, &msg.body.del_sta_info);
3051                         break;
3052
3053                 case HOST_IF_MSG_EDIT_STATION:
3054                         Handle_EditStation(msg.drv, &msg.body.edit_sta_info);
3055                         break;
3056
3057                 case HOST_IF_MSG_GET_INACTIVETIME:
3058                         Handle_Get_InActiveTime(msg.drv, &msg.body.mac_info);
3059                         break;
3060
3061                 case HOST_IF_MSG_SCAN_TIMER_FIRED:
3062                         PRINT_D(HOSTINF_DBG, "Scan Timeout\n");
3063
3064                         Handle_ScanDone(msg.drv, SCAN_EVENT_ABORTED);
3065                         break;
3066
3067                 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
3068                         PRINT_D(HOSTINF_DBG, "Connect Timeout\n");
3069                         Handle_ConnectTimeout(msg.drv);
3070                         break;
3071
3072                 case HOST_IF_MSG_POWER_MGMT:
3073                         Handle_PowerManagement(msg.drv, &msg.body.pwr_mgmt_info);
3074                         break;
3075
3076                 case HOST_IF_MSG_SET_WFIDRV_HANDLER:
3077                         Handle_SetWfiDrvHandler(msg.drv,
3078                                                 &msg.body.drv);
3079                         break;
3080
3081                 case HOST_IF_MSG_SET_OPERATION_MODE:
3082                         Handle_SetOperationMode(msg.drv, &msg.body.mode);
3083                         break;
3084
3085                 case HOST_IF_MSG_SET_IPADDRESS:
3086                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
3087                         Handle_set_IPAddress(msg.drv, msg.body.ip_info.au8IPAddr, msg.body.ip_info.idx);
3088                         break;
3089
3090                 case HOST_IF_MSG_GET_IPADDRESS:
3091                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
3092                         Handle_get_IPAddress(msg.drv, msg.body.ip_info.au8IPAddr, msg.body.ip_info.idx);
3093                         break;
3094
3095                 case HOST_IF_MSG_SET_MAC_ADDRESS:
3096                         Handle_SetMacAddress(msg.drv, &msg.body.set_mac_info);
3097                         break;
3098
3099                 case HOST_IF_MSG_GET_MAC_ADDRESS:
3100                         Handle_GetMacAddress(msg.drv, &msg.body.get_mac_info);
3101                         break;
3102
3103                 case HOST_IF_MSG_REMAIN_ON_CHAN:
3104                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REMAIN_ON_CHAN\n");
3105                         Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
3106                         break;
3107
3108                 case HOST_IF_MSG_REGISTER_FRAME:
3109                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REGISTER_FRAME\n");
3110                         Handle_RegisterFrame(msg.drv, &msg.body.reg_frame);
3111                         break;
3112
3113                 case HOST_IF_MSG_LISTEN_TIMER_FIRED:
3114                         Handle_ListenStateExpired(msg.drv, &msg.body.remain_on_ch);
3115                         break;
3116
3117                 case HOST_IF_MSG_SET_MULTICAST_FILTER:
3118                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_MULTICAST_FILTER\n");
3119                         Handle_SetMulticastFilter(msg.drv, &msg.body.multicast_info);
3120                         break;
3121
3122                 case HOST_IF_MSG_ADD_BA_SESSION:
3123                         Handle_AddBASession(msg.drv, &msg.body.session_info);
3124                         break;
3125
3126                 case HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS:
3127                         Handle_DelAllRxBASessions(msg.drv, &msg.body.session_info);
3128                         break;
3129
3130                 case HOST_IF_MSG_DEL_ALL_STA:
3131                         Handle_DelAllSta(msg.drv, &msg.body.del_all_sta_info);
3132                         break;
3133
3134                 default:
3135                         PRINT_ER("[Host Interface] undefined Received Msg ID\n");
3136                         break;
3137                 }
3138         }
3139
3140         PRINT_D(HOSTINF_DBG, "Releasing thread exit semaphore\n");
3141         up(&hSemHostIFthrdEnd);
3142         return 0;
3143 }
3144
3145 static void TimerCB_Scan(unsigned long arg)
3146 {
3147         void *pvArg = (void *)arg;
3148         struct host_if_msg msg;
3149
3150         memset(&msg, 0, sizeof(struct host_if_msg));
3151         msg.drv = pvArg;
3152         msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
3153
3154         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3155 }
3156
3157 static void TimerCB_Connect(unsigned long arg)
3158 {
3159         void *pvArg = (void *)arg;
3160         struct host_if_msg msg;
3161
3162         memset(&msg, 0, sizeof(struct host_if_msg));
3163         msg.drv = pvArg;
3164         msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
3165
3166         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3167 }
3168
3169 s32 host_int_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress)
3170 {
3171         struct wid strWID;
3172
3173         strWID.id = (u16)WID_REMOVE_KEY;
3174         strWID.type = WID_STR;
3175         strWID.val = (s8 *)pu8StaAddress;
3176         strWID.size = 6;
3177
3178         return 0;
3179 }
3180
3181 int host_int_remove_wep_key(struct host_if_drv *hif_drv, u8 index)
3182 {
3183         int result = 0;
3184         struct host_if_msg msg;
3185
3186         if (!hif_drv) {
3187                 result = -EFAULT;
3188                 PRINT_ER("Failed to send setup multicast config packet\n");
3189                 return result;
3190         }
3191
3192         memset(&msg, 0, sizeof(struct host_if_msg));
3193
3194         msg.id = HOST_IF_MSG_KEY;
3195         msg.body.key_info.type = WEP;
3196         msg.body.key_info.action = REMOVEKEY;
3197         msg.drv = hif_drv;
3198         msg.body.key_info.attr.wep.index = index;
3199
3200         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3201         if (result)
3202                 PRINT_ER("Error in sending message queue : Request to remove WEP key\n");
3203         down(&hif_drv->hSemTestKeyBlock);
3204
3205         return result;
3206 }
3207
3208 s32 host_int_set_WEPDefaultKeyID(struct host_if_drv *hif_drv, u8 u8Index)
3209 {
3210         s32 s32Error = 0;
3211         struct host_if_msg msg;
3212
3213
3214         if (!hif_drv) {
3215                 s32Error = -EFAULT;
3216                 PRINT_ER("driver is null\n");
3217                 return s32Error;
3218         }
3219
3220         memset(&msg, 0, sizeof(struct host_if_msg));
3221
3222
3223         msg.id = HOST_IF_MSG_KEY;
3224         msg.body.key_info.type = WEP;
3225         msg.body.key_info.action = DEFAULTKEY;
3226         msg.drv = hif_drv;
3227         msg.body.key_info.attr.wep.index = u8Index;
3228
3229         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3230         if (s32Error)
3231                 PRINT_ER("Error in sending message queue : Default key index\n");
3232         down(&hif_drv->hSemTestKeyBlock);
3233
3234         return s32Error;
3235 }
3236
3237 s32 host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv,
3238                                  const u8 *pu8WepKey,
3239                                  u8 u8WepKeylen,
3240                                  u8 u8Keyidx)
3241 {
3242
3243         s32 s32Error = 0;
3244         struct host_if_msg msg;
3245
3246         if (!hif_drv) {
3247                 s32Error = -EFAULT;
3248                 PRINT_ER("driver is null\n");
3249                 return s32Error;
3250         }
3251
3252         memset(&msg, 0, sizeof(struct host_if_msg));
3253
3254
3255         msg.id = HOST_IF_MSG_KEY;
3256         msg.body.key_info.type = WEP;
3257         msg.body.key_info.action = ADDKEY;
3258         msg.drv = hif_drv;
3259         msg.body.key_info.attr.wep.key = kmalloc(u8WepKeylen, GFP_KERNEL);
3260         memcpy(msg.body.key_info.attr.wep.key, pu8WepKey, u8WepKeylen);
3261         msg.body.key_info.attr.wep.key_len = (u8WepKeylen);
3262         msg.body.key_info.attr.wep.index = u8Keyidx;
3263
3264         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3265         if (s32Error)
3266                 PRINT_ER("Error in sending message queue :WEP Key\n");
3267         down(&hif_drv->hSemTestKeyBlock);
3268
3269         return s32Error;
3270
3271 }
3272
3273 s32 host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv,
3274                                 const u8 *pu8WepKey,
3275                                 u8 u8WepKeylen,
3276                                 u8 u8Keyidx,
3277                                 u8 u8mode,
3278                                 enum AUTHTYPE tenuAuth_type)
3279 {
3280
3281         s32 s32Error = 0;
3282         struct host_if_msg msg;
3283         u8 i;
3284
3285         if (!hif_drv) {
3286                 s32Error = -EFAULT;
3287                 PRINT_ER("driver is null\n");
3288                 return s32Error;
3289         }
3290
3291         memset(&msg, 0, sizeof(struct host_if_msg));
3292
3293         if (INFO) {
3294                 for (i = 0; i < u8WepKeylen; i++)
3295                         PRINT_INFO(HOSTAPD_DBG, "KEY is %x\n", pu8WepKey[i]);
3296         }
3297         msg.id = HOST_IF_MSG_KEY;
3298         msg.body.key_info.type = WEP;
3299         msg.body.key_info.action = ADDKEY_AP;
3300         msg.drv = hif_drv;
3301         msg.body.key_info.attr.wep.key = kmalloc(u8WepKeylen, GFP_KERNEL);
3302         memcpy(msg.body.key_info.attr.wep.key, pu8WepKey, (u8WepKeylen));
3303         msg.body.key_info.attr.wep.key_len = (u8WepKeylen);
3304         msg.body.key_info.attr.wep.index = u8Keyidx;
3305         msg.body.key_info.attr.wep.mode = u8mode;
3306         msg.body.key_info.attr.wep.auth_type = tenuAuth_type;
3307
3308         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3309
3310         if (s32Error)
3311                 PRINT_ER("Error in sending message queue :WEP Key\n");
3312         down(&hif_drv->hSemTestKeyBlock);
3313
3314         return s32Error;
3315
3316 }
3317
3318 s32 host_int_add_ptk(struct host_if_drv *hif_drv, const u8 *pu8Ptk,
3319                      u8 u8PtkKeylen, const u8 *mac_addr,
3320                      const u8 *pu8RxMic, const u8 *pu8TxMic,
3321                      u8 mode, u8 u8Ciphermode, u8 u8Idx)
3322 {
3323         s32 s32Error = 0;
3324         struct host_if_msg msg;
3325         u8 u8KeyLen = u8PtkKeylen;
3326         u32 i;
3327
3328         if (!hif_drv) {
3329                 s32Error = -EFAULT;
3330                 PRINT_ER("driver is null\n");
3331                 return s32Error;
3332         }
3333         if (pu8RxMic != NULL)
3334                 u8KeyLen += RX_MIC_KEY_LEN;
3335         if (pu8TxMic != NULL)
3336                 u8KeyLen += TX_MIC_KEY_LEN;
3337
3338         memset(&msg, 0, sizeof(struct host_if_msg));
3339
3340
3341         msg.id = HOST_IF_MSG_KEY;
3342         msg.body.key_info.type = WPAPtk;
3343         if (mode == AP_MODE) {
3344                 msg.body.key_info.action = ADDKEY_AP;
3345                 msg.body.key_info.attr.wpa.index = u8Idx;
3346         }
3347         if (mode == STATION_MODE)
3348                 msg.body.key_info.action = ADDKEY;
3349
3350         msg.body.key_info.attr.wpa.key = kmalloc(u8PtkKeylen, GFP_KERNEL);
3351         memcpy(msg.body.key_info.attr.wpa.key, pu8Ptk, u8PtkKeylen);
3352
3353         if (pu8RxMic != NULL) {
3354                 memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
3355                 if (INFO) {
3356                         for (i = 0; i < RX_MIC_KEY_LEN; i++)
3357                                 PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, pu8RxMic[i]);
3358                 }
3359         }
3360         if (pu8TxMic != NULL) {
3361                 memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
3362                 if (INFO) {
3363                         for (i = 0; i < TX_MIC_KEY_LEN; i++)
3364                                 PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, pu8TxMic[i]);
3365                 }
3366         }
3367
3368         msg.body.key_info.attr.wpa.key_len = u8KeyLen;
3369         msg.body.key_info.attr.wpa.mac_addr = mac_addr;
3370         msg.body.key_info.attr.wpa.mode = u8Ciphermode;
3371         msg.drv = hif_drv;
3372
3373         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3374
3375         if (s32Error)
3376                 PRINT_ER("Error in sending message queue:  PTK Key\n");
3377
3378         down(&hif_drv->hSemTestKeyBlock);
3379
3380         return s32Error;
3381 }
3382
3383 s32 host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *pu8RxGtk,
3384                         u8 u8GtkKeylen, u8 u8KeyIdx,
3385                         u32 u32KeyRSClen, const u8 *KeyRSC,
3386                         const u8 *pu8RxMic, const u8 *pu8TxMic,
3387                         u8 mode, u8 u8Ciphermode)
3388 {
3389         s32 s32Error = 0;
3390         struct host_if_msg msg;
3391         u8 u8KeyLen = u8GtkKeylen;
3392
3393         if (!hif_drv) {
3394                 s32Error = -EFAULT;
3395                 PRINT_ER("driver is null\n");
3396                 return s32Error;
3397         }
3398         memset(&msg, 0, sizeof(struct host_if_msg));
3399
3400
3401         if (pu8RxMic != NULL)
3402                 u8KeyLen += RX_MIC_KEY_LEN;
3403         if (pu8TxMic != NULL)
3404                 u8KeyLen += TX_MIC_KEY_LEN;
3405         if (KeyRSC != NULL) {
3406                 msg.body.key_info.attr.wpa.seq = kmalloc(u32KeyRSClen, GFP_KERNEL);
3407                 memcpy(msg.body.key_info.attr.wpa.seq, KeyRSC, u32KeyRSClen);
3408         }
3409
3410
3411         msg.id = HOST_IF_MSG_KEY;
3412         msg.body.key_info.type = WPARxGtk;
3413         msg.drv = hif_drv;
3414
3415         if (mode == AP_MODE) {
3416                 msg.body.key_info.action = ADDKEY_AP;
3417                 msg.body.key_info.attr.wpa.mode = u8Ciphermode;
3418         }
3419         if (mode == STATION_MODE)
3420                 msg.body.key_info.action = ADDKEY;
3421
3422         msg.body.key_info.attr.wpa.key = kmalloc(u8KeyLen, GFP_KERNEL);
3423         memcpy(msg.body.key_info.attr.wpa.key, pu8RxGtk, u8GtkKeylen);
3424
3425         if (pu8RxMic != NULL) {
3426                 memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
3427         }
3428         if (pu8TxMic != NULL) {
3429                 memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
3430         }
3431
3432         msg.body.key_info.attr.wpa.index = u8KeyIdx;
3433         msg.body.key_info.attr.wpa.key_len = u8KeyLen;
3434         msg.body.key_info.attr.wpa.seq_len = u32KeyRSClen;
3435
3436         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3437         if (s32Error)
3438                 PRINT_ER("Error in sending message queue:  RX GTK\n");
3439
3440         down(&hif_drv->hSemTestKeyBlock);
3441
3442         return s32Error;
3443 }
3444
3445 s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_attr *pu8PmkidInfoArray)
3446 {
3447         s32 s32Error = 0;
3448         struct host_if_msg msg;
3449         u32 i;
3450
3451
3452         if (!hif_drv) {
3453                 s32Error = -EFAULT;
3454                 PRINT_ER("driver is null\n");
3455                 return s32Error;
3456         }
3457
3458         memset(&msg, 0, sizeof(struct host_if_msg));
3459
3460         msg.id = HOST_IF_MSG_KEY;
3461         msg.body.key_info.type = PMKSA;
3462         msg.body.key_info.action = ADDKEY;
3463         msg.drv = hif_drv;
3464
3465         for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) {
3466                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid,
3467                             ETH_ALEN);
3468                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid,
3469                             PMKID_LEN);
3470         }
3471
3472         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3473         if (s32Error)
3474                 PRINT_ER(" Error in sending messagequeue: PMKID Info\n");
3475
3476         return s32Error;
3477 }
3478
3479 s32 host_int_get_pmkid_info(struct host_if_drv *hif_drv,
3480                             u8 *pu8PmkidInfoArray,
3481                             u32 u32PmkidInfoLen)
3482 {
3483         struct wid strWID;
3484
3485         strWID.id = (u16)WID_PMKID_INFO;
3486         strWID.type = WID_STR;
3487         strWID.size = u32PmkidInfoLen;
3488         strWID.val = pu8PmkidInfoArray;
3489
3490         return 0;
3491 }
3492
3493 s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
3494                                          u8 *pu8PassPhrase,
3495                                          u8 u8Psklength)
3496 {
3497         struct wid strWID;
3498
3499         if ((u8Psklength > 7) && (u8Psklength < 65)) {
3500                 strWID.id = (u16)WID_11I_PSK;
3501                 strWID.type = WID_STR;
3502                 strWID.val = pu8PassPhrase;
3503                 strWID.size = u8Psklength;
3504         }
3505
3506         return 0;
3507 }
3508
3509 s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
3510 {
3511         s32 s32Error = 0;
3512         struct host_if_msg msg;
3513
3514         memset(&msg, 0, sizeof(struct host_if_msg));
3515
3516         msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
3517         msg.body.get_mac_info.u8MacAddress = pu8MacAddress;
3518         msg.drv = hif_drv;
3519
3520         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3521         if (s32Error) {
3522                 PRINT_ER("Failed to send get mac address\n");
3523                 return -EFAULT;
3524         }
3525
3526         down(&hWaitResponse);
3527         return s32Error;
3528 }
3529
3530 s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
3531 {
3532         s32 s32Error = 0;
3533         struct host_if_msg msg;
3534
3535         PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]);
3536
3537         memset(&msg, 0, sizeof(struct host_if_msg));
3538         msg.id = HOST_IF_MSG_SET_MAC_ADDRESS;
3539         memcpy(msg.body.set_mac_info.u8MacAddress, pu8MacAddress, ETH_ALEN);
3540         msg.drv = hif_drv;
3541
3542         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3543         if (s32Error)
3544                 PRINT_ER("Failed to send message queue: Set mac address\n");
3545
3546         return s32Error;
3547
3548 }
3549
3550 s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
3551                                          u8 *pu8PassPhrase, u8 u8Psklength)
3552 {
3553         struct wid strWID;
3554
3555         strWID.id = (u16)WID_11I_PSK;
3556         strWID.type = WID_STR;
3557         strWID.size = u8Psklength;
3558         strWID.val = pu8PassPhrase;
3559
3560         return 0;
3561 }
3562
3563 s32 host_int_set_start_scan_req(struct host_if_drv *hif_drv, u8 scanSource)
3564 {
3565         struct wid strWID;
3566
3567         strWID.id = (u16)WID_START_SCAN_REQ;
3568         strWID.type = WID_CHAR;
3569         strWID.val = (s8 *)&scanSource;
3570         strWID.size = sizeof(char);
3571
3572         return 0;
3573 }
3574
3575 s32 host_int_get_start_scan_req(struct host_if_drv *hif_drv, u8 *pu8ScanSource)
3576 {
3577         struct wid strWID;
3578
3579         strWID.id = (u16)WID_START_SCAN_REQ;
3580         strWID.type = WID_CHAR;
3581         strWID.val = (s8 *)pu8ScanSource;
3582         strWID.size = sizeof(char);
3583
3584         return 0;
3585 }
3586
3587 s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid,
3588                           const u8 *pu8ssid, size_t ssidLen,
3589                           const u8 *pu8IEs, size_t IEsLen,
3590                           wilc_connect_result pfConnectResult, void *pvUserArg,
3591                           u8 u8security, enum AUTHTYPE tenuAuth_type,
3592                           u8 u8channel, void *pJoinParams)
3593 {
3594         s32 s32Error = 0;
3595         struct host_if_msg msg;
3596         enum scan_conn_timer enuScanConnTimer;
3597
3598         if (!hif_drv || pfConnectResult == NULL) {
3599                 s32Error = -EFAULT;
3600                 PRINT_ER("Driver is null\n");
3601                 return s32Error;
3602         }
3603
3604         if (!hif_drv) {
3605                 PRINT_ER("Driver is null\n");
3606                 return -EFAULT;
3607         }
3608
3609         if (pJoinParams == NULL) {
3610                 PRINT_ER("Unable to Join - JoinParams is NULL\n");
3611                 return -EFAULT;
3612         }
3613
3614         memset(&msg, 0, sizeof(struct host_if_msg));
3615
3616         msg.id = HOST_IF_MSG_CONNECT;
3617
3618         msg.body.con_info.u8security = u8security;
3619         msg.body.con_info.tenuAuth_type = tenuAuth_type;
3620         msg.body.con_info.u8channel = u8channel;
3621         msg.body.con_info.pfConnectResult = pfConnectResult;
3622         msg.body.con_info.pvUserArg = pvUserArg;
3623         msg.body.con_info.pJoinParams = pJoinParams;
3624         msg.drv = hif_drv ;
3625
3626         if (pu8bssid != NULL) {
3627                 msg.body.con_info.pu8bssid = kmalloc(6, GFP_KERNEL);
3628                 memcpy(msg.body.con_info.pu8bssid,
3629                             pu8bssid, 6);
3630         }
3631
3632         if (pu8ssid != NULL) {
3633                 msg.body.con_info.ssidLen = ssidLen;
3634                 msg.body.con_info.pu8ssid = kmalloc(ssidLen, GFP_KERNEL);
3635                 memcpy(msg.body.con_info.pu8ssid,
3636
3637                             pu8ssid, ssidLen);
3638         }
3639
3640         if (pu8IEs != NULL) {
3641                 msg.body.con_info.IEsLen = IEsLen;
3642                 msg.body.con_info.pu8IEs = kmalloc(IEsLen, GFP_KERNEL);
3643                 memcpy(msg.body.con_info.pu8IEs,
3644                             pu8IEs, IEsLen);
3645         }
3646         if (hif_drv->enuHostIFstate < HOST_IF_CONNECTING)
3647                 hif_drv->enuHostIFstate = HOST_IF_CONNECTING;
3648         else
3649                 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", hif_drv->enuHostIFstate);
3650
3651         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3652         if (s32Error) {
3653                 PRINT_ER("Failed to send message queue: Set join request\n");
3654                 return -EFAULT;
3655         }
3656
3657         enuScanConnTimer = CONNECT_TIMER;
3658         hif_drv->hConnectTimer.data = (unsigned long)hif_drv;
3659         mod_timer(&hif_drv->hConnectTimer,
3660                   jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3661
3662         return s32Error;
3663 }
3664
3665 s32 host_int_flush_join_req(struct host_if_drv *hif_drv)
3666 {
3667         s32 s32Error = 0;
3668         struct host_if_msg msg;
3669
3670         if (!gu8FlushedJoinReq) {
3671                 s32Error = -EFAULT;
3672                 return s32Error;
3673         }
3674
3675
3676         if (!hif_drv) {
3677                 s32Error = -EFAULT;
3678                 PRINT_ER("Driver is null\n");
3679                 return s32Error;
3680         }
3681
3682         msg.id = HOST_IF_MSG_FLUSH_CONNECT;
3683         msg.drv = hif_drv;
3684
3685         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3686         if (s32Error) {
3687                 PRINT_ER("Failed to send message queue: Flush join request\n");
3688                 return -EFAULT;
3689         }
3690
3691         return s32Error;
3692 }
3693
3694 s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode)
3695 {
3696         s32 s32Error = 0;
3697         struct host_if_msg msg;
3698
3699         if (!hif_drv) {
3700                 PRINT_ER("Driver is null\n");
3701                 return -EFAULT;
3702         }
3703
3704         memset(&msg, 0, sizeof(struct host_if_msg));
3705
3706         msg.id = HOST_IF_MSG_DISCONNECT;
3707         msg.drv = hif_drv;
3708
3709         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3710         if (s32Error)
3711                 PRINT_ER("Failed to send message queue: disconnect\n");
3712
3713         down(&hif_drv->hSemTestDisconnectBlock);
3714
3715         return s32Error;
3716 }
3717
3718 s32 host_int_disconnect_station(struct host_if_drv *hif_drv, u8 assoc_id)
3719 {
3720         struct wid strWID;
3721
3722         strWID.id = (u16)WID_DISCONNECT;
3723         strWID.type = WID_CHAR;
3724         strWID.val = (s8 *)&assoc_id;
3725         strWID.size = sizeof(char);
3726
3727         return 0;
3728 }
3729
3730 s32 host_int_get_assoc_req_info(struct host_if_drv *hif_drv, u8 *pu8AssocReqInfo,
3731                                         u32 u32AssocReqInfoLen)
3732 {
3733         struct wid strWID;
3734
3735         strWID.id = (u16)WID_ASSOC_REQ_INFO;
3736         strWID.type = WID_STR;
3737         strWID.val = pu8AssocReqInfo;
3738         strWID.size = u32AssocReqInfoLen;
3739
3740         return 0;
3741 }
3742
3743 s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, u8 *pu8AssocRespInfo,
3744                                         u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
3745 {
3746         s32 s32Error = 0;
3747         struct wid strWID;
3748
3749         if (!hif_drv) {
3750                 PRINT_ER("Driver is null\n");
3751                 return -EFAULT;
3752         }
3753
3754         strWID.id = (u16)WID_ASSOC_RES_INFO;
3755         strWID.type = WID_STR;
3756         strWID.val = pu8AssocRespInfo;
3757         strWID.size = u32MaxAssocRespInfoLen;
3758
3759         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3760                                    get_id_from_handler(hif_drv));
3761         if (s32Error) {
3762                 *pu32RcvdAssocRespInfoLen = 0;
3763                 PRINT_ER("Failed to send association response config packet\n");
3764                 return -EINVAL;
3765         } else {
3766                 *pu32RcvdAssocRespInfoLen = strWID.size;
3767         }
3768
3769         return s32Error;
3770 }
3771
3772 s32 host_int_get_rx_power_level(struct host_if_drv *hif_drv, u8 *pu8RxPowerLevel,
3773                                         u32 u32RxPowerLevelLen)
3774 {
3775         struct wid strWID;
3776
3777         strWID.id = (u16)WID_RX_POWER_LEVEL;
3778         strWID.type = WID_STR;
3779         strWID.val = pu8RxPowerLevel;
3780         strWID.size = u32RxPowerLevelLen;
3781
3782         return 0;
3783 }
3784
3785 int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel)
3786 {
3787         int result;
3788         struct host_if_msg msg;
3789
3790         if (!hif_drv) {
3791                 PRINT_ER("driver is null\n");
3792                 return -EFAULT;
3793         }
3794
3795         memset(&msg, 0, sizeof(struct host_if_msg));
3796         msg.id = HOST_IF_MSG_SET_CHANNEL;
3797         msg.body.channel_info.u8SetChan = channel;
3798         msg.drv = hif_drv;
3799
3800         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3801         if (result) {
3802                 PRINT_ER("wilc mq send fail\n");
3803                 return -EINVAL;
3804         }
3805
3806         return 0;
3807 }
3808
3809 int host_int_wait_msg_queue_idle(void)
3810 {
3811         int result = 0;
3812
3813         struct host_if_msg msg;
3814         memset(&msg, 0, sizeof(struct host_if_msg));
3815         msg.id = HOST_IF_MSG_Q_IDLE;
3816         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3817         if (result) {
3818                 PRINT_ER("wilc mq send fail\n");
3819                 result = -EINVAL;
3820         }
3821
3822         down(&hWaitResponse);
3823
3824         return result;
3825 }
3826
3827 int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv)
3828 {
3829         int result = 0;
3830
3831         struct host_if_msg msg;
3832         memset(&msg, 0, sizeof(struct host_if_msg));
3833         msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
3834         msg.body.drv.u32Address = get_id_from_handler(hif_drv);
3835         msg.drv = hif_drv;
3836
3837         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3838         if (result) {
3839                 PRINT_ER("wilc mq send fail\n");
3840                 result = -EINVAL;
3841         }
3842
3843         return result;
3844 }
3845
3846 int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode)
3847 {
3848         int result = 0;
3849
3850         struct host_if_msg msg;
3851         memset(&msg, 0, sizeof(struct host_if_msg));
3852         msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
3853         msg.body.mode.u32Mode = mode;
3854         msg.drv = hif_drv;
3855
3856         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3857         if (result) {
3858                 PRINT_ER("wilc mq send fail\n");
3859                 result = -EINVAL;
3860         }
3861
3862         return result;
3863 }
3864
3865 s32 host_int_get_host_chnl_num(struct host_if_drv *hif_drv, u8 *pu8ChNo)
3866 {
3867         s32 s32Error = 0;
3868         struct host_if_msg msg;
3869
3870         if (!hif_drv) {
3871                 PRINT_ER("driver is null\n");
3872                 return -EFAULT;
3873         }
3874
3875         memset(&msg, 0, sizeof(struct host_if_msg));
3876
3877         msg.id = HOST_IF_MSG_GET_CHNL;
3878         msg.drv = hif_drv;
3879
3880         s32Error =      wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3881         if (s32Error)
3882                 PRINT_ER("wilc mq send fail\n");
3883         down(&hif_drv->hSemGetCHNL);
3884
3885         *pu8ChNo = gu8Chnl;
3886
3887         return s32Error;
3888
3889
3890 }
3891
3892 s32 host_int_get_inactive_time(struct host_if_drv *hif_drv,
3893                                const u8 *mac, u32 *pu32InactiveTime)
3894 {
3895         s32 s32Error = 0;
3896         struct host_if_msg msg;
3897
3898         if (!hif_drv) {
3899                 PRINT_ER("driver is null\n");
3900                 return -EFAULT;
3901         }
3902
3903         memset(&msg, 0, sizeof(struct host_if_msg));
3904
3905
3906         memcpy(msg.body.mac_info.mac,
3907                     mac, ETH_ALEN);
3908
3909         msg.id = HOST_IF_MSG_GET_INACTIVETIME;
3910         msg.drv = hif_drv;
3911
3912         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3913         if (s32Error)
3914                 PRINT_ER("Failed to send get host channel param's message queue ");
3915
3916         down(&hif_drv->hSemInactiveTime);
3917
3918         *pu32InactiveTime = gu32InactiveTime;
3919
3920         return s32Error;
3921 }
3922
3923 s32 host_int_test_get_int_wid(struct host_if_drv *hif_drv, u32 *pu32TestMemAddr)
3924 {
3925
3926         s32 s32Error = 0;
3927         struct wid strWID;
3928
3929         if (!hif_drv) {
3930                 PRINT_ER("driver is null\n");
3931                 return -EFAULT;
3932         }
3933
3934         strWID.id = (u16)WID_MEMORY_ADDRESS;
3935         strWID.type = WID_INT;
3936         strWID.val = (s8 *)pu32TestMemAddr;
3937         strWID.size = sizeof(u32);
3938
3939         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3940                                    get_id_from_handler(hif_drv));
3941
3942         if (s32Error) {
3943                 PRINT_ER("Failed to get wid value\n");
3944                 return -EINVAL;
3945         } else {
3946                 PRINT_D(HOSTINF_DBG, "Successfully got wid value\n");
3947
3948         }
3949
3950         return s32Error;
3951 }
3952
3953 s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi)
3954 {
3955         s32 s32Error = 0;
3956         struct host_if_msg msg;
3957         memset(&msg, 0, sizeof(struct host_if_msg));
3958
3959         msg.id = HOST_IF_MSG_GET_RSSI;
3960         msg.drv = hif_drv;
3961
3962         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3963         if (s32Error) {
3964                 PRINT_ER("Failed to send get host channel param's message queue ");
3965                 return -EFAULT;
3966         }
3967
3968         down(&hif_drv->hSemGetRSSI);
3969
3970
3971         if (ps8Rssi == NULL) {
3972                 PRINT_ER("RSS pointer value is null");
3973                 return -EFAULT;
3974         }
3975
3976
3977         *ps8Rssi = gs8Rssi;
3978
3979
3980         return s32Error;
3981 }
3982
3983 s32 host_int_get_link_speed(struct host_if_drv *hif_drv, s8 *ps8lnkspd)
3984 {
3985         struct host_if_msg msg;
3986         s32 s32Error = 0;
3987         memset(&msg, 0, sizeof(struct host_if_msg));
3988
3989         msg.id = HOST_IF_MSG_GET_LINKSPEED;
3990         msg.drv = hif_drv;
3991
3992         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3993         if (s32Error) {
3994                 PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
3995                 return -EFAULT;
3996         }
3997
3998         down(&hif_drv->hSemGetLINKSPEED);
3999
4000
4001         if (ps8lnkspd == NULL) {
4002                 PRINT_ER("LINKSPEED pointer value is null");
4003                 return -EFAULT;
4004         }
4005
4006
4007         *ps8lnkspd = gs8lnkspd;
4008
4009
4010         return s32Error;
4011 }
4012
4013 s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
4014 {
4015         s32 s32Error = 0;
4016         struct host_if_msg msg;
4017         memset(&msg, 0, sizeof(struct host_if_msg));
4018
4019         msg.id = HOST_IF_MSG_GET_STATISTICS;
4020         msg.body.data = (char *)pstrStatistics;
4021         msg.drv = hif_drv;
4022
4023         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4024         if (s32Error) {
4025                 PRINT_ER("Failed to send get host channel param's message queue ");
4026                 return -EFAULT;
4027         }
4028
4029         down(&hWaitResponse);
4030         return s32Error;
4031 }
4032
4033 s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource,
4034                   u8 u8ScanType, u8 *pu8ChnlFreqList,
4035                   u8 u8ChnlListLen, const u8 *pu8IEs,
4036                   size_t IEsLen, wilc_scan_result ScanResult,
4037                   void *pvUserArg, struct hidden_network *pstrHiddenNetwork)
4038 {
4039         s32 s32Error = 0;
4040         struct host_if_msg msg;
4041         enum scan_conn_timer enuScanConnTimer;
4042
4043         if (!hif_drv || ScanResult == NULL) {
4044                 PRINT_ER("hif_drv or ScanResult = NULL\n");
4045                 return -EFAULT;
4046         }
4047
4048         memset(&msg, 0, sizeof(struct host_if_msg));
4049
4050         msg.id = HOST_IF_MSG_SCAN;
4051
4052         if (pstrHiddenNetwork != NULL) {
4053                 msg.body.scan_info.hidden_network.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
4054                 msg.body.scan_info.hidden_network.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
4055
4056         } else
4057                 PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n");
4058
4059         msg.drv = hif_drv;
4060         msg.body.scan_info.src = u8ScanSource;
4061         msg.body.scan_info.type = u8ScanType;
4062         msg.body.scan_info.result = ScanResult;
4063         msg.body.scan_info.arg = pvUserArg;
4064
4065         msg.body.scan_info.ch_list_len = u8ChnlListLen;
4066         msg.body.scan_info.ch_freq_list = kmalloc(u8ChnlListLen, GFP_KERNEL);
4067         memcpy(msg.body.scan_info.ch_freq_list, pu8ChnlFreqList, u8ChnlListLen);
4068
4069         msg.body.scan_info.ies_len = IEsLen;
4070         msg.body.scan_info.ies = kmalloc(IEsLen, GFP_KERNEL);
4071         memcpy(msg.body.scan_info.ies, pu8IEs, IEsLen);
4072
4073         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4074         if (s32Error) {
4075                 PRINT_ER("Error in sending message queue\n");
4076                 return -EINVAL;
4077         }
4078
4079         enuScanConnTimer = SCAN_TIMER;
4080         PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
4081         hif_drv->hScanTimer.data = (unsigned long)hif_drv;
4082         mod_timer(&hif_drv->hScanTimer,
4083                   jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
4084
4085         return s32Error;
4086
4087 }
4088
4089 s32 hif_set_cfg(struct host_if_drv *hif_drv,
4090                 struct cfg_param_val *pstrCfgParamVal)
4091 {
4092
4093         s32 s32Error = 0;
4094         struct host_if_msg msg;
4095
4096
4097         if (!hif_drv) {
4098                 PRINT_ER("hif_drv NULL\n");
4099                 return -EFAULT;
4100         }
4101
4102         memset(&msg, 0, sizeof(struct host_if_msg));
4103         msg.id = HOST_IF_MSG_CFG_PARAMS;
4104         msg.body.cfg_info.cfg_attr_info = *pstrCfgParamVal;
4105         msg.drv = hif_drv;
4106
4107         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4108
4109         return s32Error;
4110
4111 }
4112
4113 s32 hif_get_cfg(struct host_if_drv *hif_drv, u16 u16WID, u16 *pu16WID_Value)
4114 {
4115         s32 s32Error = 0;
4116
4117         down(&hif_drv->gtOsCfgValuesSem);
4118
4119         if (!hif_drv) {
4120                 PRINT_ER("hif_drv NULL\n");
4121                 return -EFAULT;
4122         }
4123         PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
4124         switch (u16WID) {
4125
4126         case WID_BSS_TYPE:
4127                 *pu16WID_Value = (u16)hif_drv->strCfgValues.bss_type;
4128                 break;
4129
4130         case WID_AUTH_TYPE:
4131                 *pu16WID_Value = (u16)hif_drv->strCfgValues.auth_type;
4132                 break;
4133
4134         case WID_AUTH_TIMEOUT:
4135                 *pu16WID_Value = hif_drv->strCfgValues.auth_timeout;
4136                 break;
4137
4138         case WID_POWER_MANAGEMENT:
4139                 *pu16WID_Value = (u16)hif_drv->strCfgValues.power_mgmt_mode;
4140                 break;
4141
4142         case WID_SHORT_RETRY_LIMIT:
4143                 *pu16WID_Value =       hif_drv->strCfgValues.short_retry_limit;
4144                 break;
4145
4146         case WID_LONG_RETRY_LIMIT:
4147                 *pu16WID_Value = hif_drv->strCfgValues.long_retry_limit;
4148                 break;
4149
4150         case WID_FRAG_THRESHOLD:
4151                 *pu16WID_Value = hif_drv->strCfgValues.frag_threshold;
4152                 break;
4153
4154         case WID_RTS_THRESHOLD:
4155                 *pu16WID_Value = hif_drv->strCfgValues.rts_threshold;
4156                 break;
4157
4158         case WID_PREAMBLE:
4159                 *pu16WID_Value = (u16)hif_drv->strCfgValues.preamble_type;
4160                 break;
4161
4162         case WID_SHORT_SLOT_ALLOWED:
4163                 *pu16WID_Value = (u16) hif_drv->strCfgValues.short_slot_allowed;
4164                 break;
4165
4166         case WID_11N_TXOP_PROT_DISABLE:
4167                 *pu16WID_Value = (u16)hif_drv->strCfgValues.txop_prot_disabled;
4168                 break;
4169
4170         case WID_BEACON_INTERVAL:
4171                 *pu16WID_Value = hif_drv->strCfgValues.beacon_interval;
4172                 break;
4173
4174         case WID_DTIM_PERIOD:
4175                 *pu16WID_Value = (u16)hif_drv->strCfgValues.dtim_period;
4176                 break;
4177
4178         case WID_SITE_SURVEY:
4179                 *pu16WID_Value = (u16)hif_drv->strCfgValues.site_survey_enabled;
4180                 break;
4181
4182         case WID_SITE_SURVEY_SCAN_TIME:
4183                 *pu16WID_Value = hif_drv->strCfgValues.site_survey_scan_time;
4184                 break;
4185
4186         case WID_ACTIVE_SCAN_TIME:
4187                 *pu16WID_Value = hif_drv->strCfgValues.active_scan_time;
4188                 break;
4189
4190         case WID_PASSIVE_SCAN_TIME:
4191                 *pu16WID_Value = hif_drv->strCfgValues.passive_scan_time;
4192                 break;
4193
4194         case WID_CURRENT_TX_RATE:
4195                 *pu16WID_Value = hif_drv->strCfgValues.curr_tx_rate;
4196                 break;
4197
4198         default:
4199                 break;
4200         }
4201
4202         up(&hif_drv->gtOsCfgValuesSem);
4203
4204         return s32Error;
4205
4206 }
4207
4208 void host_int_send_join_leave_info_to_host
4209         (u16 assocId, u8 *stationAddr, bool joining)
4210 {
4211 }
4212
4213 static void GetPeriodicRSSI(unsigned long arg)
4214 {
4215         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
4216
4217         if (!hif_drv)   {
4218                 PRINT_ER("Driver handler is NULL\n");
4219                 return;
4220         }
4221
4222         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) {
4223                 s32 s32Error = 0;
4224                 struct host_if_msg msg;
4225
4226                 memset(&msg, 0, sizeof(struct host_if_msg));
4227
4228                 msg.id = HOST_IF_MSG_GET_RSSI;
4229                 msg.drv = hif_drv;
4230
4231                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4232                 if (s32Error) {
4233                         PRINT_ER("Failed to send get host channel param's message queue ");
4234                         return;
4235                 }
4236         }
4237         g_hPeriodicRSSI.data = (unsigned long)hif_drv;
4238         mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4239 }
4240
4241
4242 void host_int_send_network_info_to_host
4243         (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi)
4244 {
4245 }
4246
4247 static u32 clients_count;
4248
4249 s32 host_int_init(struct host_if_drv **hif_drv_handler)
4250 {
4251         s32 result = 0;
4252         struct host_if_drv *hif_drv;
4253         int err;
4254
4255         PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
4256
4257         gbScanWhileConnected = false;
4258
4259         sema_init(&hWaitResponse, 0);
4260
4261         hif_drv  = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
4262         if (!hif_drv) {
4263                 result = -ENOMEM;
4264                 goto _fail_;
4265         }
4266         *hif_drv_handler = hif_drv;
4267         err = add_handler_in_list(hif_drv);
4268         if (err) {
4269                 result = -EFAULT;
4270                 goto _fail_timer_2;
4271         }
4272
4273         g_obtainingIP = false;
4274
4275         PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", hif_drv);
4276         if (clients_count == 0) {
4277                 sema_init(&hSemHostIFthrdEnd, 0);
4278                 sema_init(&hSemDeinitDrvHandle, 0);
4279                 sema_init(&hSemHostIntDeinit, 1);
4280         }
4281
4282         sema_init(&hif_drv->hSemTestKeyBlock, 0);
4283         sema_init(&hif_drv->hSemTestDisconnectBlock, 0);
4284         sema_init(&hif_drv->hSemGetRSSI, 0);
4285         sema_init(&hif_drv->hSemGetLINKSPEED, 0);
4286         sema_init(&hif_drv->hSemGetCHNL, 0);
4287         sema_init(&hif_drv->hSemInactiveTime, 0);
4288
4289         PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
4290
4291         if (clients_count == 0) {
4292                 result = wilc_mq_create(&gMsgQHostIF);
4293
4294                 if (result < 0) {
4295                         PRINT_ER("Failed to creat MQ\n");
4296                         goto _fail_;
4297                 }
4298                 HostIFthreadHandler = kthread_run(hostIFthread, NULL, "WILC_kthread");
4299                 if (IS_ERR(HostIFthreadHandler)) {
4300                         PRINT_ER("Failed to creat Thread\n");
4301                         result = -EFAULT;
4302                         goto _fail_mq_;
4303                 }
4304                 setup_timer(&g_hPeriodicRSSI, GetPeriodicRSSI,
4305                             (unsigned long)hif_drv);
4306                 mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4307         }
4308
4309         setup_timer(&hif_drv->hScanTimer, TimerCB_Scan, 0);
4310
4311         setup_timer(&hif_drv->hConnectTimer, TimerCB_Connect, 0);
4312
4313         setup_timer(&hif_drv->hRemainOnChannel, ListenTimerCB, 0);
4314
4315         sema_init(&(hif_drv->gtOsCfgValuesSem), 1);
4316         down(&hif_drv->gtOsCfgValuesSem);
4317
4318         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4319         hif_drv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
4320         hif_drv->strCfgValues.scan_source = DEFAULT_SCAN;
4321         hif_drv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
4322         hif_drv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
4323         hif_drv->strCfgValues.curr_tx_rate = AUTORATE;
4324
4325         hif_drv->u64P2p_MgmtTimeout = 0;
4326
4327         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",
4328
4329                    hif_drv->strCfgValues.site_survey_enabled, hif_drv->strCfgValues.scan_source,
4330                    hif_drv->strCfgValues.active_scan_time, hif_drv->strCfgValues.passive_scan_time,
4331                    hif_drv->strCfgValues.curr_tx_rate);
4332
4333         up(&hif_drv->gtOsCfgValuesSem);
4334
4335         clients_count++;
4336
4337         return result;
4338
4339 _fail_timer_2:
4340         up(&hif_drv->gtOsCfgValuesSem);
4341         del_timer_sync(&hif_drv->hConnectTimer);
4342         del_timer_sync(&hif_drv->hScanTimer);
4343         kthread_stop(HostIFthreadHandler);
4344 _fail_mq_:
4345         wilc_mq_destroy(&gMsgQHostIF);
4346 _fail_:
4347         return result;
4348 }
4349
4350 s32 host_int_deinit(struct host_if_drv *hif_drv)
4351 {
4352         s32 s32Error = 0;
4353         struct host_if_msg msg;
4354         int ret;
4355
4356         if (!hif_drv)   {
4357                 PRINT_ER("hif_drv = NULL\n");
4358                 return 0;
4359         }
4360
4361         down(&hSemHostIntDeinit);
4362
4363         terminated_handle = hif_drv;
4364         PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count);
4365
4366         if (del_timer_sync(&hif_drv->hScanTimer)) {
4367                 PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n");
4368         }
4369
4370         if (del_timer_sync(&hif_drv->hConnectTimer)) {
4371                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4372         }
4373
4374
4375         if (del_timer_sync(&g_hPeriodicRSSI)) {
4376                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4377         }
4378
4379         del_timer_sync(&hif_drv->hRemainOnChannel);
4380
4381         host_int_set_wfi_drv_handler(NULL);
4382         down(&hSemDeinitDrvHandle);
4383
4384         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4385                 hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
4386                                                                 hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
4387
4388                 hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
4389         }
4390
4391         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4392
4393         gbScanWhileConnected = false;
4394
4395         memset(&msg, 0, sizeof(struct host_if_msg));
4396
4397         if (clients_count == 1) {
4398                 if (del_timer_sync(&g_hPeriodicRSSI)) {
4399                         PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4400                 }
4401                 msg.id = HOST_IF_MSG_EXIT;
4402                 msg.drv = hif_drv;
4403
4404
4405                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4406                 if (s32Error != 0)
4407                         PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
4408
4409                 down(&hSemHostIFthrdEnd);
4410
4411                 wilc_mq_destroy(&gMsgQHostIF);
4412         }
4413
4414         down(&(hif_drv->gtOsCfgValuesSem));
4415
4416         ret = remove_handler_in_list(hif_drv);
4417         if (ret)
4418                 s32Error = -ENOENT;
4419
4420         kfree(hif_drv);
4421
4422         clients_count--;
4423         terminated_handle = NULL;
4424         up(&hSemHostIntDeinit);
4425         return s32Error;
4426 }
4427
4428 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
4429 {
4430         s32 s32Error = 0;
4431         struct host_if_msg msg;
4432         int id;
4433         struct host_if_drv *hif_drv = NULL;
4434
4435         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4436         hif_drv = get_handler_from_id(id);
4437
4438
4439
4440
4441         if (!hif_drv || hif_drv == terminated_handle)   {
4442                 PRINT_ER("NetworkInfo received but driver not init[%p]\n", hif_drv);
4443                 return;
4444         }
4445
4446         memset(&msg, 0, sizeof(struct host_if_msg));
4447
4448         msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
4449         msg.drv = hif_drv;
4450
4451         msg.body.net_info.u32Length = u32Length;
4452         msg.body.net_info.pu8Buffer = kmalloc(u32Length, GFP_KERNEL);
4453         memcpy(msg.body.net_info.pu8Buffer,
4454                     pu8Buffer, u32Length);
4455
4456         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4457         if (s32Error)
4458                 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
4459 }
4460
4461 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
4462 {
4463         s32 s32Error = 0;
4464         struct host_if_msg msg;
4465         int id;
4466         struct host_if_drv *hif_drv = NULL;
4467
4468         down(&hSemHostIntDeinit);
4469
4470         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4471         hif_drv = get_handler_from_id(id);
4472         PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
4473
4474
4475         if (!hif_drv || hif_drv == terminated_handle) {
4476                 PRINT_D(HOSTINF_DBG, "Wifi driver handler is equal to NULL\n");
4477                 up(&hSemHostIntDeinit);
4478                 return;
4479         }
4480
4481         if (!hif_drv->strWILC_UsrConnReq.pfUserConnectResult) {
4482                 PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n");
4483                 up(&hSemHostIntDeinit);
4484                 return;
4485         }
4486
4487         memset(&msg, 0, sizeof(struct host_if_msg));
4488
4489
4490         msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
4491         msg.drv = hif_drv;
4492
4493
4494         msg.body.async_info.u32Length = u32Length;
4495         msg.body.async_info.pu8Buffer = kmalloc(u32Length, GFP_KERNEL);
4496         memcpy(msg.body.async_info.pu8Buffer,
4497                     pu8Buffer, u32Length);
4498
4499         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4500         if (s32Error)
4501                 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
4502
4503         up(&hSemHostIntDeinit);
4504 }
4505
4506 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
4507 {
4508         s32 s32Error = 0;
4509         struct host_if_msg msg;
4510         int id;
4511         struct host_if_drv *hif_drv = NULL;
4512
4513         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4514         hif_drv = get_handler_from_id(id);
4515
4516
4517         PRINT_D(GENERIC_DBG, "Scan notification received %p\n", hif_drv);
4518
4519         if (!hif_drv || hif_drv == terminated_handle)
4520                 return;
4521
4522         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4523                 memset(&msg, 0, sizeof(struct host_if_msg));
4524
4525                 msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
4526                 msg.drv = hif_drv;
4527
4528                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4529                 if (s32Error)
4530                         PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
4531         }
4532
4533
4534         return;
4535
4536 }
4537
4538 s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID,
4539                                u32 u32duration, u16 chan,
4540                                wilc_remain_on_chan_expired RemainOnChanExpired,
4541                                wilc_remain_on_chan_ready RemainOnChanReady,
4542                                void *pvUserArg)
4543 {
4544         s32 s32Error = 0;
4545         struct host_if_msg msg;
4546
4547         if (!hif_drv) {
4548                 PRINT_ER("driver is null\n");
4549                 return -EFAULT;
4550         }
4551
4552         memset(&msg, 0, sizeof(struct host_if_msg));
4553
4554         msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
4555         msg.body.remain_on_ch.u16Channel = chan;
4556         msg.body.remain_on_ch.pRemainOnChanExpired = RemainOnChanExpired;
4557         msg.body.remain_on_ch.pRemainOnChanReady = RemainOnChanReady;
4558         msg.body.remain_on_ch.pVoid = pvUserArg;
4559         msg.body.remain_on_ch.u32duration = u32duration;
4560         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4561         msg.drv = hif_drv;
4562
4563         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4564         if (s32Error)
4565                 PRINT_ER("wilc mq send fail\n");
4566
4567         return s32Error;
4568 }
4569
4570 s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID)
4571 {
4572         s32 s32Error = 0;
4573         struct host_if_msg msg;
4574
4575         if (!hif_drv) {
4576                 PRINT_ER("driver is null\n");
4577                 return -EFAULT;
4578         }
4579
4580         del_timer(&hif_drv->hRemainOnChannel);
4581
4582         memset(&msg, 0, sizeof(struct host_if_msg));
4583         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
4584         msg.drv = hif_drv;
4585         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4586
4587         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4588         if (s32Error)
4589                 PRINT_ER("wilc mq send fail\n");
4590
4591         return s32Error;
4592 }
4593
4594 s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool bReg)
4595 {
4596         s32 s32Error = 0;
4597         struct host_if_msg msg;
4598
4599         if (!hif_drv) {
4600                 PRINT_ER("driver is null\n");
4601                 return -EFAULT;
4602         }
4603
4604         memset(&msg, 0, sizeof(struct host_if_msg));
4605
4606         msg.id = HOST_IF_MSG_REGISTER_FRAME;
4607         switch (u16FrameType) {
4608         case ACTION:
4609                 PRINT_D(HOSTINF_DBG, "ACTION\n");
4610                 msg.body.reg_frame.u8Regid = ACTION_FRM_IDX;
4611                 break;
4612
4613         case PROBE_REQ:
4614                 PRINT_D(HOSTINF_DBG, "PROBE REQ\n");
4615                 msg.body.reg_frame.u8Regid = PROBE_REQ_IDX;
4616                 break;
4617
4618         default:
4619                 PRINT_D(HOSTINF_DBG, "Not valid frame type\n");
4620                 break;
4621         }
4622         msg.body.reg_frame.u16FrameType = u16FrameType;
4623         msg.body.reg_frame.bReg = bReg;
4624         msg.drv = hif_drv;
4625
4626         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4627         if (s32Error)
4628                 PRINT_ER("wilc mq send fail\n");
4629
4630         return s32Error;
4631
4632
4633 }
4634
4635 s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
4636                         u32 u32DTIMPeriod, u32 u32HeadLen, u8 *pu8Head,
4637                         u32 u32TailLen, u8 *pu8Tail)
4638 {
4639         s32 s32Error = 0;
4640         struct host_if_msg msg;
4641         struct beacon_attr *pstrSetBeaconParam = &msg.body.beacon_info;
4642
4643         if (!hif_drv) {
4644                 PRINT_ER("driver is null\n");
4645                 return -EFAULT;
4646         }
4647
4648         memset(&msg, 0, sizeof(struct host_if_msg));
4649
4650         PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
4651
4652         msg.id = HOST_IF_MSG_ADD_BEACON;
4653         msg.drv = hif_drv;
4654         pstrSetBeaconParam->u32Interval = u32Interval;
4655         pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
4656         pstrSetBeaconParam->u32HeadLen = u32HeadLen;
4657         pstrSetBeaconParam->pu8Head = kmalloc(u32HeadLen, GFP_KERNEL);
4658         if (pstrSetBeaconParam->pu8Head == NULL) {
4659                 s32Error = -ENOMEM;
4660                 goto ERRORHANDLER;
4661         }
4662         memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
4663         pstrSetBeaconParam->u32TailLen = u32TailLen;
4664
4665         if (u32TailLen > 0) {
4666                 pstrSetBeaconParam->pu8Tail = kmalloc(u32TailLen, GFP_KERNEL);
4667                 if (pstrSetBeaconParam->pu8Tail == NULL) {
4668                         s32Error = -ENOMEM;
4669                         goto ERRORHANDLER;
4670                 }
4671                 memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
4672         } else {
4673                 pstrSetBeaconParam->pu8Tail = NULL;
4674         }
4675
4676         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4677         if (s32Error)
4678                 PRINT_ER("wilc mq send fail\n");
4679
4680 ERRORHANDLER:
4681         if (s32Error) {
4682                 if (pstrSetBeaconParam->pu8Head != NULL)
4683                         kfree(pstrSetBeaconParam->pu8Head);
4684
4685                 if (pstrSetBeaconParam->pu8Tail != NULL)
4686                         kfree(pstrSetBeaconParam->pu8Tail);
4687         }
4688
4689         return s32Error;
4690
4691 }
4692
4693 s32 host_int_del_beacon(struct host_if_drv *hif_drv)
4694 {
4695         s32 s32Error = 0;
4696         struct host_if_msg msg;
4697
4698         if (!hif_drv) {
4699                 PRINT_ER("driver is null\n");
4700                 return -EFAULT;
4701         }
4702
4703         msg.id = HOST_IF_MSG_DEL_BEACON;
4704         msg.drv = hif_drv;
4705         PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
4706
4707         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4708         if (s32Error)
4709                 PRINT_ER("wilc_mq_send fail\n");
4710
4711         return s32Error;
4712 }
4713
4714 s32 host_int_add_station(struct host_if_drv *hif_drv,
4715                          struct add_sta_param *pstrStaParams)
4716 {
4717         s32 s32Error = 0;
4718         struct host_if_msg msg;
4719         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4720
4721
4722         if (!hif_drv) {
4723                 PRINT_ER("driver is null\n");
4724                 return -EFAULT;
4725         }
4726
4727         memset(&msg, 0, sizeof(struct host_if_msg));
4728
4729         PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
4730
4731         msg.id = HOST_IF_MSG_ADD_STATION;
4732         msg.drv = hif_drv;
4733
4734         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4735         if (pstrAddStationMsg->u8NumRates > 0) {
4736                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4737
4738                 if (!rates)
4739                         return -ENOMEM;
4740
4741                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4742                 pstrAddStationMsg->pu8Rates = rates;
4743         }
4744
4745
4746         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4747         if (s32Error)
4748                 PRINT_ER("wilc_mq_send fail\n");
4749         return s32Error;
4750 }
4751
4752 s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr)
4753 {
4754         s32 s32Error = 0;
4755         struct host_if_msg msg;
4756         struct del_sta *pstrDelStationMsg = &msg.body.del_sta_info;
4757
4758         if (!hif_drv) {
4759                 PRINT_ER("driver is null\n");
4760                 return -EFAULT;
4761         }
4762
4763         memset(&msg, 0, sizeof(struct host_if_msg));
4764
4765         PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
4766
4767         msg.id = HOST_IF_MSG_DEL_STATION;
4768         msg.drv = hif_drv;
4769
4770         if (pu8MacAddr == NULL)
4771                 memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN);
4772         else
4773                 memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN);
4774
4775         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4776         if (s32Error)
4777                 PRINT_ER("wilc_mq_send fail\n");
4778         return s32Error;
4779 }
4780
4781 s32 host_int_del_allstation(struct host_if_drv *hif_drv,
4782                             u8 pu8MacAddr[][ETH_ALEN])
4783 {
4784         s32 s32Error = 0;
4785         struct host_if_msg msg;
4786         struct del_all_sta *pstrDelAllStationMsg = &msg.body.del_all_sta_info;
4787         u8 au8Zero_Buff[ETH_ALEN] = {0};
4788         u32 i;
4789         u8 u8AssocNumb = 0;
4790
4791
4792         if (!hif_drv) {
4793                 PRINT_ER("driver is null\n");
4794                 return -EFAULT;
4795         }
4796
4797         memset(&msg, 0, sizeof(struct host_if_msg));
4798
4799         PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
4800
4801         msg.id = HOST_IF_MSG_DEL_ALL_STA;
4802         msg.drv = hif_drv;
4803
4804         for (i = 0; i < MAX_NUM_STA; i++) {
4805                 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
4806                         memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN);
4807                         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],
4808                                 pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]);
4809                         u8AssocNumb++;
4810                 }
4811         }
4812         if (!u8AssocNumb) {
4813                 PRINT_D(CFG80211_DBG, "NO ASSOCIATED STAS\n");
4814                 return s32Error;
4815         }
4816
4817         pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb;
4818         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4819
4820
4821         if (s32Error)
4822                 PRINT_ER("wilc_mq_send fail\n");
4823
4824         down(&hWaitResponse);
4825
4826         return s32Error;
4827
4828 }
4829
4830 s32 host_int_edit_station(struct host_if_drv *hif_drv,
4831                           struct add_sta_param *pstrStaParams)
4832 {
4833         s32 s32Error = 0;
4834         struct host_if_msg msg;
4835         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4836
4837         if (!hif_drv) {
4838                 PRINT_ER("driver is null\n");
4839                 return -EFAULT;
4840         }
4841
4842         PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
4843
4844         memset(&msg, 0, sizeof(struct host_if_msg));
4845
4846         msg.id = HOST_IF_MSG_EDIT_STATION;
4847         msg.drv = hif_drv;
4848
4849         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4850         if (pstrAddStationMsg->u8NumRates > 0) {
4851                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4852
4853                 if (!rates)
4854                         return -ENOMEM;
4855
4856                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4857                 pstrAddStationMsg->pu8Rates = rates;
4858         }
4859
4860         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4861         if (s32Error)
4862                 PRINT_ER("wilc_mq_send fail\n");
4863
4864         return s32Error;
4865 }
4866
4867 s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv,
4868                             bool bIsEnabled,
4869                             u32 u32Timeout)
4870 {
4871         s32 s32Error = 0;
4872         struct host_if_msg msg;
4873         struct power_mgmt_param *pstrPowerMgmtParam = &msg.body.pwr_mgmt_info;
4874
4875         PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled);
4876
4877         if (!hif_drv) {
4878                 PRINT_ER("driver is null\n");
4879                 return -EFAULT;
4880         }
4881
4882         PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
4883
4884         memset(&msg, 0, sizeof(struct host_if_msg));
4885
4886         msg.id = HOST_IF_MSG_POWER_MGMT;
4887         msg.drv = hif_drv;
4888
4889         pstrPowerMgmtParam->bIsEnabled = bIsEnabled;
4890         pstrPowerMgmtParam->u32Timeout = u32Timeout;
4891
4892
4893         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4894         if (s32Error)
4895                 PRINT_ER("wilc_mq_send fail\n");
4896         return s32Error;
4897 }
4898
4899 s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv,
4900                                     bool bIsEnabled,
4901                                     u32 u32count)
4902 {
4903         s32 s32Error = 0;
4904         struct host_if_msg msg;
4905         struct set_multicast *pstrMulticastFilterParam = &msg.body.multicast_info;
4906
4907
4908         if (!hif_drv) {
4909                 PRINT_ER("driver is null\n");
4910                 return -EFAULT;
4911         }
4912
4913         PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
4914
4915         memset(&msg, 0, sizeof(struct host_if_msg));
4916
4917         msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
4918         msg.drv = hif_drv;
4919
4920         pstrMulticastFilterParam->bIsEnabled = bIsEnabled;
4921         pstrMulticastFilterParam->u32count = u32count;
4922
4923         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4924         if (s32Error)
4925                 PRINT_ER("wilc_mq_send fail\n");
4926         return s32Error;
4927 }
4928
4929 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
4930 {
4931         struct join_bss_param *pNewJoinBssParam = NULL;
4932         u8 *pu8IEs;
4933         u16 u16IEsLen;
4934         u16 index = 0;
4935         u8 suppRatesNo = 0;
4936         u8 extSuppRatesNo;
4937         u16 jumpOffset;
4938         u8 pcipherCount;
4939         u8 authCount;
4940         u8 pcipherTotalCount = 0;
4941         u8 authTotalCount = 0;
4942         u8 i, j;
4943
4944         pu8IEs = ptstrNetworkInfo->pu8IEs;
4945         u16IEsLen = ptstrNetworkInfo->u16IEsLen;
4946
4947         pNewJoinBssParam = kmalloc(sizeof(struct join_bss_param), GFP_KERNEL);
4948         if (pNewJoinBssParam != NULL) {
4949                 memset(pNewJoinBssParam, 0, sizeof(struct join_bss_param));
4950                 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
4951                 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
4952                 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
4953                 memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
4954                 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
4955                 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
4956                 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
4957                 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
4958
4959                 while (index < u16IEsLen) {
4960                         if (pu8IEs[index] == SUPP_RATES_IE) {
4961                                 suppRatesNo = pu8IEs[index + 1];
4962                                 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
4963                                 index += 2;
4964
4965                                 for (i = 0; i < suppRatesNo; i++) {
4966                                         pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
4967                                 }
4968                                 index += suppRatesNo;
4969                                 continue;
4970                         } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
4971                                 extSuppRatesNo = pu8IEs[index + 1];
4972                                 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
4973                                         pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
4974                                 else
4975                                         pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
4976                                 index += 2;
4977                                 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++) {
4978                                         pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
4979                                 }
4980                                 index += extSuppRatesNo;
4981                                 continue;
4982                         } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
4983                                 pNewJoinBssParam->ht_capable = true;
4984                                 index += pu8IEs[index + 1] + 2;
4985                                 continue;
4986                         } else if ((pu8IEs[index] == WMM_IE) &&
4987                                    (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
4988                                    (pu8IEs[index + 4] == 0xF2) &&
4989                                    (pu8IEs[index + 5] == 0x02) &&
4990                                    ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
4991                                    (pu8IEs[index + 7] == 0x01)) {
4992                                 pNewJoinBssParam->wmm_cap = true;
4993
4994                                 if (pu8IEs[index + 8] & BIT(7))
4995                                         pNewJoinBssParam->uapsd_cap = true;
4996                                 index += pu8IEs[index + 1] + 2;
4997                                 continue;
4998                         } else if ((pu8IEs[index] == P2P_IE) &&
4999                                  (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
5000                                  (pu8IEs[index + 4] == 0x9a) &&
5001                                  (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
5002                                 u16 u16P2P_count;
5003
5004                                 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
5005                                 pNewJoinBssParam->u8NoaEnbaled = 1;
5006                                 pNewJoinBssParam->u8Index = pu8IEs[index + 9];
5007
5008                                 if (pu8IEs[index + 10] & BIT(7)) {
5009                                         pNewJoinBssParam->u8OppEnable = 1;
5010                                         pNewJoinBssParam->u8CtWindow = pu8IEs[index + 10];
5011                                 } else
5012                                         pNewJoinBssParam->u8OppEnable = 0;
5013
5014                                 PRINT_D(GENERIC_DBG, "P2P Dump\n");
5015                                 for (i = 0; i < pu8IEs[index + 7]; i++)
5016                                         PRINT_D(GENERIC_DBG, " %x\n", pu8IEs[index + 9 + i]);
5017
5018                                 pNewJoinBssParam->u8Count = pu8IEs[index + 11];
5019                                 u16P2P_count = index + 12;
5020
5021                                 memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
5022                                 u16P2P_count += 4;
5023
5024                                 memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
5025                                 u16P2P_count += 4;
5026
5027                                 memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
5028
5029                                 index += pu8IEs[index + 1] + 2;
5030                                 continue;
5031
5032                         } else if ((pu8IEs[index] == RSN_IE) ||
5033                                  ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
5034                                   (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
5035                                   (pu8IEs[index + 5] == 0x01))) {
5036                                 u16 rsnIndex = index;
5037
5038                                 if (pu8IEs[rsnIndex] == RSN_IE) {
5039                                         pNewJoinBssParam->mode_802_11i = 2;
5040                                 } else {
5041                                         if (pNewJoinBssParam->mode_802_11i == 0)
5042                                                 pNewJoinBssParam->mode_802_11i = 1;
5043                                         rsnIndex += 4;
5044                                 }
5045
5046                                 rsnIndex += 7;
5047                                 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
5048                                 rsnIndex++;
5049                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5050                                 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5051                                 rsnIndex += 2;
5052
5053                                 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
5054                                         pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5055                                 }
5056                                 pcipherTotalCount += pcipherCount;
5057                                 rsnIndex += jumpOffset;
5058
5059                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5060
5061                                 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5062                                 rsnIndex += 2;
5063
5064                                 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++) {
5065                                         pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5066                                 }
5067                                 authTotalCount += authCount;
5068                                 rsnIndex += jumpOffset;
5069
5070                                 if (pu8IEs[index] == RSN_IE) {
5071                                         pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
5072                                         pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
5073                                         rsnIndex += 2;
5074                                 }
5075                                 pNewJoinBssParam->rsn_found = true;
5076                                 index += pu8IEs[index + 1] + 2;
5077                                 continue;
5078                         } else
5079                                 index += pu8IEs[index + 1] + 2;
5080
5081                 }
5082
5083
5084         }
5085
5086         return (void *)pNewJoinBssParam;
5087
5088 }
5089
5090 void host_int_freeJoinParams(void *pJoinParams)
5091 {
5092         if ((struct bss_param *)pJoinParams != NULL)
5093                 kfree((struct bss_param *)pJoinParams);
5094         else
5095                 PRINT_ER("Unable to FREE null pointer\n");
5096 }
5097
5098 s32 host_int_delBASession(struct host_if_drv *hif_drv, char *pBSSID, char TID)
5099 {
5100         s32 s32Error = 0;
5101         struct host_if_msg msg;
5102         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5103
5104         if (!hif_drv) {
5105                 PRINT_ER("driver is null\n");
5106                 return -EFAULT;
5107         }
5108
5109         memset(&msg, 0, sizeof(struct host_if_msg));
5110
5111         msg.id = HOST_IF_MSG_DEL_BA_SESSION;
5112
5113         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5114         pBASessionInfo->u8Ted = TID;
5115         msg.drv = hif_drv;
5116
5117         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5118         if (s32Error)
5119                 PRINT_ER("wilc_mq_send fail\n");
5120
5121         down(&hWaitResponse);
5122
5123         return s32Error;
5124 }
5125
5126 s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv,
5127                                   char *pBSSID,
5128                                   char TID)
5129 {
5130         s32 s32Error = 0;
5131         struct host_if_msg msg;
5132         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5133
5134         if (!hif_drv) {
5135                 PRINT_ER("driver is null\n");
5136                 return -EFAULT;
5137         }
5138
5139         memset(&msg, 0, sizeof(struct host_if_msg));
5140
5141         msg.id = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
5142
5143         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5144         pBASessionInfo->u8Ted = TID;
5145         msg.drv = hif_drv;
5146
5147         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5148         if (s32Error)
5149                 PRINT_ER("wilc_mq_send fail\n");
5150
5151         down(&hWaitResponse);
5152
5153         return s32Error;
5154 }
5155
5156 s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5157 {
5158         s32 s32Error = 0;
5159         struct host_if_msg msg;
5160
5161         return 0;
5162
5163         if (!hif_drv) {
5164                 PRINT_ER("driver is null\n");
5165                 return -EFAULT;
5166         }
5167
5168         memset(&msg, 0, sizeof(struct host_if_msg));
5169
5170         msg.id = HOST_IF_MSG_SET_IPADDRESS;
5171
5172         msg.body.ip_info.au8IPAddr = u16ipadd;
5173         msg.drv = hif_drv;
5174         msg.body.ip_info.idx = idx;
5175
5176         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5177         if (s32Error)
5178                 PRINT_ER("wilc_mq_send fail\n");
5179
5180         return s32Error;
5181
5182
5183 }
5184
5185 s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5186 {
5187         s32 s32Error = 0;
5188         struct host_if_msg msg;
5189
5190         if (!hif_drv) {
5191                 PRINT_ER("driver is null\n");
5192                 return -EFAULT;
5193         }
5194
5195         memset(&msg, 0, sizeof(struct host_if_msg));
5196
5197         msg.id = HOST_IF_MSG_GET_IPADDRESS;
5198
5199         msg.body.ip_info.au8IPAddr = u16ipadd;
5200         msg.drv = hif_drv;
5201         msg.body.ip_info.idx = idx;
5202
5203         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5204         if (s32Error)
5205                 PRINT_ER("wilc_mq_send fail\n");
5206
5207         return s32Error;
5208
5209
5210 }