Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/improv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/improv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the serial version unchanged for now but this may change in the future.


enum ImprovSerialType : uint8_t {
Expand All @@ -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<uint8_t> &data, bool check_checksum = true);
Expand Down