meshcoredecoder 0.2.3__py3-none-any.whl → 0.3.0__py3-none-any.whl

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.
cli.py CHANGED
@@ -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='0.1.0')
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
 
index.py CHANGED
@@ -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.0"
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.0"
@@ -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
- transport_code = (bytes_data[offset] |
143
- (bytes_data[offset + 1] << 8) |
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 Code',
148
- description='Used for Direct/Response routing',
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{transport_code:08x}'
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:
@@ -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
  ]
@@ -23,7 +23,7 @@ class AckPayloadDecoder:
23
23
  options = {}
24
24
 
25
25
  try:
26
- # Based on MeshCore payloads.md - Ack payload structure:
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:
@@ -53,7 +53,7 @@ class AdvertPayloadDecoder:
53
53
  segment_offset = options.get('segment_offset', 0)
54
54
  current_offset = 0
55
55
 
56
- # Parse advertisement structure from payloads.md
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
- # Based on MeshCore payloads.md - AnonRequest payload structure:
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)
@@ -0,0 +1,206 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ Control payload decoder.
6
+ Structure per docs/payloads.md: flags (1, upper 4 bits = sub_type), data (rest).
7
+ """
8
+
9
+ from typing import Optional, Dict, Any, List
10
+ from ...types.payloads import ControlPayload
11
+ from ...types.packet import PayloadSegment
12
+ from ...types.enums import PayloadType, PayloadVersion
13
+ from ...utils.hex import bytes_to_hex
14
+
15
+
16
+ # Sub-types from payloads.md (upper 4 bits of flags)
17
+ CONTROL_SUB_TYPE_DISCOVER_REQ = 0x8
18
+ CONTROL_SUB_TYPE_DISCOVER_RESP = 0x9
19
+
20
+
21
+ class ControlPayloadDecoder:
22
+ @staticmethod
23
+ def decode(
24
+ payload: bytes,
25
+ options: Optional[Dict[str, Any]] = None
26
+ ) -> Optional[ControlPayload]:
27
+ """Decode a Control payload. See docs/payloads.md Control data."""
28
+ if options is None:
29
+ options = {}
30
+
31
+ try:
32
+ if len(payload) < 1:
33
+ result = ControlPayload(
34
+ payload_type=PayloadType.Control,
35
+ version=PayloadVersion.Version1,
36
+ is_valid=False,
37
+ errors=['Control payload too short (minimum 1 byte for flags)'],
38
+ flags=0,
39
+ sub_type=0,
40
+ data_hex=''
41
+ )
42
+ if options.get('include_segments'):
43
+ result.segments = [PayloadSegment(
44
+ name='Invalid Control Data',
45
+ description='Control payload too short',
46
+ start_byte=options.get('segment_offset', 0),
47
+ end_byte=options.get('segment_offset', 0) + max(0, len(payload) - 1),
48
+ value=bytes_to_hex(payload)
49
+ )]
50
+ return result
51
+
52
+ segments: List[PayloadSegment] = []
53
+ segment_offset = options.get('segment_offset', 0)
54
+ offset = 0
55
+
56
+ flags = payload[offset]
57
+ sub_type = (flags >> 4) & 0x0F
58
+ lower_bits = flags & 0x0F
59
+
60
+ if options.get('include_segments'):
61
+ segments.append(PayloadSegment(
62
+ name='Flags',
63
+ description=f'Upper 4 bits = sub_type (0x{sub_type:x}), lower 4 bits = type-specific',
64
+ start_byte=segment_offset + offset,
65
+ end_byte=segment_offset + offset,
66
+ value=f'{flags:02x}'
67
+ ))
68
+ offset += 1
69
+
70
+ data_bytes = payload[offset:]
71
+ data_hex = bytes_to_hex(data_bytes)
72
+ parsed: Dict[str, Any] = {}
73
+
74
+ if sub_type == CONTROL_SUB_TYPE_DISCOVER_REQ and len(data_bytes) >= 5:
75
+ # DISCOVER_REQ: type_filter(1), tag(4), since(4 optional)
76
+ type_filter = data_bytes[0]
77
+ parsed['sub_type_name'] = 'DISCOVER_REQ'
78
+ parsed['prefix_only'] = bool(lower_bits & 0x01)
79
+ parsed['type_filter'] = type_filter
80
+ parsed['type_filter_hex'] = f'0x{type_filter:02x}'
81
+ if len(data_bytes) >= 9:
82
+ tag = (
83
+ data_bytes[1] |
84
+ (data_bytes[2] << 8) |
85
+ (data_bytes[3] << 16) |
86
+ (data_bytes[4] << 24)
87
+ )
88
+ parsed['tag'] = tag
89
+ parsed['tag_hex'] = f'0x{tag:08x}'
90
+ if len(data_bytes) >= 13:
91
+ since = (
92
+ data_bytes[5] |
93
+ (data_bytes[6] << 8) |
94
+ (data_bytes[7] << 16) |
95
+ (data_bytes[8] << 24)
96
+ )
97
+ parsed['since'] = since
98
+ parsed['since_hex'] = f'0x{since:08x}'
99
+
100
+ if options.get('include_segments'):
101
+ segments.append(PayloadSegment(
102
+ name='Type Filter',
103
+ description=f'Bit mask for ADV_TYPE_*: 0x{type_filter:02x}',
104
+ start_byte=segment_offset + offset,
105
+ end_byte=segment_offset + offset,
106
+ value=f'{type_filter:02x}'
107
+ ))
108
+ if len(data_bytes) >= 9:
109
+ segments.append(PayloadSegment(
110
+ name='Tag',
111
+ description=f'Random tag from sender: 0x{parsed["tag"]:08x}',
112
+ start_byte=segment_offset + offset + 1,
113
+ end_byte=segment_offset + offset + 4,
114
+ value=bytes_to_hex(data_bytes[1:5])
115
+ ))
116
+ if len(data_bytes) >= 13:
117
+ segments.append(PayloadSegment(
118
+ name='Since',
119
+ description=f'Epoch timestamp (optional): {parsed["since"]}',
120
+ start_byte=segment_offset + offset + 5,
121
+ end_byte=segment_offset + offset + 8,
122
+ value=bytes_to_hex(data_bytes[5:9])
123
+ ))
124
+
125
+ elif sub_type == CONTROL_SUB_TYPE_DISCOVER_RESP and len(data_bytes) >= 6:
126
+ # DISCOVER_RESP: snr(1, signed, SNR*4), tag(4), pubkey(8 or 32)
127
+ snr_raw = data_bytes[0]
128
+ snr_signed = snr_raw - 256 if snr_raw > 127 else snr_raw
129
+ snr_db = snr_signed / 4.0
130
+ tag = (
131
+ data_bytes[1] |
132
+ (data_bytes[2] << 8) |
133
+ (data_bytes[3] << 16) |
134
+ (data_bytes[4] << 24)
135
+ )
136
+ parsed['sub_type_name'] = 'DISCOVER_RESP'
137
+ parsed['node_type'] = lower_bits
138
+ parsed['snr_raw'] = snr_raw
139
+ parsed['snr_db'] = round(snr_db, 2)
140
+ parsed['tag'] = tag
141
+ parsed['tag_hex'] = f'0x{tag:08x}'
142
+ if len(data_bytes) >= 6 + 8:
143
+ pubkey_len = 32 if len(data_bytes) >= 6 + 32 else 8
144
+ pubkey_hex = bytes_to_hex(data_bytes[5:5 + pubkey_len])
145
+ parsed['pubkey_len'] = pubkey_len
146
+ parsed['pubkey'] = pubkey_hex
147
+
148
+ if options.get('include_segments'):
149
+ segments.append(PayloadSegment(
150
+ name='SNR',
151
+ description=f'SNR*4 (signed): {snr_db:.2f} dB',
152
+ start_byte=segment_offset + offset,
153
+ end_byte=segment_offset + offset,
154
+ value=f'{snr_raw:02x}'
155
+ ))
156
+ segments.append(PayloadSegment(
157
+ name='Tag',
158
+ description=f'Reflected from DISCOVER_REQ: 0x{tag:08x}',
159
+ start_byte=segment_offset + offset + 1,
160
+ end_byte=segment_offset + offset + 4,
161
+ value=bytes_to_hex(data_bytes[1:5])
162
+ ))
163
+ if len(data_bytes) >= 6 + 8:
164
+ pubkey_len = 32 if len(data_bytes) >= 6 + 32 else 8
165
+ segments.append(PayloadSegment(
166
+ name='Pubkey',
167
+ description=f'Node ID or prefix ({pubkey_len} bytes)',
168
+ start_byte=segment_offset + offset + 5,
169
+ end_byte=segment_offset + offset + 4 + pubkey_len,
170
+ value=bytes_to_hex(data_bytes[5:5 + pubkey_len])
171
+ ))
172
+
173
+ else:
174
+ parsed['raw'] = data_hex
175
+ if options.get('include_segments') and len(data_bytes) > 0:
176
+ segments.append(PayloadSegment(
177
+ name='Data',
178
+ description=f'Control data ({len(data_bytes)} bytes)',
179
+ start_byte=segment_offset + offset,
180
+ end_byte=segment_offset + len(payload) - 1,
181
+ value=data_hex
182
+ ))
183
+
184
+ result = ControlPayload(
185
+ payload_type=PayloadType.Control,
186
+ version=PayloadVersion.Version1,
187
+ is_valid=True,
188
+ flags=flags,
189
+ sub_type=sub_type,
190
+ data_hex=data_hex,
191
+ parsed=parsed
192
+ )
193
+ if options.get('include_segments'):
194
+ result.segments = segments
195
+ return result
196
+
197
+ except Exception as error:
198
+ return ControlPayload(
199
+ payload_type=PayloadType.Control,
200
+ version=PayloadVersion.Version1,
201
+ is_valid=False,
202
+ errors=[str(error)],
203
+ flags=0,
204
+ sub_type=0,
205
+ data_hex=''
206
+ )
@@ -38,7 +38,8 @@ class PathPayloadDecoder:
38
38
  )
39
39
 
40
40
  try:
41
- # Based on MeshCore packet_breakdown_guide.md - Path payload structure:
41
+ # docs/payloads.md: Path = dest_hash(1) + source_hash(1) + cipher MAC(2) + ciphertext.
42
+ # Ciphertext plaintext: path_length(1), path(bytes), extra_type(1), extra(rest).
42
43
  # Encrypted format:
43
44
  # - destination_hash (1 byte)
44
45
  # - source_hash (1 byte)
@@ -38,7 +38,8 @@ class RequestPayloadDecoder:
38
38
  )
39
39
 
40
40
  try:
41
- # Based on MeshCore payloads.md - Request payload structure:
41
+ # docs/payloads.md: Request payload = dest_hash(1) + source_hash(1) + cipher MAC(2) + ciphertext.
42
+ # Ciphertext plaintext: timestamp(4), request_type(1), request_data(rest).
42
43
  # - destination hash (1 byte)
43
44
  # - source hash (1 byte)
44
45
  # - cipher MAC (2 bytes)
@@ -345,6 +346,11 @@ class RequestPayloadDecoder:
345
346
  else:
346
347
  parsed['error'] = f'Request data too short (expected at least 10 bytes, got {len(request_data)})'
347
348
 
349
+ elif request_type == RequestType.GetOwnerInfo:
350
+ # 0x07 - Get Owner Info (repeater firmware-ver/name/owner info)
351
+ parsed['description'] = 'Get owner info (repeater firmware version, name, owner)'
352
+ parsed['raw'] = bytes_to_hex(request_data) if len(request_data) > 0 else ''
353
+
348
354
  else:
349
355
  # Unknown or Keepalive (deprecated)
350
356
  parsed['raw'] = bytes_to_hex(request_data)
@@ -163,7 +163,8 @@ class ResponsePayloadDecoder:
163
163
  )
164
164
 
165
165
  try:
166
- # Based on MeshCore payloads.md - Response payload structure:
166
+ # docs/payloads.md: Response = dest_hash(1) + source_hash(1) + cipher MAC(2) + ciphertext.
167
+ # Ciphertext plaintext: tag(4), content(rest).
167
168
  # - destination_hash (1 byte)
168
169
  # - source_hash (1 byte)
169
170
  # - cipher_mac (2 bytes)
@@ -38,7 +38,8 @@ class TextMessagePayloadDecoder:
38
38
  )
39
39
 
40
40
  try:
41
- # Based on MeshCore packet_breakdown_guide.md - TextMessage payload structure:
41
+ # docs/payloads.md: TextMessage = dest_hash(1) + source_hash(1) + cipher MAC(2) + ciphertext.
42
+ # Ciphertext plaintext: timestamp(4), txt_type+attempt(1), message(rest). txt_type: 0=plain, 1=CLI, 2=signed.
42
43
  # - destination_hash (1 byte)
43
44
  # - source_hash (1 byte)
44
45
  # - cipher_mac (2 bytes)
@@ -2,33 +2,39 @@
2
2
  Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
3
  MIT License
4
4
 
5
- MeshCore packet type definitions
6
- Reference: https://github.com/meshcore-dev/MeshCore/blob/main/docs/packet_structure.md
5
+ MeshCore packet type definitions.
6
+ Reference: docs/packet_format.md and docs/payloads.md
7
7
  """
