diff options
author | 2016-03-21 16:03:47 +0200 | |
---|---|---|
committer | 2016-03-21 16:03:47 +0200 | |
commit | b89efa188810bf95a9d245e69e2961b5721c3b0f (patch) | |
tree | 454273ac6c4ae972ebb8a2c86b893296970b4fa9 /scripts/external_libs/scapy-python3-0.18/scapy/contrib | |
parent | f72c6df9d2e9998ae1f3529d729ab7930b35785a (diff) |
scapy python 2/3
Diffstat (limited to 'scripts/external_libs/scapy-python3-0.18/scapy/contrib')
27 files changed, 0 insertions, 18791 deletions
diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/__init__.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/__init__.py deleted file mode 100644 index 99654377..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -## This file is part of Scapy -## See http://www.secdev.org/projects/scapy for more informations -## Copyright (C) Philippe Biondi <phil@secdev.org> -## This program is published under a GPLv2 license - -""" -Package of contrib modules that have to be loaded explicitly. -""" diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/avs.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/avs.py deleted file mode 100644 index 461b94b8..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/avs.py +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env python - -# http://trac.secdev.org/scapy/ticket/82 - -# scapy.contrib.description = AVS WLAN Monitor Header -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.dot11 import * - -AVSWLANPhyType = { 0 : "Unknown", - 1 : "FHSS 802.11 '97", - 2 : "DSSS 802.11 '97", - 3 : "IR Baseband", - 4 : "DSSS 802.11b", - 5 : "PBCC 802.11b", - 6 : "OFDM 802.11g", - 7 : "PBCC 802.11g", - 8 : "OFDM 802.11a" } - -AVSWLANEncodingType = { 0 : "Unknown", - 1 : "CCK", - 2 : "PBCC", - 3 : "OFDM"} - -AVSWLANSSIType = { 0 : "None", - 1 : "Normalized RSSI", - 2 : "dBm", - 3 : "Raw RSSI"} - -AVSWLANPreambleType = { 0 : "Unknown", - 1 : "Short", - 2 : "Long" } - - -class AVSWLANHeader(Packet): - """ iwpriv eth1 set_prismhdr 1 """ - name = "AVS WLAN Monitor Header" - fields_desc = [ IntField("version",1), - IntField("len",64), - LongField("mactime",0), - LongField("hosttime",0), - IntEnumField("phytype",0, AVSWLANPhyType), - IntField("channel",0), - IntField("datarate",0), - IntField("antenna",0), - IntField("priority",0), - IntEnumField("ssi_type",0, AVSWLANSSIType), - SignedIntField("ssi_signal",0), - SignedIntField("ssi_noise",0), - IntEnumField("preamble",0, AVSWLANPreambleType), - IntEnumField("encoding",0, AVSWLANEncodingType), - ] - -bind_layers(AVSWLANHeader, Dot11) - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/bgp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/bgp.py deleted file mode 100644 index 525dac5f..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/bgp.py +++ /dev/null @@ -1,168 +0,0 @@ -#! /usr/bin/env python - -# http://trac.secdev.org/scapy/ticket/162 - -# scapy.contrib.description = BGP -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet import TCP - - -class BGPIPField(Field): - """Represents how bgp dose an ip prefix in (length, prefix)""" - def mask2iplen(self,mask): - """turn the mask into the length in bytes of the ip field""" - return (mask + 7) // 8 - def h2i(self, pkt, h): - """human x.x.x.x/y to internal""" - ip,mask = re.split( '/', h) - return int(mask), ip - def i2h( self, pkt, i): - mask, ip = i - return ip + '/' + str( mask ) - def i2repr( self, pkt, i): - """make it look nice""" - return self.i2h(pkt,i) - def i2len(self, pkt, i): - """rely on integer division""" - mask, ip = i - return self.mask2iplen(mask) + 1 - def i2m(self, pkt, i): - """internal (ip as bytes, mask as int) to machine""" - mask, ip = i - ip = inet_aton( ip ) - return struct.pack(">B",mask) + ip[:self.mask2iplen(mask)] - def addfield(self, pkt, s, val): - return s+self.i2m(pkt, val) - def getfield(self, pkt, s): - l = self.mask2iplen( struct.unpack(">B",s[0])[0] ) + 1 - return s[l:], self.m2i(pkt,s[:l]) - def m2i(self,pkt,m): - mask = struct.unpack(">B",m[0])[0] - ip = "".join( [ m[i + 1] if i < self.mask2iplen(mask) else '\x00' for i in range(4)] ) - return (mask,inet_ntoa(ip)) - -class BGPHeader(Packet): - """The first part of any BGP packet""" - name = "BGP header" - fields_desc = [ - XBitField("marker",0xffffffffffffffffffffffffffffffff, 0x80 ), - ShortField("len", None), - ByteEnumField("type", 4, {0:"none", 1:"open",2:"update",3:"notification",4:"keep_alive"}), - ] - def post_build(self, p, pay): - if self.len is None and pay: - l = len(p) + len(pay) - p = p[:16]+struct.pack("!H", l)+p[18:] - return p+pay - -class BGPOptionalParameter(Packet): - """Format of optional Parameter for BGP Open""" - name = "BGP Optional Parameters" - fields_desc = [ - ByteField("type", 2), - ByteField("len", None), - StrLenField("value", "", length_from = lambda x: x.len), - ] - def post_build(self,p,pay): - if self.len is None: - l = len(p) - 2 # 2 is length without value - p = p[:1]+struct.pack("!B", l)+p[2:] - return p+pay - def extract_padding(self, p): - """any thing after this packet is extracted is padding""" - return "",p - -class BGPOpen(Packet): - """ Opens a new BGP session""" - name = "BGP Open Header" - fields_desc = [ - ByteField("version", 4), - ShortField("AS", 0), - ShortField("hold_time", 0), - IPField("bgp_id","0.0.0.0"), - ByteField("opt_parm_len", None), - PacketListField("opt_parm",[], BGPOptionalParameter, length_from=lambda p:p.opt_parm_len), - ] - def post_build(self, p, pay): - if self.opt_parm_len is None: - l = len(p) - 10 # 10 is regular length with no additional options - p = p[:9] + struct.pack("!B",l) +p[10:] - return p+pay - -class BGPAuthenticationData(Packet): - name = "BGP Authentication Data" - fields_desc = [ - ByteField("AuthenticationCode", 0), - ByteField("FormMeaning", 0), - FieldLenField("Algorithm", 0), - ] - -class BGPPathAttribute(Packet): - "the attribute of total path" - name = "BGP Attribute fields" - fields_desc = [ - FlagsField("flags", 0x40, 8, ["NA0","NA1","NA2","NA3","Extended-Length","Partial","Transitive","Optional"]), #Extened leght may not work - ByteEnumField("type", 1, {1:"ORIGIN", 2:"AS_PATH", 3:"NEXT_HOP", 4:"MULTI_EXIT_DISC", 5:"LOCAL_PREF", 6:"ATOMIC_AGGREGATE", 7:"AGGREGATOR"}), - ByteField("attr_len", None), - StrLenField("value", "", length_from = lambda p: p.attr_len), - ] - def post_build(self, p, pay): - if self.attr_len is None: - l = len(p) - 3 # 3 is regular length with no additional options - p = p[:2] + struct.pack("!B",l) +p[3:] - return p+pay - def extract_padding(self, p): - """any thing after this packet is extracted is padding""" - return "",p - -class BGPUpdate(Packet): - """Update the routes WithdrawnRoutes = UnfeasiableRoutes""" - name = "BGP Update fields" - fields_desc = [ - ShortField("withdrawn_len", None), - FieldListField("withdrawn",[], BGPIPField("","0.0.0.0/0"), length_from=lambda p:p.withdrawn_len), - ShortField("tp_len", None), - PacketListField("total_path", [], BGPPathAttribute, length_from = lambda p: p.tp_len), - FieldListField("nlri",[], BGPIPField("","0.0.0.0/0"), length_from=lambda p:p.underlayer.len - 23 - p.tp_len - p.withdrawn_len), # len should be BGPHeader.len - ] - def post_build(self,p,pay): - wl = self.withdrawn_len - subpacklen = lambda p: len ( str( p )) - subfieldlen = lambda p: BGPIPField("", "0.0.0.0/0").i2len(self, p ) - if wl is None: - wl = sum ( map ( subfieldlen , self.withdrawn)) - p = p[:0]+struct.pack("!H", wl)+p[2:] - if self.tp_len is None: - l = sum ( map ( subpacklen , self.total_path)) - p = p[:2+wl]+struct.pack("!H", l)+p[4+wl:] - return p+pay - -class BGPNotification(Packet): - name = "BGP Notification fields" - fields_desc = [ - ByteEnumField("ErrorCode",0,{1:"Message Header Error",2:"OPEN Message Error",3:"UPDATE Messsage Error",4:"Hold Timer Expired",5:"Finite State Machine",6:"Cease"}), - ByteEnumField("ErrorSubCode",0,{1:"MessageHeader",2:"OPENMessage",3:"UPDATEMessage"}), - LongField("Data", 0), - ] - -class BGPErrorSubcodes(Packet): - name = "BGP Error Subcodes" - Fields_desc = [ - ByteEnumField("MessageHeader",0,{1:"Connection Not Synchronized",2:"Bad Message Length",3:"Bad Messsage Type"}), - ByteEnumField("OPENMessage",0,{1:"Unsupported Version Number",2:"Bad Peer AS",3:"Bad BGP Identifier",4:"Unsupported Optional Parameter",5:"Authentication Failure",6:"Unacceptable Hold Time"}), - ByteEnumField("UPDATEMessage",0,{1:"Malformed Attribute List",2:"Unrecognized Well-Known Attribute",3:"Missing Well-Known Attribute",4:"Attribute Flags Error",5:"Attribute Length Error",6:"Invalid ORIGIN Attribute",7:"AS Routing Loop",8:"Invalid NEXT_HOP Attribute",9:"Optional Attribute Error",10:"Invalid Network Field",11:"Malformed AS_PATH"}), - ] - -bind_layers( TCP, BGPHeader, dport=179) -bind_layers( TCP, BGPHeader, sport=179) -bind_layers( BGPHeader, BGPOpen, type=1) -bind_layers( BGPHeader, BGPUpdate, type=2) -bind_layers( BGPHeader, BGPHeader, type=4) - - -if __name__ == "__main__": - interact(mydict=globals(), mybanner="BGP addon .05") - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/carp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/carp.py deleted file mode 100644 index e785adef..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/carp.py +++ /dev/null @@ -1,65 +0,0 @@ - -# scapy.contrib.description = CARP -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.layers.inet import IP -from scapy.fields import BitField, ByteField, XShortField, IntField, XIntField -from scapy.utils import checksum -import struct, hmac, hashlib - -class CARP(Packet): - name = "CARP" - fields_desc = [ BitField("version", 4, 4), - BitField("type", 4, 4), - ByteField("vhid", 1), - ByteField("advskew", 0), - ByteField("authlen", 0), - ByteField("demotion", 0), - ByteField("advbase", 0), - XShortField("chksum", 0), - XIntField("counter1", 0), - XIntField("counter2", 0), - XIntField("hmac1", 0), - XIntField("hmac2", 0), - XIntField("hmac3", 0), - XIntField("hmac4", 0), - XIntField("hmac5", 0) - ] - - def post_build(self, pkt, pay): - if self.chksum == None: - pkt = pkt[:6] + struct.pack("!H", checksum(pkt)) + pkt[8:] - - return pkt - -def build_hmac_sha1(pkt, pw = '\0' * 20, ip4l = [], ip6l = []): - if not pkt.haslayer(CARP): - return None - - p = pkt[CARP] - h = hmac.new(pw, digestmod = hashlib.sha1) - # XXX: this is a dirty hack. it needs to pack version and type into a single 8bit field - h.update('\x21') - # XXX: mac addy if different from special link layer. comes before vhid - h.update(struct.pack('!B', p.vhid)) - - sl = [] - for i in ip4l: - # sort ips from smallest to largest - sl.append(inet_aton(i)) - sl.sort() - - for i in sl: - h.update(i) - - # XXX: do ip6l sorting - - return h.digest() - -""" -XXX: Usually CARP is multicast to 224.0.0.18 but because of virtual setup, it'll -be unicast between nodes. Uncomment the following line for normal use -bind_layers(IP, CARP, proto=112, dst='224.0.0.18') -""" -bind_layers(IP, CARP, proto=112) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/cdp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/cdp.py deleted file mode 100644 index ed336162..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/cdp.py +++ /dev/null @@ -1,306 +0,0 @@ -#! /usr/bin/env python - -# scapy.contrib.description = Cisco Discovery Protocol -# scapy.contrib.status = loads - -############################################################################# -## ## -## cdp.py --- Cisco Discovery Protocol (CDP) extension for Scapy ## -## ## -## Copyright (C) 2006 Nicolas Bareil <nicolas.bareil AT eads DOT net> ## -## Arnaud Ebalard <arnaud.ebalard AT eads DOT net> ## -## EADS/CRC security team ## -## ## -## This program is free software; you can redistribute it and/or modify it ## -## under the terms of the GNU General Public License version 2 as ## -## published by the Free Software Foundation; version 2. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of ## -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## -## General Public License for more details. ## -## ## -############################################################################# - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet6 import * - - -##################################################################### -# Helpers and constants -##################################################################### - -# CDP TLV classes keyed by type -_cdp_tlv_cls = { 0x0001: "CDPMsgDeviceID", - 0x0002: "CDPMsgAddr", - 0x0003: "CDPMsgPortID", - 0x0004: "CDPMsgCapabilities", - 0x0005: "CDPMsgSoftwareVersion", - 0x0006: "CDPMsgPlatform", - 0x0007: "CDPMsgIPPrefix", - 0x0008: "CDPMsgProtoHello", - 0x0009: "CDPMsgVTPMgmtDomain", # CDPv2 - 0x000a: "CDPMsgNativeVLAN", # CDPv2 - 0x000b: "CDPMsgDuplex", # -# 0x000c: "CDPMsgGeneric", -# 0x000d: "CDPMsgGeneric", - 0x000e: "CDPMsgVoIPVLANReply", - 0x000f: "CDPMsgVoIPVLANQuery", - 0x0010: "CDPMsgPower", - 0x0011: "CDPMsgMTU", -# 0x0012: "CDPMsgTrustBitmap", -# 0x0013: "CDPMsgUntrustedPortCoS", -# 0x0014: "CDPMsgSystemName", -# 0x0015: "CDPMsgSystemOID", - 0x0016: "CDPMsgMgmtAddr", -# 0x0017: "CDPMsgLocation", - 0x0019: "CDPMsgUnknown19", -# 0x001a: "CDPPowerAvailable" - } - -_cdp_tlv_types = { 0x0001: "Device ID", - 0x0002: "Addresses", - 0x0003: "Port ID", - 0x0004: "Capabilities", - 0x0005: "Software Version", - 0x0006: "Platform", - 0x0007: "IP Prefix", - 0x0008: "Protocol Hello", - 0x0009: "VTP Mangement Domain", # CDPv2 - 0x000a: "Native VLAN", # CDPv2 - 0x000b: "Duplex", # - 0x000c: "CDP Unknown command (send us a pcap file)", - 0x000d: "CDP Unknown command (send us a pcap file)", - 0x000e: "VoIP VLAN Reply", - 0x000f: "VoIP VLAN Query", - 0x0010: "Power", - 0x0011: "MTU", - 0x0012: "Trust Bitmap", - 0x0013: "Untrusted Port CoS", - 0x0014: "System Name", - 0x0015: "System OID", - 0x0016: "Management Address", - 0x0017: "Location", - 0x0018: "CDP Unknown command (send us a pcap file)", - 0x0019: "CDP Unknown command (send us a pcap file)", - 0x001a: "Power Available"} - -def _CDPGuessPayloadClass(p, **kargs): - cls = conf.raw_layer - if len(p) >= 2: - t = struct.unpack("!H", p[:2])[0] - clsname = _cdp_tlv_cls.get(t, "CDPMsgGeneric") - cls = globals()[clsname] - - return cls(p, **kargs) - -class CDPMsgGeneric(Packet): - name = "CDP Generic Message" - fields_desc = [ XShortEnumField("type", None, _cdp_tlv_types), - FieldLenField("len", None, "val", "!H"), - StrLenField("val", "", length_from=lambda x:x.len - 4) ] - - - def guess_payload_class(self, p): - return conf.padding_layer # _CDPGuessPayloadClass - -class CDPMsgDeviceID(CDPMsgGeneric): - name = "Device ID" - type = 0x0001 - -_cdp_addr_record_ptype = {0x01: "NLPID", 0x02: "802.2"} -_cdp_addrrecord_proto_ip = "\xcc" -_cdp_addrrecord_proto_ipv6 = "\xaa\xaa\x03\x00\x00\x00\x86\xdd" - -class CDPAddrRecord(Packet): - name = "CDP Address" - fields_desc = [ ByteEnumField("ptype", 0x01, _cdp_addr_record_ptype), - FieldLenField("plen", None, "proto", "B"), - StrLenField("proto", None, length_from=lambda x:x.plen), - FieldLenField("addrlen", None, length_of=lambda x:x.addr), - StrLenField("addr", None, length_from=lambda x:x.addrlen)] - - def guess_payload_class(self, p): - return conf.padding_layer - -class CDPAddrRecordIPv4(CDPAddrRecord): - name = "CDP Address IPv4" - fields_desc = [ ByteEnumField("ptype", 0x01, _cdp_addr_record_ptype), - FieldLenField("plen", 1, "proto", "B"), - StrLenField("proto", _cdp_addrrecord_proto_ip, length_from=lambda x:x.plen), - ShortField("addrlen", 4), - IPField("addr", "0.0.0.0")] - -class CDPAddrRecordIPv6(CDPAddrRecord): - name = "CDP Address IPv6" - fields_desc = [ ByteEnumField("ptype", 0x02, _cdp_addr_record_ptype), - FieldLenField("plen", 8, "proto", "B"), - StrLenField("proto", _cdp_addrrecord_proto_ipv6, length_from=lambda x:x.plen), - ShortField("addrlen", 16), - IP6Field("addr", "::1")] - -def _CDPGuessAddrRecord(p, **kargs): - cls = conf.raw_layer - if len(p) >= 2: - plen = struct.unpack("B", p[1])[0] - proto = ''.join(struct.unpack("s" * plen, p[2:plen + 2])[0:plen]) - - if proto == _cdp_addrrecord_proto_ip: - clsname = "CDPAddrRecordIPv4" - elif proto == _cdp_addrrecord_proto_ipv6: - clsname = "CDPAddrRecordIPv6" - else: - clsname = "CDPAddrRecord" - - cls = globals()[clsname] - - return cls(p, **kargs) - -class CDPMsgAddr(CDPMsgGeneric): - name = "Addresses" - fields_desc = [ XShortEnumField("type", 0x0002, _cdp_tlv_types), - ShortField("len", None), - FieldLenField("naddr", None, "addr", "!I"), - PacketListField("addr", [], _CDPGuessAddrRecord, count_from=lambda x:x.naddr) ] - - def post_build(self, pkt, pay): - if self.len is None: - l = 8 + len(self.addr) * 9 - pkt = pkt[:2] + struct.pack("!H", l) + pkt[4:] - p = pkt + pay - return p - -class CDPMsgPortID(CDPMsgGeneric): - name = "Port ID" - fields_desc = [ XShortEnumField("type", 0x0003, _cdp_tlv_types), - FieldLenField("len", None, "iface", "!H"), - StrLenField("iface", "Port 1", length_from=lambda x:x.len - 4) ] - - -_cdp_capabilities = [ "Router", - "TransparentBridge", - "SourceRouteBridge", - "Switch", - "Host", - "IGMPCapable", - "Repeater"] + ["Bit%d" % x for x in range(25,0,-1)] - - -class CDPMsgCapabilities(CDPMsgGeneric): - name = "Capabilities" - fields_desc = [ XShortEnumField("type", 0x0004, _cdp_tlv_types), - ShortField("len", 8), - FlagsField("cap", 0, 32, _cdp_capabilities) ] - - -class CDPMsgSoftwareVersion(CDPMsgGeneric): - name = "Software Version" - type = 0x0005 - - -class CDPMsgPlatform(CDPMsgGeneric): - name = "Platform" - type = 0x0006 - -_cdp_duplex = { 0x00: "Half", 0x01: "Full" } - -# ODR Routing -class CDPMsgIPPrefix(CDPMsgGeneric): - name = "IP Prefix" - type = 0x0007 - fields_desc = [ XShortEnumField("type", 0x0007, _cdp_tlv_types), - ShortField("len", 8), - IPField("defaultgw", "192.168.0.1") ] - -# TODO : Do me !!!!!! 0x0008 -class CDPMsgProtoHello(CDPMsgGeneric): - name = "Protocol Hello" - type = 0x0008 - -class CDPMsgVTPMgmtDomain(CDPMsgGeneric): - name = "VTP Management Domain" - type = 0x0009 - -class CDPMsgNativeVLAN(CDPMsgGeneric): - name = "Native VLAN" - fields_desc = [ XShortEnumField("type", 0x000a, _cdp_tlv_types), - ShortField("len", 6), - ShortField("vlan", 1) ] - -class CDPMsgDuplex(CDPMsgGeneric): - name = "Duplex" - fields_desc = [ XShortEnumField("type", 0x000b, _cdp_tlv_types), - ShortField("len", 5), - ByteEnumField("duplex", 0x00, _cdp_duplex) ] - -class CDPMsgVoIPVLANReply(CDPMsgGeneric): - name = "VoIP VLAN Reply" - fields_desc = [ XShortEnumField("type", 0x000e, _cdp_tlv_types), - ShortField("len", 7), - ByteField("status?", 1), - ShortField("vlan", 1)] - - -# TODO : Do me !!! 0x000F -class CDPMsgVoIPVLANQuery(CDPMsgGeneric): - name = "VoIP VLAN Query" - type = 0x000f - -# fields_desc = [XShortEnumField("type", 0x000f, _cdp_tlv_types), -# FieldLenField("len", None, "val", "!H") ] - - -class _CDPPowerField(ShortField): - def i2repr(self, pkt, x): - if x is None: - x = 0 - return "%d mW" % x - - -class CDPMsgPower(CDPMsgGeneric): - name = "Power" - # Check if field length is fixed (2 bytes) - fields_desc = [ XShortEnumField("type", 0x0010, _cdp_tlv_types), - ShortField("len", 6), - _CDPPowerField("power", 1337)] - - -class CDPMsgMTU(CDPMsgGeneric): - name = "MTU" - # Check if field length is fixed (2 bytes) - fields_desc = [ XShortEnumField("type", 0x0011, _cdp_tlv_types), - ShortField("len", 6), - ShortField("mtu", 1500)] - -class CDPMsgMgmtAddr(CDPMsgAddr): - name = "Management Address" - type = 0x0016 - -class CDPMsgUnknown19(CDPMsgGeneric): - name = "Unknown CDP Message" - type = 0x0019 - -class CDPMsg(CDPMsgGeneric): - name = "CDP " - fields_desc = [ XShortEnumField("type", None, _cdp_tlv_types), - FieldLenField("len", None, "val", "!H"), - StrLenField("val", "", length_from=lambda x:x.len - 4) ] - -class _CDPChecksum: - def post_build(self, pkt, pay): - p = pkt + pay - if self.cksum is None: - cksum = checksum(p) - p = p[:2] + struct.pack("!H", cksum) + p[4:] - return p - -class CDPv2_HDR(_CDPChecksum, CDPMsgGeneric): - name = "Cisco Discovery Protocol version 2" - fields_desc = [ ByteField("vers", 2), - ByteField("ttl", 180), - XShortField("cksum", None), - PacketListField("msg", [], _CDPGuessPayloadClass) ] - -bind_layers(SNAP, CDPv2_HDR, {"code": 0x2000, "OUI": 0xC}) - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/chdlc.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/chdlc.py deleted file mode 100644 index 6e483762..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/chdlc.py +++ /dev/null @@ -1,42 +0,0 @@ -# http://trac.secdev.org/scapy/ticket/88 - -# scapy.contrib.description = Cisco HDLC and SLARP -# scapy.contrib.status = loads - -# This layer is based on information from http://www.nethelp.no/net/cisco-hdlc.txt - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.l2 import * -from scapy.layers.inet import * -from scapy.layers.inet6 import * - -class CHDLC(Packet): - name = "Cisco HDLC" - fields_desc = [ ByteEnumField("address", 0x0f, {0x0f : "unicast", 0x8f :"multicast"}), - ByteField("control", 0), - XShortField("proto", 0x0800)] - -class SLARP(Packet): - name = "SLARP" - fields_desc = [ IntEnumField("type", 2, {0 : "request", 1 : "reply", 2 :"line keepalive"}), - ConditionalField(IPField("address", "192.168.0.1"), - lambda pkt : pkt.type == 0 or pkt.type == 1), - ConditionalField(IPField("mask", "255.255.255.0"), - lambda pkt : pkt.type == 0 or pkt.type == 1), - ConditionalField(XShortField("unused", 0), - lambda pkt : pkt.type == 0 or pkt.type == 1), - ConditionalField(IntField("mysequence", 0), - lambda pkt : pkt.type == 2), - ConditionalField(IntField("yoursequence", 0), - lambda pkt : pkt.type == 2), - ConditionalField(XShortField("reliability", 0xffff), - lambda pkt : pkt.type == 2)] - -bind_layers( CHDLC, Dot3, proto=0x6558) -bind_layers( CHDLC, IP, proto=0x800) -bind_layers( CHDLC, IPv6, proto=0x86dd) -bind_layers( CHDLC, SLARP, proto=0x8035) -bind_layers( CHDLC, STP, proto=0x4242) - -conf.l2types.register(104, CHDLC) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/dtp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/dtp.py deleted file mode 100644 index 1907300b..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/dtp.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python - -# scapy.contrib.description = DTP -# scapy.contrib.status = loads - -""" - DTP Scapy Extension - ~~~~~~~~~~~~~~~~~~~ - - :version: 2008-12-22 - :author: Jochen Bartl <lobo@c3a.de> - - :Thanks: - - - TLV code derived from the CDP implementation of scapy. (Thanks to Nicolas Bareil and Arnaud Ebalard) - http://trac.secdev.org/scapy/ticket/18 -""" - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.l2 import SNAP,Dot3,LLC -from scapy.sendrecv import sendp - -class DtpGenericTlv(Packet): - name = "DTP Generic TLV" - fields_desc = [ XShortField("type", 0x0001), - FieldLenField("length", None, length_of=lambda pkt:pkt.value + 4), - StrLenField("value", "", length_from=lambda pkt:pkt.length - 4) - ] - - def guess_payload_class(self, p): - return conf.padding_layer - -class RepeatedTlvListField(PacketListField): - def __init__(self, name, default, cls): - PacketField.__init__(self, name, default, cls) - - def getfield(self, pkt, s): - lst = [] - remain = s - while len(remain) > 0: - p = self.m2i(pkt,remain) - if conf.padding_layer in p: - pad = p[conf.padding_layer] - remain = pad.load - del(pad.underlayer.payload) - else: - remain = "" - lst.append(p) - return remain,lst - - def addfield(self, pkt, s, val): - return s+reduce(str.__add__, map(str, val),"") - -_DTP_TLV_CLS = { - 0x0001 : "DTPDomain", - 0x0002 : "DTPStatus", - 0x0003 : "DTPType", - 0x0004 : "DTPNeighbor" - } - -class DTPDomain(DtpGenericTlv): - name = "DTP Domain" - fields_desc = [ ShortField("type", 1), - FieldLenField("length", None, "domain", adjust=lambda pkt,x:x + 4), - StrLenField("domain", "\x00", length_from=lambda pkt:pkt.length - 4) - ] - -class DTPStatus(DtpGenericTlv): - name = "DTP Status" - fields_desc = [ ShortField("type", 2), - FieldLenField("length", None, "status", adjust=lambda pkt,x:x + 4), - StrLenField("status", "\x03", length_from=lambda pkt:pkt.length - 4) - ] - -class DTPType(DtpGenericTlv): - name = "DTP Type" - fields_desc = [ ShortField("type", 3), - FieldLenField("length", None, "dtptype", adjust=lambda pkt,x:x + 4), - StrLenField("dtptype", "\xa5", length_from=lambda pkt:pkt.length - 4) - ] - -class DTPNeighbor(DtpGenericTlv): - name = "DTP Neighbor" - fields_desc = [ ShortField("type", 4), - #FieldLenField("length", None, "neighbor", adjust=lambda pkt,x:x + 4), - ShortField("len", 10), - MACField("neighbor", None) - ] - -def _DTPGuessPayloadClass(p, **kargs): - cls = conf.raw_layer - if len(p) >= 2: - t = struct.unpack("!H", p[:2])[0] - clsname = _DTP_TLV_CLS.get(t, "DtpGenericTlv") - cls = globals()[clsname] - return cls(p, **kargs) - -class DTP(Packet): - name = "DTP" - fields_desc = [ ByteField("ver", 1), - RepeatedTlvListField("tlvlist", [], _DTPGuessPayloadClass) - ] - -bind_layers(SNAP, DTP, code=0x2004, OUI=0xc) - - -def negotiate_trunk(iface=conf.iface, mymac=str(RandMAC())): - print("Trying to negotiate a trunk on interface %s" % iface) - p = Dot3(src=mymac, dst="01:00:0c:cc:cc:cc")/LLC()/SNAP()/DTP(tlvlist=[DTPDomain(),DTPStatus(),DTPType(),DTPNeighbor(neighbor=mymac)]) - sendp(p) - -if __name__ == "__main__": - from scapy.main import interact - interact(mydict=globals(), mybanner="DTP") diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/eigrp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/eigrp.py deleted file mode 100644 index f304ae68..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/eigrp.py +++ /dev/null @@ -1,488 +0,0 @@ -#!/usr/bin/env python - -# scapy.contrib.description = EIGRP -# scapy.contrib.status = loads - -""" - EIGRP Scapy Extension - ~~~~~~~~~~~~~~~~~~~~~ - - :version: 2009-08-13 - :copyright: 2009 by Jochen Bartl - :e-mail: lobo@c3a.de / jochen.bartl@gmail.com - :license: GPL v2 - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - :TODO - - - Replace TLV code with a more generic solution - * http://trac.secdev.org/scapy/ticket/90 - - Write function for calculating authentication data - - :Known bugs: - - - - - :Thanks: - - - TLV code derived from the CDP implementation of scapy. (Thanks to Nicolas Bareil and Arnaud Ebalard) - http://trac.secdev.org/scapy/ticket/18 - - IOS / EIGRP Version Representation FIX by Dirk Loss -""" - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet import IP -from scapy.layers.inet6 import * - -class EigrpIPField(StrField, IPField): - """ - This is a special field type for handling ip addresses of destination networks in internal and - external route updates. - - EIGRP removes zeros from the host portion of the ip address if the netmask is 8, 16 or 24 bits. - """ - - def __init__(self, name, default, length=None, length_from=None): - StrField.__init__(self, name, default) - self.length_from = length_from - if length is not None: - self.length_from = lambda pkt,length=length: length - - def h2i(self, pkt, x): - return IPField.h2i(self, pkt, x) - - def i2m(self, pkt, x): - x = inet_aton(x) - l = self.length_from(pkt) - - if l <= 8: - return x[:1] - elif l <= 16: - return x[:2] - elif l <= 24: - return x[:3] - else: - return x - - def m2i(self, pkt, x): - l = self.length_from(pkt) - - if l <= 8: - x += "\x00\x00\x00" - elif l <= 16: - x += "\x00\x00" - elif l <= 24: - x += "\x00" - - return inet_ntoa(x) - - def prefixlen_to_bytelen(self, l): - if l <= 8: - l = 1 - elif l <= 16: - l = 2 - elif l <= 24: - l = 3 - else: - l = 4 - - return l - - def i2len(self, pkt, x): - l = self.length_from(pkt) - l = self.prefixlen_to_bytelen(l) - - return l - - def getfield(self, pkt, s): - l = self.length_from(pkt) - l = self.prefixlen_to_bytelen(l) - - return s[l:], self.m2i(pkt, s[:l]) - - def randval(self): - return IPField.randval(self) - -class EigrpIP6Field(StrField, IP6Field, EigrpIPField): - """ - This is a special field type for handling ip addresses of destination networks in internal and - external route updates. - - """ - - def __init__(self, name, default, length=None, length_from=None): - StrField.__init__(self, name, default) - self.length_from = length_from - if length is not None: - self.length_from = lambda pkt,length=length: length - - def any2i(self, pkt, x): - return IP6Field.any2i(self, pkt, x) - - def i2repr(self, pkt, x): - return IP6Field.i2repr(self, pkt, x) - - def h2i(self, pkt, x): - return IP6Field.h2i(self, pkt, x) - - def i2m(self, pkt, x): - x = inet_pton(socket.AF_INET6, x) - l = self.length_from(pkt) - l = self.prefixlen_to_bytelen(l) - - return x[:l] - - def m2i(self, pkt, x): - l = self.length_from(pkt) - - prefixlen = self.prefixlen_to_bytelen(l) - if l > 128: - warning("EigrpIP6Field: Prefix length is > 128. Dissection of this packet will fail") - else: - pad = "\x00" * (16 - prefixlen) - x += pad - - return inet_ntop(socket.AF_INET6, x) - - def prefixlen_to_bytelen(self, l): - l = l / 8 - - if l < 16: - l += 1 - - return l - - def i2len(self, pkt, x): - return EigrpIPField.i2len(self, pkt, x) - - def getfield(self, pkt, s): - return EigrpIPField.getfield(self, pkt, s) - -class ThreeBytesField(X3BytesField, ByteField): - def i2repr(self, pkt, x): - return ByteField.i2repr(self, pkt, x) - - -class EIGRPGeneric(Packet): - name = "EIGRP Generic TLV" - fields_desc = [ XShortField("type", 0x0000), - FieldLenField("len", None, "value", "!H", adjust=lambda pkt,x: x + 4), - StrLenField("value", "\x00", length_from=lambda pkt: pkt.len - 4)] - - def guess_payload_class(self, p): - return conf.padding_layer - -class EIGRPParam(EIGRPGeneric): - name = "EIGRP Parameters" - fields_desc = [ XShortField("type", 0x0001), - ShortField("len", 12), - # Bandwidth - ByteField("k1", 1), - # Load - ByteField("k2", 0), - # Delay - ByteField("k3", 1), - # Reliability - ByteField("k4", 0), - # MTU - ByteField("k5", 0), - ByteField("reserved", 0), - ShortField("holdtime", 15) - ] - -class EIGRPAuthData(EIGRPGeneric): - name = "EIGRP Authentication Data" - fields_desc = [ XShortField("type", 0x0002), - FieldLenField("len", None, "authdata", "!H", adjust=lambda pkt,x: x + 24), - ShortEnumField("authtype", 2, {2 : "MD5"}), - ShortField("keysize", None), - IntField("keyid", 1), - StrFixedLenField("nullpad", "\x00" * 12, 12), - StrLenField("authdata", RandString(16), length_from=lambda pkt: pkt.keysize) - ] - - def post_build(self, p, pay): - p += pay - - if self.keysize is None: - keysize = len(self.authdata) - p = p[:6] + chr((keysize >> 8) & 0xff) + chr(keysize & 0xff) + p[8:] - - return p - -class EIGRPSeq(EIGRPGeneric): - name = "EIGRP Sequence" - fields_desc = [ XShortField("type", 0x0003), - ShortField("len", None), - ByteField("addrlen", 4), - ConditionalField(IPField("ipaddr", "192.168.0.1"), - lambda pkt:pkt.addrlen == 4), - ConditionalField(IP6Field("ip6addr", "2001::"), - lambda pkt:pkt.addrlen == 16) - ] - - def post_build(self, p, pay): - p += pay - - if self.len is None: - l = len(p) - p = p[:2] + chr((l >> 8) & 0xff) + chr(l & 0xff) + p[4:] - - return p - -class ShortVersionField(ShortField): - def i2repr(self, pkt, x): - try: - minor = x & 0xff - major = (x >> 8) & 0xff - except TypeError: - return "unknown" - else: - # We print a leading 'v' so that these values don't look like floats - return "v%s.%s" % (major, minor) - - def h2i(self, pkt, x): - """The field accepts string values like v12.1, v1.1 or integer values. - String values have to start with a "v" folled by a floating point number. - Valid numbers are between 0 and 255. - """ - - if type(x) is str and x.startswith("v") and len(x) <= 8: - major = int(x.split(".")[0][1:]) - minor = int(x.split(".")[1]) - - return (major << 8) | minor - - elif type(x) is int and x >= 0 and x <= 65535: - return x - else: - if self.default != None: - warning("set value to default. Format of %r is invalid" % x) - return self.default - else: - raise Scapy_Exception("Format of value is invalid") - - def randval(self): - return RandShort() - -class EIGRPSwVer(EIGRPGeneric): - name = "EIGRP Software Version" - fields_desc = [ XShortField("type", 0x0004), - ShortField("len", 8), - ShortVersionField("ios", "v12.0"), - ShortVersionField("eigrp", "v1.2") - ] - -class EIGRPNms(EIGRPGeneric): - name = "EIGRP Next Multicast Sequence" - fields_desc = [ XShortField("type", 0x0005), - ShortField("len", 8), - IntField("nms", 2) - ] - -# Don't get confused by the term "receive-only". This flag is always set, when you configure -# one of the stub options. It's also the only flag set, when you configure "eigrp stub receive-only". -_EIGRP_STUB_FLAGS = ["connected", "static", "summary", "receive-only", "redistributed", "leak-map"] - -class EIGRPStub(EIGRPGeneric): - name = "EIGRP Stub Router" - fields_desc = [ XShortField("type", 0x0006), - ShortField("len", 6), - FlagsField("flags", 0x000d, 16, _EIGRP_STUB_FLAGS)] - -# Delay 0xffffffff == Destination Unreachable -class EIGRPIntRoute(EIGRPGeneric): - name = "EIGRP Internal Route" - fields_desc = [ XShortField("type", 0x0102), - FieldLenField("len", None, "dst", "!H", adjust=lambda pkt,x: x + 25), - IPField("nexthop", "192.168.0.0"), - IntField("delay", 128000), - IntField("bandwidth", 256), - ThreeBytesField("mtu", 1500), - ByteField("hopcount", 0), - ByteField("reliability", 255), - ByteField("load", 0), - XShortField("reserved", 0), - ByteField("prefixlen", 24), - EigrpIPField("dst", "192.168.1.0", length_from=lambda pkt: pkt.prefixlen), - ] - -_EIGRP_EXTERNAL_PROTOCOL_ID = { - 0x01 : "IGRP", - 0x02 : "EIGRP", - 0x03 : "Static Route", - 0x04 : "RIP", - 0x05 : "Hello", - 0x06 : "OSPF", - 0x07 : "IS-IS", - 0x08 : "EGP", - 0x09 : "BGP", - 0x0A : "IDRP", - 0x0B : "Connected Link" - } - -_EIGRP_EXTROUTE_FLAGS = ["external", "candidate-default"] - -class EIGRPExtRoute(EIGRPGeneric): - name = "EIGRP External Route" - fields_desc = [ XShortField("type", 0x0103), - FieldLenField("len", None, "dst", "!H", adjust=lambda pkt,x: x + 45), - IPField("nexthop", "192.168.0.0"), - IPField("originrouter", "192.168.0.1"), - IntField("originasn", 0), - IntField("tag", 0), - IntField("externalmetric", 0), - ShortField("reserved", 0), - ByteEnumField("extprotocolid", 3, _EIGRP_EXTERNAL_PROTOCOL_ID), - FlagsField("flags", 0, 8, _EIGRP_EXTROUTE_FLAGS), - IntField("delay", 0), - IntField("bandwidth", 256), - ThreeBytesField("mtu", 1500), - ByteField("hopcount", 0), - ByteField("reliability", 255), - ByteField("load", 0), - XShortField("reserved2", 0), - ByteField("prefixlen", 24), - EigrpIPField("dst", "192.168.1.0", length_from=lambda pkt: pkt.prefixlen) - ] - -class EIGRPv6IntRoute(EIGRPGeneric): - name = "EIGRP for IPv6 Internal Route" - fields_desc = [ XShortField("type", 0x0402), - FieldLenField("len", None, "dst", "!H", adjust=lambda pkt,x: x + 37), - IP6Field("nexthop", "::"), - IntField("delay", 128000), - IntField("bandwidth", 256000), - ThreeBytesField("mtu", 1500), - ByteField("hopcount", 1), - ByteField("reliability", 255), - ByteField("load", 0), - XShortField("reserved", 0), - ByteField("prefixlen", 16), - EigrpIP6Field("dst", "2001::", length_from=lambda pkt: pkt.prefixlen) - ] - -class EIGRPv6ExtRoute(EIGRPGeneric): - name = "EIGRP for IPv6 External Route" - fields_desc = [ XShortField("type", 0x0403), - FieldLenField("len", None, "dst", "!H", adjust=lambda pkt,x: x + 57), - IP6Field("nexthop", "::"), - IPField("originrouter", "192.168.0.1"), - IntField("originasn", 0), - IntField("tag", 0), - IntField("externalmetric", 0), - ShortField("reserved", 0), - ByteEnumField("extprotocolid", 3, _EIGRP_EXTERNAL_PROTOCOL_ID), - FlagsField("flags", 0, 8, _EIGRP_EXTROUTE_FLAGS), - IntField("delay", 0), - IntField("bandwidth", 256000), - ThreeBytesField("mtu", 1500), - ByteField("hopcount", 1), - ByteField("reliability", 0), - ByteField("load", 1), - XShortField("reserved2", 0), - ByteField("prefixlen", 8), - EigrpIP6Field("dst", "::", length_from=lambda pkt: pkt.prefixlen) - ] - -_eigrp_tlv_cls = { - 0x0001: "EIGRPParam", - 0x0002: "EIGRPAuthData", - 0x0003: "EIGRPSeq", - 0x0004: "EIGRPSwVer", - 0x0005: "EIGRPNms", - 0x0006: "EIGRPStub", - 0x0102: "EIGRPIntRoute", - 0x0103: "EIGRPExtRoute", - 0x0402: "EIGRPv6IntRoute", - 0x0403: "EIGRPv6ExtRoute" - } - -class RepeatedTlvListField(PacketListField): - def __init__(self, name, default, cls): - PacketField.__init__(self, name, default, cls) - - def getfield(self, pkt, s): - lst = [] - remain = s - while len(remain) > 0: - p = self.m2i(pkt, remain) - if conf.padding_layer in p: - pad = p[conf.padding_layer] - remain = pad.load - del(pad.underlayer.payload) - else: - remain = "" - lst.append(p) - return remain,lst - - def addfield(self, pkt, s, val): - return s + reduce(str.__add__, map(str, val), "") - -def _EIGRPGuessPayloadClass(p, **kargs): - cls = conf.raw_layer - if len(p) >= 2: - t = struct.unpack("!H", p[:2])[0] - clsname = _eigrp_tlv_cls.get(t, "EIGRPGeneric") - cls = globals()[clsname] - return cls(p, **kargs) - -_EIGRP_OPCODES = { 1 : "Update", - 2 : "Request", - 3 : "Query", - 4 : "Replay", - 5 : "Hello", - 6 : "IPX SAP", - 10 : "SIA Query", - 11 : "SIA Reply" } - -# The Conditional Receive bit is used for reliable multicast communication. -# Update-Flag: Not sure if Cisco calls it that way, but it's set when neighbors -# are exchanging routing information -_EIGRP_FLAGS = ["init", "cond-recv", "unknown", "update"] - -class EIGRP(Packet): - name = "EIGRP" - fields_desc = [ ByteField("ver", 2), - ByteEnumField("opcode", 5, _EIGRP_OPCODES), - XShortField("chksum", None), - FlagsField("flags", 0, 32, _EIGRP_FLAGS), - IntField("seq", 0), - IntField("ack", 0), - IntField("asn", 100), - RepeatedTlvListField("tlvlist", [], _EIGRPGuessPayloadClass) - ] - - def post_build(self, p, pay): - p += pay - if self.chksum is None: - c = checksum(p) - p = p[:2] + chr((c >> 8) & 0xff) + chr(c & 0xff) + p[4:] - return p - - def mysummary(self): - summarystr = "EIGRP (AS=%EIGRP.asn% Opcode=%EIGRP.opcode%" - if self.opcode == 5 and self.ack != 0: - summarystr += " (ACK)" - if self.flags != 0: - summarystr += " Flags=%EIGRP.flags%" - - return self.sprintf(summarystr + ")") - -bind_layers(IP, EIGRP, proto=88) -bind_layers(IPv6, EIGRP, nh=88) - -if __name__ == "__main__": - from scapy.main import interact - interact(mydict=globals(), mybanner="EIGRP") - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/etherip.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/etherip.py deleted file mode 100644 index e331c146..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/etherip.py +++ /dev/null @@ -1,19 +0,0 @@ - -# http://trac.secdev.org/scapy/ticket/297 - -# scapy.contrib.description = EtherIP -# scapy.contrib.status = loads - -from scapy.fields import BitField -from scapy.packet import Packet, bind_layers -from scapy.layers.inet import IP -from scapy.layers.l2 import Ether - -class EtherIP(Packet): - name = "EtherIP / RFC 3378" - fields_desc = [ BitField("version", 3, 4), - BitField("reserved", 0, 12)] - -bind_layers( IP, EtherIP, frag=0, proto=0x61) -bind_layers( EtherIP, Ether) - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/gsm_um.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/gsm_um.py deleted file mode 100644 index 7b1354a4..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/gsm_um.py +++ /dev/null @@ -1,13119 +0,0 @@ -#!/usr/bin/env python - -# scapy.contrib.description = PPI -# scapy.contrib.status = loads - -""" - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -""" - - #################################################################### - # This file holds the GSM UM interface implementation for Scapy # - # author: Laurent Weber <k@0xbadcab1e.lu> # - # # - # Some examples on how to use this script: # - # http://0xbadcab1e.lu/scapy_gsm_um-howto.txt # - # # - # tested on: scapy-version: 2.2.0 (dev) # - #################################################################### - -import logging -from types import IntType -from types import NoneType -from types import StringType -#from time import sleep -import socket -logging.getLogger("scapy").setLevel(1) -from scapy.all import * - -# This method is intended to send gsm air packets. It uses a unix domain -# socket. It opens a socket, sends the parameter to the socket and -# closes the socket. -# typeSock determines the type of the socket, can be: -# 0 for UDP Socket -# 1 for Unix Domain Socket -# 2 for TCP - - -def sendum(x, typeSock=0): - try: - if type(x) is not str: - x = str(x) - if typeSock is 0: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - host = '127.0.0.1' - port = 28670 # default for openBTS - s.connect((host, port)) - elif typeSock is 1: - s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - s.connect("/tmp/osmoL") - elif typeSock is 2: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - host = '127.0.0.1' - port = 43797 - s.connect((host, port)) - s.send(x) - s.close() - except: - print("[Error]: There was a problem when trying to transmit data.\ - Please make sure you started the socket server.") - -# Known Bugs/Problems: -# If a message uses multiple times the same IE you cannot set the values -# of this IE's if you use the preconfigured packets. You need to build -# the IE's by hand and than assemble them as entire messages. - -# The ErrorLength class is a custom exception that gets raised when a -# packet doesn't have the correct size. - - -class ErrorLength(Exception): - def __str__(self): - error = "ERROR: Please make sure you build entire, 8 bit fields." - return repr(error) -### -# This method computes the length of the actual IE. -# It computes how many "None" fields have to be removed (if any). -# The method returns an integer containing the number of bytes that have to be -# cut off the packet. -# parameter length contains the max length of the IE can be found in -# 0408 -# The parameter fields contains the value of the fields (not the default but -# the real, actual value. -# The parameter fields2 contains fields_desc. -# Location contains the location of the length field in the IE. Everything -# after the the length field has to be counted (04.07 11.2.1.1.2) - - -def adapt(min_length, max_length, fields, fields2, location=2): - # find out how much bytes there are between min_length and the location of - # the length field - location = min_length - location - i = len(fields) - 1 - rm = mysum = 0 - while i >= 0: - if fields[i] is None: - rm += 1 - try: - mysum += fields2[i].size - except AttributeError: # ByteFields don't have .size - mysum += 8 - else: - break - i -= 1 - if mysum % 8 is 0: - length = mysum / 8 # Number of bytes we have to delete - dyn_length = (max_length - min_length - length) - if dyn_length < 0: - dyn_length = 0 - if length is max_length: # Fix for packets that have all values set - length -= min_length # to None - return [length, dyn_length + location] - else: - raise ErrorLength() - - -def examples(example=None): - if example == None: - print("""This command presents some example to introduce scapy -gsm-um to new users. -The following parameters can be used: - examples("imsiDetach") - examples("call") - examples("dissect")""") - elif example == "imsiDetach": - print(""" ->>> a=imsiDetachIndication() -... a.typeOfId=1; a.odd=1; a.idDigit1=0xF; -... a.idDigit2_1=2; a.idDigit2=7; a.idDigit3_1=0; -... a.idDigit3=7; a.idDigit4_1=7; a.idDigit4=2; -... a.idDigit5_1=0; a.idDigit5=0; a.idDigit6_1=0; -... a.idDigit6=1; a.idDigit7_1=2; a.idDigit7=7; -... a.idDigit8_1=7; a.idDigit8=5; a.idDigit9_1=1; a.idDigit9=4; ->>> hexdump(a) -0000 05 01 00 08 F0 27 07 72 00 01 27 75 14 .....'.r..'u. ->>> sendum(a) -""") - elif example == "call": - print(""" -If you use an USRP and the testcall function this sets up a phonecall: ->>> sendum(setupMobileOriginated()) ->>> sendum(connectAcknowledge()) -""") - - -# Section 10.2/3 -class TpPd(Packet): - """Skip indicator and transaction identifier and Protocol Discriminator""" - name = "Skip Indicator And Transaction Identifier and Protocol \ -Discriminator" - fields_desc = [ - BitField("ti", 0x0, 4), - BitField("pd", 0x3, 4) - ] - - -class MessageType(Packet): - """Message Type Section 10.4""" - name = "Message Type" - fields_desc = [ - XByteField("mesType", 0x3C) - ] - - -## -# Message for Radio Resources management (RR) Section 9.1 -### - -# Network to MS -def additionalAssignment(MobileAllocation_presence=0, - StartingTime_presence=0): - """ADDITIONAL ASSIGNMENT Section 9.1.1""" - # Mandatory - a = TpPd(pd=0x6) - b = MessageType(mesType=0x3B) # 00111011 - c = ChannelDescription() - packet = a / b / c - # Not Mandatory - if MobileAllocation_presence is 1: - d = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) - packet = packet / d - if StartingTime_presence is 1: - e = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) - packet = packet / e - return packet - - -# Network to MS -def assignmentCommand(FrequencyList_presence=0, - CellChannelDescription_presence=0, - CellChannelDescription_presence1=0, - MultislotAllocation_presence=0, - ChannelMode_presence=0, ChannelMode_presence1=0, - ChannelMode_presence2=0, ChannelMode_presence3=0, - ChannelMode_presence4=0, ChannelMode_presence5=0, - ChannelMode_presence6=0, ChannelMode_presence7=0, - ChannelDescription=0, ChannelMode2_presence=0, - MobileAllocation_presence=0, StartingTime_presence=0, - FrequencyList_presence1=0, - ChannelDescription2_presence=0, - ChannelDescription_presence=0, - FrequencyChannelSequence_presence=0, - MobileAllocation_presence1=0, - CipherModeSetting_presence=0, - VgcsTargetModeIdentication_presence=0, - MultiRateConfiguration_presence=0): - """ASSIGNMENT COMMAND Section 9.1.2""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x2e) # 101110 - c = ChannelDescription2() - d = PowerCommand() - packet = a / b / c / d - if FrequencyList_presence is 1: - e = FrequencyListHdr(ieiFL=0x05, eightBitFL=0x0) - packet = packet / e - if CellChannelDescription_presence is 1: - f = CellChannelDescriptionHdr(ieiCCD=0x62, eightBitCCD=0x0) - packet = packet / f - if MultislotAllocation_presence is 1: - g = MultislotAllocationHdr(ieiMSA=0x10, eightBitMSA=0x0) - packet = packet / g - if ChannelMode_presence is 1: - h = ChannelModeHdr(ieiCM=0x63, eightBitCM=0x0) - packet = packet / h - if ChannelMode_presence1 is 1: - i = ChannelModeHdr(ieiCM=0x11, eightBitCM=0x0) - packet = packet / i - if ChannelMode_presence2 is 1: - j = ChannelModeHdr(ieiCM=0x13, eightBitCM=0x0) - packet = packet / j - if ChannelMode_presence3 is 1: - k = ChannelModeHdr(ieiCM=0x14, eightBitCM=0x0) - packet = packet / k - if ChannelMode_presence4 is 1: - l = ChannelModeHdr(ieiCM=0x15, eightBitCM=0x0) - packet = packet / l - if ChannelMode_presence5 is 1: - m = ChannelModeHdr(ieiCM=0x16, eightBitCM=0x0) - packet = packet / m - if ChannelMode_presence6 is 1: - n = ChannelModeHdr(ieiCM=0x17, eightBitCM=0x0) - packet = packet / n - if ChannelMode_presence7 is 1: - o = ChannelModeHdr(ieiCM=0x18, eightBitCM=0x0) - packet = packet / o - if ChannelDescription_presence is 1: - p = ChannelDescriptionHdr(ieiCD=0x64, eightBitCD=0x0) - packet = packet / p - if ChannelMode2_presence is 1: - q = ChannelMode2Hdr(ieiCM2=0x66, eightBitCM2=0x0) - packet = packet / q - if MobileAllocation_presence is 1: - r = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) - packet = packet / r - if StartingTime_presence is 1: - s = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) - packet = packet / s - if FrequencyList_presence1 is 1: - t = FrequencyListHdr(ieiFL=0x19, eightBitFL=0x0) - packet = packet / t - if ChannelDescription2_presence is 1: - u = ChannelDescription2Hdr(ieiCD2=0x1C, eightBitCD2=0x0) - packet = packet / u - if ChannelDescription_presence is 1: - v = ChannelDescriptionHdr(ieiCD=0x1D, eightBitCD=0x0) - packet = packet / v - if FrequencyChannelSequence_presence is 1: - w = FrequencyChannelSequenceHdr(ieiFCS=0x1E, eightBitFCS=0x0) - packet = packet / w - if MobileAllocation_presence1 is 1: - x = MobileAllocationHdr(ieiMA=0x21, eightBitMA=0x0) - packet = packet / x - if CipherModeSetting_presence is 1: - y = CipherModeSettingHdr(ieiCMS=0x9, eightBitCMS=0x0) - packet = packet / y - if VgcsTargetModeIdentication_presence is 1: - z = VgcsTargetModeIdenticationHdr(ieiVTMI=0x01, eightBitVTMI=0x0) - packet = packet / z - if MultiRateConfiguration_presence is 1: - aa = MultiRateConfigurationHdr(ieiMRC=0x03, eightBitMRC=0x0) - packet = packet / aa - return packet - - -# MS to Network -def assignmentComplete(): - """ASSIGNMENT COMPLETE Section 9.1.3""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x29) # 00101001 - c = RrCause() - packet = a / b / c - return packet - - -# MS to Network -def assignmentFailure(): - """ASSIGNMENT FAILURE Section 9.1.4""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x2F) # 00101111 - c = RrCause() - packet = a / b / c - return packet - - -# Network to MS -def channelModeModify(VgcsTargetModeIdentication_presence=0, - MultiRateConfiguration_presence=0): - """CHANNEL MODE MODIFY Section 9.1.5""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x8) # 0001000 - c = ChannelDescription2() - d = ChannelMode() - packet = a / b / c / d - if VgcsTargetModeIdentication is 1: - e = VgcsTargetModeIdenticationHdr(ieiVTMI=0x01, eightBitVTMI=0x0) - packet = packet / e - if MultiRateConfiguration is 1: - f = MultiRateConfigurationHdr(ieiMRC=0x03, eightBitMRC=0x0) - packet = packet / f - return packet - - -def channelModeModifyAcknowledge(): - """CHANNEL MODE MODIFY ACKNOWLEDGE Section 9.1.6""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x17) # 00010111 - c = ChannelDescription2() - d = ChannelMode() - packet = a / b / c / d - return packet - - -# Network to MS -def channelRelease(BaRange_presence=0, GroupChannelDescription_presence=0, - GroupCipherKeyNumber_presence=0, GprsResumption_presence=0, - BaListPref_presence=0): - """CHANNEL RELEASE Section 9.1.7""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0xD) # 00001101 - c = RrCause() - packet = a / b / c - if BaRange_presence is 1: - d = BaRangeHdr(ieiBR=0x73, eightBitBR=0x0) - packet = packet / d - if GroupChannelDescription_presence is 1: - e = GroupChannelDescriptionHdr(ieiGCD=0x74, eightBitGCD=0x0) - packet = packet / e - if GroupCipherKeyNumber_presence is 1: - f = GroupCipherKeyNumber(ieiGCKN=0x8) - packet = packet / f - if GprsResumption_presence is 1: - g = GprsResumptionHdr(ieiGR=0xC, eightBitGR=0x0) - packet = packet / g - if BaListPref_presence is 1: - h = BaListPrefHdr(ieiBLP=0x75, eightBitBLP=0x0) - packet = packet / h - return packet - - -class ChannelRequest(Packet): - """Channel request Section 9.1.8""" - name = "Channel Request" - fields_desc = [ - ByteField("estCause", 0x0) - ] - - -def channelRequest(): - return ChannelRequest() - - -# Network to MS -def cipheringModeCommand(): - """CIPHERING MODE COMMAND Section 9.1.9""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x35) # 00110101 - c = RrCause() - #d=cipherModeSetting() - #e=cipherResponse() - # FIX - d = CipherModeSettingAndcipherResponse() - packet = a / b / c / d - return packet - - -def cipheringModeComplete(MobileId_presence=0): - """CIPHERING MODE COMPLETE Section 9.1.10""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x32) # 00110010 - packet = a / b - if MobileId_presence is 1: - c = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) - packet = packet / c - return packet - - -# Network to MS -def classmarkChange(MobileStationClassmark3_presence=0): - """CLASSMARK CHANGE Section 9.1.11""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x16) # 00010110 - c = MobileStationClassmark2() - packet = a / b / c - if MobileStationClassmark3_presence is 1: - e = MobileStationClassmark3(ieiMSC3=0x20) - packet = packet / e - return packet - - -# Network to MS -def classmarkEnquiry(): - """CLASSMARK ENQUIRY Section 9.1.12""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x13) # 00010011 - packet = a / b - return packet -# 9.1.12a Spare - - -# Network to MS -def configurationChangeCommand(ChannelMode_presence=0, - ChannelMode_presence1=0, - ChannelMode_presence2=0, - ChannelMode_presence3=0, - ChannelMode_presence4=0, - ChannelMode_presence5=0, - ChannelMode_presence6=0, - ChannelMode_presence7=0): - """CONFIGURATION CHANGE COMMAND Section 9.1.12b""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x30) # 00110000 - c = MultislotAllocation() - packet = a / b / c - if ChannelMode_presence is 1: - d = ChannelModeHdr(ieiCM=0x63, eightBitCM=0x0) - packet = packet / d - if ChannelMode_presence1 is 1: - e = ChannelModeHdr(ieiCM=0x11, eightBitCM=0x0) - packet = packet / e - if ChannelMode_presence2 is 1: - f = ChannelModeHdr(ieiCM=0x13, eightBitCM=0x0) - packet = packet / f - if ChannelMode_presence3 is 1: - g = ChannelModeHdr(ieiCM=0x14, eightBitCM=0x0) - packet = packet / g - if ChannelMode_presence4 is 1: - h = ChannelModeHdr(ieiCM=0x15, eightBitCM=0x0) - packet = packet / h - if ChannelMode_presence5 is 1: - i = ChannelModeHdr(ieiCM=0x16, eightBitCM=0x0) - packet = packet / i - if ChannelMode_presence6 is 1: - j = ChannelModeHdr(ieiCM=0x17, eightBitCM=0x0) - packet = packet / j - if ChannelMode_presence7 is 1: - k = ChannelModeHdr(ieiCM=0x18, eightBitCM=0x0) - packet = packet / k - return packet - - -def configurationChangeAcknowledge(): - """CONFIGURATION CHANGE ACKNOWLEDGE Section 9.1.12c""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x31) # 00110001 - c = MobileId() - packet = a / b / c - return packet - - -def configurationChangeReject(): - """CONFIGURATION CHANGE REJECT Section 9.1.12d""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x33) # 00110011 - c = RrCause() - packet = a / b / c - return packet - - -# Network to MS -def frequencyRedefinition(CellChannelDescription_presence=0): - """Frequency redefinition Section 9.1.13""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x14) # 00010100 - c = ChannelDescription() - d = MobileAllocation() - e = StartingTime() - packet = a / b / c / d / e - if CellChannelDescription_presence is 1: - f = CellChannelDescriptionHdr(ieiCCD=0x62, eightBitCCD=0x0) - packet = packet / f - return packet - - -# Network to MS -def pdchAssignmentCommand(ChannelDescription_presence=0, - CellChannelDescription_presence=0, - MobileAllocation_presence=0, - StartingTime_presence=0, FrequencyList_presence=0, - ChannelDescription_presence1=0, - FrequencyChannelSequence_presence=0, - MobileAllocation_presence1=0, - PacketChannelDescription_presence=0, - DedicatedModeOrTBF_presence=0): - """PDCH ASSIGNMENT COMMAND Section 9.1.13a""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x23) # 00100011 - c = ChannelDescription() - packet = a / b / c - if ChannelDescription_presence is 1: - d = ChannelDescriptionHdr(ieiCD=0x62, eightBitCD=0x0) - packet = packet / d - if CellChannelDescription_presence is 1: - e = CellChannelDescriptionHdr(ieiCCD=0x05, eightBitCCD=0x0) - packet = packet / e - if MobileAllocation_presence is 1: - f = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) - packet = packet / f - if StartingTime_presence is 1: - g = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) - packet = packet / g - if FrequencyList_presence is 1: - h = FrequencyListHdr(ieiFL=0x19, eightBitFL=0x0) - packet = packet / h - if ChannelDescription_presence1 is 1: - i = ChannelDescriptionHdr(ieiCD=0x1C, eightBitCD=0x0) - packet = packet / i - if FrequencyChannelSequence_presence is 1: - j = FrequencyChannelSequenceHdr(ieiFCS=0x1E, eightBitFCS=0x0) - packet = packet / j - if MobileAllocation_presence1 is 1: - k = MobileAllocationHdr(ieiMA=0x21, eightBitMA=0x0) - packet = packet / k - if PacketChannelDescription_presence is 1: - l = PacketChannelDescription(ieiPCD=0x22) - packet = packet / l - if DedicatedModeOrTBF_presence is 1: - m = DedicatedModeOrTBFHdr(ieiDMOT=0x23, eightBitDMOT=0x0) - packet = packet / m - return packet - - -def gprsSuspensionRequest(): - """GPRS SUSPENSION REQUEST Section 9.1.13b""" - a = TpPd(pd=0x6) - b = MessageType() - c = Tlli() - d = RoutingAreaIdentification() - e = SuspensionCause() - packet = a / b / c / d / e - return packet - - -class HandoverAccess(Packet): - name = "Handover Access" # Section 9.1.14" - fields_desc = [ - ByteField("handover", None), - ] - - -# Network to MS -def handoverCommand(SynchronizationIndication_presence=0, - FrequencyShortList_presence=0, FrequencyList_presence=0, - CellChannelDescription_presence=0, - MultislotAllocation_presence=0, - ChannelMode_presence=0, ChannelMode_presence1=0, - ChannelMode_presence2=0, - ChannelMode_presence3=0, ChannelMode_presence4=0, - ChannelMode_presence5=0, - ChannelMode_presence6=0, ChannelMode_presence7=0, - ChannelDescription_presence1=0, ChannelMode2_presence=0, - FrequencyChannelSequence_presence=0, - MobileAllocation_presence=0, - StartingTime_presence=0, TimeDifference_presence=0, - TimingAdvance_presence=0, - FrequencyShortList_presence1=0, - FrequencyList_presence1=0, - ChannelDescription2_presence=0, - ChannelDescription_presence2=0, - FrequencyChannelSequence_presence1=0, - MobileAllocation_presence1=0, - CipherModeSetting_presence=0, - VgcsTargetModeIdentication_presence=0, - MultiRateConfiguration_presence=0): - """HANDOVER COMMAND Section 9.1.15""" - name = "Handover Command" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x2b) # 00101011 - c = CellDescription() - d = ChannelDescription2() - e = HandoverReference() - f = PowerCommandAndAccessType() - packet = a / b / c / d / e / f - if SynchronizationIndication_presence is 1: - g = SynchronizationIndicationHdr(ieiSI=0xD, eightBitSI=0x0) - packet = packet / g - if FrequencyShortList_presence is 1: - h = FrequencyShortListHdr(ieiFSL=0x02) - packet = packet / h - if FrequencyList_presence is 1: - i = FrequencyListHdr(ieiFL=0x05, eightBitFL=0x0) - packet = packet / i - if CellChannelDescription_presence is 1: - j = CellChannelDescriptionHdr(ieiCCD=0x62, eightBitCCD=0x0) - packet = packet / j - if MultislotAllocation_presence is 1: - k = MultislotAllocationHdr(ieiMSA=0x10, eightBitMSA=0x0) - packet = packet / k - if ChannelMode_presence is 1: - l = ChannelModeHdr(ieiCM=0x63, eightBitCM=0x0) - packet = packet / l - if ChannelMode_presence1 is 1: - m = ChannelModeHdr(ieiCM=0x11, eightBitCM=0x0) - packet = packet / m - if ChannelMode_presence2 is 1: - n = ChannelModeHdr(ieiCM=0x13, eightBitCM=0x0) - packet = packet / n - if ChannelMode_presence3 is 1: - o = ChannelModeHdr(ieiCM=0x14, eightBitCM=0x0) - packet = packet / o - if ChannelMode_presence4 is 1: - p = ChannelModeHdr(ieiCM=0x15, eightBitCM=0x0) - packet = packet / p - if ChannelMode_presence5 is 1: - q = ChannelModeHdr(ieiCM=0x16, eightBitCM=0x0) - packet = packet / q - if ChannelMode_presence6 is 1: - r = ChannelModeHdr(ieiCM=0x17, eightBitCM=0x0) - packet = packet / r - if ChannelMode_presence7 is 1: - s = ChannelModeHdr(ieiCM=0x18, eightBitCM=0x0) - packet = packet / s - if ChannelDescription_presence1 is 1: - s1 = ChannelDescriptionHdr(ieiCD=0x64, eightBitCD=0x0) - packet = packet / s1 - if ChannelMode2_presence is 1: - t = ChannelMode2Hdr(ieiCM2=0x66, eightBitCM2=0x0) - packet = packet / t - if FrequencyChannelSequence_presence is 1: - u = FrequencyChannelSequenceHdr(ieiFCS=0x69, eightBitFCS=0x0) - packet = packet / u - if MobileAllocation_presence is 1: - v = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) - packet = packet / v - if StartingTime_presence is 1: - w = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) - packet = packet / w - if TimeDifference_presence is 1: - x = TimeDifferenceHdr(ieiTD=0x7B, eightBitTD=0x0) - packet = packet / x - if TimingAdvance_presence is 1: - y = TimingAdvanceHdr(ieiTA=0x7D, eightBitTA=0x0) - packet = packet / y - if FrequencyShortList_presence1 is 1: - z = FrequencyShortListHdr(ieiFSL=0x12) - packet = packet / z - if FrequencyList_presence1 is 1: - aa = FrequencyListHdr(ieiFL=0x19, eightBitFL=0x0) - packet = packet / aa - if ChannelDescription2_presence is 1: - ab = ChannelDescription2Hdr(ieiCD2=0x1C, eightBitCD2=0x0) - packet = packet / ab - if ChannelDescription_presence2 is 1: - ac = ChannelDescriptionHdr(ieiCD=0x1D, eightBitCD=0x0) - packet = packet / ac - if FrequencyChannelSequence_presence1 is 1: - ad = FrequencyChannelSequenceHdr(ieiFCS=0x1E, eightBitFCS=0x0) - packet = packet / ad - if MobileAllocation_presence1 is 1: - ae = MobileAllocationHdr(ieiMA=0x21, eightBitMA=0x0) - packet = packet / ae - if CipherModeSetting_presence is 1: - af = CipherModeSettingHdr(ieiCMS=0x9, eightBitCMS=0x0) - packet = packet / af - if VgcsTargetModeIdentication_presence is 1: - ag = VgcsTargetModeIdenticationHdr(ieiVTMI=0x01, eightBitVTMI=0x0) - packet = packet / ag - if MultiRateConfiguration_presence is 1: - ah = MultiRateConfigurationHdr(ieiMRC=0x03, eightBitMRC=0x0) - packet = packet / ah - return packet - - -def handoverComplete(MobileTimeDifference_presence=0): - """HANDOVER COMPLETE Section 9.1.16""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x2c) # 00101100 - c = RrCause() - packet = a / b / c - if MobileTimeDifference_presence is 1: - d = MobileTimeDifferenceHdr(ieiMTD=0x77, eightBitMTD=0x0) - packet = packet / d - return packet - - -def handoverFailure(): - """HANDOVER FAILURE Section 9.1.17""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x28) # 00101000 - c = RrCause() - packet = a / b / c - return packet - - -#The L2 pseudo length of this message is the sum of lengths of all -#information elements present in the message except -#the IA Rest Octets and L2 Pseudo Length information elements. -# Network to MS -def immediateAssignment(ChannelDescription_presence=0, - PacketChannelDescription_presence=0, - StartingTime_presence=0): - """IMMEDIATE ASSIGNMENT Section 9.1.18""" - a = L2PseudoLength() - b = TpPd(pd=0x6) - c = MessageType(mesType=0x3F) # 00111111 - d = PageModeAndDedicatedModeOrTBF() - packet = a / b / c / d - if ChannelDescription_presence is 1: - f = ChannelDescription() - packet = packet / f - if PacketChannelDescription_presence is 1: - g = PacketChannelDescription() - packet = packet / g - h = RequestReference() - i = TimingAdvance() - j = MobileAllocation() - packet = packet / h / i / j - if StartingTime_presence is 1: - k = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) - packet = packet / k - l = IaRestOctets() - packet = packet / l - return packet - - -#The L2 pseudo length of this message is the sum of lengths of all -#information elements present in the message except -#the IAX Rest Octets and L2 Pseudo Length information elements. - -# Network to MS -def immediateAssignmentExtended(StartingTime_presence=0): - """IMMEDIATE ASSIGNMENT EXTENDED Section 9.1.19""" - a = L2PseudoLength() - b = TpPd(pd=0x6) - c = MessageType(mesType=0x39) # 00111001 - d = PageModeAndSpareHalfOctets() - f = ChannelDescription() - g = RequestReference() - h = TimingAdvance() - i = MobileAllocation() - packet = a / b / c / d / f / g / h / i - if StartingTime_presence is 1: - j = StartingTimeHdr(ieiST=0x7C, eightBitST=0x0) - packet = packet / j - k = IaxRestOctets() - packet = packet / k - return packet - - -# This message has L2 pseudo length 19 -# Network to MS -def immediateAssignmentReject(): - """IMMEDIATE ASSIGNMENT REJECT Section 9.1.20""" - a = L2PseudoLength(l2pLength=0x13) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x3a) # 00111010 - d = PageModeAndSpareHalfOctets() - f = RequestReference() - g = WaitIndication() - h = RequestReference() - i = WaitIndication() - j = RequestReference() - k = WaitIndication() - l = RequestReference() - m = WaitIndication() - n = IraRestOctets() - packet = a / b / c / d / f / g / h / i / j / k / l / m / n - return packet - - -def measurementReport(): - """MEASUREMENT REPORT Section 9.1.21""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x15) # 00010101 - c = MeasurementResults() - packet = a / b / c - return packet - - -# len max 20 -class NotificationFacch(): - """NOTIFICATION/FACCH Section 9.1.21a""" - name = "Notification/facch" - fields_desc = [ - BitField("rr", 0x0, 1), - BitField("msgTyoe", 0x0, 5), - BitField("layer2Header", 0x0, 2), - BitField("frChanDes", 0x0, 24) - ] - - -# The L2 pseudo length of this message has a value one -# Network to MS -def notificationNch(): - """NOTIFICATION/NCH Section 9.1.21b""" - a = L2PseudoLength(l2pLength=0x01) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x20) # 00100000 - d = NtNRestOctets() - packet = a / b / c / d - return packet - - -def notificationResponse(): - """NOTIFICATION RESPONSE Section 9.1.21d""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x26) # 00100110 - c = MobileStationClassmark2() - d = MobileId() - e = DescriptiveGroupOrBroadcastCallReference() - packet = a / b / c / d / e - return packet - - -# Network to MS -def rrCellChangeOrder(): - """RR-CELL CHANGE ORDER Section 9.1.21e""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x8) # 00001000 - c = CellDescription() - d = NcModeAndSpareHalfOctets() - packet = a / b / c / d - return packet - - -# Network to MS -def pagingRequestType1(MobileId_presence=0): - """PAGING REQUEST TYPE 1 Section 9.1.22""" - #The L2 pseudo length of this message is the sum of lengths of all - #information elements present in the message except - #the P1 Rest Octets and L2 Pseudo Length information elements. - a = L2PseudoLength() - b = TpPd(pd=0x6) - c = MessageType(mesType=0x21) # 00100001 - d = PageModeAndChannelNeeded() - f = MobileId() - packet = a / b / c / d / f - if MobileId_presence is 1: - g = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) - packet = packet / g - h = P1RestOctets() - packet = packet / h - return packet - - -# The L2 pseudo length of this message is the sum of lengths of all -# information elements present in the message except -# Network to MS -def pagingRequestType2(MobileId_presence=0): - """PAGING REQUEST TYPE 2 Section 9.1.23""" - a = L2PseudoLength() - b = TpPd(pd=0x6) - c = MessageType(mesType=0x22) # 00100010 - d = PageModeAndChannelNeeded() - f = MobileId() - g = MobileId() - packet = a / b / c / d / f / g - if MobileId_presence is 1: - h = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) - packet = packet / h - i = P2RestOctets() - packet = packet / i - return packet - - -# Network to MS -def pagingRequestType3(): - """PAGING REQUEST TYPE 3 Section 9.1.24""" -# This message has a L2 Pseudo Length of 19 - a = L2PseudoLength(l2pLength=0x13) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x24) # 00100100 - d = PageModeAndChannelNeeded() - e = TmsiPTmsi() - f = TmsiPTmsi() - g = TmsiPTmsi() - h = TmsiPTmsi() - i = P3RestOctets() - packet = a / b / c / d / e / f / g / h / i - return packet - - -def pagingResponse(): - """PAGING RESPONSE Section 9.1.25""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x27) # 00100111 - c = CiphKeySeqNrAndSpareHalfOctets() - d = MobileStationClassmark2() - e = MobileId() - packet = a / b / c / d / e - return packet - - -# Network to MS -def partialRelease(): - """PARTIAL RELEASE Section 9.1.26""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0xa) # 00001010 - c = ChannelDescription() - packet = a / b / c - return packet - - -def partialReleaseComplete(): - """PARTIAL RELEASE COMPLETE Section 9.1.27""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0xf) # 00001111 - packet = a / b - return packet - - -# Network to MS -def physicalInformation(): - """PHYSICAL INFORMATION Section 9.1.28""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x2d) # 00101101 - c = TimingAdvance() - packet = a / b / c - return packet - - -def rrInitialisationRequest(): - """RR Initialisation Request Section 9.1.28.a""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x3c) # 00111100 - c = CiphKeySeqNrAndMacModeAndChannelCodingRequest() - e = MobileStationClassmark2() - f = Tlli() - g = ChannelRequestDescription() - h = GprsMeasurementResults() - packet = a / b / c / e / f / g / h - return packet - - -def rrStatus(): - """RR STATUS Section 9.1.29""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x12) # 00010010 - c = RrCause() - packet = a / b / c - return packet - - -# It does not -# follow the basic format. Its length is _25_ bits. The -# order of bit transmission is defined in GSM 04.04. -# Network to MS -class SynchronizationChannelInformation(): - """SYNCHRONIZATION CHANNEL INFORMATION Section 9.1.30""" - name = "Synchronization Channel Information" - fields_desc = [ - BitField("bsic", 0x0, 5), - BitField("t1Hi", 0x0, 3), - ByteField("t1Mi", 0x0), - BitField("t1Lo", 0x0, 1), - BitField("t2", 0x0, 5), - BitField("t3Hi", 0x0, 2), - BitField("t3Lo", 0x0, 1) - ] - - -# This message has a L2 Pseudo Length of 21. -# Network to MS -def systemInformationType1(): - """SYSTEM INFORMATION TYPE 1 Section 9.1.31""" - a = L2PseudoLength(l2pLength=0x15) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x19) # 00011001 - d = CellChannelDescription() - e = RachControlParameters() - f = Si1RestOctets() - packet = a / b / c / d / e / f - return packet - - -# This message has a L2 Pseudo Length of 22. -# Network to MS -def systemInformationType2(): - """SYSTEM INFORMATION TYPE 2 Section 9.1.32""" - a = L2PseudoLength(l2pLength=0x16) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x1a) # 00011010 - d = NeighbourCellsDescription() - e = NccPermitted() - f = RachControlParameters() - packet = a / b / c / d / e / f - return packet - - -# This message has a L2 pseudo length of 21 -# Network to MS -def systemInformationType2bis(): - """SYSTEM INFORMATION TYPE 2bis Section 9.1.33""" - a = L2PseudoLength(l2pLength=0x15) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x2) # 00000010 - d = NeighbourCellsDescription() - e = RachControlParameters() - f = Si2bisRestOctets() - packet = a / b / c / d / e / f - return packet - - -# This message has a L2 pseudo length of 18 -# Network to MS -def systemInformationType2ter(): - """SYSTEM INFORMATION TYPE 2ter Section 9.1.34""" - a = L2PseudoLength(l2pLength=0x12) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x3) # 00000011 - d = NeighbourCellsDescription2() - e = Si2terRestOctets() - packet = a / b / c / d / e - return packet - - -# This message has a L2 Pseudo Length of 18 -# Network to MS -def systemInformationType3(): - """SYSTEM INFORMATION TYPE 3 Section 9.1.35""" - a = L2PseudoLength(l2pLength=0x12) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x1b) # 00011011 - d = CellIdentity() - e = LocalAreaId() - f = ControlChannelDescription() - g = CellOptionsBCCH() - h = CellSelectionParameters() - i = RachControlParameters() - j = Si3RestOctets() - packet = a / b / c / d / e / f / g / h / i / j - return packet - - -#The L2 pseudo length of this message is the -#sum of lengths of all information elements present in the message except -#the SI 4 Rest Octets and L2 Pseudo Length -# Network to MS -def systemInformationType4(ChannelDescription_presence=0, - MobileAllocation_presence=0): - """SYSTEM INFORMATION TYPE 4 Section 9.1.36""" - a = L2PseudoLength() - b = TpPd(pd=0x6) - c = MessageType(mesType=0x1C) # 000111100 - d = LocalAreaId() - e = CellSelectionParameters() - f = RachControlParameters() - packet = a / b / c / d / e / f - if ChannelDescription_presence is 1: - g = ChannelDescriptionHdr(ieiCD=0x64, eightBitCD=0x0) - packet = packet / g - if MobileAllocation_presence is 1: - h = MobileAllocationHdr(ieiMA=0x72, eightBitMA=0x0) - packet = packet / h - i = Si4RestOctets() - packet = packet / i - return packet - - -#This message has a L2 Pseudo Length of 18 -# Network to MS -def systemInformationType5(): - """SYSTEM INFORMATION TYPE 5 Section 9.1.37""" - a = L2PseudoLength(l2pLength=0x12) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x35) # 000110101 - d = NeighbourCellsDescription() - packet = a / b / c / d - return packet - - -#This message has a L2 Pseudo Length of 18 -# Network to MS -def systemInformationType5bis(): - """SYSTEM INFORMATION TYPE 5bis Section 9.1.38""" - a = L2PseudoLength(l2pLength=0x12) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x5) # 00000101 - d = NeighbourCellsDescription() - packet = a / b / c / d - return packet - - -# This message has a L2 Pseudo Length of 18 -# Network to MS -def systemInformationType5ter(): - """SYSTEM INFORMATION TYPE 5ter Section 9.1.39""" - a = L2PseudoLength(l2pLength=0x12) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x6) # 00000110 - d = NeighbourCellsDescription2() - packet = a / b / c / d - return packet - - -#This message has a L2 Pseudo Length of 11 -# Network to MS -def systemInformationType6(): - """SYSTEM INFORMATION TYPE 6 Section 9.1.40""" - a = L2PseudoLength(l2pLength=0x0b) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x1e) # 00011011 - d = CellIdentity() - e = LocalAreaId() - f = CellOptionsBCCH() - g = NccPermitted() - h = Si6RestOctets() - packet = a / b / c / d / e / f / g - return packet - - -# The L2 pseudo length of this message has the value 1 -# Network to MS -def systemInformationType7(): - """SYSTEM INFORMATION TYPE 7 Section 9.1.41""" - a = L2PseudoLength(l2pLength=0x01) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x37) # 000110111 - d = Si7RestOctets() - packet = a / b / c / d - return packet - - -# The L2 pseudo length of this message has the value 1 -# Network to MS -def systemInformationType8(): - """SYSTEM INFORMATION TYPE 8 Section 9.1.42""" - a = L2PseudoLength(l2pLength=0x01) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x18) # 00011000 - d = Si8RestOctets() - packet = a / b / c / d - return packet - - -# The L2 pseudo length of this message has the value 1 -# Network to MS -def systemInformationType9(): - """SYSTEM INFORMATION TYPE 9 Section 9.1.43""" - a = L2PseudoLength(l2pLength=0x01) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x4) # 00000100 - d = Si9RestOctets() - packet = a / b / c / d - return packet - - -# The L2 pseudo length of this message has the value 0 -# Network to MS -def systemInformationType13(): - """SYSTEM INFORMATION TYPE 13 Section 9.1.43a""" - a = L2PseudoLength(l2pLength=0x00) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x0) # 00000000 - d = Si13RestOctets() - packet = a / b / c / d - return packet -# -# 9.1.43b / c spare -# - - -# The L2 pseudo length of this message has the value 1 -# Network to MS -def systemInformationType16(): - """SYSTEM INFORMATION TYPE 16 Section 9.1.43d""" - a = L2PseudoLength(l2pLength=0x01) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x3d) # 00111101 - d = Si16RestOctets() - packet = a / b / c / d - return packet - - -# The L2 pseudo length of this message has the value 1 -# Network to MS -def systemInformationType17(): - """SYSTEM INFORMATION TYPE 17 Section 9.1.43e""" - a = L2PseudoLength(l2pLength=0x01) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x3e) # 00111110 - d = Si17RestOctets() - packet = a / b / c / d - return packet - - -def talkerIndication(): - """TALKER INDICATION Section 9.1.44""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x11) # 00010001 - c = MobileStationClassmark2() - d = MobileId() - packet = a / b / c / d - return packet - - -class UplinkAccess(): - """UPLINK ACCESS Section 9.1.45""" - name = "Uplink Access" - fields_desc = [ - ByteField("establishment", 0x0) - ] - - -# Network to MS -def uplinkBusy(): - """UPLINK BUSY Section 9.1.46""" - name = "Uplink Busy" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x2a) # 00101010 - packet = a / b - return packet - - -# Network to MS -class UplinkFree(): - """UPLINK FREE Section 9.1.47""" - name = "Uplink Free" - fields_desc = [ - BitField("pd", 0x0, 1), - BitField("msgType", 0x0, 5), - BitField("layer2Header", 0x0, 2), - BitField("uplinkAccess", 0x0, 1), - BitField("lOrH", 0x0, 1), # 0 for L, 1 for H - BitField("upIdCode", 0x0, 6), - ] - - -def uplinkRelease(): - """UPLINK RELEASE Section 9.1.48""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0xe) # 00001110 - c = RrCause() - packet = a / b / c - return packet - - -# Network to MS -def vgcsUplinkGrant(): - """VGCS UPLINK GRANT Section 9.1.49""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x9) # 00001001 - c = RrCause() - d = RequestReference() - e = TimingAdvance() - packet = a / b / c / d / e - return packet - - -# Network to MS -def systemInformationType10(): - """SYSTEM INFORMATION TYPE 10 Section 9.1.50""" - name = "SyStem Information Type 10" - fields_desc = [ - BitField("pd", 0x0, 1), - BitField("msgType", 0x0, 5), - BitField("layer2Header", 0x0, 2), - BitField("si10", 0x0, 160) - ] - - -# Network to MS -# The L2 pseudo length of this message has the value 18 -def extendedMeasurementOrder(): - """EXTENDED MEASUREMENT ORDER Section 9.1.51""" - a = L2PseudoLength(l2pLength=0x12) - b = TpPd(pd=0x6) - c = MessageType(mesType=0x37) # 00110111 - d = ExtendedMeasurementFrequencyList() - packet = a / b / c / d - return packet - - -def extendedMeasurementReport(): - """EXTENDED MEASUREMENT REPORT Section 9.1.52""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x36) # 00110110 - c = ExtendedMeasurementResults() - packet = a / b / c - return packet - - -def applicationInformation(): - """APPLICATION INFORMATION Section 9.1.53""" - a = TpPd(pd=0x6) - b = MessageType(mesType=0x38) # 00111000 - c = ApduIDAndApduFlags() - e = ApduData() - packet = a / b / c / e - return packet -# -# 9.2 Messages for mobility management -# - - -# Network to MS -def authenticationReject(): - """AUTHENTICATION REJECT Section 9.2.1""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x11) # 00010001 - packet = a / b - return packet - - -# Network to MS -def authenticationRequest(): - """AUTHENTICATION REQUEST Section 9.2.2""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x12) # 00010010 - c = CiphKeySeqNrAndSpareHalfOctets() - d = AuthenticationParameterRAND() - packet = a / b / c / d - return packet - - -def authenticationResponse(): - """AUTHENTICATION RESPONSE Section 9.2.3""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x14) # 00010100 - c = AuthenticationParameterSRES() - packet = a / b / c - return packet - - -def cmReestablishmentRequest(LocalAreaId_presence=0): - """CM RE-ESTABLISHMENT REQUEST Section 9.2.4""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x28) # 00101000 - c = CiphKeySeqNrAndSpareHalfOctets() - e = MobileStationClassmark2() - f = MobileId() - if LocalAreaId_presence is 1: - g = LocalAreaId(iei=0x13, eightbit=0x0) - packet = packet / g - packet = a / b / c / e / f - return packet - - -# Network to MS -def cmServiceAccept(): - """CM SERVICE ACCEPT Section 9.2.5""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x21) # 00100001 - packet = a / b - return packet - - -# Network to MS -def cmServicePrompt(): - """CM SERVICE PROMPT Section 9.2.5a""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x25) # 00100101 - c = PdAndSapi() - packet = a / b / c - return packet - - -# Network to MS -def cmServiceReject(): - """CM SERVICE REJECT Section 9.2.6""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x22) # 00100010 - c = RejectCause() - packet = a / b / c - return packet - - -def cmServiceAbort(): - """CM SERVICE ABORT Section 9.2.7""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x23) # 00100011 - packet = a / b - return packet - - -# Network to MS -def abort(): - """ABORT Section 9.2.8""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x29) # 00101001 - c = RejectCause() - packet = a / b / c - return packet - - -def cmServiceRequest(PriorityLevel_presence=0): - """CM SERVICE REQUEST Section 9.2.9""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x24) # 00100100 - c = CmServiceTypeAndCiphKeySeqNr() - e = MobileStationClassmark2() - f = MobileId() - packet = a / b / c / e / f - if PriorityLevel_presence is 1: - g = PriorityLevelHdr(ieiPL=0x8, eightBitPL=0x0) - packet = packet / g - return packet - - -# Network to MS -def identityRequest(): - """IDENTITY REQUEST Section 9.2.10""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x8) # 00001000 - c = IdentityTypeAndSpareHalfOctets() - packet = a / b / c - return packet - - -def identityResponse(): - """IDENTITY RESPONSE Section 9.2.11""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x9) # 00001001 - c = MobileId() - packet = a / b / c - return packet - - -def imsiDetachIndication(): - """IMSI DETACH INDICATION Section 9.2.12""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x1) # 00000001 - c = MobileStationClassmark1() - d = MobileId() - packet = a / b / c / d - return packet - - -# Network to MS -def locationUpdatingAccept(MobileId_presence=0, - FollowOnProceed_presence=0, - CtsPermission_presence=0): - """LOCATION UPDATING ACCEPT Section 9.2.13""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x02) # 00000010 - c = LocalAreaId() - packet = a / b / c - if MobileId_presence is 1: - d = MobileIdHdr(ieiMI=0x17, eightBitMI=0x0) - packet = packet / d - if FollowOnProceed_presence is 1: - e = FollowOnProceed(ieiFOP=0xA1) - packet = packet / e - if CtsPermission_presence is 1: - f = CtsPermissionHdr(ieiCP=0xA2, eightBitCP=0x0) - packet = packet / f - return packet - - -# Network to MS -def locationUpdatingReject(): - """LOCATION UPDATING REJECT Section 9.2.14""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x4) # 0x00000100 - c = RejectCause() - packet = a / b / c - return packet - - -def locationUpdatingRequest(): - """LOCATION UPDATING REQUEST Section 9.2.15""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x8) # 00001000 - c = LocationUpdatingTypeAndCiphKeySeqNr() - e = LocalAreaId() - f = MobileStationClassmark1() - g = MobileId() - packet = a / b / c / e / f / g - return packet - - -# Network to MS -def mmInformation(NetworkName_presence=0, NetworkName_presence1=0, - TimeZone_presence=0, TimeZoneAndTime_presence=0, - LsaIdentifier_presence=0): - """MM INFORMATION Section 9.2.15a""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x32) # 00110010 - packet = a / b - if NetworkName_presence is 1: - c = NetworkNameHdr(ieiNN=0x43, eightBitNN=0x0) - packet = packet / c - if NetworkName_presence1 is 1: - d = NetworkNameHdr(ieiNN=0x45, eightBitNN=0x0) - packet = packet / d - if TimeZone_presence is 1: - e = TimeZoneHdr(ieiTZ=0x46, eightBitTZ=0x0) - packet = packet / e - if TimeZoneAndTime_presence is 1: - f = TimeZoneAndTimeHdr(ieiTZAT=0x47, eightBitTZAT=0x0) - packet = packet / f - if LsaIdentifier_presence is 1: - g = LsaIdentifierHdr(ieiLI=0x48, eightBitLI=0x0) - packet = packet / g - return packet - - -def mmStatus(): - """MM STATUS Section 9.2.16""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x31) # 00110001 - c = RejectCause() - packet = a / b / c - return packet - - -# Network to MS -def tmsiReallocationCommand(): - """TMSI REALLOCATION COMMAND Section 9.2.17""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x1a) # 00011010 - c = LocalAreaId() - d = MobileId() - packet = a / b / c / d - return packet - - -def tmsiReallocationComplete(): - """TMSI REALLOCATION COMPLETE Section 9.2.18""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x1b) # 00011011 - packet = a / b - return packet - - -def mmNull(): - """MM NULL Section 9.2.19""" - a = TpPd(pd=0x5) - b = MessageType(mesType=0x30) # 00110000 - packet = a / b - return packet - -# -# 9.3 Messages for circuit-switched call control -# - - -# Network to MS -def alertingNetToMs(Facility_presence=0, ProgressIndicator_presence=0, - UserUser_presence=0): - """ALERTING Section 9.3.1.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1) # 00000001 - packet = a / b - if Facility_presence is 1: - c = FacilityHdr(ieiF=0x1C) - packet = packet / c - if ProgressIndicator_presence is 1: - d = ProgressIndicatorHdr(ieiPI=0x1E) - packet = packet / d - if UserUser_presence is 1: - e = UserUserHdr(ieiUU=0x7E) - packet = packet / e - return packet - - -def alertingMsToNet(Facility_presence=0, UserUser_presence=0, - SsVersionIndicator_presence=0): - """ALERTING Section 9.3.1.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1) # 00000001 - packet = a / b - if Facility_presence is 1: - c = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / c - if UserUser_presence is 1: - d = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / d - if SsVersionIndicator_presence is 1: - e = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / e - return packet - - -def callConfirmed(RepeatIndicator_presence=0, - BearerCapability_presence=0, BearerCapability_presence1=0, - Cause_presence=0, CallControlCapabilities_presence=0): - """CALL CONFIRMED Section 9.3.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x8) # 00001000 - packet = a / b - if RepeatIndicator_presence is 1: - c = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / c - if BearerCapability_presence is 1: - d = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / d - if BearerCapability_presence1 is 1: - e = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / e - if Cause_presence is 1: - f = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / f - if CallControlCapabilities_presence is 1: - g = CallControlCapabilitiesHdr(ieiCCC=0x15, eightBitCCC=0x0) - packet = packet / g - return packet - - -# Network to MS -def callProceeding(RepeatIndicator_presence=0, - BearerCapability_presence=0, - BearerCapability_presence1=0, - Facility_presence=0, ProgressIndicator_presence=0, - PriorityLevel_presence=0): - """CALL PROCEEDING Section 9.3.3""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x2) # 00000010 - packet = a / b - if RepeatIndicator_presence is 1: - c = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / c - if BearerCapability_presence is 1: - d = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / d - if BearerCapability_presence1 is 1: - e = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / e - if Facility_presence is 1: - f = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / f - if ProgressIndicator_presence is 1: - g = ProgressIndicatorHdr(ieiPI=0x1E, eightBitPI=0x0) - packet = packet / g - if PriorityLevel_presence is 1: - h = PriorityLevelHdr(ieiPL=0x80, eightBitPL=0x0) - packet = packet / h - return packet - - -# Network to MS -def congestionControl(Cause_presence=0): - """CONGESTION CONTROL Section 9.3.4""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x39) # 00111001 - c = CongestionLevelAndSpareHalfOctets() - packet = a / b / c - if Cause_presence is 1: - e = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / e - return packet - - -# Network to MS -def connectNetToMs(Facility_presence=0, ProgressIndicator_presence=0, - ConnectedNumber_presence=0, ConnectedSubaddress_presence=0, - UserUser_presence=0): - """CONNECT Section 9.3.5.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x7) # 00000111 - packet = a / b - if Facility_presence is 1: - c = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / c - if ProgressIndicator_presence is 1: - d = ProgressIndicatorHdr(ieiPI=0x1E, eightBitPI=0x0) - packet = packet / d - if ConnectedNumber_presence is 1: - e = ConnectedNumberHdr(ieiCN=0x4C, eightBitCN=0x0) - packet = packet / e - if ConnectedSubaddress_presence is 1: - f = ConnectedSubaddressHdr(ieiCS=0x4D, eightBitCS=0x0) - packet = packet / f - if UserUser_presence is 1: - g = UserUserHdr(ieiUU=0x7F, eightBitUU=0x0) - packet = packet / g - return packet - - -def connectMsToNet(Facility_presence=0, ConnectedSubaddress_presence=0, - UserUser_presence=0, SsVersionIndicator_presence=0): - """CONNECT Section 9.3.5.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x7) # 00000111 - packet = a / b - if Facility_presence is 1: - c = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / c - if ConnectedSubaddress_presence is 1: - d = ConnectedSubaddressHdr(ieiCS=0x4D, eightBitCS=0x0) - packet = packet / d - if UserUser_presence is 1: - e = UserUserHdr(ieiUU=0x7F, eightBitUU=0x0) - packet = packet / e - if SsVersionIndicator_presence is 1: - f = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / f - return packet - - -def connectAcknowledge(): - """CONNECT ACKNOWLEDGE Section 9.3.6""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0xf) # 00001111 - packet = a / b - return packet - - -# Network to MS -def disconnectNetToMs(Facility_presence=0, ProgressIndicator_presence=0, - UserUser_presence=0, AllowedActions_presence=0): - """DISCONNECT Section 9.3.7.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x25) # 00100101 - c = Cause() - packet = a / b / c - if Facility_presence is 1: - d = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / d - if ProgressIndicator_presence is 1: - e = ProgressIndicatorHdr(ieiPI=0x1E, eightBitPI=0x0) - packet = packet / e - if UserUser_presence is 1: - f = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / f - if AllowedActions_presence is 1: - g = AllowedActionsHdr(ieiAA=0x7B, eightBitAA=0x0) - packet = packet / g - return packet - - -def disconnectMsToNet(Facility_presence=0, UserUser_presence=0, - SsVersionIndicator_presence=0): - """Disconnect Section 9.3.7.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x25) # 00100101 - c = Cause() - packet = a / b / c - if Facility_presence is 1: - d = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / d - if UserUser_presence is 1: - e = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / e - if SsVersionIndicator_presence is 1: - f = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / f - return packet - - -def emergencySetup(BearerCapability_presence=0): - """EMERGENCY SETUP Section 9.3.8""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0xe) # 00001110 - packet = a / b - if BearerCapability_presence is 1: - c = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / c - return packet - - -# Network to MS -def facilityNetToMs(): - """FACILITY Section 9.3.9.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x3a) # 00111010 - c = Facility() - packet = a / b / c - return packet - - -def facilityMsToNet(SsVersionIndicator_presence=0): - """FACILITY Section 9.3.9.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x3a) # 00111010 - c = Facility() - packet = a / b / c - if SsVersionIndicator_presence is 1: - d = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / d - return packet - - -def hold(): - """HOLD Section 9.3.10""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x18) # 00011000 - packet = a / b - return packet - - -# Network to MS -def holdAcknowledge(): - """HOLD ACKNOWLEDGE Section 9.3.11""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x19) # 00011001 - packet = a / b - return packet - - -# Network to MS -def holdReject(): - """HOLD REJECT Section 9.3.12""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1a) # 00011010 - c = Cause() - packet = a / b / c - return packet - - -def modify(LowLayerCompatibility_presence=0, - HighLayerCompatibility_presence=0, - ReverseCallSetupDirection_presence=0): - """MODIFY Section 9.3.13""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x17) # 00010111 - c = BearerCapability() - packet = a / b / c - if LowLayerCompatibility_presence is 1: - d = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / d - if HighLayerCompatibility_presence is 1: - e = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / e - if ReverseCallSetupDirection_presence is 1: - f = ReverseCallSetupDirectionHdr(ieiRCSD=0xA3) - packet = packet / f - return packet - - -def modifyComplete(LowLayerCompatibility_presence=0, - HighLayerCompatibility_presence=0, - ReverseCallSetupDirection_presence=0): - """MODIFY COMPLETE Section 9.3.14""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1f) # 00011111 - c = BearerCapability() - packet = a / b / c - if LowLayerCompatibility_presence is 1: - d = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / d - if HighLayerCompatibility_presence is 1: - e = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / e - if ReverseCallSetupDirection_presence is 1: - f = ReverseCallSetupDirection(ieiRCSD=0xA3) - packet = packet / f - return packet - - -def modifyReject(LowLayerCompatibility_presence=0, - HighLayerCompatibility_presence=0): - """MODIFY REJECT Section 9.3.15""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x13) # 00010011 - c = BearerCapability() - d = Cause() - packet = a / b / c / d - if LowLayerCompatibility_presence is 1: - e = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / e - if HighLayerCompatibility_presence is 1: - f = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / f - return packet - - -def notify(): - """NOTIFY Section 9.3.16""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x3e) # 00111110 - c = NotificationIndicator() - packet = a / b / c - return packet - - -# Network to MS -def progress(UserUser_presence=0): - """PROGRESS Section 9.3.17""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x3) # 00000011 - c = ProgressIndicator() - packet = a / b / c - if UserUser_presence is 1: - d = UserUserHdr() - packet = packet / d - return packet - - -# Network to MS -def ccEstablishment(): - """CC-ESTABLISHMENT Section 9.3.17a""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x4) # 00000100 - c = SetupContainer() - packet = a / b / c - return packet - - -def ccEstablishmentConfirmed(RepeatIndicator_presence=0, - BearerCapability_presence=0, - BearerCapability_presence1=0, - Cause_presence=0): - """CC-ESTABLISHMENT CONFIRMED Section 9.3.17b""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x6) # 00000110 - packet = a / b - if RepeatIndicator_presence is 1: - c = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / c - if BearerCapability_presence is 1: - d = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / d - if BearerCapability_presence1 is 1: - e = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / e - if Cause_presence is 1: - f = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / f - return packet - - -# Network to MS -def releaseNetToMs(): - """RELEASE Section 9.3.18.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x2d) # 00101101 - c = CauseHdr(ieiC=0x08, eightBitC=0x0) - d = CauseHdr(ieiC=0x08, eightBitC=0x0) - e = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - f = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = a / b / c / d / e / f - return packet - - -def releaseMsToNet(Cause_presence=0, Cause_presence1=0, - Facility_presence=0, UserUser_presence=0, - SsVersionIndicator_presence=0): - """RELEASE Section 9.3.18.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x2d) # 00101101 - packet = a / b - if Cause_presence is 1: - c = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / c - if Cause_presence1 is 1: - d = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / d - if Facility_presence is 1: - e = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / e - if UserUser_presence is 1: - f = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / f - if SsVersionIndicator_presence is 1: - g = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / g - return packet - - -# Network to MS -def recall(): - """RECALL Section 9.3.18a""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0xb) # 00001011 - c = RecallType() - d = Facility() - packet = a / b / c / d - return packet - - -# Network to MS -def releaseCompleteNetToMs(Cause_presence=0, Facility_presence=0, - UserUser_presence=0): - """RELEASE COMPLETE Section 9.3.19.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x2a) # 00101010 - packet = a / b - if Cause_presence is 1: - c = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / c - if Facility_presence is 1: - d = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / d - if UserUser_presence is 1: - e = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / e - return packet - - -def releaseCompleteMsToNet(Cause_presence=0, Facility_presence=0, - UserUser_presence=0, SsVersionIndicator_presence=0): - """RELEASE COMPLETE Section 9.3.19.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x2a) # 00101010 - packet = a / b - if Cause_presence is 1: - c = CauseHdr(ieiC=0x08, eightBitC=0x0) - packet = packet / c - if Facility_presence is 1: - d = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / d - if UserUser_presence is 1: - e = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / e - if SsVersionIndicator_presence is 1: - f = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / f - return packet - - -def retrieve(): - """RETRIEVE Section 9.3.20""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1c) # 00011100 - packet = a / b - return packet - - -# Network to MS -def retrieveAcknowledge(): - """RETRIEVE ACKNOWLEDGE Section 9.3.21""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1d) # 00011101 - packet = a / b - return packet - - -# Network to MS -def retrieveReject(): - """RETRIEVE REJECT Section 9.3.22""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1e) # 00011110 - c = Cause() - packet = a / b / c - return packet - - -# Network to MS -def setupMobileTerminated(RepeatIndicator_presence=0, - BearerCapability_presence=0, - BearerCapability_presence1=0, - Facility_presence=0, ProgressIndicator_presence=0, - Signal_presence=0, - CallingPartyBcdNumber_presence=0, - CallingPartySubaddress_presence=0, - CalledPartyBcdNumber_presence=0, - CalledPartySubaddress_presence=0, -# RecallType_presence=0, - RedirectingPartyBcdNumber_presence=0, - RedirectingPartySubaddress_presence=0, - RepeatIndicator_presence1=0, - LowLayerCompatibility_presence=0, - LowLayerCompatibility_presence1=0, - RepeatIndicator_presence2=0, - HighLayerCompatibility_presence=0, - HighLayerCompatibility_presence1=0, - UserUser_presence=0, PriorityLevel_presence=0, - AlertingPattern_presence=0): - """SETUP Section 9.3.23.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x5) # 00000101 - packet = a / b - if RepeatIndicator_presence is 1: - c = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / c - if BearerCapability_presence is 1: - d = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / d - if BearerCapability_presence1 is 1: - e = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / e - if Facility_presence is 1: - f = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / f - if ProgressIndicator_presence is 1: - g = ProgressIndicatorHdr(ieiPI=0x1E, eightBitPI=0x0) - packet = packet / g - if Signal_presence is 1: - h = SignalHdr(ieiS=0x34, eightBitS=0x0) - packet = packet / h - if CallingPartyBcdNumber_presence is 1: - i = CallingPartyBcdNumberHdr(ieiCPBN=0x5C, eightBitCPBN=0x0) - packet = packet / i - if CallingPartySubaddress_presence is 1: - j = CallingPartySubaddressHdr(ieiCPS=0x5D, eightBitCPS=0x0) - packet = packet / j - if CalledPartyBcdNumber_presence is 1: - k = CalledPartyBcdNumberHdr(ieiCPBN=0x5E, eightBitCPBN=0x0) - packet = packet / k - if CalledPartySubaddress_presence is 1: - l = CalledPartySubaddressHdr(ieiCPS=0x6D, eightBitCPS=0x0) - packet = packet / l - if RedirectingPartyBcdNumber_presence is 1: - n = RedirectingPartyBcdNumberHdr(ieiRPBN=0x74, eightBitRPBN=0x0) - packet = packet / n - if RedirectingPartySubaddress_presence is 1: - m = RedirectingPartySubaddress_presence(ieiRPBN=0x75, eightBitRPBN=0x0) - packet = packet / m - if RepeatIndicator_presence1 is 1: - o = RepeatIndicatorHdr(ieiRI=0xD0, eightBitRI=0x0) - packet = packet / o - if LowLayerCompatibility_presence is 1: - p = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / p - if LowLayerCompatibility_presence1 is 1: - q = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / q - if RepeatIndicator_presence2 is 1: - r = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / r - if HighLayerCompatibility_presence is 1: - s = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / s - if HighLayerCompatibility_presence1 is 1: - t = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / t - if UserUser_presence is 1: - u = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / u - if PriorityLevel_presence is 1: - v = PriorityLevelHdr(ieiPL=0x8, eightBitPL=0x0) - packet = packet / v - if AlertingPattern_presence is 1: - w = AlertingPatternHdr(ieiAP=0x19, eightBitAP=0x0) - packet = packet / w - return packet - - -def setupMobileOriginated(RepeatIndicator_presence=0, - BearerCapability_presence=0, - BearerCapability_presence1=0, - Facility_presence=0, - CallingPartySubaddress_presence=0, - CalledPartyBcdNumber_presence=0, - CalledPartySubaddress_presence=0, - RepeatIndicator_presence1=0, - LowLayerCompatibility_presence=0, - LowLayerCompatibility_presence1=0, - RepeatIndicator_presence2=0, - HighLayerCompatibility_presence=0, - HighLayerCompatibility_presence1=0, - UserUser_presence=0, SsVersionIndicator_presence=0, - ClirSuppression_presence=0, - ClirInvocation_presence=0, - CallControlCapabilities_presence=0, - Facility_presence1=0, - Facility_presence2=0): - """SETUP Section 9.3.23.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x5) # 00000101 - packet = a / b - if RepeatIndicator_presence is 1: - c = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / c - if BearerCapability_presence is 1: - d = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / d - if BearerCapability_presence1 is 1: - e = BearerCapabilityHdr(ieiBC=0x04, eightBitBC=0x0) - packet = packet / e - if Facility_presence is 1: - f = FacilityHdr(ieiF=0x1C, eightBitF=0x0) - packet = packet / f - if CallingPartySubaddress_presence is 1: - g = CallingPartySubaddressHdr(ieiCPS=0x5D, eightBitCPS=0x0) - packet = packet / g - if CalledPartyBcdNumber_presence is 1: - h = CalledPartyBcdNumberHdr(ieiCPBN=0x5E, eightBitCPBN=0x0) - packet = packet / h - if CalledPartySubaddress_presence is 1: - i = CalledPartySubaddressHdr(ieiCPS=0x6D, eightBitCPS=0x0) - packet = packet / i - if RepeatIndicator_presence1 is 1: - j = RepeatIndicatorHdr(ieiRI=0xD0, eightBitRI=0x0) - packet = packet / j - if LowLayerCompatibility_presence is 1: - k = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / k - if LowLayerCompatibility_presence1 is 1: - l = LowLayerCompatibilityHdr(ieiLLC=0x7C, eightBitLLC=0x0) - packet = packet / l - if RepeatIndicator_presence2 is 1: - m = RepeatIndicatorHdr(ieiRI=0xD, eightBitRI=0x0) - packet = packet / m - if HighLayerCompatibility_presence is 1: - n = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / n - if HighLayerCompatibility_presence1 is 1: - o = HighLayerCompatibilityHdr(ieiHLC=0x7D, eightBitHLC=0x0) - packet = packet / o - if UserUser_presence is 1: - p = UserUserHdr(ieiUU=0x7E, eightBitUU=0x0) - packet = packet / p - if SsVersionIndicator_presence is 1: - q = SsVersionIndicatorHdr(ieiSVI=0x7F, eightBitSVI=0x0) - packet = packet / q - if ClirSuppression_presence is 1: - r = ClirSuppressionHdr(ieiCS=0xA1, eightBitCS=0x0) - packet = packet / r - if ClirInvocation_presence is 1: - s = ClirInvocationHdr(ieiCI=0xA2, eightBitCI=0x0) - packet = packet / s - if CallControlCapabilities_presence is 1: - t = CallControlCapabilitiesHdr(ieiCCC=0x15, eightBitCCC=0x0) - packet = packet / t - if Facility_presence1 is 1: - u = FacilityHdr(ieiF=0x1D, eightBitF=0x0) - packet = packet / u - if Facility_presence2 is 1: - v = FacilityHdr(ieiF=0x1B, eightBitF=0x0) - packet = packet / v - return packet - - -def startCc(CallControlCapabilities_presence=0): - """START CC Section 9.3.23a""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x9) # 00001001 - packet = a / b - if CallControlCapabilities_presence is 1: - c = CallControlCapabilitiesHdr(ieiCCC=0x15, eightBitCCC=0x0) - packet = paclet / c - return packet - - -def startDtmf(): - """START DTMF Section 9.3.24""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x35) # 00110101 - c = KeypadFacilityHdr(ieiKF=0x2C, eightBitKF=0x0) - packet = a / b / c - return packet - - -# Network to MS -def startDtmfAcknowledge(): - """START DTMF ACKNOWLEDGE Section 9.3.25""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x32) # 00110010 - c = KeypadFacilityHdr(ieiKF=0x2C, eightBitKF=0x0) - packet = a / b / c - return packet - - -# Network to MS -def startDtmfReject(): - """ START DTMF REJECT Section 9.3.26""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x37) # 00110111 - c = Cause() - packet = a / b / c - return packet - - -def status(AuxiliaryStates_presence=0): - """STATUS Section 9.3.27""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x3d) # 00111101 - c = Cause() - d = CallState() - packet = a / b / c / d - if AuxiliaryStates_presence is 1: - e = AuxiliaryStatesHdr(ieiAS=0x24, eightBitAS=0x0) - packet = packet / e - return packet - - -def statusEnquiry(): - """STATUS ENQUIRY Section 9.3.28""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x34) # 00110100 - packet = a / b - return packet - - -def stopDtmf(): - """STOP DTMF Section 9.3.29""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x31) # 00110001 - packet = a / b - return packet - - -# Network to MS -def stopDtmfAcknowledge(): - """STOP DTMF ACKNOWLEDGE Section 9.3.30""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x32) # 00110010 - packet = a / b - return packet - - -def userInformation(MoreData_presence=0): - """USER INFORMATION Section 9.3.31""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x20) # 000100000 - c = UserUser() - packet = a / b / c - if MoreData_presence is 1: - d = MoreDataHdr(ieiMD=0xA0, eightBitMD=0x0) - packet = packet / d - return packet - -# -# 9.4 GPRS Mobility Management Messages -# - - -def attachRequest(PTmsiSignature_presence=0, GprsTimer_presence=0, - TmsiStatus_presence=0): - """ATTACH REQUEST Section 9.4.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1) # 0000001 - c = MsNetworkCapability() - d = AttachTypeAndCiphKeySeqNr() - f = DrxParameter() - g = MobileId() - h = RoutingAreaIdentification() - i = MsRadioAccessCapability() - packet = a / b / c / d / f / g / h / i - if PTmsiSignature_presence is 1: - j = PTmsiSignature(ieiPTS=0x19) - packet = packet / j - if GprsTimer_presence is 1: - k = GprsTimer(ieiGT=0x17) - packet = packet / k - if TmsiStatus_presence is 1: - l = TmsiStatus(ieiTS=0x9) - packet = packet / l - return packet - - -def attachAccept(PTmsiSignature_presence=0, GprsTimer_presence=0, - MobileId_presence=0, MobileId_presence1=0, - GmmCause_presence=0): - """ATTACH ACCEPT Section 9.4.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x2) # 00000010 - c = AttachResult() - d = ForceToStandby() - e = GprsTimer() - f = RadioPriorityAndSpareHalfOctets() - h = RoutingAreaIdentification() - packet = a / b / c / d / e / f / h - if PTmsiSignature_presence is 1: - i = PTmsiSignature(ieiPTS=0x19) - packet = packet / i - if GprsTimer_presence is 1: - j = GprsTimer(ieiGT=0x17) - packet = packet / j - if MobileId_presence is 1: - k = MobileIdHdr(ieiMI=0x18, eightBitMI=0x0) - packet = packet / k - if MobileId_presence1 is 1: - l = MobileIdHdr(ieiMI=0x23, eightBitMI=0x0) - packet = packet / l - if GmmCause_presence is 1: - m = GmmCause(ieiGC=0x25) - packet = packet / m - return packet - - -def attachComplete(): - """ATTACH COMPLETE Section 9.4.3""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x3) # 00000011 - packet = a / b - return packet - - -def attachReject(): - """ATTACH REJECT Section 9.4.4""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x1) # 00000001 - c = GmmCause() - packet = a / b / c - return packet - - -def detachRequest(GmmCause_presence=0): - """DETACH REQUEST Section 9.4.5""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x5) # 00000101 - c = DetachTypeAndForceToStandby() - packet = a / b / c - if GmmCause_presence is 1: - e = GmmCause(ieiGC=0x25) - packet = packet / e - return packet - - -def detachRequestMsOriginating(): - """DETACH REQUEST Section 9.4.5.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x5) # 00000101 - c = DetachTypeAndSpareHalfOctets() - packet = a / b / c - return packet - - -def detachAcceptMsTerminated(): - """DETACH ACCEPT Section 9.4.6.1""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x6) # 00000110 - packet = a / b - return packet - - -def detachAcceptMsOriginating(): - """DETACH ACCEPT Section 9.4.6.2""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x6) # 00000110 - c = ForceToStandbyAndSpareHalfOctets() - packet = a / b / c - return packet - - -def ptmsiReallocationCommand(PTmsiSignature_presence=0): - """P-TMSI REALLOCATION COMMAND Section 9.4.7""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x10) # 00010000 - c = MobileId() - d = RoutingAreaIdentification() - e = ForceToStandbyAndSpareHalfOctets() - packet = a / b / c / d / e - if PTmsiSignature_presence is 1: - g = PTmsiSignature(ieiPTS=0x19) - packet = packet / g - return packet - - -def ptmsiReallocationComplete(): - """P-TMSI REALLOCATION COMPLETE Section 9.4.8""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x11) # 00010001 - packet = a / b - return packet - - -def authenticationAndCipheringRequest( - AuthenticationParameterRAND_presence=0, - CiphKeySeqNr_presence=0): - """AUTHENTICATION AND CIPHERING REQUEST Section 9.4.9""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x12) # 00010010 - d = CipheringAlgorithmAndImeisvRequest() - e = ForceToStandbyAndAcReferenceNumber() - packet = a / b / d / e - if AuthenticationParameterRAND_presence is 1: - g = AuthenticationParameterRAND(ieiAPR=0x21) - packet = packet / g - if CiphKeySeqNr_presence is 1: - h = CiphKeySeqNrHdr(ieiCKSN=0x08, eightBitCKSN=0x0) - packet = packet / h - return packet - - -def authenticationAndCipheringResponse( - AuthenticationParameterSRES_presence=0, - MobileId_presence=0): - """AUTHENTICATION AND CIPHERING RESPONSE Section 9.4.10""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x13) # 00010011 - c = AcReferenceNumberAndSpareHalfOctets() - packet = a / b / c - if AuthenticationParameterSRES_presence is 1: - e = AuthenticationParameterSRES(ieiAPS=0x22) - packet = packet / e - if MobileId_presence is 1: - f = MobileIdHdr(ieiMI=0x23, eightBitMI=0x0) - packet = packet / f - return packet - - -def authenticationAndCipheringReject(): - """AUTHENTICATION AND CIPHERING REJECT Section 9.4.11""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x14) # 00010100 - packet = a / b - return packet - - -def identityRequest(): - """IDENTITY REQUEST Section 9.4.12""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x15) # 00010101 - c = IdentityType2AndforceToStandby() - packet = a / b / c - return packet - - -def identityResponse(): - """IDENTITY RESPONSE Section 9.4.13""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x16) # 00010110 - c = MobileId() - packet = a / b / c - return packet - - -def routingAreaUpdateRequest(PTmsiSignature_presence=0, - GprsTimer_presence=0, - DrxParameter_presence=0, - TmsiStatus_presence=0): - """ROUTING AREA UPDATE REQUEST Section 9.4.14""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x8) # 00001000 - c = UpdateTypeAndCiphKeySeqNr() - e = RoutingAreaIdentification() - f = MsNetworkCapability() - packet = a / b / c / e / f - if PTmsiSignature_presence is 1: - g = PTmsiSignature(ieiPTS=0x19) - packet = packet / g - if GprsTimer_presence is 1: - h = GprsTimer(ieiGT=0x17) - packet = packet / h - if DrxParameter_presence is 1: - i = DrxParameter(ieiDP=0x27) - packet = packet / i - if TmsiStatus_presence is 1: - j = TmsiStatus(ieiTS=0x9) - packet = packet / j - return packet - - -def routingAreaUpdateAccept(PTmsiSignature_presence=0, - MobileId_presence=0, MobileId_presence1=0, - ReceiveNpduNumbersList_presence=0, - GprsTimer_presence=0, GmmCause_presence=0): - """ROUTING AREA UPDATE ACCEPT Section 9.4.15""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x9) # 00001001 - c = ForceToStandbyAndUpdateResult() - e = GprsTimer() - f = RoutingAreaIdentification() - packet = a / b / c / e / f - if PTmsiSignature_presence is 1: - g = PTmsiSignature(ieiPTS=0x19) - packet = packet / g - if MobileId_presence is 1: - h = MobileIdHdr(ieiMI=0x18, eightBitMI=0x0) - packet = packet / h - if MobileId_presence1 is 1: - i = MobileIdHdr(ieiMI=0x23, eightBitMI=0x0) - packet = packet / i - if ReceiveNpduNumbersList_presence is 1: - j = ReceiveNpduNumbersList(ieiRNNL=0x26) - packet = packet / j - if GprsTimer_presence is 1: - k = GprsTimer(ieiGT=0x17) - packet = packet / k - if GmmCause_presence is 1: - l = GmmCause(ieiGC=0x25) - packet = packet / l - return packet - - -def routingAreaUpdateComplete(ReceiveNpduNumbersList_presence=0): - """ROUTING AREA UPDATE COMPLETE Section 9.4.16""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0xa) # 00001010 - packet = a / b - if ReceiveNpduNumbersList_presence is 1: - c = ReceiveNpduNumbersList(ieiRNNL=0x26) - packet = packet / c - return packet - - -def routingAreaUpdateReject(): - """ROUTING AREA UPDATE REJECT Section 9.4.17""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0xb) # 00001011 - c = GmmCause() - d = ForceToStandbyAndSpareHalfOctets() - packet = a / b / c / d - return packet - - -def gmmStatus(): - """GMM STATUS Section 9.4.18""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x20) # 00100000 - c = GmmCause() - packet = a / b / c - return packet - - -def gmmInformation(NetworkName_presence=0, NetworkName_presence1=0, - TimeZone_presence=0, TimeZoneAndTime_presence=0, - LsaIdentifier_presence=0): - """GMM INFORMATION Section 9.4.19""" - a = TpPd(pd=0x3) - b = MessageType(mesType=0x21) # 00100001 - packet = a / b - if NetworkName_presence is 1: - c = NetworkNameHdr(ieiNN=0x43, eightBitNN=0x0) - packet = packet / c - if NetworkName_presence1 is 1: - d = NetworkNameHdr(ieiNN=0x45, eightBitNN=0x0) - packet = packet / d - if TimeZone_presence is 1: - e = TimeZoneHdr(ieiTZ=0x46, eightBitTZ=0x0) - packet = packet / e - if TimeZoneAndTime_presence is 1: - f = TimeZoneAndTimeHdr(ieiTZAT=0x47, eightBitTZAT=0x0) - packet = packet / f - if LsaIdentifier_presence is 1: - g = LsaIdentifierHdr(ieiLI=0x48, eightBitLI=0x0) - packet = packet / g - return packet - -# -# 9.5 GPRS Session Management Messages -# - - -def activatePdpContextRequest(AccessPointName_presence=0, - ProtocolConfigurationOptions_presence=0): - """ACTIVATE PDP CONTEXT REQUEST Section 9.5.1""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x41) # 01000001 - c = NetworkServiceAccessPointIdentifier() - d = LlcServiceAccessPointIdentifier() - e = QualityOfService() - f = PacketDataProtocolAddress() - packet = a / b / c / d / e / f - if AccessPointName_presence is 1: - g = AccessPointName(ieiAPN=0x28) - packet = packet / g - if ProtocolConfigurationOptions_presence is 1: - h = ProtocolConfigurationOptions(ieiPCO=0x27) - packet = packet / h - return packet - - -def activatePdpContextAccept(PacketDataProtocolAddress_presence=0, - ProtocolConfigurationOptions_presence=0): - """ACTIVATE PDP CONTEXT ACCEPT Section 9.5.2""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x42) # 01000010 - c = LlcServiceAccessPointIdentifier() - d = QualityOfService() - e = RadioPriorityAndSpareHalfOctets() - packet = a / b / c / d / e - if PacketDataProtocolAddress_presence is 1: - f = PacketDataProtocolAddress(ieiPDPA=0x2B) - packet = packet / f - if ProtocolConfigurationOptions_presence is 1: - g = ProtocolConfigurationOptions(ieiPCO=0x27) - packet = packet / g - return packet - - -def activatePdpContextReject(ProtocolConfigurationOptions_presence=0): - """ACTIVATE PDP CONTEXT REJECT Section 9.5.3""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x43) # 01000011 - c = SmCause() - packet = a / b / c - if ProtocolConfigurationOptions_presence is 1: - d = ProtocolConfigurationOptions(ieiPCO=0x27) - packet = packet / d - return packet - - -def requestPdpContextActivation(AccessPointName_presence=0): - """REQUEST PDP CONTEXT ACTIVATION Section 9.5.4""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x44) # 01000100 - c = PacketDataProtocolAddress() - packet = a / b / c - if AccessPointName_presence is 1: - d = AccessPointName(ieiAPN=0x28) - packet = packet / d - return packet - - -def requestPdpContextActivationReject(): - """REQUEST PDP CONTEXT ACTIVATION REJECT Section 9.5.5""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x45) # 01000101 - c = SmCause() - packet = a / b / c - return packet - - -def modifyPdpContextRequest(): - """MODIFY PDP CONTEXT REQUEST Section 9.5.6""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x48) # 01001000 - c = RadioPriorityAndSpareHalfOctets() - d = LlcServiceAccessPointIdentifier() - e = QualityOfService() - packet = a / b / c / d / e - return packet - - -def modifyPdpContextAccept(): - """MODIFY PDP CONTEXT ACCEPT Section 9.5.7""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x45) # 01000101 - packet = a / b - return packet - - -def deactivatePdpContextRequest(): - """DEACTIVATE PDP CONTEXT REQUEST Section 9.5.8""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x46) # 01000110 - c = SmCause() - packet = a / b / c - return packet - - -def deactivatePdpContextAccept(): - """DEACTIVATE PDP CONTEXT ACCEPT Section 9.5.9""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x47) # 01000111 - packet = a / b - return packet - - -def activateAaPdpContextRequest(AccessPointName_presence=0, - ProtocolConfigurationOptions_presence=0, - GprsTimer_presence=0): - """ACTIVATE AA PDP CONTEXT REQUEST Section 9.5.10""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x50) # 01010000 - c = NetworkServiceAccessPointIdentifier() - d = LlcServiceAccessPointIdentifier() - e = QualityOfService() - f = PacketDataProtocolAddress() - packet = a / b / c / d / e / f - if AccessPointName_presence is 1: - g = AccessPointName(ieiAPN=0x28) - packet = packet / g - if ProtocolConfigurationOptions_presence is 1: - h = ProtocolConfigurationOptions(ieiPCO=0x27) - packet = packet / h - if GprsTimer_presence is 1: - i = GprsTimer(ieiGT=0x29) - packet = packet / i - return packet - - -def activateAaPdpContextAccept(ProtocolConfigurationOptions_presence=0, - GprsTimer_presence=0): - """ACTIVATE AA PDP CONTEXT ACCEPT Section 9.5.11""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x51) # 01010001 - c = LlcServiceAccessPointIdentifier() - d = QualityOfService() - e = MobileId() - f = PacketDataProtocolAddress() - g = RadioPriorityAndSpareHalfOctets() - packet = a / b / c / d / e / f / g - if ProtocolConfigurationOptions_presence is 1: - i = ProtocolConfigurationOptions(ieiPCO=0x27) - packet = packet / i - if GprsTimer_presence is 1: - j = GprsTimer(ieiGT=0x29) - packet = packet / j - return packet - - -def activateAaPdpContextReject(ProtocolConfigurationOptions_presence=0): - """ACTIVATE AA PDP CONTEXT REJECT Section 9.5.12""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x52) # 01010010 - c = SmCause() - packet = a / b / c - if ProtocolConfigurationOptions_presence is 1: - d = ProtocolConfigurationOptions(ieiPCO=0x27) - packet = packet / d - return packet - - -def deactivateAaPdpContextRequest(): - """DEACTIVATE AA PDP CONTEXT REQUEST Section 9.5.13""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x53) # 01010011 - c = AaDeactivationCauseAndSpareHalfOctets() - packet = a / b / c - return packet - - -def deactivateAaPdpContextAccept(): - """DEACTIVATE AA PDP CONTEXT ACCEPT Section 9.5.14""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x54) # 01010100 - packet = a / b - return packet - - -def smStatus(): - """SM STATUS Section 9.5.15""" - a = TpPd(pd=0x8) - b = MessageType(mesType=0x55) # 01010101 - c = SmCause() - packet = a / b / c - return packet - - -# ============================================# -# Information Elements contents (Section 10) # -# =========================================== # - -#### -# This section contains the elements we need to build the messages -#### - -# -# Common information elements: -# -class CellIdentityHdr(Packet): - """ Cell identity Section 10.5.1.1 """ - name = "Cell Identity" - fields_desc = [ - BitField("eightBitCI", None, 1), - XBitField("ieiCI", None, 7), - ByteField("ciValue1", 0x0), - ByteField("ciValue2", 0x0) - ] - - -class CiphKeySeqNrHdr(Packet): - """ Ciphering Key Sequence Number Section 10.5.1.2 """ - name = "Cipher Key Sequence Number" - fields_desc = [ - XBitField("ieiCKSN", None, 4), - BitField("spare", 0x0, 1), - BitField("keySeq", 0x0, 3) - ] - - -# Fix 1/2 len problem -class CiphKeySeqNrAndSpareHalfOctets(Packet): - name = "Cipher Key Sequence Number and Spare Half Octets" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("keySeq", 0x0, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -# Fix 1/2 len problem -class CiphKeySeqNrAndMacModeAndChannelCodingRequest(Packet): - name = "Cipher Key Sequence Number and Mac Mode And Channel Coding Request" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("keySeq", 0x0, 3), - BitField("macMode", 0x0, 2), - BitField("cs", 0x0, 2) - ] - - -class LocalAreaIdHdr(Packet): - """ Local Area Identification Section 10.5.1.3 """ - name = "Location Area Identification" - fields_desc = [ - BitField("eightBitLAI", None, 1), - XBitField("ieiLAI", None, 7), - BitField("mccDigit2", 0x0, 4), - BitField("mccDigit1", 0x0, 4), - BitField("mncDigit3", 0x0, 4), - BitField("mccDigit3", 0x0, 4), - BitField("mncDigit2", 0x0, 4), - BitField("mncDigit1", 0x0, 4), - ByteField("lac1", 0x0), - ByteField("lac2", 0x0) - ] -# -# The Mobile Identity is a type 4 information element with a minimum -# length of 3 octet and 11 octets length maximal. -# - - -# len 3 - 11 -class MobileIdHdr(Packet): - """ Mobile Identity Section 10.5.1.4 """ - name = "Mobile Identity" - fields_desc = [ - BitField("eightBitMI", 0x0, 1), - XBitField("ieiMI", 0x0, 7), - - XByteField("lengthMI", None), - - BitField("idDigit1", 0x0, 4), - BitField("oddEven", 0x0, 1), - BitField("typeOfId", 0x0, 3), - - BitField("idDigit2_1", None, 4), # optional - BitField("idDigit2", None, 4), - - BitField("idDigit3_1", None, 4), - BitField("idDigit3", None, 4), - - BitField("idDigit4_1", None, 4), - BitField("idDigit4", None, 4), - - BitField("idDigit5_1", None, 4), - BitField("idDigit5", None, 4), - - BitField("idDigit6_1", None, 4), - BitField("idDigit6", None, 4), - BitField("idDigit7_1", None, 4), - BitField("idDigit7", None, 4), - BitField("idDigit8_1", None, 4), - BitField("idDigit8", None, 4), - BitField("idDigit9_1", None, 4), - BitField("idDigit9", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i, None)) # this list holds the values of -# the variables, the INTERESSTING value! - res = adapt(3, 11, a, self.fields_desc) - if self.lengthMI is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - print(repr(p)) - return p + pay - - -class MobileStationClassmark1Hdr(Packet): - """ Mobile Station Classmark 1 Section 10.5.1.5 """ - name = "Mobile Station Classmark 1" - fields_desc = [ - BitField("eightBitiMSC1", None, 1), - XBitField("ieiMSC1", None, 7), - BitField("spare", 0x0, 1), - BitField("revisionLvl", 0x0, 2), - BitField("esInd", 0x0, 1), - BitField("a51", 0x0, 1), - BitField("rfPowerCap", 0x0, 3) - ] - - -class MobileStationClassmark2Hdr(Packet): - """ Mobile Station Classmark 2 Section 10.5.1.6 """ - name = "Mobile Station Classmark 2" - fields_desc = [ - BitField("eightBitMSC2", None, 1), - XBitField("ieiMSC2", None, 7), - XByteField("lengthMSC2", 0x3), - BitField("spare", 0x0, 1), - BitField("revisionLvl", 0x0, 2), - BitField("esInd", 0x0, 1), - BitField("a51", 0x0, 1), - BitField("rfPowerCap", 0x0, 3), - BitField("spare1", 0x0, 1), - BitField("psCap", 0x0, 1), - BitField("ssScreenInd", 0x0, 2), - BitField("smCaPabi", 0x0, 1), - BitField("vbs", 0x0, 1), - BitField("vgcs", 0x0, 1), - BitField("fc", 0x0, 1), - BitField("cm3", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("lcsvaCap", 0x0, 1), - BitField("spare3", 0x0, 1), - BitField("soLsa", 0x0, 1), - BitField("cmsp", 0x0, 1), - BitField("a53", 0x0, 1), - BitField("a52", 0x0, 1) - ] - - -# len max 14 -class MobileStationClassmark3(Packet): - """ Mobile Station Classmark 3 Section 10.5.1.7 """ - name = "Mobile Station Classmark 3" - fields_desc = [ - # FIXME - ByteField("ieiMSC3", 0x0), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0) - ] - - -class SpareHalfOctets(Packet): - """ Spare Half Octet Section 10.5.1.8 """ - name = "Spare Half Octet" - fields_desc = [ - BitField("filler", None, 4), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class DescriptiveGroupOrBroadcastCallReferenceHdr(Packet): - """ Descriptive group or broadcast call reference Section 10.5.1.9 """ - name = "Descriptive Group or Broadcast Call Reference" - fields_desc = [ - BitField("eightBitDGOBCR", None, 1), - XBitField("ieiDGOBCR", None, 7), - BitField("binCallRef", 0x0, 27), - BitField("sf", 0x0, 1), - BitField("fa", 0x0, 1), - BitField("callPrio", 0x0, 3), - BitField("cipherInfo", 0x0, 4), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("spare3", 0x0, 1), - BitField("spare4", 0x0, 1) - ] - - -class GroupCipherKeyNumber(Packet): - """ Group Cipher Key Number reference Section 10.5.1.10 """ - name = "Group Cipher Key Number" - fields_desc = [ - XBitField("ieiGCKN", None, 4), - BitField("groupCipher", 0x0, 4) - ] - - -class PdAndSapiHdr(Packet): - """ PD and SAPI $(CCBS)$ Section 10.5.1.10a """ - name = "PD and SAPI $(CCBS)$" - fields_desc = [ - BitField("eightBitPAS", None, 1), - XBitField("ieiPAS", None, 7), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("sapi", 0x0, 2), - BitField("pd", 0x0, 4) - ] - - -class PriorityLevelHdr(Packet): - """ Priority Level Section 10.5.1.11 """ - name = "Priority Level" - fields_desc = [ - XBitField("ieiPL", None, 4), - BitField("spare", 0x0, 1), - BitField("callPrio", 0x0, 3) - ] - -# -# Radio Resource management information elements -# - - -# len 6 to max for L3 message (251) -class BaRangeHdr(Packet): - """ BA Range Section 10.5.2.1a """ - name = "BA Range" - fields_desc = [ - BitField("eightBitBR", None, 1), - XBitField("ieiBR", None, 7), - - XByteField("lengthBR", None), -#error: byte format requires -128 <= number <= 127 - ByteField("nrOfRanges", 0x0), -# # rX = range X -# # L o = Lower H i = higher -# # H p = high Part Lp = low Part - ByteField("r1LoHp", 0x0), - - BitField("r1LoLp", 0x0, 3), - BitField("r1HiHp", 0x0, 5), - - BitField("r1HiLp", 0x0, 4), - BitField("r2LoHp", 0x0, 4), - # optional - BitField("r2LoLp", None, 5), - BitField("r2HiHp", None, 3), - - ByteField("r2HiLp", None), - ByteField("r3LoHp", None), - - BitField("r3LoLp", None, 5), - BitField("r3HiHp", None, 3), - - ByteField("r3HiLp", None), - ByteField("r4LoHp", None), - - BitField("r4LoLp", None, 5), - BitField("r4HiHp", None, 3), - ByteField("r4HiLp", None), - ByteField("r5LoHp", None), - - BitField("r5LoLp", None, 5), - BitField("r5HiHp", None, 3), - ByteField("r5HiLp", None), - ByteField("r6LoHp", None), - - BitField("r6LoLp", None, 5), - BitField("r6HiHp", None, 3), - ByteField("r6HiLp", None), - ByteField("r7LoHp", None), - - BitField("r7LoLp", None, 5), - BitField("r7HiHp", None, 3), - ByteField("r7HiLp", None), - ByteField("r8LoHp", None), - - BitField("r8LoLp", None, 5), - BitField("r8HiHp", None, 3), - ByteField("r8HiLp", None), - ByteField("r9LoHp", None), - - BitField("r9LoLp", None, 5), - BitField("r9HiHp", None, 3), - ByteField("r9HiLp", None), - ByteField("r10LoHp", None), - - BitField("r10LoLp", None, 5), - BitField("r10HiHp", None, 3), - ByteField("r10HiLp", None), - ByteField("r11LoHp", None), - - BitField("r11LoLp", None, 5), - BitField("r11HiHp", None, 3), - ByteField("r11HiLp", None), - ByteField("r12LoHp", None), - - BitField("r12LoLp", None, 5), - BitField("r12HiHp", None, 3), - ByteField("r12HiLp", None), - ByteField("r13LoHp", None), - - BitField("r13LoLp", None, 5), - BitField("r13HiHp", None, 3), - ByteField("r13HiLp", None), - ByteField("r14LoHp", None), - - BitField("r14LoLp", None, 5), - BitField("r14HiHp", None, 3), - ByteField("r14HiLp", None), - ByteField("r15LoHp", None), - - BitField("r15LoLp", None, 5), - BitField("r15HiHp", None, 3), - ByteField("r15HiLp", None), - ByteField("r16LoHp", None), - - BitField("r16LoLp", None, 5), - BitField("r16HiHp", None, 3), - ByteField("r16HiLp", None), - ByteField("r17LoHp", None), - - BitField("r17LoLp", None, 5), - BitField("r17HiHp", None, 3), - ByteField("r17HiLp", None), - ByteField("r18LoHp", None), - - BitField("r18LoLp", None, 5), - BitField("r18HiHp", None, 3), - ByteField("r18HiLp", None), - ByteField("r19LoHp", None), - - BitField("r19LoLp", None, 5), - BitField("r19HiHp", None, 3), - ByteField("r19HiLp", None), - ByteField("r20LoHp", None), - - BitField("r20LoLp", None, 5), - BitField("r20HiHp", None, 3), - ByteField("r20HiLp", None), - ByteField("r21LoHp", None), - - BitField("r21LoLp", None, 5), - BitField("r21HiHp", None, 3), - ByteField("r21HiLp", None), - ByteField("r22LoHp", None), - - BitField("r22LoLp", None, 5), - BitField("r22HiHp", None, 3), - ByteField("r22HiLp", None), - ByteField("r23LoHp", None), - - BitField("r23LoLp", None, 5), - BitField("r23HiHp", None, 3), - ByteField("r23HiLp", None), - ByteField("r24LoHp", None), - - BitField("r24LoLp", None, 5), - BitField("r24HiHp", None, 3), - ByteField("r24HiLp", None), - ByteField("r25LoHp", None), - - BitField("r25LoLp", None, 5), - BitField("r25HiHp", None, 3), - ByteField("r25HiLp", None), - ByteField("r26LoHp", None), - - BitField("r26LoLp", None, 5), - BitField("r26HiHp", None, 3), - ByteField("r26HiLp", None), - ByteField("r27LoHp", None), - - BitField("r27LoLp", None, 5), - BitField("r27HiHp", None, 3), - ByteField("r27HiLp", None), - ByteField("r28LoHp", None), - - BitField("r28LoLp", None, 5), - BitField("r28HiHp", None, 3), - ByteField("r28HiLp", None), - ByteField("r29LoHp", None), - - BitField("r29LoLp", None, 5), - BitField("r29HiHp", None, 3), - ByteField("r29HiLp", None), - ByteField("r30LoHp", None), - - BitField("r30LoLp", None, 5), - BitField("r30HiHp", None, 3), - ByteField("r30HiLp", None), - ByteField("r31LoHp", None), - - BitField("r31LoLp", None, 5), - BitField("r31HiHp", None, 3), - ByteField("r31HiLp", None), - ByteField("r32LoHp", None), - - BitField("r32LoLp", None, 5), - BitField("r32HiHp", None, 3), - ByteField("r32HiLp", None), - ByteField("r33LoHp", None), - - BitField("r33LoLp", None, 5), - BitField("r33HiHp", None, 3), - ByteField("r33HiLp", None), - ByteField("r34LoHp", None), - - BitField("r34LoLp", None, 5), - BitField("r34HiHp", None, 3), - ByteField("r34HiLp", None), - ByteField("r35LoHp", None), - - BitField("r35LoLp", None, 5), - BitField("r35HiHp", None, 3), - ByteField("r35HiLp", None), - ByteField("r36LoHp", None), - - BitField("r36LoLp", None, 5), - BitField("r36HiHp", None, 3), - ByteField("r36HiLp", None), - ByteField("r37LoHp", None), - - BitField("r37LoLp", None, 5), - BitField("r37HiHp", None, 3), - ByteField("r37HiLp", None), - ByteField("r38LoHp", None), - - BitField("r38LoLp", None, 5), - BitField("r38HiHp", None, 3), - ByteField("r38HiLp", None), - ByteField("r39LoHp", None), - - BitField("r39LoLp", None, 5), - BitField("r39HiHp", None, 3), - ByteField("r39HiLp", None), - ByteField("r40LoHp", None), - - BitField("r40LoLp", None, 5), - BitField("r40HiHp", None, 3), - ByteField("r40HiLp", None), - ByteField("r41LoHp", None), - - BitField("r41LoLp", None, 5), - BitField("r41HiHp", None, 3), - ByteField("r41HiLp", None), - ByteField("r42LoHp", None), - - BitField("r42LoLp", None, 5), - BitField("r42HiHp", None, 3), - ByteField("r42HiLp", None), - ByteField("r43LoHp", None), - - BitField("r43LoLp", None, 5), - BitField("r43HiHp", None, 3), - ByteField("r43HiLp", None), - ByteField("r44LoHp", None), - - BitField("r44LoLp", None, 5), - BitField("r44HiHp", None, 3), - ByteField("r44HiLp", None), - ByteField("r45LoHp", None), - - BitField("r45LoLp", None, 5), - BitField("r45HiHp", None, 3), - ByteField("r45HiLp", None), - ByteField("r46LoHp", None), - - BitField("r46LoLp", None, 5), - BitField("r46HiHp", None, 3), - ByteField("r46HiLp", None), - ByteField("r47LoHp", None), - - BitField("r47LoLp", None, 5), - BitField("r47HiHp", None, 3), - ByteField("r47HiLp", None), - ByteField("r48LoHp", None), - - BitField("r48LoLp", None, 5), - BitField("r48HiHp", None, 3), - ByteField("r48HiLp", None), - ByteField("r49LoHp", None), - - BitField("r49LoLp", None, 5), - BitField("r49HiHp", None, 3), - ByteField("r49HiLp", None), - ByteField("r50LoHp", None), - - BitField("r50LoLp", None, 5), - BitField("r50HiHp", None, 3), - ByteField("r50HiLp", None), - ByteField("r51LoHp", None), - - BitField("r51LoLp", None, 5), - BitField("r51HiHp", None, 3), - ByteField("r51HiLp", None), - ByteField("r52LoHp", None), - - BitField("r52LoLp", None, 5), - BitField("r52HiHp", None, 3), - ByteField("r52HiLp", None), - ByteField("r53LoHp", None), - - BitField("r53LoLp", None, 5), - BitField("r53HiHp", None, 3), - ByteField("r53HiLp", None), - ByteField("r54LoHp", None), - - BitField("r54LoLp", None, 5), - BitField("r54HiHp", None, 3), - ByteField("r54HiLp", None), - ByteField("r55LoHp", None), - - BitField("r55LoLp", None, 5), - BitField("r55HiHp", None, 3), - ByteField("r55HiLp", None), - ByteField("r56LoHp", None), - - BitField("r56LoLp", None, 5), - BitField("r56HiHp", None, 3), - ByteField("r56HiLp", None), - ByteField("r57LoHp", None), - - BitField("r57LoLp", None, 5), - BitField("r57HiHp", None, 3), - ByteField("r57HiLp", None), - ByteField("r58LoHp", None), - - BitField("r58LoLp", None, 5), - BitField("r58HiHp", None, 3), - ByteField("r58HiLp", None), - ByteField("r59LoHp", None), - - BitField("r59LoLp", None, 5), - BitField("r59HiHp", None, 3), - ByteField("r59HiLp", None), - ByteField("r60LoHp", None), - - BitField("r60LoLp", None, 5), - BitField("r60HiHp", None, 3), - ByteField("r60HiLp", None), - ByteField("r61LoHp", None), - - BitField("r61LoLp", None, 5), - BitField("r61HiHp", None, 3), - ByteField("r61HiLp", None), - ByteField("r62LoHp", None), - - BitField("r62LoLp", None, 5), - BitField("r62HiHp", None, 3), - ByteField("r62HiLp", None), - ByteField("r63LoHp", None), - - BitField("r63LoLp", None, 5), - BitField("r63HiHp", None, 3), - ByteField("r63HiLp", None), - ByteField("r64LoHp", None), - - BitField("r64LoLp", None, 5), - BitField("r64HiHp", None, 3), - ByteField("r64HiLp", None), - ByteField("r65LoHp", None), - - BitField("r65LoLp", None, 5), - BitField("r65HiHp", None, 3), - ByteField("r65HiLp", None), - ByteField("r66LoHp", None), - - BitField("r66LoLp", None, 5), - BitField("r66HiHp", None, 3), - ByteField("r66HiLp", None), - ByteField("r67LoHp", None), - - BitField("r67LoLp", None, 5), - BitField("r67HiHp", None, 3), - ByteField("r67HiLp", None), - ByteField("r68LoHp", None), - - BitField("r68LoLp", None, 5), - BitField("r68HiHp", None, 3), - ByteField("r68HiLp", None), - ByteField("r69LoHp", None), - - BitField("r69LoLp", None, 5), - BitField("r69HiHp", None, 3), - ByteField("r69HiLp", None), - ByteField("r70LoHp", None), - - BitField("r70LoLp", None, 5), - BitField("r70HiHp", None, 3), - ByteField("r70HiLp", None), - ByteField("r71LoHp", None), - - BitField("r71LoLp", None, 5), - BitField("r71HiHp", None, 3), - ByteField("r71HiLp", None), - ByteField("r72LoHp", None), - - BitField("r72LoLp", None, 5), - BitField("r72HiHp", None, 3), - ByteField("r72HiLp", None), - ByteField("r73LoHp", None), - - BitField("r73LoLp", None, 5), - BitField("r73HiHp", None, 3), - ByteField("r73HiLp", None), - ByteField("r74LoHp", None), - - BitField("r74LoLp", None, 5), - BitField("r74HiHp", None, 3), - ByteField("r74HiLp", None), - ByteField("r75LoHp", None), - - BitField("r75LoLp", None, 5), - BitField("r75HiHp", None, 3), - ByteField("r75HiLp", None), - ByteField("r76LoHp", None), - - BitField("r76LoLp", None, 5), - BitField("r76HiHp", None, 3), - ByteField("r76HiLp", None), - ByteField("r77LoHp", None), - - BitField("r77LoLp", None, 5), - BitField("r77HiHp", None, 3), - ByteField("r77HiLp", None), - ByteField("r78LoHp", None), - - BitField("r78LoLp", None, 5), - BitField("r78HiHp", None, 3), - ByteField("r78HiLp", None), - ByteField("r79LoHp", None), - - BitField("r79LoLp", None, 5), - BitField("r79HiHp", None, 3), - ByteField("r79HiLp", None), - ByteField("r80LoHp", None), - - BitField("r80LoLp", None, 5), - BitField("r80HiHp", None, 3), - ByteField("r80HiLp", None), - ByteField("r81LoHp", None), - - BitField("r81LoLp", None, 5), - BitField("r81HiHp", None, 3), - ByteField("r81HiLp", None), - ByteField("r82LoHp", None), - - BitField("r82LoLp", None, 5), - BitField("r82HiHp", None, 3), - ByteField("r82HiLp", None), - ByteField("r83LoHp", None), - - BitField("r83LoLp", None, 5), - BitField("r83HiHp", None, 3), - ByteField("r83HiLp", None), - ByteField("r84LoHp", None), - - BitField("r84LoLp", None, 5), - BitField("r84HiHp", None, 3), - ByteField("r84HiLp", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - print("i is %s" % (i,)) - aList.append(self.fields_desc[i].name) - print("aList %s" % (len(aList))) - print("self.fields_desc %s" % (len(self.fields_desc))) - for i in aList: - a.append(getattr(self, i)) - res = adapt(6, 251, a, self.fields_desc) - if self.lengthBR is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 3 to max for L3 message (251) -class BaListPrefHdr(Packet): - """ BA List Pref Section 10.5.2.1c """ - name = "BA List Pref" - fields_desc = [ - # FIXME dynamic - BitField("eightBitBLP", None, 1), - XBitField("ieiBLP", None, 7), - - XByteField("lengthBLP", None), - - BitField("fixBit", 0x0, 1), - BitField("rangeLower", 0x0, 10), - BitField("fixBit2", 0x0, 1), - BitField("rangeUpper", 0x0, 10), - BitField("baFreq", 0x0, 10), - BitField("sparePad", 0x0, 8) - ] - - -# len 17 || Have a look at the specs for the field format -# Bit map 0 format -# Range 1024 format -# Range 512 format -# Range 256 format -# Range 128 format -# Variable bit map format -class CellChannelDescriptionHdr(Packet): - """ Cell Channel Description Section 10.5.2.1b """ - name = "Cell Channel Description " - fields_desc = [ - BitField("eightBitCCD", None, 1), - XBitField("ieiCCD", None, 7), - BitField("bit128", 0x0, 1), - BitField("bit127", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - ByteField("bit120", 0x0), - ByteField("bit112", 0x0), - ByteField("bit104", 0x0), - ByteField("bit96", 0x0), - ByteField("bit88", 0x0), - ByteField("bit80", 0x0), - ByteField("bit72", 0x0), - ByteField("bit64", 0x0), - ByteField("bit56", 0x0), - ByteField("bit48", 0x0), - ByteField("bit40", 0x0), - ByteField("bit32", 0x0), - ByteField("bit24", 0x0), - ByteField("bit16", 0x0), - ByteField("bit8", 0x0) - ] - - -class CellDescriptionHdr(Packet): - """ Cell Description Section 10.5.2.2 """ - name = "Cell Description" - fields_desc = [ - BitField("eightBitCD", None, 1), - XBitField("ieiCD", None, 7), - BitField("bcchHigh", 0x0, 2), - BitField("ncc", 0x0, 3), - BitField("bcc", 0x0, 3), - ByteField("bcchLow", 0x0) - ] - - -class CellOptionsBCCHHdr(Packet): - """ Cell Options (BCCH) Section 10.5.2.3 """ - name = "Cell Options (BCCH)" - fields_desc = [ - BitField("eightBitCOB", None, 1), - XBitField("ieiCOB", None, 7), - BitField("spare", 0x0, 1), - BitField("pwrc", 0x0, 1), - BitField("dtx", 0x0, 2), - BitField("rLinkTout", 0x0, 4) - ] - - -class CellOptionsSACCHHdr(Packet): - """ Cell Options (SACCH) Section 10.5.2.3a """ - name = "Cell Options (SACCH)" - fields_desc = [ - BitField("eightBitCOS", None, 1), - XBitField("ieiCOS", None, 7), - BitField("dtx", 0x0, 1), - BitField("pwrc", 0x0, 1), - BitField("dtx", 0x0, 1), - BitField("rLinkTout", 0x0, 4) - ] - - -class CellSelectionParametersHdr(Packet): - """ Cell Selection Parameters Section 10.5.2.4 """ - name = "Cell Selection Parameters" - fields_desc = [ - BitField("eightBitCSP", None, 1), - XBitField("ieiCSP", None, 7), - BitField("cellReselect", 0x0, 3), - BitField("msTxPwrMax", 0x0, 5), - BitField("acs", None, 1), - BitField("neci", None, 1), - BitField("rxlenAccMin", None, 6) - ] - - -class MacModeAndChannelCodingRequestHdr(Packet): - """ MAC Mode and Channel Coding Requested Section 10.5.2.4a """ - name = "MAC Mode and Channel Coding Requested" - fields_desc = [ - XBitField("ieiMMACCR", None, 4), - BitField("macMode", 0x0, 2), - BitField("cs", 0x0, 2) - ] - - -class ChannelDescriptionHdr(Packet): - """ Channel Description Section 10.5.2.5 """ - name = "Channel Description" - fields_desc = [ - BitField("eightBitCD", None, 1), - XBitField("ieiCD", None, 7), - - BitField("channelTyp", 0x0, 5), - BitField("tn", 0x0, 3), - - BitField("tsc", 0x0, 3), - BitField("h", 0x1, 1), - # if h=1 maybe we find a better solution here... - BitField("maioHi", 0x0, 4), - - BitField("maioLo", 0x0, 2), - BitField("hsn", 0x0, 6) - #BitField("spare", 0x0, 2), - #BitField("arfcnHigh", 0x0, 2), - #ByteField("arfcnLow", 0x0) - ] - - -class ChannelDescription2Hdr(Packet): - """ Channel Description 2 Section 10.5.2.5a """ - name = "Channel Description 2" - fields_desc = [ - BitField("eightBitCD2", None, 1), - XBitField("ieiCD2", None, 7), - BitField("channelTyp", 0x0, 5), - BitField("tn", 0x0, 3), - BitField("tsc", 0x0, 3), - BitField("h", 0x0, 1), - # if h=1 - # BitField("maioHi", 0x0, 4), - # BitField("maioLo", 0x0, 2), - # BitField("hsn", 0x0, 6) - BitField("spare", 0x0, 2), - BitField("arfcnHigh", 0x0, 2), - ByteField("arfcnLow", 0x0) - ] - - -class ChannelModeHdr(Packet): - """ Channel Mode Section 10.5.2.6 """ - name = "Channel Mode" - fields_desc = [ - BitField("eightBitCM", None, 1), - XBitField("ieiCM", None, 7), - ByteField("mode", 0x0) - ] - - -class ChannelMode2Hdr(Packet): - """ Channel Mode 2 Section 10.5.2.7 """ - name = "Channel Mode 2" - fields_desc = [ - BitField("eightBitCM2", None, 1), - XBitField("ieiCM2", None, 7), - ByteField("mode", 0x0) - ] - - -class ChannelNeededHdr(Packet): - """ Channel Needed Section 10.5.2.8 """ - name = "Channel Needed" - fields_desc = [ - XBitField("ieiCN", None, 4), - BitField("channel2", 0x0, 2), - BitField("channel1", 0x0, 2), - ] - - -class ChannelRequestDescriptionHdr(Packet): - """Channel Request Description Section 10.5.2.8a """ - name = "Channel Request Description" - fields_desc = [ - BitField("eightBitCRD", None, 1), - XBitField("ieiCRD", None, 7), - BitField("mt", 0x0, 1), - ConditionalField(BitField("spare", 0x0, 39), - lambda pkt: pkt.mt == 0), - ConditionalField(BitField("spare", 0x0, 3), - lambda pkt: pkt.mt == 1), - ConditionalField(BitField("priority", 0x0, 2), - lambda pkt: pkt.mt == 1), - ConditionalField(BitField("rlcMode", 0x0, 1), - lambda pkt: pkt.mt == 1), - ConditionalField(BitField("llcFrame", 0x1, 1), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("reqBandMsb", 0x0), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("reqBandLsb", 0x0), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("rlcMsb", 0x0), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("rlcLsb", 0x0), - lambda pkt: pkt.mt == 1) - ] - - -class CipherModeSettingHdr(Packet): - """Cipher Mode Setting Section 10.5.2.9 """ - name = "Cipher Mode Setting" - fields_desc = [ - XBitField("ieiCMS", None, 4), - BitField("algoId", 0x0, 3), - BitField("sc", 0x0, 1), - ] - - -class CipherResponseHdr(Packet): - """Cipher Response Section 10.5.2.10 """ - name = "Cipher Response" - fields_desc = [ - XBitField("ieiCR", None, 4), - BitField("spare", 0x0, 3), - BitField("cr", 0x0, 1), - ] - - -# This packet fixes the problem with the 1/2 Byte length. Concatenation -# of cipherModeSetting and cipherResponse -class CipherModeSettingAndcipherResponse(Packet): - name = "Cipher Mode Setting And Cipher Response" - fields_desc = [ - BitField("algoId", 0x0, 3), - BitField("sc", 0x0, 1), - BitField("spare", 0x0, 3), - BitField("cr", 0x0, 1) - ] - - -class ControlChannelDescriptionHdr(Packet): - """Control Channel Description Section 10.5.2.11 """ - name = "Control Channel Description" - fields_desc = [ - BitField("eightBitCCD", None, 1), - XBitField("ieiCCD", None, 7), - - BitField("spare", 0x0, 1), - BitField("att", 0x0, 1), - BitField("bsAgBlksRes", 0x0, 3), - BitField("ccchConf", 0x0, 3), - - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("spare3", 0x0, 1), - BitField("spare4", 0x0, 1), - BitField("bsPaMfrms", 0x0, 3), - - ByteField("t3212", 0x0) - ] - - -class FrequencyChannelSequenceHdr(Packet): - """Frequency Channel Sequence Section 10.5.2.12""" - name = "Frequency Channel Sequence" - fields_desc = [ - BitField("eightBitFCS", None, 1), - XBitField("ieiFCS", None, 7), - BitField("spare", 0x0, 1), - BitField("lowestArfcn", 0x0, 7), - BitField("skipArfcn01", 0x0, 4), - BitField("skipArfcn02", 0x0, 4), - BitField("skipArfcn03", 0x0, 4), - BitField("skipArfcn04", 0x0, 4), - BitField("skipArfcn05", 0x0, 4), - BitField("skipArfcn06", 0x0, 4), - BitField("skipArfcn07", 0x0, 4), - BitField("skipArfcn08", 0x0, 4), - BitField("skipArfcn09", 0x0, 4), - BitField("skipArfcn10", 0x0, 4), - BitField("skipArfcn11", 0x0, 4), - BitField("skipArfcn12", 0x0, 4), - BitField("skipArfcn13", 0x0, 4), - BitField("skipArfcn14", 0x0, 4), - BitField("skipArfcn15", 0x0, 4), - BitField("skipArfcn16", 0x0, 4) - ] - - -class FrequencyListHdr(Packet): - """Frequency List Section 10.5.2.13""" - name = "Frequency List" - # Problem: - # There are several formats for the Frequency List information - # element, distinguished by the "format indicator" subfield. - # Some formats are frequency bit maps, the others use a special encoding - # scheme. - fields_desc = [ - BitField("eightBitFL", None, 1), - XBitField("ieiFL", None, 7), - XByteField("lengthFL", None), - - BitField("formatID", 0x0, 2), - BitField("spare", 0x0, 2), - BitField("arfcn124", 0x0, 1), - BitField("arfcn123", 0x0, 1), - BitField("arfcn122", 0x0, 1), - BitField("arfcn121", 0x0, 1), - - ByteField("arfcn120", 0x0), - ByteField("arfcn112", 0x0), - ByteField("arfcn104", 0x0), - ByteField("arfcn96", 0x0), - ByteField("arfcn88", 0x0), - ByteField("arfcn80", 0x0), - ByteField("arfcn72", 0x0), - ByteField("arfcn64", 0x0), - ByteField("arfcn56", 0x0), - ByteField("arfcn48", 0x0), - ByteField("arfcn40", 0x0), - ByteField("arfcn32", 0x0), - ByteField("arfcn24", 0x0), - ByteField("arfcn16", 0x0), - ByteField("arfcn8", 0x0) - ] - - -class FrequencyShortListHdr(Packet): - """Frequency Short List Section 10.5.2.14""" - name = "Frequency Short List" -# len is 10 -#This element is encoded exactly as the Frequency List information element, -#except that it has a fixed length instead of a -#variable length and does not contain a length indicator and that it -#shall not be encoded in bitmap 0 format. - fields_desc = [ - ByteField("ieiFSL", 0x0), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0) - ] - - -class FrequencyShortListHdr2(Packet): - """Frequency Short List2 Section 10.5.2.14a""" - name = "Frequency Short List 2" - fields_desc = [ - ByteField("byte1", 0x0), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0) - ] - - -# len 4 to 13 -class GroupChannelDescriptionHdr(Packet): - """Group Channel Description Section 10.5.2.14b""" - name = "Group Channel Description" - fields_desc = [ - BitField("eightBitGCD", None, 1), - XBitField("ieiGCD", None, 7), - - XByteField("lengthGCD", None), - - BitField("channelType", 0x0, 5), - BitField("tn", 0x0, 3), - - BitField("tsc", 0x0, 3), - BitField("h", 0x0, 1), - # if h == 0 the packet looks the following way: - ConditionalField(BitField("spare", 0x0, 2), - lambda pkt: pkt. h == 0x0), - ConditionalField(BitField("arfcnHi", 0x0, 2), - lambda pkt: pkt. h == 0x0), - ConditionalField(ByteField("arfcnLo", None), - lambda pkt: pkt. h == 0x0), - # if h == 1 the packet looks the following way: - ConditionalField(BitField("maioHi", 0x0, 4), - lambda pkt: pkt. h == 0x1), - ConditionalField(BitField("maioLo", None, 2), - lambda pkt: pkt. h == 0x1), - ConditionalField(BitField("hsn", None, 6), - lambda pkt: pkt. h == 0x1), - # finished with conditional fields - ByteField("maC6", None), - ByteField("maC7", None), - ByteField("maC8", None), - ByteField("maC9", None), - ByteField("maC10", None), - ByteField("maC11", None), - ByteField("maC12", None), - ByteField("maC13", None), - ByteField("maC14", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 13, a, self.fields_desc) - if self.lengthGCD is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class GprsResumptionHdr(Packet): - """GPRS Resumption Section 10.5.2.14c""" - name = "GPRS Resumption" - fields_desc = [ - XBitField("ieiGR", None, 4), - BitField("spare", 0x0, 3), - BitField("ack", 0x0, 1) - ] - - -class HandoverReferenceHdr(Packet): - """Handover Reference Section 10.5.2.15""" - name = "Handover Reference" - fields_desc = [ - BitField("eightBitHR", None, 1), - XBitField("ieiHR", None, 7), - ByteField("handoverRef", 0x0) - ] - - -# len 1-12 -class IaRestOctets(Packet): - """IA Rest Octets Section 10.5.2.16""" - name = "IA Rest Octets" - fields_desc = [ - ByteField("ieiIRO", 0x0), - # FIXME brainfuck packet - XByteField("lengthIRO", None), - ByteField("byte2", None), - ByteField("byte3", None), - ByteField("byte4", None), - ByteField("byte5", None), - ByteField("byte6", None), - ByteField("byte7", None), - ByteField("byte8", None), - ByteField("byte9", None), - ByteField("byte10", None), - ByteField("byte11", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 12, a, self.fields_desc) - if self.lengthIRO is None: - if res[1] < 0: # FIXME better fix - res[1] = 0 - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class IraRestOctetsHdr(Packet): - """IAR Rest Octets Section 10.5.2.17""" - name = "IAR Rest Octets" - fields_desc = [ - BitField("eightBitIRO", None, 1), - XBitField("ieiIRO", None, 7), - BitField("spare01", 0x0, 1), - BitField("spare02", 0x0, 1), - BitField("spare03", 0x1, 1), - BitField("spare04", 0x0, 1), - BitField("spare05", 0x1, 1), - BitField("spare06", 0x0, 1), - BitField("spare07", 0x1, 1), - BitField("spare08", 0x1, 1), - BitField("spare09", 0x0, 1), - BitField("spare10", 0x0, 1), - BitField("spare11", 0x1, 1), - BitField("spare12", 0x0, 1), - BitField("spare13", 0x1, 1), - BitField("spare14", 0x0, 1), - BitField("spare15", 0x1, 1), - BitField("spare16", 0x1, 1), - BitField("spare17", 0x0, 1), - BitField("spare18", 0x0, 1), - BitField("spare19", 0x1, 1), - BitField("spare20", 0x0, 1), - BitField("spare21", 0x1, 1), - BitField("spare22", 0x0, 1), - BitField("spare23", 0x1, 1), - BitField("spare24", 0x1, 1) - ] - - -# len is 1 to 5 what do we do with the variable size? no lenght -# field?! WTF -class IaxRestOctetsHdr(Packet): - """IAX Rest Octets Section 10.5.2.18""" - name = "IAX Rest Octets" - fields_desc = [ - BitField("eightBitIRO", None, 1), - XBitField("ieiIRO", None, 7), - BitField("spare01", 0x0, 1), - BitField("spare02", 0x0, 1), - BitField("spare03", 0x1, 1), - BitField("spare04", 0x0, 1), - BitField("spare05", 0x1, 1), - BitField("spare06", 0x0, 1), - BitField("spare07", 0x1, 1), - BitField("spare08", 0x1, 1), - ByteField("spareB1", None), - ByteField("spareB2", None), - ByteField("spareB3", None) - ] - - -class L2PseudoLengthHdr(Packet): - """L2 Pseudo Length Section 10.5.2.19""" - name = "L2 Pseudo Length" - fields_desc = [ - BitField("eightBitPL", None, 1), - XBitField("ieiPL", None, 7), - BitField("l2pLength", None, 6), - BitField("bit2", 0x0, 1), - BitField("bit1", 0x1, 1) - ] - - -class MeasurementResultsHdr(Packet): - """Measurement Results Section 10.5.2.20""" - name = "Measurement Results" - fields_desc = [ - BitField("eightBitMR", None, 1), - XBitField("ieiMR", None, 7), - BitField("baUsed", 0x0, 1), - BitField("dtxUsed", 0x0, 1), - BitField("rxLevFull", 0x0, 6), - BitField("spare", 0x0, 1), - BitField("measValid", 0x0, 1), - BitField("rxLevSub", 0x0, 6), - BitField("spare0", 0x0, 1), - BitField("rxqualFull", 0x0, 3), - BitField("rxqualSub", 0x0, 3), - BitField("noNcellHi", 0x0, 1), - BitField("noNcellLo", 0x0, 2), - BitField("rxlevC1", 0x0, 6), - BitField("bcchC1", 0x0, 5), - BitField("bsicC1Hi", 0x0, 3), - BitField("bsicC1Lo", 0x0, 3), - BitField("rxlevC2", 0x0, 5), - BitField("rxlevC2Lo", 0x0, 1), - BitField("bcchC2", 0x0, 5), - BitField("bsicC1Hi", 0x0, 2), - BitField("bscicC2Lo", 0x0, 4), - BitField("bscicC2Hi", 0x0, 4), - - BitField("rxlevC3Lo", 0x0, 2), - BitField("bcchC3", 0x0, 5), - BitField("rxlevC3Hi", 0x0, 1), - - BitField("bsicC3Lo", 0x0, 5), - BitField("bsicC3Hi", 0x0, 3), - - BitField("rxlevC4Lo", 0x0, 3), - BitField("bcchC4", 0x0, 5), - - BitField("bsicC4", 0x0, 6), - BitField("rxlevC5Hi", 0x0, 2), - - BitField("rxlevC5Lo", 0x0, 4), - BitField("bcchC5Hi", 0x0, 4), - - BitField("bcchC5Lo", 0x0, 1), - BitField("bsicC5", 0x0, 6), - BitField("rxlevC6", 0x0, 1), - - BitField("rxlevC6Lo", 0x0, 5), - BitField("bcchC6Hi", 0x0, 3), - - BitField("bcchC6Lo", 0x0, 3), - BitField("bsicC6", 0x0, 5) - ] - - -class GprsMeasurementResultsHdr(Packet): - """GPRS Measurement Results Section 10.5.2.20a""" - name = "GPRS Measurement Results" - fields_desc = [ - BitField("eightBitGMR", None, 1), - XBitField("ieiGMR", None, 7), - BitField("cValue", 0x0, 6), - BitField("rxqualHi", 0x0, 2), - BitField("rxqL", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("signVar", 0x0, 6) - ] - - -# len 3 to 10 -class MobileAllocationHdr(Packet): - """Mobile Allocation Section 10.5.2.21""" - name = "Mobile Allocation" - fields_desc = [ - BitField("eightBitMA", None, 1), - XBitField("ieiMA", None, 7), - XByteField("lengthMA", None), - ByteField("maC64", 0x12), - ByteField("maC56", None), # optional fields start here - ByteField("maC48", None), - ByteField("maC40", None), - ByteField("maC32", None), - ByteField("maC24", None), - ByteField("maC16", None), - ByteField("maC8", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 10, a, self.fields_desc) - if self.lengthMA is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class MobileTimeDifferenceHdr(Packet): - """Mobile Time Difference Section 10.5.2.21a""" - name = "Mobile Time Difference" - fields_desc = [ - BitField("eightBitMTD", None, 1), - XBitField("ieiMTD", None, 7), - XByteField("lengthMTD", 0x5), - ByteField("valueHi", 0x0), - ByteField("valueCnt", 0x0), - BitField("valueLow", 0x0, 5), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1) - ] - - -# min 4 octets max 8 -class MultiRateConfigurationHdr(Packet): - """ MultiRate configuration Section 10.5.2.21aa""" - name = "MultiRate Configuration" - fields_desc = [ - BitField("eightBitMRC", None, 1), - XBitField("ieiMRC", None, 7), - - XByteField("lengthMRC", None), - - BitField("mrVersion", 0x0, 3), - BitField("spare", 0x0, 1), - BitField("icmi", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("startMode", 0x0, 2), - - ByteField("amrCodec", 0x0), - - BitField("spare", None, 2), - BitField("threshold1", None, 6), - - BitField("hysteresis1", None, 4), - BitField("threshold2", None, 4), - - BitField("threshold2cnt", None, 2), - BitField("hysteresis2", None, 4), - BitField("threshold3", None, 2), - - BitField("threshold3cnt", None, 4), - BitField("hysteresis3", None, 4) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 8, a, self.fields_desc) - if self.lengthMRC is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 3 to 12 -class MultislotAllocationHdr(Packet): - """Multislot Allocation Section 10.5.2.21b""" - name = "Multislot Allocation" - fields_desc = [ - BitField("eightBitMSA", None, 1), - XBitField("ieiMSA", None, 7), - XByteField("lengthMSA", None), - BitField("ext0", 0x1, 1), - BitField("da", 0x0, 7), - ConditionalField(BitField("ext1", 0x1, 1), # optional - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("ua", 0x0, 7), - lambda pkt: pkt.ext0 == 0), - ByteField("chan1", None), - ByteField("chan2", None), - ByteField("chan3", None), - ByteField("chan4", None), - ByteField("chan5", None), - ByteField("chan6", None), - ByteField("chan7", None), - ByteField("chan8", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 12, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthMSA is None: - p = p[:1] + struct.pack(">B", len(p)-2) + p[2:] - return p + pay - - -class NcModeHdr(Packet): - """NC mode Section 10.5.2.21c""" - name = "NC Mode" - fields_desc = [ - XBitField("ieiNM", None, 4), - BitField("spare", 0x0, 2), - BitField("ncMode", 0x0, 2) - ] - - -# Fix for len problem -# concatenation NC Mode And Spare Half Octets -class NcModeAndSpareHalfOctets(Packet): - name = "NC Mode And Spare Half Octets" - fields_desc = [ - BitField("spare", 0x0, 2), - BitField("ncMode", 0x0, 2), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class NeighbourCellsDescriptionHdr(Packet): - """Neighbour Cells Description Section 10.5.2.22""" - name = "Neighbour Cells Description" - fields_desc = [ - BitField("eightBitNCD", None, 1), - XBitField("ieiNCD", None, 7), - BitField("bit128", 0x0, 1), - BitField("bit127", 0x0, 1), - BitField("extInd", 0x0, 1), - BitField("baInd", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - BitField("120bits", 0x0, 120) - ] - - -class NeighbourCellsDescription2Hdr(Packet): - """Neighbour Cells Description 2 Section 10.5.2.22a""" - name = "Neighbour Cells Description 2" - fields_desc = [ - BitField("eightBitNCD2", None, 1), - XBitField("ieiNCD2", None, 7), - BitField("bit128", 0x0, 1), - BitField("multiband", 0x0, 2), - BitField("baInd", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - BitField("120bits", 0x0, 120) - ] - - -class NtNRestOctets(Packet): - """NT/N Rest Octets Section 10.5.2.22c""" - name = "NT/N Rest Octets" - fields_desc = [ - BitField("nln", 0x0, 2), - BitField("ncnInfo", 0x0, 4), - BitField("spare", 0x0, 2) - ] - - -# -# The following packet has no length info! -# -# len 1-18 -class P1RestOctets(Packet): - """P1 Rest Octets Section 10.5.2.23""" - name = "P1 Rest Octets" - fields_desc = [ - BitField("nln", 0x0, 2), - BitField("nlnStatus", 0x0, 1), - BitField("prio1", 0x0, 3), - BitField("prio2", 0x0, 3), - # optional - BitField("pageIndication1", 0x0, 1), - BitField("pageIndication2", 0x0, 1), - BitField("spare", 0x0, 5), - ByteField("spareB1", None), - ByteField("spareB2", None), - ByteField("spareB3", None), - ByteField("spareB4", None), - ByteField("spareB5", None), - ByteField("spareB6", None), - ByteField("spareB7", None), - ByteField("spareB8", None), - ByteField("spareB9", None), - ByteField("spareB10", None), - ByteField("spareB11", None), - ByteField("spareB12", None), - ByteField("spareB13", None), - ByteField("spareB14", None), - ByteField("spareB15", None), - ByteField("spareB16", None), - ] - - -# len 2-12 -class P2RestOctets(Packet): - """P2 Rest Octets Section 10.5.2.24""" - name = "P2 Rest Octets" - fields_desc = [ - BitField("cn3", 0x0, 2), - BitField("nln", 0x0, 2), - BitField("nlnStatus", 0x0, 1), - BitField("prio1", 0x0, 3), - - BitField("prio2", 0x0, 3), - BitField("prio3", 0x0, 3), - BitField("pageIndication3", 0x0, 1), - BitField("spare", 0x0, 1), - - # optinal (No length field!) - ByteField("spareB1", None), - ByteField("spareB2", None), - ByteField("spareB3", None), - ByteField("spareB4", None), - - ByteField("spareB5", None), - ByteField("spareB6", None), - ByteField("spareB7", None), - ByteField("spareB8", None), - - ByteField("spareB9", None), - ByteField("spareB10", None) - ] - - -# len 4 -class P3RestOctets(Packet): - """P3 Rest Octets Section 10.5.2.25""" - name = "P3 Rest Octets" - fields_desc = [ - BitField("cn3", 0x0, 2), - BitField("cn4", 0x0, 2), - BitField("nln", 0x0, 2), - BitField("nlnStatus", 0x0, 1), - BitField("prio1", 0x0, 3), - BitField("prio2", 0x0, 3), - BitField("prio3", 0x0, 3), - BitField("prio4", 0x0, 3), - BitField("spare", 0x0, 5) - ] - - -# len 4 -# strange packet, lots of valid formats - -# ideas for the dynamic packets: -# 1] for user interaction: Create an interactive "builder" based on a -# Q/A process (not very scapy like) -# 2] for usage in scripts, create an alternative packet for every -# possible packet layout -# - - -class PacketChannelDescription(Packet): - """Packet Channel Description Section 10.5.2.25a""" - name = "Packet Channel Description" - fields_desc = [ - ByteField("ieiPCD", None), - BitField("chanType", 0x0, 5), # This packet has multiple - # possible layouts. I moddeled the first one - BitField("tn", 0x0, 3), # maybe build an - #"interactive" builder. Like - # a Q/A then propose a - # packet? - BitField("tsc", 0x0, 3), - BitField("chooser1", 0x0, 1), - BitField("chooser2", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("arfcn", 0x0, 10), - ] - - -class DedicatedModeOrTBFHdr(Packet): - """Dedicated mode or TBF Section 10.5.2.25b""" - name = "Dedicated Mode or TBF" - fields_desc = [ - XBitField("ieiDMOT", None, 4), - BitField("spare", 0x0, 1), - BitField("tma", 0x0, 1), - BitField("downlink", 0x0, 1), - BitField("td", 0x0, 1) - ] - - -# FIXME add implementation -class RrPacketUplinkAssignment(Packet): - """RR Packet Uplink Assignment Section 10.5.2.25c""" - name = "RR Packet Uplink Assignment" - fields_desc = [ - # Fill me - ] - - -class PageModeHdr(Packet): - """Page Mode Section 10.5.2.26""" - name = "Page Mode" - fields_desc = [ - XBitField("ieiPM", None, 4), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("pm", 0x0, 2) - ] - - -# Fix for 1/2 len problem -# concatenation: pageMode and dedicatedModeOrTBF -class PageModeAndDedicatedModeOrTBF(Packet): - name = "Page Mode and Dedicated Mode Or TBF" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("pm", 0x0, 2), - BitField("spare", 0x0, 1), - BitField("tma", 0x0, 1), - BitField("downlink", 0x0, 1), - BitField("td", 0x0, 1) - ] - - -# Fix for 1/2 len problem -# concatenation: pageMode and spareHalfOctets -class PageModeAndSpareHalfOctets(Packet): - name = "Page Mode and Spare Half Octets" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("pm", 0x0, 2), - BitField("spareHalfOctets", 0x0, 4) - ] - - -# Fix for 1/2 len problem -# concatenation: pageMode and Channel Needed -class PageModeAndChannelNeeded(Packet): - name = "Page Mode and Channel Needed" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("pm", 0x0, 2), - BitField("channel2", 0x0, 2), - BitField("channel1", 0x0, 2) - ] - - -class NccPermittedHdr(Packet): - """NCC Permitted Section 10.5.2.27""" - name = "NCC Permited" - fields_desc = [ - BitField("eightBitNP", None, 1), - XBitField("ieiNP", None, 7), - ByteField("nccPerm", 0x0) - ] - - -class PowerCommandHdr(Packet): - """Power Command Section 10.5.2.28""" - name = "Power Command" - fields_desc = [ - BitField("eightBitPC", None, 1), - XBitField("ieiPC", None, 7), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("powerLvl", 0x0, 5) - ] - - -class PowerCommandAndAccessTypeHdr(Packet): - """Power Command and access type Section 10.5.2.28a""" - name = "Power Command and Access Type" - fields_desc = [ - BitField("eightBitPCAAT", None, 1), - XBitField("ieiPCAAT", None, 7), - BitField("atc", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("powerLvl", 0x0, 5) - ] - - -class RachControlParametersHdr(Packet): - """RACH Control Parameters Section 10.5.2.29""" - name = "RACH Control Parameters" - fields_desc = [ - BitField("eightBitRCP", None, 1), - XBitField("ieiRCP", None, 7), - BitField("maxRetrans", 0x0, 2), - BitField("txInteger", 0x0, 4), - BitField("cellBarrAccess", 0x0, 1), - BitField("re", 0x0, 1), - BitField("ACC15", 0x0, 1), - BitField("ACC14", 0x0, 1), - BitField("ACC13", 0x0, 1), - BitField("ACC12", 0x0, 1), - BitField("ACC11", 0x0, 1), - BitField("ACC10", 0x0, 1), - BitField("ACC09", 0x0, 1), - BitField("ACC08", 0x0, 1), - BitField("ACC07", 0x0, 1), - BitField("ACC06", 0x0, 1), - BitField("ACC05", 0x0, 1), - BitField("ACC04", 0x0, 1), - BitField("ACC03", 0x0, 1), - BitField("ACC02", 0x0, 1), - BitField("ACC01", 0x0, 1), - BitField("ACC00", 0x0, 1), - ] - - -class RequestReferenceHdr(Packet): - """Request Reference Section 10.5.2.30""" - name = "Request Reference" - fields_desc = [ - BitField("eightBitRR", None, 1), - XBitField("ieiRR", None, 7), - ByteField("ra", 0x0), - BitField("t1", 0x0, 5), - BitField("t3Hi", 0x0, 3), - BitField("t3Lo", 0x0, 3), - BitField("t2", 0x0, 5) - ] - - -class RrCauseHdr(Packet): - """RR Cause Section 10.5.2.31""" - name = "RR Cause" - fields_desc = [ - BitField("eightBitRC", None, 1), - XBitField("ieiRC", None, 7), - ByteField("rrCause", 0x0) - ] - - -class Si1RestOctets(Packet): - """SI 1 Rest Octets Section 10.5.2.32""" - name = "SI 1 Rest Octets" - fields_desc = [ - ByteField("nchPos", 0x0) - ] - - -class Si2bisRestOctets(Packet): - """SI 2bis Rest Octets Section 10.5.2.33""" - name = "SI 2bis Rest Octets" - fields_desc = [ - ByteField("spare", 0x0) - ] - - -class Si2terRestOctets(Packet): - """SI 2ter Rest Octets Section 10.5.2.33a""" - name = "SI 2ter Rest Octets" - fields_desc = [ - ByteField("spare1", 0x0), - ByteField("spare2", 0x0), - ByteField("spare3", 0x0), - ByteField("spare4", 0x0) - ] - - -# len 5 -class Si3RestOctets(Packet): - """SI 3 Rest Octets Section 10.5.2.34""" - name = "SI 3 Rest Octets" - fields_desc = [ - ByteField("byte1", 0x0), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0) - ] - - -# len 1 to 11 -class Si4RestOctets(Packet): - """SI 4 Rest Octets Section 10.5.2.35""" - name = "SI 4 Rest Octets" - fields_desc = [ - XByteField("lengthSI4", None), - ByteField("byte2", None), - ByteField("byte3", None), - ByteField("byte4", None), - ByteField("byte5", None), - ByteField("byte6", None), - ByteField("byte7", None), - ByteField("byte8", None), - ByteField("byte9", None), - ByteField("byte10", None), - ByteField("byte11", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 11, a, self.fields_desc, 1) - if self.lengthSI4 is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - if len(p) is 1: # length of this packet can be 0, but packet is - p = '' # but the IE is manadatory 0_o - return p + pay - - -class Si6RestOctets(Packet): - """SI 6 Rest Octets Section 10.5.2.35a""" - name = "SI 4 Rest Octets" - fields_desc = [ - # FIXME - ] - - -# len 21 -class Si7RestOctets(Packet): - """SI 7 Rest Octets Section 10.5.2.36""" - name = "SI 7 Rest Octets" - fields_desc = [ - # FIXME - XByteField("lengthSI7", 0x15), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0), - ByteField("byte15", 0x0), - ByteField("byte16", 0x0), - ByteField("byte17", 0x0), - ByteField("byte18", 0x0), - ByteField("byte19", 0x0), - ByteField("byte20", 0x0), - ByteField("byte21", 0x0) - ] - - -# len 21 -class Si8RestOctets(Packet): - """SI 8 Rest Octets Section 10.5.2.37""" - name = "SI 8 Rest Octets" - fields_desc = [ - # FIXME - XByteField("lengthSI8", 0x15), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0), - ByteField("byte15", 0x0), - ByteField("byte16", 0x0), - ByteField("byte17", 0x0), - ByteField("byte18", 0x0), - ByteField("byte19", 0x0), - ByteField("byte20", 0x0), - ByteField("byte21", 0x0) - ] - - -#len 17 -class Si9RestOctets(Packet): - """SI 9 Rest Octets Section 10.5.2.37a""" - name = "SI 9 Rest Octets" - fields_desc = [ - # FIXME - XByteField("lengthSI9", 0x11), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0), - ByteField("byte15", 0x0), - ByteField("byte16", 0x0), - ByteField("byte17", 0x0) - ] - - -# len 21 -class Si13RestOctets(Packet): - """SI 13 Rest Octets Section 10.5.2.37b""" - name = "SI 13 Rest Octets" - fields_desc = [ - # FIXME - XByteField("lengthSI3", 0x15), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0), - ByteField("byte15", 0x0), - ByteField("byte16", 0x0), - ByteField("byte17", 0x0), - ByteField("byte18", 0x0), - ByteField("byte19", 0x0), - ByteField("byte20", 0x0), - ByteField("byte21", 0x0) - ] - - -# 10.5.2.37c [spare] -# 10.5.2.37d [spare] - - -# len 21 -class Si16RestOctets(Packet): - """SI 16 Rest Octets Section 10.5.2.37e""" - name = "SI 16 Rest Octets" - fields_desc = [ - # FIXME - XByteField("lengthSI16", 0x15), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0), - ByteField("byte15", 0x0), - ByteField("byte16", 0x0), - ByteField("byte17", 0x0), - ByteField("byte18", 0x0), - ByteField("byte19", 0x0), - ByteField("byte20", 0x0), - ByteField("byte21", 0x0) - ] - - -# len 21 -class Si17RestOctets(Packet): - """SI 17 Rest Octets Section 10.5.2.37f""" - name = "SI 17 Rest Octets" - fields_desc = [ - # FIXME - XByteField("lengthSI17", 0x15), - ByteField("byte2", 0x0), - ByteField("byte3", 0x0), - ByteField("byte4", 0x0), - ByteField("byte5", 0x0), - ByteField("byte6", 0x0), - ByteField("byte7", 0x0), - ByteField("byte8", 0x0), - ByteField("byte9", 0x0), - ByteField("byte10", 0x0), - ByteField("byte11", 0x0), - ByteField("byte12", 0x0), - ByteField("byte13", 0x0), - ByteField("byte14", 0x0), - ByteField("byte15", 0x0), - ByteField("byte16", 0x0), - ByteField("byte17", 0x0), - ByteField("byte18", 0x0), - ByteField("byte19", 0x0), - ByteField("byte20", 0x0), - ByteField("byte21", 0x0) - ] - - -class StartingTimeHdr(Packet): - """Starting Time Section 10.5.2.38""" - name = "Starting Time" - fields_desc = [ - BitField("eightBitST", None, 1), - XBitField("ieiST", None, 7), - ByteField("ra", 0x0), - BitField("t1", 0x0, 5), - BitField("t3Hi", 0x0, 3), - BitField("t3Lo", 0x0, 3), - BitField("t2", 0x0, 5) - ] - - -class SynchronizationIndicationHdr(Packet): - """Synchronization Indication Section 10.5.2.39""" - name = "Synchronization Indication" - fields_desc = [ - XBitField("ieiSI", None, 4), - BitField("nci", 0x0, 1), - BitField("rot", 0x0, 1), - BitField("si", 0x0, 2) - ] - - -class TimingAdvanceHdr(Packet): - """Timing Advance Section 10.5.2.40""" - name = "Timing Advance" - fields_desc = [ - BitField("eightBitTA", None, 1), - XBitField("ieiTA", None, 7), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("timingVal", 0x0, 6) - ] - - -class TimeDifferenceHdr(Packet): - """ Time Difference Section 10.5.2.41""" - name = "Time Difference" - fields_desc = [ - BitField("eightBitTD", None, 1), - XBitField("ieiTD", None, 7), - XByteField("lengthTD", 0x3), - ByteField("timeValue", 0x0) - ] - - -class TlliHdr(Packet): - """ TLLI Section Section 10.5.2.41a""" - name = "TLLI" - fields_desc = [ - BitField("eightBitT", None, 1), - XBitField("ieiT", None, 7), - ByteField("value", 0x0), - ByteField("value1", 0x0), - ByteField("value2", 0x0), - ByteField("value3", 0x0) - ] - - -class TmsiPTmsiHdr(Packet): - """ TMSI/P-TMSI Section 10.5.2.42""" - name = "TMSI/P-TMSI" - fields_desc = [ - BitField("eightBitTPT", None, 1), - XBitField("ieiTPT", None, 7), - ByteField("value", 0x0), - ByteField("value1", 0x0), - ByteField("value2", 0x0), - ByteField("value3", 0x0) - ] - - -class VgcsTargetModeIdenticationHdr(Packet): - """ VGCS target Mode Indication 10.5.2.42a""" - name = "VGCS Target Mode Indication" - fields_desc = [ - BitField("eightBitVTMI", None, 1), - XBitField("ieiVTMI", None, 7), - XByteField("lengthVTMI", 0x2), - BitField("targerMode", 0x0, 2), - BitField("cipherKeyNb", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1) - ] - - -class WaitIndicationHdr(Packet): - """ Wait Indication Section 10.5.2.43""" - name = "Wait Indication" - fields_desc = [ # asciiart of specs strange - BitField("eightBitWI", None, 1), - XBitField("ieiWI", None, 7), - ByteField("timeoutVal", 0x0) - ] - - -# len 17 -class ExtendedMeasurementResultsHdr(Packet): - """EXTENDED MEASUREMENT RESULTS Section 10.5.2.45""" - name = "Extended Measurement Results" - fields_desc = [ - BitField("eightBitEMR", None, 1), - XBitField("ieiEMR", None, 7), - - BitField("scUsed", None, 1), - BitField("dtxUsed", None, 1), - BitField("rxLevC0", None, 6), - - BitField("rxLevC1", None, 6), - BitField("rxLevC2Hi", None, 2), - - BitField("rxLevC2Lo", None, 4), - BitField("rxLevC3Hi", None, 4), - - BitField("rxLevC3Lo", None, 3), - BitField("rxLevC4", None, 5), - - BitField("rxLevC5", None, 6), - BitField("rxLevC6Hi", None, 2), - - BitField("rxLevC6Lo", None, 4), - BitField("rxLevC7Hi", None, 4), - - BitField("rxLevC7Lo", None, 2), - BitField("rxLevC8", None, 6), - - BitField("rxLevC9", None, 6), - BitField("rxLevC10Hi", None, 2), - - BitField("rxLevC10Lo", None, 4), - BitField("rxLevC11Hi", None, 4), - - BitField("rxLevC13Lo", None, 2), - BitField("rxLevC12", None, 6), - - BitField("rxLevC13", None, 6), - BitField("rxLevC14Hi", None, 2), - - BitField("rxLevC14Lo", None, 4), - BitField("rxLevC15Hi", None, 4), - - BitField("rxLevC15Lo", None, 2), - BitField("rxLevC16", None, 6), - - - BitField("rxLevC17", None, 6), - BitField("rxLevC18Hi", None, 2), - - BitField("rxLevC18Lo", None, 4), - BitField("rxLevC19Hi", None, 4), - - BitField("rxLevC19Lo", None, 2), - BitField("rxLevC20", None, 6) - ] - - -# len 17 -class ExtendedMeasurementFrequencyListHdr(Packet): - """Extended Measurement Frequency List Section 10.5.2.46""" - name = "Extended Measurement Frequency List" - fields_desc = [ - BitField("eightBitEMFL", None, 1), - XBitField("ieiEMFL", None, 7), - - BitField("bit128", 0x0, 1), - BitField("bit127", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("seqCode", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - - BitField("bitsRest", 0x0, 128) - ] - - -class SuspensionCauseHdr(Packet): - """Suspension Cause Section 10.5.2.47""" - name = "Suspension Cause" - fields_desc = [ - BitField("eightBitSC", None, 1), - XBitField("ieiSC", None, 7), - ByteField("suspVal", 0x0) - ] - - -class ApduIDHdr(Packet): - """APDU Flags Section 10.5.2.48""" - name = "Apdu Id" - fields_desc = [ - XBitField("ieiAI", None, 4), - BitField("id", None, 4) - ] - - -class ApduFlagsHdr(Packet): - """APDU Flags Section 10.5.2.49""" - name = "Apdu Flags" - fields_desc = [ - XBitField("iei", None, 4), - BitField("spare", 0x0, 1), - BitField("cr", 0x0, 1), - BitField("firstSeg", 0x0, 1), - BitField("lastSeg", 0x0, 1) - ] - - -# Fix 1/2 len problem -class ApduIDAndApduFlags(Packet): - name = "Apu Id and Apdu Flags" - fields_desc = [ - BitField("id", None, 4), - BitField("spare", 0x0, 1), - BitField("cr", 0x0, 1), - BitField("firstSeg", 0x0, 1), - BitField("lastSeg", 0x0, 1) - ] - - -# len 2 to max L3 (251) (done) -class ApduDataHdr(Packet): - """APDU Data Section 10.5.2.50""" - name = "Apdu Data" - fields_desc = [ - BitField("eightBitAD", None, 1), - XBitField("ieiAD", None, 7), - XByteField("lengthAD", None), - #optional - ByteField("apuInfo1", None), - ByteField("apuInfo2", None), - ByteField("apuInfo3", None), - ByteField("apuInfo4", None), - ByteField("apuInfo5", None), - ByteField("apuInfo6", None), - ByteField("apuInfo7", None), - ByteField("apuInfo8", None), - ByteField("apuInfo9", None), - ByteField("apuInfo10", None), - ByteField("apuInfo11", None), - ByteField("apuInfo12", None), - ByteField("apuInfo13", None), - ByteField("apuInfo14", None), - ByteField("apuInfo15", None), - ByteField("apuInfo16", None), - ByteField("apuInfo17", None), - ByteField("apuInfo18", None), - ByteField("apuInfo19", None), - ByteField("apuInfo20", None), - ByteField("apuInfo21", None), - ByteField("apuInfo22", None), - ByteField("apuInfo23", None), - ByteField("apuInfo24", None), - ByteField("apuInfo25", None), - ByteField("apuInfo26", None), - ByteField("apuInfo27", None), - ByteField("apuInfo28", None), - ByteField("apuInfo29", None), - ByteField("apuInfo30", None), - ByteField("apuInfo31", None), - ByteField("apuInfo32", None), - ByteField("apuInfo33", None), - ByteField("apuInfo34", None), - ByteField("apuInfo35", None), - ByteField("apuInfo36", None), - ByteField("apuInfo37", None), - ByteField("apuInfo38", None), - ByteField("apuInfo39", None), - ByteField("apuInfo40", None), - ByteField("apuInfo41", None), - ByteField("apuInfo42", None), - ByteField("apuInfo43", None), - ByteField("apuInfo44", None), - ByteField("apuInfo45", None), - ByteField("apuInfo46", None), - ByteField("apuInfo47", None), - ByteField("apuInfo48", None), - ByteField("apuInfo49", None), - ByteField("apuInfo50", None), - ByteField("apuInfo51", None), - ByteField("apuInfo52", None), - ByteField("apuInfo53", None), - ByteField("apuInfo54", None), - ByteField("apuInfo55", None), - ByteField("apuInfo56", None), - ByteField("apuInfo57", None), - ByteField("apuInfo58", None), - ByteField("apuInfo59", None), - ByteField("apuInfo60", None), - ByteField("apuInfo61", None), - ByteField("apuInfo62", None), - ByteField("apuInfo63", None), - ByteField("apuInfo64", None), - ByteField("apuInfo65", None), - ByteField("apuInfo66", None), - ByteField("apuInfo67", None), - ByteField("apuInfo68", None), - ByteField("apuInfo69", None), - ByteField("apuInfo70", None), - ByteField("apuInfo71", None), - ByteField("apuInfo72", None), - ByteField("apuInfo73", None), - ByteField("apuInfo74", None), - ByteField("apuInfo75", None), - ByteField("apuInfo76", None), - ByteField("apuInfo77", None), - ByteField("apuInfo78", None), - ByteField("apuInfo79", None), - ByteField("apuInfo80", None), - ByteField("apuInfo81", None), - ByteField("apuInfo82", None), - ByteField("apuInfo83", None), - ByteField("apuInfo84", None), - ByteField("apuInfo85", None), - ByteField("apuInfo86", None), - ByteField("apuInfo87", None), - ByteField("apuInfo88", None), - ByteField("apuInfo89", None), - ByteField("apuInfo90", None), - ByteField("apuInfo91", None), - ByteField("apuInfo92", None), - ByteField("apuInfo93", None), - ByteField("apuInfo94", None), - ByteField("apuInfo95", None), - ByteField("apuInfo96", None), - ByteField("apuInfo97", None), - ByteField("apuInfo98", None), - ByteField("apuInfo99", None), - ByteField("apuInfo100", None), - ByteField("apuInfo101", None), - ByteField("apuInfo102", None), - ByteField("apuInfo103", None), - ByteField("apuInfo104", None), - ByteField("apuInfo105", None), - ByteField("apuInfo106", None), - ByteField("apuInfo107", None), - ByteField("apuInfo108", None), - ByteField("apuInfo109", None), - ByteField("apuInfo110", None), - ByteField("apuInfo111", None), - ByteField("apuInfo112", None), - ByteField("apuInfo113", None), - ByteField("apuInfo114", None), - ByteField("apuInfo115", None), - ByteField("apuInfo116", None), - ByteField("apuInfo117", None), - ByteField("apuInfo118", None), - ByteField("apuInfo119", None), - ByteField("apuInfo120", None), - ByteField("apuInfo121", None), - ByteField("apuInfo122", None), - ByteField("apuInfo123", None), - ByteField("apuInfo124", None), - ByteField("apuInfo125", None), - ByteField("apuInfo126", None), - ByteField("apuInfo127", None), - ByteField("apuInfo128", None), - ByteField("apuInfo129", None), - ByteField("apuInfo130", None), - ByteField("apuInfo131", None), - ByteField("apuInfo132", None), - ByteField("apuInfo133", None), - ByteField("apuInfo134", None), - ByteField("apuInfo135", None), - ByteField("apuInfo136", None), - ByteField("apuInfo137", None), - ByteField("apuInfo138", None), - ByteField("apuInfo139", None), - ByteField("apuInfo140", None), - ByteField("apuInfo141", None), - ByteField("apuInfo142", None), - ByteField("apuInfo143", None), - ByteField("apuInfo144", None), - ByteField("apuInfo145", None), - ByteField("apuInfo146", None), - ByteField("apuInfo147", None), - ByteField("apuInfo148", None), - ByteField("apuInfo149", None), - ByteField("apuInfo150", None), - ByteField("apuInfo151", None), - ByteField("apuInfo152", None), - ByteField("apuInfo153", None), - ByteField("apuInfo154", None), - ByteField("apuInfo155", None), - ByteField("apuInfo156", None), - ByteField("apuInfo157", None), - ByteField("apuInfo158", None), - ByteField("apuInfo159", None), - ByteField("apuInfo160", None), - ByteField("apuInfo161", None), - ByteField("apuInfo162", None), - ByteField("apuInfo163", None), - ByteField("apuInfo164", None), - ByteField("apuInfo165", None), - ByteField("apuInfo166", None), - ByteField("apuInfo167", None), - ByteField("apuInfo168", None), - ByteField("apuInfo169", None), - ByteField("apuInfo170", None), - ByteField("apuInfo171", None), - ByteField("apuInfo172", None), - ByteField("apuInfo173", None), - ByteField("apuInfo174", None), - ByteField("apuInfo175", None), - ByteField("apuInfo176", None), - ByteField("apuInfo177", None), - ByteField("apuInfo178", None), - ByteField("apuInfo179", None), - ByteField("apuInfo180", None), - ByteField("apuInfo181", None), - ByteField("apuInfo182", None), - ByteField("apuInfo183", None), - ByteField("apuInfo184", None), - ByteField("apuInfo185", None), - ByteField("apuInfo186", None), - ByteField("apuInfo187", None), - ByteField("apuInfo188", None), - ByteField("apuInfo189", None), - ByteField("apuInfo190", None), - ByteField("apuInfo191", None), - ByteField("apuInfo192", None), - ByteField("apuInfo193", None), - ByteField("apuInfo194", None), - ByteField("apuInfo195", None), - ByteField("apuInfo196", None), - ByteField("apuInfo197", None), - ByteField("apuInfo198", None), - ByteField("apuInfo199", None), - ByteField("apuInfo200", None), - ByteField("apuInfo201", None), - ByteField("apuInfo202", None), - ByteField("apuInfo203", None), - ByteField("apuInfo204", None), - ByteField("apuInfo205", None), - ByteField("apuInfo206", None), - ByteField("apuInfo207", None), - ByteField("apuInfo208", None), - ByteField("apuInfo209", None), - ByteField("apuInfo210", None), - ByteField("apuInfo211", None), - ByteField("apuInfo212", None), - ByteField("apuInfo213", None), - ByteField("apuInfo214", None), - ByteField("apuInfo215", None), - ByteField("apuInfo216", None), - ByteField("apuInfo217", None), - ByteField("apuInfo218", None), - ByteField("apuInfo219", None), - ByteField("apuInfo220", None), - ByteField("apuInfo221", None), - ByteField("apuInfo222", None), - ByteField("apuInfo223", None), - ByteField("apuInfo224", None), - ByteField("apuInfo225", None), - ByteField("apuInfo226", None), - ByteField("apuInfo227", None), - ByteField("apuInfo228", None), - ByteField("apuInfo229", None), - ByteField("apuInfo230", None), - ByteField("apuInfo231", None), - ByteField("apuInfo232", None), - ByteField("apuInfo233", None), - ByteField("apuInfo234", None), - ByteField("apuInfo235", None), - ByteField("apuInfo236", None), - ByteField("apuInfo237", None), - ByteField("apuInfo238", None), - ByteField("apuInfo239", None), - ByteField("apuInfo240", None), - ByteField("apuInfo241", None), - ByteField("apuInfo242", None), - ByteField("apuInfo243", None), - ByteField("apuInfo244", None), - ByteField("apuInfo245", None), - ByteField("apuInfo246", None), - ByteField("apuInfo247", None), - ByteField("apuInfo248", None), - ByteField("apuInfo249", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 251, a, self.fields_desc) - if self.lengthAD is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - -# -# 10.5.3 Mobility management information elements -# - - -class AuthenticationParameterRAND(Packet): - """Authentication parameter RAND Section 10.5.3.1""" - name = "Authentication Parameter Rand" - fields_desc = [ - ByteField("ieiAPR", None), - BitField("randValue", 0x0, 128) - ] - - -class AuthenticationParameterSRES(Packet): - """Authentication parameter SRES Section 10.5.3.2""" - name = "Authentication Parameter Sres" - fields_desc = [ - ByteField("ieiAPS", None), - BitField("sresValue", 0x0, 40) - ] - - -class CmServiceType(Packet): - """CM service type Section 10.5.3.3""" - name = "CM Service Type" - fields_desc = [ - XBitField("ieiCST", 0x0, 4), - BitField("serviceType", 0x0, 4) - ] - - -class CmServiceTypeAndCiphKeySeqNr(Packet): - name = "CM Service Type and Cipher Key Sequence Number" - fields_desc = [ - BitField("keySeq", 0x0, 3), - BitField("spare", 0x0, 1), - BitField("serviceType", 0x0, 4) - ] - - -class IdentityType(Packet): - """Identity type Section 10.5.3.4""" - name = "Identity Type" - fields_desc = [ - XBitField("ieiIT", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("idType", 0x1, 3) - ] - - -# Fix 1/2 len problem -class IdentityTypeAndSpareHalfOctet(Packet): - name = "Identity Type and Spare Half Octet" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("idType", 0x1, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class LocationUpdatingType(Packet): - """Location updating type Section 10.5.3.5""" - name = "Location Updating Type" - fields_desc = [ - XBitField("ieiLUT", 0x0, 4), - BitField("for", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("lut", 0x0, 2) - ] - - -class LocationUpdatingTypeAndCiphKeySeqNr(Packet): - name = "Location Updating Type and Cipher Key Sequence Number" - fields_desc = [ - BitField("for", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("lut", 0x0, 2), - BitField("spare", 0x0, 1), - BitField("keySeq", 0x0, 3) - ] - - -# len 3 to L3 max (251) (done) -class NetworkNameHdr(Packet): - """Network Name Section 10.5.3.5a""" - name = "Network Name" - fields_desc = [ - BitField("eightBitNN", None, 1), - XBitField("ieiNN", None, 7), - - XByteField("lengthNN", None), - - BitField("ext1", 0x1, 1), - BitField("codingScheme", 0x0, 3), - BitField("addCi", 0x0, 1), - BitField("nbSpare", 0x0, 3), - # optional - ByteField("txtString1", None), - ByteField("txtString2", None), - ByteField("txtString3", None), - ByteField("txtString4", None), - ByteField("txtString5", None), - ByteField("txtString6", None), - ByteField("txtString7", None), - ByteField("txtString8", None), - ByteField("txtString9", None), - ByteField("txtString10", None), - ByteField("txtString11", None), - ByteField("txtString12", None), - ByteField("txtString13", None), - ByteField("txtString14", None), - ByteField("txtString15", None), - ByteField("txtString16", None), - ByteField("txtString17", None), - ByteField("txtString18", None), - ByteField("txtString19", None), - ByteField("txtString20", None), - ByteField("txtString21", None), - ByteField("txtString22", None), - ByteField("txtString23", None), - ByteField("txtString24", None), - ByteField("txtString25", None), - ByteField("txtString26", None), - ByteField("txtString27", None), - ByteField("txtString28", None), - ByteField("txtString29", None), - ByteField("txtString30", None), - ByteField("txtString31", None), - ByteField("txtString32", None), - ByteField("txtString33", None), - ByteField("txtString34", None), - ByteField("txtString35", None), - ByteField("txtString36", None), - ByteField("txtString37", None), - ByteField("txtString38", None), - ByteField("txtString39", None), - ByteField("txtString40", None), - ByteField("txtString41", None), - ByteField("txtString42", None), - ByteField("txtString43", None), - ByteField("txtString44", None), - ByteField("txtString45", None), - ByteField("txtString46", None), - ByteField("txtString47", None), - ByteField("txtString48", None), - ByteField("txtString49", None), - ByteField("txtString50", None), - ByteField("txtString51", None), - ByteField("txtString52", None), - ByteField("txtString53", None), - ByteField("txtString54", None), - ByteField("txtString55", None), - ByteField("txtString56", None), - ByteField("txtString57", None), - ByteField("txtString58", None), - ByteField("txtString59", None), - ByteField("txtString60", None), - ByteField("txtString61", None), - ByteField("txtString62", None), - ByteField("txtString63", None), - ByteField("txtString64", None), - ByteField("txtString65", None), - ByteField("txtString66", None), - ByteField("txtString67", None), - ByteField("txtString68", None), - ByteField("txtString69", None), - ByteField("txtString70", None), - ByteField("txtString71", None), - ByteField("txtString72", None), - ByteField("txtString73", None), - ByteField("txtString74", None), - ByteField("txtString75", None), - ByteField("txtString76", None), - ByteField("txtString77", None), - ByteField("txtString78", None), - ByteField("txtString79", None), - ByteField("txtString80", None), - ByteField("txtString81", None), - ByteField("txtString82", None), - ByteField("txtString83", None), - ByteField("txtString84", None), - ByteField("txtString85", None), - ByteField("txtString86", None), - ByteField("txtString87", None), - ByteField("txtString88", None), - ByteField("txtString89", None), - ByteField("txtString90", None), - ByteField("txtString91", None), - ByteField("txtString92", None), - ByteField("txtString93", None), - ByteField("txtString94", None), - ByteField("txtString95", None), - ByteField("txtString96", None), - ByteField("txtString97", None), - ByteField("txtString98", None), - ByteField("txtString99", None), - ByteField("txtString100", None), - ByteField("txtString101", None), - ByteField("txtString102", None), - ByteField("txtString103", None), - ByteField("txtString104", None), - ByteField("txtString105", None), - ByteField("txtString106", None), - ByteField("txtString107", None), - ByteField("txtString108", None), - ByteField("txtString109", None), - ByteField("txtString110", None), - ByteField("txtString111", None), - ByteField("txtString112", None), - ByteField("txtString113", None), - ByteField("txtString114", None), - ByteField("txtString115", None), - ByteField("txtString116", None), - ByteField("txtString117", None), - ByteField("txtString118", None), - ByteField("txtString119", None), - ByteField("txtString120", None), - ByteField("txtString121", None), - ByteField("txtString122", None), - ByteField("txtString123", None), - ByteField("txtString124", None), - ByteField("txtString125", None), - ByteField("txtString126", None), - ByteField("txtString127", None), - ByteField("txtString128", None), - ByteField("txtString129", None), - ByteField("txtString130", None), - ByteField("txtString131", None), - ByteField("txtString132", None), - ByteField("txtString133", None), - ByteField("txtString134", None), - ByteField("txtString135", None), - ByteField("txtString136", None), - ByteField("txtString137", None), - ByteField("txtString138", None), - ByteField("txtString139", None), - ByteField("txtString140", None), - ByteField("txtString141", None), - ByteField("txtString142", None), - ByteField("txtString143", None), - ByteField("txtString144", None), - ByteField("txtString145", None), - ByteField("txtString146", None), - ByteField("txtString147", None), - ByteField("txtString148", None), - ByteField("txtString149", None), - ByteField("txtString150", None), - ByteField("txtString151", None), - ByteField("txtString152", None), - ByteField("txtString153", None), - ByteField("txtString154", None), - ByteField("txtString155", None), - ByteField("txtString156", None), - ByteField("txtString157", None), - ByteField("txtString158", None), - ByteField("txtString159", None), - ByteField("txtString160", None), - ByteField("txtString161", None), - ByteField("txtString162", None), - ByteField("txtString163", None), - ByteField("txtString164", None), - ByteField("txtString165", None), - ByteField("txtString166", None), - ByteField("txtString167", None), - ByteField("txtString168", None), - ByteField("txtString169", None), - ByteField("txtString170", None), - ByteField("txtString171", None), - ByteField("txtString172", None), - ByteField("txtString173", None), - ByteField("txtString174", None), - ByteField("txtString175", None), - ByteField("txtString176", None), - ByteField("txtString177", None), - ByteField("txtString178", None), - ByteField("txtString179", None), - ByteField("txtString180", None), - ByteField("txtString181", None), - ByteField("txtString182", None), - ByteField("txtString183", None), - ByteField("txtString184", None), - ByteField("txtString185", None), - ByteField("txtString186", None), - ByteField("txtString187", None), - ByteField("txtString188", None), - ByteField("txtString189", None), - ByteField("txtString190", None), - ByteField("txtString191", None), - ByteField("txtString192", None), - ByteField("txtString193", None), - ByteField("txtString194", None), - ByteField("txtString195", None), - ByteField("txtString196", None), - ByteField("txtString197", None), - ByteField("txtString198", None), - ByteField("txtString199", None), - ByteField("txtString200", None), - ByteField("txtString201", None), - ByteField("txtString202", None), - ByteField("txtString203", None), - ByteField("txtString204", None), - ByteField("txtString205", None), - ByteField("txtString206", None), - ByteField("txtString207", None), - ByteField("txtString208", None), - ByteField("txtString209", None), - ByteField("txtString210", None), - ByteField("txtString211", None), - ByteField("txtString212", None), - ByteField("txtString213", None), - ByteField("txtString214", None), - ByteField("txtString215", None), - ByteField("txtString216", None), - ByteField("txtString217", None), - ByteField("txtString218", None), - ByteField("txtString219", None), - ByteField("txtString220", None), - ByteField("txtString221", None), - ByteField("txtString222", None), - ByteField("txtString223", None), - ByteField("txtString224", None), - ByteField("txtString225", None), - ByteField("txtString226", None), - ByteField("txtString227", None), - ByteField("txtString228", None), - ByteField("txtString229", None), - ByteField("txtString230", None), - ByteField("txtString231", None), - ByteField("txtString232", None), - ByteField("txtString233", None), - ByteField("txtString234", None), - ByteField("txtString235", None), - ByteField("txtString236", None), - ByteField("txtString237", None), - ByteField("txtString238", None), - ByteField("txtString239", None), - ByteField("txtString240", None), - ByteField("txtString241", None), - ByteField("txtString242", None), - ByteField("txtString243", None), - ByteField("txtString244", None), - ByteField("txtString245", None), - ByteField("txtString246", None), - ByteField("txtString247", None), - ByteField("txtString248", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 251, a, self.fields_desc) - if self.lengthNN is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class RejectCause(Packet): - """Reject cause Section 10.5.3.6""" - name = "Reject Cause" - fields_desc = [ - ByteField("ieiRC", 0x0), - ByteField("rejCause", 0x0) - ] - - -class FollowOnProceed(Packet): - """Follow-on Proceed Section 10.5.3.7""" - name = "Follow-on Proceed" - fields_desc = [ - ByteField("ieiFOP", 0x0), - ] - - -class TimeZoneHdr(Packet): - """Time Zone Section 10.5.3.8""" - name = "Time Zone" - fields_desc = [ - BitField("eightBitTZ", None, 1), - XBitField("ieiTZ", None, 7), - ByteField("timeZone", 0x0), - ] - - -class TimeZoneAndTimeHdr(Packet): - """Time Zone and Time Section 10.5.3.9""" - name = "Time Zone and Time" - fields_desc = [ - BitField("eightBitTZAT", None, 1), - XBitField("ieiTZAT", None, 7), - ByteField("year", 0x0), - ByteField("month", 0x0), - ByteField("day", 0x0), - ByteField("hour", 0x0), - ByteField("minute", 0x0), - ByteField("second", 0x0), - ByteField("timeZone", 0x0) - ] - - -class CtsPermissionHdr(Packet): - """CTS permission Section 10.5.3.10""" - name = "Cts Permission" - fields_desc = [ - BitField("eightBitCP", None, 1), - XBitField("ieiCP", None, 7), - ] - - -class LsaIdentifierHdr(Packet): - """LSA Identifier Section 10.5.3.11""" - name = "Lsa Identifier" - fields_desc = [ - BitField("eightBitLI", None, 1), - XBitField("ieiLI", None, 7), - ByteField("lsaID", 0x0), - ByteField("lsaID1", 0x0), - ByteField("lsaID2", 0x0) - ] - - -# -# 10.5.4 Call control information elements -# - -#10.5.4.1 Extensions of codesets -# This is only text and no packet - -class LockingShiftProcedureHdr(Packet): - """Locking shift procedure Section 10.5.4.2""" - name = "Locking Shift Procedure" - fields_desc = [ - XBitField("ieiLSP", None, 4), - BitField("lockShift", 0x0, 1), - BitField("codesetId", 0x0, 3) - ] - - -class NonLockingShiftProcedureHdr(Packet): - """Non-locking shift procedure Section 10.5.4.3""" - name = "Non-locking Shift Procedure" - fields_desc = [ - XBitField("ieiNLSP", None, 4), - BitField("nonLockShift", 0x1, 1), - BitField("codesetId", 0x0, 3) - ] - - -class AuxiliaryStatesHdr(Packet): - """Auxiliary states Section 10.5.4.4""" - name = "Auxiliary States" - fields_desc = [ - BitField("eightBitAS", None, 1), - XBitField("ieiAS", None, 7), - XByteField("lengthAS", 0x3), - BitField("ext", 0x1, 1), - BitField("spare", 0x0, 3), - BitField("holdState", 0x0, 2), - BitField("mptyState", 0x0, 2) - ] - - -# len 3 to 15 -class BearerCapabilityHdr(Packet): - """Bearer capability Section 10.5.4.5""" - name = "Bearer Capability" - fields_desc = [ - BitField("eightBitBC", None, 1), - XBitField("ieiBC", None, 7), - - XByteField("lengthBC", None), - - BitField("ext0", 0x1, 1), - BitField("radioChReq", 0x1, 2), - BitField("codingStd", 0x0, 1), - BitField("transMode", 0x0, 1), - BitField("infoTransCa", 0x0, 3), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("coding", None, 1), - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("spare", None, 2), - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("speechVers", 0x0, 4), - lambda pkt: pkt.ext0 == 0), - - ConditionalField(BitField("ext2", 0x1, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("compress", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("structure", None, 2), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("dupMode", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("config", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("nirr", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("establi", 0x0, 1), - lambda pkt: pkt.ext1 == 0), - - BitField("ext3", None, 1), - BitField("accessId", None, 2), - BitField("rateAda", None, 2), - BitField("signaling", None, 3), - - ConditionalField(BitField("ext4", None, 1), - lambda pkt: pkt.ext3 == 0), - ConditionalField(BitField("otherITC", None, 2), - lambda pkt: pkt.ext3 == 0), - ConditionalField(BitField("otherRate", None, 2), - lambda pkt: pkt.ext3 == 0), - ConditionalField(BitField("spare1", 0x0, 3), - lambda pkt: pkt.ext3 == 0), - - ConditionalField(BitField("ext5", 0x1, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("hdr", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("multiFr", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("mode", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("lli", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("assig", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("inbNeg", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("spare2", 0x0, 1), - lambda pkt: pkt.ext4 == 0), - - BitField("ext6", None, 1), - BitField("layer1Id", None, 2), - BitField("userInf", None, 4), - BitField("sync", None, 1), - - ConditionalField(BitField("ext7", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("stopBit", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("negoc", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("nbDataBit", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("userRate", None, 4), - lambda pkt: pkt.ext6 == 0), - - ConditionalField(BitField("ext8", None, 1), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("interRate", None, 2), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("nicTX", None, 1), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("nicRX", None, 1), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("parity", None, 3), - lambda pkt: pkt.ext7 == 0), - - ConditionalField(BitField("ext9", None, 1), - lambda pkt: pkt.ext8 == 0), - ConditionalField(BitField("connEle", None, 2), - lambda pkt: pkt.ext8 == 0), - ConditionalField(BitField("modemType", None, 5), - lambda pkt: pkt.ext8 == 0), - - ConditionalField(BitField("ext10", None, 1), - lambda pkt: pkt.ext9 == 0), - ConditionalField(BitField("otherModemType", None, 2), - lambda pkt: pkt.ext9 == 0), - ConditionalField(BitField("netUserRate", None, 5), - lambda pkt: pkt.ext9 == 0), - - ConditionalField(BitField("ext11", None, 1), - lambda pkt: pkt.ext10 == 0), - ConditionalField(BitField("chanCoding", None, 4), - lambda pkt: pkt.ext10 == 0), - ConditionalField(BitField("maxTrafficChan", None, 3), - lambda pkt: pkt.ext10 == 0), - - ConditionalField(BitField("ext12", None, 1), - lambda pkt: pkt.ext11 == 0), - ConditionalField(BitField("uimi", None, 3), - lambda pkt: pkt.ext11 == 0), - ConditionalField(BitField("airInterfaceUserRate", None, 4), - lambda pkt: pkt.ext11 == 0), - - ConditionalField(BitField("ext13", 0x1, 1), - lambda pkt: pkt.ext12 == 0), - ConditionalField(BitField("layer2Ch", None, 2), - lambda pkt: pkt.ext12 == 0), - ConditionalField(BitField("userInfoL2", 0x0, 5), - lambda pkt: pkt.ext12 == 0) - ] - -# We have a bug here. packet is not working if used in message - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 15, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - # avoids a bug. find better way - if len(p) is 5: - p = p[:-2] - if self.lengthBC is None: - print("len von a %s" % (len(p),)) - p = p[:1] + struct.pack(">B", len(p)-3) + p[2:] - return p + pay - - -class CallControlCapabilitiesHdr(Packet): - """Call Control Capabilities Section 10.5.4.5a""" - name = "Call Control Capabilities" - fields_desc = [ - BitField("eightBitCCC", None, 1), - XBitField("ieiCCC", None, 7), - XByteField("lengthCCC", 0x3), - BitField("spare", 0x0, 6), - BitField("pcp", 0x0, 1), - BitField("dtmf", 0x0, 1) - ] - - -class CallStateHdr(Packet): - """Call State Section 10.5.4.6""" - name = "Call State" - fields_desc = [ - BitField("eightBitCS", None, 1), - XBitField("ieiCS", None, 7), - BitField("codingStd", 0x0, 2), - BitField("stateValue", 0x0, 6) - ] - - -# len 3 to 43 -class CalledPartyBcdNumberHdr(Packet): - """Called party BCD number Section 10.5.4.7""" - name = "Called Party BCD Number" - fields_desc = [ - BitField("eightBitCPBN", None, 1), - XBitField("ieiCPBN", None, 7), - XByteField("lengthCPBN", None), - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("nbPlanId", 0x0, 4), - # optional - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4), - - BitField("nbDigit22", None, 4), - BitField("nbDigit21", None, 4), - BitField("nbDigit24", None, 4), - BitField("nbDigit23", None, 4), - - BitField("nbDigit26", None, 4), - BitField("nbDigit25", None, 4), - BitField("nbDigit28", None, 4), - BitField("nbDigit27", None, 4), - - BitField("nbDigit30", None, 4), - BitField("nbDigit29", None, 4), - BitField("nbDigit32", None, 4), - BitField("nbDigit31", None, 4), - - BitField("nbDigit34", None, 4), - BitField("nbDigit33", None, 4), - BitField("nbDigit36", None, 4), - BitField("nbDigit35", None, 4), - - BitField("nbDigit38", None, 4), - BitField("nbDigit37", None, 4), - BitField("nbDigit40", None, 4), - BitField("nbDigit39", None, 4), -# ^^^^^^ 20 first optional bytes ^^^^^^^^^^^^^^^ - BitField("nbDigit42", None, 4), - BitField("nbDigit41", None, 4), - BitField("nbDigit44", None, 4), - BitField("nbDigit43", None, 4), - - BitField("nbDigit46", None, 4), - BitField("nbDigit45", None, 4), - BitField("nbDigit48", None, 4), - BitField("nbDigit47", None, 4), - - BitField("nbDigit50", None, 4), - BitField("nbDigit49", None, 4), - BitField("nbDigit52", None, 4), - BitField("nbDigit51", None, 4), - - BitField("nbDigit54", None, 4), - BitField("nbDigit53", None, 4), - BitField("nbDigit56", None, 4), - BitField("nbDigit55", None, 4), - - BitField("nbDigit58", None, 4), - BitField("nbDigit57", None, 4), - BitField("nbDigit60", None, 4), - BitField("nbDigit59", None, 4), - - BitField("nbDigit62", None, 4), - BitField("nbDigit61", None, 4), - BitField("nbDigit64", None, 4), - BitField("nbDigit63", None, 4), - - BitField("nbDigit66", None, 4), - BitField("nbDigit65", None, 4), - BitField("nbDigit68", None, 4), - BitField("nbDigit67", None, 4), - - BitField("nbDigit70", None, 4), - BitField("nbDigit69", None, 4), - BitField("nbDigit72", None, 4), - BitField("nbDigit71", None, 4), - - BitField("nbDigit74", None, 4), - BitField("nbDigit73", None, 4), - BitField("nbDigit76", None, 4), - BitField("nbDigit75", None, 4), - - BitField("nbDigit78", None, 4), - BitField("nbDigit77", None, 4), - BitField("nbDigit80", None, 4), - BitField("nbDigit79", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 43, a, self.fields_desc, 2) - if self.lengthCPBN is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 2 to 23 -class CalledPartySubaddressHdr(Packet): - """Called party subaddress Section 10.5.4.8""" - name = "Called Party Subaddress" - fields_desc = [ - BitField("eightBitCPS", None, 1), - XBitField("ieiCPS", None, 7), - XByteField("lengthCPS", None), - # optional - BitField("ext", None, 1), - BitField("subAddr", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 23, a, self.fields_desc) - if self.lengthCPS is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 3 to 14 -class CallingPartyBcdNumberHdr(Packet): - """Called party subaddress Section 10.5.4.9""" - name = "Called Party Subaddress" - fields_desc = [ - BitField("eightBitCPBN", None, 1), - XBitField("ieiCPBN", None, 7), - XByteField("lengthCPBN", None), - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("nbPlanId", 0x0, 4), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("presId", None, 2), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("spare", None, 3), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("screenId", 0x0, 2), - lambda pkt: pkt.ext == 0), - - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 14, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthCPBN is None: - p = p[:1] + struct.pack(">B", len(p)-2) + p[2:] - return p + pay - - -# len 2 to 23 -class CallingPartySubaddressHdr(Packet): - """Calling party subaddress Section 10.5.4.10""" - name = "Calling Party Subaddress" - fields_desc = [ - BitField("eightBitCPS", None, 1), - XBitField("ieiCPS", None, 7), - XByteField("lengthCPS", None), - # optional - BitField("ext1", None, 1), - BitField("typeAddr", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 23, a, self.fields_desc) - if self.lengthCPS is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 4 to 32 -class CauseHdr(Packet): - """Cause Section 10.5.4.11""" - name = "Cause" - fields_desc = [ - BitField("eightBitC", None, 1), - XBitField("ieiC", None, 7), - - XByteField("lengthC", None), - - BitField("ext", 0x1, 1), - BitField("codingStd", 0x0, 2), - BitField("spare", 0x0, 1), - BitField("location", 0x0, 4), - - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("recommendation", 0x0, 7), - lambda pkt: pkt.ext == 0), - # optional - BitField("ext2", None, 1), - BitField("causeValue", None, 7), - - ByteField("diagnositc0", None), - ByteField("diagnositc1", None), - ByteField("diagnositc2", None), - ByteField("diagnositc3", None), - ByteField("diagnositc4", None), - ByteField("diagnositc5", None), - ByteField("diagnositc6", None), - ByteField("diagnositc7", None), - ByteField("diagnositc8", None), - ByteField("diagnositc9", None), - ByteField("diagnositc10", None), - ByteField("diagnositc11", None), - ByteField("diagnositc12", None), - ByteField("diagnositc13", None), - ByteField("diagnositc14", None), - ByteField("diagnositc15", None), - ByteField("diagnositc16", None), - ByteField("diagnositc17", None), - ByteField("diagnositc18", None), - ByteField("diagnositc19", None), - ByteField("diagnositc20", None), - ByteField("diagnositc21", None), - ByteField("diagnositc22", None), - ByteField("diagnositc23", None), - ByteField("diagnositc24", None), - ByteField("diagnositc25", None), - ByteField("diagnositc26", None), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 32, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthC is None: - p = p[:1] + struct.pack(">B", len(p)-2) + p[2:] - return p + pay - - -class ClirSuppressionHdr(Packet): - """CLIR suppression Section 10.5.4.11a""" - name = "Clir Suppression" - fields_desc = [ - BitField("eightBitCS", None, 1), - XBitField("ieiCS", None, 7), - ] - - -class ClirInvocationHdr(Packet): - """CLIR invocation Section 10.5.4.11b""" - name = "Clir Invocation" - fields_desc = [ - BitField("eightBitCI", None, 1), - XBitField("ieiCI", None, 7), - ] - - -class CongestionLevelHdr(Packet): - """Congestion level Section 10.5.4.12""" - name = "Congestion Level" - fields_desc = [ - XBitField("ieiCL", None, 4), - BitField("notDef", 0x0, 4) - ] - - -# Fix 1/2 len problem -class CongestionLevelAndSpareHalfOctets(Packet): - name = "Congestion Level and Spare Half Octets" - fields_desc = [ - BitField("ieiCL", 0x0, 4), - BitField("spareHalfOctets", 0x0, 4) - ] - - -# len 3 to 14 -class ConnectedNumberHdr(Packet): - """Connected number Section 10.5.4.13""" - name = "Connected Number" - fields_desc = [ - BitField("eightBitCN", None, 1), - XBitField("ieiCN", None, 7), - - XByteField("lengthCN", None), - - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("typePlanId", 0x0, 4), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("presId", None, 2), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("spare", None, 3), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("screenId", None, 2), - lambda pkt: pkt.ext == 0), - - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - sum1 = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 14, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthCN is None: - p = p[:1] + struct.pack(">B", len(p)-2) + p[2:] - return p + pay - - -# len 2 to 23 -class ConnectedSubaddressHdr(Packet): - """Connected subaddress Section 10.5.4.14""" - name = "Connected Subaddress" - fields_desc = [ - BitField("eightBitCS", None, 1), - XBitField("ieiCS", None, 7), - - XByteField("lengthCS", None), - # optional - BitField("ext", None, 1), - BitField("typeOfSub", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 23, a, self.fields_desc) - if self.lengthCS is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 2 to L3 (251) (done) -class FacilityHdr(Packet): - """Facility Section 10.5.4.15""" - name = "Facility" - fields_desc = [ - BitField("eightBitF", None, 1), - XBitField("ieiF", None, 7), - XByteField("lengthF", None), - # optional - ByteField("facilityInfo1", None), - ByteField("facilityInfo2", None), - ByteField("facilityInfo3", None), - ByteField("facilityInfo4", None), - ByteField("facilityInfo5", None), - ByteField("facilityInfo6", None), - ByteField("facilityInfo7", None), - ByteField("facilityInfo8", None), - ByteField("facilityInfo9", None), - ByteField("facilityInfo10", None), - ByteField("facilityInfo11", None), - ByteField("facilityInfo12", None), - ByteField("facilityInfo13", None), - ByteField("facilityInfo14", None), - ByteField("facilityInfo15", None), - ByteField("facilityInfo16", None), - ByteField("facilityInfo17", None), - ByteField("facilityInfo18", None), - ByteField("facilityInfo19", None), - ByteField("facilityInfo20", None), - ByteField("facilityInfo21", None), - ByteField("facilityInfo22", None), - ByteField("facilityInfo23", None), - ByteField("facilityInfo24", None), - ByteField("facilityInfo25", None), - ByteField("facilityInfo26", None), - ByteField("facilityInfo27", None), - ByteField("facilityInfo28", None), - ByteField("facilityInfo29", None), - ByteField("facilityInfo30", None), - ByteField("facilityInfo31", None), - ByteField("facilityInfo32", None), - ByteField("facilityInfo33", None), - ByteField("facilityInfo34", None), - ByteField("facilityInfo35", None), - ByteField("facilityInfo36", None), - ByteField("facilityInfo37", None), - ByteField("facilityInfo38", None), - ByteField("facilityInfo39", None), - ByteField("facilityInfo40", None), - ByteField("facilityInfo41", None), - ByteField("facilityInfo42", None), - ByteField("facilityInfo43", None), - ByteField("facilityInfo44", None), - ByteField("facilityInfo45", None), - ByteField("facilityInfo46", None), - ByteField("facilityInfo47", None), - ByteField("facilityInfo48", None), - ByteField("facilityInfo49", None), - ByteField("facilityInfo50", None), - ByteField("facilityInfo51", None), - ByteField("facilityInfo52", None), - ByteField("facilityInfo53", None), - ByteField("facilityInfo54", None), - ByteField("facilityInfo55", None), - ByteField("facilityInfo56", None), - ByteField("facilityInfo57", None), - ByteField("facilityInfo58", None), - ByteField("facilityInfo59", None), - ByteField("facilityInfo60", None), - ByteField("facilityInfo61", None), - ByteField("facilityInfo62", None), - ByteField("facilityInfo63", None), - ByteField("facilityInfo64", None), - ByteField("facilityInfo65", None), - ByteField("facilityInfo66", None), - ByteField("facilityInfo67", None), - ByteField("facilityInfo68", None), - ByteField("facilityInfo69", None), - ByteField("facilityInfo70", None), - ByteField("facilityInfo71", None), - ByteField("facilityInfo72", None), - ByteField("facilityInfo73", None), - ByteField("facilityInfo74", None), - ByteField("facilityInfo75", None), - ByteField("facilityInfo76", None), - ByteField("facilityInfo77", None), - ByteField("facilityInfo78", None), - ByteField("facilityInfo79", None), - ByteField("facilityInfo80", None), - ByteField("facilityInfo81", None), - ByteField("facilityInfo82", None), - ByteField("facilityInfo83", None), - ByteField("facilityInfo84", None), - ByteField("facilityInfo85", None), - ByteField("facilityInfo86", None), - ByteField("facilityInfo87", None), - ByteField("facilityInfo88", None), - ByteField("facilityInfo89", None), - ByteField("facilityInfo90", None), - ByteField("facilityInfo91", None), - ByteField("facilityInfo92", None), - ByteField("facilityInfo93", None), - ByteField("facilityInfo94", None), - ByteField("facilityInfo95", None), - ByteField("facilityInfo96", None), - ByteField("facilityInfo97", None), - ByteField("facilityInfo98", None), - ByteField("facilityInfo99", None), - ByteField("facilityInfo100", None), - ByteField("facilityInfo101", None), - ByteField("facilityInfo102", None), - ByteField("facilityInfo103", None), - ByteField("facilityInfo104", None), - ByteField("facilityInfo105", None), - ByteField("facilityInfo106", None), - ByteField("facilityInfo107", None), - ByteField("facilityInfo108", None), - ByteField("facilityInfo109", None), - ByteField("facilityInfo110", None), - ByteField("facilityInfo111", None), - ByteField("facilityInfo112", None), - ByteField("facilityInfo113", None), - ByteField("facilityInfo114", None), - ByteField("facilityInfo115", None), - ByteField("facilityInfo116", None), - ByteField("facilityInfo117", None), - ByteField("facilityInfo118", None), - ByteField("facilityInfo119", None), - ByteField("facilityInfo120", None), - ByteField("facilityInfo121", None), - ByteField("facilityInfo122", None), - ByteField("facilityInfo123", None), - ByteField("facilityInfo124", None), - ByteField("facilityInfo125", None), - ByteField("facilityInfo126", None), - ByteField("facilityInfo127", None), - ByteField("facilityInfo128", None), - ByteField("facilityInfo129", None), - ByteField("facilityInfo130", None), - ByteField("facilityInfo131", None), - ByteField("facilityInfo132", None), - ByteField("facilityInfo133", None), - ByteField("facilityInfo134", None), - ByteField("facilityInfo135", None), - ByteField("facilityInfo136", None), - ByteField("facilityInfo137", None), - ByteField("facilityInfo138", None), - ByteField("facilityInfo139", None), - ByteField("facilityInfo140", None), - ByteField("facilityInfo141", None), - ByteField("facilityInfo142", None), - ByteField("facilityInfo143", None), - ByteField("facilityInfo144", None), - ByteField("facilityInfo145", None), - ByteField("facilityInfo146", None), - ByteField("facilityInfo147", None), - ByteField("facilityInfo148", None), - ByteField("facilityInfo149", None), - ByteField("facilityInfo150", None), - ByteField("facilityInfo151", None), - ByteField("facilityInfo152", None), - ByteField("facilityInfo153", None), - ByteField("facilityInfo154", None), - ByteField("facilityInfo155", None), - ByteField("facilityInfo156", None), - ByteField("facilityInfo157", None), - ByteField("facilityInfo158", None), - ByteField("facilityInfo159", None), - ByteField("facilityInfo160", None), - ByteField("facilityInfo161", None), - ByteField("facilityInfo162", None), - ByteField("facilityInfo163", None), - ByteField("facilityInfo164", None), - ByteField("facilityInfo165", None), - ByteField("facilityInfo166", None), - ByteField("facilityInfo167", None), - ByteField("facilityInfo168", None), - ByteField("facilityInfo169", None), - ByteField("facilityInfo170", None), - ByteField("facilityInfo171", None), - ByteField("facilityInfo172", None), - ByteField("facilityInfo173", None), - ByteField("facilityInfo174", None), - ByteField("facilityInfo175", None), - ByteField("facilityInfo176", None), - ByteField("facilityInfo177", None), - ByteField("facilityInfo178", None), - ByteField("facilityInfo179", None), - ByteField("facilityInfo180", None), - ByteField("facilityInfo181", None), - ByteField("facilityInfo182", None), - ByteField("facilityInfo183", None), - ByteField("facilityInfo184", None), - ByteField("facilityInfo185", None), - ByteField("facilityInfo186", None), - ByteField("facilityInfo187", None), - ByteField("facilityInfo188", None), - ByteField("facilityInfo189", None), - ByteField("facilityInfo190", None), - ByteField("facilityInfo191", None), - ByteField("facilityInfo192", None), - ByteField("facilityInfo193", None), - ByteField("facilityInfo194", None), - ByteField("facilityInfo195", None), - ByteField("facilityInfo196", None), - ByteField("facilityInfo197", None), - ByteField("facilityInfo198", None), - ByteField("facilityInfo199", None), - ByteField("facilityInfo200", None), - ByteField("facilityInfo201", None), - ByteField("facilityInfo202", None), - ByteField("facilityInfo203", None), - ByteField("facilityInfo204", None), - ByteField("facilityInfo205", None), - ByteField("facilityInfo206", None), - ByteField("facilityInfo207", None), - ByteField("facilityInfo208", None), - ByteField("facilityInfo209", None), - ByteField("facilityInfo210", None), - ByteField("facilityInfo211", None), - ByteField("facilityInfo212", None), - ByteField("facilityInfo213", None), - ByteField("facilityInfo214", None), - ByteField("facilityInfo215", None), - ByteField("facilityInfo216", None), - ByteField("facilityInfo217", None), - ByteField("facilityInfo218", None), - ByteField("facilityInfo219", None), - ByteField("facilityInfo220", None), - ByteField("facilityInfo221", None), - ByteField("facilityInfo222", None), - ByteField("facilityInfo223", None), - ByteField("facilityInfo224", None), - ByteField("facilityInfo225", None), - ByteField("facilityInfo226", None), - ByteField("facilityInfo227", None), - ByteField("facilityInfo228", None), - ByteField("facilityInfo229", None), - ByteField("facilityInfo230", None), - ByteField("facilityInfo231", None), - ByteField("facilityInfo232", None), - ByteField("facilityInfo233", None), - ByteField("facilityInfo234", None), - ByteField("facilityInfo235", None), - ByteField("facilityInfo236", None), - ByteField("facilityInfo237", None), - ByteField("facilityInfo238", None), - ByteField("facilityInfo239", None), - ByteField("facilityInfo240", None), - ByteField("facilityInfo241", None), - ByteField("facilityInfo242", None), - ByteField("facilityInfo243", None), - ByteField("facilityInfo244", None), - ByteField("facilityInfo245", None), - ByteField("facilityInfo246", None), - ByteField("facilityInfo247", None), - ByteField("facilityInfo248", None), - ByteField("facilityInfo249", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 251, a, self.fields_desc) - if self.lengthF is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -#len 2 to 5 -class HighLayerCompatibilityHdr(Packet): - """High layer compatibility Section 10.5.4.16""" - name = "High Layer Compatibility" - fields_desc = [ - BitField("eightBitHLC", None, 1), - XBitField("ieiHLC", None, 7), - - XByteField("lengthHLC", None), - # optional - BitField("ext", None, 1), - BitField("codingStd", None, 2), - BitField("interpret", None, 3), - BitField("presMeth", None, 2), - - BitField("ext1", None, 1), - BitField("highLayerId", None, 7), - - ConditionalField(BitField("ext2", 0x1, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("exHiLayerId", 0x0, 7), - lambda pkt: pkt.ext1 == 0) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 5, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthHLC is None: - p = p[:1] + struct.pack(">B", len(p)-2) + p[2:] - return p + pay -# -# 10.5.4.16.1 Static conditions for the high layer -# compatibility IE contents -# - - -class KeypadFacilityHdr(Packet): - """Keypad facility Section 10.5.4.17""" - name = "Keypad Facility" - fields_desc = [ - BitField("eightBitKF", None, 1), - XBitField("ieiKF", None, 7), - BitField("spare", 0x0, 1), - BitField("keyPadInfo", 0x0, 7) - ] - - -# len 2 to 15 -class LowLayerCompatibilityHdr(Packet): - """Low layer compatibility Section 10.5.4.18""" - name = "Low Layer Compatibility" - fields_desc = [ - BitField("eightBitLLC", None, 1), - XBitField("ieiLLC", None, 7), - - XByteField("lengthLLC", None), - # optional - ByteField("rest0", None), - ByteField("rest1", None), - ByteField("rest2", None), - ByteField("rest3", None), - ByteField("rest4", None), - ByteField("rest5", None), - ByteField("rest6", None), - ByteField("rest7", None), - ByteField("rest8", None), - ByteField("rest9", None), - ByteField("rest10", None), - ByteField("rest11", None), - ByteField("rest12", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 15, a, self.fields_desc) - if self.lengthLLC is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class MoreDataHdr(Packet): - """More data Section 10.5.4.19""" - name = "More Data" - fields_desc = [ - BitField("eightBitMD", None, 1), - XBitField("ieiMD", None, 7), - ] - - -class NotificationIndicatorHdr(Packet): - """Notification indicator Section 10.5.4.20""" - name = "Notification Indicator" - fields_desc = [ - BitField("eightBitNI", None, 1), - XBitField("ieiNI", None, 7), - BitField("ext", 0x1, 1), - BitField("notifDesc", 0x0, 7) - ] - - -class ProgressIndicatorHdr(Packet): - """Progress indicator Section 10.5.4.21""" - name = "Progress Indicator" - fields_desc = [ - BitField("eightBitPI", None, 1), - XBitField("ieiPI", None, 7), - XByteField("lengthPI", 0x2), - BitField("ext", 0x1, 1), - BitField("codingStd", 0x0, 2), - BitField("spare", 0x0, 1), - BitField("location", 0x0, 4), - BitField("ext1", 0x1, 1), - BitField("progressDesc", 0x0, 7) - ] - - -class RecallTypeHdr(Packet): - """Recall type $(CCBS)$ Section 10.5.4.21a""" - name = "Recall Type $(CCBS)$" - fields_desc = [ - BitField("eightBitRT", None, 1), - XBitField("ieiRT", None, 7), - BitField("spare", 0x0, 5), - BitField("recallType", 0x0, 3) - ] - - -# len 3 to 19 -class RedirectingPartyBcdNumberHdr(Packet): - """Redirecting party BCD number Section 10.5.4.21b""" - name = "Redirecting Party BCD Number" - fields_desc = [ - BitField("eightBitRPBN", None, 1), - XBitField("ieiRPBN", None, 7), - - XByteField("lengthRPBN", None), - - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("numberingPlan", 0x0, 4), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("presId", None, 2), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("spare", None, 3), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("screenId", None, 2), - lambda pkt: pkt.ext == 0), - - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4), - - BitField("nbDigit22", None, 4), - BitField("nbDigit21", None, 4), - - BitField("nbDigit24", None, 4), - BitField("nbDigit23", None, 4), - - BitField("nbDigit26", None, 4), - BitField("nbDigit25", None, 4), - - BitField("nbDigit28", None, 4), - BitField("nbDigit27", None, 4), - - BitField("nbDigit30", None, 4), - BitField("nbDigit29", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 19, a, self.fields_desc) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthRPBN is None: - p = p[:1] + struct.pack(">B", len(p)-2) + p[2:] - return p + pay - - -# length 2 to 23 -class RedirectingPartySubaddressHdr(Packet): - """Redirecting party subaddress Section 10.5.4.21c""" - name = "Redirecting Party BCD Number" - fields_desc = [ - BitField("eightBitRPS", None, 1), - XBitField("ieiRPS", None, 7), - - XByteField("lengthRPS", None), - # optional - BitField("ext", None, 1), - BitField("typeSub", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 23, a, self.fields_desc) - if self.lengthRPS is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class RepeatIndicatorHdr(Packet): - """Repeat indicator Section 10.5.4.22""" - name = "Repeat Indicator" - fields_desc = [ - XBitField("ieiRI", None, 4), - BitField("repeatIndic", 0x0, 4) - ] - - -class ReverseCallSetupDirectionHdr(Packet): - """Reverse call setup direction Section 10.5.4.22a""" - name = "Reverse Call Setup Direction" - fields_desc = [ - ByteField("ieiRCSD", 0x0) - ] - - -# no upper length min 2(max for L3) (251) -class SetupContainerHdr(Packet): - """SETUP Container $(CCBS)$ Section 10.5.4.22b""" - name = "Setup Container $(CCBS)$" - fields_desc = [ - BitField("eightBitSC", None, 1), - XBitField("ieiSC", None, 7), - XByteField("lengthSC", None), - # optional - ByteField("mess1", None), - ByteField("mess2", None), - ByteField("mess3", None), - ByteField("mess4", None), - ByteField("mess5", None), - ByteField("mess6", None), - ByteField("mess7", None), - ByteField("mess8", None), - ByteField("mess9", None), - ByteField("mess10", None), - ByteField("mess11", None), - ByteField("mess12", None), - ByteField("mess13", None), - ByteField("mess14", None), - ByteField("mess15", None), - ByteField("mess16", None), - ByteField("mess17", None), - ByteField("mess18", None), - ByteField("mess19", None), - ByteField("mess20", None), - ByteField("mess21", None), - ByteField("mess22", None), - ByteField("mess23", None), - ByteField("mess24", None), - ByteField("mess25", None), - ByteField("mess26", None), - ByteField("mess27", None), - ByteField("mess28", None), - ByteField("mess29", None), - ByteField("mess30", None), - ByteField("mess31", None), - ByteField("mess32", None), - ByteField("mess33", None), - ByteField("mess34", None), - ByteField("mess35", None), - ByteField("mess36", None), - ByteField("mess37", None), - ByteField("mess38", None), - ByteField("mess39", None), - ByteField("mess40", None), - ByteField("mess41", None), - ByteField("mess42", None), - ByteField("mess43", None), - ByteField("mess44", None), - ByteField("mess45", None), - ByteField("mess46", None), - ByteField("mess47", None), - ByteField("mess48", None), - ByteField("mess49", None), - ByteField("mess50", None), - ByteField("mess51", None), - ByteField("mess52", None), - ByteField("mess53", None), - ByteField("mess54", None), - ByteField("mess55", None), - ByteField("mess56", None), - ByteField("mess57", None), - ByteField("mess58", None), - ByteField("mess59", None), - ByteField("mess60", None), - ByteField("mess61", None), - ByteField("mess62", None), - ByteField("mess63", None), - ByteField("mess64", None), - ByteField("mess65", None), - ByteField("mess66", None), - ByteField("mess67", None), - ByteField("mess68", None), - ByteField("mess69", None), - ByteField("mess70", None), - ByteField("mess71", None), - ByteField("mess72", None), - ByteField("mess73", None), - ByteField("mess74", None), - ByteField("mess75", None), - ByteField("mess76", None), - ByteField("mess77", None), - ByteField("mess78", None), - ByteField("mess79", None), - ByteField("mess80", None), - ByteField("mess81", None), - ByteField("mess82", None), - ByteField("mess83", None), - ByteField("mess84", None), - ByteField("mess85", None), - ByteField("mess86", None), - ByteField("mess87", None), - ByteField("mess88", None), - ByteField("mess89", None), - ByteField("mess90", None), - ByteField("mess91", None), - ByteField("mess92", None), - ByteField("mess93", None), - ByteField("mess94", None), - ByteField("mess95", None), - ByteField("mess96", None), - ByteField("mess97", None), - ByteField("mess98", None), - ByteField("mess99", None), - ByteField("mess100", None), - ByteField("mess101", None), - ByteField("mess102", None), - ByteField("mess103", None), - ByteField("mess104", None), - ByteField("mess105", None), - ByteField("mess106", None), - ByteField("mess107", None), - ByteField("mess108", None), - ByteField("mess109", None), - ByteField("mess110", None), - ByteField("mess111", None), - ByteField("mess112", None), - ByteField("mess113", None), - ByteField("mess114", None), - ByteField("mess115", None), - ByteField("mess116", None), - ByteField("mess117", None), - ByteField("mess118", None), - ByteField("mess119", None), - ByteField("mess120", None), - ByteField("mess121", None), - ByteField("mess122", None), - ByteField("mess123", None), - ByteField("mess124", None), - ByteField("mess125", None), - ByteField("mess126", None), - ByteField("mess127", None), - ByteField("mess128", None), - ByteField("mess129", None), - ByteField("mess130", None), - ByteField("mess131", None), - ByteField("mess132", None), - ByteField("mess133", None), - ByteField("mess134", None), - ByteField("mess135", None), - ByteField("mess136", None), - ByteField("mess137", None), - ByteField("mess138", None), - ByteField("mess139", None), - ByteField("mess140", None), - ByteField("mess141", None), - ByteField("mess142", None), - ByteField("mess143", None), - ByteField("mess144", None), - ByteField("mess145", None), - ByteField("mess146", None), - ByteField("mess147", None), - ByteField("mess148", None), - ByteField("mess149", None), - ByteField("mess150", None), - ByteField("mess151", None), - ByteField("mess152", None), - ByteField("mess153", None), - ByteField("mess154", None), - ByteField("mess155", None), - ByteField("mess156", None), - ByteField("mess157", None), - ByteField("mess158", None), - ByteField("mess159", None), - ByteField("mess160", None), - ByteField("mess161", None), - ByteField("mess162", None), - ByteField("mess163", None), - ByteField("mess164", None), - ByteField("mess165", None), - ByteField("mess166", None), - ByteField("mess167", None), - ByteField("mess168", None), - ByteField("mess169", None), - ByteField("mess170", None), - ByteField("mess171", None), - ByteField("mess172", None), - ByteField("mess173", None), - ByteField("mess174", None), - ByteField("mess175", None), - ByteField("mess176", None), - ByteField("mess177", None), - ByteField("mess178", None), - ByteField("mess179", None), - ByteField("mess180", None), - ByteField("mess181", None), - ByteField("mess182", None), - ByteField("mess183", None), - ByteField("mess184", None), - ByteField("mess185", None), - ByteField("mess186", None), - ByteField("mess187", None), - ByteField("mess188", None), - ByteField("mess189", None), - ByteField("mess190", None), - ByteField("mess191", None), - ByteField("mess192", None), - ByteField("mess193", None), - ByteField("mess194", None), - ByteField("mess195", None), - ByteField("mess196", None), - ByteField("mess197", None), - ByteField("mess198", None), - ByteField("mess199", None), - ByteField("mess200", None), - ByteField("mess201", None), - ByteField("mess202", None), - ByteField("mess203", None), - ByteField("mess204", None), - ByteField("mess205", None), - ByteField("mess206", None), - ByteField("mess207", None), - ByteField("mess208", None), - ByteField("mess209", None), - ByteField("mess210", None), - ByteField("mess211", None), - ByteField("mess212", None), - ByteField("mess213", None), - ByteField("mess214", None), - ByteField("mess215", None), - ByteField("mess216", None), - ByteField("mess217", None), - ByteField("mess218", None), - ByteField("mess219", None), - ByteField("mess220", None), - ByteField("mess221", None), - ByteField("mess222", None), - ByteField("mess223", None), - ByteField("mess224", None), - ByteField("mess225", None), - ByteField("mess226", None), - ByteField("mess227", None), - ByteField("mess228", None), - ByteField("mess229", None), - ByteField("mess230", None), - ByteField("mess231", None), - ByteField("mess232", None), - ByteField("mess233", None), - ByteField("mess234", None), - ByteField("mess235", None), - ByteField("mess236", None), - ByteField("mess237", None), - ByteField("mess238", None), - ByteField("mess239", None), - ByteField("mess240", None), - ByteField("mess241", None), - ByteField("mess242", None), - ByteField("mess243", None), - ByteField("mess244", None), - ByteField("mess245", None), - ByteField("mess246", None), - ByteField("mess247", None), - ByteField("mess248", None), - ByteField("mess249", None), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 251, a, self.fields_desc) - if self.lengthSC is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class SignalHdr(Packet): - """Signal Section 10.5.4.23""" - name = "Signal" - fields_desc = [ - BitField("eightBitS", None, 1), - XBitField("ieiS", None, 7), - ByteField("sigValue", 0x0) - ] - - -# length 2 to max for L3 message (251) -class SsVersionIndicatorHdr(Packet): - """SS Version Indicator Section 10.5.4.24""" - name = "SS Version Indicator" - fields_desc = [ - BitField("eightBitSVI", None, 1), - XBitField("ieiSVI", None, 7), - XByteField("lengthSVI", None), - # optional - ByteField("info1", None), - ByteField("info2", None), - ByteField("info3", None), - ByteField("info4", None), - ByteField("info5", None), - ByteField("info6", None), - ByteField("info7", None), - ByteField("info8", None), - ByteField("info9", None), - ByteField("info10", None), - ByteField("info11", None), - ByteField("info12", None), - ByteField("info13", None), - ByteField("info14", None), - ByteField("info15", None), - ByteField("info16", None), - ByteField("info17", None), - ByteField("info18", None), - ByteField("info19", None), - ByteField("info20", None), - ByteField("info21", None), - ByteField("info22", None), - ByteField("info23", None), - ByteField("info24", None), - ByteField("info25", None), - ByteField("info26", None), - ByteField("info27", None), - ByteField("info28", None), - ByteField("info29", None), - ByteField("info30", None), - ByteField("info31", None), - ByteField("info32", None), - ByteField("info33", None), - ByteField("info34", None), - ByteField("info35", None), - ByteField("info36", None), - ByteField("info37", None), - ByteField("info38", None), - ByteField("info39", None), - ByteField("info40", None), - ByteField("info41", None), - ByteField("info42", None), - ByteField("info43", None), - ByteField("info44", None), - ByteField("info45", None), - ByteField("info46", None), - ByteField("info47", None), - ByteField("info48", None), - ByteField("info49", None), - ByteField("info50", None), - ByteField("info51", None), - ByteField("info52", None), - ByteField("info53", None), - ByteField("info54", None), - ByteField("info55", None), - ByteField("info56", None), - ByteField("info57", None), - ByteField("info58", None), - ByteField("info59", None), - ByteField("info60", None), - ByteField("info61", None), - ByteField("info62", None), - ByteField("info63", None), - ByteField("info64", None), - ByteField("info65", None), - ByteField("info66", None), - ByteField("info67", None), - ByteField("info68", None), - ByteField("info69", None), - ByteField("info70", None), - ByteField("info71", None), - ByteField("info72", None), - ByteField("info73", None), - ByteField("info74", None), - ByteField("info75", None), - ByteField("info76", None), - ByteField("info77", None), - ByteField("info78", None), - ByteField("info79", None), - ByteField("info80", None), - ByteField("info81", None), - ByteField("info82", None), - ByteField("info83", None), - ByteField("info84", None), - ByteField("info85", None), - ByteField("info86", None), - ByteField("info87", None), - ByteField("info88", None), - ByteField("info89", None), - ByteField("info90", None), - ByteField("info91", None), - ByteField("info92", None), - ByteField("info93", None), - ByteField("info94", None), - ByteField("info95", None), - ByteField("info96", None), - ByteField("info97", None), - ByteField("info98", None), - ByteField("info99", None), - ByteField("info100", None), - ByteField("info101", None), - ByteField("info102", None), - ByteField("info103", None), - ByteField("info104", None), - ByteField("info105", None), - ByteField("info106", None), - ByteField("info107", None), - ByteField("info108", None), - ByteField("info109", None), - ByteField("info110", None), - ByteField("info111", None), - ByteField("info112", None), - ByteField("info113", None), - ByteField("info114", None), - ByteField("info115", None), - ByteField("info116", None), - ByteField("info117", None), - ByteField("info118", None), - ByteField("info119", None), - ByteField("info120", None), - ByteField("info121", None), - ByteField("info122", None), - ByteField("info123", None), - ByteField("info124", None), - ByteField("info125", None), - ByteField("info126", None), - ByteField("info127", None), - ByteField("info128", None), - ByteField("info129", None), - ByteField("info130", None), - ByteField("info131", None), - ByteField("info132", None), - ByteField("info133", None), - ByteField("info134", None), - ByteField("info135", None), - ByteField("info136", None), - ByteField("info137", None), - ByteField("info138", None), - ByteField("info139", None), - ByteField("info140", None), - ByteField("info141", None), - ByteField("info142", None), - ByteField("info143", None), - ByteField("info144", None), - ByteField("info145", None), - ByteField("info146", None), - ByteField("info147", None), - ByteField("info148", None), - ByteField("info149", None), - ByteField("info150", None), - ByteField("info151", None), - ByteField("info152", None), - ByteField("info153", None), - ByteField("info154", None), - ByteField("info155", None), - ByteField("info156", None), - ByteField("info157", None), - ByteField("info158", None), - ByteField("info159", None), - ByteField("info160", None), - ByteField("info161", None), - ByteField("info162", None), - ByteField("info163", None), - ByteField("info164", None), - ByteField("info165", None), - ByteField("info166", None), - ByteField("info167", None), - ByteField("info168", None), - ByteField("info169", None), - ByteField("info170", None), - ByteField("info171", None), - ByteField("info172", None), - ByteField("info173", None), - ByteField("info174", None), - ByteField("info175", None), - ByteField("info176", None), - ByteField("info177", None), - ByteField("info178", None), - ByteField("info179", None), - ByteField("info180", None), - ByteField("info181", None), - ByteField("info182", None), - ByteField("info183", None), - ByteField("info184", None), - ByteField("info185", None), - ByteField("info186", None), - ByteField("info187", None), - ByteField("info188", None), - ByteField("info189", None), - ByteField("info190", None), - ByteField("info191", None), - ByteField("info192", None), - ByteField("info193", None), - ByteField("info194", None), - ByteField("info195", None), - ByteField("info196", None), - ByteField("info197", None), - ByteField("info198", None), - ByteField("info199", None), - ByteField("info200", None), - ByteField("info201", None), - ByteField("info202", None), - ByteField("info203", None), - ByteField("info204", None), - ByteField("info205", None), - ByteField("info206", None), - ByteField("info207", None), - ByteField("info208", None), - ByteField("info209", None), - ByteField("info210", None), - ByteField("info211", None), - ByteField("info212", None), - ByteField("info213", None), - ByteField("info214", None), - ByteField("info215", None), - ByteField("info216", None), - ByteField("info217", None), - ByteField("info218", None), - ByteField("info219", None), - ByteField("info220", None), - ByteField("info221", None), - ByteField("info222", None), - ByteField("info223", None), - ByteField("info224", None), - ByteField("info225", None), - ByteField("info226", None), - ByteField("info227", None), - ByteField("info228", None), - ByteField("info229", None), - ByteField("info230", None), - ByteField("info231", None), - ByteField("info232", None), - ByteField("info233", None), - ByteField("info234", None), - ByteField("info235", None), - ByteField("info236", None), - ByteField("info237", None), - ByteField("info238", None), - ByteField("info239", None), - ByteField("info240", None), - ByteField("info241", None), - ByteField("info242", None), - ByteField("info243", None), - ByteField("info244", None), - ByteField("info245", None), - ByteField("info246", None), - ByteField("info247", None), - ByteField("info248", None), - ByteField("info249", None), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 251, a, self.fields_desc) - if self.lengthSVI is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# length 3 to 35 or 131 -class UserUserHdr(Packet): - """User-user Section 10.5.4.25""" - name = "User-User" - fields_desc = [ - BitField("eightBitUU", None, 1), - XBitField("ieiUU", None, 7), - - XByteField("lengthUU", None), # dynamic length of field depending - # of the type of message - # let user decide which length he - # wants to take - # => more fuzzing options - ByteField("userUserPD", 0x0), - # optional - ByteField("userUserInfo1", None), - ByteField("userUserInfo2", None), - ByteField("userUserInfo3", None), - ByteField("userUserInfo4", None), - ByteField("userUserInfo5", None), - ByteField("userUserInfo6", None), - ByteField("userUserInfo7", None), - ByteField("userUserInfo8", None), - ByteField("userUserInfo9", None), - ByteField("userUserInfo10", None), - ByteField("userUserInfo11", None), - ByteField("userUserInfo12", None), - ByteField("userUserInfo13", None), - ByteField("userUserInfo14", None), - ByteField("userUserInfo15", None), - ByteField("userUserInfo16", None), - ByteField("userUserInfo17", None), - ByteField("userUserInfo18", None), - ByteField("userUserInfo19", None), - ByteField("userUserInfo20", None), - ByteField("userUserInfo21", None), - ByteField("userUserInfo22", None), - ByteField("userUserInfo23", None), - ByteField("userUserInfo24", None), - ByteField("userUserInfo25", None), - ByteField("userUserInfo26", None), - ByteField("userUserInfo27", None), - ByteField("userUserInfo28", None), - ByteField("userUserInfo29", None), - ByteField("userUserInfo30", None), - ByteField("userUserInfo31", None), - ByteField("userUserInfo32", None), - # long packet - ByteField("userUserInfo33", None), - ByteField("userUserInfo34", None), - ByteField("userUserInfo35", None), - ByteField("userUserInfo36", None), - ByteField("userUserInfo37", None), - ByteField("userUserInfo38", None), - ByteField("userUserInfo39", None), - ByteField("userUserInfo40", None), - ByteField("userUserInfo41", None), - ByteField("userUserInfo42", None), - ByteField("userUserInfo43", None), - ByteField("userUserInfo44", None), - ByteField("userUserInfo45", None), - ByteField("userUserInfo46", None), - ByteField("userUserInfo47", None), - ByteField("userUserInfo48", None), - ByteField("userUserInfo49", None), - ByteField("userUserInfo50", None), - ByteField("userUserInfo51", None), - ByteField("userUserInfo52", None), - ByteField("userUserInfo53", None), - ByteField("userUserInfo54", None), - ByteField("userUserInfo55", None), - ByteField("userUserInfo56", None), - ByteField("userUserInfo57", None), - ByteField("userUserInfo58", None), - ByteField("userUserInfo59", None), - ByteField("userUserInfo60", None), - ByteField("userUserInfo61", None), - ByteField("userUserInfo62", None), - ByteField("userUserInfo63", None), - ByteField("userUserInfo64", None), - ByteField("userUserInfo65", None), - ByteField("userUserInfo66", None), - ByteField("userUserInfo67", None), - ByteField("userUserInfo68", None), - ByteField("userUserInfo69", None), - ByteField("userUserInfo70", None), - ByteField("userUserInfo71", None), - ByteField("userUserInfo72", None), - ByteField("userUserInfo73", None), - ByteField("userUserInfo74", None), - ByteField("userUserInfo75", None), - ByteField("userUserInfo76", None), - ByteField("userUserInfo77", None), - ByteField("userUserInfo78", None), - ByteField("userUserInfo79", None), - ByteField("userUserInfo80", None), - ByteField("userUserInfo81", None), - ByteField("userUserInfo82", None), - ByteField("userUserInfo83", None), - ByteField("userUserInfo84", None), - ByteField("userUserInfo85", None), - ByteField("userUserInfo86", None), - ByteField("userUserInfo87", None), - ByteField("userUserInfo88", None), - ByteField("userUserInfo89", None), - ByteField("userUserInfo90", None), - ByteField("userUserInfo91", None), - ByteField("userUserInfo92", None), - ByteField("userUserInfo93", None), - ByteField("userUserInfo94", None), - ByteField("userUserInfo95", None), - ByteField("userUserInfo96", None), - ByteField("userUserInfo97", None), - ByteField("userUserInfo98", None), - ByteField("userUserInfo99", None), - ByteField("userUserInfo100", None), - ByteField("userUserInfo101", None), - ByteField("userUserInfo102", None), - ByteField("userUserInfo103", None), - ByteField("userUserInfo104", None), - ByteField("userUserInfo105", None), - ByteField("userUserInfo106", None), - ByteField("userUserInfo107", None), - ByteField("userUserInfo108", None), - ByteField("userUserInfo109", None), - ByteField("userUserInfo110", None), - ByteField("userUserInfo111", None), - ByteField("userUserInfo112", None), - ByteField("userUserInfo113", None), - ByteField("userUserInfo114", None), - ByteField("userUserInfo115", None), - ByteField("userUserInfo116", None), - ByteField("userUserInfo117", None), - ByteField("userUserInfo118", None), - ByteField("userUserInfo119", None), - ByteField("userUserInfo120", None), - ByteField("userUserInfo121", None), - ByteField("userUserInfo122", None), - ByteField("userUserInfo123", None), - ByteField("userUserInfo124", None), - ByteField("userUserInfo125", None), - ByteField("userUserInfo126", None), - ByteField("userUserInfo127", None), - ByteField("userUserInfo128", None), - ByteField("userUserInfo129", None), - ByteField("userUserInfo130", None), - ByteField("userUserInfo131", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 131, a, self.fields_desc) - if self.lengthUU is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class AlertingPatternHdr(Packet): - """Alerting Pattern 10.5.4.26""" - name = "Alerting Pattern" - fields_desc = [ - BitField("eightBitAP", None, 1), - XBitField("ieiAP", None, 7), - XByteField("lengthAP", 0x3), - BitField("spare", 0x0, 4), - BitField("alertingValue", 0x0, 4) - ] - - -class AllowedActionsHdr(Packet): - """Allowed actions $(CCBS)$ Section 10.5.4.26""" - name = "Allowed Actions $(CCBS)$" - fields_desc = [ - BitField("eightBitAA", None, 1), - XBitField("ieiAA", None, 7), - XByteField("lengthAP", 0x3), - BitField("CCBS", 0x0, 1), - BitField("spare", 0x0, 7) - ] - - -# -# 10.5.5 GPRS mobility management information elements -# - -class AttachResult(Packet): - """Attach result Section 10.5.5.1""" - name = "Attach Result" - fields_desc = [ - XBitField("ieiAR", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("result", 0x1, 3) - ] - - -class AttachTypeHdr(Packet): - """Attach type Section 10.5.5.2""" - name = "Attach Type" - fields_desc = [ - XBitField("ieiAT", None, 4), - BitField("spare", 0x0, 1), - BitField("type", 0x1, 3) - ] - - -# Fix 1/2 len problem -class AttachTypeAndCiphKeySeqNr(Packet): - name = "Attach Type and Cipher Key Sequence Number" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("type", 0x1, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class CipheringAlgorithm(Packet): - """Ciphering algorithm Section 10.5.5.3""" - name = "Ciphering Algorithm" - fields_desc = [ - XBitField("ieiCA", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("type", 0x1, 3) - ] - - -# Fix 1/2 len problem -class CipheringAlgorithmAndImeisvRequest(Packet): - name = "Ciphering Algorithm and Imeisv Request" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("type", 0x1, 3), - BitField("spare", 0x0, 1), - BitField("imeisvVal", 0x0, 3) - ] - - -# [Spare] -class TmsiStatus(Packet): - """[Spare] TMSI status Section 10.5.5.4""" - name = "[Spare] TMSI Status" - fields_desc = [ - XBitField("ieiTS", None, 4), - BitField("spare", 0x0, 3), - BitField("flag", 0x1, 1) - ] - - -class DetachType(Packet): - """Detach type Section 10.5.5.5""" - name = "Detach Type" - fields_desc = [ - XBitField("ieiDT", 0x0, 4), - BitField("poweroff", 0x0, 1), - BitField("type", 0x1, 3) - ] - - -# Fix 1/2 len problem -class DetachTypeAndForceToStandby(Packet): - name = "Detach Type and Force To Standby" - fields_desc = [ - BitField("poweroff", 0x0, 1), - BitField("type", 0x1, 3), - BitField("spare", 0x0, 1), - BitField("forceStandby", 0x0, 3) - ] - - -# Fix 1/2 len problem -class DetachTypeAndSpareHalfOctets(Packet): - name = "Detach Type and Spare Half Octets" - fields_desc = [ - BitField("poweroff", 0x0, 1), - BitField("type", 0x1, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class DrxParameter(Packet): - """DRX parameter Section 10.5.5.6""" - name = "DRX Parameter" - fields_desc = [ - ByteField("ieiDP", 0x0), - ByteField("splitPG", 0x0), - BitField("spare", 0x0, 4), - BitField("splitCCCH", 0x0, 1), - BitField("NonDrxTimer", 0x1, 3) - ] - - -class ForceToStandby(Packet): - """Force to standby Section 10.5.5.7""" - name = "Force To Standby" - fields_desc = [ - XBitField("ieiFTS", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("forceStandby", 0x0, 3) - ] - - -# Fix 1/2 len problem -class ForceToStandbyAndAcReferenceNumber(Packet): - name = "Force To Standby And Ac Reference Number" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("forceStandby", 0x0, 3), - BitField("acRefVal", 0x0, 4) - ] - - -# Fix 1/2 len problem -class ForceToStandbyAndUpdateResult(Packet): - name = "Force To Standby And Update Result" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("forceStandby", 0x0, 3), - BitField("spare", 0x0, 1), - BitField("updateResVal", 0x0, 3) - ] - - -# Fix 1/2 len problem -class ForceToStandbyAndSpareHalfOctets(Packet): - name = "Force To Standby And Spare Half Octets" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("forceStandby", 0x0, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class PTmsiSignature(Packet): - """P-TMSI signature Section 10.5.5.8""" - name = "P-TMSI Signature" - fields_desc = [ - ByteField("ieiPTS", 0x0), - BitField("sgnature", 0x0, 24) - ] - - -class IdentityType2(Packet): - """Identity type 2 Section 10.5.5.9""" - name = "Identity Type 2" - fields_desc = [ - XBitField("ieiIT2", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("typeOfIdentity", 0x0, 3) - ] - - -# Fix 1/2 len problem -class IdentityType2AndforceToStandby(Packet): - name = "Identity Type 2 and Force to Standby" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("typeOfIdentity", 0x0, 3), - BitField("spare", 0x0, 1), - BitField("forceStandby", 0x0, 3) - ] - - -class ImeisvRequest(Packet): - """IMEISV request Section 10.5.5.10""" - name = "IMEISV Request" - fields_desc = [ - XBitField("ieiIR", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("imeisvVal", 0x0, 3) - ] - - -# Fix 1/2 len problem -class ImeisvRequestAndForceToStandby(Packet): - name = "IMEISV Request and Force To Standby" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("imeisvVal", 0x0, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -# length 4 to 19 -class ReceiveNpduNumbersList(Packet): - """Receive N-PDU Numbers list Section 10.5.5.11""" - name = "Receive N-PDU Numbers list" - fields_desc = [ - ByteField("ieiRNNL", 0x0), - - XByteField("lengthRNNL", None), - - BitField("nbList0", 0x0, 16), - # optional - ByteField("nbList1", None), - ByteField("nbList2", None), - ByteField("nbList3", None), - ByteField("nbList4", None), - ByteField("nbList5", None), - ByteField("nbList6", None), - ByteField("nbList7", None), - ByteField("nbList8", None), - ByteField("nbList9", None), - ByteField("nbList10", None), - ByteField("nbList11", None), - ByteField("nbList12", None), - ByteField("nbList13", None), - ByteField("nbList14", None), - ByteField("nbList15", None), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 19, a, self.fields_desc) - if self.lengthRNNL is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class MsNetworkCapability(Packet): - """MS network capability Section 10.5.5.12""" - name = "MS Network Capability" - fields_desc = [ - ByteField("ieiMNC", 0x0), - XByteField("lengthMNC", 0x3), - ByteField("msNetValue", 0x0) - ] - - -# length 6 to 14 -class MsRadioAccessCapability(Packet): - """MS Radio Access capability Section 10.5.5.12a""" - name = "MS Radio Access Capability" - fields_desc = [ - ByteField("ieiMRAC", 0x24), - - XByteField("lengthMRAC", None), - - BitField("spare1", 0x0, 1), # ... - - BitField("accessCap", 0x0, 4), - BitField("accessTechType", 0x0, 4), - # access capability - BitField("bool", 0x0, 1), - BitField("lengthContent", 0x0, 7), - BitField("spare1", 0x0, 1), # ... - # content - BitField("pwrCap", 0x0, 3), - BitField("bool1", 0x0, 1), - BitField("a51", 0x0, 1), - BitField("a52", 0x0, 1), - BitField("a53", 0x0, 1), - BitField("a54", 0x0, 1), - - BitField("a55", 0x0, 1), - BitField("a56", 0x0, 1), - BitField("a57", 0x0, 1), - BitField("esInd", 0x0, 1), - BitField("ps", 0x0, 1), - BitField("vgcs", 0x0, 1), - BitField("vbs", 0x0, 1), - BitField("bool2", 0x0, 1), - # multislot - BitField("bool3", 0x0, 1), - BitField("hscsd", 0x0, 5), - - BitField("bool4", 0x0, 1), - BitField("gprs", 0x0, 5), - BitField("gprsExt", 0x0, 1), - BitField("bool5", 0x0, 1), - - BitField("smsVal", 0x0, 4), - BitField("smVal", 0x0, 4) - ] - - -# 10.5.5.13 Spare -# This is intentionally left spare. - -class GmmCause(Packet): - """GMM cause Section 10.5.5.14""" - name = "GMM Cause" - fields_desc = [ - ByteField("ieiGC", 0x0), - ByteField("causeValue", 0x0) - ] - - -class RoutingAreaIdentification(Packet): - """Routing area identification Section 10.5.5.15""" - name = "Routing Area Identification" - fields_desc = [ - ByteField("ieiRAI", 0x0), - BitField("mccDigit2", 0x0, 4), - BitField("mccDigit1", 0x0, 4), - BitField("mncDigit3", 0x0, 4), - BitField("mccDigit3", 0x0, 4), - BitField("mccDigit2", 0x0, 4), - BitField("mccDigit1", 0x0, 4), - ByteField("LAC", 0x0), - ByteField("LAC1", 0x0), - ByteField("LAC", 0x0) - ] -# 10.5.5.16 Spare -# This is intentionally left spare. - - -class UpdateResult(Packet): - """Update result Section 10.5.5.17""" - name = "Update Result" - fields_desc = [ - XBitField("ieiUR", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("updateResVal", 0x0, 3) - ] - - -class UpdateType(Packet): - """Update type Section 10.5.5.18""" - name = "Update Type" - fields_desc = [ - XBitField("ieiUT", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("updateTypeVal", 0x0, 3) - ] - - -# Fix 1/2 len problem -class UpdateTypeAndCiphKeySeqNr(Packet): - name = "Update Type and Cipher Key Sequence Number" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("updateTypeVal", 0x0, 3), - BitField("spare", 0x0, 1), - BitField("keySeq", 0x0, 3) - ] - - -class AcReferenceNumber(Packet): - """A&C reference number Section 10.5.5.19""" - name = "A&C Reference Number" - fields_desc = [ - XBitField("ieiARN", 0x0, 4), - BitField("acRefVal", 0x0, 4) - ] - - -# Fix 1/2 len problem -class AcReferenceNumberAndSpareHalfOctets(Packet): - name = "A&C Reference Number and Spare Half Octets" - fields_desc = [ - BitField("acRefVal", 0x0, 4), - BitField("spareHalfOctets", 0x0, 4) - ] -# -# 10.5.6 Session management information elements -# -# length 3 to 102 - - -class AccessPointName(Packet): - """Access Point Name Section 10.5.6.1""" - name = "Access Point Name" - fields_desc = [ - ByteField("ieiAPN", 0x0), - XByteField("lengthAPN", None), - ByteField("apName", 0x0), - # optional - ByteField("apName1", None), - ByteField("apName2", None), - ByteField("apName3", None), - ByteField("apName4", None), - ByteField("apName5", None), - ByteField("apName6", None), - ByteField("apName7", None), - ByteField("apName8", None), - ByteField("apName9", None), - ByteField("apName10", None), - ByteField("apName11", None), - ByteField("apName12", None), - ByteField("apName13", None), - ByteField("apName14", None), - ByteField("apName15", None), - ByteField("apName16", None), - ByteField("apName17", None), - ByteField("apName18", None), - ByteField("apName19", None), - ByteField("apName20", None), - ByteField("apName21", None), - ByteField("apName22", None), - ByteField("apName23", None), - ByteField("apName24", None), - ByteField("apName25", None), - ByteField("apName26", None), - ByteField("apName27", None), - ByteField("apName28", None), - ByteField("apName29", None), - ByteField("apName30", None), - ByteField("apName31", None), - ByteField("apName32", None), - ByteField("apName33", None), - ByteField("apName34", None), - ByteField("apName35", None), - ByteField("apName36", None), - ByteField("apName37", None), - ByteField("apName38", None), - ByteField("apName39", None), - ByteField("apName40", None), - ByteField("apName41", None), - ByteField("apName42", None), - ByteField("apName43", None), - ByteField("apName44", None), - ByteField("apName45", None), - ByteField("apName46", None), - ByteField("apName47", None), - ByteField("apName48", None), - ByteField("apName49", None), - ByteField("apName50", None), - ByteField("apName51", None), - ByteField("apName52", None), - ByteField("apName53", None), - ByteField("apName54", None), - ByteField("apName55", None), - ByteField("apName56", None), - ByteField("apName57", None), - ByteField("apName58", None), - ByteField("apName59", None), - ByteField("apName60", None), - ByteField("apName61", None), - ByteField("apName62", None), - ByteField("apName63", None), - ByteField("apName64", None), - ByteField("apName65", None), - ByteField("apName66", None), - ByteField("apName67", None), - ByteField("apName68", None), - ByteField("apName69", None), - ByteField("apName70", None), - ByteField("apName71", None), - ByteField("apName72", None), - ByteField("apName73", None), - ByteField("apName74", None), - ByteField("apName75", None), - ByteField("apName76", None), - ByteField("apName77", None), - ByteField("apName78", None), - ByteField("apName79", None), - ByteField("apName80", None), - ByteField("apName81", None), - ByteField("apName82", None), - ByteField("apName83", None), - ByteField("apName84", None), - ByteField("apName85", None), - ByteField("apName86", None), - ByteField("apName87", None), - ByteField("apName88", None), - ByteField("apName89", None), - ByteField("apName90", None), - ByteField("apName91", None), - ByteField("apName92", None), - ByteField("apName93", None), - ByteField("apName94", None), - ByteField("apName95", None), - ByteField("apName96", None), - ByteField("apName97", None), - ByteField("apName98", None), - ByteField("apName99", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 102, a, self.fields_desc) - if self.lengthAPN is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class NetworkServiceAccessPointIdentifier(Packet): - """Network service access point identifier Section 10.5.6.2""" - name = "Network Service Access Point Identifier" - fields_desc = [ - ByteField("ieiNSAPI", 0x0), - BitField("spare", 0x0, 4), - BitField("nsapiVal", 0x0, 4) - ] - - -# length 2 to 253 -class ProtocolConfigurationOptions(Packet): - """Protocol configuration options Section 10.5.6.3""" - name = "Protocol Configuration Options" - fields_desc = [ - ByteField("ieiPCO", 0x0), - - XByteField("lengthPCO", None), - # optional - BitField("ext", None, 1), - BitField("spare", None, 4), - BitField("configProto", None, 3), - - ByteField("protoId1", None), - ByteField("lenProto1", None), - ByteField("proto1Content", None), - - ByteField("protoId2", None), - ByteField("lenProto2", None), - ByteField("proto2Content", None), - - ByteField("protoId3", None), - ByteField("lenProto3", None), - ByteField("proto3Content", None), - - ByteField("protoId4", None), - ByteField("lenProto4", None), - ByteField("proto4Content", None), - - - ByteField("protoId5", None), - ByteField("lenProto5", None), - ByteField("proto5Content", None), - - ByteField("protoId6", None), - ByteField("lenProto6", None), - ByteField("proto6Content", None), - - ByteField("protoId7", None), - ByteField("lenProto7", None), - ByteField("proto7Content", None), - - ByteField("protoId8", None), - ByteField("lenProto8", None), - ByteField("proto8Content", None), - - ByteField("protoId9", None), - ByteField("lenProto9", None), - ByteField("proto9Content", None), - - ByteField("protoId10", None), - ByteField("lenProto10", None), - ByteField("proto10Content", None), - - ByteField("protoId11", None), - ByteField("lenProto11", None), - ByteField("proto11Content", None), - - ByteField("protoId12", None), - ByteField("lenProto12", None), - ByteField("proto12Content", None), - - ByteField("protoId13", None), - ByteField("lenProto13", None), - ByteField("proto13Content", None), - - ByteField("protoId14", None), - ByteField("lenProto14", None), - ByteField("proto14Content", None), - - ByteField("protoId15", None), - ByteField("lenProto15", None), - ByteField("proto15Content", None), - - ByteField("protoId16", None), - ByteField("lenProto16", None), - ByteField("proto16Content", None), - - ByteField("protoId17", None), - ByteField("lenProto17", None), - ByteField("proto17Content", None), - - ByteField("protoId18", None), - ByteField("lenProto18", None), - ByteField("proto18Content", None), - - ByteField("protoId19", None), - ByteField("lenProto19", None), - ByteField("proto19Content", None), - - ByteField("protoId20", None), - ByteField("lenProto20", None), - ByteField("proto20Content", None), - - ByteField("protoId21", None), - ByteField("lenProto21", None), - ByteField("proto21Content", None), - - ByteField("protoId22", None), - ByteField("lenProto22", None), - ByteField("proto22Content", None), - - ByteField("protoId23", None), - ByteField("lenProto23", None), - ByteField("proto23Content", None), - - ByteField("protoId24", None), - ByteField("lenProto24", None), - ByteField("proto24Content", None), - - ByteField("protoId25", None), - ByteField("lenProto25", None), - ByteField("proto25Content", None), - - ByteField("protoId26", None), - ByteField("lenProto26", None), - ByteField("proto26Content", None), - - ByteField("protoId27", None), - ByteField("lenProto27", None), - ByteField("proto27Content", None), - - ByteField("protoId28", None), - ByteField("lenProto28", None), - ByteField("proto28Content", None), - - ByteField("protoId29", None), - ByteField("lenProto29", None), - ByteField("proto29Content", None), - - ByteField("protoId30", None), - ByteField("lenProto30", None), - ByteField("proto30Content", None), - - ByteField("protoId31", None), - ByteField("lenProto31", None), - ByteField("proto31Content", None), - - ByteField("protoId32", None), - ByteField("lenProto32", None), - ByteField("proto32Content", None), - - ByteField("protoId33", None), - ByteField("lenProto33", None), - ByteField("proto33Content", None), - - ByteField("protoId34", None), - ByteField("lenProto34", None), - ByteField("proto34Content", None), - - ByteField("protoId35", None), - ByteField("lenProto35", None), - ByteField("proto35Content", None), - - ByteField("protoId36", None), - ByteField("lenProto36", None), - ByteField("proto36Content", None), - - ByteField("protoId37", None), - ByteField("lenProto37", None), - ByteField("proto37Content", None), - - ByteField("protoId38", None), - ByteField("lenProto38", None), - ByteField("proto38Content", None), - - ByteField("protoId39", None), - ByteField("lenProto39", None), - ByteField("proto39Content", None), - - ByteField("protoId40", None), - ByteField("lenProto40", None), - ByteField("proto40Content", None), - - ByteField("protoId41", None), - ByteField("lenProto41", None), - ByteField("proto41Content", None), - - ByteField("protoId42", None), - ByteField("lenProto42", None), - ByteField("proto42Content", None), - - ByteField("protoId43", None), - ByteField("lenProto43", None), - ByteField("proto43Content", None), - - ByteField("protoId44", None), - ByteField("lenProto44", None), - ByteField("proto44Content", None), - - ByteField("protoId45", None), - ByteField("lenProto45", None), - ByteField("proto45Content", None), - - ByteField("protoId46", None), - ByteField("lenProto46", None), - ByteField("proto46Content", None), - - ByteField("protoId47", None), - ByteField("lenProto47", None), - ByteField("proto47Content", None), - - ByteField("protoId48", None), - ByteField("lenProto48", None), - ByteField("proto48Content", None), - - ByteField("protoId49", None), - ByteField("lenProto49", None), - ByteField("proto49Content", None), - - ByteField("protoId50", None), - ByteField("lenProto50", None), - ByteField("proto50Content", None), - - ByteField("protoId51", None), - ByteField("lenProto51", None), - ByteField("proto51Content", None), - - ByteField("protoId52", None), - ByteField("lenProto52", None), - ByteField("proto52Content", None), - - ByteField("protoId53", None), - ByteField("lenProto53", None), - ByteField("proto53Content", None), - - ByteField("protoId54", None), - ByteField("lenProto54", None), - ByteField("proto54Content", None), - - ByteField("protoId55", None), - ByteField("lenProto55", None), - ByteField("proto55Content", None), - - ByteField("protoId56", None), - ByteField("lenProto56", None), - ByteField("proto56Content", None), - - ByteField("protoId57", None), - ByteField("lenProto57", None), - ByteField("proto57Content", None), - - ByteField("protoId58", None), - ByteField("lenProto58", None), - ByteField("proto58Content", None), - - ByteField("protoId59", None), - ByteField("lenProto59", None), - ByteField("proto59Content", None), - - ByteField("protoId60", None), - ByteField("lenProto60", None), - ByteField("proto60Content", None), - - ByteField("protoId61", None), - ByteField("lenProto61", None), - ByteField("proto61Content", None), - - ByteField("protoId62", None), - ByteField("lenProto62", None), - ByteField("proto62Content", None), - - ByteField("protoId63", None), - ByteField("lenProto63", None), - ByteField("proto63Content", None), - - ByteField("protoId64", None), - ByteField("lenProto64", None), - ByteField("proto64Content", None), - - ByteField("protoId65", None), - ByteField("lenProto65", None), - ByteField("proto65Content", None), - - ByteField("protoId66", None), - ByteField("lenProto66", None), - ByteField("proto66Content", None), - - ByteField("protoId67", None), - ByteField("lenProto67", None), - ByteField("proto67Content", None), - - ByteField("protoId68", None), - ByteField("lenProto68", None), - ByteField("proto68Content", None), - - ByteField("protoId69", None), - ByteField("lenProto69", None), - ByteField("proto69Content", None), - - ByteField("protoId70", None), - ByteField("lenProto70", None), - ByteField("proto70Content", None), - - ByteField("protoId71", None), - ByteField("lenProto71", None), - ByteField("proto71Content", None), - - ByteField("protoId72", None), - ByteField("lenProto72", None), - ByteField("proto72Content", None), - - ByteField("protoId73", None), - ByteField("lenProto73", None), - ByteField("proto73Content", None), - - ByteField("protoId74", None), - ByteField("lenProto74", None), - ByteField("proto74Content", None), - - ByteField("protoId75", None), - ByteField("lenProto75", None), - ByteField("proto75Content", None), - - ByteField("protoId76", None), - ByteField("lenProto76", None), - ByteField("proto76Content", None), - - ByteField("protoId77", None), - ByteField("lenProto77", None), - ByteField("proto77Content", None), - - ByteField("protoId78", None), - ByteField("lenProto78", None), - ByteField("proto78Content", None), - - ByteField("protoId79", None), - ByteField("lenProto79", None), - ByteField("proto79Content", None), - - ByteField("protoId80", None), - ByteField("lenProto80", None), - ByteField("proto80Content", None), - - ByteField("protoId81", None), - ByteField("lenProto81", None), - ByteField("proto81Content", None), - - ByteField("protoId82", None), - ByteField("lenProto82", None), - ByteField("proto82Content", None), - - ByteField("protoId83", None), - ByteField("lenProto83", None), - ByteField("proto83Content", None), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 253, a, self.fields_desc) - if self.lengthPCO is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 4 to 20 -class PacketDataProtocolAddress(Packet): - """Packet data protocol address Section 10.5.6.4""" - name = "Packet Data Protocol Address" - fields_desc = [ - ByteField("ieiPDPA", 0x0), - - XByteField("lengthPDPA", None), - - BitField("spare", 0x0, 4), - BitField("pdpTypeOrga", 0x0, 4), - - ByteField("pdpTypeNb", 0x0), - # optional - ByteField("addressInfo1", None), - ByteField("addressInfo2", None), - ByteField("addressInfo3", None), - ByteField("addressInfo4", None), - ByteField("addressInfo5", None), - ByteField("addressInfo6", None), - ByteField("addressInfo7", None), - ByteField("addressInfo8", None), - ByteField("addressInfo9", None), - ByteField("addressInfo10", None), - ByteField("addressInfo11", None), - ByteField("addressInfo12", None), - ByteField("addressInfo13", None), - ByteField("addressInfo14", None), - ByteField("addressInfo15", None), - ByteField("addressInfo16", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 20, a, self.fields_desc) - if self.lengthPDPA is None: - p = p[:1] + struct.pack(">B", res[1]) + p[2:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class QualityOfService(Packet): - """Quality of service Section 10.5.6.5""" - name = "Quality of Service" - fields_desc = [ - ByteField("ieiQOS", 0x0), - XByteField("lengthQOS", 0x5), - - BitField("spare", 0x0, 2), - BitField("delayClass", 0x0, 3), - BitField("reliaClass", 0x0, 3), - - BitField("peak", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("precedenceCl", 0x0, 3), - - BitField("spare", 0x0, 3), - BitField("mean", 0x0, 5) - ] - - -class SmCause(Packet): - """SM cause Section 10.5.6.6""" - name = "SM Cause" - fields_desc = [ - ByteField("ieiSC", 0x0), - ByteField("causeVal", 0x0) - ] - -# 10.5.6.7 Spare -# This is intentionally left spare. - - -class AaDeactivationCause(Packet): - """AA deactivation cause Section 10.5.6.8""" - name = "AA Deactivation Cause" - fields_desc = [ - XBitField("ieiADC", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("aaVal", 0x0, 3) - ] - - -# Fix 1/2 len problem -class AaDeactivationCauseAndSpareHalfOctets(Packet): - name = "AA Deactivation Cause and Spare Half Octets" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("aaVal", 0x0, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class LlcServiceAccessPointIdentifier(Packet): - """LLC service access point identifier Section 10.5.6.9""" - name = "LLC Service Access Point Identifier" - fields_desc = [ - ByteField("ieiLSAPI", None), - BitField("spare", 0x0, 4), - BitField("llcVal", 0x0, 4) - ] - - -# -# 10.5.7 GPRS Common information elements -# - -# 10.5.7.1 [Spare] - -class RadioPriority(Packet): - """Radio priority Section 10.5.7.2""" - name = "Radio Priority" - fields_desc = [ - XBitField("ieiRP", 0x0, 4), - BitField("spare", 0x1, 1), - BitField("rplv", 0x0, 3) - ] - - -# Fix 1/2 len problem -class RadioPriorityAndSpareHalfOctets(Packet): - name = "Radio Priority and Spare Half Octets" - fields_desc = [ - BitField("spare", 0x1, 1), - BitField("rplv", 0x0, 3), - BitField("spareHalfOctets", 0x0, 4) - ] - - -class GprsTimer(Packet): - """GPRS Timer Section 10.5.7.3""" - name = "GPRS Timer" - fields_desc = [ - ByteField("ieiGT", 0x0), - BitField("unit", 0x0, 3), - BitField("timerVal", 0x0, 5) - ] - - -class CellIdentity(Packet): - """ Cell identity Section 10.5.1.1 """ - name = "Cell Identity" - fields_desc = [ - ByteField("ciValue1", 0x0), - ByteField("ciValue2", 0x0) - ] - - -class CiphKeySeqNr(Packet): - """ Ciphering Key Sequence Number Section 10.5.1.2 """ - name = "Cipher Key Sequence Number" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("keySeq", 0x0, 3) - ] - - -class LocalAreaId(Packet): - """ Local Area Identification Section 10.5.1.3 """ - name = "Location Area Identification" - fields_desc = [ - BitField("mccDigit2", 0x0, 4), - BitField("mccDigit1", 0x0, 4), - BitField("mncDigit3", 0x0, 4), - BitField("mccDigit3", 0x0, 4), - BitField("mncDigit2", 0x0, 4), - BitField("mncDigit1", 0x0, 4), - ByteField("lac1", 0x0), - ByteField("lac2", 0x0) - ] -# -# The Mobile Identity is a type 4 information element with a minimum -# length of 3 octet and 11 octets length maximal. -# - - -# len 3 - 11 -class MobileId(Packet): - """ Mobile Identity Section 10.5.1.4 """ - name = "Mobile Identity" - fields_desc = [ - XByteField("lengthMI", None), - BitField("idDigit1", 0x0, 4), - BitField("oddEven", 0x0, 1), - BitField("typeOfId", 0x0, 3), - - BitField("idDigit2_1", None, 4), # optional - BitField("idDigit2", None, 4), - BitField("idDigit3_1", None, 4), - BitField("idDigit3", None, 4), - BitField("idDigit4_1", None, 4), - BitField("idDigit4", None, 4), - BitField("idDigit5_1", None, 4), - BitField("idDigit5", None, 4), - BitField("idDigit6_1", None, 4), - BitField("idDigit6", None, 4), - BitField("idDigit7_1", None, 4), - BitField("idDigit7", None, 4), - BitField("idDigit8_1", None, 4), - BitField("idDigit8", None, 4), - BitField("idDigit9_1", None, 4), - BitField("idDigit9", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 10, a, self.fields_desc, 1) - if self.lengthMI is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class MobileStationClassmark1(Packet): - """ Mobile Station Classmark 1 Section 10.5.1.5 """ - name = "Mobile Station Classmark 1" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("revisionLvl", 0x0, 2), - BitField("esInd", 0x0, 1), - BitField("a51", 0x0, 1), - BitField("rfPowerCap", 0x0, 3) - ] - - -class MobileStationClassmark2(Packet): - """ Mobile Station Classmark 2 Section 10.5.1.6 """ - name = "Mobile Station Classmark 2" - fields_desc = [ - XByteField("lengthMSC2", 0x3), - BitField("spare", 0x0, 1), - BitField("revisionLvl", 0x0, 2), - BitField("esInd", 0x0, 1), - BitField("a51", 0x0, 1), - BitField("rfPowerCap", 0x0, 3), - BitField("spare1", 0x0, 1), - BitField("psCap", 0x0, 1), - BitField("ssScreenInd", 0x0, 2), - BitField("smCaPabi", 0x0, 1), - BitField("vbs", 0x0, 1), - BitField("vgcs", 0x0, 1), - BitField("fc", 0x0, 1), - BitField("cm3", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("lcsvaCap", 0x0, 1), - BitField("spare3", 0x0, 1), - BitField("soLsa", 0x0, 1), - BitField("cmsp", 0x0, 1), - BitField("a53", 0x0, 1), - BitField("a52", 0x0, 1) - ] - - -class DescriptiveGroupOrBroadcastCallReference(Packet): - """ Descriptive group or broadcast call reference Section 10.5.1.9 """ - name = "Descriptive Group or Broadcast Call Reference" - fields_desc = [ - BitField("binCallRef", 0x0, 27), - BitField("sf", 0x0, 1), - BitField("fa", 0x0, 1), - BitField("callPrio", 0x0, 3), - BitField("cipherInfo", 0x0, 4), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("spare3", 0x0, 1), - BitField("spare4", 0x0, 1) - ] - - -class PdAndSapi(Packet): - """ PD and SAPI $(CCBS)$ Section 10.5.1.10a """ - name = "PD and SAPI $(CCBS)$" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("sapi", 0x0, 2), - BitField("pd", 0x0, 4) - ] - - -class PriorityLevel(Packet): - """ Priority Level Section 10.5.1.11 """ - name = "Priority Level" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("callPrio", 0x0, 3) - ] - -# -# Radio Resource management information elements -# - - -# len 6 to max for L3 message (251) -class BaRange(Packet): - """ BA Range Section 10.5.2.1a """ - name = "BA Range" - fields_desc = [ - - XByteField("lengthBR", None), -#error: byte format requires -128 <= number <= 127 - ByteField("nrOfRanges", 0x0), -# # rX = range X -# # L o = Lower H i = higher -# # H p = high Part Lp = low Part - ByteField("r1LoHp", 0x0), - - BitField("r1LoLp", 0x0, 3), - BitField("r1HiHp", 0x0, 5), - - BitField("r1HiLp", 0x0, 4), - BitField("r2LoHp", 0x0, 4), - # optional - BitField("r2LoLp", None, 5), - BitField("r2HiHp", None, 3), - - ByteField("r2HiLp", None), - ByteField("r3LoHp", None), - - BitField("r3LoLp", None, 5), - BitField("r3HiHp", None, 3), - - ByteField("r3HiLp", None), - ByteField("r4LoHp", None), - - BitField("r4LoLp", None, 5), - BitField("r4HiHp", None, 3), - ByteField("r4HiLp", None), - ByteField("r5LoHp", None), - - BitField("r5LoLp", None, 5), - BitField("r5HiHp", None, 3), - ByteField("r5HiLp", None), - ByteField("r6LoHp", None), - - BitField("r6LoLp", None, 5), - BitField("r6HiHp", None, 3), - ByteField("r6HiLp", None), - ByteField("r7LoHp", None), - - BitField("r7LoLp", None, 5), - BitField("r7HiHp", None, 3), - ByteField("r7HiLp", None), - ByteField("r8LoHp", None), - - BitField("r8LoLp", None, 5), - BitField("r8HiHp", None, 3), - ByteField("r8HiLp", None), - ByteField("r9LoHp", None), - - BitField("r9LoLp", None, 5), - BitField("r9HiHp", None, 3), - ByteField("r9HiLp", None), - ByteField("r10LoHp", None), - - BitField("r10LoLp", None, 5), - BitField("r10HiHp", None, 3), - ByteField("r10HiLp", None), - ByteField("r11LoHp", None), - - BitField("r11LoLp", None, 5), - BitField("r11HiHp", None, 3), - ByteField("r11HiLp", None), - ByteField("r12LoHp", None), - - BitField("r12LoLp", None, 5), - BitField("r12HiHp", None, 3), - ByteField("r12HiLp", None), - ByteField("r13LoHp", None), - - BitField("r13LoLp", None, 5), - BitField("r13HiHp", None, 3), - ByteField("r13HiLp", None), - ByteField("r14LoHp", None), - - BitField("r14LoLp", None, 5), - BitField("r14HiHp", None, 3), - ByteField("r14HiLp", None), - ByteField("r15LoHp", None), - - BitField("r15LoLp", None, 5), - BitField("r15HiHp", None, 3), - ByteField("r15HiLp", None), - ByteField("r16LoHp", None), - - BitField("r16LoLp", None, 5), - BitField("r16HiHp", None, 3), - ByteField("r16HiLp", None), - ByteField("r17LoHp", None), - - BitField("r17LoLp", None, 5), - BitField("r17HiHp", None, 3), - ByteField("r17HiLp", None), - ByteField("r18LoHp", None), - - BitField("r18LoLp", None, 5), - BitField("r18HiHp", None, 3), - ByteField("r18HiLp", None), - ByteField("r19LoHp", None), - - BitField("r19LoLp", None, 5), - BitField("r19HiHp", None, 3), - ByteField("r19HiLp", None), - ByteField("r20LoHp", None), - - BitField("r20LoLp", None, 5), - BitField("r20HiHp", None, 3), - ByteField("r20HiLp", None), - ByteField("r21LoHp", None), - - BitField("r21LoLp", None, 5), - BitField("r21HiHp", None, 3), - ByteField("r21HiLp", None), - ByteField("r22LoHp", None), - - BitField("r22LoLp", None, 5), - BitField("r22HiHp", None, 3), - ByteField("r22HiLp", None), - ByteField("r23LoHp", None), - - BitField("r23LoLp", None, 5), - BitField("r23HiHp", None, 3), - ByteField("r23HiLp", None), - ByteField("r24LoHp", None), - - BitField("r24LoLp", None, 5), - BitField("r24HiHp", None, 3), - ByteField("r24HiLp", None), - ByteField("r25LoHp", None), - - BitField("r25LoLp", None, 5), - BitField("r25HiHp", None, 3), - ByteField("r25HiLp", None), - ByteField("r26LoHp", None), - - BitField("r26LoLp", None, 5), - BitField("r26HiHp", None, 3), - ByteField("r26HiLp", None), - ByteField("r27LoHp", None), - - BitField("r27LoLp", None, 5), - BitField("r27HiHp", None, 3), - ByteField("r27HiLp", None), - ByteField("r28LoHp", None), - - BitField("r28LoLp", None, 5), - BitField("r28HiHp", None, 3), - ByteField("r28HiLp", None), - ByteField("r29LoHp", None), - - BitField("r29LoLp", None, 5), - BitField("r29HiHp", None, 3), - ByteField("r29HiLp", None), - ByteField("r30LoHp", None), - - BitField("r30LoLp", None, 5), - BitField("r30HiHp", None, 3), - ByteField("r30HiLp", None), - ByteField("r31LoHp", None), - - BitField("r31LoLp", None, 5), - BitField("r31HiHp", None, 3), - ByteField("r31HiLp", None), - ByteField("r32LoHp", None), - - BitField("r32LoLp", None, 5), - BitField("r32HiHp", None, 3), - ByteField("r32HiLp", None), - ByteField("r33LoHp", None), - - BitField("r33LoLp", None, 5), - BitField("r33HiHp", None, 3), - ByteField("r33HiLp", None), - ByteField("r34LoHp", None), - - BitField("r34LoLp", None, 5), - BitField("r34HiHp", None, 3), - ByteField("r34HiLp", None), - ByteField("r35LoHp", None), - - BitField("r35LoLp", None, 5), - BitField("r35HiHp", None, 3), - ByteField("r35HiLp", None), - ByteField("r36LoHp", None), - - BitField("r36LoLp", None, 5), - BitField("r36HiHp", None, 3), - ByteField("r36HiLp", None), - ByteField("r37LoHp", None), - - BitField("r37LoLp", None, 5), - BitField("r37HiHp", None, 3), - ByteField("r37HiLp", None), - ByteField("r38LoHp", None), - - BitField("r38LoLp", None, 5), - BitField("r38HiHp", None, 3), - ByteField("r38HiLp", None), - ByteField("r39LoHp", None), - - BitField("r39LoLp", None, 5), - BitField("r39HiHp", None, 3), - ByteField("r39HiLp", None), - ByteField("r40LoHp", None), - - BitField("r40LoLp", None, 5), - BitField("r40HiHp", None, 3), - ByteField("r40HiLp", None), - ByteField("r41LoHp", None), - - BitField("r41LoLp", None, 5), - BitField("r41HiHp", None, 3), - ByteField("r41HiLp", None), - ByteField("r42LoHp", None), - - BitField("r42LoLp", None, 5), - BitField("r42HiHp", None, 3), - ByteField("r42HiLp", None), - ByteField("r43LoHp", None), - - BitField("r43LoLp", None, 5), - BitField("r43HiHp", None, 3), - ByteField("r43HiLp", None), - ByteField("r44LoHp", None), - - BitField("r44LoLp", None, 5), - BitField("r44HiHp", None, 3), - ByteField("r44HiLp", None), - ByteField("r45LoHp", None), - - BitField("r45LoLp", None, 5), - BitField("r45HiHp", None, 3), - ByteField("r45HiLp", None), - ByteField("r46LoHp", None), - - BitField("r46LoLp", None, 5), - BitField("r46HiHp", None, 3), - ByteField("r46HiLp", None), - ByteField("r47LoHp", None), - - BitField("r47LoLp", None, 5), - BitField("r47HiHp", None, 3), - ByteField("r47HiLp", None), - ByteField("r48LoHp", None), - - BitField("r48LoLp", None, 5), - BitField("r48HiHp", None, 3), - ByteField("r48HiLp", None), - ByteField("r49LoHp", None), - - BitField("r49LoLp", None, 5), - BitField("r49HiHp", None, 3), - ByteField("r49HiLp", None), - ByteField("r50LoHp", None), - - BitField("r50LoLp", None, 5), - BitField("r50HiHp", None, 3), - ByteField("r50HiLp", None), - ByteField("r51LoHp", None), - - BitField("r51LoLp", None, 5), - BitField("r51HiHp", None, 3), - ByteField("r51HiLp", None), - ByteField("r52LoHp", None), - - BitField("r52LoLp", None, 5), - BitField("r52HiHp", None, 3), - ByteField("r52HiLp", None), - ByteField("r53LoHp", None), - - BitField("r53LoLp", None, 5), - BitField("r53HiHp", None, 3), - ByteField("r53HiLp", None), - ByteField("r54LoHp", None), - - BitField("r54LoLp", None, 5), - BitField("r54HiHp", None, 3), - ByteField("r54HiLp", None), - ByteField("r55LoHp", None), - - BitField("r55LoLp", None, 5), - BitField("r55HiHp", None, 3), - ByteField("r55HiLp", None), - ByteField("r56LoHp", None), - - BitField("r56LoLp", None, 5), - BitField("r56HiHp", None, 3), - ByteField("r56HiLp", None), - ByteField("r57LoHp", None), - - BitField("r57LoLp", None, 5), - BitField("r57HiHp", None, 3), - ByteField("r57HiLp", None), - ByteField("r58LoHp", None), - - BitField("r58LoLp", None, 5), - BitField("r58HiHp", None, 3), - ByteField("r58HiLp", None), - ByteField("r59LoHp", None), - - BitField("r59LoLp", None, 5), - BitField("r59HiHp", None, 3), - ByteField("r59HiLp", None), - ByteField("r60LoHp", None), - - BitField("r60LoLp", None, 5), - BitField("r60HiHp", None, 3), - ByteField("r60HiLp", None), - ByteField("r61LoHp", None), - - BitField("r61LoLp", None, 5), - BitField("r61HiHp", None, 3), - ByteField("r61HiLp", None), - ByteField("r62LoHp", None), - - BitField("r62LoLp", None, 5), - BitField("r62HiHp", None, 3), - ByteField("r62HiLp", None), - ByteField("r63LoHp", None), - - BitField("r63LoLp", None, 5), - BitField("r63HiHp", None, 3), - ByteField("r63HiLp", None), - ByteField("r64LoHp", None), - - BitField("r64LoLp", None, 5), - BitField("r64HiHp", None, 3), - ByteField("r64HiLp", None), - ByteField("r65LoHp", None), - - BitField("r65LoLp", None, 5), - BitField("r65HiHp", None, 3), - ByteField("r65HiLp", None), - ByteField("r66LoHp", None), - - BitField("r66LoLp", None, 5), - BitField("r66HiHp", None, 3), - ByteField("r66HiLp", None), - ByteField("r67LoHp", None), - - BitField("r67LoLp", None, 5), - BitField("r67HiHp", None, 3), - ByteField("r67HiLp", None), - ByteField("r68LoHp", None), - - BitField("r68LoLp", None, 5), - BitField("r68HiHp", None, 3), - ByteField("r68HiLp", None), - ByteField("r69LoHp", None), - - BitField("r69LoLp", None, 5), - BitField("r69HiHp", None, 3), - ByteField("r69HiLp", None), - ByteField("r70LoHp", None), - - BitField("r70LoLp", None, 5), - BitField("r70HiHp", None, 3), - ByteField("r70HiLp", None), - ByteField("r71LoHp", None), - - BitField("r71LoLp", None, 5), - BitField("r71HiHp", None, 3), - ByteField("r71HiLp", None), - ByteField("r72LoHp", None), - - BitField("r72LoLp", None, 5), - BitField("r72HiHp", None, 3), - ByteField("r72HiLp", None), - ByteField("r73LoHp", None), - - BitField("r73LoLp", None, 5), - BitField("r73HiHp", None, 3), - ByteField("r73HiLp", None), - ByteField("r74LoHp", None), - - BitField("r74LoLp", None, 5), - BitField("r74HiHp", None, 3), - ByteField("r74HiLp", None), - ByteField("r75LoHp", None), - - BitField("r75LoLp", None, 5), - BitField("r75HiHp", None, 3), - ByteField("r75HiLp", None), - ByteField("r76LoHp", None), - - BitField("r76LoLp", None, 5), - BitField("r76HiHp", None, 3), - ByteField("r76HiLp", None), - ByteField("r77LoHp", None), - - BitField("r77LoLp", None, 5), - BitField("r77HiHp", None, 3), - ByteField("r77HiLp", None), - ByteField("r78LoHp", None), - - BitField("r78LoLp", None, 5), - BitField("r78HiHp", None, 3), - ByteField("r78HiLp", None), - ByteField("r79LoHp", None), - - BitField("r79LoLp", None, 5), - BitField("r79HiHp", None, 3), - ByteField("r79HiLp", None), - ByteField("r80LoHp", None), - - BitField("r80LoLp", None, 5), - BitField("r80HiHp", None, 3), - ByteField("r80HiLp", None), - ByteField("r81LoHp", None), - - BitField("r81LoLp", None, 5), - BitField("r81HiHp", None, 3), - ByteField("r81HiLp", None), - ByteField("r82LoHp", None), - - BitField("r82LoLp", None, 5), - BitField("r82HiHp", None, 3), - ByteField("r82HiLp", None), - ByteField("r83LoHp", None), - - BitField("r83LoLp", None, 5), - BitField("r83HiHp", None, 3), - ByteField("r83HiLp", None), - ByteField("r84LoHp", None), - - BitField("r84LoLp", None, 5), - BitField("r84HiHp", None, 3), - ByteField("r84HiLp", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(5, 253, a, self.fields_desc, 1) - if self.lengthBR is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 3 to max for L3 message (251) -class BaListPref(Packet): - """ BA List Pref Section 10.5.2.1c """ - name = "BA List Pref" - fields_desc = [ - XByteField("lengthBLP", None), - - BitField("fixBit", 0x0, 1), - BitField("rangeLower", 0x0, 10), - BitField("fixBit2", 0x0, 1), - BitField("rangeUpper", 0x0, 10), - BitField("baFreq", 0x0, 10), - BitField("sparePad", 0x0, 8) - ] - - -# len 17 || Have a look at the specs for the field format -# Bit map 0 format -# Range 1024 format -# Range 512 format -# Range 256 format -# Range 128 format -# Variable bit map format -class CellChannelDescription(Packet): - """ Cell Channel Description Section 10.5.2.1b """ - name = "Cell Channel Description " - fields_desc = [ - BitField("bit128", 0x0, 1), - BitField("bit127", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - ByteField("bit120", 0x0), - ByteField("bit112", 0x0), - ByteField("bit104", 0x0), - ByteField("bit96", 0x0), - ByteField("bit88", 0x0), - ByteField("bit80", 0x0), - ByteField("bit72", 0x0), - ByteField("bit64", 0x0), - ByteField("bit56", 0x0), - ByteField("bit48", 0x0), - ByteField("bit40", 0x0), - ByteField("bit32", 0x0), - ByteField("bit24", 0x0), - ByteField("bit16", 0x0), - ByteField("bit8", 0x0) - ] - - -class CellDescription(Packet): - """ Cell Description Section 10.5.2.2 """ - name = "Cell Description" - fields_desc = [ - BitField("bcchHigh", 0x0, 2), - BitField("ncc", 0x0, 3), - BitField("bcc", 0x0, 3), - ByteField("bcchLow", 0x0) - ] - - -class CellOptionsBCCH(Packet): - """ Cell Options (BCCH) Section 10.5.2.3 """ - name = "Cell Options (BCCH)" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("pwrc", 0x0, 1), - BitField("dtx", 0x0, 2), - BitField("rLinkTout", 0x0, 4) - ] - - -class CellOptionsSACCH(Packet): - """ Cell Options (SACCH) Section 10.5.2.3a """ - name = "Cell Options (SACCH)" - fields_desc = [ - BitField("dtx", 0x0, 1), - BitField("pwrc", 0x0, 1), - BitField("dtx", 0x0, 1), - BitField("rLinkTout", 0x0, 4) - ] - - -class CellSelectionParameters(Packet): - """ Cell Selection Parameters Section 10.5.2.4 """ - name = "Cell Selection Parameters" - fields_desc = [ - BitField("cellReselect", 0x0, 3), - BitField("msTxPwrMax", 0x0, 5), - BitField("acs", None, 1), - BitField("neci", None, 1), - BitField("rxlenAccMin", None, 6) - ] - - -class MacModeAndChannelCodingRequest(Packet): - """ MAC Mode and Channel Coding Requested Section 10.5.2.4a """ - name = "MAC Mode and Channel Coding Requested" - fields_desc = [ - BitField("macMode", 0x0, 2), - BitField("cs", 0x0, 2) - ] - - -class ChannelDescription(Packet): - """ Channel Description Section 10.5.2.5 """ - name = "Channel Description" - fields_desc = [ - - BitField("channelTyp", 0x0, 5), - BitField("tn", 0x0, 3), - - BitField("tsc", 0x0, 3), - BitField("h", 0x1, 1), - BitField("maioHi", 0x0, 4), - - BitField("maioLo", 0x0, 2), - BitField("hsn", 0x0, 6) - ] - - -class ChannelDescription2(Packet): - """ Channel Description 2 Section 10.5.2.5a """ - name = "Channel Description 2" - fields_desc = [ - BitField("channelTyp", 0x0, 5), - BitField("tn", 0x0, 3), - BitField("tsc", 0x0, 3), - BitField("h", 0x0, 1), - # if h=1 - # BitField("maioHi", 0x0, 4), - # BitField("maioLo", 0x0, 2), - # BitField("hsn", 0x0, 6) - BitField("spare", 0x0, 2), - BitField("arfcnHigh", 0x0, 2), - ByteField("arfcnLow", 0x0) - ] - - -class ChannelMode(Packet): - """ Channel Mode Section 10.5.2.6 """ - name = "Channel Mode" - fields_desc = [ - ByteField("mode", 0x0) - ] - - -class ChannelMode2(Packet): - """ Channel Mode 2 Section 10.5.2.7 """ - name = "Channel Mode 2" - fields_desc = [ - ByteField("mode", 0x0) - ] - - -class ChannelNeeded(Packet): - """ Channel Needed Section 10.5.2.8 """ - name = "Channel Needed" - fields_desc = [ - BitField("channel2", 0x0, 2), - BitField("channel1", 0x0, 2), - ] - - -class ChannelRequestDescription(Packet): - """Channel Request Description Section 10.5.2.8a """ - name = "Channel Request Description" - fields_desc = [ - BitField("mt", 0x0, 1), - ConditionalField(BitField("spare", 0x0, 39), - lambda pkt: pkt.mt == 0), - ConditionalField(BitField("spare", 0x0, 3), - lambda pkt: pkt.mt == 1), - ConditionalField(BitField("priority", 0x0, 2), - lambda pkt: pkt.mt == 1), - ConditionalField(BitField("rlcMode", 0x0, 1), - lambda pkt: pkt.mt == 1), - ConditionalField(BitField("llcFrame", 0x1, 1), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("reqBandMsb", 0x0), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("reqBandLsb", 0x0), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("rlcMsb", 0x0), - lambda pkt: pkt.mt == 1), - ConditionalField(ByteField("rlcLsb", 0x0), - lambda pkt: pkt.mt == 1) - ] - - -class CipherModeSetting(Packet): - """Cipher Mode Setting Section 10.5.2.9 """ - name = "Cipher Mode Setting" - fields_desc = [ - BitField("algoId", 0x0, 3), - BitField("sc", 0x0, 1), - ] - - -class CipherResponse(Packet): - """Cipher Response Section 10.5.2.10 """ - name = "Cipher Response" - fields_desc = [ - BitField("spare", 0x0, 3), - BitField("cr", 0x0, 1), - ] - - -class ControlChannelDescription(Packet): - """Control Channel Description Section 10.5.2.11 """ - name = "Control Channel Description" - fields_desc = [ - - BitField("spare", 0x0, 1), - BitField("att", 0x0, 1), - BitField("bsAgBlksRes", 0x0, 3), - BitField("ccchConf", 0x0, 3), - - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("spare3", 0x0, 1), - BitField("spare4", 0x0, 1), - BitField("bsPaMfrms", 0x0, 3), - - ByteField("t3212", 0x0) - ] - - -class FrequencyChannelSequence(Packet): - """Frequency Channel Sequence Section 10.5.2.12""" - name = "Frequency Channel Sequence" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("lowestArfcn", 0x0, 7), - BitField("skipArfcn01", 0x0, 4), - BitField("skipArfcn02", 0x0, 4), - BitField("skipArfcn03", 0x0, 4), - BitField("skipArfcn04", 0x0, 4), - BitField("skipArfcn05", 0x0, 4), - BitField("skipArfcn06", 0x0, 4), - BitField("skipArfcn07", 0x0, 4), - BitField("skipArfcn08", 0x0, 4), - BitField("skipArfcn09", 0x0, 4), - BitField("skipArfcn10", 0x0, 4), - BitField("skipArfcn11", 0x0, 4), - BitField("skipArfcn12", 0x0, 4), - BitField("skipArfcn13", 0x0, 4), - BitField("skipArfcn14", 0x0, 4), - BitField("skipArfcn15", 0x0, 4), - BitField("skipArfcn16", 0x0, 4) - ] - - -class FrequencyList(Packet): - """Frequency List Section 10.5.2.13""" - name = "Frequency List" - # Problem: - # There are several formats for the Frequency List information - # element, distinguished by the "format indicator" subfield. - # Some formats are frequency bit maps, the others use a special encoding - # scheme. - fields_desc = [ - XByteField("lengthFL", None), - - BitField("formatID", 0x0, 2), - BitField("spare", 0x0, 2), - BitField("arfcn124", 0x0, 1), - BitField("arfcn123", 0x0, 1), - BitField("arfcn122", 0x0, 1), - BitField("arfcn121", 0x0, 1), - - ByteField("arfcn120", 0x0), - ByteField("arfcn112", 0x0), - ByteField("arfcn104", 0x0), - ByteField("arfcn96", 0x0), - ByteField("arfcn88", 0x0), - ByteField("arfcn80", 0x0), - ByteField("arfcn72", 0x0), - ByteField("arfcn64", 0x0), - ByteField("arfcn56", 0x0), - ByteField("arfcn48", 0x0), - ByteField("arfcn40", 0x0), - ByteField("arfcn32", 0x0), - ByteField("arfcn24", 0x0), - ByteField("arfcn16", 0x0), - ByteField("arfcn8", 0x0) - ] - - -# len 4 to 13 -class GroupChannelDescription(Packet): - """Group Channel Description Section 10.5.2.14b""" - name = "Group Channel Description" - fields_desc = [ - XByteField("lengthGCD", None), - - BitField("channelType", 0x0, 5), - BitField("tn", 0x0, 3), - - BitField("tsc", 0x0, 3), - BitField("h", 0x0, 1), - # if h == 0 the packet looks the following way: - ConditionalField(BitField("spare", 0x0, 2), - lambda pkt: pkt. h == 0x0), - ConditionalField(BitField("arfcnHi", 0x0, 2), - lambda pkt: pkt. h == 0x0), - ConditionalField(ByteField("arfcnLo", None), - lambda pkt: pkt. h == 0x0), - # if h == 1 the packet looks the following way: - ConditionalField(BitField("maioHi", 0x0, 4), - lambda pkt: pkt. h == 0x1), - ConditionalField(BitField("maioLo", None, 2), - lambda pkt: pkt. h == 0x1), - ConditionalField(BitField("hsn", None, 6), - lambda pkt: pkt. h == 0x1), - # finished with conditional fields - ByteField("maC6", None), - ByteField("maC7", None), - ByteField("maC8", None), - ByteField("maC9", None), - ByteField("maC10", None), - ByteField("maC11", None), - ByteField("maC12", None), - ByteField("maC13", None), - ByteField("maC14", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(4, 13, a, self.fields_desc, 1) - if self.lengthGCD is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class GprsResumption(Packet): - """GPRS Resumption Section 10.5.2.14c""" - name = "GPRS Resumption" - fields_desc = [ - BitField("spare", 0x0, 3), - BitField("ack", 0x0, 1) - ] - - -class HandoverReference(Packet): - """Handover Reference Section 10.5.2.15""" - name = "Handover Reference" - fields_desc = [ - ByteField("handoverRef", 0x0) - ] - - -class IraRestOctets(Packet): - """IAR Rest Octets Section 10.5.2.17""" - name = "IAR Rest Octets" - fields_desc = [ - BitField("spare01", 0x0, 1), - BitField("spare02", 0x0, 1), - BitField("spare03", 0x1, 1), - BitField("spare04", 0x0, 1), - BitField("spare05", 0x1, 1), - BitField("spare06", 0x0, 1), - BitField("spare07", 0x1, 1), - BitField("spare08", 0x1, 1), - BitField("spare09", 0x0, 1), - BitField("spare10", 0x0, 1), - BitField("spare11", 0x1, 1), - BitField("spare12", 0x0, 1), - BitField("spare13", 0x1, 1), - BitField("spare14", 0x0, 1), - BitField("spare15", 0x1, 1), - BitField("spare16", 0x1, 1), - BitField("spare17", 0x0, 1), - BitField("spare18", 0x0, 1), - BitField("spare19", 0x1, 1), - BitField("spare20", 0x0, 1), - BitField("spare21", 0x1, 1), - BitField("spare22", 0x0, 1), - BitField("spare23", 0x1, 1), - BitField("spare24", 0x1, 1) - ] - - -# len is 1 to 5 what do we do with the variable size? no lenght -# field?! WTF -class IaxRestOctets(Packet): - """IAX Rest Octets Section 10.5.2.18""" - name = "IAX Rest Octets" - fields_desc = [ - BitField("spare01", 0x0, 1), - BitField("spare02", 0x0, 1), - BitField("spare03", 0x1, 1), - BitField("spare04", 0x0, 1), - BitField("spare05", 0x1, 1), - BitField("spare06", 0x0, 1), - BitField("spare07", 0x1, 1), - BitField("spare08", 0x1, 1), - ByteField("spareB1", None), - ByteField("spareB2", None), - ByteField("spareB3", None) - ] - - -class L2PseudoLength(Packet): - """L2 Pseudo Length Section 10.5.2.19""" - name = "L2 Pseudo Length" - fields_desc = [ - BitField("l2pLength", None, 6), - BitField("bit2", 0x0, 1), - BitField("bit1", 0x1, 1) - ] - - -class MeasurementResults(Packet): - """Measurement Results Section 10.5.2.20""" - name = "Measurement Results" - fields_desc = [ - BitField("baUsed", 0x0, 1), - BitField("dtxUsed", 0x0, 1), - BitField("rxLevFull", 0x0, 6), - - BitField("spare", 0x0, 1), - BitField("measValid", 0x0, 1), - BitField("rxLevSub", 0x0, 6), - - BitField("spare0", 0x0, 1), - BitField("rxqualFull", 0x0, 3), - BitField("rxqualSub", 0x0, 3), - BitField("noNcellHi", 0x0, 1), - - BitField("noNcellLo", 0x0, 2), - BitField("rxlevC1", 0x0, 6), - - BitField("bcchC1", 0x0, 5), - BitField("bsicC1Hi", 0x0, 3), - - BitField("bsicC1Lo", 0x0, 3), - BitField("rxlevC2", 0x0, 5), - - BitField("rxlevC2Lo", 0x0, 1), - BitField("bcchC2", 0x0, 5), - BitField("bsicC2Hi", 0x0, 2), - - BitField("bscicC2Lo", 0x0, 4), - BitField("bscicC2Hi", 0x0, 4), - - BitField("rxlevC3Lo", 0x0, 2), - BitField("bcchC3", 0x0, 5), - BitField("rxlevC3Hi", 0x0, 1), - - BitField("bsicC3Lo", 0x0, 5), - BitField("bsicC3Hi", 0x0, 3), - - BitField("rxlevC4Lo", 0x0, 3), - BitField("bcchC4", 0x0, 5), - - BitField("bsicC4", 0x0, 6), - BitField("rxlevC5Hi", 0x0, 2), - - BitField("rxlevC5Lo", 0x0, 4), - BitField("bcchC5Hi", 0x0, 4), - - BitField("bcchC5Lo", 0x0, 1), - BitField("bsicC5", 0x0, 6), - BitField("rxlevC6", 0x0, 1), - - BitField("rxlevC6Lo", 0x0, 5), - BitField("bcchC6Hi", 0x0, 3), - - BitField("bcchC6Lo", 0x0, 3), - BitField("bsicC6", 0x0, 5) - ] - - -class GprsMeasurementResults(Packet): - """GPRS Measurement Results Section 10.5.2.20a""" - name = "GPRS Measurement Results" - fields_desc = [ - BitField("cValue", 0x0, 6), - BitField("rxqualHi", 0x0, 2), - BitField("rxqL", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("signVar", 0x0, 6) - ] - - -# len 3 to 10 -class MobileAllocation(Packet): - """Mobile Allocation Section 10.5.2.21""" - name = "Mobile Allocation" - fields_desc = [ - XByteField("lengthMA", None), - ByteField("maC64", 0x12), - ByteField("maC56", None), # optional fields start here - ByteField("maC48", None), - ByteField("maC40", None), - ByteField("maC32", None), - ByteField("maC24", None), - ByteField("maC16", None), - ByteField("maC8", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 9, a, self.fields_desc, 1) - if self.lengthMA is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class MobileTimeDifference(Packet): - """Mobile Time Difference Section 10.5.2.21a""" - name = "Mobile Time Difference" - fields_desc = [ - XByteField("lengthMTD", 0x5), - ByteField("valueHi", 0x0), - ByteField("valueCnt", 0x0), - BitField("valueLow", 0x0, 5), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1) - ] - - -# min 4 octets max 8 -class MultiRateConfiguration(Packet): - """ MultiRate configuration Section 10.5.2.21aa""" - name = "MultiRate Configuration" - # This packet has a variable length and hence structure. This packet - # implements the longuest possible packet. If you biuild a shorter - # packet, for example having only 6 bytes, the last 4 bytes are named - # "Spare" in the specs. Here they are named "threshold2" - fields_desc = [ - XByteField("lengthMRC", None), - - BitField("mrVersion", 0x0, 3), - BitField("spare", 0x0, 1), - BitField("icmi", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("startMode", 0x0, 2), - - ByteField("amrCodec", None), - - BitField("spare", None, 2), - BitField("threshold1", None, 6), - - BitField("hysteresis1", None, 4), - BitField("threshold2", None, 4), - - BitField("threshold2cnt", None, 2), - BitField("hysteresis2", None, 4), - BitField("threshold3", None, 2), - - BitField("threshold3cnt", None, 4), - BitField("hysteresis3", None, 4) - ] - - def post_build(self, p, pay): - # we set the length - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 7, a, self.fields_desc, 1) - if self.lengthMRC is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 2 to 11 -class MultislotAllocation(Packet): - """Multislot Allocation Section 10.5.2.21b""" - name = "Multislot Allocation" - fields_desc = [ - XByteField("lengthMSA", None), - BitField("ext0", 0x1, 1), - BitField("da", 0x0, 7), - ConditionalField(BitField("ext1", 0x1, 1), # optional - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("ua", 0x0, 7), - lambda pkt: pkt.ext0 == 0), - ByteField("chan1", None), - ByteField("chan2", None), - ByteField("chan3", None), - ByteField("chan4", None), - ByteField("chan5", None), - ByteField("chan6", None), - ByteField("chan7", None), - ByteField("chan8", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 11, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthMSA is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay - - -class NcMode(Packet): - """NC mode Section 10.5.2.21c""" - name = "NC Mode" - fields_desc = [ - BitField("spare", 0x0, 2), - BitField("ncMode", 0x0, 2) - ] - - -class NeighbourCellsDescription(Packet): - """Neighbour Cells Description Section 10.5.2.22""" - name = "Neighbour Cells Description" - fields_desc = [ - BitField("bit128", 0x0, 1), - BitField("bit127", 0x0, 1), - BitField("extInd", 0x0, 1), - BitField("baInd", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - BitField("120bits", 0x0, 120) - ] - - -class NeighbourCellsDescription2(Packet): - """Neighbour Cells Description 2 Section 10.5.2.22a""" - name = "Neighbour Cells Description 2" - fields_desc = [ - BitField("bit128", 0x0, 1), - BitField("multiband", 0x0, 2), - BitField("baInd", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - BitField("120bits", 0x0, 120) - ] - - -# len 4 -# strange packet, lots of valid formats - -# ideas for the dynamic packets: -# 1] for user interaction: Create an interactive "builder" based on a -# Q/A process (not very scapy like) -# 2] for usage in scripts, create an alternative packet for every -# possible packet layout -# - -class DedicatedModeOrTBF(Packet): - """Dedicated mode or TBF Section 10.5.2.25b""" - name = "Dedicated Mode or TBF" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("tma", 0x0, 1), - BitField("downlink", 0x0, 1), - BitField("td", 0x0, 1) - ] - - -class PageMode(Packet): - """Page Mode Section 10.5.2.26""" - name = "Page Mode" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("pm", 0x0, 2) - ] - - -class NccPermitted(Packet): - """NCC Permitted Section 10.5.2.27""" - name = "NCC Permited" - fields_desc = [ - ByteField("nccPerm", 0x0) - ] - - -class PowerCommand(Packet): - """Power Command Section 10.5.2.28""" - name = "Power Command" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("spare2", 0x0, 1), - BitField("powerLvl", 0x0, 5) - ] - - -class PowerCommandAndAccessType(Packet): - """Power Command and access type Section 10.5.2.28a""" - name = "Power Command and Access Type" - fields_desc = [ - BitField("atc", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("powerLvl", 0x0, 5) - ] - - -class RachControlParameters(Packet): - """RACH Control Parameters Section 10.5.2.29""" - name = "RACH Control Parameters" - fields_desc = [ - BitField("maxRetrans", 0x0, 2), - BitField("txInteger", 0x0, 4), - BitField("cellBarrAccess", 0x0, 1), - BitField("re", 0x0, 1), - BitField("ACC15", 0x0, 1), - BitField("ACC14", 0x0, 1), - BitField("ACC13", 0x0, 1), - BitField("ACC12", 0x0, 1), - BitField("ACC11", 0x0, 1), - BitField("ACC10", 0x0, 1), - BitField("ACC09", 0x0, 1), - BitField("ACC08", 0x0, 1), - BitField("ACC07", 0x0, 1), - BitField("ACC06", 0x0, 1), - BitField("ACC05", 0x0, 1), - BitField("ACC04", 0x0, 1), - BitField("ACC03", 0x0, 1), - BitField("ACC02", 0x0, 1), - BitField("ACC01", 0x0, 1), - BitField("ACC00", 0x0, 1), - ] - - -class RequestReference(Packet): - """Request Reference Section 10.5.2.30""" - name = "Request Reference" - fields_desc = [ - ByteField("ra", 0x0), - BitField("t1", 0x0, 5), - BitField("t3Hi", 0x0, 3), - BitField("t3Lo", 0x0, 3), - BitField("t2", 0x0, 5) - ] - - -class RrCause(Packet): - """RR Cause Section 10.5.2.31""" - name = "RR Cause" - fields_desc = [ - ByteField("rrCause", 0x0) - ] - - -class StartingTime(Packet): - """Starting Time Section 10.5.2.38""" - name = "Starting Time" - fields_desc = [ - ByteField("ra", 0x0), - BitField("t1", 0x0, 5), - BitField("t3Hi", 0x0, 3), - BitField("t3Lo", 0x0, 3), - BitField("t2", 0x0, 5) - ] - - -class SynchronizationIndication(Packet): - """Synchronization Indication Section 10.5.2.39""" - name = "Synchronization Indication" - fields_desc = [ - BitField("nci", 0x0, 1), - BitField("rot", 0x0, 1), - BitField("si", 0x0, 2) - ] - - -class TimingAdvance(Packet): - """Timing Advance Section 10.5.2.40""" - name = "Timing Advance" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1), - BitField("timingVal", 0x0, 6) - ] - - -class TimeDifference(Packet): - """ Time Difference Section 10.5.2.41""" - name = "Time Difference" - fields_desc = [ - XByteField("lengthTD", 0x3), - ByteField("timeValue", 0x0) - ] - - -class Tlli(Packet): - """ TLLI Section Section 10.5.2.41a""" - name = "TLLI" - fields_desc = [ - ByteField("value", 0x0), - ByteField("value1", 0x0), - ByteField("value2", 0x0), - ByteField("value3", 0x0) - ] - - -class TmsiPTmsi(Packet): - """ TMSI/P-TMSI Section 10.5.2.42""" - name = "TMSI/P-TMSI" - fields_desc = [ - ByteField("value", 0x0), - ByteField("value1", 0x0), - ByteField("value2", 0x0), - ByteField("value3", 0x0) - ] - - -class VgcsTargetModeIdentication(Packet): - """ VGCS target Mode Indication 10.5.2.42a""" - name = "VGCS Target Mode Indication" - fields_desc = [ - XByteField("lengthVTMI", 0x2), - BitField("targerMode", 0x0, 2), - BitField("cipherKeyNb", 0x0, 4), - BitField("spare", 0x0, 1), - BitField("spare1", 0x0, 1) - ] - - -class WaitIndication(Packet): - """ Wait Indication Section 10.5.2.43""" - name = "Wait Indication" - fields_desc = [ # asciiart of specs strange - ByteField("timeoutVal", 0x0) - ] - - -#class Si10RestOctets(Packet): -# """SI10 rest octets 10.5.2.44""" -# name = "SI10 rest octets" -# fields_desc = [ - - -# len 17 -class ExtendedMeasurementResults(Packet): - """EXTENDED MEASUREMENT RESULTS Section 10.5.2.45""" - name = "Extended Measurement Results" - fields_desc = [ - - BitField("scUsed", None, 1), - BitField("dtxUsed", None, 1), - BitField("rxLevC0", None, 6), - - BitField("rxLevC1", None, 6), - BitField("rxLevC2Hi", None, 2), - - BitField("rxLevC2Lo", None, 4), - BitField("rxLevC3Hi", None, 4), - - BitField("rxLevC3Lo", None, 3), - BitField("rxLevC4", None, 5), - - BitField("rxLevC5", None, 6), - BitField("rxLevC6Hi", None, 2), - - BitField("rxLevC6Lo", None, 4), - BitField("rxLevC7Hi", None, 4), - - BitField("rxLevC7Lo", None, 2), - BitField("rxLevC8", None, 6), - - BitField("rxLevC9", None, 6), - BitField("rxLevC10Hi", None, 2), - - BitField("rxLevC10Lo", None, 4), - BitField("rxLevC11Hi", None, 4), - - BitField("rxLevC13Lo", None, 2), - BitField("rxLevC12", None, 6), - - BitField("rxLevC13", None, 6), - BitField("rxLevC14Hi", None, 2), - - BitField("rxLevC14Lo", None, 4), - BitField("rxLevC15Hi", None, 4), - - BitField("rxLevC15Lo", None, 2), - BitField("rxLevC16", None, 6), - - - BitField("rxLevC17", None, 6), - BitField("rxLevC18Hi", None, 2), - - BitField("rxLevC18Lo", None, 4), - BitField("rxLevC19Hi", None, 4), - - BitField("rxLevC19Lo", None, 2), - BitField("rxLevC20", None, 6) - ] - - -# len 17 -class ExtendedMeasurementFrequencyList(Packet): - """Extended Measurement Frequency List Section 10.5.2.46""" - name = "Extended Measurement Frequency List" - fields_desc = [ - - BitField("bit128", 0x0, 1), - BitField("bit127", 0x0, 1), - BitField("spare", 0x0, 1), - BitField("seqCode", 0x0, 1), - BitField("bit124", 0x0, 1), - BitField("bit123", 0x0, 1), - BitField("bit122", 0x0, 1), - BitField("bit121", 0x0, 1), - - BitField("bitsRest", 0x0, 128) - ] - - -class SuspensionCause(Packet): - """Suspension Cause Section 10.5.2.47""" - name = "Suspension Cause" - fields_desc = [ - ByteField("suspVal", 0x0) - ] - - -class ApduID(Packet): - """APDU Flags Section 10.5.2.48""" - name = "Apdu Id" - fields_desc = [ - BitField("id", None, 4) - ] - - -class ApduFlags(Packet): - """APDU Flags Section 10.5.2.49""" - name = "Apdu Flags" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("cr", 0x0, 1), - BitField("firstSeg", 0x0, 1), - BitField("lastSeg", 0x0, 1) - ] - - -# len 1 to max L3 (251) (done) -class ApduData(Packet): - """APDU Data Section 10.5.2.50""" - name = "Apdu Data" - fields_desc = [ - XByteField("lengthAD", None), - #optional - ByteField("apuInfo1", None), - ByteField("apuInfo2", None), - ByteField("apuInfo3", None), - ByteField("apuInfo4", None), - ByteField("apuInfo5", None), - ByteField("apuInfo6", None), - ByteField("apuInfo7", None), - ByteField("apuInfo8", None), - ByteField("apuInfo9", None), - ByteField("apuInfo10", None), - ByteField("apuInfo11", None), - ByteField("apuInfo12", None), - ByteField("apuInfo13", None), - ByteField("apuInfo14", None), - ByteField("apuInfo15", None), - ByteField("apuInfo16", None), - ByteField("apuInfo17", None), - ByteField("apuInfo18", None), - ByteField("apuInfo19", None), - ByteField("apuInfo20", None), - ByteField("apuInfo21", None), - ByteField("apuInfo22", None), - ByteField("apuInfo23", None), - ByteField("apuInfo24", None), - ByteField("apuInfo25", None), - ByteField("apuInfo26", None), - ByteField("apuInfo27", None), - ByteField("apuInfo28", None), - ByteField("apuInfo29", None), - ByteField("apuInfo30", None), - ByteField("apuInfo31", None), - ByteField("apuInfo32", None), - ByteField("apuInfo33", None), - ByteField("apuInfo34", None), - ByteField("apuInfo35", None), - ByteField("apuInfo36", None), - ByteField("apuInfo37", None), - ByteField("apuInfo38", None), - ByteField("apuInfo39", None), - ByteField("apuInfo40", None), - ByteField("apuInfo41", None), - ByteField("apuInfo42", None), - ByteField("apuInfo43", None), - ByteField("apuInfo44", None), - ByteField("apuInfo45", None), - ByteField("apuInfo46", None), - ByteField("apuInfo47", None), - ByteField("apuInfo48", None), - ByteField("apuInfo49", None), - ByteField("apuInfo50", None), - ByteField("apuInfo51", None), - ByteField("apuInfo52", None), - ByteField("apuInfo53", None), - ByteField("apuInfo54", None), - ByteField("apuInfo55", None), - ByteField("apuInfo56", None), - ByteField("apuInfo57", None), - ByteField("apuInfo58", None), - ByteField("apuInfo59", None), - ByteField("apuInfo60", None), - ByteField("apuInfo61", None), - ByteField("apuInfo62", None), - ByteField("apuInfo63", None), - ByteField("apuInfo64", None), - ByteField("apuInfo65", None), - ByteField("apuInfo66", None), - ByteField("apuInfo67", None), - ByteField("apuInfo68", None), - ByteField("apuInfo69", None), - ByteField("apuInfo70", None), - ByteField("apuInfo71", None), - ByteField("apuInfo72", None), - ByteField("apuInfo73", None), - ByteField("apuInfo74", None), - ByteField("apuInfo75", None), - ByteField("apuInfo76", None), - ByteField("apuInfo77", None), - ByteField("apuInfo78", None), - ByteField("apuInfo79", None), - ByteField("apuInfo80", None), - ByteField("apuInfo81", None), - ByteField("apuInfo82", None), - ByteField("apuInfo83", None), - ByteField("apuInfo84", None), - ByteField("apuInfo85", None), - ByteField("apuInfo86", None), - ByteField("apuInfo87", None), - ByteField("apuInfo88", None), - ByteField("apuInfo89", None), - ByteField("apuInfo90", None), - ByteField("apuInfo91", None), - ByteField("apuInfo92", None), - ByteField("apuInfo93", None), - ByteField("apuInfo94", None), - ByteField("apuInfo95", None), - ByteField("apuInfo96", None), - ByteField("apuInfo97", None), - ByteField("apuInfo98", None), - ByteField("apuInfo99", None), - ByteField("apuInfo100", None), - ByteField("apuInfo101", None), - ByteField("apuInfo102", None), - ByteField("apuInfo103", None), - ByteField("apuInfo104", None), - ByteField("apuInfo105", None), - ByteField("apuInfo106", None), - ByteField("apuInfo107", None), - ByteField("apuInfo108", None), - ByteField("apuInfo109", None), - ByteField("apuInfo110", None), - ByteField("apuInfo111", None), - ByteField("apuInfo112", None), - ByteField("apuInfo113", None), - ByteField("apuInfo114", None), - ByteField("apuInfo115", None), - ByteField("apuInfo116", None), - ByteField("apuInfo117", None), - ByteField("apuInfo118", None), - ByteField("apuInfo119", None), - ByteField("apuInfo120", None), - ByteField("apuInfo121", None), - ByteField("apuInfo122", None), - ByteField("apuInfo123", None), - ByteField("apuInfo124", None), - ByteField("apuInfo125", None), - ByteField("apuInfo126", None), - ByteField("apuInfo127", None), - ByteField("apuInfo128", None), - ByteField("apuInfo129", None), - ByteField("apuInfo130", None), - ByteField("apuInfo131", None), - ByteField("apuInfo132", None), - ByteField("apuInfo133", None), - ByteField("apuInfo134", None), - ByteField("apuInfo135", None), - ByteField("apuInfo136", None), - ByteField("apuInfo137", None), - ByteField("apuInfo138", None), - ByteField("apuInfo139", None), - ByteField("apuInfo140", None), - ByteField("apuInfo141", None), - ByteField("apuInfo142", None), - ByteField("apuInfo143", None), - ByteField("apuInfo144", None), - ByteField("apuInfo145", None), - ByteField("apuInfo146", None), - ByteField("apuInfo147", None), - ByteField("apuInfo148", None), - ByteField("apuInfo149", None), - ByteField("apuInfo150", None), - ByteField("apuInfo151", None), - ByteField("apuInfo152", None), - ByteField("apuInfo153", None), - ByteField("apuInfo154", None), - ByteField("apuInfo155", None), - ByteField("apuInfo156", None), - ByteField("apuInfo157", None), - ByteField("apuInfo158", None), - ByteField("apuInfo159", None), - ByteField("apuInfo160", None), - ByteField("apuInfo161", None), - ByteField("apuInfo162", None), - ByteField("apuInfo163", None), - ByteField("apuInfo164", None), - ByteField("apuInfo165", None), - ByteField("apuInfo166", None), - ByteField("apuInfo167", None), - ByteField("apuInfo168", None), - ByteField("apuInfo169", None), - ByteField("apuInfo170", None), - ByteField("apuInfo171", None), - ByteField("apuInfo172", None), - ByteField("apuInfo173", None), - ByteField("apuInfo174", None), - ByteField("apuInfo175", None), - ByteField("apuInfo176", None), - ByteField("apuInfo177", None), - ByteField("apuInfo178", None), - ByteField("apuInfo179", None), - ByteField("apuInfo180", None), - ByteField("apuInfo181", None), - ByteField("apuInfo182", None), - ByteField("apuInfo183", None), - ByteField("apuInfo184", None), - ByteField("apuInfo185", None), - ByteField("apuInfo186", None), - ByteField("apuInfo187", None), - ByteField("apuInfo188", None), - ByteField("apuInfo189", None), - ByteField("apuInfo190", None), - ByteField("apuInfo191", None), - ByteField("apuInfo192", None), - ByteField("apuInfo193", None), - ByteField("apuInfo194", None), - ByteField("apuInfo195", None), - ByteField("apuInfo196", None), - ByteField("apuInfo197", None), - ByteField("apuInfo198", None), - ByteField("apuInfo199", None), - ByteField("apuInfo200", None), - ByteField("apuInfo201", None), - ByteField("apuInfo202", None), - ByteField("apuInfo203", None), - ByteField("apuInfo204", None), - ByteField("apuInfo205", None), - ByteField("apuInfo206", None), - ByteField("apuInfo207", None), - ByteField("apuInfo208", None), - ByteField("apuInfo209", None), - ByteField("apuInfo210", None), - ByteField("apuInfo211", None), - ByteField("apuInfo212", None), - ByteField("apuInfo213", None), - ByteField("apuInfo214", None), - ByteField("apuInfo215", None), - ByteField("apuInfo216", None), - ByteField("apuInfo217", None), - ByteField("apuInfo218", None), - ByteField("apuInfo219", None), - ByteField("apuInfo220", None), - ByteField("apuInfo221", None), - ByteField("apuInfo222", None), - ByteField("apuInfo223", None), - ByteField("apuInfo224", None), - ByteField("apuInfo225", None), - ByteField("apuInfo226", None), - ByteField("apuInfo227", None), - ByteField("apuInfo228", None), - ByteField("apuInfo229", None), - ByteField("apuInfo230", None), - ByteField("apuInfo231", None), - ByteField("apuInfo232", None), - ByteField("apuInfo233", None), - ByteField("apuInfo234", None), - ByteField("apuInfo235", None), - ByteField("apuInfo236", None), - ByteField("apuInfo237", None), - ByteField("apuInfo238", None), - ByteField("apuInfo239", None), - ByteField("apuInfo240", None), - ByteField("apuInfo241", None), - ByteField("apuInfo242", None), - ByteField("apuInfo243", None), - ByteField("apuInfo244", None), - ByteField("apuInfo245", None), - ByteField("apuInfo246", None), - ByteField("apuInfo247", None), - ByteField("apuInfo248", None), - ByteField("apuInfo249", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 250, a, self.fields_desc, 1) - if self.lengthAD is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay -# -# 10.5.3 Mobility management information elements -# - - -# len 3 to L3 max (251) (done) -class NetworkName(Packet): - """Network Name Section 10.5.3.5a""" - name = "Network Name" - fields_desc = [ - - XByteField("lengthNN", None), - - BitField("ext", 0x1, 1), - BitField("codingScheme", 0x0, 3), - BitField("addCi", 0x0, 1), - BitField("nbSpare", 0x0, 3), - # optional - ByteField("txtString1", None), - ByteField("txtString2", None), - ByteField("txtString3", None), - ByteField("txtString4", None), - ByteField("txtString5", None), - ByteField("txtString6", None), - ByteField("txtString7", None), - ByteField("txtString8", None), - ByteField("txtString9", None), - ByteField("txtString10", None), - ByteField("txtString11", None), - ByteField("txtString12", None), - ByteField("txtString13", None), - ByteField("txtString14", None), - ByteField("txtString15", None), - ByteField("txtString16", None), - ByteField("txtString17", None), - ByteField("txtString18", None), - ByteField("txtString19", None), - ByteField("txtString20", None), - ByteField("txtString21", None), - ByteField("txtString22", None), - ByteField("txtString23", None), - ByteField("txtString24", None), - ByteField("txtString25", None), - ByteField("txtString26", None), - ByteField("txtString27", None), - ByteField("txtString28", None), - ByteField("txtString29", None), - ByteField("txtString30", None), - ByteField("txtString31", None), - ByteField("txtString32", None), - ByteField("txtString33", None), - ByteField("txtString34", None), - ByteField("txtString35", None), - ByteField("txtString36", None), - ByteField("txtString37", None), - ByteField("txtString38", None), - ByteField("txtString39", None), - ByteField("txtString40", None), - ByteField("txtString41", None), - ByteField("txtString42", None), - ByteField("txtString43", None), - ByteField("txtString44", None), - ByteField("txtString45", None), - ByteField("txtString46", None), - ByteField("txtString47", None), - ByteField("txtString48", None), - ByteField("txtString49", None), - ByteField("txtString50", None), - ByteField("txtString51", None), - ByteField("txtString52", None), - ByteField("txtString53", None), - ByteField("txtString54", None), - ByteField("txtString55", None), - ByteField("txtString56", None), - ByteField("txtString57", None), - ByteField("txtString58", None), - ByteField("txtString59", None), - ByteField("txtString60", None), - ByteField("txtString61", None), - ByteField("txtString62", None), - ByteField("txtString63", None), - ByteField("txtString64", None), - ByteField("txtString65", None), - ByteField("txtString66", None), - ByteField("txtString67", None), - ByteField("txtString68", None), - ByteField("txtString69", None), - ByteField("txtString70", None), - ByteField("txtString71", None), - ByteField("txtString72", None), - ByteField("txtString73", None), - ByteField("txtString74", None), - ByteField("txtString75", None), - ByteField("txtString76", None), - ByteField("txtString77", None), - ByteField("txtString78", None), - ByteField("txtString79", None), - ByteField("txtString80", None), - ByteField("txtString81", None), - ByteField("txtString82", None), - ByteField("txtString83", None), - ByteField("txtString84", None), - ByteField("txtString85", None), - ByteField("txtString86", None), - ByteField("txtString87", None), - ByteField("txtString88", None), - ByteField("txtString89", None), - ByteField("txtString90", None), - ByteField("txtString91", None), - ByteField("txtString92", None), - ByteField("txtString93", None), - ByteField("txtString94", None), - ByteField("txtString95", None), - ByteField("txtString96", None), - ByteField("txtString97", None), - ByteField("txtString98", None), - ByteField("txtString99", None), - ByteField("txtString100", None), - ByteField("txtString101", None), - ByteField("txtString102", None), - ByteField("txtString103", None), - ByteField("txtString104", None), - ByteField("txtString105", None), - ByteField("txtString106", None), - ByteField("txtString107", None), - ByteField("txtString108", None), - ByteField("txtString109", None), - ByteField("txtString110", None), - ByteField("txtString111", None), - ByteField("txtString112", None), - ByteField("txtString113", None), - ByteField("txtString114", None), - ByteField("txtString115", None), - ByteField("txtString116", None), - ByteField("txtString117", None), - ByteField("txtString118", None), - ByteField("txtString119", None), - ByteField("txtString120", None), - ByteField("txtString121", None), - ByteField("txtString122", None), - ByteField("txtString123", None), - ByteField("txtString124", None), - ByteField("txtString125", None), - ByteField("txtString126", None), - ByteField("txtString127", None), - ByteField("txtString128", None), - ByteField("txtString129", None), - ByteField("txtString130", None), - ByteField("txtString131", None), - ByteField("txtString132", None), - ByteField("txtString133", None), - ByteField("txtString134", None), - ByteField("txtString135", None), - ByteField("txtString136", None), - ByteField("txtString137", None), - ByteField("txtString138", None), - ByteField("txtString139", None), - ByteField("txtString140", None), - ByteField("txtString141", None), - ByteField("txtString142", None), - ByteField("txtString143", None), - ByteField("txtString144", None), - ByteField("txtString145", None), - ByteField("txtString146", None), - ByteField("txtString147", None), - ByteField("txtString148", None), - ByteField("txtString149", None), - ByteField("txtString150", None), - ByteField("txtString151", None), - ByteField("txtString152", None), - ByteField("txtString153", None), - ByteField("txtString154", None), - ByteField("txtString155", None), - ByteField("txtString156", None), - ByteField("txtString157", None), - ByteField("txtString158", None), - ByteField("txtString159", None), - ByteField("txtString160", None), - ByteField("txtString161", None), - ByteField("txtString162", None), - ByteField("txtString163", None), - ByteField("txtString164", None), - ByteField("txtString165", None), - ByteField("txtString166", None), - ByteField("txtString167", None), - ByteField("txtString168", None), - ByteField("txtString169", None), - ByteField("txtString170", None), - ByteField("txtString171", None), - ByteField("txtString172", None), - ByteField("txtString173", None), - ByteField("txtString174", None), - ByteField("txtString175", None), - ByteField("txtString176", None), - ByteField("txtString177", None), - ByteField("txtString178", None), - ByteField("txtString179", None), - ByteField("txtString180", None), - ByteField("txtString181", None), - ByteField("txtString182", None), - ByteField("txtString183", None), - ByteField("txtString184", None), - ByteField("txtString185", None), - ByteField("txtString186", None), - ByteField("txtString187", None), - ByteField("txtString188", None), - ByteField("txtString189", None), - ByteField("txtString190", None), - ByteField("txtString191", None), - ByteField("txtString192", None), - ByteField("txtString193", None), - ByteField("txtString194", None), - ByteField("txtString195", None), - ByteField("txtString196", None), - ByteField("txtString197", None), - ByteField("txtString198", None), - ByteField("txtString199", None), - ByteField("txtString200", None), - ByteField("txtString201", None), - ByteField("txtString202", None), - ByteField("txtString203", None), - ByteField("txtString204", None), - ByteField("txtString205", None), - ByteField("txtString206", None), - ByteField("txtString207", None), - ByteField("txtString208", None), - ByteField("txtString209", None), - ByteField("txtString210", None), - ByteField("txtString211", None), - ByteField("txtString212", None), - ByteField("txtString213", None), - ByteField("txtString214", None), - ByteField("txtString215", None), - ByteField("txtString216", None), - ByteField("txtString217", None), - ByteField("txtString218", None), - ByteField("txtString219", None), - ByteField("txtString220", None), - ByteField("txtString221", None), - ByteField("txtString222", None), - ByteField("txtString223", None), - ByteField("txtString224", None), - ByteField("txtString225", None), - ByteField("txtString226", None), - ByteField("txtString227", None), - ByteField("txtString228", None), - ByteField("txtString229", None), - ByteField("txtString230", None), - ByteField("txtString231", None), - ByteField("txtString232", None), - ByteField("txtString233", None), - ByteField("txtString234", None), - ByteField("txtString235", None), - ByteField("txtString236", None), - ByteField("txtString237", None), - ByteField("txtString238", None), - ByteField("txtString239", None), - ByteField("txtString240", None), - ByteField("txtString241", None), - ByteField("txtString242", None), - ByteField("txtString243", None), - ByteField("txtString244", None), - ByteField("txtString245", None), - ByteField("txtString246", None), - ByteField("txtString247", None), - ByteField("txtString248", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 250, a, self.fields_desc, 1) - if self.lengthNN is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class TimeZone(Packet): - """Time Zone Section 10.5.3.8""" - name = "Time Zone" - fields_desc = [ - ByteField("timeZone", 0x0), - ] - - -class TimeZoneAndTime(Packet): - """Time Zone and Time Section 10.5.3.9""" - name = "Time Zone and Time" - fields_desc = [ - ByteField("year", 0x0), - ByteField("month", 0x0), - ByteField("day", 0x0), - ByteField("hour", 0x0), - ByteField("minute", 0x0), - ByteField("second", 0x0), - ByteField("timeZone", 0x0) - ] - - -class CtsPermission(Packet): - """CTS permission Section 10.5.3.10""" - name = "Cts Permission" - fields_desc = [ - ] - - -class LsaIdentifier(Packet): - """LSA Identifier Section 10.5.3.11""" - name = "Lsa Identifier" - fields_desc = [ - ByteField("lsaID", 0x0), - ByteField("lsaID1", 0x0), - ByteField("lsaID2", 0x0) - ] - - -# -# 10.5.4 Call control information elements -# - -#10.5.4.1 Extensions of codesets -# This is only text and no packet - -class LockingShiftProcedure(Packet): - """Locking shift procedure Section 10.5.4.2""" - name = "Locking Shift Procedure" - fields_desc = [ - BitField("lockShift", 0x0, 1), - BitField("codesetId", 0x0, 3) - ] - - -class NonLockingShiftProcedure(Packet): - """Non-locking shift procedure Section 10.5.4.3""" - name = "Non-locking Shift Procedure" - fields_desc = [ - BitField("nonLockShift", 0x1, 1), - BitField("codesetId", 0x0, 3) - ] - - -class AuxiliaryStates(Packet): - """Auxiliary states Section 10.5.4.4""" - name = "Auxiliary States" - fields_desc = [ - XByteField("lengthAS", 0x3), - BitField("ext", 0x1, 1), - BitField("spare", 0x0, 3), - BitField("holdState", 0x0, 2), - BitField("mptyState", 0x0, 2) - ] - - -# len 3 to 15 -class BearerCapability(Packet): - """Bearer capability Section 10.5.4.5""" - name = "Bearer Capability" - fields_desc = [ - - XByteField("lengthBC", None), - - BitField("ext0", 0x1, 1), - BitField("radioChReq", 0x1, 2), - BitField("codingStd", 0x0, 1), - BitField("transMode", 0x0, 1), - BitField("infoTransCa", 0x0, 3), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("coding", None, 1), - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("spare", None, 2), - lambda pkt: pkt.ext0 == 0), - ConditionalField(BitField("speechVers", 0x0, 4), - lambda pkt: pkt.ext0 == 0), - - ConditionalField(BitField("ext2", 0x1, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("compress", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("structure", None, 2), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("dupMode", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("config", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("nirr", None, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("establi", 0x0, 1), - lambda pkt: pkt.ext1 == 0), - - BitField("ext3", None, 1), - BitField("accessId", None, 2), - BitField("rateAda", None, 2), - BitField("signaling", None, 3), - - ConditionalField(BitField("ext4", None, 1), - lambda pkt: pkt.ext3 == 0), - ConditionalField(BitField("otherITC", None, 2), - lambda pkt: pkt.ext3 == 0), - ConditionalField(BitField("otherRate", None, 2), - lambda pkt: pkt.ext3 == 0), - ConditionalField(BitField("spare1", 0x0, 3), - lambda pkt: pkt.ext3 == 0), - - ConditionalField(BitField("ext5", 0x1, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("hdr", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("multiFr", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("mode", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("lli", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("assig", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("inbNeg", None, 1), - lambda pkt: pkt.ext4 == 0), - ConditionalField(BitField("spare2", 0x0, 1), - lambda pkt: pkt.ext4 == 0), - - BitField("ext6", None, 1), - BitField("layer1Id", None, 2), - BitField("userInf", None, 4), - BitField("sync", None, 1), - - ConditionalField(BitField("ext7", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("stopBit", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("negoc", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("nbDataBit", None, 1), - lambda pkt: pkt.ext6 == 0), - ConditionalField(BitField("userRate", None, 4), - lambda pkt: pkt.ext6 == 0), - - ConditionalField(BitField("ext8", None, 1), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("interRate", None, 2), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("nicTX", None, 1), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("nicRX", None, 1), - lambda pkt: pkt.ext7 == 0), - ConditionalField(BitField("parity", None, 3), - lambda pkt: pkt.ext7 == 0), - - ConditionalField(BitField("ext9", None, 1), - lambda pkt: pkt.ext8 == 0), - ConditionalField(BitField("connEle", None, 2), - lambda pkt: pkt.ext8 == 0), - ConditionalField(BitField("modemType", None, 5), - lambda pkt: pkt.ext8 == 0), - - ConditionalField(BitField("ext10", None, 1), - lambda pkt: pkt.ext9 == 0), - ConditionalField(BitField("otherModemType", None, 2), - lambda pkt: pkt.ext9 == 0), - ConditionalField(BitField("netUserRate", None, 5), - lambda pkt: pkt.ext9 == 0), - - ConditionalField(BitField("ext11", None, 1), - lambda pkt: pkt.ext10 == 0), - ConditionalField(BitField("chanCoding", None, 4), - lambda pkt: pkt.ext10 == 0), - ConditionalField(BitField("maxTrafficChan", None, 3), - lambda pkt: pkt.ext10 == 0), - - ConditionalField(BitField("ext12", None, 1), - lambda pkt: pkt.ext11 == 0), - ConditionalField(BitField("uimi", None, 3), - lambda pkt: pkt.ext11 == 0), - ConditionalField(BitField("airInterfaceUserRate", None, 4), - lambda pkt: pkt.ext11 == 0), - - ConditionalField(BitField("ext13", 0x1, 1), - lambda pkt: pkt.ext12 == 0), - ConditionalField(BitField("layer2Ch", None, 2), - lambda pkt: pkt.ext12 == 0), - ConditionalField(BitField("userInfoL2", 0x0, 5), - lambda pkt: pkt.ext12 == 0) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 15, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthBC is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay - - -class CallControlCapabilities(Packet): - """Call Control Capabilities Section 10.5.4.5a""" - name = "Call Control Capabilities" - fields_desc = [ - XByteField("lengthCCC", 0x3), - BitField("spare", 0x0, 6), - BitField("pcp", 0x0, 1), - BitField("dtmf", 0x0, 1) - ] - - -class CallState(Packet): - """Call State Section 10.5.4.6""" - name = "Call State" - fields_desc = [ - BitField("codingStd", 0x0, 2), - BitField("stateValue", 0x0, 6) - ] - - -# len 3 to 43 -class CalledPartyBcdNumber(Packet): - """Called party BCD number Section 10.5.4.7""" - name = "Called Party BCD Number" - fields_desc = [ - XByteField("lengthCPBN", None), - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("nbPlanId", 0x0, 4), - # optional - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4), - - BitField("nbDigit22", None, 4), - BitField("nbDigit21", None, 4), - BitField("nbDigit24", None, 4), - BitField("nbDigit23", None, 4), - - BitField("nbDigit26", None, 4), - BitField("nbDigit25", None, 4), - BitField("nbDigit28", None, 4), - BitField("nbDigit27", None, 4), - - BitField("nbDigit30", None, 4), - BitField("nbDigit29", None, 4), - BitField("nbDigit32", None, 4), - BitField("nbDigit31", None, 4), - - BitField("nbDigit34", None, 4), - BitField("nbDigit33", None, 4), - BitField("nbDigit36", None, 4), - BitField("nbDigit35", None, 4), - - BitField("nbDigit38", None, 4), - BitField("nbDigit37", None, 4), - BitField("nbDigit40", None, 4), - BitField("nbDigit39", None, 4), -# ^^^^^^ 20 first optional bytes ^^^^^^^^^^^^^^^ - BitField("nbDigit42", None, 4), - BitField("nbDigit41", None, 4), - BitField("nbDigit44", None, 4), - BitField("nbDigit43", None, 4), - - BitField("nbDigit46", None, 4), - BitField("nbDigit45", None, 4), - BitField("nbDigit48", None, 4), - BitField("nbDigit47", None, 4), - - BitField("nbDigit50", None, 4), - BitField("nbDigit49", None, 4), - BitField("nbDigit52", None, 4), - BitField("nbDigit51", None, 4), - - BitField("nbDigit54", None, 4), - BitField("nbDigit53", None, 4), - BitField("nbDigit56", None, 4), - BitField("nbDigit55", None, 4), - - BitField("nbDigit58", None, 4), - BitField("nbDigit57", None, 4), - BitField("nbDigit60", None, 4), - BitField("nbDigit59", None, 4), - - BitField("nbDigit62", None, 4), - BitField("nbDigit61", None, 4), - BitField("nbDigit64", None, 4), - BitField("nbDigit63", None, 4), - - BitField("nbDigit66", None, 4), - BitField("nbDigit65", None, 4), - BitField("nbDigit68", None, 4), - BitField("nbDigit67", None, 4), - - BitField("nbDigit70", None, 4), - BitField("nbDigit69", None, 4), - BitField("nbDigit72", None, 4), - BitField("nbDigit71", None, 4), - - BitField("nbDigit74", None, 4), - BitField("nbDigit73", None, 4), - BitField("nbDigit76", None, 4), - BitField("nbDigit75", None, 4), - - BitField("nbDigit78", None, 4), - BitField("nbDigit77", None, 4), - BitField("nbDigit80", None, 4), - BitField("nbDigit79", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 42, a, self.fields_desc, 1) - if self.lengthCPBN is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 2 to 23 -class CalledPartySubaddress(Packet): - """Called party subaddress Section 10.5.4.8""" - name = "Called Party Subaddress" - fields_desc = [ - XByteField("lengthCPS", None), - # optional - BitField("ext", None, 1), - BitField("subAddr", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 23, a, self.fields_desc, 1) - if self.lengthCPS is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 3 to 14 -class CallingPartyBcdNumber(Packet): - """Called party subaddress Section 10.5.4.9""" - name = "Called Party Subaddress" - fields_desc = [ - XByteField("lengthCPBN", None), - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("nbPlanId", 0x0, 4), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("presId", None, 2), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("spare", None, 3), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("screenId", 0x0, 2), - lambda pkt: pkt.ext == 0), - - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 13, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthCPBN is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay - - -# len 2 to 23 -class CallingPartySubaddress(Packet): - """Calling party subaddress Section 10.5.4.10""" - name = "Calling Party Subaddress" - fields_desc = [ - XByteField("lengthCPS", None), - # optional - BitField("ext1", None, 1), - BitField("typeAddr", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 22, a, self.fields_desc, 1) - if self.lengthCPS is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 4 to 32 -class Cause(Packet): - """Cause Section 10.5.4.11""" - name = "Cause" - fields_desc = [ - - XByteField("lengthC", None), - - BitField("ext", 0x1, 1), - BitField("codingStd", 0x0, 2), - BitField("spare", 0x0, 1), - BitField("location", 0x0, 4), - - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("recommendation", 0x1, 7), - lambda pkt: pkt.ext == 0), - # optional - BitField("ext2", None, 1), - BitField("causeValue", None, 7), - - ByteField("diagnositc0", None), - ByteField("diagnositc1", None), - ByteField("diagnositc2", None), - ByteField("diagnositc3", None), - ByteField("diagnositc4", None), - ByteField("diagnositc5", None), - ByteField("diagnositc6", None), - ByteField("diagnositc7", None), - ByteField("diagnositc8", None), - ByteField("diagnositc9", None), - ByteField("diagnositc10", None), - ByteField("diagnositc11", None), - ByteField("diagnositc12", None), - ByteField("diagnositc13", None), - ByteField("diagnositc14", None), - ByteField("diagnositc15", None), - ByteField("diagnositc16", None), - ByteField("diagnositc17", None), - ByteField("diagnositc18", None), - ByteField("diagnositc19", None), - ByteField("diagnositc20", None), - ByteField("diagnositc21", None), - ByteField("diagnositc22", None), - ByteField("diagnositc23", None), - ByteField("diagnositc24", None), - ByteField("diagnositc25", None), - ByteField("diagnositc26", None), - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(3, 31, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthC is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay - - -class ClirSuppression(Packet): - """CLIR suppression Section 10.5.4.11a""" - name = "Clir Suppression" - fields_desc = [ - ] - - -class ClirInvocation(Packet): - """CLIR invocation Section 10.5.4.11b""" - name = "Clir Invocation" - fields_desc = [ - ] - - -class CongestionLevel(Packet): - """Congestion level Section 10.5.4.12""" - name = "Congestion Level" - fields_desc = [ - BitField("notDef", 0x0, 4) # not defined by the std - ] - - -# len 3 to 14 -class ConnectedNumber(Packet): - """Connected number Section 10.5.4.13""" - name = "Connected Number" - fields_desc = [ - - XByteField("lengthCN", None), - - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("typePlanId", 0x0, 4), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("presId", None, 2), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("spare", None, 3), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("screenId", None, 2), - lambda pkt: pkt.ext == 0), - - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 13, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthCN is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay - - -# len 2 to 23 -class ConnectedSubaddress(Packet): - """Connected subaddress Section 10.5.4.14""" - name = "Connected Subaddress" - fields_desc = [ - - XByteField("lengthCS", None), - # optional - BitField("ext", None, 1), - BitField("typeOfSub", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - a = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 22, a, self.fields_desc, 1) - if self.lengthCS is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# len 2 to L3 (251) (done) -class Facility(Packet): - """Facility Section 10.5.4.15""" - name = "Facility" - fields_desc = [ - XByteField("lengthF", None), - # optional - ByteField("facilityInfo1", None), - ByteField("facilityInfo2", None), - ByteField("facilityInfo3", None), - ByteField("facilityInfo4", None), - ByteField("facilityInfo5", None), - ByteField("facilityInfo6", None), - ByteField("facilityInfo7", None), - ByteField("facilityInfo8", None), - ByteField("facilityInfo9", None), - ByteField("facilityInfo10", None), - ByteField("facilityInfo11", None), - ByteField("facilityInfo12", None), - ByteField("facilityInfo13", None), - ByteField("facilityInfo14", None), - ByteField("facilityInfo15", None), - ByteField("facilityInfo16", None), - ByteField("facilityInfo17", None), - ByteField("facilityInfo18", None), - ByteField("facilityInfo19", None), - ByteField("facilityInfo20", None), - ByteField("facilityInfo21", None), - ByteField("facilityInfo22", None), - ByteField("facilityInfo23", None), - ByteField("facilityInfo24", None), - ByteField("facilityInfo25", None), - ByteField("facilityInfo26", None), - ByteField("facilityInfo27", None), - ByteField("facilityInfo28", None), - ByteField("facilityInfo29", None), - ByteField("facilityInfo30", None), - ByteField("facilityInfo31", None), - ByteField("facilityInfo32", None), - ByteField("facilityInfo33", None), - ByteField("facilityInfo34", None), - ByteField("facilityInfo35", None), - ByteField("facilityInfo36", None), - ByteField("facilityInfo37", None), - ByteField("facilityInfo38", None), - ByteField("facilityInfo39", None), - ByteField("facilityInfo40", None), - ByteField("facilityInfo41", None), - ByteField("facilityInfo42", None), - ByteField("facilityInfo43", None), - ByteField("facilityInfo44", None), - ByteField("facilityInfo45", None), - ByteField("facilityInfo46", None), - ByteField("facilityInfo47", None), - ByteField("facilityInfo48", None), - ByteField("facilityInfo49", None), - ByteField("facilityInfo50", None), - ByteField("facilityInfo51", None), - ByteField("facilityInfo52", None), - ByteField("facilityInfo53", None), - ByteField("facilityInfo54", None), - ByteField("facilityInfo55", None), - ByteField("facilityInfo56", None), - ByteField("facilityInfo57", None), - ByteField("facilityInfo58", None), - ByteField("facilityInfo59", None), - ByteField("facilityInfo60", None), - ByteField("facilityInfo61", None), - ByteField("facilityInfo62", None), - ByteField("facilityInfo63", None), - ByteField("facilityInfo64", None), - ByteField("facilityInfo65", None), - ByteField("facilityInfo66", None), - ByteField("facilityInfo67", None), - ByteField("facilityInfo68", None), - ByteField("facilityInfo69", None), - ByteField("facilityInfo70", None), - ByteField("facilityInfo71", None), - ByteField("facilityInfo72", None), - ByteField("facilityInfo73", None), - ByteField("facilityInfo74", None), - ByteField("facilityInfo75", None), - ByteField("facilityInfo76", None), - ByteField("facilityInfo77", None), - ByteField("facilityInfo78", None), - ByteField("facilityInfo79", None), - ByteField("facilityInfo80", None), - ByteField("facilityInfo81", None), - ByteField("facilityInfo82", None), - ByteField("facilityInfo83", None), - ByteField("facilityInfo84", None), - ByteField("facilityInfo85", None), - ByteField("facilityInfo86", None), - ByteField("facilityInfo87", None), - ByteField("facilityInfo88", None), - ByteField("facilityInfo89", None), - ByteField("facilityInfo90", None), - ByteField("facilityInfo91", None), - ByteField("facilityInfo92", None), - ByteField("facilityInfo93", None), - ByteField("facilityInfo94", None), - ByteField("facilityInfo95", None), - ByteField("facilityInfo96", None), - ByteField("facilityInfo97", None), - ByteField("facilityInfo98", None), - ByteField("facilityInfo99", None), - ByteField("facilityInfo100", None), - ByteField("facilityInfo101", None), - ByteField("facilityInfo102", None), - ByteField("facilityInfo103", None), - ByteField("facilityInfo104", None), - ByteField("facilityInfo105", None), - ByteField("facilityInfo106", None), - ByteField("facilityInfo107", None), - ByteField("facilityInfo108", None), - ByteField("facilityInfo109", None), - ByteField("facilityInfo110", None), - ByteField("facilityInfo111", None), - ByteField("facilityInfo112", None), - ByteField("facilityInfo113", None), - ByteField("facilityInfo114", None), - ByteField("facilityInfo115", None), - ByteField("facilityInfo116", None), - ByteField("facilityInfo117", None), - ByteField("facilityInfo118", None), - ByteField("facilityInfo119", None), - ByteField("facilityInfo120", None), - ByteField("facilityInfo121", None), - ByteField("facilityInfo122", None), - ByteField("facilityInfo123", None), - ByteField("facilityInfo124", None), - ByteField("facilityInfo125", None), - ByteField("facilityInfo126", None), - ByteField("facilityInfo127", None), - ByteField("facilityInfo128", None), - ByteField("facilityInfo129", None), - ByteField("facilityInfo130", None), - ByteField("facilityInfo131", None), - ByteField("facilityInfo132", None), - ByteField("facilityInfo133", None), - ByteField("facilityInfo134", None), - ByteField("facilityInfo135", None), - ByteField("facilityInfo136", None), - ByteField("facilityInfo137", None), - ByteField("facilityInfo138", None), - ByteField("facilityInfo139", None), - ByteField("facilityInfo140", None), - ByteField("facilityInfo141", None), - ByteField("facilityInfo142", None), - ByteField("facilityInfo143", None), - ByteField("facilityInfo144", None), - ByteField("facilityInfo145", None), - ByteField("facilityInfo146", None), - ByteField("facilityInfo147", None), - ByteField("facilityInfo148", None), - ByteField("facilityInfo149", None), - ByteField("facilityInfo150", None), - ByteField("facilityInfo151", None), - ByteField("facilityInfo152", None), - ByteField("facilityInfo153", None), - ByteField("facilityInfo154", None), - ByteField("facilityInfo155", None), - ByteField("facilityInfo156", None), - ByteField("facilityInfo157", None), - ByteField("facilityInfo158", None), - ByteField("facilityInfo159", None), - ByteField("facilityInfo160", None), - ByteField("facilityInfo161", None), - ByteField("facilityInfo162", None), - ByteField("facilityInfo163", None), - ByteField("facilityInfo164", None), - ByteField("facilityInfo165", None), - ByteField("facilityInfo166", None), - ByteField("facilityInfo167", None), - ByteField("facilityInfo168", None), - ByteField("facilityInfo169", None), - ByteField("facilityInfo170", None), - ByteField("facilityInfo171", None), - ByteField("facilityInfo172", None), - ByteField("facilityInfo173", None), - ByteField("facilityInfo174", None), - ByteField("facilityInfo175", None), - ByteField("facilityInfo176", None), - ByteField("facilityInfo177", None), - ByteField("facilityInfo178", None), - ByteField("facilityInfo179", None), - ByteField("facilityInfo180", None), - ByteField("facilityInfo181", None), - ByteField("facilityInfo182", None), - ByteField("facilityInfo183", None), - ByteField("facilityInfo184", None), - ByteField("facilityInfo185", None), - ByteField("facilityInfo186", None), - ByteField("facilityInfo187", None), - ByteField("facilityInfo188", None), - ByteField("facilityInfo189", None), - ByteField("facilityInfo190", None), - ByteField("facilityInfo191", None), - ByteField("facilityInfo192", None), - ByteField("facilityInfo193", None), - ByteField("facilityInfo194", None), - ByteField("facilityInfo195", None), - ByteField("facilityInfo196", None), - ByteField("facilityInfo197", None), - ByteField("facilityInfo198", None), - ByteField("facilityInfo199", None), - ByteField("facilityInfo200", None), - ByteField("facilityInfo201", None), - ByteField("facilityInfo202", None), - ByteField("facilityInfo203", None), - ByteField("facilityInfo204", None), - ByteField("facilityInfo205", None), - ByteField("facilityInfo206", None), - ByteField("facilityInfo207", None), - ByteField("facilityInfo208", None), - ByteField("facilityInfo209", None), - ByteField("facilityInfo210", None), - ByteField("facilityInfo211", None), - ByteField("facilityInfo212", None), - ByteField("facilityInfo213", None), - ByteField("facilityInfo214", None), - ByteField("facilityInfo215", None), - ByteField("facilityInfo216", None), - ByteField("facilityInfo217", None), - ByteField("facilityInfo218", None), - ByteField("facilityInfo219", None), - ByteField("facilityInfo220", None), - ByteField("facilityInfo221", None), - ByteField("facilityInfo222", None), - ByteField("facilityInfo223", None), - ByteField("facilityInfo224", None), - ByteField("facilityInfo225", None), - ByteField("facilityInfo226", None), - ByteField("facilityInfo227", None), - ByteField("facilityInfo228", None), - ByteField("facilityInfo229", None), - ByteField("facilityInfo230", None), - ByteField("facilityInfo231", None), - ByteField("facilityInfo232", None), - ByteField("facilityInfo233", None), - ByteField("facilityInfo234", None), - ByteField("facilityInfo235", None), - ByteField("facilityInfo236", None), - ByteField("facilityInfo237", None), - ByteField("facilityInfo238", None), - ByteField("facilityInfo239", None), - ByteField("facilityInfo240", None), - ByteField("facilityInfo241", None), - ByteField("facilityInfo242", None), - ByteField("facilityInfo243", None), - ByteField("facilityInfo244", None), - ByteField("facilityInfo245", None), - ByteField("facilityInfo246", None), - ByteField("facilityInfo247", None), - ByteField("facilityInfo248", None), - ByteField("facilityInfo249", None) - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(7, 250, a, self.fields_desc, 1) - if self.lengthF is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -#len 2 to 5 -class HighLayerCompatibility(Packet): - """High layer compatibility Section 10.5.4.16""" - name = "High Layer Compatibility" - fields_desc = [ - - XByteField("lengthHLC", None), - # optional - BitField("ext", None, 1), - BitField("codingStd", None, 2), - BitField("interpret", None, 3), - BitField("presMeth", None, 2), - - BitField("ext1", None, 1), - BitField("highLayerId", None, 7), - - ConditionalField(BitField("ext2", 0x1, 1), - lambda pkt: pkt.ext1 == 0), - ConditionalField(BitField("exHiLayerId", 0x0, 7), - lambda pkt: pkt.ext1 == 0), - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 4, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthHLC is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay -# -# 10.5.4.16.1 Static conditions for the high layer -# compatibility IE contents -# - - -class KeypadFacility(Packet): - """Keypad facility Section 10.5.4.17""" - name = "Keypad Facility" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("keyPadInfo", 0x0, 7) - ] - - -# len 2 to 15 -class LowLayerCompatibility(Packet): - """Low layer compatibility Section 10.5.4.18""" - name = "Low Layer Compatibility" - fields_desc = [ - - XByteField("lengthLLC", None), - # optional - ByteField("rest0", None), - ByteField("rest1", None), - ByteField("rest2", None), - ByteField("rest3", None), - ByteField("rest4", None), - ByteField("rest5", None), - ByteField("rest6", None), - ByteField("rest7", None), - ByteField("rest8", None), - ByteField("rest9", None), - ByteField("rest10", None), - ByteField("rest11", None), - ByteField("rest12", None) - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 14, a, self.fields_desc, 1) - if self.lengthLLC is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class MoreData(Packet): - """More data Section 10.5.4.19""" - name = "More Data" - fields_desc = [ - ] - - -class NotificationIndicator(Packet): - """Notification indicator Section 10.5.4.20""" - name = "Notification Indicator" - fields_desc = [ - BitField("ext1", 0x1, 1), - BitField("notifDesc", 0x0, 7) - ] - - -class ProgressIndicator(Packet): - """Progress indicator Section 10.5.4.21""" - name = "Progress Indicator" - fields_desc = [ - XByteField("lengthPI", 0x2), - BitField("ext", 0x1, 1), - BitField("codingStd", 0x0, 2), - BitField("spare", 0x0, 1), - BitField("location", 0x0, 4), - BitField("ext1", 0x1, 1), - BitField("progressDesc", 0x0, 7) - ] - - -class RecallType(Packet): - """Recall type $(CCBS)$ Section 10.5.4.21a""" - name = "Recall Type $(CCBS)$" - fields_desc = [ - BitField("spare", 0x0, 5), - BitField("recallType", 0x0, 3) - ] - - -# len 3 to 19 -class RedirectingPartyBcdNumber(Packet): - """Redirecting party BCD number Section 10.5.4.21b""" - name = "Redirecting Party BCD Number" - fields_desc = [ - - XByteField("lengthRPBN", None), - - BitField("ext", 0x1, 1), - BitField("typeNb", 0x0, 3), - BitField("numberingPlan", 0x0, 4), - # optional - ConditionalField(BitField("ext1", 0x1, 1), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("presId", 0x0, 2), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("spare", 0x0, 3), - lambda pkt: pkt.ext == 0), - ConditionalField(BitField("screenId", 0x0, 2), - lambda pkt: pkt.ext == 0), - - BitField("nbDigit2", None, 4), - BitField("nbDigit1", None, 4), - - BitField("nbDigit4", None, 4), - BitField("nbDigit3", None, 4), - - BitField("nbDigit6", None, 4), - BitField("nbDigit5", None, 4), - - BitField("nbDigit8", None, 4), - BitField("nbDigit7", None, 4), - - BitField("nbDigit10", None, 4), - BitField("nbDigit9", None, 4), - - BitField("nbDigit12", None, 4), - BitField("nbDigit11", None, 4), - - BitField("nbDigit14", None, 4), - BitField("nbDigit13", None, 4), - - BitField("nbDigit16", None, 4), - BitField("nbDigit15", None, 4), - - BitField("nbDigit18", None, 4), - BitField("nbDigit17", None, 4), - - BitField("nbDigit20", None, 4), - BitField("nbDigit19", None, 4), - - BitField("nbDigit22", None, 4), - BitField("nbDigit21", None, 4), - - BitField("nbDigit24", None, 4), - BitField("nbDigit23", None, 4), - - BitField("nbDigit26", None, 4), - BitField("nbDigit25", None, 4), - - BitField("nbDigit28", None, 4), - BitField("nbDigit27", None, 4), - - BitField("nbDigit30", None, 4), - BitField("nbDigit29", None, 4), - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 18, a, self.fields_desc, 1) - if res[0] is not 0: - p = p[:-res[0]] - if self.lengthRPBN is None: - p = struct.pack(">B", len(p)-1) + p[1:] - return p + pay - - -# length 2 to 23 -class RedirectingPartySubaddress(Packet): - """Redirecting party subaddress Section 10.5.4.21c""" - name = "Redirecting Party BCD Number" - fields_desc = [ - - XByteField("lengthRPS", None), - # optional - BitField("ext", None, 1), - BitField("typeSub", None, 3), - BitField("oddEven", None, 1), - BitField("spare", None, 3), - - ByteField("subInfo0", None), - ByteField("subInfo1", None), - ByteField("subInfo2", None), - ByteField("subInfo3", None), - ByteField("subInfo4", None), - ByteField("subInfo5", None), - ByteField("subInfo6", None), - ByteField("subInfo7", None), - ByteField("subInfo8", None), - ByteField("subInfo9", None), - ByteField("subInfo10", None), - ByteField("subInfo11", None), - ByteField("subInfo12", None), - ByteField("subInfo13", None), - ByteField("subInfo14", None), - ByteField("subInfo15", None), - ByteField("subInfo16", None), - ByteField("subInfo17", None), - ByteField("subInfo18", None), - ByteField("subInfo19", None) - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 22, a, self.fields_desc, 1) - if self.lengthRPS is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class RepeatIndicator(Packet): - """Repeat indicator Section 10.5.4.22""" - name = "Repeat Indicator" - fields_desc = [ - BitField("repeatIndic", 0x0, 4) - ] - - -# no upper length min 2(max for L3) (251) -class SetupContainer(Packet): - """SETUP Container $(CCBS)$ Section 10.5.4.22b""" - name = "Setup Container $(CCBS)$" - fields_desc = [ - XByteField("lengthSC", None), - # optional - ByteField("mess1", None), - ByteField("mess2", None), - ByteField("mess3", None), - ByteField("mess4", None), - ByteField("mess5", None), - ByteField("mess6", None), - ByteField("mess7", None), - ByteField("mess8", None), - ByteField("mess9", None), - ByteField("mess10", None), - ByteField("mess11", None), - ByteField("mess12", None), - ByteField("mess13", None), - ByteField("mess14", None), - ByteField("mess15", None), - ByteField("mess16", None), - ByteField("mess17", None), - ByteField("mess18", None), - ByteField("mess19", None), - ByteField("mess20", None), - ByteField("mess21", None), - ByteField("mess22", None), - ByteField("mess23", None), - ByteField("mess24", None), - ByteField("mess25", None), - ByteField("mess26", None), - ByteField("mess27", None), - ByteField("mess28", None), - ByteField("mess29", None), - ByteField("mess30", None), - ByteField("mess31", None), - ByteField("mess32", None), - ByteField("mess33", None), - ByteField("mess34", None), - ByteField("mess35", None), - ByteField("mess36", None), - ByteField("mess37", None), - ByteField("mess38", None), - ByteField("mess39", None), - ByteField("mess40", None), - ByteField("mess41", None), - ByteField("mess42", None), - ByteField("mess43", None), - ByteField("mess44", None), - ByteField("mess45", None), - ByteField("mess46", None), - ByteField("mess47", None), - ByteField("mess48", None), - ByteField("mess49", None), - ByteField("mess50", None), - ByteField("mess51", None), - ByteField("mess52", None), - ByteField("mess53", None), - ByteField("mess54", None), - ByteField("mess55", None), - ByteField("mess56", None), - ByteField("mess57", None), - ByteField("mess58", None), - ByteField("mess59", None), - ByteField("mess60", None), - ByteField("mess61", None), - ByteField("mess62", None), - ByteField("mess63", None), - ByteField("mess64", None), - ByteField("mess65", None), - ByteField("mess66", None), - ByteField("mess67", None), - ByteField("mess68", None), - ByteField("mess69", None), - ByteField("mess70", None), - ByteField("mess71", None), - ByteField("mess72", None), - ByteField("mess73", None), - ByteField("mess74", None), - ByteField("mess75", None), - ByteField("mess76", None), - ByteField("mess77", None), - ByteField("mess78", None), - ByteField("mess79", None), - ByteField("mess80", None), - ByteField("mess81", None), - ByteField("mess82", None), - ByteField("mess83", None), - ByteField("mess84", None), - ByteField("mess85", None), - ByteField("mess86", None), - ByteField("mess87", None), - ByteField("mess88", None), - ByteField("mess89", None), - ByteField("mess90", None), - ByteField("mess91", None), - ByteField("mess92", None), - ByteField("mess93", None), - ByteField("mess94", None), - ByteField("mess95", None), - ByteField("mess96", None), - ByteField("mess97", None), - ByteField("mess98", None), - ByteField("mess99", None), - ByteField("mess100", None), - ByteField("mess101", None), - ByteField("mess102", None), - ByteField("mess103", None), - ByteField("mess104", None), - ByteField("mess105", None), - ByteField("mess106", None), - ByteField("mess107", None), - ByteField("mess108", None), - ByteField("mess109", None), - ByteField("mess110", None), - ByteField("mess111", None), - ByteField("mess112", None), - ByteField("mess113", None), - ByteField("mess114", None), - ByteField("mess115", None), - ByteField("mess116", None), - ByteField("mess117", None), - ByteField("mess118", None), - ByteField("mess119", None), - ByteField("mess120", None), - ByteField("mess121", None), - ByteField("mess122", None), - ByteField("mess123", None), - ByteField("mess124", None), - ByteField("mess125", None), - ByteField("mess126", None), - ByteField("mess127", None), - ByteField("mess128", None), - ByteField("mess129", None), - ByteField("mess130", None), - ByteField("mess131", None), - ByteField("mess132", None), - ByteField("mess133", None), - ByteField("mess134", None), - ByteField("mess135", None), - ByteField("mess136", None), - ByteField("mess137", None), - ByteField("mess138", None), - ByteField("mess139", None), - ByteField("mess140", None), - ByteField("mess141", None), - ByteField("mess142", None), - ByteField("mess143", None), - ByteField("mess144", None), - ByteField("mess145", None), - ByteField("mess146", None), - ByteField("mess147", None), - ByteField("mess148", None), - ByteField("mess149", None), - ByteField("mess150", None), - ByteField("mess151", None), - ByteField("mess152", None), - ByteField("mess153", None), - ByteField("mess154", None), - ByteField("mess155", None), - ByteField("mess156", None), - ByteField("mess157", None), - ByteField("mess158", None), - ByteField("mess159", None), - ByteField("mess160", None), - ByteField("mess161", None), - ByteField("mess162", None), - ByteField("mess163", None), - ByteField("mess164", None), - ByteField("mess165", None), - ByteField("mess166", None), - ByteField("mess167", None), - ByteField("mess168", None), - ByteField("mess169", None), - ByteField("mess170", None), - ByteField("mess171", None), - ByteField("mess172", None), - ByteField("mess173", None), - ByteField("mess174", None), - ByteField("mess175", None), - ByteField("mess176", None), - ByteField("mess177", None), - ByteField("mess178", None), - ByteField("mess179", None), - ByteField("mess180", None), - ByteField("mess181", None), - ByteField("mess182", None), - ByteField("mess183", None), - ByteField("mess184", None), - ByteField("mess185", None), - ByteField("mess186", None), - ByteField("mess187", None), - ByteField("mess188", None), - ByteField("mess189", None), - ByteField("mess190", None), - ByteField("mess191", None), - ByteField("mess192", None), - ByteField("mess193", None), - ByteField("mess194", None), - ByteField("mess195", None), - ByteField("mess196", None), - ByteField("mess197", None), - ByteField("mess198", None), - ByteField("mess199", None), - ByteField("mess200", None), - ByteField("mess201", None), - ByteField("mess202", None), - ByteField("mess203", None), - ByteField("mess204", None), - ByteField("mess205", None), - ByteField("mess206", None), - ByteField("mess207", None), - ByteField("mess208", None), - ByteField("mess209", None), - ByteField("mess210", None), - ByteField("mess211", None), - ByteField("mess212", None), - ByteField("mess213", None), - ByteField("mess214", None), - ByteField("mess215", None), - ByteField("mess216", None), - ByteField("mess217", None), - ByteField("mess218", None), - ByteField("mess219", None), - ByteField("mess220", None), - ByteField("mess221", None), - ByteField("mess222", None), - ByteField("mess223", None), - ByteField("mess224", None), - ByteField("mess225", None), - ByteField("mess226", None), - ByteField("mess227", None), - ByteField("mess228", None), - ByteField("mess229", None), - ByteField("mess230", None), - ByteField("mess231", None), - ByteField("mess232", None), - ByteField("mess233", None), - ByteField("mess234", None), - ByteField("mess235", None), - ByteField("mess236", None), - ByteField("mess237", None), - ByteField("mess238", None), - ByteField("mess239", None), - ByteField("mess240", None), - ByteField("mess241", None), - ByteField("mess242", None), - ByteField("mess243", None), - ByteField("mess244", None), - ByteField("mess245", None), - ByteField("mess246", None), - ByteField("mess247", None), - ByteField("mess248", None), - ByteField("mess249", None), - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 250, a, self.fields_desc, 1) - if self.lengthSC is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class Signal(Packet): - """Signal Section 10.5.4.23""" - name = "Signal" - fields_desc = [ - ByteField("sigValue", 0x0) - ] - - -# length 2 to max for L3 message (251) -class SsVersionIndicator(Packet): - """SS Version Indicator Section 10.5.4.24""" - name = "SS Version Indicator" - fields_desc = [ - XByteField("lengthSVI", None), - # optional - ByteField("info1", None), - ByteField("info2", None), - ByteField("info3", None), - ByteField("info4", None), - ByteField("info5", None), - ByteField("info6", None), - ByteField("info7", None), - ByteField("info8", None), - ByteField("info9", None), - ByteField("info10", None), - ByteField("info11", None), - ByteField("info12", None), - ByteField("info13", None), - ByteField("info14", None), - ByteField("info15", None), - ByteField("info16", None), - ByteField("info17", None), - ByteField("info18", None), - ByteField("info19", None), - ByteField("info20", None), - ByteField("info21", None), - ByteField("info22", None), - ByteField("info23", None), - ByteField("info24", None), - ByteField("info25", None), - ByteField("info26", None), - ByteField("info27", None), - ByteField("info28", None), - ByteField("info29", None), - ByteField("info30", None), - ByteField("info31", None), - ByteField("info32", None), - ByteField("info33", None), - ByteField("info34", None), - ByteField("info35", None), - ByteField("info36", None), - ByteField("info37", None), - ByteField("info38", None), - ByteField("info39", None), - ByteField("info40", None), - ByteField("info41", None), - ByteField("info42", None), - ByteField("info43", None), - ByteField("info44", None), - ByteField("info45", None), - ByteField("info46", None), - ByteField("info47", None), - ByteField("info48", None), - ByteField("info49", None), - ByteField("info50", None), - ByteField("info51", None), - ByteField("info52", None), - ByteField("info53", None), - ByteField("info54", None), - ByteField("info55", None), - ByteField("info56", None), - ByteField("info57", None), - ByteField("info58", None), - ByteField("info59", None), - ByteField("info60", None), - ByteField("info61", None), - ByteField("info62", None), - ByteField("info63", None), - ByteField("info64", None), - ByteField("info65", None), - ByteField("info66", None), - ByteField("info67", None), - ByteField("info68", None), - ByteField("info69", None), - ByteField("info70", None), - ByteField("info71", None), - ByteField("info72", None), - ByteField("info73", None), - ByteField("info74", None), - ByteField("info75", None), - ByteField("info76", None), - ByteField("info77", None), - ByteField("info78", None), - ByteField("info79", None), - ByteField("info80", None), - ByteField("info81", None), - ByteField("info82", None), - ByteField("info83", None), - ByteField("info84", None), - ByteField("info85", None), - ByteField("info86", None), - ByteField("info87", None), - ByteField("info88", None), - ByteField("info89", None), - ByteField("info90", None), - ByteField("info91", None), - ByteField("info92", None), - ByteField("info93", None), - ByteField("info94", None), - ByteField("info95", None), - ByteField("info96", None), - ByteField("info97", None), - ByteField("info98", None), - ByteField("info99", None), - ByteField("info100", None), - ByteField("info101", None), - ByteField("info102", None), - ByteField("info103", None), - ByteField("info104", None), - ByteField("info105", None), - ByteField("info106", None), - ByteField("info107", None), - ByteField("info108", None), - ByteField("info109", None), - ByteField("info110", None), - ByteField("info111", None), - ByteField("info112", None), - ByteField("info113", None), - ByteField("info114", None), - ByteField("info115", None), - ByteField("info116", None), - ByteField("info117", None), - ByteField("info118", None), - ByteField("info119", None), - ByteField("info120", None), - ByteField("info121", None), - ByteField("info122", None), - ByteField("info123", None), - ByteField("info124", None), - ByteField("info125", None), - ByteField("info126", None), - ByteField("info127", None), - ByteField("info128", None), - ByteField("info129", None), - ByteField("info130", None), - ByteField("info131", None), - ByteField("info132", None), - ByteField("info133", None), - ByteField("info134", None), - ByteField("info135", None), - ByteField("info136", None), - ByteField("info137", None), - ByteField("info138", None), - ByteField("info139", None), - ByteField("info140", None), - ByteField("info141", None), - ByteField("info142", None), - ByteField("info143", None), - ByteField("info144", None), - ByteField("info145", None), - ByteField("info146", None), - ByteField("info147", None), - ByteField("info148", None), - ByteField("info149", None), - ByteField("info150", None), - ByteField("info151", None), - ByteField("info152", None), - ByteField("info153", None), - ByteField("info154", None), - ByteField("info155", None), - ByteField("info156", None), - ByteField("info157", None), - ByteField("info158", None), - ByteField("info159", None), - ByteField("info160", None), - ByteField("info161", None), - ByteField("info162", None), - ByteField("info163", None), - ByteField("info164", None), - ByteField("info165", None), - ByteField("info166", None), - ByteField("info167", None), - ByteField("info168", None), - ByteField("info169", None), - ByteField("info170", None), - ByteField("info171", None), - ByteField("info172", None), - ByteField("info173", None), - ByteField("info174", None), - ByteField("info175", None), - ByteField("info176", None), - ByteField("info177", None), - ByteField("info178", None), - ByteField("info179", None), - ByteField("info180", None), - ByteField("info181", None), - ByteField("info182", None), - ByteField("info183", None), - ByteField("info184", None), - ByteField("info185", None), - ByteField("info186", None), - ByteField("info187", None), - ByteField("info188", None), - ByteField("info189", None), - ByteField("info190", None), - ByteField("info191", None), - ByteField("info192", None), - ByteField("info193", None), - ByteField("info194", None), - ByteField("info195", None), - ByteField("info196", None), - ByteField("info197", None), - ByteField("info198", None), - ByteField("info199", None), - ByteField("info200", None), - ByteField("info201", None), - ByteField("info202", None), - ByteField("info203", None), - ByteField("info204", None), - ByteField("info205", None), - ByteField("info206", None), - ByteField("info207", None), - ByteField("info208", None), - ByteField("info209", None), - ByteField("info210", None), - ByteField("info211", None), - ByteField("info212", None), - ByteField("info213", None), - ByteField("info214", None), - ByteField("info215", None), - ByteField("info216", None), - ByteField("info217", None), - ByteField("info218", None), - ByteField("info219", None), - ByteField("info220", None), - ByteField("info221", None), - ByteField("info222", None), - ByteField("info223", None), - ByteField("info224", None), - ByteField("info225", None), - ByteField("info226", None), - ByteField("info227", None), - ByteField("info228", None), - ByteField("info229", None), - ByteField("info230", None), - ByteField("info231", None), - ByteField("info232", None), - ByteField("info233", None), - ByteField("info234", None), - ByteField("info235", None), - ByteField("info236", None), - ByteField("info237", None), - ByteField("info238", None), - ByteField("info239", None), - ByteField("info240", None), - ByteField("info241", None), - ByteField("info242", None), - ByteField("info243", None), - ByteField("info244", None), - ByteField("info245", None), - ByteField("info246", None), - ByteField("info247", None), - ByteField("info248", None), - ByteField("info249", None), - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(1, 250, a, self.fields_desc, 1) - if self.lengthSVI is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -# length 3 to 35 or 131 -class UserUser(Packet): - """User-user Section 10.5.4.25""" - name = "User-User" - fields_desc = [ - - XByteField("lengthUU", None), # dynamic length of field depending - # of the type of message - # let user decide which length he - # wants to take - # => more fuzzing options - ByteField("userUserPD", 0x0), - # optional - ByteField("userUserInfo1", None), - ByteField("userUserInfo2", None), - ByteField("userUserInfo3", None), - ByteField("userUserInfo4", None), - ByteField("userUserInfo5", None), - ByteField("userUserInfo6", None), - ByteField("userUserInfo7", None), - ByteField("userUserInfo8", None), - ByteField("userUserInfo9", None), - ByteField("userUserInfo10", None), - ByteField("userUserInfo11", None), - ByteField("userUserInfo12", None), - ByteField("userUserInfo13", None), - ByteField("userUserInfo14", None), - ByteField("userUserInfo15", None), - ByteField("userUserInfo16", None), - ByteField("userUserInfo17", None), - ByteField("userUserInfo18", None), - ByteField("userUserInfo19", None), - ByteField("userUserInfo20", None), - ByteField("userUserInfo21", None), - ByteField("userUserInfo22", None), - ByteField("userUserInfo23", None), - ByteField("userUserInfo24", None), - ByteField("userUserInfo25", None), - ByteField("userUserInfo26", None), - ByteField("userUserInfo27", None), - ByteField("userUserInfo28", None), - ByteField("userUserInfo29", None), - ByteField("userUserInfo30", None), - ByteField("userUserInfo31", None), - ByteField("userUserInfo32", None), - # long packet - ByteField("userUserInfo33", None), - ByteField("userUserInfo34", None), - ByteField("userUserInfo35", None), - ByteField("userUserInfo36", None), - ByteField("userUserInfo37", None), - ByteField("userUserInfo38", None), - ByteField("userUserInfo39", None), - ByteField("userUserInfo40", None), - ByteField("userUserInfo41", None), - ByteField("userUserInfo42", None), - ByteField("userUserInfo43", None), - ByteField("userUserInfo44", None), - ByteField("userUserInfo45", None), - ByteField("userUserInfo46", None), - ByteField("userUserInfo47", None), - ByteField("userUserInfo48", None), - ByteField("userUserInfo49", None), - ByteField("userUserInfo50", None), - ByteField("userUserInfo51", None), - ByteField("userUserInfo52", None), - ByteField("userUserInfo53", None), - ByteField("userUserInfo54", None), - ByteField("userUserInfo55", None), - ByteField("userUserInfo56", None), - ByteField("userUserInfo57", None), - ByteField("userUserInfo58", None), - ByteField("userUserInfo59", None), - ByteField("userUserInfo60", None), - ByteField("userUserInfo61", None), - ByteField("userUserInfo62", None), - ByteField("userUserInfo63", None), - ByteField("userUserInfo64", None), - ByteField("userUserInfo65", None), - ByteField("userUserInfo66", None), - ByteField("userUserInfo67", None), - ByteField("userUserInfo68", None), - ByteField("userUserInfo69", None), - ByteField("userUserInfo70", None), - ByteField("userUserInfo71", None), - ByteField("userUserInfo72", None), - ByteField("userUserInfo73", None), - ByteField("userUserInfo74", None), - ByteField("userUserInfo75", None), - ByteField("userUserInfo76", None), - ByteField("userUserInfo77", None), - ByteField("userUserInfo78", None), - ByteField("userUserInfo79", None), - ByteField("userUserInfo80", None), - ByteField("userUserInfo81", None), - ByteField("userUserInfo82", None), - ByteField("userUserInfo83", None), - ByteField("userUserInfo84", None), - ByteField("userUserInfo85", None), - ByteField("userUserInfo86", None), - ByteField("userUserInfo87", None), - ByteField("userUserInfo88", None), - ByteField("userUserInfo89", None), - ByteField("userUserInfo90", None), - ByteField("userUserInfo91", None), - ByteField("userUserInfo92", None), - ByteField("userUserInfo93", None), - ByteField("userUserInfo94", None), - ByteField("userUserInfo95", None), - ByteField("userUserInfo96", None), - ByteField("userUserInfo97", None), - ByteField("userUserInfo98", None), - ByteField("userUserInfo99", None), - ByteField("userUserInfo100", None), - ByteField("userUserInfo101", None), - ByteField("userUserInfo102", None), - ByteField("userUserInfo103", None), - ByteField("userUserInfo104", None), - ByteField("userUserInfo105", None), - ByteField("userUserInfo106", None), - ByteField("userUserInfo107", None), - ByteField("userUserInfo108", None), - ByteField("userUserInfo109", None), - ByteField("userUserInfo110", None), - ByteField("userUserInfo111", None), - ByteField("userUserInfo112", None), - ByteField("userUserInfo113", None), - ByteField("userUserInfo114", None), - ByteField("userUserInfo115", None), - ByteField("userUserInfo116", None), - ByteField("userUserInfo117", None), - ByteField("userUserInfo118", None), - ByteField("userUserInfo119", None), - ByteField("userUserInfo120", None), - ByteField("userUserInfo121", None), - ByteField("userUserInfo122", None), - ByteField("userUserInfo123", None), - ByteField("userUserInfo124", None), - ByteField("userUserInfo125", None), - ByteField("userUserInfo126", None), - ByteField("userUserInfo127", None), - ByteField("userUserInfo128", None), - ByteField("userUserInfo129", None), - ByteField("userUserInfo130", None), - ByteField("userUserInfo131", None) - ] - - def post_build(self, p, pay): - aList = [] - i = 0 - for i in range(0, len(self.fields_desc)): - aList.append(self.fields_desc[i].name) - a = [] - for i in aList: - a.append(getattr(self, i)) - res = adapt(2, 133, a, self.fields_desc, 1) - if self.lengthUU is None: - p = struct.pack(">B", res[1]) + p[1:] - if res[0] is not 0: - p = p[:-res[0]] - return p + pay - - -class AlertingPattern(Packet): - """Alerting Pattern 10.5.4.26""" - name = "Alerting Pattern" - fields_desc = [ - XByteField("lengthAP", 0x3), - BitField("spare", 0x0, 4), - BitField("alertingValue", 0x0, 4) - ] - - -class AllowedActions(Packet): - """Allowed actions $(CCBS)$ Section 10.5.4.26""" - name = "Allowed Actions $(CCBS)$" - fields_desc = [ - XByteField("lengthAP", 0x3), - BitField("CCBS", 0x0, 1), - BitField("spare", 0x0, 7) - ] - - -# -# 10.5.5 GPRS mobility management information elements -# - - -class AttachType(Packet): - """Attach type Section 10.5.5.2""" - name = "Attach Type" - fields_desc = [ - BitField("spare", 0x0, 1), - BitField("type", 0x1, 3) - ] - - -if __name__ == "__main__": - interact(mydict=globals(), mybanner="Scapy GSM-UM (Air) Addon") diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/gtp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/gtp.py deleted file mode 100644 index 008a0200..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/gtp.py +++ /dev/null @@ -1,546 +0,0 @@ -#! /usr/bin/env python - -## Copyright (C) 2014 Guillaume Valadon <guillaume.valadon@ssi.gouv.fr> -## 2014 Alexis Sultan <alexis.sultan@sfr.com> -## 2012 ffranz <ffranz@iniqua.com> -## -## This program is published under a GPLv2 license - -# scapy.contrib.description = GTP -# scapy.contrib.status = loads - -import time -import logging - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet import IP, UDP - -# GTP Data types - -GTPmessageType = { 1: "echo_request", - 2: "echo_response", - 16: "create_pdp_context_req", - 17: "create_pdp_context_res", - 20: "delete_pdp_context_req", - 21: "delete_pdp_context_res", - 26: "error_indication", - 27: "pdu_notification_req", - 255: "gtp_u_header" } - -IEType = { 1: "Cause", - 2: "IMSI", - 3: "RAI", - 4: "TLLI", - 5: "P_TMSI", - 14: "Recovery", - 15: "SelectionMode", - 16: "TEIDI", - 17: "TEICP", - 19: "TeardownInd", - 20: "NSAPI", - 26: "ChargingChrt", - 27: "TraceReference", - 28: "TraceType", - 128: "EndUserAddress", - 131: "AccessPointName", - 132: "ProtocolConfigurationOptions", - 133: "GSNAddress", - 134: "MSInternationalNumber", - 135: "QoS", - 148: "CommonFlags", - 151: "RatType", - 152: "UserLocationInformation", - 153: "MSTimeZone", - 154: "IMEI" } - -CauseValues = { 0: "Request IMSI", - 1: "Request IMEI", - 2: "Request IMSI and IMEI", - 3: "No identity needed", - 4: "MS Refuses", - 5: "MS is not GPRS Responding", - 128: "Request accepted", - 129: "New PDP type due to network preference", - 130: "New PDP type due to single address bearer only", - 192: "Non-existent", - 193: "Invalid message format", - 194: "IMSI not known", - 195: "MS is GPRS Detached", - 196: "MS is not GPRS Responding", - 197: "MS Refuses", - 198: "Version not supported", - 199: "No resources available", - 200: "Service not supported", - 201: "Mandatory IE incorrect", - 202: "Mandatory IE missing", - 203: "Optional IE incorrect", - 204: "System failure", - 205: "Roaming restriction", - 206: "P-TMSI Signature mismatch", - 207: "GPRS connection suspended", - 208: "Authentication failure", - 209: "User authentication failed", - 210: "Context not found", - 211: "All dynamic PDP addresses are occupied", - 212: "No memory is available", - 213: "Reallocation failure", - 214: "Unknown mandatory extension header", - 215: "Semantic error in the TFT operation", - 216: "Syntactic error in TFT operation", - 217: "Semantic errors in packet filter(s)", - 218: "Syntactic errors in packet filter(s)", - 219: "Missing or unknown APN", - 220: "Unknown PDP address or PDP type", - 221: "PDP context without TFT already activated", - 222: "APN access denied : no subscription", - 223: "APN Restriction type incompatibility with currently active PDP Contexts", - 224: "MS MBMS Capabilities Insufficient", - 225: "Invalid Correlation : ID", - 226: "MBMS Bearer Context Superseded", - 227: "Bearer Control Mode violation", - 228: "Collision with network initiated request" } - -Selection_Mode = { 11111100: "MS or APN", - 11111101: "MS", - 11111110: "NET", - 11111111: "FutureUse" } - -TeardownInd_value = { 254: "False", - 255: "True" } - -class TBCDByteField(StrFixedLenField): - - def i2h(self, pkt, val): - ret = [] - for i in range(len(val)): - byte = ord(val[i]) - left = byte >> 4 - right = byte & 0xF - if left == 0xF: - ret += [ "%d" % right ] - else: - ret += [ "%d" % right, "%d" % left ] - return "".join(ret) - - def i2repr(self, pkt, x): - return repr(self.i2h(pkt,x)) - - def i2m(self, pkt, val): - ret_string = "" - for i in range(0, len(val), 2): - tmp = val[i:i+2] - if len(tmp) == 2: - ret_string += chr(int(tmp[1] + tmp[0], 16)) - else: - ret_string += chr(int("F" + tmp[0], 16)) - return ret_string - -class GTPHeader(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Header" - fields_desc=[ BitField("version", 1, 3), - BitField("PT", 1, 1), - BitField("reserved", 0, 1), - BitField("E", 0, 1), - BitField("S", 1, 1), - BitField("PN", 0, 1), - ByteEnumField("gtp_type", None, GTPmessageType), - ShortField("length", None), - IntField("teid", 0) ] - - def post_build(self, p, pay): - p += pay - if self.length is None: - l = len(p)-8 - p = p[:2] + struct.pack("!H", l)+ p[4:] - return p - - def hashret(self): - return struct.pack("B", self.version) + self.payload.hashret() - - def answers(self, other): - return (isinstance(other, GTPHeader) and - self.version == other.version and - self.payload.answers(other.payload)) - -class GTPEchoRequest(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Echo Request" - fields_desc = [ XBitField("seq", 0, 16), - ByteField("npdu", 0), - ByteField("next_ex", 0),] - - def hashret(self): - return struct.pack("H", self.seq) - -class IE_Cause(Packet): - name = "Cause" - fields_desc = [ ByteEnumField("ietype", 1, IEType), - BitField("Response", None, 1), - BitField("Rejection", None, 1), - BitEnumField("CauseValue", None, 6, CauseValues) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_IMSI(Packet): - name = "IMSI - Subscriber identity of the MS" - fields_desc = [ ByteEnumField("ietype", 2, IEType), - TBCDByteField("imsi", str(RandNum(0, 999999999999999)), 8) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_Routing(Packet): - name = "Routing Area Identity" - fields_desc = [ ByteEnumField("ietype", 3, IEType), - TBCDByteField("MCC", "", 2), - # MNC: if the third digit of MCC is 0xf, then the length of MNC is 1 byte - TBCDByteField("MNC", "", 1), - ShortField("LAC", None), - ByteField("RAC", None) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_Recovery(Packet): - name = "Recovery" - fields_desc = [ ByteEnumField("ietype", 14, IEType), - ByteField("res-counter", 24) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_SelectionMode(Packet): - # Indicates the origin of the APN in the message - name = "Selection Mode" - fields_desc = [ ByteEnumField("ietype", 15, IEType), - BitEnumField("SelectionMode", "MS or APN", 8, Selection_Mode) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_TEIDI(Packet): - name = "Tunnel Endpoint Identifier Data" - fields_desc = [ ByteEnumField("ietype", 16, IEType), - XIntField("TEIDI", RandInt()) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_TEICP(Packet): - name = "Tunnel Endpoint Identifier Control Plane" - fields_desc = [ ByteEnumField("ietype", 17, IEType), - XIntField("TEICI", RandInt())] - def extract_padding(self, pkt): - return "",pkt - -class IE_Teardown(Packet): - name = "Teardown Indicator" - fields_desc = [ ByteEnumField("ietype", 19, IEType), - ByteEnumField("indicator", "True", TeardownInd_value) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_NSAPI(Packet): - # Identifies a PDP context in a mobility management context specified by TEICP - name = "NSAPI" - fields_desc = [ ByteEnumField("ietype", 20, IEType), - XBitField("sparebits", 0x0000, 4), - XBitField("NSAPI", RandNum(0, 15), 4) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_ChargingCharacteristics(Packet): - # Way of informing both the SGSN and GGSN of the rules for - name = "Charging Characteristics" - fields_desc = [ ByteEnumField("ietype", 26, IEType), - # producing charging information based on operator configured triggers. - # 0000 .... .... .... : spare - # .... 1... .... .... : normal charging - # .... .0.. .... .... : prepaid charging - # .... ..0. .... .... : flat rate charging - # .... ...0 .... .... : hot billing charging - # .... .... 0000 0000 : reserved - XBitField("Ch_ChSpare", None, 4), - XBitField("normal_charging", None, 1), - XBitField("prepaid_charging", None, 1), - XBitField("flat_rate_charging", None, 1), - XBitField("hot_billing_charging", None, 1), - XBitField("Ch_ChReserved", 0, 8) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_TraceReference(Packet): - # Identifies a record or a collection of records for a particular trace. - name = "Trace Reference" - fields_desc = [ ByteEnumField("ietype", 27, IEType), - XBitField("Trace_reference", None, 16) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_TraceType(Packet): - # Indicates the type of the trace - name = "Trace Type" - fields_desc = [ ByteEnumField("ietype", 28, IEType), - XBitField("Trace_type", None, 16) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_EndUserAddress(Packet): - # Supply protocol specific information of the external packet - name = "End User Addresss" - fields_desc = [ ByteEnumField("ietype", 128, IEType), - # data network accessed by the GGPRS subscribers. - # - Request - # 1 Type (1byte) - # 2-3 Length (2bytes) - value 2 - # 4 Spare + PDP Type Organization - # 5 PDP Type Number - # - Response - # 6-n PDP Address - BitField("EndUserAddressLength", 2, 16), - BitField("EndUserAddress", 1111, 4), - BitField("PDPTypeOrganization", 1, 4), - XByteField("PDPTypeNumber", None) ] - def extract_padding(self, pkt): - return "",pkt - -class APNStrLenField(StrLenField): - # Inspired by DNSStrField - def m2i(self, pkt, s): - ret_s = "" - tmp_s = s - while tmp_s: - tmp_len = struct.unpack("!B", tmp_s[0])[0] + 1 - if tmp_len > len(tmp_s): - warning("APN prematured end of character-string (size=%i, remaining bytes=%i)" % (tmp_len, len(tmp_s))) - ret_s += tmp_s[1:tmp_len] - tmp_s = tmp_s[tmp_len:] - if len(tmp_s) : - ret_s += "." - s = ret_s - return s - def i2m(self, pkt, s): - s = "".join(map(lambda x: chr(len(x))+x, s.split("."))) - return s - - -class IE_AccessPointName(Packet): - # Sent by SGSN or by GGSN as defined in 3GPP TS 23.060 - name = "Access Point Name" - fields_desc = [ ByteEnumField("ietype", 131, IEType), - ShortField("length", None), - APNStrLenField("APN", "nternet", length_from=lambda x: x.length) ] - def extract_padding(self, pkt): - return "",pkt - def post_build(self, p, pay): - if self.length is None: - l = len(p)-3 - p = p[:2] + struct.pack("!B", l)+ p[3:] - return p - -class IE_ProtocolConfigurationOptions(Packet): - name = "Protocol Configuration Options" - fields_desc = [ ByteEnumField("ietype", 132, IEType), - ShortField("length", 4), - StrLenField("Protocol Configuration", "", length_from=lambda x: x.length) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_GSNAddress(Packet): - name = "GSN Address" - fields_desc = [ ByteEnumField("ietype", 133, IEType), - ShortField("length", 4), - IPField("address", RandIP()) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_MSInternationalNumber(Packet): - name = "MS International Number" - fields_desc = [ ByteEnumField("ietype", 134, IEType), - ShortField("length", None), - FlagsField("flags", 0x91, 8, ["Extension","","","International Number","","","","ISDN numbering"]), - TBCDByteField("digits", "33607080910", length_from=lambda x: x.length-1) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_UserLocationInformation(Packet): - name = "User Location Information" - fields_desc = [ ByteEnumField("ietype", 152, IEType), - ShortField("length", None), - ByteField("type", 1), - # Only type 1 is currently supported - TBCDByteField("MCC", "", 2), - # MNC: if the third digit of MCC is 0xf, then the length of MNC is 1 byte - TBCDByteField("MNC", "", 1), - ShortField("LAC", None), - ShortField("SAC", None) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_IMEI(Packet): - name = "IMEI" - fields_desc = [ ByteEnumField("ietype", 154, IEType), - ShortField("length", None), - TBCDByteField("IMEI", "", length_from=lambda x: x.length) ] - def extract_padding(self, pkt): - return "",pkt - -class IE_NotImplementedTLV(Packet): - name = "IE not implemented" - fields_desc = [ ByteEnumField("ietype", 0, IEType), - ShortField("length", None), - StrLenField("data", "", length_from=lambda x: x.length) ] - def extract_padding(self, pkt): - return "",pkt - -ietypecls = { 1: IE_Cause, 2: IE_IMSI, 3: IE_Routing, 14: IE_Recovery, 15: IE_SelectionMode, 16: IE_TEIDI, - 17: IE_TEICP, 19: IE_Teardown, 20: IE_NSAPI, 26: IE_ChargingCharacteristics, - 27: IE_TraceReference, 28: IE_TraceType, - 128: IE_EndUserAddress, 131: IE_AccessPointName, 132: IE_ProtocolConfigurationOptions, - 133: IE_GSNAddress, 134: IE_MSInternationalNumber, 152: IE_UserLocationInformation, 154: IE_IMEI } - -def IE_Dispatcher(s): - """Choose the correct Information Element class.""" - - if len(s) < 1: - return Raw(s) - - # Get the IE type - ietype = ord(s[0]) - cls = ietypecls.get(ietype, Raw) - - # if ietype greater than 128 are TLVs - if cls == Raw and ietype & 128 == 128: - cls = IE_NotImplementedTLV - - return cls(s) - -class GTPEchoResponse(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Echo Response" - fields_desc = [ XBitField("seq", 0, 16), - ByteField("npdu", 0), - ByteField("next_ex", 0), - PacketListField("IE_list", [], IE_Dispatcher) ] - - def hashret(self): - return struct.pack("H", self.seq) - - def answers(self, other): - return self.seq == other.seq - - -class GTPCreatePDPContextRequest(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Create PDP Context Request" - fields_desc = [ ShortField("seq", RandShort()), - ByteField("npdu", 0), - ByteField("next_ex", 0), - PacketListField("IE_list", [ IE_TEIDI(), IE_NSAPI(), IE_GSNAddress(), - IE_GSNAddress(), - IE_NotImplementedTLV(ietype=135, length=15,data=RandString(15)) ], - IE_Dispatcher) ] - def hashret(self): - return struct.pack("H", self.seq) - -class GTPCreatePDPContextResponse(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Create PDP Context Response" - fields_desc = [ ShortField("seq", RandShort()), - ByteField("npdu", 0), - ByteField("next_ex", 0), - PacketListField("IE_list", [], IE_Dispatcher) ] - - def hashret(self): - return struct.pack("H", self.seq) - - def answers(self, other): - return self.seq == other.seq - -class GTPErrorIndication(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Error Indication" - fields_desc = [ XBitField("seq", 0, 16), - ByteField("npdu", 0), - ByteField("next_ex",0), - PacketListField("IE_list", [], IE_Dispatcher) ] - -class GTPDeletePDPContextRequest(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Delete PDP Context Request" - fields_desc = [ XBitField("seq", 0, 16), - ByteField("npdu", 0), - ByteField("next_ex", 0), - PacketListField("IE_list", [], IE_Dispatcher) ] - -class GTPDeletePDPContextResponse(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP Delete PDP Context Response" - fields_desc = [ XBitField("seq", 0, 16), - ByteField("npdu", 0), - ByteField("next_ex",0), - PacketListField("IE_list", [], IE_Dispatcher) ] - -class GTPPDUNotificationRequest(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP PDU Notification Request" - fields_desc = [ XBitField("seq", 0, 16), - ByteField("npdu", 0), - ByteField("next_ex", 0), - PacketListField("IE_list", [ IE_IMSI(), - IE_TEICP(TEICI=RandInt()), - IE_EndUserAddress(PDPTypeNumber=0x21), - IE_AccessPointName(), - IE_GSNAddress(address="127.0.0.1"), - ], IE_Dispatcher) ] - -class GTP_U_Header(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP-U Header" - # GTP-U protocol is used to transmit T-PDUs between GSN pairs (or between an SGSN and an RNC in UMTS), - # encapsulated in G-PDUs. A G-PDU is a packet including a GTP-U header and a T-PDU. The Path Protocol - # defines the path and the GTP-U header defines the tunnel. Several tunnels may be multiplexed on a single path. - fields_desc = [ BitField("version", 1,3), - BitField("PT", 1, 1), - BitField("Reserved", 0, 1), - BitField("E", 0,1), - BitField("S", 0, 1), - BitField("PN", 0, 1), - ByteEnumField("gtp_type", None, GTPmessageType), - BitField("length", None, 16), - XBitField("TEID", 0, 32), - ConditionalField(XBitField("seq", 0, 16), lambda pkt:pkt.E==1 or pkt.S==1 or pkt.PN==1), - ConditionalField(ByteField("npdu", 0), lambda pkt:pkt.E==1 or pkt.S==1 or pkt.PN==1), - ConditionalField(ByteField("next_ex", 0), lambda pkt:pkt.E==1 or pkt.S==1 or pkt.PN==1), - ] - - def post_build(self, p, pay): - p += pay - if self.length is None: - l = len(p)-8 - p = p[:2] + struct.pack("!H", l)+ p[4:] - return p - -class GTPmorethan1500(Packet): - # 3GPP TS 29.060 V9.1.0 (2009-12) - name = "GTP More than 1500" - fields_desc = [ ByteEnumField("IE_Cause", "Cause", IEType), - BitField("IE", 1, 12000),] - -# Bind GTP-C -bind_layers(UDP, GTPHeader, dport = 2123) -bind_layers(UDP, GTPHeader, sport = 2123) -bind_layers(GTPHeader, GTPEchoRequest, gtp_type = 1) -bind_layers(GTPHeader, GTPEchoResponse, gtp_type = 2) -bind_layers(GTPHeader, GTPCreatePDPContextRequest, gtp_type = 16) -bind_layers(GTPHeader, GTPCreatePDPContextResponse, gtp_type = 17) -bind_layers(GTPHeader, GTPDeletePDPContextRequest, gtp_type = 20) -bind_layers(GTPHeader, GTPDeletePDPContextResponse, gtp_type = 21) -bind_layers(GTPHeader, GTPPDUNotificationRequest, gtp_type = 27) - -# Bind GTP-U -bind_layers(UDP, GTP_U_Header, dport = 2152) -bind_layers(UDP, GTP_U_Header, sport = 2152) -bind_layers(GTP_U_Header, IP, gtp_type = 255) - -if __name__ == "__main__": - from scapy.all import * - interact(mydict=globals(), mybanner="GTPv1 add-on") - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/igmp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/igmp.py deleted file mode 100644 index b3505810..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/igmp.py +++ /dev/null @@ -1,171 +0,0 @@ -#! /usr/bin/env python - -# scapy.contrib.description = IGMP/IGMPv2 -# scapy.contrib.status = loads - - -# TODO: scapy 2 has function getmacbyip, maybe it can replace igmpize -# at least from the MAC layer - -from scapy.all import * - -#-------------------------------------------------------------------------- -def isValidMCAddr(ip): - """convert dotted quad string to long and check the first octet""" - FirstOct=atol(ip)>>24 & 0xFF - return (FirstOct >= 224) and (FirstOct <= 239) - -#-------------------------------------------------------------------------- - -class IGMP(Packet): - """IGMP Message Class for v1 and v2. - -This class is derived from class Packet. You need to "igmpize" -the IP and Ethernet layers before a full packet is sent. -a=Ether(src="00:01:02:03:04:05") -b=IP(src="1.2.3.4") -c=IGMP(type=0x12, gaddr="224.2.3.4") -c.igmpize(b, a) -print("Joining IP " + c.gaddr + " MAC " + a.dst) -sendp(a/b/c, iface="en0") - - Parameters: - type IGMP type field, 0x11, 0x12, 0x16 or 0x17 - mrtime Maximum Response time (zero for v1) - gaddr Multicast Group Address 224.x.x.x/4 - -See RFC2236, Section 2. Introduction for definitions of proper -IGMPv2 message format http://www.faqs.org/rfcs/rfc2236.html - - """ - name = "IGMP" - - igmptypes = { 0x11 : "Group Membership Query", - 0x12 : "Version 1 - Membership Report", - 0x16 : "Version 2 - Membership Report", - 0x17 : "Leave Group"} - - fields_desc = [ ByteEnumField("type", 0x11, igmptypes), - ByteField("mrtime",20), - XShortField("chksum", None), - IPField("gaddr", "0.0.0.0")] - -#-------------------------------------------------------------------------- - def post_build(self, p, pay): - """Called implicitly before a packet is sent to compute and place IGMP checksum. - - Parameters: - self The instantiation of an IGMP class - p The IGMP message in hex in network byte order - pay Additional payload for the IGMP message - """ - p += pay - if self.chksum is None: - ck = checksum(p) - p = p[:2]+chr(ck>>8)+chr(ck&0xff)+p[4:] - return p - -#-------------------------------------------------------------------------- - def mysummary(self): - """Display a summary of the IGMP object.""" - - if isinstance(self.underlayer, IP): - return self.underlayer.sprintf("IGMP: %IP.src% > %IP.dst% %IGMP.type% %IGMP.gaddr%") - else: - return self.sprintf("IGMP %IGMP.type% %IGMP.gaddr%") - -#-------------------------------------------------------------------------- - def igmpize(self, ip=None, ether=None): - """Called to explicitely fixup associated IP and Ethernet headers - - Parameters: - self The instantiation of an IGMP class. - ip The instantiation of the associated IP class. - ether The instantiation of the associated Ethernet. - - Returns: - True The tuple ether/ip/self passed all check and represents - a proper IGMP packet. - False One of more validation checks failed and no fields - were adjusted. - - The function will examine the IGMP message to assure proper format. - Corrections will be attempted if possible. The IP header is then properly - adjusted to ensure correct formatting and assignment. The Ethernet header - is then adjusted to the proper IGMP packet format. - """ - -# The rules are: -# 1. the Max Response time is meaningful only in Membership Queries and should be zero -# otherwise (RFC 2236, section 2.2) - - if (self.type != 0x11): #rule 1 - self.mrtime = 0 - - if (self.adjust_ip(ip) == True): - if (self.adjust_ether(ip, ether) == True): return True - return False - -#-------------------------------------------------------------------------- - def adjust_ether (self, ip=None, ether=None): - """Called to explicitely fixup an associated Ethernet header - - The function adjusts the ethernet header destination MAC address based on - the destination IP address. - """ -# The rules are: -# 1. send to the group mac address address corresponding to the IP.dst - if ip != None and ip.haslayer(IP) and ether != None and ether.haslayer(Ether): - iplong = atol(ip.dst) - ether.dst = "01:00:5e:%02x:%02x:%02x" % ( (iplong>>16)&0x7F, (iplong>>8)&0xFF, (iplong)&0xFF ) - # print "igmpize ip " + ip.dst + " as mac " + ether.dst - return True - else: - return False - -#-------------------------------------------------------------------------- - def adjust_ip (self, ip=None): - """Called to explicitely fixup an associated IP header - - The function adjusts the IP header based on conformance rules - and the group address encoded in the IGMP message. - The rules are: - 1. Send General Group Query to 224.0.0.1 (all systems) - 2. Send Leave Group to 224.0.0.2 (all routers) - 3a.Otherwise send the packet to the group address - 3b.Send reports/joins to the group address - 4. ttl = 1 (RFC 2236, section 2) - 5. send the packet with the router alert IP option (RFC 2236, section 2) - """ - if ip != None and ip.haslayer(IP): - if (self.type == 0x11): - if (self.gaddr == "0.0.0.0"): - ip.dst = "224.0.0.1" # IP rule 1 - retCode = True - elif isValidMCAddr(self.gaddr): - ip.dst = self.gaddr # IP rule 3a - retCode = True - else: - print("Warning: Using invalid Group Address") - retCode = False - elif ((self.type == 0x17) and isValidMCAddr(self.gaddr)): - ip.dst = "224.0.0.2" # IP rule 2 - retCode = True - elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(self.gaddr)): - ip.dst = self.gaddr # IP rule 3b - retCode = True - else: - print("Warning: Using invalid IGMP Type") - retCode = False - else: - print("Warning: No IGMP Group Address set") - retCode = False - if retCode == True: - ip.ttl=1 # IP Rule 4 - ip.options=[IPOption_Router_Alert()] # IP rule 5 - return retCode - - -bind_layers( IP, IGMP, frag=0, proto=2) - - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/igmpv3.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/igmpv3.py deleted file mode 100644 index 8322c7a3..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/igmpv3.py +++ /dev/null @@ -1,270 +0,0 @@ -#! /usr/bin/env python - -# http://trac.secdev.org/scapy/ticket/31 - -# scapy.contrib.description = IGMPv3 -# scapy.contrib.status = loads - -from scapy.packet import * - -""" Based on the following references - http://www.iana.org/assignments/igmp-type-numbers - http://www.rfc-editor.org/rfc/pdfrfc/rfc3376.txt.pdf - -""" - -# TODO: Merge IGMPv3 packet Bindlayers correct for -# membership source/Group records -# ConditionalField parameters for IGMPv3 commented out -# -# See RFC3376, Section 4. Message Formats for definitions of proper IGMPv3 message format -# http://www.faqs.org/rfcs/rfc3376.html -# -# See RFC4286, For definitions of proper messages for Multicast Router Discovery. -# http://www.faqs.org/rfcs/rfc4286.html -# - -#import sys, socket, struct, time -from scapy.all import * -print("IGMPv3 is still under development - Nov 2010") - - -class IGMPv3gr(Packet): - """IGMP Group Record for IGMPv3 Membership Report - - This class is derived from class Packet and should be concatenated to an - instantiation of class IGMPv3. Within the IGMPv3 instantiation, the numgrp - element will need to be manipulated to indicate the proper number of - group records. - """ - name = "IGMPv3gr" - igmpv3grtypes = { 1 : "Mode Is Include", - 2 : "Mode Is Exclude", - 3 : "Change To Include Mode", - 4 : "Change To Exclude Mode", - 5 : "Allow New Sources", - 6 : "Block Old Sources"} - - fields_desc = [ ByteEnumField("rtype", 1, igmpv3grtypes), - ByteField("auxdlen",0), - FieldLenField("numsrc", None, "srcaddrs"), - IPField("maddr", "0.0.0.0"), - FieldListField("srcaddrs", None, IPField("sa", "0.0.0.0"), "numsrc") ] - #show_indent=0 -#-------------------------------------------------------------------------- - def post_build(self, p, pay): - """Called implicitly before a packet is sent. - """ - p += pay - if self.auxdlen != 0: - print("NOTICE: A properly formatted and complaint V3 Group Record should have an Auxiliary Data length of zero (0).") - print(" Subsequent Group Records are lost!") - return p -#-------------------------------------------------------------------------- - def mysummary(self): - """Display a summary of the IGMPv3 group record.""" - return self.sprintf("IGMPv3 Group Record %IGMPv3gr.type% %IGMPv3gr.maddr%") - - -class IGMPv3(Packet): - """IGMP Message Class for v3. - - This class is derived from class Packet. - The fields defined below are a - direct interpretation of the v3 Membership Query Message. - Fields 'type' through 'qqic' are directly assignable. - For 'numsrc', do not assign a value. - Instead add to the 'srcaddrs' list to auto-set 'numsrc'. To - assign values to 'srcaddrs', use the following methods: - c = IGMPv3() - c.srcaddrs = ['1.2.3.4', '5.6.7.8'] - c.srcaddrs += ['192.168.10.24'] - At this point, 'c.numsrc' is three (3) - - 'chksum' is automagically calculated before the packet is sent. - - 'mrcode' is also the Advertisement Interval field - - """ - name = "IGMPv3" - igmpv3types = { 0x11 : "Membership Query", - 0x22 : "Version 3 Membership Report", - 0x30 : "Multicast Router Advertisement", - 0x31 : "Multicast Router Solicitation", - 0x32 : "Multicast Router Termination"} - - fields_desc = [ ByteEnumField("type", 0x11, igmpv3types), - ByteField("mrcode",0), - XShortField("chksum", None), - IPField("gaddr", "0.0.0.0") - ] - # use float_encode() - - # if type = 0x11 (Membership Query), the next field is group address - # ConditionalField(IPField("gaddr", "0.0.0.0"), "type", lambda x:x==0x11), - # else if type = 0x22 (Membership Report), the next fields are - # reserved and number of group records - #ConditionalField(ShortField("rsvd2", 0), "type", lambda x:x==0x22), - #ConditionalField(ShortField("numgrp", 0), "type", lambda x:x==0x22), -# FieldLenField("numgrp", None, "grprecs")] - # else if type = 0x30 (Multicast Router Advertisement), the next fields are - # query interval and robustness - #ConditionalField(ShortField("qryIntvl", 0), "type", lambda x:x==0x30), - #ConditionalField(ShortField("robust", 0), "type", lambda x:x==0x30), -# The following are only present for membership queries - # ConditionalField(BitField("resv", 0, 4), "type", lambda x:x==0x11), - # ConditionalField(BitField("s", 0, 1), "type", lambda x:x==0x11), - # ConditionalField(BitField("qrv", 0, 3), "type", lambda x:x==0x11), - # ConditionalField(ByteField("qqic",0), "type", lambda x:x==0x11), - # ConditionalField(FieldLenField("numsrc", None, "srcaddrs"), "type", lambda x:x==0x11), - # ConditionalField(FieldListField("srcaddrs", None, IPField("sa", "0.0.0.0"), "numsrc"), "type", lambda x:x==0x11), - -#-------------------------------------------------------------------------- - def float_encode(self, value): - """Convert the integer value to its IGMPv3 encoded time value if needed. - - If value < 128, return the value specified. If >= 128, encode as a floating - point value. Value can be 0 - 31744. - """ - if value < 128: - code = value - elif value > 31743: - code = 255 - else: - exp=0 - value>>=3 - while(value>31): - exp+=1 - value>>=1 - exp<<=4 - code = 0x80 | exp | (value & 0x0F) - return code - -#-------------------------------------------------------------------------- - def post_build(self, p, pay): - """Called implicitly before a packet is sent to compute and place IGMPv3 checksum. - - Parameters: - self The instantiation of an IGMPv3 class - p The IGMPv3 message in hex in network byte order - pay Additional payload for the IGMPv3 message - """ - p += pay - if self.type in [0, 0x31, 0x32, 0x22]: # for these, field is reserved (0) - p = p[:1]+chr(0)+p[2:] - if self.chksum is None: - ck = checksum(p) - p = p[:2]+chr(ck>>8)+chr(ck&0xff)+p[4:] - return p - -#-------------------------------------------------------------------------- - def mysummary(self): - """Display a summary of the IGMPv3 object.""" - - if isinstance(self.underlayer, IP): - return self.underlayer.sprintf("IGMPv3: %IP.src% > %IP.dst% %IGMPv3.type% %IGMPv3.gaddr%") - else: - return self.sprintf("IGMPv3 %IGMPv3.type% %IGMPv3.gaddr%") - -#-------------------------------------------------------------------------- - def igmpize(self, ip=None, ether=None): - """Called to explicitely fixup associated IP and Ethernet headers - - Parameters: - self The instantiation of an IGMP class. - ip The instantiation of the associated IP class. - ether The instantiation of the associated Ethernet. - - Returns: - True The tuple ether/ip/self passed all check and represents - a proper IGMP packet. - False One of more validation checks failed and no fields - were adjusted. - - The function will examine the IGMP message to assure proper format. - Corrections will be attempted if possible. The IP header is then properly - adjusted to ensure correct formatting and assignment. The Ethernet header - is then adjusted to the proper IGMP packet format. - """ - -# The rules are: -# 1. ttl = 1 (RFC 2236, section 2) -# igmp_binds = [ (IP, IGMP, { "proto": 2 , "ttl": 1 }), -# 2. tos = 0xC0 (RFC 3376, section 4) -# (IP, IGMPv3, { "proto": 2 , "ttl": 1, "tos":0xc0 }), -# (IGMPv3, IGMPv3gr, { }) ] -# The rules are: -# 1. the Max Response time is meaningful only in Membership Queries and should be zero -# otherwise (RFC 2236, section 2.2) - - if (self.type != 0x11): #rule 1 - self.mrtime = 0 - - if (self.adjust_ip(ip) == True): - if (self.adjust_ether(ip, ether) == True): return True - return False - -#-------------------------------------------------------------------------- - def adjust_ether (self, ip=None, ether=None): - """Called to explicitely fixup an associated Ethernet header - - The function adjusts the ethernet header destination MAC address based on - the destination IP address. - """ -# The rules are: -# 1. send to the group mac address address corresponding to the IP.dst - if ip != None and ip.haslayer(IP) and ether != None and ether.haslayer(Ether): - iplong = atol(ip.dst) - ether.dst = "01:00:5e:%02x:%02x:%02x" % ( (iplong>>16)&0x7F, (iplong>>8)&0xFF, (iplong)&0xFF ) - # print "igmpize ip " + ip.dst + " as mac " + ether.dst - return True - else: - return False - -#-------------------------------------------------------------------------- - def adjust_ip (self, ip=None): - """Called to explicitely fixup an associated IP header - - The function adjusts the IP header based on conformance rules - and the group address encoded in the IGMP message. - The rules are: - 1. Send General Group Query to 224.0.0.1 (all systems) - 2. Send Leave Group to 224.0.0.2 (all routers) - 3a.Otherwise send the packet to the group address - 3b.Send reports/joins to the group address - 4. ttl = 1 (RFC 2236, section 2) - 5. send the packet with the router alert IP option (RFC 2236, section 2) - """ - if ip != None and ip.haslayer(IP): - if (self.type == 0x11): - if (self.gaddr == "0.0.0.0"): - ip.dst = "224.0.0.1" # IP rule 1 - retCode = True - elif isValidMCAddr(self.gaddr): - ip.dst = self.gaddr # IP rule 3a - retCode = True - else: - print("Warning: Using invalid Group Address") - retCode = False - elif ((self.type == 0x17) and isValidMCAddr(self.gaddr)): - ip.dst = "224.0.0.2" # IP rule 2 - retCode = True - elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(self.gaddr)): - ip.dst = self.gaddr # IP rule 3b - retCode = True - else: - print("Warning: Using invalid IGMP Type") - retCode = False - else: - print("Warning: No IGMP Group Address set") - retCode = False - if retCode == True: - ip.ttl=1 # IP Rule 4 - ip.options=[IPOption_Router_Alert()] # IP rule 5 - return retCode - - -bind_layers( IP, IGMPv3, frag=0, proto=2, ttl=1, tos=0xc0) -bind_layers( IGMPv3, IGMPv3gr, frag=0, proto=2) -bind_layers( IGMPv3gr, IGMPv3gr, frag=0, proto=2) - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ikev2.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ikev2.py deleted file mode 100644 index fd38b80c..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ikev2.py +++ /dev/null @@ -1,362 +0,0 @@ -#!/usr/bin/env python - -# http://trac.secdev.org/scapy/ticket/353 - -# scapy.contrib.description = IKEv2 -# scapy.contrib.status = loads - -from scapy.all import * -import logging - - -## Modified from the original ISAKMP code by Yaron Sheffer <yaronf.ietf@gmail.com>, June 2010. - -import struct -from scapy.packet import * -from scapy.fields import * -from scapy.ansmachine import * -from scapy.layers.inet import IP,UDP -from scapy.sendrecv import sr - -# see http://www.iana.org/assignments/ikev2-parameters for details -IKEv2AttributeTypes= { "Encryption": (1, { "DES-IV64" : 1, - "DES" : 2, - "3DES" : 3, - "RC5" : 4, - "IDEA" : 5, - "CAST" : 6, - "Blowfish" : 7, - "3IDEA" : 8, - "DES-IV32" : 9, - "AES-CBC" : 12, - "AES-CTR" : 13, - "AES-CCM-8" : 14, - "AES-CCM-12" : 15, - "AES-CCM-16" : 16, - "AES-GCM-8ICV" : 18, - "AES-GCM-12ICV" : 19, - "AES-GCM-16ICV" : 20, - "Camellia-CBC" : 23, - "Camellia-CTR" : 24, - "Camellia-CCM-8ICV" : 25, - "Camellia-CCM-12ICV" : 26, - "Camellia-CCM-16ICV" : 27, - }, 0), - "PRF": (2, {"PRF_HMAC_MD5":1, - "PRF_HMAC_SHA1":2, - "PRF_HMAC_TIGER":3, - "PRF_AES128_XCBC":4, - "PRF_HMAC_SHA2_256":5, - "PRF_HMAC_SHA2_384":6, - "PRF_HMAC_SHA2_512":7, - "PRF_AES128_CMAC":8, - }, 0), - "Integrity": (3, { "HMAC-MD5-96": 1, - "HMAC-SHA1-96": 2, - "DES-MAC": 3, - "KPDK-MD5": 4, - "AES-XCBC-96": 5, - "HMAC-MD5-128": 6, - "HMAC-SHA1-160": 7, - "AES-CMAC-96": 8, - "AES-128-GMAC": 9, - "AES-192-GMAC": 10, - "AES-256-GMAC": 11, - "SHA2-256-128": 12, - "SHA2-384-192": 13, - "SHA2-512-256": 14, - }, 0), - "GroupDesc": (4, { "768MODPgr" : 1, - "1024MODPgr" : 2, - "1536MODPgr" : 5, - "2048MODPgr" : 14, - "3072MODPgr" : 15, - "4096MODPgr" : 16, - "6144MODPgr" : 17, - "8192MODPgr" : 18, - "256randECPgr" : 19, - "384randECPgr" : 20, - "521randECPgr" : 21, - "1024MODP160POSgr" : 22, - "2048MODP224POSgr" : 23, - "2048MODP256POSgr" : 24, - "192randECPgr" : 25, - "224randECPgr" : 26, - }, 0), - "Extended Sequence Number": (5, {"No ESN": 0, - "ESN": 1, }, 0), - } - -# the name 'IKEv2TransformTypes' is actually a misnomer (since the table -# holds info for all IKEv2 Attribute types, not just transforms, but we'll -# keep it for backwards compatibility... for now at least -IKEv2TransformTypes = IKEv2AttributeTypes - -IKEv2TransformNum = {} -for n in IKEv2TransformTypes: - val = IKEv2TransformTypes[n] - tmp = {} - for e in val[1]: - tmp[val[1][e]] = e - IKEv2TransformNum[val[0]] = (n,tmp, val[2]) - -IKEv2Transforms = {} -for n in IKEv2TransformTypes: - IKEv2Transforms[IKEv2TransformTypes[n][0]]=n - -del(n) -del(e) -del(tmp) -del(val) - -# Note: Transform and Proposal can only be used inside the SA payload -IKEv2_payload_type = ["None", "", "Proposal", "Transform"] - -IKEv2_payload_type.extend([""] * 29) -IKEv2_payload_type.extend(["SA","KE","IDi","IDr", "CERT","CERTREQ","AUTH","Nonce","Notify","Delete", - "VendorID","TSi","TSr","Encrypted","CP","EAP"]) - -IKEv2_exchange_type = [""] * 34 -IKEv2_exchange_type.extend(["IKE_SA_INIT","IKE_AUTH","CREATE_CHILD_SA", - "INFORMATIONAL", "IKE_SESSION_RESUME"]) - - -class IKEv2_class(Packet): - def guess_payload_class(self, payload): - np = self.next_payload - logging.debug("For IKEv2_class np=%d" % np) - if np == 0: - return conf.raw_layer - elif np < len(IKEv2_payload_type): - pt = IKEv2_payload_type[np] - logging.debug(globals().get("IKEv2_payload_%s" % pt, IKEv2_payload)) - return globals().get("IKEv2_payload_%s" % pt, IKEv2_payload) - else: - return IKEv2_payload - - -class IKEv2(IKEv2_class): # rfc4306 - name = "IKEv2" - fields_desc = [ - StrFixedLenField("init_SPI","",8), - StrFixedLenField("resp_SPI","",8), - ByteEnumField("next_payload",0,IKEv2_payload_type), - XByteField("version",0x20), # IKEv2, right? - ByteEnumField("exch_type",0,IKEv2_exchange_type), - FlagsField("flags",0, 8, ["res0","res1","res2","Initiator","Version","Response","res6","res7"]), - IntField("id",0), - IntField("length",None) - ] - - def guess_payload_class(self, payload): - if self.flags & 1: - return conf.raw_layer - return IKEv2_class.guess_payload_class(self, payload) - - def answers(self, other): - if isinstance(other, IKEv2): - if other.init_SPI == self.init_SPI: - return 1 - return 0 - def post_build(self, p, pay): - p += pay - if self.length is None: - p = p[:24]+struct.pack("!I",len(p))+p[28:] - return p - - -class IKEv2_Key_Length_Attribute(IntField): - # We only support the fixed-length Key Length attribute (the only one currently defined) - name="key length" - def __init__(self, name): - IntField.__init__(self, name, "0x800E0000") - - def i2h(self, pkt, x): - return IntField.i2h(self, pkt, x & 0xFFFF) - - def h2i(self, pkt, x): - return IntField.h2i(self, pkt, struct.pack("!I", 0x800E0000 | int(x, 0))) - - -class IKEv2_Transform_ID(ShortField): - def i2h(self, pkt, x): - if pkt == None: - return None - else: - map = IKEv2TransformNum[pkt.transform_type][1] - return map[x] - - def h2i(self, pkt, x): - if pkt == None: - return None - else: - map = IKEv2TransformNum[pkt.transform_type][1] - for k in keys(map): - if map[k] == x: - return k - return None - -class IKEv2_payload_Transform(IKEv2_class): - name = "IKE Transform" - fields_desc = [ - ByteEnumField("next_payload",None,{0:"last", 3:"Transform"}), - ByteField("res",0), - ShortField("length",8), - ByteEnumField("transform_type",None,IKEv2Transforms), - ByteField("res2",0), - IKEv2_Transform_ID("transform_id", 0), - ConditionalField(IKEv2_Key_Length_Attribute("key_length"), lambda pkt: pkt.length > 8), - ] - -class IKEv2_payload_Proposal(IKEv2_class): - name = "IKEv2 Proposal" - fields_desc = [ - ByteEnumField("next_payload",None,{0:"last", 2:"Proposal"}), - ByteField("res",0), - FieldLenField("length",None,"trans","H", adjust=lambda pkt,x:x+8), - ByteField("proposal",1), - ByteEnumField("proto",1,{1:"IKEv2"}), - FieldLenField("SPIsize",None,"SPI","B"), - ByteField("trans_nb",None), - StrLenField("SPI","",length_from=lambda x:x.SPIsize), - PacketLenField("trans",conf.raw_layer(),IKEv2_payload_Transform,length_from=lambda x:x.length-8), - ] - - -class IKEv2_payload(IKEv2_class): - name = "IKEv2 Payload" - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - FlagsField("flags",0, 8, ["critical","res1","res2","res3","res4","res5","res6","res7"]), - FieldLenField("length",None,"load","H", adjust=lambda pkt,x:x+4), - StrLenField("load","",length_from=lambda x:x.length-4), - ] - - -class IKEv2_payload_VendorID(IKEv2_class): - name = "IKEv2 Vendor ID" - overload_fields = { IKEv2: { "next_payload":43 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"vendorID","H", adjust=lambda pkt,x:x+4), - StrLenField("vendorID","",length_from=lambda x:x.length-4), - ] - -class IKEv2_payload_Delete(IKEv2_class): - name = "IKEv2 Vendor ID" - overload_fields = { IKEv2: { "next_payload":42 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"vendorID","H", adjust=lambda pkt,x:x+4), - StrLenField("vendorID","",length_from=lambda x:x.length-4), - ] - -class IKEv2_payload_SA(IKEv2_class): - name = "IKEv2 SA" - overload_fields = { IKEv2: { "next_payload":33 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"prop","H", adjust=lambda pkt,x:x+4), - PacketLenField("prop",conf.raw_layer(),IKEv2_payload_Proposal,length_from=lambda x:x.length-4), - ] - -class IKEv2_payload_Nonce(IKEv2_class): - name = "IKEv2 Nonce" - overload_fields = { IKEv2: { "next_payload":40 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"load","H", adjust=lambda pkt,x:x+4), - StrLenField("load","",length_from=lambda x:x.length-4), - ] - -class IKEv2_payload_Notify(IKEv2_class): - name = "IKEv2 Notify" - overload_fields = { IKEv2: { "next_payload":41 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"load","H", adjust=lambda pkt,x:x+4), - StrLenField("load","",length_from=lambda x:x.length-4), - ] - -class IKEv2_payload_KE(IKEv2_class): - name = "IKEv2 Key Exchange" - overload_fields = { IKEv2: { "next_payload":34 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"load","H", adjust=lambda pkt,x:x+6), - ShortEnumField("group", 0, IKEv2TransformTypes['GroupDesc'][1]), - StrLenField("load","",length_from=lambda x:x.length-6), - ] - -class IKEv2_payload_IDi(IKEv2_class): - name = "IKEv2 Identification - Initiator" - overload_fields = { IKEv2: { "next_payload":35 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"load","H",adjust=lambda pkt,x:x+8), - ByteEnumField("IDtype",1,{1:"IPv4_addr", 11:"Key"}), - ByteEnumField("ProtoID",0,{0:"Unused"}), - ShortEnumField("Port",0,{0:"Unused"}), -# IPField("IdentData","127.0.0.1"), - StrLenField("load","",length_from=lambda x:x.length-8), - ] - -class IKEv2_payload_IDr(IKEv2_class): - name = "IKEv2 Identification - Responder" - overload_fields = { IKEv2: { "next_payload":36 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"load","H",adjust=lambda pkt,x:x+8), - ByteEnumField("IDtype",1,{1:"IPv4_addr", 11:"Key"}), - ByteEnumField("ProtoID",0,{0:"Unused"}), - ShortEnumField("Port",0,{0:"Unused"}), -# IPField("IdentData","127.0.0.1"), - StrLenField("load","",length_from=lambda x:x.length-8), - ] - - - -class IKEv2_payload_Encrypted(IKEv2_class): - name = "IKEv2 Encrypted and Authenticated" - overload_fields = { IKEv2: { "next_payload":46 }} - fields_desc = [ - ByteEnumField("next_payload",None,IKEv2_payload_type), - ByteField("res",0), - FieldLenField("length",None,"load","H",adjust=lambda pkt,x:x+4), - StrLenField("load","",length_from=lambda x:x.length-4), - ] - - - -IKEv2_payload_type_overload = {} -for i in range(len(IKEv2_payload_type)): - name = "IKEv2_payload_%s" % IKEv2_payload_type[i] - if name in globals(): - IKEv2_payload_type_overload[globals()[name]] = {"next_payload":i} - -del(i) -del(name) -IKEv2_class.overload_fields = IKEv2_payload_type_overload.copy() - -split_layers(UDP, ISAKMP, sport=500) -split_layers(UDP, ISAKMP, dport=500) - -bind_layers( UDP, IKEv2, dport=500, sport=500) # TODO: distinguish IKEv1/IKEv2 -bind_layers( UDP, IKEv2, dport=4500, sport=4500) - -def ikev2scan(ip): - return sr(IP(dst=ip)/UDP()/IKEv2(init_SPI=RandString(8), - exch_type=34)/IKEv2_payload_SA(prop=IKEv2_payload_Proposal())) - -# conf.debug_dissector = 1 - -if __name__ == "__main__": - interact(mydict=globals(), mybanner="IKEv2 alpha-level protocol implementation") diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ldp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ldp.py deleted file mode 100644 index bc2464ab..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ldp.py +++ /dev/null @@ -1,475 +0,0 @@ -# scapy.contrib.description = Label Distribution Protocol (LDP) -# scapy.contrib.status = loads - -# http://git.savannah.gnu.org/cgit/ldpscapy.git/snapshot/ldpscapy-5285b81d6e628043df2a83301b292f24a95f0ba1.tar.gz - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -# Copyright (C) 2010 Florian Duraffourg - -import struct - -from scapy.packet import * -from scapy.fields import * -from scapy.ansmachine import * -from scapy.layers.inet import UDP -from scapy.layers.inet import TCP -from scapy.base_classes import Net - - -# Guess payload -def guess_payload(p): - LDPTypes = { - 0x0001: LDPNotification, - 0x0100: LDPHello, - 0x0200: LDPInit, - 0x0201: LDPKeepAlive, - 0x0300: LDPAddress, - 0x0301: LDPAddressWM, - 0x0400: LDPLabelMM, - 0x0401: LDPLabelReqM, - 0x0404: LDPLabelARM, - 0x0402: LDPLabelWM, - 0x0403: LDPLabelRelM, - } - type = struct.unpack("!H",p[0:2])[0] - type = type & 0x7fff - if type == 0x0001 and struct.unpack("!H",p[2:4])[0] > 20: - return LDP - if type in LDPTypes: - return LDPTypes[type] - else: - return conf.raw_layer - -## Fields ## - -# 3.4.1. FEC TLV - -class FecTLVField(StrField): - islist=1 - def m2i(self, pkt, x): - nbr = struct.unpack("!H",x[2:4])[0] - used = 0 - x=x[4:] - list=[] - while x: - #if x[0] == 1: - # list.append('Wildcard') - #else: - #mask=ord(x[8*i+3]) - #add=inet_ntoa(x[8*i+4:8*i+8]) - mask=ord(x[3]) - nbroctets = mask / 8 - if mask % 8: - nbroctets += 1 - add=inet_ntoa(x[4:4+nbroctets]+"\x00"*(4-nbroctets)) - list.append( (add, mask) ) - used += 4 + nbroctets - x=x[4+nbroctets:] - return list - def i2m(self, pkt, x): - if type(x) is str: - return x - s = "\x01\x00" - l = 0 - fec = "" - for o in x: - fec += "\x02\x00\x01" - # mask length - fec += struct.pack("!B",o[1]) - # Prefix - fec += inet_aton(o[0]) - l += 8 - s += struct.pack("!H",l) - s += fec - return s - def size(self, s): - """Get the size of this field""" - l = 4 + struct.unpack("!H",s[2:4])[0] - return l - def getfield(self, pkt, s): - l = self.size(s) - return s[l:],self.m2i(pkt, s[:l]) - - -# 3.4.2.1. Generic Label TLV - -class LabelTLVField(StrField): - def m2i(self, pkt, x): - return struct.unpack("!I",x[4:8])[0] - def i2m(self, pkt, x): - if type(x) is str: - return x - s = "\x02\x00\x00\x04" - s += struct.pack("!I",x) - return s - def size(self, s): - """Get the size of this field""" - l = 4 + struct.unpack("!H",s[2:4])[0] - return l - def getfield(self, pkt, s): - l = self.size(s) - return s[l:],self.m2i(pkt, s[:l]) - - -# 3.4.3. Address List TLV - -class AddressTLVField(StrField): - islist=1 - def m2i(self, pkt, x): - nbr = struct.unpack("!H",x[2:4])[0] - 2 - nbr /= 4 - x=x[6:] - list=[] - for i in range(0,nbr): - add = x[4*i:4*i+4] - list.append(inet_ntoa(add)) - return list - def i2m(self, pkt, x): - if type(x) is str: - return x - l=2+len(x)*4 - s = "\x01\x01"+struct.pack("!H",l)+"\x00\x01" - for o in x: - s += inet_aton(o) - return s - def size(self, s): - """Get the size of this field""" - l = 4 + struct.unpack("!H",s[2:4])[0] - return l - def getfield(self, pkt, s): - l = self.size(s) - return s[l:],self.m2i(pkt, s[:l]) - - -# 3.4.6. Status TLV - -class StatusTLVField(StrField): - islist=1 - def m2i(self, pkt, x): - l = [] - statuscode = struct.unpack("!I",x[4:8])[0] - l.append( (statuscode & 2**31) >> 31) - l.append( (statuscode & 2**30) >> 30) - l.append( statuscode & 0x3FFFFFFF ) - l.append( struct.unpack("!I", x[8:12])[0] ) - l.append( struct.unpack("!H", x[12:14])[0] ) - return l - def i2m(self, pkt, x): - if type(x) is str: - return x - s = "\x03\x00" + struct.pack("!H",10) - statuscode = 0 - if x[0] != 0: - statuscode += 2**31 - if x[1] != 0: - statuscode += 2**30 - statuscode += x[2] - s += struct.pack("!I",statuscode) - if len(x) > 3: - s += struct.pack("!I",x[3]) - else: - s += "\x00\x00\x00\x00" - if len(x) > 4: - s += struct.pack("!H",x[4]) - else: - s += "\x00\x00" - return s - def getfield(self, pkt, s): - l = 14 - return s[l:],self.m2i(pkt, s[:l]) - - -# 3.5.2 Common Hello Parameters TLV -class CommonHelloTLVField(StrField): - islist = 1 - def m2i(self, pkt, x): - list = [] - v = struct.unpack("!H",x[4:6])[0] - list.append(v) - flags = struct.unpack("B",x[6])[0] - v = ( flags & 0x80 ) >> 7 - list.append(v) - v = ( flags & 0x40 ) >> 7 - list.append(v) - return list - def i2m(self, pkt, x): - if type(x) is str: - return x - s = "\x04\x00\x00\x04" - s += struct.pack("!H",x[0]) - byte = 0 - if x[1] == 1: - byte += 0x80 - if x[2] == 1: - byte += 0x40 - s += struct.pack("!B",byte) - s += "\x00" - return s - def getfield(self, pkt, s): - l = 8 - return s[l:],self.m2i(pkt, s[:l]) - - -# 3.5.3 Common Session Parameters TLV -class CommonSessionTLVField(StrField): - islist = 1 - def m2i(self, pkt, x): - l = [] - l.append(struct.unpack("!H",x[6:8])[0]) - octet = struct.unpack("B",x[8:9])[0] - l.append( (octet & 2**7 ) >> 7 ) - l.append( (octet & 2**6 ) >> 6 ) - l.append( struct.unpack("B",x[9:10])[0] ) - l.append( struct.unpack("!H",x[10:12])[0] ) - l.append( inet_ntoa(x[12:16]) ) - l.append( struct.unpack("!H",x[16:18])[0] ) - return l - def i2m(self, pkt, x): - if type(x) is str: - return x - s = "\x05\x00\x00\x0E\x00\x01" - s += struct.pack("!H",x[0]) - octet = 0 - if x[1] != 0: - octet += 2**7 - if x[2] != 0: - octet += 2**6 - s += struct.pack("!B",octet) - s += struct.pack("!B",x[3]) - s += struct.pack("!H",x[4]) - s += inet_aton(x[5]) - s += struct.pack("!H",x[6]) - return s - def getfield(self, pkt, s): - l = 18 - return s[l:],self.m2i(pkt, s[:l]) - - - -## Messages ## - -# 3.5.1. Notification Message -class LDPNotification(Packet): - name = "LDPNotification" - fields_desc = [ BitField("u",0,1), - BitField("type", 0x0001, 15), - ShortField("len", None), - IntField("id", 0) , - StatusTLVField("status",(0,0,0,0,0)) ] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.2. Hello Message -class LDPHello(Packet): - name = "LDPHello" - fields_desc = [ BitField("u",0,1), - BitField("type", 0x0100, 15), - ShortField("len", None), - IntField("id", 0) , - CommonHelloTLVField("params",[180,0,0]) ] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.3. Initialization Message -class LDPInit(Packet): - name = "LDPInit" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0200, 15), - ShortField("len", None), - IntField("id", 0), - CommonSessionTLVField("params",None)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.4. KeepAlive Message -class LDPKeepAlive(Packet): - name = "LDPKeepAlive" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0201, 15), - ShortField("len", None), - IntField("id", 0)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.5. Address Message - -class LDPAddress(Packet): - name = "LDPAddress" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0300, 15), - ShortField("len", None), - IntField("id", 0), - AddressTLVField("address",None) ] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.6. Address Withdraw Message - -class LDPAddressWM(Packet): - name = "LDPAddressWM" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0301, 15), - ShortField("len", None), - IntField("id", 0), - AddressTLVField("address",None) ] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.7. Label Mapping Message - -class LDPLabelMM(Packet): - name = "LDPLabelMM" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0400, 15), - ShortField("len", None), - IntField("id", 0), - FecTLVField("fec",None), - LabelTLVField("label",0)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - -# 3.5.8. Label Request Message - -class LDPLabelReqM(Packet): - name = "LDPLabelReqM" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0401, 15), - ShortField("len", None), - IntField("id", 0), - FecTLVField("fec",None)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.9. Label Abort Request Message - -class LDPLabelARM(Packet): - name = "LDPLabelARM" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0404, 15), - ShortField("len", None), - IntField("id", 0), - FecTLVField("fec",None), - IntField("labelRMid",0)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.10. Label Withdraw Message - -class LDPLabelWM(Packet): - name = "LDPLabelWM" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0402, 15), - ShortField("len", None), - IntField("id", 0), - FecTLVField("fec",None), - LabelTLVField("label",0)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.5.11. Label Release Message - -class LDPLabelRelM(Packet): - name = "LDPLabelRelM" - fields_desc = [ BitField("u",0,1), - XBitField("type", 0x0403, 15), - ShortField("len", None), - IntField("id", 0), - FecTLVField("fec",None), - LabelTLVField("label",0)] - def post_build(self, p, pay): - if self.len is None: - l = len(p) - 4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - - -# 3.1. LDP PDUs -class LDP(Packet): - name = "LDP" - fields_desc = [ ShortField("version",1), - ShortField("len", None), - IPField("id","127.0.0.1"), - ShortField("space",0) ] - def post_build(self, p, pay): - if self.len is None: - l = len(p)+len(pay)-4 - p = p[:2]+struct.pack("!H", l)+p[4:] - return p+pay - def guess_payload_class(self, p): - return guess_payload(p) - -bind_layers( TCP, LDP, sport=646, dport=646 ) -bind_layers( UDP, LDP, sport=646, dport=646 ) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/mpls.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/mpls.py deleted file mode 100644 index 037278c5..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/mpls.py +++ /dev/null @@ -1,17 +0,0 @@ -# http://trac.secdev.org/scapy/ticket/31 - -# scapy.contrib.description = MPLS -# scapy.contrib.status = loads - -from scapy.packet import Packet,bind_layers -from scapy.fields import BitField,ByteField -from scapy.layers.l2 import Ether - -class MPLS(Packet): - name = "MPLS" - fields_desc = [ BitField("label", 3, 20), - BitField("cos", 0, 3), - BitField("s", 1, 1), - ByteField("ttl", 0) ] - -bind_layers(Ether, MPLS, type=0x8847) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ospf.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ospf.py deleted file mode 100644 index a6422bd8..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ospf.py +++ /dev/null @@ -1,833 +0,0 @@ -#!/usr/bin/env python - -# scapy.contrib.description = OSPF -# scapy.contrib.status = loads - -""" -OSPF extension for Scapy <http://www.secdev.org/scapy> - -This module provides Scapy layers for the Open Shortest Path First -routing protocol as defined in RFC 2328 and RFC 5340. - -Copyright (c) 2008 Dirk Loss : mail dirk-loss de -Copyright (c) 2010 Jochen Bartl : jochen.bartl gmail com - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -""" - - -from scapy.all import * - -EXT_VERSION = "v0.9.2" - - -class OSPFOptionsField(FlagsField): - - def __init__(self, name="options", default=0, size=8, - names=["MT", "E", "MC", "NP", "L", "DC", "O", "DN"]): - FlagsField.__init__(self, name, default, size, names) - - -_OSPF_types = {1: "Hello", - 2: "DBDesc", - 3: "LSReq", - 4: "LSUpd", - 5: "LSAck"} - - -class OSPF_Hdr(Packet): - name = "OSPF Header" - fields_desc = [ - ByteField("version", 2), - ByteEnumField("type", 1, _OSPF_types), - ShortField("len", None), - IPField("src", "1.1.1.1"), - IPField("area", "0.0.0.0"), # default: backbone - XShortField("chksum", None), - ShortEnumField("authtype", 0, {0:"Null", 1:"Simple", 2:"Crypto"}), - # Null or Simple Authentication - ConditionalField(XLongField("authdata", 0), lambda pkt:pkt.authtype != 2), - # Crypto Authentication - ConditionalField(XShortField("reserved", 0), lambda pkt:pkt.authtype == 2), - ConditionalField(ByteField("keyid", 1), lambda pkt:pkt.authtype == 2), - ConditionalField(ByteField("authdatalen", 0), lambda pkt:pkt.authtype == 2), - ConditionalField(XIntField("seq", 0), lambda pkt:pkt.authtype == 2), - # TODO: Support authdata (which is appended to the packets as if it were padding) - ] - - def post_build(self, p, pay): - # TODO: Remove LLS data from pay - # LLS data blocks may be attached to OSPF Hello and DD packets - # The length of the LLS block shall not be included into the length of OSPF packet - # See <http://tools.ietf.org/html/rfc5613> - p += pay - l = self.len - if l is None: - l = len(p) - p = p[:2] + struct.pack("!H", l) + p[4:] - if self.chksum is None: - if self.authtype == 2: - ck = 0 # Crypto, see RFC 2328, D.4.3 - else: - # Checksum is calculated without authentication data - # Algorithm is the same as in IP() - ck = checksum(p[:16] + p[24:]) - p = p[:12] + chr(ck >> 8) + chr(ck & 0xff) + p[14:] - # TODO: Handle Crypto: Add message digest (RFC 2328, D.4.3) - return p - - def hashret(self): - return struct.pack("H", self.area) + self.payload.hashret() - - def answers(self, other): - if (isinstance(other, OSPF_Hdr) and - self.area == other.area and - self.type == 5): # Only acknowledgements answer other packets - return self.payload.answers(other.payload) - return 0 - - -class OSPF_Hello(Packet): - name = "OSPF Hello" - fields_desc = [IPField("mask", "255.255.255.0"), - ShortField("hellointerval", 10), - OSPFOptionsField(), - ByteField("prio", 1), - IntField("deadinterval", 40), - IPField("router", "0.0.0.0"), - IPField("backup", "0.0.0.0"), - FieldListField("neighbors", [], IPField("", "0.0.0.0"), length_from=lambda pkt: (pkt.underlayer.len - 44))] - - def guess_payload_class(self, payload): - # check presence of LLS data block flag - if self.options & 0x10 == 0x10: - return OSPF_LLS_Hdr - else: - return Packet.guess_payload_class(self, payload) - - -class LLS_Generic_TLV(Packet): - name = "LLS Generic" - fields_desc = [ShortField("type", 1), - FieldLenField("len", None, length_of=lambda x: x.val), - StrLenField("val", "", length_from=lambda x: x.len)] - - def guess_payload_class(self, p): - return conf.padding_layer - - -class LLS_ExtendedOptionsField(FlagsField): - - def __init__(self, name="options", default=0, size=32, - names=["LR", "RS"]): - FlagsField.__init__(self, name, default, size, names) - - -class LLS_Extended_Options(LLS_Generic_TLV): - name = "LLS Extended Options and Flags" - fields_desc = [ShortField("type", 1), - ShortField("len", 4), - LLS_ExtendedOptionsField()] - - -class LLS_Crypto_Auth(LLS_Generic_TLV): - name = "LLS Cryptographic Authentication" - fields_desc = [ShortField("type", 2), - FieldLenField("len", 20, fmt="B", length_of=lambda x: x.authdata), - XIntField("sequence", "\x00\x00\x00\x00"), - StrLenField("authdata", "\x00" * 16, length_from=lambda x: x.len)] - - def post_build(self, p, pay): - p += pay - l = self.len - - if l is None: - # length = len(sequence) + len(authdata) + len(payload) - l = len(p[3:]) - p = p[:2] + struct.pack("!H", l) + p[3:] - - return p - -_OSPF_LLSclasses = {1: "LLS_Extended_Options", - 2: "LLS_Crypto_Auth"} - - -def _LLSGuessPayloadClass(p, **kargs): - """ Guess the correct LLS class for a given payload """ - - cls = conf.raw_layer - if len(p) >= 4: - typ = struct.unpack("!H", p[0:2])[0] - clsname = _OSPF_LLSclasses.get(typ, "LLS_Generic_TLV") - cls = globals()[clsname] - return cls(p, **kargs) - - -class OSPF_LLS_Hdr(Packet): - name = "OSPF Link-local signaling" - fields_desc = [XShortField("chksum", None), - # FIXME Length should be displayed in 32-bit words - ShortField("len", None), - PacketListField("llstlv", [], _LLSGuessPayloadClass)] - - def post_build(self, p, pay): - p += pay - l = self.len - if l is None: - # Length in 32-bit words - l = len(p) / 4 - p = p[:2] + struct.pack("!H", l) + p[4:] - if self.chksum is None: - c = checksum(p) - p = chr((c >> 8) & 0xff) + chr(c & 0xff) + p[2:] - return p - -_OSPF_LStypes = {1: "router", - 2: "network", - 3: "summaryIP", - 4: "summaryASBR", - 5: "external", - 7: "NSSAexternal"} - -_OSPF_LSclasses = {1: "OSPF_Router_LSA", - 2: "OSPF_Network_LSA", - 3: "OSPF_SummaryIP_LSA", - 4: "OSPF_SummaryASBR_LSA", - 5: "OSPF_External_LSA", - 7: "OSPF_NSSA_External_LSA"} - - -def ospf_lsa_checksum(lsa): - """ Fletcher checksum for OSPF LSAs, returned as a 2 byte string. - - Give the whole LSA packet as argument. - For details on the algorithm, see RFC 2328 chapter 12.1.7 and RFC 905 Annex B. - """ - # This is based on the GPLed C implementation in Zebra <http://www.zebra.org/> - - CHKSUM_OFFSET = 16 - - if len(lsa) < CHKSUM_OFFSET: - raise Exception("LSA Packet too short (%s bytes)" % len(lsa)) - - c0 = c1 = 0 - # Calculation is done with checksum set to zero - lsa = lsa[:CHKSUM_OFFSET] + "\x00\x00" + lsa[CHKSUM_OFFSET + 2:] - for char in lsa[2:]: # leave out age - c0 += ord(char) - c1 += c0 - - c0 %= 255 - c1 %= 255 - - x = ((len(lsa) - CHKSUM_OFFSET - 1) * c0 - c1) % 255 - - if (x <= 0): - x += 255 - - y = 510 - c0 - x - - if (y > 255): - y -= 255 - #checksum = (x << 8) + y - - return chr(x) + chr(y) - - -class OSPF_LSA_Hdr(Packet): - name = "OSPF LSA Header" - fields_desc = [ShortField("age", 1), - OSPFOptionsField(), - ByteEnumField("type", 1, _OSPF_LStypes), - IPField("id", "192.168.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", 0), - ShortField("len", 36)] - - def extract_padding(self, s): - return "", s - - -_OSPF_Router_LSA_types = {1: "p2p", - 2: "transit", - 3: "stub", - 4: "virtual"} - - -class OSPF_Link(Packet): - name = "OSPF Link" - fields_desc = [IPField("id", "192.168.0.0"), - IPField("data", "255.255.255.0"), - ByteEnumField("type", 3, _OSPF_Router_LSA_types), - ByteField("toscount", 0), - ShortField("metric", 10), - # TODO: define correct conditions - ConditionalField(ByteField("tos", 0), lambda pkt: False), - ConditionalField(ByteField("reserved", 0), lambda pkt: False), - ConditionalField(ShortField("tosmetric", 0), lambda pkt: False)] - - def extract_padding(self, s): - return "", s - - -def _LSAGuessPayloadClass(p, **kargs): - """ Guess the correct LSA class for a given payload """ - # This is heavily based on scapy-cdp.py by Nicolas Bareil and Arnaud Ebalard - # XXX: This only works if all payload - cls = conf.raw_layer - if len(p) >= 4: - typ = struct.unpack("!B", p[3])[0] - clsname = _OSPF_LSclasses.get(typ, "Raw") - cls = globals()[clsname] - return cls(p, **kargs) - - -class OSPF_BaseLSA(Packet): - """ An abstract base class for Link State Advertisements """ - - def post_build(self, p, pay): - length = self.len - if length is None: - length = len(p) - p = p[:18] + struct.pack("!H", length) + p[20:] - if self.chksum is None: - chksum = ospf_lsa_checksum(p) - p = p[:16] + chksum + p[18:] - return p # p+pay? - - def extract_padding(self, s): - length = self.len - return "", s - - -class OSPF_Router_LSA(OSPF_BaseLSA): - name = "OSPF Router LSA" - fields_desc = [ShortField("age", 1), - OSPFOptionsField(), - ByteField("type", 1), - IPField("id", "1.1.1.1"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - FlagsField("flags", 0, 8, ["B", "E", "V", "W", "Nt"]), - ByteField("reserved", 0), - FieldLenField("linkcount", None, count_of="linklist"), - PacketListField("linklist", [], OSPF_Link, - count_from=lambda pkt: pkt.linkcount, - length_from=lambda pkt: pkt.linkcount * 12)] - - -class OSPF_Network_LSA(OSPF_BaseLSA): - name = "OSPF Network LSA" - fields_desc = [ShortField("age", 1), - OSPFOptionsField(), - ByteField("type", 2), - IPField("id", "192.168.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - IPField("mask", "255.255.255.0"), - FieldListField("routerlist", [], IPField("", "1.1.1.1"), - length_from=lambda pkt: pkt.len - 24)] - - -class OSPF_SummaryIP_LSA(OSPF_BaseLSA): - name = "OSPF Summary LSA (IP Network)" - fields_desc = [ShortField("age", 1), - OSPFOptionsField(), - ByteField("type", 3), - IPField("id", "192.168.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - IPField("mask", "255.255.255.0"), - ByteField("reserved", 0), - X3BytesField("metric", 10), - # TODO: Define correct conditions - ConditionalField(ByteField("tos", 0), lambda pkt:False), - ConditionalField(X3BytesField("tosmetric", 0), lambda pkt:False)] - - -class OSPF_SummaryASBR_LSA(OSPF_SummaryIP_LSA): - name = "OSPF Summary LSA (AS Boundary Router)" - type = 4 - id = "2.2.2.2" - mask = "0.0.0.0" - metric = 20 - - -class OSPF_External_LSA(OSPF_BaseLSA): - name = "OSPF External LSA (ASBR)" - fields_desc = [ShortField("age", 1), - OSPFOptionsField(), - ByteField("type", 5), - IPField("id", "192.168.0.0"), - IPField("adrouter", "2.2.2.2"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - IPField("mask", "255.255.255.0"), - FlagsField("ebit", 0, 1, ["E"]), - BitField("reserved", 0, 7), - X3BytesField("metric", 20), - IPField("fwdaddr", "0.0.0.0"), - XIntField("tag", 0), - # TODO: Define correct conditions - ConditionalField(ByteField("tos", 0), lambda pkt:False), - ConditionalField(X3BytesField("tosmetric", 0), lambda pkt:False)] - - -class OSPF_NSSA_External_LSA(OSPF_External_LSA): - name = "OSPF NSSA External LSA" - type = 7 - - -class OSPF_DBDesc(Packet): - name = "OSPF Database Description" - fields_desc = [ShortField("mtu", 1500), - OSPFOptionsField(), - FlagsField("dbdescr", 0, 8, ["MS", "M", "I", "R", "4", "3", "2", "1"]), - IntField("ddseq", 1), - PacketListField("lsaheaders", None, OSPF_LSA_Hdr, - count_from = lambda pkt: None, - length_from = lambda pkt: pkt.underlayer.len - 24 - 8)] - - def guess_payload_class(self, payload): - # check presence of LLS data block flag - if self.options & 0x10 == 0x10: - return OSPF_LLS_Hdr - else: - return Packet.guess_payload_class(self, payload) - - -class OSPF_LSReq_Item(Packet): - name = "OSPF Link State Request (item)" - fields_desc = [IntEnumField("type", 1, _OSPF_LStypes), - IPField("id", "1.1.1.1"), - IPField("adrouter", "1.1.1.1")] - - def extract_padding(self, s): - return "", s - - -class OSPF_LSReq(Packet): - name = "OSPF Link State Request (container)" - fields_desc = [PacketListField("requests", None, OSPF_LSReq_Item, - count_from = lambda pkt:None, - length_from = lambda pkt:pkt.underlayer.len - 24)] - - -class OSPF_LSUpd(Packet): - name = "OSPF Link State Update" - fields_desc = [FieldLenField("lsacount", None, fmt="!I", count_of="lsalist"), - PacketListField("lsalist", [], _LSAGuessPayloadClass, - count_from = lambda pkt: pkt.lsacount, - length_from = lambda pkt: pkt.underlayer.len - 24)] - - -class OSPF_LSAck(Packet): - name = "OSPF Link State Acknowledgement" - fields_desc = [PacketListField("lsaheaders", None, OSPF_LSA_Hdr, - count_from = lambda pkt: None, - length_from = lambda pkt: pkt.underlayer.len - 24)] - - def answers(self, other): - if isinstance(other, OSPF_LSUpd): - for reqLSA in other.lsalist: - for ackLSA in self.lsaheaders: - if (reqLSA.type == ackLSA.type and - reqLSA.seq == ackLSA.seq): - return 1 - return 0 - - -#------------------------------------------------------------------------------ -# OSPFv3 -#------------------------------------------------------------------------------ -# TODO: Add length_from / adjust functionality to IP6Field and remove this class -class OspfIP6Field(StrField, IP6Field): - """ - Special IP6Field for prefix fields in OSPFv3 LSAs - """ - - def __init__(self, name, default, length=None, length_from=None): - StrField.__init__(self, name, default) - self.length_from = length_from - if length is not None: - self.length_from = lambda pkt, length = length: length - - def any2i(self, pkt, x): - return IP6Field.any2i(self, pkt, x) - - def i2repr(self, pkt, x): - return IP6Field.i2repr(self, pkt, x) - - def h2i(self, pkt, x): - return IP6Field.h2i(self, pkt, x) - - def i2m(self, pkt, x): - x = inet_pton(socket.AF_INET6, x) - l = self.length_from(pkt) - l = self.prefixlen_to_bytelen(l) - - return x[:l] - - def m2i(self, pkt, x): - l = self.length_from(pkt) - - prefixlen = self.prefixlen_to_bytelen(l) - if l > 128: - warning("OspfIP6Field: Prefix length is > 128. Dissection of this packet will fail") - else: - pad = "\x00" * (16 - prefixlen) - x += pad - - return inet_ntop(socket.AF_INET6, x) - - def prefixlen_to_bytelen(self, l): - if l <= 32: - return 4 - elif l <= 64: - return 8 - elif l <= 96: - return 12 - else: - return 16 - - def i2len(self, pkt, x): - l = self.length_from(pkt) - l = self.prefixlen_to_bytelen(l) - - return l - - def getfield(self, pkt, s): - l = self.length_from(pkt) - l = self.prefixlen_to_bytelen(l) - - return s[l:], self.m2i(pkt, s[:l]) - - -class OSPFv3_Hdr(Packet): - name = "OSPFv3 Header" - fields_desc = [ByteField("version", 3), - ByteEnumField("type", 1, _OSPF_types), - ShortField("len", None), - IPField("src", "1.1.1.1"), - IPField("area", "0.0.0.0"), - XShortField("chksum", None), - ByteField("instance", 0), - ByteField("reserved", 0)] - - def post_build(self, p, pay): - p += pay - l = self.len - - if l is None: - l = len(p) - p = p[:2] + struct.pack("!H", l) + p[4:] - - if self.chksum is None: - chksum = in6_chksum(89, self.underlayer, p) - p = p[:12] + chr(chksum >> 8) + chr(chksum & 0xff) + p[14:] - - return p - - -class OSPFv3OptionsField(FlagsField): - - def __init__(self, name="options", default=0, size=24, - names=["V6", "E", "MC", "N", "R", "DC", "AF", "L", "I", "F"]): - FlagsField.__init__(self, name, default, size, names) - - -class OSPFv3_Hello(Packet): - name = "OSPFv3 Hello" - fields_desc = [IntField("intid", 0), - ByteField("prio", 1), - OSPFv3OptionsField(), - ShortField("hellointerval", 10), - ShortField("deadinterval", 40), - IPField("router", "0.0.0.0"), - IPField("backup", "0.0.0.0"), - FieldListField("neighbors", [], IPField("", "0.0.0.0"), - length_from=lambda pkt: (pkt.underlayer.len - 36))] - - -_OSPFv3_LStypes = {0x2001: "router", - 0x2002: "network", - 0x2003: "interAreaPrefix", - 0x2004: "interAreaRouter", - 0x4005: "asExternal", - 0x2007: "type7", - 0x0008: "link", - 0x2009: "intraAreaPrefix"} - -_OSPFv3_LSclasses = {0x2001: "OSPFv3_Router_LSA", - 0x2002: "OSPFv3_Network_LSA", - 0x2003: "OSPFv3_Inter_Area_Prefix_LSA", - 0x2004: "OSPFv3_Inter_Area_Router_LSA", - 0x4005: "OSPFv3_AS_External_LSA", - 0x2007: "OSPFv3_Type_7_LSA", - 0x0008: "OSPFv3_Link_LSA", - 0x2009: "OSPFv3_Intra_Area_Prefix_LSA"} - - -class OSPFv3_LSA_Hdr(Packet): - name = "OSPFv3 LSA Header" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x2001, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", 0), - ShortField("len", 36)] - - def extract_padding(self, s): - return "", s - - -def _OSPFv3_LSAGuessPayloadClass(p, **kargs): - """ Guess the correct OSPFv3 LSA class for a given payload """ - - cls = conf.raw_layer - - if len(p) >= 6: - typ = struct.unpack("!H", p[2:4])[0] - clsname = _OSPFv3_LSclasses.get(typ, "Raw") - cls = globals()[clsname] - - return cls(p, **kargs) - - -_OSPFv3_Router_LSA_types = {1: "p2p", - 2: "transit", - 3: "reserved", - 4: "virtual"} - - -class OSPFv3_Link(Packet): - name = "OSPFv3 Link" - fields_desc = [ByteEnumField("type", 1, _OSPFv3_Router_LSA_types), - ByteField("reserved", 0), - ShortField("metric", 10), - IntField("intid", 0), - IntField("neighintid", 0), - IPField("neighbor", "2.2.2.2")] - - def extract_padding(self, s): - return "", s - - -class OSPFv3_Router_LSA(OSPF_BaseLSA): - name = "OSPFv3 Router LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x2001, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - FlagsField("flags", 0, 8, ["B", "E", "V", "W"]), - OSPFv3OptionsField(), - PacketListField("linklist", [], OSPFv3_Link, - length_from=lambda pkt:pkt.len - 24)] - - -class OSPFv3_Network_LSA(OSPF_BaseLSA): - name = "OSPFv3 Network LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x2002, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - ByteField("reserved", 0), - OSPFv3OptionsField(), - FieldListField("routerlist", [], IPField("", "0.0.0.1"), - length_from=lambda pkt: pkt.len - 24)] - - -class OSPFv3PrefixOptionsField(FlagsField): - - def __init__(self, name="prefixoptions", default=0, size=8, - names=["NU", "LA", "MC", "P"]): - FlagsField.__init__(self, name, default, size, names) - - -class OSPFv3_Inter_Area_Prefix_LSA(OSPF_BaseLSA): - name = "OSPFv3 Inter Area Prefix LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x2003, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - ByteField("reserved", 0), - X3BytesField("metric", 10), - ByteField("prefixlen", 64), - OSPFv3PrefixOptionsField(), - ShortField("reserved2", 0), - OspfIP6Field("prefix", "2001:db8:0:42::", length_from=lambda pkt: pkt.prefixlen)] - - -class OSPFv3_Inter_Area_Router_LSA(OSPF_BaseLSA): - name = "OSPFv3 Inter Area Router LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x2004, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - ByteField("reserved", 0), - X3BytesField("metric", 1), - IPField("router", "2.2.2.2")] - - -class OSPFv3_AS_External_LSA(OSPF_BaseLSA): - name = "OSPFv3 AS External LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x4005, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - FlagsField("flags", 0, 8, ["T", "F", "E"]), - X3BytesField("metric", 20), - ByteField("prefixlen", 64), - OSPFv3PrefixOptionsField(), - ShortEnumField("reflstype", 0, _OSPFv3_LStypes), - OspfIP6Field("prefix", "2001:db8:0:42::", length_from=lambda pkt: pkt.prefixlen), - ConditionalField(IP6Field("fwaddr", "::"), lambda pkt: pkt.flags & 0x02 == 0x02), - ConditionalField(IntField("tag", 0), lambda pkt: pkt.flags & 0x01 == 0x01), - ConditionalField(IPField("reflsid", 0), lambda pkt: pkt.reflstype != 0)] - - -class OSPFv3_Type_7_LSA(OSPFv3_AS_External_LSA): - name = "OSPFv3 Type 7 LSA" - type = 0x2007 - - -class OSPFv3_Prefix_Item(Packet): - name = "OSPFv3 Link Prefix Item" - fields_desc = [ByteField("prefixlen", 64), - OSPFv3PrefixOptionsField(), - ShortField("metric", 10), - OspfIP6Field("prefix", "2001:db8:0:42::", length_from=lambda pkt: pkt.prefixlen)] - - def extract_padding(self, s): - return "", s - - -class OSPFv3_Link_LSA(OSPF_BaseLSA): - name = "OSPFv3 Link LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x0008, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - ByteField("prio", 1), - OSPFv3OptionsField(), - IP6Field("lladdr", "fe80::"), - IntField("prefixes", 0), - PacketListField("prefixlist", None, OSPFv3_Prefix_Item, - count_from = lambda pkt: pkt.prefixes)] - - -class OSPFv3_Intra_Area_Prefix_LSA(OSPF_BaseLSA): - name = "OSPFv3 Intra Area Prefix LSA" - fields_desc = [ShortField("age", 1), - ShortEnumField("type", 0x2009, _OSPFv3_LStypes), - IPField("id", "0.0.0.0"), - IPField("adrouter", "1.1.1.1"), - XIntField("seq", 0x80000001), - XShortField("chksum", None), - ShortField("len", None), - ShortField("prefixes", 0), - ShortEnumField("reflstype", 0, _OSPFv3_LStypes), - IPField("reflsid", "0.0.0.0"), - IPField("refadrouter", "0.0.0.0"), - PacketListField("prefixlist", None, OSPFv3_Prefix_Item, - count_from = lambda pkt: pkt.prefixes)] - - -class OSPFv3_DBDesc(Packet): - name = "OSPFv3 Database Description" - fields_desc = [ByteField("reserved", 0), - OSPFv3OptionsField(), - ShortField("mtu", 1500), - ByteField("reserved2", 0), - FlagsField("dbdescr", 0, 8, ["MS", "M", "I", "R"]), - IntField("ddseq", 1), - PacketListField("lsaheaders", None, OSPFv3_LSA_Hdr, - count_from = lambda pkt:None, - length_from = lambda pkt:pkt.underlayer.len - 28)] - - -class OSPFv3_LSReq_Item(Packet): - name = "OSPFv3 Link State Request (item)" - fields_desc = [ShortField("reserved", 0), - ShortEnumField("type", 0x2001, _OSPFv3_LStypes), - IPField("id", "1.1.1.1"), - IPField("adrouter", "1.1.1.1")] - - def extract_padding(self, s): - return "", s - - -class OSPFv3_LSReq(Packet): - name = "OSPFv3 Link State Request (container)" - fields_desc = [PacketListField("requests", None, OSPFv3_LSReq_Item, - count_from = lambda pkt:None, - length_from = lambda pkt:pkt.underlayer.len - 16)] - - -class OSPFv3_LSUpd(Packet): - name = "OSPFv3 Link State Update" - fields_desc = [FieldLenField("lsacount", None, fmt="!I", count_of="lsalist"), - PacketListField("lsalist", [], _OSPFv3_LSAGuessPayloadClass, - count_from = lambda pkt:pkt.lsacount, - length_from = lambda pkt:pkt.underlayer.len - 16)] - - -class OSPFv3_LSAck(Packet): - name = "OSPFv3 Link State Acknowledgement" - fields_desc = [PacketListField("lsaheaders", None, OSPFv3_LSA_Hdr, - count_from = lambda pkt:None, - length_from = lambda pkt:pkt.underlayer.len - 16)] - - -bind_layers(IP, OSPF_Hdr, proto=89) -bind_layers(OSPF_Hdr, OSPF_Hello, type=1) -bind_layers(OSPF_Hdr, OSPF_DBDesc, type=2) -bind_layers(OSPF_Hdr, OSPF_LSReq, type=3) -bind_layers(OSPF_Hdr, OSPF_LSUpd, type=4) -bind_layers(OSPF_Hdr, OSPF_LSAck, type=5) - -bind_layers(IPv6, OSPFv3_Hdr, nh=89) -bind_layers(OSPFv3_Hdr, OSPFv3_Hello, type=1) -bind_layers(OSPFv3_Hdr, OSPFv3_DBDesc, type=2) -bind_layers(OSPFv3_Hdr, OSPFv3_LSReq, type=3) -bind_layers(OSPFv3_Hdr, OSPFv3_LSUpd, type=4) -bind_layers(OSPFv3_Hdr, OSPFv3_LSAck, type=5) - - -if __name__ == "__main__": - interact(mydict=globals(), mybanner="OSPF extension %s" % EXT_VERSION) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi.py deleted file mode 100644 index f4364096..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi.py +++ /dev/null @@ -1,86 +0,0 @@ -## This file is (hopefully) part of Scapy -## See http://www.secdev.org/projects/scapy for more informations -## <jellch@harris.com> -## This program is published under a GPLv2 license - -# scapy.contrib.description = PPI -# scapy.contrib.status = loads - - -""" -PPI (Per-Packet Information). -""" -import logging,struct -from scapy.config import conf -from scapy.packet import * -from scapy.fields import * -from scapy.layers.l2 import Ether -from scapy.layers.dot11 import Dot11 - -# Dictionary to map the TLV type to the class name of a sub-packet -_ppi_types = {} -def addPPIType(id, value): - _ppi_types[id] = value -def getPPIType(id, default="default"): - return _ppi_types.get(id, _ppi_types.get(default, None)) - - -# Default PPI Field Header -class PPIGenericFldHdr(Packet): - name = "PPI Field Header" - fields_desc = [ LEShortField('pfh_type', 0), - FieldLenField('pfh_length', None, length_of="value", fmt='<H', adjust=lambda p,x:x+4), - StrLenField("value", "", length_from=lambda p:p.pfh_length) ] - - def extract_padding(self, p): - return "",p - -def _PPIGuessPayloadClass(p, **kargs): - """ This function tells the PacketListField how it should extract the - TLVs from the payload. We pass cls only the length string - pfh_len says it needs. If a payload is returned, that means - part of the sting was unused. This converts to a Raw layer, and - the remainder of p is added as Raw's payload. If there is no - payload, the remainder of p is added as out's payload. - """ - if len(p) >= 4: - t,pfh_len = struct.unpack("<HH", p[:4]) - # Find out if the value t is in the dict _ppi_types. - # If not, return the default TLV class - cls = getPPIType(t, "default") - pfh_len += 4 - out = cls(p[:pfh_len], **kargs) - if (out.payload): - out.payload = conf.raw_layer(out.payload.load) - if (len(p) > pfh_len): - out.payload.payload = conf.padding_layer(p[pfh_len:]) - elif (len(p) > pfh_len): - out.payload = conf.padding_layer(p[pfh_len:]) - - else: - out = conf.raw_layer(p, **kargs) - return out - - - - -class PPI(Packet): - name = "PPI Packet Header" - fields_desc = [ ByteField('pph_version', 0), - ByteField('pph_flags', 0), - FieldLenField('pph_len', None, length_of="PPIFieldHeaders", fmt="<H", adjust=lambda p,x:x+8 ), - LEIntField('dlt', None), - PacketListField("PPIFieldHeaders", [], _PPIGuessPayloadClass, length_from=lambda p:p.pph_len-8,) ] - def guess_payload_class(self,payload): - return conf.l2types.get(self.dlt, Packet.guess_payload_class(self, payload)) - -#Register PPI -addPPIType("default", PPIGenericFldHdr) - -conf.l2types.register(192, PPI) -conf.l2types.register_num2layer(192, PPI) - -bind_layers(PPI, Dot11, dlt=conf.l2types.get(Dot11)) -bind_layers(Dot11, PPI) -bind_layers(PPI, Ether, dlt=conf.l2types.get(Ether)) -bind_layers(Dot11, Ether) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi_cace.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi_cace.py deleted file mode 100644 index ba2c4abf..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi_cace.py +++ /dev/null @@ -1,87 +0,0 @@ -## This file is (hopefully) part of Scapy -## See http://www.secdev.org/projects/scapy for more informations -## <jellch@harris.com> -## This program is published under a GPLv2 license - -# scapy.contrib.description = PPI CACE -# scapy.contrib.status = loads - -""" -CACE PPI types -""" -import logging,struct -from scapy.config import conf -from scapy.packet import * -from scapy.fields import * -from scapy.layers.l2 import Ether -from scapy.layers.dot11 import Dot11 -from scapy.contrib.ppi import * - -PPI_DOT11COMMON = 2 -PPI_DOT11NMAC = 3 -PPI_DOT11NMACPHY = 4 -PPI_SPECTRUMMAP = 5 -PPI_PROCESSINFO = 6 -PPI_CAPTUREINFO = 7 -PPI_AGGREGATION = 8 -PPI_DOT3 = 9 - -# PPI 802.11 Common Field Header Fields -class dBmByteField(Field): - def __init__(self, name, default): - Field.__init__(self, name, default, "b") - def i2repr(self, pkt, val): - if (val != None): - val = "%4d dBm" % val - return val - -class PPITSFTField(LELongField): - def i2h(self, pkt, val): - flags = 0 - if (pkt): - flags = pkt.getfieldval("Pkt_Flags") - if not flags: - flags = 0 - if (flags & 0x02): - scale = 1e-3 - else: - scale = 1e-6 - tout = scale * float(val) - return tout - def h2i(self, pkt, val): - scale = 1e6 - if pkt: - flags = pkt.getfieldval("Pkt_Flags") - if flags: - if (flags & 0x02): - scale = 1e3 - tout = int((scale * val) + 0.5) - return tout - -_PPIDot11CommonChFlags = ['','','','','Turbo','CCK','OFDM','2GHz','5GHz', - 'PassiveOnly','Dynamic CCK-OFDM','GSFK'] - -_PPIDot11CommonPktFlags = ['FCS','TSFT_ms','FCS_Invalid','PHY_Error'] - -# PPI 802.11 Common Field Header -class Dot11Common(Packet): - name = "PPI 802.11-Common" - fields_desc = [ LEShortField('pfh_type',PPI_DOT11COMMON), - LEShortField('pfh_length', 20), - PPITSFTField('TSF_Timer', 0), - FlagsField('Pkt_Flags',0, -16, _PPIDot11CommonPktFlags), - LEShortField('Rate',0), - LEShortField('Ch_Freq',0), - FlagsField('Ch_Flags', 0, -16, _PPIDot11CommonChFlags), - ByteField('FHSS_Hop',0), - ByteField('FHSS_Pat',0), - dBmByteField('Antsignal',-128), - dBmByteField('Antnoise',-128)] - - def extract_padding(self, p): - return "",p -#Hopefully other CACE defined types will be added here. - -#Add the dot11common layer to the PPI array -addPPIType(PPI_DOT11COMMON, Dot11Common) - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi_geotag.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi_geotag.py deleted file mode 100644 index 19371512..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ppi_geotag.py +++ /dev/null @@ -1,464 +0,0 @@ -## This file is (hopefully) part of Scapy -## See http://www.secdev.org/projects/scapy for more informations -## <jellch@harris.com> -## This program is published under a GPLv2 license - -# scapy.contrib.description = PPI GEOLOCATION -# scapy.contrib.status = loads - - -""" -PPI-GEOLOCATION tags -""" -import struct -from scapy.packet import * -from scapy.fields import * -from scapy.contrib.ppi import PPIGenericFldHdr,addPPIType - -CURR_GEOTAG_VER = 2 #Major revision of specification - -PPI_GPS = 30002 -PPI_VECTOR = 30003 -PPI_SENSOR = 30004 -PPI_ANTENNA = 30005 -#The FixedX_Y Fields are used to store fixed point numbers in a variety of fields in the GEOLOCATION-TAGS specification -class Fixed3_6Field(LEIntField): - def i2h(self, pkt, x): - if x is not None: - if (x < 0): - warning("Fixed3_6: Internal value too negative: %d" % x) - x = 0 - elif (x > 999999999): - warning("Fixed3_6: Internal value too positive: %d" % x) - x = 999999999 - x = x * 1e-6 - return x - def h2i(self, pkt, x): - if x is not None: - if (x <= -0.5e-6): - warning("Fixed3_6: Input value too negative: %.7f" % x) - x = 0 - elif (x >= 999.9999995): - warning("Fixed3_6: Input value too positive: %.7f" % x) - x = 999.999999 - x = int(round(x * 1e6)) - return x - def i2m(self, pkt, x): - """Convert internal value to machine value""" - if x is None: - #Try to return zero if undefined - x = self.h2i(pkt, 0) - return x - - def i2repr(self,pkt,x): - if x is None: - y=0 - else: - y=self.i2h(pkt,x) - return "%3.6f"%(y) -class Fixed3_7Field(LEIntField): - def i2h(self, pkt, x): - if x is not None: - if (x < 0): - warning("Fixed3_7: Internal value too negative: %d" % x) - x = 0 - elif (x > 3600000000): - warning("Fixed3_7: Internal value too positive: %d" % x) - x = 3600000000 - x = (x - 1800000000) * 1e-7 - return x - def h2i(self, pkt, x): - if x is not None: - if (x <= -180.00000005): - warning("Fixed3_7: Input value too negative: %.8f" % x) - x = -180.0 - elif (x >= 180.00000005): - warning("Fixed3_7: Input value too positive: %.8f" % x) - x = 180.0 - x = int(round((x + 180.0) * 1e7)) - return x - def i2m(self, pkt, x): - """Convert internal value to machine value""" - if x is None: - #Try to return zero if undefined - x = self.h2i(pkt, 0) - return x - def i2repr(self,pkt,x): - if x is None: - y=0 - else: - y=self.i2h(pkt,x) - return "%3.7f"%(y) - -class Fixed6_4Field(LEIntField): - def i2h(self, pkt, x): - if x is not None: - if (x < 0): - warning("Fixed6_4: Internal value too negative: %d" % x) - x = 0 - elif (x > 3600000000): - warning("Fixed6_4: Internal value too positive: %d" % x) - x = 3600000000 - x = (x - 1800000000) * 1e-4 - return x - def h2i(self, pkt, x): - if x is not None: - if (x <= -180000.00005): - warning("Fixed6_4: Input value too negative: %.5f" % x) - x = -180000.0 - elif (x >= 180000.00005): - warning("Fixed6_4: Input value too positive: %.5f" % x) - x = 180000.0 - x = int(round((x + 180000.0) * 1e4)) - return x - def i2m(self, pkt, x): - """Convert internal value to machine value""" - if x is None: - #Try to return zero if undefined - x = self.h2i(pkt, 0) - return x - def i2repr(self,pkt,x): - if x is None: - y=0 - else: - y=self.i2h(pkt,x) - return "%6.4f"%(y) -#The GPS timestamps fractional time counter is stored in a 32-bit unsigned ns counter. -#The ept field is as well, -class NSCounter_Field(LEIntField): - def i2h(self, pkt, x): #converts nano-seconds to seconds for output - if x is not None: - if (x < 0): - warning("NSCounter_Field: Internal value too negative: %d" % x) - x = 0 - elif (x >= 2**32): - warning("NSCounter_Field: Internal value too positive: %d" % x) - x = 2**32-1 - x = (x / 1e9) - return x - def h2i(self, pkt, x): #converts input in seconds into nano-seconds for storage - if x is not None: - if (x < 0): - warning("NSCounter_Field: Input value too negative: %.10f" % x) - x = 0 - elif (x >= (2**32) / 1e9): - warning("NSCounter_Field: Input value too positive: %.10f" % x) - x = (2**32-1) / 1e9 - x = int(round((x * 1e9))) - return x - def i2repr(self,pkt,x): - if x is None: - y=0 - else: - y=self.i2h(pkt,x) - return "%1.9f"%(y) - -class UTCTimeField(IntField): - def __init__(self, name, default, epoch=time.gmtime(0), strf="%a, %d %b %Y %H:%M:%S +0000"): - IntField.__init__(self, name, default) - self.epoch = epoch - self.delta = time.mktime(epoch) - time.mktime(time.gmtime(0)) - self.strf = strf - def i2repr(self, pkt, x): - if x is None: - x = 0 - x = int(x) + self.delta - t = time.strftime(self.strf, time.gmtime(x)) - return "%s (%d)" % (t, x) - -class LETimeField(UTCTimeField,LEIntField): - def __init__(self, name, default, epoch=time.gmtime(0), strf="%a, %d %b %Y %H:%M:%S +0000"): - LEIntField.__init__(self, name, default) - self.epoch = epoch - self.delta = time.mktime(epoch) - time.mktime(time.gmtime(0)) - self.strf = strf - -class SignedByteField(Field): - def __init__(self, name, default): - Field.__init__(self, name, default, "b") - def randval(self): - return RandSByte() - -class XLEShortField(LEShortField,XShortField): - def i2repr(self, pkt, x): - return XShortField.i2repr(self, pkt, x) - -class XLEIntField(LEIntField,XIntField): - def i2repr(self, pkt, x): - return XIntField.i2repr(self, pkt, x) - -class GPSTime_Field(LETimeField): - def __init__(self, name, default): - return LETimeField.__init__(self, name, default, strf="%a, %d %b %Y %H:%M:%S UTC") - -class VectorFlags_Field(XLEIntField): - """Represents te VectorFlags field. Handles the RelativeTo:sub-field""" - _fwdstr = "DefinesForward" - _resmask = 0xfffffff8 - _relmask = 0x6 - _relnames = ["RelativeToForward", "RelativeToEarth", "RelativeToCurrent", "RelativeToReserved"] - _relvals = [0x00, 0x02, 0x04, 0x06] - def i2repr(self, pkt, x): - if x is None: - return str(x) - r = [] - if (x & 0x1): - r.append(self._fwdstr) - i = (x & self._relmask) >> 1 - r.append(self._relnames[i]) - i = x & self._resmask - if (i): - r.append("ReservedBits:%08X" % i) - sout = "+".join(r) - return sout - def any2i(self, pkt, x): - if type(x) is str: - r = x.split("+") - y = 0 - for value in r: - if (value == self._fwdstr): - y |= 0x1 - elif (value in self._relnames): - i = self._relnames.index(value) - y &= (~self._relmask) - y |= self._relvals[i] - else: - #logging.warning("Unknown VectorFlags Argument: %s" % value) - pass - else: - y = x - #print "any2i: %s --> %s" % (str(x), str(y)) - return y - -class HCSIFlagsField(FlagsField): - """ A FlagsField where each bit/flag turns a conditional field on or off. - If the value is None when building a packet, i2m() will check the value of - every field in self.names. If the field's value is not None, the corresponding - flag will be set. """ - def i2m(self, pkt, val): - if val is None: - val = 0 - if (pkt): - for i in range(len(self.names)): - name = self.names[i][0] - value = pkt.getfieldval(name) - if value is not None: - val |= 1 << i - return val - -class HCSINullField(StrFixedLenField): - def __init__(self, name, default): - return StrFixedLenField.__init__(self, name, default, length=0) - -class HCSIDescField(StrFixedLenField): - def __init__(self, name, default): - return StrFixedLenField.__init__(self, name, default, length=32) - -class HCSIAppField(StrFixedLenField): - def __init__(self, name, default): - return StrFixedLenField.__init__(self, name, default, length=60) - -def _FlagsList(myfields): - flags = [] - for i in range(32): - flags.append("Reserved%02d" % i) - for i in myfields.keys(): - flags[i] = myfields[i] - return flags - -# Define all geolocation-tag flags lists -_hcsi_gps_flags = _FlagsList({0:"No Fix Available", 1:"GPS", 2:"Differential GPS", - 3:"Pulse Per Second", 4:"Real Time Kinematic", - 5:"Float Real Time Kinematic", 6:"Estimated (Dead Reckoning)", - 7:"Manual Input", 8:"Simulation"}) - -#_hcsi_vector_flags = _FlagsList({0:"ForwardFrame", 1:"RotationsAbsoluteXYZ", 5:"OffsetFromGPS_XYZ"}) -#This has been replaced with the VectorFlags_Field class, in order to handle the RelativeTo:subfield - -_hcsi_vector_char_flags = _FlagsList({0:"Antenna", 1:"Direction of Travel", - 2:"Front of Vehicle", 3:"Angle of Arrival", 4:"Transmitter Position", - 8:"GPS Derived", 9:"INS Derived", 10:"Compass Derived", - 11:"Acclerometer Derived", 12:"Human Derived"}) - -_hcsi_antenna_flags = _FlagsList({ 1:"Horizontal Polarization", 2:"Vertical Polarization", - 3:"Circular Polarization Left", 4:"Circular Polarization Right", - 16:"Electronically Steerable", 17:"Mechanically Steerable"}) - -""" HCSI PPI Fields are similar to RadioTap. A mask field called "present" specifies if each field -is present. All other fields are conditional. When dissecting a packet, each field is present if -"present" has the corresponding bit set. When building a packet, if "present" is None, the mask is -set to include every field that does not have a value of None. Otherwise, if the mask field is -not None, only the fields specified by "present" will be added to the packet. - -To build each Packet type, build a list of the fields normally, excluding the present bitmask field. -The code will then construct conditional versions of each field and add the present field. -See GPS_Fields as an example. """ - -# Conditional test for all HCSI Fields -def _HCSITest(pkt, ibit, name): - if pkt.present is None: - return (pkt.getfieldval(name) is not None) - return pkt.present & ibit - -# Wrap optional fields in ConditionalField, add HCSIFlagsField -def _HCSIBuildFields(fields): - names = [f.name for f in fields] - cond_fields = [ HCSIFlagsField('present', None, -len(names), names)] - for i in range(len(names)): - ibit = 1 << i - seval = "lambda pkt:_HCSITest(pkt,%s,'%s')" % (ibit, names[i]) - test = eval(seval) - cond_fields.append(ConditionalField(fields[i], test)) - return cond_fields - -class HCSIPacket(Packet): - name = "PPI HCSI" - fields_desc = [ LEShortField('pfh_type', None), - LEShortField('pfh_length', None), - ByteField('geotag_ver', CURR_GEOTAG_VER), - ByteField('geotag_pad', 0), - LEShortField('geotag_len', None)] - def post_build(self, p, pay): - if self.pfh_length is None: - l = len(p) - 4 - sl = struct.pack('<H',l) - p = p[:2] + sl + p[4:] - if self.geotag_len is None: - l_g = len(p) - 4 - sl_g = struct.pack('<H',l_g) - p = p[:6] + sl_g + p[8:] - p += pay - return p - def extract_padding(self, p): - return "",p - -#GPS Fields -GPS_Fields = [FlagsField("GPSFlags", None, -32, _hcsi_gps_flags), - Fixed3_7Field("Latitude", None), - Fixed3_7Field("Longitude", None), Fixed6_4Field("Altitude", None), - Fixed6_4Field("Altitude_g", None), GPSTime_Field("GPSTime", None), - NSCounter_Field("FractionalTime", None), Fixed3_6Field("eph", None), - Fixed3_6Field("epv", None), NSCounter_Field("ept", None), - HCSINullField("Reserved10", None), HCSINullField("Reserved11", None), - HCSINullField("Reserved12", None), HCSINullField("Reserved13", None), - HCSINullField("Reserved14", None), HCSINullField("Reserved15", None), - HCSINullField("Reserved16", None), HCSINullField("Reserved17", None), - HCSINullField("Reserved18", None), HCSINullField("Reserved19", None), - HCSINullField("Reserved20", None), HCSINullField("Reserved21", None), - HCSINullField("Reserved22", None), HCSINullField("Reserved23", None), - HCSINullField("Reserved24", None), HCSINullField("Reserved25", None), - HCSINullField("Reserved26", None), HCSINullField("Reserved27", None), - HCSIDescField("DescString", None), XLEIntField("AppId", None), - HCSIAppField("AppData", None), HCSINullField("Extended", None)] - -class GPS(HCSIPacket): - name = "PPI GPS" - fields_desc = [ LEShortField('pfh_type', PPI_GPS), #pfh_type - LEShortField('pfh_length', None), #pfh_len - ByteField('geotag_ver', CURR_GEOTAG_VER), #base_geotag_header.ver - ByteField('geotag_pad', 0), #base_geotag_header.pad - LEShortField('geotag_len', None)] + _HCSIBuildFields(GPS_Fields) - - -#Vector Fields -VEC_Fields = [VectorFlags_Field("VectorFlags", None), - FlagsField("VectorChars", None, -32, _hcsi_vector_char_flags), - Fixed3_6Field("Pitch", None), Fixed3_6Field("Roll", None), - Fixed3_6Field("Heading", None), Fixed6_4Field("Off_X", None), - Fixed6_4Field("Off_Y", None), Fixed6_4Field("Off_Z", None), - HCSINullField("Reserved08", None), HCSINullField("Reserved09", None), - HCSINullField("Reserved10", None), HCSINullField("Reserved11", None), - HCSINullField("Reserved12", None), HCSINullField("Reserved13", None), - HCSINullField("Reserved14", None), HCSINullField("Reserved15", None), - Fixed3_6Field("Err_Rot", None), Fixed6_4Field("Err_Off", None), - HCSINullField("Reserved18", None), HCSINullField("Reserved19", None), - HCSINullField("Reserved20", None), HCSINullField("Reserved21", None), - HCSINullField("Reserved22", None), HCSINullField("Reserved23", None), - HCSINullField("Reserved24", None), HCSINullField("Reserved25", None), - HCSINullField("Reserved26", None), HCSINullField("Reserved27", None), - HCSIDescField("DescString", None), XLEIntField("AppId", None), - HCSIAppField("AppData", None), HCSINullField("Extended", None)] - -class Vector(HCSIPacket): - name = "PPI Vector" - fields_desc = [ LEShortField('pfh_type', PPI_VECTOR), #pfh_type - LEShortField('pfh_length', None), #pfh_len - ByteField('geotag_ver', CURR_GEOTAG_VER), #base_geotag_header.ver - ByteField('geotag_pad', 0), #base_geotag_header.pad - LEShortField('geotag_len', None)] + _HCSIBuildFields(VEC_Fields) - -#Sensor Fields -# http://www.iana.org/assignments/icmp-parameters -sensor_types= { 1 : "Velocity", - 2 : "Acceleration", - 3 : "Jerk", - 100 : "Rotation", - 101 : "Magnetic", - 1000: "Temperature", - 1001: "Barometer", - 1002: "Humidity", - 2000: "TDOA_Clock", - 2001: "Phase" - } -SENS_Fields = [ LEShortEnumField('SensorType', None, sensor_types), - SignedByteField('ScaleFactor', None), - Fixed6_4Field('Val_X', None), - Fixed6_4Field('Val_Y', None), - Fixed6_4Field('Val_Z', None), - Fixed6_4Field('Val_T', None), - Fixed6_4Field('Val_E', None), - HCSINullField("Reserved07", None), HCSINullField("Reserved08", None), - HCSINullField("Reserved09", None), HCSINullField("Reserved10", None), - HCSINullField("Reserved11", None), HCSINullField("Reserved12", None), - HCSINullField("Reserved13", None), HCSINullField("Reserved14", None), - HCSINullField("Reserved15", None), HCSINullField("Reserved16", None), - HCSINullField("Reserved17", None), HCSINullField("Reserved18", None), - HCSINullField("Reserved19", None), HCSINullField("Reserved20", None), - HCSINullField("Reserved21", None), HCSINullField("Reserved22", None), - HCSINullField("Reserved23", None), HCSINullField("Reserved24", None), - HCSINullField("Reserved25", None), HCSINullField("Reserved26", None), - HCSINullField("Reserved27", None), - HCSIDescField("DescString", None), XLEIntField("AppId", None), - HCSIAppField("AppData", None), HCSINullField("Extended", None)] - - - -class Sensor(HCSIPacket): - name = "PPI Sensor" - fields_desc = [ LEShortField('pfh_type', PPI_SENSOR), #pfh_type - LEShortField('pfh_length', None), #pfh_len - ByteField('geotag_ver', CURR_GEOTAG_VER ), #base_geotag_header.ver - ByteField('geotag_pad', 0), #base_geotag_header.pad - LEShortField('geotag_len', None)] + _HCSIBuildFields(SENS_Fields) - -# HCSIAntenna Fields -ANT_Fields = [FlagsField("AntennaFlags", None, -32, _hcsi_antenna_flags), - ByteField("Gain", None), - Fixed3_6Field("HorizBw", None), Fixed3_6Field("VertBw", None), - Fixed3_6Field("PrecisionGain",None), XLEShortField("BeamID", None), - HCSINullField("Reserved06", None), HCSINullField("Reserved07", None), - HCSINullField("Reserved08", None), HCSINullField("Reserved09", None), - HCSINullField("Reserved10", None), HCSINullField("Reserved11", None), - HCSINullField("Reserved12", None), HCSINullField("Reserved13", None), - HCSINullField("Reserved14", None), HCSINullField("Reserved15", None), - HCSINullField("Reserved16", None), HCSINullField("Reserved17", None), - HCSINullField("Reserved18", None), HCSINullField("Reserved19", None), - HCSINullField("Reserved20", None), HCSINullField("Reserved21", None), - HCSINullField("Reserved22", None), HCSINullField("Reserved23", None), - HCSINullField("Reserved24", None), HCSINullField("Reserved25", None), - HCSIDescField("SerialNumber", None), HCSIDescField("ModelName", None), - HCSIDescField("DescString", None), XLEIntField("AppId", None), - HCSIAppField("AppData", None), HCSINullField("Extended", None)] - -class Antenna(HCSIPacket): - name = "PPI Antenna" - fields_desc = [ LEShortField('pfh_type', PPI_ANTENNA), #pfh_type - LEShortField('pfh_length', None), #pfh_len - ByteField('geotag_ver', CURR_GEOTAG_VER), #base_geotag_header.ver - ByteField('geotag_pad', 0), #base_geotag_header.pad - LEShortField('geotag_len', None)] + _HCSIBuildFields(ANT_Fields) - -addPPIType(PPI_GPS, GPS) -addPPIType(PPI_VECTOR, Vector) -addPPIType(PPI_SENSOR, Sensor) -addPPIType(PPI_ANTENNA,Antenna) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ripng.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ripng.py deleted file mode 100644 index 47e17bc4..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ripng.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python - -# http://trac.secdev.org/scapy/ticket/301 - -# scapy.contrib.description = RIPng -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet import UDP -from scapy.layers.inet6 import * - -class RIPng(Packet): - name = "RIPng header" - fields_desc = [ - ByteEnumField("cmd", 1, {1 : "req", 2 : "resp"}), - ByteField("ver", 1), - ShortField("null", 0), - ] - -class RIPngEntry(Packet): - name = "RIPng entry" - fields_desc = [ - ConditionalField(IP6Field("prefix", "::"), - lambda pkt: pkt.metric != 255), - ConditionalField(IP6Field("nexthop", "::"), - lambda pkt: pkt.metric == 255), - ShortField("routetag", 0), - ByteField("prefixlen", 0), - ByteEnumField("metric", 1, {16 : "Unreach", - 255 : "next-hop entry"}) - ] - -bind_layers(UDP, RIPng, sport=521, dport=521) -bind_layers(RIPng, RIPngEntry) -bind_layers(RIPngEntry, RIPngEntry) - -if __name__ == "__main__": - from scapy.main import interact - interact(mydict=globals(), mybanner="RIPng") - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/rsvp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/rsvp.py deleted file mode 100644 index c9d4ebee..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/rsvp.py +++ /dev/null @@ -1,188 +0,0 @@ -## RSVP layer - -# http://trac.secdev.org/scapy/ticket/197 - -# scapy.contrib.description = RSVP -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet import IP - -rsvpmsgtypes = { 0x01 : "Path", - 0x02 : "Reservation request", - 0x03 : "Path error", - 0x04 : "Reservation request error", - 0x05 : "Path teardown", - 0x06 : "Reservation teardown", - 0x07 : "Reservation request acknowledgment" -} - -class RSVP(Packet): - name = "RSVP" - fields_desc = [ BitField("Version",1,4), - BitField("Flags",1,4), - ByteEnumField("Class",0x01, rsvpmsgtypes), - XShortField("chksum", None), - ByteField("TTL",1), - XByteField("dataofs", 0), - ShortField("Length",None)] - def post_build(self, p, pay): - p += pay - if self.Length is None: - l = len(p) - p = p[:6]+chr((l>>8)&0xff)+chr(l&0xff)+p[8:] - if self.chksum is None: - ck = checksum(p) - p = p[:2]+chr(ck>>8)+chr(ck&0xff)+p[4:] - return p - -rsvptypes = { 0x01 : "Session", - 0x03 : "HOP", - 0x04 : "INTEGRITY", - 0x05 : "TIME_VALUES", - 0x06 : "ERROR_SPEC", - 0x07 : "SCOPE", - 0x08 : "STYLE", - 0x09 : "FLOWSPEC", - 0x0A : "FILTER_SPEC", - 0x0B : "SENDER_TEMPLATE", - 0x0C : "SENDER_TSPEC", - 0x0D : "ADSPEC", - 0x0E : "POLICY_DATA", - 0x0F : "RESV_CONFIRM", - 0x10 : "RSVP_LABEL", - 0x11 : "HOP_COUNT", - 0x12 : "STRICT_SOURCE_ROUTE", - 0x13 : "LABEL_REQUEST", - 0x14 : "EXPLICIT_ROUTE", - 0x15 : "ROUTE_RECORD", - 0x16 : "HELLO", - 0x17 : "MESSAGE_ID", - 0x18 : "MESSAGE_ID_ACK", - 0x19 : "MESSAGE_ID_LIST", - 0x1E : "DIAGNOSTIC", - 0x1F : "ROUTE", - 0x20 : "DIAG_RESPONSE", - 0x21 : "DIAG_SELECT", - 0x22 : "RECOVERY_LABEL", - 0x23 : "UPSTREAM_LABEL", - 0x24 : "LABEL_SET", - 0x25 : "PROTECTION", - 0x26 : "PRIMARY PATH ROUTE", - 0x2A : "DSBM IP ADDRESS", - 0x2B : "SBM_PRIORITY", - 0x2C : "DSBM TIMER INTERVALS", - 0x2D : "SBM_INFO", - 0x32 : "S2L_SUB_LSP", - 0x3F : "DETOUR", - 0x40 : "CHALLENGE", - 0x41 : "DIFF-SERV", - 0x42 : "CLASSTYPE", - 0x43 : "LSP_REQUIRED_ATTRIBUTES", - 0x80 : "NODE_CHAR", - 0x81 : "SUGGESTED_LABEL", - 0x82 : "ACCEPTABLE_LABEL_SET", - 0x83 : "RESTART_CA", - 0x84 : "SESSION-OF-INTEREST", - 0x85 : "LINK_CAPABILITY", - 0x86 : "Capability Object", - 0xA1 : "RSVP_HOP_L2", - 0xA2 : "LAN_NHOP_L2", - 0xA3 : "LAN_NHOP_L3", - 0xA4 : "LAN_LOOPBACK", - 0xA5 : "TCLASS", - 0xC0 : "TUNNEL", - 0xC1 : "LSP_TUNNEL_INTERFACE_ID", - 0xC2 : "USER_ERROR_SPEC", - 0xC3 : "NOTIFY_REQUEST", - 0xC4 : "ADMIN-STATUS", - 0xC5 : "LSP_ATTRIBUTES", - 0xC6 : "ALARM_SPEC", - 0xC7 : "ASSOCIATION", - 0xC8 : "SECONDARY_EXPLICIT_ROUTE", - 0xC9 : "SECONDARY_RECORD_ROUTE", - 0xCD : "FAST_REROUTE", - 0xCF : "SESSION_ATTRIBUTE", - 0xE1 : "DCLASS", - 0xE2 : "PACKETCABLE EXTENSIONS", - 0xE3 : "ATM_SERVICECLASS", - 0xE4 : "CALL_OPS (ASON)", - 0xE5 : "GENERALIZED_UNI", - 0xE6 : "CALL_ID", - 0xE7 : "3GPP2_Object", - 0xE8 : "EXCLUDE_ROUTE" -} - -class RSVP_Object(Packet): - name = "RSVP_Object" - fields_desc = [ ShortField("Length",4), - ByteEnumField("Class",0x01, rsvptypes), - ByteField("C-Type",1)] - def guess_payload_class(self, payload): - if self.Class == 0x03: - return RSVP_HOP - elif self.Class == 0x05: - return RSVP_Time - elif self.Class == 0x0c: - return RSVP_SenderTSPEC - elif self.Class == 0x13: - return RSVP_LabelReq - elif self.Class == 0xCF: - return RSVP_SessionAttrb - else: - return RSVP_Data - - - -class RSVP_Data(Packet): - name = "Data" - fields_desc = [StrLenField("Data","",length_from= lambda pkt:pkt.underlayer.Length - 4)] - def default_payload_class(self, payload): - return RSVP_Object - -class RSVP_HOP(Packet): - name = "HOP" - fields_desc = [ IPField("neighbor","0.0.0.0"), - BitField("inface",1,32)] - def default_payload_class(self, payload): - return RSVP_Object - -class RSVP_Time(Packet): - name = "Time Val" - fields_desc = [ BitField("refresh",1,32)] - def default_payload_class(self, payload): - return RSVP_Object - -class RSVP_SenderTSPEC(Packet): - name = "Sender_TSPEC" - fields_desc = [ ByteField("Msg_Format",0), - ByteField("reserve",0), - ShortField("Data_Length",4), - ByteField("Srv_hdr",1), - ByteField("reserve2",0), - ShortField("Srv_Length",4), - StrLenField("Tokens","",length_from= lambda pkt:pkt.underlayer.Length - 12) ] - def default_payload_class(self, payload): - return RSVP_Object - -class RSVP_LabelReq(Packet): - name = "Lable Req" - fields_desc = [ ShortField("reserve",1), - ShortField("L3PID",1)] - def default_payload_class(self, payload): - return RSVP_Object - -class RSVP_SessionAttrb(Packet): - name = "Session_Attribute" - fields_desc = [ ByteField("Setup_priority",1), - ByteField("Hold_priority",1), - ByteField("flags",1), - ByteField("Name_length",1), - StrLenField("Name","",length_from= lambda pkt:pkt.underlayer.Length - 8), - ] - def default_payload_class(self, payload): - return RSVP_Object - -bind_layers( IP, RSVP, { "proto" : 46} ) -bind_layers( RSVP, RSVP_Object, {}) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/skinny.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/skinny.py deleted file mode 100644 index 47935c9e..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/skinny.py +++ /dev/null @@ -1,499 +0,0 @@ -#! /usr/bin/env python - -# scapy.contrib.description = Skinny Call Control Protocol (SCCP) -# scapy.contrib.status = loads - - -############################################################################# -## ## -## scapy-skinny.py --- Skinny Call Control Protocol (SCCP) extension ## -## ## -## Copyright (C) 2006 Nicolas Bareil <nicolas.bareil@ eads.net> ## -## EADS/CRC security team ## -## ## -## This program is free software; you can redistribute it and/or modify it ## -## under the terms of the GNU General Public License version 2 as ## -## published by the Free Software Foundation; version 2. ## -## ## -## This program is distributed in the hope that it will be useful, but ## -## WITHOUT ANY WARRANTY; without even the implied warranty of ## -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## -## General Public License for more details. ## -## ## -############################################################################# - -from scapy.all import * -import builtins - -##################################################################### -# Helpers and constants -##################################################################### - -skinny_messages_cls = { -# Station -> Callmanager - 0x0000: "SkinnyMessageKeepAlive", - 0x0001: "SkinnyMessageRegister", - 0x0002: "SkinnyMessageIpPort", - 0x0003: "SkinnyMessageKeypadButton", - 0x0004: "SkinnyMessageEnblocCall", - 0x0005: "SkinnyMessageStimulus", - 0x0006: "SkinnyMessageOffHook", - 0x0007: "SkinnyMessageOnHook", - 0x0008: "SkinnyMessageHookFlash", - 0x0009: "SkinnyMessageForwardStatReq", - 0x000A: "SkinnyMessageSpeedDialStatReq", - 0x000B: "SkinnyMessageLineStatReq", - 0x000C: "SkinnyMessageConfigStatReq", - 0x000D: "SkinnyMessageTimeDateReq", - 0x000E: "SkinnyMessageButtonTemplateReq", - 0x000F: "SkinnyMessageVersionReq", - 0x0010: "SkinnyMessageCapabilitiesRes", - 0x0011: "SkinnyMessageMediaPortList", - 0x0012: "SkinnyMessageServerReq", - 0x0020: "SkinnyMessageAlarm", - 0x0021: "SkinnyMessageMulticastMediaReceptionAck", - 0x0022: "SkinnyMessageOpenReceiveChannelAck", - 0x0023: "SkinnyMessageConnectionStatisticsRes", - 0x0024: "SkinnyMessageOffHookWithCgpn", - 0x0025: "SkinnyMessageSoftKeySetReq", - 0x0026: "SkinnyMessageSoftKeyEvent", - 0x0027: "SkinnyMessageUnregister", - 0x0028: "SkinnyMessageSoftKeyTemplateReq", - 0x0029: "SkinnyMessageRegisterTokenReq", - 0x002A: "SkinnyMessageMediaTransmissionFailure", - 0x002B: "SkinnyMessageHeadsetStatus", - 0x002C: "SkinnyMessageMediaResourceNotification", - 0x002D: "SkinnyMessageRegisterAvailableLines", - 0x002E: "SkinnyMessageDeviceToUserData", - 0x002F: "SkinnyMessageDeviceToUserDataResponse", - 0x0030: "SkinnyMessageUpdateCapabilities", - 0x0031: "SkinnyMessageOpenMultiMediaReceiveChannelAck", - 0x0032: "SkinnyMessageClearConference", - 0x0033: "SkinnyMessageServiceURLStatReq", - 0x0034: "SkinnyMessageFeatureStatReq", - 0x0035: "SkinnyMessageCreateConferenceRes", - 0x0036: "SkinnyMessageDeleteConferenceRes", - 0x0037: "SkinnyMessageModifyConferenceRes", - 0x0038: "SkinnyMessageAddParticipantRes", - 0x0039: "SkinnyMessageAuditConferenceRes", - 0x0040: "SkinnyMessageAuditParticipantRes", - 0x0041: "SkinnyMessageDeviceToUserDataVersion1", -# Callmanager -> Station */ - 0x0081: "SkinnyMessageRegisterAck", - 0x0082: "SkinnyMessageStartTone", - 0x0083: "SkinnyMessageStopTone", - 0x0085: "SkinnyMessageSetRinger", - 0x0086: "SkinnyMessageSetLamp", - 0x0087: "SkinnyMessageSetHkFDetect", - 0x0088: "SkinnyMessageSpeakerMode", - 0x0089: "SkinnyMessageSetMicroMode", - 0x008A: "SkinnyMessageStartMediaTransmission", - 0x008B: "SkinnyMessageStopMediaTransmission", - 0x008C: "SkinnyMessageStartMediaReception", - 0x008D: "SkinnyMessageStopMediaReception", - 0x008F: "SkinnyMessageCallInfo", - 0x0090: "SkinnyMessageForwardStat", - 0x0091: "SkinnyMessageSpeedDialStat", - 0x0092: "SkinnyMessageLineStat", - 0x0093: "SkinnyMessageConfigStat", - 0x0094: "SkinnyMessageTimeDate", - 0x0095: "SkinnyMessageStartSessionTransmission", - 0x0096: "SkinnyMessageStopSessionTransmission", - 0x0097: "SkinnyMessageButtonTemplate", - 0x0098: "SkinnyMessageVersion", - 0x0099: "SkinnyMessageDisplayText", - 0x009A: "SkinnyMessageClearDisplay", - 0x009B: "SkinnyMessageCapabilitiesReq", - 0x009C: "SkinnyMessageEnunciatorCommand", - 0x009D: "SkinnyMessageRegisterReject", - 0x009E: "SkinnyMessageServerRes", - 0x009F: "SkinnyMessageReset", - 0x0100: "SkinnyMessageKeepAliveAck", - 0x0101: "SkinnyMessageStartMulticastMediaReception", - 0x0102: "SkinnyMessageStartMulticastMediaTransmission", - 0x0103: "SkinnyMessageStopMulticastMediaReception", - 0x0104: "SkinnyMessageStopMulticastMediaTransmission", - 0x0105: "SkinnyMessageOpenReceiveChannel", - 0x0106: "SkinnyMessageCloseReceiveChannel", - 0x0107: "SkinnyMessageConnectionStatisticsReq", - 0x0108: "SkinnyMessageSoftKeyTemplateRes", - 0x0109: "SkinnyMessageSoftKeySetRes", - 0x0110: "SkinnyMessageSoftKeyEvent", - 0x0111: "SkinnyMessageCallState", - 0x0112: "SkinnyMessagePromptStatus", - 0x0113: "SkinnyMessageClearPromptStatus", - 0x0114: "SkinnyMessageDisplayNotify", - 0x0115: "SkinnyMessageClearNotify", - 0x0116: "SkinnyMessageCallPlane", - 0x0117: "SkinnyMessageCallPlane", - 0x0118: "SkinnyMessageUnregisterAck", - 0x0119: "SkinnyMessageBackSpaceReq", - 0x011A: "SkinnyMessageRegisterTokenAck", - 0x011B: "SkinnyMessageRegisterTokenReject", - 0x0042: "SkinnyMessageDeviceToUserDataResponseVersion1", - 0x011C: "SkinnyMessageStartMediaFailureDetection", - 0x011D: "SkinnyMessageDialedNumber", - 0x011E: "SkinnyMessageUserToDeviceData", - 0x011F: "SkinnyMessageFeatureStat", - 0x0120: "SkinnyMessageDisplayPriNotify", - 0x0121: "SkinnyMessageClearPriNotify", - 0x0122: "SkinnyMessageStartAnnouncement", - 0x0123: "SkinnyMessageStopAnnouncement", - 0x0124: "SkinnyMessageAnnouncementFinish", - 0x0127: "SkinnyMessageNotifyDtmfTone", - 0x0128: "SkinnyMessageSendDtmfTone", - 0x0129: "SkinnyMessageSubscribeDtmfPayloadReq", - 0x012A: "SkinnyMessageSubscribeDtmfPayloadRes", - 0x012B: "SkinnyMessageSubscribeDtmfPayloadErr", - 0x012C: "SkinnyMessageUnSubscribeDtmfPayloadReq", - 0x012D: "SkinnyMessageUnSubscribeDtmfPayloadRes", - 0x012E: "SkinnyMessageUnSubscribeDtmfPayloadErr", - 0x012F: "SkinnyMessageServiceURLStat", - 0x0130: "SkinnyMessageCallSelectStat", - 0x0131: "SkinnyMessageOpenMultiMediaChannel", - 0x0132: "SkinnyMessageStartMultiMediaTransmission", - 0x0133: "SkinnyMessageStopMultiMediaTransmission", - 0x0134: "SkinnyMessageMiscellaneousCommand", - 0x0135: "SkinnyMessageFlowControlCommand", - 0x0136: "SkinnyMessageCloseMultiMediaReceiveChannel", - 0x0137: "SkinnyMessageCreateConferenceReq", - 0x0138: "SkinnyMessageDeleteConferenceReq", - 0x0139: "SkinnyMessageModifyConferenceReq", - 0x013A: "SkinnyMessageAddParticipantReq", - 0x013B: "SkinnyMessageDropParticipantReq", - 0x013C: "SkinnyMessageAuditConferenceReq", - 0x013D: "SkinnyMessageAuditParticipantReq", - 0x013F: "SkinnyMessageUserToDeviceDataVersion1", - } - -skinny_callstates = { - 0x1: "Off Hook", - 0x2: "On Hook", - 0x3: "Ring out", - 0xc: "Proceeding", -} - - -skinny_ring_type = { - 0x1: "Ring off" -} - -skinny_speaker_modes = { - 0x1: "Speaker on", - 0x2: "Speaker off" -} - -skinny_lamp_mode = { - 0x1: "Off (?)", - 0x2: "On", -} - -skinny_stimulus = { - 0x9: "Line" -} - - -############ -## Fields ## -############ - -class SkinnyDateTimeField(StrFixedLenField): - def __init__(self, name, default): - StrFixedLenField.__init__(self, name, default, 32) - - def m2i(self, pkt, s): - year,month,dow,day,hour,min,sec,milisecond=struct.unpack('<8I', s) - return (year, month, day, hour, min, sec) - - def i2m(self, pkt, val): - if type(val) is str: - val = self.h2i(pkt, val) - l= val[:2] + (0,) + val[2:7] + (0,) - return struct.pack('<8I', *l) - - def i2h(self, pkt, x): - if type(x) is str: - return x - else: - return time.ctime(time.mktime(x+(0,0,0))) - - def i2repr(self, pkt, x): - return self.i2h(pkt, x) - - def h2i(self, pkt, s): - t = () - if type(s) is str: - t = time.strptime(s) - t = t[:2] + t[2:-3] - else: - if not s: - y,m,d,h,min,sec,rest,rest,rest = time.gmtime(time.time()) - t = (y,m,d,h,min,sec) - else: - t=s - return t - - -########################### -## Packet abstract class ## -########################### - -class SkinnyMessageGeneric(Packet): - name='Generic message' - -class SkinnyMessageKeepAlive(Packet): - name='keep alive' - -class SkinnyMessageKeepAliveAck(Packet): - name='keep alive ack' - -class SkinnyMessageOffHook(Packet): - name = 'Off Hook' - fields_desc = [ LEIntField("unknown1", 0), - LEIntField("unknown2", 0),] - -class SkinnyMessageOnHook(SkinnyMessageOffHook): - name = 'On Hook' - -class SkinnyMessageCallState(Packet): - name='Skinny Call state message' - fields_desc = [ LEIntEnumField("state", 1, skinny_callstates), - LEIntField("instance", 1), - LEIntField("callid", 0), - LEIntField("unknown1", 4), - LEIntField("unknown2", 0), - LEIntField("unknown3", 0) ] - -class SkinnyMessageSoftKeyEvent(Packet): - name='Soft Key Event' - fields_desc = [ LEIntField("key", 0), - LEIntField("instance", 1), - LEIntField("callid", 0)] - -class SkinnyMessageSetRinger(Packet): - name='Ring message' - fields_desc = [ LEIntEnumField("ring", 0x1, skinny_ring_type), - LEIntField("unknown1", 0), - LEIntField("unknown2", 0), - LEIntField("unknown3", 0) ] - -_skinny_tones = { - 0x21: 'Inside dial tone', - 0x22: 'xxx', - 0x23: 'xxx', - 0x24: 'Alerting tone', - 0x25: 'Reorder Tone' - } - -class SkinnyMessageStartTone(Packet): - name='Start tone' - fields_desc = [ LEIntEnumField("tone", 0x21, _skinny_tones), - LEIntField("unknown1", 0), - LEIntField("instance", 1), - LEIntField("callid", 0)] - -class SkinnyMessageStopTone(SkinnyMessageGeneric): - name='stop tone' - fields_desc = [ LEIntField("instance", 1), - LEIntField("callid", 0)] - - -class SkinnyMessageSpeakerMode(Packet): - name='Speaker mdoe' - fields_desc = [ LEIntEnumField("ring", 0x1, skinny_speaker_modes) ] - -class SkinnyMessageSetLamp(Packet): - name='Lamp message (light of the phone)' - fields_desc = [ LEIntEnumField("stimulus", 0x5, skinny_stimulus), - LEIntField("instance", 1), - LEIntEnumField("mode", 2, skinny_lamp_mode) ] - -class SkinnyMessageSoftKeyEvent(Packet): - name=' Call state message' - fields_desc = [ LEIntField("instance", 1), - LEIntField("callid", 0), - LEIntField("set", 0), - LEIntField("map", 0xffff)] - -class SkinnyMessagePromptStatus(Packet): - name='Prompt status' - fields_desc = [ LEIntField("timeout", 0), - StrFixedLenField("text", "\0"*32, 32), - LEIntField("instance", 1), - LEIntField("callid", 0)] - -class SkinnyMessageCallPlane(Packet): - name='Activate/Desactivate Call Plane Message' - fields_desc = [ LEIntField("instance", 1)] - -class SkinnyMessageTimeDate(Packet): - name='Setting date and time' - fields_desc = [ SkinnyDateTimeField("settime", None), - LEIntField("timestamp", 0) ] - -class SkinnyMessageClearPromptStatus(Packet): - name='clear prompt status' - fields_desc = [ LEIntField("instance", 1), - LEIntField("callid", 0)] - -class SkinnyMessageKeypadButton(Packet): - name='keypad button' - fields_desc = [ LEIntField("key", 0), - LEIntField("instance", 1), - LEIntField("callid", 0)] - -class SkinnyMessageDialedNumber(Packet): - name='dialed number' - fields_desc = [ StrFixedLenField("number", "1337", 24), - LEIntField("instance", 1), - LEIntField("callid", 0)] - -_skinny_message_callinfo_restrictions = ['CallerName' - , 'CallerNumber' - , 'CalledName' - , 'CalledNumber' - , 'OriginalCalledName' - , 'OriginalCalledNumber' - , 'LastRedirectName' - , 'LastRedirectNumber'] + ['Bit%d' % i for i in range(8,15)] -class SkinnyMessageCallInfo(Packet): - name='call information' - fields_desc = [ StrFixedLenField("callername", "Jean Valjean", 40), - StrFixedLenField("callernum", "1337", 24), - StrFixedLenField("calledname", "Causette", 40), - StrFixedLenField("callednum", "1034", 24), - LEIntField("lineinstance", 1), - LEIntField("callid", 0), - StrFixedLenField("originalcalledname", "Causette", 40), - StrFixedLenField("originalcallednum", "1034", 24), - StrFixedLenField("lastredirectingname", "Causette", 40), - StrFixedLenField("lastredirectingnum", "1034", 24), - LEIntField("originalredirectreason", 0), - LEIntField("lastredirectreason", 0), - StrFixedLenField('voicemailboxG', '\0'*24, 24), - StrFixedLenField('voicemailboxD', '\0'*24, 24), - StrFixedLenField('originalvoicemailboxD', '\0'*24, 24), - StrFixedLenField('lastvoicemailboxD', '\0'*24, 24), - LEIntField('security', 0), - FlagsField('restriction', 0, 16, _skinny_message_callinfo_restrictions), - LEIntField('unknown', 0)] - - -class SkinnyRateField(LEIntField): - def i2repr(self, pkt, x): - if x is None: - x=0 - return '%d ms/pkt' % x - -_skinny_codecs = { - 0x0: 'xxx', - 0x1: 'xxx', - 0x2: 'xxx', - 0x3: 'xxx', - 0x4: 'G711 ulaw 64k' - } - -_skinny_echo = { - 0x0: 'echo cancelation off', - 0x1: 'echo cancelation on' - } - -class SkinnyMessageOpenReceiveChannel(Packet): - name='open receive channel' - fields_desc = [LEIntField('conference', 0), - LEIntField('passthru', 0), - SkinnyRateField('rate', 20), - LEIntEnumField('codec', 4, _skinny_codecs), - LEIntEnumField('echo', 0, _skinny_echo), - LEIntField('unknown1', 0), - LEIntField('callid', 0)] - - def guess_payload_class(self, p): - return conf.padding_layer - -_skinny_receive_channel_status = { - 0x0: 'ok', - 0x1: 'ko' - } - -class SkinnyMessageOpenReceiveChannelAck(Packet): - name='open receive channel' - fields_desc = [LEIntEnumField('status', 0, _skinny_receive_channel_status), - IPField('remote', '0.0.0.0'), - LEIntField('port', RandShort()), - LEIntField('passthru', 0), - LEIntField('callid', 0)] - -_skinny_silence = { - 0x0: 'silence suppression off', - 0x1: 'silence suppression on', - } - -class SkinnyFramePerPacketField(LEIntField): - def i2repr(self, pkt, x): - if x is None: - x=0 - return '%d frames/pkt' % x - -class SkinnyMessageStartMediaTransmission(Packet): - name='start multimedia transmission' - fields_desc = [LEIntField('conference', 0), - LEIntField('passthru', 0), - IPField('remote', '0.0.0.0'), - LEIntField('port', RandShort()), - SkinnyRateField('rate', 20), - LEIntEnumField('codec', 4, _skinny_codecs), - LEIntField('precedence', 200), - LEIntEnumField('silence', 0, _skinny_silence), - SkinnyFramePerPacketField('maxframes', 0), - LEIntField('unknown1', 0), - LEIntField('callid', 0)] - - def guess_payload_class(self, p): - return conf.padding_layer - -class SkinnyMessageCloseReceiveChannel(Packet): - name='close receive channel' - fields_desc = [LEIntField('conference', 0), - LEIntField('passthru', 0), - IPField('remote', '0.0.0.0'), - LEIntField('port', RandShort()), - SkinnyRateField('rate', 20), - LEIntEnumField('codec', 4, _skinny_codecs), - LEIntField('precedence', 200), - LEIntEnumField('silence', 0, _skinny_silence), - LEIntField('callid', 0)] - -class SkinnyMessageStopMultiMediaTransmission(Packet): - name='stop multimedia transmission' - fields_desc = [LEIntField('conference', 0), - LEIntField('passthru', 0), - LEIntField('callid', 0)] - -class Skinny(Packet): - name="Skinny" - fields_desc = [ LEIntField("len", None), - LEIntField("res",0), - LEIntEnumField("msg",0, skinny_messages) ] - - def post_build(self, pkt, p): - if self.len is None: - l=len(p)+len(pkt)-8 # on compte pas les headers len et reserved - pkt=struct.pack('@I', l)+pkt[4:] - return pkt+p - -# An helper -def get_cls(name, fallback_cls): - return globals().get(name, fallback_cls) - #return builtins.__dict__.get(name, fallback_cls) - -for msgid,strcls in skinny_messages_cls.items(): - cls=get_cls(strcls, SkinnyMessageGeneric) - bind_layers(Skinny, cls, {"msg": msgid}) - -bind_layers(TCP, Skinny, { "dport": 2000 } ) -bind_layers(TCP, Skinny, { "sport": 2000 } ) - -if __name__ == "__main__": - interact(mydict=globals(),mybanner="Welcome to Skinny add-on") - diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ubberlogger.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ubberlogger.py deleted file mode 100644 index 1c01db2f..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/ubberlogger.py +++ /dev/null @@ -1,101 +0,0 @@ -# Author: Sylvain SARMEJEANNE -# http://trac.secdev.org/scapy/ticket/1 - -# scapy.contrib.description = Ubberlogger dissectors -# scapy.contrib.status = untested - -from scapy.packet import * -from scapy.fields import * - -# Syscalls known by Uberlogger -uberlogger_sys_calls = {0:"READ_ID", - 1:"OPEN_ID", - 2:"WRITE_ID", - 3:"CHMOD_ID", - 4:"CHOWN_ID", - 5:"SETUID_ID", - 6:"CHROOT_ID", - 7:"CREATE_MODULE_ID", - 8:"INIT_MODULE_ID", - 9:"DELETE_MODULE_ID", - 10:"CAPSET_ID", - 11:"CAPGET_ID", - 12:"FORK_ID", - 13:"EXECVE_ID"} - -# First part of the header -class Uberlogger_honeypot_caract(Packet): - name = "Uberlogger honeypot_caract" - fields_desc = [ByteField("honeypot_id", 0), - ByteField("reserved", 0), - ByteField("os_type_and_version", 0)] - -# Second part of the header -class Uberlogger_uber_h(Packet): - name = "Uberlogger uber_h" - fields_desc = [ByteEnumField("syscall_type", 0, uberlogger_sys_calls), - IntField("time_sec", 0), - IntField("time_usec", 0), - IntField("pid", 0), - IntField("uid", 0), - IntField("euid", 0), - IntField("cap_effective", 0), - IntField("cap_inheritable", 0), - IntField("cap_permitted", 0), - IntField("res", 0), - IntField("length", 0)] - -# The 9 following classes are options depending on the syscall type -class Uberlogger_capget_data(Packet): - name = "Uberlogger capget_data" - fields_desc = [IntField("target_pid", 0)] - -class Uberlogger_capset_data(Packet): - name = "Uberlogger capset_data" - fields_desc = [IntField("target_pid", 0), - IntField("effective_cap", 0), - IntField("permitted_cap", 0), - IntField("inheritable_cap", 0)] - -class Uberlogger_chmod_data(Packet): - name = "Uberlogger chmod_data" - fields_desc = [ShortField("mode", 0)] - -class Uberlogger_chown_data(Packet): - name = "Uberlogger chown_data" - fields_desc = [IntField("uid", 0), - IntField("gid", 0)] - -class Uberlogger_open_data(Packet): - name = "Uberlogger open_data" - fields_desc = [IntField("flags", 0), - IntField("mode", 0)] - -class Uberlogger_read_data(Packet): - name = "Uberlogger read_data" - fields_desc = [IntField("fd", 0), - IntField("count", 0)] - -class Uberlogger_setuid_data(Packet): - name = "Uberlogger setuid_data" - fields_desc = [IntField("uid", 0)] - -class Uberlogger_create_module_data(Packet): - name = "Uberlogger create_module_data" - fields_desc = [IntField("size", 0)] - -class Uberlogger_execve_data(Packet): - name = "Uberlogger execve_data" - fields_desc = [IntField("nbarg", 0)] - -# Layer bounds for Uberlogger -bind_layers(Uberlogger_honeypot_caract,Uberlogger_uber_h) -bind_layers(Uberlogger_uber_h,Uberlogger_capget_data) -bind_layers(Uberlogger_uber_h,Uberlogger_capset_data) -bind_layers(Uberlogger_uber_h,Uberlogger_chmod_data) -bind_layers(Uberlogger_uber_h,Uberlogger_chown_data) -bind_layers(Uberlogger_uber_h,Uberlogger_open_data) -bind_layers(Uberlogger_uber_h,Uberlogger_read_data) -bind_layers(Uberlogger_uber_h,Uberlogger_setuid_data) -bind_layers(Uberlogger_uber_h,Uberlogger_create_module_data) -bind_layers(Uberlogger_uber_h,Uberlogger_execve_data) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/vqp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/vqp.py deleted file mode 100644 index 9328cea4..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/vqp.py +++ /dev/null @@ -1,58 +0,0 @@ - -# http://trac.secdev.org/scapy/ticket/147 - -# scapy.contrib.description = VLAN Query Protocol -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.inet import UDP - -class VQP(Packet): - name = "VQP" - fields_desc = [ - ByteField("const", 1), - ByteEnumField("type", 1, { - 1:"requestPort", 2:"responseVLAN", - 3:"requestReconfirm", 4:"responseReconfirm" - }), - ByteEnumField("errorcodeaction", 0, { - 0:"none",3:"accessDenied", - 4:"shutdownPort", 5:"wrongDomain" - }), - ByteEnumField("unknown", 2, { - 2:"inGoodResponse", 6:"inRequests" - }), - IntField("seq",0), - ] - -class VQPEntry(Packet): - name = "VQPEntry" - fields_desc = [ - IntEnumField("datatype", 0, { - 3073:"clientIPAddress", 3074:"portName", - 3075:"VLANName", 3076:"Domain", 3077:"ethernetPacket", - 3078:"ReqMACAddress", 3079:"unknown", - 3080:"ResMACAddress" - }), - FieldLenField("len", None), - ConditionalField(IPField("datatom", "0.0.0.0"), - lambda p:p.datatype==3073), - ConditionalField(MACField("data", "00:00:00:00:00:00"), - lambda p:p.datatype==3078), - ConditionalField(MACField("data", "00:00:00:00:00:00"), - lambda p:p.datatype==3080), - ConditionalField(StrLenField("data", None, - length_from=lambda p:p.len), - lambda p:p.datatype not in [3073, 3078, 3080]), - ] - def post_build(self, p, pay): - if self.len is None: - l = len(p.data) - p = p[:2]+struct.pack("!H",l)+p[4:] - return p - -bind_layers(UDP, VQP, sport=1589) -bind_layers(UDP, VQP, dport=1589) -bind_layers(VQP, VQPEntry, ) -bind_layers(VQPEntry, VQPEntry, ) diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/vtp.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/vtp.py deleted file mode 100644 index af5c2823..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/vtp.py +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env python - -# scapy.contrib.description = VLAN Trunking Protocol (VTP) -# scapy.contrib.status = loads - -""" - VTP Scapy Extension - ~~~~~~~~~~~~~~~~~~~~~ - - :version: 2009-02-15 - :copyright: 2009 by Jochen Bartl - :e-mail: lobo@c3a.de / jochen.bartl@gmail.com - :license: GPL v2 - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - :TODO - - - Join messages - - RE MD5 hash calculation - - Have a closer look at 8 byte padding in summary adv. - "debug sw-vlan vtp packets" sais the TLV length is invalid, - when I change the values - '\x00\x00\x00\x01\x06\x01\x00\x02' - * \x00\x00 ? - * \x00\x01 tlvtype? - * \x06 length? - * \x00\x02 value? - - h2i function for VTPTimeStampField - - :References: - - - Understanding VLAN Trunk Protocol (VTP) - http://www.cisco.com/en/US/tech/tk389/tk689/technologies_tech_note09186a0080094c52.shtml -""" - -from scapy.all import * - -_VTP_VLAN_TYPE = { - 1 : 'Ethernet', - 2 : 'FDDI', - 3 : 'TrCRF', - 4 : 'FDDI-net', - 5 : 'TrBRF' - } - -_VTP_VLANINFO_TLV_TYPE = { - 0x01 : 'Source-Routing Ring Number', - 0x02 : 'Source-Routing Bridge Number', - 0x03 : 'Spanning-Tree Protocol Type', - 0x04 : 'Parent VLAN', - 0x05 : 'Translationally Bridged VLANs', - 0x06 : 'Pruning', - 0x07 : 'Bridge Type', - 0x08 : 'Max ARE Hop Count', - 0x09 : 'Max STE Hop Count', - 0x0A : 'Backup CRF Mode' - } - - -class VTPVlanInfoTlv(Packet): - name = "VTP VLAN Info TLV" - fields_desc = [ - ByteEnumField("type", 0, _VTP_VLANINFO_TLV_TYPE), - ByteField("length", 0), - StrLenField("value", None, length_from=lambda pkt : pkt.length + 1) - ] - - def guess_payload_class(self, p): - return conf.padding_layer - -class VTPVlanInfo(Packet): - name = "VTP VLAN Info" - fields_desc = [ - ByteField("len", None), # FIXME: compute length - ByteEnumField("status", 0, {0 : "active", 1 : "suspended"}), - ByteEnumField("type", 1, _VTP_VLAN_TYPE), - FieldLenField("vlannamelen", None, "vlanname", "B"), - ShortField("vlanid", 1), - ShortField("mtu", 1500), - XIntField("dot10index", None), - StrLenField("vlanname", "default", length_from=lambda pkt:4 * ((pkt.vlannamelen + 3) / 4)), - ConditionalField(PacketListField("tlvlist", [], VTPVlanInfoTlv, - length_from=lambda pkt:pkt.len - 12 - (4 * ((pkt.vlannamelen + 3) / 4))), - lambda pkt:pkt.type not in [1, 2]) - ] - - def post_build(self, p, pay): - vlannamelen = 4 * ((len(self.vlanname) + 3) / 4) - - if self.len == None: - l = vlannamelen + 12 - p = chr(l & 0xff) + p[1:] - - # Pad vlan name with zeros if vlannamelen > len(vlanname) - l = vlannamelen - len(self.vlanname) - if l != 0: - p += "\x00" * l - - p += pay - - return p - - def guess_payload_class(self, p): - return conf.padding_layer - -_VTP_Types = { - 1 : 'Summary Advertisement', - 2 : 'Subset Advertisements', - 3 : 'Advertisement Request', - 4 : 'Join' - } - -class VTPTimeStampField(StrFixedLenField): - def __init__(self, name, default): - StrFixedLenField.__init__(self, name, default, 12) - - def i2repr(self, pkt, x): - return "%s-%s-%s %s:%s:%s" % (x[:2], x[2:4], x[4:6], x[6:8], x[8:10], x[10:12]) - -class VTP(Packet): - name = "VTP" - fields_desc = [ - ByteField("ver", 2), - ByteEnumField("code", 1, _VTP_Types), - ConditionalField(ByteField("followers", 1), - lambda pkt:pkt.code == 1), - ConditionalField(ByteField("seq", 1), - lambda pkt:pkt.code == 2), - ConditionalField(ByteField("reserved", 0), - lambda pkt:pkt.code == 3), - ByteField("domnamelen", None), - StrFixedLenField("domname", "manbearpig", 32), - ConditionalField(SignedIntField("rev", 0), - lambda pkt:pkt.code == 1 or - pkt.code == 2), - # updater identity - ConditionalField(IPField("uid", "192.168.0.1"), - lambda pkt:pkt.code == 1), - ConditionalField(VTPTimeStampField("timestamp", '930301000000'), - lambda pkt:pkt.code == 1), - ConditionalField(StrFixedLenField("md5", "\x00" * 16, 16), - lambda pkt:pkt.code == 1), - ConditionalField( - PacketListField("vlaninfo", [], VTPVlanInfo), - lambda pkt: pkt.code == 2), - ConditionalField(ShortField("startvalue", 0), - lambda pkt:pkt.code == 3) - ] - - def post_build(self, p, pay): - if self.domnamelen == None: - domnamelen = len(self.domname.strip("\x00")) - p = p[:3] + chr(domnamelen & 0xff) + p[4:] - - p += pay - - return p - -bind_layers(SNAP, VTP, code=0x2003) - -if __name__ == '__main__': - interact(mydict=globals(), mybanner="VTP") diff --git a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/wpa_eapol.py b/scripts/external_libs/scapy-python3-0.18/scapy/contrib/wpa_eapol.py deleted file mode 100644 index 084eedd8..00000000 --- a/scripts/external_libs/scapy-python3-0.18/scapy/contrib/wpa_eapol.py +++ /dev/null @@ -1,35 +0,0 @@ - -# http://trac.secdev.org/scapy/ticket/104 - -# scapy.contrib.description = WPA EAPOL dissector -# scapy.contrib.status = loads - -from scapy.packet import * -from scapy.fields import * -from scapy.layers.l2 import * - -class WPA_key(Packet): - name = "WPA_key" - fields_desc = [ ByteField("descriptor_type", 1), - ShortField("key_info",0), - LenField("len", None, "H"), - StrFixedLenField("replay_counter", "", 8), - StrFixedLenField("nonce", "", 32), - StrFixedLenField("key_iv", "", 16), - StrFixedLenField("wpa_key_rsc", "", 8), - StrFixedLenField("wpa_key_id", "", 8), - StrFixedLenField("wpa_key_mic", "", 16), - LenField("wpa_key_length", None, "H"), - StrLenField("wpa_key", "", length_from=lambda pkt:pkt.wpa_key_length) ] - def extract_padding(self, s): - l = self.len - return s[:l],s[l:] - def hashret(self): - return chr(self.type)+self.payload.hashret() - def answers(self, other): - if isinstance(other,WPA_key): - return 1 - return 0 - - -bind_layers( EAPOL, WPA_key, type=3) |