New bt beacon api

by Willy-JL
This commit is contained in:
MX 2023-09-07 13:45:37 +03:00
parent 45fd5ef9d8
commit 1df2fc035f
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
5 changed files with 86 additions and 49 deletions

View File

@ -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_hal_bt_change_app,_Bool,"FuriHalBtProfile, GapEventCallback, void*"
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_ensure_c2_mode,_Bool,BleGlueC2Mode
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_stop,void,
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_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 )]"
@ -1663,7 +1665,6 @@ Function,-,gammaf_r,float,"float, int*"
Function,-,gap_get_remote_conn_rssi,uint32_t,int8_t*
Function,-,gap_get_state,GapState,
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_stop_advertising,void,
Function,-,gap_thread_stop,void,

1 entry status name type params
1037 Function + furi_get_tick uint32_t
1038 Function + furi_hal_bt_change_app _Bool FuriHalBtProfile, GapEventCallback, void*
1039 Function + furi_hal_bt_clear_white_list _Bool
1040 Function + furi_hal_bt_custom_adv_set _Bool const uint8_t*, size_t
1041 Function + furi_hal_bt_custom_adv_start _Bool uint16_t, uint16_t, uint8_t, const uint8_t[( 6 )], uint8_t
1042 Function + furi_hal_bt_custom_adv_stop _Bool
1043 Function + furi_hal_bt_dump_state void FuriString*
1044 Function + furi_hal_bt_ensure_c2_mode _Bool BleGlueC2Mode
1045 Function - furi_hal_bt_get_conn_rssi uint32_t uint8_t*
1082 Function + furi_hal_bt_serial_start void
1083 Function + furi_hal_bt_serial_stop void
1084 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
1085 Function + furi_hal_bt_set_key_storage_change_callback void BleGlueKeyStorageChangedCallback, void*
1086 Function + furi_hal_bt_set_profile_adv_name void FuriHalBtProfile, const char[( ( 1 + 8 + ( 8 + 1 ) ) + 1 )]
1087 Function + furi_hal_bt_set_profile_mac_addr void FuriHalBtProfile, const uint8_t[( 6 )]
1665 Function - gap_get_remote_conn_rssi uint32_t int8_t*
1666 Function - gap_get_state GapState
1667 Function - gap_init _Bool GapConfig*, GapEventCallback, void*
Function - gap_set_custom_adv_data void size_t, const uint8_t*
1668 Function - gap_start_advertising void
1669 Function - gap_stop_advertising void
1670 Function - gap_thread_stop void

View File

@ -37,9 +37,6 @@ typedef struct {
FuriThread* thread;
FuriMessageQueue* command_queue;
bool enable_adv;
// API for BLE beacon plugin
size_t custom_adv_len;
const uint8_t* custom_adv_data;
} Gap;
typedef enum {
@ -433,36 +430,18 @@ static void gap_advertise_start(GapState new_state) {
}
}
// 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(
ADV_IND,
min_interval,
max_interval,
CFG_IDENTITY_ADDRESS,
0,
strlen(gap->service.adv_name),
(uint8_t*)gap->service.adv_name,
gap->service.adv_svc_uuid_len,
gap->service.adv_svc_uuid,
0,
0);
}
status = aci_gap_set_discoverable(
ADV_IND,
min_interval,
max_interval,
CFG_IDENTITY_ADDRESS,
0,
strlen(gap->service.adv_name),
(uint8_t*)gap->service.adv_name,
gap->service.adv_svc_uuid_len,
gap->service.adv_svc_uuid,
0,
0);
if(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;
}
// 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 state;
if(gap) {

View File

@ -83,8 +83,6 @@ void gap_thread_stop();
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
}
#endif

View File

@ -484,10 +484,48 @@ uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi) {
}
// API for BLE beacon plugin
void furi_hal_bt_set_custom_adv_data(const uint8_t* adv_data, size_t adv_len) {
gap_set_custom_adv_data(adv_len, adv_data);
furi_hal_bt_stop_advertising();
furi_hal_bt_start_advertising();
bool furi_hal_bt_custom_adv_set(const uint8_t* adv_data, size_t adv_len) {
tBleStatus status = aci_gap_additional_beacon_set_data(adv_len, adv_data);
if(status) {
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]) {

View File

@ -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);
// 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);