|
1 /* |
|
2 * Copyright (c) 2001-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: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #if !defined(_GSMSIM_HEADER_H_) |
|
22 #define _GSMSIM_HEADER_H_ |
|
23 |
|
24 #include "eap_tools.h" |
|
25 #include "eap_header.h" |
|
26 #include "eap_type_gsmsim_types.h" |
|
27 |
|
28 /** @file */ |
|
29 |
|
30 const u32_t TRACE_FLAGS_GSMSIM_ERROR = eap_am_tools_c::eap_trace_mask_error; |
|
31 |
|
32 |
|
33 //---------------------------------------------------------------------------- |
|
34 |
|
35 |
|
36 /// This class defines the attribute payload header of GSMSIM EAP-type. |
|
37 /** |
|
38 * Here is a figure of attribute payload header of GSMSIM EAP-type. |
|
39 * Attribute payload data is (m_length*4)-sizeof(gsmsim_payload_AT_header_c) |
|
40 * data octets that follows gsmsim_payload_AT_header_c. |
|
41 * @code |
|
42 * 0 1 2 3 |
|
43 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
|
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
45 * | Type | Length | Value ... | |
|
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
47 * | Attribute payload data ... |
|
48 * +-+-+-+-+-+-+-+-+-+-+- |
|
49 * @endcode |
|
50 * |
|
51 */ |
|
52 class EAP_EXPORT gsmsim_payload_AT_header_c |
|
53 : public eap_general_header_base_c |
|
54 { |
|
55 private: |
|
56 //-------------------------------------------------- |
|
57 |
|
58 /// This is pointer to the tools class. |
|
59 abs_eap_am_tools_c * const m_am_tools; |
|
60 |
|
61 //-------------------------------------------------- |
|
62 protected: |
|
63 //-------------------------------------------------- |
|
64 |
|
65 enum offsets |
|
66 { |
|
67 m_type_offset = 0ul, |
|
68 m_length_offset = m_type_offset+sizeof(u8_t), |
|
69 m_reserved_offset = m_length_offset+sizeof(u8_t), |
|
70 m_data_offset = m_reserved_offset+sizeof(u16_t), |
|
71 }; |
|
72 |
|
73 //-------------------------------------------------- |
|
74 public: |
|
75 //-------------------------------------------------- |
|
76 |
|
77 // |
|
78 EAP_FUNC_IMPORT virtual ~gsmsim_payload_AT_header_c(); |
|
79 |
|
80 // |
|
81 EAP_FUNC_IMPORT gsmsim_payload_AT_header_c( |
|
82 abs_eap_am_tools_c * const tools, |
|
83 void * const header_buffer, |
|
84 const u32_t header_buffer_length); |
|
85 |
|
86 EAP_FUNC_IMPORT gsmsim_payload_AT_type_e get_current_payload() const; |
|
87 |
|
88 EAP_FUNC_IMPORT u16_t get_payload_length() const; |
|
89 |
|
90 EAP_FUNC_IMPORT u16_t get_reserved() const; |
|
91 |
|
92 EAP_FUNC_IMPORT u32_t get_data_length() const; |
|
93 |
|
94 EAP_FUNC_IMPORT static u16_t get_header_length(); |
|
95 |
|
96 EAP_FUNC_IMPORT static u16_t get_max_payload_data_length(); |
|
97 |
|
98 EAP_FUNC_IMPORT u8_t * get_data(const u32_t contignuous_bytes) const; |
|
99 |
|
100 EAP_FUNC_IMPORT u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const; |
|
101 |
|
102 EAP_FUNC_IMPORT u8_t * get_next_header() const; |
|
103 |
|
104 // Mostly this is zero. |
|
105 // With some attributes this is used for special purposes. |
|
106 EAP_FUNC_IMPORT void set_reserved(const u16_t reserved); |
|
107 |
|
108 EAP_FUNC_IMPORT void set_current_payload(const gsmsim_payload_AT_type_e p_current_payload); |
|
109 |
|
110 EAP_FUNC_IMPORT void set_data_length(const u16_t p_data_length); |
|
111 |
|
112 EAP_FUNC_IMPORT void reset_header(const u16_t data_length); |
|
113 |
|
114 EAP_FUNC_IMPORT static eap_const_string get_payload_AT_string(const gsmsim_payload_AT_type_e payload_type); |
|
115 |
|
116 EAP_FUNC_IMPORT eap_const_string get_payload_AT_string() const; |
|
117 |
|
118 EAP_FUNC_IMPORT eap_status_e check_header() const; |
|
119 |
|
120 // |
|
121 //-------------------------------------------------- |
|
122 }; // class gsmsim_payload_AT_header_c |
|
123 |
|
124 |
|
125 |
|
126 //---------------------------------------------------------------------------- |
|
127 |
|
128 |
|
129 /// This class defines header of GSMSIM EAP-type. |
|
130 /** |
|
131 * Here is a figure of header of GSMSIM EAP-type. |
|
132 * Subtype-Data is m_length-sizeof(gsmsim_header_c) data octets that follows gsmsim_header_c. |
|
133 * @code |
|
134 * 0 1 2 3 |
|
135 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
|
136 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
137 * | Code | Identifier | Length | |
|
138 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
139 * | Type=18 | Subtype | Reserved = 0 | |
|
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
141 * | Subtype-Data... |
|
142 * +-+-+-+-+-+-+-+-+-+-+- |
|
143 * @endcode |
|
144 * |
|
145 */ |
|
146 class gsmsim_header_c |
|
147 : public eap_header_base_c |
|
148 { |
|
149 private: |
|
150 //-------------------------------------------------- |
|
151 |
|
152 /// This is pointer to the tools class. |
|
153 abs_eap_am_tools_c * const m_am_tools; |
|
154 |
|
155 enum delta_offsets |
|
156 { |
|
157 m_subtype_delta_offset = 0ul, // This is offset from the end of the type field. NOTE type field could be extented 8 bytes in length. |
|
158 m_reserved_delta_offset = m_subtype_delta_offset+sizeof(u8_t), |
|
159 m_data_delta_offset = m_reserved_delta_offset+sizeof(u16_t), |
|
160 }; |
|
161 |
|
162 //-------------------------------------------------- |
|
163 public: |
|
164 //-------------------------------------------------- |
|
165 |
|
166 // |
|
167 EAP_FUNC_IMPORT virtual ~gsmsim_header_c(); |
|
168 |
|
169 // |
|
170 EAP_FUNC_IMPORT gsmsim_header_c( |
|
171 abs_eap_am_tools_c * const tools, |
|
172 u8_t * const header_buffer, |
|
173 const u32_t header_buffer_length); |
|
174 |
|
175 EAP_FUNC_IMPORT gsmsim_subtype_e get_subtype() const; |
|
176 |
|
177 EAP_FUNC_IMPORT u16_t get_data_length() const; |
|
178 |
|
179 /// This returns the length of EAP-header, EAP-type, subtype and reserved fields. |
|
180 EAP_FUNC_IMPORT u32_t get_header_length() const; |
|
181 |
|
182 EAP_FUNC_IMPORT u32_t get_sub_type_offset() const; |
|
183 |
|
184 EAP_FUNC_IMPORT u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const; |
|
185 |
|
186 EAP_FUNC_IMPORT u8_t * get_data(const u32_t contignuous_bytes) const; |
|
187 |
|
188 EAP_FUNC_IMPORT u16_t get_reserved() const; |
|
189 |
|
190 EAP_FUNC_IMPORT eap_status_e check_header() const; |
|
191 |
|
192 EAP_FUNC_IMPORT eap_const_string get_subtype_string() const; |
|
193 |
|
194 EAP_FUNC_IMPORT eap_const_string get_code_string() const; |
|
195 |
|
196 EAP_FUNC_IMPORT eap_const_string get_eap_type_string() const; |
|
197 |
|
198 EAP_FUNC_IMPORT void set_reserved(const u16_t reserved); |
|
199 |
|
200 EAP_FUNC_IMPORT void set_subtype(const gsmsim_subtype_e p_subtype); |
|
201 |
|
202 EAP_FUNC_IMPORT void set_data_length( |
|
203 const u32_t p_data_length, |
|
204 const bool expanded_type_when_true); |
|
205 |
|
206 EAP_FUNC_IMPORT void reset_header( |
|
207 const u32_t buffer_length, |
|
208 const bool expanded_type_when_true); |
|
209 |
|
210 // |
|
211 //-------------------------------------------------- |
|
212 }; // class gsmsim_header_c |
|
213 |
|
214 //-------------------------------------------------- |
|
215 |
|
216 /// Macro traces payload type and data. |
|
217 #define EAP_GSMSIM_TRACE_PAYLOAD(prefix, payload) \ |
|
218 { \ |
|
219 EAP_TRACE_DEBUG( \ |
|
220 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
221 (EAPL("%s (0x%08x): current payload 0x%04x=%s, data length 0x%04x.\n"), \ |
|
222 prefix, (payload)->get_header_buffer((payload)->get_payload_length()), (payload)->get_current_payload(), \ |
|
223 (payload)->get_payload_AT_string(), (payload)->get_data_length())); \ |
|
224 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, (EAPL("payload"), \ |
|
225 (payload)->get_header_buffer((payload)->get_payload_length()), \ |
|
226 (payload)->get_payload_length())); \ |
|
227 } |
|
228 |
|
229 //-------------------------------------------------- |
|
230 |
|
231 #endif //#if !defined(_GSMSIM_HEADER_H_) |
|
232 |
|
233 |
|
234 |
|
235 // End. |