feat(#1158): refuse a local CLI send the radio can't run, and say why

Epic #1155, owner decision 2 (2026-11-19): block the write, not only the
button. LocalCliService.run refuses before building frame 66 when
supportsLocalCli is false: nothing is sent, a warning is logged (without
the command text, which may hold a secret), and LocalCliUnsupported is
thrown. LocalCliTransport maps it to CliConsoleUnsupported, and the
console adds a row that stays in the transcript: "<cmd>: not sent. Your
radio's firmware doesn't support the device CLI." English key only;
untranslated.json regenerated (17 locales fall back to English).

The existing local CLI suites now connect a stock 1.18 radio first,
since an unclassified connector no longer sends frame 66.

Tests: 40 pass across the service, console and transport suites. With
the refusal check removed, the 2 refusal tests fail.

Agent: BrightForge (session 440fbe94)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pull/1188/head
diffwireauto 1 week ago committed by Strycher
parent e80f3624c2
commit 16ca4fd6a6

@ -240,6 +240,15 @@
}
}
},
"deviceCli_localUnsupported": "{command}: not sent. Your radio's firmware doesn't support the device CLI.",
"@deviceCli_localUnsupported": {
"description": "Console row when the client refuses to send a local CLI command because the connected radio does not support the device CLI (#1158). Nothing was transmitted.",
"placeholders": {
"command": {
"type": "String"
}
}
},
"deviceCli_sendFailed": "Send failed: {error}",
"@deviceCli_sendFailed": {
"placeholders": {

@ -790,6 +790,12 @@ abstract class AppLocalizations {
/// **'{command}: not sent. Your radio\'s firmware doesn\'t support remote CLI.'**
String deviceCli_remoteUnsupported(String command);
/// Console row when the client refuses to send a local CLI command because the connected radio does not support the device CLI (#1158). Nothing was transmitted.
///
/// In en, this message translates to:
/// **'{command}: not sent. Your radio\'s firmware doesn\'t support the device CLI.'**
String deviceCli_localUnsupported(String command);
/// No description provided for @deviceCli_sendFailed.
///
/// In en, this message translates to:

@ -386,6 +386,11 @@ class AppLocalizationsBg extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -389,6 +389,11 @@ class AppLocalizationsDe extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -383,6 +383,11 @@ class AppLocalizationsEn extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -387,6 +387,11 @@ class AppLocalizationsEs extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -389,6 +389,11 @@ class AppLocalizationsFr extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -386,6 +386,11 @@ class AppLocalizationsHu extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -389,6 +389,11 @@ class AppLocalizationsIt extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -376,6 +376,11 @@ class AppLocalizationsJa extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -375,6 +375,11 @@ class AppLocalizationsKo extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -385,6 +385,11 @@ class AppLocalizationsNl extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -390,6 +390,11 @@ class AppLocalizationsPl extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -388,6 +388,11 @@ class AppLocalizationsPt extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -388,6 +388,11 @@ class AppLocalizationsRu extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -387,6 +387,11 @@ class AppLocalizationsSk extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -385,6 +385,11 @@ class AppLocalizationsSl extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -384,6 +384,11 @@ class AppLocalizationsSv extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -387,6 +387,11 @@ class AppLocalizationsUk extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -373,6 +373,11 @@ class AppLocalizationsZh extends AppLocalizations {
return '$command: not sent. Your radio\'s firmware doesn\'t support remote CLI.';
}
@override
String deviceCli_localUnsupported(String command) {
return '$command: not sent. Your radio\'s firmware doesn\'t support the device CLI.';
}
@override
String deviceCli_sendFailed(String error) {
return 'Send failed: $error';

@ -233,11 +233,14 @@ class _DeviceCliScreenState extends State<DeviceCliScreen> {
);
} on CliConsoleUnsupported {
if (!mounted) return;
// The connected radio refused the send itself (pre-1.18 firmware), so
// nothing went out: say so now instead of waiting out a timeout that
// would blame the target.
// Nothing went out: the radio refused a remote send (pre-1.18 firmware),
// or the client refused a local one (#1158). Say so now instead of
// waiting out a timeout that would blame the target. The row stays in
// the transcript, so the error persists until the console is closed.
entry = _ConsoleEntry.sendFailed(
context.l10n.deviceCli_remoteUnsupported(command),
_isRemote
? context.l10n.deviceCli_remoteUnsupported(command)
: context.l10n.deviceCli_localUnsupported(command),
);
} catch (e) {
if (!mounted) return;

@ -37,10 +37,11 @@ class CliConsoleTimeout implements Exception {
String toString() => 'CLI command timed out after $secondsText s';
}
/// The connected radio refused to send a remote CLI command at all: its
/// firmware does not accept TXT_TYPE_CLI_COMMAND (pre-1.18 answers
/// ERR_CODE_UNSUPPORTED_CMD). Distinct from [CliConsoleTimeout], which means
/// the command went out and the target never answered.
/// The command was not run because the connected radio cannot run it. Remote:
/// its firmware refused TXT_TYPE_CLI_COMMAND (pre-1.18 answers
/// ERR_CODE_UNSUPPORTED_CMD). Local: the client refused before sending, as the
/// radio does not support the device CLI (#1158). Distinct from
/// [CliConsoleTimeout], which means the command went out and nothing answered.
class CliConsoleUnsupported implements Exception {
const CliConsoleUnsupported({required this.command});
@ -73,6 +74,8 @@ class LocalCliTransport implements CliConsoleTransport {
return await _service.run(command, timeout: timeout);
} on LocalCliTimeout catch (e) {
throw CliConsoleTimeout(command: command, secondsText: e.secondsText);
} on LocalCliUnsupported {
throw CliConsoleUnsupported(command: command);
}
}

@ -3,8 +3,10 @@
// correlated RESP_CODE_CLI_REPLY. No mesh legs, so no retries: the transport
// is the connected link, and a lost frame surfaces as a timeout.
//
// Population gating is NOT here: callers (the console entry point, #884)
// must only construct/offer this where the classifier allows frame 66.
// Callers (the console entry point, #884) only offer this where the radio
// supports frame 66. This also refuses the WRITE when it does not (#1158), so a
// caller that slips past the entry gate gets a loud, explained refusal rather
// than a frame the radio cannot run.
import 'dart:async';
@ -28,6 +30,17 @@ class LocalCliTimeout implements Exception {
String toString() => 'CLI command timed out after $secondsText s';
}
/// Thrown, before anything is sent, when the connected radio does not run the
/// local CLI ([MeshCoreConnector.supportsLocalCli] is false) (#1158).
class LocalCliUnsupported implements Exception {
const LocalCliUnsupported({required this.command});
final String command;
@override
String toString() => 'The connected radio does not support the device CLI';
}
class LocalCliService {
LocalCliService(this._connector) {
_detach = _connector.addCliReplyListenerForLocalCli(_handleReply);
@ -46,8 +59,18 @@ class LocalCliService {
static const Duration defaultTimeout = Duration(seconds: 10);
/// Sends [command] to the connected device; completes with the correlated
/// reply or throws [LocalCliTimeout] / [ArgumentError] (codec rejections).
/// reply or throws [LocalCliTimeout] / [ArgumentError] (codec rejections) /
/// [LocalCliUnsupported] (nothing sent).
Future<CliReply> run(String command, {Duration? timeout}) async {
if (!_connector.supportsLocalCli) {
// The command text is not logged: it may carry a secret (set wifi.pwd).
appLogger.warn(
'CLI command refused, not sent: the connected radio does not '
'support the device CLI',
tag: 'LocalCli',
);
throw LocalCliUnsupported(command: command);
}
final window = timeout ?? defaultTimeout;
final prefix = _prefixes.next(_pending.keys.toSet());
final frame = buildRunCliCommandFrame(command, prefix: prefix);

@ -64,6 +64,14 @@ void main() {
sent = [];
connector.sendFrameOverrideForTest = sent.add;
connector.setConnectedForTest();
// A stock 1.18 radio, so the console may send frame 66 (#1158).
final v = ascii.encode('v1.18.0');
final info = Uint8List(82)
..[0] = 13
..[1] = 14
..setRange(60, 60 + v.length, v);
connector.handleFrameForTest(info);
sent.clear();
});
tearDown(() async {
@ -398,4 +406,35 @@ void main() {
expect(find.textContaining('may not allow remote CLI'), findsNothing);
});
});
// #1158: a local command on a radio without the device CLI is refused before
// anything is sent, and the console row says why and stays.
testWidgets('local: a radio without the device CLI refuses, nothing sent', (
tester,
) async {
final v = ascii.encode('1.4.0-1.17.0');
final offband = Uint8List(87)
..[0] = 13
..[1] = 22
..setRange(60, 60 + v.length, v);
connector.handleFrameForTest(offband);
sent.clear();
await pumpScreen(tester);
await send(tester, 'get radio');
await tester.pumpAndSettle();
expect(
find.text(
"get radio: not sent. Your radio's firmware doesn't support the "
'device CLI.',
),
findsOneWidget,
);
expect(
sent.where((f) => f.isNotEmpty && f[0] == cmdRunCliCommand),
isEmpty,
);
expect(find.textContaining('no reply'), findsNothing);
});
}

@ -5,6 +5,8 @@ import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/cli_command_codec.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/connector/offband_capability_advert.dart';
import 'package:meshcore_open/connector/offband_device_ui.dart';
import 'package:meshcore_open/services/app_debug_log_service.dart';
import 'package:meshcore_open/services/command_correlation.dart';
import 'package:meshcore_open/services/local_cli_service.dart';
@ -14,6 +16,24 @@ import 'package:meshcore_open/storage/drift/offband_database.dart';
import 'package:meshcore_open/storage/prefs_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
Uint8List _deviceInfo(int length, int verCode, String version) {
final v = ascii.encode(version);
final f = Uint8List(length);
f[0] = 13;
f[1] = verCode;
f.setRange(60, 60 + v.length, v);
return f;
}
Uint8List stock118DeviceInfo() => _deviceInfo(82, 14, 'v1.18.0');
Uint8List offbandDeviceInfo() => _deviceInfo(87, 22, '1.8.0-1.18.0');
Uint8List advert(List<int> tags) => Uint8List.fromList([
cmdOffbandDeviceUi,
offbandUiInfoGet,
for (final t in tags) ...[t, 0x00],
]);
void main() {
group('PrefixAllocator / splitCorrelated', () {
test('allocates unique XX| tokens and skips in-flight ones', () {
@ -57,6 +77,9 @@ void main() {
sent = [];
connector.sendFrameOverrideForTest = sent.add;
connector.setConnectedForTest();
// A stock 1.18 radio, so the service may send frame 66 (#1158).
connector.handleFrameForTest(stock118DeviceInfo());
sent.clear();
service = LocalCliService(connector);
});
@ -74,6 +97,39 @@ void main() {
]);
}
// #1158: block the write, not only the button.
test('a radio without the device CLI: refused, nothing sent', () async {
connector.handleFrameForTest(offbandDeviceInfo());
connector.handleFrameForTest(advert([offbandInfoTagCliRemote]));
sent.clear();
await expectLater(
service.run('get radio'),
throwsA(
isA<LocalCliUnsupported>().having(
(e) => e.command,
'command',
'get radio',
),
),
);
expect(
sent.where((f) => f.isNotEmpty && f[0] == cmdRunCliCommand),
isEmpty,
);
});
test('an Offband radio advertising 0x06: the command goes out', () async {
connector.handleFrameForTest(offbandDeviceInfo());
connector.handleFrameForTest(advert([offbandInfoTagCliLocal]));
sent.clear();
final future = service.run('get radio');
expect(sent.single[0], cmdRunCliCommand);
connector.handleFrameForTest(replyFor(sent.single, '> ok'));
expect((await future).text, '> ok');
});
test('round trip: command out, correlated reply completes it', () async {
final future = service.run('get radio');
expect(sent, hasLength(1));

@ -20,6 +20,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -433,6 +434,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -846,6 +848,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -1259,6 +1262,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -1672,6 +1676,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -2085,6 +2090,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -2498,6 +2504,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -2911,6 +2918,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -3324,6 +3332,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -3737,6 +3746,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -4150,6 +4160,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -4563,6 +4574,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -4976,6 +4988,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -5389,6 +5402,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -5802,6 +5816,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -6215,6 +6230,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",
@ -6628,6 +6644,7 @@
"deviceCli_noReply",
"deviceCli_remoteNoReply",
"deviceCli_remoteUnsupported",
"deviceCli_localUnsupported",
"deviceCli_sendFailed",
"deviceCli_truncatedByDevice",
"deviceCli_secretLongPressToCopy",

Loading…
Cancel
Save

Powered by TurnKey Linux.