| 1 |
/*
|
| 2 |
utils.c:
|
| 3 |
Copyright (C) 2003-2004 Ludovic Rousseau
|
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify
|
| 6 |
it under the terms of the GNU General Public License as published by
|
| 7 |
the Free Software Foundation; either version 2 of the License, or
|
| 8 |
(at your option) any later version.
|
| 9 |
|
| 10 |
This program 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
|
| 13 |
GNU General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License
|
| 16 |
along with this program; if not, write to the Free Software
|
| 17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 18 |
*/
|
| 19 |
|
| 20 |
/*
|
| 21 |
* $Id$
|
| 22 |
*/
|
| 23 |
|
| 24 |
#include <PCSC/pcsclite.h>
|
| 25 |
|
| 26 |
#include "ccid.h"
|
| 27 |
#include "defs.h"
|
| 28 |
#include "ccid_ifdhandler.h"
|
| 29 |
#include "utils.h"
|
| 30 |
#include "debug.h"
|
| 31 |
|
| 32 |
int ReaderIndex[CCID_DRIVER_MAX_READERS];
|
| 33 |
|
| 34 |
void InitReaderIndex(void)
|
| 35 |
{
|
| 36 |
int i;
|
| 37 |
|
| 38 |
for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
|
| 39 |
ReaderIndex[i] = -1;
|
| 40 |
} /* InitReaderIndex */
|
| 41 |
|
| 42 |
int GetNewReaderIndex(const DWORD Lun)
|
| 43 |
{
|
| 44 |
int i;
|
| 45 |
|
| 46 |
for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
|
| 47 |
if (-1 == ReaderIndex[i])
|
| 48 |
{
|
| 49 |
ReaderIndex[i] = Lun;
|
| 50 |
return i;
|
| 51 |
}
|
| 52 |
|
| 53 |
DEBUG_CRITICAL("ReaderIndex[] is full");
|
| 54 |
return -1;
|
| 55 |
} /* GetReaderIndex */
|
| 56 |
|
| 57 |
int LunToReaderIndex(const DWORD Lun)
|
| 58 |
{
|
| 59 |
int i;
|
| 60 |
|
| 61 |
for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
|
| 62 |
if (Lun == ReaderIndex[i])
|
| 63 |
return i;
|
| 64 |
|
| 65 |
DEBUG_CRITICAL2("Lun: %X not found", Lun);
|
| 66 |
return -1;
|
| 67 |
} /* LunToReaderIndex */
|
| 68 |
|
| 69 |
int ReleaseReaderIndex(const int index)
|
| 70 |
{
|
| 71 |
ReaderIndex[index] = -1;
|
| 72 |
} /* ReleaseReaderIndex */
|
| 73 |
|