meshcoredecoder 0.2.3__tar.gz → 0.3.1__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.
Files changed (45) hide show
  1. {meshcoredecoder-0.2.3/meshcoredecoder.egg-info → meshcoredecoder-0.3.1}/PKG-INFO +78 -10
  2. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/README.md +77 -9
  3. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/cli.py +5 -2
  4. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/index.py +1 -1
  5. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/__init__.py +1 -1
  6. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/crypto/channel_crypto.py +18 -8
  7. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/crypto/ed25519_verifier.py +14 -10
  8. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/packet_decoder.py +137 -65
  9. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/__init__.py +3 -1
  10. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/ack.py +1 -1
  11. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/advert.py +1 -1
  12. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/anon_request.py +1 -1
  13. meshcoredecoder-0.3.1/meshcoredecoder/decoder/payload_decoders/control.py +206 -0
  14. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/path.py +39 -19
  15. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/request.py +7 -1
  16. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/response.py +2 -1
  17. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/text_message.py +2 -1
  18. meshcoredecoder-0.3.1/meshcoredecoder/types/enums.py +69 -0
  19. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/types/packet.py +10 -2
  20. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/types/payloads.py +32 -3
  21. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/utils/enum_names.py +2 -0
  22. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1/meshcoredecoder.egg-info}/PKG-INFO +78 -10
  23. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder.egg-info/SOURCES.txt +1 -0
  24. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/pyproject.toml +1 -1
  25. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/setup.py +1 -1
  26. meshcoredecoder-0.2.3/meshcoredecoder/types/enums.py +0 -61
  27. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/LICENSE +0 -0
  28. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/MANIFEST.in +0 -0
  29. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/crypto/__init__.py +0 -0
  30. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/crypto/key_manager.py +0 -0
  31. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/__init__.py +0 -0
  32. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/group_data.py +0 -0
  33. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/group_text.py +0 -0
  34. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/decoder/payload_decoders/trace.py +0 -0
  35. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/types/__init__.py +0 -0
  36. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/types/crypto.py +0 -0
  37. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/utils/__init__.py +0 -0
  38. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/utils/auth_token.py +0 -0
  39. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder/utils/hex.py +0 -0
  40. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder.egg-info/dependency_links.txt +0 -0
  41. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder.egg-info/entry_points.txt +0 -0
  42. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder.egg-info/requires.txt +0 -0
  43. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/meshcoredecoder.egg-info/top_level.txt +0 -0
  44. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/requirements.txt +0 -0
  45. {meshcoredecoder-0.2.3 → meshcoredecoder-0.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshcoredecoder
3
- Version: 0.2.3
3
+ Version: 0.3.1
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 other encrypted payloads
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** (already supported) - SNR values for each hop in the path
235
- 2. **GetStats Response Packets** (just implemented) - Full neighbor table with SNR values
236
- 3. **DISCOVER_RESP Control Packets** (not yet implemented) - SNR in discovery responses
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, 0x01 for GetStats)
251
- - Request data (optional, empty for GetStats)
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 | ❌ No (not yet implemented) |
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, but not the full neighbor table.
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: 0x{ack.checksum:08X}")
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 other encrypted payloads
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** (already supported) - SNR values for each hop in the path
196
- 2. **GetStats Response Packets** (just implemented) - Full neighbor table with SNR values
197
- 3. **DISCOVER_RESP Control Packets** (not yet implemented) - SNR in discovery responses
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, 0x01 for GetStats)
212
- - Request data (optional, empty for GetStats)
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 | ❌ No (not yet implemented) |
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, but not the full neighbor table.
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: 0x{ack.checksum:08X}")
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
@@ -36,6 +36,9 @@ def print_formatted_packet(packet, keys: Optional[List[str]] = None):
36
36
  print(f'{bold("Payload Type:")} {get_payload_type_name(packet.payload_type)}')
37
37
  print(f'{bold("Total Bytes:")} {packet.total_bytes}')
38
38
 
39
+ # Path comes from the decoder (which applies path-length fallback for repeater-style adverts)
40
+ if packet.path_length and packet.path_length > 0:
41
+ print(f'{bold("Path Length:")} {packet.path_length} byte(s)')
39
42
  if packet.path and len(packet.path) > 0:
40
43
  print(f'{bold("Path:")} {" → ".join(packet.path)}')
41
44
 
@@ -877,7 +880,7 @@ def main():
877
880
  formatter_class=argparse.RawDescriptionHelpFormatter
878
881
  )
879
882
 
880
- parser.add_argument('--version', action='version', version='0.1.0')
883
+ parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
881
884
 
882
885
  subparsers = parser.add_subparsers(dest='command', help='Commands')
883
886
 
@@ -6,7 +6,7 @@ MIT License
6
6
  Main entry point for the MeshCore decoder Python port
