Skip to content

Commit c786cfe

Browse files
Add KISS Modem firmware
1 parent acca73f commit c786cfe

5 files changed

Lines changed: 706 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ For developers;
3939
- Clone and open the MeshCore repository in Visual Studio Code.
4040
- See the example applications you can modify and run:
4141
- [Companion Radio](./examples/companion_radio) - For use with an external chat app, over BLE, USB or WiFi.
42+
- [KISS Modem](./examples/kiss_modem) - Serial KISS protocol bridge for host applications. ([protocol docs](./docs/kiss_modem_protocol.md))
4243
- [Simple Repeater](./examples/simple_repeater) - Extends network coverage by relaying messages.
4344
- [Simple Room Server](./examples/simple_room_server) - A simple BBS server for shared Posts.
4445
- [Simple Secure Chat](./examples/simple_secure_chat) - Secure terminal based text communication between devices.
46+
- [Simple Sensor](./examples/simple_sensor) - Remote sensor node with telemetry and alerting.
4547

4648
The Simple Secure Chat example can be interacted with through the Serial Monitor in Visual Studio Code, or with a Serial USB Terminal on Android.
4749

docs/kiss_modem_protocol.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# MeshCore KISS Modem Protocol
2+
3+
Serial protocol for the KISS modem firmware. Enables sending/receiving MeshCore packets over LoRa and cryptographic operations using the modem's identity.
4+
5+
## Serial Configuration
6+
7+
115200 baud, 8N1, no flow control.
8+
9+
## Frame Format
10+
11+
Standard KISS framing with byte stuffing.
12+
13+
| Byte | Name | Description |
14+
|------|------|-------------|
15+
| `0xC0` | FEND | Frame delimiter |
16+
| `0xDB` | FESC | Escape character |
17+
| `0xDC` | TFEND | Escaped FEND (FESC + TFEND = 0xC0) |
18+
| `0xDD` | TFESC | Escaped FESC (FESC + TFESC = 0xDB) |
19+
20+
```
21+
┌──────┬─────────┬──────────────┬──────┐
22+
│ FEND │ Command │ Data (escaped)│ FEND │
23+
│ 0xC0 │ 1 byte │ 0-510 bytes │ 0xC0 │
24+
└──────┴─────────┴──────────────┴──────┘
25+
```
26+
27+
Maximum unescaped frame size: 512 bytes.
28+
29+
## Commands
30+
31+
### Request Commands (Host → Modem)
32+
33+
| Command | Value | Data |
34+
|---------|-------|------|
35+
| `CMD_DATA` | `0x00` | Packet (2-255 bytes) |
36+
| `CMD_GET_IDENTITY` | `0x01` | - |
37+
| `CMD_GET_RANDOM` | `0x02` | Length (1 byte, 1-64) |
38+
| `CMD_VERIFY_SIGNATURE` | `0x03` | PubKey (32) + Signature (64) + Data |
39+
| `CMD_SIGN_DATA` | `0x04` | Data to sign |
40+
| `CMD_ENCRYPT_DATA` | `0x05` | Key (32) + Plaintext |
41+
| `CMD_DECRYPT_DATA` | `0x06` | Key (32) + MAC (2) + Ciphertext |
42+
| `CMD_KEY_EXCHANGE` | `0x07` | Remote PubKey (32) |
43+
| `CMD_HASH` | `0x08` | Data to hash |
44+
| `CMD_SET_RADIO` | `0x09` | Freq (4) + BW (4) + SF (1) + CR (1) |
45+
| `CMD_SET_TX_POWER` | `0x0A` | Power dBm (1) |
46+
| `CMD_SET_SYNC_WORD` | `0x0B` | Sync word (1) |
47+
| `CMD_GET_RADIO` | `0x0C` | - |
48+
| `CMD_GET_TX_POWER` | `0x0D` | - |
49+
| `CMD_GET_SYNC_WORD` | `0x0E` | - |
50+
| `CMD_GET_VERSION` | `0x0F` | - |
51+
52+
### Response Commands (Modem → Host)
53+
54+
| Command | Value | Data |
55+
|---------|-------|------|
56+
| `CMD_DATA` | `0x00` | SNR (1) + RSSI (1) + Packet |
57+
| `RESP_IDENTITY` | `0x11` | PubKey (32) |
58+
| `RESP_RANDOM` | `0x12` | Random bytes (1-64) |
59+
| `RESP_VERIFY` | `0x13` | Result (1): 0x00=invalid, 0x01=valid |
60+
| `RESP_SIGNATURE` | `0x14` | Signature (64) |
61+
| `RESP_ENCRYPTED` | `0x15` | MAC (2) + Ciphertext |
62+
| `RESP_DECRYPTED` | `0x16` | Plaintext |
63+
| `RESP_SHARED_SECRET` | `0x17` | Shared secret (32) |
64+
| `RESP_HASH` | `0x18` | SHA-256 hash (32) |
65+
| `RESP_OK` | `0x19` | - |
66+
| `RESP_RADIO` | `0x1A` | Freq (4) + BW (4) + SF (1) + CR (1) |
67+
| `RESP_TX_POWER` | `0x1B` | Power dBm (1) |
68+
| `RESP_SYNC_WORD` | `0x1C` | Sync word (1) |
69+
| `RESP_VERSION` | `0x1D` | Version (1) + Reserved (1) |
70+
| `RESP_ERROR` | `0x1E` | Error code (1) |
71+
| `RESP_TX_DONE` | `0x1F` | Result (1): 0x00=failed, 0x01=success |
72+
73+
## Error Codes
74+
75+
| Code | Value | Description |
76+
|------|-------|-------------|
77+
| `ERR_INVALID_LENGTH` | `0x01` | Request data too short |
78+
| `ERR_INVALID_PARAM` | `0x02` | Invalid parameter value |
79+
| `ERR_NO_CALLBACK` | `0x03` | Radio callback not set |
80+
| `ERR_MAC_FAILED` | `0x04` | MAC verification failed |
81+
| `ERR_UNKNOWN_CMD` | `0x05` | Unknown command |
82+
| `ERR_ENCRYPT_FAILED` | `0x06` | Encryption failed |
83+
84+
## Data Formats
85+
86+
### Radio Parameters (CMD_SET_RADIO / RESP_RADIO)
87+
88+
All values little-endian.
89+
90+
| Field | Size | Description |
91+
|-------|------|-------------|
92+
| Frequency | 4 bytes | Hz (e.g., 869618000) |
93+
| Bandwidth | 4 bytes | Hz (e.g., 62500) |
94+
| SF | 1 byte | Spreading factor (5-12) |
95+
| CR | 1 byte | Coding rate (5-8) |
96+
97+
### Received Packet (CMD_DATA response)
98+
99+
| Field | Size | Description |
100+
|-------|------|-------------|
101+
| SNR | 1 byte | Signal-to-noise × 4, signed |
102+
| RSSI | 1 byte | Signal strength dBm, signed |
103+
| Packet | variable | Raw MeshCore packet |
104+
105+
## Notes
106+
107+
- Modem generates identity on first boot (stored in flash)
108+
- SNR values multiplied by 4 for 0.25 dB precision
109+
- Wait for `RESP_TX_DONE` before sending next packet
110+
- See [packet_structure.md](./packet_structure.md) for packet format

0 commit comments

Comments
 (0)