meshcoredecoder 0.1.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.
Files changed (34) hide show
  1. cli.py +249 -0
  2. index.py +66 -0
  3. meshcoredecoder/__init__.py +8 -0
  4. meshcoredecoder/crypto/__init__.py +6 -0
  5. meshcoredecoder/crypto/channel_crypto.py +113 -0
  6. meshcoredecoder/crypto/ed25519_verifier.py +136 -0
  7. meshcoredecoder/crypto/key_manager.py +71 -0
  8. meshcoredecoder/decoder/__init__.py +26 -0
  9. meshcoredecoder/decoder/packet_decoder.py +500 -0
  10. meshcoredecoder/decoder/payload_decoders/__init__.py +22 -0
  11. meshcoredecoder/decoder/payload_decoders/ack.py +91 -0
  12. meshcoredecoder/decoder/payload_decoders/advert.py +281 -0
  13. meshcoredecoder/decoder/payload_decoders/anon_request.py +137 -0
  14. meshcoredecoder/decoder/payload_decoders/group_text.py +130 -0
  15. meshcoredecoder/decoder/payload_decoders/path.py +89 -0
  16. meshcoredecoder/decoder/payload_decoders/request.py +143 -0
  17. meshcoredecoder/decoder/payload_decoders/response.py +133 -0
  18. meshcoredecoder/decoder/payload_decoders/text_message.py +70 -0
  19. meshcoredecoder/decoder/payload_decoders/trace.py +156 -0
  20. meshcoredecoder/types/__init__.py +15 -0
  21. meshcoredecoder/types/crypto.py +67 -0
  22. meshcoredecoder/types/enums.py +60 -0
  23. meshcoredecoder/types/packet.py +139 -0
  24. meshcoredecoder/types/payloads.py +244 -0
  25. meshcoredecoder/utils/__init__.py +18 -0
  26. meshcoredecoder/utils/auth_token.py +234 -0
  27. meshcoredecoder/utils/enum_names.py +58 -0
  28. meshcoredecoder/utils/hex.py +38 -0
  29. meshcoredecoder-0.1.0.dist-info/METADATA +332 -0
  30. meshcoredecoder-0.1.0.dist-info/RECORD +34 -0
  31. meshcoredecoder-0.1.0.dist-info/WHEEL +5 -0
  32. meshcoredecoder-0.1.0.dist-info/entry_points.txt +2 -0
  33. meshcoredecoder-0.1.0.dist-info/licenses/LICENSE +21 -0
  34. meshcoredecoder-0.1.0.dist-info/top_level.txt +3 -0
