Skip to content

Commit

Permalink
Allow firmware update with invalid magic header after user confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Jan 13, 2024
1 parent ee81887 commit ee16dbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ui_firmwareupdatedialog.h"
#include "../../VNA_embedded/Application/Communication/PacketConstants.h"
#include "CustomWidgets/informationbox.h"

#include <QFileDialog>
#include <QStyle>
Expand Down Expand Up @@ -60,8 +61,25 @@ void FirmwareUpdateDialog::on_bStart_clicked()
char header[24];
file->read(header, sizeof(header));
if(strncmp(header, dev->getFirmwareMagicString().toStdString().c_str(), 4)) {
abortWithError("Invalid magic header constant");
return;
// might be a firmware file for a wrong LibreVNA
if(dev->getProtocolVersion() == Protocol::Version) {
// we are talking to a LibreVNA with the correct protocol, this is definitely the wrong firmware file
abortWithError("Invalid magic header constant");
return;
} else {
// we might be talking to the correct hardware but with the wrong protocol version (which might result
// in the magic string check falsely failing. Process after user confirmation
auto confirm = InformationBox::AskQuestion("Continue?", "The firmware magic header constant does not match the expected"
" value for your LibreVNA. Either this is the wrong firmware file"
" or the hardware ID of your LibreVNA was read incorrectly. This"
" can happen if the LibreVNA uses a different protocol version than"
" what it expected by the GUI. Do you want to continue with the firmware update?", true);
if(!confirm) {
abortWithError("Aborted by user");
return;
}
}

}
file->seek(0);
state = State::ErasingFLASH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ LibreVNADriver::LibreVNADriver()
skipOwnPacketHandling = false;
SApoints = 0;
hardwareVersion = 0;
protocolVersion = 0;
setSynchronization(Synchronization::Disabled, false);

auto manual = new QAction("Manual Control");
Expand Down Expand Up @@ -589,6 +590,7 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet)
switch(packet.type) {
case Protocol::PacketType::DeviceInfo: {
// Check protocol version
protocolVersion = packet.info.ProtocolVersion;
if(packet.info.ProtocolVersion != Protocol::Version) {
auto ret = InformationBox::AskQuestion("Warning",
"The device reports a different protocol"
Expand Down Expand Up @@ -703,6 +705,11 @@ QString LibreVNADriver::hardwareVersionToString(uint8_t version)
}
}

unsigned int LibreVNADriver::getProtocolVersion() const
{
return protocolVersion;
}

unsigned int LibreVNADriver::getMaxAmplitudePoints() const
{
return limits_maxAmplitudePoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class LibreVNADriver : public DeviceDriver

QString getFirmwareMagicString();

unsigned int getProtocolVersion() const;

signals:
void receivedAnswer(const LibreVNADriver::TransmissionResult &result);
void receivedPacket(const Protocol::PacketInfo& packet);
Expand All @@ -194,6 +196,7 @@ protected slots:
QString hardwareVersionToString(uint8_t version);

bool connected;
unsigned int protocolVersion;
QString serial;
Info info;
uint8_t hardwareVersion;
Expand Down

0 comments on commit ee16dbc

Please sign in to comment.