---
plugins/atgen.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/plugins/atgen.c b/plugins/atgen.c
index 1ce2467..1b898b7 100644
--- a/plugins/atgen.c
+++ b/plugins/atgen.c
@@ -25,6 +25,8 @@
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
#include <glib.h>
#include <gatchat.h>
@@ -55,6 +57,9 @@
#include <ofono/gprs.h>
#include <ofono/gprs-context.h>
+static const char *none_prefix[] = { NULL };
+static const char *cscs_prefix[] = { "+CSCS:", NULL };
+
static const char *tty_opts[] = {
"Baud",
"Read",
@@ -67,6 +72,48 @@ static const char *tty_opts[] = {
NULL,
};
+static const char *best_charset(int supported)
+{
+ const char *charset = "Invalid";
+
+ if (supported & AT_UTIL_CHARSET_GSM)
+ charset = "GSM";
+
+ if (supported & AT_UTIL_CHARSET_UTF8)
+ charset = "UTF-8";
+
+ return charset;
+}
+
+static void list_charsets_cb(gboolean ok, GAtResult *result,
+ gpointer user_data)
+{
+ struct ofono_modem *modem = user_data;
+ GAtChat *chat = ofono_modem_get_data(modem);
+ const char *charset;
+ int supported = 0;
+ char buf[32];
+
+ if (!ok)
+ return;
+
+ if (!at_util_parse_cscs_supported(result, &supported))
+ return;
+
+ charset = best_charset(supported);
+ snprintf(buf, sizeof(buf), "AT+CSCS=\"%s\"", charset);
+
+ g_at_chat_send(chat, buf, none_prefix, NULL, NULL, NULL);
+}
+
+static void list_charsets(struct ofono_modem *modem)
+{
+ GAtChat *chat = ofono_modem_get_data(modem);
+
+ g_at_chat_send(chat, "AT+CSCS=?", cscs_prefix,
+ list_charsets_cb, modem, NULL);
+}
+
static int atgen_probe(struct ofono_modem *modem)
{
return 0;
@@ -207,6 +254,8 @@ static void atgen_pre_sim(struct ofono_modem *modem)
if (sim)
ofono_sim_inserted_notify(sim, TRUE);
+
+ list_charsets(modem);
}
static void atgen_post_sim(struct ofono_modem *modem)
--
1.7.0.4