serial.h File Reference

serial.h header file More...

#include <avr/io.h>
#include "scd_logger.h"

Go to the source code of this file.

Enumerations

enum  AT_CMD {
  AT_NONE, AT_CRST, AT_CTERM, AT_CLET,
  AT_CGEE, AT_CEEE, AT_CGBM, AT_CCINIT,
  AT_CCAPDU, AT_CCEND, AT_DUMMY
}

Functions

char * ProcessSerialData (const char *data, log_struct_t *logger)
 Process serial data received from the host.
uint8_t ParseATCommand (const char *data, AT_CMD *command, char **atparams)
 Parse an AT command received from the host.
uint8_t SendEEPROMHexVSerial ()
 Send EEPROM content as Intel Hex format to the virtual serial port.
void TerminalVSerial (log_struct_t *logger)
 Virtual Serial Terminal application.
uint8_t hexCharsToByte (char c1, char c2)
 Convert two hex digit characters into a byte.
char nibbleToHexChar (uint8_t b, uint8_t high)
 Convert a nibble into a hex char.

Variables

uint8_t lcdAvailable
uint16_t revision
uint8_t selected

Detailed Description

serial.h header file

This file defines the methods and commands for serial communication between the SCD and a host.

These functions are not microcontroller dependent but they are intended for the AVR 8-bit architecture

Copyright (C) 2012 Omar Choudary (omar.choudary@cl.cam.ac.uk)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file serial.h.


Enumeration Type Documentation

enum AT_CMD

Enum defining the different types of AT commands supported

Enumerator:
AT_NONE 
AT_CRST 
AT_CTERM 
AT_CLET 
AT_CGEE 
AT_CEEE 
AT_CGBM 
AT_CCINIT 
AT_CCAPDU 
AT_CCEND 
AT_DUMMY 

Definition at line 51 of file serial.h.


Function Documentation

uint8_t hexCharsToByte ( char  c1,
char  c2 
)

Convert two hex digit characters into a byte.

Convert 2 hexadecimal characters ('0' to '9', 'A' to 'F') into its binary/hexa representation

Parameters:
c1 the most significant hexa character
c2 the least significant hexa character
Returns:
a byte containing the binary representation

Definition at line 437 of file serial.c.

char nibbleToHexChar ( uint8_t  b,
uint8_t  high 
)

Convert a nibble into a hex char.

Convert a nibble into a hexadecimal character ('0' to '9', 'A' to 'F')

Parameters:
b the byte containing the binary representation
high set to 1 if high nibble should be converted, zero if the low nibble is desired. Example: byteToHexChar(0xF3, 1) returns "F".
Returns:
the character hexa representation of the given nibble

Definition at line 472 of file serial.c.

uint8_t ParseATCommand ( const char *  data,
AT_CMD atcmd,
char **  atparams 
)

Parse an AT command received from the host.

This method parses a data stream that should correspond to an AT command and returns the type of command and any parameters.

Parameters:
data a NUL ('') terminated string representing the data received from the host
atcmd stores the type of command in data if parsing is successful. The caller is responsible for allocating space for this.
atparams points to the place in data where the parameters of the command are located or is NULL if there are no parameters
Returns:
0 if success, non-zero otherwise

Definition at line 151 of file serial.c.

char* ProcessSerialData ( const char *  data,
log_struct_t logger 
)

Process serial data received from the host.

This method handles the data received from the serial or virtual serial port.

The SCD should make any necessary processing and then return a response data. However sending a command (e.g. CTERM or CRST) that will reset the SCD will have the obvious consequence that no response will be received. Even more the communication to the host will be interrupted so the host should take care of this.

Parameters:
data a NUL ('') terminated string representing the data to be processed by the SCD, as sent by the serial host
logger the log structure or NULL if no log is desired
Returns:
a NUL ('') terminated string representing the response of this method if success, or NULL if any error occurs. The caller is responsible for eliberating the space ocuppied by the response.

Definition at line 87 of file serial.c.

uint8_t SendEEPROMHexVSerial (  ) 

Send EEPROM content as Intel Hex format to the virtual serial port.

This method reads the content of the EEPROM and transmits it in Intel Hex format to the Virtual Serial port. It is the responsibility of the caller to make sure the virtual serial port is availble.

Returns:
zero if success, non-zero otherwise

Definition at line 228 of file serial.c.

void TerminalVSerial ( log_struct_t logger  ) 

Virtual Serial Terminal application.

This method implements a virtual serial terminal application.

The SCD receives CAPDUs from the Virtual Serial host and transmits back the RAPDUs received from the card. This method should be called upon reciving the AT+CINIT serial command.

This function never returns, after completion it will restart the SCD.

Parameters:
logger the log structure or NULL if a log is not desired

Definition at line 312 of file serial.c.


Variable Documentation

uint8_t lcdAvailable

Definition at line 96 of file scd.c.

uint16_t revision

Definition at line 100 of file scd.c.

uint8_t selected

Definition at line 98 of file scd.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Tue Apr 24 12:00:30 2012 for The Smart Card Detective (SCD) by  doxygen 1.6.3