pm5: hw bwm wifipower, WiFi off or the modem power-save type
New `hw bwm wifipower [off|none|min|max]`. `off` turns the BWM's WiFi fully off (BLE-only, persisted; the same path as `hw bwm wifi stop`, and the module's default state). The other three set the ESP's persisted WiFi modem power-save type (CMD_PM5_BWM_WIFI_PS 0x0182, module commands 2052/2053, esp_wifi_set_ps()) used while WiFi is up: min (the ESP-IDF default, the modem sleeps between DTIM beacons), max (sleeps for the whole listen interval, lowest current, slower to react), none (modem always on, lowest latency). With no argument it reports whether WiFi is up at all and the stored type. Independent of `hw bwm powersave`. The link helper's "cmd failed" diagnostic is now printed only at debug level: a status query while WiFi is off fails by design and was cluttering every call. Verified on hardware: default reads min with WiFi off; none, max and min each set and read back; off tears WiFi down; an unknown value is rejected; max survives a module reboot. Not measured with WiFi associated. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
552276c75f
commit
5e1b04def1
8 files changed
+190
-25
No files matched your search
+106
-14
@@ -697,6 +697,40 @@ static int CmdBwmName(const char *Cmd) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// Round trip for the BWM u8 settings (`hw bwm powersave`, `hw bwm wifipower`):
|
||||
// send [action][value] (value only when has_value) and wait for the ESP's answer.
|
||||
// Prints the generic failure messages; on PM3_SUCCESS resp holds >= 1 byte.
|
||||
static int bwm_setting_txn(uint16_t cmd, uint8_t action, uint8_t value, bool has_value,
|
||||
PacketResponseNG *resp, const char *what) {
|
||||
uint8_t payload[2] = { action, value };
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(cmd, payload, has_value ? 2 : 1);
|
||||
if (WaitForResponseTimeout(cmd, resp, 8000) == false) {
|
||||
PrintAndLogEx(WARNING, "command timeout (is this a PM5 with a responsive BWM?)");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
if (resp->status == PM3_ENOTIMPL) {
|
||||
PrintAndLogEx(WARNING, "firmware built without BWM link support");
|
||||
return resp->status;
|
||||
}
|
||||
if (resp->status != PM3_SUCCESS || resp->length < 1) {
|
||||
PrintAndLogEx(FAILED, "BWM did not answer the %s command (BWM firmware too old?)", what);
|
||||
return (resp->status != PM3_SUCCESS) ? resp->status : PM3_EFAILED;
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static const char *bwm_wifi_state_name(uint8_t state) {
|
||||
switch (state) {
|
||||
case 0: return "disconnected";
|
||||
case 1: return "connecting";
|
||||
case 2: return "connected";
|
||||
case 3: return "reconnecting";
|
||||
case 4: return "connect task stopped";
|
||||
default: return "unknown state";
|
||||
}
|
||||
}
|
||||
|
||||
static int CmdBwmPowerSave(const char *Cmd) {
|
||||
// Positional sub-action (no dashes): hw bwm powersave [on | off]; no verb shows the state
|
||||
char verb[16] = {0};
|
||||
@@ -728,27 +762,84 @@ static int CmdBwmPowerSave(const char *Cmd) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint8_t payload[2] = { show ? BWM_POWERSAVE_ACTION_GET : BWM_POWERSAVE_ACTION_SET, on ? 1 : 0 };
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_PM5_BWM_POWERSAVE, payload, show ? 1 : 2);
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_PM5_BWM_POWERSAVE, &resp, 5000) == false) {
|
||||
PrintAndLogEx(WARNING, "command timeout (is this a PM5 with a responsive BWM?)");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
if (resp.status == PM3_ENOTIMPL) {
|
||||
PrintAndLogEx(WARNING, "firmware built without BWM link support");
|
||||
return resp.status;
|
||||
}
|
||||
if (resp.status != PM3_SUCCESS || resp.length < 1) {
|
||||
PrintAndLogEx(FAILED, "BWM did not answer the power-save command (BWM firmware too old?)");
|
||||
return (resp.status != PM3_SUCCESS) ? resp.status : PM3_EFAILED;
|
||||
int res = bwm_setting_txn(CMD_PM5_BWM_POWERSAVE, show ? BWM_POWERSAVE_ACTION_GET : BWM_POWERSAVE_ACTION_SET,
|
||||
on ? 1 : 0, !show, &resp, "power-save");
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
bool state = (resp.data.asBytes[0] != 0);
|
||||
PrintAndLogEx(SUCCESS, "BWM power save..... %s", state ? _GREEN_("on") : _YELLOW_("off"));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static const char *bwm_wifi_ps_name(uint8_t mode) {
|
||||
switch (mode) {
|
||||
case BWM_WIFI_PS_NONE: return "none";
|
||||
case BWM_WIFI_PS_MIN: return "min";
|
||||
case BWM_WIFI_PS_MAX: return "max";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static int CmdBwmWifiPower(const char *Cmd) {
|
||||
// Positional sub-action (no dashes): hw bwm wifipower [off | none | min | max]; no verb shows the state
|
||||
char verb[16] = {0};
|
||||
sscanf(Cmd, "%15s", verb);
|
||||
int mode = -1;
|
||||
if (verb[0] == 0) {
|
||||
mode = -1;
|
||||
} else if (strcmp(verb, "off") == 0) {
|
||||
// WiFi fully off: same as `hw bwm wifi stop`.
|
||||
return CmdBWMWifi("stop");
|
||||
} else if (strcmp(verb, "none") == 0) {
|
||||
mode = BWM_WIFI_PS_NONE;
|
||||
} else if (strcmp(verb, "min") == 0) {
|
||||
mode = BWM_WIFI_PS_MIN;
|
||||
} else if (strcmp(verb, "max") == 0) {
|
||||
mode = BWM_WIFI_PS_MAX;
|
||||
} else {
|
||||
// Not a recognised sub-action: render help (also serves -h), or error on
|
||||
// a stray token, then stop.
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hw bwm wifipower",
|
||||
"Show or set how much power the BWM (ESP32) spends on WiFi.\n"
|
||||
_YELLOW_("off") " turns WiFi fully off (BLE-only, persisted; the default state, same as\n"
|
||||
"`hw bwm wifi stop`). Bring it back with " _YELLOW_("hw bwm wifi --ssid <ssid> --pwd <pwd>") ".\n"
|
||||
"The other three set the modem power-save type while WiFi is up, stored on the\n"
|
||||
"BWM: " _GREEN_("min") " (default) sleeps between DTIM beacons, " _YELLOW_("max") " for the whole\n"
|
||||
"listen interval, " _YELLOW_("none") " never. Independent of " _YELLOW_("hw bwm powersave") ". PM5 only.",
|
||||
"hw bwm wifipower --> show whether WiFi is up and the power-save type\n"
|
||||
"hw bwm wifipower off --> WiFi fully off, BLE-only\n"
|
||||
"hw bwm wifipower none --> modem always on while WiFi is up\n"
|
||||
"hw bwm wifipower min --> ESP-IDF default (DTIM sleep)\n"
|
||||
"hw bwm wifipower max --> deepest modem sleep");
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
CLIParserFree(ctx);
|
||||
PrintAndLogEx(WARNING, "specify " _YELLOW_("off") ", " _YELLOW_("none") ", " _YELLOW_("min") ", " _YELLOW_("max") " or nothing to show the state");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
PacketResponseNG resp;
|
||||
int res = bwm_setting_txn(CMD_PM5_BWM_WIFI_PS, (mode < 0) ? BWM_WIFI_PS_ACTION_GET : BWM_WIFI_PS_ACTION_SET,
|
||||
(mode < 0) ? 0 : (uint8_t)mode, mode >= 0, &resp, "WiFi power");
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
uint8_t wifi_state = (resp.length >= 2) ? resp.data.asBytes[1] : BWM_WIFI_STATE_OFF;
|
||||
if (wifi_state == BWM_WIFI_STATE_OFF) {
|
||||
PrintAndLogEx(SUCCESS, "BWM WiFi................ " _GREEN_("off") " (BLE-only)");
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "BWM WiFi................ " _YELLOW_("on") " (%s)", bwm_wifi_state_name(wifi_state));
|
||||
}
|
||||
PrintAndLogEx(SUCCESS, "BWM WiFi power save..... " _YELLOW_("%s"), bwm_wifi_ps_name(resp.data.asBytes[0]));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static command_t BwmCommandTable[] = {
|
||||
{"help", CmdHelpBwm, AlwaysAvailable, "This help"},
|
||||
{"autooff", CmdBwmAutoOff, IfBwm, "Toggle auto power-off on USB unplug"},
|
||||
@@ -759,6 +850,7 @@ static command_t BwmCommandTable[] = {
|
||||
{"upgrade", CmdBWMUpgrade, IfBwm, "Reflash BWM (ESP32) firmware over the BWM link, no header"},
|
||||
{"vchg", CmdBwmVchg, IfBwm, "Set charger charge-voltage target (default 4100 mV)"},
|
||||
{"wifi", CmdBWMWifi, IfBwm, "Bring up WiFi (STA + TCP server) for a tcp: connection"},
|
||||
{"wifipower", CmdBwmWifiPower, IfBwm, "WiFi fully off, or the modem power-save type (none/min/max)"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user