debug
Conor Patrick 2016-11-12 22:36:44 -05:00
rodzic d25109479d
commit a6c0343903
12 zmienionych plików z 172 dodań i 155 usunięć

Wyświetl plik

@ -49,7 +49,7 @@
<listOptionValue builtIn="false" value="&quot;${StudioSdkPath}/Device/EFM8UB1/peripheral_driver/inc&quot;"/>
<listOptionValue builtIn="false" value="&quot;${StudioSdkPath}/Lib/efm8_assert&quot;"/>
</option>
<option id="com.silabs.ide.si8051.keil.compiler.category.general.code.389376290" name="Code size" superClass="com.silabs.ide.si8051.keil.compiler.category.general.code" value="com.silabs.ide.si8051.keil.compiler.category.general.code.large" valueType="enumerated"/>
<option id="com.silabs.ide.si8051.keil.compiler.category.general.code.389376290" name="Code size" superClass="com.silabs.ide.si8051.keil.compiler.category.general.code" value="com.silabs.ide.si8051.keil.compiler.category.general.code.compact" valueType="enumerated"/>
<option id="com.silabs.ide.si8051.keil.compiler.category.misc.extraflags.762226691" name="Additional Flags" superClass="com.silabs.ide.si8051.keil.compiler.category.misc.extraflags" value="" valueType="string"/>
<inputType id="com.silabs.ide.si8051.keil.compiler.inputType.261436307" superClass="com.silabs.ide.si8051.keil.compiler.inputType"/>
</tool>

Wyświetl plik

@ -0,0 +1,2 @@
copiedFilesOriginState={}
eclipse.preferences.version=1

Wyświetl plik

@ -39,7 +39,7 @@
// application settings
#define U2F_ATTESTATION_KEY_SLOT 15
//#define ATECC_SETUP_DEVICE
//#define U2F_PRINT
#define U2F_PRINT
//#define U2F_BLINK_ERRORS
// efm8ub1 application eeprom memory mappings

Wyświetl plik

@ -37,10 +37,10 @@ extern void enter_DefaultMode_from_RESET(void) {
TIMER16_2_enter_DefaultMode_from_RESET();
TIMER16_3_enter_DefaultMode_from_RESET();
TIMER_SETUP_0_enter_DefaultMode_from_RESET();
PCA_0_enter_DefaultMode_from_RESET();
PCACH_0_enter_DefaultMode_from_RESET();
PCACH_1_enter_DefaultMode_from_RESET();
PCACH_2_enter_DefaultMode_from_RESET();
// PCA_0_enter_DefaultMode_from_RESET();
// PCACH_0_enter_DefaultMode_from_RESET();
// PCACH_1_enter_DefaultMode_from_RESET();
// PCACH_2_enter_DefaultMode_from_RESET();
SMBUS_0_enter_DefaultMode_from_RESET();
UART_0_enter_DefaultMode_from_RESET();
INTERRUPT_0_enter_DefaultMode_from_RESET();

Wyświetl plik

@ -207,7 +207,6 @@ SI_INTERRUPT (SMBUS0_ISR, SMBUS0_IRQn)
return;
fail:
u2f_printb("smbus fail ",1,bus);
restart_bus();
SMB0CN0_SI = 0;
}

Wyświetl plik

