diff --git a/src/improv.cpp b/src/improv.cpp index 8a540e9..7868b32 100644 --- a/src/improv.cpp +++ b/src/improv.cpp @@ -51,6 +51,17 @@ ImprovCommand parse_improv_data(const uint8_t *data, size_t length, bool check_c std::string ssid(data + ssid_start, data + ssid_end); std::string password(data + pass_start, data + pass_end); return {.command = command, .ssid = ssid, .password = password}; + } else if ((command == HOSTNAME || command == DEVICE_NAME) && data[2] > 0) { + uint8_t name_length = data[2]; + uint8_t name_start = 3; + size_t name_end = name_start + name_length; + if (name_end > length) { + improv_command.command = UNKNOWN; + return improv_command; + } + + std::string name(data + name_start, data + name_end); + return {.command = command, .name = name}; } improv_command.command = command; diff --git a/src/improv.h b/src/improv.h index d6befbd..e866e26 100644 --- a/src/improv.h +++ b/src/improv.h @@ -24,6 +24,7 @@ enum Error : uint8_t { ERROR_UNKNOWN_RPC = 0x02, ERROR_UNABLE_TO_CONNECT = 0x03, ERROR_NOT_AUTHORIZED = 0x04, + ERROR_BAD_HOSTNAME = 0x05, ERROR_UNKNOWN = 0xFF, }; @@ -42,10 +43,16 @@ enum Command : uint8_t { GET_CURRENT_STATE = 0x02, GET_DEVICE_INFO = 0x03, GET_WIFI_NETWORKS = 0x04, + HOSTNAME = 0x05, + DEVICE_NAME = 0x06, BAD_CHECKSUM = 0xFF, }; -static const uint8_t CAPABILITY_IDENTIFY = 0x01; +static const uint8_t CAPABILITY_IDENTIFY = 1 << 0; +static const uint8_t CAPABILITY_GET_DEVICE_INFO = 1 << 1; +static const uint8_t CAPABILITY_GET_WIFI_NETWORKS = 1 << 2; +static const uint8_t CAPABILITY_HOSTNAME = 1 << 3; +static const uint8_t CAPABILITY_DEVICE_NAME = 1 << 4; static const uint8_t IMPROV_SERIAL_VERSION = 1; enum ImprovSerialType : uint8_t { @@ -59,6 +66,7 @@ struct ImprovCommand { Command command; std::string ssid; std::string password; + std::string name; // hostname or device_name }; ImprovCommand parse_improv_data(const std::vector &data, bool check_checksum = true);