8
8
 
9
9
  from enum import Enum
10
10
 
11
11
 
12
12
  class RouteType(Enum):
13
- TransportFlood = 0x00
14
- Flood = 0x01
15
- Direct = 0x02
16
- TransportDirect = 0x03
13
+ """Route types from packet header bits 0-1 (mask 0x03). See packet_format.md."""
14
+ TransportFlood = 0x00 # ROUTE_TYPE_TRANSPORT_FLOOD
15
+ Flood = 0x01 # ROUTE_TYPE_FLOOD
16
+ Direct = 0x02 # ROUTE_TYPE_DIRECT
17
+ TransportDirect = 0x03 # ROUTE_TYPE_TRANSPORT_DIRECT
17
18
 
18
19
 
19
20
  class PayloadType(Enum):
20
- Request = 0x00
21
- Response = 0x01
22
- TextMessage = 0x02
23
- Ack = 0x03
24
- Advert = 0x04
25
- GroupText = 0x05
26
- GroupData = 0x06
27
- AnonRequest = 0x07
28
- Path = 0x08
29
- Trace = 0x09
30
- Multipart = 0x0A
31
- RawCustom = 0x0F
21
+ """Payload types from packet header bits 2-5 (mask 0x3C). See packet_format.md."""
22
+ Request = 0x00 # PAYLOAD_TYPE_REQ
23
+ Response = 0x01 # PAYLOAD_TYPE_RESPONSE
24
+ TextMessage = 0x02 # PAYLOAD_TYPE_TXT_MSG
25
+ Ack = 0x03 # PAYLOAD_TYPE_ACK
26
+ Advert = 0x04 # PAYLOAD_TYPE_ADVERT
27
+ GroupText = 0x05 # PAYLOAD_TYPE_GRP_TXT
28
+ GroupData = 0x06 # PAYLOAD_TYPE_GRP_DATA
29
+ AnonRequest = 0x07 # PAYLOAD_TYPE_ANON_REQ
30
+ Path = 0x08 # PAYLOAD_TYPE_PATH
31
+ Trace = 0x09 # PAYLOAD_TYPE_TRACE
32
+ Multipart = 0x0A # PAYLOAD_TYPE_MULTIPART
33
+ Control = 0x0B # PAYLOAD_TYPE_CONTROL
34
+ Reserved0C = 0x0C # reserved
35
+ Reserved0D = 0x0D # reserved
36
+ Reserved0E = 0x0E # reserved
37
+ RawCustom = 0x0F # PAYLOAD_TYPE_RAW_CUSTOM
32
38
 
