[PATCH 4/5] huawei: implement ussd encoding/decoding



Huawei wants the USSD as packed GSM.
---
 plugins/mm-modem-huawei-gsm.c |   51 +++++++++++++++++++++++++++++++++++++++-
 src/mm-generic-gsm.c          |    2 +-
 src/mm-modem-gsm-ussd.h       |    4 +++
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/plugins/mm-modem-huawei-gsm.c b/plugins/mm-modem-huawei-gsm.c
index e038069..5f4c2fb 100644
--- a/plugins/mm-modem-huawei-gsm.c
+++ b/plugins/mm-modem-huawei-gsm.c
@@ -25,21 +25,25 @@
 #include "mm-modem-huawei-gsm.h"
 #include "mm-modem-gsm-network.h"
 #include "mm-modem-gsm-card.h"
+#include "mm-modem-gsm-ussd.h"
 #include "mm-errors.h"
 #include "mm-callback-info.h"
 #include "mm-at-serial-port.h"
 #include "mm-serial-parsers.h"
 #include "mm-log.h"
+#include "mm-utils.h"
 
 static void modem_init (MMModem *modem_class);
 static void modem_gsm_network_init (MMModemGsmNetwork *gsm_network_class);
 static void modem_gsm_card_init (MMModemGsmCard *gsm_card_class);
+static void modem_gsm_ussd_init (MMModemGsmUssd *ussd_class);
 
 G_DEFINE_TYPE_EXTENDED (MMModemHuaweiGsm, mm_modem_huawei_gsm, MM_TYPE_GENERIC_GSM, 0,
                         G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init)
                         G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_GSM_NETWORK, modem_gsm_network_init)
-                        G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_GSM_CARD, modem_gsm_card_init))
-
+                        G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_GSM_CARD, modem_gsm_card_init)
+                        G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM_GSM_USSD, modem_gsm_ussd_init)
+)
 
 #define MM_MODEM_HUAWEI_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_HUAWEI_GSM, MMModemHuaweiGsmPrivate))
 
@@ -874,6 +878,42 @@ out:
     return !!port;
 }
 
+/* Encode to packed GSM - this is what Huawei supports on all known models */
+static char*
+ussd_encode (MMModemGsmUssd *self, const char* command, guint *scheme)
+{
+    char *hex;
+    guint8 *gsm, *packed;
+    guint32 len = 0, packed_len = 0;
+
+    *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT;
+    gsm = mm_charset_utf8_to_unpacked_gsm (command, &len);
+    packed = gsm_pack (gsm, len, 0, &packed_len);
+    hex = utils_bin2hexstr (packed, packed_len);
+    g_free (packed);
+    g_free (gsm);
+
+    return hex;
+}
+
+/* Unparse packed gsm to utf8 */
+static char*
+ussd_decode (MMModemGsmUssd *self, const char* reply, guint scheme)
+{
+    char *bin, *utf8;
+    guint8 *unpacked;
+    gsize bin_len;
+    guint32 unpacked_len;
+
+    bin = utils_hexstr2bin (reply, &bin_len);
+    unpacked = gsm_unpack ((guint8*)bin, bin_len, 0, &unpacked_len);
+    utf8 = (char*)mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len);
+
+    g_free (bin);
+    g_free (unpacked);
+    return utf8;
+}
+
 /*****************************************************************************/
 
 static void
@@ -902,6 +942,13 @@ mm_modem_huawei_gsm_init (MMModemHuaweiGsm *self)
 }
 
 static void
+modem_gsm_ussd_init (MMModemGsmUssd *ussd_class)
+{
+    ussd_class->encode = ussd_encode;
+    ussd_class->decode = ussd_decode;
+}
+
+static void
 mm_modem_huawei_gsm_class_init (MMModemHuaweiGsmClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index 83e7a0b..0c6f9d8 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -4792,9 +4792,9 @@ ussd_encode (MMModemGsmUssd *modem, const char* command, guint *scheme)
     if (!success)
         goto out;
 
+    *scheme = MM_MODEM_GSM_USSD_SCHEME_7BIT;
     /* convert to hex representation */
     hex = utils_bin2hexstr (ussd_command->data, ussd_command->len);
-    *scheme = 15;
 
  out:
     g_byte_array_free (ussd_command, TRUE);
diff --git a/src/mm-modem-gsm-ussd.h b/src/mm-modem-gsm-ussd.h
index 6859d73..04d2be8 100644
--- a/src/mm-modem-gsm-ussd.h
+++ b/src/mm-modem-gsm-ussd.h
@@ -80,6 +80,10 @@ void mm_modem_gsm_ussd_cancel (MMModemGsmUssd *self,
                                MMModemFn callback,
                                gpointer user_data);
 
+/* CBS data coding scheme - 3GPP TS 23.038 */
+#define MM_MODEM_GSM_USSD_SCHEME_7BIT 0b00001111;
+#define MM_MODEM_GSM_USSD_SCHEME_UCS2 0b01001000;
+
 char *mm_modem_gsm_ussd_encode (MMModemGsmUssd *self,
                                 const char* command,
                                 guint *scheme);
-- 
1.7.5.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]