mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-22 20:43:07 +00:00
New bt beacon api
by Willy-JL
This commit is contained in:
parent
45fd5ef9d8
commit
1df2fc035f
5 changed files with 86 additions and 49 deletions
|
@ -1037,6 +1037,9 @@ Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, ui
|
||||||
Function,+,furi_get_tick,uint32_t,
|
Function,+,furi_get_tick,uint32_t,
|
||||||
Function,+,furi_hal_bt_change_app,_Bool,"FuriHalBtProfile, GapEventCallback, void*"
|
Function,+,furi_hal_bt_change_app,_Bool,"FuriHalBtProfile, GapEventCallback, void*"
|
||||||
Function,+,furi_hal_bt_clear_white_list,_Bool,
|
Function,+,furi_hal_bt_clear_white_list,_Bool,
|
||||||
|
Function,+,furi_hal_bt_custom_adv_set,_Bool,"const uint8_t*, size_t"
|
||||||
|
Function,+,furi_hal_bt_custom_adv_start,_Bool,"uint16_t, uint16_t, uint8_t, const uint8_t[( 6 )], uint8_t"
|
||||||
|
Function,+,furi_hal_bt_custom_adv_stop,_Bool,
|
||||||
Function,+,furi_hal_bt_dump_state,void,FuriString*
|
Function,+,furi_hal_bt_dump_state,void,FuriString*
|
||||||
Function,+,furi_hal_bt_ensure_c2_mode,_Bool,BleGlueC2Mode
|
Function,+,furi_hal_bt_ensure_c2_mode,_Bool,BleGlueC2Mode
|
||||||
Function,-,furi_hal_bt_get_conn_rssi,uint32_t,uint8_t*
|
Function,-,furi_hal_bt_get_conn_rssi,uint32_t,uint8_t*
|
||||||
|
@ -1079,7 +1082,6 @@ Function,+,furi_hal_bt_serial_set_rpc_status,void,FuriHalBtSerialRpcStatus
|
||||||
Function,+,furi_hal_bt_serial_start,void,
|
Function,+,furi_hal_bt_serial_start,void,
|
||||||
Function,+,furi_hal_bt_serial_stop,void,
|
Function,+,furi_hal_bt_serial_stop,void,
|
||||||
Function,+,furi_hal_bt_serial_tx,_Bool,"uint8_t*, uint16_t"
|
Function,+,furi_hal_bt_serial_tx,_Bool,"uint8_t*, uint16_t"
|
||||||
Function,+,furi_hal_bt_set_custom_adv_data,void,"const uint8_t*, size_t"
|
|
||||||
Function,+,furi_hal_bt_set_key_storage_change_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
Function,+,furi_hal_bt_set_key_storage_change_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
||||||
Function,+,furi_hal_bt_set_profile_adv_name,void,"FuriHalBtProfile, const char[( ( 1 + 8 + ( 8 + 1 ) ) + 1 )]"
|
Function,+,furi_hal_bt_set_profile_adv_name,void,"FuriHalBtProfile, const char[( ( 1 + 8 + ( 8 + 1 ) ) + 1 )]"
|
||||||
Function,+,furi_hal_bt_set_profile_mac_addr,void,"FuriHalBtProfile, const uint8_t[( 6 )]"
|
Function,+,furi_hal_bt_set_profile_mac_addr,void,"FuriHalBtProfile, const uint8_t[( 6 )]"
|
||||||
|
@ -1663,7 +1665,6 @@ Function,-,gammaf_r,float,"float, int*"
|
||||||
Function,-,gap_get_remote_conn_rssi,uint32_t,int8_t*
|
Function,-,gap_get_remote_conn_rssi,uint32_t,int8_t*
|
||||||
Function,-,gap_get_state,GapState,
|
Function,-,gap_get_state,GapState,
|
||||||
Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
|
Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
|
||||||
Function,-,gap_set_custom_adv_data,void,"size_t, const uint8_t*"
|
|
||||||
Function,-,gap_start_advertising,void,
|
Function,-,gap_start_advertising,void,
|
||||||
Function,-,gap_stop_advertising,void,
|
Function,-,gap_stop_advertising,void,
|
||||||
Function,-,gap_thread_stop,void,
|
Function,-,gap_thread_stop,void,
|
||||||
|
|
|
|
@ -37,9 +37,6 @@ typedef struct {
|
||||||
FuriThread* thread;
|
FuriThread* thread;
|
||||||
FuriMessageQueue* command_queue;
|
FuriMessageQueue* command_queue;
|
||||||
bool enable_adv;
|
bool enable_adv;
|
||||||
// API for BLE beacon plugin
|
|
||||||
size_t custom_adv_len;
|
|
||||||
const uint8_t* custom_adv_data;
|
|
||||||
} Gap;
|
} Gap;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -433,23 +430,6 @@ static void gap_advertise_start(GapState new_state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Configure advertising
|
// Configure advertising
|
||||||
// API For BLE beacon plugin
|
|
||||||
if(gap->custom_adv_data) {
|
|
||||||
// Custom adv logic from https://techryptic.github.io/2023/09/01/Annoying-Apple-Fans/
|
|
||||||
static const uint16_t gap_appearance = 0x0000; //GAP_APPEARANCE_UNKNOWN
|
|
||||||
status = aci_gatt_update_char_value(
|
|
||||||
gap->service.gap_svc_handle,
|
|
||||||
gap->service.gap_svc_handle,
|
|
||||||
0,
|
|
||||||
sizeof(gap_appearance),
|
|
||||||
(uint8_t*)&gap_appearance);
|
|
||||||
status = aci_gap_set_discoverable(
|
|
||||||
ADV_IND, min_interval, max_interval, CFG_IDENTITY_ADDRESS, 0, 0, NULL, 0, NULL, 0, 0);
|
|
||||||
status = aci_gap_delete_ad_type(AD_TYPE_FLAGS);
|
|
||||||
status = aci_gap_delete_ad_type(AD_TYPE_TX_POWER_LEVEL);
|
|
||||||
status = aci_gap_update_adv_data(gap->custom_adv_len, gap->custom_adv_data);
|
|
||||||
} else {
|
|
||||||
// Default adv logic
|
|
||||||
status = aci_gap_set_discoverable(
|
status = aci_gap_set_discoverable(
|
||||||
ADV_IND,
|
ADV_IND,
|
||||||
min_interval,
|
min_interval,
|
||||||
|
@ -462,7 +442,6 @@ static void gap_advertise_start(GapState new_state) {
|
||||||
gap->service.adv_svc_uuid,
|
gap->service.adv_svc_uuid,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
}
|
|
||||||
if(status) {
|
if(status) {
|
||||||
FURI_LOG_E(TAG, "set_discoverable failed %d", status);
|
FURI_LOG_E(TAG, "set_discoverable failed %d", status);
|
||||||
}
|
}
|
||||||
|
@ -580,13 +559,6 @@ uint32_t gap_get_remote_conn_rssi(int8_t* rssi) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// API For BLE beacon plugin
|
|
||||||
|
|
||||||
void gap_set_custom_adv_data(size_t adv_len, const uint8_t* adv_data) {
|
|
||||||
gap->custom_adv_len = adv_len;
|
|
||||||
gap->custom_adv_data = adv_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
GapState gap_get_state() {
|
GapState gap_get_state() {
|
||||||
GapState state;
|
GapState state;
|
||||||
if(gap) {
|
if(gap) {
|
||||||
|
|
|
@ -83,8 +83,6 @@ void gap_thread_stop();
|
||||||
|
|
||||||
uint32_t gap_get_remote_conn_rssi(int8_t* rssi);
|
uint32_t gap_get_remote_conn_rssi(int8_t* rssi);
|
||||||
|
|
||||||
void gap_set_custom_adv_data(size_t adv_len, const uint8_t* adv_data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -484,10 +484,48 @@ uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// API for BLE beacon plugin
|
// API for BLE beacon plugin
|
||||||
void furi_hal_bt_set_custom_adv_data(const uint8_t* adv_data, size_t adv_len) {
|
bool furi_hal_bt_custom_adv_set(const uint8_t* adv_data, size_t adv_len) {
|
||||||
gap_set_custom_adv_data(adv_len, adv_data);
|
tBleStatus status = aci_gap_additional_beacon_set_data(adv_len, adv_data);
|
||||||
furi_hal_bt_stop_advertising();
|
if(status) {
|
||||||
furi_hal_bt_start_advertising();
|
FURI_LOG_E(TAG, "custom_adv_set failed %d", status);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
FURI_LOG_D(TAG, "custom_adv_set success");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool furi_hal_bt_custom_adv_start(
|
||||||
|
uint16_t min_interval,
|
||||||
|
uint16_t max_interval,
|
||||||
|
uint8_t mac_type,
|
||||||
|
const uint8_t mac_addr[GAP_MAC_ADDR_SIZE],
|
||||||
|
uint8_t power_amp_level) {
|
||||||
|
tBleStatus status = aci_gap_additional_beacon_start(
|
||||||
|
min_interval / 0.625, // Millis to gap time
|
||||||
|
max_interval / 0.625, // Millis to gap time
|
||||||
|
0b00000111, // All 3 channels
|
||||||
|
mac_type,
|
||||||
|
mac_addr,
|
||||||
|
power_amp_level);
|
||||||
|
if(status) {
|
||||||
|
FURI_LOG_E(TAG, "custom_adv_start failed %d", status);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
FURI_LOG_D(TAG, "custom_adv_start success");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool furi_hal_bt_custom_adv_stop() {
|
||||||
|
tBleStatus status = aci_gap_additional_beacon_stop();
|
||||||
|
if(status) {
|
||||||
|
FURI_LOG_E(TAG, "custom_adv_stop failed %d", status);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
FURI_LOG_D(TAG, "custom_adv_stop success");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void furi_hal_bt_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) {
|
void furi_hal_bt_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) {
|
||||||
|
|
|
@ -253,7 +253,35 @@ const uint8_t* furi_hal_bt_get_profile_mac_addr(FuriHalBtProfile profile);
|
||||||
uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi);
|
uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi);
|
||||||
|
|
||||||
// API for BLE Beacon plugin
|
// API for BLE Beacon plugin
|
||||||
void furi_hal_bt_set_custom_adv_data(const uint8_t* adv_data, size_t adv_len);
|
/** Set custom advertisement packet data
|
||||||
|
* @param[in] adv_data pointer to advertisement data
|
||||||
|
* @param[in] adv_len length of advertisement data
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool furi_hal_bt_custom_adv_set(const uint8_t* adv_data, size_t adv_len);
|
||||||
|
|
||||||
|
/** Start custom advertisement beacon
|
||||||
|
* @param[in] min_interval minimum advertisement interval (20 - 10240 ms)
|
||||||
|
* @param[in] max_interval maximum advertisement interval (20 - 10240 ms)
|
||||||
|
* @param[in] mac_type type of mac address (0x00 public, 0x01 static random)
|
||||||
|
* @param[in] mac_addr pointer to mac address
|
||||||
|
* @param[in] power_amp_level amplifier level (output dBm) (0x00 - 0x1F)
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool furi_hal_bt_custom_adv_start(
|
||||||
|
uint16_t min_interval,
|
||||||
|
uint16_t max_interval,
|
||||||
|
uint8_t mac_type,
|
||||||
|
const uint8_t mac_addr[GAP_MAC_ADDR_SIZE],
|
||||||
|
uint8_t power_amp_level);
|
||||||
|
|
||||||
|
/** Stop custom advertisement beacon
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool furi_hal_bt_custom_adv_stop();
|
||||||
|
|
||||||
void furi_hal_bt_set_profile_pairing_method(FuriHalBtProfile profile, GapPairing pairing_method);
|
void furi_hal_bt_set_profile_pairing_method(FuriHalBtProfile profile, GapPairing pairing_method);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue