[PATCH 0/2] device and wifi cleanup

2011-08-24 Thread Jukka Rissanen
Hi,

attached patches do minor cleanup for device.c and wifi.c

Regards,
Jukka


Jukka Rissanen (2):
  device: Device scan function made private.
  wifi: Remove not used code.

 plugins/wifi.c |   14 --
 src/connman.h  |1 -
 src/device.c   |4 ++--
 3 files changed, 2 insertions(+), 17 deletions(-)

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH 1/2] device: Device scan function made private.

2011-08-24 Thread Jukka Rissanen
The __connman_device_scan() is now static as it is only
called from device.c
---
 src/connman.h |1 -
 src/device.c  |4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 17add6d..9ed9d24 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -361,7 +361,6 @@ void __connman_device_set_network(struct connman_device 
*device,
struct connman_network *network);
 void __connman_device_cleanup_networks(struct connman_device *device);
 
-int __connman_device_scan(struct connman_device *device);
 int __connman_device_enable(struct connman_device *device);
 int __connman_device_enable_persistent(struct connman_device *device);
 int __connman_device_disable(struct connman_device *device);
diff --git a/src/device.c b/src/device.c
index 3fb4b1e..12fa49a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -725,7 +725,7 @@ connman_bool_t __connman_device_get_blocked(struct 
connman_device *device)
return device-blocked;
 }
 
-int __connman_device_scan(struct connman_device *device)
+static int device_scan(struct connman_device *device)
 {
if (!device-driver || !device-driver-scan)
return -EOPNOTSUPP;
@@ -1310,7 +1310,7 @@ int __connman_device_request_scan(enum 
connman_service_type type)
continue;
}
 
-   err = __connman_device_scan(device);
+   err = device_scan(device);
if (err  0  err != -EINPROGRESS) {
DBG(err %d, err);
/* XXX maybe only a continue? */
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH 2/2] wifi: Remove not used code.

2011-08-24 Thread Jukka Rissanen
---
 plugins/wifi.c |   14 --
 1 files changed, 0 insertions(+), 14 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 469ec67..f3ea836 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -764,26 +764,12 @@ static void interface_removed(GSupplicantInterface 
*interface)
 
 static void scan_started(GSupplicantInterface *interface)
 {
-   struct wifi_data *wifi;
-
DBG();
-
-   wifi = g_supplicant_interface_get_data(interface);
-
-   if (wifi == NULL)
-   return;
 }
 
 static void scan_finished(GSupplicantInterface *interface)
 {
-   struct wifi_data *wifi;
-
DBG();
-
-   wifi = g_supplicant_interface_get_data(interface);
-
-   if (wifi == NULL)
-   return;
 }
 
 static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH service move v2 1/6] service: Ignore ipconfig that is not active when moving service.

2011-08-24 Thread Jukka Rissanen
---
 src/service.c |   49 +
 1 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/service.c b/src/service.c
index fc90934..b8f1c70 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2920,6 +2920,8 @@ static DBusMessage *move_service(DBusConnection *conn,
struct connman_service *target;
const char *path;
GSequenceIter *src, *dst;
+   enum connman_ipconfig_method target4, target6;
+   enum connman_ipconfig_method service4, service6;
 
DBG(service %p, service);
 
@@ -2933,11 +2935,50 @@ static DBusMessage *move_service(DBusConnection *conn,
if (target == NULL || target-favorite == FALSE || target == service)
return __connman_error_invalid_service(msg);
 
-   DBG(target %s, target-identifier);
+   target4 = __connman_ipconfig_get_method(target-ipconfig_ipv4);
+   target6 = __connman_ipconfig_get_method(target-ipconfig_ipv6);
+   service4 = __connman_ipconfig_get_method(service-ipconfig_ipv4);
+   service6 = __connman_ipconfig_get_method(service-ipconfig_ipv6);
 
-   if (target-state_ipv4 != service-state_ipv4 
-   target-state_ipv6 != service-state_ipv6)
-   return __connman_error_invalid_service(msg);
+   DBG(target %s method %d/%d state %d/%d, target-identifier,
+   target4, target6,
+   target-state_ipv4, target-state_ipv6);
+
+   DBG(service %s method %d/%d state %d/%d, service-identifier,
+   service4, service6,
+   service-state_ipv4, service-state_ipv6);
+
+   /*
+* If method is OFF, then we do not need to check the corresponding
+* ipconfig state.
+*/
+   if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (target-state_ipv6 != service-state_ipv6)
+   return __connman_error_invalid_service(msg);
+   }
+   }
+
+   if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (target-state_ipv4 != service-state_ipv4)
+   return __connman_error_invalid_service(msg);
+   }
+   }
+
+   if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (target-state_ipv6 != service-state_ipv6)
+   return __connman_error_invalid_service(msg);
+   }
+   }
+
+   if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
+   if (target-state_ipv4 != service-state_ipv4)
+   return __connman_error_invalid_service(msg);
+   }
+   }
 
g_get_current_time(service-modified);
__connman_storage_save_service(service);
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH service move v2 0/6] Fix moving services

2011-08-24 Thread Jukka Rissanen
Hi,

This v2 fixes style issue in service.c (patch #4) and
unnecessary pointer check in connection.c (patch #6).

This patchset fixes the https://bugs.meego.com/show_bug.cgi?id=22540
and allows connected services to be moved around. When moving
connected services, the default route is also properly set.

Regards,
Jukka


Jukka Rissanen (6):
  service: Ignore ipconfig that is not active when moving service.
  service: Allow ready service to be moved before online one.
  service: Allow state downgrade from online to ready.
  service: Prefer online state over ready when comparing services.
  test: Script for testing service.MoveBefore interface.
  connection: Default gateway is changed when reorganizing services.

 src/connection.c |   90 +++-
 src/connman.h|1 +
 src/service.c|  104 +++---
 test/service-move-before |   27 
 4 files changed, 214 insertions(+), 8 deletions(-)
 create mode 100755 test/service-move-before

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH service move v2 3/6] service: Allow state downgrade from online to ready.

2011-08-24 Thread Jukka Rissanen
---
 src/connman.h |1 +
 src/service.c |   19 +++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 17add6d..d74e653 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -560,6 +560,7 @@ void __connman_service_notify(struct connman_service 
*service,
 
 int __connman_service_counter_register(const char *counter);
 void __connman_service_counter_unregister(const char *counter);
+void __connman_service_downgrade_state(struct connman_service *service);
 
 struct connman_session;
 struct service_entry;
diff --git a/src/service.c b/src/service.c
index 2819d51..0380dbe 100644
--- a/src/service.c
+++ b/src/service.c
@@ -5158,6 +5158,25 @@ __connman_service_create_from_provider(struct 
connman_provider *provider)
return service;
 }
 
+void __connman_service_downgrade_state(struct connman_service *service)
+{
+   if (service == NULL)
+   return;
+
+   DBG(service %p state4 %d state6 %d, service, service-state_ipv4,
+   service-state_ipv6);
+
+   if (service-state_ipv4 == CONNMAN_SERVICE_STATE_ONLINE)
+   __connman_service_ipconfig_indicate_state(service,
+   CONNMAN_SERVICE_STATE_READY,
+   CONNMAN_IPCONFIG_TYPE_IPV4);
+
+   if (service-state_ipv6 == CONNMAN_SERVICE_STATE_ONLINE)
+   __connman_service_ipconfig_indicate_state(service,
+   CONNMAN_SERVICE_STATE_READY,
+   CONNMAN_IPCONFIG_TYPE_IPV6);
+}
+
 static int service_load(struct connman_service *service)
 {
const char *ident = service-profile;
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH service move v2 5/6] test: Script for testing service.MoveBefore interface.

2011-08-24 Thread Jukka Rissanen
---
 test/service-move-before |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100755 test/service-move-before

diff --git a/test/service-move-before b/test/service-move-before
new file mode 100755
index 000..f1fddd1
--- /dev/null
+++ b/test/service-move-before
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def print_usage():
+   print Usage: %s service target service % (sys.argv[0])
+
+
+if (len(sys.argv)  2):
+   print_usage()
+   sys.exit(1)
+
+bus = dbus.SystemBus()
+path = /profile/default/ + sys.argv[1]
+service = dbus.Interface(bus.get_object('net.connman', path),
+   'net.connman.Service')
+
+path2 = /profile/default/ + sys.argv[2]
+service2 = dbus.Interface(bus.get_object('net.connman', path2),
+   'net.connman.Service')
+
+print Moving %s before %s % (sys.argv[1], sys.argv[2])
+
+service.MoveBefore(service2)
+
+print
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH service move v2 2/6] service: Allow ready service to be moved before online one.

2011-08-24 Thread Jukka Rissanen
---
 src/service.c |   28 
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/service.c b/src/service.c
index b8f1c70..2819d51 100644
--- a/src/service.c
+++ b/src/service.c
@@ -2912,6 +2912,22 @@ static DBusMessage *remove_service(DBusConnection *conn,
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+static gboolean check_suitable_state(enum connman_service_state a,
+   enum connman_service_state b)
+{
+   /*
+* Special check so that ready service can be moved before
+* online one.
+*/
+   if ((a == CONNMAN_SERVICE_STATE_ONLINE 
+   b == CONNMAN_SERVICE_STATE_READY) ||
+   (b == CONNMAN_SERVICE_STATE_ONLINE 
+   a == CONNMAN_SERVICE_STATE_READY))
+   return TRUE;
+
+   return a == b;
+}
+
 static DBusMessage *move_service(DBusConnection *conn,
DBusMessage *msg, void *user_data,
gboolean before)
@@ -2954,28 +2970,32 @@ static DBusMessage *move_service(DBusConnection *conn,
 */
if (target4 == CONNMAN_IPCONFIG_METHOD_OFF) {
if (service6 != CONNMAN_IPCONFIG_METHOD_OFF) {
-   if (target-state_ipv6 != service-state_ipv6)
+   if (check_suitable_state(target-state_ipv6,
+   service-state_ipv6) == FALSE)
return __connman_error_invalid_service(msg);
}
}
 
if (target6 == CONNMAN_IPCONFIG_METHOD_OFF) {
if (service4 != CONNMAN_IPCONFIG_METHOD_OFF) {
-   if (target-state_ipv4 != service-state_ipv4)
+   if (check_suitable_state(target-state_ipv4,
+   service-state_ipv4) == FALSE)
return __connman_error_invalid_service(msg);
}
}
 
if (service4 == CONNMAN_IPCONFIG_METHOD_OFF) {
if (target6 != CONNMAN_IPCONFIG_METHOD_OFF) {
-   if (target-state_ipv6 != service-state_ipv6)
+   if (check_suitable_state(target-state_ipv6,
+   service-state_ipv6) == FALSE)
return __connman_error_invalid_service(msg);
}
}
 
if (service6 == CONNMAN_IPCONFIG_METHOD_OFF) {
if (target4 != CONNMAN_IPCONFIG_METHOD_OFF) {
-   if (target-state_ipv4 != service-state_ipv4)
+   if (check_suitable_state(target-state_ipv4,
+   service-state_ipv4) == FALSE)
return __connman_error_invalid_service(msg);
}
}
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH service move v2 6/6] connection: Default gateway is changed when reorganizing services.

2011-08-24 Thread Jukka Rissanen
Fixes BMC#22540
---
 src/connection.c |   90 -
 1 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 84e3ab4..3a6a116 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -326,6 +326,70 @@ done:
__connman_service_indicate_default(data-service);
 }
 
+static void unset_default_gateway(struct gateway_data *data,
+   enum connman_ipconfig_type type)
+{
+   int index;
+   int status4 = 0, status6 = 0;
+   int do_ipv4 = FALSE, do_ipv6 = FALSE;
+
+   if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+   do_ipv4 = TRUE;
+   else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+   do_ipv6 = TRUE;
+   else
+   do_ipv4 = do_ipv6 = TRUE;
+
+   DBG(type %d gateway ipv4 %p ipv6 %p, type, data-ipv4_gateway,
+   data-ipv6_gateway);
+
+   if (do_ipv4 == TRUE  data-ipv4_gateway != NULL 
+   data-ipv4_gateway-vpn == TRUE) {
+   connman_inet_del_host_route(data-index,
+   data-ipv4_gateway-vpn_ip);
+   connman_inet_clear_gateway_address(data-index,
+   data-ipv4_gateway-vpn_ip);
+   data-ipv4_gateway-active = FALSE;
+
+   return;
+   }
+
+   if (do_ipv6 == TRUE  data-ipv6_gateway != NULL 
+   data-ipv6_gateway-vpn == TRUE) {
+   connman_inet_del_ipv6_host_route(data-index,
+   data-ipv6_gateway-vpn_ip);
+   connman_inet_clear_ipv6_gateway_address(data-index,
+   data-ipv6_gateway-vpn_ip);
+   data-ipv6_gateway-active = FALSE;
+
+   return;
+   }
+
+   index = __connman_service_get_index(data-service);
+
+   if (do_ipv4 == TRUE  data-ipv4_gateway != NULL 
+   g_strcmp0(data-ipv4_gateway-gateway,
+   0.0.0.0) == 0) {
+   connman_inet_clear_gateway_interface(index);
+   return;
+   }
+
+   if (do_ipv6 == TRUE  data-ipv6_gateway != NULL 
+   g_strcmp0(data-ipv6_gateway-gateway,
+   ::) == 0) {
+   connman_inet_clear_ipv6_gateway_interface(index);
+   return;
+   }
+
+   if (do_ipv6 == TRUE  data-ipv6_gateway != NULL)
+   status6 = connman_inet_clear_ipv6_gateway_address(index,
+   data-ipv6_gateway-gateway);
+
+   if (do_ipv4 == TRUE  data-ipv4_gateway != NULL)
+   status4 = connman_inet_clear_gateway_address(index,
+   data-ipv4_gateway-gateway);
+}
+
 static struct gateway_data *find_default_gateway(void)
 {
struct gateway_data *found = NULL;
@@ -684,14 +748,36 @@ gboolean __connman_connection_update_gateway(void)
if (gateway_hash == NULL)
return updated;
 
+   active_gateway = find_active_gateway();
+
update_order();
 
-   active_gateway = find_active_gateway();
default_gateway = find_default_gateway();
 
-   if (active_gateway  active_gateway != default_gateway)
+   if (active_gateway  active_gateway != default_gateway) {
updated = TRUE;
 
+   if (active_gateway-ipv4_gateway)
+   unset_default_gateway(active_gateway,
+   CONNMAN_IPCONFIG_TYPE_IPV4);
+
+   if (active_gateway-ipv6_gateway)
+   unset_default_gateway(active_gateway,
+   CONNMAN_IPCONFIG_TYPE_IPV6);
+
+   __connman_service_downgrade_state(active_gateway-service);
+
+   if (default_gateway) {
+   if (default_gateway-ipv4_gateway)
+   set_default_gateway(default_gateway,
+   CONNMAN_IPCONFIG_TYPE_IPV4);
+
+   if (default_gateway-ipv6_gateway)
+   set_default_gateway(default_gateway,
+   CONNMAN_IPCONFIG_TYPE_IPV6);
+   }
+   }
+
return updated;
 }
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH service move v2 0/6] Fix moving services

2011-08-24 Thread Samuel Ortiz
Hi Jukka,

