2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
21 using System.Threading.Tasks;
22 using System.Runtime.InteropServices;
24 namespace Tizen.Network.WiFi
27 /// A class for managing the EAP information of the access point (AP).
29 /// <since_tizen> 3 </since_tizen>
30 public class WiFiEap : IWiFiEap
32 private Interop.WiFi.SafeWiFiAPHandle _apHandle;
35 /// The file path of CA Certificate of EAP.
37 /// <since_tizen> 3 </since_tizen>
38 /// <value>CA certification file of EAP.</value>
39 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
40 /// <exception cref="ArgumentNullException">Thrown while setting this value when the file value is null.</exception>
41 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
42 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
43 public string CaCertificationFile
48 int ret = Interop.WiFi.AP.GetEapCaCertFile(_apHandle, out strPtr);
49 if (ret != (int)WiFiError.None)
51 Log.Error(Globals.LogTag, "Failed to get caCertFile, Error - " + (WiFiError)ret);
54 return Marshal.PtrToStringAnsi(strPtr);
60 throw new ArgumentNullException("File value is null");
62 int ret = Interop.WiFi.AP.SetEapCaCertFile(_apHandle, value);
63 if (ret != (int)WiFiError.None)
65 Log.Error(Globals.LogTag, "Failed to set caCertFile, Error - " + (WiFiError)ret);
66 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
72 /// The EAP type of Wi-Fi.
74 /// <since_tizen> 3 </since_tizen>
75 /// <value>Type of EAP.</value>
76 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
77 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
78 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
79 public WiFiEapType EapType
84 int ret = Interop.WiFi.AP.GetEapType(_apHandle, out type);
85 if (ret != (int)WiFiError.None)
87 Log.Error(Globals.LogTag, "Failed to get eap type, Error - " + (WiFiError)ret);
89 return (WiFiEapType)type;
93 int ret = Interop.WiFi.AP.SetEapType(_apHandle, (int)value);
94 if (ret != (int)WiFiError.None)
96 Log.Error(Globals.LogTag, "Failed to set eap type, Error - " + (WiFiError)ret);
97 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
103 /// The type of EAP phase 2 authentication of the Wi-Fi.
105 /// <since_tizen> 3 </since_tizen>
106 /// <value>Authentication type of the Wi-Fi.</value>
107 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
108 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
109 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
110 public WiFiAuthenticationType AuthenticationType
115 int ret = Interop.WiFi.AP.GetEapAuthType(_apHandle, out type);
116 if (ret != (int)WiFiError.None)
118 Log.Error(Globals.LogTag, "Failed to get auth type, Error - " + (WiFiError)ret);
120 return (WiFiAuthenticationType)type;
124 int ret = Interop.WiFi.AP.SetEapAuthType(_apHandle, (int)value);
125 if (ret != (int)WiFiError.None)
127 Log.Error(Globals.LogTag, "Failed to set eap auth type, Error - " + (WiFiError)ret);
128 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
133 internal WiFiEap(Interop.WiFi.SafeWiFiAPHandle apHandle)
135 _apHandle = apHandle;
139 /// Gets the private key file of EAP.
141 /// <since_tizen> 3 </since_tizen>
142 /// <returns>The file path of private key.</returns>
143 /// <feature>http://tizen.org/feature/network.wifi</feature>
144 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
145 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
146 /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception>
147 /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception>
148 public string GetPrivateKeyFile()
151 int ret = Interop.WiFi.AP.GetEapPrivateKeyFile(_apHandle, out strPtr);
152 if (ret != (int)WiFiError.None)
154 Log.Error(Globals.LogTag, "Failed to get private key file, Error - " + (WiFiError)ret);
155 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
157 return Marshal.PtrToStringAnsi(strPtr);
161 /// Sets the private key information of EAP.
163 /// <since_tizen> 3 </since_tizen>
164 /// <param name="privateKeyFile">The file path of private key.</param>
165 /// <param name="password">The password.</param>
166 /// <feature>http://tizen.org/feature/network.wifi</feature>
167 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
168 /// <exception cref="ArgumentNullException">Thrown when the file path of private key is null.</exception>
169 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
170 /// <exception cref="InvalidOperationException">Thrown when the method failed due an to invalid operation.</exception>
171 public void SetPrivateKeyFile(string privateKeyFile, string password)
173 if (privateKeyFile == null)
175 throw new ArgumentNullException("File path of private key is null");
177 int ret = Interop.WiFi.AP.SetEapPrivateKeyFile(_apHandle, privateKeyFile, password);
178 if (ret != (int)WiFiError.None)
180 Log.Error(Globals.LogTag, "Failed to set private key file, Error - " + (WiFiError)ret);
181 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
186 /// Gets the client certificate of EAP.
188 /// <since_tizen> 3 </since_tizen>
189 /// <returns>The file path of client certificate.</returns>
190 /// <feature>http://tizen.org/feature/network.wifi</feature>
191 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
192 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
193 /// <exception cref="InvalidOperationException">Thrown when the method failed due an to invalid operation.</exception>
194 public string GetClientCertFile()
197 int ret = Interop.WiFi.AP.GetEapClientCertFile(_apHandle, out strPtr);
198 if (ret != (int)WiFiError.None)
200 Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret);
201 if (ret == (int)WiFiError.InvalidParameterError)
203 throw new InvalidOperationException("Invalid handle");
205 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
207 return Marshal.PtrToStringAnsi(strPtr);
211 /// Sets the CA certificate of EAP.
213 /// <since_tizen> 3 </since_tizen>
214 /// <param name="clientCertFile">The file path of client certificate.</param>
215 /// <feature>http://tizen.org/feature/network.wifi</feature>
216 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
217 /// <exception cref="ArgumentNullException">Thrown when the file path of client certificate is null.</exception>
218 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
219 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
220 public void SetClientCertFile(string clientCertFile)
222 if (clientCertFile == null)
224 throw new ArgumentNullException("File path of Client certificate is null");
226 int ret = Interop.WiFi.AP.SetEapClientCertFile(_apHandle, clientCertFile);
227 if (ret != (int)WiFiError.None)
229 Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret);
230 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
235 /// Gets the username of EAP passphrase.
237 /// <since_tizen> 3 </since_tizen>
238 /// <returns>The user name</returns>
239 /// <feature>http://tizen.org/feature/network.wifi</feature>
240 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
241 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
242 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
243 public string GetUserName()
247 int ret = Interop.WiFi.AP.GetEapPassphrase(_apHandle, out strptr, out passwordSet);
248 if (ret != (int)WiFiError.None)
250 Log.Error(Globals.LogTag, "Failed to get user name in eap passphrase, Error - " + (WiFiError)ret);
251 if (ret == (int)WiFiError.InvalidParameterError)
253 throw new InvalidOperationException("Invalid handle");
255 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
257 return Marshal.PtrToStringAnsi(strptr);
261 /// Returns whether the password is set or not.
263 /// <since_tizen> 3 </since_tizen>
264 /// <returns>True if password is set, false if password is not set.</returns>
265 /// <feature>http://tizen.org/feature/network.wifi</feature>
266 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
267 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
268 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
269 public bool IsPasswordSet()
273 int ret = Interop.WiFi.AP.GetEapPassphrase(_apHandle, out strptr, out passwordSet);
274 if (ret != (int)WiFiError.None)
276 Log.Error(Globals.LogTag, "Failed to get IsPasswordSet in passphrase, Error - " + (WiFiError)ret);
277 if (ret == (int)WiFiError.InvalidParameterError)
279 throw new InvalidOperationException("Invalid handle");
281 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
287 /// Sets the user name of EAP.
289 /// <since_tizen> 3 </since_tizen>
290 /// <param name="userName">The user name</param>
291 /// <feature>http://tizen.org/feature/network.wifi</feature>
292 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
293 /// <exception cref="ArgumentNullException">Thrown when the user name is passed as null.</exception>
294 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
295 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
296 public void SetUserName(string userName)
298 if (userName == null)
300 throw new ArgumentNullException("User name is null");
302 int ret = Interop.WiFi.AP.SetEapPassphrase(_apHandle, userName, null);
303 if (ret != (int)WiFiError.None)
305 Log.Error(Globals.LogTag, "Failed to set username, Error - " + (WiFiError)ret);
306 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
311 /// Sets the password of EAP.
313 /// <since_tizen> 3 </since_tizen>
314 /// <param name="password">The password</param>
315 /// <feature>http://tizen.org/feature/network.wifi</feature>
316 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
317 /// <exception cref="ArgumentNullException">Thrown when the password is passed as null.</exception>
318 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
319 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
320 public void SetPassword(string password)
322 if (password == null)
324 throw new ArgumentNullException("Password is null");
326 int ret = Interop.WiFi.AP.SetEapPassphrase(_apHandle, null, password);
327 if (ret != (int)WiFiError.None)
329 Log.Error(Globals.LogTag, "Failed to set password, Error - " + (WiFiError)ret);
330 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
333 } //WiFiEapInformation