Most tests pass.

pull/156/head
Fredrik Öhrström 2020-09-08 20:50:51 +02:00
rodzic dcf67bf9b2
commit c12a0e8e19
7 zmienionych plików z 20 dodań i 12 usunięć

Wyświetl plik

@ -481,7 +481,8 @@ void perform_auto_scan_of_devices(Configuration *config)
wmbus->setLinkModes(config->listen_to_link_modes);
//string using_link_modes = wmbus->getLinkModes().hr();
//verbose("(config) listen to link modes: %s\n", using_link_modes.c_str());
wmbus->onTelegram([&](vector<uchar> data){return meter_manager_->handleTelegram(data);});
bool simulated = detected.type == WMBusDeviceType::DEVICE_SIMULATOR;
wmbus->onTelegram([&, simulated](vector<uchar> data){return meter_manager_->handleTelegram(data, simulated);});
wmbus->setTimeout(config->alarm_timeout, config->alarm_expected_activity);
}
}
@ -518,8 +519,10 @@ void detectAndConfigureWMBusDevices(Configuration *config)
wmbus->setLinkModes(config->listen_to_link_modes);
//string using_link_modes = wmbus->getLinkModes().hr();
//verbose("(config) listen to link modes: %s\n", using_link_modes.c_str());
wmbus->onTelegram([&](vector<uchar> data){return meter_manager_->handleTelegram(data);});
bool simulated = detected.type == WMBusDeviceType::DEVICE_SIMULATOR;
wmbus->onTelegram([&, simulated](vector<uchar> data){return meter_manager_->handleTelegram(data, simulated);});
wmbus->setTimeout(config->alarm_timeout, config->alarm_expected_activity);
serial_manager_->expectDevicesToWork();
}
}

Wyświetl plik

@ -60,7 +60,7 @@ struct MeterManagerImplementation : public virtual MeterManager
return meters_.size() != 0;
}
bool handleTelegram(vector<uchar> data)
bool handleTelegram(vector<uchar> data, bool simulated)
{
if (!hasMeters())
{
@ -75,7 +75,7 @@ struct MeterManagerImplementation : public virtual MeterManager
for (auto &m : meters_)
{
bool h = m->handleTelegram(data);
bool h = m->handleTelegram(data, simulated);
if (h) handled = true;
}
if (isVerboseEnabled() && !handled)
@ -412,11 +412,13 @@ string concatFields(Meter *m, Telegram *t, char c, vector<Print> &prints, vector
return s;
}
bool MeterCommonImplementation::handleTelegram(vector<uchar> input_frame)
bool MeterCommonImplementation::handleTelegram(vector<uchar> input_frame, bool simulated)
{
Telegram t;
bool ok = t.parseHeader(input_frame);
if (simulated) t.markAsSimulated();
if (!ok || !isTelegramForMe(&t))
{
// This telegram is not intended for this meter.

Wyświetl plik

@ -201,7 +201,7 @@ struct Meter
// The handleTelegram expects an input_frame where the DLL crcs have been removed.
// Returns true of this meter handled this telegram!
virtual bool handleTelegram(vector<uchar> input_frame) = 0;
virtual bool handleTelegram(vector<uchar> input_frame, bool simulated) = 0;
virtual bool isTelegramForMe(Telegram *t) = 0;
virtual MeterKeys *meterKeys() = 0;
@ -222,7 +222,7 @@ struct MeterManager
virtual void addMeter(unique_ptr<Meter> meter) = 0;
virtual void removeAllMeters() = 0;
virtual void forEachMeter(std::function<void(Meter*)> cb) = 0;
virtual bool handleTelegram(vector<uchar> data) = 0;
virtual bool handleTelegram(vector<uchar> data, bool simulated) = 0;
virtual bool hasAllMetersReceivedATelegram() = 0;
virtual bool hasMeters() = 0;
virtual void onTelegram(function<void(vector<uchar>)> cb) = 0;

Wyświetl plik

@ -85,7 +85,7 @@ protected:
// Print the dimensionless Text quantity, no unit is needed.
void addPrint(string vname, Quantity vquantity,
function<std::string()> getValueFunc, string help, bool field, bool json);
bool handleTelegram(vector<uchar> frame);
bool handleTelegram(vector<uchar> frame, bool simulated);
void printMeter(Telegram *t,
string *human_readable,
string *fields, char separator,

Wyświetl plik

@ -1215,10 +1215,12 @@ bool Telegram::parseTPLConfig(std::vector<uchar>::iterator &pos)
if (meter_keys->confidentiality_key.size() != 16)
{
if (meter_keys->isSimulation()) {
if (isSimulated())
{
debug("(wmbus) simulation without keys, not generating Kmac and Kenc.\n");
return true;
}
debug("(wmbus) no key, thus cannot execute kdf.\n");
return false;
}
AES_CMAC(&meter_keys->confidentiality_key[0], &input[0], 16, &mac[0]);
@ -1351,7 +1353,7 @@ bool Telegram::potentiallyDecrypt(vector<uchar>::iterator &pos)
}
else if (tpl_sec_mode == TPLSecurityMode::AES_CBC_NO_IV)
{
if (!meter_keys->hasConfidentialityKey() && meter_keys->isSimulation())
if (!meter_keys->hasConfidentialityKey() && isSimulated())
{
CHECK(2);
addExplanationAndIncrementPos(pos, 2, "%02x%02x (already) decrypted check bytes", *(pos+0), *(pos+1));

Wyświetl plik

@ -294,11 +294,9 @@ struct MeterKeys
{
vector<uchar> confidentiality_key;
vector<uchar> authentication_key;
bool simulation {};
bool hasConfidentialityKey() { return confidentiality_key.size() > 0; }
bool hasAuthenticationKey() { return authentication_key.size() > 0; }
bool isSimulation() { return simulation; }
};
struct Telegram
@ -413,6 +411,7 @@ struct Telegram
void explainParse(string intro, int from);
bool isSimulated() { return is_simulated_; }
void markAsSimulated() { is_simulated_ = true; }
// Extracted mbus values.
std::map<std::string,std::pair<int,DVEntry>> values;

Wyświetl plik

@ -14,6 +14,8 @@ Forren lansensm 00010206 NOKEY
cat > $TEST/test_expected.txt <<EOF
(meter) Dorren: meter detection did not match the selected driver lansendw! correct driver is: unknown!
(meter) please consider opening an issue at https://github.com/weetmuts/wmbusmeters/
(meter) to add support for this unknown mfct,media,version combination
{"media":"Unknown","meter":"lansendw","name":"Dorren","id":"00010205","status":"OPEN","timestamp":"1111-11-11T11:11:11Z"}
(meter) Forren: meter detection did not match the selected driver lansensm! correct driver is: lansendw
{"media":"reserved","meter":"lansensm","name":"Forren","id":"00010206","status":"OK","timestamp":"1111-11-11T11:11:11Z"}