[PATCH] atmodem: check the Packet Domain service state before attaching

2012-06-04 Thread Philippe Nunes
---
 drivers/atmodem/gprs.c |   66 +---
 1 file changed, 62 insertions(+), 4 deletions(-)

diff --git a/drivers/atmodem/gprs.c b/drivers/atmodem/gprs.c
index 65a8b7b..3be0a9d 100644
--- a/drivers/atmodem/gprs.c
+++ b/drivers/atmodem/gprs.c
@@ -44,6 +44,7 @@
 
 static const char *cgreg_prefix[] = { "+CGREG:", NULL };
 static const char *cgdcont_prefix[] = { "+CGDCONT:", NULL };
+static const char *cgatt_prefix[] = { "+CGATT:", NULL };
 static const char *none_prefix[] = { NULL };
 
 struct gprs_data {
@@ -62,17 +63,74 @@ static void at_cgatt_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
cb(&error, cbd->data);
 }
 
+static void at_cgatt_query_cb(gboolean ok, GAtResult *result,
+   gpointer user_data)
+{
+   struct cb_data *cbd = user_data;
+   ofono_gprs_cb_t cb = cbd->cb;
+   struct gprs_data *gd = cbd->user;
+   struct ofono_error error;
+   GAtResultIter iter;
+   int state;
+
+   decode_at_error(&error, g_at_result_final_response(result));
+
+   if (!ok) {
+   cb(&error, cbd->data);
+   g_free(cbd);
+   return;
+   }
+
+   g_at_result_iter_init(&iter, result);
+
+   if (!g_at_result_iter_next(&iter, "+CGATT:")) {
+   CALLBACK_WITH_FAILURE(cb, cbd->data);
+   g_free(cbd);
+   return;
+   }
+
+   g_at_result_iter_next_number(&iter, &state);
+
+   switch (state) {
+   case 0:
+   if (g_at_chat_send(gd->chat, "AT+CGATT=1", none_prefix,
+   at_cgatt_cb, cbd, g_free) > 0)
+   return;
+
+   CALLBACK_WITH_FAILURE(cb, cbd->data);
+   break;
+   case 1:
+   CALLBACK_WITH_SUCCESS(cb, cbd->data);
+   break;
+   }
+
+   g_free(cbd);
+}
+
 static void at_gprs_set_attached(struct ofono_gprs *gprs, int attached,
ofono_gprs_cb_t cb, void *data)
 {
struct gprs_data *gd = ofono_gprs_get_data(gprs);
struct cb_data *cbd = cb_data_new(cb, data);
-   char buf[64];
 
-   snprintf(buf, sizeof(buf), "AT+CGATT=%i", attached ? 1 : 0);
+   cbd->user = gd;
 
-   if (g_at_chat_send(gd->chat, buf, none_prefix,
-   at_cgatt_cb, cbd, g_free) > 0)
+   /*
+* Before attaching, check the current state.
+* If we are already attached to the packet domain service, it means
+* that the attachment is done automatically at power on.
+* If we send again the command +CGATT, this command should be ignored
+* by the modem but some of them are initiating a complete new
+* attachment procedure resulting in a preliminary IMSI/P-TMSI detach.
+* To prevent such bad behavior, the command +CGATT is not sent if the
+* modem is already in the requested state.
+*/
+   if (attached == TRUE) {
+   if (g_at_chat_send(gd->chat, "AT+CGATT?", cgatt_prefix,
+   at_cgatt_query_cb, cbd, NULL) > 0)
+   return;
+   } else if (g_at_chat_send(gd->chat, "AT+CGATT=0", none_prefix,
+   at_cgatt_cb, cbd, g_free) > 0)
return;
 
g_free(cbd);
-- 
1.7.9.5

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


Re: [PATCH v0 3/3] dundee: Ignore DUN device if PAN is present

2012-06-04 Thread Daniel Wagner
On 04.06.2012 16:11, Daniel Wagner wrote:
> From: Daniel Wagner 
> 
> ---
>  dundee/bluetooth.c |9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
> index 5a913cc..8762f51 100644
> --- a/dundee/bluetooth.c
> +++ b/dundee/bluetooth.c
> @@ -141,6 +141,15 @@ static int bt_probe(GSList *uuids, const char *path, 
> const char *dev_addr,
>  
>   DBG("");
>  
> + for (; uuids; uuids = uuids->next) {
> + const char *uuid = uuids->data;
> +
> + if (g_strcmp0(uuid, NAP_UUID) == 0) {
> + ofono_info("Device %s supports DUN and PAN at the same 
> time. DUN is ignored", path);

argh, this line is a bit too long...
___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v0 3/3] dundee: Ignore DUN device if PAN is present

2012-06-04 Thread Daniel Wagner
From: Daniel Wagner 

---
 dundee/bluetooth.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
index 5a913cc..8762f51 100644
--- a/dundee/bluetooth.c
+++ b/dundee/bluetooth.c
@@ -141,6 +141,15 @@ static int bt_probe(GSList *uuids, const char *path, const 
char *dev_addr,
 
DBG("");
 
+   for (; uuids; uuids = uuids->next) {
+   const char *uuid = uuids->data;
+
+   if (g_strcmp0(uuid, NAP_UUID) == 0) {
+   ofono_info("Device %s supports DUN and PAN at the same 
time. DUN is ignored", path);
+   return -EUNATCH;
+   }
+   }
+
/* We already have this device in our hash, ignore */
if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
return -EALREADY;
-- 
1.7.10.130.g36e6c

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v0 2/3] bluetooth: Add PAN UUID

2012-06-04 Thread Daniel Wagner
From: Daniel Wagner 

---
 plugins/bluetooth.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index c06abf7..e801bfc 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -32,6 +32,7 @@
 #define DBUS_TIMEOUT 15
 
 #define DUN_GW_UUID"1103--1000-8000-00805f9b34fb"
+#define NAP_UUID   "1116--1000-8000-00805f9b34fb"
 #define HFP_AG_UUID"111f--1000-8000-00805f9b34fb"
 #define HFP_HS_UUID"111e--1000-8000-00805f9b34fb"
 #define SAP_UUID   "112d--1000-8000-00805f9b34fb"
-- 
1.7.10.130.g36e6c

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v0 1/3] bluetooth: Add list of UUIDs to probe function

2012-06-04 Thread Daniel Wagner
From: Daniel Wagner 

---
 dundee/bluetooth.c  |2 +-
 plugins/bluetooth.c |8 +---
 plugins/bluetooth.h |2 +-
 plugins/hfp_hf.c|2 +-
 plugins/sap.c   |2 +-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
index e2e2bca..5a913cc 100644
--- a/dundee/bluetooth.c
+++ b/dundee/bluetooth.c
@@ -132,7 +132,7 @@ struct dundee_device_driver bluetooth_driver = {
.disconnect = bt_disconnect,
 };
 
-static int bt_probe(const char *path, const char *dev_addr,
+static int bt_probe(GSList *uuids, const char *path, const char *dev_addr,
const char *adapter_addr, const char *alias)
 {
struct bluetooth_device *bt;
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index dbf79eb..0be6000 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -265,16 +265,18 @@ static void bluetooth_probe(GSList *uuids, const char 
*path,
const char *device, const char *adapter,
const char *alias)
 {
-   for (; uuids; uuids = uuids->next) {
+   GSList *l;
+
+   for (l = uuids; l; l = l->next) {
struct bluetooth_profile *driver;
-   const char *uuid = uuids->data;
+   const char *uuid = l->data;
int err;
 
driver = g_hash_table_lookup(uuid_hash, uuid);
if (driver == NULL)
continue;
 
-   err = driver->probe(path, device, adapter, alias);
+   err = driver->probe(uuids, path, device, adapter, alias);
if (err == 0)
continue;
 
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 4fc16ad..c06abf7 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -38,7 +38,7 @@
 
 struct bluetooth_profile {
const char *name;
-   int (*probe)(const char *device, const char *dev_addr,
+   int (*probe)(GSList *uuids, const char *device, const char *dev_addr,
const char *adapter_addr, const char *alias);
void (*remove)(const char *prefix);
void (*set_alias)(const char *device, const char *);
diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 7c500e3..74780b7 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -206,7 +206,7 @@ static const GDBusMethodTable agent_methods[] = {
{ }
 };
 
-static int hfp_hf_probe(const char *device, const char *dev_addr,
+static int hfp_hf_probe(GSList *uuids, const char *device, const char 
*dev_addr,
const char *adapter_addr, const char *alias)
 {
struct ofono_modem *modem;
diff --git a/plugins/sap.c b/plugins/sap.c
index d893bc1..7f728f9 100644
--- a/plugins/sap.c
+++ b/plugins/sap.c
@@ -235,7 +235,7 @@ static void sap_post_online(struct ofono_modem *modem)
data->sap_driver->post_online(data->hw_modem);
 }
 
-static int bluetooth_sap_probe(const char *device, const char *dev_addr,
+static int bluetooth_sap_probe(GSList *uuds, const char *device, const char 
*dev_addr,
const char *adapter_addr, const char *alias)
 {
struct ofono_modem *modem;
-- 
1.7.10.130.g36e6c

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono


[PATCH v0 0/3] Prefer PAN over DUN

2012-06-04 Thread Daniel Wagner
From: Daniel Wagner 

Hi,

So here is the first oFono version for the "prefer pan over dun"
feature. Since this is a policy thing, it makes sense to place this
inside dundee and not inside ConnMan or BlueZ.

I am not really happy to pass in the UUIDs but I found it a lot nicer
than adding a 'filter' callback to struct bluetooth_profile. 

Another idea how to implement it I had was, adding a blacklist when
registering the profile.

Let's start with the simplest possible solution.

cheers,
daniel

Daniel Wagner (3):
  bluetooth: Add list of UUIDs to probe function
  bluetooth: Add PAN UUID
  dundee: Ignore DUN device if PAN is present

 dundee/bluetooth.c  |   11 ++-
 plugins/bluetooth.c |8 +---
 plugins/bluetooth.h |3 ++-
 plugins/hfp_hf.c|2 +-
 plugins/sap.c   |2 +-
 5 files changed, 19 insertions(+), 7 deletions(-)

-- 
1.7.10.130.g36e6c

___
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono