1 /* |
|
2 * Copyright (c) 2001-2010 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 * %version: 17 % |
|
20 */ |
|
21 |
|
22 |
|
23 #include "eap_am_tools.h" |
|
24 #include "eap_am_export.h" |
|
25 #include "EapCoreIf.h" |
|
26 #include "eap_automatic_variable.h" |
|
27 #include "eap_config.h" |
|
28 #include "eap_file_config.h" |
|
29 #include "abs_eap_am_mutex.h" |
|
30 #include "EapServerClientDef.h" |
|
31 |
|
32 /** @file */ |
|
33 |
|
34 //-------------------------------------------------- |
|
35 |
|
36 /** |
|
37 * This is the timer ID used with abs_eap_am_tools_c::set_timer() and abs_eap_am_tools_c::cancel_timer(). |
|
38 */ |
|
39 enum eap_am_core_message_if_timer_id |
|
40 { |
|
41 EAP_AM_CORE_MESSAGE_IF_TIMER_PROCESS_DATA_ID, |
|
42 EAP_AM_CORE_MESSAGE_IF_TIMER_SEND_DATA_ID, |
|
43 }; |
|
44 |
|
45 //-------------------------------------------------- |
|
46 |
|
47 CEapCoreIf::CEapCoreIf( |
|
48 abs_eap_am_tools_c * const tools, |
|
49 eap_am_message_if_c * const server, |
|
50 AbsEapSendInterface * client) |
|
51 : m_am_tools(tools) |
|
52 , m_client_if(client) |
|
53 , m_server_if(server) |
|
54 , m_fileconfig(0) |
|
55 , m_use_asyncronous_test(false) |
|
56 , iIsValid(false) |
|
57 { |
|
58 if (m_am_tools == 0 || m_am_tools->get_is_valid() == false) |
|
59 { |
|
60 return; |
|
61 } |
|
62 |
|
63 if (m_client_if == 0) |
|
64 { |
|
65 return; |
|
66 } |
|
67 |
|
68 if (m_server_if == 0 || m_server_if->get_is_valid() == false) |
|
69 { |
|
70 return; |
|
71 } |
|
72 |
|
73 iIsValid = true; |
|
74 } |
|
75 |
|
76 //-------------------------------------------------- |
|
77 |
|
78 CEapCoreIf::~CEapCoreIf() |
|
79 { |
|
80 if (m_server_if != 0) |
|
81 { |
|
82 m_server_if->shutdown(); |
|
83 } |
|
84 delete m_server_if; |
|
85 m_server_if = 0; |
|
86 |
|
87 delete m_fileconfig; |
|
88 m_fileconfig = 0; |
|
89 } |
|
90 |
|
91 //-------------------------------------------------- |
|
92 |
|
93 bool CEapCoreIf::get_is_valid() |
|
94 { |
|
95 return iIsValid; |
|
96 } |
|
97 |
|
98 //-------------------------------------------------- |
|
99 |
|
100 eap_status_e CEapCoreIf::configure( |
|
101 const eap_variable_data_c * const client_configuration) |
|
102 { |
|
103 return m_server_if->configure(client_configuration); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------- |
|
107 |
|
108 eap_status_e CEapCoreIf::send_data(const void * const data, const u32_t length) |
|
109 { |
|
110 return m_client_if->SendData(data, length, EEapCoreSendData); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------- |
|
114 |
|
115 eap_status_e CEapCoreIf::process_data(const void * const data, const u32_t length) |
|
116 { |
|
117 return m_server_if->process_data(data, length); |
|
118 } |
|
119 |
|
120 //-------------------------------------------------- |
|
121 |
|
122 // |
|
123 eap_status_e CEapCoreIf::shutdown() |
|
124 { |
|
125 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
126 |
|
127 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
128 |
|
129 EAP_TRACE_DEBUG( |
|
130 m_am_tools, |
|
131 EAP_TRACE_FLAGS_MESSAGE_DATA, |
|
132 (EAPL("CEapCoreIf::shutdown(): this = 0x%08x.\n"), |
|
133 this)); |
|
134 |
|
135 eap_status_e status(eap_status_process_general_error); |
|
136 |
|
137 if (m_server_if != 0) |
|
138 { |
|
139 m_server_if->shutdown(); |
|
140 } |
|
141 |
|
142 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
143 return EAP_STATUS_RETURN(m_am_tools, status); |
|
144 } |
|
145 |
|
146 //-------------------------------------------------- |
|
147 |
|
148 CEapCoreIf* CEapCoreIf::new_CEapCoreIf( |
|
149 abs_eap_am_tools_c * const tools, |
|
150 const bool is_client_when_true, |
|
151 const u32_t MTU, |
|
152 AbsEapSendInterface * client) |
|
153 { |
|
154 eap_am_message_if_c *server = eap_am_message_if_c::new_eap_am_server_message_if_c( |
|
155 tools, |
|
156 is_client_when_true, |
|
157 MTU); |
|
158 |
|
159 eap_automatic_variable_c<eap_am_message_if_c> automatic_server( |
|
160 tools, |
|
161 server); |
|
162 |
|
163 if (server == 0 |
|
164 || server->get_is_valid() == false) |
|
165 { |
|
166 // ERROR. |
|
167 if (server != 0) |
|
168 { |
|
169 EAP_TRACE_DEBUG( |
|
170 tools, |
|
171 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
172 (EAPL("calls: CEapCoreIf(): server->shutdown(): %s.\n"), |
|
173 (is_client_when_true == true) ? "client": "server")); |
|
174 |
|
175 server->shutdown(); |
|
176 } |
|
177 |
|
178 return 0; |
|
179 } |
|
180 |
|
181 CEapCoreIf * core_if = new CEapCoreIf( |
|
182 tools, |
|
183 server, |
|
184 client); |
|
185 |
|
186 eap_automatic_variable_c<CEapCoreIf> automatic_core_if( |
|
187 tools, |
|
188 core_if); |
|
189 |
|
190 if (core_if == 0 |
|
191 || core_if->get_is_valid() == false) |
|
192 { |
|
193 // ERROR. |
|
194 if (core_if != 0) |
|
195 { |
|
196 EAP_TRACE_DEBUG( |
|
197 tools, |
|
198 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
199 (EAPL("calls: CEapCoreIf(): core_if->shutdown(): %s.\n"), |
|
200 (is_client_when_true == true) ? "client": "server")); |
|
201 |
|
202 // automatic_core_if will delete core_if and core_if will delete server too. |
|
203 automatic_server.do_not_free_variable(); |
|
204 core_if->shutdown(); |
|
205 } |
|
206 |
|
207 return 0; |
|
208 } |
|
209 |
|
210 server->set_partner(core_if); |
|
211 |
|
212 automatic_server.do_not_free_variable(); |
|
213 automatic_core_if.do_not_free_variable(); |
|
214 |
|
215 return core_if; |
|
216 } |
|
217 |
|
218 //-------------------------------------------------- |
|
219 // End |
|