This commit is contained in:
NIIBE Yutaka
2010-08-30 11:39:10 +09:00
parent 0e2a614ed3
commit 6bb07657d8
30 changed files with 114 additions and 859 deletions

10
README
View File

@@ -10,11 +10,13 @@ External source
Taken from http://chibios.sourceforge.net/ Taken from http://chibios.sourceforge.net/
Note that CRLF is converted to LF in this repository. Note that CRLF is converted to LF in this repository.
* STM32_USB-FS-Device_Driver * PolarSSS 0.14.0
Taken from http://github.com/robots/STM32.git Taken from http://polarssl.org/
* USBCDC * STM32F10x USB Full Speed Device Library (USB-FS-Device_Lib)
Taken from http://github.com/robots/STM32.git I took Libraries/STM32_USB-FS-Device_Driver and a part of
Project/Virtual_COM_Port in STM32_USB-FS-Device_Lib distribution.
See http://www.st.com for detail.
HOWTO RUN HOWTO RUN

View File

@@ -1,3 +1,6 @@
# Makefile for Gnuk
############################################################################## ##############################################################################
# Build global options # Build global options
# NOTE: Can be overridden externally. # NOTE: Can be overridden externally.
@@ -62,7 +65,7 @@ include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F10x/port.mk include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F10x/port.mk
include $(CHIBIOS)/os/kernel/kernel.mk include $(CHIBIOS)/os/kernel/kernel.mk
include stmusb.mk include stmusb.mk
include usbcdc.mk include vcomport.mk
include rsa.mk include rsa.mk
include ../boards/OLIMEX_STM32_H103/board.mk include ../boards/OLIMEX_STM32_H103/board.mk
@@ -76,15 +79,16 @@ CSRC = $(PORTSRC) \
$(CHIBIOS)/os/various/evtimer.c \ $(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/syscalls.c \ $(CHIBIOS)/os/various/syscalls.c \
$(STMUSBSRC) \ $(STMUSBSRC) \
$(USBCDCSRC) \ $(VCOMSRC) \
$(RSASRC) \ $(RSASRC) \
main.c hw_config.c usb_lld.c usb_desc.c usb_prop.c usb-icc.c gpg.c ac.c gpg-do.c main.c hw_config.c usb_lld.c usb_desc.c usb_prop.c \
usb-icc.c gpg.c ac.c openpgp-do.c flash.c
# List ASM source files here # List ASM source files here
ASMSRC = $(PORTASM) \ ASMSRC = $(PORTASM) \
$(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F10x/vectors.s gpg-data.s $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F10x/vectors.s gpg-data.s
INCDIR = $(RSAINCDIR) $(STMUSBINCDIR) $(USBCDCDIR) \ INCDIR = $(RSAINCDIR) $(STMUSBINCDIR) $(VCOMDIR) \
$(PORTINC) $(KERNINC) $(TESTINC) \ $(PORTINC) $(KERNINC) $(TESTINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) \ $(HALINC) $(PLATFORMINC) $(BOARDINC) \
$(CHIBIOS)/os/various $(CHIBIOS)/os/various

View File

@@ -1,494 +1,56 @@
/* /* ChibiOS/RT configuration file */
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
---
A special exception to the GPL can be applied should you wish to distribute
a combined work that includes ChibiOS/RT, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/
/**
* @file templates/chconf.h
* @brief Configuration file template.
* @details A copy of this file must be placed in each project directory, it
* contains the application specific kernel settings.
*
* @addtogroup config
* @details Kernel related settings and hooks.
* @{
*/
#ifndef _CHCONF_H_ #ifndef _CHCONF_H_
#define _CHCONF_H_ #define _CHCONF_H_
/*===========================================================================*/
/* Kernel parameters. */
/*===========================================================================*/
/**
* @brief System tick frequency.
* @details Frequency of the system timer that drives the system ticks. This
* setting also defines the system tick time unit.
*/
#if !defined(CH_FREQUENCY) || defined(__DOXYGEN__)
#define CH_FREQUENCY 1000 #define CH_FREQUENCY 1000
#endif
/**
* @brief Round robin interval.
* @details This constant is the number of system ticks allowed for the
* threads before preemption occurs. Setting this value to zero
* disables the preemption for threads with equal priority and the
* round robin becomes cooperative. Note that higher priority
* threads can still preempt, the kernel is always preemptive.
*
* @note Disabling the round robin preemption makes the kernel more compact
* and generally faster.
*/
#if !defined(CH_TIME_QUANTUM) || defined(__DOXYGEN__)
#define CH_TIME_QUANTUM 20 #define CH_TIME_QUANTUM 20
#endif
/**
* @brief Nested locks.
* @details If enabled then the use of nested @p chSysLock() / @p chSysUnlock()
* operations is allowed.<br>
* For performance and code size reasons the recommended setting
* is to leave this option disabled.<br>
* You may use this option if you need to merge ChibiOS/RT with
* external libraries that require nested lock/unlock operations.
*
* @note T he default is @p FALSE.
*/
#if !defined(CH_USE_NESTED_LOCKS) || defined(__DOXYGEN__)
#define CH_USE_NESTED_LOCKS FALSE #define CH_USE_NESTED_LOCKS FALSE
#endif #define CH_MEMCORE_SIZE 0 /* Whole RAM */
/**
* @brief Managed RAM size.
* @details Size of the RAM area to be managed by the OS. If set to zero
* then the whole available RAM is used. The core memory is made
* available to the heap allocator and/or can be used directly through
* the simplified core memory allocator.
*
* @note In order to let the OS manage the whole RAM the linker script must
* provide the @p __heap_base__ and @p __heap_end__ symbols.
* @note Requires @p CH_USE_COREMEM.
*/
#if !defined(CH_MEMCORE_SIZE) || defined(__DOXYGEN__)
#define CH_MEMCORE_SIZE 0
#endif
/*===========================================================================*/
/* Performance options. */
/*===========================================================================*/
/**
* @brief OS optimization.
* @details If enabled then time efficient rather than space efficient code
* is used when two possible implementations exist.
*
* @note This is not related to the compiler optimization options.
* @note The default is @p TRUE.
*/
#if !defined(CH_OPTIMIZE_SPEED) || defined(__DOXYGEN__)
#define CH_OPTIMIZE_SPEED TRUE #define CH_OPTIMIZE_SPEED TRUE
#endif
/**
* @brief Exotic optimization.
* @details If defined then a CPU register is used as storage for the global
* @p currp variable. Caching this variable in a register greatly
* improves both space and time OS efficiency. A side effect is that
* one less register has to be saved during the context switch
* resulting in lower RAM usage and faster context switch.
*
* @note This option is only usable with the GCC compiler and is only useful
* on processors with many registers like ARM cores.
* @note If this option is enabled then ALL the libraries linked to the
* ChibiOS/RT code <b>must</b> be recompiled with the GCC option @p
* -ffixed-@<reg@>.
* @note This option must be enabled in the Makefile, it is listed here for
* documentation only.
*/
#if defined(__DOXYGEN__)
#define CH_CURRP_REGISTER_CACHE "reg"
#endif
/*===========================================================================*/
/* Subsystem options. */
/*===========================================================================*/
/**
* @brief Threads registry APIs.
* @details If enabled then the registry APIs are included in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_REGISTRY) || defined(__DOXYGEN__)
#define CH_USE_REGISTRY TRUE #define CH_USE_REGISTRY TRUE
#endif
/**
* @brief Threads synchronization APIs.
* @details If enabled then the @p chThdWait() function is included in
* the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_WAITEXIT) || defined(__DOXYGEN__)
#define CH_USE_WAITEXIT TRUE #define CH_USE_WAITEXIT TRUE
#endif #define CH_USE_SEMAPHORES FALSE
/**
* @brief Semaphores APIs.
* @details If enabled then the Semaphores APIs are included in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_SEMAPHORES) || defined(__DOXYGEN__)
#define CH_USE_SEMAPHORES TRUE
#endif
/**
* @brief Semaphores queuing mode.
* @details If enabled then the threads are enqueued on semaphores by
* priority rather than in FIFO order.
*
* @note The default is @p FALSE. Enable this if you have special requirements.
* @note Requires @p CH_USE_SEMAPHORES.
*/
#if !defined(CH_USE_SEMAPHORES_PRIORITY) || defined(__DOXYGEN__)
#define CH_USE_SEMAPHORES_PRIORITY FALSE #define CH_USE_SEMAPHORES_PRIORITY FALSE
#endif #define CH_USE_SEMSW FALSE
/**
* @brief Atomic semaphore API.
* @details If enabled then the semaphores the @p chSemSignalWait() API
* is included in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_SEMAPHORES.
*/
#if !defined(CH_USE_SEMSW) || defined(__DOXYGEN__)
#define CH_USE_SEMSW TRUE
#endif
/**
* @brief Mutexes APIs.
* @details If enabled then the mutexes APIs are included in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_MUTEXES) || defined(__DOXYGEN__)
#define CH_USE_MUTEXES TRUE #define CH_USE_MUTEXES TRUE
#endif
/**
* @brief Conditional Variables APIs.
* @details If enabled then the conditional variables APIs are included
* in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_MUTEXES.
*/
#if !defined(CH_USE_CONDVARS) || defined(__DOXYGEN__)
#define CH_USE_CONDVARS TRUE #define CH_USE_CONDVARS TRUE
#endif
/**
* @brief Conditional Variables APIs with timeout.
* @details If enabled then the conditional variables APIs with timeout
* specification are included in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_CONDVARS.
*/
#if !defined(CH_USE_CONDVARS_TIMEOUT) || defined(__DOXYGEN__)
#define CH_USE_CONDVARS_TIMEOUT TRUE #define CH_USE_CONDVARS_TIMEOUT TRUE
#endif #define CH_USE_EVENTS TRUE /* We use this! */
#define CH_USE_EVENTS_TIMEOUT TRUE /* We use this! */
/**
* @brief Events Flags APIs.
* @details If enabled then the event flags APIs are included in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_EVENTS) || defined(__DOXYGEN__)
#define CH_USE_EVENTS TRUE
#endif
/**
* @brief Events Flags APIs with timeout.
* @details If enabled then the events APIs with timeout specification
* are included in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_EVENTS.
*/
#if !defined(CH_USE_EVENTS_TIMEOUT) || defined(__DOXYGEN__)
#define CH_USE_EVENTS_TIMEOUT TRUE
#endif
/**
* @brief Synchronous Messages APIs.
* @details If enabled then the synchronous messages APIs are included
* in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_MESSAGES) || defined(__DOXYGEN__)
#define CH_USE_MESSAGES TRUE #define CH_USE_MESSAGES TRUE
#endif
/**
* @brief Synchronous Messages queuing mode.
* @details If enabled then messages are served by priority rather than in
* FIFO order.
*
* @note The default is @p FALSE. Enable this if you have special requirements.
* @note Requires @p CH_USE_MESSAGES.
*/
#if !defined(CH_USE_MESSAGES_PRIORITY) || defined(__DOXYGEN__)
#define CH_USE_MESSAGES_PRIORITY FALSE #define CH_USE_MESSAGES_PRIORITY FALSE
#endif #define CH_USE_MAILBOXES FALSE
#define CH_USE_QUEUES FALSE
/**
* @brief Mailboxes APIs.
* @details If enabled then the asynchronous messages (mailboxes) APIs are
* included in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_SEMAPHORES.
*/
#if !defined(CH_USE_MAILBOXES) || defined(__DOXYGEN__)
#define CH_USE_MAILBOXES TRUE
#endif
/**
* @brief I/O Queues APIs.
* @details If enabled then the I/O queues APIs are included in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_SEMAPHORES.
*/
#if !defined(CH_USE_QUEUES) || defined(__DOXYGEN__)
#define CH_USE_QUEUES TRUE
#endif
/**
* @brief Core Memory Manager APIs.
* @details If enabled then the core memory manager APIs are included
* in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_MEMCORE) || defined(__DOXYGEN__)
#define CH_USE_MEMCORE TRUE #define CH_USE_MEMCORE TRUE
#endif
/**
* @brief Heap Allocator APIs.
* @details If enabled then the memory heap allocator APIs are included
* in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_COREMEM and either @p CH_USE_MUTEXES or
* @p CH_USE_SEMAPHORES.
* @note Mutexes are recommended.
*/
#if !defined(CH_USE_HEAP) || defined(__DOXYGEN__)
#define CH_USE_HEAP TRUE #define CH_USE_HEAP TRUE
#endif
/**
* @brief C-runtime allocator.
* @details If enabled the the heap allocator APIs just wrap the C-runtime
* @p malloc() and @p free() functions.
*
* @note The default is @p FALSE.
* @note Requires @p CH_USE_HEAP.
* @note The C-runtime may or may not require @p CH_USE_COREMEM, see the
* appropriate documentation.
*/
#if !defined(CH_USE_MALLOC_HEAP) || defined(__DOXYGEN__)
#define CH_USE_MALLOC_HEAP FALSE #define CH_USE_MALLOC_HEAP FALSE
#endif
/**
* @brief Memory Pools Allocator APIs.
* @details If enabled then the memory pools allocator APIs are included
* in the kernel.
*
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_MEMPOOLS) || defined(__DOXYGEN__)
#define CH_USE_MEMPOOLS TRUE #define CH_USE_MEMPOOLS TRUE
#endif #define CH_USE_DYNAMIC FALSE
/** /* Debug options */
* @brief Dynamic Threads APIs.
* @details If enabled then the dynamic threads creation APIs are included
* in the kernel.
*
* @note The default is @p TRUE.
* @note Requires @p CH_USE_WAITEXIT.
* @note Requires @p CH_USE_HEAP and/or @p CH_USE_MEMPOOLS.
*/
#if !defined(CH_USE_DYNAMIC) || defined(__DOXYGEN__)
#define CH_USE_DYNAMIC TRUE
#endif
/*===========================================================================*/
/* Debug options. */
/*===========================================================================*/
/**
* @brief Debug option, parameters checks.
* @details If enabled then the checks on the API functions input
* parameters are activated.
*
* @note The default is @p FALSE.
*/
#if !defined(CH_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
#define CH_DBG_ENABLE_CHECKS FALSE #define CH_DBG_ENABLE_CHECKS FALSE
#endif
/**
* @brief Debug option, consistency checks.
* @details If enabled then all the assertions in the kernel code are
* activated. This includes consistency checks inside the kernel,
* runtime anomalies and port-defined checks.
*
* @note The default is @p FALSE.
*/
#if !defined(CH_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
#define CH_DBG_ENABLE_ASSERTS FALSE #define CH_DBG_ENABLE_ASSERTS FALSE
#endif
/**
* @brief Debug option, trace buffer.
* @details If enabled then the context switch circular trace buffer is
* activated.
*
* @note The default is @p FALSE.
*/
#if !defined(CH_DBG_ENABLE_TRACE) || defined(__DOXYGEN__)
#define CH_DBG_ENABLE_TRACE FALSE #define CH_DBG_ENABLE_TRACE FALSE
#endif
/**
* @brief Debug option, stack checks.
* @details If enabled then a runtime stack check is performed.
*
* @note The default is @p FALSE.
* @note The stack check is performed in a architecture/port dependent way.
* It may not be implemented or some ports.
* @note The default failure mode is to halt the system with the global
* @p panic_msg variable set to @p NULL.
*/
#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__)
#define CH_DBG_ENABLE_STACK_CHECK FALSE #define CH_DBG_ENABLE_STACK_CHECK FALSE
#endif
/**
* @brief Debug option, stacks initialization.
* @details If enabled then the threads working area is filled with a byte
* value when a thread is created. This can be useful for the
* runtime measurement of the used stack.
*
* @note The default is @p FALSE.
*/
#if !defined(CH_DBG_FILL_THREADS) || defined(__DOXYGEN__)
#define CH_DBG_FILL_THREADS FALSE #define CH_DBG_FILL_THREADS FALSE
#endif
/**
* @brief Debug option, threads profiling.
* @details If enabled then a field is added to the @p Thread structure that
* counts the system ticks occurred while executing the thread.
*
* @note The default is @p TRUE.
* @note This debug option is defaulted to TRUE because it is required by
* some test cases into the test suite.
*/
#if !defined(CH_DBG_THREADS_PROFILING) || defined(__DOXYGEN__)
#define CH_DBG_THREADS_PROFILING TRUE #define CH_DBG_THREADS_PROFILING TRUE
#endif
/*===========================================================================*/
/* Kernel hooks. */
/*===========================================================================*/
/**
* @brief Threads descriptor structure hook.
* @details User fields added to the end of the @p Thread structure.
*/
#if !defined(THREAD_EXT_FIELDS) || defined(__DOXYGEN__)
#define THREAD_EXT_FIELDS \ #define THREAD_EXT_FIELDS \
struct { \ struct { \
/* Add threads custom fields here.*/ \ /* Add threads custom fields here.*/ \
}; };
#endif
/**
* @brief Threads initialization hook.
* @details User initialization code added to the @p chThdInit() API.
*
* @note It is invoked from within @p chThdInit() and implicitily from all
* the threads creation APIs.
*/
#if !defined(THREAD_EXT_INIT) || defined(__DOXYGEN__)
#define THREAD_EXT_INIT(tp) { \ #define THREAD_EXT_INIT(tp) { \
/* Add threads initialization code here.*/ \ /* Add threads initialization code here.*/ \
} }
#endif
/**
* @brief Threads finalization hook.
* @details User finalization code added to the @p chThdExit() API.
*
* @note It is inserted into lock zone.
* @note It is also invoked when the threads simply return in order to
* terminate.
*/
#if !defined(THREAD_EXT_EXIT) || defined(__DOXYGEN__)
#define THREAD_EXT_EXIT(tp) { \ #define THREAD_EXT_EXIT(tp) { \
/* Add threads finalization code here.*/ \ /* Add threads finalization code here.*/ \
} }
#endif
/**
* @brief Idle Loop hook.
* @details This hook is continuously invoked by the idle thread loop.
*/
#if !defined(IDLE_LOOP_HOOK) || defined(__DOXYGEN__)
#define IDLE_LOOP_HOOK() { \ #define IDLE_LOOP_HOOK() { \
/* Idle loop code here.*/ \ /* Idle loop code here.*/ \
} }
#endif
/*===========================================================================*/
/* Port-specific settings (override port settings defaulted in chcore.h). */
/*===========================================================================*/
#endif /* _CHCONF_H_ */ #endif /* _CHCONF_H_ */
/** @} */

