summaryrefslogtreecommitdiff
path: root/src/pdu_encode.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdu_encode.c')
-rw-r--r--src/pdu_encode.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/pdu_encode.c b/src/pdu_encode.c
index ce62ee8..4d43eac 100644
--- a/src/pdu_encode.c
+++ b/src/pdu_encode.c
@@ -183,7 +183,9 @@ int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *n
}
- //Convert to GSM character set, Only for 7-bit character set
+ // ---------------------------------------------------------------------
+ // FOR GSM 7-BIT ENCODING ONLY, ENCODE FROM IRA ALPHABET TO GSM ALPHABET
+ // ---------------------------------------------------------------------
if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) {
int read = 0;
int store = 0;
@@ -226,28 +228,36 @@ int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *n
}
+ // ------------------------------
+ // ENCODE USER DATA INTO PDU DATA
+ // ------------------------------
+ // GSM 7-BIT ENCODING
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");
return -1;
}
- *nr_octets = octet_align(pdu->user_data_len);
+ *nr_octets = octets_from_septets(pdu->user_data_len);
for (i = 0; i < *nr_octets; i++) {
octets[i] = encode_octet(pdu->user_data, i);
+ log_debug("ENCODE: i: %d data: 0x%02X --> octet: 0x%02X", i, pdu->user_data[i], octets[i]);
}
+
+ // CDMA 7-BIT ENCODING
} else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) {
if (pdu->user_data_len > PDU_UD_7BIT_MAX) {
log_error("string exceeds 7-bit data max length");
return -1;
}
- //CDMA ENCODING
- *nr_octets = octet_align(pdu->user_data_len);
- pdu->user_data_len = *nr_octets;
+ *nr_octets = octets_from_septets(pdu->user_data_len);
for (i = 0; i < *nr_octets; i++) {
octets[i] = encode_cdma_octet(pdu->user_data, i);
+ log_debug("ENCODE: i: %d data: 0x%02X --> octet: 0x%02X", i, pdu->user_data[i], octets[i]);
}
+
+ // ALL 8-BIT ENCODING
} else {
if (pdu->user_data_len > PDU_UD_8BIT_MAX) {
log_error("string exceeds 8-bit data max length");
@@ -265,10 +275,19 @@ int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *n
return -1;
}
- tmp = hex_byte_encode(pdu_str, len, pdu->user_data_len);
- ENCODE_FAIL(tmp != HEX_BYTE_LEN, "user-data-len", -1);
- pdu_str += tmp;
- len -= tmp;
+ if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) {
+ // user_data_len is stored as number of encoded octets
+ // (but GSM is stored as originial # of septets)
+ log_debug("putting nr_octets into PDU as data length (CDMA)");
+ tmp = hex_byte_encode(pdu_str, len, *nr_octets);
+ }
+ else {
+ log_debug("putting user_data_len into PDU as data length");
+ tmp = hex_byte_encode(pdu_str, len, pdu->user_data_len);
+ }
+ ENCODE_FAIL(tmp != HEX_BYTE_LEN, "user-data-len", -1);
+ pdu_str += tmp;
+ len -= tmp;
for (i = 0; i < *nr_octets; i++) {
hex_byte_encode(pdu_str, len, octets[i]);
@@ -277,8 +296,8 @@ int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *n
len -= *nr_octets * 2;
pdu_str[i] = '\0';
- log_debug("user-data-len: 0x%02X", pdu->user_data_len);
- log_debug("nr_octets: 0x%02X", *nr_octets);
+ log_debug("user-data-len: 0x%02X (before encoding)", pdu->user_data_len);
+ log_debug("nr_octets: 0x%02X (after encoding)", *nr_octets);
return pdu_str - begin;
}