diff --git a/include/os_io_seproxyhal.h b/include/os_io_seproxyhal.h index 83d236e22..b8e35a0a7 100644 --- a/include/os_io_seproxyhal.h +++ b/include/os_io_seproxyhal.h @@ -316,6 +316,7 @@ void io_seproxyhal_play_tune(tune_index_e tune_index); void io_seph_ble_enable(unsigned char enable); void io_seph_ble_clear_bond_db(void); void io_seph_ble_name_changed(void); +void io_seph_ux_accept_pairing(unsigned char status); #endif // HAVE_BLE void io_seph_ux_redisplay(void); diff --git a/include/seproxyhal_protocol.h b/include/seproxyhal_protocol.h index e4ffe62c6..481628a65 100644 --- a/include/seproxyhal_protocol.h +++ b/include/seproxyhal_protocol.h @@ -205,6 +205,7 @@ #define SEPROXYHAL_TAG_UX_CMD_BLE_RESET_PAIRINGS 0x02 #define SEPROXYHAL_TAG_UX_CMD_REDISPLAY 0x03 #define SEPROXYHAL_TAG_UX_CMD_BLE_NAME_CHANGED 0x04 +#define SEPROXYHAL_TAG_UX_CMD_ACCEPT_PAIRING 0x05 #ifdef HAVE_SERIALIZED_NBGL #define SEPROXYHAL_TAG_NBGL_SERIALIZED 0x5C diff --git a/lib_blewbxx_impl/include/ledger_ble.h b/lib_blewbxx_impl/include/ledger_ble.h index 4183a7a65..9c7100b6c 100644 --- a/lib_blewbxx_impl/include/ledger_ble.h +++ b/lib_blewbxx_impl/include/ledger_ble.h @@ -39,6 +39,7 @@ void LEDGER_BLE_send(uint8_t *packet, uint16_t packet_length); void LEDGER_BLE_receive(void); void LEDGER_BLE_enable_advertising(uint8_t enable); void LEDGER_BLE_reset_pairings(void); +void LEDGER_BLE_accept_pairing(uint8_t status); #define LEDGER_BLE_get_mac_address(address) \ { \ diff --git a/lib_blewbxx_impl/src/ledger_ble.c b/lib_blewbxx_impl/src/ledger_ble.c index 4eba98fba..61b8f239e 100644 --- a/lib_blewbxx_impl/src/ledger_ble.c +++ b/lib_blewbxx_impl/src/ledger_ble.c @@ -747,12 +747,16 @@ static void ask_user_pairing_numeric_comparison(uint32_t code) bolos_ux_params_t ux_params; ux_params.u.pairing_request.type = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST_NUMCOMP; + ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST; + ux_params.len = sizeof(ux_params.u.pairing_request); + ledger_ble_data.pairing_in_progress = 1; ux_params.u.pairing_request.pairing_info_len = 6; SPRINTF(ux_params.u.pairing_request.pairing_info, "%06d", (unsigned int) code); - ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST; - ux_params.len = sizeof(ux_params.u.pairing_request); +#ifdef TARGET_STAX + G_io_asynch_ux_callback.asynchmodal_end_callback = NULL; +#else // !TARGET_STAX G_io_asynch_ux_callback.asynchmodal_end_callback = rsp_user_pairing_numeric_comparison; - ledger_ble_data.pairing_in_progress = 1; +#endif // !TARGET_STAX os_ux(&ux_params); } @@ -779,28 +783,35 @@ static void ask_user_pairing_passkey(void) { bolos_ux_params_t ux_params; - ledger_ble_data.pairing_code = cx_rng_u32_range_func(0, 1000000, cx_rng_u32); ux_params.u.pairing_request.type = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST_PASSKEY; + ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST; + ux_params.len = sizeof(ux_params.u.pairing_request); + ledger_ble_data.pairing_in_progress = 1; + ledger_ble_data.pairing_code = cx_rng_u32_range_func(0, 1000000, cx_rng_u32); ux_params.u.pairing_request.pairing_info_len = 6; SPRINTF(ux_params.u.pairing_request.pairing_info, "%06d", ledger_ble_data.pairing_code); - ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST; - ux_params.len = sizeof(ux_params.u.pairing_request); +#ifdef TARGET_STAX + G_io_asynch_ux_callback.asynchmodal_end_callback = NULL; +#else // !TARGET_STAX G_io_asynch_ux_callback.asynchmodal_end_callback = rsp_user_pairing_passkey; - ledger_ble_data.pairing_in_progress = 1; +#endif // !TARGET_STAX os_ux(&ux_params); } static void rsp_user_pairing_passkey(unsigned int status) { - if (status != BOLOS_UX_OK) { // BLE_TODO + if (status == BOLOS_UX_OK) { end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_ACCEPT_PASSKEY); ledger_ble_data.pairing_code = cx_rng_u32_range_func(0, 1000000, cx_rng_u32); + aci_gap_pass_key_resp(ledger_ble_data.connection.connection_handle, + ledger_ble_data.pairing_code); + } + else if (status == BOLOS_UX_IGNORE) { + ledger_ble_data.pairing_in_progress = 0; } else { end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_CANCEL_PASSKEY); } - aci_gap_pass_key_resp(ledger_ble_data.connection.connection_handle, - ledger_ble_data.pairing_code); } static void attribute_modified(uint8_t *buffer, uint16_t length) @@ -1146,6 +1157,16 @@ void LEDGER_BLE_reset_pairings(void) } } +void LEDGER_BLE_accept_pairing(uint8_t status) +{ + if (ledger_ble_data.pairing_in_progress == 1) { + rsp_user_pairing_numeric_comparison(status); + } + else if (ledger_ble_data.pairing_in_progress == 2) { + rsp_user_pairing_passkey(status); + } +} + int hci_send_req(struct hci_request *p_cmd, uint8_t async) { UNUSED(async); diff --git a/lib_ux_stax/ux.c b/lib_ux_stax/ux.c index 8ac3b24c1..1b4d3c248 100644 --- a/lib_ux_stax/ux.c +++ b/lib_ux_stax/ux.c @@ -37,17 +37,6 @@ static bool ux_forward_event(bool ignoring_app_if_ux_busy) G_ux_params.len = 0; os_ux(&G_ux_params); G_ux_params.len = os_sched_last_status(TASK_BOLOS_UX); -#ifdef HAVE_BLE - if (G_ux.asynchmodal_end_callback - && (os_ux_get_status(BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST) != 0)) { - asynchmodal_end_callback_t cb = G_ux.asynchmodal_end_callback; - // reset G_ux.asynchmodal_end_callback for next time - G_ux.asynchmodal_end_callback = NULL; - cb(os_ux_get_status(BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST)); - // for app to redraw/refresh itself - G_ux_params.len = BOLOS_UX_REDRAW; - } -#endif // HAVE_BLE if (G_ux_params.len == BOLOS_UX_REDRAW) { // enable drawing according to UX decision nbgl_objAllowDrawing(true); diff --git a/src/os_io_seproxyhal.c b/src/os_io_seproxyhal.c index acdc3f398..dc435a067 100644 --- a/src/os_io_seproxyhal.c +++ b/src/os_io_seproxyhal.c @@ -312,6 +312,11 @@ unsigned int io_seproxyhal_handle_event(void) G_io_app.name_changed = 1; io_seph_ble_enable(0); break; + + case SEPROXYHAL_TAG_UX_CMD_ACCEPT_PAIRING: + LEDGER_BLE_accept_pairing(G_io_seproxyhal_spi_buffer[4]); + return 1; + break; #endif // HAVE_BLE #if !defined(HAVE_BOLOS) && defined(HAVE_BAGL) @@ -319,7 +324,16 @@ unsigned int io_seproxyhal_handle_event(void) ux_stack_redisplay(); return 1; break; -#endif // HAVE_BOLOS +#endif // HAVE_BOLOS && HAVE_BAGL + +#if !defined(HAVE_BOLOS) && defined(HAVE_NBGL) + case SEPROXYHAL_TAG_UX_CMD_REDISPLAY: + nbgl_objAllowDrawing(true); + nbgl_screenRedraw(); + nbgl_refresh(); + return 1; + break; +#endif // HAVE_BOLOS && HAVE_NBGL default: return io_event(CHANNEL_SPI); @@ -1081,6 +1095,16 @@ void io_seph_ux_redisplay(void) io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 4); } +void io_seph_ux_accept_pairing(unsigned char status) +{ + G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_UX_CMD; + G_io_seproxyhal_spi_buffer[1] = 0; + G_io_seproxyhal_spi_buffer[2] = 2; + G_io_seproxyhal_spi_buffer[3] = SEPROXYHAL_TAG_UX_CMD_ACCEPT_PAIRING; + G_io_seproxyhal_spi_buffer[4] = status; + io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 5); +} + static const unsigned char seph_io_usb_disconnect[] = { SEPROXYHAL_TAG_USB_CONFIG, 0,