Below changes are applied
authorSeungyoun Ju <sy39.ju@samsung.com>
Tue, 9 Apr 2013 10:22:52 +0000 (19:22 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Tue, 9 Apr 2013 10:49:18 +0000 (19:49 +0900)
- Fix the multiple notification issue
- Support i80211n
- Channel is changed to 6
- Implement status notification for bluetooth visibility
- Change the power manager api
- Implement connection timer
- Reference count is used
- Support Mobile AP

Change-Id: If49d42e733e46ebb5a45429146906544c05dcdc9

16 files changed:
CMakeLists.txt
include/mobileap.h
include/mobileap_agent.h
include/mobileap_bluetooth.h
include/mobileap_common.h
include/mobileap_network.h
include/mobileap_notification.h
include/mobileap_usb.h
include/tethering-dbus-interface.xml
src/mobileap_bluetooth.c
src/mobileap_common.c
src/mobileap_main.c
src/mobileap_network.c
src/mobileap_notification.c
src/mobileap_usb.c
src/mobileap_wifi.c

index 1b66801..45b36e4 100644 (file)
@@ -28,7 +28,7 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 INCLUDE_DIRECTORIES(${INCLUDE_DIR})
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED dlog dbus-glib-1 pmapi vconf notification libssl secure-storage capi-network-connection capi-network-bluetooth)
+pkg_check_modules(pkgs REQUIRED dlog dbus-glib-1 pmapi vconf notification libssl secure-storage capi-network-connection capi-network-bluetooth ${PRIVATE_REQUIRED_PKGS})
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
index 5d144a8..e751ec8 100644 (file)
@@ -28,7 +28,7 @@ extern "C" {
 
 #define DBUS_STRUCT_STATIONS (dbus_g_type_get_struct ("GValueArray", \
                        G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, \
-                       G_TYPE_STRING, G_TYPE_INVALID))
+                       G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID))
 
 #define DBUS_STRUCT_STATION (dbus_g_type_get_struct ("GValueArray", \
                        G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
