Skip to content

Commit

Permalink
Add decoder for decrypted payload of PVVX encrypted advertisements
Browse files Browse the repository at this point in the history
  • Loading branch information
koenvervloesem committed Jul 7, 2023
1 parent 58db767 commit aab680b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TheengsDecoder {
LYWSD03MMC_ATC,
LYWSD03MMC_PVVX,
LYWSD03MMC_PVVX_ENCR,
LYWSD03MMC_PVVX_DECR,
CGPR1,
THERMOBEACON,
H5055,
Expand Down
1 change: 1 addition & 0 deletions src/devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const char* _devices[][2] = {
{_LYWSD03MMC_json_ATC, _LYWSD03MMC_json_props},
{_LYWSD03MMC_json_PVVX, _LYWSD03MMC_json_props},
{_LYWSD03MMC_ENCR_json_PVVX, _LYWSD03MMC_ENCR_json_props},
{_LYWSD03MMC_json_PVVX_DECR, _LYWSD03MMC_json_props},
{_CGPR1_json, _CGPR1_json_props},
{_ThermoBeacon_json, _ThermoBeacon_json_props},
{_H5055_json, _H5055_json_props},
Expand Down
23 changes: 23 additions & 0 deletions src/devices/LYWSD03MMC_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,27 @@ const char* _LYWSD03MMC_json_PVVX = "{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor
}
})"""";*/

const char* _LYWSD03MMC_json_PVVX_DECR = "{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX_DECR\",\"tag\":\"01\",\"condition\":[\"servicedata\",\"=\",12,\"&\",\"uuid\",\"index\",0,\"181a\"],\"properties\":{\"tempc\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",0,4,true,true],\"post_proc\":[\"/\",100]},\"hum\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",4,4,true,false],\"post_proc\":[\"/\",100]},\"batt\":{\"decoder\":[\"value_from_hex_data\",\"servicedata\",8,2,false,false]}}}";
/* R""""(
{
"brand":"Xiaomi",
"model":"TH Sensor",
"model_id":"LYWSD03MMC/MJWSD05MMC_PVVX_DECR",
"tag":"01",
"condition":["servicedata", "=", 12, "&", "uuid", "index", 0, "181a"],
"properties":{
"tempc":{
"decoder":["value_from_hex_data", "servicedata", 0, 4, true, true],
"post_proc":["/", 100]
},
"hum":{
"decoder":["value_from_hex_data", "servicedata", 4, 4, true, false],
"post_proc":["/", 100]
},
"batt":{
"decoder":["value_from_hex_data", "servicedata", 8, 2, false, false]
}
}
})"""";*/

const char* _LYWSD03MMC_json_props = _common_BVTH_props;
5 changes: 4 additions & 1 deletion tests/BLE/test_ble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const char* expected_uuid_name_svcdata[] = {
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1\",\"model_id\":\"SBBT-002C\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"packet\":171,\"batt\":100,\"press\":1}",
"{\"brand\":\"Shelly\",\"model\":\"ShellyBLU Button1 encrypted\",\"model_id\":\"SBBT_002C_ENCR\",\"type\":\"BTN\",\"acts\":true,\"cont\":true,\"encr\":true,\"cipher\":\"62511158bd25\",\"ctr\":\"b8f09364\",\"mic\":\"5b573115\"}",
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX_ENCR\",\"type\":\"THB\",\"encr\":true,\"cipher\":\"ef56583dd420\",\"ctr\":\"23\",\"mic\":\"50fe8e4d\"}",
"{\"brand\":\"Xiaomi\",\"model\":\"TH Sensor\",\"model_id\":\"LYWSD03MMC/MJWSD05MMC_PVVX_DECR\",\"type\":\"THB\",\"tempc\":24.60,\"tempf\":76.28,\"hum\":43.54,\"batt\":100}",
};

const char* expected_uuid[] = {
Expand Down Expand Up @@ -605,7 +606,8 @@ const char* test_uuid_name_svcdata[][4] = {
{"SBBT-002C long press", "0xfcd2", "SBBT-002C", "40002001643a04"},
{"SBBT-002C press", "0xfcd2", "SBBT-002C", "4400ab01643a01"},
{"SBBT-002C encrypted", "0xfcd2", "SBBT-002C", "4562511158bd25b8f093645b573115"},
{"LYWSD03MMC_PVVX_ENCT", "0x181a", "ATC_9C58AB", "23ef56583dd42050fe8e4d"},
{"LYWSD03MMC_PVVX_ENCR", "0x181a", "ATC_9C58AB", "23ef56583dd42050fe8e4d"},
{"LYWSD03MMC_PVVX_DECR", "0x181a", "ATC_89DF88", "9c0902116404"},
};

TheengsDecoder::BLE_ID_NUM test_uuid_name_svcdata_id_num[]{
Expand Down Expand Up @@ -636,6 +638,7 @@ TheengsDecoder::BLE_ID_NUM test_uuid_name_svcdata_id_num[]{
TheengsDecoder::BLE_ID_NUM::SBBT_002C,
TheengsDecoder::BLE_ID_NUM::SBBT_002C_ENCR,
TheengsDecoder::BLE_ID_NUM::LYWSD03MMC_PVVX_ENCR,
TheengsDecoder::BLE_ID_NUM::LYWSD03MMC_PVVX_DECR,
};

// uuid test input [test name] [uuid] [data source] [data]
Expand Down

0 comments on commit aab680b

Please sign in to comment.