mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 00:51:25 +02:00
@@ -15,8 +15,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "picokeys.h"
|
||||
#include "led/led.h"
|
||||
#include "random.h"
|
||||
#include "pico_keys.h"
|
||||
#ifdef PICO_PLATFORM
|
||||
#include "bsp/board.h"
|
||||
#endif
|
||||
@@ -27,7 +28,6 @@
|
||||
#include "emulation.h"
|
||||
#endif
|
||||
#include "ccid.h"
|
||||
#include "usb_descriptors.h"
|
||||
#include "apdu.h"
|
||||
#include "usb.h"
|
||||
|
||||
@@ -154,7 +154,7 @@ static int driver_init_ccid(uint8_t itf) {
|
||||
|
||||
//ccid_tx[itf].w_ptr = ccid_tx[itf].r_ptr = 0;
|
||||
|
||||
return PICOKEY_OK;
|
||||
return PICOKEYS_OK;
|
||||
}
|
||||
|
||||
void tud_vendor_rx_cb(uint8_t itf, const uint8_t *buffer, uint16_t bufsize) {
|
||||
@@ -347,10 +347,10 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of
|
||||
void ccid_task(void) {
|
||||
for (int itf = 0; itf < ITF_SC_TOTAL; itf++) {
|
||||
int status = card_status(sc_itf_to_usb_itf(itf));
|
||||
if (status == PICOKEY_OK) {
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_ccid(itf, finished_data_size);
|
||||
}
|
||||
else if (status == PICOKEY_ERR_BLOCKED) {
|
||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||
driver_exec_timeout_ccid(itf);
|
||||
}
|
||||
if (ccid_tx[itf].w_ptr > ccid_tx[itf].r_ptr) {
|
||||
|
||||
@@ -40,4 +40,30 @@ enum ccid_state {
|
||||
|
||||
extern const uint8_t *ccid_atr;
|
||||
|
||||
PACK(
|
||||
struct ccid_class_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdCCID;
|
||||
uint8_t bMaxSlotIndex;
|
||||
uint8_t bVoltageSupport;
|
||||
uint32_t dwProtocols;
|
||||
uint32_t dwDefaultClock;
|
||||
uint32_t dwMaximumClock;
|
||||
uint8_t bNumClockSupport;
|
||||
uint32_t dwDataRate;
|
||||
uint32_t dwMaxDataRate;
|
||||
uint8_t bNumDataRatesSupported;
|
||||
uint32_t dwMaxIFSD;
|
||||
uint32_t dwSynchProtocols;
|
||||
uint32_t dwMechanical;
|
||||
uint32_t dwFeatures;
|
||||
uint32_t dwMaxCCIDMessageLength;
|
||||
uint8_t bClassGetResponse;
|
||||
uint8_t bclassEnvelope;
|
||||
uint16_t wLcdLayout;
|
||||
uint8_t bPINSupport;
|
||||
uint8_t bMaxCCIDBusySlots;
|
||||
});
|
||||
|
||||
#endif //_CCID_H_
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pico_keys.h"
|
||||
#include "emulation.h"
|
||||
#include <stdio.h>
|
||||
#ifndef _MSC_VER
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "queue.h"
|
||||
#include "board.h"
|
||||
#include "compat/queue.h"
|
||||
#include "compat/board.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define USB_BUFFER_SIZE 4096
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pico_keys.h"
|
||||
#include "picokeys.h"
|
||||
#include "serial.h"
|
||||
#ifndef ENABLE_EMULATION
|
||||
#include "tusb.h"
|
||||
#if defined(PICO_PLATFORM)
|
||||
@@ -27,7 +28,7 @@ static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
|
||||
#include "emulation.h"
|
||||
#endif
|
||||
#include "ctap_hid.h"
|
||||
#include "pico_keys_version.h"
|
||||
#include "picokeys_version.h"
|
||||
#include "apdu.h"
|
||||
#include "usb.h"
|
||||
|
||||
@@ -399,8 +400,8 @@ int driver_process_usb_packet_hid(uint16_t read) {
|
||||
memcpy(resp->nonce, req->nonce, sizeof(resp->nonce));
|
||||
resp->cid = 0x01000000;
|
||||
resp->versionInterface = CTAPHID_IF_VERSION;
|
||||
resp->versionMajor = get_version_major ? get_version_major() : PICO_KEYS_SDK_VERSION_MAJOR;
|
||||
resp->versionMinor = get_version_minor ? get_version_minor() : PICO_KEYS_SDK_VERSION_MINOR;
|
||||
resp->versionMajor = get_version_major ? get_version_major() : PICOKEYS_SDK_VERSION_MAJOR;
|
||||
resp->versionMinor = get_version_minor ? get_version_minor() : PICOKEYS_SDK_VERSION_MINOR;
|
||||
resp->capFlags = CAPFLAG_WINK | CAPFLAG_CBOR;
|
||||
|
||||
ctap_resp->cid = ctap_req->cid;
|
||||
@@ -467,8 +468,8 @@ int driver_process_usb_packet_hid(uint16_t read) {
|
||||
else if (ctap_req->init.cmd == CTAPHID_VERSION) {
|
||||
ctap_resp->cid = ctap_req->cid;
|
||||
ctap_resp->init.cmd = ctap_req->init.cmd;
|
||||
ctap_resp->init.data[0] = PICO_KEYS_SDK_VERSION_MAJOR;
|
||||
ctap_resp->init.data[1] = PICO_KEYS_SDK_VERSION_MINOR;
|
||||
ctap_resp->init.data[0] = PICOKEYS_SDK_VERSION_MAJOR;
|
||||
ctap_resp->init.data[1] = PICOKEYS_SDK_VERSION_MINOR;
|
||||
ctap_resp->init.bcntl = 4;
|
||||
driver_write_hid(ITF_HID_CTAP, (const uint8_t *)ctap_resp, 64);
|
||||
msg_packet.len = msg_packet.current_len = 0;
|
||||
@@ -577,7 +578,7 @@ void driver_exec_finished_hid(uint16_t size_next) {
|
||||
else {
|
||||
if (is_nk) {
|
||||
memmove(apdu.rdata + 2, apdu.rdata, size_next - 2);
|
||||
put_uint16_t_be(apdu.sw, apdu.rdata);
|
||||
put_uint16_be(apdu.sw, apdu.rdata);
|
||||
}
|
||||
driver_exec_finished_cont_hid(ITF_HID_CTAP, size_next, 7);
|
||||
}
|
||||
@@ -620,10 +621,10 @@ void hid_task(void) {
|
||||
driver_process_usb_nopacket_hid();
|
||||
}
|
||||
int status = card_status(ITF_HID);
|
||||
if (status == PICOKEY_OK) {
|
||||
if (status == PICOKEYS_OK) {
|
||||
driver_exec_finished_hid(finished_data_size);
|
||||
}
|
||||
else if (status == PICOKEY_ERR_BLOCKED) {
|
||||
else if (status == PICOKEYS_ERR_BLOCKED) {
|
||||
send_keepalive();
|
||||
}
|
||||
if (hid_tx[ITF_HID_CTAP].w_ptr > hid_tx[ITF_HID_CTAP].r_ptr && last_write_result[ITF_HID_CTAP] != WRITE_PENDING) {
|
||||
|
||||
@@ -43,31 +43,31 @@ The smartphone may be artificially picky about which Ethernet MAC address to rec
|
||||
try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00 (clearing bit 1).
|
||||
*/
|
||||
|
||||
#if !defined(ESP_PLATFORM)
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#include "dhserver.h"
|
||||
#include "dnserver.h"
|
||||
#include "lwip/ethip6.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/timeouts.h"
|
||||
#endif
|
||||
#include "rest_server.h"
|
||||
#include "rest_server_tls.h"
|
||||
#include "tusb.h"
|
||||
|
||||
/* shared between tud_network_recv_cb() and service_traffic() */
|
||||
static struct pbuf *received_frame;
|
||||
|
||||
#if !defined(ESP_PLATFORM)
|
||||
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
|
||||
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
|
||||
/* it is suggested that the first byte is 0x02 to indicate a link-local address */
|
||||
uint8_t tud_network_mac_address[6] = {0x02, 0x02, 0x84, 0x6A, 0x96, 0x00};
|
||||
|
||||
#define INIT_IP4(a, b, c, d) \
|
||||
{ PP_HTONL(LWIP_MAKEU32(a, b, c, d)) }
|
||||
|
||||
/* lwip context */
|
||||
static struct netif netif_data;
|
||||
|
||||
/* shared between tud_network_recv_cb() and service_traffic() */
|
||||
static struct pbuf *received_frame;
|
||||
|
||||
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
|
||||
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
|
||||
/* it is suggested that the first byte is 0x02 to indicate a link-local address */
|
||||
uint8_t tud_network_mac_address[6] = {0x02, 0x02, 0x84, 0x6A, 0x96, 0x00};
|
||||
|
||||
/* network parameters of this MCU */
|
||||
static const ip4_addr_t ipaddr = INIT_IP4(192, 168, 7, 1);
|
||||
static const ip4_addr_t netmask = INIT_IP4(255, 255, 255, 0);
|
||||
@@ -201,8 +201,9 @@ void service_traffic(void) {
|
||||
received_frame = NULL;
|
||||
tud_network_recv_renew();
|
||||
}
|
||||
|
||||
#if !defined(ESP_PLATFORM)
|
||||
sys_check_timeouts();
|
||||
#endif
|
||||
}
|
||||
|
||||
void tud_network_init_cb(void) {
|
||||
@@ -213,11 +214,14 @@ void tud_network_init_cb(void) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
int lwip_itf_init(void) {
|
||||
#if !defined(ESP_PLATFORM)
|
||||
init_lwip();
|
||||
while (!netif_is_up(&netif_data));
|
||||
while (dhserv_init(&dhcp_config) != ERR_OK);
|
||||
while (dnserv_init(IP_ADDR_ANY, 53, dns_query_proc) != ERR_OK);
|
||||
#endif
|
||||
while (rest_server_init(REST_CONN_ALL) != ERR_OK);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "picokeys.h"
|
||||
#include "pico_time.h"
|
||||
#include "rest.h"
|
||||
#include <strings.h>
|
||||
#include "random.h"
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef REST_SERVER_H
|
||||
#define REST_SERVER_H
|
||||
#ifndef REST_H
|
||||
#define REST_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "cJSON.h"
|
||||
#include "pico_keys.h"
|
||||
|
||||
#define REST_MAX_REQUEST_SIZE 1024
|
||||
#define REST_MAX_METHOD_SIZE 8
|
||||
|
||||
@@ -15,18 +15,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
#include "picokeys.h"
|
||||
#include "rest_server.h"
|
||||
#include "rest_server_tls.h"
|
||||
#include "pico_keys.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#ifdef ENABLE_EMULATION
|
||||
@@ -127,7 +121,7 @@ void rest_task(void) {
|
||||
return;
|
||||
}
|
||||
status = card_status(ITF_LWIP);
|
||||
if (status != PICOKEY_OK) {
|
||||
if (status != PICOKEYS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PICO_KEYS_REST_SERVER_H
|
||||
#define PICO_KEYS_REST_SERVER_H
|
||||
#ifndef REST_SERVER_H
|
||||
#define REST_SERVER_H
|
||||
|
||||
#ifdef ENABLE_EMULATION
|
||||
typedef int err_t;
|
||||
|
||||
@@ -15,13 +15,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||
#include "picokeys.h"
|
||||
#include "rest_server_tls.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
extern void rest_close_conn(rest_conn_t *conn);
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PICO_KEYS_REST_SERVER_TLS_H
|
||||
#define PICO_KEYS_REST_SERVER_TLS_H
|
||||
#ifndef REST_SERVER_TLS_H
|
||||
#define REST_SERVER_TLS_H
|
||||
|
||||
#ifdef ENABLE_EMULATION
|
||||
typedef int err_t;
|
||||
@@ -58,4 +58,4 @@ extern void tls_handle_client(int client_fd);
|
||||
extern struct tcp_pcb *tls_listener_pcb;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif // REST_SERVER_TLS_H
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico_keys.h"
|
||||
#include "picokeys.h"
|
||||
#include "usb.h"
|
||||
#include "led/led.h"
|
||||
#include "button.h"
|
||||
#if defined(PICO_PLATFORM)
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/bootrom.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "hardware/sync.h"
|
||||
#include "bsp/board.h"
|
||||
#define multicore_launch_func_core1(a) multicore_launch_core1((void (*) (void))a)
|
||||
#endif
|
||||
#include "usb.h"
|
||||
#include "apdu.h"
|
||||
#ifndef ENABLE_EMULATION
|
||||
#include "tusb.h"
|
||||
@@ -31,10 +33,6 @@
|
||||
#include "emulation.h"
|
||||
#endif
|
||||
|
||||
// For memcpy
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Device specific functions
|
||||
static uint32_t *timeout_counter = NULL;
|
||||
static uint8_t card_locked_itf = 0; // no locked
|
||||
@@ -44,7 +42,7 @@ static mutex_t mutex;
|
||||
#endif
|
||||
#if !defined(PICO_PLATFORM) && !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#ifdef _MSC_VER
|
||||
#include "pthread_win32.h"
|
||||
#include "compat/pthread_win32.h"
|
||||
#endif
|
||||
pthread_t hcore0, hcore1;
|
||||
#endif
|
||||
@@ -327,7 +325,7 @@ void usb_task(void) {
|
||||
int card_status(uint8_t itf) {
|
||||
if (card_locked_itf == itf) {
|
||||
if (timeout == 0) {
|
||||
return PICOKEY_ERR_FILE_NOT_FOUND;
|
||||
return PICOKEYS_ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
uint32_t m = 0x0;
|
||||
#ifndef ENABLE_EMULATION
|
||||
@@ -343,11 +341,11 @@ int card_status(uint8_t itf) {
|
||||
if (m == EV_EXEC_FINISHED) {
|
||||
timeout_stop();
|
||||
led_set_mode(MODE_MOUNTED);
|
||||
return PICOKEY_OK;
|
||||
return PICOKEYS_OK;
|
||||
}
|
||||
#ifndef ENABLE_EMULATION
|
||||
else if (m == EV_PRESS_BUTTON) {
|
||||
uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
|
||||
uint32_t flag = button_wait() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
|
||||
queue_try_add(&usb_to_card_q, &flag);
|
||||
}
|
||||
#endif
|
||||
@@ -356,18 +354,18 @@ int card_status(uint8_t itf) {
|
||||
usb_secure_reboot_now();
|
||||
}
|
||||
#endif
|
||||
return PICOKEY_ERR_FILE_NOT_FOUND;
|
||||
return PICOKEYS_ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
else {
|
||||
if (timeout > 0) {
|
||||
if (timeout + timeout_counter[itf] < board_millis()) {
|
||||
timeout = board_millis();
|
||||
return PICOKEY_ERR_BLOCKED;
|
||||
return PICOKEYS_ERR_BLOCKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return PICOKEY_ERR_FILE_NOT_FOUND;
|
||||
return PICOKEYS_ERR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
#ifndef USB_ITF_CCID
|
||||
|
||||
@@ -18,18 +18,20 @@
|
||||
#ifndef _USB_H_
|
||||
#define _USB_H_
|
||||
|
||||
#include "picokeys.h"
|
||||
|
||||
#if defined(ENABLE_EMULATION)
|
||||
#include "emulation.h"
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#include "esp_compat.h"
|
||||
#include "compat/esp_compat.h"
|
||||
#elif defined(PICO_PLATFORM)
|
||||
#include "pico/util/queue.h"
|
||||
#else
|
||||
#include "queue.h"
|
||||
#include "board.h"
|
||||
#include "compat/queue.h"
|
||||
#include "compat/board.h"
|
||||
#endif
|
||||
|
||||
#include "compat.h"
|
||||
#include "compat/compat.h"
|
||||
|
||||
/* USB thread */
|
||||
#define EV_CARD_CHANGE 1
|
||||
|
||||
@@ -15,17 +15,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pico_keys.h"
|
||||
#include "picokeys.h"
|
||||
#include "tusb.h"
|
||||
#include "usb_descriptors.h"
|
||||
#if defined(PICO_PLATFORM)
|
||||
#include "pico/unique_id.h"
|
||||
#endif
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "tinyusb.h"
|
||||
#endif
|
||||
#include "pico_keys_version.h"
|
||||
#include "picokeys_version.h"
|
||||
#include "usb.h"
|
||||
#include "serial.h"
|
||||
|
||||
#ifndef USB_VID
|
||||
#define USB_VID 0x2E8A
|
||||
@@ -59,7 +56,7 @@ tusb_desc_device_t desc_device = {
|
||||
|
||||
.idVendor = (USB_VID),
|
||||
.idProduct = (USB_PID),
|
||||
.bcdDevice = PICO_KEYS_SDK_VERSION,
|
||||
.bcdDevice = PICOKEYS_SDK_VERSION,
|
||||
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Pico Keys SDK distribution (https://github.com/polhenarejos/pico-keys-sdk).
|
||||
* Copyright (c) 2022 Pol Henarejos.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef USB_DESCRIPTORS_H_
|
||||
#define USB_DESCRIPTORS_H_
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
PACK(
|
||||
struct ccid_class_descriptor {
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t bcdCCID;
|
||||
uint8_t bMaxSlotIndex;
|
||||
uint8_t bVoltageSupport;
|
||||
uint32_t dwProtocols;
|
||||
uint32_t dwDefaultClock;
|
||||
uint32_t dwMaximumClock;
|
||||
uint8_t bNumClockSupport;
|
||||
uint32_t dwDataRate;
|
||||
uint32_t dwMaxDataRate;
|
||||
uint8_t bNumDataRatesSupported;
|
||||
uint32_t dwMaxIFSD;
|
||||
uint32_t dwSynchProtocols;
|
||||
uint32_t dwMechanical;
|
||||
uint32_t dwFeatures;
|
||||
uint32_t dwMaxCCIDMessageLength;
|
||||
uint8_t bClassGetResponse;
|
||||
uint8_t bclassEnvelope;
|
||||
uint16_t wLcdLayout;
|
||||
uint8_t bPINSupport;
|
||||
uint8_t bMaxCCIDBusySlots;
|
||||
});
|
||||
|
||||
#endif /* USB_DESCRIPTORS_H_ */
|
||||
Reference in New Issue
Block a user