scapy.layers.sixlowpan

6LoWPAN Protocol Stack

This implementation follows the next documents:

  • Transmission of IPv6 Packets over IEEE 802.15.4 Networks: RFC 4944

  • Compression Format for IPv6 Datagrams in Low Power and Lossy networks (6LoWPAN): RFC 6282

  • 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

  • Unimplemented IPv6 extensions fields

class scapy.layers.sixlowpan.IP6FieldLenField(name, default, length_of=None)[source]

Bases: IP6Field

addfield(pkt, s, val)[source]

Add an internal value to a string

getfield(pkt, s)[source]
length_of
class scapy.layers.sixlowpan.LoWPANBroadcast(_pkt, /, *, reserved=80, seq=0)[source]

Bases: Packet

aliastypes
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    RESERVED   |      SEQ      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                       Fig. LoWPANBroadcast                       
LoWPANBroadcast fields

reserved

ByteField

80

seq

ByteField

0

payload_guess

Possible sublayers: SixLoWPAN

class scapy.layers.sixlowpan.LoWPANFragmentationFirst(_pkt, /, *, reserved=24, datagramSize=0, datagramTag=0)[source]

Bases: Packet

aliastypes
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| RESERVED|     DATAGRAMSIZE    |          DATAGRAMTAG          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                  Fig. LoWPANFragmentationFirst                   
LoWPANFragmentationFirst fields

reserved

BitField (5 bits)

24

datagramSize

BitField (11 bits)

0

datagramTag

XShortField

0

payload_guess

Possible sublayers: SixLoWPAN

class scapy.layers.sixlowpan.LoWPANFragmentationSubsequent(_pkt, /, *, reserved=28, datagramSize=0, datagramTag=<RandShort>, datagramOffset=0)[source]

Bases: Packet

aliastypes
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| RESERVED|     DATAGRAMSIZE    |          DATAGRAMTAG          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| DATAGRAMOFFSET|
+-+-+-+-+-+-+-+-+

                Fig. LoWPANFragmentationSubsequent                
LoWPANFragmentationSubsequent fields

reserved

BitField (5 bits)

28

datagramSize

BitField (11 bits)

0

datagramTag

XShortField

<RandShort>

datagramOffset

ByteField

0

class scapy.layers.sixlowpan.LoWPANMesh(_pkt, /, *, reserved=2, v=0, f=0, hopsLeft=0, src=None, dst=None)[source]

Bases: Packet

aliastypes
deprecated_fields: Dict[str, Tuple[str, str]] = {'_destinyAddr': ('dst', '2.4.4'), '_f': ('f', '2.4.4'), '_sourceAddr': ('src', '2.4.4'), '_v': ('v', '2.4.4')}
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|RES|V|F|HOPSLEF|                      SRC                      |
+-+-+-+-+-+-+-+-+                                               +
|                                                               |
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |                      DST                      |
+-+-+-+-+-+-+-+-+                                               +
|                                                               |
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |
+-+-+-+-+-+-+-+-+

                         Fig. LoWPANMesh                          
LoWPANMesh fields

reserved

BitField (2 bits)

2

v

BitEnumField

0

f

BitEnumField

0

hopsLeft

BitField (4 bits)

0

src

MultipleTypeField (XShortField, XLongField)

0

dst

MultipleTypeField (XShortField, XLongField)

0

payload_guess

Possible sublayers: SixLoWPAN

class scapy.layers.sixlowpan.LoWPANUncompressedIPv6(_pkt, /, *, _type=65)[source]

Bases: Packet

aliastypes
default_payload_class(pay)[source]
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      TYPE     |
+-+-+-+-+-+-+-+-+

                   Fig. LoWPANUncompressedIPv6                    
LoWPANUncompressedIPv6 fields

_type

BitField (8 bits)

65

class scapy.layers.sixlowpan.LoWPAN_HC1(_pkt, /, *, reserved=66, sp=0, si=0, dp=0, di=0, tc_fl=0, nh=0, hc2=0, hc2Field=None, hopLimit=0, src='::', dst='::', traffic_class=0, flow_label=0, udpSourcePort=None, udpDestPort=None, udpLength=0, udpChecksum=0, pad=0)[source]

