Skip to content

Commit 64ec02e

Browse files
committed
MCU8MASS-1790 Expose readProvisionItem in ECC608 and remove functions for thingname and endpoint
1 parent 88cf4c2 commit 64ec02e

File tree

8 files changed

+68
-90
lines changed

8 files changed

+68
-90
lines changed

examples/mqtt_low_power/mqtt_low_power.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ bool initMQTTTopics() {
2525
size_t thingNameLen = sizeof(thingName);
2626

2727
// -- Get the thingname
28-
ATCA_STATUS status = ECC608.getThingName(thingName, &thingNameLen);
28+
ATCA_STATUS status =
29+
ECC608.readProvisionItem(AWS_THINGNAME, thingName, &thingNameLen);
2930
if (status != ATCA_SUCCESS) {
3031
Log.error("Could not retrieve thingname from the ECC");
3132
return false;

examples/mqtt_polling_aws/mqtt_polling_aws.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ bool initMQTTTopics() {
3030
size_t thingNameLen = sizeof(thingName);
3131

3232
// -- Get the thingname
33-
ATCA_STATUS status = ECC608.getThingName(thingName, &thingNameLen);
33+
ATCA_STATUS status =
34+
ECC608.readProvisionItem(AWS_THINGNAME, thingName, &thingNameLen);
3435
if (status != ATCA_SUCCESS) {
3536
Log.error("Could not retrieve thingname from the ECC");
3637
return false;

examples/mqtt_with_connection_loss_handling/mqtt_with_connection_loss_handling.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ bool initMQTTTopics() {
3232
size_t thingNameLen = sizeof(thingName);
3333

3434
// -- Get the thingname
35-
ATCA_STATUS status = ECC608.getThingName(thingName, &thingNameLen);
35+
ATCA_STATUS status =
36+
ECC608.readProvisionItem(AWS_THINGNAME, thingName, &thingNameLen);
3637
if (status != ATCA_SUCCESS) {
3738
Log.error("Could not retrieve thingname from the ECC");
3839
return false;

examples/provision/provision.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,9 @@ static ATCA_STATUS constructCSR(char* pem, size_t* pem_size) {
739739
uint8_t common_name[128];
740740
size_t common_name_length = sizeof(common_name);
741741

742-
if (ECC608.getThingName(common_name, &common_name_length) != ATCA_SUCCES) {
742+
if (ECC608.readProvisionItem(AWS_THINGNAME,
743+
common_name,
744+
&common_name_length) != ATCA_SUCCES) {
743745
const char* default_identifier = "AVR-IoT Cellular Mini";
744746
common_name_length = strlen(default_identifier);
745747
memcpy(common_name, default_identifier, common_name_length);

examples/sandbox/sandbox.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ void setup() {
310310
uint8_t thing_name[128];
311311
size_t thing_name_len = sizeof(thing_name);
312312

313-
ATCA_STATUS status = ECC608.getThingName(thing_name, &thing_name_len);
313+
ATCA_STATUS status =
314+
ECC608.readProvisionItem(AWS_THINGNAME, thing_name, &thing_name_len);
314315
if (status != ATCA_SUCCESS) {
315316
Log.error("Could not retrieve thing name from the ECC");
316317
Log.error("Unable to initialize the MQTT topics. Stopping...");

src/ecc608.cpp

Lines changed: 25 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,32 @@ struct DataHeader {
2929
uint16_t type : 7; // Type of current item, see provision_data.h
3030
};
3131

32-
enum EccDataType {
33-
EMPTY = 0,
34-
AWS_THINGNAME = 1,
35-
AWS_ENDPOINT = 2,
36-
AZURE_ID_SCOPE = 3,
37-
AZURE_IOT_HUB_NAME = 4,
38-
AZURE_DEVICE_ID = 5,
39-
GOOGLE_PROJECT_ID = 6,
40-
GOOGLE_PROJECT_REGION = 7,
41-
GOOGLE_REGISTRY_ID = 8,
42-
GOOGLE_DEVICE_ID = 9,
43-
NUM_TYPES // Placeholder, keep this last
44-
};
32+
ECC608Class ECC608 = ECC608Class::instance();
4533

46-
/**
47-
* @brief Extract item with given type from ECC slot.
48-
*
49-
* This code traverses the list until matching type is found,
50-
* assuming there is only one item of each type in the slot.
51-
* Notice: A \0 terminator is added to the returned item for
52-
* easier string processing. This is not included in returned
53-
* length, but there must be space for it in the buffer.
54-
*
55-
* @param type [in] Type of requested item
56-
* @param buffer [out] Buffer to store item in
57-
* @param length [in, out] Pointer to length of buffer. Set to actual item
58-
* length on return.
59-
*
60-
* @return ATCA_STATUS error code. If the item is not found ATCA_INVALID_ID will
61-
* be returned.
62-
*/
63-
static ATCA_STATUS
64-
readProvisionItem(const enum EccDataType type, uint8_t* buffer, size_t* size) {
34+
ATCA_STATUS ECC608Class::begin() {
35+
if (initialized) {
36+
return ATCA_SUCCESS;
37+
} else {
38+
initialized = true;
39+
}
40+
41+
static ATCAIfaceCfg ECCConfig = {ATCA_I2C_IFACE,
42+
ATECC608B,
43+
{
44+
0x58, // 7 bit address of ECC
45+
2, // Bus number
46+
100000 // Baud rate
47+
},
48+
1560,
49+
20,
50+
NULL};
51+
52+
return atcab_init(&ECCConfig);
53+
}
54+
55+
ATCA_STATUS ECC608Class::readProvisionItem(const enum EccDataType type,
56+
uint8_t* buffer,
57+
size_t* size) {
6558

6659
ATCA_STATUS atca_status = ATCA_SUCCESS;
6760

@@ -131,37 +124,6 @@ readProvisionItem(const enum EccDataType type, uint8_t* buffer, size_t* size) {
131124
return ATCA_INVALID_ID;
132125
}
133126

134-
ECC608Class ECC608 = ECC608Class::instance();
135-
136-
ATCA_STATUS ECC608Class::begin() {
137-
if (initialized) {
138-
return ATCA_SUCCESS;
139-
} else {
140-
initialized = true;
141-
}
142-
143-
static ATCAIfaceCfg ECCConfig = {ATCA_I2C_IFACE,
144-
ATECC608B,
145-
{
146-
0x58, // 7 bit address of ECC
147-
2, // Bus number
148-
100000 // Baud rate
149-
},
150-
1560,
151-
20,
152-
NULL};
153-
154-
return atcab_init(&ECCConfig);
155-
}
156-
157-
ATCA_STATUS ECC608Class::getEndpoint(uint8_t* endpoint, size_t* size) {
158-
return readProvisionItem(AWS_ENDPOINT, endpoint, size);
159-
}
160-
161-
ATCA_STATUS ECC608Class::getThingName(uint8_t* thing_name, size_t* size) {
162-
return readProvisionItem(AWS_THINGNAME, thing_name, size);
163-
}
164-
165127
int ECC608Class::getRootCertificateSize(size_t* size) {
166128
return tng_atcacert_root_cert_size(size);
167129
}

src/ecc608.h

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
#include "cryptoauthlib/lib/atcacert/atcacert.h"
1010
#include "cryptoauthlib/lib/cryptoauthlib.h"
1111

12+
enum EccDataType {
13+
EMPTY = 0,
14+
AWS_THINGNAME = 1,
15+
AWS_ENDPOINT = 2,
16+
AZURE_ID_SCOPE = 3,
17+
AZURE_IOT_HUB_NAME = 4,
18+
AZURE_DEVICE_ID = 5,
19+
GOOGLE_PROJECT_ID = 6,
20+
GOOGLE_PROJECT_REGION = 7,
21+
GOOGLE_REGISTRY_ID = 8,
22+
GOOGLE_DEVICE_ID = 9,
23+
NUM_TYPES // Placeholder, keep this last
24+
};
25+
1226
class ECC608Class {
1327

1428
private:
@@ -32,8 +46,6 @@ class ECC608Class {
3246
return instance;
3347
}
3448

35-
// TODO: add read provision item as public here
36-
3749
/**
3850
* @brief Initializes the ECC.
3951
*
@@ -42,28 +54,26 @@ class ECC608Class {
4254
ATCA_STATUS begin();
4355

4456
/**
45-
* @brief Retrieves the AWS endpoint stored in the ECC.
57+
* @brief Extract item with given type from ECC slot.
4658
*
47-
* @param endpoint [out] Buffer to place the endpoint.
48-
* @param size [in, out] Size of buffer. Will be overwritten with the
49-
* endpoint length.
50-
*
51-
* @return The enumerations of cryptoauthlib's #ATCA_STATUS. #ATCA_SUCCESS
52-
* on success.
53-
*/
54-
ATCA_STATUS getEndpoint(uint8_t* endpoint, size_t* size);
55-
56-
/**
57-
* @brief Retrieves the thing name stored in the ECC.
59+
* This code traverses the list until matching type is found,
60+
* assuming there is only one item of each type in the slot.
61+
* Notice: A \0 terminator is added to the returned item for
62+
* easier string processing. This is not included in returned
63+
* length, but there must be space for it in the buffer.
5864
*
59-
* @param thing_name [out] Buffer to place the thing name.
60-
* @param size [in, out] size of buffer. Will be overwritten with the
61-
* thing name length.
65+
* @param type [in] Type of requested item.
66+
* @param buffer [out] Buffer to store item in.
67+
* @param length [in, out] Pointer to length of buffer. Set to actual item
68+
* length on return..
6269
*
63-
* @return The enumerations of cryptoauthlib's #ATCA_STATUS. #ATCA_SUCCESS
64-
* on success.
70+
* @return ATCA_STATUS error code. If the item is not found ATCA_INVALID_ID
71+
* will be returned.
6572
*/
66-
ATCA_STATUS getThingName(uint8_t* thing_name, size_t* size);
73+
ATCA_STATUS
74+
readProvisionItem(const enum EccDataType type,
75+
uint8_t* buffer,
76+
size_t* size);
6777

6878
/**
6979
* @brief Get the size of the root certificate (not base64 encoded. The size

src/mqtt_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ bool MqttClientClass::beginAWS() {
356356
uint8_t endpoint[128];
357357
size_t endpointLen = sizeof(endpoint);
358358

359-
status = ECC608.getThingName(thingName, &thingNameLen);
359+
status = ECC608.readProvisionItem(AWS_THINGNAME, thingName, &thingNameLen);
360360

361361
if (status != ATCA_SUCCESS) {
362362
Log.errorf("Could not retrieve thing name from the ECC, cryptoauthlib "
@@ -365,7 +365,7 @@ bool MqttClientClass::beginAWS() {
365365
return false;
366366
}
367367

368-
status = ECC608.getEndpoint(endpoint, &endpointLen);
368+
status = ECC608.readProvisionItem(AWS_ENDPOINT, endpoint, &endpointLen);
369369

370370
if (status != ATCA_SUCCESS) {
371371
Log.errorf("Could not retrieve endpoint from the ECC, cryptoauthlib "

0 commit comments

Comments
 (0)