From f7e26ae952f05742b89c6bd58d50d0bb59e0ce46 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 14 Jan 2011 15:47:15 +0900 Subject: [PATCH] version 0.6 --- AUTHORS | 6 +++ ChangeLog | 19 +++++++++ NEWS | 25 ++++++++++++ README | 9 ++++- boards/STBEE_MINI/board.h | 4 ++ boards/STM8S_DISCOVERY/board.c | 70 ++++++++++++++++++++++++++++++++++ boards/STM8S_DISCOVERY/board.h | 12 ++++++ src/pin-cir.c | 4 ++ src/usb_prop.c | 19 ++++----- 9 files changed, 158 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 6115e69..04c16ef 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,6 +7,11 @@ Kaz Kojima: NIIBE Yutaka: Founder of the project. + Added STM8S Discovery Kit support: + boards/STM8S_DISCOVERY/board.c + boards/STM8S_DISCOVERY/board.h + boards/STM8S_DISCOVERY/board.mk + boards/STM8S_DISCOVERY/mcuconf.mk Added STBee Mini support: boards/STBEE_MINI/board.c boards/STBEE_MINI/board.h @@ -39,5 +44,6 @@ NIIBE Yutaka: src/openpgp.c src/call-rsa.c src/random.c + src/pin-cir.c * and others. diff --git a/ChangeLog b/ChangeLog index 6841f47..7a89245 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2011-01-14 NIIBE Yutaka + + * Version 0.6. + + * src/usb_prop.c (gnukStringSerial): Include version number (again). + + * boards/STM8S_DISCOVERY/board.c (hwinit1): Initialize TIM3 and + remap TIM3. + (cir_ext_disable, cir_ext_enable, EXTI9_5_IRQHandler) + (TIM3_IRQHandler): New. + + * boards/STBEE_MINI/board.h (HAVE_7SEGLED): New. + + * boards/STM8S_DISCOVERY/board.h: Include "config.h". + (VAL_GPIOBODR): PB0 (TIM3_CH3) is pull-down for PINPAD_SUPPORT. + + * src/pin-cir.c (pindisp): Handle the board with no 7 segment + display. + 2011-01-11 NIIBE Yutaka * src/openpgp-do.c (do_openpgpcard_aid): Fix length of res_p; diff --git a/NEWS b/NEWS index 9eb67d5..55a763e 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,30 @@ Gnuk NEWS - User visible changes +* Major changes in Gnuk 0.6 + + Released 2011-01-14, by NIIBE Yutaka + +** Experimental PIN-pad support is added. +Local PIN-pad input is suppored for boards which have input hardware. +PIN input using consumer IR receive module is tested with STBee Mini +and STM8S Discovery. + +** USB device serial number is virtually unique now. +STM32F103 has 96-bit unique chip identifier. We take advantage of +this, Gnuk Token has virtually unique USB serial number. + +** Card serial number is determined at run time by chip identifier. +Until version 0.5, card serial number was compile time option. If we +used same binary for different devices, card serial number was same. +Now, we use STM32F103's 96-bit unique chip identifier for card serial +number (when you don't use --with-fixed-serial option). + +** More improved USB-CCID/ICCD implementation. +The changes in 0.5 was not that good for libccid 1.3.11, which has +small buffer (only 262-byte APDU). Workaround for libccid 1.3.11 is +implemented. + + * Major changes in Gnuk 0.5 Released 2010-12-13, by NIIBE Yutaka diff --git a/README b/README index 5a47154..f37f1af 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ Gnuk - software for GPG USB Token Version 0.6 - 2011-01-XX + 2011-01-14 Niibe Yutaka Free Software Initiative of Japan @@ -84,6 +84,13 @@ read protect using JTAG debugger. I think that it could run on Olimex STM32-P103, or STBee too. Besides, we are porting it to STM32 Primer 2. +For PIN-pad support, I connect a consumer IR receive module to STBee +Mini and STM8S Discovery Kit, and use controller for TV. Yes, it is +not secure totally, since it is very easy to monitor IR output of the +controllers. It is experiment, and hardware needed for this +experiment is only a consumer IR receive module which is as cheap as +50 JPY. + Souce code ========== diff --git a/boards/STBEE_MINI/board.h b/boards/STBEE_MINI/board.h index ce3b501..7853a0b 100644 --- a/boards/STBEE_MINI/board.h +++ b/boards/STBEE_MINI/board.h @@ -39,6 +39,10 @@ #define BOARD_NAME "STBee Mini" #define CPU_WITH_NO_GPIOE 1 +#if defined(PINPAD_SUPPORT) +#define HAVE_7SEGLED 1 +#endif + /* * Board frequencies. */ diff --git a/boards/STM8S_DISCOVERY/board.c b/boards/STM8S_DISCOVERY/board.c index 62edafc..88f4032 100644 --- a/boards/STM8S_DISCOVERY/board.c +++ b/boards/STM8S_DISCOVERY/board.c @@ -14,6 +14,36 @@ void hwinit1 (void) { hwinit1_common (); + +#if defined(PINPAD_SUPPORT) + /* EXTI5 <= PB5 */ + AFIO->EXTICR[1] = AFIO_EXTICR2_EXTI5_PB; + EXTI->IMR = 0; + EXTI->FTSR = EXTI_FTSR_TR5; + NVICEnableVector(EXTI9_5_IRQn, + CORTEX_PRIORITY_MASK(CORTEX_MINIMUM_PRIORITY)); + + /* TIM3 */ + RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; + RCC->APB1RSTR = RCC_APB1RSTR_TIM3RST; + RCC->APB1RSTR = 0; + NVICEnableVector(TIM3_IRQn, + CORTEX_PRIORITY_MASK(CORTEX_MINIMUM_PRIORITY)); + TIM3->CR1 = TIM_CR1_URS | TIM_CR1_ARPE; /* Don't enable TIM3 for now */ + TIM3->CR2 = TIM_CR2_TI1S; + TIM3->SMCR = TIM_SMCR_TS_0 | TIM_SMCR_TS_2 | TIM_SMCR_SMS_2; + TIM3->DIER = 0; /* Disable interrupt for now */ + TIM3->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_IC1F_0 | TIM_CCMR1_IC1F_3 + | TIM_CCMR1_CC2S_1 | TIM_CCMR1_IC2F_0 | TIM_CCMR1_IC2F_3; + TIM3->CCMR2 = 0; + TIM3->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC2P; + TIM3->PSC = 72 - 1; /* 1 MHz */ + TIM3->ARR = 18000; /* 18 ms */ + /* Generate UEV to upload PSC and ARR */ + TIM3->EGR = TIM_EGR_UG; +#endif + /* Remap (PB4, PB5) -> (TIM3_CH1, TIM3_CH2) */ + AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIALREMAP; } void @@ -31,3 +61,43 @@ set_led (int value) else palClearPad (IOPORT1, GPIOA_LED); } + +#if defined(PINPAD_SUPPORT) +void +cir_ext_disable (void) +{ + EXTI->PR = EXTI_PR_PR5; + EXTI->IMR &= ~EXTI_IMR_MR5; +} + +void +cir_ext_enable (void) +{ + EXTI->IMR |= EXTI_IMR_MR5; +} + +extern void cir_ext_interrupt (void); +extern void cir_timer_interrupt (void); + +CH_IRQ_HANDLER (EXTI9_5_IRQHandler) +{ + CH_IRQ_PROLOGUE (); + chSysLockFromIsr (); + + cir_ext_interrupt (); + + chSysUnlockFromIsr (); + CH_IRQ_EPILOGUE (); +} + +CH_IRQ_HANDLER (TIM3_IRQHandler) +{ + CH_IRQ_PROLOGUE(); + chSysLockFromIsr(); + + cir_timer_interrupt (); + + chSysUnlockFromIsr(); + CH_IRQ_EPILOGUE(); +} +#endif diff --git a/boards/STM8S_DISCOVERY/board.h b/boards/STM8S_DISCOVERY/board.h index 2ad370b..e0a2a5e 100644 --- a/boards/STM8S_DISCOVERY/board.h +++ b/boards/STM8S_DISCOVERY/board.h @@ -27,6 +27,7 @@ #ifndef _BOARD_H_ #define _BOARD_H_ +#include "config.h" /* * Setup for the ST-Link part of STM8S-Discovery board. */ @@ -90,6 +91,16 @@ #define VAL_GPIOACRH 0x88888883 /* PA15...PA8 */ #define VAL_GPIOAODR 0xFFFFFFFF +#if defined(PINPAD_SUPPORT) +/* + * Port B setup. + * Everything input with pull-up except: + * PB0 - (TIM3_CH3) input with pull-down + */ +#define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */ +#define VAL_GPIOBCRH 0x88888888 /* PB15...PB8 */ +#define VAL_GPIOBODR 0xFFFFFFFE +#else /* * Port B setup. * Everything input with pull-up except: @@ -97,6 +108,7 @@ #define VAL_GPIOBCRL 0x88888888 /* PB7...PB0 */ #define VAL_GPIOBCRH 0x88888888 /* PB15...PB8 */ #define VAL_GPIOBODR 0xFFFFFFFF +#endif /* * Port C setup. diff --git a/src/pin-cir.c b/src/pin-cir.c index 18c7638..86fe175 100644 --- a/src/pin-cir.c +++ b/src/pin-cir.c @@ -139,6 +139,7 @@ uint8_t pin_input_len; static void pindisp (uint8_t c) { +#if defined(HAVE_7SEGLED) switch (c) { case 'G': @@ -153,6 +154,9 @@ pindisp (uint8_t c) default: palWritePort (IOPORT2, 0xffff); } +#else + (void)c; +#endif } #if defined(DEBUG_CIR) diff --git a/src/usb_prop.c b/src/usb_prop.c index bb7db2c..283f305 100644 --- a/src/usb_prop.c +++ b/src/usb_prop.c @@ -36,16 +36,17 @@ #include "usb-cdc-vport.c" #endif -#define SIZE_STRING_SERIAL 22 -static uint8_t gnukStringSerial[SIZE_STRING_SERIAL] = { - 10*2+2, /* bLength */ +static uint8_t gnukStringSerial[] = { + 14*2+2, /* bLength */ USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */ #if defined(SERIAL_NUMBER_IN_AID) 'F', 0, /* 'F' for Fixed */ #else 'C', 0, /* 'C' for Chip uniqure ID */ #endif - '-', 0, + '-', 0, + '0', 0, '.', 0, '6', 0, /* Version number of Gnuk */ + '-', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; @@ -58,10 +59,10 @@ gnuk_device_init (void) for (i = 0; i < 4; i++) { - gnukStringSerial[i*4+0x6] = (u[i*2] >> 4) + 'A'; - gnukStringSerial[i*4+0x7] = 0; - gnukStringSerial[i*4+0x8] = (u[i*2+1] & 0x0f) + 'A'; - gnukStringSerial[i*4+0x9] = 0; + gnukStringSerial[i*4+14] = (u[i*2] >> 4) + 'A'; + gnukStringSerial[i*4+15] = 0; + gnukStringSerial[i*4+16] = (u[i*2+1] & 0x0f) + 'A'; + gnukStringSerial[i*4+17] = 0; } pInformation->Current_Configuration = 0; @@ -190,7 +191,7 @@ gnuk_device_GetStringDescriptor (uint16_t Length) /* Serial number is requested */ if (Length == 0) { - pInformation->Ctrl_Info.Usb_wLength = SIZE_STRING_SERIAL - wOffset; + pInformation->Ctrl_Info.Usb_wLength = sizeof gnukStringSerial - wOffset; return 0; } else