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