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