Re: Telit HE910 modem --- unable be put on line by Connman

2012-12-03 Thread Daniel Wagner

Hi Mingli,


On 30.11.2012 16:40, Ming Li Wu wrote:

Hello,

I am working on Telit HE910 modem.

I am using ofono 1.11, and the commit is
6e3a6156b34c52bde253b097976d0ba9dd575879.

For the Telit modem, AT+CFUN=4 is used to enable
the modem. According to Telit He910 AT Commands
Reference Guide, issuing AT+CFUN=4[,0] actually
causes the module to perform either a network
deregistration and a SIM deactivation.


Is rfkill enabled?

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


Re: Telit HE910 modem --- unable be put on line by Connman

2012-12-03 Thread Christopher Vogl

Hi Mingli,

On 30/11/12 16:40, Ming Li Wu wrote:

Hello,

I am working on Telit HE910 modem.

I am using ofono 1.11, and the commit is
6e3a6156b34c52bde253b097976d0ba9dd575879.

For the Telit modem, AT+CFUN=4 is used to enable
the modem. According to Telit He910 AT Commands
Reference Guide, issuing AT+CFUN=4[,0] actually
causes the module to perform either a network
deregistration and a SIM deactivation.

After this command is sent out, an unsolicited indication
\r\n#QSS: 0\r\n is received by of ofono. This means that
the sim card cannot be detected by the modem. It turns out
that Connman will not put the modem on line.

if AT+CFUN=5 was used, it worked fine.

My questions are:
1. Why is AT+CFUN=4 used to enable the modem, instead of AT+CFUN=1 
or AT+CFUN=5?
2. If AT+CFUN=4 is reasonable, are there any solutions to solve this 
problem?


Thanks!

Mingli


The following is the log  when AT+CFUN=4 was used.
ofonod[358]: plugins/udevng.c:setup_telit() modem=/dev/ttyACM0 
aux=/dev/ttyACM3 gps=(null) diag=/dev/ttyACM1
ofonod[358]: src/modem.c:set_modem_property() modem 0x1152008 property 
Modem
ofonod[358]: src/modem.c:set_modem_property() modem 0x1152008 property 
Aux
ofonod[358]: src/modem.c:set_modem_property() modem 0x1152008 property 
Diag

ofonod[358]: src/modem.c:ofono_modem_register() 0x1152008
ofonod[358]: plugins/telit.c:telit_probe() 0x1152008
ofonod[358]: src/modem.c:emit_modem_added() 0x1152008
ofonod[358]: src/modem.c:call_modemwatches() 0x1152008 added:1
ofonod[358]: plugins/hfp_ag.c:modem_watch() modem: 0x1152008, added: 1
ofonod[358]: plugins/dun_gw.c:modem_watch() modem: 0x1152008, added: 1
ofonod[358]: plugins/smart-messaging.c:modem_watch() modem: 0x1152008, 
added: 1
ofonod[358]: plugins/push-notification.c:modem_watch() modem: 
0x1152008, added: 1

ofonod[358]: plugins/telit.c:telit_enable() 0x1152008
ofonod[358]: src/modem.c:get_modem_property() modem 0x1152008 property 
Modem

ofonod[358]: plugins/telit.c:open_device() Modem /dev/ttyACM0
ofonod[358]: src/modem.c:get_modem_property() modem 0x1152008 property 
Aux

ofonod[358]: plugins/telit.c:open_device() Aux /dev/ttyACM3
ofonod[358]: Aux:  ATE0 +CMEE=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT#QSS=0\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CFUN=4\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: plugins/telit.c:cfun_enable_cb() 0x1152008
ofonod[358]: src/modem.c:modem_change_state() old state: 0, new state: 1
ofonod[358]: plugins/telit.c:telit_pre_sim() 0x1152008
ofonod[358]: Aux:  ATC0\r
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+GCAP\r
ofonod[358]: Aux:  \r\n+GCAP: +CGSM,+DS,+FCLASS,+MS,+ES\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CRC=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CLIP=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CDIP=1\r
ofonod[358]: Aux:  \r\nERROR\r\n
ofonod[358]: Aux:  AT+CNAP=1\r
ofonod[358]: Aux:  \r\nERROR\r\n
ofonod[358]: Aux:  AT+COLP=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CSSN=1,1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+VTD?\r
ofonod[358]: Aux:  \r\n0\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CCWA=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: drivers/atmodem/voicecall.c:at_voicecall_initialized() 
voicecall_init: registering to notifications

ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: Aux:  AT#AUTOATT=0\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT#QSS=2\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CGMI\r
ofonod[358]: Aux:  \r\nTelit\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CLCC\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CGMM\r
ofonod[358]: Aux:  \r\nHE910\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CGMR\r
ofonod[358]: Aux:  \r\n12.00.003\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CGSN\r
ofonod[358]: Aux:  \r\n357164040533674\r\n\r\nOK\r\n
ofonod[358]: Aux:  \r\n#QSS: 0\r\n
ofonod[358]: plugins/telit.c:telit_qss_notify() 0x1152008
ofonod[358]: plugins/telit.c:switch_sim_state_status() 0x1152008, SIM 
status: 0





AT+CFUN=1 is used to set the modem online, i.e. enable RX, TX it also 
enables the SIM. AT+CFUN = 4 is used to set the modem in flight mode.
I cannot see that the modem is set online in your debug output, i.e. a 
D-Bus call to org.ofono.Modem.SetProperty('Online', true) is made.
Without this call you will never get an URC of #QSS with a value greater 
than 0. SIM detection is enabled after AT+CFUN=1.
I never worked with ConnMan so I don't know what causes ConnMan to set 
the modem online.


Try to issue
dbus-send --system --type=method_call --print-reply --dest=org.ofono 
/telit_0 org.ofono.Modem.SetProperty string:'Online' variant:boolean:'true'

