diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-07-21 15:15:09 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-07-21 15:16:44 -0500 |
commit | 70715c1c124b3220969a432be5ad2ad6f44913fe (patch) | |
tree | 59e70bb7f0559320caeafaa0701806e7d954c97f | |
parent | b82cec8c7e0aaab04a855d64ac46b6244b6cd98c (diff) |
huawei: implement ussd encoding/decoding
Huawei wants the USSD as packed GSM.
-rw-r--r-- | plugins/mm-modem-huawei-gsm.c | 51 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 2 | ||||
-rw-r--r-- | 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 e038069c..5f4c2fbb 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 854ac0c0..541c2dda 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -4820,9 +4820,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 6859d739..04d2be88 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); |