Bases: Packet

aliastypes
decompressDestAddr()[source]
decompressSourceAddr()[source]
do_build()[source]
do_build_payload()[source]
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    RESERVED   |S|S|D|D|T| NH|H|HC2FIEL|    HOPLIMIT   |      SRC      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                               +-+-+-+-+-+-+-+-+
|                                               |      DST      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+                                               +-+-+-+-+-+-+-+-+
|                                               | TRAFFIC CLASS |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               FLOW LABEL              |     UDPSOURCEPORT     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       |          UDPDESTPORT          |       UDPLENGTH       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       |          UDPCHECKSUM          |PA|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Fig. LoWPAN_HC1                          
LoWPAN_HC1 fields

reserved

ByteField

66

sp

BitEnumField

0

si

BitEnumField

0

dp

BitEnumField

0

di

BitEnumField

0

tc_fl

BitEnumField

0

nh

BitEnumField

0

hc2

BitEnumField

0

hc2Field

MultipleTypeField (Cond, PacketField, StrFixedLenField)

b''

hopLimit

ByteField

0

src

IP6FieldLenField

'::'

dst

IP6FieldLenField

'::'

traffic_class

ByteField (Cond)

0

flow_label

BitField (Cond) (20 bits)

0

udpSourcePort

MultipleTypeField (Cond, BitScalingField, BitField)

0

udpDestPort

MultipleTypeField (Cond, BitScalingField, BitField)

0

udpLength

BitField (Cond) (16 bits)

0

udpChecksum

XBitField (Cond) (16 bits)

0

pad

BitLenField (0 bit)

0

payload_guess

Possible sublayers: IPv6

post_dissect(data)[source]
class scapy.layers.sixlowpan.LoWPAN_HC2_UDP(_pkt, /, *, sc=0, dc=0, lc=0, res=0)[source]

Bases: Packet

aliastypes
default_payload_class(payload)[source]
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|S|D|L|   RES   |
+-+-+-+-+-+-+-+-+

                       Fig. LoWPAN_HC2_UDP                        
LoWPAN_HC2_UDP fields

sc

BitEnumField

0

dc

BitEnumField

0

lc

BitEnumField

0

res

BitField (5 bits)

0

class scapy.layers.sixlowpan.LoWPAN_IPHC(_pkt, /, *, _reserved=3, tf=0, nh=0, hlim=0, cid=0, sac=0, sam=0, m=0, dac=0, dam=0, sci=0, dci=0, tc_ecn=0, tc_dscp=0, rsv=None, flowlabel=0, nhField=0, hopLimit=0, src='::', dst='::')[source]

Bases: Packet

6LoWPAN IPv6 header compressed packets

It follows the implementation of RFC6282

aliastypes
compressDestAddr(ipv6)[source]
compressSourceAddr(ipv6)[source]
decompressDestAddr(packet)[source]
decompressSourceAddr(packet)[source]
deprecated_fields: Dict[str, Tuple[str, str]] = {'_hopLimit': ('hopLimit', '2.4.4'), '_nhField': ('nhField', '2.4.4'), 'destinyAddr': ('dst', '2.4.4'), 'sourceAddr': ('src', '2.4.4'), 'udpDestinyPort': ('udpDestPort', '2.4.4')}
do_build()[source]
do_build_payload()[source]
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| RESE| TF|N|HLI|C|S|SAM|M|D|DAM|  SCI  |  DCI  |TC |  TC DSCP  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|RSV|               FLOWLABEL               |    NHFIELD    |HOP|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           |                        SRC                        |
+-+-+-+-+-+-+                                                   +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+           +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           |                        DST                        |
+-+-+-+-+-+-+                                                   +
|                                                               |
+                                                               +
|                                                               |
+                                                               +
|                                                               |
+           +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           |
+-+-+-+-+-+-+

                         Fig. LoWPAN_IPHC                         
