/*
* 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 Tizen.Network.Connection;
namespace Tizen.Network.WiFi
{
///
/// A class for managing the Wi-Fi security information.
///
/// 3
public class WiFiSecurity
{
private Interop.WiFi.SafeWiFiAPHandle _apHandle;
private WiFiEap _eap;
///
/// The type of Wi-Fi security.
///
/// 3
/// Represents the security type of the Wi-Fi.
/// Thrown while setting this property when Wi-Fi is not supported.
/// Thrown while setting this property due to an invalid parameter.
/// Thrown while setting this value due to an invalid operation.
public WiFiSecurityType SecurityType
{
get
{
int type;
int ret = Interop.WiFi.AP.GetSecurityType(_apHandle, out type);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to get security type, Error - " + (WiFiError)ret);
}
return (WiFiSecurityType)type;
}
set
{
int ret = Interop.WiFi.AP.SetSecurityType(_apHandle, (int)value);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to set security type, Error - " + (WiFiError)ret);
WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
}
}
}
///
/// The type of Wi-Fi encryption.
///
/// 3
/// Represents the encryption type of the Wi-Fi.
/// Thrown while setting this property when Wi-Fi is not supported.
/// Thrown while setting this property due to an invalid parameter.
/// Thrown while setting this value due to an invalid operation.
public WiFiEncryptionType EncryptionType
{
get
{
int type;
int ret = Interop.WiFi.AP.GetEncryptionType(_apHandle, out type);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to get encryption type, Error - " + (WiFiError)ret);
}
return (WiFiEncryptionType)type;
}
set
{
int ret = Interop.WiFi.AP.SetEncryptionType(_apHandle, (int)value);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to set encryption type, Error - " + (WiFiError)ret);
WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
}
}
}
///
/// The EAP information.
///
/// 3
/// EAP information of the Wi-Fi.
public WiFiEap EapInformation
{
get
{
return _eap;
}
}
///
/// A property to check whether the passphrase is required or not.
///
/// 3
/// Boolean value to check if the passphrase is required or not.
public bool IsPassphraseRequired
{
get
{
bool required;
int ret = Interop.WiFi.AP.IsPassphraseRequired(_apHandle, out required);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to get isPassportRequired, Error - " + (WiFiError)ret);
}
return required;
}
}
///
/// A property to check whether Wi-Fi Protected Setup (WPS) is supported.
///
/// 3
/// Boolean value to check if WPS is supported.
public bool IsWpsSupported
{
get
{
bool supported;
int ret = Interop.WiFi.AP.IsWpsSupported(_apHandle, out supported);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to get isWapSupported, Error - " + (WiFiError)ret);
}
return supported;
}
}
internal WiFiSecurity(Interop.WiFi.SafeWiFiAPHandle apHandle)
{
_apHandle = apHandle;
_eap = new WiFiEap(apHandle);
}
///
/// Sets the passphrase.
///
/// 3
/// The passphrase of the access point.
/// http://tizen.org/feature/network.wifi
/// Thrown when Wi-Fi is not supported.
/// Thrown when the passphrase is passed as null.
/// Thrown when the method failed due to an invalid parameter.
/// Thrown when the method failed due to an invalid operation.
public void SetPassphrase(string passphrase)
{
if (passphrase == null)
{
throw new ArgumentNullException("Passphrase is null");
}
int ret = Interop.WiFi.AP.SetPassphrase(_apHandle, passphrase);
if (ret != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Failed to set passphrase, Error - " + (WiFiError)ret);
WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
}
}
} //WiFiSecurityInformation
}