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