21 #include "os_settings.h"
22 #include "os_io_seproxyhal.h"
24 #include "ble_hci_le.h"
25 #include "ble_hal_aci.h"
26 #include "ble_gap_aci.h"
27 #include "ble_l2cap_aci.h"
28 #include "ble_gatt_aci.h"
29 #include "ble_legacy.h"
33 #include "ledger_protocol.h"
94 char device_name[20 + 1];
96 uint8_t random_address[CONFIG_DATA_RANDOM_ADDRESS_LEN];
143 #define MAX_MTU_SIZE 156
145 #define BLE_SLAVE_CONN_INTERVAL_MIN 12
146 #define BLE_SLAVE_CONN_INTERVAL_MAX 24
148 #define BLE_ADVERTISING_INTERVAL_MIN 48
149 #define BLE_ADVERTISING_INTERVAL_MAX 96
152 #define LOG_BLE PRINTF
160 static void get_device_name(
void);
161 static void configure_advertising_mngr(
uint16_t opcode);
163 static void hci_evt_cmd_complete(
const uint8_t *buffer,
uint16_t length);
164 static void hci_evt_le_meta_evt(
const uint8_t *buffer,
uint16_t length);
166 #ifdef HAVE_INAPP_BLE_PAIRING
167 static void end_pairing_ux(
uint8_t pairing_ok);
168 static void ask_user_pairing_numeric_comparison(uint32_t code);
169 static void rsp_user_pairing_numeric_comparison(
unsigned int status);
170 static void ask_user_pairing_passkey(
void);
171 static void rsp_user_pairing_passkey(
unsigned int status);
173 static void attribute_modified(
const uint8_t *buffer,
uint16_t length);
174 static void write_permit_request(
const uint8_t *buffer,
uint16_t length);
175 static void advertising_enable(
uint8_t enable);
176 static void start_advertising(
void);
177 static void notify_chunk(
void);
178 static void check_transfer_mode(
uint8_t enable);
185 const uint8_t service_uuid[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x00,0x00,0x04,0x30,0x97,0x2C,0x00,0x34,0xD6,0x13,};
186 const uint8_t charUuidTX[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x01,0x00,0x04,0x30,0x97,0x2C,0x00,0x34,0xD6,0x13,};
187 const uint8_t charUuidRX[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x02,0x00,0x04,0x30,0x97,0x2C,0x00,0x34,0xD6,0x13,};
188 const uint8_t charUuidRX2[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x03,0x00,0x04,0x30,0x97,0x2C,0x00,0x34,0xD6,0x13,};
192 const uint8_t service_uuid[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x00,0x00,0x04,0x60,0x97,0x2C,0x00,0x34,0xD6,0x13,};
193 const uint8_t charUuidTX[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x01,0x00,0x04,0x60,0x97,0x2C,0x00,0x34,0xD6,0x13,};
194 const uint8_t charUuidRX[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x02,0x00,0x04,0x60,0x97,0x2C,0x00,0x34,0xD6,0x13,};
195 const uint8_t charUuidRX2[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x03,0x00,0x04,0x60,0x97,0x2C,0x00,0x34,0xD6,0x13,};
199 const uint8_t service_uuid[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x00,0x00,0x04,0x00,0x97,0x2C,0x00,0x34,0xD6,0x13,};
200 const uint8_t charUuidTX[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x01,0x00,0x04,0x00,0x97,0x2C,0x00,0x34,0xD6,0x13,};
201 const uint8_t charUuidRX[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x02,0x00,0x04,0x00,0x97,0x2C,0x00,0x34,0xD6,0x13,};
202 const uint8_t charUuidRX2[16] = {0x72,0x65,0x67,0x64,0x65,0x4c,0x03,0x00,0x04,0x00,0x97,0x2C,0x00,0x34,0xD6,0x13,};
206 static ledger_protocol_t ledger_protocol_data;
210 static void copy_apdu_to_app(
bool update_wait_status)
214 memcpy(ledger_protocol_data.rx_dst_buffer,
215 ledger_protocol_data.rx_apdu_buffer,
216 ledger_protocol_data.rx_apdu_length);
217 G_io_app.apdu_length = ledger_protocol_data.rx_apdu_length;
218 G_io_app.apdu_state = APDU_BLE;
219 G_io_app.apdu_media = IO_APDU_MEDIA_BLE;
220 ledger_protocol_data.rx_apdu_length = 0;
221 if (update_wait_status) {
222 ledger_protocol_data.rx_apdu_status = APDU_STATUS_WAITING;
226 static void get_device_name(
void)
234 static void configure_advertising_mngr(
uint16_t opcode)
247 LOG_BLE(
"CONFIGURE ADVERTISING START\n");
263 buffer[index++] = AD_TYPE_FLAGS;
264 buffer[index++] = FLAG_BIT_BR_EDR_NOT_SUPPORTED | FLAG_BIT_LE_GENERAL_DISCOVERABLE_MODE;
269 buffer[index++] = AD_TYPE_COMPLETE_LOCAL_NAME;
274 aci_gap_update_adv_data(index, buffer);
279 buffer[index++] =
sizeof(service_uuid) + 1;
280 buffer[index++] = AD_TYPE_128_BIT_SERV_UUID;
281 memcpy(&buffer[index], service_uuid,
sizeof(service_uuid));
282 index +=
sizeof(service_uuid);
286 buffer[index++] = AD_TYPE_SLAVE_CONN_INTERVAL;
293 hci_le_set_scan_response_data(index, buffer);
307 advertising_enable(1);
311 LOG_BLE(
"CONFIGURE ADVERTISING END\n");
339 else if ((length >= 2)
343 else if ((length >= 2)
347 else if ((length >= 2)
352 ledger_ble_data.
adv_enable = !os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
353 configure_advertising_mngr(opcode);
368 aci_hal_write_config_data(CONFIG_DATA_RANDOM_ADDRESS_OFFSET,
369 CONFIG_DATA_RANDOM_ADDRESS_LEN,
380 aci_gap_init(GAP_PERIPHERAL_ROLE,
390 aci_gap_set_io_capability(IO_CAP_DISPLAY_YES_NO);
395 aci_gap_set_authentication_requirement(
397 MITM_PROTECTION_REQUIRED,
399 KEYPRESS_NOT_SUPPORTED,
400 MIN_ENCRY_KEY_SIZE + 1,
402 DONOT_USE_FIXED_PIN_FOR_PAIRING,
409 aci_gatt_add_service(UUID_TYPE_128,
410 (
const Service_UUID_t *) service_uuid,
420 (
const Char_UUID_t *) charUuidTX,
423 ATTR_PERMISSION_AUTHEN_WRITE,
424 GATT_DONT_NOTIFY_EVENTS,
426 CHAR_VALUE_LEN_VARIABLE,
434 (
const Char_UUID_t *) charUuidRX,
437 ATTR_PERMISSION_AUTHEN_WRITE,
438 GATT_NOTIFY_WRITE_REQ_AND_WAIT_FOR_APPL_RESP,
440 CHAR_VALUE_LEN_VARIABLE,
448 (
const Char_UUID_t *) charUuidRX2,
450 CHAR_PROP_WRITE_WITHOUT_RESP,
451 ATTR_PERMISSION_AUTHEN_WRITE,
452 GATT_NOTIFY_ATTRIBUTE_WRITE,
454 CHAR_VALUE_LEN_VARIABLE,
460 aci_hal_set_tx_power_level(1,
461 #
if defined(TARGET_STAX) || defined(TARGET_FLEX)
471 ledger_ble_data.
adv_enable = !os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
472 configure_advertising_mngr(0);
479 aci_gap_clear_security_db();
481 G_io_app.ble_ready = 1;
490 static void hci_evt_cmd_complete(
const uint8_t *buffer,
uint16_t length)
499 init_mngr(opcode, &buffer[3], length);
502 configure_advertising_mngr(opcode);
504 else if (opcode == 0xfd26) {
508 if (ledger_protocol_data.tx_chunk_length >= 2) {
509 G_io_app.ble_xfer_timeout = 2000;
514 else if (opcode == 0xfd06) {
516 ledger_protocol_data.tx_chunk_length = 0;
518 if ((ledger_protocol_data.rx_apdu_length)
519 && (ledger_protocol_data.rx_apdu_status == APDU_STATUS_COMPLETE)) {
520 copy_apdu_to_app(
false);
524 if (ledger_protocol_data.tx_apdu_buffer) {
525 LEDGER_PROTOCOL_tx(&ledger_protocol_data, NULL, 0);
528 if (!ledger_protocol_data.tx_apdu_buffer) {
529 ledger_protocol_data.tx_chunk_length = 0;
530 G_io_app.ble_xfer_timeout = 0;
531 G_io_app.apdu_state = APDU_IDLE;
535 aci_l2cap_connection_parameter_update_req(
545 else if ((opcode == 0xfc81) || (opcode == 0xfc83)) {
546 LOG_BLE(
"HCI_LE_SET_ADVERTISE_ENABLE %04X %d %d\n",
548 G_io_app.disabling_advertising,
549 G_io_app.enabling_advertising);
551 if (G_io_app.disabling_advertising) {
553 #ifdef HAVE_INAPP_BLE_PAIRING
554 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_FAILED);
559 else if (G_io_app.disabling_advertising) {
561 if (G_io_app.name_changed) {
565 else if (G_io_app.enabling_advertising) {
571 G_io_app.disabling_advertising = 0;
572 G_io_app.enabling_advertising = 0;
574 else if (opcode == 0xfca5) {
575 LOG_BLE(
"ACI_GAP_NUMERIC_COMPARISON_VALUE_CONFIRM_YESNO\n");
577 else if (opcode == 0xfc94) {
578 LOG_BLE(
"ACI_GAP_CLEAR_SECURITY_DB\n");
580 else if (opcode == 0xfd25) {
581 LOG_BLE(
"ACI_GATT_CONFIRM_INDICATION\n");
584 LOG_BLE(
"HCI EVT CMD COMPLETE 0x%04X\n", opcode);
588 static void hci_evt_le_meta_evt(
const uint8_t *buffer,
uint16_t length)
595 case HCI_LE_CONNECTION_COMPLETE_SUBEVT_CODE:
606 LOG_BLE(
"LE CONNECTION COMPLETE %04X - %04X- %04X- %04X\n",
611 ledger_protocol_data.mtu = ATT_MTU - 3 + 2;
614 ledger_protocol_data.mtu_negotiated = 0;
618 case HCI_LE_CONNECTION_UPDATE_COMPLETE_SUBEVT_CODE:
623 LOG_BLE(
"LE CONNECTION UPDATE %04X - %04X- %04X- %04X\n",
630 case HCI_LE_DATA_LENGTH_CHANGE_SUBEVT_CODE:
636 LOG_BLE(
"LE DATA LENGTH CHANGE %04X - %04X- %04X- %04X\n",
644 case HCI_LE_PHY_UPDATE_COMPLETE_SUBEVT_CODE:
648 LOG_BLE(
"LE PHY UPDATE %02X - %02X\n",
655 LOG_BLE(
"HCI LE META 0x%02X\n", buffer[0]);
673 #ifdef HAVE_INAPP_BLE_PAIRING
674 case ACI_GAP_PAIRING_COMPLETE_VSEVT_CODE:
677 case SMP_PAIRING_STATUS_SUCCESS:
679 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_SUCCESS);
682 case SMP_PAIRING_STATUS_SMP_TIMEOUT:
684 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_TIMEOUT);
687 case SMP_PAIRING_STATUS_PAIRING_FAILED:
688 LOG_BLE(
" FAILED : %02X\n", buffer[5]);
689 if (buffer[5] == 0x08) {
690 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_CANCELLED_FROM_REMOTE);
693 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_FAILED);
698 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_FAILED);
704 case ACI_GAP_PASS_KEY_REQ_VSEVT_CODE:
706 ask_user_pairing_passkey();
709 case ACI_GAP_NUMERIC_COMPARISON_VALUE_VSEVT_CODE:
710 LOG_BLE(
"NUMERIC COMP : %d\n", U4LE(buffer, 4));
711 ask_user_pairing_numeric_comparison(U4LE(buffer, 4));
715 case ACI_GATT_ATTRIBUTE_MODIFIED_VSEVT_CODE:
716 attribute_modified(&buffer[4], length - 4);
719 case ACI_ATT_EXCHANGE_MTU_RESP_VSEVT_CODE:
720 ledger_protocol_data.mtu = U2LE(buffer, 4) - 3 + 2;
721 ledger_protocol_data.mtu_negotiated = 1;
722 LOG_BLE(
"MTU : %d\n", U2LE(buffer, 4));
725 case ACI_L2CAP_CONNECTION_UPDATE_RESP_VSEVT_CODE:
726 LOG_BLE(
"CONNECTION UPDATE RESP %d\n", buffer[4]);
729 case ACI_GATT_WRITE_PERMIT_REQ_VSEVT_CODE:
730 write_permit_request(&buffer[4], length - 4);
733 case ACI_GATT_INDICATION_VSEVT_CODE:
738 case ACI_GATT_PROC_COMPLETE_VSEVT_CODE:
739 LOG_BLE(
"PROCEDURE COMPLETE\n");
742 case ACI_GATT_PROC_TIMEOUT_VSEVT_CODE:
743 LOG_BLE(
"PROCEDURE TIMEOUT\n");
744 #ifdef HAVE_INAPP_BLE_PAIRING
745 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_FAILED);
751 LOG_BLE(
"HCI VENDOR 0x%04X\n", opcode);
756 #ifdef HAVE_INAPP_BLE_PAIRING
757 static void end_pairing_ux(
uint8_t pairing_ok)
759 bolos_ux_params_t ux_params;
763 ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_CANCEL;
764 ux_params.u.pairing_status.pairing_ok = pairing_ok;
765 ux_params.len =
sizeof(ux_params.u.pairing_status);
766 G_io_asynch_ux_callback.asynchmodal_end_callback = NULL;
771 static void ask_user_pairing_numeric_comparison(uint32_t code)
773 bolos_ux_params_t ux_params;
775 ux_params.u.pairing_request.type = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST_NUMCOMP;
776 ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST;
777 ux_params.len =
sizeof(ux_params.u.pairing_request);
779 ux_params.u.pairing_request.pairing_info_len = 6;
780 SPRINTF(ux_params.u.pairing_request.pairing_info,
"%06d", (
unsigned int) code);
781 #if defined(TARGET_STAX) || defined(TARGET_FLEX)
782 G_io_asynch_ux_callback.asynchmodal_end_callback = NULL;
784 G_io_asynch_ux_callback.asynchmodal_end_callback = rsp_user_pairing_numeric_comparison;
789 static void rsp_user_pairing_numeric_comparison(
unsigned int status)
791 if (status == BOLOS_UX_OK) {
792 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_CONFIRM_CODE_YES);
796 else if (status == BOLOS_UX_IGNORE) {
802 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_CONFIRM_CODE_NO);
808 static void ask_user_pairing_passkey(
void)
810 bolos_ux_params_t ux_params;
812 ux_params.u.pairing_request.type = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST_PASSKEY;
813 ux_params.ux_id = BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST;
814 ux_params.len =
sizeof(ux_params.u.pairing_request);
816 ledger_ble_data.
pairing_code = cx_rng_u32_range_func(0, 1000000, cx_rng_u32);
817 ux_params.u.pairing_request.pairing_info_len = 6;
818 SPRINTF(ux_params.u.pairing_request.pairing_info,
"%06d", ledger_ble_data.
pairing_code);
819 #if defined(TARGET_STAX) || defined(TARGET_FLEX)
820 G_io_asynch_ux_callback.asynchmodal_end_callback = NULL;
822 G_io_asynch_ux_callback.asynchmodal_end_callback = rsp_user_pairing_passkey;
827 static void rsp_user_pairing_passkey(
unsigned int status)
829 if (status == BOLOS_UX_OK) {
830 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_ACCEPT_PASSKEY);
831 ledger_ble_data.
pairing_code = cx_rng_u32_range_func(0, 1000000, cx_rng_u32);
835 else if (status == BOLOS_UX_IGNORE) {
839 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_CANCEL_PASSKEY);
850 uint16_t att_handle = U2LE(buffer, 0);
852 uint16_t att_data_length = U2LE(buffer, 4);
855 && (att_data_length == 2) && (offset == 0)) {
857 if (U2LE(buffer, 6) != 0) {
858 LOG_BLE(
"REGISTERED FOR NOTIFICATIONS\n");
860 if (!ledger_protocol_data.mtu_negotiated) {
865 LOG_BLE(
"NOT REGISTERED FOR NOTIFICATIONS\n");
871 && (att_data_length)) {
872 LOG_BLE(
"WRITE CMD %d\n", length - 4);
873 LEDGER_PROTOCOL_rx(&ledger_protocol_data, &buffer[4], length - 4);
875 if (ledger_protocol_data.rx_apdu_status == APDU_STATUS_COMPLETE) {
876 check_transfer_mode(G_io_app.transfer_mode);
878 if (U2BE(ledger_ble_data.
resp, 0) != SWO_SUCCESS) {
879 LOG_BLE(
"Transfer failed 0x%04x\n", U2BE(ledger_ble_data.
resp, 0));
880 G_io_app.transfer_mode = 0;
881 check_transfer_mode(G_io_app.transfer_mode);
882 copy_apdu_to_app(
true);
886 &ledger_protocol_data, ledger_ble_data.
resp, ledger_ble_data.
resp_length);
892 copy_apdu_to_app(
true);
895 else if (ledger_protocol_data.tx_chunk_length >= 2) {
896 G_io_app.ble_xfer_timeout = 2000;
898 G_io_app.apdu_state = APDU_BLE;
902 LOG_BLE(
"ATT MODIFIED %04X %d bytes at offset %d\n", att_handle, att_data_length, offset);
906 static void write_permit_request(
const uint8_t *buffer,
uint16_t length)
912 uint16_t att_handle = U2LE(buffer, 0);
913 uint8_t data_length = buffer[2];
920 LEDGER_PROTOCOL_rx(&ledger_protocol_data, &buffer[1], length - 1);
924 HCI_SUCCESS_ERR_CODE,
927 if (ledger_protocol_data.rx_apdu_status == APDU_STATUS_COMPLETE) {
928 copy_apdu_to_app(
true);
932 LOG_BLE(
"ATT WRITE %04X %d bytes\n", att_handle, data_length);
933 ledger_protocol_data.tx_chunk_length = 0;
937 HCI_SUCCESS_ERR_CODE,
943 static void advertising_enable(
uint8_t enable)
949 buffer[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
951 aci_gap_set_discoverable(ADV_IND,
964 aci_gap_set_non_discoverable();
968 static void start_advertising(
void)
970 if (G_io_app.name_changed) {
971 G_io_app.name_changed = 0;
980 ledger_ble_data.
adv_enable = !os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
981 configure_advertising_mngr(0);
984 static void notify_chunk(
void)
986 if (ledger_protocol_data.tx_chunk_length >= 2) {
990 ledger_protocol_data.tx_chunk_length - 2,
991 &ledger_protocol_data.tx_chunk[2]);
995 static void check_transfer_mode(
uint8_t enable)
998 LOG_BLE(
"LEDGER_BLE_set_transfer_mode %d\n", enable);
1003 U2BE_ENCODE(ledger_ble_data.
resp, 0, SWO_SUCCESS);
1012 G_io_app.enabling_advertising = 0;
1013 G_io_app.disabling_advertising = 0;
1016 memset(&ledger_ble_data, 0,
sizeof(ledger_ble_data));
1020 memset(&ledger_ble_data, 0,
sizeof(ledger_ble_data));
1028 memset(&ledger_protocol_data, 0,
sizeof(ledger_protocol_data));
1029 ledger_protocol_data.rx_apdu_buffer = ledger_ble_data.
apdu_buffer;
1030 ledger_protocol_data.rx_apdu_buffer_max_length =
sizeof(ledger_ble_data.
apdu_buffer);
1031 #ifdef HAVE_LOCAL_APDU_BUFFER
1032 ledger_protocol_data.rx_dst_buffer = NULL;
1034 ledger_protocol_data.rx_dst_buffer = G_io_apdu_buffer;
1036 LEDGER_PROTOCOL_init(&ledger_protocol_data);
1038 init_mngr(0, NULL, 0);
1043 ledger_protocol_data.rx_dst_buffer = buffer;
1044 ledger_protocol_data.rx_apdu_buffer_max_length
1051 G_io_app.apdu_state = APDU_IDLE;
1053 ledger_ble_data.
resp[0] = packet[0];
1054 ledger_ble_data.
resp[1] = packet[1];
1055 if (ledger_protocol_data.rx_apdu_length) {
1056 LEDGER_PROTOCOL_tx(&ledger_protocol_data, packet, packet_length);
1061 if ((ledger_ble_data.
resp_length != 0) && (U2BE(ledger_ble_data.
resp, 0) != SWO_SUCCESS)) {
1063 &ledger_protocol_data, ledger_ble_data.
resp, ledger_ble_data.
resp_length);
1066 LEDGER_PROTOCOL_tx(&ledger_protocol_data, packet, packet_length);
1078 if (spi_buffer[3] == HCI_EVENT_PKT_TYPE) {
1079 switch (spi_buffer[4]) {
1080 case HCI_DISCONNECTION_COMPLETE_EVT_CODE:
1081 LOG_BLE(
"HCI DISCONNECTION COMPLETE code %02X\n", spi_buffer[9]);
1086 G_io_app.transfer_mode = 0;
1087 #ifdef HAVE_INAPP_BLE_PAIRING
1088 end_pairing_ux(BOLOS_UX_ASYNCHMODAL_PAIRING_STATUS_FAILED);
1090 if (spi_buffer[9] != 0x28) {
1091 start_advertising();
1100 case HCI_ENCRYPTION_CHANGE_EVT_CODE:
1102 if (spi_buffer[9]) {
1107 LOG_BLE(
"Link not encrypted\n");
1112 LOG_BLE(
"HCI ENCRYPTION CHANGE EVT %d on connection handle \n",
1114 U2LE(spi_buffer, 7));
1118 case HCI_COMMAND_COMPLETE_EVT_CODE:
1119 hci_evt_cmd_complete(&spi_buffer[6], spi_buffer[5]);
1122 case HCI_COMMAND_STATUS_EVT_CODE:
1123 LOG_BLE(
"HCI COMMAND_STATUS\n");
1126 case HCI_ENCRYPTION_KEY_REFRESH_COMPLETE_EVT_CODE:
1127 LOG_BLE(
"HCI KEY_REFRESH_COMPLETE\n");
1130 case HCI_LE_META_EVT_CODE:
1131 hci_evt_le_meta_evt(&spi_buffer[6], spi_buffer[5]);
1134 case HCI_VENDOR_SPECIFIC_DEBUG_EVT_CODE:
1135 hci_evt_vendor(&spi_buffer[6], spi_buffer[5]);
1146 if ((G_io_app.name_changed) && (G_io_app.ble_ready) && (!enable)
1148 G_io_app.name_changed = 0;
1150 else if (G_io_app.ble_ready) {
1152 G_io_app.enabling_advertising = 1;
1153 G_io_app.disabling_advertising = 0;
1156 G_io_app.enabling_advertising = 0;
1157 G_io_app.disabling_advertising = 1;
1159 advertising_enable(enable);
1165 if (G_io_app.ble_ready) {
1172 aci_gap_clear_security_db();
1180 rsp_user_pairing_numeric_comparison(status);
1183 rsp_user_pairing_passkey(status);
1191 uint16_t opcode = ((p_cmd->ocf) & 0x03ff) | ((p_cmd->ogf) << 10);
1194 tag_buffer[0] = SEPROXYHAL_TAG_BLE_SEND;
1195 tag_buffer[1] = (p_cmd->clen + 2) >> 8;
1196 tag_buffer[2] = (p_cmd->clen + 2);
1197 tag_buffer[3] = opcode >> 8;
1198 tag_buffer[4] = opcode;
1199 io_seproxyhal_spi_send(tag_buffer, 5);
1200 io_seproxyhal_spi_send(p_cmd->cparam, p_cmd->clen);
1204 void BLE_power(
unsigned char powered,
const char *discovered_name)
1206 UNUSED(discovered_name);
1208 LOG_BLE(
"BLE_power %d\n", powered);
Random Number Generation.
#define BLE_ADVERTISING_INTERVAL_MIN
@ BLE_CONFIG_ADV_STEP_START
@ BLE_CONFIG_ADV_STEP_SET_ADV_DATAS
@ BLE_CONFIG_ADV_STEP_SET_GAP_DEVICE_NAME
@ BLE_CONFIG_ADV_STEP_SET_SCAN_RSP_DATAS
@ BLE_CONFIG_ADV_STEP_END
@ BLE_CONFIG_ADV_STEP_IDLE
#define BLE_ADVERTISING_INTERVAL_MAX
void LEDGER_BLE_receive(const uint8_t *spi_buffer)
void BLE_power(unsigned char powered, const char *discovered_name)
void LEDGER_BLE_reset_pairings(void)
int hci_send_req(struct hci_request *p_cmd, uint8_t async)
@ BLE_STATE_DISCONNECTING
@ BLE_STATE_CONFIGURE_ADVERTISING
void LEDGER_BLE_enable_advertising(uint8_t enable)
@ BLE_INIT_STEP_SET_IO_CAPABILITIES
@ BLE_INIT_STEP_ADD_NOTIFICATION_CHARACTERISTIC
@ BLE_INIT_STEP_SET_AUTH_REQUIREMENTS
@ BLE_INIT_STEP_CONFIGURE_ADVERTISING
@ BLE_INIT_STEP_ADD_WRITE_CHARACTERISTIC
@ BLE_INIT_STEP_SET_TX_POWER_LEVEL
@ BLE_INIT_STEP_STATIC_ADDRESS
@ BLE_INIT_STEP_ADD_WRITE_COMMAND_CHARACTERISTIC
@ BLE_INIT_STEP_ADD_SERVICE
@ BLE_INIT_STEP_GATT_INIT
void LEDGER_BLE_set_recv_buffer(uint8_t *buffer, uint16_t buffer_length)
#define BLE_SLAVE_CONN_INTERVAL_MIN
void LEDGER_BLE_send(const uint8_t *packet, uint16_t packet_length)
void LEDGER_BLE_accept_pairing(uint8_t status)
void LEDGER_BLE_init(void)
#define BLE_SLAVE_CONN_INTERVAL_MAX
#define LEDGER_BLE_get_mac_address(address)
uint8_t peer_address_random
uint16_t connection_handle
uint16_t supervision_timeout
uint8_t master_clock_accuracy
uint8_t random_address[CONFIG_DATA_RANDOM_ADDRESS_LEN]
uint8_t pairing_in_progress
uint8_t apdu_buffer[IO_APDU_BUFFER_SIZE]
uint8_t wait_write_resp_ack
uint16_t gap_device_name_characteristic_handle
uint8_t transfer_mode_enable
ble_connection_t connection
uint16_t ledger_gatt_notification_characteristic_handle
uint8_t advertising_enabled
uint16_t ledger_gatt_write_characteristic_handle
ble_config_adv_step_t adv_step
uint16_t gap_appearance_characteristic_handle
uint16_t ledger_gatt_service_handle
uint16_t apdu_buffer_length
uint8_t connection_updated
uint16_t ledger_gatt_write_cmd_characteristic_handle
uint8_t notifications_enabled
ble_init_step_t init_step
uint16_t gap_service_handle