3 Protocol Parameters Selection
5 This file is part of the Unix driver for Towitoko smartcard readers
6 Copyright (C) 2000 2001 Carlos Prados <cprados@yahoo.com>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with this library; if not, write to the Free Software Foundation,
20 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <ifdhandler.h>
38 * Not exported funtions declaration
41 static int PPS_Match (BYTE * request, unsigned len_request, BYTE * reply, unsigned len_reply);
43 static unsigned PPS_GetLength (BYTE * block);
45 static BYTE PPS_GetPCK (BYTE * block, unsigned length);
48 PPS_Exchange (int lun, BYTE * params, unsigned *length, unsigned char *pps1)
50 BYTE confirm[PPS_MAX_LENGTH];
51 unsigned len_request, len_confirm;
54 len_request = PPS_GetLength (params);
55 params[len_request - 1] = PPS_GetPCK(params, len_request - 1);
57 DEBUG_XXD ("PPS: Sending request: ", params, len_request);
59 /* Send PPS request */
60 if (CCID_Transmit (lun, len_request, params, isCharLevel(lun) ? 4 : 0, 0)
65 len_confirm = sizeof(confirm);
66 if (CCID_Receive (lun, &len_confirm, confirm, NULL) != IFD_SUCCESS)
69 DEBUG_XXD ("PPS: Receiving confirm: ", confirm, len_confirm);
71 if (!PPS_Match (params, len_request, confirm, len_confirm))
72 ret = PPS_HANDSAKE_ERROR;
76 *pps1 = 0x11; /* default TA1 */
78 /* if PPS1 is echoed */
79 if (PPS_HAS_PPS1 (params) && PPS_HAS_PPS1 (confirm))
82 /* Copy PPS handsake */
83 memcpy (params, confirm, len_confirm);
84 (*length) = len_confirm;
90 PPS_Match (BYTE * request, unsigned len_request, BYTE * confirm, unsigned len_confirm)
92 /* See if the reply differs from request */
93 if ((len_request == len_confirm) && /* same length */
94 memcmp (request, confirm, len_request)) /* different contents */
97 if (len_request < len_confirm) /* confirm longer than request */
100 /* See if the card specifies other than default FI and D */
101 if ((PPS_HAS_PPS1 (confirm)) && (confirm[2] != request[2]))
108 PPS_GetLength (BYTE * block)
112 if (PPS_HAS_PPS1 (block))
115 if (PPS_HAS_PPS2 (block))
118 if (PPS_HAS_PPS3 (block))
125 PPS_GetPCK (BYTE * block, unsigned length)
131 for (i = 1; i < length; i++)