|
1 /* |
|
2 * Copyright (c) 2006-2009 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 for parsing RM Beacon Request IEs. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_frame_rm_ie_beacon_request.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 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_MIN_LENGTH = 18; |
|
26 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_REGULATORY_CLASS_OFFSET = 5; |
|
27 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_CHANNEL_NUMBER_OFFSET = 6; |
|
28 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_RANDOMIZATION_INTERVAL_OFFSET = 7; |
|
29 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_MEASUREMENT_DURATION_OFFSET = 9; |
|
30 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_MEASUREMENT_MODE_OFFSET = 11; |
|
31 const u8_t CORE_FRAME_RM_IE_BEACON_REQUEST_BSSID_OFFSET = 12; |
|
32 |
|
33 const u16_t CORE_FRAME_RM_IE_BEACON_REQUEST_IE_INDEX = 18; |
|
34 |
|
35 //#define WLAN_CORE_FRAME_RM_IE_BEACON_REQUEST_IE_DEBUG |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 core_frame_rm_ie_beacon_request_c* core_frame_rm_ie_beacon_request_c::instance( |
|
41 const core_frame_dot11_ie_c& ie ) |
|
42 { |
|
43 u16_t length = ie.data_length(); |
|
44 if ( length < CORE_FRAME_RM_IE_BEACON_REQUEST_MIN_LENGTH ) |
|
45 { |
|
46 DEBUG( "core_frame_rm_ie_beacon_request_c::instance() - not a valid IE, invalid length" ); |
|
47 |
|
48 return NULL; |
|
49 } |
|
50 |
|
51 core_frame_rm_ie_beacon_request_c* instance = new core_frame_rm_ie_beacon_request_c( |
|
52 length, |
|
53 ie.data(), |
|
54 0 ); |
|
55 |
|
56 if ( !instance ) |
|
57 { |
|
58 DEBUG( "core_frame_rm_ie_beacon_request_c::instance() - unable to create an instance" ); |
|
59 |
|
60 return NULL; |
|
61 } |
|
62 |
|
63 DEBUG1( "core_frame_rm_ie_beacon_request_c::instance() - Regulatory Class: 0x%02X", |
|
64 instance->regulatory_class() ); |
|
65 DEBUG1( "core_frame_rm_ie_beacon_request_c::instance() - Channel Number: 0x%02X", |
|
66 instance->channel_number() ); |
|
67 DEBUG1( "core_frame_rm_ie_beacon_request_c::instance() - Randomization Interval: 0x%04X (TU)", |
|
68 instance->randomization_interval() ); |
|
69 DEBUG1( "core_frame_rm_ie_beacon_request_c::instance() - Measurement Duration: 0x%04X (TU)", |
|
70 instance->measurement_duration() ); |
|
71 DEBUG1( "core_frame_rm_ie_beacon_request_c::instance() - Measurement Mode: 0x%02X", |
|
72 instance->measurement_mode() ); |
|
73 core_mac_address_s a = instance->bssid(); |
|
74 DEBUG6( "core_frame_rm_ie_beacon_request_c::instance() - BSSID: %02X:%02X:%02X:%02X:%02X:%02X", |
|
75 a.addr[0],a.addr[1],a.addr[2],a.addr[3],a.addr[4],a.addr[5] ); |
|
76 |
|
77 return instance; |
|
78 } |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 core_frame_rm_ie_beacon_request_c::~core_frame_rm_ie_beacon_request_c() |
|
84 { |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 u8_t core_frame_rm_ie_beacon_request_c::regulatory_class() const |
|
91 { |
|
92 return data_m[CORE_FRAME_RM_IE_BEACON_REQUEST_REGULATORY_CLASS_OFFSET]; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 u8_t core_frame_rm_ie_beacon_request_c::channel_number() const |
|
99 { |
|
100 return data_m[CORE_FRAME_RM_IE_BEACON_REQUEST_CHANNEL_NUMBER_OFFSET]; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 u16_t core_frame_rm_ie_beacon_request_c::randomization_interval() const |
|
107 { |
|
108 u16_t random_interval( 0 ); |
|
109 core_tools_c::copy( &random_interval, &data_m[CORE_FRAME_RM_IE_BEACON_REQUEST_RANDOMIZATION_INTERVAL_OFFSET], sizeof( random_interval ) ); |
|
110 |
|
111 return random_interval; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 u16_t core_frame_rm_ie_beacon_request_c::measurement_duration() const |
|
118 { |
|
119 u16_t measurement_duration( 0 ); |
|
120 core_tools_c::copy( &measurement_duration, &data_m[CORE_FRAME_RM_IE_BEACON_REQUEST_MEASUREMENT_DURATION_OFFSET], sizeof( measurement_duration ) ); |
|
121 |
|
122 return measurement_duration; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 u8_t core_frame_rm_ie_beacon_request_c::measurement_mode() const |
|
129 { |
|
130 return data_m[CORE_FRAME_RM_IE_BEACON_REQUEST_MEASUREMENT_MODE_OFFSET]; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 core_mac_address_s core_frame_rm_ie_beacon_request_c::bssid() const |
|
137 { |
|
138 core_mac_address_s mac_addr( ZERO_MAC_ADDR ); |
|
139 core_tools_c::copy( &mac_addr, &data_m[CORE_FRAME_RM_IE_BEACON_REQUEST_BSSID_OFFSET], sizeof( core_mac_address_s ) ); |
|
140 return mac_addr; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 u16_t core_frame_rm_ie_beacon_request_c::first_ie_offset() const |
|
147 { |
|
148 return CORE_FRAME_RM_IE_BEACON_REQUEST_IE_INDEX; |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 u16_t core_frame_rm_ie_beacon_request_c::payload_data_length() const |
|
155 { |
|
156 u16_t length( data_length_m - CORE_FRAME_RM_IE_BEACON_REQUEST_MIN_LENGTH ); |
|
157 |
|
158 return length; |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 const u8_t* core_frame_rm_ie_beacon_request_c::payload_data() const |
|
165 { |
|
166 u8_t* data( data_m + CORE_FRAME_RM_IE_BEACON_REQUEST_MIN_LENGTH ); |
|
167 |
|
168 return data; |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 core_frame_dot11_ie_c* core_frame_rm_ie_beacon_request_c::first_ie() |
|
175 { |
|
176 u16_t offset = first_ie_offset(); |
|
177 if( !offset ) |
|
178 { |
|
179 DEBUG( "core_frame_rm_ie_beacon_request_c::instance() - the frame has no IEs" ); |
|
180 return NULL; |
|
181 } |
|
182 |
|
183 current_ie_m = payload_data(); |
|
184 current_ie_max_length_m = payload_data_length(); |
|
185 |
|
186 return next_ie(); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 core_frame_dot11_ie_c* core_frame_rm_ie_beacon_request_c::next_ie() |
|
193 { |
|
194 |
|
195 #ifdef WLAN_CORE_FRAME_RM_IE_BEACON_REQUEST_IE_DEBUG |
|
196 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - real frame length: %u", |
|
197 data_length_m ); |
|
198 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - data_m is at %08X", |
|
199 data_m ); |
|
200 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - current_ie_m is at %08X", |
|
201 current_ie_m ); |
|
202 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - data end is at %08X", |
|
203 data_m + data_length_m ); |
|
204 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - maximum IE length is %u", |
|
205 current_ie_max_length_m ); |
|
206 #endif // WLAN_CORE_FRAME_RM_IE_BEACON_REQUEST_IE_DEBUG |
|
207 |
|
208 if( !current_ie_max_length_m ) |
|
209 { |
|
210 return NULL; |
|
211 } |
|
212 |
|
213 core_frame_dot11_ie_c* instance = |
|
214 core_frame_dot11_ie_c::instance( current_ie_max_length_m, current_ie_m ); |
|
215 if( !instance ) |
|
216 { |
|
217 DEBUG( "core_frame_rm_ie_beacon_request_c::next_ie() - unable to create IE parser" ); |
|
218 |
|
219 return NULL; |
|
220 } |
|
221 |
|
222 current_ie_m += instance->data_length(); |
|
223 |
|
224 #ifdef WLAN_CORE_FRAME_RM_IE_BEACON_REQUEST_IE_DEBUG |
|
225 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - IE ID is %u", |
|
226 instance->element_id() ); |
|
227 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - IE length is %u", |
|
228 instance->length() ); |
|
229 DEBUG1( "core_frame_rm_ie_beacon_request_c::next_ie() - IE data length is %u", |
|
230 instance->data_length() ); |
|
231 #endif // WLAN_CORE_FRAME_RM_IE_BEACON_REQUEST_IE_DEBUG |
|
232 |
|
233 ASSERT( current_ie_m <= data_m + data_length_m ); |
|
234 current_ie_max_length_m -= instance->data_length(); |
|
235 |
|
236 return instance; |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 core_frame_rm_ie_beacon_request_c::core_frame_rm_ie_beacon_request_c( |
|
243 u16_t data_length, |
|
244 const u8_t* data, |
|
245 u16_t max_data_length ) : |
|
246 core_frame_rm_ie_c( data_length, data, max_data_length ), |
|
247 current_ie_m( NULL ), |
|
248 current_ie_max_length_m( 0 ) |
|
249 { |
|
250 } |