Changes to IP conflict detection mode get/set API. 07/158007/9
authorAbhishek Sansanwal <abhishek.s94@samsung.com>
Fri, 27 Oct 2017 07:31:14 +0000 (13:01 +0530)
committerAbhishek Sansanwal <abhishek.s94@samsung.com>
Wed, 8 Nov 2017 06:47:26 +0000 (12:17 +0530)
Description: Removed the exponential IP conflict detection mode.
Changed and renamed the set detection mode dbus method to set only
the time period. Added the conflict detection time period get API.

Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Change-Id: I7d05dc9f93825ef091938568fb51ae021efe091c

include/ip-conflict-detect.h
interfaces/netconfig-iface-wifi.xml
resources/etc/dbus-1/system.d/net-config.conf
src/ip-conflict-detect.c
src/wifi.c

index 6cd9608..f830a4f 100644 (file)
@@ -42,10 +42,12 @@ void stop_ip_conflict_mon();
 gboolean handle_ip_conflict_set_enable(Wifi *wifi, GDBusMethodInvocation *context,
                bool detect);
 gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation *context);
-gboolean handle_set_ip_conflict_mode(Wifi *wifi, GDBusMethodInvocation *context,
-               guint mode, guint initial_time);
+gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context,
+               guint initial_time);
 gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation
-                                     *context);
+               *context);
+gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context);
+
 
 #ifdef __cplusplus
 }
index 023659c..54c665a 100755 (executable)
@@ -37,6 +37,9 @@
                <method name="GetIpConflictState">
                        <arg type="u" name="state" direction="out"/>
                </method>
+               <method name="GetIpConflictPeriod">
+                       <arg type="u" name="initial_time" direction="out"/>
+               </method>
                <method name="GetAutoscanmode">
                        <arg type="u" name="autoscanmode" direction="out"/>
                </method>
@@ -64,8 +67,7 @@
                        <arg type="s" name="config_id" direction="in"/>
                        <arg type="a{sv}" name="Configuration" direction="in"/>
                </method>
-               <method name="SetIpConflictMode">
-                       <arg type="u" name="mode" direction="in"/>
+               <method name="SetIpConflictPeriod">
                        <arg type="u" name="initial_time" direction="in"/>
                </method>
                <method name="RemoveConfiguration">
index 5355c87..04677f7 100755 (executable)
@@ -20,6 +20,8 @@
                <allow send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="GetAutoscan" />
                <allow send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="GetAutoscanmode" />
                <allow send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="FlushBss" />
+               <allow send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="SetIpConflictPeriod" />
+               <allow send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="GetIpConflictPeriod" />
 
                <check send_destination="net.netconfig" send_interface="net.netconfig.network" send_member="AddRoute" privilege="http://tizen.org/privilege/network.set" />
                <check send_destination="net.netconfig" send_interface="net.netconfig.network" send_member="RemoveRoute" privilege="http://tizen.org/privilege/network.set" />
index 414298a..53c1dd1 100644 (file)
@@ -44,6 +44,7 @@
 #define IP_ADDRESS_LENGTH 4
 #define MAC_ADDRESS_LENGTH 6
 #define WLAN_MAC_ADDR_MAX 20
+#define ARP_SOURCE_IP "0.0.0.0"
 
 #define MIN_ARP_SEND_TIME 2000
 #define MAX_ARP_SEND_TIME 32000
