All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Add subscriber number for handsfree
@ 2014-04-08  8:21 Andrew Earl
  2014-04-08  8:21 ` [PATCH 1/4] doc: Add subscriber number to handsfree-api Andrew Earl
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Andrew Earl @ 2014-04-08  8:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 654 bytes --]

Hi Denis,

Here are the changes to add the subscriber number to the handsfree
API.

Thanks,

Andrew


Andrew Earl (4):
  doc: Add subscriber number to handsfree-api
  include: Add subscriber number to handsfree API
  hfp: Add subscriber number to handsfree properties
  hfp: Add CNUM query to handsfree interface for subscriber number

 doc/handsfree-api.txt        |   4 ++
 drivers/hfpmodem/handsfree.c |  88 ++++++++++++++++++++++++++++++
 include/handsfree.h          |   6 +++
 src/handsfree.c              | 124 +++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 219 insertions(+), 3 deletions(-)

-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] doc: Add subscriber number to handsfree-api
  2014-04-08  8:21 [PATCH 0/4] Add subscriber number for handsfree Andrew Earl
@ 2014-04-08  8:21 ` Andrew Earl
  2014-04-08  8:21 ` [PATCH 2/4] include: Add subscriber number to handsfree API Andrew Earl
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Earl @ 2014-04-08  8:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]

---
 doc/handsfree-api.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/doc/handsfree-api.txt b/doc/handsfree-api.txt
index 94e9a8f..5f45efb 100644
--- a/doc/handsfree-api.txt
+++ b/doc/handsfree-api.txt
@@ -76,3 +76,7 @@ Properties	array{string} Features [readonly]
 
 			The current charge level of the battery.  The value
 			can be between 0 and 5 respectively.
+
+		array{string} SubscriberNumbers [readonly]
+
+			List of subscriber numbers provided by the AG.
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] include: Add subscriber number to handsfree API
  2014-04-08  8:21 [PATCH 0/4] Add subscriber number for handsfree Andrew Earl
  2014-04-08  8:21 ` [PATCH 1/4] doc: Add subscriber number to handsfree-api Andrew Earl
@ 2014-04-08  8:21 ` Andrew Earl
  2014-04-08  8:21 ` [PATCH 3/4] hfp: Add subscriber number to handsfree properties Andrew Earl
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Earl @ 2014-04-08  8:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

---
 include/handsfree.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/handsfree.h b/include/handsfree.h
