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.

30 lines
720 B

2 years ago
  1. #include "xs_id.h"
  2. #include "main.h"
  3. #include "rng.h"
  4. extern RNG_HandleTypeDef hrng;
  5. void xs_id_generate_random_mac(mac_t* id) {
  6. id->mac[0] = 0x00; // 00 80 E1 ��STM32��MAC��ַǰ��λ
  7. id->mac[1] = 0x80;
  8. id->mac[2] = 0xE1;
  9. uint32_t random0 = 0;
  10. uint32_t random1 = 0;
  11. uint32_t random2 = 0;
  12. HAL_RNG_GenerateRandomNumber(&hrng, &random0);
  13. HAL_RNG_GenerateRandomNumber(&hrng, &random1);
  14. HAL_RNG_GenerateRandomNumber(&hrng, &random2);
  15. id->mac[3] = random0 % 256;
  16. id->mac[4] = random1 % 256;
  17. id->mac[5] = random2 % 256;
  18. }
  19. void xs_id_get_uuid(device_id_t* id) {
  20. // UID_BASE
  21. uint8_t* uid_base = (uint8_t*)UID_BASE;
  22. for (int32_t i = 0; i < 12; i++) {
  23. id->id[i] = uid_base[i];
  24. }
  25. return;
  26. }