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