瀏覽代碼

First part of protocol documentation.

Mathias Gottschlag 5 年之前
父節點
當前提交
3c0b03f73d
共有 1 個檔案被更改,包括 51 行新增0 行删除
  1. 51
    0
      README.md

+ 51
- 0
README.md 查看文件

@@ -47,6 +47,57 @@ For an Ubuntu host, the following steps can be used:
47 47
 
48 48
         cargo build --target=arm-unknown-linux-gnueabihf
49 49
 
50
+# Protocol
51
+
52
+Packets are up to 32 bytes long. Most bytes are encrypted via XXTEA, except for
53
+one packet sent to the base station from a device to request a random number. The
54
+base station then replies with an encrypted packet containing a random salt
55
+value, and the device uses this salt for all further communication until the next
56
+reset, increasing the salt value by one for each packet sent. This scheme removes
57
+the need for the device to generate random numbers, as microcontrollers commonly
58
+are not capable of generation of high-quality ranodm numbers.
59
+
60
+The packet sent from the device to the base station to request a salt consists of
61
+a single byte with the sender ID and is recognized by the base station by its
62
+length.
63
+
64
+All encrypted packets follow the same scheme, with everything following after the
65
+salt being encrypted using a per-device XXTEA key hardcoded on the device and
66
+known to the base station. The packet fields are as follows, with multi-byte
67
+fields being encoded as little-endian:
68
+
69
+1. Device ID (1 byte)
70
+2. Salt (8 bytes)
71
+
72
+   The most significant bit of the salt value is 0 for packets from the device
73
+   to the base station and 1 for packets from the base station to the device.
74
+
75
+All fields from here on are encrypted with XXTEA, using the salt value contained
76
+in the packet.
77
+
78
+
79
+
80
+3. Packet type and element count (1 byte)
81
+
82
+   The 5 least significant bits of the field encode the packet type, with the
83
+   following possible values:
84
+
85
+   0. Salt: The packet is sent by the base station to the device whenever a
86
+      1-byte packet containing the device ID is received.
87
+   1. Report: The packet contains values measured by _this_ node. The element
88
+      count signals the number of values (of different types) reported by the
89
+      device.
90
+   2. GetValues: Sent by a device to request values generated by _other_ sensor
91
+      nodes from the base station, or to request the current time. The element
92
+      count signals the number of different values requested.
93
+   3. Values: Reply to a `GetValues` packet containing the requested information.
94
+
95
+4. Packet payload (variable)
96
+
97
+   TODO
98
+
99
+5. CRC-16-CCITT checksum
100
+
50 101
 # License
51 102
 
52 103
 The hardware contained in this repository is licensed under the [CERN Open Hardware Licence Version 2 - Weakly Reciprocal](cern_ohl_w_v2.txt), and the software is licensed under the [GNU General Public License v3](gpl-3.0.md).

Loading…
取消
儲存