LLC - Logical Link Control

pcapkit.protocols.link.llc.protocol contains LLC, which implements the extractor for the IEEE 802.2 Logical Link Control (LLC) [*] PDU of ISO/IEC 8802-2, whose structure is:

Octets

Bits

Name

Description

0

0

llc.dsap

DSAP address, its low bit the I/G bit

1

8

llc.ssap

SSAP address, less its low bit

1

15

llc.cr

C/R bit, the low bit of the SSAP octet

2

16

llc.control

Control field, one octet in the U format and two in the I and S formats

Where the PDU comes from, and where its information field goes:

        flowchart TD
    ETH["Ethernet, Length/Type up to 0x05DC"] --> LLC
    WLAN["802.11 data frame carrying an MSDU"] --> LLC
    ATM["LINKTYPE_ATM_RFC1483"] --> LLC
    LLC{"control field format"}
    LLC -->|"I PDU or UI PDU"| DSAP{"LLC.\_\_proto\_\_ by DSAP"}
    LLC -->|"S, or U other than UI"| RAW["Raw"]
    DSAP -->|"0xAA, paired: SSAP 0xAA too"| SNAP{"SNAP, by OUI"}
    DSAP -->|"paired, another SSAP"| RAW
    DSAP -->|"no entry"| RAW
    SNAP -->|"00-00-00: the PID as an EtherType"| LINK["Link.\_\_proto\_\_"]
    SNAP -->|"any other"| RAW
    

Added in version 1.9.0.

class pcapkit.protocols.link.llc.protocol.LLC(file, length=None, /, *, layer=None, protocol=None, context=None)[source]

Bases: Link[LLC, LLC]

This class implements IEEE 802.2 Logical Link Control.

The PDU is dispatched from Ethernet, where its Length/Type field is a length, from IEEE802_11, as the frame body of a data frame carrying an MSDU, and from Frame.__proto__ and PCAPNG.__proto__ at LINKTYPE_ATM_RFC1483.

The control field is one octet in the U format, whose two low bits are 11, and two in the I format, whose low bit is 0, and the S format, whose two low bits are 01. The information field of an I PDU or a UI PDU is the next layer, dispatched by the DSAP through the protocols registered in the self.__proto__ attribute. A DSAP self.__paired__ flags is dispatched only when the SSAP, less its C/R bit, is the same address, as RFC 1042 sets both to the SNAP SAP and IEEE Std 802.1D-2004 both to the Bridge Spanning Tree Protocol SAP:

That of any other PDU, such as the XID or TEST information LLC exchanges itself, is kept as Raw.

Added in version 1.9.0.

Defaults

__proto__: DefaultDict[int | LSAP, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]

Protocol index mapping for decoding next layer, see self._decode_next_layer & self._import_next_layer. Keyed by DSAP rather than by EtherType, so this class keeps a registry of its own instead of sharing Link.__proto__; an entry is registered with register_lsap().

__paired__: dict[int | LSAP, bool]

DSAP to paired flag mapping, read by read(). A DSAP it flags is handed on only when the SSAP, less its C/R bit, is the same address, as the standard of the protocol at that DSAP fixes it, and one it does not hold is dispatched on alone. Written with the DSAP’s entry in __proto__ by register(), through its paired keyword.

__proto_key__: ClassVar[tuple[Type[EnumRegistry], bool]]

The enum the protocol map is keyed by, and that a bare int is no key, as Link.__proto_key__ describes.

Properties

property name: Literal['Logical Link Control']

Name of current protocol.

property length: Literal[3, 4]

Header length of current protocol, the control field included.

Methods

read(length=None, **kwargs)[source]

Read IEEE 802.2 Logical Link Control.

Structure of LLC PDU [IEEE Std 802.2]:

+--------+--------+-------------+-----------------------+
|  DSAP  |  SSAP  |   Control   |      Information      |
|        |        |  8/16 bits  |                       |
+--------+--------+-------------+-----------------------+

Each field is transmitted least significant bit first, so the I/G bit of the DSAP, the C/R bit of the SSAP and the format bits of the control field are the low bits of their octets.

Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

LLC

Returns:

Parsed packet data.

make(*, dsap=LSAP.SNAP, ssap=LSAP.SNAP, cr=False, format='U', function=None, send_seq=None, recv_seq=None, poll_final=False, reserved=None, payload=b'', **kwargs)[source]

Make (construct) packet data.

format decides which fields of the control field are carried. A field it carries and the caller leaves out is written as zeros, so function is UI in the U format and RR in the S format; a field it does not carry must be left out.