33
39
 
34
40
  class PayloadVersion(Enum):
@@ -53,9 +59,11 @@ class AdvertFlags(Enum):
53
59
 
54
60
 
55
61
  class RequestType(Enum):
62
+ """Request types in REQ payload ciphertext. See payloads.md Request type table."""
56
63
  GetStats = 0x01
57
64
  Keepalive = 0x02 # deprecated
58
65
  GetTelemetryData = 0x03
59
66
  GetMinMaxAvgData = 0x04
60
67
  GetAccessList = 0x05
61
68
  GetNeighbours = 0x06
69
+ GetOwnerInfo = 0x07
@@ -1,6 +1,6 @@
1
1
  """
2
- Payload type definitions
3
- Reference: https://github.com/meshcore-dev/MeshCore/blob/main/docs/payloads.md
2
+ Payload type definitions.
3
+ Reference: docs/payloads.md
4
4
  """
5
5
 
6
6
  from typing import Dict, Optional, List, Any
@@ -326,6 +326,34 @@ class NeighborEntry:
326
326
  }
327
327
 
328
328
 
329
+ class ControlPayload(BasePayload):
330
+ """Control packet payload (unencrypted). See payloads.md Control data."""
331
+ def __init__(
332
+ self,
333
+ flags: int,
334
+ sub_type: int,
335
+ data_hex: str,
336
+ parsed: Optional[Dict[str, Any]] = None,
337
+ **kwargs
338
+ ):
339
+ super().__init__(**kwargs)
340
+ self.flags = flags
341
+ self.sub_type = sub_type
342
+ self.data_hex = data_hex
343
+ self.parsed = parsed or {}
344
+
345
+ def to_dict(self) -> Dict[str, Any]:
346
+ result = super().to_dict()
347
+ result.update({
348
+ 'flags': self.flags,
349
+ 'subType': self.sub_type,
350
+ 'dataHex': self.data_hex,
351
+ })
352
+ if self.parsed:
353
+ result['parsed'] = self.parsed
354
+ return result
355
+
356
+
329
357
  class ResponsePayload(BasePayload):
