From f3f97428d23001b652186f3e1034f851cc590f64 Mon Sep 17 00:00:00 2001 From: kbx81 Date: Fri, 12 Jun 2026 01:41:10 -0500 Subject: [PATCH 1/2] Add GET_CAPABILITIES command and extend the capability bitmask Adds a GET_CAPABILITIES (0x07) RPC command. Its response returns the device capability bitmask in the first byte; when CAPABILITY_ONLINE is set, reachable device URL(s) follow as subsequent string elements. Extends the existing capability bitmask (previously just CAPABILITY_IDENTIFY) into a shared `Capability` enum -- ONLINE plus the supported network interfaces (WIFI/ETHERNET/THREAD/MODEM). The same mask is advertised over BLE, so this is purely additive (existing clients read only the bits they know). CAPABILITY_ONLINE is dynamic; a live serial query reflects it, while the BLE capabilities value is set at setup and must be updated/notified by the device to be meaningful there. 0x05 (Get/Set Hostname) and 0x06 (Get/Set Device Name) are reserved by the Improv spec, so the command uses the next free value, 0x07. No parser changes are needed: parse_improv_data passes unknown commands through and build_rpc_response writes any command byte, so older clients/devices remain compatible. --- src/improv.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/improv.h b/src/improv.h index d6befbd..454bd74 100644 --- a/src/improv.h +++ b/src/improv.h @@ -42,10 +42,26 @@ enum Command : uint8_t { GET_CURRENT_STATE = 0x02, GET_DEVICE_INFO = 0x03, GET_WIFI_NETWORKS = 0x04, + // 0x05 (Get/Set Hostname) and 0x06 (Get/Set Device Name) are reserved by the Improv spec. + GET_CAPABILITIES = 0x07, BAD_CHECKSUM = 0xFF, }; -static const uint8_t CAPABILITY_IDENTIFY = 0x01; +// Device capability bitmask. Advertised over BLE (CAPABILITIES characteristic / service data) and +// returned in the first byte of a GET_CAPABILITIES serial RPC response. When CAPABILITY_ONLINE is +// set in the serial response, any reachable device URL(s) follow as subsequent string elements. +// +// CAPABILITY_ONLINE is dynamic (current connectivity); the others are static device facts. A live +// query (serial GET_CAPABILITIES) always reflects current ONLINE state; the BLE capabilities value +// is set at setup, so a device must update/notify it for ONLINE to be meaningful over BLE. +enum Capability : uint8_t { + CAPABILITY_IDENTIFY = 0x01, // device can identify itself (e.g. flash an LED) on request + CAPABILITY_ONLINE = 0x02, // device currently has network connectivity via any interface + CAPABILITY_WIFI = 0x04, // Wi-Fi is supported (hardware present; may be disabled) + CAPABILITY_ETHERNET = 0x08, // Ethernet is supported + CAPABILITY_THREAD = 0x10, // Thread is supported + CAPABILITY_MODEM = 0x20, // Cellular modem is supported +}; static const uint8_t IMPROV_SERIAL_VERSION = 1; enum ImprovSerialType : uint8_t { From 4de6edab0f5429258dbefae6f25531ef52712c36 Mon Sep 17 00:00:00 2001 From: kbx81 Date: Mon, 15 Jun 2026 19:21:10 -0500 Subject: [PATCH 2/2] Separate network state from the capabilities bitmask Per the Improv spec, the capabilities bitmask reports which RPC commands a device supports. This reworks the connectivity reporting so it doesn't overload that bitmask: - Rename the command GET_CAPABILITIES -> GET_NETWORK_STATE (0x07). - Replace the extended capability bits with a separate NetworkState enum (NETWORK_IS_ONLINE + present interfaces NETWORK_SUPPORTS_WIFI/ETHERNET/THREAD/ MODEM), restoring CAPABILITY_IDENTIFY as the lone capability constant. Keeps connectivity ("is it online, what interfaces") distinct from capabilities ("which commands are supported"), and avoids colliding with the in-flight Improv 2.4 capabilities work (#32). --- src/improv.h | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/improv.h b/src/improv.h index 941adf8..f2ae050 100644 --- a/src/improv.h +++ b/src/improv.h @@ -44,24 +44,22 @@ enum Command : uint8_t { GET_WIFI_NETWORKS = 0x04, GET_SET_HOSTNAME = 0x05, GET_SET_DEVICE_NAME = 0x06, - GET_CAPABILITIES = 0x07, + GET_NETWORK_STATE = 0x07, BAD_CHECKSUM = 0xFF, }; -// Device capability bitmask. Advertised over BLE (CAPABILITIES characteristic / service data) and -// returned in the first byte of a GET_CAPABILITIES serial RPC response. When CAPABILITY_ONLINE is -// set in the serial response, any reachable device URL(s) follow as subsequent string elements. -// -// CAPABILITY_ONLINE is dynamic (current connectivity); the others are static device facts. A live -// query (serial GET_CAPABILITIES) always reflects current ONLINE state; the BLE capabilities value -// is set at setup, so a device must update/notify it for ONLINE to be meaningful over BLE. -enum Capability : uint8_t { - CAPABILITY_IDENTIFY = 0x01, // device can identify itself (e.g. flash an LED) on request - CAPABILITY_ONLINE = 0x02, // device currently has network connectivity via any interface - CAPABILITY_WIFI = 0x04, // Wi-Fi is supported (hardware present; may be disabled) - CAPABILITY_ETHERNET = 0x08, // Ethernet is supported - CAPABILITY_THREAD = 0x10, // Thread is supported - CAPABILITY_MODEM = 0x20, // Cellular modem is supported +static const uint8_t CAPABILITY_IDENTIFY = 0x01; + +// Network-state flags, returned in the first byte of a GET_NETWORK_STATE (0x07) RPC response. This +// is a separate bitfield from the BLE capabilities bitmask (which reports supported RPC commands). +// NETWORK_IS_ONLINE is dynamic (current connectivity); the SUPPORTS_* bits report which interfaces +// the device has. When NETWORK_IS_ONLINE is set, reachable device URL(s) follow as later elements. +enum NetworkState : uint8_t { + NETWORK_IS_ONLINE = 1 << 0, // device currently has network connectivity via any interface + NETWORK_SUPPORTS_WIFI = 1 << 1, // Wi-Fi interface present (may be disabled) + NETWORK_SUPPORTS_ETHERNET = 1 << 2, // Ethernet interface present + NETWORK_SUPPORTS_THREAD = 1 << 3, // Thread interface present + NETWORK_SUPPORTS_MODEM = 1 << 4, // Cellular modem present }; static const uint8_t IMPROV_SERIAL_VERSION = 1;