Exemplo n.º 1
0
class AT_ENCR_DATA(TLV):
    constructorList = [
        Int(CallName="T", ReprName="Type", Pt=130, 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="encr", ReprName="Encrypted Data", Repr="hex"),
        ]
    
    def __init__(self, encr=''):
        Layer.__init__(self, CallName='ENCR', ReprName='AT_ENCR_DATA')
        self.encr.Pt = encr
        self.encr.PtFunc = lambda encr: self.pad4( str(encr), const=4 )
        self.encr.Len = self.L
        self.encr.LenFunc = lambda L: ( int(L)*4 ) - 4
        self.L.Pt = self.encr
        self.L.PtFunc = lambda encr: self.len4( len(encr) + 4 )
    
    # encryption must use AES-CBC-128 with IV from AT_IV
    # Encrypted Data: contains nested EAP-AKA TLV attributes     # MANAGED AT THE BLOCK LEVEL
    # The length of the Encrypted Data must be a multiple of 16 bytes   # MANAGED AT THE BLOCK LEVEL
    # >>> if needed AT_PADDING is used as the last nested attribute for padding to a 16-bytes multiple.     #  MANAGED AT THE BLOCK LEVEL:
    
    def cipher(self, data, key=4*'mich', iv=4*'mich'):
        if len(key) != 16: print '[WNG]: key must be 16 bytes long'
        if len(iv) != 16: print '[WNG]: iv must be 16 bytes long'
        if len(data) == 0 or len(data) % 16 != 0: print '[WNG]: data must be 16 bytes long and not null'
        return AES.new(key=key, mode=2, IV=iv).encrypt(data)
    
    def uncipher(self, data, key=4*'mich', iv=4*'mich'):
        if len(key) != 16: print '[WNG]: key must be 16 bytes long'
        if len(iv) != 16: print '[WNG]: iv must be 16 bytes long'
        if len(data) == 0 or len(data) % 16 != 0: print '[WNG]: data must be 16 bytes long and not null'
        return AES.new(key=key, mode=2, IV=iv).decrypt(data)
Exemplo n.º 2
0
class pay_Del(Layer):
    constructorList = [
        Int(CallName='Ptype', ReprName="Payload Type", Pt=42, Type='uint8', \
            Dict=PayloadType, Trans=True),
        Int(CallName='np', ReprName='Next Payload', Pt=0, Type='uint8', \
            Dict=PayloadType),
        Str(CallName='res', ReprName='Reserved', Pt='\x00', Len=1, Repr="hex"),
        Int(CallName='len', ReprName='Length', Type='uint16'),
        Int(CallName='pID', ReprName='Protocol ID', Type='uint8', Dict=ProtocolID),
        Int(CallName='SPIs', ReprName='SPI size', Type='uint8'),
        Int(CallName='Snum', ReprName='number of SPIs',Type='uint16'),
        Str(CallName='SPI', Repr="hex"),
        ]

    def __init__(self, pID=1, Snum=1, SPI=''):
        Layer.__init__(self, CallName='Del', ReprName='Delete')
        self.pID.Pt = pID
        self.Snum.Pt = Snum
        self.SPI.Pt = SPI
        self.SPI.Len = (self.SPIs, self.Snum)
        self.SPI.LenFunc = lambda (SPIs, Snum): int(SPIs) * int(Snum)
        self.SPIs.Pt = (self.SPI, self.Snum)
        self.SPIs.PtFunc = lambda (SPI, Snum): len(SPI) * int(Snum)
        self.len.Pt = self.SPI
        self.len.PtFunc = lambda SPI: len(SPI) + 8
Exemplo n.º 3
0
class Param(Layer):
    constructorList = [
        Int(CallName='T', ReprName='Tag', Type='uint16', Dict=Params),
        Int(CallName='L', ReprName='Length', Type='uint16'),
        Str(CallName='V', ReprName='Value'),
        Str(CallName='p', ReprName='Padding', Pt='', Len=0, Repr='hex'),
        ]
    
    padding_byte = '\0'
    
    def __init__(self, T=0, V=''):
        Layer.__init__(self, CallName='Param', \
              ReprName='SIGTRAN common parameter')
        self.T.Pt = T
        # Lots of values are encoded as integer 
        # corresponding with specific enum()
        self.V.Pt = V
        self.V.Len = self.L
        self.V.LenFunc = lambda L: int(L)-4
        self.L.Pt = self.V
        self.L.PtFunc = lambda V: len(V)+4
        self.p.Pt = self.V
        self.p.PtFunc = lambda V: self.__pad(V)
        self.p.Len = self.V
        self.p.LenFunc = lambda V: self.__pad_len(V)
    
    def __pad(self, V):
        return (4-len(V)%4)%4 * self.padding_byte
    
    def __pad_len(self, V):
        return (4-len(V)%4)%4
