/******************************************************************************* * Ledger Nano S - Secure firmware * (c) 2022 Ledger * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ********************************************************************************/ #ifndef SEPROXYHAL_PROTOCOL_H #define SEPROXYHAL_PROTOCOL_H #define BLE_CMD_APDU 0x05 #define BLE_CHUNK_LENGTH 20 #define M24SR_CHUNK_LENGTH 0xF6 // EVENTS #define SEPROXYHAL_TAG_SESSION_START_EVENT 0x01 // // // // // // #define SEPROXYHAL_TAG_SESSION_START_EVENT_REQBLE 0x01 #define SEPROXYHAL_TAG_SESSION_START_EVENT_RECOVERY 0x02 #define SEPROXYHAL_TAG_SESSION_START_EVENT_FLASHBACK 0x04 #define SEPROXYHAL_TAG_SESSION_START_EVENT_BOOTMENU 0x08 #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_USB 0x00000001UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_BLE 0x00000002UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_TOUCH 0x00000004UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_BUTTON_COUNT 0x000000F0UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_BUTTON_COUNT_POS 4 #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_SCREEN_MASK 0x00000F00UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_NO_SCREEN 0x00000000UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_SCREEN_BIG 0x00000100UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_SCREEN_SML 0x00000200UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_SCREEN_SSD1312 0x00000300UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_LEDRGB 0x00001000UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_BATTERY 0x00000008UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_ISET_MASK 0xF0000000UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_ISET_BASIC 0x00000000UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_ISET_MCUSEC 0x10000000UL #define SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_ISET_MCUBL 0x20000000UL #define SEPROXYHAL_TAG_BLE_SECURITY_DB_EVENT 0x02 #define SEPROXYHAL_TAG_BLE_SECURITY_DB_LOADED_EVENT 0x00 // the security db chunk has ben loaded into MCU's RAM, the SE can proceed with the next one #define SEPROXYHAL_TAG_BLE_SECURITY_DB_DUMP_EVENT 0x01 // content of the security db at given offset #define SEPROXYHAL_TAG_BLE_WRITE_REQUEST_EVENT 0x03 #define SEPROXYHAL_TAG_BLE_READ_REQUEST_EVENT 0x04 #define SEPROXYHAL_TAG_BUTTON_PUSH_EVENT 0x05 #define SEPROXYHAL_TAG_BUTTON_PUSH_ID_MASK 0xFE // up to 7 physical buttons (bit is 1 when pressed, and 0 when released) #define SEPROXYHAL_TAG_BUTTON_PUSH_INTERVAL_MS 100 // an event generated every x ms #define SEPROXYHAL_TAG_NFC_FIELD_DETECTION_EVENT 0x06 #define SEPROXYHAL_TAG_NFC_APDU_RECEIVED_EVENT 0x07 #define SEPROXYHAL_TAG_BATTERY_NOTIFICATION_EVENT 0x08 #define SEPROXYHAL_TAG_M24SR_GPO_CHANGE_EVENT 0x09 #define SEPROXYHAL_TAG_M24SR_RESPONSE_APDU_EVENT 0x0A #define SEPROXYHAL_TAG_BLE_NOTIFY_INDICATE_EVENT 0x0B #define SEPROXYHAL_TAG_FINGER_EVENT 0x0C #define SEPROXYHAL_TAG_FINGER_EVENT_TOUCH 0x01 #define SEPROXYHAL_TAG_FINGER_EVENT_RELEASE 0x02 #define SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT 0x0D #define SEPROXYHAL_TAG_TICKER_EVENT 0x0E // #define SEPROXYHAL_TAG_USB_EVENT 0x0F // #define SEPROXYHAL_TAG_USB_EVENT_RESET 0x01 #define SEPROXYHAL_TAG_USB_EVENT_SOF 0x02 #define SEPROXYHAL_TAG_USB_EVENT_SUSPENDED 0x04 #define SEPROXYHAL_TAG_USB_EVENT_RESUMED 0x08 #define SEPROXYHAL_TAG_USB_EP_XFER_EVENT 0x10 // #define SEPROXYHAL_TAG_USB_EP_XFER_SETUP 0x01 #define SEPROXYHAL_TAG_USB_EP_XFER_IN 0x02 #define SEPROXYHAL_TAG_USB_EP_XFER_OUT 0x04 #define SEPROXYHAL_TAG_BLE_CONNECTION_EVENT 0x11 // #define SEPROXYHAL_TAG_UNSEC_CHUNK_EVENT 0x12 #define SEPROXYHAL_TAG_ACK_LINK_SPEED 0x13 // #define SEPROXYHAL_TAG_BLUENRG_RECV_EVENT 0x14 // #define SEPROXYHAL_TAG_STATUS_EVENT 0x15 // #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_CHARGING 0x00000001 #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_ON 0x00000002 #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_BLE_ON 0x00000004 #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED 0x00000008 #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_CHARGING_ISSUE 0x00000010 #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_TEMPERATURE_ISSUE 0x00000020 #define SEPROXYHAL_TAG_STATUS_EVENT_FLAG_BATTERY_ISSUE 0x00000040 #define SEPROXYHAL_TAG_CAPDU_EVENT 0x16 // raw command apdu transport #define SEPROXYHAL_TAG_I2C_EVENT 0x17 // #define SEPROXYHAL_TAG_I2C_EVENT_KIND_READ 0x01 #define SEPROXYHAL_TAG_I2C_EVENT_KIND_WRITE 0x02 #define SEPROXYHAL_TAG_BLE_RECV_EVENT 0x18 // #define SEPROXYHAL_TAG_BOOTLOADER_RAPDU_EVENT 0x19 // #define SEPROXYHAL_TAG_UX_EVENT 0x1A // #define SEPH_PROTOCOL_EVT_POWER_BUTTON_EVENT 0x1B // // COMMANDS #ifdef HAVE_SEPROXYHAL_MCU #define SEPROXYHAL_TAG_MCU 0x31 // #define SEPROXYHAL_TAG_MCU_TYPE_BOOTLOADER 0x00 #define SEPROXYHAL_TAG_MCU_TYPE_LOCK 0x01 #ifdef HAVE_MCU_PROTECT #define SEPROXYHAL_TAG_MCU_TYPE_PROTECT 0x02 // for instance ask RDP2 to be engaged #endif // HAVE_MCU_PROTECT #define SEPROXYHAL_TAG_MCU_TYPE_BD_ADDR 0x03 #define SEPROXYHAL_TAG_MCU_BOOTLOADER SEPROXYHAL_TAG_MCU #endif // HAVE_SEPROXYHAL_MCU #define SEPROXYHAL_TAG_UNSEC_CHUNK_READ 0x32 // // available if SEPROXYHAL_TAG_SESSION_START_EVENT_FEATURE_ISET_MCUSEC #define SEPROXYHAL_TAG_UNSEC_CHUNK_READ_EXT 0x33 // #define SEPROXYHAL_TAG_BLE_SEND 0x38 // #define SEPROXYHAL_TAG_SET_SCREEN_CONFIG 0x3E // #define SEPROXYHAL_TAG_SET_LINK_PROP 0x3F // #define SEPROXYHAL_TAG_BLUENRG_SEND 0x40 // #define SEPROXYHAL_TAG_BLE_DEFINE_GENERIC_SETTING 0x41 #define SEPROXYHAL_TAG_BLE_DEFINE_SERVICE_SETTING 0x42 #define SEPROXYHAL_TAG_NFC_DEFINE_SERVICE_SETTING 0x43 #define SEPROXYHAL_TAG_BLE_RADIO_POWER 0x44 // #define SEPROXYHAL_TAG_BLE_RADIO_POWER_ACTION_ON 0x02 #define SEPROXYHAL_TAG_BLE_RADIO_POWER_ACTION_DBWIPE 0x04 #define SEPROXYHAL_TAG_BLE_RADIO_POWER_FACTORY_TEST 0x40 #define SEPROXYHAL_TAG_NFC_RADIO_POWER 0x45 #define SEPROXYHAL_TAG_SE_POWER_OFF 0x46 #ifdef HAVE_NOR_FLASH #define SEPROXYHAL_TAG_SPI_CS 0x47 #endif //#define SEPROXYHAL_TAG_SCREEN_POWER 0x47 #define SEPROXYHAL_TAG_BLE_SECURITY_DB 0x48 // // TODO use a pairing key between the SE and MCU to decrypt/encrypt the content of the pairing DB. #define SEPROXYHAL_TAG_BLE_SECURITY_DB_CMD_READ 0x01 // -noarg- request the content of the security db to be transmitted through SEPROXYHAL_TAG_BLE_SECURITY_DB_EVENT #define SEPROXYHAL_TAG_BLE_SECURITY_DB_CMD_WRITE 0x02 // request to write a chunk of the security db at the given offset #define SEPROXYHAL_TAG_BATTERY_CHARGE 0x49 // <> //#define SEPROXYHAL_TAG_SCREEN_DISPLAY 0x4A // wait for display_event after sent #define SEPROXYHAL_TAG_DEVICE_OFF 0x4B #define SEPROXYHAL_TAG_MORE_TIME 0x4C #define SEPROXYHAL_TAG_M24SR_C_APDU 0x4D #define SEPROXYHAL_TAG_SET_TICKER_INTERVAL 0x4E #define SEPROXYHAL_TAG_USB_CONFIG 0x4F // #define SEPROXYHAL_TAG_USB_CONFIG_CONNECT 0x01 // <> #define SEPROXYHAL_TAG_USB_CONFIG_DISCONNECT 0x02 // <> #define SEPROXYHAL_TAG_USB_CONFIG_ADDR 0x03 // #define SEPROXYHAL_TAG_USB_CONFIG_ENDPOINTS 0x04 // [ ] #define SEPROXYHAL_TAG_USB_CONFIG_TYPE_DISABLED 0x00 #define SEPROXYHAL_TAG_USB_CONFIG_TYPE_CONTROL 0x01 #define SEPROXYHAL_TAG_USB_CONFIG_TYPE_INTERRUPT 0x02 #define SEPROXYHAL_TAG_USB_CONFIG_TYPE_BULK 0x03 #define SEPROXYHAL_TAG_USB_CONFIG_TYPE_ISOCHRONOUS 0x04 #define SEPROXYHAL_TAG_USB_EP_PREPARE 0x50 // #define SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_SETUP 0x10 #define SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_IN 0x20 #define SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_OUT 0x30 #define SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_STALL 0x40 #define SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_UNSTALL 0x80 #define SEPROXYHAL_TAG_SET_LED 0x51 // #define SEPROXYHAL_TAG_REQUEST_STATUS 0x52 // no args, request power levels of all peripherals and current charging state or not if a battery is present. #define SEPROXYHAL_TAG_RAPDU 0x53 // raw response apdu transport #define SEPROXYHAL_TAG_I2C_XFER 0x54 // #define SEPROXYHAL_TAG_UX_CMD 0x5D #define SEPROXYHAL_TAG_UX_CMD_BLE_DISABLE_ADV 0x00 #define SEPROXYHAL_TAG_UX_CMD_BLE_ENABLE_ADV 0x01 #define SEPROXYHAL_TAG_UX_CMD_BLE_RESET_PAIRINGS 0x02 #define SEPROXYHAL_TAG_UX_CMD_REDISPLAY 0x03 #ifdef HAVE_SERIALIZED_NBGL #define SEPROXYHAL_TAG_NBGL_SERIALIZED 0x5C #endif #define SEPROXYHAL_TAG_PRINTF 0x5F // #define SEPROXYHAL_TAG_DBG_SCREEN_DISPLAY_STATUS 0x5E // #ifdef HAVE_PIEZO_SOUND #define SEPROXYHAL_TAG_PLAY_TUNE 0x56 #endif // HAVE_PIEZO_SOUND #ifdef HAVE_SHIP_MODE #define SEPH_PROTOCOL_CMD_SET_SHIP_MODE 0x57 #endif // HAVE_SHIP_MODE // STATUS #define SEPROXYHAL_TAG_STATUS_MASK 0x60 #define SEPROXYHAL_TAG_GENERAL_STATUS 0x60 #define SEPROXYHAL_TAG_GENERAL_STATUS_LAST_COMMAND 0x0000 //#define SEPROXYHAL_TAG_GENERAL_STATUS_MORE_COMMAND 0x0001 // it's a status, but it shall be a command instead to avoid perturbating the simple seproxyhal bus logic //#define SEPROXYHAL_TAG_GENERAL_STATUS_ERROR 0x0002 // shall be a command instead #define SEPROXYHAL_TAG_PAIRING_STATUS 0x61 #define SEPROXYHAL_TAG_BLE_READ_RESPONSE_STATUS 0x62 #define SEPROXYHAL_TAG_NFC_READ_RESPONSE_STATUS 0x63 #define SEPROXYHAL_TAG_BLE_NOTIFY_INDICATE_STATUS 0x64 #define SEPROXYHAL_TAG_SCREEN_DISPLAY_STATUS 0x65 // #define SEPROXYHAL_TAG_PRINTF_STATUS 0x66 #define SEPROXYHAL_TAG_SET_LINK_SPEED 0x67 // #define SEPROXYHAL_TAG_SCREEN_ANIMATION_STATUS 0x68 // // replied with a display processed event when done #define SEPROXYHAL_TAG_SCREEN_ANIMATION_STATUS_VERTICAL_SPLIT_SLIDE 0x00 // param[0:1](BE) = split Y coordinate, param[2:3](BE) = animation duration in ms #define SEPROXYHAL_TAG_BOOTLOADER_CAPDU_STATUS 0x6A // #endif