Re: ConnMan 1.7 crashing in Set Powered

2012-09-20 Thread Daniel Wagner

On 19.09.2012 22:16, Gustavo Padovan wrote:

Hi,

After executing:

SetProperty(Powered, True)
SetProperty(Powered, False)
SetProperty(Powered, True)
SetProperty(Powered, False)


many times I got this crash:

http://pastebin.com/5wKtKGEg

#0  0xb7f15d5c in g_list_find () from /lib/i386-linux-gnu/libglib-2.0.so.0
#1  0xb7f286c4 in g_queue_remove () from /lib/i386-linux-gnu/libglib-2.0.so.0
#2  0x08060907 in sort_and_return_results (lookup=0x8105b90)
 at gweb/gresolv.c:503
#3  0x080609b3 in query_timeout (user_data=0x8105f68) at gweb/gresolv.c:524
#4  0xb7f19f6f in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
#5  0xb7f19276 in g_main_context_dispatch ()
from /lib/i386-linux-gnu/libglib-2.0.so.0
#6  0xb7f19615 in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
#7  0xb7f19a5b in g_main_loop_run () from /lib/i386-linux-gnu/libglib-2.0.so.0
#8  0x08079f54 in main (argc=1, argv=0xb754) at src/main.c:586


FWI, I saw one of those crashes yesterday too. I could trigger it with 
running test-session. Since I had a modified version of ConnMan no report.



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


[PATCH] wifi: fix tethering

2012-09-20 Thread Artem Bityutskiy
From: Artem Bityutskiy artem.bityuts...@linux.intel.com

The problem
~~~

Wifi tethering works with kernel 3.4, but it does not work with kernel 3.5.
Bisecting showed that the following kernel patch causes the breakage:
3edaf3e mac80211: manage AP netdev carrier state

Running connman with debugging enabled shoed that in case of 3.4 we
have the following sequence of RTM_NEWLINK events from the kernel:

1. IFF_UP not set, ifi_change=1
2. IFF_UP,IFF_LOWER_UP, ifi_change=1

which makes connman do the following:

connmand[210]: plugins/wifi.c:wifi_newlink() index 4 flags 4098 change 1
connmand[210]: plugins/wifi.c:wifi_newlink() interface down
connmand[210]: plugins/wifi.c:wifi_newlink() index 4 flags 69635 change 1
connmand[210]: plugins/wifi.c:wifi_newlink() interface up
connmand[210]: plugins/wifi.c:wifi_newlink() carrier on
connmand[210]: plugins/wifi.c:handle_tethering() index 4 bridge tether

However, in 3.5 we have the following sequents of events from the kernel:

1. IFF_UP, ifi_change=1
2. IFF_UP,IFF_LOWER_UP, ifi_change=0

which makes connman do the following:

connmand[493]: plugins/wifi.c:wifi_newlink() index 4 flags 4099 change 1
connmand[493]: plugins/wifi.c:wifi_newlink() interface up
connmand[493]: plugins/wifi.c:wifi_newlink() index 4 flags 69635 change 0

So as you see, handle_tethering() is never called, and tethering does not work.

Analysis


The root-cause for it is that connman handles the ifi_change flag
incorrectly. Namely, this check in 'wifi_newlink()' is the problem:

if (!change)
return;

Connman interprets it as if non-zero, there was some change,
which is wrong. According to RFC 3549, it is:
reserved for future use.  Must be set to 0x

However, I see that the kernel does not always set it to 0x
(grep for rtmsg_ifinfo() in the kernel sources). I do not know why,
but for connman it is better to ignore this value.

Thus, just remove that check, which makes tethering work.

Thanks to Tomasz Bursztyka tomasz.burszt...@linux.intel.com for help.

Signed-off-by: Artem Bityutskiy artem.bityuts...@linux.intel.com
---
 plugins/wifi.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index f5690b5..2d81f80 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -142,9 +142,6 @@ static void wifi_newlink(unsigned flags, unsigned change, 
void *user_data)
 
DBG(index %d flags %d change %d, wifi-index, flags, change);
 
