Introducing EF_PHY to store PHY (VIDPID and LED no.).

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-04-17 11:40:01 +02:00
parent 22d4e62952
commit cf1e076453
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
4 changed files with 40 additions and 16 deletions

View file

@ -41,6 +41,11 @@ extern uint8_t flash_read_uint8(uintptr_t addr);
extern uint8_t *flash_read(uintptr_t addr);
extern void low_flash_available();
#ifndef ENABLE_EMULATION
file_t sef_phy = {.fid = EF_PHY, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH | FILE_PERSISTENT, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = {0xff}};
file_t *ef_phy = &sef_phy;
#endif
//puts FCI in the RAPDU
void process_fci(const file_t *pe, int fmd) {
res_APDU_size = 0;
@ -144,7 +149,11 @@ file_t *search_by_name(uint8_t *name, uint16_t namelen) {
}
file_t *search_by_fid(const uint16_t fid, const file_t *parent, const uint8_t sp) {
#ifndef ENABLE_EMULATION
if (fid == EF_PHY) {
return ef_phy;
}
#endif
for (file_t *p = file_entries; p != file_last; p++) {
if (p->fid != 0x0000 && p->fid == fid) {
if (!parent || (parent && is_parent(p, parent))) {
@ -263,9 +272,6 @@ 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 &&
@ -281,12 +287,6 @@ 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) {

View file

@ -67,9 +67,14 @@
#define EF_SKDFS 0x6045
#define EF_META 0xE010
#ifndef ENABLE_EMULATION
#define EF_VP 0xE020
#endif
#define EF_PHY 0xE020
#define PHY_VID 0x0
#define PHY_PID 0x2
#define PHY_LED_GPIO 0x4
#define PHY_LED_MODE 0x5
#define PHY_MAX_SIZE 6
#define MAX_DEPTH 4
@ -129,4 +134,8 @@ extern int meta_delete(uint16_t fid);
extern int meta_add(uint16_t fid, const uint8_t *data, uint16_t len);
extern int delete_file(file_t *ef);
#ifndef ENABLE_EMULATION
extern file_t *ef_phy;
#endif
#endif

View file

@ -21,13 +21,16 @@
#ifndef ENABLE_EMULATION
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "tusb.h"
#include "bsp/board.h"
#endif
#include "pico_keys.h"
#include "usb.h"
#include "apdu.h"
#ifndef ENABLE_EMULATION
#include "tusb.h"
#endif
// For memcpy
#include <string.h>
#include <stdlib.h>
@ -158,8 +161,20 @@ queue_t usb_to_card_q;
queue_t card_to_usb_q;
#endif
#ifndef ENABLE_EMULATION
extern tusb_desc_device_t desc_device;
#endif
void usb_init() {
#ifndef ENABLE_EMULATION
uint16_t usb_vid = USB_VID, usb_pid = USB_PID;
if (file_has_data(ef_phy) && file_get_size(ef_phy) >= 4) {
uint8_t *data = file_get_data(ef_phy);
usb_vid = (data[PHY_VID] << 8) | data[PHY_VID+1];
usb_pid = (data[PHY_PID] << 8) | data[PHY_PID+1];
}
desc_device.idVendor = usb_vid;
desc_device.idProduct = usb_pid;
queue_init(&card_to_usb_q, sizeof(uint32_t), 64);
queue_init(&usb_to_card_q, sizeof(uint32_t), 64);
#endif

View file

@ -20,6 +20,7 @@
#include "pico/unique_id.h"
#include "pico_keys_version.h"
#include "usb.h"
#include "pico_keys.h"
#ifndef USB_VID
#define USB_VID 0xFEFF
@ -34,11 +35,10 @@
#define MAX_USB_POWER 1
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
tusb_desc_device_t const desc_device = {
tusb_desc_device_t desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = (USB_BCD),