LoWPAN_IPHC fields

_reserved

BitField (3 bits)

3

tf

BitField (2 bits)

0

nh

BitEnumField

0

hlim

BitEnumField

0

cid

BitEnumField

0

sac

BitEnumField

0

sam

BitEnumField

0

m

BitEnumField

0

dac

BitEnumField

0

dam

BitEnumField

0

sci

BitField (Cond) (4 bits)

0

dci

BitField (Cond) (4 bits)

0

tc_ecn

BitField (Cond) (2 bits)

0

tc_dscp

BitField (Cond) (6 bits)

0

rsv

MultipleTypeField (Cond, BitField, BitField)

0

flowlabel

BitField (Cond) (20 bits)

0

nhField

ByteEnumField (Cond)

0

hopLimit

ByteField (Cond)

0

src

IP6FieldLenField

'::'

dst

IP6FieldLenField

'::'

guess_payload_class(payload)[source]
post_dissect(data)[source]

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.LoWPAN_NHC(_pkt, /, *, exts=[])[source]

Bases: Packet

aliastypes
do_build()[source]
do_build_payload()[source]
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              EXTS             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                         Fig. LoWPAN_NHC                          
LoWPAN_NHC fields

exts

PacketListField

[]

guess_payload_class(payload)[source]
post_dissect(data)[source]
class scapy.layers.sixlowpan.LoWPAN_NHC_Hdr(_pkt, /)[source]

Bases: Packet

aliastypes
classmethod dispatch_hook(_pkt=b'', *args, **kargs)[source]
extract_padding(s)[source]
classmethod get_next_cls(s)[source]
class scapy.layers.sixlowpan.LoWPAN_NHC_IPv6Ext(_pkt, /, *, res=14, eid=0, nh=0, nhField=0, len=None, data=b'')[source]

Bases: LoWPAN_NHC_Hdr

aliastypes
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  RES  | EID |N|    NHFIELD    |      LEN      |      DATA     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |
+-+-+-+-+-+-+-+-+

                     Fig. LoWPAN_NHC_IPv6Ext                      
LoWPAN_NHC_IPv6Ext fields

res

BitField (4 bits)

14

eid

BitEnumField

0

nh

BitField (1 bit)

0

nhField

ByteField (Cond)

0

len

FieldLenField

None

data

StrFixedLenField

b''

post_build(p, pay)[source]
class scapy.layers.sixlowpan.LoWPAN_NHC_UDP(_pkt, /, *, res=30, C=0, P=0, udpSourcePort=None, udpDestPort=None, udpChecksum=0)[source]

Bases: LoWPAN_NHC_Hdr

aliastypes
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   RES   |C| P |         UDPSOURCEPORT         |  UDPDESTPORT  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |          UDPCHECKSUM          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                       Fig. LoWPAN_NHC_UDP                        
LoWPAN_NHC_UDP fields

res

BitField (5 bits)

30

C

BitField (1 bit)

0

P

BitField (2 bits)

0

udpSourcePort

MultipleTypeField (BitField, BitField, BitField, BitField)

0

udpDestPort

MultipleTypeField (BitField, BitField, BitField, BitField)

0

udpChecksum

XShortField (Cond)

0

class scapy.layers.sixlowpan.SixLoWPAN(_pkt, /)[source]

Bases: Packet

aliastypes
classmethod dispatch_hook(_pkt=b'', *args, **kargs)[source]

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

class scapy.layers.sixlowpan.SixLoWPAN_ESC(_pkt, /, *, dispatch=0)[source]

Bases: Packet

aliastypes
fields_desc
Display RFC-like schema
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    DISPATCH   |
+-+-+-+-+-+-+-+-+

                        Fig. SixLoWPAN_ESC                        
SixLoWPAN_ESC fields

dispatch

ByteField

0

scapy.layers.sixlowpan.dest_addr_size(pkt)[source]

Destination address size

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

Keyword arguments: pkt – packet object instance

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

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_size(pkt)[source]

Source address size

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

Keyword arguments: pkt – packet object instance