Skip to content

Commit 8fe68c1

Browse files
committed
add GET_PROVISIONING_SKETCH_VERSION and GET_NET_CONF_LIB_VERSION commands
1 parent 65cd57a commit 8fe68c1

17 files changed

+249
-38
lines changed

extras/test/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ FetchContent_Declare(
1616

1717
FetchContent_Declare(
1818
cloudutils
19-
GIT_REPOSITORY https://github.com/andreagilardoni/Arduino_CloudUtils.git
20-
GIT_TAG cbor-messages
19+
GIT_REPOSITORY https://github.com/arduino-libraries/Arduino_CloudUtils.git
20+
GIT_TAG main
2121
CONFIGURE_COMMAND ""
2222
BUILD_COMMAND ""
2323
)
@@ -125,12 +125,12 @@ set(TEST_TARGET_SRCS
125125

126126
##########################################################################
127127

128-
add_compile_definitions(BOARD_HAS_LORA BOARD_HAS_CATM1_NBIOT BOARD_HAS_WIFI BOARD_HAS_ETHERNET BOARD_HAS_CELLULAR BOARD_HAS_NB BOARD_HAS_GSM)
128+
add_compile_definitions(CI_TEST BOARD_HAS_LORA BOARD_HAS_CATM1_NBIOT BOARD_HAS_WIFI BOARD_HAS_ETHERNET BOARD_HAS_CELLULAR BOARD_HAS_NB BOARD_HAS_GSM)
129129
add_compile_options(-Wextra -Werror)
130130
add_compile_options(-Wno-cast-function-type)
131131

132132
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage")
133-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy")
133+
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy -Wno-missing-field-initializers")
134134

135135
##########################################################################
136136

extras/test/src/test_provisioning_command_decode.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <Decoder.h>
1515
#include <cbor/MessageDecoder.h>
1616
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBOR.h"
17+
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBORInstances.h"
1718
#include <IPAddress.h>
1819

1920
/******************************************************************************

extras/test/src/test_provisioning_command_encode.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Encoder.h>
1313
#include <cbor/MessageEncoder.h>
1414
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBOR.h"
15+
#include "../../src/ConfiguratorAgents/agents/BoardConfigurationProtocol/cbor/CBORInstances.h"
1516

1617
/******************************************************************************
1718
TEST CODE
@@ -233,4 +234,59 @@
233234
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
234235
}
235236
}
237+
238+
WHEN("Encode a message with provisioning sketch version ")
239+
{
240+
ProvSketchVersionProvisioningMessage command;
241+
command.c.id = ProvisioningMessageId::ProvSketchVersionProvisioningMessageId;
242+
command.provSketchVersion = "1.6.0";
243+
uint8_t buffer[512];
244+
size_t bytes_encoded = sizeof(buffer);
245+
246+
CBORMessageEncoder encoder;
247+
MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
248+
249+
uint8_t expected_result[] = {
250+
0xda, 0x00, 0x01, 0x20, 0x15, 0x81, 0x65, 0x31, 0x2E, 0x36, 0x2E, 0x30
251+
};
252+
253+
// Test the encoding is
254+
// DA 00012015 # tag(73749)
255+
// 81 # array(1)
256+
// 65 # text(5)
257+
// 312E362E30 # "1.6.0"
258+
THEN("The encoding is successful") {
259+
REQUIRE(err == MessageEncoder::Status::Complete);
260+
REQUIRE(bytes_encoded == sizeof(expected_result));
261+
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
262+
}
263+
}
264+
265+
WHEN("Encode a message with provisioning Network Configurator lib version ")
266+
{
267+
NetConfigLibVersionProvisioningMessage command;
268+
command.c.id = ProvisioningMessageId::NetConfigLibVersProvisioningMessageId;
269+
command.netConfigLibVersion = "1.6.0";
270+
uint8_t buffer[512];
271+
size_t bytes_encoded = sizeof(buffer);
272+
273+
CBORMessageEncoder encoder;
274+
MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded);
275+
276+
uint8_t expected_result[] = {
277+
0xda, 0x00, 0x01, 0x20, 0x16, 0x81, 0x65, 0x31, 0x2E, 0x36, 0x2E, 0x30
278+
};
279+
280+
// Test the encoding is
281+
// DA 00012016 # tag(73750)
282+
// 81 # array(1)
283+
// 65 # text(5)
284+
// 312E362E30 # "1.6.0"
285+
printf("res %d\n", (int)err);
286+
THEN("The encoding is successful") {
287+
REQUIRE(err == MessageEncoder::Status::Complete);
288+
REQUIRE(bytes_encoded == sizeof(expected_result));
289+
REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0);
290+
}
291+
}
236292
}

src/ANetworkConfigurator_Config.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*/
88
#pragma once
99

10-
#define NETWORK_CONFIGURATOR_COMPATIBLE 0
11-
#define ZERO_TOUCH_ENABLED 0
10+
#define ANetworkConfigurator_LIB_VERSION "0.1.0"
1211

1312
#if defined(ARDUINO_SAMD_MKRWIFI1010)
1413
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
@@ -119,6 +118,15 @@
119118
#define LED_OFF HIGH
120119
#endif
121120

121+
#ifdef CI_TEST
122+
#define NETWORK_CONFIGURATOR_COMPATIBLE 1
123+
#endif
124+
125+
#ifndef NETWORK_CONFIGURATOR_COMPATIBLE
126+
#define NETWORK_CONFIGURATOR_COMPATIBLE 0
127+
#define ZERO_TOUCH_ENABLED 0
128+
#endif
129+
122130
#ifndef RESET_HOLD_TIME
123131
#define RESET_HOLD_TIME 3000000
124132
#endif

src/Arduino_NetworkConfigurator.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ bool NetworkConfiguratorClass::begin() {
7979

8080
_agentsManager->addRequestHandler(RequestType::GET_WIFI_FW_VERSION, getWiFiFWVersionHandler);
8181

82+
_agentsManager->addRequestHandler(RequestType::GET_NETCONFIG_LIB_VERSION, getNetConfLibVersionHandler);
83+
8284
if (!_agentsManager->begin()) {
8385
DEBUG_ERROR("NetworkConfiguratorClass::%s Failed to initialize the AgentsManagerClass", __FUNCTION__);
8486
}
@@ -343,6 +345,10 @@ void NetworkConfiguratorClass::getWiFiFWVersionHandler() {
343345
_receivedEvent = NetworkConfiguratorEvents::GET_WIFI_FW_VERSION;
344346
}
345347

348+
void NetworkConfiguratorClass::getNetConfLibVersionHandler() {
349+
_receivedEvent = NetworkConfiguratorEvents::GET_NET_CONF_LIB_VERSION;
350+
}
351+
346352
bool NetworkConfiguratorClass::handleConnectRequest() {
347353
if (_networkSetting.type == NetworkAdapter::NONE) {
348354
sendStatus(StatusMessage::PARAMS_NOT_FOUND);
@@ -419,6 +425,12 @@ void NetworkConfiguratorClass::handleGetWiFiFWVersion() {
419425
_agentsManager->sendMsg(fwVersionMsg);
420426
}
421427

428+
void NetworkConfiguratorClass::handleGetNetConfLibVersion() {
429+
ProvisioningOutputMessage libVersionMsg = { MessageOutputType::NETCONFIG_LIB_VERSION };
430+
libVersionMsg.m.netConfigLibVersion = ANetworkConfigurator_LIB_VERSION;
431+
_agentsManager->sendMsg(libVersionMsg);
432+
}
433+
422434
void NetworkConfiguratorClass::startReconfigureProcedure() {
423435
resetStoredConfiguration();
424436
// Set to restart the BLE after reboot
@@ -507,10 +519,11 @@ NetworkConfiguratorStates NetworkConfiguratorClass::handleWaitingForConf() {
507519
_agentsManager->update();
508520
bool connecting = false;
509521
switch (_receivedEvent) {
510-
case NetworkConfiguratorEvents::SCAN_REQ: scanNetworkOptions (); break;
511-
case NetworkConfiguratorEvents::CONNECT_REQ: connecting = handleConnectRequest (); break;
512-
case NetworkConfiguratorEvents::GET_WIFI_FW_VERSION: handleGetWiFiFWVersion(); break;
513-
case NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS: break;
522+
case NetworkConfiguratorEvents::SCAN_REQ: scanNetworkOptions (); break;
523+
case NetworkConfiguratorEvents::CONNECT_REQ: connecting = handleConnectRequest (); break;
524+
case NetworkConfiguratorEvents::GET_WIFI_FW_VERSION: handleGetWiFiFWVersion (); break;
525+
case NetworkConfiguratorEvents::GET_NET_CONF_LIB_VERSION: handleGetNetConfLibVersion(); break;
526+
case NetworkConfiguratorEvents::NEW_NETWORK_SETTINGS: break;
514527
}
515528
_receivedEvent = NetworkConfiguratorEvents::NONE;
516529

src/Arduino_NetworkConfigurator.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ class NetworkConfiguratorClass {
171171
SCAN_REQ,
172172
CONNECT_REQ,
173173
NEW_NETWORK_SETTINGS,
174-
GET_WIFI_FW_VERSION };
174+
GET_WIFI_FW_VERSION,
175+
GET_NET_CONF_LIB_VERSION };
175176
static inline NetworkConfiguratorEvents _receivedEvent;
176177

177178
enum class ConnectionResult { SUCCESS,
@@ -193,6 +194,7 @@ class NetworkConfiguratorClass {
193194
NetworkConfiguratorStates handleErrorState();
194195
bool handleConnectRequest();
195196
void handleGetWiFiFWVersion();
197+
void handleGetNetConfLibVersion();
196198

197199
void startReconfigureProcedure();
198200

@@ -213,6 +215,7 @@ class NetworkConfiguratorClass {
213215
static void connectReqHandler();
214216
static void setNetworkSettingsHandler(models::NetworkSetting *netSetting);
215217
static void getWiFiFWVersionHandler();
218+
static void getNetConfLibVersionHandler();
216219
};
217220

218221
#endif // NETWORK_CONFIGURATOR_COMPATIBLE

src/ConfiguratorAgents/AgentsManager.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,13 @@ void AgentsManagerClass::updateProgressRequest(StatusMessage type) {
302302
void AgentsManagerClass::updateProgressRequest(MessageOutputType type) {
303303
RequestType key = RequestType::NONE;
304304
switch (type) {
305-
case MessageOutputType::NETWORK_OPTIONS: key = RequestType::SCAN ; break;
306-
case MessageOutputType::UHWID: key = RequestType::GET_ID ; break;
307-
case MessageOutputType::JWT: key = RequestType::GET_ID ; break;
308-
case MessageOutputType::BLE_MAC_ADDRESS: key = RequestType::GET_BLE_MAC_ADDRESS; break;
309-
case MessageOutputType::WIFI_FW_VERSION: key = RequestType::GET_WIFI_FW_VERSION; break;
305+
case MessageOutputType::NETWORK_OPTIONS: key = RequestType::SCAN ; break;
306+
case MessageOutputType::UHWID: key = RequestType::GET_ID ; break;
307+
case MessageOutputType::JWT: key = RequestType::GET_ID ; break;
308+
case MessageOutputType::BLE_MAC_ADDRESS: key = RequestType::GET_BLE_MAC_ADDRESS ; break;
309+
case MessageOutputType::WIFI_FW_VERSION: key = RequestType::GET_WIFI_FW_VERSION ; break;
310+
case MessageOutputType::PROV_SKETCH_VERSION: key = RequestType::GET_PROVISIONING_SKETCH_VERSION; break;
311+
case MessageOutputType::NETCONFIG_LIB_VERSION: key = RequestType::GET_NETCONFIG_LIB_VERSION ; break;
310312
}
311313

312314
if (key == RequestType::NONE) {
@@ -336,12 +338,14 @@ void AgentsManagerClass::handleReceivedCommands(RemoteCommands cmd) {
336338

337339
RequestType type = RequestType::NONE;
338340
switch (cmd) {
339-
case RemoteCommands::CONNECT: type = RequestType::CONNECT ; break;
340-
case RemoteCommands::SCAN: type = RequestType::SCAN ; break;
341-
case RemoteCommands::GET_ID: type = RequestType::GET_ID ; break;
342-
case RemoteCommands::GET_BLE_MAC_ADDRESS: type = RequestType::GET_BLE_MAC_ADDRESS; break;
343-
case RemoteCommands::RESET: type = RequestType::RESET ; break;
344-
case RemoteCommands::GET_WIFI_FW_VERSION: type = RequestType::GET_WIFI_FW_VERSION; break;
341+
case RemoteCommands::CONNECT: type = RequestType::CONNECT ; break;
342+
case RemoteCommands::SCAN: type = RequestType::SCAN ; break;
343+
case RemoteCommands::GET_ID: type = RequestType::GET_ID ; break;
344+
case RemoteCommands::GET_BLE_MAC_ADDRESS: type = RequestType::GET_BLE_MAC_ADDRESS ; break;
345+
case RemoteCommands::RESET: type = RequestType::RESET ; break;
346+
case RemoteCommands::GET_WIFI_FW_VERSION: type = RequestType::GET_WIFI_FW_VERSION ; break;
347+
case RemoteCommands::GET_PROVISIONING_SKETCH_VERSION: type = RequestType::GET_PROVISIONING_SKETCH_VERSION; break;
348+
case RemoteCommands::GET_NETCONFIG_LIB_VERSION: type = RequestType::GET_NETCONFIG_LIB_VERSION ; break;
345349
}
346350

347351
if(type == RequestType::NONE) {

src/ConfiguratorAgents/AgentsManager.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ enum class RequestType: int { NONE = -1,
5454
GET_ID = 2,
5555
RESET = 3,
5656
GET_WIFI_FW_VERSION = 4,
57-
GET_BLE_MAC_ADDRESS = 5 };
57+
GET_BLE_MAC_ADDRESS = 5,
58+
GET_PROVISIONING_SKETCH_VERSION = 6,
59+
GET_NETCONFIG_LIB_VERSION = 7};
5860

5961
/**
6062
* @class AgentsManagerClass
@@ -209,7 +211,7 @@ class AgentsManagerClass {
209211
AgentsManagerStates _state;
210212
std::list<ConfiguratorAgent *> _agentsList;
211213
bool _enabledAgents[2];
212-
ConfiguratorRequestHandler _reqHandlers[6];
214+
ConfiguratorRequestHandler _reqHandlers[8];
213215
ReturnTimestamp _returnTimestampCb;
214216
ReturnNetworkSettings _returnNetworkSettingsCb;
215217
ConfiguratorAgent *_selectedAgent;

src/ConfiguratorAgents/MessagesDefinitions.h

+13-7
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ enum class StatusMessage {
4242
};
4343

4444
/* Commands codes */
45-
enum class RemoteCommands { CONNECT = 1,
46-
GET_ID = 2,
47-
GET_BLE_MAC_ADDRESS = 3,
48-
RESET = 4,
49-
SCAN = 100,
50-
GET_WIFI_FW_VERSION = 101
45+
enum class RemoteCommands { CONNECT = 1,
46+
GET_ID = 2,
47+
GET_BLE_MAC_ADDRESS = 3,
48+
RESET = 4,
49+
SCAN = 100,
50+
GET_WIFI_FW_VERSION = 101,
51+
GET_PROVISIONING_SKETCH_VERSION = 200,
52+
GET_NETCONFIG_LIB_VERSION = 201,
5153
};
5254

5355
/* Types of outgoing messages */
@@ -56,7 +58,9 @@ enum class MessageOutputType { STATUS,
5658
UHWID,
5759
JWT,
5860
BLE_MAC_ADDRESS,
59-
WIFI_FW_VERSION
61+
WIFI_FW_VERSION,
62+
PROV_SKETCH_VERSION,
63+
NETCONFIG_LIB_VERSION,
6064
};
6165

6266
/* Types of ingoing messages */
@@ -80,6 +84,8 @@ struct ProvisioningOutputMessage {
8084
const char *jwt;
8185
const uint8_t *BLEMacAddress;
8286
const char *wifiFwVersion;
87+
const char *provSketchVersion;
88+
const char *netConfigLibVersion;
8389
} m;
8490
};
8591

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/BoardConfigurationProtocol.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ bool BoardConfigurationProtocol::sendMsg(ProvisioningOutputMessage &msg) {
6767
res = sendBleMacAddress(msg.m.BLEMacAddress, BLE_MAC_ADDRESS_SIZE);
6868
break;
6969
case MessageOutputType::WIFI_FW_VERSION:
70-
res = sendWifiFWVersion(msg.m.wifiFwVersion);
70+
res = sendVersion(msg.m.wifiFwVersion, msg.type);
71+
break;
72+
case MessageOutputType::PROV_SKETCH_VERSION:
73+
res = sendVersion(msg.m.provSketchVersion, msg.type);
74+
break;
75+
case MessageOutputType::NETCONFIG_LIB_VERSION:
76+
res = sendVersion(msg.m.netConfigLibVersion, msg.type);
7177
break;
7278
default:
7379
break;
@@ -310,21 +316,27 @@ bool BoardConfigurationProtocol::sendBleMacAddress(const uint8_t *mac, size_t le
310316
return res;
311317
}
312318

313-
bool BoardConfigurationProtocol::sendWifiFWVersion(const char *wifiFWVersion) {
319+
bool BoardConfigurationProtocol::sendVersion(const char *version, MessageOutputType type) {
314320
bool res = false;
315321

316-
size_t cborDataLen = CBOR_MIN_WIFI_FW_VERSION_LEN + strlen(wifiFWVersion);
322+
size_t cborDataLen = CBOR_MIN_WIFI_FW_VERSION_LEN + strlen(version);
317323
uint8_t data[cborDataLen];
318324

319-
res = CBORAdapter::wifiFWVersionToCBOR(wifiFWVersion, data, &cborDataLen);
325+
switch (type)
326+
{
327+
case MessageOutputType::WIFI_FW_VERSION: res = CBORAdapter::wifiFWVersionToCBOR (version, data, &cborDataLen); break;
328+
case MessageOutputType::PROV_SKETCH_VERSION: res = CBORAdapter::provSketchVersionToCBOR (version, data, &cborDataLen); break;
329+
case MessageOutputType::NETCONFIG_LIB_VERSION: res = CBORAdapter::netConfigLibVersionToCBOR(version, data, &cborDataLen); break;
330+
default: return false;
331+
}
332+
320333
if (!res) {
321334
return res;
322335
}
323336

324337
res = sendData(PacketManager::MessageType::DATA, data, cborDataLen);
325338
if (!res) {
326-
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send WiFi FW version", __FUNCTION__);
327-
return res;
339+
DEBUG_WARNING("BoardConfigurationProtocol::%s failed to send version of type %d", __FUNCTION__, (int)type);
328340
}
329341

330342
return res;

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/BoardConfigurationProtocol.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class BoardConfigurationProtocol {
9797
bool sendUhwid(const byte *uhwid);
9898
bool sendJwt(const char *jwt, size_t len);
9999
bool sendBleMacAddress(const uint8_t *mac, size_t len);
100-
bool sendWifiFWVersion(const char *wifiFWVersion);
100+
bool sendVersion(const char *version, MessageOutputType type);
101101
TransmissionResult transmitStream();
102102
void printPacket(const char *label, const uint8_t *data, size_t len);
103103
std::list<OutputPacketBuffer> _outputMessagesList;

src/ConfiguratorAgents/agents/BoardConfigurationProtocol/CBORAdapter.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,34 @@ bool CBORAdapter::wifiFWVersionToCBOR(const char *wifiFWVersion, uint8_t *data,
9797
return status == MessageEncoder::Status::Complete ? true : false;
9898
}
9999

100+
bool CBORAdapter::provSketchVersionToCBOR(const char *provSketchVersion, uint8_t *data, size_t *len) {
101+
CBORMessageEncoder encoder;
102+
if(*len < CBOR_MIN_PROV_SKETCH_VERSION_LEN + strlen(provSketchVersion)) {
103+
return false;
104+
}
105+
ProvSketchVersionProvisioningMessage provSketchVersionMsg;
106+
provSketchVersionMsg.c.id = ProvisioningMessageId::ProvSketchVersionProvisioningMessageId;
107+
provSketchVersionMsg.provSketchVersion = provSketchVersion;
108+
109+
MessageEncoder::Status status = encoder.encode((Message *)&provSketchVersionMsg, data, *len);
110+
111+
return status == MessageEncoder::Status::Complete ? true : false;
112+
}
113+
114+
bool CBORAdapter::netConfigLibVersionToCBOR(const char *netConfigLibVersion, uint8_t *data, size_t *len) {
115+
CBORMessageEncoder encoder;
116+
if(*len < CBOR_MIN_NETCONFIG_LIB_VERSION_LEN + strlen(netConfigLibVersion)) {
117+
return false;
118+
}
119+
NetConfigLibVersionProvisioningMessage netConfigLibVersionMsg;
120+
netConfigLibVersionMsg.c.id = ProvisioningMessageId::NetConfigLibVersProvisioningMessageId;
121+
netConfigLibVersionMsg.netConfigLibVersion = netConfigLibVersion;
122+
123+
MessageEncoder::Status status = encoder.encode((Message *)&netConfigLibVersionMsg, data, *len);
124+
125+
return status == MessageEncoder::Status::Complete ? true : false;
126+
}
127+
100128
bool CBORAdapter::networkOptionsToCBOR(const NetworkOptions *netOptions, uint8_t *data, size_t *len) {
101129
bool result = false;
102130
switch (netOptions->type) {

0 commit comments

Comments
 (0)