-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhif.c
2582 lines (2112 loc) · 65.3 KB
/
hif.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
* All rights reserved.
*/
#include "netdev.h"
#define WILC_HIF_SCAN_TIMEOUT_MS 5000
#define WILC_HIF_CONNECT_TIMEOUT_MS 9500
#define WILC_FALSE_FRMWR_CHANNEL 100
struct send_buffered_eap {
void (*deliver_to_stack)(struct wilc_vif *vif, u8 *buff, u32 size,
u32 pkt_offset, u8 status);
void (*eap_buf_param)(void *priv);
u8 *buff;
unsigned int size;
unsigned int pkt_offset;
void *user_arg;
};
#define WILC_SCAN_WID_LIST_SIZE 6
struct wilc_rcvd_mac_info {
u8 status;
};
struct wilc_set_multicast {
u32 enabled;
u32 cnt;
u8 *mc_list;
};
struct host_if_wowlan_trigger {
u8 wowlan_trigger;
};
struct host_if_set_ant {
u8 mode;
u8 antenna1;
u8 antenna2;
u8 gpio_mode;
};
struct tx_power {
u8 tx_pwr;
};
struct power_mgmt_param {
bool enabled;
u32 timeout;
};
struct wilc_del_all_sta {
u8 assoc_sta;
u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
};
struct add_sta_param {
u8 bssid[ETH_ALEN];
u16 aid;
u8 supported_rates_len;
const u8 *supported_rates;
bool ht_supported;
struct ieee80211_ht_cap ht_capa;
u16 flags_mask;
u16 flags_set;
};
union wilc_message_body {
struct wilc_rcvd_net_info net_info;
struct wilc_rcvd_mac_info mac_info;
struct wilc_set_multicast mc_info;
struct wilc_remain_ch remain_on_ch;
char *data;
struct host_if_wowlan_trigger wow_trigger;
struct send_buffered_eap send_buff_eap;
struct host_if_set_ant set_ant;
struct tx_power tx_power;
struct power_mgmt_param pwr_mgmt_info;
struct add_sta_param add_sta_info;
struct add_sta_param edit_sta_info;
};
struct host_if_msg {
union wilc_message_body body;
struct wilc_vif *vif;
struct work_struct work;
void (*fn)(struct work_struct *ws);
struct completion work_comp;
bool is_sync;
};
/* 'msg' should be free by the caller for syc */
static struct host_if_msg*
wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
bool is_sync)
{
struct host_if_msg *msg;
if (!work_fun)
return ERR_PTR(-EINVAL);
msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
if (!msg)
return ERR_PTR(-ENOMEM);
msg->fn = work_fun;
msg->vif = vif;
msg->is_sync = is_sync;
if (is_sync)
init_completion(&msg->work_comp);
return msg;
}
static int wilc_enqueue_work(struct host_if_msg *msg)
{
INIT_WORK(&msg->work, msg->fn);
if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
return -EINVAL;
if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
return -EINVAL;
return 0;
}
/* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
* special purpose in wilc device, so we add 1 to the index to starts from 1.
* As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
*/
int wilc_get_vif_idx(struct wilc_vif *vif)
{
return vif->idx + 1;
}
/* We need to minus 1 from idx which is from wilc device to get real index
* of wilc->vif[], because we add 1 when pass to wilc device in the function
* wilc_get_vif_idx.
* As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
*/
static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
{
int index = idx - 1;
struct wilc_vif *vif;
if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
return NULL;
list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
if (vif->idx == index)
return vif;
}
return NULL;
}
int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
{
int result = 0;
u8 abort_running_scan;
struct wid wid;
struct host_if_drv *hif_drv = vif->hif_drv;
struct wilc_user_scan_req *scan_req;
u8 null_bssid[6] = {0};
PRINT_INFO(vif->ndev, HOSTINF_DBG, "handling scan done\n");
if (!hif_drv) {
PRINT_ER(vif->ndev, "hif driver is NULL\n");
return result;
}
if (evt == SCAN_EVENT_DONE) {
if (memcmp(hif_drv->assoc_bssid, null_bssid, ETH_ALEN) == 0)
hif_drv->hif_state = HOST_IF_IDLE;
else
hif_drv->hif_state = HOST_IF_CONNECTED;
} else if (evt == SCAN_EVENT_ABORTED) {
PRINT_INFO(vif->ndev, GENERIC_DBG, "Abort running scan\n");
abort_running_scan = 1;
wid.id = WID_ABORT_RUNNING_SCAN;
wid.type = WID_CHAR;
wid.val = (s8 *)&abort_running_scan;
wid.size = sizeof(char);
result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
if (result) {
PRINT_ER(vif->ndev, "Failed to set abort running\n");
result = -EFAULT;
}
}
scan_req = &hif_drv->usr_scan_req;
if (scan_req->scan_result) {
scan_req->scan_result(evt, NULL, scan_req->arg);
scan_req->scan_result = NULL;
}
return result;
}
static void handle_send_buffered_eap(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
struct wilc_vif *vif = msg->vif;
struct send_buffered_eap *hif_buff_eap = &msg->body.send_buff_eap;
PRINT_INFO(vif->ndev, HOSTINF_DBG, "Sending bufferd eapol to WPAS\n");
if (!hif_buff_eap->buff)
goto out;
if (hif_buff_eap->deliver_to_stack)
hif_buff_eap->deliver_to_stack(vif, hif_buff_eap->buff,
hif_buff_eap->size,
hif_buff_eap->pkt_offset,
PKT_STATUS_BUFFERED);
if (hif_buff_eap->eap_buf_param)
hif_buff_eap->eap_buf_param(hif_buff_eap->user_arg);
if (hif_buff_eap->buff != NULL) {
kfree(hif_buff_eap->buff);
hif_buff_eap->buff = NULL;
}
out:
kfree(msg);
}
int 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)
{
int result = 0;
struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
u32 index = 0;
u32 i, scan_timeout;
u8 *buffer;
u8 valuesize = 0;
u8 *search_ssid_vals = NULL;
struct host_if_drv *hif_drv = vif->hif_drv;
struct wilc_vif *vif_tmp;
int srcu_idx;
PRINT_INFO(vif->ndev, HOSTINF_DBG, "Setting SCAN params\n");
PRINT_INFO(vif->ndev, HOSTINF_DBG, "Scanning: In [%d] state\n",
hif_drv->hif_state);
srcu_idx = srcu_read_lock(&vif->wilc->srcu);
list_for_each_entry_rcu(vif_tmp, &vif->wilc->vif_list, list) {
struct host_if_drv *hif_drv_tmp;
if (vif_tmp == NULL || vif_tmp->hif_drv == NULL)
continue;
hif_drv_tmp = vif_tmp->hif_drv;
if (hif_drv_tmp->hif_state != HOST_IF_IDLE &&
hif_drv_tmp->hif_state != HOST_IF_CONNECTED) {
PRINT_INFO(vif_tmp->ndev, GENERIC_DBG,
"Abort scan. In state [%d]\n",
hif_drv_tmp->hif_state);
result = -EBUSY;
srcu_read_unlock(&vif->wilc->srcu, srcu_idx);
goto error;
}
}
srcu_read_unlock(&vif->wilc->srcu, srcu_idx);
if (vif->connecting) {
PRINT_INFO(vif->ndev, GENERIC_DBG,
"Don't do scan in (CONNECTING) state\n");
result = -EBUSY;
goto error;
}
PRINT_INFO(vif->ndev, HOSTINF_DBG, "Setting SCAN params\n");
hif_drv->usr_scan_req.ch_cnt = 0;
if (request->n_ssids) {
for (i = 0; i < request->n_ssids; i++)
valuesize += ((request->ssids[i].ssid_len) + 1);
search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
if (search_ssid_vals) {
wid_list[index].id = WID_SSID_PROBE_REQ;
wid_list[index].type = WID_STR;
wid_list[index].val = search_ssid_vals;
buffer = wid_list[index].val;
*buffer++ = request->n_ssids;
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"In Handle_ProbeRequest number of ssid %d\n",
request->n_ssids);
for (i = 0; i < request->n_ssids; i++) {
*buffer++ = request->ssids[i].ssid_len;
memcpy(buffer, request->ssids[i].ssid,
request->ssids[i].ssid_len);
buffer += request->ssids[i].ssid_len;
}
wid_list[index].size = (s32)(valuesize + 1);
index++;
}
}
wid_list[index].id = WID_INFO_ELEMENT_PROBE;
wid_list[index].type = WID_BIN_DATA;
wid_list[index].val = (s8 *)request->ie;
wid_list[index].size = request->ie_len;
index++;
wid_list[index].id = WID_SCAN_TYPE;
wid_list[index].type = WID_CHAR;
wid_list[index].size = sizeof(char);
wid_list[index].val = (s8 *)&scan_type;
index++;
if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
wid_list[index].id = WID_PASSIVE_SCAN_TIME;
wid_list[index].type = WID_SHORT;
wid_list[index].size = sizeof(u16);
wid_list[index].val = (s8 *)&request->duration;
index++;
scan_timeout = (request->duration * ch_list_len) + 500;
} else {
scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
}
wid_list[index].id = WID_SCAN_CHANNEL_LIST;
wid_list[index].type = WID_BIN_DATA;
if (ch_freq_list && ch_list_len > 0) {
for (i = 0; i < ch_list_len; i++) {
if (ch_freq_list[i] > 0)
ch_freq_list[i] -= 1;
}
}
wid_list[index].val = ch_freq_list;
wid_list[index].size = ch_list_len;
index++;
wid_list[index].id = WID_START_SCAN_REQ;
wid_list[index].type = WID_CHAR;
wid_list[index].size = sizeof(char);
wid_list[index].val = (s8 *)&scan_source;
index++;
hif_drv->usr_scan_req.scan_result = scan_result_fn;
hif_drv->usr_scan_req.arg = user_arg;
result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
if (result) {
netdev_err(vif->ndev, "Failed to send scan parameters\n");
goto error;
} else {
hif_drv->scan_timer_vif = vif;
PRINT_INFO(vif->ndev, HOSTINF_DBG,
">> Starting the SCAN timer\n");
mod_timer(&hif_drv->scan_timer,
jiffies + msecs_to_jiffies(scan_timeout));
}
error:
kfree(search_ssid_vals);
return result;
}
static int wilc_send_connect_wid(struct wilc_vif *vif)
{
int result = 0;
struct wid wid_list[5];
u32 wid_cnt = 0;
struct host_if_drv *hif_drv = vif->hif_drv;
struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
struct wilc_join_bss_param *bss_param = conn_attr->param;
struct wilc_vif *vif_tmp;
int srcu_idx;
srcu_idx = srcu_read_lock(&vif->wilc->srcu);
list_for_each_entry_rcu(vif_tmp, &vif->wilc->vif_list, list) {
struct host_if_drv *hif_drv_tmp;
if (vif_tmp == NULL || vif_tmp->hif_drv == NULL)
continue;
hif_drv_tmp = vif_tmp->hif_drv;
if (hif_drv_tmp->hif_state == HOST_IF_SCANNING) {
PRINT_INFO(vif_tmp->ndev, GENERIC_DBG,
"Abort connect in state [%d]\n",
hif_drv_tmp->hif_state);
result = -EBUSY;
srcu_read_unlock(&vif->wilc->srcu, srcu_idx);
goto error;
}
}
srcu_read_unlock(&vif->wilc->srcu, srcu_idx);
wid_list[wid_cnt].id = WID_SET_MFP;
wid_list[wid_cnt].type = WID_CHAR;
wid_list[wid_cnt].size = sizeof(char);
wid_list[wid_cnt].val = (s8 *)&conn_attr->mfp_type;
wid_cnt++;
wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
wid_list[wid_cnt].type = WID_BIN_DATA;
wid_list[wid_cnt].val = conn_attr->req_ies;
wid_list[wid_cnt].size = conn_attr->req_ies_len;
wid_cnt++;
wid_list[wid_cnt].id = WID_11I_MODE;
wid_list[wid_cnt].type = WID_CHAR;
wid_list[wid_cnt].size = sizeof(char);
wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
wid_cnt++;
PRINT_D(vif->ndev, HOSTINF_DBG, "Encrypt Mode = %x\n",
conn_attr->security);
wid_list[wid_cnt].id = WID_AUTH_TYPE;
wid_list[wid_cnt].type = WID_CHAR;
wid_list[wid_cnt].size = sizeof(char);
wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
wid_cnt++;
PRINT_D(vif->ndev, HOSTINF_DBG, "Authentication Type = %x\n",
conn_attr->auth_type);
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"Connecting to network on channel %d\n", conn_attr->ch);
wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
wid_list[wid_cnt].type = WID_STR;
wid_list[wid_cnt].size = sizeof(*bss_param);
wid_list[wid_cnt].val = (u8 *)bss_param;
wid_cnt++;
PRINT_INFO(vif->ndev, GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
if (result) {
netdev_err(vif->ndev, "failed to send config packet\n");
goto error;
} else {
if (conn_attr->auth_type == WILC_FW_AUTH_SAE)
hif_drv->hif_state = HOST_IF_EXTERNAL_AUTH;
else
hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
}
return 0;
error:
kfree(conn_attr->req_ies);
conn_attr->req_ies = NULL;
return result;
}
static void handle_connect_timeout(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
struct wilc_vif *vif = msg->vif;
int result;
struct wid wid;
u16 dummy_reason_code = 0;
struct host_if_drv *hif_drv = vif->hif_drv;
if (!hif_drv) {
netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
goto out;
}
hif_drv->hif_state = HOST_IF_IDLE;
if (hif_drv->conn_info.conn_result) {
hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
WILC_MAC_STATUS_DISCONNECTED,
hif_drv->conn_info.arg);
} else {
netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
}
wid.id = WID_DISCONNECT;
wid.type = WID_CHAR;
wid.val = (s8 *)&dummy_reason_code;
wid.size = sizeof(char);
PRINT_INFO(vif->ndev, HOSTINF_DBG, "Sending disconnect request\n");
result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
if (result)
netdev_err(vif->ndev, "Failed to send disconnect\n");
hif_drv->conn_info.req_ies_len = 0;
kfree(hif_drv->conn_info.req_ies);
hif_drv->conn_info.req_ies = NULL;
out:
kfree(msg);
}
void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
struct cfg80211_crypto_settings *crypto)
{
struct wilc_join_bss_param *param;
struct ieee80211_p2p_noa_attr noa_attr;
u8 rates_len = 0;
const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
int ret;
const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
param = kzalloc(sizeof(*param), GFP_KERNEL);
if (!param)
return NULL;
param->beacon_period = cpu_to_le16(bss->beacon_interval);
param->cap_info = cpu_to_le16(bss->capability);
param->bss_type = WILC_FW_BSS_TYPE_INFRA;
param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
ether_addr_copy(param->bssid, bss->bssid);
ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
if (ssid_elm) {
if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
}
tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
if (tim_elm && tim_elm[1] >= 2)
param->dtim_period = tim_elm[3];
memset(param->p_suites, 0xFF, 3);
memset(param->akm_suites, 0xFF, 3);
rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
if (rates_ie) {
rates_len = rates_ie[1];
if (rates_len > WILC_MAX_RATES_SUPPORTED)
rates_len = WILC_MAX_RATES_SUPPORTED;
param->supp_rates[0] = rates_len;
memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len);
}
if (rates_len < WILC_MAX_RATES_SUPPORTED) {
supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
ies->data, ies->len);
if (supp_rates_ie) {
u8 ext_rates = supp_rates_ie[1];
if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
else
param->supp_rates[0] += ext_rates;
memcpy(¶m->supp_rates[rates_len + 1],
supp_rates_ie + 2,
(param->supp_rates[0] - rates_len));
}
}
ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
if (ht_ie)
param->ht_capable = true;
ret = cfg80211_get_p2p_attr(ies->data, ies->len,
IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
(u8 *)&noa_attr, sizeof(noa_attr));
if (ret > 0) {
param->tsf_lo = cpu_to_le32(ies->tsf);
param->noa_enabled = 1;
param->idx = noa_attr.index;
if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
param->opp_enabled = 1;
param->opp_en.ct_window = noa_attr.oppps_ctwindow;
param->opp_en.cnt = noa_attr.desc[0].count;
param->opp_en.duration = noa_attr.desc[0].duration;
param->opp_en.interval = noa_attr.desc[0].interval;
param->opp_en.start_time = noa_attr.desc[0].start_time;
} else {
param->opp_enabled = 0;
param->opp_dis.cnt = noa_attr.desc[0].count;
param->opp_dis.duration = noa_attr.desc[0].duration;
param->opp_dis.interval = noa_attr.desc[0].interval;
param->opp_dis.start_time = noa_attr.desc[0].start_time;
}
}
wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
WLAN_OUI_TYPE_MICROSOFT_WMM,
ies->data, ies->len);
if (wmm_ie) {
struct ieee80211_wmm_param_ie *ie;
ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
ie->version == 1) {
param->wmm_cap = true;
if (ie->qos_info & BIT(7))
param->uapsd_cap = true;
}
}
wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
WLAN_OUI_TYPE_MICROSOFT_WPA,
ies->data, ies->len);
if (wpa_ie) {
param->mode_802_11i = 1;
param->rsn_found = true;
}
rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
if (rsn_ie) {
int rsn_ie_len = sizeof(struct element) + rsn_ie[1];
int offset = 8;
param->mode_802_11i = 2;
param->rsn_found = true;
/* extract RSN capabilities */
if (offset < rsn_ie_len) {
/* skip over pairwise suites */
offset += (rsn_ie[offset] * 4) + 2;
if (offset < rsn_ie_len) {
/* skip over authentication suites */
offset += (rsn_ie[offset] * 4) + 2;
if (offset + 1 < rsn_ie_len)
memcpy(param->rsn_cap, &rsn_ie[offset], 2);
}
}
}
if (param->rsn_found) {
int i;
param->rsn_grp_policy = crypto->cipher_group & 0xFF;
for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
}
return (void *)param;
}
static void handle_rcvd_ntwrk_info(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
struct host_if_drv *hif_drv;
struct wilc_user_scan_req *scan_req;
const u8 *ch_elm;
u8 *ies;
int ies_len;
size_t offset;
PRINT_D(msg->vif->ndev, HOSTINF_DBG,
"Handling received network info\n");
if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
else
goto done;
ies = rcvd_info->mgmt->u.beacon.variable;
ies_len = rcvd_info->frame_len - offset;
if (ies_len <= 0)
goto done;
PRINT_INFO(msg->vif->ndev, HOSTINF_DBG, "New network found\n");
/* extract the channel from received mgmt frame */
ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
if (ch_elm && ch_elm[1] > 0)
rcvd_info->ch = ch_elm[2];
if (!msg->vif || !msg->vif->hif_drv)
goto done;
hif_drv = msg->vif->hif_drv;
scan_req = &hif_drv->usr_scan_req;
if (scan_req->scan_result)
scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
scan_req->arg);
done:
kfree(rcvd_info->mgmt);
kfree(msg);
}
static void 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)
{
int result;
struct wid wid;
wid.id = WID_ASSOC_RES_INFO;
wid.type = WID_STR;
wid.val = assoc_resp_info;
wid.size = max_assoc_resp_info_len;
result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
if (result) {
*rcvd_assoc_resp_info_len = 0;
netdev_err(vif->ndev, "Failed to send association response\n");
return;
}
*rcvd_assoc_resp_info_len = wid.size;
}
static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
struct wilc_conn_info *ret_conn_info)
{
u8 *ies;
u16 ies_len;
struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
ret_conn_info->status = le16_to_cpu(res->status_code);
if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
ies = &buffer[sizeof(*res)];
ies_len = buffer_len - sizeof(*res);
ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
if (!ret_conn_info->resp_ies)
return -ENOMEM;
ret_conn_info->resp_ies_len = ies_len;
}
return 0;
}
static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
u8 mac_status)
{
struct host_if_drv *hif_drv = vif->hif_drv;
struct wilc_conn_info *conn_info = &hif_drv->conn_info;
if (mac_status == WILC_MAC_STATUS_CONNECTED) {
u32 assoc_resp_info_len;
memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
WILC_MAX_ASSOC_RESP_FRAME_SIZE,
&assoc_resp_info_len);
PRINT_D(vif->ndev, HOSTINF_DBG,
"Received association response = %d\n",
assoc_resp_info_len);
if (assoc_resp_info_len != 0) {
s32 err = 0;
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"Parsing association response\n");
err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
assoc_resp_info_len,
conn_info);
if (err)
netdev_err(vif->ndev,
"wilc_parse_assoc_resp_info() returned error %d\n",
err);
}
}
del_timer(&hif_drv->connect_timer);
conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
hif_drv->conn_info.arg);
if (mac_status == WILC_MAC_STATUS_CONNECTED &&
conn_info->status == WLAN_STATUS_SUCCESS) {
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"MAC status : CONNECTED and Connect Status : Successful\n");
ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
hif_drv->hif_state = HOST_IF_CONNECTED;
} else {
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"MAC status : %d and Connect Status : %d\n",
mac_status, conn_info->status);
hif_drv->hif_state = HOST_IF_IDLE;
}
kfree(conn_info->resp_ies);
conn_info->resp_ies = NULL;
conn_info->resp_ies_len = 0;
kfree(conn_info->req_ies);
conn_info->req_ies = NULL;
conn_info->req_ies_len = 0;
}
void wilc_handle_disconnect(struct wilc_vif *vif)
{
struct host_if_drv *hif_drv = vif->hif_drv;
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"Received WILC_MAC_STATUS_DISCONNECTED from the FW\n");
if (hif_drv->usr_scan_req.scan_result) {
PRINT_INFO(vif->ndev, HOSTINF_DBG,
"\n\n<< Abort the running OBSS Scan >>\n\n");
del_timer(&hif_drv->scan_timer);
handle_scan_done(vif, SCAN_EVENT_ABORTED);
}
if (hif_drv->conn_info.conn_result)
hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
0, hif_drv->conn_info.arg);
eth_zero_addr(hif_drv->assoc_bssid);
hif_drv->conn_info.req_ies_len = 0;
kfree(hif_drv->conn_info.req_ies);
hif_drv->conn_info.req_ies = NULL;
hif_drv->hif_state = HOST_IF_IDLE;
}
static void handle_rcvd_gnrl_async_info(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
struct wilc_vif *vif = msg->vif;
struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
struct host_if_drv *hif_drv = vif->hif_drv;
if (!hif_drv) {
netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
goto free_msg;
}
PRINT_INFO(vif->ndev, GENERIC_DBG,
"Current State = %d,Received state = %d\n",
hif_drv->hif_state, mac_info->status);
if (!hif_drv->conn_info.conn_result) {
netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
goto free_msg;
}
if (hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) {
cfg80211_external_auth_request(vif->ndev, &vif->auth,
GFP_KERNEL);
hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
} else if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
/* check connecting state before parsing the ASSOC response */
if (!vif->connecting)
goto free_msg;
host_int_parse_assoc_resp_info(vif, mac_info->status);
} else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
if (hif_drv->hif_state == HOST_IF_CONNECTED) {
wilc_handle_disconnect(vif);
} else if (hif_drv->usr_scan_req.scan_result) {
PRINT_WRN(vif->ndev, HOSTINF_DBG,
"Received WILC_MAC_STATUS_DISCONNECTED. Abort the running Scan");
del_timer(&hif_drv->scan_timer);
handle_scan_done(vif, SCAN_EVENT_ABORTED);
}
}
free_msg:
kfree(msg);
}
int wilc_disconnect(struct wilc_vif *vif)
{
struct wid wid;
struct host_if_drv *hif_drv = vif->hif_drv;
struct wilc_user_scan_req *scan_req;
struct wilc_conn_info *conn_info;
int result;
u16 dummy_reason_code = 0;
struct wilc_vif *vif_tmp;
int srcu_idx;
srcu_idx = srcu_read_lock(&vif->wilc->srcu);
list_for_each_entry_rcu(vif_tmp, &vif->wilc->vif_list, list) {
struct host_if_drv *hif_drv_tmp;
if (vif_tmp == NULL || vif_tmp->hif_drv == NULL)
continue;
hif_drv_tmp = vif_tmp->hif_drv;
if (hif_drv_tmp->hif_state == HOST_IF_SCANNING) {
PRINT_INFO(vif_tmp->ndev, GENERIC_DBG,
"Abort scan from disconnect. state [%d]\n",
hif_drv_tmp->hif_state);
del_timer(&hif_drv_tmp->scan_timer);
handle_scan_done(vif_tmp, SCAN_EVENT_ABORTED);
}
}
srcu_read_unlock(&vif->wilc->srcu, srcu_idx);
wid.id = WID_DISCONNECT;
wid.type = WID_CHAR;
wid.val = (s8 *)&dummy_reason_code;
wid.size = sizeof(char);
PRINT_INFO(vif->ndev, HOSTINF_DBG, "Sending disconnect request\n");
result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
if (result) {
netdev_err(vif->ndev, "Failed to send disconnect\n");
return result;
}
scan_req = &hif_drv->usr_scan_req;
conn_info = &hif_drv->conn_info;
if (scan_req->scan_result) {
del_timer(&hif_drv->scan_timer);
scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
scan_req->scan_result = NULL;
}
if (conn_info->conn_result) {
if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) {
del_timer(&hif_drv->connect_timer);
conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP,
WILC_MAC_STATUS_DISCONNECTED,
conn_info->arg);
} else if (hif_drv->hif_state == HOST_IF_CONNECTED) {
conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
WILC_MAC_STATUS_DISCONNECTED,
conn_info->arg);
}
} else {
netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
}
hif_drv->hif_state = HOST_IF_IDLE;
eth_zero_addr(hif_drv->assoc_bssid);
conn_info->req_ies_len = 0;
kfree(conn_info->req_ies);
conn_info->req_ies = NULL;
conn_info->conn_result = NULL;
return 0;
}
int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
{
struct wid wid_list[5];
u32 wid_cnt = 0, result;
wid_list[wid_cnt].id = WID_LINKSPEED;
wid_list[wid_cnt].type = WID_CHAR;
wid_list[wid_cnt].size = sizeof(char);
wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
wid_cnt++;
wid_list[wid_cnt].id = WID_RSSI;
wid_list[wid_cnt].type = WID_CHAR;
wid_list[wid_cnt].size = sizeof(char);
wid_list[wid_cnt].val = (s8 *)&stats->rssi;
wid_cnt++;
wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
wid_list[wid_cnt].type = WID_INT;
wid_list[wid_cnt].size = sizeof(u32);
wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
wid_cnt++;
wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
wid_list[wid_cnt].type = WID_INT;
wid_list[wid_cnt].size = sizeof(u32);
wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
wid_cnt++;
wid_list[wid_cnt].id = WID_FAILED_COUNT;
wid_list[wid_cnt].type = WID_INT;
wid_list[wid_cnt].size = sizeof(u32);
wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
wid_cnt++;
result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
if (result) {
netdev_err(vif->ndev, "Failed to send scan parameters\n");
return result;
}