kopia lustrzana https://github.com/conorpp/u2f-zero
testing here
rodzic
6aa59a6f96
commit
9965cf21a3
|
@ -162,7 +162,7 @@
|
|||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="com.silabs.ide.project.core" project.generation="77" projectCommon.buildArtifactType="EXE" projectCommon.kitId="com.silabs.kit.si8051.efm8ub1_slstk2000a" projectCommon.partId="com.silabs.mcu.si8051.efm8ub1_g.efm8ub10f16g" projectCommon.sdkId="com.silabs.sdk.si8051.sls:3.0.0"/>
|
||||
<storageModule moduleId="com.silabs.ide.project.core" project.generation="31" projectCommon.buildArtifactType="EXE" projectCommon.kitId="com.silabs.kit.si8051.efm8ub1_slstk2000a" projectCommon.partId="com.silabs.mcu.si8051.efm8ub1_g.efm8ub10f16g" projectCommon.sdkId="com.silabs.sdk.si8051.sls:3.0.0"/>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="u2f-firmware.com.silabs.ide.project.core.cdt.cdtMbsProjectType.801504117" name="SLS CDT Project" projectType="com.silabs.ide.project.core.cdt.cdtMbsProjectType"/>
|
||||
</storageModule>
|
||||
|
|
|
@ -59,10 +59,8 @@ struct APP_DATA
|
|||
{
|
||||
// must be at least 70 bytes
|
||||
uint8_t tmp[70];
|
||||
uint8_t state;
|
||||
uint8_t error;
|
||||
|
||||
struct u2f_hid_msg * hid_msg;
|
||||
|
||||
};
|
||||
|
||||
#define U2F_CONFIG_GET_SERIAL_NUM 0x80
|
||||
|
@ -85,6 +83,12 @@ extern data struct APP_DATA appdata;
|
|||
|
||||
void set_app_u2f_hid_msg(struct u2f_hid_msg * msg );
|
||||
void set_app_error(APP_ERROR_CODE ec);
|
||||
uint8_t get_app_error();
|
||||
|
||||
uint8_t get_app_state();
|
||||
|
||||
void set_app_state(APP_STATE s);
|
||||
|
||||
void rgb(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
// should be called after initializing eeprom
|
||||
|
|
|
@ -13,7 +13,6 @@ struct smb_interrupt_interface
|
|||
uint8_t addr;
|
||||
uint16_t crc;
|
||||
uint8_t crc_offset;
|
||||
uint8_t errors;
|
||||
|
||||
uint8_t* write_buf;
|
||||
uint8_t write_len;
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved.
|
||||
*
|
||||
* http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt
|
||||
*****************************************************************************/
|
||||
|
||||
#include "si_toolchain.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Constants
|
||||
// ----------------------------------------------------------------------------
|
||||
#define DEFAULT_IDLE_RATE 500 // Rate defined in the HID class doc.
|
||||
#define POLL_RATE 24 // The bInterval reported with the
|
||||
// interrupt IN endpoint descriptor.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Typedefs
|
||||
// ----------------------------------------------------------------------------
|
||||
typedef struct
|
||||
{
|
||||
uint8_t rate;
|
||||
uint16_t timer;
|
||||
} idleTimer_TypeDef;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Function Prototypes
|
||||
// ----------------------------------------------------------------------------
|
||||
void idleTimerStart(void);
|
||||
bool isIdleTimerIndefinite(void);
|
||||
bool isIdleTimerExpired(void);
|
||||
void idleTimerSet(uint8_t rate);
|
||||
void idleTimerTick(void);
|
||||
uint8_t idleGetRate(void);
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#include "si_toolchain.h"
|
||||
#include "efm8_usb.h"
|
||||
#include "assert.h"
|
||||
//#include "assert.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define SLAB_ASSERT(x)
|
||||
// -----------------------------------------------------------------------------
|
||||
// Global Variables
|
||||
|
||||
|
|
|
@ -414,16 +414,16 @@ extern void PBCFG_0_enter_DefaultMode_from_RESET(void) {
|
|||
|
||||
// $[XBR1 - Port I/O Crossbar 1]
|
||||
/*
|
||||
// PCA0ME (PCA Module I/O Enable) = CEX0_CEX1 (CEX0, CEX1 routed to Port
|
||||
// pins.)
|
||||
// PCA0ME (PCA Module I/O Enable) = CEX0_CEX1_CEX2 (CEX0, CEX1, CEX2
|
||||
// routed to Port pins.)
|
||||
// ECIE (PCA0 External Counter Input Enable) = DISABLED (ECI unavailable
|
||||
// at Port pin.)
|
||||
// T0E (T0 Enable) = DISABLED (T0 unavailable at Port pin.)
|
||||
// T1E (T1 Enable) = DISABLED (T1 unavailable at Port pin.)
|
||||
// T2E (T2 Enable) = DISABLED (T2 unavailable at Port pin.)
|
||||
*/
|
||||
XBR1 = XBR1_PCA0ME__CEX0_CEX1 | XBR1_ECIE__DISABLED | XBR1_T0E__DISABLED
|
||||
| XBR1_T1E__DISABLED | XBR1_T2E__DISABLED;
|
||||
XBR1 = XBR1_PCA0ME__CEX0_CEX1_CEX2 | XBR1_ECIE__DISABLED
|
||||
| XBR1_T0E__DISABLED | XBR1_T1E__DISABLED | XBR1_T2E__DISABLED;
|
||||
// [XBR1 - Port I/O Crossbar 1]$
|
||||
|
||||
}
|
||||
|
@ -858,17 +858,9 @@ extern void PCACH_0_enter_DefaultMode_from_RESET(void) {
|
|||
// [PCA0CPM0 - PCA Channel 0 Capture/Compare Mode]$
|
||||
|
||||
// $[PCA0CPL0 - PCA Channel 0 Capture Module Low Byte]
|
||||
/*
|
||||
// PCA0CPL0 (PCA Channel 0 Capture Module Low Byte) = 0xDC
|
||||
*/
|
||||
PCA0CPL0 = (0xDC << PCA0CPL0_PCA0CPL0__SHIFT);
|
||||
// [PCA0CPL0 - PCA Channel 0 Capture Module Low Byte]$
|
||||
|
||||
// $[PCA0CPH0 - PCA Channel 0 Capture Module High Byte]
|
||||
/*
|
||||
// PCA0CPH0 (PCA Channel 0 Capture Module High Byte) = 0xFF
|
||||
*/
|
||||
PCA0CPH0 = (0xFF << PCA0CPH0_PCA0CPH0__SHIFT);
|
||||
// [PCA0CPH0 - PCA Channel 0 Capture Module High Byte]$
|
||||
|
||||
// $[Auto-reload]
|
||||
|
|
|
@ -137,7 +137,7 @@ int8_t atecc_send_recv(uint8_t cmd, uint8_t p1, uint16_t p2,
|
|||
{
|
||||
return -1;
|
||||
}
|
||||
switch(appdata.error)
|
||||
switch(get_app_error())
|
||||
{
|
||||
case ERROR_NOTHING:
|
||||
delay_cmd(cmd);
|
||||
|
|
|
@ -66,34 +66,56 @@ USB_Status_TypeDef USBD_SetupCmdCb(
|
|||
|
||||
switch (setup->bRequest) {
|
||||
case GET_DESCRIPTOR:
|
||||
if ((setup->wValue >> 8) == USB_HID_REPORT_DESCRIPTOR) {
|
||||
switch (setup->wIndex) {
|
||||
case 0: // Interface 0
|
||||
USBD_Write(EP0, ReportDescriptor0,
|
||||
EFM8_MIN(sizeof(ReportDescriptor0), setup->wLength),
|
||||
false);
|
||||
retVal = USB_STATUS_OK;
|
||||
break;
|
||||
if (setup->wIndex == 0)
|
||||
{
|
||||
if ((setup->wValue >> 8) == USB_HID_REPORT_DESCRIPTOR) {
|
||||
|
||||
default: // Unhandled Interface
|
||||
break;
|
||||
}
|
||||
} else if ((setup->wValue >> 8) == USB_HID_DESCRIPTOR) {
|
||||
switch (setup->wIndex) {
|
||||
case 0: // Interface 0
|
||||
USBD_Write(EP0, (&configDesc[18]),
|
||||
EFM8_MIN(USB_HID_DESCSIZE, setup->wLength), false);
|
||||
retVal = USB_STATUS_OK;
|
||||
break;
|
||||
USBD_Write(EP0, ReportDescriptor0,
|
||||
EFM8_MIN(sizeof(ReportDescriptor0), setup->wLength),
|
||||
false);
|
||||
retVal = USB_STATUS_OK;
|
||||
|
||||
} else if ((setup->wValue >> 8) == USB_HID_DESCRIPTOR) {
|
||||
|
||||
USBD_Write(EP0, (&configDesc[18]),
|
||||
EFM8_MIN(USB_HID_DESCSIZE, setup->wLength), false);
|
||||
retVal = USB_STATUS_OK;
|
||||
|
||||
default: // Unhandled Interface
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ((setup->bmRequestType.Type == USB_SETUP_TYPE_CLASS)
|
||||
&& (setup->bmRequestType.Recipient == USB_SETUP_RECIPIENT_INTERFACE)
|
||||
&& (setup->wIndex == HID_INTERFACE_INDEX))
|
||||
{
|
||||
// Implement the necessary HID class specific commands.
|
||||
switch (setup->bRequest)
|
||||
{
|
||||
case USB_HID_SET_IDLE:
|
||||
if (((setup->wValue & 0xFF) == 0) // Report ID
|
||||
&& (setup->wLength == 0)
|
||||
&& (setup->bmRequestType.Direction != USB_SETUP_DIR_IN))
|
||||
{
|
||||
retVal = USB_STATUS_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_HID_GET_IDLE:
|
||||
if ((setup->wValue == 0) // Report ID
|
||||
&& (setup->wLength == 1)
|
||||
&& (setup->bmRequestType.Direction == USB_SETUP_DIR_IN))
|
||||
{
|
||||
tmpBuffer = 24;
|
||||
USBD_Write(EP0, &tmpBuffer, 1, false);
|
||||
retVal = USB_STATUS_OK;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
@ -112,8 +134,6 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status,
|
|||
set_app_u2f_hid_msg((struct u2f_hid_msg *) hidmsgbuf );
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
/**************************************************************************//**
|
||||
* Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved.
|
||||
*
|
||||
* http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt
|
||||
*****************************************************************************/
|
||||
|
||||
#include "si_toolchain.h"
|
||||
#include "idle.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Variables
|
||||
// ----------------------------------------------------------------------------
|
||||
static idleTimer_TypeDef idle;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void idleTimerStart(void)
|
||||
{
|
||||
if (idle.rate > 0)
|
||||
{
|
||||
idle.timer = idle.rate * 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
idle.timer = POLL_RATE;
|
||||
}
|
||||
}
|
||||
|
||||
bool isIdleTimerIndefinite(void)
|
||||
{
|
||||
if (idle.rate == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
bool isIdleTimerExpired(void)
|
||||
{
|
||||
if (idle.timer == 0)
|
||||
{
|
||||
idleTimerStart();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void idleTimerSet(uint8_t rate)
|
||||
{
|
||||
if ((rate != 0) && (rate < (POLL_RATE / 4)))
|
||||
{
|
||||
idle.rate = POLL_RATE / 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
idle.rate = rate;
|
||||
}
|
||||
|
||||
idleTimerStart();
|
||||
}
|
||||
|
||||
void idleTimerTick(void)
|
||||
{
|
||||
if (idle.timer > 0)
|
||||
{
|
||||
idle.timer--;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t idleGetRate(void)
|
||||
{
|
||||
return idle.rate;
|
||||
}
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
data struct APP_DATA appdata;
|
||||
|
||||
uint8_t error;
|
||||
uint8_t state;
|
||||
struct u2f_hid_msg * hid_msg;
|
||||
|
||||
static void init(struct APP_DATA* ap)
|
||||
{
|
||||
memset(ap,0, sizeof(struct APP_DATA));
|
||||
|
@ -28,17 +32,34 @@ static void init(struct APP_DATA* ap)
|
|||
u2f_init();
|
||||
#endif
|
||||
U2F_BUTTON_VAL = 1;
|
||||
state = APP_NOTHING;
|
||||
error = ERROR_NOTHING;
|
||||
}
|
||||
|
||||
void set_app_error(APP_ERROR_CODE ec)
|
||||
{
|
||||
appdata.error = ec;
|
||||
error = ec;
|
||||
}
|
||||
|
||||
uint8_t get_app_error()
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
uint8_t get_app_state()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
void set_app_state(APP_STATE s)
|
||||
{
|
||||
state = s;
|
||||
}
|
||||
|
||||
void set_app_u2f_hid_msg(struct u2f_hid_msg * msg )
|
||||
{
|
||||
appdata.state = APP_HID_MSG;
|
||||
appdata.hid_msg = msg;
|
||||
state = APP_HID_MSG;
|
||||
hid_msg = msg;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,12 +109,12 @@ int16_t main(void) {
|
|||
}
|
||||
|
||||
|
||||
if (!USBD_EpIsBusy(EP1OUT) && !USBD_EpIsBusy(EP1IN) && appdata.state != APP_HID_MSG)
|
||||
if (!USBD_EpIsBusy(EP1OUT) && !USBD_EpIsBusy(EP1IN) && state != APP_HID_MSG)
|
||||
{
|
||||
USBD_Read(EP1OUT, hidmsgbuf, sizeof(hidmsgbuf), true);
|
||||
}
|
||||
|
||||
switch(appdata.state)
|
||||
switch(state)
|
||||
{
|
||||
case APP_NOTHING:
|
||||
if (ms_since(ms_grad, 10))
|
||||
|
@ -120,18 +141,18 @@ int16_t main(void) {
|
|||
break;
|
||||
case APP_HID_MSG:
|
||||
#ifndef ATECC_SETUP_DEVICE
|
||||
u2f_hid_request(appdata.hid_msg);
|
||||
u2f_hid_request(hid_msg);
|
||||
#else
|
||||
atecc_setup_device((struct config_msg*)appdata.hid_msg);
|
||||
#endif
|
||||
if (appdata.state == APP_HID_MSG)
|
||||
appdata.state = APP_NOTHING;
|
||||
if (state == APP_HID_MSG)
|
||||
state = APP_NOTHING;
|
||||
break;
|
||||
case APP_WINK:
|
||||
rgb(0,0,150);
|
||||
light = 150;
|
||||
ms_wink = get_ms();
|
||||
appdata.state = _APP_WINK;
|
||||
state = _APP_WINK;
|
||||
break;
|
||||
case _APP_WINK:
|
||||
|
||||
|
@ -144,15 +165,15 @@ int16_t main(void) {
|
|||
if (winks == 5)
|
||||
{
|
||||
winks = 0;
|
||||
appdata.state = APP_NOTHING;
|
||||
state = APP_NOTHING;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (appdata.error)
|
||||
if (error)
|
||||
{
|
||||
u2f_printb("error: ", 1, appdata.error);
|
||||
appdata.error = 0;
|
||||
u2f_printb("error: ", 1, error);
|
||||
error = 0;
|
||||
rgb(200,0,0);
|
||||
}
|
||||
|
||||
|
|
|
@ -340,7 +340,7 @@ static void hid_u2f_parse(struct u2f_hid_msg* req)
|
|||
u2f_hid_set_len(0);
|
||||
u2f_hid_writeback(NULL, 0);
|
||||
u2f_hid_flush();
|
||||
appdata.state = APP_WINK;
|
||||
set_app_state(APP_WINK);
|
||||
break;
|
||||
case U2FHID_LOCK:
|
||||
// TODO
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<property object="CLOCK_0" propertyId="clock.clockselect.clocksourcedivider" value="SYSCLK / 1"/>
|
||||
<property object="CLOCK_0" propertyId="clock.clockselect.selectclocksource" value="Internal High Frequency Oscillator 1"/>
|
||||
<property object="CRC_0" propertyId="crc.crccontrol.enablecrcinitialization" value="Initialize"/>
|
||||
<property object="CROSSBAR0" propertyId="xbar0.pca0.cex" value="CEX0 and CEX1"/>
|
||||
<property object="CROSSBAR0" propertyId="xbar0.pca0.cex" value="CEX0, CEX1, and CEX2"/>
|
||||
<property object="CROSSBAR0" propertyId="xbar0.smbus0.clockdata" value="Enabled"/>
|
||||
<property object="CROSSBAR0" propertyId="xbar0.uart0.data" value="Enabled"/>
|
||||
<property object="DefaultMode" propertyId="mode.diagramLocation" value="100, 100"/>
|
||||
|
@ -41,8 +41,6 @@
|
|||
<property object="P1.0" propertyId="ports.settings.outputmode" value="Push-pull"/>
|
||||
<property object="PBCFG_0" propertyId="pbcfg.settings.enablecrossbar" value="Enabled"/>
|
||||
<property object="PCACH_0" propertyId="ABPeripheral.included" value="true"/>
|
||||
<property object="PCACH_0" propertyId="pcach.pcachannel.capturecomparehighbyte" value="255"/>
|
||||
<property object="PCACH_0" propertyId="pcach.pcachannel.capturecomparelowbyte" value="220"/>
|
||||
<property object="PCACH_0" propertyId="pcach.pcachannel.capturecompareregister" value="65500"/>
|
||||
<property object="PCACH_0" propertyId="pcach.pcachannel.clockdivider" value="100"/>
|
||||
<property object="PCACH_0" propertyId="pcach.pcachannelcapturecomparemode.enablechannelcomparatorfunction" value="Enabled"/>
|
||||
|
|
Ładowanie…
Reference in New Issue