libtins  4.0
rsn_information.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_RSN_INFORMATION) && defined(TINS_HAVE_DOT11)
33 #define TINS_RSN_INFORMATION
34 
35 #include <stdint.h>
36 #include <vector>
37 #include <tins/macros.h>
38 #include <tins/endianness.h>
39 
40 namespace Tins{
41 class Dot11;
42 template<typename T, typename U>
43 class PDUOption;
47 class TINS_API RSNInformation {
48 public:
52  enum CypherSuites {
53  WEP_40 = 0x01ac0f00,
54  TKIP = 0x02ac0f00,
55  CCMP = 0x04ac0f00,
56  WEP_104 = 0x05ac0f00,
57  BIP_CMAC_128 = 0x06ac0f00,
58  GCMP_128 = 0x08ac0f00,
59  GCMP_256 = 0x09ac0f00,
60  CCMP_256 = 0x10ac0f00,
61  BIP_GMAC_128 = 0x11ac0f00,
62  BIP_GMAC_256 = 0x12ac0f00,
63  BIP_CMAC_256 = 0x13ac0f00
64  };
65 
69  enum AKMSuites {
70  EAP = 0x01ac0f00,
71  PSK = 0x02ac0f00,
72  EAP_FT = 0x03ac0f00,
73  PSK_FT = 0x04ac0f00,
74  EAP_SHA256 = 0x05ac0f00,
75  PSK_SHA256 = 0x06ac0f00,
76  TDLS = 0x07ac0f00,
77  SAE_SHA256 = 0x08ac0f00,
78  SAE_FT = 0x09ac0f00,
79  APPEERKEY = 0x10ac0f00,
80  EAP_SHA256_FIPSB = 0x11ac0f00,
81  EAP_SHA384_FIPSB = 0x12ac0f00,
82  EAP_SHA384 = 0x13ac0f00
83  };
84 
88  typedef std::vector<CypherSuites> cyphers_type;
89 
93  typedef std::vector<AKMSuites> akm_type;
94 
98  typedef std::vector<uint8_t> serialization_type;
99 
105  RSNInformation();
106 
113  RSNInformation(const serialization_type& buffer);
114 
124  RSNInformation(const uint8_t* buffer, uint32_t total_sz);
125 
131  static RSNInformation wpa2_psk();
132 
137  void add_pairwise_cypher(CypherSuites cypher);
138 
143  void add_akm_cypher(AKMSuites akm);
144 
149  void group_suite(CypherSuites group);
150 
155  void version(uint16_t ver);
156 
161  void capabilities(uint16_t cap);
162 
163  /* Getters */
164 
170  return static_cast<CypherSuites>(Endian::le_to_host<uint32_t>(group_suite_));
171  }
172 
177  uint16_t version() const {
178  return Endian::le_to_host(version_);
179  }
180 
185  uint16_t capabilities() const {
186  return Endian::le_to_host(capabilities_);
187  }
188 
193  const cyphers_type& pairwise_cyphers() const {
194  return pairwise_cyphers_;
195  }
196 
201  const akm_type& akm_cyphers() const {
202  return akm_cyphers_;
203  }
204 
209  serialization_type serialize() const;
210 
214  static RSNInformation from_option(const PDUOption<uint8_t, Dot11>& opt);
215 private:
216  void init(const uint8_t* buffer, uint32_t total_sz);
217 
218  uint16_t version_, capabilities_;
219  CypherSuites group_suite_;
220  akm_type akm_cyphers_;
221  cyphers_type pairwise_cyphers_;
222 };
223 } // namespace Tins
224 
225 #endif // TINS_RSN_INFORMATION
Class that models the RSN information structure.
Definition: rsn_information.h:47
std::vector< uint8_t > serialization_type
Definition: rsn_information.h:98
const cyphers_type & pairwise_cyphers() const
Getter for the pairwise cypher suite list.
Definition: rsn_information.h:193
uint16_t capabilities() const
Getter for the capabilities field.
Definition: rsn_information.h:185
CypherSuites
Enum that represents the different cypher suites.
Definition: rsn_information.h:52
CypherSuites group_suite() const
Getter for the group suite field.
Definition: rsn_information.h:169
Represents a PDU option field.
Definition: pdu_option.h:201
std::vector< AKMSuites > akm_type
Definition: rsn_information.h:93
The Tins namespace.
Definition: address_range.h:38
const akm_type & akm_cyphers() const
Getter for the akm suite list.
Definition: rsn_information.h:201
std::vector< CypherSuites > cyphers_type
Definition: rsn_information.h:88
AKMSuites
Enum that represents the different akm suites.
Definition: rsn_information.h:69
uint16_t version() const
Getter for the version field.
Definition: rsn_information.h:177