forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCW80211InformationElements.c
More file actions
1462 lines (1118 loc) · 40.8 KB
/
CW80211InformationElements.c
File metadata and controls
1462 lines (1118 loc) · 40.8 KB
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
/**************************************
*
* Elena Agostini elena.ago@gmail.com
* 802.11 Information Elements
*
***************************************/
#include "CWWTP.h"
/* +++++++++++++++++++ ASSEMBLE +++++++++++++++++++++ */
/* FIXED LEN IE */
CWBool CW80211AssembleIEFrameControl(char * frame, int * offset, int frameType, int frameSubtype) {
short int val = IEEE80211_FC(frameType, frameSubtype);
CW_COPY_MEMORY(frame, &(val), LEN_IE_FRAME_CONTROL);
(*offset) += LEN_IE_FRAME_CONTROL;
return CW_TRUE;
}
CWBool CW80211AssembleIEFrameControlData(char * frame, int * offset, int frameType, int frameSubtype, int toDS, int fromDS) {
short int val = IEEE80211_FC(frameType, frameSubtype);
if(toDS == 1)
SETBIT(val,8);
else
CLEARBIT(val,8);
if(fromDS == 1)
SETBIT(val,9);
else
CLEARBIT(val,9);
CW_COPY_MEMORY(frame, &(val), LEN_IE_FRAME_CONTROL);
(*offset) += LEN_IE_FRAME_CONTROL;
return CW_TRUE;
}
CWBool CW80211AssembleIEDuration(char * frame, int * offset, int value) {
short int val = htons(host_to_le16(value));
CW_COPY_MEMORY(frame, &(val), LEN_IE_DURATION);
(*offset) += LEN_IE_DURATION;
return CW_TRUE;
}
CWBool CW80211AssembleIESequenceNumber(char * frame, int * offset, int value) {
short int val = htons(host_to_le16(value));
CW_COPY_MEMORY(frame, &(val), LEN_IE_SEQ_CTRL);
(*offset) += LEN_IE_SEQ_CTRL;
return CW_TRUE;
}
CWBool CW80211AssembleIEAddr(char * frame, int * offset, char * value) {
//Broadcast
if(value == NULL)
memset(frame, 0xff, ETH_ALEN);
else
CW_COPY_MEMORY(frame, value, ETH_ALEN);
(*offset) += ETH_ALEN;
return CW_TRUE;
}
CWBool CW80211AssembleIEBeaconInterval(char * frame, int * offset, short int value) {
short int val = htons(host_to_le16(value));
CW_COPY_MEMORY(frame, &(val), LEN_IE_BEACON_INT);
(*offset) += LEN_IE_BEACON_INT;
return CW_TRUE;
}
CWBool CW80211AssembleIECapability(char * frame, int * offset, short int value) {
CW_COPY_MEMORY(frame, &(value), LEN_IE_CAPABILITY);
(*offset) += LEN_IE_CAPABILITY;
return CW_TRUE;
}
CWBool CW80211AssembleIEAuthAlgoNum(char * frame, int * offset, short int value) {
CW_COPY_MEMORY(frame, &(value), LEN_IE_AUTH_ALG);
(*offset) += LEN_IE_AUTH_ALG;
return CW_TRUE;
}
CWBool CW80211AssembleIEAuthTransNum(char * frame, int * offset, short int value) {
CW_COPY_MEMORY(frame, &(value), LEN_IE_AUTH_TRANS);
(*offset) += LEN_IE_AUTH_TRANS;
return CW_TRUE;
}
CWBool CW80211AssembleIEStatusCode(char * frame, int * offset, short int value) {
CW_COPY_MEMORY(frame, &(value), LEN_IE_STATUS_CODE);
(*offset) += LEN_IE_STATUS_CODE;
return CW_TRUE;
}
CWBool CW80211SetAssociationID(short int * assID) {
srand(time(NULL));
(*assID) = rand()%256;
return CW_TRUE;
}
CWBool CW80211AssembleIEAssID(char * frame, int * offset, short int value) {
value |= BIT(14);
value |= BIT(15);
CW_COPY_MEMORY(frame, &(value), LEN_IE_ASSOCIATION_ID);
(*offset) += LEN_IE_ASSOCIATION_ID;
return CW_TRUE;
}
/* VARIABLE LEN IE */
CWBool CW80211AssembleIESSID(char * frame, int * offset, char * value) {
//Type
unsigned char val=IE_TYPE_SSID;
CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
(*offset) += IE_TYPE_LEN;
//len
val=strlen(value);
CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(val), IE_SIZE_LEN);
(*offset) += IE_SIZE_LEN;
//value
CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), value, strlen(value));
(*offset) += strlen(value);
return CW_TRUE;
}
float mapSupportedRatesValues(float rate, short int mode)
{
if(mode == CW_80211_SUPP_RATES_CONVERT_VALUE_TO_FRAME)
{
if(rate == 1)
return 2;
if(rate == 2)
return 4;
if(rate == 5.5)
return 11;
if(rate == 6)
return 12;
if(rate == 9)
return 18;
if(rate == 11)
return 22;
if(rate == 12)
return 24;
if(rate == 18)
return 36;
if(rate == 22)
return 44;
if(rate == 24)
return 48;
if(rate == 33)
return 66;
if(rate == 36)
return 72;
if(rate == 48)
return 96;
if(rate == 54)
return 108;
}
if(mode == CW_80211_SUPP_RATES_CONVERT_FRAME_TO_VALUE)
{
if(rate == 2)
return 1;
if(rate == 4)
return 2;
if(rate == 11)
return 5.5;
if(rate == 12)
return 6;
if(rate == 18)
return 9;
if(rate == 22)
return 11;
if(rate == 24)
return 12;
if(rate == 36)
return 18;
if(rate == 44)
return 22;
if(rate == 48)
return 24;
if(rate == 66)
return 33;
if(rate == 72)
return 36;
if(rate == 96)
return 48;
if(rate == 108)
return 54;
}
return -1;
}
CWBool CW80211AssembleIESupportedRates(char * frame, int * offset, char * value, int numRates) {
char val=IE_TYPE_SUPP_RATES;
CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
(*offset) += IE_TYPE_LEN;
if(numRates <= 0)
return CW_FALSE;
CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(numRates), IE_SIZE_LEN);
(*offset) += IE_SIZE_LEN;
CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), value, numRates);
(*offset) += numRates;
return CW_TRUE;
}
CWBool CW80211AssembleIEDSSS(char * frame, int * offset, char value) {
char val=IE_TYPE_DSSS;
CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
(*offset) += IE_TYPE_LEN;
val=1;
CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(val), IE_SIZE_LEN);
(*offset) += IE_SIZE_LEN;
CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), &(value), 1);
(*offset) += 1;
return CW_TRUE;
}
CWBool CW80211AssembleIEMaxIdlePeriod(char * frame, int * offset, short int value) {
char val=IE_TYPE_BSS_MAX_IDLE_PERIOD;
CW_COPY_MEMORY(frame, &(val), IE_TYPE_LEN);
(*offset) += IE_TYPE_LEN;
val=300;
CW_COPY_MEMORY((frame+IE_TYPE_LEN), &(val), IE_SIZE_LEN);
(*offset) += IE_SIZE_LEN;
/*
unsigned int val;
*pos++ = WLAN_EID_BSS_MAX_IDLE_PERIOD;
*pos++ = 3;
val = hapd->conf->ap_max_inactivity;
if (val > 68000)
val = 68000;
val *= 1000;
val /= 1024;
if (val == 0)
val = 1;
if (val > 65535)
val = 65535;
WPA_PUT_LE16(pos, val);
pos += 2;
*pos++ = 0x00; // TODO: Protected Keep-Alive Required
*/
CW_COPY_MEMORY((frame+IE_TYPE_LEN+IE_SIZE_LEN), &(value), 1);
(*offset) += 1;
return CW_TRUE;
}
//802.3
CWBool CW8023AssembleHdrLength(char * frame, int * offset, short int value) {
CW_COPY_MEMORY(frame, &(value), 2);
(*offset) += 2;
return CW_TRUE;
}
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* ------------------ PARSE ---------------------- */
CWBool CW80211ParseFrameIEControl(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_FRAME_CONTROL);
(*offsetFrameReceived) += LEN_IE_FRAME_CONTROL;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEDuration(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_DURATION);
(*offsetFrameReceived) += LEN_IE_DURATION;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEAddr(char * frameReceived, int * offsetFrameReceived, unsigned char * addr) {
CW_COPY_MEMORY(addr, frameReceived, ETH_ALEN);
(*offsetFrameReceived) += ETH_ALEN;
return CW_TRUE;
}
CWBool CW80211ParseFrameIESeqCtrl(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_SEQ_CTRL);
(*offsetFrameReceived) += LEN_IE_SEQ_CTRL;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEStatusCode(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_STATUS_CODE);
(*offsetFrameReceived) += LEN_IE_STATUS_CODE;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEReasonCode(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_REASON_CODE);
(*offsetFrameReceived) += LEN_IE_REASON_CODE;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEAuthAlgo(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_AUTH_ALG);
(*offsetFrameReceived) += LEN_IE_AUTH_ALG;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEAuthTransaction(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_AUTH_TRANS);
(*offsetFrameReceived) += LEN_IE_AUTH_TRANS;
return CW_TRUE;
}
CWBool CW80211ParseFrameIECapability(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_CAPABILITY);
(*offsetFrameReceived) += LEN_IE_CAPABILITY;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEAssID(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_ASSOCIATION_ID);
(*offsetFrameReceived) += LEN_IE_ASSOCIATION_ID;
return CW_TRUE;
}
CWBool CW80211ParseFrameIEListenInterval(char * frameReceived, int * offsetFrameReceived, short int * value) {
CW_COPY_MEMORY(value,frameReceived, LEN_IE_LISTEN_INTERVAL);
(*offsetFrameReceived) += LEN_IE_LISTEN_INTERVAL;
return CW_TRUE;
}
CWBool CW80211ParseFrameIESSID(char * frameReceived, int * offsetFrameReceived, char ** value) {
if(frameReceived[0] != IE_TYPE_SSID)
return CW_FALSE;
(*offsetFrameReceived)++;
short int len = frameReceived[1];
if(len == 0)
return CW_FALSE;
(*offsetFrameReceived)++;
CW_CREATE_ARRAY_CALLOC_ERR((*value), len+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return CW_FALSE;});
CW_COPY_MEMORY((*value),&(frameReceived[2]), len);
(*offsetFrameReceived) += len;
return CW_TRUE;
}
CWBool CW80211ParseFrameIESupportedRates(char * frameReceived, int * offsetFrameReceived, char ** value, int * lenIE) {
if(frameReceived[0] != IE_TYPE_SUPP_RATES)
return CW_FALSE;
(*offsetFrameReceived)++;
short int len = frameReceived[1];
if(len == 0)
return CW_FALSE;
(*offsetFrameReceived)++;
(*lenIE) = len;
CW_CREATE_ARRAY_CALLOC_ERR((*value), len+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return CW_FALSE;});
CW_COPY_MEMORY((*value),&(frameReceived[2]), len);
(*offsetFrameReceived) += len;
return CW_TRUE;
}
/*
* Scan ieee80211 frame body arguments
*/
ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
struct ieee802_11_elems *elems,
int show_errors)
{
size_t left = len;
const u8 *pos = start;
int unknown = 0;
os_memset(elems, 0, sizeof(*elems));
while (left >= 2) {
u8 id, elen;
id = *pos++;
elen = *pos++;
left -= 2;
if (elen > left) {
if (show_errors) {
CWLog("IEEE 802.11 element "
"parse failed (id=%d elen=%d "
"left=%lu)",
id, elen, (unsigned long) left);
//wpa_hexdump(MSG_MSGDUMP, "IEs", start, len);
}
return ParseFailed;
}
switch (id) {
case WLAN_EID_SSID:
elems->ssid = pos;
elems->ssid_len = elen;
CWLog("SSID[0]: %c", elems->ssid[0]);
break;
case WLAN_EID_SUPP_RATES:
elems->supp_rates = pos;
elems->supp_rates_len = elen;
CWLog("SUPP RATES[0]: %c", elems->supp_rates[0]);
break;
case WLAN_EID_DS_PARAMS:
elems->ds_params = pos;
elems->ds_params_len = elen;
break;
/*
case WLAN_EID_CF_PARAMS:
case WLAN_EID_TIM:
break;
case WLAN_EID_CHALLENGE:
elems->challenge = pos;
elems->challenge_len = elen;
break;
case WLAN_EID_ERP_INFO:
elems->erp_info = pos;
elems->erp_info_len = elen;
break;
case WLAN_EID_EXT_SUPP_RATES:
elems->ext_supp_rates = pos;
elems->ext_supp_rates_len = elen;
break;
case WLAN_EID_VENDOR_SPECIFIC:
if (ieee802_11_parse_vendor_specific(pos, elen,
elems,
show_errors))
unknown++;
break;
case WLAN_EID_RSN:
elems->rsn_ie = pos;
elems->rsn_ie_len = elen;
break;
case WLAN_EID_PWR_CAPABILITY:
break;
case WLAN_EID_SUPPORTED_CHANNELS:
elems->supp_channels = pos;
elems->supp_channels_len = elen;
break;
case WLAN_EID_MOBILITY_DOMAIN:
elems->mdie = pos;
elems->mdie_len = elen;
break;
case WLAN_EID_FAST_BSS_TRANSITION:
elems->ftie = pos;
elems->ftie_len = elen;
break;
case WLAN_EID_TIMEOUT_INTERVAL:
elems->timeout_int = pos;
elems->timeout_int_len = elen;
break;
case WLAN_EID_HT_CAP:
elems->ht_capabilities = pos;
elems->ht_capabilities_len = elen;
break;
case WLAN_EID_HT_OPERATION:
elems->ht_operation = pos;
elems->ht_operation_len = elen;
break;
case WLAN_EID_VHT_CAP:
elems->vht_capabilities = pos;
elems->vht_capabilities_len = elen;
break;
case WLAN_EID_VHT_OPERATION:
elems->vht_operation = pos;
elems->vht_operation_len = elen;
break;
case WLAN_EID_VHT_OPERATING_MODE_NOTIFICATION:
if (elen != 1)
break;
elems->vht_opmode_notif = pos;
break;
case WLAN_EID_LINK_ID:
if (elen < 18)
break;
elems->link_id = pos;
break;
case WLAN_EID_INTERWORKING:
elems->interworking = pos;
elems->interworking_len = elen;
break;
case WLAN_EID_QOS_MAP_SET:
if (elen < 16)
break;
elems->qos_map_set = pos;
elems->qos_map_set_len = elen;
break;
case WLAN_EID_EXT_CAPAB:
elems->ext_capab = pos;
elems->ext_capab_len = elen;
break;
case WLAN_EID_BSS_MAX_IDLE_PERIOD:
if (elen < 3)
break;
elems->bss_max_idle_period = pos;
break;
case WLAN_EID_SSID_LIST:
elems->ssid_list = pos;
elems->ssid_list_len = elen;
break;
*/
default:
unknown++;
if (!show_errors)
break;
CWLog("IEEE 802.11 element parse "
"ignored unknown element (id=%d elen=%d)",
id, elen);
break;
}
left -= elen;
pos += elen;
}
if (left)
return ParseFailed;
return unknown ? ParseUnknown : ParseOK;
}
/* ----------------------------------------------- */
/* +++++++++++++++++++++ ASSEMBLE +++++++++++++++++++++++ */
//Genera beacon frame
char * CW80211AssembleBeacon(WTPBSSInfo * WTPBSSInfoPtr, int *offset) {
char * beaconFrame;
CW_CREATE_ARRAY_CALLOC_ERR(beaconFrame, (MGMT_FRAME_FIXED_LEN_BEACON+MGMT_FRAME_IE_FIXED_LEN+strlen(WTPBSSInfoPtr->interfaceInfo->SSID)+1), char, { CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;}); //MAC80211_HEADER_FIXED_LEN+MAC80211_BEACON_BODY_MANDATORY_MIN_LEN+2+strlen(interfaceInfo->SSID)+10+1), char, return CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL););
(*offset)=0;
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(beaconFrame[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_BEACON))
return NULL;
//duration: 2 byte
if(!CW80211AssembleIEDuration(&(beaconFrame[(*offset)]), offset, 0))
return NULL;
//da: 6 byte. Broadcast
if(!CW80211AssembleIEAddr(&(beaconFrame[(*offset)]), offset, NULL))
return NULL;
//sa: 6 byte
if(!CW80211AssembleIEAddr(&(beaconFrame[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->MACaddr))
return NULL;
//bssid: 6 byte
if(!CW80211AssembleIEAddr(&(beaconFrame[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->BSSID))
return NULL;
//2 (sequence ctl) + 8 (timestamp): vengono impostati in automatico
(*offset) += LEN_IE_SEQ_CTRL;
(*offset) += LEN_IE_TIMESTAMP;
//beacon interval: 2 byte
if(!CW80211AssembleIEBeaconInterval(&(beaconFrame[(*offset)]), offset, 100))
return NULL;
//capability: 2 byte
if(!CW80211AssembleIECapability(&(beaconFrame[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->capabilityBit))
return NULL;
//SSID
if(!CW80211AssembleIESSID(&(beaconFrame[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->SSID))
return NULL;
return beaconFrame;
}
//Genera probe response
char * CW80211AssembleProbeResponse(WTPBSSInfo * WTPBSSInfoPtr, struct CWFrameProbeRequest *request, int *offset)
{
if(request == NULL)
return NULL;
CWLog("[CW80211] Assemble Probe response per SSID: %s", WTPBSSInfoPtr->interfaceInfo->ifName);
(*offset)=0;
/* ***************** PROBE RESPONSE FRAME FIXED ******************** */
char * frameProbeResponse;
CW_CREATE_ARRAY_CALLOC_ERR(frameProbeResponse, MGMT_FRAME_FIXED_LEN_PROBE_RESP+MGMT_FRAME_IE_FIXED_LEN*3+strlen(WTPBSSInfoPtr->interfaceInfo->SSID)+CW_80211_MAX_SUPP_RATES+1+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;});
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(frameProbeResponse[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_PROBE_RESP))
return NULL;
//duration: 2 byte
if(!CW80211AssembleIEDuration(&(frameProbeResponse[(*offset)]), offset, 0))
return NULL;
//da: 6 byte
if(request)
{
if(!CW80211AssembleIEAddr(&(frameProbeResponse[(*offset)]), offset, request->SA))
return NULL;
}
else
{
if(!CW80211AssembleIEAddr(&(frameProbeResponse[(*offset)]), offset, NULL))
return NULL;
}
//sa: 6 byte
if(!CW80211AssembleIEAddr(&(frameProbeResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->MACaddr))
return NULL;
//bssid: 6 byte
if(!CW80211AssembleIEAddr(&(frameProbeResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->BSSID))
return NULL;
//2 (sequence ctl) + 8 (timestamp): vengono impostati in automatico
(*offset) += LEN_IE_SEQ_CTRL;
(*offset) += LEN_IE_TIMESTAMP;
//beacon interval: 2 byte
if(!CW80211AssembleIEBeaconInterval(&(frameProbeResponse[(*offset)]), offset, 100))
return NULL;
//capability: 2 byte
if(!CW80211AssembleIECapability(&(frameProbeResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->capabilityBit))
return NULL;
/* *************************************************** */
//SSID
if(!CW80211AssembleIESSID(&(frameProbeResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->SSID))
return NULL;
//Supported Rates
int indexRates=0;
unsigned char suppRate[CW_80211_MAX_SUPP_RATES];
for(indexRates=0; indexRates < WTP_NL80211_BITRATE_NUM && indexRates < CW_80211_MAX_SUPP_RATES && indexRates < WTPBSSInfoPtr->phyInfo->lenSupportedRates; indexRates++)
suppRate[indexRates] = (char) mapSupportedRatesValues(WTPBSSInfoPtr->phyInfo->phyMbpsSet[indexRates], CW_80211_SUPP_RATES_CONVERT_VALUE_TO_FRAME);
if(!CW80211AssembleIESupportedRates(&(frameProbeResponse[(*offset)]), offset, suppRate, indexRates))
return NULL;
//DSSS
unsigned char channel = CW_WTP_DEFAULT_RADIO_CHANNEL+1;
if(!CW80211AssembleIEDSSS(&(frameProbeResponse[(*offset)]), offset, channel))
return NULL;
return frameProbeResponse;
}
//Genera auth response
char * CW80211AssembleAuthResponse(char * addrAP, struct CWFrameAuthRequest *request, int *offset)
{
if(request == NULL)
return NULL;
CWLog("[CW80211] Assemble Auth response");
(*offset)=0;
/* ***************** FRAME FIXED ******************** */
char * frameAuthResponse;
CW_CREATE_ARRAY_CALLOC_ERR(frameAuthResponse, MGMT_FRAME_FIXED_LEN_AUTH, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;});
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(frameAuthResponse[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_AUTH))
return NULL;
//duration: 2 byte
if(!CW80211AssembleIEDuration(&(frameAuthResponse[(*offset)]), offset, 0))
return NULL;
//da: 6 byte
if(request)
{
if(!CW80211AssembleIEAddr(&(frameAuthResponse[(*offset)]), offset, request->SA))
return NULL;
}
else
{
if(!CW80211AssembleIEAddr(&(frameAuthResponse[(*offset)]), offset, NULL))
return NULL;
}
//sa: 6 byte
if(!CW80211AssembleIEAddr(&(frameAuthResponse[(*offset)]), offset, addrAP))
return NULL;
//bssid: 6 byte
if(!CW80211AssembleIEAddr(&(frameAuthResponse[(*offset)]), offset, addrAP))
return NULL;
//2 (sequence ctl)
(*offset) += LEN_IE_SEQ_CTRL;
//Auth Algorithm Number: 2 byte
if(!CW80211AssembleIEAuthAlgoNum(&(frameAuthResponse[(*offset)]), offset, IE_AUTH_OPEN_SYSTEM))
return NULL;
//Auth Algorithm Number: 2 byte (valore seq: 2)
if(!CW80211AssembleIEAuthTransNum(&(frameAuthResponse[(*offset)]), offset, 2))
return NULL;
//Status Code: 2 byte (valore: 0 status code success)
if(!CW80211AssembleIEStatusCode(&(frameAuthResponse[(*offset)]), offset, IE_STATUS_CODE_SUCCESS))
return NULL;
/* ************************************************* */
return frameAuthResponse;
}
//Genera association response
char * CW80211AssembleAssociationResponse(WTPBSSInfo * WTPBSSInfoPtr, WTPSTAInfo * thisSTA, struct CWFrameAssociationRequest *request, int *offset)
{
if(request == NULL)
return NULL;
CWLog("[CW80211] Assemble Association response");
(*offset)=0;
/* ***************** FRAME FIXED ******************** */
char * frameAssociationResponse;
CW_CREATE_ARRAY_CALLOC_ERR(frameAssociationResponse, MGMT_FRAME_FIXED_LEN_ASSOCIATION+MGMT_FRAME_IE_FIXED_LEN*3+CW_80211_MAX_SUPP_RATES+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;});
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(frameAssociationResponse[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ASSOC_RESP))
return NULL;
//duration: 2 byte
if(!CW80211AssembleIEDuration(&(frameAssociationResponse[(*offset)]), offset, 0))
return NULL;
//da: 6 byte
if(request)
{
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, request->SA))
return NULL;
}
else
{
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, NULL))
return NULL;
}
//sa: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->MACaddr))
return NULL;
//bssid: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->BSSID))
return NULL;
//2 (sequence ctl)
(*offset) += LEN_IE_SEQ_CTRL;
//capability: 2 byte
if(!CW80211AssembleIECapability(&(frameAssociationResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->capabilityBit))
return NULL;
/* ************************************************* */
//Status Code: 2 byte (valore: 0 status code success)
if(!CW80211AssembleIEStatusCode(&(frameAssociationResponse[(*offset)]), offset, IE_STATUS_CODE_SUCCESS))
return NULL;
//Association ID: 2 byte
if(!CW80211AssembleIEAssID(&(frameAssociationResponse[(*offset)]), offset, thisSTA->staAID))
return NULL;
//Supported Rates
//TODO: Capability Re-set? Use STA capability value?
int indexRates=0;
unsigned char suppRate[CW_80211_MAX_SUPP_RATES];
for(indexRates=0; indexRates < WTP_NL80211_BITRATE_NUM && indexRates < CW_80211_MAX_SUPP_RATES && indexRates < WTPBSSInfoPtr->phyInfo->lenSupportedRates; indexRates++)
suppRate[indexRates] = (char) mapSupportedRatesValues(WTPBSSInfoPtr->phyInfo->phyMbpsSet[indexRates], CW_80211_SUPP_RATES_CONVERT_VALUE_TO_FRAME);
if(!CW80211AssembleIESupportedRates(&(frameAssociationResponse[(*offset)]), offset, suppRate, indexRates))
return NULL;
/*
* idle timeout
if(!CW80211AssembleIESupportedRates(&(frameAssociationResponse[(*offset)]), offset, suppRate, indexRates))
return NULL;
*/
return frameAssociationResponse;
}
//Genera reassociation response
char * CW80211AssembleReassociationResponse(WTPBSSInfo * WTPBSSInfoPtr, WTPSTAInfo * thisSTA, struct CWFrameAssociationRequest *request, int *offset)
{
if(request == NULL)
return NULL;
CWLog("[CW80211] Assemble Association response");
(*offset)=0;
/* ***************** FRAME FIXED ******************** */
char * frameAssociationResponse;
CW_CREATE_ARRAY_CALLOC_ERR(frameAssociationResponse, MGMT_FRAME_FIXED_LEN_ASSOCIATION+MGMT_FRAME_IE_FIXED_LEN*3+CW_80211_MAX_SUPP_RATES+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;});
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(frameAssociationResponse[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_REASSOC_RESP))
return NULL;
//duration: 2 byte
if(!CW80211AssembleIEDuration(&(frameAssociationResponse[(*offset)]), offset, 0))
return NULL;
//da: 6 byte
if(request)
{
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, request->SA))
return NULL;
}
else
{
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, NULL))
return NULL;
}
//sa: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->MACaddr))
return NULL;
//bssid: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->BSSID))
return NULL;
//2 (sequence ctl)
(*offset) += LEN_IE_SEQ_CTRL;
//capability: 2 byte
if(!CW80211AssembleIECapability(&(frameAssociationResponse[(*offset)]), offset, WTPBSSInfoPtr->interfaceInfo->capabilityBit))
return NULL;
/* ************************************************* */
//Status Code: 2 byte (valore: 0 status code success)
if(!CW80211AssembleIEStatusCode(&(frameAssociationResponse[(*offset)]), offset, IE_STATUS_CODE_SUCCESS))
return NULL;
//Association ID: 2 byte
if(!CW80211AssembleIEAssID(&(frameAssociationResponse[(*offset)]), offset, thisSTA->staAID))
return NULL;
//Supported Rates
//TODO: Capability Re-set? Use STA capability value?
int indexRates=0;
unsigned char suppRate[CW_80211_MAX_SUPP_RATES];
for(indexRates=0; indexRates < WTP_NL80211_BITRATE_NUM && indexRates < CW_80211_MAX_SUPP_RATES && indexRates < WTPBSSInfoPtr->phyInfo->lenSupportedRates; indexRates++)
suppRate[indexRates] = (char) mapSupportedRatesValues(WTPBSSInfoPtr->phyInfo->phyMbpsSet[indexRates], CW_80211_SUPP_RATES_CONVERT_VALUE_TO_FRAME);
if(!CW80211AssembleIESupportedRates(&(frameAssociationResponse[(*offset)]), offset, suppRate, indexRates))
return NULL;
//idle timeout
return frameAssociationResponse;
}
char * CW80211AssembleAssociationResponseAC(unsigned char * MACAddr, unsigned char * BSSID, short int capabilityBit, short int staAID, unsigned char * suppRate, int suppRatesLen, struct CWFrameAssociationRequest *request, int *offset)
{
if(request == NULL || BSSID == NULL || MACAddr == NULL || suppRate == NULL)
return NULL;
CWLog("[CW80211] Assemble Association response AC side");
(*offset)=0;
/* ***************** FRAME FIXED ******************** */
char * frameAssociationResponse;
CW_CREATE_ARRAY_CALLOC_ERR(frameAssociationResponse, MGMT_FRAME_FIXED_LEN_ASSOCIATION+MGMT_FRAME_IE_FIXED_LEN+CW_80211_MAX_SUPP_RATES+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;});
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(frameAssociationResponse[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ASSOC_RESP))
return NULL;
//duration: 2 byte
if(!CW80211AssembleIEDuration(&(frameAssociationResponse[(*offset)]), offset, 0))
return NULL;
//da: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, request->SA))
return NULL;
//sa: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, MACAddr))
return NULL;
//bssid: 6 byte
if(!CW80211AssembleIEAddr(&(frameAssociationResponse[(*offset)]), offset, BSSID))
return NULL;
//2 (sequence ctl)
(*offset) += LEN_IE_SEQ_CTRL;
//capability: 2 byte
if(!CW80211AssembleIECapability(&(frameAssociationResponse[(*offset)]), offset, capabilityBit))
return NULL;
/* ************************************************* */
//Status Code: 2 byte (valore: 0 status code success)
if(!CW80211AssembleIEStatusCode(&(frameAssociationResponse[(*offset)]), offset, IE_STATUS_CODE_SUCCESS))
return NULL;
//Association ID: 2 byte
if(!CW80211AssembleIEAssID(&(frameAssociationResponse[(*offset)]), offset, staAID))
return NULL;
if(suppRatesLen > 0)
{
//Supported Rates
if(!CW80211AssembleIESupportedRates(&(frameAssociationResponse[(*offset)]), offset, suppRate, suppRatesLen))
return NULL;
}
return frameAssociationResponse;
}
char * CW80211AssembleReassociationResponseAC(unsigned char * MACAddr, unsigned char * BSSID, short int capabilityBit, short int staAID, unsigned char * suppRate, int suppRatesLen, struct CWFrameAssociationRequest *request, int *offset)
{
if(request == NULL || BSSID == NULL || MACAddr == NULL || suppRate == NULL)
return NULL;
CWLog("[CW80211] Assemble Reassociation response AC side");
(*offset)=0;
/* ***************** FRAME FIXED ******************** */
char * frameAssociationResponse;
CW_CREATE_ARRAY_CALLOC_ERR(frameAssociationResponse, MGMT_FRAME_FIXED_LEN_ASSOCIATION+MGMT_FRAME_IE_FIXED_LEN+CW_80211_MAX_SUPP_RATES+1, char, {CWErrorRaise(CW_ERROR_OUT_OF_MEMORY, NULL); return NULL;});
//frame control: 2 byte
if(!CW80211AssembleIEFrameControl(&(frameAssociationResponse[(*offset)]), offset, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_REASSOC_RESP))