diff options
author | Brandon Bayer <bbayer@multitech.com> | 2016-02-05 15:49:00 -0600 |
---|---|---|
committer | Brandon Bayer <bbayer@multitech.com> | 2016-02-08 16:45:03 -0600 |
commit | c75545e97a0d29de082b9ae7a65ec152416753b6 (patch) | |
tree | cfe29153b7b28fdc165109af68c0e937c96912f9 | |
parent | fea5d250ef5dd8d2b13aa0748b38e621e5eec6f4 (diff) | |
download | sms-utils-c75545e97a0d29de082b9ae7a65ec152416753b6.tar.gz sms-utils-c75545e97a0d29de082b9ae7a65ec152416753b6.tar.bz2 sms-utils-c75545e97a0d29de082b9ae7a65ec152416753b6.zip |
style: convert tabs to spaces
-rw-r--r-- | src/pdu_decode.c | 536 | ||||
-rw-r--r-- | src/pdu_encode.c | 556 |
2 files changed, 546 insertions, 546 deletions
diff --git a/src/pdu_decode.c b/src/pdu_decode.c index 27822f3..ae235e0 100644 --- a/src/pdu_decode.c +++ b/src/pdu_decode.c @@ -37,130 +37,130 @@ #define DECODE_FAIL(cond, name, ret) \ do { \ - if (cond) { \ - log_error("decode failed at %s", name); \ - return ret; \ - } \ + if (cond) { \ + log_error("decode failed at %s", name); \ + return ret; \ + } \ } while (0) int pdu_decode_timestamp(const char *pdu_str, struct tm *tm) { - char buf[PDU_TIMESTAMP_SIZE + 3]; - char *cp; - int off_upper; - int off_lower; - int off; + char buf[PDU_TIMESTAMP_SIZE + 3]; + char *cp; + int off_upper; + int off_lower; + int off; - STRLEN_CHECK(pdu_str, PDU_TIMESTAMP_LEN, -1); + STRLEN_CHECK(pdu_str, PDU_TIMESTAMP_LEN, -1); - memset(tm, 0, sizeof(*tm)); - memset(buf, 0, sizeof(buf)); + memset(tm, 0, sizeof(*tm)); + memset(buf, 0, sizeof(buf)); - strncpy(buf, pdu_str, PDU_TIMESTAMP_LEN); - nibble_swap(buf, PDU_TIMESTAMP_LEN); - strunpad(buf, 'F'); + strncpy(buf, pdu_str, PDU_TIMESTAMP_LEN); + nibble_swap(buf, PDU_TIMESTAMP_LEN); + strunpad(buf, 'F'); - off_upper = hex_nibble_scan(buf + GMT_OFFSET_IDX, 1); - off_lower = hex_nibble_scan(buf + GMT_OFFSET_IDX + 1, 1); + off_upper = hex_nibble_scan(buf + GMT_OFFSET_IDX, 1); + off_lower = hex_nibble_scan(buf + GMT_OFFSET_IDX + 1, 1); - if (off_upper & BIT(3)) { - off_upper &= ~BIT(3); - buf[GMT_OFFSET_IDX] = '-'; - } else { - buf[GMT_OFFSET_IDX] = '+'; - } + if (off_upper & BIT(3)) { + off_upper &= ~BIT(3); + buf[GMT_OFFSET_IDX] = '-'; + } else { + buf[GMT_OFFSET_IDX] = '+'; + } - off = (off_upper * 10 + off_lower) * 15; + off = (off_upper * 10 + off_lower) * 15; - snprintf(buf + GMT_OFFSET_IDX + 1, 5, "%02d%02d", off / 60, off % 60); + snprintf(buf + GMT_OFFSET_IDX + 1, 5, "%02d%02d", off / 60, off % 60); - cp = (char *) strptime(buf, "%y%m%d%H%M%S%z", tm); - if (!cp || *cp) { - log_error("timestamp could not be converted to tm"); - return -1; - } + cp = (char *) strptime(buf, "%y%m%d%H%M%S%z", tm); + if (!cp || *cp) { + log_error("timestamp could not be converted to tm"); + return -1; + } - return PDU_TIMESTAMP_LEN; + return PDU_TIMESTAMP_LEN; } int pdu_decode_cdma_timestamp(const char *pdu_str, struct tm *tm) { - char buf[PDU_CDMA_TIMESTAMP_LEN + 1]; - char *cp; + char buf[PDU_CDMA_TIMESTAMP_LEN + 1]; + char *cp; - STRLEN_CHECK(pdu_str, PDU_CDMA_TIMESTAMP_LEN, -1); + STRLEN_CHECK(pdu_str, PDU_CDMA_TIMESTAMP_LEN, -1); - memset(tm, 0, sizeof(*tm)); - memset(buf, 0, sizeof(buf)); + memset(tm, 0, sizeof(*tm)); + memset(buf, 0, sizeof(buf)); - strncpy(buf, pdu_str, PDU_CDMA_TIMESTAMP_LEN); + strncpy(buf, pdu_str, PDU_CDMA_TIMESTAMP_LEN); - cp = (char *) strptime(buf, "%y%m%d%H%M%S", tm); - if (!cp || *cp) { - log_error("timestamp could not be converted to tm"); - return -1; - } + cp = (char *) strptime(buf, "%y%m%d%H%M%S", tm); + if (!cp || *cp) { + log_error("timestamp could not be converted to tm"); + return -1; + } - return PDU_CDMA_TIMESTAMP_LEN; + return PDU_CDMA_TIMESTAMP_LEN; } int pdu_decode_addr(const char *pdu_str, struct pdu_addr *addr, int smsc) { - const char *begin = pdu_str; - int addr_len; - int tmp; + const char *begin = pdu_str; + int addr_len; + int tmp; - memset(addr, 0, sizeof(*addr)); + memset(addr, 0, sizeof(*addr)); - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "addr-len", -1); - pdu_str += HEX_BYTE_LEN; - addr->len = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "addr-len", -1); + pdu_str += HEX_BYTE_LEN; + addr->len = tmp; - addr_len = addr->len; - if (smsc) { - if (!addr_len) { - goto done; - } - addr_len = addr_len * HEX_BYTE_LEN - HEX_BYTE_LEN; - } else { - if (addr_len & 1) { - addr_len++; - } - } + addr_len = addr->len; + if (smsc) { + if (!addr_len) { + goto done; + } + addr_len = addr_len * HEX_BYTE_LEN - HEX_BYTE_LEN; + } else { + if (addr_len & 1) { + addr_len++; + } + } - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "addr-type", -1); - pdu_str += HEX_BYTE_LEN; - addr->type = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "addr-type", -1); + pdu_str += HEX_BYTE_LEN; + addr->type = tmp; - if (addr_len < 0 || addr_len >= sizeof(addr->addr)) { - log_error("invalid length: 0x%02X", addr_len); - return -1; - } + if (addr_len < 0 || addr_len >= sizeof(addr->addr)) { + log_error("invalid length: 0x%02X", addr_len); + return -1; + } - log_debug("addr-len [transformed]: 0x%02X", addr_len); - log_debug("addr-type: 0x%02X", addr->type); + log_debug("addr-len [transformed]: 0x%02X", addr_len); + log_debug("addr-type: 0x%02X", addr->type); - STRLEN_CHECK(pdu_str, addr_len, -1); + STRLEN_CHECK(pdu_str, addr_len, -1); - strncpy(addr->addr, pdu_str, addr_len); + strncpy(addr->addr, pdu_str, addr_len); - nibble_swap(addr->addr, addr_len); - strunpad(addr->addr, 'F'); - pdu_str += addr_len; + nibble_swap(addr->addr, addr_len); + strunpad(addr->addr, 'F'); + pdu_str += addr_len; done: - log_debug("addr: %s", addr->addr); - log_debug("addr-len: 0x%02X", addr->len); + log_debug("addr: %s", addr->addr); + log_debug("addr-len: 0x%02X", addr->len); - return pdu_str - begin; + return pdu_str - begin; } @@ -174,30 +174,30 @@ shiftl(buf[octet_idx(n) - 1], cycledown(n, 8)) & 0x7F int pdu_decode_user_data(const char *pdu_str, struct pdu_info *pdu, int *nr_octets) { - const char *begin = pdu_str; - int tmp; - uint8_t octets[PDU_OCTETS_MAX + 1]; + const char *begin = pdu_str; + int tmp; + uint8_t octets[PDU_OCTETS_MAX + 1]; int user_data_start_index = 0; - int i; + int i; - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "user-data-len", -1); - pdu_str += HEX_BYTE_LEN; - pdu->user_data_len = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "user-data-len", -1); + pdu_str += HEX_BYTE_LEN; + pdu->user_data_len = tmp; - if (pdu->data_coding.general.unused) { - log_error("data coding group 0x%02X not implemented", - pdu->data_coding.data_coding & 0xF0); - return -1; - } + if (pdu->data_coding.general.unused) { + log_error("data coding group 0x%02X not implemented", + pdu->data_coding.data_coding & 0xF0); + return -1; + } // ----------------------------------------------------------------------------- // VERIFY DATA LENGTH AND GET NUMBER OF OCTETS (ACTUAL DATA BYTES IN PDU STRING) // ----------------------------------------------------------------------------- - if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) || + if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) || (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT_MULTI)) { if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT_MULTI) { //GSM style 7-bit encoding but with UDH multi-part header (LE910-SVG) @@ -207,15 +207,15 @@ int pdu_decode_user_data(const char *pdu_str, struct pdu_info *pdu, int *nr_octe log_debug("data coding alphabet is default"); } - if (pdu->user_data_len > PDU_UD_7BIT_MAX) { - log_warning("pdu contains invalid user-data-len: 0x%02X", - pdu->user_data_len); - pdu->user_data_len = PDU_UD_7BIT_MAX; - } + if (pdu->user_data_len > PDU_UD_7BIT_MAX) { + log_warning("pdu contains invalid user-data-len: 0x%02X", + pdu->user_data_len); + pdu->user_data_len = PDU_UD_7BIT_MAX; + } //GSM 7-bit data (septets) length is encoded in PDU as number of septets // (which is same as user_data_len), but octets is needed for decoding loop - *nr_octets = octets_from_septets(pdu->user_data_len); + *nr_octets = octets_from_septets(pdu->user_data_len); // CDMA 7-BIT ENCODING } else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) { @@ -237,89 +237,89 @@ int pdu_decode_user_data(const char *pdu_str, struct pdu_info *pdu, int *nr_octe } // GSM & CDMA 8-BIT ENCODING - } else if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_EIGHT) || + } else if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_EIGHT) || (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_EIGHT)) { - log_debug("data coding alphabet is eight"); + log_debug("data coding alphabet is eight"); - if (pdu->user_data_len > PDU_UD_8BIT_MAX) { - log_warning("pdu contains invalid user-data-len: 0x%02X", - pdu->user_data_len); - pdu->user_data_len = PDU_UD_8BIT_MAX; - } + if (pdu->user_data_len > PDU_UD_8BIT_MAX) { + log_warning("pdu contains invalid user-data-len: 0x%02X", + pdu->user_data_len); + pdu->user_data_len = PDU_UD_8BIT_MAX; + } //Original data is octets (all 8 bits could contain data) //Therefore, octets = user_data_len - *nr_octets = pdu->user_data_len; + *nr_octets = pdu->user_data_len; // UNSUPPORTED - } else { - log_debug("data coding alphabet 0x%02X not implemented", - pdu->data_coding.general.alphabet); - return -1; - } + } else { + log_debug("data coding alphabet 0x%02X not implemented", + pdu->data_coding.general.alphabet); + return -1; + } - STRLEN_CHECK(pdu_str, *nr_octets * 2, -1); + STRLEN_CHECK(pdu_str, *nr_octets * 2, -1); - log_debug("nr_octets: 0x%02X (encoded data length)", *nr_octets); - log_debug("user-data-len: 0x%02X (decoded data length)", pdu->user_data_len); + log_debug("nr_octets: 0x%02X (encoded data length)", *nr_octets); + log_debug("user-data-len: 0x%02X (decoded data length)", pdu->user_data_len); //Copy user data from pdu string into octets - for (i = 0; i < *nr_octets; i++) { - octets[i] = hex_byte_decode(pdu_str); - pdu_str += HEX_BYTE_LEN; - } + for (i = 0; i < *nr_octets; i++) { + octets[i] = hex_byte_decode(pdu_str); + pdu_str += HEX_BYTE_LEN; + } // --------------------------------------------------------- // DECODE USER DATA (IF NEEDED) AND COPY INTO pdu->user_data // --------------------------------------------------------- // GSM 7-BIT & LVW2 7-BIT MULTI-PART - if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) || + if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) || (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT_MULTI)) { - // Keep UDH for concatenated SMS. - // Otherwise it is impossible to process correctly concatenated SMS. - i = 0; - if (pdu->type.user_data_header || + // Keep UDH for concatenated SMS. + // Otherwise it is impossible to process correctly concatenated SMS. + i = 0; + if (pdu->type.user_data_header || (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT_MULTI)) { - for (i = 0; i <= octets[0]; ++i) { - pdu->user_data[i] = octets[i]; - } - i = octets[0] + 1; // Set message text start after UDH. - // Process octets padding for 7-bit encoding. - if (0 != (i * 8) % 7) { - pdu->user_data[i] = 0; // set padding data to 0; - i++; - } - } + for (i = 0; i <= octets[0]; ++i) { + pdu->user_data[i] = octets[i]; + } + i = octets[0] + 1; // Set message text start after UDH. + // Process octets padding for 7-bit encoding. + if (0 != (i * 8) % 7) { + pdu->user_data[i] = 0; // set padding data to 0; + i++; + } + } user_data_start_index = i; - for (; i < pdu->user_data_len; i++) { - pdu->user_data[i] = decode_septet_from_octet(octets, i); + for (; i < pdu->user_data_len; i++) { + pdu->user_data[i] = decode_septet_from_octet(octets, i); log_debug("DECODE: i: %d octet: 0x%02X --> data: 0x%02X", i, octets[i], pdu->user_data[i]); - } - pdu->user_data[i] = '\0'; + } + pdu->user_data[i] = '\0'; // CDMA 7-BIT } else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) { - // Keep UDH for concatenated SMS. - // Otherwise it is impossible to process correctly concatenated SMS. - i = 0; - if (pdu->type.user_data_header) { - for (i = 0; i <= octets[0]; ++i) { - pdu->user_data[i] = octets[i]; - } - i = octets[0] + 1; // Set message text start after UDH. - // Process octets padding for 7-bit encoding. - if (0 != (i * 8) % 7) { - pdu->user_data[i] = 0; // set padding data to 0; - i++; - } - } - - for (; i < pdu->user_data_len; i++) { - pdu->user_data[i] = decode_cdma_septet_from_octet(octets, i); + // Keep UDH for concatenated SMS. + // Otherwise it is impossible to process correctly concatenated SMS. + i = 0; + if (pdu->type.user_data_header) { + for (i = 0; i <= octets[0]; ++i) { + pdu->user_data[i] = octets[i]; + } + i = octets[0] + 1; // Set message text start after UDH. + // Process octets padding for 7-bit encoding. + if (0 != (i * 8) % 7) { + pdu->user_data[i] = 0; // set padding data to 0; + i++; + } + } + + for (; i < pdu->user_data_len; i++) { + pdu->user_data[i] = decode_cdma_septet_from_octet(octets, i); log_debug("DECODE: i: %d octet: 0x%02X --> data: 0x%02X", i, octets[i], pdu->user_data[i]); - } + } //Remove padded byte for data length of 7 characters if not LE910-SVG if (strcmp(Global.core.model, "LE910-SVG") && (pdu->user_data[i-1] == 0)) { @@ -327,22 +327,22 @@ int pdu_decode_user_data(const char *pdu_str, struct pdu_info *pdu, int *nr_octe i--; pdu->user_data_len--; } - pdu->user_data[i] = '\0'; + pdu->user_data[i] = '\0'; // ALL 8-BIT ENCODING - } else { - for (i = 0; i < pdu->user_data_len; i++) { - pdu->user_data[i] = octets[i]; - } - pdu->user_data[i] = '\0'; - } + } else { + for (i = 0; i < pdu->user_data_len; i++) { + pdu->user_data[i] = octets[i]; + } + pdu->user_data[i] = '\0'; + } // --------------------------------------------------------------------- // FOR GSM 7-BIT ENCODING ONLY, DECODE FROM GSM ALPHABET TO IRA ALPHABET // (includes LVW2 multi-part) // --------------------------------------------------------------------- - if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) || + if ((pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) || (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT_MULTI)) { int read = user_data_start_index; int store = user_data_start_index; @@ -366,147 +366,147 @@ int pdu_decode_user_data(const char *pdu_str, struct pdu_info *pdu, int *nr_octe pdu_str -= (read - store) * HEX_BYTE_LEN; } - return pdu_str - begin; + return pdu_str - begin; } int pdu_decode(const char *pdu_str, struct pdu_info *pdu) { - const char *begin = pdu_str; - const char *msg_begin; - int tmp; + const char *begin = pdu_str; + const char *msg_begin; + int tmp; int nr_octets; - memset(pdu, 0, sizeof(*pdu)); + memset(pdu, 0, sizeof(*pdu)); - tmp = pdu_decode_addr(pdu_str, &pdu->smsc_addr, 1); - DECODE_FAIL(tmp < 0, "smsc-addr", -1); - pdu_str += tmp; + tmp = pdu_decode_addr(pdu_str, &pdu->smsc_addr, 1); + DECODE_FAIL(tmp < 0, "smsc-addr", -1); + pdu_str += tmp; - msg_begin = pdu_str; + msg_begin = pdu_str; - log_debug("smsc-addr: %s", pdu->smsc_addr.addr); - log_debug("smsc-addr-type: 0x%02X", pdu->smsc_addr.type); - log_debug("smsc-addr-len: 0x%02X", pdu->smsc_addr.len); + log_debug("smsc-addr: %s", pdu->smsc_addr.addr); + log_debug("smsc-addr-type: 0x%02X", pdu->smsc_addr.type); + log_debug("smsc-addr-len: 0x%02X", pdu->smsc_addr.len); - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "type", -1); - pdu_str += HEX_BYTE_LEN; - pdu->type.type = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "type", -1); + pdu_str += HEX_BYTE_LEN; + pdu->type.type = tmp; - log_debug("type: 0x%02X", pdu->type.type); + log_debug("type: 0x%02X", pdu->type.type); - if (pdu->type.msg_type == PDU_MTI_SUBMIT || - pdu->type.msg_type == PDU_MTI_REPORT) { - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + if (pdu->type.msg_type == PDU_MTI_SUBMIT || + pdu->type.msg_type == PDU_MTI_REPORT) { + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "msg-reference", -1); - pdu_str += HEX_BYTE_LEN; - pdu->msg_reference = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "msg-reference", -1); + pdu_str += HEX_BYTE_LEN; + pdu->msg_reference = tmp; - log_debug("msg-reference: 0x%02X", pdu->msg_reference); - } + log_debug("msg-reference: 0x%02X", pdu->msg_reference); + } - tmp = pdu_decode_addr(pdu_str, &pdu->addr, 0); - DECODE_FAIL(tmp < 0, "addr", -1); - pdu_str += tmp; + tmp = pdu_decode_addr(pdu_str, &pdu->addr, 0); + DECODE_FAIL(tmp < 0, "addr", -1); + pdu_str += tmp; - log_debug("addr: %s", pdu->addr.addr); - log_debug("addr-type: 0x%02X", pdu->addr.type); - log_debug("addr-len: 0x%02X", pdu->addr.len); + log_debug("addr: %s", pdu->addr.addr); + log_debug("addr-type: 0x%02X", pdu->addr.type); + log_debug("addr-len: 0x%02X", pdu->addr.len); - switch (pdu->type.msg_type) { - case PDU_MTI_REPORT: - tmp = pdu_decode_timestamp(pdu_str, &pdu->timestamp); - DECODE_FAIL(tmp < 0, "report-timestamp", -1); - pdu_str += tmp; + switch (pdu->type.msg_type) { + case PDU_MTI_REPORT: + tmp = pdu_decode_timestamp(pdu_str, &pdu->timestamp); + DECODE_FAIL(tmp < 0, "report-timestamp", -1); + pdu_str += tmp; - break; - case PDU_MTI_DELIVER: - case PDU_MTI_SUBMIT: - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + break; + case PDU_MTI_DELIVER: + case PDU_MTI_SUBMIT: + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "protocol-id", -1); - pdu_str += HEX_BYTE_LEN; - pdu->protocol_id = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "protocol-id", -1); + pdu_str += HEX_BYTE_LEN; + pdu->protocol_id = tmp; - log_debug("protocol-id: 0x%02X", pdu->protocol_id); + log_debug("protocol-id: 0x%02X", pdu->protocol_id); - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "data-coding-scheme", -1); - pdu_str += HEX_BYTE_LEN; - pdu->data_coding.data_coding = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "data-coding-scheme", -1); + pdu_str += HEX_BYTE_LEN; + pdu->data_coding.data_coding = tmp; - log_debug("data-coding-scheme: 0x%02X", pdu->data_coding.data_coding); + log_debug("data-coding-scheme: 0x%02X", pdu->data_coding.data_coding); - if (pdu->type.msg_type == PDU_MTI_SUBMIT) { - log_debug("validity-period-format: 0x%02X", - pdu->type.validity_period_format); - switch (pdu->type.validity_period_format) { - case PDU_VPF_RELATIVE: - STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); + if (pdu->type.msg_type == PDU_MTI_SUBMIT) { + log_debug("validity-period-format: 0x%02X", + pdu->type.validity_period_format); + switch (pdu->type.validity_period_format) { + case PDU_VPF_RELATIVE: + STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); - tmp = hex_byte_decode(pdu_str); - DECODE_FAIL(tmp < 0, "validity-period", -1); - pdu_str += HEX_BYTE_LEN; - pdu->validity_period = tmp; + tmp = hex_byte_decode(pdu_str); + DECODE_FAIL(tmp < 0, "validity-period", -1); + pdu_str += HEX_BYTE_LEN; + pdu->validity_period = tmp; - log_debug("validity-period: 0x%02X", pdu->validity_period); + log_debug("validity-period: 0x%02X", pdu->validity_period); - break; + break; - case PDU_VPF_ENHANCED: - log_warning("PDU_VPF_ENHANCED? Falling through to absolute"); - case PDU_VPF_ABSOUTE: - tmp = pdu_decode_timestamp(pdu_str, &pdu->timestamp); - DECODE_FAIL(tmp < 0, "validity-period-timestamp", -1); - pdu_str += tmp; + case PDU_VPF_ENHANCED: + log_warning("PDU_VPF_ENHANCED? Falling through to absolute"); + case PDU_VPF_ABSOUTE: + tmp = pdu_decode_timestamp(pdu_str, &pdu->timestamp); + DECODE_FAIL(tmp < 0, "validity-period-timestamp", -1); + pdu_str += tmp; - return -1; + return -1; - case PDU_VPF_NOT_PRESENT: - default: - break; - } - } else if (pdu->type.msg_type == PDU_MTI_DELIVER) { - tmp = pdu_decode_timestamp(pdu_str, &pdu->timestamp); - DECODE_FAIL(tmp < 0, "delivery-timestamp", -1); - pdu_str += tmp; - } + case PDU_VPF_NOT_PRESENT: + default: + break; + } + } else if (pdu->type.msg_type == PDU_MTI_DELIVER) { + tmp = pdu_decode_timestamp(pdu_str, &pdu->timestamp); + DECODE_FAIL(tmp < 0, "delivery-timestamp", -1); + pdu_str += tmp; + } - tmp = pdu_decode_user_data(pdu_str, pdu, &nr_octets); - DECODE_FAIL(tmp < 0, "user-data", -1); - pdu_str += tmp; - } + tmp = pdu_decode_user_data(pdu_str, pdu, &nr_octets); + DECODE_FAIL(tmp < 0, "user-data", -1); + pdu_str += tmp; + } - pdu->msg_len = (pdu_str - msg_begin) / 2; + pdu->msg_len = (pdu_str - msg_begin) / 2; - log_debug("msg_len: %d", pdu->msg_len); + log_debug("msg_len: %d", pdu->msg_len); - return pdu_str - begin; + return pdu_str - begin; } int pdu_decode_cdma(const char *pdu_str, struct pdu_info *pdu) { - const char *begin = pdu_str; - const char *msg_begin; - int tmp; - int nr_octets; + const char *begin = pdu_str; + const char *msg_begin; + int tmp; + int nr_octets; - memset(pdu, 0, sizeof(*pdu)); + memset(pdu, 0, sizeof(*pdu)); //Destination address - tmp = pdu_decode_addr(pdu_str, &pdu->addr, 1); - DECODE_FAIL(tmp < 0, "addr", -1); - pdu_str += tmp; + tmp = pdu_decode_addr(pdu_str, &pdu->addr, 1); + DECODE_FAIL(tmp < 0, "addr", -1); + pdu_str += tmp; - msg_begin = pdu_str; + msg_begin = pdu_str; STRLEN_CHECK(pdu_str, HEX_BYTE_LEN, -1); @@ -544,9 +544,9 @@ int pdu_decode_cdma(const char *pdu_str, struct pdu_info *pdu) DECODE_FAIL(tmp < 0, "user-data", -1); pdu_str += tmp; - pdu->msg_len = 6 + nr_octets; + pdu->msg_len = 6 + nr_octets; - log_debug("msg_len: %d", pdu->msg_len); + log_debug("msg_len: %d", pdu->msg_len); - return pdu_str - begin; + return pdu_str - begin; } diff --git a/src/pdu_encode.c b/src/pdu_encode.c index 4d43eac..db8c475 100644 --- a/src/pdu_encode.c +++ b/src/pdu_encode.c @@ -33,60 +33,60 @@ #define ENCODE_FAIL(cond, name, ret) \ do { \ - if (cond) { \ - log_error("encode failed at %s", name); \ - return ret; \ - } \ + if (cond) { \ + log_error("encode failed at %s", name); \ + return ret; \ + } \ } while (0) #define CEIL(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X)) int pdu_encode_timestamp(char *pdu_str, size_t len, struct tm *tm) { - int tmp; - int off_upper; - int off_lower; - int off; - int negative; - - if (len < PDU_TIMESTAMP_SIZE) { - log_error("buffer is not large enough to hold a timestamp"); - return -1; - } + int tmp; + int off_upper; + int off_lower; + int off; + int negative; + + if (len < PDU_TIMESTAMP_SIZE) { + log_error("buffer is not large enough to hold a timestamp"); + return -1; + } - tmp = strftime(pdu_str, PDU_TIMESTAMP_SIZE, "%y%m%d%H%M%S", tm); - ENCODE_FAIL(tmp != GMT_OFFSET_IDX, "timestamp", -1); + tmp = strftime(pdu_str, PDU_TIMESTAMP_SIZE, "%y%m%d%H%M%S", tm); + ENCODE_FAIL(tmp != GMT_OFFSET_IDX, "timestamp", -1); - off = tm->tm_gmtoff; - if (off < 0) { - off = -off; - negative = 1; - } - off = off / 60 / 15; + off = tm->tm_gmtoff; + if (off < 0) { + off = -off; + negative = 1; + } + off = off / 60 / 15; - off_upper = off / 10; - off_lower = off % 10; + off_upper = off / 10; + off_lower = off % 10; - if (negative) { - off_upper |= BIT(3); - } + if (negative) { + off_upper |= BIT(3); + } - snprintf(pdu_str + GMT_OFFSET_IDX, 2, "%X", off_upper & 0xF); - snprintf(pdu_str + GMT_OFFSET_IDX + 1, 2, "%X", off_lower & 0xF); + snprintf(pdu_str + GMT_OFFSET_IDX, 2, "%X", off_upper & 0xF); + snprintf(pdu_str + GMT_OFFSET_IDX + 1, 2, "%X", off_lower & 0xF); - strpad(pdu_str, PDU_TIMESTAMP_LEN, 'F'); - nibble_swap(pdu_str, PDU_TIMESTAMP_LEN); + strpad(pdu_str, PDU_TIMESTAMP_LEN, 'F'); + nibble_swap(pdu_str, PDU_TIMESTAMP_LEN); - log_debug("encode_timestamp: %s", pdu_str); + log_debug("encode_timestamp: %s", pdu_str); - return PDU_TIMESTAMP_LEN; + return PDU_TIMESTAMP_LEN; } int pdu_encode_addr(char *pdu_str, size_t len, struct pdu_addr *addr, int smsc) { - char *begin = pdu_str; - int addr_len; - int tmp; + char *begin = pdu_str; + int addr_len; + int tmp; if (isCdmaTypeModel()) { //CDMA length is # of bytes including address type @@ -100,52 +100,52 @@ int pdu_encode_addr(char *pdu_str, size_t len, struct pdu_addr *addr, int smsc) addr_len = strlen(addr->addr); } - if (smsc) { - if (addr_len) { - if (addr_len & 1) { - addr_len++; - } - addr_len = addr_len / HEX_BYTE_LEN + 1; - } - } - - log_debug("addr-len [transformed]: 0x%02X", addr_len); - addr->len = addr_len; - - tmp = hex_byte_encode(pdu_str, len, addr_len); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "addr-len", -1); - pdu_str += tmp; - len -= tmp; - - if (smsc && !addr_len) { - log_debug("smsc addr is empty"); - goto done; - } - - tmp = hex_byte_encode(pdu_str, len, addr->type); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "addr-type", -1); - pdu_str += tmp; - len -= tmp; - - addr_len = strlen(addr->addr); - if (addr_len & 1) { - addr_len++; - } - - if (len < addr_len + 1) { - log_error("buffer is not large enough to hold the addr"); - return -1; - } - - strcpy(pdu_str, addr->addr); - strpad(pdu_str, addr_len, 'F'); - nibble_swap(pdu_str, addr_len); - len -= addr_len; - pdu_str += addr_len; + if (smsc) { + if (addr_len) { + if (addr_len & 1) { + addr_len++; + } + addr_len = addr_len / HEX_BYTE_LEN + 1; + } + } + + log_debug("addr-len [transformed]: 0x%02X", addr_len); + addr->len = addr_len; + + tmp = hex_byte_encode(pdu_str, len, addr_len); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "addr-len", -1); + pdu_str += tmp; + len -= tmp; + + if (smsc && !addr_len) { + log_debug("smsc addr is empty"); + goto done; + } + + tmp = hex_byte_encode(pdu_str, len, addr->type); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "addr-type", -1); + pdu_str += tmp; + len -= tmp; + + addr_len = strlen(addr->addr); + if (addr_len & 1) { + addr_len++; + } + + if (len < addr_len + 1) { + log_error("buffer is not large enough to hold the addr"); + return -1; + } + + strcpy(pdu_str, addr->addr); + strpad(pdu_str, addr_len, 'F'); + nibble_swap(pdu_str, addr_len); + len -= addr_len; + pdu_str += addr_len; done: - return pdu_str - begin; + return pdu_str - begin; } @@ -159,34 +159,34 @@ shiftl(buf[septet_idx(n)], cycleup(n, 7) + 1) | shiftr(buf[septet_idx(n) + 1], c int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *nr_octets) { - char *begin = pdu_str; - int tmp; - uint8_t octets[PDU_OCTETS_MAX]; - int i; - - if (pdu->data_coding.general.unused) { - log_error("data coding group 0x%02X not implemented", - pdu->data_coding.data_coding & 0xF0); - return -1; - } - - if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) { - log_debug("data coding alphabet is default (7-bit)"); - } else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_EIGHT) { - log_debug("data coding alphabet is eight"); - } else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) { - log_debug("data coding alphabet is CDMA default (7-bit)"); - } else { - log_debug("data coding alphabet 0x%02X not implemented", - pdu->data_coding.general.alphabet); - return -1; - } + char *begin = pdu_str; + int tmp; + uint8_t octets[PDU_OCTETS_MAX]; + int i; + + if (pdu->data_coding.general.unused) { + log_error("data coding group 0x%02X not implemented", + pdu->data_coding.data_coding & 0xF0); + return -1; + } + + if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) { + log_debug("data coding alphabet is default (7-bit)"); + } else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_EIGHT) { + log_debug("data coding alphabet is eight"); + } else if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) { + log_debug("data coding alphabet is CDMA default (7-bit)"); + } else { + log_debug("data coding alphabet 0x%02X not implemented", + pdu->data_coding.general.alphabet); + return -1; + } // --------------------------------------------------------------------- // FOR GSM 7-BIT ENCODING ONLY, ENCODE FROM IRA ALPHABET TO GSM ALPHABET // --------------------------------------------------------------------- - if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) { + if (pdu->data_coding.general.alphabet == PDU_ALPHABET_DEFAULT) { int read = 0; int store = 0; char initial_user_data[PDU_UD_7BIT_MAX]; @@ -232,48 +232,48 @@ 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 = octets_from_septets(pdu->user_data_len); - for (i = 0; i < *nr_octets; i++) { - octets[i] = encode_octet(pdu->user_data, i); + 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 = 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; - } - - *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); + if (pdu->user_data_len > PDU_UD_7BIT_MAX) { + log_error("string exceeds 7-bit data max length"); + return -1; + } + + *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"); - return -1; - } - - *nr_octets = pdu->user_data_len; - for (i = 0; i < pdu->user_data_len; i++) { - octets[i] = pdu->user_data[i]; - } - } - - if (len < *nr_octets * 2 + HEX_BYTE_LEN + 1) { - log_error("buffer is not large enough to hold user-data"); - return -1; - } + } else { + if (pdu->user_data_len > PDU_UD_8BIT_MAX) { + log_error("string exceeds 8-bit data max length"); + return -1; + } + + *nr_octets = pdu->user_data_len; + for (i = 0; i < pdu->user_data_len; i++) { + octets[i] = pdu->user_data[i]; + } + } + + if (len < *nr_octets * 2 + HEX_BYTE_LEN + 1) { + log_error("buffer is not large enough to hold user-data"); + return -1; + } if (pdu->data_coding.general.alphabet == PDU_ALPHABET_CDMA_DEFAULT) { // user_data_len is stored as number of encoded octets @@ -289,179 +289,179 @@ int pdu_encode_user_data(char *pdu_str, size_t len, struct pdu_info *pdu, int *n pdu_str += tmp; len -= tmp; - for (i = 0; i < *nr_octets; i++) { - hex_byte_encode(pdu_str, len, octets[i]); - pdu_str += HEX_BYTE_LEN; - } - len -= *nr_octets * 2; - pdu_str[i] = '\0'; + for (i = 0; i < *nr_octets; i++) { + hex_byte_encode(pdu_str, len, octets[i]); + pdu_str += HEX_BYTE_LEN; + } + len -= *nr_octets * 2; + pdu_str[i] = '\0'; - log_debug("user-data-len: 0x%02X (before encoding)", pdu->user_data_len); - log_debug("nr_octets: 0x%02X (after encoding)", *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; + return pdu_str - begin; } int pdu_encode(char *pdu_str, size_t len, struct pdu_info *pdu) { - char *begin = pdu_str; - char *msg_begin = pdu_str; - int tmp; - int nr_octets; - - tmp = pdu_encode_addr(pdu_str, len, &pdu->smsc_addr, 1); - ENCODE_FAIL(tmp < 0, "smsc-addr", -1); - len -= tmp; - pdu_str += tmp; - - msg_begin = pdu_str; - - tmp = hex_byte_encode(pdu_str, len, pdu->type.type); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "type", -1); - len -= tmp; - pdu_str += tmp; - - if (pdu->type.msg_type == PDU_MTI_SUBMIT || - pdu->type.msg_type == PDU_MTI_REPORT) { - tmp = hex_byte_encode(pdu_str, len, pdu->msg_reference); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "msg-reference", -1); - len -= tmp; - pdu_str += tmp; - } - - tmp = pdu_encode_addr(pdu_str, len, &pdu->addr, 0); - ENCODE_FAIL(tmp < 0, "addr", -1); - len -= tmp; - pdu_str += tmp; - - switch (pdu->type.msg_type) { - case PDU_MTI_REPORT: - tmp = pdu_encode_timestamp(pdu_str, len, &pdu->timestamp); - ENCODE_FAIL(tmp < 0, "report-timestamp", -1); - len -= tmp; - pdu_str += tmp; - - break; - case PDU_MTI_DELIVER: - case PDU_MTI_SUBMIT: - tmp = hex_byte_encode(pdu_str, len, pdu->protocol_id); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "protocol-id", -1); - len -= tmp; - pdu_str += tmp; - - tmp = hex_byte_encode(pdu_str, len, pdu->data_coding.data_coding); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "data-coding-scheme", -1); - len -= tmp; - pdu_str += tmp; - - if (pdu->type.msg_type == PDU_MTI_SUBMIT) { - switch (pdu->type.validity_period_format) { - case PDU_VPF_RELATIVE: - tmp = hex_byte_encode(pdu_str, len, pdu->validity_period); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "validity-period", -1); - len -= tmp; - pdu_str += tmp; - - break; - - case PDU_VPF_ENHANCED: - log_warning("PDU_VPF_ENHANCED? Falling through to absolute"); - case PDU_VPF_ABSOUTE: - tmp = pdu_encode_timestamp(pdu_str, len, &pdu->timestamp); - ENCODE_FAIL(tmp < 0, "validity-period-timestamp", -1); - len -= tmp; - pdu_str += tmp; - - break; - - case PDU_VPF_NOT_PRESENT: - default: - break; - } - } else if (pdu->type.msg_type == PDU_MTI_DELIVER) { - tmp = pdu_encode_timestamp(pdu_str, len, &pdu->timestamp); - ENCODE_FAIL(tmp < 0, "delivery-timestamp", -1); - len -= tmp; - pdu_str += tmp; - } - - tmp = pdu_encode_user_data(pdu_str, len, pdu, &nr_octets); - ENCODE_FAIL(tmp < 0, "user-data", -1); - len -= tmp; - pdu_str += tmp; - } - - pdu->msg_len = (pdu_str - msg_begin) / 2; - log_debug("msg-len: %d", pdu->msg_len); - - return pdu_str - begin; + char *begin = pdu_str; + char *msg_begin = pdu_str; + int tmp; + int nr_octets; + + tmp = pdu_encode_addr(pdu_str, len, &pdu->smsc_addr, 1); + ENCODE_FAIL(tmp < 0, "smsc-addr", -1); + len -= tmp; + pdu_str += tmp; + + msg_begin = pdu_str; + + tmp = hex_byte_encode(pdu_str, len, pdu->type.type); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "type", -1); + len -= tmp; + pdu_str += tmp; + + if (pdu->type.msg_type == PDU_MTI_SUBMIT || + pdu->type.msg_type == PDU_MTI_REPORT) { + tmp = hex_byte_encode(pdu_str, len, pdu->msg_reference); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "msg-reference", -1); + len -= tmp; + pdu_str += tmp; + } + + tmp = pdu_encode_addr(pdu_str, len, &pdu->addr, 0); + ENCODE_FAIL(tmp < 0, "addr", -1); + len -= tmp; + pdu_str += tmp; + + switch (pdu->type.msg_type) { + case PDU_MTI_REPORT: + tmp = pdu_encode_timestamp(pdu_str, len, &pdu->timestamp); + ENCODE_FAIL(tmp < 0, "report-timestamp", -1); + len -= tmp; + pdu_str += tmp; + + break; + case PDU_MTI_DELIVER: + case PDU_MTI_SUBMIT: + tmp = hex_byte_encode(pdu_str, len, pdu->protocol_id); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "protocol-id", -1); + len -= tmp; + pdu_str += tmp; + + tmp = hex_byte_encode(pdu_str, len, pdu->data_coding.data_coding); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "data-coding-scheme", -1); + len -= tmp; + pdu_str += tmp; + + if (pdu->type.msg_type == PDU_MTI_SUBMIT) { + switch (pdu->type.validity_period_format) { + case PDU_VPF_RELATIVE: + tmp = hex_byte_encode(pdu_str, len, pdu->validity_period); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "validity-period", -1); + len -= tmp; + pdu_str += tmp; + + break; + + case PDU_VPF_ENHANCED: + log_warning("PDU_VPF_ENHANCED? Falling through to absolute"); + case PDU_VPF_ABSOUTE: + tmp = pdu_encode_timestamp(pdu_str, len, &pdu->timestamp); + ENCODE_FAIL(tmp < 0, "validity-period-timestamp", -1); + len -= tmp; + pdu_str += tmp; + + break; + + case PDU_VPF_NOT_PRESENT: + default: + break; + } + } else if (pdu->type.msg_type == PDU_MTI_DELIVER) { + tmp = pdu_encode_timestamp(pdu_str, len, &pdu->timestamp); + ENCODE_FAIL(tmp < 0, "delivery-timestamp", -1); + len -= tmp; + pdu_str += tmp; + } + + tmp = pdu_encode_user_data(pdu_str, len, pdu, &nr_octets); + ENCODE_FAIL(tmp < 0, "user-data", -1); + len -= tmp; + pdu_str += tmp; + } + + pdu->msg_len = (pdu_str - msg_begin) / 2; + log_debug("msg-len: %d", pdu->msg_len); + + return pdu_str - begin; } int pdu_encode_cdma(char *pdu_str, size_t len, struct pdu_info *pdu) { - char *begin = pdu_str; - char *msg_begin = pdu_str; - int tmp; - int nr_octets; + char *begin = pdu_str; + char *msg_begin = pdu_str; + int tmp; + int nr_octets; //Set pdu encoding for CDMA pdu->data_coding.general.alphabet = PDU_ALPHABET_CDMA_DEFAULT; //Destination address - tmp = pdu_encode_addr(pdu_str, len, &pdu->addr, 0); - ENCODE_FAIL(tmp < 0, "addr", -1); - len -= tmp; - pdu_str += tmp; + tmp = pdu_encode_addr(pdu_str, len, &pdu->addr, 0); + ENCODE_FAIL(tmp < 0, "addr", -1); + len -= tmp; + pdu_str += tmp; //Callback address (Always 00 because it's empty) - tmp = hex_byte_encode(pdu_str, len, 0); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "callback-addr-len", -1); - pdu_str += tmp; - len -= tmp; + tmp = hex_byte_encode(pdu_str, len, 0); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "callback-addr-len", -1); + pdu_str += tmp; + len -= tmp; //Teleservice ID (always 1002) - tmp = hex_byte_encode(pdu_str, len, 16); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "tele-id-1", -1); - pdu_str += tmp; - len -= tmp; - tmp = hex_byte_encode(pdu_str, len, 2); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "tele-id-2", -1); - pdu_str += tmp; - len -= tmp; + tmp = hex_byte_encode(pdu_str, len, 16); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "tele-id-1", -1); + pdu_str += tmp; + len -= tmp; + tmp = hex_byte_encode(pdu_str, len, 2); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "tele-id-2", -1); + pdu_str += tmp; + len -= tmp; //Priority (always 00 for normal) - tmp = hex_byte_encode(pdu_str, len, 0); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "priority", -1); - pdu_str += tmp; - len -= tmp; + tmp = hex_byte_encode(pdu_str, len, 0); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "priority", -1); + pdu_str += tmp; + len -= tmp; - switch (pdu->type.msg_type) { - case PDU_MTI_REPORT: + switch (pdu->type.msg_type) { + case PDU_MTI_REPORT: log_error("msg_type PDU_MTI_REPORT not supported!"); return 0; - case PDU_MTI_DELIVER: + case PDU_MTI_DELIVER: log_debug("msg_type: PDU_MTI_DELIVER"); - case PDU_MTI_SUBMIT: + case PDU_MTI_SUBMIT: log_debug("msg_type: PDU_MTI_SUBMIT"); //add data coding scheme - tmp = hex_byte_encode(pdu_str, len, pdu->data_coding.data_coding); - ENCODE_FAIL(tmp != HEX_BYTE_LEN, "data-coding-scheme", -1); - len -= tmp; - pdu_str += tmp; + tmp = hex_byte_encode(pdu_str, len, pdu->data_coding.data_coding); + ENCODE_FAIL(tmp != HEX_BYTE_LEN, "data-coding-scheme", -1); + len -= tmp; + pdu_str += tmp; - tmp = pdu_encode_user_data(pdu_str, len, pdu, &nr_octets); - ENCODE_FAIL(tmp < 0, "user-data", -1); - len -= tmp; - pdu_str += tmp; - } + tmp = pdu_encode_user_data(pdu_str, len, pdu, &nr_octets); + ENCODE_FAIL(tmp < 0, "user-data", -1); + len -= tmp; + pdu_str += tmp; + } - // pdu->msg_len = (pdu_str - msg_begin) / 2; - pdu->msg_len = 6 + nr_octets; - log_debug("msg-len: %d", pdu->msg_len); + // pdu->msg_len = (pdu_str - msg_begin) / 2; + pdu->msg_len = 6 + nr_octets; + log_debug("msg-len: %d", pdu->msg_len); - return pdu_str - begin; + return pdu_str - begin; } |