aboutsummaryrefslogtreecommitdiff
path: root/inform_protocol.md
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2013-09-19 00:26:41 -0400
committerMike Crute <mcrute@gmail.com>2013-09-19 00:26:41 -0400
commit8e9b9067e09ed978e551af04481c4d5f40a9ceeb (patch)
tree46176695359f9d456f6db5759aa1e6ade1990eb3 /inform_protocol.md
parent302dfb895aa3a1566a5a722353dffd1f5487f6d5 (diff)
downloadubntmfi-8e9b9067e09ed978e551af04481c4d5f40a9ceeb.tar.bz2
ubntmfi-8e9b9067e09ed978e551af04481c4d5f40a9ceeb.tar.xz
ubntmfi-8e9b9067e09ed978e551af04481c4d5f40a9ceeb.zip
Rename notes to markdown
Diffstat (limited to 'inform_protocol.md')
-rw-r--r--inform_protocol.md138
1 files changed, 138 insertions, 0 deletions
diff --git a/inform_protocol.md b/inform_protocol.md
new file mode 100644
index 0000000..50c1b20
--- /dev/null
+++ b/inform_protocol.md
@@ -0,0 +1,138 @@
1Ubiquiti Inform Protocol
2========================
3
4The mFi uses the Ubiquiti inform protocol to handle all communications to and
5from the controller. This is the way that it transmits the current state of the
6system to the controller (looks like it just sends mca-dump output) as well as
7how it receives the instructions from the controller as to what to enable or
8disable.
9
10Everything appears to be pull-based, even provisioning. This makes sense with
11the cloud controller where the controller has no access to your network. I
12haven't documented yet how anything works within the protocol, that's next.
13This documents the overall protocol itself.
14
15The device will inform by executing an HTTP POST with an encrypted payload to
16http://controller:6080/inform at a regular interval (default is 10 seconds) and
17will expect an encrypted payload to be returned. If the device gets a command
18response instead of a noop response it will immediately do another inform; this
19continues until the controller sends the next noop response. Responses never
20appear to contain multiple commands.
21
22Raw Packet Structure
23--------------------
244 bytes magic number integer
254 bytes version integer
266 bytes hwaddr string
272 bytes flags short
2816 bytes initialization vector string
294 bytes data version integer
304 bytes data length integer
31n bytes encrypted payload string
32
33Raw Packet Constraints
34----------------------
35magic must == 1414414933
36data version must < 1
37flags & 0x1 != 0 means encrypted
38flags & 0x2 != 0 means compressed
39
40Payload Types
41-------------
42The payload is AES encrypted in CBC mode using PKCS5 padding. They key is the
43device auth key from the database or a master key that is hard coded if the
44device hasn't been provisioned yet. The master key is hard coded in the
45controller code in the DeviceManager class and pretty easy to find.
46
47MASTER_KEY = "ba86f2bbe107c7c57eb5f2690775c712"
48
49On devices running protocol version 1 the encrypted payload is just JSON data.
50In version 0 of the protocol the data was key=value pairs separated by
51newlines. All of the mFi hardware I have access to uses protocol version 1.
52
53The payloads break down into two categories; those coming into the controller
54and those going out of the controller.
55
56Output Payloads
57---------------
58Output payloads are those that originate from the controller and are bound for
59the device. These always appear to contain a _type field. I have observed the
60following output payloads.
61
62 _type: firmware upgrade (upgrade)
63 url: full url to firmware.bin
64 datetime: rfc3339 formatted date, server time
65 server_time_in_utc: server time in UTC as a unix timestamp (string)
66 version: firmware version (string)
67 time: server time as unix timestamp (int)
68 _id: unknown id string (5232701de4b0457a2f2f031f)
69 device_id: device ID from mongodb
70
71 _type: config update (setparam)
72 port_cfg: configuration for ports as string
73 server_time_in_utc: server time in UTC as a unix timestamp (string)
74
75
76 _type: reboot (reboot)
77 datetime: rfc3339 formatted date, server time
78 device_id: device ID from mongodb
79
80 _type: heartbeat (noop)
81 interval: next checkin time in seconds (integer)
82
83 _type: command (cmd)
84 _admin: admin data object
85 _id: mongodb id of admin
86 lang: admin language (en_US)
87 name: admin username
88 x_password: admin password
89 _id: unknown id string (5232701de4b0457a2f2f031f)
90 datetime: rfc3339 formatted date, server time
91 server_time_in_utc: server time in UTC as a unix timestamp (string)
92 time: server time as unix timestamp (int)
93 device_id: device ID from mongodb
94 cmd: command to use (mfi-output)
95 mac: device mac address
96 model: device model (Outlet for mPower)
97 off_volt: ?? (int)
98 port: device port to update (int)
99 sId: sensor ID
100 timer: ?? (int)
101 val: output value (int)
102 volt: ?? (int)
103
104 // val and volt set to 1 to turn on, 0 to turn off
105
106
107Input Payloads
108--------------
109Incoming packets appear to be a JSON version of the out put of the `mca-dump`
110command on the device. There is definitely some AirOS legacy in here. I don't
111document the whole input payload since most of it isn't interesting.
112
113 callback from device: javascript object
114 alarm: list of sensors
115 index: port name
116 sId: sensor ID hash
117 time: device time
118
119 // For mPort Only
120 tag: kind of reading presented (magnetic, temperature, humidity)
121 type: kind of device (input, analog, output)
122 val: value (float)
123
124 // For mPower Only
125 entries: list of entry objects
126 tag: kind of reading (output, pf, energy_sum, v_rms, i_rms, active_pwr)
127 type: sensor type (output, analog, rmsSum, rms)
128 val: value (float)
129
130 hostname: hostname of device ("ubnt" unless changed)
131 ip: IP of device
132 mac: mac address of primary interface
133 mfi: boolean, indicates if an mfi device
134 model: device model name
135 model_display: display name for device
136 serial: device serial number
137 uptime: uptime in seconds since last reboot
138 version: firmware version