Below changes are applied
authorSeungyoun Ju <sy39.ju@samsung.com>
Tue, 9 Apr 2013 09:48:27 +0000 (18:48 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Tue, 9 Apr 2013 09:48:27 +0000 (18:48 +0900)
- TETHERING_ERROR_NOT_PERMITTED is added
- Implement connection timer
- Reference count is used
- Add API : tethering_xxx_ip_forward_status()
- TETHERING_ERROR_NOT_SUPPORT_API is added for tethering_create()
- TETHERING_ERROR_NOT_SUPPORT_API is returned when API is not supported
- sysinfo-tethering.xml is installed depending on build machine

Change-Id: I4b1096dd3ee727b324136c2be9b0f50463d61b6a

CMakeLists.txt
include/marshal.list
include/tethering.h
include/tethering.xml
include/tethering_private.h
packaging/capi-network-tethering.spec
src/tethering.c
src/tethering_client.c
sysinfo-tethering.xml [new file with mode: 0644]

index 474670b..153cb1a 100644 (file)
@@ -68,6 +68,10 @@ CONFIGURE_FILE(
     @ONLY
 )
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+MESSAGE("Arch ${ARCH}")
+IF(NOT "${ARCH}" STREQUAL "emul")
+       INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/sysinfo-tethering.xml" DESTINATION "/etc/config/connectivity")
+ENDIF(NOT "${ARCH}" STREQUAL "emul")
 
 ADD_SUBDIRECTORY(test)
 
index 410363f..4cfa58e 100644 (file)
@@ -1,3 +1,3 @@
 # DBUS Signal argument converting list
-VOID:STRING,UINT,STRING,STRING,STRING
+VOID:STRING,UINT,STRING,STRING,STRING,UINT
 
index f68dc5e..71fa7b3 100644 (file)
@@ -18,6 +18,7 @@
 #define __TIZEN_NETWORK_TETHERING_H__
 
 #include <tizen.h>
+#include <time.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,12 +39,14 @@ typedef void * tethering_h;
  */
 typedef enum {
     TETHERING_ERROR_NONE = TIZEN_ERROR_NONE,  /**< Successful */
+    TETHERING_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED,  /**< Operation not permitted */
     TETHERING_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,  /**< Invalid parameter */
     TETHERING_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,  /**< Out of memory */
     TETHERING_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY,  /**< Resource busy */
     TETHERING_ERROR_NOT_ENABLED = TIZEN_ERROR_NETWORK_CLASS | 0x0501,  /**< Not enabled */
     TETHERING_ERROR_OPERATION_FAILED = TIZEN_ERROR_NETWORK_CLASS | 0x0502,  /**< Operation failed */
     TETHERING_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
+    TETHERING_ERROR_NOT_SUPPORT_API = TIZEN_ERROR_NOT_SUPPORT_API, /**< API is not supported */
 } tethering_error_e;
 
 /**
@@ -214,6 +217,7 @@ typedef void (*tethering_wifi_passphrase_changed_cb)(void *user_data);
  * @retval  #TETHERING_ERROR_NONE  Successful
  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval  #TETHERING_ERROR_NOT_SUPPORT_API  API is not supported
  * @see  tethering_destroy()
  */
 int tethering_create(tethering_h *tethering);
@@ -387,6 +391,27 @@ int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb call
 int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data);
 
 /**
+ * @brief Set the ip forward status
+ * @param[in]  tethering  The handle of tethering
+ * @param[in]  status  The ip forward status: (@c true = enable, @c false = disable)
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @see  tethering_get_ip_forward_status()
+ */
+int tethering_set_ip_forward_status(tethering_h tethering, bool status);
+
+/**
+ * @brief Get the ip forward status
+ * @param[in]  tethering  The handle of tethering
+ * @param[out]  status  The ip forward status: (@c true = enable, @c false = disable)
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
+ * @see  tethering_set_ip_forward_status()
+ */
+int tethering_get_ip_forward_status(tethering_h tethering, bool *status);
+
+/**
  * @brief Registers the callback function called when tethering is enabled.
  * @param[in]  tethering  The handle of tethering
  * @param[in]  type  The type of tethering
@@ -717,6 +742,18 @@ int tethering_client_get_ip_address(tethering_client_h client, tethering_address
 int tethering_client_get_mac_address(tethering_client_h client, char **mac_address);
 
 /**
+ * @brief  Gets the connection time of client.
+ * @param[in]  client  The handle of client
+ * @param[out]  time  The connected time of client
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @see  tethering_usb_get_connected_client()
+ * @see  tethering_connection_state_changed_cb()
+ */
+int tethering_client_get_time(tethering_client_h client, time_t *timestamp);
+
+/**
  * @}
  */
 
