Skip to content

Commit fe92dc5

Browse files
committed
Inform user about incompatible server/bootloader variant
1 parent 475e534 commit fe92dc5

5 files changed

Lines changed: 45 additions & 27 deletions

File tree

flasher.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,21 @@ void Flasher::LoopHandler() {
186186
emit SetButtons(is_bootloader_);
187187

188188
if (is_bootloader_) {
189-
GetVersionJson(bl_version_);
190-
if (bl_version_.empty()) {
189+
GetVersionJson(bl_sw_info);
190+
if (bl_sw_info.empty()) {
191191
GetVersion();
192192
} else {
193-
if ("secured" == bl_version_.value("build_variant").toString()) {
193+
if ("secured" == bl_sw_info.value("build_variant").toString()) {
194194
emit DisableBrowseFileButton();
195+
is_secure_bootloader_ = true;
196+
} else {
197+
is_secure_bootloader_ = false;
195198
}
196199
}
197200
SetState(FlasherStates::kCheckBoardInfo);
198201
} else {
199-
GetVersionJson(fw_version_);
200-
if (fw_version_.empty()) {
202+
GetVersionJson(fw_sw_info);
203+
if (fw_sw_info.empty()) {
201204
GetVersion();
202205
}
203206
SetState(FlasherStates::kIdle);
@@ -248,14 +251,19 @@ void Flasher::LoopHandler() {
248251

249252
case FlasherStates::kServerDataExchange:
250253
if (!board_info_.empty() && socket_client_) {
251-
if (socket_client_->SendBoardInfo(board_info_, bl_version_, fw_version_)) {
252-
if (socket_client_->ReceiveProductInfo(board_info_, product_info_)) {
254+
if (socket_client_->SendBoardInfo(board_info_, bl_sw_info, fw_sw_info)) {
255+
if (socket_client_->ReceiveProductInfo(board_info_, bl_sw_info, product_info_, is_secure_communication_)) {
253256
if (!product_info_.empty()) {
254257
emit SetFileVersionsList(product_info_);
255258
}
256259
}
260+
261+
if (is_secure_communication_ != is_secure_bootloader_) {
262+
emit ShowTextInBrowser("Bootloader variant is incompatible with the server!");
263+
}
257264
}
258265
}
266+
emit ClearStatusMsg();
259267

260268
SetState(FlasherStates::kIdle);
261269
break;
@@ -702,7 +710,7 @@ bool Flasher::CollectSecurityDataFromBoard() {
702710
}
703711

704712
if (!success) {
705-
qInfo() << "Security data error";
713+
qInfo() << "No security data from bootloader";
706714
}
707715

708716
return success;

flasher.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ class Flasher : public QObject {
288288
QJsonObject board_info_; //!< Board information
289289
QJsonObject client_security_data_; //!< Security data client
290290
QJsonObject server_security_data_; //!< Security data server
291-
QJsonObject bl_version_; //!< Bootloader version
292-
QJsonObject fw_version_; //!< Firmware version
291+
QJsonObject bl_sw_info; //!< Bootloader software info
292+
QJsonObject fw_sw_info; //!< Firmware software info
293293
QJsonArray product_info_; //!< Product information
294294
QString selected_file_version_; //!< Selected file version
295295
QString file_source_; //!< File source (URL or Server)
@@ -305,6 +305,8 @@ class Flasher : public QObject {
305305
bool is_file_downloaded_{false}; //!< Is file downloaded flag
306306
bool is_download_success_{false}; //!< Is download successfully done
307307
bool is_signature_warning_enabled_{false}; //!< Is signature warning enabled
308+
bool is_secure_communication_{false}; //!< Is communication with the server secure
309+
bool is_secure_bootloader_{false}; //!< Is secure bootloader variant
308310
QByteArray file_content_; //!< File content
309311
communication::SerialPort serial_port_; //!< Serial port object
310312
std::shared_ptr<socket::SocketClient> socket_client_; //!< Shared pointer to SocketClient object

socket_client.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,22 @@ bool SocketClient::CheckAck() {
205205
return success;
206206
}
207207

208-
bool SocketClient::SendBoardInfo(QJsonObject board_info, QJsonObject bl_version, QJsonObject fw_version) {
208+
bool SocketClient::SendBoardInfo(QJsonObject board_info, QJsonObject bl_sw_info, QJsonObject fw_sw_info) {
209209
bool success = Connect();
210210

211211
if (success) {
212212

213-
QJsonObject app_version;
214-
app_version.insert("app_branch", GIT_BRANCH);
215-
app_version.insert("app_hash", GIT_HASH);
216-
app_version.insert("app_tag", GIT_TAG);
213+
QJsonObject app_sw_info;
214+
app_sw_info.insert("app_branch", GIT_BRANCH);
215+
app_sw_info.insert("app_hash", GIT_HASH);
216+
app_sw_info.insert("app_tag", GIT_TAG);
217217

218218
QJsonObject packet_object;
219219
packet_object.insert("header", kHeaderClientBoardInfo);
220220
packet_object.insert("board_info", board_info);
221-
packet_object.insert("bl_version", bl_version);
222-
packet_object.insert("fw_version", fw_version);
223-
packet_object.insert("app_version", app_version);
221+
packet_object.insert("bl_sw_info", bl_sw_info);
222+
packet_object.insert("fw_sw_info", fw_sw_info);
223+
packet_object.insert("app_sw_info", app_sw_info);
224224

225225
success = SendQJsonObject(packet_object);
226226

@@ -234,13 +234,14 @@ bool SocketClient::SendBoardInfo(QJsonObject board_info, QJsonObject bl_version,
234234
return success;
235235
}
236236

237-
bool SocketClient::ReceiveProductInfo(QJsonObject board_info, QJsonArray& product_info) {
237+
bool SocketClient::ReceiveProductInfo(QJsonObject board_info, QJsonObject bl_sw_info, QJsonArray& product_info, bool& is_secure_communication) {
238238
bool success = Connect();
239239

240240
if (success) {
241241
QJsonObject packet_object;
242242
packet_object.insert("header", kHeaderClientProductInfo);
243243
packet_object.insert("board_info", board_info);
244+
packet_object.insert("bl_sw_info", bl_sw_info);
244245

245246
success = SendQJsonObject(packet_object);
246247
}
@@ -259,6 +260,7 @@ bool SocketClient::ReceiveProductInfo(QJsonObject board_info, QJsonArray& produc
259260

260261
if (packet_object.value("header").toString() == kHeaderServerProductInfo) {
261262
product_info = packet_object.value("product_info").toArray();
263+
is_secure_communication = packet_object.value("secure_communication").toBool();
262264
} else {
263265
success = false;
264266
}

socket_client.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,21 @@ class SocketClient : public QTcpSocket {
7575
/*!
7676
* \brief Sending information about board to the server
7777
* \param board_info - Json object with board info for server
78-
* \param bl_version - Json object with bootloader git version
79-
* \param fw_version - Json object with firmware git version
78+
* \param bl_sw_info - Json object with bootloader software info about version, variant, etc
79+
* \param fq_sw_info - Json object with firmware software info about version, variant, etc
8080
* \return True if board info is successfully send, false otherwise
8181
*/
82-
virtual bool SendBoardInfo(QJsonObject board_info, QJsonObject bl_version, QJsonObject fw_version);
82+
virtual bool SendBoardInfo(QJsonObject board_info, QJsonObject bl_sw_info, QJsonObject fw_sw_info);
8383

8484
/*!
8585
* \brief Receive product info for given board info from the server
8686
* \param board_info - Json object with board info from server
87+
* \param bl_sw_info - Json object with bootloader software info about version, variant, etc
8788
* \param product_info - Json array with product info from server
89+
* \param is_secure_communication - Flag indicating if the server uses secure communication
8890
* \return
8991
*/
90-
virtual bool ReceiveProductInfo(QJsonObject board_info, QJsonArray& product_info);
92+
virtual bool ReceiveProductInfo(QJsonObject board_info, QJsonObject bl_sw_info, QJsonArray& product_info, bool& is_secure_communication);
9193

9294
/*!
9395
* \brief Download file from the server

tests/tst_socket.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ void TestSocket::TestSendBoardInfo() {
173173
QVERIFY2(rx_json_board_info.value("product_type") == product_type, "Sending product type failed");
174174

175175
QJsonObject rx_json_bl_version;
176-
rx_json_bl_version = packet_object.value("bl_version").toObject();
176+
rx_json_bl_version = packet_object.value("bl_sw_info").toObject();
177177
QVERIFY2(rx_json_bl_version.value("git_branch") == bl_git_branch, "Sending bl version failed");
178178
QVERIFY2(rx_json_bl_version.value("git_hash") == bl_git_hash, "Sending bl version failed");
179179
QVERIFY2(rx_json_bl_version.value("git_tag") == bl_git_tag, "Sending bl version failed");
180180

181181
QJsonObject rx_json_fw_version;
182-
rx_json_fw_version = packet_object.value("fw_version").toObject();
182+
rx_json_fw_version = packet_object.value("fw_sw_info").toObject();
183183
QVERIFY2(rx_json_fw_version.value("git_branch") == fw_git_branch, "Sending fw version failed");
184184
QVERIFY2(rx_json_fw_version.value("git_hash") == fw_git_hash, "Sending fw version failed");
185185
QVERIFY2(rx_json_fw_version.value("git_tag") == fw_git_tag, "Sending fw version failed");
@@ -227,7 +227,9 @@ void TestSocket::TestReceiveProductType() {
227227
socket.read_data_.emplace_back(json_data.toJson());
228228

229229
QJsonArray rx_product_info;
230-
bool success = socket.ReceiveProductInfo(tx_json_board_info, rx_product_info);
230+
bool is_secure_communication;
231+
QJsonObject bl_sw_info;
232+
bool success = socket.ReceiveProductInfo(tx_json_board_info, bl_sw_info, rx_product_info, is_secure_communication);
231233
QVERIFY2(success, "Receive product info failed");
232234

233235
json_data = QJsonDocument::fromJson(socket.send_data_.at(1));
@@ -306,6 +308,8 @@ void TestSocket::TestSendFail() {
306308

307309
QJsonArray rx_product_info;
308310

309-
bool success = socket.ReceiveProductInfo(tx_json_board_info, rx_product_info);
311+
bool is_secure_communication;
312+
QJsonObject bl_sw_info;
313+
bool success = socket.ReceiveProductInfo(tx_json_board_info, bl_sw_info, rx_product_info, is_secure_communication);
310314
QVERIFY2(!success, "Send data did not fail");
311315
}

0 commit comments

Comments
 (0)