Skip to contentSkip to conversation

HFP: add call, callsetup indicators and +COPS support

PATCH Superseded Frédéric Danis 2 participants 9 messages Mar 17, 2011 – Mar 18, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover HFP: add call, callsetup indicators and +COPS support

AT+COPS support needs to be in emulator as HFP plugin should answer requests even when oFono is not registered on network.

Frédéric Danis (4):
emulator: add defines for call and callsetup indicators
emulator: add call and callsetup indicators
emulator: add API to set network mode and name
emulator: add +COPS support

 include/emulator.h |   13 +++++++
 src/emulator.c     |   75 +++++++++++++++++++++++++++++++++++++++++++
 src/network.c      |   90 +++++++++++++++++++++++++++++++++++++++++++++++----
 src/voicecall.c    |   86 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 257 insertions(+), 7 deletions(-)
#1 lore raw

PATCH 1/4 emulator: add defines for call and callsetup indicators

---
 include/emulator.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/emulator.h +8 -0
index 71b7c24..701decd 100644
@@ -36,6 +36,14 @@ extern "C" {
 #define OFONO_EMULATOR_IND_SERVICE "service"
 #define OFONO_EMULATOR_IND_SIGNAL "signal"
 
+#define OFONO_EMULATOR_CALL_INACTIVE 0
+#define OFONO_EMULATOR_CALL_ACTIVE 1
+
+#define OFONO_EMULATOR_CALLSETUP_INACTIVE 0
+#define OFONO_EMULATOR_CALLSETUP_INCOMING 1
+#define OFONO_EMULATOR_CALLSETUP_OUTGOING 2
+#define OFONO_EMULATOR_CALLSETUP_ALERTING 3
+
 struct ofono_emulator;
 struct ofono_emulator_request;
 
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/4 emulator: add call and callsetup indicators

In reply to Frédéric Danis
---
 src/emulator.c  |    3 ++
 src/voicecall.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 0 deletions(-)
src/emulator.c +3 -0
index c84f0a9..864e50b 100644
@@ -455,6 +455,9 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 
 	if (em->type == OFONO_EMULATOR_TYPE_HFP) {
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALL, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALLSETUP, 0, 3,
+									0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5);
src/voicecall.c +86 -0

128 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 2/4] emulator: add call and callsetup indicators

Hi Frédéric,

Quoted 65 lines · Frédéric Danis
---
 src/emulator.c  |    3 ++
 src/voicecall.c |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 0 deletions(-)
src/emulator.c +3 -0
index c84f0a9..864e50b 100644
@@ -455,6 +455,9 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 
 	if (em->type == OFONO_EMULATOR_TYPE_HFP) {
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALL, 0, 1, 0);
+		emulator_add_indicator(em, OFONO_EMULATOR_IND_CALLSETUP, 0, 3,
+									0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0);
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5);
src/voicecall.c +31 -0
index cb5258d..d0ddad6 100644
@@ -59,6 +59,7 @@ struct ofono_voicecall {
 	struct dial_request *dial_req;
 	GQueue *toneq;
 	guint tone_source;
+	unsigned int hfp_watch;
 };
 
 struct voicecall {
@@ -692,6 +693,55 @@ static void voicecall_emit_multiparty(struct voicecall *call, gboolean mpty)
 						&val);
 }
 
+static void notify_emulator_call_status_cb(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+
+	switch (GPOINTER_TO_INT(data)) {
+	case CALL_STATUS_ACTIVE:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALL,
+						OFONO_EMULATOR_CALL_ACTIVE);
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
+					OFONO_EMULATOR_CALLSETUP_INACTIVE);
+		break;
+
+	case CALL_STATUS_DIALING:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
+					OFONO_EMULATOR_CALLSETUP_OUTGOING);
+		break;
+
+	case CALL_STATUS_ALERTING:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
+					OFONO_EMULATOR_CALLSETUP_ALERTING);
+		break;
+
+	case CALL_STATUS_INCOMING:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
+					OFONO_EMULATOR_CALLSETUP_INCOMING);
+		break;
+
+	case CALL_STATUS_DISCONNECTED:
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALL,
+						OFONO_EMULATOR_CALL_INACTIVE);

src/voicecall.c static void voicecall_emit_multiparty(struct voicecall *call, gboolean mpty) · line 735

Quoted 10 lines
src/voicecall.c +10 -0
+		ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
+					OFONO_EMULATOR_CALLSETUP_INACTIVE);
+		break;
+
+	case CALL_STATUS_WAITING:
+	case CALL_STATUS_HELD:
+		break;
+	}
+}
+

