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 is the WiFiProfile class. 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)
36 /// Destroy the WiFiProfile object
43 /// The ESSID (Extended Service Set Identifier).
45 /// <since_tizen> 3 </since_tizen>
46 /// <value>ESSID of the WiFi.</value>
52 int ret = Interop.ConnectionWiFiProfile.GetEssid(ProfileHandle, out value);
53 if ((ConnectionError)ret != ConnectionError.None)
55 Log.Error(Globals.LogTag, "It failed to create profile handle, " + (ConnectionError)ret);
57 string result = Marshal.PtrToStringAnsi(value);
58 Interop.Libc.Free(value);
64 /// The BSSID (Basic Service Set Identifier).
66 /// <since_tizen> 3 </since_tizen>
67 /// <value>BSSID of the WiFi.</value>
73 int ret = Interop.ConnectionWiFiProfile.GetBssid(ProfileHandle, out value);
74 if ((ConnectionError)ret != ConnectionError.None)
76 Log.Error(Globals.LogTag, "It failed to get bssid, " + (ConnectionError)ret);
78 string result = Marshal.PtrToStringAnsi(value);
79 Interop.Libc.Free(value);
87 /// <since_tizen> 3 </since_tizen>
88 /// <value>RSSI of the WiFi.</value>
94 int ret = Interop.ConnectionWiFiProfile.GetRssi(ProfileHandle, out value);
95 if ((ConnectionError)ret != ConnectionError.None)
97 Log.Error(Globals.LogTag, "It failed to get rssi, " + (ConnectionError)ret);
104 /// The frequency (MHz).
106 /// <since_tizen> 3 </since_tizen>
107 /// <value>Frequency of the WiFi.</value>
113 int ret = Interop.ConnectionWiFiProfile.GetFrequency(ProfileHandle, out value);
114 if ((ConnectionError)ret != ConnectionError.None)
116 Log.Error(Globals.LogTag, "It failed to get frequency, " + (ConnectionError)ret);
123 /// The max speed (Mbps).
125 /// <since_tizen> 3 </since_tizen>
126 /// <value>Maximum speed of the WiFi.</value>
132 int ret = Interop.ConnectionWiFiProfile.GetMaxSpeed(ProfileHandle, out value);
133 if ((ConnectionError)ret != ConnectionError.None)
135 Log.Error(Globals.LogTag, "It failed to get max speed, " + (ConnectionError)ret);
142 /// The security type of WiFi.
144 /// <since_tizen> 3 </since_tizen>
145 /// <value>Security type of the WiFi.</value>
146 public WiFiSecurityType SecurityType
151 int ret = Interop.ConnectionWiFiProfile.GetSecurityType(ProfileHandle, out value);
152 if ((ConnectionError)ret != ConnectionError.None)
154 Log.Error(Globals.LogTag, "It failed to get security type, " + (ConnectionError)ret);
156 return (WiFiSecurityType)value;
161 /// The encryption type of WiFi.
163 /// <since_tizen> 3 </since_tizen>
164 /// <value>Encryption mode of the WiFi.</value>
165 public WiFiEncryptionType EncryptionType
170 int ret = Interop.ConnectionWiFiProfile.GetEncryptionType(ProfileHandle, out value);
171 if ((ConnectionError)ret != ConnectionError.None)
173 Log.Error(Globals.LogTag, "It failed to get encryption type, " + (ConnectionError)ret);
175 return (WiFiEncryptionType)value;
180 /// Checks whether passphrase is required.
182 /// <since_tizen> 3 </since_tizen>
183 /// <value>True if a passphrase is required, otherwise false.</value>
184 /// <remarks>This property is not valid if <c>WiFiSecurityType</c> is <c>Eap</c>.</remarks>
185 public bool PassphraseRequired
190 int ret = Interop.ConnectionWiFiProfile.IsRequiredPassphrase(ProfileHandle, out value);
191 if ((ConnectionError)ret != ConnectionError.None)
193 Log.Error(Globals.LogTag, "It failed to get PassphraseRequired, " + (ConnectionError)ret);
200 /// Checks whether the WPS (Wi-Fi Protected Setup) is supported.
202 /// <since_tizen> 3 </since_tizen>
203 /// <value>True if WPS is supported, otherwise false.</value>
204 public bool WpsSupported
209 int ret = Interop.ConnectionWiFiProfile.IsSupportedWps(ProfileHandle, out value);
210 if ((ConnectionError)ret != ConnectionError.None)
212 Log.Error(Globals.LogTag, "It failed to get IsSupportedWps, " + (ConnectionError)ret);
219 /// Sets the passphrase of the Wi-Fi WPA.
221 /// <since_tizen> 3 </since_tizen>
222 /// <param name="passphrase">The passphrase of Wi-Fi security.</param>
223 /// <feature>http://tizen.org/feature/network.wifi</feature>
224 /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
225 /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
226 /// <exception cref="System.ArgumentNullException">Thrown when a passphrase is null.</exception>
227 /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
228 /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
229 public void SetPassphrase(string passphrase)
232 if (passphrase != null)
234 int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, passphrase);
235 if ((ConnectionError)ret != ConnectionError.None)
237 Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret);
238 ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi");
239 ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
240 ConnectionErrorFactory.ThrowConnectionException(ret);
246 throw new ArgumentNullException("Value of passphrase is null");