3 Copyright (C) 2003-2008 Ludovic Rousseau
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "ccid_ifdhandler.h"
30 int ReaderIndex[CCID_DRIVER_MAX_READERS];
32 void InitReaderIndex(void)
36 for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
38 } /* InitReaderIndex */
40 int GetNewReaderIndex(const int Lun)
44 /* check that Lun is NOT already used */
45 for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
46 if (Lun == ReaderIndex[i])
49 if (i < CCID_DRIVER_MAX_READERS)
51 DEBUG_CRITICAL2("Lun: %d is already used", Lun);
55 for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
56 if (-1 == ReaderIndex[i])
62 DEBUG_CRITICAL("ReaderIndex[] is full");
64 } /* GetReaderIndex */
66 int LunToReaderIndex(const int Lun)
70 for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
71 if (Lun == ReaderIndex[i])
74 DEBUG_CRITICAL2("Lun: %X not found", Lun);
76 } /* LunToReaderIndex */
78 void ReleaseReaderIndex(const int index)
80 ReaderIndex[index] = -1;
81 } /* ReleaseReaderIndex */
83 /* Read a non aligned 16-bit integer */
84 uint16_t get_U16(void *buf)
88 memcpy(&value, buf, sizeof value);
93 /* Read a non aligned 32-bit integer */
94 uint32_t get_U32(void *buf)
98 memcpy(&value, buf, sizeof value);
103 /* Write a non aligned 16-bit integer */
104 void set_U16(void *buf, uint16_t value)
106 memcpy(buf, &value, sizeof value);
109 /* Write a non aligned 32-bit integer */
110 void set_U32(void *buf, uint32_t value)
112 memcpy(buf, &value, sizeof value);
115 /* swap a 16-bits integer in memory */
117 void p_bswap_16(void *ptr)
127 /* swap a 32-bits integer in memory */
128 /* "ABCD" -> "DCBA" */
129 void p_bswap_32(void *ptr)