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