scapy.layers.sixlowpan module

6LoWPAN Protocol Stack

This implementation follows the next documents:

  • Transmission of IPv6 Packets over IEEE 802.15.4 Networks
  • Compression Format for IPv6 Datagrams in Low Power and Lossy networks (6LoWPAN): draft-ietf-6lowpan-hc-15
  • RFC 4291
Application Application Protocols
Transport UDP TCP
Network IPv6
  LoWPAN
Data Link Layer IEEE 802.15.4 MAC
Physical IEEE 802.15.4 PHY

Note that:

  • Only IPv6 is supported
  • LoWPAN is in the middle between network and data link layer

The Internet Control Message protocol v6 (ICMPv6) is used for control messaging.

Adaptation between full IPv6 and the LoWPAN format is performed by routers at the edge of 6LoWPAN islands.

A LoWPAN support addressing; a direct mapping between the link-layer address and the IPv6 address is used for achieving compression.

Known Issues:
  • Unimplemented context information
  • Next header compression techniques
  • Unimplemented LoWPANBroadcast
class scapy.layers.sixlowpan.BitVarSizeField(name, default, calculate_length=None)

Bases: scapy.fields.BitField

addfield(pkt, s, val)

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

getfield(pkt, s)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

length_f
class scapy.layers.sixlowpan.IP6FieldLenField(name, default, size, length_of=None)

Bases: scapy.fields.IP6Field

addfield(pkt, s, val)

Add an internal value to a string

getfield(pkt, s)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

length_of
class scapy.layers.sixlowpan.LoWPANFragmentationFirst

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.sixlowpan.LoWPANFragmentationFirst'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (LoWPANFragmentationFirst).reserved>, <Field (LoWPANFragmentationFirst).datagramSize>, <Field (LoWPANFragmentationFirst).datagramTag>]
class scapy.layers.sixlowpan.LoWPANFragmentationSubsequent

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.sixlowpan.LoWPANFragmentationSubsequent'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (LoWPANFragmentationSubsequent).reserved>, <Field (LoWPANFragmentationSubsequent).datagramSize>, <Field (LoWPANFragmentationSubsequent).datagramTag>, <Field (LoWPANFragmentationSubsequent).datagramOffset>]
class scapy.layers.sixlowpan.LoWPANMesh

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.sixlowpan.LoWPANMesh'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (LoWPANMesh).reserved>, <Field (LoWPANMesh)._v>, <Field (LoWPANMesh)._f>, <Field (LoWPANMesh)._hopsLeft>, <Field (LoWPANMesh)._sourceAddr>, <Field (LoWPANMesh)._destinyAddr>]
guess_payload_class(payload)

DEV: Guesses the next payload class from layer bonds. Can be overloaded to use a different mechanism.

Parameters:payload (str) – the layer’s payload
Returns:the payload class
payload_guess = [({}, <class 'scapy.layers.sixlowpan.LoWPANFragmentationFirst'>), ({}, <class 'scapy.layers.sixlowpan.LoWPANFragmentationSubsequent'>)]
class scapy.layers.sixlowpan.LoWPANUncompressedIPv6

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.sixlowpan.LoWPANUncompressedIPv6'>, <class 'scapy.packet.Packet'>]
default_payload_class(pay)

DEV: Returns the default payload class if nothing has been found by the guess_payload_class() method.

Parameters:payload (str) – the layer’s payload
Returns:the default payload class define inside the configuration file
fields_desc = [<Field (LoWPANUncompressedIPv6)._type>]
class scapy.layers.sixlowpan.LoWPAN_HC1

Bases: scapy.packet.Raw

aliastypes = [<class 'scapy.layers.sixlowpan.LoWPAN_HC1'>, <class 'scapy.packet.Raw'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (Raw,Padding,LoWPAN_HC1,_UnknownOpenFlow).load>]
class scapy.layers.sixlowpan.LoWPAN_IPHC

Bases: scapy.packet.Packet

6LoWPAN IPv6 header compressed packets

It follows the implementation of draft-ietf-6lowpan-hc-15.

aliastypes = [<class 'scapy.layers.sixlowpan.LoWPAN_IPHC'>, <class 'scapy.packet.Packet'>]
compressDestinyAddr(ipv6)
compressSourceAddr(ipv6)
decompressDestinyAddr(packet)
decompressSourceAddr(packet)
do_build()

