From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [RFC v6 07/12] hfp_ag: Add AT+NREC support
Date: Wed, 01 Aug 2012 12:09:42 +0200 [thread overview]
Message-ID: <1343815787-22670-8-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1343815787-22670-1-git-send-email-frederic.danis@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 5074 bytes --]
---
plugins/hfp_ag.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 152 insertions(+), 1 deletion(-)
diff --git a/plugins/hfp_ag.c b/plugins/hfp_ag.c
index 2652f3f..342f959 100644
--- a/plugins/hfp_ag.c
+++ b/plugins/hfp_ag.c
@@ -37,7 +37,8 @@
#define AGENT_PATH "/hfp_ag"
#define VERSION_1_5 0x0105
-#define FEATURES (HFP_AG_FEATURE_3WAY | HFP_AG_FEATURE_REJECT_CALL | \
+#define FEATURES (HFP_AG_FEATURE_3WAY | HFP_AG_FEATURE_ECNR | \
+ HFP_AG_FEATURE_REJECT_CALL | \
HFP_AG_FEATURE_ENHANCED_CALL_STATUS | \
HFP_AG_FEATURE_ENHANCED_CALL_CONTROL | \
HFP_AG_FEATURE_EXTENDED_RES_CODE)
@@ -46,10 +47,150 @@
#define DBUS_TYPE_UNIX_FD -1
#endif
+struct bt_audio {
+ struct ofono_emulator *em;
+ char *path;
+ guint16 r_features;
+ DBusPendingCall *call;
+};
+
static guint modemwatch_id;
static GList *modems;
static GHashTable *sim_hash = NULL;
+static void audio_transport_set_property_cb(DBusPendingCall *call,
+ gpointer user_data)
+{
+ struct bt_audio *audio = user_data;
+ DBusMessage *reply;
+ struct DBusError derr;
+ struct ofono_error result;
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&derr);
+
+ if (dbus_set_error_from_message(&derr, reply)) {
+ ofono_error("MediaTransport.SetProperties replied an error: " \
+ "%s, %s", derr.name, derr.message);
+ dbus_error_free(&derr);
+ result.type = OFONO_ERROR_TYPE_FAILURE;
+ } else
+ result.type = OFONO_ERROR_TYPE_NO_ERROR;
+
+ result.error = 0;
+ ofono_emulator_send_final(audio->em, &result);
+
+ dbus_message_unref(reply);
+
+ dbus_pending_call_unref(audio->call);
+ audio->call = NULL;
+}
+
+static void audio_transport_set_property(struct bt_audio *audio,
+ const char *name, int type, const void *value)
+{
+ DBusMessage *msg;
+ DBusMessageIter iter, var;
+ const char *str_type;
+ DBusConnection *connection;
+ struct ofono_error result;
+
+ if (audio->call != NULL)
+ goto fail;
+
+ if (audio->path == NULL)
+ goto fail;
+
+ switch (type) {
+ case DBUS_TYPE_BOOLEAN:
+ str_type = DBUS_TYPE_BOOLEAN_AS_STRING;
+ break;
+
+ case DBUS_TYPE_UINT16:
+ str_type = DBUS_TYPE_UINT16_AS_STRING;
+ break;
+
+ default:
+ goto fail;
+ }
+
+ msg = dbus_message_new_method_call(BLUEZ_SERVICE, audio->path,
+ BLUEZ_TRANSPORT_INTERFACE, "SetProperty");
+ if (msg == NULL)
+ goto fail;
+
+ dbus_message_iter_init_append(msg, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, str_type,
+ &var);
+ dbus_message_iter_append_basic(&var, type, value);
+ dbus_message_iter_close_container(&iter, &var);
+
+ connection = ofono_dbus_get_connection();
+
+ if (!dbus_connection_send_with_reply(connection, msg, &audio->call,
+ -1)) {
+ ofono_error("Sending SetProperty failed");
+ dbus_message_unref(msg);
+ goto fail;
+ }
+
+ dbus_pending_call_set_notify(audio->call,
+ audio_transport_set_property_cb,
+ audio, NULL);
+
+ dbus_message_unref(msg);
+ return;
+
+fail:
+ result.error = 0;
+ result.type = OFONO_ERROR_TYPE_FAILURE;
+ ofono_emulator_send_final(audio->em, &result);
+}
+
+static void emulator_nrec_cb(struct ofono_emulator *em,
+ struct ofono_emulator_request *req, void *userdata)
+{
+ struct bt_audio *audio = userdata;
+ struct ofono_error result;
+ int val;
+
+ switch (ofono_emulator_request_get_type(req)) {
+ case OFONO_EMULATOR_REQUEST_TYPE_SET:
+ if (!ofono_emulator_request_next_number(req, &val))
+ goto fail;
+
+ if (val != 0 && val != 1)
+ goto fail;
+
+ audio_transport_set_property(audio, "NREC", DBUS_TYPE_BOOLEAN,
+ &val);
+ break;
+
+ default:
+fail:
+ result.error = 0;
+ result.type = OFONO_ERROR_TYPE_FAILURE;
+ ofono_emulator_send_final(em, &result);
+ };
+}
+
+static void free_audio_management(struct bt_audio *audio)
+{
+ DBG("");
+
+ if (audio == NULL)
+ return;
+
+ if (audio->call)
+ dbus_pending_call_cancel(audio->call);
+
+ g_free(audio->path);
+ g_free(audio);
+}
+
static DBusMessage *hfp_ag_agent_new_connection(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -60,6 +201,7 @@ static DBusMessage *hfp_ag_agent_new_connection(DBusConnection *conn,
guint16 features = 0;
struct ofono_emulator *em;
struct ofono_modem *modem;
+ struct bt_audio *audio;
fd = bluetooth_parse_newconnection_message(msg, &device, &version,
&features, &path);
@@ -83,6 +225,15 @@ static DBusMessage *hfp_ag_agent_new_connection(DBusConnection *conn,
ofono_emulator_register(em, fd);
+ audio = g_new0(struct bt_audio, 1);
+ audio->em = em;
+ audio->path = g_strdup(path);
+ audio->r_features = features;
+ ofono_emulator_set_data(em, audio,
+ (ofono_destroy_func)free_audio_management);
+
+ ofono_emulator_add_handler(em, "+NREC", emulator_nrec_cb, audio, NULL);
+
return dbus_message_new_method_return(msg);
}
--
1.7.9.5
next prev parent reply other threads:[~2012-08-01 10:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-01 10:09 [RFC v6 00/12] Add org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 01/12] bluetooth: Add org.bluez.Telephony helpers =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 02/12] hfp_hf: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 03/12] hfp_ag: " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 04/12] bluetooth: Add define for MediaTransport interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 05/12] include: Add set/get data APIs to emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 06/12] emulator: Add set/get data APIs =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2012-08-01 10:09 ` [RFC v6 08/12] hfp_ag: Add +BSIR support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 09/12] hfp_ag: Add AT+VGM support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 10/12] hfp_ag: Add AT+VGS support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 11/12] emulator: Update supported features =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2012-08-01 10:09 ` [RFC v6 12/12] dun_gw: Update to org.bluez.Telephony interface =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343815787-22670-8-git-send-email-frederic.danis@linux.intel.com \
--to=frederic.danis@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.