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