/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace Tizen.Network.Connection { /// /// This is the WiFiProfile class. It provides functions to manage the WiFi profile. /// /// 3 public class WiFiProfile : ConnectionProfile { internal WiFiProfile(IntPtr Handle) : base(Handle) { } /// /// Destroy the WiFiProfile object /// ~WiFiProfile() { } /// /// The ESSID (Extended Service Set Identifier). /// /// 3 /// ESSID of the WiFi. public string Essid { get { IntPtr value; int ret = Interop.ConnectionWiFiProfile.GetEssid(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to create profile handle, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(value); Interop.Libc.Free(value); return result; } } /// /// The BSSID (Basic Service Set Identifier). /// /// 3 /// BSSID of the WiFi. public string Bssid { get { IntPtr value; int ret = Interop.ConnectionWiFiProfile.GetBssid(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get bssid, " + (ConnectionError)ret); } string result = Marshal.PtrToStringAnsi(value); Interop.Libc.Free(value); return result; } } /// /// The RSSI. /// /// 3 /// RSSI of the WiFi. public int Rssi { get { int value; int ret = Interop.ConnectionWiFiProfile.GetRssi(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get rssi, " + (ConnectionError)ret); } return value; } } /// /// The frequency (MHz). /// /// 3 /// Frequency of the WiFi. public int Frequency { get { int value; int ret = Interop.ConnectionWiFiProfile.GetFrequency(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get frequency, " + (ConnectionError)ret); } return value; } } /// /// The max speed (Mbps). /// /// 3 /// Maximum speed of the WiFi. public int MaxSpeed { get { int value; int ret = Interop.ConnectionWiFiProfile.GetMaxSpeed(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get max speed, " + (ConnectionError)ret); } return value; } } /// /// The security type of WiFi. /// /// 3 /// Security type of the WiFi. public WiFiSecurityType SecurityType { get { int value; int ret = Interop.ConnectionWiFiProfile.GetSecurityType(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get security type, " + (ConnectionError)ret); } return (WiFiSecurityType)value; } } /// /// The encryption type of WiFi. /// /// 3 /// Encryption mode of the WiFi. public WiFiEncryptionType EncryptionType { get { int value; int ret = Interop.ConnectionWiFiProfile.GetEncryptionType(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get encryption type, " + (ConnectionError)ret); } return (WiFiEncryptionType)value; } } /// /// Checks whether passphrase is required. /// /// 3 /// True if a passphrase is required, otherwise false. /// This property is not valid if WiFiSecurityType is Eap. public bool PassphraseRequired { get { bool value; int ret = Interop.ConnectionWiFiProfile.IsRequiredPassphrase(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get PassphraseRequired, " + (ConnectionError)ret); } return value; } } /// /// Checks whether the WPS (Wi-Fi Protected Setup) is supported. /// /// 3 /// True if WPS is supported, otherwise false. public bool WpsSupported { get { bool value; int ret = Interop.ConnectionWiFiProfile.IsSupportedWps(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get IsSupportedWps, " + (ConnectionError)ret); } return value; } } /// /// Sets the passphrase of the Wi-Fi WPA. /// /// 3 /// The passphrase of Wi-Fi security. /// http://tizen.org/feature/network.wifi /// Thrown when a feature is not supported. /// Thrown when a value is an invalid parameter. /// Thrown when a passphrase is null. /// Thrown when a profile instance is invalid or when a method fails due to an invalid operation. /// Thrown when an operation is performed on a disposed object. public void SetPassphrase(string passphrase) { CheckDisposed(); if (passphrase != null) { int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, passphrase); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret); ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi"); ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } else { throw new ArgumentNullException("Value of passphrase is null"); } } } }