"+val+"
";
}
function dv_str(str) {
var out = "";
for(var a=0;a127)) out += " " + pad(ch.toString(16),2) + " ";
else out += str[a];
}
out += "
";
return out;
}
function logTLVs(view,i,command_length) {
if (!loggingDisabled) return;
while (i!=command_length) {
let tag = view.getUint16(0*2+i,false);
let len = view.getUint16(1*2+i,false);
i+=4;
var str = "",str_b = "";
for(var a=0;a"+String.fromCharCode(v)+"
";
else {
str_b += " ";
str_b += pad(view.getUint8(i+a,false).toString(16),2);
str_b += "";
}
}
//str += pad(view.getUint8(i+a,false).toString(16),2)+" ";
}
i+=len;
logRaw("TLV [tag:"+tag+" len:"+len+" val:"+str+" text: "+str_b+"] ");
}
}
function smppTLVStr(tag) {
switch (tag) {
case 0x0005: return "dest_addr_subunit";
case 0x0006: return "dest_network_type";
case 0x0007: return "dest_bearer_type";
case 0x0017: return "qos_time_to_live";
case 0x0019: return "payload_type";
case 0x001d: return "additional_status_info_text";
case 0x001e: return "receipted_message_id";
case 0x001f: return "ms_msg_wait_facilities";
case 0x0204: return "user_message_reference";
case 0x020c: return "sar_msg_ref_num";
case 0x020e: return "sar_total_segments";
case 0x020f: return "sar_segment_seqnum";
case 0x0210: return "sc_interface_version";
case 0x420: return "dpf_result";
case 0x421: return "set_dpf";
case 0x422: return "ms_availability_status";
case 0x423: return "network_error_code";
case 0x424: return "message_payload";
case 0x425: return "delivery_failure_reason";
case 0x426: return "more_messages_to_send";
case 0x427: return "message_state";
}
return "UNKNOWN";
}
function smppCommandStr(command_id) {
switch (command_id) {
case 0x00000004: return "submit_sm";
case 0x80000004: return "submit_sm_resp";
case 0x00000005: return "deliver_sm";
case 0x80000005: return "deliver_sm_resp";
case 0x00000006: return "unbind";
case 0x80000006: return "unbind_resp";
case 0x00000009: return "bind_transceiver";
case 0x80000009: return "bind_transceiver_resp";
case 0x00000015: return "enquire_link";
case 0x80000015: return "enquire_link_resp";
}
return "UNKNOWN";
}
function smppCmdStatusStr(command_status) {
switch (command_status) {
case 0x0: return "ROK";
case 0x1: return "RINVMSGLEN";
case 0x2: return "RINVCMDLEN";
case 0x3: return "RINVCMDID";
case 0x4: return "RINVBNDSTS";
case 0x5: return "RALYBND";
case 0x6: return "RINVPRTFLG";
case 0x7: return "RINVREGDLVFLG";
case 0x8: return "RSYSERR";
case 0x9: return "RINVSRCADR";
case 0xa: return "RINVSRCADR";
case 0xb: return "RINVDSTADR";
case 0xc: return "RINVMSG";
case 0xd: return "RBINDFAIL";
case 0xe: return "RINVPASWD";
case 0xf: return "RINVSYSID";
case 0x11: return "RCANCELFAIL";
case 0x13: return "RREPLACEFAIL";
case 0x14: return "RMSGQFUL";
case 0x15: return "RINVSERTYP";
case 0x33: return "RINVNUMDESTS";
case 0x34: return "RRINVDLNAME";
case 0x40: return "RINVDESTFLAG";
case 0x42: return "RINVSUBREP";
case 0x43: return "RINVESMCLASS";
case 0x44: return "RCNTSUBDL";
case 0x45: return "RSUBMITFAIL";
case 0x48: return "RINVSRCTON";
case 0x49: return "RINVSRCNPI";
case 0x50: return "RINVDSTTON";
case 0x51: return "RINVDSTNPI";
case 0x53: return "RINVSYSTYP";
case 0x54: return "RINVREPFLAG";
case 0x55: return "RINVNUMMSGS";
case 0x58: return "RTHROTTLED";
case 0x61: return "RINVSCHED";
case 0x63: return "RINVDFTMSGID";
case 0x64: return "RX_T_APPN";
case 0x65: return "RX_P_APPN";
case 0x66: return "RX_R_APPN";
case 0x67: return "RQUERYFAIL";
case 0xc0: return "RINVTLVSTREAM";
case 0xc1: return "RTLVNOTALLWD";
case 0xc2: return "RINVTLVLEN";
case 0xc3: return "RMISSINGTLV";
case 0xc4: return "RINVTLVVAL";
case 0xfe: return "RDELIVERYFAILURE";
case 0xff: return "RUNKNOWNERR";
case 0x100: return "RSERTYPUNAUTH";
case 0x101: return "RPROHIBITED";
case 0x102: return "RSERTYPUNAVAIL";
case 0x103: return "RSERTYPDENIED";
case 0x104: return "RINVDCS";
}
return "UNKNOWN";
}
function strTLVs(view,i,command_length) {
var str_tlvs = "";
while (i!=command_length) {
let tag = view.getUint16(0*2+i,false);
let len = view.getUint16(1*2+i,false);
i+=4;
var str = "",str_b = "";
for(var a=0;a"+String.fromCharCode(v)+"
";
else {
str_b += " ";
str_b += pad(view.getUint8(i+a,false).toString(16),2);
str_b += "";
}
}
}
i+=len;
if (str_tlvs!="") str_tlvs += " ";
str_tlvs += 'TLV tag:0x'+tag.toString(16)+' ('+smppTLVStr(tag)+') len:'+len+' val(hex):'+str+' text: '+str_b+'';
}
return str_tlvs;
}
function getNumSMSParts(dataCoding, msg) {
var isGSM7Msg = isGSM7Message( msg );
var bitsPerChar = isGSM7Msg?7:16;
if ( dataCoding == 8 ) bitsPerChar=16;
//
var sms_len = msg.length;
var sms_count = 0;
var sms_concat_space = (140*8 - 6*8) / bitsPerChar;
if (sms_len>0) {
if (sms_len<= Math.floor(140*8/bitsPerChar) ) sms_count = 1;
else {
sms_count = Math.floor(sms_len / sms_concat_space);
if ((sms_len % sms_concat_space) > 0) sms_count++;
}
}
return sms_count;
}
function logLow(a,b){ if (!loggingDisabled) console.log(a); }
class SMPPSession {
constructor(host,port,systemid,password) {
this.wsSocket = null;
/* SOCKS */
this.socksState = 0;
this.socksTargetHost = host;
this.socksTargetPort = port;
/* SMPP */
this.smppSeqNoOut = 1;
this.stateBound = false;
this.smppSystemID = systemid;
this.smppPassword = password;
this.smppSystemType = "";
this.smppAddressRange = "";
this.smppVersion = 0x34;
//console.log("SMPPSession");
//console.log(this);
}
userBindTRXRespSuccessFunc() {}
userWSCloseFunc() {}
showState(state) {}
logLow(a,b){ if (!loggingDisabled) console.log(a); }
log(direction,command_id,command_status,sequence_number,str,str_tlvs,pdu_hex_dump) {
if (loggingDisabled) return;
var badgeColour = "secondary";
var outcome = '' + smppCommandStr(command_id) + ""; // + " (0x" + pad(command_id.toString(16),8) + ")";
if (command_id>=0x80000000) {
if (command_status==0) outcome += ' OK';
else outcome += ' ERROR: ' + smppCmdStatusStr(command_status) + ' (0x'+pad(command_status.toString(16),3)+')';
}
//outcome += " 0x" + pad(command_status.toString(16),8) + " ";
outcome += " ";
if (str) outcome += str;
if (this.stateBound) badgeColour = "success";
var seqno_block = "";
switch (direction) {
case 0: chDir = '-'; break;
case 1: chDir = '<'; break;
case -1: chDir = '>'; break;
}
seqno_block = ' ' + pad(sequence_number,4) + ' ' + chDir + '' + ' ';
var localDateTime = new Date();
var outline = "";
outline += '"+pdu_hex_dump+"
";
outline += '"+mc_system_id+"
";
var str_tlvs = strTLVs(view,i,command_length+pidx);
_self.log(-1, command_id,command_status,sequence_number,line,str_tlvs,pdu_hex_dump);
}
else {
_self.log(-1, command_id,command_status,sequence_number,str,null,pdu_hex_dump);
}
}
else if (command_id==0x80000004) { /*submit_sm_resp*/
if (command_status==0) {
var i=16+pidx;
var message_id = getString(view,i);
i += message_id.length+1;
var str_tlvs = strTLVs(view,i,command_length+pidx);
//log(-1, command_id,command_status,sequence_number,"Message ID: "+message_id+"
",str_tlvs,pdu_hex_dump);
if (typeof _self.userSubmitSMRespSuccessFunc == 'function') {
_self.userSubmitSMRespSuccessFunc(message_id,sequence_number);
}
}
else {
var str_tlvs = strTLVs(view,i,command_length+pidx);
//log(-1, command_id,command_status,sequence_number,str,str_tlvs,pdu_hex_dump);
console.log(pdu_hex_dump);
if (typeof _self.userSubmitSMRespFailFunc == 'function') {
_self.userSubmitSMRespFailFunc(command_status,sequence_number);
}
}
}
else if (command_id==0x00000005) { /* deliver_sm */
var i=16+pidx;
var service_type = getString(view,i);
i += service_type.length+1;
var source_addr_ton = view.getUint8(i++,false);
var source_addr_npi = view.getUint8(i++,false);
var source_addr = getString(view,i);
i += source_addr.length+1;
var dest_addr_ton = view.getUint8(i++,false);
var dest_addr_npi = view.getUint8(i++,false);
var destination_addr = getString(view,i);
i += destination_addr.length+1;
var esm_class = view.getUint8(i++,false);
var protocol_id = view.getUint8(i++,false);
var priority_flag = view.getUint8(i++,false);
var schedule_delivery_time = getString(view,i);
i += schedule_delivery_time.length+1;
var validity_period = getString(view,i);
i += validity_period.length+1;
var registered_delivery = view.getUint8(i++,false);
var replace_if_present_flag = view.getUint8(i++,false);
var data_coding = view.getUint8(i++,false);
var sm_default_msg_id = view.getUint8(i++,false);
var sm_length = view.getUint8(i++,false);
var short_message = "";
for(var a=0;a"+pdu_hex_dump+"
";
outline += '