1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-26 07:11:25 +00:00

fixup! feat(core:): introduce BLE driver

This commit is contained in:
tychovrahe 2025-01-08 11:25:52 +01:00
parent bece4d87e1
commit a265089ad9
2 changed files with 28 additions and 4 deletions

View File

@ -56,6 +56,9 @@ typedef struct {
typedef struct { typedef struct {
bool connected; bool connected;
bool connectable;
bool pairing;
bool pairing_requested;
uint8_t peer_count; uint8_t peer_count;
} ble_state_t; } ble_state_t;

View File

@ -51,6 +51,7 @@ typedef struct {
bool initialized; bool initialized;
bool status_valid; bool status_valid;
bool accept_msgs; bool accept_msgs;
bool pairing_requested;
ble_event_t event_queue_buffers[EVENT_QUEUE_LEN]; ble_event_t event_queue_buffers[EVENT_QUEUE_LEN];
tsqueue_entry_t event_queue_entries[EVENT_QUEUE_LEN]; tsqueue_entry_t event_queue_entries[EVENT_QUEUE_LEN];
tsqueue_t event_queue; tsqueue_t event_queue;
@ -103,14 +104,26 @@ static bool ble_send_disconnect(void) {
static bool ble_send_pairing_reject(void) { static bool ble_send_pairing_reject(void) {
uint8_t cmd = INTERNAL_CMD_REJECT_PAIRING; uint8_t cmd = INTERNAL_CMD_REJECT_PAIRING;
return nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL) >= bool result =
0; nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL);
if (result) {
g_ble_driver.pairing_requested = false;
}
return result;
} }
static bool ble_send_pairing_accept(void) { static bool ble_send_pairing_accept(void) {
uint8_t cmd = INTERNAL_CMD_ALLOW_PAIRING; uint8_t cmd = INTERNAL_CMD_ALLOW_PAIRING;
return nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL) >= bool result =
0; nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL);
if (result) {
g_ble_driver.pairing_requested = false;
}
return result;
} }
static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) { static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
@ -152,6 +165,8 @@ static void ble_process_rx_msg_status(const uint8_t *data, uint32_t len) {
if (drv->mode_current == BLE_MODE_PAIRING) { if (drv->mode_current == BLE_MODE_PAIRING) {
drv->mode_requested = BLE_MODE_CONNECTABLE; drv->mode_requested = BLE_MODE_CONNECTABLE;
} }
drv->pairing_requested = false;
} }
drv->connected = msg.connected; drv->connected = msg.connected;
@ -193,6 +208,8 @@ static void ble_process_rx_msg_pairing_request(const uint8_t *data,
if (!tsqueue_enqueue(&drv->event_queue, (uint8_t *)&event, sizeof(event), if (!tsqueue_enqueue(&drv->event_queue, (uint8_t *)&event, sizeof(event),
NULL)) { NULL)) {
ble_send_pairing_reject(); ble_send_pairing_reject();
} else {
drv->pairing_requested = true;
} }
} }
@ -205,6 +222,7 @@ static void ble_process_rx_msg_pairing_cancelled(const uint8_t *data,
ble_event_t event = {.type = BLE_PAIRING_CANCELLED, .data_len = 0}; ble_event_t event = {.type = BLE_PAIRING_CANCELLED, .data_len = 0};
tsqueue_enqueue(&drv->event_queue, (uint8_t *)&event, sizeof(event), NULL); tsqueue_enqueue(&drv->event_queue, (uint8_t *)&event, sizeof(event), NULL);
drv->pairing_requested = false;
} }
static void ble_process_rx_msg(const uint8_t *data, uint32_t len) { static void ble_process_rx_msg(const uint8_t *data, uint32_t len) {
@ -489,6 +507,9 @@ void ble_get_state(ble_state_t *state) {
state->connected = drv->connected; state->connected = drv->connected;
state->peer_count = drv->peer_count; state->peer_count = drv->peer_count;
state->pairing = drv->mode_current == BLE_MODE_PAIRING;
state->connectable = drv->mode_current == BLE_MODE_CONNECTABLE;
state->pairing_requested = drv->pairing_requested;
} }
#endif #endif