]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/wilc1000/host_interface.c
b450136afbc2bc4cc47b2d04f5fddb2848016ae5
[karo-tx-linux.git] / drivers / staging / wilc1000 / host_interface.c
1 #include <linux/slab.h>
2 #include <linux/time.h>
3 #include <linux/kthread.h>
4 #include <linux/delay.h>
5 #include "host_interface.h"
6 #include "coreconfigurator.h"
7 #include "wilc_wlan_if.h"
8 #include "wilc_msgqueue.h"
9 #include <linux/etherdevice.h>
10
11 extern u8 connecting;
12
13 extern struct timer_list hDuringIpTimer;
14
15 extern u8 g_wilc_initialized;
16
17 #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 *bssid;
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->bssid, 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->bssid != NULL) {
1035                 hif_drv->strWILC_UsrConnReq.pu8bssid = kmalloc(6, GFP_KERNEL);
1036                 memcpy(hif_drv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->bssid, 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->bssid != NULL)
1152                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
1153         pu8CurrByte += 6;
1154
1155         *(pu8CurrByte++)  = (ptstrJoinBssParam->beacon_period) & 0xFF;
1156         *(pu8CurrByte++)  = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
1157         PRINT_D(HOSTINF_DBG, "* Beacon Period %d*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
1158         *(pu8CurrByte++)  =  ptstrJoinBssParam->dtim_period;
1159         PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1)));
1160
1161         memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
1162         pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
1163
1164         *(pu8CurrByte++)  =  ptstrJoinBssParam->wmm_cap;
1165         PRINT_D(HOSTINF_DBG, "* wmm cap%d*\n", (*(pu8CurrByte - 1)));
1166         *(pu8CurrByte++)  = ptstrJoinBssParam->uapsd_cap;
1167
1168         *(pu8CurrByte++)  = ptstrJoinBssParam->ht_capable;
1169         hif_drv->strWILC_UsrConnReq.IsHTCapable = ptstrJoinBssParam->ht_capable;
1170
1171         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_found;
1172         PRINT_D(HOSTINF_DBG, "* rsn found %d*\n", *(pu8CurrByte - 1));
1173         *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_grp_policy;
1174         PRINT_D(HOSTINF_DBG, "* rsn group policy %0x*\n", (*(pu8CurrByte - 1)));
1175         *(pu8CurrByte++) =  ptstrJoinBssParam->mode_802_11i;
1176         PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1)));
1177
1178         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
1179         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
1180
1181         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
1182         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
1183
1184         memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
1185         pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
1186
1187         *(pu8CurrByte++) = REAL_JOIN_REQ;
1188
1189         *(pu8CurrByte++) = ptstrJoinBssParam->u8NoaEnbaled;
1190         if (ptstrJoinBssParam->u8NoaEnbaled) {
1191                 PRINT_D(HOSTINF_DBG, "NOA present\n");
1192
1193                 *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
1194                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 8) & 0xFF;
1195                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
1196                 *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
1197
1198                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Index;
1199
1200                 *(pu8CurrByte++) = ptstrJoinBssParam->u8OppEnable;
1201
1202                 if (ptstrJoinBssParam->u8OppEnable)
1203                         *(pu8CurrByte++) = ptstrJoinBssParam->u8CtWindow;
1204
1205                 *(pu8CurrByte++) = ptstrJoinBssParam->u8Count;
1206
1207                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration));
1208
1209                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration);
1210
1211                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval));
1212
1213                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval);
1214
1215                 memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime));
1216
1217                 pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime);
1218
1219         } else
1220                 PRINT_D(HOSTINF_DBG, "NOA not present\n");
1221
1222         pu8CurrByte = strWIDList[u32WidsCount].val;
1223         u32WidsCount++;
1224         gu32WidConnRstHack = 0;
1225
1226         if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
1227                 memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize);
1228                 gu8FlushedJoinReqDrvHandler = hif_drv;
1229         }
1230
1231         PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
1232
1233         if (pstrHostIFconnectAttr->bssid != NULL) {
1234                 memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->bssid, ETH_ALEN);
1235
1236                 PRINT_D(GENERIC_DBG, "save Bssid = %pM\n", pstrHostIFconnectAttr->bssid);
1237                 PRINT_D(GENERIC_DBG, "save bssid = %pM\n", u8ConnectedSSID);
1238         }
1239
1240         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
1241                                    get_id_from_handler(hif_drv));
1242         if (s32Error) {
1243                 PRINT_ER("failed to send config packet\n");
1244                 s32Error = -EFAULT;
1245                 goto ERRORHANDLER;
1246         } else {
1247                 PRINT_D(GENERIC_DBG, "set HOST_IF_WAITING_CONN_RESP\n");
1248                 hif_drv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
1249         }
1250
1251 ERRORHANDLER:
1252         if (s32Error) {
1253                 tstrConnectInfo strConnectInfo;
1254
1255                 del_timer(&hif_drv->hConnectTimer);
1256
1257                 PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n");
1258
1259                 memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1260
1261                 if (pstrHostIFconnectAttr->pfConnectResult != NULL) {
1262                         if (pstrHostIFconnectAttr->bssid != NULL)
1263                                 memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->bssid, 6);
1264
1265                         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1266                                 strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->IEsLen;
1267                                 strConnectInfo.pu8ReqIEs = kmalloc(pstrHostIFconnectAttr->IEsLen, GFP_KERNEL);
1268                                 memcpy(strConnectInfo.pu8ReqIEs,
1269                                             pstrHostIFconnectAttr->pu8IEs,
1270                                             pstrHostIFconnectAttr->IEsLen);
1271                         }
1272
1273                         pstrHostIFconnectAttr->pfConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1274                                                                &strConnectInfo,
1275                                                                MAC_DISCONNECTED,
1276                                                                NULL,
1277                                                                pstrHostIFconnectAttr->pvUserArg);
1278                         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1279                         if (strConnectInfo.pu8ReqIEs != NULL) {
1280                                 kfree(strConnectInfo.pu8ReqIEs);
1281                                 strConnectInfo.pu8ReqIEs = NULL;
1282                         }
1283
1284                 } else {
1285                         PRINT_ER("Connect callback function pointer is NULL\n");
1286                 }
1287         }
1288
1289         PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n");
1290         if (pstrHostIFconnectAttr->bssid != NULL) {
1291                 kfree(pstrHostIFconnectAttr->bssid);
1292                 pstrHostIFconnectAttr->bssid = NULL;
1293         }
1294
1295         if (pstrHostIFconnectAttr->pu8ssid != NULL) {
1296                 kfree(pstrHostIFconnectAttr->pu8ssid);
1297                 pstrHostIFconnectAttr->pu8ssid = NULL;
1298         }
1299
1300         if (pstrHostIFconnectAttr->pu8IEs != NULL) {
1301                 kfree(pstrHostIFconnectAttr->pu8IEs);
1302                 pstrHostIFconnectAttr->pu8IEs = NULL;
1303         }
1304
1305         if (pu8CurrByte != NULL)
1306                 kfree(pu8CurrByte);
1307         return s32Error;
1308 }
1309
1310 static s32 Handle_FlushConnect(struct host_if_drv *hif_drv)
1311 {
1312         s32 s32Error = 0;
1313         struct wid strWIDList[5];
1314         u32 u32WidsCount = 0;
1315         u8 *pu8CurrByte = NULL;
1316
1317         strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
1318         strWIDList[u32WidsCount].type = WID_BIN_DATA;
1319         strWIDList[u32WidsCount].val = gu8FlushedInfoElemAsoc;
1320         strWIDList[u32WidsCount].size = gu32FlushedInfoElemAsocSize;
1321         u32WidsCount++;
1322
1323         strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
1324         strWIDList[u32WidsCount].type = WID_CHAR;
1325         strWIDList[u32WidsCount].size = sizeof(char);
1326         strWIDList[u32WidsCount].val = (s8 *)(&(gu8Flushed11iMode));
1327         u32WidsCount++;
1328
1329
1330
1331         strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
1332         strWIDList[u32WidsCount].type = WID_CHAR;
1333         strWIDList[u32WidsCount].size = sizeof(char);
1334         strWIDList[u32WidsCount].val = (s8 *)(&gu8FlushedAuthType);
1335         u32WidsCount++;
1336
1337         strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
1338         strWIDList[u32WidsCount].type = WID_STR;
1339         strWIDList[u32WidsCount].size = gu32FlushedJoinReqSize;
1340         strWIDList[u32WidsCount].val = (s8 *)gu8FlushedJoinReq;
1341         pu8CurrByte = strWIDList[u32WidsCount].val;
1342
1343         pu8CurrByte += FLUSHED_BYTE_POS;
1344         *(pu8CurrByte) = FLUSHED_JOIN_REQ;
1345
1346         u32WidsCount++;
1347
1348         s32Error = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
1349                                    get_id_from_handler(gu8FlushedJoinReqDrvHandler));
1350         if (s32Error) {
1351                 PRINT_ER("failed to send config packet\n");
1352                 s32Error = -EINVAL;
1353         }
1354
1355         return s32Error;
1356 }
1357
1358 static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv)
1359 {
1360         s32 s32Error = 0;
1361         tstrConnectInfo strConnectInfo;
1362         struct wid strWID;
1363         u16 u16DummyReasonCode = 0;
1364
1365         if (!hif_drv) {
1366                 PRINT_ER("Driver handler is NULL\n");
1367                 return s32Error;
1368         }
1369
1370         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1371
1372         gbScanWhileConnected = false;
1373
1374
1375         memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1376
1377         if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
1378                 if (hif_drv->strWILC_UsrConnReq.pu8bssid != NULL) {
1379                         memcpy(strConnectInfo.au8bssid,
1380                                     hif_drv->strWILC_UsrConnReq.pu8bssid, 6);
1381                 }
1382
1383                 if (hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
1384                         strConnectInfo.ReqIEsLen = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1385                         strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->strWILC_UsrConnReq.ConnReqIEsLen, GFP_KERNEL);
1386                         memcpy(strConnectInfo.pu8ReqIEs,
1387                                     hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1388                                     hif_drv->strWILC_UsrConnReq.ConnReqIEsLen);
1389                 }
1390
1391                 hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1392                                                                    &strConnectInfo,
1393                                                                    MAC_DISCONNECTED,
1394                                                                    NULL,
1395                                                                    hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1396
1397                 if (strConnectInfo.pu8ReqIEs != NULL) {
1398                         kfree(strConnectInfo.pu8ReqIEs);
1399                         strConnectInfo.pu8ReqIEs = NULL;
1400                 }
1401         } else {
1402                 PRINT_ER("Connect callback function pointer is NULL\n");
1403         }
1404
1405         strWID.id = (u16)WID_DISCONNECT;
1406         strWID.type = WID_CHAR;
1407         strWID.val = (s8 *)&u16DummyReasonCode;
1408         strWID.size = sizeof(char);
1409
1410         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
1411
1412         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1413                                    get_id_from_handler(hif_drv));
1414         if (s32Error)
1415                 PRINT_ER("Failed to send dissconect config packet\n");
1416
1417         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1418         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1419         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1420         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1421         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1422
1423         eth_zero_addr(u8ConnectedSSID);
1424
1425         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1426                 kfree(gu8FlushedJoinReq);
1427                 gu8FlushedJoinReq = NULL;
1428         }
1429         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1430                 kfree(gu8FlushedInfoElemAsoc);
1431                 gu8FlushedInfoElemAsoc = NULL;
1432         }
1433
1434         return s32Error;
1435 }
1436
1437 static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv,
1438                                 struct rcvd_net_info *pstrRcvdNetworkInfo)
1439 {
1440         u32 i;
1441         bool bNewNtwrkFound;
1442
1443
1444
1445         s32 s32Error = 0;
1446         tstrNetworkInfo *pstrNetworkInfo = NULL;
1447         void *pJoinParams = NULL;
1448
1449         bNewNtwrkFound = true;
1450         PRINT_INFO(HOSTINF_DBG, "Handling received network info\n");
1451
1452         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1453                 PRINT_D(HOSTINF_DBG, "State: Scanning, parsing network information received\n");
1454                 parse_network_info(pstrRcvdNetworkInfo->pu8Buffer, &pstrNetworkInfo);
1455                 if ((pstrNetworkInfo == NULL)
1456                     || (hif_drv->strWILC_UsrScanReq.pfUserScanResult == NULL)) {
1457                         PRINT_ER("driver is null\n");
1458                         s32Error = -EINVAL;
1459                         goto done;
1460                 }
1461
1462                 for (i = 0; i < hif_drv->strWILC_UsrScanReq.u32RcvdChCount; i++) {
1463
1464                         if ((hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) &&
1465                             (pstrNetworkInfo->au8bssid != NULL)) {
1466                                 if (memcmp(hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid,
1467                                                 pstrNetworkInfo->au8bssid, 6) == 0) {
1468                                         if (pstrNetworkInfo->s8rssi <= hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) {
1469                                                 PRINT_D(HOSTINF_DBG, "Network previously discovered\n");
1470                                                 goto done;
1471                                         } else {
1472                                                 hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi;
1473                                                 bNewNtwrkFound = false;
1474                                                 break;
1475                                         }
1476                                 }
1477                         }
1478                 }
1479
1480                 if (bNewNtwrkFound == true) {
1481                         PRINT_D(HOSTINF_DBG, "New network found\n");
1482
1483                         if (hif_drv->strWILC_UsrScanReq.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) {
1484                                 hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi;
1485
1486                                 if ((hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL)
1487                                     && (pstrNetworkInfo->au8bssid != NULL)) {
1488                                         memcpy(hif_drv->strWILC_UsrScanReq.astrFoundNetworkInfo[hif_drv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid,
1489                                                     pstrNetworkInfo->au8bssid, 6);
1490
1491                                         hif_drv->strWILC_UsrScanReq.u32RcvdChCount++;
1492
1493                                         pstrNetworkInfo->bNewNetwork = true;
1494                                         pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
1495
1496                                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1497                                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid,
1498                                                                                         pJoinParams);
1499
1500
1501                                 }
1502                         } else {
1503                                 PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit\n");
1504                         }
1505                 } else {
1506                         pstrNetworkInfo->bNewNetwork = false;
1507                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
1508                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
1509                 }
1510         }
1511
1512 done:
1513         if (pstrRcvdNetworkInfo->pu8Buffer != NULL) {
1514                 kfree(pstrRcvdNetworkInfo->pu8Buffer);
1515                 pstrRcvdNetworkInfo->pu8Buffer = NULL;
1516         }
1517
1518         if (pstrNetworkInfo != NULL) {
1519                 DeallocateNetworkInfo(pstrNetworkInfo);
1520                 pstrNetworkInfo = NULL;
1521         }
1522
1523         return s32Error;
1524 }
1525
1526 static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv,
1527                                     struct rcvd_async_info *pstrRcvdGnrlAsyncInfo)
1528 {
1529         s32 s32Error = 0;
1530         u8 u8MsgType = 0;
1531         u8 u8MsgID = 0;
1532         u16 u16MsgLen = 0;
1533         u16 u16WidID = (u16)WID_NIL;
1534         u8 u8WidLen  = 0;
1535         u8 u8MacStatus;
1536         u8 u8MacStatusReasonCode;
1537         u8 u8MacStatusAdditionalInfo;
1538         tstrConnectInfo strConnectInfo;
1539         tstrDisconnectNotifInfo strDisconnectNotifInfo;
1540         s32 s32Err = 0;
1541
1542         if (!hif_drv) {
1543                 PRINT_ER("Driver handler is NULL\n");
1544                 return -ENODEV;
1545         }
1546         PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", hif_drv->enuHostIFstate,
1547                 pstrRcvdGnrlAsyncInfo->pu8Buffer[7]);
1548
1549         if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) ||
1550             (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) ||
1551             hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1552                 if ((pstrRcvdGnrlAsyncInfo->pu8Buffer == NULL) ||
1553                     (hif_drv->strWILC_UsrConnReq.pfUserConnectResult == NULL)) {
1554                         PRINT_ER("driver is null\n");
1555                         return -EINVAL;
1556                 }
1557
1558                 u8MsgType = pstrRcvdGnrlAsyncInfo->pu8Buffer[0];
1559
1560                 if ('I' != u8MsgType) {
1561                         PRINT_ER("Received Message format incorrect.\n");
1562                         return -EFAULT;
1563                 }
1564
1565                 u8MsgID = pstrRcvdGnrlAsyncInfo->pu8Buffer[1];
1566                 u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[2], pstrRcvdGnrlAsyncInfo->pu8Buffer[3]);
1567                 u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[4], pstrRcvdGnrlAsyncInfo->pu8Buffer[5]);
1568                 u8WidLen = pstrRcvdGnrlAsyncInfo->pu8Buffer[6];
1569                 u8MacStatus  = pstrRcvdGnrlAsyncInfo->pu8Buffer[7];
1570                 u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->pu8Buffer[8];
1571                 u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->pu8Buffer[9];
1572                 PRINT_INFO(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Info = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
1573                 if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
1574                         u32 u32RcvdAssocRespInfoLen;
1575                         tstrConnectRespInfo *pstrConnectRespInfo = NULL;
1576
1577                         PRINT_D(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Code = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
1578
1579                         memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
1580
1581                         if (u8MacStatus == MAC_CONNECTED) {
1582                                 memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
1583
1584                                 host_int_get_assoc_res_info(hif_drv,
1585                                                             gapu8RcvdAssocResp,
1586                                                             MAX_ASSOC_RESP_FRAME_SIZE,
1587                                                             &u32RcvdAssocRespInfoLen);
1588
1589                                 PRINT_INFO(HOSTINF_DBG, "Received association response with length = %d\n", u32RcvdAssocRespInfoLen);
1590
1591                                 if (u32RcvdAssocRespInfoLen != 0) {
1592
1593                                         PRINT_D(HOSTINF_DBG, "Parsing association response\n");
1594                                         s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen,
1595                                                                     &pstrConnectRespInfo);
1596                                         if (s32Err) {
1597                                                 PRINT_ER("ParseAssocRespInfo() returned error %d\n", s32Err);
1598                                         } else {
1599                                                 strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus;
1600
1601                                                 if (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
1602                                                         PRINT_INFO(HOSTINF_DBG, "Association response received : Successful connection status\n");
1603                                                         if (pstrConnectRespInfo->pu8RespIEs != NULL) {
1604                                                                 strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen;
1605
1606
1607                                                                 strConnectInfo.pu8RespIEs = kmalloc(pstrConnectRespInfo->u16RespIEsLen, GFP_KERNEL);
1608                                                                 memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs,
1609                                                                             pstrConnectRespInfo->u16RespIEsLen);
1610                                                         }
1611                                                 }
1612
1613                                                 if (pstrConnectRespInfo != NULL) {
1614                                                         DeallocateAssocRespInfo(pstrConnectRespInfo);
1615                                                         pstrConnectRespInfo = NULL;
1616                                                 }
1617                                         }
1618                                 }
1619                         }
1620
1621                         if ((u8MacStatus == MAC_CONNECTED) &&
1622                             (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) {
1623                                 PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
1624                                 eth_zero_addr(u8ConnectedSSID);
1625
1626                         } else if (u8MacStatus == MAC_DISCONNECTED)    {
1627                                 PRINT_ER("Received MAC status is MAC_DISCONNECTED\n");
1628                                 eth_zero_addr(u8ConnectedSSID);
1629                         }
1630
1631                         if (hif_drv->strWILC_UsrConnReq.pu8bssid != NULL) {
1632                                 PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n");
1633                                 memcpy(strConnectInfo.au8bssid, hif_drv->strWILC_UsrConnReq.pu8bssid, 6);
1634
1635                                 if ((u8MacStatus == MAC_CONNECTED) &&
1636                                     (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
1637                                         memcpy(hif_drv->au8AssociatedBSSID,
1638                                                     hif_drv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN);
1639                                 }
1640                         }
1641
1642
1643                         if (hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
1644                                 strConnectInfo.ReqIEsLen = hif_drv->strWILC_UsrConnReq.ConnReqIEsLen;
1645                                 strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->strWILC_UsrConnReq.ConnReqIEsLen, GFP_KERNEL);
1646                                 memcpy(strConnectInfo.pu8ReqIEs,
1647                                             hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs,
1648                                             hif_drv->strWILC_UsrConnReq.ConnReqIEsLen);
1649                         }
1650
1651
1652                         del_timer(&hif_drv->hConnectTimer);
1653                         hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
1654                                                                            &strConnectInfo,
1655                                                                            u8MacStatus,
1656                                                                            NULL,
1657                                                                            hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1658
1659                         if ((u8MacStatus == MAC_CONNECTED) &&
1660                             (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
1661                                 host_int_set_power_mgmt(hif_drv, 0, 0);
1662
1663                                 PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n");
1664                                 hif_drv->enuHostIFstate = HOST_IF_CONNECTED;
1665
1666                                 PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n");
1667                                 g_obtainingIP = true;
1668                                 mod_timer(&hDuringIpTimer,
1669                                           jiffies + msecs_to_jiffies(10000));
1670                         } else {
1671                                 PRINT_D(HOSTINF_DBG, "MAC status : %d and Connect Status : %d\n", u8MacStatus, strConnectInfo.u16ConnectStatus);
1672                                 hif_drv->enuHostIFstate = HOST_IF_IDLE;
1673                                 gbScanWhileConnected = false;
1674                         }
1675
1676                         if (strConnectInfo.pu8RespIEs != NULL) {
1677                                 kfree(strConnectInfo.pu8RespIEs);
1678                                 strConnectInfo.pu8RespIEs = NULL;
1679                         }
1680
1681                         if (strConnectInfo.pu8ReqIEs != NULL) {
1682                                 kfree(strConnectInfo.pu8ReqIEs);
1683                                 strConnectInfo.pu8ReqIEs = NULL;
1684                         }
1685                         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1686                         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1687                         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1688                         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1689                         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1690                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1691                            (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)) {
1692                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n");
1693
1694                         memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
1695
1696                         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
1697                                 PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >>\n\n");
1698                                 del_timer(&hif_drv->hScanTimer);
1699                                 Handle_ScanDone((void *)hif_drv, SCAN_EVENT_ABORTED);
1700                         }
1701
1702                         strDisconnectNotifInfo.u16reason = 0;
1703                         strDisconnectNotifInfo.ie = NULL;
1704                         strDisconnectNotifInfo.ie_len = 0;
1705
1706                         if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
1707                                 g_obtainingIP = false;
1708                                 host_int_set_power_mgmt(hif_drv, 0, 0);
1709
1710                                 hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
1711                                                                                    NULL,
1712                                                                                    0,
1713                                                                                    &strDisconnectNotifInfo,
1714                                                                                    hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
1715
1716                         } else {
1717                                 PRINT_ER("Connect result callback function is NULL\n");
1718                         }
1719
1720                         eth_zero_addr(hif_drv->au8AssociatedBSSID);
1721
1722                         hif_drv->strWILC_UsrConnReq.ssidLen = 0;
1723                         kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
1724                         kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
1725                         hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
1726                         kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
1727
1728                         if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1729                                 kfree(gu8FlushedJoinReq);
1730                                 gu8FlushedJoinReq = NULL;
1731                         }
1732                         if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
1733                                 kfree(gu8FlushedInfoElemAsoc);
1734                                 gu8FlushedInfoElemAsoc = NULL;
1735                         }
1736
1737                         hif_drv->enuHostIFstate = HOST_IF_IDLE;
1738                         gbScanWhileConnected = false;
1739
1740                 } else if ((u8MacStatus == MAC_DISCONNECTED) &&
1741                            (hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL)) {
1742                         PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n");
1743                         PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >>\n\n");
1744
1745                         del_timer(&hif_drv->hScanTimer);
1746                         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult)
1747                                 Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
1748
1749                 }
1750
1751         }
1752
1753         if (pstrRcvdGnrlAsyncInfo->pu8Buffer != NULL) {
1754                 kfree(pstrRcvdGnrlAsyncInfo->pu8Buffer);
1755                 pstrRcvdGnrlAsyncInfo->pu8Buffer = NULL;
1756         }
1757
1758         return s32Error;
1759 }
1760
1761 static int Handle_Key(struct host_if_drv *hif_drv,
1762                       struct key_attr *pstrHostIFkeyAttr)
1763 {
1764         s32 s32Error = 0;
1765         struct wid strWID;
1766         struct wid strWIDList[5];
1767         u8 i;
1768         u8 *pu8keybuf;
1769         s8 s8idxarray[1];
1770         s8 ret = 0;
1771
1772         switch (pstrHostIFkeyAttr->type) {
1773
1774
1775         case WEP:
1776
1777                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1778
1779                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
1780                         PRINT_D(GENERIC_DBG, "ID Hostint is %d\n", (pstrHostIFkeyAttr->attr.wep.index));
1781                         strWIDList[0].id = (u16)WID_11I_MODE;
1782                         strWIDList[0].type = WID_CHAR;
1783                         strWIDList[0].size = sizeof(char);
1784                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.mode));
1785
1786                         strWIDList[1].id = WID_AUTH_TYPE;
1787                         strWIDList[1].type = WID_CHAR;
1788                         strWIDList[1].size = sizeof(char);
1789                         strWIDList[1].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.auth_type));
1790
1791                         strWIDList[2].id = (u16)WID_KEY_ID;
1792                         strWIDList[2].type = WID_CHAR;
1793
1794                         strWIDList[2].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
1795                         strWIDList[2].size = sizeof(char);
1796
1797                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len, GFP_KERNEL);
1798
1799                         if (pu8keybuf == NULL) {
1800                                 PRINT_ER("No buffer to send Key\n");
1801                                 return -1;
1802                         }
1803
1804                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wep.key,
1805                                     pstrHostIFkeyAttr->attr.wep.key_len);
1806
1807                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1808
1809                         strWIDList[3].id = (u16)WID_WEP_KEY_VALUE;
1810                         strWIDList[3].type = WID_STR;
1811                         strWIDList[3].size = pstrHostIFkeyAttr->attr.wep.key_len;
1812                         strWIDList[3].val = (s8 *)pu8keybuf;
1813
1814
1815                         s32Error = send_config_pkt(SET_CFG, strWIDList, 4,
1816                                                    get_id_from_handler(hif_drv));
1817                         kfree(pu8keybuf);
1818
1819
1820                 }
1821
1822                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1823                         PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
1824                         pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL);
1825                         if (pu8keybuf == NULL) {
1826                                 PRINT_ER("No buffer to send Key\n");
1827                                 return -1;
1828                         }
1829                         pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
1830                         memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->attr.wep.key_len, 1);
1831                         memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->attr.wep.key,
1832                                     pstrHostIFkeyAttr->attr.wep.key_len);
1833                         kfree(pstrHostIFkeyAttr->attr.wep.key);
1834
1835                         strWID.id = (u16)WID_ADD_WEP_KEY;
1836                         strWID.type = WID_STR;
1837                         strWID.val = (s8 *)pu8keybuf;
1838                         strWID.size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
1839
1840                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1841                                                    get_id_from_handler(hif_drv));
1842                         kfree(pu8keybuf);
1843                 } else if (pstrHostIFkeyAttr->action & REMOVEKEY) {
1844
1845                         PRINT_D(HOSTINF_DBG, "Removing key\n");
1846                         strWID.id = (u16)WID_REMOVE_WEP_KEY;
1847                         strWID.type = WID_STR;
1848
1849                         s8idxarray[0] = (s8)pstrHostIFkeyAttr->attr.wep.index;
1850                         strWID.val = s8idxarray;
1851                         strWID.size = 1;
1852
1853                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1854                                                    get_id_from_handler(hif_drv));
1855                 } else {
1856                         strWID.id = (u16)WID_KEY_ID;
1857                         strWID.type = WID_CHAR;
1858                         strWID.val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
1859                         strWID.size = sizeof(char);
1860
1861                         PRINT_D(HOSTINF_DBG, "Setting default key index\n");
1862
1863                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1864                                                    get_id_from_handler(hif_drv));
1865                 }
1866                 up(&hif_drv->hSemTestKeyBlock);
1867                 break;
1868
1869         case WPARxGtk:
1870                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1871                         pu8keybuf = kmalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1872                         if (pu8keybuf == NULL) {
1873                                 PRINT_ER("No buffer to send RxGTK Key\n");
1874                                 ret = -1;
1875                                 goto _WPARxGtk_end_case_;
1876                         }
1877
1878                         memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
1879
1880                         if (pstrHostIFkeyAttr->attr.wpa.seq != NULL)
1881                                 memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1882
1883                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1884                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1885                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1886                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1887
1888                         strWIDList[0].id = (u16)WID_11I_MODE;
1889                         strWIDList[0].type = WID_CHAR;
1890                         strWIDList[0].size = sizeof(char);
1891                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wpa.mode));
1892
1893                         strWIDList[1].id = (u16)WID_ADD_RX_GTK;
1894                         strWIDList[1].type = WID_STR;
1895                         strWIDList[1].val = (s8 *)pu8keybuf;
1896                         strWIDList[1].size = RX_MIC_KEY_MSG_LEN;
1897
1898                         s32Error = send_config_pkt(SET_CFG, strWIDList, 2,
1899                                                    get_id_from_handler(hif_drv));
1900
1901                         kfree(pu8keybuf);
1902                         up(&hif_drv->hSemTestKeyBlock);
1903                 }
1904
1905                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1906                         PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n");
1907
1908                         pu8keybuf = kmalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
1909                         if (pu8keybuf == NULL) {
1910                                 PRINT_ER("No buffer to send RxGTK Key\n");
1911                                 ret = -1;
1912                                 goto _WPARxGtk_end_case_;
1913                         }
1914
1915                         memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
1916
1917                         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
1918                                 memcpy(pu8keybuf, hif_drv->au8AssociatedBSSID, ETH_ALEN);
1919                         else
1920                                 PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED\n");
1921
1922                         memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
1923                         memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1924                         memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1925                         memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
1926                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1927
1928                         strWID.id = (u16)WID_ADD_RX_GTK;
1929                         strWID.type = WID_STR;
1930                         strWID.val = (s8 *)pu8keybuf;
1931                         strWID.size = RX_MIC_KEY_MSG_LEN;
1932
1933                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
1934                                                    get_id_from_handler(hif_drv));
1935
1936                         kfree(pu8keybuf);
1937                         up(&hif_drv->hSemTestKeyBlock);
1938                 }
1939 _WPARxGtk_end_case_:
1940                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
1941                 kfree(pstrHostIFkeyAttr->attr.wpa.seq);
1942                 if (ret == -1)
1943                         return ret;
1944
1945                 break;
1946
1947         case WPAPtk:
1948                 if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
1949
1950
1951                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
1952
1953
1954
1955                         if (pu8keybuf == NULL) {
1956                                 PRINT_ER("No buffer to send PTK Key\n");
1957                                 ret = -1;
1958                                 goto _WPAPtk_end_case_;
1959
1960                         }
1961
1962                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1963                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.index, 1);
1964                         memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1965                         memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->attr.wpa.key,
1966                                     pstrHostIFkeyAttr->attr.wpa.key_len);
1967
1968                         strWIDList[0].id = (u16)WID_11I_MODE;
1969                         strWIDList[0].type = WID_CHAR;
1970                         strWIDList[0].size = sizeof(char);
1971                         strWIDList[0].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wpa.mode));
1972
1973                         strWIDList[1].id = (u16)WID_ADD_PTK;
1974                         strWIDList[1].type = WID_STR;
1975                         strWIDList[1].val = (s8 *)pu8keybuf;
1976                         strWIDList[1].size = PTK_KEY_MSG_LEN + 1;
1977
1978                         s32Error = send_config_pkt(SET_CFG, strWIDList, 2,
1979                                                    get_id_from_handler(hif_drv));
1980                         kfree(pu8keybuf);
1981                         up(&hif_drv->hSemTestKeyBlock);
1982                 }
1983                 if (pstrHostIFkeyAttr->action & ADDKEY) {
1984
1985
1986                         pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
1987
1988
1989
1990                         if (pu8keybuf == NULL) {
1991                                 PRINT_ER("No buffer to send PTK Key\n");
1992                                 ret = -1;
1993                                 goto _WPAPtk_end_case_;
1994
1995                         }
1996
1997                         memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
1998                         memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
1999                         memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->attr.wpa.key,
2000                                     pstrHostIFkeyAttr->attr.wpa.key_len);
2001
2002                         strWID.id = (u16)WID_ADD_PTK;
2003                         strWID.type = WID_STR;
2004                         strWID.val = (s8 *)pu8keybuf;
2005                         strWID.size = PTK_KEY_MSG_LEN;
2006
2007                         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2008                                                    get_id_from_handler(hif_drv));
2009                         kfree(pu8keybuf);
2010                         up(&hif_drv->hSemTestKeyBlock);
2011                 }
2012
2013 _WPAPtk_end_case_:
2014                 kfree(pstrHostIFkeyAttr->attr.wpa.key);
2015                 if (ret == -1)
2016                         return ret;
2017
2018                 break;
2019
2020
2021         case PMKSA:
2022
2023                 PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n");
2024
2025                 pu8keybuf = kmalloc((pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1, GFP_KERNEL);
2026                 if (pu8keybuf == NULL) {
2027                         PRINT_ER("No buffer to send PMKSA Key\n");
2028                         return -1;
2029                 }
2030
2031                 pu8keybuf[0] = pstrHostIFkeyAttr->attr.pmkid.numpmkid;
2032
2033                 for (i = 0; i < pstrHostIFkeyAttr->attr.pmkid.numpmkid; i++) {
2034                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
2035                         memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
2036                 }
2037
2038                 strWID.id = (u16)WID_PMKID_INFO;
2039                 strWID.type = WID_STR;
2040                 strWID.val = (s8 *)pu8keybuf;
2041                 strWID.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
2042
2043                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2044                                            get_id_from_handler(hif_drv));
2045
2046                 kfree(pu8keybuf);
2047                 break;
2048         }
2049
2050         if (s32Error)
2051                 PRINT_ER("Failed to send key config packet\n");
2052
2053
2054         return s32Error;
2055 }
2056
2057 static void Handle_Disconnect(struct host_if_drv *hif_drv)
2058 {
2059         struct wid strWID;
2060
2061         s32 s32Error = 0;
2062         u16 u16DummyReasonCode = 0;
2063
2064         strWID.id = (u16)WID_DISCONNECT;
2065         strWID.type = WID_CHAR;
2066         strWID.val = (s8 *)&u16DummyReasonCode;
2067         strWID.size = sizeof(char);
2068
2069
2070
2071         PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
2072
2073         g_obtainingIP = false;
2074         host_int_set_power_mgmt(hif_drv, 0, 0);
2075
2076         eth_zero_addr(u8ConnectedSSID);
2077
2078         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2079                                    get_id_from_handler(hif_drv));
2080
2081         if (s32Error) {
2082                 PRINT_ER("Failed to send dissconect config packet\n");
2083         } else {
2084                 tstrDisconnectNotifInfo strDisconnectNotifInfo;
2085
2086                 memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
2087
2088                 strDisconnectNotifInfo.u16reason = 0;
2089                 strDisconnectNotifInfo.ie = NULL;
2090                 strDisconnectNotifInfo.ie_len = 0;
2091
2092                 if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
2093                         del_timer(&hif_drv->hScanTimer);
2094                         hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
2095                                                                         hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
2096
2097                         hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
2098                 }
2099
2100                 if (hif_drv->strWILC_UsrConnReq.pfUserConnectResult != NULL)    {
2101                         if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2102                                 PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n");
2103                                 del_timer(&hif_drv->hConnectTimer);
2104                         }
2105
2106                         hif_drv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
2107                                                                            0, &strDisconnectNotifInfo, hif_drv->strWILC_UsrConnReq.u32UserConnectPvoid);
2108                 } else {
2109                         PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL\n");
2110                 }
2111
2112                 gbScanWhileConnected = false;
2113
2114                 hif_drv->enuHostIFstate = HOST_IF_IDLE;
2115
2116                 eth_zero_addr(hif_drv->au8AssociatedBSSID);
2117
2118                 hif_drv->strWILC_UsrConnReq.ssidLen = 0;
2119                 kfree(hif_drv->strWILC_UsrConnReq.pu8ssid);
2120                 kfree(hif_drv->strWILC_UsrConnReq.pu8bssid);
2121                 hif_drv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
2122                 kfree(hif_drv->strWILC_UsrConnReq.pu8ConnReqIEs);
2123
2124                 if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
2125                         kfree(gu8FlushedJoinReq);
2126                         gu8FlushedJoinReq = NULL;
2127                 }
2128                 if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == hif_drv) {
2129                         kfree(gu8FlushedInfoElemAsoc);
2130                         gu8FlushedInfoElemAsoc = NULL;
2131                 }
2132
2133         }
2134
2135         up(&hif_drv->hSemTestDisconnectBlock);
2136 }
2137
2138
2139 void resolve_disconnect_aberration(struct host_if_drv *hif_drv)
2140 {
2141         if (!hif_drv)
2142                 return;
2143         if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (hif_drv->enuHostIFstate == HOST_IF_CONNECTING)) {
2144                 PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n");
2145                 host_int_disconnect(hif_drv, 1);
2146         }
2147 }
2148
2149 static s32 Handle_GetChnl(struct host_if_drv *hif_drv)
2150 {
2151
2152         s32 s32Error = 0;
2153         struct wid strWID;
2154
2155         strWID.id = (u16)WID_CURRENT_CHANNEL;
2156         strWID.type = WID_CHAR;
2157         strWID.val = (s8 *)&gu8Chnl;
2158         strWID.size = sizeof(char);
2159
2160         PRINT_D(HOSTINF_DBG, "Getting channel value\n");
2161
2162         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2163                                    get_id_from_handler(hif_drv));
2164
2165         if (s32Error) {
2166                 PRINT_ER("Failed to get channel number\n");
2167                 s32Error = -EFAULT;
2168         }
2169
2170         up(&hif_drv->hSemGetCHNL);
2171
2172         return s32Error;
2173
2174
2175
2176 }
2177
2178 static void Handle_GetRssi(struct host_if_drv *hif_drv)
2179 {
2180         s32 s32Error = 0;
2181         struct wid strWID;
2182
2183         strWID.id = (u16)WID_RSSI;
2184         strWID.type = WID_CHAR;
2185         strWID.val = &gs8Rssi;
2186         strWID.size = sizeof(char);
2187
2188         PRINT_D(HOSTINF_DBG, "Getting RSSI value\n");
2189
2190         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2191                                    get_id_from_handler(hif_drv));
2192         if (s32Error) {
2193                 PRINT_ER("Failed to get RSSI value\n");
2194                 s32Error = -EFAULT;
2195         }
2196
2197         up(&hif_drv->hSemGetRSSI);
2198
2199
2200 }
2201
2202
2203 static void Handle_GetLinkspeed(struct host_if_drv *hif_drv)
2204 {
2205         s32 s32Error = 0;
2206         struct wid strWID;
2207
2208         gs8lnkspd = 0;
2209
2210         strWID.id = (u16)WID_LINKSPEED;
2211         strWID.type = WID_CHAR;
2212         strWID.val = &gs8lnkspd;
2213         strWID.size = sizeof(char);
2214
2215         PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n");
2216
2217         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2218                                    get_id_from_handler(hif_drv));
2219         if (s32Error) {
2220                 PRINT_ER("Failed to get LINKSPEED value\n");
2221                 s32Error = -EFAULT;
2222         }
2223
2224         up(&(hif_drv->hSemGetLINKSPEED));
2225
2226
2227 }
2228
2229 s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
2230 {
2231         struct wid strWIDList[5];
2232         u32 u32WidsCount = 0, s32Error = 0;
2233
2234         strWIDList[u32WidsCount].id = WID_LINKSPEED;
2235         strWIDList[u32WidsCount].type = WID_CHAR;
2236         strWIDList[u32WidsCount].size = sizeof(char);
2237         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u8LinkSpeed));
2238         u32WidsCount++;
2239
2240         strWIDList[u32WidsCount].id = WID_RSSI;
2241         strWIDList[u32WidsCount].type = WID_CHAR;
2242         strWIDList[u32WidsCount].size = sizeof(char);
2243         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->s8RSSI));
2244         u32WidsCount++;
2245
2246         strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
2247         strWIDList[u32WidsCount].type = WID_INT;
2248         strWIDList[u32WidsCount].size = sizeof(u32);
2249         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32TxCount));
2250         u32WidsCount++;
2251
2252         strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
2253         strWIDList[u32WidsCount].type = WID_INT;
2254         strWIDList[u32WidsCount].size = sizeof(u32);
2255         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32RxCount));
2256         u32WidsCount++;
2257
2258         strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
2259         strWIDList[u32WidsCount].type = WID_INT;
2260         strWIDList[u32WidsCount].size = sizeof(u32);
2261         strWIDList[u32WidsCount].val = (s8 *)(&(pstrStatistics->u32TxFailureCount));
2262         u32WidsCount++;
2263
2264         s32Error = send_config_pkt(GET_CFG, strWIDList, u32WidsCount,
2265                                    get_id_from_handler(hif_drv));
2266
2267         if (s32Error)
2268                 PRINT_ER("Failed to send scan paramters config packet\n");
2269
2270         up(&hWaitResponse);
2271         return 0;
2272
2273 }
2274
2275 static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv,
2276                                    struct sta_inactive_t *strHostIfStaInactiveT)
2277 {
2278
2279         s32 s32Error = 0;
2280         u8 *stamac;
2281         struct wid strWID;
2282
2283         strWID.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
2284         strWID.type = WID_STR;
2285         strWID.size = ETH_ALEN;
2286         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2287
2288
2289         stamac = strWID.val;
2290         memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
2291
2292
2293         PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
2294
2295
2296         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2297                                    get_id_from_handler(hif_drv));
2298
2299         if (s32Error) {
2300                 PRINT_ER("Failed to SET incative time\n");
2301                 return -EFAULT;
2302         }
2303
2304
2305         strWID.id = (u16)WID_GET_INACTIVE_TIME;
2306         strWID.type = WID_INT;
2307         strWID.val = (s8 *)&gu32InactiveTime;
2308         strWID.size = sizeof(u32);
2309
2310
2311         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
2312                                    get_id_from_handler(hif_drv));
2313
2314         if (s32Error) {
2315                 PRINT_ER("Failed to get incative time\n");
2316                 return -EFAULT;
2317         }
2318
2319
2320         PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", gu32InactiveTime);
2321
2322         up(&hif_drv->hSemInactiveTime);
2323
2324         return s32Error;
2325
2326
2327
2328 }
2329
2330 static void Handle_AddBeacon(struct host_if_drv *hif_drv,
2331                              struct beacon_attr *pstrSetBeaconParam)
2332 {
2333         s32 s32Error = 0;
2334         struct wid strWID;
2335         u8 *pu8CurrByte;
2336
2337         PRINT_D(HOSTINF_DBG, "Adding BEACON\n");
2338
2339         strWID.id = (u16)WID_ADD_BEACON;
2340         strWID.type = WID_BIN;
2341         strWID.size = pstrSetBeaconParam->u32HeadLen + pstrSetBeaconParam->u32TailLen + 16;
2342         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2343         if (strWID.val == NULL)
2344                 goto ERRORHANDLER;
2345
2346         pu8CurrByte = strWID.val;
2347         *pu8CurrByte++ = (pstrSetBeaconParam->u32Interval & 0xFF);
2348         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 8) & 0xFF);
2349         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 16) & 0xFF);
2350         *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 24) & 0xFF);
2351
2352         *pu8CurrByte++ = (pstrSetBeaconParam->u32DTIMPeriod & 0xFF);
2353         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 8) & 0xFF);
2354         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 16) & 0xFF);
2355         *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 24) & 0xFF);
2356
2357         *pu8CurrByte++ = (pstrSetBeaconParam->u32HeadLen & 0xFF);
2358         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 8) & 0xFF);
2359         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 16) & 0xFF);
2360         *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 24) & 0xFF);
2361
2362         memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Head, pstrSetBeaconParam->u32HeadLen);
2363         pu8CurrByte += pstrSetBeaconParam->u32HeadLen;
2364
2365         *pu8CurrByte++ = (pstrSetBeaconParam->u32TailLen & 0xFF);
2366         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 8) & 0xFF);
2367         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 16) & 0xFF);
2368         *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 24) & 0xFF);
2369
2370         if (pstrSetBeaconParam->pu8Tail > 0)
2371                 memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Tail, pstrSetBeaconParam->u32TailLen);
2372         pu8CurrByte += pstrSetBeaconParam->u32TailLen;
2373
2374         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2375                                    get_id_from_handler(hif_drv));
2376         if (s32Error)
2377                 PRINT_ER("Failed to send add beacon config packet\n");
2378
2379 ERRORHANDLER:
2380         kfree(strWID.val);
2381         kfree(pstrSetBeaconParam->pu8Head);
2382         kfree(pstrSetBeaconParam->pu8Tail);
2383 }
2384
2385 static void Handle_DelBeacon(struct host_if_drv *hif_drv)
2386 {
2387         s32 s32Error = 0;
2388         struct wid strWID;
2389         u8 *pu8CurrByte;
2390
2391         strWID.id = (u16)WID_DEL_BEACON;
2392         strWID.type = WID_CHAR;
2393         strWID.size = sizeof(char);
2394         strWID.val = &gu8DelBcn;
2395
2396         if (strWID.val == NULL)
2397                 return;
2398
2399         pu8CurrByte = strWID.val;
2400
2401         PRINT_D(HOSTINF_DBG, "Deleting BEACON\n");
2402
2403         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2404                                    get_id_from_handler(hif_drv));
2405         if (s32Error)
2406                 PRINT_ER("Failed to send delete beacon config packet\n");
2407 }
2408
2409 static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer,
2410                                     struct add_sta_param *pstrStationParam)
2411 {
2412         u8 *pu8CurrByte;
2413
2414         pu8CurrByte = pu8Buffer;
2415
2416         PRINT_D(HOSTINF_DBG, "Packing STA params\n");
2417         memcpy(pu8CurrByte, pstrStationParam->au8BSSID, ETH_ALEN);
2418         pu8CurrByte +=  ETH_ALEN;
2419
2420         *pu8CurrByte++ = pstrStationParam->u16AssocID & 0xFF;
2421         *pu8CurrByte++ = (pstrStationParam->u16AssocID >> 8) & 0xFF;
2422
2423         *pu8CurrByte++ = pstrStationParam->u8NumRates;
2424         if (pstrStationParam->u8NumRates > 0)
2425                 memcpy(pu8CurrByte, pstrStationParam->pu8Rates, pstrStationParam->u8NumRates);
2426         pu8CurrByte += pstrStationParam->u8NumRates;
2427
2428         *pu8CurrByte++ = pstrStationParam->bIsHTSupported;
2429         *pu8CurrByte++ = pstrStationParam->u16HTCapInfo & 0xFF;
2430         *pu8CurrByte++ = (pstrStationParam->u16HTCapInfo >> 8) & 0xFF;
2431
2432         *pu8CurrByte++ = pstrStationParam->u8AmpduParams;
2433         memcpy(pu8CurrByte, pstrStationParam->au8SuppMCsSet, WILC_SUPP_MCS_SET_SIZE);
2434         pu8CurrByte += WILC_SUPP_MCS_SET_SIZE;
2435
2436         *pu8CurrByte++ = pstrStationParam->u16HTExtParams & 0xFF;
2437         *pu8CurrByte++ = (pstrStationParam->u16HTExtParams >> 8) & 0xFF;
2438
2439         *pu8CurrByte++ = pstrStationParam->u32TxBeamformingCap & 0xFF;
2440         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 8) & 0xFF;
2441         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 16) & 0xFF;
2442         *pu8CurrByte++ = (pstrStationParam->u32TxBeamformingCap >> 24) & 0xFF;
2443
2444         *pu8CurrByte++ = pstrStationParam->u8ASELCap;
2445
2446         *pu8CurrByte++ = pstrStationParam->u16FlagsMask & 0xFF;
2447         *pu8CurrByte++ = (pstrStationParam->u16FlagsMask >> 8) & 0xFF;
2448
2449         *pu8CurrByte++ = pstrStationParam->u16FlagsSet & 0xFF;
2450         *pu8CurrByte++ = (pstrStationParam->u16FlagsSet >> 8) & 0xFF;
2451
2452         return pu8CurrByte - pu8Buffer;
2453 }
2454
2455 static void Handle_AddStation(struct host_if_drv *hif_drv,
2456                               struct add_sta_param *pstrStationParam)
2457 {
2458         s32 s32Error = 0;
2459         struct wid strWID;
2460         u8 *pu8CurrByte;
2461
2462         PRINT_D(HOSTINF_DBG, "Handling add station\n");
2463         strWID.id = (u16)WID_ADD_STA;
2464         strWID.type = WID_BIN;
2465         strWID.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
2466
2467         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2468         if (strWID.val == NULL)
2469                 goto ERRORHANDLER;
2470
2471         pu8CurrByte = strWID.val;
2472         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2473
2474         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2475                                    get_id_from_handler(hif_drv));
2476         if (s32Error != 0)
2477                 PRINT_ER("Failed to send add station config packet\n");
2478
2479 ERRORHANDLER:
2480         kfree(pstrStationParam->pu8Rates);
2481         kfree(strWID.val);
2482 }
2483
2484 static void Handle_DelAllSta(struct host_if_drv *hif_drv,
2485                              struct del_all_sta *pstrDelAllStaParam)
2486 {
2487         s32 s32Error = 0;
2488
2489         struct wid strWID;
2490         u8 *pu8CurrByte;
2491         u8 i;
2492         u8 au8Zero_Buff[6] = {0};
2493
2494         strWID.id = (u16)WID_DEL_ALL_STA;
2495         strWID.type = WID_STR;
2496         strWID.size = (pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1;
2497
2498         PRINT_D(HOSTINF_DBG, "Handling delete station\n");
2499
2500         strWID.val = kmalloc((pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1, GFP_KERNEL);
2501         if (strWID.val == NULL)
2502                 goto ERRORHANDLER;
2503
2504         pu8CurrByte = strWID.val;
2505
2506         *(pu8CurrByte++) = pstrDelAllStaParam->u8Num_AssocSta;
2507
2508         for (i = 0; i < MAX_NUM_STA; i++) {
2509                 if (memcmp(pstrDelAllStaParam->au8Sta_DelAllSta[i], au8Zero_Buff, ETH_ALEN))
2510                         memcpy(pu8CurrByte, pstrDelAllStaParam->au8Sta_DelAllSta[i], ETH_ALEN);
2511                 else
2512                         continue;
2513
2514                 pu8CurrByte += ETH_ALEN;
2515         }
2516
2517         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2518                                    get_id_from_handler(hif_drv));
2519         if (s32Error)
2520                 PRINT_ER("Failed to send add station config packet\n");
2521
2522 ERRORHANDLER:
2523         kfree(strWID.val);
2524
2525         up(&hWaitResponse);
2526 }
2527
2528 static void Handle_DelStation(struct host_if_drv *hif_drv,
2529                               struct del_sta *pstrDelStaParam)
2530 {
2531         s32 s32Error = 0;
2532         struct wid strWID;
2533         u8 *pu8CurrByte;
2534
2535         strWID.id = (u16)WID_REMOVE_STA;
2536         strWID.type = WID_BIN;
2537         strWID.size = ETH_ALEN;
2538
2539         PRINT_D(HOSTINF_DBG, "Handling delete station\n");
2540
2541         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2542         if (strWID.val == NULL)
2543                 goto ERRORHANDLER;
2544
2545         pu8CurrByte = strWID.val;
2546
2547         memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN);
2548
2549         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2550                                    get_id_from_handler(hif_drv));
2551         if (s32Error)
2552                 PRINT_ER("Failed to send add station config packet\n");
2553
2554 ERRORHANDLER:
2555         kfree(strWID.val);
2556 }
2557
2558 static void Handle_EditStation(struct host_if_drv *hif_drv,
2559                                struct add_sta_param *pstrStationParam)
2560 {
2561         s32 s32Error = 0;
2562         struct wid strWID;
2563         u8 *pu8CurrByte;
2564
2565         strWID.id = (u16)WID_EDIT_STA;
2566         strWID.type = WID_BIN;
2567         strWID.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
2568
2569         PRINT_D(HOSTINF_DBG, "Handling edit station\n");
2570         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2571         if (strWID.val == NULL)
2572                 goto ERRORHANDLER;
2573
2574         pu8CurrByte = strWID.val;
2575         pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
2576
2577         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2578                                    get_id_from_handler(hif_drv));
2579         if (s32Error)
2580                 PRINT_ER("Failed to send edit station config packet\n");
2581
2582 ERRORHANDLER:
2583         kfree(pstrStationParam->pu8Rates);
2584         kfree(strWID.val);
2585 }
2586
2587 static int Handle_RemainOnChan(struct host_if_drv *hif_drv,
2588                                struct remain_ch *pstrHostIfRemainOnChan)
2589 {
2590         s32 s32Error = 0;
2591         u8 u8remain_on_chan_flag;
2592         struct wid strWID;
2593
2594         if (!hif_drv->u8RemainOnChan_pendingreq) {
2595                 hif_drv->strHostIfRemainOnChan.pVoid = pstrHostIfRemainOnChan->pVoid;
2596                 hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired;
2597                 hif_drv->strHostIfRemainOnChan.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady;
2598                 hif_drv->strHostIfRemainOnChan.u16Channel = pstrHostIfRemainOnChan->u16Channel;
2599                 hif_drv->strHostIfRemainOnChan.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID;
2600         } else {
2601                 pstrHostIfRemainOnChan->u16Channel = hif_drv->strHostIfRemainOnChan.u16Channel;
2602         }
2603
2604         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
2605                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while scanning return\n");
2606                 hif_drv->u8RemainOnChan_pendingreq = 1;
2607                 s32Error = -EBUSY;
2608                 goto ERRORHANDLER;
2609         }
2610         if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
2611                 PRINT_INFO(GENERIC_DBG, "Required to remain on chan while connecting return\n");
2612                 s32Error = -EBUSY;
2613                 goto ERRORHANDLER;
2614         }
2615
2616         if (g_obtainingIP || connecting) {
2617                 PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
2618                 s32Error = -EBUSY;
2619                 goto ERRORHANDLER;
2620         }
2621
2622         PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", pstrHostIfRemainOnChan->u16Channel);
2623
2624         u8remain_on_chan_flag = true;
2625         strWID.id = (u16)WID_REMAIN_ON_CHAN;
2626         strWID.type = WID_STR;
2627         strWID.size = 2;
2628         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2629
2630         if (strWID.val == NULL) {
2631                 s32Error = -ENOMEM;
2632                 goto ERRORHANDLER;
2633         }
2634
2635         strWID.val[0] = u8remain_on_chan_flag;
2636         strWID.val[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
2637
2638         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2639                                    get_id_from_handler(hif_drv));
2640         if (s32Error != 0)
2641                 PRINT_ER("Failed to set remain on channel\n");
2642
2643 ERRORHANDLER:
2644         {
2645                 P2P_LISTEN_STATE = 1;
2646                 hif_drv->hRemainOnChannel.data = (unsigned long)hif_drv;
2647                 mod_timer(&hif_drv->hRemainOnChannel,
2648                           jiffies +
2649                           msecs_to_jiffies(pstrHostIfRemainOnChan->u32duration));
2650
2651                 if (hif_drv->strHostIfRemainOnChan.pRemainOnChanReady)
2652                         hif_drv->strHostIfRemainOnChan.pRemainOnChanReady(hif_drv->strHostIfRemainOnChan.pVoid);
2653
2654                 if (hif_drv->u8RemainOnChan_pendingreq)
2655                         hif_drv->u8RemainOnChan_pendingreq = 0;
2656         }
2657         return s32Error;
2658 }
2659
2660 static int Handle_RegisterFrame(struct host_if_drv *hif_drv,
2661                                 struct reg_frame *pstrHostIfRegisterFrame)
2662 {
2663         s32 s32Error = 0;
2664         struct wid strWID;
2665         u8 *pu8CurrByte;
2666
2667         PRINT_D(HOSTINF_DBG, "Handling frame register Flag : %d FrameType: %d\n", pstrHostIfRegisterFrame->bReg, pstrHostIfRegisterFrame->u16FrameType);
2668
2669         strWID.id = (u16)WID_REGISTER_FRAME;
2670         strWID.type = WID_STR;
2671         strWID.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
2672         if (strWID.val == NULL)
2673                 return -ENOMEM;
2674
2675         pu8CurrByte = strWID.val;
2676
2677         *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg;
2678         *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid;
2679         memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16));
2680
2681
2682         strWID.size = sizeof(u16) + 2;
2683
2684         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2685                                    get_id_from_handler(hif_drv));
2686         if (s32Error) {
2687                 PRINT_ER("Failed to frame register config packet\n");
2688                 s32Error = -EINVAL;
2689         }
2690
2691         return s32Error;
2692
2693 }
2694
2695 #define FALSE_FRMWR_CHANNEL 100
2696 static u32 Handle_ListenStateExpired(struct host_if_drv *hif_drv,
2697                                      struct remain_ch *pstrHostIfRemainOnChan)
2698 {
2699         u8 u8remain_on_chan_flag;
2700         struct wid strWID;
2701         s32 s32Error = 0;
2702
2703         PRINT_D(HOSTINF_DBG, "CANCEL REMAIN ON CHAN\n");
2704
2705         if (P2P_LISTEN_STATE) {
2706                 u8remain_on_chan_flag = false;
2707                 strWID.id = (u16)WID_REMAIN_ON_CHAN;
2708                 strWID.type = WID_STR;
2709                 strWID.size = 2;
2710                 strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2711
2712                 if (strWID.val == NULL)
2713                         PRINT_ER("Failed to allocate memory\n");
2714
2715                 strWID.val[0] = u8remain_on_chan_flag;
2716                 strWID.val[1] = FALSE_FRMWR_CHANNEL;
2717
2718                 s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2719                                            get_id_from_handler(hif_drv));
2720                 if (s32Error != 0) {
2721                         PRINT_ER("Failed to set remain on channel\n");
2722                         goto _done_;
2723                 }
2724
2725                 if (hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired) {
2726                         hif_drv->strHostIfRemainOnChan.pRemainOnChanExpired(hif_drv->strHostIfRemainOnChan.pVoid
2727                                                                                , pstrHostIfRemainOnChan->u32ListenSessionID);
2728                 }
2729                 P2P_LISTEN_STATE = 0;
2730         } else {
2731                 PRINT_D(GENERIC_DBG, "Not in listen state\n");
2732                 s32Error = -EFAULT;
2733         }
2734
2735 _done_:
2736         return s32Error;
2737 }
2738
2739 static void ListenTimerCB(unsigned long arg)
2740 {
2741         s32 s32Error = 0;
2742         struct host_if_msg msg;
2743         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
2744
2745         del_timer(&hif_drv->hRemainOnChannel);
2746
2747         memset(&msg, 0, sizeof(struct host_if_msg));
2748         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
2749         msg.drv = hif_drv;
2750         msg.body.remain_on_ch.u32ListenSessionID = hif_drv->strHostIfRemainOnChan.u32ListenSessionID;
2751
2752         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2753         if (s32Error)
2754                 PRINT_ER("wilc_mq_send fail\n");
2755 }
2756
2757 static void Handle_PowerManagement(struct host_if_drv *hif_drv,
2758                                    struct power_mgmt_param *strPowerMgmtParam)
2759 {
2760         s32 s32Error = 0;
2761         struct wid strWID;
2762         s8 s8PowerMode;
2763
2764         strWID.id = (u16)WID_POWER_MANAGEMENT;
2765
2766         if (strPowerMgmtParam->bIsEnabled == true)
2767                 s8PowerMode = MIN_FAST_PS;
2768         else
2769                 s8PowerMode = NO_POWERSAVE;
2770         PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode);
2771         strWID.val = &s8PowerMode;
2772         strWID.size = sizeof(char);
2773
2774         PRINT_D(HOSTINF_DBG, "Handling Power Management\n");
2775
2776         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2777                                    get_id_from_handler(hif_drv));
2778         if (s32Error)
2779                 PRINT_ER("Failed to send power management config packet\n");
2780 }
2781
2782 static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv,
2783                                       struct set_multicast *strHostIfSetMulti)
2784 {
2785         s32 s32Error = 0;
2786         struct wid strWID;
2787         u8 *pu8CurrByte;
2788
2789         PRINT_D(HOSTINF_DBG, "Setup Multicast Filter\n");
2790
2791         strWID.id = (u16)WID_SETUP_MULTICAST_FILTER;
2792         strWID.type = WID_BIN;
2793         strWID.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->u32count) * ETH_ALEN);
2794         strWID.val = kmalloc(strWID.size, GFP_KERNEL);
2795         if (strWID.val == NULL)
2796                 goto ERRORHANDLER;
2797
2798         pu8CurrByte = strWID.val;
2799         *pu8CurrByte++ = (strHostIfSetMulti->bIsEnabled & 0xFF);
2800         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 8) & 0xFF);
2801         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 16) & 0xFF);
2802         *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 24) & 0xFF);
2803
2804         *pu8CurrByte++ = (strHostIfSetMulti->u32count & 0xFF);
2805         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 8) & 0xFF);
2806         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 16) & 0xFF);
2807         *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 24) & 0xFF);
2808
2809         if ((strHostIfSetMulti->u32count) > 0)
2810                 memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->u32count) * ETH_ALEN));
2811
2812         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2813                                    get_id_from_handler(hif_drv));
2814         if (s32Error)
2815                 PRINT_ER("Failed to send setup multicast config packet\n");
2816
2817 ERRORHANDLER:
2818         kfree(strWID.val);
2819
2820 }
2821
2822 static s32 Handle_AddBASession(struct host_if_drv *hif_drv,
2823                                struct ba_session_info *strHostIfBASessionInfo)
2824 {
2825         s32 s32Error = 0;
2826         struct wid strWID;
2827         int AddbaTimeout = 100;
2828         char *ptr = NULL;
2829
2830         PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\nBufferSize == %d\nSessionTimeOut = %d\n",
2831                 strHostIfBASessionInfo->au8Bssid[0],
2832                 strHostIfBASessionInfo->au8Bssid[1],
2833                 strHostIfBASessionInfo->au8Bssid[2],
2834                 strHostIfBASessionInfo->u16BufferSize,
2835                 strHostIfBASessionInfo->u16SessionTimeout,
2836                 strHostIfBASessionInfo->u8Ted);
2837
2838         strWID.id = (u16)WID_11E_P_ACTION_REQ;
2839         strWID.type = WID_STR;
2840         strWID.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
2841         strWID.size = BLOCK_ACK_REQ_SIZE;
2842         ptr = strWID.val;
2843         *ptr++ = 0x14;
2844         *ptr++ = 0x3;
2845         *ptr++ = 0x0;
2846         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2847         ptr += ETH_ALEN;
2848         *ptr++ = strHostIfBASessionInfo->u8Ted;
2849         *ptr++ = 1;
2850         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
2851         *ptr++ = ((strHostIfBASessionInfo->u16BufferSize >> 16) & 0xFF);
2852         *ptr++ = (strHostIfBASessionInfo->u16SessionTimeout & 0xFF);
2853         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
2854         *ptr++ = (AddbaTimeout & 0xFF);
2855         *ptr++ = ((AddbaTimeout >> 16) & 0xFF);
2856         *ptr++ = 8;
2857         *ptr++ = 0;
2858
2859         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2860                                    get_id_from_handler(hif_drv));
2861         if (s32Error)
2862                 PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n");
2863
2864
2865         strWID.id = (u16)WID_11E_P_ACTION_REQ;
2866         strWID.type = WID_STR;
2867         strWID.size = 15;
2868         ptr = strWID.val;
2869         *ptr++ = 15;
2870         *ptr++ = 7;
2871         *ptr++ = 0x2;
2872         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2873         ptr += ETH_ALEN;
2874         *ptr++ = strHostIfBASessionInfo->u8Ted;
2875         *ptr++ = 8;
2876         *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
2877         *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
2878         *ptr++ = 3;
2879         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2880                                    get_id_from_handler(hif_drv));
2881
2882         if (strWID.val != NULL)
2883                 kfree(strWID.val);
2884
2885         return s32Error;
2886
2887 }
2888
2889 static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv,
2890                                      struct ba_session_info *strHostIfBASessionInfo)
2891 {
2892         s32 s32Error = 0;
2893         struct wid strWID;
2894         char *ptr = NULL;
2895
2896         PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
2897                 strHostIfBASessionInfo->au8Bssid[0],
2898                 strHostIfBASessionInfo->au8Bssid[1],
2899                 strHostIfBASessionInfo->au8Bssid[2],
2900                 strHostIfBASessionInfo->u8Ted);
2901
2902         strWID.id = (u16)WID_DEL_ALL_RX_BA;
2903         strWID.type = WID_STR;
2904         strWID.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
2905         strWID.size = BLOCK_ACK_REQ_SIZE;
2906         ptr = strWID.val;
2907         *ptr++ = 0x14;
2908         *ptr++ = 0x3;
2909         *ptr++ = 0x2;
2910         memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
2911         ptr += ETH_ALEN;
2912         *ptr++ = strHostIfBASessionInfo->u8Ted;
2913         *ptr++ = 0;
2914         *ptr++ = 32;
2915
2916         s32Error = send_config_pkt(SET_CFG, &strWID, 1,
2917                                    get_id_from_handler(hif_drv));
2918         if (s32Error)
2919                 PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
2920
2921
2922         if (strWID.val != NULL)
2923                 kfree(strWID.val);
2924
2925         up(&hWaitResponse);
2926
2927         return s32Error;
2928
2929 }
2930
2931 static int hostIFthread(void *pvArg)
2932 {
2933         u32 u32Ret;
2934         struct host_if_msg msg;
2935         struct host_if_drv *hif_drv;
2936
2937         memset(&msg, 0, sizeof(struct host_if_msg));
2938
2939         while (1) {
2940                 wilc_mq_recv(&gMsgQHostIF, &msg, sizeof(struct host_if_msg), &u32Ret);
2941                 hif_drv = (struct host_if_drv *)msg.drv;
2942                 if (msg.id == HOST_IF_MSG_EXIT) {
2943                         PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n");
2944                         break;
2945                 }
2946
2947                 if ((!g_wilc_initialized)) {
2948                         PRINT_D(GENERIC_DBG, "--WAIT--");
2949                         usleep_range(200 * 1000, 200 * 1000);
2950                         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2951                         continue;
2952                 }
2953
2954                 if (msg.id == HOST_IF_MSG_CONNECT && hif_drv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
2955                         PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n");
2956                         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
2957                         usleep_range(2 * 1000, 2 * 1000);
2958                         continue;
2959                 }
2960
2961                 switch (msg.id) {
2962                 case HOST_IF_MSG_Q_IDLE:
2963                         Handle_wait_msg_q_empty();
2964                         break;
2965
2966                 case HOST_IF_MSG_SCAN:
2967                         Handle_Scan(msg.drv, &msg.body.scan_info);
2968                         break;
2969
2970                 case HOST_IF_MSG_CONNECT:
2971                         Handle_Connect(msg.drv, &msg.body.con_info);
2972                         break;
2973
2974                 case HOST_IF_MSG_FLUSH_CONNECT:
2975                         Handle_FlushConnect(msg.drv);
2976                         break;
2977
2978                 case HOST_IF_MSG_RCVD_NTWRK_INFO:
2979                         Handle_RcvdNtwrkInfo(msg.drv, &msg.body.net_info);
2980                         break;
2981
2982                 case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
2983                         Handle_RcvdGnrlAsyncInfo(msg.drv, &msg.body.async_info);
2984                         break;
2985
2986                 case HOST_IF_MSG_KEY:
2987                         Handle_Key(msg.drv, &msg.body.key_info);
2988                         break;
2989
2990                 case HOST_IF_MSG_CFG_PARAMS:
2991
2992                         Handle_CfgParam(msg.drv, &msg.body.cfg_info);
2993                         break;
2994
2995                 case HOST_IF_MSG_SET_CHANNEL:
2996                         Handle_SetChannel(msg.drv, &msg.body.channel_info);
2997                         break;
2998
2999                 case HOST_IF_MSG_DISCONNECT:
3000                         Handle_Disconnect(msg.drv);
3001                         break;
3002
3003                 case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
3004                         del_timer(&hif_drv->hScanTimer);
3005                         PRINT_D(HOSTINF_DBG, "scan completed successfully\n");
3006
3007                         if (!linux_wlan_get_num_conn_ifcs())
3008                                 chip_sleep_manually(INFINITE_SLEEP_TIME);
3009
3010                         Handle_ScanDone(msg.drv, SCAN_EVENT_DONE);
3011
3012                         if (hif_drv->u8RemainOnChan_pendingreq)
3013                                 Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
3014
3015                         break;
3016
3017                 case HOST_IF_MSG_GET_RSSI:
3018                         Handle_GetRssi(msg.drv);
3019                         break;
3020
3021                 case HOST_IF_MSG_GET_LINKSPEED:
3022                         Handle_GetLinkspeed(msg.drv);
3023                         break;
3024
3025                 case HOST_IF_MSG_GET_STATISTICS:
3026                         Handle_GetStatistics(msg.drv, (struct rf_info *)msg.body.data);
3027                         break;
3028
3029                 case HOST_IF_MSG_GET_CHNL:
3030                         Handle_GetChnl(msg.drv);
3031                         break;
3032
3033                 case HOST_IF_MSG_ADD_BEACON:
3034                         Handle_AddBeacon(msg.drv, &msg.body.beacon_info);
3035                         break;
3036
3037                 case HOST_IF_MSG_DEL_BEACON:
3038                         Handle_DelBeacon(msg.drv);
3039                         break;
3040
3041                 case HOST_IF_MSG_ADD_STATION:
3042                         Handle_AddStation(msg.drv, &msg.body.add_sta_info);
3043                         break;
3044
3045                 case HOST_IF_MSG_DEL_STATION:
3046                         Handle_DelStation(msg.drv, &msg.body.del_sta_info);
3047                         break;
3048
3049                 case HOST_IF_MSG_EDIT_STATION:
3050                         Handle_EditStation(msg.drv, &msg.body.edit_sta_info);
3051                         break;
3052
3053                 case HOST_IF_MSG_GET_INACTIVETIME:
3054                         Handle_Get_InActiveTime(msg.drv, &msg.body.mac_info);
3055                         break;
3056
3057                 case HOST_IF_MSG_SCAN_TIMER_FIRED:
3058                         PRINT_D(HOSTINF_DBG, "Scan Timeout\n");
3059
3060                         Handle_ScanDone(msg.drv, SCAN_EVENT_ABORTED);
3061                         break;
3062
3063                 case HOST_IF_MSG_CONNECT_TIMER_FIRED:
3064                         PRINT_D(HOSTINF_DBG, "Connect Timeout\n");
3065                         Handle_ConnectTimeout(msg.drv);
3066                         break;
3067
3068                 case HOST_IF_MSG_POWER_MGMT:
3069                         Handle_PowerManagement(msg.drv, &msg.body.pwr_mgmt_info);
3070                         break;
3071
3072                 case HOST_IF_MSG_SET_WFIDRV_HANDLER:
3073                         Handle_SetWfiDrvHandler(msg.drv,
3074                                                 &msg.body.drv);
3075                         break;
3076
3077                 case HOST_IF_MSG_SET_OPERATION_MODE:
3078                         Handle_SetOperationMode(msg.drv, &msg.body.mode);
3079                         break;
3080
3081                 case HOST_IF_MSG_SET_IPADDRESS:
3082                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
3083                         Handle_set_IPAddress(msg.drv, msg.body.ip_info.au8IPAddr, msg.body.ip_info.idx);
3084                         break;
3085
3086                 case HOST_IF_MSG_GET_IPADDRESS:
3087                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
3088                         Handle_get_IPAddress(msg.drv, msg.body.ip_info.au8IPAddr, msg.body.ip_info.idx);
3089                         break;
3090
3091                 case HOST_IF_MSG_SET_MAC_ADDRESS:
3092                         Handle_SetMacAddress(msg.drv, &msg.body.set_mac_info);
3093                         break;
3094
3095                 case HOST_IF_MSG_GET_MAC_ADDRESS:
3096                         Handle_GetMacAddress(msg.drv, &msg.body.get_mac_info);
3097                         break;
3098
3099                 case HOST_IF_MSG_REMAIN_ON_CHAN:
3100                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REMAIN_ON_CHAN\n");
3101                         Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
3102                         break;
3103
3104                 case HOST_IF_MSG_REGISTER_FRAME:
3105                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REGISTER_FRAME\n");
3106                         Handle_RegisterFrame(msg.drv, &msg.body.reg_frame);
3107                         break;
3108
3109                 case HOST_IF_MSG_LISTEN_TIMER_FIRED:
3110                         Handle_ListenStateExpired(msg.drv, &msg.body.remain_on_ch);
3111                         break;
3112
3113                 case HOST_IF_MSG_SET_MULTICAST_FILTER:
3114                         PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_MULTICAST_FILTER\n");
3115                         Handle_SetMulticastFilter(msg.drv, &msg.body.multicast_info);
3116                         break;
3117
3118                 case HOST_IF_MSG_ADD_BA_SESSION:
3119                         Handle_AddBASession(msg.drv, &msg.body.session_info);
3120                         break;
3121
3122                 case HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS:
3123                         Handle_DelAllRxBASessions(msg.drv, &msg.body.session_info);
3124                         break;
3125
3126                 case HOST_IF_MSG_DEL_ALL_STA:
3127                         Handle_DelAllSta(msg.drv, &msg.body.del_all_sta_info);
3128                         break;
3129
3130                 default:
3131                         PRINT_ER("[Host Interface] undefined Received Msg ID\n");
3132                         break;
3133                 }
3134         }
3135
3136         PRINT_D(HOSTINF_DBG, "Releasing thread exit semaphore\n");
3137         up(&hSemHostIFthrdEnd);
3138         return 0;
3139 }
3140
3141 static void TimerCB_Scan(unsigned long arg)
3142 {
3143         void *pvArg = (void *)arg;
3144         struct host_if_msg msg;
3145
3146         memset(&msg, 0, sizeof(struct host_if_msg));
3147         msg.drv = pvArg;
3148         msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
3149
3150         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3151 }
3152
3153 static void TimerCB_Connect(unsigned long arg)
3154 {
3155         void *pvArg = (void *)arg;
3156         struct host_if_msg msg;
3157
3158         memset(&msg, 0, sizeof(struct host_if_msg));
3159         msg.drv = pvArg;
3160         msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
3161
3162         wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3163 }
3164
3165 s32 host_int_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress)
3166 {
3167         struct wid strWID;
3168
3169         strWID.id = (u16)WID_REMOVE_KEY;
3170         strWID.type = WID_STR;
3171         strWID.val = (s8 *)pu8StaAddress;
3172         strWID.size = 6;
3173
3174         return 0;
3175 }
3176
3177 int host_int_remove_wep_key(struct host_if_drv *hif_drv, u8 index)
3178 {
3179         int result = 0;
3180         struct host_if_msg msg;
3181
3182         if (!hif_drv) {
3183                 result = -EFAULT;
3184                 PRINT_ER("Failed to send setup multicast config packet\n");
3185                 return result;
3186         }
3187
3188         memset(&msg, 0, sizeof(struct host_if_msg));
3189
3190         msg.id = HOST_IF_MSG_KEY;
3191         msg.body.key_info.type = WEP;
3192         msg.body.key_info.action = REMOVEKEY;
3193         msg.drv = hif_drv;
3194         msg.body.key_info.attr.wep.index = index;
3195
3196         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3197         if (result)
3198                 PRINT_ER("Error in sending message queue : Request to remove WEP key\n");
3199         down(&hif_drv->hSemTestKeyBlock);
3200
3201         return result;
3202 }
3203
3204 s32 host_int_set_WEPDefaultKeyID(struct host_if_drv *hif_drv, u8 u8Index)
3205 {
3206         s32 s32Error = 0;
3207         struct host_if_msg msg;
3208
3209
3210         if (!hif_drv) {
3211                 s32Error = -EFAULT;
3212                 PRINT_ER("driver is null\n");
3213                 return s32Error;
3214         }
3215
3216         memset(&msg, 0, sizeof(struct host_if_msg));
3217
3218
3219         msg.id = HOST_IF_MSG_KEY;
3220         msg.body.key_info.type = WEP;
3221         msg.body.key_info.action = DEFAULTKEY;
3222         msg.drv = hif_drv;
3223         msg.body.key_info.attr.wep.index = u8Index;
3224
3225         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3226         if (s32Error)
3227                 PRINT_ER("Error in sending message queue : Default key index\n");
3228         down(&hif_drv->hSemTestKeyBlock);
3229
3230         return s32Error;
3231 }
3232
3233 s32 host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv,
3234                                  const u8 *pu8WepKey,
3235                                  u8 u8WepKeylen,
3236                                  u8 u8Keyidx)
3237 {
3238
3239         s32 s32Error = 0;
3240         struct host_if_msg msg;
3241
3242         if (!hif_drv) {
3243                 s32Error = -EFAULT;
3244                 PRINT_ER("driver is null\n");
3245                 return s32Error;
3246         }
3247
3248         memset(&msg, 0, sizeof(struct host_if_msg));
3249
3250
3251         msg.id = HOST_IF_MSG_KEY;
3252         msg.body.key_info.type = WEP;
3253         msg.body.key_info.action = ADDKEY;
3254         msg.drv = hif_drv;
3255         msg.body.key_info.attr.wep.key = kmalloc(u8WepKeylen, GFP_KERNEL);
3256         memcpy(msg.body.key_info.attr.wep.key, pu8WepKey, u8WepKeylen);
3257         msg.body.key_info.attr.wep.key_len = (u8WepKeylen);
3258         msg.body.key_info.attr.wep.index = u8Keyidx;
3259
3260         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3261         if (s32Error)
3262                 PRINT_ER("Error in sending message queue :WEP Key\n");
3263         down(&hif_drv->hSemTestKeyBlock);
3264
3265         return s32Error;
3266
3267 }
3268
3269 s32 host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv,
3270                                 const u8 *pu8WepKey,
3271                                 u8 u8WepKeylen,
3272                                 u8 u8Keyidx,
3273                                 u8 u8mode,
3274                                 enum AUTHTYPE tenuAuth_type)
3275 {
3276
3277         s32 s32Error = 0;
3278         struct host_if_msg msg;
3279         u8 i;
3280
3281         if (!hif_drv) {
3282                 s32Error = -EFAULT;
3283                 PRINT_ER("driver is null\n");
3284                 return s32Error;
3285         }
3286
3287         memset(&msg, 0, sizeof(struct host_if_msg));
3288
3289         if (INFO) {
3290                 for (i = 0; i < u8WepKeylen; i++)
3291                         PRINT_INFO(HOSTAPD_DBG, "KEY is %x\n", pu8WepKey[i]);
3292         }
3293         msg.id = HOST_IF_MSG_KEY;
3294         msg.body.key_info.type = WEP;
3295         msg.body.key_info.action = ADDKEY_AP;
3296         msg.drv = hif_drv;
3297         msg.body.key_info.attr.wep.key = kmalloc(u8WepKeylen, GFP_KERNEL);
3298         memcpy(msg.body.key_info.attr.wep.key, pu8WepKey, (u8WepKeylen));
3299         msg.body.key_info.attr.wep.key_len = (u8WepKeylen);
3300         msg.body.key_info.attr.wep.index = u8Keyidx;
3301         msg.body.key_info.attr.wep.mode = u8mode;
3302         msg.body.key_info.attr.wep.auth_type = tenuAuth_type;
3303
3304         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3305
3306         if (s32Error)
3307                 PRINT_ER("Error in sending message queue :WEP Key\n");
3308         down(&hif_drv->hSemTestKeyBlock);
3309
3310         return s32Error;
3311
3312 }
3313
3314 s32 host_int_add_ptk(struct host_if_drv *hif_drv, const u8 *pu8Ptk,
3315                      u8 u8PtkKeylen, const u8 *mac_addr,
3316                      const u8 *pu8RxMic, const u8 *pu8TxMic,
3317                      u8 mode, u8 u8Ciphermode, u8 u8Idx)
3318 {
3319         s32 s32Error = 0;
3320         struct host_if_msg msg;
3321         u8 u8KeyLen = u8PtkKeylen;
3322         u32 i;
3323
3324         if (!hif_drv) {
3325                 s32Error = -EFAULT;
3326                 PRINT_ER("driver is null\n");
3327                 return s32Error;
3328         }
3329         if (pu8RxMic != NULL)
3330                 u8KeyLen += RX_MIC_KEY_LEN;
3331         if (pu8TxMic != NULL)
3332                 u8KeyLen += TX_MIC_KEY_LEN;
3333
3334         memset(&msg, 0, sizeof(struct host_if_msg));
3335
3336
3337         msg.id = HOST_IF_MSG_KEY;
3338         msg.body.key_info.type = WPAPtk;
3339         if (mode == AP_MODE) {
3340                 msg.body.key_info.action = ADDKEY_AP;
3341                 msg.body.key_info.attr.wpa.index = u8Idx;
3342         }
3343         if (mode == STATION_MODE)
3344                 msg.body.key_info.action = ADDKEY;
3345
3346         msg.body.key_info.attr.wpa.key = kmalloc(u8PtkKeylen, GFP_KERNEL);
3347         memcpy(msg.body.key_info.attr.wpa.key, pu8Ptk, u8PtkKeylen);
3348
3349         if (pu8RxMic != NULL) {
3350                 memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
3351                 if (INFO) {
3352                         for (i = 0; i < RX_MIC_KEY_LEN; i++)
3353                                 PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, pu8RxMic[i]);
3354                 }
3355         }
3356         if (pu8TxMic != NULL) {
3357                 memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
3358                 if (INFO) {
3359                         for (i = 0; i < TX_MIC_KEY_LEN; i++)
3360                                 PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, pu8TxMic[i]);
3361                 }
3362         }
3363
3364         msg.body.key_info.attr.wpa.key_len = u8KeyLen;
3365         msg.body.key_info.attr.wpa.mac_addr = mac_addr;
3366         msg.body.key_info.attr.wpa.mode = u8Ciphermode;
3367         msg.drv = hif_drv;
3368
3369         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3370
3371         if (s32Error)
3372                 PRINT_ER("Error in sending message queue:  PTK Key\n");
3373
3374         down(&hif_drv->hSemTestKeyBlock);
3375
3376         return s32Error;
3377 }
3378
3379 s32 host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *pu8RxGtk,
3380                         u8 u8GtkKeylen, u8 u8KeyIdx,
3381                         u32 u32KeyRSClen, const u8 *KeyRSC,
3382                         const u8 *pu8RxMic, const u8 *pu8TxMic,
3383                         u8 mode, u8 u8Ciphermode)
3384 {
3385         s32 s32Error = 0;
3386         struct host_if_msg msg;
3387         u8 u8KeyLen = u8GtkKeylen;
3388
3389         if (!hif_drv) {
3390                 s32Error = -EFAULT;
3391                 PRINT_ER("driver is null\n");
3392                 return s32Error;
3393         }
3394         memset(&msg, 0, sizeof(struct host_if_msg));
3395
3396
3397         if (pu8RxMic != NULL)
3398                 u8KeyLen += RX_MIC_KEY_LEN;
3399         if (pu8TxMic != NULL)
3400                 u8KeyLen += TX_MIC_KEY_LEN;
3401         if (KeyRSC != NULL) {
3402                 msg.body.key_info.attr.wpa.seq = kmalloc(u32KeyRSClen, GFP_KERNEL);
3403                 memcpy(msg.body.key_info.attr.wpa.seq, KeyRSC, u32KeyRSClen);
3404         }
3405
3406
3407         msg.id = HOST_IF_MSG_KEY;
3408         msg.body.key_info.type = WPARxGtk;
3409         msg.drv = hif_drv;
3410
3411         if (mode == AP_MODE) {
3412                 msg.body.key_info.action = ADDKEY_AP;
3413                 msg.body.key_info.attr.wpa.mode = u8Ciphermode;
3414         }
3415         if (mode == STATION_MODE)
3416                 msg.body.key_info.action = ADDKEY;
3417
3418         msg.body.key_info.attr.wpa.key = kmalloc(u8KeyLen, GFP_KERNEL);
3419         memcpy(msg.body.key_info.attr.wpa.key, pu8RxGtk, u8GtkKeylen);
3420
3421         if (pu8RxMic != NULL) {
3422                 memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
3423         }
3424         if (pu8TxMic != NULL) {
3425                 memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
3426         }
3427
3428         msg.body.key_info.attr.wpa.index = u8KeyIdx;
3429         msg.body.key_info.attr.wpa.key_len = u8KeyLen;
3430         msg.body.key_info.attr.wpa.seq_len = u32KeyRSClen;
3431
3432         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3433         if (s32Error)
3434                 PRINT_ER("Error in sending message queue:  RX GTK\n");
3435
3436         down(&hif_drv->hSemTestKeyBlock);
3437
3438         return s32Error;
3439 }
3440
3441 s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_attr *pu8PmkidInfoArray)
3442 {
3443         s32 s32Error = 0;
3444         struct host_if_msg msg;
3445         u32 i;
3446
3447
3448         if (!hif_drv) {
3449                 s32Error = -EFAULT;
3450                 PRINT_ER("driver is null\n");
3451                 return s32Error;
3452         }
3453
3454         memset(&msg, 0, sizeof(struct host_if_msg));
3455
3456         msg.id = HOST_IF_MSG_KEY;
3457         msg.body.key_info.type = PMKSA;
3458         msg.body.key_info.action = ADDKEY;
3459         msg.drv = hif_drv;
3460
3461         for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) {
3462                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid,
3463                             ETH_ALEN);
3464                 memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid,
3465                             PMKID_LEN);
3466         }
3467
3468         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3469         if (s32Error)
3470                 PRINT_ER(" Error in sending messagequeue: PMKID Info\n");
3471
3472         return s32Error;
3473 }
3474
3475 s32 host_int_get_pmkid_info(struct host_if_drv *hif_drv,
3476                             u8 *pu8PmkidInfoArray,
3477                             u32 u32PmkidInfoLen)
3478 {
3479         struct wid strWID;
3480
3481         strWID.id = (u16)WID_PMKID_INFO;
3482         strWID.type = WID_STR;
3483         strWID.size = u32PmkidInfoLen;
3484         strWID.val = pu8PmkidInfoArray;
3485
3486         return 0;
3487 }
3488
3489 s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
3490                                          u8 *pu8PassPhrase,
3491                                          u8 u8Psklength)
3492 {
3493         struct wid strWID;
3494
3495         if ((u8Psklength > 7) && (u8Psklength < 65)) {
3496                 strWID.id = (u16)WID_11I_PSK;
3497                 strWID.type = WID_STR;
3498                 strWID.val = pu8PassPhrase;
3499                 strWID.size = u8Psklength;
3500         }
3501
3502         return 0;
3503 }
3504
3505 s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
3506 {
3507         s32 s32Error = 0;
3508         struct host_if_msg msg;
3509
3510         memset(&msg, 0, sizeof(struct host_if_msg));
3511
3512         msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
3513         msg.body.get_mac_info.u8MacAddress = pu8MacAddress;
3514         msg.drv = hif_drv;
3515
3516         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3517         if (s32Error) {
3518                 PRINT_ER("Failed to send get mac address\n");
3519                 return -EFAULT;
3520         }
3521
3522         down(&hWaitResponse);
3523         return s32Error;
3524 }
3525
3526 s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
3527 {
3528         s32 s32Error = 0;
3529         struct host_if_msg msg;
3530
3531         PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]);
3532
3533         memset(&msg, 0, sizeof(struct host_if_msg));
3534         msg.id = HOST_IF_MSG_SET_MAC_ADDRESS;
3535         memcpy(msg.body.set_mac_info.u8MacAddress, pu8MacAddress, ETH_ALEN);
3536         msg.drv = hif_drv;
3537
3538         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3539         if (s32Error)
3540                 PRINT_ER("Failed to send message queue: Set mac address\n");
3541
3542         return s32Error;
3543
3544 }
3545
3546 s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
3547                                          u8 *pu8PassPhrase, u8 u8Psklength)
3548 {
3549         struct wid strWID;
3550
3551         strWID.id = (u16)WID_11I_PSK;
3552         strWID.type = WID_STR;
3553         strWID.size = u8Psklength;
3554         strWID.val = pu8PassPhrase;
3555
3556         return 0;
3557 }
3558
3559 s32 host_int_set_start_scan_req(struct host_if_drv *hif_drv, u8 scanSource)
3560 {
3561         struct wid strWID;
3562
3563         strWID.id = (u16)WID_START_SCAN_REQ;
3564         strWID.type = WID_CHAR;
3565         strWID.val = (s8 *)&scanSource;
3566         strWID.size = sizeof(char);
3567
3568         return 0;
3569 }
3570
3571 s32 host_int_get_start_scan_req(struct host_if_drv *hif_drv, u8 *pu8ScanSource)
3572 {
3573         struct wid strWID;
3574
3575         strWID.id = (u16)WID_START_SCAN_REQ;
3576         strWID.type = WID_CHAR;
3577         strWID.val = (s8 *)pu8ScanSource;
3578         strWID.size = sizeof(char);
3579
3580         return 0;
3581 }
3582
3583 s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid,
3584                           const u8 *pu8ssid, size_t ssidLen,
3585                           const u8 *pu8IEs, size_t IEsLen,
3586                           wilc_connect_result pfConnectResult, void *pvUserArg,
3587                           u8 u8security, enum AUTHTYPE tenuAuth_type,
3588                           u8 u8channel, void *pJoinParams)
3589 {
3590         s32 s32Error = 0;
3591         struct host_if_msg msg;
3592         enum scan_conn_timer enuScanConnTimer;
3593
3594         if (!hif_drv || pfConnectResult == NULL) {
3595                 s32Error = -EFAULT;
3596                 PRINT_ER("Driver is null\n");
3597                 return s32Error;
3598         }
3599
3600         if (!hif_drv) {
3601                 PRINT_ER("Driver is null\n");
3602                 return -EFAULT;
3603         }
3604
3605         if (pJoinParams == NULL) {
3606                 PRINT_ER("Unable to Join - JoinParams is NULL\n");
3607                 return -EFAULT;
3608         }
3609
3610         memset(&msg, 0, sizeof(struct host_if_msg));
3611
3612         msg.id = HOST_IF_MSG_CONNECT;
3613
3614         msg.body.con_info.u8security = u8security;
3615         msg.body.con_info.tenuAuth_type = tenuAuth_type;
3616         msg.body.con_info.u8channel = u8channel;
3617         msg.body.con_info.pfConnectResult = pfConnectResult;
3618         msg.body.con_info.pvUserArg = pvUserArg;
3619         msg.body.con_info.pJoinParams = pJoinParams;
3620         msg.drv = hif_drv ;
3621
3622         if (pu8bssid != NULL) {
3623                 msg.body.con_info.bssid = kmalloc(6, GFP_KERNEL);
3624                 memcpy(msg.body.con_info.bssid, pu8bssid, 6);
3625         }
3626
3627         if (pu8ssid != NULL) {
3628                 msg.body.con_info.ssidLen = ssidLen;
3629                 msg.body.con_info.pu8ssid = kmalloc(ssidLen, GFP_KERNEL);
3630                 memcpy(msg.body.con_info.pu8ssid,
3631
3632                             pu8ssid, ssidLen);
3633         }
3634
3635         if (pu8IEs != NULL) {
3636                 msg.body.con_info.IEsLen = IEsLen;
3637                 msg.body.con_info.pu8IEs = kmalloc(IEsLen, GFP_KERNEL);
3638                 memcpy(msg.body.con_info.pu8IEs,
3639                             pu8IEs, IEsLen);
3640         }
3641         if (hif_drv->enuHostIFstate < HOST_IF_CONNECTING)
3642                 hif_drv->enuHostIFstate = HOST_IF_CONNECTING;
3643         else
3644                 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", hif_drv->enuHostIFstate);
3645
3646         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3647         if (s32Error) {
3648                 PRINT_ER("Failed to send message queue: Set join request\n");
3649                 return -EFAULT;
3650         }
3651
3652         enuScanConnTimer = CONNECT_TIMER;
3653         hif_drv->hConnectTimer.data = (unsigned long)hif_drv;
3654         mod_timer(&hif_drv->hConnectTimer,
3655                   jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3656
3657         return s32Error;
3658 }
3659
3660 s32 host_int_flush_join_req(struct host_if_drv *hif_drv)
3661 {
3662         s32 s32Error = 0;
3663         struct host_if_msg msg;
3664
3665         if (!gu8FlushedJoinReq) {
3666                 s32Error = -EFAULT;
3667                 return s32Error;
3668         }
3669
3670
3671         if (!hif_drv) {
3672                 s32Error = -EFAULT;
3673                 PRINT_ER("Driver is null\n");
3674                 return s32Error;
3675         }
3676
3677         msg.id = HOST_IF_MSG_FLUSH_CONNECT;
3678         msg.drv = hif_drv;
3679
3680         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3681         if (s32Error) {
3682                 PRINT_ER("Failed to send message queue: Flush join request\n");
3683                 return -EFAULT;
3684         }
3685
3686         return s32Error;
3687 }
3688
3689 s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode)
3690 {
3691         s32 s32Error = 0;
3692         struct host_if_msg msg;
3693
3694         if (!hif_drv) {
3695                 PRINT_ER("Driver is null\n");
3696                 return -EFAULT;
3697         }
3698
3699         memset(&msg, 0, sizeof(struct host_if_msg));
3700
3701         msg.id = HOST_IF_MSG_DISCONNECT;
3702         msg.drv = hif_drv;
3703
3704         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3705         if (s32Error)
3706                 PRINT_ER("Failed to send message queue: disconnect\n");
3707
3708         down(&hif_drv->hSemTestDisconnectBlock);
3709
3710         return s32Error;
3711 }
3712
3713 s32 host_int_disconnect_station(struct host_if_drv *hif_drv, u8 assoc_id)
3714 {
3715         struct wid strWID;
3716
3717         strWID.id = (u16)WID_DISCONNECT;
3718         strWID.type = WID_CHAR;
3719         strWID.val = (s8 *)&assoc_id;
3720         strWID.size = sizeof(char);
3721
3722         return 0;
3723 }
3724
3725 s32 host_int_get_assoc_req_info(struct host_if_drv *hif_drv, u8 *pu8AssocReqInfo,
3726                                         u32 u32AssocReqInfoLen)
3727 {
3728         struct wid strWID;
3729
3730         strWID.id = (u16)WID_ASSOC_REQ_INFO;
3731         strWID.type = WID_STR;
3732         strWID.val = pu8AssocReqInfo;
3733         strWID.size = u32AssocReqInfoLen;
3734
3735         return 0;
3736 }
3737
3738 s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, u8 *pu8AssocRespInfo,
3739                                         u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
3740 {
3741         s32 s32Error = 0;
3742         struct wid strWID;
3743
3744         if (!hif_drv) {
3745                 PRINT_ER("Driver is null\n");
3746                 return -EFAULT;
3747         }
3748
3749         strWID.id = (u16)WID_ASSOC_RES_INFO;
3750         strWID.type = WID_STR;
3751         strWID.val = pu8AssocRespInfo;
3752         strWID.size = u32MaxAssocRespInfoLen;
3753
3754         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3755                                    get_id_from_handler(hif_drv));
3756         if (s32Error) {
3757                 *pu32RcvdAssocRespInfoLen = 0;
3758                 PRINT_ER("Failed to send association response config packet\n");
3759                 return -EINVAL;
3760         } else {
3761                 *pu32RcvdAssocRespInfoLen = strWID.size;
3762         }
3763
3764         return s32Error;
3765 }
3766
3767 s32 host_int_get_rx_power_level(struct host_if_drv *hif_drv, u8 *pu8RxPowerLevel,
3768                                         u32 u32RxPowerLevelLen)
3769 {
3770         struct wid strWID;
3771
3772         strWID.id = (u16)WID_RX_POWER_LEVEL;
3773         strWID.type = WID_STR;
3774         strWID.val = pu8RxPowerLevel;
3775         strWID.size = u32RxPowerLevelLen;
3776
3777         return 0;
3778 }
3779
3780 int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel)
3781 {
3782         int result;
3783         struct host_if_msg msg;
3784
3785         if (!hif_drv) {
3786                 PRINT_ER("driver is null\n");
3787                 return -EFAULT;
3788         }
3789
3790         memset(&msg, 0, sizeof(struct host_if_msg));
3791         msg.id = HOST_IF_MSG_SET_CHANNEL;
3792         msg.body.channel_info.u8SetChan = channel;
3793         msg.drv = hif_drv;
3794
3795         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3796         if (result) {
3797                 PRINT_ER("wilc mq send fail\n");
3798                 return -EINVAL;
3799         }
3800
3801         return 0;
3802 }
3803
3804 int host_int_wait_msg_queue_idle(void)
3805 {
3806         int result = 0;
3807
3808         struct host_if_msg msg;
3809         memset(&msg, 0, sizeof(struct host_if_msg));
3810         msg.id = HOST_IF_MSG_Q_IDLE;
3811         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3812         if (result) {
3813                 PRINT_ER("wilc mq send fail\n");
3814                 result = -EINVAL;
3815         }
3816
3817         down(&hWaitResponse);
3818
3819         return result;
3820 }
3821
3822 int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv)
3823 {
3824         int result = 0;
3825
3826         struct host_if_msg msg;
3827         memset(&msg, 0, sizeof(struct host_if_msg));
3828         msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
3829         msg.body.drv.u32Address = get_id_from_handler(hif_drv);
3830         msg.drv = hif_drv;
3831
3832         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3833         if (result) {
3834                 PRINT_ER("wilc mq send fail\n");
3835                 result = -EINVAL;
3836         }
3837
3838         return result;
3839 }
3840
3841 int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode)
3842 {
3843         int result = 0;
3844
3845         struct host_if_msg msg;
3846         memset(&msg, 0, sizeof(struct host_if_msg));
3847         msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
3848         msg.body.mode.u32Mode = mode;
3849         msg.drv = hif_drv;
3850
3851         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3852         if (result) {
3853                 PRINT_ER("wilc mq send fail\n");
3854                 result = -EINVAL;
3855         }
3856
3857         return result;
3858 }
3859
3860 s32 host_int_get_host_chnl_num(struct host_if_drv *hif_drv, u8 *pu8ChNo)
3861 {
3862         s32 s32Error = 0;
3863         struct host_if_msg msg;
3864
3865         if (!hif_drv) {
3866                 PRINT_ER("driver is null\n");
3867                 return -EFAULT;
3868         }
3869
3870         memset(&msg, 0, sizeof(struct host_if_msg));
3871
3872         msg.id = HOST_IF_MSG_GET_CHNL;
3873         msg.drv = hif_drv;
3874
3875         s32Error =      wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3876         if (s32Error)
3877                 PRINT_ER("wilc mq send fail\n");
3878         down(&hif_drv->hSemGetCHNL);
3879
3880         *pu8ChNo = gu8Chnl;
3881
3882         return s32Error;
3883
3884
3885 }
3886
3887 s32 host_int_get_inactive_time(struct host_if_drv *hif_drv,
3888                                const u8 *mac, u32 *pu32InactiveTime)
3889 {
3890         s32 s32Error = 0;
3891         struct host_if_msg msg;
3892
3893         if (!hif_drv) {
3894                 PRINT_ER("driver is null\n");
3895                 return -EFAULT;
3896         }
3897
3898         memset(&msg, 0, sizeof(struct host_if_msg));
3899
3900
3901         memcpy(msg.body.mac_info.mac,
3902                     mac, ETH_ALEN);
3903
3904         msg.id = HOST_IF_MSG_GET_INACTIVETIME;
3905         msg.drv = hif_drv;
3906
3907         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3908         if (s32Error)
3909                 PRINT_ER("Failed to send get host channel param's message queue ");
3910
3911         down(&hif_drv->hSemInactiveTime);
3912
3913         *pu32InactiveTime = gu32InactiveTime;
3914
3915         return s32Error;
3916 }
3917
3918 s32 host_int_test_get_int_wid(struct host_if_drv *hif_drv, u32 *pu32TestMemAddr)
3919 {
3920
3921         s32 s32Error = 0;
3922         struct wid strWID;
3923
3924         if (!hif_drv) {
3925                 PRINT_ER("driver is null\n");
3926                 return -EFAULT;
3927         }
3928
3929         strWID.id = (u16)WID_MEMORY_ADDRESS;
3930         strWID.type = WID_INT;
3931         strWID.val = (s8 *)pu32TestMemAddr;
3932         strWID.size = sizeof(u32);
3933
3934         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3935                                    get_id_from_handler(hif_drv));
3936
3937         if (s32Error) {
3938                 PRINT_ER("Failed to get wid value\n");
3939                 return -EINVAL;
3940         } else {
3941                 PRINT_D(HOSTINF_DBG, "Successfully got wid value\n");
3942
3943         }
3944
3945         return s32Error;
3946 }
3947
3948 s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi)
3949 {
3950         s32 s32Error = 0;
3951         struct host_if_msg msg;
3952         memset(&msg, 0, sizeof(struct host_if_msg));
3953
3954         msg.id = HOST_IF_MSG_GET_RSSI;
3955         msg.drv = hif_drv;
3956
3957         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3958         if (s32Error) {
3959                 PRINT_ER("Failed to send get host channel param's message queue ");
3960                 return -EFAULT;
3961         }
3962
3963         down(&hif_drv->hSemGetRSSI);
3964
3965
3966         if (ps8Rssi == NULL) {
3967                 PRINT_ER("RSS pointer value is null");
3968                 return -EFAULT;
3969         }
3970
3971
3972         *ps8Rssi = gs8Rssi;
3973
3974
3975         return s32Error;
3976 }
3977
3978 s32 host_int_get_link_speed(struct host_if_drv *hif_drv, s8 *ps8lnkspd)
3979 {
3980         struct host_if_msg msg;
3981         s32 s32Error = 0;
3982         memset(&msg, 0, sizeof(struct host_if_msg));
3983
3984         msg.id = HOST_IF_MSG_GET_LINKSPEED;
3985         msg.drv = hif_drv;
3986
3987         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3988         if (s32Error) {
3989                 PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
3990                 return -EFAULT;
3991         }
3992
3993         down(&hif_drv->hSemGetLINKSPEED);
3994
3995
3996         if (ps8lnkspd == NULL) {
3997                 PRINT_ER("LINKSPEED pointer value is null");
3998                 return -EFAULT;
3999         }
4000
4001
4002         *ps8lnkspd = gs8lnkspd;
4003
4004
4005         return s32Error;
4006 }
4007
4008 s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
4009 {
4010         s32 s32Error = 0;
4011         struct host_if_msg msg;
4012         memset(&msg, 0, sizeof(struct host_if_msg));
4013
4014         msg.id = HOST_IF_MSG_GET_STATISTICS;
4015         msg.body.data = (char *)pstrStatistics;
4016         msg.drv = hif_drv;
4017
4018         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4019         if (s32Error) {
4020                 PRINT_ER("Failed to send get host channel param's message queue ");
4021                 return -EFAULT;
4022         }
4023
4024         down(&hWaitResponse);
4025         return s32Error;
4026 }
4027
4028 s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource,
4029                   u8 u8ScanType, u8 *pu8ChnlFreqList,
4030                   u8 u8ChnlListLen, const u8 *pu8IEs,
4031                   size_t IEsLen, wilc_scan_result ScanResult,
4032                   void *pvUserArg, struct hidden_network *pstrHiddenNetwork)
4033 {
4034         s32 s32Error = 0;
4035         struct host_if_msg msg;
4036         enum scan_conn_timer enuScanConnTimer;
4037
4038         if (!hif_drv || ScanResult == NULL) {
4039                 PRINT_ER("hif_drv or ScanResult = NULL\n");
4040                 return -EFAULT;
4041         }
4042
4043         memset(&msg, 0, sizeof(struct host_if_msg));
4044
4045         msg.id = HOST_IF_MSG_SCAN;
4046
4047         if (pstrHiddenNetwork != NULL) {
4048                 msg.body.scan_info.hidden_network.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
4049                 msg.body.scan_info.hidden_network.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
4050
4051         } else
4052                 PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n");
4053
4054         msg.drv = hif_drv;
4055         msg.body.scan_info.src = u8ScanSource;
4056         msg.body.scan_info.type = u8ScanType;
4057         msg.body.scan_info.result = ScanResult;
4058         msg.body.scan_info.arg = pvUserArg;
4059
4060         msg.body.scan_info.ch_list_len = u8ChnlListLen;
4061         msg.body.scan_info.ch_freq_list = kmalloc(u8ChnlListLen, GFP_KERNEL);
4062         memcpy(msg.body.scan_info.ch_freq_list, pu8ChnlFreqList, u8ChnlListLen);
4063
4064         msg.body.scan_info.ies_len = IEsLen;
4065         msg.body.scan_info.ies = kmalloc(IEsLen, GFP_KERNEL);
4066         memcpy(msg.body.scan_info.ies, pu8IEs, IEsLen);
4067
4068         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4069         if (s32Error) {
4070                 PRINT_ER("Error in sending message queue\n");
4071                 return -EINVAL;
4072         }
4073
4074         enuScanConnTimer = SCAN_TIMER;
4075         PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
4076         hif_drv->hScanTimer.data = (unsigned long)hif_drv;
4077         mod_timer(&hif_drv->hScanTimer,
4078                   jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
4079
4080         return s32Error;
4081
4082 }
4083
4084 s32 hif_set_cfg(struct host_if_drv *hif_drv,
4085                 struct cfg_param_val *pstrCfgParamVal)
4086 {
4087
4088         s32 s32Error = 0;
4089         struct host_if_msg msg;
4090
4091
4092         if (!hif_drv) {
4093                 PRINT_ER("hif_drv NULL\n");
4094                 return -EFAULT;
4095         }
4096
4097         memset(&msg, 0, sizeof(struct host_if_msg));
4098         msg.id = HOST_IF_MSG_CFG_PARAMS;
4099         msg.body.cfg_info.cfg_attr_info = *pstrCfgParamVal;
4100         msg.drv = hif_drv;
4101
4102         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4103
4104         return s32Error;
4105
4106 }
4107
4108 s32 hif_get_cfg(struct host_if_drv *hif_drv, u16 u16WID, u16 *pu16WID_Value)
4109 {
4110         s32 s32Error = 0;
4111
4112         down(&hif_drv->gtOsCfgValuesSem);
4113
4114         if (!hif_drv) {
4115                 PRINT_ER("hif_drv NULL\n");
4116                 return -EFAULT;
4117         }
4118         PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
4119         switch (u16WID) {
4120
4121         case WID_BSS_TYPE:
4122                 *pu16WID_Value = (u16)hif_drv->strCfgValues.bss_type;
4123                 break;
4124
4125         case WID_AUTH_TYPE:
4126                 *pu16WID_Value = (u16)hif_drv->strCfgValues.auth_type;
4127                 break;
4128
4129         case WID_AUTH_TIMEOUT:
4130                 *pu16WID_Value = hif_drv->strCfgValues.auth_timeout;
4131                 break;
4132
4133         case WID_POWER_MANAGEMENT:
4134                 *pu16WID_Value = (u16)hif_drv->strCfgValues.power_mgmt_mode;
4135                 break;
4136
4137         case WID_SHORT_RETRY_LIMIT:
4138                 *pu16WID_Value =       hif_drv->strCfgValues.short_retry_limit;
4139                 break;
4140
4141         case WID_LONG_RETRY_LIMIT:
4142                 *pu16WID_Value = hif_drv->strCfgValues.long_retry_limit;
4143                 break;
4144
4145         case WID_FRAG_THRESHOLD:
4146                 *pu16WID_Value = hif_drv->strCfgValues.frag_threshold;
4147                 break;
4148
4149         case WID_RTS_THRESHOLD:
4150                 *pu16WID_Value = hif_drv->strCfgValues.rts_threshold;
4151                 break;
4152
4153         case WID_PREAMBLE:
4154                 *pu16WID_Value = (u16)hif_drv->strCfgValues.preamble_type;
4155                 break;
4156
4157         case WID_SHORT_SLOT_ALLOWED:
4158                 *pu16WID_Value = (u16) hif_drv->strCfgValues.short_slot_allowed;
4159                 break;
4160
4161         case WID_11N_TXOP_PROT_DISABLE:
4162                 *pu16WID_Value = (u16)hif_drv->strCfgValues.txop_prot_disabled;
4163                 break;
4164
4165         case WID_BEACON_INTERVAL:
4166                 *pu16WID_Value = hif_drv->strCfgValues.beacon_interval;
4167                 break;
4168
4169         case WID_DTIM_PERIOD:
4170                 *pu16WID_Value = (u16)hif_drv->strCfgValues.dtim_period;
4171                 break;
4172
4173         case WID_SITE_SURVEY:
4174                 *pu16WID_Value = (u16)hif_drv->strCfgValues.site_survey_enabled;
4175                 break;
4176
4177         case WID_SITE_SURVEY_SCAN_TIME:
4178                 *pu16WID_Value = hif_drv->strCfgValues.site_survey_scan_time;
4179                 break;
4180
4181         case WID_ACTIVE_SCAN_TIME:
4182                 *pu16WID_Value = hif_drv->strCfgValues.active_scan_time;
4183                 break;
4184
4185         case WID_PASSIVE_SCAN_TIME:
4186                 *pu16WID_Value = hif_drv->strCfgValues.passive_scan_time;
4187                 break;
4188
4189         case WID_CURRENT_TX_RATE:
4190                 *pu16WID_Value = hif_drv->strCfgValues.curr_tx_rate;
4191                 break;
4192
4193         default:
4194                 break;
4195         }
4196
4197         up(&hif_drv->gtOsCfgValuesSem);
4198
4199         return s32Error;
4200
4201 }
4202
4203 void host_int_send_join_leave_info_to_host
4204         (u16 assocId, u8 *stationAddr, bool joining)
4205 {
4206 }
4207
4208 static void GetPeriodicRSSI(unsigned long arg)
4209 {
4210         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
4211
4212         if (!hif_drv)   {
4213                 PRINT_ER("Driver handler is NULL\n");
4214                 return;
4215         }
4216
4217         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) {
4218                 s32 s32Error = 0;
4219                 struct host_if_msg msg;
4220
4221                 memset(&msg, 0, sizeof(struct host_if_msg));
4222
4223                 msg.id = HOST_IF_MSG_GET_RSSI;
4224                 msg.drv = hif_drv;
4225
4226                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4227                 if (s32Error) {
4228                         PRINT_ER("Failed to send get host channel param's message queue ");
4229                         return;
4230                 }
4231         }
4232         g_hPeriodicRSSI.data = (unsigned long)hif_drv;
4233         mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4234 }
4235
4236
4237 void host_int_send_network_info_to_host
4238         (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi)
4239 {
4240 }
4241
4242 static u32 clients_count;
4243
4244 s32 host_int_init(struct host_if_drv **hif_drv_handler)
4245 {
4246         s32 result = 0;
4247         struct host_if_drv *hif_drv;
4248         int err;
4249
4250         PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
4251
4252         gbScanWhileConnected = false;
4253
4254         sema_init(&hWaitResponse, 0);
4255
4256         hif_drv  = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
4257         if (!hif_drv) {
4258                 result = -ENOMEM;
4259                 goto _fail_;
4260         }
4261         *hif_drv_handler = hif_drv;
4262         err = add_handler_in_list(hif_drv);
4263         if (err) {
4264                 result = -EFAULT;
4265                 goto _fail_timer_2;
4266         }
4267
4268         g_obtainingIP = false;
4269
4270         PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", hif_drv);
4271         if (clients_count == 0) {
4272                 sema_init(&hSemHostIFthrdEnd, 0);
4273                 sema_init(&hSemDeinitDrvHandle, 0);
4274                 sema_init(&hSemHostIntDeinit, 1);
4275         }
4276
4277         sema_init(&hif_drv->hSemTestKeyBlock, 0);
4278         sema_init(&hif_drv->hSemTestDisconnectBlock, 0);
4279         sema_init(&hif_drv->hSemGetRSSI, 0);
4280         sema_init(&hif_drv->hSemGetLINKSPEED, 0);
4281         sema_init(&hif_drv->hSemGetCHNL, 0);
4282         sema_init(&hif_drv->hSemInactiveTime, 0);
4283
4284         PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
4285
4286         if (clients_count == 0) {
4287                 result = wilc_mq_create(&gMsgQHostIF);
4288
4289                 if (result < 0) {
4290                         PRINT_ER("Failed to creat MQ\n");
4291                         goto _fail_;
4292                 }
4293                 HostIFthreadHandler = kthread_run(hostIFthread, NULL, "WILC_kthread");
4294                 if (IS_ERR(HostIFthreadHandler)) {
4295                         PRINT_ER("Failed to creat Thread\n");
4296                         result = -EFAULT;
4297                         goto _fail_mq_;
4298                 }
4299                 setup_timer(&g_hPeriodicRSSI, GetPeriodicRSSI,
4300                             (unsigned long)hif_drv);
4301                 mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4302         }
4303
4304         setup_timer(&hif_drv->hScanTimer, TimerCB_Scan, 0);
4305
4306         setup_timer(&hif_drv->hConnectTimer, TimerCB_Connect, 0);
4307
4308         setup_timer(&hif_drv->hRemainOnChannel, ListenTimerCB, 0);
4309
4310         sema_init(&(hif_drv->gtOsCfgValuesSem), 1);
4311         down(&hif_drv->gtOsCfgValuesSem);
4312
4313         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4314         hif_drv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
4315         hif_drv->strCfgValues.scan_source = DEFAULT_SCAN;
4316         hif_drv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
4317         hif_drv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
4318         hif_drv->strCfgValues.curr_tx_rate = AUTORATE;
4319
4320         hif_drv->u64P2p_MgmtTimeout = 0;
4321
4322         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",
4323
4324                    hif_drv->strCfgValues.site_survey_enabled, hif_drv->strCfgValues.scan_source,
4325                    hif_drv->strCfgValues.active_scan_time, hif_drv->strCfgValues.passive_scan_time,
4326                    hif_drv->strCfgValues.curr_tx_rate);
4327
4328         up(&hif_drv->gtOsCfgValuesSem);
4329
4330         clients_count++;
4331
4332         return result;
4333
4334 _fail_timer_2:
4335         up(&hif_drv->gtOsCfgValuesSem);
4336         del_timer_sync(&hif_drv->hConnectTimer);
4337         del_timer_sync(&hif_drv->hScanTimer);
4338         kthread_stop(HostIFthreadHandler);
4339 _fail_mq_:
4340         wilc_mq_destroy(&gMsgQHostIF);
4341 _fail_:
4342         return result;
4343 }
4344
4345 s32 host_int_deinit(struct host_if_drv *hif_drv)
4346 {
4347         s32 s32Error = 0;
4348         struct host_if_msg msg;
4349         int ret;
4350
4351         if (!hif_drv)   {
4352                 PRINT_ER("hif_drv = NULL\n");
4353                 return 0;
4354         }
4355
4356         down(&hSemHostIntDeinit);
4357
4358         terminated_handle = hif_drv;
4359         PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count);
4360
4361         if (del_timer_sync(&hif_drv->hScanTimer)) {
4362                 PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n");
4363         }
4364
4365         if (del_timer_sync(&hif_drv->hConnectTimer)) {
4366                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4367         }
4368
4369
4370         if (del_timer_sync(&g_hPeriodicRSSI)) {
4371                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4372         }
4373
4374         del_timer_sync(&hif_drv->hRemainOnChannel);
4375
4376         host_int_set_wfi_drv_handler(NULL);
4377         down(&hSemDeinitDrvHandle);
4378
4379         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4380                 hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
4381                                                                 hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
4382
4383                 hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
4384         }
4385
4386         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4387
4388         gbScanWhileConnected = false;
4389
4390         memset(&msg, 0, sizeof(struct host_if_msg));
4391
4392         if (clients_count == 1) {
4393                 if (del_timer_sync(&g_hPeriodicRSSI)) {
4394                         PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4395                 }
4396                 msg.id = HOST_IF_MSG_EXIT;
4397                 msg.drv = hif_drv;
4398
4399
4400                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4401                 if (s32Error != 0)
4402                         PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
4403
4404                 down(&hSemHostIFthrdEnd);
4405
4406                 wilc_mq_destroy(&gMsgQHostIF);
4407         }
4408
4409         down(&(hif_drv->gtOsCfgValuesSem));
4410
4411         ret = remove_handler_in_list(hif_drv);
4412         if (ret)
4413                 s32Error = -ENOENT;
4414
4415         kfree(hif_drv);
4416
4417         clients_count--;
4418         terminated_handle = NULL;
4419         up(&hSemHostIntDeinit);
4420         return s32Error;
4421 }
4422
4423 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
4424 {
4425         s32 s32Error = 0;
4426         struct host_if_msg msg;
4427         int id;
4428         struct host_if_drv *hif_drv = NULL;
4429
4430         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4431         hif_drv = get_handler_from_id(id);
4432
4433
4434
4435
4436         if (!hif_drv || hif_drv == terminated_handle)   {
4437                 PRINT_ER("NetworkInfo received but driver not init[%p]\n", hif_drv);
4438                 return;
4439         }
4440
4441         memset(&msg, 0, sizeof(struct host_if_msg));
4442
4443         msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
4444         msg.drv = hif_drv;
4445
4446         msg.body.net_info.u32Length = u32Length;
4447         msg.body.net_info.pu8Buffer = kmalloc(u32Length, GFP_KERNEL);
4448         memcpy(msg.body.net_info.pu8Buffer,
4449                     pu8Buffer, u32Length);
4450
4451         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4452         if (s32Error)
4453                 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
4454 }
4455
4456 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
4457 {
4458         s32 s32Error = 0;
4459         struct host_if_msg msg;
4460         int id;
4461         struct host_if_drv *hif_drv = NULL;
4462
4463         down(&hSemHostIntDeinit);
4464
4465         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4466         hif_drv = get_handler_from_id(id);
4467         PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
4468
4469
4470         if (!hif_drv || hif_drv == terminated_handle) {
4471                 PRINT_D(HOSTINF_DBG, "Wifi driver handler is equal to NULL\n");
4472                 up(&hSemHostIntDeinit);
4473                 return;
4474         }
4475
4476         if (!hif_drv->strWILC_UsrConnReq.pfUserConnectResult) {
4477                 PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n");
4478                 up(&hSemHostIntDeinit);
4479                 return;
4480         }
4481
4482         memset(&msg, 0, sizeof(struct host_if_msg));
4483
4484
4485         msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
4486         msg.drv = hif_drv;
4487
4488
4489         msg.body.async_info.u32Length = u32Length;
4490         msg.body.async_info.pu8Buffer = kmalloc(u32Length, GFP_KERNEL);
4491         memcpy(msg.body.async_info.pu8Buffer,
4492                     pu8Buffer, u32Length);
4493
4494         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4495         if (s32Error)
4496                 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
4497
4498         up(&hSemHostIntDeinit);
4499 }
4500
4501 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
4502 {
4503         s32 s32Error = 0;
4504         struct host_if_msg msg;
4505         int id;
4506         struct host_if_drv *hif_drv = NULL;
4507
4508         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4509         hif_drv = get_handler_from_id(id);
4510
4511
4512         PRINT_D(GENERIC_DBG, "Scan notification received %p\n", hif_drv);
4513
4514         if (!hif_drv || hif_drv == terminated_handle)
4515                 return;
4516
4517         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4518                 memset(&msg, 0, sizeof(struct host_if_msg));
4519
4520                 msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
4521                 msg.drv = hif_drv;
4522
4523                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4524                 if (s32Error)
4525                         PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
4526         }
4527
4528
4529         return;
4530
4531 }
4532
4533 s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID,
4534                                u32 u32duration, u16 chan,
4535                                wilc_remain_on_chan_expired RemainOnChanExpired,
4536                                wilc_remain_on_chan_ready RemainOnChanReady,
4537                                void *pvUserArg)
4538 {
4539         s32 s32Error = 0;
4540         struct host_if_msg msg;
4541
4542         if (!hif_drv) {
4543                 PRINT_ER("driver is null\n");
4544                 return -EFAULT;
4545         }
4546
4547         memset(&msg, 0, sizeof(struct host_if_msg));
4548
4549         msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
4550         msg.body.remain_on_ch.u16Channel = chan;
4551         msg.body.remain_on_ch.pRemainOnChanExpired = RemainOnChanExpired;
4552         msg.body.remain_on_ch.pRemainOnChanReady = RemainOnChanReady;
4553         msg.body.remain_on_ch.pVoid = pvUserArg;
4554         msg.body.remain_on_ch.u32duration = u32duration;
4555         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4556         msg.drv = hif_drv;
4557
4558         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4559         if (s32Error)
4560                 PRINT_ER("wilc mq send fail\n");
4561
4562         return s32Error;
4563 }
4564
4565 s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID)
4566 {
4567         s32 s32Error = 0;
4568         struct host_if_msg msg;
4569
4570         if (!hif_drv) {
4571                 PRINT_ER("driver is null\n");
4572                 return -EFAULT;
4573         }
4574
4575         del_timer(&hif_drv->hRemainOnChannel);
4576
4577         memset(&msg, 0, sizeof(struct host_if_msg));
4578         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
4579         msg.drv = hif_drv;
4580         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4581
4582         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4583         if (s32Error)
4584                 PRINT_ER("wilc mq send fail\n");
4585
4586         return s32Error;
4587 }
4588
4589 s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool bReg)
4590 {
4591         s32 s32Error = 0;
4592         struct host_if_msg msg;
4593
4594         if (!hif_drv) {
4595                 PRINT_ER("driver is null\n");
4596                 return -EFAULT;
4597         }
4598
4599         memset(&msg, 0, sizeof(struct host_if_msg));
4600
4601         msg.id = HOST_IF_MSG_REGISTER_FRAME;
4602         switch (u16FrameType) {
4603         case ACTION:
4604                 PRINT_D(HOSTINF_DBG, "ACTION\n");
4605                 msg.body.reg_frame.u8Regid = ACTION_FRM_IDX;
4606                 break;
4607
4608         case PROBE_REQ:
4609                 PRINT_D(HOSTINF_DBG, "PROBE REQ\n");
4610                 msg.body.reg_frame.u8Regid = PROBE_REQ_IDX;
4611                 break;
4612
4613         default:
4614                 PRINT_D(HOSTINF_DBG, "Not valid frame type\n");
4615                 break;
4616         }
4617         msg.body.reg_frame.u16FrameType = u16FrameType;
4618         msg.body.reg_frame.bReg = bReg;
4619         msg.drv = hif_drv;
4620
4621         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4622         if (s32Error)
4623                 PRINT_ER("wilc mq send fail\n");
4624
4625         return s32Error;
4626
4627
4628 }
4629
4630 s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
4631                         u32 u32DTIMPeriod, u32 u32HeadLen, u8 *pu8Head,
4632                         u32 u32TailLen, u8 *pu8Tail)
4633 {
4634         s32 s32Error = 0;
4635         struct host_if_msg msg;
4636         struct beacon_attr *pstrSetBeaconParam = &msg.body.beacon_info;
4637
4638         if (!hif_drv) {
4639                 PRINT_ER("driver is null\n");
4640                 return -EFAULT;
4641         }
4642
4643         memset(&msg, 0, sizeof(struct host_if_msg));
4644
4645         PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
4646
4647         msg.id = HOST_IF_MSG_ADD_BEACON;
4648         msg.drv = hif_drv;
4649         pstrSetBeaconParam->u32Interval = u32Interval;
4650         pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
4651         pstrSetBeaconParam->u32HeadLen = u32HeadLen;
4652         pstrSetBeaconParam->pu8Head = kmalloc(u32HeadLen, GFP_KERNEL);
4653         if (pstrSetBeaconParam->pu8Head == NULL) {
4654                 s32Error = -ENOMEM;
4655                 goto ERRORHANDLER;
4656         }
4657         memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
4658         pstrSetBeaconParam->u32TailLen = u32TailLen;
4659
4660         if (u32TailLen > 0) {
4661                 pstrSetBeaconParam->pu8Tail = kmalloc(u32TailLen, GFP_KERNEL);
4662                 if (pstrSetBeaconParam->pu8Tail == NULL) {
4663                         s32Error = -ENOMEM;
4664                         goto ERRORHANDLER;
4665                 }
4666                 memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
4667         } else {
4668                 pstrSetBeaconParam->pu8Tail = NULL;
4669         }
4670
4671         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4672         if (s32Error)
4673                 PRINT_ER("wilc mq send fail\n");
4674
4675 ERRORHANDLER:
4676         if (s32Error) {
4677                 if (pstrSetBeaconParam->pu8Head != NULL)
4678                         kfree(pstrSetBeaconParam->pu8Head);
4679
4680                 if (pstrSetBeaconParam->pu8Tail != NULL)
4681                         kfree(pstrSetBeaconParam->pu8Tail);
4682         }
4683
4684         return s32Error;
4685
4686 }
4687
4688 s32 host_int_del_beacon(struct host_if_drv *hif_drv)
4689 {
4690         s32 s32Error = 0;
4691         struct host_if_msg msg;
4692
4693         if (!hif_drv) {
4694                 PRINT_ER("driver is null\n");
4695                 return -EFAULT;
4696         }
4697
4698         msg.id = HOST_IF_MSG_DEL_BEACON;
4699         msg.drv = hif_drv;
4700         PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
4701
4702         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4703         if (s32Error)
4704                 PRINT_ER("wilc_mq_send fail\n");
4705
4706         return s32Error;
4707 }
4708
4709 s32 host_int_add_station(struct host_if_drv *hif_drv,
4710                          struct add_sta_param *pstrStaParams)
4711 {
4712         s32 s32Error = 0;
4713         struct host_if_msg msg;
4714         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4715
4716
4717         if (!hif_drv) {
4718                 PRINT_ER("driver is null\n");
4719                 return -EFAULT;
4720         }
4721
4722         memset(&msg, 0, sizeof(struct host_if_msg));
4723
4724         PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
4725
4726         msg.id = HOST_IF_MSG_ADD_STATION;
4727         msg.drv = hif_drv;
4728
4729         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4730         if (pstrAddStationMsg->u8NumRates > 0) {
4731                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4732
4733                 if (!rates)
4734                         return -ENOMEM;
4735
4736                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4737                 pstrAddStationMsg->pu8Rates = rates;
4738         }
4739
4740
4741         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4742         if (s32Error)
4743                 PRINT_ER("wilc_mq_send fail\n");
4744         return s32Error;
4745 }
4746
4747 s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr)
4748 {
4749         s32 s32Error = 0;
4750         struct host_if_msg msg;
4751         struct del_sta *pstrDelStationMsg = &msg.body.del_sta_info;
4752
4753         if (!hif_drv) {
4754                 PRINT_ER("driver is null\n");
4755                 return -EFAULT;
4756         }
4757
4758         memset(&msg, 0, sizeof(struct host_if_msg));
4759
4760         PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
4761
4762         msg.id = HOST_IF_MSG_DEL_STATION;
4763         msg.drv = hif_drv;
4764
4765         if (pu8MacAddr == NULL)
4766                 memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN);
4767         else
4768                 memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN);
4769
4770         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4771         if (s32Error)
4772                 PRINT_ER("wilc_mq_send fail\n");
4773         return s32Error;
4774 }
4775
4776 s32 host_int_del_allstation(struct host_if_drv *hif_drv,
4777                             u8 pu8MacAddr[][ETH_ALEN])
4778 {
4779         s32 s32Error = 0;
4780         struct host_if_msg msg;
4781         struct del_all_sta *pstrDelAllStationMsg = &msg.body.del_all_sta_info;
4782         u8 au8Zero_Buff[ETH_ALEN] = {0};
4783         u32 i;
4784         u8 u8AssocNumb = 0;
4785
4786
4787         if (!hif_drv) {
4788                 PRINT_ER("driver is null\n");
4789                 return -EFAULT;
4790         }
4791
4792         memset(&msg, 0, sizeof(struct host_if_msg));
4793
4794         PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
4795
4796         msg.id = HOST_IF_MSG_DEL_ALL_STA;
4797         msg.drv = hif_drv;
4798
4799         for (i = 0; i < MAX_NUM_STA; i++) {
4800                 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
4801                         memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN);
4802                         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],
4803                                 pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]);
4804                         u8AssocNumb++;
4805                 }
4806         }
4807         if (!u8AssocNumb) {
4808                 PRINT_D(CFG80211_DBG, "NO ASSOCIATED STAS\n");
4809                 return s32Error;
4810         }
4811
4812         pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb;
4813         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4814
4815
4816         if (s32Error)
4817                 PRINT_ER("wilc_mq_send fail\n");
4818
4819         down(&hWaitResponse);
4820
4821         return s32Error;
4822
4823 }
4824
4825 s32 host_int_edit_station(struct host_if_drv *hif_drv,
4826                           struct add_sta_param *pstrStaParams)
4827 {
4828         s32 s32Error = 0;
4829         struct host_if_msg msg;
4830         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4831
4832         if (!hif_drv) {
4833                 PRINT_ER("driver is null\n");
4834                 return -EFAULT;
4835         }
4836
4837         PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
4838
4839         memset(&msg, 0, sizeof(struct host_if_msg));
4840
4841         msg.id = HOST_IF_MSG_EDIT_STATION;
4842         msg.drv = hif_drv;
4843
4844         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4845         if (pstrAddStationMsg->u8NumRates > 0) {
4846                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4847
4848                 if (!rates)
4849                         return -ENOMEM;
4850
4851                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4852                 pstrAddStationMsg->pu8Rates = rates;
4853         }
4854
4855         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4856         if (s32Error)
4857                 PRINT_ER("wilc_mq_send fail\n");
4858
4859         return s32Error;
4860 }
4861
4862 s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv,
4863                             bool bIsEnabled,
4864                             u32 u32Timeout)
4865 {
4866         s32 s32Error = 0;
4867         struct host_if_msg msg;
4868         struct power_mgmt_param *pstrPowerMgmtParam = &msg.body.pwr_mgmt_info;
4869
4870         PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled);
4871
4872         if (!hif_drv) {
4873                 PRINT_ER("driver is null\n");
4874                 return -EFAULT;
4875         }
4876
4877         PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
4878
4879         memset(&msg, 0, sizeof(struct host_if_msg));
4880
4881         msg.id = HOST_IF_MSG_POWER_MGMT;
4882         msg.drv = hif_drv;
4883
4884         pstrPowerMgmtParam->bIsEnabled = bIsEnabled;
4885         pstrPowerMgmtParam->u32Timeout = u32Timeout;
4886
4887
4888         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4889         if (s32Error)
4890                 PRINT_ER("wilc_mq_send fail\n");
4891         return s32Error;
4892 }
4893
4894 s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv,
4895                                     bool bIsEnabled,
4896                                     u32 u32count)
4897 {
4898         s32 s32Error = 0;
4899         struct host_if_msg msg;
4900         struct set_multicast *pstrMulticastFilterParam = &msg.body.multicast_info;
4901
4902
4903         if (!hif_drv) {
4904                 PRINT_ER("driver is null\n");
4905                 return -EFAULT;
4906         }
4907
4908         PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
4909
4910         memset(&msg, 0, sizeof(struct host_if_msg));
4911
4912         msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
4913         msg.drv = hif_drv;
4914
4915         pstrMulticastFilterParam->bIsEnabled = bIsEnabled;
4916         pstrMulticastFilterParam->u32count = u32count;
4917
4918         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4919         if (s32Error)
4920                 PRINT_ER("wilc_mq_send fail\n");
4921         return s32Error;
4922 }
4923
4924 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
4925 {
4926         struct join_bss_param *pNewJoinBssParam = NULL;
4927         u8 *pu8IEs;
4928         u16 u16IEsLen;
4929         u16 index = 0;
4930         u8 suppRatesNo = 0;
4931         u8 extSuppRatesNo;
4932         u16 jumpOffset;
4933         u8 pcipherCount;
4934         u8 authCount;
4935         u8 pcipherTotalCount = 0;
4936         u8 authTotalCount = 0;
4937         u8 i, j;
4938
4939         pu8IEs = ptstrNetworkInfo->pu8IEs;
4940         u16IEsLen = ptstrNetworkInfo->u16IEsLen;
4941
4942         pNewJoinBssParam = kmalloc(sizeof(struct join_bss_param), GFP_KERNEL);
4943         if (pNewJoinBssParam != NULL) {
4944                 memset(pNewJoinBssParam, 0, sizeof(struct join_bss_param));
4945                 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
4946                 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
4947                 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
4948                 memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
4949                 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
4950                 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
4951                 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
4952                 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
4953
4954                 while (index < u16IEsLen) {
4955                         if (pu8IEs[index] == SUPP_RATES_IE) {
4956                                 suppRatesNo = pu8IEs[index + 1];
4957                                 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
4958                                 index += 2;
4959
4960                                 for (i = 0; i < suppRatesNo; i++) {
4961                                         pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
4962                                 }
4963                                 index += suppRatesNo;
4964                                 continue;
4965                         } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
4966                                 extSuppRatesNo = pu8IEs[index + 1];
4967                                 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
4968                                         pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
4969                                 else
4970                                         pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
4971                                 index += 2;
4972                                 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++) {
4973                                         pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
4974                                 }
4975                                 index += extSuppRatesNo;
4976                                 continue;
4977                         } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
4978                                 pNewJoinBssParam->ht_capable = true;
4979                                 index += pu8IEs[index + 1] + 2;
4980                                 continue;
4981                         } else if ((pu8IEs[index] == WMM_IE) &&
4982                                    (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
4983                                    (pu8IEs[index + 4] == 0xF2) &&
4984                                    (pu8IEs[index + 5] == 0x02) &&
4985                                    ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
4986                                    (pu8IEs[index + 7] == 0x01)) {
4987                                 pNewJoinBssParam->wmm_cap = true;
4988
4989                                 if (pu8IEs[index + 8] & BIT(7))
4990                                         pNewJoinBssParam->uapsd_cap = true;
4991                                 index += pu8IEs[index + 1] + 2;
4992                                 continue;
4993                         } else if ((pu8IEs[index] == P2P_IE) &&
4994                                  (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
4995                                  (pu8IEs[index + 4] == 0x9a) &&
4996                                  (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
4997                                 u16 u16P2P_count;
4998
4999                                 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
5000                                 pNewJoinBssParam->u8NoaEnbaled = 1;
5001                                 pNewJoinBssParam->u8Index = pu8IEs[index + 9];
5002
5003                                 if (pu8IEs[index + 10] & BIT(7)) {
5004                                         pNewJoinBssParam->u8OppEnable = 1;
5005                                         pNewJoinBssParam->u8CtWindow = pu8IEs[index + 10];
5006                                 } else
5007                                         pNewJoinBssParam->u8OppEnable = 0;
5008
5009                                 PRINT_D(GENERIC_DBG, "P2P Dump\n");
5010                                 for (i = 0; i < pu8IEs[index + 7]; i++)
5011                                         PRINT_D(GENERIC_DBG, " %x\n", pu8IEs[index + 9 + i]);
5012
5013                                 pNewJoinBssParam->u8Count = pu8IEs[index + 11];
5014                                 u16P2P_count = index + 12;
5015
5016                                 memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
5017                                 u16P2P_count += 4;
5018
5019                                 memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
5020                                 u16P2P_count += 4;
5021
5022                                 memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
5023
5024                                 index += pu8IEs[index + 1] + 2;
5025                                 continue;
5026
5027                         } else if ((pu8IEs[index] == RSN_IE) ||
5028                                  ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
5029                                   (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
5030                                   (pu8IEs[index + 5] == 0x01))) {
5031                                 u16 rsnIndex = index;
5032
5033                                 if (pu8IEs[rsnIndex] == RSN_IE) {
5034                                         pNewJoinBssParam->mode_802_11i = 2;
5035                                 } else {
5036                                         if (pNewJoinBssParam->mode_802_11i == 0)
5037                                                 pNewJoinBssParam->mode_802_11i = 1;
5038                                         rsnIndex += 4;
5039                                 }
5040
5041                                 rsnIndex += 7;
5042                                 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
5043                                 rsnIndex++;
5044                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5045                                 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5046                                 rsnIndex += 2;
5047
5048                                 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
5049                                         pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5050                                 }
5051                                 pcipherTotalCount += pcipherCount;
5052                                 rsnIndex += jumpOffset;
5053
5054                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5055
5056                                 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5057                                 rsnIndex += 2;
5058
5059                                 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++) {
5060                                         pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5061                                 }
5062                                 authTotalCount += authCount;
5063                                 rsnIndex += jumpOffset;
5064
5065                                 if (pu8IEs[index] == RSN_IE) {
5066                                         pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
5067                                         pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
5068                                         rsnIndex += 2;
5069                                 }
5070                                 pNewJoinBssParam->rsn_found = true;
5071                                 index += pu8IEs[index + 1] + 2;
5072                                 continue;
5073                         } else
5074                                 index += pu8IEs[index + 1] + 2;
5075
5076                 }
5077
5078
5079         }
5080
5081         return (void *)pNewJoinBssParam;
5082
5083 }
5084
5085 void host_int_freeJoinParams(void *pJoinParams)
5086 {
5087         if ((struct bss_param *)pJoinParams != NULL)
5088                 kfree((struct bss_param *)pJoinParams);
5089         else
5090                 PRINT_ER("Unable to FREE null pointer\n");
5091 }
5092
5093 s32 host_int_delBASession(struct host_if_drv *hif_drv, char *pBSSID, char TID)
5094 {
5095         s32 s32Error = 0;
5096         struct host_if_msg msg;
5097         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5098
5099         if (!hif_drv) {
5100                 PRINT_ER("driver is null\n");
5101                 return -EFAULT;
5102         }
5103
5104         memset(&msg, 0, sizeof(struct host_if_msg));
5105
5106         msg.id = HOST_IF_MSG_DEL_BA_SESSION;
5107
5108         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5109         pBASessionInfo->u8Ted = TID;
5110         msg.drv = hif_drv;
5111
5112         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5113         if (s32Error)
5114                 PRINT_ER("wilc_mq_send fail\n");
5115
5116         down(&hWaitResponse);
5117
5118         return s32Error;
5119 }
5120
5121 s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv,
5122                                   char *pBSSID,
5123                                   char TID)
5124 {
5125         s32 s32Error = 0;
5126         struct host_if_msg msg;
5127         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5128
5129         if (!hif_drv) {
5130                 PRINT_ER("driver is null\n");
5131                 return -EFAULT;
5132         }
5133
5134         memset(&msg, 0, sizeof(struct host_if_msg));
5135
5136         msg.id = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
5137
5138         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5139         pBASessionInfo->u8Ted = TID;
5140         msg.drv = hif_drv;
5141
5142         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5143         if (s32Error)
5144                 PRINT_ER("wilc_mq_send fail\n");
5145
5146         down(&hWaitResponse);
5147
5148         return s32Error;
5149 }
5150
5151 s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5152 {
5153         s32 s32Error = 0;
5154         struct host_if_msg msg;
5155
5156         return 0;
5157
5158         if (!hif_drv) {
5159                 PRINT_ER("driver is null\n");
5160                 return -EFAULT;
5161         }
5162
5163         memset(&msg, 0, sizeof(struct host_if_msg));
5164
5165         msg.id = HOST_IF_MSG_SET_IPADDRESS;
5166
5167         msg.body.ip_info.au8IPAddr = u16ipadd;
5168         msg.drv = hif_drv;
5169         msg.body.ip_info.idx = idx;
5170
5171         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5172         if (s32Error)
5173                 PRINT_ER("wilc_mq_send fail\n");
5174
5175         return s32Error;
5176
5177
5178 }
5179
5180 s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5181 {
5182         s32 s32Error = 0;
5183         struct host_if_msg msg;
5184
5185         if (!hif_drv) {
5186                 PRINT_ER("driver is null\n");
5187                 return -EFAULT;
5188         }
5189
5190         memset(&msg, 0, sizeof(struct host_if_msg));
5191
5192         msg.id = HOST_IF_MSG_GET_IPADDRESS;
5193
5194         msg.body.ip_info.au8IPAddr = u16ipadd;
5195         msg.drv = hif_drv;
5196         msg.body.ip_info.idx = idx;
5197
5198         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5199         if (s32Error)
5200                 PRINT_ER("wilc_mq_send fail\n");
5201
5202         return s32Error;
5203
5204
5205 }