-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathRadioTapFields.cs
More file actions
1911 lines (1716 loc) · 50.1 KB
/
RadioTapFields.cs
File metadata and controls
1911 lines (1716 loc) · 50.1 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
/*
This file is part of PacketDotNet.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
using System;
using System.IO;
using PacketDotNet.Utils.Converters;
namespace PacketDotNet.Ieee80211;
/// <summary>
/// The presence of this field indicates that the frame was received or transmitted using the VHT PHY (Wi-Fi 5 / ieee802.11ac).
/// </summary>
public class VeryHighThroughputRadioTapField : RadioTapField
{
/// <summary>
/// Indicates the precense of data in this field
/// </summary>
public RadioTapVhtKnown Known { get; set; }
/// <summary>
/// VHT Flags
/// </summary>
public RadioTapVhtFlags Flags { get; set; }
/// <summary>
/// Indicates the bandwidth and side channel for a frame capture with VHT
/// </summary>
public RadioTapVhtBandwidth Bandwidth { get; set; }
/// <summary>
/// Indicates MCS and NSS for user 1
/// </summary>
public RadioTapVhtMcsNss McsNss1 { get; set; }
/// <summary>
/// Indicates MCS and NSS for user 2
/// </summary>
public RadioTapVhtMcsNss McsNss2 { get; set; }
/// <summary>
/// Indicates MCS and NSS for user 3
/// </summary>
public RadioTapVhtMcsNss McsNss3 { get; set; }
/// <summary>
/// Indicates MCS and NSS for user 4
/// </summary>
public RadioTapVhtMcsNss McsNss4 { get; set; }
/// <summary>
/// The coding for a user is only valid if the NSS (in the mcs_nss field) for that user is nonzero.
/// Encodes the FEC for up to four users
/// </summary>
public RadioTapVhtCoding Coding { get; set; }
/// <summary>
/// Group ID
/// The Group ID can be used to differentiate between SU PPDUs (group ID is 0 or 63) and MU PPDUs (group ID is 1 through 62).
/// </summary>
public byte GroupId { get; set; }
/// <summary>
/// Partial AID
/// Only applicable to SU PPDUs.
/// </summary>
public ushort PartialAid { get; set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public VeryHighThroughputRadioTapField(BinaryReader br)
{
Known = (RadioTapVhtKnown)br.ReadUInt16();
Flags = (RadioTapVhtFlags)br.ReadByte();
Bandwidth = (RadioTapVhtBandwidth)br.ReadByte();
McsNss1 = (RadioTapVhtMcsNss)br.ReadByte();
McsNss2 = (RadioTapVhtMcsNss)br.ReadByte();
McsNss3 = (RadioTapVhtMcsNss)br.ReadByte();
McsNss4 = (RadioTapVhtMcsNss)br.ReadByte();
Coding = (RadioTapVhtCoding)br.ReadByte();
GroupId = br.ReadByte();
PartialAid = br.ReadUInt16();
}
/// <summary>
/// Initializes a new instance of the <see cref="VeryHighThroughputRadioTapField" /> class.
/// </summary>
public VeryHighThroughputRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="VeryHighThroughputRadioTapField" /> class.
/// </summary>
public VeryHighThroughputRadioTapField(
RadioTapVhtKnown known,
RadioTapVhtFlags flags,
RadioTapVhtBandwidth bandwidth,
RadioTapVhtMcsNss mcsNss1,
RadioTapVhtMcsNss mcsNss2,
RadioTapVhtMcsNss mcsNss3,
RadioTapVhtMcsNss mcsNss4,
RadioTapVhtCoding coding,
byte groupId,
ushort partialAid)
{
Known = known;
Flags = flags;
Bandwidth = bandwidth;
McsNss1 = mcsNss1;
McsNss2 = mcsNss2;
McsNss3 = mcsNss3;
McsNss4 = mcsNss4;
Coding = coding;
GroupId = groupId;
PartialAid = partialAid;
}
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.VeryHighThroughput;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 12;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => 2;
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
EndianBitConverter.Little.CopyBytes((ushort)Known, dest, offset);
EndianBitConverter.Little.CopyBytes((byte)Flags, dest, offset + 2);
EndianBitConverter.Little.CopyBytes((byte)Bandwidth, dest, offset + 3);
EndianBitConverter.Little.CopyBytes((byte)McsNss1, dest, offset + 4);
EndianBitConverter.Little.CopyBytes((byte)McsNss2, dest, offset + 5);
EndianBitConverter.Little.CopyBytes((byte)McsNss3, dest, offset + 6);
EndianBitConverter.Little.CopyBytes((byte)McsNss4, dest, offset + 7);
EndianBitConverter.Little.CopyBytes((byte)Coding, dest, offset + 8);
EndianBitConverter.Little.CopyBytes(GroupId, dest, offset + 9);
EndianBitConverter.Little.CopyBytes(PartialAid, dest, offset + 10);
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"Known {Known}, Flags {Flags}, Bandwidth {Bandwidth}, McsNss1 {McsNss1}, McsNss2 {McsNss2}, McsNss3 {McsNss3}, McsNss4 {McsNss4}, Coding {Coding}, GroupId {GroupId}, PartialAid {PartialAid}";
}
}
/// <summary>
/// The presence of this field indicates that the frame was received or transmitted using the HE PHY (Wi-Fi 6 / ieee802.11ax).
/// </summary>
public class HighEfficiencyRadioTapField : RadioTapField
{
/// <summary>
/// Indicates the presence of known fields as well as the HE PPDU format
/// </summary>
public RadioTapHighEfficiencyData1 Data1 { get; set; }
/// <summary>
/// Indicates the presence of known fields as well as the PRI/SEC 80MHz field
/// </summary>
public RadioTapHighEfficiencyData2 Data2 { get; set; }
/// <summary>
/// Indicates the presence of additional known fields as well as the value of pri/sec 80MHz
/// </summary>
public RadioTapHighEfficiencyData3 Data3 { get; set; }
/// <summary>
/// Data depends on the PPDU Format (See Data.HePpduFormat)
/// </summary>
public ushort Data4 { get; set; }
/// <summary>
/// Data fields where the availability depends on the known flags from Data1/Data2
/// </summary>
public RadioTapHighEfficiencyData5 Data5 { get; set; }
/// <summary>
/// Data fields where the availability depends on the known flags from Data1/Data2
/// </summary>
public RadioTapHighEfficiencyData6 Data6 { get; set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public HighEfficiencyRadioTapField(BinaryReader br)
{
Data1 = (RadioTapHighEfficiencyData1)br.ReadUInt16();
Data2 = (RadioTapHighEfficiencyData2)br.ReadUInt16();
Data3 = (RadioTapHighEfficiencyData3)br.ReadUInt16();
Data4 = br.ReadUInt16();
Data5 = (RadioTapHighEfficiencyData5)br.ReadUInt16();
Data6 = (RadioTapHighEfficiencyData6)br.ReadUInt16();
}
/// <summary>
/// Initializes a new instance of the <see cref="HighEfficiencyRadioTapField" /> class.
/// </summary>
public HighEfficiencyRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="HighEfficiencyRadioTapField" /> class.
/// </summary>
public HighEfficiencyRadioTapField(RadioTapHighEfficiencyData1 data1, RadioTapHighEfficiencyData2 data2, RadioTapHighEfficiencyData3 data3, ushort data4, RadioTapHighEfficiencyData5 data5, RadioTapHighEfficiencyData6 data6)
{
Data1 = data1;
Data2 = data2;
Data3 = data3;
Data4 = data4;
Data5 = data5;
Data6 = data6;
}
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.HighEfficiency;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 12;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => 2;
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
EndianBitConverter.Little.CopyBytes((ushort)Data1, dest, offset);
EndianBitConverter.Little.CopyBytes((ushort)Data2, dest, offset + 2);
EndianBitConverter.Little.CopyBytes((ushort)Data3, dest, offset + 4);
EndianBitConverter.Little.CopyBytes(Data4, dest, offset + 6);
EndianBitConverter.Little.CopyBytes((ushort)Data5, dest, offset + 8);
EndianBitConverter.Little.CopyBytes((ushort)Data6, dest, offset + 10);
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"Data1 {Data1}, Data2 {Data2}, Data3 {Data3}, Data4 {Data4}, Data5 {Data5}, Data6 {Data6}";
}
}
public class McsRadioTapField : RadioTapField
{
/// <summary>
/// Indicates which information is known
/// </summary>
public RadioTapMcsKnown Known { get; set; }
/// <summary>
/// Indicates which information is known
/// </summary>
public RadioTapMcsFlags Flags { get; set; }
/// <summary>
/// Modulation and Coding Scheme
/// Determines the modulation type and coding rate.
/// </summary>
public byte Mcs { get; set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public McsRadioTapField(BinaryReader br)
{
Known = (RadioTapMcsKnown)br.ReadByte();
Flags = (RadioTapMcsFlags)br.ReadByte();
Mcs = br.ReadByte();
}
/// <summary>
/// Initializes a new instance of the <see cref="McsRadioTapField" /> class.
/// </summary>
public McsRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="McsRadioTapField" /> class.
/// <param name="known">Known information</param>
/// <param name="flags">MCS Flags</param>
/// <param name="mcs">Known information</param>
/// </summary>
public McsRadioTapField(RadioTapMcsKnown known, RadioTapMcsFlags flags, byte mcs)
{
Known = known;
Flags = flags;
Mcs = mcs;
}
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.Mcs;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 3;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => 1;
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
EndianBitConverter.Little.CopyBytes((byte)Known, dest, offset);
EndianBitConverter.Little.CopyBytes((byte)Flags, dest, offset + 1);
EndianBitConverter.Little.CopyBytes((byte)Mcs, dest, offset + 2);
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"Known {Known}, Flags {Flags}, Mcs {Mcs}";
}
}
/// <summary>
/// Channel field
/// </summary>
public class ChannelRadioTapField : RadioTapField
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public ChannelRadioTapField(BinaryReader br)
{
FrequencyMHz = br.ReadUInt16();
Channel = ChannelFromFrequencyMHz(FrequencyMHz);
Flags = (RadioTapChannelFlags) br.ReadUInt16();
}
/// <summary>
/// Initializes a new instance of the <see cref="ChannelRadioTapField" /> class.
/// </summary>
public ChannelRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="ChannelRadioTapField" /> class.
/// </summary>
/// <param name="frequencyMhz">Tx/Rx Frequency in MHz.</param>
/// <param name="flags">Flags.</param>
public ChannelRadioTapField(ushort frequencyMhz, RadioTapChannelFlags flags)
{
FrequencyMHz = frequencyMhz;
Channel = ChannelFromFrequencyMHz(FrequencyMHz);
Flags = flags;
}
/// <summary>
/// Channel number derived from frequency
/// </summary>
public int Channel { get; set; }
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.Channel;
/// <summary>
/// Gets the channel flags.
/// </summary>
public RadioTapChannelFlags Flags { get; }
/// <summary>
/// Frequency in MHz
/// </summary>
public ushort FrequencyMHz { get; set; }
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 4;
/// <summary>
/// Note that the alignment of the channel field is two bytes as it is comprised of two 2 byte fields
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => 2;
/// <summary>
/// Convert a frequency to a channel
/// </summary>
/// <remarks>
/// There is some overlap between the 802.11b/g channel numbers and the 802.11a channel numbers. This means that while a particular frequncy will only
/// ever map to single channel number the same channel number may be returned for more than one frequency. At present this affects channel numbers 8 and 12.
/// </remarks>
/// <param name="frequencyMHz">
/// A <see cref="int" />
/// </param>
/// <returns>
/// A <see cref="int" />
/// </returns>
public static int ChannelFromFrequencyMHz(int frequencyMHz)
{
switch (frequencyMHz)
{
//802.11 bg channel numbers
case 2412:
{
return 1;
}
case 2417:
{
return 2;
}
case 2422:
{
return 3;
}
case 2427:
{
return 4;
}
case 2432:
{
return 5;
}
case 2437:
{
return 6;
}
case 2442:
{
return 7;
}
case 2447:
{
return 8;
}
case 2452:
{
return 9;
}
case 2457:
{
return 10;
}
case 2462:
{
return 11;
}
case 2467:
{
return 12;
}
case 2472:
{
return 13;
}
case 2484:
{
return 14;
}
//802.11 a channel numbers
case 4920:
{
return 240;
}
case 4940:
{
return 244;
}
case 4960:
{
return 248;
}
case 4980:
{
return 252;
}
case 5040:
{
return 8;
}
case 5060:
{
return 12;
}
case 5080:
{
return 16;
}
case 5170:
{
return 34;
}
case 5180:
{
return 36;
}
case 5190:
{
return 38;
}
case 5200:
{
return 40;
}
case 5210:
{
return 42;
}
case 5220:
{
return 44;
}
case 5230:
{
return 46;
}
case 5240:
{
return 48;
}
case 5260:
{
return 52;
}
case 5280:
{
return 56;
}
case 5300:
{
return 60;
}
case 5320:
{
return 64;
}
case 5500:
{
return 100;
}
case 5520:
{
return 104;
}
case 5540:
{
return 108;
}
case 5560:
{
return 112;
}
case 5580:
{
return 116;
}
case 5600:
{
return 120;
}
case 5620:
{
return 124;
}
case 5640:
{
return 128;
}
case 5660:
{
return 132;
}
case 5680:
{
return 136;
}
case 5700:
{
return 140;
}
case 5745:
{
return 149;
}
case 5765:
{
return 153;
}
case 5785:
{
return 157;
}
case 5805:
{
return 161;
}
case 5825:
{
return 165;
}
default:
{
return 0;
}
}
}
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
EndianBitConverter.Little.CopyBytes(FrequencyMHz, dest, offset);
EndianBitConverter.Little.CopyBytes((ushort) Flags, dest, offset + 2);
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"FrequencyMHz {FrequencyMHz}, Channel {Channel}, Flags {Flags}";
}
}
/// <summary>
/// Fhss radio tap field
/// </summary>
public class FhssRadioTapField : RadioTapField
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public FhssRadioTapField(BinaryReader br)
{
var u16 = br.ReadUInt16();
ChannelHoppingSet = (byte) (u16 & 0xff);
Pattern = (byte) ((u16 >> 8) & 0xff);
}
/// <summary>
/// Initializes a new instance of the <see cref="FhssRadioTapField" /> class.
/// </summary>
public FhssRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="FhssRadioTapField" /> class.
/// </summary>
/// <param name='channelHoppingSet'>
/// Channel hopping set.
/// </param>
/// <param name='pattern'>
/// Channel hopping pattern.
/// </param>
public FhssRadioTapField(byte channelHoppingSet, byte pattern)
{
ChannelHoppingSet = channelHoppingSet;
Pattern = pattern;
}
/// <summary>
/// Hop set
/// </summary>
public byte ChannelHoppingSet { get; set; }
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.Fhss;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 2;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => Length;
/// <summary>
/// Hop pattern
/// </summary>
public byte Pattern { get; set; }
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
dest[offset] = ChannelHoppingSet;
dest[offset + 1] = Pattern;
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"ChannelHoppingSet {ChannelHoppingSet}, Pattern {Pattern}";
}
}
/// <summary>
/// Radio tap flags
/// </summary>
public class FlagsRadioTapField : RadioTapField
{
/// <summary>
/// Flags set
/// </summary>
public RadioTapFlags Flags;
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public FlagsRadioTapField(BinaryReader br)
{
var u8 = br.ReadByte();
Flags = (RadioTapFlags) u8;
}
/// <summary>
/// Initializes a new instance of the <see cref="FlagsRadioTapField" /> class.
/// </summary>
public FlagsRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="FlagsRadioTapField" /> class.
/// </summary>
/// <param name='flags'>
/// Flags.
/// </param>
public FlagsRadioTapField(RadioTapFlags flags)
{
Flags = flags;
}
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.Flags;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 1;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => Length;
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
dest[offset] = (byte) Flags;
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"Flags {Flags}";
}
}
/// <summary>
/// Rate field
/// </summary>
public class RateRadioTapField : RadioTapField
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public RateRadioTapField(BinaryReader br)
{
var u8 = br.ReadByte();
RateMbps = 0.5 * (u8 & 0x7f);
}
/// <summary>
/// Initializes a new instance of the <see cref="RateRadioTapField" /> class.
/// </summary>
public RateRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="RateRadioTapField" /> class.
/// </summary>
/// <param name='rateMbps'>
/// Rate mbps.
/// </param>
public RateRadioTapField(double rateMbps)
{
RateMbps = rateMbps;
}
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.Rate;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 1;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => Length;
/// <summary>
/// Rate in Mbps
/// </summary>
public double RateMbps { get; set; }
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
dest[offset] = (byte) (RateMbps / 0.5);
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"RateMbps {RateMbps}";
}
}
/// <summary>
/// Db antenna signal
/// </summary>
public class DbAntennaSignalRadioTapField : RadioTapField
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="br">
/// A <see cref="BinaryReader" />
/// </param>
public DbAntennaSignalRadioTapField(BinaryReader br)
{
SignalStrengthdB = br.ReadByte();
}
/// <summary>
/// Initializes a new instance of the <see cref="DbAntennaSignalRadioTapField" /> class.
/// </summary>
public DbAntennaSignalRadioTapField()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="DbAntennaSignalRadioTapField" /> class.
/// </summary>
/// <param name='signalStrengthdB'>
/// Signal strength in dB
/// </param>
public DbAntennaSignalRadioTapField(byte signalStrengthdB)
{
SignalStrengthdB = signalStrengthdB;
}
/// <summary>Type of the field</summary>
public override RadioTapType FieldType => RadioTapType.DbAntennaSignal;
/// <summary>
/// Gets the length of the field data.
/// </summary>
/// <value>
/// The length.
/// </value>
public override ushort Length => 1;
/// <summary>
/// Gets the alignment.
/// </summary>
/// <value>The alignment.</value>
public override ushort Alignment => Length;
/// <summary>
/// Signal strength in dB
/// </summary>
public byte SignalStrengthdB { get; set; }
/// <summary>
/// Copies the field data to the destination buffer at the specified offset.
/// </summary>
public override void CopyTo(byte[] dest, int offset)
{
dest[offset] = SignalStrengthdB;
}
/// <summary>
/// ToString() override
/// </summary>
/// <returns>
/// A <see cref="string" />
/// </returns>
public override string ToString()
{
return $"SignalStrengthdB {SignalStrengthdB}";
}
}
/// <summary>