-   if (!change)
-   return;
-
if ((wifi-flags  IFF_UP) != (flags  IFF_UP)) {
if (flags  IFF_UP)
DBG(interface up);
-- 
1.7.7

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


[PATCH] technology: Update tethering properties when relevant

2012-09-20 Thread Tomasz Bursztyka
---
Hi,

Currently when setting tethering related properties, it does not send a 
PropertyChanged signal.
From a client point of view it's not nice: either you believe the SetProperty 
return success or 
after it you run a GetTechnologies again to be sure. I prefer having such 
signal, what do you think?
(at least it goes like all other properties)

Tomasz

 src/technology.c | 28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/technology.c b/src/technology.c
index 3fc7afc..d78e7b3 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -734,9 +734,17 @@ static DBusMessage *set_property(DBusConnection *conn,
if (strlen(str)  1 || strlen(str)  32)
return __connman_error_invalid_arguments(msg);
 
-   g_free(technology-tethering_ident);
-   technology-tethering_ident = g_strdup(str);
-   technology_save(technology);
+   if (g_strcmp0(technology-tethering_ident, str) != 0) {
+   g_free(technology-tethering_ident);
+   technology-tethering_ident = g_strdup(str);
+   technology_save(technology);
+
+   connman_dbus_property_changed_basic(technology-path,
+   CONNMAN_TECHNOLOGY_INTERFACE,
+   TetheringIdentifier,
+   DBUS_TYPE_STRING,
+   technology-tethering_ident);
+   }
} else if (g_str_equal(name, TetheringPassphrase) == TRUE) {
const char *str;
 
@@ -748,9 +756,17 @@ static DBusMessage *set_property(DBusConnection *conn,
if (strlen(str)  8 || strlen(str)  63)
return __connman_error_passphrase_required(msg);
 
-   g_free(technology-tethering_passphrase);
-   technology-tethering_passphrase = g_strdup(str);
-   technology_save(technology);
+   if (g_strcmp0(technology-tethering_passphrase, str) != 0) {
+   g_free(technology-tethering_passphrase);
+   technology-tethering_passphrase = g_strdup(str);
+   technology_save(technology);
+
+   connman_dbus_property_changed_basic(technology-path,
+   CONNMAN_TECHNOLOGY_INTERFACE,
+   TetheringPassphrase,
+   DBUS_TYPE_STRING,
+   technology-tethering_passphrase);
+   }
} else if (g_str_equal(name, Powered) == TRUE) {
connman_bool_t enable;
 
-- 
1.7.12

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


[PATCH v1 01/33] session: Check D-Bus argumets for Changed method

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/session.c b/src/session.c
index d4798ed..c869143 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1266,8 +1266,15 @@ static DBusMessage *change_session(DBusConnection *conn,
if (dbus_message_iter_init(msg, iter) == FALSE)
return __connman_error_invalid_arguments(msg);
 
+   if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+   return __connman_error_invalid_arguments(msg);
+
dbus_message_iter_get_basic(iter, name);
dbus_message_iter_next(iter);
+
+   if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT)
+   return __connman_error_invalid_arguments(msg);
+
dbus_message_iter_recurse(iter, value);
 
switch (dbus_message_iter_get_arg_type(value)) {
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 00/33] Session Policy Plugin

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

Hi,

Here is the current state of work on the session policy plugin.

The series is not perfect, meaning some stuff could be rearanged or
merged/splitted, but I am not sure if that is really needed.  I tried
to keep the patches small so, each step should make sense. Maybe it
helps to apply all patches and look at the result.

cheers,
daniel


Daniel Wagner (33):
  session: Check D-Bus argumets for Changed method
  session: Move plugin code up
  session: Add plugin priority
  session_policy: Set plugin priority to low
  session: Remove global configuration plugin
  session: Maintain plugin list sorted
  session: Assign config plugin to session
  session: Update session when plugin is add/removed
  session: Remove AvoidHandover documentation
  session: Remove AvoidHandover implementation
  unit: Update session unit test to API changes
  session: No need to free NULL list
  session: Rename connman_session_config to connman_session_policy
  session: Move struct connman_session to session.h
  session: Use session pointer instead of string id
  session: Move bearer_info to session.h
  session: Move configuration bits to a public struct
  session: Allow plugin access to connman_session_allowed_bearers_any
  session: Add callbacks for config creation/distruction
  session_policy: Implement config creation/destruction
  session: Get config from policy plugin
  session: Remove unused functions
  session: Add bearer list cleanup function
  session_policy: Use bearer free function
  session: Support no match AllowedBearers
  session: Update ConnnectionType documentation
  session: Enforce correct ConnectionType settings
  session: Apply policy on AllowedBearers
  session: Update AllowedBearers documentation
  unit: Do not append empty AllowedBearers dictionary
  unit: Support ConnectionType unknown
  session: Apply policy on ConnnectionType
  session: Update sessions on config updates

 doc/session-api.txt  |  46 ++--
 include/session.h|  57 +++-
 plugins/session_policy.c |  77 --
 src/connman.h|   3 +-
 src/session.c| 661 +++
 unit/session-api.c   | 118 +
 unit/test-connman.h  |  29 +--
 7 files changed, 509 insertions(+), 482 deletions(-)

-- 
1.7.12.315.g682ce8b

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


[PATCH v1 03/33] session: Add plugin priority

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

In order to support several session configuration plugins at runtime.
---
 include/session.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/session.h b/include/session.h
index 5aa3e5e..30e8859 100644
--- a/include/session.h
+++ b/include/session.h
@@ -28,11 +28,16 @@
 extern C {
 #endif
 
+#define CONNMAN_SESSION_CONFIG_PRIORITY_LOW  -100
+#define CONNMAN_SESSION_CONFIG_PRIORITY_DEFAULT 0
+#define CONNMAN_SESSION_CONFIG_PRIORITY_HIGH  100
+
 /*
  * The session are identified through the pid is only a temporary solution
  */
 struct connman_session_config {
const char *name;
+   int priority;
int (*get_bool) (const char *id, const char *key, connman_bool_t *val);
int (*get_string) (const char *id, const char *key, char **val);
 };
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 04/33] session_policy: Set plugin priority to low

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 plugins/session_policy.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/session_policy.c b/plugins/session_policy.c
index 626d9bb..ca40e8d 100644
--- a/plugins/session_policy.c
+++ b/plugins/session_policy.c
@@ -61,6 +61,7 @@ static int config_get_string(const char *id, const char *key, 
char **val)
 
 static struct connman_session_config session_config = {
.name = session policy configuration,
+   .priority = CONNMAN_SESSION_CONFIG_PRIORITY_LOW,
.get_bool = config_get_bool,
.get_string = config_get_string,
 };
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 05/33] session: Remove global configuration plugin

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

And support per session configuration plugin. Obviously, this patch
itsel is not complete. The code for assigning a configuration
plugin to session-config follows in the next patches.
---
 src/session.c | 43 +++
 1 file changed, 15 insertions(+), 28 deletions(-)

diff --git a/src/session.c b/src/session.c
index 4c5b55c..7e6d2c5 100644
--- a/src/session.c
+++ b/src/session.c
@@ -36,7 +36,7 @@ static DBusConnection *connection;
 static GHashTable *session_hash;
 static connman_bool_t sessionmode;
 static struct connman_session *ecall_session;
-static struct connman_session_config *session_config;
+static GSList *config_list;
 
 enum connman_session_trigger {
CONNMAN_SESSION_TRIGGER_UNKNOWN = 0,
@@ -103,6 +103,8 @@ struct connman_session {
char *notify_path;
guint notify_watch;
 
+   struct connman_session_config *config;
+
connman_bool_t append_all;
struct session_info *info;
struct session_info *info_last;
@@ -253,24 +255,27 @@ static char *service2bearer(enum connman_service_type 
type)
return ;
 }
 
-static int config_get_bool(const char *id, const char *key, connman_bool_t 
*val)
+static int config_get_bool(struct connman_session *session, const char *id,
+   const char *key, connman_bool_t *val)
 {
-   if (session_config == NULL) {
+   if (session-config == NULL) {
*val = FALSE;
return -EINVAL;
}
 
-   return (*session_config-get_bool)(id, key, val);
+   return (*session-config-get_bool)(id, key, val);
 }
 
-static int config_get_string(const char *id, const char *key, char **val)
+static int config_get_string(struct connman_session *session, const char *id,
+   const char *key, char **val)
 {
-   if (session_config == NULL) {
+   if (session-config == NULL) {
*val = NULL;
return -EINVAL;
}
 
-   return (*session_config-get_string)(id, key, val);
+   return (*session-config-get_string)(id, key, val);
+}
 }
 
 static struct connman_session *session_lookup_by_id(const char *id)
@@ -339,30 +344,12 @@ int connman_session_config_register(struct 
connman_session_config *config)
 {
DBG(name %s, config-name);
 
-   if (session_config != NULL) {
-   connman_warn(A session configuration plugin '%s' is 
-   already registerd. Skipping registration 
-   of plugin '%s',
-   session_config-name, config-name);
-   return -EALREADY;
-   }
-
-   session_config = config;
-
return 0;
 }
 
 void connman_session_config_unregister(struct connman_session_config *config)
 {
DBG(name %s, config-name);
-
-   if (config != session_config) {
-   connman_warn(Trying to unregister session configuration 
-   plugin '%s', config-name);
-   return;
-   }
-
-   session_config = NULL;
 }
 
 static void cleanup_bearer_info(gpointer data, gpointer user_data)
@@ -1607,9 +1594,9 @@ int __connman_session_create(DBusMessage *msg)
info = session-info;
info_last = session-info_last;
 
-   config_get_bool(owner, Priority, priority);
-   config_get_bool(owner, EmergencyCall, ecall_app);
-   config_get_string(owner, RoamingPolicy, roaming_policy_str);
+   config_get_bool(session, owner, Priority, priority);
+   config_get_bool(session, owner, EmergencyCall, ecall_app);
+   config_get_string(session, owner, RoamingPolicy, roaming_policy_str);
roaming_policy = string2roamingpolicy(roaming_policy_str);
 
session-owner = g_strdup(owner);
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 06/33] session: Maintain plugin list sorted

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/session.c b/src/session.c
index 7e6d2c5..880c7ed 100644
--- a/src/session.c
+++ b/src/session.c
@@ -276,6 +276,13 @@ static int config_get_string(struct connman_session 
*session, const char *id,
 
return (*session-config-get_string)(id, key, val);
 }
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+   const struct connman_session_config *config1 = a;
+   const struct connman_session_config *config2 = b;
+
+   return config2-priority - config1-priority;
 }
 
 static struct connman_session *session_lookup_by_id(const char *id)
@@ -344,12 +351,16 @@ int connman_session_config_register(struct 
connman_session_config *config)
 {
DBG(name %s, config-name);
 
+   config_list = g_slist_insert_sorted(config_list, config,
+   compare_priority);
return 0;
 }
 
 void connman_session_config_unregister(struct connman_session_config *config)
 {
DBG(name %s, config-name);
+
+   config_list = g_slist_remove(config_list, config);
 }
 
 static void cleanup_bearer_info(gpointer data, gpointer user_data)
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 07/33] session: Assign config plugin to session

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

Let's pick the first plugin. If needed we can add some more smart code
later on.
---
 src/session.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/src/session.c b/src/session.c
index 880c7ed..102b523 100644
--- a/src/session.c
+++ b/src/session.c
@@ -277,6 +277,24 @@ static int config_get_string(struct connman_session 
*session, const char *id,
return (*session-config-get_string)(id, key, val);
 }
 
+static int assign_config_plugin(struct connman_session *session)
+{
+   GSList *list;
+   struct connman_session_config *config;
+
+   if (session-config != NULL)
+   return -EALREADY;
+
+   for (list = config_list; list != NULL; list = list-next) {
+   config = list-data;
+
+   session-config = config;
+   break;
+   }
+
+   return 0;
+}
+
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
const struct connman_session_config *config1 = a;
@@ -1605,6 +1623,8 @@ int __connman_session_create(DBusMessage *msg)
info = session-info;
info_last = session-info_last;
 
+   assign_config_plugin(session);
+
config_get_bool(session, owner, Priority, priority);
config_get_bool(session, owner, EmergencyCall, ecall_app);
config_get_string(session, owner, RoamingPolicy, roaming_policy_str);
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 08/33] session: Update session when plugin is add/removed

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/src/session.c b/src/session.c
index 102b523..61fbd93 100644
--- a/src/session.c
+++ b/src/session.c
@@ -295,6 +295,48 @@ static int assign_config_plugin(struct connman_session 
*session)
return 0;
 }
 
