source: trunk/csctapi/apdu.h@ 1

Last change on this file since 1 was 1, checked in by root, 14 years ago

initial import

File size: 4.3 KB
Line 
1/*
2 apdu.h
3 Definitions for ISO 7816-4 Application Layer PDU's handling
4
5 This file is part of the Unix driver for Towitoko smartcard readers
6 Copyright (C) 2000 2001 Carlos Prados <cprados@yahoo.com>
7
8 This version is modified by doz21 to work in a special manner ;)
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23*/
24
25#ifndef _APDU_
26#define _APDU_
27
28#include "defines.h"
29
30/*
31 * Exported constants definiton
32 */
33
34/* Return codes */
35#define APDU_OK 0 /* Parsing of APDU OK */
36#define APDU_MALFORMED 5 /* Malformed APDU */
37
38/* Types of APDU's */
39#define APDU_CASE_1 0x0001 /* Nor send neither receive data */
40#define APDU_CASE_2S 0x0002 /* Receive data (1..256) */
41#define APDU_CASE_3S 0x0003 /* Send data (1..255) */
42#define APDU_CASE_4S 0x0004 /* Send data (1..255) and receive data (1..256) */
43#define APDU_CASE_2E 0x0102 /* Receive data (1..65536) */
44#define APDU_CASE_3E 0x0103 /* Send data (1..65535) */
45#define APDU_CASE_4E 0x0104 /* Send data (1..65535) and receive data (1..65536) */
46
47/* Maximum sizes of buffers */
48#define APDU_MAX_CMD_SIZE 65545 /* Max command size */
49#define APDU_MAX_RSP_SIZE 65538 /* Max response size */
50
51/*
52 * Exported macros definition
53 */
54#define APDU_CASE_IS_EXTENDED(c) (((c) & 0x0100) == 0x0100)
55
56/*
57 * Exported data types definition
58 */
59
60/* Command APDU */
61typedef struct
62{
63 BYTE *command;
64 unsigned long length;
65}
66APDU_Cmd;
67
68/* Response APDU */
69typedef struct
70{
71 BYTE *response;
72 unsigned long length;
73}
74APDU_Rsp;
75
76/*
77 * Exported functions declaration
78 */
79
80/* Create a APDU_Cmd */
81extern APDU_Cmd *APDU_Cmd_New (BYTE * data, unsigned long length);
82
83/* Delete a APDU_Cmd */
84extern void APDU_Cmd_Delete (APDU_Cmd * apdu);
85
86/* Return the case of command */
87extern int APDU_Cmd_Case (APDU_Cmd * apdu);
88
89/* Return class of command */
90extern BYTE APDU_Cmd_Cla (APDU_Cmd * apdu);
91
92/* Return command instruction */
93extern BYTE APDU_Cmd_Ins (APDU_Cmd * apdu);
94
95/* Return first paramenter of command */
96extern BYTE APDU_Cmd_P1 (APDU_Cmd * apdu);
97
98/* Return second parameter of command */
99extern BYTE APDU_Cmd_P2 (APDU_Cmd * apdu);
100
101/* Return length of data sent */
102extern unsigned long APDU_Cmd_Lc (APDU_Cmd * apdu);
103
104/* Return length of data expected */
105extern unsigned long APDU_Cmd_Le (APDU_Cmd * apdu);
106
107/* Return TRUE if the command requires all data available */
108extern bool APDU_Cmd_Le_Available (APDU_Cmd * apdu);
109
110/* Return a pointer to the header of the command */
111extern BYTE *APDU_Cmd_Header (APDU_Cmd * apdu);
112
113/* Return a pointer to the data of the comamnd */
114extern BYTE *APDU_Cmd_Data (APDU_Cmd * apdu);
115
116/* Return a pointer to the whole command */
117extern BYTE *APDU_Cmd_Raw (APDU_Cmd * apdu);
118
119/* Return the length of the whole command */
120extern unsigned long APDU_Cmd_RawLen (APDU_Cmd * apdu);
121
122/* Create a APDU_Rsp */
123extern APDU_Rsp *APDU_Rsp_New (BYTE * data, unsigned long length);
124
125/* Delete a APDU_Rsp */
126extern void APDU_Rsp_Delete (APDU_Rsp * apdu);
127
128/* Return fitst status byte */
129extern BYTE APDU_Rsp_SW1 (APDU_Rsp * apdu);
130
131/* Return second status byte */
132extern BYTE APDU_Rsp_SW2 (APDU_Rsp * apdu);
133
134/* Return length of the data of the response */
135extern unsigned long APDU_Rsp_DataLen (APDU_Rsp * apdu);
136
137/* Return a pointer to the data of the response */
138extern BYTE *APDU_Rsp_Data (APDU_Rsp * apdu);
139
140/* Return a pointer to the whole response */
141extern BYTE *APDU_Rsp_Raw (APDU_Rsp * apdu);
142
143/* Return the length of the whole response */
144extern unsigned long APDU_Rsp_RawLen (APDU_Rsp * apdu);
145
146/* Truncate size of response APDU */
147extern void APDU_Rsp_TruncateData (APDU_Rsp * apdu, unsigned long length);
148
149/* Adds one APDU at the end of the data bytes of an APDU */
150extern int APDU_Rsp_AppendData (APDU_Rsp * apdu1, APDU_Rsp * apdu2);
151
152#endif
153
Note: See TracBrowser for help on using the repository browser.