meshcoredecoder 0.2.2__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {meshcoredecoder-0.2.2/meshcoredecoder.egg-info → meshcoredecoder-0.3.0}/PKG-INFO +78 -10
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/README.md +77 -9
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/cli.py +2 -2
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/index.py +1 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/__init__.py +1 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/crypto/channel_crypto.py +52 -81
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/packet_decoder.py +16 -8
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/__init__.py +3 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/ack.py +1 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/advert.py +1 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/anon_request.py +1 -1
- meshcoredecoder-0.3.0/meshcoredecoder/decoder/payload_decoders/control.py +206 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/path.py +2 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/request.py +7 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/response.py +94 -24
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/text_message.py +5 -1
- meshcoredecoder-0.3.0/meshcoredecoder/types/enums.py +69 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/types/payloads.py +32 -3
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/utils/enum_names.py +2 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0/meshcoredecoder.egg-info}/PKG-INFO +78 -10
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder.egg-info/SOURCES.txt +1 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/pyproject.toml +1 -1
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/setup.py +1 -1
- meshcoredecoder-0.2.2/meshcoredecoder/types/enums.py +0 -61
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/LICENSE +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/MANIFEST.in +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/crypto/__init__.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/crypto/ed25519_verifier.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/crypto/key_manager.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/__init__.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/group_data.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/group_text.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/trace.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/types/__init__.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/types/crypto.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/types/packet.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/utils/__init__.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/utils/auth_token.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/utils/hex.py +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder.egg-info/dependency_links.txt +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder.egg-info/entry_points.txt +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder.egg-info/requires.txt +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder.egg-info/top_level.txt +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/requirements.txt +0 -0
- {meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meshcoredecoder
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Complete Python implementation of the MeshCore Packet Decoder
|
|
5
5
|
Home-page: https://github.com/chrisdavis2110/meshcore-decoder-py
|
|
6
6
|
Author: Chris Davis
|
|
@@ -46,9 +46,18 @@ A Python library for decoding MeshCore mesh networking packets with full cryptog
|
|
|
46
46
|
## Features
|
|
47
47
|
|
|
48
48
|
- **Packet Decoding**: Decode MeshCore packets
|
|
49
|
-
- **Built-in Decryption**: Decrypt GroupText, TextMessage, and
|
|
49
|
+
- **Built-in Decryption**: Decrypt GroupText, TextMessage, Request, Response, Path, and AnonRequest payloads
|
|
50
50
|
- **Developer Friendly**: Python-first with full type hints and data classes
|
|
51
51
|
|
|
52
|
+
## Protocol reference
|
|
53
|
+
|
|
54
|
+
Packet and payload layouts follow the MeshCore protocol as described in the local docs:
|
|
55
|
+
|
|
56
|
+
- **[docs/packet_format.md](docs/packet_format.md)** – Packet layout (header, transport codes, path, payload), route types, payload types, payload versions
|
|
57
|
+
- **[docs/payloads.md](docs/payloads.md)** – Payload formats (Advert, Ack, Request/Response, TextMessage, Path, Control, Group text/datagram, etc.)
|
|
58
|
+
|
|
59
|
+
Supported payload types include: Request, Response, TextMessage, Ack, Advert, GroupText, GroupData, AnonRequest, Path, Trace, Multipart, Control (DISCOVER_REQ / DISCOVER_RESP), reserved (0x0C–0x0E), and RawCustom. Request types include GetStats, Keepalive, GetTelemetryData, GetMinMaxAvgData, GetAccessList, GetNeighbours, and GetOwnerInfo.
|
|
60
|
+
|
|
52
61
|
## Installation
|
|
53
62
|
|
|
54
63
|
### Install to a single project
|
|
@@ -231,9 +240,9 @@ if packet.payload_type == PayloadType.Trace and packet.payload.get('decoded'):
|
|
|
231
240
|
|
|
232
241
|
SNR (Signal-to-Noise Ratio) data is available from multiple packet types:
|
|
233
242
|
|
|
234
|
-
1. **TRACE Packets**
|
|
235
|
-
2. **GetStats Response Packets**
|
|
236
|
-
3. **DISCOVER_RESP Control Packets**
|
|
243
|
+
1. **TRACE Packets** – SNR values for each hop in the path
|
|
244
|
+
2. **GetStats / GetNeighbours Response Packets** – Full neighbor table with SNR values (requires decryption)
|
|
245
|
+
3. **DISCOVER_RESP Control Packets** – SNR in discovery responses (unencrypted; decode with `PayloadType.Control`)
|
|
237
246
|
|
|
238
247
|
### How GetStats Works
|
|
239
248
|
|
|
@@ -247,8 +256,8 @@ GetStats is a request/response protocol used to query a repeater node for its ne
|
|
|
247
256
|
- **Cipher MAC** (2 bytes): MAC for encrypted data
|
|
248
257
|
- **Ciphertext**: Encrypted data containing:
|
|
249
258
|
- Timestamp (4 bytes, Unix timestamp)
|
|
250
|
-
- Request type (1 byte
|
|
251
|
-
- Request data (optional,
|
|
259
|
+
- Request type (1 byte): e.g. 0x01 GetStats, 0x06 GetNeighbours, 0x07 GetOwnerInfo (see [docs/payloads.md](docs/payloads.md))
|
|
260
|
+
- Request data (optional, depends on request type)
|
|
252
261
|
|
|
253
262
|
**2. Receiving a Neighbor List Response:**
|
|
254
263
|
- The target repeater responds with a Response packet
|
|
@@ -378,9 +387,9 @@ Byte 8+: Array of neighbor entries, each entry:
|
|
|
378
387
|
|--------|---------|-----------------|---------------------|
|
|
379
388
|
| **TRACE Packets** | ✅ Path SNR per hop | Path hashes, trace tag | ❌ No |
|
|
380
389
|
| **Response Packets** | ✅ Neighbor SNR | Full neighbor table (pubkey prefixes, timestamps) | ✅ Yes (node key) |
|
|
381
|
-
| **DISCOVER_RESP** | ✅ SNR | Node info, tag
|
|
390
|
+
| **DISCOVER_RESP (Control)** | ✅ SNR | Node info, tag, pubkey (8 or 32 bytes) | ❌ No |
|
|
382
391
|
|
|
383
|
-
**Note:** Response packets are the only source that provides the complete neighbor table with pubkey prefixes, timestamps, and SNR values. TRACE packets provide SNR for the specific path taken
|
|
392
|
+
**Note:** Response packets are the only source that provides the complete neighbor table with pubkey prefixes, timestamps, and SNR values. TRACE packets provide SNR for the specific path taken. Control packets with sub_type DISCOVER_RESP provide SNR and node pubkey (or prefix) without decryption.
|
|
384
393
|
|
|
385
394
|
**NeighborEntry Object:**
|
|
386
395
|
|
|
@@ -432,6 +441,10 @@ The CLI will automatically:
|
|
|
432
441
|
- Display total neighbors available and neighbors in the packet
|
|
433
442
|
- Show each neighbor's pubkey prefix, SNR, and timestamps
|
|
434
443
|
|
|
444
|
+
## Packet format (summary)
|
|
445
|
+
|
|
446
|
+
Each packet is: **header** (1 byte) → optional **transport_codes** (4 bytes for Transport Flood/Direct) → **path_length** (1 byte) → **path** (0–64 bytes) → **payload** (0–184 bytes). The header encodes route type (bits 0–1), payload type (bits 2–5), and payload version (bits 6–7). Path length is variable (e.g. 0, 1, or 2 bytes of path data are all valid). Full field descriptions and tables are in [docs/packet_format.md](docs/packet_format.md).
|
|
447
|
+
|
|
435
448
|
## Packet Structure Analysis
|
|
436
449
|
|
|
437
450
|
For detailed packet analysis and debugging, use `analyze_structure()` to get byte-level breakdowns:
|
|
@@ -671,7 +684,7 @@ packet = MeshCoreDecoder.decode(packet_hex)
|
|
|
671
684
|
|
|
672
685
|
if packet.payload_type == PayloadType.Ack:
|
|
673
686
|
ack = packet.payload['decoded']
|
|
674
|
-
print(f"Checksum:
|
|
687
|
+
print(f"Checksum: {ack.checksum}") # 4-byte CRC (hex)
|
|
675
688
|
```
|
|
676
689
|
|
|
677
690
|
#### Trace
|
|
@@ -689,6 +702,25 @@ if packet.payload_type == PayloadType.Trace:
|
|
|
689
702
|
print(f" Hop {i}: {snr:.1f} dB")
|
|
690
703
|
```
|
|
691
704
|
|
|
705
|
+
#### Control (DISCOVER_REQ / DISCOVER_RESP)
|
|
706
|
+
```python
|
|
707
|
+
# Control payloads are unencrypted. Sub-types include DISCOVER_REQ (0x8) and DISCOVER_RESP (0x9).
|
|
708
|
+
packet_hex = "2D00..." # Flood + Control + path_len=0 + payload (flags + data)
|
|
709
|
+
packet = MeshCoreDecoder.decode(packet_hex)
|
|
710
|
+
|
|
711
|
+
if packet.payload_type == PayloadType.Control and packet.payload.get('decoded'):
|
|
712
|
+
ctrl = packet.payload['decoded']
|
|
713
|
+
print(f"Sub-type: 0x{ctrl.sub_type:x}")
|
|
714
|
+
if ctrl.parsed.get('sub_type_name') == 'DISCOVER_REQ':
|
|
715
|
+
print(f" prefix_only: {ctrl.parsed.get('prefix_only')}")
|
|
716
|
+
print(f" type_filter: {ctrl.parsed.get('type_filter_hex')}")
|
|
717
|
+
print(f" tag: {ctrl.parsed.get('tag_hex')}")
|
|
718
|
+
elif ctrl.parsed.get('sub_type_name') == 'DISCOVER_RESP':
|
|
719
|
+
print(f" SNR: {ctrl.parsed.get('snr_db')} dB")
|
|
720
|
+
print(f" tag: {ctrl.parsed.get('tag_hex')}")
|
|
721
|
+
print(f" pubkey: {ctrl.parsed.get('pubkey', '')[:16]}...")
|
|
722
|
+
```
|
|
723
|
+
|
|
692
724
|
### Encrypted Packets (Require Keys)
|
|
693
725
|
|
|
694
726
|
#### GroupText
|
|
@@ -800,6 +832,42 @@ for name, hex_data, opts in packets:
|
|
|
800
832
|
|
|
801
833
|
|
|
802
834
|
|
|
835
|
+
## Publishing to PyPI
|
|
836
|
+
|
|
837
|
+
To release a new version and upload to PyPI:
|
|
838
|
+
|
|
839
|
+
1. **Bump the version** in these files (keep them in sync):
|
|
840
|
+
- `pyproject.toml` → `version = "X.Y.Z"`
|
|
841
|
+
- `meshcoredecoder/__init__.py` → `__version__ = "X.Y.Z"`
|
|
842
|
+
- `setup.py` → `version="X.Y.Z"`
|
|
843
|
+
- `index.py` → `__version__ = "X.Y.Z"`
|
|
844
|
+
|
|
845
|
+
2. **Install build tools** (if needed):
|
|
846
|
+
```bash
|
|
847
|
+
pip install build twine
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
3. **Build the package**:
|
|
851
|
+
```bash
|
|
852
|
+
python -m build
|
|
853
|
+
```
|
|
854
|
+
This creates `dist/meshcoredecoder-X.Y.Z.tar.gz` and `dist/meshcoredecoder_X.Y.Z-*.whl`.
|
|
855
|
+
|
|
856
|
+
4. **Upload to PyPI** (requires a [PyPI account](https://pypi.org/account/register/) and API token):
|
|
857
|
+
```bash
|
|
858
|
+
twine upload dist/*
|
|
859
|
+
```
|
|
860
|
+
Use your PyPI username and an [API token](https://pypi.org/manage/account/token/) as the password. For Test PyPI first:
|
|
861
|
+
```bash
|
|
862
|
+
twine upload --repository testpypi dist/*
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
5. **Tag the release** (optional):
|
|
866
|
+
```bash
|
|
867
|
+
git tag vX.Y.Z
|
|
868
|
+
git push origin vX.Y.Z
|
|
869
|
+
```
|
|
870
|
+
|
|
803
871
|
## License
|
|
804
872
|
|
|
805
873
|
MIT License
|
|
@@ -7,9 +7,18 @@ A Python library for decoding MeshCore mesh networking packets with full cryptog
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **Packet Decoding**: Decode MeshCore packets
|
|
10
|
-
- **Built-in Decryption**: Decrypt GroupText, TextMessage, and
|
|
10
|
+
- **Built-in Decryption**: Decrypt GroupText, TextMessage, Request, Response, Path, and AnonRequest payloads
|
|
11
11
|
- **Developer Friendly**: Python-first with full type hints and data classes
|
|
12
12
|
|
|
13
|
+
## Protocol reference
|
|
14
|
+
|
|
15
|
+
Packet and payload layouts follow the MeshCore protocol as described in the local docs:
|
|
16
|
+
|
|
17
|
+
- **[docs/packet_format.md](docs/packet_format.md)** – Packet layout (header, transport codes, path, payload), route types, payload types, payload versions
|
|
18
|
+
- **[docs/payloads.md](docs/payloads.md)** – Payload formats (Advert, Ack, Request/Response, TextMessage, Path, Control, Group text/datagram, etc.)
|
|
19
|
+
|
|
20
|
+
Supported payload types include: Request, Response, TextMessage, Ack, Advert, GroupText, GroupData, AnonRequest, Path, Trace, Multipart, Control (DISCOVER_REQ / DISCOVER_RESP), reserved (0x0C–0x0E), and RawCustom. Request types include GetStats, Keepalive, GetTelemetryData, GetMinMaxAvgData, GetAccessList, GetNeighbours, and GetOwnerInfo.
|
|
21
|
+
|
|
13
22
|
## Installation
|
|
14
23
|
|
|
15
24
|
### Install to a single project
|
|
@@ -192,9 +201,9 @@ if packet.payload_type == PayloadType.Trace and packet.payload.get('decoded'):
|
|
|
192
201
|
|
|
193
202
|
SNR (Signal-to-Noise Ratio) data is available from multiple packet types:
|
|
194
203
|
|
|
195
|
-
1. **TRACE Packets**
|
|
196
|
-
2. **GetStats Response Packets**
|
|
197
|
-
3. **DISCOVER_RESP Control Packets**
|
|
204
|
+
1. **TRACE Packets** – SNR values for each hop in the path
|
|
205
|
+
2. **GetStats / GetNeighbours Response Packets** – Full neighbor table with SNR values (requires decryption)
|
|
206
|
+
3. **DISCOVER_RESP Control Packets** – SNR in discovery responses (unencrypted; decode with `PayloadType.Control`)
|
|
198
207
|
|
|
199
208
|
### How GetStats Works
|
|
200
209
|
|
|
@@ -208,8 +217,8 @@ GetStats is a request/response protocol used to query a repeater node for its ne
|
|
|
208
217
|
- **Cipher MAC** (2 bytes): MAC for encrypted data
|
|
209
218
|
- **Ciphertext**: Encrypted data containing:
|
|
210
219
|
- Timestamp (4 bytes, Unix timestamp)
|
|
211
|
-
- Request type (1 byte
|
|
212
|
-
- Request data (optional,
|
|
220
|
+
- Request type (1 byte): e.g. 0x01 GetStats, 0x06 GetNeighbours, 0x07 GetOwnerInfo (see [docs/payloads.md](docs/payloads.md))
|
|
221
|
+
- Request data (optional, depends on request type)
|
|
213
222
|
|
|
214
223
|
**2. Receiving a Neighbor List Response:**
|
|
215
224
|
- The target repeater responds with a Response packet
|
|
@@ -339,9 +348,9 @@ Byte 8+: Array of neighbor entries, each entry:
|
|
|
339
348
|
|--------|---------|-----------------|---------------------|
|
|
340
349
|
| **TRACE Packets** | ✅ Path SNR per hop | Path hashes, trace tag | ❌ No |
|
|
341
350
|
| **Response Packets** | ✅ Neighbor SNR | Full neighbor table (pubkey prefixes, timestamps) | ✅ Yes (node key) |
|
|
342
|
-
| **DISCOVER_RESP** | ✅ SNR | Node info, tag
|
|
351
|
+
| **DISCOVER_RESP (Control)** | ✅ SNR | Node info, tag, pubkey (8 or 32 bytes) | ❌ No |
|
|
343
352
|
|
|
344
|
-
**Note:** Response packets are the only source that provides the complete neighbor table with pubkey prefixes, timestamps, and SNR values. TRACE packets provide SNR for the specific path taken
|
|
353
|
+
**Note:** Response packets are the only source that provides the complete neighbor table with pubkey prefixes, timestamps, and SNR values. TRACE packets provide SNR for the specific path taken. Control packets with sub_type DISCOVER_RESP provide SNR and node pubkey (or prefix) without decryption.
|
|
345
354
|
|
|
346
355
|
**NeighborEntry Object:**
|
|
347
356
|
|
|
@@ -393,6 +402,10 @@ The CLI will automatically:
|
|
|
393
402
|
- Display total neighbors available and neighbors in the packet
|
|
394
403
|
- Show each neighbor's pubkey prefix, SNR, and timestamps
|
|
395
404
|
|
|
405
|
+
## Packet format (summary)
|
|
406
|
+
|
|
407
|
+
Each packet is: **header** (1 byte) → optional **transport_codes** (4 bytes for Transport Flood/Direct) → **path_length** (1 byte) → **path** (0–64 bytes) → **payload** (0–184 bytes). The header encodes route type (bits 0–1), payload type (bits 2–5), and payload version (bits 6–7). Path length is variable (e.g. 0, 1, or 2 bytes of path data are all valid). Full field descriptions and tables are in [docs/packet_format.md](docs/packet_format.md).
|
|
408
|
+
|
|
396
409
|
## Packet Structure Analysis
|
|
397
410
|
|
|
398
411
|
For detailed packet analysis and debugging, use `analyze_structure()` to get byte-level breakdowns:
|
|
@@ -632,7 +645,7 @@ packet = MeshCoreDecoder.decode(packet_hex)
|
|
|
632
645
|
|
|
633
646
|
if packet.payload_type == PayloadType.Ack:
|
|
634
647
|
ack = packet.payload['decoded']
|
|
635
|
-
print(f"Checksum:
|
|
648
|
+
print(f"Checksum: {ack.checksum}") # 4-byte CRC (hex)
|
|
636
649
|
```
|
|
637
650
|
|
|
638
651
|
#### Trace
|
|
@@ -650,6 +663,25 @@ if packet.payload_type == PayloadType.Trace:
|
|
|
650
663
|
print(f" Hop {i}: {snr:.1f} dB")
|
|
651
664
|
```
|
|
652
665
|
|
|
666
|
+
#### Control (DISCOVER_REQ / DISCOVER_RESP)
|
|
667
|
+
```python
|
|
668
|
+
# Control payloads are unencrypted. Sub-types include DISCOVER_REQ (0x8) and DISCOVER_RESP (0x9).
|
|
669
|
+
packet_hex = "2D00..." # Flood + Control + path_len=0 + payload (flags + data)
|
|
670
|
+
packet = MeshCoreDecoder.decode(packet_hex)
|
|
671
|
+
|
|
672
|
+
if packet.payload_type == PayloadType.Control and packet.payload.get('decoded'):
|
|
673
|
+
ctrl = packet.payload['decoded']
|
|
674
|
+
print(f"Sub-type: 0x{ctrl.sub_type:x}")
|
|
675
|
+
if ctrl.parsed.get('sub_type_name') == 'DISCOVER_REQ':
|
|
676
|
+
print(f" prefix_only: {ctrl.parsed.get('prefix_only')}")
|
|
677
|
+
print(f" type_filter: {ctrl.parsed.get('type_filter_hex')}")
|
|
678
|
+
print(f" tag: {ctrl.parsed.get('tag_hex')}")
|
|
679
|
+
elif ctrl.parsed.get('sub_type_name') == 'DISCOVER_RESP':
|
|
680
|
+
print(f" SNR: {ctrl.parsed.get('snr_db')} dB")
|
|
681
|
+
print(f" tag: {ctrl.parsed.get('tag_hex')}")
|
|
682
|
+
print(f" pubkey: {ctrl.parsed.get('pubkey', '')[:16]}...")
|
|
683
|
+
```
|
|
684
|
+
|
|
653
685
|
### Encrypted Packets (Require Keys)
|
|
654
686
|
|
|
655
687
|
#### GroupText
|
|
@@ -761,6 +793,42 @@ for name, hex_data, opts in packets:
|
|
|
761
793
|
|
|
762
794
|
|
|
763
795
|
|
|
796
|
+
## Publishing to PyPI
|
|
797
|
+
|
|
798
|
+
To release a new version and upload to PyPI:
|
|
799
|
+
|
|
800
|
+
1. **Bump the version** in these files (keep them in sync):
|
|
801
|
+
- `pyproject.toml` → `version = "X.Y.Z"`
|
|
802
|
+
- `meshcoredecoder/__init__.py` → `__version__ = "X.Y.Z"`
|
|
803
|
+
- `setup.py` → `version="X.Y.Z"`
|
|
804
|
+
- `index.py` → `__version__ = "X.Y.Z"`
|
|
805
|
+
|
|
806
|
+
2. **Install build tools** (if needed):
|
|
807
|
+
```bash
|
|
808
|
+
pip install build twine
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
3. **Build the package**:
|
|
812
|
+
```bash
|
|
813
|
+
python -m build
|
|
814
|
+
```
|
|
815
|
+
This creates `dist/meshcoredecoder-X.Y.Z.tar.gz` and `dist/meshcoredecoder_X.Y.Z-*.whl`.
|
|
816
|
+
|
|
817
|
+
4. **Upload to PyPI** (requires a [PyPI account](https://pypi.org/account/register/) and API token):
|
|
818
|
+
```bash
|
|
819
|
+
twine upload dist/*
|
|
820
|
+
```
|
|
821
|
+
Use your PyPI username and an [API token](https://pypi.org/manage/account/token/) as the password. For Test PyPI first:
|
|
822
|
+
```bash
|
|
823
|
+
twine upload --repository testpypi dist/*
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
5. **Tag the release** (optional):
|
|
827
|
+
```bash
|
|
828
|
+
git tag vX.Y.Z
|
|
829
|
+
git push origin vX.Y.Z
|
|
830
|
+
```
|
|
831
|
+
|
|
764
832
|
## License
|
|
765
833
|
|
|
766
834
|
MIT License
|
|
@@ -11,7 +11,7 @@ import sys
|
|
|
11
11
|
import json
|
|
12
12
|
import asyncio
|
|
13
13
|
from typing import List, Optional
|
|
14
|
-
from meshcoredecoder import MeshCoreDecoder
|
|
14
|
+
from meshcoredecoder import MeshCoreDecoder, __version__
|
|
15
15
|
from meshcoredecoder.crypto import MeshCoreKeyStore
|
|
16
16
|
from meshcoredecoder.types.crypto import DecryptionOptions
|
|
17
17
|
from meshcoredecoder.utils.enum_names import get_route_type_name, get_payload_type_name, get_device_role_name
|
|
@@ -877,7 +877,7 @@ def main():
|
|
|
877
877
|
formatter_class=argparse.RawDescriptionHelpFormatter
|
|
878
878
|
)
|
|
879
879
|
|
|
880
|
-
parser.add_argument('--version', action='version', version='
|
|
880
|
+
parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
|
|
881
881
|
|
|
882
882
|
subparsers = parser.add_subparsers(dest='command', help='Commands')
|
|
883
883
|
|
|
@@ -1014,7 +1014,7 @@ class ChannelCrypto:
|
|
|
1014
1014
|
(decrypted_bytes[3] << 24)
|
|
1015
1015
|
)
|
|
1016
1016
|
|
|
1017
|
-
#
|
|
1017
|
+
# For anonrequest payloads, default to repeater/sensor login
|
|
1018
1018
|
# Room server: timestamp(4) + sync_timestamp(4) + password
|
|
1019
1019
|
# Repeater/Sensor: timestamp(4) + password
|
|
1020
1020
|
# Regular request: timestamp(4) + req_type(1) + req_data
|
|
@@ -1023,89 +1023,31 @@ class ChannelCrypto:
|
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
1025
|
if len(decrypted_bytes) >= 8:
|
|
1026
|
-
#
|
|
1027
|
-
|
|
1028
|
-
decrypted_bytes[4] |
|
|
1029
|
-
(decrypted_bytes[5] << 8) |
|
|
1030
|
-
(decrypted_bytes[6] << 16) |
|
|
1031
|
-
(decrypted_bytes[7] << 24)
|
|
1032
|
-
)
|
|
1033
|
-
|
|
1034
|
-
# Check if bytes 4-7 look like a valid timestamp (reasonable Unix timestamp)
|
|
1035
|
-
# If sync_timestamp is 0 or very small, it might actually be the start of a password
|
|
1036
|
-
# Room server sync_timestamp should be a reasonable timestamp (e.g., > 1000000000)
|
|
1037
|
-
is_likely_sync_timestamp = (sync_timestamp > 1000000000)
|
|
1038
|
-
|
|
1039
|
-
if is_likely_sync_timestamp:
|
|
1040
|
-
# Room server login: timestamp(4) + sync_timestamp(4) + password
|
|
1041
|
-
result_data['sync_timestamp'] = sync_timestamp
|
|
1042
|
-
# Try to decode password (null-terminated string)
|
|
1043
|
-
password_bytes = decrypted_bytes[8:]
|
|
1044
|
-
try:
|
|
1045
|
-
password = password_bytes.decode('utf-8')
|
|
1046
|
-
null_index = password.find('\0')
|
|
1047
|
-
if null_index >= 0:
|
|
1048
|
-
password = password[:null_index]
|
|
1049
|
-
result_data['password'] = password
|
|
1050
|
-
result_data['type'] = 'room_server_login'
|
|
1051
|
-
except UnicodeDecodeError:
|
|
1052
|
-
# Might be regular request format
|
|
1053
|
-
if len(decrypted_bytes) >= 5:
|
|
1054
|
-
request_type = decrypted_bytes[4]
|
|
1055
|
-
request_data = decrypted_bytes[5:]
|
|
1056
|
-
result_data['request_type'] = request_type
|
|
1057
|
-
result_data['request_data'] = request_data
|
|
1058
|
-
result_data['type'] = 'request'
|
|
1059
|
-
else:
|
|
1060
|
-
# sync_timestamp is 0 or very small - could be repeater/sensor login OR regular request
|
|
1061
|
-
# Check if byte 4 is a valid request type first (0x01-0x06)
|
|
1062
|
-
if len(decrypted_bytes) >= 5:
|
|
1063
|
-
request_type_byte = decrypted_bytes[4]
|
|
1064
|
-
is_valid_request_type = (0x01 <= request_type_byte <= 0x06)
|
|
1065
|
-
|
|
1066
|
-
if is_valid_request_type:
|
|
1067
|
-
# Regular request: timestamp(4) + req_type(1) + req_data
|
|
1068
|
-
request_type = request_type_byte
|
|
1069
|
-
request_data = decrypted_bytes[5:]
|
|
1070
|
-
result_data['request_type'] = request_type
|
|
1071
|
-
result_data['request_data'] = request_data
|
|
1072
|
-
result_data['type'] = 'request'
|
|
1073
|
-
else:
|
|
1074
|
-
# Not a valid request type - likely repeater/sensor login
|
|
1075
|
-
# Repeater/Sensor login: timestamp(4) + password(null-terminated string)
|
|
1076
|
-
# Password starts at byte 4
|
|
1077
|
-
password_bytes = decrypted_bytes[4:]
|
|
1078
|
-
try:
|
|
1079
|
-
password = password_bytes.decode('utf-8')
|
|
1080
|
-
null_index = password.find('\0')
|
|
1081
|
-
if null_index >= 0:
|
|
1082
|
-
password = password[:null_index]
|
|
1083
|
-
result_data['password'] = password
|
|
1084
|
-
result_data['type'] = 'repeater_sensor_login'
|
|
1085
|
-
except UnicodeDecodeError:
|
|
1086
|
-
# If it's not valid UTF-8, treat as unknown
|
|
1087
|
-
result_data['raw'] = bytes_to_hex(decrypted_bytes[4:])
|
|
1088
|
-
result_data['type'] = 'unknown'
|
|
1089
|
-
else:
|
|
1090
|
-
# Too short - can't determine
|
|
1091
|
-
result_data['raw'] = bytes_to_hex(decrypted_bytes)
|
|
1092
|
-
result_data['type'] = 'unknown'
|
|
1093
|
-
elif len(decrypted_bytes) >= 5:
|
|
1094
|
-
# Could be regular request format or repeater/sensor login
|
|
1095
|
-
# Check if byte 4 is a valid request type (0x01-0x06)
|
|
1026
|
+
# Check if byte 4 is a valid request type first (0x01-0x06)
|
|
1027
|
+
# This takes priority over checking for sync_timestamp
|
|
1096
1028
|
request_type_byte = decrypted_bytes[4]
|
|
1097
1029
|
is_valid_request_type = (0x01 <= request_type_byte <= 0x06)
|
|
1098
1030
|
|
|
1099
1031
|
if is_valid_request_type:
|
|
1100
|
-
# Regular request
|
|
1032
|
+
# Regular request: timestamp(4) + req_type(1) + req_data
|
|
1101
1033
|
request_type = request_type_byte
|
|
1102
1034
|
request_data = decrypted_bytes[5:]
|
|
1103
1035
|
result_data['request_type'] = request_type
|
|
1104
1036
|
result_data['request_data'] = request_data
|
|
1105
1037
|
result_data['type'] = 'request'
|
|
1106
1038
|
else:
|
|
1039
|
+
# Not a valid request type - check if it could be room server or repeater/sensor login
|
|
1040
|
+
sync_timestamp = (
|
|
1041
|
+
decrypted_bytes[4] |
|
|
1042
|
+
(decrypted_bytes[5] << 8) |
|
|
1043
|
+
(decrypted_bytes[6] << 16) |
|
|
1044
|
+
(decrypted_bytes[7] << 24)
|
|
1045
|
+
)
|
|
1046
|
+
|
|
1047
|
+
# For anonrequest payloads, default to repeater/sensor login
|
|
1048
|
+
# AnonRequest logins are always repeater/sensor logins, not room server logins
|
|
1107
1049
|
# Repeater/Sensor login: timestamp(4) + password(null-terminated string)
|
|
1108
|
-
#
|
|
1050
|
+
# Password starts at byte 4
|
|
1109
1051
|
password_bytes = decrypted_bytes[4:]
|
|
1110
1052
|
try:
|
|
1111
1053
|
password = password_bytes.decode('utf-8')
|
|
@@ -1115,15 +1057,44 @@ class ChannelCrypto:
|
|
|
1115
1057
|
result_data['password'] = password
|
|
1116
1058
|
result_data['type'] = 'repeater_sensor_login'
|
|
1117
1059
|
except UnicodeDecodeError:
|
|
1118
|
-
# If it's not valid UTF-8,
|
|
1119
|
-
|
|
1120
|
-
result_data['
|
|
1121
|
-
result_data['request_data'] = decrypted_bytes[5:]
|
|
1122
|
-
result_data['type'] = 'request'
|
|
1060
|
+
# If it's not valid UTF-8, treat as unknown
|
|
1061
|
+
result_data['raw'] = bytes_to_hex(decrypted_bytes[4:])
|
|
1062
|
+
result_data['type'] = 'unknown'
|
|
1123
1063
|
else:
|
|
1124
|
-
#
|
|
1125
|
-
|
|
1126
|
-
|
|
1064
|
+
# Less than 8 bytes - check if byte 4 is a valid request type
|
|
1065
|
+
if len(decrypted_bytes) >= 5:
|
|
1066
|
+
request_type_byte = decrypted_bytes[4]
|
|
1067
|
+
is_valid_request_type = (0x01 <= request_type_byte <= 0x06)
|
|
1068
|
+
|
|
1069
|
+
if is_valid_request_type:
|
|
1070
|
+
# Regular request: timestamp(4) + req_type(1) + req_data
|
|
1071
|
+
request_type = request_type_byte
|
|
1072
|
+
request_data = decrypted_bytes[5:]
|
|
1073
|
+
result_data['request_type'] = request_type
|
|
1074
|
+
result_data['request_data'] = request_data
|
|
1075
|
+
result_data['type'] = 'request'
|
|
1076
|
+
else:
|
|
1077
|
+
# Not a valid request type - likely repeater/sensor login
|
|
1078
|
+
# Repeater/Sensor login: timestamp(4) + password(null-terminated string)
|
|
1079
|
+
# Byte 4 is the start of the password string
|
|
1080
|
+
password_bytes = decrypted_bytes[4:]
|
|
1081
|
+
try:
|
|
1082
|
+
password = password_bytes.decode('utf-8')
|
|
1083
|
+
null_index = password.find('\0')
|
|
1084
|
+
if null_index >= 0:
|
|
1085
|
+
password = password[:null_index]
|
|
1086
|
+
result_data['password'] = password
|
|
1087
|
+
result_data['type'] = 'repeater_sensor_login'
|
|
1088
|
+
except UnicodeDecodeError:
|
|
1089
|
+
# If it's not valid UTF-8, might still be a request with invalid type
|
|
1090
|
+
# or corrupted data - try as request anyway
|
|
1091
|
+
result_data['request_type'] = request_type_byte
|
|
1092
|
+
result_data['request_data'] = decrypted_bytes[5:] if len(decrypted_bytes) > 5 else b''
|
|
1093
|
+
result_data['type'] = 'request'
|
|
1094
|
+
else:
|
|
1095
|
+
# Too short - can't determine
|
|
1096
|
+
result_data['raw'] = bytes_to_hex(decrypted_bytes)
|
|
1097
|
+
result_data['type'] = 'unknown'
|
|
1127
1098
|
|
|
1128
1099
|
return DecryptionResult(
|
|
1129
1100
|
success=True,
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
|
|
3
3
|
MIT License
|
|
4
4
|
|
|
5
|
-
Main packet decoder - orchestrates all payload decoders
|
|
5
|
+
Main packet decoder - orchestrates all payload decoders.
|
|
6
|
+
Packet layout: docs/packet_format.md. Payload formats: docs/payloads.md.
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
from typing import Optional, Dict, Any, List, Tuple
|
|
@@ -23,6 +24,7 @@ from .payload_decoders.request import RequestPayloadDecoder
|
|
|
23
24
|
from .payload_decoders.response import ResponsePayloadDecoder
|
|
24
25
|
from .payload_decoders.anon_request import AnonRequestPayloadDecoder
|
|
25
26
|
from .payload_decoders.text_message import TextMessagePayloadDecoder
|
|
27
|
+
from .payload_decoders.control import ControlPayloadDecoder
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
class MeshCorePacketDecoder:
|
|
@@ -139,16 +141,14 @@ class MeshCorePacketDecoder:
|
|
|
139
141
|
transport_codes = (code1, code2)
|
|
140
142
|
|
|
141
143
|
if include_structure:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
(bytes_data[offset + 2] << 16) |
|
|
145
|
-
(bytes_data[offset + 3] << 24))
|
|
144
|
+
transport_code_1 = bytes_data[offset] | (bytes_data[offset + 1] << 8)
|
|
145
|
+
transport_code_2 = bytes_data[offset + 2] | (bytes_data[offset + 3] << 8)
|
|
146
146
|
segments.append(PacketSegment(
|
|
147
|
-
name='Transport
|
|
148
|
-
description='
|
|
147
|
+
name='Transport Codes',
|
|
148
|
+
description='2× uint16: transport_code_1 (region scope), transport_code_2 (reserved). See packet_format.md.',
|
|
149
149
|
start_byte=offset,
|
|
150
150
|
end_byte=offset + 3,
|
|
151
|
-
value=f'0x{
|
|
151
|
+
value=f'0x{transport_code_1:04x} 0x{transport_code_2:04x}'
|
|
152
152
|
))
|
|
153
153
|
offset += 4
|
|
154
154
|
|
|
@@ -296,6 +296,14 @@ class MeshCorePacketDecoder:
|
|
|
296
296
|
decoder_options['include_segments'] = include_structure
|
|
297
297
|
decoder_options['segment_offset'] = 0
|
|
298
298
|
decoded_payload = TextMessagePayloadDecoder.decode(payload_bytes, options if options else decoder_options)
|
|
299
|
+
elif payload_type == PayloadType.Control:
|
|
300
|
+
result = ControlPayloadDecoder.decode(payload_bytes, {'include_segments': include_structure, 'segment_offset': 0})
|
|
301
|
+
decoded_payload = result
|
|
302
|
+
if result and hasattr(result, 'segments') and result.segments:
|
|
303
|
+
payload_segments.extend(result.segments)
|
|
304
|
+
elif payload_type in (PayloadType.Reserved0C, PayloadType.Reserved0D, PayloadType.Reserved0E):
|
|
305
|
+
# Reserved payload types: show raw only
|
|
306
|
+
decoded_payload = None
|
|
299
307
|
|
|
300
308
|
# If no segments were generated and we need structure, show basic payload info
|
|
301
309
|
if include_structure and len(payload_segments) == 0 and len(bytes_data) > offset:
|
{meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/__init__.py
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Payload decoder modules"""
|
|
1
|
+
"""Payload decoder modules. See docs/payloads.md for formats."""
|
|
2
2
|
from .ack import AckPayloadDecoder
|
|
3
3
|
from .trace import TracePayloadDecoder
|
|
4
4
|
from .path import PathPayloadDecoder
|
|
@@ -9,6 +9,7 @@ from .request import RequestPayloadDecoder
|
|
|
9
9
|
from .response import ResponsePayloadDecoder
|
|
10
10
|
from .anon_request import AnonRequestPayloadDecoder
|
|
11
11
|
from .text_message import TextMessagePayloadDecoder
|
|
12
|
+
from .control import ControlPayloadDecoder
|
|
12
13
|
|
|
13
14
|
__all__ = [
|
|
14
15
|
'AckPayloadDecoder',
|
|
@@ -21,4 +22,5 @@ __all__ = [
|
|
|
21
22
|
'ResponsePayloadDecoder',
|
|
22
23
|
'AnonRequestPayloadDecoder',
|
|
23
24
|
'TextMessagePayloadDecoder',
|
|
25
|
+
'ControlPayloadDecoder',
|
|
24
26
|
]
|
{meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/ack.py
RENAMED
|
@@ -23,7 +23,7 @@ class AckPayloadDecoder:
|
|
|
23
23
|
options = {}
|
|
24
24
|
|
|
25
25
|
try:
|
|
26
|
-
#
|
|
26
|
+
# docs/payloads.md: Ack = checksum(4), CRC of message timestamp, text, and sender pubkey.
|
|
27
27
|
# - checksum (4 bytes) - CRC checksum of message timestamp, text, and sender pubkey
|
|
28
28
|
|
|
29
29
|
if len(payload) < 4:
|
{meshcoredecoder-0.2.2 → meshcoredecoder-0.3.0}/meshcoredecoder/decoder/payload_decoders/advert.py
RENAMED
|
@@ -53,7 +53,7 @@ class AdvertPayloadDecoder:
|
|
|
53
53
|
segment_offset = options.get('segment_offset', 0)
|
|
54
54
|
current_offset = 0
|
|
55
55
|
|
|
56
|
-
#
|
|
56
|
+
# docs/payloads.md: Advert = public_key(32) + timestamp(4) + signature(64) + appdata (flags + optional lat/long, feature1/2, name).
|
|
57
57
|
public_key = bytes_to_hex(payload[current_offset:current_offset + 32])
|
|
58
58
|
if options.get('include_segments'):
|
|
59
59
|
segments.append(PayloadSegment(
|
|
@@ -38,7 +38,7 @@ class AnonRequestPayloadDecoder:
|
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
try:
|
|
41
|
-
#
|
|
41
|
+
# docs/payloads.md: AnonRequest = dest_hash(1) + public_key(32) + cipher MAC(2) + ciphertext.
|
|
42
42
|
# - destination_hash (1 byte)
|
|
43
43
|
# - sender_public_key (32 bytes)
|
|
44
44
|
# - cipher_mac (2 bytes)
|