more
This commit is contained in:
4
src/config.h
Normal file
4
src/config.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#define DEBUG 1
|
||||
#define ENABLE_VIRTUAL_COM_PORT 1
|
||||
|
||||
#define GNUK_MAX_PACKET_SIZE 64 /* USB */
|
||||
56
src/flash.c
Normal file
56
src/flash.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* flash.c -- Data Objects (DO) and GPG Key handling on Flash ROM
|
||||
*
|
||||
* Copyright (C) 2010 Free Software Initiative of Japan
|
||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||
*
|
||||
* 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 "ch.h"
|
||||
#include "gnuk.h"
|
||||
|
||||
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;
|
||||
}
|
||||
100
src/usb-cdc-vport.c
Normal file
100
src/usb-cdc-vport.c
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This file is included by usb_prop.c to provide Virtual COM port feature
|
||||
*/
|
||||
|
||||
/* Original is ../Virtual_COM_Port/usb_prop.c by STMicroelectronics */
|
||||
/* Chopped and modified for Gnuk */
|
||||
|
||||
#include "usb-cdc.h"
|
||||
|
||||
/* Original copyright notice is following: */
|
||||
/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
|
||||
* File Name : usb_prop.c
|
||||
* Author : MCD Application Team
|
||||
* Version : V3.1.1
|
||||
* Date : 04/07/2010
|
||||
* Description : All processing related to Virtual Com Port Demo
|
||||
********************************************************************************
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
||||
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
||||
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
||||
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*******************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static RESULT
|
||||
Virtual_Com_Port_Data_Setup (uint8_t RequestNo)
|
||||
{
|
||||
uint8_t *(*CopyRoutine)(uint16_t);
|
||||
|
||||
CopyRoutine = NULL;
|
||||
|
||||
if (RequestNo == USB_CDC_REQ_GET_LINE_CODING)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
CopyRoutine = Virtual_Com_Port_GetLineCoding;
|
||||
}
|
||||
else if (RequestNo == USB_CDC_REQ_SET_LINE_CODING)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||
CopyRoutine = Virtual_Com_Port_SetLineCoding;
|
||||
}
|
||||
|
||||
if (CopyRoutine == NULL)
|
||||
return USB_UNSUPPORT;
|
||||
|
||||
pInformation->Ctrl_Info.CopyData = CopyRoutine;
|
||||
pInformation->Ctrl_Info.Usb_wOffset = 0;
|
||||
(*CopyRoutine) (0); /* Set Ctrl_Info.Usb_wLength */
|
||||
|
||||
return USB_SUCCESS;
|
||||
}
|
||||
|
||||
static RESULT
|
||||
Virtual_Com_Port_NoData_Setup (uint8_t RequestNo)
|
||||
{
|
||||
if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)
|
||||
&& RequestNo == USB_CDC_REQ_SET_CONTROL_LINE_STATE)
|
||||
/* Do nothing and success */
|
||||
return USB_SUCCESS;
|
||||
|
||||
return USB_UNSUPPORT;
|
||||
}
|
||||
7
src/usb-cdc.h
Normal file
7
src/usb-cdc.h
Normal file
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Class specific control requests for CDC
|
||||
*/
|
||||
#define USB_CDC_REQ_SET_LINE_CODING 0x20
|
||||
#define USB_CDC_REQ_GET_LINE_CODING 0x21
|
||||
#define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
|
||||
#define USB_CDC_REQ_SEND_BREAK 0x23
|
||||
Reference in New Issue
Block a user