Fixed extraction of UDH header from original buffer rather than from encoded message as CSMS reference / values number greater than 0x7F were not decoded properly.

This commit is contained in:
Qasim Ayyaz Khan
2016-06-02 23:52:25 -04:00
parent 7d0da6202c
commit 8f1c94724c
2 changed files with 27 additions and 14 deletions
+4 -12
View File
@@ -368,18 +368,10 @@ function longSms(pduObj) {
// reference number is of one octet otherwise it consists of 2 octets. Other fields can
// be found from below reference.
// reference: https://en.wikipedia.org/wiki/Concatenated_SMS
var encodedMessage = utils.encodeMsg(pduObj.params.short_message),
udhSize = encodedMessage[0];
var smsGroupId, smsParts, partNr;
if(udhSize === 0x05) {
smsGroupId = encodedMessage[3],
smsParts = encodedMessage[4],
partNr = encodedMessage[5];
} else {
smsGroupId = (encodedMessage[3] * 256) + encodedMessage[4],
smsParts = encodedMessage[5],
partNr = encodedMessage[6];
}
var udhSize = pduObj.params['udhHeader'].size,
smsGroupId = pduObj.params['udhHeader'].reference,
smsParts = pduObj.params['udhHeader'].totalParts,
partNr = pduObj.params['udhHeader'].partNr;
var longSmsId = pduObj.params.source_addr + '_' + pduObj.params.destination_addr + '_' + smsGroupId;
+23 -2
View File
@@ -271,8 +271,29 @@ function pduToObj(pdu, stupidNullByte, callback) {
paramSize = command.params[param].type.size(retObj.params[param]);
log.silly('larvitsmpp: lib/utils.js: pduToObj() - Reading param "' + param + '" at offset ' + offset + ' with calculated size: ' + paramSize + ' content in hex: ' + pdu.slice(offset, offset + paramSize).toString('hex'));
if (param === 'short_message') {
if((retObj.params['esm_class'] & 0x40) === 0x40) {
//This is a part of long sms. We should save UDH header information in params.
console.log(pdu.slice(offset, offset + paramSize).toString('hex').slice(6, 8))
var hsize = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(0, 2));
//If hsize is >5 then CSMS Reference consist of two parts
if(hsize == 5) {
var reference = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(6, 8)),
totalParts = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(8, 10)),
partNr = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(10, 12));
} else {
var reference = (parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(6, 8)) * 256) + parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(8, 10)),
totalParts = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(10, 12)),
partNr = parseInt("0x" + pdu.slice(offset, offset + paramSize).toString('hex').slice(12, 14));
}
var udhHeader = {
'size': hsize,
'reference': reference,
'totalParts': totalParts,
'partNr': partNr
}
retObj.params['udhHeader'] = udhHeader;
}
// Check if we have a trailing NULL octet after the short_message. Some idiot thought that would be a good idea
// in some implementations, so we need to account for that.
if (stupidNullByte === true) {
@@ -782,4 +803,4 @@ exports.pduReturn = pduReturn;
exports.smppDate = smppDate;
exports.bitCount = bitCount;
exports.splitMsg = splitMsg;
exports.smsDlr = smsDlr;
exports.smsDlr = smsDlr;