diff options
-rw-r--r-- | audio/headset.c | 57 | ||||
-rw-r--r-- | audio/telephony-dummy.c | 23 | ||||
-rw-r--r-- | audio/telephony.h | 8 |
3 files changed, 85 insertions, 3 deletions
diff --git a/audio/headset.c b/audio/headset.c index 64749053..7edb0d30 100644 --- a/audio/headset.c +++ b/audio/headset.c @@ -215,16 +215,67 @@ static int supported_features(struct audio_device *device, const char *buf) return headset_send(hs, "\r\nOK\r\n"); } +static char *indicator_ranges(struct indicator *indicators) +{ + int i; + GString *gstr; + + gstr = g_string_new("\r\n+CIND:"); + + for (i = 0; indicators[i].desc != NULL; i++) { + if (i == 0) + g_string_append_printf(gstr, "(\"%s\",(%s))", + indicators[i].desc, + indicators[i].range); + else + g_string_append_printf(gstr, ",(\"%s\",(%s))", + indicators[i].desc, + indicators[i].range); + } + + g_string_append(gstr, "\r\n"); + + return g_string_free(gstr, FALSE); +} + +static char *indicator_values(struct indicator *indicators) +{ + int i; + GString *gstr; + + gstr = g_string_new("\r\n+CIND:"); + + for (i = 0; indicators[i].desc != NULL; i++) { + if (i == 0) + g_string_append_printf(gstr, "%d", indicators[i].val); + else + g_string_append_printf(gstr, ",%d", indicators[i].val); + } + + g_string_append(gstr, "\r\n"); + + return g_string_free(gstr, FALSE); +} + static int report_indicators(struct audio_device *device, const char *buf) { struct headset *hs = device->headset; int err; + char *str; + struct indicator *indicators; + + indicators = telephony_indicators_req(); + if (!indicators) + return headset_send(hs, "\r\nERROR\r\n"); if (buf[7] == '=') - err = headset_send(hs, "\r\n+CIND:(\"service\",(0,1))," - "(\"call\",(0,1)),(\"callsetup\",(0-3))\r\n"); + str = indicator_ranges(indicators); else - err = headset_send(hs, "\r\n+CIND:1,0,0\r\n"); + str = indicator_values(indicators); + + err = headset_send(hs, str); + + g_free(str); if (err < 0) return err; diff --git a/audio/telephony-dummy.c b/audio/telephony-dummy.c index 9d07f56a..5a9f244d 100644 --- a/audio/telephony-dummy.c +++ b/audio/telephony-dummy.c @@ -26,8 +26,26 @@ #include <config.h> #endif +#include <stdlib.h> +#include <stdio.h> + #include "telephony.h" +static struct indicator indicators[] = +{ + { "battchg", "0-5", 5 }, + { "signal", "0-5", 5 }, + { "service", "0,1", 1 }, + { "sounder", "0,1", 0 }, + { "message", "0,1", 0 }, + { "call", "0,1", 0 }, + { "callsetup", "0-3", 0 }, + { "vox", "0,1", 0 }, + { "roam", "0,1", 0 }, + { "smsfull", "0,1", 0 }, + { NULL } +}; + int telephony_init(void) { return 0; @@ -45,3 +63,8 @@ int telephony_features_req(void) return 0; } + +struct indicator *telephony_indicators_req(void) +{ + return indicators; +} diff --git a/audio/telephony.h b/audio/telephony.h index 67887ca9..2fca71ab 100644 --- a/audio/telephony.h +++ b/audio/telephony.h @@ -24,6 +24,12 @@ #include <stdint.h> +struct indicator { + const char *desc; + const char *range; + int val; +}; + int telephony_init(void); void telephony_exit(void); @@ -31,3 +37,5 @@ void telephony_exit(void); int telephony_features_req(void); void telephony_features_rsp(uint32_t features); + +struct indicator *telephony_indicators_req(void); |