
Contents | Parent Topic | Previous Topic | Next Topic
This part of the manual assumes you know how to program in C++. It may not be complete. May the source be with you!
A new reader for SCAM can consist of code that communicates with a physical smart card reader (like the "dumbmouse" reader), or code that implements a protocol or certain functions (like the "t1" reader).
The rascal subdirectory contains all the driver code for the readers, protocols and applications.
The t_reader class is an abstract class that specifies all the functions a reader should implement. These include:
t_reader()
t_reader(const char *d)
~t_reader()
All these functions apply to the communication between the reader and the smart card, not the communication between the reader and the computer! Most of them do not need to be implemented for "smart" readers, or cannot even be implemented for some readers.
int speed()
void set_speed(int s)
int wait_etu()
long wait_us()
void set_wait_etu(int etu)
void set_wait_us(long us)
t_parity parity()
void set_parity(t_parity parity)
These functions apply to the communication to the card, not to the reader. The driver implementation should handle the embedding into a reader protocol and things like that.
void ISO7816_reset()
int ISO7816_write(const unsigned char *buf, int len)
int ISO7816_read()
int ISO7816_read(long wait)
void flush()
These functions are extras. Not every reader implements them, but a lot of readers do.
bool probe_reader()
bool probe_card()
bool auto_convention()
To implement your favourite reader, derive a class from the t_reader class (or a class derived from it) in which you implement all the abstract functions of its base class.
For examples, see the readers that are already implemented. For readers that use the serial port, a t_serial_reader class was designed, that uses the t_serial datatype that is implemented in serial.h. It is implemented in ser_reader.h. It is adviced to derive such a reader's implementation from this class, as it will then have to use the (portable) t_serial class.
The rascal directory contains more than just physical reader code. Implementations for ISO 7816-3 protocols can also be found. Details can be found in the RASCaL manual.
You may want to use these implementations for your code.
Now that you have written the reader code, you should make an interface for SCAM. SCAM, to be precise its interpreter in scam_interpreter.h, sees a reader as a variable of type t_scr *, which is defined in scr.h.
The t_scr class is an abstract class. Its derived classes should interpret reader specific commands and initialization options. To make life easier a few standard routines, such as for passing reader options or parsing reader specific commands have already been implemented in this abstract class.
To implement a reader, derive a class from t_scr (or a class derived from it) and implement all the necessary functions. For the parsing you will have to know how the lexical scanner class t_scam_scanner in sscanner.h works.
For a non-physical reader, you may want to derive your class from t_scr_soft, thereby giving it access to all physical readers that are implemented.
The t_scr class is derived from the t_interpreter class, which means that you do not have to write your own interpreter functions. This means you can use the lexical scanner p_s, the output stream *p_out and the error stream *p_err. See interpreter.h for details.
The t_scr class provides the following functions and variables:
t_scr(t_scam_scanner &s, ostream *out, ostream *err)
virtual int exec()
virtual void reset()
virtual void write()
virtual void read()
virtual void flush()
virtual int init()
virtual void set_option(const char *name, const char *val)
virtual void initialize()
static int dump_mode
static const char *default_device()
const char * const
scr_myreader_default_device = __DEFAULT_MYREADER__;
char p_optname[scr_max_opt_name_length+1]
char p_optval[scr_max_opt_val_length+1]
virtual void r_reset()
virtual void r_write(const unsigned char *, int)
virtual void r_flush()
virtual int r_read()
virtual bool r_card()
virtual void dump()
So only a few functions have to be implemented. In addition you have to implement the settings function, which displays the current settings on *p_err, and help which shows help on the reader options on *p_err.
For examples, see the already implemented readers.
The t_scr_soft class implements
You have to implement settings() and help().
Now all that is left is making the reader visible for SCAM. There is only one part of the code that will be affected: the file readernames.h.
Just add the right #include-lines to the file and add a line like this:
READER(name,scamreadertype,rascaltype,description)
where name is the name (in quotes), scamreadertype is a classname derived from t_scr (or a class derived from it), rascaltype is a classname derived from t_reader (or a class derived from it). rascaltype is not used for non-physical readers, so any value can be entered there for those readers. description is the text that appears in the help reader command.
If your new reader consists of not only header files, but also source files, make sure the object file is added to the list in the Makefile.
After compilation, SCAM will be able to use the new reader. Physical readers can even be used by non-physical readers by the reader= option.