* [PATCH 1/6] include: Add ofono_emulator_create_card()
2013-04-24 17:13 [PATCH 0/6] Add HandsfreeAudioCard to emulator Paulo Borges
@ 2013-04-24 17:13 ` Paulo Borges
2013-04-25 8:35 ` Denis Kenzior
2013-04-24 17:13 ` [PATCH 2/6] emulator: Implement ofono_emulator_create_card() Paulo Borges
` (4 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Paulo Borges @ 2013-04-24 17:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
---
include/emulator.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/emulator.h b/include/emulator.h
index 5cd894b..49168a1 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -74,6 +74,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd);
void ofono_emulator_remove(struct ofono_emulator *em);
+int ofono_emulator_create_card(struct ofono_emulator *em, int fd, int version);
+
void ofono_emulator_send_final(struct ofono_emulator *em,
const struct ofono_error *final);
void ofono_emulator_send_unsolicited(struct ofono_emulator *em,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 1/6] include: Add ofono_emulator_create_card()
2013-04-24 17:13 ` [PATCH 1/6] include: Add ofono_emulator_create_card() Paulo Borges
@ 2013-04-25 8:35 ` Denis Kenzior
2013-04-25 17:36 ` Paulo Borges
0 siblings, 1 reply; 9+ messages in thread
From: Denis Kenzior @ 2013-04-25 8:35 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 967 bytes --]
Hi Paulo,
On 04/24/2013 12:13 PM, Paulo Borges wrote:
> ---
> include/emulator.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/emulator.h b/include/emulator.h
> index 5cd894b..49168a1 100644
> --- a/include/emulator.h
> +++ b/include/emulator.h
> @@ -74,6 +74,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd);
>
> void ofono_emulator_remove(struct ofono_emulator *em);
>
> +int ofono_emulator_create_card(struct ofono_emulator *em, int fd, int version);
> +
Why do you need the fd argument? It can be obtained from the
g_at_server object. e.g.
GIOChannel *channel = g_at_server_get_channel(server);
fd = g_io_channel_get_unix_fd(channel);
Also, what is the purpose of the version parameter?
> void ofono_emulator_send_final(struct ofono_emulator *em,
> const struct ofono_error *final);
> void ofono_emulator_send_unsolicited(struct ofono_emulator *em,
Regards,
-Denis
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/6] include: Add ofono_emulator_create_card()
2013-04-25 8:35 ` Denis Kenzior
@ 2013-04-25 17:36 ` Paulo Borges
0 siblings, 0 replies; 9+ messages in thread
From: Paulo Borges @ 2013-04-25 17:36 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 565 bytes --]
Hi Denis,
On Thu, Apr 25, 2013 at 5:35 AM, Denis Kenzior <denkenz@gmail.com> wrote:
>
>
> Why do you need the fd argument? It can be obtained from the g_at_server
> object. e.g.
> GIOChannel *channel = g_at_server_get_channel(**server);
> fd = g_io_channel_get_unix_fd(**channel);
>
You are right, I'll fix it.
> Also, what is the purpose of the version parameter?
In the next patch series I'll need this parameter to set the correct card
driver. So I already put the parameter here to prevent breaking the build.
--
Cheers,
Paulo.
[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 1228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/6] emulator: Implement ofono_emulator_create_card()
2013-04-24 17:13 [PATCH 0/6] Add HandsfreeAudioCard to emulator Paulo Borges
2013-04-24 17:13 ` [PATCH 1/6] include: Add ofono_emulator_create_card() Paulo Borges
@ 2013-04-24 17:13 ` Paulo Borges
2013-04-24 17:13 ` [PATCH 3/6] hfp_ag_bluez5: Create card when connect Paulo Borges
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Paulo Borges @ 2013-04-24 17:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1241 bytes --]
---
src/emulator.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/emulator.c b/src/emulator.c
index 70505b5..8acdae1 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -29,6 +29,9 @@
#include <glib.h>
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/handsfree-audio.h>
+
#include "ofono.h"
#include "common.h"
#include "hfp.h"
@@ -53,6 +56,7 @@ struct ofono_emulator {
gboolean clip;
gboolean ccwa;
int pns_id;
+ struct ofono_handsfree_card *card;
};
struct indicator {
@@ -880,6 +884,11 @@ static void emulator_unregister(struct ofono_atom *atom)
g_at_server_unref(em->server);
em->server = NULL;
+
+ if (em->card) {
+ ofono_handsfree_card_remove(em->card);
+ em->card = NULL;
+ }
}
void ofono_emulator_register(struct ofono_emulator *em, int fd)
@@ -990,6 +999,13 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
return em;
}
+int ofono_emulator_create_card(struct ofono_emulator *em, int fd, int version)
+{
+ em->card = ofono_handsfree_card_create(0, NULL, NULL);
+
+ return 0;
+}
+
void ofono_emulator_remove(struct ofono_emulator *em)
{
__ofono_atom_free(em->atom);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/6] hfp_ag_bluez5: Create card when connect
2013-04-24 17:13 [PATCH 0/6] Add HandsfreeAudioCard to emulator Paulo Borges
2013-04-24 17:13 ` [PATCH 1/6] include: Add ofono_emulator_create_card() Paulo Borges
2013-04-24 17:13 ` [PATCH 2/6] emulator: Implement ofono_emulator_create_card() Paulo Borges
@ 2013-04-24 17:13 ` Paulo Borges
2013-04-24 17:13 ` [PATCH 4/6] emulator: Register card when establish SLC Paulo Borges
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Paulo Borges @ 2013-04-24 17:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 730 bytes --]
---
plugins/hfp_ag_bluez5.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 245de21..e971a22 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -123,6 +123,14 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
ofono_emulator_register(em, fd);
+ if (ofono_emulator_create_card(em, 0, 0) < 0) {
+ close(fd);
+ ofono_emulator_remove(em);
+ return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+ ".Rejected",
+ "Not enough resources");
+ }
+
fd_dup = dup(fd);
io = g_io_channel_unix_new(fd_dup);
g_io_add_watch_full(io, G_PRIORITY_DEFAULT, G_IO_HUP, io_hup_cb,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/6] emulator: Register card when establish SLC
2013-04-24 17:13 [PATCH 0/6] Add HandsfreeAudioCard to emulator Paulo Borges
` (2 preceding siblings ...)
2013-04-24 17:13 ` [PATCH 3/6] hfp_ag_bluez5: Create card when connect Paulo Borges
@ 2013-04-24 17:13 ` Paulo Borges
2013-04-24 17:13 ` [PATCH 5/6] emulator: Set local and remote address of card Paulo Borges
2013-04-24 17:13 ` [PATCH 6/6] hfp_ag_bluez5: Send fd to card creation Paulo Borges
5 siblings, 0 replies; 9+ messages in thread
From: Paulo Borges @ 2013-04-24 17:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 385 bytes --]
---
src/emulator.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/emulator.c b/src/emulator.c
index 8acdae1..4d5e835 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -641,6 +641,9 @@ done:
g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
em->slc = TRUE;
+
+ ofono_handsfree_card_register(em->card);
+
break;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 5/6] emulator: Set local and remote address of card
2013-04-24 17:13 [PATCH 0/6] Add HandsfreeAudioCard to emulator Paulo Borges
` (3 preceding siblings ...)
2013-04-24 17:13 ` [PATCH 4/6] emulator: Register card when establish SLC Paulo Borges
@ 2013-04-24 17:13 ` Paulo Borges
2013-04-24 17:13 ` [PATCH 6/6] hfp_ag_bluez5: Send fd to card creation Paulo Borges
5 siblings, 0 replies; 9+ messages in thread
From: Paulo Borges @ 2013-04-24 17:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2134 bytes --]
This commit extracts local and remote address from the socket and
stores them into the card.
---
src/emulator.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/emulator.c b/src/emulator.c
index 4d5e835..6acf384 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -23,11 +23,15 @@
#include <config.h>
#endif
+#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include <glib.h>
+#include <sys/socket.h>
#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/handsfree-audio.h>
@@ -37,6 +41,7 @@
#include "hfp.h"
#include "gatserver.h"
#include "gatppp.h"
+#include "bluetooth.h"
#define RING_TIMEOUT 3
@@ -1002,11 +1007,50 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
return em;
}
+static int card_set_local_remote(struct ofono_handsfree_card *card, int fd)
+{
+ struct sockaddr_rc saddr;
+ socklen_t optlen;
+ char local[18], remote[18];
+ int err;
+
+ memset(&saddr, 0, sizeof(saddr));
+ optlen = sizeof(saddr);
+
+ if (getsockname(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+ err = errno;
+ ofono_error("RFCOMM getsockname: %s (%d)", strerror(err), err);
+ return -err;
+ }
+
+ bt_ba2str(&saddr.rc_bdaddr, local);
+
+ DBG("local %s", local);
+
+ memset(&saddr, 0, sizeof(saddr));
+ optlen = sizeof(saddr);
+
+ if (getpeername(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+ err = errno;
+ ofono_error("RFCOMM getpeername: %s (%d)", strerror(err), err);
+ return -err;
+ }
+
+ bt_ba2str(&saddr.rc_bdaddr, remote);
+
+ DBG("remote %s", remote);
+
+ ofono_handsfree_card_set_local(card, local);
+ ofono_handsfree_card_set_remote(card, remote);
+
+ return 0;
+}
+
int ofono_emulator_create_card(struct ofono_emulator *em, int fd, int version)
{
em->card = ofono_handsfree_card_create(0, NULL, NULL);
- return 0;
+ return card_set_local_remote(em->card, fd);
}
void ofono_emulator_remove(struct ofono_emulator *em)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 6/6] hfp_ag_bluez5: Send fd to card creation
2013-04-24 17:13 [PATCH 0/6] Add HandsfreeAudioCard to emulator Paulo Borges
` (4 preceding siblings ...)
2013-04-24 17:13 ` [PATCH 5/6] emulator: Set local and remote address of card Paulo Borges
@ 2013-04-24 17:13 ` Paulo Borges
5 siblings, 0 replies; 9+ messages in thread
From: Paulo Borges @ 2013-04-24 17:13 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
---
plugins/hfp_ag_bluez5.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index e971a22..b3017a9 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -123,7 +123,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
ofono_emulator_register(em, fd);
- if (ofono_emulator_create_card(em, 0, 0) < 0) {
+ if (ofono_emulator_create_card(em, fd, 0) < 0) {
close(fd);
ofono_emulator_remove(em);
return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
--
1.7.9.5
^ permalink raw reply related [flat|nested] 9+ messages in thread