So I don't think this will really work once you introduce multiparty calls. The indicators depend on the state of all calls, not just one particular call. As an example, you can have one party of an active mpty drop which would cause 'call' to go to inactive, even though you still have other calls active.

In addition, waiting calls should trigger a callsetup=1. See 4.22.1.

You might have to put the logic into voicecall.c itself. Something like:

if (have_dialing)
callsetup = 2
elif (have_alerting)
callsetup = 3
elif (have_incoming || have_waiting)
callsetup = 1
else
callsetup = 0

And you have to pay very close attention to the order in which the indicators are reported. Look at the logic inside drivers/hfpmodem/voicecall.c for what we expect, the BT HFP1.5 diagrams and

Quoted 73 lines
src/voicecall.c +41 -0
+static void notify_emulator_call_status(struct ofono_voicecall *vc, int status)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(vc->atom);
+
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+					notify_emulator_call_status_cb,
+					GINT_TO_POINTER(status));
+}
+
 static void voicecall_set_call_status(struct voicecall *call, int status)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
@@ -714,6 +764,8 @@ static void voicecall_set_call_status(struct voicecall *call, int status)
 						"State", DBUS_TYPE_STRING,
 						&status_str);
 
+	notify_emulator_call_status(call->vc, status);
+
 	if (status == CALL_STATUS_ACTIVE &&
 		(old_status == CALL_STATUS_INCOMING ||
 			old_status == CALL_STATUS_DIALING ||
@@ -1043,6 +1095,8 @@ static void voicecalls_emit_call_added(struct ofono_voicecall *vc,
 	DBusMessageIter dict;
 	const char *path;
 
+	notify_emulator_call_status(vc, v->call->status);
+
 	path = __ofono_atom_get_path(vc->atom);
 
 	signal = dbus_message_new_signal(path,
@@ -2188,6 +2242,10 @@ static void voicecall_unregister(struct ofono_atom *atom)
 	const char *path = __ofono_atom_get_path(atom);
 	GSList *l;
 
+	notify_emulator_call_status(vc, CALL_STATUS_DISCONNECTED);
+
+	__ofono_modem_remove_atom_watch(modem, vc->hfp_watch);
+
 	if (vc->sim_watch) {
 		__ofono_modem_remove_atom_watch(modem, vc->sim_watch);
 		vc->sim_watch = 0;
@@ -2362,6 +2420,30 @@ static void sim_watch(struct ofono_atom *atom,
 	sim_state_watch(ofono_sim_get_state(sim), vc);
 }
 
+static void emulator_hfp_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	struct ofono_voicecall *vc = data;
+
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
+		if (voicecalls_have_with_status(vc, CALL_STATUS_ACTIVE))
+			notify_emulator_call_status(vc, CALL_STATUS_ACTIVE);
+
+		if (voicecalls_have_with_status(vc, CALL_STATUS_DIALING))
+			notify_emulator_call_status(vc, CALL_STATUS_DIALING);
+		else if (voicecalls_have_with_status(vc, CALL_STATUS_ALERTING))
+			notify_emulator_call_status(vc, CALL_STATUS_ALERTING);
+		else if (voicecalls_have_with_status(vc, CALL_STATUS_INCOMING))
+			notify_emulator_call_status(vc, CALL_STATUS_INCOMING);
+		else if (voicecalls_have_with_status(vc, CALL_STATUS_WAITING))
+			notify_emulator_call_status(vc, CALL_STATUS_WAITING);
+
+		if (voicecalls_have_with_status(vc, CALL_STATUS_HELD))
+			notify_emulator_call_status(vc, CALL_STATUS_HELD);
+	}
+}
+
 void ofono_voicecall_register(struct ofono_voicecall *vc)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();

src/voicecall.c void ofono_voicecall_register(struct ofono_voicecall *vc) · line 2489

Quoted 10 lines
src/voicecall.c +4 -0
@@ -2398,6 +2480,10 @@ void ofono_voicecall_register(struct ofono_voicecall *vc)
 		sim_watch(sim_atom, OFONO_ATOM_WATCH_CONDITION_REGISTERED, vc);
 
 	__ofono_atom_register(vc->atom, voicecall_unregister);
+
+	vc->hfp_watch = __ofono_modem_add_atom_watch(modem,
+					OFONO_ATOM_TYPE_EMULATOR_HFP,
+					emulator_hfp_watch, vc, NULL);
 }
 
 void ofono_voicecall_remove(struct ofono_voicecall *vc)

Regards,
-Denis

#4 lore raw

PATCH 3/4 emulator: add API to set network mode and name

In reply to Frédéric Danis
---
 include/emulator.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
include/emulator.h +5 -0
index 701decd..509ec71 100644
@@ -101,6 +101,11 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type(
 void ofono_emulator_set_indicator(struct ofono_emulator *em,
 					const char *name, int value);
 
+void ofono_emulator_set_network_name(struct ofono_emulator *em,
+					const char *name);
+
+void ofono_emulator_set_network_mode(struct ofono_emulator *em, int mode);
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
1.7.1
#5 lore raw

Re: [PATCH 3/4] emulator: add API to set network mode and name

Hi Frédéric,

Quoted 9 lines · Frédéric Danis
---
 include/emulator.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
include/emulator.h +0 -0
index 701decd..509ec71 100644

include/emulator.h enum ofono_emulator_request_type ofono_emulator_request_get_type( · line 108

Quoted 8 lines
include/emulator.h +5 -0
@@ -101,6 +101,11 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type(
 void ofono_emulator_set_indicator(struct ofono_emulator *em,
 					const char *name, int value);
 
+void ofono_emulator_set_network_name(struct ofono_emulator *em,
+					const char *name);
+
+void ofono_emulator_set_network_mode(struct ofono_emulator *em, int mode);
+

I'd really rather do this inside netreg.c itself.

include/emulator.h enum ofono_emulator_request_type ofono_emulator_request_get_type( · line 111

Quoted 3 lines
include/emulator.h +0 -0
 #ifdef __cplusplus
 }
 #endif

Regards,
-Denis

#6 lore raw

PATCH 4/4 emulator: add +COPS support

In reply to Frédéric Danis

This needs to be in emulator as HFP plugin should answer AT+COPS requests even when oFono is not registered on network.

---
 src/emulator.c |   72 ++++++++++++++++++++++++++++++++++++++++++++
 src/network.c  |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 155 insertions(+), 7 deletions(-)
src/emulator.c +72 -0
index 864e50b..eb4f49e 100644
@@ -49,6 +49,8 @@ struct ofono_emulator {
 	int events_mode;
 	gboolean events_ind;
 	GSList *indicators;
+	char op_name[17];
+	int net_mode;
 };
 
 struct indicator {
@@ -387,6 +389,59 @@ fail:
 	}
 }
 
+static void cops_cb(GAtServer *server, GAtServerRequestType type,
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	char buf[32];
+
+	if (em->type == OFONO_EMULATOR_TYPE_HFP && em->slc == FALSE) {
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
+		return;
+	}
+
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		sprintf(buf, "+COPS: %d,0,\"%s\"", em->net_mode, em->op_name);
+		g_at_server_send_info(em->server, buf, TRUE);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int val;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val != 3)
+			goto fail;
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val != 0)
+			goto fail;
+
+		/* check there is no more parameter */
+		if (g_at_result_iter_skip_next(&iter))
+			goto fail;
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+	}
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+
 static void emulator_add_indicator(struct ofono_emulator *em, const char* name,
 					int min, int max, int dflt)
 {
@@ -465,6 +520,7 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "+BRSF", brsf_cb, em, NULL);
 		g_at_server_register(em->server, "+CIND", cind_cb, em, NULL);
 		g_at_server_register(em->server, "+CMER", cmer_cb, em, NULL);
+		g_at_server_register(em->server, "+COPS", cops_cb, em, NULL);
 	}
 
 	__ofono_atom_register(em->atom, emulator_unregister);
@@ -508,6 +564,7 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 	/* TODO: Check real local features */
 	em->l_features = 32;
 	em->events_mode = 3;	/* default mode is forwarding events */
+	em->op_name[0] = '\0';
 
 	em->atom = __ofono_modem_add_atom_offline(modem, atom_t,
 							emulator_remove, em);
@@ -703,3 +760,18 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em,
 		return;
 	}
 }
