scapy.layers.sixlowpan
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)
- getfield(pkt, s)
- 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)
- length_of
- class scapy.layers.sixlowpan.LoWPANFragmentationFirst(*args, **kargs)
Bases:
scapy.packet.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
0
- class scapy.layers.sixlowpan.LoWPANFragmentationSubsequent(*args, **kargs)
Bases:
scapy.packet.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
<RandShort>
datagramOffset
0
- class scapy.layers.sixlowpan.LoWPANMesh(*args, **kargs)
Bases:
scapy.packet.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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |RES| | | HOPSLE| SOURCEADDR | DESTINYADDR | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | +-+-+-+-+-+-+-+-+ Fig. LoWPANMesh
LoWPANMesh fields reserved
BitField
(2 bits)2
_v
BitEnumField
(1 bit)0
_f
BitEnumField
(1 bit)0
_hopsLeft
BitField
(4 bits)0
_sourceAddr
0
_destinyAddr
0
- guess_payload_class(payload)
- payload_guess
Possible sublayers:
LoWPANFragmentationFirst
,LoWPANFragmentationSubsequent
- class scapy.layers.sixlowpan.LoWPANUncompressedIPv6(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- default_payload_class(pay)
- class scapy.layers.sixlowpan.LoWPAN_HC1(*args, **kargs)
Bases:
scapy.packet.Raw
- aliastypes
- class scapy.layers.sixlowpan.LoWPAN_IPHC(*args, **kargs)
Bases:
scapy.packet.Packet
6LoWPAN IPv6 header compressed packets
It follows the implementation of RFC6282
- aliastypes
- compressDestinyAddr(ipv6)
- compressSourceAddr(ipv6)
- decompressDestinyAddr(packet)
- decompressSourceAddr(packet)
- do_build()
- do_build_payload()
- 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| CONTEXTIDENTIF|TC EC|TC DSC| PAD|FLOWLABE| NHFIELD | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | HOPLIMIT | SOURCEADDR | +-+-+-+-+-+-+-+-+ + | | + + | | + + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | DESTINYADDR | +-+-+-+-+-+-+-+-+ + | | + + | | + + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |HEADER COMPRESS| UDPSOURCEPORT | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | UDPDESTINYPORT | UDPCHECKSUM | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. LoWPAN_IPHC
LoWPAN_IPHC fields _reserved
BitField
(3 bits)3
tf
BitField
(2 bits)0
nh
BitEnumField
(1 bit)0
hlim
BitField
(2 bits)0
cid
BitEnumField
(1 bit)0
sac
BitEnumField
(1 bit)0
sam
BitEnumField
(2 bits)0
m
BitEnumField
(1 bit)0
dac
BitEnumField
(1 bit)0
dam
BitEnumField
(2 bits)0
_contextIdentifierExtension
ByteField
(Cond)0
tc_ecn
BitVarSizeField
(0 bit)0
tc_dscp
BitVarSizeField
(0 bit)0
_padd
BitVarSizeField
(0 bit)0
flowlabel
BitVarSizeField
(0 bit)0
_nhField
ByteField
(Cond)0
_hopLimit
ByteField
(Cond)0
sourceAddr
'::'
destinyAddr
'::'
header_compression
FlagsField
(Cond) (8 bits)<Flag 0 ()>
udpSourcePort
BitFieldLenField
(Cond) (16 bits)0
udpDestinyPort
BitFieldLenField
(Cond) (16 bits)0
udpChecksum
XShortField
(Cond)0
- guess_payload_class(payload)
- 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(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- classmethod dispatch_hook(_pkt=b'', *args, **kargs)
Depending on the payload content, the frame type we should interpretate
- payload_guess
Possible sublayers:
LoWPANFragmentationFirst
,LoWPANFragmentationSubsequent
,LoWPANMesh
,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)
- i2repr(pkt, x)
- 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