On Wed, Aug 24, 2011 at 11:36:37AM +0300, Jukka Rissanen wrote:
 Hi,
 
 This v2 fixes style issue in service.c (patch #4) and
 unnecessary pointer check in connection.c (patch #6).
 
 This patchset fixes the https://bugs.meego.com/show_bug.cgi?id=22540
 and allows connected services to be moved around. When moving
 connected services, the default route is also properly set.
Thanks. All 6 patches applied. I had to manually fix #6 as it was introducing
a couple of warnings.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH] pacrunner: libproxy: supports various SOCKS proxies

2011-08-24 Thread Alban Crequy
Le Tue, 23 Aug 2011 18:32:20 +0200,
Samuel Ortiz sa...@linux.intel.com a écrit :

 Hi Alban,
 
 On Wed, Aug 17, 2011 at 04:41:38PM +0100, Alban Crequy wrote:
  @@ -77,12 +77,12 @@ static char **extract_result(const char *str)
  result[0] = NULL;
  result[1] = NULL;
   
  -   if (strcmp(str, DIRECT) == 0) {
  +   if (strcasecmp(str, DIRECT) == 0) {
  result[0] = strdup(direct://);
  return result;
  }
   
  -   if (strncmp(str, PROXY , 6) == 0) {
  +   if (strncasecmp(str, PROXY , 6) == 0) {
 So those 2 changes are not related to this patch. Moreover, why would
 we want to be case-insensitive now ?

In order to be compatible with existing PAC files which return
something like proxy server:port. They work on Windows but they would
not work if pacrunner is case-sensitive.

We don't lose anything by accepting those existing PAC files in my
opinion. libproxy is also case-insensitive.

I'm not sure if there was any consensus in our discussion on IRC
yesterday. So I will send a patch to support only SOCKS now and keep
the discussion about the case sensitiveness and SOCKS4a for later.

Cheers,
Alban
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH] pacrunner: libproxy: supports various SOCKS proxies

2011-08-24 Thread Samuel Ortiz
Hi Alban,

On Wed, Aug 24, 2011 at 01:15:15PM +0100, Alban Crequy wrote:
 Le Tue, 23 Aug 2011 18:32:20 +0200,
 Samuel Ortiz sa...@linux.intel.com a écrit :
 
  Hi Alban,
  
  On Wed, Aug 17, 2011 at 04:41:38PM +0100, Alban Crequy wrote:
   @@ -77,12 +77,12 @@ static char **extract_result(const char *str)
 result[0] = NULL;
 result[1] = NULL;

   - if (strcmp(str, DIRECT) == 0) {
   + if (strcasecmp(str, DIRECT) == 0) {
 result[0] = strdup(direct://);
 return result;
 }

   - if (strncmp(str, PROXY , 6) == 0) {
   + if (strncasecmp(str, PROXY , 6) == 0) {
  So those 2 changes are not related to this patch. Moreover, why would
  we want to be case-insensitive now ?
 
 In order to be compatible with existing PAC files which return
 something like proxy server:port. They work on Windows but they would
 not work if pacrunner is case-sensitive.
I was under the impression that only upper case strings were accepted, but I
guess not. Thanks Windows.

 
 We don't lose anything by accepting those existing PAC files in my
 opinion. libproxy is also case-insensitive.
 
 I'm not sure if there was any consensus in our discussion on IRC
 yesterday. 
I think it basically was that case insensitiveness is fine but the SOCKS4a is
not at that point.

Please send me 2 patches: One that adds case insensitiveness to the existing
code, and another one for adding SOCKS, SOCKS4 and SOCKS5 support.

Thanks in advance.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 01/24] technology: Refactor enable/disable APIs.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

connman_technology_enable: Enable a technology. Enables all the
devices in the device_list of the technology.
connman_technology_enabled: Callback for connman_technology_enable.
Changes the state of the technology to ENABLED.
Ditto for connman_technology_disable/connman_technology_disabled.
---
 src/connman.h|5 ++-
 src/device.c |   65 +++--
 src/manager.c|8 +++---
 src/technology.c |   58 ++-
 4 files changed, 67 insertions(+), 69 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 17add6d..c7cb0dd 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -314,8 +314,11 @@ void __connman_technology_list(DBusMessageIter *iter, void 
*user_data);
 
 int __connman_technology_add_device(struct connman_device *device);
 int __connman_technology_remove_device(struct connman_device *device);
+int __connman_technology_enabled(enum connman_service_type type);
 int __connman_technology_enable(enum connman_service_type type);
+int __connman_technology_disabled(enum connman_service_type type);
 int __connman_technology_disable(enum connman_service_type type);
+
 int __connman_technology_add_rfkill(unsigned int index,
enum connman_service_type type,
connman_bool_t softblock,
@@ -342,8 +345,6 @@ void __connman_device_list(DBusMessageIter *iter, void 
*user_data);
 enum connman_service_type __connman_device_get_service_type(struct 
connman_device *device);
 struct connman_device *__connman_device_find_device(enum connman_service_type 
type);
 int __connman_device_request_scan(enum connman_service_type type);
-int __connman_device_enable_technology(enum connman_service_type type);
-int __connman_device_disable_technology(enum connman_service_type type);
 
 connman_bool_t __connman_device_isfiltered(const char *devname);
 
diff --git a/src/device.c b/src/device.c
index 3fb4b1e..e4603cc 100644
--- a/src/device.c
+++ b/src/device.c
@@ -246,7 +246,7 @@ int __connman_device_enable(struct connman_device *device)
__connman_profile_set_offlinemode(FALSE, FALSE);
 
type = __connman_device_get_service_type(device);
-   __connman_technology_enable(type);
+   __connman_technology_enabled(type);
 
return 0;
 }
@@ -286,7 +286,7 @@ int __connman_device_disable(struct connman_device *device)
device-powered = FALSE;
 
type = __connman_device_get_service_type(device);
-   __connman_technology_disable(type);
+   __connman_technology_disabled(type);
 
return 0;
 }
@@ -680,9 +680,9 @@ int connman_device_set_powered(struct connman_device 
*device,
type = __connman_device_get_service_type(device);
 
if (device-powered == TRUE)
-   __connman_technology_enable(type);
+   __connman_technology_enabled(type);
else
-   __connman_technology_disable(type);
+   __connman_technology_disabled(type);
 
if (device-offlinemode == TRUE  powered == TRUE)
return connman_device_set_powered(device, FALSE);
@@ -1321,63 +1321,6 @@ int __connman_device_request_scan(enum 
connman_service_type type)
return 0;
 }
 
-static int set_technology(enum connman_service_type type, connman_bool_t 
enable)
-{
-   GSList *list;
-   int err;
-
-   DBG(type %d enable %d, type, enable);
-
-   switch (type) {
-   case CONNMAN_SERVICE_TYPE_UNKNOWN:
-   case CONNMAN_SERVICE_TYPE_SYSTEM:
-   case CONNMAN_SERVICE_TYPE_GPS:
-   case CONNMAN_SERVICE_TYPE_VPN:
-   case CONNMAN_SERVICE_TYPE_GADGET:
-   return 0;
-   case CONNMAN_SERVICE_TYPE_ETHERNET:
-   case CONNMAN_SERVICE_TYPE_WIFI:
-   case CONNMAN_SERVICE_TYPE_WIMAX:
-   case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-   case CONNMAN_SERVICE_TYPE_CELLULAR:
-   break;
-   }
-
-   for (list = device_list; list != NULL; list = list-next) {
-   struct connman_device *device = list-data;
-   enum connman_service_type service_type =
-   __connman_device_get_service_type(device);
-
-   if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN 
-   service_type != type) {
-   continue;
-   }
-
-   if (enable == TRUE)
-   err = __connman_device_enable_persistent(device);
-   else
-   err = __connman_device_disable_persistent(device);
-
-   if (err  0  err != -EINPROGRESS) {
-   DBG(err %d, err);
-   /* XXX maybe only a continue? */
-   return err;
-   }
-   }
-
-   return 0;
-}
-
-int __connman_device_enable_technology(enum connman_service_type type)
-{
-   return set_technology(type, 

[PATCH v2 02/24] device: update profile in enable_persistent callback.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

---
 src/device.c |   14 +-
 src/technology.c |5 +
 2 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/src/device.c b/src/device.c
index e4603cc..61945d4 100644
--- a/src/device.c
+++ b/src/device.c
@@ -740,25 +740,13 @@ int __connman_device_scan(struct connman_device *device)
 
 int __connman_device_enable_persistent(struct connman_device *device)
 {
-   int err;
-
DBG(device %p, device);
 
device-powered_persistent = TRUE;
 
__connman_storage_save_device(device);
 
-   err = __connman_device_enable(device);
-   if (err == 0 || err == -EINPROGRESS) {
-   device-offlinemode = FALSE;
-   if (__connman_profile_get_offlinemode() == TRUE) {
-   __connman_profile_set_offlinemode(FALSE, FALSE);
-
-   __connman_profile_save_default();
-   }
-   }
-
-   return err;
+   return __connman_device_enable(device);
 }
 
 int __connman_device_disable_persistent(struct connman_device *device)
diff --git a/src/technology.c b/src/technology.c
index cb065e2..2e91b41 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -693,6 +693,11 @@ int __connman_technology_enabled(enum connman_service_type 
type)
state_changed(technology);
}
 
+   if (__connman_profile_get_offlinemode() == TRUE) {
+   __connman_profile_set_offlinemode(FALSE, FALSE);
+   __connman_profile_save_default();
+   }
+
return 0;
 }
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 04/24] technology: Modify technology enable/disable APIs.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Add the pending dbus message per technology. Also move the pending
timeout from manager to technology.
---
 src/connman.h|4 +-
 src/manager.c|   88 ++
 src/technology.c |  113 +++--
 3 files changed, 106 insertions(+), 99 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index c7cb0dd..05681a6 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -315,9 +315,9 @@ void __connman_technology_list(DBusMessageIter *iter, void 
*user_data);
 int __connman_technology_add_device(struct connman_device *device);
 int __connman_technology_remove_device(struct connman_device *device);
 int __connman_technology_enabled(enum connman_service_type type);
-int __connman_technology_enable(enum connman_service_type type);
+int __connman_technology_enable(enum connman_service_type type, DBusMessage 
*msg);
 int __connman_technology_disabled(enum connman_service_type type);
-int __connman_technology_disable(enum connman_service_type type);
+int __connman_technology_disable(enum connman_service_type type, DBusMessage 
*msg);
 
 int __connman_technology_add_rfkill(unsigned int index,
enum connman_service_type type,
diff --git a/src/manager.c b/src/manager.c
index a276e0b..54de643 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -221,59 +221,6 @@ static DBusMessage *request_scan(DBusConnection *conn,
 
 static DBusConnection *connection = NULL;
 
-static enum connman_service_type technology_type;
-static connman_bool_t technology_enabled;
-static DBusMessage *technology_pending = NULL;
-static guint technology_timeout = 0;
-
-static void technology_reply(int error)
-{
-   DBG();
-
-   if (technology_timeout  0) {
-   g_source_remove(technology_timeout);
-   technology_timeout = 0;
-   }
-
-   if (technology_pending != NULL) {
-   if (error  0) {
-   DBusMessage *reply;
-
-   reply = __connman_error_failed(technology_pending,
-   error);
-   if (reply != NULL)
-   g_dbus_send_message(connection, reply);
-   } else
-   g_dbus_send_reply(connection, technology_pending,
-   DBUS_TYPE_INVALID);
-
-   dbus_message_unref(technology_pending);
-   technology_pending = NULL;
-   }
-
-   technology_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
-}
-
-static gboolean technology_abort(gpointer user_data)
-{
-   DBG();
-
-   technology_timeout = 0;
-
-   technology_reply(ETIMEDOUT);
-
-   return FALSE;
-}
-
-static void technology_notify(enum connman_service_type type,
-   connman_bool_t enabled)
-{
-   DBG(type %d enabled %d, type, enabled);
-
-   if (type == technology_type  enabled == technology_enabled)
-   technology_reply(0);
-}
-
 static void session_mode_notify(void)
 {
DBusMessage *reply;
@@ -301,7 +248,6 @@ static void idle_state(connman_bool_t idle)
 static struct connman_notifier technology_notifier = {
.name   = manager,
.priority   = CONNMAN_NOTIFIER_PRIORITY_HIGH,
-   .service_enabled= technology_notify,
.idle_state = idle_state,
 };
 
@@ -310,13 +256,9 @@ static DBusMessage *enable_technology(DBusConnection *conn,
 {
enum connman_service_type type;
const char *str;
-   int err;
 
DBG(conn %p, conn);
 
-   if (technology_pending != NULL)
-   return __connman_error_in_progress(msg);
-
dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, str,
DBUS_TYPE_INVALID);
 
@@ -339,16 +281,7 @@ static DBusMessage *enable_technology(DBusConnection *conn,
if (__connman_notifier_is_enabled(type) == TRUE)
return __connman_error_already_enabled(msg);
 
-   technology_type = type;
-   technology_enabled = TRUE;
-   technology_pending = dbus_message_ref(msg);
-
-   err = __connman_technology_enable(type);
-   if (err  0)
-   technology_reply(-err);
-   else
-   technology_timeout = g_timeout_add_seconds(15,
-   technology_abort, NULL);
+__connman_technology_enable(type, msg);
 
return NULL;
 }
@@ -358,13 +291,9 @@ static DBusMessage *disable_technology(DBusConnection 
*conn,
 {
enum connman_service_type type;
const char *str;
-   int err;
 
DBG(conn %p, conn);
 
-   if (technology_pending != NULL)
-   return __connman_error_in_progress(msg);
-
dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, str,
  

[PATCH v2 03/24] device: redo pending power request logic.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Use 3 values(None/Enable/Disable) for the power_pending.
It helps keep track of the ongoing pending request.
Add a pending timeout. If the daemon handling the device fails
to send a response then we need to reset the power_pending flag.
---
 src/device.c |  149 --
 1 files changed, 92 insertions(+), 57 deletions(-)

diff --git a/src/device.c b/src/device.c
index 61945d4..7611ff1 100644
--- a/src/device.c
+++ b/src/device.c
@@ -32,13 +32,20 @@ static GSList *device_list = NULL;
 static gchar **device_filter = NULL;
 static gchar **nodevice_filter = NULL;
 
+enum connman_pending_type {
+   PENDING_NONE= 0,
+   PENDING_ENABLE  = 1,
+   PENDING_DISABLE = 2,
+};
+
 struct connman_device {
gint refcount;
enum connman_device_type type;
+   enum connman_pending_type powered_pending;  /* Indicates a pending
+   enable/disable request 
*/
connman_bool_t offlinemode;
connman_bool_t blocked;
connman_bool_t powered;
-   connman_bool_t powered_pending;
connman_bool_t powered_persistent;
connman_bool_t scanning;
connman_bool_t disconnected;
@@ -56,6 +63,7 @@ struct connman_device {
int index;
unsigned int connections;
guint scan_timeout;
+   guint pending_timeout;
 
struct connman_device_driver *driver;
void *driver_data;
@@ -209,62 +217,93 @@ enum connman_service_type 
__connman_device_get_service_type(struct connman_devic
return CONNMAN_SERVICE_TYPE_UNKNOWN;
 }
 
+static gboolean device_pending_reset(gpointer user_data)
+{
+   struct connman_device *device = user_data;
+
+   DBG(device %p, device);
+
+   /* Power request timedout, reset power pending state. */
+   if (device-pending_timeout  0) {
+   g_source_remove(device-pending_timeout);
+   device-pending_timeout = 0;
+   device-powered_pending = PENDING_NONE;
+   }
+
+   return FALSE;
+}
+
 int __connman_device_enable(struct connman_device *device)
 {
int err;
-   enum connman_service_type type;
 
DBG(device %p %d, device, device-blocked);
 
if (!device-driver || !device-driver-enable)
return -EOPNOTSUPP;
 
-   if (device-powered_pending == TRUE)
-   return -EALREADY;
-
if (device-blocked == TRUE)
return -ENOLINK;
 
-   connman_device_set_disconnected(device, FALSE);
-   device-scanning = FALSE;
+   /* There is an ongoing power disable request. */
+   if (device-powered_pending == PENDING_DISABLE)
+   return -EBUSY;
 
-   err = device-driver-enable(device);
-   if (err  0  err != -EALREADY) {
-   if (err == -EINPROGRESS) {
-   device-powered_pending = TRUE;
-   device-offlinemode = FALSE;
-   if (__connman_profile_get_offlinemode() == TRUE)
-   __connman_profile_set_offlinemode(FALSE, FALSE);
-   }
-   return err;
-   }
+   if (device-powered_pending == PENDING_ENABLE)
+   return -EALREADY;
 
-   device-powered_pending = TRUE;
-   device-powered = TRUE;
-   device-offlinemode = FALSE;
-   if (__connman_profile_get_offlinemode() == TRUE)
-   __connman_profile_set_offlinemode(FALSE, FALSE);
+   if (device-powered_pending == PENDING_NONE  device-powered == TRUE)
+   return -EALREADY;
 
-   type = __connman_device_get_service_type(device);
-   __connman_technology_enabled(type);
+   device-powered_pending = PENDING_ENABLE;
 
-   return 0;
+   err = device-driver-enable(device);
+   /*
+* device gets enabled right away.
+* Invoke the callback
+*/
+   if (err == 0) {
+   connman_device_set_powered(device, TRUE);
+   goto done;
+   }
+
+   if (err == -EALREADY) {
+   /* If device is already powered, but connman is not updated */
+   connman_device_set_powered(device, TRUE);
+   goto done;
+   }
+   /*
+* if err == -EINPROGRESS, then the DBus call to the respective daemon
+* was successful. We set a 4 sec timeout so if the daemon never
+* returns a reply, we would reset the pending request.
+*/
+   if (err == -EINPROGRESS)
+   device-pending_timeout = g_timeout_add_seconds(4,
+   device_pending_reset, device);
+done:
+   return err;
 }
 
 int __connman_device_disable(struct connman_device *device)
 {
int err;
-   enum connman_service_type type;
 
DBG(device %p, device);
 
if (!device-driver || !device-driver-disable)
return -EOPNOTSUPP;
 
-   if 

[PATCH v2 05/24] technology: Remove global rfkill table.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Remove the global rfkill_table and maintain a per technology
rfkill table.
---
 src/connman.h|4 +++-
 src/rfkill.c |9 +
 src/technology.c |   16 +---
 3 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 05681a6..2fb4ea3 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -324,9 +324,11 @@ int __connman_technology_add_rfkill(unsigned int index,
connman_bool_t softblock,
connman_bool_t hardblock);
 int __connman_technology_update_rfkill(unsigned int index,
+   enum connman_service_type type,
connman_bool_t softblock,
connman_bool_t hardblock);
-int __connman_technology_remove_rfkill(unsigned int index);
+int __connman_technology_remove_rfkill(unsigned int index,
+   enum connman_service_type type);
 
 void __connman_technology_add_interface(enum connman_service_type type,
int index, const char *name, const char *ident);
diff --git a/src/rfkill.c b/src/rfkill.c
index 2a4458b..3d214ef 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -99,18 +99,19 @@ static GIOStatus rfkill_process(GIOChannel *chan)
event-type, event-op,
event-soft, event-hard);
 
+   type = convert_type(event-type);
+
switch (event-op) {
case RFKILL_OP_ADD:
-   type = convert_type(event-type);
__connman_technology_add_rfkill(event-idx, type,
event-soft, event-hard);
break;
case RFKILL_OP_DEL:
-   __connman_technology_remove_rfkill(event-idx);
+   __connman_technology_remove_rfkill(event-idx, type);
break;
case RFKILL_OP_CHANGE:
-   __connman_technology_update_rfkill(event-idx, event-soft,
-   event-hard);
+   __connman_technology_update_rfkill(event-idx, type,
+   event-soft, event-hard);
break;
default:
break;
diff --git a/src/technology.c b/src/technology.c
index cc44658..849d72a 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -32,7 +32,6 @@
 
 static DBusConnection *connection;
 
-static GHashTable *rfkill_table;
 static GHashTable *device_table;
 static GSList *technology_list = NULL;
 
@@ -908,8 +907,6 @@ int __connman_technology_add_rfkill(unsigned int index,
rfkill-softblock = softblock;
rfkill-hardblock = hardblock;
 
-   g_hash_table_replace(rfkill_table, rfkill-index, technology);
-
g_hash_table_replace(technology-rfkill_list, rfkill-index, rfkill);
 
blocked = (softblock || hardblock) ? TRUE : FALSE;
@@ -927,6 +924,7 @@ int __connman_technology_add_rfkill(unsigned int index,
 }
 
 int __connman_technology_update_rfkill(unsigned int index,
+   enum connman_service_type type,
connman_bool_t softblock,
connman_bool_t hardblock)
 {
@@ -936,7 +934,7 @@ int __connman_technology_update_rfkill(unsigned int index,
 
DBG(index %u soft %u hard %u, index, softblock, hardblock);
 
-   technology = g_hash_table_lookup(rfkill_table, index);
+   technology = technology_find(type);
if (technology == NULL)
return -ENXIO;
 
@@ -976,7 +974,8 @@ int __connman_technology_update_rfkill(unsigned int index,
return 0;
 }
 
-int __connman_technology_remove_rfkill(unsigned int index)
+int __connman_technology_remove_rfkill(unsigned int index,
+   enum connman_service_type type)
 {
struct connman_technology *technology;
struct connman_rfkill *rfkill;
@@ -984,7 +983,7 @@ int __connman_technology_remove_rfkill(unsigned int index)
 
DBG(index %u, index);
 
-   technology = g_hash_table_lookup(rfkill_table, index);
+   technology = technology_find(type);
if (technology == NULL)
return -ENXIO;
 
@@ -996,8 +995,6 @@ int __connman_technology_remove_rfkill(unsigned int index)
 
g_hash_table_remove(technology-rfkill_list, index);
 
-   g_hash_table_remove(rfkill_table, index);
-
if (blocked 
g_atomic_int_dec_and_test(technology-blocked) == TRUE) {
technology_blocked(technology, FALSE);
@@ -1028,8 +1025,6 @@ int __connman_technology_init(void)
 
connection = connman_dbus_get_connection();
 
-   rfkill_table = g_hash_table_new_full(g_int_hash, g_int_equal,

[PATCH v2 06/24] technology: Remove the global device hash.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

There is a device list per technology. Hence removing the global
device hash.
---
 src/technology.c |   19 +--
 1 files changed, 1 insertions(+), 18 deletions(-)

diff --git a/src/technology.c b/src/technology.c
index 849d72a..eee4981 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -32,7 +32,6 @@
 
 static DBusConnection *connection;
 
-static GHashTable *device_table;
 static GSList *technology_list = NULL;
 
 struct connman_rfkill {
@@ -614,13 +613,6 @@ void __connman_technology_remove_interface(enum 
connman_service_type type,
technology_put(technology);
 }
 
-static void unregister_technology(gpointer data)
-{
-   struct connman_technology *technology = data;
-
-   technology_put(technology);
-}
-
 int __connman_technology_add_device(struct connman_device *device)
 {
struct connman_technology *technology;
@@ -635,8 +627,6 @@ int __connman_technology_add_device(struct connman_device 
*device)
if (technology == NULL)
return -ENXIO;
 
-   g_hash_table_insert(device_table, device, technology);
-
if (g_atomic_int_get(technology-blocked))
goto done;
 
@@ -662,7 +652,7 @@ int __connman_technology_remove_device(struct 
connman_device *device)
type = __connman_device_get_service_type(device);
__connman_notifier_unregister(type);
 
-   technology = g_hash_table_lookup(device_table, device);
+   technology = technology_find(type);
if (technology == NULL)
return -ENXIO;
 
@@ -673,8 +663,6 @@ int __connman_technology_remove_device(struct 
connman_device *device)
state_changed(technology);
}
 
-   g_hash_table_remove(device_table, device);
-
return 0;
 }
 
@@ -1025,9 +1013,6 @@ int __connman_technology_init(void)
 
connection = connman_dbus_get_connection();
 
-   device_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
-   NULL, unregister_technology);
-
return 0;
 }
 
@@ -1035,7 +1020,5 @@ void __connman_technology_cleanup(void)
 {
DBG();
 
-   g_hash_table_destroy(device_table);
-
dbus_connection_unref(connection);
 }
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 07/24] technology: save state persistently.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Save the technology state persistently. This will help in resuming
the technology state after offlinemode or during startup. This patch
just saves the states.
---
 include/storage.h |3 ++
 src/connman.h |2 +
 src/storage.c |   36 +
 src/technology.c  |   90 +++--
 4 files changed, 128 insertions(+), 3 deletions(-)

diff --git a/include/storage.h b/include/storage.h
index 6b733f8..a612feb 100644
--- a/include/storage.h
+++ b/include/storage.h
@@ -25,6 +25,7 @@
 #include connman/profile.h
 #include connman/service.h
 #include connman/device.h
+#include connman/technology.h
 
 #ifdef __cplusplus
 extern C {
@@ -52,6 +53,8 @@ struct connman_storage {
enum connman_device_type device_type;
int (*device_load) (struct connman_device *device);
int (*device_save) (struct connman_device *device);
+   int (*tech_load) (struct connman_technology *technology);
+   int (*tech_save) (struct connman_technology *technology);
 };
 
 int connman_storage_register(struct connman_storage *storage);
diff --git a/src/connman.h b/src/connman.h
index 2fb4ea3..0b4e374 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -174,6 +174,8 @@ int __connman_storage_load_service(struct connman_service 
*service);
 int __connman_storage_save_service(struct connman_service *service);
 int __connman_storage_load_device(struct connman_device *device);
 int __connman_storage_save_device(struct connman_device *device);
+int __connman_storage_load_technology(struct connman_technology *technology);
+int __connman_storage_save_technology(struct connman_technology *technology);
 
 int __connman_detect_init(void);
 void __connman_detect_cleanup(void);
diff --git a/src/storage.c b/src/storage.c
index 81f9ecd..274997b 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -307,6 +307,42 @@ int __connman_storage_save_device(struct connman_device 
*device)
return -ENOENT;
 }
 
+int __connman_storage_load_technology(struct connman_technology *technology)
+{
+   GSList *list;
+
+   DBG(technology %p, technology);
+
+   for (list = storage_list; list; list = list-next) {
+   struct connman_storage *storage = list-data;
+
+   if (storage-tech_load) {
+   if (storage-tech_load(technology) == 0)
+   return 0;
+   }
+   }
+
+   return -ENOENT;
+}
+
+int __connman_storage_save_technology(struct connman_technology *technology)
+{
+   GSList *list;
+
+   DBG(technology %p, technology);
+
+   for (list = storage_list; list; list = list-next) {
+   struct connman_storage *storage = list-data;
+
+   if (storage-tech_save) {
+   if (storage-tech_save(technology) == 0)
+   return 0;
+   }
+   }
+
+   return -ENOENT;
+}
+
 int __connman_storage_init(void)
 {
DBG();
diff --git a/src/technology.c b/src/technology.c
index eee4981..fb7f058 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -64,6 +64,8 @@ struct connman_technology {
char *tethering_ident;
char *tethering_passphrase;
 
+   connman_bool_t enable_persistent; /* Save the tech state */
+
struct connman_technology_driver *driver;
void *driver_data;
 
@@ -483,6 +485,8 @@ static struct connman_technology *technology_get(enum 
connman_service_type type)
technology-pending_reply = NULL;
technology-state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
 
+   __connman_storage_load_technology(technology);
+
if (g_dbus_register_interface(connection, technology-path,
CONNMAN_TECHNOLOGY_INTERFACE,
technology_methods, technology_signals,
@@ -739,8 +743,16 @@ int __connman_technology_enable(enum connman_service_type 
type, DBusMessage *msg
goto done;
}
 
-   if (msg != NULL)
+   if (msg != NULL) {
technology-pending_reply = dbus_message_ref(msg);
+   /*
+* This is a bit of a trick. When msg is not NULL it means
+* thats technology_enable was invoked from the manager API. 
Hence we save
+* the state here.
+*/
+   technology-enable_persistent = TRUE;
+   __connman_storage_save_technology(technology);
+   }
 
for (list = technology-device_list; list; list = list-next) {
struct connman_device *device = list-data;
@@ -829,8 +841,11 @@ int __connman_technology_disable(enum connman_service_type 
type, DBusMessage *ms
goto done;
}
 
-   if (msg != NULL)
+   if (msg != NULL) {
technology-pending_reply = dbus_message_ref(msg);
+   technology-enable_persistent = FALSE;
+   

[PATCH v2 09/24] technology: Remove 'available' state.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

The connman technology state machine is simplified.
It now has 3 states:
Offline: Technology is disabled.
Enabled: Technology is enabled.
Connected: Technology is connected.
---
 doc/technology-api.txt |3 +--
 src/technology.c   |   21 +
 2 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/doc/technology-api.txt b/doc/technology-api.txt
index c86a58e..12b421c 100644
--- a/doc/technology-api.txt
+++ b/doc/technology-api.txt
@@ -21,8 +21,7 @@ Propertiesstring State [readonly]
 
The technology state information.
 
-   Valid states are offline, available, enabled
-   and connected.
+   Valid states are offline, enabled and connected.
 
string Name [readonly]
 
diff --git a/src/technology.c b/src/technology.c
index 19a096d..4d8eb03 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -44,9 +44,8 @@ struct connman_rfkill {
 enum connman_technology_state {
CONNMAN_TECHNOLOGY_STATE_UNKNOWN   = 0,
CONNMAN_TECHNOLOGY_STATE_OFFLINE   = 1,
-   CONNMAN_TECHNOLOGY_STATE_AVAILABLE = 2,
-   CONNMAN_TECHNOLOGY_STATE_ENABLED   = 3,
-   CONNMAN_TECHNOLOGY_STATE_CONNECTED = 4,
+   CONNMAN_TECHNOLOGY_STATE_ENABLED   = 2,
+   CONNMAN_TECHNOLOGY_STATE_CONNECTED = 3,
 };
 
 struct connman_technology {
@@ -256,8 +255,6 @@ static const char *state2string(enum 
connman_technology_state state)
break;
case CONNMAN_TECHNOLOGY_STATE_OFFLINE:
return offline;
-   case CONNMAN_TECHNOLOGY_STATE_AVAILABLE:
-   return available;
case CONNMAN_TECHNOLOGY_STATE_ENABLED:
return enabled;
case CONNMAN_TECHNOLOGY_STATE_CONNECTED:
@@ -634,10 +631,6 @@ int __connman_technology_add_device(struct connman_device 
*device)
if (g_atomic_int_get(technology-blocked))
goto done;
 
-   technology-state = CONNMAN_TECHNOLOGY_STATE_AVAILABLE;
-
-   state_changed(technology);
-
 done:
 
technology-device_list = g_slist_append(technology-device_list,
@@ -797,8 +790,7 @@ int __connman_technology_disabled(enum connman_service_type 
type)
 
if (g_atomic_int_dec_and_test(technology-enabled) == TRUE) {
__connman_notifier_disable(type);
-
-   technology-state = CONNMAN_TECHNOLOGY_STATE_AVAILABLE;
+   technology-state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
state_changed(technology);
}
 
@@ -809,9 +801,6 @@ int __connman_technology_disabled(enum connman_service_type 
type)
return 0;
}
 
-   technology-state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
-   state_changed(technology);
-
return 0;
 }
 
@@ -992,7 +981,7 @@ int __connman_technology_update_rfkill(unsigned int index,
return 0;
 
technology_blocked(technology, blocked);
-   technology-state = CONNMAN_TECHNOLOGY_STATE_AVAILABLE;
+   technology-state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
state_changed(technology);
}
 
@@ -1023,7 +1012,7 @@ int __connman_technology_remove_rfkill(unsigned int index,
if (blocked 
g_atomic_int_dec_and_test(technology-blocked) == TRUE) {
technology_blocked(technology, FALSE);
-   technology-state = CONNMAN_TECHNOLOGY_STATE_AVAILABLE;
+   technology-state = CONNMAN_TECHNOLOGY_STATE_OFFLINE;
state_changed(technology);
}
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 11/24] rfkill: Add technology soft blocking API.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

---
 src/connman.h |   11 ++-
 src/rfkill.c  |   56 
 2 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 884463e..5e4db20 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -135,11 +135,6 @@ typedef void (*__connman_inet_rs_cb_t) (struct 
nd_router_advert *reply,
 int __connman_inet_ipv6_send_rs(int index, int timeout,
__connman_inet_rs_cb_t callback, void *user_data);
 
-#include connman/rfkill.h
-
-int __connman_rfkill_init(void);
-void __connman_rfkill_cleanup(void);
-
 #include connman/resolver.h
 
 int __connman_resolver_init(connman_bool_t dnsproxy);
@@ -384,6 +379,12 @@ connman_bool_t __connman_device_get_reconnect(struct 
connman_device *device);
 
 const char *__connman_device_get_type(struct connman_device *device);
 
+#include connman/rfkill.h
+
+int __connman_rfkill_init(void);
+void __connman_rfkill_cleanup(void);
+int __connman_rfkill_block(enum connman_service_type type, connman_bool_t 
block);
+
 #include connman/network.h
 
 int __connman_network_init(void);
diff --git a/src/rfkill.c b/src/rfkill.c
index 3d214ef..17592da 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -41,6 +41,7 @@ enum rfkill_type {
RFKILL_TYPE_WWAN,
RFKILL_TYPE_GPS,
RFKILL_TYPE_FM,
+   NUM_RFKILL_TYPES,
 };
 
 enum rfkill_operation {
@@ -74,6 +75,30 @@ static enum connman_service_type convert_type(uint8_t type)
return CONNMAN_SERVICE_TYPE_UNKNOWN;
 }
 
+static enum rfkill_type convert_service_type(enum connman_service_type type)
+{
+   switch (type) {
+   case CONNMAN_SERVICE_TYPE_WIFI:
+   return RFKILL_TYPE_WLAN;
+   case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+   return RFKILL_TYPE_BLUETOOTH;
+   case CONNMAN_SERVICE_TYPE_WIMAX:
+   return RFKILL_TYPE_WIMAX;
+   case CONNMAN_SERVICE_TYPE_CELLULAR:
+   return RFKILL_TYPE_WWAN;
+   case CONNMAN_SERVICE_TYPE_GPS:
+   return RFKILL_TYPE_GPS;
+   case CONNMAN_SERVICE_TYPE_SYSTEM:
+   case CONNMAN_SERVICE_TYPE_ETHERNET:
+   case CONNMAN_SERVICE_TYPE_VPN:
+   case CONNMAN_SERVICE_TYPE_GADGET:
+   case CONNMAN_SERVICE_TYPE_UNKNOWN:
+   return NUM_RFKILL_TYPES;
+   }
+
+   return NUM_RFKILL_TYPES;
+}
+
 static GIOStatus rfkill_process(GIOChannel *chan)
 {
unsigned char buf[32];
@@ -134,6 +159,37 @@ static gboolean rfkill_event(GIOChannel *chan,
 
 static GIOChannel *channel = NULL;
 
+int __connman_rfkill_block(enum connman_service_type type, connman_bool_t 
block)
+{
+   uint8_t rfkill_type;
+   struct rfkill_event event;
+   ssize_t len;
+   int fd;
+
+   DBG(type %d block %d, type, block);
+
+   rfkill_type = convert_service_type(type);
+   if (rfkill_type == NUM_RFKILL_TYPES)
+   return -EINVAL;
+
+   fd = open(/dev/rfkill, O_RDWR);
+   if (fd  0)
+   return fd;
+
+   memset(event, 0, sizeof(event));
+   event.op = RFKILL_OP_CHANGE_ALL;
+   event.type = rfkill_type;
+   event.soft = block;
+
+   len = write(fd, event, sizeof(event));
+   if (len  0)
+   connman_error(Failed to change RFKILL state);
+
+   close(fd);
+
+   return 0;
+}
+
 int __connman_rfkill_init(void)
 {
GIOFlags flags;
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 10/24] technology: Fix enable notifier to be invoked just once.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

When there are multiple devices, the technology enable notifier
was invoked multiple times. But when disabling the technology, the
disable notifier was invoked just once, hence there was a mismatch
in the technology states.
---
 src/technology.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/src/technology.c b/src/technology.c
index 4d8eb03..ae381aa 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -693,9 +693,8 @@ int __connman_technology_enabled(enum connman_service_type 
type)
if (g_atomic_int_get(technology-blocked))
return -ERFKILL;
 
-   __connman_notifier_enable(type);
-
if (g_atomic_int_exchange_and_add(technology-enabled, 1) == 0) {
+   __connman_notifier_enable(type);
technology-state = CONNMAN_TECHNOLOGY_STATE_ENABLED;
state_changed(technology);
}
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 12/24] technology/device: remove blocked variables and associated functions.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Rely on global offline status instead of caching them in technology and
device structs.
---
 src/connman.h|5 --
 src/device.c |   65 ++
 src/profile.c|9 
 src/technology.c |  135 -
 4 files changed, 55 insertions(+), 159 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 5e4db20..17768e7 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -333,8 +333,6 @@ void __connman_technology_add_interface(enum 
connman_service_type type,
 void __connman_technology_remove_interface(enum connman_service_type type,
int index, const char *name, const char *ident);
 
-connman_bool_t __connman_technology_get_blocked(enum connman_service_type 
type);
-
 #include connman/device.h
 
 int __connman_device_init(const char *device, const char *nodevice);
@@ -351,9 +349,6 @@ connman_bool_t __connman_device_isfiltered(const char 
*devname);
 int __connman_device_get_phyindex(struct connman_device *device);
 void __connman_device_set_phyindex(struct connman_device *device,
int phyindex);
-int __connman_device_set_blocked(struct connman_device *device,
-   connman_bool_t blocked);
-connman_bool_t __connman_device_get_blocked(struct connman_device *device);
 
 void __connman_device_increase_connections(struct connman_device *device);
 void __connman_device_decrease_connections(struct connman_device *device);
diff --git a/src/device.c b/src/device.c
index 1f6ec5a..92341d4 100644
--- a/src/device.c
+++ b/src/device.c
@@ -44,7 +44,6 @@ struct connman_device {
enum connman_pending_type powered_pending;  /* Indicates a pending
enable/disable request 
*/
connman_bool_t offlinemode;
-   connman_bool_t blocked;
connman_bool_t powered;
connman_bool_t powered_persistent;
connman_bool_t scanning;
@@ -237,14 +236,11 @@ int __connman_device_enable(struct connman_device *device)
 {
int err;
 
-   DBG(device %p %d, device, device-blocked);
+   DBG(device %p, device);
 
if (!device-driver || !device-driver-enable)
return -EOPNOTSUPP;
 
-   if (device-blocked == TRUE)
-   return -ENOLINK;
-
/* There is an ongoing power disable request. */
if (device-powered_pending == PENDING_DISABLE)
return -EBUSY;
@@ -293,9 +289,6 @@ int __connman_device_disable(struct connman_device *device)
if (!device-driver || !device-driver-disable)
return -EOPNOTSUPP;
 
-   if (device-blocked == TRUE)
-   return -ENOLINK;
-
/* Ongoing power enable request */
if (device-powered_pending == PENDING_ENABLE)
return -EBUSY;
@@ -328,29 +321,6 @@ done:
return err;
 }
 
-static int set_powered(struct connman_device *device, connman_bool_t powered)
-{
-   DBG(device %p powered %d, device, powered);
-
-   if (powered == TRUE)
-   return __connman_device_enable(device);
-   else
-   return __connman_device_disable(device);
-}
-
-static int setup_device(struct connman_device *device)
-{
-   DBG(device %p, device);
-
-   __connman_technology_add_device(device);
-
-   if (device-offlinemode == FALSE 
-   device-powered_persistent == TRUE)
-   __connman_device_enable(device);
-
-   return 0;
-}
-
 static void probe_driver(struct connman_device_driver *driver)
 {
GSList *list;
@@ -371,7 +341,7 @@ static void probe_driver(struct connman_device_driver 
*driver)
 
device-driver = driver;
 
-   setup_device(device);
+   __connman_technology_add_device(device);
}
 }
 
@@ -524,7 +494,7 @@ struct connman_device *connman_device_create(const char 
*node,
device-phyindex = -1;
 
service_type = __connman_device_get_service_type(device);
-   device-blocked = __connman_technology_get_blocked(service_type);
+
device-backoff_interval = SCAN_INITIAL_DELAY;
 
switch (type) {
@@ -733,33 +703,6 @@ int connman_device_set_powered(struct connman_device 
*device,
return 0;
 }
 
-int __connman_device_set_blocked(struct connman_device *device,
-   connman_bool_t blocked)
-{
-   connman_bool_t powered;
-
-   DBG(device %p blocked %d, device, blocked);
-
-   device-blocked = blocked;
-
-   if (device-offlinemode == TRUE)
-   return 0;
-
-   connman_info(%s {rfkill} blocked %d, device-interface, blocked);
-
-   if (blocked == FALSE)
-   powered = device-powered_persistent;
-   else
-   powered = FALSE;
-
-   return set_powered(device, powered);
-}
-
-connman_bool_t 

[PATCH v2 13/24] device: remove caching of offlinemode in device structure.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

---
 src/device.c |6 --
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/src/device.c b/src/device.c
index 92341d4..12ebfa8 100644
--- a/src/device.c
+++ b/src/device.c
@@ -43,7 +43,6 @@ struct connman_device {
enum connman_device_type type;
enum connman_pending_type powered_pending;  /* Indicates a pending
enable/disable request 
*/
-   connman_bool_t offlinemode;
connman_bool_t powered;
connman_bool_t powered_persistent;
connman_bool_t scanning;
@@ -675,9 +674,6 @@ int connman_device_set_powered(struct connman_device 
*device,
device-pending_timeout = 0;
device-powered_pending = PENDING_NONE;
 
-   if (device-offlinemode == TRUE  powered == TRUE)
-   return __connman_device_disable(device);
-
device-powered = powered;
 
type = __connman_device_get_service_type(device);
@@ -1143,8 +1139,6 @@ int connman_device_register(struct connman_device *device)
 {
__connman_storage_load_device(device);
 
-   device-offlinemode = __connman_profile_get_offlinemode();
-
return device_probe(device);
 }
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v2 15/24] technology: Save/Load offlinemode.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Load/Save offlinemode in technology.c instead of profile.c.
---
 src/connman.h|1 +
 src/manager.c|   13 +
 src/technology.c |   78 +++--
 3 files changed, 65 insertions(+), 27 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index ccb00a8..6825442 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -314,6 +314,7 @@ int __connman_technology_enable(enum connman_service_type 
type, DBusMessage *msg
 int __connman_technology_disabled(enum connman_service_type type);
 int __connman_technology_disable(enum connman_service_type type, DBusMessage 
*msg);
 int __connman_technology_set_offlinemode(connman_bool_t offlinemode);
+connman_bool_t __connman_technology_get_offlinemode(void);
 
 int __connman_technology_add_rfkill(unsigned int index,
enum connman_service_type type,
diff --git a/src/manager.c b/src/manager.c
index f39c2be..51d5ffa 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -50,11 +50,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
 
connman_dbus_dict_open(array, dict);
 
-   str = __connman_profile_active_path();
-   if (str != NULL)
-   connman_dbus_dict_append_basic(dict, ActiveProfile,
-   DBUS_TYPE_OBJECT_PATH, str);
-
connman_dbus_dict_append_array(dict, Services,
DBUS_TYPE_OBJECT_PATH, __connman_service_list, NULL);
connman_dbus_dict_append_array(dict, Technologies,
@@ -64,7 +59,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
connman_dbus_dict_append_basic(dict, State,
DBUS_TYPE_STRING, str);
 
-   offlinemode = __connman_profile_get_offlinemode();
+   offlinemode = __connman_technology_get_offlinemode();
connman_dbus_dict_append_basic(dict, OfflineMode,
DBUS_TYPE_BOOLEAN, offlinemode);
 
@@ -122,12 +117,6 @@ static DBusMessage *set_property(DBusConnection *conn,
dbus_message_iter_get_basic(value, offlinemode);
 
__connman_technology_set_offlinemode(offlinemode);
-   } else if (g_str_equal(name, ActiveProfile) == TRUE) {
-   const char *str;
-
-   dbus_message_iter_get_basic(value, str);
-
-   return __connman_error_not_supported(msg);
} else if (g_str_equal(name, SessionMode) == TRUE) {
connman_bool_t sessionmode;
 
diff --git a/src/technology.c b/src/technology.c
index e71bed5..4e81066 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -34,6 +34,8 @@ static DBusConnection *connection;
 
 static GSList *technology_list = NULL;
 
+static connman_bool_t global_offlinemode;
+
 struct connman_rfkill {
unsigned int index;
enum connman_service_type type;
@@ -300,6 +302,49 @@ static const char *get_name(enum connman_service_type type)
return NULL;
 }
 
+connman_bool_t __connman_technology_get_offlinemode(void)
+{
+   return global_offlinemode;
+}
+
+static int connman_technology_save_offlinemode()
+{
+   GKeyFile *keyfile;
+
+   keyfile = __connman_storage_open_profile(default);
+   if (keyfile == NULL)
+   return -EIO;
+
+   g_key_file_set_boolean(keyfile, global,
+   OfflineMode, global_offlinemode);
+
+   __connman_storage_close_profile(default, keyfile, TRUE);
+
+   return 0;
+}
+
+static connman_bool_t connman_technology_load_offlinemode()
+{
+   GKeyFile *keyfile;
+   GError *error = NULL;
+   connman_bool_t offlinemode;
+
+   /* If there is a error, we enable offlinemode */
+   keyfile = __connman_storage_open_profile(default);
+   if (keyfile == NULL)
+   return TRUE;
+
+   offlinemode = g_key_file_get_boolean(keyfile, global,
+   OfflineMode, error);
+   if (error != NULL) {
+   offlinemode = TRUE;
+   g_clear_error(error);
+   }
+   __connman_storage_close_profile(default, keyfile, FALSE);
+
+   return offlinemode;
+}
+
 static DBusMessage *get_properties(DBusConnection *conn,
DBusMessage *message, void *user_data)
 {
@@ -617,7 +662,6 @@ int __connman_technology_add_device(struct connman_device 
*device)
 {
struct connman_technology *technology;
enum connman_service_type type;
-   connman_bool_t offlinemode = __connman_profile_get_offlinemode();
 
DBG(device %p, device);
 
@@ -628,7 +672,7 @@ int __connman_technology_add_device(struct connman_device 
*device)
if (technology == NULL)
return -ENXIO;
 
-   if (technology-enable_persistent  !offlinemode)
+   if (technology-enable_persistent  !global_offlinemode)
__connman_device_enable(device);
/* 

[PATCH v2 16/24] service: Add services changed signal.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Move the services changed dbus signal handling from profile.
---
 src/notifier.c |2 --
 src/profile.c  |   39 ---
 src/service.c  |   51 ---
 3 files changed, 44 insertions(+), 48 deletions(-)

diff --git a/src/notifier.c b/src/notifier.c
index aa6611b..722f997 100644
--- a/src/notifier.c
+++ b/src/notifier.c
@@ -464,8 +464,6 @@ void __connman_notifier_offlinemode(connman_bool_t enabled)
 
DBG(enabled %d, enabled);
 
-   __connman_profile_changed(FALSE);
-
offlinemode_changed(enabled);
 
for (list = notifier_list; list; list = list-next) {
diff --git a/src/profile.c b/src/profile.c
index aaf0ad0..b0cb3ef 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -95,45 +95,6 @@ const char *__connman_profile_active_path(void)
return default_profile-path;
 }
 
-static guint changed_timeout = 0;
-
-static gboolean services_changed(gpointer user_data)
-{
-   changed_timeout = 0;
-
-   if (default_profile == NULL)
-   return FALSE;
-
-   connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
-   CONNMAN_MANAGER_INTERFACE, Services,
-   DBUS_TYPE_OBJECT_PATH, __connman_service_list,
-   NULL);
-
-   return FALSE;
-}
-
-void __connman_profile_changed(gboolean delayed)
-{
-   DBG();
-
-   if (changed_timeout  0) {
-   g_source_remove(changed_timeout);
-   changed_timeout = 0;
-   }
-
-   if (__connman_connection_update_gateway() == TRUE) {
-   services_changed(NULL);
-   return;
-   }
-
-   if (delayed == FALSE) {
-   services_changed(NULL);
-   return;
-   }
-
-   changed_timeout = g_timeout_add_seconds(1, services_changed, NULL);
-}
-
 static void free_profile(struct connman_profile *profile)
 {
g_free(profile-name);
diff --git a/src/service.c b/src/service.c
index fc90934..6b7d163 100644
--- a/src/service.c
+++ b/src/service.c
@@ -298,6 +298,43 @@ static enum connman_service_proxy_method 
string2proxymethod(const char *method)
return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
 }
 
+static guint changed_timeout = 0;
+
+static gboolean notify_services_changed(gpointer user_data)
+{
+   changed_timeout = 0;
+
+   connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
+   CONNMAN_MANAGER_INTERFACE, Services,
+   DBUS_TYPE_OBJECT_PATH, __connman_service_list,
+   NULL);
+
+   return FALSE;
+}
+
+static void services_changed(gboolean delayed)
+{
+   DBG();
+
+   if (changed_timeout  0) {
+   g_source_remove(changed_timeout);
+   changed_timeout = 0;
+   }
+
+   if (__connman_connection_update_gateway() == TRUE) {
+   notify_services_changed(NULL);
+   return;
+   }
+
+   if (delayed == FALSE) {
+   notify_services_changed(NULL);
+   return;
+   }
+
+   changed_timeout = g_timeout_add_seconds(1, notify_services_changed,
+NULL);
+}
+
 static enum connman_service_state combine_state(
enum connman_service_state state_a,
enum connman_service_state state_b)
@@ -2947,7 +2984,7 @@ static DBusMessage *move_service(DBusConnection *conn,
 
before ? g_sequence_move(src, dst) : g_sequence_move(dst, src);
 
-   __connman_profile_changed(FALSE);
+   services_changed(FALSE);
 
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
@@ -3012,7 +3049,7 @@ static void service_free(gpointer user_data)
service-path = NULL;
 
if (path != NULL) {
-   __connman_profile_changed(FALSE);
+   services_changed(FALSE);
 
g_dbus_unregister_interface(connection, path,
CONNMAN_SERVICE_INTERFACE);
@@ -3422,7 +3459,7 @@ int __connman_service_set_favorite(struct connman_service 
*service,
 
g_sequence_sort_changed(iter, service_compare, NULL);
 
-   __connman_profile_changed(FALSE);
+   services_changed(FALSE);
 
return 0;
 }
@@ -3485,7 +3522,7 @@ static void report_error_cb(struct connman_service 
*service,
__connman_service_connect(service);
else {
service_complete(service);
-   __connman_profile_changed(FALSE);
+   services_changed(FALSE);
__connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
}
 }
@@ -3627,7 +3664,7 @@ static int __connman_service_indicate_state(struct 
connman_service *service)
if (iter != NULL)
g_sequence_sort_changed(iter, 

[PATCH v2 20/24] service: Directly use service load/save functions.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

---
 src/service.c |  823 +++--
 1 files changed, 395 insertions(+), 428 deletions(-)

diff --git a/src/service.c b/src/service.c
index ba0a2d9..0a890d9 100644
--- a/src/service.c
+++ b/src/service.c
@@ -297,6 +297,384 @@ static enum connman_service_proxy_method 
string2proxymethod(const char *method)
return CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN;
 }
 
+static int service_load(struct connman_service *service)
+{
+   const char *ident = default;
+   GKeyFile *keyfile;
+   GError *error = NULL;
+   gchar *pathname, *data = NULL;
+   gsize length;
+   gchar *str;
+   connman_bool_t autoconnect;
+   unsigned int ssid_len;
+   int err = 0;
+
+   DBG(service %p, service);
+
+   if (ident == NULL)
+   return -EINVAL;
+
+   pathname = g_strdup_printf(%s/%s.profile, STORAGEDIR, ident);
+   if (pathname == NULL)
+   return -ENOMEM;
+
+   keyfile = g_key_file_new();
+
+   if (g_file_get_contents(pathname, data, length, NULL) == FALSE) {
+   g_free(pathname);
+   return -ENOENT;
+   }
+
+   g_free(pathname);
+
+   if (g_key_file_load_from_data(keyfile, data, length,
+   0, NULL) == FALSE) {
+   g_free(data);
+   return -EILSEQ;
+   }
+
+   g_free(data);
+
+   switch (service-type) {
+   case CONNMAN_SERVICE_TYPE_UNKNOWN:
+   case CONNMAN_SERVICE_TYPE_SYSTEM:
+   case CONNMAN_SERVICE_TYPE_ETHERNET:
+   case CONNMAN_SERVICE_TYPE_GPS:
+   case CONNMAN_SERVICE_TYPE_VPN:
+   case CONNMAN_SERVICE_TYPE_GADGET:
+   break;
+   case CONNMAN_SERVICE_TYPE_WIFI:
+   if (service-name == NULL) {
+   gchar *name;
+
+   name = g_key_file_get_string(keyfile,
+   service-identifier, Name, NULL);
+   if (name != NULL) {
+   g_free(service-name);
+   service-name = name;
+   }
+
+   if (service-network != NULL)
+   connman_network_set_name(service-network,
+   name);
+   }
+
+   if (service-network 
+   connman_network_get_blob(service-network,
+   WiFi.SSID, ssid_len) == NULL) {
+   gchar *hex_ssid;
+
+   hex_ssid = g_key_file_get_string(keyfile,
+   service-identifier,
+   SSID, NULL);
+
+   if (hex_ssid != NULL) {
+   gchar *ssid;
+   unsigned int i, j = 0, hex;
+   size_t hex_ssid_len = strlen(hex_ssid);
+
+   ssid = g_try_malloc0(hex_ssid_len / 2);
+   if (ssid == NULL) {
+   g_free(hex_ssid);
+   err = -ENOMEM;
+   goto done;
+   }
+
+   for (i = 0; i  hex_ssid_len; i += 2) {
+   sscanf(hex_ssid + i, %02x, hex);
+   ssid[j++] = hex;
+   }
+
+   connman_network_set_blob(service-network,
+   WiFi.SSID, ssid, hex_ssid_len / 2);
+   }
+
+   g_free(hex_ssid);
+   }
+   /* fall through */
+
+   case CONNMAN_SERVICE_TYPE_WIMAX:
+   case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+   case CONNMAN_SERVICE_TYPE_CELLULAR:
+   service-favorite = g_key_file_get_boolean(keyfile,
+   service-identifier, Favorite, NULL);
+
+   autoconnect = g_key_file_get_boolean(keyfile,
+   service-identifier, AutoConnect, error);
+   if (error == NULL)
+   service-autoconnect = autoconnect;
+   g_clear_error(error);
+
+   str = g_key_file_get_string(keyfile,
+   service-identifier, Failure, NULL);
+   if (str != NULL) {
+   if (service-favorite == FALSE)
+   service-state_ipv4 = service-state_ipv6 =
+   CONNMAN_SERVICE_STATE_FAILURE;
+   service-error = string2error(str);
+   }
+   break;
+   }
+
+   str = 

[PATCH fast connect 0/9] Fast connect resend

2011-08-24 Thread Jukka Rissanen
Hi,

here is the fast connect patches sent again. The patches
consists of Mohamed's original patches + some fixes to
make the fast connect work properly.
The patches also require supplicant changes (patch sent to
supplicant mailing list 23 Aug).

Jukka


Jukka Rissanen (4):
  gsupplicant: Fix the ssid array.
  wifi: Removed extra scan request call.
  device: Make debug print more useful.
  wifi: Fallback to normal scan if fast scan is not supported.

Mohamed Abbas (5):
  Add frequency support to service.
  Add support to multi scan type.
  Add support to append char ** entries to dbus dict.
  Get the number of scan ssids from supplicant.
  Add ssids and frequencies to wpa_supplicant scan for fast scan.

 gsupplicant/dbus.c|   29 ++
 gsupplicant/dbus.h|   20 
 gsupplicant/gsupplicant.h |   19 
 gsupplicant/supplicant.c  |  162 +--
 include/device.h  |1 +
 plugins/wifi.c|  240 -
 src/device.c  |6 +-
 src/service.c |5 +
 8 files changed, 469 insertions(+), 13 deletions(-)

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH fast connect 1/9] service: Add frequency support to service.

2011-08-24 Thread Jukka Rissanen
From: Mohamed Abbas mohamed.ab...@intel.com

Get the frequncy of gsupplicant network on connman network
creation, and always save the frequency of the wifi service.
---
 gsupplicant/gsupplicant.h |1 +
 gsupplicant/supplicant.c  |   10 ++
 plugins/wifi.c|3 +++
 src/service.c |5 +
 4 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 5c453aa..a634141 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -196,6 +196,7 @@ const void 
*g_supplicant_network_get_ssid(GSupplicantNetwork *network,
 const char *g_supplicant_network_get_mode(GSupplicantNetwork *network);
 const char *g_supplicant_network_get_security(GSupplicantNetwork *network);
 dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network);
+dbus_int16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network);
 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network);
 
 struct _GSupplicantCallbacks {
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index e5743f0..ba9f207 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -178,6 +178,7 @@ struct _GSupplicantNetwork {
unsigned char ssid[32];
unsigned int ssid_len;
dbus_int16_t signal;
+   dbus_uint16_t frequency;
GSupplicantMode mode;
GSupplicantSecurity security;
dbus_bool_t wps;
@@ -782,6 +783,14 @@ dbus_int16_t 
g_supplicant_network_get_signal(GSupplicantNetwork *network)
return network-signal;
 }
 
+dbus_int16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
+{
+   if (network == NULL)
+   return 0;
+
+   return network-frequency;
+}
+
 dbus_bool_t g_supplicant_network_get_wps(GSupplicantNetwork *network)
 {
if (network == NULL)
@@ -1006,6 +1015,7 @@ static void add_bss_to_network(struct g_supplicant_bss 
*bss)
network-ssid_len = bss-ssid_len;
memcpy(network-ssid, bss-ssid, bss-ssid_len);
network-signal = bss-signal;
+   network-frequency = bss-frequency;
 
network-wps = FALSE;
if ((bss-keymgmt  G_SUPPLICANT_KEYMGMT_WPS) != 0)
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 469ec67..9ec6581 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -850,6 +850,9 @@ static void network_added(GSupplicantNetwork 
*supplicant_network)
calculate_strength(supplicant_network));
connman_network_set_bool(network, WiFi.WPS, wps);
 
+   connman_network_set_frequency(network,
+   g_supplicant_network_get_frequency(supplicant_network));
+
connman_network_set_available(network, TRUE);
 
if (ssid != NULL)
diff --git a/src/service.c b/src/service.c
index fc90934..f1f768a 100644
--- a/src/service.c
+++ b/src/service.c
@@ -5293,6 +5293,7 @@ static int service_save(struct connman_service *service)
gchar *pathname, *data = NULL;
gsize length;
gchar *str;
+   gint freq;
const char *cst_str = NULL;
int err = 0;
 
@@ -5359,6 +5360,10 @@ update:
 
g_string_free(str, TRUE);
}
+
+   freq = connman_network_get_frequency(service-network);
+   g_key_file_set_integer(keyfile, service-identifier,
+   Frequency, freq);
}
/* fall through */
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH fast connect 4/9] gsupplicant: Get the number of scan ssids from supplicant.

2011-08-24 Thread Jukka Rissanen
From: Mohamed Abbas mohamed.ab...@intel.com

---
 gsupplicant/gsupplicant.h |2 ++
 gsupplicant/supplicant.c  |   18 +-
 2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index a634141..5f7adc0 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -181,6 +181,8 @@ const void 
*g_supplicant_interface_get_wps_ssid(GSupplicantInterface *interface,
unsigned int *ssid_len);
 GSupplicantWpsState g_supplicant_interface_get_wps_state(GSupplicantInterface 
*interface);
 unsigned int g_supplicant_interface_get_mode(GSupplicantInterface *interface);
+unsigned int g_supplicant_interface_get_max_scan_ssids(
+   GSupplicantInterface *interface);
 
 /* Network API */
 struct _GSupplicantNetwork;
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index ba9f207..828d6f3 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -153,6 +153,7 @@ struct _GSupplicantInterface {
unsigned int pairwise_capa;
unsigned int scan_capa;
unsigned int mode_capa;
+   unsigned int max_scan_ssids;
dbus_bool_t ready;
GSupplicantState state;
dbus_bool_t scanning;
@@ -611,7 +612,13 @@ static void interface_capability(const char *key, 
DBusMessageIter *iter,
else if (g_strcmp0(key, Modes) == 0)
supplicant_dbus_array_foreach(iter,
interface_capability_mode, interface);
-   else
+   else if (g_strcmp0(key, MaxScanSSID) == 0) {
+   dbus_int32_t max_scan_ssid;
+
+   dbus_message_iter_get_basic(iter, max_scan_ssid);
+   interface-max_scan_ssids = max_scan_ssid;
+
+   } else
SUPPLICANT_DBG(key %s type %c,
key, dbus_message_iter_get_arg_type(iter));
 }
@@ -714,6 +721,15 @@ unsigned int 
g_supplicant_interface_get_mode(GSupplicantInterface *interface)
return interface-mode_capa;
 }
 
+unsigned int g_supplicant_interface_get_max_scan_ssids(
+   GSupplicantInterface *interface)
+{
+   if (interface == NULL)
+   return 0;
+
+   return interface-max_scan_ssids;
+}
+
 GSupplicantInterface *g_supplicant_network_get_interface(
GSupplicantNetwork *network)
 {
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH fast connect 6/9] gsupplicant: Fix the ssid array.

2011-08-24 Thread Jukka Rissanen
---
 gsupplicant/gsupplicant.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 059837f..93e1c8e 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -135,7 +135,7 @@ typedef struct _GSupplicantSSID GSupplicantSSID;
 
 struct _GSupplicantScanParams {
struct scan_ssid {
-   unsigned char *ssid[32];
+   unsigned char ssid[32];
uint8_t ssid_len;
} ssids[G_SUPPLICANT_MAX_FAST_SCAN];
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH fast connect 5/9] wifi: Add SSIDs and frequencies to wpa_supplicant scan for fast scan.

2011-08-24 Thread Jukka Rissanen
From: Mohamed Abbas mohamed.ab...@intel.com

---
 gsupplicant/gsupplicant.h |   16 
 gsupplicant/supplicant.c  |  134 ++--
 plugins/wifi.c|  217 -
 3 files changed, 357 insertions(+), 10 deletions(-)

diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 5f7adc0..059837f 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -73,6 +73,8 @@ extern C {
 #define G_SUPPLICANT_PAIRWISE_TKIP (1  1)
 #define G_SUPPLICANT_PAIRWISE_CCMP (1  2)
 
+#define G_SUPPLICANT_MAX_FAST_SCAN 4
+
 typedef enum {
G_SUPPLICANT_MODE_UNKNOWN,
G_SUPPLICANT_MODE_INFRA,
@@ -131,6 +133,19 @@ struct _GSupplicantSSID {
 
 typedef struct _GSupplicantSSID GSupplicantSSID;
 
+struct _GSupplicantScanParams {
+   struct scan_ssid {
+   unsigned char *ssid[32];
+   uint8_t ssid_len;
+   } ssids[G_SUPPLICANT_MAX_FAST_SCAN];
+
+   uint8_t num_ssids;
+
+   uint16_t freqs[G_SUPPLICANT_MAX_FAST_SCAN];
+};
+
+typedef struct _GSupplicantScanParams GSupplicantScanParams;
+
 /* global API */
 typedef void (*GSupplicantCountryCallback) (void *user_data);
 
@@ -155,6 +170,7 @@ int g_supplicant_interface_remove(GSupplicantInterface 
*interface,
GSupplicantInterfaceCallback callback,
void *user_data);
 int g_supplicant_interface_scan(GSupplicantInterface *interface,
+   GSupplicantScanParams *scan_data,
GSupplicantInterfaceCallback callback,
void *user_data);
 
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 828d6f3..d2e6aff 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -2113,6 +2113,13 @@ struct interface_connect_data {
void *user_data;
 };
 
+struct interface_scan_data {
+   GSupplicantInterface *interface;
+   GSupplicantInterfaceCallback callback;
+   GSupplicantScanParams *scan_params;
+   void *user_data;
+};
+
 static void interface_create_property(const char *key, DBusMessageIter *iter,
void *user_data)
 {
@@ -2368,9 +2375,11 @@ int g_supplicant_interface_remove(GSupplicantInterface 
*interface,
 static void interface_scan_result(const char *error,
DBusMessageIter *iter, void *user_data)
 {
-   struct interface_data *data = user_data;
+   struct interface_scan_data *data = user_data;
 
if (error != NULL) {
+   SUPPLICANT_DBG(error %s, error);
+
if (data-callback != NULL)
data-callback(-EIO, data-interface, data-user_data);
} else {
@@ -2378,27 +2387,134 @@ static void interface_scan_result(const char *error,
data-interface-scan_data = data-user_data;
}
 
+   if (data != NULL  data-scan_params != NULL)
+   g_free(data-scan_params);
+
dbus_free(data);
 }
 
+static void add_scan_frequency(DBusMessageIter *iter, unsigned int freq)
+{
+   DBusMessageIter data;
+   unsigned int width;
+
+   dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, data);
+
+   dbus_message_iter_append_basic(data, DBUS_TYPE_UINT32, freq);
+   dbus_message_iter_append_basic(data, DBUS_TYPE_UINT32, width);
+
+   dbus_message_iter_close_container(iter, data);
+}
+
+static void add_scan_frequencies(DBusMessageIter *iter,
+   void *user_data)
+{
+   GSupplicantScanParams *scan_data = user_data;
+   unsigned int freq;
+   int i;
+
+   for (i = 0; i  G_SUPPLICANT_MAX_FAST_SCAN; i++) {
+   freq = scan_data-freqs[i];
+   if (!freq)
+   break;
+
+   add_scan_frequency(iter, freq);
+   }
+}
+
+static void append_ssid(DBusMessageIter *iter,
+   const void *ssid, unsigned int len)
+{
+   DBusMessageIter array;
+
+   dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+   DBUS_TYPE_BYTE_AS_STRING, array);
+
+   dbus_message_iter_append_fixed_array(array, DBUS_TYPE_BYTE,
+   ssid, len);
+   dbus_message_iter_close_container(iter, array);
+}
+
+static void append_ssids(DBusMessageIter *iter, void *user_data)
+{
+   GSupplicantScanParams *scan_data = user_data;
+   int i;
+
+   for (i = 0; i  scan_data-num_ssids; i++)
+   append_ssid(iter, scan_data-ssids[i].ssid,
+   scan_data-ssids[i].ssid_len);
+}
+
+static void supplicant_add_scan_frequency(DBusMessageIter *dict,
+   const char *key, supplicant_dbus_array_function function,
+   void 

[PATCH fast connect 8/9] device: Make debug print more useful.

2011-08-24 Thread Jukka Rissanen
---
 src/device.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/device.c b/src/device.c
index 6b8e873..6e84bc4 100644
--- a/src/device.c
+++ b/src/device.c
@@ -106,7 +106,7 @@ static void reset_scan_trigger(struct connman_device 
*device)
} else
interval = device-scan_interval;
 
-   DBG(interval %d, interval);
+   DBG(interface %s interval %d, device-interface, interval);
 
device-scan_timeout = g_timeout_add_seconds(interval,
device_scan_trigger, device);
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH fast connect 7/9] wifi: Removed extra scan request call.

2011-08-24 Thread Jukka Rissanen
The wifi_scan_fast() is already called in connman_device_set_powered()
so no need to call it again immediately.
---
 plugins/wifi.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index b9e30db..c0607f5 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -801,8 +801,6 @@ static void interface_added(GSupplicantInterface *interface)
 
if (wifi-tethering == TRUE)
return;
-
-   wifi_scan_fast(wifi-device);
 }
 
 static connman_bool_t is_idle(struct wifi_data *wifi)
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH fast connect 9/9] wifi: Fallback to normal scan if fast scan is not supported.

2011-08-24 Thread Jukka Rissanen
---
 plugins/wifi.c |9 ++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index c0607f5..410095d 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -506,13 +506,16 @@ static int wifi_scan_fast(struct connman_device *device)
if (wifi-tethering == TRUE)
return 0;
 
+   driver_max = g_supplicant_interface_get_max_scan_ssids(
+   wifi-interface);
+   DBG(max ssids %d, driver_max);
+   if (driver_max == 0)
+   return wifi_scan(device);
+
scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
if (scan_params == NULL)
return -ENOMEM;
 
-   driver_max = g_supplicant_interface_get_max_scan_ssids(
-   wifi-interface);
-   DBG(max ssids %d, driver_max);
get_latest_connections(wifi_, driver_max, scan_params);
 
ret = g_supplicant_interface_scan(wifi-interface, scan_params,
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v1 0/3] New storage structure.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

Hi Marcel/Samuel, 

According to our discussion on IRC here is the patch set (version 1)
for the storage changes. I have moved the global settings, which include
offlinemode and technology states to STORAGEDIR/settings. I am migrating these
from the older default.profile file for smoother migration.
Service data, which include the settings of the service and stats, are saved in
STORAGEDIR/service_id/ dir. The provisioning config files still reside in
STORAGEDIR. We also dont save all the available services, just the ones we
connect to. stats/ has folded in the respective service_id dir.

Cheers,
Alok.


Alok Barsode (3):
  storage: switch to settings file.
  storage: switch to service_id directories.
  stats: Move stat files to respective service identifier directory.

 src/config.c |   19 +---
 src/connman.h|   25 ++---
 src/main.c   |7 +-
 src/service.c|   69 ++--
 src/stats.c  |   29 +-
 src/storage.c|  310 +++---
 src/technology.c |   50 +
 7 files changed, 331 insertions(+), 178 deletions(-)

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH v1 1/3] storage: switch to settings file.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

All the global settings would reside in /var/lib/connman/settings.
We also migrate global keys from /var/lib/connman/default.profile
to /var/lib/connman/settings for a smooth transition.
---
 src/config.c |   19 +
 src/connman.h|   21 ++---
 src/main.c   |1 +
 src/service.c|5 +-
 src/storage.c|  239 +++---
 src/technology.c |   50 +++-
 6 files changed, 220 insertions(+), 115 deletions(-)

diff --git a/src/config.c b/src/config.c
index 90a2180..db15228 100644
--- a/src/config.c
+++ b/src/config.c
@@ -383,7 +383,7 @@ static int load_config(struct connman_config *config)
 
DBG(config %p, config);
 
-   keyfile = __connman_storage_open_config(config-ident);
+   keyfile = __connman_storage_load_config(config-ident);
if (keyfile == NULL)
return -EIO;
 
@@ -418,7 +418,7 @@ static int load_config(struct connman_config *config)
 
g_strfreev(groups);
 
-   __connman_storage_close_config(config-ident, keyfile, FALSE);
+   g_key_file_free(keyfile);
 
return 0;
 }
@@ -453,7 +453,7 @@ int __connman_config_load_service(GKeyFile *keyfile, const 
char *group,
 {
struct connman_config *config;
const char *service_name;
-   char *ident, *filename = NULL, *content = NULL;
+   char *ident, *content = NULL;
gsize content_length;
int err;
 
@@ -491,26 +491,15 @@ int __connman_config_load_service(GKeyFile *keyfile, 
const char *group,
goto out;
}
 
-   filename = g_strdup_printf(%s/%s.config, STORAGEDIR, ident);
-   if (filename == NULL) {
-   err = -ENOMEM;
-   goto out;
-   }
-
DBG(Saving %zu bytes to %s, content_length, service_name);
 
-   if (g_file_set_contents(filename, content,
-   content_length, NULL) == FALSE) {
-   err = -EIO;
-   goto out;
-   }
+   __connman_storage_save_config(keyfile, ident);
 
return 0;
 
 out:
g_free(ident);
g_free(content);
-   g_free(filename);
 
return err;
 }
diff --git a/src/connman.h b/src/connman.h
index 3f33045..92124cd 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -142,19 +142,14 @@ void __connman_resolver_cleanup(void);
 int __connman_resolvfile_append(const char *interface, const char *domain, 
const char *server);
 int __connman_resolvfile_remove(const char *interface, const char *domain, 
const char *server);
 
-GKeyFile *__connman_storage_open(const char *ident, const char *suffix);
-void __connman_storage_close(const char *ident, const char *suffix,
-   GKeyFile *keyfile, gboolean save);
-void __connman_storage_delete(const char *ident, const char *suffix);
-
-GKeyFile *__connman_storage_open_profile(const char *ident);
-void __connman_storage_close_profile(const char *ident,
-   GKeyFile *keyfile, gboolean save);
-void __connman_storage_delete_profile(const char *ident);
-
-GKeyFile *__connman_storage_open_config(const char *ident);
-void __connman_storage_close_config(const char *ident,
-   GKeyFile *keyfile, gboolean save);
+void __connman_storage_migrate(void);
+GKeyFile *__connman_storage_open_global();
+GKeyFile *__connman_storage_load_global();
+void __connman_storage_save_global(GKeyFile *keyfile);
+void __connman_storage_delete_global();
+
+GKeyFile *__connman_storage_load_config(const char *ident);
+void __connman_storage_save_config(GKeyFile *keyfile, const char *ident);
 void __connman_storage_delete_config(const char *ident);
 
 int __connman_detect_init(void);
diff --git a/src/main.c b/src/main.c
index 959a43f..dd67cb9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -334,6 +334,7 @@ int main(int argc, char *argv[])
 
parse_config(config);
 
+   __connman_storage_migrate();
__connman_technology_init();
__connman_notifier_init();
__connman_location_init();
diff --git a/src/service.c b/src/service.c
index 0a890d9..d328a29 100644
--- a/src/service.c
+++ b/src/service.c
@@ -5041,7 +5041,7 @@ void __connman_service_read_ip4config(struct 
connman_service *service)
if (service-ipconfig_ipv4 == NULL)
return;
 
-   keyfile = __connman_storage_open_profile(default);
+   keyfile = __connman_storage_load_global();
if (keyfile == NULL)
return;
 
@@ -5070,7 +5070,7 @@ void __connman_service_read_ip6config(struct 
connman_service *service)
if (service-ipconfig_ipv6 == NULL)
return;
 
-   keyfile = __connman_storage_open_profile(default);
+   keyfile = __connman_storage_load_global();
if (keyfile == NULL)
return;
 
@@ -5089,6 +5089,7 @@ void __connman_service_create_ip6config(struct 
connman_service *service,

[PATCH v1 3/3] stats: Move stat files to respective service identifier directory.

2011-08-24 Thread Alok Barsode
From: Alok Barsode alok.bars...@linux.intel.com

---
 src/main.c  |6 --
 src/stats.c |   29 +
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/main.c b/src/main.c
index dd67cb9..283b10a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -293,12 +293,6 @@ int main(int argc, char *argv[])
perror(Failed to create storage directory);
}
 
-   if (mkdir(STORAGEDIR /stats, S_IRUSR | S_IWUSR | S_IXUSR |
-   S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)  0) {
-   if (errno != EEXIST)
-   perror(Failed to create statistics directory);
-   }
-
umask(0077);
 
main_loop = g_main_loop_new(NULL, FALSE);
diff --git a/src/stats.c b/src/stats.c
index 743b795..df28eb4 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -33,9 +33,13 @@
 #include unistd.h
 #include string.h
 #include limits.h
+#include sys/stat.h
 
 #include connman.h
 
+#define MODE   (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
+   S_IXGRP | S_IROTH | S_IXOTH)
+
 #ifdef TEMP_FAILURE_RETRY
 #define TFR TEMP_FAILURE_RETRY
 #else
@@ -345,7 +349,7 @@ static int stats_open(struct stats_file *file,
 
 static int stats_open_temp(struct stats_file *file)
 {
-   file-name = g_strdup_printf(%s/stats/stats.XX.tmp,
+   file-name = g_strdup_printf(%s/stats.XX.tmp,
STORAGEDIR);
file-fd = g_mkstemp_full(file-name, O_RDWR | O_CREAT, 0644);
if (file-fd  0) {
@@ -667,7 +671,7 @@ static int stats_file_history_update(struct stats_file 
*data_file)
 int __connman_stats_service_register(struct connman_service *service)
 {
struct stats_file *file;
-   char *name;
+   char *name, *dir;
int err;
 
DBG(service %p, service);
@@ -683,9 +687,26 @@ int __connman_stats_service_register(struct 
connman_service *service)
return -EALREADY;
}
 
-   name = g_strdup_printf(%s/stats/%s.data, STORAGEDIR,
+   dir = g_strdup_printf(%s/%s, STORAGEDIR,
+   __connman_service_get_ident(service));
+
+   /* If the dir doesn't exist, create it */
+   if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+   if(mkdir(dir, MODE)  0) {
+   if (errno != EEXIST) {
+   g_free(dir);
+
+   err = -errno;
+   goto err;
+   }
+   }
+   }
+
+   g_free(dir);
+
+   name = g_strdup_printf(%s/%s/data, STORAGEDIR,
__connman_service_get_ident(service));
-   file-history_name = g_strdup_printf(%s/stats/%s.history, STORAGEDIR,
+   file-history_name = g_strdup_printf(%s/%s/history, STORAGEDIR,
__connman_service_get_ident(service));
 
/* TODO: Use a global config file instead of hard coded value. */
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 03/14] service: Add function to get the ipconfig state.

2011-08-24 Thread Jukka Rissanen
---
 src/connman.h |3 +++
 src/service.c |   13 +
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/connman.h b/src/connman.h
index 17add6d..6b2216a 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -502,6 +502,9 @@ void __connman_service_set_string(struct connman_service 
*service,
 int __connman_service_ipconfig_indicate_state(struct connman_service *service,
enum connman_service_state new_state,
enum connman_ipconfig_type type);
+enum connman_service_state __connman_service_ipconfig_get_state(
+   struct connman_service *service,
+   enum connman_ipconfig_type type);
 
 int __connman_service_indicate_error(struct connman_service *service,
enum connman_service_error error);
diff --git a/src/service.c b/src/service.c
index fc90934..60c5ccc 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3702,6 +3702,19 @@ int __connman_service_indicate_default(struct 
connman_service *service)
return 0;
 }
 
+enum connman_service_state __connman_service_ipconfig_get_state(
+   struct connman_service *service,
+   enum connman_ipconfig_type type)
+{
+   if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
+   return service-state_ipv4;
+
+   if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
+   return service-state_ipv6;
+
+   return CONNMAN_SERVICE_STATE_UNKNOWN;
+}
+
 static void check_proxy_setup(struct connman_service *service)
 {
/*
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 01/14] provider: NULL pointer check.

2011-08-24 Thread Jukka Rissanen
---
 src/provider.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/provider.c b/src/provider.c
index 9ae62cd..633ca40 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -879,6 +879,9 @@ int connman_provider_append_route(struct connman_provider 
*provider,
 
 const char *connman_provider_get_driver_name(struct connman_provider *provider)
 {
+   if (provider-driver == NULL)
+   return NULL;
+
return provider-driver-name;
 }
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 08/14] service: Fix state combining.

2011-08-24 Thread Jukka Rissanen
If we have IPv6 state as DISCONNECT and IPv4 state as
ONLINE or READY then we are not disconnected.
---
 src/service.c |   64 ++--
 1 files changed, 16 insertions(+), 48 deletions(-)

diff --git a/src/service.c b/src/service.c
index 089a715..2aebff2 100644
--- a/src/service.c
+++ b/src/service.c
@@ -329,75 +329,43 @@ static enum connman_service_state combine_state(
goto done;
}
 
-   if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
-   if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION ||
-   state_b == CONNMAN_SERVICE_STATE_ONLINE ||
-   state_b == CONNMAN_SERVICE_STATE_READY)
-   result = state_b;
-   else
-   result = state_a;
+   if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
+   result = state_a;
goto done;
}
 
-   if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
-   if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION ||
-   state_a == CONNMAN_SERVICE_STATE_ONLINE ||
-   state_a == CONNMAN_SERVICE_STATE_READY)
-   result = state_a;
-   else
-   result = state_b;
+   if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
+   result = state_b;
goto done;
}
 
-   if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
-   if (state_b == CONNMAN_SERVICE_STATE_ONLINE ||
-   state_b == CONNMAN_SERVICE_STATE_READY)
-   result = state_b;
-   else
-   result = state_a;
+   if (state_a == CONNMAN_SERVICE_STATE_READY) {
+   result = state_a;
goto done;
}
 
-   if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
-   if (state_a == CONNMAN_SERVICE_STATE_ONLINE ||
-   state_a == CONNMAN_SERVICE_STATE_READY)
-   result = state_a;
-   else
-   result = state_b;
+   if (state_b == CONNMAN_SERVICE_STATE_READY) {
+   result = state_b;
goto done;
}
 
-   if (state_a == CONNMAN_SERVICE_STATE_READY) {
-   if (state_b == CONNMAN_SERVICE_STATE_ONLINE ||
-   state_b == CONNMAN_SERVICE_STATE_DISCONNECT)
-   result = state_b;
-   else
-   result = state_a;
+   if (state_a == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+   result = state_a;
goto done;
}
 
-   if (state_b == CONNMAN_SERVICE_STATE_READY) {
-   if (state_a == CONNMAN_SERVICE_STATE_ONLINE ||
-   state_a == CONNMAN_SERVICE_STATE_DISCONNECT)
-   result = state_a;
-   else
-   result = state_b;
+   if (state_b == CONNMAN_SERVICE_STATE_CONFIGURATION) {
+   result = state_b;
goto done;
}
 
-   if (state_a == CONNMAN_SERVICE_STATE_ONLINE) {
-   if (state_b == CONNMAN_SERVICE_STATE_DISCONNECT)
-   result = state_b;
-   else
-   result = state_a;
+   if (state_a == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+   result = state_a;
goto done;
}
 
-   if (state_b == CONNMAN_SERVICE_STATE_ONLINE) {
-   if (state_a == CONNMAN_SERVICE_STATE_DISCONNECT)
-   result = state_a;
-   else
-   result = state_b;
+   if (state_b == CONNMAN_SERVICE_STATE_ASSOCIATION) {
+   result = state_b;
goto done;
}
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 07/14] service: Change the debug print location to be more useful.

2011-08-24 Thread Jukka Rissanen
---
 src/service.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/service.c b/src/service.c
index 7ec4a30..089a715 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3501,9 +3501,6 @@ static int service_indicate_state(struct connman_service 
*service)
old_state = service-state;
new_state = combine_state(service-state_ipv4, service-state_ipv6);
 
-   if (old_state == new_state)
-   return -EALREADY;
-
DBG(service %p old %s - new %s/%s = %s,
service,
state2string(old_state),
@@ -3511,6 +3508,9 @@ static int service_indicate_state(struct connman_service 
*service)
state2string(service-state_ipv6),
state2string(new_state));
 
+   if (old_state == new_state)
+   return -EALREADY;
+
service-state = new_state;
state_changed(service);
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 09/14] service: Set the service state to IDLE if method is off or unknown.

2011-08-24 Thread Jukka Rissanen
---
 src/service.c |   28 +++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/service.c b/src/service.c
index 2aebff2..a081b79 100644
--- a/src/service.c
+++ b/src/service.c
@@ -3711,6 +3711,7 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
 {
struct connman_ipconfig *ipconfig = NULL;
enum connman_service_state old_state;
+   int ret;
 
if (service == NULL)
return -EINVAL;
@@ -3768,7 +3769,32 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
service-state_ipv6 = new_state;
 
-   return service_indicate_state(service);
+   ret = service_indicate_state(service);
+
+   /*
+* If the ipconfig method is OFF, then we set the state to IDLE
+* so that it will not affect the combined state in the future.
+*/
+   if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+   enum connman_ipconfig_method method;
+   method = __connman_ipconfig_get_method(service-ipconfig_ipv4);
+   if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
+   method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
+   service-state_ipv4 = CONNMAN_SERVICE_STATE_IDLE;
+   ret = service_indicate_state(service);
+   }
+
+   } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
+   enum connman_ipconfig_method method;
+   method = __connman_ipconfig_get_method(service-ipconfig_ipv6);
+   if (method == CONNMAN_IPCONFIG_METHOD_OFF ||
+   method == CONNMAN_IPCONFIG_METHOD_UNKNOWN) {
+   service-state_ipv6 = CONNMAN_SERVICE_STATE_IDLE;
+   ret = service_indicate_state(service);
+   }
+   }
+
+   return ret;
 }
 
 int __connman_service_request_login(struct connman_service *service)
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 10/14] provider: Add ref counting debug.

2011-08-24 Thread Jukka Rissanen
---
 src/provider.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/provider.c b/src/provider.c
index 633ca40..bbd462e 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -143,7 +143,7 @@ static void provider_unregister(struct connman_provider 
*provider)
 
 struct connman_provider *connman_provider_ref(struct connman_provider 
*provider)
 {
-   DBG(provider %p, provider);
+   DBG(provider %p refcount %d, provider, provider-refcount + 1);
 
g_atomic_int_inc(provider-refcount);
 
@@ -165,7 +165,7 @@ static void provider_destruct(struct connman_provider 
*provider)
 
 void connman_provider_unref(struct connman_provider *provider)
 {
-   DBG(provider %p, provider);
+   DBG(provider %p refcount %d, provider, provider-refcount - 1);
 
if (g_atomic_int_dec_and_test(provider-refcount) == FALSE)
return;
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 13/14] network: Add NULL check.

2011-08-24 Thread Jukka Rissanen
---
 src/network.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/network.c b/src/network.c
index 31e7eaa..b8175a5 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1330,6 +1330,9 @@ int __connman_network_set_ipconfig(struct connman_network 
*network,
enum connman_ipconfig_method method;
int ret;
 
+   if (network == NULL)
+   return -EINVAL;
+
if (ipconfig_ipv6) {
method = __connman_ipconfig_get_method(ipconfig_ipv6);
 
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 11/14] provider: Return existing service path if already connected.

2011-08-24 Thread Jukka Rissanen
---
 src/provider.c |9 +
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/provider.c b/src/provider.c
index bbd462e..8f1862e 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -571,11 +571,12 @@ int __connman_provider_create_and_connect(DBusMessage 
*msg)
err = -EOPNOTSUPP;
goto unref;
}
-   }
 
-   err = __connman_service_connect(provider-vpn_service);
-   if (err  0  err != -EINPROGRESS)
-   goto failed;
+   err = __connman_service_connect(provider-vpn_service);
+   if (err  0  err != -EINPROGRESS)
+   goto failed;
+   } else
+   DBG(provider already connected);
 
service_path = __connman_service_get_path(provider-vpn_service);
g_dbus_send_reply(connection, msg,
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH misc 12/14] connection: Service was not ref counted properly.

2011-08-24 Thread Jukka Rissanen
The reference counting problems were clearly seen with VPN service.
---
 src/connection.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 84e3ab4..6323401 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -229,6 +229,7 @@ static struct gateway_data *add_gateway(struct 
connman_service *service,
}
}
 
+   connman_service_ref(service);
g_hash_table_replace(gateway_hash, service, data);
 
return data;
@@ -657,9 +658,10 @@ void __connman_connection_gateway_remove(struct 
connman_service *service,
 do_ipv4 == TRUE) ||
(data-ipv6_gateway != NULL  data-ipv4_gateway == NULL
 do_ipv6 == TRUE)
-   )
+   ) {
+   connman_service_unref(service);
g_hash_table_remove(gateway_hash, service);
-   else
+   } else
DBG(Not yet removing gw ipv4 %p/%d ipv6 %p/%d,
data-ipv4_gateway, do_ipv4,
data-ipv6_gateway, do_ipv6);
-- 
1.7.1

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [systemd-devel] net stats per app

2011-08-24 Thread Gustavo Sverzut Barbieri
On Wed, Aug 24, 2011 at 10:42 AM, Lennart Poettering
lenn...@poettering.net wrote:
 On Tue, 02.08.11 15:51, Daniel Wagner (w...@monom.org) wrote:

 So my thinking is, instead of using the uid driver trick, I could use
 cgroups for collecting the network traffic. At least from the sub module
 description it seems to be the right spot to add a new statistic
 interface.

 Yupp, that makes a lot of sense I'd say. For CPU accounting there's
 already cpuacct. Adding a netacct cgroup controller would make a lot of
 sense to me. (a hackish way to achieve this with existing tools might be
 to use net_cls for this or so. dunno, might already be enough if ip
 rules allows accounting.)

 A open question is how I get the whole thing persistent. So not each
 time when an application starts the counters begin at 0. My guts feeling
 systemd should take of this but I don't know if that is the right
 direction.

 Hmm, you could simply precreate the cgroups and mark the tasks file with
 +t (sticky bit). systemd won't remove the cgroup then after use. Or, we
 could add a new switch ControlGroupPersistant=yes or so which would
 set +t automatically but systemd would still create the groups for you
 (so that youdon't have to pre-create anything), but not delete them
 anymore. Would that make sense?

 (I have added this option now to the todo list, since it will make sense
 for stuff like cpuacct where we are in the same boat)

Likely he will need to keep accounting between reboots as well, in
this case the solution can't be in systemd or kernel, will need a tool
to walk these groups accumulate them into a persistent media. Be it
periodically, upon reboot or some other method.

-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--
MSN: barbi...@gmail.com
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH 0/2] device and wifi cleanup

2011-08-24 Thread Samuel Ortiz
Hi Jukka,

On Wed, Aug 24, 2011 at 10:00:20AM +0300, Jukka Rissanen wrote:
 Hi,
 
 attached patches do minor cleanup for device.c and wifi.c
Thanks, both of them applied now.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH 1/2] pacrunner: libproxy: don't be case sensitive with the strings returned by PAC files

2011-08-24 Thread Alban Crequy
Be compatible with existing PAC files which return something like proxy
server:port. They work on Windows but they would not work if pacrunner was
case-sensitive.
---
 libproxy/proxy.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libproxy/proxy.c b/libproxy/proxy.c
index 641e791..6dfbfd2 100644
--- a/libproxy/proxy.c
+++ b/libproxy/proxy.c
@@ -77,12 +77,12 @@ static char **extract_result(const char *str)
result[0] = NULL;
result[1] = NULL;
 
-   if (strcmp(str, DIRECT) == 0) {
+   if (strcasecmp(str, DIRECT) == 0) {
result[0] = strdup(direct://);
return result;
}
 
-   if (strncmp(str, PROXY , 6) == 0) {
+   if (strncasecmp(str, PROXY , 6) == 0) {
int len = strlen(str + 6) + 8;
result[0] = malloc(len);
if (result[0] != NULL)
-- 
1.7.5.4

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


[PATCH 2/2] pacrunner: libproxy: supports various SOCKS proxies

2011-08-24 Thread Alban Crequy
---
 libproxy/proxy.c |   24 
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/libproxy/proxy.c b/libproxy/proxy.c
index 6dfbfd2..ae53a7a 100644
--- a/libproxy/proxy.c
+++ b/libproxy/proxy.c
@@ -90,6 +90,30 @@ static char **extract_result(const char *str)
return result;
}
 
+   if (strncasecmp(str, SOCKS , 6) == 0) {
+   int len = strlen(str + 6) + 9;
+   result[0] = malloc(len);
+   if (result[0] != NULL)
+   sprintf(result[0], socks://%s, str + 6);
+   return result;
+   }
+
+   if (strncasecmp(str, SOCKS4 , 7) == 0) {
+   int len = strlen(str + 7) + 10;
+   result[0] = malloc(len);
+   if (result[0] != NULL)
+   sprintf(result[0], socks4://%s, str + 7);
+   return result;
+   }
+
+   if (strncasecmp(str, SOCKS5 , 7) == 0) {
+   int len = strlen(str + 7) + 10;
+   result[0] = malloc(len);
+   if (result[0] != NULL)
+   sprintf(result[0], socks5://%s, str + 7);
+   return result;
+   }
+
return result;
 }
 
-- 
1.7.5.4

___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [systemd-devel] net stats per app

2011-08-24 Thread Daniel Wagner

Hi Lennart,

On 08/24/2011 03:42 PM, Lennart Poettering wrote:

On Tue, 02.08.11 15:51, Daniel Wagner (w...@monom.org) wrote:


So my thinking is, instead of using the uid driver trick, I could use
cgroups for collecting the network traffic. At least from the sub module
description it seems to be the right spot to add a new statistic
interface.


Yupp, that makes a lot of sense I'd say. For CPU accounting there's
already cpuacct. Adding a netacct cgroup controller would make a lot of
sense to me. (a hackish way to achieve this with existing tools might be
to use net_cls for this or so. dunno, might already be enough if ip
rules allows accounting.)


By coincidence I meet Glauber at LinuxCon. He told me he is writing a 
new cgroup for controlling sockets. Adding tx/rx stats wouldn't be a big 
deal. Hope those patches are making good progress :)


net_cls wont work since we could only track tx traffic not rx traffic. 
So the only place to collect the stats is between the network stack and 
the userspace.


cheers,
daniel
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [systemd-devel] net stats per app

2011-08-24 Thread Daniel Wagner

On 08/24/2011 04:19 PM, Gustavo Sverzut Barbieri wrote:

A open question is how I get the whole thing persistent. So not each
time when an application starts the counters begin at 0. My guts feeling
systemd should take of this but I don't know if that is the right
direction.


Hmm, you could simply precreate the cgroups and mark the tasks file with
+t (sticky bit). systemd won't remove the cgroup then after use. Or, we
could add a new switch ControlGroupPersistant=yes or so which would
set +t automatically but systemd would still create the groups for you
(so that youdon't have to pre-create anything), but not delete them
anymore. Would that make sense?

(I have added this option now to the todo list, since it will make sense
for stuff like cpuacct where we are in the same boat)


Likely he will need to keep accounting between reboots as well, in
this case the solution can't be in systemd or kernel, will need a tool
to walk these groups accumulate them into a persistent media. Be it
periodically, upon reboot or some other method.


Yes, the aim is to maintain statistics even over system reboots. I had 
not yet time to figure out how this could be done.


The use case is as following:

We have a browser instance which is only used to connect to a our 
company portal. The user is able to start another instance of the 
browser which is used for ordinary web browsing. These two instance 
should be treated differently, so we have to maintain two statistics,
one for the portal browser and one for the normal browser. If a certain 
traffic limit has been reached on the ordinary web browser, ConnMan 
should stop this session. The portal web browser is still allowed to 
access the internet through the current path.


We have some more of those use cases but most of them can be mapped to 
that one. If a limit for an application is reached either shutdown the 
session or reroute the traffic to an different device.


If ConnMan would know which application is put into which cgroup then 
ConnMan could maintain the statistics (also persistent). ConnMan knows 
which network device/route is currently in use for the application. So 
everything is there. I think systemd would be the wrong place to solve this.


cheers,
daniel
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH fast connect 1/9] service: Add frequency support to service.

2011-08-24 Thread Samuel Ortiz
Hi Jukka,

On Wed, Aug 24, 2011 at 04:48:06PM +0300, Jukka Rissanen wrote:
 +dbus_int16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
We should return a dbus_uint16_t here.

 @@ -5293,6 +5293,7 @@ static int service_save(struct connman_service *service)
   gchar *pathname, *data = NULL;
   gsize length;
   gchar *str;
 + gint freq;
And that should be a guint.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH fast connect 3/9] gsupplicant: Add support to append char ** entries to dbus dict.

2011-08-24 Thread Samuel Ortiz
Hi Jukka,


On Wed, Aug 24, 2011 at 04:48:08PM +0300, Jukka Rissanen wrote:
 From: Mohamed Abbas mohamed.ab...@intel.com
 
 ---
  gsupplicant/dbus.c |   29 +
  gsupplicant/dbus.h |   20 
  2 files changed, 49 insertions(+), 0 deletions(-)
 
 diff --git a/gsupplicant/dbus.c b/gsupplicant/dbus.c
 index e014265..e48343c 100644
 --- a/gsupplicant/dbus.c
 +++ b/gsupplicant/dbus.c
 @@ -520,3 +520,32 @@ void 
 supplicant_dbus_property_append_fixed_array(DBusMessageIter *iter,
  
   dbus_message_iter_close_container(iter, value);
  }
 +
 +void supplicant_dbus_property_append_array(DBusMessageIter *iter,
 + const char *key, int type,
 + supplicant_dbus_array_function function,
 + void *user_data)
 +{
 + DBusMessageIter value, array;
 + const char *variant_sig, *array_sig;
 +
 + variant_sig = DBUS_TYPE_ARRAY_AS_STRING
 + DBUS_TYPE_ARRAY_AS_STRING
 + DBUS_TYPE_BYTE_AS_STRING;
 +
 + array_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
So we should build the variant and array signatures according to the type
argument. See connman_dbus_property_append_array() for an example of doing so.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH fast connect 5/9] wifi: Add SSIDs and frequencies to wpa_supplicant scan for fast scan.

2011-08-24 Thread Samuel Ortiz
Hi Jukka,

On Wed, Aug 24, 2011 at 04:48:10PM +0300, Jukka Rissanen wrote:
 +static void supplicant_add_scan_frequency(DBusMessageIter *dict,
 + const char *key, supplicant_dbus_array_function function,
The key argument is not needed here, as we know it will always be Channels.

  static void interface_scan_params(DBusMessageIter *iter, void *user_data)
  {
   DBusMessageIter dict;
 - const char *type = passive;
 + const char *type_active = active;
 + const char *type_passive = passive;
Let's just keep one string here, and set it depending on the scan data we get.


 + struct interface_scan_data *data = user_data;
  
   supplicant_dbus_dict_open(iter, dict);
  
 - supplicant_dbus_dict_append_basic(dict, Type,
 - DBUS_TYPE_STRING, type);
 + if (data  data-scan_params  data-scan_params-freqs[0] != 0) {
I think the data-scan_params-freqs[0] should be handled by the
supplicant_add_scan_frequency routine.


 +
 + supplicant_dbus_dict_append_basic(dict, Type,
 + DBUS_TYPE_STRING, type_active);
 +
 + if (data-scan_params-num_ssids  0)
This is already handled by append_ssids, no need to check for num_ssids here.

 +static int get_latest_connections(const char *prefix, int max_ssids,
 + GSupplicantScanParams *scan_data)
 +{
 + struct last_connected latest_list;
 + GKeyFile *keyfile;
 + gchar *pathname, *data = NULL;
 + gsize length;
 + char **groups;
 + gchar *str = NULL;
 + int i;
 + int freq;
 + GTimeVal modified;
 +
 + memset(latest_list, 0, sizeof(latest_list));
 +
 + pathname = g_strdup_printf(%s/default.profile, STORAGEDIR);
 + if (pathname == NULL)
 + return -ENOMEM;
 +
 + keyfile = g_key_file_new();
 +
 + if (g_file_get_contents(pathname, data, length, NULL) == FALSE) {
 + g_free(pathname);
 + return -ENOENT;
 + }
 +
 + g_free(pathname);
 +
 + if (g_key_file_load_from_data(keyfile, data, length,
 + 0, NULL) == FALSE) {
 + g_free(data);
 + return -EILSEQ;
 + }
 +
 + g_free(data);
 +
 + groups = g_key_file_get_groups(keyfile, length);
 + for (i = 0; groups[i] != NULL; i++) {
 +
 + if (g_str_has_prefix(groups[i], prefix) == TRUE) {
 + str = g_key_file_get_string(keyfile,
 + groups[i], Favorite, NULL);
 + if (str == NULL || g_strcmp0(str, true)) {
 + if (str)
 + g_free(str);
 + continue;
 + }
 + g_free(str);
 +
 + str = g_key_file_get_string(keyfile,
 + groups[i], AutoConnect, NULL);
 + if (str == NULL || g_strcmp0(str, true)) {
 + if (str)
 + g_free(str);
 + continue;
 + }
 + g_free(str);
 +
 + str = g_key_file_get_string(keyfile,
 + groups[i], Modified, NULL);
 + if (str != NULL) {
 + g_time_val_from_iso8601(str, modified);
 + g_free(str);
 + }
 +
 + freq = g_key_file_get_integer(keyfile, groups[i],
 + Frequency, NULL);
 +
 + if (freq)
 + add_conn_list(latest_list, groups[i],
 + freq, modified);
 + }
 + }
 +
 + for (i = 0; i  latest_list.num_ssids; i++)
 + add_scan_param(keyfile, latest_list.ssids[i].group,
 + latest_list.ssids[i].freq, scan_data, max_ssids);
I think we're slightly re-inventing the wheel with the whole add_conn_list()
routine.
Can't we build a sorted list (as in e.g. a GSequence) of SSIDs and
frequencies, and then pass that list to add_scan_parameters(). The later would
iterate through the G_SUPPLICANT_MAX_FAST_SCAN first GSequence entries.

  static int wifi_scan_fast(struct connman_device *device)
  {
   struct wifi_data *wifi = connman_device_get_data(device);
 + GSupplicantScanParams *scan_params = NULL;
   int ret;
 + int driver_max = 0;
It doesn't hurt to simply call this one driver_max_ssids.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH fast connect 6/9] gsupplicant: Fix the ssid array.

2011-08-24 Thread Samuel Ortiz
Hi Jukka,

On Wed, Aug 24, 2011 at 04:48:11PM +0300, Jukka Rissanen wrote:
 ---
  gsupplicant/gsupplicant.h |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
 index 059837f..93e1c8e 100644
 --- a/gsupplicant/gsupplicant.h
 +++ b/gsupplicant/gsupplicant.h
 @@ -135,7 +135,7 @@ typedef struct _GSupplicantSSID GSupplicantSSID;
  
  struct _GSupplicantScanParams {
   struct scan_ssid {
 - unsigned char *ssid[32];
 + unsigned char ssid[32];
   uint8_t ssid_len;
   } ssids[G_SUPPLICANT_MAX_FAST_SCAN];
Could we please merge this patch with the previous one ?

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH fast connect 7/9] wifi: Removed extra scan request call.

2011-08-24 Thread Samuel Ortiz
Hi Jukka,

On Wed, Aug 24, 2011 at 04:48:12PM +0300, Jukka Rissanen wrote:
 The wifi_scan_fast() is already called in connman_device_set_powered()
 so no need to call it again immediately.
 ---
  plugins/wifi.c |2 --
  1 files changed, 0 insertions(+), 2 deletions(-)
 
 diff --git a/plugins/wifi.c b/plugins/wifi.c
 index b9e30db..c0607f5 100644
 --- a/plugins/wifi.c
 +++ b/plugins/wifi.c
 @@ -801,8 +801,6 @@ static void interface_added(GSupplicantInterface 
 *interface)
  
   if (wifi-tethering == TRUE)
   return;
 -
 - wifi_scan_fast(wifi-device);
I think we could merge this one with whatever patch was adding this in the
first place.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH 1/2] pacrunner: libproxy: don't be case sensitive with the strings returned by PAC files

2011-08-24 Thread Samuel Ortiz
Hi Alban,

On Wed, Aug 24, 2011 at 04:01:05PM +0100, Alban Crequy wrote:
 Be compatible with existing PAC files which return something like proxy
 server:port. They work on Windows but they would not work if pacrunner was
 case-sensitive.
Patch applied, thanks a lot.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH 2/2] pacrunner: libproxy: supports various SOCKS proxies

2011-08-24 Thread Samuel Ortiz
Hi Alban,

On Wed, Aug 24, 2011 at 04:01:06PM +0100, Alban Crequy wrote:
 ---
  libproxy/proxy.c |   24 
  1 files changed, 24 insertions(+), 0 deletions(-)
Patch applied as well, thanks.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH v2 01/24] technology: Refactor enable/disable APIs.

2011-08-24 Thread Samuel Ortiz
Hi Alok,

On Wed, Aug 24, 2011 at 04:44:07PM +0300, Alok Barsode wrote:
 From: Alok Barsode alok.bars...@linux.intel.com

I'm still waiting for patches 22, 23 and 24 from this serie.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH v2 01/24] technology: Refactor enable/disable APIs.

2011-08-24 Thread Samuel Ortiz
Hi Alok,

On Wed, Aug 24, 2011 at 04:44:07PM +0300, Alok Barsode wrote:
 From: Alok Barsode alok.bars...@linux.intel.com
 
 connman_technology_enable: Enable a technology. Enables all the
 devices in the device_list of the technology.
 connman_technology_enabled: Callback for connman_technology_enable.
 Changes the state of the technology to ENABLED.
 Ditto for connman_technology_disable/connman_technology_disabled.
So I tested those patches, and I have a couple concerns:

1) I had to apply the following patch:

diff --git a/src/device.c b/src/device.c
index cdd9118..52a5029 100644
--- a/src/device.c
+++ b/src/device.c
@@ -663,10 +663,12 @@ int connman_device_set_powered(struct connman_device
*devi
if (device-powered == powered)
return -EALREADY;
 
-   /* Reset pending request */
-   g_source_remove(device-pending_timeout);
-   device-pending_timeout = 0;
-   device-powered_pending = PENDING_NONE;
+   if (device-pending_timeout) {
+   /* Reset pending request */
+   g_source_remove(device-pending_timeout);

in order to avoid GLib critical warnings. Try disabling/enabling ethernet and
you will get the same. There is no pending request with synchronous
technologies as ethernet.

2) I found at least one bug, where turning offline mode on while my WiFi
chipset was associating wouldn't turn WiFi off. I got this from test-manager:

AvailableTechnologies
[ ethernet wifi ]
OfflineMode
true
Technologies
/net/connman/technology/bluetooth
State = offline
Type = bluetooth
Name = Bluetooth
Tethering = false
/net/connman/technology/wifi
State = enabled
Type = wifi
Name = WiFi
Tethering = false
/net/connman/technology/ethernet
State = enabled
Type = ethernet
Name = Wired
Tethering = false
SessionMode
0

3) I realized that we never move the technology states to connected. This is
not a regression, but I'd appreciate if you could look at it.


So, I think we should fix 1) and 2) before pushing this patchset as they're
real regressions.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman