From c575802491884b566daf2130edd329b91780901b Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Tue, 6 Oct 2015 12:48:14 +0200 Subject: hfp_ag_bluez5: register audio card To let others (PulseAudio) be notified when a handsfree device is connected with us and can be used for audio routing we need to expose this by registering a audio card with the correct type. --- plugins/hfp_ag_bluez5.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'plugins') diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c index 93de3026..ef8a0480 100644 --- a/plugins/hfp_ag_bluez5.c +++ b/plugins/hfp_ag_bluez5.c @@ -22,6 +22,7 @@ #include #endif #include +#include #include #include #include @@ -35,15 +36,18 @@ #include #include #include +#include #include "hfp.h" #include "bluez5.h" +#include "bluetooth.h" #ifndef DBUS_TYPE_UNIX_FD #define DBUS_TYPE_UNIX_FD -1 #endif #define HFP_AG_EXT_PROFILE_PATH "/bluetooth/profile/hfp_ag" +#define BT_ADDR_SIZE 18 static guint modemwatch_id; static GList *modems; @@ -77,8 +81,13 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, const char *device; GIOChannel *io; int fd, fd_dup; + struct sockaddr_rc saddr; + socklen_t optlen; struct ofono_emulator *em; struct ofono_modem *modem; + char local[BT_ADDR_SIZE], remote[BT_ADDR_SIZE]; + struct ofono_handsfree_card *card; + int err; DBG("Profile handler NewConnection"); @@ -111,8 +120,35 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, } modem = modems->data; + DBG("Picked modem %p for emulator", modem); + 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); + close(fd); + goto invalid; + } + + bt_ba2str(&saddr.rc_bdaddr, 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); + close(fd); + goto invalid; + } + + bt_ba2str(&saddr.rc_bdaddr, remote); + em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HFP); if (em == NULL) { close(fd); @@ -129,6 +165,15 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, g_strdup(device), g_free); g_io_channel_unref(io); + card = ofono_handsfree_card_create(0, + OFONO_HANDSFREE_CARD_TYPE_GATEWAY, + NULL, NULL); + + ofono_handsfree_card_set_local(card, local); + ofono_handsfree_card_set_remote(card, remote); + + ofono_emulator_set_handsfree_card(em, card); + g_hash_table_insert(connection_hash, g_strdup(device), GINT_TO_POINTER(fd_dup)); @@ -346,6 +391,8 @@ static int hfp_ag_init(void) connection_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, connection_destroy); + ofono_handsfree_audio_ref(); + return 0; } @@ -362,6 +409,8 @@ static void hfp_ag_exit(void) g_list_free(modems); g_hash_table_foreach_remove(sim_hash, sim_watch_remove, NULL); g_hash_table_destroy(sim_hash); + + ofono_handsfree_audio_unref(); } OFONO_PLUGIN_DEFINE(hfp_ag_bluez5, "Hands-Free Audio Gateway Profile Plugins", -- cgit v1.2.3