gap.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <furi_hal_version.h>
  5. #define GAP_MAC_ADDR_SIZE (6)
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef enum {
  10. GapEventTypeConnected,
  11. GapEventTypeDisconnected,
  12. GapEventTypeStartAdvertising,
  13. GapEventTypeStopAdvertising,
  14. GapEventTypePinCodeShow,
  15. GapEventTypePinCodeVerify,
  16. GapEventTypeUpdateMTU,
  17. } GapEventType;
  18. typedef union {
  19. uint32_t pin_code;
  20. uint16_t max_packet_size;
  21. } GapEventData;
  22. typedef struct {
  23. GapEventType type;
  24. GapEventData data;
  25. } GapEvent;
  26. typedef bool (*GapEventCallback)(GapEvent event, void* context);
  27. typedef struct {
  28. uint8_t type;
  29. uint8_t mac[6];
  30. } GapAddress;
  31. typedef void (*GapScanCallback)(GapAddress address, void* context);
  32. typedef enum {
  33. GapStateUninitialized,
  34. GapStateIdle,
  35. GapStateStartingAdv,
  36. GapStateAdvFast,
  37. GapStateAdvLowPower,
  38. GapStateConnected,
  39. } GapState;
  40. typedef enum {
  41. GapPairingNone,
  42. GapPairingPinCodeShow,
  43. GapPairingPinCodeVerifyYesNo,
  44. } GapPairing;
  45. typedef struct {
  46. uint16_t adv_service_uuid;
  47. uint16_t appearance_char;
  48. bool bonding_mode;
  49. GapPairing pairing_method;
  50. uint8_t mac_address[GAP_MAC_ADDR_SIZE];
  51. char adv_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH];
  52. } GapConfig;
  53. bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context);
  54. void gap_start_advertising();
  55. void gap_stop_advertising();
  56. GapState gap_get_state();
  57. void gap_thread_stop();
  58. void gap_start_scan(GapScanCallback callback, void* context);
  59. void gap_stop_scan();
  60. #ifdef __cplusplus
  61. }
  62. #endif