You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
719 B

#include "xs_id.h"
#include "main.h"
#include "rng.h"
extern RNG_HandleTypeDef hrng;
void xs_id_generate_random_mac(mac_t* id) {
id->mac[0] = 0x00; // 00 80 E1 ÊÇSTM32µÄMACµØÖ·Ç°Èýλ
id->mac[1] = 0x80;
id->mac[2] = 0xE1;
uint32_t random0 = 0;
uint32_t random1 = 0;
uint32_t random2 = 0;
HAL_RNG_GenerateRandomNumber(&hrng, &random0);
HAL_RNG_GenerateRandomNumber(&hrng, &random1);
HAL_RNG_GenerateRandomNumber(&hrng, &random2);
id->mac[3] = random0 % 256;
id->mac[4] = random1 % 256;
id->mac[5] = random2 % 256;
}
void xs_id_get_cpu_id(cpu_id_t* id) {
// UID_BASE
uint8_t* uid_base = (uint8_t*)UID_BASE;
for (int32_t i = 0; i < 12; i++) {
id->id[i] = uid_base[i];
}
return;
}