+static void probe_config(struct connman_session_config *config)
+{
+
+   GHashTableIter iter;
+   gpointer key, value;
+   struct connman_session *session;
+
+   DBG(config %p name %s, config, config-name);
+
+   g_hash_table_iter_init(iter, session_hash);
+
+   while (g_hash_table_iter_next(iter, key, value) == TRUE) {
+   session = value;
+
+   if (session-config != NULL)
+   continue;
+
+   assign_config_plugin(session);
+   }
+}
+
+static void remove_config(struct connman_session_config *config)
+{
+   GHashTableIter iter;
+   gpointer key, value;
+   struct connman_session *session;
+
+   DBG(config %p name %s, config, config-name);
+
+   g_hash_table_iter_init(iter, session_hash);
+
+   while (g_hash_table_iter_next(iter, key, value) == TRUE) {
+   session = value;
+
+   if (session-config != config)
+   continue;
+
+   session-config = NULL;
+   assign_config_plugin(session);
+   }
+}
+
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
const struct connman_session_config *config1 = a;
@@ -371,6 +413,9 @@ int connman_session_config_register(struct 
connman_session_config *config)
 
config_list = g_slist_insert_sorted(config_list, config,
compare_priority);
+
+   probe_config(config);
+
return 0;
 }
 
@@ -379,6 +424,8 @@ void connman_session_config_unregister(struct 
connman_session_config *config)
DBG(name %s, config-name);
 
config_list = g_slist_remove(config_list, config);
+
+   remove_config(config);
 }
 
 static void cleanup_bearer_info(gpointer data, gpointer user_data)
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 09/33] session: Remove AvoidHandover documentation

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

The AvoidHandover boolean was there to fine tune the selection
algorithm in ConnMan. It was never implemented. Let's get rid
for the time beeing. If there is a real need for it we should
implemented this setting through the configuration plugin.
---
 doc/session-api.txt | 21 -
 1 file changed, 21 deletions(-)

diff --git a/doc/session-api.txt b/doc/session-api.txt
index df1b4f2..98051a6 100644
--- a/doc/session-api.txt
+++ b/doc/session-api.txt
@@ -144,27 +144,6 @@ Settings   boolean State [readonly]
certain bearers such as Wifi with a fallback to any
other available bearer.
 
-   boolean AvoidHandover [readwrite]
-
-   By default this setting is false. It can be used
-   to indicate that a handover is currently not a good
-   idea. However no connection is guaranteed. So a
-   handover can happen anyway. This is just an indication
-   that the application would like to avoid it right now.
-
-   It is a bad idea to always enable this settings and
-   actually it will be reset after a while to avoid
-   congestion.
-
-   Main use case it is for application that are currently
-   doing a specific tasks that it prefers to finish
-   before allowing handovers again. An example would
-   be synchronization.
-
-   Never the less application needs to be aware that
-   handovers can happen at any time even if this is
-   set to true.
-
string ConnectionType [readwrite]
 
This is used to indicate which connection is requested
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 10/33] session: Remove AvoidHandover implementation

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 30 +-
 1 file changed, 1 insertion(+), 29 deletions(-)

diff --git a/src/session.c b/src/session.c
index 61fbd93..0ebc75c 100644
--- a/src/session.c
+++ b/src/session.c
@@ -90,7 +90,6 @@ struct session_info {
enum connman_session_type type;
connman_bool_t priority;
GSList *allowed_bearers;
-   connman_bool_t avoid_handover;
enum connman_session_roaming_policy roaming_policy;
 
struct service_entry *entry;
@@ -624,14 +623,6 @@ static void append_notify(DBusMessageIter *dict,
info_last-allowed_bearers = info-allowed_bearers;
}
 
-   if (session-append_all == TRUE ||
-   info-avoid_handover != info_last-avoid_handover) {
-   connman_dbus_dict_append_basic(dict, AvoidHandover,
-   DBUS_TYPE_BOOLEAN,
-   info-avoid_handover);
-   info_last-avoid_handover = info-avoid_handover;
-   }
-
session-append_all = FALSE;
 }
 
@@ -673,7 +664,6 @@ static connman_bool_t compute_notifiable_changes(struct 
connman_session *session
return TRUE;
 
if (info-allowed_bearers != info_last-allowed_bearers ||
-   info-avoid_handover != info_last-avoid_handover ||
info-type != info_last-type)
return TRUE;
 
@@ -1453,14 +1443,6 @@ static DBusMessage *change_session(DBusConnection *conn,
goto err;
}
break;
-   case DBUS_TYPE_BOOLEAN:
-   if (g_str_equal(name, AvoidHandover) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-avoid_handover);
-   } else {
-   goto err;
-   }
-   break;
case DBUS_TYPE_STRING:
if (g_str_equal(name, ConnectionType) == TRUE) {
dbus_message_iter_get_basic(value, val);
@@ -1567,7 +1549,7 @@ int __connman_session_create(DBusMessage *msg)
struct session_info *info, *info_last;
 
enum connman_session_type type = CONNMAN_SESSION_TYPE_ANY;
-   connman_bool_t priority, avoid_handover = FALSE;
+   connman_bool_t priority;
connman_bool_t ecall_app;
enum connman_session_roaming_policy roaming_policy;
char *roaming_policy_str;
@@ -1609,14 +1591,6 @@ int __connman_session_create(DBusMessage *msg)
return -EINVAL;
}
break;
-   case DBUS_TYPE_BOOLEAN:
-   if (g_str_equal(key, AvoidHandover) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   avoid_handover);
-   } else {
-   return -EINVAL;
-   }
-   break;
case DBUS_TYPE_STRING:
if (g_str_equal(key, ConnectionType) == TRUE) {
dbus_message_iter_get_basic(value, val);
@@ -1689,7 +1663,6 @@ int __connman_session_create(DBusMessage *msg)
info-state = CONNMAN_SESSION_STATE_DISCONNECTED;
info-type = type;
info-priority = priority;
-   info-avoid_handover = avoid_handover;
info-roaming_policy = roaming_policy;
info-entry = NULL;
 
@@ -1730,7 +1703,6 @@ int __connman_session_create(DBusMessage *msg)
 
info_last-state = info-state;
info_last-priority = info-priority;
-   info_last-avoid_handover = info-avoid_handover;
info_last-roaming_policy = info-roaming_policy;
info_last-entry = info-entry;
info_last-allowed_bearers = info-allowed_bearers;
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 11/33] unit: Update session unit test to API changes

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 unit/session-api.c  | 113 
 unit/test-connman.h |  14 ++-
 2 files changed, 3 insertions(+), 124 deletions(-)

