From: Jo?o Paulo Rechi Vita <jprvita@xxxxxxxxxxxxx> This method is used by the Handsfree Audio Manager to pass the file descriptor to the Handsfree Audio Agent. --- src/modules/bluetooth/bluetooth-util.c | 43 +++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c index 47d164b..a2be396 100644 --- a/src/modules/bluetooth/bluetooth-util.c +++ b/src/modules/bluetooth/bluetooth-util.c @@ -2408,6 +2408,47 @@ static DBusMessage *hfagent_release(DBusConnection *c, DBusMessage *m, void *use return r; } +static DBusMessage *hfagent_new_connection(DBusConnection *c, DBusMessage *m, void *userdata) { + DBusMessage *r; + const char *sender, *card; + int fd; + uint8_t codec; + struct handsfree_card *hf_card; + pa_bluetooth_discovery *y = userdata; + + pa_assert(y); + + sender = dbus_message_get_sender(m); + if (!pa_streq(y->ofono_bus_id, sender)) { + pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.NotAllowed", "Operation is not allowed by this sender")); + return r; + } + + if (dbus_message_get_args(m, NULL, + DBUS_TYPE_OBJECT_PATH, &card, + DBUS_TYPE_UNIX_FD, &fd, + DBUS_TYPE_BYTE, &codec, + DBUS_TYPE_INVALID) == FALSE) { + pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.InvalidArguments", "Invalid arguments in method call")); + return r; + } + + if ( !(hf_card = pa_hashmap_get(y->hf_cards, card)) ) { + pa_log_warn("New audio connection on unknown card %s (fd=%d, codec=%d)", card, fd, codec); + pa_assert_se(r = dbus_message_new_error(m, "org.ofono.Error.InvalidArguments", "Unknown card")); + return r; + } else + pa_log_debug("New audio connection on card %s (fd=%d, codec=%d)", card, fd, codec); + + hf_card->fd = fd; + hf_card->codec = codec; + hf_card->device->transports[PROFILE_HFP_AG]->state = PA_BLUETOOTH_TRANSPORT_STATE_PLAYING; + pa_hook_fire(&y->hooks[PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED], hf_card->device->transports[PROFILE_HFP_AG]); + + pa_assert_se(r = dbus_message_new_method_return(m)); + return r; +} + static DBusHandlerResult dbus_msg_handler(DBusConnection *c, DBusMessage *m, void *userdata) { struct pa_bluetooth_discovery *y = userdata; DBusMessage *r = NULL; @@ -2449,7 +2490,7 @@ static DBusHandlerResult dbus_msg_handler(DBusConnection *c, DBusMessage *m, voi else if (dbus_message_is_method_call(m, "org.ofono.HandsfreeAudioAgent", "Release")) r = hfagent_release(c, m, userdata); else if (dbus_message_is_method_call(m, "org.ofono.HandsfreeAudioAgent", "NewConnection")) - pa_assert_se(r = dbus_message_new_method_return(m)); + r = hfagent_new_connection(c, m, userdata); else return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -- 1.7.11.7