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.Runtime.InteropServices;
20 namespace Tizen.Network.WiFi
23 /// A class for managing the EAP configuration.
25 /// <since_tizen> 3 </since_tizen>
26 public class WiFiEapConfiguration : IWiFiEap
28 private Interop.WiFi.SafeWiFiConfigHandle _configHandle;
31 /// The file path of CA certificate of EAP.
33 /// <since_tizen> 3 </since_tizen>
34 /// <value>CA certification file of EAP.</value>
35 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
36 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
37 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
38 public string CaCertificationFile
43 int ret = Interop.WiFi.Config.GetEapCaCertFile(_configHandle, out strPtr);
44 if (ret != (int)WiFiError.None)
46 Log.Error(Globals.LogTag, "Failed to get caCertFile Error - " + (WiFiError)ret);
49 return Marshal.PtrToStringAnsi(strPtr);
53 int ret = Interop.WiFi.Config.SetEapCaCertFile(_configHandle, value);
54 if (ret != (int)WiFiError.None)
56 Log.Error(Globals.LogTag, "Failed to set caCertFile, Error - " + (WiFiError)ret);
57 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
63 /// The EAP type of the Wi-Fi.
65 /// <since_tizen> 3 </since_tizen>
66 /// <value>Type of EAP.</value>
67 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
68 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
69 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
70 public WiFiEapType EapType
75 int ret = Interop.WiFi.Config.GetEapType(_configHandle, out type);
76 if (ret != (int)WiFiError.None)
78 Log.Error(Globals.LogTag, "Failed to eap type Error - " + (WiFiError)ret);
80 return (WiFiEapType)type;
84 int ret = Interop.WiFi.Config.SetEapType(_configHandle, (int)value);
85 if (ret != (int)WiFiError.None)
87 Log.Error(Globals.LogTag, "Failed to set eap type, Error - " + (WiFiError)ret);
88 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
94 /// The type of EAP phase2 authentication of the Wi-Fi.
96 /// <since_tizen> 3 </since_tizen>
97 /// <value>Authentication type of the Wi-Fi.</value>
98 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
99 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
100 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
101 public WiFiAuthenticationType AuthenticationType
106 int ret = Interop.WiFi.Config.GetEapAuthType(_configHandle, out type);
107 if (ret != (int)WiFiError.None)
109 Log.Error(Globals.LogTag, "Failed to get auth type Error - " + (WiFiError)ret);
111 return (WiFiAuthenticationType)type;
115 int ret = Interop.WiFi.Config.SetEapAuthType(_configHandle, (int)value);
116 if (ret != (int)WiFiError.None)
118 Log.Error(Globals.LogTag, "Failed to set eap auth type, Error - " + (WiFiError)ret);
119 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
125 /// The anonymous identity of the access point (AP).
127 /// <since_tizen> 3 </since_tizen>
128 /// <value>Represents the anonymous identity of the access point.</value>
129 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
130 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
131 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
132 public string AnonymousIdentify
137 int ret = Interop.WiFi.Config.GetEapAnonymousIdentity(_configHandle, out strPtr);
138 if (ret != (int)WiFiError.None)
140 Log.Error(Globals.LogTag, "Failed to get anonymous identify Error - " + (WiFiError)ret);
143 return Marshal.PtrToStringAnsi(strPtr);
147 int ret = Interop.WiFi.Config.SetEapAnonymousIdentity(_configHandle, value);
148 if (ret != (int)WiFiError.None)
150 Log.Error(Globals.LogTag, "Failed to set anonymous identify, Error - " + (WiFiError)ret);
151 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
157 /// The identity of the access point (AP).
159 /// <since_tizen> 3 </since_tizen>
160 /// <value>Represents the identity of the access point.</value>
161 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
162 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
163 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
164 public string Identity
169 int ret = Interop.WiFi.Config.GetEapIdentity(_configHandle, out strPtr);
170 if (ret != (int)WiFiError.None)
172 Log.Error(Globals.LogTag, "Failed to get identify Error - " + (WiFiError)ret);
175 return Marshal.PtrToStringAnsi(strPtr);
179 int ret = Interop.WiFi.Config.SetEapIdentity(_configHandle, value);
180 if (ret != (int)WiFiError.None)
182 Log.Error(Globals.LogTag, "Failed to set identify, Error - " + (WiFiError)ret);
183 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
189 /// The subject match of the access point (AP).
191 /// <since_tizen> 3 </since_tizen>
192 /// <value>Represents the subject match of the AP.</value>
193 /// <exception cref="NotSupportedException">Thrown while setting this value when Wi-Fi is not supported.</exception>
194 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
195 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
196 public string SubjectMatch
201 int ret = Interop.WiFi.Config.GetEapSubjectMatch(_configHandle, out strPtr);
202 if (ret != (int)WiFiError.None)
204 Log.Error(Globals.LogTag, "Failed to get subject match Error - " + (WiFiError)ret);
207 return Marshal.PtrToStringAnsi(strPtr);
211 int ret = Interop.WiFi.Config.SetEapSubjectMatch(_configHandle, value);
212 if (ret != (int)WiFiError.None)
214 Log.Error(Globals.LogTag, "Failed to set subject match, Error - " + (WiFiError)ret);
215 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
220 internal WiFiEapConfiguration(Interop.WiFi.SafeWiFiConfigHandle handle)
222 _configHandle = handle;
226 /// Gets the access point client certificate file from the configuration.
228 /// <since_tizen> 3 </since_tizen>
229 /// <returns>The certification authority (CA) certificates file of the access point.</returns>
230 /// <feature>http://tizen.org/feature/network.wifi</feature>
231 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
232 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
233 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
234 public string GetClientCertFile()
237 int ret = Interop.WiFi.Config.GetEapClientCertFile(_configHandle, out strPtr);
238 if (ret != (int)WiFiError.None)
240 Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret);
241 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
243 return Marshal.PtrToStringAnsi(strPtr);
247 /// Sets the access point client certificate file to configuration.
249 /// <since_tizen> 3 </since_tizen>
250 /// <param name="privateKey">The private key file.</param>
251 /// <param name="clientCert">The certification authority(CA) certifies the files of access points.</param>
252 /// <feature>http://tizen.org/feature/network.wifi</feature>
253 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
254 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
255 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
256 public void SetClientCertFile(string privateKey, string clientCert)
258 int ret = Interop.WiFi.Config.SetEapClientCertFile(_configHandle, privateKey, clientCert);
259 if (ret != (int)WiFiError.None)
261 Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret);
262 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle());
265 } //WiFiEapConfiguration