mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-25 06:40:58 +00:00
fixup! feat(core:): introduce BLE driver
This commit is contained in:
parent
bece4d87e1
commit
a265089ad9
@ -56,6 +56,9 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
bool connected;
|
||||
bool connectable;
|
||||
bool pairing;
|
||||
bool pairing_requested;
|
||||
uint8_t peer_count;
|
||||
} ble_state_t;
|
||||
|
||||
|
@ -51,6 +51,7 @@ typedef struct {
|
||||
bool initialized;
|
||||
bool status_valid;
|
||||
bool accept_msgs;
|
||||
bool pairing_requested;
|
||||
ble_event_t event_queue_buffers[EVENT_QUEUE_LEN];
|
||||
tsqueue_entry_t event_queue_entries[EVENT_QUEUE_LEN];
|
||||
tsqueue_t event_queue;
|
||||
@ -103,14 +104,26 @@ static bool ble_send_disconnect(void) {
|
||||
|
||||
static bool ble_send_pairing_reject(void) {
|
||||
uint8_t cmd = INTERNAL_CMD_REJECT_PAIRING;
|
||||
return nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL) >=
|
||||
0;
|
||||
bool result =
|
||||
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) {
|
||||
uint8_t cmd = INTERNAL_CMD_ALLOW_PAIRING;
|
||||
return nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL) >=
|
||||
0;
|
||||
bool result =
|
||||
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) {
|
||||
@ -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) {
|
||||
drv->mode_requested = BLE_MODE_CONNECTABLE;
|
||||
}
|
||||
|
||||
drv->pairing_requested = false;
|
||||
}
|
||||
|
||||
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),
|
||||
NULL)) {
|
||||
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};
|
||||
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) {
|
||||
@ -489,6 +507,9 @@ void ble_get_state(ble_state_t *state) {
|
||||
|
||||
state->connected = drv->connected;
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user