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;
20 using System.Runtime.InteropServices;
21 using Tizen.Network.Connection;
23 namespace Tizen.Network.WiFi
26 /// A class for managing the Wi-Fi network information.
28 public class WiFiNetwork : IDisposable
30 private IntPtr _apHandle = IntPtr.Zero;
31 private IAddressInformation _ipv4;
32 private IAddressInformation _ipv6;
33 private bool disposed = false;
34 private string _essid;
37 /// The Extended Service Set Identifier(ESSID).
43 if (string.IsNullOrEmpty(_essid))
46 int ret = Interop.WiFi.AP.GetEssid(_apHandle, out strPtr);
47 if (ret != (int)WiFiError.None)
49 Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
54 _essid = Marshal.PtrToStringAnsi(strPtr);
62 /// The Basic Service Set Identifier(BSSID).
69 int ret = Interop.WiFi.AP.GetBssid(_apHandle, out strPtr);
70 if (ret != (int)WiFiError.None)
72 Log.Error(Globals.LogTag, "Failed to get bssid, Error - " + (WiFiError)ret);
75 return Marshal.PtrToStringAnsi(strPtr);
80 /// The address informaiton for IPv4.
82 public IAddressInformation IPv4Setting
91 /// The address ainformation for IPv6.
93 public IAddressInformation IPv6Setting
102 /// The proxy address.
104 public string ProxyAddress
109 int ret = Interop.WiFi.AP.GetProxyAddress(_apHandle, (int)AddressFamily.IPv4, out strPtr);
110 if (ret != (int)WiFiError.None)
112 Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret);
115 return Marshal.PtrToStringAnsi(strPtr);
119 int ret = Interop.WiFi.AP.SetProxyAddress(_apHandle, (int)AddressFamily.IPv4, value);
120 if (ret != (int)WiFiError.None)
122 Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret);
128 /// The proxy type(IPv6).
130 public WiFiProxyType ProxyType
135 int ret = Interop.WiFi.AP.GetProxyType(_apHandle, out type);
136 if (ret != (int)WiFiError.None)
138 Log.Error(Globals.LogTag, "Failed to get proxy type, Error - " + (WiFiError)ret);
140 return (WiFiProxyType)type;
144 int ret = Interop.WiFi.AP.SetProxyType(_apHandle, (int)value);
145 if (ret != (int)WiFiError.None)
147 Log.Error(Globals.LogTag, "Failed to set proxy type, Error - " + (WiFiError)ret);
153 /// The frequency band(MHz).
160 int ret = Interop.WiFi.AP.GetFrequency(_apHandle, out freq);
161 if (ret != (int)WiFiError.None)
163 Log.Error(Globals.LogTag, "Failed to get frequency, Error - " + (WiFiError)ret);
170 /// The Received signal strength indication(RSSI).
172 public WiFiRssiLevel Rssi
177 int ret = Interop.WiFi.AP.GetRssi(_apHandle, out rssi);
178 if (ret != (int)WiFiError.None)
180 Log.Error(Globals.LogTag, "Failed to get rssi, Error - " + (WiFiError)ret);
182 return (WiFiRssiLevel)rssi;
187 /// The max speed (Mbps).
194 int ret = Interop.WiFi.AP.GetMaxSpeed(_apHandle, out maxSpeed);
195 if (ret != (int)WiFiError.None)
197 Log.Error(Globals.LogTag, "Failed to get max speed, Error - " + (WiFiError)ret);
204 /// A property to check whether the access point is favorite or not.
206 public bool IsFavorite
211 int ret = Interop.WiFi.AP.IsFavorite(_apHandle, out isFavorite);
212 if (ret != (int)WiFiError.None)
214 Log.Error(Globals.LogTag, "Failed to get favorite, Error - " + (WiFiError)ret);
221 /// A property to check whether the access point is passpoint or not.
223 public bool IsPasspoint
228 Log.Debug(Globals.LogTag, "Handle: " + _apHandle);
229 int ret = Interop.WiFi.AP.IsPasspoint(_apHandle, out isPasspoint);
230 if (ret != (int)WiFiError.None)
232 Log.Error(Globals.LogTag, "Failed to get isPassport, Error - " + (WiFiError)ret);
239 /// The connection state.
241 public WiFiConnectionState ConnectionState
246 int ret = Interop.WiFi.AP.GetConnectionState(_apHandle, out state);
247 if (ret != (int)WiFiError.None)
249 Log.Error(Globals.LogTag, "Failed to get connection state, Error - " + (WiFiError)ret);
251 return (WiFiConnectionState)state;
255 internal WiFiNetwork(IntPtr apHandle)
257 _apHandle = apHandle;
258 _ipv4 = new WiFiAddressInformation(apHandle, AddressFamily.IPv4);
259 _ipv6 = new WiFiAddressInformation(apHandle, AddressFamily.IPv6);
262 int ret = Interop.WiFi.AP.GetEssid(_apHandle, out strPtr);
263 if (ret != (int)WiFiError.None)
265 Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
267 _essid = Marshal.PtrToStringAnsi(strPtr);
276 /// A method to destroy managed WiFiNetwork objects.
278 public void Dispose()
281 GC.SuppressFinalize(this);
284 private void Dispose(bool disposing)
294 _apHandle = IntPtr.Zero;
298 } //WiFiNetworkInformation