emulator: add simple incoming call support
cover emulator: add simple incoming call support
Add call related indicators, +CLIP, RING to signal incoming call, ATA to allow reception and AT+CHUP to reject or finish of an incoming call in HFP AG
Frédéric Danis (7):
emulator: add defines for call, callsetup and callheld indicators
emulator: add call, callsetup and callheld indicators
emulator: add RING for HFP AG
emulator: add incoming call API
emulator: add +CLIP support for HFP AG
voicecall: add ATA support for HFP emulator
voicecall: add +CHUP support for HFP emulator
include/emulator.h | 15 +++ src/emulator.c | 106 ++++++++++++++++++ src/voicecall.c | 306 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 427 insertions(+), 0 deletions(-)
PATCH 1/7 emulator: add defines for call, callsetup and callheld indicators
--- include/emulator.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
include/emulator.h +12 -0
@@ -36,6 +36,18 @@ 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 + +#define OFONO_EMULATOR_CALLHELD_NONE 0 +#define OFONO_EMULATOR_CALLHELD_MULTIPLE 1 +#define OFONO_EMULATOR_CALLHELD_ON_HOLD 2 +struct ofono_emulator ;struct ofono_emulator_request ;
Signature · 1 line
1.7.1
PATCH 2/7 emulator: add call, callsetup and callheld indicators
In reply to Frédéric Danis--- src/emulator.c | 5 ++ src/voicecall.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 0 deletions(-)
src/emulator.c +5 -0
@@ -455,6 +455,11 @@ 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_CALLHELD ,0 ,2 , +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 +131 -0
173 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 3/7 emulator: add RING for HFP AG
In reply to Frédéric Danis--- src/emulator.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)
src/emulator.c +45 -0
@@ -37,6 +37,8 @@#define DUN_DNS_SERVER_1 "10.10.10.10"#define DUN_DNS_SERVER_2 "10.10.10.11" +#define RING_TIMEOUT 3 +struct ofono_emulator {struct ofono_atom *atom;enum ofono_emulator_type type;
@@ -49,6 +51,8 @@ struct ofono_emulator {int events_mode;gboolean events_ind;GSList *indicators; +guint ring; +gboolean active_call; };struct indicator {
@@ -177,6 +181,18 @@ error:g_at_server_send_final (em->server,G_AT_SERVER_RESULT_ERROR ); } +static gboolean ring_cb (gpointer user_data) +{ +struct ofono_emulator *em = user_data; + +if (em->type ==OFONO_EMULATOR_TYPE_HFP && em->slc == FALSE) +return TRUE; + +g_at_server_send_unsolicited (em->server,"RING" ); + +return TRUE; +} +static void brsf_cb (GAtServer *server,GAtServerRequestType type,GAtResult *result,gpointer user_data) {
@@ -418,6 +434,11 @@ static void emulator_unregister(struct ofono_atom *atom) em->source =0 ; } +if (em->ring) { +g_source_remove (em->ring); + em->ring =0 ; + } +for (l = em->indicators; l; l = l->next) {struct indicator *ind = l->data;
@@ -697,11 +718,35 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em, ind->value = value; +if (g_str_equal (name,OFONO_EMULATOR_IND_CALL ) == TRUE) + em->active_call = value; +if (em->events_mode ==3 && em->events_ind && em->slc) {sprintf (buf,"+CIEV: %d,%d" , i, ind->value);g_at_server_send_info (em->server, buf, TRUE); } +/* +* Ring timer should be started when callsetup indicator +* is set to Incoming, but only if there is no active or held +* call (active indicator set to 1) +* It should be stopped for all other values of callsetup +*/ +if (g_str_equal (name,OFONO_EMULATOR_IND_CALLSETUP ) == TRUE) { +if (value ==OFONO_EMULATOR_CALLSETUP_INCOMING && + !em->active_call && em->ring ==0 ) { +ring_cb (em); + em->ring =g_timeout_add_seconds (RING_TIMEOUT , + ring_cb, em); + } + +if (value !=OFONO_EMULATOR_CALLSETUP_INCOMING && + em->ring) { +g_source_remove (em->ring); + em->ring =0 ; + } + } +return ; } }
Signature · 1 line
1.7.1
Re: [PATCH 3/7] emulator: add RING for HFP AG
j'aime pas cette variable
+ gboolean active_call;
d'autant plus que call est le premier indicateur de la liste, c'est donc une copie de ((struct indicator*)indicators->data)->value
Quoted 93 lines · Frédéric Danis
--- src/emulator.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)src/emulator.c +45
-0@@ -37,6 +37,8 @@#define DUN_DNS_SERVER_1 "10.10.10.10"#define DUN_DNS_SERVER_2 "10.10.10.11" +#define RING_TIMEOUT 3 +struct ofono_emulator {struct ofono_atom *atom;enum ofono_emulator_type type;@@ -49,6 +51,8 @@ struct ofono_emulator {int events_mode;gboolean events_ind;GSList *indicators; +guint ring; +gboolean active_call; };struct indicator {@@ -177,6 +181,18 @@ error:g_at_server_send_final (em->server,G_AT_SERVER_RESULT_ERROR ); } +static gboolean ring_cb (gpointer user_data) +{ +struct ofono_emulator *em = user_data; + +if (em->type ==OFONO_EMULATOR_TYPE_HFP && em->slc == FALSE) +return TRUE; + +g_at_server_send_unsolicited (em->server,"RING" ); + +return TRUE; +} +static void brsf_cb (GAtServer *server,GAtServerRequestType type,GAtResult *result,gpointer user_data) {@@ -418,6 +434,11 @@ static void emulator_unregister(struct ofono_atom *atom) em->source =0 ; } +if (em->ring) { +g_source_remove (em->ring); + em->ring =0 ; + } +for (l = em->indicators; l; l = l->next) {struct indicator *ind = l->data;@@ -697,11 +718,35 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em, ind->value = value; +if (g_str_equal (name,OFONO_EMULATOR_IND_CALL ) == TRUE) + em->active_call = value; +if (em->events_mode ==3 && em->events_ind&& em->slc) {sprintf (buf,"+CIEV: %d,%d" , i, ind->value);g_at_server_send_info (em->server, buf, TRUE); } +/* +* Ring timer should be started when callsetup indicator +* is set to Incoming, but only if there is no active or held +* call (active indicator set to 1) +* It should be stopped for all other values of callsetup +*/ +if (g_str_equal (name,OFONO_EMULATOR_IND_CALLSETUP ) == TRUE) { +if (value ==OFONO_EMULATOR_CALLSETUP_INCOMING && + !em->active_call&& em->ring ==0 ) { +ring_cb (em); + em->ring =g_timeout_add_seconds (RING_TIMEOUT , + ring_cb, em); + } + +if (value !=OFONO_EMULATOR_CALLSETUP_INCOMING && + em->ring) { +g_source_remove (em->ring); + em->ring =0 ; + } + } +return ; } }
Re: [PATCH 3/7] emulator: add RING for HFP AG
Dear list,
Quoted 7 lines · Frédéric Dalleau
j'aime pas cette variable
+ gboolean
active_call;d'autant plus que call est le premier indicateur de la liste, c'est donc une copie de ((struct indicator*)indicators->data)->value
Sorry for the spam,
Frederic Dalleau
PATCH 4/7 emulator: add incoming call API
In reply to Frédéric Danis--- include/emulator.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
include/emulator.h +3 -0
@@ -105,6 +105,9 @@ 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_incoming_call (struct ofono_emulator *em, +struct ofono_call *call); + #ifdef __cplusplus }#endif
Signature · 1 line
1.7.1
PATCH 5/7 emulator: add +CLIP support for HFP AG
In reply to Frédéric Danis--- src/emulator.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/voicecall.c | 17 ++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-)
src/emulator.c +56 -0
@@ -29,6 +29,7 @@#include <glib.h> #include "ofono.h" +#include "common.h" #include "gatserver.h" #include "gatppp.h"
@@ -53,6 +54,9 @@ struct ofono_emulator {GSList *indicators;guint ring;gboolean active_call; +struct ofono_call *incoming; +gboolean clip; +char clip_str[OFONO_MAX_PHONE_NUMBER_LENGTH +13 +1 ]; };struct indicator {
@@ -184,12 +188,25 @@ error:static gboolean ring_cb (gpointer user_data) {struct ofono_emulator *em = user_data; +const char *phone;if (em->type ==OFONO_EMULATOR_TYPE_HFP && em->slc == FALSE)return TRUE;g_at_server_send_unsolicited (em->server,"RING" ); +if (!em->clip || !em->incoming || + em->incoming->clip_validity !=CLIP_VALIDITY_VALID ) +return TRUE; + +if (em->clip_str[0 ] =='\0' ) { + phone =phone_number_to_string (&em->incoming->phone_number); +sprintf (em->clip_str,"+CLIP: \"%s\",%d" , phone, + em->incoming->phone_number.type); + } + +g_at_server_send_unsolicited (em->server, em->clip_str); +return TRUE; }
@@ -403,6 +420,35 @@ fail: } } +static void clip_cb (GAtServer *server,GAtServerRequestType type, +GAtResult *result,gpointer user_data) +{ +struct ofono_emulator *em = user_data; +GAtResultIter iter; +int val; + +switch (type) { +case G_AT_SERVER_REQUEST_TYPE_SET : +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 !=0 && val !=1 ) + goto fail; + + em->clip = val; + +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 ); + }; +} +static void emulator_add_indicator (struct ofono_emulator *em,const char * name,int min,int max,int dflt) {
@@ -488,6 +534,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,"+CLIP" , clip_cb, em,NULL ); }__ofono_atom_register (em->atom, emulator_unregister);
@@ -531,6 +578,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->clip_str[0 ] ='\0' ; em->atom =__ofono_modem_add_atom_offline (modem, atom_t, emulator_remove, em);
@@ -744,9 +792,17 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em, em->ring) {g_source_remove (em->ring); em->ring =0 ; + em->incoming =NULL ; + em->clip_str[0 ] ='\0' ; } }return ; } } + +void ofono_emulator_incoming_call (struct ofono_emulator *em, +struct ofono_call *call) +{ + em->incoming = call; +}
src/voicecall.c +15 -2
@@ -714,6 +714,13 @@ static void emulator_callheld_status_cb(struct ofono_atom *atom, void *data) GPOINTER_TO_INT(data)); } +static void emulator_incoming_cb (struct ofono_atom *atom,void *data) +{ +struct ofono_emulator *em =__ofono_atom_get_data (atom); + +ofono_emulator_incoming_call (em, data); +} +static void notify_emulator_call_status (struct ofono_voicecall *vc) {struct ofono_modem *modem =__ofono_atom_get_modem (vc->atom);
@@ -726,6 +733,7 @@ static void notify_emulator_call_status(struct ofono_voicecall *vc)gboolean waiting = FALSE;GSList *l;struct voicecall *v; +struct ofono_call *caller =NULL ;for (l = vc->call_list; l; l = l->next) { v = l->data;
@@ -749,10 +757,12 @@ static void notify_emulator_call_status(struct ofono_voicecall *vc)case CALL_STATUS_INCOMING : incoming = TRUE; + caller = v->call;break ;case CALL_STATUS_WAITING : waiting = TRUE; + caller = v->call;break ; } }
@@ -765,9 +775,12 @@ static void notify_emulator_call_status(struct ofono_voicecall *vc) emulator_call_status_cb, GINT_TO_POINTER(status)); -if (incoming || waiting) +if (incoming || waiting) { status =OFONO_EMULATOR_CALLSETUP_INCOMING ; -else if (dialing) +__ofono_modem_foreach_registered_atom (modem, +OFONO_ATOM_TYPE_EMULATOR_HFP , + emulator_incoming_cb, caller); + }else if (dialing) status =OFONO_EMULATOR_CALLSETUP_OUTGOING ;else if (alerting) status =OFONO_EMULATOR_CALLSETUP_ALERTING ;
Signature · 1 line
1.7.1
PATCH 6/7 voicecall: add ATA support for HFP emulator
In reply to Frédéric Danis--- src/voicecall.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 56 insertions(+), 2 deletions(-)
src/voicecall.c +56 -2
@@ -2314,6 +2314,13 @@ void ofono_voicecall_driver_unregister(const struct ofono_voicecall_driver *d) g_drivers =g_slist_remove (g_drivers, (void *) d); } +static void emulator_remove_handler (struct ofono_atom *atom,void *data) +{ +struct ofono_emulator *em =__ofono_atom_get_data (atom); + +ofono_emulator_remove_handler (em, data); +} +static void voicecall_unregister (struct ofono_atom *atom) {DBusConnection *conn =ofono_dbus_get_connection ();
@@ -2333,6 +2340,11 @@ static void voicecall_unregister(struct ofono_atom *atom)OFONO_ATOM_TYPE_EMULATOR_HFP , emulator_callheld_status_cb, 0); +__ofono_modem_foreach_registered_atom (modem, +OFONO_ATOM_TYPE_EMULATOR_HFP , + emulator_remove_handler, +"A" ); +__ofono_modem_remove_atom_watch (modem, vc->hfp_watch);if (vc->sim_watch) {
@@ -2510,12 +2522,54 @@ static void sim_watch(struct ofono_atom *atom,sim_state_watch (ofono_sim_get_state (sim), vc); } +static void emulator_generic_cb (const struct ofono_error *error,void *data) +{ +struct ofono_emulator *em = data; +struct ofono_error result; + + result.type = error->type; + +ofono_emulator_send_final (em, &result); +} + +static void emulator_ata_cb (struct ofono_emulator *em, +struct ofono_emulator_request *req,void *userdata) +{ +struct ofono_voicecall *vc = userdata; +struct ofono_error result; + + result.error =0 ; + +switch (ofono_emulator_request_get_type (req)) { +case OFONO_EMULATOR_REQUEST_TYPE_COMMAND_ONLY : +if (!voicecalls_have_incoming (vc)) + goto fail; + +if (vc->driver->answer ==NULL ) + goto fail; + + vc->driver->answer (vc, emulator_generic_cb, em); +break ; + +default : +fail: + result.type =OFONO_ERROR_TYPE_FAILURE ; +ofono_emulator_send_final (em, &result); + }; +} +static void emulator_hfp_watch (struct ofono_atom *atom,enum ofono_atom_watch_condition cond,void *data) { -if (cond ==OFONO_ATOM_WATCH_CONDITION_REGISTERED ) -notify_emulator_call_status (data); +struct ofono_emulator *em =__ofono_atom_get_data (atom); + +if (cond !=OFONO_ATOM_WATCH_CONDITION_REGISTERED ) +return ; + +notify_emulator_call_status (data); + +ofono_emulator_add_handler (em,"A" , emulator_ata_cb, data,NULL ); }void ofono_voicecall_register (struct ofono_voicecall *vc)
Signature · 1 line
1.7.1
PATCH 7/7 voicecall: add +CHUP support for HFP emulator
In reply to Frédéric Danis--- src/voicecall.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 108 insertions(+), 0 deletions(-)
src/voicecall.c +108 -0
@@ -60,6 +60,7 @@ struct ofono_voicecall {GQueue *toneq;guint tone_source;unsigned int hfp_watch; +GSList *hfp_release_list; };struct voicecall {
@@ -95,6 +96,11 @@ struct tone_queue_entry {int id; }; +struct emulator_release { +struct ofono_voicecall *vc; +struct ofono_emulator *em; +}; +static const char *default_en_list[] = {"911" ,"112" ,NULL };static const char *default_en_list_no_sim[] = {"119" ,"118" ,"999" ,"110" ,"08" ,"000" ,NULL };
@@ -102,6 +108,7 @@ static const char *default_en_list_no_sim[] = { "119", "118", "999", "110",static void generic_callback (const struct ofono_error *error,void *data);static void multirelease_callback (const struct ofono_error *err,void *data);static gboolean tone_request_run (gpointer user_data); +static void emulator_release_next (struct emulator_release *er);static gint call_compare_by_id (gconstpointer a,gconstpointer b) {
@@ -2344,6 +2351,10 @@ static void voicecall_unregister(struct ofono_atom *atom)OFONO_ATOM_TYPE_EMULATOR_HFP , emulator_remove_handler, "A"); +__ofono_modem_foreach_registered_atom (modem, +OFONO_ATOM_TYPE_EMULATOR_HFP , + emulator_remove_handler, +"+CHUP" );__ofono_modem_remove_atom_watch (modem, vc->hfp_watch);
@@ -2558,6 +2569,102 @@ fail: }; } +static void emulator_multirelease_callback (const struct ofono_error *error, +void *data) +{ +struct emulator_release *er = data; +struct ofono_voicecall *vc = er->vc; + +if (vc->hfp_release_list !=NULL ) { +emulator_release_next (er); +return ; + } + +emulator_generic_cb (error, er->em); + +g_free (er); +} + +static void emulator_release_next (struct emulator_release *er) +{ +struct ofono_voicecall *vc; +struct voicecall *call; + + vc = er->vc; + + call = vc->hfp_release_list->data; + + vc->hfp_release_list =g_slist_remove (vc->hfp_release_list, call); + + vc->driver->release_specific (vc, call->call->id, + emulator_multirelease_callback, er); +} + +static void emulator_chup_cb (struct ofono_emulator *em, +struct ofono_emulator_request *req,void *userdata) +{ +struct ofono_voicecall *vc = userdata; +struct ofono_error result; +struct emulator_release *er; +GSList *l; +struct voicecall *call; + + result.error =0 ; + +switch (ofono_emulator_request_get_type (req)) { +case OFONO_EMULATOR_REQUEST_TYPE_COMMAND_ONLY : +if (vc->driver->release_specific ==NULL && + vc->driver->hangup_active ==NULL ) + goto fail; + +if (vc->driver->hangup_active) { + vc->driver->hangup_active (vc, emulator_generic_cb, em); + goto done; + } + +/* if there is already a CHUP pending we return an error */ +if (vc->hfp_release_list) + goto fail; + + er = g_try_new0(struct emulator_release, 1); +if (er ==NULL ) { +ofono_error ("Unable to allocate release structure" ); + goto fail; + } + + er->vc = vc; + er->em = em; + +for (l = vc->call_list; l; l = l->next) { + call = l->data; + +if (call->call->status ==CALL_STATUS_WAITING || + call->call->status ==CALL_STATUS_HELD ) +continue ; + + vc->hfp_release_list =g_slist_prepend ( + vc->hfp_release_list, + l->data); + } + +if (vc->hfp_release_list ==NULL ) { +g_free (er); + goto fail; + } + +emulator_release_next (er); + +done: +dial_request_user_cancel (vc,NULL ); +break ; + +default : +fail: + result.type =OFONO_ERROR_TYPE_FAILURE ; +ofono_emulator_send_final (em, &result); + }; +} +static void emulator_hfp_watch (struct ofono_atom *atom,enum ofono_atom_watch_condition cond,void *data)
@@ -2570,6 +2677,7 @@ static void emulator_hfp_watch(struct ofono_atom *atom,notify_emulator_call_status (data);ofono_emulator_add_handler (em,"A" , emulator_ata_cb, data,NULL ); +ofono_emulator_add_handler (em,"+CHUP" , emulator_chup_cb, data,NULL ); }void ofono_voicecall_register (struct ofono_voicecall *vc)
Signature · 1 line
1.7.1