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.Runtime.InteropServices;
23 namespace Tizen.Network.Connection
26 /// This Class is WiFiProfile. It provides functions to manage the WiFi profile.
28 /// <since_tizen> 3 </since_tizen>
29 public class WiFiProfile : ConnectionProfile
31 internal WiFiProfile(IntPtr Handle) : base(Handle)
40 /// The ESSID (Extended Service Set Identifier).
42 /// <since_tizen> 3 </since_tizen>
43 /// <value>ESSID of the WiFi.</value>
49 int ret = Interop.ConnectionWiFiProfile.GetEssid(ProfileHandle, out value);
50 if ((ConnectionError)ret != ConnectionError.None)
52 Log.Error(Globals.LogTag, "It failed to create profile handle, " + (ConnectionError)ret);
54 string result = Marshal.PtrToStringAnsi(value);
55 Interop.Libc.Free(value);
61 /// The BSSID (Basic Service Set Identifier).
63 /// <since_tizen> 3 </since_tizen>
64 /// <value>BSSID of the WiFi.</value>
70 int ret = Interop.ConnectionWiFiProfile.GetBssid(ProfileHandle, out value);
71 if ((ConnectionError)ret != ConnectionError.None)
73 Log.Error(Globals.LogTag, "It failed to get bssid, " + (ConnectionError)ret);
75 string result = Marshal.PtrToStringAnsi(value);
76 Interop.Libc.Free(value);
84 /// <since_tizen> 3 </since_tizen>
85 /// <value>RSSI of the WiFi.</value>
91 int ret = Interop.ConnectionWiFiProfile.GetRssi(ProfileHandle, out value);
92 if ((ConnectionError)ret != ConnectionError.None)
94 Log.Error(Globals.LogTag, "It failed to get rssi, " + (ConnectionError)ret);
101 /// The frequency (MHz).
103 /// <since_tizen> 3 </since_tizen>
104 /// <value>Frequency of the WiFi.</value>
110 int ret = Interop.ConnectionWiFiProfile.GetFrequency(ProfileHandle, out value);
111 if ((ConnectionError)ret != ConnectionError.None)
113 Log.Error(Globals.LogTag, "It failed to get frequency, " + (ConnectionError)ret);
120 /// The max speed (Mbps).
122 /// <since_tizen> 3 </since_tizen>
123 /// <value>Maximum speed of the WiFi.</value>
129 int ret = Interop.ConnectionWiFiProfile.GetMaxSpeed(ProfileHandle, out value);
130 if ((ConnectionError)ret != ConnectionError.None)
132 Log.Error(Globals.LogTag, "It failed to get max speed, " + (ConnectionError)ret);
139 /// The security type of WiFi.
141 /// <since_tizen> 3 </since_tizen>
142 /// <value>Security type of the WiFi.</value>
143 public WiFiSecurityType SecurityType
148 int ret = Interop.ConnectionWiFiProfile.GetSecurityType(ProfileHandle, out value);
149 if ((ConnectionError)ret != ConnectionError.None)
151 Log.Error(Globals.LogTag, "It failed to get security type, " + (ConnectionError)ret);
153 return (WiFiSecurityType)value;
158 /// The encryption type of WiFi.
160 /// <since_tizen> 3 </since_tizen>
161 /// <value>Encryption mode of the WiFi.</value>
162 public WiFiEncryptionType EncryptionType
167 int ret = Interop.ConnectionWiFiProfile.GetEncryptionType(ProfileHandle, out value);
168 if ((ConnectionError)ret != ConnectionError.None)
170 Log.Error(Globals.LogTag, "It failed to get encryption type, " + (ConnectionError)ret);
172 return (WiFiEncryptionType)value;
177 /// Checks whether passphrase is required.
179 /// <since_tizen> 3 </since_tizen>
180 /// <value>True if a passphrase is required, otherwise false.</value>
181 /// <remarks>This property is not valid if <c>WiFiSecurityType</c> is <c>Eap</c>.</remarks>
182 public bool PassphraseRequired
187 int ret = Interop.ConnectionWiFiProfile.IsRequiredPassphrase(ProfileHandle, out value);
188 if ((ConnectionError)ret != ConnectionError.None)
190 Log.Error(Globals.LogTag, "It failed to get PassphraseRequired, " + (ConnectionError)ret);
197 /// Checks whether the WPS (Wi-Fi Protected Setup) is supported.
199 /// <since_tizen> 3 </since_tizen>
200 /// <value>True if WPS is supported, otherwise false.</value>
201 public bool WpsSupported
206 int ret = Interop.ConnectionWiFiProfile.IsSupportedWps(ProfileHandle, out value);
207 if ((ConnectionError)ret != ConnectionError.None)
209 Log.Error(Globals.LogTag, "It failed to get IsSupportedWps, " + (ConnectionError)ret);
216 /// Sets the passphrase of the Wi-Fi WPA.
218 /// <since_tizen> 3 </since_tizen>
219 /// <param name="passphrase">The passphrase of Wi-Fi security</param>
220 /// <feature>http://tizen.org/feature/network.wifi</feature>
221 /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
222 /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
223 /// <exception cref="System.ArgumentNullException">Thrown when passphrase is null.</exception>
224 /// <exception cref="System.InvalidOperationException">Thrown when profile instance is invalid or when method failed due to invalid operation.</exception>
225 /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
226 public void SetPassphrase(string passphrase)
229 if (passphrase != null)
231 int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, passphrase);
232 if ((ConnectionError)ret != ConnectionError.None)
234 Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret);
235 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi");
236 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
237 ConnectionErrorFactory.ThrowConnectionException(ret);
243 throw new ArgumentNullException("Value of passphrase is null");