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