libtins 4.5
Loading...
Searching...
No Matches
dot11_mgmt.h
1/*
2 * Copyright (c) 2017, Matias Fontanini
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <tins/config.h>
31
32#if !defined(TINS_DOT11_DOT11_MGMT_H) && defined(TINS_HAVE_DOT11)
33
34#define TINS_DOT11_DOT11_MGMT_H
35
36#include <vector>
37#include <utility>
38#include <tins/dot11/dot11_base.h>
39#include <tins/macros.h>
40
41namespace Tins {
45class TINS_API Dot11ManagementFrame : public Dot11 {
46public:
50 typedef std::vector<float> rates_type;
51
55 typedef std::vector<std::pair<uint8_t, uint8_t> > channels_type;
56
60 typedef std::vector<std::pair<uint8_t, uint8_t> > channel_map_type;
61
65 typedef std::vector<uint8_t> request_info_type;
66
70 static const PDU::PDUType pdu_flag = PDU::DOT11_MANAGEMENT;
71
79 UNSPECIFIED = 1,
80 PREV_AUTH_NOT_VALID = 2,
81 STA_LEAVING_IBSS_ESS = 3,
82 INACTIVITY = 4,
83 CANT_HANDLE_STA = 5,
84 CLASS2_FROM_NO_AUTH = 6,
85 CLASS3_FROM_NO_AUTH = 7,
86 STA_LEAVING_BSS = 8,
87 STA_NOT_AUTH_WITH_STA = 9,
88 POW_CAP_NOT_VALID = 10,
89 SUPPORTED_CHANN_NOT_VALID = 11,
90 INVALID_CONTENT = 13,
91 MIC_FAIL = 14,
92 HANDSHAKE_TIMEOUT = 15,
93 GROUP_KEY_TIMEOUT = 16,
94 WRONG_HANDSHAKE = 17,
95 INVALID_GROUP_CIPHER = 18,
96 INVALID_PAIRWISE_CIPHER = 19,
97 INVALID_AKMP = 20,
98 UNSOPPORTED_RSN_VERSION = 21,
99 INVALID_RSN_CAPABILITIES = 22,
100 AUTH_FAILED = 23,
101 CIPHER_SUITE_REJECTED = 24,
102 UNSPECIFIED_QOS_REASON = 32,
103 NOT_ENOUGH_BANDWITH = 33,
104 POOR_CHANNEL = 34,
105 STA_OUT_OF_LIMITS = 35,
106 REQUESTED_BY_STA_LEAVING = 36,
107 REQUESTED_BY_STA_REJECT_MECHANISM = 37,
108 REQUESTED_BY_STA_REJECT_SETUP = 38,
109 REQUESTED_BY_STA_TIMEOUT = 39,
110 PEER_STA_NOT_SUPPORT_CIPHER = 45
111 };
112
119 enum MapMask {
120 BSS = 0x1,
121 OFDM_PREAMBLE = 0x2,
122 UNIDENTIFIED_SIGNAL = 0x4,
123 RADAR = 0x8,
124 UNMEASURED = 0x10,
125 RESERVED = 0xE0
126 };
127
131 TINS_BEGIN_PACK
133 private:
134 #if TINS_IS_LITTLE_ENDIAN
135 uint16_t ess_:1,
136 ibss_:1,
137 cf_poll_:1,
138 cf_poll_req_:1,
139 privacy_:1,
140 short_preamble_:1,
141 pbcc_:1,
142 channel_agility_:1,
143 spectrum_mgmt_:1,
144 qos_:1,
145 sst_:1,
146 apsd_:1,
147 radio_measurement_:1,
148 dsss_ofdm_:1,
149 delayed_block_ack_:1,
150 immediate_block_ack_:1;
151 #elif TINS_IS_BIG_ENDIAN
152 uint16_t channel_agility_:1,
153 pbcc_:1,
154 short_preamble_:1,
155 privacy_:1,
156 cf_poll_req_:1,
157 cf_poll_:1,
158 ibss_:1,
159 ess_:1,
160 immediate_block_ack_:1,
161 delayed_block_ack_:1,
162 dsss_ofdm_:1,
163 radio_measurement_:1,
164 apsd_:1,
165 sst_:1,
166 qos_:1,
167 spectrum_mgmt_:1;
168 #endif
169 public:
175 bool ess() const {
176 return ess_;
177 }
178
184 bool ibss() const {
185 return ibss_;
186 }
187
193 bool cf_poll() const {
194 return cf_poll_;
195 }
196
202 bool cf_poll_req() const {
203 return cf_poll_req_;
204 }
205
211 bool privacy() const {
212 return privacy_;
213 }
214
220 bool short_preamble() const {
221 return short_preamble_;
222 }
223
229 bool pbcc() const {
230 return pbcc_;
231 }
232
238 bool channel_agility() const {
239 return channel_agility_;
240 }
241
247 bool spectrum_mgmt() const {
248 return spectrum_mgmt_;
249 }
250
256 bool qos() const {
257 return qos_;
258 }
259
265 bool sst() const {
266 return sst_;
267 }
268
274 bool apsd() const {
275 return apsd_;
276 }
277
283 bool radio_measurement() const {
284 return radio_measurement_;
285 }
286
292 bool dsss_ofdm() const {
293 return dsss_ofdm_;
294 }
295
301 bool delayed_block_ack() const {
302 return delayed_block_ack_;
303 }
304
310 bool immediate_block_ack() const {
311 return immediate_block_ack_;
312 }
313
319 void ess(bool new_value) {
320 ess_ = new_value;
321 }
322
328 void ibss(bool new_value) {
329 ibss_ = new_value;
330 }
331
337 void cf_poll(bool new_value) {
338 cf_poll_ = new_value;
339 }
340
346 void cf_poll_req(bool new_value) {
347 cf_poll_req_ = new_value;
348 }
349
355 void privacy(bool new_value) {
356 privacy_ = new_value;
357 }
358
364 void short_preamble(bool new_value) {
365 short_preamble_ = new_value;
366 }
367
373 void pbcc(bool new_value) {
374 pbcc_ = new_value;
375 }
376
382 void channel_agility(bool new_value) {
383 channel_agility_ = new_value;
384 }
385
391 void spectrum_mgmt(bool new_value) {
392 spectrum_mgmt_ = new_value;
393 }
394
400 void qos(bool new_value) {
401 qos_ = new_value;
402 }
403
409 void sst(bool new_value) {
410 sst_ = new_value;
411 }
412
418 void apsd(bool new_value) {
419 apsd_ = new_value;
420 }
421
427 void radio_measurement(bool new_value) {
428 radio_measurement_ = new_value;
429 }
430
436 void dsss_ofdm(bool new_value) {
437 dsss_ofdm_ = new_value;
438 }
439
445 void delayed_block_ack(bool new_value) {
446 delayed_block_ack_ = new_value;
447 }
448
454 void immediate_block_ack(bool new_value) {
455 immediate_block_ack_ = new_value;
456 }
457 } TINS_END_PACK;
458
463 uint16_t dwell_time;
464 uint8_t hop_set, hop_pattern, hop_index;
465
467 : dwell_time(0), hop_set(0), hop_pattern(0), hop_index(0) {}
468
469 fh_params_set(uint16_t dwell_time,
470 uint8_t hop_set,
471 uint8_t hop_pattern,
472 uint8_t hop_index)
473 : dwell_time(dwell_time), hop_set(hop_set),
474 hop_pattern(hop_pattern), hop_index(hop_index) {}
475
476 static fh_params_set from_option(const option& opt);
477 };
478
483 uint8_t cfp_count, cfp_period;
484 uint16_t cfp_max_duration, cfp_dur_remaining;
485
487 : cfp_count(0), cfp_period(0), cfp_max_duration(0), cfp_dur_remaining(0) {}
488
489 cf_params_set(uint8_t cfp_count,
490 uint8_t cfp_period,
491 uint16_t cfp_max_duration,
492 uint16_t cfp_dur_remaining)
493 : cfp_count(cfp_count), cfp_period(cfp_period),
494 cfp_max_duration(cfp_max_duration),
495 cfp_dur_remaining(cfp_dur_remaining) {}
496
497 static cf_params_set from_option(const option& opt);
498 };
499
504 static const size_t minimum_size = address_type::address_size + sizeof(uint8_t) + 2 * sizeof(uint8_t);
505
506 address_type dfs_owner;
507 uint8_t recovery_interval;
508 channel_map_type channel_map;
509
510 ibss_dfs_params() : recovery_interval(0) {}
511
512 ibss_dfs_params(const address_type& addr,
513 uint8_t recovery_interval,
514 const channel_map_type& channel_map)
515 : dfs_owner(addr), recovery_interval(recovery_interval),
516 channel_map(channel_map) {}
517
518 static ibss_dfs_params from_option(const option& opt);
519 };
520
525 // String identifier: 3 bytes
526 static const size_t minimum_size = 3 + sizeof(uint8_t) * 3;
527
528 std::string country;
529 byte_array first_channel, number_channels, max_transmit_power;
530
531 country_params() {}
532
533 country_params(const std::string& country,
534 const byte_array& first,
535 const byte_array& number,
536 const byte_array& max)
537 : country(country), first_channel(first), number_channels(number),
538 max_transmit_power(max) {}
539
540 static country_params from_option(const option& opt);
541 };
542
547 static const size_t minimum_size = sizeof(uint8_t) * 4;
548
549 uint8_t flag, number_of_sets, modulus, offset;
550 byte_array random_table;
551
553 : flag(0), number_of_sets(0), modulus(0), offset(0) {}
554
555 fh_pattern_type(uint8_t flag,
556 uint8_t sets,
557 uint8_t modulus,
558 uint8_t offset,
559 const byte_array& table)
560 : flag(flag), number_of_sets(sets), modulus(modulus),
561 offset(offset), random_table(table) {}
562
563 static fh_pattern_type from_option(const option& opt);
564 };
565
570 uint8_t switch_mode, new_channel, switch_count;
571
573 : switch_mode(0), new_channel(0), switch_count(0) {}
574
575 channel_switch_type(uint8_t mode,
576 uint8_t channel,
577 uint8_t count)
578 : switch_mode(mode), new_channel(channel), switch_count(count) { }
579
580 static channel_switch_type from_option(const option& opt);
581 };
582
586 struct quiet_type {
587 uint8_t quiet_count, quiet_period;
588 uint16_t quiet_duration, quiet_offset;
589
590 quiet_type()
591 : quiet_count(0), quiet_period(0), quiet_duration(0), quiet_offset(0) {}
592
593 quiet_type(uint8_t count,
594 uint8_t period,
595 uint16_t duration,
596 uint16_t offset)
597 : quiet_count(count), quiet_period(period),
598 quiet_duration(duration), quiet_offset(offset) {}
599
600 static quiet_type from_option(const option& opt);
601 };
602
607 uint16_t station_count;
608 uint16_t available_capacity;
609 uint8_t channel_utilization;
610
612 : station_count(0), available_capacity(0), channel_utilization(0) {}
613
614 bss_load_type(uint16_t count, uint8_t utilization, uint16_t capacity)
615 : station_count(count), available_capacity(capacity),
616 channel_utilization(utilization) {}
617
618 static bss_load_type from_option(const option& opt);
619 };
620
624 struct tim_type {
625 uint8_t dtim_count, dtim_period, bitmap_control;
626 byte_array partial_virtual_bitmap;
627
628 tim_type()
629 : dtim_count(0), dtim_period(0), bitmap_control(0) {}
630
631 tim_type(uint8_t count,
632 uint8_t period,
633 uint8_t control,
634 const byte_array& bitmap)
635 : dtim_count(count), dtim_period(period), bitmap_control(control),
636 partial_virtual_bitmap(bitmap) {}
637
638 static tim_type from_option(const option& opt);
639 };
640
645 typedef HWAddress<3> oui_type;
646
647 oui_type oui;
648 byte_array data;
649
651 const byte_array& data = byte_array())
652 : oui(oui), data(data) { }
653
654 static vendor_specific_type from_bytes(const uint8_t* buffer, uint32_t sz);
655 };
656
660 typedef uint8_t qos_capability_type;
661
668 return ext_header_.addr2;
669 }
670
677 return ext_header_.addr3;
678 }
679
686 #if TINS_IS_LITTLE_ENDIAN
687 return ext_header_.frag_seq & 0xf;
688 #else
689 return (ext_header_.frag_seq >> 8) & 0xf;
690 #endif
691 }
692
699 #if TINS_IS_LITTLE_ENDIAN
700 return (ext_header_.frag_seq >> 4) & 0xfff;
701 #else
702 return (Endian::le_to_host<uint16_t>(ext_header_.frag_seq) >> 4) & 0xfff;
703 #endif
704 }
705
711 const address_type& addr4() const {
712 return addr4_;
713 }
714
720 void addr2(const address_type& new_addr2);
721
727 void addr3(const address_type& new_addr3);
728
734 void frag_num(small_uint<4> new_frag_num);
735
741 void seq_num(small_uint<12> new_seq_num);
742
748 void addr4(const address_type& new_addr4);
749
750 // Option setter helpers
751
757 void ssid(const std::string& new_ssid);
758
764 void rsn_information(const RSNInformation& info);
765
771 void supported_rates(const rates_type& new_rates);
772
778 void extended_supported_rates(const rates_type& new_rates);
779
785 void qos_capability(qos_capability_type new_qos_capability);
786
793 void power_capability(uint8_t min_power, uint8_t max_power);
794
804 void supported_channels(const channels_type& new_channels);
805
814 void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo);
815
821 void request_information(const request_info_type elements);
822
828 void fh_parameter_set(const fh_params_set& fh_params);
829
835 void ds_parameter_set(uint8_t current_channel);
836
842 void cf_parameter_set(const cf_params_set& params);
843
849 void ibss_parameter_set(uint16_t atim_window);
850
856 void ibss_dfs(const ibss_dfs_params& params);
857
863 void country(const country_params& params);
864
871 void fh_parameters(uint8_t prime_radix, uint8_t number_channels);
872
878 void fh_pattern_table(const fh_pattern_type& params);
879
885 void power_constraint(uint8_t local_power_constraint);
886
892 void channel_switch(const channel_switch_type& data);
893
899 void quiet(const quiet_type& data);
900
907 void tpc_report(uint8_t transmit_power, uint8_t link_margin);
908
914 void erp_information(uint8_t value);
915
921 void bss_load(const bss_load_type& data);
922
928 void tim(const tim_type& data);
929
935 void challenge_text(const std::string& text);
936
942 void vendor_specific(const vendor_specific_type& data);
943
944 // Option searching helpers
945
955 RSNInformation rsn_information() const;
956
965 std::string ssid() const;
966
975 rates_type supported_rates() const;
976
985 rates_type extended_supported_rates() const;
986
995 qos_capability_type qos_capability() const;
996
1005 std::pair<uint8_t, uint8_t> power_capability() const;
1006
1019 channels_type supported_channels() const;
1020
1029 request_info_type request_information() const;
1030
1039 fh_params_set fh_parameter_set() const;
1040
1049 uint8_t ds_parameter_set() const;
1050
1059 cf_params_set cf_parameter_set() const;
1060
1061
1070 uint16_t ibss_parameter_set() const;
1071
1080 ibss_dfs_params ibss_dfs() const;
1081
1090 country_params country() const;
1091
1100 std::pair<uint8_t, uint8_t> fh_parameters() const;
1101
1110 fh_pattern_type fh_pattern_table() const;
1111
1120 uint8_t power_constraint() const;
1121
1130 channel_switch_type channel_switch() const;
1131
1140 quiet_type quiet() const;
1141
1150 std::pair<uint8_t, uint8_t> tpc_report() const;
1151
1160 uint8_t erp_information() const;
1161
1170 bss_load_type bss_load() const;
1171
1180 tim_type tim() const;
1181
1190 std::string challenge_text() const;
1191
1200 vendor_specific_type vendor_specific() const;
1201
1202 // ************************
1203
1210 uint32_t header_size() const;
1211
1218 return pdu_flag;
1219 }
1220
1226 bool matches_flag(PDUType flag) const {
1227 return flag == pdu_flag || Dot11::matches_flag(flag);
1228 }
1229protected:
1230 TINS_BEGIN_PACK
1232 uint8_t addr2[address_type::address_size];
1233 uint8_t addr3[address_type::address_size];
1234 uint16_t frag_seq;
1235 } TINS_END_PACK;
1236
1237
1238 Dot11ManagementFrame(const address_type& dst_hw_addr = address_type(),
1239 const address_type& src_hw_addr = address_type());
1240
1255 Dot11ManagementFrame(const uint8_t* buffer, uint32_t total_sz);
1256
1257 void write_ext_header(Memory::OutputMemoryStream& stream);
1258
1259 uint32_t management_frame_size() {
1260 return Dot11ManagementFrame::header_size();
1261 }
1262private:
1263 static std::vector<uint8_t> serialize_rates(const rates_type& rates);
1264 static rates_type deserialize_rates(const option* option);
1265
1266 template<typename T>
1267 T search_and_convert(OptionTypes opt_type) const {
1268 const option* opt = search_option(opt_type);
1269 if (!opt) {
1270 throw option_not_found();
1271 }
1272 return opt->to<T>();
1273 }
1274
1275 dot11_extended_header ext_header_;
1276 address_type addr4_;
1277};
1278
1279} // namespace Tins
1280
1281#endif // TINS_DOT11_DOT11_MGMT_H
bool pbcc() const
Getter for the pbcc flag.
Definition dot11_mgmt.h:229
void delayed_block_ack(bool new_value)
Setter for the delayed_block_ack flag.
Definition dot11_mgmt.h:445
bool cf_poll_req() const
Getter for the cf_poll_req flag.
Definition dot11_mgmt.h:202
void ibss(bool new_value)
Setter for the ibss flag.
Definition dot11_mgmt.h:328
bool ibss() const
Getter for the ibss flag.
Definition dot11_mgmt.h:184
void spectrum_mgmt(bool new_value)
Setter for the spectrum_mgmt flag.
Definition dot11_mgmt.h:391
bool dsss_ofdm() const
Getter for the dsss_ofdm flag.
Definition dot11_mgmt.h:292
bool cf_poll() const
Getter for the cf_poll flag.
Definition dot11_mgmt.h:193
bool radio_measurement() const
Getter for the radio measurement flag.
Definition dot11_mgmt.h:283
void immediate_block_ack(bool new_value)
Setter for the immediate_block_ack flag.
Definition dot11_mgmt.h:454
bool channel_agility() const
Getter for the channel_agility flag.
Definition dot11_mgmt.h:238
bool ess() const
Getter for the ess flag.
Definition dot11_mgmt.h:175
bool immediate_block_ack() const
Getter for the immediate_block_ack flag.
Definition dot11_mgmt.h:310
void sst(bool new_value)
Setter for the sst flag.
Definition dot11_mgmt.h:409
void radio_measurement(bool new_value)
Setter for the radio measurement flag.
Definition dot11_mgmt.h:427
void cf_poll(bool new_value)
Setter for the cf_poll flag.
Definition dot11_mgmt.h:337
bool short_preamble() const
Getter for the short_preamble flag.
Definition dot11_mgmt.h:220
void privacy(bool new_value)
Setter for the privacy flag.
Definition dot11_mgmt.h:355
void channel_agility(bool new_value)
Setter for the channel_agility flag.
Definition dot11_mgmt.h:382
void cf_poll_req(bool new_value)
Setter for the cf_poll_req flag.
Definition dot11_mgmt.h:346
void apsd(bool new_value)
Setter for the apsd flag.
Definition dot11_mgmt.h:418
bool privacy() const
Getter for the privacy flag.
Definition dot11_mgmt.h:211
bool delayed_block_ack() const
Getter for the delayed_block_ack flag.
Definition dot11_mgmt.h:301
void ess(bool new_value)
Setter for the ess flag.
Definition dot11_mgmt.h:319
void short_preamble(bool new_value)
Setter for the short_preamble flag.
Definition dot11_mgmt.h:364
bool spectrum_mgmt() const
Getter for the spectrum_mgmt flag.
Definition dot11_mgmt.h:247
void dsss_ofdm(bool new_value)
Setter for the dsss_ofdm flag.
Definition dot11_mgmt.h:436
void qos(bool new_value)
Setter for the qos flag.
Definition dot11_mgmt.h:400
bool sst() const
Getter for the sst flag.
Definition dot11_mgmt.h:265
bool apsd() const
Getter for the apsd flag.
Definition dot11_mgmt.h:274
void pbcc(bool new_value)
Setter for the pbcc flag.
Definition dot11_mgmt.h:373
bool qos() const
Getter for the qos flag.
Definition dot11_mgmt.h:256
Base class for all management frames in the IEEE 802.11 protocol.
Definition dot11_mgmt.h:45
std::vector< float > rates_type
Definition dot11_mgmt.h:50
std::vector< std::pair< uint8_t, uint8_t > > channel_map_type
Definition dot11_mgmt.h:60
uint8_t qos_capability_type
Definition dot11_mgmt.h:660
ReasonCodes
Enum used in the reason code field.
Definition dot11_mgmt.h:78
std::vector< std::pair< uint8_t, uint8_t > > channels_type
Definition dot11_mgmt.h:55
const address_type & addr4() const
Getter for the fourth address.
Definition dot11_mgmt.h:711
void ssid(const std::string &new_ssid)
Helper method to set the SSID.
small_uint< 4 > frag_num() const
Getter for the fragment number.
Definition dot11_mgmt.h:685
address_type addr2() const
Getter for the second address.
Definition dot11_mgmt.h:667
small_uint< 12 > seq_num() const
Getter for the sequence number field.
Definition dot11_mgmt.h:698
std::vector< uint8_t > request_info_type
Definition dot11_mgmt.h:65
address_type addr3() const
Getter for the third address.
Definition dot11_mgmt.h:676
void challenge_text(const std::string &text)
Helper method to set the Challenge Text tagged option.
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_mgmt.h:1217
MapMask
Enum that represents the map field within a channels map field.
Definition dot11_mgmt.h:119
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_mgmt.h:1226
Class representing an 802.11 frame.
Definition dot11_base.h:54
Represents a PDU option field.
Definition rsn_information.h:43
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
Class that models the RSN information structure.
Definition rsn_information.h:47
Exception thrown when an option is not found.
Definition exceptions.h:56
Represents a field of n bits.
Definition small_uint.h:52
The Tins namespace.
Definition address_range.h:38
std::vector< uint8_t > byte_array
Definition pdu.h:50
Definition dot11_mgmt.h:586
Definition dot11_mgmt.h:624