+
+void ofono_emulator_set_network_name(struct ofono_emulator *em,
+					const char *name)
+{
+	if (name == NULL)
+		return;
+
+	strncpy(em->op_name, name, 16);
+	em->op_name[16] = '\0';
+}
+
+void ofono_emulator_set_network_mode(struct ofono_emulator *em, int mode)
+{
+	em->net_mode = mode;
+}
src/network.c +83 -7

208 lines not on this page · raw message

Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH 4/4] emulator: add +COPS support

Hi Frédéric,

Quoted 25 lines · Frédéric Danis

This needs to be in emulator as HFP plugin should answer AT+COPS requests even when oFono is not registered on network.

---
 src/emulator.c |   72 ++++++++++++++++++++++++++++++++++++++++++++
 src/network.c  |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 155 insertions(+), 7 deletions(-)
src/emulator.c +3 -0
index 864e50b..eb4f49e 100644
@@ -49,6 +49,8 @@ struct ofono_emulator {
 	int events_mode;
 	gboolean events_ind;
 	GSList *indicators;
+	char op_name[17];
+	int net_mode;
 };
 
 struct indicator {
@@ -387,6 +389,59 @@ fail:
 	}
 }
 
+static void cops_cb(GAtServer *server, GAtServerRequestType type,

src/emulator.c fail: · line 402

Quoted 10 lines
src/emulator.c +10 -0
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	char buf[32];
+
+	if (em->type == OFONO_EMULATOR_TYPE_HFP && em->slc == FALSE) {
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
+		return;
+	}
+

There's no need for this if you use ofono_emulator_add_handler since the handler_proxy will take care of this detail.

Quoted 32 lines
src/emulator.c +32 -0
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		sprintf(buf, "+COPS: %d,0,\"%s\"", em->net_mode, em->op_name);
+		g_at_server_send_info(em->server, buf, TRUE);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int val;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val != 3)
+			goto fail;
+
+		if (!g_at_result_iter_next_number(&iter, &val))
+			goto fail;
+
+		if (val != 0)
+			goto fail;
+
+		/* check there is no more parameter */
+		if (g_at_result_iter_skip_next(&iter))
+			goto fail;
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);

