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 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 WiFi is not supported.</exception>
40 /// <exception cref="ArgumentNullException">Thrown while setting this value when 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 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 wifi.
74 /// <since_tizen> 3 </since_tizen>
75 /// <value>Type of EAP.</value>
76 /// <exception cref="NotSupportedException">Thrown while setting this value when WiFi 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 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 phase2 authentication of Wi-Fi.
105 /// <since_tizen> 3 </since_tizen>
106 /// <value>Authentication type of WiFi.</value>
107 /// <exception cref="NotSupportedException">Thrown while setting this value when WiFi 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 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 WiFi is not supported.</exception>
145 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory. </exception>
146 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
147 /// <exception cref="InvalidOperationException">Thrown when the method failed due to 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 WiFi is not supported.</exception>
168 /// <exception cref="ArgumentNullException">Thrown when file path of private key is null.</exception>
169 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
170 /// <exception cref="InvalidOperationException">Thrown when the method failed due 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 WiFi is not supported.</exception>
192 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory. </exception>
193 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
194 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
195 public string GetClientCertFile()
198 int ret = Interop.WiFi.AP.GetEapClientCertFile(_apHandle, out strPtr);
199 if (ret != (int)WiFiError.None)
201 Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret);
202 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
204 return Marshal.PtrToStringAnsi(strPtr);
208 /// Sets the CA Certificate of EAP.
210 /// <since_tizen> 3 </since_tizen>
211 /// <param name="clientCertFile">The file path of Client Certificate.</param>
212 /// <feature>http://tizen.org/feature/network.wifi</feature>
213 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
214 /// <exception cref="ArgumentNullException">Thrown when file path of Client Certificate is null.</exception>
215 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
216 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
217 public void SetClientCertFile(string clientCertFile)
219 if (clientCertFile == null)
221 throw new ArgumentNullException("File path of Client certificate is null");
223 int ret = Interop.WiFi.AP.SetEapClientCertFile(_apHandle, clientCertFile);
224 if (ret != (int)WiFiError.None)
226 Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret);
227 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
232 /// Gets the username of EAP passphrase.
234 /// <since_tizen> 3 </since_tizen>
235 /// <returns>The user name</returns>
236 /// <feature>http://tizen.org/feature/network.wifi</feature>
237 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
238 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory. </exception>
239 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
240 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
241 public string GetUserName()
245 int ret = Interop.WiFi.AP.GetEapPassphrase(_apHandle, out strptr, out passwordSet);
246 if (ret != (int)WiFiError.None)
248 Log.Error(Globals.LogTag, "Failed to get user name in eap passphrase, Error - " + (WiFiError)ret);
249 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
251 return Marshal.PtrToStringAnsi(strptr);
255 /// Returns whether the password is set or not.
257 /// <since_tizen> 3 </since_tizen>
258 /// <returns>True if password is set, false if password is not set.</returns>
259 /// <feature>http://tizen.org/feature/network.wifi</feature>
260 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
261 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory. </exception>
262 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
263 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
264 public bool IsPasswordSet()
268 int ret = Interop.WiFi.AP.GetEapPassphrase(_apHandle, out strptr, out passwordSet);
269 if (ret != (int)WiFiError.None)
271 Log.Error(Globals.LogTag, "Failed to get IsPasswordSet in passphrase, Error - " + (WiFiError)ret);
272 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
278 /// Sets the user name of EAP.
280 /// <since_tizen> 3 </since_tizen>
281 /// <param name="userName">The user name</param>
282 /// <feature>http://tizen.org/feature/network.wifi</feature>
283 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
284 /// <exception cref="ArgumentNullException">Thrown when the user name is passed as null. </exception>
285 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
286 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
287 public void SetUserName(string userName)
289 if (userName == null)
291 throw new ArgumentNullException("User name is null");
293 int ret = Interop.WiFi.AP.SetEapPassphrase(_apHandle, userName, null);
294 if (ret != (int)WiFiError.None)
296 Log.Error(Globals.LogTag, "Failed to set username, Error - " + (WiFiError)ret);
297 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
302 /// Sets the password of EAP.
304 /// <since_tizen> 3 </since_tizen>
305 /// <param name="password">The password</param>
306 /// <feature>http://tizen.org/feature/network.wifi</feature>
307 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
308 /// <exception cref="ArgumentNullException">Thrown when the password is passed as null. </exception>
309 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
310 /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
311 public void SetPassword(string password)
313 if (password == null)
315 throw new ArgumentNullException("Password is null");
317 int ret = Interop.WiFi.AP.SetEapPassphrase(_apHandle, null, password);
318 if (ret != (int)WiFiError.None)
320 Log.Error(Globals.LogTag, "Failed to set password, Error - " + (WiFiError)ret);
321 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
324 } //WiFiEapInformation