power tests

This commit is contained in:
Conor Patrick 2018-06-04 19:35:34 -04:00
parent e69865384f
commit 45cdc5c54d
12 changed files with 283 additions and 157 deletions

34
convert_log_to_c.py Normal file
View File

@ -0,0 +1,34 @@
import sys
from sys import argv
if len(argv) != 2:
print("usage: %s <input-log>" % argv[0]);
sys.exit(1)
log = open(argv[1]).readlines()
nums = []
for x in log:
parse = []
for i in x.split(' '):
try:
n = int(i,16)
parse.append(n)
except:
pass
if len(parse) == 0:
continue
assert(len(parse) == 64)
nums.append(parse)
hexlines = []
for l in nums:
s = ''
for x in l:
s += '\\x%02x' % x
hexlines.append(s)
for x in hexlines:
print('"'+x+'"')

1
ctap.c
View File

@ -1196,6 +1196,7 @@ done:
} }
printf1(TAG_CTAP,"cbor output structure: %d bytes\n", resp->length); printf1(TAG_CTAP,"cbor output structure: %d bytes\n", resp->length);
return status; return status;
} }

View File

@ -270,12 +270,12 @@ class Tester():
print('PASS: Test not cont') print('PASS: Test not cont')
print('Check random cont ignored') print('Check random cont ignored')
self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88') #self.send_data(CTAPHID.INIT, '\x11\x22\x33\x44\x55\x66\x77\x88')
self.send_raw('\x01\x10\x00') #self.send_raw('\x01\x10\x00')
try: #try:
cmd,r = self.recv_raw() # timeout response #cmd,r = self.recv_raw() # timeout response
except socket.timeout: #except socket.timeout:
pass #pass
print('PASS: random cont') print('PASS: random cont')
print('Check busy') print('Check busy')
@ -330,11 +330,12 @@ class Tester():
print('PASS: busy interleaved') print('PASS: busy interleaved')
#print('Test idle') print('Test idle, wait for timeout')
#try: sys.stdout.flush()
#cmd,resp = self.recv_raw() try:
#except socket.timeout: cmd,resp = self.recv_raw()
#print('Pass: Idle') except socket.timeout:
print('Pass: Idle')
print('Test cid 0 is invalid') print('Test cid 0 is invalid')
self.set_cid('\x00\x00\x00\x00') self.set_cid('\x00\x00\x00\x00')
@ -397,7 +398,7 @@ class Tester():
self.ctap.reset() self.ctap.reset()
for i in range(0,2048): for i in range(0,2048**2):
creds = [] creds = []
print(i) print(i)
@ -552,8 +553,8 @@ if __name__ == '__main__':
t.find_device() t.find_device()
#t.test_hid() #t.test_hid()
#t.test_fido2() #t.test_fido2()
#t.test_fido2_simple() t.test_fido2_simple()
t.test_fido2_brute_force() #t.test_fido2_brute_force()

13
log.c
View File

@ -17,6 +17,7 @@ struct logtag
}; };
struct logtag tagtable[] = { struct logtag tagtable[] = {
{TAG_GEN,""},
{TAG_MC,"MC"}, {TAG_MC,"MC"},
{TAG_GA,"GA"}, {TAG_GA,"GA"},
{TAG_CP,"CP"}, {TAG_CP,"CP"},
@ -26,9 +27,10 @@ struct logtag tagtable[] = {
{TAG_U2F,"U2F"}, {TAG_U2F,"U2F"},
{TAG_DUMP,"DUMP"}, {TAG_DUMP,"DUMP"},
{TAG_HID,"HID"}, {TAG_HID,"HID"},
{TAG_GREEN,"\x1b[32mDEBUG\x1b[0m"}, {TAG_USB,"USB"},
{TAG_RED,"\x1b[31mDEBUG\x1b[0m"}, {TAG_GREEN,"DEBUG"},
{TAG_TIME,"\x1b[33mTIME\x1b[0m"}, {TAG_RED,"DEBUG"},
{TAG_TIME,"TIME"},
}; };
@ -49,14 +51,14 @@ void LOG(uint32_t tag, const char * filename, int num, const char * fmt, ...)
{ {
if (tag & tagtable[i].tagn) if (tag & tagtable[i].tagn)
{ {
printf("[%s] ", tagtable[i].tag); if (tagtable[i].tag[0]) printf("[%s] ", tagtable[i].tag);
i = 0; i = 0;
break; break;
} }
} }
if (i != 0) if (i != 0)
{ {
printf("INVALID LOG TAG\n"); printf2(TAG_ERR,"INVALID LOG TAG\n");
exit(1); exit(1);
} }
set_logging_tag(tag); set_logging_tag(tag);
@ -78,5 +80,6 @@ void LOG_HEX(uint32_t tag, uint8_t * data, int length)
{ {
return; return;
} }
set_logging_tag(tag);
dump_hex(data,length); dump_hex(data,length);
} }

