| 1 |
/*
|
| 2 |
utils.c:
|
| 3 |
Copyright (C) 2003-2004 Ludovic Rousseau
|
| 4 |
|
| 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.
|
| 9 |
|
| 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.
|
| 14 |
|
| 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.
|
| 18 |
*/
|
| 19 |
|
| 20 |
/*
|
| 21 |
* $Id$
|
| 22 |
*/
|
| 23 |
|
| 24 |
#include <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 int Lun)
|
| 43 |
{
|
| 44 |
int i;
|
| 45 |
|
| 46 |
/* check that Lun is NOT already used */
|
| 47 |
for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
|
| 48 |
if (Lun == ReaderIndex[i])
|
| 49 |
break;
|
| 50 |
|
| 51 |
if (i < CCID_DRIVER_MAX_READERS)
|
| 52 |
{
|
| 53 |
DEBUG_CRITICAL2("Lun: %d is already used", Lun);
|
| 54 |
return -1;
|
| 55 |
}
|
| 56 |
|
| 57 |
for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
|
| 58 |
if (-1 == ReaderIndex[i])
|
| 59 |
{
|
| 60 |
ReaderIndex[i] = Lun;
|
| 61 |
return i;
|
| 62 |
}
|
| 63 |
|
| 64 |
DEBUG_CRITICAL("ReaderIndex[] is full");
|
| 65 |
return -1;
|
| 66 |
} /* GetReaderIndex */
|
| 67 |
|
| 68 |
int LunToReaderIndex(const int Lun)
|
| 69 |
{
|
| 70 |
int i;
|
| 71 |
|
| 72 |
for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
|
| 73 |
if (Lun == ReaderIndex[i])
|
| 74 |
return i;
|
| 75 |
|
| 76 |
DEBUG_CRITICAL2("Lun: %X not found", Lun);
|
| 77 |
return -1;
|
| 78 |
} /* LunToReaderIndex */
|
| 79 |
|
| 80 |
void ReleaseReaderIndex(const int index)
|
| 81 |
{
|
| 82 |
ReaderIndex[index] = -1;
|
| 83 |
} /* ReleaseReaderIndex */
|
| 84 |
|