|
1 /* |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class parsing 802.11 IEs. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "genscaninfo.h" |
|
20 #include "core_frame_dot11_ie.h" |
|
21 #include "core_tools.h" |
|
22 #include "core_tools_parser.h" |
|
23 #include "am_debug.h" |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 const u8_t CORE_FRAME_DOT11_IE_LENGTH = 2; |
|
28 const u8_t CORE_FRAME_DOT11_IE_MIN_LENGTH_FIELD = 0; |
|
29 |
|
30 const u8_t CORE_FRAME_DOT11_IE_ELEMENT_INDEX = 0; |
|
31 const u8_t CORE_FRAME_DOT11_IE_LENGTH_INDEX = 1; |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 core_frame_dot11_ie_c* core_frame_dot11_ie_c::instance( |
|
37 u16_t data_length, |
|
38 const u8_t* data, |
|
39 bool_t is_copied ) |
|
40 { |
|
41 if ( data_length < CORE_FRAME_DOT11_IE_LENGTH ) |
|
42 { |
|
43 DEBUG2( "core_frame_dot11_ie_c::instance() - IE data length is too short, actual length %u, minimum length %u", |
|
44 data_length, CORE_FRAME_DOT11_IE_LENGTH ); |
|
45 |
|
46 return NULL; |
|
47 } |
|
48 |
|
49 u8_t* buffer = const_cast<u8_t*>( data ); |
|
50 u16_t buffer_length( 0 ); |
|
51 |
|
52 if ( is_copied ) |
|
53 { |
|
54 DEBUG( "core_frame_dot11_ie_c::instance() - copying IE data" ); |
|
55 |
|
56 buffer_length = data_length; |
|
57 buffer = new u8_t[buffer_length]; |
|
58 |
|
59 if ( !buffer ) |
|
60 { |
|
61 DEBUG( "core_frame_dot11_ie_c::instance() - not able to allocate buffer for copying" ); |
|
62 |
|
63 return NULL; |
|
64 } |
|
65 |
|
66 core_tools_c::copy( |
|
67 buffer, |
|
68 data, |
|
69 buffer_length ); |
|
70 } |
|
71 |
|
72 core_frame_dot11_ie_c* instance = new core_frame_dot11_ie_c( |
|
73 data_length, |
|
74 buffer, |
|
75 buffer_length ); |
|
76 if ( !instance ) |
|
77 { |
|
78 DEBUG( "core_frame_dot11_ie_c::instance() - unable to create an instance" ); |
|
79 |
|
80 if ( is_copied ) |
|
81 { |
|
82 delete[] buffer; |
|
83 } |
|
84 |
|
85 return NULL; |
|
86 } |
|
87 |
|
88 if ( instance->length() + CORE_FRAME_DOT11_IE_HEADER_LENGTH > data_length ) |
|
89 { |
|
90 DEBUG( "core_frame_dot11_ie_c::instance() - length field is too big" ); |
|
91 DEBUG2( "core_frame_dot11_ie_c::instance() - IE size is %u, IE length field is %u", |
|
92 data_length, instance->length() ); |
|
93 delete instance; |
|
94 |
|
95 return NULL; |
|
96 } |
|
97 |
|
98 return instance; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 core_frame_dot11_ie_c::~core_frame_dot11_ie_c() |
|
105 { |
|
106 /** |
|
107 * If maximum IE length has been defined, we have allocated |
|
108 * the frame buffer ourselves. |
|
109 */ |
|
110 if ( max_data_length_m ) |
|
111 { |
|
112 delete[] data_m; |
|
113 } |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 u8_t core_frame_dot11_ie_c::element_id() const |
|
120 { |
|
121 return data_m[CORE_FRAME_DOT11_IE_ELEMENT_INDEX]; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 u8_t core_frame_dot11_ie_c::length() const |
|
128 { |
|
129 return data_m[CORE_FRAME_DOT11_IE_LENGTH_INDEX]; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 u16_t core_frame_dot11_ie_c::data_length() const |
|
136 { |
|
137 return length() + CORE_FRAME_DOT11_IE_HEADER_LENGTH; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 const u8_t* core_frame_dot11_ie_c::data() const |
|
144 { |
|
145 return data_m; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void core_frame_dot11_ie_c::generate( |
|
152 u8_t element_id ) |
|
153 { |
|
154 ASSERT( !data_length_m ); |
|
155 ASSERT( max_data_length_m ); |
|
156 |
|
157 data_length_m = 0; |
|
158 |
|
159 // Element ID |
|
160 data_m[data_length_m++] = element_id; |
|
161 |
|
162 // Length |
|
163 data_m[data_length_m++] = CORE_FRAME_DOT11_IE_MIN_LENGTH_FIELD; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void core_frame_dot11_ie_c::set_length( |
|
170 u8_t length ) |
|
171 { |
|
172 data_m[CORE_FRAME_DOT11_IE_LENGTH_INDEX] = length - CORE_FRAME_DOT11_IE_HEADER_LENGTH; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 core_frame_dot11_ie_c::core_frame_dot11_ie_c( |
|
179 u16_t data_length, |
|
180 const u8_t* data, |
|
181 u16_t max_data_length ) : |
|
182 data_length_m( data_length ), |
|
183 data_m( NULL ), |
|
184 max_data_length_m( max_data_length ) |
|
185 { |
|
186 /** |
|
187 * The reason the const is discarded is that the same pointer |
|
188 * is used when we have allocated the frame buffer ourselves. |
|
189 */ |
|
190 data_m = const_cast<u8_t*>( data ); |
|
191 } |