<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">

<refentry>

<refentryinfo>
        <address><email>cprados@yahoo.com</email></address>
        <author>
	<firstname>Carlos</firstname>
	<surname>Prados</surname>
	</author>
        <copyright><year>2001</year><holder>Carlos Prados</holder></copyright>
        <date>06-03-2001</date>
</refentryinfo>

<refmeta>
	<refentrytitle>CT-API</refentrytitle>
	<manvolnum>3</manvolnum>
</refmeta>

<refnamediv id="X1">
	<refdescriptor>CT_init, CT_data, CT_close</refdescriptor>
	<refname>CT_init</refname>
	<refname>CT_data</refname>
	<refname>CT_close</refname>
        <refpurpose>
	Functions to handle communication with integrated circuit cards and 
	cardterminals
	</refpurpose>
</refnamediv>

<refsynopsisdiv>
        <!-- Function prototypes for CT-API -->
        <funcsynopsis>
        <funcsynopsisinfo>#include &lt;ctapi.h&gt;</funcsynopsisinfo>

        <!-- CT_init -->
        <funcprototype>
        <funcdef>char <function>CT_init</function></funcdef>
        <paramdef>      unsigned short <parameter>ctn</parameter></paramdef>
        <paramdef>      unsigned short <parameter>pn</parameter></paramdef>
        </funcprototype>

        <!-- CT_data -->
        <funcprototype>
        <funcdef>char <function>CT_data</function></funcdef>
        <paramdef>      unsigned short <parameter>ctn</parameter></paramdef>
        <paramdef>      unsigned char * <parameter>dad</parameter></paramdef>
        <paramdef>      unsigned char * <parameter>sad</parameter></paramdef>
        <paramdef>      unsigned short <parameter>lenc</parameter></paramdef>
        <paramdef>      unsigned char * <parameter>command</parameter></paramdef>
        <paramdef>      unsigned short * <parameter>lenr</parameter></paramdef>
        <paramdef>      unsigned char * <parameter>response</parameter></paramdef>
        </funcprototype>

        <!-- CT_close -->
        <funcprototype>
        <funcdef>char <function>CT_close</function></funcdef>
        <paramdef>      unsigned short <parameter>ctn</parameter></paramdef>
        </funcprototype>

        </funcsynopsis>
</refsynopsisdiv>

<refsect1>
        <title>DESCRIPTION</title>

        <para>
	This manual page describes the CT-API functions used to handle
        communication with integrated circuit cards and cardterminals. The 
	CT-API functions are generic, and allows the use of memory cards (often 
	referred as synchronous cards) and processor cards (often referred 
	as asynchronous cards).
        </para>

        <para>
	The CT-API implementation is dependent on the cardterminal that is 
	used. For each cardterminal a CT-API library implementation 
	should be provided, either by the manufacturer or by third parties. 
	This manpage is not a complete specification of the CT-API, but 
	a general overview of the most common functionalities.
        </para>

        <!-- CT_init -->
        <para><function>CT_init()</function> selects and initializes the 
	interface with the cardterminal (f.i. serial port, USB bus, or any 
	other type of connector). The CT_init() function must be called before 
	communicating with the card or the cardterminal. A unique cardterminal 
	number chosen by the caller is assigned by the CT-API library to the 
	initialized connection.
        </para>

        <variablelist>

        <varlistentry>
        <term><parameter>ctn</parameter></term>
        <listitem>
        <para>Cardterminal number: identifies the connection with the
        cardterminal for further references. It's chosen by the caller
        of the function.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>pn</parameter></term>
        <listitem>
        <para>Port number: selects the physical interface. The port number
        assignment is dependent on the CT-API implementation. However most
        serial cardterminal implementations use the convention of assigning 
	the value 0 to the first serial port, 1 to the second serial port and 
	so on. See the file <filename>/usr/include/ctapi.h</filename> of
	your CT-API implementation for a list of allowed values.
        </para>
        </listitem>
        </varlistentry>

        </variablelist>

        <!-- CT_data -->
        <para><function>CT_data()</function> sends a command to the card or to 
	the cardterminal and returns the response to the calling program.
        </para>

        <variablelist>

        <varlistentry>
        <term><parameter>ctn</parameter></term>
        <listitem>
        <para>Cardterminal number: the number specified in <function>CT_init()
	</function> call for this cardterminal.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>dad</parameter></term>
        <listitem>
        <para>Destination address. If the command is sent to the cardterminal, 
	it must point to a variable containing the value CT (0x01). If the 
	command is sent to a card, the destination address variable must be 
	set to the number identifying the slot of the cardterminal where the 
	card is inserted, ranging from ICC1 (0x00) and ICC2 (0x02) to ICC14 
	(0x0E).
	</para>
	<para>
	On the return of the response, the variable pointed by dad is set to 
	the value HOST (0x02) or REMOTE_HOST (0x05).
	</para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>sad</parameter></term>
        <listitem>
        <para>Source address. When the function is called it is usually set to 
	point to a variable with the value HOST (0x02), although the value
	REMOTE_HOST (0x05) may ocurr in some applications if the CT-API 
	implementation supports remote calls.
        </para>
	<para>
	On the return of the response, the variable pointed by sad is set to any 
	of the values from CT (0x01), ICC1 (0x00), ICC2 (0x02) to ICC14 (0x0E).
	</para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>lenc</parameter></term>
        <listitem>
        <para>Command length in bytes.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>command</parameter></term>
        <listitem>
        <para>Pointer to the buffer that conveys the command to be sent
        to the card or cardterminal.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>lenr</parameter></term>
        <listitem>
        <para>Before function call, pointer to a variable containig the 
	maximum buffer size in bytes for the response data. After 
	successful function call it contains the size in bytes of the 
	response data.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><parameter>response</parameter></term>
        <listitem>
        <para>Pointer to the response data. Memory buffer of at least the size
        in bytes specified in <parameter>lenr</parameter> must be allocated 
	before calling to the function.
        </para>
        </listitem>
        </varlistentry>

        </variablelist>

        <!-- CT_close -->
        <para><function>CT_close()</function> terminates the communication 
	with the cardterminal which has been assigned to a logical cardterminal
	number by the function <function>CT_init()</function>. The function 
	shall be called for each initialized cardtreminal before the end of 
	the program in order to free resources if necessary.
        </para>

        <variablelist>

        <varlistentry>
        <term><parameter>ctn</parameter></term>
        <listitem>
        <para>Cardterminal number: as specified in <function>CT_init()
	</function> call for this cardterminal.
        </para>
        </listitem>
        </varlistentry>

        </variablelist>


