-
Notifications
You must be signed in to change notification settings - Fork 962
/
rtw_p2p.c
executable file
·5395 lines (4441 loc) · 151 KB
/
rtw_p2p.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
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _RTW_P2P_C_
#include <drv_types.h>
#ifdef CONFIG_P2P
int rtw_p2p_is_channel_list_ok( u8 desired_ch, u8* ch_list, u8 ch_cnt )
{
int found = 0, i = 0;
for( i = 0; i < ch_cnt; i++ )
{
if ( ch_list[ i ] == desired_ch )
{
found = 1;
break;
}
}
return( found );
}
int is_any_client_associated(_adapter *padapter)
{
return padapter->stapriv.asoc_list_cnt ? _TRUE : _FALSE;
}
static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
{
_irqL irqL;
_list *phead, *plist;
u32 len=0;
u16 attr_len = 0;
u8 tmplen, *pdata_attr, *pstart, *pcur;
struct sta_info *psta = NULL;
_adapter *padapter = pwdinfo->padapter;
struct sta_priv *pstapriv = &padapter->stapriv;
DBG_871X("%s\n", __FUNCTION__);
pdata_attr = rtw_zmalloc(MAX_P2P_IE_LEN);
if(NULL == pdata_attr){
DBG_871X("%s pdata_attr malloc failed \n", __FUNCTION__);
goto _exit;
}
pstart = pdata_attr;
pcur = pdata_attr;
_enter_critical_bh(&pstapriv->asoc_list_lock, &irqL);
phead = &pstapriv->asoc_list;
plist = get_next(phead);
//look up sta asoc_queue
while ((rtw_end_of_queue_search(phead, plist)) == _FALSE)
{
psta = LIST_CONTAINOR(plist, struct sta_info, asoc_list);
plist = get_next(plist);
if(psta->is_p2p_device)
{
tmplen = 0;
pcur++;
//P2P device address
_rtw_memcpy(pcur, psta->dev_addr, ETH_ALEN);
pcur += ETH_ALEN;
//P2P interface address
_rtw_memcpy(pcur, psta->hwaddr, ETH_ALEN);
pcur += ETH_ALEN;
*pcur = psta->dev_cap;
pcur++;
//*(u16*)(pcur) = cpu_to_be16(psta->config_methods);
RTW_PUT_BE16(pcur, psta->config_methods);
pcur += 2;
_rtw_memcpy(pcur, psta->primary_dev_type, 8);
pcur += 8;
*pcur = psta->num_of_secdev_type;
pcur++;
_rtw_memcpy(pcur, psta->secdev_types_list, psta->num_of_secdev_type*8);
pcur += psta->num_of_secdev_type*8;
if(psta->dev_name_len>0)
{
//*(u16*)(pcur) = cpu_to_be16( WPS_ATTR_DEVICE_NAME );
RTW_PUT_BE16(pcur, WPS_ATTR_DEVICE_NAME);
pcur += 2;
//*(u16*)(pcur) = cpu_to_be16( psta->dev_name_len );
RTW_PUT_BE16(pcur, psta->dev_name_len);
pcur += 2;
_rtw_memcpy(pcur, psta->dev_name, psta->dev_name_len);
pcur += psta->dev_name_len;
}
tmplen = (u8)(pcur-pstart);
*pstart = (tmplen-1);
attr_len += tmplen;
//pstart += tmplen;
pstart = pcur;
}
}
_exit_critical_bh(&pstapriv->asoc_list_lock, &irqL);
if(attr_len>0)
{
len = rtw_set_p2p_attr_content(pbuf, P2P_ATTR_GROUP_INFO, attr_len, pdata_attr);
}
rtw_mfree(pdata_attr, MAX_P2P_IE_LEN);
_exit:
return len;
}
static void issue_group_disc_req(struct wifidirect_info *pwdinfo, u8 *da)
{
struct xmit_frame *pmgntframe;
struct pkt_attrib *pattrib;
unsigned char *pframe;
struct rtw_ieee80211_hdr *pwlanhdr;
unsigned short *fctrl;
_adapter *padapter = pwdinfo->padapter;
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
unsigned char category = RTW_WLAN_CATEGORY_P2P;//P2P action frame
u32 p2poui = cpu_to_be32(P2POUI);
u8 oui_subtype = P2P_GO_DISC_REQUEST;
u8 dialogToken=0;
DBG_871X("[%s]\n", __FUNCTION__);
if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
{
return;
}
//update attribute
pattrib = &pmgntframe->attrib;
update_mgntframe_attrib(padapter, pattrib);
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
fctrl = &(pwlanhdr->frame_ctl);
*(fctrl) = 0;
_rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr2, pwdinfo->interface_addr, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr3, pwdinfo->interface_addr, ETH_ALEN);
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
pmlmeext->mgnt_seq++;
SetFrameSubType(pframe, WIFI_ACTION);
pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
//Build P2P action frame header
pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
//there is no IE in this P2P action frame
pattrib->last_txcmdsz = pattrib->pktlen;
dump_mgntframe(padapter, pmgntframe);
}
static void issue_p2p_devdisc_resp(struct wifidirect_info *pwdinfo, u8 *da, u8 status, u8 dialogToken)
{
struct xmit_frame *pmgntframe;
struct pkt_attrib *pattrib;
unsigned char *pframe;
struct rtw_ieee80211_hdr *pwlanhdr;
unsigned short *fctrl;
_adapter *padapter = pwdinfo->padapter;
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
u8 action = P2P_PUB_ACTION_ACTION;
u32 p2poui = cpu_to_be32(P2POUI);
u8 oui_subtype = P2P_DEVDISC_RESP;
u8 p2pie[8] = { 0x00 };
u32 p2pielen = 0;
DBG_871X("[%s]\n", __FUNCTION__);
if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
{
return;
}
//update attribute
pattrib = &pmgntframe->attrib;
update_mgntframe_attrib(padapter, pattrib);
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
fctrl = &(pwlanhdr->frame_ctl);
*(fctrl) = 0;
_rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr2, pwdinfo->device_addr, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr3, pwdinfo->device_addr, ETH_ALEN);
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
pmlmeext->mgnt_seq++;
SetFrameSubType(pframe, WIFI_ACTION);
pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
//Build P2P public action frame header
pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
//Build P2P IE
// P2P OUI
p2pielen = 0;
p2pie[ p2pielen++ ] = 0x50;
p2pie[ p2pielen++ ] = 0x6F;
p2pie[ p2pielen++ ] = 0x9A;
p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
// P2P_ATTR_STATUS
p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_STATUS, 1, &status);
pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, p2pie, &pattrib->pktlen);
pattrib->last_txcmdsz = pattrib->pktlen;
dump_mgntframe(padapter, pmgntframe);
}
static void issue_p2p_provision_resp(struct wifidirect_info *pwdinfo, u8* raddr, u8* frame_body, u16 config_method)
{
_adapter *padapter = pwdinfo->padapter;
unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
u8 action = P2P_PUB_ACTION_ACTION;
u8 dialogToken = frame_body[7]; // The Dialog Token of provisioning discovery request frame.
u32 p2poui = cpu_to_be32(P2POUI);
u8 oui_subtype = P2P_PROVISION_DISC_RESP;
u8 wpsie[ 100 ] = { 0x00 };
u8 wpsielen = 0;
#ifdef CONFIG_WFD
u32 wfdielen = 0;
#endif //CONFIG_WFD
struct xmit_frame *pmgntframe;
struct pkt_attrib *pattrib;
unsigned char *pframe;
struct rtw_ieee80211_hdr *pwlanhdr;
unsigned short *fctrl;
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
{
return;
}
//update attribute
pattrib = &pmgntframe->attrib;
update_mgntframe_attrib(padapter, pattrib);
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
fctrl = &(pwlanhdr->frame_ctl);
*(fctrl) = 0;
_rtw_memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr3, adapter_mac_addr(padapter), ETH_ALEN);
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
pmlmeext->mgnt_seq++;
SetFrameSubType(pframe, WIFI_ACTION);
pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
wpsielen = 0;
// WPS OUI
//*(u32*) ( wpsie ) = cpu_to_be32( WPSOUI );
RTW_PUT_BE32(wpsie, WPSOUI);
wpsielen += 4;
#if 0
// WPS version
// Type:
*(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_VER1 );
wpsielen += 2;
// Length:
*(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0001 );
wpsielen += 2;
// Value:
wpsie[wpsielen++] = WPS_VERSION_1; // Version 1.0
#endif
// Config Method
// Type:
//*(u16*) ( wpsie + wpsielen ) = cpu_to_be16( WPS_ATTR_CONF_METHOD );
RTW_PUT_BE16(wpsie + wpsielen, WPS_ATTR_CONF_METHOD);
wpsielen += 2;
// Length:
//*(u16*) ( wpsie + wpsielen ) = cpu_to_be16( 0x0002 );
RTW_PUT_BE16(wpsie + wpsielen, 0x0002);
wpsielen += 2;
// Value:
//*(u16*) ( wpsie + wpsielen ) = cpu_to_be16( config_method );
RTW_PUT_BE16(wpsie + wpsielen, config_method);
wpsielen += 2;
pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *) wpsie, &pattrib->pktlen );
#ifdef CONFIG_WFD
wfdielen = build_provdisc_resp_wfd_ie(pwdinfo, pframe);
pframe += wfdielen;
pattrib->pktlen += wfdielen;
#endif //CONFIG_WFD
pattrib->last_txcmdsz = pattrib->pktlen;
dump_mgntframe(padapter, pmgntframe);
return;
}
static void issue_p2p_presence_resp(struct wifidirect_info *pwdinfo, u8 *da, u8 status, u8 dialogToken)
{
struct xmit_frame *pmgntframe;
struct pkt_attrib *pattrib;
unsigned char *pframe;
struct rtw_ieee80211_hdr *pwlanhdr;
unsigned short *fctrl;
_adapter *padapter = pwdinfo->padapter;
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
unsigned char category = RTW_WLAN_CATEGORY_P2P;//P2P action frame
u32 p2poui = cpu_to_be32(P2POUI);
u8 oui_subtype = P2P_PRESENCE_RESPONSE;
u8 p2pie[ MAX_P2P_IE_LEN] = { 0x00 };
u8 noa_attr_content[32] = { 0x00 };
u32 p2pielen = 0;
DBG_871X("[%s]\n", __FUNCTION__);
if ((pmgntframe = alloc_mgtxmitframe(pxmitpriv)) == NULL)
{
return;
}
//update attribute
pattrib = &pmgntframe->attrib;
update_mgntframe_attrib(padapter, pattrib);
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
fctrl = &(pwlanhdr->frame_ctl);
*(fctrl) = 0;
_rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr2, pwdinfo->interface_addr, ETH_ALEN);
_rtw_memcpy(pwlanhdr->addr3, pwdinfo->interface_addr, ETH_ALEN);
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
pmlmeext->mgnt_seq++;
SetFrameSubType(pframe, WIFI_ACTION);
pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
//Build P2P action frame header
pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *) &(p2poui), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
//Add P2P IE header
// P2P OUI
p2pielen = 0;
p2pie[ p2pielen++ ] = 0x50;
p2pie[ p2pielen++ ] = 0x6F;
p2pie[ p2pielen++ ] = 0x9A;
p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
//Add Status attribute in P2P IE
p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_STATUS, 1, &status);
//Add NoA attribute in P2P IE
noa_attr_content[0] = 0x1;//index
noa_attr_content[1] = 0x0;//CTWindow and OppPS Parameters
//todo: Notice of Absence Descriptor(s)
p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_NOA, 2, noa_attr_content);
pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, p2pie, &(pattrib->pktlen));
pattrib->last_txcmdsz = pattrib->pktlen;
dump_mgntframe(padapter, pmgntframe);
}
u32 build_beacon_p2p_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
{
u8 p2pie[ MAX_P2P_IE_LEN] = { 0x00 };
u16 capability=0;
u32 len=0, p2pielen = 0;
// P2P OUI
p2pielen = 0;
p2pie[ p2pielen++ ] = 0x50;
p2pie[ p2pielen++ ] = 0x6F;
p2pie[ p2pielen++ ] = 0x9A;
p2pie[ p2pielen++ ] = 0x09; // WFA P2P v1.0
// According to the P2P Specification, the beacon frame should contain 3 P2P attributes
// 1. P2P Capability
// 2. P2P Device ID
// 3. Notice of Absence ( NOA )
// P2P Capability ATTR
// Type:
// Length:
// Value:
// Device Capability Bitmap, 1 byte
// Be able to participate in additional P2P Groups and
// support the P2P Invitation Procedure
// Group Capability Bitmap, 1 byte
capability = P2P_DEVCAP_INVITATION_PROC|P2P_DEVCAP_CLIENT_DISCOVERABILITY;
capability |= ((P2P_GRPCAP_GO | P2P_GRPCAP_INTRABSS) << 8);
if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_PROVISIONING_ING))
capability |= (P2P_GRPCAP_GROUP_FORMATION<<8);
capability = cpu_to_le16(capability);
p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_CAPABILITY, 2, (u8*)&capability);
// P2P Device ID ATTR
p2pielen += rtw_set_p2p_attr_content(&p2pie[p2pielen], P2P_ATTR_DEVICE_ID, ETH_ALEN, pwdinfo->device_addr);
// Notice of Absence ATTR
// Type:
// Length:
// Value:
//go_add_noa_attr(pwdinfo);
pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *) p2pie, &len);
return len;
}
#ifdef CONFIG_WFD
u32 build_beacon_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
{
u8 wfdie[ MAX_WFD_IE_LEN] = { 0x00 };
u16 val16=0;
u32 len=0, wfdielen = 0;
_adapter *padapter = pwdinfo->padapter;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct wifi_display_info* pwfd_info = padapter->wdinfo.wfd_info;
// WFD OUI
wfdielen = 0;
wfdie[ wfdielen++ ] = 0x50;
wfdie[ wfdielen++ ] = 0x6F;
wfdie[ wfdielen++ ] = 0x9A;
wfdie[ wfdielen++ ] = 0x0A; // WFA WFD v1.0
// Commented by Albert 20110812
// According to the WFD Specification, the beacon frame should contain 4 WFD attributes
// 1. WFD Device Information
// 2. Associated BSSID
// 3. Coupled Sink Information
// WFD Device Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_DEVICE_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
wfdielen += 2;
// Value1:
// WFD device information
if ( P2P_ROLE_GO == pwdinfo->role )
{
if ( is_any_client_associated( pwdinfo->padapter ) )
{
// WFD primary sink + WiFi Direct mode + WSD (WFD Service Discovery)
val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_WSD;
RTW_PUT_BE16(wfdie + wfdielen, val16);
}
else
{
// WFD primary sink + available for WFD session + WiFi Direct mode + WSD (WFD Service Discovery)
val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
RTW_PUT_BE16(wfdie + wfdielen, val16);
}
}
else
{
// WFD primary sink + available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery )
val16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD;
RTW_PUT_BE16(wfdie + wfdielen, val16);
}
wfdielen += 2;
// Value2:
// Session Management Control Port
// Default TCP port for RTSP messages is 554
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport );
wfdielen += 2;
// Value3:
// WFD Device Maximum Throughput
// 300Mbps is the maximum throughput
RTW_PUT_BE16(wfdie + wfdielen, 300);
wfdielen += 2;
// Associated BSSID ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_ASSOC_BSSID;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
wfdielen += 2;
// Value:
// Associated BSSID
if ( check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE )
{
_rtw_memcpy( wfdie + wfdielen, &pmlmepriv->assoc_bssid[ 0 ], ETH_ALEN );
}
else
{
_rtw_memset( wfdie + wfdielen, 0x00, ETH_ALEN );
}
wfdielen += ETH_ALEN;
// Coupled Sink Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_COUPLED_SINK_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
wfdielen += 2;
// Value:
// Coupled Sink Status bitmap
// Not coupled/available for Coupling
wfdie[ wfdielen++ ] = 0;
// MAC Addr.
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
return len;
}
u32 build_probe_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
{
u8 wfdie[ MAX_WFD_IE_LEN] = { 0x00 };
u16 val16=0;
u32 len=0, wfdielen = 0;
_adapter *padapter = pwdinfo->padapter;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct wifi_display_info* pwfd_info = padapter->wdinfo.wfd_info;
// WFD OUI
wfdielen = 0;
wfdie[ wfdielen++ ] = 0x50;
wfdie[ wfdielen++ ] = 0x6F;
wfdie[ wfdielen++ ] = 0x9A;
wfdie[ wfdielen++ ] = 0x0A; // WFA WFD v1.0
// Commented by Albert 20110812
// According to the WFD Specification, the probe request frame should contain 4 WFD attributes
// 1. WFD Device Information
// 2. Associated BSSID
// 3. Coupled Sink Information
// WFD Device Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_DEVICE_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
wfdielen += 2;
// Value1:
// WFD device information
if ( 1 == pwdinfo->wfd_tdls_enable )
{
// WFD primary sink + available for WFD session + WiFi TDLS mode + WSC ( WFD Service Discovery )
val16 = pwfd_info->wfd_device_type |
WFD_DEVINFO_SESSION_AVAIL |
WFD_DEVINFO_WSD |
WFD_DEVINFO_PC_TDLS;
RTW_PUT_BE16(wfdie + wfdielen, val16 );
}
else
{
// WFD primary sink + available for WFD session + WiFi Direct mode + WSC ( WFD Service Discovery )
val16 = pwfd_info->wfd_device_type |
WFD_DEVINFO_SESSION_AVAIL |
WFD_DEVINFO_WSD;
RTW_PUT_BE16(wfdie + wfdielen, val16 );
}
wfdielen += 2;
// Value2:
// Session Management Control Port
// Default TCP port for RTSP messages is 554
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport );
wfdielen += 2;
// Value3:
// WFD Device Maximum Throughput
// 300Mbps is the maximum throughput
RTW_PUT_BE16(wfdie + wfdielen, 300);
wfdielen += 2;
// Associated BSSID ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_ASSOC_BSSID;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
wfdielen += 2;
// Value:
// Associated BSSID
if ( check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE )
{
_rtw_memcpy( wfdie + wfdielen, &pmlmepriv->assoc_bssid[ 0 ], ETH_ALEN );
}
else
{
_rtw_memset( wfdie + wfdielen, 0x00, ETH_ALEN );
}
wfdielen += ETH_ALEN;
// Coupled Sink Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_COUPLED_SINK_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
wfdielen += 2;
// Value:
// Coupled Sink Status bitmap
// Not coupled/available for Coupling
wfdie[ wfdielen++ ] = 0;
// MAC Addr.
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
return len;
}
u32 build_probe_resp_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf, u8 tunneled)
{
u8 wfdie[ MAX_WFD_IE_LEN] = { 0x00 };
u32 len=0, wfdielen = 0;
_adapter *padapter = pwdinfo->padapter;
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct wifi_display_info* pwfd_info = padapter->wdinfo.wfd_info;
// WFD OUI
wfdielen = 0;
wfdie[ wfdielen++ ] = 0x50;
wfdie[ wfdielen++ ] = 0x6F;
wfdie[ wfdielen++ ] = 0x9A;
wfdie[ wfdielen++ ] = 0x0A; // WFA WFD v1.0
// Commented by Albert 20110812
// According to the WFD Specification, the probe response frame should contain 4 WFD attributes
// 1. WFD Device Information
// 2. Associated BSSID
// 3. Coupled Sink Information
// 4. WFD Session Information
// WFD Device Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_DEVICE_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
wfdielen += 2;
// Value1:
// WFD device information
// WFD primary sink + available for WFD session + WiFi Direct mode
if ( _TRUE == pwdinfo->session_available )
{
if ( P2P_ROLE_GO == pwdinfo->role )
{
if ( is_any_client_associated( pwdinfo->padapter ) )
{
if ( pwdinfo->wfd_tdls_enable )
{
// TDLS mode + WSD ( WFD Service Discovery )
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT);
}
else
{
// WiFi Direct mode + WSD ( WFD Service Discovery )
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT);
}
}
else
{
if ( pwdinfo->wfd_tdls_enable )
{
// available for WFD session + TDLS mode + WSD ( WFD Service Discovery )
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT);
}
else
{
// available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery )
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT);
}
}
}
else
{
if ( pwdinfo->wfd_tdls_enable )
{
// available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery )
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT);
}
else
{
// available for WFD session + WiFi Direct mode + WSD ( WFD Service Discovery )
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT);
}
}
}
else
{
if ( pwdinfo->wfd_tdls_enable )
{
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_WSD |WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_HDCP_SUPPORT);
}
else
{
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->wfd_device_type | WFD_DEVINFO_WSD | WFD_DEVINFO_HDCP_SUPPORT);
}
}
wfdielen += 2;
// Value2:
// Session Management Control Port
// Default TCP port for RTSP messages is 554
RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->rtsp_ctrlport );
wfdielen += 2;
// Value3:
// WFD Device Maximum Throughput
// 300Mbps is the maximum throughput
RTW_PUT_BE16(wfdie + wfdielen, 300);
wfdielen += 2;
// Associated BSSID ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_ASSOC_BSSID;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
wfdielen += 2;
// Value:
// Associated BSSID
if ( check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE )
{
_rtw_memcpy( wfdie + wfdielen, &pmlmepriv->assoc_bssid[ 0 ], ETH_ALEN );
}
else
{
_rtw_memset( wfdie + wfdielen, 0x00, ETH_ALEN );
}
wfdielen += ETH_ALEN;
// Coupled Sink Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_COUPLED_SINK_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0007);
wfdielen += 2;
// Value:
// Coupled Sink Status bitmap
// Not coupled/available for Coupling
wfdie[ wfdielen++ ] = 0;
// MAC Addr.
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
wfdie[ wfdielen++ ] = 0;
if(rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
{
// WFD Session Information ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_SESSION_INFO;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, 0x0000);
wfdielen += 2;
// Todo: to add the list of WFD device info descriptor in WFD group.
}
#ifdef CONFIG_CONCURRENT_MODE
#ifdef CONFIG_TDLS
if ( ( tunneled == 0 ) && ( padapter->pbuddy_adapter->wdinfo.wfd_tdls_enable == 1 ) )
{
// Alternative MAC Address ATTR
// Type:
wfdie[ wfdielen++ ] = WFD_ATTR_ALTER_MAC;
// Length:
// Note: In the WFD specification, the size of length field is 2.
RTW_PUT_BE16(wfdie + wfdielen, ETH_ALEN );
wfdielen += 2;
// Value:
// Alternative MAC Address
_rtw_memcpy(wfdie + wfdielen, adapter_mac_addr(padapter->pbuddy_adapter), ETH_ALEN);
// This mac address is used to make the WFD session when TDLS is enable.
wfdielen += ETH_ALEN;
}
#endif // CONFIG_TDLS
#endif // CONFIG_CONCURRENT_MODE
pbuf = rtw_set_ie(pbuf, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, &len);
return len;
}
u32 build_assoc_req_wfd_ie(struct wifidirect_info *pwdinfo, u8 *pbuf)
{
u8 wfdie[ MAX_WFD_IE_LEN] = { 0x00 };
u16 val16=0;
u32 len=0, wfdielen = 0;
_adapter *padapter = NULL;
struct mlme_priv *pmlmepriv = NULL;
struct wifi_display_info *pwfd_info = NULL;
// WFD OUI
if(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
{
return 0;
}
padapter = pwdinfo->padapter;
pmlmepriv = &padapter->mlmepriv;
pwfd_info = padapter->wdinfo.wfd_info;
wfdielen = 0;
wfdie[ wfdielen++ ] = 0x50;
wfdie[ wfdielen++ ] = 0x6F;
wfdie[ wfdielen++ ] = 0x9A;
wfdie[ wfdielen++ ] = 0x0A; // WFA WFD v1.0
// Commented by Albert 20110812
// According to the WFD Specification, the probe request frame should contain 4 WFD attributes
// 1. WFD Device Information
// 2. Associated BSSID
// 3. Coupled Sink Information