1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-02 03:48:58 +00:00

refactor(ble): rename ble_management

[no changelog]
This commit is contained in:
tychovrahe 2025-02-20 09:13:11 +01:00 committed by TychoVrahe
parent c97dd18c2d
commit 06223b78fe
6 changed files with 27 additions and 27 deletions

View File

@ -13,7 +13,7 @@ target_sources(app PRIVATE
src/main.c src/main.c
src/ble/connection.c src/ble/connection.c
src/ble/advertising.c src/ble/advertising.c
src/ble/management.c src/ble/ble_management.c
src/ble/service.c src/ble/service.c
src/ble/bonds.c src/ble/bonds.c
src/ble/pairing.c src/ble/pairing.c

View File

@ -129,32 +129,32 @@ void advertising_start(bool wl, uint8_t color, uint32_t device_code,
} }
if (err) { if (err) {
LOG_ERR("Advertising failed to start (err %d)", err); LOG_ERR("Advertising failed to start (err %d)", err);
management_send_status_event(); ble_management_send_status_event();
return; return;
} }
advertising = true; advertising = true;
advertising_wl = wl; advertising_wl = wl;
management_send_status_event(); ble_management_send_status_event();
} }
void advertising_stop(void) { void advertising_stop(void) {
if (!advertising) { if (!advertising) {
LOG_WRN("Not advertising"); LOG_WRN("Not advertising");
management_send_status_event(); ble_management_send_status_event();
return; return;
} }
int err = bt_le_adv_stop(); int err = bt_le_adv_stop();
if (err) { if (err) {
LOG_ERR("Advertising failed to stop (err %d)", err); LOG_ERR("Advertising failed to stop (err %d)", err);
management_send_status_event(); ble_management_send_status_event();
return; return;
} }
advertising = false; advertising = false;
advertising_wl = false; advertising_wl = false;
management_send_status_event(); ble_management_send_status_event();
} }
bool advertising_is_advertising(void) { return advertising; } bool advertising_is_advertising(void) { return advertising; }

View File

@ -74,12 +74,12 @@ bool ble_init(void) {
} }
advertising_init(); advertising_init();
management_init(); ble_management_init();
k_sem_give(&ble_init_ok); k_sem_give(&ble_init_ok);
LOG_INF("Bluetooth initialized"); LOG_INF("Bluetooth initialized");
management_send_status_event(); ble_management_send_status_event();
return true; return true;
} }

View File