@@ -0,0 +1,143 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ Request payload decoder
6
+ """
7
+
8
+ from typing import Optional, Dict, Any, List
9
+ from ...types.payloads import RequestPayload
10
+ from ...types.packet import PayloadSegment
11
+ from ...types.enums import PayloadType, PayloadVersion, RequestType
12
+ from ...utils.hex import bytes_to_hex
13
+
14
+
15
+ class RequestPayloadDecoder:
16
+ @staticmethod
17
+ def decode(
18
+ payload: bytes,
19
+ options: Optional[Dict[str, Any]] = None
20
+ ) -> Optional[RequestPayload]:
21
+ """Decode a Request payload"""
22
+ if options is None:
23
+ options = {}
24
+
25
+ try:
26
+ # Based on MeshCore payloads.md - Request payload structure:
27
+ # - destination hash (1 byte)
28
+ # - source hash (1 byte)
29
+ # - cipher MAC (2 bytes)
30
+ # - ciphertext (rest of payload) - contains encrypted timestamp, request type, and request data
31
+
32
+ if len(payload) < 4:
33
+ result = RequestPayload(
34
+ payload_type=PayloadType.Request,
35
+ version=PayloadVersion.Version1,
36
+ is_valid=False,
37
+ errors=['Request payload too short (minimum 4 bytes: dest hash + source hash + MAC)'],
38
+ timestamp=0,
39
+ request_type=RequestType.GetStats,
40
+ request_data='',
41
+ destination_hash='',
42
+ source_hash='',
43
+ cipher_mac='',
44
+ ciphertext=''
45
+ )
46
+
47
+ if options.get('include_segments'):
48
+ result.segments = [PayloadSegment(
49
+ name='Invalid Request Data',
50
+ description='Request payload too short (minimum 4 bytes required: 1 for dest hash + 1 for source hash + 2 for MAC)',
51
+ start_byte=options.get('segment_offset', 0),
52
+ end_byte=(options.get('segment_offset', 0) + len(payload) - 1),
53
+ value=bytes_to_hex(payload)
54
+ )]
55
+
56
+ return result
57
+
58
+ segments: List[PayloadSegment] = []
59
+ segment_offset = options.get('segment_offset', 0)
60
+ offset = 0
61
+
62
+ # Parse destination hash (1 byte)
63
+ destination_hash = bytes_to_hex(payload[offset:offset + 1])
64
+
65
+ if options.get('include_segments'):
66
+ segments.append(PayloadSegment(
67
+ name='Destination Hash',
68
+ description=f'First byte of destination node public key: 0x{destination_hash}',
69
+ start_byte=segment_offset + offset,
70
+ end_byte=segment_offset + offset,
71
+ value=destination_hash
72
+ ))
73
+ offset += 1
74
+
75
+ # Parse source hash (1 byte)
76
+ source_hash = bytes_to_hex(payload[offset:offset + 1])
77
+
78
+ if options.get('include_segments'):
79
+ segments.append(PayloadSegment(
80
+ name='Source Hash',
81
+ description=f'First byte of source node public key: 0x{source_hash}',
82
+ start_byte=segment_offset + offset,
83
+ end_byte=segment_offset + offset,
84
+ value=source_hash
85
+ ))
86
+ offset += 1
87
+
88
+ # Parse cipher MAC (2 bytes)
89
+ cipher_mac = bytes_to_hex(payload[offset:offset + 2])
90
+
91
+ if options.get('include_segments'):
92
+ segments.append(PayloadSegment(
93
+ name='Cipher MAC',
94
+ description='MAC for encrypted data verification (2 bytes)',
95
+ start_byte=segment_offset + offset,
96
+ end_byte=segment_offset + offset + 1,
97
+ value=cipher_mac
98
+ ))
99
+ offset += 2
100
+
101
+ # Parse ciphertext (remaining bytes)
102
+ ciphertext = bytes_to_hex(payload[offset:])
103
+
104
+ if options.get('include_segments') and len(payload) > offset:
105
+ segments.append(PayloadSegment(
106
+ name='Ciphertext',
107
+ description=f'Encrypted message data ({len(payload) - offset} bytes). Contains encrypted plaintext with timestamp, request type, and request data',
108
+ start_byte=segment_offset + offset,
109
+ end_byte=segment_offset + len(payload) - 1,
110
+ value=ciphertext
111
+ ))
112
+
113
+ result = RequestPayload(
114
+ payload_type=PayloadType.Request,
115
+ version=PayloadVersion.Version1,
116
+ is_valid=True,
117
+ timestamp=0, # Will be decrypted if key is available
118
+ request_type=RequestType.GetStats, # Default value, will be overridden if decrypted
119
+ request_data='',
120
+ destination_hash=destination_hash,
121
+ source_hash=source_hash,
122
+ cipher_mac=cipher_mac,
123
+ ciphertext=ciphertext
124
+ )
125
+
126
+ if options.get('include_segments'):
127
+ result.segments = segments
128
+
129
+ return result
130
+ except Exception as error:
131
+ return RequestPayload(
132
+ payload_type=PayloadType.Request,
133
+ version=PayloadVersion.Version1,
134
+ is_valid=False,
135
+ errors=[str(error)],
136
+ timestamp=0,
137
+ request_type=RequestType.GetStats,
138
+ request_data='',
139
+ destination_hash='',
140
+ source_hash='',
141
+ cipher_mac='',
142
+ ciphertext=''
143
+ )
@@ -0,0 +1,133 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ Response payload decoder
6
+ """
7
+
8
+ from typing import Optional, Dict, Any, List
9
+ from ...types.payloads import ResponsePayload
10
+ from ...types.packet import PayloadSegment
11
+ from ...types.enums import PayloadType, PayloadVersion
12
+ from ...utils.hex import byte_to_hex, bytes_to_hex
13
+
14
+
15
+ class ResponsePayloadDecoder:
16
+ @staticmethod
17
+ def decode(
18
+ payload: bytes,
19
+ options: Optional[Dict[str, Any]] = None
20
+ ) -> Optional[ResponsePayload]:
21
+ """Decode a Response payload"""
22
+ if options is None:
23
+ options = {}
24
+
25
+ try:
26
+ # Based on MeshCore payloads.md - Response payload structure:
27
+ # - destination_hash (1 byte)
28
+ # - source_hash (1 byte)
29
+ # - cipher_mac (2 bytes)
30
+ # - ciphertext (rest of payload)
31
+
32
+ if len(payload) < 4:
33
+ result = ResponsePayload(
34
+ payload_type=PayloadType.Response,
35
+ version=PayloadVersion.Version1,
36
+ is_valid=False,
37
+ errors=['Response payload too short (minimum 4 bytes: dest + source + MAC)'],
38
+ destination_hash='',
39
+ source_hash='',
40
+ cipher_mac='',
41
+ ciphertext='',
42
+ ciphertext_length=0
43
+ )
44
+
45
+ if options.get('include_segments'):
46
+ result.segments = [PayloadSegment(
47
+ name='Invalid Response Data',
48
+ description='Response payload too short (minimum 4 bytes required)',
49
+ start_byte=options.get('segment_offset', 0),
50
+ end_byte=(options.get('segment_offset', 0) + len(payload) - 1),
51
+ value=bytes_to_hex(payload)
52
+ )]
53
+
54
+ return result
55
+
56
+ segments: List[PayloadSegment] = []
57
+ segment_offset = options.get('segment_offset', 0)
58
+ offset = 0
59
+
60
+ # Destination Hash (1 byte)
61
+ destination_hash = byte_to_hex(payload[offset])
62
+ if options.get('include_segments'):
63
+ segments.append(PayloadSegment(
64
+ name='Destination Hash',
65
+ description='First byte of destination node public key',
66
+ start_byte=segment_offset + offset,
67
+ end_byte=segment_offset + offset,
68
+ value=destination_hash
69
+ ))
70
+ offset += 1
71
+
72
+ # Source hash (1 byte)
73
+ source_hash = byte_to_hex(payload[offset])
74
+ if options.get('include_segments'):
75
+ segments.append(PayloadSegment(
76
+ name='Source Hash',
77
+ description='First byte of source node public key',
78
+ start_byte=segment_offset + offset,
79
+ end_byte=segment_offset + offset,
80
+ value=source_hash
81
+ ))
82
+ offset += 1
83
+
84
+ # Cipher MAC (2 bytes)
85
+ cipher_mac = bytes_to_hex(payload[offset:offset + 2])
86
+ if options.get('include_segments'):
87
+ segments.append(PayloadSegment(
88
+ name='Cipher MAC',
89
+ description='MAC for encrypted data in next field',
90
+ start_byte=segment_offset + offset,
91
+ end_byte=segment_offset + offset + 1,
92
+ value=cipher_mac
93
+ ))
94
+ offset += 2
95
+
96
+ # Ciphertext (remaining bytes)
97
+ ciphertext = bytes_to_hex(payload[offset:])
98
+ if options.get('include_segments') and len(payload) > offset:
99
+ segments.append(PayloadSegment(
100
+ name='Ciphertext',
101
+ description='Encrypted response data (tag + content)',
102
+ start_byte=segment_offset + offset,
103
+ end_byte=segment_offset + len(payload) - 1,
104
+ value=ciphertext
105
+ ))
106
+
107
+ result = ResponsePayload(
108
+ payload_type=PayloadType.Response,
109
+ version=PayloadVersion.Version1,
110
+ is_valid=True,
111
+ destination_hash=destination_hash,
112
+ source_hash=source_hash,
113
+ cipher_mac=cipher_mac,
114
+ ciphertext=ciphertext,
115
+ ciphertext_length=len(payload) - 4
116
+ )
117
+
118
+ if options.get('include_segments'):
119
+ result.segments = segments
120
+
121
+ return result
122
+ except Exception as error:
123
+ return ResponsePayload(
124
+ payload_type=PayloadType.Response,
125
+ version=PayloadVersion.Version1,
126
+ is_valid=False,
127
+ errors=[str(error)],
128
+ destination_hash='',
129
+ source_hash='',
130
+ cipher_mac='',
131
+ ciphertext='',
132
+ ciphertext_length=0
133
+ )
@@ -0,0 +1,70 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ TextMessage payload decoder
6
+ """
7
+
8
+ from typing import Optional, Dict, Any
9
+ from ...types.payloads import TextMessagePayload
10
+ from ...types.enums import PayloadType, PayloadVersion
11
+ from ...utils.hex import byte_to_hex, bytes_to_hex
12
+
13
+
14
+ class TextMessagePayloadDecoder:
15
+ @staticmethod
16
+ def decode(
17
+ payload: bytes,
18
+ options: Optional[Dict[str, Any]] = None
19
+ ) -> Optional[TextMessagePayload]:
20
+ """Decode a TextMessage payload"""
21
+ if options is None:
22
+ options = {}
23
+
24
+ try:
25
+ # Based on MeshCore payloads.md - TextMessage payload structure:
26
+ # - destination_hash (1 byte)
27
+ # - source_hash (1 byte)
28
+ # - cipher_mac (2 bytes)
29
+ # - ciphertext (rest of payload)
30
+
31
+ if len(payload) < 4:
32
+ return TextMessagePayload(
33
+ payload_type=PayloadType.TextMessage,
34
+ version=PayloadVersion.Version1,
35
+ is_valid=False,
36
+ errors=['TextMessage payload too short (minimum 4 bytes: dest + source + MAC)'],
37
+ destination_hash='',
38
+ source_hash='',
39
+ cipher_mac='',
40
+ ciphertext='',
41
+ ciphertext_length=0
42
+ )
43
+
44
+ destination_hash = byte_to_hex(payload[0])
45
+ source_hash = byte_to_hex(payload[1])
46
+ cipher_mac = bytes_to_hex(payload[2:4])
47
+ ciphertext = bytes_to_hex(payload[4:])
48
+
49
+ return TextMessagePayload(
50
+ payload_type=PayloadType.TextMessage,
51
+ version=PayloadVersion.Version1,
52
+ is_valid=True,
53
+ destination_hash=destination_hash,
54
+ source_hash=source_hash,
55
+ cipher_mac=cipher_mac,
56
+ ciphertext=ciphertext,
57
+ ciphertext_length=len(payload) - 4
58
+ )
59
+ except Exception as error:
60
+ return TextMessagePayload(
61
+ payload_type=PayloadType.TextMessage,
62
+ version=PayloadVersion.Version1,
63
+ is_valid=False,
64
+ errors=[str(error)],
65
+ destination_hash='',
66
+ source_hash='',
67
+ cipher_mac='',
68
+ ciphertext='',
69
+ ciphertext_length=0
70
+ )
@@ -0,0 +1,156 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ Trace payload decoder
6
+ """
7
+
8
+ from typing import Optional, Dict, Any, List
9
+ from ...types.payloads import TracePayload
10
+ from ...types.packet import PayloadSegment
11
+ from ...types.enums import PayloadType, PayloadVersion
12
+ from ...utils.hex import byte_to_hex, bytes_to_hex, number_to_hex
13
+
14
+
15
+ class TracePayloadDecoder:
16
+ @staticmethod
17
+ def decode(
18
+ payload: bytes,
19
+ path_data: Optional[List[str]] = None,
20
+ options: Optional[Dict[str, Any]] = None
21
+ ) -> Optional[TracePayload]:
22
+ """Decode a Trace payload"""
23
+ if options is None:
24
+ options = {}
25
+
26
+ try:
27
+ if len(payload) < 9:
28
+ result = TracePayload(
29
+ payload_type=PayloadType.Trace,
30
+ version=PayloadVersion.Version1,
31
+ is_valid=False,
32
+ errors=['Trace payload too short (need at least tag(4) + auth(4) + flags(1))'],
33
+ trace_tag='00000000',
34
+ auth_code=0,
35
+ flags=0,
36
+ path_hashes=[]
37
+ )
38
+
39
+ if options.get('include_segments'):
40
+ result.segments = [PayloadSegment(
41
+ name='Invalid Trace Data',
42
+ description='Trace payload too short (minimum 9 bytes required)',
43
+ start_byte=options.get('segment_offset', 0),
44
+ end_byte=(options.get('segment_offset', 0) + len(payload) - 1),
45
+ value=bytes_to_hex(payload)
46
+ )]
47
+
48
+ return result
49
+
50
+ offset = 0
51
+ segments: List[PayloadSegment] = []
52
+ segment_offset = options.get('segment_offset', 0)
53
+
54
+ # Trace Tag (4 bytes) - unique identifier
55
+ trace_tag_raw = TracePayloadDecoder._read_uint32_le(payload, offset)
56
+ trace_tag = number_to_hex(trace_tag_raw, 8)
57
+
58
+ if options.get('include_segments'):
59
+ segments.append(PayloadSegment(
60
+ name='Trace Tag',
61
+ description=f'Unique identifier for this trace: 0x{trace_tag_raw:08x}',
62
+ start_byte=segment_offset + offset,
63
+ end_byte=segment_offset + offset + 3,
64
+ value=bytes_to_hex(payload[offset:offset + 4])
65
+ ))
66
+ offset += 4
67
+
68
+ # Auth Code (4 bytes) - authentication/verification code
69
+ auth_code = TracePayloadDecoder._read_uint32_le(payload, offset)
70
+
71
+ if options.get('include_segments'):
72
+ segments.append(PayloadSegment(
73
+ name='Auth Code',
74
+ description=f'Authentication/verification code: {auth_code}',
75
+ start_byte=segment_offset + offset,
76
+ end_byte=segment_offset + offset + 3,
77
+ value=bytes_to_hex(payload[offset:offset + 4])
78
+ ))
79
+ offset += 4
80
+
81
+ # Flags (1 byte) - application-defined control flags
82
+ flags = payload[offset]
83
+
84
+ if options.get('include_segments'):
85
+ segments.append(PayloadSegment(
86
+ name='Flags',
87
+ description=f'Application-defined control flags: 0x{flags:02x} ({flags:08b}b)',
88
+ start_byte=segment_offset + offset,
89
+ end_byte=segment_offset + offset,
90
+ value=f'{flags:02X}'
91
+ ))
92
+ offset += 1
93
+
94
+ # Remaining bytes are path hashes (node hashes in the trace path)
95
+ path_hashes: List[str] = []
96
+ path_hashes_start = offset
97
+ while offset < len(payload):
98
+ path_hashes.append(byte_to_hex(payload[offset]))
99
+ offset += 1
100
+
101
+ if options.get('include_segments') and path_hashes:
102
+ path_hashes_display = ' '.join(path_hashes)
103
+ segments.append(PayloadSegment(
104
+ name='Path Hashes',
105
+ description=f'Node hashes in trace path: {path_hashes_display}',
106
+ start_byte=segment_offset + path_hashes_start,
107
+ end_byte=segment_offset + len(payload) - 1,
108
+ value=bytes_to_hex(payload[path_hashes_start:])
109
+ ))
110
+
111
+ # Extract SNR values from path field for TRACE packets
112
+ snr_values: Optional[List[float]] = None
113
+ if path_data and len(path_data) > 0:
114
+ snr_values = []
115
+ for hex_byte in path_data:
116
+ byte_value = int(hex_byte, 16)
117
+ # Convert unsigned byte to signed int8 (SNR values are stored as signed int8 * 4)
118
+ snr_signed = byte_value - 256 if byte_value > 127 else byte_value
119
+ snr_values.append(snr_signed / 4.0) # Convert to dB
120
+
121
+ result = TracePayload(
122
+ payload_type=PayloadType.Trace,
123
+ version=PayloadVersion.Version1,
124
+ is_valid=True,
125
+ trace_tag=trace_tag,
126
+ auth_code=auth_code,
127
+ flags=flags,
128
+ path_hashes=path_hashes,
129
+ snr_values=snr_values
130
+ )
131
+
132
+ if options.get('include_segments'):
133
+ result.segments = segments
134
+
135
+ return result
136
+ except Exception as error:
137
+ return TracePayload(
138
+ payload_type=PayloadType.Trace,
139
+ version=PayloadVersion.Version1,
140
+ is_valid=False,
141
+ errors=[str(error)],
142
+ trace_tag='00000000',
143
+ auth_code=0,
144
+ flags=0,
145
+ path_hashes=[]
146
+ )
147
+
148
+ @staticmethod
149
+ def _read_uint32_le(buffer: bytes, offset: int) -> int:
150
+ """Read a 32-bit unsigned integer in little-endian format"""
151
+ return (
152
+ buffer[offset] |
153
+ (buffer[offset + 1] << 8) |
154
+ (buffer[offset + 2] << 16) |
155
+ (buffer[offset + 3] << 24)
156
+ )
@@ -0,0 +1,15 @@
1
+ """Type definitions"""
2
+ from .enums import (
3
+ RouteType, PayloadType, PayloadVersion, DeviceRole, AdvertFlags, RequestType
4
+ )
5
+ from .crypto import CryptoKeyStore, DecryptionOptions, DecryptionResult, ValidationResult
6
+ from .packet import DecodedPacket, PacketStructure, PacketSegment, PayloadSegment, HeaderBreakdown
7
+
8
+ __all__ = [
9
+ # Enums
10
+ 'RouteType', 'PayloadType', 'PayloadVersion', 'DeviceRole', 'AdvertFlags', 'RequestType',
11
+ # Crypto
12
+ 'CryptoKeyStore', 'DecryptionOptions', 'DecryptionResult', 'ValidationResult',
13
+ # Packet
14
+ 'DecodedPacket', 'PacketStructure', 'PacketSegment', 'PayloadSegment', 'HeaderBreakdown',
15
+ ]
@@ -0,0 +1,67 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ Crypto-related type definitions
6
+ """
7
+
8
+ from typing import Dict, List, Protocol, Optional, Any
9
+
10
+
11
+ class CryptoKeyStore(Protocol):
12
+ """Protocol for key storage"""
13
+ # node keys for TextMessage/Request decryption
14
+ node_keys: Dict[str, str] # nodePublicKey -> privateKey (hex)
15
+
16
+ def add_node_key(self, public_key: str, private_key: str) -> None:
17
+ """Add/update keys"""
18
+ ...
19
+
20
+ def has_channel_key(self, channel_hash: str) -> bool:
21
+ """Check if keys are available"""
22
+ ...
23
+
24
+ def has_node_key(self, public_key: str) -> bool:
25
+ """Check if node key is available"""
26
+ ...
27
+
28
+ def get_channel_keys(self, channel_hash: str) -> List[str]:
29
+ """Get channel keys for a channel hash"""
30
+ ...
31
+
32
+
33
+ class DecryptionOptions:
34
+ """Options for packet decryption"""
35
+ def __init__(
36
+ self,
37
+ key_store: Optional[CryptoKeyStore] = None,
38
+ attempt_decryption: bool = True, # default: true if keyStore provided
39
+ include_raw_ciphertext: bool = True # default: true
40
+ ):
41
+ self.key_store = key_store
42
+ self.attempt_decryption = attempt_decryption if key_store else False
43
+ self.include_raw_ciphertext = include_raw_ciphertext
44
+
45
+
46
+ class DecryptionResult:
47
+ """Result of a decryption operation"""
48
+ def __init__(
49
+ self,
50
+ success: bool,
51
+ data: Optional[Any] = None,
52
+ error: Optional[str] = None
53
+ ):
54
+ self.success = success
55
+ self.data = data
56
+ self.error = error
57
+
58
+
59
+ class ValidationResult:
60
+ """Result of a validation operation"""
61
+ def __init__(
62
+ self,
63
+ is_valid: bool,
64
+ errors: Optional[List[str]] = None
65
+ ):
66
+ self.is_valid = is_valid
67
+ self.errors = errors or []
@@ -0,0 +1,60 @@
1
+ """
2
+ Copyright (c) 2025 Michael Hart: https://github.com/michaelhart/meshcore-decoder
3
+ MIT License
4
+
5
+ MeshCore packet type definitions
6
+ Reference: https://github.com/meshcore-dev/MeshCore/blob/main/docs/packet_structure.md
7
+ """
8
+
9
+ from enum import Enum
10
+
11
+
12
+ class RouteType(Enum):
13
+ TransportFlood = 0x00
14
+ Flood = 0x01
15
+ Direct = 0x02
16
+ TransportDirect = 0x03
17
+
18
+
19
+ 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
32
+
33
+
34
+ class PayloadVersion(Enum):
35
+ Version1 = 0x00
36
+ Version2 = 0x01
37
+ Version3 = 0x02
38
+ Version4 = 0x03
39
+
40
+
41
+ class DeviceRole(Enum):
42
+ ChatNode = 0x01
43
+ Repeater = 0x02
44
+ RoomServer = 0x03
45
+ Sensor = 0x04
46
+
47
+
48
+ class AdvertFlags(Enum):
49
+ HasLocation = 0x10
50
+ HasFeature1 = 0x20
51
+ HasFeature2 = 0x40
52
+ HasName = 0x80
53
+
54
+
55
+ class RequestType(Enum):
56
+ GetStats = 0x01
57
+ Keepalive = 0x02 # deprecated
58
+ GetTelemetryData = 0x03
59
+ GetMinMaxAvgData = 0x04
60
+ GetAccessList = 0x05