farhadi / node-smpp

SMPP client and server implementation in node.js
MIT License
418 stars 177 forks source link

message.decode() incorrect detects encoding #66

Open dariusmi opened 7 years ago

dariusmi commented 7 years ago

defs.filters.message.decode() function detects encoding simply encoding = this.data_coding & 0x0F; But according documentation this is incorrect when data_coding carriers more information than only encoding ftp://www.3gpp.org/tsg_t/TSG_T/TSGT_04/Docs/PDFs/TP-99127.pdf

What about to change line encoding = this.data_coding & 0x0F; to


var encoding = 0;

if (this.data_coding <= 0x0E) {    
    encoding = this.data_coding & 0x0F;
}
// Non-MWI Mode 1
else if ((this.data_coding & 0xF0) == 0xF0) {
    encoding = (this.data_coding & 0x04) ? consts.ENCODING.BINARY : consts.ENCODING.ASCII; // grab bit 2
}
// Non-MWI Mode 0
else if ((this.data_coding & 0xC0) == 0x00) {
    encoding = (this.data_coding & 0x0C) >> 2; // grab bit 3,2
    if (encoding == 0) {
        encoding = consts.ENCODING.ASCII;
    } else if (encoding == 1) {
        encoding = consts.ENCODING.BINARY;
    } else if (encoding == 2) {
        encoding = consts.ENCODING.UCS2;
    } else {   // 3 is reserved
        //encoding = consts.ENCODING.ASCII;
    }
}
// MWI Mode
else if ((this.data_coding & 0xC0) == 0xC0) {
    encoding = ((this.data_coding & 0xE0) == 0xE0) ? consts.ENCODING.UCS2 : consts.ENCODING.ASCII;
}
juliangut commented 4 years ago

This is what SMPP protocol specifications 3.4 and 5 (which are the ones covered by this package) explains about data_ _coding field

0x00 <= data_coding <= 0x0E "Current behabiour" 0x0F <= data_coding <= 0xBF Reserved 0xC0 <= data_coding <= 0xDF GSM MWI control - see [GSM 03.38]: The data_coding parameter will evolve to specify Character code settings only. Thus the recommended way to specify GSM MWI control is by specifying the relevant settings in the TLVs ms_msg_wait_facilities and ms_validity 0xE0 <= data_coding <= 0xEF Reserved 0xF0 <= data_coding <= 0xFF GSM message class control - see [GSM 03.38]: The data_coding parameter will evolve to specify Character code settings only. Thus the recommended way to specify GSM message class control is by specifying the relevant setting in the TLV dest_addr_subunit

According to previous specification we should focus on 0x00-0x0E, 0xC0-0xDF and 0xF0-0xFF and avoid Reserved groups:

var encoding = consts.ENCODING.SMSC_DEFAULT;

if (this.data_coding <= 0x0E) {    
    encoding = this.data_coding & 0x0F;
} else if (this.data_coding >= 0xF0) {
    // Bit 2 => 0: Default alphabet - 1: 8-bit data
    encoding = (this.data_coding & 0x04) ? consts.ENCODING.BINARY : consts.ENCODING.SMSC_DEFAULT;
} else if (this.data_coding >= 0xC0 && this.data_coding <= 0xDF) {
    // Text included in the user data is coded in the Default Alphabet.
    // Message should be stored (0xDX) or discarded (0xCX) but no encoding info is provided
} else {
    // Reserved
}