2021-09-13 14:25:37 +03:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-12 19:41:42 +03:00
|
|
|
#include <stdint.h>
|
2021-09-13 14:25:37 +03:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2022-01-05 19:10:18 +03:00
|
|
|
#include <furi_hal_version.h>
|
2021-12-08 14:28:01 +03:00
|
|
|
|
|
|
|
#define GAP_MAC_ADDR_SIZE (6)
|
|
|
|
|
2024-02-16 10:20:45 +03:00
|
|
|
/*
|
|
|
|
* GAP helpers - background thread that handles BLE GAP events and advertising.
|
|
|
|
*/
|
|
|
|
|
2021-09-13 14:25:37 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-10-12 19:41:42 +03:00
|
|
|
typedef enum {
|
2022-01-03 01:36:42 +03:00
|
|
|
GapEventTypeConnected,
|
|
|
|
GapEventTypeDisconnected,
|
|
|
|
GapEventTypeStartAdvertising,
|
|
|
|
GapEventTypeStopAdvertising,
|
|
|
|
GapEventTypePinCodeShow,
|
|
|
|
GapEventTypePinCodeVerify,
|
|
|
|
GapEventTypeUpdateMTU,
|
2024-02-16 10:20:45 +03:00
|
|
|
GapEventTypeBeaconStart,
|
|
|
|
GapEventTypeBeaconStop,
|
2022-01-03 01:36:42 +03:00
|
|
|
} GapEventType;
|
2021-10-12 19:41:42 +03:00
|
|
|
|
|
|
|
typedef union {
|
|
|
|
uint32_t pin_code;
|
2021-11-21 17:47:54 +03:00
|
|
|
uint16_t max_packet_size;
|
2022-01-03 01:36:42 +03:00
|
|
|
} GapEventData;
|
2021-10-12 19:41:42 +03:00
|
|
|
|
|
|
|
typedef struct {
|
2022-01-03 01:36:42 +03:00
|
|
|
GapEventType type;
|
|
|
|
GapEventData data;
|
|
|
|
} GapEvent;
|
2021-10-12 19:41:42 +03:00
|
|
|
|
2022-01-05 19:10:18 +03:00
|
|
|
typedef bool (*GapEventCallback)(GapEvent event, void* context);
|
2022-01-03 01:36:42 +03:00
|
|
|
|
2021-09-13 14:25:37 +03:00
|
|
|
typedef enum {
|
2022-01-03 01:36:42 +03:00
|
|
|
GapStateUninitialized,
|
2021-09-13 14:25:37 +03:00
|
|
|
GapStateIdle,
|
2021-12-08 14:28:01 +03:00
|
|
|
GapStateStartingAdv,
|
2021-09-13 14:25:37 +03:00
|
|
|
GapStateAdvFast,
|
|
|
|
GapStateAdvLowPower,
|
|
|
|
GapStateConnected,
|
|
|
|
} GapState;
|
|
|
|
|
2021-12-08 14:28:01 +03:00
|
|
|
typedef enum {
|
2022-01-03 01:36:42 +03:00
|
|
|
GapPairingNone,
|
2021-12-08 14:28:01 +03:00
|
|
|
GapPairingPinCodeShow,
|
|
|
|
GapPairingPinCodeVerifyYesNo,
|
|
|
|
} GapPairing;
|
|
|
|
|
2022-03-31 17:57:23 +03:00
|
|
|
typedef struct {
|
|
|
|
uint16_t conn_interval;
|
|
|
|
uint16_t slave_latency;
|
|
|
|
uint16_t supervisor_timeout;
|
|
|
|
} GapConnectionParams;
|
|
|
|
|
2022-01-21 20:32:03 +03:00
|
|
|
typedef struct {
|
|
|
|
uint16_t conn_int_min;
|
|
|
|
uint16_t conn_int_max;
|
|
|
|
uint16_t slave_latency;
|
|
|
|
uint16_t supervisor_timeout;
|
2022-03-31 17:57:23 +03:00
|
|
|
} GapConnectionParamsRequest;
|
2022-01-21 20:32:03 +03:00
|
|
|
|
2021-12-08 14:28:01 +03:00
|
|
|
typedef struct {
|
|
|
|
uint16_t adv_service_uuid;
|
|
|
|
uint16_t appearance_char;
|
|
|
|
bool bonding_mode;
|
|
|
|
GapPairing pairing_method;
|
|
|
|
uint8_t mac_address[GAP_MAC_ADDR_SIZE];
|
|
|
|
char adv_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH];
|
2022-03-31 17:57:23 +03:00
|
|
|
GapConnectionParamsRequest conn_param;
|
2021-12-08 14:28:01 +03:00
|
|
|
} GapConfig;
|
|
|
|
|
2022-01-03 01:36:42 +03:00
|
|
|
bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context);
|
2021-09-13 14:25:37 +03:00
|
|
|
|
2024-02-16 10:20:45 +03:00
|
|
|
void gap_start_advertising(void);
|
|
|
|
|
|
|
|
void gap_stop_advertising(void);
|
2021-09-15 19:58:32 +03:00
|
|
|
|
2024-02-16 10:20:45 +03:00
|
|
|
GapState gap_get_state(void);
|
2021-09-15 19:58:32 +03:00
|
|
|
|
2024-02-16 10:20:45 +03:00
|
|
|
void gap_thread_stop(void);
|
2021-09-13 14:25:37 +03:00
|
|
|
|
2024-02-16 10:20:45 +03:00
|
|
|
void gap_emit_ble_beacon_status_event(bool active);
|
2021-12-08 14:28:01 +03:00
|
|
|
|
2021-09-13 14:25:37 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|