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