|
1 /* |
|
2 * ============================================================================ |
|
3 * Name : ./accesssec/eapol/eapol_framework/wapi_common/include/ec_cs_tlv_header.h |
|
4 * Part of : WAPI / WAPI *** Info from the SWAD |
|
5 * Description : WAPI authentication |
|
6 * Version : %version: 12 % << Don't touch! Updated by Synergy at check-out. |
|
7 * |
|
8 * Copyright © 2001-2009 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 * Template version: 4.2 |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #if !defined(_EC_CS_TLV_HEADER_H_) |
|
23 #define _EC_CS_TLV_HEADER_H_ |
|
24 |
|
25 #if defined(USE_WAPI_CORE) |
|
26 |
|
27 #include "eap_tools.h" |
|
28 #include "eap_general_header_base.h" |
|
29 #include "ec_cs_types.h" |
|
30 |
|
31 /** @file */ |
|
32 |
|
33 |
|
34 //---------------------------------------------------------------------------- |
|
35 |
|
36 |
|
37 /// This class defines header of Attribute-Value Pairs. |
|
38 /** |
|
39 * Here is a figure of header of Attribute-Value Pairs. |
|
40 * Value data follows ec_cs_tlv_header_c. |
|
41 * @code |
|
42 * TLV-header: |
|
43 * 0 1 2 3 |
|
44 * 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 |
|
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
46 * | Type | Length | |
|
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
48 * | Value... |
|
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
50 * @endcode |
|
51 * |
|
52 * @code |
|
53 * The fields of this header are: |
|
54 * 16-bits Type; This is a TLV type. |
|
55 * 16-bits value length (Length); This is a length field, the length (in bytes) of the following value. |
|
56 * @endcode |
|
57 * |
|
58 * For details see <a href="../../../internal/doc/WAPI/WAPI_design.doc">WAPI_design.doc</a>. |
|
59 */ |
|
60 class EAP_EXPORT ec_cs_tlv_header_c |
|
61 : public eap_general_header_base_c |
|
62 { |
|
63 private: |
|
64 //-------------------------------------------------- |
|
65 |
|
66 /// This is pointer to the tools class. |
|
67 abs_eap_am_tools_c * const m_am_tools; |
|
68 |
|
69 //-------------------------------------------------- |
|
70 protected: |
|
71 //-------------------------------------------------- |
|
72 |
|
73 /// This is enumeration of offsets to data fields. |
|
74 enum sizes |
|
75 { |
|
76 m_type_size = sizeof(u16_t), ///< This is size of type 16-bit field. |
|
77 m_length_size = sizeof(u16_t), ///< This is size of length 16-bit field. |
|
78 }; |
|
79 |
|
80 /// This is enumeration of offsets to data fields. |
|
81 enum offsets |
|
82 { |
|
83 m_type_offset = 0ul, ///< This is offset to type 16-bit field. |
|
84 m_length_offset = m_type_offset+m_type_size, ///< This is offset to length 16-bit field. |
|
85 m_data_offset = m_length_offset+m_length_size, ///< This is offset to data field. |
|
86 }; |
|
87 |
|
88 //-------------------------------------------------- |
|
89 public: |
|
90 //-------------------------------------------------- |
|
91 |
|
92 /** |
|
93 * The destructor of the ec_cs_tlv_header_c class does nothing. |
|
94 */ |
|
95 virtual ~ec_cs_tlv_header_c(); |
|
96 |
|
97 /** |
|
98 * The constructor of the ec_cs_tlv_header_c class simply initializes the attributes. |
|
99 */ |
|
100 ec_cs_tlv_header_c( |
|
101 abs_eap_am_tools_c * const tools, |
|
102 void * const header_begin, |
|
103 const u32_t header_buffer_length); |
|
104 |
|
105 /** |
|
106 * This function returns the TLV Type. |
|
107 */ |
|
108 ec_cs_tlv_type_e get_type() const; |
|
109 |
|
110 /** |
|
111 * This function returns the data length of TLV. |
|
112 */ |
|
113 u32_t get_data_length() const; |
|
114 |
|
115 /** |
|
116 * This function returns the header length of TLV. |
|
117 */ |
|
118 static u32_t get_header_length(); |
|
119 |
|
120 /** |
|
121 * This function returns pointer to the offset of data of TLV. |
|
122 * @param offset is the offset of queried data in bytes. |
|
123 * @param contignuous_bytes is the length of queried data in bytes. |
|
124 */ |
|
125 u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const; |
|
126 |
|
127 |
|
128 /** |
|
129 * This function returns pointer to the offset of data of TLV. |
|
130 * @param contignuous_bytes is the length of queried data in bytes. |
|
131 */ |
|
132 u8_t * get_data(const u32_t contignuous_bytes) const; |
|
133 |
|
134 |
|
135 /** |
|
136 * This function return pointer to the next TLV header in the same buffer. |
|
137 */ |
|
138 u8_t * get_next_header() const; |
|
139 |
|
140 |
|
141 /** |
|
142 * This function checks the header is valid. |
|
143 */ |
|
144 eap_status_e check_header() const; |
|
145 |
|
146 /** |
|
147 * This function returns debug strings of the TLV type. |
|
148 */ |
|
149 static eap_const_string get_tlv_string(const ec_cs_tlv_type_e type); |
|
150 |
|
151 /** |
|
152 * This function returns debug strings of the TLV type. |
|
153 */ |
|
154 eap_const_string get_tlv_string() const; |
|
155 |
|
156 /** |
|
157 * This function sets the TLV Type. |
|
158 */ |
|
159 eap_status_e set_type(const ec_cs_tlv_type_e type); |
|
160 |
|
161 /** |
|
162 * This function sets the TLV data length. |
|
163 */ |
|
164 eap_status_e set_data_length(const u32_t p_length); |
|
165 |
|
166 /** |
|
167 * This function resets the TLV header. |
|
168 */ |
|
169 eap_status_e reset_header(); |
|
170 |
|
171 /** |
|
172 * This function resets the TLV header object. |
|
173 */ |
|
174 eap_status_e reset(); |
|
175 |
|
176 // |
|
177 //-------------------------------------------------- |
|
178 }; // class ec_cs_tlv_header_c |
|
179 |
|
180 //---------------------------------------------------------------------------------- |
|
181 |
|
182 /// Macro traces payload type and data. |
|
183 #define EC_CS_TLV_TRACE_PAYLOAD(prefix, payload, when_true_is_client) \ |
|
184 { \ |
|
185 EAP_TRACE_DEBUG( \ |
|
186 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
187 (EAPL("v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v \n"))); \ |
|
188 if ((payload) != 0 && (payload)->get_is_valid() == true) \ |
|
189 { \ |
|
190 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
191 (EAPL("- buffer"), (payload)->get_header_buffer((payload)->get_header_buffer_length()), \ |
|
192 (payload)->get_header_buffer_length())); \ |
|
193 EAP_TRACE_DEBUG( \ |
|
194 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
195 (EAPL("- %s %s (0x%08x): TLV type 0x%04x=%s, data length 0x%04x.\n"), \ |
|
196 prefix, \ |
|
197 ((when_true_is_client) == true ? "client" : "server"), \ |
|
198 (payload)->get_header_buffer((payload)->get_data_length()), \ |
|
199 (payload)->get_type(), \ |
|
200 (payload)->get_tlv_string(), \ |
|
201 (payload)->get_data_length())); \ |
|
202 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
203 ((payload)->get_tlv_string(), (payload)->get_data((payload)->get_data_length()), \ |
|
204 (payload)->get_data_length())); \ |
|
205 } \ |
|
206 else \ |
|
207 { \ |
|
208 EAP_TRACE_DEBUG( \ |
|
209 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
210 (EAPL("payload=0x%08x is illegal.\n"), payload)); \ |
|
211 } \ |
|
212 EAP_TRACE_DEBUG( \ |
|
213 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
214 (EAPL("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \n"))); \ |
|
215 } |
|
216 |
|
217 //---------------------------------------------------------------------------------- |
|
218 |
|
219 #endif //#if defined(USE_WAPI_CORE) |
|
220 |
|
221 #endif //#if !defined(_EC_CS_TLV_HEADER_H_) |
|
222 |
|
223 |
|
224 |
|
225 // End. |