Create the default version of the layer

Returns:a string of the packet with the payload
do_build_payload()

Create the default version of the payload layer

Returns:a string of payload layer
fields_desc = [<Field (LoWPAN_IPHC)._reserved>, <Field (LoWPAN_IPHC).tf>, <Field (LoWPAN_IPHC).nh>, <Field (LoWPAN_IPHC).hlim>, <Field (LoWPAN_IPHC).cid>, <Field (LoWPAN_IPHC).sac>, <Field (LoWPAN_IPHC).sam>, <Field (LoWPAN_IPHC).m>, <Field (LoWPAN_IPHC).dac>, <Field (LoWPAN_IPHC).dam>, <scapy.fields.ConditionalField object>, <Field (LoWPAN_IPHC).tc_ecn>, <Field (LoWPAN_IPHC).tc_dscp>, <Field (LoWPAN_IPHC)._padd>, <Field (LoWPAN_IPHC).flowlabel>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <Field (LoWPAN_IPHC).sourceAddr>, <Field (LoWPAN_IPHC).destinyAddr>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]
guess_payload_class(payload)

DEV: Guesses the next payload class from layer bonds. Can be overloaded to use a different mechanism.

Parameters:payload (str) – the layer’s payload
Returns:the payload class
post_dissect(data)

dissect the IPv6 package compressed into this IPHC packet.

The packet payload needs to be decompressed and depending on the arguments, several conversions should be done.

class scapy.layers.sixlowpan.SixLoWPAN

Bases: scapy.packet.Packet

aliastypes = [<class 'scapy.layers.sixlowpan.SixLoWPAN'>, <class 'scapy.packet.Packet'>]
classmethod dispatch_hook(_pkt=b'', *args, **kargs)

Depending on the payload content, the frame type we should interpretate

payload_guess = [({}, <class 'scapy.layers.sixlowpan.LoWPANFragmentationFirst'>), ({}, <class 'scapy.layers.sixlowpan.LoWPANFragmentationSubsequent'>), ({}, <class 'scapy.layers.sixlowpan.LoWPANMesh'>), ({}, <class 'scapy.layers.sixlowpan.LoWPAN_IPHC'>)]
class scapy.layers.sixlowpan.SixLoWPANAddrField(name, default, length_of=None, fmt='H', count_of=None, adjust=<function FieldLenField.<lambda>>, fld=None)

Bases: scapy.fields.FieldLenField

Special field to store 6LoWPAN addresses

6LoWPAN Addresses have a variable length depending on other parameters. This special field allows to save them, and encode/decode no matter which encoding parameters they have.

addfield(pkt, s, val)

Add an internal value to a string

getfield(pkt, s)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

i2repr(pkt, x)

Convert internal value to a nice representation

scapy.layers.sixlowpan.destiny_addr_mode(pkt)

This function depending on the arguments returns the amount of bits to be used by the destiny address.

Keyword arguments: pkt – packet object instance

scapy.layers.sixlowpan.flowlabel_len(pkt)

This function depending on the arguments returns the amount of bits to be used by the padding of the traffic class.

Keyword arguments: pkt – packet object instance

scapy.layers.sixlowpan.nhc_port(pkt)
scapy.layers.sixlowpan.pad_trafficclass(pkt)

This function depending on the arguments returns the amount of bits to be used by the padding of the traffic class.

Keyword arguments: pkt – packet object instance

scapy.layers.sixlowpan.sixlowpan_defragment(packet_list)
scapy.layers.sixlowpan.sixlowpan_fragment(packet, datagram_tag=1)

Split a packet into different links to transmit as 6lowpan packets. Usage example:

>>> ipv6 = ..... (very big packet)
>>> pkts = sixlowpan_fragment(ipv6, datagram_tag=0x17)
>>> send = [Dot15d4()/Dot15d4Data()/x for x in pkts]
>>> wireshark(send)
scapy.layers.sixlowpan.source_addr_mode2(pkt)

source_addr_mode

This function depending on the arguments returns the amount of bits to be used by the source address.

Keyword arguments: pkt – packet object instance