@@ -74,12 +75,6 @@ struct arp_message {
 };
 
 typedef enum {
-       IP_CONFLICT_MODE_EXPONENTIAL = 0x00,
-       IP_CONFLICT_MODE_PERIODIC,
-       IP_CONFLICT_MODE_MAX
-} ip_conflict_mode_e;
-
-typedef enum {
        NETCONFIG_IP_CONFLICT_STATE_UNKNOWN,
        NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED,
        NETCONFIG_IP_CONFLICT_STATE_CONFLICT_DETECTED
@@ -88,10 +83,9 @@ typedef enum {
 struct timer_data {
        guint initial_time;
        guint timeout;
-       ip_conflict_mode_e mode;
 };
 static struct timer_data td = {
-       MIN_ARP_SEND_TIME, MIN_ARP_SEND_TIME, IP_CONFLICT_MODE_PERIODIC
+       MIN_ARP_SEND_TIME, MIN_ARP_SEND_TIME
 };
 
 int ioctl_sock;
@@ -121,6 +115,11 @@ static unsigned int __convert_uchar_to_uint(unsigned char b[IP_ADDRESS_LENGTH])
 
 static gboolean __arp_reply_timeout_cb(gpointer data)
 {
+       if (sd == NULL) {
+               INFO("Ignore timeout cb");
+               return G_SOURCE_REMOVE;
+       }
+
        sd->iteration++;
        sd->arp_reply_timer = -1;
        if (sd->timer_id != -1)
@@ -250,7 +249,7 @@ static gboolean send_arp(gpointer data)
                goto err;
        }
 
-       source_ip = inet_addr(default_ip);
+       source_ip = inet_addr(ARP_SOURCE_IP);
        target_ip = inet_addr(default_ip);
        memcpy(arp.s_IPaddr, &source_ip, IP_ADDRESS_LENGTH);                    /* source IP address */
        memcpy(arp.s_hwaddr, source_mac, MAC_ADDRESS_LENGTH);                   /* source hardware address */
@@ -302,10 +301,8 @@ static gboolean send_arp(gpointer data)
        }
 
        g_source_remove(sd->timer_id);
-       if (td.mode == IP_CONFLICT_MODE_PERIODIC)
-               sd->timeout = td.initial_time;
-       else if (td.mode == IP_CONFLICT_MODE_EXPONENTIAL && 2*sd->timeout < MAX_ARP_SEND_TIME)
-               sd->timeout *= 2;
+
+       sd->timeout = td.initial_time;
 
        /* Adding timeout callback for arp request */
        sd->arp_reply_timer = g_timeout_add(1000, __arp_reply_timeout_cb,
@@ -460,19 +457,17 @@ gboolean handle_is_ip_conflict_detect_enabled(Wifi *wifi, GDBusMethodInvocation
        return TRUE;
 }
 
-gboolean handle_set_ip_conflict_mode(Wifi *wifi, GDBusMethodInvocation *context,
-                                    guint mode, guint initial_time)
+gboolean handle_set_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context, guint initial_time)
 {
        g_return_val_if_fail(wifi != NULL, FALSE);
        if (initial_time < MAX_ARP_SEND_TIME && initial_time > MIN_ARP_SEND_TIME)
                return FALSE;
 
        td.initial_time = 1000 * initial_time;
-       td.mode = mode;
        // remove timer
        stop_ip_conflict_mon();
        start_ip_conflict_mon();
-       wifi_complete_set_ip_conflict_mode(wifi, context);
+       wifi_complete_set_ip_conflict_period(wifi, context);
        return TRUE;
 }
 
@@ -484,3 +479,12 @@ gboolean handle_get_ip_conflict_state(Wifi *wifi, GDBusMethodInvocation *context
        g_dbus_method_invocation_return_value(context, param);
        return TRUE;
 }
+
+gboolean handle_get_ip_conflict_period(Wifi *wifi, GDBusMethodInvocation *context)
+{
+       g_return_val_if_fail(wifi != NULL, FALSE);
+       GVariant *param = NULL;
+       param = g_variant_new("(u)", td.initial_time/1000);
+       g_dbus_method_invocation_return_value(context, param);
+       return TRUE;
+}
index 0fdc0ba..3ec8d94 100755 (executable)
@@ -196,10 +196,12 @@ void wifi_object_create_and_init(void)
                        G_CALLBACK(handle_ip_conflict_set_enable), NULL);
        g_signal_connect(wifi_object, "handle-is-ip-conflict-detect-enabled",
                        G_CALLBACK(handle_is_ip_conflict_detect_enabled), NULL);
-       g_signal_connect(wifi_object, "handle-set-ip-conflict-mode",
-                       G_CALLBACK(handle_set_ip_conflict_mode), NULL);
+       g_signal_connect(wifi_object, "handle-set-ip-conflict-period",
+                       G_CALLBACK(handle_set_ip_conflict_period), NULL);
        g_signal_connect(wifi_object, "handle-get-ip-conflict-state",
                        G_CALLBACK(handle_get_ip_conflict_state), NULL);
+       g_signal_connect(wifi_object, "handle-get-ip-conflict-period",
+                       G_CALLBACK(handle_get_ip_conflict_period), NULL);
 
        /* WIFI configuration */
        g_signal_connect(wifi_object, "handle-save-configuration",