pm5: hw bwm ble, the module's BLE settings incl. on/off and pairing

The module ships with BLE open: anyone in range can connect and run
commands, and there was no way to turn the radio off or to require
pairing from the PM5, although the module already implements bonding
with a static passkey (LE Secure Connections + MITM, SPP characteristic
encrypted) behind commands nothing exposed.

New CMD_PM5_BWM_BLE (0x0183): one action byte, then a full status
snapshot back (bwm_ble_status_t: switch, state, bonding, passkey, TX
power, address, name, bonded devices). Client menu `hw bwm ble`:
  status              everything above, with a warning while open
  on | off            persisted radio switch (needs the companion
                      Proxmark5_BWM_esp32 PR; off =
                      nothing can connect, USB/WiFi only)
  pairing on|off [-k] require the 6-digit passkey, set the passkey; a
                      change of on/off restarts the stack (drops a
                      connected client), the factory key 123456 is
                      flagged
  forget -i N | --all remove bonded devices
  txpower -a/-c dBm   advertising / connection power, -24..18 and 20

The firmware replies before restarting the stack so the reply survives
when the command itself arrived over BLE. Fields a module without the
switch cannot answer read 0xFF and print as unknown. A module that does
not answer at all ends the status snapshot after its first query instead
of running into the client's timeout.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
MsprgandClaude Fable 5.1 committed 2026-09-24 10:33:47 +02:00
1 parent 465cb47b5a
commit 39bbf20cce
8 files changed
+589 -2

No files matched your search

+22
View File
@@ -961,6 +961,28 @@ typedef struct {
#define BWM_WIFI_PS_MIN 1 // sleeps between DTIM beacons (ESP-IDF default)
#define BWM_WIFI_PS_MAX 2 // sleeps for the listen interval
#define BWM_WIFI_STATE_OFF 0xFF // wifi_state byte: WiFi stack down (BLE-only)
// PM5, BWM BLE settings (`hw bwm ble`). req: [action:u8][args]; resp: bwm_ble_status_t
// on success. Unknown fields (module firmware without the command) read 0xFF.
#define CMD_PM5_BWM_BLE 0x0183
#define BWM_BLE_ACTION_STATUS 0x00
#define BWM_BLE_ACTION_ENABLE 0x01 // [on:u8], persisted on the module
#define BWM_BLE_ACTION_PAIRING 0x02 // [on:u8], persisted; restarts the stack (drops a BLE client)
#define BWM_BLE_ACTION_KEY 0x03 // [6 ASCII digits], persisted
#define BWM_BLE_ACTION_FORGET 0x04 // [idx:u8, 0xFF = all bonded devices]
#define BWM_BLE_ACTION_TXPOWER 0x05 // [type:u8 0 adv 1 conn][level:u8 esp_power_level_t 0..15, -24 dBm + 3/step, 15 = 20 dBm]
#define BWM_BLE_BONDED_MAX 8
typedef struct {
uint8_t enabled; // persisted switch
uint8_t state; // 0 off, 1 advertising, 2 client connected
uint8_t bonding; // 1 = pairing with passkey required, SPP characteristic encrypted
char passkey[6]; // ASCII digits, not NUL-terminated
uint8_t txp_adv; // esp_power_level_t index
uint8_t txp_conn;
uint8_t addr[6]; // as the module reports it (big-endian display order)
char name[16]; // NUL-padded
uint8_t bonded_count;
uint8_t bonded[BWM_BLE_BONDED_MAX][7]; // addr[6] + type, first bonded_count valid
} PACKED bwm_ble_status_t;
#define BWM_OTA_ACTION_BEGIN 0x00
#define BWM_OTA_ACTION_WRITE 0x01
#define BWM_OTA_ACTION_END 0x02