Skip to content

Commit 799bdfa

Browse files
committed
SE050: add API to read serial number raw bytes
1 parent 1169821 commit 799bdfa

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

cores/arduino/api

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../ArduinoCore-API/api/
1+
/home/pennam/Arduino/API/api/

libraries/SE05X/src/SE05X.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
SE05X_EC_SIGNATURE_RAW_LENGTH
7070

7171
#define SE05X_SHA256_LENGTH 32
72-
#define SE05X_SN_LENGTH 18
7372

7473
#define SE05X_TEMP_OBJECT 9999
7574

@@ -108,22 +107,29 @@ void SE05XClass::end()
108107
Se05x_API_SessionClose(&_se05x_session);
109108
}
110109

111-
String SE05XClass::serialNumber()
110+
int SE05XClass::serialNumber(byte sn[], size_t length)
112111
{
113-
String result = (char*)NULL;
114-
byte UID[SE05X_SN_LENGTH];
115-
size_t uidLen = SE05X_SN_LENGTH;
112+
size_t uidLen;
116113
const int kSE05x_AppletResID_UNIQUE_ID = 0x7FFF0206,
117114

118-
status = Se05x_API_ReadObject(&_se05x_session, kSE05x_AppletResID_UNIQUE_ID, 0, uidLen, UID, &uidLen);
119-
if (status != SM_OK) {
115+
status = Se05x_API_ReadObject(&_se05x_session, kSE05x_AppletResID_UNIQUE_ID, 0, length, sn, &uidLen);
116+
if (status != SM_OK || length != uidLen) {
120117
SMLOG_E("Error in Se05x_API_ReadObject \n");
121-
return "";
118+
return 0;
122119
}
120+
return 1;
121+
}
122+
123+
String SE05XClass::serialNumber()
124+
{
125+
String result = (char*)NULL;
126+
byte UID[SE05X_SN_LENGTH];
127+
128+
serialNumber(UID, sizeof(UID));
123129

124-
result.reserve(uidLen * 2);
130+
result.reserve(SE05X_SN_LENGTH * 2);
125131

126-
for (size_t i = 0; i < uidLen; i++) {
132+
for (size_t i = 0; i < SE05X_SN_LENGTH; i++) {
127133
byte b = UID[i];
128134

129135
if (b < 16) {

libraries/SE05X/src/SE05X.h

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ extern "C" {
3333
}
3434
#endif
3535

36+
#define SE05X_SN_LENGTH 18
37+
3638
class SE05XClass
3739
{
3840
public:
@@ -42,6 +44,7 @@ class SE05XClass
4244
int begin();
4345
void end();
4446

47+
int serialNumber(byte sn[], size_t length);
4548
#if defined (ARDUINO)
4649
String serialNumber();
4750
#endif

0 commit comments

Comments
 (0)