Merge fixes

+ thanks @Willy-JL !
This commit is contained in:
MX 2024-02-19 03:52:35 +03:00
parent 9fcf3795ee
commit 66c60e65aa
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
13 changed files with 89 additions and 331 deletions

View File

@ -77,6 +77,8 @@ static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
gui_add_view_port(bt->gui, bt->pin_code_view_port, GuiLayerFullscreen);
}
notification_message(bt->notification, &sequence_display_backlight_on);
if(bt->suppress_pin_screen) return;
gui_view_port_send_to_front(bt->gui, bt->pin_code_view_port);
view_port_enabled_set(bt->pin_code_view_port, true);
}
@ -91,8 +93,9 @@ static void bt_pin_code_hide(Bt* bt) {
static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) {
furi_assert(bt);
bt->pin_code = pin;
if(bt->suppress_pin_screen) return true;
notification_message(bt->notification, &sequence_display_backlight_on);
if(bt->suppress_pin_screen) return true;
FuriString* pin_str;
if(!bt->dialog_message) {
bt->dialog_message = dialog_message_alloc();
@ -141,9 +144,7 @@ Bt* bt_alloc() {
bt->max_packet_size = BLE_PROFILE_SERIAL_PACKET_SIZE_MAX;
bt->current_profile = NULL;
// Load settings
if(!bt_settings_load(&bt->bt_settings)) {
bt_settings_save(&bt->bt_settings);
}
bt_settings_load(&bt->bt_settings);
// Keys storage
bt->keys_storage = bt_keys_storage_alloc(BT_KEYS_STORAGE_PATH);
// Alloc queue
@ -250,6 +251,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
furi_assert(context);
Bt* bt = context;
bool ret = false;
bt->pin = 0;
bool do_update_status = false;
bool current_profile_is_serial =
furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial);
@ -258,26 +260,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
// Update status bar
bt->status = BtStatusConnected;
do_update_status = true;
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
if(current_profile_is_serial) {
// Open RPC session
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
if(bt->rpc_session) {
FURI_LOG_I(TAG, "Open RPC connection");
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
rpc_session_set_buffer_is_empty_callback(
bt->rpc_session, bt_serial_buffer_is_empty_callback);
rpc_session_set_context(bt->rpc_session, bt);
ble_profile_serial_set_event_callback(
bt->current_profile, RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
ble_profile_serial_set_rpc_active(
bt->current_profile, FuriHalBtSerialRpcStatusActive);
} else {
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
}
}
bt_open_rpc_connection(bt);
// Update battery level
PowerInfo info;
power_get_info(bt->power, &info);
@ -376,7 +359,31 @@ static void bt_show_warning(Bt* bt, const char* text) {
dialog_message_show(bt->dialogs, bt->dialog_message);
}
static void bt_close_rpc_connection(Bt* bt) {
void bt_open_rpc_connection(Bt* bt) {
if(!bt->rpc_session && bt->status == BtStatusConnected) {
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
if(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial)) {
// Open RPC session
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
if(bt->rpc_session) {
FURI_LOG_I(TAG, "Open RPC connection");
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
rpc_session_set_buffer_is_empty_callback(
bt->rpc_session, bt_serial_buffer_is_empty_callback);
rpc_session_set_context(bt->rpc_session, bt);
ble_profile_serial_set_event_callback(
bt->current_profile, RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
ble_profile_serial_set_rpc_active(
bt->current_profile, FuriHalBtSerialRpcStatusActive);
} else {
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
}
}
}
}
void bt_close_rpc_connection(Bt* bt) {
if(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial) &&
bt->rpc_session) {
FURI_LOG_I(TAG, "Close RPC connection");
@ -389,7 +396,6 @@ static void bt_close_rpc_connection(Bt* bt) {
static void bt_change_profile(Bt* bt, BtMessage* message) {
if(furi_hal_bt_is_gatt_gap_supported()) {
bt_settings_load(&bt->bt_settings);
bt_close_rpc_connection(bt);
bt_keys_storage_load(bt->keys_storage);
@ -433,52 +439,6 @@ static void bt_close_connection(Bt* bt, BtMessage* message) {
if(message->lock) api_lock_unlock(message->lock);
}
static inline FuriHalBtProfile get_hal_bt_profile(BtProfile profile) {
if(profile == BtProfileHidKeyboard) {
return FuriHalBtProfileHidKeyboard;
} else {
return FuriHalBtProfileSerial;
}
}
void bt_restart(Bt* bt) {
furi_hal_bt_change_app(get_hal_bt_profile(bt->profile), bt_on_gap_event_callback, bt);
furi_hal_bt_start_advertising();
}
void bt_set_profile_adv_name(Bt* bt, const char* fmt, ...) {
furi_assert(bt);
furi_assert(fmt);
char name[FURI_HAL_BT_ADV_NAME_LENGTH];
va_list args;
va_start(args, fmt);
vsnprintf(name, sizeof(name), fmt, args);
va_end(args);
furi_hal_bt_set_profile_adv_name(get_hal_bt_profile(bt->profile), name);
bt_restart(bt);
}
const char* bt_get_profile_adv_name(Bt* bt) {
furi_assert(bt);
return furi_hal_bt_get_profile_adv_name(get_hal_bt_profile(bt->profile));
}
void bt_set_profile_mac_address(Bt* bt, const uint8_t mac[6]) {
furi_assert(bt);
furi_assert(mac);
furi_hal_bt_set_profile_mac_addr(get_hal_bt_profile(bt->profile), mac);
bt_restart(bt);
}
const uint8_t* bt_get_profile_mac_address(Bt* bt) {
furi_assert(bt);
return furi_hal_bt_get_profile_mac_addr(get_hal_bt_profile(bt->profile));
}
bool bt_remote_rssi(Bt* bt, uint8_t* rssi) {
furi_assert(bt);
@ -492,27 +452,6 @@ bool bt_remote_rssi(Bt* bt, uint8_t* rssi) {
return true;
}
void bt_set_profile_pairing_method(Bt* bt, GapPairing pairing_method) {
furi_assert(bt);
furi_hal_bt_set_profile_pairing_method(get_hal_bt_profile(bt->profile), pairing_method);
bt_restart(bt);
}
GapPairing bt_get_profile_pairing_method(Bt* bt) {
furi_assert(bt);
return furi_hal_bt_get_profile_pairing_method(get_hal_bt_profile(bt->profile));
}
void bt_disable_peer_key_update(Bt* bt) {
UNUSED(bt);
furi_hal_bt_set_key_storage_change_callback(NULL, NULL);
}
void bt_enable_peer_key_update(Bt* bt) {
furi_assert(bt);
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
}
int32_t bt_srv(void* p) {
UNUSED(p);
Bt* bt = bt_alloc();

View File

@ -5,8 +5,6 @@
#include <furi_ble/profile_interface.h>
#include <core/common_defines.h>
#include <furi_hal_bt.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -22,6 +20,11 @@ typedef enum {
BtStatusConnected,
} BtStatus;
typedef struct {
uint8_t rssi;
uint32_t since;
} BtRssi;
typedef void (*BtStatusChangedCallback)(BtStatus status, void* context);
/** Change BLE Profile
@ -81,31 +84,20 @@ void bt_keys_storage_set_storage_path(Bt* bt, const char* keys_storage_path);
*/
void bt_keys_storage_set_default_path(Bt* bt);
// New methods
void bt_set_profile_adv_name(Bt* bt, const char* fmt, ...);
const char* bt_get_profile_adv_name(Bt* bt);
void bt_set_profile_mac_address(Bt* bt, const uint8_t mac[6]);
const uint8_t* bt_get_profile_mac_address(Bt* bt);
bool bt_remote_rssi(Bt* bt, uint8_t* rssi);
void bt_set_profile_pairing_method(Bt* bt, GapPairing pairing_method);
GapPairing bt_get_profile_pairing_method(Bt* bt);
/** Stop saving new peer key to flash (in .bt.keys file)
/**
*
* (Probably bad) way of opening the RPC connection, everywhereTM
*/
void bt_disable_peer_key_update(Bt* bt);
/** Enable saving peer key to internal flash (enable by default)
void bt_open_rpc_connection(Bt* bt);
/**
*
* @note This function should be called if bt_disable_peer_key_update was called before
* Closing the RPC connection, everywhereTM
*/
void bt_enable_peer_key_update(Bt* bt);
void bt_close_rpc_connection(Bt* bt);
#ifdef __cplusplus
}

View File

@ -99,7 +99,7 @@ int32_t namechanger_on_system_start(void* p) {
furi_delay_ms(3);
Bt* bt = furi_record_open(RECORD_BT);
if(!bt_set_profile(bt, BtProfileSerial)) {
if(!bt_profile_restore_default(bt)) {
//FURI_LOG_D(TAG, "Failed to touch bluetooth to name change");
}
furi_record_close(RECORD_BT);

View File

@ -100,13 +100,6 @@ bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile);
*/
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta);
/** Retrieves LED state from remote BT HID host
*
* @return (look at HID usage page to know what each bit of the returned byte means)
* NB: RFU bit has been shifted out in the returned octet so USB defines should work
*/
uint8_t furi_hal_bt_hid_get_led_state(void);
#ifdef __cplusplus
}
#endif

View File

@ -748,17 +748,15 @@ Function,+,ble_svc_serial_start,BleServiceSerial*,
Function,+,ble_svc_serial_stop,void,BleServiceSerial*
Function,+,ble_svc_serial_update_tx,_Bool,"BleServiceSerial*, uint8_t*, uint16_t"
Function,-,bsearch,void*,"const void*, const void*, size_t, size_t, __compar_fn_t"
Function,+,bt_disable_peer_key_update,void,Bt*
Function,-,bt_close_rpc_connection,void,Bt*
Function,+,bt_disconnect,void,Bt*
Function,+,bt_enable_peer_key_update,void,Bt*
Function,+,bt_forget_bonded_devices,void,Bt*
Function,+,bt_get_profile_adv_name,const char*,Bt*
Function,+,bt_get_profile_mac_address,const uint8_t*,Bt*
Function,+,bt_get_profile_pairing_method,GapPairing,Bt*
Function,+,bt_keys_storage_set_default_path,void,Bt*
Function,+,bt_keys_storage_set_storage_path,void,"Bt*, const char*"
Function,-,bt_open_rpc_connection,void,Bt*
Function,+,bt_profile_restore_default,_Bool,Bt*
Function,+,bt_profile_start,FuriHalBleProfileBase*,"Bt*, const FuriHalBleProfileTemplate*, FuriHalBleProfileParams"
Function,+,bt_remote_rssi,_Bool,"Bt*, uint8_t*"
Function,+,bt_set_status_changed_callback,void,"Bt*, BtStatusChangedCallback, void*"
Function,+,buffered_file_stream_alloc,Stream*,Storage*
Function,+,buffered_file_stream_close,_Bool,Stream*
@ -1190,9 +1188,6 @@ Function,+,furi_get_tick,uint32_t,
Function,+,furi_hal_bt_change_app,FuriHalBleProfileBase*,"const FuriHalBleProfileTemplate*, FuriHalBleProfileParams, GapEventCallback, void*"
Function,+,furi_hal_bt_check_profile_type,_Bool,"FuriHalBleProfileBase*, const FuriHalBleProfileTemplate*"
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_extra_beacon_get_config,const GapExtraBeaconConfig*,
@ -1202,17 +1197,15 @@ Function,+,furi_hal_bt_extra_beacon_set_config,_Bool,const GapExtraBeaconConfig*
Function,+,furi_hal_bt_extra_beacon_set_data,_Bool,"const uint8_t*, uint8_t"
Function,+,furi_hal_bt_extra_beacon_start,_Bool,
Function,+,furi_hal_bt_extra_beacon_stop,_Bool,
Function,-,furi_hal_bt_get_conn_rssi,uint32_t,uint8_t*
Function,+,furi_hal_bt_get_key_storage_buff,void,"uint8_t**, uint16_t*"
Function,+,furi_hal_bt_get_profile_adv_name,const char*,FuriHalBtProfile
Function,+,furi_hal_bt_get_profile_mac_addr,const uint8_t*,FuriHalBtProfile
Function,-,furi_hal_bt_get_profile_pairing_method,GapPairing,FuriHalBtProfile
Function,+,furi_hal_bt_get_radio_stack,FuriHalBtStack,
Function,+,furi_hal_bt_get_rssi,float,
Function,+,furi_hal_bt_get_transmitted_packets,uint32_t,
Function,+,furi_hal_bt_hid_consumer_key_press,_Bool,uint16_t
Function,-,furi_hal_bt_init,void,
Function,+,furi_hal_bt_is_active,_Bool,
Function,+,furi_hal_bt_is_alive,_Bool,
Function,+,furi_hal_bt_is_connected,_Bool,
Function,+,furi_hal_bt_is_gatt_gap_supported,_Bool,
Function,+,furi_hal_bt_is_testing_supported,_Bool,
Function,+,furi_hal_bt_lock_core2,void,
@ -1221,9 +1214,6 @@ Function,+,furi_hal_bt_nvm_sram_sem_release,void,
Function,+,furi_hal_bt_reinit,void,
Function,+,furi_hal_bt_reverse_mac_addr,void,uint8_t[( 6 )]
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 )]"
Function,+,furi_hal_bt_set_profile_pairing_method,void,"FuriHalBtProfile, GapPairing"
Function,+,furi_hal_bt_start_advertising,void,
Function,+,furi_hal_bt_start_app,FuriHalBleProfileBase*,"const FuriHalBleProfileTemplate*, FuriHalBleProfileParams, GapEventCallback, void*"
Function,+,furi_hal_bt_start_packet_rx,void,"uint8_t, uint8_t"
@ -1851,6 +1841,7 @@ Function,-,gap_extra_beacon_set_config,_Bool,const GapExtraBeaconConfig*
Function,-,gap_extra_beacon_set_data,_Bool,"const uint8_t*, uint8_t"
Function,-,gap_extra_beacon_start,_Bool,
Function,-,gap_extra_beacon_stop,_Bool,
Function,-,gap_get_remote_conn_rssi,uint32_t,int8_t*
Function,-,gap_get_state,GapState,
Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
Function,-,gap_start_advertising,void,

1 entry status name type params
748 Function + ble_svc_serial_stop void BleServiceSerial*
749 Function + ble_svc_serial_update_tx _Bool BleServiceSerial*, uint8_t*, uint16_t
750 Function - bsearch void* const void*, const void*, size_t, size_t, __compar_fn_t
751 Function + - bt_disable_peer_key_update bt_close_rpc_connection void Bt*
752 Function + bt_disconnect void Bt*
Function + bt_enable_peer_key_update void Bt*
753 Function + bt_forget_bonded_devices void Bt*
Function + bt_get_profile_adv_name const char* Bt*
Function + bt_get_profile_mac_address const uint8_t* Bt*
Function + bt_get_profile_pairing_method GapPairing Bt*
754 Function + bt_keys_storage_set_default_path void Bt*
755 Function + bt_keys_storage_set_storage_path void Bt*, const char*
756 Function - bt_open_rpc_connection void Bt*
757 Function + bt_profile_restore_default _Bool Bt*
758 Function + bt_profile_start FuriHalBleProfileBase* Bt*, const FuriHalBleProfileTemplate*, FuriHalBleProfileParams
759 Function + bt_remote_rssi _Bool Bt*, uint8_t*
760 Function + bt_set_status_changed_callback void Bt*, BtStatusChangedCallback, void*
761 Function + buffered_file_stream_alloc Stream* Storage*
762 Function + buffered_file_stream_close _Bool Stream*
1188 Function + furi_hal_bt_change_app FuriHalBleProfileBase* const FuriHalBleProfileTemplate*, FuriHalBleProfileParams, GapEventCallback, void*
1189 Function + furi_hal_bt_check_profile_type _Bool FuriHalBleProfileBase*, const FuriHalBleProfileTemplate*
1190 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
1191 Function + furi_hal_bt_dump_state void FuriString*
1192 Function + furi_hal_bt_ensure_c2_mode _Bool BleGlueC2Mode
1193 Function + furi_hal_bt_extra_beacon_get_config const GapExtraBeaconConfig*
1197 Function + furi_hal_bt_extra_beacon_set_data _Bool const uint8_t*, uint8_t
1198 Function + furi_hal_bt_extra_beacon_start _Bool
1199 Function + furi_hal_bt_extra_beacon_stop _Bool
1200 Function - furi_hal_bt_get_conn_rssi uint32_t uint8_t*
1201 Function + furi_hal_bt_get_key_storage_buff void uint8_t**, uint16_t*
Function + furi_hal_bt_get_profile_adv_name const char* FuriHalBtProfile
Function + furi_hal_bt_get_profile_mac_addr const uint8_t* FuriHalBtProfile
Function - furi_hal_bt_get_profile_pairing_method GapPairing FuriHalBtProfile
1202 Function + furi_hal_bt_get_radio_stack FuriHalBtStack
1203 Function + furi_hal_bt_get_rssi float
1204 Function + furi_hal_bt_get_transmitted_packets uint32_t
Function + furi_hal_bt_hid_consumer_key_press _Bool uint16_t
1205 Function - furi_hal_bt_init void
1206 Function + furi_hal_bt_is_active _Bool
1207 Function + furi_hal_bt_is_alive _Bool
1208 Function + furi_hal_bt_is_connected _Bool
1209 Function + furi_hal_bt_is_gatt_gap_supported _Bool
1210 Function + furi_hal_bt_is_testing_supported _Bool
1211 Function + furi_hal_bt_lock_core2 void
1214 Function + furi_hal_bt_reinit void
1215 Function + furi_hal_bt_reverse_mac_addr void uint8_t[( 6 )]
1216 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 )]
Function + furi_hal_bt_set_profile_pairing_method void FuriHalBtProfile, GapPairing
1217 Function + furi_hal_bt_start_advertising void
1218 Function + furi_hal_bt_start_app FuriHalBleProfileBase* const FuriHalBleProfileTemplate*, FuriHalBleProfileParams, GapEventCallback, void*
1219 Function + furi_hal_bt_start_packet_rx void uint8_t, uint8_t
1841 Function - gap_extra_beacon_set_data _Bool const uint8_t*, uint8_t
1842 Function - gap_extra_beacon_start _Bool
1843 Function - gap_extra_beacon_stop _Bool
1844 Function - gap_get_remote_conn_rssi uint32_t int8_t*
1845 Function - gap_get_state GapState
1846 Function - gap_init _Bool GapConfig*, GapEventCallback, void*
1847 Function - gap_start_advertising void

View File

@ -63,7 +63,7 @@ void ble_gatt_characteristic_init(
char_data_descriptor->security_permissions,
char_data_descriptor->access_permissions,
char_data_descriptor->gatt_evt_mask,
MIN_ENCRY_KEY_SIZE,
GATT_MIN_READ_KEY_SIZE,
char_data_descriptor->is_variable,
&char_instance->descriptor_handle);
if(status) {

View File

@ -372,35 +372,33 @@ static void gap_init_svc(Gap* gap) {
// Set default PHY
hci_le_set_default_phy(ALL_PHYS_PREFERENCE, TX_2M_PREFERRED, RX_2M_PREFERRED);
// Set I/O capability
bool bonding_mode = gap->config->bonding_mode;
uint8_t cfg_mitm_protection = CFG_MITM_PROTECTION;
uint8_t cfg_used_fixed_pin = CFG_USED_FIXED_PIN;
bool keypress_supported = false;
// New things below
uint8_t conf_mitm = CFG_MITM_PROTECTION;
uint8_t conf_used_fixed_pin = CFG_USED_FIXED_PIN;
bool conf_bonding = gap->config->bonding_mode;
if(gap->config->pairing_method == GapPairingPinCodeShow) {
aci_gap_set_io_capability(IO_CAP_DISPLAY_ONLY);
} else if(gap->config->pairing_method == GapPairingPinCodeVerifyYesNo) {
aci_gap_set_io_capability(IO_CAP_DISPLAY_YES_NO);
keypress_supported = true;
} else if(gap->config->pairing_method == GapPairingNone) {
// Just works pairing method (IOS accept it, it seems android and linux doesn't)
conf_mitm = 0;
conf_used_fixed_pin = 0;
conf_bonding = false;
// if just works isn't supported, we want the numeric comparaison method
// "Just works" pairing method (iOS accepts it, it seems Android and Linux don't)
bonding_mode = false;
cfg_mitm_protection = MITM_PROTECTION_NOT_REQUIRED;
cfg_used_fixed_pin = USE_FIXED_PIN_FOR_PAIRING_ALLOWED;
// If "just works" isn't supported, we want the numeric comparaison method
aci_gap_set_io_capability(IO_CAP_DISPLAY_YES_NO);
keypress_supported = true;
}
// Setup authentication
aci_gap_set_authentication_requirement(
conf_bonding,
conf_mitm,
bonding_mode,
cfg_mitm_protection,
CFG_SC_SUPPORT,
keypress_supported,
CFG_ENCRYPTION_KEY_SIZE_MIN,
CFG_ENCRYPTION_KEY_SIZE_MAX,
conf_used_fixed_pin, // 0x0 for no pin
cfg_used_fixed_pin,
0,
CFG_IDENTITY_ADDRESS);
// Configure whitelist
@ -554,6 +552,17 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
return true;
}
// Get RSSI
uint32_t gap_get_remote_conn_rssi(int8_t* rssi) {
if(gap && gap->state == GapStateConnected) {
fetch_rssi();
*rssi = gap->conn_rssi;
if(gap->time_rssi_sample) return furi_get_tick() - gap->time_rssi_sample;
}
return 0;
}
GapState gap_get_state(void) {
GapState state;
if(gap) {

View File

@ -73,7 +73,7 @@ typedef struct {
bool bonding_mode;
GapPairing pairing_method;
uint8_t mac_address[GAP_MAC_ADDR_SIZE];
char adv_name[FURI_HAL_BT_ADV_NAME_LENGTH];
char adv_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH];
GapConnectionParamsRequest conn_param;
} GapConfig;

View File

@ -402,51 +402,6 @@ uint32_t furi_hal_bt_get_conn_rssi(uint8_t* rssi) {
return since;
}
// API for BLE beacon plugin
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]) {
uint8_t tmp;
for(size_t i = 0; i < GAP_MAC_ADDR_SIZE / 2; i++) {
@ -456,52 +411,6 @@ void furi_hal_bt_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) {
}
}
void furi_hal_bt_set_profile_adv_name(
FuriHalBtProfile profile,
const char name[FURI_HAL_BT_ADV_NAME_LENGTH]) {
furi_assert(profile < FuriHalBtProfileNumber);
furi_assert(name);
if(strlen(name) == 0) {
memset(&(profile_config[profile].config.adv_name[1]), 0, FURI_HAL_BT_ADV_NAME_LENGTH - 1);
} else {
profile_config[profile].config.adv_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
strlcpy(
&(profile_config[profile].config.adv_name[1]),
name,
FURI_HAL_BT_ADV_NAME_LENGTH - 1 /* BLE symbol */);
}
}
const char* furi_hal_bt_get_profile_adv_name(FuriHalBtProfile profile) {
furi_assert(profile < FuriHalBtProfileNumber);
return &(profile_config[profile].config.adv_name[1]);
}
void furi_hal_bt_set_profile_mac_addr(
FuriHalBtProfile profile,
const uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) {
furi_assert(profile < FuriHalBtProfileNumber);
furi_assert(mac_addr);
memcpy(profile_config[profile].config.mac_address, mac_addr, GAP_MAC_ADDR_SIZE);
}
const uint8_t* furi_hal_bt_get_profile_mac_addr(FuriHalBtProfile profile) {
furi_assert(profile < FuriHalBtProfileNumber);
return profile_config[profile].config.mac_address;
}
void furi_hal_bt_set_profile_pairing_method(FuriHalBtProfile profile, GapPairing pairing_method) {
furi_assert(profile < FuriHalBtProfileNumber);
profile_config[profile].config.pairing_method = pairing_method;
}
GapPairing furi_hal_bt_get_profile_pairing_method(FuriHalBtProfile profile) {
furi_assert(profile < FuriHalBtProfileNumber);
return profile_config[profile].config.pairing_method;
}
uint32_t furi_hal_bt_get_transmitted_packets() {
uint32_t packets = 0;
aci_hal_le_tx_test_packet_number(&packets);

View File

@ -91,7 +91,14 @@ typedef struct {
static FuriHalVersion furi_hal_version = {0};
void furi_hal_version_set_name(const char* name) {
if(name != NULL) {
uint32_t udn = LL_FLASH_GetUDN();
if(name == NULL) {
name = version_get_custom_name(NULL);
if(name != NULL) {
udn = *((uint32_t*)name);
}
}
if(name != NULL && strlen(name)) {
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
snprintf(
furi_hal_version.device_name,
@ -105,11 +112,6 @@ void furi_hal_version_set_name(const char* name) {
furi_hal_version.device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
// BLE Mac address
uint32_t udn = LL_FLASH_GetUDN();
if(version_get_custom_name(NULL) != NULL) {
udn = *((uint32_t*)version_get_custom_name(NULL));
}
uint32_t company_id = LL_FLASH_GetSTCompanyID();
// uint32_t device_id = LL_FLASH_GetDeviceID();
// Some flippers return 0x27 (flippers with chip revision 2003 6495) instead of 0x26 (flippers with chip revision 2001 6495)
@ -137,11 +139,7 @@ static void furi_hal_version_load_otp_v0() {
furi_hal_version.board_body = otp->board_body;
furi_hal_version.board_connect = otp->board_connect;
if(version_get_custom_name(NULL) != NULL) {
furi_hal_version_set_name(version_get_custom_name(NULL));
} else {
furi_hal_version_set_name(otp->name);
}
furi_hal_version_set_name(otp->name);
}
static void furi_hal_version_load_otp_v1() {
@ -155,11 +153,7 @@ static void furi_hal_version_load_otp_v1() {
furi_hal_version.board_color = otp->board_color;
furi_hal_version.board_region = otp->board_region;
if(version_get_custom_name(NULL) != NULL) {
furi_hal_version_set_name(version_get_custom_name(NULL));
} else {
furi_hal_version_set_name(otp->name);
}
furi_hal_version_set_name(otp->name);
}
static void furi_hal_version_load_otp_v2() {
@ -179,11 +173,7 @@ static void furi_hal_version_load_otp_v2() {
if(otp->board_color != 0xFF) {
furi_hal_version.board_color = otp->board_color;
furi_hal_version.board_region = otp->board_region;
if(version_get_custom_name(NULL) != NULL) {
furi_hal_version_set_name(version_get_custom_name(NULL));
} else {
furi_hal_version_set_name(otp->name);
}
furi_hal_version_set_name(otp->name);
} else {
furi_hal_version.board_color = 0;
furi_hal_version.board_region = 0;

View File

@ -18,12 +18,6 @@
#define FURI_HAL_BT_STACK_VERSION_MINOR (12)
#define FURI_HAL_BT_C2_START_TIMEOUT (1000)
#define FURI_HAL_BT_EMPTY_MAC_ADDR \
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
#define FURI_HAL_BT_DEFAULT_MAC_ADDR \
{ 0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x72 }
#ifdef __cplusplus
extern "C" {
#endif
@ -236,69 +230,13 @@ float furi_hal_bt_get_rssi();
*/
uint32_t furi_hal_bt_get_transmitted_packets();
// BadBT Stuff
/** Reverse a MAC address byte order in-place
* @param[in] mac mac address to reverse
*/
void furi_hal_bt_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]);
/** Modify profile advertisement name and restart bluetooth
* @param[in] profile profile type
* @param[in] name new adv name
*/
void furi_hal_bt_set_profile_adv_name(
FuriHalBtProfile profile,
const char name[FURI_HAL_BT_ADV_NAME_LENGTH]);
const char* furi_hal_bt_get_profile_adv_name(FuriHalBtProfile profile);
/** Modify profile mac address and restart bluetooth
* @param[in] profile profile type
* @param[in] mac new mac address
*/
void furi_hal_bt_set_profile_mac_addr(
FuriHalBtProfile profile,
const uint8_t mac_addr[GAP_MAC_ADDR_SIZE]);
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
/** 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);
GapPairing furi_hal_bt_get_profile_pairing_method(FuriHalBtProfile profile);
bool furi_hal_bt_is_connected(void);
/** Check & switch C2 to given mode

View File

@ -46,8 +46,6 @@ bool furi_hal_region_is_provisioned();
*
* 2 letter Region code according to iso 3166 standard
* There are 2 extra values that we use in special cases:
* RM, whats the reason you not doing a release?
* Waiting for my commits?
* - "00" - developer edition, unlocked
* - "WW" - world wide, region provisioned by default
* - "--" - no provisioned region

View File

@ -16,10 +16,9 @@ extern "C" {
#define FURI_HAL_VERSION_NAME_LENGTH 8
#define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1)
/** BLE symbol + "Flipper " + name */
#define FURI_HAL_VERSION_DEVICE_NAME_LENGTH (1 + 8 + FURI_HAL_VERSION_ARRAY_NAME_LENGTH)
// 18 characters + null terminator
#define FURI_HAL_BT_ADV_NAME_LENGTH (FURI_HAL_VERSION_DEVICE_NAME_LENGTH + 1)
#define FURI_HAL_BT_ADV_NAME_LENGTH (18 + 1) // 18 characters + null terminator
#define FURI_HAL_VERSION_DEVICE_NAME_LENGTH \
(1 + FURI_HAL_BT_ADV_NAME_LENGTH) // Used for custom BT name, BLE symbol + name
/** OTP Versions enum */
typedef enum {