Parameters:
  • dsap (LSAP | int) – DSAP address, its I/G bit included.

  • ssap (LSAP | int) – SSAP address, an individual one.

  • cr (bool) – C/R bit; True for a response.

  • format (Literal['I', 'S', 'U']) – Format of the control field.

  • function (SupervisoryFunction | ModifierFunction | int | None) – Supervisory function in the S format, or modifier function in the U format, as the first octet of the control field masked to its bits.

  • send_seq (int | None) – Send sequence number, N(S), in the I format.

  • recv_seq (int | None) – Receive sequence number, N(R), in the I and S formats.

  • poll_final (bool) – Poll/final bit.

  • reserved (int | None) – Reserved bits 5 to 8 of the S format.

  • payload (bytes | ProtocolBase | Schema) – Payload data, the information field.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

LLC

Returns:

Constructed packet data.

Raises:

ProtocolError – If dsap, ssap or function is a name, or a code its field cannot carry; if ssap is a group address; if format is none of 'I', 'S' and 'U'; if a field is given that format does not carry; or if a value does not fit its field.

classmethod register(code, protocol, *, paired=False)[source]

Register a new protocol class for a DSAP.

Notes

The fully qualified class name of the new protocol class should be {protocol.module}.{protocol.name}.

The paired flag goes with the entry. Handing back the entry code shipped with, as a restore does, puts back the flag it shipped with too, so that an override and its restore leave __paired__ as it was; any other entry takes paired.

Parameters:

Important

This overrides Link.register because self.__proto__ is keyed by DSAP rather than by EtherType (#2511).

Raises:

pcapkit.utilities.exceptions.RegistryError – If protocol is not a class, or not a ProtocolBase subclass.

Warns:

pcapkit.utilities.warnings.RegistryWarning – If this DSAP is already registered and the incumbent differs from the replacement; the message names both. See Protocol.register for the guard, and for the shipped descriptor a restore puts back (#1504).

Data Models

__length_hint__()[source]

Return an estimated length for the object.

The longer form – a two-octet control field, 4 octets – per the reason L2TPv2.__length_hint__ gives for a variable-length header.

Return type:

Literal[4]

classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

LinkType

Returns:

Numeral registry index of the protocol in tcpdump link-layer header types, whose LINKTYPE_ATM_RFC1483 packet begins with an LLC header.

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (LLC) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_make_function(function, namespace, mask)[source]

Make the function bits of an S-format or U-format control field.

Parameters:
Return type:

int

Returns:

The function bits, in place in the first octet.

Raises:

ProtocolError – If function is a name, or a code with a bit outside mask set.

Header Schemas

class pcapkit.protocols.link.llc.schema.LLC(dsap=NO_VALUE, ssap=NO_VALUE, control=NO_VALUE, control_ext=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for LLC PDUs.

dsap: LSAP = <EnumField dsap>

DSAP address, its I/G bit included.

ssap: int = <UInt8Field ssap>

SSAP address, its C/R bit included.

control: int = <UInt8Field control>

First octet of the control field.

control_ext: int | None = <ConditionalField control_ext>

Second octet of the control field, in the I and S formats.

payload: bytes = <PayloadField payload>

Information field.

Auxiliary Functions

pcapkit.protocols.link.llc.schema.llc_control_is_long(pkt)[source]

Whether the control field is two octets long.

Parameters:

pkt (dict[str, Any]) – Packet data.

Return type:

bool

Returns:

Whether the first octet opens an I-format or S-format control field, two octets long, rather than a U-format one, of one octet.

Data Models

class pcapkit.protocols.link.llc.data.LLC(dsap, ssap, cr, control)[source]

Bases: Protocol

Data model for LLC PDUs.

dsap: LSAP

DSAP address, whose least significant bit is the I/G bit, 1 for a group address.

ssap: LSAP

SSAP address, without its C/R bit.

cr: bool

C/R bit of the SSAP, True for a response.

control: Control

Control field.

class pcapkit.protocols.link.llc.data.Control(format, function, send_seq, recv_seq, poll_final, reserved)[source]

Bases: Data

Data model for the LLC control field.

format: Literal['I', 'S', 'U']

Format of the control field, 'I' (information transfer), 'S' (supervisory) or 'U' (unnumbered).

function: SupervisoryFunction | ModifierFunction | None

Supervisory function of the S format, or modifier function of the U format; None in the I format.

send_seq: int | None

Send sequence number, N(S), of the I format; None otherwise.

recv_seq: int | None

Receive sequence number, N(R), of the I and S formats; None in the U format.

poll_final: bool

Poll/final bit.

reserved: int | None

Reserved bits 5 to 8 of the S format, sent as zero; None otherwise.

Footnotes