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