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 Tizen.Network.Connection;
20 namespace Tizen.Network.WiFi
23 /// A class for managing the WiFi security information.
25 /// <since_tizen> 3 </since_tizen>
26 public class WiFiSecurity
28 private Interop.WiFi.SafeWiFiAPHandle _apHandle;
32 /// The type of Wi-Fi security.
34 /// <since_tizen> 3 </since_tizen>
35 /// <value>Represents the security type of WiFi.</value>
36 /// <exception cref="NotSupportedException">Thrown while setting this property when WiFi is not supported.</exception>
37 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
38 /// <exception cref="InvalidOperationException">Thrown while setting this value due to invalid operation.</exception>
39 public WiFiSecurityType SecurityType
44 int ret = Interop.WiFi.AP.GetSecurityType(_apHandle, out type);
45 if (ret != (int)WiFiError.None)
47 Log.Error(Globals.LogTag, "Failed to get security type, Error - " + (WiFiError)ret);
49 return (WiFiSecurityType)type;
53 int ret = Interop.WiFi.AP.SetSecurityType(_apHandle, (int)value);
54 if (ret != (int)WiFiError.None)
56 Log.Error(Globals.LogTag, "Failed to set security type, Error - " + (WiFiError)ret);
57 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
63 /// The type of Wi-Fi encryption
65 /// <since_tizen> 3 </since_tizen>
66 /// <value>Represents the encryption type of WiFi.</value>
67 /// <exception cref="NotSupportedException">Thrown while setting this property when WiFi 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 invalid operation.</exception>
70 public WiFiEncryptionType EncryptionType
75 int ret = Interop.WiFi.AP.GetEncryptionType(_apHandle, out type);
76 if (ret != (int)WiFiError.None)
78 Log.Error(Globals.LogTag, "Failed to get encryption type, Error - " + (WiFiError)ret);
80 return (WiFiEncryptionType)type;
84 int ret = Interop.WiFi.AP.SetEncryptionType(_apHandle, (int)value);
85 if (ret != (int)WiFiError.None)
87 Log.Error(Globals.LogTag, "Failed to set encryption type, Error - " + (WiFiError)ret);
88 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
94 /// The EAP information
96 /// <since_tizen> 3 </since_tizen>
97 /// <value>Eap information of WiFi.</value>
98 public WiFiEap EapInformation
107 /// A property to check whether the passphrase is required or not.
109 /// <since_tizen> 3 </since_tizen>
110 /// <value>Boolean value to check if passphrase is required or not.</value>
111 public bool IsPassphraseRequired
116 int ret = Interop.WiFi.AP.IsPassphraseRequired(_apHandle, out required);
117 if (ret != (int)WiFiError.None)
119 Log.Error(Globals.LogTag, "Failed to get isPassportRequired, Error - " + (WiFiError)ret);
126 /// A property to check whether the Wi-Fi Protected Setup(WPS) is supported or not.
128 /// <since_tizen> 3 </since_tizen>
129 /// <value>Boolean value to check if wps is supported or not.</value>
130 public bool IsWpsSupported
135 int ret = Interop.WiFi.AP.IsWpsSupported(_apHandle, out supported);
136 if (ret != (int)WiFiError.None)
138 Log.Error(Globals.LogTag, "Failed to get isWapSupported, Error - " + (WiFiError)ret);
144 internal WiFiSecurity(Interop.WiFi.SafeWiFiAPHandle apHandle)
146 _apHandle = apHandle;
147 _eap = new WiFiEap(apHandle);
151 /// Sets the passphrase.
153 /// <since_tizen> 3 </since_tizen>
154 /// <param name="passphrase">The passphrase of the access point.</param>
155 /// <feature>http://tizen.org/feature/network.wifi</feature>
156 /// <exception cref="NotSupportedException">Thrown when WiFi is not supported.</exception>
157 /// <exception cref="ArgumentNullException">Thrown when passphrase is passed as null.</exception>
158 /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
159 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
160 public void SetPassphrase(string passphrase)
162 if (passphrase == null)
164 throw new ArgumentNullException("Passphrase is null");
166 int ret = Interop.WiFi.AP.SetPassphrase(_apHandle, passphrase);
167 if (ret != (int)WiFiError.None)
169 Log.Error(Globals.LogTag, "Failed to set passphrase, Error - " + (WiFiError)ret);
170 WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
173 } //WiFiSecurityInformation