|
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 // This is enumeration of EAPOL source code. |
|
20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
21 #undef EAP_FILE_NUMBER_ENUM |
|
22 #define EAP_FILE_NUMBER_ENUM 102 |
|
23 #undef EAP_FILE_NUMBER_DATE |
|
24 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
26 |
|
27 |
|
28 |
|
29 #include "eap_radius_attribute_header.h" |
|
30 #include "eap_header_string.h" |
|
31 |
|
32 |
|
33 /** @file */ |
|
34 |
|
35 |
|
36 // |
|
37 EAP_FUNC_EXPORT eap_radius_attribute_header_c::~eap_radius_attribute_header_c() |
|
38 { |
|
39 } |
|
40 |
|
41 // |
|
42 EAP_FUNC_EXPORT eap_radius_attribute_header_c::eap_radius_attribute_header_c( |
|
43 abs_eap_am_tools_c * const tools, |
|
44 void * const header_buffer, |
|
45 const u32_t header_buffer_length) |
|
46 : eap_general_header_base_c(tools, header_buffer, header_buffer_length) |
|
47 , m_am_tools(tools) |
|
48 { |
|
49 } |
|
50 |
|
51 EAP_FUNC_EXPORT eap_diameter_avp_code_c eap_radius_attribute_header_c::get_current_payload() const |
|
52 { |
|
53 const u8_t * const payload_data = get_header_offset(m_type_offset, sizeof(u8_t)); |
|
54 if (payload_data != 0) |
|
55 { |
|
56 eap_diameter_avp_code_c avp_code(static_cast<eap_diameter_avp_code_of_ietf_e>(*payload_data)); |
|
57 return avp_code; |
|
58 } |
|
59 else |
|
60 { |
|
61 return eap_diameter_avp_code_none; |
|
62 } |
|
63 } |
|
64 |
|
65 EAP_FUNC_EXPORT u16_t eap_radius_attribute_header_c::get_length() const |
|
66 { |
|
67 const u8_t * const length_data = get_header_offset(m_length_offset, sizeof(u8_t)); |
|
68 if (length_data != 0) |
|
69 { |
|
70 return static_cast<u16_t>(*length_data); |
|
71 } |
|
72 else |
|
73 { |
|
74 return 0ul; |
|
75 } |
|
76 } |
|
77 |
|
78 EAP_FUNC_EXPORT u32_t eap_radius_attribute_header_c::get_data_length() const |
|
79 { |
|
80 if (get_length() > get_header_length()) |
|
81 return static_cast<u32_t>(get_length()-get_header_length()); |
|
82 else |
|
83 return 0; |
|
84 } |
|
85 |
|
86 EAP_FUNC_EXPORT u16_t eap_radius_attribute_header_c::get_header_length() |
|
87 { |
|
88 return m_data_offset; |
|
89 } |
|
90 |
|
91 EAP_FUNC_EXPORT u16_t eap_radius_attribute_header_c::get_max_attribute_data_length() |
|
92 { |
|
93 return static_cast<u16_t>((0xff & (~0)) - get_header_length()); |
|
94 } |
|
95 |
|
96 EAP_FUNC_EXPORT u8_t * eap_radius_attribute_header_c::get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const |
|
97 { |
|
98 u32_t data_length = get_header_buffer_length() - get_header_length(); |
|
99 |
|
100 if (data_length >= offset+contignuous_bytes |
|
101 && contignuous_bytes > 0) |
|
102 { |
|
103 u8_t * const data = get_header_offset(m_data_offset, contignuous_bytes); |
|
104 if (data != 0) |
|
105 { |
|
106 return data+offset; // Data begins after the header. |
|
107 } |
|
108 else |
|
109 { |
|
110 return 0; |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 EAP_ASSERT( |
|
116 data_length >= offset+contignuous_bytes |
|
117 && contignuous_bytes > 0); |
|
118 } |
|
119 return 0; |
|
120 } |
|
121 |
|
122 EAP_FUNC_EXPORT u8_t * eap_radius_attribute_header_c::get_next_header() const |
|
123 { |
|
124 if (get_header_buffer_length() >= get_data_length()+2ul*get_header_length()) |
|
125 { |
|
126 return get_data_offset(get_data_length(), get_header_length()); |
|
127 } |
|
128 else |
|
129 { |
|
130 return 0; |
|
131 } |
|
132 } |
|
133 |
|
134 EAP_FUNC_EXPORT void eap_radius_attribute_header_c::set_current_payload( |
|
135 const eap_diameter_avp_code_c p_current_payload) |
|
136 { |
|
137 u8_t * const payload_type = get_header_offset(m_type_offset, sizeof(u8_t)); |
|
138 |
|
139 EAP_ASSERT(payload_type != 0); |
|
140 |
|
141 *payload_type = static_cast<u8_t>(p_current_payload.get_vendor_code()); |
|
142 } |
|
143 |
|
144 EAP_FUNC_EXPORT void eap_radius_attribute_header_c::set_data_length(const u16_t p_data_length) |
|
145 { |
|
146 u32_t total_length = p_data_length+eap_radius_attribute_header_c::get_header_length(); |
|
147 |
|
148 u8_t * const length_data = get_header_offset(m_length_offset, sizeof(u8_t)); |
|
149 |
|
150 EAP_ASSERT(length_data != 0); |
|
151 |
|
152 *length_data = static_cast<u8_t>(total_length); |
|
153 } |
|
154 |
|
155 EAP_FUNC_EXPORT void eap_radius_attribute_header_c::reset_header(const u16_t data_length) |
|
156 { |
|
157 set_current_payload(eap_diameter_avp_code_none); |
|
158 set_data_length(data_length); |
|
159 } |
|
160 |
|
161 EAP_FUNC_EXPORT eap_const_string eap_radius_attribute_header_c::get_payload_type_string() const |
|
162 { |
|
163 |
|
164 #if defined(USE_EAP_TRACE_STRINGS) |
|
165 const eap_diameter_avp_code_c payload_type = get_current_payload(); |
|
166 |
|
167 EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_none) |
|
168 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_user_name) |
|
169 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_user_password) |
|
170 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_chap_password) |
|
171 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_nas_ip_address) |
|
172 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_nas_port) |
|
173 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_service_type) |
|
174 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_protocol) |
|
175 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_ip_address) |
|
176 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_ip_netmask) |
|
177 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_routing) |
|
178 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_filter_id) |
|
179 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_mtu) |
|
180 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_compression) |
|
181 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_ip_host) |
|
182 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_service) |
|
183 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_tcp_port) |
|
184 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_reply_message) |
|
185 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_callback_number) |
|
186 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_callback_id) |
|
187 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_route) |
|
188 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_ipx_network) |
|
189 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_state) |
|
190 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_class) |
|
191 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_vendor_specific) |
|
192 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_session_timeout) |
|
193 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_idle_timeout) |
|
194 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_termination_action) |
|
195 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_called_station_id) |
|
196 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_calling_station_id) |
|
197 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_nas_identifier) |
|
198 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_proxy_state) |
|
199 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_lat_service) |
|
200 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_lat_node) |
|
201 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_lat_group) |
|
202 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_appletalk_link) |
|
203 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_appletalk_network) |
|
204 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_framed_appletalk_zone) |
|
205 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_chap_challenge) |
|
206 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_nas_port_type) |
|
207 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_port_limit) |
|
208 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_login_lat_port) |
|
209 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_eap_message) |
|
210 else EAP_IF_RETURN_STRING(payload_type, eap_diameter_avp_code_message_authenticator) |
|
211 #endif // #if defined(USE_EAP_TRACE_STRINGS) |
|
212 { |
|
213 return EAPL("Unknown RADIUS payload AT"); |
|
214 } |
|
215 } |
|
216 |
|
217 EAP_FUNC_EXPORT eap_status_e eap_radius_attribute_header_c::check_header() const |
|
218 { |
|
219 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
220 } |
|
221 |
|
222 // End. |