and see what happens (you may need to change /telit_0 to what
dbus-send --system --type=method_call --print-reply --dest=org.ofono / 
org.ofono.Manager.GetModems


Re: Telit HE910 modem --- unable be put on line by Connman

2012-12-03 Thread Ming Li Wu

Hi Daniel,

Thanks for your reply.

I am using an arm development board in which ofono is running.
rfkill is not installed. should I install it?

Thanks!

Mingli

On 12/03/2012 09:32 AM, Daniel Wagner wrote:

Hi Mingli,


On 30.11.2012 16:40, Ming Li Wu wrote:

Hello,

I am working on Telit HE910 modem.

I am using ofono 1.11, and the commit is
6e3a6156b34c52bde253b097976d0ba9dd575879.

For the Telit modem, AT+CFUN=4 is used to enable
the modem. According to Telit He910 AT Commands
Reference Guide, issuing AT+CFUN=4[,0] actually
causes the module to perform either a network
deregistration and a SIM deactivation.


Is rfkill enabled?

cheers,
daniel



--
Mingli Wu   South Pole AB
Phone:  +46 8 56237100  Anderstorpsvägen 16
Mobile: +46 73 7628460  SE - 171 54 Solna
e-mail: min...@southpole.se  www.southpole.se

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


Re: Telit HE910 modem --- unable be put on line by Connman

2012-12-03 Thread Jonas Bonn

On 12/03/2012 10:55 AM, Christopher Vogl wrote:

Hi Mingli,

On 30/11/12 16:40, Ming Li Wu wrote:

Hello,

I am working on Telit HE910 modem.

I am using ofono 1.11, and the commit is
6e3a6156b34c52bde253b097976d0ba9dd575879.

For the Telit modem, AT+CFUN=4 is used to enable
the modem. According to Telit He910 AT Commands
Reference Guide, issuing AT+CFUN=4[,0] actually
causes the module to perform either a network
deregistration and a SIM deactivation.

After this command is sent out, an unsolicited indication
\r\n#QSS: 0\r\n is received by of ofono. This means that
the sim card cannot be detected by the modem. It turns out
that Connman will not put the modem on line.

if AT+CFUN=5 was used, it worked fine.

My questions are:
1. Why is AT+CFUN=4 used to enable the modem, instead of AT+CFUN=1
or AT+CFUN=5?
2. If AT+CFUN=4 is reasonable, are there any solutions to solve this
problem?

Thanks!

Mingli


The following is the log  when AT+CFUN=4 was used.
ofonod[358]: plugins/udevng.c:setup_telit() modem=/dev/ttyACM0
aux=/dev/ttyACM3 gps=(null) diag=/dev/ttyACM1
ofonod[358]: src/modem.c:set_modem_property() modem 0x1152008 property
Modem
ofonod[358]: src/modem.c:set_modem_property() modem 0x1152008 property
Aux
ofonod[358]: src/modem.c:set_modem_property() modem 0x1152008 property
Diag
ofonod[358]: src/modem.c:ofono_modem_register() 0x1152008
ofonod[358]: plugins/telit.c:telit_probe() 0x1152008
ofonod[358]: src/modem.c:emit_modem_added() 0x1152008
ofonod[358]: src/modem.c:call_modemwatches() 0x1152008 added:1
ofonod[358]: plugins/hfp_ag.c:modem_watch() modem: 0x1152008, added: 1
ofonod[358]: plugins/dun_gw.c:modem_watch() modem: 0x1152008, added: 1
ofonod[358]: plugins/smart-messaging.c:modem_watch() modem: 0x1152008,
added: 1
ofonod[358]: plugins/push-notification.c:modem_watch() modem:
0x1152008, added: 1
ofonod[358]: plugins/telit.c:telit_enable() 0x1152008
ofonod[358]: src/modem.c:get_modem_property() modem 0x1152008 property
Modem
ofonod[358]: plugins/telit.c:open_device() Modem /dev/ttyACM0
ofonod[358]: src/modem.c:get_modem_property() modem 0x1152008 property
Aux
ofonod[358]: plugins/telit.c:open_device() Aux /dev/ttyACM3
ofonod[358]: Aux:  ATE0 +CMEE=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT#QSS=0\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CFUN=4\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: plugins/telit.c:cfun_enable_cb() 0x1152008
ofonod[358]: src/modem.c:modem_change_state() old state: 0, new state: 1
ofonod[358]: plugins/telit.c:telit_pre_sim() 0x1152008
ofonod[358]: Aux:  ATC0\r
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+GCAP\r
ofonod[358]: Aux:  \r\n+GCAP: +CGSM,+DS,+FCLASS,+MS,+ES\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CRC=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CLIP=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CDIP=1\r
ofonod[358]: Aux:  \r\nERROR\r\n
ofonod[358]: Aux:  AT+CNAP=1\r
ofonod[358]: Aux:  \r\nERROR\r\n
ofonod[358]: Aux:  AT+COLP=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CSSN=1,1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+VTD?\r
ofonod[358]: Aux:  \r\n0\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CCWA=1\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: drivers/atmodem/voicecall.c:at_voicecall_initialized()
voicecall_init: registering to notifications
ofonod[358]: src/sim.c:ofono_sim_add_state_watch() 0x1153d30
ofonod[358]: Aux:  AT#AUTOATT=0\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT#QSS=2\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CGMI\r
ofonod[358]: Aux:  \r\nTelit\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CLCC\r
ofonod[358]: Aux:  \r\nOK\r\n
ofonod[358]: Aux:  AT+CGMM\r
ofonod[358]: Aux:  \r\nHE910\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CGMR\r
ofonod[358]: Aux:  \r\n12.00.003\r\n\r\nOK\r\n
ofonod[358]: Aux:  AT+CGSN\r
ofonod[358]: Aux:  \r\n357164040533674\r\n\r\nOK\r\n
ofonod[358]: Aux:  \r\n#QSS: 0\r\n
ofonod[358]: plugins/telit.c:telit_qss_notify() 0x1152008
ofonod[358]: plugins/telit.c:switch_sim_state_status() 0x1152008, SIM
status: 0




AT+CFUN=1 is used to set the modem online, i.e. enable RX, TX it also
enables the SIM. AT+CFUN = 4 is used to set the modem in flight mode.
I cannot see that the modem is set online in your debug output, i.e. a
D-Bus call to org.ofono.Modem.SetProperty('Online', true) is made.
Without this call you will never get an URC of #QSS with a value greater
than 0. SIM detection is enabled after AT+CFUN=1.
I never worked with ConnMan so I don't know what causes ConnMan to set
the modem online.


ConnMan can enable the modem, but needs the GPRS interface exported from 
Ofono in order to be able to do so, something which happens in post_sim 
for the Telit modem.  So this is a catch 22...


The online-modem command works fine for this modem, the dilemma is to 
get ConnMan to do issue it for 

Re: Telit HE910 modem --- unable be put on line by Connman

2012-12-03 Thread Daniel Wagner

Hi Mingli

[please don't top post.]

On 03.12.2012 11:37, Ming Li Wu wrote:

Hi Daniel,

Thanks for your reply.

I am using an arm development board in which ofono is running.
rfkill is not installed. should I install it?


I wanted to ask you if the the interface is rfkilled (e.b. by ConnMan). 
The rfkill tool is able to show the current applied settings.


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


[PATCH v0 00/14] External HFP Profile

2012-12-03 Thread Claudio Takahasi
BlueZ supports now external profile registration, see:
bluez/doc/profile-api.txt

This patch series has the initial implementation of the HFP external
profile in oFono. HandsfreeAgent and HandsfreeGateway interfaces were
removed from BlueZ.

Modem are being registered dinamically when the new connection is
notified instead of registering the modem when the Bluetooth device
is created/probed.

* Needs to be applied after [PATCH v0 1/4] bluetooth: Fix reading
Bluetooth Adapters series

Changes from RFC v1:
- Remove optional RequireAuthorization  RequireAuthentication to
  Register HFP profile.

Next actions:
 - Implement MediaTransport
 - MediaEndpoint set configuration

Development branch:
git://git.infradead.org/users/cktakahasi/ofono.git hfp


Claudio Takahasi (14):
  hfp_hf: Add HFP external Profile registration
  hfp_hf: Add BlueZ Profile handler
  hfp_hf: Add parsing of Profile NewConnection call
  hfp_hf: Add SLC setup
  hfp_hf: Add Profile1 Release
  hfp_hf: Remove HandsfreeAgent and HandsfreeGateway
  hfp_hf: Register HFP modem dynamically
  hfp_hf: Fix updating alias
  bluetooth: Reuse D-Bus dictionary parser function
  hfp_hf: Add Version and Features parsing
  bluetooth: Use generic function to parse dict
  bluetooth: Fix memory leak of adapter_any_path
  hfp_hf: Handle connections before probe
  bluetooth: Fix memory leak of UUIDs list

 plugins/bluetooth.c | 268 +++
 plugins/bluetooth.h |  12 +-
 plugins/hfp_hf.c| 451 +++-
 3 files changed, 446 insertions(+), 285 deletions(-)

-- 
1.7.11.7

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


[PATCH v0 01/14] hfp_hf: Add HFP external Profile registration

2012-12-03 Thread Claudio Takahasi
This patch adds the functions to allow registering and unregistering HFP
external profile using BlueZ ProfileManager1 interface.
---
 plugins/bluetooth.c | 137 
 plugins/bluetooth.h |   5 +-
 plugins/hfp_hf.c|  12 +
 3 files changed, 153 insertions(+), 1 deletion(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 09c9870..201c851 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -65,6 +65,39 @@ struct cb_data {
GIOChannel *io;
 };
 
+static void append_variant(DBusMessageIter *iter, int type, void *val)
+{
+   DBusMessageIter value;
+   char sig[2] = { type, '\0' };
+
+   dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, value);
+
+   dbus_message_iter_append_basic(value, type, val);
+
+   dbus_message_iter_close_container(iter, value);
+}
+
+static void dict_append_entry(DBusMessageIter *dict, const char *key, int type,
+   void *val)
+{
+   DBusMessageIter entry;
+
+   if (type == DBUS_TYPE_STRING) {
+   const char *str = *((const char **) val);
+   if (str == NULL)
+   return;
+   }
+
+   dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, NULL,
+   entry);
+
+   dbus_message_iter_append_basic(entry, DBUS_TYPE_STRING, key);
+
+   append_variant(entry, type, val);
+
+   dbus_message_iter_close_container(dict, entry);
+}
+
 void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
char *buf, int size)
 {
@@ -968,6 +1001,110 @@ void bluetooth_unregister_uuid(const char *uuid)
bluetooth_unref();
 }
 
