Add procedure to compute unique ID at startup.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
019c5929a2
commit
22d4e62952
7 changed files with 42 additions and 26 deletions
|
|
@ -37,14 +37,9 @@ void hash_multi(const uint8_t *input, uint16_t len, uint8_t output[32]) {
|
|||
mbedtls_sha256_context ctx;
|
||||
mbedtls_sha256_init(&ctx);
|
||||
uint16_t iters = 256;
|
||||
#ifndef ENABLE_EMULATION
|
||||
pico_unique_board_id_t unique_id;
|
||||
|
||||
pico_get_unique_board_id(&unique_id);
|
||||
#endif
|
||||
mbedtls_sha256_starts(&ctx, 0);
|
||||
#ifndef ENABLE_EMULATION
|
||||
mbedtls_sha256_update(&ctx, unique_id.id, sizeof(unique_id.id));
|
||||
mbedtls_sha256_update(&ctx, pico_serial.id, sizeof(pico_serial.id));
|
||||
#endif
|
||||
|
||||
while (iters > len) {
|
||||
|
|
|
|||
|
|
@ -263,6 +263,9 @@ void scan_region(bool persistent) {
|
|||
}
|
||||
}
|
||||
void wait_flash_finish();
|
||||
#ifndef ENABLE_EMULATION
|
||||
extern uint16_t usb_vid, usb_pid;
|
||||
#endif
|
||||
void scan_flash() {
|
||||
initialize_flash(false); //soft initialization
|
||||
if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff &&
|
||||
|
|
@ -278,6 +281,12 @@ void scan_flash() {
|
|||
printf("SCAN\n");
|
||||
scan_region(true);
|
||||
scan_region(false);
|
||||
#ifndef ENABLE_EMULATION
|
||||
file_t *ef_vp = search_dynamic_file(EF_VP);
|
||||
if (file_has_data(ef_vp)) {
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t *file_read(const uint8_t *addr) {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@
|
|||
#define EF_SKDFS 0x6045
|
||||
#define EF_META 0xE010
|
||||
|
||||
#ifndef ENABLE_EMULATION
|
||||
#define EF_VP 0xE020
|
||||
#endif
|
||||
|
||||
#define MAX_DEPTH 4
|
||||
|
||||
typedef PACK(struct file {
|
||||
|
|
|
|||
13
src/main.c
13
src/main.c
|
|
@ -170,7 +170,7 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp)
|
|||
(void)tzp;
|
||||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
|
||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
||||
// until 00:00:00 January 1, 1970
|
||||
// until 00:00:00 January 1, 1970
|
||||
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
|
||||
|
||||
SYSTEMTIME system_time;
|
||||
|
|
@ -313,7 +313,18 @@ void execute_tasks() {
|
|||
led_blinking_task();
|
||||
}
|
||||
|
||||
char pico_serial_str[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1];
|
||||
pico_unique_board_id_t pico_serial;
|
||||
#ifdef ENABLE_EMULATION
|
||||
#define pico_get_unique_board_id(a) memset(a, 0, sizeof(*(a)))
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
pico_get_unique_board_id(&pico_serial);
|
||||
memset(pico_serial_str, 0, sizeof(pico_serial_str));
|
||||
for (int i = 0; i < sizeof(pico_serial); i++) {
|
||||
snprintf(&pico_serial_str[2 * i], 3, "%02X", pico_serial.id[i]);
|
||||
}
|
||||
#ifndef ENABLE_EMULATION
|
||||
usb_init();
|
||||
|
||||
|
|
|
|||
|
|
@ -156,4 +156,12 @@ extern uint32_t button_timeout;
|
|||
#define CCID_WRONG_PADDING -1011
|
||||
#define CCID_VERIFICATION_FAILED -1012
|
||||
|
||||
#if defined(ENABLE_EMULATION)
|
||||
#define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8
|
||||
typedef struct { uint8_t id[PICO_UNIQUE_BOARD_ID_SIZE_BYTES]; } pico_unique_board_id_t;
|
||||
#endif
|
||||
|
||||
extern pico_unique_board_id_t pico_serial;
|
||||
extern char pico_serial_str[];
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -101,7 +101,6 @@ struct ccid_header {
|
|||
|
||||
uint8_t ccid_status = 1;
|
||||
static uint8_t itf_num;
|
||||
extern tusb_desc_endpoint_t const desc_ep3;
|
||||
|
||||
void ccid_write_offset(uint8_t itf, uint16_t size, uint16_t offset) {
|
||||
if (*usb_get_tx(itf) + offset != 0x81) {
|
||||
|
|
@ -284,38 +283,31 @@ uint8_t *driver_prepare_response_ccid(uint8_t itf) {
|
|||
#define MAX_USB_POWER 1
|
||||
|
||||
static void ccid_init_cb(void) {
|
||||
TU_LOG1("-------- CCID INIT\n");
|
||||
vendord_init();
|
||||
}
|
||||
|
||||
static void ccid_reset_cb(uint8_t rhport) {
|
||||
TU_LOG1("-------- CCID RESET\n");
|
||||
itf_num = 0;
|
||||
vendord_reset(rhport);
|
||||
}
|
||||
|
||||
static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
|
||||
uint8_t *itf_vendor = (uint8_t *) malloc(sizeof(uint8_t) * max_len);
|
||||
//TU_LOG1("-------- CCID OPEN\n");
|
||||
TU_VERIFY(
|
||||
itf_desc->bInterfaceClass == TUSB_CLASS_SMART_CARD && itf_desc->bInterfaceSubClass == 0 && itf_desc->bInterfaceProtocol == 0,
|
||||
0);
|
||||
TU_VERIFY( itf_desc->bInterfaceClass == TUSB_CLASS_SMART_CARD && itf_desc->bInterfaceSubClass == 0 && itf_desc->bInterfaceProtocol == 0, 0);
|
||||
|
||||
//vendord_open expects a CLASS_VENDOR interface class
|
||||
uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) + 3 * sizeof(tusb_desc_endpoint_t);
|
||||
memcpy(itf_vendor, itf_desc, sizeof(uint8_t) * max_len);
|
||||
((tusb_desc_interface_t *) itf_vendor)->bInterfaceClass = TUSB_CLASS_VENDOR_SPECIFIC;
|
||||
((tusb_desc_interface_t *) itf_vendor)->bNumEndpoints -= 1;
|
||||
vendord_open(rhport,
|
||||
(tusb_desc_interface_t *) itf_vendor,
|
||||
max_len - sizeof(tusb_desc_endpoint_t));
|
||||
TU_ASSERT(usbd_edpt_open(rhport, &desc_ep3), 0);
|
||||
vendord_open(rhport, (tusb_desc_interface_t *) itf_vendor, max_len - sizeof(tusb_desc_endpoint_t));
|
||||
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *)((uint8_t *)itf_desc + drv_len - sizeof(tusb_desc_endpoint_t));
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
|
||||
free(itf_vendor);
|
||||
|
||||
uint8_t msg[] = { 0x50, 0x03 };
|
||||
usbd_edpt_xfer(rhport, desc_ep3.bEndpointAddress, msg, sizeof(msg));
|
||||
usbd_edpt_xfer(rhport, desc_ep->bEndpointAddress, msg, sizeof(msg));
|
||||
|
||||
uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) +
|
||||
3 * sizeof(tusb_desc_endpoint_t);
|
||||
TU_VERIFY(max_len >= drv_len, 0);
|
||||
|
||||
itf_num = itf_desc->bInterfaceNumber;
|
||||
|
|
|
|||
|
|
@ -427,15 +427,12 @@ int driver_process_usb_packet_hid(uint16_t read) {
|
|||
memset(ctap_resp, 0, 64);
|
||||
ctap_resp->cid = ctap_req->cid;
|
||||
ctap_resp->init.cmd = ctap_req->init.cmd;
|
||||
#ifndef ENABLE_EMULATION
|
||||
pico_unique_board_id_t rpiid;
|
||||
pico_get_unique_board_id(&rpiid);
|
||||
#else
|
||||
#ifdef ENABLE_EMULATION
|
||||
struct {
|
||||
uint8_t id[8];
|
||||
} rpiid = { 0 };
|
||||
#endif
|
||||
memcpy(ctap_resp->init.data, rpiid.id, sizeof(rpiid.id));
|
||||
memcpy(ctap_resp->init.data, pico_serial.id, sizeof(pico_serial.id));
|
||||
ctap_resp->init.bcntl = 16;
|
||||
hid_write(64);
|
||||
msg_packet.len = msg_packet.current_len = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue