libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
rsn_information.h
1 /*
2  * Copyright (c) 2016, 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_RSN_INFORMATION) && defined(TINS_HAVE_DOT11)
33 #define TINS_RSN_INFORMATION
34 
35 #include <stdint.h>
36 #include <vector>
37 #include "macros.h"
38 #include "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  };
58 
62  enum AKMSuites {
63  PMKSA = 0x01ac0f00,
64  PSK = 0x02ac0f00
65  };
66 
70  typedef std::vector<CypherSuites> cyphers_type;
71 
75  typedef std::vector<AKMSuites> akm_type;
76 
80  typedef std::vector<uint8_t> serialization_type;
81 
88 
95  RSNInformation(const serialization_type& buffer);
96 
106  RSNInformation(const uint8_t* buffer, uint32_t total_sz);
107 
113  static RSNInformation wpa2_psk();
114 
119  void add_pairwise_cypher(CypherSuites cypher);
120 
125  void add_akm_cypher(AKMSuites akm);
126 
131  void group_suite(CypherSuites group);
132 
137  void version(uint16_t ver);
138 
143  void capabilities(uint16_t cap);
144 
145  /* Getters */
146 
152  return static_cast<CypherSuites>(Endian::le_to_host<uint32_t>(group_suite_));
153  }
154 
159  uint16_t version() const {
160  return Endian::le_to_host(version_);
161  }
162 
167  uint16_t capabilities() const {
168  return Endian::le_to_host(capabilities_);
169  }
170 
176  return pairwise_cyphers_;
177  }
178 
183  const akm_type& akm_cyphers() const {
184  return akm_cyphers_;
185  }
186 
191  serialization_type serialize() const;
192 
196  static RSNInformation from_option(const PDUOption<uint8_t, Dot11>& opt);
197 private:
198  void init(const uint8_t* buffer, uint32_t total_sz);
199 
200  uint16_t version_, capabilities_;
201  CypherSuites group_suite_;
202  akm_type akm_cyphers_;
203  cyphers_type pairwise_cyphers_;
204 };
205 } // namespace Tins
206 
207 #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:80
const cyphers_type & pairwise_cyphers() const
Getter for the pairwise cypher suite list.
Definition: rsn_information.h:175
uint16_t capabilities() const
Getter for the capabilities field.
Definition: rsn_information.h:167
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:151
Represents a PDU option field.
Definition: pdu_option.h:320
std::vector< AKMSuites > akm_type
Definition: rsn_information.h:75
const akm_type & akm_cyphers() const
Getter for the akm suite list.
Definition: rsn_information.h:183
std::vector< CypherSuites > cyphers_type
Definition: rsn_information.h:70
AKMSuites
Enum that represents the different akm suites.
Definition: rsn_information.h:62
uint16_t version() const
Getter for the version field.
Definition: rsn_information.h:159