|
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 and generating 802.11 action frames for Neighbor Reports. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_frame_action_nr.h" |
|
20 #include "core_frame_nr_ie.h" |
|
21 #include "core_tools.h" |
|
22 #include "am_debug.h" |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 const u16_t CORE_FRAME_ACTION_NR_IE_INDEX = 3; |
|
27 const u16_t CORE_FRAME_ACTION_NR_MIN_LENGTH = 28; |
|
28 const u16_t CORE_FRAME_ACTION_NR_LENGTH = 61; |
|
29 const u16_t CORE_FRAME_ACTION_NR_TOKEN_INDEX = 26; |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 core_frame_action_nr_c* core_frame_action_nr_c::instance( |
|
35 const core_frame_action_c& frame, |
|
36 bool_t is_copied ) |
|
37 { |
|
38 if ( frame.data_length() < CORE_FRAME_ACTION_NR_MIN_LENGTH ) |
|
39 { |
|
40 DEBUG( "core_frame_action_nr_c::instance() - not a valid 802.11 frame, frame is too short" ); |
|
41 |
|
42 return NULL; |
|
43 } |
|
44 |
|
45 u8_t* buffer = const_cast<u8_t*>( frame.data() ); |
|
46 u16_t buffer_length( 0 ); |
|
47 |
|
48 if( is_copied ) |
|
49 { |
|
50 buffer_length = frame.data_length(); |
|
51 buffer = new u8_t[buffer_length]; |
|
52 |
|
53 if( !buffer ) |
|
54 { |
|
55 DEBUG( "core_frame_action_nr_c::instance() - not able to allocate buffer for copying" ); |
|
56 |
|
57 return NULL; |
|
58 } |
|
59 |
|
60 core_tools_c::copy( buffer, frame.data(), buffer_length ); |
|
61 } |
|
62 |
|
63 core_frame_action_nr_c* instance = new core_frame_action_nr_c( |
|
64 buffer_length, |
|
65 buffer, |
|
66 buffer_length ); |
|
67 |
|
68 if ( !instance ) |
|
69 { |
|
70 DEBUG( "core_frame_action_nr_c::instance() - unable to create an instance" ); |
|
71 |
|
72 return NULL; |
|
73 } |
|
74 |
|
75 return instance; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 core_frame_action_nr_c* core_frame_action_nr_c::instance( |
|
82 u16_t duration, |
|
83 const core_mac_address_s& destination, |
|
84 const core_mac_address_s& source, |
|
85 const core_mac_address_s& bssid, |
|
86 u16_t sequence_control, |
|
87 u8_t action_type, |
|
88 u8_t dialog_token, |
|
89 const core_frame_nr_ie_c* nr_ie ) |
|
90 { |
|
91 const u8_t max_data_length = CORE_FRAME_ACTION_NR_LENGTH; |
|
92 |
|
93 u8_t* buffer = new u8_t[max_data_length]; |
|
94 if ( !buffer ) |
|
95 { |
|
96 DEBUG( "core_frame_action_nr_c::instance() - unable create the internal buffer" ); |
|
97 return NULL; |
|
98 } |
|
99 |
|
100 core_frame_action_nr_c* instance = |
|
101 new core_frame_action_nr_c( 0, buffer, max_data_length ); |
|
102 if ( !instance ) |
|
103 { |
|
104 DEBUG( "core_frame_action_nr_c::instance() - unable to create an instance" ); |
|
105 delete[] buffer; |
|
106 buffer = NULL; |
|
107 |
|
108 return NULL; |
|
109 } |
|
110 |
|
111 instance->generate( |
|
112 duration, |
|
113 destination, |
|
114 source, |
|
115 bssid, |
|
116 sequence_control, |
|
117 action_type, |
|
118 dialog_token, |
|
119 nr_ie ); |
|
120 |
|
121 return instance; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 core_frame_action_nr_c::~core_frame_action_nr_c() |
|
128 { |
|
129 DEBUG1( "core_frame_action_nr_c::~core_frame_action_nr_c() @ 0x%08X", this ); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 u8_t core_frame_action_nr_c::dialog_token() const |
|
136 { |
|
137 return data_m[CORE_FRAME_ACTION_NR_TOKEN_INDEX]; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 u16_t core_frame_action_nr_c::first_ie_offset() const |
|
144 { |
|
145 return CORE_FRAME_ACTION_NR_IE_INDEX; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void core_frame_action_nr_c::generate( |
|
152 u16_t duration, |
|
153 const core_mac_address_s& destination, |
|
154 const core_mac_address_s& source, |
|
155 const core_mac_address_s& bssid, |
|
156 u16_t sequence_control, |
|
157 u8_t action_type, |
|
158 u8_t dialog_token, |
|
159 const core_frame_nr_ie_c* nr_ie ) |
|
160 { |
|
161 ASSERT( !data_length_m ); |
|
162 ASSERT( max_data_length_m ); |
|
163 ASSERT( nr_ie ); |
|
164 |
|
165 core_frame_action_c::generate( |
|
166 duration, |
|
167 destination, |
|
168 source, |
|
169 bssid, |
|
170 sequence_control, |
|
171 core_frame_action_c::core_dot11_action_category_rm ); |
|
172 |
|
173 // Action Type |
|
174 data_m[data_length_m++] = action_type; |
|
175 |
|
176 // Dialog Token |
|
177 data_m[data_length_m++] = dialog_token; |
|
178 |
|
179 // IE |
|
180 core_tools_c::copy( |
|
181 &data_m[data_length_m], |
|
182 nr_ie->data(), |
|
183 nr_ie->data_length() ); |
|
184 data_length_m += nr_ie->data_length(); |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 core_frame_action_nr_c::core_frame_action_nr_c( |
|
191 u16_t data_length, |
|
192 const u8_t* data, |
|
193 u16_t max_data_length ) : |
|
194 core_frame_action_c( data_length, data, max_data_length ) |
|
195 { |
|
196 } |