mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-14 13:08:35 -07:00
Merge branch 'ble-refactor' into xfw-dev
This commit is contained in:
11
applications/examples/example_ble_beacon/application.fam
Normal file
11
applications/examples/example_ble_beacon/application.fam
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
App(
|
||||||
|
appid="example_ble_beacon",
|
||||||
|
name="Example: BLE Beacon",
|
||||||
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
|
entry_point="ble_beacon_app",
|
||||||
|
requires=["gui"],
|
||||||
|
stack_size=1 * 1024,
|
||||||
|
fap_icon="example_ble_beacon_10px.png",
|
||||||
|
fap_category="Examples",
|
||||||
|
fap_icon_assets="images",
|
||||||
|
)
|
||||||
149
applications/examples/example_ble_beacon/ble_beacon_app.c
Normal file
149
applications/examples/example_ble_beacon/ble_beacon_app.c
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#include "ble_beacon_app.h"
|
||||||
|
|
||||||
|
#include <extra_beacon.h>
|
||||||
|
#include <furi_hal_version.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define TAG "ble_beacon_app"
|
||||||
|
|
||||||
|
static bool ble_beacon_app_custom_event_callback(void* context, uint32_t event) {
|
||||||
|
furi_assert(context);
|
||||||
|
BleBeaconApp* app = context;
|
||||||
|
return scene_manager_handle_custom_event(app->scene_manager, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ble_beacon_app_back_event_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
BleBeaconApp* app = context;
|
||||||
|
return scene_manager_handle_back_event(app->scene_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_beacon_app_tick_event_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
BleBeaconApp* app = context;
|
||||||
|
scene_manager_handle_tick_event(app->scene_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_beacon_app_restore_beacon_state(BleBeaconApp* app) {
|
||||||
|
// Restore beacon data from service
|
||||||
|
GapExtraBeaconConfig* local_config = &app->beacon_config;
|
||||||
|
const GapExtraBeaconConfig* config = furi_hal_bt_extra_beacon_get_config();
|
||||||
|
if(config) {
|
||||||
|
// We have a config, copy it
|
||||||
|
memcpy(local_config, config, sizeof(app->beacon_config));
|
||||||
|
} else {
|
||||||
|
// No config, set up default values - they will stay until overriden or device is reset
|
||||||
|
local_config->min_adv_interval_ms = 50;
|
||||||
|
local_config->max_adv_interval_ms = 150;
|
||||||
|
|
||||||
|
local_config->adv_channel_map = GapAdvChannelMapAll;
|
||||||
|
local_config->adv_power_level = GapAdvPowerLevel_0dBm;
|
||||||
|
|
||||||
|
local_config->address_type = GapAddressTypePublic;
|
||||||
|
memcpy(
|
||||||
|
local_config->address, furi_hal_version_get_ble_mac(), sizeof(local_config->address));
|
||||||
|
// Modify MAC address to make it different from the one used by the main app
|
||||||
|
local_config->address[0] ^= 0xFF;
|
||||||
|
local_config->address[3] ^= 0xFF;
|
||||||
|
|
||||||
|
furi_check(furi_hal_bt_extra_beacon_set_config(local_config));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get beacon state
|
||||||
|
app->is_beacon_active = furi_hal_bt_extra_beacon_is_active();
|
||||||
|
|
||||||
|
// Restore last beacon data
|
||||||
|
app->beacon_data_len = furi_hal_bt_extra_beacon_get_data(app->beacon_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BleBeaconApp* ble_beacon_app_alloc() {
|
||||||
|
BleBeaconApp* app = malloc(sizeof(BleBeaconApp));
|
||||||
|
|
||||||
|
app->gui = furi_record_open(RECORD_GUI);
|
||||||
|
|
||||||
|
app->scene_manager = scene_manager_alloc(&ble_beacon_app_scene_handlers, app);
|
||||||
|
app->view_dispatcher = view_dispatcher_alloc();
|
||||||
|
|
||||||
|
app->status_string = furi_string_alloc();
|
||||||
|
|
||||||
|
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
|
||||||
|
view_dispatcher_set_custom_event_callback(
|
||||||
|
app->view_dispatcher, ble_beacon_app_custom_event_callback);
|
||||||
|
view_dispatcher_set_navigation_event_callback(
|
||||||
|
app->view_dispatcher, ble_beacon_app_back_event_callback);
|
||||||
|
view_dispatcher_set_tick_event_callback(
|
||||||
|
app->view_dispatcher, ble_beacon_app_tick_event_callback, 100);
|
||||||
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
||||||
|
view_dispatcher_enable_queue(app->view_dispatcher);
|
||||||
|
|
||||||
|
app->submenu = submenu_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
app->view_dispatcher, BleBeaconAppViewSubmenu, submenu_get_view(app->submenu));
|
||||||
|
|
||||||
|
app->dialog_ex = dialog_ex_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
app->view_dispatcher, BleBeaconAppViewDialog, dialog_ex_get_view(app->dialog_ex));
|
||||||
|
|
||||||
|
app->byte_input = byte_input_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
app->view_dispatcher, BleBeaconAppViewByteInput, byte_input_get_view(app->byte_input));
|
||||||
|
|
||||||
|
ble_beacon_app_restore_beacon_state(app);
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_beacon_app_free(BleBeaconApp* app) {
|
||||||
|
view_dispatcher_remove_view(app->view_dispatcher, BleBeaconAppViewByteInput);
|
||||||
|
view_dispatcher_remove_view(app->view_dispatcher, BleBeaconAppViewSubmenu);
|
||||||
|
view_dispatcher_remove_view(app->view_dispatcher, BleBeaconAppViewDialog);
|
||||||
|
|
||||||
|
free(app->byte_input);
|
||||||
|
free(app->submenu);
|
||||||
|
free(app->dialog_ex);
|
||||||
|
|
||||||
|
free(app->scene_manager);
|
||||||
|
free(app->view_dispatcher);
|
||||||
|
|
||||||
|
free(app->status_string);
|
||||||
|
|
||||||
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
|
furi_record_close(RECORD_GUI);
|
||||||
|
app->gui = NULL;
|
||||||
|
|
||||||
|
free(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ble_beacon_app(void* args) {
|
||||||
|
UNUSED(args);
|
||||||
|
|
||||||
|
BleBeaconApp* app = ble_beacon_app_alloc();
|
||||||
|
|
||||||
|
scene_manager_next_scene(app->scene_manager, BleBeaconAppSceneRunBeacon);
|
||||||
|
|
||||||
|
view_dispatcher_run(app->view_dispatcher);
|
||||||
|
|
||||||
|
ble_beacon_app_free(app);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_update_state(BleBeaconApp* app) {
|
||||||
|
furi_hal_bt_extra_beacon_stop();
|
||||||
|
|
||||||
|
furi_check(furi_hal_bt_extra_beacon_set_config(&app->beacon_config));
|
||||||
|
|
||||||
|
app->beacon_data_len = 0;
|
||||||
|
while((app->beacon_data[app->beacon_data_len] != 0) &&
|
||||||
|
(app->beacon_data_len < sizeof(app->beacon_data))) {
|
||||||
|
app->beacon_data_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_I(TAG, "beacon_data_len: %d", app->beacon_data_len);
|
||||||
|
|
||||||
|
furi_check(furi_hal_bt_extra_beacon_set_data(app->beacon_data, app->beacon_data_len));
|
||||||
|
|
||||||
|
if(app->is_beacon_active) {
|
||||||
|
furi_check(furi_hal_bt_extra_beacon_start());
|
||||||
|
}
|
||||||
|
}
|
||||||
50
applications/examples/example_ble_beacon/ble_beacon_app.h
Normal file
50
applications/examples/example_ble_beacon/ble_beacon_app.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "extra_beacon.h"
|
||||||
|
#include <furi.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <gui/view.h>
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
#include <gui/view_dispatcher.h>
|
||||||
|
|
||||||
|
#include <gui/modules/widget.h>
|
||||||
|
#include <gui/modules/submenu.h>
|
||||||
|
#include <gui/modules/byte_input.h>
|
||||||
|
#include <gui/modules/dialog_ex.h>
|
||||||
|
|
||||||
|
#include <rpc/rpc_app.h>
|
||||||
|
#include <notification/notification_messages.h>
|
||||||
|
|
||||||
|
#include <furi_hal_bt.h>
|
||||||
|
|
||||||
|
#include "scenes/scenes.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Gui* gui;
|
||||||
|
SceneManager* scene_manager;
|
||||||
|
ViewDispatcher* view_dispatcher;
|
||||||
|
|
||||||
|
Submenu* submenu;
|
||||||
|
ByteInput* byte_input;
|
||||||
|
DialogEx* dialog_ex;
|
||||||
|
|
||||||
|
FuriString* status_string;
|
||||||
|
|
||||||
|
GapExtraBeaconConfig beacon_config;
|
||||||
|
uint8_t beacon_data[EXTRA_BEACON_MAX_DATA_SIZE];
|
||||||
|
uint8_t beacon_data_len;
|
||||||
|
bool is_beacon_active;
|
||||||
|
} BleBeaconApp;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BleBeaconAppViewSubmenu,
|
||||||
|
BleBeaconAppViewByteInput,
|
||||||
|
BleBeaconAppViewDialog,
|
||||||
|
} BleBeaconAppView;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BleBeaconAppCustomEventDataEditResult = 100,
|
||||||
|
} BleBeaconAppCustomEvent;
|
||||||
|
|
||||||
|
void ble_beacon_app_update_state(BleBeaconApp* app);
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.7 KiB |
@@ -0,0 +1,4 @@
|
|||||||
|
ADD_SCENE(ble_beacon_app, menu, Menu)
|
||||||
|
ADD_SCENE(ble_beacon_app, input_mac_addr, InputMacAddress)
|
||||||
|
ADD_SCENE(ble_beacon_app, input_beacon_data, InputBeaconData)
|
||||||
|
ADD_SCENE(ble_beacon_app, run_beacon, RunBeacon)
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include "../ble_beacon_app.h"
|
||||||
|
|
||||||
|
static void ble_beacon_app_scene_add_type_byte_input_callback(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
ble_beacon->view_dispatcher, BleBeaconAppCustomEventDataEditResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_input_beacon_data_on_enter(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
byte_input_set_header_text(ble_beacon->byte_input, "Enter beacon data");
|
||||||
|
|
||||||
|
byte_input_set_result_callback(
|
||||||
|
ble_beacon->byte_input,
|
||||||
|
ble_beacon_app_scene_add_type_byte_input_callback,
|
||||||
|
NULL,
|
||||||
|
context,
|
||||||
|
ble_beacon->beacon_data,
|
||||||
|
sizeof(ble_beacon->beacon_data));
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewByteInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_beacon_app_scene_input_beacon_data_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == BleBeaconAppCustomEventDataEditResult) {
|
||||||
|
ble_beacon_app_update_state(ble_beacon);
|
||||||
|
scene_manager_previous_scene(scene_manager);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_input_beacon_data_on_exit(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
|
||||||
|
byte_input_set_result_callback(ble_beacon->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||||
|
byte_input_set_header_text(ble_beacon->byte_input, NULL);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include "../ble_beacon_app.h"
|
||||||
|
|
||||||
|
static void ble_beacon_app_scene_add_type_byte_input_callback(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
view_dispatcher_send_custom_event(
|
||||||
|
ble_beacon->view_dispatcher, BleBeaconAppCustomEventDataEditResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_input_mac_addr_on_enter(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
byte_input_set_header_text(ble_beacon->byte_input, "Enter MAC (reversed)");
|
||||||
|
|
||||||
|
byte_input_set_result_callback(
|
||||||
|
ble_beacon->byte_input,
|
||||||
|
ble_beacon_app_scene_add_type_byte_input_callback,
|
||||||
|
NULL,
|
||||||
|
context,
|
||||||
|
ble_beacon->beacon_config.address,
|
||||||
|
sizeof(ble_beacon->beacon_config.address));
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewByteInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_beacon_app_scene_input_mac_addr_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == BleBeaconAppCustomEventDataEditResult) {
|
||||||
|
ble_beacon_app_update_state(ble_beacon);
|
||||||
|
scene_manager_previous_scene(scene_manager);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_input_mac_addr_on_exit(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
|
||||||
|
byte_input_set_result_callback(ble_beacon->byte_input, NULL, NULL, NULL, NULL, 0);
|
||||||
|
byte_input_set_header_text(ble_beacon->byte_input, NULL);
|
||||||
|
}
|
||||||
56
applications/examples/example_ble_beacon/scenes/scene_menu.c
Normal file
56
applications/examples/example_ble_beacon/scenes/scene_menu.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "../ble_beacon_app.h"
|
||||||
|
|
||||||
|
enum SubmenuIndex {
|
||||||
|
SubmenuIndexSetMac,
|
||||||
|
SubmenuIndexSetData,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void ble_beacon_app_scene_menu_submenu_callback(void* context, uint32_t index) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
view_dispatcher_send_custom_event(ble_beacon->view_dispatcher, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_menu_on_enter(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
Submenu* submenu = ble_beacon->submenu;
|
||||||
|
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Set MAC",
|
||||||
|
SubmenuIndexSetMac,
|
||||||
|
ble_beacon_app_scene_menu_submenu_callback,
|
||||||
|
ble_beacon);
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Set Data",
|
||||||
|
SubmenuIndexSetData,
|
||||||
|
ble_beacon_app_scene_menu_submenu_callback,
|
||||||
|
ble_beacon);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewSubmenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_beacon_app_scene_menu_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||||
|
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
const uint32_t submenu_index = event.event;
|
||||||
|
if(submenu_index == SubmenuIndexSetMac) {
|
||||||
|
scene_manager_next_scene(scene_manager, BleBeaconAppSceneInputMacAddress);
|
||||||
|
consumed = true;
|
||||||
|
} else if(submenu_index == SubmenuIndexSetData) {
|
||||||
|
scene_manager_next_scene(scene_manager, BleBeaconAppSceneInputBeaconData);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_menu_on_exit(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
submenu_reset(ble_beacon->submenu);
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#include "../ble_beacon_app.h"
|
||||||
|
#include <example_ble_beacon_icons.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
ble_beacon_app_scene_run_beacon_confirm_dialog_callback(DialogExResult result, void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
|
||||||
|
view_dispatcher_send_custom_event(ble_beacon->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update_status_text(BleBeaconApp* ble_beacon) {
|
||||||
|
DialogEx* dialog_ex = ble_beacon->dialog_ex;
|
||||||
|
|
||||||
|
dialog_ex_set_header(dialog_ex, "BLE Beacon Demo", 64, 0, AlignCenter, AlignTop);
|
||||||
|
|
||||||
|
FuriString* status = ble_beacon->status_string;
|
||||||
|
|
||||||
|
furi_string_reset(status);
|
||||||
|
|
||||||
|
furi_string_cat_str(status, "Status: ");
|
||||||
|
if(ble_beacon->is_beacon_active) {
|
||||||
|
furi_string_cat_str(status, "Running\n");
|
||||||
|
} else {
|
||||||
|
furi_string_cat_str(status, "Stopped\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output MAC in reverse order
|
||||||
|
for(int i = sizeof(ble_beacon->beacon_config.address) - 1; i >= 0; i--) {
|
||||||
|
furi_string_cat_printf(status, "%02X", ble_beacon->beacon_config.address[i]);
|
||||||
|
if(i > 0) {
|
||||||
|
furi_string_cat_str(status, ":");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_string_cat_printf(status, "\nData length: %d", ble_beacon->beacon_data_len);
|
||||||
|
|
||||||
|
dialog_ex_set_text(dialog_ex, furi_string_get_cstr(status), 0, 29, AlignLeft, AlignCenter);
|
||||||
|
|
||||||
|
dialog_ex_set_icon(dialog_ex, 93, 20, &I_lighthouse_35x44);
|
||||||
|
|
||||||
|
dialog_ex_set_left_button_text(dialog_ex, "Config");
|
||||||
|
|
||||||
|
dialog_ex_set_center_button_text(dialog_ex, ble_beacon->is_beacon_active ? "Stop" : "Start");
|
||||||
|
|
||||||
|
dialog_ex_set_result_callback(
|
||||||
|
dialog_ex, ble_beacon_app_scene_run_beacon_confirm_dialog_callback);
|
||||||
|
dialog_ex_set_context(dialog_ex, ble_beacon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_run_beacon_on_enter(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
|
||||||
|
update_status_text(ble_beacon);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(ble_beacon->view_dispatcher, BleBeaconAppViewDialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_beacon_app_scene_run_beacon_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
SceneManager* scene_manager = ble_beacon->scene_manager;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == DialogExResultLeft) {
|
||||||
|
scene_manager_next_scene(scene_manager, BleBeaconAppSceneMenu);
|
||||||
|
return true;
|
||||||
|
} else if(event.event == DialogExResultCenter) {
|
||||||
|
ble_beacon->is_beacon_active = !ble_beacon->is_beacon_active;
|
||||||
|
ble_beacon_app_update_state(ble_beacon);
|
||||||
|
update_status_text(ble_beacon);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_beacon_app_scene_run_beacon_on_exit(void* context) {
|
||||||
|
BleBeaconApp* ble_beacon = context;
|
||||||
|
UNUSED(ble_beacon);
|
||||||
|
}
|
||||||
30
applications/examples/example_ble_beacon/scenes/scenes.c
Normal file
30
applications/examples/example_ble_beacon/scenes/scenes.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "scenes.h"
|
||||||
|
|
||||||
|
// Generate scene on_enter handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||||
|
void (*const ble_beacon_app_on_enter_handlers[])(void*) = {
|
||||||
|
#include "scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_event handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||||
|
bool (*const ble_beacon_app_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||||
|
#include "scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_exit handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||||
|
void (*const ble_beacon_app_on_exit_handlers[])(void* context) = {
|
||||||
|
#include "scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Initialize scene handlers configuration structure
|
||||||
|
const SceneManagerHandlers ble_beacon_app_scene_handlers = {
|
||||||
|
.on_enter_handlers = ble_beacon_app_on_enter_handlers,
|
||||||
|
.on_event_handlers = ble_beacon_app_on_event_handlers,
|
||||||
|
.on_exit_handlers = ble_beacon_app_on_exit_handlers,
|
||||||
|
.scene_num = BleBeaconAppSceneNum,
|
||||||
|
};
|
||||||
29
applications/examples/example_ble_beacon/scenes/scenes.h
Normal file
29
applications/examples/example_ble_beacon/scenes/scenes.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
|
||||||
|
// Generate scene id and total number
|
||||||
|
#define ADD_SCENE(prefix, name, id) BleBeaconAppScene##id,
|
||||||
|
typedef enum {
|
||||||
|
#include "scene_config.h"
|
||||||
|
BleBeaconAppSceneNum,
|
||||||
|
} BleBeaconAppScene;
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
extern const SceneManagerHandlers ble_beacon_app_scene_handlers;
|
||||||
|
|
||||||
|
// Generate scene on_enter handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||||
|
#include "scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_event handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) \
|
||||||
|
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||||
|
#include "scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_exit handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||||
|
#include "scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
App(
|
App(
|
||||||
appid="example_custom_font",
|
appid="example_custom_font",
|
||||||
name="Example: custom font",
|
name="Example: custom font",
|
||||||
apptype=FlipperAppType.DEBUG,
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
entry_point="example_custom_font_main",
|
entry_point="example_custom_font_main",
|
||||||
requires=["gui"],
|
requires=["gui"],
|
||||||
stack_size=1 * 1024,
|
stack_size=1 * 1024,
|
||||||
fap_category="Debug",
|
fap_category="Examples",
|
||||||
)
|
)
|
||||||
Submodule applications/external updated: c389bb7442...6798ec01a7
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "archive_files.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ArchiveAppTypeU2f,
|
ArchiveAppTypeU2f,
|
||||||
ArchiveAppTypeSearch,
|
ArchiveAppTypeSearch,
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#include "bad_kb_app.h"
|
#include "bad_kb_app_i.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
#include <lib/toolbox/path.h>
|
#include <lib/toolbox/path.h>
|
||||||
#include <xtreme/xtreme.h>
|
#include <xtreme/xtreme.h>
|
||||||
#include <lib/flipper_format/flipper_format.h>
|
#include <lib/flipper_format/flipper_format.h>
|
||||||
|
|
||||||
#include <bt/bt_service/bt_i.h>
|
#include <bt/bt_service/bt_i.h>
|
||||||
#include <bt/bt_service/bt.h>
|
#include "helpers/ducky_script_i.h"
|
||||||
|
|
||||||
|
// Adjusts to serial MAC +2 in app init
|
||||||
|
uint8_t BAD_KB_BOUND_MAC[GAP_MAC_ADDR_SIZE] = {0};
|
||||||
|
|
||||||
static bool bad_kb_app_custom_event_callback(void* context, uint32_t event) {
|
static bool bad_kb_app_custom_event_callback(void* context, uint32_t event) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
@@ -30,12 +32,6 @@ static void bad_kb_app_tick_event_callback(void* context) {
|
|||||||
static void bad_kb_load_settings(BadKbApp* app) {
|
static void bad_kb_load_settings(BadKbApp* app) {
|
||||||
furi_string_reset(app->keyboard_layout);
|
furi_string_reset(app->keyboard_layout);
|
||||||
BadKbConfig* cfg = &app->config;
|
BadKbConfig* cfg = &app->config;
|
||||||
strcpy(cfg->bt_name, "");
|
|
||||||
memcpy(cfg->bt_mac, BAD_KB_EMPTY_MAC, BAD_KB_MAC_LEN);
|
|
||||||
strcpy(cfg->usb_cfg.manuf, "");
|
|
||||||
strcpy(cfg->usb_cfg.product, "");
|
|
||||||
cfg->usb_cfg.vid = 0;
|
|
||||||
cfg->usb_cfg.pid = 0;
|
|
||||||
|
|
||||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
@@ -45,29 +41,30 @@ static void bad_kb_load_settings(BadKbApp* app) {
|
|||||||
furi_string_reset(app->keyboard_layout);
|
furi_string_reset(app->keyboard_layout);
|
||||||
}
|
}
|
||||||
if(flipper_format_read_string(file, "Bt_Name", tmp_str) && !furi_string_empty(tmp_str)) {
|
if(flipper_format_read_string(file, "Bt_Name", tmp_str) && !furi_string_empty(tmp_str)) {
|
||||||
strlcpy(cfg->bt_name, furi_string_get_cstr(tmp_str), BAD_KB_NAME_LEN);
|
strlcpy(cfg->ble.name, furi_string_get_cstr(tmp_str), sizeof(cfg->ble.name));
|
||||||
} else {
|
} else {
|
||||||
strcpy(cfg->bt_name, "");
|
strcpy(cfg->ble.name, "");
|
||||||
}
|
}
|
||||||
if(!flipper_format_read_hex(file, "Bt_Mac", (uint8_t*)&cfg->bt_mac, BAD_KB_MAC_LEN)) {
|
if(!flipper_format_read_hex(
|
||||||
memcpy(cfg->bt_mac, BAD_KB_EMPTY_MAC, BAD_KB_MAC_LEN);
|
file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac))) {
|
||||||
|
memset(cfg->ble.mac, 0, sizeof(cfg->ble.mac));
|
||||||
}
|
}
|
||||||
if(flipper_format_read_string(file, "Usb_Manuf", tmp_str) && !furi_string_empty(tmp_str)) {
|
if(flipper_format_read_string(file, "Usb_Manuf", tmp_str) && !furi_string_empty(tmp_str)) {
|
||||||
strlcpy(cfg->usb_cfg.manuf, furi_string_get_cstr(tmp_str), BAD_KB_USB_LEN);
|
strlcpy(cfg->usb.manuf, furi_string_get_cstr(tmp_str), sizeof(cfg->usb.manuf));
|
||||||
} else {
|
} else {
|
||||||
strcpy(cfg->usb_cfg.manuf, "");
|
strcpy(cfg->usb.manuf, "");
|
||||||
}
|
}
|
||||||
if(flipper_format_read_string(file, "Usb_Product", tmp_str) &&
|
if(flipper_format_read_string(file, "Usb_Product", tmp_str) &&
|
||||||
!furi_string_empty(tmp_str)) {
|
!furi_string_empty(tmp_str)) {
|
||||||
strlcpy(cfg->usb_cfg.product, furi_string_get_cstr(tmp_str), BAD_KB_USB_LEN);
|
strlcpy(cfg->usb.product, furi_string_get_cstr(tmp_str), sizeof(cfg->usb.product));
|
||||||
} else {
|
} else {
|
||||||
strcpy(cfg->usb_cfg.product, "");
|
strcpy(cfg->usb.product, "");
|
||||||
}
|
}
|
||||||
if(!flipper_format_read_uint32(file, "Usb_Vid", &cfg->usb_cfg.vid, 1)) {
|
if(!flipper_format_read_uint32(file, "Usb_Vid", &cfg->usb.vid, 1)) {
|
||||||
cfg->usb_cfg.vid = 0;
|
cfg->usb.vid = 0;
|
||||||
}
|
}
|
||||||
if(!flipper_format_read_uint32(file, "Usb_Pid", &cfg->usb_cfg.pid, 1)) {
|
if(!flipper_format_read_uint32(file, "Usb_Pid", &cfg->usb.pid, 1)) {
|
||||||
cfg->usb_cfg.pid = 0;
|
cfg->usb.pid = 0;
|
||||||
}
|
}
|
||||||
furi_string_free(tmp_str);
|
furi_string_free(tmp_str);
|
||||||
flipper_format_file_close(file);
|
flipper_format_file_close(file);
|
||||||
@@ -96,12 +93,12 @@ static void bad_kb_save_settings(BadKbApp* app) {
|
|||||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||||
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
|
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
|
||||||
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
|
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
|
||||||
flipper_format_write_string_cstr(file, "Bt_Name", cfg->bt_name);
|
flipper_format_write_string_cstr(file, "Bt_Name", cfg->ble.name);
|
||||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->bt_mac, BAD_KB_MAC_LEN);
|
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac));
|
||||||
flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb_cfg.manuf);
|
flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb.manuf);
|
||||||
flipper_format_write_string_cstr(file, "Usb_Product", cfg->usb_cfg.product);
|
flipper_format_write_string_cstr(file, "Usb_Product", cfg->usb.product);
|
||||||
flipper_format_write_uint32(file, "Usb_Vid", &cfg->usb_cfg.vid, 1);
|
flipper_format_write_uint32(file, "Usb_Vid", &cfg->usb.vid, 1);
|
||||||
flipper_format_write_uint32(file, "Usb_Pid", &cfg->usb_cfg.pid, 1);
|
flipper_format_write_uint32(file, "Usb_Pid", &cfg->usb.pid, 1);
|
||||||
flipper_format_file_close(file);
|
flipper_format_file_close(file);
|
||||||
}
|
}
|
||||||
flipper_format_free(file);
|
flipper_format_free(file);
|
||||||
@@ -119,6 +116,165 @@ void bad_kb_app_show_loading_popup(BadKbApp* app, bool show) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t bad_kb_conn_apply(BadKbApp* app) {
|
||||||
|
if(app->is_bt) {
|
||||||
|
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
||||||
|
bt_disconnect(app->bt);
|
||||||
|
furi_delay_ms(200);
|
||||||
|
bt_keys_storage_set_storage_path(app->bt, BAD_KB_KEYS_PATH);
|
||||||
|
|
||||||
|
// Setup new config
|
||||||
|
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||||
|
memcpy(&app->cur_ble_cfg, &cfg->ble, sizeof(cfg->ble));
|
||||||
|
app->cur_ble_cfg.bonding = app->bt_remember;
|
||||||
|
if(app->bt_remember) {
|
||||||
|
app->cur_ble_cfg.pairing = GapPairingPinCodeVerifyYesNo;
|
||||||
|
} else {
|
||||||
|
app->cur_ble_cfg.pairing = GapPairingNone;
|
||||||
|
memcpy(app->cur_ble_cfg.mac, BAD_KB_BOUND_MAC, sizeof(BAD_KB_BOUND_MAC));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set profile
|
||||||
|
app->ble_hid = bt_profile_start(app->bt, ble_profile_hid, &app->cur_ble_cfg);
|
||||||
|
furi_check(app->ble_hid);
|
||||||
|
|
||||||
|
// Advertise even if BT is off in settings
|
||||||
|
furi_hal_bt_start_advertising();
|
||||||
|
|
||||||
|
app->conn_mode = BadKbConnModeBt;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Unlock RPC connections
|
||||||
|
furi_hal_usb_unlock();
|
||||||
|
|
||||||
|
// Context will apply with set_config only if pointer address is different, so we use a copy
|
||||||
|
FuriHalUsbHidConfig* cur_usb_cfg = malloc(sizeof(FuriHalUsbHidConfig));
|
||||||
|
|
||||||
|
// Setup new config
|
||||||
|
BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config;
|
||||||
|
memcpy(cur_usb_cfg, &cfg->usb, sizeof(cfg->usb));
|
||||||
|
|
||||||
|
// Set profile
|
||||||
|
furi_check(furi_hal_usb_set_config(&usb_hid, cur_usb_cfg));
|
||||||
|
if(app->cur_usb_cfg) free(app->cur_usb_cfg);
|
||||||
|
app->cur_usb_cfg = cur_usb_cfg;
|
||||||
|
|
||||||
|
app->conn_mode = BadKbConnModeUsb;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bad_kb_conn_reset(BadKbApp* app) {
|
||||||
|
if(app->conn_mode == BadKbConnModeBt) {
|
||||||
|
bt_disconnect(app->bt);
|
||||||
|
furi_delay_ms(200);
|
||||||
|
bt_keys_storage_set_default_path(app->bt);
|
||||||
|
furi_check(bt_profile_restore_default(app->bt));
|
||||||
|
} else if(app->conn_mode == BadKbConnModeUsb) {
|
||||||
|
// TODO: maybe also restore USB context?
|
||||||
|
furi_check(furi_hal_usb_set_config(app->prev_usb_mode, NULL));
|
||||||
|
}
|
||||||
|
|
||||||
|
app->conn_mode = BadKbConnModeNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bad_kb_config_adjust(BadKbConfig* cfg) {
|
||||||
|
// Avoid empty name
|
||||||
|
if(cfg->ble.name[0] == '\0') {
|
||||||
|
snprintf(
|
||||||
|
cfg->ble.name, sizeof(cfg->ble.name), "Control %s", furi_hal_version_get_name_ptr());
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t* normal_mac = furi_hal_version_get_ble_mac();
|
||||||
|
uint8_t empty_mac[sizeof(cfg->ble.mac)] = {0};
|
||||||
|
uint8_t default_mac[sizeof(cfg->ble.mac)] = {0x6c, 0x7a, 0xd8, 0xac, 0x57, 0x72}; //furi_hal_bt
|
||||||
|
if(memcmp(cfg->ble.mac, empty_mac, sizeof(cfg->ble.mac)) == 0 ||
|
||||||
|
memcmp(cfg->ble.mac, normal_mac, sizeof(cfg->ble.mac)) == 0 ||
|
||||||
|
memcmp(cfg->ble.mac, default_mac, sizeof(cfg->ble.mac)) == 0) {
|
||||||
|
memcpy(cfg->ble.mac, normal_mac, sizeof(cfg->ble.mac));
|
||||||
|
cfg->ble.mac[2]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use defaults if vid or pid are unset
|
||||||
|
if(cfg->usb.vid == 0) cfg->usb.vid = HID_VID_DEFAULT;
|
||||||
|
if(cfg->usb.pid == 0) cfg->usb.pid = HID_PID_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bad_kb_config_refresh(BadKbApp* app) {
|
||||||
|
bt_set_status_changed_callback(app->bt, NULL, NULL);
|
||||||
|
furi_hal_hid_set_state_callback(NULL, NULL);
|
||||||
|
if(app->bad_kb_script) {
|
||||||
|
furi_thread_flags_set(furi_thread_get_id(app->bad_kb_script->thread), WorkerEvtDisconnect);
|
||||||
|
}
|
||||||
|
if(app->conn_init_thread) {
|
||||||
|
furi_thread_join(app->conn_init_thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool apply = false;
|
||||||
|
if(app->is_bt) {
|
||||||
|
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
||||||
|
bad_kb_config_adjust(cfg);
|
||||||
|
|
||||||
|
if(app->conn_mode != BadKbConnModeBt) {
|
||||||
|
apply = true;
|
||||||
|
bad_kb_conn_reset(app);
|
||||||
|
} else {
|
||||||
|
BleProfileHidParams* cur = &app->cur_ble_cfg;
|
||||||
|
apply = apply || cfg->ble.bonding != app->bt_remember;
|
||||||
|
apply = apply || strncmp(cfg->ble.name, cur->name, sizeof(cfg->ble.name));
|
||||||
|
apply = apply || memcmp(cfg->ble.mac, cur->mac, sizeof(cfg->ble.mac));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config;
|
||||||
|
bad_kb_config_adjust(cfg);
|
||||||
|
|
||||||
|
if(app->conn_mode != BadKbConnModeUsb) {
|
||||||
|
apply = true;
|
||||||
|
bad_kb_conn_reset(app);
|
||||||
|
} else {
|
||||||
|
FuriHalUsbHidConfig* cur = app->cur_usb_cfg;
|
||||||
|
apply = apply || cfg->usb.vid != cur->vid;
|
||||||
|
apply = apply || cfg->usb.pid != cur->pid;
|
||||||
|
apply = apply || strncmp(cfg->usb.manuf, cur->manuf, sizeof(cur->manuf));
|
||||||
|
apply = apply || strncmp(cfg->usb.product, cur->product, sizeof(cur->product));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(apply) {
|
||||||
|
bad_kb_conn_apply(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(app->bad_kb_script) {
|
||||||
|
BadKbScript* script = app->bad_kb_script;
|
||||||
|
script->st.is_bt = app->is_bt;
|
||||||
|
script->bt = app->is_bt ? app->bt : NULL;
|
||||||
|
bool connected;
|
||||||
|
if(app->is_bt) {
|
||||||
|
bt_set_status_changed_callback(app->bt, bad_kb_bt_hid_state_callback, script);
|
||||||
|
connected = furi_hal_bt_is_connected();
|
||||||
|
} else {
|
||||||
|
furi_hal_hid_set_state_callback(bad_kb_usb_hid_state_callback, script);
|
||||||
|
connected = furi_hal_hid_is_connected();
|
||||||
|
}
|
||||||
|
if(connected) {
|
||||||
|
furi_thread_flags_set(furi_thread_get_id(script->thread), WorkerEvtConnect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload config page
|
||||||
|
scene_manager_next_scene(app->scene_manager, BadKbSceneConfig);
|
||||||
|
scene_manager_previous_scene(app->scene_manager);
|
||||||
|
|
||||||
|
// Update settings
|
||||||
|
if(xtreme_settings.bad_bt != app->is_bt ||
|
||||||
|
xtreme_settings.bad_bt_remember != app->bt_remember) {
|
||||||
|
xtreme_settings.bad_bt = app->is_bt;
|
||||||
|
xtreme_settings.bad_bt_remember = app->bt_remember;
|
||||||
|
xtreme_settings_save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BadKbApp* bad_kb_app_alloc(char* arg) {
|
BadKbApp* bad_kb_app_alloc(char* arg) {
|
||||||
BadKbApp* app = malloc(sizeof(BadKbApp));
|
BadKbApp* app = malloc(sizeof(BadKbApp));
|
||||||
|
|
||||||
@@ -158,13 +314,9 @@ BadKbApp* bad_kb_app_alloc(char* arg) {
|
|||||||
|
|
||||||
// Save prev config
|
// Save prev config
|
||||||
app->prev_usb_mode = furi_hal_usb_get_config();
|
app->prev_usb_mode = furi_hal_usb_get_config();
|
||||||
FuriHalBtProfile kbd = FuriHalBtProfileHidKeyboard;
|
|
||||||
app->prev_bt_mode = furi_hal_bt_get_profile_pairing_method(kbd);
|
|
||||||
memcpy(app->prev_bt_mac, furi_hal_bt_get_profile_mac_addr(kbd), BAD_KB_MAC_LEN);
|
|
||||||
strlcpy(app->prev_bt_name, furi_hal_bt_get_profile_adv_name(kbd), BAD_KB_NAME_LEN);
|
|
||||||
|
|
||||||
// Adjust BT remember MAC to be serial MAC +2
|
// Adjust BT remember MAC to be serial MAC +2
|
||||||
memcpy(BAD_KB_BOUND_MAC, furi_hal_version_get_ble_mac(), BAD_KB_MAC_LEN);
|
memcpy(BAD_KB_BOUND_MAC, furi_hal_version_get_ble_mac(), sizeof(BAD_KB_BOUND_MAC));
|
||||||
BAD_KB_BOUND_MAC[2] += 2;
|
BAD_KB_BOUND_MAC[2] += 2;
|
||||||
|
|
||||||
// Custom Widget
|
// Custom Widget
|
||||||
@@ -256,7 +408,7 @@ void bad_kb_app_free(BadKbApp* app) {
|
|||||||
app->conn_init_thread = NULL;
|
app->conn_init_thread = NULL;
|
||||||
}
|
}
|
||||||
bad_kb_conn_reset(app);
|
bad_kb_conn_reset(app);
|
||||||
if(app->hid_cfg) free(app->hid_cfg);
|
if(app->cur_usb_cfg) free(app->cur_usb_cfg);
|
||||||
|
|
||||||
// Close records
|
// Close records
|
||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
@@ -272,8 +424,8 @@ void bad_kb_app_free(BadKbApp* app) {
|
|||||||
free(app);
|
free(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t bad_kb_app(char* p) {
|
int32_t bad_kb_app(void* p) {
|
||||||
BadKbApp* bad_kb_app = bad_kb_app_alloc(p);
|
BadKbApp* bad_kb_app = bad_kb_app_alloc((char*)p);
|
||||||
|
|
||||||
view_dispatcher_run(bad_kb_app->view_dispatcher);
|
view_dispatcher_run(bad_kb_app->view_dispatcher);
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "scenes/bad_kb_scene.h"
|
#ifdef __cplusplus
|
||||||
#include "helpers/ducky_script.h"
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gui/gui.h>
|
typedef struct BadKbApp BadKbApp;
|
||||||
#include <assets_icons.h>
|
|
||||||
#include <gui/scene_manager.h>
|
|
||||||
#include <dialogs/dialogs.h>
|
|
||||||
#include <notification/notification_messages.h>
|
|
||||||
|
|
||||||
#define BAD_KB_APP_SCRIPT_EXTENSION ".txt"
|
#ifdef __cplusplus
|
||||||
#define BAD_KB_APP_LAYOUT_EXTENSION ".kl"
|
}
|
||||||
|
#endif
|
||||||
typedef enum BadKbCustomEvent {
|
|
||||||
BadKbAppCustomEventTextInputDone,
|
|
||||||
BadKbAppCustomEventByteInputDone,
|
|
||||||
BadKbCustomEventErrorBack
|
|
||||||
} BadKbCustomEvent;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BadKbAppViewWidget,
|
|
||||||
BadKbAppViewWork,
|
|
||||||
BadKbAppViewVarItemList,
|
|
||||||
BadKbAppViewByteInput,
|
|
||||||
BadKbAppViewTextInput,
|
|
||||||
BadKbAppViewLoading,
|
|
||||||
} BadKbAppView;
|
|
||||||
|
|
||||||
void bad_kb_app_show_loading_popup(BadKbApp* app, bool show);
|
|
||||||
|
|||||||
111
applications/main/bad_kb/bad_kb_app_i.h
Normal file
111
applications/main/bad_kb/bad_kb_app_i.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "bad_kb_app.h"
|
||||||
|
#include "scenes/bad_kb_scene.h"
|
||||||
|
#include "helpers/ducky_script.h"
|
||||||
|
#include "helpers/ble_hid.h"
|
||||||
|
#include "bad_kb_paths.h"
|
||||||
|
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <assets_icons.h>
|
||||||
|
#include <gui/view_dispatcher.h>
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
#include <gui/modules/submenu.h>
|
||||||
|
#include <dialogs/dialogs.h>
|
||||||
|
#include <notification/notification_messages.h>
|
||||||
|
#include <gui/modules/variable_item_list.h>
|
||||||
|
#include <gui/modules/text_input.h>
|
||||||
|
#include <gui/modules/byte_input.h>
|
||||||
|
#include <gui/modules/loading.h>
|
||||||
|
#include <gui/modules/widget.h>
|
||||||
|
#include "views/bad_kb_view.h"
|
||||||
|
#include <furi_hal_usb.h>
|
||||||
|
|
||||||
|
#define BAD_KB_APP_SCRIPT_EXTENSION ".txt"
|
||||||
|
#define BAD_KB_APP_LAYOUT_EXTENSION ".kl"
|
||||||
|
|
||||||
|
extern uint8_t BAD_KB_BOUND_MAC[GAP_MAC_ADDR_SIZE]; // For remember mode
|
||||||
|
|
||||||
|
typedef enum BadKbCustomEvent {
|
||||||
|
BadKbAppCustomEventTextInputDone,
|
||||||
|
BadKbAppCustomEventByteInputDone,
|
||||||
|
BadKbCustomEventErrorBack
|
||||||
|
} BadKbCustomEvent;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BadKbAppErrorNoFiles,
|
||||||
|
} BadKbAppError;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BleProfileHidParams ble;
|
||||||
|
FuriHalUsbHidConfig usb;
|
||||||
|
} BadKbConfig;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BadKbConnModeNone,
|
||||||
|
BadKbConnModeUsb,
|
||||||
|
BadKbConnModeBt,
|
||||||
|
} BadKbConnMode;
|
||||||
|
|
||||||
|
struct BadKbApp {
|
||||||
|
Gui* gui;
|
||||||
|
ViewDispatcher* view_dispatcher;
|
||||||
|
SceneManager* scene_manager;
|
||||||
|
NotificationApp* notifications;
|
||||||
|
DialogsApp* dialogs;
|
||||||
|
Widget* widget;
|
||||||
|
VariableItemList* var_item_list;
|
||||||
|
TextInput* text_input;
|
||||||
|
ByteInput* byte_input;
|
||||||
|
Loading* loading;
|
||||||
|
|
||||||
|
char bt_name_buf[FURI_HAL_BT_ADV_NAME_LENGTH];
|
||||||
|
uint8_t bt_mac_buf[GAP_MAC_ADDR_SIZE];
|
||||||
|
char usb_name_buf[HID_MANUF_PRODUCT_NAME_LEN];
|
||||||
|
uint16_t usb_vidpid_buf[2];
|
||||||
|
|
||||||
|
BadKbAppError error;
|
||||||
|
FuriString* file_path;
|
||||||
|
FuriString* keyboard_layout;
|
||||||
|
BadKb* bad_kb_view;
|
||||||
|
BadKbScript* bad_kb_script;
|
||||||
|
|
||||||
|
Bt* bt;
|
||||||
|
bool is_bt;
|
||||||
|
bool bt_remember;
|
||||||
|
BadKbConfig config; // User options
|
||||||
|
BadKbConfig id_config; // ID and BT_ID values
|
||||||
|
|
||||||
|
bool set_bt_id;
|
||||||
|
bool set_usb_id;
|
||||||
|
bool has_bt_id;
|
||||||
|
bool has_usb_id;
|
||||||
|
|
||||||
|
FuriHalBleProfileBase* ble_hid;
|
||||||
|
FuriHalUsbInterface* prev_usb_mode;
|
||||||
|
|
||||||
|
BleProfileHidParams cur_ble_cfg;
|
||||||
|
FuriHalUsbHidConfig* cur_usb_cfg;
|
||||||
|
|
||||||
|
BadKbConnMode conn_mode;
|
||||||
|
FuriThread* conn_init_thread;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BadKbAppViewWidget,
|
||||||
|
BadKbAppViewWork,
|
||||||
|
BadKbAppViewVarItemList,
|
||||||
|
BadKbAppViewByteInput,
|
||||||
|
BadKbAppViewTextInput,
|
||||||
|
BadKbAppViewLoading,
|
||||||
|
} BadKbAppView;
|
||||||
|
|
||||||
|
void bad_kb_app_show_loading_popup(BadKbApp* app, bool show);
|
||||||
|
|
||||||
|
int32_t bad_kb_conn_apply(BadKbApp* app);
|
||||||
|
|
||||||
|
void bad_kb_conn_reset(BadKbApp* app);
|
||||||
|
|
||||||
|
void bad_kb_config_refresh(BadKbApp* app);
|
||||||
|
|
||||||
|
void bad_kb_config_adjust(BadKbConfig* cfg);
|
||||||
416
applications/main/bad_kb/helpers/ble_hid.c
Normal file
416
applications/main/bad_kb/helpers/ble_hid.c
Normal file
@@ -0,0 +1,416 @@
|
|||||||
|
#include "ble_hid.h"
|
||||||
|
|
||||||
|
#include <furi_hal_usb_hid.h>
|
||||||
|
#include <services/dev_info_service.h>
|
||||||
|
#include <services/battery_service.h>
|
||||||
|
#include "ble_hid_svc.h"
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <usb_hid.h>
|
||||||
|
#include <ble/ble.h>
|
||||||
|
|
||||||
|
#define HID_INFO_BASE_USB_SPECIFICATION (0x0101)
|
||||||
|
#define HID_INFO_COUNTRY_CODE (0x00)
|
||||||
|
#define BLE_PROFILE_HID_INFO_FLAG_REMOTE_WAKE_MSK (0x01)
|
||||||
|
#define BLE_PROFILE_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK (0x02)
|
||||||
|
|
||||||
|
#define BLE_PROFILE_HID_KB_MAX_KEYS (6)
|
||||||
|
#define BLE_PROFILE_CONSUMER_MAX_KEYS (1)
|
||||||
|
|
||||||
|
// Report ids cant be 0
|
||||||
|
enum HidReportId {
|
||||||
|
ReportIdKeyboard = 1,
|
||||||
|
ReportIdMouse = 2,
|
||||||
|
ReportIdConsumer = 3,
|
||||||
|
};
|
||||||
|
// Report numbers corresponded to the report id with an offset of 1
|
||||||
|
enum HidInputNumber {
|
||||||
|
ReportNumberKeyboard = 0,
|
||||||
|
ReportNumberMouse = 1,
|
||||||
|
ReportNumberConsumer = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t mods;
|
||||||
|
uint8_t reserved;
|
||||||
|
uint8_t key[BLE_PROFILE_HID_KB_MAX_KEYS];
|
||||||
|
} FURI_PACKED FuriHalBtHidKbReport;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t btn;
|
||||||
|
int8_t x;
|
||||||
|
int8_t y;
|
||||||
|
int8_t wheel;
|
||||||
|
} FURI_PACKED FuriHalBtHidMouseReport;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t key[BLE_PROFILE_CONSUMER_MAX_KEYS];
|
||||||
|
} FURI_PACKED FuriHalBtHidConsumerReport;
|
||||||
|
|
||||||
|
// keyboard+mouse+consumer hid report
|
||||||
|
static const uint8_t ble_profile_hid_report_map_data[] = {
|
||||||
|
// Keyboard Report
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||||
|
HID_USAGE(HID_DESKTOP_KEYBOARD),
|
||||||
|
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||||
|
HID_REPORT_ID(ReportIdKeyboard),
|
||||||
|
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||||
|
HID_USAGE_MINIMUM(HID_KEYBOARD_L_CTRL),
|
||||||
|
HID_USAGE_MAXIMUM(HID_KEYBOARD_R_GUI),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_LOGICAL_MAXIMUM(1),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_REPORT_COUNT(8),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_REPORT_COUNT(1),
|
||||||
|
HID_REPORT_SIZE(8),
|
||||||
|
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_LED),
|
||||||
|
HID_REPORT_COUNT(8),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_USAGE_MINIMUM(1),
|
||||||
|
HID_USAGE_MAXIMUM(8),
|
||||||
|
HID_OUTPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_REPORT_COUNT(BLE_PROFILE_HID_KB_MAX_KEYS),
|
||||||
|
HID_REPORT_SIZE(8),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_LOGICAL_MAXIMUM(101),
|
||||||
|
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||||
|
HID_USAGE_MINIMUM(0),
|
||||||
|
HID_USAGE_MAXIMUM(101),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
// Mouse Report
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||||
|
HID_USAGE(HID_DESKTOP_MOUSE),
|
||||||
|
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||||
|
HID_USAGE(HID_DESKTOP_POINTER),
|
||||||
|
HID_COLLECTION(HID_PHYSICAL_COLLECTION),
|
||||||
|
HID_REPORT_ID(ReportIdMouse),
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_BUTTON),
|
||||||
|
HID_USAGE_MINIMUM(1),
|
||||||
|
HID_USAGE_MAXIMUM(3),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_LOGICAL_MAXIMUM(1),
|
||||||
|
HID_REPORT_COUNT(3),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_REPORT_COUNT(5),
|
||||||
|
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||||
|
HID_USAGE(HID_DESKTOP_X),
|
||||||
|
HID_USAGE(HID_DESKTOP_Y),
|
||||||
|
HID_USAGE(HID_DESKTOP_WHEEL),
|
||||||
|
HID_LOGICAL_MINIMUM(-127),
|
||||||
|
HID_LOGICAL_MAXIMUM(127),
|
||||||
|
HID_REPORT_SIZE(8),
|
||||||
|
HID_REPORT_COUNT(3),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
// Consumer Report
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_CONSUMER),
|
||||||
|
HID_USAGE(HID_CONSUMER_CONTROL),
|
||||||
|
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||||
|
HID_REPORT_ID(ReportIdConsumer),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_RI_LOGICAL_MAXIMUM(16, 0x3FF),
|
||||||
|
HID_USAGE_MINIMUM(0),
|
||||||
|
HID_RI_USAGE_MAXIMUM(16, 0x3FF),
|
||||||
|
HID_REPORT_COUNT(BLE_PROFILE_CONSUMER_MAX_KEYS),
|
||||||
|
HID_REPORT_SIZE(16),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriHalBleProfileBase base;
|
||||||
|
|
||||||
|
FuriHalBtHidKbReport* kb_report;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report;
|
||||||
|
|
||||||
|
BleServiceBattery* battery_svc;
|
||||||
|
BleServiceDevInfo* dev_info_svc;
|
||||||
|
BleServiceHid* hid_svc;
|
||||||
|
} BleProfileHid;
|
||||||
|
_Static_assert(offsetof(BleProfileHid, base) == 0, "Wrong layout");
|
||||||
|
|
||||||
|
static FuriHalBleProfileBase* ble_profile_hid_start(FuriHalBleProfileParams profile_params) {
|
||||||
|
UNUSED(profile_params);
|
||||||
|
|
||||||
|
BleProfileHid* profile = malloc(sizeof(BleProfileHid));
|
||||||
|
|
||||||
|
profile->base.config = ble_profile_hid;
|
||||||
|
|
||||||
|
profile->battery_svc = ble_svc_battery_start(true);
|
||||||
|
profile->dev_info_svc = ble_svc_dev_info_start();
|
||||||
|
profile->hid_svc = ble_svc_hid_start();
|
||||||
|
|
||||||
|
// Configure HID Keyboard
|
||||||
|
profile->kb_report = malloc(sizeof(FuriHalBtHidKbReport));
|
||||||
|
profile->mouse_report = malloc(sizeof(FuriHalBtHidMouseReport));
|
||||||
|
profile->consumer_report = malloc(sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
|
||||||
|
// Configure Report Map characteristic
|
||||||
|
ble_svc_hid_update_report_map(
|
||||||
|
profile->hid_svc,
|
||||||
|
ble_profile_hid_report_map_data,
|
||||||
|
sizeof(ble_profile_hid_report_map_data));
|
||||||
|
// Configure HID Information characteristic
|
||||||
|
uint8_t hid_info_val[4] = {
|
||||||
|
HID_INFO_BASE_USB_SPECIFICATION & 0x00ff,
|
||||||
|
(HID_INFO_BASE_USB_SPECIFICATION & 0xff00) >> 8,
|
||||||
|
HID_INFO_COUNTRY_CODE,
|
||||||
|
BLE_PROFILE_HID_INFO_FLAG_REMOTE_WAKE_MSK |
|
||||||
|
BLE_PROFILE_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK,
|
||||||
|
};
|
||||||
|
ble_svc_hid_update_info(profile->hid_svc, hid_info_val);
|
||||||
|
|
||||||
|
return &profile->base;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_profile_hid_stop(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
ble_svc_battery_stop(hid_profile->battery_svc);
|
||||||
|
ble_svc_dev_info_stop(hid_profile->dev_info_svc);
|
||||||
|
ble_svc_hid_stop(hid_profile->hid_svc);
|
||||||
|
|
||||||
|
free(hid_profile->kb_report);
|
||||||
|
free(hid_profile->mouse_report);
|
||||||
|
free(hid_profile->consumer_report);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_kb_press(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||||
|
if(kb_report->key[i] == 0) {
|
||||||
|
kb_report->key[i] = button & 0xFF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kb_report->mods |= (button >> 8);
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberKeyboard,
|
||||||
|
(uint8_t*)kb_report,
|
||||||
|
sizeof(FuriHalBtHidKbReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_kb_release(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
|
||||||
|
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||||
|
if(kb_report->key[i] == (button & 0xFF)) {
|
||||||
|
kb_report->key[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kb_report->mods &= ~(button >> 8);
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberKeyboard,
|
||||||
|
(uint8_t*)kb_report,
|
||||||
|
sizeof(FuriHalBtHidKbReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_kb_release_all(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||||
|
kb_report->key[i] = 0;
|
||||||
|
}
|
||||||
|
kb_report->mods = 0;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberKeyboard,
|
||||||
|
(uint8_t*)kb_report,
|
||||||
|
sizeof(FuriHalBtHidKbReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_consumer_key_press(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||||
|
if(consumer_report->key[i] == 0) {
|
||||||
|
consumer_report->key[i] = button;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberConsumer,
|
||||||
|
(uint8_t*)consumer_report,
|
||||||
|
sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_consumer_key_release(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||||
|
if(consumer_report->key[i] == button) {
|
||||||
|
consumer_report->key[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberConsumer,
|
||||||
|
(uint8_t*)consumer_report,
|
||||||
|
sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_consumer_key_release_all(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||||
|
consumer_report->key[i] = 0;
|
||||||
|
}
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberConsumer,
|
||||||
|
(uint8_t*)consumer_report,
|
||||||
|
sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_move(FuriHalBleProfileBase* profile, int8_t dx, int8_t dy) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->x = dx;
|
||||||
|
mouse_report->y = dy;
|
||||||
|
bool state = ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
mouse_report->x = 0;
|
||||||
|
mouse_report->y = 0;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_press(FuriHalBleProfileBase* profile, uint8_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->btn |= button;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_release(FuriHalBleProfileBase* profile, uint8_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->btn &= ~button;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->btn = 0;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->wheel = delta;
|
||||||
|
bool state = ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
mouse_report->wheel = 0;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GapConfig template_config = {
|
||||||
|
.adv_service_uuid = HUMAN_INTERFACE_DEVICE_SERVICE_UUID,
|
||||||
|
.appearance_char = GAP_APPEARANCE_KEYBOARD,
|
||||||
|
.bonding_mode = true,
|
||||||
|
.pairing_method = GapPairingPinCodeVerifyYesNo,
|
||||||
|
.conn_param =
|
||||||
|
{
|
||||||
|
.conn_int_min = 0x18, // 30 ms
|
||||||
|
.conn_int_max = 0x24, // 45 ms
|
||||||
|
.slave_latency = 0,
|
||||||
|
.supervisor_timeout = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void ble_profile_hid_get_config(GapConfig* config, FuriHalBleProfileParams profile_params) {
|
||||||
|
BleProfileHidParams* hid_profile_params = profile_params;
|
||||||
|
|
||||||
|
furi_check(config);
|
||||||
|
memcpy(config, &template_config, sizeof(GapConfig));
|
||||||
|
|
||||||
|
// Set mac address
|
||||||
|
memcpy(config->mac_address, hid_profile_params->mac, sizeof(config->mac_address));
|
||||||
|
|
||||||
|
// Set advertise name
|
||||||
|
config->adv_name[0] = furi_hal_version_get_ble_local_device_name_ptr()[0];
|
||||||
|
strlcpy(config->adv_name + 1, hid_profile_params->name, sizeof(config->adv_name) - 1);
|
||||||
|
|
||||||
|
// Set bonding mode
|
||||||
|
config->bonding_mode = hid_profile_params->bonding;
|
||||||
|
|
||||||
|
// Set pairing method
|
||||||
|
config->pairing_method = hid_profile_params->pairing;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const FuriHalBleProfileTemplate profile_callbacks = {
|
||||||
|
.start = ble_profile_hid_start,
|
||||||
|
.stop = ble_profile_hid_stop,
|
||||||
|
.get_gap_config = ble_profile_hid_get_config,
|
||||||
|
};
|
||||||
|
|
||||||
|
const FuriHalBleProfileTemplate* ble_profile_hid = &profile_callbacks;
|
||||||
107
applications/main/bad_kb/helpers/ble_hid.h
Normal file
107
applications/main/bad_kb/helpers/ble_hid.h
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi_ble/profile_interface.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional arguments to pass along with profile template as
|
||||||
|
* FuriHalBleProfileParams for tuning profile behavior
|
||||||
|
**/
|
||||||
|
typedef struct {
|
||||||
|
char name[FURI_HAL_BT_ADV_NAME_LENGTH]; /**< Full device name */
|
||||||
|
uint8_t mac[GAP_MAC_ADDR_SIZE]; /**< Full device address */
|
||||||
|
bool bonding; /**< Save paired devices */
|
||||||
|
GapPairing pairing; /**< Pairing security method */
|
||||||
|
} BleProfileHidParams;
|
||||||
|
|
||||||
|
/** Hid Keyboard Profile descriptor */
|
||||||
|
extern const FuriHalBleProfileTemplate* ble_profile_hid;
|
||||||
|
|
||||||
|
/** Press keyboard button
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button button code from HID specification
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_kb_press(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Release keyboard button
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button button code from HID specification
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_kb_release(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Release all keyboard buttons
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_kb_release_all(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set the following consumer key to pressed state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_consumer_key_press(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Set the following consumer key to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_consumer_key_release(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Set consumer key to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_consumer_key_release_all(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set mouse movement and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param dx x coordinate delta
|
||||||
|
* @param dy y coordinate delta
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_move(FuriHalBleProfileBase* profile, int8_t dx, int8_t dy);
|
||||||
|
|
||||||
|
/** Set mouse button to pressed state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_press(FuriHalBleProfileBase* profile, uint8_t button);
|
||||||
|
|
||||||
|
/** Set mouse button to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_release(FuriHalBleProfileBase* profile, uint8_t button);
|
||||||
|
|
||||||
|
/** Set mouse button to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set mouse wheel position and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param delta number of scroll steps
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
320
applications/main/bad_kb/helpers/ble_hid_svc.c
Normal file
320
applications/main/bad_kb/helpers/ble_hid_svc.c
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
#include "ble_hid_svc.h"
|
||||||
|
#include "app_common.h"
|
||||||
|
#include <ble/ble.h>
|
||||||
|
#include <furi_ble/event_dispatcher.h>
|
||||||
|
#include <furi_ble/gatt.h>
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define TAG "BleHid"
|
||||||
|
|
||||||
|
#define BLE_SVC_HID_REPORT_MAP_MAX_LEN (255)
|
||||||
|
#define BLE_SVC_HID_REPORT_MAX_LEN (255)
|
||||||
|
#define BLE_SVC_HID_REPORT_REF_LEN (2)
|
||||||
|
#define BLE_SVC_HID_INFO_LEN (4)
|
||||||
|
#define BLE_SVC_HID_CONTROL_POINT_LEN (1)
|
||||||
|
|
||||||
|
#define BLE_SVC_HID_INPUT_REPORT_COUNT (3)
|
||||||
|
#define BLE_SVC_HID_OUTPUT_REPORT_COUNT (0)
|
||||||
|
#define BLE_SVC_HID_FEATURE_REPORT_COUNT (0)
|
||||||
|
#define BLE_SVC_HID_REPORT_COUNT \
|
||||||
|
(BLE_SVC_HID_INPUT_REPORT_COUNT + BLE_SVC_HID_OUTPUT_REPORT_COUNT + \
|
||||||
|
BLE_SVC_HID_FEATURE_REPORT_COUNT)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HidSvcGattCharacteristicProtocolMode = 0,
|
||||||
|
HidSvcGattCharacteristicReportMap,
|
||||||
|
HidSvcGattCharacteristicInfo,
|
||||||
|
HidSvcGattCharacteristicCtrlPoint,
|
||||||
|
HidSvcGattCharacteristicCount,
|
||||||
|
} HidSvcGattCharacteristicId;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_idx;
|
||||||
|
uint8_t report_type;
|
||||||
|
} HidSvcReportId;
|
||||||
|
|
||||||
|
static_assert(sizeof(HidSvcReportId) == sizeof(uint16_t), "HidSvcReportId must be 2 bytes");
|
||||||
|
|
||||||
|
static const Service_UUID_t ble_svc_hid_uuid = {
|
||||||
|
.Service_UUID_16 = HUMAN_INTERFACE_DEVICE_SERVICE_UUID,
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool ble_svc_hid_char_desc_data_callback(
|
||||||
|
const void* context,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint16_t* data_len) {
|
||||||
|
const HidSvcReportId* report_id = context;
|
||||||
|
*data_len = sizeof(HidSvcReportId);
|
||||||
|
if(data) {
|
||||||
|
*data = (const uint8_t*)report_id;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const void* data_ptr;
|
||||||
|
uint16_t data_len;
|
||||||
|
} HidSvcDataWrapper;
|
||||||
|
|
||||||
|
static bool ble_svc_hid_report_data_callback(
|
||||||
|
const void* context,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint16_t* data_len) {
|
||||||
|
const HidSvcDataWrapper* report_data = context;
|
||||||
|
if(data) {
|
||||||
|
*data = report_data->data_ptr;
|
||||||
|
*data_len = report_data->data_len;
|
||||||
|
} else {
|
||||||
|
*data_len = BLE_SVC_HID_REPORT_MAP_MAX_LEN;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const BleGattCharacteristicParams ble_svc_hid_chars[HidSvcGattCharacteristicCount] = {
|
||||||
|
[HidSvcGattCharacteristicProtocolMode] =
|
||||||
|
{.name = "Protocol Mode",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = 1,
|
||||||
|
.uuid.Char_UUID_16 = PROTOCOL_MODE_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RESP,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
[HidSvcGattCharacteristicReportMap] =
|
||||||
|
{.name = "Report Map",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
||||||
|
.data.callback.fn = ble_svc_hid_report_data_callback,
|
||||||
|
.data.callback.context = NULL,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_MAP_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_VARIABLE},
|
||||||
|
[HidSvcGattCharacteristicInfo] =
|
||||||
|
{.name = "HID Information",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = BLE_SVC_HID_INFO_LEN,
|
||||||
|
.data.fixed.ptr = NULL,
|
||||||
|
.uuid.Char_UUID_16 = HID_INFORMATION_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
[HidSvcGattCharacteristicCtrlPoint] =
|
||||||
|
{.name = "HID Control Point",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = BLE_SVC_HID_CONTROL_POINT_LEN,
|
||||||
|
.uuid.Char_UUID_16 = HID_CONTROL_POINT_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_WRITE_WITHOUT_RESP,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const BleGattCharacteristicDescriptorParams ble_svc_hid_char_descr_template = {
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_REFERENCE_DESCRIPTOR_UUID,
|
||||||
|
.max_length = BLE_SVC_HID_REPORT_REF_LEN,
|
||||||
|
.data_callback.fn = ble_svc_hid_char_desc_data_callback,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.access_permissions = ATTR_ACCESS_READ_WRITE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const BleGattCharacteristicParams ble_svc_hid_report_template = {
|
||||||
|
.name = "Report",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
||||||
|
.data.callback.fn = ble_svc_hid_report_data_callback,
|
||||||
|
.data.callback.context = NULL,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_VARIABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BleServiceHid {
|
||||||
|
uint16_t svc_handle;
|
||||||
|
BleGattCharacteristicInstance chars[HidSvcGattCharacteristicCount];
|
||||||
|
BleGattCharacteristicInstance input_report_chars[BLE_SVC_HID_INPUT_REPORT_COUNT];
|
||||||
|
BleGattCharacteristicInstance output_report_chars[BLE_SVC_HID_OUTPUT_REPORT_COUNT];
|
||||||
|
BleGattCharacteristicInstance feature_report_chars[BLE_SVC_HID_FEATURE_REPORT_COUNT];
|
||||||
|
GapSvcEventHandler* event_handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BleEventAckStatus ble_svc_hid_event_handler(void* event, void* context) {
|
||||||
|
UNUSED(context);
|
||||||
|
|
||||||
|
BleEventAckStatus ret = BleEventNotAck;
|
||||||
|
hci_event_pckt* event_pckt = (hci_event_pckt*)(((hci_uart_pckt*)event)->data);
|
||||||
|
evt_blecore_aci* blecore_evt = (evt_blecore_aci*)event_pckt->data;
|
||||||
|
// aci_gatt_attribute_modified_event_rp0* attribute_modified;
|
||||||
|
if(event_pckt->evt == HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE) {
|
||||||
|
if(blecore_evt->ecode == ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE) {
|
||||||
|
// Process modification events
|
||||||
|
ret = BleEventAckFlowEnable;
|
||||||
|
} else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) {
|
||||||
|
// Process notification confirmation
|
||||||
|
ret = BleEventAckFlowEnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
BleServiceHid* ble_svc_hid_start() {
|
||||||
|
BleServiceHid* hid_svc = malloc(sizeof(BleServiceHid));
|
||||||
|
|
||||||
|
// Register event handler
|
||||||
|
hid_svc->event_handler =
|
||||||
|
ble_event_dispatcher_register_svc_handler(ble_svc_hid_event_handler, hid_svc);
|
||||||
|
/**
|
||||||
|
* Add Human Interface Device Service
|
||||||
|
*/
|
||||||
|
if(!ble_gatt_service_add(
|
||||||
|
UUID_TYPE_16,
|
||||||
|
&ble_svc_hid_uuid,
|
||||||
|
PRIMARY_SERVICE,
|
||||||
|
2 + /* protocol mode */
|
||||||
|
(4 * BLE_SVC_HID_INPUT_REPORT_COUNT) + (3 * BLE_SVC_HID_OUTPUT_REPORT_COUNT) +
|
||||||
|
(3 * BLE_SVC_HID_FEATURE_REPORT_COUNT) + 1 + 2 + 2 +
|
||||||
|
2, /* Service + Report Map + HID Information + HID Control Point */
|
||||||
|
&hid_svc->svc_handle)) {
|
||||||
|
free(hid_svc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maintain previously defined characteristic order
|
||||||
|
ble_gatt_characteristic_init(
|
||||||
|
hid_svc->svc_handle,
|
||||||
|
&ble_svc_hid_chars[HidSvcGattCharacteristicProtocolMode],
|
||||||
|
&hid_svc->chars[HidSvcGattCharacteristicProtocolMode]);
|
||||||
|
|
||||||
|
uint8_t protocol_mode = 1;
|
||||||
|
ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle,
|
||||||
|
&hid_svc->chars[HidSvcGattCharacteristicProtocolMode],
|
||||||
|
&protocol_mode);
|
||||||
|
|
||||||
|
// reports
|
||||||
|
BleGattCharacteristicDescriptorParams ble_svc_hid_char_descr;
|
||||||
|
BleGattCharacteristicParams report_char;
|
||||||
|
HidSvcReportId report_id;
|
||||||
|
|
||||||
|
memcpy(
|
||||||
|
&ble_svc_hid_char_descr, &ble_svc_hid_char_descr_template, sizeof(ble_svc_hid_char_descr));
|
||||||
|
memcpy(&report_char, &ble_svc_hid_report_template, sizeof(report_char));
|
||||||
|
|
||||||
|
ble_svc_hid_char_descr.data_callback.context = &report_id;
|
||||||
|
report_char.descriptor_params = &ble_svc_hid_char_descr;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_type;
|
||||||
|
uint8_t report_count;
|
||||||
|
BleGattCharacteristicInstance* chars;
|
||||||
|
} HidSvcReportCharProps;
|
||||||
|
|
||||||
|
HidSvcReportCharProps hid_report_chars[] = {
|
||||||
|
{0x01, BLE_SVC_HID_INPUT_REPORT_COUNT, hid_svc->input_report_chars},
|
||||||
|
{0x02, BLE_SVC_HID_OUTPUT_REPORT_COUNT, hid_svc->output_report_chars},
|
||||||
|
{0x03, BLE_SVC_HID_FEATURE_REPORT_COUNT, hid_svc->feature_report_chars},
|
||||||
|
};
|
||||||
|
|
||||||
|
for(size_t report_type_idx = 0; report_type_idx < COUNT_OF(hid_report_chars);
|
||||||
|
report_type_idx++) {
|
||||||
|
report_id.report_type = hid_report_chars[report_type_idx].report_type;
|
||||||
|
for(size_t report_idx = 0; report_idx < hid_report_chars[report_type_idx].report_count;
|
||||||
|
report_idx++) {
|
||||||
|
report_id.report_idx = report_idx + 1;
|
||||||
|
ble_gatt_characteristic_init(
|
||||||
|
hid_svc->svc_handle,
|
||||||
|
&report_char,
|
||||||
|
&hid_report_chars[report_type_idx].chars[report_idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup remaining characteristics
|
||||||
|
for(size_t i = HidSvcGattCharacteristicReportMap; i < HidSvcGattCharacteristicCount; i++) {
|
||||||
|
ble_gatt_characteristic_init(
|
||||||
|
hid_svc->svc_handle, &ble_svc_hid_chars[i], &hid_svc->chars[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hid_svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_report_map(BleServiceHid* hid_svc, const uint8_t* data, uint16_t len) {
|
||||||
|
furi_assert(data);
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
|
||||||
|
HidSvcDataWrapper report_data = {
|
||||||
|
.data_ptr = data,
|
||||||
|
.data_len = len,
|
||||||
|
};
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicReportMap], &report_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_input_report(
|
||||||
|
BleServiceHid* hid_svc,
|
||||||
|
uint8_t input_report_num,
|
||||||
|
uint8_t* data,
|
||||||
|
uint16_t len) {
|
||||||
|
furi_assert(data);
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
furi_assert(input_report_num < BLE_SVC_HID_INPUT_REPORT_COUNT);
|
||||||
|
|
||||||
|
HidSvcDataWrapper report_data = {
|
||||||
|
.data_ptr = data,
|
||||||
|
.data_len = len,
|
||||||
|
};
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle, &hid_svc->input_report_chars[input_report_num], &report_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_info(BleServiceHid* hid_svc, uint8_t* data) {
|
||||||
|
furi_assert(data);
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicInfo], &data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_svc_hid_stop(BleServiceHid* hid_svc) {
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
ble_event_dispatcher_unregister_svc_handler(hid_svc->event_handler);
|
||||||
|
// Delete characteristics
|
||||||
|
for(size_t i = 0; i < HidSvcGattCharacteristicCount; i++) {
|
||||||
|
ble_gatt_characteristic_delete(hid_svc->svc_handle, &hid_svc->chars[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_count;
|
||||||
|
BleGattCharacteristicInstance* chars;
|
||||||
|
} HidSvcReportCharProps;
|
||||||
|
|
||||||
|
HidSvcReportCharProps hid_report_chars[] = {
|
||||||
|
{BLE_SVC_HID_INPUT_REPORT_COUNT, hid_svc->input_report_chars},
|
||||||
|
{BLE_SVC_HID_OUTPUT_REPORT_COUNT, hid_svc->output_report_chars},
|
||||||
|
{BLE_SVC_HID_FEATURE_REPORT_COUNT, hid_svc->feature_report_chars},
|
||||||
|
};
|
||||||
|
|
||||||
|
for(size_t report_type_idx = 0; report_type_idx < COUNT_OF(hid_report_chars);
|
||||||
|
report_type_idx++) {
|
||||||
|
for(size_t report_idx = 0; report_idx < hid_report_chars[report_type_idx].report_count;
|
||||||
|
report_idx++) {
|
||||||
|
ble_gatt_characteristic_delete(
|
||||||
|
hid_svc->svc_handle, &hid_report_chars[report_type_idx].chars[report_idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete service
|
||||||
|
ble_gatt_service_delete(hid_svc->svc_handle);
|
||||||
|
free(hid_svc);
|
||||||
|
}
|
||||||
29
applications/main/bad_kb/helpers/ble_hid_svc.h
Normal file
29
applications/main/bad_kb/helpers/ble_hid_svc.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct BleServiceHid BleServiceHid;
|
||||||
|
|
||||||
|
BleServiceHid* ble_svc_hid_start();
|
||||||
|
|
||||||
|
void ble_svc_hid_stop(BleServiceHid* service);
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_report_map(BleServiceHid* service, const uint8_t* data, uint16_t len);
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_input_report(
|
||||||
|
BleServiceHid* service,
|
||||||
|
uint8_t input_report_num,
|
||||||
|
uint8_t* data,
|
||||||
|
uint16_t len);
|
||||||
|
|
||||||
|
// Expects data to be of length BLE_SVC_HID_INFO_LEN (4 bytes)
|
||||||
|
bool ble_svc_hid_update_info(BleServiceHid* service, uint8_t* data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,23 +1,16 @@
|
|||||||
|
#include "../bad_kb_app_i.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <input/input.h>
|
#include <input/input.h>
|
||||||
#include <lib/toolbox/args.h>
|
#include <lib/toolbox/args.h>
|
||||||
#include <furi_hal_bt_hid.h>
|
|
||||||
#include <furi_hal_usb_hid.h>
|
#include <furi_hal_usb_hid.h>
|
||||||
#include <bt/bt_service/bt.h>
|
#include "ble_hid.h"
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
#include "ducky_script.h"
|
#include "ducky_script.h"
|
||||||
#include "ducky_script_i.h"
|
#include "ducky_script_i.h"
|
||||||
#include <dolphin/dolphin.h>
|
#include <dolphin/dolphin.h>
|
||||||
#include <toolbox/hex.h>
|
#include <toolbox/hex.h>
|
||||||
#include <xtreme/xtreme.h>
|
|
||||||
#include "../scenes/bad_kb_scene.h"
|
|
||||||
|
|
||||||
const uint8_t BAD_KB_EMPTY_MAC[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
|
||||||
|
|
||||||
// Adjusts to serial MAC +2 in app init
|
|
||||||
uint8_t BAD_KB_BOUND_MAC[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
|
||||||
|
|
||||||
#define TAG "BadKb"
|
#define TAG "BadKb"
|
||||||
#define WORKER_TAG TAG "Worker"
|
#define WORKER_TAG TAG "Worker"
|
||||||
@@ -27,11 +20,11 @@ uint8_t BAD_KB_BOUND_MAC[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
|||||||
|
|
||||||
// Delays for waiting between HID key press and key release
|
// Delays for waiting between HID key press and key release
|
||||||
const uint8_t bt_hid_delays[LevelRssiNum] = {
|
const uint8_t bt_hid_delays[LevelRssiNum] = {
|
||||||
45, // LevelRssi122_100
|
60, // LevelRssi122_100
|
||||||
38, // LevelRssi99_80
|
55, // LevelRssi99_80
|
||||||
30, // LevelRssi79_60
|
50, // LevelRssi79_60
|
||||||
26, // LevelRssi59_40
|
47, // LevelRssi59_40
|
||||||
21, // LevelRssi39_0
|
34, // LevelRssi39_0
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t bt_timeout = 0;
|
uint8_t bt_timeout = 0;
|
||||||
@@ -63,14 +56,6 @@ static inline void update_bt_timeout(Bt* bt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
WorkerEvtStartStop = (1 << 0),
|
|
||||||
WorkerEvtPauseResume = (1 << 1),
|
|
||||||
WorkerEvtEnd = (1 << 2),
|
|
||||||
WorkerEvtConnect = (1 << 3),
|
|
||||||
WorkerEvtDisconnect = (1 << 4),
|
|
||||||
} WorkerEvtFlags;
|
|
||||||
|
|
||||||
static const char ducky_cmd_id[] = {"ID"};
|
static const char ducky_cmd_id[] = {"ID"};
|
||||||
static const char ducky_cmd_bt_id[] = {"BT_ID"};
|
static const char ducky_cmd_bt_id[] = {"BT_ID"};
|
||||||
|
|
||||||
@@ -120,12 +105,17 @@ bool ducky_get_number(const char* param, uint32_t* val) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t furi_hal_bt_hid_get_led_state() {
|
||||||
|
// FIXME
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void ducky_numlock_on(BadKbScript* bad_kb) {
|
void ducky_numlock_on(BadKbScript* bad_kb) {
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
if((furi_hal_bt_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
|
if((furi_hal_bt_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
|
||||||
furi_hal_bt_hid_kb_press(HID_KEYBOARD_LOCK_NUM_LOCK);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, HID_KEYBOARD_LOCK_NUM_LOCK);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(HID_KEYBOARD_LOCK_NUM_LOCK);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, HID_KEYBOARD_LOCK_NUM_LOCK);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if((furi_hal_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
|
if((furi_hal_hid_get_led_state() & HID_KB_LED_NUM) == 0) {
|
||||||
@@ -140,9 +130,9 @@ bool ducky_numpad_press(BadKbScript* bad_kb, const char num) {
|
|||||||
|
|
||||||
uint16_t key = numpad_keys[num - '0'];
|
uint16_t key = numpad_keys[num - '0'];
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(key);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(key);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, key);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(key);
|
furi_hal_hid_kb_press(key);
|
||||||
furi_hal_hid_kb_release(key);
|
furi_hal_hid_kb_release(key);
|
||||||
@@ -156,7 +146,7 @@ bool ducky_altchar(BadKbScript* bad_kb, const char* charcode) {
|
|||||||
bool state = false;
|
bool state = false;
|
||||||
|
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(KEY_MOD_LEFT_ALT);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, KEY_MOD_LEFT_ALT);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
|
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT);
|
||||||
}
|
}
|
||||||
@@ -168,7 +158,7 @@ bool ducky_altchar(BadKbScript* bad_kb, const char* charcode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release(KEY_MOD_LEFT_ALT);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, KEY_MOD_LEFT_ALT);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
|
furi_hal_hid_kb_release(KEY_MOD_LEFT_ALT);
|
||||||
}
|
}
|
||||||
@@ -213,9 +203,9 @@ bool ducky_string(BadKbScript* bad_kb, const char* param) {
|
|||||||
uint16_t keycode = BADKB_ASCII_TO_KEY(bad_kb, param[i]);
|
uint16_t keycode = BADKB_ASCII_TO_KEY(bad_kb, param[i]);
|
||||||
if(keycode != HID_KEYBOARD_NONE) {
|
if(keycode != HID_KEYBOARD_NONE) {
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(keycode);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, keycode);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(keycode);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, keycode);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(keycode);
|
furi_hal_hid_kb_press(keycode);
|
||||||
furi_hal_hid_kb_release(keycode);
|
furi_hal_hid_kb_release(keycode);
|
||||||
@@ -223,9 +213,9 @@ bool ducky_string(BadKbScript* bad_kb, const char* param) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(HID_KEYBOARD_RETURN);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(HID_KEYBOARD_RETURN);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
|
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
|
||||||
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
|
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
|
||||||
@@ -248,9 +238,9 @@ static bool ducky_string_next(BadKbScript* bad_kb) {
|
|||||||
uint16_t keycode = BADKB_ASCII_TO_KEY(bad_kb, print_char);
|
uint16_t keycode = BADKB_ASCII_TO_KEY(bad_kb, print_char);
|
||||||
if(keycode != HID_KEYBOARD_NONE) {
|
if(keycode != HID_KEYBOARD_NONE) {
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(keycode);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, keycode);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(keycode);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, keycode);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(keycode);
|
furi_hal_hid_kb_press(keycode);
|
||||||
furi_hal_hid_kb_release(keycode);
|
furi_hal_hid_kb_release(keycode);
|
||||||
@@ -258,9 +248,9 @@ static bool ducky_string_next(BadKbScript* bad_kb) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(HID_KEYBOARD_RETURN);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(HID_KEYBOARD_RETURN);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, HID_KEYBOARD_RETURN);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
|
furi_hal_hid_kb_press(HID_KEYBOARD_RETURN);
|
||||||
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
|
furi_hal_hid_kb_release(HID_KEYBOARD_RETURN);
|
||||||
@@ -302,9 +292,9 @@ static int32_t ducky_parse_line(BadKbScript* bad_kb, FuriString* line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(key);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release(key);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, key);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(key);
|
furi_hal_hid_kb_press(key);
|
||||||
furi_hal_hid_kb_release(key);
|
furi_hal_hid_kb_release(key);
|
||||||
@@ -313,7 +303,7 @@ static int32_t ducky_parse_line(BadKbScript* bad_kb, FuriString* line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool ducky_set_usb_id(BadKbScript* bad_kb, const char* line) {
|
static bool ducky_set_usb_id(BadKbScript* bad_kb, const char* line) {
|
||||||
FuriHalUsbHidConfig* cfg = &bad_kb->app->id_config.usb_cfg;
|
FuriHalUsbHidConfig* cfg = &bad_kb->app->id_config.usb;
|
||||||
|
|
||||||
if(sscanf(line, "%lX:%lX", &cfg->vid, &cfg->pid) == 2) {
|
if(sscanf(line, "%lX:%lX", &cfg->vid, &cfg->pid) == 2) {
|
||||||
cfg->manuf[0] = '\0';
|
cfg->manuf[0] = '\0';
|
||||||
@@ -339,20 +329,20 @@ static bool ducky_set_bt_id(BadKbScript* bad_kb, const char* line) {
|
|||||||
BadKbConfig* cfg = &bad_kb->app->id_config;
|
BadKbConfig* cfg = &bad_kb->app->id_config;
|
||||||
|
|
||||||
size_t line_len = strlen(line);
|
size_t line_len = strlen(line);
|
||||||
size_t mac_len = BAD_KB_MAC_LEN * 3; // 2 text chars + separator per byte
|
size_t mac_len = sizeof(cfg->ble.mac) * 3; // 2 text chars + separator per byte
|
||||||
if(line_len < mac_len + 1) return false; // MAC + at least 1 char for name
|
if(line_len < mac_len + 1) return false; // MAC + at least 1 char for name
|
||||||
|
|
||||||
for(size_t i = 0; i < BAD_KB_MAC_LEN; i++) {
|
for(size_t i = 0; i < sizeof(cfg->ble.mac); i++) {
|
||||||
char a = line[i * 3];
|
char a = line[i * 3];
|
||||||
char b = line[i * 3 + 1];
|
char b = line[i * 3 + 1];
|
||||||
if((a < 'A' && a > 'F') || (a < '0' && a > '9') || (b < 'A' && b > 'F') ||
|
if((a < 'A' && a > 'F') || (a < '0' && a > '9') || (b < 'A' && b > 'F') ||
|
||||||
(b < '0' && b > '9') || !hex_char_to_uint8(a, b, &cfg->bt_mac[i])) {
|
(b < '0' && b > '9') || !hex_char_to_uint8(a, b, &cfg->ble.mac[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
furi_hal_bt_reverse_mac_addr(cfg->bt_mac);
|
furi_hal_bt_reverse_mac_addr(cfg->ble.mac);
|
||||||
|
|
||||||
strlcpy(cfg->bt_name, line + mac_len, BAD_KB_NAME_LEN);
|
strlcpy(cfg->ble.name, line + mac_len, sizeof(cfg->ble.name));
|
||||||
FURI_LOG_D(WORKER_TAG, "set bt id: %s", line);
|
FURI_LOG_D(WORKER_TAG, "set bt id: %s", line);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -473,7 +463,7 @@ static int32_t ducky_script_execute_next(BadKbScript* bad_kb, File* script_file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bad_kb_bt_hid_state_callback(BtStatus status, void* context) {
|
void bad_kb_bt_hid_state_callback(BtStatus status, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
BadKbScript* bad_kb = context;
|
BadKbScript* bad_kb = context;
|
||||||
bool state = (status == BtStatusConnected);
|
bool state = (status == BtStatusConnected);
|
||||||
@@ -489,7 +479,7 @@ static void bad_kb_bt_hid_state_callback(BtStatus status, void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bad_kb_usb_hid_state_callback(bool state, void* context) {
|
void bad_kb_usb_hid_state_callback(bool state, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
BadKbScript* bad_kb = context;
|
BadKbScript* bad_kb = context;
|
||||||
|
|
||||||
@@ -513,188 +503,6 @@ static uint32_t bad_kb_flags_get(uint32_t flags_mask, uint32_t timeout) {
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t bad_kb_conn_apply(BadKbApp* app) {
|
|
||||||
if(app->is_bt) {
|
|
||||||
// Shorthands so this bs is readable
|
|
||||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
|
||||||
FuriHalBtProfile kbd = FuriHalBtProfileHidKeyboard;
|
|
||||||
|
|
||||||
// Setup new config
|
|
||||||
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
|
||||||
bt_disconnect(app->bt);
|
|
||||||
furi_delay_ms(200);
|
|
||||||
bt_keys_storage_set_storage_path(app->bt, BAD_KB_KEYS_PATH);
|
|
||||||
furi_hal_bt_set_profile_adv_name(kbd, cfg->bt_name);
|
|
||||||
if(app->bt_remember) {
|
|
||||||
furi_hal_bt_set_profile_mac_addr(kbd, BAD_KB_BOUND_MAC);
|
|
||||||
furi_hal_bt_set_profile_pairing_method(kbd, GapPairingPinCodeVerifyYesNo);
|
|
||||||
} else {
|
|
||||||
furi_hal_bt_set_profile_mac_addr(kbd, cfg->bt_mac);
|
|
||||||
furi_hal_bt_set_profile_pairing_method(kbd, GapPairingNone);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set profile, restart BT, adjust defaults
|
|
||||||
furi_check(bt_set_profile(app->bt, BtProfileHidKeyboard));
|
|
||||||
|
|
||||||
// Advertise even if BT is off in settings
|
|
||||||
furi_hal_bt_start_advertising();
|
|
||||||
|
|
||||||
// Toggle key callback after since BT restart resets it
|
|
||||||
if(app->bt_remember) {
|
|
||||||
bt_enable_peer_key_update(app->bt);
|
|
||||||
} else {
|
|
||||||
bt_disable_peer_key_update(app->bt);
|
|
||||||
}
|
|
||||||
|
|
||||||
app->conn_mode = BadKbConnModeBt;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Unlock RPC connections
|
|
||||||
furi_hal_usb_unlock();
|
|
||||||
|
|
||||||
// Context will apply with set_config only if pointer address is different, so we use a copy
|
|
||||||
FuriHalUsbHidConfig* hid_cfg = malloc(sizeof(FuriHalUsbHidConfig));
|
|
||||||
memcpy(
|
|
||||||
hid_cfg,
|
|
||||||
app->set_usb_id ? &app->id_config.usb_cfg : &app->config.usb_cfg,
|
|
||||||
sizeof(FuriHalUsbHidConfig));
|
|
||||||
furi_check(furi_hal_usb_set_config(&usb_hid, hid_cfg));
|
|
||||||
if(app->hid_cfg) free(app->hid_cfg);
|
|
||||||
app->hid_cfg = hid_cfg;
|
|
||||||
|
|
||||||
app->conn_mode = BadKbConnModeUsb;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bad_kb_conn_reset(BadKbApp* app) {
|
|
||||||
if(app->conn_mode == BadKbConnModeBt) {
|
|
||||||
// TODO: maybe also restore BT profile?
|
|
||||||
bt_disconnect(app->bt);
|
|
||||||
furi_delay_ms(200);
|
|
||||||
bt_keys_storage_set_default_path(app->bt);
|
|
||||||
FuriHalBtProfile kbd = FuriHalBtProfileHidKeyboard;
|
|
||||||
furi_hal_bt_set_profile_mac_addr(kbd, app->prev_bt_mac);
|
|
||||||
furi_hal_bt_set_profile_adv_name(kbd, app->prev_bt_name);
|
|
||||||
furi_hal_bt_set_profile_pairing_method(kbd, app->prev_bt_mode);
|
|
||||||
furi_check(bt_set_profile(app->bt, BtProfileSerial));
|
|
||||||
bt_enable_peer_key_update(app->bt);
|
|
||||||
|
|
||||||
} else if(app->conn_mode == BadKbConnModeUsb) {
|
|
||||||
// TODO: maybe also restore USB context?
|
|
||||||
furi_check(furi_hal_usb_set_config(app->prev_usb_mode, NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
app->conn_mode = BadKbConnModeNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bad_kb_config_adjust(BadKbConfig* cfg) {
|
|
||||||
// Avoid empty name
|
|
||||||
if(strcmp(cfg->bt_name, "") == 0) {
|
|
||||||
snprintf(cfg->bt_name, BAD_KB_NAME_LEN, "Control %s", furi_hal_version_get_name_ptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
// MAC is adjusted by furi_hal_bt, adjust here too so it matches after applying
|
|
||||||
const uint8_t* normal_mac = furi_hal_version_get_ble_mac();
|
|
||||||
uint8_t empty_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR;
|
|
||||||
uint8_t default_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_DEFAULT_MAC_ADDR;
|
|
||||||
if(memcmp(cfg->bt_mac, empty_mac, BAD_KB_MAC_LEN) == 0 ||
|
|
||||||
memcmp(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN) == 0 ||
|
|
||||||
memcmp(cfg->bt_mac, default_mac, BAD_KB_MAC_LEN) == 0) {
|
|
||||||
memcpy(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN);
|
|
||||||
cfg->bt_mac[2]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use defaults if vid or pid are unset
|
|
||||||
if(cfg->usb_cfg.vid == 0) cfg->usb_cfg.vid = HID_VID_DEFAULT;
|
|
||||||
if(cfg->usb_cfg.pid == 0) cfg->usb_cfg.pid = HID_PID_DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bad_kb_config_refresh(BadKbApp* app) {
|
|
||||||
bt_set_status_changed_callback(app->bt, NULL, NULL);
|
|
||||||
furi_hal_hid_set_state_callback(NULL, NULL);
|
|
||||||
if(app->bad_kb_script) {
|
|
||||||
furi_thread_flags_set(furi_thread_get_id(app->bad_kb_script->thread), WorkerEvtDisconnect);
|
|
||||||
}
|
|
||||||
if(app->conn_init_thread) {
|
|
||||||
furi_thread_join(app->conn_init_thread);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool apply = false;
|
|
||||||
if(app->is_bt) {
|
|
||||||
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
|
|
||||||
bad_kb_config_adjust(cfg);
|
|
||||||
|
|
||||||
if(app->conn_mode != BadKbConnModeBt) {
|
|
||||||
apply = true;
|
|
||||||
bad_kb_conn_reset(app);
|
|
||||||
} else {
|
|
||||||
apply = apply || strncmp(
|
|
||||||
cfg->bt_name,
|
|
||||||
furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard),
|
|
||||||
BAD_KB_NAME_LEN);
|
|
||||||
apply = apply || memcmp(
|
|
||||||
app->bt_remember ? BAD_KB_BOUND_MAC : cfg->bt_mac,
|
|
||||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
|
||||||
BAD_KB_MAC_LEN);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config;
|
|
||||||
bad_kb_config_adjust(cfg);
|
|
||||||
|
|
||||||
if(app->conn_mode != BadKbConnModeUsb) {
|
|
||||||
apply = true;
|
|
||||||
bad_kb_conn_reset(app);
|
|
||||||
} else {
|
|
||||||
void* ctx;
|
|
||||||
if(furi_hal_usb_get_config() == &usb_hid &&
|
|
||||||
(ctx = furi_hal_usb_get_config_context()) != NULL) {
|
|
||||||
FuriHalUsbHidConfig* cur = ctx;
|
|
||||||
apply = apply || cfg->usb_cfg.vid != cur->vid;
|
|
||||||
apply = apply || cfg->usb_cfg.pid != cur->pid;
|
|
||||||
apply = apply || strncmp(cfg->usb_cfg.manuf, cur->manuf, sizeof(cur->manuf));
|
|
||||||
apply = apply || strncmp(cfg->usb_cfg.product, cur->product, sizeof(cur->product));
|
|
||||||
} else {
|
|
||||||
apply = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(apply) {
|
|
||||||
bad_kb_conn_apply(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(app->bad_kb_script) {
|
|
||||||
BadKbScript* script = app->bad_kb_script;
|
|
||||||
script->st.is_bt = app->is_bt;
|
|
||||||
script->bt = app->is_bt ? app->bt : NULL;
|
|
||||||
bool connected;
|
|
||||||
if(app->is_bt) {
|
|
||||||
bt_set_status_changed_callback(app->bt, bad_kb_bt_hid_state_callback, script);
|
|
||||||
connected = furi_hal_bt_is_connected();
|
|
||||||
} else {
|
|
||||||
furi_hal_hid_set_state_callback(bad_kb_usb_hid_state_callback, script);
|
|
||||||
connected = furi_hal_hid_is_connected();
|
|
||||||
}
|
|
||||||
if(connected) {
|
|
||||||
furi_thread_flags_set(furi_thread_get_id(script->thread), WorkerEvtConnect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reload config page
|
|
||||||
scene_manager_next_scene(app->scene_manager, BadKbSceneConfig);
|
|
||||||
scene_manager_previous_scene(app->scene_manager);
|
|
||||||
|
|
||||||
// Update settings
|
|
||||||
if(xtreme_settings.bad_bt != app->is_bt ||
|
|
||||||
xtreme_settings.bad_bt_remember != app->bt_remember) {
|
|
||||||
xtreme_settings.bad_bt = app->is_bt;
|
|
||||||
xtreme_settings.bad_bt_remember = app->bt_remember;
|
|
||||||
xtreme_settings_save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t bad_kb_worker(void* context) {
|
static int32_t bad_kb_worker(void* context) {
|
||||||
BadKbScript* bad_kb = context;
|
BadKbScript* bad_kb = context;
|
||||||
|
|
||||||
@@ -838,14 +646,14 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
} else if(flags & WorkerEvtStartStop) {
|
} else if(flags & WorkerEvtStartStop) {
|
||||||
worker_state = BadKbStateIdle; // Stop executing script
|
worker_state = BadKbStateIdle; // Stop executing script
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
} else if(flags & WorkerEvtDisconnect) {
|
} else if(flags & WorkerEvtDisconnect) {
|
||||||
worker_state = BadKbStateNotConnected; // Disconnected
|
worker_state = BadKbStateNotConnected; // Disconnected
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
@@ -871,7 +679,7 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
worker_state = BadKbStateScriptError;
|
worker_state = BadKbStateScriptError;
|
||||||
bad_kb->st.state = worker_state;
|
bad_kb->st.state = worker_state;
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
@@ -880,7 +688,7 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
worker_state = BadKbStateIdle;
|
worker_state = BadKbStateIdle;
|
||||||
bad_kb->st.state = BadKbStateDone;
|
bad_kb->st.state = BadKbStateDone;
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
@@ -917,7 +725,7 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
} else if(flags & WorkerEvtDisconnect) {
|
} else if(flags & WorkerEvtDisconnect) {
|
||||||
worker_state = BadKbStateNotConnected; // Disconnected
|
worker_state = BadKbStateNotConnected; // Disconnected
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
@@ -940,7 +748,7 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
worker_state = BadKbStateIdle; // Stop executing script
|
worker_state = BadKbStateIdle; // Stop executing script
|
||||||
bad_kb->st.state = worker_state;
|
bad_kb->st.state = worker_state;
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
@@ -948,7 +756,7 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
worker_state = BadKbStateNotConnected; // Disconnected
|
worker_state = BadKbStateNotConnected; // Disconnected
|
||||||
bad_kb->st.state = worker_state;
|
bad_kb->st.state = worker_state;
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
@@ -983,14 +791,14 @@ static int32_t bad_kb_worker(void* context) {
|
|||||||
} else if(flags & WorkerEvtStartStop) {
|
} else if(flags & WorkerEvtStartStop) {
|
||||||
worker_state = BadKbStateIdle; // Stop executing script
|
worker_state = BadKbStateIdle; // Stop executing script
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
} else if(flags & WorkerEvtDisconnect) {
|
} else if(flags & WorkerEvtDisconnect) {
|
||||||
worker_state = BadKbStateNotConnected; // Disconnected
|
worker_state = BadKbStateNotConnected; // Disconnected
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release_all();
|
furi_hal_hid_kb_release_all();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,9 @@ extern "C" {
|
|||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <bt/bt_service/bt_i.h>
|
#include <bt/bt_service/bt.h>
|
||||||
|
|
||||||
#include <gui/view_dispatcher.h>
|
#include "../bad_kb_app.h"
|
||||||
#include <gui/modules/widget.h>
|
|
||||||
#include <gui/modules/variable_item_list.h>
|
|
||||||
#include <gui/modules/text_input.h>
|
|
||||||
#include <gui/modules/byte_input.h>
|
|
||||||
#include <gui/modules/loading.h>
|
|
||||||
#include "../views/bad_kb_view.h"
|
|
||||||
#include "../bad_kb_paths.h"
|
|
||||||
|
|
||||||
#define FILE_BUFFER_LEN 16
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LevelRssi122_100,
|
LevelRssi122_100,
|
||||||
@@ -33,6 +24,14 @@ extern const uint8_t bt_hid_delays[LevelRssiNum];
|
|||||||
|
|
||||||
extern uint8_t bt_timeout;
|
extern uint8_t bt_timeout;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WorkerEvtStartStop = (1 << 0),
|
||||||
|
WorkerEvtPauseResume = (1 << 1),
|
||||||
|
WorkerEvtEnd = (1 << 2),
|
||||||
|
WorkerEvtConnect = (1 << 3),
|
||||||
|
WorkerEvtDisconnect = (1 << 4),
|
||||||
|
} WorkerEvtFlags;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BadKbStateInit,
|
BadKbStateInit,
|
||||||
BadKbStateNotConnected,
|
BadKbStateNotConnected,
|
||||||
@@ -48,7 +47,7 @@ typedef enum {
|
|||||||
BadKbStateFileError,
|
BadKbStateFileError,
|
||||||
} BadKbWorkerState;
|
} BadKbWorkerState;
|
||||||
|
|
||||||
struct BadKbState {
|
typedef struct {
|
||||||
BadKbWorkerState state;
|
BadKbWorkerState state;
|
||||||
bool is_bt;
|
bool is_bt;
|
||||||
uint32_t pin;
|
uint32_t pin;
|
||||||
@@ -58,36 +57,9 @@ struct BadKbState {
|
|||||||
size_t error_line;
|
size_t error_line;
|
||||||
char error[64];
|
char error[64];
|
||||||
uint32_t elapsed;
|
uint32_t elapsed;
|
||||||
};
|
} BadKbState;
|
||||||
|
|
||||||
typedef struct BadKbApp BadKbApp;
|
typedef struct BadKbScript BadKbScript;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
FuriThread* thread;
|
|
||||||
BadKbState st;
|
|
||||||
|
|
||||||
FuriString* file_path;
|
|
||||||
FuriString* keyboard_layout;
|
|
||||||
uint8_t file_buf[FILE_BUFFER_LEN + 1];
|
|
||||||
uint8_t buf_start;
|
|
||||||
uint8_t buf_len;
|
|
||||||
bool file_end;
|
|
||||||
|
|
||||||
uint32_t defdelay;
|
|
||||||
uint32_t stringdelay;
|
|
||||||
uint16_t layout[128];
|
|
||||||
|
|
||||||
FuriString* line;
|
|
||||||
FuriString* line_prev;
|
|
||||||
uint32_t repeat_cnt;
|
|
||||||
uint8_t key_hold_nb;
|
|
||||||
|
|
||||||
FuriString* string_print;
|
|
||||||
size_t string_print_pos;
|
|
||||||
|
|
||||||
Bt* bt;
|
|
||||||
BadKbApp* app;
|
|
||||||
} BadKbScript;
|
|
||||||
|
|
||||||
BadKbScript* bad_kb_script_open(FuriString* file_path, Bt* bt, BadKbApp* app);
|
BadKbScript* bad_kb_script_open(FuriString* file_path, Bt* bt, BadKbApp* app);
|
||||||
|
|
||||||
@@ -105,79 +77,9 @@ void bad_kb_script_pause_resume(BadKbScript* bad_kb);
|
|||||||
|
|
||||||
BadKbState* bad_kb_script_get_state(BadKbScript* bad_kb);
|
BadKbState* bad_kb_script_get_state(BadKbScript* bad_kb);
|
||||||
|
|
||||||
#define BAD_KB_NAME_LEN FURI_HAL_BT_ADV_NAME_LENGTH
|
void bad_kb_bt_hid_state_callback(BtStatus status, void* context);
|
||||||
#define BAD_KB_MAC_LEN GAP_MAC_ADDR_SIZE
|
|
||||||
#define BAD_KB_USB_LEN HID_MANUF_PRODUCT_NAME_LEN
|
|
||||||
|
|
||||||
extern const uint8_t BAD_KB_EMPTY_MAC[BAD_KB_MAC_LEN];
|
void bad_kb_usb_hid_state_callback(bool state, void* context);
|
||||||
extern uint8_t BAD_KB_BOUND_MAC[BAD_KB_MAC_LEN]; // For remember mode
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BadKbAppErrorNoFiles,
|
|
||||||
} BadKbAppError;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char bt_name[BAD_KB_NAME_LEN];
|
|
||||||
uint8_t bt_mac[BAD_KB_MAC_LEN];
|
|
||||||
FuriHalUsbHidConfig usb_cfg;
|
|
||||||
} BadKbConfig;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BadKbConnModeNone,
|
|
||||||
BadKbConnModeUsb,
|
|
||||||
BadKbConnModeBt,
|
|
||||||
} BadKbConnMode;
|
|
||||||
|
|
||||||
struct BadKbApp {
|
|
||||||
Gui* gui;
|
|
||||||
ViewDispatcher* view_dispatcher;
|
|
||||||
SceneManager* scene_manager;
|
|
||||||
NotificationApp* notifications;
|
|
||||||
DialogsApp* dialogs;
|
|
||||||
Widget* widget;
|
|
||||||
VariableItemList* var_item_list;
|
|
||||||
TextInput* text_input;
|
|
||||||
ByteInput* byte_input;
|
|
||||||
Loading* loading;
|
|
||||||
char usb_name_buf[BAD_KB_USB_LEN];
|
|
||||||
uint16_t usb_vidpid_buf[2];
|
|
||||||
char bt_name_buf[BAD_KB_NAME_LEN];
|
|
||||||
uint8_t bt_mac_buf[BAD_KB_MAC_LEN];
|
|
||||||
|
|
||||||
BadKbAppError error;
|
|
||||||
FuriString* file_path;
|
|
||||||
FuriString* keyboard_layout;
|
|
||||||
BadKb* bad_kb_view;
|
|
||||||
BadKbScript* bad_kb_script;
|
|
||||||
|
|
||||||
Bt* bt;
|
|
||||||
bool is_bt;
|
|
||||||
bool bt_remember;
|
|
||||||
BadKbConfig config; // User options
|
|
||||||
BadKbConfig id_config; // ID and BT_ID values
|
|
||||||
|
|
||||||
bool set_usb_id;
|
|
||||||
bool set_bt_id;
|
|
||||||
bool has_usb_id;
|
|
||||||
bool has_bt_id;
|
|
||||||
|
|
||||||
GapPairing prev_bt_mode;
|
|
||||||
char prev_bt_name[BAD_KB_NAME_LEN];
|
|
||||||
uint8_t prev_bt_mac[BAD_KB_MAC_LEN];
|
|
||||||
FuriHalUsbInterface* prev_usb_mode;
|
|
||||||
|
|
||||||
FuriHalUsbHidConfig* hid_cfg;
|
|
||||||
BadKbConnMode conn_mode;
|
|
||||||
FuriThread* conn_init_thread;
|
|
||||||
};
|
|
||||||
|
|
||||||
int32_t bad_kb_conn_apply(BadKbApp* app);
|
|
||||||
|
|
||||||
void bad_kb_conn_reset(BadKbApp* app);
|
|
||||||
|
|
||||||
void bad_kb_config_refresh(BadKbApp* app);
|
|
||||||
|
|
||||||
void bad_kb_config_adjust(BadKbConfig* cfg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
#include "../bad_kb_app_i.h"
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <furi_hal_bt_hid.h>
|
|
||||||
#include <furi_hal_usb_hid.h>
|
#include <furi_hal_usb_hid.h>
|
||||||
|
#include "ble_hid.h"
|
||||||
#include "ducky_script.h"
|
#include "ducky_script.h"
|
||||||
#include "ducky_script_i.h"
|
#include "ducky_script_i.h"
|
||||||
|
|
||||||
@@ -83,10 +84,11 @@ static int32_t ducky_fnc_sysrq(BadKbScript* bad_kb, const char* line, int32_t pa
|
|||||||
line = &line[ducky_get_command_len(line) + 1];
|
line = &line[ducky_get_command_len(line) + 1];
|
||||||
uint16_t key = ducky_get_keycode(bad_kb, line, true);
|
uint16_t key = ducky_get_keycode(bad_kb, line, true);
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
ble_profile_hid_kb_press(
|
||||||
furi_hal_bt_hid_kb_press(key);
|
bad_kb->app->ble_hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
||||||
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||||
furi_delay_ms(bt_timeout);
|
furi_delay_ms(bt_timeout);
|
||||||
furi_hal_bt_hid_kb_release_all();
|
ble_profile_hid_kb_release_all(bad_kb->app->ble_hid);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
furi_hal_hid_kb_press(KEY_MOD_LEFT_ALT | HID_KEYBOARD_PRINT_SCREEN);
|
||||||
furi_hal_hid_kb_press(key);
|
furi_hal_hid_kb_press(key);
|
||||||
@@ -132,7 +134,7 @@ static int32_t ducky_fnc_hold(BadKbScript* bad_kb, const char* line, int32_t par
|
|||||||
return ducky_error(bad_kb, "Too many keys are hold");
|
return ducky_error(bad_kb, "Too many keys are hold");
|
||||||
}
|
}
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_press(key);
|
ble_profile_hid_kb_press(bad_kb->app->ble_hid, key);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_press(key);
|
furi_hal_hid_kb_press(key);
|
||||||
}
|
}
|
||||||
@@ -152,7 +154,7 @@ static int32_t ducky_fnc_release(BadKbScript* bad_kb, const char* line, int32_t
|
|||||||
}
|
}
|
||||||
bad_kb->key_hold_nb--;
|
bad_kb->key_hold_nb--;
|
||||||
if(bad_kb->bt) {
|
if(bad_kb->bt) {
|
||||||
furi_hal_bt_hid_kb_release(key);
|
ble_profile_hid_kb_release(bad_kb->app->ble_hid, key);
|
||||||
} else {
|
} else {
|
||||||
furi_hal_hid_kb_release(key);
|
furi_hal_hid_kb_release(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,35 @@ extern "C" {
|
|||||||
#define SCRIPT_STATE_STRING_START (-5)
|
#define SCRIPT_STATE_STRING_START (-5)
|
||||||
#define SCRIPT_STATE_WAIT_FOR_BTN (-6)
|
#define SCRIPT_STATE_WAIT_FOR_BTN (-6)
|
||||||
|
|
||||||
|
#define FILE_BUFFER_LEN 16
|
||||||
|
|
||||||
|
struct BadKbScript {
|
||||||
|
FuriThread* thread;
|
||||||
|
BadKbState st;
|
||||||
|
|
||||||
|
FuriString* file_path;
|
||||||
|
FuriString* keyboard_layout;
|
||||||
|
uint8_t file_buf[FILE_BUFFER_LEN + 1];
|
||||||
|
uint8_t buf_start;
|
||||||
|
uint8_t buf_len;
|
||||||
|
bool file_end;
|
||||||
|
|
||||||
|
uint32_t defdelay;
|
||||||
|
uint32_t stringdelay;
|
||||||
|
uint16_t layout[128];
|
||||||
|
|
||||||
|
FuriString* line;
|
||||||
|
FuriString* line_prev;
|
||||||
|
uint32_t repeat_cnt;
|
||||||
|
uint8_t key_hold_nb;
|
||||||
|
|
||||||
|
FuriString* string_print;
|
||||||
|
size_t string_print_pos;
|
||||||
|
|
||||||
|
Bt* bt;
|
||||||
|
BadKbApp* app;
|
||||||
|
};
|
||||||
|
|
||||||
uint16_t ducky_get_keycode(BadKbScript* bad_kb, const char* param, bool accept_chars);
|
uint16_t ducky_get_keycode(BadKbScript* bad_kb, const char* param, bool accept_chars);
|
||||||
|
|
||||||
uint32_t ducky_get_command_len(const char* line);
|
uint32_t ducky_get_command_len(const char* line);
|
||||||
|
|||||||
0
applications/main/bad_kb/resources/badkb/assets/layouts/sk-SK.kl
Normal file → Executable file
0
applications/main/bad_kb/resources/badkb/assets/layouts/sk-SK.kl
Normal file → Executable file
@@ -1,5 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
#include "../helpers/ducky_script.h"
|
|
||||||
#include "furi_hal_power.h"
|
#include "furi_hal_power.h"
|
||||||
#include "furi_hal_usb.h"
|
#include "furi_hal_usb.h"
|
||||||
#include <xtreme/xtreme.h>
|
#include <xtreme/xtreme.h>
|
||||||
@@ -143,7 +142,7 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) {
|
|||||||
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigBtMac);
|
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigBtMac);
|
||||||
break;
|
break;
|
||||||
case VarItemListIndexBtRandomizeMac:
|
case VarItemListIndexBtRandomizeMac:
|
||||||
furi_hal_random_fill_buf(bad_kb->config.bt_mac, BAD_KB_MAC_LEN);
|
furi_hal_random_fill_buf(bad_kb->config.ble.mac, sizeof(bad_kb->config.ble.mac));
|
||||||
bad_kb_config_refresh(bad_kb);
|
bad_kb_config_refresh(bad_kb);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -167,8 +166,8 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) {
|
|||||||
case VarItemListIndexUsbRandomizeVidPid:
|
case VarItemListIndexUsbRandomizeVidPid:
|
||||||
furi_hal_random_fill_buf(
|
furi_hal_random_fill_buf(
|
||||||
(void*)bad_kb->usb_vidpid_buf, sizeof(bad_kb->usb_vidpid_buf));
|
(void*)bad_kb->usb_vidpid_buf, sizeof(bad_kb->usb_vidpid_buf));
|
||||||
bad_kb->config.usb_cfg.vid = bad_kb->usb_vidpid_buf[0];
|
bad_kb->config.usb.vid = bad_kb->usb_vidpid_buf[0];
|
||||||
bad_kb->config.usb_cfg.pid = bad_kb->usb_vidpid_buf[1];
|
bad_kb->config.usb.pid = bad_kb->usb_vidpid_buf[1];
|
||||||
bad_kb_config_refresh(bad_kb);
|
bad_kb_config_refresh(bad_kb);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
|
|
||||||
void bad_kb_scene_config_bt_mac_byte_input_callback(void* context) {
|
void bad_kb_scene_config_bt_mac_byte_input_callback(void* context) {
|
||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
@@ -10,7 +10,7 @@ void bad_kb_scene_config_bt_mac_on_enter(void* context) {
|
|||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
ByteInput* byte_input = bad_kb->byte_input;
|
ByteInput* byte_input = bad_kb->byte_input;
|
||||||
|
|
||||||
memmove(bad_kb->bt_mac_buf, bad_kb->config.bt_mac, BAD_KB_MAC_LEN);
|
memcpy(bad_kb->bt_mac_buf, bad_kb->config.ble.mac, sizeof(bad_kb->bt_mac_buf));
|
||||||
furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf);
|
furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf);
|
||||||
byte_input_set_header_text(byte_input, "Set BT MAC address");
|
byte_input_set_header_text(byte_input, "Set BT MAC address");
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ void bad_kb_scene_config_bt_mac_on_enter(void* context) {
|
|||||||
NULL,
|
NULL,
|
||||||
bad_kb,
|
bad_kb,
|
||||||
bad_kb->bt_mac_buf,
|
bad_kb->bt_mac_buf,
|
||||||
BAD_KB_MAC_LEN);
|
sizeof(bad_kb->bt_mac_buf));
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewByteInput);
|
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewByteInput);
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ bool bad_kb_scene_config_bt_mac_on_event(void* context, SceneManagerEvent event)
|
|||||||
consumed = true;
|
consumed = true;
|
||||||
if(event.event == BadKbAppCustomEventByteInputDone) {
|
if(event.event == BadKbAppCustomEventByteInputDone) {
|
||||||
furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf);
|
furi_hal_bt_reverse_mac_addr(bad_kb->bt_mac_buf);
|
||||||
memmove(bad_kb->config.bt_mac, bad_kb->bt_mac_buf, BAD_KB_MAC_LEN);
|
memcpy(bad_kb->config.ble.mac, bad_kb->bt_mac_buf, sizeof(bad_kb->config.ble.mac));
|
||||||
bad_kb_config_refresh(bad_kb);
|
bad_kb_config_refresh(bad_kb);
|
||||||
}
|
}
|
||||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
|
|
||||||
static void bad_kb_scene_config_bt_name_text_input_callback(void* context) {
|
static void bad_kb_scene_config_bt_name_text_input_callback(void* context) {
|
||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
@@ -10,7 +10,7 @@ void bad_kb_scene_config_bt_name_on_enter(void* context) {
|
|||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
TextInput* text_input = bad_kb->text_input;
|
TextInput* text_input = bad_kb->text_input;
|
||||||
|
|
||||||
strlcpy(bad_kb->bt_name_buf, bad_kb->config.bt_name, BAD_KB_NAME_LEN);
|
strlcpy(bad_kb->bt_name_buf, bad_kb->config.ble.name, sizeof(bad_kb->bt_name_buf));
|
||||||
text_input_set_header_text(text_input, "Set BT device name");
|
text_input_set_header_text(text_input, "Set BT device name");
|
||||||
|
|
||||||
text_input_set_result_callback(
|
text_input_set_result_callback(
|
||||||
@@ -18,7 +18,7 @@ void bad_kb_scene_config_bt_name_on_enter(void* context) {
|
|||||||
bad_kb_scene_config_bt_name_text_input_callback,
|
bad_kb_scene_config_bt_name_text_input_callback,
|
||||||
bad_kb,
|
bad_kb,
|
||||||
bad_kb->bt_name_buf,
|
bad_kb->bt_name_buf,
|
||||||
BAD_KB_NAME_LEN,
|
sizeof(bad_kb->bt_name_buf),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
||||||
@@ -31,7 +31,7 @@ bool bad_kb_scene_config_bt_name_on_event(void* context, SceneManagerEvent event
|
|||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
consumed = true;
|
consumed = true;
|
||||||
if(event.event == BadKbAppCustomEventTextInputDone) {
|
if(event.event == BadKbAppCustomEventTextInputDone) {
|
||||||
strlcpy(bad_kb->config.bt_name, bad_kb->bt_name_buf, BAD_KB_NAME_LEN);
|
strlcpy(bad_kb->config.ble.name, bad_kb->bt_name_buf, sizeof(bad_kb->config.ble.name));
|
||||||
bad_kb_config_refresh(bad_kb);
|
bad_kb_config_refresh(bad_kb);
|
||||||
}
|
}
|
||||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
#include "furi_hal_power.h"
|
#include "furi_hal_power.h"
|
||||||
#include "furi_hal_usb.h"
|
#include "furi_hal_usb.h"
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
|
|
||||||
static void bad_kb_scene_config_usb_name_text_input_callback(void* context) {
|
static void bad_kb_scene_config_usb_name_text_input_callback(void* context) {
|
||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
@@ -11,10 +11,10 @@ void bad_kb_scene_config_usb_name_on_enter(void* context) {
|
|||||||
TextInput* text_input = bad_kb->text_input;
|
TextInput* text_input = bad_kb->text_input;
|
||||||
|
|
||||||
if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) {
|
if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) {
|
||||||
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb_cfg.manuf, BAD_KB_USB_LEN);
|
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb.manuf, sizeof(bad_kb->usb_name_buf));
|
||||||
text_input_set_header_text(text_input, "Set USB manufacturer name");
|
text_input_set_header_text(text_input, "Set USB manufacturer name");
|
||||||
} else {
|
} else {
|
||||||
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb_cfg.product, BAD_KB_USB_LEN);
|
strlcpy(bad_kb->usb_name_buf, bad_kb->config.usb.product, sizeof(bad_kb->usb_name_buf));
|
||||||
text_input_set_header_text(text_input, "Set USB product name");
|
text_input_set_header_text(text_input, "Set USB product name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ void bad_kb_scene_config_usb_name_on_enter(void* context) {
|
|||||||
bad_kb_scene_config_usb_name_text_input_callback,
|
bad_kb_scene_config_usb_name_text_input_callback,
|
||||||
bad_kb,
|
bad_kb,
|
||||||
bad_kb->usb_name_buf,
|
bad_kb->usb_name_buf,
|
||||||
BAD_KB_USB_LEN,
|
sizeof(bad_kb->usb_name_buf),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
||||||
@@ -37,9 +37,15 @@ bool bad_kb_scene_config_usb_name_on_event(void* context, SceneManagerEvent even
|
|||||||
consumed = true;
|
consumed = true;
|
||||||
if(event.event == BadKbAppCustomEventTextInputDone) {
|
if(event.event == BadKbAppCustomEventTextInputDone) {
|
||||||
if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) {
|
if(scene_manager_get_scene_state(bad_kb->scene_manager, BadKbSceneConfigUsbName)) {
|
||||||
strlcpy(bad_kb->config.usb_cfg.manuf, bad_kb->usb_name_buf, BAD_KB_USB_LEN);
|
strlcpy(
|
||||||
|
bad_kb->config.usb.manuf,
|
||||||
|
bad_kb->usb_name_buf,
|
||||||
|
sizeof(bad_kb->config.usb.product));
|
||||||
} else {
|
} else {
|
||||||
strlcpy(bad_kb->config.usb_cfg.product, bad_kb->usb_name_buf, BAD_KB_USB_LEN);
|
strlcpy(
|
||||||
|
bad_kb->config.usb.product,
|
||||||
|
bad_kb->usb_name_buf,
|
||||||
|
sizeof(bad_kb->config.usb.product));
|
||||||
}
|
}
|
||||||
bad_kb_config_refresh(bad_kb);
|
bad_kb_config_refresh(bad_kb);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
|
|
||||||
void bad_kb_scene_config_usb_vidpid_byte_input_callback(void* context) {
|
void bad_kb_scene_config_usb_vidpid_byte_input_callback(void* context) {
|
||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
@@ -10,8 +10,8 @@ void bad_kb_scene_config_usb_vidpid_on_enter(void* context) {
|
|||||||
BadKbApp* bad_kb = context;
|
BadKbApp* bad_kb = context;
|
||||||
ByteInput* byte_input = bad_kb->byte_input;
|
ByteInput* byte_input = bad_kb->byte_input;
|
||||||
|
|
||||||
bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->config.usb_cfg.vid);
|
bad_kb->usb_vidpid_buf[0] = __REVSH(bad_kb->config.usb.vid);
|
||||||
bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->config.usb_cfg.pid);
|
bad_kb->usb_vidpid_buf[1] = __REVSH(bad_kb->config.usb.pid);
|
||||||
byte_input_set_header_text(byte_input, "Set USB VID:PID");
|
byte_input_set_header_text(byte_input, "Set USB VID:PID");
|
||||||
|
|
||||||
byte_input_set_result_callback(
|
byte_input_set_result_callback(
|
||||||
@@ -32,8 +32,8 @@ bool bad_kb_scene_config_usb_vidpid_on_event(void* context, SceneManagerEvent ev
|
|||||||
if(event.type == SceneManagerEventTypeCustom) {
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
consumed = true;
|
consumed = true;
|
||||||
if(event.event == BadKbAppCustomEventByteInputDone) {
|
if(event.event == BadKbAppCustomEventByteInputDone) {
|
||||||
bad_kb->config.usb_cfg.vid = __REVSH(bad_kb->usb_vidpid_buf[0]);
|
bad_kb->config.usb.vid = __REVSH(bad_kb->usb_vidpid_buf[0]);
|
||||||
bad_kb->config.usb_cfg.pid = __REVSH(bad_kb->usb_vidpid_buf[1]);
|
bad_kb->config.usb.pid = __REVSH(bad_kb->usb_vidpid_buf[1]);
|
||||||
bad_kb_config_refresh(bad_kb);
|
bad_kb_config_refresh(bad_kb);
|
||||||
}
|
}
|
||||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bad_kb_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
|
bad_kb_scene_error_event_callback(GuiButtonType result, InputType type, void* context) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
#include <furi_hal_power.h>
|
#include <furi_hal_power.h>
|
||||||
#include <furi_hal_usb.h>
|
#include <furi_hal_usb.h>
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "../helpers/ducky_script.h"
|
#include "../helpers/ducky_script.h"
|
||||||
#include "../bad_kb_app.h"
|
#include "../bad_kb_app_i.h"
|
||||||
#include "../views/bad_kb_view.h"
|
#include "../views/bad_kb_view.h"
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include "toolbox/path.h"
|
#include "toolbox/path.h"
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
|
#include "../bad_kb_app_i.h"
|
||||||
#include "bad_kb_view.h"
|
#include "bad_kb_view.h"
|
||||||
#include "../helpers/ducky_script.h"
|
#include "../helpers/ducky_script.h"
|
||||||
#include "../bad_kb_app.h"
|
|
||||||
#include <toolbox/path.h>
|
#include <toolbox/path.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
#include <xtreme/xtreme.h>
|
#include <xtreme/xtreme.h>
|
||||||
|
#include <bt/bt_service/bt_i.h>
|
||||||
|
|
||||||
#define MAX_NAME_LEN 64
|
#define MAX_NAME_LEN 64
|
||||||
|
|
||||||
|
struct BadKb {
|
||||||
|
View* view;
|
||||||
|
BadKbButtonCallback callback;
|
||||||
|
void* context;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char file_name[MAX_NAME_LEN];
|
char file_name[MAX_NAME_LEN];
|
||||||
char layout[MAX_NAME_LEN];
|
char layout[MAX_NAME_LEN];
|
||||||
@@ -44,6 +51,8 @@ static void bad_kb_draw_callback(Canvas* canvas, void* _model) {
|
|||||||
canvas_draw_str(
|
canvas_draw_str(
|
||||||
canvas, 2, 8 + canvas_current_font_height(canvas), furi_string_get_cstr(disp_str));
|
canvas, 2, 8 + canvas_current_font_height(canvas), furi_string_get_cstr(disp_str));
|
||||||
|
|
||||||
|
furi_string_reset(disp_str);
|
||||||
|
|
||||||
canvas_draw_icon(canvas, 22, 24, &I_UsbTree_48x22);
|
canvas_draw_icon(canvas, 22, 24, &I_UsbTree_48x22);
|
||||||
|
|
||||||
if((state == BadKbStateIdle) || (state == BadKbStateDone) ||
|
if((state == BadKbStateIdle) || (state == BadKbStateDone) ||
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
|
#include "../helpers/ducky_script.h"
|
||||||
|
|
||||||
|
typedef struct BadKb BadKb;
|
||||||
typedef void (*BadKbButtonCallback)(InputKey key, void* context);
|
typedef void (*BadKbButtonCallback)(InputKey key, void* context);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
View* view;
|
|
||||||
BadKbButtonCallback callback;
|
|
||||||
void* context;
|
|
||||||
} BadKb;
|
|
||||||
|
|
||||||
typedef struct BadKbState BadKbState;
|
|
||||||
|
|
||||||
BadKb* bad_kb_alloc();
|
BadKb* bad_kb_alloc();
|
||||||
|
|
||||||
void bad_kb_free(BadKb* bad_kb);
|
void bad_kb_free(BadKb* bad_kb);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ static const char* opal_usages[14] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Opal file 0x7 structure. Assumes a little-endian CPU.
|
// Opal file 0x7 structure. Assumes a little-endian CPU.
|
||||||
typedef struct __attribute__((__packed__)) {
|
typedef struct FURI_PACKED {
|
||||||
uint32_t serial : 32;
|
uint32_t serial : 32;
|
||||||
uint8_t check_digit : 4;
|
uint8_t check_digit : 4;
|
||||||
bool blocked : 1;
|
bool blocked : 1;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <ble/ble.h>
|
#include <ble/ble.h>
|
||||||
#include "bt_settings.h"
|
#include "bt_settings.h"
|
||||||
#include "bt_service/bt.h"
|
#include "bt_service/bt.h"
|
||||||
|
#include <profiles/serial_profile.h>
|
||||||
|
|
||||||
static void bt_cli_command_hci_info(Cli* cli, FuriString* args, void* context) {
|
static void bt_cli_command_hci_info(Cli* cli, FuriString* args, void* context) {
|
||||||
UNUSED(cli);
|
UNUSED(cli);
|
||||||
@@ -45,7 +46,7 @@ static void bt_cli_command_carrier_tx(Cli* cli, FuriString* args, void* context)
|
|||||||
}
|
}
|
||||||
furi_hal_bt_stop_tone_tx();
|
furi_hal_bt_stop_tone_tx();
|
||||||
|
|
||||||
bt_set_profile(bt, BtProfileSerial);
|
bt_profile_restore_default(bt);
|
||||||
furi_record_close(RECORD_BT);
|
furi_record_close(RECORD_BT);
|
||||||
} while(false);
|
} while(false);
|
||||||
}
|
}
|
||||||
@@ -76,7 +77,7 @@ static void bt_cli_command_carrier_rx(Cli* cli, FuriString* args, void* context)
|
|||||||
|
|
||||||
furi_hal_bt_stop_packet_test();
|
furi_hal_bt_stop_packet_test();
|
||||||
|
|
||||||
bt_set_profile(bt, BtProfileSerial);
|
bt_profile_restore_default(bt);
|
||||||
furi_record_close(RECORD_BT);
|
furi_record_close(RECORD_BT);
|
||||||
} while(false);
|
} while(false);
|
||||||
}
|
}
|
||||||
@@ -124,7 +125,7 @@ static void bt_cli_command_packet_tx(Cli* cli, FuriString* args, void* context)
|
|||||||
furi_hal_bt_stop_packet_test();
|
furi_hal_bt_stop_packet_test();
|
||||||
printf("Transmitted %lu packets", furi_hal_bt_get_transmitted_packets());
|
printf("Transmitted %lu packets", furi_hal_bt_get_transmitted_packets());
|
||||||
|
|
||||||
bt_set_profile(bt, BtProfileSerial);
|
bt_profile_restore_default(bt);
|
||||||
furi_record_close(RECORD_BT);
|
furi_record_close(RECORD_BT);
|
||||||
} while(false);
|
} while(false);
|
||||||
}
|
}
|
||||||
@@ -159,7 +160,7 @@ static void bt_cli_command_packet_rx(Cli* cli, FuriString* args, void* context)
|
|||||||
uint16_t packets_received = furi_hal_bt_stop_packet_test();
|
uint16_t packets_received = furi_hal_bt_stop_packet_test();
|
||||||
printf("Received %hu packets", packets_received);
|
printf("Received %hu packets", packets_received);
|
||||||
|
|
||||||
bt_set_profile(bt, BtProfileSerial);
|
bt_profile_restore_default(bt);
|
||||||
furi_record_close(RECORD_BT);
|
furi_record_close(RECORD_BT);
|
||||||
} while(false);
|
} while(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
#include "bt_i.h"
|
#include "bt_i.h"
|
||||||
#include "bt_keys_storage.h"
|
#include "bt_keys_storage.h"
|
||||||
|
|
||||||
|
#include <core/check.h>
|
||||||
|
#include <furi_hal_bt.h>
|
||||||
#include <services/battery_service.h>
|
#include <services/battery_service.h>
|
||||||
#include <notification/notification_messages.h>
|
#include <notification/notification_messages.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
|
#include <profiles/serial_profile.h>
|
||||||
|
|
||||||
#define TAG "BtSrv"
|
#define TAG "BtSrv"
|
||||||
|
|
||||||
@@ -12,14 +15,21 @@
|
|||||||
#define BT_RPC_EVENT_DISCONNECTED (1UL << 1)
|
#define BT_RPC_EVENT_DISCONNECTED (1UL << 1)
|
||||||
#define BT_RPC_EVENT_ALL (BT_RPC_EVENT_BUFF_SENT | BT_RPC_EVENT_DISCONNECTED)
|
#define BT_RPC_EVENT_ALL (BT_RPC_EVENT_BUFF_SENT | BT_RPC_EVENT_DISCONNECTED)
|
||||||
|
|
||||||
|
#define ICON_SPACER 2
|
||||||
|
|
||||||
static void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
|
static void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
|
||||||
Bt* bt = context;
|
Bt* bt = context;
|
||||||
|
uint8_t draw_offset = 0;
|
||||||
|
if(bt->beacon_active) {
|
||||||
|
canvas_draw_icon(canvas, 0, 0, &I_BLE_beacon_7x8);
|
||||||
|
draw_offset += icon_get_width(&I_BLE_beacon_7x8) + ICON_SPACER;
|
||||||
|
}
|
||||||
if(bt->status == BtStatusAdvertising) {
|
if(bt->status == BtStatusAdvertising) {
|
||||||
canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_Idle_5x8);
|
canvas_draw_icon(canvas, draw_offset, 0, &I_Bluetooth_Idle_5x8);
|
||||||
} else if(bt->status == BtStatusConnected) {
|
} else if(bt->status == BtStatusConnected) {
|
||||||
canvas_draw_icon(canvas, 0, 0, &I_Bluetooth_Connected_16x8);
|
canvas_draw_icon(canvas, draw_offset, 0, &I_Bluetooth_Connected_16x8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +70,12 @@ static ViewPort* bt_pin_code_view_port_alloc(Bt* bt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
|
static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
|
||||||
furi_assert(bt);
|
|
||||||
bt->pin_code = pin_code;
|
bt->pin_code = pin_code;
|
||||||
|
if(!bt->pin_code_view_port) {
|
||||||
|
// Pin code view port
|
||||||
|
bt->pin_code_view_port = bt_pin_code_view_port_alloc(bt);
|
||||||
|
gui_add_view_port(bt->gui, bt->pin_code_view_port, GuiLayerFullscreen);
|
||||||
|
}
|
||||||
notification_message(bt->notification, &sequence_display_backlight_on);
|
notification_message(bt->notification, &sequence_display_backlight_on);
|
||||||
if(bt->suppress_pin_screen) return;
|
if(bt->suppress_pin_screen) return;
|
||||||
|
|
||||||
@@ -71,7 +85,7 @@ static void bt_pin_code_show(Bt* bt, uint32_t pin_code) {
|
|||||||
|
|
||||||
static void bt_pin_code_hide(Bt* bt) {
|
static void bt_pin_code_hide(Bt* bt) {
|
||||||
bt->pin_code = 0;
|
bt->pin_code = 0;
|
||||||
if(view_port_is_enabled(bt->pin_code_view_port)) {
|
if(bt->pin_code_view_port && view_port_is_enabled(bt->pin_code_view_port)) {
|
||||||
view_port_enabled_set(bt->pin_code_view_port, false);
|
view_port_enabled_set(bt->pin_code_view_port, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,6 +97,9 @@ static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) {
|
|||||||
if(bt->suppress_pin_screen) return true;
|
if(bt->suppress_pin_screen) return true;
|
||||||
|
|
||||||
FuriString* pin_str;
|
FuriString* pin_str;
|
||||||
|
if(!bt->dialog_message) {
|
||||||
|
bt->dialog_message = dialog_message_alloc();
|
||||||
|
}
|
||||||
dialog_message_set_icon(bt->dialog_message, &I_BLE_Pairing_128x64, 0, 0);
|
dialog_message_set_icon(bt->dialog_message, &I_BLE_Pairing_128x64, 0, 0);
|
||||||
pin_str = furi_string_alloc_printf("Verify code\n%06lu", pin);
|
pin_str = furi_string_alloc_printf("Verify code\n%06lu", pin);
|
||||||
dialog_message_set_text(
|
dialog_message_set_text(
|
||||||
@@ -100,25 +117,32 @@ static void bt_battery_level_changed_callback(const void* _event, void* context)
|
|||||||
Bt* bt = context;
|
Bt* bt = context;
|
||||||
BtMessage message = {};
|
BtMessage message = {};
|
||||||
const PowerEvent* event = _event;
|
const PowerEvent* event = _event;
|
||||||
if(event->type == PowerEventTypeBatteryLevelChanged) {
|
bool is_charging = false;
|
||||||
|
switch(event->type) {
|
||||||
|
case PowerEventTypeBatteryLevelChanged:
|
||||||
message.type = BtMessageTypeUpdateBatteryLevel;
|
message.type = BtMessageTypeUpdateBatteryLevel;
|
||||||
message.data.battery_level = event->data.battery_level;
|
message.data.battery_level = event->data.battery_level;
|
||||||
furi_check(
|
furi_check(
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
} else if(
|
break;
|
||||||
event->type == PowerEventTypeStartCharging || event->type == PowerEventTypeFullyCharged ||
|
case PowerEventTypeStartCharging:
|
||||||
event->type == PowerEventTypeStopCharging) {
|
is_charging = true;
|
||||||
|
/* fallthrough */
|
||||||
|
case PowerEventTypeFullyCharged:
|
||||||
|
case PowerEventTypeStopCharging:
|
||||||
message.type = BtMessageTypeUpdatePowerState;
|
message.type = BtMessageTypeUpdatePowerState;
|
||||||
|
message.data.power_state_charging = is_charging;
|
||||||
furi_check(
|
furi_check(
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bt* bt_alloc() {
|
Bt* bt_alloc() {
|
||||||
Bt* bt = malloc(sizeof(Bt));
|
Bt* bt = malloc(sizeof(Bt));
|
||||||
// Init default maximum packet size
|
// Init default maximum packet size
|
||||||
bt->max_packet_size = FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX;
|
bt->max_packet_size = BLE_PROFILE_SERIAL_PACKET_SIZE_MAX;
|
||||||
bt->profile = BtProfileSerial;
|
bt->current_profile = NULL;
|
||||||
// Load settings
|
// Load settings
|
||||||
bt_settings_load(&bt->bt_settings);
|
bt_settings_load(&bt->bt_settings);
|
||||||
// Keys storage
|
// Keys storage
|
||||||
@@ -128,18 +152,14 @@ Bt* bt_alloc() {
|
|||||||
|
|
||||||
// Setup statusbar view port
|
// Setup statusbar view port
|
||||||
bt->statusbar_view_port = bt_statusbar_view_port_alloc(bt);
|
bt->statusbar_view_port = bt_statusbar_view_port_alloc(bt);
|
||||||
// Pin code view port
|
|
||||||
bt->pin_code_view_port = bt_pin_code_view_port_alloc(bt);
|
|
||||||
// Notification
|
// Notification
|
||||||
bt->notification = furi_record_open(RECORD_NOTIFICATION);
|
bt->notification = furi_record_open(RECORD_NOTIFICATION);
|
||||||
// Gui
|
// Gui
|
||||||
bt->gui = furi_record_open(RECORD_GUI);
|
bt->gui = furi_record_open(RECORD_GUI);
|
||||||
gui_add_view_port(bt->gui, bt->statusbar_view_port, GuiLayerStatusBarLeft);
|
gui_add_view_port(bt->gui, bt->statusbar_view_port, GuiLayerStatusBarLeft);
|
||||||
gui_add_view_port(bt->gui, bt->pin_code_view_port, GuiLayerFullscreen);
|
|
||||||
|
|
||||||
// Dialogs
|
// Dialogs
|
||||||
bt->dialogs = furi_record_open(RECORD_DIALOGS);
|
bt->dialogs = furi_record_open(RECORD_DIALOGS);
|
||||||
bt->dialog_message = dialog_message_alloc();
|
|
||||||
|
|
||||||
// Power
|
// Power
|
||||||
bt->power = furi_record_open(RECORD_POWER);
|
bt->power = furi_record_open(RECORD_POWER);
|
||||||
@@ -176,7 +196,11 @@ static uint16_t bt_serial_event_callback(SerialServiceEvent event, void* context
|
|||||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_BUFF_SENT);
|
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_BUFF_SENT);
|
||||||
} else if(event.event == SerialServiceEventTypesBleResetRequest) {
|
} else if(event.event == SerialServiceEventTypesBleResetRequest) {
|
||||||
FURI_LOG_I(TAG, "BLE restart request received");
|
FURI_LOG_I(TAG, "BLE restart request received");
|
||||||
BtMessage message = {.type = BtMessageTypeSetProfile, .data.profile = BtProfileSerial};
|
BtMessage message = {
|
||||||
|
.type = BtMessageTypeSetProfile,
|
||||||
|
.data.profile.params = NULL,
|
||||||
|
.data.profile.template = ble_profile_serial,
|
||||||
|
};
|
||||||
furi_check(
|
furi_check(
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
}
|
}
|
||||||
@@ -197,10 +221,10 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
|
|||||||
while(bytes_sent < bytes_len) {
|
while(bytes_sent < bytes_len) {
|
||||||
size_t bytes_remain = bytes_len - bytes_sent;
|
size_t bytes_remain = bytes_len - bytes_sent;
|
||||||
if(bytes_remain > bt->max_packet_size) {
|
if(bytes_remain > bt->max_packet_size) {
|
||||||
furi_hal_bt_serial_tx(&bytes[bytes_sent], bt->max_packet_size);
|
ble_profile_serial_tx(bt->current_profile, &bytes[bytes_sent], bt->max_packet_size);
|
||||||
bytes_sent += bt->max_packet_size;
|
bytes_sent += bt->max_packet_size;
|
||||||
} else {
|
} else {
|
||||||
furi_hal_bt_serial_tx(&bytes[bytes_sent], bytes_remain);
|
ble_profile_serial_tx(bt->current_profile, &bytes[bytes_sent], bytes_remain);
|
||||||
bytes_sent += bytes_remain;
|
bytes_sent += bytes_remain;
|
||||||
}
|
}
|
||||||
// We want BT_RPC_EVENT_DISCONNECTED to stick, so don't clear
|
// We want BT_RPC_EVENT_DISCONNECTED to stick, so don't clear
|
||||||
@@ -215,49 +239,55 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bt_serial_buffer_is_empty_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
Bt* bt = context;
|
||||||
|
furi_check(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial));
|
||||||
|
ble_profile_serial_notify_buffer_is_empty(bt->current_profile);
|
||||||
|
}
|
||||||
|
|
||||||
// Called from GAP thread
|
// Called from GAP thread
|
||||||
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Bt* bt = context;
|
Bt* bt = context;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
bt->pin = 0;
|
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);
|
||||||
|
|
||||||
if(event.type == GapEventTypeConnected) {
|
if(event.type == GapEventTypeConnected) {
|
||||||
// Update status bar
|
// Update status bar
|
||||||
bt->status = BtStatusConnected;
|
bt->status = BtStatusConnected;
|
||||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
do_update_status = true;
|
||||||
furi_check(
|
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
|
||||||
bt_open_rpc_connection(bt);
|
bt_open_rpc_connection(bt);
|
||||||
// Update battery level
|
// Update battery level
|
||||||
PowerInfo info;
|
PowerInfo info;
|
||||||
power_get_info(bt->power, &info);
|
power_get_info(bt->power, &info);
|
||||||
|
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||||
message.type = BtMessageTypeUpdateBatteryLevel;
|
message.type = BtMessageTypeUpdateBatteryLevel;
|
||||||
message.data.battery_level = info.charge;
|
message.data.battery_level = info.charge;
|
||||||
furi_check(
|
furi_check(
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if(event.type == GapEventTypeDisconnected) {
|
} else if(event.type == GapEventTypeDisconnected) {
|
||||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
if(current_profile_is_serial && bt->rpc_session) {
|
||||||
FURI_LOG_I(TAG, "Close RPC connection");
|
FURI_LOG_I(TAG, "Close RPC connection");
|
||||||
furi_hal_bt_serial_set_rpc_status(FuriHalBtSerialRpcStatusNotActive);
|
ble_profile_serial_set_rpc_active(
|
||||||
|
bt->current_profile, FuriHalBtSerialRpcStatusNotActive);
|
||||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||||
rpc_session_close(bt->rpc_session);
|
rpc_session_close(bt->rpc_session);
|
||||||
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
|
ble_profile_serial_set_event_callback(bt->current_profile, 0, NULL, NULL);
|
||||||
bt->rpc_session = NULL;
|
bt->rpc_session = NULL;
|
||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if(event.type == GapEventTypeStartAdvertising) {
|
} else if(event.type == GapEventTypeStartAdvertising) {
|
||||||
bt->status = BtStatusAdvertising;
|
bt->status = BtStatusAdvertising;
|
||||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
do_update_status = true;
|
||||||
furi_check(
|
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if(event.type == GapEventTypeStopAdvertising) {
|
} else if(event.type == GapEventTypeStopAdvertising) {
|
||||||
bt->status = BtStatusOff;
|
bt->status = BtStatusOff;
|
||||||
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
do_update_status = true;
|
||||||
furi_check(
|
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
|
||||||
ret = true;
|
ret = true;
|
||||||
} else if(event.type == GapEventTypePinCodeShow) {
|
} else if(event.type == GapEventTypePinCodeShow) {
|
||||||
bt->pin = event.data.pin_code;
|
bt->pin = event.data.pin_code;
|
||||||
@@ -272,6 +302,20 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
|||||||
} else if(event.type == GapEventTypeUpdateMTU) {
|
} else if(event.type == GapEventTypeUpdateMTU) {
|
||||||
bt->max_packet_size = event.data.max_packet_size;
|
bt->max_packet_size = event.data.max_packet_size;
|
||||||
ret = true;
|
ret = true;
|
||||||
|
} else if(event.type == GapEventTypeBeaconStart) {
|
||||||
|
bt->beacon_active = true;
|
||||||
|
do_update_status = true;
|
||||||
|
ret = true;
|
||||||
|
} else if(event.type == GapEventTypeBeaconStop) {
|
||||||
|
bt->beacon_active = false;
|
||||||
|
do_update_status = true;
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(do_update_status) {
|
||||||
|
BtMessage message = {.type = BtMessageTypeUpdateStatus};
|
||||||
|
furi_check(
|
||||||
|
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -288,11 +332,18 @@ static void bt_on_key_storage_change_callback(uint8_t* addr, uint16_t size, void
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void bt_statusbar_update(Bt* bt) {
|
static void bt_statusbar_update(Bt* bt) {
|
||||||
|
uint8_t active_icon_width = 0;
|
||||||
|
if(bt->beacon_active) {
|
||||||
|
active_icon_width = icon_get_width(&I_BLE_beacon_7x8) + ICON_SPACER;
|
||||||
|
}
|
||||||
if(bt->status == BtStatusAdvertising) {
|
if(bt->status == BtStatusAdvertising) {
|
||||||
view_port_set_width(bt->statusbar_view_port, icon_get_width(&I_Bluetooth_Idle_5x8));
|
active_icon_width += icon_get_width(&I_Bluetooth_Idle_5x8);
|
||||||
view_port_enabled_set(bt->statusbar_view_port, true);
|
|
||||||
} else if(bt->status == BtStatusConnected) {
|
} else if(bt->status == BtStatusConnected) {
|
||||||
view_port_set_width(bt->statusbar_view_port, icon_get_width(&I_Bluetooth_Connected_16x8));
|
active_icon_width += icon_get_width(&I_Bluetooth_Connected_16x8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(active_icon_width > 0) {
|
||||||
|
view_port_set_width(bt->statusbar_view_port, active_icon_width);
|
||||||
view_port_enabled_set(bt->statusbar_view_port, true);
|
view_port_enabled_set(bt->statusbar_view_port, true);
|
||||||
} else {
|
} else {
|
||||||
view_port_enabled_set(bt->statusbar_view_port, false);
|
view_port_enabled_set(bt->statusbar_view_port, false);
|
||||||
@@ -300,6 +351,9 @@ static void bt_statusbar_update(Bt* bt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void bt_show_warning(Bt* bt, const char* text) {
|
static void bt_show_warning(Bt* bt, const char* text) {
|
||||||
|
if(!bt->dialog_message) {
|
||||||
|
bt->dialog_message = dialog_message_alloc();
|
||||||
|
}
|
||||||
dialog_message_set_text(bt->dialog_message, text, 64, 28, AlignCenter, AlignCenter);
|
dialog_message_set_text(bt->dialog_message, text, 64, 28, AlignCenter, AlignCenter);
|
||||||
dialog_message_set_buttons(bt->dialog_message, "Quit", NULL, NULL);
|
dialog_message_set_buttons(bt->dialog_message, "Quit", NULL, NULL);
|
||||||
dialog_message_show(bt->dialogs, bt->dialog_message);
|
dialog_message_show(bt->dialogs, bt->dialog_message);
|
||||||
@@ -309,18 +363,19 @@ void bt_open_rpc_connection(Bt* bt) {
|
|||||||
if(!bt->rpc_session && bt->status == BtStatusConnected) {
|
if(!bt->rpc_session && bt->status == BtStatusConnected) {
|
||||||
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
|
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
|
||||||
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||||
if(bt->profile == BtProfileSerial) {
|
if(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial)) {
|
||||||
// Open RPC session
|
// Open RPC session
|
||||||
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
|
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
|
||||||
if(bt->rpc_session) {
|
if(bt->rpc_session) {
|
||||||
FURI_LOG_I(TAG, "Open RPC connection");
|
FURI_LOG_I(TAG, "Open RPC connection");
|
||||||
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
|
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
|
||||||
rpc_session_set_buffer_is_empty_callback(
|
rpc_session_set_buffer_is_empty_callback(
|
||||||
bt->rpc_session, furi_hal_bt_serial_notify_buffer_is_empty);
|
bt->rpc_session, bt_serial_buffer_is_empty_callback);
|
||||||
rpc_session_set_context(bt->rpc_session, bt);
|
rpc_session_set_context(bt->rpc_session, bt);
|
||||||
furi_hal_bt_serial_set_event_callback(
|
ble_profile_serial_set_event_callback(
|
||||||
RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
|
bt->current_profile, RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
|
||||||
furi_hal_bt_serial_set_rpc_status(FuriHalBtSerialRpcStatusActive);
|
ble_profile_serial_set_rpc_active(
|
||||||
|
bt->current_profile, FuriHalBtSerialRpcStatusActive);
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
|
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
|
||||||
}
|
}
|
||||||
@@ -329,49 +384,51 @@ void bt_open_rpc_connection(Bt* bt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bt_close_rpc_connection(Bt* bt) {
|
void bt_close_rpc_connection(Bt* bt) {
|
||||||
if(bt->profile == BtProfileSerial && bt->rpc_session) {
|
if(furi_hal_bt_check_profile_type(bt->current_profile, ble_profile_serial) &&
|
||||||
|
bt->rpc_session) {
|
||||||
FURI_LOG_I(TAG, "Close RPC connection");
|
FURI_LOG_I(TAG, "Close RPC connection");
|
||||||
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||||
rpc_session_close(bt->rpc_session);
|
rpc_session_close(bt->rpc_session);
|
||||||
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
|
ble_profile_serial_set_event_callback(bt->current_profile, 0, NULL, NULL);
|
||||||
bt->rpc_session = NULL;
|
bt->rpc_session = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
static void bt_change_profile(Bt* bt, BtMessage* message) {
|
||||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
if(furi_hal_bt_is_gatt_gap_supported()) {
|
||||||
bt_close_rpc_connection(bt);
|
bt_close_rpc_connection(bt);
|
||||||
|
|
||||||
FuriHalBtProfile furi_profile;
|
|
||||||
if(message->data.profile == BtProfileHidKeyboard) {
|
|
||||||
furi_profile = FuriHalBtProfileHidKeyboard;
|
|
||||||
} else {
|
|
||||||
furi_profile = FuriHalBtProfileSerial;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_keys_storage_load(bt->keys_storage);
|
bt_keys_storage_load(bt->keys_storage);
|
||||||
|
|
||||||
if(furi_hal_bt_change_app(furi_profile, bt_on_gap_event_callback, bt)) {
|
bt->current_profile = furi_hal_bt_change_app(
|
||||||
|
message->data.profile.template,
|
||||||
|
message->data.profile.params,
|
||||||
|
bt_on_gap_event_callback,
|
||||||
|
bt);
|
||||||
|
if(bt->current_profile) {
|
||||||
FURI_LOG_I(TAG, "Bt App started");
|
FURI_LOG_I(TAG, "Bt App started");
|
||||||
if(bt->bt_settings.enabled) {
|
if(bt->bt_settings.enabled) {
|
||||||
furi_hal_bt_start_advertising();
|
furi_hal_bt_start_advertising();
|
||||||
}
|
}
|
||||||
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
|
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
|
||||||
bt->profile = message->data.profile;
|
|
||||||
if(message->result) {
|
|
||||||
*message->result = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_E(TAG, "Failed to start Bt App");
|
FURI_LOG_E(TAG, "Failed to start Bt App");
|
||||||
if(message->result) {
|
|
||||||
*message->result = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(message->profile_instance) {
|
||||||
|
*message->profile_instance = bt->current_profile;
|
||||||
|
}
|
||||||
|
if(message->result) {
|
||||||
|
*message->result = bt->current_profile != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bt_show_warning(bt, "Radio stack doesn't support this app");
|
bt_show_warning(bt, "Radio stack doesn't support this app");
|
||||||
if(message->result) {
|
if(message->result) {
|
||||||
*message->result = false;
|
*message->result = false;
|
||||||
}
|
}
|
||||||
|
if(message->profile_instance) {
|
||||||
|
*message->profile_instance = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(message->lock) api_lock_unlock(message->lock);
|
if(message->lock) api_lock_unlock(message->lock);
|
||||||
}
|
}
|
||||||
@@ -382,52 +439,6 @@ static void bt_close_connection(Bt* bt, BtMessage* message) {
|
|||||||
if(message->lock) api_lock_unlock(message->lock);
|
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) {
|
bool bt_remote_rssi(Bt* bt, uint8_t* rssi) {
|
||||||
furi_assert(bt);
|
furi_assert(bt);
|
||||||
|
|
||||||
@@ -441,27 +452,6 @@ bool bt_remote_rssi(Bt* bt, uint8_t* rssi) {
|
|||||||
return true;
|
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) {
|
int32_t bt_srv(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
Bt* bt = bt_alloc();
|
Bt* bt = bt_alloc();
|
||||||
@@ -483,8 +473,10 @@ int32_t bt_srv(void* p) {
|
|||||||
FURI_LOG_E(TAG, "Radio stack start failed");
|
FURI_LOG_E(TAG, "Radio stack start failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
if(furi_hal_bt_is_gatt_gap_supported()) {
|
||||||
if(!furi_hal_bt_start_app(FuriHalBtProfileSerial, bt_on_gap_event_callback, bt)) {
|
bt->current_profile =
|
||||||
|
furi_hal_bt_start_app(ble_profile_serial, NULL, bt_on_gap_event_callback, bt);
|
||||||
|
if(!bt->current_profile) {
|
||||||
FURI_LOG_E(TAG, "BLE App start failed");
|
FURI_LOG_E(TAG, "BLE App start failed");
|
||||||
} else {
|
} else {
|
||||||
if(bt->bt_settings.enabled) {
|
if(bt->bt_settings.enabled) {
|
||||||
@@ -514,7 +506,7 @@ int32_t bt_srv(void* p) {
|
|||||||
// Update battery level
|
// Update battery level
|
||||||
furi_hal_bt_update_battery_level(message.data.battery_level);
|
furi_hal_bt_update_battery_level(message.data.battery_level);
|
||||||
} else if(message.type == BtMessageTypeUpdatePowerState) {
|
} else if(message.type == BtMessageTypeUpdatePowerState) {
|
||||||
furi_hal_bt_update_power_state();
|
furi_hal_bt_update_power_state(message.data.power_state_charging);
|
||||||
} else if(message.type == BtMessageTypePinCodeShow) {
|
} else if(message.type == BtMessageTypePinCodeShow) {
|
||||||
// Display PIN code
|
// Display PIN code
|
||||||
bt_pin_code_show(bt, message.data.pin_code);
|
bt_pin_code_show(bt, message.data.pin_code);
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <furi_hal_bt.h>
|
#include <furi_ble/profile_interface.h>
|
||||||
|
#include <core/common_defines.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -19,11 +20,6 @@ typedef enum {
|
|||||||
BtStatusConnected,
|
BtStatusConnected,
|
||||||
} BtStatus;
|
} BtStatus;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BtProfileSerial,
|
|
||||||
BtProfileHidKeyboard,
|
|
||||||
} BtProfile;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t rssi;
|
uint8_t rssi;
|
||||||
uint32_t since;
|
uint32_t since;
|
||||||
@@ -34,12 +30,25 @@ typedef void (*BtStatusChangedCallback)(BtStatus status, void* context);
|
|||||||
/** Change BLE Profile
|
/** Change BLE Profile
|
||||||
* @note Call of this function leads to 2nd core restart
|
* @note Call of this function leads to 2nd core restart
|
||||||
*
|
*
|
||||||
* @param bt Bt instance
|
* @param bt Bt instance
|
||||||
* @param profile BtProfile
|
* @param profile_template Profile template to change to
|
||||||
|
* @param params Profile parameters. Can be NULL
|
||||||
*
|
*
|
||||||
* @return true on success
|
* @return true on success
|
||||||
*/
|
*/
|
||||||
bool bt_set_profile(Bt* bt, BtProfile profile);
|
FURI_WARN_UNUSED FuriHalBleProfileBase* bt_profile_start(
|
||||||
|
Bt* bt,
|
||||||
|
const FuriHalBleProfileTemplate* profile_template,
|
||||||
|
FuriHalBleProfileParams params);
|
||||||
|
|
||||||
|
/** Stop current BLE Profile and restore default profile
|
||||||
|
* @note Call of this function leads to 2nd core restart
|
||||||
|
*
|
||||||
|
* @param bt Bt instance
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool bt_profile_restore_default(Bt* bt);
|
||||||
|
|
||||||
/** Disconnect from Central
|
/** Disconnect from Central
|
||||||
*
|
*
|
||||||
@@ -75,30 +84,8 @@ void bt_keys_storage_set_storage_path(Bt* bt, const char* keys_storage_path);
|
|||||||
*/
|
*/
|
||||||
void bt_keys_storage_set_default_path(Bt* bt);
|
void bt_keys_storage_set_default_path(Bt* bt);
|
||||||
|
|
||||||
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);
|
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)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void bt_disable_peer_key_update(Bt* bt);
|
|
||||||
|
|
||||||
/** Enable saving peer key to internal flash (enable by default)
|
|
||||||
*
|
|
||||||
* @note This function should be called if bt_disable_peer_key_update was called before
|
|
||||||
*/
|
|
||||||
void bt_enable_peer_key_update(Bt* bt);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* (Probably bad) way of opening the RPC connection, everywhereTM
|
* (Probably bad) way of opening the RPC connection, everywhereTM
|
||||||
|
|||||||
@@ -1,21 +1,34 @@
|
|||||||
#include "bt_i.h"
|
#include "bt_i.h"
|
||||||
|
#include <profiles/serial_profile.h>
|
||||||
|
|
||||||
bool bt_set_profile(Bt* bt, BtProfile profile) {
|
FuriHalBleProfileBase* bt_profile_start(
|
||||||
|
Bt* bt,
|
||||||
|
const FuriHalBleProfileTemplate* profile_template,
|
||||||
|
FuriHalBleProfileParams params) {
|
||||||
furi_assert(bt);
|
furi_assert(bt);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
bool result = false;
|
FuriHalBleProfileBase* profile_instance = NULL;
|
||||||
|
|
||||||
BtMessage message = {
|
BtMessage message = {
|
||||||
.lock = api_lock_alloc_locked(),
|
.lock = api_lock_alloc_locked(),
|
||||||
.type = BtMessageTypeSetProfile,
|
.type = BtMessageTypeSetProfile,
|
||||||
.data.profile = profile,
|
.profile_instance = &profile_instance,
|
||||||
.result = &result};
|
.data.profile.params = params,
|
||||||
|
.data.profile.template = profile_template,
|
||||||
|
};
|
||||||
furi_check(
|
furi_check(
|
||||||
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
|
||||||
// Wait for unlock
|
// Wait for unlock
|
||||||
api_lock_wait_unlock_and_free(message.lock);
|
api_lock_wait_unlock_and_free(message.lock);
|
||||||
|
|
||||||
return result;
|
bt->current_profile = profile_instance;
|
||||||
|
return profile_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bt_profile_restore_default(Bt* bt) {
|
||||||
|
bt->current_profile = bt_profile_start(bt, ble_profile_serial, NULL);
|
||||||
|
return bt->current_profile != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disconnect(Bt* bt) {
|
void bt_disconnect(Bt* bt) {
|
||||||
|
|||||||
@@ -41,7 +41,12 @@ typedef struct {
|
|||||||
typedef union {
|
typedef union {
|
||||||
uint32_t pin_code;
|
uint32_t pin_code;
|
||||||
uint8_t battery_level;
|
uint8_t battery_level;
|
||||||
BtProfile profile;
|
bool power_state_charging;
|
||||||
|
struct {
|
||||||
|
const FuriHalBleProfileTemplate* template;
|
||||||
|
FuriHalBleProfileParams params;
|
||||||
|
} profile;
|
||||||
|
FuriHalBleProfileParams profile_params;
|
||||||
BtKeyStorageUpdateData key_storage_data;
|
BtKeyStorageUpdateData key_storage_data;
|
||||||
} BtMessageData;
|
} BtMessageData;
|
||||||
|
|
||||||
@@ -50,6 +55,7 @@ typedef struct {
|
|||||||
BtMessageType type;
|
BtMessageType type;
|
||||||
BtMessageData data;
|
BtMessageData data;
|
||||||
bool* result;
|
bool* result;
|
||||||
|
FuriHalBleProfileBase** profile_instance;
|
||||||
} BtMessage;
|
} BtMessage;
|
||||||
|
|
||||||
struct Bt {
|
struct Bt {
|
||||||
@@ -59,7 +65,8 @@ struct Bt {
|
|||||||
BtSettings bt_settings;
|
BtSettings bt_settings;
|
||||||
BtKeysStorage* keys_storage;
|
BtKeysStorage* keys_storage;
|
||||||
BtStatus status;
|
BtStatus status;
|
||||||
BtProfile profile;
|
bool beacon_active;
|
||||||
|
FuriHalBleProfileBase* current_profile;
|
||||||
FuriMessageQueue* message_queue;
|
FuriMessageQueue* message_queue;
|
||||||
NotificationApp* notification;
|
NotificationApp* notification;
|
||||||
Gui* gui;
|
Gui* gui;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "cli_command_gpio.h"
|
#include "cli_command_gpio.h"
|
||||||
|
|
||||||
#include "core/string.h"
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <lib/toolbox/args.h>
|
#include <lib/toolbox/args.h>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "cli_commands.h"
|
#include "cli_commands.h"
|
||||||
#include "cli_command_gpio.h"
|
#include "cli_command_gpio.h"
|
||||||
|
|
||||||
|
#include <core/thread.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <furi_hal_info.h>
|
#include <furi_hal_info.h>
|
||||||
#include <task_control_block.h>
|
#include <task_control_block.h>
|
||||||
@@ -398,27 +399,30 @@ void cli_command_ps(Cli* cli, FuriString* args, void* context) {
|
|||||||
|
|
||||||
const uint8_t threads_num_max = 32;
|
const uint8_t threads_num_max = 32;
|
||||||
FuriThreadId threads_ids[threads_num_max];
|
FuriThreadId threads_ids[threads_num_max];
|
||||||
uint8_t thread_num = furi_thread_enumerate(threads_ids, threads_num_max);
|
uint32_t thread_num = furi_thread_enumerate(threads_ids, threads_num_max);
|
||||||
printf(
|
printf(
|
||||||
"%-20s %-20s %-14s %-8s %-8s %s\r\n",
|
"%-17s %-20s %-5s %-13s %-6s %-8s %s\r\n",
|
||||||
"AppID",
|
"AppID",
|
||||||
"Name",
|
"Name",
|
||||||
|
"Prio",
|
||||||
"Stack start",
|
"Stack start",
|
||||||
"Heap",
|
"Heap",
|
||||||
"Stack",
|
"Stack",
|
||||||
"Stack min free");
|
"Stack min free");
|
||||||
for(uint8_t i = 0; i < thread_num; i++) {
|
for(uint8_t i = 0; i < thread_num; i++) {
|
||||||
TaskControlBlock* tcb = (TaskControlBlock*)threads_ids[i];
|
TaskControlBlock* tcb = (TaskControlBlock*)threads_ids[i];
|
||||||
|
size_t thread_heap = memmgr_heap_get_thread_memory(threads_ids[i]);
|
||||||
printf(
|
printf(
|
||||||
"%-20s %-20s 0x%-12lx %-8zu %-8lu %-8lu\r\n",
|
"%-17s %-20s %-5d 0x%-11lx %-6zu %-8lu %-8lu\r\n",
|
||||||
furi_thread_get_appid(threads_ids[i]),
|
furi_thread_get_appid(threads_ids[i]),
|
||||||
furi_thread_get_name(threads_ids[i]),
|
furi_thread_get_name(threads_ids[i]),
|
||||||
|
furi_thread_get_priority(threads_ids[i]),
|
||||||
(uint32_t)tcb->pxStack,
|
(uint32_t)tcb->pxStack,
|
||||||
memmgr_heap_get_thread_memory(threads_ids[i]),
|
thread_heap == MEMMGR_HEAP_UNKNOWN ? 0u : thread_heap,
|
||||||
(uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(StackType_t),
|
(uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(StackType_t),
|
||||||
furi_thread_get_stack_space(threads_ids[i]));
|
furi_thread_get_stack_space(threads_ids[i]));
|
||||||
}
|
}
|
||||||
printf("\r\nTotal: %d", thread_num);
|
printf("\r\nTotal: %lu", thread_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cli_command_free(Cli* cli, FuriString* args, void* context) {
|
void cli_command_free(Cli* cli, FuriString* args, void* context) {
|
||||||
|
|||||||
@@ -4,10 +4,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../widget.h"
|
||||||
|
#include "widget_element.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
#include <input/input.h>
|
#include <input/input.h>
|
||||||
#include "widget_element.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "core/core_defines.h"
|
|
||||||
#include "loader_i.h"
|
#include "loader_i.h"
|
||||||
#include <applications.h>
|
#include <applications.h>
|
||||||
#include <storage/storage.h>
|
#include <storage/storage.h>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "profiles/serial_profile.h"
|
||||||
#include "rpc_i.h"
|
#include "rpc_i.h"
|
||||||
|
|
||||||
#include <pb.h>
|
#include <pb.h>
|
||||||
@@ -334,7 +335,7 @@ static int32_t rpc_session_worker(void* context) {
|
|||||||
// Disconnect BLE session
|
// Disconnect BLE session
|
||||||
FURI_LOG_E("RPC", "BLE session closed due to a decode error");
|
FURI_LOG_E("RPC", "BLE session closed due to a decode error");
|
||||||
Bt* bt = furi_record_open(RECORD_BT);
|
Bt* bt = furi_record_open(RECORD_BT);
|
||||||
bt_set_profile(bt, BtProfileSerial);
|
bt_profile_restore_default(bt);
|
||||||
furi_record_close(RECORD_BT);
|
furi_record_close(RECORD_BT);
|
||||||
FURI_LOG_E("RPC", "Finished disconnecting the BLE session");
|
FURI_LOG_E("RPC", "Finished disconnecting the BLE session");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ void rpc_session_set_send_bytes_callback(RpcSession* session, RpcSendBytesCallba
|
|||||||
*
|
*
|
||||||
* @param session pointer to RpcSession descriptor
|
* @param session pointer to RpcSession descriptor
|
||||||
* @param callback callback to notify client that buffer is empty (can be NULL)
|
* @param callback callback to notify client that buffer is empty (can be NULL)
|
||||||
|
* @param context context to pass to callback
|
||||||
*/
|
*/
|
||||||
void rpc_session_set_buffer_is_empty_callback(
|
void rpc_session_set_buffer_is_empty_callback(
|
||||||
RpcSession* session,
|
RpcSession* session,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void bt_settings_scene_start_on_enter(void* context) {
|
|||||||
VariableItemList* var_item_list = app->var_item_list;
|
VariableItemList* var_item_list = app->var_item_list;
|
||||||
VariableItem* item;
|
VariableItem* item;
|
||||||
|
|
||||||
if(furi_hal_bt_is_ble_gatt_gap_supported()) {
|
if(furi_hal_bt_is_gatt_gap_supported()) {
|
||||||
item = variable_item_list_add(
|
item = variable_item_list_add(
|
||||||
var_item_list,
|
var_item_list,
|
||||||
"Bluetooth",
|
"Bluetooth",
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ App(
|
|||||||
apptype=FlipperAppType.EXTERNAL,
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
entry_point="hid_usb_app",
|
entry_point="hid_usb_app",
|
||||||
stack_size=1 * 1024,
|
stack_size=1 * 1024,
|
||||||
|
sources=["*.c", "!transport_ble.c"],
|
||||||
|
cdefines=["HID_TRANSPORT_USB"],
|
||||||
|
fap_description="Use Flipper as a HID remote control over USB",
|
||||||
|
fap_version="1.0",
|
||||||
fap_category="USB",
|
fap_category="USB",
|
||||||
fap_icon="hid_usb_10px.png",
|
fap_icon="hid_usb_10px.png",
|
||||||
fap_icon_assets="assets",
|
fap_icon_assets="assets",
|
||||||
@@ -17,6 +21,11 @@ App(
|
|||||||
apptype=FlipperAppType.EXTERNAL,
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
entry_point="hid_ble_app",
|
entry_point="hid_ble_app",
|
||||||
stack_size=1 * 1024,
|
stack_size=1 * 1024,
|
||||||
|
sources=["*.c", "!transport_usb.c"],
|
||||||
|
cdefines=["HID_TRANSPORT_BLE"],
|
||||||
|
fap_libs=["ble_profile"],
|
||||||
|
fap_description="Use Flipper as a HID remote control over Bluetooth",
|
||||||
|
fap_version="1.0",
|
||||||
fap_category="Bluetooth",
|
fap_category="Bluetooth",
|
||||||
fap_icon="hid_ble_10px.png",
|
fap_icon="hid_ble_10px.png",
|
||||||
fap_icon_assets="assets",
|
fap_icon_assets="assets",
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
|
#include <extra_profiles/hid_profile.h>
|
||||||
|
#include <profiles/serial_profile.h>
|
||||||
#include "views.h"
|
#include "views.h"
|
||||||
#include <notification/notification_messages.h>
|
#include <notification/notification_messages.h>
|
||||||
#include <dolphin/dolphin.h>
|
#include <dolphin/dolphin.h>
|
||||||
@@ -18,8 +20,22 @@ enum HidDebugSubmenuIndex {
|
|||||||
HidSubmenuIndexMouseClicker,
|
HidSubmenuIndexMouseClicker,
|
||||||
HidSubmenuIndexMouseJiggler,
|
HidSubmenuIndexMouseJiggler,
|
||||||
HidSubmenuIndexPushToTalk,
|
HidSubmenuIndexPushToTalk,
|
||||||
|
HidSubmenuIndexRemovePairing,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void bt_hid_remove_pairing(Bt* bt) {
|
||||||
|
bt_disconnect(bt);
|
||||||
|
|
||||||
|
// Wait 2nd core to update nvm storage
|
||||||
|
furi_delay_ms(200);
|
||||||
|
|
||||||
|
furi_hal_bt_stop_advertising();
|
||||||
|
|
||||||
|
bt_forget_bonded_devices(bt);
|
||||||
|
|
||||||
|
furi_hal_bt_start_advertising();
|
||||||
|
}
|
||||||
|
|
||||||
static void hid_submenu_callback(void* context, uint32_t index) {
|
static void hid_submenu_callback(void* context, uint32_t index) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Hid* app = context;
|
Hid* app = context;
|
||||||
@@ -61,6 +77,8 @@ static void hid_submenu_callback(void* context, uint32_t index) {
|
|||||||
} else if(index == HidSubmenuIndexPushToTalk) {
|
} else if(index == HidSubmenuIndexPushToTalk) {
|
||||||
app->view_id = HidViewPushToTalkMenu;
|
app->view_id = HidViewPushToTalkMenu;
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewPushToTalkMenu);
|
view_dispatcher_switch_to_view(app->view_dispatcher, HidViewPushToTalkMenu);
|
||||||
|
} else if(index == HidSubmenuIndexRemovePairing) {
|
||||||
|
bt_hid_remove_pairing(app->bt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,13 +86,13 @@ static void bt_hid_connection_status_changed_callback(BtStatus status, void* con
|
|||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Hid* hid = context;
|
Hid* hid = context;
|
||||||
bool connected = (status == BtStatusConnected);
|
bool connected = (status == BtStatusConnected);
|
||||||
if(hid->transport == HidTransportBle) {
|
#ifdef HID_TRANSPORT_BLE
|
||||||
if(connected) {
|
if(connected) {
|
||||||
notification_internal_message(hid->notifications, &sequence_set_blue_255);
|
notification_internal_message(hid->notifications, &sequence_set_blue_255);
|
||||||
} else {
|
} else {
|
||||||
notification_internal_message(hid->notifications, &sequence_reset_blue);
|
notification_internal_message(hid->notifications, &sequence_reset_blue);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
hid_keynote_set_connected_status(hid->hid_keynote, connected);
|
hid_keynote_set_connected_status(hid->hid_keynote, connected);
|
||||||
hid_keyboard_set_connected_status(hid->hid_keyboard, connected);
|
hid_keyboard_set_connected_status(hid->hid_keyboard, connected);
|
||||||
hid_numpad_set_connected_status(hid->hid_numpad, connected);
|
hid_numpad_set_connected_status(hid->hid_numpad, connected);
|
||||||
@@ -103,9 +121,8 @@ static uint32_t hid_ptt_menu_view(void* context) {
|
|||||||
return HidViewPushToTalkMenu;
|
return HidViewPushToTalkMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hid* hid_alloc(HidTransport transport) {
|
Hid* hid_alloc() {
|
||||||
Hid* app = malloc(sizeof(Hid));
|
Hid* app = malloc(sizeof(Hid));
|
||||||
app->transport = transport;
|
|
||||||
|
|
||||||
// Gui
|
// Gui
|
||||||
app->gui = furi_record_open(RECORD_GUI);
|
app->gui = furi_record_open(RECORD_GUI);
|
||||||
@@ -146,14 +163,12 @@ Hid* hid_alloc(HidTransport transport) {
|
|||||||
app->device_type_submenu, "Movie", HidSubmenuIndexMovie, hid_submenu_callback, app);
|
app->device_type_submenu, "Movie", HidSubmenuIndexMovie, hid_submenu_callback, app);
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
app->device_type_submenu, "Mouse", HidSubmenuIndexMouse, hid_submenu_callback, app);
|
app->device_type_submenu, "Mouse", HidSubmenuIndexMouse, hid_submenu_callback, app);
|
||||||
if(app->transport == HidTransportBle) {
|
submenu_add_item(
|
||||||
submenu_add_item(
|
app->device_type_submenu,
|
||||||
app->device_type_submenu,
|
"TikTok / YT Shorts",
|
||||||
"TikTok / YT Shorts",
|
HidSubmenuIndexTikShorts,
|
||||||
HidSubmenuIndexTikShorts,
|
hid_submenu_callback,
|
||||||
hid_submenu_callback,
|
app);
|
||||||
app);
|
|
||||||
}
|
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
app->device_type_submenu,
|
app->device_type_submenu,
|
||||||
"Mouse Clicker",
|
"Mouse Clicker",
|
||||||
@@ -172,6 +187,14 @@ Hid* hid_alloc(HidTransport transport) {
|
|||||||
HidSubmenuIndexPushToTalk,
|
HidSubmenuIndexPushToTalk,
|
||||||
hid_submenu_callback,
|
hid_submenu_callback,
|
||||||
app);
|
app);
|
||||||
|
#ifdef HID_TRANSPORT_BLE
|
||||||
|
submenu_add_item(
|
||||||
|
app->device_type_submenu,
|
||||||
|
"Remove Pairing",
|
||||||
|
HidSubmenuIndexRemovePairing,
|
||||||
|
hid_submenu_callback,
|
||||||
|
app);
|
||||||
|
#endif
|
||||||
view_set_previous_callback(submenu_get_view(app->device_type_submenu), hid_exit);
|
view_set_previous_callback(submenu_get_view(app->device_type_submenu), hid_exit);
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->device_type_submenu));
|
app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->device_type_submenu));
|
||||||
@@ -265,10 +288,9 @@ void hid_free(Hid* app) {
|
|||||||
furi_assert(app);
|
furi_assert(app);
|
||||||
|
|
||||||
// Reset notification
|
// Reset notification
|
||||||
if(app->transport == HidTransportBle) {
|
#ifdef HID_TRANSPORT_BLE
|
||||||
notification_internal_message(app->notifications, &sequence_reset_blue);
|
notification_internal_message(app->notifications, &sequence_reset_blue);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
// Free views
|
// Free views
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewSubmenu);
|
view_dispatcher_remove_view(app->view_dispatcher, HidViewSubmenu);
|
||||||
submenu_free(app->device_type_submenu);
|
submenu_free(app->device_type_submenu);
|
||||||
@@ -310,131 +332,9 @@ void hid_free(Hid* app) {
|
|||||||
free(app);
|
free(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_kb_press(event);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_kb_press(event);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_kb_release(event);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_kb_release(event);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_keyboard_release_all(Hid* instance) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_kb_release_all();
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_kb_release_all();
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_consumer_key_press(event);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_consumer_key_press(event);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_consumer_key_release(event);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_consumer_key_release(event);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_consumer_key_release_all(Hid* instance) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_consumer_key_release_all();
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_kb_release_all();
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_mouse_move(dx, dy);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_mouse_move(dx, dy);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_mouse_scroll(delta);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_mouse_scroll(delta);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_mouse_press(Hid* instance, uint16_t event) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_mouse_press(event);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_mouse_press(event);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_mouse_release(Hid* instance, uint16_t event) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_mouse_release(event);
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_mouse_release(event);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void hid_hal_mouse_release_all(Hid* instance) {
|
|
||||||
furi_assert(instance);
|
|
||||||
if(instance->transport == HidTransportBle) {
|
|
||||||
furi_hal_bt_hid_mouse_release_all();
|
|
||||||
} else if(instance->transport == HidTransportUsb) {
|
|
||||||
furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT);
|
|
||||||
furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT);
|
|
||||||
} else {
|
|
||||||
furi_crash();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t hid_usb_app(void* p) {
|
int32_t hid_usb_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
Hid* app = hid_alloc(HidTransportUsb);
|
Hid* app = hid_alloc();
|
||||||
app = hid_app_alloc_view(app);
|
app = hid_app_alloc_view(app);
|
||||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||||
furi_hal_usb_unlock();
|
furi_hal_usb_unlock();
|
||||||
@@ -455,7 +355,7 @@ int32_t hid_usb_app(void* p) {
|
|||||||
|
|
||||||
int32_t hid_ble_app(void* p) {
|
int32_t hid_ble_app(void* p) {
|
||||||
UNUSED(p);
|
UNUSED(p);
|
||||||
Hid* app = hid_alloc(HidTransportBle);
|
Hid* app = hid_alloc();
|
||||||
app = hid_app_alloc_view(app);
|
app = hid_app_alloc_view(app);
|
||||||
|
|
||||||
bt_disconnect(app->bt);
|
bt_disconnect(app->bt);
|
||||||
@@ -475,7 +375,9 @@ int32_t hid_ble_app(void* p) {
|
|||||||
|
|
||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
furi_check(bt_set_profile(app->bt, BtProfileHidKeyboard));
|
app->ble_hid_profile = bt_profile_start(app->bt, ble_profile_hid, NULL);
|
||||||
|
|
||||||
|
furi_check(app->ble_hid_profile);
|
||||||
|
|
||||||
furi_hal_bt_start_advertising();
|
furi_hal_bt_start_advertising();
|
||||||
bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app);
|
bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app);
|
||||||
@@ -493,7 +395,7 @@ int32_t hid_ble_app(void* p) {
|
|||||||
|
|
||||||
bt_keys_storage_set_default_path(app->bt);
|
bt_keys_storage_set_default_path(app->bt);
|
||||||
|
|
||||||
furi_check(bt_set_profile(app->bt, BtProfileSerial));
|
furi_check(bt_profile_restore_default(app->bt));
|
||||||
|
|
||||||
hid_free(app);
|
hid_free(app);
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal_bt.h>
|
#include <furi_hal_bt.h>
|
||||||
#include <furi_hal_bt_hid.h>
|
|
||||||
#include <furi_hal_usb.h>
|
#include <furi_hal_usb.h>
|
||||||
#include <furi_hal_usb_hid.h>
|
#include <furi_hal_usb_hid.h>
|
||||||
|
|
||||||
|
#include <extra_profiles/hid_profile.h>
|
||||||
|
|
||||||
#include <bt/bt_service/bt.h>
|
#include <bt/bt_service/bt.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <gui/view.h>
|
#include <gui/view.h>
|
||||||
@@ -40,6 +41,7 @@ typedef enum {
|
|||||||
typedef struct Hid Hid;
|
typedef struct Hid Hid;
|
||||||
|
|
||||||
struct Hid {
|
struct Hid {
|
||||||
|
FuriHalBleProfileBase* ble_hid_profile;
|
||||||
Bt* bt;
|
Bt* bt;
|
||||||
Gui* gui;
|
Gui* gui;
|
||||||
NotificationApp* notifications;
|
NotificationApp* notifications;
|
||||||
|
|||||||
60
applications/system/hid_app/transport_ble.c
Normal file
60
applications/system/hid_app/transport_ble.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "hid.h"
|
||||||
|
|
||||||
|
#ifndef HID_TRANSPORT_BLE
|
||||||
|
#error "HID_TRANSPORT_BLE must be defined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_kb_press(instance->ble_hid_profile, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_kb_release(instance->ble_hid_profile, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_keyboard_release_all(Hid* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_kb_release_all(instance->ble_hid_profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_consumer_key_press(instance->ble_hid_profile, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_consumer_key_release(instance->ble_hid_profile, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_consumer_key_release_all(Hid* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_consumer_key_release_all(instance->ble_hid_profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_mouse_move(instance->ble_hid_profile, dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_mouse_scroll(instance->ble_hid_profile, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_press(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_mouse_press(instance->ble_hid_profile, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_release(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_mouse_release(instance->ble_hid_profile, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_release_all(Hid* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
ble_profile_hid_mouse_release_all(instance->ble_hid_profile);
|
||||||
|
}
|
||||||
61
applications/system/hid_app/transport_usb.c
Normal file
61
applications/system/hid_app/transport_usb.c
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include "hid.h"
|
||||||
|
|
||||||
|
#ifndef HID_TRANSPORT_USB
|
||||||
|
#error "HID_TRANSPORT_USB must be defined"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void hid_hal_keyboard_press(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_kb_press(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_keyboard_release(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_kb_release(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_keyboard_release_all(Hid* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_kb_release_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_consumer_key_press(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_consumer_key_press(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_consumer_key_release(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_consumer_key_release(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_consumer_key_release_all(Hid* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_kb_release_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_mouse_move(dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_scroll(Hid* instance, int8_t delta) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_mouse_scroll(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_press(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_mouse_press(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_release(Hid* instance, uint16_t event) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_mouse_release(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_hal_mouse_release_all(Hid* instance) {
|
||||||
|
furi_assert(instance);
|
||||||
|
furi_hal_hid_mouse_release(HID_MOUSE_BTN_LEFT);
|
||||||
|
furi_hal_hid_mouse_release(HID_MOUSE_BTN_RIGHT);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "hid_media.h"
|
#include "hid_media.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal_bt_hid.h>
|
|
||||||
#include <furi_hal_usb_hid.h>
|
#include <furi_hal_usb_hid.h>
|
||||||
|
#include <extra_profiles/hid_profile.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include "../hid.h"
|
#include "../hid.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "hid_movie.h"
|
#include "hid_movie.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal_bt_hid.h>
|
|
||||||
#include <furi_hal_usb_hid.h>
|
#include <furi_hal_usb_hid.h>
|
||||||
|
#include <extra_profiles/hid_profile.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include "../hid.h"
|
#include "../hid.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "hid_music_macos.h"
|
#include "hid_music_macos.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal_bt_hid.h>
|
|
||||||
#include <furi_hal_usb_hid.h>
|
#include <furi_hal_usb_hid.h>
|
||||||
|
#include <extra_profiles/hid_profile.h>
|
||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include "../hid.h"
|
#include "../hid.h"
|
||||||
|
|
||||||
|
|||||||
BIN
assets/icons/StatusBar/BLE_beacon_7x8.png
Normal file
BIN
assets/icons/StatusBar/BLE_beacon_7x8.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 117 B |
@@ -139,8 +139,12 @@ for app_dir, _ in fwenv["APPDIRS"]:
|
|||||||
|
|
||||||
fwenv.PrepareApplicationsBuild()
|
fwenv.PrepareApplicationsBuild()
|
||||||
|
|
||||||
|
|
||||||
# Build external apps + configure SDK
|
# Build external apps + configure SDK
|
||||||
if env["IS_BASE_FIRMWARE"]:
|
if env["IS_BASE_FIRMWARE"]:
|
||||||
|
# Ensure all libs are built - even if they are not used in firmware
|
||||||
|
fw_artifacts.append(fwenv["LIB_DIST_DIR"].glob("*.a"))
|
||||||
|
|
||||||
fwenv.SetDefault(FBT_FAP_DEBUG_ELF_ROOT=fwenv["BUILD_DIR"].Dir(".extapps"))
|
fwenv.SetDefault(FBT_FAP_DEBUG_ELF_ROOT=fwenv["BUILD_DIR"].Dir(".extapps"))
|
||||||
fw_extapps = fwenv["FW_EXTAPPS"] = SConscript(
|
fw_extapps = fwenv["FW_EXTAPPS"] = SConscript(
|
||||||
"site_scons/extapps.scons",
|
"site_scons/extapps.scons",
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ static void __furi_print_stack_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void __furi_print_bt_stack_info() {
|
static void __furi_print_bt_stack_info() {
|
||||||
const FuriHalBtHardfaultInfo* fault_info = furi_hal_bt_get_hardfault_info();
|
const BleGlueHardfaultInfo* fault_info = ble_glue_get_hardfault_info();
|
||||||
if(fault_info == NULL) {
|
if(fault_info == NULL) {
|
||||||
furi_log_puts("\r\n\tcore2: not faulted");
|
furi_log_puts("\r\n\tcore2: not faulted");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <furi_hal_rtc.h>
|
#include <furi_hal_rtc.h>
|
||||||
|
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <task.h>
|
#include <task.h>
|
||||||
|
|
||||||
#define TAG "FuriThread"
|
#define TAG "FuriThread"
|
||||||
@@ -191,6 +192,12 @@ void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority) {
|
|||||||
thread->priority = priority;
|
thread->priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FuriThreadPriority furi_thread_get_priority(FuriThread* thread) {
|
||||||
|
furi_assert(thread);
|
||||||
|
TaskHandle_t hTask = furi_thread_get_id(thread);
|
||||||
|
return (FuriThreadPriority)uxTaskPriorityGet(hTask);
|
||||||
|
}
|
||||||
|
|
||||||
void furi_thread_set_current_priority(FuriThreadPriority priority) {
|
void furi_thread_set_current_priority(FuriThreadPriority priority) {
|
||||||
UBaseType_t new_priority = priority ? priority : FuriThreadPriorityNormal;
|
UBaseType_t new_priority = priority ? priority : FuriThreadPriorityNormal;
|
||||||
vTaskPrioritySet(NULL, new_priority);
|
vTaskPrioritySet(NULL, new_priority);
|
||||||
@@ -465,22 +472,23 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo
|
|||||||
return (rflags);
|
return (rflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_items) {
|
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_item_count) {
|
||||||
uint32_t i, count;
|
uint32_t i, count;
|
||||||
TaskStatus_t* task;
|
TaskStatus_t* task;
|
||||||
|
|
||||||
if(FURI_IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U)) {
|
if(FURI_IS_IRQ_MODE() || (thread_array == NULL) || (array_item_count == 0U)) {
|
||||||
count = 0U;
|
count = 0U;
|
||||||
} else {
|
} else {
|
||||||
vTaskSuspendAll();
|
vTaskSuspendAll();
|
||||||
|
|
||||||
count = uxTaskGetNumberOfTasks();
|
count = uxTaskGetNumberOfTasks();
|
||||||
task = pvPortMalloc(count * sizeof(TaskStatus_t));
|
task = pvPortMalloc(count * sizeof(TaskStatus_t));
|
||||||
|
configRUN_TIME_COUNTER_TYPE total_run_time;
|
||||||
|
|
||||||
if(task != NULL) {
|
if(task != NULL) {
|
||||||
count = uxTaskGetSystemState(task, count, NULL);
|
count = uxTaskGetSystemState(task, count, &total_run_time);
|
||||||
|
|
||||||
for(i = 0U; (i < count) && (i < array_items); i++) {
|
for(i = 0U; (i < count) && (i < array_item_count); i++) {
|
||||||
thread_array[i] = (FuriThreadId)task[i].xHandle;
|
thread_array[i] = (FuriThreadId)task[i].xHandle;
|
||||||
}
|
}
|
||||||
count = i;
|
count = i;
|
||||||
|
|||||||
@@ -138,6 +138,13 @@ void furi_thread_set_context(FuriThread* thread, void* context);
|
|||||||
*/
|
*/
|
||||||
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority);
|
void furi_thread_set_priority(FuriThread* thread, FuriThreadPriority priority);
|
||||||
|
|
||||||
|
/** Get FuriThread priority
|
||||||
|
*
|
||||||
|
* @param thread FuriThread instance
|
||||||
|
* @return FuriThreadPriority value
|
||||||
|
*/
|
||||||
|
FuriThreadPriority furi_thread_get_priority(FuriThread* thread);
|
||||||
|
|
||||||
/** Set current thread priority
|
/** Set current thread priority
|
||||||
*
|
*
|
||||||
* @param priority FuriThreadPriority value
|
* @param priority FuriThreadPriority value
|
||||||
@@ -259,7 +266,7 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo
|
|||||||
* @param array_items array size
|
* @param array_items array size
|
||||||
* @return uint32_t threads count
|
* @return uint32_t threads count
|
||||||
*/
|
*/
|
||||||
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_items);
|
uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_item_count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get thread name
|
* @brief Get thread name
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ libs = env.BuildModules(
|
|||||||
"update_util",
|
"update_util",
|
||||||
"xtreme",
|
"xtreme",
|
||||||
"heatshrink",
|
"heatshrink",
|
||||||
|
"ble_profile",
|
||||||
"bit_lib",
|
"bit_lib",
|
||||||
"datetime",
|
"datetime",
|
||||||
],
|
],
|
||||||
|
|||||||
27
lib/ble_profile/SConscript
Normal file
27
lib/ble_profile/SConscript
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
Import("env")
|
||||||
|
|
||||||
|
env.Append(
|
||||||
|
CPPPATH=[
|
||||||
|
"#/lib/ble_profile",
|
||||||
|
],
|
||||||
|
SDK_HEADERS=[
|
||||||
|
File("extra_profiles/hid_profile.h"),
|
||||||
|
File("extra_services/hid_service.h"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
libenv = env.Clone(FW_LIB_NAME="ble_profile")
|
||||||
|
libenv.AppendUnique(
|
||||||
|
CCFLAGS=[
|
||||||
|
# Required for lib to be linkable with .faps
|
||||||
|
"-mword-relocations",
|
||||||
|
"-mlong-calls",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
libenv.ApplyLibFlags()
|
||||||
|
|
||||||
|
sources = libenv.GlobRecursive("*.c")
|
||||||
|
|
||||||
|
lib = libenv.StaticLibrary("${FW_LIB_NAME}", sources)
|
||||||
|
libenv.Install("${LIB_DIST_DIR}", lib)
|
||||||
|
Return("lib")
|
||||||
427
lib/ble_profile/extra_profiles/hid_profile.c
Normal file
427
lib/ble_profile/extra_profiles/hid_profile.c
Normal file
@@ -0,0 +1,427 @@
|
|||||||
|
#include "hid_profile.h"
|
||||||
|
|
||||||
|
#include <furi_hal_usb_hid.h>
|
||||||
|
#include <services/dev_info_service.h>
|
||||||
|
#include <services/battery_service.h>
|
||||||
|
#include <extra_services/hid_service.h>
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <usb_hid.h>
|
||||||
|
#include <ble/ble.h>
|
||||||
|
|
||||||
|
#define HID_INFO_BASE_USB_SPECIFICATION (0x0101)
|
||||||
|
#define HID_INFO_COUNTRY_CODE (0x00)
|
||||||
|
#define BLE_PROFILE_HID_INFO_FLAG_REMOTE_WAKE_MSK (0x01)
|
||||||
|
#define BLE_PROFILE_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK (0x02)
|
||||||
|
|
||||||
|
#define BLE_PROFILE_HID_KB_MAX_KEYS (6)
|
||||||
|
#define BLE_PROFILE_CONSUMER_MAX_KEYS (1)
|
||||||
|
|
||||||
|
// Report ids cant be 0
|
||||||
|
enum HidReportId {
|
||||||
|
ReportIdKeyboard = 1,
|
||||||
|
ReportIdMouse = 2,
|
||||||
|
ReportIdConsumer = 3,
|
||||||
|
};
|
||||||
|
// Report numbers corresponded to the report id with an offset of 1
|
||||||
|
enum HidInputNumber {
|
||||||
|
ReportNumberKeyboard = 0,
|
||||||
|
ReportNumberMouse = 1,
|
||||||
|
ReportNumberConsumer = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t mods;
|
||||||
|
uint8_t reserved;
|
||||||
|
uint8_t key[BLE_PROFILE_HID_KB_MAX_KEYS];
|
||||||
|
} FURI_PACKED FuriHalBtHidKbReport;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t btn;
|
||||||
|
int8_t x;
|
||||||
|
int8_t y;
|
||||||
|
int8_t wheel;
|
||||||
|
} FURI_PACKED FuriHalBtHidMouseReport;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t key[BLE_PROFILE_CONSUMER_MAX_KEYS];
|
||||||
|
} FURI_PACKED FuriHalBtHidConsumerReport;
|
||||||
|
|
||||||
|
// keyboard+mouse+consumer hid report
|
||||||
|
static const uint8_t ble_profile_hid_report_map_data[] = {
|
||||||
|
// Keyboard Report
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||||
|
HID_USAGE(HID_DESKTOP_KEYBOARD),
|
||||||
|
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||||
|
HID_REPORT_ID(ReportIdKeyboard),
|
||||||
|
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||||
|
HID_USAGE_MINIMUM(HID_KEYBOARD_L_CTRL),
|
||||||
|
HID_USAGE_MAXIMUM(HID_KEYBOARD_R_GUI),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_LOGICAL_MAXIMUM(1),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_REPORT_COUNT(8),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_REPORT_COUNT(1),
|
||||||
|
HID_REPORT_SIZE(8),
|
||||||
|
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_LED),
|
||||||
|
HID_REPORT_COUNT(8),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_USAGE_MINIMUM(1),
|
||||||
|
HID_USAGE_MAXIMUM(8),
|
||||||
|
HID_OUTPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_REPORT_COUNT(BLE_PROFILE_HID_KB_MAX_KEYS),
|
||||||
|
HID_REPORT_SIZE(8),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_LOGICAL_MAXIMUM(101),
|
||||||
|
HID_USAGE_PAGE(HID_DESKTOP_KEYPAD),
|
||||||
|
HID_USAGE_MINIMUM(0),
|
||||||
|
HID_USAGE_MAXIMUM(101),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
// Mouse Report
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||||
|
HID_USAGE(HID_DESKTOP_MOUSE),
|
||||||
|
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||||
|
HID_USAGE(HID_DESKTOP_POINTER),
|
||||||
|
HID_COLLECTION(HID_PHYSICAL_COLLECTION),
|
||||||
|
HID_REPORT_ID(ReportIdMouse),
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_BUTTON),
|
||||||
|
HID_USAGE_MINIMUM(1),
|
||||||
|
HID_USAGE_MAXIMUM(3),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_LOGICAL_MAXIMUM(1),
|
||||||
|
HID_REPORT_COUNT(3),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_REPORT_SIZE(1),
|
||||||
|
HID_REPORT_COUNT(5),
|
||||||
|
HID_INPUT(HID_IOF_CONSTANT | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_DESKTOP),
|
||||||
|
HID_USAGE(HID_DESKTOP_X),
|
||||||
|
HID_USAGE(HID_DESKTOP_Y),
|
||||||
|
HID_USAGE(HID_DESKTOP_WHEEL),
|
||||||
|
HID_LOGICAL_MINIMUM(-127),
|
||||||
|
HID_LOGICAL_MAXIMUM(127),
|
||||||
|
HID_REPORT_SIZE(8),
|
||||||
|
HID_REPORT_COUNT(3),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
// Consumer Report
|
||||||
|
HID_USAGE_PAGE(HID_PAGE_CONSUMER),
|
||||||
|
HID_USAGE(HID_CONSUMER_CONTROL),
|
||||||
|
HID_COLLECTION(HID_APPLICATION_COLLECTION),
|
||||||
|
HID_REPORT_ID(ReportIdConsumer),
|
||||||
|
HID_LOGICAL_MINIMUM(0),
|
||||||
|
HID_RI_LOGICAL_MAXIMUM(16, 0x3FF),
|
||||||
|
HID_USAGE_MINIMUM(0),
|
||||||
|
HID_RI_USAGE_MAXIMUM(16, 0x3FF),
|
||||||
|
HID_REPORT_COUNT(BLE_PROFILE_CONSUMER_MAX_KEYS),
|
||||||
|
HID_REPORT_SIZE(16),
|
||||||
|
HID_INPUT(HID_IOF_DATA | HID_IOF_ARRAY | HID_IOF_ABSOLUTE),
|
||||||
|
HID_END_COLLECTION,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriHalBleProfileBase base;
|
||||||
|
|
||||||
|
FuriHalBtHidKbReport* kb_report;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report;
|
||||||
|
|
||||||
|
BleServiceBattery* battery_svc;
|
||||||
|
BleServiceDevInfo* dev_info_svc;
|
||||||
|
BleServiceHid* hid_svc;
|
||||||
|
} BleProfileHid;
|
||||||
|
_Static_assert(offsetof(BleProfileHid, base) == 0, "Wrong layout");
|
||||||
|
|
||||||
|
static FuriHalBleProfileBase* ble_profile_hid_start(FuriHalBleProfileParams profile_params) {
|
||||||
|
UNUSED(profile_params);
|
||||||
|
|
||||||
|
BleProfileHid* profile = malloc(sizeof(BleProfileHid));
|
||||||
|
|
||||||
|
profile->base.config = ble_profile_hid;
|
||||||
|
|
||||||
|
profile->battery_svc = ble_svc_battery_start(true);
|
||||||
|
profile->dev_info_svc = ble_svc_dev_info_start();
|
||||||
|
profile->hid_svc = ble_svc_hid_start();
|
||||||
|
|
||||||
|
// Configure HID Keyboard
|
||||||
|
profile->kb_report = malloc(sizeof(FuriHalBtHidKbReport));
|
||||||
|
profile->mouse_report = malloc(sizeof(FuriHalBtHidMouseReport));
|
||||||
|
profile->consumer_report = malloc(sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
|
||||||
|
// Configure Report Map characteristic
|
||||||
|
ble_svc_hid_update_report_map(
|
||||||
|
profile->hid_svc,
|
||||||
|
ble_profile_hid_report_map_data,
|
||||||
|
sizeof(ble_profile_hid_report_map_data));
|
||||||
|
// Configure HID Information characteristic
|
||||||
|
uint8_t hid_info_val[4] = {
|
||||||
|
HID_INFO_BASE_USB_SPECIFICATION & 0x00ff,
|
||||||
|
(HID_INFO_BASE_USB_SPECIFICATION & 0xff00) >> 8,
|
||||||
|
HID_INFO_COUNTRY_CODE,
|
||||||
|
BLE_PROFILE_HID_INFO_FLAG_REMOTE_WAKE_MSK |
|
||||||
|
BLE_PROFILE_HID_INFO_FLAG_NORMALLY_CONNECTABLE_MSK,
|
||||||
|
};
|
||||||
|
ble_svc_hid_update_info(profile->hid_svc, hid_info_val);
|
||||||
|
|
||||||
|
return &profile->base;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_profile_hid_stop(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
ble_svc_battery_stop(hid_profile->battery_svc);
|
||||||
|
ble_svc_dev_info_stop(hid_profile->dev_info_svc);
|
||||||
|
ble_svc_hid_stop(hid_profile->hid_svc);
|
||||||
|
|
||||||
|
free(hid_profile->kb_report);
|
||||||
|
free(hid_profile->mouse_report);
|
||||||
|
free(hid_profile->consumer_report);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_kb_press(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||||
|
if(kb_report->key[i] == 0) {
|
||||||
|
kb_report->key[i] = button & 0xFF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kb_report->mods |= (button >> 8);
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberKeyboard,
|
||||||
|
(uint8_t*)kb_report,
|
||||||
|
sizeof(FuriHalBtHidKbReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_kb_release(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
|
||||||
|
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||||
|
if(kb_report->key[i] == (button & 0xFF)) {
|
||||||
|
kb_report->key[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
kb_report->mods &= ~(button >> 8);
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberKeyboard,
|
||||||
|
(uint8_t*)kb_report,
|
||||||
|
sizeof(FuriHalBtHidKbReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_kb_release_all(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidKbReport* kb_report = hid_profile->kb_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_HID_KB_MAX_KEYS; i++) {
|
||||||
|
kb_report->key[i] = 0;
|
||||||
|
}
|
||||||
|
kb_report->mods = 0;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberKeyboard,
|
||||||
|
(uint8_t*)kb_report,
|
||||||
|
sizeof(FuriHalBtHidKbReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_consumer_key_press(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||||
|
if(consumer_report->key[i] == 0) {
|
||||||
|
consumer_report->key[i] = button;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberConsumer,
|
||||||
|
(uint8_t*)consumer_report,
|
||||||
|
sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_consumer_key_release(FuriHalBleProfileBase* profile, uint16_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||||
|
if(consumer_report->key[i] == button) {
|
||||||
|
consumer_report->key[i] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberConsumer,
|
||||||
|
(uint8_t*)consumer_report,
|
||||||
|
sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_consumer_key_release_all(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidConsumerReport* consumer_report = hid_profile->consumer_report;
|
||||||
|
for(uint8_t i = 0; i < BLE_PROFILE_CONSUMER_MAX_KEYS; i++) { //-V1008
|
||||||
|
consumer_report->key[i] = 0;
|
||||||
|
}
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberConsumer,
|
||||||
|
(uint8_t*)consumer_report,
|
||||||
|
sizeof(FuriHalBtHidConsumerReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_move(FuriHalBleProfileBase* profile, int8_t dx, int8_t dy) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->x = dx;
|
||||||
|
mouse_report->y = dy;
|
||||||
|
bool state = ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
mouse_report->x = 0;
|
||||||
|
mouse_report->y = 0;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_press(FuriHalBleProfileBase* profile, uint8_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->btn |= button;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_release(FuriHalBleProfileBase* profile, uint8_t button) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->btn &= ~button;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->btn = 0;
|
||||||
|
return ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_hid);
|
||||||
|
|
||||||
|
BleProfileHid* hid_profile = (BleProfileHid*)profile;
|
||||||
|
FuriHalBtHidMouseReport* mouse_report = hid_profile->mouse_report;
|
||||||
|
mouse_report->wheel = delta;
|
||||||
|
bool state = ble_svc_hid_update_input_report(
|
||||||
|
hid_profile->hid_svc,
|
||||||
|
ReportNumberMouse,
|
||||||
|
(uint8_t*)mouse_report,
|
||||||
|
sizeof(FuriHalBtHidMouseReport));
|
||||||
|
mouse_report->wheel = 0;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GapConfig template_config = {
|
||||||
|
.adv_service_uuid = HUMAN_INTERFACE_DEVICE_SERVICE_UUID,
|
||||||
|
.appearance_char = GAP_APPEARANCE_KEYBOARD,
|
||||||
|
.bonding_mode = true,
|
||||||
|
.pairing_method = GapPairingPinCodeVerifyYesNo,
|
||||||
|
.conn_param =
|
||||||
|
{
|
||||||
|
.conn_int_min = 0x18, // 30 ms
|
||||||
|
.conn_int_max = 0x24, // 45 ms
|
||||||
|
.slave_latency = 0,
|
||||||
|
.supervisor_timeout = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void ble_profile_hid_get_config(GapConfig* config, FuriHalBleProfileParams profile_params) {
|
||||||
|
BleProfileHidParams* hid_profile_params = profile_params;
|
||||||
|
|
||||||
|
furi_check(config);
|
||||||
|
memcpy(config, &template_config, sizeof(GapConfig));
|
||||||
|
// Set mac address
|
||||||
|
memcpy(config->mac_address, furi_hal_version_get_ble_mac(), sizeof(config->mac_address));
|
||||||
|
|
||||||
|
// Change MAC address for HID profile
|
||||||
|
config->mac_address[2]++;
|
||||||
|
if(hid_profile_params) {
|
||||||
|
config->mac_address[0] ^= hid_profile_params->mac_xor;
|
||||||
|
config->mac_address[1] ^= hid_profile_params->mac_xor >> 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set advertise name
|
||||||
|
memset(config->adv_name, 0, sizeof(config->adv_name));
|
||||||
|
FuriString* name = furi_string_alloc_set(furi_hal_version_get_ble_local_device_name_ptr());
|
||||||
|
|
||||||
|
const char* clicker_str = "Control";
|
||||||
|
if(hid_profile_params && hid_profile_params->device_name_prefix) {
|
||||||
|
clicker_str = hid_profile_params->device_name_prefix;
|
||||||
|
}
|
||||||
|
furi_string_replace_str(name, "Flipper", clicker_str);
|
||||||
|
if(furi_string_size(name) >= sizeof(config->adv_name)) {
|
||||||
|
furi_string_left(name, sizeof(config->adv_name) - 1);
|
||||||
|
}
|
||||||
|
memcpy(config->adv_name, furi_string_get_cstr(name), furi_string_size(name));
|
||||||
|
furi_string_free(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const FuriHalBleProfileTemplate profile_callbacks = {
|
||||||
|
.start = ble_profile_hid_start,
|
||||||
|
.stop = ble_profile_hid_stop,
|
||||||
|
.get_gap_config = ble_profile_hid_get_config,
|
||||||
|
};
|
||||||
|
|
||||||
|
const FuriHalBleProfileTemplate* ble_profile_hid = &profile_callbacks;
|
||||||
105
lib/ble_profile/extra_profiles/hid_profile.h
Normal file
105
lib/ble_profile/extra_profiles/hid_profile.h
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi_ble/profile_interface.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional arguments to pass along with profile template as
|
||||||
|
* FuriHalBleProfileParams for tuning profile behavior
|
||||||
|
**/
|
||||||
|
typedef struct {
|
||||||
|
const char* device_name_prefix; /**< Prefix for device name. Length must be less than 8 */
|
||||||
|
uint16_t mac_xor; /**< XOR mask for device address, for uniqueness */
|
||||||
|
} BleProfileHidParams;
|
||||||
|
|
||||||
|
/** Hid Keyboard Profile descriptor */
|
||||||
|
extern const FuriHalBleProfileTemplate* ble_profile_hid;
|
||||||
|
|
||||||
|
/** Press keyboard button
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button button code from HID specification
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_kb_press(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Release keyboard button
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button button code from HID specification
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_kb_release(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Release all keyboard buttons
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_kb_release_all(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set the following consumer key to pressed state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_consumer_key_press(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Set the following consumer key to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_consumer_key_release(FuriHalBleProfileBase* profile, uint16_t button);
|
||||||
|
|
||||||
|
/** Set consumer key to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_consumer_key_release_all(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set mouse movement and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param dx x coordinate delta
|
||||||
|
* @param dy y coordinate delta
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_move(FuriHalBleProfileBase* profile, int8_t dx, int8_t dy);
|
||||||
|
|
||||||
|
/** Set mouse button to pressed state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_press(FuriHalBleProfileBase* profile, uint8_t button);
|
||||||
|
|
||||||
|
/** Set mouse button to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_release(FuriHalBleProfileBase* profile, uint8_t button);
|
||||||
|
|
||||||
|
/** Set mouse button to released state and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param button key code
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_release_all(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set mouse wheel position and send HID report
|
||||||
|
*
|
||||||
|
* @param profile profile instance
|
||||||
|
* @param delta number of scroll steps
|
||||||
|
*/
|
||||||
|
bool ble_profile_hid_mouse_scroll(FuriHalBleProfileBase* profile, int8_t delta);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
320
lib/ble_profile/extra_services/hid_service.c
Normal file
320
lib/ble_profile/extra_services/hid_service.c
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
#include "hid_service.h"
|
||||||
|
#include "app_common.h"
|
||||||
|
#include <ble/ble.h>
|
||||||
|
#include <furi_ble/event_dispatcher.h>
|
||||||
|
#include <furi_ble/gatt.h>
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define TAG "BleHid"
|
||||||
|
|
||||||
|
#define BLE_SVC_HID_REPORT_MAP_MAX_LEN (255)
|
||||||
|
#define BLE_SVC_HID_REPORT_MAX_LEN (255)
|
||||||
|
#define BLE_SVC_HID_REPORT_REF_LEN (2)
|
||||||
|
#define BLE_SVC_HID_INFO_LEN (4)
|
||||||
|
#define BLE_SVC_HID_CONTROL_POINT_LEN (1)
|
||||||
|
|
||||||
|
#define BLE_SVC_HID_INPUT_REPORT_COUNT (3)
|
||||||
|
#define BLE_SVC_HID_OUTPUT_REPORT_COUNT (0)
|
||||||
|
#define BLE_SVC_HID_FEATURE_REPORT_COUNT (0)
|
||||||
|
#define BLE_SVC_HID_REPORT_COUNT \
|
||||||
|
(BLE_SVC_HID_INPUT_REPORT_COUNT + BLE_SVC_HID_OUTPUT_REPORT_COUNT + \
|
||||||
|
BLE_SVC_HID_FEATURE_REPORT_COUNT)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HidSvcGattCharacteristicProtocolMode = 0,
|
||||||
|
HidSvcGattCharacteristicReportMap,
|
||||||
|
HidSvcGattCharacteristicInfo,
|
||||||
|
HidSvcGattCharacteristicCtrlPoint,
|
||||||
|
HidSvcGattCharacteristicCount,
|
||||||
|
} HidSvcGattCharacteristicId;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_idx;
|
||||||
|
uint8_t report_type;
|
||||||
|
} HidSvcReportId;
|
||||||
|
|
||||||
|
static_assert(sizeof(HidSvcReportId) == sizeof(uint16_t), "HidSvcReportId must be 2 bytes");
|
||||||
|
|
||||||
|
static const Service_UUID_t ble_svc_hid_uuid = {
|
||||||
|
.Service_UUID_16 = HUMAN_INTERFACE_DEVICE_SERVICE_UUID,
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool ble_svc_hid_char_desc_data_callback(
|
||||||
|
const void* context,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint16_t* data_len) {
|
||||||
|
const HidSvcReportId* report_id = context;
|
||||||
|
*data_len = sizeof(HidSvcReportId);
|
||||||
|
if(data) {
|
||||||
|
*data = (const uint8_t*)report_id;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const void* data_ptr;
|
||||||
|
uint16_t data_len;
|
||||||
|
} HidSvcDataWrapper;
|
||||||
|
|
||||||
|
static bool ble_svc_hid_report_data_callback(
|
||||||
|
const void* context,
|
||||||
|
const uint8_t** data,
|
||||||
|
uint16_t* data_len) {
|
||||||
|
const HidSvcDataWrapper* report_data = context;
|
||||||
|
if(data) {
|
||||||
|
*data = report_data->data_ptr;
|
||||||
|
*data_len = report_data->data_len;
|
||||||
|
} else {
|
||||||
|
*data_len = BLE_SVC_HID_REPORT_MAP_MAX_LEN;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const BleGattCharacteristicParams ble_svc_hid_chars[HidSvcGattCharacteristicCount] = {
|
||||||
|
[HidSvcGattCharacteristicProtocolMode] =
|
||||||
|
{.name = "Protocol Mode",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = 1,
|
||||||
|
.uuid.Char_UUID_16 = PROTOCOL_MODE_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_WRITE_WITHOUT_RESP,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
[HidSvcGattCharacteristicReportMap] =
|
||||||
|
{.name = "Report Map",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
||||||
|
.data.callback.fn = ble_svc_hid_report_data_callback,
|
||||||
|
.data.callback.context = NULL,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_MAP_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_VARIABLE},
|
||||||
|
[HidSvcGattCharacteristicInfo] =
|
||||||
|
{.name = "HID Information",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = BLE_SVC_HID_INFO_LEN,
|
||||||
|
.data.fixed.ptr = NULL,
|
||||||
|
.uuid.Char_UUID_16 = HID_INFORMATION_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
[HidSvcGattCharacteristicCtrlPoint] =
|
||||||
|
{.name = "HID Control Point",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = BLE_SVC_HID_CONTROL_POINT_LEN,
|
||||||
|
.uuid.Char_UUID_16 = HID_CONTROL_POINT_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_WRITE_WITHOUT_RESP,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_NOTIFY_ATTRIBUTE_WRITE,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const BleGattCharacteristicDescriptorParams ble_svc_hid_char_descr_template = {
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_REFERENCE_DESCRIPTOR_UUID,
|
||||||
|
.max_length = BLE_SVC_HID_REPORT_REF_LEN,
|
||||||
|
.data_callback.fn = ble_svc_hid_char_desc_data_callback,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.access_permissions = ATTR_ACCESS_READ_WRITE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const BleGattCharacteristicParams ble_svc_hid_report_template = {
|
||||||
|
.name = "Report",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataCallback,
|
||||||
|
.data.callback.fn = ble_svc_hid_report_data_callback,
|
||||||
|
.data.callback.context = NULL,
|
||||||
|
.uuid.Char_UUID_16 = REPORT_CHAR_UUID,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
||||||
|
.security_permissions = ATTR_PERMISSION_NONE,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_VARIABLE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BleServiceHid {
|
||||||
|
uint16_t svc_handle;
|
||||||
|
BleGattCharacteristicInstance chars[HidSvcGattCharacteristicCount];
|
||||||
|
BleGattCharacteristicInstance input_report_chars[BLE_SVC_HID_INPUT_REPORT_COUNT];
|
||||||
|
BleGattCharacteristicInstance output_report_chars[BLE_SVC_HID_OUTPUT_REPORT_COUNT];
|
||||||
|
BleGattCharacteristicInstance feature_report_chars[BLE_SVC_HID_FEATURE_REPORT_COUNT];
|
||||||
|
GapSvcEventHandler* event_handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
static BleEventAckStatus ble_svc_hid_event_handler(void* event, void* context) {
|
||||||
|
UNUSED(context);
|
||||||
|
|
||||||
|
BleEventAckStatus ret = BleEventNotAck;
|
||||||
|
hci_event_pckt* event_pckt = (hci_event_pckt*)(((hci_uart_pckt*)event)->data);
|
||||||
|
evt_blecore_aci* blecore_evt = (evt_blecore_aci*)event_pckt->data;
|
||||||
|
// aci_gatt_attribute_modified_event_rp0* attribute_modified;
|
||||||
|
if(event_pckt->evt == HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE) {
|
||||||
|
if(blecore_evt->ecode == ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE) {
|
||||||
|
// Process modification events
|
||||||
|
ret = BleEventAckFlowEnable;
|
||||||
|
} else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) {
|
||||||
|
// Process notification confirmation
|
||||||
|
ret = BleEventAckFlowEnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
BleServiceHid* ble_svc_hid_start() {
|
||||||
|
BleServiceHid* hid_svc = malloc(sizeof(BleServiceHid));
|
||||||
|
|
||||||
|
// Register event handler
|
||||||
|
hid_svc->event_handler =
|
||||||
|
ble_event_dispatcher_register_svc_handler(ble_svc_hid_event_handler, hid_svc);
|
||||||
|
/**
|
||||||
|
* Add Human Interface Device Service
|
||||||
|
*/
|
||||||
|
if(!ble_gatt_service_add(
|
||||||
|
UUID_TYPE_16,
|
||||||
|
&ble_svc_hid_uuid,
|
||||||
|
PRIMARY_SERVICE,
|
||||||
|
2 + /* protocol mode */
|
||||||
|
(4 * BLE_SVC_HID_INPUT_REPORT_COUNT) + (3 * BLE_SVC_HID_OUTPUT_REPORT_COUNT) +
|
||||||
|
(3 * BLE_SVC_HID_FEATURE_REPORT_COUNT) + 1 + 2 + 2 +
|
||||||
|
2, /* Service + Report Map + HID Information + HID Control Point */
|
||||||
|
&hid_svc->svc_handle)) {
|
||||||
|
free(hid_svc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Maintain previously defined characteristic order
|
||||||
|
ble_gatt_characteristic_init(
|
||||||
|
hid_svc->svc_handle,
|
||||||
|
&ble_svc_hid_chars[HidSvcGattCharacteristicProtocolMode],
|
||||||
|
&hid_svc->chars[HidSvcGattCharacteristicProtocolMode]);
|
||||||
|
|
||||||
|
uint8_t protocol_mode = 1;
|
||||||
|
ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle,
|
||||||
|
&hid_svc->chars[HidSvcGattCharacteristicProtocolMode],
|
||||||
|
&protocol_mode);
|
||||||
|
|
||||||
|
// reports
|
||||||
|
BleGattCharacteristicDescriptorParams ble_svc_hid_char_descr;
|
||||||
|
BleGattCharacteristicParams report_char;
|
||||||
|
HidSvcReportId report_id;
|
||||||
|
|
||||||
|
memcpy(
|
||||||
|
&ble_svc_hid_char_descr, &ble_svc_hid_char_descr_template, sizeof(ble_svc_hid_char_descr));
|
||||||
|
memcpy(&report_char, &ble_svc_hid_report_template, sizeof(report_char));
|
||||||
|
|
||||||
|
ble_svc_hid_char_descr.data_callback.context = &report_id;
|
||||||
|
report_char.descriptor_params = &ble_svc_hid_char_descr;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_type;
|
||||||
|
uint8_t report_count;
|
||||||
|
BleGattCharacteristicInstance* chars;
|
||||||
|
} HidSvcReportCharProps;
|
||||||
|
|
||||||
|
HidSvcReportCharProps hid_report_chars[] = {
|
||||||
|
{0x01, BLE_SVC_HID_INPUT_REPORT_COUNT, hid_svc->input_report_chars},
|
||||||
|
{0x02, BLE_SVC_HID_OUTPUT_REPORT_COUNT, hid_svc->output_report_chars},
|
||||||
|
{0x03, BLE_SVC_HID_FEATURE_REPORT_COUNT, hid_svc->feature_report_chars},
|
||||||
|
};
|
||||||
|
|
||||||
|
for(size_t report_type_idx = 0; report_type_idx < COUNT_OF(hid_report_chars);
|
||||||
|
report_type_idx++) {
|
||||||
|
report_id.report_type = hid_report_chars[report_type_idx].report_type;
|
||||||
|
for(size_t report_idx = 0; report_idx < hid_report_chars[report_type_idx].report_count;
|
||||||
|
report_idx++) {
|
||||||
|
report_id.report_idx = report_idx + 1;
|
||||||
|
ble_gatt_characteristic_init(
|
||||||
|
hid_svc->svc_handle,
|
||||||
|
&report_char,
|
||||||
|
&hid_report_chars[report_type_idx].chars[report_idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup remaining characteristics
|
||||||
|
for(size_t i = HidSvcGattCharacteristicReportMap; i < HidSvcGattCharacteristicCount; i++) {
|
||||||
|
ble_gatt_characteristic_init(
|
||||||
|
hid_svc->svc_handle, &ble_svc_hid_chars[i], &hid_svc->chars[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hid_svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_report_map(BleServiceHid* hid_svc, const uint8_t* data, uint16_t len) {
|
||||||
|
furi_assert(data);
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
|
||||||
|
HidSvcDataWrapper report_data = {
|
||||||
|
.data_ptr = data,
|
||||||
|
.data_len = len,
|
||||||
|
};
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicReportMap], &report_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_input_report(
|
||||||
|
BleServiceHid* hid_svc,
|
||||||
|
uint8_t input_report_num,
|
||||||
|
uint8_t* data,
|
||||||
|
uint16_t len) {
|
||||||
|
furi_assert(data);
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
furi_assert(input_report_num < BLE_SVC_HID_INPUT_REPORT_COUNT);
|
||||||
|
|
||||||
|
HidSvcDataWrapper report_data = {
|
||||||
|
.data_ptr = data,
|
||||||
|
.data_len = len,
|
||||||
|
};
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle, &hid_svc->input_report_chars[input_report_num], &report_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_info(BleServiceHid* hid_svc, uint8_t* data) {
|
||||||
|
furi_assert(data);
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
|
hid_svc->svc_handle, &hid_svc->chars[HidSvcGattCharacteristicInfo], &data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_svc_hid_stop(BleServiceHid* hid_svc) {
|
||||||
|
furi_assert(hid_svc);
|
||||||
|
ble_event_dispatcher_unregister_svc_handler(hid_svc->event_handler);
|
||||||
|
// Delete characteristics
|
||||||
|
for(size_t i = 0; i < HidSvcGattCharacteristicCount; i++) {
|
||||||
|
ble_gatt_characteristic_delete(hid_svc->svc_handle, &hid_svc->chars[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_count;
|
||||||
|
BleGattCharacteristicInstance* chars;
|
||||||
|
} HidSvcReportCharProps;
|
||||||
|
|
||||||
|
HidSvcReportCharProps hid_report_chars[] = {
|
||||||
|
{BLE_SVC_HID_INPUT_REPORT_COUNT, hid_svc->input_report_chars},
|
||||||
|
{BLE_SVC_HID_OUTPUT_REPORT_COUNT, hid_svc->output_report_chars},
|
||||||
|
{BLE_SVC_HID_FEATURE_REPORT_COUNT, hid_svc->feature_report_chars},
|
||||||
|
};
|
||||||
|
|
||||||
|
for(size_t report_type_idx = 0; report_type_idx < COUNT_OF(hid_report_chars);
|
||||||
|
report_type_idx++) {
|
||||||
|
for(size_t report_idx = 0; report_idx < hid_report_chars[report_type_idx].report_count;
|
||||||
|
report_idx++) {
|
||||||
|
ble_gatt_characteristic_delete(
|
||||||
|
hid_svc->svc_handle, &hid_report_chars[report_type_idx].chars[report_idx]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete service
|
||||||
|
ble_gatt_service_delete(hid_svc->svc_handle);
|
||||||
|
free(hid_svc);
|
||||||
|
}
|
||||||
29
lib/ble_profile/extra_services/hid_service.h
Normal file
29
lib/ble_profile/extra_services/hid_service.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct BleServiceHid BleServiceHid;
|
||||||
|
|
||||||
|
BleServiceHid* ble_svc_hid_start();
|
||||||
|
|
||||||
|
void ble_svc_hid_stop(BleServiceHid* service);
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_report_map(BleServiceHid* service, const uint8_t* data, uint16_t len);
|
||||||
|
|
||||||
|
bool ble_svc_hid_update_input_report(
|
||||||
|
BleServiceHid* service,
|
||||||
|
uint8_t input_report_num,
|
||||||
|
uint8_t* data,
|
||||||
|
uint16_t len);
|
||||||
|
|
||||||
|
// Expects data to be of length BLE_SVC_HID_INFO_LEN (4 bytes)
|
||||||
|
bool ble_svc_hid_update_info(BleServiceHid* service, uint8_t* data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "st25tb.h"
|
#include "st25tb.h"
|
||||||
|
|
||||||
#include "core/string.h"
|
|
||||||
#include "flipper_format.h"
|
#include "flipper_format.h"
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ sources += Glob(
|
|||||||
)
|
)
|
||||||
sources += [
|
sources += [
|
||||||
"stm32wb_copro/wpan/interface/patterns/ble_thread/tl/tl_mbox.c",
|
"stm32wb_copro/wpan/interface/patterns/ble_thread/tl/tl_mbox.c",
|
||||||
"stm32wb_copro/wpan/ble/svc/Src/svc_ctl.c",
|
|
||||||
"stm32wb_copro/wpan/ble/core/auto/ble_gap_aci.c",
|
"stm32wb_copro/wpan/ble/core/auto/ble_gap_aci.c",
|
||||||
"stm32wb_copro/wpan/ble/core/auto/ble_gatt_aci.c",
|
"stm32wb_copro/wpan/ble/core/auto/ble_gatt_aci.c",
|
||||||
"stm32wb_copro/wpan/ble/core/auto/ble_hal_aci.c",
|
"stm32wb_copro/wpan/ble/core/auto/ble_hal_aci.c",
|
||||||
|
|||||||
@@ -30,8 +30,11 @@ class HardwareTargetLoader:
|
|||||||
if not target_json_file.exists():
|
if not target_json_file.exists():
|
||||||
raise Exception(f"Target file {target_json_file} does not exist")
|
raise Exception(f"Target file {target_json_file} does not exist")
|
||||||
with open(target_json_file.get_abspath(), "r") as f:
|
with open(target_json_file.get_abspath(), "r") as f:
|
||||||
vals = json.load(f)
|
try:
|
||||||
return vals
|
vals = json.load(f)
|
||||||
|
return vals
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
raise Exception(f"Failed to parse target file {target_json_file}: {e}")
|
||||||
|
|
||||||
def _processTargetDefinitions(self, target_id):
|
def _processTargetDefinitions(self, target_id):
|
||||||
target_dir = self._getTargetDir(target_id)
|
target_dir = self._getTargetDir(target_id)
|
||||||
|
|||||||
@@ -63,7 +63,13 @@ class Main(App):
|
|||||||
return dist_target_path
|
return dist_target_path
|
||||||
|
|
||||||
def note_dist_component(self, component: str, extension: str, srcpath: str) -> None:
|
def note_dist_component(self, component: str, extension: str, srcpath: str) -> None:
|
||||||
self._dist_components[f"{component}.{extension}"] = srcpath
|
component_key = f"{component}.{extension}"
|
||||||
|
if component_key in self._dist_components:
|
||||||
|
self.logger.debug(
|
||||||
|
f"Skipping duplicate component {component_key} in {srcpath}"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
self._dist_components[component_key] = srcpath
|
||||||
|
|
||||||
def get_dist_file_name(self, dist_artifact_type: str, filetype: str) -> str:
|
def get_dist_file_name(self, dist_artifact_type: str, filetype: str) -> str:
|
||||||
return f"{self.DIST_FILE_PREFIX}{self.target}-{dist_artifact_type}-{self.args.suffix}.{filetype}"
|
return f"{self.DIST_FILE_PREFIX}{self.target}-{dist_artifact_type}-{self.args.suffix}.{filetype}"
|
||||||
@@ -162,8 +168,9 @@ class Main(App):
|
|||||||
"scripts.dir",
|
"scripts.dir",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sdk_bundle_path = self.get_dist_path(self.get_dist_file_name("sdk", "zip"))
|
||||||
with zipfile.ZipFile(
|
with zipfile.ZipFile(
|
||||||
self.get_dist_path(self.get_dist_file_name("sdk", "zip")),
|
sdk_bundle_path,
|
||||||
"w",
|
"w",
|
||||||
zipfile.ZIP_DEFLATED,
|
zipfile.ZIP_DEFLATED,
|
||||||
) as zf:
|
) as zf:
|
||||||
@@ -205,6 +212,10 @@ class Main(App):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.logger.info(
|
||||||
|
fg.boldgreen(f"SDK bundle can be found at:\n\t{sdk_bundle_path}")
|
||||||
|
)
|
||||||
|
|
||||||
def bundle_update_package(self):
|
def bundle_update_package(self):
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
f"Generating update bundle with version {self.args.version} for {self.target}"
|
f"Generating update bundle with version {self.args.version} for {self.target}"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
entry,status,name,type,params
|
entry,status,name,type,params
|
||||||
Version,+,57.0,,
|
Version,+,58.0,,
|
||||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||||
Header,+,applications/services/cli/cli.h,,
|
Header,+,applications/services/cli/cli.h,,
|
||||||
Header,+,applications/services/cli/cli_vcp.h,,
|
Header,+,applications/services/cli/cli_vcp.h,,
|
||||||
@@ -38,6 +38,8 @@ Header,+,applications/services/power/power_service/power.h,,
|
|||||||
Header,+,applications/services/rpc/rpc_app.h,,
|
Header,+,applications/services/rpc/rpc_app.h,,
|
||||||
Header,+,applications/services/storage/storage.h,,
|
Header,+,applications/services/storage/storage.h,,
|
||||||
Header,+,lib/bit_lib/bit_lib.h,,
|
Header,+,lib/bit_lib/bit_lib.h,,
|
||||||
|
Header,+,lib/ble_profile/extra_profiles/hid_profile.h,,
|
||||||
|
Header,+,lib/ble_profile/extra_services/hid_service.h,,
|
||||||
Header,+,lib/datetime/datetime.h,,
|
Header,+,lib/datetime/datetime.h,,
|
||||||
Header,+,lib/digital_signal/digital_sequence.h,,
|
Header,+,lib/digital_signal/digital_sequence.h,,
|
||||||
Header,+,lib/digital_signal/digital_signal.h,,
|
Header,+,lib/digital_signal/digital_signal.h,,
|
||||||
@@ -169,6 +171,13 @@ Header,+,lib/toolbox/version.h,,
|
|||||||
Header,+,targets/f18/furi_hal/furi_hal_resources.h,,
|
Header,+,targets/f18/furi_hal/furi_hal_resources.h,,
|
||||||
Header,+,targets/f18/furi_hal/furi_hal_spi_config.h,,
|
Header,+,targets/f18/furi_hal/furi_hal_spi_config.h,,
|
||||||
Header,+,targets/f18/furi_hal/furi_hal_target_hw.h,,
|
Header,+,targets/f18/furi_hal/furi_hal_target_hw.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/furi_ble/event_dispatcher.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/furi_ble/gatt.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/furi_ble/profile_interface.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/profiles/serial_profile.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/services/battery_service.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/services/dev_info_service.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/services/serial_service.h,,
|
||||||
Header,+,targets/f7/furi_hal/furi_hal_bus.h,,
|
Header,+,targets/f7/furi_hal/furi_hal_bus.h,,
|
||||||
Header,+,targets/f7/furi_hal/furi_hal_clock.h,,
|
Header,+,targets/f7/furi_hal/furi_hal_clock.h,,
|
||||||
Header,+,targets/f7/furi_hal/furi_hal_dma.h,,
|
Header,+,targets/f7/furi_hal/furi_hal_dma.h,,
|
||||||
@@ -191,8 +200,6 @@ Header,+,targets/f7/platform_specific/intrinsic_export.h,,
|
|||||||
Header,+,targets/f7/platform_specific/math_wrapper.h,,
|
Header,+,targets/f7/platform_specific/math_wrapper.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal.h,,
|
Header,+,targets/furi_hal_include/furi_hal.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_bt.h,,
|
Header,+,targets/furi_hal_include/furi_hal_bt.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_bt_hid.h,,
|
|
||||||
Header,+,targets/furi_hal_include/furi_hal_bt_serial.h,,
|
|
||||||
Header,+,targets/furi_hal_include/furi_hal_cortex.h,,
|
Header,+,targets/furi_hal_include/furi_hal_cortex.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_crypto.h,,
|
Header,+,targets/furi_hal_include/furi_hal_crypto.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_debug.h,,
|
Header,+,targets/furi_hal_include/furi_hal_debug.h,,
|
||||||
@@ -310,6 +317,9 @@ Function,-,LL_USART_DeInit,ErrorStatus,const USART_TypeDef*
|
|||||||
Function,+,LL_USART_Init,ErrorStatus,"USART_TypeDef*, const LL_USART_InitTypeDef*"
|
Function,+,LL_USART_Init,ErrorStatus,"USART_TypeDef*, const LL_USART_InitTypeDef*"
|
||||||
Function,-,LL_USART_StructInit,void,LL_USART_InitTypeDef*
|
Function,-,LL_USART_StructInit,void,LL_USART_InitTypeDef*
|
||||||
Function,-,LL_mDelay,void,uint32_t
|
Function,-,LL_mDelay,void,uint32_t
|
||||||
|
Function,-,Osal_MemCmp,int,"const void*, const void*, unsigned int"
|
||||||
|
Function,-,Osal_MemCpy,void*,"void*, const void*, unsigned int"
|
||||||
|
Function,-,Osal_MemSet,void*,"void*, int, unsigned int"
|
||||||
Function,-,SystemCoreClockUpdate,void,
|
Function,-,SystemCoreClockUpdate,void,
|
||||||
Function,-,SystemInit,void,
|
Function,-,SystemInit,void,
|
||||||
Function,-,_Exit,void,int
|
Function,-,_Exit,void,int
|
||||||
@@ -602,9 +612,20 @@ Function,+,bit_lib_set_bit,void,"uint8_t*, size_t, _Bool"
|
|||||||
Function,+,bit_lib_set_bits,void,"uint8_t*, size_t, uint8_t, uint8_t"
|
Function,+,bit_lib_set_bits,void,"uint8_t*, size_t, uint8_t, uint8_t"
|
||||||
Function,+,bit_lib_test_parity,_Bool,"const uint8_t*, size_t, uint8_t, BitLibParity, uint8_t"
|
Function,+,bit_lib_test_parity,_Bool,"const uint8_t*, size_t, uint8_t, BitLibParity, uint8_t"
|
||||||
Function,+,bit_lib_test_parity_32,_Bool,"uint32_t, BitLibParity"
|
Function,+,bit_lib_test_parity_32,_Bool,"uint32_t, BitLibParity"
|
||||||
Function,+,ble_app_get_key_storage_buff,void,"uint8_t**, uint16_t*"
|
Function,-,ble_app_deinit,void,
|
||||||
Function,+,ble_app_init,_Bool,
|
Function,-,ble_app_get_key_storage_buff,void,"uint8_t**, uint16_t*"
|
||||||
Function,+,ble_app_thread_stop,void,
|
Function,-,ble_app_init,_Bool,
|
||||||
|
Function,-,ble_event_app_notification,BleEventFlowStatus,void*
|
||||||
|
Function,-,ble_event_dispatcher_init,void,
|
||||||
|
Function,-,ble_event_dispatcher_process_event,BleEventFlowStatus,void*
|
||||||
|
Function,+,ble_event_dispatcher_register_svc_handler,GapSvcEventHandler*,"BleSvcEventHandlerCb, void*"
|
||||||
|
Function,-,ble_event_dispatcher_reset,void,
|
||||||
|
Function,+,ble_event_dispatcher_unregister_svc_handler,void,GapSvcEventHandler*
|
||||||
|
Function,+,ble_gatt_characteristic_delete,void,"uint16_t, BleGattCharacteristicInstance*"
|
||||||
|
Function,+,ble_gatt_characteristic_init,void,"uint16_t, const BleGattCharacteristicParams*, BleGattCharacteristicInstance*"
|
||||||
|
Function,+,ble_gatt_characteristic_update,_Bool,"uint16_t, BleGattCharacteristicInstance*, const void*"
|
||||||
|
Function,+,ble_gatt_service_add,_Bool,"uint8_t, const Service_UUID_t*, uint8_t, uint8_t, uint16_t*"
|
||||||
|
Function,+,ble_gatt_service_delete,_Bool,uint16_t
|
||||||
Function,+,ble_glue_force_c2_mode,BleGlueCommandResult,BleGlueC2Mode
|
Function,+,ble_glue_force_c2_mode,BleGlueCommandResult,BleGlueC2Mode
|
||||||
Function,-,ble_glue_fus_get_status,BleGlueCommandResult,
|
Function,-,ble_glue_fus_get_status,BleGlueCommandResult,
|
||||||
Function,-,ble_glue_fus_stack_delete,BleGlueCommandResult,
|
Function,-,ble_glue_fus_stack_delete,BleGlueCommandResult,
|
||||||
@@ -612,20 +633,55 @@ Function,-,ble_glue_fus_stack_install,BleGlueCommandResult,"uint32_t, uint32_t"
|
|||||||
Function,-,ble_glue_fus_wait_operation,BleGlueCommandResult,
|
Function,-,ble_glue_fus_wait_operation,BleGlueCommandResult,
|
||||||
Function,+,ble_glue_get_c2_info,const BleGlueC2Info*,
|
Function,+,ble_glue_get_c2_info,const BleGlueC2Info*,
|
||||||
Function,-,ble_glue_get_c2_status,BleGlueStatus,
|
Function,-,ble_glue_get_c2_status,BleGlueStatus,
|
||||||
|
Function,-,ble_glue_get_hardfault_info,const BleGlueHardfaultInfo*,
|
||||||
Function,+,ble_glue_init,void,
|
Function,+,ble_glue_init,void,
|
||||||
Function,+,ble_glue_is_alive,_Bool,
|
Function,+,ble_glue_is_alive,_Bool,
|
||||||
Function,+,ble_glue_is_radio_stack_ready,_Bool,
|
Function,+,ble_glue_is_radio_stack_ready,_Bool,
|
||||||
Function,+,ble_glue_reinit_c2,_Bool,
|
Function,+,ble_glue_reinit_c2,_Bool,
|
||||||
Function,+,ble_glue_set_key_storage_changed_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
Function,+,ble_glue_set_key_storage_changed_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
||||||
Function,+,ble_glue_start,_Bool,
|
Function,+,ble_glue_start,_Bool,
|
||||||
Function,+,ble_glue_thread_stop,void,
|
Function,+,ble_glue_stop,void,
|
||||||
Function,+,ble_glue_wait_for_c2_start,_Bool,int32_t
|
Function,+,ble_glue_wait_for_c2_start,_Bool,int32_t
|
||||||
|
Function,-,ble_profile_hid_consumer_key_press,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_consumer_key_release,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_consumer_key_release_all,_Bool,FuriHalBleProfileBase*
|
||||||
|
Function,-,ble_profile_hid_kb_press,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_kb_release,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_kb_release_all,_Bool,FuriHalBleProfileBase*
|
||||||
|
Function,-,ble_profile_hid_mouse_move,_Bool,"FuriHalBleProfileBase*, int8_t, int8_t"
|
||||||
|
Function,-,ble_profile_hid_mouse_press,_Bool,"FuriHalBleProfileBase*, uint8_t"
|
||||||
|
Function,-,ble_profile_hid_mouse_release,_Bool,"FuriHalBleProfileBase*, uint8_t"
|
||||||
|
Function,-,ble_profile_hid_mouse_release_all,_Bool,FuriHalBleProfileBase*
|
||||||
|
Function,-,ble_profile_hid_mouse_scroll,_Bool,"FuriHalBleProfileBase*, int8_t"
|
||||||
|
Function,+,ble_profile_serial_notify_buffer_is_empty,void,FuriHalBleProfileBase*
|
||||||
|
Function,+,ble_profile_serial_set_event_callback,void,"FuriHalBleProfileBase*, uint16_t, FuriHalBtSerialCallback, void*"
|
||||||
|
Function,+,ble_profile_serial_set_rpc_active,void,"FuriHalBleProfileBase*, _Bool"
|
||||||
|
Function,+,ble_profile_serial_tx,_Bool,"FuriHalBleProfileBase*, uint8_t*, uint16_t"
|
||||||
|
Function,+,ble_svc_battery_start,BleServiceBattery*,_Bool
|
||||||
|
Function,+,ble_svc_battery_state_update,void,"uint8_t*, _Bool*"
|
||||||
|
Function,+,ble_svc_battery_stop,void,BleServiceBattery*
|
||||||
|
Function,+,ble_svc_battery_update_level,_Bool,"BleServiceBattery*, uint8_t"
|
||||||
|
Function,+,ble_svc_battery_update_power_state,_Bool,"BleServiceBattery*, _Bool"
|
||||||
|
Function,+,ble_svc_dev_info_start,BleServiceDevInfo*,
|
||||||
|
Function,+,ble_svc_dev_info_stop,void,BleServiceDevInfo*
|
||||||
|
Function,-,ble_svc_hid_start,BleServiceHid*,
|
||||||
|
Function,-,ble_svc_hid_stop,void,BleServiceHid*
|
||||||
|
Function,-,ble_svc_hid_update_info,_Bool,"BleServiceHid*, uint8_t*"
|
||||||
|
Function,-,ble_svc_hid_update_input_report,_Bool,"BleServiceHid*, uint8_t, uint8_t*, uint16_t"
|
||||||
|
Function,-,ble_svc_hid_update_report_map,_Bool,"BleServiceHid*, const uint8_t*, uint16_t"
|
||||||
|
Function,+,ble_svc_serial_notify_buffer_is_empty,void,BleServiceSerial*
|
||||||
|
Function,+,ble_svc_serial_set_callbacks,void,"BleServiceSerial*, uint16_t, SerialServiceEventCallback, void*"
|
||||||
|
Function,+,ble_svc_serial_set_rpc_active,void,"BleServiceSerial*, _Bool"
|
||||||
|
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,-,bsearch,void*,"const void*, const void*, size_t, size_t, __compar_fn_t"
|
||||||
Function,+,bt_disconnect,void,Bt*
|
Function,+,bt_disconnect,void,Bt*
|
||||||
Function,+,bt_forget_bonded_devices,void,Bt*
|
Function,+,bt_forget_bonded_devices,void,Bt*
|
||||||
Function,+,bt_keys_storage_set_default_path,void,Bt*
|
Function,+,bt_keys_storage_set_default_path,void,Bt*
|
||||||
Function,+,bt_keys_storage_set_storage_path,void,"Bt*, const char*"
|
Function,+,bt_keys_storage_set_storage_path,void,"Bt*, const char*"
|
||||||
Function,+,bt_set_profile,_Bool,"Bt*, BtProfile"
|
Function,+,bt_profile_restore_default,_Bool,Bt*
|
||||||
|
Function,+,bt_profile_start,FuriHalBleProfileBase*,"Bt*, const FuriHalBleProfileTemplate*, FuriHalBleProfileParams"
|
||||||
Function,+,bt_set_status_changed_callback,void,"Bt*, BtStatusChangedCallback, void*"
|
Function,+,bt_set_status_changed_callback,void,"Bt*, BtStatusChangedCallback, void*"
|
||||||
Function,+,buffered_file_stream_alloc,Stream*,Storage*
|
Function,+,buffered_file_stream_alloc,Stream*,Storage*
|
||||||
Function,+,buffered_file_stream_close,_Bool,Stream*
|
Function,+,buffered_file_stream_close,_Bool,Stream*
|
||||||
@@ -1030,46 +1086,34 @@ Function,+,furi_event_flag_get,uint32_t,FuriEventFlag*
|
|||||||
Function,+,furi_event_flag_set,uint32_t,"FuriEventFlag*, uint32_t"
|
Function,+,furi_event_flag_set,uint32_t,"FuriEventFlag*, uint32_t"
|
||||||
Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, uint32_t"
|
Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, uint32_t"
|
||||||
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,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_clear_white_list,_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_hardfault_info,const FuriHalBtHardfaultInfo*,
|
Function,+,furi_hal_bt_extra_beacon_get_config,const GapExtraBeaconConfig*,
|
||||||
|
Function,+,furi_hal_bt_extra_beacon_get_data,uint8_t,uint8_t*
|
||||||
|
Function,+,furi_hal_bt_extra_beacon_is_active,_Bool,
|
||||||
|
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_key_storage_buff,void,"uint8_t**, uint16_t*"
|
Function,+,furi_hal_bt_get_key_storage_buff,void,"uint8_t**, uint16_t*"
|
||||||
Function,+,furi_hal_bt_get_radio_stack,FuriHalBtStack,
|
Function,+,furi_hal_bt_get_radio_stack,FuriHalBtStack,
|
||||||
Function,+,furi_hal_bt_get_rssi,float,
|
Function,+,furi_hal_bt_get_rssi,float,
|
||||||
Function,+,furi_hal_bt_get_transmitted_packets,uint32_t,
|
Function,+,furi_hal_bt_get_transmitted_packets,uint32_t,
|
||||||
Function,+,furi_hal_bt_hid_consumer_key_press,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_consumer_key_release,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_consumer_key_release_all,_Bool,
|
|
||||||
Function,+,furi_hal_bt_hid_kb_press,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_kb_release,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_kb_release_all,_Bool,
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_move,_Bool,"int8_t, int8_t"
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_press,_Bool,uint8_t
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_release,_Bool,uint8_t
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_release_all,_Bool,
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_scroll,_Bool,int8_t
|
|
||||||
Function,+,furi_hal_bt_hid_start,void,
|
|
||||||
Function,+,furi_hal_bt_hid_stop,void,
|
|
||||||
Function,-,furi_hal_bt_init,void,
|
Function,-,furi_hal_bt_init,void,
|
||||||
Function,+,furi_hal_bt_is_active,_Bool,
|
Function,+,furi_hal_bt_is_active,_Bool,
|
||||||
Function,+,furi_hal_bt_is_alive,_Bool,
|
Function,+,furi_hal_bt_is_alive,_Bool,
|
||||||
Function,+,furi_hal_bt_is_ble_gatt_gap_supported,_Bool,
|
Function,+,furi_hal_bt_is_gatt_gap_supported,_Bool,
|
||||||
Function,+,furi_hal_bt_is_testing_supported,_Bool,
|
Function,+,furi_hal_bt_is_testing_supported,_Bool,
|
||||||
Function,+,furi_hal_bt_lock_core2,void,
|
Function,+,furi_hal_bt_lock_core2,void,
|
||||||
Function,+,furi_hal_bt_nvm_sram_sem_acquire,void,
|
Function,+,furi_hal_bt_nvm_sram_sem_acquire,void,
|
||||||
Function,+,furi_hal_bt_nvm_sram_sem_release,void,
|
Function,+,furi_hal_bt_nvm_sram_sem_release,void,
|
||||||
Function,+,furi_hal_bt_reinit,void,
|
Function,+,furi_hal_bt_reinit,void,
|
||||||
Function,+,furi_hal_bt_serial_notify_buffer_is_empty,void,
|
|
||||||
Function,+,furi_hal_bt_serial_set_event_callback,void,"uint16_t, FuriHalBtSerialCallback, void*"
|
|
||||||
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_key_storage_change_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
Function,+,furi_hal_bt_set_key_storage_change_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
||||||
Function,+,furi_hal_bt_start_advertising,void,
|
Function,+,furi_hal_bt_start_advertising,void,
|
||||||
Function,+,furi_hal_bt_start_app,_Bool,"FuriHalBtProfile, GapEventCallback, 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"
|
Function,+,furi_hal_bt_start_packet_rx,void,"uint8_t, uint8_t"
|
||||||
Function,+,furi_hal_bt_start_packet_tx,void,"uint8_t, uint8_t, uint8_t"
|
Function,+,furi_hal_bt_start_packet_tx,void,"uint8_t, uint8_t, uint8_t"
|
||||||
Function,+,furi_hal_bt_start_radio_stack,_Bool,
|
Function,+,furi_hal_bt_start_radio_stack,_Bool,
|
||||||
@@ -1081,7 +1125,7 @@ Function,+,furi_hal_bt_stop_rx,void,
|
|||||||
Function,+,furi_hal_bt_stop_tone_tx,void,
|
Function,+,furi_hal_bt_stop_tone_tx,void,
|
||||||
Function,+,furi_hal_bt_unlock_core2,void,
|
Function,+,furi_hal_bt_unlock_core2,void,
|
||||||
Function,+,furi_hal_bt_update_battery_level,void,uint8_t
|
Function,+,furi_hal_bt_update_battery_level,void,uint8_t
|
||||||
Function,+,furi_hal_bt_update_power_state,void,
|
Function,+,furi_hal_bt_update_power_state,void,_Bool
|
||||||
Function,+,furi_hal_bus_deinit_early,void,
|
Function,+,furi_hal_bus_deinit_early,void,
|
||||||
Function,+,furi_hal_bus_disable,void,FuriHalBus
|
Function,+,furi_hal_bus_disable,void,FuriHalBus
|
||||||
Function,+,furi_hal_bus_enable,void,FuriHalBus
|
Function,+,furi_hal_bus_enable,void,FuriHalBus
|
||||||
@@ -1530,6 +1574,7 @@ Function,+,furi_thread_get_current_priority,FuriThreadPriority,
|
|||||||
Function,+,furi_thread_get_heap_size,size_t,FuriThread*
|
Function,+,furi_thread_get_heap_size,size_t,FuriThread*
|
||||||
Function,+,furi_thread_get_id,FuriThreadId,FuriThread*
|
Function,+,furi_thread_get_id,FuriThreadId,FuriThread*
|
||||||
Function,+,furi_thread_get_name,const char*,FuriThreadId
|
Function,+,furi_thread_get_name,const char*,FuriThreadId
|
||||||
|
Function,+,furi_thread_get_priority,FuriThreadPriority,FuriThread*
|
||||||
Function,+,furi_thread_get_return_code,int32_t,FuriThread*
|
Function,+,furi_thread_get_return_code,int32_t,FuriThread*
|
||||||
Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId
|
Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId
|
||||||
Function,+,furi_thread_get_state,FuriThreadState,FuriThread*
|
Function,+,furi_thread_get_state,FuriThreadState,FuriThread*
|
||||||
@@ -1568,6 +1613,15 @@ Function,-,gamma,double,double
|
|||||||
Function,-,gamma_r,double,"double, int*"
|
Function,-,gamma_r,double,"double, int*"
|
||||||
Function,-,gammaf,float,float
|
Function,-,gammaf,float,float
|
||||||
Function,-,gammaf_r,float,"float, int*"
|
Function,-,gammaf_r,float,"float, int*"
|
||||||
|
Function,-,gap_emit_ble_beacon_status_event,void,_Bool
|
||||||
|
Function,-,gap_extra_beacon_get_config,const GapExtraBeaconConfig*,
|
||||||
|
Function,-,gap_extra_beacon_get_data,uint8_t,uint8_t*
|
||||||
|
Function,-,gap_extra_beacon_get_state,GapExtraBeaconState,
|
||||||
|
Function,-,gap_extra_beacon_init,void,
|
||||||
|
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_state,GapState,
|
Function,-,gap_get_state,GapState,
|
||||||
Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
|
Function,-,gap_init,_Bool,"GapConfig*, GapEventCallback, void*"
|
||||||
Function,-,gap_start_advertising,void,
|
Function,-,gap_start_advertising,void,
|
||||||
@@ -1591,6 +1645,7 @@ Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"
|
|||||||
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
||||||
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
||||||
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
||||||
|
Function,-,hci_send_req,int,"hci_request*, uint8_t"
|
||||||
Function,+,hex_char_to_hex_nibble,_Bool,"char, uint8_t*"
|
Function,+,hex_char_to_hex_nibble,_Bool,"char, uint8_t*"
|
||||||
Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*"
|
Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*"
|
||||||
Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*"
|
Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*"
|
||||||
@@ -2274,13 +2329,6 @@ Function,+,scene_manager_stop,void,SceneManager*
|
|||||||
Function,+,sd_api_get_fs_type_text,const char*,SDFsType
|
Function,+,sd_api_get_fs_type_text,const char*,SDFsType
|
||||||
Function,-,secure_getenv,char*,const char*
|
Function,-,secure_getenv,char*,const char*
|
||||||
Function,-,seed48,unsigned short*,unsigned short[3]
|
Function,-,seed48,unsigned short*,unsigned short[3]
|
||||||
Function,-,serial_svc_is_started,_Bool,
|
|
||||||
Function,-,serial_svc_notify_buffer_is_empty,void,
|
|
||||||
Function,-,serial_svc_set_callbacks,void,"uint16_t, SerialServiceEventCallback, void*"
|
|
||||||
Function,-,serial_svc_set_rpc_status,void,SerialServiceRpcStatus
|
|
||||||
Function,-,serial_svc_start,void,
|
|
||||||
Function,-,serial_svc_stop,void,
|
|
||||||
Function,-,serial_svc_update_tx,_Bool,"uint8_t*, uint16_t"
|
|
||||||
Function,-,setbuf,void,"FILE*, char*"
|
Function,-,setbuf,void,"FILE*, char*"
|
||||||
Function,-,setbuffer,void,"FILE*, char*, int"
|
Function,-,setbuffer,void,"FILE*, char*, int"
|
||||||
Function,-,setenv,int,"const char*, const char*, int"
|
Function,-,setenv,int,"const char*, const char*, int"
|
||||||
@@ -2693,6 +2741,8 @@ Variable,+,_impure_data,_reent,
|
|||||||
Variable,+,_impure_ptr,_reent*,
|
Variable,+,_impure_ptr,_reent*,
|
||||||
Variable,-,_sys_errlist,const char*[],
|
Variable,-,_sys_errlist,const char*[],
|
||||||
Variable,-,_sys_nerr,int,
|
Variable,-,_sys_nerr,int,
|
||||||
|
Variable,-,ble_profile_hid,const FuriHalBleProfileTemplate*,
|
||||||
|
Variable,-,ble_profile_serial,const FuriHalBleProfileTemplate*,
|
||||||
Variable,+,cli_vcp,CliSession,
|
Variable,+,cli_vcp,CliSession,
|
||||||
Variable,+,firmware_api_interface,const ElfApiInterface*,
|
Variable,+,firmware_api_interface,const ElfApiInterface*,
|
||||||
Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus,
|
Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus,
|
||||||
|
|||||||
|
@@ -1,5 +1,5 @@
|
|||||||
entry,status,name,type,params
|
entry,status,name,type,params
|
||||||
Version,+,57.0,,
|
Version,+,58.0,,
|
||||||
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
|
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
|
||||||
Header,+,applications/main/archive/helpers/archive_helpers_ext.h,,
|
Header,+,applications/main/archive/helpers/archive_helpers_ext.h,,
|
||||||
Header,+,applications/main/subghz/subghz_fap.h,,
|
Header,+,applications/main/subghz/subghz_fap.h,,
|
||||||
@@ -50,6 +50,8 @@ Header,+,applications/services/rpc/rpc_app.h,,
|
|||||||
Header,+,applications/services/storage/storage.h,,
|
Header,+,applications/services/storage/storage.h,,
|
||||||
Header,+,build/icons/assets_icons.h,,
|
Header,+,build/icons/assets_icons.h,,
|
||||||
Header,+,lib/bit_lib/bit_lib.h,,
|
Header,+,lib/bit_lib/bit_lib.h,,
|
||||||
|
Header,+,lib/ble_profile/extra_profiles/hid_profile.h,,
|
||||||
|
Header,+,lib/ble_profile/extra_services/hid_service.h,,
|
||||||
Header,+,lib/datetime/datetime.h,,
|
Header,+,lib/datetime/datetime.h,,
|
||||||
Header,+,lib/digital_signal/digital_sequence.h,,
|
Header,+,lib/digital_signal/digital_sequence.h,,
|
||||||
Header,+,lib/digital_signal/digital_signal.h,,
|
Header,+,lib/digital_signal/digital_signal.h,,
|
||||||
@@ -246,6 +248,13 @@ Header,+,lib/toolbox/tar/tar_archive.h,,
|
|||||||
Header,+,lib/toolbox/value_index.h,,
|
Header,+,lib/toolbox/value_index.h,,
|
||||||
Header,+,lib/toolbox/version.h,,
|
Header,+,lib/toolbox/version.h,,
|
||||||
Header,+,lib/xtreme/xtreme.h,,
|
Header,+,lib/xtreme/xtreme.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/furi_ble/event_dispatcher.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/furi_ble/gatt.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/furi_ble/profile_interface.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/profiles/serial_profile.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/services/battery_service.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/services/dev_info_service.h,,
|
||||||
|
Header,+,targets/f7/ble_glue/services/serial_service.h,,
|
||||||
Header,+,targets/f7/furi_hal/furi_hal_bus.h,,
|
Header,+,targets/f7/furi_hal/furi_hal_bus.h,,
|
||||||
Header,+,targets/f7/furi_hal/furi_hal_clock.h,,
|
Header,+,targets/f7/furi_hal/furi_hal_clock.h,,
|
||||||
Header,+,targets/f7/furi_hal/furi_hal_dma.h,,
|
Header,+,targets/f7/furi_hal/furi_hal_dma.h,,
|
||||||
@@ -274,8 +283,6 @@ Header,+,targets/f7/platform_specific/intrinsic_export.h,,
|
|||||||
Header,+,targets/f7/platform_specific/math_wrapper.h,,
|
Header,+,targets/f7/platform_specific/math_wrapper.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal.h,,
|
Header,+,targets/furi_hal_include/furi_hal.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_bt.h,,
|
Header,+,targets/furi_hal_include/furi_hal_bt.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_bt_hid.h,,
|
|
||||||
Header,+,targets/furi_hal_include/furi_hal_bt_serial.h,,
|
|
||||||
Header,+,targets/furi_hal_include/furi_hal_cortex.h,,
|
Header,+,targets/furi_hal_include/furi_hal_cortex.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_crypto.h,,
|
Header,+,targets/furi_hal_include/furi_hal_crypto.h,,
|
||||||
Header,+,targets/furi_hal_include/furi_hal_debug.h,,
|
Header,+,targets/furi_hal_include/furi_hal_debug.h,,
|
||||||
@@ -400,6 +407,9 @@ Function,+,LL_USART_Init,ErrorStatus,"USART_TypeDef*, const LL_USART_InitTypeDef
|
|||||||
Function,-,LL_USART_StructInit,void,LL_USART_InitTypeDef*
|
Function,-,LL_USART_StructInit,void,LL_USART_InitTypeDef*
|
||||||
Function,-,LL_mDelay,void,uint32_t
|
Function,-,LL_mDelay,void,uint32_t
|
||||||
Function,+,LOAD_POWER_SETTINGS,_Bool,uint32_t*
|
Function,+,LOAD_POWER_SETTINGS,_Bool,uint32_t*
|
||||||
|
Function,-,Osal_MemCmp,int,"const void*, const void*, unsigned int"
|
||||||
|
Function,-,Osal_MemCpy,void*,"void*, const void*, unsigned int"
|
||||||
|
Function,-,Osal_MemSet,void*,"void*, int, unsigned int"
|
||||||
Function,+,SAVE_POWER_SETTINGS,_Bool,uint32_t*
|
Function,+,SAVE_POWER_SETTINGS,_Bool,uint32_t*
|
||||||
Function,-,SK6805_get_led_count,uint8_t,
|
Function,-,SK6805_get_led_count,uint8_t,
|
||||||
Function,-,SK6805_init,void,
|
Function,-,SK6805_init,void,
|
||||||
@@ -697,9 +707,20 @@ Function,+,bit_lib_set_bit,void,"uint8_t*, size_t, _Bool"
|
|||||||
Function,+,bit_lib_set_bits,void,"uint8_t*, size_t, uint8_t, uint8_t"
|
Function,+,bit_lib_set_bits,void,"uint8_t*, size_t, uint8_t, uint8_t"
|
||||||
Function,+,bit_lib_test_parity,_Bool,"const uint8_t*, size_t, uint8_t, BitLibParity, uint8_t"
|
Function,+,bit_lib_test_parity,_Bool,"const uint8_t*, size_t, uint8_t, BitLibParity, uint8_t"
|
||||||
Function,+,bit_lib_test_parity_32,_Bool,"uint32_t, BitLibParity"
|
Function,+,bit_lib_test_parity_32,_Bool,"uint32_t, BitLibParity"
|
||||||
Function,+,ble_app_get_key_storage_buff,void,"uint8_t**, uint16_t*"
|
Function,-,ble_app_deinit,void,
|
||||||
Function,+,ble_app_init,_Bool,
|
Function,-,ble_app_get_key_storage_buff,void,"uint8_t**, uint16_t*"
|
||||||
Function,+,ble_app_thread_stop,void,
|
Function,-,ble_app_init,_Bool,
|
||||||
|
Function,-,ble_event_app_notification,BleEventFlowStatus,void*
|
||||||
|
Function,-,ble_event_dispatcher_init,void,
|
||||||
|
Function,+,ble_event_dispatcher_process_event,BleEventFlowStatus,void*
|
||||||
|
Function,+,ble_event_dispatcher_register_svc_handler,GapSvcEventHandler*,"BleSvcEventHandlerCb, void*"
|
||||||
|
Function,-,ble_event_dispatcher_reset,void,
|
||||||
|
Function,+,ble_event_dispatcher_unregister_svc_handler,void,GapSvcEventHandler*
|
||||||
|
Function,+,ble_gatt_characteristic_delete,void,"uint16_t, BleGattCharacteristicInstance*"
|
||||||
|
Function,+,ble_gatt_characteristic_init,void,"uint16_t, const BleGattCharacteristicParams*, BleGattCharacteristicInstance*"
|
||||||
|
Function,+,ble_gatt_characteristic_update,_Bool,"uint16_t, BleGattCharacteristicInstance*, const void*"
|
||||||
|
Function,+,ble_gatt_service_add,_Bool,"uint8_t, const Service_UUID_t*, uint8_t, uint8_t, uint16_t*"
|
||||||
|
Function,+,ble_gatt_service_delete,_Bool,uint16_t
|
||||||
Function,+,ble_glue_force_c2_mode,BleGlueCommandResult,BleGlueC2Mode
|
Function,+,ble_glue_force_c2_mode,BleGlueCommandResult,BleGlueC2Mode
|
||||||
Function,-,ble_glue_fus_get_status,BleGlueCommandResult,
|
Function,-,ble_glue_fus_get_status,BleGlueCommandResult,
|
||||||
Function,-,ble_glue_fus_stack_delete,BleGlueCommandResult,
|
Function,-,ble_glue_fus_stack_delete,BleGlueCommandResult,
|
||||||
@@ -707,31 +728,58 @@ Function,-,ble_glue_fus_stack_install,BleGlueCommandResult,"uint32_t, uint32_t"
|
|||||||
Function,-,ble_glue_fus_wait_operation,BleGlueCommandResult,
|
Function,-,ble_glue_fus_wait_operation,BleGlueCommandResult,
|
||||||
Function,+,ble_glue_get_c2_info,const BleGlueC2Info*,
|
Function,+,ble_glue_get_c2_info,const BleGlueC2Info*,
|
||||||
Function,-,ble_glue_get_c2_status,BleGlueStatus,
|
Function,-,ble_glue_get_c2_status,BleGlueStatus,
|
||||||
|
Function,-,ble_glue_get_hardfault_info,const BleGlueHardfaultInfo*,
|
||||||
Function,+,ble_glue_init,void,
|
Function,+,ble_glue_init,void,
|
||||||
Function,+,ble_glue_is_alive,_Bool,
|
Function,+,ble_glue_is_alive,_Bool,
|
||||||
Function,+,ble_glue_is_radio_stack_ready,_Bool,
|
Function,+,ble_glue_is_radio_stack_ready,_Bool,
|
||||||
Function,+,ble_glue_reinit_c2,_Bool,
|
Function,+,ble_glue_reinit_c2,_Bool,
|
||||||
Function,+,ble_glue_set_key_storage_changed_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
Function,+,ble_glue_set_key_storage_changed_callback,void,"BleGlueKeyStorageChangedCallback, void*"
|
||||||
Function,+,ble_glue_start,_Bool,
|
Function,-,ble_glue_start,_Bool,
|
||||||
Function,+,ble_glue_thread_stop,void,
|
Function,-,ble_glue_stop,void,
|
||||||
Function,+,ble_glue_wait_for_c2_start,_Bool,int32_t
|
Function,+,ble_glue_wait_for_c2_start,_Bool,int32_t
|
||||||
|
Function,-,ble_profile_hid_consumer_key_press,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_consumer_key_release,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_consumer_key_release_all,_Bool,FuriHalBleProfileBase*
|
||||||
|
Function,-,ble_profile_hid_kb_press,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_kb_release,_Bool,"FuriHalBleProfileBase*, uint16_t"
|
||||||
|
Function,-,ble_profile_hid_kb_release_all,_Bool,FuriHalBleProfileBase*
|
||||||
|
Function,-,ble_profile_hid_mouse_move,_Bool,"FuriHalBleProfileBase*, int8_t, int8_t"
|
||||||
|
Function,-,ble_profile_hid_mouse_press,_Bool,"FuriHalBleProfileBase*, uint8_t"
|
||||||
|
Function,-,ble_profile_hid_mouse_release,_Bool,"FuriHalBleProfileBase*, uint8_t"
|
||||||
|
Function,-,ble_profile_hid_mouse_release_all,_Bool,FuriHalBleProfileBase*
|
||||||
|
Function,-,ble_profile_hid_mouse_scroll,_Bool,"FuriHalBleProfileBase*, int8_t"
|
||||||
|
Function,+,ble_profile_serial_notify_buffer_is_empty,void,FuriHalBleProfileBase*
|
||||||
|
Function,+,ble_profile_serial_set_event_callback,void,"FuriHalBleProfileBase*, uint16_t, FuriHalBtSerialCallback, void*"
|
||||||
|
Function,+,ble_profile_serial_set_rpc_active,void,"FuriHalBleProfileBase*, _Bool"
|
||||||
|
Function,+,ble_profile_serial_tx,_Bool,"FuriHalBleProfileBase*, uint8_t*, uint16_t"
|
||||||
|
Function,+,ble_svc_battery_start,BleServiceBattery*,_Bool
|
||||||
|
Function,+,ble_svc_battery_state_update,void,"uint8_t*, _Bool*"
|
||||||
|
Function,+,ble_svc_battery_stop,void,BleServiceBattery*
|
||||||
|
Function,+,ble_svc_battery_update_level,_Bool,"BleServiceBattery*, uint8_t"
|
||||||
|
Function,+,ble_svc_battery_update_power_state,_Bool,"BleServiceBattery*, _Bool"
|
||||||
|
Function,+,ble_svc_dev_info_start,BleServiceDevInfo*,
|
||||||
|
Function,+,ble_svc_dev_info_stop,void,BleServiceDevInfo*
|
||||||
|
Function,-,ble_svc_hid_start,BleServiceHid*,
|
||||||
|
Function,-,ble_svc_hid_stop,void,BleServiceHid*
|
||||||
|
Function,-,ble_svc_hid_update_info,_Bool,"BleServiceHid*, uint8_t*"
|
||||||
|
Function,-,ble_svc_hid_update_input_report,_Bool,"BleServiceHid*, uint8_t, uint8_t*, uint16_t"
|
||||||
|
Function,-,ble_svc_hid_update_report_map,_Bool,"BleServiceHid*, const uint8_t*, uint16_t"
|
||||||
|
Function,+,ble_svc_serial_notify_buffer_is_empty,void,BleServiceSerial*
|
||||||
|
Function,+,ble_svc_serial_set_callbacks,void,"BleServiceSerial*, uint16_t, SerialServiceEventCallback, void*"
|
||||||
|
Function,+,ble_svc_serial_set_rpc_active,void,"BleServiceSerial*, _Bool"
|
||||||
|
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,-,bsearch,void*,"const void*, const void*, size_t, size_t, __compar_fn_t"
|
||||||
Function,-,bt_close_rpc_connection,void,Bt*
|
Function,-,bt_close_rpc_connection,void,Bt*
|
||||||
Function,+,bt_disable_peer_key_update,void,Bt*
|
|
||||||
Function,+,bt_disconnect,void,Bt*
|
Function,+,bt_disconnect,void,Bt*
|
||||||
Function,+,bt_enable_peer_key_update,void,Bt*
|
|
||||||
Function,+,bt_forget_bonded_devices,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_default_path,void,Bt*
|
||||||
Function,+,bt_keys_storage_set_storage_path,void,"Bt*, const char*"
|
Function,+,bt_keys_storage_set_storage_path,void,"Bt*, const char*"
|
||||||
Function,-,bt_open_rpc_connection,void,Bt*
|
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_remote_rssi,_Bool,"Bt*, uint8_t*"
|
||||||
Function,+,bt_set_profile,_Bool,"Bt*, BtProfile"
|
|
||||||
Function,+,bt_set_profile_adv_name,void,"Bt*, const char*, ..."
|
|
||||||
Function,+,bt_set_profile_mac_address,void,"Bt*, const uint8_t[6]"
|
|
||||||
Function,+,bt_set_profile_pairing_method,void,"Bt*, GapPairing"
|
|
||||||
Function,+,bt_set_status_changed_callback,void,"Bt*, BtStatusChangedCallback, void*"
|
Function,+,bt_set_status_changed_callback,void,"Bt*, BtStatusChangedCallback, void*"
|
||||||
Function,-,bt_settings_load,_Bool,BtSettings*
|
Function,-,bt_settings_load,_Bool,BtSettings*
|
||||||
Function,+,bt_settings_save,_Bool,BtSettings*
|
Function,+,bt_settings_save,_Bool,BtSettings*
|
||||||
@@ -1184,59 +1232,37 @@ Function,+,furi_event_flag_get,uint32_t,FuriEventFlag*
|
|||||||
Function,+,furi_event_flag_set,uint32_t,"FuriEventFlag*, uint32_t"
|
Function,+,furi_event_flag_set,uint32_t,"FuriEventFlag*, uint32_t"
|
||||||
Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, uint32_t"
|
Function,+,furi_event_flag_wait,uint32_t,"FuriEventFlag*, uint32_t, uint32_t, uint32_t"
|
||||||
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,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_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_extra_beacon_get_config,const GapExtraBeaconConfig*,
|
||||||
|
Function,+,furi_hal_bt_extra_beacon_get_data,uint8_t,uint8_t*
|
||||||
|
Function,+,furi_hal_bt_extra_beacon_is_active,_Bool,
|
||||||
|
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_conn_rssi,uint32_t,uint8_t*
|
||||||
Function,-,furi_hal_bt_get_hardfault_info,const FuriHalBtHardfaultInfo*,
|
|
||||||
Function,+,furi_hal_bt_get_key_storage_buff,void,"uint8_t**, uint16_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_radio_stack,FuriHalBtStack,
|
||||||
Function,+,furi_hal_bt_get_rssi,float,
|
Function,+,furi_hal_bt_get_rssi,float,
|
||||||
Function,+,furi_hal_bt_get_transmitted_packets,uint32_t,
|
Function,+,furi_hal_bt_get_transmitted_packets,uint32_t,
|
||||||
Function,+,furi_hal_bt_hid_consumer_key_press,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_consumer_key_release,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_consumer_key_release_all,_Bool,
|
|
||||||
Function,+,furi_hal_bt_hid_get_led_state,uint8_t,
|
|
||||||
Function,+,furi_hal_bt_hid_kb_press,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_kb_release,_Bool,uint16_t
|
|
||||||
Function,+,furi_hal_bt_hid_kb_release_all,_Bool,
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_move,_Bool,"int8_t, int8_t"
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_press,_Bool,uint8_t
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_release,_Bool,uint8_t
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_release_all,_Bool,
|
|
||||||
Function,+,furi_hal_bt_hid_mouse_scroll,_Bool,int8_t
|
|
||||||
Function,+,furi_hal_bt_hid_start,void,
|
|
||||||
Function,+,furi_hal_bt_hid_stop,void,
|
|
||||||
Function,-,furi_hal_bt_init,void,
|
Function,-,furi_hal_bt_init,void,
|
||||||
Function,+,furi_hal_bt_is_active,_Bool,
|
Function,+,furi_hal_bt_is_active,_Bool,
|
||||||
Function,+,furi_hal_bt_is_alive,_Bool,
|
Function,+,furi_hal_bt_is_alive,_Bool,
|
||||||
Function,+,furi_hal_bt_is_ble_gatt_gap_supported,_Bool,
|
|
||||||
Function,+,furi_hal_bt_is_connected,_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_is_testing_supported,_Bool,
|
||||||
Function,+,furi_hal_bt_lock_core2,void,
|
Function,+,furi_hal_bt_lock_core2,void,
|
||||||
Function,+,furi_hal_bt_nvm_sram_sem_acquire,void,
|
Function,+,furi_hal_bt_nvm_sram_sem_acquire,void,
|
||||||
Function,+,furi_hal_bt_nvm_sram_sem_release,void,
|
Function,+,furi_hal_bt_nvm_sram_sem_release,void,
|
||||||
Function,+,furi_hal_bt_reinit,void,
|
Function,+,furi_hal_bt_reinit,void,
|
||||||
Function,+,furi_hal_bt_reverse_mac_addr,void,uint8_t[( 6 )]
|
Function,+,furi_hal_bt_reverse_mac_addr,void,uint8_t[( 6 )]
|
||||||
Function,+,furi_hal_bt_serial_notify_buffer_is_empty,void,
|
|
||||||
Function,+,furi_hal_bt_serial_set_event_callback,void,"uint16_t, FuriHalBtSerialCallback, void*"
|
|
||||||
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_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[( 18 + 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_advertising,void,
|
||||||
Function,+,furi_hal_bt_start_app,_Bool,"FuriHalBtProfile, GapEventCallback, 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"
|
Function,+,furi_hal_bt_start_packet_rx,void,"uint8_t, uint8_t"
|
||||||
Function,+,furi_hal_bt_start_packet_tx,void,"uint8_t, uint8_t, uint8_t"
|
Function,+,furi_hal_bt_start_packet_tx,void,"uint8_t, uint8_t, uint8_t"
|
||||||
Function,+,furi_hal_bt_start_radio_stack,_Bool,
|
Function,+,furi_hal_bt_start_radio_stack,_Bool,
|
||||||
@@ -1248,7 +1274,7 @@ Function,+,furi_hal_bt_stop_rx,void,
|
|||||||
Function,+,furi_hal_bt_stop_tone_tx,void,
|
Function,+,furi_hal_bt_stop_tone_tx,void,
|
||||||
Function,+,furi_hal_bt_unlock_core2,void,
|
Function,+,furi_hal_bt_unlock_core2,void,
|
||||||
Function,+,furi_hal_bt_update_battery_level,void,uint8_t
|
Function,+,furi_hal_bt_update_battery_level,void,uint8_t
|
||||||
Function,+,furi_hal_bt_update_power_state,void,
|
Function,+,furi_hal_bt_update_power_state,void,_Bool
|
||||||
Function,+,furi_hal_bus_deinit_early,void,
|
Function,+,furi_hal_bus_deinit_early,void,
|
||||||
Function,+,furi_hal_bus_disable,void,FuriHalBus
|
Function,+,furi_hal_bus_disable,void,FuriHalBus
|
||||||
Function,+,furi_hal_bus_enable,void,FuriHalBus
|
Function,+,furi_hal_bus_enable,void,FuriHalBus
|
||||||
@@ -1820,6 +1846,7 @@ Function,+,furi_thread_get_current_priority,FuriThreadPriority,
|
|||||||
Function,+,furi_thread_get_heap_size,size_t,FuriThread*
|
Function,+,furi_thread_get_heap_size,size_t,FuriThread*
|
||||||
Function,+,furi_thread_get_id,FuriThreadId,FuriThread*
|
Function,+,furi_thread_get_id,FuriThreadId,FuriThread*
|
||||||
Function,+,furi_thread_get_name,const char*,FuriThreadId
|
Function,+,furi_thread_get_name,const char*,FuriThreadId
|
||||||
|
Function,+,furi_thread_get_priority,FuriThreadPriority,FuriThread*
|
||||||
Function,+,furi_thread_get_return_code,int32_t,FuriThread*
|
Function,+,furi_thread_get_return_code,int32_t,FuriThread*
|
||||||
Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId
|
Function,+,furi_thread_get_stack_space,uint32_t,FuriThreadId
|
||||||
Function,+,furi_thread_get_state,FuriThreadState,FuriThread*
|
Function,+,furi_thread_get_state,FuriThreadState,FuriThread*
|
||||||
@@ -1859,6 +1886,15 @@ Function,-,gamma,double,double
|
|||||||
Function,-,gamma_r,double,"double, int*"
|
Function,-,gamma_r,double,"double, int*"
|
||||||
Function,-,gammaf,float,float
|
Function,-,gammaf,float,float
|
||||||
Function,-,gammaf_r,float,"float, int*"
|
Function,-,gammaf_r,float,"float, int*"
|
||||||
|
Function,-,gap_emit_ble_beacon_status_event,void,_Bool
|
||||||
|
Function,-,gap_extra_beacon_get_config,const GapExtraBeaconConfig*,
|
||||||
|
Function,-,gap_extra_beacon_get_data,uint8_t,uint8_t*
|
||||||
|
Function,-,gap_extra_beacon_get_state,GapExtraBeaconState,
|
||||||
|
Function,-,gap_extra_beacon_init,void,
|
||||||
|
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_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*"
|
||||||
@@ -1884,6 +1920,7 @@ Function,+,gui_set_hide_statusbar,void,"Gui*, _Bool"
|
|||||||
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
||||||
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
||||||
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
||||||
|
Function,-,hci_send_req,int,"hci_request*, uint8_t"
|
||||||
Function,+,hex_char_to_hex_nibble,_Bool,"char, uint8_t*"
|
Function,+,hex_char_to_hex_nibble,_Bool,"char, uint8_t*"
|
||||||
Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*"
|
Function,+,hex_char_to_uint8,_Bool,"char, char, uint8_t*"
|
||||||
Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*"
|
Function,+,hex_chars_to_uint64,_Bool,"const char*, uint64_t*"
|
||||||
@@ -2986,13 +3023,6 @@ Function,+,scene_manager_stop,void,SceneManager*
|
|||||||
Function,+,sd_api_get_fs_type_text,const char*,SDFsType
|
Function,+,sd_api_get_fs_type_text,const char*,SDFsType
|
||||||
Function,-,secure_getenv,char*,const char*
|
Function,-,secure_getenv,char*,const char*
|
||||||
Function,-,seed48,unsigned short*,unsigned short[3]
|
Function,-,seed48,unsigned short*,unsigned short[3]
|
||||||
Function,-,serial_svc_is_started,_Bool,
|
|
||||||
Function,-,serial_svc_notify_buffer_is_empty,void,
|
|
||||||
Function,-,serial_svc_set_callbacks,void,"uint16_t, SerialServiceEventCallback, void*"
|
|
||||||
Function,-,serial_svc_set_rpc_status,void,SerialServiceRpcStatus
|
|
||||||
Function,-,serial_svc_start,void,
|
|
||||||
Function,-,serial_svc_stop,void,
|
|
||||||
Function,-,serial_svc_update_tx,_Bool,"uint8_t*, uint16_t"
|
|
||||||
Function,-,setbuf,void,"FILE*, char*"
|
Function,-,setbuf,void,"FILE*, char*"
|
||||||
Function,-,setbuffer,void,"FILE*, char*, int"
|
Function,-,setbuffer,void,"FILE*, char*, int"
|
||||||
Function,-,setenv,int,"const char*, const char*, int"
|
Function,-,setenv,int,"const char*, const char*, int"
|
||||||
@@ -3683,6 +3713,7 @@ Variable,+,I_ArrowUpEmpty_14x15,Icon,
|
|||||||
Variable,+,I_ArrowUpFilled_14x15,Icon,
|
Variable,+,I_ArrowUpFilled_14x15,Icon,
|
||||||
Variable,+,I_Auth_62x31,Icon,
|
Variable,+,I_Auth_62x31,Icon,
|
||||||
Variable,+,I_BLE_Pairing_128x64,Icon,
|
Variable,+,I_BLE_Pairing_128x64,Icon,
|
||||||
|
Variable,+,I_BLE_beacon_7x8,Icon,
|
||||||
Variable,+,I_Background_128x11,Icon,
|
Variable,+,I_Background_128x11,Icon,
|
||||||
Variable,+,I_BatteryBody_52x28,Icon,
|
Variable,+,I_BatteryBody_52x28,Icon,
|
||||||
Variable,+,I_Battery_16x16,Icon,
|
Variable,+,I_Battery_16x16,Icon,
|
||||||
@@ -3920,6 +3951,8 @@ Variable,+,_impure_data,_reent,
|
|||||||
Variable,+,_impure_ptr,_reent*,
|
Variable,+,_impure_ptr,_reent*,
|
||||||
Variable,-,_sys_errlist,const char*[],
|
Variable,-,_sys_errlist,const char*[],
|
||||||
Variable,-,_sys_nerr,int,
|
Variable,-,_sys_nerr,int,
|
||||||
|
Variable,-,ble_profile_hid,const FuriHalBleProfileTemplate*,
|
||||||
|
Variable,-,ble_profile_serial,const FuriHalBleProfileTemplate*,
|
||||||
Variable,+,cli_vcp,CliSession,
|
Variable,+,cli_vcp,CliSession,
|
||||||
Variable,+,firmware_api_interface,const ElfApiInterface*,
|
Variable,+,firmware_api_interface,const ElfApiInterface*,
|
||||||
Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus,
|
Variable,+,furi_hal_i2c_bus_external,FuriHalI2cBus,
|
||||||
|
|||||||
|
@@ -7,6 +7,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include <core/common_defines.h>
|
#include <core/common_defines.h>
|
||||||
#include <tl.h>
|
#include <interface/patterns/ble_thread/tl/tl.h>
|
||||||
|
|
||||||
#include "app_conf.h"
|
#include "app_conf.h"
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
* Maximum number of simultaneous connections that the device will support.
|
* Maximum number of simultaneous connections that the device will support.
|
||||||
* Valid values are from 1 to 8
|
* Valid values are from 1 to 8
|
||||||
*/
|
*/
|
||||||
#define CFG_BLE_NUM_LINK 1
|
#define CFG_BLE_NUM_LINK 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of Services that can be stored in the GATT database.
|
* Maximum number of Services that can be stored in the GATT database.
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
#include "ble_app.h"
|
#include "ble_app.h"
|
||||||
|
|
||||||
|
#include <core/check.h>
|
||||||
#include <ble/ble.h>
|
#include <ble/ble.h>
|
||||||
#include <interface/patterns/ble_thread/tl/hci_tl.h>
|
#include <interface/patterns/ble_thread/tl/hci_tl.h>
|
||||||
#include <interface/patterns/ble_thread/shci/shci.h>
|
#include <interface/patterns/ble_thread/shci/shci.h>
|
||||||
#include "gap.h"
|
#include "gap.h"
|
||||||
|
#include "furi_ble/event_dispatcher.h"
|
||||||
|
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
|
||||||
#define TAG "Bt"
|
#define TAG "Bt"
|
||||||
|
|
||||||
#define BLE_APP_FLAG_HCI_EVENT (1UL << 0)
|
|
||||||
#define BLE_APP_FLAG_KILL_THREAD (1UL << 1)
|
|
||||||
#define BLE_APP_FLAG_ALL (BLE_APP_FLAG_HCI_EVENT | BLE_APP_FLAG_KILL_THREAD)
|
|
||||||
|
|
||||||
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer;
|
PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static TL_CmdPacket_t ble_app_cmd_buffer;
|
||||||
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint32_t ble_app_nvm[BLE_NVM_SRAM_SIZE];
|
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint32_t ble_app_nvm[BLE_NVM_SRAM_SIZE];
|
||||||
|
|
||||||
@@ -24,12 +22,10 @@ _Static_assert(
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
FuriMutex* hci_mtx;
|
FuriMutex* hci_mtx;
|
||||||
FuriSemaphore* hci_sem;
|
FuriSemaphore* hci_sem;
|
||||||
FuriThread* thread;
|
|
||||||
} BleApp;
|
} BleApp;
|
||||||
|
|
||||||
static BleApp* ble_app = NULL;
|
static BleApp* ble_app = NULL;
|
||||||
|
|
||||||
static int32_t ble_app_hci_thread(void* context);
|
|
||||||
static void ble_app_hci_event_handler(void* pPayload);
|
static void ble_app_hci_event_handler(void* pPayload);
|
||||||
static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
|
static void ble_app_hci_status_not_handler(HCI_TL_CmdStatus_t status);
|
||||||
|
|
||||||
@@ -81,30 +77,35 @@ static const SHCI_C2_Ble_Init_Cmd_Packet_t ble_init_cmd_packet = {
|
|||||||
SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY,
|
SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY,
|
||||||
}};
|
}};
|
||||||
|
|
||||||
bool ble_app_init() {
|
bool ble_app_init(void) {
|
||||||
SHCI_CmdStatus_t status;
|
SHCI_CmdStatus_t status;
|
||||||
ble_app = malloc(sizeof(BleApp));
|
ble_app = malloc(sizeof(BleApp));
|
||||||
// Allocate semafore and mutex for ble command buffer access
|
// Allocate semafore and mutex for ble command buffer access
|
||||||
ble_app->hci_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
ble_app->hci_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||||
ble_app->hci_sem = furi_semaphore_alloc(1, 0);
|
ble_app->hci_sem = furi_semaphore_alloc(1, 0);
|
||||||
// HCI transport layer thread to handle user asynch events
|
|
||||||
ble_app->thread = furi_thread_alloc_ex("BleHciDriver", 1024, ble_app_hci_thread, ble_app);
|
|
||||||
furi_thread_start(ble_app->thread);
|
|
||||||
|
|
||||||
// Initialize Ble Transport Layer
|
// Initialize Ble Transport Layer
|
||||||
hci_init(ble_app_hci_event_handler, (void*)&hci_tl_config);
|
hci_init(ble_app_hci_event_handler, (void*)&hci_tl_config);
|
||||||
|
|
||||||
// Configure NVM store for pairing data
|
do {
|
||||||
status = SHCI_C2_Config((SHCI_C2_CONFIG_Cmd_Param_t*)&config_param);
|
// Configure NVM store for pairing data
|
||||||
if(status) {
|
if((status = SHCI_C2_Config((SHCI_C2_CONFIG_Cmd_Param_t*)&config_param))) {
|
||||||
FURI_LOG_E(TAG, "Failed to configure 2nd core: %d", status);
|
FURI_LOG_E(TAG, "Failed to configure 2nd core: %d", status);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start ble stack on 2nd core
|
||||||
|
if((status = SHCI_C2_BLE_Init((SHCI_C2_Ble_Init_Cmd_Packet_t*)&ble_init_cmd_packet))) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to start ble stack: %d", status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((status = SHCI_C2_SetFlashActivityControl(FLASH_ACTIVITY_CONTROL_SEM7))) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to set flash activity control: %d", status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while(false);
|
||||||
|
|
||||||
// Start ble stack on 2nd core
|
|
||||||
status = SHCI_C2_BLE_Init((SHCI_C2_Ble_Init_Cmd_Packet_t*)&ble_init_cmd_packet);
|
|
||||||
if(status) {
|
|
||||||
FURI_LOG_E(TAG, "Failed to start ble stack: %d", status);
|
|
||||||
}
|
|
||||||
return status == SHCI_Success;
|
return status == SHCI_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,48 +114,19 @@ void ble_app_get_key_storage_buff(uint8_t** addr, uint16_t* size) {
|
|||||||
*size = sizeof(ble_app_nvm);
|
*size = sizeof(ble_app_nvm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ble_app_thread_stop() {
|
void ble_app_deinit(void) {
|
||||||
if(ble_app) {
|
|
||||||
FuriThreadId thread_id = furi_thread_get_id(ble_app->thread);
|
|
||||||
furi_assert(thread_id);
|
|
||||||
furi_thread_flags_set(thread_id, BLE_APP_FLAG_KILL_THREAD);
|
|
||||||
furi_thread_join(ble_app->thread);
|
|
||||||
furi_thread_free(ble_app->thread);
|
|
||||||
// Free resources
|
|
||||||
furi_mutex_free(ble_app->hci_mtx);
|
|
||||||
furi_semaphore_free(ble_app->hci_sem);
|
|
||||||
free(ble_app);
|
|
||||||
ble_app = NULL;
|
|
||||||
memset(&ble_app_cmd_buffer, 0, sizeof(ble_app_cmd_buffer));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t ble_app_hci_thread(void* arg) {
|
|
||||||
UNUSED(arg);
|
|
||||||
uint32_t flags = 0;
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
flags = furi_thread_flags_wait(BLE_APP_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
|
||||||
if(flags & BLE_APP_FLAG_KILL_THREAD) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(flags & BLE_APP_FLAG_HCI_EVENT) {
|
|
||||||
hci_user_evt_proc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called by WPAN lib
|
|
||||||
void hci_notify_asynch_evt(void* pdata) {
|
|
||||||
UNUSED(pdata);
|
|
||||||
furi_check(ble_app);
|
furi_check(ble_app);
|
||||||
FuriThreadId thread_id = furi_thread_get_id(ble_app->thread);
|
|
||||||
furi_assert(thread_id);
|
furi_mutex_free(ble_app->hci_mtx);
|
||||||
furi_thread_flags_set(thread_id, BLE_APP_FLAG_HCI_EVENT);
|
furi_semaphore_free(ble_app->hci_sem);
|
||||||
|
free(ble_app);
|
||||||
|
ble_app = NULL;
|
||||||
|
memset(&ble_app_cmd_buffer, 0, sizeof(ble_app_cmd_buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// AN5289, 4.9
|
||||||
|
|
||||||
void hci_cmd_resp_release(uint32_t flag) {
|
void hci_cmd_resp_release(uint32_t flag) {
|
||||||
UNUSED(flag);
|
UNUSED(flag);
|
||||||
furi_check(ble_app);
|
furi_check(ble_app);
|
||||||
@@ -166,13 +138,16 @@ void hci_cmd_resp_wait(uint32_t timeout) {
|
|||||||
furi_check(furi_semaphore_acquire(ble_app->hci_sem, timeout) == FuriStatusOk);
|
furi_check(furi_semaphore_acquire(ble_app->hci_sem, timeout) == FuriStatusOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ble_app_hci_event_handler(void* pPayload) {
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
SVCCTL_UserEvtFlowStatus_t svctl_return_status;
|
|
||||||
tHCI_UserEvtRxParam* pParam = (tHCI_UserEvtRxParam*)pPayload;
|
|
||||||
|
|
||||||
|
static void ble_app_hci_event_handler(void* pPayload) {
|
||||||
furi_check(ble_app);
|
furi_check(ble_app);
|
||||||
svctl_return_status = SVCCTL_UserEvtRx((void*)&(pParam->pckt->evtserial));
|
|
||||||
if(svctl_return_status != SVCCTL_UserEvtFlowDisable) {
|
tHCI_UserEvtRxParam* pParam = (tHCI_UserEvtRxParam*)pPayload;
|
||||||
|
BleEventFlowStatus event_flow_status =
|
||||||
|
ble_event_dispatcher_process_event((void*)&(pParam->pckt->evtserial));
|
||||||
|
|
||||||
|
if(event_flow_status != BleEventFlowDisable) {
|
||||||
pParam->status = HCI_TL_UserEventFlow_Enable;
|
pParam->status = HCI_TL_UserEventFlow_Enable;
|
||||||
} else {
|
} else {
|
||||||
pParam->status = HCI_TL_UserEventFlow_Disable;
|
pParam->status = HCI_TL_UserEventFlow_Disable;
|
||||||
|
|||||||
@@ -3,13 +3,19 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BLE stack init and cleanup
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool ble_app_init();
|
bool ble_app_init(void);
|
||||||
|
|
||||||
void ble_app_get_key_storage_buff(uint8_t** addr, uint16_t* size);
|
void ble_app_get_key_storage_buff(uint8_t** addr, uint16_t* size);
|
||||||
void ble_app_thread_stop();
|
|
||||||
|
void ble_app_deinit(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,9 @@
|
|||||||
#include "app_conf.h"
|
#include "app_conf.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is one handler per service enabled
|
* We're not using WPAN's event dispatchers
|
||||||
* Note: There is no handler for the Device Information Service
|
* so both client & service max callback count is set to 0.
|
||||||
*
|
|
||||||
* This shall take into account all registered handlers
|
|
||||||
* (from either the provided services or the custom services)
|
|
||||||
*/
|
*/
|
||||||
#define BLE_CFG_SVC_MAX_NBR_CB 7
|
#define BLE_CFG_SVC_MAX_NBR_CB 0
|
||||||
|
|
||||||
#define BLE_CFG_CLT_MAX_NBR_CB 0
|
#define BLE_CFG_CLT_MAX_NBR_CB 0
|
||||||
|
|||||||
96
targets/f7/ble_glue/ble_event_thread.c
Normal file
96
targets/f7/ble_glue/ble_event_thread.c
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#include "app_common.h"
|
||||||
|
|
||||||
|
#include <core/check.h>
|
||||||
|
#include <core/thread.h>
|
||||||
|
#include <core/log.h>
|
||||||
|
|
||||||
|
#include <interface/patterns/ble_thread/tl/shci_tl.h>
|
||||||
|
#include <interface/patterns/ble_thread/tl/hci_tl.h>
|
||||||
|
|
||||||
|
#define TAG "BleEvt"
|
||||||
|
|
||||||
|
#define BLE_EVENT_THREAD_FLAG_SHCI_EVENT (1UL << 0)
|
||||||
|
#define BLE_EVENT_THREAD_FLAG_HCI_EVENT (1UL << 1)
|
||||||
|
#define BLE_EVENT_THREAD_FLAG_KILL_THREAD (1UL << 2)
|
||||||
|
|
||||||
|
#define BLE_EVENT_THREAD_FLAG_ALL \
|
||||||
|
(BLE_EVENT_THREAD_FLAG_SHCI_EVENT | BLE_EVENT_THREAD_FLAG_HCI_EVENT | \
|
||||||
|
BLE_EVENT_THREAD_FLAG_KILL_THREAD)
|
||||||
|
|
||||||
|
static FuriThread* event_thread = NULL;
|
||||||
|
|
||||||
|
static int32_t ble_event_thread(void* context) {
|
||||||
|
UNUSED(context);
|
||||||
|
uint32_t flags = 0;
|
||||||
|
|
||||||
|
while((flags & BLE_EVENT_THREAD_FLAG_KILL_THREAD) == 0) {
|
||||||
|
flags =
|
||||||
|
furi_thread_flags_wait(BLE_EVENT_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
||||||
|
if(flags & BLE_EVENT_THREAD_FLAG_SHCI_EVENT) {
|
||||||
|
#ifdef FURI_BLE_EXTRA_LOG
|
||||||
|
FURI_LOG_W(TAG, "shci_user_evt_proc");
|
||||||
|
#endif
|
||||||
|
shci_user_evt_proc();
|
||||||
|
}
|
||||||
|
if(flags & BLE_EVENT_THREAD_FLAG_HCI_EVENT) {
|
||||||
|
#ifdef FURI_BLE_EXTRA_LOG
|
||||||
|
FURI_LOG_W(TAG, "hci_user_evt_proc");
|
||||||
|
#endif
|
||||||
|
hci_user_evt_proc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void shci_notify_asynch_evt(void* pdata) {
|
||||||
|
UNUSED(pdata);
|
||||||
|
if(!event_thread) {
|
||||||
|
#ifdef FURI_BLE_EXTRA_LOG
|
||||||
|
FURI_LOG_E(TAG, "shci: event_thread is NULL");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FuriThreadId thread_id = furi_thread_get_id(event_thread);
|
||||||
|
furi_assert(thread_id);
|
||||||
|
furi_thread_flags_set(thread_id, BLE_EVENT_THREAD_FLAG_SHCI_EVENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hci_notify_asynch_evt(void* pdata) {
|
||||||
|
UNUSED(pdata);
|
||||||
|
if(!event_thread) {
|
||||||
|
#ifdef FURI_BLE_EXTRA_LOG
|
||||||
|
FURI_LOG_E(TAG, "hci: event_thread is NULL");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FuriThreadId thread_id = furi_thread_get_id(event_thread);
|
||||||
|
furi_assert(thread_id);
|
||||||
|
furi_thread_flags_set(thread_id, BLE_EVENT_THREAD_FLAG_HCI_EVENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_event_thread_stop(void) {
|
||||||
|
if(!event_thread) {
|
||||||
|
#ifdef FURI_BLE_EXTRA_LOG
|
||||||
|
FURI_LOG_E(TAG, "thread_stop: event_thread is NULL");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FuriThreadId thread_id = furi_thread_get_id(event_thread);
|
||||||
|
furi_assert(thread_id);
|
||||||
|
furi_thread_flags_set(thread_id, BLE_EVENT_THREAD_FLAG_KILL_THREAD);
|
||||||
|
furi_thread_join(event_thread);
|
||||||
|
furi_thread_free(event_thread);
|
||||||
|
event_thread = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_event_thread_start(void) {
|
||||||
|
furi_check(event_thread == NULL);
|
||||||
|
|
||||||
|
event_thread = furi_thread_alloc_ex("BleEventWorker", 1024, ble_event_thread, NULL);
|
||||||
|
furi_thread_set_priority(event_thread, FuriThreadPriorityHigh);
|
||||||
|
furi_thread_start(event_thread);
|
||||||
|
}
|
||||||
15
targets/f7/ble_glue/ble_event_thread.h
Normal file
15
targets/f7/ble_glue/ble_event_thread.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Controls for thread handling SHCI & HCI event queues. Used internally. */
|
||||||
|
|
||||||
|
void ble_event_thread_start(void);
|
||||||
|
|
||||||
|
void ble_event_thread_stop(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
#include "ble_glue.h"
|
#include "ble_glue.h"
|
||||||
#include "app_common.h"
|
#include "app_common.h"
|
||||||
#include "ble_app.h"
|
#include "ble_app.h"
|
||||||
|
#include "ble_event_thread.h"
|
||||||
|
|
||||||
|
#include <furi_hal_cortex.h>
|
||||||
|
#include <core/mutex.h>
|
||||||
|
#include <core/timer.h>
|
||||||
#include <ble/ble.h>
|
#include <ble/ble.h>
|
||||||
#include <hci_tl.h>
|
#include <hci_tl.h>
|
||||||
|
|
||||||
@@ -13,26 +18,26 @@
|
|||||||
|
|
||||||
#define TAG "Core2"
|
#define TAG "Core2"
|
||||||
|
|
||||||
#define BLE_GLUE_FLAG_SHCI_EVENT (1UL << 0)
|
#define BLE_GLUE_HARDFAULT_CHECK_PERIOD_MS (5000)
|
||||||
#define BLE_GLUE_FLAG_KILL_THREAD (1UL << 1)
|
|
||||||
#define BLE_GLUE_FLAG_ALL (BLE_GLUE_FLAG_SHCI_EVENT | BLE_GLUE_FLAG_KILL_THREAD)
|
#define BLE_GLUE_HARDFAULT_INFO_MAGIC (0x1170FD0F)
|
||||||
|
|
||||||
#define POOL_SIZE \
|
#define POOL_SIZE \
|
||||||
(CFG_TLBLE_EVT_QUEUE_LENGTH * 4U * \
|
(CFG_TLBLE_EVT_QUEUE_LENGTH * 4U * \
|
||||||
DIVC((sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE), 4U))
|
DIVC((sizeof(TL_PacketHeader_t) + TL_BLE_EVENT_FRAME_SIZE), 4U))
|
||||||
|
|
||||||
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ble_glue_event_pool[POOL_SIZE];
|
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ble_event_pool[POOL_SIZE];
|
||||||
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t ble_glue_system_cmd_buff;
|
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t ble_glue_cmd_buff;
|
||||||
PLACE_IN_SECTION("MB_MEM2")
|
PLACE_IN_SECTION("MB_MEM2")
|
||||||
ALIGN(4)
|
ALIGN(4)
|
||||||
static uint8_t ble_glue_system_spare_event_buff[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255U];
|
static uint8_t ble_glue_spare_event_buff[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255U];
|
||||||
PLACE_IN_SECTION("MB_MEM2")
|
PLACE_IN_SECTION("MB_MEM2")
|
||||||
ALIGN(4)
|
ALIGN(4)
|
||||||
static uint8_t ble_glue_ble_spare_event_buff[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255];
|
static uint8_t ble_spare_event_buff[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255];
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FuriMutex* shci_mtx;
|
FuriMutex* shci_mtx;
|
||||||
FuriThread* thread;
|
FuriTimer* hardfault_check_timer;
|
||||||
BleGlueStatus status;
|
BleGlueStatus status;
|
||||||
BleGlueKeyStorageChangedCallback callback;
|
BleGlueKeyStorageChangedCallback callback;
|
||||||
BleGlueC2Info c2_info;
|
BleGlueC2Info c2_info;
|
||||||
@@ -41,9 +46,10 @@ typedef struct {
|
|||||||
|
|
||||||
static BleGlue* ble_glue = NULL;
|
static BleGlue* ble_glue = NULL;
|
||||||
|
|
||||||
static int32_t ble_glue_shci_thread(void* argument);
|
// static int32_t ble_glue_shci_thread(void* argument);
|
||||||
static void ble_glue_sys_status_not_callback(SHCI_TL_CmdStatus_t status);
|
static void ble_sys_status_not_callback(SHCI_TL_CmdStatus_t status);
|
||||||
static void ble_glue_sys_user_event_callback(void* pPayload);
|
static void ble_sys_user_event_callback(void* pPayload);
|
||||||
|
static void ble_glue_clear_shared_memory();
|
||||||
|
|
||||||
void ble_glue_set_key_storage_changed_callback(
|
void ble_glue_set_key_storage_changed_callback(
|
||||||
BleGlueKeyStorageChangedCallback callback,
|
BleGlueKeyStorageChangedCallback callback,
|
||||||
@@ -54,43 +60,21 @@ void ble_glue_set_key_storage_changed_callback(
|
|||||||
ble_glue->context = context;
|
ble_glue->context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
static void furi_hal_bt_hardfault_check(void* context) {
|
||||||
|
UNUSED(context);
|
||||||
/* TL hook to catch hardfaults */
|
if(ble_glue_get_hardfault_info()) {
|
||||||
|
|
||||||
int32_t ble_glue_TL_SYS_SendCmd(uint8_t* buffer, uint16_t size) {
|
|
||||||
if(furi_hal_bt_get_hardfault_info()) {
|
|
||||||
furi_crash("ST(R) Copro(R) HardFault");
|
furi_crash("ST(R) Copro(R) HardFault");
|
||||||
}
|
}
|
||||||
|
|
||||||
return TL_SYS_SendCmd(buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void shci_register_io_bus(tSHciIO* fops) {
|
|
||||||
/* Register IO bus services */
|
|
||||||
fops->Init = TL_SYS_Init;
|
|
||||||
fops->Send = ble_glue_TL_SYS_SendCmd;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t ble_glue_TL_BLE_SendCmd(uint8_t* buffer, uint16_t size) {
|
|
||||||
if(furi_hal_bt_get_hardfault_info()) {
|
|
||||||
furi_crash("ST(R) Copro(R) HardFault");
|
|
||||||
}
|
|
||||||
|
|
||||||
return TL_BLE_SendCmd(buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hci_register_io_bus(tHciIO* fops) {
|
|
||||||
/* Register IO bus services */
|
|
||||||
fops->Init = TL_BLE_Init;
|
|
||||||
fops->Send = ble_glue_TL_BLE_SendCmd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ble_glue_init() {
|
void ble_glue_init(void) {
|
||||||
ble_glue = malloc(sizeof(BleGlue));
|
ble_glue = malloc(sizeof(BleGlue));
|
||||||
ble_glue->status = BleGlueStatusStartup;
|
ble_glue->status = BleGlueStatusStartup;
|
||||||
|
ble_glue->hardfault_check_timer =
|
||||||
|
furi_timer_alloc(furi_hal_bt_hardfault_check, FuriTimerTypePeriodic, NULL);
|
||||||
|
furi_timer_start(ble_glue->hardfault_check_timer, BLE_GLUE_HARDFAULT_CHECK_PERIOD_MS);
|
||||||
|
|
||||||
#ifdef BLE_GLUE_DEBUG
|
#ifdef BLE_GLUE_DEBUG
|
||||||
APPD_Init();
|
APPD_Init();
|
||||||
@@ -105,18 +89,17 @@ void ble_glue_init() {
|
|||||||
ble_glue->shci_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
ble_glue->shci_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||||
|
|
||||||
// FreeRTOS system task creation
|
// FreeRTOS system task creation
|
||||||
ble_glue->thread = furi_thread_alloc_ex("BleShciDriver", 1024, ble_glue_shci_thread, ble_glue);
|
ble_event_thread_start();
|
||||||
furi_thread_start(ble_glue->thread);
|
|
||||||
|
|
||||||
// System channel initialization
|
// System channel initialization
|
||||||
SHci_Tl_Init_Conf.p_cmdbuffer = (uint8_t*)&ble_glue_system_cmd_buff;
|
SHci_Tl_Init_Conf.p_cmdbuffer = (uint8_t*)&ble_glue_cmd_buff;
|
||||||
SHci_Tl_Init_Conf.StatusNotCallBack = ble_glue_sys_status_not_callback;
|
SHci_Tl_Init_Conf.StatusNotCallBack = ble_sys_status_not_callback;
|
||||||
shci_init(ble_glue_sys_user_event_callback, (void*)&SHci_Tl_Init_Conf);
|
shci_init(ble_sys_user_event_callback, (void*)&SHci_Tl_Init_Conf);
|
||||||
|
|
||||||
/**< Memory Manager channel initialization */
|
/**< Memory Manager channel initialization */
|
||||||
tl_mm_config.p_BleSpareEvtBuffer = ble_glue_ble_spare_event_buff;
|
tl_mm_config.p_BleSpareEvtBuffer = ble_spare_event_buff;
|
||||||
tl_mm_config.p_SystemSpareEvtBuffer = ble_glue_system_spare_event_buff;
|
tl_mm_config.p_SystemSpareEvtBuffer = ble_glue_spare_event_buff;
|
||||||
tl_mm_config.p_AsynchEvtPool = ble_glue_event_pool;
|
tl_mm_config.p_AsynchEvtPool = ble_event_pool;
|
||||||
tl_mm_config.AsynchEvtPoolSize = POOL_SIZE;
|
tl_mm_config.AsynchEvtPoolSize = POOL_SIZE;
|
||||||
TL_MM_Init(&tl_mm_config);
|
TL_MM_Init(&tl_mm_config);
|
||||||
TL_Enable();
|
TL_Enable();
|
||||||
@@ -124,15 +107,15 @@ void ble_glue_init() {
|
|||||||
/*
|
/*
|
||||||
* From now, the application is waiting for the ready event ( VS_HCI_C2_Ready )
|
* From now, the application is waiting for the ready event ( VS_HCI_C2_Ready )
|
||||||
* received on the system channel before starting the Stack
|
* received on the system channel before starting the Stack
|
||||||
* This system event is received with ble_glue_sys_user_event_callback()
|
* This system event is received with ble_sys_user_event_callback()
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
const BleGlueC2Info* ble_glue_get_c2_info() {
|
const BleGlueC2Info* ble_glue_get_c2_info(void) {
|
||||||
return &ble_glue->c2_info;
|
return &ble_glue->c2_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
BleGlueStatus ble_glue_get_c2_status() {
|
BleGlueStatus ble_glue_get_c2_status(void) {
|
||||||
return ble_glue->status;
|
return ble_glue->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +142,7 @@ static const char* ble_glue_get_reltype_str(const uint8_t reltype) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ble_glue_update_c2_fw_info() {
|
static void ble_glue_update_c2_fw_info(void) {
|
||||||
WirelessFwInfo_t wireless_info;
|
WirelessFwInfo_t wireless_info;
|
||||||
SHCI_GetWirelessFwInfo(&wireless_info);
|
SHCI_GetWirelessFwInfo(&wireless_info);
|
||||||
BleGlueC2Info* local_info = &ble_glue->c2_info;
|
BleGlueC2Info* local_info = &ble_glue->c2_info;
|
||||||
@@ -178,7 +161,7 @@ static void ble_glue_update_c2_fw_info() {
|
|||||||
local_info->StackType = wireless_info.StackType;
|
local_info->StackType = wireless_info.StackType;
|
||||||
snprintf(
|
snprintf(
|
||||||
local_info->StackTypeString,
|
local_info->StackTypeString,
|
||||||
BLE_GLUE_MAX_VERSION_STRING_LEN,
|
BLE_MAX_VERSION_STRING_LEN,
|
||||||
"%d.%d.%d:%s",
|
"%d.%d.%d:%s",
|
||||||
local_info->VersionMajor,
|
local_info->VersionMajor,
|
||||||
local_info->VersionMinor,
|
local_info->VersionMinor,
|
||||||
@@ -193,7 +176,7 @@ static void ble_glue_update_c2_fw_info() {
|
|||||||
local_info->FusMemorySizeFlash = wireless_info.FusMemorySizeFlash;
|
local_info->FusMemorySizeFlash = wireless_info.FusMemorySizeFlash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ble_glue_dump_stack_info() {
|
static void ble_glue_dump_stack_info(void) {
|
||||||
const BleGlueC2Info* c2_info = &ble_glue->c2_info;
|
const BleGlueC2Info* c2_info = &ble_glue->c2_info;
|
||||||
FURI_LOG_I(
|
FURI_LOG_I(
|
||||||
TAG,
|
TAG,
|
||||||
@@ -216,59 +199,63 @@ static void ble_glue_dump_stack_info() {
|
|||||||
c2_info->MemorySizeFlash);
|
c2_info->MemorySizeFlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_glue_wait_for_c2_start(int32_t timeout) {
|
bool ble_glue_wait_for_c2_start(int32_t timeout_ms) {
|
||||||
bool started = false;
|
bool started = false;
|
||||||
|
|
||||||
|
FuriHalCortexTimer timer = furi_hal_cortex_timer_get(timeout_ms * 1000);
|
||||||
do {
|
do {
|
||||||
|
furi_delay_tick(1);
|
||||||
started = ble_glue->status == BleGlueStatusC2Started;
|
started = ble_glue->status == BleGlueStatusC2Started;
|
||||||
if(!started) {
|
} while(!started && !furi_hal_cortex_timer_is_expired(timer));
|
||||||
timeout--;
|
|
||||||
furi_delay_tick(1);
|
|
||||||
}
|
|
||||||
} while(!started && (timeout > 0));
|
|
||||||
|
|
||||||
if(started) {
|
if(!started) {
|
||||||
FURI_LOG_I(
|
|
||||||
TAG,
|
|
||||||
"C2 boot completed, mode: %s",
|
|
||||||
ble_glue->c2_info.mode == BleGlueC2ModeFUS ? "FUS" : "Stack");
|
|
||||||
ble_glue_update_c2_fw_info();
|
|
||||||
ble_glue_dump_stack_info();
|
|
||||||
} else {
|
|
||||||
FURI_LOG_E(TAG, "C2 startup failed");
|
FURI_LOG_E(TAG, "C2 startup failed");
|
||||||
ble_glue->status = BleGlueStatusBroken;
|
ble_glue->status = BleGlueStatusBroken;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return started;
|
FURI_LOG_I(
|
||||||
|
TAG,
|
||||||
|
"C2 boot completed, mode: %s",
|
||||||
|
ble_glue->c2_info.mode == BleGlueC2ModeFUS ? "FUS" : "Stack");
|
||||||
|
ble_glue_update_c2_fw_info();
|
||||||
|
ble_glue_dump_stack_info();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_glue_start() {
|
bool ble_glue_start(void) {
|
||||||
furi_assert(ble_glue);
|
furi_assert(ble_glue);
|
||||||
|
|
||||||
if(ble_glue->status != BleGlueStatusC2Started) {
|
if(ble_glue->status != BleGlueStatusC2Started) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = false;
|
if(!ble_app_init()) {
|
||||||
if(ble_app_init()) {
|
|
||||||
FURI_LOG_I(TAG, "Radio stack started");
|
|
||||||
ble_glue->status = BleGlueStatusRadioStackRunning;
|
|
||||||
ret = true;
|
|
||||||
if(SHCI_C2_SetFlashActivityControl(FLASH_ACTIVITY_CONTROL_SEM7) == SHCI_Success) {
|
|
||||||
FURI_LOG_I(TAG, "Flash activity control switched to SEM7");
|
|
||||||
} else {
|
|
||||||
FURI_LOG_E(TAG, "Failed to switch flash activity control to SEM7");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FURI_LOG_E(TAG, "Radio stack startup failed");
|
FURI_LOG_E(TAG, "Radio stack startup failed");
|
||||||
ble_glue->status = BleGlueStatusRadioStackMissing;
|
ble_glue->status = BleGlueStatusRadioStackMissing;
|
||||||
ble_app_thread_stop();
|
ble_app_deinit();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
FURI_LOG_I(TAG, "Radio stack started");
|
||||||
|
ble_glue->status = BleGlueStatusRadioStackRunning;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_glue_is_alive() {
|
void ble_glue_stop(void) {
|
||||||
|
furi_assert(ble_glue);
|
||||||
|
|
||||||
|
ble_event_thread_stop();
|
||||||
|
// Free resources
|
||||||
|
furi_mutex_free(ble_glue->shci_mtx);
|
||||||
|
furi_timer_free(ble_glue->hardfault_check_timer);
|
||||||
|
|
||||||
|
ble_glue_clear_shared_memory();
|
||||||
|
free(ble_glue);
|
||||||
|
ble_glue = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_glue_is_alive(void) {
|
||||||
if(!ble_glue) {
|
if(!ble_glue) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -276,7 +263,7 @@ bool ble_glue_is_alive() {
|
|||||||
return ble_glue->status >= BleGlueStatusC2Started;
|
return ble_glue->status >= BleGlueStatusC2Started;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_glue_is_radio_stack_ready() {
|
bool ble_glue_is_radio_stack_ready(void) {
|
||||||
if(!ble_glue) {
|
if(!ble_glue) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -319,7 +306,7 @@ BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode desired_mode) {
|
|||||||
return BleGlueCommandResultError;
|
return BleGlueCommandResultError;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ble_glue_sys_status_not_callback(SHCI_TL_CmdStatus_t status) {
|
static void ble_sys_status_not_callback(SHCI_TL_CmdStatus_t status) {
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case SHCI_TL_CmdBusy:
|
case SHCI_TL_CmdBusy:
|
||||||
furi_mutex_acquire(ble_glue->shci_mtx, FuriWaitForever);
|
furi_mutex_acquire(ble_glue->shci_mtx, FuriWaitForever);
|
||||||
@@ -341,7 +328,7 @@ static void ble_glue_sys_status_not_callback(SHCI_TL_CmdStatus_t status) {
|
|||||||
* ( eg ((tSHCI_UserEvtRxParam*)pPayload)->status shall be set to SHCI_TL_UserEventFlow_Disable )
|
* ( eg ((tSHCI_UserEvtRxParam*)pPayload)->status shall be set to SHCI_TL_UserEventFlow_Disable )
|
||||||
* When the status is not filled, the buffer is released by default
|
* When the status is not filled, the buffer is released by default
|
||||||
*/
|
*/
|
||||||
static void ble_glue_sys_user_event_callback(void* pPayload) {
|
static void ble_sys_user_event_callback(void* pPayload) {
|
||||||
UNUSED(pPayload);
|
UNUSED(pPayload);
|
||||||
|
|
||||||
#ifdef BLE_GLUE_DEBUG
|
#ifdef BLE_GLUE_DEBUG
|
||||||
@@ -375,60 +362,18 @@ static void ble_glue_sys_user_event_callback(void* pPayload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ble_glue_clear_shared_memory() {
|
static void ble_glue_clear_shared_memory(void) {
|
||||||
memset(ble_glue_event_pool, 0, sizeof(ble_glue_event_pool));
|
memset(ble_event_pool, 0, sizeof(ble_event_pool));
|
||||||
memset(&ble_glue_system_cmd_buff, 0, sizeof(ble_glue_system_cmd_buff));
|
memset(&ble_glue_cmd_buff, 0, sizeof(ble_glue_cmd_buff));
|
||||||
memset(ble_glue_system_spare_event_buff, 0, sizeof(ble_glue_system_spare_event_buff));
|
memset(ble_glue_spare_event_buff, 0, sizeof(ble_glue_spare_event_buff));
|
||||||
memset(ble_glue_ble_spare_event_buff, 0, sizeof(ble_glue_ble_spare_event_buff));
|
memset(ble_spare_event_buff, 0, sizeof(ble_spare_event_buff));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ble_glue_thread_stop() {
|
bool ble_glue_reinit_c2(void) {
|
||||||
if(ble_glue) {
|
return (SHCI_C2_Reinit() == SHCI_Success);
|
||||||
FuriThreadId thread_id = furi_thread_get_id(ble_glue->thread);
|
|
||||||
furi_assert(thread_id);
|
|
||||||
furi_thread_flags_set(thread_id, BLE_GLUE_FLAG_KILL_THREAD);
|
|
||||||
furi_thread_join(ble_glue->thread);
|
|
||||||
furi_thread_free(ble_glue->thread);
|
|
||||||
// Free resources
|
|
||||||
furi_mutex_free(ble_glue->shci_mtx);
|
|
||||||
ble_glue_clear_shared_memory();
|
|
||||||
free(ble_glue);
|
|
||||||
ble_glue = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap functions
|
BleGlueCommandResult ble_glue_fus_stack_delete(void) {
|
||||||
static int32_t ble_glue_shci_thread(void* context) {
|
|
||||||
UNUSED(context);
|
|
||||||
uint32_t flags = 0;
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
flags = furi_thread_flags_wait(BLE_GLUE_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
|
||||||
if(flags & BLE_GLUE_FLAG_SHCI_EVENT) {
|
|
||||||
shci_user_evt_proc();
|
|
||||||
}
|
|
||||||
if(flags & BLE_GLUE_FLAG_KILL_THREAD) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void shci_notify_asynch_evt(void* pdata) {
|
|
||||||
UNUSED(pdata);
|
|
||||||
if(ble_glue) {
|
|
||||||
FuriThreadId thread_id = furi_thread_get_id(ble_glue->thread);
|
|
||||||
furi_assert(thread_id);
|
|
||||||
furi_thread_flags_set(thread_id, BLE_GLUE_FLAG_SHCI_EVENT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ble_glue_reinit_c2() {
|
|
||||||
return SHCI_C2_Reinit() == SHCI_Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_stack_delete() {
|
|
||||||
FURI_LOG_I(TAG, "Erasing stack");
|
FURI_LOG_I(TAG, "Erasing stack");
|
||||||
SHCI_CmdStatus_t erase_stat = SHCI_C2_FUS_FwDelete();
|
SHCI_CmdStatus_t erase_stat = SHCI_C2_FUS_FwDelete();
|
||||||
FURI_LOG_I(TAG, "Cmd res = %x", erase_stat);
|
FURI_LOG_I(TAG, "Cmd res = %x", erase_stat);
|
||||||
@@ -450,8 +395,9 @@ BleGlueCommandResult ble_glue_fus_stack_install(uint32_t src_addr, uint32_t dst_
|
|||||||
return BleGlueCommandResultError;
|
return BleGlueCommandResultError;
|
||||||
}
|
}
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_get_status() {
|
BleGlueCommandResult ble_glue_fus_get_status(void) {
|
||||||
furi_check(ble_glue->c2_info.mode == BleGlueC2ModeFUS);
|
furi_check(ble_glue->c2_info.mode == BleGlueC2ModeFUS);
|
||||||
|
|
||||||
SHCI_FUS_GetState_ErrorCode_t error_code = 0;
|
SHCI_FUS_GetState_ErrorCode_t error_code = 0;
|
||||||
uint8_t fus_state = SHCI_C2_FUS_GetState(&error_code);
|
uint8_t fus_state = SHCI_C2_FUS_GetState(&error_code);
|
||||||
FURI_LOG_I(TAG, "FUS state: %x, error: %x", fus_state, error_code);
|
FURI_LOG_I(TAG, "FUS state: %x, error: %x", fus_state, error_code);
|
||||||
@@ -465,7 +411,7 @@ BleGlueCommandResult ble_glue_fus_get_status() {
|
|||||||
return BleGlueCommandResultOK;
|
return BleGlueCommandResultOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_wait_operation() {
|
BleGlueCommandResult ble_glue_fus_wait_operation(void) {
|
||||||
furi_check(ble_glue->c2_info.mode == BleGlueC2ModeFUS);
|
furi_check(ble_glue->c2_info.mode == BleGlueC2ModeFUS);
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
@@ -479,3 +425,12 @@ BleGlueCommandResult ble_glue_fus_wait_operation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BleGlueHardfaultInfo* ble_glue_get_hardfault_info(void) {
|
||||||
|
/* AN5289, 4.8.2 */
|
||||||
|
const BleGlueHardfaultInfo* info = (BleGlueHardfaultInfo*)(SRAM2A_BASE);
|
||||||
|
if(info->magic != BLE_GLUE_HARDFAULT_INFO_MAGIC) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,13 +7,17 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Low-level interface to Core2 - startup, shutdown, mode switching, FUS commands.
|
||||||
|
*/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BleGlueC2ModeUnknown = 0,
|
BleGlueC2ModeUnknown = 0,
|
||||||
BleGlueC2ModeFUS,
|
BleGlueC2ModeFUS,
|
||||||
BleGlueC2ModeStack,
|
BleGlueC2ModeStack,
|
||||||
} BleGlueC2Mode;
|
} BleGlueC2Mode;
|
||||||
|
|
||||||
#define BLE_GLUE_MAX_VERSION_STRING_LEN 20
|
#define BLE_MAX_VERSION_STRING_LEN (20)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BleGlueC2Mode mode;
|
BleGlueC2Mode mode;
|
||||||
/**
|
/**
|
||||||
@@ -29,7 +33,7 @@ typedef struct {
|
|||||||
uint8_t MemorySizeSram1; /*< Multiple of 1K */
|
uint8_t MemorySizeSram1; /*< Multiple of 1K */
|
||||||
uint8_t MemorySizeFlash; /*< Multiple of 4K */
|
uint8_t MemorySizeFlash; /*< Multiple of 4K */
|
||||||
uint8_t StackType;
|
uint8_t StackType;
|
||||||
char StackTypeString[BLE_GLUE_MAX_VERSION_STRING_LEN];
|
char StackTypeString[BLE_MAX_VERSION_STRING_LEN];
|
||||||
/**
|
/**
|
||||||
* Fus Info
|
* Fus Info
|
||||||
*/
|
*/
|
||||||
@@ -55,35 +59,37 @@ typedef void (
|
|||||||
*BleGlueKeyStorageChangedCallback)(uint8_t* change_addr_start, uint16_t size, void* context);
|
*BleGlueKeyStorageChangedCallback)(uint8_t* change_addr_start, uint16_t size, void* context);
|
||||||
|
|
||||||
/** Initialize start core2 and initialize transport */
|
/** Initialize start core2 and initialize transport */
|
||||||
void ble_glue_init();
|
void ble_glue_init(void);
|
||||||
|
|
||||||
/** Start Core2 Radio stack
|
/** Start Core2 Radio stack
|
||||||
*
|
*
|
||||||
* @return true on success
|
* @return true on success
|
||||||
*/
|
*/
|
||||||
bool ble_glue_start();
|
bool ble_glue_start(void);
|
||||||
|
|
||||||
|
void ble_glue_stop(void);
|
||||||
|
|
||||||
/** Is core2 alive and at least FUS is running
|
/** Is core2 alive and at least FUS is running
|
||||||
*
|
*
|
||||||
* @return true if core2 is alive
|
* @return true if core2 is alive
|
||||||
*/
|
*/
|
||||||
bool ble_glue_is_alive();
|
bool ble_glue_is_alive(void);
|
||||||
|
|
||||||
/** Waits for C2 to reports its mode to callback
|
/** Waits for C2 to reports its mode to callback
|
||||||
*
|
*
|
||||||
* @return true if it reported before reaching timeout
|
* @return true if it reported before reaching timeout
|
||||||
*/
|
*/
|
||||||
bool ble_glue_wait_for_c2_start(int32_t timeout);
|
bool ble_glue_wait_for_c2_start(int32_t timeout_ms);
|
||||||
|
|
||||||
BleGlueStatus ble_glue_get_c2_status();
|
BleGlueStatus ble_glue_get_c2_status(void);
|
||||||
|
|
||||||
const BleGlueC2Info* ble_glue_get_c2_info();
|
const BleGlueC2Info* ble_glue_get_c2_info(void);
|
||||||
|
|
||||||
/** Is core2 radio stack present and ready
|
/** Is core2 radio stack present and ready
|
||||||
*
|
*
|
||||||
* @return true if present and ready
|
* @return true if present and ready
|
||||||
*/
|
*/
|
||||||
bool ble_glue_is_radio_stack_ready();
|
bool ble_glue_is_radio_stack_ready(void);
|
||||||
|
|
||||||
/** Set callback for NVM in RAM changes
|
/** Set callback for NVM in RAM changes
|
||||||
*
|
*
|
||||||
@@ -94,9 +100,6 @@ void ble_glue_set_key_storage_changed_callback(
|
|||||||
BleGlueKeyStorageChangedCallback callback,
|
BleGlueKeyStorageChangedCallback callback,
|
||||||
void* context);
|
void* context);
|
||||||
|
|
||||||
/** Stop SHCI thread */
|
|
||||||
void ble_glue_thread_stop();
|
|
||||||
|
|
||||||
bool ble_glue_reinit_c2();
|
bool ble_glue_reinit_c2();
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -113,13 +116,26 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode mode);
|
BleGlueCommandResult ble_glue_force_c2_mode(BleGlueC2Mode mode);
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_stack_delete();
|
BleGlueCommandResult ble_glue_fus_stack_delete(void);
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_stack_install(uint32_t src_addr, uint32_t dst_addr);
|
BleGlueCommandResult ble_glue_fus_stack_install(uint32_t src_addr, uint32_t dst_addr);
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_get_status();
|
BleGlueCommandResult ble_glue_fus_get_status(void);
|
||||||
|
|
||||||
BleGlueCommandResult ble_glue_fus_wait_operation();
|
BleGlueCommandResult ble_glue_fus_wait_operation(void);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t magic;
|
||||||
|
uint32_t source_pc;
|
||||||
|
uint32_t source_lr;
|
||||||
|
uint32_t source_sp;
|
||||||
|
} BleGlueHardfaultInfo;
|
||||||
|
|
||||||
|
/** Get hardfault info
|
||||||
|
*
|
||||||
|
* @return hardfault info. NULL if no hardfault
|
||||||
|
*/
|
||||||
|
const BleGlueHardfaultInfo* ble_glue_get_hardfault_info(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
40
targets/f7/ble_glue/ble_tl_hooks.c
Normal file
40
targets/f7/ble_glue/ble_tl_hooks.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "ble_glue.h"
|
||||||
|
|
||||||
|
#include <interface/patterns/ble_thread/tl/shci_tl.h>
|
||||||
|
#include <ble/ble.h>
|
||||||
|
#include <hci_tl.h>
|
||||||
|
#include <furi.h>
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TL hooks to catch hardfaults
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t ble_glue_TL_SYS_SendCmd(uint8_t* buffer, uint16_t size) {
|
||||||
|
if(ble_glue_get_hardfault_info()) {
|
||||||
|
furi_crash("ST(R) Copro(R) HardFault");
|
||||||
|
}
|
||||||
|
|
||||||
|
return TL_SYS_SendCmd(buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shci_register_io_bus(tSHciIO* fops) {
|
||||||
|
/* Register IO bus services */
|
||||||
|
fops->Init = TL_SYS_Init;
|
||||||
|
fops->Send = ble_glue_TL_SYS_SendCmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t ble_glue_TL_BLE_SendCmd(uint8_t* buffer, uint16_t size) {
|
||||||
|
if(ble_glue_get_hardfault_info()) {
|
||||||
|
furi_crash("ST(R) Copro(R) HardFault");
|
||||||
|
}
|
||||||
|
|
||||||
|
return TL_BLE_SendCmd(buffer, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hci_register_io_bus(tHciIO* fops) {
|
||||||
|
/* Register IO bus services */
|
||||||
|
fops->Init = TL_BLE_Init;
|
||||||
|
fops->Send = ble_glue_TL_BLE_SendCmd;
|
||||||
|
}
|
||||||
161
targets/f7/ble_glue/extra_beacon.c
Normal file
161
targets/f7/ble_glue/extra_beacon.c
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
#include "extra_beacon.h"
|
||||||
|
#include "gap.h"
|
||||||
|
|
||||||
|
#include <ble/ble.h>
|
||||||
|
#include <furi.h>
|
||||||
|
|
||||||
|
#define TAG "BleExtraBeacon"
|
||||||
|
|
||||||
|
#define GAP_MS_TO_SCAN_INTERVAL(x) ((uint16_t)((x) / 0.625))
|
||||||
|
|
||||||
|
// Also used as an indicator of whether the beacon had ever been configured
|
||||||
|
#define GAP_MIN_ADV_INTERVAL_MS (20)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
GapExtraBeaconConfig last_config;
|
||||||
|
GapExtraBeaconState extra_beacon_state;
|
||||||
|
uint8_t extra_beacon_data[EXTRA_BEACON_MAX_DATA_SIZE];
|
||||||
|
uint8_t extra_beacon_data_len;
|
||||||
|
FuriMutex* state_mutex;
|
||||||
|
} ExtraBeacon;
|
||||||
|
|
||||||
|
static ExtraBeacon extra_beacon = {0};
|
||||||
|
|
||||||
|
void gap_extra_beacon_init() {
|
||||||
|
if(extra_beacon.state_mutex) {
|
||||||
|
// Already initialized - restore state if needed
|
||||||
|
FURI_LOG_I(TAG, "Restoring state");
|
||||||
|
gap_extra_beacon_set_data(
|
||||||
|
extra_beacon.extra_beacon_data, extra_beacon.extra_beacon_data_len);
|
||||||
|
if(extra_beacon.extra_beacon_state == GapExtraBeaconStateStarted) {
|
||||||
|
extra_beacon.extra_beacon_state = GapExtraBeaconStateStopped;
|
||||||
|
gap_extra_beacon_set_config(&extra_beacon.last_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// First time init
|
||||||
|
FURI_LOG_I(TAG, "Init");
|
||||||
|
extra_beacon.extra_beacon_state = GapExtraBeaconStateStopped;
|
||||||
|
extra_beacon.extra_beacon_data_len = 0;
|
||||||
|
memset(extra_beacon.extra_beacon_data, 0, EXTRA_BEACON_MAX_DATA_SIZE);
|
||||||
|
extra_beacon.state_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gap_extra_beacon_set_config(const GapExtraBeaconConfig* config) {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
furi_check(config);
|
||||||
|
|
||||||
|
furi_check(config->min_adv_interval_ms <= config->max_adv_interval_ms);
|
||||||
|
furi_check(config->min_adv_interval_ms >= GAP_MIN_ADV_INTERVAL_MS);
|
||||||
|
|
||||||
|
if(extra_beacon.extra_beacon_state != GapExtraBeaconStateStopped) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_mutex_acquire(extra_beacon.state_mutex, FuriWaitForever);
|
||||||
|
if(config != &extra_beacon.last_config) {
|
||||||
|
memcpy(&extra_beacon.last_config, config, sizeof(GapExtraBeaconConfig));
|
||||||
|
}
|
||||||
|
furi_mutex_release(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gap_extra_beacon_start() {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
furi_check(extra_beacon.last_config.min_adv_interval_ms >= GAP_MIN_ADV_INTERVAL_MS);
|
||||||
|
|
||||||
|
if(extra_beacon.extra_beacon_state != GapExtraBeaconStateStopped) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_I(TAG, "Starting");
|
||||||
|
furi_mutex_acquire(extra_beacon.state_mutex, FuriWaitForever);
|
||||||
|
const GapExtraBeaconConfig* config = &extra_beacon.last_config;
|
||||||
|
tBleStatus status = aci_gap_additional_beacon_start(
|
||||||
|
GAP_MS_TO_SCAN_INTERVAL(config->min_adv_interval_ms),
|
||||||
|
GAP_MS_TO_SCAN_INTERVAL(config->max_adv_interval_ms),
|
||||||
|
(uint8_t)config->adv_channel_map,
|
||||||
|
config->address_type,
|
||||||
|
config->address,
|
||||||
|
(uint8_t)config->adv_power_level);
|
||||||
|
if(status) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to start: 0x%x", status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
extra_beacon.extra_beacon_state = GapExtraBeaconStateStarted;
|
||||||
|
gap_emit_ble_beacon_status_event(true);
|
||||||
|
furi_mutex_release(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gap_extra_beacon_stop() {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
if(extra_beacon.extra_beacon_state != GapExtraBeaconStateStarted) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FURI_LOG_I(TAG, "Stopping");
|
||||||
|
furi_mutex_acquire(extra_beacon.state_mutex, FuriWaitForever);
|
||||||
|
tBleStatus status = aci_gap_additional_beacon_stop();
|
||||||
|
if(status) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to stop: 0x%x", status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
extra_beacon.extra_beacon_state = GapExtraBeaconStateStopped;
|
||||||
|
gap_emit_ble_beacon_status_event(false);
|
||||||
|
furi_mutex_release(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gap_extra_beacon_set_data(const uint8_t* data, uint8_t length) {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
furi_check(data);
|
||||||
|
furi_check(length <= EXTRA_BEACON_MAX_DATA_SIZE);
|
||||||
|
|
||||||
|
furi_mutex_acquire(extra_beacon.state_mutex, FuriWaitForever);
|
||||||
|
if(data != extra_beacon.extra_beacon_data) {
|
||||||
|
memcpy(extra_beacon.extra_beacon_data, data, length);
|
||||||
|
}
|
||||||
|
extra_beacon.extra_beacon_data_len = length;
|
||||||
|
|
||||||
|
tBleStatus status = aci_gap_additional_beacon_set_data(length, data);
|
||||||
|
if(status) {
|
||||||
|
FURI_LOG_E(TAG, "Failed updating adv data: %d", status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
furi_mutex_release(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t gap_extra_beacon_get_data(uint8_t* data) {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
furi_check(data);
|
||||||
|
|
||||||
|
furi_mutex_acquire(extra_beacon.state_mutex, FuriWaitForever);
|
||||||
|
memcpy(data, extra_beacon.extra_beacon_data, extra_beacon.extra_beacon_data_len);
|
||||||
|
furi_mutex_release(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
return extra_beacon.extra_beacon_data_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
GapExtraBeaconState gap_extra_beacon_get_state() {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
return extra_beacon.extra_beacon_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
const GapExtraBeaconConfig* gap_extra_beacon_get_config() {
|
||||||
|
furi_check(extra_beacon.state_mutex);
|
||||||
|
|
||||||
|
if(extra_beacon.last_config.min_adv_interval_ms < GAP_MIN_ADV_INTERVAL_MS) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &extra_beacon.last_config;
|
||||||
|
}
|
||||||
98
targets/f7/ble_glue/extra_beacon.h
Normal file
98
targets/f7/ble_glue/extra_beacon.h
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Additinal non-connetable beacon API.
|
||||||
|
* Not to be used directly, but through furi_hal_bt_extra_beacon_* APIs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define EXTRA_BEACON_MAX_DATA_SIZE (31)
|
||||||
|
#define EXTRA_BEACON_MAC_ADDR_SIZE (6)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GapAdvChannelMap37 = 0b001,
|
||||||
|
GapAdvChannelMap38 = 0b010,
|
||||||
|
GapAdvChannelMap39 = 0b100,
|
||||||
|
GapAdvChannelMapAll = 0b111,
|
||||||
|
} GapAdvChannelMap;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GapAdvPowerLevel_Neg40dBm = 0x00,
|
||||||
|
GapAdvPowerLevel_Neg20_85dBm = 0x01,
|
||||||
|
GapAdvPowerLevel_Neg19_75dBm = 0x02,
|
||||||
|
GapAdvPowerLevel_Neg18_85dBm = 0x03,
|
||||||
|
GapAdvPowerLevel_Neg17_6dBm = 0x04,
|
||||||
|
GapAdvPowerLevel_Neg16_5dBm = 0x05,
|
||||||
|
GapAdvPowerLevel_Neg15_25dBm = 0x06,
|
||||||
|
GapAdvPowerLevel_Neg14_1dBm = 0x07,
|
||||||
|
GapAdvPowerLevel_Neg13_15dBm = 0x08,
|
||||||
|
GapAdvPowerLevel_Neg12_05dBm = 0x09,
|
||||||
|
GapAdvPowerLevel_Neg10_9dBm = 0x0A,
|
||||||
|
GapAdvPowerLevel_Neg9_9dBm = 0x0B,
|
||||||
|
GapAdvPowerLevel_Neg8_85dBm = 0x0C,
|
||||||
|
GapAdvPowerLevel_Neg7_8dBm = 0x0D,
|
||||||
|
GapAdvPowerLevel_Neg6_9dBm = 0x0E,
|
||||||
|
GapAdvPowerLevel_Neg5_9dBm = 0x0F,
|
||||||
|
GapAdvPowerLevel_Neg4_95dBm = 0x10,
|
||||||
|
GapAdvPowerLevel_Neg4dBm = 0x11,
|
||||||
|
GapAdvPowerLevel_Neg3_15dBm = 0x12,
|
||||||
|
GapAdvPowerLevel_Neg2_45dBm = 0x13,
|
||||||
|
GapAdvPowerLevel_Neg1_8dBm = 0x14,
|
||||||
|
GapAdvPowerLevel_Neg1_3dBm = 0x15,
|
||||||
|
GapAdvPowerLevel_Neg0_85dBm = 0x16,
|
||||||
|
GapAdvPowerLevel_Neg0_5dBm = 0x17,
|
||||||
|
GapAdvPowerLevel_Neg0_15dBm = 0x18,
|
||||||
|
GapAdvPowerLevel_0dBm = 0x19,
|
||||||
|
GapAdvPowerLevel_1dBm = 0x1A,
|
||||||
|
GapAdvPowerLevel_2dBm = 0x1B,
|
||||||
|
GapAdvPowerLevel_3dBm = 0x1C,
|
||||||
|
GapAdvPowerLevel_4dBm = 0x1D,
|
||||||
|
GapAdvPowerLevel_5dBm = 0x1E,
|
||||||
|
GapAdvPowerLevel_6dBm = 0x1F,
|
||||||
|
} GapAdvPowerLevelInd;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GapAddressTypePublic = 0,
|
||||||
|
GapAddressTypeRandom = 1,
|
||||||
|
} GapAddressType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t min_adv_interval_ms, max_adv_interval_ms;
|
||||||
|
GapAdvChannelMap adv_channel_map;
|
||||||
|
GapAdvPowerLevelInd adv_power_level;
|
||||||
|
GapAddressType address_type;
|
||||||
|
uint8_t address[EXTRA_BEACON_MAC_ADDR_SIZE];
|
||||||
|
} GapExtraBeaconConfig;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GapExtraBeaconStateUndefined = 0,
|
||||||
|
GapExtraBeaconStateStopped,
|
||||||
|
GapExtraBeaconStateStarted,
|
||||||
|
} GapExtraBeaconState;
|
||||||
|
|
||||||
|
void gap_extra_beacon_init();
|
||||||
|
|
||||||
|
GapExtraBeaconState gap_extra_beacon_get_state();
|
||||||
|
|
||||||
|
bool gap_extra_beacon_start();
|
||||||
|
|
||||||
|
bool gap_extra_beacon_stop();
|
||||||
|
|
||||||
|
bool gap_extra_beacon_set_config(const GapExtraBeaconConfig* config);
|
||||||
|
|
||||||
|
const GapExtraBeaconConfig* gap_extra_beacon_get_config();
|
||||||
|
|
||||||
|
bool gap_extra_beacon_set_data(const uint8_t* data, uint8_t length);
|
||||||
|
|
||||||
|
// Fill "data" with last configured extra beacon data and return its length
|
||||||
|
uint8_t gap_extra_beacon_get_data(uint8_t* data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
97
targets/f7/ble_glue/furi_ble/event_dispatcher.c
Normal file
97
targets/f7/ble_glue/furi_ble/event_dispatcher.c
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
#include "event_dispatcher.h"
|
||||||
|
#include <core/check.h>
|
||||||
|
#include <furi.h>
|
||||||
|
#include <ble/ble.h>
|
||||||
|
|
||||||
|
#include <m-list.h>
|
||||||
|
|
||||||
|
struct GapEventHandler {
|
||||||
|
void* context;
|
||||||
|
BleSvcEventHandlerCb callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
LIST_DEF(GapSvcEventHandlerList, GapSvcEventHandler, M_POD_OPLIST);
|
||||||
|
|
||||||
|
static GapSvcEventHandlerList_t handlers;
|
||||||
|
static bool initialized = false;
|
||||||
|
|
||||||
|
BleEventFlowStatus ble_event_dispatcher_process_event(void* payload) {
|
||||||
|
furi_check(initialized);
|
||||||
|
|
||||||
|
GapSvcEventHandlerList_it_t it;
|
||||||
|
BleEventAckStatus ack_status = BleEventNotAck;
|
||||||
|
|
||||||
|
for(GapSvcEventHandlerList_it(it, handlers); !GapSvcEventHandlerList_end_p(it);
|
||||||
|
GapSvcEventHandlerList_next(it)) {
|
||||||
|
const GapSvcEventHandler* item = GapSvcEventHandlerList_cref(it);
|
||||||
|
ack_status = item->callback(payload, item->context);
|
||||||
|
if(ack_status == BleEventNotAck) {
|
||||||
|
/* Keep going */
|
||||||
|
continue;
|
||||||
|
} else if((ack_status == BleEventAckFlowEnable) || (ack_status == BleEventAckFlowDisable)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handlers for client-mode events are also to be implemented here. But not today. */
|
||||||
|
|
||||||
|
/* Now, decide on a flow control action based on results of all handlers */
|
||||||
|
switch(ack_status) {
|
||||||
|
case BleEventNotAck:
|
||||||
|
/* The event has NOT been managed yet. Pass to app for processing */
|
||||||
|
return ble_event_app_notification(payload);
|
||||||
|
case BleEventAckFlowEnable:
|
||||||
|
return BleEventFlowEnable;
|
||||||
|
case BleEventAckFlowDisable:
|
||||||
|
return BleEventFlowDisable;
|
||||||
|
default:
|
||||||
|
return BleEventFlowEnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_event_dispatcher_init(void) {
|
||||||
|
furi_assert(!initialized);
|
||||||
|
|
||||||
|
GapSvcEventHandlerList_init(handlers);
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_event_dispatcher_reset(void) {
|
||||||
|
furi_assert(initialized);
|
||||||
|
furi_check(GapSvcEventHandlerList_size(handlers) == 0);
|
||||||
|
|
||||||
|
GapSvcEventHandlerList_clear(handlers);
|
||||||
|
}
|
||||||
|
|
||||||
|
GapSvcEventHandler*
|
||||||
|
ble_event_dispatcher_register_svc_handler(BleSvcEventHandlerCb handler, void* context) {
|
||||||
|
furi_check(handler);
|
||||||
|
furi_check(context);
|
||||||
|
furi_check(initialized);
|
||||||
|
|
||||||
|
GapSvcEventHandler* item = GapSvcEventHandlerList_push_raw(handlers);
|
||||||
|
item->context = context;
|
||||||
|
item->callback = handler;
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_event_dispatcher_unregister_svc_handler(GapSvcEventHandler* handler) {
|
||||||
|
furi_check(handler);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
GapSvcEventHandlerList_it_t it;
|
||||||
|
|
||||||
|
for(GapSvcEventHandlerList_it(it, handlers); !GapSvcEventHandlerList_end_p(it);
|
||||||
|
GapSvcEventHandlerList_next(it)) {
|
||||||
|
const GapSvcEventHandler* item = GapSvcEventHandlerList_cref(it);
|
||||||
|
|
||||||
|
if(item == handler) {
|
||||||
|
GapSvcEventHandlerList_remove(handlers, it);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_check(found);
|
||||||
|
}
|
||||||
50
targets/f7/ble_glue/furi_ble/event_dispatcher.h
Normal file
50
targets/f7/ble_glue/furi_ble/event_dispatcher.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <core/common_defines.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BleEventNotAck,
|
||||||
|
BleEventAckFlowEnable,
|
||||||
|
BleEventAckFlowDisable,
|
||||||
|
} BleEventAckStatus;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BleEventFlowDisable,
|
||||||
|
BleEventFlowEnable,
|
||||||
|
} BleEventFlowStatus;
|
||||||
|
|
||||||
|
/* Using other types so not to leak all the BLE stack headers
|
||||||
|
(we don't have a wrapper for them yet)
|
||||||
|
* Event data is hci_uart_pckt*
|
||||||
|
* Context is user-defined
|
||||||
|
*/
|
||||||
|
typedef BleEventAckStatus (*BleSvcEventHandlerCb)(void* event, void* context);
|
||||||
|
|
||||||
|
typedef struct GapEventHandler GapSvcEventHandler;
|
||||||
|
|
||||||
|
/* To be called once at BLE system startup */
|
||||||
|
void ble_event_dispatcher_init(void);
|
||||||
|
|
||||||
|
/* To be called at stack reset - ensures that all handlers are unregistered */
|
||||||
|
void ble_event_dispatcher_reset(void);
|
||||||
|
|
||||||
|
BleEventFlowStatus ble_event_dispatcher_process_event(void* payload);
|
||||||
|
|
||||||
|
/* Final handler for event not ack'd by services - to be implemented by app */
|
||||||
|
BleEventFlowStatus ble_event_app_notification(void* pckt);
|
||||||
|
|
||||||
|
/* Add a handler to the list of handlers */
|
||||||
|
FURI_WARN_UNUSED GapSvcEventHandler*
|
||||||
|
ble_event_dispatcher_register_svc_handler(BleSvcEventHandlerCb handler, void* context);
|
||||||
|
|
||||||
|
/* Remove a handler from the list of handlers */
|
||||||
|
void ble_event_dispatcher_unregister_svc_handler(GapSvcEventHandler* handler);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "gatt_char.h"
|
#include "gatt.h"
|
||||||
|
#include <ble/ble.h>
|
||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
|
||||||
@@ -6,19 +7,19 @@
|
|||||||
|
|
||||||
#define GATT_MIN_READ_KEY_SIZE (10)
|
#define GATT_MIN_READ_KEY_SIZE (10)
|
||||||
|
|
||||||
void flipper_gatt_characteristic_init(
|
void ble_gatt_characteristic_init(
|
||||||
uint16_t svc_handle,
|
uint16_t svc_handle,
|
||||||
const FlipperGattCharacteristicParams* char_descriptor,
|
const BleGattCharacteristicParams* char_descriptor,
|
||||||
FlipperGattCharacteristicInstance* char_instance) {
|
BleGattCharacteristicInstance* char_instance) {
|
||||||
furi_assert(char_descriptor);
|
furi_assert(char_descriptor);
|
||||||
furi_assert(char_instance);
|
furi_assert(char_instance);
|
||||||
|
|
||||||
// Copy the descriptor to the instance, since it may point to stack memory
|
// Copy the descriptor to the instance, since it may point to stack memory
|
||||||
char_instance->characteristic = malloc(sizeof(FlipperGattCharacteristicParams));
|
char_instance->characteristic = malloc(sizeof(BleGattCharacteristicParams));
|
||||||
memcpy(
|
memcpy(
|
||||||
(void*)char_instance->characteristic,
|
(void*)char_instance->characteristic,
|
||||||
char_descriptor,
|
char_descriptor,
|
||||||
sizeof(FlipperGattCharacteristicParams));
|
sizeof(BleGattCharacteristicParams));
|
||||||
|
|
||||||
uint16_t char_data_size = 0;
|
uint16_t char_data_size = 0;
|
||||||
if(char_descriptor->data_prop_type == FlipperGattCharacteristicDataFixed) {
|
if(char_descriptor->data_prop_type == FlipperGattCharacteristicDataFixed) {
|
||||||
@@ -46,7 +47,7 @@ void flipper_gatt_characteristic_init(
|
|||||||
char_instance->descriptor_handle = 0;
|
char_instance->descriptor_handle = 0;
|
||||||
if((status == 0) && char_descriptor->descriptor_params) {
|
if((status == 0) && char_descriptor->descriptor_params) {
|
||||||
uint8_t const* char_data = NULL;
|
uint8_t const* char_data = NULL;
|
||||||
const FlipperGattCharacteristicDescriptorParams* char_data_descriptor =
|
const BleGattCharacteristicDescriptorParams* char_data_descriptor =
|
||||||
char_descriptor->descriptor_params;
|
char_descriptor->descriptor_params;
|
||||||
bool release_data = char_data_descriptor->data_callback.fn(
|
bool release_data = char_data_descriptor->data_callback.fn(
|
||||||
char_data_descriptor->data_callback.context, &char_data, &char_data_size);
|
char_data_descriptor->data_callback.context, &char_data, &char_data_size);
|
||||||
@@ -74,9 +75,9 @@ void flipper_gatt_characteristic_init(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void flipper_gatt_characteristic_delete(
|
void ble_gatt_characteristic_delete(
|
||||||
uint16_t svc_handle,
|
uint16_t svc_handle,
|
||||||
FlipperGattCharacteristicInstance* char_instance) {
|
BleGattCharacteristicInstance* char_instance) {
|
||||||
tBleStatus status = aci_gatt_del_char(svc_handle, char_instance->handle);
|
tBleStatus status = aci_gatt_del_char(svc_handle, char_instance->handle);
|
||||||
if(status) {
|
if(status) {
|
||||||
FURI_LOG_E(
|
FURI_LOG_E(
|
||||||
@@ -85,12 +86,12 @@ void flipper_gatt_characteristic_delete(
|
|||||||
free((void*)char_instance->characteristic);
|
free((void*)char_instance->characteristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flipper_gatt_characteristic_update(
|
bool ble_gatt_characteristic_update(
|
||||||
uint16_t svc_handle,
|
uint16_t svc_handle,
|
||||||
FlipperGattCharacteristicInstance* char_instance,
|
BleGattCharacteristicInstance* char_instance,
|
||||||
const void* source) {
|
const void* source) {
|
||||||
furi_assert(char_instance);
|
furi_assert(char_instance);
|
||||||
const FlipperGattCharacteristicParams* char_descriptor = char_instance->characteristic;
|
const BleGattCharacteristicParams* char_descriptor = char_instance->characteristic;
|
||||||
FURI_LOG_D(TAG, "Updating %s char", char_descriptor->name);
|
FURI_LOG_D(TAG, "Updating %s char", char_descriptor->name);
|
||||||
|
|
||||||
const uint8_t* char_data = NULL;
|
const uint8_t* char_data = NULL;
|
||||||
@@ -120,3 +121,27 @@ bool flipper_gatt_characteristic_update(
|
|||||||
}
|
}
|
||||||
return result != BLE_STATUS_SUCCESS;
|
return result != BLE_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ble_gatt_service_add(
|
||||||
|
uint8_t Service_UUID_Type,
|
||||||
|
const Service_UUID_t* Service_UUID,
|
||||||
|
uint8_t Service_Type,
|
||||||
|
uint8_t Max_Attribute_Records,
|
||||||
|
uint16_t* Service_Handle) {
|
||||||
|
tBleStatus result = aci_gatt_add_service(
|
||||||
|
Service_UUID_Type, Service_UUID, Service_Type, Max_Attribute_Records, Service_Handle);
|
||||||
|
if(result) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to add service: %x", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result == BLE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_gatt_service_delete(uint16_t svc_handle) {
|
||||||
|
tBleStatus result = aci_gatt_del_service(svc_handle);
|
||||||
|
if(result) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to delete service: %x", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result == BLE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
110
targets/f7/ble_glue/furi_ble/gatt.h
Normal file
110
targets/f7/ble_glue/furi_ble/gatt.h
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <ble/core/auto/ble_types.h>
|
||||||
|
|
||||||
|
/* Callback signature for getting characteristic data
|
||||||
|
* Is called when characteristic is created to get max data length. Data ptr is NULL in this case
|
||||||
|
* The result is passed to aci_gatt_add_char as "Char_Value_Length"
|
||||||
|
* For updates, called with a context - see flipper_gatt_characteristic_update
|
||||||
|
* Returns true if *data ownership is transferred to the caller and will be freed */
|
||||||
|
typedef bool (
|
||||||
|
*cbBleGattCharacteristicData)(const void* context, const uint8_t** data, uint16_t* data_len);
|
||||||
|
|
||||||
|
/* Used to specify the type of data for a characteristic - constant or callback-based */
|
||||||
|
typedef enum {
|
||||||
|
FlipperGattCharacteristicDataFixed,
|
||||||
|
FlipperGattCharacteristicDataCallback,
|
||||||
|
} BleGattCharacteristicDataType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Char_Desc_Uuid_t uuid;
|
||||||
|
struct {
|
||||||
|
cbBleGattCharacteristicData fn;
|
||||||
|
const void* context;
|
||||||
|
} data_callback;
|
||||||
|
uint8_t uuid_type;
|
||||||
|
uint8_t max_length;
|
||||||
|
uint8_t security_permissions;
|
||||||
|
uint8_t access_permissions;
|
||||||
|
uint8_t gatt_evt_mask;
|
||||||
|
uint8_t is_variable;
|
||||||
|
} BleGattCharacteristicDescriptorParams;
|
||||||
|
|
||||||
|
/* Describes a single characteristic, providing data or callbacks to get data */
|
||||||
|
typedef struct {
|
||||||
|
const char* name;
|
||||||
|
BleGattCharacteristicDescriptorParams* descriptor_params;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
const uint8_t* ptr;
|
||||||
|
uint16_t length;
|
||||||
|
} fixed;
|
||||||
|
struct {
|
||||||
|
cbBleGattCharacteristicData fn;
|
||||||
|
const void* context;
|
||||||
|
} callback;
|
||||||
|
} data;
|
||||||
|
Char_UUID_t uuid;
|
||||||
|
// Some packed bitfields to save space
|
||||||
|
BleGattCharacteristicDataType data_prop_type : 2;
|
||||||
|
uint8_t is_variable : 2;
|
||||||
|
uint8_t uuid_type : 2;
|
||||||
|
uint8_t char_properties;
|
||||||
|
uint8_t security_permissions;
|
||||||
|
uint8_t gatt_evt_mask;
|
||||||
|
} BleGattCharacteristicParams;
|
||||||
|
|
||||||
|
_Static_assert(
|
||||||
|
sizeof(BleGattCharacteristicParams) == 36,
|
||||||
|
"BleGattCharacteristicParams size must be 36 bytes");
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const BleGattCharacteristicParams* characteristic;
|
||||||
|
uint16_t handle;
|
||||||
|
uint16_t descriptor_handle;
|
||||||
|
} BleGattCharacteristicInstance;
|
||||||
|
|
||||||
|
/* Initialize a characteristic instance; copies the characteristic descriptor
|
||||||
|
* into the instance */
|
||||||
|
void ble_gatt_characteristic_init(
|
||||||
|
uint16_t svc_handle,
|
||||||
|
const BleGattCharacteristicParams* char_descriptor,
|
||||||
|
BleGattCharacteristicInstance* char_instance);
|
||||||
|
|
||||||
|
/* Delete a characteristic instance; frees the copied characteristic
|
||||||
|
* descriptor from the instance */
|
||||||
|
void ble_gatt_characteristic_delete(
|
||||||
|
uint16_t svc_handle,
|
||||||
|
BleGattCharacteristicInstance* char_instance);
|
||||||
|
|
||||||
|
/* Update a characteristic instance; if source==NULL, uses the data from
|
||||||
|
* the characteristic:
|
||||||
|
* - For fixed data, fixed.ptr is used as the source if source==NULL
|
||||||
|
* - For callback-based data, collback.context is passed as the context
|
||||||
|
* if source==NULL
|
||||||
|
*/
|
||||||
|
bool ble_gatt_characteristic_update(
|
||||||
|
uint16_t svc_handle,
|
||||||
|
BleGattCharacteristicInstance* char_instance,
|
||||||
|
const void* source);
|
||||||
|
|
||||||
|
bool ble_gatt_service_add(
|
||||||
|
uint8_t Service_UUID_Type,
|
||||||
|
const Service_UUID_t* Service_UUID,
|
||||||
|
uint8_t Service_Type,
|
||||||
|
uint8_t Max_Attribute_Records,
|
||||||
|
uint16_t* Service_Handle);
|
||||||
|
|
||||||
|
bool ble_gatt_service_delete(uint16_t svc_handle);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
39
targets/f7/ble_glue/furi_ble/profile_interface.h
Normal file
39
targets/f7/ble_glue/furi_ble/profile_interface.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <gap.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct FuriHalBleProfileTemplate FuriHalBleProfileTemplate;
|
||||||
|
|
||||||
|
/* Actual profiles must inherit (include this structure) as their first field */
|
||||||
|
typedef struct {
|
||||||
|
/* Pointer to the config for this profile. Must be used to check if the
|
||||||
|
* instance belongs to the profile */
|
||||||
|
const FuriHalBleProfileTemplate* config;
|
||||||
|
} FuriHalBleProfileBase;
|
||||||
|
|
||||||
|
typedef void* FuriHalBleProfileParams;
|
||||||
|
|
||||||
|
typedef FuriHalBleProfileBase* (*FuriHalBleProfileStart)(FuriHalBleProfileParams profile_params);
|
||||||
|
typedef void (*FuriHalBleProfileStop)(FuriHalBleProfileBase* profile);
|
||||||
|
typedef void (*FuriHalBleProfileGetGapConfig)(
|
||||||
|
GapConfig* target_config,
|
||||||
|
FuriHalBleProfileParams profile_params);
|
||||||
|
|
||||||
|
struct FuriHalBleProfileTemplate {
|
||||||
|
/* Returns an instance of the profile */
|
||||||
|
FuriHalBleProfileStart start;
|
||||||
|
/* Destroys the instance of the profile. Must check if instance belongs to the profile */
|
||||||
|
FuriHalBleProfileStop stop;
|
||||||
|
/* Called before starting the profile to get the GAP configuration */
|
||||||
|
FuriHalBleProfileGetGapConfig get_gap_config;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
#include "gap.h"
|
#include "gap.h"
|
||||||
|
|
||||||
#include "app_common.h"
|
#include "app_common.h"
|
||||||
|
#include <core/mutex.h>
|
||||||
|
#include "furi_ble/event_dispatcher.h"
|
||||||
#include <ble/ble.h>
|
#include <ble/ble.h>
|
||||||
|
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define TAG "BtGap"
|
#define TAG "BleGap"
|
||||||
|
|
||||||
#define FAST_ADV_TIMEOUT 30000
|
#define FAST_ADV_TIMEOUT 30000
|
||||||
#define INITIAL_ADV_TIMEOUT 60000
|
#define INITIAL_ADV_TIMEOUT 60000
|
||||||
@@ -98,7 +101,7 @@ static void gap_verify_connection_parameters(Gap* gap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) {
|
BleEventFlowStatus ble_event_app_notification(void* pckt) {
|
||||||
hci_event_pckt* event_pckt;
|
hci_event_pckt* event_pckt;
|
||||||
evt_le_meta_event* meta_evt;
|
evt_le_meta_event* meta_evt;
|
||||||
evt_blecore_aci* blue_evt;
|
evt_blecore_aci* blue_evt;
|
||||||
@@ -293,7 +296,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification(void* pckt) {
|
|||||||
if(gap) {
|
if(gap) {
|
||||||
furi_mutex_release(gap->state_mutex);
|
furi_mutex_release(gap->state_mutex);
|
||||||
}
|
}
|
||||||
return SVCCTL_UserEvtFlowEnable;
|
return BleEventFlowEnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_advertisment_service_uid(uint8_t* uid, uint8_t uid_len) {
|
static void set_advertisment_service_uid(uint8_t* uid, uint8_t uid_len) {
|
||||||
@@ -370,35 +373,21 @@ static void gap_init_svc(Gap* gap) {
|
|||||||
hci_le_set_default_phy(ALL_PHYS_PREFERENCE, TX_2M_PREFERRED, RX_2M_PREFERRED);
|
hci_le_set_default_phy(ALL_PHYS_PREFERENCE, TX_2M_PREFERRED, RX_2M_PREFERRED);
|
||||||
// Set I/O capability
|
// Set I/O capability
|
||||||
bool keypress_supported = false;
|
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) {
|
if(gap->config->pairing_method == GapPairingPinCodeShow) {
|
||||||
aci_gap_set_io_capability(IO_CAP_DISPLAY_ONLY);
|
aci_gap_set_io_capability(IO_CAP_DISPLAY_ONLY);
|
||||||
} else if(gap->config->pairing_method == GapPairingPinCodeVerifyYesNo) {
|
} else if(gap->config->pairing_method == GapPairingPinCodeVerifyYesNo) {
|
||||||
aci_gap_set_io_capability(IO_CAP_DISPLAY_YES_NO);
|
aci_gap_set_io_capability(IO_CAP_DISPLAY_YES_NO);
|
||||||
keypress_supported = true;
|
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
|
|
||||||
aci_gap_set_io_capability(IO_CAP_DISPLAY_YES_NO);
|
|
||||||
keypress_supported = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup authentication
|
// Setup authentication
|
||||||
aci_gap_set_authentication_requirement(
|
aci_gap_set_authentication_requirement(
|
||||||
conf_bonding,
|
gap->config->bonding_mode,
|
||||||
conf_mitm,
|
CFG_MITM_PROTECTION,
|
||||||
CFG_SC_SUPPORT,
|
CFG_SC_SUPPORT,
|
||||||
keypress_supported,
|
keypress_supported,
|
||||||
CFG_ENCRYPTION_KEY_SIZE_MIN,
|
CFG_ENCRYPTION_KEY_SIZE_MIN,
|
||||||
CFG_ENCRYPTION_KEY_SIZE_MAX,
|
CFG_ENCRYPTION_KEY_SIZE_MAX,
|
||||||
conf_used_fixed_pin, // 0x0 for no pin
|
CFG_USED_FIXED_PIN,
|
||||||
0,
|
0,
|
||||||
CFG_IDENTITY_ADDRESS);
|
CFG_IDENTITY_ADDRESS);
|
||||||
// Configure whitelist
|
// Configure whitelist
|
||||||
@@ -410,6 +399,8 @@ static void gap_advertise_start(GapState new_state) {
|
|||||||
uint16_t min_interval;
|
uint16_t min_interval;
|
||||||
uint16_t max_interval;
|
uint16_t max_interval;
|
||||||
|
|
||||||
|
FURI_LOG_I(TAG, "Start: %d", new_state);
|
||||||
|
|
||||||
if(new_state == GapStateAdvFast) {
|
if(new_state == GapStateAdvFast) {
|
||||||
min_interval = 0x80; // 80 ms
|
min_interval = 0x80; // 80 ms
|
||||||
max_interval = 0xa0; // 100 ms
|
max_interval = 0xa0; // 100 ms
|
||||||
@@ -452,7 +443,8 @@ static void gap_advertise_start(GapState new_state) {
|
|||||||
furi_timer_start(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
|
furi_timer_start(gap->advertise_timer, INITIAL_ADV_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gap_advertise_stop() {
|
static void gap_advertise_stop(void) {
|
||||||
|
FURI_LOG_I(TAG, "Stop");
|
||||||
tBleStatus ret;
|
tBleStatus ret;
|
||||||
if(gap->state > GapStateIdle) {
|
if(gap->state > GapStateIdle) {
|
||||||
if(gap->state == GapStateConnected) {
|
if(gap->state == GapStateConnected) {
|
||||||
@@ -478,7 +470,7 @@ static void gap_advertise_stop() {
|
|||||||
gap->on_event_cb(event, gap->context);
|
gap->on_event_cb(event, gap->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gap_start_advertising() {
|
void gap_start_advertising(void) {
|
||||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||||
if(gap->state == GapStateIdle) {
|
if(gap->state == GapStateIdle) {
|
||||||
gap->state = GapStateStartingAdv;
|
gap->state = GapStateStartingAdv;
|
||||||
@@ -490,7 +482,7 @@ void gap_start_advertising() {
|
|||||||
furi_mutex_release(gap->state_mutex);
|
furi_mutex_release(gap->state_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gap_stop_advertising() {
|
void gap_stop_advertising(void) {
|
||||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||||
if(gap->state > GapStateIdle) {
|
if(gap->state > GapStateIdle) {
|
||||||
FURI_LOG_I(TAG, "Stop advertising");
|
FURI_LOG_I(TAG, "Stop advertising");
|
||||||
@@ -519,8 +511,7 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
|
|||||||
// Initialization of GATT & GAP layer
|
// Initialization of GATT & GAP layer
|
||||||
gap->service.adv_name = config->adv_name;
|
gap->service.adv_name = config->adv_name;
|
||||||
gap_init_svc(gap);
|
gap_init_svc(gap);
|
||||||
// Initialization of the BLE Services
|
ble_event_dispatcher_init();
|
||||||
SVCCTL_Init();
|
|
||||||
// Initialization of the GAP state
|
// Initialization of the GAP state
|
||||||
gap->state_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
gap->state_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||||
gap->state = GapStateIdle;
|
gap->state = GapStateIdle;
|
||||||
@@ -546,6 +537,7 @@ bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context) {
|
|||||||
// Set callback
|
// Set callback
|
||||||
gap->on_event_cb = on_event_cb;
|
gap->on_event_cb = on_event_cb;
|
||||||
gap->context = context;
|
gap->context = context;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,7 +552,7 @@ uint32_t gap_get_remote_conn_rssi(int8_t* rssi) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GapState gap_get_state() {
|
GapState gap_get_state(void) {
|
||||||
GapState state;
|
GapState state;
|
||||||
if(gap) {
|
if(gap) {
|
||||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||||
@@ -572,7 +564,7 @@ GapState gap_get_state() {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gap_thread_stop() {
|
void gap_thread_stop(void) {
|
||||||
if(gap) {
|
if(gap) {
|
||||||
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
furi_mutex_acquire(gap->state_mutex, FuriWaitForever);
|
||||||
gap->enable_adv = false;
|
gap->enable_adv = false;
|
||||||
@@ -585,6 +577,8 @@ void gap_thread_stop() {
|
|||||||
furi_mutex_free(gap->state_mutex);
|
furi_mutex_free(gap->state_mutex);
|
||||||
furi_message_queue_free(gap->command_queue);
|
furi_message_queue_free(gap->command_queue);
|
||||||
furi_timer_free(gap->advertise_timer);
|
furi_timer_free(gap->advertise_timer);
|
||||||
|
|
||||||
|
ble_event_dispatcher_reset();
|
||||||
free(gap);
|
free(gap);
|
||||||
gap = NULL;
|
gap = NULL;
|
||||||
}
|
}
|
||||||
@@ -615,3 +609,9 @@ static int32_t gap_app(void* context) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gap_emit_ble_beacon_status_event(bool active) {
|
||||||
|
GapEvent event = {.type = active ? GapEventTypeBeaconStart : GapEventTypeBeaconStop};
|
||||||
|
gap->on_event_cb(event, gap->context);
|
||||||
|
FURI_LOG_I(TAG, "Beacon status event: %d", active);
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
#define GAP_MAC_ADDR_SIZE (6)
|
#define GAP_MAC_ADDR_SIZE (6)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GAP helpers - background thread that handles BLE GAP events and advertising.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -19,6 +23,8 @@ typedef enum {
|
|||||||
GapEventTypePinCodeShow,
|
GapEventTypePinCodeShow,
|
||||||
GapEventTypePinCodeVerify,
|
GapEventTypePinCodeVerify,
|
||||||
GapEventTypeUpdateMTU,
|
GapEventTypeUpdateMTU,
|
||||||
|
GapEventTypeBeaconStart,
|
||||||
|
GapEventTypeBeaconStop,
|
||||||
} GapEventType;
|
} GapEventType;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -73,13 +79,15 @@ typedef struct {
|
|||||||
|
|
||||||
bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context);
|
bool gap_init(GapConfig* config, GapEventCallback on_event_cb, void* context);
|
||||||
|
|
||||||
void gap_start_advertising();
|
void gap_start_advertising(void);
|
||||||
|
|
||||||
void gap_stop_advertising();
|
void gap_stop_advertising(void);
|
||||||
|
|
||||||
GapState gap_get_state();
|
GapState gap_get_state(void);
|
||||||
|
|
||||||
void gap_thread_stop();
|
void gap_thread_stop(void);
|
||||||
|
|
||||||
|
void gap_emit_ble_beacon_status_event(bool active);
|
||||||
|
|
||||||
uint32_t gap_get_remote_conn_rssi(int8_t* rssi);
|
uint32_t gap_get_remote_conn_rssi(int8_t* rssi);
|
||||||
|
|
||||||
|
|||||||
114
targets/f7/ble_glue/profiles/serial_profile.c
Normal file
114
targets/f7/ble_glue/profiles/serial_profile.c
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#include "serial_profile.h"
|
||||||
|
|
||||||
|
#include <gap.h>
|
||||||
|
#include <furi_ble/profile_interface.h>
|
||||||
|
#include <services/dev_info_service.h>
|
||||||
|
#include <services/battery_service.h>
|
||||||
|
#include <services/serial_service.h>
|
||||||
|
#include <furi.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
FuriHalBleProfileBase base;
|
||||||
|
|
||||||
|
BleServiceDevInfo* dev_info_svc;
|
||||||
|
BleServiceBattery* battery_svc;
|
||||||
|
BleServiceSerial* serial_svc;
|
||||||
|
} BleProfileSerial;
|
||||||
|
_Static_assert(offsetof(BleProfileSerial, base) == 0, "Wrong layout");
|
||||||
|
|
||||||
|
static FuriHalBleProfileBase* ble_profile_serial_start(FuriHalBleProfileParams profile_params) {
|
||||||
|
UNUSED(profile_params);
|
||||||
|
|
||||||
|
BleProfileSerial* profile = malloc(sizeof(BleProfileSerial));
|
||||||
|
|
||||||
|
profile->base.config = ble_profile_serial;
|
||||||
|
|
||||||
|
profile->dev_info_svc = ble_svc_dev_info_start();
|
||||||
|
profile->battery_svc = ble_svc_battery_start(true);
|
||||||
|
profile->serial_svc = ble_svc_serial_start();
|
||||||
|
|
||||||
|
return &profile->base;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ble_profile_serial_stop(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile);
|
||||||
|
furi_check(profile->config == ble_profile_serial);
|
||||||
|
|
||||||
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
||||||
|
ble_svc_battery_stop(serial_profile->battery_svc);
|
||||||
|
ble_svc_dev_info_stop(serial_profile->dev_info_svc);
|
||||||
|
ble_svc_serial_stop(serial_profile->serial_svc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GapConfig serial_template_config = {
|
||||||
|
.adv_service_uuid = 0x3080,
|
||||||
|
.appearance_char = 0x8600,
|
||||||
|
.bonding_mode = true,
|
||||||
|
.pairing_method = GapPairingPinCodeShow,
|
||||||
|
.conn_param = {
|
||||||
|
.conn_int_min = 0x18, // 30 ms
|
||||||
|
.conn_int_max = 0x24, // 45 ms
|
||||||
|
.slave_latency = 0,
|
||||||
|
.supervisor_timeout = 0,
|
||||||
|
}};
|
||||||
|
|
||||||
|
static void
|
||||||
|
ble_profile_serial_get_config(GapConfig* config, FuriHalBleProfileParams profile_params) {
|
||||||
|
UNUSED(profile_params);
|
||||||
|
|
||||||
|
furi_check(config);
|
||||||
|
memcpy(config, &serial_template_config, sizeof(GapConfig));
|
||||||
|
// Set mac address
|
||||||
|
memcpy(config->mac_address, furi_hal_version_get_ble_mac(), sizeof(config->mac_address));
|
||||||
|
// Set advertise name
|
||||||
|
strlcpy(
|
||||||
|
config->adv_name,
|
||||||
|
furi_hal_version_get_ble_local_device_name_ptr(),
|
||||||
|
FURI_HAL_VERSION_DEVICE_NAME_LENGTH);
|
||||||
|
config->adv_service_uuid |= furi_hal_version_get_hw_color();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const FuriHalBleProfileTemplate profile_callbacks = {
|
||||||
|
.start = ble_profile_serial_start,
|
||||||
|
.stop = ble_profile_serial_stop,
|
||||||
|
.get_gap_config = ble_profile_serial_get_config,
|
||||||
|
};
|
||||||
|
|
||||||
|
const FuriHalBleProfileTemplate* ble_profile_serial = &profile_callbacks;
|
||||||
|
|
||||||
|
void ble_profile_serial_set_event_callback(
|
||||||
|
FuriHalBleProfileBase* profile,
|
||||||
|
uint16_t buff_size,
|
||||||
|
FuriHalBtSerialCallback callback,
|
||||||
|
void* context) {
|
||||||
|
furi_check(profile && (profile->config == ble_profile_serial));
|
||||||
|
|
||||||
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
||||||
|
ble_svc_serial_set_callbacks(serial_profile->serial_svc, buff_size, callback, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_profile_serial_notify_buffer_is_empty(FuriHalBleProfileBase* profile) {
|
||||||
|
furi_check(profile && (profile->config == ble_profile_serial));
|
||||||
|
|
||||||
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
||||||
|
ble_svc_serial_notify_buffer_is_empty(serial_profile->serial_svc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_profile_serial_set_rpc_active(FuriHalBleProfileBase* profile, bool active) {
|
||||||
|
furi_check(profile && (profile->config == ble_profile_serial));
|
||||||
|
|
||||||
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
||||||
|
ble_svc_serial_set_rpc_active(serial_profile->serial_svc, active);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_profile_serial_tx(FuriHalBleProfileBase* profile, uint8_t* data, uint16_t size) {
|
||||||
|
furi_check(profile && (profile->config == ble_profile_serial));
|
||||||
|
|
||||||
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
||||||
|
|
||||||
|
if(size > BLE_PROFILE_SERIAL_PACKET_SIZE_MAX) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ble_svc_serial_update_tx(serial_profile->serial_svc, data, size);
|
||||||
|
}
|
||||||
61
targets/f7/ble_glue/profiles/serial_profile.h
Normal file
61
targets/f7/ble_glue/profiles/serial_profile.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi_ble/profile_interface.h>
|
||||||
|
|
||||||
|
#include <services/serial_service.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BLE_PROFILE_SERIAL_PACKET_SIZE_MAX BLE_SVC_SERIAL_DATA_LEN_MAX
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
FuriHalBtSerialRpcStatusNotActive,
|
||||||
|
FuriHalBtSerialRpcStatusActive,
|
||||||
|
} FuriHalBtSerialRpcStatus;
|
||||||
|
|
||||||
|
/** Serial service callback type */
|
||||||
|
typedef SerialServiceEventCallback FuriHalBtSerialCallback;
|
||||||
|
|
||||||
|
/** Serial profile descriptor */
|
||||||
|
extern const FuriHalBleProfileTemplate* ble_profile_serial;
|
||||||
|
|
||||||
|
/** Send data through BLE
|
||||||
|
*
|
||||||
|
* @param profile Profile instance
|
||||||
|
* @param data data buffer
|
||||||
|
* @param size data buffer size
|
||||||
|
*
|
||||||
|
* @return true on success
|
||||||
|
*/
|
||||||
|
bool ble_profile_serial_tx(FuriHalBleProfileBase* profile, uint8_t* data, uint16_t size);
|
||||||
|
|
||||||
|
/** Set BLE RPC status
|
||||||
|
*
|
||||||
|
* @param profile Profile instance
|
||||||
|
* @param active true if RPC is active
|
||||||
|
*/
|
||||||
|
void ble_profile_serial_set_rpc_active(FuriHalBleProfileBase* profile, bool active);
|
||||||
|
|
||||||
|
/** Notify that application buffer is empty
|
||||||
|
* @param profile Profile instance
|
||||||
|
*/
|
||||||
|
void ble_profile_serial_notify_buffer_is_empty(FuriHalBleProfileBase* profile);
|
||||||
|
|
||||||
|
/** Set Serial service events callback
|
||||||
|
*
|
||||||
|
* @param profile Profile instance
|
||||||
|
* @param buffer_size Applicaition buffer size
|
||||||
|
* @param calback FuriHalBtSerialCallback instance
|
||||||
|
* @param context pointer to context
|
||||||
|
*/
|
||||||
|
void ble_profile_serial_set_event_callback(
|
||||||
|
FuriHalBleProfileBase* profile,
|
||||||
|
uint16_t buff_size,
|
||||||
|
FuriHalBtSerialCallback callback,
|
||||||
|
void* context);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,28 +1,30 @@
|
|||||||
#include "battery_service.h"
|
#include "battery_service.h"
|
||||||
#include "app_common.h"
|
#include "app_common.h"
|
||||||
#include "gatt_char.h"
|
#include <core/check.h>
|
||||||
|
#include <furi_ble/gatt.h>
|
||||||
|
|
||||||
#include <ble/ble.h>
|
#include <ble/ble.h>
|
||||||
|
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal_power.h>
|
|
||||||
|
#include <m-list.h>
|
||||||
|
|
||||||
#define TAG "BtBatterySvc"
|
#define TAG "BtBatterySvc"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
// Common states
|
/* Common states */
|
||||||
BatterySvcPowerStateUnknown = 0b00,
|
BatterySvcPowerStateUnknown = 0b00,
|
||||||
BatterySvcPowerStateUnsupported = 0b01,
|
BatterySvcPowerStateUnsupported = 0b01,
|
||||||
// Level states
|
/* Level states */
|
||||||
BatterySvcPowerStateGoodLevel = 0b10,
|
BatterySvcPowerStateGoodLevel = 0b10,
|
||||||
BatterySvcPowerStateCriticallyLowLevel = 0b11,
|
BatterySvcPowerStateCriticallyLowLevel = 0b11,
|
||||||
// Charging states
|
/* Charging states */
|
||||||
BatterySvcPowerStateNotCharging = 0b10,
|
BatterySvcPowerStateNotCharging = 0b10,
|
||||||
BatterySvcPowerStateCharging = 0b11,
|
BatterySvcPowerStateCharging = 0b11,
|
||||||
// Discharging states
|
/* Discharging states */
|
||||||
BatterySvcPowerStateNotDischarging = 0b10,
|
BatterySvcPowerStateNotDischarging = 0b10,
|
||||||
BatterySvcPowerStateDischarging = 0b11,
|
BatterySvcPowerStateDischarging = 0b11,
|
||||||
// Battery states
|
/* Battery states */
|
||||||
BatterySvcPowerStateBatteryNotPresent = 0b10,
|
BatterySvcPowerStateBatteryNotPresent = 0b10,
|
||||||
BatterySvcPowerStateBatteryPresent = 0b11,
|
BatterySvcPowerStateBatteryPresent = 0b11,
|
||||||
};
|
};
|
||||||
@@ -46,96 +48,110 @@ typedef enum {
|
|||||||
BatterySvcGattCharacteristicCount,
|
BatterySvcGattCharacteristicCount,
|
||||||
} BatterySvcGattCharacteristicId;
|
} BatterySvcGattCharacteristicId;
|
||||||
|
|
||||||
static const FlipperGattCharacteristicParams battery_svc_chars[BatterySvcGattCharacteristicCount] =
|
static const BleGattCharacteristicParams battery_svc_chars[BatterySvcGattCharacteristicCount] = {
|
||||||
{[BatterySvcGattCharacteristicBatteryLevel] =
|
[BatterySvcGattCharacteristicBatteryLevel] =
|
||||||
{.name = "Battery Level",
|
{.name = "Battery Level",
|
||||||
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
|
||||||
.data.fixed.length = 1,
|
|
||||||
.uuid.Char_UUID_16 = BATTERY_LEVEL_CHAR_UUID,
|
|
||||||
.uuid_type = UUID_TYPE_16,
|
|
||||||
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
|
||||||
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
|
||||||
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
|
||||||
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
|
||||||
[BatterySvcGattCharacteristicPowerState] = {
|
|
||||||
.name = "Power State",
|
|
||||||
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
.data.fixed.length = 1,
|
.data.fixed.length = 1,
|
||||||
.uuid.Char_UUID_16 = BATTERY_POWER_STATE,
|
.uuid.Char_UUID_16 = BATTERY_LEVEL_CHAR_UUID,
|
||||||
.uuid_type = UUID_TYPE_16,
|
.uuid_type = UUID_TYPE_16,
|
||||||
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
||||||
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
||||||
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
.is_variable = CHAR_VALUE_LEN_CONSTANT}};
|
.is_variable = CHAR_VALUE_LEN_CONSTANT},
|
||||||
|
[BatterySvcGattCharacteristicPowerState] = {
|
||||||
|
.name = "Power State",
|
||||||
|
.data_prop_type = FlipperGattCharacteristicDataFixed,
|
||||||
|
.data.fixed.length = 1,
|
||||||
|
.uuid.Char_UUID_16 = BATTERY_POWER_STATE,
|
||||||
|
.uuid_type = UUID_TYPE_16,
|
||||||
|
.char_properties = CHAR_PROP_READ | CHAR_PROP_NOTIFY,
|
||||||
|
.security_permissions = ATTR_PERMISSION_AUTHEN_READ,
|
||||||
|
.gatt_evt_mask = GATT_DONT_NOTIFY_EVENTS,
|
||||||
|
.is_variable = CHAR_VALUE_LEN_CONSTANT}};
|
||||||
|
|
||||||
typedef struct {
|
struct BleServiceBattery {
|
||||||
uint16_t svc_handle;
|
uint16_t svc_handle;
|
||||||
FlipperGattCharacteristicInstance chars[BatterySvcGattCharacteristicCount];
|
BleGattCharacteristicInstance chars[BatterySvcGattCharacteristicCount];
|
||||||
} BatterySvc;
|
bool auto_update;
|
||||||
|
};
|
||||||
|
|
||||||
static BatterySvc* battery_svc = NULL;
|
LIST_DEF(BatterySvcInstanceList, BleServiceBattery*, M_POD_OPLIST);
|
||||||
|
|
||||||
void battery_svc_start() {
|
/* We need to keep track of all battery service instances so that we can update
|
||||||
battery_svc = malloc(sizeof(BatterySvc));
|
* them when the battery state changes. */
|
||||||
tBleStatus status;
|
static BatterySvcInstanceList_t instances;
|
||||||
|
static bool instances_initialized = false;
|
||||||
|
|
||||||
// Add Battery service
|
BleServiceBattery* ble_svc_battery_start(bool auto_update) {
|
||||||
status = aci_gatt_add_service(
|
BleServiceBattery* battery_svc = malloc(sizeof(BleServiceBattery));
|
||||||
UUID_TYPE_16, (Service_UUID_t*)&service_uuid, PRIMARY_SERVICE, 8, &battery_svc->svc_handle);
|
|
||||||
if(status) {
|
if(!ble_gatt_service_add(
|
||||||
FURI_LOG_E(TAG, "Failed to add Battery service: %d", status);
|
UUID_TYPE_16,
|
||||||
|
(Service_UUID_t*)&service_uuid,
|
||||||
|
PRIMARY_SERVICE,
|
||||||
|
8,
|
||||||
|
&battery_svc->svc_handle)) {
|
||||||
|
free(battery_svc);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
for(size_t i = 0; i < BatterySvcGattCharacteristicCount; i++) {
|
for(size_t i = 0; i < BatterySvcGattCharacteristicCount; i++) {
|
||||||
flipper_gatt_characteristic_init(
|
ble_gatt_characteristic_init(
|
||||||
battery_svc->svc_handle, &battery_svc_chars[i], &battery_svc->chars[i]);
|
battery_svc->svc_handle, &battery_svc_chars[i], &battery_svc->chars[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
battery_svc_update_power_state();
|
battery_svc->auto_update = auto_update;
|
||||||
}
|
if(auto_update) {
|
||||||
|
if(!instances_initialized) {
|
||||||
void battery_svc_stop() {
|
BatterySvcInstanceList_init(instances);
|
||||||
tBleStatus status;
|
instances_initialized = true;
|
||||||
if(battery_svc) {
|
|
||||||
for(size_t i = 0; i < BatterySvcGattCharacteristicCount; i++) {
|
|
||||||
flipper_gatt_characteristic_delete(battery_svc->svc_handle, &battery_svc->chars[i]);
|
|
||||||
}
|
}
|
||||||
// Delete Battery service
|
|
||||||
status = aci_gatt_del_service(battery_svc->svc_handle);
|
BatterySvcInstanceList_push_back(instances, battery_svc);
|
||||||
if(status) {
|
}
|
||||||
FURI_LOG_E(TAG, "Failed to delete Battery service: %d", status);
|
|
||||||
|
return battery_svc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ble_svc_battery_stop(BleServiceBattery* battery_svc) {
|
||||||
|
furi_assert(battery_svc);
|
||||||
|
if(battery_svc->auto_update) {
|
||||||
|
BatterySvcInstanceList_it_t it;
|
||||||
|
for(BatterySvcInstanceList_it(it, instances); !BatterySvcInstanceList_end_p(it);
|
||||||
|
BatterySvcInstanceList_next(it)) {
|
||||||
|
if(*BatterySvcInstanceList_ref(it) == battery_svc) {
|
||||||
|
BatterySvcInstanceList_remove(instances, it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(battery_svc);
|
|
||||||
battery_svc = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(size_t i = 0; i < BatterySvcGattCharacteristicCount; i++) {
|
||||||
|
ble_gatt_characteristic_delete(battery_svc->svc_handle, &battery_svc->chars[i]);
|
||||||
|
}
|
||||||
|
/* Delete Battery service */
|
||||||
|
ble_gatt_service_delete(battery_svc->svc_handle);
|
||||||
|
free(battery_svc);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool battery_svc_is_started() {
|
bool ble_svc_battery_update_level(BleServiceBattery* battery_svc, uint8_t battery_charge) {
|
||||||
return battery_svc != NULL;
|
furi_check(battery_svc);
|
||||||
}
|
/* Update battery level characteristic */
|
||||||
|
return ble_gatt_characteristic_update(
|
||||||
bool battery_svc_update_level(uint8_t battery_charge) {
|
|
||||||
// Check if service was started
|
|
||||||
if(battery_svc == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Update battery level characteristic
|
|
||||||
return flipper_gatt_characteristic_update(
|
|
||||||
battery_svc->svc_handle,
|
battery_svc->svc_handle,
|
||||||
&battery_svc->chars[BatterySvcGattCharacteristicBatteryLevel],
|
&battery_svc->chars[BatterySvcGattCharacteristicBatteryLevel],
|
||||||
&battery_charge);
|
&battery_charge);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool battery_svc_update_power_state() {
|
bool ble_svc_battery_update_power_state(BleServiceBattery* battery_svc, bool charging) {
|
||||||
// Check if service was started
|
furi_check(battery_svc);
|
||||||
if(battery_svc == NULL) {
|
|
||||||
return false;
|
/* Update power state characteristic */
|
||||||
}
|
|
||||||
// Update power state characteristic
|
|
||||||
BattrySvcPowerState power_state = {
|
BattrySvcPowerState power_state = {
|
||||||
.level = BatterySvcPowerStateUnsupported,
|
.level = BatterySvcPowerStateUnsupported,
|
||||||
.present = BatterySvcPowerStateBatteryPresent,
|
.present = BatterySvcPowerStateBatteryPresent,
|
||||||
};
|
};
|
||||||
if(furi_hal_power_is_charging()) {
|
if(charging) {
|
||||||
power_state.charging = BatterySvcPowerStateCharging;
|
power_state.charging = BatterySvcPowerStateCharging;
|
||||||
power_state.discharging = BatterySvcPowerStateNotDischarging;
|
power_state.discharging = BatterySvcPowerStateNotDischarging;
|
||||||
} else {
|
} else {
|
||||||
@@ -143,8 +159,29 @@ bool battery_svc_update_power_state() {
|
|||||||
power_state.discharging = BatterySvcPowerStateDischarging;
|
power_state.discharging = BatterySvcPowerStateDischarging;
|
||||||
}
|
}
|
||||||
|
|
||||||
return flipper_gatt_characteristic_update(
|
return ble_gatt_characteristic_update(
|
||||||
battery_svc->svc_handle,
|
battery_svc->svc_handle,
|
||||||
&battery_svc->chars[BatterySvcGattCharacteristicPowerState],
|
&battery_svc->chars[BatterySvcGattCharacteristicPowerState],
|
||||||
&power_state);
|
&power_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ble_svc_battery_state_update(uint8_t* battery_level, bool* charging) {
|
||||||
|
if(!instances_initialized) {
|
||||||
|
#ifdef FURI_BLE_EXTRA_LOG
|
||||||
|
FURI_LOG_W(TAG, "Battery service not initialized");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BatterySvcInstanceList_it_t it;
|
||||||
|
for(BatterySvcInstanceList_it(it, instances); !BatterySvcInstanceList_end_p(it);
|
||||||
|
BatterySvcInstanceList_next(it)) {
|
||||||
|
BleServiceBattery* battery_svc = *BatterySvcInstanceList_ref(it);
|
||||||
|
if(battery_level) {
|
||||||
|
ble_svc_battery_update_level(battery_svc, *battery_level);
|
||||||
|
}
|
||||||
|
if(charging) {
|
||||||
|
ble_svc_battery_update_power_state(battery_svc, *charging);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,15 +7,27 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void battery_svc_start();
|
/*
|
||||||
|
* Battery service. Can be used in most profiles.
|
||||||
|
* If auto_update is true, the service will automatically update the battery
|
||||||
|
* level and charging state from power state updates.
|
||||||
|
*/
|
||||||
|
|
||||||
void battery_svc_stop();
|
typedef struct BleServiceBattery BleServiceBattery;
|
||||||
|
|
||||||
bool battery_svc_is_started();
|
BleServiceBattery* ble_svc_battery_start(bool auto_update);
|
||||||
|
|
||||||
bool battery_svc_update_level(uint8_t battery_level);
|
void ble_svc_battery_stop(BleServiceBattery* service);
|
||||||
|
|
||||||
bool battery_svc_update_power_state();
|
bool ble_svc_battery_update_level(BleServiceBattery* service, uint8_t battery_level);
|
||||||
|
|
||||||
|
bool ble_svc_battery_update_power_state(BleServiceBattery* service, bool charging);
|
||||||
|
|
||||||
|
/* Global function, callable without a service instance
|
||||||
|
* Will update all service instances created with auto_update==true
|
||||||
|
* Both parameters are optional, pass NULL if no value is available
|
||||||
|
*/
|
||||||
|
void ble_svc_battery_state_update(uint8_t* battery_level, bool* charging);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user