Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fields_desc = [
BitEnumField('_type', 0x07, 7, LLDPDU.TYPES),
BitFieldLenField('_length', 4, 9),
BitField('reserved_5_available', 0, 1),
BitField('reserved_4_available', 0, 1),
BitField('reserved_3_available', 0, 1),
BitField('reserved_2_available', 0, 1),
BitField('reserved_1_available', 0, 1),
BitField('two_port_mac_relay_available', 0, 1),
BitField('s_vlan_component_available', 0, 1),
BitField('c_vlan_component_available', 0, 1),
BitField('station_only_available', 0, 1),
BitField('docsis_cable_device_available', 0, 1),
BitField('telephone_available', 0, 1),
BitField('router_available', 0, 1),
BitField('wlan_access_point_available', 0, 1),
BitField('mac_bridge_available', 0, 1),
BitField('repeater_available', 0, 1),
BitField('other_available', 0, 1),
BitField('reserved_5_enabled', 0, 1),
BitField('reserved_4_enabled', 0, 1),
BitField('reserved_3_enabled', 0, 1),
BitField('reserved_2_enabled', 0, 1),
BitField('reserved_1_enabled', 0, 1),
BitField('two_port_mac_relay_enabled', 0, 1),
BitField('s_vlan_component_enabled', 0, 1),
BitField('c_vlan_component_enabled', 0, 1),
BitField('station_only_enabled', 0, 1),
BitField('docsis_cable_device_enabled', 0, 1),
BitField('telephone_enabled', 0, 1),
BitField('router_enabled', 0, 1),
BitField('wlan_access_point_enabled', 0, 1),
XShortEnumField("proto", 0x800, ETHER_TYPES)]
class SNAP(Packet):
name = "SNAP"
fields_desc = [X3BytesField("OUI", 0x000000),
XShortEnumField("code", 0x000, ETHER_TYPES)]
conf.neighbor.register_l3(Dot3, SNAP, l2_register_l3)
class Dot1Q(Packet):
name = "802.1Q"
aliastypes = [Ether]
fields_desc = [BitField("prio", 0, 3),
BitField("id", 0, 1),
BitField("vlan", 1, 12),
XShortEnumField("type", 0x0000, ETHER_TYPES)]
def answers(self, other):
if isinstance(other, Dot1Q):
if ((self.type == other.type) and
(self.vlan == other.vlan)):
return self.payload.answers(other.payload)
else:
return self.payload.answers(other)
return 0
def default_payload_class(self, pay):
if self.type <= 1500:
return LLC
ECA(ByteField("snap_action", None), {AA.W}),
ECA(ByteField("most_recent_status_snapshot", None), {AA.R}), # TODO: N field
ECA(ByteField("reset_action", None), {AA.W}),
]
mandatory_operations = {OP.Get, OP.Set, OP.GetNext}
class AdtnVlanTaggingOperation(Packet):
name = "VlanTaggingOperation"
fields_desc = [
BitField("filter_outer_priority", 0, 4),
BitField("filter_outer_vid", 0, 13),
BitField("filter_outer_tpid_de", 0, 3),
BitField("pad1", 0, 12),
BitField("filter_inner_priority", 0, 4),
BitField("filter_inner_vid", 0, 13),
BitField("filter_inner_tpid_de", 0, 3),
BitField("pad2", 0, 8),
BitField("filter_ether_type", 0, 4),
BitField("treatment_tags_to_remove", 0, 2),
BitField("pad3", 0, 10),
BitField("treatment_outer_priority", 0, 4),
BitField("treatment_outer_vid", 0, 13),
BitField("treatment_outer_tpid_de", 0, 3),
BitField("pad4", 0, 12),
BitField("treatment_inner_priority", 0, 4),
BitField("treatment_inner_vid", 0, 13),
BitField("treatment_inner_tpid_de", 0, 3),
]
GEN_FLAG_SUBSTITUTED_TIME: 'substituted time'
}
SU_FLAG_NORMAL_TIME = 0
SU_FLAG_SUMMER_TIME = 1
SU_FLAGS = {
SU_FLAG_NORMAL_TIME: 'normal time',
SU_FLAG_SUMMER_TIME: 'summer time'
}
informantion_element_fields = [
LEShortField('sec_milli', 0),
BitEnumField('iv', 0, 1, IEC104_IE_CommonQualityFlags.IV_FLAGS),
BitEnumField('gen', 0, 1, GEN_FLAGS),
# only valid in monitor direction ToDo: special treatment needed?
BitField('minutes', 0, 6),
BitEnumField('su', 0, 1, SU_FLAGS),
BitField('reserved_2', 0, 2),
BitField('hours', 0, 5),
BitEnumField('weekday', 0, 3, WEEK_DAY_FLAGS),
BitField('day-of-month', 0, 5),
BitField('reserved_3', 0, 4),
BitField('month', 0, 4),
BitField('reserved_4', 0, 1),
BitField('year', 0, 7),
]
class IEC104_IE_CP56TIME2A_START_TIME(IEC104_IE_CP56TIME2A):
"""
derived IE, used for ASDU that requires two CP56TIME2A timestamps for
defining a range
class EAP_PEAP(EAP):
"""
draft-josefsson-pppext-eap-tls-eap-05.txt - "Protected EAP Protocol (PEAP)"
"""
name = "PEAP"
fields_desc = [
ByteEnumField("code", 1, eap_codes),
ByteField("id", 0),
FieldLenField("len", None, fmt="H", length_of="tls_data",
adjust=lambda p, x: x + 10 if p.L == 1 else x + 6),
ByteEnumField("type", 25, eap_types),
BitField("L", 0, 1),
BitField("M", 0, 1),
BitField("S", 0, 1),
BitField("reserved", 0, 3),
BitField("version", 1, 2),
ConditionalField(IntField("tls_message_len", 0), lambda pkt: pkt.L == 1), # noqa: E501
XStrLenField("tls_data", "", length_from=lambda pkt: 0 if pkt.len is None else pkt.len - (6 + 4 * pkt.L)) # noqa: E501
]
class EAP_FAST(EAP):
"""
RFC 4851 - "The Flexible Authentication via Secure Tunneling
Extensible Authentication Protocol Method (EAP-FAST)"
"""
name = "EAP-FAST"
fields_desc = [
ByteEnumField("code", 1, eap_codes),
ByteField("id", 0),
BitField("R3INFO_USERID", 0, 1), # 63
BitField("CHECKRADIO_EVENTS", 0, 1), # 62
BitField("R3INFO_FLAGS", 0, 1), # 61
BitField("COMBOBOX_TABLE", 0, 1), # 60
BitField("ISO_LANGUAGE", 0, 1), # 59
BitField("INPUT_REQUIRED", 0, 1), # 58
BitField("COMBOBOX", 0, 1), # 57
BitField("TYPE_SERVER", 0, 1), # 56
BitField("LABEL_OWNER", 0, 1), # 71
BitField("EVENT_DESCRIPTION", 0, 1), # 70
BitField("SCROLLABLE_TABSTRIP_PAGE", 0, 1), # 69
BitField("CONTEXT_MENU", 0, 1), # 68
BitField("WIN16", 0, 1), # 67
BitField("NUM_FIELD", 0, 1), # 66
BitField("USER_TURNTIME2", 0, 1), # 65
BitField("R3INFO_ROLLCOUNT", 0, 1), # 64
BitField("NOTGUI", 0, 1), # 79
BitField("R3INFO_IMODEUUID", 0, 1), # 78
BitField("VARINFO_CONTAINER", 0, 1), # 77
BitField("PROPFONT_VALID", 0, 1), # 76
BitField("TABLE_ROW_REFERENCES_2", 0, 1), # 75
BitField("UNUSED_1", 0, 1), # 74
BitField("PROPERTY_BAG", 0, 1), # 73
BitField("CLICKABLE_FIELD", 0, 1), # 72
BitField("ENJOY_IMODEUUID", 0, 1), # 87
BitField("CTL_PROPCACHE", 0, 1), # 86
BitField("DPLOADONDEMAND", 0, 1), # 85
BitField("JAVA_BEANS", 0, 1), # 84
ShortField("max_simultaneous_groups", None),
IntField("max_multicast_bw", None),
ShortField("mcast_operations_profile_pointer", None),
StrFixedLenField("reserved1", None, 8)
]
def to_json(self):
return json.dumps(self.fields, separators=(',', ':'))
class AllowedPreviewGroupsRow0(Packet):
name = "AllowedPreviewGroupsRow0"
fields_desc = [
BitField("set_ctrl", 0, 2),
BitField("row_part_id", 0, 3),
BitField("reserved0", 0, 1),
BitField("row_key", 0, 10),
StrFixedLenField("ipv6_pad", 0, 12),
IPField("src_ip", None),
ShortField("vlan_id_ani", None),
ShortField("vlan_id_uni", None)
]
def to_json(self):
return json.dumps(self.fields, separators=(',', ':'))
class AllowedPreviewGroupsRow1(Packet):
name = "AllowedPreviewGroupsRow1"
fields_desc = [
BitField("set_ctrl", 0, 2),
class Dot15d4Beacon(Packet):
name = "802.15.4 Beacon"
fields_desc = [
XLEShortField("src_panid", 0x0),
dot15d4AddressField("src_addr", None, length_of="fcf_srcaddrmode"),
# Security field present if fcf_security == True
ConditionalField(PacketField("aux_sec_header", Dot15d4AuxSecurityHeader(), Dot15d4AuxSecurityHeader), # noqa: E501
lambda pkt:pkt.underlayer.getfieldval("fcf_security") is True), # noqa: E501
# Superframe spec field:
BitField("sf_sforder", 15, 4), # not used by ZigBee
BitField("sf_beaconorder", 15, 4), # not used by ZigBee
BitEnumField("sf_assocpermit", 0, 1, [False, True]),
BitEnumField("sf_pancoord", 0, 1, [False, True]),
BitField("sf_reserved", 0, 1), # not used by ZigBee
BitEnumField("sf_battlifeextend", 0, 1, [False, True]), # not used by ZigBee # noqa: E501
BitField("sf_finalcapslot", 15, 4), # not used by ZigBee
# GTS Fields
# GTS Specification (1 byte)
BitEnumField("gts_spec_permit", 1, 1, [False, True]), # GTS spec bit 7, true=1 iff PAN cord is accepting GTS requests # noqa: E501
BitField("gts_spec_reserved", 0, 4), # GTS spec bits 3-6
BitField("gts_spec_desccount", 0, 3), # GTS spec bits 0-2
# GTS Directions (0 or 1 byte)
ConditionalField(BitField("gts_dir_reserved", 0, 1), lambda pkt:pkt.getfieldval("gts_spec_desccount") != 0), # noqa: E501
ConditionalField(BitField("gts_dir_mask", 0, 7), lambda pkt:pkt.getfieldval("gts_spec_desccount") != 0), # noqa: E501
# GTS List (variable size)
# TODO add a Packet/FieldListField tied to 3bytes per count in gts_spec_desccount # noqa: E501
# Pending Address Fields:
# Pending Address Specification (1 byte)
l_pay = len(pay)
else:
l_pay = 0
p = p[:1] + chb(l_pay & 0x3f) + p[2:]
if not isinstance(self.underlayer, BTLE):
self.add_underlayer(BTLE)
return p
class BTLE_DATA(Packet):
name = "BTLE data header"
fields_desc = [
BitField("RFU", 0, 3), # Unused
BitField("MD", 0, 1),
BitField("SN", 0, 1),
BitField("NESN", 0, 1),
BitEnumField("LLID", 0, 2, {1: "continue", 2: "start", 3: "control"}),
ByteField("len", None),
]
def post_build(self, p, pay):
if self.len is None:
p = p[:-1] + chb(len(pay))
return p + pay
class BTLE_ADV_IND(Packet):
name = "BTLE ADV_IND"
fields_desc = [
BDAddrField("AdvA", None),
PacketListField("data", None, EIR_Hdr)
]
# Bit 0 - 4: Reserved
ConditionalField(BitField("reserved", 0, 5), lambda pkt: pkt.cmd_identifier == 4), # noqa: E501
# - Route Record Command - #
# Relay count (1 octet)
ConditionalField(ByteField("rr_relay_count", 0), lambda pkt: pkt.cmd_identifier == 5), # noqa: E501
# Relay list (variable in length)
ConditionalField(
FieldListField("rr_relay_list", [], XLEShortField("", 0x0000), count_from=lambda pkt:pkt.rr_relay_count), # noqa: E501
lambda pkt:pkt.cmd_identifier == 5),
# - Rejoin Request Command - #
# Capability Information (1 octet)
ConditionalField(BitField("allocate_address", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # Allocate Address # noqa: E501
ConditionalField(BitField("security_capability", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # Security Capability # noqa: E501
ConditionalField(BitField("reserved2", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # bit 5 is reserved # noqa: E501
ConditionalField(BitField("reserved1", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # bit 4 is reserved # noqa: E501
ConditionalField(BitField("receiver_on_when_idle", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # Receiver On When Idle # noqa: E501
ConditionalField(BitField("power_source", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # Power Source # noqa: E501
ConditionalField(BitField("device_type", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # Device Type # noqa: E501
ConditionalField(BitField("alternate_pan_coordinator", 0, 1), lambda pkt:pkt.cmd_identifier == 6), # Alternate PAN Coordinator # noqa: E501
# - Rejoin Response Command - #
# Network address (2 octets)
ConditionalField(XLEShortField("network_address", 0xFFFF), lambda pkt:pkt.cmd_identifier == 7), # noqa: E501
# Rejoin status (1 octet)
ConditionalField(ByteField("rejoin_status", 0), lambda pkt:pkt.cmd_identifier == 7), # noqa: E501
# - Link Status Command - #
# Command options (1 octet)
ConditionalField(BitField("reserved", 0, 1), lambda pkt:pkt.cmd_identifier == 8), # Reserved # noqa: E501
ConditionalField(BitField("last_frame", 0, 1), lambda pkt:pkt.cmd_identifier == 8), # Last frame # noqa: E501