26
log.h
View File

@ -11,18 +11,20 @@ void set_logging_tag(uint32_t tag);
typedef enum typedef enum
{ {
TAG_MC = (1 << 0), TAG_GEN = (1 << 0),
TAG_GA = (1 << 1), TAG_MC = (1 << 1),
TAG_CP = (1 << 2), TAG_GA = (1 << 2),
TAG_ERR = (1 << 3), TAG_CP = (1 << 3),
TAG_PARSE= (1 << 4), TAG_ERR = (1 << 4),
TAG_CTAP = (1 << 5), TAG_PARSE= (1 << 5),
TAG_U2F = (1 << 6), TAG_CTAP = (1 << 6),
TAG_DUMP = (1 << 7), TAG_U2F = (1 << 7),
TAG_GREEN = (1 << 8), TAG_DUMP = (1 << 8),
TAG_RED= (1 << 9), TAG_GREEN = (1 << 9),
TAG_TIME= (1 << 10), TAG_RED= (1 << 10),
TAG_HID = (1 << 11), TAG_TIME= (1 << 11),
TAG_HID = (1 << 12),
TAG_USB = (1 << 13),
TAG_FILENO = (1<<31) TAG_FILENO = (1<<31)
} LOG_TAG; } LOG_TAG;

161
main.c
View File

