mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
Remove carriage return \r for better debug.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -121,9 +121,9 @@ uint16_t apdu_process(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//printf("apdu.nc %ld, apdu.ne %ld\r\n",apdu.nc,apdu.ne);
|
//printf("apdu.nc %ld, apdu.ne %ld\n",apdu.nc,apdu.ne);
|
||||||
if (apdu.header[1] == 0xc0) {
|
if (apdu.header[1] == 0xc0) {
|
||||||
//printf("apdu.ne %u, apdu.rlen %d, bk %x\r\n",apdu.ne,apdu.rlen,rdata_bk);
|
//printf("apdu.ne %u, apdu.rlen %d, bk %x\n",apdu.ne,apdu.rlen,rdata_bk);
|
||||||
timeout_stop();
|
timeout_stop();
|
||||||
*(uint16_t *) rdata_gr = rdata_bk;
|
*(uint16_t *) rdata_gr = rdata_bk;
|
||||||
if (apdu.rlen <= apdu.ne) {
|
if (apdu.rlen <= apdu.ne) {
|
||||||
@@ -215,7 +215,7 @@ done: ;
|
|||||||
uint32_t flag = EV_EXEC_FINISHED;
|
uint32_t flag = EV_EXEC_FINISHED;
|
||||||
queue_add_blocking(&card_to_usb_q, &flag);
|
queue_add_blocking(&card_to_usb_q, &flag);
|
||||||
}
|
}
|
||||||
//printf("EXIT !!!!!!\r\n");
|
//printf("EXIT !!!!!!\n");
|
||||||
if (current_app && current_app->unload) {
|
if (current_app && current_app->unload) {
|
||||||
current_app->unload();
|
current_app->unload();
|
||||||
current_app = NULL;
|
current_app = NULL;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ typedef struct cmd {
|
|||||||
|
|
||||||
#if defined(DEBUG_APDU) && DEBUG_APDU == 1
|
#if defined(DEBUG_APDU) && DEBUG_APDU == 1
|
||||||
#define DEBUG_PAYLOAD(_p, _s) { \
|
#define DEBUG_PAYLOAD(_p, _s) { \
|
||||||
printf("Payload %s (%d bytes):\r\n", #_p, (int) (_s)); \
|
printf("Payload %s (%d bytes):\n", #_p, (int) (_s)); \
|
||||||
for (int _i = 0; _i < _s; _i += 16) { \
|
for (int _i = 0; _i < _s; _i += 16) { \
|
||||||
printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \
|
printf("%" PRIxPTR "h : ", (uintptr_t) (_i + _p)); \
|
||||||
for (int _j = 0; _j < 16; _j++) { \
|
for (int _j = 0; _j < 16; _j++) { \
|
||||||
@@ -56,12 +56,12 @@ typedef struct cmd {
|
|||||||
else printf(" "); \
|
else printf(" "); \
|
||||||
if (_j == 7) printf(" "); \
|
if (_j == 7) printf(" "); \
|
||||||
} \
|
} \
|
||||||
printf("\r\n"); \
|
printf("\n"); \
|
||||||
} printf("\r\n"); \
|
} printf("\n"); \
|
||||||
}
|
}
|
||||||
#define DEBUG_DATA(_p, _s) \
|
#define DEBUG_DATA(_p, _s) \
|
||||||
{ \
|
{ \
|
||||||
printf("Data %s (%d bytes):\r\n", #_p, (int) (_s)); \
|
printf("Data %s (%d bytes):\n", #_p, (int) (_s)); \
|
||||||
char *tmp = (char *) calloc(1, 2 * _s + 1); \
|
char *tmp = (char *) calloc(1, 2 * _s + 1); \
|
||||||
for (int _i = 0; _i < _s; _i++) \
|
for (int _i = 0; _i < _s; _i++) \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ void scan_region(bool persistent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t fid = flash_read_uint16(base + sizeof(uintptr_t) + sizeof(uintptr_t));
|
uint16_t fid = flash_read_uint16(base + sizeof(uintptr_t) + sizeof(uintptr_t));
|
||||||
printf("[%x] scan fid %x, len %d\r\n", (unsigned int) base, fid,
|
printf("[%x] scan fid %x, len %d\n", (unsigned int) base, fid,
|
||||||
flash_read_uint16(base + sizeof(uintptr_t) + sizeof(uintptr_t) + sizeof(uint16_t)));
|
flash_read_uint16(base + sizeof(uintptr_t) + sizeof(uintptr_t) + sizeof(uint16_t)));
|
||||||
file_t *file = (file_t *) search_by_fid(fid, NULL, SPECIFY_EF);
|
file_t *file = (file_t *) search_by_fid(fid, NULL, SPECIFY_EF);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -267,7 +267,7 @@ void scan_flash() {
|
|||||||
initialize_flash(false); //soft initialization
|
initialize_flash(false); //soft initialization
|
||||||
if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff &&
|
if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff &&
|
||||||
*(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t)) == 0xffffffff) {
|
*(uintptr_t *) flash_read(end_rom_pool + sizeof(uintptr_t)) == 0xffffffff) {
|
||||||
printf("First initialization (or corrupted!)\r\n");
|
printf("First initialization (or corrupted!)\n");
|
||||||
uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)];
|
uint8_t empty[sizeof(uintptr_t) * 2 + sizeof(uint32_t)];
|
||||||
memset(empty, 0, sizeof(empty));
|
memset(empty, 0, sizeof(empty));
|
||||||
flash_program_block(end_data_pool, empty, sizeof(empty));
|
flash_program_block(end_data_pool, empty, sizeof(empty));
|
||||||
@@ -275,7 +275,7 @@ void scan_flash() {
|
|||||||
//low_flash_available();
|
//low_flash_available();
|
||||||
//wait_flash_finish();
|
//wait_flash_finish();
|
||||||
}
|
}
|
||||||
printf("SCAN\r\n");
|
printf("SCAN\n");
|
||||||
scan_region(true);
|
scan_region(true);
|
||||||
scan_region(false);
|
scan_region(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ uintptr_t allocate_free_addr(uint16_t size, bool persistent) {
|
|||||||
uintptr_t addr_alg = base & -FLASH_SECTOR_SIZE; //start address of sector
|
uintptr_t addr_alg = base & -FLASH_SECTOR_SIZE; //start address of sector
|
||||||
uintptr_t potential_addr = base - real_size;
|
uintptr_t potential_addr = base - real_size;
|
||||||
next_base = flash_read_uintptr(base);
|
next_base = flash_read_uintptr(base);
|
||||||
//printf("nb %x %x %x %x\r\n",base,next_base,addr_alg,potential_addr);
|
//printf("nb %x %x %x %x\n",base,next_base,addr_alg,potential_addr);
|
||||||
//printf("fid %x\r\n",flash_read_uint16(next_base+sizeof(uintptr_t)));
|
//printf("fid %x\n",flash_read_uint16(next_base+sizeof(uintptr_t)));
|
||||||
if (next_base == 0x0) { //we are at the end
|
if (next_base == 0x0) { //we are at the end
|
||||||
//now we check if we fit in the current sector
|
//now we check if we fit in the current sector
|
||||||
if (addr_alg <= potential_addr) { //it fits in the current sector
|
if (addr_alg <= potential_addr) { //it fits in the current sector
|
||||||
@@ -121,7 +121,7 @@ int flash_clear_file(file_t *file) {
|
|||||||
(uintptr_t)(file->data - sizeof(uintptr_t) - sizeof(uint16_t) - sizeof(uintptr_t));
|
(uintptr_t)(file->data - sizeof(uintptr_t) - sizeof(uint16_t) - sizeof(uintptr_t));
|
||||||
uintptr_t prev_addr = flash_read_uintptr(base_addr + sizeof(uintptr_t));
|
uintptr_t prev_addr = flash_read_uintptr(base_addr + sizeof(uintptr_t));
|
||||||
uintptr_t next_addr = flash_read_uintptr(base_addr);
|
uintptr_t next_addr = flash_read_uintptr(base_addr);
|
||||||
//printf("nc %lx->%lx %lx->%lx\r\n",prev_addr,flash_read_uintptr(prev_addr),base_addr,next_addr);
|
//printf("nc %lx->%lx %lx->%lx\n",prev_addr,flash_read_uintptr(prev_addr),base_addr,next_addr);
|
||||||
flash_program_uintptr(prev_addr, next_addr);
|
flash_program_uintptr(prev_addr, next_addr);
|
||||||
flash_program_halfword((uintptr_t) file->data, 0);
|
flash_program_halfword((uintptr_t) file->data, 0);
|
||||||
if (next_addr > 0) {
|
if (next_addr > 0) {
|
||||||
@@ -130,7 +130,7 @@ int flash_clear_file(file_t *file) {
|
|||||||
flash_program_uintptr(base_addr, 0);
|
flash_program_uintptr(base_addr, 0);
|
||||||
flash_program_uintptr(base_addr + sizeof(uintptr_t), 0);
|
flash_program_uintptr(base_addr + sizeof(uintptr_t), 0);
|
||||||
file->data = NULL;
|
file->data = NULL;
|
||||||
//printf("na %lx->%lx\r\n",prev_addr,flash_read_uintptr(prev_addr));
|
//printf("na %lx->%lx\n",prev_addr,flash_read_uintptr(prev_addr));
|
||||||
return CCID_OK;
|
return CCID_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t new_addr = allocate_free_addr(len, (file->type & FILE_PERSISTENT) == FILE_PERSISTENT);
|
uintptr_t new_addr = allocate_free_addr(len, (file->type & FILE_PERSISTENT) == FILE_PERSISTENT);
|
||||||
//printf("na %x\r\n",new_addr);
|
//printf("na %x\n",new_addr);
|
||||||
if (new_addr == 0x0) {
|
if (new_addr == 0x0) {
|
||||||
return CCID_ERR_NO_MEMORY;
|
return CCID_ERR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ int driver_process_usb_nopacket_ccid() {
|
|||||||
int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read) {
|
int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read) {
|
||||||
if (rx_read >= 10) {
|
if (rx_read >= 10) {
|
||||||
driver_init_ccid(itf);
|
driver_init_ccid(itf);
|
||||||
//printf("%ld %d %x %x\r\n",ccid_header->dwLength,rx_read-10,ccid_header->bMessageType,ccid_header->bSeq);
|
//printf("%ld %d %x %x\n",ccid_header->dwLength,rx_read-10,ccid_header->bMessageType,ccid_header->bSeq);
|
||||||
if (ccid_header[itf]->dwLength <= rx_read - 10) {
|
if (ccid_header[itf]->dwLength <= rx_read - 10) {
|
||||||
size_t apdu_sent = 0;
|
size_t apdu_sent = 0;
|
||||||
if (ccid_header[itf]->bMessageType != CCID_SLOT_STATUS) {
|
if (ccid_header[itf]->bMessageType != CCID_SLOT_STATUS) {
|
||||||
@@ -180,7 +180,7 @@ int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read) {
|
|||||||
ccid_response[itf]->bSeq = ccid_header[itf]->bSeq;
|
ccid_response[itf]->bSeq = ccid_header[itf]->bSeq;
|
||||||
ccid_response[itf]->abRFU0 = 0;
|
ccid_response[itf]->abRFU0 = 0;
|
||||||
ccid_response[itf]->abRFU1 = 0;
|
ccid_response[itf]->abRFU1 = 0;
|
||||||
//printf("1 %x %x %x || %x %x %x\r\n",ccid_response->apdu,apdu.rdata,ccid_response,ccid_header,ccid_header->apdu,apdu.data);
|
//printf("1 %x %x %x || %x %x %x\n",ccid_response->apdu,apdu.rdata,ccid_response,ccid_header,ccid_header->apdu,apdu.data);
|
||||||
memcpy(&ccid_response[itf]->apdu, ccid_atr + 1, size_atr);
|
memcpy(&ccid_response[itf]->apdu, ccid_atr + 1, size_atr);
|
||||||
if (ccid_status == 1) {
|
if (ccid_status == 1) {
|
||||||
card_start(apdu_thread);
|
card_start(apdu_thread);
|
||||||
@@ -284,19 +284,19 @@ uint8_t *driver_prepare_response_ccid(uint8_t itf) {
|
|||||||
#define MAX_USB_POWER 1
|
#define MAX_USB_POWER 1
|
||||||
|
|
||||||
static void ccid_init_cb(void) {
|
static void ccid_init_cb(void) {
|
||||||
TU_LOG1("-------- CCID INIT\r\n");
|
TU_LOG1("-------- CCID INIT\n");
|
||||||
vendord_init();
|
vendord_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ccid_reset_cb(uint8_t rhport) {
|
static void ccid_reset_cb(uint8_t rhport) {
|
||||||
TU_LOG1("-------- CCID RESET\r\n");
|
TU_LOG1("-------- CCID RESET\n");
|
||||||
itf_num = 0;
|
itf_num = 0;
|
||||||
vendord_reset(rhport);
|
vendord_reset(rhport);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
|
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);
|
uint8_t *itf_vendor = (uint8_t *) malloc(sizeof(uint8_t) * max_len);
|
||||||
//TU_LOG1("-------- CCID OPEN\r\n");
|
//TU_LOG1("-------- CCID OPEN\n");
|
||||||
TU_VERIFY(
|
TU_VERIFY(
|
||||||
itf_desc->bInterfaceClass == TUSB_CLASS_SMART_CARD && itf_desc->bInterfaceSubClass == 0 && itf_desc->bInterfaceProtocol == 0,
|
itf_desc->bInterfaceClass == TUSB_CLASS_SMART_CARD && itf_desc->bInterfaceSubClass == 0 && itf_desc->bInterfaceProtocol == 0,
|
||||||
0);
|
0);
|
||||||
@@ -327,13 +327,13 @@ static bool ccid_control_xfer_cb(uint8_t __unused rhport,
|
|||||||
uint8_t stage,
|
uint8_t stage,
|
||||||
tusb_control_request_t const *request) {
|
tusb_control_request_t const *request) {
|
||||||
// nothing to do with DATA & ACK stage
|
// nothing to do with DATA & ACK stage
|
||||||
TU_LOG2("-------- CCID CTRL XFER\r\n");
|
TU_LOG2("-------- CCID CTRL XFER\n");
|
||||||
if (stage != CONTROL_STAGE_SETUP) {
|
if (stage != CONTROL_STAGE_SETUP) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->wIndex == itf_num) {
|
if (request->wIndex == itf_num) {
|
||||||
TU_LOG2("-------- bmRequestType %x, bRequest %x, wValue %x, wLength %x\r\n",
|
TU_LOG2("-------- bmRequestType %x, bRequest %x, wValue %x, wLength %x\n",
|
||||||
request->bmRequestType,
|
request->bmRequestType,
|
||||||
request->bRequest,
|
request->bRequest,
|
||||||
request->wValue,
|
request->wValue,
|
||||||
@@ -371,7 +371,7 @@ static bool ccid_xfer_cb(uint8_t rhport,
|
|||||||
uint8_t ep_addr,
|
uint8_t ep_addr,
|
||||||
xfer_result_t result,
|
xfer_result_t result,
|
||||||
uint32_t xferred_bytes) {
|
uint32_t xferred_bytes) {
|
||||||
//printf("------ CALLED XFER_CB\r\n");
|
//printf("------ CALLED XFER_CB\n");
|
||||||
return vendord_xfer_cb(rhport, ep_addr, result, xferred_bytes);
|
return vendord_xfer_cb(rhport, ep_addr, result, xferred_bytes);
|
||||||
//return true;
|
//return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ void usb_task() {
|
|||||||
uint32_t m = 0x0;
|
uint32_t m = 0x0;
|
||||||
bool has_m = queue_try_remove(&card_to_usb_q, &m);
|
bool has_m = queue_try_remove(&card_to_usb_q, &m);
|
||||||
//if (m != 0)
|
//if (m != 0)
|
||||||
// printf("\r\n ------ M = %lu\r\n",m);
|
// printf("\n ------ M = %lu\n",m);
|
||||||
if (has_m) {
|
if (has_m) {
|
||||||
if (m == EV_EXEC_FINISHED) {
|
if (m == EV_EXEC_FINISHED) {
|
||||||
timeout_stop();
|
timeout_stop();
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
|
|||||||
if (request->bRequest == 0x22) {
|
if (request->bRequest == 0x22) {
|
||||||
web_serial_connected = (request->wValue != 0);
|
web_serial_connected = (request->wValue != 0);
|
||||||
if (web_serial_connected) {
|
if (web_serial_connected) {
|
||||||
printf("\r\nWebUSB interface connected\r\n");
|
printf("\nWebUSB interface connected\n");
|
||||||
}
|
}
|
||||||
return tud_control_status(rhport, request);
|
return tud_control_status(rhport, request);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user