bluetooth: add CIND and CIEV support in HFP AG
v3 cover bluetooth: add CIND and CIEV support in HFP AG
Add indicator support in emulator atom
Add CIND and CIEV support for HFP AG
Frédéric Danis (3):
emulator: add indicator support API
emulator: add support of indicators
emulator: add CIND support
include/emulator.h | 11 ++++ src/emulator.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/network.c | 77 +++++++++++++++++++++++++++- 3 files changed, 232 insertions(+), 1 deletions(-)
PATCH v3 1/3 emulator: add indicator support API
--- include/emulator.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
include/emulator.h +11 -0
@@ -28,6 +28,14 @@ extern "C" {#include <ofono/types.h> +#define OFONO_EMULATOR_IND_BATTERY "battchg" +#define OFONO_EMULATOR_IND_CALL "call" +#define OFONO_EMULATOR_IND_CALLHELD "callheld" +#define OFONO_EMULATOR_IND_CALLSETUP "callsetup" +#define OFONO_EMULATOR_IND_ROAMING "roam" +#define OFONO_EMULATOR_IND_SERVICE "service" +#define OFONO_EMULATOR_IND_SIGNAL "signal" +struct ofono_emulator ;struct ofono_emulator_request ;
@@ -82,6 +90,9 @@ const char *ofono_emulator_request_get_raw(struct ofono_emulator_request *req);enum ofono_emulator_request_type ofono_emulator_request_get_type (struct ofono_emulator_request *req); +void ofono_emulator_set_indicator (struct ofono_emulator *em, +const char *name,int value); + #ifdef __cplusplus }#endif
Signature · 1 line
1.7.1
Re: [PATCH 1/3] emulator: add indicator support API
Hi Frédéric,
Quoted 4 lines · Frédéric Danis
--- include/emulator.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
Patch has been applied, thanks.
Regards,
-Denis
PATCH v3 2/3 emulator: add support of indicators
In reply to Frédéric Danis--- src/emulator.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/network.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 1 deletions(-)
src/emulator.c +72 -0
@@ -24,6 +24,7 @@#endif #include <stdio.h> +#include <string.h> #include <glib.h>
@@ -42,6 +43,14 @@ struct ofono_emulator {GAtServer *server;GAtPPP *ppp;guint source; +GSList *indicators; +}; + +struct indicator { +char *name; +int value; +int min; +int max; };static void emulator_debug (const char *str,void *data)
@@ -163,9 +172,29 @@ error:g_at_server_send_final (em->server,G_AT_SERVER_RESULT_ERROR ); } +static void emulator_add_indicator (struct ofono_emulator *em,const char * name, +int min,int max,int dflt) +{ +struct indicator *ind; + + ind = g_try_new0(struct indicator, 1); +if (ind ==NULL ) { +ofono_error ("Unable to allocate indicator structure" ); +return ; + } + + ind->name =g_strdup (name); + ind->min = min; + ind->max = max; + ind->value = dflt; + + em->indicators =g_slist_append (em->indicators, ind); +} +static void emulator_unregister (struct ofono_atom *atom) {struct ofono_emulator *em =__ofono_atom_get_data (atom); +GSList *l;DBG ("%p" , em);
@@ -174,6 +203,14 @@ static void emulator_unregister(struct ofono_atom *atom) em->source =0 ; } +for (l = em->indicators; l; l = em->indicators) { +struct indicator *ind = l->data; + + em->indicators =g_slist_remove (em->indicators, ind); +g_free (ind->name); +g_free (ind); + } +g_at_server_unref (em->server); em->server =NULL ; }
@@ -199,6 +236,13 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)g_at_server_set_disconnect_function (em->server, emulator_disconnect, em); +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_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 ); + } +__ofono_atom_register (em->atom, emulator_unregister);if (em->type ==OFONO_EMULATOR_TYPE_DUN )
@@ -397,3 +441,31 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type( {return req->type; } + +void ofono_emulator_set_indicator (struct ofono_emulator *em, +const char *name,int value) +{ +GSList *l; +int i; +char buf[20 ]; + + i =1 ; +for (l = em->indicators; l; l = l->next) { +struct indicator *ind = l->data; + +if (!strcmp (ind->name, name)) { +if ((ind->value == value) || (value < ind->min) + || (value > ind->max)) +return ; + + ind->value = value; + +sprintf (buf,"+CIEV: %d,%d" , i, ind->value); +g_at_server_send_info (em->server, buf, TRUE); + +break ; + } + + i++; + } +}
src/network.c +76 -1
136 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v3 3/3 emulator: add CIND support
In reply to Frédéric Danis--- src/emulator.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-)
src/emulator.c +73 -0
@@ -172,6 +172,77 @@ error:g_at_server_send_final (em->server,G_AT_SERVER_RESULT_ERROR ); } +static void cind_cb (GAtServer *server,GAtServerRequestType type, +GAtResult *result,gpointer user_data) +{ +struct ofono_emulator *em = user_data; +GSList *l; +struct indicator *ind; +gsize size; +int len; +char *buf; +char *tmp; + +switch (type) { +case G_AT_SERVER_REQUEST_TYPE_QUERY : + size =7 + (g_slist_length (em->indicators) *4 ) +1 ; + buf =g_try_malloc0 (size); +if (buf ==NULL ) + goto fail; + + len =sprintf (buf,"+CIND: " ); + tmp = buf + len; + +for (l = em->indicators; l; l = l->next) { + ind = l->data; + len =sprintf (tmp,"%s%d" , + l == em->indicators ?"" :"," , + ind->value); + tmp = tmp + len; + } + +g_at_server_send_info (em->server, buf, FALSE); +g_free (buf); +g_at_server_send_final (server,G_AT_SERVER_RESULT_OK ); +break ; + +case G_AT_SERVER_REQUEST_TYPE_SUPPORT : + size =8 ; + +for (l = em->indicators; l; l = l->next) { + ind = l->data; + size +=strlen (ind->name) +15 ; + } + + buf =g_try_malloc0 (size); +if (buf ==NULL ) + goto fail; + + len =sprintf (buf,"+CIND: " ); + tmp = buf + len; + +for (l = em->indicators; l; l = l->next) { + ind = l->data; + len =sprintf (tmp,"%s(\"%s\",(%d%c%d))" , + l == em->indicators ?"" :"," , + ind->name, ind->min, + (ind->max - ind->min) ==1 ?',' :'-' , + ind->max); + tmp = tmp + len; + } + +g_at_server_send_info (server, buf, FALSE); +g_free (buf); +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) {
@@ -241,6 +312,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)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 ); + +g_at_server_register (em->server,"+CIND" , cind_cb, em,NULL ); }__ofono_atom_register (em->atom, emulator_unregister);
Signature · 1 line
1.7.1