@ -45,6 +45,8 @@ void u2f_delay(uint32_t ms) {
void usb_write(uint8_t* buf, uint8_t len)
{
uint8_t errors = 0;
u2f_prints("<< ");
dump_hex(buf,len);
while (USB_STATUS_OK != (USBD_Write(EP1IN, buf, len, false)))
{
u2f_delay(2);

Wyświetl plik

@ -153,6 +153,8 @@ uint16_t USBD_XferCompleteCb(uint8_t epAddr, USB_Status_TypeDef status,
if (epAddr == EP1OUT)
{
set_app_u2f_hid_msg((struct u2f_hid_msg *) hidmsgbuf );
u2f_prints(">> ");
dump_hex(hidmsgbuf,sizeof(hidmsgbuf));
}
return 0;
}

Wyświetl plik

@ -2,23 +2,26 @@
#include <stdint.h>
code uint8_t __attest[] =
"\x30\x82\x01\x5b\x30\x82\x01\x00\x02\x01\x01\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d"
"\x04\x03\x02\x30\x39\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x56\x41\x31\x14"
"\x30\x12\x06\x03\x55\x04\x0a\x0c\x0b\x43\x6f\x6e\x6f\x72\x43\x6f\x20\x4c\x4c\x43"
"\x31\x14\x30\x12\x06\x03\x55\x04\x03\x0c\x0b\x75\x32\x66\x7a\x65\x72\x6f\x2e\x63"
"\x6f\x6d\x30\x1e\x17\x0d\x31\x36\x30\x37\x32\x36\x30\x34\x35\x33\x30\x39\x5a\x17"
"\x0d\x32\x32\x30\x37\x32\x35\x30\x34\x35\x33\x30\x39\x5a\x30\x39\x31\x0b\x30\x09"
"\x06\x03\x55\x04\x06\x13\x02\x56\x41\x31\x14\x30\x12\x06\x03\x55\x04\x0a\x0c\x0b"
"\x43\x6f\x6e\x6f\x72\x43\x6f\x20\x4c\x4c\x43\x31\x14\x30\x12\x06\x03\x55\x04\x03"
"\x0c\x0b\x75\x32\x66\x7a\x65\x72\x6f\x2e\x63\x6f\x6d\x30\x59\x30\x13\x06\x07\x2a"
"\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07\x03\x42\x00\x04"
"\x7e\xb9\x41\xe6\x14\x25\x3d\x85\xb2\x45\x3f\xdc\xdf\x6d\x0f\x02\x52\xd5\xda\xfb"
"\x5a\xfe\xdb\xa8\xf2\x01\xe0\x03\xc9\xe5\x2b\x1d\xbf\x64\x03\x34\x33\xe6\xe0\xc1"
"\xa1\x21\x53\x6d\xa5\x7c\xc5\x82\xb5\xd1\x53\x54\xfb\x99\xbb\x27\xec\x18\x78\x48"
"\x23\x34\x09\x5b\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d\x04\x03\x02\x03\x49\x00\x30"
"\x46\x02\x21\x00\xb9\x01\x10\xf1\x18\xb4\xf0\xbd\x35\x3b\x6a\x60\x55\x8d\xe8\x3a"
"\x88\x70\x8a\x3c\x03\x2b\x14\x56\x58\xfe\x11\x29\x7d\x3a\x05\xce\x02\x21\x00\xf4"
"\xd8\x89\x1a\xfc\x36\x5a\xd7\xf2\xe9\x8d\x5a\xb3\x4b\xae\xa2\xa1\x48\x80\xdb\x37"
"\x14\xc3\xb7\x56\xbb\x2b\x12\x69\xf2\x07\xcd"
"\x30\x82\x01\x9b\x30\x82\x01\x41\x02\x01\x01\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d"
"\x04\x03\x02\x30\x7d\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x55\x53\x31\x13"
"\x30\x11\x06\x03\x55\x04\x08\x0c\x0a\x53\x6f\x6d\x65\x20\x73\x74\x61\x74\x65\x31"
"\x12\x30\x10\x06\x03\x55\x04\x07\x0c\x09\x53\x6f\x6d\x65\x20\x63\x69\x74\x79\x31"
"\x15\x30\x13\x06\x03\x55\x04\x0a\x0c\x0c\x53\x6f\x6d\x65\x20\x63\x6f\x6d\x70\x61"
"\x6e\x79\x31\x18\x30\x16\x06\x03\x55\x04\x0b\x0c\x0f\x53\x6f\x6d\x65\x20\x64\x65"
"\x70\x61\x72\x74\x6d\x65\x6e\x74\x31\x14\x30\x12\x06\x03\x55\x04\x03\x0c\x0b\x63"
"\x6f\x6e\x6f\x72\x70\x70\x2e\x63\x6f\x6d\x30\x1e\x17\x0d\x31\x36\x31\x31\x31\x32"
"\x32\x33\x32\x33\x31\x36\x5a\x17\x0d\x32\x32\x31\x31\x31\x31\x32\x33\x32\x33\x31"
"\x36\x5a\x30\x36\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x55\x53\x31\x11\x30"
"\x0f\x06\x03\x55\x04\x0a\x0c\x08\x55\x32\x46\x20\x5a\x65\x72\x6f\x31\x14\x30\x12"
"\x06\x03\x55\x04\x03\x0c\x0b\x75\x32\x66\x7a\x65\x72\x6f\x2e\x63\x6f\x6d\x30\x59"
"\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48\xce\x3d\x03\x01"
"\x07\x03\x42\x00\x04\xf2\xcc\x4a\xa6\xef\x5a\xa6\x0c\xc6\x2e\x76\x53\xdf\x45\x02"
"\x13\x29\x12\x31\x4f\xdd\xda\x50\x56\x91\x95\x56\xb3\x05\xba\x83\xef\xfa\x55\x9a"
"\x8a\x26\x95\x5c\x0d\x4d\x8e\x4c\x9d\xfa\x6d\xe6\xea\x68\xf1\x85\xc1\xd7\x15\x5f"
"\x7f\x93\x77\xf5\x7f\x13\x74\x0c\xcb\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d\x04\x03"
"\x02\x03\x48\x00\x30\x45\x02\x20\x3e\x52\xa9\xb3\x71\x4b\x0e\xbd\xae\x6a\xf9\x87"
"\xc5\x00\x4c\x87\x4c\xc3\x73\xc2\xf0\xa1\x81\x95\x51\x51\x5c\x6a\xe3\xf0\x08\x78"
"\x02\x21\x00\xde\x1c\x1d\xd3\x1a\xe6\xc2\x7a\xd3\x64\xed\xaa\x82\x88\xc7\x9c\x6b"
"\xd3\xda\x32\x79\x80\x83\x4d\x73\x7f\x31\x4b\x4c\x4d\xf8\x81"
;
const uint16_t __attest_size = sizeof(__attest)-1;

Wyświetl plik

@ -103,35 +103,35 @@ void set_app_u2f_hid_msg(struct u2f_hid_msg * msg )
void rgb(uint8_t r, uint8_t g, uint8_t b)
{
if (r)
{
PCA0CPM2 |= PCA0CPM2_PWM__ENABLED;
LED_R(r);
}
else
{
PCA0CPM2 &= ~PCA0CPM2_PWM__ENABLED;
}
if (b)
{
PCA0CPM0 |= PCA0CPM0_PWM__ENABLED;
LED_B(b);
}
else
{
PCA0CPM0 &= ~PCA0CPM0_PWM__ENABLED;
}
if (g)
{
PCA0CPM1 |= PCA0CPM1_PWM__ENABLED;
LED_G(g);
}
else
{
PCA0CPM1 &= ~PCA0CPM1_PWM__ENABLED;
}
// if (r)
// {
// PCA0CPM2 |= PCA0CPM2_PWM__ENABLED;
// LED_R(r);
// }
// else
// {
// PCA0CPM2 &= ~PCA0CPM2_PWM__ENABLED;
// }
//
// if (b)
// {
// PCA0CPM0 |= PCA0CPM0_PWM__ENABLED;
// LED_B(b);
// }
// else
// {
// PCA0CPM0 &= ~PCA0CPM0_PWM__ENABLED;
// }
//
// if (g)
// {
// PCA0CPM1 |= PCA0CPM1_PWM__ENABLED;
// LED_G(g);
// }
// else
// {
// PCA0CPM1 &= ~PCA0CPM1_PWM__ENABLED;
// }
}
@ -148,7 +148,7 @@ int16_t main(void) {
int8_t ii;
enter_DefaultMode_from_RESET();
rgb_hex(0);
//rgb_hex(0);
// ~200 ms interval watchdog
WDTCN = 4;
@ -158,9 +158,9 @@ int16_t main(void) {
// Enable interrupts
IE_EA = 1;
watchdog();
//watchdog();
u2f_prints("U2F ZERO\r\n");
//u2f_prints("U2F ZERO\r\n");
if (RSTSRC & RSTSRC_WDTRSF__SET)
{
@ -171,16 +171,16 @@ int16_t main(void) {
atecc_setup_init(appdata.tmp);
rgb_hex(0);
//rgb_hex(0);
while (1) {
watchdog();
if (ms_since(ms_heart,500))
{
u2f_printl("ms ", 1, get_ms());
}
// if (ms_since(ms_heart,500))
// {
// u2f_printl("ms ", 1, get_ms());
// }
if (!USBD_EpIsBusy(EP1OUT) && !USBD_EpIsBusy(EP1IN) && state != APP_HID_MSG)
{
@ -193,35 +193,35 @@ int16_t main(void) {
{
case APP_NOTHING:
// Flash gradient on LED
if (ms_since(ms_grad, 150))
{
if (light == 16)
{
grad_dir = 0;
}
else if (light == 1)
{
grad_dir = 1;
}
if (grad_dir)
if (U2F_BUTTON_IS_PRESSED())
rgb(0,0,light++);
else
rgb(0,light++,0);
else
if (U2F_BUTTON_IS_PRESSED())
rgb(0,0,light--);
else
rgb(0,light--,0);
}
// if (ms_since(ms_grad, 150))
// {
//// if (light == 16)
//// {
//// grad_dir = 0;
//// }
//// else if (light == 1)
//// {
//// grad_dir = 1;
//// }
//// if (grad_dir)
//// if (U2F_BUTTON_IS_PRESSED())
//// rgb(0,0,light++);
//// else
//// rgb(0,light++,0);
//// else
//// if (U2F_BUTTON_IS_PRESSED())
//// rgb(0,0,light--);
//// else
//// rgb(0,light--,0);
// }
break;
case APP_HID_MSG:
// HID msg received, pass to protocols
if (custom_command(hid_msg))
{
}
else
// if (custom_command(hid_msg))
// {
//
// }
// else
{
u2f_hid_request(hid_msg);
}
@ -280,7 +280,7 @@ int16_t main(void) {
}
#else
rgb_hex(U2F_DEFAULT_COLOR_ERROR);
//rgb_hex(U2F_DEFAULT_COLOR_ERROR);
#endif
error = 0;
while(!ms_since(ms_heart,500))

Wyświetl plik

@ -211,6 +211,12 @@ static int16_t u2f_register(struct u2f_register_request * req)
const uint16_t attest_size = u2f_attestation_cert_size();
u2f_prints("REG req\r\n");
u2f_prints("chal: ");
dump_hex(req->chal, 32);
u2f_prints("app: ");
dump_hex(req->app, 32);
if (u2f_get_user_feedback())
{
u2f_hid_set_len(2);
@ -223,6 +229,9 @@ static int16_t u2f_register(struct u2f_register_request * req)
return U2F_SW_INSUFFICIENT_MEMORY;
}
u2f_prints("new handle:\r\n");
dump_hex(key_handle, U2F_KEY_HANDLE_SIZE);
u2f_sha256_start();
u2f_sha256_update(i,1);
u2f_sha256_update(req->app,32);
@ -236,6 +245,7 @@ static int16_t u2f_register(struct u2f_register_request * req)
if (u2f_ecdsa_sign((uint8_t*)req, U2F_ATTESTATION_HANDLE) == -1)
{
u2f_prints("FAIL\r\n");
return U2F_SW_WRONG_DATA;
}
@ -251,7 +261,7 @@ static int16_t u2f_register(struct u2f_register_request * req)
dump_signature_der((uint8_t*)req);
u2f_prints("WIN\r\n");
return U2F_SW_NO_ERROR;
}

Wyświetl plik

@ -157,7 +157,6 @@ void u2f_init()
sizeof(appdata.tmp), &res);
if (ec != 0)
{
u2f_printb("atecc_send_recv failed ",2,i,-ec);
// erase eeprom
eeprom_erase(U2F_EEPROM_CONFIG);

Wyświetl plik

@ -378,41 +378,41 @@ static uint8_t hid_u2f_parse(struct u2f_hid_msg* req)
break;
case U2FHID_PING:
if (hid_layer.bytes_buffered == 0)
{
start_buffering(req);
u2f_hid_set_len(U2FHID_LEN(req));
if (hid_layer.bytes_buffered >= U2FHID_LEN(req))
{
u2f_hid_writeback(hid_layer.buffer,hid_layer.bytes_buffered);
u2f_hid_flush();
}
else
{
return 1;
}
}
else
{
if (hid_layer.bytes_buffered + U2FHID_CONT_PAYLOAD_SIZE > BUFFER_SIZE)
{
u2f_hid_writeback(hid_layer.buffer,hid_layer.bytes_buffered);
hid_layer.bytes_buffered = 0;
}
buffer_request(req);
if (hid_layer.bytes_buffered + hid_layer.bytes_written >= hid_layer.req_len)
{
u2f_hid_writeback(hid_layer.buffer,hid_layer.bytes_buffered);
u2f_hid_flush();
}
else
{
return 1;
}
}
//
// if (hid_layer.bytes_buffered == 0)
// {
// start_buffering(req);
// u2f_hid_set_len(U2FHID_LEN(req));
// if (hid_layer.bytes_buffered >= U2FHID_LEN(req))
// {
// u2f_hid_writeback(hid_layer.buffer,hid_layer.bytes_buffered);
// u2f_hid_flush();
// }
// else
// {
// return 1;
// }
// }
// else
// {
// if (hid_layer.bytes_buffered + U2FHID_CONT_PAYLOAD_SIZE > BUFFER_SIZE)
// {
// u2f_hid_writeback(hid_layer.buffer,hid_layer.bytes_buffered);
// hid_layer.bytes_buffered = 0;
//
// }
//
// buffer_request(req);
// if (hid_layer.bytes_buffered + hid_layer.bytes_written >= hid_layer.req_len)
// {
// u2f_hid_writeback(hid_layer.buffer,hid_layer.bytes_buffered);
// u2f_hid_flush();
// }
// else
// {
// return 1;
// }
// }
break;
@ -428,42 +428,42 @@ static uint8_t hid_u2f_parse(struct u2f_hid_msg* req)
u2f_hid_flush();
app_wink(U2F_COLOR_WINK);
break;
case U2FHID_LOCK:
secs = req->pkt.init.payload[0];
if (secs > 10)
{
stamp_error(hid_layer.current_cid, ERR_INVALID_PAR);
}
else
{
if (secs)
{
_hid_lock_cid = hid_layer.current_cid;
_hid_lockt = get_ms() + 1000 * secs;
}
else
{
_hid_lockt = get_ms();
_hid_lock_cid = 0;
}
hid_layer.current_cmd = U2FHID_LOCK;
u2f_hid_set_len(0);
u2f_hid_writeback(NULL, 0);
u2f_hid_flush();
}
break;
// case U2FHID_LOCK:
//
// secs = req->pkt.init.payload[0];
// if (secs > 10)
// {
// stamp_error(hid_layer.current_cid, ERR_INVALID_PAR);
// }
// else
// {
// if (secs)
// {
// _hid_lock_cid = hid_layer.current_cid;
// _hid_lockt = get_ms() + 1000 * secs;
//
// }
// else
// {
// _hid_lockt = get_ms();
// _hid_lock_cid = 0;
// }
// hid_layer.current_cmd = U2FHID_LOCK;
// u2f_hid_set_len(0);
// u2f_hid_writeback(NULL, 0);
// u2f_hid_flush();
// }
// break;
default:
set_app_error(ERROR_HID_INVALID_CMD);
stamp_error(hid_layer.current_cid, ERR_INVALID_CMD);
u2f_printb("invalid cmd: ",1,hid_layer.current_cmd);
//u2f_printb("invalid cmd: ",1,hid_layer.current_cmd);
}
return u2f_hid_busy();
fail:
u2f_prints("U2F HID FAIL\r\n");
//u2f_prints("U2F HID FAIL\r\n");
return 0;
}
@ -474,7 +474,7 @@ void u2f_hid_check_timeouts()
{
if (CIDS[i].busy && ((get_ms() - CIDS[i].last_used) >= 750))
{
u2f_printlx("timeout cid ",2,CIDS[i].cid,get_ms());
//u2f_printlx("timeout cid ",2,CIDS[i].cid,get_ms());
stamp_error(CIDS[i].cid, ERR_MSG_TIMEOUT);
del_cid(CIDS[i].cid);
u2f_hid_reset_packet();