-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwl_cfgp2p.c
2465 lines (2167 loc) · 70.1 KB
/
wl_cfgp2p.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
/*
* Linux cfgp2p driver
*
* Copyright (C) 1999-2013, Broadcom Corporation
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
* under the terms of the GNU General Public License version 2 (the "GPL"),
* available at http://www.broadcom.com/licenses/GPLv2.php, with the
* following added to such license:
*
* As a special exception, the copyright holders of this software give you
* permission to link this software with independent modules, and to copy and
* distribute the resulting executable under terms of your choice, provided that
* you also meet, for each linked independent module, the terms and conditions of
* the license of that module. An independent module is a module which is not
* derived from this software. The special exception does not apply to any
* modifications of the software.
*
* Notwithstanding the above, under no circumstances may you combine this
* software in any way with any other Broadcom software provided under a license
* other than the GPL, without Broadcom's express prior written consent.
*
* $Id: wl_cfgp2p.c 387791 2013-02-27 03:34:55Z $
*
*/
#include <typedefs.h>
#include <linuxver.h>
#include <osl.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/if_arp.h>
#include <asm/uaccess.h>
#include <bcmutils.h>
#include <bcmendian.h>
#include <proto/ethernet.h>
#include <proto/802.11.h>
#include <wl_cfg80211.h>
#include <wl_cfgp2p.h>
#include <wldev_common.h>
#include <wl_android.h>
static s8 scanparambuf[WLC_IOCTL_SMLEN];
static s8 g_mgmt_ie_buf[2048];
static bool
wl_cfgp2p_has_ie(u8 *ie, u8 **tlvs, u32 *tlvs_len, const u8 *oui, u32 oui_len, u8 type);
static u32
wl_cfgp2p_vndr_ie(struct wl_priv *wl, u8 *iebuf, s32 pktflag,
s8 *oui, s32 ie_id, s8 *data, s32 datalen, const s8* add_del_cmd);
static int wl_cfgp2p_start_xmit(struct sk_buff *skb, struct net_device *ndev);
static int wl_cfgp2p_do_ioctl(struct net_device *net, struct ifreq *ifr, int cmd);
static int wl_cfgp2p_if_open(struct net_device *net);
static int wl_cfgp2p_if_stop(struct net_device *net);
static s32 wl_cfgp2p_cancel_listen(struct wl_priv *wl, struct net_device *ndev,
bool notify);
static const struct net_device_ops wl_cfgp2p_if_ops = {
.ndo_open = wl_cfgp2p_if_open,
.ndo_stop = wl_cfgp2p_if_stop,
.ndo_do_ioctl = wl_cfgp2p_do_ioctl,
.ndo_start_xmit = wl_cfgp2p_start_xmit,
};
bool wl_cfgp2p_is_pub_action(void *frame, u32 frame_len)
{
wifi_p2p_pub_act_frame_t *pact_frm;
if (frame == NULL)
return false;
pact_frm = (wifi_p2p_pub_act_frame_t *)frame;
if (frame_len < sizeof(wifi_p2p_pub_act_frame_t) -1)
return false;
if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
pact_frm->action == P2P_PUB_AF_ACTION &&
pact_frm->oui_type == P2P_VER &&
memcmp(pact_frm->oui, P2P_OUI, sizeof(pact_frm->oui)) == 0) {
return true;
}
return false;
}
bool wl_cfgp2p_is_p2p_action(void *frame, u32 frame_len)
{
wifi_p2p_action_frame_t *act_frm;
if (frame == NULL)
return false;
act_frm = (wifi_p2p_action_frame_t *)frame;
if (frame_len < sizeof(wifi_p2p_action_frame_t) -1)
return false;
if (act_frm->category == P2P_AF_CATEGORY &&
act_frm->type == P2P_VER &&
memcmp(act_frm->OUI, P2P_OUI, DOT11_OUI_LEN) == 0) {
return true;
}
return false;
}
#ifdef WL11U
#define GAS_RESP_LEN 2
#define DOUBLE_TLV_BODY_OFF 4
#define GAS_RESP_OFFSET 4
#define GAS_CRESP_OFFSET 5
bool wl_cfgp2p_find_gas_subtype(u8 subtype, u8* data, u32 len)
{
bcm_tlv_t *ie = (bcm_tlv_t *)data;
u8 *frame = NULL;
u16 id, flen;
/* Skipped first ANQP Element, if frame has anqp elemnt */
ie = bcm_parse_tlvs(ie, (int)len, DOT11_MNG_ADVERTISEMENT_ID);
if (ie == NULL)
return false;
frame = (uint8 *)ie + ie->len + TLV_HDR_LEN + GAS_RESP_LEN;
id = ((u16) (((frame)[1] << 8) | (frame)[0]));
flen = ((u16) (((frame)[3] << 8) | (frame)[2]));
/* If the contents match the OUI and the type */
if (flen >= WFA_OUI_LEN + 1 &&
id == P2PSD_GAS_NQP_INFOID &&
!bcmp(&frame[DOUBLE_TLV_BODY_OFF], (const uint8*)WFA_OUI, WFA_OUI_LEN) &&
subtype == frame[DOUBLE_TLV_BODY_OFF+WFA_OUI_LEN]) {
return true;
}
return false;
}
#endif /* WL11U */
bool wl_cfgp2p_is_gas_action(void *frame, u32 frame_len)
{
wifi_p2psd_gas_pub_act_frame_t *sd_act_frm;
if (frame == NULL)
return false;
sd_act_frm = (wifi_p2psd_gas_pub_act_frame_t *)frame;
if (frame_len < sizeof(wifi_p2psd_gas_pub_act_frame_t) - 1)
return false;
if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
return false;
#ifdef WL11U
if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP)
return wl_cfgp2p_find_gas_subtype(P2PSD_GAS_OUI_SUBTYPE,
(u8 *)sd_act_frm->query_data + GAS_RESP_OFFSET,
frame_len);
else if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
return wl_cfgp2p_find_gas_subtype(P2PSD_GAS_OUI_SUBTYPE,
(u8 *)sd_act_frm->query_data + GAS_CRESP_OFFSET,
frame_len);
else if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ)
return true;
else
return false;
#else
if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
return true;
else
return false;
#endif /* WL11U */
}
void wl_cfgp2p_print_actframe(bool tx, void *frame, u32 frame_len, u32 channel)
{
wifi_p2p_pub_act_frame_t *pact_frm;
wifi_p2p_action_frame_t *act_frm;
wifi_p2psd_gas_pub_act_frame_t *sd_act_frm;
if (!frame || frame_len <= 2)
return;
if (wl_cfgp2p_is_pub_action(frame, frame_len)) {
pact_frm = (wifi_p2p_pub_act_frame_t *)frame;
switch (pact_frm->subtype) {
case P2P_PAF_GON_REQ:
CFGP2P_ACTION(("%s P2P Group Owner Negotiation Req Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_GON_RSP:
CFGP2P_ACTION(("%s P2P Group Owner Negotiation Rsp Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_GON_CONF:
CFGP2P_ACTION(("%s P2P Group Owner Negotiation Confirm Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_INVITE_REQ:
CFGP2P_ACTION(("%s P2P Invitation Request Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_INVITE_RSP:
CFGP2P_ACTION(("%s P2P Invitation Response Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_DEVDIS_REQ:
CFGP2P_ACTION(("%s P2P Device Discoverability Request Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_DEVDIS_RSP:
CFGP2P_ACTION(("%s P2P Device Discoverability Response Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_PROVDIS_REQ:
CFGP2P_ACTION(("%s P2P Provision Discovery Request Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_PAF_PROVDIS_RSP:
CFGP2P_ACTION(("%s P2P Provision Discovery Response Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
default:
CFGP2P_ACTION(("%s Unknown P2P Public Action Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
}
} else if (wl_cfgp2p_is_p2p_action(frame, frame_len)) {
act_frm = (wifi_p2p_action_frame_t *)frame;
switch (act_frm->subtype) {
case P2P_AF_NOTICE_OF_ABSENCE:
CFGP2P_ACTION(("%s P2P Notice of Absence Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_AF_PRESENCE_REQ:
CFGP2P_ACTION(("%s P2P Presence Request Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_AF_PRESENCE_RSP:
CFGP2P_ACTION(("%s P2P Presence Response Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
case P2P_AF_GO_DISC_REQ:
CFGP2P_ACTION(("%s P2P Discoverability Request Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
break;
default:
CFGP2P_ACTION(("%s Unknown P2P Action Frame,"
" channel=%d\n", (tx)? "TX": "RX", channel));
}
} else if (wl_cfgp2p_is_gas_action(frame, frame_len)) {
sd_act_frm = (wifi_p2psd_gas_pub_act_frame_t *)frame;
switch (sd_act_frm->action) {
case P2PSD_ACTION_ID_GAS_IREQ:
CFGP2P_ACTION(("%s P2P GAS Initial Request,"
" channel=%d\n", (tx)? "TX" : "RX", channel));
break;
case P2PSD_ACTION_ID_GAS_IRESP:
CFGP2P_ACTION(("%s P2P GAS Initial Response,"
" channel=%d\n", (tx)? "TX" : "RX", channel));
break;
case P2PSD_ACTION_ID_GAS_CREQ:
CFGP2P_ACTION(("%s P2P GAS Comback Request,"
" channel=%d\n", (tx)? "TX" : "RX", channel));
break;
case P2PSD_ACTION_ID_GAS_CRESP:
CFGP2P_ACTION(("%s P2P GAS Comback Response,"
" channel=%d\n", (tx)? "TX" : "RX", channel));
break;
default:
CFGP2P_ACTION(("%s Unknown P2P GAS Frame,"
" channel=%d\n", (tx)? "TX" : "RX", channel));
}
}
}
/*
* Initialize variables related to P2P
*
*/
s32
wl_cfgp2p_init_priv(struct wl_priv *wl)
{
if (!(wl->p2p = kzalloc(sizeof(struct p2p_info), GFP_KERNEL))) {
CFGP2P_ERR(("struct p2p_info allocation failed\n"));
return -ENOMEM;
}
#define INIT_IE(IE_TYPE, BSS_TYPE) \
do { \
memset(wl_to_p2p_bss_saved_ie(wl, BSS_TYPE).p2p_ ## IE_TYPE ## _ie, 0, \
sizeof(wl_to_p2p_bss_saved_ie(wl, BSS_TYPE).p2p_ ## IE_TYPE ## _ie)); \
wl_to_p2p_bss_saved_ie(wl, BSS_TYPE).p2p_ ## IE_TYPE ## _ie_len = 0; \
} while (0);
INIT_IE(probe_req, P2PAPI_BSSCFG_PRIMARY);
INIT_IE(probe_res, P2PAPI_BSSCFG_PRIMARY);
INIT_IE(assoc_req, P2PAPI_BSSCFG_PRIMARY);
INIT_IE(assoc_res, P2PAPI_BSSCFG_PRIMARY);
INIT_IE(beacon, P2PAPI_BSSCFG_PRIMARY);
INIT_IE(probe_req, P2PAPI_BSSCFG_DEVICE);
INIT_IE(probe_res, P2PAPI_BSSCFG_DEVICE);
INIT_IE(assoc_req, P2PAPI_BSSCFG_DEVICE);
INIT_IE(assoc_res, P2PAPI_BSSCFG_DEVICE);
INIT_IE(beacon, P2PAPI_BSSCFG_DEVICE);
INIT_IE(probe_req, P2PAPI_BSSCFG_CONNECTION);
INIT_IE(probe_res, P2PAPI_BSSCFG_CONNECTION);
INIT_IE(assoc_req, P2PAPI_BSSCFG_CONNECTION);
INIT_IE(assoc_res, P2PAPI_BSSCFG_CONNECTION);
INIT_IE(beacon, P2PAPI_BSSCFG_CONNECTION);
#undef INIT_IE
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_PRIMARY) = wl_to_prmry_ndev(wl);
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_PRIMARY) = 0;
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_DEVICE) = NULL;
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) = 0;
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION) = NULL;
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_CONNECTION) = 0;
return BCME_OK;
}
/*
* Deinitialize variables related to P2P
*
*/
void
wl_cfgp2p_deinit_priv(struct wl_priv *wl)
{
CFGP2P_DBG(("In\n"));
if (wl->p2p) {
kfree(wl->p2p);
wl->p2p = NULL;
}
wl->p2p_supported = 0;
}
/*
* Set P2P functions into firmware
*/
s32
wl_cfgp2p_set_firm_p2p(struct wl_priv *wl)
{
struct net_device *ndev = wl_to_prmry_ndev(wl);
struct ether_addr null_eth_addr = { { 0, 0, 0, 0, 0, 0 } };
s32 ret = BCME_OK;
s32 val = 0;
/* Do we have to check whether APSTA is enabled or not ? */
ret = wldev_iovar_getint(ndev, "apsta", &val);
if (ret < 0) {
CFGP2P_ERR(("get apsta error %d\n", ret));
return ret;
}
if (val == 0) {
val = 1;
ret = wldev_ioctl(ndev, WLC_DOWN, &val, sizeof(s32), true);
if (ret < 0) {
CFGP2P_ERR(("WLC_DOWN error %d\n", ret));
return ret;
}
wldev_iovar_setint(ndev, "apsta", val);
ret = wldev_ioctl(ndev, WLC_UP, &val, sizeof(s32), true);
if (ret < 0) {
CFGP2P_ERR(("WLC_UP error %d\n", ret));
return ret;
}
}
/* In case of COB type, firmware has default mac address
* After Initializing firmware, we have to set current mac address to
* firmware for P2P device address
*/
ret = wldev_iovar_setbuf_bsscfg(ndev, "p2p_da_override", &null_eth_addr,
sizeof(null_eth_addr), wl->ioctl_buf, WLC_IOCTL_MAXLEN, 0, &wl->ioctl_buf_sync);
if (ret && ret != BCME_UNSUPPORTED) {
CFGP2P_ERR(("failed to update device address ret %d\n", ret));
}
return ret;
}
/* Create a new P2P BSS.
* Parameters:
* @mac : MAC address of the BSS to create
* @if_type : interface type: WL_P2P_IF_GO or WL_P2P_IF_CLIENT
* @chspec : chspec to use if creating a GO BSS.
* Returns 0 if success.
*/
s32
wl_cfgp2p_ifadd(struct wl_priv *wl, struct ether_addr *mac, u8 if_type,
chanspec_t chspec)
{
wl_p2p_if_t ifreq;
s32 err;
u32 scb_timeout = WL_SCB_TIMEOUT;
struct net_device *ndev = wl_to_prmry_ndev(wl);
ifreq.type = if_type;
ifreq.chspec = chspec;
memcpy(ifreq.addr.octet, mac->octet, sizeof(ifreq.addr.octet));
CFGP2P_DBG(("---wl p2p_ifadd "MACDBG" %s %u\n",
MAC2STRDBG(ifreq.addr.octet),
(if_type == WL_P2P_IF_GO) ? "go" : "client",
(chspec & WL_CHANSPEC_CHAN_MASK) >> WL_CHANSPEC_CHAN_SHIFT));
err = wldev_iovar_setbuf(ndev, "p2p_ifadd", &ifreq, sizeof(ifreq),
wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
if (unlikely(err < 0))
printk("'wl p2p_ifadd' error %d\n", err);
else if (if_type == WL_P2P_IF_GO) {
err = wldev_ioctl(ndev, WLC_SET_SCB_TIMEOUT, &scb_timeout, sizeof(u32), true);
if (unlikely(err < 0))
printk("'wl scb_timeout' error %d\n", err);
}
return err;
}
/* Disable a P2P BSS.
* Parameters:
* @mac : MAC address of the BSS to create
* Returns 0 if success.
*/
s32
wl_cfgp2p_ifdisable(struct wl_priv *wl, struct ether_addr *mac)
{
s32 ret;
struct net_device *netdev = wl_to_prmry_ndev(wl);
CFGP2P_INFO(("------primary idx %d : wl p2p_ifdis "MACDBG"\n",
netdev->ifindex, MAC2STRDBG(mac->octet)));
ret = wldev_iovar_setbuf(netdev, "p2p_ifdis", mac, sizeof(*mac),
wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
if (unlikely(ret < 0)) {
printk("'wl p2p_ifdis' error %d\n", ret);
}
return ret;
}
/* Delete a P2P BSS.
* Parameters:
* @mac : MAC address of the BSS to create
* Returns 0 if success.
*/
s32
wl_cfgp2p_ifdel(struct wl_priv *wl, struct ether_addr *mac)
{
s32 ret;
struct net_device *netdev = wl_to_prmry_ndev(wl);
CFGP2P_INFO(("------primary idx %d : wl p2p_ifdel "MACDBG"\n",
netdev->ifindex, MAC2STRDBG(mac->octet)));
ret = wldev_iovar_setbuf(netdev, "p2p_ifdel", mac, sizeof(*mac),
wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
if (unlikely(ret < 0)) {
printk("'wl p2p_ifdel' error %d\n", ret);
}
return ret;
}
/* Change a P2P Role.
* Parameters:
* @mac : MAC address of the BSS to change a role
* Returns 0 if success.
*/
s32
wl_cfgp2p_ifchange(struct wl_priv *wl, struct ether_addr *mac, u8 if_type,
chanspec_t chspec)
{
wl_p2p_if_t ifreq;
s32 err;
u32 scb_timeout = WL_SCB_TIMEOUT;
struct net_device *netdev = wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_CONNECTION);
ifreq.type = if_type;
ifreq.chspec = chspec;
memcpy(ifreq.addr.octet, mac->octet, sizeof(ifreq.addr.octet));
CFGP2P_INFO(("---wl p2p_ifchange "MACDBG" %s %u"
" chanspec 0x%04x\n", MAC2STRDBG(ifreq.addr.octet),
(if_type == WL_P2P_IF_GO) ? "go" : "client",
(chspec & WL_CHANSPEC_CHAN_MASK) >> WL_CHANSPEC_CHAN_SHIFT,
ifreq.chspec));
err = wldev_iovar_setbuf(netdev, "p2p_ifupd", &ifreq, sizeof(ifreq),
wl->ioctl_buf, WLC_IOCTL_MAXLEN, &wl->ioctl_buf_sync);
if (unlikely(err < 0)) {
printk("'wl p2p_ifupd' error %d\n", err);
} else if (if_type == WL_P2P_IF_GO) {
err = wldev_ioctl(netdev, WLC_SET_SCB_TIMEOUT, &scb_timeout, sizeof(u32), true);
if (unlikely(err < 0))
printk("'wl scb_timeout' error %d\n", err);
}
return err;
}
/* Get the index of a created P2P BSS.
* Parameters:
* @mac : MAC address of the created BSS
* @index : output: index of created BSS
* Returns 0 if success.
*/
s32
wl_cfgp2p_ifidx(struct wl_priv *wl, struct ether_addr *mac, s32 *index)
{
s32 ret;
u8 getbuf[64];
struct net_device *dev = wl_to_prmry_ndev(wl);
CFGP2P_INFO(("---wl p2p_if "MACDBG"\n", MAC2STRDBG(mac->octet)));
ret = wldev_iovar_getbuf_bsscfg(dev, "p2p_if", mac, sizeof(*mac), getbuf,
sizeof(getbuf), wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_PRIMARY), NULL);
if (ret == 0) {
memcpy(index, getbuf, sizeof(s32));
CFGP2P_INFO(("---wl p2p_if ==> %d\n", *index));
}
return ret;
}
static s32
wl_cfgp2p_set_discovery(struct wl_priv *wl, s32 on)
{
s32 ret = BCME_OK;
struct net_device *ndev = wl_to_prmry_ndev(wl);
CFGP2P_DBG(("enter\n"));
ret = wldev_iovar_setint(ndev, "p2p_disc", on);
if (unlikely(ret < 0)) {
CFGP2P_ERR(("p2p_disc %d error %d\n", on, ret));
}
return ret;
}
/* Set the WL driver's P2P mode.
* Parameters :
* @mode : is one of WL_P2P_DISC_ST_{SCAN,LISTEN,SEARCH}.
* @channel : the channel to listen
* @listen_ms : the time (milli seconds) to wait
* @bssidx : bss index for BSSCFG
* Returns 0 if success
*/
s32
wl_cfgp2p_set_p2p_mode(struct wl_priv *wl, u8 mode, u32 channel, u16 listen_ms, int bssidx)
{
wl_p2p_disc_st_t discovery_mode;
s32 ret;
struct net_device *dev;
CFGP2P_DBG(("enter\n"));
if (unlikely(bssidx == WL_INVALID)) {
CFGP2P_ERR((" %d index out of range\n", bssidx));
return -1;
}
dev = wl_cfgp2p_find_ndev(wl, bssidx);
if (unlikely(dev == NULL)) {
CFGP2P_ERR(("bssidx %d is not assigned\n", bssidx));
return BCME_NOTFOUND;
}
/* Put the WL driver into P2P Listen Mode to respond to P2P probe reqs */
discovery_mode.state = mode;
discovery_mode.chspec = wl_ch_host_to_driver(channel);
discovery_mode.dwell = listen_ms;
ret = wldev_iovar_setbuf_bsscfg(dev, "p2p_state", &discovery_mode,
sizeof(discovery_mode), wl->ioctl_buf, WLC_IOCTL_MAXLEN,
bssidx, &wl->ioctl_buf_sync);
return ret;
}
/* Get the index of the P2P Discovery BSS */
static s32
wl_cfgp2p_get_disc_idx(struct wl_priv *wl, s32 *index)
{
s32 ret;
struct net_device *dev = wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_PRIMARY);
ret = wldev_iovar_getint(dev, "p2p_dev", index);
CFGP2P_INFO(("p2p_dev bsscfg_idx=%d ret=%d\n", *index, ret));
if (unlikely(ret < 0)) {
CFGP2P_ERR(("'p2p_dev' error %d\n", ret));
return ret;
}
return ret;
}
s32
wl_cfgp2p_init_discovery(struct wl_priv *wl)
{
s32 index = 0;
s32 ret = BCME_OK;
CFGP2P_DBG(("enter\n"));
if (wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) != 0) {
CFGP2P_ERR(("do nothing, already initialized\n"));
return ret;
}
ret = wl_cfgp2p_set_discovery(wl, 1);
if (ret < 0) {
CFGP2P_ERR(("set discover error\n"));
return ret;
}
/* Enable P2P Discovery in the WL Driver */
ret = wl_cfgp2p_get_disc_idx(wl, &index);
if (ret < 0) {
return ret;
}
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_DEVICE) =
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_PRIMARY);
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) = index;
/* Set the initial discovery state to SCAN */
ret = wl_cfgp2p_set_p2p_mode(wl, WL_P2P_DISC_ST_SCAN, 0, 0,
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE));
if (unlikely(ret != 0)) {
CFGP2P_ERR(("unable to set WL_P2P_DISC_ST_SCAN\n"));
wl_cfgp2p_set_discovery(wl, 0);
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) = 0;
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_DEVICE) = NULL;
return 0;
}
return ret;
}
/* Deinitialize P2P Discovery
* Parameters :
* @wl : wl_private data
* Returns 0 if succes
*/
static s32
wl_cfgp2p_deinit_discovery(struct wl_priv *wl)
{
s32 ret = BCME_OK;
CFGP2P_DBG(("enter\n"));
if (wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) == 0) {
CFGP2P_ERR(("do nothing, not initialized\n"));
return -1;
}
/* Set the discovery state to SCAN */
ret = wl_cfgp2p_set_p2p_mode(wl, WL_P2P_DISC_ST_SCAN, 0, 0,
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE));
/* Disable P2P discovery in the WL driver (deletes the discovery BSSCFG) */
ret = wl_cfgp2p_set_discovery(wl, 0);
/* Clear our saved WPS and P2P IEs for the discovery BSS. The driver
* deleted these IEs when wl_cfgp2p_set_discovery() deleted the discovery
* BSS.
*/
/* Clear the saved bsscfg index of the discovery BSSCFG to indicate we
* have no discovery BSS.
*/
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) = WL_INVALID;
wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_DEVICE) = NULL;
return ret;
}
/* Enable P2P Discovery
* Parameters:
* @wl : wl_private data
* @ie : probe request ie (WPS IE + P2P IE)
* @ie_len : probe request ie length
* Returns 0 if success.
*/
s32
wl_cfgp2p_enable_discovery(struct wl_priv *wl, struct net_device *dev,
const u8 *ie, u32 ie_len)
{
s32 ret = BCME_OK;
s32 bssidx;
if (wl_to_prmry_ndev(wl) == dev) {
bssidx = wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE);
} else if (wl_cfgp2p_find_idx(wl, dev, &bssidx) != BCME_OK) {
WL_ERR(("Find p2p index from dev(%p) failed\n", dev));
return BCME_ERROR;
}
if (wl_get_p2p_status(wl, DISCOVERY_ON)) {
CFGP2P_INFO((" DISCOVERY is already initialized, we have nothing to do\n"));
goto set_ie;
}
wl_set_p2p_status(wl, DISCOVERY_ON);
CFGP2P_DBG(("enter\n"));
ret = wl_cfgp2p_init_discovery(wl);
if (unlikely(ret < 0)) {
CFGP2P_ERR((" init discovery error %d\n", ret));
goto exit;
}
/* Set wsec to any non-zero value in the discovery bsscfg to ensure our
* P2P probe responses have the privacy bit set in the 802.11 WPA IE.
* Some peer devices may not initiate WPS with us if this bit is not set.
*/
ret = wldev_iovar_setint_bsscfg(wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_DEVICE),
"wsec", AES_ENABLED, wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE));
if (unlikely(ret < 0)) {
CFGP2P_ERR((" wsec error %d\n", ret));
}
set_ie:
if (ie_len) {
ret = wl_cfgp2p_set_management_ie(wl, dev,
bssidx,
VNDR_IE_PRBREQ_FLAG, ie, ie_len);
if (unlikely(ret < 0)) {
CFGP2P_ERR(("set probreq ie occurs error %d\n", ret));
goto exit;
}
}
exit:
return ret;
}
/* Disable P2P Discovery
* Parameters:
* @wl : wl_private_data
* Returns 0 if success.
*/
s32
wl_cfgp2p_disable_discovery(struct wl_priv *wl)
{
s32 ret = BCME_OK;
CFGP2P_DBG((" enter\n"));
wl_clr_p2p_status(wl, DISCOVERY_ON);
if (wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE) == 0) {
CFGP2P_ERR((" do nothing, not initialized\n"));
goto exit;
}
ret = wl_cfgp2p_set_p2p_mode(wl, WL_P2P_DISC_ST_SCAN, 0, 0,
wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE));
if (unlikely(ret < 0)) {
CFGP2P_ERR(("unable to set WL_P2P_DISC_ST_SCAN\n"));
}
/* Do a scan abort to stop the driver's scan engine in case it is still
* waiting out an action frame tx dwell time.
*/
wl_clr_p2p_status(wl, DISCOVERY_ON);
ret = wl_cfgp2p_deinit_discovery(wl);
exit:
return ret;
}
s32
wl_cfgp2p_escan(struct wl_priv *wl, struct net_device *dev, u16 active,
u32 num_chans, u16 *channels,
s32 search_state, u16 action, u32 bssidx, struct ether_addr *tx_dst_addr)
{
s32 ret = BCME_OK;
s32 memsize;
s32 eparams_size;
u32 i;
s8 *memblk;
wl_p2p_scan_t *p2p_params;
wl_escan_params_t *eparams;
wlc_ssid_t ssid;
/* Scan parameters */
#define P2PAPI_SCAN_NPROBES 1
#define P2PAPI_SCAN_DWELL_TIME_MS 80
#define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
#define P2PAPI_SCAN_HOME_TIME_MS 60
#define P2PAPI_SCAN_NPROBS_TIME_MS 30
#define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
struct net_device *pri_dev = wl_to_p2p_bss_ndev(wl, P2PAPI_BSSCFG_PRIMARY);
/* Allocate scan params which need space for 3 channels and 0 ssids */
eparams_size = (WL_SCAN_PARAMS_FIXED_SIZE +
OFFSETOF(wl_escan_params_t, params)) +
num_chans * sizeof(eparams->params.channel_list[0]);
memsize = sizeof(wl_p2p_scan_t) + eparams_size;
memblk = scanparambuf;
if (memsize > sizeof(scanparambuf)) {
CFGP2P_ERR((" scanpar buf too small (%u > %zu)\n",
memsize, sizeof(scanparambuf)));
return -1;
}
memset(memblk, 0, memsize);
memset(wl->ioctl_buf, 0, WLC_IOCTL_MAXLEN);
if (search_state == WL_P2P_DISC_ST_SEARCH) {
/*
* If we in SEARCH STATE, we don't need to set SSID explictly
* because dongle use P2P WILDCARD internally by default
*/
wl_cfgp2p_set_p2p_mode(wl, WL_P2P_DISC_ST_SEARCH, 0, 0, bssidx);
/* use null ssid */
ssid.SSID_len = 0;
memset(&ssid.SSID, 0, sizeof(ssid.SSID));
} else if (search_state == WL_P2P_DISC_ST_SCAN) {
/* SCAN STATE 802.11 SCAN
* WFD Supplicant has p2p_find command with (type=progressive, type= full)
* So if P2P_find command with type=progressive,
* we have to set ssid to P2P WILDCARD because
* we just do broadcast scan unless setting SSID
*/
wl_cfgp2p_set_p2p_mode(wl, WL_P2P_DISC_ST_SCAN, 0, 0, bssidx);
/* use wild card ssid */
ssid.SSID_len = WL_P2P_WILDCARD_SSID_LEN;
memset(&ssid.SSID, 0, sizeof(ssid.SSID));
memcpy(&ssid.SSID, WL_P2P_WILDCARD_SSID, WL_P2P_WILDCARD_SSID_LEN);
} else {
CFGP2P_ERR((" invalid search state %d\n", search_state));
return -1;
}
/* Fill in the P2P scan structure at the start of the iovar param block */
p2p_params = (wl_p2p_scan_t*) memblk;
p2p_params->type = 'E';
/* Fill in the Scan structure that follows the P2P scan structure */
eparams = (wl_escan_params_t*) (p2p_params + 1);
eparams->params.bss_type = DOT11_BSSTYPE_ANY;
if (active)
eparams->params.scan_type = DOT11_SCANTYPE_ACTIVE;
else
eparams->params.scan_type = DOT11_SCANTYPE_PASSIVE;
if (tx_dst_addr == NULL)
memcpy(&eparams->params.bssid, ðer_bcast, ETHER_ADDR_LEN);
else
memcpy(&eparams->params.bssid, tx_dst_addr, ETHER_ADDR_LEN);
if (ssid.SSID_len)
memcpy(&eparams->params.ssid, &ssid, sizeof(wlc_ssid_t));
eparams->params.home_time = htod32(P2PAPI_SCAN_HOME_TIME_MS);
/* SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan supported by
* the supplicant
*/
if ((num_chans == SOCIAL_CHAN_CNT) || (num_chans == SOCIAL_CHAN_CNT + 1))
eparams->params.active_time = htod32(P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS);
else if (num_chans == AF_PEER_SEARCH_CNT)
eparams->params.active_time = htod32(P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS);
else if (wl_get_drv_status_all(wl, CONNECTED))
eparams->params.active_time = -1;
else
eparams->params.active_time = htod32(P2PAPI_SCAN_DWELL_TIME_MS);
eparams->params.nprobes = htod32((eparams->params.active_time /
P2PAPI_SCAN_NPROBS_TIME_MS));
/* Override scan params to find a peer for a connection */
if (num_chans == 1) {
eparams->params.active_time = htod32(WL_SCAN_CONNECT_DWELL_TIME_MS);
eparams->params.nprobes = htod32(eparams->params.active_time /
WL_SCAN_JOIN_PROBE_INTERVAL_MS);
}
if (eparams->params.nprobes <= 0)
eparams->params.nprobes = 1;
CFGP2P_DBG(("nprobes # %d, active_time %d\n",
eparams->params.nprobes, eparams->params.active_time));
eparams->params.passive_time = htod32(-1);
eparams->params.channel_num = htod32((0 << WL_SCAN_PARAMS_NSSID_SHIFT) |
(num_chans & WL_SCAN_PARAMS_COUNT_MASK));
for (i = 0; i < num_chans; i++) {
eparams->params.channel_list[i] = wl_ch_host_to_driver(channels[i]);
}
eparams->version = htod32(ESCAN_REQ_VERSION);
eparams->action = htod16(action);
wl_escan_set_sync_id(eparams->sync_id, wl);
CFGP2P_INFO(("SCAN CHANNELS : "));
for (i = 0; i < num_chans; i++) {
if (i == 0) CFGP2P_INFO(("%d", channels[i]));
else CFGP2P_INFO((",%d", channels[i]));
}
CFGP2P_INFO(("\n"));
ret = wldev_iovar_setbuf_bsscfg(pri_dev, "p2p_scan",
memblk, memsize, wl->ioctl_buf, WLC_IOCTL_MAXLEN, bssidx, &wl->ioctl_buf_sync);
if (ret == BCME_OK)
wl_set_p2p_status(wl, SCANNING);
return ret;
}
/* search function to reach at common channel to send action frame
* Parameters:
* @wl : wl_private data
* @ndev : net device for bssidx
* @bssidx : bssidx for BSS
* Returns 0 if success.
*/
s32
wl_cfgp2p_act_frm_search(struct wl_priv *wl, struct net_device *ndev,
s32 bssidx, s32 channel, struct ether_addr *tx_dst_addr)
{
s32 ret = 0;
u32 chan_cnt = 0;
u16 *default_chan_list = NULL;
if (!p2p_is_on(wl) || ndev == NULL || bssidx == WL_INVALID)
return -BCME_ERROR;
CFGP2P_ERR((" Enter\n"));
if (bssidx == wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_PRIMARY))
bssidx = wl_to_p2p_bss_bssidx(wl, P2PAPI_BSSCFG_DEVICE);
if (channel)
chan_cnt = AF_PEER_SEARCH_CNT;
else
chan_cnt = SOCIAL_CHAN_CNT;
default_chan_list = kzalloc(chan_cnt * sizeof(*default_chan_list), GFP_KERNEL);
if (default_chan_list == NULL) {
CFGP2P_ERR(("channel list allocation failed \n"));
ret = -ENOMEM;
goto exit;
}
if (channel) {
u32 i;
/* insert same channel to the chan_list */
for (i = 0; i < chan_cnt; i++) {
default_chan_list[i] = channel;
}
} else {
default_chan_list[0] = SOCIAL_CHAN_1;
default_chan_list[1] = SOCIAL_CHAN_2;
default_chan_list[2] = SOCIAL_CHAN_3;
}
ret = wl_cfgp2p_escan(wl, ndev, true, chan_cnt,
default_chan_list, WL_P2P_DISC_ST_SEARCH,
WL_SCAN_ACTION_START, bssidx, tx_dst_addr);
kfree(default_chan_list);
exit:
return ret;
}
/* Check whether pointed-to IE looks like WPA. */
#define wl_cfgp2p_is_wpa_ie(ie, tlvs, len) wl_cfgp2p_has_ie(ie, tlvs, len, \
(const uint8 *)WPS_OUI, WPS_OUI_LEN, WPA_OUI_TYPE)
/* Check whether pointed-to IE looks like WPS. */
#define wl_cfgp2p_is_wps_ie(ie, tlvs, len) wl_cfgp2p_has_ie(ie, tlvs, len, \
(const uint8 *)WPS_OUI, WPS_OUI_LEN, WPS_OUI_TYPE)
/* Check whether the given IE looks like WFA P2P IE. */
#define wl_cfgp2p_is_p2p_ie(ie, tlvs, len) wl_cfgp2p_has_ie(ie, tlvs, len, \
(const uint8 *)WFA_OUI, WFA_OUI_LEN, WFA_OUI_TYPE_P2P)
/* Check whether the given IE looks like WFA WFDisplay IE. */
#ifndef WFA_OUI_TYPE_WFD
#define WFA_OUI_TYPE_WFD 0x0a /* WiFi Display OUI TYPE */
#endif
#define wl_cfgp2p_is_wfd_ie(ie, tlvs, len) wl_cfgp2p_has_ie(ie, tlvs, len, \
(const uint8 *)WFA_OUI, WFA_OUI_LEN, WFA_OUI_TYPE_WFD)
static s32
wl_cfgp2p_parse_vndr_ies(u8 *parse, u32 len,
struct parsed_vndr_ies *vndr_ies)
{
s32 err = BCME_OK;
vndr_ie_t *vndrie;
bcm_tlv_t *ie;
struct parsed_vndr_ie_info *parsed_info;
u32 count = 0;
s32 remained_len;
remained_len = (s32)len;
memset(vndr_ies, 0, sizeof(*vndr_ies));
WL_INFO(("---> len %d\n", len));
ie = (bcm_tlv_t *) parse;
if (!bcm_valid_tlv(ie, remained_len))
ie = NULL;
while (ie) {
if (count >= MAX_VNDR_IE_NUMBER)
break;
if (ie->id == DOT11_MNG_VS_ID) {
vndrie = (vndr_ie_t *) ie;
/* len should be bigger than OUI length + one data length at least */
if (vndrie->len < (VNDR_IE_MIN_LEN + 1)) {