Name: csapi-network-connection
Summary: Tizen Connection API for C#
-Version: 1.0.18
+Version: 1.0.19
Release: 1
Group: Development/Libraries
License: Apache-2.0
[DllImport(Libraries.Connection, EntryPoint = "connection_reset_statistics")]
public static extern int ResetStatistics(IntPtr handle, int connectionType, int statisticsType);
+ [DllImport(Libraries.Connection, EntryPoint = "connection_add_route_entry")]
+ public static extern int AddRoute(IntPtr handle, AddressFamily family, string interfaceName, string address, string gateway);
+
+ [DllImport(Libraries.Connection, EntryPoint = "connection_remove_route_entry")]
+ public static extern int RemoveRoute(IntPtr handle, AddressFamily family, string interfaceName, string address, string gateway);
+
[DllImport(Libraries.Connection, EntryPoint = "connection_set_type_changed_cb")]
public static extern int SetTypeChangedCallback(IntPtr handle, ConnectionTypeChangedCallback callback, IntPtr userData);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_dns_config_type")]
public static extern int GetDnsConfigType(IntPtr profileHandle, int family, out int type);
+ [DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_dhcp_server_address")]
+ public static extern int GetDhcpServerAddress(IntPtr profileHandle, AddressFamily family, out string dhcpServerAddress);
+
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_refresh")]
public static extern int Refresh(IntPtr profileHandle);
public static extern int SetGatewayAddress(IntPtr profileHandle, int family, string address);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_dns_address")]
- public static extern int SetDnsAddress(IntPtr profileHandle, int family, string address);
+ public static extern int SetDnsAddress(IntPtr profileHandle, int order, int family, string address);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_proxy_address")]
public static extern int SetProxyAddress(IntPtr profileHandle, int family, string address);
public static extern int GetApn(IntPtr profileHandle, out IntPtr apn);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_cellular_auth_info")]
- public static extern int GetAuthInfo(IntPtr profileHandle, out int authType, out IntPtr name, out IntPtr password);
+ public static extern int GetAuthInfo(IntPtr profileHandle, out int authType, out string name, out string password);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_cellular_home_url")]
public static extern int GetHomeUrl(IntPtr profileHandle, out IntPtr homeUrl);
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <Version>1.0.18</Version>
+ <Version>1.0.19</Version>
<Authors>Samsung Electronics</Authors>
<Copyright>© Samsung Electronics Co., Ltd All Rights Reserved</Copyright>
<Description>Provides the Connection APIs for Tizen .NET</Description>
/// <since_tizen> 3 </since_tizen>
public class CellularProfile : ConnectionProfile
{
- private CellularAuthInformation AuthInfo;
-
internal CellularProfile(IntPtr handle): base(handle)
{
- AuthInfo = new CellularAuthInformation(handle);
}
~CellularProfile()
}
}
- /// <summary>
+ /// <summary>
/// The cellular pdn type.
/// </summary>
/// <since_tizen> 3 </since_tizen>
{
get
{
+ int type;
+ string name;
+ string password;
+ int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to get cellular authentication information, " + (ConnectionError)ret);
+ return null;
+ }
+
+ CellularAuthInformation AuthInfo = new CellularAuthInformation();
+ AuthInfo.AuthType = (CellularAuthType)type;
+ AuthInfo.UserName = name;
+ AuthInfo.Password = password;
return AuthInfo;
}
+
+ set
+ {
+ CheckDisposed();
+ if (value != null)
+ {
+ CellularAuthInformation AuthInfo = value;
+ int type = (int)AuthInfo.AuthType;
+ string name = AuthInfo.UserName;
+ string password = AuthInfo.Password;
+ int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, type, name, password);
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+ }
+
+ else
+ {
+ throw new ArgumentNullException("CellularAuthInformation value is null");
+ }
+ }
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
public class CellularAuthInformation
{
- private IntPtr ProfileHandle;
-
- private string Name = "";
- private string Passwd = "";
- private CellularAuthType AuthenType = CellularAuthType.None;
-
- internal CellularAuthInformation(IntPtr handle)
+ /// <summary>
+ /// Default Constructor.Initializes an object of CellularAuthInformation.
+ /// </summary>
+ public CellularAuthInformation()
{
- ProfileHandle = handle;
}
/// <summary>
/// <since_tizen> 3 </since_tizen>
/// </summary>
/// <value>Cellular user name.</value>
- public string UserName
- {
- get
- {
- int type;
- IntPtr name;
- IntPtr password;
-
- int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get auth information, " + (ConnectionError)ret);
- }
-
- Name = Marshal.PtrToStringAnsi(name);
- Passwd = Marshal.PtrToStringAnsi(name);
- AuthenType = (CellularAuthType)type;
-
- Interop.Libc.Free(name);
- Interop.Libc.Free(password);
-
- return Name;
- }
- set
- {
- Name = value;
- int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, (int)AuthenType, (string)value, Passwd);
- Log.Error(Globals.LogTag, "UserName : "+ value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
- }
- }
-
+ public string UserName { get; set;}
/// <summary>
/// The password
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value>Cellular password.</value>
- public string Password
- {
- get
- {
- int type;
- IntPtr name;
- IntPtr password;
-
- int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get auth information, " + (ConnectionError)ret);
- }
- Name = Marshal.PtrToStringAnsi(name);
- Passwd = Marshal.PtrToStringAnsi(password);
- AuthenType = (CellularAuthType)type;
-
- Interop.Libc.Free(name);
- Interop.Libc.Free(password);
-
- return Passwd;
- }
- set
- {
- Passwd = value;
- int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, (int)AuthenType, Name, (string)value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
- }
- }
+ public string Password { get; set; }
/// <summary>
/// The authentication type
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <value>Cellular authentication type.</value>
- public CellularAuthType AuthType
- {
- get
- {
- int type;
- IntPtr name;
- IntPtr password;
-
- int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get auth information, " + (ConnectionError)ret);
- }
-
- Name = Marshal.PtrToStringAnsi(name);
- Passwd = Marshal.PtrToStringAnsi(name);
- AuthenType = (CellularAuthType)type;
-
- Interop.Libc.Free(name);
- Interop.Libc.Free(password);
- return AuthenType;
- }
- set
- {
- AuthenType = value;
- int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, (int)value, Name, Passwd);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
- }
- }
+ public CellularAuthType AuthType { get; set; }
}
}
internal System.Net.IPAddress GetIPAddress(AddressFamily family)
{
+ Log.Debug(Globals.LogTag, "GetIPAddress " + family);
IntPtr ip;
int ret = Interop.Connection.GetIPAddress(GetHandle(), (int)family, out ip);
if ((ConnectionError)ret != ConnectionError.None)
ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released");
ConnectionErrorFactory.ThrowConnectionException(ret);
}
+
string result = Marshal.PtrToStringAnsi(mac);
Interop.Libc.Free(mac);
return result;
}
}
+ internal void AddRoute(AddressFamily family, string interfaceName, System.Net.IPAddress address, System.Net.IPAddress gateway)
+ {
+ if (interfaceName != null && address != null && gateway != null)
+ {
+ Log.Debug(Globals.LogTag, "AddRoute " + family + ", " + interfaceName + ", " + address + ", " + gateway);
+ int ret = Interop.Connection.AddRoute(GetHandle(), family, interfaceName, address.ToString(), gateway.ToString());
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to add route to the routing table, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet");
+ ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+ }
+
+ else
+ {
+ throw new ArgumentNullException("Arguments are null");
+ }
+ }
+
+ internal void RemoveRoute(AddressFamily family, string interfaceName, System.Net.IPAddress address, System.Net.IPAddress gateway)
+ {
+ if (interfaceName != null && address != null && gateway != null)
+ {
+ Log.Debug(Globals.LogTag, "RemoveRoute " + family + ", " + interfaceName + ", " + address + ", " + gateway);
+ int ret = Interop.Connection.RemoveRoute(GetHandle(), family, interfaceName, address.ToString(), gateway.ToString());
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to remove route from the routing table, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet");
+ ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+ }
+
+ else
+ {
+ throw new ArgumentNullException("Arguments are null");
+ }
+ }
+
internal ConnectionType ConnectionType
{
get
}
/// <summary>
+ /// Adds a route to the routing table.
+ /// </summary>
+ /// <param name="family">The address family</param>
+ /// <param name="interfaceName">The name of network interface</param>
+ /// <param name="hostAddress">The IP address of the host</param>
+ /// <param name="gateway">The gateway address</param>
+ /// <privilege>http://tizen.org/privilege/network.get</privilege>
+ /// <privilege>http://tizen.org/privilege/network.set</privilege>
+ /// <feature>http://tizen.org/feature/network.telephony</feature>
+ /// <feature>http://tizen.org/feature/network.wifi</feature>
+ /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
+ /// <feature>http://tizen.org/feature/network.ethernet</feature>
+ /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
+ /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
+ /// <exception cref="System.ArgumentNullException">Thrown when interfaceName or hostAddress or gateway is null.</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
+ public static void AddRoute(AddressFamily family, string interfaceName, System.Net.IPAddress hostAddress, System.Net.IPAddress gateway)
+ {
+ ConnectionInternalManager.Instance.AddRoute(family, interfaceName, hostAddress, gateway);
+ }
+
+ /// <summary>
+ /// Removes a route from the routing table.
+ /// </summary>
+ /// <param name="family">The address family</param>
+ /// <param name="interfaceName">The name of network interface</param>
+ /// <param name="hostAddress">The IP address of the host</param>
+ /// <param name="gateway">The gateway address</param>
+ /// <privilege>http://tizen.org/privilege/network.get</privilege>
+ /// <privilege>http://tizen.org/privilege/network.set</privilege>
+ /// <feature>http://tizen.org/feature/network.telephony</feature>
+ /// <feature>http://tizen.org/feature/network.wifi</feature>
+ /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
+ /// <feature>http://tizen.org/feature/network.ethernet</feature>
+ /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
+ /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
+ /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
+ /// <exception cref="System.ArgumentNullException">Thrown when interfaceName or hostAddress or gateway is null.</exception>
+ /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
+ /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
+ public static void RemoveRoute(AddressFamily family, string interfaceName, System.Net.IPAddress hostAddress, System.Net.IPAddress gateway)
+ {
+ ConnectionInternalManager.Instance.RemoveRoute(family, interfaceName, hostAddress, gateway);
+ }
+
+ /// <summary>
/// Type and state of the current profile for data connection
/// </summary>
/// <since_tizen> 3 </since_tizen>
/// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
public ProfileState GetState(AddressFamily family)
{
- int Value;
- int ret = (int)ConnectionError.None;
- if (family == AddressFamily.IPv4)
- {
- ret = Interop.ConnectionProfile.GetState(ProfileHandle, out Value);
- }
- else
- {
- ret = Interop.ConnectionProfile.GetIPv6State(ProfileHandle, out Value);
- }
+ CheckDisposed();
+ int Value;
+ int ret = (int)ConnectionError.None;
+ if (family == AddressFamily.IPv4)
+ {
+ ret = Interop.ConnectionProfile.GetState(ProfileHandle, out Value);
+ }
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get profile state, " + (ConnectionError)ret);
- }
- return (ProfileState)Value;
+ else
+ {
+ ret = Interop.ConnectionProfile.GetIPv6State(ProfileHandle, out Value);
+ }
+
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to get profile state, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+
+ return (ProfileState)Value;
}
/// <summary>
/// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
/// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
DnsConfigType DnsConfigType { get; set; }
+
+ /// <summary>
+ /// The DHCP server address. It is only supported for IPV4 address family.
+ /// </summary>
+ /// <value>Server address of the DHCP.</value>
+ System.Net.IPAddress DhcpServerAddress { get; }
}
internal class ConnectionAddressInformation : IAddressInformation
set
{
- int ret = Interop.ConnectionProfile.SetDnsAddress(_profileHandle, (int)_family, value.ToString());
+ int ret = Interop.ConnectionProfile.SetDnsAddress(_profileHandle, 1, (int)_family, value.ToString());
if ((ConnectionError)ret != ConnectionError.None)
{
Log.Error(Globals.LogTag, "It failed to set dns1 address, " + (ConnectionError)ret);
set
{
- int ret = Interop.ConnectionProfile.SetDnsAddress(_profileHandle, (int)_family, value.ToString());
+ int ret = Interop.ConnectionProfile.SetDnsAddress(_profileHandle, 2, (int)_family, value.ToString());
if ((ConnectionError)ret != ConnectionError.None)
{
Log.Error(Globals.LogTag, "It failed to set dns2 address, " + (ConnectionError)ret);
}
}
}
+
+ public System.Net.IPAddress DhcpServerAddress
+ {
+ get
+ {
+ string dhcpServer;
+ int ret = Interop.ConnectionProfile.GetDhcpServerAddress(_profileHandle, _family, out dhcpServer);
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to get the DHCP server address, " + (ConnectionError)ret);
+ }
+
+ if (dhcpServer == null)
+ {
+ return System.Net.IPAddress.Parse("0.0.0.0");
+ }
+
+ else
+ {
+ return System.Net.IPAddress.Parse(dhcpServer);
+ }
+ }
+ }
}
}