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