summaryrefslogtreecommitdiff
path: root/src/pdu_encode.c
diff options
context:
space:
mode:
authorBrandon Bayer <bbayer@multitech.com>2015-11-16 09:59:15 -0600
committerBrandon Bayer <bbayer@multitech.com>2015-11-17 09:27:36 -0600
commitd8be565fc564cbd6e3beaddb3fc77b311abf2359 (patch)
tree5c6e960dee414104cd1e0ba227ac674bfc9cf7f1 /src/pdu_encode.c
parentf3b916f22265f3f173987e28d8fdc2c8a3502519 (diff)
downloadsms-utils-d8be565fc564cbd6e3beaddb3fc77b311abf2359.tar.gz
sms-utils-d8be565fc564cbd6e3beaddb3fc77b311abf2359.tar.bz2
sms-utils-d8be565fc564cbd6e3beaddb3fc77b311abf2359.zip
feat: implement IRA->GSM character set encoding & decoding0.0.10
This adds support for certain characters like @ $ ~ ^
Diffstat (limited to 'src/pdu_encode.c')
-rw-r--r--src/pdu_encode.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/pdu_encode.c b/src/pdu_encode.c
index 1bb7e4d..f0d8c96 100644
--- a/src/pdu_encode.c
+++ b/src/pdu_encode.c
@@ -182,6 +182,51 @@ int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *n
return -1;
}
+
+ //Convert to GSM character set, Only for 7-bit character sets
+ if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) ||
+ (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT)) {
+ int read = 0;
+ int store = 0;
+ char initial_user_data[PDU_UD_7BIT_MAX];
+
+ for (read = 0; read < pdu->user_data_len; read++) {
+ initial_user_data[read] = pdu->user_data[read];
+ }
+ initial_user_data[read] = 0;
+
+ log_debug("Converting from IRA character set to GSM");
+ for (read = 0; read < pdu->user_data_len; read++) {
+ int GSMchar = indexOfChar(strGSMTable, GSM_TABLE_SIZE, initial_user_data[read]);
+
+ if (GSMchar >= 0) {
+ log_debug("IRA before: 0x%02X | GSM after: 0x%02X", initial_user_data[read], GSMchar);
+ pdu->user_data[store] = GSMchar;
+ }
+ else {
+ //Check in extended table
+ GSMchar = indexOfChar(strExtendedTable, GSM_TABLE_SIZE, initial_user_data[read]);
+
+ if (GSMchar >= 0) {
+ log_debug("IRA before: 0x%02X | GSM after: 0x1B%02X", initial_user_data[read], GSMchar);
+ pdu->user_data[store] = 0x1B;
+ store++;
+ pdu->user_data[store] = GSMchar;
+ }
+ else {
+ log_debug("IRA before: 0x%02X | Translation not found - no change", initial_user_data[read]);
+ pdu->user_data[store] = initial_user_data[read];
+ }
+ }
+
+ store++;
+ }
+
+ //Update lengths
+ pdu->user_data_len += store - read;
+ }
+
+
if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) {
if (pdu->user_data_len > PDU_UD_7BIT_MAX) {
log_error("string exceeds 7-bit data max length");