7
7
  """
8
8
 
9
- __version__ = "0.2.3"
9
+ __version__ = "0.3.1"
10
10
 
11
11
  # Main decoder
12
12
  from src.decoder.packet_decoder import MeshCorePacketDecoder
@@ -5,4 +5,4 @@ from .decoder.packet_decoder import MeshCorePacketDecoder
5
5
  MeshCoreDecoder = MeshCorePacketDecoder
6
6
 
7
7
  __all__ = ['MeshCoreDecoder', 'MeshCorePacketDecoder']
8
- __version__ = "0.2.3"
8
+ __version__ = "0.3.1"
@@ -1147,20 +1147,30 @@ class ChannelCrypto:
1147
1147
  if not decrypted_bytes or len(decrypted_bytes) < 2:
1148
1148
  return DecryptionResult(success=False, error='Decrypted content too short')
1149
1149
 
1150
- # Parse MeshCore path format: path_len(1) + path(path_len) + extra_type(1) + extra(variable)
1151
- path_len = decrypted_bytes[0]
1152
-
1153
- if len(decrypted_bytes) < 1 + path_len + 1:
1150
+ # Parse MeshCore path format (same encoding as packet header): path_len_byte(1) with
1151
+ # bits 7:6 = hash_size-1 (1/2/3 bytes per hop), bits 5:0 = hop count (0-63).
1152
+ # path_byte_len = hop_count * hash_size; then extra_type(1) + extra(variable).
1153
+ path_len_byte = decrypted_bytes[0]
1154
+ path_hash_size = (path_len_byte >> 6) + 1 # 1, 2, or 3; 4 = reserved
1155
+ path_hash_count = path_len_byte & 63
1156
+ path_byte_len = path_hash_count * path_hash_size
1157
+
1158
+ if path_hash_size == 4:
1159
+ return DecryptionResult(success=False, error='Reserved path hash size in Path payload')
1160
+
1161
+ if len(decrypted_bytes) < 1 + path_byte_len + 1:
1154
1162
  return DecryptionResult(success=False, error='Decrypted content too short for path structure')
1155
1163
 
1156
- path = decrypted_bytes[1:1 + path_len]
1157
- extra_type = decrypted_bytes[1 + path_len]
1158
- extra = decrypted_bytes[2 + path_len:] if len(decrypted_bytes) > 2 + path_len else b''
1164
+ path = decrypted_bytes[1:1 + path_byte_len]
1165
+ extra_type = decrypted_bytes[1 + path_byte_len]
1166
+ extra = decrypted_bytes[2 + path_byte_len:] if len(decrypted_bytes) > 2 + path_byte_len else b''
1159
1167
 
1160
1168
  return DecryptionResult(
1161
1169
  success=True,
1162
1170
  data={
1163
- 'path_len': path_len,
1171
+ 'path_len_byte': path_len_byte,
1172
+ 'path_hash_size': path_hash_size,
1173
+ 'path_hash_count': path_hash_count,
1164
1174
  'path': path,
1165
1175
  'extra_type': extra_type,
1166
1176
  'extra': extra
@@ -34,24 +34,28 @@ class Ed25519SignatureVerifier:
34
34
  app_data_hex: str
35
35
  ) -> bool:
36
36
  """
37
- Verify an Ed25519 signature for MeshCore advertisement packets
37
+ Verify an Ed25519 signature for MeshCore advertisement packets.
38
38
 
39
- According to MeshCore protocol, the signed message for advertisements is:
40
- public_key (32 bytes) + timestamp (4 bytes LE) + app_data (variable)
39
+ Signed message is public_key + timestamp + app_data (docs/payloads.md).
40
+ We also try timestamp + public_key + app_data in case firmware varies.
41
41
  """
42
42
  try:
43
- # Convert hex strings to bytes
44
43
  public_key = hex_to_bytes(public_key_hex)
45
44
  signature = hex_to_bytes(signature_hex)
46
45
  app_data = hex_to_bytes(app_data_hex)
46
+ timestamp_bytes = timestamp.to_bytes(4, byteorder='little')
47
47
 
48
- # Construct the signed message according to MeshCore format
49
- message = Ed25519SignatureVerifier._construct_advert_signed_message(
50
- public_key_hex, timestamp, app_data
51
- )
48
+ # Primary: public_key + timestamp (LE) + app_data (per payloads.md)
49
+ message_pk_first = public_key + timestamp_bytes + app_data
50
+ if Ed25519SignatureVerifier._verify_signature(signature, message_pk_first, public_key):
51
+ return True
52
52
 
53
- # Verify the signature
54
- return Ed25519SignatureVerifier._verify_signature(signature, message, public_key)
53
+ # Alternative: timestamp + public_key + app_data (in case firmware uses this order)
54
+ message_ts_first = timestamp_bytes + public_key + app_data
55
+ if Ed25519SignatureVerifier._verify_signature(signature, message_ts_first, public_key):
56
+ return True
57
+
58
+ return False
55
59
  except Exception as error:
56
60
  print(f'Ed25519 signature verification failed: {error}')
57
61
  return False