index 929fb32..9f4d0e2 100644
--- a/include/handsfree.h
+++ b/include/handsfree.h
@@ -36,12 +36,18 @@ typedef void (*ofono_handsfree_cb_t)(const struct ofono_error *error,
 typedef void (*ofono_handsfree_phone_cb_t)(const struct ofono_error *error,
 					const struct ofono_phone_number *number,
 					void *data);
+typedef void (*ofono_handsfree_cnum_query_cb_t)(const struct ofono_error *error,
+				int total,
+				const struct ofono_phone_number *numbers,
+				void *data);
 
 struct ofono_handsfree_driver {
 	const char *name;
 	int (*probe)(struct ofono_handsfree *hf, unsigned int vendor,
 			void *data);
 	void (*remove)(struct ofono_handsfree *hf);
+	void (*cnum_query)(struct ofono_handsfree *hf,
+				ofono_handsfree_cnum_query_cb_t cb, void *data);
 	void (*request_phone_number) (struct ofono_handsfree *hf,
 					ofono_handsfree_phone_cb_t cb,
 					void *data);
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] hfp: Add subscriber number to handsfree properties
  2014-04-08  8:21 [PATCH 0/4] Add subscriber number for handsfree Andrew Earl
  2014-04-08  8:21 ` [PATCH 1/4] doc: Add subscriber number to handsfree-api Andrew Earl
  2014-04-08  8:21 ` [PATCH 2/4] include: Add subscriber number to handsfree API Andrew Earl
@ 2014-04-08  8:21 ` Andrew Earl
  2014-04-08  8:21 ` [PATCH 4/4] hfp: Add CNUM query to handsfree interface for subscriber number Andrew Earl
  2014-04-10 15:07 ` [PATCH 0/4] Add subscriber number for handsfree Denis Kenzior
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Earl @ 2014-04-08  8:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5299 bytes --]

---
 src/handsfree.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 121 insertions(+), 3 deletions(-)

diff --git a/src/handsfree.c b/src/handsfree.c
index 745cc9f..5462b19 100644
--- a/src/handsfree.c
+++ b/src/handsfree.c
@@ -44,6 +44,8 @@
 
 static GSList *g_drivers = NULL;
 
+#define HANDSFREE_FLAG_CACHED 0x1
+
 struct ofono_handsfree {
 	ofono_bool_t nrec;
 	ofono_bool_t inband_ringing;
@@ -52,11 +54,13 @@ struct ofono_handsfree {
 	unsigned int ag_features;
 	unsigned int ag_chld_features;
 	unsigned char battchg;
+	GSList *subscriber_numbers;
 
 	const struct ofono_handsfree_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
 	DBusMessage *pending;
+	int flags;
 };
 
 static const char **ag_features_list(unsigned int features,
@@ -177,10 +181,50 @@ void ofono_handsfree_battchg_notify(struct ofono_handsfree *hf,
 					&level);
 }
 
-static DBusMessage *handsfree_get_properties(DBusConnection *conn,
-						DBusMessage *msg, void *data)
+static gboolean ofono_handsfree_is_busy(struct ofono_handsfree *hf)
+{
+	return hf->pending ? TRUE : FALSE;
+}
+
+static void ofono_append_subscriber_numbers(GSList *subscriber_numbers,
+				DBusMessageIter *iter)
+{
+	DBusMessageIter entry;
+	DBusMessageIter variant, array;
+	int i;
+	GSList *l;
+	const char *subscriber_number_string;
+	char arraysig[3];
+	char *subscriber_number_text = "SubscriberNumbers";
+
+	arraysig[0] = DBUS_TYPE_ARRAY;
+	arraysig[1] = DBUS_TYPE_STRING;
+	arraysig[2] = '\0';
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY,
+					NULL, &entry);
+	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING,
+					&subscriber_number_text);
+	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+					arraysig, &variant);
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+					DBUS_TYPE_STRING_AS_STRING, &array);
+
+	for (i = 0, l = subscriber_numbers; l; l = l->next, i++) {
+		subscriber_number_string = phone_number_to_string(l->data);
+		dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING,
+					&subscriber_number_string);
+	}
+
+	dbus_message_iter_close_container(&variant, &array);
+
+	dbus_message_iter_close_container(&entry, &variant);
+	dbus_message_iter_close_container(iter, &entry);
+}
+
+static DBusMessage *generate_get_properties_reply(struct ofono_handsfree *hf,
+						DBusMessage *msg)
 {
-	struct ofono_handsfree *hf = data;
 	DBusMessage *reply;
 	DBusMessageIter iter;
 	DBusMessageIter dict;
@@ -217,11 +261,81 @@ static DBusMessage *handsfree_get_properties(DBusConnection *conn,
 	ofono_dbus_dict_append(&dict, "BatteryChargeLevel", DBUS_TYPE_BYTE,
 				&hf->battchg);
 
+	if (hf->subscriber_numbers)
+		ofono_append_subscriber_numbers(hf->subscriber_numbers, &dict);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
 }
 
+static void hf_cnum_callback(const struct ofono_error *error, int total,
+				const struct ofono_phone_number *numbers,
+				void *data)
+{
+	struct ofono_handsfree *hf = data;
+	int num;
+	struct ofono_phone_number *subscriber_number_string;
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
+		goto out;
+
+	for (num = 0; num < total; num++) {
+		subscriber_number_string = g_new0(struct ofono_phone_number, 1);
+
+		subscriber_number_string->type = numbers[num].type;
+		strncpy(subscriber_number_string->number, numbers[num].number,
+					OFONO_MAX_PHONE_NUMBER_LENGTH+1);
+
+		hf->subscriber_numbers = g_slist_prepend(hf->subscriber_numbers,
+					subscriber_number_string);
+	}
+
+	hf->subscriber_numbers = g_slist_reverse(hf->subscriber_numbers);
+
+out:
+	hf->flags |= HANDSFREE_FLAG_CACHED;
+
+	if (hf->pending) {
+		DBusMessage *reply = generate_get_properties_reply(
+							hf, hf->pending);
+		__ofono_dbus_pending_reply(&hf->pending, reply);
+	}
+}
+
+static void query_cnum(struct ofono_handsfree *hf)
+{
+	if (hf->driver->cnum_query == NULL) {
+		if (hf->pending) {
+			DBusMessage *reply = generate_get_properties_reply(
+							hf, hf->pending);
+			__ofono_dbus_pending_reply(&hf->pending, reply);
+		}
+		return;
+	}
+
+	hf->driver->cnum_query(hf, hf_cnum_callback, hf);
+}
+
+static DBusMessage *handsfree_get_properties(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	struct ofono_handsfree *hf = data;
+
+	if (ofono_handsfree_is_busy(hf))
+		return __ofono_error_busy(msg);
+
+	if (hf->flags & HANDSFREE_FLAG_CACHED)
+		return generate_get_properties_reply(hf, msg);
+
+	/* Query the settings and report back */
+	hf->pending = dbus_message_ref(msg);
+
+	query_cnum(hf);
+
+	return NULL;
+}
+
 static void voicerec_set_cb(const struct ofono_error *error, void *data)
 {
 	struct ofono_handsfree *hf = data;
@@ -453,6 +567,10 @@ static void handsfree_unregister(struct ofono_atom *atom)
 		__ofono_dbus_pending_reply(&hf->pending, reply);
 	}
 
+	g_slist_foreach(hf->subscriber_numbers, (GFunc) g_free, NULL);
+	g_slist_free(hf->subscriber_numbers);
+	hf->subscriber_numbers = NULL;
+
 	ofono_modem_remove_interface(modem, OFONO_HANDSFREE_INTERFACE);
 	g_dbus_unregister_interface(conn, path,
 					OFONO_HANDSFREE_INTERFACE);
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] hfp: Add CNUM query to handsfree interface for subscriber number
  2014-04-08  8:21 [PATCH 0/4] Add subscriber number for handsfree Andrew Earl
                   ` (2 preceding siblings ...)
  2014-04-08  8:21 ` [PATCH 3/4] hfp: Add subscriber number to handsfree properties Andrew Earl
@ 2014-04-08  8:21 ` Andrew Earl
  2014-04-10 15:07 ` [PATCH 0/4] Add subscriber number for handsfree Denis Kenzior
  4 siblings, 0 replies; 6+ messages in thread
From: Andrew Earl @ 2014-04-08  8:21 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3103 bytes --]

---
 drivers/hfpmodem/handsfree.c | 88 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/drivers/hfpmodem/handsfree.c b/drivers/hfpmodem/handsfree.c
index e62fa26..81baaa1 100644
--- a/drivers/hfpmodem/handsfree.c
+++ b/drivers/hfpmodem/handsfree.c
@@ -43,6 +43,8 @@
 #include "hfp.h"
 #include "slc.h"
 
+#define OFONO_HANDSFREE_CNUM_SERVICE_VOICE 4
+
 static const char *binp_prefix[] = { "+BINP:", NULL };
 static const char *bvra_prefix[] = { "+BVRA:", NULL };
 
@@ -125,6 +127,91 @@ static void ciev_notify(GAtResult *result, gpointer user_data)
 	ofono_handsfree_battchg_notify(hf, value);
 }
 
+static void cnum_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_handsfree_cnum_query_cb_t cb = cbd->cb;
+	GAtResultIter iter;
+	struct ofono_phone_number *list = NULL;
+	int num = 0;
+	struct ofono_error error;
+
+	decode_at_error(&error, g_at_result_final_response(result));
+
+	if (!ok)
+		goto out;
+
+	g_at_result_iter_init(&iter, result);
+
+	while (g_at_result_iter_next(&iter, "+CNUM:"))
+		num++;
+
+	if (num == 0)
+		goto out;
+
+	list = g_new(struct ofono_phone_number, num);
+
+	g_at_result_iter_init(&iter, result);
+
+	for (num = 0; g_at_result_iter_next(&iter, "+CNUM:"); ) {
+		const char *number;
+		int len;
+		int service;
+		int type;
+
+		list[num].number[0] = '\0';
+		list[num].type = 129;
+
+		if (!g_at_result_iter_skip_next(&iter))
+			continue;
+
+		if (!g_at_result_iter_next_string(&iter, &number))
+			continue;
+
+		if (!g_at_result_iter_next_number(&iter, &type))
+			continue;
+
+		if (!g_at_result_iter_skip_next(&iter))
+			continue;
+
+		if (!g_at_result_iter_next_number(&iter, &service))
+			continue;
+
+		if (service == OFONO_HANDSFREE_CNUM_SERVICE_VOICE) {
+			len = strlen(number);
+			if (len > OFONO_MAX_PHONE_NUMBER_LENGTH)
+				len = OFONO_MAX_PHONE_NUMBER_LENGTH;
+			strncpy(list[num].number, number, len);
+			list[num].number[len] = '\0';
+			list[num].type = type;
+
+			DBG("cnum_notify:%s", list[num].number);
+			num++;
+		}
+	}
+
+out:
+	cb(&error, num, list, cbd->data);
+
+	g_free(list);
+
+}
+
+static void at_cnum_query(struct ofono_handsfree *hf,
+			ofono_handsfree_cnum_query_cb_t cb, void *data)
+{
+	struct hf_data *hd = ofono_handsfree_get_data(hf);
+	struct cb_data *cbd = cb_data_new(cb, data);
+
+	if (g_at_chat_send(hd->chat, "AT+CNUM", NULL,
+					cnum_query_cb, cbd, g_free) > 0)
+		return;
+
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, -1, NULL, data);
+}
+
 static gboolean hfp_handsfree_register(gpointer user_data)
 {
 	struct ofono_handsfree *hf = user_data;
@@ -283,6 +370,7 @@ static struct ofono_handsfree_driver driver = {
 	.name			= "hfpmodem",
 	.probe			= hfp_handsfree_probe,
 	.remove			= hfp_handsfree_remove,
+	.cnum_query		= at_cnum_query,
 	.request_phone_number	= hfp_request_phone_number,
 	.voice_recognition	= hfp_voice_recognition,
 	.disable_nrec		= hfp_disable_nrec,
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] Add subscriber number for handsfree
  2014-04-08  8:21 [PATCH 0/4] Add subscriber number for handsfree Andrew Earl
                   ` (3 preceding siblings ...)
  2014-04-08  8:21 ` [PATCH 4/4] hfp: Add CNUM query to handsfree interface for subscriber number Andrew Earl
@ 2014-04-10 15:07 ` Denis Kenzior
  4 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2014-04-10 15:07 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

Hi Andrew,

On 04/08/2014 03:21 AM, Andrew Earl wrote:
> Hi Denis,
> 
> Here are the changes to add the subscriber number to the handsfree
> API.
> 
> Thanks,
> 
> Andrew
> 
> 
> Andrew Earl (4):
>   doc: Add subscriber number to handsfree-api
>   include: Add subscriber number to handsfree API
>   hfp: Add subscriber number to handsfree properties
>   hfp: Add CNUM query to handsfree interface for subscriber number
> 
>  doc/handsfree-api.txt        |   4 ++
>  drivers/hfpmodem/handsfree.c |  88 ++++++++++++++++++++++++++++++
>  include/handsfree.h          |   6 +++
>  src/handsfree.c              | 124 +++++++++++++++++++++++++++++++++++++++++--
>  4 files changed, 219 insertions(+), 3 deletions(-)
> 

I went ahead and applied all four patches.  I did reflow a couple of
functions and tweaked variable names after patch 3 & patch 4.  Please
let me know if I broke something.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-10 15:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-08  8:21 [PATCH 0/4] Add subscriber number for handsfree Andrew Earl
2014-04-08  8:21 ` [PATCH 1/4] doc: Add subscriber number to handsfree-api Andrew Earl
2014-04-08  8:21 ` [PATCH 2/4] include: Add subscriber number to handsfree API Andrew Earl
2014-04-08  8:21 ` [PATCH 3/4] hfp: Add subscriber number to handsfree properties Andrew Earl
2014-04-08  8:21 ` [PATCH 4/4] hfp: Add CNUM query to handsfree interface for subscriber number Andrew Earl
2014-04-10 15:07 ` [PATCH 0/4] Add subscriber number for handsfree Denis Kenzior

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.