| 1 |
#!/usr/bin/env python
|
| 2 |
|
| 3 |
"""
|
| 4 |
# short_apdu_readers.py get a list of short APDU readers
|
| 5 |
# Copyright (C) 2009 Ludovic Rousseau
|
| 6 |
#
|
| 7 |
# This program is free software; you can redistribute it and/or modify
|
| 8 |
# it under the terms of the GNU General Public License as published by
|
| 9 |
# the Free Software Foundation; either version 2 of the License, or
|
| 10 |
# (at your option) any later version.
|
| 11 |
#
|
| 12 |
# This program is distributed in the hope that it will be useful,
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 15 |
# GNU General Public License for more details.
|
| 16 |
#
|
| 17 |
# You should have received a copy of the GNU General Public License along
|
| 18 |
# with this program; if not, write to the Free Software Foundation, Inc.,
|
| 19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
| 20 |
"""
|
| 21 |
|
| 22 |
# $Id$
|
| 23 |
|
| 24 |
from matrix import *
|
| 25 |
import sys
|
| 26 |
|
| 27 |
CCID_CLASS_AUTO_CONF_ATR = 0x00000002
|
| 28 |
CCID_CLASS_AUTO_VOLTAGE = 0x00000008
|
| 29 |
CCID_CLASS_AUTO_BAUD = 0x00000020
|
| 30 |
CCID_CLASS_AUTO_PPS_PROP = 0x00000040
|
| 31 |
CCID_CLASS_AUTO_PPS_CUR = 0x00000080
|
| 32 |
CCID_CLASS_AUTO_IFSD = 0x00000400
|
| 33 |
CCID_CLASS_ICCD = 0x00000800
|
| 34 |
CCID_CLASS_CHARACTER = 0x00000000
|
| 35 |
CCID_CLASS_TPDU = 0x00010000
|
| 36 |
CCID_CLASS_SHORT_APDU = 0x00020000
|
| 37 |
CCID_CLASS_EXTENDED_APDU = 0x00040000
|
| 38 |
CCID_CLASS_EXCHANGE_MASK = 0x00070000
|
| 39 |
|
| 40 |
path = "../trunk/Drivers/ccid/readers/"
|
| 41 |
|
| 42 |
|
| 43 |
def get_extended_apdu_readers(readers):
|
| 44 |
""" return the list of readers supporting extended APDU """
|
| 45 |
d = {}
|
| 46 |
for r in readers.keys():
|
| 47 |
dwFeatures = int(readers[r]['dwFeatures'], 16)
|
| 48 |
# TPDU level exchanges with CCID
|
| 49 |
if (dwFeatures & CCID_CLASS_EXCHANGE_MASK) == CCID_CLASS_TPDU:
|
| 50 |
d[r] = readers[r]
|
| 51 |
# Extended APDU level exchange with CCID
|
| 52 |
if (dwFeatures & CCID_CLASS_EXCHANGE_MASK) == CCID_CLASS_EXTENDED_APDU:
|
| 53 |
d[r] = readers[r]
|
| 54 |
|
| 55 |
return d
|
| 56 |
|
| 57 |
|
| 58 |
def get_short_apdu_readers(readers):
|
| 59 |
""" return the list of readers NOT supporting extended APDU """
|
| 60 |
d = {}
|
| 61 |
for r in readers.keys():
|
| 62 |
dwFeatures = int(readers[r]['dwFeatures'], 16)
|
| 63 |
# Short APDU level exchange with CCID
|
| 64 |
if (dwFeatures & CCID_CLASS_EXCHANGE_MASK) == CCID_CLASS_SHORT_APDU:
|
| 65 |
d[r] = readers[r]
|
| 66 |
|
| 67 |
return d
|
| 68 |
|
| 69 |
|
| 70 |
def apdu_no_ifsd(readers):
|
| 71 |
""" return the list of Short APDU readers doing auto IFSD """
|
| 72 |
for r in readers.keys():
|
| 73 |
dwFeatures = int(readers[r]['dwFeatures'], 16)
|
| 74 |
# Short APDU level exchange with CCID
|
| 75 |
if ((dwFeatures & CCID_CLASS_EXCHANGE_MASK) == CCID_CLASS_SHORT_APDU and not(dwFeatures & CCID_CLASS_ICCD)):
|
| 76 |
print r,
|
| 77 |
if (dwFeatures & CCID_CLASS_AUTO_IFSD):
|
| 78 |
print "CCID_CLASS_AUTO_IFSD"
|
| 79 |
else:
|
| 80 |
print "NON"
|
| 81 |
|
| 82 |
|
| 83 |
def extended_apdu(readers):
|
| 84 |
""" return the list of APDU readers supporting extended APDU """
|
| 85 |
for r in readers.keys():
|
| 86 |
dwFeatures = int(readers[r]['dwFeatures'], 16)
|
| 87 |
# Short APDU level exchange with CCID
|
| 88 |
if ((dwFeatures & CCID_CLASS_EXCHANGE_MASK) == CCID_CLASS_EXTENDED_APDU):
|
| 89 |
print r
|
| 90 |
|
| 91 |
|
| 92 |
def get_all_readers():
|
| 93 |
""" returns the list of all readers """
|
| 94 |
|
| 95 |
supported_readers = parse_ini(path, "supported")
|
| 96 |
shouldwork_readers = parse_ini(path, "shouldwork")
|
| 97 |
unsupported_readers = parse_ini(path, "unsupported")
|
| 98 |
|
| 99 |
# all_readers contains the union of the 3 lists
|
| 100 |
all_readers = dict(supported_readers)
|
| 101 |
all_readers.update(shouldwork_readers)
|
| 102 |
all_readers.update(unsupported_readers)
|
| 103 |
|
| 104 |
return all_readers
|
| 105 |
|
| 106 |
if __name__ == "__main__":
|
| 107 |
all_readers = get_all_readers()
|
| 108 |
cat_name = {"supported": "Supported readers",
|
| 109 |
"shouldwork": "Should work readers",
|
| 110 |
"unsupported": "Unsupported readers"}
|
| 111 |
|
| 112 |
for cat in ["supported", "shouldwork", "unsupported"]:
|
| 113 |
all_readers = parse_ini(path, cat)
|
| 114 |
|
| 115 |
if len(sys.argv) > 1:
|
| 116 |
readers = get_extended_apdu_readers(all_readers)
|
| 117 |
else:
|
| 118 |
readers = get_short_apdu_readers(all_readers)
|
| 119 |
|
| 120 |
# sort the readers by manufacturers
|
| 121 |
manufacturer_readers = get_by_manufacturer(readers)
|
| 122 |
manufacturers = list(manufacturer_readers)
|
| 123 |
# sort the manufacturers list alphabetically
|
| 124 |
manufacturers.sort(key=str.lower)
|
| 125 |
|
| 126 |
print "<li>%s<ul>" % cat_name[cat]
|
| 127 |
|
| 128 |
# for each manufacturer
|
| 129 |
for m in manufacturers:
|
| 130 |
# for each reader
|
| 131 |
for r in sorted(manufacturer_readers[m]):
|
| 132 |
|
| 133 |
print '<li>%s <a href="ccid/%s.html#%s%s">%s</a></li>' % (all_readers[r]['iManufacturer'], all_readers[r]['section'], all_readers[r]['idVendor'], all_readers[r]['idProduct'], all_readers[r]['iProduct'])
|
| 134 |
|
| 135 |
print "</ul>"
|