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