| 102 |
int fd; |
int fd; |
| 103 |
|
|
| 104 |
/* |
/* |
| 105 |
* channel used (1..4) |
* device used ("/dev/ttyS?" under Linux) |
| 106 |
*/ |
*/ |
| 107 |
int channel; |
char *device; |
| 108 |
|
|
| 109 |
/* |
/* |
| 110 |
* serial communication buffer |
* serial communication buffer |
| 132 |
#include "ccid_serial.h" |
#include "ccid_serial.h" |
| 133 |
|
|
| 134 |
static _serialDevice serialDevice[PCSCLITE_MAX_READERS] = { |
static _serialDevice serialDevice[PCSCLITE_MAX_READERS] = { |
| 135 |
[ 0 ... (PCSCLITE_MAX_READERS-1) ] = { -1, -1 } |
[ 0 ... (PCSCLITE_MAX_READERS-1) ] = { -1, NULL } |
| 136 |
}; |
}; |
| 137 |
|
|
| 138 |
/***************************************************************************** |
/***************************************************************************** |
| 427 |
status_t OpenSerial(int lun, int channel) |
status_t OpenSerial(int lun, int channel) |
| 428 |
{ |
{ |
| 429 |
char dev_name[FILENAME_MAX]; |
char dev_name[FILENAME_MAX]; |
|
struct termios current_termios; |
|
|
int i; |
|
|
int reader = LunToReaderIndex(lun); |
|
| 430 |
|
|
| 431 |
DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel); |
DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel); |
| 432 |
|
|
| 453 |
|
|
| 454 |
sprintf(dev_name, "/dev/pcsc/%d", (int) channel); |
sprintf(dev_name, "/dev/pcsc/%d", (int) channel); |
| 455 |
|
|
| 456 |
|
return OpenSerialByName(lun, dev_name); |
| 457 |
|
} /* OpenSerial */ |
| 458 |
|
|
| 459 |
|
/***************************************************************************** |
| 460 |
|
* |
| 461 |
|
* OpenSerialByName: open the port |
| 462 |
|
* |
| 463 |
|
*****************************************************************************/ |
| 464 |
|
status_t OpenSerialByName(int lun, char *dev_name) |
| 465 |
|
{ |
| 466 |
|
struct termios current_termios; |
| 467 |
|
int i; |
| 468 |
|
int reader = LunToReaderIndex(lun); |
| 469 |
|
|
| 470 |
|
DEBUG_COMM3("Lun: %X, Device: %d", lun, dev_name); |
| 471 |
|
|
| 472 |
/* check if the same channel is not already used */ |
/* check if the same channel is not already used */ |
| 473 |
for (i=0; i<PCSCLITE_MAX_READERS; i++) |
for (i=0; i<PCSCLITE_MAX_READERS; i++) |
| 474 |
{ |
{ |
| 475 |
if (serialDevice[i].channel == channel) |
if (serialDevice[i].device && |
| 476 |
|
strcmp(serialDevice[i].device, dev_name) == 0) |
| 477 |
{ |
{ |
| 478 |
DEBUG_CRITICAL2("Channel %s already in use", dev_name); |
DEBUG_CRITICAL2("Device %s already in use", dev_name); |
| 479 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 480 |
} |
} |
| 481 |
} |
} |
| 489 |
} |
} |
| 490 |
|
|
| 491 |
/* set channel used */ |
/* set channel used */ |
| 492 |
serialDevice[reader].channel = channel; |
serialDevice[reader].device = strdup(dev_name); |
| 493 |
|
|
| 494 |
/* empty in and out serial buffers */ |
/* empty in and out serial buffers */ |
| 495 |
if (tcflush(serialDevice[reader].fd, TCIOFLUSH)) |
if (tcflush(serialDevice[reader].fd, TCIOFLUSH)) |
| 541 |
serialDevice[reader].buffer_offset_last = 0; |
serialDevice[reader].buffer_offset_last = 0; |
| 542 |
|
|
| 543 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
| 544 |
} /* OpenSerial */ |
} /* OpenSerialByName */ |
| 545 |
|
|
| 546 |
|
|
| 547 |
/***************************************************************************** |
/***************************************************************************** |
| 554 |
int reader = LunToReaderIndex(lun); |
int reader = LunToReaderIndex(lun); |
| 555 |
|
|
| 556 |
close(serialDevice[reader].fd); |
close(serialDevice[reader].fd); |
|
|
|
| 557 |
serialDevice[reader].fd = -1; |
serialDevice[reader].fd = -1; |
| 558 |
serialDevice[reader].channel = -1; |
|
| 559 |
|
free(serialDevice[reader].device); |
| 560 |
|
serialDevice[reader].device = NULL; |
| 561 |
|
|
| 562 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
| 563 |
} /* CloseSerial */ |
} /* CloseSerial */ |