---
 plugins/phonesim.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index d3caa20..521e8ae 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -64,6 +64,7 @@
 #include <drivers/atmodem/atutil.h>
 
 static const char *none_prefix[] = { NULL };
+static const char *cscs_prefix[] = { "+CSCS:", NULL };
 
 struct phonesim_data {
        GAtMux *mux;
@@ -72,6 +73,57 @@ struct phonesim_data {
        gboolean use_mux;
 };
 
+static const char *best_charset(int supported)
+{
+       const char *charset = "Invalid";
+
+       if (supported & AT_UTIL_CHARSET_UCS2)
+               charset = "UCS2";
+
+       if (supported & AT_UTIL_CHARSET_GSM)
+               charset = "GSM";
+
+       return charset;
+}
+
+static void set_charset_cb(gboolean ok, GAtResult *result,
+                               gpointer user_data)
+{
+       if (!ok)
+               ofono_error("Setting character set failed");
+}
+
+static void list_charsets_cb(gboolean ok, GAtResult *result,
+                               gpointer user_data)
+{
+       struct ofono_modem *modem = user_data;
+       struct phonesim_data *data = 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);
+
+       if (!g_at_chat_send(data->chat, buf, none_prefix, set_charset_cb, 
+                       modem, NULL))
+               ofono_error("Setting charset: %s failed", charset);
+}
+
+static void list_charsets(struct ofono_modem *modem)
+{
+       struct phonesim_data *data = ofono_modem_get_data(modem);
+       if (!g_at_chat_send(data->chat, "AT+CSCS=?", cscs_prefix,
+                       list_charsets_cb, modem, NULL))
+               ofono_error("AT+CSCS=? request failed");
+}
+
 static int phonesim_probe(struct ofono_modem *modem)
 {
        struct phonesim_data *data;
@@ -321,6 +373,8 @@ static void phonesim_pre_sim(struct ofono_modem *modem)
 
        if (sim)
                ofono_sim_inserted_notify(sim, TRUE);
+
+       list_charsets(modem);
 }
 
 static void phonesim_post_sim(struct ofono_modem *modem)
-- 
1.7.0.4

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to