diff --git a/unit/session-api.c b/unit/session-api.c
index 5ed6744..c5df010 100644
--- a/unit/session-api.c
+++ b/unit/session-api.c
@@ -49,42 +49,6 @@ static enum connman_session_state string2type(const char 
*type)
return CONNMAN_SESSION_TYPE_ANY;
 }
 
-static const char *roamingpolicy2string(enum connman_session_roaming_policy 
policy)
-{
-   switch (policy) {
-   case CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN:
-   break;
-   case CONNMAN_SESSION_ROAMING_POLICY_DEFAULT:
-   return default;
-   case CONNMAN_SESSION_ROAMING_POLICY_ALWAYS:
-   return always;
-   case CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN:
-   return forbidden;
-   case CONNMAN_SESSION_ROAMING_POLICY_NATIONAL:
-   return national;
-   case CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL:
-   return international;
-   }
-
-   return ;
-}
-
-static enum connman_session_roaming_policy string2roamingpolicy(const char 
*policy)
-{
-   if (g_strcmp0(policy, default) == 0)
-   return CONNMAN_SESSION_ROAMING_POLICY_DEFAULT;
-   else if (g_strcmp0(policy, always) == 0)
-   return CONNMAN_SESSION_ROAMING_POLICY_ALWAYS;
-   else if (g_strcmp0(policy, forbidden) == 0)
-   return CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN;
-   else if (g_strcmp0(policy, national) == 0)
-   return CONNMAN_SESSION_ROAMING_POLICY_NATIONAL;
-   else if (g_strcmp0(policy, international) == 0)
-   return CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL;
-   else
-   return CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN;
-}
-
 void bearer_info_cleanup(gpointer data, gpointer user_data)
 {
struct test_bearer_info *info = data;
@@ -182,46 +146,6 @@ static DBusMessage *notify_update(DBusConnection *conn,
return __connman_error_invalid_arguments(msg);
}
break;
-   case DBUS_TYPE_BOOLEAN:
-   if (g_str_equal(key, Priority) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-priority);
-
-   } else if (g_str_equal(key, AvoidHandover) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-avoid_handover);
-
-   } else if (g_str_equal(key, StayConnected) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-stay_connected);
-
-   } else if (g_str_equal(key, EmergencyCall) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-ecall);
-
-   } else {
-   g_assert(FALSE);
-   return __connman_error_invalid_arguments(msg);
-   }
-   break;
-   case DBUS_TYPE_UINT32:
-   if (g_str_equal(key, PeriodicConnect) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   
info-periodic_connect);
-
-   } else if (g_str_equal(key, IdleTimeout) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-idle_timeout);
-
-   } else if (g_str_equal(key, SessionMarker) == TRUE) {
-   dbus_message_iter_get_basic(value,
-   info-marker);
-
-   } else {
-   g_assert(FALSE);
-   return __connman_error_invalid_arguments(msg);
-   }
-   break;
case DBUS_TYPE_STRING:
if (g_str_equal(key, State) == TRUE) {
const char *val;
@@ -246,12 +170,6 @@ static DBusMessage *notify_update(DBusConnection *conn,
 
info-name = g_strdup(val);
 
-   } else if (g_str_equal(key, RoamingPolicy) == TRUE) {
-   const char *val;
-   dbus_message_iter_get_basic(value, val);
-   info-roaming_policy =
-   string2roamingpolicy(val);
-
} else if (g_str_equal(key, Interface) == TRUE) {
const char 

[PATCH v1 12/33] session: No need to free NULL list

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/session.c b/src/session.c
index 0ebc75c..1957a21 100644
--- a/src/session.c
+++ b/src/session.c
@@ -480,11 +480,8 @@ static GSList *session_allowed_bearers_any(void)
GSList *list = NULL;
 
info = g_try_new0(struct bearer_info, 1);
-   if (info == NULL) {
-   g_slist_free(list);
-
+   if (info == NULL)
return NULL;
-   }
 
info-name = g_strdup();
info-match_all = TRUE;
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 13/33] session: Rename connman_session_config to connman_session_policy

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 include/session.h| 12 -
 plugins/session_policy.c | 22 
 src/session.c| 66 
 3 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/include/session.h b/include/session.h
index 30e8859..deff0fc 100644
--- a/include/session.h
+++ b/include/session.h
@@ -28,22 +28,22 @@
 extern C {
 #endif
 
-#define CONNMAN_SESSION_CONFIG_PRIORITY_LOW  -100
-#define CONNMAN_SESSION_CONFIG_PRIORITY_DEFAULT 0
-#define CONNMAN_SESSION_CONFIG_PRIORITY_HIGH  100
+#define CONNMAN_SESSION_POLICY_PRIORITY_LOW  -100
+#define CONNMAN_SESSION_POLICY_PRIORITY_DEFAULT 0
+#define CONNMAN_SESSION_POLICY_PRIORITY_HIGH  100
 
 /*
  * The session are identified through the pid is only a temporary solution
  */
-struct connman_session_config {
+struct connman_session_policy {
const char *name;
int priority;
int (*get_bool) (const char *id, const char *key, connman_bool_t *val);
int (*get_string) (const char *id, const char *key, char **val);
 };
 
-int connman_session_config_register(struct connman_session_config *config);
-void connman_session_config_unregister(struct connman_session_config *config);
+int connman_session_policy_register(struct connman_session_policy *config);
+void connman_session_policy_unregister(struct connman_session_policy *config);
 
 int connman_session_update_bool(const char *id, const char *key,
connman_bool_t val);
diff --git a/plugins/session_policy.c b/plugins/session_policy.c
index ca40e8d..acbf154 100644
--- a/plugins/session_policy.c
+++ b/plugins/session_policy.c
@@ -33,7 +33,7 @@
 #include connman/log.h
 #include connman/session.h
 
-static int config_get_bool(const char *id, const char *key, connman_bool_t 
*val)
+static int policy_get_bool(const char *id, const char *key, connman_bool_t 
*val)
 {
DBG(id %s key %s, id, key);
 
@@ -47,7 +47,7 @@ static int config_get_bool(const char *id, const char *key, 
connman_bool_t *val)
return 0;
 }
 
-static int config_get_string(const char *id, const char *key, char **val)
+static int policy_get_string(const char *id, const char *key, char **val)
 {
DBG(id %s key %s, id, key);
 
@@ -59,29 +59,29 @@ static int config_get_string(const char *id, const char 
*key, char **val)
return 0;
 }
 
-static struct connman_session_config session_config = {
+static struct connman_session_policy session_policy = {
.name = session policy configuration,
-   .priority = CONNMAN_SESSION_CONFIG_PRIORITY_LOW,
-   .get_bool = config_get_bool,
-   .get_string = config_get_string,
+   .priority = CONNMAN_SESSION_POLICY_PRIORITY_LOW,
+   .get_bool = policy_get_bool,
+   .get_string = policy_get_string,
 };
 
-static int session_config_init(void)
+static int session_policy_init(void)
 {
int err;
 
-   err = connman_session_config_register(session_config);
+   err = connman_session_policy_register(session_policy);
if (err  0)
return err;
 
return 0;
 }
 
-static void session_config_exit(void)
+static void session_policy_exit(void)
 {
-   connman_session_config_unregister(session_config);
+   connman_session_policy_unregister(session_policy);
 }
 
 CONNMAN_PLUGIN_DEFINE(session_policy, Session policy configuration plugin,
VERSION, CONNMAN_PLUGIN_PRIORITY_DEFAULT,
-   session_config_init, session_config_exit)
+   session_policy_init, session_policy_exit)
diff --git a/src/session.c b/src/session.c
index 1957a21..3b4d4ab 100644
--- a/src/session.c
+++ b/src/session.c
@@ -36,7 +36,7 @@ static DBusConnection *connection;
 static GHashTable *session_hash;
 static connman_bool_t sessionmode;
 static struct connman_session *ecall_session;
-static GSList *config_list;
+static GSList *policy_list;
 
 enum connman_session_trigger {
CONNMAN_SESSION_TRIGGER_UNKNOWN = 0,
@@ -102,7 +102,7 @@ struct connman_session {
char *notify_path;
guint notify_watch;
 
-   struct connman_session_config *config;
+   struct connman_session_policy *policy;
 
connman_bool_t append_all;
struct session_info *info;
@@ -257,91 +257,91 @@ static char *service2bearer(enum connman_service_type 
type)
 static int config_get_bool(struct connman_session *session, const char *id,
const char *key, connman_bool_t *val)
 {
-   if (session-config == NULL) {
+   if (session-policy == NULL) {
*val = FALSE;
return -EINVAL;
}
 
-   return (*session-config-get_bool)(id, key, val);
+   return (*session-policy-get_bool)(id, key, val);
 }
 
 static int config_get_string(struct connman_session *session, const char *id,
const char *key, char **val)
 {
-   if (session-config == 

[PATCH v1 25/33] session: Support no match AllowedBearers

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

Up to now an empty AllowedBearers was interpreted as match any. Let's
make the match all explicit by expecting '*'. If an empty AllowedBearers
is provided, we interpret this as no match. In this case
the application will never get an online notifcation.
---
 src/session.c | 49 +
 1 file changed, 25 insertions(+), 24 deletions(-)

diff --git a/src/session.c b/src/session.c
index 06fe77f..7f73131 100644
--- a/src/session.c
+++ b/src/session.c
@@ -335,14 +335,15 @@ void connman_session_free_bearers(GSList *bearers)
g_slist_free(bearers);
 }
 
-static GSList *session_parse_allowed_bearers(DBusMessageIter *iter)
+static int session_parse_allowed_bearers(DBusMessageIter *iter, GSList **list)
 {
struct connman_session_bearer *bearer;
DBusMessageIter array;
-   GSList *list = NULL;
 
dbus_message_iter_recurse(iter, array);
 
+   *list = NULL;
+
while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_STRING) {
char *bearer_name = NULL;
 
@@ -350,8 +351,9 @@ static GSList 
*session_parse_allowed_bearers(DBusMessageIter *iter)
 
bearer = g_try_new0(struct connman_session_bearer, 1);
if (bearer == NULL) {
-   connman_session_free_bearers(list);
-   return NULL;
+   connman_session_free_bearers(*list);
+   *list = NULL;
+   return -ENOMEM;
}
 
bearer-name = g_strdup(bearer_name);
@@ -364,12 +366,12 @@ static GSList 
*session_parse_allowed_bearers(DBusMessageIter *iter)
bearer-match_all = FALSE;
}
 
-   list = g_slist_append(list, bearer);
+   *list = g_slist_append(*list, bearer);
 
dbus_message_iter_next(array);
}
 
-   return list;
+   return 0;
 }
 
 GSList *connman_session_allowed_bearers_any(void)
@@ -1301,6 +1303,7 @@ static DBusMessage *change_session(DBusConnection *conn,
const char *name;
const char *val;
GSList *allowed_bearers;
+   int err;
 
DBG(session %p, session);
if (dbus_message_iter_init(msg, iter) == FALSE)
@@ -1320,16 +1323,12 @@ static DBusMessage *change_session(DBusConnection *conn,
switch (dbus_message_iter_get_arg_type(value)) {
case DBUS_TYPE_ARRAY:
if (g_str_equal(name, AllowedBearers) == TRUE) {
-   allowed_bearers = session_parse_allowed_bearers(value);
+   err = session_parse_allowed_bearers(value,
+   allowed_bearers);
+   if (err  0)
+   return __connman_error_failed(msg, err);
 

connman_session_free_bearers(info-config.allowed_bearers);
-   if (allowed_bearers == NULL) {
-   allowed_bearers = 
connman_session_allowed_bearers_any();
-
-   if (allowed_bearers == NULL)
-   return __connman_error_failed(msg, 
ENOMEM);
-   }
-
info-config.allowed_bearers = allowed_bearers;
} else {
goto err;
@@ -1440,7 +1439,8 @@ int __connman_session_create(DBusMessage *msg)
struct connman_session *session = NULL;
struct session_info *info, *info_last;
enum connman_session_type type = CONNMAN_SESSION_TYPE_ANY;
-   GSList *allowed_bearers = NULL;
+   GSList *allowed_bearers;
+   connman_bool_t allowed_bearers_valid = FALSE;
int err;
 
owner = dbus_message_get_sender(msg);
@@ -1472,8 +1472,12 @@ int __connman_session_create(DBusMessage *msg)
switch (dbus_message_iter_get_arg_type(value)) {
case DBUS_TYPE_ARRAY:
if (g_str_equal(key, AllowedBearers) == TRUE) {
-   allowed_bearers =
-   session_parse_allowed_bearers(value);
+   err = session_parse_allowed_bearers(value,
+   allowed_bearers);
+   if (err  0)
+   goto err;
+
+   allowed_bearers_valid = TRUE;
} else {
return -EINVAL;
}
@@ -1553,17 +1557,14 @@ int __connman_session_create(DBusMessage *msg)
info-config.roaming_policy = session-policy_config-roaming_policy;
info-entry = NULL;
 
-   if (allowed_bearers == NULL) {
-   info-config.allowed_bearers =
-   connman_session_allowed_bearers_any();
-
-   if 

[PATCH v1 26/33] session: Update ConnnectionType documentation

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 doc/session-api.txt | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/doc/session-api.txt b/doc/session-api.txt
index 98051a6..14ff76b 100644
--- a/doc/session-api.txt
+++ b/doc/session-api.txt
@@ -148,19 +148,27 @@ Settings  boolean State [readonly]
 
This is used to indicate which connection is requested
from the session. The state of the session will be
-   updated accordingly. Values can be nothing, 'local' or
-   'internet'.
+   updated accordingly. Values can be 'local',
+   'internet' or 'any'.
+
'local' means the session requests to be connected,
but does not require specifically to be online.
Therefore State property will be set to 'connected' if
underlying service gets ready and/or online.
+
'online' means the session requests to be connected,
and online. State property will never get 'connected'
but instead will switch to 'online' if underlying
service gets online.
-   No value means the session requests any kind of
-   connection and the state will be updated on all steps,
-   'connected' and 'online'. This is the default value.
+
+   'any' means either 'local' or 'internet'.
+
+   Invalid values will be ignored and removed. An
+   empty ConnectionType is an invalid configuration.
+
+   When a session is created and the provided settings
+   dictionary does not contain ConnectionType, a default
+   session with 'any' will be created.
 
(This setting will be removed when the unique process
identifaction problem is solved.)
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 28/33] session: Apply policy on AllowedBearers

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 103 --
 1 file changed, 100 insertions(+), 3 deletions(-)

diff --git a/src/session.c b/src/session.c
index dad367a..2e6355d 100644
--- a/src/session.c
+++ b/src/session.c
@@ -378,6 +378,90 @@ static int session_parse_allowed_bearers(DBusMessageIter 
*iter, GSList **list)
return 0;
 }
 
+static struct connman_session_bearer *clone_bearer(
+   struct connman_session_bearer *orig)
+{
+   struct connman_session_bearer *bearer;
+
+   bearer = g_try_new0(struct connman_session_bearer, 1);
+   if (bearer == NULL)
+   return NULL;
+
+   bearer-name = g_strdup(orig-name);
+   bearer-match_all = orig-match_all;
+   bearer-service_type = orig-service_type;
+
+   return bearer;
+}
+
+static int filter_bearer(GSList *policy_bearers,
+   struct connman_session_bearer *bearer,
+   GSList **list)
+{
+   struct connman_session_bearer *policy, *tmp;
+   GSList *it;
+
+   if (policy_bearers == NULL)
+   goto clone;
+
+   for (it = policy_bearers; it != NULL; it = it-next) {
+   policy = it-data;
+
+   if (policy-match_all == FALSE 
+   bearer-service_type != policy-service_type)
+   continue;
+
+   goto clone;
+   }
+
+   *list = NULL;
+
+   return 0;
+
+clone:
+   tmp = clone_bearer(bearer);
+   if (tmp == NULL) {
+   connman_session_free_bearers(*list);
+   *list = NULL;
+   return -ENOMEM;
+   }
+   *list = g_slist_append(*list, tmp);
+
+   return 0;
+}
+
+static connman_bool_t is_bearer_valid(struct connman_session_bearer *bearer)
+{
+   if (bearer-match_all == FALSE 
+   bearer-service_type == CONNMAN_SERVICE_TYPE_UNKNOWN)
+   return FALSE;
+
+   return TRUE;
+}
+
+static int apply_policy_on_bearers(GSList *policy_bearers, GSList *bearers,
+   GSList **list)
+{
+   struct connman_session_bearer *bearer;
+   GSList *it;
+   int err;
+
+   *list = NULL;
+
+   for (it = bearers; it != NULL; it = it-next) {
+   bearer = it-data;
+
+   if (is_bearer_valid(bearer) == FALSE)
+   continue;
+
+   err = filter_bearer(policy_bearers, bearer, list);
+   if (err  0)
+   return err;
+   }
+
+   return 0;
+}
+
 GSList *connman_session_allowed_bearers_any(void)
 {
struct connman_session_bearer *bearer;
@@ -1335,7 +1419,14 @@ static DBusMessage *change_session(DBusConnection *conn,
return __connman_error_failed(msg, err);
 

connman_session_free_bearers(info-config.allowed_bearers);
-   info-config.allowed_bearers = allowed_bearers;
+   err = apply_policy_on_bearers(
+   session-policy_config-allowed_bearers,
+   allowed_bearers,
+   info-config.allowed_bearers);
+
+   connman_session_free_bearers(allowed_bearers);
+   if (err  0)
+   return __connman_error_failed(msg, err);
} else {
goto err;
}
@@ -1445,7 +1536,7 @@ int __connman_session_create(DBusMessage *msg)
struct connman_session *session = NULL;
struct session_info *info, *info_last;
enum connman_session_type type;
-   GSList *allowed_bearers;
+   GSList *allowed_bearers = NULL;
connman_bool_t allowed_bearers_valid = FALSE;
connman_bool_t type_valid = FALSE;
int err;
@@ -1574,7 +1665,13 @@ int __connman_session_create(DBusMessage *msg)
goto err;
}
}
-   info-config.allowed_bearers = allowed_bearers;
+
+   err = apply_policy_on_bearers(
+   session-policy_config-allowed_bearers,
+   allowed_bearers,
+   info-config.allowed_bearers);
+   if (err  0)
+   goto err;
 
g_hash_table_replace(session_hash, session-session_path, session);
 
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 27/33] session: Enforce correct ConnectionType settings

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

Up to now an empty or wrong ConnectionType was interpreted as 'any'.
If the ConnectionType is either wrong ignore it. If no ConnectionType
setting is passed in during creation of the session choose 'any'.
---
 include/session.h |  7 ---
 src/session.c | 16 +---
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/session.h b/include/session.h
index 0e47b55..7e45276 100644
--- a/include/session.h
+++ b/include/session.h
@@ -43,9 +43,10 @@ enum connman_session_roaming_policy {
 };
 
 enum connman_session_type {
-   CONNMAN_SESSION_TYPE_ANY  = 0,
-   CONNMAN_SESSION_TYPE_LOCAL= 1,
-   CONNMAN_SESSION_TYPE_INTERNET = 2,
+   CONNMAN_SESSION_TYPE_UNKNOWN  = 0,
+   CONNMAN_SESSION_TYPE_ANY  = 1,
+   CONNMAN_SESSION_TYPE_LOCAL= 2,
+   CONNMAN_SESSION_TYPE_INTERNET = 3,
 };
 
 struct connman_session;
diff --git a/src/session.c b/src/session.c
index 7f73131..dad367a 100644
--- a/src/session.c
+++ b/src/session.c
@@ -147,8 +147,10 @@ static const char *state2string(enum connman_session_state 
state)
 static const char *type2string(enum connman_session_type type)
 {
switch (type) {
-   case CONNMAN_SESSION_TYPE_ANY:
+   case CONNMAN_SESSION_TYPE_UNKNOWN:
return ;
+   case CONNMAN_SESSION_TYPE_ANY:
+   return any;
case CONNMAN_SESSION_TYPE_LOCAL:
return local;
case CONNMAN_SESSION_TYPE_INTERNET:
@@ -160,12 +162,14 @@ static const char *type2string(enum connman_session_type 
type)
 
 static enum connman_session_type string2type(const char *type)
 {
+   if (g_strcmp0(type, any) == 0)
+   return CONNMAN_SESSION_TYPE_ANY;
if (g_strcmp0(type, local) == 0)
return CONNMAN_SESSION_TYPE_LOCAL;
else if (g_strcmp0(type, internet) == 0)
return CONNMAN_SESSION_TYPE_INTERNET;
 
-   return CONNMAN_SESSION_TYPE_ANY;
+   return CONNMAN_SESSION_TYPE_UNKNOWN;
 }
 
 static enum connman_service_type bearer2service(const char *bearer)
@@ -528,6 +532,8 @@ static connman_bool_t is_type_matching_state(enum 
connman_session_state *state,
enum connman_session_type type)
 {
switch (type) {
+   case CONNMAN_SESSION_TYPE_UNKNOWN:
+   return FALSE;
case CONNMAN_SESSION_TYPE_ANY:
return TRUE;
case CONNMAN_SESSION_TYPE_LOCAL:
@@ -1438,9 +1444,10 @@ int __connman_session_create(DBusMessage *msg)
DBusMessageIter iter, array;
struct connman_session *session = NULL;
struct session_info *info, *info_last;
-   enum connman_session_type type = CONNMAN_SESSION_TYPE_ANY;
+   enum connman_session_type type;
GSList *allowed_bearers;
connman_bool_t allowed_bearers_valid = FALSE;
+   connman_bool_t type_valid = FALSE;
int err;
 
owner = dbus_message_get_sender(msg);
@@ -1486,6 +1493,7 @@ int __connman_session_create(DBusMessage *msg)
if (g_str_equal(key, ConnectionType) == TRUE) {
dbus_message_iter_get_basic(value, val);
type = string2type(val);
+   type_valid = TRUE;
} else {
return -EINVAL;
}
@@ -1552,6 +1560,8 @@ int __connman_session_create(DBusMessage *msg)
ecall_session = session;
 
info-state = CONNMAN_SESSION_STATE_DISCONNECTED;
+   if (type_valid == FALSE)
+   type = CONNMAN_SESSION_TYPE_ANY;
info-config.type = type;
info-config.priority = session-policy_config-priority;
info-config.roaming_policy = session-policy_config-roaming_policy;
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 29/33] session: Update AllowedBearers documentation

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 doc/session-api.txt | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/doc/session-api.txt b/doc/session-api.txt
index 14ff76b..aab7a9a 100644
--- a/doc/session-api.txt
+++ b/doc/session-api.txt
@@ -141,9 +141,18 @@ Settings   boolean State [readonly]
entries in this list.
 
Also * matches any bearer. This is usefull to prefer
-   certain bearers such as Wifi with a fallback to any
+   certain bearers such as 'wifi' with a fallback to any
other available bearer.
 
+   Invalid bearer names will be ignored and removed
+   from the list. And empty AllowedBearers will
+   not match to any bearer, therefore the session
+   will never go online.
+
+   When a session is created and the provided settings
+   dictionary does not contain AllowedBearers, a default
+   session with * will be created.
+
string ConnectionType [readwrite]
 
This is used to indicate which connection is requested
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 30/33] unit: Do not append empty AllowedBearers dictionary

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

An empty AllowedBearers means do not match anything.
---
 unit/session-api.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/unit/session-api.c b/unit/session-api.c
index c5df010..980366f 100644
--- a/unit/session-api.c
+++ b/unit/session-api.c
@@ -252,6 +252,9 @@ static void append_allowed_bearers(DBusMessageIter *iter, 
void *user_data)
 void session_append_settings(DBusMessageIter *dict,
struct test_session_info *info)
 {
+   if (info-allowed_bearers == NULL)
+   return;
+
connman_dbus_dict_append_array(dict, AllowedBearers,
DBUS_TYPE_STRING,
append_allowed_bearers,
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 31/33] unit: Support ConnectionType unknown

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 unit/session-api.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/unit/session-api.c b/unit/session-api.c
index 980366f..e82199d 100644
--- a/unit/session-api.c
+++ b/unit/session-api.c
@@ -41,12 +41,14 @@ static enum connman_session_state string2state(const char 
*state)
 
 static enum connman_session_state string2type(const char *type)
 {
+   if (g_strcmp0(type, any) == 0)
+   return CONNMAN_SESSION_TYPE_ANY;
if (g_strcmp0(type, local) == 0)
return CONNMAN_SESSION_TYPE_LOCAL;
if (g_strcmp0(type, internet) == 0)
return CONNMAN_SESSION_TYPE_INTERNET;
 
-   return CONNMAN_SESSION_TYPE_ANY;
+   return CONNMAN_SESSION_TYPE_UNKNOWN;
 }
 
 void bearer_info_cleanup(gpointer data, gpointer user_data)
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 32/33] session: Apply policy on ConnnectionType

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

---
 src/session.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/session.c b/src/session.c
index 2e6355d..8930a0a 100644
--- a/src/session.c
+++ b/src/session.c
@@ -325,6 +325,22 @@ void connman_session_policy_unregister(struct 
connman_session_policy *policy)
remove_policy(policy);
 }
 
+static enum connman_session_type apply_policy_on_type(
+   enum connman_session_type policy,
+   enum connman_session_type type)
+{
+   if (type == CONNMAN_SESSION_TYPE_UNKNOWN)
+   return CONNMAN_SESSION_TYPE_UNKNOWN;
+
+   if (policy == CONNMAN_SESSION_TYPE_ANY)
+   return type;
+
+   if (policy == CONNMAN_SESSION_TYPE_LOCAL)
+   return CONNMAN_SESSION_TYPE_LOCAL;
+
+   return CONNMAN_SESSION_TYPE_INTERNET;
+}
+
 static void cleanup_bearer(gpointer data, gpointer user_data)
 {
struct connman_session_bearer *bearer = data;
@@ -1434,7 +1450,9 @@ static DBusMessage *change_session(DBusConnection *conn,
case DBUS_TYPE_STRING:
if (g_str_equal(name, ConnectionType) == TRUE) {
dbus_message_iter_get_basic(value, val);
-   info-config.type = string2type(val);
+   info-config.type = apply_policy_on_type(
+   session-policy_config-type,
+   string2type(val));
} else {
goto err;
}
@@ -1653,7 +1671,9 @@ int __connman_session_create(DBusMessage *msg)
info-state = CONNMAN_SESSION_STATE_DISCONNECTED;
if (type_valid == FALSE)
type = CONNMAN_SESSION_TYPE_ANY;
-   info-config.type = type;
+   info-config.type = apply_policy_on_type(
+   session-policy_config-type,
+   type);
info-config.priority = session-policy_config-priority;
info-config.roaming_policy = session-policy_config-roaming_policy;
info-entry = NULL;
-- 
1.7.12.315.g682ce8b

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


[PATCH v1 33/33] session: Update sessions on config updates

2012-09-20 Thread Daniel Wagner
From: Daniel Wagner daniel.wag...@bmw-carit.de

Give the policy plugin a way to inform the session core that
some of the config values have changed.

This could be done in a more clever way, e.g. figure out only
to update the necessary info entries.

It is not expected that there are many updates so let's keep it
simple for the time beeing.
---
 include/session.h |  2 ++
 src/session.c | 37 +
 2 files changed, 39 insertions(+)

diff --git a/include/session.h b/include/session.h
index 7e45276..0e3d4c1 100644
--- a/include/session.h
+++ b/include/session.h
@@ -79,6 +79,8 @@ struct connman_session_policy {
 int connman_session_policy_register(struct connman_session_policy *config);
 void connman_session_policy_unregister(struct connman_session_policy *config);
 
+void connman_session_config_update(struct connman_session *session);
+
 GSList *connman_session_allowed_bearers_any(void);
 void connman_session_free_bearers(GSList *bearers);
 
diff --git a/src/session.c b/src/session.c
index 8930a0a..8fdaa8b 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1362,6 +1362,43 @@ static void session_changed(struct connman_session 
*session,
session_notify(session);
 }
 
+void connman_session_config_update(struct connman_session *session)
+{
+   struct session_info *info = session-info;
+   GSList *allowed_bearers;
+   int err;
+
+   DBG(session %p, session);
+
+   /*
+* We update all configuration even though only one entry
+* might have changed. We can still optimize this later.
+*/
+
+   err = apply_policy_on_bearers(
+   session-policy_config-allowed_bearers,
+   info-config.allowed_bearers,
+   allowed_bearers);
+   if (err  0)
+   return;
+   connman_session_free_bearers(info-config.allowed_bearers);
+   info-config.allowed_bearers = allowed_bearers;
+
+   info-config.type = apply_policy_on_type(
+   session-policy_config-type,
+   info-config.type);
+
+   info-config.roaming_policy = session-policy_config-roaming_policy;
+
+   info-config.ecall = session-policy_config-ecall;
+   if (info-config.ecall == TRUE)
+   ecall_session = session;
+
+   info-config.priority = session-policy_config-priority;
+
+   session_changed(session, CONNMAN_SESSION_TRIGGER_SETTING);
+}
+
 static DBusMessage *connect_session(DBusConnection *conn,
DBusMessage *msg, void *user_data)
 {
-- 
1.7.12.315.g682ce8b

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


Re: no wifi services

2012-09-20 Thread Felipe Tonello
Hi Jeff,

Sorry for the duplicated message.

On Wed, Sep 19, 2012 at 5:46 PM, Zheng, Jeff jeff.zh...@intel.com wrote:

 Hi Felipe,


RX bytes:5721 (5.5 KiB)  TX bytes:7348 (7.1 KiB) root@g2:/#
  /usr/lib/connman/test/test-connman enable wifi root@g2:/#
  /usr/lib/connman/test/test-connman services root@g2:/#
  /usr/lib/connman/test/test-connman state System is idle root@g2:/#
  /usr/lib/connman/test/test-manager


 Could you please kill wpa_supplicant and restart connmand, run
 test-connman enable wifi and check if wpa_supplicant is running.
 Then you will get service list by test-connman services


Still not working.

Isn't there is any other configuration that I'm missing? Maybe in
compile-time.

Thanks

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


[PATCH] client: Fix AutoConnect configuration

2012-09-20 Thread Justin Maggard
Changing the AutoConnect setting via connmanctl does not work, due to the
mistaken use of || instead of .
This patch fixes the issue, and tries to make things a little more readable.
---
 client/commands.c |   20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/client/commands.c b/client/commands.c
index 0caacd9..22d5b3c 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -134,16 +134,20 @@ int config_switch(int argc, char *argv[], int c, 
DBusConnection *conn)
 
switch (c) {
case 'a':
-   if (*optarg != 'y' || *optarg != 'n' || *optarg != '1' ||
-   *optarg != '0' || *optarg != 't' ||
-   *optarg != 'f')
-   return -EINVAL;
-   if (*optarg == 'y' || *optarg == '1' ||
-   *optarg == 't')
+   switch (*optarg) {
+   case 'y':
+   case '1':
+   case 't':
val = TRUE;
-   else if (*optarg == 'n' || *optarg == '0' ||
-   *optarg == 'f')
+   break;
+   case 'n':
+   case '0':
+   case 'f':
val = FALSE;
+   break;
+   default:
+   return -EINVAL;
+   }
error = set_service_property(conn, message, argv[1],
AutoConnect, NULL,
val, 0);
-- 
1.7.9.5

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


Re: [PATCH] client: Fix AutoConnect configuration

2012-09-20 Thread Kok, Auke-jan H
On Thu, Sep 20, 2012 at 4:12 PM, Justin Maggard jmaggar...@gmail.com wrote:
 Changing the AutoConnect setting via connmanctl does not work, due to the
 mistaken use of || instead of .
 This patch fixes the issue, and tries to make things a little more readable.
 ---
  client/commands.c |   20 
  1 file changed, 12 insertions(+), 8 deletions(-)

 diff --git a/client/commands.c b/client/commands.c
 index 0caacd9..22d5b3c 100644
 --- a/client/commands.c
 +++ b/client/commands.c
 @@ -134,16 +134,20 @@ int config_switch(int argc, char *argv[], int c, 
 DBusConnection *conn)

 switch (c) {
 case 'a':
 -   if (*optarg != 'y' || *optarg != 'n' || *optarg != '1' ||
 -   *optarg != '0' || *optarg != 't' ||
 -   *optarg != 'f')
 -   return -EINVAL;
 -   if (*optarg == 'y' || *optarg == '1' ||
 -   *optarg == 't')
 +   switch (*optarg) {
 +   case 'y':
 +   case '1':
 +   case 't':
 val = TRUE;
 -   else if (*optarg == 'n' || *optarg == '0' ||
 -   *optarg == 'f')
 +   break;
 +   case 'n':
 +   case '0':
 +   case 'f':
 val = FALSE;
 +   break;
 +   default:
 +   return -EINVAL;
 +   }
 error = set_service_property(conn, message, argv[1],
 AutoConnect, NULL,
 val, 0);
 --
 1.7.9.5

Thanks, that indeed looks a lot better.


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


Re: no wifi services

2012-09-20 Thread Felipe Tonello
I made it work now, I just ignored with -I eth0. But there is still a
problem: the ./test-connman scan wifi is not working and when I want to
list the services, it's always empty.

Then when I do a iwlist wlan0 scan, the services are listed successfully.

Is it correct the procedure? enable, scan and connect?

Thanks in advance,
Felipe
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


RE: no wifi services

2012-09-20 Thread Zheng, Jeff
Hi Felipe

 
 I made it work now, I just ignored with -I eth0. But there is still a
 problem: the ./test-connman scan wifi is not working and when I want to list
 the services, it's always empty.
 
 Then when I do a iwlist wlan0 scan, the services are listed successfully.

I saw same issue on one of my test machine. See 
http://bugs.meego.com/show_bug.cgi?id=25307

So you don't need -I eth0, just iwlist wlan0 scan.

Could you please submit an new bug?

 
 Is it correct the procedure? enable, scan and connect?

Yes. Enable, scan and connect through test-connman.

 
 Thanks in advance,
 Felipe
 ___
 connman mailing list
 connman@connman.net
 http://lists.connman.net/listinfo/connman
___
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman


Re: [PATCH 0/5] Remove wispr reference counting

2012-09-20 Thread Gustavo Padovan
HI Patrik,

* patrik.fl...@linux.intel.com patrik.fl...@linux.intel.com [2012-09-07 
15:00:33 +0300]:

 From: Patrik Flykt patrik.fl...@linux.intel.com
 
   Hi,
 
 Here is a patch set removing reference counting in wispr.c. Turns out
 that no reference counting is needed since all asynchronous calls can be
 cancelled.
 
 Patch 01 cleans up reference counting related to g_web and patch 02 does the
 same for the Agent API calls. When this is done, the wispr portal context
 reference count is always 1 and the service usage reset doesn't need a
 specific function anymore. The function is removed in patch 03. Since
 wispr_portal_context_ref() isn't used anymore either, it is removed in
 patch 04. Finally all calls to wispr_portal_context_unref() can be converted
 to free_connman_wispr_portal_context() in patch 05, as the reference count is
 always 1 and any unref encountered would remove the structure.
 
 This patch set needs the functionality present in the previous Fixes for
 various wispr issues patch set.

This patch set fixes the crash I had in the gresolv.c, the failure was related
to the refcounting code in the wisprc code. (http://pastebin.com/5wKtKGEg)

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