@ -88,13 +88,13 @@ typedef enum {
// BLE management functions // BLE management functions
// Initialization // Initialization
void management_init(void); void ble_management_init(void);
// Send status event // Send status event
void management_send_status_event(void); void ble_management_send_status_event(void);
// Send Pairing Request event, data is the pairing code // Send Pairing Request event, data is the pairing code
void management_send_pairing_request_event(uint8_t *data, uint16_t len); void ble_management_send_pairing_request_event(uint8_t *data, uint16_t len);
// Send Pairing Cancelled event // Send Pairing Cancelled event
void management_send_pairing_cancelled_event(void); void ble_management_send_pairing_cancelled_event(void);
// Bonds // Bonds
// Erase all bonds // Erase all bonds

View File

@ -33,9 +33,9 @@
#define LOG_MODULE_NAME ble_manangement #define LOG_MODULE_NAME ble_manangement
LOG_MODULE_REGISTER(LOG_MODULE_NAME); LOG_MODULE_REGISTER(LOG_MODULE_NAME);
static K_SEM_DEFINE(management_ok, 0, 1); static K_SEM_DEFINE(ble_management_ok, 0, 1);
void management_send_status_event(void) { void ble_management_send_status_event(void) {
// ble_version_t version = {0}; // ble_version_t version = {0};
// //
// sd_ble_version_get(&version); // sd_ble_version_get(&version);
@ -60,21 +60,21 @@ void management_send_status_event(void) {
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, (uint8_t *)&msg, sizeof(msg)); trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, (uint8_t *)&msg, sizeof(msg));
} }
void management_send_success_event(void) { static void management_send_success_event(void) {
uint8_t tx_data[] = { uint8_t tx_data[] = {
INTERNAL_EVENT_SUCCESS, INTERNAL_EVENT_SUCCESS,
}; };
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data)); trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
} }
void management_send_failure_event(void) { static void management_send_failure_event(void) {
uint8_t tx_data[] = { uint8_t tx_data[] = {
INTERNAL_EVENT_FAILURE, INTERNAL_EVENT_FAILURE,
}; };
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data)); trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
} }
void management_send_pairing_cancelled_event(void) { void ble_management_send_pairing_cancelled_event(void) {
uint8_t tx_data[1] = {0}; uint8_t tx_data[1] = {0};
tx_data[0] = INTERNAL_EVENT_PAIRING_CANCELLED; tx_data[0] = INTERNAL_EVENT_PAIRING_CANCELLED;
@ -82,7 +82,7 @@ void management_send_pairing_cancelled_event(void) {
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data)); trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
} }
void management_send_pairing_request_event(uint8_t *data, uint16_t len) { void ble_management_send_pairing_request_event(uint8_t *data, uint16_t len) {
uint8_t tx_data[7] = {0}; uint8_t tx_data[7] = {0};
tx_data[0] = INTERNAL_EVENT_PAIRING_REQUEST; tx_data[0] = INTERNAL_EVENT_PAIRING_REQUEST;
@ -96,7 +96,7 @@ void management_send_pairing_request_event(uint8_t *data, uint16_t len) {
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data)); trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
} }
void management_send_mac(uint8_t *mac) { static void management_send_mac(uint8_t *mac) {
uint8_t tx_data[1 + BT_ADDR_SIZE] = {0}; uint8_t tx_data[1 + BT_ADDR_SIZE] = {0};
tx_data[0] = INTERNAL_EVENT_MAC; tx_data[0] = INTERNAL_EVENT_MAC;
memcpy(&tx_data[1], mac, BT_ADDR_SIZE); memcpy(&tx_data[1], mac, BT_ADDR_SIZE);
@ -110,7 +110,7 @@ static void process_command(uint8_t *data, uint16_t len) {
switch (cmd) { switch (cmd) {
case INTERNAL_CMD_SEND_STATE: case INTERNAL_CMD_SEND_STATE:
send_response = false; send_response = false;
management_send_status_event(); ble_management_send_status_event();
break; break;
case INTERNAL_CMD_ADVERTISING_ON: { case INTERNAL_CMD_ADVERTISING_ON: {
uint8_t color = data[2]; uint8_t color = data[2];
@ -162,11 +162,11 @@ static void process_command(uint8_t *data, uint16_t len) {
} }
} }
void management_init(void) { k_sem_give(&management_ok); } void ble_management_init(void) { k_sem_give(&ble_management_ok); }
void management_thread(void) { void ble_management_thread(void) {
/* Don't go any further until BLE is initialized */ /* Don't go any further until BLE is initialized */
k_sem_take(&management_ok, K_FOREVER); k_sem_take(&ble_management_ok, K_FOREVER);
for (;;) { for (;;) {
trz_packet_t *buf = trz_comm_poll_data(NRF_SERVICE_BLE_MANAGER); trz_packet_t *buf = trz_comm_poll_data(NRF_SERVICE_BLE_MANAGER);
@ -175,5 +175,5 @@ void management_thread(void) {
} }
} }
K_THREAD_DEFINE(management_thread_id, CONFIG_DEFAULT_THREAD_STACK_SIZE, K_THREAD_DEFINE(ble_management_thread_id, CONFIG_DEFAULT_THREAD_STACK_SIZE,
management_thread, NULL, NULL, NULL, 7, 0, 0); ble_management_thread, NULL, NULL, NULL, 7, 0, 0);

View File

@ -56,7 +56,7 @@ void connected(struct bt_conn *conn, uint8_t err) {
// LOG_ERR("Phy update request failed: %d", err); // LOG_ERR("Phy update request failed: %d", err);
// } // }
management_send_status_event(); ble_management_send_status_event();
} }
void disconnected(struct bt_conn *conn, uint8_t reason) { void disconnected(struct bt_conn *conn, uint8_t reason) {
@ -73,7 +73,7 @@ void disconnected(struct bt_conn *conn, uint8_t reason) {
current_conn = NULL; current_conn = NULL;
} }
management_send_status_event(); ble_management_send_status_event();
} }
static void security_changed(struct bt_conn *conn, bt_security_t level, static void security_changed(struct bt_conn *conn, bt_security_t level,