]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/wilc1000/host_interface.c
staging: wilc1000: rename pu8ssid of struct connect_attr
[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 *ssid;
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->ssid != NULL) {
1041                 hif_drv->strWILC_UsrConnReq.pu8ssid = kmalloc(pstrHostIFconnectAttr->ssidLen + 1, GFP_KERNEL);
1042                 memcpy(hif_drv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->ssid,
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->ssid, 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->ssid, 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->ssid, 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->ssid, 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->ssid != NULL) {
1135                 memcpy(pu8CurrByte, pstrHostIFconnectAttr->ssid, 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->ssid, 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->ssid != NULL) {
1296                 kfree(pstrHostIFconnectAttr->ssid);
1297                 pstrHostIFconnectAttr->ssid = 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.ssid = kmalloc(ssidLen, GFP_KERNEL);
3630                 memcpy(msg.body.con_info.ssid, pu8ssid, ssidLen);
3631         }
3632
3633         if (pu8IEs != NULL) {
3634                 msg.body.con_info.IEsLen = IEsLen;
3635                 msg.body.con_info.pu8IEs = kmalloc(IEsLen, GFP_KERNEL);
3636                 memcpy(msg.body.con_info.pu8IEs,
3637                             pu8IEs, IEsLen);
3638         }
3639         if (hif_drv->enuHostIFstate < HOST_IF_CONNECTING)
3640                 hif_drv->enuHostIFstate = HOST_IF_CONNECTING;
3641         else
3642                 PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", hif_drv->enuHostIFstate);
3643
3644         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3645         if (s32Error) {
3646                 PRINT_ER("Failed to send message queue: Set join request\n");
3647                 return -EFAULT;
3648         }
3649
3650         enuScanConnTimer = CONNECT_TIMER;
3651         hif_drv->hConnectTimer.data = (unsigned long)hif_drv;
3652         mod_timer(&hif_drv->hConnectTimer,
3653                   jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
3654
3655         return s32Error;
3656 }
3657
3658 s32 host_int_flush_join_req(struct host_if_drv *hif_drv)
3659 {
3660         s32 s32Error = 0;
3661         struct host_if_msg msg;
3662
3663         if (!gu8FlushedJoinReq) {
3664                 s32Error = -EFAULT;
3665                 return s32Error;
3666         }
3667
3668
3669         if (!hif_drv) {
3670                 s32Error = -EFAULT;
3671                 PRINT_ER("Driver is null\n");
3672                 return s32Error;
3673         }
3674
3675         msg.id = HOST_IF_MSG_FLUSH_CONNECT;
3676         msg.drv = hif_drv;
3677
3678         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3679         if (s32Error) {
3680                 PRINT_ER("Failed to send message queue: Flush join request\n");
3681                 return -EFAULT;
3682         }
3683
3684         return s32Error;
3685 }
3686
3687 s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode)
3688 {
3689         s32 s32Error = 0;
3690         struct host_if_msg msg;
3691
3692         if (!hif_drv) {
3693                 PRINT_ER("Driver is null\n");
3694                 return -EFAULT;
3695         }
3696
3697         memset(&msg, 0, sizeof(struct host_if_msg));
3698
3699         msg.id = HOST_IF_MSG_DISCONNECT;
3700         msg.drv = hif_drv;
3701
3702         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3703         if (s32Error)
3704                 PRINT_ER("Failed to send message queue: disconnect\n");
3705
3706         down(&hif_drv->hSemTestDisconnectBlock);
3707
3708         return s32Error;
3709 }
3710
3711 s32 host_int_disconnect_station(struct host_if_drv *hif_drv, u8 assoc_id)
3712 {
3713         struct wid strWID;
3714
3715         strWID.id = (u16)WID_DISCONNECT;
3716         strWID.type = WID_CHAR;
3717         strWID.val = (s8 *)&assoc_id;
3718         strWID.size = sizeof(char);
3719
3720         return 0;
3721 }
3722
3723 s32 host_int_get_assoc_req_info(struct host_if_drv *hif_drv, u8 *pu8AssocReqInfo,
3724                                         u32 u32AssocReqInfoLen)
3725 {
3726         struct wid strWID;
3727
3728         strWID.id = (u16)WID_ASSOC_REQ_INFO;
3729         strWID.type = WID_STR;
3730         strWID.val = pu8AssocReqInfo;
3731         strWID.size = u32AssocReqInfoLen;
3732
3733         return 0;
3734 }
3735
3736 s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv, u8 *pu8AssocRespInfo,
3737                                         u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
3738 {
3739         s32 s32Error = 0;
3740         struct wid strWID;
3741
3742         if (!hif_drv) {
3743                 PRINT_ER("Driver is null\n");
3744                 return -EFAULT;
3745         }
3746
3747         strWID.id = (u16)WID_ASSOC_RES_INFO;
3748         strWID.type = WID_STR;
3749         strWID.val = pu8AssocRespInfo;
3750         strWID.size = u32MaxAssocRespInfoLen;
3751
3752         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3753                                    get_id_from_handler(hif_drv));
3754         if (s32Error) {
3755                 *pu32RcvdAssocRespInfoLen = 0;
3756                 PRINT_ER("Failed to send association response config packet\n");
3757                 return -EINVAL;
3758         } else {
3759                 *pu32RcvdAssocRespInfoLen = strWID.size;
3760         }
3761
3762         return s32Error;
3763 }
3764
3765 s32 host_int_get_rx_power_level(struct host_if_drv *hif_drv, u8 *pu8RxPowerLevel,
3766                                         u32 u32RxPowerLevelLen)
3767 {
3768         struct wid strWID;
3769
3770         strWID.id = (u16)WID_RX_POWER_LEVEL;
3771         strWID.type = WID_STR;
3772         strWID.val = pu8RxPowerLevel;
3773         strWID.size = u32RxPowerLevelLen;
3774
3775         return 0;
3776 }
3777
3778 int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel)
3779 {
3780         int result;
3781         struct host_if_msg msg;
3782
3783         if (!hif_drv) {
3784                 PRINT_ER("driver is null\n");
3785                 return -EFAULT;
3786         }
3787
3788         memset(&msg, 0, sizeof(struct host_if_msg));
3789         msg.id = HOST_IF_MSG_SET_CHANNEL;
3790         msg.body.channel_info.u8SetChan = channel;
3791         msg.drv = hif_drv;
3792
3793         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3794         if (result) {
3795                 PRINT_ER("wilc mq send fail\n");
3796                 return -EINVAL;
3797         }
3798
3799         return 0;
3800 }
3801
3802 int host_int_wait_msg_queue_idle(void)
3803 {
3804         int result = 0;
3805
3806         struct host_if_msg msg;
3807         memset(&msg, 0, sizeof(struct host_if_msg));
3808         msg.id = HOST_IF_MSG_Q_IDLE;
3809         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3810         if (result) {
3811                 PRINT_ER("wilc mq send fail\n");
3812                 result = -EINVAL;
3813         }
3814
3815         down(&hWaitResponse);
3816
3817         return result;
3818 }
3819
3820 int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv)
3821 {
3822         int result = 0;
3823
3824         struct host_if_msg msg;
3825         memset(&msg, 0, sizeof(struct host_if_msg));
3826         msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
3827         msg.body.drv.u32Address = get_id_from_handler(hif_drv);
3828         msg.drv = hif_drv;
3829
3830         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3831         if (result) {
3832                 PRINT_ER("wilc mq send fail\n");
3833                 result = -EINVAL;
3834         }
3835
3836         return result;
3837 }
3838
3839 int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode)
3840 {
3841         int result = 0;
3842
3843         struct host_if_msg msg;
3844         memset(&msg, 0, sizeof(struct host_if_msg));
3845         msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
3846         msg.body.mode.u32Mode = mode;
3847         msg.drv = hif_drv;
3848
3849         result = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3850         if (result) {
3851                 PRINT_ER("wilc mq send fail\n");
3852                 result = -EINVAL;
3853         }
3854
3855         return result;
3856 }
3857
3858 s32 host_int_get_host_chnl_num(struct host_if_drv *hif_drv, u8 *pu8ChNo)
3859 {
3860         s32 s32Error = 0;
3861         struct host_if_msg msg;
3862
3863         if (!hif_drv) {
3864                 PRINT_ER("driver is null\n");
3865                 return -EFAULT;
3866         }
3867
3868         memset(&msg, 0, sizeof(struct host_if_msg));
3869
3870         msg.id = HOST_IF_MSG_GET_CHNL;
3871         msg.drv = hif_drv;
3872
3873         s32Error =      wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3874         if (s32Error)
3875                 PRINT_ER("wilc mq send fail\n");
3876         down(&hif_drv->hSemGetCHNL);
3877
3878         *pu8ChNo = gu8Chnl;
3879
3880         return s32Error;
3881
3882
3883 }
3884
3885 s32 host_int_get_inactive_time(struct host_if_drv *hif_drv,
3886                                const u8 *mac, u32 *pu32InactiveTime)
3887 {
3888         s32 s32Error = 0;
3889         struct host_if_msg msg;
3890
3891         if (!hif_drv) {
3892                 PRINT_ER("driver is null\n");
3893                 return -EFAULT;
3894         }
3895
3896         memset(&msg, 0, sizeof(struct host_if_msg));
3897
3898
3899         memcpy(msg.body.mac_info.mac,
3900                     mac, ETH_ALEN);
3901
3902         msg.id = HOST_IF_MSG_GET_INACTIVETIME;
3903         msg.drv = hif_drv;
3904
3905         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3906         if (s32Error)
3907                 PRINT_ER("Failed to send get host channel param's message queue ");
3908
3909         down(&hif_drv->hSemInactiveTime);
3910
3911         *pu32InactiveTime = gu32InactiveTime;
3912
3913         return s32Error;
3914 }
3915
3916 s32 host_int_test_get_int_wid(struct host_if_drv *hif_drv, u32 *pu32TestMemAddr)
3917 {
3918
3919         s32 s32Error = 0;
3920         struct wid strWID;
3921
3922         if (!hif_drv) {
3923                 PRINT_ER("driver is null\n");
3924                 return -EFAULT;
3925         }
3926
3927         strWID.id = (u16)WID_MEMORY_ADDRESS;
3928         strWID.type = WID_INT;
3929         strWID.val = (s8 *)pu32TestMemAddr;
3930         strWID.size = sizeof(u32);
3931
3932         s32Error = send_config_pkt(GET_CFG, &strWID, 1,
3933                                    get_id_from_handler(hif_drv));
3934
3935         if (s32Error) {
3936                 PRINT_ER("Failed to get wid value\n");
3937                 return -EINVAL;
3938         } else {
3939                 PRINT_D(HOSTINF_DBG, "Successfully got wid value\n");
3940
3941         }
3942
3943         return s32Error;
3944 }
3945
3946 s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi)
3947 {
3948         s32 s32Error = 0;
3949         struct host_if_msg msg;
3950         memset(&msg, 0, sizeof(struct host_if_msg));
3951
3952         msg.id = HOST_IF_MSG_GET_RSSI;
3953         msg.drv = hif_drv;
3954
3955         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3956         if (s32Error) {
3957                 PRINT_ER("Failed to send get host channel param's message queue ");
3958                 return -EFAULT;
3959         }
3960
3961         down(&hif_drv->hSemGetRSSI);
3962
3963
3964         if (ps8Rssi == NULL) {
3965                 PRINT_ER("RSS pointer value is null");
3966                 return -EFAULT;
3967         }
3968
3969
3970         *ps8Rssi = gs8Rssi;
3971
3972
3973         return s32Error;
3974 }
3975
3976 s32 host_int_get_link_speed(struct host_if_drv *hif_drv, s8 *ps8lnkspd)
3977 {
3978         struct host_if_msg msg;
3979         s32 s32Error = 0;
3980         memset(&msg, 0, sizeof(struct host_if_msg));
3981
3982         msg.id = HOST_IF_MSG_GET_LINKSPEED;
3983         msg.drv = hif_drv;
3984
3985         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
3986         if (s32Error) {
3987                 PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
3988                 return -EFAULT;
3989         }
3990
3991         down(&hif_drv->hSemGetLINKSPEED);
3992
3993
3994         if (ps8lnkspd == NULL) {
3995                 PRINT_ER("LINKSPEED pointer value is null");
3996                 return -EFAULT;
3997         }
3998
3999
4000         *ps8lnkspd = gs8lnkspd;
4001
4002
4003         return s32Error;
4004 }
4005
4006 s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
4007 {
4008         s32 s32Error = 0;
4009         struct host_if_msg msg;
4010         memset(&msg, 0, sizeof(struct host_if_msg));
4011
4012         msg.id = HOST_IF_MSG_GET_STATISTICS;
4013         msg.body.data = (char *)pstrStatistics;
4014         msg.drv = hif_drv;
4015
4016         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4017         if (s32Error) {
4018                 PRINT_ER("Failed to send get host channel param's message queue ");
4019                 return -EFAULT;
4020         }
4021
4022         down(&hWaitResponse);
4023         return s32Error;
4024 }
4025
4026 s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource,
4027                   u8 u8ScanType, u8 *pu8ChnlFreqList,
4028                   u8 u8ChnlListLen, const u8 *pu8IEs,
4029                   size_t IEsLen, wilc_scan_result ScanResult,
4030                   void *pvUserArg, struct hidden_network *pstrHiddenNetwork)
4031 {
4032         s32 s32Error = 0;
4033         struct host_if_msg msg;
4034         enum scan_conn_timer enuScanConnTimer;
4035
4036         if (!hif_drv || ScanResult == NULL) {
4037                 PRINT_ER("hif_drv or ScanResult = NULL\n");
4038                 return -EFAULT;
4039         }
4040
4041         memset(&msg, 0, sizeof(struct host_if_msg));
4042
4043         msg.id = HOST_IF_MSG_SCAN;
4044
4045         if (pstrHiddenNetwork != NULL) {
4046                 msg.body.scan_info.hidden_network.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
4047                 msg.body.scan_info.hidden_network.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
4048
4049         } else
4050                 PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n");
4051
4052         msg.drv = hif_drv;
4053         msg.body.scan_info.src = u8ScanSource;
4054         msg.body.scan_info.type = u8ScanType;
4055         msg.body.scan_info.result = ScanResult;
4056         msg.body.scan_info.arg = pvUserArg;
4057
4058         msg.body.scan_info.ch_list_len = u8ChnlListLen;
4059         msg.body.scan_info.ch_freq_list = kmalloc(u8ChnlListLen, GFP_KERNEL);
4060         memcpy(msg.body.scan_info.ch_freq_list, pu8ChnlFreqList, u8ChnlListLen);
4061
4062         msg.body.scan_info.ies_len = IEsLen;
4063         msg.body.scan_info.ies = kmalloc(IEsLen, GFP_KERNEL);
4064         memcpy(msg.body.scan_info.ies, pu8IEs, IEsLen);
4065
4066         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4067         if (s32Error) {
4068                 PRINT_ER("Error in sending message queue\n");
4069                 return -EINVAL;
4070         }
4071
4072         enuScanConnTimer = SCAN_TIMER;
4073         PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
4074         hif_drv->hScanTimer.data = (unsigned long)hif_drv;
4075         mod_timer(&hif_drv->hScanTimer,
4076                   jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
4077
4078         return s32Error;
4079
4080 }
4081
4082 s32 hif_set_cfg(struct host_if_drv *hif_drv,
4083                 struct cfg_param_val *pstrCfgParamVal)
4084 {
4085
4086         s32 s32Error = 0;
4087         struct host_if_msg msg;
4088
4089
4090         if (!hif_drv) {
4091                 PRINT_ER("hif_drv NULL\n");
4092                 return -EFAULT;
4093         }
4094
4095         memset(&msg, 0, sizeof(struct host_if_msg));
4096         msg.id = HOST_IF_MSG_CFG_PARAMS;
4097         msg.body.cfg_info.cfg_attr_info = *pstrCfgParamVal;
4098         msg.drv = hif_drv;
4099
4100         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4101
4102         return s32Error;
4103
4104 }
4105
4106 s32 hif_get_cfg(struct host_if_drv *hif_drv, u16 u16WID, u16 *pu16WID_Value)
4107 {
4108         s32 s32Error = 0;
4109
4110         down(&hif_drv->gtOsCfgValuesSem);
4111
4112         if (!hif_drv) {
4113                 PRINT_ER("hif_drv NULL\n");
4114                 return -EFAULT;
4115         }
4116         PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
4117         switch (u16WID) {
4118
4119         case WID_BSS_TYPE:
4120                 *pu16WID_Value = (u16)hif_drv->strCfgValues.bss_type;
4121                 break;
4122
4123         case WID_AUTH_TYPE:
4124                 *pu16WID_Value = (u16)hif_drv->strCfgValues.auth_type;
4125                 break;
4126
4127         case WID_AUTH_TIMEOUT:
4128                 *pu16WID_Value = hif_drv->strCfgValues.auth_timeout;
4129                 break;
4130
4131         case WID_POWER_MANAGEMENT:
4132                 *pu16WID_Value = (u16)hif_drv->strCfgValues.power_mgmt_mode;
4133                 break;
4134
4135         case WID_SHORT_RETRY_LIMIT:
4136                 *pu16WID_Value =       hif_drv->strCfgValues.short_retry_limit;
4137                 break;
4138
4139         case WID_LONG_RETRY_LIMIT:
4140                 *pu16WID_Value = hif_drv->strCfgValues.long_retry_limit;
4141                 break;
4142
4143         case WID_FRAG_THRESHOLD:
4144                 *pu16WID_Value = hif_drv->strCfgValues.frag_threshold;
4145                 break;
4146
4147         case WID_RTS_THRESHOLD:
4148                 *pu16WID_Value = hif_drv->strCfgValues.rts_threshold;
4149                 break;
4150
4151         case WID_PREAMBLE:
4152                 *pu16WID_Value = (u16)hif_drv->strCfgValues.preamble_type;
4153                 break;
4154
4155         case WID_SHORT_SLOT_ALLOWED:
4156                 *pu16WID_Value = (u16) hif_drv->strCfgValues.short_slot_allowed;
4157                 break;
4158
4159         case WID_11N_TXOP_PROT_DISABLE:
4160                 *pu16WID_Value = (u16)hif_drv->strCfgValues.txop_prot_disabled;
4161                 break;
4162
4163         case WID_BEACON_INTERVAL:
4164                 *pu16WID_Value = hif_drv->strCfgValues.beacon_interval;
4165                 break;
4166
4167         case WID_DTIM_PERIOD:
4168                 *pu16WID_Value = (u16)hif_drv->strCfgValues.dtim_period;
4169                 break;
4170
4171         case WID_SITE_SURVEY:
4172                 *pu16WID_Value = (u16)hif_drv->strCfgValues.site_survey_enabled;
4173                 break;
4174
4175         case WID_SITE_SURVEY_SCAN_TIME:
4176                 *pu16WID_Value = hif_drv->strCfgValues.site_survey_scan_time;
4177                 break;
4178
4179         case WID_ACTIVE_SCAN_TIME:
4180                 *pu16WID_Value = hif_drv->strCfgValues.active_scan_time;
4181                 break;
4182
4183         case WID_PASSIVE_SCAN_TIME:
4184                 *pu16WID_Value = hif_drv->strCfgValues.passive_scan_time;
4185                 break;
4186
4187         case WID_CURRENT_TX_RATE:
4188                 *pu16WID_Value = hif_drv->strCfgValues.curr_tx_rate;
4189                 break;
4190
4191         default:
4192                 break;
4193         }
4194
4195         up(&hif_drv->gtOsCfgValuesSem);
4196
4197         return s32Error;
4198
4199 }
4200
4201 void host_int_send_join_leave_info_to_host
4202         (u16 assocId, u8 *stationAddr, bool joining)
4203 {
4204 }
4205
4206 static void GetPeriodicRSSI(unsigned long arg)
4207 {
4208         struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
4209
4210         if (!hif_drv)   {
4211                 PRINT_ER("Driver handler is NULL\n");
4212                 return;
4213         }
4214
4215         if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) {
4216                 s32 s32Error = 0;
4217                 struct host_if_msg msg;
4218
4219                 memset(&msg, 0, sizeof(struct host_if_msg));
4220
4221                 msg.id = HOST_IF_MSG_GET_RSSI;
4222                 msg.drv = hif_drv;
4223
4224                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4225                 if (s32Error) {
4226                         PRINT_ER("Failed to send get host channel param's message queue ");
4227                         return;
4228                 }
4229         }
4230         g_hPeriodicRSSI.data = (unsigned long)hif_drv;
4231         mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4232 }
4233
4234
4235 void host_int_send_network_info_to_host
4236         (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi)
4237 {
4238 }
4239
4240 static u32 clients_count;
4241
4242 s32 host_int_init(struct host_if_drv **hif_drv_handler)
4243 {
4244         s32 result = 0;
4245         struct host_if_drv *hif_drv;
4246         int err;
4247
4248         PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
4249
4250         gbScanWhileConnected = false;
4251
4252         sema_init(&hWaitResponse, 0);
4253
4254         hif_drv  = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
4255         if (!hif_drv) {
4256                 result = -ENOMEM;
4257                 goto _fail_;
4258         }
4259         *hif_drv_handler = hif_drv;
4260         err = add_handler_in_list(hif_drv);
4261         if (err) {
4262                 result = -EFAULT;
4263                 goto _fail_timer_2;
4264         }
4265
4266         g_obtainingIP = false;
4267
4268         PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", hif_drv);
4269         if (clients_count == 0) {
4270                 sema_init(&hSemHostIFthrdEnd, 0);
4271                 sema_init(&hSemDeinitDrvHandle, 0);
4272                 sema_init(&hSemHostIntDeinit, 1);
4273         }
4274
4275         sema_init(&hif_drv->hSemTestKeyBlock, 0);
4276         sema_init(&hif_drv->hSemTestDisconnectBlock, 0);
4277         sema_init(&hif_drv->hSemGetRSSI, 0);
4278         sema_init(&hif_drv->hSemGetLINKSPEED, 0);
4279         sema_init(&hif_drv->hSemGetCHNL, 0);
4280         sema_init(&hif_drv->hSemInactiveTime, 0);
4281
4282         PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
4283
4284         if (clients_count == 0) {
4285                 result = wilc_mq_create(&gMsgQHostIF);
4286
4287                 if (result < 0) {
4288                         PRINT_ER("Failed to creat MQ\n");
4289                         goto _fail_;
4290                 }
4291                 HostIFthreadHandler = kthread_run(hostIFthread, NULL, "WILC_kthread");
4292                 if (IS_ERR(HostIFthreadHandler)) {
4293                         PRINT_ER("Failed to creat Thread\n");
4294                         result = -EFAULT;
4295                         goto _fail_mq_;
4296                 }
4297                 setup_timer(&g_hPeriodicRSSI, GetPeriodicRSSI,
4298                             (unsigned long)hif_drv);
4299                 mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
4300         }
4301
4302         setup_timer(&hif_drv->hScanTimer, TimerCB_Scan, 0);
4303
4304         setup_timer(&hif_drv->hConnectTimer, TimerCB_Connect, 0);
4305
4306         setup_timer(&hif_drv->hRemainOnChannel, ListenTimerCB, 0);
4307
4308         sema_init(&(hif_drv->gtOsCfgValuesSem), 1);
4309         down(&hif_drv->gtOsCfgValuesSem);
4310
4311         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4312         hif_drv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
4313         hif_drv->strCfgValues.scan_source = DEFAULT_SCAN;
4314         hif_drv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
4315         hif_drv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
4316         hif_drv->strCfgValues.curr_tx_rate = AUTORATE;
4317
4318         hif_drv->u64P2p_MgmtTimeout = 0;
4319
4320         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",
4321
4322                    hif_drv->strCfgValues.site_survey_enabled, hif_drv->strCfgValues.scan_source,
4323                    hif_drv->strCfgValues.active_scan_time, hif_drv->strCfgValues.passive_scan_time,
4324                    hif_drv->strCfgValues.curr_tx_rate);
4325
4326         up(&hif_drv->gtOsCfgValuesSem);
4327
4328         clients_count++;
4329
4330         return result;
4331
4332 _fail_timer_2:
4333         up(&hif_drv->gtOsCfgValuesSem);
4334         del_timer_sync(&hif_drv->hConnectTimer);
4335         del_timer_sync(&hif_drv->hScanTimer);
4336         kthread_stop(HostIFthreadHandler);
4337 _fail_mq_:
4338         wilc_mq_destroy(&gMsgQHostIF);
4339 _fail_:
4340         return result;
4341 }
4342
4343 s32 host_int_deinit(struct host_if_drv *hif_drv)
4344 {
4345         s32 s32Error = 0;
4346         struct host_if_msg msg;
4347         int ret;
4348
4349         if (!hif_drv)   {
4350                 PRINT_ER("hif_drv = NULL\n");
4351                 return 0;
4352         }
4353
4354         down(&hSemHostIntDeinit);
4355
4356         terminated_handle = hif_drv;
4357         PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count);
4358
4359         if (del_timer_sync(&hif_drv->hScanTimer)) {
4360                 PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n");
4361         }
4362
4363         if (del_timer_sync(&hif_drv->hConnectTimer)) {
4364                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4365         }
4366
4367
4368         if (del_timer_sync(&g_hPeriodicRSSI)) {
4369                 PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4370         }
4371
4372         del_timer_sync(&hif_drv->hRemainOnChannel);
4373
4374         host_int_set_wfi_drv_handler(NULL);
4375         down(&hSemDeinitDrvHandle);
4376
4377         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4378                 hif_drv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
4379                                                                 hif_drv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
4380
4381                 hif_drv->strWILC_UsrScanReq.pfUserScanResult = NULL;
4382         }
4383
4384         hif_drv->enuHostIFstate = HOST_IF_IDLE;
4385
4386         gbScanWhileConnected = false;
4387
4388         memset(&msg, 0, sizeof(struct host_if_msg));
4389
4390         if (clients_count == 1) {
4391                 if (del_timer_sync(&g_hPeriodicRSSI)) {
4392                         PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
4393                 }
4394                 msg.id = HOST_IF_MSG_EXIT;
4395                 msg.drv = hif_drv;
4396
4397
4398                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4399                 if (s32Error != 0)
4400                         PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
4401
4402                 down(&hSemHostIFthrdEnd);
4403
4404                 wilc_mq_destroy(&gMsgQHostIF);
4405         }
4406
4407         down(&(hif_drv->gtOsCfgValuesSem));
4408
4409         ret = remove_handler_in_list(hif_drv);
4410         if (ret)
4411                 s32Error = -ENOENT;
4412
4413         kfree(hif_drv);
4414
4415         clients_count--;
4416         terminated_handle = NULL;
4417         up(&hSemHostIntDeinit);
4418         return s32Error;
4419 }
4420
4421 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
4422 {
4423         s32 s32Error = 0;
4424         struct host_if_msg msg;
4425         int id;
4426         struct host_if_drv *hif_drv = NULL;
4427
4428         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4429         hif_drv = get_handler_from_id(id);
4430
4431
4432
4433
4434         if (!hif_drv || hif_drv == terminated_handle)   {
4435                 PRINT_ER("NetworkInfo received but driver not init[%p]\n", hif_drv);
4436                 return;
4437         }
4438
4439         memset(&msg, 0, sizeof(struct host_if_msg));
4440
4441         msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
4442         msg.drv = hif_drv;
4443
4444         msg.body.net_info.u32Length = u32Length;
4445         msg.body.net_info.pu8Buffer = kmalloc(u32Length, GFP_KERNEL);
4446         memcpy(msg.body.net_info.pu8Buffer,
4447                     pu8Buffer, u32Length);
4448
4449         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4450         if (s32Error)
4451                 PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
4452 }
4453
4454 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
4455 {
4456         s32 s32Error = 0;
4457         struct host_if_msg msg;
4458         int id;
4459         struct host_if_drv *hif_drv = NULL;
4460
4461         down(&hSemHostIntDeinit);
4462
4463         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4464         hif_drv = get_handler_from_id(id);
4465         PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
4466
4467
4468         if (!hif_drv || hif_drv == terminated_handle) {
4469                 PRINT_D(HOSTINF_DBG, "Wifi driver handler is equal to NULL\n");
4470                 up(&hSemHostIntDeinit);
4471                 return;
4472         }
4473
4474         if (!hif_drv->strWILC_UsrConnReq.pfUserConnectResult) {
4475                 PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n");
4476                 up(&hSemHostIntDeinit);
4477                 return;
4478         }
4479
4480         memset(&msg, 0, sizeof(struct host_if_msg));
4481
4482
4483         msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
4484         msg.drv = hif_drv;
4485
4486
4487         msg.body.async_info.u32Length = u32Length;
4488         msg.body.async_info.pu8Buffer = kmalloc(u32Length, GFP_KERNEL);
4489         memcpy(msg.body.async_info.pu8Buffer,
4490                     pu8Buffer, u32Length);
4491
4492         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4493         if (s32Error)
4494                 PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
4495
4496         up(&hSemHostIntDeinit);
4497 }
4498
4499 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
4500 {
4501         s32 s32Error = 0;
4502         struct host_if_msg msg;
4503         int id;
4504         struct host_if_drv *hif_drv = NULL;
4505
4506         id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
4507         hif_drv = get_handler_from_id(id);
4508
4509
4510         PRINT_D(GENERIC_DBG, "Scan notification received %p\n", hif_drv);
4511
4512         if (!hif_drv || hif_drv == terminated_handle)
4513                 return;
4514
4515         if (hif_drv->strWILC_UsrScanReq.pfUserScanResult) {
4516                 memset(&msg, 0, sizeof(struct host_if_msg));
4517
4518                 msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
4519                 msg.drv = hif_drv;
4520
4521                 s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4522                 if (s32Error)
4523                         PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
4524         }
4525
4526
4527         return;
4528
4529 }
4530
4531 s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID,
4532                                u32 u32duration, u16 chan,
4533                                wilc_remain_on_chan_expired RemainOnChanExpired,
4534                                wilc_remain_on_chan_ready RemainOnChanReady,
4535                                void *pvUserArg)
4536 {
4537         s32 s32Error = 0;
4538         struct host_if_msg msg;
4539
4540         if (!hif_drv) {
4541                 PRINT_ER("driver is null\n");
4542                 return -EFAULT;
4543         }
4544
4545         memset(&msg, 0, sizeof(struct host_if_msg));
4546
4547         msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
4548         msg.body.remain_on_ch.u16Channel = chan;
4549         msg.body.remain_on_ch.pRemainOnChanExpired = RemainOnChanExpired;
4550         msg.body.remain_on_ch.pRemainOnChanReady = RemainOnChanReady;
4551         msg.body.remain_on_ch.pVoid = pvUserArg;
4552         msg.body.remain_on_ch.u32duration = u32duration;
4553         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4554         msg.drv = hif_drv;
4555
4556         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4557         if (s32Error)
4558                 PRINT_ER("wilc mq send fail\n");
4559
4560         return s32Error;
4561 }
4562
4563 s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID)
4564 {
4565         s32 s32Error = 0;
4566         struct host_if_msg msg;
4567
4568         if (!hif_drv) {
4569                 PRINT_ER("driver is null\n");
4570                 return -EFAULT;
4571         }
4572
4573         del_timer(&hif_drv->hRemainOnChannel);
4574
4575         memset(&msg, 0, sizeof(struct host_if_msg));
4576         msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
4577         msg.drv = hif_drv;
4578         msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
4579
4580         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4581         if (s32Error)
4582                 PRINT_ER("wilc mq send fail\n");
4583
4584         return s32Error;
4585 }
4586
4587 s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool bReg)
4588 {
4589         s32 s32Error = 0;
4590         struct host_if_msg msg;
4591
4592         if (!hif_drv) {
4593                 PRINT_ER("driver is null\n");
4594                 return -EFAULT;
4595         }
4596
4597         memset(&msg, 0, sizeof(struct host_if_msg));
4598
4599         msg.id = HOST_IF_MSG_REGISTER_FRAME;
4600         switch (u16FrameType) {
4601         case ACTION:
4602                 PRINT_D(HOSTINF_DBG, "ACTION\n");
4603                 msg.body.reg_frame.u8Regid = ACTION_FRM_IDX;
4604                 break;
4605
4606         case PROBE_REQ:
4607                 PRINT_D(HOSTINF_DBG, "PROBE REQ\n");
4608                 msg.body.reg_frame.u8Regid = PROBE_REQ_IDX;
4609                 break;
4610
4611         default:
4612                 PRINT_D(HOSTINF_DBG, "Not valid frame type\n");
4613                 break;
4614         }
4615         msg.body.reg_frame.u16FrameType = u16FrameType;
4616         msg.body.reg_frame.bReg = bReg;
4617         msg.drv = hif_drv;
4618
4619         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4620         if (s32Error)
4621                 PRINT_ER("wilc mq send fail\n");
4622
4623         return s32Error;
4624
4625
4626 }
4627
4628 s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
4629                         u32 u32DTIMPeriod, u32 u32HeadLen, u8 *pu8Head,
4630                         u32 u32TailLen, u8 *pu8Tail)
4631 {
4632         s32 s32Error = 0;
4633         struct host_if_msg msg;
4634         struct beacon_attr *pstrSetBeaconParam = &msg.body.beacon_info;
4635
4636         if (!hif_drv) {
4637                 PRINT_ER("driver is null\n");
4638                 return -EFAULT;
4639         }
4640
4641         memset(&msg, 0, sizeof(struct host_if_msg));
4642
4643         PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
4644
4645         msg.id = HOST_IF_MSG_ADD_BEACON;
4646         msg.drv = hif_drv;
4647         pstrSetBeaconParam->u32Interval = u32Interval;
4648         pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
4649         pstrSetBeaconParam->u32HeadLen = u32HeadLen;
4650         pstrSetBeaconParam->pu8Head = kmalloc(u32HeadLen, GFP_KERNEL);
4651         if (pstrSetBeaconParam->pu8Head == NULL) {
4652                 s32Error = -ENOMEM;
4653                 goto ERRORHANDLER;
4654         }
4655         memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
4656         pstrSetBeaconParam->u32TailLen = u32TailLen;
4657
4658         if (u32TailLen > 0) {
4659                 pstrSetBeaconParam->pu8Tail = kmalloc(u32TailLen, GFP_KERNEL);
4660                 if (pstrSetBeaconParam->pu8Tail == NULL) {
4661                         s32Error = -ENOMEM;
4662                         goto ERRORHANDLER;
4663                 }
4664                 memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
4665         } else {
4666                 pstrSetBeaconParam->pu8Tail = NULL;
4667         }
4668
4669         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4670         if (s32Error)
4671                 PRINT_ER("wilc mq send fail\n");
4672
4673 ERRORHANDLER:
4674         if (s32Error) {
4675                 if (pstrSetBeaconParam->pu8Head != NULL)
4676                         kfree(pstrSetBeaconParam->pu8Head);
4677
4678                 if (pstrSetBeaconParam->pu8Tail != NULL)
4679                         kfree(pstrSetBeaconParam->pu8Tail);
4680         }
4681
4682         return s32Error;
4683
4684 }
4685
4686 s32 host_int_del_beacon(struct host_if_drv *hif_drv)
4687 {
4688         s32 s32Error = 0;
4689         struct host_if_msg msg;
4690
4691         if (!hif_drv) {
4692                 PRINT_ER("driver is null\n");
4693                 return -EFAULT;
4694         }
4695
4696         msg.id = HOST_IF_MSG_DEL_BEACON;
4697         msg.drv = hif_drv;
4698         PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
4699
4700         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4701         if (s32Error)
4702                 PRINT_ER("wilc_mq_send fail\n");
4703
4704         return s32Error;
4705 }
4706
4707 s32 host_int_add_station(struct host_if_drv *hif_drv,
4708                          struct add_sta_param *pstrStaParams)
4709 {
4710         s32 s32Error = 0;
4711         struct host_if_msg msg;
4712         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4713
4714
4715         if (!hif_drv) {
4716                 PRINT_ER("driver is null\n");
4717                 return -EFAULT;
4718         }
4719
4720         memset(&msg, 0, sizeof(struct host_if_msg));
4721
4722         PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
4723
4724         msg.id = HOST_IF_MSG_ADD_STATION;
4725         msg.drv = hif_drv;
4726
4727         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4728         if (pstrAddStationMsg->u8NumRates > 0) {
4729                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4730
4731                 if (!rates)
4732                         return -ENOMEM;
4733
4734                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4735                 pstrAddStationMsg->pu8Rates = rates;
4736         }
4737
4738
4739         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4740         if (s32Error)
4741                 PRINT_ER("wilc_mq_send fail\n");
4742         return s32Error;
4743 }
4744
4745 s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr)
4746 {
4747         s32 s32Error = 0;
4748         struct host_if_msg msg;
4749         struct del_sta *pstrDelStationMsg = &msg.body.del_sta_info;
4750
4751         if (!hif_drv) {
4752                 PRINT_ER("driver is null\n");
4753                 return -EFAULT;
4754         }
4755
4756         memset(&msg, 0, sizeof(struct host_if_msg));
4757
4758         PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
4759
4760         msg.id = HOST_IF_MSG_DEL_STATION;
4761         msg.drv = hif_drv;
4762
4763         if (pu8MacAddr == NULL)
4764                 memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN);
4765         else
4766                 memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN);
4767
4768         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4769         if (s32Error)
4770                 PRINT_ER("wilc_mq_send fail\n");
4771         return s32Error;
4772 }
4773
4774 s32 host_int_del_allstation(struct host_if_drv *hif_drv,
4775                             u8 pu8MacAddr[][ETH_ALEN])
4776 {
4777         s32 s32Error = 0;
4778         struct host_if_msg msg;
4779         struct del_all_sta *pstrDelAllStationMsg = &msg.body.del_all_sta_info;
4780         u8 au8Zero_Buff[ETH_ALEN] = {0};
4781         u32 i;
4782         u8 u8AssocNumb = 0;
4783
4784
4785         if (!hif_drv) {
4786                 PRINT_ER("driver is null\n");
4787                 return -EFAULT;
4788         }
4789
4790         memset(&msg, 0, sizeof(struct host_if_msg));
4791
4792         PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
4793
4794         msg.id = HOST_IF_MSG_DEL_ALL_STA;
4795         msg.drv = hif_drv;
4796
4797         for (i = 0; i < MAX_NUM_STA; i++) {
4798                 if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
4799                         memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN);
4800                         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],
4801                                 pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]);
4802                         u8AssocNumb++;
4803                 }
4804         }
4805         if (!u8AssocNumb) {
4806                 PRINT_D(CFG80211_DBG, "NO ASSOCIATED STAS\n");
4807                 return s32Error;
4808         }
4809
4810         pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb;
4811         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4812
4813
4814         if (s32Error)
4815                 PRINT_ER("wilc_mq_send fail\n");
4816
4817         down(&hWaitResponse);
4818
4819         return s32Error;
4820
4821 }
4822
4823 s32 host_int_edit_station(struct host_if_drv *hif_drv,
4824                           struct add_sta_param *pstrStaParams)
4825 {
4826         s32 s32Error = 0;
4827         struct host_if_msg msg;
4828         struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
4829
4830         if (!hif_drv) {
4831                 PRINT_ER("driver is null\n");
4832                 return -EFAULT;
4833         }
4834
4835         PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
4836
4837         memset(&msg, 0, sizeof(struct host_if_msg));
4838
4839         msg.id = HOST_IF_MSG_EDIT_STATION;
4840         msg.drv = hif_drv;
4841
4842         memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
4843         if (pstrAddStationMsg->u8NumRates > 0) {
4844                 u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
4845
4846                 if (!rates)
4847                         return -ENOMEM;
4848
4849                 memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
4850                 pstrAddStationMsg->pu8Rates = rates;
4851         }
4852
4853         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4854         if (s32Error)
4855                 PRINT_ER("wilc_mq_send fail\n");
4856
4857         return s32Error;
4858 }
4859
4860 s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv,
4861                             bool bIsEnabled,
4862                             u32 u32Timeout)
4863 {
4864         s32 s32Error = 0;
4865         struct host_if_msg msg;
4866         struct power_mgmt_param *pstrPowerMgmtParam = &msg.body.pwr_mgmt_info;
4867
4868         PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled);
4869
4870         if (!hif_drv) {
4871                 PRINT_ER("driver is null\n");
4872                 return -EFAULT;
4873         }
4874
4875         PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
4876
4877         memset(&msg, 0, sizeof(struct host_if_msg));
4878
4879         msg.id = HOST_IF_MSG_POWER_MGMT;
4880         msg.drv = hif_drv;
4881
4882         pstrPowerMgmtParam->bIsEnabled = bIsEnabled;
4883         pstrPowerMgmtParam->u32Timeout = u32Timeout;
4884
4885
4886         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4887         if (s32Error)
4888                 PRINT_ER("wilc_mq_send fail\n");
4889         return s32Error;
4890 }
4891
4892 s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv,
4893                                     bool bIsEnabled,
4894                                     u32 u32count)
4895 {
4896         s32 s32Error = 0;
4897         struct host_if_msg msg;
4898         struct set_multicast *pstrMulticastFilterParam = &msg.body.multicast_info;
4899
4900
4901         if (!hif_drv) {
4902                 PRINT_ER("driver is null\n");
4903                 return -EFAULT;
4904         }
4905
4906         PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
4907
4908         memset(&msg, 0, sizeof(struct host_if_msg));
4909
4910         msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
4911         msg.drv = hif_drv;
4912
4913         pstrMulticastFilterParam->bIsEnabled = bIsEnabled;
4914         pstrMulticastFilterParam->u32count = u32count;
4915
4916         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
4917         if (s32Error)
4918                 PRINT_ER("wilc_mq_send fail\n");
4919         return s32Error;
4920 }
4921
4922 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
4923 {
4924         struct join_bss_param *pNewJoinBssParam = NULL;
4925         u8 *pu8IEs;
4926         u16 u16IEsLen;
4927         u16 index = 0;
4928         u8 suppRatesNo = 0;
4929         u8 extSuppRatesNo;
4930         u16 jumpOffset;
4931         u8 pcipherCount;
4932         u8 authCount;
4933         u8 pcipherTotalCount = 0;
4934         u8 authTotalCount = 0;
4935         u8 i, j;
4936
4937         pu8IEs = ptstrNetworkInfo->pu8IEs;
4938         u16IEsLen = ptstrNetworkInfo->u16IEsLen;
4939
4940         pNewJoinBssParam = kmalloc(sizeof(struct join_bss_param), GFP_KERNEL);
4941         if (pNewJoinBssParam != NULL) {
4942                 memset(pNewJoinBssParam, 0, sizeof(struct join_bss_param));
4943                 pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
4944                 pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
4945                 pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
4946                 memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
4947                 memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
4948                 pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
4949                 memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
4950                 memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
4951
4952                 while (index < u16IEsLen) {
4953                         if (pu8IEs[index] == SUPP_RATES_IE) {
4954                                 suppRatesNo = pu8IEs[index + 1];
4955                                 pNewJoinBssParam->supp_rates[0] = suppRatesNo;
4956                                 index += 2;
4957
4958                                 for (i = 0; i < suppRatesNo; i++) {
4959                                         pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
4960                                 }
4961                                 index += suppRatesNo;
4962                                 continue;
4963                         } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
4964                                 extSuppRatesNo = pu8IEs[index + 1];
4965                                 if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
4966                                         pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
4967                                 else
4968                                         pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
4969                                 index += 2;
4970                                 for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++) {
4971                                         pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
4972                                 }
4973                                 index += extSuppRatesNo;
4974                                 continue;
4975                         } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
4976                                 pNewJoinBssParam->ht_capable = true;
4977                                 index += pu8IEs[index + 1] + 2;
4978                                 continue;
4979                         } else if ((pu8IEs[index] == WMM_IE) &&
4980                                    (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
4981                                    (pu8IEs[index + 4] == 0xF2) &&
4982                                    (pu8IEs[index + 5] == 0x02) &&
4983                                    ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
4984                                    (pu8IEs[index + 7] == 0x01)) {
4985                                 pNewJoinBssParam->wmm_cap = true;
4986
4987                                 if (pu8IEs[index + 8] & BIT(7))
4988                                         pNewJoinBssParam->uapsd_cap = true;
4989                                 index += pu8IEs[index + 1] + 2;
4990                                 continue;
4991                         } else if ((pu8IEs[index] == P2P_IE) &&
4992                                  (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
4993                                  (pu8IEs[index + 4] == 0x9a) &&
4994                                  (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
4995                                 u16 u16P2P_count;
4996
4997                                 pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
4998                                 pNewJoinBssParam->u8NoaEnbaled = 1;
4999                                 pNewJoinBssParam->u8Index = pu8IEs[index + 9];
5000
5001                                 if (pu8IEs[index + 10] & BIT(7)) {
5002                                         pNewJoinBssParam->u8OppEnable = 1;
5003                                         pNewJoinBssParam->u8CtWindow = pu8IEs[index + 10];
5004                                 } else
5005                                         pNewJoinBssParam->u8OppEnable = 0;
5006
5007                                 PRINT_D(GENERIC_DBG, "P2P Dump\n");
5008                                 for (i = 0; i < pu8IEs[index + 7]; i++)
5009                                         PRINT_D(GENERIC_DBG, " %x\n", pu8IEs[index + 9 + i]);
5010
5011                                 pNewJoinBssParam->u8Count = pu8IEs[index + 11];
5012                                 u16P2P_count = index + 12;
5013
5014                                 memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
5015                                 u16P2P_count += 4;
5016
5017                                 memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
5018                                 u16P2P_count += 4;
5019
5020                                 memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
5021
5022                                 index += pu8IEs[index + 1] + 2;
5023                                 continue;
5024
5025                         } else if ((pu8IEs[index] == RSN_IE) ||
5026                                  ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
5027                                   (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
5028                                   (pu8IEs[index + 5] == 0x01))) {
5029                                 u16 rsnIndex = index;
5030
5031                                 if (pu8IEs[rsnIndex] == RSN_IE) {
5032                                         pNewJoinBssParam->mode_802_11i = 2;
5033                                 } else {
5034                                         if (pNewJoinBssParam->mode_802_11i == 0)
5035                                                 pNewJoinBssParam->mode_802_11i = 1;
5036                                         rsnIndex += 4;
5037                                 }
5038
5039                                 rsnIndex += 7;
5040                                 pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
5041                                 rsnIndex++;
5042                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5043                                 pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5044                                 rsnIndex += 2;
5045
5046                                 for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
5047                                         pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5048                                 }
5049                                 pcipherTotalCount += pcipherCount;
5050                                 rsnIndex += jumpOffset;
5051
5052                                 jumpOffset = pu8IEs[rsnIndex] * 4;
5053
5054                                 authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
5055                                 rsnIndex += 2;
5056
5057                                 for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++) {
5058                                         pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
5059                                 }
5060                                 authTotalCount += authCount;
5061                                 rsnIndex += jumpOffset;
5062
5063                                 if (pu8IEs[index] == RSN_IE) {
5064                                         pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
5065                                         pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
5066                                         rsnIndex += 2;
5067                                 }
5068                                 pNewJoinBssParam->rsn_found = true;
5069                                 index += pu8IEs[index + 1] + 2;
5070                                 continue;
5071                         } else
5072                                 index += pu8IEs[index + 1] + 2;
5073
5074                 }
5075
5076
5077         }
5078
5079         return (void *)pNewJoinBssParam;
5080
5081 }
5082
5083 void host_int_freeJoinParams(void *pJoinParams)
5084 {
5085         if ((struct bss_param *)pJoinParams != NULL)
5086                 kfree((struct bss_param *)pJoinParams);
5087         else
5088                 PRINT_ER("Unable to FREE null pointer\n");
5089 }
5090
5091 s32 host_int_delBASession(struct host_if_drv *hif_drv, char *pBSSID, char TID)
5092 {
5093         s32 s32Error = 0;
5094         struct host_if_msg msg;
5095         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5096
5097         if (!hif_drv) {
5098                 PRINT_ER("driver is null\n");
5099                 return -EFAULT;
5100         }
5101
5102         memset(&msg, 0, sizeof(struct host_if_msg));
5103
5104         msg.id = HOST_IF_MSG_DEL_BA_SESSION;
5105
5106         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5107         pBASessionInfo->u8Ted = TID;
5108         msg.drv = hif_drv;
5109
5110         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5111         if (s32Error)
5112                 PRINT_ER("wilc_mq_send fail\n");
5113
5114         down(&hWaitResponse);
5115
5116         return s32Error;
5117 }
5118
5119 s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv,
5120                                   char *pBSSID,
5121                                   char TID)
5122 {
5123         s32 s32Error = 0;
5124         struct host_if_msg msg;
5125         struct ba_session_info *pBASessionInfo = &msg.body.session_info;
5126
5127         if (!hif_drv) {
5128                 PRINT_ER("driver is null\n");
5129                 return -EFAULT;
5130         }
5131
5132         memset(&msg, 0, sizeof(struct host_if_msg));
5133
5134         msg.id = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
5135
5136         memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
5137         pBASessionInfo->u8Ted = TID;
5138         msg.drv = hif_drv;
5139
5140         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5141         if (s32Error)
5142                 PRINT_ER("wilc_mq_send fail\n");
5143
5144         down(&hWaitResponse);
5145
5146         return s32Error;
5147 }
5148
5149 s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5150 {
5151         s32 s32Error = 0;
5152         struct host_if_msg msg;
5153
5154         return 0;
5155
5156         if (!hif_drv) {
5157                 PRINT_ER("driver is null\n");
5158                 return -EFAULT;
5159         }
5160
5161         memset(&msg, 0, sizeof(struct host_if_msg));
5162
5163         msg.id = HOST_IF_MSG_SET_IPADDRESS;
5164
5165         msg.body.ip_info.au8IPAddr = u16ipadd;
5166         msg.drv = hif_drv;
5167         msg.body.ip_info.idx = idx;
5168
5169         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5170         if (s32Error)
5171                 PRINT_ER("wilc_mq_send fail\n");
5172
5173         return s32Error;
5174
5175
5176 }
5177
5178 s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
5179 {
5180         s32 s32Error = 0;
5181         struct host_if_msg msg;
5182
5183         if (!hif_drv) {
5184                 PRINT_ER("driver is null\n");
5185                 return -EFAULT;
5186         }
5187
5188         memset(&msg, 0, sizeof(struct host_if_msg));
5189
5190         msg.id = HOST_IF_MSG_GET_IPADDRESS;
5191
5192         msg.body.ip_info.au8IPAddr = u16ipadd;
5193         msg.drv = hif_drv;
5194         msg.body.ip_info.idx = idx;
5195
5196         s32Error = wilc_mq_send(&gMsgQHostIF, &msg, sizeof(struct host_if_msg));
5197         if (s32Error)
5198                 PRINT_ER("wilc_mq_send fail\n");
5199
5200         return s32Error;
5201
5202
5203 }