class GA_RRC_hdr(Layer): constructorList = [ Int(CallName='len', ReprName='Message Length', Type='uint16'), Bit(CallName='si', ReprName='Skip Indicator', Pt=0, BitLen=4, Repr='hex'), Bit(CallName='pd', ReprName='Protocol Discriminator', Pt=3, BitLen=4, Repr='hum', Dict=ProtocolDiscriminator), Int(CallName='type', ReprName='Message Type', Type='uint8', Dict=RRCMsgType) ] def __init__(self, type=0): Layer.__init__(self, CallName='hdr') self.len.Pt = self.get_payload self.len.PtFunc = lambda pay: len(pay()) + 2 self.type.Pt = type
class ToCeff(Layer): _byte_aligned = False constructorList = [ Bit('F', ReprName='Frame following', Pt=0, BitLen=1), Bit('FT', ReprName='Frame Type index', Pt=0, BitLen=4, \ Dict=codecs_dict, Repr='hum'), Bit('Q', ReprName='Frame Quality indicator', Pt=1, BitLen=1)]
def __init__(self, with_options=False, with_security=False, **kwargs): Layer3NASEMM.__init__(self, with_security) self.extend([ Int('NASSecAlg', ReprName='Selected NAS Security Algorithms', Pt=0, Type='uint8', Repr='hex'), Bit('spare', Pt=0, BitLen=4), Bit('NASKSI', ReprName='NAS Key Set Indentifier', Pt=0, BitLen=4, Dict=NASKSI_dict, Repr='hum'), Type4_LV('UESecCap', ReprName='Replayed UE Security Capabilities', V=2 * '\0'), Type1_TV('IMEISVReq', T=0x0C, V=0), Type3_TV('NonceUE', ReprName='Replayed Nonce UE', T=0x55, V=4 * '\0', Len=4), Type3_TV('NonceMME', T=0x56, V=4 * '\0', Len=4) ]) self._post_init(with_options, **kwargs)
class GA_PSR_hdr(Layer): constructorList = [ Int(CallName='len', ReprName='Message Length', Type='uint16'), Bit(CallName='si', ReprName='Skip Indicator', Pt=0, BitLen=4, Repr='hex'), Bit(CallName='pd', ReprName='Protocol Discriminator', Pt=2, BitLen=4, Repr='hum', Dict=ProtocolDiscriminator), Int(CallName='type', ReprName='Message Type', Type='uint8', Dict=PSRMsgType), Int(CallName='tlli', ReprName='Temporary Logical Link Identity', Type='uint32'), ] def __init__(self, type=0, tlli=0): Layer.__init__(self, CallName='hdr') self.len.Pt = self.get_payload self.len.PtFunc = lambda pay: len(pay()) + 2 self.type.Pt = type self.tlli.Pt = tlli
class SERVICE_REQUEST(Layer3NASEMM): ''' UE -> Net Dual special processing, sent during radio bearer establishment ''' constructorList = [ Bit('SH', ReprName='Security Header Type', Pt=1, BitLen=4, Dict=SecHdr_dict, Repr='hum'), Bit('PD', ReprName='Protocol Discriminator', Pt=7, BitLen=4, Dict=PD_dict, Repr='hum'), Bit('NASKSI', Pt=0, BitLen=3, Dict=NASKSI_dict, Repr='hum'), Bit('SN', ReprName='NAS COUNT LSB', Pt=0, BitLen=5, Repr='hum'), Str('MAC', ReprName='Message Authentication Code LSB', Pt='\0\0', Len=2, Repr='hex') ]
def __init__(self, with_options=False, with_security=False, **kwargs): Layer3NASEMM.__init__(self, with_security) self.extend([ Bit('NASKSI', ReprName='NAS Key Set Indentifier', Pt=0, BitLen=4, Dict=NASKSI_dict, Repr='hum'), Bit('ServType', ReprName='Service Type', Pt=0, BitLen=4, Dict=ServType_dict, Repr='hum'), Type4_LV('ID', ReprName='M-TMSI', V=ID()), Type1_TV('CSFBResp', T=0xB, V=0, Dict=CSFBResp_dict), Type4_TLV('EPSCtxStat', ReprName='EPS Bearer Context Status', T=0x57, V=2 * '\0'), Type1_TV('DevProp', ReprName='Device Properties', T=0xD, V=0, Dict=DevProp_dict) ]) self._post_init(with_options, **kwargs)
def __init__(self, with_options=False, with_security=False, **kwargs): Layer3NASEMM.__init__(self, with_security) if self._initiator != 'Net': self.extend([ Bit('NASKSI', ReprName='NAS Key Set Indentifier', Pt=0, BitLen=4, Dict=NASKSI_dict, Repr='hum'), Bit('DetType', ReprName='Detach Type', Pt=0, BitLen=4, Dict=MEDetType_dict, Repr='hum'), Type4_LV('EPS_ID', ReprName='EPS Mobile Identity', V=4 * '\0') ]) else: self.extend([ Bit('spare', Pt=0, BitLen=4), Bit('DetType', ReprName='Detach Type', Pt=0, BitLen=4, Dict=NetDetType_dict, Repr='hum'), Type3_TV('EMMCause', T=0x53, V='\0', Len=1) ]) self._post_init(with_options, **kwargs)
def __init__(self, with_options=False, with_security=False, **kwargs): Layer3NASEMM.__init__(self, with_security) self.extend([ Bit('spare', Pt=0, BitLen=4), Bit('EPSUpdRes', ReprName='EPS Update Result', Pt=0, BitLen=4, Dict=EPSUpdRes_dict, Repr='hum'), Type3_TV('T3412', ReprName='GPRS Timer', T=0x5A, V='\0', Len=1), Type4_TLV('GUTI', T=0x50, V=11*'\0'), Type4_TLV('TAIList', ReprName='Tracking Area Identity List', T=0x54, V=6*'\0'), Type4_TLV('EPSCtxStat', ReprName='EPS Bearer Context Status', T=0x57, V=2*'\0'), Type3_TV('LAI', ReprName='Old LAI', T=0x13, V=LAI(), Len=5), Type4_TLV('ID', T=0x23, V=ID()), Type3_TV('EMMCause', T=0x53, V='\0', Len=1), Type3_TV('T3402', T=0x17, V='\0', Len=1), Type3_TV('T3423', T=0x59, V='\0', Len=1), Type4_TLV('PLMNList', ReprName='Equivalent PLMNs', T=0x4A, V=PLMNList()), Type4_TLV('ECNList', ReprName='Emergency Number List', T=0x34, V='\0\0\0'), Type4_TLV('EPSFeatSup', ReprName='EPS Network Feature Support', T=0x64, V='\0'), Type1_TV('AddUpdRes', ReprName='Additional Update Result', T=0xF, V=0), Type4_TLV('T3412ext', ReprName='GPRS Timer 3', T=0x5E, V='\0') ]) self._post_init(with_options, **kwargs)
def encode_bit_str(self, obj): if isinstance(obj._val, ASN1.ASN1Obj): # obj._val: ASN1Obj, according to CONTAINING constraint V = Layer('V') V.append(Int('pad_len', Pt=0, Type='uint8')) obj._val._encode() V.extend(obj._val._msg) obj._val._msg = None # else: # obj._val: (BE uint value, BE uint bit length) val_len = obj._val[1] // 8 val_ext = obj._val[1] % 8 if val_ext: val_len += 1 V = Layer('V') V.append(Int('pad_len', Pt=(8 - val_ext) % 8, Type='uint8')) V.append( Bit('val', Pt=obj._val[0], BitLen=obj._val[1], Repr=self._REPR_BIT_STR)) if val_ext > 0: V.append( Bit('pad', Pt=0, BitLen=8 - val_ext, Repr=self._REPR_BIT_STR)) # obj._msg = BER_TLV(obj.get_name()) obj._msg.set(V) self.handle_tag_enc(obj)
class SOS(segment): constructorList = [ Int('mark', Pt=0xFF, Type='uint8', Repr='hex'), Int('type', Pt=0xDA, Type='uint8', Repr='hum', Dict=Seg_dict), Int('len', Pt=0, Type='uint16'), Int('Nf', ReprName='Number of image components in frame', Pt=0, \ Type='uint8'), Str('components', Pt=''), Int('Ss', ReprName='Start of spectral or predictor selection', Pt=0, \ Type='uint8'), Int('Se', ReprName='End of spectral selection', Pt=0, Type='uint8'), Bit('Ah', ReprName='Successive approximation bit position high', \ Pt=0, BitLen=4, Repr='hum'), Bit('Al', ReprName='Successive approximation bit position low', \ Pt=0, BitLen=4, Repr='hum'), ] def __init__(self, **kwargs): Layer.__init__(self, **kwargs) self.components.Len = self.len self.components.LenFunc = lambda l: l() - 6 self.len.Pt = self.components self.len.PtFunc = lambda p: len(p) + 6 def map(self, s=''): Layer.map(self, s) if len(self.components) / 2.0 == self.Nf(): cpn_s = self.components() self.remove(self.components) pos = 4 while len(cpn_s) > 0: self.insert(pos, SOSComponent()) self[pos].map(cpn_s) cpn_s = cpn_s[2:] pos += 1
def __init__(self, with_options=True, **kwargs): Layer3.__init__(self) self.extend([ \ Bit('Level', Pt=0, BitLen=4, Repr='hum'), Bit('spare', Pt=0, BitLen=4), Type4_TLV('Cause', T=0x8, V='\0\x80')]) self._post_init(with_options, **kwargs)
def __init__(self, CallName='', LH='L', Dict=None): self.LHdict = iad({0:'L', 1:'H'}) Bit.__init__(self, CallName=CallName, BitLen=1, Dict=Dict, Repr='hum') if LH not in ('L', 'H'): LH = 'L' self.LH = LH self.Pt = 0 self.PtFunc = self.__lh_val
class RP_DATA_NETToMS(Layer): ''' Net -> MS ''' constructorList = [ Bit('spare', Pt=0, BitLen=5, Repr='hex'), Bit('Type', Pt=1, BitLen=3, Repr='hum', Dict=RPType_dict), Int('Ref', Type='uint8'), # reference to be used in ACKed RP_Originator_Address(), # length 1-12 Type4_LV('DestAddrNull', V=''), # null address Type4_LV('Data', V=''), # length <= 233 ] def map(self, s=''): Layer.map(self, s) self._map_tp() def _map_tp(self): data = self.Data.V() if not data: return mti = ord(data[0])&0b11 if mti != 0: return tp = SMS_DELIVER() try: tp.map(data) except: return if str(tp) != data: return self.Data.L > tp self.Data.V > tp self.Data.V < None
class DHT(segment): constructorList = [ Int('mark', Pt=0xFF, Type='uint8', Repr='hex'), Int('type', Pt=0xC4, Type='uint8', Repr='hum', Dict=Seg_dict), Int('len', Pt=0, Type='uint16'), Bit('Tc', ReprName='Huffman table class', Pt=0, BitLen=4, Repr='hum'), Bit('Th', ReprName='Huffman table destination identifier', Pt=0, \ BitLen=4, Repr='hum')] + [ \ Int('L%i'%i, ReprName='Number of huffman codes of length %i'%i, \ Pt=0, Type='uint8') for i in range(1, 17)] + \ [Str('V', ReprName='Values for huffman codes of given length', Pt='')] # this is a shortcut for huffman Values def __init__(self, **kwargs): Layer.__init__(self, **kwargs) # length automation self.len.Pt = self.L1 self.len.PtFunc = lambda x: sum(map(len, self[21:])) + 19 # huffman values length automation self.V.Len = self.L1 self.V.LenFunc = lambda x: sum(map(int, self[5:21])) def map(self, s=''): Layer.map(self, s) values, pos = self.V(), 0 self.remove(self[-1]) for i in self[5:21]: for j in range(1, i() + 1): ith = int(i.CallName[1:]) self.append(\ Int('V%i%i'%(ith,j), \ ReprName='Value %i for huffman code of length %i'%(j,ith), \ Val=ord(values[pos]), Type='uint8')) pos += 1
class SMS_COMMAND(Layer): constructorList = [ Bit('spare', Pt=0, BitLen=1), Bit('TP_UDHI', ReprName='TP User Data Header Indicator', Pt=0, BitLen=1), Bit('TP_SRR', ReprName='TP Status Report Request', Pt=0, BitLen=1, \ Repr='hum', Dict=TP_SRR_dict), Bit('spare', Pt=0, BitLen=3), Bit('TP_MTI', ReprName='TP Message Type Indicator', Pt=0, BitLen=2, \ Repr='hum', Dict=TP_MTI_MStoSC_dict), Int('TP_MR', ReprName='TP Message Reference', Pt=0, Type='uint8'), TP_PID(), Int('TP_CT', ReprName='TP Command Type', Pt=0, Type='uint8', \ Dict=TP_CT_dict), Int('TP_MN', ReprName='TP Message Number', Pt=0, Type='uint8'), TP_Destination_Address(), # length 2-12 Int('TP_CDL', ReprName='TP Command Data Length', Type='uint8'), Str('TP_CD', Pt=''), ] def __init__(self, with_options=False, **kwargs): Layer.__init__(self, **kwargs) self.TP_CDL.Pt = self.TP_CD self.TP_CDL.PtFunc = lambda d: len(d) self.TP_CD.Len = self.TP_CDL self.TP_CD.LenFunc = lambda l: l()
class LAPDm_ctrl(Layer): # byte unalignment is needed to compute correctly # transparency bit per bit _byte_aligned = False # msb_data can be: recv() seq number # lsb_data can be: send() seq number constructorList = [ Bit('msb_data', Pt=0, BitLen=3, Repr='hum'), Bit('PF', ReprName='Poll / Final bit', Pt=0, BitLen=1, Repr='hum'), Bit('lsb_data', Pt=0, Repr='hum'), Bit('fmt_ext', Pt=1, Repr='hum', Dict=LAPFmtExt_dict), Bit('fmt', Pt=1, Repr='hum', Dict=LAPFmt_dict) ] def __init__(self, **kwargs): Layer.__init__(self, **kwargs) # fmt, fmt_ext and lsb_data: length automation self.fmt_ext.Trans = self.fmt self.fmt_ext.TransFunc = lambda f: False if f() else True self.lsb_data.BitLen = self.fmt self.lsb_data.BitLenFunc = lambda f: 2 if f() else 3 # this map() is needed, cause lsb_data and fmt_ext # depends on fmt, which comes after them... def map(self, string=''): if len(string) > 0: self.fmt < ord(string[0])&0b1 Layer.map(self, string)
def __init__(self, with_options=True, **kwargs): Layer3.__init__(self) self.extend([ \ Bit('ForceStdby', ReprName='Force to standby', Pt=0, BitLen=4, Repr='hum', Dict=ForceStdby_dict), Bit('AttachResFOP', ReprName='Attach follow-on proceed', Pt=0, BitLen=1, Repr='hum', Dict=AttachResFOP_dict), Bit('AttachRes', ReprName='Attach result', Pt=1, BitLen=3, Repr='hum', Dict=AttachRes_dict), Int('GPRSTimer', ReprName='Periodic RA update timer', Pt=0, Type='uint8'), Bit('RadioPrio_2', ReprName='Radio priority 2', Pt=1, BitLen=4), Bit('RadioPrio', ReprName='Radio priority', Pt=1, BitLen=4), Str('RAI', ReprName='Routing area identification', Pt=6*'\0', Len=6), Type3_TV('PTMSISign', ReprName='Old P-TMSI signature', T=0x19, V=3*'\0', Len=3), Type3_TV('GPRSTimer_2', ReprName='Negotiated READY timer', T=0x17, V='\0', Len=1), Type4_TLV('ID', ReprName='Allocated P-TMSI', T=0x18, V=ID(type='TMSI')), Type4_TLV('ID_2', ReprName='MS identity', T=0x23, V=ID()), Type3_TV('GMMCause', T=0x25, V='\x01', Len=1), # see GMMCause_dict Type4_TLV('T3302', T=0x2A, V='\0'), Type2('CellNotif', T=0x8C), Type4_TLV('PLMNList', ReprName='Equivalent PLMNs', T=0x4A, V=PLMNList()), Type1_TV('NetFeatSupport', T=0xA, V=0), Type4_TLV('T3319', T=0x37, V='\0'), Type4_TLV('T3323', T=0x38, V='\0'), ]) self._post_init(with_options, **kwargs)
def __init__(self, with_options=True, **kwargs): Layer3.__init__(self) self.extend([ \ Bit('spare', Pt=0, BitLen=2), Bit('SAPI', Pt=0, BitLen=2), Bit('SAPI_PD', Pt=6, BitLen=4, Dict=PD_dict, Repr='hum')]) self._post_init(with_options, **kwargs)
class AMRalign(Layer): constructorList = [ Bit('CMR', ReprName='Codec Mode Request', Pt=0, BitLen=4, \ Dict=codecs_dict, Repr='hum'), Bit('res', Pt=0, BitLen=4), Bit('ILL', ReprName='Interleaving length', BitLen=4, Trans=True), Bit('ILP', ReprName='Interleaving index', BitLen=4, Trans=True)]
class DATA(SCTP_chunk): constructorList = [ Int(CallName='type', ReprName='Chunk Type', Pt=0, Type='uint8', \ Dict=chunk_dict), Bit(CallName='res', ReprName='Reserved', Pt=0, BitLen=5), Bit(CallName='U', ReprName='Unordered', Pt=0, BitLen=1), Bit(CallName='B', ReprName='Beginning', Pt=0, BitLen=1), Bit(CallName='E', ReprName='Ending', Pt=0, BitLen=1), Int(CallName='len', ReprName='Chunk Length', Type='uint16'), Int(CallName='tsn', ReprName='Transmission Sequence Number', Type='uint32'), Int(CallName='sid', ReprName='Stream Identifier', Type='uint16'), Int(CallName='sqn', ReprName='Stream Sequence Number', Type='uint16'), Int(CallName='ppid', ReprName='Payload Protocol Identifier', Type='uint32', \ Dict=protocol_dict), Str(CallName='data', ReprName='User Data'), Str(CallName='pad', ReprName='Padding', Repr='hex'), ] padding_byte = '\x00' def __init__(self, tsn=0, sid=0, sqn=0, ppid=0, data=''): Layer.__init__(self, CallName='data', ReprName='SCTP DATA chunk') self.len.Pt = self.data self.len.PtFunc = lambda data: len(data) + 16 self.tsn.Pt = tsn self.sid.Pt = sid self.sqn.Pt = sqn self.ppid.Pt = ppid self.data.Pt = data self.pad.Pt = self.data self.pad.PtFunc = lambda val: self._pad(s=val) self.pad.Len = self.data self.pad.LenFunc = lambda val: len(val) % 4
class INIT_ACK(Layer): constructorList = [ Int(CallName='type', ReprName='Chunk Type', Pt=2, Type='uint8', \ Dict=chunk_dict), Bit(CallName='res', ReprName='Reserved', Pt=0, BitLen=5), Bit(CallName='U', ReprName='Unordered', Pt=0, BitLen=1), Bit(CallName='B', ReprName='Beginning', Pt=0, BitLen=1), Bit(CallName='E', ReprName='Ending', Pt=0, BitLen=1), Int(CallName='len', ReprName='Chunk Length', Type='uint16'), Int(CallName='init', ReprName='Initiate Tag', Type='uint32'), Int(CallName='a_rwnd', ReprName='Advertised Receiver Wundow Credit', \ Type='uint32'), Int(CallName='outs', ReprName='Number of Outbound Streams', Type='uint16'), Int(CallName='ins', ReprName='Number of Inbound Streams', Type='uint16'), Int(CallName='itsn', ReprName='Initial Transmission Sequence Number', \ Type='uint32'), ] def __init__(self, init=0x6D696368, a_rwnd=0x00100000, \ outs=10, ins=10, itsn=0x6D696368): Layer.__init__(self, CallName='init-ack', ReprName='SCTP INIT ACK chunk') self.len.Pt = self.get_payload self.len.PtFunc = lambda pay: len(pay()) + 16 self.init.Pt = init self.a_rwnd.Pt = a_rwnd self.outs.Pt = outs self.ins.Pt = ins self.itsn.Pt = itsn
def __init__(self, with_options=True, **kwargs): Layer3.__init__(self) self.extend([ \ Bit('Dedicated', ReprName='Dedicated mode or TBF', Pt=0, \ BitLen=4, Repr='hum', Dict=Dedic_dict), Bit('Page', ReprName='Page mode', Pt=0, BitLen=4, Repr='hum', \ Dict=Page_dict), Str('ChanDesc', ReprName='Channel description', \ Pt=ChanDesc(), Len=3), # 44018, 10.5.2.5, in L3GSM_IE.py Str('PChanDesc', ReprName='Packet channel description', \ Pt=PChanDesc(build_auto=True), Len=3), # TODO: 44018, 10.5.2.25a Str('ReqRef', ReprName='Request reference', Pt=ReqRef(), \ Len=3), # TODO: 44018, 10.5.2.30 Int('TimeAdv', ReprName='Timing Advance', Pt=0, Type='uint8'), Type4_LV('MobAlloc', ReprName='Mobile allocation', \ V=MobAlloc()), # 44018, 10.5.2.21, in L3GSM_IE.py Type3_TV('Start', ReprName='Starting time', T=0x7C, \ V='\0\0', Len=2), # 44018, 10.5.2.38 StrRR('IARestOctets', Repr='hex')]) # 44018, 10.5.2.16 self._post_init(with_options, **kwargs) # L2 pseudo header automation self.len.Pt = (self.ChanDesc, self.PChanDesc, self.MobAlloc, self.Start) self.len.PtFunc = lambda x: sum(map(len, x))+7 self.IARestOctets.Len = self.len self.IARestOctets.LenFunc = lambda l: 22-l() # Handling of packet / CS dedicated chan assignment self.ChanDesc.Trans = self.Dedicated self.ChanDesc.TransFunc = lambda dedi: False if dedi() == 0 else True self.PChanDesc.Trans = self.Dedicated self.PChanDesc.TransFunc = lambda dedi: False if dedi() in (1,3,5,7) \ else True
class L(Layer): _byte_aligned = True constructorList = [ Bit('Form', Pt=0, BitLen=1, Repr='hum', Dict={0:'short', 1:'long'}), Bit('L', Pt=0, BitLen=7, Repr='hum') ] def __init__(self, **kwargs): if 'indefinite' in kwargs and kwargs['indefinite']: # indefinite form Layer.__init__(self, Form=1, L=0) else: # default short definite form Layer.__init__(self, **kwargs) if self.Form(): # long definite form self.set(kwargs['L'], force_long=True) def set(self, L=0, force_long=False): if L <= 127 and not force_long: self.Form.Pt = 0 self.L.Pt = L else: self.Form.Pt = 1 # encode the length in the minimum number of bytes len_hex = hex(L)[2:] if len_hex[-1] == 'L': len_hex = len_hex[:-1] if len(len_hex) % 2: len_hex = '0'+len_hex self.L.Pt = len(len_hex)//2 self.append( Bit('L_ext', Pt=L, BitLen=len(len_hex)*4, Repr='hum') ) def get(self): return self() def map(self, s=''): if len(s) < 1: return '' if len(self.elementList) != 2: self.__init__() Layer.map(self, s[0]) if self.Form() and self.L(): self.append( Bit('L_ext', BitLen=self.L()*8, Repr='hum') ) self[-1].map(s[1:]) def __call__(self): if self.Form(): if self.L() == 0: return -1 else: return self.L_ext() else: return self.L() def __repr__(self): form = self.Form.Dict[self.Form()] if self() == -1: form = 'indefinite' return '<Len [%s]: %s>' % (form, self())
class DACComponent(Layer): constructorList = [ Bit('Tc', ReprName='Table class', Pt=0, BitLen=4, Repr='hum'), Bit('Tb', ReprName='Arithmetic coding conditioning table destination identifier', \ Pt=0, BitLen=4, Repr='hum'), Int('CS', ReprName='Conditioning table value', Pt=0, Type='uint8'), ]
class TP_PID(Layer): _byte_aligned = False constructorList = [ Bit('Format', Pt=0, BitLen=2, Repr='hum', Dict=TP_PID_format_dict), Bit('Telematic', Pt=0, BitLen=1, Repr='hum', Dict=TP_PID_telematic_dict), Bit('Protocol', Pt=0, Repr='hum') ] def __init__(self, **kwargs): Layer.__init__(self, **kwargs) # telematic and protocol field length self.Telematic.Trans = self.Format self.Telematic.TransFunc = lambda f: True if f() else False self.Protocol.BitLen = self.Format self.Protocol.BitLenFunc = lambda f: 6 if f() else 5 # dictionnary selection self.Protocol.Dict = self.Format self.Protocol.DictFunc = self._get_dict def _get_dict(self, f): if f() == 0: if self.Telematic() == 1: return TP_PID_teleserv_dict else: return TP_PID_serv_dict elif f() == 1: return TP_PID_serv_dict else: return {}
class ToC(Layer): constructorList = [ Bit('F', ReprName='Frame following', Pt=0, BitLen=1), Bit('FT', ReprName='Frame Type index', Pt=0, BitLen=4, \ Dict=codecs_dict, Repr='hum'), Bit('Q', ReprName='Frame Quality indicator', Pt=1, BitLen=1), Bit('P', ReprName='Padding', Pt=0, BitLen=2)]
class SMS_SUBMIT_REPORT_RP_ERROR(Layer): constructorList = [ Bit('spare', Pt=0, BitLen=1), Bit('TP_UDHI', ReprName='TP User Data Header Indicator', Pt=0, BitLen=1), Bit('spare', Pt=0, BitLen=4), Bit('TP_MTI', ReprName='TP Message Type Indicator', Pt=0, BitLen=2, \ Repr='hum', Dict=TP_MTI_SCtoMS_dict), Int('TP_FCS', ReprName='Failure Cause', Pt=0, Type='uint8', \ Dict=TP_FCS_dict), # only on RP-ERROR TP_PI(), TP_SCTS(), TP_PID(), TP_DCS(), Int('TP_UDL', ReprName='User Data Length (in character)', Pt=0, \ Type='uint8'), Str7b('TP_UD', Pt=''), ] def __init__(self, with_options=False, **kwargs): Layer.__init__(self, **kwargs) self.TP_UDL.Pt = self.TP_UD self.TP_UDL.PtFunc = self._get_udl self.TP_UD.Len = self.TP_UDL self.TP_UD.LenFunc = self._get_ud_len if not with_options: self.TP_PID.Trans = True self.TP_DCS.Trans = True self.TP_UDL.Trans = True self.TP_UD.Trans = True def _get_udl(self, _unused): if hasattr(self.TP_DCS, 'Charset') \ and not self.TP_DCS.Charset.is_transparent(): if self.TP_DCS.Charset() == 1: return len(self.TP_UD) elif self.TP_DCS.Charset() == 2: return len(self.TP_UD)//2 return len(self.TP_UD.decode()) def _get_ud_len(self, _unused): if hasattr(self.TP_DCS, 'Charset') \ and not self.TP_DCS.Charset.is_transparent(): if self.TP_DCS.Charset() == 1: return self.TP_UDL() elif self.TP_DCS.Charset() == 2: return self.TP_UDL()*2 return int(ceil(self.TP_UDL()*7.0/8)) def map(self, s=''): s_len = len(s) if s_len < 14: self.TP_UD.Trans = True if s_len < 13: self.TP_UDL.Trans = True if s_len < 12: self.TP_DCS.Trans = True if s_len < 11: self.TP_PID.Trans = True Layer.map(self, s)
def __init__(self, with_options=True, **kwargs): Layer3.__init__(self) self.extend([ \ Bit('ForceStdby', ReprName='Force to standby', Pt=0, BitLen=4, Repr='hum', Dict=ForceStdby_dict), Bit('IDtype', Pt=1, BitLen=4, Repr='hum', Dict=IDType_dict) ]) self._post_init(with_options, **kwargs)
class TP_PI(Layer): constructorList = [ Bit('Ext', Pt=0, BitLen=1), Bit('Res', Pt=0, BitLen=4), Bit('TP-UDL', Pt=0, BitLen=1), Bit('TP-DCS', Pt=0, BitLen=1), Bit('TP-PID', Pt=0, BitLen=1), ]
class SOSComponent(Layer): constructorList = [ Int('Cs', ReprName='Scan component selector', Pt=0, Type='uint8'), Bit('Td', ReprName='DC entropy coding table destination selector', \ Pt=0, BitLen=4, Repr='hum'), Bit('Ta', ReprName='AC entropy coding table destination selector', \ Pt=0, BitLen=4, Repr='hum'), ]