330
358
  """Response payload"""
331
359
  def __init__(
@@ -377,5 +405,6 @@ class ResponsePayload(BasePayload):
377
405
  # Union type for all payload types
378
406
  PayloadData = (
379
407
  AdvertPayload | TracePayload | GroupTextPayload | GroupDataPayload | RequestPayload |
380
- TextMessagePayload | AnonRequestPayload | AckPayload | PathPayload | ResponsePayload
408
+ TextMessagePayload | AnonRequestPayload | AckPayload | PathPayload | ResponsePayload |
409
+ ControlPayload
381
410
  )
@@ -54,5 +54,7 @@ def get_request_type_name(request_type: RequestType) -> str:
54
54
  RequestType.GetTelemetryData: 'Get Telemetry Data',
55
55
  RequestType.GetMinMaxAvgData: 'Get Min/Max/Avg Data',
56
56
  RequestType.GetAccessList: 'Get Access List',
57
+ RequestType.GetNeighbours: 'Get Neighbors',
58
+ RequestType.GetOwnerInfo: 'Get Owner Info',
57
59
  }
58
60
  return mapping.get(request_type, f"Unknown ({request_type})")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshcoredecoder
3
- Version: 0.2.3
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 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
@@ -0,0 +1,36 @@
1
+ cli.py,sha256=oMW7wy8UoVFiS6fcp5jZ8ZojbVm7ZrbLJcX0_CmVljo,51434
2
+ index.py,sha256=dPlGhLOsOIhFtz5pCKOMJzBDD1lAEjI8NkZH5j-GeRw,2448
3
+ meshcoredecoder/__init__.py,sha256=OqlWqWYHDEvulEe-sCfkgQB7Vyi3eT4niUFIbly74Zo,275
4
+ meshcoredecoder/crypto/__init__.py,sha256=00r884_WImNp5YOYfSKYtUaIj6gZdyJV0--xC_Y71Ok,236
5
+ meshcoredecoder/crypto/channel_crypto.py,sha256=YKcFcD14ToqDhGfNUZwHEEW-kXKB8UP0VRuQWW75h7M,55512
6
+ meshcoredecoder/crypto/ed25519_verifier.py,sha256=9DAx0gqnf9I7fPxfKU4G1y0GbJK1stCtTKpCX4foL5k,5057
7
+ meshcoredecoder/crypto/key_manager.py,sha256=FXABZBd1B0kQwpyg7EX-pZDqxh5KVKnlB7A1FE3NQeU,5034
8
+ meshcoredecoder/decoder/__init__.py,sha256=P_E5CQS1eXoVy59A1mAV9TD5XCS6FpQpc4RizhOZVrw,654
9
+ meshcoredecoder/decoder/packet_decoder.py,sha256=qQA0wPI63fIjT8z95rrjkMBYfM6GmIuiAZaMRmvfGfM,25055
10
+ meshcoredecoder/decoder/payload_decoders/__init__.py,sha256=Q3khEbL1w84VhfczwcMm8KVT9HCjBPb8RzmcoU-NtB8,885
11
+ meshcoredecoder/decoder/payload_decoders/ack.py,sha256=Ao9M4b5e-aoNoq6pVAHkmcx1wJFrzsHLnSSjK84jcM8,3332
12
+ meshcoredecoder/decoder/payload_decoders/advert.py,sha256=iWJLyiU1mZ_wbfLaS51KFPdDeLJ0iTwM3Nn-LrIpu8Q,12710
13
+ meshcoredecoder/decoder/payload_decoders/anon_request.py,sha256=MwCaHNcNZAMmc4C9jXccQbEY61b3OIQzeIb-XS02tbw,7868
14
+ meshcoredecoder/decoder/payload_decoders/control.py,sha256=wWWOGLzuyTMpIbBtpI3k4lL88Us-3Ca7byK76d1ifw8,8836
15
+ meshcoredecoder/decoder/payload_decoders/group_data.py,sha256=llDm6lXDYqM_3udSz7lOtKCfHR39hUa5zivyfs21B_U,5435
16
+ meshcoredecoder/decoder/payload_decoders/group_text.py,sha256=BhdF1ZYrMS_UH7-xRxeNHU1WvgNf2Buk9SxpDN0YYcQ,5526
17
+ meshcoredecoder/decoder/payload_decoders/path.py,sha256=nsY4XzSPYBtMhMWDqLf2aDx0n3mg19qH8fo_sb04Nc4,13899
18
+ meshcoredecoder/decoder/payload_decoders/request.py,sha256=M4YMuVPNvSyyZjvIIpy1KaO5lFO9JyviKMRU9-52oag,19055
19
+ meshcoredecoder/decoder/payload_decoders/response.py,sha256=jab9mYYNYJH4xSCn2Fo9eOECvnMiplUxgW7MKvcC8_M,61439
20
+ meshcoredecoder/decoder/payload_decoders/text_message.py,sha256=JBwizJ58xRWB_JehPwLcatAP-K3WGag25zBaVrdZLu0,10622
21
+ meshcoredecoder/decoder/payload_decoders/trace.py,sha256=eN3E_5oidZzGdNsr--PhxtwYAwLW0lMJDGHz09lDqzA,6110
22
+ meshcoredecoder/types/__init__.py,sha256=XReL92twDsQQf8GUxYbPEdZGlV8XweQCPT-43jn8IfA,640
23
+ meshcoredecoder/types/crypto.py,sha256=o7C7IsiwMtJjzIUYRw548-AJmm898ucLDy1xYVukreE,1842
24
+ meshcoredecoder/types/enums.py,sha256=nBnpiQ1iFxeMaQBpQKrz2UrJqgH3Pw_LXrzK-aUlPc0,2019
25
+ meshcoredecoder/types/packet.py,sha256=LAMTHsFX3pWxP5M4gVsMRHEct2C2p36gpij_BuJofMw,3874
26
+ meshcoredecoder/types/payloads.py,sha256=Vbhx0ayfZ8Xg3UaCv29Ysb6zHSEP6_rWn8oDCUKe1Ks,12778
27
+ meshcoredecoder/utils/__init__.py,sha256=0_EpRPd97R2Cead_BTG9SDS6vVZV268u3XBkA-syOHk,739
28
+ meshcoredecoder/utils/auth_token.py,sha256=gVVgHH_Am1k-cZxPbrTHCafvqdWSqlg9Dw-RRYaRI8Y,6973
29
+ meshcoredecoder/utils/enum_names.py,sha256=Rb64MIF0ygzCkLMWCsMbSV3wAbExMVpoCWS3jdYR8Ms,2040
30
+ meshcoredecoder/utils/hex.py,sha256=IjDuoeIAr7swv9Fa1NKstZTotTwmtufdi_psCjqVU5k,1136
31
+ meshcoredecoder-0.3.0.dist-info/licenses/LICENSE,sha256=W4bNA8wxOTF7Wmcmi5UwjrrKnjT_Qua52Z5wQLPLfKM,1130
32
+ meshcoredecoder-0.3.0.dist-info/METADATA,sha256=RSx1Bwxi2wxPwu7zYPgP-GGCec2WMrASxZKzRB6G6P8,34093
33
+ meshcoredecoder-0.3.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
34
+ meshcoredecoder-0.3.0.dist-info/entry_points.txt,sha256=P8cgSHWETiDCc2jRCB95PuVyJDDeSq0gH-ufYVlqWDY,45
35
+ meshcoredecoder-0.3.0.dist-info/top_level.txt,sha256=Rj9ZjVG2I6CEgpgF8I_QqUDp-vTQEdYm2KD93mIGkJM,26
36
+ meshcoredecoder-0.3.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (82.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,35 +0,0 @@
1
- cli.py,sha256=bJXnvtgbn_en1KqD6mPtSvGEvpgwVVllISo9952pVmc,51403
2
- index.py,sha256=ibKxOS2MGPtzbEEjXawcN21M2Qlw3-qCwiQPyyw46Ak,2448
3
- meshcoredecoder/__init__.py,sha256=UD6zQ-wRynZRuzjRyUi2qkoaBBlKftkfl7xjd88G2ss,275
4
- meshcoredecoder/crypto/__init__.py,sha256=00r884_WImNp5YOYfSKYtUaIj6gZdyJV0--xC_Y71Ok,236
5
- meshcoredecoder/crypto/channel_crypto.py,sha256=YKcFcD14ToqDhGfNUZwHEEW-kXKB8UP0VRuQWW75h7M,55512
6
- meshcoredecoder/crypto/ed25519_verifier.py,sha256=9DAx0gqnf9I7fPxfKU4G1y0GbJK1stCtTKpCX4foL5k,5057
7
- meshcoredecoder/crypto/key_manager.py,sha256=FXABZBd1B0kQwpyg7EX-pZDqxh5KVKnlB7A1FE3NQeU,5034
8
- meshcoredecoder/decoder/__init__.py,sha256=P_E5CQS1eXoVy59A1mAV9TD5XCS6FpQpc4RizhOZVrw,654
9
- meshcoredecoder/decoder/packet_decoder.py,sha256=eNiOQdfUWU1Sb0mbo94Ox2CFMxz01XLwCm1mjtBdNwY,24351
10
- meshcoredecoder/decoder/payload_decoders/__init__.py,sha256=DGuu2SfDuAEg8hu9V6iWcxyXOUoen816SqcdZgVzHmU,778
11
- meshcoredecoder/decoder/payload_decoders/ack.py,sha256=W6JgF6ylf-Y5IWW33P-_EHTz5GEYY_-ng_aUxvDdHac,3299
12
- meshcoredecoder/decoder/payload_decoders/advert.py,sha256=OiOvjD2Db6d5GPA0Og2j7BQReGWLhiv6OcoyOtzZWOg,12627
13
- meshcoredecoder/decoder/payload_decoders/anon_request.py,sha256=IhoQLnC7_7MDbdZLtFjcBBbAbQ-EC9k6JFfirhct3wg,7839
14
- meshcoredecoder/decoder/payload_decoders/group_data.py,sha256=llDm6lXDYqM_3udSz7lOtKCfHR39hUa5zivyfs21B_U,5435
15
- meshcoredecoder/decoder/payload_decoders/group_text.py,sha256=BhdF1ZYrMS_UH7-xRxeNHU1WvgNf2Buk9SxpDN0YYcQ,5526
16
- meshcoredecoder/decoder/payload_decoders/path.py,sha256=MTptEthcN9R9r9KJf6Y40AWoZI54_vVlqBvXyAywrXk,13791
17
- meshcoredecoder/decoder/payload_decoders/request.py,sha256=eYA_rxrEKZa1gS7pMGWMb6I_0F89vRoMW23b_3-nx_0,18601
18
- meshcoredecoder/decoder/payload_decoders/response.py,sha256=UP5yLbHrQjwn9azf3lVDRQdxQ1Fh4s2nB4OgRyrDUrs,61351
19
- meshcoredecoder/decoder/payload_decoders/text_message.py,sha256=D1uTlw5UW4C8VZRt0hQiPdpFHABJbl3J3wBX90b11wU,10485
20
- meshcoredecoder/decoder/payload_decoders/trace.py,sha256=eN3E_5oidZzGdNsr--PhxtwYAwLW0lMJDGHz09lDqzA,6110
21
- meshcoredecoder/types/__init__.py,sha256=XReL92twDsQQf8GUxYbPEdZGlV8XweQCPT-43jn8IfA,640
22
- meshcoredecoder/types/crypto.py,sha256=o7C7IsiwMtJjzIUYRw548-AJmm898ucLDy1xYVukreE,1842
23
- meshcoredecoder/types/enums.py,sha256=Cjl4VuEdW30KS8cY-atZY2-no523VPR46YFF-57dtOs,1139
24
- meshcoredecoder/types/packet.py,sha256=LAMTHsFX3pWxP5M4gVsMRHEct2C2p36gpij_BuJofMw,3874
25
- meshcoredecoder/types/payloads.py,sha256=cSKJYM5j2MZwEjbQrCS1ljX1LQvdPjY5GVNorQ3Q91A,12048
26
- meshcoredecoder/utils/__init__.py,sha256=0_EpRPd97R2Cead_BTG9SDS6vVZV268u3XBkA-syOHk,739
27
- meshcoredecoder/utils/auth_token.py,sha256=gVVgHH_Am1k-cZxPbrTHCafvqdWSqlg9Dw-RRYaRI8Y,6973
28
- meshcoredecoder/utils/enum_names.py,sha256=6cSkbxexW8PT4MkwvWUA-oHQCvELUN2o3alIbp8bkP0,1936
29
- meshcoredecoder/utils/hex.py,sha256=IjDuoeIAr7swv9Fa1NKstZTotTwmtufdi_psCjqVU5k,1136
30
- meshcoredecoder-0.2.3.dist-info/licenses/LICENSE,sha256=W4bNA8wxOTF7Wmcmi5UwjrrKnjT_Qua52Z5wQLPLfKM,1130
31
- meshcoredecoder-0.2.3.dist-info/METADATA,sha256=GNlSaQ4Tn89WFE5zNx05a5SS_n4-JM1dRaTUgXoFlhY,30671
32
- meshcoredecoder-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
- meshcoredecoder-0.2.3.dist-info/entry_points.txt,sha256=P8cgSHWETiDCc2jRCB95PuVyJDDeSq0gH-ufYVlqWDY,45
34
- meshcoredecoder-0.2.3.dist-info/top_level.txt,sha256=Rj9ZjVG2I6CEgpgF8I_QqUDp-vTQEdYm2KD93mIGkJM,26
35
- meshcoredecoder-0.2.3.dist-info/RECORD,,