[TCSACR-27] Implemented new apis and properties
authorchleun.moon <chleun.moon@samsung.com>
Wed, 31 May 2017 01:25:53 +0000 (10:25 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Mon, 10 Jul 2017 05:08:24 +0000 (14:08 +0900)
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 <chleun.moon@samsung.com>
packaging/csapi-network-connection.spec
src/Tizen.Network.Connection/Interop/Interop.Connection.cs
src/Tizen.Network.Connection/Tizen.Network.Connection.csproj
src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs

index 7f42220..f107151 100755 (executable)
@@ -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
index 5563025..89011c8 100755 (executable)
@@ -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);
index 4bf81dd..2ab4365 100644 (file)
@@ -1,7 +1,7 @@
 <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>
index 77d0319..325bc45 100755 (executable)
@@ -28,11 +28,8 @@ namespace Tizen.Network.Connection
     /// <since_tizen> 3 </since_tizen>
     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
             }
         }
 
-   /// <summary>
+        /// <summary>
         /// The cellular pdn type.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -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");
+                }
+            }
         }
 
         /// <summary>
@@ -333,15 +369,11 @@ namespace Tizen.Network.Connection
     /// <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>
@@ -349,118 +381,19 @@ namespace Tizen.Network.Connection
         /// <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; }
     }
 }
index 715d02d..cad51a7 100755 (executable)
@@ -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
index 0a6f3d8..0b574b5 100755 (executable)
@@ -294,6 +294,54 @@ namespace Tizen.Network.Connection
         }
 
         /// <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>
index 0819f96..87fc8a2 100755 (executable)
@@ -284,22 +284,28 @@ namespace Tizen.Network.Connection
         /// <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>
index bd2ff74..5185186 100755 (executable)
@@ -109,6 +109,12 @@ namespace Tizen.Network.Connection
         /// <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
@@ -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);
+                }
+            }
+        }
     }
 }