API for BLE Beacon app

thanks to Willy-JL
This commit is contained in:
MX 2023-09-05 16:22:14 +03:00
parent b3cce2351a
commit d40f664342
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
5 changed files with 54 additions and 12 deletions

View File

@ -1079,6 +1079,7 @@ 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 )]"
@ -1662,6 +1663,7 @@ 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,

1 entry status name type params
1079 Function + furi_hal_bt_serial_start void
1080 Function + furi_hal_bt_serial_stop void
1081 Function + furi_hal_bt_serial_tx _Bool uint8_t*, uint16_t
1082 Function + furi_hal_bt_set_custom_adv_data void const uint8_t*, size_t
1083 Function + furi_hal_bt_set_key_storage_change_callback void BleGlueKeyStorageChangedCallback, void*
1084 Function + furi_hal_bt_set_profile_adv_name void FuriHalBtProfile, const char[( ( 1 + 8 + ( 8 + 1 ) ) + 1 )]
1085 Function + furi_hal_bt_set_profile_mac_addr void FuriHalBtProfile, const uint8_t[( 6 )]
1663 Function - gap_get_remote_conn_rssi uint32_t int8_t*
1664 Function - gap_get_state GapState
1665 Function - gap_init _Bool GapConfig*, GapEventCallback, void*
1666 Function - gap_set_custom_adv_data void size_t, const uint8_t*
1667 Function - gap_start_advertising void
1668 Function - gap_stop_advertising void
1669 Function - gap_thread_stop void

View File

@ -37,6 +37,9 @@ 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 {
@ -430,6 +433,23 @@ 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,
@ -442,6 +462,7 @@ 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);
} }
@ -559,6 +580,13 @@ 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) {

View File

@ -83,6 +83,8 @@ 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

View File

@ -483,6 +483,13 @@ uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi) {
return since; return since;
} }
// 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();
}
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]) {
uint8_t tmp; uint8_t tmp;
for(size_t i = 0; i < GAP_MAC_ADDR_SIZE / 2; i++) { for(size_t i = 0; i < GAP_MAC_ADDR_SIZE / 2; i++) {

View File

@ -252,6 +252,9 @@ 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
void furi_hal_bt_set_custom_adv_data(const uint8_t* adv_data, size_t adv_len);
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);
GapPairing furi_hal_bt_get_profile_pairing_method(FuriHalBtProfile profile); GapPairing furi_hal_bt_get_profile_pairing_method(FuriHalBtProfile profile);