</refsect1>

<refsect1>

        <title>RETURN VALUE</title>

        <para><function>CT_init(),</function> <function>CT_data(),</function>
        and <function>CT_close()</function> functions return a value of type
        char.
        </para>

        <variablelist>

        <varlistentry>
        <term><returnvalue>OK</returnvalue></term>
        <listitem>
        <para>Function call was successful.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><returnvalue>ERR_INVALID</returnvalue></term>
        <listitem>
        <para>Invalid parameter or value.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><returnvalue>ERR_CT</returnvalue></term>
        <listitem>
        <para>Cardterminal Error. The cardterminal is temporarily not
        accessible (busy with  other or internal processes). The problem can
        be solved by the application.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><returnvalue>ERR_TRANS</returnvalue></term>
        <listitem>
        <para>Transmission Error. Transmission errors due to mechanical, 
	electrical or protocol failures. Reset of the cardterminal is 
	necessary.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><returnvalue>ERR_MEMORY</returnvalue></term>
        <listitem>
        <para>Memory assignment error. A memory error occurred (f.i. the 
	allocated buffer is too small for the returned data).
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term><returnvalue>ERR_HTSI</returnvalue></term>
        <listitem>
        <para>Host Transport Service Interface error. Commonly returned if
        the error is produced by the software layer and not in the 
	communication with the hardware.
        </para>
        </listitem>
        </varlistentry>


</variablelist>

</refsect1>

<refsect1>

        <title>SEE ALSO</title>

	<para>ctbcs (3).</para>

        <para>The <productname>MKT</productname> (Multifunktionale 
	KartenTerminals) specifications, available for download from 
	<acronym>Teletrust</acronym> website 
	<ulink url="http://www.teletrust.de">http://www.teletrust.de</ulink>.
        In special the documents:</para>

        <variablelist>

        <varlistentry>
        <term>Part 3:</term>
        <listitem>
        <para>CT-API. Cardterminal Applications Programming Interface.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term>Part 4:</term>
        <listitem>
        <para>CT-BCS. Cardterminal Basic Command Set.
        </para>
        </listitem>
        </varlistentry>

        <varlistentry>
        <term>Part 7:</term>
        <listitem>
        <para>IC cards with synchronous transmission Part3: Usage of 
	interindustry Commands.
        </para>
        </listitem>
        </varlistentry>

        </variablelist>

	<para>
	ISO/IEC 7816: <productname>Identification cards - Integrated circuit(s) 
	cards with contacts</productname>: 
	</para>

	<variablelist>

	<varlistentry>
	<term>Part 4:</term>
	<listitem>
	<para>
	Interindustry commands for interchange.
	</para>
	</listitem>
	</varlistentry>

	</variablelist>

</refsect1>

<refsect1>

        <title>AUTHOR</title>

        <para>
	This manual page was written by Carlos Prados 
	<email>&lt;cprados@yahoo.com&gt;</email>.
        </para>

</refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:2
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:nil
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
