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 information. It allows applications to manager network information.
27 /// This class is not intended to create instance directly from applications.
29 public class WiFiNetwork : IDisposable
31 private IntPtr _apHandle = IntPtr.Zero;
32 private IAddressInformation _ipv4;
33 private IAddressInformation _ipv6;
34 private bool disposed = false;
35 private string _essid;
38 /// The Extended Service Set Identifier(ESSID).
44 if (string.IsNullOrEmpty(_essid))
47 int ret = Interop.WiFi.Ap.GetEssid(_apHandle, out strPtr);
48 if (ret != (int)WiFiError.None)
50 Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
55 _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);
79 /// The address informaiton for Ipv4.
81 public IAddressInformation Ipv4Setting
89 /// The address ainformation for Ipv6.
91 public IAddressInformation Ipv6Setting
99 /// The proxy address.
101 public string ProxyAddress
106 int ret = Interop.WiFi.Ap.GetProxyAddress(_apHandle, (int)AddressFamily.Ipv4, out strPtr);
107 if (ret != (int)WiFiError.None)
109 Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret);
112 return Marshal.PtrToStringAnsi(strPtr);
116 int ret = Interop.WiFi.Ap.SetProxyAddress(_apHandle, (int)AddressFamily.Ipv4, value);
117 if (ret != (int)WiFiError.None)
119 Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret);
124 /// The proxy type(Ipv6).
126 public WiFiProxyType ProxyType
131 int ret = Interop.WiFi.Ap.GetProxyType(_apHandle, out type);
132 if (ret != (int)WiFiError.None)
134 Log.Error(Globals.LogTag, "Failed to get proxy type, Error - " + (WiFiError)ret);
136 return (WiFiProxyType)type;
140 int ret = Interop.WiFi.Ap.SetProxyType(_apHandle, (int)value);
141 if (ret != (int)WiFiError.None)
143 Log.Error(Globals.LogTag, "Failed to set proxy type, Error - " + (WiFiError)ret);
148 /// The frequency band(MHz).
155 int ret = Interop.WiFi.Ap.GetFrequency(_apHandle, out freq);
156 if (ret != (int)WiFiError.None)
158 Log.Error(Globals.LogTag, "Failed to get frequency, Error - " + (WiFiError)ret);
164 /// The Received signal strength indication(RSSI).
171 int ret = Interop.WiFi.Ap.GetRssi(_apHandle, out rssi);
172 if (ret != (int)WiFiError.None)
174 Log.Error(Globals.LogTag, "Failed to get rssi, Error - " + (WiFiError)ret);
180 /// Rhe max speed (Mbps).
187 int ret = Interop.WiFi.Ap.GetMaxSpeed(_apHandle, out maxSpeed);
188 if (ret != (int)WiFiError.None)
190 Log.Error(Globals.LogTag, "Failed to get max speed, Error - " + (WiFiError)ret);
196 /// A property to check whether the access point is favorite or not.
198 public bool IsFavorite
203 int ret = Interop.WiFi.Ap.IsFavorite(_apHandle, out isFavorite);
204 if (ret != (int)WiFiError.None)
206 Log.Error(Globals.LogTag, "Failed to get favorite, Error - " + (WiFiError)ret);
212 /// A property to check whether the access point is passpoint or not.
214 public bool IsPasspoint
219 Log.Debug(Globals.LogTag, "Handle: " + _apHandle);
220 int ret = Interop.WiFi.Ap.IsPasspoint(_apHandle, out isPasspoint);
221 if (ret != (int)WiFiError.None)
223 Log.Error(Globals.LogTag, "Failed to get isPassport, Error - " + (WiFiError)ret);
229 /// The connection state.
231 public WiFiConnectionState ConnectionState
236 int ret = Interop.WiFi.Ap.GetConnectionState(_apHandle, out state);
237 if (ret != (int)WiFiError.None)
239 Log.Error(Globals.LogTag, "Failed to get connection state, Error - " + (WiFiError)ret);
241 return (WiFiConnectionState)state;
245 internal WiFiNetwork(IntPtr apHandle)
247 _apHandle = apHandle;
248 _ipv4 = new WiFiAddressInformation(apHandle, AddressFamily.Ipv4);
249 _ipv6 = new WiFiAddressInformation(apHandle, AddressFamily.Ipv6);
252 int ret = Interop.WiFi.Ap.GetEssid(_apHandle, out strPtr);
253 if (ret != (int)WiFiError.None)
255 Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
257 _essid = Marshal.PtrToStringAnsi(strPtr);
265 public void Dispose()
268 GC.SuppressFinalize(this);
271 private void Dispose(bool disposing)
281 _apHandle = IntPtr.Zero;
285 } //WiFiNetworkInformation