meshtastic 0.0.183 → 0.0.184

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eea2644a6ee8e957223fd803b7b2e944bf0ceb1ca43704da2a58ebdfd6354aff
4
- data.tar.gz: cf26d06b47b3bf0f7ec8d006dd791c77ce077b9b75e51e23a5b5b447d3906472
3
+ metadata.gz: 763ef1042cfde175868eab3896f7b53eaa75daf8984e64295b1b6db22a39a31e
4
+ data.tar.gz: eb3ba83188a23a19013c769fd8181962c8d8e0ca9e35c98a8c87efa600bef281
5
5
  SHA512:
6
- metadata.gz: d1b64a05eba845736dd161a666e98464315fecfa242ccff79bf915711dd88a453cfe438788738070202f5e8d2c07f9e3657e102bfd42a020881c449e2a71ff63
7
- data.tar.gz: cbd371281dd057d34c6e2d9c8bb697996b0c8e646ab6b475da637c579009cfc7095f6122e5a4a223c17ed358259d3bb701b1ae8bc70e98f7bffa18eb812cb75e
6
+ metadata.gz: 03e7f64573c6baaa1a52624a184dd6c119f3e56fa0dd39dae82ed3540451fd835e6783fc59a6dd7cc2af2a3b0fe965c70c64a6049e0626f225762e6185141765
7
+ data.tar.gz: 394b62b327b1ca44b89d961f2896d9e1c1389a677353314cd7319a589e009372ab56868fb5ece662d84d6f2e0a1a3e29d9b13f622e89d9c85c417acbb7f2d19c
@@ -28,6 +28,7 @@ Do not open Serial and Bluetooth to the same radio at once. Always `disconnect`
28
28
  ## Feature modules
29
29
 
30
30
  - [Meshtastic::Admin](admin.md)
31
+ - [Meshtastic::Admin::Backup](admin-backup.md)
31
32
  - [Meshtastic::Admin::Channel](admin-channel.md)
32
33
  - [Meshtastic::Admin::Config](admin-config.md)
33
34
  - [Meshtastic::Admin::Firmware](admin-firmware.md)
