|
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(_SIMPLE_CONFIG_TLV_HEADER_H_) |
|
22 #define _SIMPLE_CONFIG_TLV_HEADER_H_ |
|
23 |
|
24 #include "eap_tools.h" |
|
25 #include "eap_general_header_base.h" |
|
26 #include "simple_config_attribute_type.h" |
|
27 |
|
28 /** @file */ |
|
29 |
|
30 |
|
31 //---------------------------------------------------------------------------- |
|
32 |
|
33 |
|
34 /// This class defines header of Attribute-Value Pairs. |
|
35 /** |
|
36 * Here is a figure of header of Attribute-Value Pairs. |
|
37 * Value data follows simple_config_tlv_header_c. |
|
38 * @code |
|
39 * TLV-header: |
|
40 * 0 1 2 3 |
|
41 * 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 |
|
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
43 * | Attribute Type | Data Length | |
|
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
45 * | Data ... |
|
46 * +-+-+-+-+-+-+-+-+-+- |
|
47 * @endcode |
|
48 * |
|
49 * @code |
|
50 * The fields of this header are: |
|
51 * 16-bits Attribute Type This is a TLV type. |
|
52 * 16-bits Data Length; This is a length field, the length (in bytes) of the following Data. |
|
53 * @endcode |
|
54 */ |
|
55 class EAP_EXPORT simple_config_tlv_header_c |
|
56 : public eap_general_header_base_c |
|
57 { |
|
58 private: |
|
59 //-------------------------------------------------- |
|
60 |
|
61 /// This is pointer to the tools class. |
|
62 abs_eap_am_tools_c * const m_am_tools; |
|
63 |
|
64 //-------------------------------------------------- |
|
65 protected: |
|
66 //-------------------------------------------------- |
|
67 |
|
68 /// This is enumeration of offsets to data fields. |
|
69 enum offsets |
|
70 { |
|
71 m_tlv_type_offset = 0ul, ///< This is offset to fags and tlv type 16-bit field. |
|
72 m_length_offset = m_tlv_type_offset+sizeof(u16_t), ///< This is offset to length 16-bit field. |
|
73 m_data_offset = m_length_offset+sizeof(u16_t), ///< This is offset to data field. |
|
74 }; |
|
75 |
|
76 //-------------------------------------------------- |
|
77 public: |
|
78 //-------------------------------------------------- |
|
79 |
|
80 /** |
|
81 * The destructor of the simple_config_tlv_header_c class does nothing. |
|
82 */ |
|
83 virtual ~simple_config_tlv_header_c(); |
|
84 |
|
85 /** |
|
86 * The constructor of the simple_config_tlv_header_c class simply initializes the attributes. |
|
87 */ |
|
88 simple_config_tlv_header_c( |
|
89 abs_eap_am_tools_c * const tools); |
|
90 |
|
91 /** |
|
92 * The constructor of the simple_config_tlv_header_c class simply initializes the attributes. |
|
93 */ |
|
94 simple_config_tlv_header_c( |
|
95 abs_eap_am_tools_c * const tools, |
|
96 void * const header_begin, |
|
97 const u32_t header_buffer_length); |
|
98 |
|
99 /** |
|
100 * This function returns the TLV type flag. |
|
101 */ |
|
102 simple_config_Attribute_Type_e get_tlv_type() const; |
|
103 |
|
104 /** |
|
105 * This function returns the length of TLV (header+data). |
|
106 */ |
|
107 u32_t get_length() const; |
|
108 |
|
109 /** |
|
110 * This function returns the data length of TLV. |
|
111 */ |
|
112 u16_t get_data_length() const; |
|
113 |
|
114 /** |
|
115 * This function returns the header length of TLV. |
|
116 */ |
|
117 static u32_t get_header_length(); |
|
118 |
|
119 /** |
|
120 * This function returns pointer to the offset of data of TLV. |
|
121 * @param offset is the offset of queried data in bytes. |
|
122 * @param contignuous_bytes is the length of queried data in bytes. |
|
123 */ |
|
124 u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const; |
|
125 |
|
126 |
|
127 /** |
|
128 * This function returns pointer to the offset of data of TLV. |
|
129 * @param contignuous_bytes is the length of queried data in bytes. |
|
130 */ |
|
131 u8_t * get_data(const u32_t contignuous_bytes) const; |
|
132 |
|
133 |
|
134 /** |
|
135 * This function return pointer to the next TLV header in the same buffer. |
|
136 */ |
|
137 u8_t * get_next_header() const; |
|
138 |
|
139 |
|
140 /** |
|
141 * This function checks the header is valid. |
|
142 */ |
|
143 eap_status_e check_header() const; |
|
144 |
|
145 /** |
|
146 * This function returns debug strings of the TLV type. |
|
147 */ |
|
148 eap_const_string get_tlv_type_string() const; |
|
149 |
|
150 /** |
|
151 * This function sets the TLV type flag. |
|
152 */ |
|
153 void set_tlv_type(simple_config_Attribute_Type_e type); |
|
154 |
|
155 /** |
|
156 * This function sets the TLV data length. |
|
157 */ |
|
158 void set_data_length(const u16_t p_length); |
|
159 |
|
160 /** |
|
161 * This function resets the TLV header. |
|
162 */ |
|
163 void reset_header(const u16_t buffer_length); |
|
164 |
|
165 // |
|
166 //-------------------------------------------------- |
|
167 }; // class simple_config_tlv_header_c |
|
168 |
|
169 |
|
170 //-------------------------------------------------- |
|
171 |
|
172 /// Macro traces payload type and data. |
|
173 #define SIMPLE_CONFIG_TLV_TRACE_PAYLOAD(prefix, payload) \ |
|
174 { \ |
|
175 EAP_TRACE_DEBUG( \ |
|
176 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
177 (EAPL("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"))); \ |
|
178 EAP_TRACE_DEBUG( \ |
|
179 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
180 (EAPL("- %s (0x%08x): TLV type 0x%08x=%s, data length 0x%04x.\n"), \ |
|
181 prefix, (payload)->get_header_buffer((payload)->get_length()), \ |
|
182 (payload)->get_tlv_type(), \ |
|
183 (payload)->get_tlv_type_string(), (payload)->get_data_length())); \ |
|
184 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
185 (EAPL("- data"), (payload)->get_data((payload)->get_data_length()), \ |
|
186 (payload)->get_data_length())); \ |
|
187 EAP_TRACE_DEBUG( \ |
|
188 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
189 (EAPL("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n"))); \ |
|
190 } |
|
191 |
|
192 //-------------------------------------------------- |
|
193 |
|
194 #endif //#if !defined(_SIMPLE_CONFIG_TLV_HEADER_H_) |
|
195 |
|
196 |
|
197 |
|
198 // End. |