View File

@@ -44,8 +44,9 @@ extern int verify_pso_admin (uint8_t *pw, int pw_len);
extern void write_res_apdu (const uint8_t *p, int len, extern void write_res_apdu (const uint8_t *p, int len,
uint8_t sw1, uint8_t sw2); uint8_t sw1, uint8_t sw2);
#define DEBUG 1
extern int gpg_do_table_init (void); extern int gpg_do_table_init (void);
extern void gpg_do_get_data (uint16_t tag); extern void gpg_do_get_data (uint16_t tag);
extern void gpg_do_put_data (uint16_t tag, uint8_t *data, int len); extern void gpg_do_put_data (uint16_t tag, uint8_t *data, int len);
extern uint8_t * flash_do_write (uint16_t tag, uint8_t *data, int len);

View File

@@ -1,159 +1,17 @@
/* /* HAL configuration file for ChibiOS/RT */
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
---
A special exception to the GPL can be applied should you wish to distribute
a combined work that includes ChibiOS/RT, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/
/**
* @file templates/halconf.h
* @brief HAL configuration header.
* @addtogroup HAL_CONF
* @{
*/
/*
* HAL configuration file, this file allows to enable or disable the various
* device drivers from your application. You may also use this file in order
* to override the device drivers default settings.
*/
#ifndef _HALCONF_H_ #ifndef _HALCONF_H_
#define _HALCONF_H_ #define _HALCONF_H_
/*
* Uncomment the following line in order to include a mcu-related
* settings file. This file can be used to include platform specific
* header files or to override the low level drivers settings.
*/
#include "mcuconf.h" #include "mcuconf.h"
/*===========================================================================*/
/* PAL driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the PAL subsystem.
*/
#if !defined(CH_HAL_USE_PAL) || defined(__DOXYGEN__)
#define CH_HAL_USE_PAL TRUE #define CH_HAL_USE_PAL TRUE
#endif
/*===========================================================================*/
/* ADC driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the ADC subsystem.
*/
#if !defined(CH_HAL_USE_ADC) || defined(__DOXYGEN__)
#define CH_HAL_USE_ADC FALSE #define CH_HAL_USE_ADC FALSE
#endif
/*===========================================================================*/
/* CAN driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the CAN subsystem.
*/
#if !defined(CH_HAL_USE_CAN) || defined(__DOXYGEN__)
#define CH_HAL_USE_CAN FALSE #define CH_HAL_USE_CAN FALSE
#endif
/*===========================================================================*/
/* MAC driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the MAC subsystem.
*/
#if !defined(CH_HAL_USE_MAC) || defined(__DOXYGEN__)
#define CH_HAL_USE_MAC FALSE #define CH_HAL_USE_MAC FALSE
#endif
/*===========================================================================*/
/* PWM driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the PWM subsystem.
*/
#if !defined(CH_HAL_USE_PWM) || defined(__DOXYGEN__)
#define CH_HAL_USE_PWM FALSE #define CH_HAL_USE_PWM FALSE
#endif #define CH_HAL_USE_SERIAL FALSE
/*===========================================================================*/
/* SERIAL driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the SERIAL subsystem.
*/
#if !defined(CH_HAL_USE_SERIAL) || defined(__DOXYGEN__)
#define CH_HAL_USE_SERIAL TRUE
#endif
/*
* Default SERIAL settings overrides (uncomment to override).
*/
/*#define SERIAL_DEFAULT_BITRATE 38400*/
/*#define SERIAL_BUFFERS_SIZE 64*/
/*===========================================================================*/
/* SPI driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the SPI subsystem.
*/
#if !defined(CH_HAL_USE_SPI) || defined(__DOXYGEN__)
#define CH_HAL_USE_SPI FALSE #define CH_HAL_USE_SPI FALSE
#endif
/*
* Default SPI settings overrides (uncomment to override).
*/
/*#define SPI_USE_MUTUAL_EXCLUSION TRUE*/
/*===========================================================================*/
/* MMC_SPI driver related settings. */
/*===========================================================================*/
/**
* @brief Enables the MMC_SPI subsystem.
*/
#if !defined(CH_HAL_USE_MMC_SPI) || defined(__DOXYGEN__)
#define CH_HAL_USE_MMC_SPI FALSE #define CH_HAL_USE_MMC_SPI FALSE
#endif
/*
* Default MMC_SPI settings overrides (uncomment to override).
*/
/*#define MMC_SECTOR_SIZE 512*/
/*#define MMC_NICE_WAITING TRUE*/
/*#define MMC_POLLING_INTERVAL 10*/
/*#define MMC_POLLING_DELAY 10*/
#endif /* _HALCONF_H_ */ #endif /* _HALCONF_H_ */
/** @} */

