Skip to content

Commit 6dc4c06

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

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Diff for: libraries/SE05X/src/SE05X.cpp

+17-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,30 @@ void SE05XClass::end()
108107
Se05x_API_SessionClose(&_se05x_session);
109108
}
110109

110+
int SE05XClass::serialNumber(byte sn[], size_t length)
111+
{
112+
size_t uidLen = length;
113+
const int kSE05x_AppletResID_UNIQUE_ID = 0x7FFF0206;
114+
smStatus_t status;
115+
116+
status = Se05x_API_ReadObject(&_se05x_session, kSE05x_AppletResID_UNIQUE_ID, 0, length, sn, &uidLen);
117+
if (status != SM_OK || length != uidLen) {
118+
SMLOG_E("Error in Se05x_API_ReadObject \n");
119+
return 0;
120+
}
121+
return 1;
122+
}
123+
111124
String SE05XClass::serialNumber()
112125
{
113126
String result = (char*)NULL;
114127
byte UID[SE05X_SN_LENGTH];
115-
size_t uidLen = SE05X_SN_LENGTH;
116-
const int kSE05x_AppletResID_UNIQUE_ID = 0x7FFF0206,
117128

118-
status = Se05x_API_ReadObject(&_se05x_session, kSE05x_AppletResID_UNIQUE_ID, 0, uidLen, UID, &uidLen);
119-
if (status != SM_OK) {
120-
SMLOG_E("Error in Se05x_API_ReadObject \n");
121-
return "";
122-
}
129+
serialNumber(UID, sizeof(UID));
123130

124-
result.reserve(uidLen * 2);
131+
result.reserve(SE05X_SN_LENGTH * 2);
125132

126-
for (size_t i = 0; i < uidLen; i++) {
133+
for (size_t i = 0; i < SE05X_SN_LENGTH; i++) {
127134
byte b = UID[i];
128135

129136
if (b < 16) {

Diff for: 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)