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
30 private Interop.WiFi.SafeWiFiAPHandle _apHandle;
31 private IAddressInformation _ipv4;
32 private IAddressInformation _ipv6;
33 private string _essid;
36 /// The Extended Service Set Identifier(ESSID).
42 if (string.IsNullOrEmpty(_essid))
45 int ret = Interop.WiFi.AP.GetEssid(_apHandle, out strPtr);
46 if (ret != (int)WiFiError.None)
48 Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
53 _essid = Marshal.PtrToStringAnsi(strPtr);
61 /// The Basic Service Set Identifier(BSSID).
68 int ret = Interop.WiFi.AP.GetBssid(_apHandle, out strPtr);
69 if (ret != (int)WiFiError.None)
71 Log.Error(Globals.LogTag, "Failed to get bssid, Error - " + (WiFiError)ret);
74 return Marshal.PtrToStringAnsi(strPtr);
79 /// The address informaiton for IPv4.
81 public IAddressInformation IPv4Setting
90 /// The address ainformation for IPv6.
92 public IAddressInformation IPv6Setting
101 /// The proxy address.
103 public string ProxyAddress
108 int ret = Interop.WiFi.AP.GetProxyAddress(_apHandle, (int)AddressFamily.IPv4, out strPtr);
109 if (ret != (int)WiFiError.None)
111 Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret);
114 return Marshal.PtrToStringAnsi(strPtr);
118 int ret = Interop.WiFi.AP.SetProxyAddress(_apHandle, (int)AddressFamily.IPv4, value);
119 if (ret != (int)WiFiError.None)
121 Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret);
127 /// The proxy type(IPv6).
129 public WiFiProxyType ProxyType
134 int ret = Interop.WiFi.AP.GetProxyType(_apHandle, out type);
135 if (ret != (int)WiFiError.None)
137 Log.Error(Globals.LogTag, "Failed to get proxy type, Error - " + (WiFiError)ret);
139 return (WiFiProxyType)type;
143 int ret = Interop.WiFi.AP.SetProxyType(_apHandle, (int)value);
144 if (ret != (int)WiFiError.None)
146 Log.Error(Globals.LogTag, "Failed to set proxy type, Error - " + (WiFiError)ret);
152 /// The frequency band(MHz).
159 int ret = Interop.WiFi.AP.GetFrequency(_apHandle, out freq);
160 if (ret != (int)WiFiError.None)
162 Log.Error(Globals.LogTag, "Failed to get frequency, Error - " + (WiFiError)ret);
169 /// The Received signal strength indication(RSSI).
171 public WiFiRssiLevel Rssi
176 int ret = Interop.WiFi.AP.GetRssi(_apHandle, out rssi);
177 if (ret != (int)WiFiError.None)
179 Log.Error(Globals.LogTag, "Failed to get rssi, Error - " + (WiFiError)ret);
181 return (WiFiRssiLevel)rssi;
186 /// The max speed (Mbps).
193 int ret = Interop.WiFi.AP.GetMaxSpeed(_apHandle, out maxSpeed);
194 if (ret != (int)WiFiError.None)
196 Log.Error(Globals.LogTag, "Failed to get max speed, Error - " + (WiFiError)ret);
203 /// A property to check whether the access point is favorite or not.
205 public bool IsFavorite
210 int ret = Interop.WiFi.AP.IsFavorite(_apHandle, out isFavorite);
211 if (ret != (int)WiFiError.None)
213 Log.Error(Globals.LogTag, "Failed to get favorite, Error - " + (WiFiError)ret);
220 /// A property to check whether the access point is passpoint or not.
222 public bool IsPasspoint
227 Log.Debug(Globals.LogTag, "Handle: " + _apHandle);
228 int ret = Interop.WiFi.AP.IsPasspoint(_apHandle, out isPasspoint);
229 if (ret != (int)WiFiError.None)
231 Log.Error(Globals.LogTag, "Failed to get isPassport, Error - " + (WiFiError)ret);
238 /// The connection state.
240 public WiFiConnectionState ConnectionState
245 int ret = Interop.WiFi.AP.GetConnectionState(_apHandle, out state);
246 if (ret != (int)WiFiError.None)
248 Log.Error(Globals.LogTag, "Failed to get connection state, Error - " + (WiFiError)ret);
250 return (WiFiConnectionState)state;
254 internal WiFiNetwork(Interop.WiFi.SafeWiFiAPHandle apHandle)
256 _apHandle = apHandle;
257 _ipv4 = new WiFiAddressInformation(apHandle, AddressFamily.IPv4);
258 _ipv6 = new WiFiAddressInformation(apHandle, AddressFamily.IPv6);
261 int ret = Interop.WiFi.AP.GetEssid(_apHandle, out strPtr);
262 if (ret != (int)WiFiError.None)
264 Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
266 _essid = Marshal.PtrToStringAnsi(strPtr);
268 } //WiFiNetworkInformation