Skip to content

SLIP Encoded IP Packets

Bryce Salmi edited this page Feb 3, 2018 · 4 revisions

faradayio sends SLIP encoded data over the serial port. The data sent will be exclusively IP packets. This page documents some examples to better define the interface for any serial device that wishes to use faradayio

Hello, World!

Let's send a simple IP packet with a string that says Hello, world!. There are no escape characters or anything to be worried about in this simple example. Using scapy a simple IP packet in the format of a UDP packet was generated to send from 10.0.0.1 port 9998 to a destination of 10.0.0.2 port 9999.

###[ IP ]###
  version   = 4
  ihl       = 5
  tos       = 0x0
  len       = 41
  id        = 1
  flags     = 
  frag      = 0
  ttl       = 64
  proto     = udp
  chksum    = 0x66c1
  src       = 10.0.0.1
  dst       = 10.0.0.2
  \options   \
###[ UDP ]###
     sport     = 9998
     dport     = 9999
     len       = 21
     chksum    = 0x5c58
###[ Raw ]###
        load      = 'Hello, world!'

Hex

E\x00\x00)\x00\x01\x00\x00@\x11f\xc1\n\x00\x00\x01\n\x00\x00\x02'\x0e'\x0f\x00\x15\\XHello, world!

Raw Hex

4500002900010000401166c10a0000010a000002270e270f00155c5848656c6c6f2c20776f726c6421

SLIP Encoded Hex

\xc0E\x00\x00)\x00\x01\x00\x00@\x11f\xc1\n\x00\x00\x01\n\x00\x00\x02'\x0e'\x0f\x00\x15\\XHello, world!\xc0

String With SLIP Escape Inside

Now we should show an example packet that includes an escape value xDB in SLIP which will force sliplib to escape the escape value. Per the SLIP documentation this will result in an xDD added to the string where appropriate. This will also provide an example for any interfacing serial device to encounter a known packet where it must recover the escape value correctly.

###[ IP ]###
  version   = 4
  ihl       = 5
  tos       = 0x0
  len       = 73
  id        = 1
  flags     = 
  frag      = 0
  ttl       = 64
  proto     = udp
  chksum    = 0x66a1
  src       = 10.0.0.1
  dst       = 10.0.0.2
  \options   \
###[ UDP ]###
     sport     = 9998
     dport     = 9999
     len       = 53
     chksum    = 0xaade
###[ Raw ]###
        load      = b'This string has \xdb which should escape in SLIP'

Hex

E\x00\x00I\x00\x01\x00\x00@\x11f\xa1\n\x00\x00\x01\n\x00\x00\x02'\x0e'\x0f\x005\xaa\xdeThis string has \xdb which should escape in SLIP

Raw Hex

4500004900010000401166a10a0000010a000002270e270f0035aade5468697320737472696e672068617320db2077686963682073686f756c642065736361706520696e20534c4950

SLIP Encoded Hex

\xc0E\x00\x00I\x00\x01\x00\x00@\x11f\xa1\n\x00\x00\x01\n\x00\x00\x02'\x0e'\x0f\x005\xaa\xdeThis string has \xdb\xdd which should escape in SLIP\xc0