index 0d5231e..4aee14e 100644 (file)
@@ -9,6 +9,9 @@
 
                <!-- Method definitions -->
 
+               <method name="init">
+               </method>
+
                <method name="deinit">
                </method>
 
@@ -60,7 +63,7 @@
                <method name="get_station_info">
                        <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
                        <arg type="u" name="type" direction="out"/>
-                       <arg type="a(usss)" name="station" direction="out"/>
+                       <arg type="a(usssu)" name="station" direction="out"/>
                </method>
 
                <method name="get_usb_station_info">
                        <arg type="a(ssss)" name="interface" direction="out"/>
                </method>
 
+               <method name="set_ip_forward_status">
+                       <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+                       <arg type="i" name="forward_status" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+
+               <method name="get_ip_forward_status">
+                       <arg type="i" name="forward_status" direction="out"/>
+               </method>
+
                <method name="get_wifi_tethering_hide_mode">
                        <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
                        <arg type="i" name="hide_mode" direction="out"/>
                        <arg type="s" name="ip" direction="out"/>
                        <arg type="s" name="mac" direction="out"/>
                        <arg type="s" name="name" direction="out"/>
+                       <arg type="u" name="time" direction="out"/>
                </signal>
 
                <signal name="security_type_changed">
index 8ad1150..e37f07a 100644 (file)
@@ -202,6 +202,7 @@ typedef enum {
 /**
 * End of mobileap-agent common values
 */
+#define TETHERING_DBUS_MAX_RETRY_COUNT                 3
 
 #define TETHERING_DEFAULT_SSID                         "Redwood"
 #define TETHERING_DEFAULT_PASSPHRASE                   "eoiugkl!"
@@ -242,6 +243,7 @@ typedef struct {
        char ip[TETHERING_STR_INFO_LEN];                /**< assigned IP address */
        char mac[TETHERING_STR_INFO_LEN];               /**< MAC Address */
        char hostname[TETHERING_STR_HOSTNAME_LEN];      /**< alphanumeric name */
+       time_t tm;      /**< connection time */
 } __tethering_client_h;
 
 typedef struct {
index ca0b4e8..695232e 100644 (file)
@@ -29,7 +29,15 @@ Development package for Tethering framework library
 %setup -q
 
 %build
-%cmake .
+%ifarch %{arm}
+%cmake . -DARCH=arm
+%else
+%if 0%{?simulator}
+%cmake . -DARCH=emul
+%else
+%cmake . -DARCH=i586
+%endif
+%endif
 make %{?jobs:-j%jobs}
 
 %install
@@ -43,6 +51,15 @@ make %{?jobs:-j%jobs}
 %manifest capi-network-tethering.manifest
 %defattr(-,root,root,-)
 %{_libdir}/*.so.*
+%ifarch %{arm}
+/etc/config/connectivity/sysinfo-tethering.xml
+%else
+%if 0%{?simulator}
+# Noop
+%else
+/etc/config/connectivity/sysinfo-tethering.xml
+%endif
+%endif
 
 %files devel
 %defattr(-,root,root,-)
index a4c8284..49d3b41 100644 (file)
@@ -116,7 +116,7 @@ static tethering_error_e __get_error(int agent_error)
                break;
 
        case MOBILE_AP_ERROR_NOT_PERMITTED:
-               err = TETHERING_ERROR_OPERATION_FAILED;
+               err = TETHERING_ERROR_NOT_PERMITTED;
                break;
 
        default:
@@ -130,7 +130,7 @@ static tethering_error_e __get_error(int agent_error)
 
 static void __handle_dhcp(DBusGProxy *proxy, const char *member,
                guint interface, const char *ip, const char *mac,
-               const char *name, gpointer user_data)
+               const char *name, guint timestamp, gpointer user_data)
 {
        DBG("+\n");
 
@@ -172,6 +172,7 @@ static void __handle_dhcp(DBusGProxy *proxy, const char *member,
        g_strlcpy(client.ip, ip, sizeof(client.ip));
        g_strlcpy(client.mac, mac, sizeof(client.mac));
        g_strlcpy(client.hostname, name, sizeof(client.hostname));
+       client.tm = (time_t)timestamp;
 
        ccb((tethering_client_h)&client, opened, data);
 
@@ -642,6 +643,19 @@ static void __get_data_usage_cb(DBusGProxy *remoteobj, guint event,
        return;
 }
 
+static void __ip_forward_cb(DBusGProxy *remoteobj, gint result,
+               GError *error, gpointer user_data)
+{
+       _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
+
+       if (error) {
+               ERR("DBus fail [%s]\n", error->message);
+               g_error_free(error);
+       }
+
+       return;
+}
+
 static void __connect_signals(tethering_h tethering)
 {
        _retm_if(tethering == NULL, "parameter(tethering) is NULL\n");
@@ -657,12 +671,12 @@ static void __connect_signals(tethering_h tethering)
                                G_CALLBACK(sigs[i].cb), (gpointer)tethering, NULL);
        }
 
-       dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_STRING_STRING_STRING,
+       dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_STRING_STRING_STRING_UINT,
                        G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING,
-                       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+                       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
        dbus_g_proxy_add_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
                        G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING,
-                       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
+                       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_DHCP_STATUS,
                        G_CALLBACK(__handle_dhcp), (gpointer)tethering, NULL);
 
@@ -823,6 +837,7 @@ static void __wifi_set_passphrase_cb(DBusGProxy *remoteobj,
  * @retval  #TETHERING_ERROR_NONE  Successful
  * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
  * @retval  #TETHERING_ERROR_OUT_OF_MEMORY  Out of memory
+ * @retval  #TETHERING_ERROR_NOT_SUPPORT_API  API is not supported
  * @see  tethering_destroy()
  */
 API int tethering_create(tethering_h *tethering)
@@ -832,6 +847,7 @@ API int tethering_create(tethering_h *tethering)
 
        __tethering_h *th = NULL;
        GError *error = NULL;
+       int retry = TETHERING_DBUS_MAX_RETRY_COUNT;
 
        th = (__tethering_h *)malloc(sizeof(__tethering_h));
        _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY,
@@ -860,6 +876,33 @@ API int tethering_create(tethering_h *tethering)
                return TETHERING_ERROR_OPERATION_FAILED;
        }
 
+       while (retry--) {
+               org_tizen_tethering_init(th->client_bus_proxy, &error);
+               if (error != NULL) {
+                       ERR("Couldn't connect to the System bus[%s]",
+                                       error->message);
+
+                       if (error->code == DBUS_GERROR_SERVICE_UNKNOWN) {
+                               DBG("Tethering is not supported\n");
+                               g_error_free(error);
+                               error = NULL;
+                               dbus_g_connection_unref(th->client_bus);
+                               free(th);
+                               return TETHERING_ERROR_NOT_SUPPORT_API;
+                       }
+
+                       g_error_free(error);
+                       error = NULL;
+                       if (retry == 0) {
+                               dbus_g_connection_unref(th->client_bus);
+                               free(th);
+                               return TETHERING_ERROR_OPERATION_FAILED;
+                       }
+               } else {
+                       break;
+               }
+       }
+
        __connect_signals((tethering_h)th);
 
        *tethering = (tethering_h)th;
@@ -1382,6 +1425,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
        gchar *ip = NULL;
        gchar *mac = NULL;
        gchar *hostname = NULL;
+       guint timestamp = 0;
 
        org_tizen_tethering_get_station_info(th->client_bus_proxy, &event,
                        &array, &error);
@@ -1397,7 +1441,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                g_value_set_boxed(&value, g_ptr_array_index(array, i));
 
                dbus_g_type_struct_get(&value, 0, &interface, 1, &ip,
-                               2, &mac, 3, &hostname, G_MAXUINT);
+                               2, &mac, 3, &hostname, 4, &timestamp, G_MAXUINT);
 
                if (interface == MOBILE_AP_TYPE_USB)
                        client.interface = TETHERING_TYPE_USB;
