Exemplo n.º 1
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Str('ChanDesc', ReprName='Channel Description 2', Pt=ChanDesc(), \
             Len=3), # TODO: check 10.5.2.5a, with diff TDMAoff_dict
         Str('PowCmd', ReprName='Power Command', Pt='\0', Len=1),
         Type4_TLV('FreqList', ReprName='Frequency list, after time', \
                   T=0x05, V='\0\0'),
         Type3_TV('CellChan', ReprName='Cell Channel description', \
                  T=0x62, V=CellChan(), Len=16),
         Type4_TLV('MultAlloc', ReprName='Multi-slot allocation', \
                   T=0x10, V='\0'),
         Type3_TV('ChanSet1', ReprName='Channel Set 1', T=0x63, \
                  V='\0', Len=1),
         Type3_TV('ChanSet2', ReprName='Channel Set 2', T=0x11, \
                  V='\0', Len=1),
         Type3_TV('ChanSet3', ReprName='Channel Set 3', T=0x13, \
                  V='\0', Len=1),
         Type3_TV('ChanSet4', ReprName='Channel Set 4', T=0x14, \
                  V='\0', Len=1),
         Type3_TV('ChanSet5', ReprName='Channel Set 5', T=0x15, \
                  V='\0', Len=1),
         Type3_TV('ChanSet6', ReprName='Channel Set 6', T=0x16, \
                  V='\0', Len=1),
         Type3_TV('ChanSet7', ReprName='Channel Set 7', T=0x17, \
                  V='\0', Len=1),
         Type3_TV('ChanSet8', ReprName='Channel Set 8', T=0x18, \
                  V='\0', Len=1),
         Type3_TV('ChanDesc_2', ReprName='2nd channel description, ' \
                  'after time', T=0x64, V=ChanDesc(), Len=3),
         Type3_TV('ChanMod2', ReprName='Channel Mode 2', T=0x66, \
                  V='\0', Len=1),
         Type4_TLV('MobAlloc', ReprName='Mobile allocation', T=0x72, \
                   V=MobAlloc()),
         Type3_TV('Start', ReprName='Starting time', T=0x7C, \
                  V='\0\0', Len=2),
         Type4_TLV('FreqListB', ReprName='Frequency list, before time', \
                   T=0x19, V='\0\0'),
         Type3_TV('ChanDesc_3', ReprName='1st channel description, '
                  'before time', T=0x1C, V=ChanDesc(), Len=3),
         Type3_TV('ChanDesc2B', ReprName='2nd channel description, ' \
                  'before time', T=0x1D, V='\0\0\0', Len=3),
         Type3_TV('FreqChanSeq', ReprName='Frequency channel sequence', \
                  T=0x1E, V=9*'\0', Len=9),
         Type4_TLV('MobAlloc', ReprName='Mobile allocation, before time', \
                   T=0x21, V=MobAlloc()),
         Type2('CiphMod', ReprName='Cipher mode setting', T=0x09),
         Type4_TLV('VGCSind', ReprName='VGCS target mode indication', \
                   T=0x01, V='\0'),
         Type4_TLV('MRconf', ReprName='Multi-rate config', \
                   T=0x03, V='\0\0'),
         Type4_TLV('VGCSciph', ReprName='VGCS ciphering parameters', \
                   T=0x04, V='\0')])
     self._post_init(with_options, **kwargs)
Exemplo n.º 2
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Str('BCCHFreq', ReprName='Neighbour Cell Description', \
             Pt=BCCHFreq(), Len=16), # 44018, 10.5.2.22, in L3GSM_IE.py
         Bit('NCCPerm', ReprName='NCC Permitted', Pt=255, BitLen=8, \
             Repr='bin'), # 44018, 10.5.2.27
         Str('RACHCtrl', ReprName='RACH Control Parameters', Pt=RACHCtrl(),\
             Len=3)]) # 44018, 10.5.2.29, in L3GSM_IE.py
     self._post_init(with_options, **kwargs)
     self.len.Pt = 22
Exemplo n.º 3
0
class MAC_BlockAckReq(MAC):
    constructorList = [
        FrameCtrl(Type=1, Subtype=8),
        Int('Duration', Pt=0, Type='uint16'),
        Str('RA', Pt=6*'\0', Len=6, Repr='hex'),
        Str('TA', Pt=6*'\0', Len=6, Repr='hex'),
        Bit('Reserved', Pt=0, BitLen=12),
        Bit('TID', Pt=0, BitLen=4),
        Bit('FragNum', Pt=0, BitLen=4),
        Bit('StartSeqNum', Pt=0, BitLen=12),
        Int('FCS', Pt=0, Type='uint32', Repr='hex')
        ]