View File

@@ -1,3 +1,10 @@
/* Hardware specific USB functions */
/*
* For detail, please see the documentation of
* STM32F10x USB Full Speed Device Library (USB-FS-Device_Lib)
* by STMicroelectronics' MCD Application Team
*/
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"

View File

@@ -1,27 +1,24 @@
/* /*
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. * main.c - main routine of Gnuk
*
This file is part of ChibiOS/RT. * Copyright (C) 2010 Free Software Initiative of Japan
* Author: NIIBE Yutaka <gniibe@fsij.org>
ChibiOS/RT is free software; you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by * This file is a part of Gnuk, a GnuPG USB Token implementation.
the Free Software Foundation; either version 3 of the License, or *
(at your option) any later version. * Gnuk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
ChibiOS/RT is distributed in the hope that it will be useful, * the Free Software Foundation, either version 3 of the License, or
but WITHOUT ANY WARRANTY; without even the implied warranty of * (at your option) any later version.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
GNU General Public License for more details. * Gnuk is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
You should have received a copy of the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
along with this program. If not, see <http://www.gnu.org/licenses/>. * License for more details.
*
--- * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
A special exception to the GPL can be applied should you wish to distribute *
a combined work that includes ChibiOS/RT, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/ */
#include "ch.h" #include "ch.h"
@@ -174,7 +171,8 @@ extern msg_t GPGthread (void *arg);
* Entry point, note, the main() function is already a thread in the system * Entry point, note, the main() function is already a thread in the system
* on entry. * on entry.
*/ */
int main(int argc, char **argv) int
main (int argc, char **argv)
{ {
int count = 0; int count = 0;

View File

@@ -1,5 +1,5 @@
/* /*
* gpg-do.c -- OpenPGP card Data Objects (DO) handling * openpgp-do.c -- OpenPGP card Data Objects (DO) handling
* *
* Copyright (C) 2010 Free Software Initiative of Japan * Copyright (C) 2010 Free Software Initiative of Japan
* Author: NIIBE Yutaka <gniibe@fsij.org> * Author: NIIBE Yutaka <gniibe@fsij.org>
@@ -21,6 +21,8 @@
* *
*/ */
#include "config.h"
#include "ch.h" #include "ch.h"
#include "gnuk.h" #include "gnuk.h"
@@ -619,37 +621,6 @@ gpg_do_get_data (uint16_t tag)
write_res_apdu (NULL, 0, 0x6a, 0x88); write_res_apdu (NULL, 0, 0x6a, 0x88);
} }
uint8_t *
flash_do_write (uint16_t tag, uint8_t *data, int len)
{
static uint8_t do_pool[1024];
static uint8_t *last_p = do_pool;
uint8_t *p = last_p;
if (last_p - do_pool + len + 2 + 3 > 1024)
return NULL;
*last_p++ = (tag >> 8);
*last_p++ = (tag & 0xff);
if (len < 128)
*last_p++ = len;
else if (len < 256)
{
*last_p++ = 0x81;
*last_p++ = len;
}
else
{
*last_p++ = 0x82;
*last_p++ = (len >> 8);
*last_p++ = (len & 0xff);
}
memcpy (last_p, data, len);
last_p += len;
return p + 2;
}
void void
gpg_do_put_data (uint16_t tag, uint8_t *data, int len) gpg_do_put_data (uint16_t tag, uint8_t *data, int len)
{ {

View File

@@ -74,7 +74,7 @@ rsa_sign (unsigned char *raw_message)
len = (cmd_APDU[5]<<8) | cmd_APDU[6]; /* cmd_APDU_size - 6 */ len = (cmd_APDU[5]<<8) | cmd_APDU[6]; /* cmd_APDU_size - 6 */
mpi_init( &P1, &Q1, &H, NULL ); mpi_init( &P1, &Q1, &H, NULL );
rsa_init( &ctx, RSA_PKCS_V15, 0, NULL, NULL ); rsa_init( &ctx, RSA_PKCS_V15, 0 );
#if 0 #if 0
ctx.len = 2048 / 8; ctx.len = 2048 / 8;

View File

@@ -1,4 +1,4 @@
RSADIR = ../../polarssl-0.13.1 RSADIR = ../polarssl-0.14.0
RSASRCDIR = $(RSADIR)/library RSASRCDIR = $(RSADIR)/library
RSAINCDIR = $(RSADIR)/include RSAINCDIR = $(RSADIR)/include
RSASRC = $(RSASRCDIR)/bignum.c $(RSASRCDIR)/rsa.c rsa_sign.c RSASRC = $(RSASRCDIR)/bignum.c $(RSASRCDIR)/rsa.c rsa-sign.c

View File

@@ -1,36 +1,26 @@
/* USB configuration file for USB-FS-Device_Lib */
/* /*
(C) COPYRIGHT 2010 STMicroelectronics * For detail, please see the documentation of
usb_conf.h * STM32F10x USB Full Speed Device Library (USB-FS-Device_Lib)
MCD Application Team * by STMicroelectronics
V3.1.1
04/07/2010
Virtual COM Port Demo configuration header
*/ */
#ifndef __USB_CONF_H #ifndef __USB_CONF_H
#define __USB_CONF_H #define __USB_CONF_H
/*-------------------------------------------------------------*/ #ifdef ENABLE_VIRTUAL_COM_PORT
/* EP_NUM */
/* defines how many endpoints are used by the device */
/*-------------------------------------------------------------*/
#define EP_NUM (6) #define EP_NUM (6)
#else
#define EP_NUM (3)
#endif
/*-------------------------------------------------------------*/
/* -------------- Buffer Description Table -----------------*/
/*-------------------------------------------------------------*/
/* buffer table base address */
/* buffer table base address */
#define BTABLE_ADDRESS (0x00) #define BTABLE_ADDRESS (0x00)
/* EP0 */ /* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x40) #define ENDP0_RXADDR (0x40)
#define ENDP0_TXADDR (0x80) #define ENDP0_TXADDR (0x80)
/* EP1 */ /* EP1 */
/* tx buffer base address */
#define ENDP1_TXADDR (0xC0) #define ENDP1_TXADDR (0xC0)
/* EP2 */ /* EP2 */
#define ENDP2_TXADDR (0x100) #define ENDP2_TXADDR (0x100)
@@ -43,39 +33,6 @@ Virtual COM Port Demo configuration header
/* EP5 */ /* EP5 */
#define ENDP5_RXADDR (0x1C0) #define ENDP5_RXADDR (0x1C0)
/*-------------------------------------------------------------*/
/* ------------------- ISTR events -------------------------*/
/*-------------------------------------------------------------*/
/* IMR_MSK */
/* mask defining which events has to be handled */
/* by the device application software */
#define IMR_MSK (CNTR_CTRM | CNTR_SOFM | CNTR_RESETM ) #define IMR_MSK (CNTR_CTRM | CNTR_SOFM | CNTR_RESETM )
/*#define CTR_CALLBACK*/
/*#define DOVR_CALLBACK*/
/*#define ERR_CALLBACK*/
/*#define WKUP_CALLBACK*/
/*#define SUSP_CALLBACK*/
/*#define RESET_CALLBACK*/
/*#define SOF_CALLBACK*/
/*#define ESOF_CALLBACK*/
#if 0
#define EP1_IN_Callback NOP_Process
#define EP2_IN_Callback NOP_Process
#define EP3_IN_Callback NOP_Process
#define EP4_IN_Callback NOP_Process
#define EP5_IN_Callback NOP_Process
#define EP6_IN_Callback NOP_Process
#define EP7_IN_Callback NOP_Process
#define EP1_OUT_Callback NOP_Process
#define EP2_OUT_Callback NOP_Process
#define EP3_OUT_Callback NOP_Process
#define EP4_OUT_Callback NOP_Process
#define EP5_OUT_Callback NOP_Process
#define EP6_OUT_Callback NOP_Process
#define EP7_OUT_Callback NOP_Process
#endif
#endif /* __USB_CONF_H */ #endif /* __USB_CONF_H */

View File

@@ -1,8 +1,2 @@
/**
* @brief USB interrupt priority level setting.
*/
#if !defined(STM32_USB_IRQ_PRIORITY) || defined(__DOXYGEN__)
#define STM32_USB_IRQ_PRIORITY 11 #define STM32_USB_IRQ_PRIORITY 11
#endif
void usb_lld_init (void); void usb_lld_init (void);

View File

@@ -1,11 +1,28 @@
/* /*
usb_prop.c * usb_prop.c - glue/interface code between Gnuk and USB-FS-Device_Lib
MCD Application Team *
V3.1.1 * Copyright (C) 2010 Free Software Initiative of Japan
04/07/2010 * Author: NIIBE Yutaka <gniibe@fsij.org>
All processing related to Virtual Com Port Demo *
* This file is a part of Gnuk, a GnuPG USB Token implementation.
*
* Gnuk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gnuk 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 General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
#include "config.h"
#include "usb_lib.h" #include "usb_lib.h"
#include "usb_conf.h" #include "usb_conf.h"
#include "usb_prop.h" #include "usb_prop.h"
@@ -13,56 +30,16 @@ All processing related to Virtual Com Port Demo
#include "usb_pwr.h" #include "usb_pwr.h"
#include "hw_config.h" #include "hw_config.h"
#if 0 #ifdef ENABLE_VIRTUAL_COM_PORT
static uint8_t Request = 0; #include "usb-cdc-vport.c"
#endif #endif
typedef struct
{
uint32_t bitrate;
uint8_t format;
uint8_t paritytype;
uint8_t datatype;
} LINE_CODING;
static LINE_CODING linecoding = {
115200, /* baud rate*/
0x00, /* stop bits-1*/
0x00, /* parity - none*/
0x08 /* no. of bits 8*/
};
static uint8_t *Virtual_Com_Port_GetLineCoding(uint16_t Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
return NULL;
}
return (uint8_t *)&linecoding;
}
static uint8_t *Virtual_Com_Port_SetLineCoding(uint16_t Length)
{
if (Length == 0)
{
pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);
return NULL;
}
return (uint8_t *)&linecoding;
}
#define GNUK_MAX_PACKET_SIZE 64
static void static void
gnuk_device_init (void) gnuk_device_init (void)
{ {
/*
/* Update the serial number string descriptor with the data from the unique * Update the serial number string descriptor (if needed)
ID*/ */
Get_SerialNum (); Get_SerialNum ();
pInformation->Current_Configuration = 0; pInformation->Current_Configuration = 0;
@@ -79,13 +56,13 @@ gnuk_device_init (void)
static void static void
gnuk_device_reset (void) gnuk_device_reset (void)
{ {
/* Set Virtual_Com_Port DEVICE as not configured */ /* Set DEVICE as not configured */
pInformation->Current_Configuration = 0; pInformation->Current_Configuration = 0;
/* Current Feature initialization */ /* Current Feature initialization */
pInformation->Current_Feature = Config_Descriptor.Descriptor[7]; pInformation->Current_Feature = Config_Descriptor.Descriptor[7];
/* Set Virtual_Com_Port DEVICE with the default Interface*/ /* Set DEVICE with the default Interface*/
pInformation->Current_Interface = 0; pInformation->Current_Interface = 0;
SetBTABLE (BTABLE_ADDRESS); SetBTABLE (BTABLE_ADDRESS);
@@ -99,6 +76,7 @@ gnuk_device_reset (void)
SetEPRxCount (ENDP0, GNUK_MAX_PACKET_SIZE); SetEPRxCount (ENDP0, GNUK_MAX_PACKET_SIZE);
SetEPRxValid (ENDP0); SetEPRxValid (ENDP0);
#ifdef ENABLE_VIRTUAL_COM_PORT
/* Initialize Endpoint 1 */ /* Initialize Endpoint 1 */
SetEPType (ENDP1, EP_BULK); SetEPType (ENDP1, EP_BULK);
SetEPTxAddr (ENDP1, ENDP1_TXADDR); SetEPTxAddr (ENDP1, ENDP1_TXADDR);
@@ -117,6 +95,7 @@ gnuk_device_reset (void)
SetEPRxCount (ENDP3, VIRTUAL_COM_PORT_DATA_SIZE); SetEPRxCount (ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
SetEPRxStatus (ENDP3, EP_RX_VALID); SetEPRxStatus (ENDP3, EP_RX_VALID);
SetEPTxStatus (ENDP3, EP_TX_DIS); SetEPTxStatus (ENDP3, EP_TX_DIS);
#endif
/* Initialize Endpoint 4 */ /* Initialize Endpoint 4 */
SetEPType (ENDP4, EP_BULK); SetEPType (ENDP4, EP_BULK);
@@ -127,7 +106,7 @@ gnuk_device_reset (void)
/* Initialize Endpoint 5 */ /* Initialize Endpoint 5 */
SetEPType (ENDP5, EP_BULK); SetEPType (ENDP5, EP_BULK);
SetEPRxAddr (ENDP5, ENDP5_RXADDR); SetEPRxAddr (ENDP5, ENDP5_RXADDR);
SetEPRxCount (ENDP5, VIRTUAL_COM_PORT_DATA_SIZE); /* XXX */ SetEPRxCount (ENDP5, GNUK_MAX_PACKET_SIZE);
SetEPRxStatus (ENDP5, EP_RX_VALID); SetEPRxStatus (ENDP5, EP_RX_VALID);
SetEPTxStatus (ENDP5, EP_TX_DIS); SetEPTxStatus (ENDP5, EP_TX_DIS);
@@ -157,10 +136,6 @@ gnuk_device_SetDeviceAddress (void)
static void static void
gnuk_device_Status_In (void) gnuk_device_Status_In (void)
{ {
#if 0
if (Request == SET_LINE_CODING)
Request = 0;
#endif
} }
/* OUT to port 0 */ /* OUT to port 0 */
@@ -169,65 +144,6 @@ gnuk_device_Status_Out (void)
{ {
} }
/*******************************************************************************
* Function Name : Virtual_Com_Port_Data_Setup
* Description : handle the data class specific requests
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
static RESULT
Virtual_Com_Port_Data_Setup (uint8_t RequestNo)
{
uint8_t *(*CopyRoutine)(uint16_t);
CopyRoutine = NULL;
if (RequestNo == GET_LINE_CODING)
{
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
CopyRoutine = Virtual_Com_Port_GetLineCoding;
}
else if (RequestNo == SET_LINE_CODING)
{
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
CopyRoutine = Virtual_Com_Port_SetLineCoding;
#if 0
Request = SET_LINE_CODING;
#endif
}
if (CopyRoutine == NULL)
return USB_UNSUPPORT;
pInformation->Ctrl_Info.CopyData = CopyRoutine;
pInformation->Ctrl_Info.Usb_wOffset = 0;
(*CopyRoutine) (0);
return USB_SUCCESS;
}
/*******************************************************************************
* Function Name : Virtual_Com_Port_NoData_Setup.
* Description : handle the no data class specific requests.
* Input : Request Nb.
* Output : None.
* Return : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
static RESULT
Virtual_Com_Port_NoData_Setup (uint8_t RequestNo)
{
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
{
if (RequestNo == SET_COMM_FEATURE)
return USB_SUCCESS;
else if (RequestNo == SET_CONTROL_LINE_STATE)
return USB_SUCCESS;
}
return USB_UNSUPPORT;
}
static uint8_t * static uint8_t *
gnuk_device_GetDeviceDescriptor (uint16_t Length) gnuk_device_GetDeviceDescriptor (uint16_t Length)
{ {
@@ -261,7 +177,7 @@ gnuk_device_Get_Interface_Setting (uint8_t Interface, uint8_t AlternateSetting)
return USB_SUCCESS; return USB_SUCCESS;
} }
/* /*
* Interface to USB core * Interface to USB core
*/ */
@@ -271,8 +187,13 @@ DEVICE_PROP Device_Property = {
gnuk_device_reset, gnuk_device_reset,
gnuk_device_Status_In, gnuk_device_Status_In,
gnuk_device_Status_Out, gnuk_device_Status_Out,
#ifdef ENABLE_VIRTUAL_COM_PORT
Virtual_Com_Port_Data_Setup, Virtual_Com_Port_Data_Setup,
Virtual_Com_Port_NoData_Setup, Virtual_Com_Port_NoData_Setup,
#else
NULL,
NULL,
#endif
gnuk_device_Get_Interface_Setting, gnuk_device_Get_Interface_Setting,
gnuk_device_GetDeviceDescriptor, gnuk_device_GetDeviceDescriptor,
gnuk_device_GetConfigDescriptor, gnuk_device_GetConfigDescriptor,

View File

@@ -1,25 +1,6 @@
/*
(C) COPYRIGHT 2010 STMicroelectronics
usb_prop.h
MCD Application Team
V3.1.1
04/07/2010
All processing related to Virtual COM Port Demo (Endpoint 0)
*/
#ifndef __usb_prop_H #ifndef __usb_prop_H
#define __usb_prop_H #define __usb_prop_H
#define SEND_ENCAPSULATED_COMMAND 0x00
#define GET_ENCAPSULATED_RESPONSE 0x01
#define SET_COMM_FEATURE 0x02
#define GET_COMM_FEATURE 0x03
#define CLEAR_COMM_FEATURE 0x04
#define SET_LINE_CODING 0x20
#define GET_LINE_CODING 0x21
#define SET_CONTROL_LINE_STATE 0x22
#define SEND_BREAK 0x23
extern ONE_DESCRIPTOR Device_Descriptor; extern ONE_DESCRIPTOR Device_Descriptor;
extern ONE_DESCRIPTOR Config_Descriptor; extern ONE_DESCRIPTOR Config_Descriptor;
extern ONE_DESCRIPTOR String_Descriptor[4]; extern ONE_DESCRIPTOR String_Descriptor[4];

View File

@@ -1,3 +0,0 @@
USBCDCDIR = ../USBCDC
USBCDCSRC= $(USBCDCDIR)/usb_endp.c $(USBCDCDIR)/usb_istr.c \
$(USBCDCDIR)/usb_pwr.c

2
src/vcomport.mk Normal file
View File

@@ -0,0 +1,2 @@
VCOMDIR = ../Virtual_COM_Port
VCOMSRC= $(VCOMDIR)/usb_endp.c $(VCOMDIR)/usb_istr.c $(VCOMDIR)/usb_pwr.c