@ -5,12 +5,13 @@
#include "cbor.h" #include "cbor.h"
#include "device.h" #include "device.h"
#include "ctaphid.h" #include "ctaphid.h"
#include "bsp.h"
#include "util.h" #include "util.h"
#include "log.h" #include "log.h"
#include "ctap.h" #include "ctap.h"
#ifndef TEST #if !defined(TEST) && !defined(TEST_POWER)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
@ -21,31 +22,35 @@ int main(int argc, char * argv[])
uint8_t hidmsg[64]; uint8_t hidmsg[64];
set_logging_mask( set_logging_mask(
/*0*/
/*TAG_GEN|*/
/*TAG_MC |*/ /*TAG_MC |*/
/*TAG_GA |*/ /*TAG_GA |*/
/*TAG_CP |*/ /*TAG_CP |*/
/*TAG_CTAP|*/ TAG_CTAP|
/*TAG_HID|*/
/*TAG_U2F|*/ /*TAG_U2F|*/
/*TAG_PARSE |*/ /*TAG_PARSE |*/
/*TAG_TIME|*/ /*TAG_TIME|*/
/*TAG_DUMP|*/ TAG_DUMP|
/*TAG_GREEN|*/ /*TAG_GREEN|*/
/*TAG_RED|*/ /*TAG_RED|*/
TAG_ERR TAG_ERR
); );
printf("init device\n"); printf1(TAG_GEN,"init device\n");
device_init(); device_init();
printf("init ctaphid\n"); printf1(TAG_GEN,"init ctaphid\n");
ctaphid_init(); ctaphid_init();
printf("init ctap\n"); printf1(TAG_GEN,"init ctap\n");
ctap_init(); ctap_init();
memset(hidmsg,0,sizeof(hidmsg)); memset(hidmsg,0,sizeof(hidmsg));
printf("recv'ing hid msg \n"); printf1(TAG_GEN,"recv'ing hid msg \n");
while(1) while(1)
{ {
@ -79,3 +84,145 @@ int main(int argc, char * argv[])
} }
#endif #endif
#ifdef TEST_POWER
#define BUTT NRF_GPIO_PIN_MAP(0,11)
#define TRIG NRF_GPIO_PIN_MAP(0,30)
int main(int argc, char * argv[])
{
int count = 0;
uint64_t t1 = 0;
uint64_t t2 = 0;
uint64_t accum = 0;
uint8_t hidmsg[64];
set_logging_mask(
0
/*TAG_GEN|*/
/*TAG_MC |*/
/*TAG_GA |*/
/*TAG_CP |*/
/*TAG_CTAP|*/
/*TAG_HID|*/
/*TAG_U2F|*/
/*TAG_PARSE |*/
/*TAG_TIME|*/
/*TAG_DUMP|*/
/*TAG_GREEN|*/
/*TAG_RED|*/
/*TAG_ERR*/
);
device_init();
ctaphid_init();
ctap_init();
nrf_gpio_cfg_input(BUTT, NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_output(TRIG);
nrf_gpio_pin_clear(TRIG);
memset(hidmsg,0,sizeof(hidmsg));
printf1(TAG_GEN,"recv'ing hid msg \n");
while(1)
{
if (millis() - t1 > 100)
{
/*printf("heartbeat %ld\n", beat++);*/
heartbeat();
t1 = millis();
}
if (usbhid_recv(hidmsg) > 0)
{
printf1(TAG_DUMP,"%d>> ",count++); dump_hex1(TAG_DUMP, hidmsg,sizeof(hidmsg));
t2 = millis();
ctaphid_handle_packet(hidmsg);
accum += millis() - t2;
printf1(TAG_TIME,"accum: %lu\n", (uint32_t)accum);
memset(hidmsg, 0, sizeof(hidmsg));
}
else
{
/*main_loop_delay();*/
}
ctaphid_check_timeouts();
}
// Should never get here
usbhid_close();
printf("done\n");
return 0;
}
void delay(int ms)
{
uint64_t t1;
t1 = millis();
while(millis()-t1 < ms)
;
}
void ctaphid_write_block(uint8_t * data)
{
// Don't actually use usb
/*usbhid_send(data);*/
}
uint8_t hidcmds[][64] = {"\x03\x00\x00\x00\x86\x00\x08\x2d\x73\x95\x80\x2e\xbb\x44\x8d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x03\x00\x00\x00\x90\x00\x01\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x03\x00\x00\x00\x90\x00\x75\x01\xa5\x01\x58\x20\xe5\x64\xed\x22\x01\xda\x3c\x2d\xab\x85\x3c\x1d\x04\x62\x67\x8a\x40\xaa\x1c\x3f\x31\x22\x21\x23\x35\xd5\xf8\xe4\x26\xc8\xd1\xa0\x02\xa2\x62\x69\x64\x6b\x65\x78\x61\x6d\x70\x6c\x6f\x2e\x6f\x72\x67\x64\x6e\x61",
"\x03\x00\x00\x00\x00\x6d\x65\x65\x45\x78\x61\x52\x50\x03\xa2\x62\x69\x64\x47\x75\x73\x65\x65\x5f\x6f\x64\x64\x6e\x61\x6d\x65\x67\x41\x42\x20\x55\x73\x65\x72\x04\x81\xa2\x63\x61\x6c\x67\x26\x64\x74\x79\x70\x65\x6a\x70\x75\x62\x6c\x69\x63\x2d\x6b\x65\x79\x05",
"\x03\x00\x00\x00\x01\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x03\x00\x00\x00\x90\x00\x01\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x03\x00\x00\x00\x90\x00\xf2\x02\xa3\x01\x6b\x65\x78\x61\x6d\x70\x6c\x6f\x2e\x6f\x72\x67\x02\x58\x20\xc4\x74\xef\xcd\xb3\xf9\x61\x18\xdd\xfb\x2f\xe5\x7b\x05\xd2\xf1\x23\xba\x20\x7c\x87\xea\x9e\xfd\x07\xa3\xe3\x21\xdc\x60\x9f\x63\x03\x81\xa2\x62\x69\x64\x58",
"\x03\x00\x00\x00\x00\xa8\x6a\x7e\x7b\xe7\x95\x63\xb1\x38\x2e\x2f\x03\xd6\x6c\xf5\xa3\xa9\x00\x00\x00\x00\x00\x00\x00\x00\x08\x24\x17\x4e\x23\xfd\x17\x7f\xb3\x18\x7c\x74\xe0\xbe\x35\x35\x94\x02\x7f\x61\xe3\x1c\xae\x73\xb4\x02\x7f\xf6\x7e\xc1\x36\x43\x2b\xc2",
"\x03\x00\x00\x00\x01\x60\xdd\xb8\x0b\x4a\xbb\x6f\x61\xac\xc3\xc6\x37\x9d\x33\x71\xe3\xcf\xa2\x4f\x5c\x11\x97\x44\xf8\x87\xb0\xd2\x67\xe8\x9a\xeb\x61\x39\x29\x61\xbf\xf7\xd1\xe1\xa9\x79\x26\x4a\x1a\xe7\x26\x60\xa4\x3d\x9f\x5c\xfe\x57\xbc\x4a\x74\x71\xf5\x67",
"\x03\x00\x00\x00\x02\xdd\x8d\x40\x49\x1e\x2d\x28\x15\x18\xbd\xf2\xe2\xef\x61\xbc\xb6\x04\x6f\x51\xdb\xe6\xc6\xd0\x9f\xbb\x06\xae\xac\xe4\xf6\xbd\x05\x85\xd3\x31\x5b\x98\x75\x2a\x4a\x31\xea\x5d\xc8\x78\x15\xee\xbe\x56\x0b\x43\x64\x74\x79\x70\x65\x6a\x70\x75",
"\x03\x00\x00\x00\x03\x62\x6c\x69\x63\x2d\x6b\x65\x79\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"};
int usbhid_recv(uint8_t * msg)
{
static int lastval = 0;
static int reading = 0;
int val;
// button1 == p0.11
// button2 == p0.12
// button3 == p0.24
// button4 == p0.25
if (!reading)
{
delay(1);
nrf_gpio_pin_clear(TRIG);
val = nrf_gpio_pin_read(BUTT);
if (val == 0)
{
if (lastval != 0)
{
printf1(TAG_GEN, "button!\n");
/*printf1(TAG_GEN,"size of array: %d elements", sizeof(hidcmds)/64);*/
reading = 1;
}
}
lastval = val;
}
else
{
nrf_gpio_pin_set(TRIG);
memmove(msg, hidcmds[reading-1], 64);
reading++;
if (reading-1 == sizeof(hidcmds)/64)
{
reading = 0;
}
return 64;
}
return 0;
}
#endif

View File

@ -76,9 +76,6 @@ SRC_FILES += \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \ $(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(SDK_ROOT)/components/libraries/bsp/bsp_cli.c \ $(SDK_ROOT)/components/libraries/bsp/bsp_cli.c \
\ \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_hw/nrf_hw_backend_init.c \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_hw/nrf_hw_backend_rng.c \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_hw/nrf_hw_backend_rng_mbedtls.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/blockwise.c \ $(SDK_ROOT)/external/cifra_AES128-EAX/blockwise.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/cifra_cmac.c \ $(SDK_ROOT)/external/cifra_AES128-EAX/cifra_cmac.c \
$(SDK_ROOT)/external/cifra_AES128-EAX/cifra_eax_aes.c \ $(SDK_ROOT)/external/cifra_AES128-EAX/cifra_eax_aes.c \
@ -88,38 +85,9 @@ SRC_FILES += \
$(SDK_ROOT)/external/cifra_AES128-EAX/modes.c \ $(SDK_ROOT)/external/cifra_AES128-EAX/modes.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \ $(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \ $(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
$(SDK_ROOT)/components/libraries/crypto/backend/micro_ecc/micro_ecc_backend_ecc.c \
$(SDK_ROOT)/components/libraries/crypto/backend/micro_ecc/micro_ecc_backend_ecdh.c \
$(SDK_ROOT)/components/libraries/crypto/backend/micro_ecc/micro_ecc_backend_ecdsa.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_rng.c \ $(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_rng.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \ $(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rng.c \ $(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rng.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cifra/cifra_backend_aes_aead.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_aead.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_aes.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_aes_shared.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_ecc.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_ecdh.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_ecdsa.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_error.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_hash.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_hkdf.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_hmac.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_init.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_rng.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_shared.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_aes.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_aes_aead.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_chacha_poly_aead.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_ecc.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_ecdh.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_ecdsa.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_hash.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_hmac.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_init.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_mutex.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_rng.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_shared.c \
@ -193,8 +161,6 @@ INC_FOLDERS += \
$(SDK_ROOT)/modules/nrfx/hal \ $(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/external/fprintf \ $(SDK_ROOT)/external/fprintf \
\ \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310 \
$(SDK_ROOT)/components/libraries/crypto/backend/cifra \
$(SDK_ROOT)/external/fprintf \ $(SDK_ROOT)/external/fprintf \
$(PROJ_DIR) \ $(PROJ_DIR) \
$(SDK_ROOT)/components/libraries/experimental_section_vars \ $(SDK_ROOT)/components/libraries/experimental_section_vars \
@ -209,7 +175,6 @@ INC_FOLDERS += \
$(SDK_ROOT)/components/libraries/mem_manager \ $(SDK_ROOT)/components/libraries/mem_manager \
$(SDK_ROOT)/external/nrf_oberon \ $(SDK_ROOT)/external/nrf_oberon \
$(SDK_ROOT)/components/libraries/atomic \ $(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_sw \
$(SDK_ROOT)/components/libraries/strerror \ $(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/integration/nrfx \ $(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/modules/nrfx/drivers/include \ $(SDK_ROOT)/modules/nrfx/drivers/include \
@ -218,22 +183,15 @@ INC_FOLDERS += \
$(SDK_ROOT)/components/libraries/util \ $(SDK_ROOT)/components/libraries/util \
$(SDK_ROOT)/modules/nrfx \ $(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \ $(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/external/micro-ecc/micro-ecc \
$(SDK_ROOT)/external/segger_rtt \ $(SDK_ROOT)/external/segger_rtt \
$(SDK_ROOT)/modules/nrfx/mdk \ $(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/modules/nrfx/hal \ $(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/libraries/mutex \ $(SDK_ROOT)/components/libraries/mutex \
$(SDK_ROOT)/components/libraries/crypto/backend/micro_ecc \
$(SDK_ROOT)/components/libraries/crypto/backend/mbedtls \
$(SDK_ROOT)/components/libraries/queue \ $(SDK_ROOT)/components/libraries/queue \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_hw \
$(SDK_ROOT)/integration/nrfx/legacy \ $(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/external/cifra_AES128-EAX \ $(SDK_ROOT)/external/cifra_AES128-EAX \
$(SDK_ROOT)/external/nrf_tls/mbedtls/nrf_crypto/config \
$(SDK_ROOT)/components/boards \ $(SDK_ROOT)/components/boards \
$(SDK_ROOT)/external/nrf_cc310/include \ $(SDK_ROOT)/external/nrf_cc310/include \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310_bl \
$(SDK_ROOT)/components/libraries/crypto/backend/oberon \
# Libraries common to all targets # Libraries common to all targets
@ -256,6 +214,7 @@ CFLAGS += -DNRF52840_XXAA
#CFLAGS += -DSTUB_CTAPHID #CFLAGS += -DSTUB_CTAPHID
#CFLAGS += -DSTUB_CTAP #CFLAGS += -DSTUB_CTAP
CFLAGS += -DuECC_PLATFORM=5 CFLAGS += -DuECC_PLATFORM=5
CFLAGS += -DTEST_POWER
CFLAGS += -std=gnu11 CFLAGS += -std=gnu11
CFLAGS += -mcpu=cortex-m4 CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs CFLAGS += -mthumb -mabi=aapcs

View File

@ -6,22 +6,22 @@
// <i> or this value is actually used. It depends on which one is bigger. // <i> or this value is actually used. It depends on which one is bigger.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP #ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_UP
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 64 #define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 4096
#endif #endif
// <o> SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS - Size of upstream buffer. // <o> SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS #ifndef SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 8 #define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 16
#endif #endif
// <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN - Size of upstream buffer. // <o> SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN #ifndef SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 64 #define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 8
#endif #endif
// <o> SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS - Size of upstream buffer. // <o> SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS - Size of upstream buffer.
#ifndef SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS #ifndef SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS
#define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 8 #define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2
#endif #endif
// <o> SEGGER_RTT_CONFIG_DEFAULT_MODE - RTT behavior if the buffer is full. // <o> SEGGER_RTT_CONFIG_DEFAULT_MODE - RTT behavior if the buffer is full.
@ -36,9 +36,9 @@
// <2=> BLOCK_IF_FIFO_FULL // <2=> BLOCK_IF_FIFO_FULL
#ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE #ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 2 #define SEGGER_RTT_CONFIG_DEFAULT_MODE 1
#define APP_FIFO_ENABLED 1 #define APP_FIFO_ENABLED 2
#endif #endif

View File

@ -179,40 +179,6 @@ void crypto_ecc256_init()
ret = SaSi_LibInit(); ret = SaSi_LibInit();
if (ret != SA_SILIB_RET_OK) { if (ret != SA_SILIB_RET_OK) {
printf("Failed SaSi_LibInit - ret = 0x%x\n", ret); printf("Failed SaSi_LibInit - ret = 0x%x\n", ret);
/*switch(ret)*/
/*{*/
/*case SA_SILIB_RET_OK:*/
/*printf("SA_SILIB_RET_OK\n");*/
/*break;*/
/*case SA_SILIB_RET_EINVAL_CTX_PTR:*/
/*printf("SA_SILIB_RET_EINVAL_CTX_PTR\n");*/
/*break;*/
/*case SA_SILIB_RET_EINVAL_WORK_BUF_PTR:*/
/*printf("SA_SILIB_RET_EINVAL_WORK_BUF_PTR\n");*/
/*break;*/
/*case SA_SILIB_RET_HAL:*/
/*printf("SA_SILIB_RET_HAL\n");*/
/*break;*/
/*case SA_SILIB_RET_PAL:*/
/*printf("SA_SILIB_RET_PAL\n");*/
/*break;*/
/*case SA_SILIB_RET_EINVAL_HW_VERSION :*/
/*printf("SA_SILIB_RET_EINVAL_HW_VERSION \n");*/
/*break;*/
/*case SA_SILIB_RET_EINVAL_HW_SIGNATURE:*/
/*printf("SA_SILIB_RET_EINVAL_HW_SIGNATURE\n");*/
/*break;*/
/*case SA_SILIB_RESERVE32B:*/
/*printf("SA_SILIB_RESERVE32B\n");*/
/*break;*/
/*}*/
exit(1); exit(1);
} }
@ -223,8 +189,7 @@ void crypto_ecc256_init()
ret = CRYS_RndInit(&rndState_ptr, &rndWorkBuff_ptr); ret = CRYS_RndInit(&rndState_ptr, &rndWorkBuff_ptr);
if (ret != SA_SILIB_RET_OK) { if (ret != SA_SILIB_RET_OK) {
printf("Failed CRYS_RndInit - ret = 0x%x\n", ret); printf("Failed CRYS_RndInit - ret = 0x%x\n", ret);
while(1) exit(1);
;
} }
_es256_curve = CRYS_ECPKI_GetEcDomain(CRYS_ECPKI_DomainID_secp256r1); _es256_curve = CRYS_ECPKI_GetEcDomain(CRYS_ECPKI_DomainID_secp256r1);
@ -374,7 +339,7 @@ void derive_private_key_pair(uint8_t * data, int len, uint8_t * data2, int len2,
break; break;
} }
// There isn't a CC310 function for calculating a public key from a private // There isn't a CC310 function for calculating a public key from a private,
// so to get around it, we can "fix" the RNG input to GenKeyPair // so to get around it, we can "fix" the RNG input to GenKeyPair
if(pubkey != NULL) if(pubkey != NULL)

View File

@ -168,17 +168,21 @@ app_fifo_t USBHID_RECV_FIFO;
void usbhid_init() void usbhid_init()
{ {
#ifndef TEST_POWER
app_fifo_init(&USBHID_RECV_FIFO, fifo_buf, sizeof(fifo_buf)); app_fifo_init(&USBHID_RECV_FIFO, fifo_buf, sizeof(fifo_buf));
usb_init(); usb_init();
#endif
} }
// Receive 64 byte USB HID message, don't block, return size of packet, return 0 if nothing // Receive 64 byte USB HID message, don't block, return size of packet, return 0 if nothing
#ifndef TEST_POWER
int usbhid_recv(uint8_t * msg) int usbhid_recv(uint8_t * msg)
{ {
uint32_t size = 64; uint32_t size = 64;
app_fifo_read(&USBHID_RECV_FIFO, msg, &size); app_fifo_read(&USBHID_RECV_FIFO, msg, &size);
return size; return size;
} }
#endif
// Send 64 byte USB HID message // Send 64 byte USB HID message
@ -212,12 +216,13 @@ void heartbeat()
nrf_gpio_pin_toggle(LED_4); nrf_gpio_pin_toggle(LED_4);
} }
#ifndef TEST_POWER
void ctaphid_write_block(uint8_t * data) void ctaphid_write_block(uint8_t * data)
{ {
printf1(TAG_DUMP,"<< "); dump_hex1(TAG_DUMP,data, 64); printf1(TAG_DUMP,"<< "); dump_hex1(TAG_DUMP,data, 64);
usbhid_send(data); usbhid_send(data);
} }
#endif
int ctap_user_presence_test() int ctap_user_presence_test()

View File

@ -13,6 +13,8 @@ void set_logging_tag(uint32_t tag)
term++; term++;
tag = tag >> 1; tag = tag >> 1;
} }
_SEGGER_TERM = term;
} }
#if defined(__CC_ARM) #if defined(__CC_ARM)
@ -44,12 +46,23 @@ int __putchar(int ch, FILE * p_file)
int _write(int file, const char * p_char, int len) int _write(int file, const char * p_char, int len)
{ {
int i; int i;
static int lastterm = -1;
/*char buf[2];*/
/*buf[1] = 0;*/
UNUSED_PARAMETER(file); UNUSED_PARAMETER(file);
if (_SEGGER_TERM != lastterm)
{
SEGGER_RTT_SetTerminal(_SEGGER_TERM);
lastterm = _SEGGER_TERM;
}
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
SEGGER_RTT_PutChar(_SEGGER_TERM, *p_char++); /*buf[0] = *p_char++;*/
SEGGER_RTT_PutChar(0, *p_char++);
/*SEGGER_RTT_TerminalOut(_SEGGER_TERM, buf);*/
} }
return len; return len;
@ -58,11 +71,6 @@ int _write(int file, const char * p_char, int len)
int _read(int file, char * p_char, int len) int _read(int file, char * p_char, int len)
{ {
*p_char = '0'; *p_char = '0';
/*UNUSED_PARAMETER(file);*/
/*while (app_uart_get((uint8_t *)p_char) == NRF_ERROR_NOT_FOUND)*/
/*{*/
/*// No implementation needed.*/
/*}*/
return 1; return 1;
} }

View File

@ -58,6 +58,7 @@
#include "nrf_cli.h" #include "nrf_cli.h"
#include "util.h" #include "util.h"
#include "log.h"
#include "usb.h" #include "usb.h"
#define BTN_DATA_SEND 0 #define BTN_DATA_SEND 0
@ -448,7 +449,7 @@ static void respond_setup_data(
ret = nrf_drv_usbd_ep_transfer(NRF_DRV_USBD_EPIN0, &transfer); ret = nrf_drv_usbd_ep_transfer(NRF_DRV_USBD_EPIN0, &transfer);
if (ret != NRF_SUCCESS) if (ret != NRF_SUCCESS)
{ {
printf("Transfer starting failed: %lu", (uint32_t)ret); printf1(TAG_USB,"Transfer starting failed: %lu", (uint32_t)ret);
} }
ASSERT(ret == NRF_SUCCESS); ASSERT(ret == NRF_SUCCESS);
UNUSED_VARIABLE(ret); UNUSED_VARIABLE(ret);
@ -538,7 +539,7 @@ static void usbd_setup_GetStatus(nrf_drv_usbd_setup_t const * const p_setup)
default: default:
break; // Just go to stall break; // Just go to stall
} }
printf("Unknown status: 0x%2x", p_setup->bmRequestType); printf1(TAG_USB,"Unknown status: 0x%2x", p_setup->bmRequestType);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
@ -568,7 +569,7 @@ static void usbd_setup_ClearFeature(nrf_drv_usbd_setup_t const * const p_setup)
} }
} }
} }
printf("Unknown feature to clear"); printf1(TAG_USB,"Unknown feature to clear");
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
@ -598,7 +599,7 @@ static void usbd_setup_SetFeature(nrf_drv_usbd_setup_t const * const p_setup)
} }
} }
} }
printf("Unknown feature to set"); printf1(TAG_USB, "Unknown feature to set");
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
@ -673,7 +674,7 @@ static void usbd_setup_GetDescriptor(nrf_drv_usbd_setup_t const * const p_setup)
if ((p_setup->bmRequestType) == 0x80) if ((p_setup->bmRequestType) == 0x80)
{ {
// Which endpoint? // Which endpoint?
printf("endpoint descriptor: %d\n", ((p_setup->wValue) & 0xFF)); printf1(TAG_USB,"endpoint descriptor: %d\n", ((p_setup->wValue) & 0xFF));
if (((p_setup->wValue) & 0xFF) == 1) if (((p_setup->wValue) & 0xFF) == 1)
{ {
respond_setup_data( respond_setup_data(
@ -725,7 +726,7 @@ static void usbd_setup_GetDescriptor(nrf_drv_usbd_setup_t const * const p_setup)
break; // Not supported - go to stall break; // Not supported - go to stall
} }
printf("Unknown : 0x%02x, type: 0x%02x or value: 0x%02x\n", printf1(TAG_USB,"Unknown : 0x%02x, type: 0x%02x or value: 0x%02x\n",
p_setup->wValue >> 8, p_setup->wValue >> 8,
p_setup->bmRequestType, p_setup->bmRequestType,
p_setup->wValue & 0xFF); p_setup->wValue & 0xFF);
@ -765,7 +766,7 @@ static void usbd_setup_SetConfig(nrf_drv_usbd_setup_t const * const p_setup)
} }
} }
} }
printf("Wrong configuration: Index: 0x%2x, Value: 0x%2x.", printf1(TAG_USB,"Wrong configuration: Index: 0x%2x, Value: 0x%2x.",
p_setup->wIndex, p_setup->wIndex,
p_setup->wValue); p_setup->wValue);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
@ -779,7 +780,7 @@ static void usbd_setup_SetIdle(nrf_drv_usbd_setup_t const * const p_setup)
nrf_drv_usbd_setup_clear(); nrf_drv_usbd_setup_clear();
return; return;
} }
printf("Set Idle wrong type: 0x%2x.", p_setup->bmRequestType); printf1(TAG_USB,"Set Idle wrong type: 0x%2x.", p_setup->bmRequestType);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
@ -787,7 +788,7 @@ static void usbd_setup_SetInterface(
nrf_drv_usbd_setup_t const * const p_setup) nrf_drv_usbd_setup_t const * const p_setup)
{ {
//no alternate setting is supported - STALL always //no alternate setting is supported - STALL always
printf("No alternate interfaces supported."); printf1(TAG_USB,"No alternate interfaces supported.");
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
@ -800,7 +801,7 @@ static void usbd_setup_SetProtocol(
nrf_drv_usbd_setup_clear(); nrf_drv_usbd_setup_clear();
return; return;
} }
printf("Set Protocol wrong type: 0x%2x.", p_setup->bmRequestType); printf1(TAG_USB,"Set Protocol wrong type: 0x%2x.", p_setup->bmRequestType);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
@ -818,15 +819,15 @@ static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
switch (p_event->type) switch (p_event->type)
{ {
case NRF_DRV_USBD_EVT_SUSPEND: case NRF_DRV_USBD_EVT_SUSPEND:
printf("SUSPEND state detected\n"); printf1(TAG_USB,"SUSPEND state detected\n");
m_usbd_suspend_state_req = true; m_usbd_suspend_state_req = true;
break; break;
case NRF_DRV_USBD_EVT_RESUME: case NRF_DRV_USBD_EVT_RESUME:
printf("RESUMING from suspend\n"); printf1(TAG_USB,"RESUMING from suspend\n");
m_usbd_suspend_state_req = false; m_usbd_suspend_state_req = false;
break; break;
case NRF_DRV_USBD_EVT_WUREQ: case NRF_DRV_USBD_EVT_WUREQ:
printf("RemoteWU initiated\n"); printf1(TAG_USB,"RemoteWU initiated\n");
m_usbd_suspend_state_req = false; m_usbd_suspend_state_req = false;
break; break;
case NRF_DRV_USBD_EVT_RESET: case NRF_DRV_USBD_EVT_RESET:
@ -859,7 +860,7 @@ static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
app_fifo_write(&USBHID_RECV_FIFO, buf, &size); app_fifo_write(&USBHID_RECV_FIFO, buf, &size);
if (size != 64) if (size != 64)
{ {
printf("Error, USB FIFO is full\n"); printf2(TAG_ERR,"Error, USB FIFO is full\n");
APP_ERROR_CHECK(NRF_ERROR_NO_MEM); APP_ERROR_CHECK(NRF_ERROR_NO_MEM);
} }
break; break;
@ -869,16 +870,16 @@ static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
transfer.size = nrf_drv_usbd_epout_size_get(NRF_DRV_USBD_EPOUT1);; transfer.size = nrf_drv_usbd_epout_size_get(NRF_DRV_USBD_EPOUT1);;
if (transfer.size > 64) if (transfer.size > 64)
{ {
printf("Error, invalid transfer size\n"); printf2(TAG_ERR,"Error, invalid transfer size\n");
return; return;
} }
nrf_drv_usbd_ep_transfer(NRF_DRV_USBD_EPOUT1, &transfer); nrf_drv_usbd_ep_transfer(NRF_DRV_USBD_EPOUT1, &transfer);
break; break;
case NRF_USBD_EP_OVERLOAD: case NRF_USBD_EP_OVERLOAD:
printf("NRF_USBD_EP_OVERLOAD\n"); printf1(TAG_ERR,"NRF_USBD_EP_OVERLOAD\n");
break; break;
case NRF_USBD_EP_ABORTED: case NRF_USBD_EP_ABORTED:
printf("NRF_USBD_EP_ABORTED\n"); printf1(TAG_ERR,"NRF_USBD_EP_ABORTED\n");
break; break;
default: default:
break; break;
@ -898,11 +899,11 @@ static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
else if (NRF_USBD_EP_ABORTED == p_event->data.eptransfer.status) else if (NRF_USBD_EP_ABORTED == p_event->data.eptransfer.status)
{ {
/* Just ignore */ /* Just ignore */
printf("Transfer aborted event on EPIN0\n"); printf1(TAG_USB,"Transfer aborted event on EPIN0\n");
} }
else else
{ {
printf("Transfer failed on EPIN0: %d", p_event->data.eptransfer.status); printf1(TAG_USB,"Transfer failed on EPIN0: %d", p_event->data.eptransfer.status);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
} }
@ -923,11 +924,11 @@ static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
else if (NRF_USBD_EP_ABORTED == p_event->data.eptransfer.status) else if (NRF_USBD_EP_ABORTED == p_event->data.eptransfer.status)
{ {
/* Just ignore */ /* Just ignore */
printf("Transfer aborted event on EPOUT0\n"); printf1(TAG_USB,"Transfer aborted event on EPOUT0\n");
} }
else else
{ {
printf("Transfer failed on EPOUT0: %d", p_event->data.eptransfer.status); printf1(TAG_USB,"Transfer failed on EPOUT0: %d", p_event->data.eptransfer.status);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
} }
@ -979,19 +980,19 @@ static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
} }
else else
{ {
printf("Command 0xB. Unknown request: 0x%2x", setup.bmRequestType); printf1(TAG_USB,"Command 0xB. Unknown request: 0x%2x", setup.bmRequestType);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
} }
break; break;
default: default:
printf("Unknown request: 0x%2x", setup.bmRequest); printf1(TAG_USB,"Unknown request: 0x%2x", setup.bmRequest);
nrf_drv_usbd_setup_stall(); nrf_drv_usbd_setup_stall();
return; return;
} }
break; break;
} }
default: default:
printf("unknown usb event\n"); printf1(TAG_USB,"unknown usb event\n");
break; break;
} }
} }
@ -1003,14 +1004,14 @@ static void power_usb_event_handler(nrf_drv_power_usb_evt_t event)
switch (event) switch (event)
{ {
case NRF_DRV_POWER_USB_EVT_DETECTED: case NRF_DRV_POWER_USB_EVT_DETECTED:
printf("USB power detected\n"); printf1(TAG_USB,"USB power detected\n");
if (!nrf_drv_usbd_is_enabled()) if (!nrf_drv_usbd_is_enabled())
{ {
nrf_drv_usbd_enable(); nrf_drv_usbd_enable();
} }
break; break;
case NRF_DRV_POWER_USB_EVT_REMOVED: case NRF_DRV_POWER_USB_EVT_REMOVED:
printf("USB power removed\n"); printf1(TAG_USB,"USB power removed\n");
m_usbd_configured = false; m_usbd_configured = false;
m_send_mouse_position = false; m_send_mouse_position = false;
if (nrf_drv_usbd_is_started()) if (nrf_drv_usbd_is_started())
@ -1026,7 +1027,7 @@ static void power_usb_event_handler(nrf_drv_power_usb_evt_t event)
bsp_board_led_off(LED_USB_POWER); bsp_board_led_off(LED_USB_POWER);
break; break;
case NRF_DRV_POWER_USB_EVT_READY: case NRF_DRV_POWER_USB_EVT_READY:
printf("USB ready\n"); printf1(TAG_USB,"USB ready\n");
bsp_board_led_on(LED_USB_POWER); bsp_board_led_on(LED_USB_POWER);
if (!nrf_drv_usbd_is_started()) if (!nrf_drv_usbd_is_started())
{ {