From 403ce32c3f421aa74319560e2c4c0535fb361688 Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Wed, 31 May 2017 10:25:53 +0900 Subject: [PATCH] [TCSACR-27] Implemented new apis and properties 1. Add AddRoute() and RemoveRoute() to ConnectionManager 2. Add DhcpServerAddress to IAddressInformation 3. Add CellularAuthInfo to CellularProfile 4. Fixed setter of Dns1 and Dns2 in IAddressInformation Change-Id: Id1486f164de269ad61d9abd84267326acac9d500 Signed-off-by: cheoleun --- packaging/csapi-network-connection.spec | 2 +- .../Interop/Interop.Connection.cs | 13 +- .../Tizen.Network.Connection.csproj | 2 +- .../Tizen.Network.Connection/CellularProfile.cs | 161 ++++++--------------- .../ConnectionInternalManager.cs | 46 ++++++ .../Tizen.Network.Connection/ConnectionManager.cs | 48 ++++++ .../Tizen.Network.Connection/ConnectionProfile.cs | 36 +++-- .../IAddressInformation.cs | 33 ++++- 8 files changed, 206 insertions(+), 135 deletions(-) diff --git a/packaging/csapi-network-connection.spec b/packaging/csapi-network-connection.spec index 7f42220..f107151 100755 --- a/packaging/csapi-network-connection.spec +++ b/packaging/csapi-network-connection.spec @@ -1,6 +1,6 @@ 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 diff --git a/src/Tizen.Network.Connection/Interop/Interop.Connection.cs b/src/Tizen.Network.Connection/Interop/Interop.Connection.cs index 5563025..89011c8 100755 --- a/src/Tizen.Network.Connection/Interop/Interop.Connection.cs +++ b/src/Tizen.Network.Connection/Interop/Interop.Connection.cs @@ -75,6 +75,12 @@ internal static partial class Interop [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); @@ -198,6 +204,9 @@ internal static partial class Interop [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); @@ -217,7 +226,7 @@ internal static partial class Interop 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); @@ -244,7 +253,7 @@ internal static partial class Interop 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); diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection.csproj b/src/Tizen.Network.Connection/Tizen.Network.Connection.csproj index 4bf81dd..2ab4365 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection.csproj +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection.csproj @@ -1,7 +1,7 @@  - 1.0.18 + 1.0.19 Samsung Electronics © Samsung Electronics Co., Ltd All Rights Reserved Provides the Connection APIs for Tizen .NET diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs index 77d0319..325bc45 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs @@ -28,11 +28,8 @@ namespace Tizen.Network.Connection /// 3 public class CellularProfile : ConnectionProfile { - private CellularAuthInformation AuthInfo; - internal CellularProfile(IntPtr handle): base(handle) { - AuthInfo = new CellularAuthInformation(handle); } ~CellularProfile() @@ -175,7 +172,7 @@ namespace Tizen.Network.Connection } } - /// + /// /// The cellular pdn type. /// /// 3 @@ -265,8 +262,47 @@ namespace Tizen.Network.Connection { 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"); + } + } } /// @@ -333,15 +369,11 @@ namespace Tizen.Network.Connection /// 3 public class CellularAuthInformation { - private IntPtr ProfileHandle; - - private string Name = ""; - private string Passwd = ""; - private CellularAuthType AuthenType = CellularAuthType.None; - - internal CellularAuthInformation(IntPtr handle) + /// + /// Default Constructor.Initializes an object of CellularAuthInformation. + /// + public CellularAuthInformation() { - ProfileHandle = handle; } /// @@ -349,118 +381,19 @@ namespace Tizen.Network.Connection /// 3 /// /// Cellular user name. - 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;} /// /// The password /// /// 3 /// Cellular password. - 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; } /// /// The authentication type /// /// 3 /// Cellular authentication type. - 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; } } } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs index 715d02d..cad51a7 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs @@ -400,6 +400,7 @@ namespace Tizen.Network.Connection 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) @@ -472,6 +473,7 @@ namespace Tizen.Network.Connection 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; @@ -509,6 +511,50 @@ namespace Tizen.Network.Connection } } + 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 diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs index 0a6f3d8..0b574b5 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs @@ -294,6 +294,54 @@ namespace Tizen.Network.Connection } /// + /// Adds a route to the routing table. + /// + /// The address family + /// The name of network interface + /// The IP address of the host + /// The gateway address + /// http://tizen.org/privilege/network.get + /// http://tizen.org/privilege/network.set + /// 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 + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when interfaceName or hostAddress or gateway is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation. + public static void AddRoute(AddressFamily family, string interfaceName, System.Net.IPAddress hostAddress, System.Net.IPAddress gateway) + { + ConnectionInternalManager.Instance.AddRoute(family, interfaceName, hostAddress, gateway); + } + + /// + /// Removes a route from the routing table. + /// + /// The address family + /// The name of network interface + /// The IP address of the host + /// The gateway address + /// http://tizen.org/privilege/network.get + /// http://tizen.org/privilege/network.set + /// 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 + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when interfaceName or hostAddress or gateway is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation. + public static void RemoveRoute(AddressFamily family, string interfaceName, System.Net.IPAddress hostAddress, System.Net.IPAddress gateway) + { + ConnectionInternalManager.Instance.RemoveRoute(family, interfaceName, hostAddress, gateway); + } + + /// /// Type and state of the current profile for data connection /// /// 3 diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs index 0819f96..87fc8a2 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs @@ -284,22 +284,28 @@ namespace Tizen.Network.Connection /// Thrown when operation is performed on a disposed object. 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; } /// diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs index bd2ff74..5185186 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs @@ -109,6 +109,12 @@ namespace Tizen.Network.Connection /// Thrown during set when value is invalid parameter. /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. DnsConfigType DnsConfigType { get; set; } + + /// + /// The DHCP server address. It is only supported for IPV4 address family. + /// + /// Server address of the DHCP. + System.Net.IPAddress DhcpServerAddress { get; } } internal class ConnectionAddressInformation : IAddressInformation @@ -141,7 +147,7 @@ namespace Tizen.Network.Connection 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); @@ -170,7 +176,7 @@ namespace Tizen.Network.Connection 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); @@ -350,5 +356,28 @@ namespace Tizen.Network.Connection } } } + + 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); + } + } + } } } -- 2.7.4