From 2a886f4333432a1b90ad7c7323546c79256d840b Mon Sep 17 00:00:00 2001 From: Abhishek Sansanwal Date: Fri, 27 Oct 2017 13:01:14 +0530 Subject: [PATCH] Changes to IP conflict detection mode get/set API. 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 Change-Id: I7d05dc9f93825ef091938568fb51ae021efe091c --- include/ip-conflict-detect.h | 8 +++--- interfaces/netconfig-iface-wifi.xml | 6 +++-- resources/etc/dbus-1/system.d/net-config.conf | 2 ++ src/ip-conflict-detect.c | 38 +++++++++++++++------------ src/wifi.c | 6 +++-- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/include/ip-conflict-detect.h b/include/ip-conflict-detect.h index 6cd9608..f830a4f 100644 --- a/include/ip-conflict-detect.h +++ b/include/ip-conflict-detect.h @@ -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 } diff --git a/interfaces/netconfig-iface-wifi.xml b/interfaces/netconfig-iface-wifi.xml index 023659c..54c665a 100755 --- a/interfaces/netconfig-iface-wifi.xml +++ b/interfaces/netconfig-iface-wifi.xml @@ -37,6 +37,9 @@ + + + @@ -64,8 +67,7 @@ - - + diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf index 5355c87..04677f7 100755 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -20,6 +20,8 @@ + + diff --git a/src/ip-conflict-detect.c b/src/ip-conflict-detect.c index 414298a..53c1dd1 100644 --- a/src/ip-conflict-detect.c +++ b/src/ip-conflict-detect.c @@ -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; +} diff --git a/src/wifi.c b/src/wifi.c index 0fdc0ba..3ec8d94 100755 --- a/src/wifi.c +++ b/src/wifi.c @@ -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", -- 2.7.4