Exemplo n.º 4
0
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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
class Trans(Layer):
    constructorList = [
        Int(CallName='last', Pt=0, Type='uint8', Dict={0:"last", 3:"more"}),
        Str(CallName='res', ReprName='Reserved', Pt='\x00', Len=1, Repr="hex"),
        Int(CallName='len', ReprName='Length', Type='uint16'),
        Int(CallName='type', ReprName='Transform type', Type='uint8', \
            Dict=TransformType),
        Str(CallName='res2', ReprName='Reserved2', Pt='\x00', Len=1, Repr="hex"),
        Int(CallName='tID', ReprName='Transform ID', Type='uint16'),
        ]

    def __init__(self, type=1, tID=11):
        Layer.__init__(self, CallName='Trans', ReprName='Transform')
        self.type.Pt = type
        self.tID.Pt = tID
        self.tID.Dict = TransformID[int(self.type)]
        self.len.Pt = self.get_payload
        self.len.PtFunc = lambda pay: len(pay()) + 8

    # really dirty way to manage pseudo-dynamically the tID dictionnary,
    # depending on the type of transformation...
    def __repr__(self):
        self.tID.Dict = TransformID[int(self.type)]
        return Layer.__repr__(self)

    def show(self, with_trans=False):
        self.tID.Dict = TransformID[int(self.type)]
        return Layer.show(self, with_trans)

    def map(self, string=''):
        Layer.map(self, string)
        self.tID.Dict = TransformID[int(self.type)]
Exemplo n.º 7
0
class TS(Layer):
    constructorList = [
        Int(CallName='TSt', ReprName='TS Type', Type='uint8', Dict=TSType),
        Int(CallName='IPpID',
            ReprName='IP protocol ID',
            Type='uint8',
            Dict=IP_prot),
        Int(CallName='Slen', ReprName='Selector Length', Type='uint16'),
        Int(CallName='sp', ReprName='Start Port', Type='uint16'),
        Int(CallName='ep', ReprName='End Port', Type='uint16'),
        Str(CallName='sa', ReprName='Start Address'),
        Str(CallName='ea', ReprName='End Address'),
    ]

    def __init__(self, TSt=7, IPpID=0, sp=0, ep=65535, sa=None, ea=None):
        Layer.__init__(self, CallName='TS', ReprName='Traffic Selector')
        self.TSt.Pt = TSt
        self.IPpID.Pt = IPpID
        self.sp.Pt = sp
        self.ep.Pt = ep
        self.sa.Pt = sa
        self.sa.Len = self.Slen
        self.sa.LenFunc = lambda Slen: (int(Slen) - 8) / 2
        self.ea.Pt = ea
        self.ea.Len = self.Slen
        self.ea.LenFunc = lambda Slen: (int(Slen) - 8) / 2
        self.Slen.Pt = (self.sa, self.ea)
        self.Slen.PtFunc = lambda (sa, ea): len(sa) + len(ea) + 8

    # represent the address in a nice IPv4 format, if possible
    def __repr__(self):
        if len(self.sa) == 4: self.sa.Repr = 'ipv4'
        if len(self.ea) == 4: self.ea.Repr = 'ipv4'
        return Layer.__repr__(self)
Exemplo n.º 8
0
 def map(self, s=''):
     if not s:
         return
     # check the security header
     s0 = ord(s[0])
     sh, pd = s0>>4, s0&0xF
     # ESM, or EMM with no security header
     if pd == 2 or sh in (0, 12):
         self.__init__(with_security=False)
         Layer3.map(self, s)
         self._map_eps_id()
     # EMM with security header
     elif pd == 7 and sh in (1, 2, 3, 4):
         self.ins_sec_hdr()
         # if no ciphering applied
         if sh in (1, 3): 
         #if sh in (1, 3) or self.EEA not in (EEA1, EEA2, EEA3):
             # if no payload is already there, just add a ciphered-like one
             if len(self.elementList) == 4:
                 self << Str('_enc')
             # map directly the buffer onto the NAS payload
             Layer3.map(self, s)
             self._map_eps_id()
         else:
             # keep track of all IE of the original packet
             self._pay = self[4:]
             # replace them with a dummy string
             for ie in self._pay:
                 self.remove(ie)
             self << Str('_enc')
             Layer3.map(self, s)
     else:
         log(ERR, '[ERR] invalid Security Header value %i' % sh)
