libtins  4.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
dot11_beacon.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 "../config.h"
31 
32 #if !defined(TINS_DOT11_DOT11_BEACON_H) && defined(TINS_HAVE_DOT11)
33 #define TINS_DOT11_DOT11_BEACON_H
34 
35 #include "../dot11/dot11_mgmt.h"
36 #include "../macros.h"
37 
38 namespace Tins {
39 
44 class TINS_API Dot11Beacon : public Dot11ManagementFrame {
45 public:
49  static const PDU::PDUType pdu_flag = PDU::DOT11_BEACON;
50 
60  Dot11Beacon(const address_type& dst_hw_addr = address_type(),
61  const address_type& src_hw_addr = address_type());
62 
77  Dot11Beacon(const uint8_t* buffer, uint32_t total_sz);
78 
84  uint64_t timestamp() const {
85  return Endian::le_to_host(body_.timestamp);
86  }
87 
93  uint16_t interval() const {
94  return Endian::le_to_host(body_.interval);
95  }
96 
104  return body_.capability;
105  }
106 
114  return body_.capability;
115  }
116 
122  void timestamp(uint64_t new_timestamp);
123 
129  void interval(uint16_t new_interval);
130 
137  uint32_t header_size() const;
138 
144  bool matches_flag(PDUType flag) const {
145  return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
146  }
147 
153  Dot11Beacon* clone() const {
154  return new Dot11Beacon(*this);
155  }
156 
161  PDUType pdu_type() const {
162  return pdu_flag;
163  }
164 private:
165  TINS_BEGIN_PACK
166  struct dot11_beacon_body {
167  uint64_t timestamp;
168  uint16_t interval;
169  capability_information capability;
170  } TINS_END_PACK;
171 
172  void write_fixed_parameters(Memory::OutputMemoryStream& stream);
173 
174  dot11_beacon_body body_;
175 };
176 
177 } // namespace Tins
178 
179 #endif // TINS_DOT11_DOT11_BEACON_H
capability_information & capabilities()
Getter for the Capabilities Information.
Definition: dot11_beacon.h:113
PDUType
Enum which identifies each type of PDU.
Definition: pdu.h:127
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition: dot11_mgmt.h:1226
Represents an IEEE 802.11 Beacon.
Definition: dot11_beacon.h:44
PDUType pdu_type() const
Getter for the PDU's type.
Definition: dot11_beacon.h:161
bool matches_flag(PDUType flag) const
Check whether this PDU matches the specified flag.
Definition: dot11_beacon.h:144
Base class for all management frames in the IEEE 802.11 protocol.
Definition: dot11_mgmt.h:45
uint16_t interval() const
Getter for the interval field.
Definition: dot11_beacon.h:93
uint64_t timestamp() const
Getter for the timestamp field.
Definition: dot11_beacon.h:84
Dot11Beacon * clone() const
Clones this PDU.
Definition: dot11_beacon.h:153
const capability_information & capabilities() const
Getter for the Capabilities Information structure.
Definition: dot11_beacon.h:103