@@ -90,7 +90,7 @@ typedef enum {
 /**
 * WiFi tethering configuration
 */
-#define MOBILE_AP_WIFI_CHANNEL         7       /**< Channel number */
+#define MOBILE_AP_WIFI_CHANNEL         6       /**< Channel number */
 #define MOBILE_AP_WIFI_BSSID_LEN       6       /**< BSSID Length */
 #define MOBILE_AP_WIFI_SSID_MAX_LEN    31      /**< Maximum length of ssid */
 #define MOBILE_AP_WIFI_KEY_MIN_LEN     8       /**< Minimum length of wifi key */
@@ -182,6 +182,7 @@ typedef struct {
        char ip[MOBILE_AP_STR_INFO_LEN];                /**< assigned IP address */
        char mac[MOBILE_AP_STR_INFO_LEN];               /**< MAC Address */
        char hostname[MOBILE_AP_STR_HOSTNAME_LEN];      /**< alphanumeric name */
+       time_t tm;      /**< connection time*/
 } mobile_ap_station_info_t;
 
 typedef struct {
index 2344166..8ae515e 100644 (file)
@@ -97,6 +97,7 @@
                                "channel=%d\n" \
                                "ignore_broadcast_ssid=%d\n" \
                                "max_num_sta=%d\n" \
+                               "ieee80211n=1\n" \
                                "%s\n"
 #define HOSTAPD_DEBUG_FILE     "/tmp/hostapd.log"
 #define HOSTAPD_REQ_MAX_LEN    128
index f890d8c..95e28a7 100644 (file)
@@ -28,4 +28,4 @@ gboolean tethering_enable_bt_tethering(TetheringObject *obj,
 gboolean tethering_disable_bt_tethering(TetheringObject *obj,
                DBusGMethodInvocation *context);
 
-#endif
+#endif /* __MOBILEAP_BLUETOOTH_H__ */
index be0cbaf..5760577 100644 (file)
@@ -48,4 +48,4 @@ int _get_data_usage(const char *src, const char *dest, unsigned long long *tx, u
 int _execute_command(const char *cmd);
 int _get_tethering_type_from_ip(const char *ip, mobile_ap_type_e *type);
 
-#endif
+#endif /* __MOBILEAP_COMMON_H__ */
index 985797f..3959886 100644 (file)
@@ -21,6 +21,7 @@
 #include <glib.h>
 
 gboolean _get_network_interface_name(char **if_name);
+gboolean _is_trying_network_operation(void);
 gboolean _set_masquerade(void);
 gboolean _unset_masquerade(void);
 gboolean _open_network(void);
@@ -28,4 +29,4 @@ gboolean _close_network(void);
 gboolean _init_network(void *user_data);
 gboolean _deinit_network(void);
 
-#endif
+#endif /* __MOBILEAP_NETWORK_H__ */
index 35a6273..94a1e58 100644 (file)
 
 int _create_timeout_noti(const char *content, const char *title,
                const char *icon_path);
-
+int _delete_timeout_noti(void);
 int _create_connected_noti(const char *content, const char *title,
                const char *icon_path);
 int _update_connected_noti(const char *content);
 int _delete_connected_noti(void);
-
+int _create_status_noti(const char *content);
 #endif
index 9acc5e6..4ad58b8 100644 (file)
@@ -31,5 +31,4 @@ gboolean tethering_get_usb_station_info(TetheringObject *obj,
                                                DBusGMethodInvocation *context);
 gboolean tethering_get_usb_interface_info(TetheringObject *obj,
                                                DBusGMethodInvocation *context);
-
-#endif
+#endif /* __MOBILEAP_USB_H__ */
index 0d5231e..3dbcac1 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 5fac0be..38eceee 100644 (file)
@@ -26,6 +26,7 @@
 #include "mobileap_common.h"
 #include "mobileap_bluetooth.h"
 #include "mobileap_handler.h"
+#include "mobileap_notification.h"
 
 typedef struct {
        bt_device_info_s *info;
@@ -228,6 +229,8 @@ static void __bt_adapter_state_changed(int result, bt_adapter_state_e adapter_st
                return;
 
        int ret;
+       int duration;
+       bt_adapter_visibility_mode_e mode;
        TetheringObject *obj = (TetheringObject *)user_data;
        DBusGMethodInvocation *context = obj->bt_context;
 
@@ -250,6 +253,10 @@ static void __bt_adapter_state_changed(int result, bt_adapter_state_e adapter_st
                _emit_mobileap_dbus_signal(obj, E_SIGNAL_BT_TETHER_OFF,
                                SIGNAL_MSG_NOT_AVAIL_INTERFACE);
                return;
+       } else {
+               ret = bt_adapter_get_visibility(&mode, &duration);
+               if (ret == BT_ERROR_NONE && mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE)
+                       _create_status_noti("Bluetooth visible time is off. You may not find your device.");
        }
 
        ret = __activate_bt_nap(obj);
@@ -292,62 +299,25 @@ void _bt_get_remote_device_name(TetheringObject *obj, const char *mac, char **na
        return;
 }
 
-mobile_ap_error_code_e _disable_bt_tethering(TetheringObject *obj)
-{
-       int bt_ret;
-
-       if (!_mobileap_is_enabled(MOBILE_AP_STATE_BT)) {
-               ERR("BT tethering has not been enabled\n");
-               return MOBILE_AP_ERROR_NOT_ENABLED;
-       }
-
-       __deactivate_bt_nap();
-
-       bt_ret = bt_adapter_unset_state_changed_cb();
-       if (bt_ret != BT_ERROR_NONE)
-               ERR("bt_adapter_unset_state_changed_cb is failed : %d\n", bt_ret);
-
-       bt_ret = bt_deinitialize();
-       if (bt_ret != BT_ERROR_NONE)
-               ERR("bt_deinitialize is failed : %d\n", bt_ret);
-
-       _remove_station_info_all(MOBILE_AP_TYPE_BT);
-       __del_bt_remote_all();
-       _deinit_timeout_cb(MOBILE_AP_TYPE_BT);
-
-       _deinit_tethering(obj);
-       _mobileap_clear_state(MOBILE_AP_STATE_BT);
-
-       return MOBILE_AP_ERROR_NONE;
-}
-
-gboolean tethering_enable_bt_tethering(TetheringObject *obj,
+mobile_ap_error_code_e _enable_bt_tethering(TetheringObject *obj,
                DBusGMethodInvocation *context)
 {
-       int ret;
+       mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
        int bt_ret;
+       int duration;
+       bt_adapter_visibility_mode_e mode;
        bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED;
 
-       DBG("+\n");
-
-       g_assert(obj != NULL);
-       g_assert(context != NULL);
-
-
        if (_mobileap_is_enabled(MOBILE_AP_STATE_BT)) {
                ERR("Bluetooth tethering is already enabled\n");
                ret = MOBILE_AP_ERROR_ALREADY_ENABLED;
-               dbus_g_method_return(context,
-                               MOBILE_AP_ENABLE_BT_TETHERING_CFM, ret);
-               return FALSE;
+               return ret;
        }
 
        if (obj->bt_context != NULL) {
                ERR("Bluetooth tethering request is progressing\n");
                ret = MOBILE_AP_ERROR_IN_PROGRESS;
-               dbus_g_method_return(context,
-                               MOBILE_AP_ENABLE_BT_TETHERING_CFM, ret);
-               return FALSE;
+               return ret;
        }
 
        if (!_mobileap_set_state(MOBILE_AP_STATE_BT)) {
@@ -398,7 +368,12 @@ gboolean tethering_enable_bt_tethering(TetheringObject *obj,
                        goto FAIL;
                }
                obj->bt_context = context;
-               return TRUE;
+               return ret;
+       } else {
+               bt_ret = bt_adapter_get_visibility(&mode, &duration);
+               if (bt_ret == BT_ERROR_NONE && mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE)
+                       _create_status_noti("Bluetooth visible time is off. You may not find your device.");
+
        }
 
        ret = __activate_bt_nap(obj);
@@ -410,17 +385,71 @@ gboolean tethering_enable_bt_tethering(TetheringObject *obj,
                goto FAIL;
        }
 
+       _delete_timeout_noti();
        _init_timeout_cb(MOBILE_AP_TYPE_BT, (void *)obj);
        _start_timeout_cb(MOBILE_AP_TYPE_BT);
 
-       _emit_mobileap_dbus_signal(obj, E_SIGNAL_BT_TETHER_ON, NULL);
-       dbus_g_method_return(context, MOBILE_AP_ENABLE_BT_TETHERING_CFM, ret);
-       return TRUE;
+       return ret;
 
 FAIL:
        _mobileap_clear_state(MOBILE_AP_STATE_BT);
-       dbus_g_method_return(context, MOBILE_AP_ENABLE_BT_TETHERING_CFM, ret);
-       return FALSE;
+
+       return ret;
+}
+
+mobile_ap_error_code_e _disable_bt_tethering(TetheringObject *obj)
+{
+       int bt_ret;
+
+       if (!_mobileap_is_enabled(MOBILE_AP_STATE_BT)) {
+               ERR("BT tethering has not been enabled\n");
+               return MOBILE_AP_ERROR_NOT_ENABLED;
+       }
+
+       __deactivate_bt_nap();
+
+       bt_ret = bt_adapter_unset_state_changed_cb();
+       if (bt_ret != BT_ERROR_NONE)
+               ERR("bt_adapter_unset_state_changed_cb is failed : %d\n", bt_ret);
+
+       bt_ret = bt_deinitialize();
+       if (bt_ret != BT_ERROR_NONE)
+               ERR("bt_deinitialize is failed : %d\n", bt_ret);
+
+       _remove_station_info_all(MOBILE_AP_TYPE_BT);
+       __del_bt_remote_all();
+       _deinit_timeout_cb(MOBILE_AP_TYPE_BT);
+
+       _deinit_tethering(obj);
+       _mobileap_clear_state(MOBILE_AP_STATE_BT);
+
+       return MOBILE_AP_ERROR_NONE;
+}
+
+gboolean tethering_enable_bt_tethering(TetheringObject *obj,
+               DBusGMethodInvocation *context)
+{
+       mobile_ap_error_code_e ret;
+
+       DBG("+\n");
+
+       g_assert(obj != NULL);
+       g_assert(context != NULL);
+
+
+       ret = _enable_bt_tethering(obj, context);
+       if (ret != MOBILE_AP_ERROR_NONE) {
+               ERR("_enable_bt_tethering() is failed : %d\n", ret);
+               dbus_g_method_return(context,
+                               MOBILE_AP_ENABLE_BT_TETHERING_CFM, ret);
+               return FALSE;
+       } else if (obj->bt_context == NULL) {
+               _emit_mobileap_dbus_signal(obj, E_SIGNAL_BT_TETHER_ON, NULL);
+               dbus_g_method_return(context,
+                               MOBILE_AP_ENABLE_BT_TETHERING_CFM, ret);
+       }
+
+       return TRUE;
 }
 
 
index 41b9f7d..8271601 100644 (file)
@@ -103,6 +103,7 @@ void _send_dbus_station_info(const char *member, mobile_ap_station_info_t *info)
                                DBUS_TYPE_STRING, &ip,
                                DBUS_TYPE_STRING, &mac,
                                DBUS_TYPE_STRING, &hostname,
+                               DBUS_TYPE_UINT32, &info->tm,
                                DBUS_TYPE_INVALID)) {
                ERR("Event sending failed\n");
                dbus_message_unref(msg);
@@ -177,6 +178,7 @@ int _add_station_info(mobile_ap_station_info_t *info)
                DBG("[%d] station MAC : %s\n", i, si->mac);
                DBG("[%d] station Hostname : %s\n", i, si->hostname);
                DBG("[%d] station IP : %s\n", i, si->ip);
+               DBG("[%d] station connected time : %d\n", i, si->tm);
                i++;
        }
 
@@ -395,7 +397,6 @@ int _get_data_usage(const char *src, const char *dest,
        snprintf(cmd, sizeof(cmd),
                        "%s -L FORWARD -vx | %s \"%s[ ]*%s\" | %s '{ print $2 }' > %s",
                        IPTABLES, GREP, src, dest, AWK, DATA_USAGE_FILE);
-       DBG("GET DATA USAGE : %s\n", cmd);
        if (system(cmd) < 0) {
                ERR("\"cmd\" is failed\n");
        }
@@ -404,7 +405,6 @@ int _get_data_usage(const char *src, const char *dest,
        snprintf(cmd, sizeof(cmd),
                        "%s -L FORWARD -vx | %s \"%s[ ]*%s\" | %s '{ print $2 }' >> %s",
                        IPTABLES, GREP, dest, src, AWK, DATA_USAGE_FILE);
-       DBG("GET DATA USAGE : %s\n", cmd);
        if (system(cmd) < 0) {
                ERR("\"cmd\" is failed\n");
        }
@@ -420,13 +420,11 @@ int _get_data_usage(const char *src, const char *dest,
                *tx = 0LL;
        else
                *tx = atoll(buf);
-       DBG("Tx(%s -> %s) : %llu\n", src, dest, *tx);
 
        if (fgets(buf, sizeof(buf), fp) == NULL)
                *rx = 0LL;
        else
                *rx = atoll(buf);
-       DBG("Rx(%s -> %s) : %llu\n", dest, src, *rx);
 
        fclose(fp);
        unlink(DATA_USAGE_FILE);
index fcc3c70..b7b14a2 100644 (file)
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+#include <fcntl.h>
+#include <unistd.h>
 #include <glib.h>
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -42,14 +44,21 @@ GMainLoop *mainloop = NULL;
 int mobileap_state = MOBILE_AP_STATE_NONE;
 DBusConnection *tethering_conn = NULL;
 
+gboolean tethering_init(TetheringObject *obj, GError **error);
 gboolean tethering_deinit(TetheringObject *obj, GError **error);
 gboolean tethering_disable(TetheringObject *obj, DBusGMethodInvocation *context);
 gboolean tethering_get_station_info(TetheringObject *obj,
                DBusGMethodInvocation *context);
 gboolean tethering_get_data_packet_usage(TetheringObject *obj,
                DBusGMethodInvocation *context);
+gboolean tethering_set_ip_forward_status(TetheringObject *obj,
+               gint forward_mode,  DBusGMethodInvocation *context);
+gboolean tethering_get_ip_forward_status(TetheringObject *obj, gint *forward_mode);
+
 #include "tethering-server-stub.h"
 
+int ref_agent = 0;
+
 static void tethering_object_init(TetheringObject *obj)
 {
        DBG("+\n");
@@ -127,7 +136,7 @@ static void __add_station_info_to_array(gpointer data, gpointer user_data)
        g_value_take_boxed(&value,
                        dbus_g_type_specialized_construct(DBUS_STRUCT_STATIONS));
        dbus_g_type_struct_set(&value, 0, si->interface, 1, si->ip,
-                       2, si->mac, 3, si->hostname, G_MAXUINT);
+                       2, si->mac, 3, si->hostname, 4, (guint)(si->tm), G_MAXUINT);
        g_ptr_array_add(array, g_value_get_boxed(&value));
 }
 
@@ -271,17 +280,23 @@ gboolean _deinit_tethering(TetheringObject *obj)
        return TRUE;
 }
 
+gboolean tethering_init(TetheringObject *obj, GError **error)
+{
+       DBG("There are [%d] references\n", ++ref_agent);
+
+       return TRUE;
+}
 
 gboolean tethering_deinit(TetheringObject *obj, GError **error)
 {
-       DBG("+\n");
-       g_assert(obj != NULL);
-
-       if (_mobileap_is_disabled()) {
-               DBG("Mobile AP is not activated, so we quit the mobileap-agent.\n");
+       if (--ref_agent <= 0 && _mobileap_is_disabled() &&
+                       !_is_trying_network_operation()) {
+               DBG("Terminate mobileap-agent\n");
                g_main_loop_quit(mainloop);
        }
 
+       DBG("There are [%d] references\n", ref_agent);
+
        return TRUE;
 }
 
@@ -345,7 +360,7 @@ gboolean tethering_get_data_packet_usage(TetheringObject *obj,
        if (_get_network_interface_name(&if_name) == FALSE) {
                ERR("No network interface\n");
                dbus_g_method_return(context, MOBILE_AP_GET_DATA_PACKET_USAGE_CFM,
-                               0, 0);
+                               0ULL, 0ULL);
                return FALSE;
        }
 
@@ -371,6 +386,51 @@ gboolean tethering_get_data_packet_usage(TetheringObject *obj,
        return TRUE;
 }
 
+gboolean tethering_set_ip_forward_status(TetheringObject *obj,
+               gint forward_mode,  DBusGMethodInvocation *context)
+{
+       g_assert(obj != NULL);
+
+       gboolean ret;
+
+       if (forward_mode == 0) {
+               ret = _unset_masquerade();
+       } else {
+               ret = _set_masquerade();
+       }
+
+       dbus_g_method_return(context, ret);
+
+       return TRUE;
+}
+
+gboolean tethering_get_ip_forward_status(TetheringObject *obj, gint *forward_mode)
+{
+       g_assert(obj != NULL);
+
+       int fd;
+       int ret;
+       char value[2] = {0, };
+
+       fd = open(IP_FORWARD, O_RDONLY);
+       if (fd < 0) {
+               ERR("open failed\n");
+               return FALSE;
+       }
+
+       ret = read(fd, value, sizeof(value));
+       if (ret < 0) {
+               ERR("read is failed\n");
+               close(fd);
+               return FALSE;
+       }
+       close(fd);
+
+       *forward_mode = atoi(value);
+
+       return TRUE;
+}
+
 
 static DBusHandlerResult __dnsmasq_signal_filter(DBusConnection *conn,
                DBusMessage *msg, void *user_data)
@@ -389,6 +449,7 @@ static DBusHandlerResult __dnsmasq_signal_filter(DBusConnection *conn,
        TetheringObject *obj = (TetheringObject *)user_data;
        mobile_ap_station_info_t *info = NULL;
        int n_station = 0;
+       time_t tm;
 
        dbus_error_init(&error);
        if (dbus_message_is_signal(msg, DNSMASQ_DBUS_INTERFACE,
@@ -441,6 +502,8 @@ static DBusHandlerResult __dnsmasq_signal_filter(DBusConnection *conn,
                                free(bt_remote_device_name);
                        }
                }
+               time(&tm);
+               info->tm = tm;
 
                if (_add_station_info(info) != MOBILE_AP_ERROR_NONE) {
                        free(info);
index 796f097..8a65ecb 100644 (file)
 #include "mobileap_common.h"
 #include "mobileap_network.h"
 
+
+extern int ref_agent;
 static connection_h connection = NULL;
 static connection_profile_h cprof = NULL;
-static connection_profile_h old_prof = NULL;
 
 static void __print_profile(connection_profile_h profile)
 {
-#define __check_connection_return(conn_ret)    \
-       do {    \
-               if (conn_ret != CONNECTION_ERROR_NONE)  \
-                       ERR("connection API fail : 0x%X\n", conn_ret);  \
-       } while(0)
-
        if (profile == NULL)
                return;
 
        int conn_ret;
        bool roaming;
-       char *apn;
-       char *home_url;
+       char *apn = NULL;
+       char *home_url = NULL;
        connection_cellular_network_type_e network_type;
        connection_cellular_service_type_e service_type;
 
        conn_ret = connection_profile_get_cellular_network_type(profile, &network_type);
-       __check_connection_return(conn_ret);
-       DBG("Network type : %d\n", network_type);
+       if (conn_ret != CONNECTION_ERROR_NONE)
+               ERR("connection API fail : 0x%X\n", conn_ret);
+       else
+               DBG("Network type : %d\n", network_type);
 
        conn_ret = connection_profile_get_cellular_service_type(profile, &service_type);
-       __check_connection_return(conn_ret);
-       DBG("Service type : %d\n", service_type);
+       if (conn_ret != CONNECTION_ERROR_NONE)
+               ERR("connection API fail : 0x%X\n", conn_ret);
+       else
+               DBG("Service type : %d\n", service_type);
 
        conn_ret = connection_profile_get_cellular_apn(profile, &apn);
-       __check_connection_return(conn_ret);
-       DBG("APN : %s\n", apn);
-       free(apn);
+       if (conn_ret != CONNECTION_ERROR_NONE)
+               ERR("connection API fail : 0x%X\n", conn_ret);
+       else {
+               DBG("APN : %s\n", apn);
+               free(apn);
+       }
 
        conn_ret = connection_profile_get_cellular_home_url(profile, &home_url);
-       __check_connection_return(conn_ret);
-       DBG("Home url : %s\n", home_url);
-       free(home_url);
+       if (conn_ret != CONNECTION_ERROR_NONE)
+               ERR("connection API fail : 0x%X\n", conn_ret);
+       else {
+               DBG("Home url : %s\n", home_url);
+               free(home_url);
+       }
 
        conn_ret = connection_profile_is_cellular_roaming(profile, &roaming);
-       __check_connection_return(conn_ret);
-       DBG("Roaming : %d\n", roaming);
+       if (conn_ret != CONNECTION_ERROR_NONE)
+               ERR("connection API fail : 0x%X\n", conn_ret);
+       else
+               DBG("Roaming : %d\n", roaming);
 
-#undef __check_connection_return
        return;
 }
 
-static gboolean __is_connected_prof(connection_profile_h profile)
+static gboolean __is_connected_profile(connection_profile_h profile)
 {
+       if (profile == NULL) {
+               ERR("profile is NULL\n");
+               return FALSE;
+       }
+
        int conn_ret;
        connection_profile_state_e pstat = CONNECTION_PROFILE_STATE_DISCONNECTED;
 
@@ -91,8 +102,14 @@ static gboolean __is_connected_prof(connection_profile_h profile)
        return TRUE;
 }
 
-static gboolean __get_current_prof(connection_profile_h *r_prof, connection_profile_type_e *r_net_type)
+
+static gboolean __get_connected_profile(connection_profile_h *r_prof, connection_profile_type_e *r_net_type)
 {
+       if (r_prof == NULL || r_net_type == NULL) {
+               ERR("Invalid param [%p] [%p]\n", r_prof, r_net_type);
+               return FALSE;
+       }
+
        int conn_ret;
        connection_profile_h profile = NULL;
        connection_profile_type_e net_type = CONNECTION_PROFILE_TYPE_CELLULAR;
@@ -115,20 +132,32 @@ static gboolean __get_current_prof(connection_profile_h *r_prof, connection_prof
        return TRUE;
 }
 
-static gboolean __get_network_prof(connection_profile_h *r_prof)
+static gboolean __get_network_profile(connection_profile_h *r_prof)
 {
+       if (r_prof == NULL) {
+               ERR("r_prof is NULL\n");
+               return FALSE;
+       }
+
        connection_profile_h profile;
        connection_profile_type_e net_type = CONNECTION_PROFILE_TYPE_CELLULAR;
 
-       if (__get_current_prof(&profile, &net_type) != TRUE) {
+       if (__get_connected_profile(&profile, &net_type) == FALSE) {
                ERR("There is no available network\n");
                return FALSE;
        }
 
        DBG("Current connected net_type : %d\n", net_type);
-       if (net_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
-               __print_profile(profile);
+       if (net_type == CONNECTION_PROFILE_TYPE_WIFI) {
+               *r_prof = profile;
+               return TRUE;
+       }
+
+       if (net_type != CONNECTION_PROFILE_TYPE_CELLULAR) {
+               ERR("Network type [%d] is not supported\n", net_type);
+               return FALSE;
        }
+       __print_profile(profile);
 
        *r_prof = profile;
        return TRUE;
@@ -136,32 +165,56 @@ static gboolean __get_network_prof(connection_profile_h *r_prof)
 
 static void __connection_type_changed_cb(connection_type_e type, void *user_data)
 {
-       if (_mobileap_is_disabled()) {
-               DBG("Tethering is not enabled\n");
-               return;
-       }
-
        DBG("Changed connection type is %s\n",
                        type == CONNECTION_TYPE_DISCONNECTED ? "DISCONNECTED" :
-                       type == CONNECTION_TYPE_WIFI ? "Wi-FI" :
+                       type == CONNECTION_TYPE_WIFI ? "Wi-Fi" :
                        type == CONNECTION_TYPE_CELLULAR ? "Cellular" :
                        type == CONNECTION_TYPE_ETHERNET ? "Ethernet" :
                        "Unknown");
 
-       _close_network();
-       if (type == CONNECTION_TYPE_DISCONNECTED)
+
+       if (_mobileap_is_disabled()) {
+               DBG("Tethering is not enabled\n");
+               return;
+       }
+
+       if (_unset_masquerade() == FALSE) {
+               ERR("_unset_masquerade is failed\n");
+       }
+
+       if (cprof) {
+               connection_profile_destroy(cprof);
+               cprof = NULL;
+       }
+
+       if (type == CONNECTION_TYPE_DISCONNECTED) {
                return;
+       }
 
        _open_network();
+
        return;
 }
 
+gboolean _is_trying_network_operation(void)
+{
+
+       return FALSE;
+}
+
 gboolean _get_network_interface_name(char **if_name)
 {
-       int conn_ret = 0;
+       if (if_name == NULL) {
+               ERR("if_name is NULL\n");
+               return FALSE;
+       }
 
-       if (cprof == NULL)
+       if (cprof == NULL) {
+               ERR("There is no connected profile\n");
                return FALSE;
+       }
+
+       int conn_ret = 0;
 
        conn_ret = connection_profile_get_network_interface_name(cprof, if_name);
        if (conn_ret != CONNECTION_ERROR_NONE) {
@@ -190,6 +243,11 @@ gboolean _set_masquerade(void)
 
 gboolean _unset_masquerade(void)
 {
+       if (cprof == NULL) {
+               DBG("There is nothing to unset masquerading\n");
+               return TRUE;
+       }
+
        char *if_name = NULL;
 
        if (_get_network_interface_name(&if_name) == FALSE) {
@@ -210,18 +268,17 @@ gboolean _open_network(void)
 
        DBG("+\n");
 
-       if (__get_network_prof(&profile) == FALSE) {
-               ERR("__get_network_prof is failed\n");
+       if (__get_network_profile(&profile) == FALSE) {
+               ERR("__get_network_profile is failed\n");
                return FALSE;
        }
-       cprof = profile;
 
-       if (__is_connected_prof(cprof) == FALSE) {
-               DBG("Connection is not yet opened\n");
+       if (!__is_connected_profile(profile)) {
+               connection_profile_destroy(profile);
                return TRUE;
        }
+       cprof = profile;
 
-       DBG("Set masquerading\n");
        if (_set_masquerade() == FALSE) {
                ERR("_set_masquerade is failed\n");
                _close_network();
@@ -239,11 +296,6 @@ gboolean _close_network(void)
 
        DBG("+\n");
 
-       if (cprof == NULL && old_prof == NULL) {
-               ERR("There is nothing to handle\n");
-               return TRUE;
-       }
-
        ret = _unset_masquerade();
        if (ret == FALSE)
                ERR("_unset_masquerade is failed\n");
@@ -252,6 +304,7 @@ gboolean _close_network(void)
        cprof = NULL;
 
        DBG("-\n");
+
        return TRUE;
 }
 
index 4004cee..ba2ad85 100644 (file)
@@ -26,6 +26,7 @@
 #include "mobileap_agent.h"
 
 #define MH_NOTI_APP_NAME       "org.tizen.tethering"
+#define MH_AGENT_PKG_NAME "mobileap-agent"
 
 static int connected_noti_id = 0;
 static int timeout_noti_id = 0;
@@ -61,10 +62,9 @@ int _create_timeout_noti(const char *content, const char *title,
                timeout_noti_id = 0;
        }
 
-       noti = notification_new(NOTIFICATION_TYPE_NOTI,
-                       NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
+       noti = notification_create(NOTIFICATION_TYPE_NOTI);
        if (!noti) {
-               ERR("Fail to notification_new [%d]\n", ret);
+               ERR("Fail to notification_create\n");
                return MOBILE_AP_ERROR_INTERNAL;
        }
 
@@ -141,6 +141,33 @@ FAIL:
        return MOBILE_AP_ERROR_INTERNAL;
 }
 
+int _delete_timeout_noti(void)
+{
+       notification_error_e ret = NOTIFICATION_ERROR_NONE;
+       notification_list_h noti_list = NULL;
+       notification_h noti = NULL;
+
+       ret = notification_get_detail_list(MH_AGENT_PKG_NAME,
+                                                            NOTIFICATION_GROUP_ID_NONE,
+                                                            NOTIFICATION_PRIV_ID_NONE,
+                                                            -1,
+                                                            &noti_list);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_get_detail_list\n");
+               return MOBILE_AP_ERROR_INTERNAL;
+       }
+
+       if (noti_list) {
+               noti = notification_list_get_data(noti_list);
+               if (noti)
+                       notification_delete(noti);
+
+               notification_free_list(noti_list);
+       }
+
+       return MOBILE_AP_ERROR_NONE;
+}
+
 int _create_connected_noti(const char *content, const char *title,
                const char *icon_path)
 {
@@ -148,10 +175,9 @@ int _create_connected_noti(const char *content, const char *title,
        notification_h noti = NULL;
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
 
-       noti = notification_new(NOTIFICATION_TYPE_ONGOING,
-                       NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
+       noti = notification_create(NOTIFICATION_TYPE_ONGOING);
        if (!noti) {
-               ERR("Fail to notification_new [%d]\n", ret);
+               ERR("Fail to notification_create\n");
                return MOBILE_AP_ERROR_INTERNAL;
        }
 
@@ -310,3 +336,18 @@ int _delete_connected_noti(void)
        return MOBILE_AP_ERROR_NONE;
 }
 
+int _create_status_noti(const char *content)
+{
+       if (content == NULL)
+               return MOBILE_AP_ERROR_INVALID_PARAM;
+
+       notification_error_e ret;
+
+       ret = notification_status_message_post(content);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("notification_status_message_post() is failed : %d\n", ret);
+               return MOBILE_AP_ERROR_INTERNAL;
+       }
+
+       return MOBILE_AP_ERROR_NONE;
+}
index 8de107f..edf870e 100644 (file)
@@ -135,61 +135,23 @@ static void __handle_usb_mode_change(keynode_t *key, void *data)
        }
 }
 
-mobile_ap_error_code_e _disable_usb_tethering(TetheringObject *obj)
+mobile_ap_error_code_e _enable_usb_tethering(TetheringObject *obj,
+               DBusGMethodInvocation *context)
 {
        mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
-
-       if (!_mobileap_is_enabled(MOBILE_AP_STATE_USB)) {
-               ERR("USB tethering has not been enabled\n");
-               ret = MOBILE_AP_ERROR_NOT_ENABLED;
-               return ret;
-       }
-
-       _deinit_tethering(obj);
-
-       if (_remove_station_info_all(MOBILE_AP_TYPE_USB) != MOBILE_AP_ERROR_NONE) {
-               ERR("_remove_station_info_all is failed. Ignore it\n");
-       }
-
-       vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
-                       __handle_usb_disconnect_cb);
-       vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
-                       __handle_usb_disconnect_cb);
-
-       _mobileap_clear_state(MOBILE_AP_STATE_USB);
-
-       DBG("_disable_usb_tethering is done\n");
-
-       return ret;
-}
-
-gboolean tethering_enable_usb_tethering(TetheringObject *obj,
-                                               DBusGMethodInvocation *context)
-{
        int vconf_ret;
        int usb_mode = SETTING_USB_NONE_MODE;
-       int ret = MOBILE_AP_ERROR_NONE;
-
-       DBG("+\n");
-
-       g_assert(obj != NULL);
-       g_assert(context != NULL);
-
 
        if (_mobileap_is_enabled(MOBILE_AP_STATE_USB)) {
                ERR("USB tethering is already enabled\n");
                ret = MOBILE_AP_ERROR_ALREADY_ENABLED;
-               dbus_g_method_return(context,
-                               MOBILE_AP_ENABLE_USB_TETHERING_CFM, ret);
-               return FALSE;
+               return ret;
        }
 
        if (obj->usb_context) {
                ERR("USB request is progressing\n");
                ret = MOBILE_AP_ERROR_IN_PROGRESS;
-               dbus_g_method_return(context,
-                               MOBILE_AP_ENABLE_USB_TETHERING_CFM, ret);
-               return FALSE;
+               return ret;
        }
 
        vconf_notify_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
@@ -227,28 +189,80 @@ gboolean tethering_enable_usb_tethering(TetheringObject *obj,
        }
 
        if (usb_mode == SETTING_USB_TETHERING_MODE) {
-               DBG("Don't need to wait for usb-setting\n");
                obj->usb_context = NULL;
                vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
                                __handle_usb_mode_change);
-               _emit_mobileap_dbus_signal(obj, E_SIGNAL_USB_TETHER_ON, NULL);
-               dbus_g_method_return(context,
-                               MOBILE_AP_ENABLE_USB_TETHERING_CFM, ret);
-               return TRUE;
        }
 
        DBG("-\n");
-       return TRUE;
+       return MOBILE_AP_ERROR_NONE;
 
 FAIL:
        vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
                        __handle_usb_disconnect_cb);
        _mobileap_clear_state(MOBILE_AP_STATE_USB);
-       dbus_g_method_return(context,
-                       MOBILE_AP_ENABLE_USB_TETHERING_CFM, ret);
-       return FALSE;
+
+       return ret;
 }
 
+mobile_ap_error_code_e _disable_usb_tethering(TetheringObject *obj)
+{
+       mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
+
+       if (!_mobileap_is_enabled(MOBILE_AP_STATE_USB)) {
+               ERR("USB tethering has not been enabled\n");
+               ret = MOBILE_AP_ERROR_NOT_ENABLED;
+               return ret;
+       }
+
+       _deinit_tethering(obj);
+
+       if (_remove_station_info_all(MOBILE_AP_TYPE_USB) != MOBILE_AP_ERROR_NONE) {
+               ERR("_remove_station_info_all is failed. Ignore it\n");
+       }
+
+       vconf_ignore_key_changed(VCONFKEY_SETAPPL_USB_MODE_INT,
+                       __handle_usb_disconnect_cb);
+       vconf_ignore_key_changed(VCONFKEY_SYSMAN_USB_STATUS,
+                       __handle_usb_disconnect_cb);
+
+       _mobileap_clear_state(MOBILE_AP_STATE_USB);
+
+       DBG("_disable_usb_tethering is done\n");
+
+       return ret;
+}
+
+gboolean tethering_enable_usb_tethering(TetheringObject *obj,
+               DBusGMethodInvocation *context)
+{
+       mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
+
+       DBG("+\n");
+
+       g_assert(obj != NULL);
+       g_assert(context != NULL);
+
+
+       ret = _enable_usb_tethering(obj, context);
+       if (ret != MOBILE_AP_ERROR_NONE) {
+               ERR("_enable_usb_tethering() is failed : %d\n", ret);
+               dbus_g_method_return(context,
+                               MOBILE_AP_ENABLE_USB_TETHERING_CFM, ret);
+               return FALSE;
+       } else if (obj->usb_context == NULL) {
+               DBG("Don't need to wait for usb-setting\n");
+               _emit_mobileap_dbus_signal(obj, E_SIGNAL_USB_TETHER_ON, NULL);
+               dbus_g_method_return(context,
+                               MOBILE_AP_ENABLE_USB_TETHERING_CFM, ret);
+       } else {
+               DBG("dbus will be returned by vconf callback\n");
+       }
+
+       return TRUE;
+}
+
+
 gboolean tethering_disable_usb_tethering(TetheringObject *obj,
                DBusGMethodInvocation *context)
 {
index dc9646b..fea6629 100644 (file)
@@ -28,6 +28,7 @@
 #include "mobileap_common.h"
 #include "mobileap_wifi.h"
 #include "mobileap_handler.h"
+#include "mobileap_notification.h"
 
 static int __generate_initial_passphrase(char *passphrase_buf);
 static mobile_ap_error_code_e __get_hide_mode(int *hide_mode);
@@ -333,6 +334,57 @@ void _add_wifi_device_to_array(softap_device_info_t *di, GPtrArray *array)
        }
 }
 
+mobile_ap_error_code_e _enable_wifi_tethering(TetheringObject *obj, gchar *ssid)
+{
+       mobile_ap_error_code_e ret;
+
+       if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI)) {
+               ERR("Wi-Fi tethering is already enabled\n");
+               ret = MOBILE_AP_ERROR_ALREADY_ENABLED;
+               return ret;
+       }
+
+       /* Update global state */
+       if (!_mobileap_set_state(MOBILE_AP_STATE_WIFI)) {
+               ret = MOBILE_AP_ERROR_RESOURCE;
+               return ret;
+       }
+
+       /* Update Wi-Fi hotspot data to common object */
+       ret = __update_wifi_data(obj);
+       if (ret != MOBILE_AP_ERROR_NONE) {
+               _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
+               return ret;
+       }
+
+       if (ssid != NULL && strlen(ssid) > 0) {
+               DBG("Private(Passed) SSID is used : %s\n", ssid);
+               g_strlcpy(obj->ssid, ssid, sizeof(obj->ssid));
+       }
+
+       /* Initialize tethering */
+       if (!_init_tethering(obj)) {
+               _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
+               ret = MOBILE_AP_ERROR_RESOURCE;
+               return ret;
+       }
+
+       /* Upload driver */
+       ret = _mh_core_enable_softap(obj->ssid, obj->security_type,
+                       obj->key, obj->hide_mode);
+       if (ret != MOBILE_AP_ERROR_NONE) {
+               _deinit_tethering(obj);
+               _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
+               return ret;
+       }
+
+       _delete_timeout_noti();
+       _init_timeout_cb(MOBILE_AP_TYPE_WIFI, (void *)obj);
+       _start_timeout_cb(MOBILE_AP_TYPE_WIFI);
+
+       return MOBILE_AP_ERROR_NONE;
+}
+
 mobile_ap_error_code_e _disable_wifi_tethering(TetheringObject *obj)
 {
        int ret = MOBILE_AP_ERROR_NONE;
@@ -406,66 +458,27 @@ static mobile_ap_error_code_e __update_wifi_data(TetheringObject *obj)
 gboolean tethering_enable_wifi_tethering(TetheringObject *obj, gchar *ssid,
                gchar *key, gint hide_mode, DBusGMethodInvocation *context)
 {
-       int ret = MOBILE_AP_ERROR_NONE;
+       mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
+       gboolean ret_val = FALSE;
 
        g_assert(obj != NULL);
        g_assert(context != NULL);
 
 
-       if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI)) {
-               ERR("Wi-Fi tethering is already enabled\n");
-               ret = MOBILE_AP_ERROR_ALREADY_ENABLED;
-               dbus_g_method_return(context,
-                               MOBILE_AP_ENABLE_WIFI_TETHERING_CFM, ret);
-               return FALSE;
-       }
-
-       /* Update global state */
-       if (!_mobileap_set_state(MOBILE_AP_STATE_WIFI)) {
-               ret = MOBILE_AP_ERROR_RESOURCE;
-               goto FAIL;
-       }
-
-       /* Update Wi-Fi hotspot data to common object */
-       ret = __update_wifi_data(obj);
-       if (ret != MOBILE_AP_ERROR_NONE) {
-               goto FAIL;
-       }
-
-       if (strlen(ssid) > 0) {
-               DBG("Private(Passed) SSID is used : %s\n", ssid);
-               g_strlcpy(obj->ssid, ssid, sizeof(obj->ssid));
-       }
-
-       /* Initialize tethering */
-       if (!_init_tethering(obj)) {
-               ret = MOBILE_AP_ERROR_RESOURCE;
-               goto FAIL;
-       }
-
-       /* Upload driver */
-       ret = _mh_core_enable_softap(obj->ssid, obj->security_type,
-                       obj->key, obj->hide_mode);
+       ret = _enable_wifi_tethering(obj, ssid);
        if (ret != MOBILE_AP_ERROR_NONE) {
-               _deinit_tethering(obj);
-               goto FAIL;
+               ERR("_enable_wifi_tethering is failed\n");
+       } else {
+               _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_ON, NULL);
+               ret_val = TRUE;
        }
 
-       _init_timeout_cb(MOBILE_AP_TYPE_WIFI, (void *)obj);
-       _start_timeout_cb(MOBILE_AP_TYPE_WIFI);
-
-       _emit_mobileap_dbus_signal(obj, E_SIGNAL_WIFI_TETHER_ON, NULL);
-       dbus_g_method_return(context, MOBILE_AP_ENABLE_WIFI_TETHERING_CFM, ret);
-
-       return TRUE;
-
-FAIL:
-       _mobileap_clear_state(MOBILE_AP_STATE_WIFI);
        dbus_g_method_return(context, MOBILE_AP_ENABLE_WIFI_TETHERING_CFM, ret);
 
-       return FALSE;
+       return ret_val;
 }
 
+
 gboolean tethering_disable_wifi_tethering(TetheringObject *obj,
                DBusGMethodInvocation *context)
 {
@@ -482,8 +495,8 @@ gboolean tethering_disable_wifi_tethering(TetheringObject *obj,
 
        if (ret != MOBILE_AP_ERROR_NONE)
                return FALSE;
-       else
-               return TRUE;
+
+       return TRUE;
 }
 
 gboolean tethering_get_wifi_tethering_hide_mode(TetheringObject *obj,