+static void register_profile_cb(DBusPendingCall *call, gpointer user_data)
+{
+   DBusMessage *reply;
+   DBusError derr;
+
+   reply = dbus_pending_call_steal_reply(call);
+
+   dbus_error_init(derr);
+
+   if (dbus_set_error_from_message(derr, reply)) {
+   ofono_error(RegisterProfile() replied an error: %s, %s,
+   derr.name, derr.message);
+   dbus_error_free(derr);
+   goto done;
+   }
+
+   DBG();
+
+done:
+   dbus_message_unref(reply);
+}
+
+int bluetooth_register_profile(const char *uuid, const char *name,
+   const char *object)
+{
+   DBusMessageIter iter, dict;
+   DBusPendingCall *c;
+   DBusMessage *msg;
+
+   DBG(Bluetooth: Registering %s (%s) profile, uuid, name);
+
+   msg = dbus_message_new_method_call(BLUEZ_SERVICE, /org/bluez,
+   BLUEZ_PROFILE_MGMT_INTERFACE, RegisterProfile);
+
+   dbus_message_iter_init_append(msg, iter);
+   dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, object);
+   dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, uuid);
+
+   dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, {sv}, dict);
+   dict_append_entry(dict, Name, DBUS_TYPE_STRING, name);
+   dbus_message_iter_close_container(iter, dict);
+
+   if (!dbus_connection_send_with_reply(connection, msg, c, -1)) {
+   ofono_error(Sending RegisterProfile failed);
+   dbus_message_unref(msg);
+   return -EIO;
+   }
+
+   dbus_pending_call_set_notify(c, register_profile_cb, NULL, NULL);
+   dbus_pending_call_unref(c);
+
+   dbus_message_unref(msg);
+
+   return 0;
+}
+
+static void unregister_profile_cb(DBusPendingCall *call, gpointer user_data)
+{
+   DBusMessage *reply;
+   DBusError derr;
+
+   reply = dbus_pending_call_steal_reply(call);
+
+   dbus_error_init(derr);
+
+   if (dbus_set_error_from_message(derr, reply)) {
+   ofono_error(UnregisterProfile() replied an error: %s, %s,
+   derr.name, derr.message);
+   dbus_error_free(derr);
+   goto done;
+   }
+
+   DBG();
+
+done:
+   dbus_message_unref(reply);
+}
+
+void bluetooth_unregister_profile(const char *object)
+{
+   DBusMessageIter iter;
+   DBusPendingCall *c;
+   DBusMessage *msg;
+
+   DBG(Bluetooth: Unregistering profile %s, object);
+
+   msg = dbus_message_new_method_call(BLUEZ_SERVICE, /org/bluez,
+   BLUEZ_PROFILE_MGMT_INTERFACE, UnregisterProfile);
+
+   dbus_message_iter_init_append(msg, iter);
+   dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, object);
+
+   if (!dbus_connection_send_with_reply(connection, msg, c, -1)) {
+   ofono_error(Sending RegisterProfile failed);
+   dbus_message_unref(msg);
+   return;
+   }
+
+   dbus_pending_call_set_notify(c, unregister_profile_cb, NULL, NULL);
+   dbus_pending_call_unref(c);
+
+   

[PATCH v0 02/14] hfp_hf: Add BlueZ Profile handler

2012-12-03 Thread Claudio Takahasi
This patch declares the external HFP Profile handler. It contains the
initial implementation of the D-Bus Profile1 interface and methods
responsible for handling Bluetooth connections.
---
 plugins/bluetooth.h |  2 ++
 plugins/hfp_hf.c| 66 -
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index ffaf9e3..a9355f6 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -24,7 +24,9 @@
 
 #defineBLUEZ_SERVICE org.bluez
 #defineBLUEZ_MANAGER_INTERFACE BLUEZ_SERVICE .Manager
+#defineBLUEZ_ERROR_INTERFACE   BLUEZ_SERVICE .Error
 #define BLUEZ_PROFILE_MGMT_INTERFACE   BLUEZ_SERVICE .ProfileManager1
+#defineBLUEZ_PROFILE_INTERFACE BLUEZ_SERVICE .Profile1
 #defineBLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE .Adapter
 #defineBLUEZ_DEVICE_INTERFACE  BLUEZ_SERVICE .Device
 #defineBLUEZ_SERVICE_INTERFACE BLUEZ_SERVICE .Service
diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 1e0064c..6836c45 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -339,6 +339,55 @@ static int hfp_unregister_ofono_handsfree(struct 
ofono_modem *modem)
return 0;
 }
 
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+   DBusMessage *msg, void *data)
+{
+   DBG(Profile handler NewConnection);
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static DBusMessage *profile_release(DBusConnection *conn,
+   DBusMessage *msg, void *data)
+{
+   DBG(Profile handler Release);
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static DBusMessage *profile_cancel(DBusConnection *conn,
+   DBusMessage *msg, void *data)
+{
+   DBG(Profile handler Cancel);
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static DBusMessage *profile_disconnection(DBusConnection *conn,
+   DBusMessage *msg, void *data)
+{
+   DBG(Profile handler RequestDisconnection);
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+   .NotImplemented,
+   Implementation not provided);
+}
+
+static const GDBusMethodTable profile_methods[] = {
+   { GDBUS_ASYNC_METHOD(NewConnection,
+   GDBUS_ARGS({ device, o}, { fd, h},
+   { fd_properties, a{sv} }),
+   NULL, profile_new_connection) },
+   { GDBUS_METHOD(Release, NULL, NULL, profile_release) },
+   { GDBUS_METHOD(Cancel, NULL, NULL, profile_cancel) },
+   { GDBUS_METHOD(RequestDisconnection,
+   GDBUS_ARGS({device, o}), NULL,
+   profile_disconnection) },
+   { }
+};
+
 static int hfp_probe(struct ofono_modem *modem)
 {
const char *obj_path = ofono_modem_get_path(modem);
@@ -526,12 +575,24 @@ static int hfp_init(void)
 
connection = ofono_dbus_get_connection();
 
+   /* Registers External Profile handler */
+   if (!g_dbus_register_interface(connection, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE,
+   profile_methods, NULL,
+   NULL, NULL, NULL)) {
+   ofono_error(Register Profile interface failed: %s,
+   HFP_EXT_PROFILE_PATH);
+   return -EIO;
+   }
+
err = ofono_modem_driver_register(hfp_driver);
if (err  0)
return err;
 
err = bluetooth_register_uuid(HFP_AG_UUID, hfp_hf);
if (err  0) {
+   g_dbus_unregister_interface(connection, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE);
ofono_modem_driver_unregister(hfp_driver);
return err;
}
@@ -539,6 +600,8 @@ static int hfp_init(void)
err = bluetooth_register_profile(HFP_HS_UUID, hfp_hf,
HFP_EXT_PROFILE_PATH);
if (err  0) {
+   g_dbus_unregister_interface(connection, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE);
bluetooth_unregister_uuid(HFP_AG_UUID);
ofono_modem_driver_unregister(hfp_driver);
   

[PATCH v0 03/14] hfp_hf: Add parsing of Profile NewConnection call

2012-12-03 Thread Claudio Takahasi
This patch adds the parsing of the mandatory arguments in NewConnection
method call implemented in Profile1 interface.
---
 plugins/hfp_hf.c | 37 ++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 6836c45..03f3371 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -342,10 +342,41 @@ static int hfp_unregister_ofono_handsfree(struct 
ofono_modem *modem)
 static DBusMessage *profile_new_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
 {
+   struct ofono_modem *modem;
+   const char *device;
+   DBusMessageIter entry;
+   int fd;
+
DBG(Profile handler NewConnection);
-   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-   .NotImplemented,
-   Implementation not provided);
+
+   if (dbus_message_iter_init(msg, entry) == FALSE)
+   goto error;
+
+   if (dbus_message_iter_get_arg_type(entry) != DBUS_TYPE_OBJECT_PATH)
+   goto error;
+
+   dbus_message_iter_get_basic(entry, device);
+   modem = g_hash_table_lookup(modem_hash, device);
+   if (modem == NULL) {
+   DBG(%s: modem not found, device);
+   goto error;
+   }
+
+   dbus_message_iter_next(entry);
+   if (dbus_message_iter_get_arg_type(entry) != DBUS_TYPE_UNIX_FD)
+   goto error;
+
+   dbus_message_iter_get_basic(entry, fd);
+   if (fd  0)
+   goto error;
+
+   DBG(modem %p, SLC FD: %d, modem, fd);
+
+   return dbus_message_new_method_return(msg);
+
+error:
+   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE .Rejected,
+   Invalid arguments in method call);
 }
 
 static DBusMessage *profile_release(DBusConnection *conn,
-- 
1.7.11.7

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


[PATCH v0 04/14] hfp_hf: Add SLC setup

2012-12-03 Thread Claudio Takahasi
This patch adds the SLC setup when the NewConnection is notified.
---
 plugins/hfp_hf.c | 24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 03f3371..644067c 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -101,9 +101,10 @@ static void slc_failed(gpointer userdata)
struct hfp_data *data = ofono_modem_get_data(modem);
DBusMessage *msg;
 
-   msg = g_dbus_create_error(data-slc_msg, HFP_AGENT_ERROR_INTERFACE
-   .Failed,
-   HFP Handshake failed);
+   msg = g_dbus_create_error(data-slc_msg, BLUEZ_ERROR_INTERFACE
+   .Failed,
+   HFP Handshake failed);
+
g_dbus_send_message(connection, msg);
dbus_message_unref(data-slc_msg);
data-slc_msg = NULL;
@@ -343,9 +344,11 @@ static DBusMessage *profile_new_connection(DBusConnection 
*conn,
DBusMessage *msg, void *data)
 {
struct ofono_modem *modem;
+   struct hfp_data *hfp_data;
const char *device;
DBusMessageIter entry;
-   int fd;
+   int fd, err;
+   guint16 version = 0x0105;
 
DBG(Profile handler NewConnection);
 
@@ -370,9 +373,18 @@ static DBusMessage *profile_new_connection(DBusConnection 
*conn,
if (fd  0)
goto error;
 
-   DBG(modem %p, SLC FD: %d, modem, fd);
+   hfp_data = ofono_modem_get_data(modem);
+   DBG(modem %p, hfp_data: %p SLC FD: %d, modem, hfp_data, fd);
 
-   return dbus_message_new_method_return(msg);
+   hfp_slc_info_init(hfp_data-info, version);
+
+   err = service_level_connection(modem, fd);
+   if (err  0  err != -EINPROGRESS)
+   return __ofono_error_failed(msg);
+
+   hfp_data-slc_msg = dbus_message_ref(msg);
+
+   return NULL;
 
 error:
return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE .Rejected,
-- 
1.7.11.7

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


[PATCH v0 05/14] hfp_hf: Add Profile1 Release

2012-12-03 Thread Claudio Takahasi
This patch adds the Release method of the external Profile handler.
Release method gets called when BlueZ unregisters the HFP profile.
---
 plugins/hfp_hf.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 644067c..dd09142 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -395,9 +395,13 @@ static DBusMessage *profile_release(DBusConnection *conn,
DBusMessage *msg, void *data)
 {
DBG(Profile handler Release);
-   return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-   .NotImplemented,
-   Implementation not provided);
+
+   g_dbus_unregister_interface(connection, HFP_EXT_PROFILE_PATH,
+   BLUEZ_PROFILE_INTERFACE);
+
+   g_hash_table_foreach_remove(modem_hash, hfp_remove_modem, NULL);
+
+   return dbus_message_new_method_return(msg);
 }
 
 static DBusMessage *profile_cancel(DBusConnection *conn,
-- 
1.7.11.7

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


[PATCH v0 07/14] hfp_hf: Register HFP modem dynamically

2012-12-03 Thread Claudio Takahasi
This patch moves the modem creation from the Bluetooth profile probe
to the NewConnection method call. HFP modem is now registered when
the Bluetooth link is established.
---
 plugins/hfp_hf.c | 109 +--
 1 file changed, 73 insertions(+), 36 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index d91c197..1d1edf1 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -57,13 +57,28 @@
 
 static DBusConnection *connection;
 static GHashTable *modem_hash = NULL;
+static GHashTable *hfp_hash = NULL;
 
 struct hfp_data {
struct hfp_slc_info info;
-   char *handsfree_address;
+   gchar *device_address;
+   gchar *adapter_address;
+   gchar *device_alias;
+   gchar *device_path;
DBusMessage *slc_msg;
 };
 
+static void hfp_data_free(gpointer user_data)
+{
+   struct hfp_data *hfp_data = user_data;
+
+   g_free(hfp_data-device_address);
+   g_free(hfp_data-adapter_address);
+   g_free(hfp_data-device_alias);
+   g_free(hfp_data-device_path);
+   g_free(hfp_data);
+}
+
 static void hfp_debug(const char *str, void *user_data)
 {
const char *prefix = user_data;
@@ -117,6 +132,10 @@ static void hfp_disconnected_cb(gpointer user_data)
 
g_at_chat_unref(data-info.chat);
data-info.chat = NULL;
+
+   g_hash_table_remove(modem_hash, data-device_path);
+
+   ofono_modem_remove(modem);
 }
 
 /* either oFono or Phone could request SLC connection */
@@ -153,46 +172,72 @@ static int service_level_connection(struct ofono_modem 
*modem, int fd)
return -EINPROGRESS;
 }
 
-static int hfp_hf_probe(const char *device, const char *dev_addr,
-   const char *adapter_addr, const char *alias)
+static int modem_register(const char *device, struct hfp_data *hfp_data, int 
fd)
 {
struct ofono_modem *modem;
-   struct hfp_data *data;
char buf[256];
+   guint16 version = 0x0105;
 
/* We already have this device in our hash, ignore */
if (g_hash_table_lookup(modem_hash, device) != NULL)
return -EALREADY;
 
-   ofono_info(Using device: %s, devaddr: %s, adapter: %s,
-   device, dev_addr, adapter_addr);
-
strcpy(buf, hfp/);
-   bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
+   bluetooth_create_path(hfp_data-device_address,
+   hfp_data-adapter_address, buf + 4, sizeof(buf) - 4);
 
modem = ofono_modem_create(buf, hfp);
if (modem == NULL)
return -ENOMEM;
 
-   data = g_try_new0(struct hfp_data, 1);
-   if (data == NULL)
+   ofono_modem_set_data(modem, hfp_data);
+   ofono_modem_set_name(modem, hfp_data-device_alias);
+   ofono_modem_register(modem);
+
+   g_hash_table_insert(modem_hash, g_strdup(device), modem);
+
+   hfp_slc_info_init(hfp_data-info, version);
+
+   return service_level_connection(modem, fd);
+}
+
+static int hfp_hf_probe(const char *device, const char *dev_addr,
+   const char *adapter_addr, const char *alias)
+{
+   struct hfp_data *hfp_data;
+
+   if (g_hash_table_lookup(hfp_hash, device) != NULL)
+   return -EALREADY;
+
+   ofono_info(Using device: %s, devaddr: %s, adapter: %s,
+   device, dev_addr, adapter_addr);
+
+   hfp_data = g_try_new0(struct hfp_data, 1);
+   if (hfp_data == NULL)
goto free;
 
-   data-handsfree_address = g_strdup(dev_addr);
-   if (data-handsfree_address == NULL)
+   hfp_data-adapter_address = g_strdup(adapter_addr);
+   if (hfp_data-adapter_address == NULL)
goto free;
 
-   ofono_modem_set_data(modem, data);
-   ofono_modem_set_name(modem, alias);
-   ofono_modem_register(modem);
+   hfp_data-device_address = g_strdup(dev_addr);
+   if (hfp_data-device_address == NULL)
+   goto free;
 
-   g_hash_table_insert(modem_hash, g_strdup(device), modem);
+   hfp_data-device_path = g_strdup(device);
+   if (hfp_data-device_path == NULL)
+   goto free;
+
+   hfp_data-device_alias = g_strdup(alias);
+   if (hfp_data-device_alias == NULL)
+   goto free;
+
+   g_hash_table_insert(hfp_hash, g_strdup(device), hfp_data);
 
return 0;
 
 free:
-   g_free(data);
-   ofono_modem_remove(modem);
+   hfp_data_free(hfp_data);
 
return -ENOMEM;
 }
@@ -240,12 +285,10 @@ static void hfp_hf_set_alias(const char *device, const 
char *alias)
 static DBusMessage *profile_new_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
 {
-   struct ofono_modem *modem;
struct hfp_data *hfp_data;
const char *device;
DBusMessageIter entry;
int fd, err;
-   guint16 version = 0x0105;
 
DBG(Profile handler 

[PATCH v0 06/14] hfp_hf: Remove HandsfreeAgent and HandsfreeGateway

2012-12-03 Thread Claudio Takahasi
This patch removes the deprecated HandsfreeAgent and HandsfreeGateway
interfaces. New connections are now being managed by a BlueZ external
Profile handler.
---
 plugins/hfp_hf.c | 215 ++-
 1 file changed, 7 insertions(+), 208 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index dd09142..d91c197 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -49,11 +49,6 @@
 
 #include bluetooth.h
 
-#defineBLUEZ_GATEWAY_INTERFACE BLUEZ_SERVICE 
.HandsfreeGateway
-
-#define HFP_AGENT_INTERFACE org.bluez.HandsfreeAgent
-#define HFP_AGENT_ERROR_INTERFACE org.bluez.Error
-
 #define HFP_EXT_PROFILE_PATH   /bluetooth/profile/hfp_hf
 
 #ifndef DBUS_TYPE_UNIX_FD
@@ -65,11 +60,8 @@ static GHashTable *modem_hash = NULL;
 
 struct hfp_data {
struct hfp_slc_info info;
-   char *handsfree_path;
char *handsfree_address;
DBusMessage *slc_msg;
-   gboolean agent_registered;
-   DBusPendingCall *call;
 };
 
 static void hfp_debug(const char *str, void *user_data)
@@ -161,54 +153,6 @@ static int service_level_connection(struct ofono_modem 
*modem, int fd)
return -EINPROGRESS;
 }
 
-static DBusMessage *hfp_agent_new_connection(DBusConnection *conn,
-   DBusMessage *msg, void *data)
-{
-   int fd, err;
-   struct ofono_modem *modem = data;
-   struct hfp_data *hfp_data = ofono_modem_get_data(modem);
-   guint16 version;
-
-   if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_UNIX_FD, fd,
-   DBUS_TYPE_UINT16, version, DBUS_TYPE_INVALID))
-   return __ofono_error_invalid_args(msg);
-
-   hfp_slc_info_init(hfp_data-info, version);
-
-   err = service_level_connection(modem, fd);
-   if (err  0  err != -EINPROGRESS)
-   return __ofono_error_failed(msg);
-
-   hfp_data-slc_msg = msg;
-   dbus_message_ref(msg);
-
-   return NULL;
-}
-
-static DBusMessage *hfp_agent_release(DBusConnection *conn,
-   DBusMessage *msg, void *data)
-{
-   struct ofono_modem *modem = data;
-   struct hfp_data *hfp_data = ofono_modem_get_data(modem);
-   const char *obj_path = ofono_modem_get_path(modem);
-
-   g_dbus_unregister_interface(connection, obj_path, HFP_AGENT_INTERFACE);
-   hfp_data-agent_registered = FALSE;
-
-   g_hash_table_remove(modem_hash, hfp_data-handsfree_path);
-   ofono_modem_remove(modem);
-
-   return dbus_message_new_method_return(msg);
-}
-
-static const GDBusMethodTable agent_methods[] = {
-   { GDBUS_ASYNC_METHOD(NewConnection,
-   GDBUS_ARGS({ fd, h }, { version, q }),
-   NULL, hfp_agent_new_connection) },
-   { GDBUS_METHOD(Release, NULL, NULL, hfp_agent_release) },
-   { }
-};
-
 static int hfp_hf_probe(const char *device, const char *dev_addr,
const char *adapter_addr, const char *alias)
 {
@@ -234,10 +178,6 @@ static int hfp_hf_probe(const char *device, const char 
*dev_addr,
if (data == NULL)
goto free;
 
-   data-handsfree_path = g_strdup(device);
-   if (data-handsfree_path == NULL)
-   goto free;
-
data-handsfree_address = g_strdup(dev_addr);
if (data-handsfree_address == NULL)
goto free;
@@ -251,9 +191,6 @@ static int hfp_hf_probe(const char *device, const char 
*dev_addr,
return 0;
 
 free:
-   if (data != NULL)
-   g_free(data-handsfree_path);
-
g_free(data);
ofono_modem_remove(modem);
 
@@ -300,46 +237,6 @@ static void hfp_hf_set_alias(const char *device, const 
char *alias)
ofono_modem_set_name(modem, alias);
 }
 
-static int hfp_register_ofono_handsfree(struct ofono_modem *modem)
-{
-   const char *obj_path = ofono_modem_get_path(modem);
-   struct hfp_data *data = ofono_modem_get_data(modem);
-   DBusMessage *msg;
-
-   DBG(Registering oFono Agent to bluetooth daemon);
-
-   msg = dbus_message_new_method_call(BLUEZ_SERVICE, data-handsfree_path,
-   BLUEZ_GATEWAY_INTERFACE, RegisterAgent);
-   if (msg == NULL)
-   return -ENOMEM;
-
-   dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, obj_path,
-   DBUS_TYPE_INVALID);
-
-   g_dbus_send_message(connection, msg);
-   return 0;
-}
-
-static int hfp_unregister_ofono_handsfree(struct ofono_modem *modem)
-{
-   const char *obj_path = ofono_modem_get_path(modem);
-   struct hfp_data *data = ofono_modem_get_data(modem);
-   DBusMessage *msg;
-
-   DBG(Unregistering oFono Agent from bluetooth daemon);
-
-   msg = dbus_message_new_method_call(BLUEZ_SERVICE, data-handsfree_path,
-   BLUEZ_GATEWAY_INTERFACE, UnregisterAgent);
-   if (msg == NULL)
-   return 

[PATCH v0 08/14] hfp_hf: Fix updating alias

2012-12-03 Thread Claudio Takahasi
This patch fixes the Bluetooth device alias for the HFP when the modem
is not registered yet. Modem is being created with the first alias
informed when in the Bluetooth profile probe callback.
---
 plugins/hfp_hf.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 1d1edf1..da20917 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -271,15 +271,20 @@ static void hfp_hf_remove(const char *prefix)
 static void hfp_hf_set_alias(const char *device, const char *alias)
 {
struct ofono_modem *modem;
+   struct hfp_data *hfp_data;
 
if (device == NULL || alias == NULL)
return;
 
-   modem = g_hash_table_lookup(modem_hash, device);
-   if (modem == NULL)
-   return;
+   hfp_data = g_hash_table_lookup(hfp_hash, device);
+   if (hfp_data) {
+   g_free(hfp_data-device_alias);
+   hfp_data-device_alias = g_strdup(alias);
+   }
 
-   ofono_modem_set_name(modem, alias);
+   modem = g_hash_table_lookup(modem_hash, device);
+   if (modem)
+   ofono_modem_set_name(modem, alias);
 }
 
 static DBusMessage *profile_new_connection(DBusConnection *conn,
-- 
1.7.11.7

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


[PATCH v0 09/14] bluetooth: Reuse D-Bus dictionary parser function

2012-12-03 Thread Claudio Takahasi
This patch changes the Bluetooth D-Bus property parser function to allow
reusing on other messages. The dictionary can be placed on any position
of the message, the current implementation assumes that the first
message parameter should be a dictionary.
---
 plugins/bluetooth.c | 27 ---
 plugins/bluetooth.h |  3 ++-
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 201c851..37738e7 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -195,11 +195,14 @@ static gint property_handler_compare(gconstpointer a, 
gconstpointer b)
return strcmp(handler-property, property);
 }
 
-void bluetooth_parse_properties(DBusMessage *reply, const char *property, ...)
+void bluetooth_parse_properties(DBusMessageIter *array, const char *property, 
...)
 {
va_list args;
GSList *prop_handlers = NULL;
-   DBusMessageIter array, dict;
+   DBusMessageIter dict;
+
+   if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+   goto done;
 
va_start(args, property);
 
@@ -218,13 +221,7 @@ void bluetooth_parse_properties(DBusMessage *reply, const 
char *property, ...)
 
va_end(args);
 
-   if (dbus_message_iter_init(reply, array) == FALSE)
-   goto done;
-
-   if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
-   goto done;
-
-   dbus_message_iter_recurse(array, dict);
+   dbus_message_iter_recurse(array, dict);
 
while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;
@@ -324,6 +321,7 @@ static void device_properties_cb(DBusPendingCall *call, 
gpointer user_data)
const char *adapter_addr = NULL;
const char *device_addr = NULL;
const char *alias = NULL;
+   DBusMessageIter iter;
struct DBusError derr;
GSList *uuids = NULL;
 
@@ -341,7 +339,10 @@ static void device_properties_cb(DBusPendingCall *call, 
gpointer user_data)
 
DBG();
 
-   bluetooth_parse_properties(reply, UUIDs, parse_uuids, uuids,
+   if (dbus_message_iter_init(reply, iter) == FALSE)
+   goto done;
+
+   bluetooth_parse_properties(iter, UUIDs, parse_uuids, uuids,
Adapter, parse_string, adapter,
Address, parse_string, device_addr,
Alias, parse_string, alias, NULL);
@@ -480,6 +481,7 @@ static void adapter_properties_cb(DBusPendingCall *call, 
gpointer user_data)
 {
const char *path = user_data;
DBusMessage *reply;
+   DBusMessageIter iter;
DBusError derr;
GSList *device_list = NULL;
GSList *l;
@@ -499,7 +501,10 @@ static void adapter_properties_cb(DBusPendingCall *call, 
gpointer user_data)
 
DBG();
 
-   bluetooth_parse_properties(reply,
+   if (dbus_message_iter_init(reply, iter) == FALSE)
+   goto done;
+
+   bluetooth_parse_properties(iter,
Devices, parse_devices, device_list,
Address, parse_string, addr,
NULL);
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index a9355f6..5b4d9d4 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -84,7 +84,8 @@ int bluetooth_send_with_reply(const char *path, const char 
*interface,
DBusPendingCallNotifyFunction cb,
void *user_data, DBusFreeFunction free_func,
int timeout, int type, ...);
-void bluetooth_parse_properties(DBusMessage *reply, const char *property, ...);
+void bluetooth_parse_properties(DBusMessageIter *array,
+   const char *property, ...);
 
 int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
struct ofono_modem *modem);
-- 
1.7.11.7

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


[PATCH v0 10/14] hfp_hf: Add Version and Features parsing

2012-12-03 Thread Claudio Takahasi
This patch adds parsing of the Version and Features properties of the
NewConnection fd_dictionary.
---
 plugins/hfp_hf.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index da20917..8dd8dd9 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -79,6 +79,16 @@ static void hfp_data_free(gpointer user_data)
g_free(hfp_data);
 }
 
+static void parse_guint16(DBusMessageIter *iter, gpointer user_data)
+{
+   guint16 *value = user_data;
+
+   if (dbus_message_iter_get_arg_type(iter) !=  DBUS_TYPE_UINT16)
+   return;
+
+   dbus_message_iter_get_basic(iter, value);
+}
+
 static void hfp_debug(const char *str, void *user_data)
 {
const char *prefix = user_data;
@@ -172,11 +182,11 @@ static int service_level_connection(struct ofono_modem 
*modem, int fd)
return -EINPROGRESS;
 }
 
-static int modem_register(const char *device, struct hfp_data *hfp_data, int 
fd)
+static int modem_register(const char *device, struct hfp_data *hfp_data,
+   int fd, guint16 version)
 {
struct ofono_modem *modem;
char buf[256];
-   guint16 version = 0x0105;
 
/* We already have this device in our hash, ignore */
if (g_hash_table_lookup(modem_hash, device) != NULL)
@@ -294,6 +304,7 @@ static DBusMessage *profile_new_connection(DBusConnection 
*conn,
const char *device;
DBusMessageIter entry;
int fd, err;
+   guint16 version = 0x0105, features = 0x;
 
DBG(Profile handler NewConnection);
 
@@ -318,9 +329,17 @@ static DBusMessage *profile_new_connection(DBusConnection 
*conn,
if (fd  0)
goto error;
 
-   DBG(hfp_data: %p SLC FD: %d, hfp_data, fd);
+   dbus_message_iter_next(entry);
+
+   bluetooth_parse_properties(entry,
+   Version, parse_guint16, version,
+   Features, parse_guint16, features,
+   NULL);
+
+   DBG(hfp_data: %p SLC FD: %d Version: 0x%04x Features: 0x%04x,
+   hfp_data, fd, version, features);
 
-   err = modem_register(device, hfp_data, fd);
+   err = modem_register(device, hfp_data, fd, version);
if (err  0  err != -EINPROGRESS)
return __ofono_error_failed(msg);
 
-- 
1.7.11.7

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


[PATCH v0 11/14] bluetooth: Use generic function to parse dict

2012-12-03 Thread Claudio Takahasi
This patch changes the Device PropertiesChanged signal parser to use
the generic utility function to decode dictionary entries.
---
 plugins/bluetooth.c | 81 ++---
 1 file changed, 27 insertions(+), 54 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 37738e7..a3dccee 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -401,8 +401,9 @@ static void get_device_properties(const char *path)
 static gboolean properties_changed(DBusConnection *conn, DBusMessage *msg,
void *user_data)
 {
-   const char *property, *interface;
-   DBusMessageIter iter, dict, entry, variant;
+   const char *interface, *path, *alias = NULL;
+   DBusMessageIter iter;
+   GSList *uuids = NULL;
 
DBG();
 
@@ -420,59 +421,31 @@ static gboolean properties_changed(DBusConnection *conn, 
DBusMessage *msg,
if (!dbus_message_iter_next(iter))
return FALSE;
 
-   /* Reading Dict entries containing properties */
-   dbus_message_iter_recurse(iter, dict);
-
-   do {
-   if (dbus_message_iter_get_arg_type(dict) !=
-   DBUS_TYPE_DICT_ENTRY)
-   return FALSE;
-
-   dbus_message_iter_recurse(dict, entry);
-
-   if (dbus_message_iter_get_arg_type(entry) != DBUS_TYPE_STRING)
-   return FALSE;
-
-   dbus_message_iter_get_basic(entry, property);
-
-   if (!dbus_message_iter_next(entry))
-   return FALSE;
-
-   if (dbus_message_iter_get_arg_type(entry) != DBUS_TYPE_VARIANT)
-   return FALSE;
-
-   dbus_message_iter_recurse(entry, variant);
-   if (g_str_equal(property, UUIDs) == TRUE) {
-   GSList *uuids = NULL;
-   const char *path = dbus_message_get_path(msg);
-
-   parse_uuids(variant, uuids);
-
-   /* We need the full set of properties to be able to
-* create the modem properly, including Adapter and
-* Alias, so refetch everything again
-*/
-   if (uuids)
-   get_device_properties(path);
-   } else if (g_str_equal(property, Alias) == TRUE) {
-   const char *path = dbus_message_get_path(msg);
-   struct bluetooth_profile *profile;
-   const char *alias = NULL;
-   GHashTableIter hash_iter;
-   gpointer key, value;
-
-   parse_string(variant, alias);
-
-   g_hash_table_iter_init(hash_iter, uuid_hash);
-   while (g_hash_table_iter_next(hash_iter, key,
-   value)) {
-   profile = value;
-   if (profile-set_alias)
-   profile-set_alias(path, alias);
-   }
+   bluetooth_parse_properties(iter,
+   UUIDs, parse_uuids, uuids,
+   Alias, parse_string, alias,
+   NULL);
+
+   path = dbus_message_get_path(msg);
+
+   /* We need the full set of properties to be able to
+* create the modem properly, including Adapter and
+* Alias, so refetch everything again
+*/
+   if (uuids)
+   get_device_properties(path);
+
+   if (alias) {
+   GHashTableIter hash_iter;
+   gpointer key, value;
+
+   g_hash_table_iter_init(hash_iter, uuid_hash);
+   while (g_hash_table_iter_next(hash_iter, key, value)) {
+   struct bluetooth_profile *profile = value;
+   if (profile-set_alias)
+   profile-set_alias(path, alias);
}
-
-   } while (dbus_message_iter_next(dict));
+   }
 
return TRUE;
 }
-- 
1.7.11.7

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


[PATCH v0 12/14] bluetooth: Fix memory leak of adapter_any_path

2012-12-03 Thread Claudio Takahasi
This patch fixes a memory leak when BlueZ service re-connects to the
system Bus and oFono calls FindAdapter method.
---
 plugins/bluetooth.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index a3dccee..6447e77 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -45,7 +45,7 @@ static GHashTable *adapter_address_hash = NULL;
 static gint bluetooth_refcount;
 static GSList *server_list = NULL;
 static const char *adapter_any_name = any;
-static char *adapter_any_path;
+static char *adapter_any_path = NULL;
 
 #define TIMEOUT 60 /* Timeout for user response (seconds) */
 
@@ -733,6 +733,7 @@ static void find_adapter_cb(DBusPendingCall *call, gpointer 
user_data)
dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, path,
DBUS_TYPE_INVALID);
 
+   g_free(adapter_any_path);
adapter_any_path = g_strdup(path);
 
g_slist_foreach(server_list, (GFunc) add_record, NULL);
-- 
1.7.11.7

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


[PATCH v0 13/14] hfp_hf: Handle connections before probe

2012-12-03 Thread Claudio Takahasi
This patch allows oFono HFP plugin to handle HFP connections before
the Bluetooth device creation procedure finishes.
---
 plugins/bluetooth.c | 26 +
 plugins/bluetooth.h |  2 ++
 plugins/hfp_hf.c| 84 +++--
 3 files changed, 83 insertions(+), 29 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 6447e77..ce6dcae 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -31,6 +31,8 @@
 #include unistd.h
 #include glib.h
 #include gdbus.h
+#include bluetooth/bluetooth.h
+#include bluetooth/rfcomm.h
 
 #define OFONO_API_SUBJECT_TO_CHANGE
 #include ofono/plugin.h
@@ -1141,5 +1143,29 @@ void bluetooth_unregister_server(struct server *server)
bluetooth_unref();
 }
 
+int bluetooth_get_address(int fd, char *adapter_address, char *device_address)
+{
+   struct sockaddr_rc saddr;
+   socklen_t alen;
+
+   alen = sizeof(saddr);
+
+   if (adapter_address) {
+   if (getsockname(fd, (struct sockaddr *)saddr, alen)  0)
+   return -errno;
+
+   ba2str(saddr.rc_bdaddr, adapter_address);
+   }
+
+   if (device_address) {
+   if (getpeername(fd, (struct sockaddr *)saddr, alen)  0)
+   return -errno;
+
+   ba2str(saddr.rc_bdaddr, device_address);
+   }
+
+   return 0;
+}
+
 OFONO_PLUGIN_DEFINE(bluetooth, Bluetooth Utils Plugins, VERSION,
OFONO_PLUGIN_PRIORITY_DEFAULT, NULL, NULL)
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 5b4d9d4..c1c274d 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -90,3 +90,5 @@ void bluetooth_parse_properties(DBusMessageIter *array,
 int bluetooth_sap_client_register(struct bluetooth_sap_driver *sap,
struct ofono_modem *modem);
 void bluetooth_sap_client_unregister(struct ofono_modem *modem);
+
+int bluetooth_get_address(int fd, char *adapter_address, char *device_address);
diff --git a/plugins/hfp_hf.c b/plugins/hfp_hf.c
index 8dd8dd9..5d71558 100644
--- a/plugins/hfp_hf.c
+++ b/plugins/hfp_hf.c
@@ -79,6 +79,40 @@ static void hfp_data_free(gpointer user_data)
g_free(hfp_data);
 }
 
+static struct hfp_data *hfp_data_new(const gchar *adapter_addr,
+   const gchar *device_addr,
+   const gchar *device_path,
+   const gchar *alias)
+{
+   struct hfp_data *hfp_data;
+
+   hfp_data = g_try_new0(struct hfp_data, 1);
+   if (hfp_data == NULL)
+   return NULL;
+
+   hfp_data-adapter_address = g_strdup(adapter_addr);
+   if (hfp_data-adapter_address == NULL)
+   goto free;
+
+   hfp_data-device_address = g_strdup(device_addr);
+   if (hfp_data-device_address == NULL)
+   goto free;
+
+   hfp_data-device_path = g_strdup(device_path);
+   if (hfp_data-device_path == NULL)
+   goto free;
+
+   hfp_data-device_alias = g_strdup(alias);
+   if (hfp_data-device_alias == NULL)
+   goto free;
+
+   return hfp_data;
+
+free:
+   hfp_data_free(hfp_data);
+   return NULL;
+}
+
 static void parse_guint16(DBusMessageIter *iter, gpointer user_data)
 {
guint16 *value = user_data;
@@ -222,34 +256,13 @@ static int hfp_hf_probe(const char *device, const char 
*dev_addr,
ofono_info(Using device: %s, devaddr: %s, adapter: %s,
device, dev_addr, adapter_addr);
 
-   hfp_data = g_try_new0(struct hfp_data, 1);
+   hfp_data = hfp_data_new(adapter_addr, dev_addr, device, alias);
if (hfp_data == NULL)
-   goto free;
-
-   hfp_data-adapter_address = g_strdup(adapter_addr);
-   if (hfp_data-adapter_address == NULL)
-   goto free;
-
-   hfp_data-device_address = g_strdup(dev_addr);
-   if (hfp_data-device_address == NULL)
-   goto free;
-
-   hfp_data-device_path = g_strdup(device);
-   if (hfp_data-device_path == NULL)
-   goto free;
-
-   hfp_data-device_alias = g_strdup(alias);
-   if (hfp_data-device_alias == NULL)
-   goto free;
+   return -ENOMEM;
 
g_hash_table_insert(hfp_hash, g_strdup(device), hfp_data);
 
return 0;
-
-free:
-   hfp_data_free(hfp_data);
-
-   return -ENOMEM;
 }
 
 static gboolean hfp_remove_modem(gpointer key, gpointer value,
@@ -315,12 +328,6 @@ static DBusMessage *profile_new_connection(DBusConnection 
*conn,
goto error;
 
dbus_message_iter_get_basic(entry, device);
-   hfp_data = g_hash_table_lookup(hfp_hash, device);
-   if (hfp_data == NULL) {
-   DBG(%s: doesn't support HFP, device);
-   goto error;
-   }
-
dbus_message_iter_next(entry);
if (dbus_message_iter_get_arg_type(entry) != 

[PATCH v0 14/14] bluetooth: Fix memory leak of UUIDs list

2012-12-03 Thread Claudio Takahasi
---
 plugins/bluetooth.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index ce6dcae..52bf71f 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -434,8 +434,10 @@ static gboolean properties_changed(DBusConnection *conn, 
DBusMessage *msg,
 * create the modem properly, including Adapter and
 * Alias, so refetch everything again
 */
-   if (uuids)
+   if (uuids) {
get_device_properties(path);
+   g_slist_free(uuids);
+   }
 
if (alias) {
GHashTableIter hash_iter;
-- 
1.7.11.7

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


Re: Telit HE910 modem --- unable be put on line by Connman

2012-12-03 Thread Jonas Bonn

On 12/03/2012 12:40 PM, Jonas Bonn wrote:

So, my thinking is that we need to do something like this:

i)   At telit_enable, set CFUN=1 and wait for QSS=2 or QSS=3.
ii)  When we get QSS=2 or QSS=3 then we can set SIM_READY state so that
post_sim gets called... this should be called after all the IMSI
querying, etc. (right?)
iii) Once we're in SIM_READY state, we set CFUN=4... this is the 'end'
of the 'telit_enable' phase
iv)  While in CFUN=4 state, we ignore QSS: 0
V)   This should result in the GPRS interface being exported so that
connman can call 'online' call which will result in the switch to the
real CFUN=1


I gave this a try with the HE910 from Telit and the following works (not 
in git format, this is just for reference... I will resubmit it later 
after comment).  Just note that it takes about 1 min for the SIM to 
reach ready state after power up.


This also doesn't account for QSS: 0 occurring during 'offline' state... 
need to check what happens there.


Comments?


diff --git a/plugins/telit.c b/plugins/telit.c
index fe2ccd6..40d72fe 100644
--- a/plugins/telit.c
+++ b/plugins/telit.c
@@ -339,7 +339,7 @@ static int telit_enable(struct ofono_modem *modem)
g_at_chat_send(data-chat, AT#QSS=0, none_prefix, NULL, NULL, 
NULL);


/* Set phone functionality */
-   g_at_chat_send(data-chat, AT+CFUN=4, none_prefix,
+   g_at_chat_send(data-chat, AT+CFUN=1, none_prefix,
cfun_enable_cb, modem, NULL);

return -EINPROGRESS;
@@ -565,6 +565,16 @@ static void telit_post_sim(struct ofono_modem *modem)

if (gprs  gc)
ofono_gprs_add_context(gprs, gc);
+
+   /*
+* We need the modem in CFUN!=4 state in order to get to
+* post_sim... now we can check if we really should be offline
+* and, if so, set CFUN=4
+*/
+   if (!ofono_modem_get_online(modem)) {
+   g_at_chat_send(data-chat, AT+CFUN=4, none_prefix,
+   NULL, NULL, NULL);
+   }
 }

 static void set_online_cb(gboolean ok, GAtResult *result, gpointer 
user_data)


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