src/emulator.c fail: · line 444

Quoted 10 lines
src/emulator.c +10 -0
+		break;
+	}
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+

Please move this function to netreg.c. This should make this patch quite a bit simpler.

<snip>

Regards,
-Denis

#8 lore raw

Re: [PATCH 4/4] emulator: add +COPS support

Hello Denis,

Quoted 88 lines · Denis Kenzior

Hi Frédéric,

Quoted 25 lines · Frédéric Danis

This needs to be in emulator as HFP plugin should answer AT+COPS requests even when oFono is not registered on network.

---
  src/emulator.c |   72 ++++++++++++++++++++++++++++++++++++++++++++
  src/network.c  |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++----
  2 files changed, 155 insertions(+), 7 deletions(-)
src/emulator.c +3 -0
index 864e50b..eb4f49e 100644
@@ -49,6 +49,8 @@ struct ofono_emulator {
  	int events_mode;
  	gboolean events_ind;
  	GSList *indicators;
+	char op_name[17];
+	int net_mode;
  };
 
  struct indicator {
@@ -387,6 +389,59 @@ fail:
  	}
  }
 
+static void cops_cb(GAtServer *server, GAtServerRequestType type,

src/emulator.c fail: · line 402

Quoted 10 lines
src/emulator.c +10 -0
+			GAtResult *result, gpointer user_data)
+{
+	struct ofono_emulator *em = user_data;
+	char buf[32];
+
+	if (em->type == OFONO_EMULATOR_TYPE_HFP&&  em->slc == FALSE) {
+		g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR);
+		return;
+	}
+

There's no need for this if you use ofono_emulator_add_handler since the handler_proxy will take care of this detail.

Quoted 32 lines
src/emulator.c +32 -0
+	switch (type) {
+	case G_AT_SERVER_REQUEST_TYPE_QUERY:
+		sprintf(buf, "+COPS: %d,0,\"%s\"", em->net_mode, em->op_name);
+		g_at_server_send_info(em->server, buf, TRUE);
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
+		break;
+
+	case G_AT_SERVER_REQUEST_TYPE_SET:
+	{
+		GAtResultIter iter;
+		int val;
+
+		g_at_result_iter_init(&iter, result);
+		g_at_result_iter_next(&iter, "");
+
+		if (!g_at_result_iter_next_number(&iter,&val))
+			goto fail;
+
+		if (val != 3)
+			goto fail;
+
+		if (!g_at_result_iter_next_number(&iter,&val))
+			goto fail;
+
+		if (val != 0)
+			goto fail;
+
+		/* check there is no more parameter */
+		if (g_at_result_iter_skip_next(&iter))
+			goto fail;
+
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);

src/emulator.c fail: · line 444

Quoted 10 lines
src/emulator.c +10 -0
+		break;
+	}
+
+	default:
+fail:
+		g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+		break;
+	}
+}
+

Please move this function to netreg.c. This should make this patch quite a bit simpler.

Quoted 4 lines

<snip>

Regards,
-Denis

If this is moved to netreg.c, AT+COPS requests will not be handled when oFono modem is not online.
I understand that there is no problem to reply ERROR to AT+COPS?, but I think this is wrong for AT+COPS=3,0.
This is why I do this in emulator.c.

Signature · 2 lines
Frederic Danis                            Open Source Technology Centre
frederic.danis(a)intel.com                              Intel Corporation