Exemplo n.º 9
0
class pay_Not(Layer):
    constructorList = [
        Int(CallName='Ptype', ReprName="Payload Type", Pt=41, Type='uint8', \
            Dict=PayloadType, Trans=True),
        Int(CallName='np', ReprName='Next Payload', Pt=0, Type='uint8', \
            Dict=PayloadType),
        Str(CallName='res', ReprName='Reserved', Pt='\x00', Len=1, Repr="hex"),
        Int(CallName='len', ReprName='Length', Type='uint16'),
        Int(CallName='pID', ReprName='Protocol ID', Type='uint8', Dict=ProtocolID),
        Int(CallName='SPIs', ReprName='SPI size', Type='uint8'),
        Int(CallName='nott', ReprName='Notify Type', Type='uint16', Dict=NotifyType),
        Str(CallName='SPI', Repr="hex"),
        Str(CallName='notm', ReprName='Notify Message'),
        ]

    def __init__(self, pID=1, nott=0, SPI='', notm=None):
        Layer.__init__(self, CallName='Not', ReprName='Notify')
        self.pID.Pt = pID
        self.nott.Pt = nott
        self.SPI.Pt = SPI
        self.SPI.Len = self.SPIs
        self.SPI.LenFunc = lambda SPIs: int(SPIs)
        self.notm.Pt = notm
        self.notm.Len = (self.len, self.SPIs)
        self.notm.LenFunc = lambda (len, SPIs): int(len) - int(SPIs) - 8
        self.SPIs.Pt = self.SPI
        self.SPIs.PtFunc = lambda SPI: len(SPI)
        self.len.Pt = (self.SPI, self.notm)
        self.len.PtFunc = lambda (SPI, notm): len(SPI) + len(notm) + 8
Exemplo n.º 10
0
class MAC_CFEndCFAck(MAC):
    constructorList = [
        FrameCtrl(Type=1, Subtype=15),
        Int('Duration', Pt=0, Type='uint16'),
        Str('RA', Pt=6*'\0', Len=6, Repr='hex'),
        Str('BSSID', Pt=6*'\0', Len=6, Repr='hex'),
        Int('FCS', Pt=0, Type='uint32', Repr='hex')
        ]
Exemplo n.º 11
0
class MAC_PSPoll(MAC):
    constructorList = [
        FrameCtrl(Type=1, Subtype=10),
        Int('AID', Pt=0, Type='uint16'),
        Str('BSSID', Pt=6*'\0', Len=6, Repr='hex'),
        Str('TA', Pt=6*'\0', Len=6, Repr='hex'),
        Int('FCS', Pt=0, Type='uint32', Repr='hex')
        ]
Exemplo n.º 12
0
class MAC_RTS(MAC):
    constructorList = [
        FrameCtrl(Type=1, Subtype=11),
        Int('Duration', Pt=0, Type='uint16'),
        Str('RA', Pt=6*'\0', Len=6, Repr='hex'),
        Str('TA', Pt=6*'\0', Len=6, Repr='hex'),
        Int('FCS', Pt=0, Type='uint32', Repr='hex')
        ]
Exemplo n.º 13
0
class e_ident(Layer):
    constructorList = [
        Str('EI_MAG', Pt='\x7FELF', Len=4, Repr='hum'),
        Int('EI_CLASS', Pt=1, Type='uint8', Dict=ei_class_dict),
        Int('EI_DATA', Pt=1, Type='uint8', Dict=ei_data_dict),
        Int('EI_VERSION', Pt=1, Type='uint8', Dict=e_version_dict),
        Int('EI_OSABI', Pt=0, Type='uint8', Dict=ei_osabi_dict),
        Int('EI_OSABIVERSION', Pt=0, Type='uint8'),
        Str('EI_PAD', Pt='\0\0\0\0\0\0\0', Len=6, Repr='hex'),
        Int('EI_NIDENT', Pt=0, Type='uint8')
    ]
Exemplo n.º 14
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.º 15
0
class PHY(Layer):
    constructorList = [
        Str('Preamble', Pt='\0\0\0\0', Len=4, Repr='hex'),
        Str('SFD', Pt='\xA7', Len=1, Repr='hex'),
        Bit('Res', Pt=0, BitLen=1),
        Bit('Length', BitLen=7, Repr='hum')]
    
    def __init__(self, **kwargs):
        Layer.__init__(self, **kwargs)
        self.Length.Pt = self.get_payload
        self.Length.PtFunc = lambda pay: len(pay())
Exemplo n.º 16
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.º 17
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.º 18
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.º 19
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.º 20
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.º 21
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.º 22
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.º 23
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.º 24
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.º 25
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.º 26
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.º 27
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.º 28
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.º 29
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.º 30
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:]