@@ -34,7 +34,6 @@ extern "C" {
34
34
#include " rtl8721d_efuse.h"
35
35
}
36
36
37
-
38
37
namespace {
39
38
40
39
using namespace particle ;
@@ -50,20 +49,12 @@ using namespace particle;
50
49
#define HARDWARE_DATA_OFFSET 0x178
51
50
#define HARDWARE_MODEL_OFFSET 0x17B
52
51
53
- #define WIFI_MAC_SIZE 6
54
- #define BLE_MAC_SIZE 6
55
52
#define SERIAL_NUMBER_FRONT_PART_SIZE 9
56
53
#define HARDWARE_DATA_SIZE 4
57
54
#define HARDWARE_MODEL_SIZE 4
58
55
#define WIFI_OUID_SIZE 3
59
56
#define DEVICE_ID_PREFIX_SIZE 6
60
57
61
- // Offsets from base WiFi MAC address for reserved interfaces
62
- #define WIFI_STA_MAC_DELTA 0
63
- #define WIFI_AP_MAC_DELTA 1
64
- #define BLE_MAC_DELTA 2
65
- #define ETH_MAC_DELTA 3
66
-
67
58
const uint8_t DEVICE_ID_PREFIX[] = {0x0a , 0x10 , 0xac , 0xed , 0x20 , 0x21 };
68
59
69
60
int readLogicalEfuse (uint32_t offset, uint8_t * buf, size_t size) {
@@ -107,20 +98,20 @@ int HAL_Get_Device_Identifier(const char** name, char* buf, size_t buflen, unsig
107
98
return SYSTEM_ERROR_NOT_SUPPORTED;
108
99
}
109
100
110
- int hal_get_ble_mac_address (uint8_t * dest, size_t destLen, void * reserved) {
111
- CHECK_TRUE (dest && destLen >= BLE_MAC_SIZE, SYSTEM_ERROR_INVALID_ARGUMENT);
112
- uint8_t mac[BLE_MAC_SIZE] = {};
113
- destLen = BLE_MAC_SIZE;
114
- CHECK (readLogicalEfuse (BLE_MAC_OFFSET, mac, BLE_MAC_SIZE));
115
- // As per BLE spec, we store BLE data in little-endian
116
- for (uint8_t i = 0 , j = BLE_MAC_SIZE - 1 ; i < BLE_MAC_SIZE; i++, j--) {
117
- dest[i] = mac[j];
101
+ int hal_get_mac_address (uint8_t type, uint8_t * dest, size_t destLen, void * reserved) {
102
+ CHECK_TRUE (dest && destLen >= MAC_ADDR_SIZE, SYSTEM_ERROR_INVALID_ARGUMENT);
103
+ CHECK_TRUE (isSupportedMacType (type), SYSTEM_ERROR_INVALID_ARGUMENT);
104
+ uint8_t mac[MAC_ADDR_SIZE] = {};
105
+ if (type == HAL_DEVICE_MAC_BLE) {
106
+ CHECK (readLogicalEfuse (BLE_MAC_OFFSET, mac, MAC_ADDR_SIZE));
107
+ } else {
108
+ CHECK (readLogicalEfuse (WIFI_MAC_OFFSET, mac, MAC_ADDR_SIZE));
109
+ // Derive the final MAC address
110
+ mac[5 ] += type;
118
111
}
119
- return BLE_MAC_SIZE ;
112
+ return MAC_ADDR_SIZE ;
120
113
}
121
114
122
-
123
-
124
115
int hal_get_device_serial_number (char * str, size_t size, void * reserved) {
125
116
char fullSerialNumber[HAL_DEVICE_SERIAL_NUMBER_SIZE] = {};
126
117
@@ -133,7 +124,7 @@ int hal_get_device_serial_number(char* str, size_t size, void* reserved) {
133
124
CHECK (readLogicalEfuse (SERIAL_NUMBER_OFFSET, (uint8_t *)fullSerialNumber, SERIAL_NUMBER_FRONT_PART_SIZE));
134
125
135
126
// generate hex string from non-OUI MAC bytes
136
- uint8_t wifiMacRandomBytes[WIFI_MAC_SIZE - WIFI_OUID_SIZE] = {};
127
+ uint8_t wifiMacRandomBytes[MAC_ADDR_SIZE - WIFI_OUID_SIZE] = {};
137
128
CHECK (readLogicalEfuse (WIFI_MAC_OFFSET + WIFI_OUID_SIZE, wifiMacRandomBytes, sizeof (wifiMacRandomBytes)));
138
129
bytes2hexbuf (wifiMacRandomBytes, sizeof (wifiMacRandomBytes), &fullSerialNumber[SERIAL_NUMBER_FRONT_PART_SIZE]);
139
130
0 commit comments