def parseGSM0340_request(self, data): try: Msg = "parseGSM0340_request Init " PCA_GenLib.WriteLog(Msg, 2) Msg = "GSM 0340 data =\n%s" % PCA_GenLib.HexDump(data) PCA_GenLib.WriteLog(Msg, 2) mt_fsm_gsm_0340_pdu = data tag = mt_fsm_gsm_0340_pdu[0] source = mt_fsm_gsm_0340_pdu[1:] name = "OA length" attrs = source[0] content = ord(attrs) tag_length = content tag_length = tag_length / 2 self.set_handler(name, attrs, tag_length) source = source[1:] name = "GSM0340 originating address" attrs = source[0:tag_length + 1] toa = PCA_GenLib.getHexString(attrs[1]) tag_value = "%s:%s" % (toa, PCA_GenLib.getHexBCDString(attrs[1:])) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, tag_value) self.set_handler(name, attrs, tag_value) source = source[tag_length + 1:] pid = source[0] dcs = source[1] time_stamp = source[2:2 + 6] source = source[9:] name = "GSM0340 user data length" attrs = source[0] content = ord(attrs) user_data_length = content self.set_handler(name, attrs, content) source = source[1:] tag_name = "GSM0340 sms text" attrs = source[0:user_data_length] Msg = "PCA DEBUG SMS Text = %s " % attrs PCA_GenLib.WriteLog(Msg, 1) #tag_value = PCA_GenLib.getHexString(attrs) tag_value = smspdu.pdu.unpack7bit(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler("sms text", attrs, content) Msg = "parseGSM0340_request ok " PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parseGSM0340_request error : <%s>,<%s>" % (sys.exc_type, sys.exc_value) PCA_GenLib.WriteLog(Msg, 0) Msg = "parseGSM0340_request error source =\n%s" % PCA_GenLib.HexDump( source) PCA_GenLib.WriteLog(Msg, 3)
def parseGSM0340_request(self, data): try: Msg = "parseGSM0340_request Init " PCA_GenLib.WriteLog(Msg, 9) Msg = "GSM 0340 data =\n%s" % PCA_GenLib.HexDump(data) PCA_GenLib.WriteLog(Msg, 3) gsm_0340_pdu = data tag = gsm_0340_pdu[0] TP_MR = gsm_0340_pdu[1] source = gsm_0340_pdu[2:] name = "GSM0340 recipient length" attrs = source[0] content = ord(attrs) tag_length = content tag_length = tag_length / 2 self.set_handler(name, attrs, tag_length) source = source[1:] name = "GSM0340 recipient address" attrs = source[0:tag_length + 1] toa = PCA_GenLib.getHexString(attrs[1]) #tag_value = "%s:%s" % (toa,PCA_GenLib.getHexBCDString(attrs[1:])) tag_value = "%s" % (PCA_GenLib.getHexBCDString(attrs[1:])) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, tag_value) self.set_handler(name, attrs, tag_value) source = source[tag_length + 1:] pid = source[0] dcs = source[1] validity_period = source[2] name = "GSM0340 user data length" attrs = source[3] content = ord(attrs) user_data_length = content #self.set_handler(name,attrs,content) source = source[4:] tag_name = "GSM0340 sms text" attrs = source[0:user_data_length] Msg = "PCA DEBUG MO Text = %s " % attrs PCA_GenLib.WriteLog(Msg, 2) tag_value = smspdu.pdu.unpack7bit(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler("sms text", attrs, tag_value) Msg = "parseGSM0340_request ok " PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parseGSM0340_request error : <%s>,<%s>" % (sys.exc_type, sys.exc_value) PCA_GenLib.WriteLog(Msg, 3)
def parseGSM0340_SRI_SM_response(self, data): name = 'undef' try: Msg = "parseGSM0340_SRI_SM_response Init " PCA_GenLib.WriteLog(Msg, 9) Msg = "GSM 0340 data =\n%s" % PCA_GenLib.HexDump(data) PCA_GenLib.WriteLog(Msg, 2) name = "GSM0340 tp_udhi" attrs = data[0] content = ord(attrs) self.set_handler(name, attrs, content) name = "GSM0340 tp_mti" attrs = data[1] content = ord(attrs) self.set_handler(name, attrs, content) name = "GSM0340 tp_date" attrs = data[2:5] content = PCA_GenLib.getHexString(attrs) content = "%s%s%s%s%s%s" % (content[1], content[0], content[3], content[2], content[5], content[4]) self.set_handler(name, attrs, content) name = "GSM0340 tp_time" attrs = data[5:8] content = PCA_GenLib.getHexString(attrs) content = "%s%s%s%s%s%s" % (content[1], content[0], content[3], content[2], content[5], content[4]) self.set_handler(name, attrs, content) name = "GSM0340 tp_timezone" attrs = data[8] content = ord(attrs) self.set_handler(name, attrs, content) Msg = "parseGSM0340_SRI_SM_response ok " PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parseGSM0340_SRI_SM_response error : <%s>,<%s>,name=<%s>" % ( sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 0)
def getDetailMessage(message,parameter_list,display_flags): try: Msg = "-----------------------------------------------------------------" PCA_GenLib.WriteLog(Msg,2) sccp_msg_dict = {} for m3ua_key in sorted(message): if m3ua_key == "M3UA sccp_msg_dict": sccp_msg_dict = message[m3ua_key][0] else: Msg = "<%s>=<%s>,hex=<%s>*" % (m3ua_key,message[m3ua_key][0],PCA_GenLib.getHexString(message[m3ua_key][1])) PCA_GenLib.WriteLog(Msg,display_flags) parameter_list[m3ua_key] = message[m3ua_key] tcap_msg_dict = {} for sccp_key in sorted(sccp_msg_dict): if sccp_key == "SCCP tcap_msg_dict": tcap_msg_dict = sccp_msg_dict[sccp_key][0] else: Msg = "<%s>=<%s>,hex=<%s>*" % (sccp_key,sccp_msg_dict[sccp_key][0],PCA_GenLib.getHexString(sccp_msg_dict[sccp_key][1])) PCA_GenLib.WriteLog(Msg,display_flags) parameter_list[sccp_key] = sccp_msg_dict[sccp_key] map_msg_dict = {} for tcap_key in sorted(tcap_msg_dict): if tcap_key == "TCAP map_msg_dict": map_msg_dict = tcap_msg_dict[tcap_key][0] else: Msg = "<%s>=<%s>,hex=<%s>*" % (tcap_key,tcap_msg_dict[tcap_key][0],PCA_GenLib.getHexString(tcap_msg_dict[tcap_key][1])) PCA_GenLib.WriteLog(Msg,display_flags) parameter_list[tcap_key] = tcap_msg_dict[tcap_key] for map_key in sorted(map_msg_dict): Msg = "<%s>=<%s>,hex=<%s>*" % (map_key,map_msg_dict[map_key][0],PCA_GenLib.getHexString(map_msg_dict[map_key][1])) PCA_GenLib.WriteLog(Msg,display_flags) parameter_list[map_key] = map_msg_dict[map_key] Msg = "-----------------------------------------------------------------" PCA_GenLib.WriteLog(Msg,2) #return parameter_list except: Msg = "getDetailMessage error : <%s>,<%s> " % (sys.exc_type,sys.exc_value) PCA_GenLib.WriteLog(Msg,0) raise
def parse(self, source, Is_TCAP_begin, app_context): try: Msg = "parser init" PCA_GenLib.WriteLog(Msg, 9) orig_data = source name = 'none' self.StartParsing = 0 TID = "na" content = "na" Msg = "MAP SRI-SM data =<\n%s\n>" % PCA_GenLib.HexDump(source) PCA_GenLib.WriteLog(Msg, 3) if (source != None): self._cont_handler.startDocument() self.StartParsing = 1 self.DebugStr = "" name = "MAP Tag" attrs = source[0] Tag_Type = 'Primitive' if (ord(attrs) & 0x40): name = "%s-Constructor" % name attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) else: name = "%s-Primitive" % name content = ord(attrs) self.set_handler(name, attrs, content) if Tag_Type == 'Primitive': source = source[1:] else: source = source[2:] self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name, attrs, content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) source = source[1:] name = "value" attrs = source[0:tag_length] content = PCA_GenLib.getHexString(attrs) self.set_handler(name, attrs, content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) #self.parseTLV(attrs) source = attrs name = "invoke" tag_name = name attrs = source[0] content = ord(attrs) self.set_handler(name, attrs, content) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name, attrs, content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) source = source[1:] #name = "invoke value" name = "invoke_id" attrs = source[0] content = ord(attrs) tag_value = content self.set_handler(name, attrs, content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) Msg = "MAP SRI-SM Is_TCAP_begin = <%s>" % Is_TCAP_begin PCA_GenLib.WriteLog(Msg, 3) # SRI request if Is_TCAP_begin == 1: Msg = "MAP SRI-SM DEBUG data begin =<\n%s\n>" % PCA_GenLib.HexDump( source) PCA_GenLib.WriteLog(Msg, 3) source = source[1:] name = "opCode" tag_name = name attrs = source[0] content = ord(attrs) self.set_handler(name, attrs, content) source = source[1:] name = "opCode length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name, attrs, content) source = source[1:] name = "opCode" attrs = source[0] content = ord(attrs) op_code = 'na' try: tag_value = PCA_MAPParameters.op_code[content] op_code = tag_value #Msg = "MAP opcode = <%s>" % tag_value #PCA_GenLib.WriteLog(Msg,1) except: Msg = "unknow opCode Value = %s" % content PCA_GenLib.WriteLog(Msg, 0) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = source[1:] name = "msisdn tag" tag_name = name attrs = source[0] content = ord(attrs) self.set_handler(name, attrs, content) source = source[1:] name = "msisdn tag length" attrs = source[0] content = ord(attrs) tag_length = content #self.set_handler(name,attrs,content) source = source[1:] name = "msisdn tag value" attrs = source[0:tag_length] tag_value = PCA_GenLib.getHexString(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = attrs name = "msisdn" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "msisdn value" attrs = source[1:tag_length] tag_value = PCA_GenLib.getHexBCDString(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = source[tag_length:] if op_code != "reportSM-DeliveryStatus": name = "Priority Flag" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "Priority Flag value" attrs = source[0:tag_length] tag_value = PCA_GenLib.getHexString(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = source[1:] name = "sc-address" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "sc-address length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "sc-address value" attrs = source[1:tag_length] tag_value = PCA_GenLib.getHexBCDString(attrs) Msg = "sc_address = <%s>" % tag_value PCA_GenLib.WriteLog(Msg, 3) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = source[tag_length:] if op_code == "reportSM-DeliveryStatus": name = "sm-DeliveryOutcom" attrs = source[2] content = ord(attrs) self.set_handler(name, attrs, content) Msg = "name = %s , value = %s" % (name, content) PCA_GenLib.WriteLog(Msg, 3) else: # SRI response Msg = "MAP SRI-SM DEBUG data end =<\n%s\n>" % PCA_GenLib.HexDump( source) PCA_GenLib.WriteLog(Msg, 3) source = source[1:] name = "resultretres" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "resultretres value" attrs = source[0:tag_length] source = attrs name = "opCode" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "opCode" attrs = source[0] content = ord(attrs) try: tag_value = PCA_MAPParameters.op_code[content] except: Msg = "unknow opCode Value = %s" % content PCA_GenLib.WriteLog(Msg, 0) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = source[1:] name = "sm-rp-UI" tag_name = name attrs = source[0] content = ord(attrs) self.set_handler(name, attrs, content) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content #self.set_handler(name,attrs,content) source = source[1:] name = "sm-rp-UI value" attrs = source[0:tag_length] tag_value = PCA_GenLib.getHexString(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = attrs name = "imsi" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "imsi value" attrs = source[0:tag_length] tag_value = PCA_GenLib.getHexIMSIString(attrs)[0:15] self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = source[tag_length:] name = "location-info-with-LMSI" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "location-info-with-LMSI value" attrs = source[0:tag_length] tag_value = PCA_GenLib.getHexString(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) self.set_handler(name, attrs, tag_value) source = attrs name = "NNN" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "NNN value" attrs = source[1:tag_length] #tag_value = PCA_GenLib.getHexString(attrs) tag_value = PCA_GenLib.getHexBCDString(attrs) self.set_handler(name, tag_value, tag_value) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) #self.set_handler(name,attrs,tag_value) #source = source[1:] #name = "location GT" #attrs = source #content = PCA_GenLib.getHexBCDString(attrs) #self.set_handler(name,attrs,content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,tag_name,tag_value) if self.StartParsing == 1: self._cont_handler.endDocument(orig_data, self.DebugStr) Msg = "parser OK" PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parser :<%s>,<%s>,name=<%s>" % (sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 2) Msg = "orig data =\n%s" % PCA_GenLib.HexDump(orig_data) PCA_GenLib.WriteLog(Msg, 2) self.set_handler("opCode", "sendRoutingInfoForSM", "sendRoutingInfoForSM")
def parseTLV(self, data): try: Msg = "parseTLV Init " PCA_GenLib.WriteLog(Msg, 9) source = data tlv_desc = 'na' tlv_type = 'na' name = 'na' number_of_tlv = 0 Msg = "MAP shortMsgGateway SRI parseTLV data =\n%s" % PCA_GenLib.HexDump( source) PCA_GenLib.WriteLog(Msg, 0) tag = "" while len(source) > 0: number_of_tlv = number_of_tlv + 1 if number_of_tlv > 100: Msg = "number of TLV > 100 " PCA_GenLib.WriteLog(Msg, 0) break self.tag_index = self.tag_index + 1 name = "Tag" attrs = source[0] tag_desc = "na" try: tag_desc = PCA_MAPParameters.Tag_Desc[attrs] content = tag_desc if content == "invoke_id": if self.invoke_id == 1: tag_desc = "opCode" content = tag_desc self.invoke_id = 2 else: self.invoke_id = 1 else: content = tag_desc except: content = "undef:%s" % PCA_GenLib.getHexString(attrs) #tag = content #tag = "%s:%s" % (content,PCA_GenLib.getHexString(attrs)) tag = "%s" % content #self.set_handler(name,chr(0x00),content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) tag_class = ord(attrs) & 0xc0 tag_class = tag_class >> 6 Tag_Type = 'Primitive' if (ord(attrs) & 0x20): attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) Tag_Type = 'Constructor' else: content = ord(attrs) Tag_Type = 'Primitive' name = "tag type" content = Tag_Type Tag_form = "Extended format" if (ord(source[0]) & 0x1f) == 0x1f: Tag_form = "Extended format" source = source[2:] #source = source[1:] else: Tag_form = "One octet format" source = source[1:] name = "tag form" content = Tag_form #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) name = "length" name = "%s length" % tag attrs = source[0] content = ord(attrs) tag_length_form = "short" if content & 0x80: tag_length_form = "long" long_tag_length = chr(content & 0x7F) + source[1] content = struct.unpack("!H", long_tag_length)[0] tag_length = content else: tag_length_form = "short" content = struct.unpack("!B", attrs)[0] tag_length = content #self.set_handler(name,attrs,content) name = "%s %s" % (tag_length_form, name) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) if tag_length_form == "short": source = source[1:] else: source = source[2:] name = "value" name = "%s value" % tag attrs = source[0:tag_length] # OpCode if self.invoke_id == 2 and tag_desc == "opCode": content = ord(attrs) content = PCA_MAPParameters.op_code[content] elif tag_desc == "Originator_address" or tag_desc == "SC_Address" or tag_desc == "msisdn": TOA = PCA_GenLib.getHexString(attrs[0]) content = PCA_GenLib.getHexBCDString(attrs[1:]) content = "%s:%s" % (TOA, content) else: content = PCA_GenLib.getHexString(attrs) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) #self.set_handler(tag,attrs,content) if Tag_Type == 'Constructor': self.parseTLV(attrs) # DEBUG ONLY self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) self.set_handler(tag, attrs, content) #elif tag_desc == "SM_RP_UI" : # if self.Is_TCAP_begin == 1: # self.parseGSM0340_request(attrs) # else: # if self.app_context == "shortMsgGateway_SRI_v3": # # SRI response # self.parseGSM0340_SRI_SM_response(attrs) # else: # self.parseGSM0340_response(attrs) else: self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) self.set_handler(tag, attrs, content) try: source = source[tag_length:] except IndexError: Msg = "parseTLV index error : <%s>,<%s>,name=<%s> " % ( sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 0) break Msg = "parseTLV Ok " PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parseTLV error : <%s>,<%s>,name=<%s> " % ( sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 0)
def parse(self, source): try: Msg = "parser init" PCA_GenLib.WriteLog(Msg, 9) self.SOURCD_ID = 'HeartBeat' self.DebugStr = ' ' orig_data = source name = 'none' self.StartParsing = 1 self.bind_error = 0 start_pos = string.find(source, chr(0x00)) system_id = source[0:start_pos] self.DebugStr = "system_id = <%s>" % system_id source = source[start_pos + 1:] start_pos = string.find(source, chr(0x00)) password = source[0:start_pos] self.DebugStr = "%s , password = <%s>" % (self.DebugStr, password) source = source[start_pos + 1:] start_pos = string.find(source, chr(0x00)) system_type = source[0:start_pos] self.DebugStr = "%s , system_type = <%s>" % (self.DebugStr, system_type) source = source[start_pos + 1:] interface_version = struct.unpack("!b", source[0])[0] self.DebugStr = "%s , interface_version = <%s>" % ( self.DebugStr, interface_version) source = source[1:] ton = struct.unpack("!b", source[0])[0] self.DebugStr = "%s , ton = <%s>" % (self.DebugStr, ton) source = source[1:] npi = struct.unpack("!b", source[0])[0] self.DebugStr = "%s , npi = <%s>" % (self.DebugStr, npi) source = source[1:] start_pos = string.find(source, chr(0x00)) address_range = PCA_GenLib.getHexString(source[0:start_pos]) self.DebugStr = "%s , address_range = <%s>" % (self.DebugStr, address_range) if self.StartParsing == 1: self._cont_handler.endDocument(self.DebugStr, self.TID, self.SOURCD_ID) Msg = "parser OK" PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parser :<%s>,<%s>,name=<%s>" % (sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 0) Msg = "orig data =\n%s" % PCA_GenLib.HexDump(orig_data) PCA_GenLib.WriteLog(Msg, 0) Msg = "rest data =\n%s" % PCA_GenLib.HexDump(source) PCA_GenLib.WriteLog(Msg, 0) if self.StartParsing == 1: self._cont_handler.endDocument(self.DebugStr, self.TID, self.SOURCD_ID) raise
def parse_old(self, source): try: Msg = "parser init" PCA_GenLib.WriteLog(Msg,9) orig_data = source name = 'none' self.StartParsing = 0 TID = "na" content = "na" Msg = "MAP shortMORelay Response data =<\n%s\n>" % PCA_GenLib.HexDump(source) PCA_GenLib.WriteLog(Msg,5) if (source != None) : self._cont_handler.startDocument() self.StartParsing = 1 self.DebugStr = "" name = "MAP Tag" attrs = source[0] Tag_Type = 'Primitive' if (ord(attrs) & 0x40): name = "%s-Constructor" % name attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) else: name = "%s-Primitive" % name content = ord(attrs) self.set_handler(name,attrs,content) if Tag_Type == 'Primitive': source = source[1:] else: source = source[2:] self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name,attrs,content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) source = source[1:] name = "value" attrs = source[0:tag_length] content = PCA_GenLib.getHexString(attrs) self.set_handler(name,attrs,content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) #self.parseTLV(attrs) source = attrs name = "invoke" tag_name = name attrs = source[0] content = ord(attrs) #self.set_handler(name,attrs,content) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name,attrs,content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) source = source[1:] name = "invoke value" attrs = source[0] content = ord(attrs) tag_value = content self.set_handler(name,attrs,content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,tag_name,tag_value) source = source[1:] name = "resultretres" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "resultretres value" attrs = source[0:tag_length] #content = ord(attrs) source = attrs name = "opCode" tag_name = name attrs = source[0] content = ord(attrs) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content source = source[1:] name = "opCode value" attrs = source[0] content = ord(attrs) try: tag_value = PCA_MAPParameters.op_code[content] except: Msg = "unknow opCode Value = %s" % content PCA_GenLib.WriteLog(Msg,0) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,tag_name,tag_value) self.set_handler(name,attrs,tag_value) source = source[1:] name = "sm-rp-UI" tag_name = name attrs = source[0] content = ord(attrs) self.set_handler(name,attrs,content) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name,attrs,content) source = source[1:] name = "sm-rp-UI value" attrs = source[0:tag_length] tag_value = PCA_GenLib.getHexString(attrs) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,tag_name,tag_value) self.set_handler(name,attrs,tag_value) if self.StartParsing == 1: self._cont_handler.endDocument(orig_data,self.DebugStr) Msg = "parser OK" PCA_GenLib.WriteLog(Msg,9) except: Msg = "parser :<%s>,<%s>,name=<%s>" % (sys.exc_type,sys.exc_value,name) PCA_GenLib.WriteLog(Msg,0) Msg = "orig data =\n%s" % PCA_GenLib.HexDump(orig_data) PCA_GenLib.WriteLog(Msg,0) raise
def parseTLV(self,data): try: Msg = "parseTLV Init " PCA_GenLib.WriteLog(Msg,9) source = data tlv_desc = 'na' tlv_type = 'na' name = 'na' number_of_tlv = 0 Msg = "MAP parseTLV data =\n%s" % PCA_GenLib.HexDump(source) PCA_GenLib.WriteLog(Msg,3) tag_index = 0 while len(source) > 0: if number_of_tlv > 100: Msg = "number of TLV > 100 " PCA_GenLib.WriteLog(Msg,0) break tag_index = tag_index + 1 name = "Tag" name = "%s %s" % (name,tag_index) attrs = source[0] content = PCA_GenLib.getHexString(attrs) self.set_handler(name,chr(0x00),content) tag_class = ord(attrs) & 0xc0 tag_class = tag_class >> 6 Tag_Type = 'Primitive' if (ord(attrs) & 0x20): name = "C_%s-" % name name = "%s %s" % (name,tag_index) attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) Tag_Type = 'Constructor' else: name = "P_%s-" % name name = "%s %s" % (name,tag_index) content = ord(attrs) Tag_Type = 'Primitive' name = "%s-%s" % (name,PCA_MAPParameters.tag_class[tag_class]) if Tag_Type == 'Primitive': attrs = struct.pack("!b",ord(attrs) & 0x1f) name = "%s %s" % (name,tag_index) self.set_handler(name,attrs,content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) if Tag_Type == 'Primitive': source = source[1:] else: source = source[2:] name = "length" name = "%s %s" % (name,tag_index) attrs = source[0] content = ord(attrs) tag_length = content tag_length_form = "short" if tag_length > 128: tag_length_form = "long" attrs = source[1] content = ord(attrs) tag_length = content else: tag_length_form = "short" self.set_handler(name,attrs,content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) if tag_length_form == "short": source = source[1:] else: source = source[2:] name = "value" name = "%s %s" % (name,tag_index) attrs = source[0:tag_length] if Tag_Type == 'Constructor': content = PCA_GenLib.getHexBCDString(attrs[1:]) else: content = PCA_GenLib.getHexString(attrs) self.set_handler(name,attrs,content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) if Tag_Type == 'Constructor': self.parseTLV(attrs) try: source = source[tag_length:] except IndexError: Msg = "parseTLV index error : <%s>,<%s>,name=<%s> " % (sys.exc_type,sys.exc_value,name) PCA_GenLib.WriteLog(Msg,0) break Msg = "parseTLV Ok " PCA_GenLib.WriteLog(Msg,9) except: Msg = "parseTLV error : <%s>,<%s>,name=<%s> " % (sys.exc_type,sys.exc_value,name) PCA_GenLib.WriteLog(Msg,0)
def parseTLV(self,data): try: Msg = "parseTLV Init " PCA_GenLib.WriteLog(Msg,9) source = data tlv_desc = 'na' tlv_type = 'na' name = 'na' number_of_tlv = 0 tag_desc = "" #Msg = "MAP parseTLV data =\n%s" % PCA_GenLib.HexDump(source) #PCA_GenLib.WriteLog(Msg,0) tag = "" while len(source) > 0: number_of_tlv = number_of_tlv + 1 if number_of_tlv > 100: Msg = "number of TLV > 100 " PCA_GenLib.WriteLog(Msg,0) break self.tag_index = self.tag_index + 1 name = "Tag" attrs = source[0] tag_desc = "na" try: #content = "%s:%s" % (PCA_TCAPParameters.Tag_Desc[attrs],PCA_GenLib.getHexString(attrs)) if self.tcap_hearder_get == 0: self.tcap_hearder_get = 1 tag_desc = PCA_TCAPParameters.Tag_Header_Desc[attrs] else: tag_desc = PCA_TCAPParameters.Tag_Desc[attrs] #tag_desc = PCA_TCAPParameters.Tag_Desc[attrs] Msg = "tag_desc = <%s>" % tag_desc PCA_GenLib.WriteLog(Msg,3) content = tag_desc except: #content = "undef:%s" % PCA_GenLib.getHexString(attrs) content = "undef:%s" % PCA_GenLib.getHexString(attrs) #Msg = "PCA DEBUG error : <%s>,<%s> content = <%s>" % (sys.exc_type,sys.exc_value,content) #PCA_GenLib.WriteLog(Msg,0) #tag = content ##tag = "%s:%s" % (content,PCA_GenLib.getHexString(attrs)) tag = "%s" % content #self.set_handler(name,chr(0x00),content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) tag_class = ord(attrs) & 0xc0 tag_class = tag_class >> 6 Tag_Type = 'Primitive' if (ord(attrs) & 0x20): attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) Tag_Type = 'Constructor' else: content = ord(attrs) Tag_Type = 'Primitive' name = "tag type" content = Tag_Type #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) # name = "%s form" % tag #self.set_handler(name,chr(0x00),Tag_Type) #name = "%s-%s" % (name,PCA_TCAPParameters.tag_class[tag_class]) #if Tag_Type == 'Primitive': # attrs = struct.pack("!b",ord(attrs) & 0x1f) #name = "%s %s" % (tag,tag_index) #self.set_handler(name,attrs,content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) Tag_form = "Extended format" if (ord(source[0]) & 0x1f) == 0x1f: Tag_form = "Extended format" source = source[2:] #source = source[1:] else: Tag_form = "One octet format" source = source[1:] name = "tag form" content = Tag_form #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) name = "length" name = "%s length" % tag attrs = source[0] content = ord(attrs) tag_length_form = "short" if content & 0x80: tag_length_form = "long" long_tag_length = chr(content & 0x7F) + source[1] content = struct.unpack("!H",long_tag_length)[0] tag_length = content #tag_length = struct.unpack("!B" else: tag_length_form = "short" content = struct.unpack("!B",attrs)[0] tag_length = content #self.set_handler(name,attrs,content) name = "%s %s" % (tag_length_form,name) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) if tag_length_form == "short": source = source[1:] else: source = source[2:] name = "value" name = "%s value" % tag attrs = source[0:tag_length] if tag_desc == "oid": try: Msg = "oid debug =\n%s" % PCA_GenLib.HexDump(attrs) PCA_GenLib.WriteLog(Msg,3) content = PCA_GenLib.getOctString(attrs) self.app_context = PCA_TCAPParameters.app_context[content] Msg = "app_context = %s" % self.app_context PCA_GenLib.WriteLog(Msg,3) self.DebugStr = "%s,<application>=<%s>" % (self.DebugStr,self.app_context) content = self.app_context tag = 'ap_context_name' except: Msg = "id-as-dialog %s" % PCA_GenLib.getOctString(attrs) PCA_GenLib.WriteLog(Msg,2) content = "id-as-dialog %s" % PCA_GenLib.getOctString(attrs) elif tag_desc == "tcap_begin": self.Is_TCAP_begin = 1 content = PCA_GenLib.getHexString(attrs) elif tag_desc == "tcap_end": self.Is_TCAP_begin = 0 content = PCA_GenLib.getHexString(attrs) elif tag_desc == "tcap_continue": self.Is_TCAP_begin = 2 content = PCA_GenLib.getHexString(attrs) self.set_handler(tag_desc,attrs,content) #Msg = "PCA DEBUG tcap_continue " #PCA_GenLib.WriteLog(Msg,1) self.app_context = "shortMsgMT_Relay_v3_continue" self.set_handler("ap_context_name",self.app_context,self.app_context) else: content = PCA_GenLib.getHexString(attrs) #Msg = "PCA DEBUG tag_desc=<%s>,content=<%s>" % (tag_desc,content) #PCA_GenLib.WriteLog(Msg,1) if Tag_Type == 'Constructor': if tag_desc == "component_portion": Msg = "GSM 0340 layer , not parsing now" PCA_GenLib.WriteLog(Msg,3) self.set_handler("map_message",chr(0x00),attrs) #################################################### # Parsing MAP #################################################### #Msg = "MAP application data =<\n%s\n>" % PCA_GenLib.HexDump(attrs) #PCA_GenLib.WriteLog(Msg,3) else: self.parseTLV(attrs) #if tag_desc == "tcap_continue": # self.set_handler(tag_desc,attrs,content) #Msg = "PCA DEBUG Possible MT-FSM-Req tacp continue .... " #PCA_GenLib.WriteLog(Msg,1) #else: self.set_handler(tag,attrs,content) else: self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) self.set_handler(tag,attrs,content) try: source = source[tag_length:] except IndexError: Msg = "parseTLV index error : <%s>,<%s>,name=<%s> " % (sys.exc_type,sys.exc_value,name) PCA_GenLib.WriteLog(Msg,0) break Msg = "parseTLV Ok " PCA_GenLib.WriteLog(Msg,9) except: Msg = "parseTLV error : <%s>,<%s>,name=<%s> " % (sys.exc_type,sys.exc_value,name) PCA_GenLib.WriteLog(Msg,0)
def parseTLV(self, data): try: Msg = "parseTLV Init " PCA_GenLib.WriteLog(Msg, 9) source = data tlv_desc = 'na' tlv_type = 'na' name = 'na' number_of_tlv = 0 #Msg = "MAP parseTLV data =\n%s" % PCA_GenLib.HexDump(source) #PCA_GenLib.WriteLog(Msg,0) tag = "" while len(source) > 0: number_of_tlv = number_of_tlv + 1 if number_of_tlv > 100: Msg = "number of TLV > 100 " PCA_GenLib.WriteLog(Msg, 0) break self.tag_index = self.tag_index + 1 name = "Tag" attrs = source[0] tag_desc = "na" try: #content = "%s:%s" % (PCA_TCAPParameters.Tag_Desc[attrs],PCA_GenLib.getHexString(attrs)) tag_desc = PCA_TCAPParameters.Tag_Desc[attrs] content = tag_desc except: #content = "undef:%s" % PCA_GenLib.getHexString(attrs) content = "undef:%s" % PCA_GenLib.getHexString(attrs) #tag = content ##tag = "%s:%s" % (content,PCA_GenLib.getHexString(attrs)) tag = "%s" % content #self.set_handler(name,chr(0x00),content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) tag_class = ord(attrs) & 0xc0 tag_class = tag_class >> 6 Tag_Type = 'Primitive' if (ord(attrs) & 0x20): attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) Tag_Type = 'Constructor' else: content = ord(attrs) Tag_Type = 'Primitive' name = "tag type" content = Tag_Type #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) # name = "%s form" % tag #self.set_handler(name,chr(0x00),Tag_Type) #name = "%s-%s" % (name,PCA_TCAPParameters.tag_class[tag_class]) #if Tag_Type == 'Primitive': # attrs = struct.pack("!b",ord(attrs) & 0x1f) #name = "%s %s" % (tag,tag_index) #self.set_handler(name,attrs,content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) Tag_form = "Extended format" if (ord(source[0]) & 0x1f) == 0x1f: Tag_form = "Extended format" source = source[2:] #source = source[1:] else: Tag_form = "One octet format" source = source[1:] name = "tag form" content = Tag_form #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) name = "length" name = "%s length" % tag attrs = source[0] content = ord(attrs) tag_length_form = "short" if content & 0x80: tag_length_form = "long" long_tag_length = chr(content & 0x7F) + source[1] content = struct.unpack("!H", long_tag_length)[0] tag_length = content #tag_length = struct.unpack("!B" else: tag_length_form = "short" content = struct.unpack("!B", attrs)[0] tag_length = content #self.set_handler(name,attrs,content) name = "%s %s" % (tag_length_form, name) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) if tag_length_form == "short": source = source[1:] else: source = source[2:] name = "value" name = "%s value" % tag attrs = source[0:tag_length] if tag_desc == "oid": try: content = PCA_GenLib.getOctString(attrs) self.app_context = PCA_TCAPParameters.app_context[ content] Msg = "app_context = %s" % self.app_context PCA_GenLib.WriteLog(Msg, 3) self.DebugStr = "%s,<application>=<%s>" % ( self.DebugStr, self.app_context) content = self.app_context except: Msg = "undef ctx %s" % PCA_GenLib.getOctString(attrs) PCA_GenLib.WriteLog(Msg, 3) content = "undef ctx %s" % PCA_GenLib.getOctString( attrs) elif tag_desc == "tcap_begin": self.Is_TCAP_begin = 1 content = PCA_GenLib.getHexString(attrs) elif tag_desc == "tcap_end": self.Is_TCAP_begin = 0 content = PCA_GenLib.getHexString(attrs) else: content = PCA_GenLib.getHexString(attrs) if Tag_Type == 'Constructor': if tag_desc == "component_portion": Msg = "GSM 0340 layer , not parsing now" PCA_GenLib.WriteLog(Msg, 3) #################################################### # Parsing MAP #################################################### Msg = "MAP application data =<\n%s\n>" % PCA_GenLib.HexDump( attrs) PCA_GenLib.WriteLog(Msg, 3) dll_file_name = self.app_context Msg = "dll_file_name = <%s>" % dll_file_name PCA_GenLib.WriteLog(Msg, 3) #dll_file_name = "PCA_MAPParser" Script_File = PCA_DLL.DLL(dll_file_name) factory_function = "Parser" factory_component = Script_File.symbol( factory_function) parser = factory_component() Script_File = PCA_DLL.DLL(dll_file_name) factory_function = "Handler" factory_component = Script_File.symbol( factory_function) handler = factory_component() parser.setContentHandler(handler) parser.parse(attrs, self.Is_TCAP_begin, self.app_context) response_message = handler.getHandlerResponse() self.set_handler('map_msg_dict', chr(0x00), response_message) response_ServerID = handler.getTID() response_DebugStr = handler.getDebugStr() self.DebugStr = "%s,<MAP MSG>=%s" % (self.DebugStr, response_DebugStr) else: self.parseTLV(attrs) self.set_handler(tag, attrs, content) else: self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) self.set_handler(tag, attrs, content) try: source = source[tag_length:] except IndexError: Msg = "parseTLV index error : <%s>,<%s>,name=<%s> " % ( sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 0) break Msg = "parseTLV Ok " PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parseTLV error : <%s>,<%s>,name=<%s> " % ( sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 0)
def parse(self, source, Is_TCAP_begin, app_context): try: Msg = "parser init" PCA_GenLib.WriteLog(Msg, 9) orig_data = source name = 'none' self.StartParsing = 0 TID = "na" content = "na" Msg = "MAP SRI-SM data =<\n%s\n>" % PCA_GenLib.HexDump(source) PCA_GenLib.WriteLog(Msg, 3) if (source != None): self._cont_handler.startDocument() self.StartParsing = 1 self.DebugStr = "" name = "MAP Tag" attrs = source[0] Tag_Type = 'Primitive' if (ord(attrs) & 0x40): name = "%s-Constructor" % name attrs = source[0:2] content = PCA_GenLib.getHexString(attrs) else: name = "%s-Primitive" % name content = ord(attrs) self.set_handler(name, attrs, content) if Tag_Type == 'Primitive': source = source[1:] else: source = source[2:] self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name, attrs, content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, name, content) source = source[1:] name = "value" attrs = source[0:tag_length] content = PCA_GenLib.getHexString(attrs) self.set_handler(name, attrs, content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) #self.parseTLV(attrs) source = attrs name = "invoke" tag_name = name attrs = source[0] content = ord(attrs) self.set_handler(name, attrs, content) source = source[1:] name = "length" attrs = source[0] content = ord(attrs) tag_length = content self.set_handler(name, attrs, content) #self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr,name,content) source = source[1:] #name = "invoke value" name = "invoke_id" attrs = source[0] content = ord(attrs) tag_value = content self.set_handler(name, attrs, content) self.DebugStr = "%s,<%s>=<%s>" % (self.DebugStr, tag_name, tag_value) if self.StartParsing == 1: self._cont_handler.endDocument(orig_data, self.DebugStr) Msg = "parser OK" PCA_GenLib.WriteLog(Msg, 9) except: Msg = "parser :<%s>,<%s>,name=<%s>" % (sys.exc_type, sys.exc_value, name) PCA_GenLib.WriteLog(Msg, 1) Msg = "orig data =\n%s" % PCA_GenLib.HexDump(orig_data) PCA_GenLib.WriteLog(Msg, 1)