@@ -1412,6 +1456,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                g_strlcpy(client.ip, ip, sizeof(client.ip));
                g_strlcpy(client.mac, mac, sizeof(client.mac));
                g_strlcpy(client.hostname, hostname, sizeof(client.hostname));
+               client.tm = (time_t)timestamp;
 
                if (callback((tethering_client_h)&client, user_data) == false) {
                        DBG("iteration is stopped\n");
@@ -1426,6 +1471,65 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
 }
 
 /**
+ * @brief Set the ip forward status
+ * @param[in]  tethering  The handle of tethering
+ * @param[in]  status  The ip forward status: (@c true = enable, @c false = disable)
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @see  tethering_get_ip_forward_status()
+ */
+API int tethering_set_ip_forward_status(tethering_h tethering, bool status)
+{
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+
+       __tethering_h *th = (__tethering_h *)tethering;
+       DBusGProxy *proxy = th->client_bus_proxy;
+
+       org_tizen_tethering_set_ip_forward_status_async(proxy, status,
+                       __ip_forward_cb, (gpointer)tethering);
+
+       return TETHERING_ERROR_NONE;
+}
+
+/**
+ * @brief Get the ip forward status
+ * @param[in]  tethering  The handle of tethering
+ * @param[out]  status  The ip forward status: (@c true = enable, @c false = disable)
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
+ * @see  tethering_set_ip_forward_status()
+ */
+API int tethering_get_ip_forward_status(tethering_h tethering, bool *status)
+{
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+       _retvm_if(status == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(status) is NULL\n");
+
+       __tethering_h *th = (__tethering_h *)tethering;
+       DBusGProxy *proxy = th->client_bus_proxy;
+       GError *error = NULL;
+       int forward_mode = 0;
+
+       org_tizen_tethering_get_ip_forward_status(proxy, &forward_mode, &error);
+       if (error != NULL) {
+               ERR("DBus fail : %s\n", error->message);
+               g_error_free(error);
+               return TETHERING_ERROR_OPERATION_FAILED;
+       }
+
+       if (forward_mode == 1)
+               *status = true;
+       else
+               *status = false;
+
+       return TETHERING_ERROR_NONE;
+}
+
+
+/**
  * @brief Registers the callback function called when tethering is enabled.
  * @param[in]  tethering  The handle of tethering
  * @param[in]  type  The type of tethering
index 64cd78b..c8a7cd9 100644 (file)
@@ -117,3 +117,16 @@ API int tethering_client_get_mac_address(tethering_client_h client, char **mac_a
        return TETHERING_ERROR_NONE;
 }
 
+API int tethering_client_get_time(tethering_client_h client, time_t *timestamp)
+{
+       _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+
+
+       __tethering_client_h *si = (__tethering_client_h *)client;
+
+       *timestamp = si->tm;
+
+       return TETHERING_ERROR_NONE;
+}
+
diff --git a/sysinfo-tethering.xml b/sysinfo-tethering.xml
new file mode 100644 (file)
index 0000000..9a0bce2
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<sys-info>
+       <default>
+         <key id="tethering-support" string="TRUE"/>
+       </default>
+</sys-info>