1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
4  * All rights reserved.
5  */
6 
7 #include "netdev.h"
8 
9 #define WILC_HIF_SCAN_TIMEOUT_MS                5000
10 #define WILC_HIF_CONNECT_TIMEOUT_MS             9500
11 
12 #define WILC_FALSE_FRMWR_CHANNEL		100
13 
14 #define WILC_SCAN_WID_LIST_SIZE		6
15 
16 struct wilc_rcvd_mac_info {
17 	u8 status;
18 };
19 
20 struct wilc_set_multicast {
21 	u32 enabled;
22 	u32 cnt;
23 	u8 *mc_list;
24 };
25 
26 struct host_if_wowlan_trigger {
27 	u8 wowlan_trigger;
28 };
29 
30 struct wilc_del_all_sta {
31 	u8 assoc_sta;
32 	u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
33 };
34 
35 union wilc_message_body {
36 	struct wilc_rcvd_net_info net_info;
37 	struct wilc_rcvd_mac_info mac_info;
38 	struct wilc_set_multicast mc_info;
39 	struct wilc_remain_ch remain_on_ch;
40 	char *data;
41 	struct host_if_wowlan_trigger wow_trigger;
42 };
43 
44 struct host_if_msg {
45 	union wilc_message_body body;
46 	struct wilc_vif *vif;
47 	struct work_struct work;
48 	void (*fn)(struct work_struct *ws);
49 	struct completion work_comp;
50 	bool is_sync;
51 };
52 
53 /* 'msg' should be free by the caller for syc */
54 static struct host_if_msg*
55 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
56 		bool is_sync)
57 {
58 	struct host_if_msg *msg;
59 
60 	if (!work_fun)
61 		return ERR_PTR(-EINVAL);
62 
63 	msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
64 	if (!msg)
65 		return ERR_PTR(-ENOMEM);
66 	msg->fn = work_fun;
67 	msg->vif = vif;
68 	msg->is_sync = is_sync;
69 	if (is_sync)
70 		init_completion(&msg->work_comp);
71 
72 	return msg;
73 }
74 
75 static int wilc_enqueue_work(struct host_if_msg *msg)
76 {
77 	INIT_WORK(&msg->work, msg->fn);
78 
79 	if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
80 		return -EINVAL;
81 
82 	if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
83 		return -EINVAL;
84 
85 	return 0;
86 }
87 
88 /* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
89  * special purpose in wilc device, so we add 1 to the index to starts from 1.
90  * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
91  */
92 int wilc_get_vif_idx(struct wilc_vif *vif)
93 {
94 	return vif->idx + 1;
95 }
96 
97 /* We need to minus 1 from idx which is from wilc device to get real index
98  * of wilc->vif[], because we add 1 when pass to wilc device in the function
99  * wilc_get_vif_idx.
100  * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
101  */
102 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
103 {
104 	int index = idx - 1;
105 	struct wilc_vif *vif;
106 
107 	if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
108 		return NULL;
109 
110 	list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
111 		if (vif->idx == index)
112 			return vif;
113 	}
114 
115 	return NULL;
116 }
117 
118 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
119 {
120 	int result = 0;
121 	u8 abort_running_scan;
122 	struct wid wid;
123 	struct host_if_drv *hif_drv = vif->hif_drv;
124 	struct wilc_user_scan_req *scan_req;
125 
126 	if (evt == SCAN_EVENT_ABORTED) {
127 		abort_running_scan = 1;
128 		wid.id = WID_ABORT_RUNNING_SCAN;
129 		wid.type = WID_CHAR;
130 		wid.val = (s8 *)&abort_running_scan;
131 		wid.size = sizeof(char);
132 
133 		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
134 		if (result) {
135 			netdev_err(vif->ndev, "Failed to set abort running\n");
136 			result = -EFAULT;
137 		}
138 	}
139 
140 	if (!hif_drv) {
141 		netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
142 		return result;
143 	}
144 
145 	scan_req = &hif_drv->usr_scan_req;
146 	if (scan_req->scan_result) {
147 		scan_req->scan_result(evt, NULL, scan_req->arg);
148 		scan_req->scan_result = NULL;
149 	}
150 
151 	return result;
152 }
153 
154 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
155 	      u8 *ch_freq_list, u8 ch_list_len,
156 	      void (*scan_result_fn)(enum scan_event,
157 				     struct wilc_rcvd_net_info *, void *),
158 	      void *user_arg, struct cfg80211_scan_request *request)
159 {
160 	int result = 0;
161 	struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
162 	u32 index = 0;
163 	u32 i, scan_timeout;
164 	u8 *buffer;
165 	u8 valuesize = 0;
166 	u8 *search_ssid_vals = NULL;
167 	struct host_if_drv *hif_drv = vif->hif_drv;
168 
169 	if (hif_drv->hif_state >= HOST_IF_SCANNING &&
170 	    hif_drv->hif_state < HOST_IF_CONNECTED) {
171 		netdev_err(vif->ndev, "Already scan\n");
172 		result = -EBUSY;
173 		goto error;
174 	}
175 
176 	if (vif->connecting) {
177 		netdev_err(vif->ndev, "Don't do obss scan\n");
178 		result = -EBUSY;
179 		goto error;
180 	}
181 
182 	hif_drv->usr_scan_req.ch_cnt = 0;
183 
184 	if (request->n_ssids) {
185 		for (i = 0; i < request->n_ssids; i++)
186 			valuesize += ((request->ssids[i].ssid_len) + 1);
187 		search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
188 		if (search_ssid_vals) {
189 			wid_list[index].id = WID_SSID_PROBE_REQ;
190 			wid_list[index].type = WID_STR;
191 			wid_list[index].val = search_ssid_vals;
192 			buffer = wid_list[index].val;
193 
194 			*buffer++ = request->n_ssids;
195 
196 			for (i = 0; i < request->n_ssids; i++) {
197 				*buffer++ = request->ssids[i].ssid_len;
198 				memcpy(buffer, request->ssids[i].ssid,
199 				       request->ssids[i].ssid_len);
200 				buffer += request->ssids[i].ssid_len;
201 			}
202 			wid_list[index].size = (s32)(valuesize + 1);
203 			index++;
204 		}
205 	}
206 
207 	wid_list[index].id = WID_INFO_ELEMENT_PROBE;
208 	wid_list[index].type = WID_BIN_DATA;
209 	wid_list[index].val = (s8 *)request->ie;
210 	wid_list[index].size = request->ie_len;
211 	index++;
212 
213 	wid_list[index].id = WID_SCAN_TYPE;
214 	wid_list[index].type = WID_CHAR;
215 	wid_list[index].size = sizeof(char);
216 	wid_list[index].val = (s8 *)&scan_type;
217 	index++;
218 
219 	if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
220 		wid_list[index].id = WID_PASSIVE_SCAN_TIME;
221 		wid_list[index].type = WID_SHORT;
222 		wid_list[index].size = sizeof(u16);
223 		wid_list[index].val = (s8 *)&request->duration;
224 		index++;
225 
226 		scan_timeout = (request->duration * ch_list_len) + 500;
227 	} else {
228 		scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
229 	}
230 
231 	wid_list[index].id = WID_SCAN_CHANNEL_LIST;
232 	wid_list[index].type = WID_BIN_DATA;
233 
234 	if (ch_freq_list && ch_list_len > 0) {
235 		for (i = 0; i < ch_list_len; i++) {
236 			if (ch_freq_list[i] > 0)
237 				ch_freq_list[i] -= 1;
238 		}
239 	}
240 
241 	wid_list[index].val = ch_freq_list;
242 	wid_list[index].size = ch_list_len;
243 	index++;
244 
245 	wid_list[index].id = WID_START_SCAN_REQ;
246 	wid_list[index].type = WID_CHAR;
247 	wid_list[index].size = sizeof(char);
248 	wid_list[index].val = (s8 *)&scan_source;
249 	index++;
250 
251 	hif_drv->usr_scan_req.scan_result = scan_result_fn;
252 	hif_drv->usr_scan_req.arg = user_arg;
253 
254 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
255 	if (result) {
256 		netdev_err(vif->ndev, "Failed to send scan parameters\n");
257 		goto error;
258 	}
259 
260 	hif_drv->scan_timer_vif = vif;
261 	mod_timer(&hif_drv->scan_timer,
262 		  jiffies + msecs_to_jiffies(scan_timeout));
263 
264 error:
265 
266 	kfree(search_ssid_vals);
267 
268 	return result;
269 }
270 
271 static int wilc_send_connect_wid(struct wilc_vif *vif)
272 {
273 	int result = 0;
274 	struct wid wid_list[5];
275 	u32 wid_cnt = 0;
276 	struct host_if_drv *hif_drv = vif->hif_drv;
277 	struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
278 	struct wilc_join_bss_param *bss_param = conn_attr->param;
279 
280 
281         wid_list[wid_cnt].id = WID_SET_MFP;
282         wid_list[wid_cnt].type = WID_CHAR;
283         wid_list[wid_cnt].size = sizeof(char);
284         wid_list[wid_cnt].val = (s8 *)&conn_attr->mfp_type;
285         wid_cnt++;
286 
287 	wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
288 	wid_list[wid_cnt].type = WID_BIN_DATA;
289 	wid_list[wid_cnt].val = conn_attr->req_ies;
290 	wid_list[wid_cnt].size = conn_attr->req_ies_len;
291 	wid_cnt++;
292 
293 	wid_list[wid_cnt].id = WID_11I_MODE;
294 	wid_list[wid_cnt].type = WID_CHAR;
295 	wid_list[wid_cnt].size = sizeof(char);
296 	wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
297 	wid_cnt++;
298 
299 	wid_list[wid_cnt].id = WID_AUTH_TYPE;
300 	wid_list[wid_cnt].type = WID_CHAR;
301 	wid_list[wid_cnt].size = sizeof(char);
302 	wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
303 	wid_cnt++;
304 
305 	wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
306 	wid_list[wid_cnt].type = WID_STR;
307 	wid_list[wid_cnt].size = sizeof(*bss_param);
308 	wid_list[wid_cnt].val = (u8 *)bss_param;
309 	wid_cnt++;
310 
311 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
312 	if (result) {
313 		netdev_err(vif->ndev, "failed to send config packet\n");
314 		goto error;
315 	} else {
316                 if (conn_attr->auth_type == WILC_FW_AUTH_SAE)
317                         hif_drv->hif_state = HOST_IF_EXTERNAL_AUTH;
318                 else
319                         hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
320 	}
321 
322 	return 0;
323 
324 error:
325 
326 	kfree(conn_attr->req_ies);
327 	conn_attr->req_ies = NULL;
328 
329 	return result;
330 }
331 
332 static void handle_connect_timeout(struct work_struct *work)
333 {
334 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
335 	struct wilc_vif *vif = msg->vif;
336 	int result;
337 	struct wid wid;
338 	u16 dummy_reason_code = 0;
339 	struct host_if_drv *hif_drv = vif->hif_drv;
340 
341 	if (!hif_drv) {
342 		netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
343 		goto out;
344 	}
345 
346 	hif_drv->hif_state = HOST_IF_IDLE;
347 
348 	if (hif_drv->conn_info.conn_result) {
349 		hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
350 					       WILC_MAC_STATUS_DISCONNECTED,
351 					       hif_drv->conn_info.arg);
352 
353 	} else {
354 		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
355 	}
356 
357 	wid.id = WID_DISCONNECT;
358 	wid.type = WID_CHAR;
359 	wid.val = (s8 *)&dummy_reason_code;
360 	wid.size = sizeof(char);
361 
362 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
363 	if (result)
364 		netdev_err(vif->ndev, "Failed to send disconnect\n");
365 
366 	hif_drv->conn_info.req_ies_len = 0;
367 	kfree(hif_drv->conn_info.req_ies);
368 	hif_drv->conn_info.req_ies = NULL;
369 
370 out:
371 	kfree(msg);
372 }
373 
374 void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
375 				struct cfg80211_crypto_settings *crypto)
376 {
377 	const u8 *ies_data, *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
378 	const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
379 	struct ieee80211_p2p_noa_attr noa_attr;
380 	const struct cfg80211_bss_ies *ies;
381 	struct wilc_join_bss_param *param;
382 	u8 rates_len = 0;
383 	int ies_len;
384 	int ret;
385 
386 	param = kzalloc(sizeof(*param), GFP_KERNEL);
387 	if (!param)
388 		return NULL;
389 
390 	rcu_read_lock();
391 	ies = rcu_dereference(bss->ies);
392 	ies_data = kmemdup(ies->data, ies->len, GFP_ATOMIC);
393 	if (!ies_data) {
394 		rcu_read_unlock();
395 		kfree(param);
396 		return NULL;
397 	}
398 	ies_len = ies->len;
399 	rcu_read_unlock();
400 
401 	param->beacon_period = cpu_to_le16(bss->beacon_interval);
402 	param->cap_info = cpu_to_le16(bss->capability);
403 	param->bss_type = WILC_FW_BSS_TYPE_INFRA;
404 	param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
405 	ether_addr_copy(param->bssid, bss->bssid);
406 
407 	ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies_data, ies_len);
408 	if (ssid_elm) {
409 		if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
410 			memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
411 	}
412 
413 	tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies_data, ies_len);
414 	if (tim_elm && tim_elm[1] >= 2)
415 		param->dtim_period = tim_elm[3];
416 
417 	memset(param->p_suites, 0xFF, 3);
418 	memset(param->akm_suites, 0xFF, 3);
419 
420 	rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies_data, ies_len);
421 	if (rates_ie) {
422 		rates_len = rates_ie[1];
423 		if (rates_len > WILC_MAX_RATES_SUPPORTED)
424 			rates_len = WILC_MAX_RATES_SUPPORTED;
425 		param->supp_rates[0] = rates_len;
426 		memcpy(&param->supp_rates[1], rates_ie + 2, rates_len);
427 	}
428 
429 	if (rates_len < WILC_MAX_RATES_SUPPORTED) {
430 		supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
431 						 ies_data, ies_len);
432 		if (supp_rates_ie) {
433 			u8 ext_rates = supp_rates_ie[1];
434 
435 			if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
436 				param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
437 			else
438 				param->supp_rates[0] += ext_rates;
439 
440 			memcpy(&param->supp_rates[rates_len + 1],
441 			       supp_rates_ie + 2,
442 			       (param->supp_rates[0] - rates_len));
443 		}
444 	}
445 
446 	ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies_data, ies_len);
447 	if (ht_ie)
448 		param->ht_capable = true;
449 
450 	ret = cfg80211_get_p2p_attr(ies_data, ies_len,
451 				    IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
452 				    (u8 *)&noa_attr, sizeof(noa_attr));
453 	if (ret > 0) {
454 		param->tsf_lo = cpu_to_le32(ies->tsf);
455 		param->noa_enabled = 1;
456 		param->idx = noa_attr.index;
457 		if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
458 			param->opp_enabled = 1;
459 			param->opp_en.ct_window = noa_attr.oppps_ctwindow;
460 			param->opp_en.cnt = noa_attr.desc[0].count;
461 			param->opp_en.duration = noa_attr.desc[0].duration;
462 			param->opp_en.interval = noa_attr.desc[0].interval;
463 			param->opp_en.start_time = noa_attr.desc[0].start_time;
464 		} else {
465 			param->opp_enabled = 0;
466 			param->opp_dis.cnt = noa_attr.desc[0].count;
467 			param->opp_dis.duration = noa_attr.desc[0].duration;
468 			param->opp_dis.interval = noa_attr.desc[0].interval;
469 			param->opp_dis.start_time = noa_attr.desc[0].start_time;
470 		}
471 	}
472 	wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
473 					 WLAN_OUI_TYPE_MICROSOFT_WMM,
474 					 ies_data, ies_len);
475 	if (wmm_ie) {
476 		struct ieee80211_wmm_param_ie *ie;
477 
478 		ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
479 		if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
480 		    ie->version == 1) {
481 			param->wmm_cap = true;
482 			if (ie->qos_info & BIT(7))
483 				param->uapsd_cap = true;
484 		}
485 	}
486 
487 	wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
488 					 WLAN_OUI_TYPE_MICROSOFT_WPA,
489 					 ies_data, ies_len);
490 	if (wpa_ie) {
491 		param->mode_802_11i = 1;
492 		param->rsn_found = true;
493 	}
494 
495 	rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies_data, ies_len);
496 	if (rsn_ie) {
497 		int rsn_ie_len = sizeof(struct element) + rsn_ie[1];
498 		int offset = 8;
499 
500 		param->mode_802_11i = 2;
501 		param->rsn_found = true;
502 
503 		/* extract RSN capabilities */
504 		if (offset < rsn_ie_len) {
505 			/* skip over pairwise suites */
506 			offset += (rsn_ie[offset] * 4) + 2;
507 
508 			if (offset < rsn_ie_len) {
509 				/* skip over authentication suites */
510 				offset += (rsn_ie[offset] * 4) + 2;
511 
512 				if (offset + 1 < rsn_ie_len)
513 					memcpy(param->rsn_cap, &rsn_ie[offset], 2);
514 			}
515 		}
516 	}
517 
518 	if (param->rsn_found) {
519 		int i;
520 
521 		param->rsn_grp_policy = crypto->cipher_group & 0xFF;
522 		for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
523 			param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
524 
525 		for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
526 			param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
527 	}
528 
529 	kfree(ies_data);
530 	return (void *)param;
531 }
532 
533 static void handle_rcvd_ntwrk_info(struct work_struct *work)
534 {
535 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
536 	struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
537 	struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
538 	const u8 *ch_elm;
539 	u8 *ies;
540 	int ies_len;
541 	size_t offset;
542 
543 	if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
544 		offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
545 	else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
546 		offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
547 	else
548 		goto done;
549 
550 	ies = rcvd_info->mgmt->u.beacon.variable;
551 	ies_len = rcvd_info->frame_len - offset;
552 	if (ies_len <= 0)
553 		goto done;
554 
555 	ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
556 	if (ch_elm && ch_elm[1] > 0)
557 		rcvd_info->ch = ch_elm[2];
558 
559 	if (scan_req->scan_result)
560 		scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
561 				      scan_req->arg);
562 
563 done:
564 	kfree(rcvd_info->mgmt);
565 	kfree(msg);
566 }
567 
568 static void host_int_get_assoc_res_info(struct wilc_vif *vif,
569 					u8 *assoc_resp_info,
570 					u32 max_assoc_resp_info_len,
571 					u32 *rcvd_assoc_resp_info_len)
572 {
573 	int result;
574 	struct wid wid;
575 
576 	wid.id = WID_ASSOC_RES_INFO;
577 	wid.type = WID_STR;
578 	wid.val = assoc_resp_info;
579 	wid.size = max_assoc_resp_info_len;
580 
581 	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
582 	if (result) {
583 		*rcvd_assoc_resp_info_len = 0;
584 		netdev_err(vif->ndev, "Failed to send association response\n");
585 		return;
586 	}
587 
588 	*rcvd_assoc_resp_info_len = wid.size;
589 }
590 
591 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
592 				      struct wilc_conn_info *ret_conn_info)
593 {
594 	u8 *ies;
595 	u16 ies_len;
596 	struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
597 
598 	ret_conn_info->status = le16_to_cpu(res->status_code);
599 	if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
600 		ies = &buffer[sizeof(*res)];
601 		ies_len = buffer_len - sizeof(*res);
602 
603 		ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
604 		if (!ret_conn_info->resp_ies)
605 			return -ENOMEM;
606 
607 		ret_conn_info->resp_ies_len = ies_len;
608 	}
609 
610 	return 0;
611 }
612 
613 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
614 						  u8 mac_status)
615 {
616 	struct host_if_drv *hif_drv = vif->hif_drv;
617 	struct wilc_conn_info *conn_info = &hif_drv->conn_info;
618 
619 	if (mac_status == WILC_MAC_STATUS_CONNECTED) {
620 		u32 assoc_resp_info_len;
621 
622 		memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
623 
624 		host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
625 					    WILC_MAX_ASSOC_RESP_FRAME_SIZE,
626 					    &assoc_resp_info_len);
627 
628 		if (assoc_resp_info_len != 0) {
629 			s32 err = 0;
630 
631 			err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
632 							 assoc_resp_info_len,
633 							 conn_info);
634 			if (err)
635 				netdev_err(vif->ndev,
636 					   "wilc_parse_assoc_resp_info() returned error %d\n",
637 					   err);
638 		}
639 	}
640 
641 	del_timer(&hif_drv->connect_timer);
642 	conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
643 			       hif_drv->conn_info.arg);
644 
645 	if (mac_status == WILC_MAC_STATUS_CONNECTED &&
646 	    conn_info->status == WLAN_STATUS_SUCCESS) {
647 		ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
648 		hif_drv->hif_state = HOST_IF_CONNECTED;
649 	} else {
650 		hif_drv->hif_state = HOST_IF_IDLE;
651 	}
652 
653 	kfree(conn_info->resp_ies);
654 	conn_info->resp_ies = NULL;
655 	conn_info->resp_ies_len = 0;
656 
657 	kfree(conn_info->req_ies);
658 	conn_info->req_ies = NULL;
659 	conn_info->req_ies_len = 0;
660 }
661 
662 void wilc_handle_disconnect(struct wilc_vif *vif)
663 {
664 	struct host_if_drv *hif_drv = vif->hif_drv;
665 
666 	if (hif_drv->usr_scan_req.scan_result) {
667 		del_timer(&hif_drv->scan_timer);
668 		handle_scan_done(vif, SCAN_EVENT_ABORTED);
669 	}
670 
671 	if (hif_drv->conn_info.conn_result)
672 		hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
673 					       0, hif_drv->conn_info.arg);
674 
675 	eth_zero_addr(hif_drv->assoc_bssid);
676 
677 	hif_drv->conn_info.req_ies_len = 0;
678 	kfree(hif_drv->conn_info.req_ies);
679 	hif_drv->conn_info.req_ies = NULL;
680 	hif_drv->hif_state = HOST_IF_IDLE;
681 }
682 
683 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
684 {
685 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
686 	struct wilc_vif *vif = msg->vif;
687 	struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
688 	struct host_if_drv *hif_drv = vif->hif_drv;
689 
690 	if (!hif_drv) {
691 		netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
692 		goto free_msg;
693 	}
694 
695 	if (!hif_drv->conn_info.conn_result) {
696 		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
697 		goto free_msg;
698 	}
699 
700 
701         if (hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) {
702                 cfg80211_external_auth_request(vif->ndev, &vif->auth,
703 					       GFP_KERNEL);
704                 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
705         } else if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
706 		host_int_parse_assoc_resp_info(vif, mac_info->status);
707 	} else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
708 		if (hif_drv->hif_state == HOST_IF_CONNECTED) {
709 			wilc_handle_disconnect(vif);
710 		} else if (hif_drv->usr_scan_req.scan_result) {
711 			del_timer(&hif_drv->scan_timer);
712 			handle_scan_done(vif, SCAN_EVENT_ABORTED);
713 		}
714 	}
715 
716 free_msg:
717 	kfree(msg);
718 }
719 
720 int wilc_disconnect(struct wilc_vif *vif)
721 {
722 	struct wid wid;
723 	struct host_if_drv *hif_drv = vif->hif_drv;
724 	struct wilc_user_scan_req *scan_req;
725 	struct wilc_conn_info *conn_info;
726 	int result;
727 	u16 dummy_reason_code = 0;
728 
729 	wid.id = WID_DISCONNECT;
730 	wid.type = WID_CHAR;
731 	wid.val = (s8 *)&dummy_reason_code;
732 	wid.size = sizeof(char);
733 
734 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
735 	if (result) {
736 		netdev_err(vif->ndev, "Failed to send disconnect\n");
737 		return result;
738 	}
739 
740 	scan_req = &hif_drv->usr_scan_req;
741 	conn_info = &hif_drv->conn_info;
742 
743 	if (scan_req->scan_result) {
744 		del_timer(&hif_drv->scan_timer);
745 		scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
746 		scan_req->scan_result = NULL;
747 	}
748 
749 	if (conn_info->conn_result) {
750 		if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
751 		    hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH)
752 			del_timer(&hif_drv->connect_timer);
753 
754 		conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
755 				       conn_info->arg);
756 	} else {
757 		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
758 	}
759 
760 	hif_drv->hif_state = HOST_IF_IDLE;
761 
762 	eth_zero_addr(hif_drv->assoc_bssid);
763 
764 	conn_info->req_ies_len = 0;
765 	kfree(conn_info->req_ies);
766 	conn_info->req_ies = NULL;
767 
768 	return 0;
769 }
770 
771 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
772 {
773 	struct wid wid_list[5];
774 	u32 wid_cnt = 0, result;
775 
776 	wid_list[wid_cnt].id = WID_LINKSPEED;
777 	wid_list[wid_cnt].type = WID_CHAR;
778 	wid_list[wid_cnt].size = sizeof(char);
779 	wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
780 	wid_cnt++;
781 
782 	wid_list[wid_cnt].id = WID_RSSI;
783 	wid_list[wid_cnt].type = WID_CHAR;
784 	wid_list[wid_cnt].size = sizeof(char);
785 	wid_list[wid_cnt].val = (s8 *)&stats->rssi;
786 	wid_cnt++;
787 
788 	wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
789 	wid_list[wid_cnt].type = WID_INT;
790 	wid_list[wid_cnt].size = sizeof(u32);
791 	wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
792 	wid_cnt++;
793 
794 	wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
795 	wid_list[wid_cnt].type = WID_INT;
796 	wid_list[wid_cnt].size = sizeof(u32);
797 	wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
798 	wid_cnt++;
799 
800 	wid_list[wid_cnt].id = WID_FAILED_COUNT;
801 	wid_list[wid_cnt].type = WID_INT;
802 	wid_list[wid_cnt].size = sizeof(u32);
803 	wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
804 	wid_cnt++;
805 
806 	result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
807 	if (result) {
808 		netdev_err(vif->ndev, "Failed to send scan parameters\n");
809 		return result;
810 	}
811 
812 	if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
813 	    stats->link_speed != DEFAULT_LINK_SPEED)
814 		wilc_enable_tcp_ack_filter(vif, true);
815 	else if (stats->link_speed != DEFAULT_LINK_SPEED)
816 		wilc_enable_tcp_ack_filter(vif, false);
817 
818 	return result;
819 }
820 
821 static void handle_get_statistics(struct work_struct *work)
822 {
823 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
824 	struct wilc_vif *vif = msg->vif;
825 	struct rf_info *stats = (struct rf_info *)msg->body.data;
826 
827 	wilc_get_statistics(vif, stats);
828 
829 	kfree(msg);
830 }
831 
832 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
833 				    struct station_parameters *params)
834 {
835 	ether_addr_copy(cur_byte, mac);
836 	cur_byte += ETH_ALEN;
837 
838 	put_unaligned_le16(params->aid, cur_byte);
839 	cur_byte += 2;
840 
841 	*cur_byte++ = params->link_sta_params.supported_rates_len;
842 	if (params->link_sta_params.supported_rates_len > 0)
843 		memcpy(cur_byte, params->link_sta_params.supported_rates,
844 		       params->link_sta_params.supported_rates_len);
845 	cur_byte += params->link_sta_params.supported_rates_len;
846 
847 	if (params->link_sta_params.ht_capa) {
848 		*cur_byte++ = true;
849 		memcpy(cur_byte, params->link_sta_params.ht_capa,
850 		       sizeof(struct ieee80211_ht_cap));
851 	} else {
852 		*cur_byte++ = false;
853 	}
854 	cur_byte += sizeof(struct ieee80211_ht_cap);
855 
856 	put_unaligned_le16(params->sta_flags_mask, cur_byte);
857 	cur_byte += 2;
858 	put_unaligned_le16(params->sta_flags_set, cur_byte);
859 }
860 
861 static int handle_remain_on_chan(struct wilc_vif *vif,
862 				 struct wilc_remain_ch *hif_remain_ch)
863 {
864 	int result;
865 	u8 remain_on_chan_flag;
866 	struct wid wid;
867 	struct host_if_drv *hif_drv = vif->hif_drv;
868 
869 	if (hif_drv->usr_scan_req.scan_result)
870 		return -EBUSY;
871 
872 	if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
873 		return -EBUSY;
874 
875 	if (vif->connecting)
876 		return -EBUSY;
877 
878 	remain_on_chan_flag = true;
879 	wid.id = WID_REMAIN_ON_CHAN;
880 	wid.type = WID_STR;
881 	wid.size = 2;
882 	wid.val = kmalloc(wid.size, GFP_KERNEL);
883 	if (!wid.val)
884 		return -ENOMEM;
885 
886 	wid.val[0] = remain_on_chan_flag;
887 	wid.val[1] = (s8)hif_remain_ch->ch;
888 
889 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
890 	kfree(wid.val);
891 	if (result)
892 		return -EBUSY;
893 
894 	hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
895 	hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
896 	hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
897 	hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
898 	hif_drv->remain_on_ch_timer_vif = vif;
899 
900 	return 0;
901 }
902 
903 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
904 {
905 	u8 remain_on_chan_flag;
906 	struct wid wid;
907 	int result;
908 	struct host_if_drv *hif_drv = vif->hif_drv;
909 
910 	if (vif->priv.p2p_listen_state) {
911 		remain_on_chan_flag = false;
912 		wid.id = WID_REMAIN_ON_CHAN;
913 		wid.type = WID_STR;
914 		wid.size = 2;
915 
916 		wid.val = kmalloc(wid.size, GFP_KERNEL);
917 		if (!wid.val)
918 			return -ENOMEM;
919 
920 		wid.val[0] = remain_on_chan_flag;
921 		wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
922 
923 		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
924 		kfree(wid.val);
925 		if (result != 0) {
926 			netdev_err(vif->ndev, "Failed to set remain channel\n");
927 			return -EINVAL;
928 		}
929 
930 		if (hif_drv->remain_on_ch.expired) {
931 			hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
932 						      cookie);
933 		}
934 	} else {
935 		netdev_dbg(vif->ndev, "Not in listen state\n");
936 	}
937 
938 	return 0;
939 }
940 
941 static void wilc_handle_listen_state_expired(struct work_struct *work)
942 {
943 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
944 
945 	wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
946 	kfree(msg);
947 }
948 
949 static void listen_timer_cb(struct timer_list *t)
950 {
951 	struct host_if_drv *hif_drv = from_timer(hif_drv, t,
952 						      remain_on_ch_timer);
953 	struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
954 	int result;
955 	struct host_if_msg *msg;
956 
957 	del_timer(&vif->hif_drv->remain_on_ch_timer);
958 
959 	msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
960 	if (IS_ERR(msg))
961 		return;
962 
963 	msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
964 
965 	result = wilc_enqueue_work(msg);
966 	if (result) {
967 		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
968 		kfree(msg);
969 	}
970 }
971 
972 static void handle_set_mcast_filter(struct work_struct *work)
973 {
974 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
975 	struct wilc_vif *vif = msg->vif;
976 	struct wilc_set_multicast *set_mc = &msg->body.mc_info;
977 	int result;
978 	struct wid wid;
979 	u8 *cur_byte;
980 
981 	wid.id = WID_SETUP_MULTICAST_FILTER;
982 	wid.type = WID_BIN;
983 	wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
984 	wid.val = kmalloc(wid.size, GFP_KERNEL);
985 	if (!wid.val)
986 		goto error;
987 
988 	cur_byte = wid.val;
989 	put_unaligned_le32(set_mc->enabled, cur_byte);
990 	cur_byte += 4;
991 
992 	put_unaligned_le32(set_mc->cnt, cur_byte);
993 	cur_byte += 4;
994 
995 	if (set_mc->cnt > 0 && set_mc->mc_list)
996 		memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
997 
998 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
999 	if (result)
1000 		netdev_err(vif->ndev, "Failed to send setup multicast\n");
1001 
1002 error:
1003 	kfree(set_mc->mc_list);
1004 	kfree(wid.val);
1005 	kfree(msg);
1006 }
1007 
1008 void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled)
1009 {
1010 	int ret;
1011 	struct wid wid;
1012 	u8 wowlan_trigger = 0;
1013 
1014 	if (enabled)
1015 		wowlan_trigger = 1;
1016 
1017 	wid.id = WID_WOWLAN_TRIGGER;
1018 	wid.type = WID_CHAR;
1019 	wid.val = &wowlan_trigger;
1020 	wid.size = sizeof(char);
1021 
1022 	ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1023 	if (ret)
1024 		pr_err("Failed to send wowlan trigger config packet\n");
1025 }
1026 
1027 int wilc_set_external_auth_param(struct wilc_vif *vif,
1028 				 struct cfg80211_external_auth_params *auth)
1029 {
1030 	int ret;
1031 	struct wid wid;
1032 	struct wilc_external_auth_param *param;
1033 
1034 	wid.id = WID_EXTERNAL_AUTH_PARAM;
1035 	wid.type = WID_BIN_DATA;
1036 	wid.size = sizeof(*param);
1037 	param = kzalloc(sizeof(*param), GFP_KERNEL);
1038 	if (!param)
1039 		return -EINVAL;
1040 
1041 	wid.val = (u8 *)param;
1042 	param->action = auth->action;
1043 	ether_addr_copy(param->bssid, auth->bssid);
1044 	memcpy(param->ssid, auth->ssid.ssid, auth->ssid.ssid_len);
1045 	param->ssid_len = auth->ssid.ssid_len;
1046 	ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1047 
1048 	kfree(param);
1049 	return ret;
1050 }
1051 
1052 static void handle_scan_timer(struct work_struct *work)
1053 {
1054 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1055 
1056 	handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
1057 	kfree(msg);
1058 }
1059 
1060 static void handle_scan_complete(struct work_struct *work)
1061 {
1062 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1063 
1064 	del_timer(&msg->vif->hif_drv->scan_timer);
1065 
1066 	handle_scan_done(msg->vif, SCAN_EVENT_DONE);
1067 
1068 	kfree(msg);
1069 }
1070 
1071 static void timer_scan_cb(struct timer_list *t)
1072 {
1073 	struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
1074 	struct wilc_vif *vif = hif_drv->scan_timer_vif;
1075 	struct host_if_msg *msg;
1076 	int result;
1077 
1078 	msg = wilc_alloc_work(vif, handle_scan_timer, false);
1079 	if (IS_ERR(msg))
1080 		return;
1081 
1082 	result = wilc_enqueue_work(msg);
1083 	if (result)
1084 		kfree(msg);
1085 }
1086 
1087 static void timer_connect_cb(struct timer_list *t)
1088 {
1089 	struct host_if_drv *hif_drv = from_timer(hif_drv, t,
1090 						      connect_timer);
1091 	struct wilc_vif *vif = hif_drv->connect_timer_vif;
1092 	struct host_if_msg *msg;
1093 	int result;
1094 
1095 	msg = wilc_alloc_work(vif, handle_connect_timeout, false);
1096 	if (IS_ERR(msg))
1097 		return;
1098 
1099 	result = wilc_enqueue_work(msg);
1100 	if (result)
1101 		kfree(msg);
1102 }
1103 
1104 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
1105 		 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
1106 		 u8 mode, u8 cipher_mode, u8 index)
1107 {
1108 	int result = 0;
1109 	u8 t_key_len  = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1110 
1111 	if (mode == WILC_AP_MODE) {
1112 		struct wid wid_list[2];
1113 		struct wilc_ap_wpa_ptk *key_buf;
1114 
1115 		wid_list[0].id = WID_11I_MODE;
1116 		wid_list[0].type = WID_CHAR;
1117 		wid_list[0].size = sizeof(char);
1118 		wid_list[0].val = (s8 *)&cipher_mode;
1119 
1120 		key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1121 		if (!key_buf)
1122 			return -ENOMEM;
1123 
1124 		ether_addr_copy(key_buf->mac_addr, mac_addr);
1125 		key_buf->index = index;
1126 		key_buf->key_len = t_key_len;
1127 		memcpy(&key_buf->key[0], ptk, ptk_key_len);
1128 
1129 		if (rx_mic)
1130 			memcpy(&key_buf->key[ptk_key_len], rx_mic,
1131 			       WILC_RX_MIC_KEY_LEN);
1132 
1133 		if (tx_mic)
1134 			memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1135 			       tx_mic, WILC_TX_MIC_KEY_LEN);
1136 
1137 		wid_list[1].id = WID_ADD_PTK;
1138 		wid_list[1].type = WID_STR;
1139 		wid_list[1].size = sizeof(*key_buf) + t_key_len;
1140 		wid_list[1].val = (u8 *)key_buf;
1141 		result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1142 					      ARRAY_SIZE(wid_list));
1143 		kfree(key_buf);
1144 	} else if (mode == WILC_STATION_MODE) {
1145 		struct wid wid;
1146 		struct wilc_sta_wpa_ptk *key_buf;
1147 
1148 		key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1149 		if (!key_buf)
1150 			return -ENOMEM;
1151 
1152 		ether_addr_copy(key_buf->mac_addr, mac_addr);
1153 		key_buf->key_len = t_key_len;
1154 		memcpy(&key_buf->key[0], ptk, ptk_key_len);
1155 
1156 		if (rx_mic)
1157 			memcpy(&key_buf->key[ptk_key_len], rx_mic,
1158 			       WILC_RX_MIC_KEY_LEN);
1159 
1160 		if (tx_mic)
1161 			memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1162 			       tx_mic, WILC_TX_MIC_KEY_LEN);
1163 
1164 		wid.id = WID_ADD_PTK;
1165 		wid.type = WID_STR;
1166 		wid.size = sizeof(*key_buf) + t_key_len;
1167 		wid.val = (s8 *)key_buf;
1168 		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1169 		kfree(key_buf);
1170 	}
1171 
1172 	return result;
1173 }
1174 
1175 int wilc_add_igtk(struct wilc_vif *vif, const u8 *igtk, u8 igtk_key_len,
1176 		  const u8 *pn, u8 pn_len, const u8 *mac_addr, u8 mode, u8 index)
1177 {
1178 	int result = 0;
1179 	u8 t_key_len = igtk_key_len;
1180 	struct wid wid;
1181 	struct wilc_wpa_igtk *key_buf;
1182 
1183 	key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1184 	if (!key_buf)
1185 		return -ENOMEM;
1186 
1187 	key_buf->index = index;
1188 
1189 	memcpy(&key_buf->pn[0], pn, pn_len);
1190 	key_buf->pn_len = pn_len;
1191 
1192 	memcpy(&key_buf->key[0], igtk, igtk_key_len);
1193 	key_buf->key_len = t_key_len;
1194 
1195 	wid.id = WID_ADD_IGTK;
1196 	wid.type = WID_STR;
1197 	wid.size = sizeof(*key_buf) + t_key_len;
1198 	wid.val = (s8 *)key_buf;
1199 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1200 	kfree(key_buf);
1201 
1202 	return result;
1203 }
1204 
1205 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
1206 		    u8 index, u32 key_rsc_len, const u8 *key_rsc,
1207 		    const u8 *rx_mic, const u8 *tx_mic, u8 mode,
1208 		    u8 cipher_mode)
1209 {
1210 	int result = 0;
1211 	struct wilc_gtk_key *gtk_key;
1212 	int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1213 
1214 	gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
1215 	if (!gtk_key)
1216 		return -ENOMEM;
1217 
1218 	/* fill bssid value only in station mode */
1219 	if (mode == WILC_STATION_MODE &&
1220 	    vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1221 		memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
1222 
1223 	if (key_rsc)
1224 		memcpy(gtk_key->rsc, key_rsc, 8);
1225 	gtk_key->index = index;
1226 	gtk_key->key_len = t_key_len;
1227 	memcpy(&gtk_key->key[0], rx_gtk, gtk_key_len);
1228 
1229 	if (rx_mic)
1230 		memcpy(&gtk_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
1231 
1232 	if (tx_mic)
1233 		memcpy(&gtk_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
1234 		       tx_mic, WILC_TX_MIC_KEY_LEN);
1235 
1236 	if (mode == WILC_AP_MODE) {
1237 		struct wid wid_list[2];
1238 
1239 		wid_list[0].id = WID_11I_MODE;
1240 		wid_list[0].type = WID_CHAR;
1241 		wid_list[0].size = sizeof(char);
1242 		wid_list[0].val = (s8 *)&cipher_mode;
1243 
1244 		wid_list[1].id = WID_ADD_RX_GTK;
1245 		wid_list[1].type = WID_STR;
1246 		wid_list[1].size = sizeof(*gtk_key) + t_key_len;
1247 		wid_list[1].val = (u8 *)gtk_key;
1248 
1249 		result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1250 					      ARRAY_SIZE(wid_list));
1251 	} else if (mode == WILC_STATION_MODE) {
1252 		struct wid wid;
1253 
1254 		wid.id = WID_ADD_RX_GTK;
1255 		wid.type = WID_STR;
1256 		wid.size = sizeof(*gtk_key) + t_key_len;
1257 		wid.val = (u8 *)gtk_key;
1258 		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1259 	}
1260 
1261 	kfree(gtk_key);
1262 	return result;
1263 }
1264 
1265 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
1266 {
1267 	struct wid wid;
1268 
1269 	wid.id = WID_PMKID_INFO;
1270 	wid.type = WID_STR;
1271 	wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
1272 	wid.val = (u8 *)pmkid;
1273 
1274 	return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1275 }
1276 
1277 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1278 {
1279 	int result;
1280 	struct wid wid;
1281 
1282 	wid.id = WID_MAC_ADDR;
1283 	wid.type = WID_STR;
1284 	wid.size = ETH_ALEN;
1285 	wid.val = mac_addr;
1286 
1287 	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1288 	if (result)
1289 		netdev_err(vif->ndev, "Failed to get mac address\n");
1290 
1291 	return result;
1292 }
1293 
1294 int wilc_set_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1295 {
1296 	struct wid wid;
1297 	int result;
1298 
1299 	wid.id = WID_MAC_ADDR;
1300 	wid.type = WID_STR;
1301 	wid.size = ETH_ALEN;
1302 	wid.val = mac_addr;
1303 
1304 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1305 	if (result)
1306 		netdev_err(vif->ndev, "Failed to set mac address\n");
1307 
1308 	return result;
1309 }
1310 
1311 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
1312 		      size_t ies_len)
1313 {
1314 	int result;
1315 	struct host_if_drv *hif_drv = vif->hif_drv;
1316 	struct wilc_conn_info *conn_info = &hif_drv->conn_info;
1317 
1318 	if (bssid)
1319 		ether_addr_copy(conn_info->bssid, bssid);
1320 
1321 	if (ies) {
1322 		conn_info->req_ies_len = ies_len;
1323 		conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
1324 		if (!conn_info->req_ies)
1325 			return -ENOMEM;
1326 	}
1327 
1328 	result = wilc_send_connect_wid(vif);
1329 	if (result)
1330 		goto free_ies;
1331 
1332 	hif_drv->connect_timer_vif = vif;
1333 	mod_timer(&hif_drv->connect_timer,
1334 		  jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
1335 
1336 	return 0;
1337 
1338 free_ies:
1339 	kfree(conn_info->req_ies);
1340 
1341 	return result;
1342 }
1343 
1344 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1345 {
1346 	struct wid wid;
1347 	int result;
1348 
1349 	wid.id = WID_CURRENT_CHANNEL;
1350 	wid.type = WID_CHAR;
1351 	wid.size = sizeof(char);
1352 	wid.val = &channel;
1353 
1354 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1355 	if (result)
1356 		netdev_err(vif->ndev, "Failed to set channel\n");
1357 
1358 	return result;
1359 }
1360 
1361 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1362 			    u8 ifc_id)
1363 {
1364 	struct wid wid;
1365 	int result;
1366 	struct wilc_drv_handler drv;
1367 
1368 	wid.id = WID_SET_OPERATION_MODE;
1369 	wid.type = WID_STR;
1370 	wid.size = sizeof(drv);
1371 	wid.val = (u8 *)&drv;
1372 
1373 	drv.handler = cpu_to_le32(index);
1374 	drv.mode = (ifc_id | (mode << 1));
1375 
1376 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1377 	if (result)
1378 		netdev_err(vif->ndev, "Failed to set driver handler\n");
1379 
1380 	return result;
1381 }
1382 
1383 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1384 {
1385 	struct wid wid;
1386 	s32 result;
1387 
1388 	wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
1389 	wid.type = WID_STR;
1390 	wid.size = ETH_ALEN;
1391 	wid.val = kzalloc(wid.size, GFP_KERNEL);
1392 	if (!wid.val)
1393 		return -ENOMEM;
1394 
1395 	ether_addr_copy(wid.val, mac);
1396 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1397 	kfree(wid.val);
1398 	if (result) {
1399 		netdev_err(vif->ndev, "Failed to set inactive mac\n");
1400 		return result;
1401 	}
1402 
1403 	wid.id = WID_GET_INACTIVE_TIME;
1404 	wid.type = WID_INT;
1405 	wid.val = (s8 *)out_val;
1406 	wid.size = sizeof(u32);
1407 	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1408 	if (result)
1409 		netdev_err(vif->ndev, "Failed to get inactive time\n");
1410 
1411 	return result;
1412 }
1413 
1414 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
1415 {
1416 	struct wid wid;
1417 	int result;
1418 
1419 	if (!rssi_level) {
1420 		netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
1421 		return -EFAULT;
1422 	}
1423 
1424 	wid.id = WID_RSSI;
1425 	wid.type = WID_CHAR;
1426 	wid.size = sizeof(char);
1427 	wid.val = rssi_level;
1428 	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1429 	if (result)
1430 		netdev_err(vif->ndev, "Failed to get RSSI value\n");
1431 
1432 	return result;
1433 }
1434 
1435 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
1436 {
1437 	int result;
1438 	struct host_if_msg *msg;
1439 
1440 	msg = wilc_alloc_work(vif, handle_get_statistics, false);
1441 	if (IS_ERR(msg))
1442 		return PTR_ERR(msg);
1443 
1444 	msg->body.data = (char *)stats;
1445 
1446 	result = wilc_enqueue_work(msg);
1447 	if (result) {
1448 		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1449 		kfree(msg);
1450 		return result;
1451 	}
1452 
1453 	return result;
1454 }
1455 
1456 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
1457 {
1458 	struct wid wid_list[4];
1459 	int i = 0;
1460 
1461 	if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
1462 		wid_list[i].id = WID_SHORT_RETRY_LIMIT;
1463 		wid_list[i].val = (s8 *)&param->short_retry_limit;
1464 		wid_list[i].type = WID_SHORT;
1465 		wid_list[i].size = sizeof(u16);
1466 		i++;
1467 	}
1468 	if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
1469 		wid_list[i].id = WID_LONG_RETRY_LIMIT;
1470 		wid_list[i].val = (s8 *)&param->long_retry_limit;
1471 		wid_list[i].type = WID_SHORT;
1472 		wid_list[i].size = sizeof(u16);
1473 		i++;
1474 	}
1475 	if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
1476 		wid_list[i].id = WID_FRAG_THRESHOLD;
1477 		wid_list[i].val = (s8 *)&param->frag_threshold;
1478 		wid_list[i].type = WID_SHORT;
1479 		wid_list[i].size = sizeof(u16);
1480 		i++;
1481 	}
1482 	if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
1483 		wid_list[i].id = WID_RTS_THRESHOLD;
1484 		wid_list[i].val = (s8 *)&param->rts_threshold;
1485 		wid_list[i].type = WID_SHORT;
1486 		wid_list[i].size = sizeof(u16);
1487 		i++;
1488 	}
1489 
1490 	return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
1491 }
1492 
1493 static void get_periodic_rssi(struct timer_list *t)
1494 {
1495 	struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
1496 
1497 	if (!vif->hif_drv) {
1498 		netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1499 		return;
1500 	}
1501 
1502 	if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1503 		wilc_get_stats_async(vif, &vif->periodic_stat);
1504 
1505 	mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1506 }
1507 
1508 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1509 {
1510 	struct host_if_drv *hif_drv;
1511 	struct wilc_vif *vif = netdev_priv(dev);
1512 
1513 	hif_drv  = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
1514 	if (!hif_drv)
1515 		return -ENOMEM;
1516 
1517 	*hif_drv_handler = hif_drv;
1518 
1519 	vif->hif_drv = hif_drv;
1520 
1521 	timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
1522 	mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1523 
1524 	timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
1525 	timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
1526 	timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
1527 
1528 	hif_drv->hif_state = HOST_IF_IDLE;
1529 
1530 	hif_drv->p2p_timeout = 0;
1531 
1532 	return 0;
1533 }
1534 
1535 int wilc_deinit(struct wilc_vif *vif)
1536 {
1537 	int result = 0;
1538 	struct host_if_drv *hif_drv = vif->hif_drv;
1539 
1540 	if (!hif_drv) {
1541 		netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1542 		return -EFAULT;
1543 	}
1544 
1545 	mutex_lock(&vif->wilc->deinit_lock);
1546 
1547 	timer_shutdown_sync(&hif_drv->scan_timer);
1548 	timer_shutdown_sync(&hif_drv->connect_timer);
1549 	del_timer_sync(&vif->periodic_rssi);
1550 	timer_shutdown_sync(&hif_drv->remain_on_ch_timer);
1551 
1552 	if (hif_drv->usr_scan_req.scan_result) {
1553 		hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1554 						  hif_drv->usr_scan_req.arg);
1555 		hif_drv->usr_scan_req.scan_result = NULL;
1556 	}
1557 
1558 	hif_drv->hif_state = HOST_IF_IDLE;
1559 
1560 	kfree(hif_drv);
1561 	vif->hif_drv = NULL;
1562 	mutex_unlock(&vif->wilc->deinit_lock);
1563 	return result;
1564 }
1565 
1566 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1567 {
1568 	int result;
1569 	struct host_if_msg *msg;
1570 	int id;
1571 	struct host_if_drv *hif_drv;
1572 	struct wilc_vif *vif;
1573 
1574 	id = get_unaligned_le32(&buffer[length - 4]);
1575 	vif = wilc_get_vif_from_idx(wilc, id);
1576 	if (!vif)
1577 		return;
1578 	hif_drv = vif->hif_drv;
1579 
1580 	if (!hif_drv) {
1581 		netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
1582 		return;
1583 	}
1584 
1585 	msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
1586 	if (IS_ERR(msg))
1587 		return;
1588 
1589 	msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
1590 	msg->body.net_info.rssi = buffer[8];
1591 	msg->body.net_info.mgmt = kmemdup(&buffer[9],
1592 					  msg->body.net_info.frame_len,
1593 					  GFP_KERNEL);
1594 	if (!msg->body.net_info.mgmt) {
1595 		kfree(msg);
1596 		return;
1597 	}
1598 
1599 	result = wilc_enqueue_work(msg);
1600 	if (result) {
1601 		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1602 		kfree(msg->body.net_info.mgmt);
1603 		kfree(msg);
1604 	}
1605 }
1606 
1607 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1608 {
1609 	int result;
1610 	struct host_if_msg *msg;
1611 	int id;
1612 	struct host_if_drv *hif_drv;
1613 	struct wilc_vif *vif;
1614 
1615 	mutex_lock(&wilc->deinit_lock);
1616 
1617 	id = get_unaligned_le32(&buffer[length - 4]);
1618 	vif = wilc_get_vif_from_idx(wilc, id);
1619 	if (!vif) {
1620 		mutex_unlock(&wilc->deinit_lock);
1621 		return;
1622 	}
1623 
1624 	hif_drv = vif->hif_drv;
1625 
1626 	if (!hif_drv) {
1627 		mutex_unlock(&wilc->deinit_lock);
1628 		return;
1629 	}
1630 
1631 	if (!hif_drv->conn_info.conn_result) {
1632 		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1633 		mutex_unlock(&wilc->deinit_lock);
1634 		return;
1635 	}
1636 
1637 	msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
1638 	if (IS_ERR(msg)) {
1639 		mutex_unlock(&wilc->deinit_lock);
1640 		return;
1641 	}
1642 
1643 	msg->body.mac_info.status = buffer[7];
1644 	result = wilc_enqueue_work(msg);
1645 	if (result) {
1646 		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1647 		kfree(msg);
1648 	}
1649 
1650 	mutex_unlock(&wilc->deinit_lock);
1651 }
1652 
1653 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
1654 {
1655 	int result;
1656 	int id;
1657 	struct host_if_drv *hif_drv;
1658 	struct wilc_vif *vif;
1659 
1660 	id = get_unaligned_le32(&buffer[length - 4]);
1661 	vif = wilc_get_vif_from_idx(wilc, id);
1662 	if (!vif)
1663 		return;
1664 	hif_drv = vif->hif_drv;
1665 
1666 	if (!hif_drv)
1667 		return;
1668 
1669 	if (hif_drv->usr_scan_req.scan_result) {
1670 		struct host_if_msg *msg;
1671 
1672 		msg = wilc_alloc_work(vif, handle_scan_complete, false);
1673 		if (IS_ERR(msg))
1674 			return;
1675 
1676 		result = wilc_enqueue_work(msg);
1677 		if (result) {
1678 			netdev_err(vif->ndev, "%s: enqueue work failed\n",
1679 				   __func__);
1680 			kfree(msg);
1681 		}
1682 	}
1683 }
1684 
1685 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
1686 			   u32 duration, u16 chan,
1687 			   void (*expired)(void *, u64),
1688 			   void *user_arg)
1689 {
1690 	struct wilc_remain_ch roc;
1691 	int result;
1692 
1693 	roc.ch = chan;
1694 	roc.expired = expired;
1695 	roc.arg = user_arg;
1696 	roc.duration = duration;
1697 	roc.cookie = cookie;
1698 	result = handle_remain_on_chan(vif, &roc);
1699 	if (result)
1700 		netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
1701 			   __func__);
1702 
1703 	return result;
1704 }
1705 
1706 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
1707 {
1708 	if (!vif->hif_drv) {
1709 		netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1710 		return -EFAULT;
1711 	}
1712 
1713 	del_timer(&vif->hif_drv->remain_on_ch_timer);
1714 
1715 	return wilc_handle_roc_expired(vif, cookie);
1716 }
1717 
1718 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
1719 {
1720 	struct wid wid;
1721 	int result;
1722 	struct wilc_reg_frame reg_frame;
1723 
1724 	wid.id = WID_REGISTER_FRAME;
1725 	wid.type = WID_STR;
1726 	wid.size = sizeof(reg_frame);
1727 	wid.val = (u8 *)&reg_frame;
1728 
1729 	memset(&reg_frame, 0x0, sizeof(reg_frame));
1730 
1731 	if (reg)
1732 		reg_frame.reg = 1;
1733 
1734 	switch (frame_type) {
1735 	case IEEE80211_STYPE_ACTION:
1736 		reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
1737 		break;
1738 
1739 	case IEEE80211_STYPE_PROBE_REQ:
1740 		reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
1741 		break;
1742 
1743         case IEEE80211_STYPE_AUTH:
1744                 reg_frame.reg_id = WILC_FW_AUTH_REQ_IDX;
1745                 break;
1746 
1747 	default:
1748 		break;
1749 	}
1750 	reg_frame.frame_type = cpu_to_le16(frame_type);
1751 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1752 	if (result)
1753 		netdev_err(vif->ndev, "Failed to frame register\n");
1754 }
1755 
1756 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
1757 		    struct cfg80211_beacon_data *params)
1758 {
1759 	struct wid wid;
1760 	int result;
1761 	u8 *cur_byte;
1762 
1763 	wid.id = WID_ADD_BEACON;
1764 	wid.type = WID_BIN;
1765 	wid.size = params->head_len + params->tail_len + 16;
1766 	wid.val = kzalloc(wid.size, GFP_KERNEL);
1767 	if (!wid.val)
1768 		return -ENOMEM;
1769 
1770 	cur_byte = wid.val;
1771 	put_unaligned_le32(interval, cur_byte);
1772 	cur_byte += 4;
1773 	put_unaligned_le32(dtim_period, cur_byte);
1774 	cur_byte += 4;
1775 	put_unaligned_le32(params->head_len, cur_byte);
1776 	cur_byte += 4;
1777 
1778 	if (params->head_len > 0)
1779 		memcpy(cur_byte, params->head, params->head_len);
1780 	cur_byte += params->head_len;
1781 
1782 	put_unaligned_le32(params->tail_len, cur_byte);
1783 	cur_byte += 4;
1784 
1785 	if (params->tail_len > 0)
1786 		memcpy(cur_byte, params->tail, params->tail_len);
1787 
1788 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1789 	if (result)
1790 		netdev_err(vif->ndev, "Failed to send add beacon\n");
1791 
1792 	kfree(wid.val);
1793 
1794 	return result;
1795 }
1796 
1797 int wilc_del_beacon(struct wilc_vif *vif)
1798 {
1799 	int result;
1800 	struct wid wid;
1801 	u8 del_beacon = 0;
1802 
1803 	wid.id = WID_DEL_BEACON;
1804 	wid.type = WID_CHAR;
1805 	wid.size = sizeof(char);
1806 	wid.val = &del_beacon;
1807 
1808 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1809 	if (result)
1810 		netdev_err(vif->ndev, "Failed to send delete beacon\n");
1811 
1812 	return result;
1813 }
1814 
1815 int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
1816 		     struct station_parameters *params)
1817 {
1818 	struct wid wid;
1819 	int result;
1820 	u8 *cur_byte;
1821 
1822 	wid.id = WID_ADD_STA;
1823 	wid.type = WID_BIN;
1824 	wid.size = WILC_ADD_STA_LENGTH +
1825 		   params->link_sta_params.supported_rates_len;
1826 	wid.val = kmalloc(wid.size, GFP_KERNEL);
1827 	if (!wid.val)
1828 		return -ENOMEM;
1829 
1830 	cur_byte = wid.val;
1831 	wilc_hif_pack_sta_param(cur_byte, mac, params);
1832 
1833 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1834 	if (result != 0)
1835 		netdev_err(vif->ndev, "Failed to send add station\n");
1836 
1837 	kfree(wid.val);
1838 
1839 	return result;
1840 }
1841 
1842 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
1843 {
1844 	struct wid wid;
1845 	int result;
1846 
1847 	wid.id = WID_REMOVE_STA;
1848 	wid.type = WID_BIN;
1849 	wid.size = ETH_ALEN;
1850 	wid.val = kzalloc(wid.size, GFP_KERNEL);
1851 	if (!wid.val)
1852 		return -ENOMEM;
1853 
1854 	if (!mac_addr)
1855 		eth_broadcast_addr(wid.val);
1856 	else
1857 		ether_addr_copy(wid.val, mac_addr);
1858 
1859 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1860 	if (result)
1861 		netdev_err(vif->ndev, "Failed to del station\n");
1862 
1863 	kfree(wid.val);
1864 
1865 	return result;
1866 }
1867 
1868 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
1869 {
1870 	struct wid wid;
1871 	int result;
1872 	int i;
1873 	u8 assoc_sta = 0;
1874 	struct wilc_del_all_sta del_sta;
1875 
1876 	memset(&del_sta, 0x0, sizeof(del_sta));
1877 	for (i = 0; i < WILC_MAX_NUM_STA; i++) {
1878 		if (!is_zero_ether_addr(mac_addr[i])) {
1879 			assoc_sta++;
1880 			ether_addr_copy(del_sta.mac[i], mac_addr[i]);
1881 		}
1882 	}
1883 
1884 	if (!assoc_sta)
1885 		return 0;
1886 
1887 	del_sta.assoc_sta = assoc_sta;
1888 
1889 	wid.id = WID_DEL_ALL_STA;
1890 	wid.type = WID_STR;
1891 	wid.size = (assoc_sta * ETH_ALEN) + 1;
1892 	wid.val = (u8 *)&del_sta;
1893 
1894 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1895 	if (result)
1896 		netdev_err(vif->ndev, "Failed to send delete all station\n");
1897 
1898 	return result;
1899 }
1900 
1901 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
1902 		      struct station_parameters *params)
1903 {
1904 	struct wid wid;
1905 	int result;
1906 	u8 *cur_byte;
1907 
1908 	wid.id = WID_EDIT_STA;
1909 	wid.type = WID_BIN;
1910 	wid.size = WILC_ADD_STA_LENGTH +
1911 		   params->link_sta_params.supported_rates_len;
1912 	wid.val = kmalloc(wid.size, GFP_KERNEL);
1913 	if (!wid.val)
1914 		return -ENOMEM;
1915 
1916 	cur_byte = wid.val;
1917 	wilc_hif_pack_sta_param(cur_byte, mac, params);
1918 
1919 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1920 	if (result)
1921 		netdev_err(vif->ndev, "Failed to send edit station\n");
1922 
1923 	kfree(wid.val);
1924 	return result;
1925 }
1926 
1927 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
1928 {
1929 	struct wilc *wilc = vif->wilc;
1930 	struct wid wid;
1931 	int result;
1932 	s8 power_mode;
1933 
1934 	if (enabled)
1935 		power_mode = WILC_FW_MIN_FAST_PS;
1936 	else
1937 		power_mode = WILC_FW_NO_POWERSAVE;
1938 
1939 	wid.id = WID_POWER_MANAGEMENT;
1940 	wid.val = &power_mode;
1941 	wid.size = sizeof(char);
1942 	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1943 	if (result)
1944 		netdev_err(vif->ndev, "Failed to send power management\n");
1945 	else
1946 		wilc->power_save_mode = enabled;
1947 
1948 	return result;
1949 }
1950 
1951 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
1952 				u8 *mc_list)
1953 {
1954 	int result;
1955 	struct host_if_msg *msg;
1956 
1957 	msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
1958 	if (IS_ERR(msg))
1959 		return PTR_ERR(msg);
1960 
1961 	msg->body.mc_info.enabled = enabled;
1962 	msg->body.mc_info.cnt = count;
1963 	msg->body.mc_info.mc_list = mc_list;
1964 
1965 	result = wilc_enqueue_work(msg);
1966 	if (result) {
1967 		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1968 		kfree(msg);
1969 	}
1970 	return result;
1971 }
1972 
1973 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
1974 {
1975 	struct wid wid;
1976 
1977 	wid.id = WID_TX_POWER;
1978 	wid.type = WID_CHAR;
1979 	wid.val = &tx_power;
1980 	wid.size = sizeof(char);
1981 
1982 	return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1983 }
1984 
1985 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
1986 {
1987 	struct wid wid;
1988 
1989 	wid.id = WID_TX_POWER;
1990 	wid.type = WID_CHAR;
1991 	wid.val = tx_power;
1992 	wid.size = sizeof(char);
1993 
1994 	return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1995 }
1996 
1997 int wilc_set_default_mgmt_key_index(struct wilc_vif *vif, u8 index)
1998 {
1999         struct wid wid;
2000         int result;
2001 
2002         wid.id = WID_DEFAULT_MGMT_KEY_ID;
2003         wid.type = WID_CHAR;
2004         wid.size = sizeof(char);
2005         wid.val = &index;
2006         result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
2007         if (result)
2008                 netdev_err(vif->ndev,
2009                            "Failed to send default mgmt key index\n");
2010 
2011         return result;
2012 }
2013