diff options
Diffstat (limited to 'src/pdu_encode.c')
-rw-r--r-- | src/pdu_encode.c | 45 |
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"); |