Exemplo n.º 4
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Bit('CKSN', ReprName='Ciphering Key Sequence Number', \
             Pt=0, BitLen=4, Dict=CKSN_dict, Repr='hum'),
         Bit('LUType', ReprName='Location Update Type', \
             Pt=0, BitLen=4, Dict=LUType_dict, Repr='hum'),
         Str('LAI', Pt=LAI(), Len=5),
         Str('MSCm1', Pt=MSCm1(), Len=1),
         Type4_LV('ID', V=ID()),
         Type4_TLV('MSCm2', T=0x33, V=MSCm2())])
     self._post_init(with_options, **kwargs)
Exemplo n.º 5
0
class SCTP_raw(SCTP_chunk):
    constructorList = [
        Str(CallName='val', ReprName='Parameter Value'),
        Str(CallName='pad', ReprName='Padding', Repr='hex'),
    ]
    padding_byte = '\0'

    def __init__(self, val=''):
        Layer.__init__(self, CallName='raw', ReprName='SCTP raw data')
        self.val.Pt = val
        self.pad.Pt = self.val
        self.pad.PtFunc = lambda val: self._pad(s=val)
        self.pad.Len = self.val
        self.pad.LenFunc = lambda val: len(val) % 4
Exemplo n.º 6
0
class MAC_MGT(MAC):
    constructorList = [
        FrameCtrl(Type=2),
        Int('Duration', Pt=0, Type='uint16'),
        Str('Addr1', Pt=6*'\0', Len=6, Repr='hex'),
        Str('Addr2', Pt=6*'\0', Len=6, Repr='hex'),
        Str('Addr3', Pt=6*'\0', Len=6, Repr='hex'),
        Bit('FragNum', Pt=0, BitLen=4, Repr='hum'), # sequence ctrl
        Bit('SeqNum', Pt=0, BitLen=12, Repr='hum'), # sequence ctrl
        Str('Body', Pt=''),
        Int('FCS', Pt=0, Type='uint32', Repr='hex')
        ]
    def __init__(self, **kwargs):
        MAC.__init__(self, **kwargs)
Exemplo n.º 7
0
class atom(Layer):
    constructorList = [
        Int(CallName='size', Type='uint32'),
        Str(CallName='type', Len=4),
        Str(CallName='data', Pt=''),
    ]

    def __init__(self, type='ftyp', data=''):
        Layer.__init__(self, CallName='atom', ReprName='MPEG4 atom')
        self.type.Pt = type
        self.data.Pt = data
        self.data.Len = self.size
        self.data.LenFunc = lambda size: int(size) - 8
        self.size.Pt = (self.data, self.get_payload)
        self.size.PtFunc = lambda (data, pay): len(data) + len(pay()) + 8
