libtins 4.5
Loading...
Searching...
No Matches
dot11_control.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_CONTROL_H) && defined(TINS_HAVE_DOT11)
33
34#define TINS_DOT11_DOT11_CONTROL_H
35
36#include <tins/dot11/dot11_base.h>
37#include <tins/macros.h>
38
39namespace Tins {
43class TINS_API Dot11Control : public Dot11 {
44public:
48 static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL;
49
58 Dot11Control(const address_type& dst_addr = address_type());
59
74 Dot11Control(const uint8_t* buffer, uint32_t total_sz);
75
80 PDUType pdu_type() const {
81 return pdu_flag;
82 }
83
89 bool matches_flag(PDUType flag) const {
90 return flag == pdu_flag || Dot11::matches_flag(flag);
91 }
92};
93
98class TINS_API Dot11ControlTA : public Dot11Control {
99public:
103 static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL_TA;
104
109 return taddr_;
110 }
111
116 void target_addr(const address_type& addr);
117
123 bool matches_flag(PDUType flag) const {
124 return flag == pdu_flag || Dot11::matches_flag(flag);
125 }
126protected:
136 Dot11ControlTA(const address_type& dst_addr = address_type(),
137 const address_type& target_addr = address_type());
138
153 Dot11ControlTA(const uint8_t* buffer, uint32_t total_sz);
154
161 uint32_t header_size() const;
162protected:
166 uint32_t controlta_size() const {
167 return static_cast<uint32_t>(taddr_.size() + sizeof(dot11_header));
168 }
169
170 void write_ext_header(Memory::OutputMemoryStream& stream);
171private:
172
173 address_type taddr_;
174};
175
179class TINS_API Dot11RTS : public Dot11ControlTA {
180public:
184 static const PDU::PDUType pdu_flag = PDU::DOT11_RTS;
185
195 Dot11RTS(const address_type& dst_addr = address_type(),
196 const address_type& target_addr = address_type());
197
211 Dot11RTS(const uint8_t* buffer, uint32_t total_sz);
212
218 Dot11RTS* clone() const {
219 return new Dot11RTS(*this);
220 }
221
227 return pdu_flag;
228 }
229
235 bool matches_flag(PDUType flag) const {
236 return flag == pdu_flag || Dot11Control::matches_flag(flag);
237 }
238};
239
240class TINS_API Dot11PSPoll : public Dot11ControlTA {
241public:
245 static const PDU::PDUType pdu_flag = PDU::DOT11_PS_POLL;
246
256 Dot11PSPoll(const address_type& dst_addr = address_type(),
257 const address_type& target_addr = address_type());
258
273 Dot11PSPoll(const uint8_t* buffer, uint32_t total_sz);
274
281 return new Dot11PSPoll(*this);
282 }
283
289 return pdu_flag;
290 }
291
297 bool matches_flag(PDUType flag) const {
298 return flag == pdu_flag || Dot11Control::matches_flag(flag);
299 }
300};
301
302class TINS_API Dot11CFEnd : public Dot11ControlTA {
303public:
307 static const PDU::PDUType pdu_flag = PDU::DOT11_CF_END;
308
318 Dot11CFEnd(const address_type& dst_addr = address_type(),
319 const address_type& target_addr = address_type());
320
335 Dot11CFEnd(const uint8_t* buffer, uint32_t total_sz);
336
342 Dot11CFEnd* clone() const {
343 return new Dot11CFEnd(*this);
344 }
345
351 return pdu_flag;
352 }
353
359 bool matches_flag(PDUType flag) const {
360 return flag == pdu_flag || Dot11Control::matches_flag(flag);
361 }
362};
363
364class TINS_API Dot11EndCFAck : public Dot11ControlTA {
365public:
369 static const PDU::PDUType pdu_flag = PDU::DOT11_END_CF_ACK;
370
380 Dot11EndCFAck(const address_type& dst_addr = address_type(),
381 const address_type& target_addr = address_type());
382
397 Dot11EndCFAck(const uint8_t* buffer, uint32_t total_sz);
398
405 return new Dot11EndCFAck(*this);
406 }
407
413 return pdu_flag;
414 }
415
421 bool matches_flag(PDUType flag) const {
422 return flag == pdu_flag || Dot11Control::matches_flag(flag);
423 }
424};
425
426class TINS_API Dot11Ack : public Dot11Control {
427public:
431 static const PDU::PDUType pdu_flag = PDU::DOT11_ACK;
432
441 Dot11Ack(const address_type& dst_addr = address_type());
442
457 Dot11Ack(const uint8_t* buffer, uint32_t total_sz);
458
464 Dot11Ack* clone() const {
465 return new Dot11Ack(*this);
466 }
467
473 return pdu_flag;
474 }
475
481 bool matches_flag(PDUType flag) const {
482 return flag == pdu_flag || Dot11Control::matches_flag(flag);
483 }
484};
485
489class TINS_API Dot11BlockAckRequest : public Dot11ControlTA {
490public:
494 static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK_REQ;
495
506 const address_type& target_addr = address_type());
507
522 Dot11BlockAckRequest(const uint8_t* buffer, uint32_t total_sz);
523
524 /* Getter */
525
531 #if TINS_IS_LITTLE_ENDIAN
532 return bar_control_ & 0xf;
533 #else
534 return (bar_control_ >> 8) & 0xf;
535 #endif
536 }
537
543 #if TINS_IS_LITTLE_ENDIAN
544 return (start_sequence_ >> 4) & 0xfff;
545 #else
546 return (Endian::le_to_host<uint16_t>(start_sequence_) >> 4) & 0xfff;
547 #endif
548 }
549
555 #if TINS_IS_LITTLE_ENDIAN
556 return start_sequence_ & 0xf;
557 #else
558 return (start_sequence_ >> 8) & 0xf;
559 #endif
560 }
561
568 uint32_t header_size() const;
569
570 /* Setter */
571
576 void bar_control(small_uint<4> bar);
577
582 void start_sequence(small_uint<12> seq);
583
588 void fragment_number(small_uint<4> frag);
589
596 return new Dot11BlockAckRequest(*this);
597 }
598
604 return pdu_flag;
605 }
606
612 bool matches_flag(PDUType flag) const {
613 return flag == pdu_flag || Dot11Control::matches_flag(flag);
614 }
615protected:
616 void write_ext_header(Memory::OutputMemoryStream& stream);
617private:
618 uint16_t bar_control_;
619 uint16_t start_sequence_;
620};
621
625class TINS_API Dot11BlockAck : public Dot11ControlTA {
626public:
630 static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK;
631
635 static const size_t bitmap_size = 8;
636
646 Dot11BlockAck(const address_type& dst_addr = address_type(),
647 const address_type& target_addr = address_type());
648
663 Dot11BlockAck(const uint8_t* buffer, uint32_t total_sz);
664
665 /* Getters */
666
672 #if TINS_IS_LITTLE_ENDIAN
673 return bar_control_ & 0xf;
674 #else
675 return (bar_control_ >> 8) & 0xf;
676 #endif
677 }
678
684 #if TINS_IS_LITTLE_ENDIAN
685 return (start_sequence_ >> 4) & 0xfff;
686 #else
687 return (Endian::le_to_host<uint16_t>(start_sequence_) >> 4) & 0xfff;
688 #endif
689 }
690
696 #if TINS_IS_LITTLE_ENDIAN
697 return start_sequence_ & 0xf;
698 #else
699 return (start_sequence_ >> 8) & 0xf;
700 #endif
701 }
702
709 uint32_t header_size() const;
710
711 /* Setters */
712
717 void bar_control(small_uint<4> bar);
718
723 void start_sequence(small_uint<12> seq);
724
729 void fragment_number(small_uint<4> frag);
730
738 const uint8_t* bitmap() const {
739 return bitmap_;
740 }
741
746 void bitmap(const uint8_t* bit);
747
753 return pdu_flag;
754 }
755
761 bool matches_flag(PDUType flag) const {
762 return flag == pdu_flag || Dot11Control::matches_flag(flag);
763 }
764
771 return new Dot11BlockAck(*this);
772 }
773private:
774 void write_ext_header(Memory::OutputMemoryStream& stream);
775
776 uint16_t bar_control_, start_sequence_;
777 uint8_t bitmap_[bitmap_size];
778};
779
780} // namespace Tins
781
782#endif // TINS_DOT11_DOT11_CONTROL_H
Definition dot11_control.h:426
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:481
Dot11Ack * clone() const
Clones this PDU.
Definition dot11_control.h:464
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:472
Class that represents an 802.11 Block Ack Request PDU.
Definition dot11_control.h:489
Dot11BlockAckRequest * clone() const
Clones this PDU.
Definition dot11_control.h:595
small_uint< 4 > bar_control() const
Getter for the bar control field.
Definition dot11_control.h:530
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:612
small_uint< 4 > fragment_number() const
Getter for the fragment number field.
Definition dot11_control.h:554
small_uint< 12 > start_sequence() const
Getter for the start sequence field.
Definition dot11_control.h:542
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:603
Class that represents an 802.11 block ack frame.
Definition dot11_control.h:625
const uint8_t * bitmap() const
Getter for the bitmap field.
Definition dot11_control.h:738
small_uint< 4 > bar_control() const
Getter for the bar control field.
Definition dot11_control.h:671
small_uint< 12 > start_sequence() const
Getter for the start sequence field.
Definition dot11_control.h:683
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:761
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:752
small_uint< 4 > fragment_number() const
Getter for the fragment number field.
Definition dot11_control.h:695
Dot11BlockAck * clone() const
Clones this PDU.
Definition dot11_control.h:770
Definition dot11_control.h:302
Dot11CFEnd * clone() const
Clones this PDU.
Definition dot11_control.h:342
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:350
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:359
Class that represents an abstraction of the 802.11 control frames that contain a target address.
Definition dot11_control.h:98
uint32_t controlta_size() const
Getter for the control ta additional fields size.
Definition dot11_control.h:166
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:123
address_type target_addr() const
Getter for the target address field.
Definition dot11_control.h:108
Represents an IEEE 802.11 control frame.
Definition dot11_control.h:43
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:89
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:80
Definition dot11_control.h:364
Dot11EndCFAck * clone() const
Clones this PDU.
Definition dot11_control.h:404
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:421
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:412
Definition dot11_control.h:240
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:288
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:297
Dot11PSPoll * clone() const
Clones this PDU.
Definition dot11_control.h:280
IEEE 802.11 RTS frame.
Definition dot11_control.h:179
Dot11RTS * clone() const
Clones this PDU.
Definition dot11_control.h:218
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition dot11_control.h:235
PDUType pdu_type() const
Getter for the PDU's type.
Definition dot11_control.h:226
Class representing an 802.11 frame.
Definition dot11_base.h:54
PDUType
Enum which identifies each type of PDU.
Definition pdu.h:127
Represents a field of n bits.
Definition small_uint.h:52
The Tins namespace.
Definition address_range.h:38
Definition dot11_base.h:674