@@ -0,0 +1,369 @@
1
+ # Admin::Backup — native host-side configuration snapshots
2
+
3
+ `Meshtastic::Admin::Backup` exports a versioned JSON document (default) or binary
4
+ Meshtastic `DeviceProfile` (`format: :device_profile`) using fresh,
5
+ request-ID/source-correlated Admin requests. It imports validated protobuf
6
+ sections with bounded routing ACK waits. It does not invoke the firmware's
7
+ filesystem backup/restore commands or shell out to another client.
8
+
9
+ **Backups contain secrets by default**, including channel PSKs, Wi-Fi/MQTT
10
+ credentials, private security keys and UI PINs when firmware returns them in
11
+ selected sections. Keep the file and returned Hash private; do not print either
12
+ in logs. Firmware can redact secrets or return default/empty values. Such a
13
+ snapshot cannot recover values the device did not disclose. Importing those
14
+ values can clear existing settings. Review the selection before exporting and
15
+ before restoring, especially across devices or firmware versions.
16
+
17
+ ## Export
18
+
19
+ ```ruby
20
+ require 'meshtastic'
21
+ require 'meshtastic/admin/backup'
22
+
23
+ snapshot = Meshtastic::Admin::Backup.export(
24
+ transport_obj: connection,
25
+ path: '/private/directory/node-backup.json', # optional; MUST NOT exist
26
+ config_types: %i[DEVICE_CONFIG POSITION_CONFIG POWER_CONFIG DISPLAY_CONFIG LORA_CONFIG],
27
+ module_config_types: %i[MQTT_CONFIG TELEMETRY_CONFIG],
28
+ channel_indexes: [0, 1],
29
+ include_owner: true,
30
+ include_ui: false,
31
+ timeout: 10
32
+ )
33
+ # Safe to display status/count; NOT snapshot[:backup].
34
+ snapshot.slice(:status, :count)
35
+ ```
36
+
37
+ `transport_obj:` is a connected Serial, Bluetooth or TCP handle with a receive
38
+ queue. **MQTT synchronous export/import is explicitly unsupported**, including
39
+ dry runs. `to:` optionally selects a unicast target; otherwise the connected
40
+ local node is used. `channel:` and `hop_limit:` are Admin delivery options.
41
+ Pause external queue consumers and do not interleave other Admin edits with a
42
+ backup/restore. The underlying Admin layer serializes individual requests,
43
+ not an entire multi-request snapshot or transaction.
44
+
45
+ JSON selection defaults (binary-specific differences are listed below):
46
+
47
+ - `include_owner: true`: only `long_name`, `short_name`, `is_licensed`.
48
+ Never clone User ID, MAC, hardware model, public key, role or messaging
49
+ capability metadata. Role belongs to device configuration; security keys
50
+ belong to explicitly selected security configuration.
51
+ - `config_types:` defaults to `DEVICE_CONFIG`, `POSITION_CONFIG`, `POWER_CONFIG`,
52
+ `NETWORK_CONFIG`, `DISPLAY_CONFIG`, `LORA_CONFIG`, `BLUETOOTH_CONFIG`,
53
+ `SECURITY_CONFIG`. Use a narrower list for firmware that lacks sections.
54
+ - `module_config_types: []`: opt in to supported module ConfigType symbols.
55
+ All 17 currently generated ModuleConfig sections are supported, including
56
+ `EXTNOTIF_CONFIG`, `STOREFORWARD_CONFIG`, `CANNEDMSG_CONFIG`,
57
+ `STATUSMESSAGE_CONFIG`, `TRAFFICMANAGEMENT_CONFIG`, `TAK_CONFIG`,
58
+ `MESHBEACON_CONFIG`. `Backup::MODULE_TYPES` lists the complete set.
59
+ - `channel_indexes: [0, 1, 2, 3, 4, 5, 6, 7]`: explicit zero-based slots,
60
+ including disabled channels. Wire getters use one-based indexes.
61
+ - `include_ui: false`: opt in to dedicated get/store UI operations.
62
+ - `timeout: 10`: positive finite seconds **per Admin request**, not a deadline
63
+ for the entire backup. Remote writes can first acquire an Admin session.
64
+
65
+ Unsupported selected sections fail the export; they are not silently skipped.
66
+ No file is created until every selected response has been collected and the
67
+ document validated. Empty JSON selections are allowed. A successful JSON return contains
68
+ `:status => :exported`, `:count`, `:backup` and `:warnings`. A read error raises.
69
+ Snapshots are sequential fresh reads, not an atomic device-wide snapshot.
70
+
71
+ Files are exclusively created with mode `0600`, `O_EXCL` and `O_NOFOLLOW`, then
72
+ flushed and fsynced. There is no overwrite flag. Existing files and final-path
73
+ symlinks fail. Use a trusted parent directory: parent-directory symlinks are not
74
+ resolved or pinned. A disk write/sync failure raises and can leave a partial
75
+ 0600 file; it is never reported as a successful backup. File mode protection is
76
+ not encryption and does not protect against privileged host access.
77
+
78
+ ## Validate, plan and import
79
+
80
+ ```ruby
81
+ plan = Meshtastic::Admin::Backup.import(
82
+ transport_obj: connection,
83
+ path: '/private/directory/node-backup.json',
84
+ dry_run: true
85
+ )
86
+
87
+ result = Meshtastic::Admin::Backup.import(
88
+ transport_obj: connection,
89
+ backup: snapshot[:backup], # use exactly one of backup: or path:
90
+ edit_transaction: true, # ONLY when target firmware supports it
91
+ verify: true,
92
+ timeout: 10
93
+ )
94
+ ```
95
+
96
+ `dry_run: true` performs **no radio requests or writes**, including no session
97
+ acquisition, edit begin, getters or readback. It validates the entire document
98
+ first. `dry_run`, `edit_transaction` and `verify` default to `false` and must be
99
+ booleans. Unknown options are rejected. Import paths must be regular files and
100
+ must not be final-path symlinks.
101
+
102
+ The importer rejects incompatible format/version, unknown document/record/
103
+ protobuf fields, unknown section selectors, duplicate section/slot records,
104
+ invalid channel indexes, section/slot mismatches, conflicting oneofs, malformed
105
+ protobuf scalar values, null values and noncanonical bytes/base64 **before any
106
+ radio request**. A version-1 document is a Hash with string keys:
107
+
108
+ ```json
109
+ {
110
+ "format": "meshtastic-admin-backup",
111
+ "version": 1,
112
+ "warning": "A human-readable limitations notice",
113
+ "records": [
114
+ {
115
+ "section": "config",
116
+ "slot": "DEVICE_CONFIG",
117
+ "value": { "device": { "serial_enabled": false } }
118
+ }
119
+ ]
120
+ }
121
+ ```
122
+
123
+ Sections are `owner`, `config`, `module_config`, `channel`, `ui`. Owner/UI slots
124
+ are JSON null; config/module slots are uppercase enum names; channel slots are
125
+ integers. `value` is protobuf JSON with **snake_case protobuf field names**,
126
+ canonical base64 bytes, protobuf enum representations and emitted scalar
127
+ defaults. Known fields and protobuf presence/default semantics round-trip;
128
+ unknown binary wire fields are not archived. This is not an opaque protobuf
129
+ wire backup. Missing fields in a manually edited document mean protobuf
130
+ defaults, not a patch/merge. YAML and arbitrary object deserialization are never
131
+ used. Session envelope passkeys and `SESSIONKEY_CONFIG` are never exported or
132
+ accepted; automatic session state stays inside the existing Admin connection.
133
+
134
+ Writes preserve input order within priority groups: ordinary owner/module/UI/
135
+ core settings first, channels next, then LoRa, Bluetooth, network and security.
136
+ These latter settings can disrupt the connection. Other firmware-specific
137
+ settings can also disrupt it; ordering cannot guarantee connectivity.
138
+
139
+ ## Binary DeviceProfile (`.cfg`) export and import
140
+
141
+ Select binary output explicitly; export accepts only `format: :json` (default)
142
+ or `format: :device_profile`, not `:auto`. The path extension does not choose
143
+ export format. JSON version-1 output and return keys are unchanged.
144
+
145
+ ```ruby
146
+ snapshot = Meshtastic::Admin::Backup.export(
147
+ transport_obj: connection,
148
+ format: :device_profile,
149
+ path: '/private/directory/nodeConfig.cfg', # optional; MUST NOT exist
150
+ config_types: %i[DEVICE_CONFIG POSITION_CONFIG LORA_CONFIG],
151
+ module_config_types: %i[MQTT_CONFIG TELEMETRY_CONFIG],
152
+ channel_indexes: [0, 1], # actual contiguous PRIMARY/SECONDARY slots only
153
+ include_owner: true,
154
+ include_ui: false,
155
+ include_ringtone: true,
156
+ include_canned_messages: true,
157
+ timeout: 10
158
+ )
159
+ # Safe status fields only. NEVER print backup bytes or decoded profile.
160
+ snapshot.slice(:status, :format, :count)
161
+ # snapshot[:backup] is a raw ASCII-8BIT String, not JSON/base64 or a protobuf object.
162
+ # Pass it directly to Backup.import(transport_obj: connection,
163
+ # backup: snapshot[:backup], dry_run: true).
164
+ ```
165
+
166
+ Binary returns `{ status: :exported, format: :device_profile, count: Integer,
167
+ backup: binary_string, warnings: [...] }`. `count` is the number of restorable
168
+ sections (owner counts once, each channel counts once, duplicate URL/config
169
+ LoRa counts once), not the byte count or number of protobuf fields. The `.cfg`
170
+ file contains exactly `snapshot[:backup]`. File protections are the same
171
+ exclusive/no-follow 0600 creation, flush and fsync as JSON. No file is created
172
+ until reads and strict binary validation succeed.
173
+
174
+ Binary selection uses the same core/module/owner/channel defaults as JSON,
175
+ with these format-specific rules:
176
+
177
+ - All eight core and 17 module selections are supported. Present empty nested
178
+ messages, byte fields, repeated values and scalar defaults round-trip. Local
179
+ container storage versions are not invented.
180
+ - Owner names and license flag are explicitly present, including empty names
181
+ and `false`. Optional `is_unmessagable` is copied only when present in the
182
+ fresh User response, including explicitly present `false`. ID, MAC, hardware,
183
+ public key and envelope session passkeys are not copied.
184
+ - `include_ui: true` is **rejected before any radio requests**: DeviceProfile
185
+ has no UI field. Use JSON for UI snapshots.
186
+ - ChannelSet URLs cannot preserve arbitrary indexes or disabled slots. Select
187
+ `channel_indexes: []` to omit channels, or an ordered contiguous prefix such
188
+ as `[0]` or `[0, 1]`. Sparse/reordered selections are rejected before requests.
189
+ Returned slot 0 must be PRIMARY, later selected slots SECONDARY, each with
190
+ settings; mismatched indexes, disabled slots and other roles fail export
191
+ without creating a file. No selected channel is silently skipped or moved.
192
+ **The default all-eight selection therefore fails if any slot is disabled**;
193
+ choose the actual enabled prefix or use JSON to preserve disabled/sparse slots.
194
+ Selected LoRa is included identically in both `config.lora` and the URL;
195
+ if LoRa is not selected, the URL does not invent or fetch it. Unselected
196
+ trailing channel slots are not disabled by a later binary import.
197
+ - `include_ringtone: true` and `include_canned_messages: true` request fresh
198
+ strings and preserve present empty strings. Both default to false and are
199
+ binary-only options; JSON rejects these keys rather than ignoring them.
200
+ - `fixed_position:` optionally accepts an explicit `Meshtastic::Position` or
201
+ field Hash, e.g. `{ latitude_i: 0, longitude_i: 0, altitude: 0 }`. It is
202
+ validated before any requests and copied with protobuf presence/defaults.
203
+ This is caller-supplied input, **not a fresh radio read**: no dedicated Admin
204
+ getter exists. It defaults to absent and is binary-only. No position is
205
+ inferred from cached GPS data or the position configuration.
206
+ - An entirely empty binary selection is rejected before requests because it
207
+ would not produce an importable profile. JSON still permits empty records.
208
+
209
+ The importer accepts the same binary `meshtastic.DeviceProfile` used by
210
+ Meshtastic clients, entirely in Ruby.
211
+ Use exactly one source and select `format: :device_profile` explicitly, or use
212
+ `format: :auto` (the default for import):
213
+
214
+ ```ruby
215
+ plan = Meshtastic::Admin::Backup.import(
216
+ transport_obj: connection,
217
+ path: '/private/directory/nodeConfig.cfg',
218
+ format: :device_profile,
219
+ dry_run: true
220
+ )
221
+ # Only section/slot identities and counts are returned; no profile contents.
222
+ plan.slice(:status, :planned, :plan)
223
+
224
+ # Alternative in-memory source, still offline validation with no radio requests:
225
+ plan = Meshtastic::Admin::Backup.import(
226
+ transport_obj: connection,
227
+ backup: binary_profile_string,
228
+ format: :device_profile,
229
+ dry_run: true
230
+ )
231
+ ```
232
+
233
+ `format:` accepts only `:auto`, `:json`, or `:device_profile`. In auto mode a
234
+ `.cfg` path (case-insensitive) selects binary, `.json` selects JSON, and a Hash
235
+ selects the existing JSON document API. Other paths and Strings are validated
236
+ as binary first, then as JSON when JSON-looking content fails binary validation.
237
+ This avoids confusing a valid binary name field beginning with a newline and
238
+ `{` with JSON. Explicit format overrides the extension. JSON Strings are also
239
+ accepted; versioned JSON Hash behavior and JSON export selections are unchanged.
240
+ No YAML, executable serialization, or implicit protobuf object input is used.
241
+
242
+ Presence-aware mapping:
243
+
244
+ - Present `long_name`, `short_name`, `is_licensed`, and `is_unmessagable` become
245
+ one `owner`/`set_owner` operation. Explicit `false` and empty names are not
246
+ treated as absent. User identity/MAC/hardware/public-key fields are never
247
+ synthesized. The Admin User schema has no presence for names/license, so
248
+ omitted members of a sent owner message carry protobuf defaults; this is not
249
+ a read/merge patch API. Firmware determines how those defaults are applied.
250
+ - Every present `LocalConfig` and `LocalModuleConfig` message becomes its own
251
+ writable Config/ModuleConfig oneof, including present empty submessages.
252
+ All eight core and 17 module sections are supported. Nested bytes, repeated
253
+ values, defaults and optional presence are retained. The local containers'
254
+ `version` fields are storage-schema metadata, not Admin settings; they are
255
+ validated but not written. A metadata-only/empty profile is rejected.
256
+ - `channel_url` must be an HTTPS `meshtastic.org/e/` or `/d/` URL with a valid
257
+ base64url ChannelSet and one through eight settings, no query or userinfo.
258
+ Settings map in order to primary slot 0 and secondary slots 1–7; unlisted
259
+ trailing slots are **not** disabled. PSK lengths and channel-name bounds are
260
+ checked. Embedded LoRa configuration is restored too. If both the profile and
261
+ URL carry LoRa, equal messages are deduplicated; conflicting messages reject
262
+ the entire profile rather than silently choosing one.
263
+ - Present `fixed_position`, `ringtone`, and `canned_messages` map respectively
264
+ to `set_fixed_position`, `set_ringtone_message`, and
265
+ `set_canned_message_module_messages`, with nil slots and matching section
266
+ names in the plan. Zero coordinates/altitude and present empty strings are
267
+ preserved. Absent fields are not turned into clears or removal operations.
268
+
269
+ The **entire** binary profile and nested ChannelSet are validated before any
270
+ Admin request, including session acquisition or begin-edit. A strict recursive
271
+ wire check rejects unknown tags (including sessionkey additions), unknown enum
272
+ values, duplicate singular fields/conflicting oneofs, invalid wire types,
273
+ truncation, oversized/noncanonical varints, invalid booleans and nonfinite
274
+ floats. Binary messages are limited to 1 MiB and 32 nested levels. Empty or
275
+ arbitrary bytes are not accepted as an empty restore. Strictness intentionally
276
+ rejects unsupported future schemas rather than dropping fields. This is format
277
+ validation, not authentication: protobuf has no file magic or signature, so a
278
+ valid nonempty DeviceProfile cannot be distinguished from another byte stream
279
+ that happens to encode the same schema. Session passkeys are never imported.
280
+
281
+ `verify: true` compares fresh owner/config/module/channel/ringtone/canned-message
282
+ responses. Fixed position has **no dedicated Admin getter**: its record reports
283
+ `readback: :unsupported`, making the overall status `:readback_incomplete` even
284
+ when all available comparisons match. No cached position or config flag is
285
+ misrepresented as fixed-position verification. All existing ACK, transaction,
286
+ no-replay, secret-handling and persistence limitations apply.
287
+
288
+ ## Transactions and failure reporting
289
+
290
+ `edit_transaction: true` explicitly sends `begin_edit_settings`, waits for its
291
+ ACK, sends each section once with a correlated ACK wait (or matching timeout
292
+ readback as described below), then sends
293
+ `commit_edit_settings` and waits again. Current upstream
294
+ [AdminModule.cpp](https://github.com/meshtastic/firmware/blob/master/src/modules/AdminModule.cpp)
295
+ implements a begin flag and commit save of configuration/module/device/channel/
296
+ node database segments. Commit also disables Bluetooth. **This is not an atomic
297
+ rollback facility**: firmware may apply values before commit, UI has its own
298
+ storage operation, and the protocol has no supported cancel/rollback here.
299
+ There is no reliable capability probe, so enable this option only with firmware
300
+ you have verified supports it. Default `false` avoids claiming universal edit
301
+ transaction support.
302
+
303
+ Result fields:
304
+
305
+ - `status`: `dry_run`, `acknowledged`, `applied`, `partial_failure`,
306
+ `readback_matched` or `readback_incomplete`. `applied` means all sections
307
+ completed, but at least one required timeout readback instead of an ACK;
308
+ it does not claim every mutation was acknowledged or persisted.
309
+ - `planned`, `attempted`, `acknowledged`, `readback_confirmed`: section counts, excluding transaction
310
+ commands and automatic session requests. Attempted is an API attempt and
311
+ does not prove the write reached the wire.
312
+ - `plan`: ordered section/slot identities, including in dry runs; no secret values.
313
+ - `acknowledged` counts only actual successful setter ACKs. `readback_confirmed`
314
+ counts only setters whose ACK timed out but whose fresh getter matched.
315
+ These counts are separate, never double-counted, and retained on later failure.
316
+ - `records`: completed section/slot statuses (`acknowledged` or
317
+ `readback_confirmed`), without configuration values.
318
+ - `transaction`: `not_requested`, `begin_uncertain`, `open`, `commit_uncertain`
319
+ or `commit_acknowledged`.
320
+ - `failure`: on write/begin/commit failure, the operation, section/slot where
321
+ applicable, exception class and routing reason where available. Exception
322
+ contents and secrets are not included. Failed timeout recovery also includes
323
+ `readback: mismatch|unsupported|failed`; getter exceptions retain their class
324
+ and routing reason where available.
325
+ - `warnings`: secret/redaction/persistence limitations.
326
+ - `persistence_verified`: always `false`.
327
+
328
+ Only a section setter's `Timeout::Error` triggers recovery: if a supported
329
+ getter exists, import issues one **new**, request-ID/source-correlated Admin GET
330
+ with its own per-request timeout. This happens even with `verify: false`.
331
+ It continues only if the entire expected protobuf setting matches, using the
332
+ same presence-aware comparison as optional verification. Portable owner fields
333
+ are compared while generated owner identity/hardware metadata is excluded.
334
+ No cached value, unrelated response, late setter ACK, or transport submission
335
+ is substituted for that fresh read. The mutation is **never resent**.
336
+
337
+ Mismatch (including redacted/empty secrets in place of expected nonempty
338
+ secrets), absent getter, getter timeout/error, and correlated routing rejection
339
+ remain partial failures. Secret fields are not ignored or treated as wildcards;
340
+ the report never includes expected/actual values. Firmware normalization can
341
+ also prevent exact matching. A matching empty/default value cannot establish
342
+ that firmware disclosed a secret; existing backup completeness limitations
343
+ still apply. Fixed-position writes have no supported getter. Begin and commit
344
+ timeouts do not use this recovery, and routing errors do not trigger it.
345
+
346
+ After an unresolved failed write, no later sections, commit, rollback or replay are sent.
347
+ A transaction may remain open. A missing commit ACK is uncertain even when all
348
+ section ACKs arrived; the node may have committed and rebooted. Inspect the
349
+ node and establish a fresh connection before deciding on any manual recovery.
350
+ Do not automatically rerun the import.
351
+
352
+ `verify: true` performs another round of fresh correlated reads **after** all
353
+ sections complete and any requested commit ACK arrives. Timeout-recovery reads
354
+ do not replace this optional post-commit check.
355
+ It compares protobuf values (only portable owner fields), adds per-record
356
+ `readback: matched|mismatch|failed` and `readback_matched` count. Redaction,
357
+ normalization, link loss or reboot can prevent a match. Readback failures never
358
+ replay writes. Even a match proves only current reported state, not persistence
359
+ across reboot or successful firmware-side storage.
360
+
361
+ ## Verification scope
362
+
363
+ The automated peer decodes production Serial framing/ToRadio/Admin protobufs,
364
+ maintains configuration state, and returns encoded correlated FromRadio Admin
365
+ or routing packets through the real Admin queue. Tests cover round-trip bytes
366
+ and defaults, dry runs, validation, secret handling, file permissions/symlinks,
367
+ ACK failures, timeouts, commit uncertainty, optional readback and help
368
+ conventions. No hardware, firmware reboot/persistence, radio-link reliability,
369
+ Bluetooth GATT or live TCP endpoint was exercised for this feature.
@@ -24,6 +24,10 @@ Every generated payload field is available through `encode` and `send`, includin
24
24
 
25
25
  ## Operation catalog
26
26
 
27
+ For host-side configuration files, use [Admin::Backup](admin-backup.md).
28
+ The `backup_preferences` / `restore_preferences` operations below instead manage
29
+ the device's own FLASH/SD preference backup; they do not export a file to the host.
30
+
27
31
  | Group | Methods and payload arguments |
28
32
  | --- | --- |
29
33
  | Identity | `get_owner`; `set_owner(owner:)` or `set_owner(long_name:, short_name:)`; `set_ham_mode(ham:)` or callsign/frequency/power/name fields |