Exemplo n.º 8
0
class MAC(Layer):
    constructorList = [
        FrameCtrl(),
        Int('Duration', Pt=0, Type='uint16'),
        Str('Addr1', Pt=6*'\0', Len=6, Repr='hex'),
        Str('Addr2', Pt=6*'\0', Len=6, Repr='hex'),
        Str('Addr3', Pt=6*'\0', Len=6, Repr='hex'),
        Bit('FragNum', Pt=0, BitLen=4, Repr='hum'), # sequence ctrl
        Bit('SeqNum', Pt=0, BitLen=12, Repr='hum'), # sequence ctrl 
        Str('Addr4', Pt=6*'\0', Len=6, Repr='hex'),
        Int('QoSCtrl', Pt=0, Type='uint16'),
        Str('Body', Pt=''),
        Int('FCS', Pt=0, Type='uint32', Repr='hex')
        ]
    '''
Exemplo n.º 9
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Str('CellID', Pt='\0\0', ReprName='Cell identity', Len=2, \
             Repr='hex'), # 44018, 10.5.1.1
         Str('LAI', ReprName='Location Area Identity', Pt=LAI(), \
             Len=5), # 44018, 10.5.1.3, in L3Mobile_IE.py
         Str('CellOpt', ReprName='Cell Options (BCCH)', Pt=CellOpt(), \
             Len=1), # 44018, 10.5.2.3, in L3GSM_IE.py
         Bit('NCCPerm', ReprName='NCC Permitted', Pt=255, BitLen=8, \
             Repr='bin'), # 44018, 10.5.2.27
         StrRR('SI6RestOctets', Len=7, Repr='hex')]) # 44018, 10.5.2.35a
     #self.len.Pt = 11 # WTF ! RestOctets are 7 and length should be 11 ?
     # anyway, length is in LAPDm, not directly into L3...
     self._post_init(with_options, **kwargs)
Exemplo n.º 10
0
class AT_MAC(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=11, Type="uint8", Dict=SIMAKAAttribute),
        Int(CallName="L", ReprName="Length", Type="uint8"),
        Str(CallName="res", ReprName="Reserved", Pt="\x00\x00", Len=2, Repr="hex"),
        Str(CallName="mac", ReprName="MAC", Repr="hex"),
        ]
    
    def __init__(self, mac=''):
        Layer.__init__(self, CallName='MAC', ReprName='AT_MAC')
        self.mac.Pt = mac
        self.mac.PtFunc = lambda mac: self.pad4( str(mac), const=4 )
        self.mac.Len = self.L
        self.mac.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.mac
        self.L.PtFunc = lambda mac: self.len4( len(mac) + 4 )
Exemplo n.º 11
0
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')
    ]
Exemplo n.º 12
0
class TI_PSD(Layer):
    _byte_aligned = False
    constructorList = [
        Bit('unused', Pt=0, BitLen=3, Repr='bin'),
        Bit('GenProt', ReprName='Generic protocol', Pt=0, BitLen=1,
            Repr='hum', Dict=Bool_dict),
        Bit('BufOF', ReprName='Buffer overflow', Pt=0, BitLen=1,
            Repr='hum', Dict=Bool_dict),
        Bit('Incomp', ReprName='Incomplete packet', Pt=0, BitLen=1,
            Repr='hum', Dict=Bool_dict),
        Bit('Corrinc', ReprName='Correlation used', Pt=0, BitLen=1,
            Repr='hum', Dict=Bool_dict),
        Bit('FCSinc', ReprName='FCS included', Pt=0, BitLen=1,
            Repr='hum', Dict=Bool_dict),
        Int('Pnbr', ReprName='Packet number', Pt=0, Type='uint32'),
        Int('Ts', ReprName='Timestamp', Pt=0, Type='uint64'),
        # Length field seems to depend of SmartRF Packet Sniffer version
        #Int('Length', Pt=0, Type='uint16'),
        Int('Length', Pt=0, Type='uint8'),
        #
        TI_CC(),
        Str('spare', Pt='', Repr='hex')
        ]
    def __init__(self, **kwargs):
        Layer.__init__(self, **kwargs)
        self.Pnbr._endian = 'little'
        self.Ts._endian = 'little'
        self.Length._endian = 'little'
Exemplo n.º 13
0
class NCP(Layer):
    constructorList = [
        Int('Code', Pt=0, Type='uint8', Dict=LCPCode_dict),
        Int('Identifier', Pt=0, Type='uint8'),
        Int('Length', Type='uint16'),
        Str('Data', Pt=''),  #, Repr='hex'),
    ]

    def __init__(self, **kwargs):
        Layer.__init__(self, **kwargs)
        self.Length.Pt = self.Data
        self.Length.PtFunc = lambda d: len(d) + 4
        self.Data.Len = self.Length
        self.Data.LenFunc = lambda l: l() - 4

    def map(self, s='', ipcp=True):
        if s:
            Layer.map(self, s)
            if ipcp:
                data, ipcp_list = self.Data(), []
                while data:
                    ipcp = IPCP()
                    ipcp.map(data)
                    data = data[len(ipcp):]
                    ipcp_list.append(ipcp)
                if ipcp_list:
                    self.Data.Val = None
                    self.Data.Pt = tuple(ipcp_list)
Exemplo n.º 14
0
class DAC(segment):
    constructorList = [
        Int('mark', Pt=0xFF, Type='uint8', Repr='hex'),
        Int('type', Pt=0xCC, Type='uint8', Repr='hum', Dict=Seg_dict),
        Int('len', Pt=0, Type='uint16'),
        Str('pay', Pt='\0\0'),
    ]

    def __init__(self, **kwargs):
        Layer.__init__(self, **kwargs)
        # length automation
        self.pay.Len = self.len
        self.pay.LenFunc = lambda l: l() - 2
        self.len.Pt = self.pay
        self.len.PtFunc = lambda p: len(p) + 2

    def map(self, s=''):
        Layer.map(self, s)
        if len(self.pay) % 2 == 0:
            pay = str(self.pay)
            self.remove(self[-1])
            while len(pay) > 0:
                self.append(DACComponent())
                self[-1].map(pay)
                pay = pay[2:]
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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
Exemplo n.º 17
0
class Eth(Layer):
    constructorList = [
        Str(CallName='dst', ReprName='Destination MAC', Pt='', \
            Len=6, Repr='hex'),
        Str(CallName='src', ReprName='Source MAC', Pt='', \
            Len=6, Repr='hex'),
        Int(CallName='typ', ReprName='Ethertype', Pt=0x0800, \
            Type='uint16', Repr='hex'),
        ]
    
    def __init__(self, src='\0\0\0\0\0\0', dst='\xFF\xFF\xFF\xFF\xFF\xFF'):
        Layer.__init__(self, CallName='eth', ReprName='Ethernet header')
        self.src.Pt = src
        self.dst.Pt = dst
        self.typ.Pt = self.get_payload
        self.typ.PtFunc = lambda pay: binder[type(pay()[0])]
Exemplo n.º 18
0
class l1ctl_h1(Layer):
    constructorList = [
        Int('hsn', Pt=0, Type='uint8'),
        Int('maio', Pt=0, Type='uint8'),
        Int('n', Pt=0, Type='uint8'),
        Str('padding', Pt='\0', Len=1, Repr='hex')] + \
        [Int('ma_%i' % i, Pt=0, Type='uint16') for i in range(64)]
Exemplo n.º 19
0
class l1ctl_pm_req(Layer):
    constructorList = [
        Int('type', Pt=1, Type='uint8'),
        Str('padding', Pt='\0\0\0', Len=3, Repr='hex'),
        Int('band_arfcn_from', Pt=0, Type='uint16'),
        Int('band_arfcn_to', Pt=0, Type='uint16'),
    ]
Exemplo n.º 20
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Type4_LV('Cause', V='\0\x80'),
         Str('CallState', Pt='\0', Len=1, Repr='hex'),
         Type4_TLV('AuxState', T=0x24, V=AuxState())])
     self._post_init(with_options, **kwargs)
Exemplo n.º 21
0
class AT_CHECKCODE(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=134, Type="uint8", Dict=SIMAKAAttribute),
        Int(CallName="L", ReprName="Length", Type="uint8"),
        Str(CallName="res", ReprName="Reserved", Pt="\x00\x00", Len=2, Repr="hex"),
        Str(CallName="ck", ReprName="Checkcode", Repr="hex"),
        ]
    
    def __init__(self, ck=''):
        Layer.__init__(self, CallName='Check', ReprName='AT_CHECKCODE')
        self.ck.Pt = ck
        self.ck.PtFunc = lambda ck: self.pad4( str(ck), const=4 )
        self.ck.Len = self.L
        self.ck.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.ck
        self.L.PtFunc = lambda ck: self.len4( len(ck) + 4 )
Exemplo n.º 22
0
class AT_IV(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=129, Type="uint8", Dict=SIMAKAAttribute),
        Int(CallName="L", ReprName="Length", Type="uint8"),
        Str(CallName="res", ReprName="Reserved", Pt="\x00\x00", Len=2, Repr="hex"),
        Str(CallName="iv", ReprName="IV", Repr="hex"),
        ]
    
    def __init__(self, iv=''):
        Layer.__init__(self, CallName='IV', ReprName='AT_IV')
        self.iv.Pt = iv
        self.iv.PtFunc = lambda iv: self.pad4( str(iv), const=4 )
        self.iv.Len = self.L
        self.iv.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.iv
        self.L.PtFunc = lambda iv: self.len4( len(iv) + 4 )
Exemplo n.º 23
0
class AT_AUTN(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=2, Type="uint8", Dict=SIMAKAAttribute),
        Int(CallName="L", ReprName="Length", Type="uint8"),
        Str(CallName="res", ReprName="Reserved", Pt="\x00\x00", Len=2, Repr="hex"),
        Str(CallName="autn", ReprName="AUTN", Repr="hex"),
        ]
    
    def __init__(self, autn=''):
        Layer.__init__(self, CallName='AUTN', ReprName='AT_AUTN')
        self.autn.Pt = autn
        self.autn.PtFunc = lambda autn: self.pad4( str(autn), const=4 )
        self.autn.Len = self.L
        self.autn.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.autn
        self.L.PtFunc = lambda autn: self.len4( len(autn) + 4 )
Exemplo n.º 24
0
class AT_RAND(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=1, Type="uint8", Dict=SIMAKAAttribute),
        Int(CallName="L", ReprName="Length", Type="uint8"),
        Str(CallName="res", ReprName="Reserved", Pt="\x00\x00", Len=2, Repr="hex"),
        Str(CallName="rand", ReprName="RAND", Repr="hex"),
        ]
    
    def __init__(self, rand=4*'mich'):
        Layer.__init__(self, CallName='RAND', ReprName='AT_RAND')
        self.rand.Pt = rand
        self.rand.PtFunc = lambda rand: self.pad4( str(rand), const=4 )
        self.rand.Len = self.L
        self.rand.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.rand
        self.L.PtFunc = lambda rand: self.len4( len(rand) + 4 )
Exemplo n.º 25
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Str('ExtBCCHFreq', ReprName='Neighbour Cell Description', \
             Pt=ExtBCCHFreq(), Len=16), # 44018, 10.5.2.22, in L3GSM_IE.py
         Str('RACHCtrl', ReprName='RACH Control Parameters', Pt=RACHCtrl(),\
             Len=3), # 44018, 10.5.2.29, in L3GSM_IE.py
         StrRR('SI2bisRestOctets', Len=1, Repr='hex')]) # 10.5.2.33
     self._post_init(with_options, **kwargs)
     #self.len.Pt = 21
     # standard rest octet is 1 byte for SI2bis
     # L2 pseudo header automation
     self.len.Pt = (self.ExtBCCHFreq, self.RACHCtrl)
     self.len.PtFunc = lambda (e, r): len(e)+len(r)+2
     self.SI2bisRestOctets.Len = self.len
     self.SI2bisRestOctets.LenFunc = lambda l: 22-l()
Exemplo n.º 26
0
class AT_NONCE_MT(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=7, Type="uint8", Dict=SIMAKAAttribute),
        Int(CallName="L", ReprName="Length", Type="uint8"),
        Str(CallName="res", ReprName="Reserved", Pt="\x00\x00", Len=2, Repr="hex"),
        Str(CallName="n_mt", ReprName="NONCE_MT", Repr="hex"),
        ]
    
    def __init__(self, n_mt=''):
        Layer.__init__(self, CallName='N_MT', ReprName='AT_NONCE_MT')
        self.n_mt.Pt = n_mt
        self.n_mt.PtFunc = lambda n_mt: self.pad4( str(n_mt), const=4 )
        self.n_mt.Len = self.L
        self.n_mt.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.n_mt
        self.L.PtFunc = lambda n_mt: self.len4( len(n_mt) + 4 )
Exemplo n.º 27
0
class SOF(segment):
    constructorList = [
        Int('mark', Pt=0xFF, Type='uint8', Repr='hex'),
        Int('type', Pt=0xC0, Type='uint8', Repr='hum', Dict=Seg_dict),
        Int('len', Pt=0, Type='uint16'),
        Int('P', ReprName='Sample Precision', Pt=0, Type='uint8'),
        Int('Y', ReprName='Number of lines', Pt=0, Type='uint16'),
        Int('X', ReprName='Number of sample per line', Pt=0, Type='uint16'),
        Int('Nf', ReprName='Number of image components in frame', Pt=0, \
            Type='uint8'),
        Str('components', Pt=''),
        ]

    def __init__(self, **kwargs):
        Layer.__init__(self, **kwargs)
        self.components.Len = self.len
        self.components.LenFunc = lambda l: l() - 8
        self.len.Pt = self.components
        self.len.PtFunc = lambda p: len(p) + 8

    def map(self, s=''):
        Layer.map(self, s)
        if len(self.components) / 3.0 == self.Nf():
            cpn_s = self.components()
            self.remove(self.components)
            while len(cpn_s) > 0:
                self.append(SOFComponent())
                self[-1].map(cpn_s)
                cpn_s = cpn_s[3:]
Exemplo n.º 28
0
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()
Exemplo n.º 29
0
 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)
Exemplo n.º 30
0
 def __init__(self, with_options=True, **kwargs):
     Layer3.__init__(self)
     self.extend([ \
         Str('RES', Pt='\0\0\0\0', Len=4, Repr='hex'),
         Type4_TLV('RESext', T=0x21, V='\0\0\0\0')])
     self.RESext.V.Repr = 'hex'
     self._post_init(with_options, **kwargs)
Exemplo n.º 31
0
 def __repr__(self):
     # for hex representation, revert byte
     # 802.15.4 addresses are actually little endian integers
     if self.Repr == "hex": 
         h = hex(self)
         return '0x%s' % h[-2:] + \
                ''.join([h[-i-2:-i] for i in range(2, len(h), 2)])
     else:
         return Str.__repr__(self)
Exemplo n.º 32
0
 def __call__(self):
     # when length has fixed or known value:
     if self.LenFunc is not None:
         if self.safe:
             assert(type(self.LenFunc(self.Len)) is int)
         l = self.LenFunc(self.Len)
     else:
         l = None
     return Str.__call__(self, l)
Exemplo n.º 33
0
 def __repr__(self):
     if self.Repr == 'hum' \
     and (self.Pt is not None or self.Val is not None):
         return self.decode()
     else:
         return Str.__repr__(self)