diff --git a/json/schemas/whitelabel-schema.json b/json/schemas/whitelabel-schema.json index a9444b1..2dbefe3 100644 --- a/json/schemas/whitelabel-schema.json +++ b/json/schemas/whitelabel-schema.json @@ -49,15 +49,20 @@ "description": "Max power consumption, in 2mA units", "type": ["integer", "string"], "maximum": 255, - "pattern": "^0x[0-9a-fA-F]{0,2}$" + "pattern": "^0x[0-9a-fA-F]{1,2}$" }, "attributes": { "description": "Device attributes: bit 7 must be 1, bit 6 is self-powered, bit 5 is remote wakeup, bits 0-4 must be 0", "type": ["integer", "string"], - "maximum": 255, - "pattern": "^0x[0-9a-fA-F]{0,2}$" + "minimum": 128, + "maximum": 224, + "pattern": "^0x[0-9a-fA-F]{2}$" } }, + "dependentRequired": { + "max_power": ["attributes"], + "attributes": ["max_power"] + }, "additionalProperties": false }, "scsi": { diff --git a/main.cpp b/main.cpp index 0bc722d..d1e43c2 100644 --- a/main.cpp +++ b/main.cpp @@ -7278,19 +7278,20 @@ bool otp_white_label_command::execute(device_map &devices) { // Check for separate max_power and attributes uint16_t val = 0; int hex_val = 0; - if (wl_json["device"].contains("max_power")) { + if (wl_json["device"].contains("max_power") && wl_json["device"].contains("attributes")) { if (!get_json_int(wl_json["device"]["max_power"], hex_val)) { fail(ERROR_FORMAT, "MaxPower must be an integer"); } val |= (hex_val << 8); - } - if (wl_json["device"].contains("attributes")) { + if (!get_json_int(wl_json["device"]["attributes"], hex_val)) { fail(ERROR_FORMAT, "Device Attributes must be an integer"); } else if (hex_val & 0b11111 || ~hex_val & 0x80) { fail(ERROR_FORMAT, "Device Attributes must have bit 7 set (0x80), and bits 4-0 clear"); } val |= hex_val; + } else if (wl_json["device"].contains("max_power") || wl_json["device"].contains("attributes")) { + fail(ERROR_INCOMPATIBLE, "Must specify both max_power and attributes in the JSON file"); } if (val) { fos << "Setting attributes " << hex_string(val, 4) << "\n";