[Pcsclite-cvs-commit] r2431 - in trunk/Drivers/ccid: . contrib contrib/midswitch

Ludovic Rousseau rousseau at alioth.debian.org
Sat Feb 24 18:41:25 CET 2007


Author: rousseau
Date: 2007-02-24 18:41:24 +0100 (Sat, 24 Feb 2007)
New Revision: 2431

Added:
   trunk/Drivers/ccid/contrib/
   trunk/Drivers/ccid/contrib/Makefile.am
   trunk/Drivers/ccid/contrib/midswitch/
   trunk/Drivers/ccid/contrib/midswitch/Makefile.am
   trunk/Drivers/ccid/contrib/midswitch/README.txt
   trunk/Drivers/ccid/contrib/midswitch/midswitch.c
Modified:
   trunk/Drivers/ccid/Makefile.am
   trunk/Drivers/ccid/configure.in
Log:
add contrib/midswitch to activate the CCID reader of the Kobil mIDentity


Modified: trunk/Drivers/ccid/Makefile.am
===================================================================
--- trunk/Drivers/ccid/Makefile.am	2007-02-23 17:09:49 UTC (rev 2430)
+++ trunk/Drivers/ccid/Makefile.am	2007-02-24 17:41:24 UTC (rev 2431)
@@ -1,6 +1,6 @@
 # $Id$
 
-SUBDIRS = aclocal src readers examples
+SUBDIRS = aclocal src readers examples contrib
 
 AUX_DIST = \
 	$(ac_aux_dir)/aclocal.m4 \

Modified: trunk/Drivers/ccid/configure.in
===================================================================
--- trunk/Drivers/ccid/configure.in	2007-02-23 17:09:49 UTC (rev 2430)
+++ trunk/Drivers/ccid/configure.in	2007-02-24 17:41:24 UTC (rev 2431)
@@ -261,6 +261,8 @@
 	aclocal/Makefile
 	src/Makefile
 	readers/Makefile
+	contrib/Makefile
+	contrib/midswitch/Makefile
 	examples/Makefile)
 
 AC_OUTPUT

Added: trunk/Drivers/ccid/contrib/Makefile.am
===================================================================
--- trunk/Drivers/ccid/contrib/Makefile.am	2007-02-23 17:09:49 UTC (rev 2430)
+++ trunk/Drivers/ccid/contrib/Makefile.am	2007-02-24 17:41:24 UTC (rev 2431)
@@ -0,0 +1 @@
+SUBDIRS = midswitch

Added: trunk/Drivers/ccid/contrib/midswitch/Makefile.am
===================================================================
--- trunk/Drivers/ccid/contrib/midswitch/Makefile.am	2007-02-23 17:09:49 UTC (rev 2430)
+++ trunk/Drivers/ccid/contrib/midswitch/Makefile.am	2007-02-24 17:41:24 UTC (rev 2431)
@@ -0,0 +1,3 @@
+sbin_PROGRAMS = midswitch
+midswitch_SOURCES = midswitch.c
+midswitch_LDADD = -lusb

Added: trunk/Drivers/ccid/contrib/midswitch/README.txt
===================================================================
--- trunk/Drivers/ccid/contrib/midswitch/README.txt	2007-02-23 17:09:49 UTC (rev 2430)
+++ trunk/Drivers/ccid/contrib/midswitch/README.txt	2007-02-24 17:41:24 UTC (rev 2431)
@@ -0,0 +1,250 @@
+The midswitch program is used to activate the Kobil mIDenty smart card
+CCID reader.
+
+The USB device is by default:
+  ID 0d46:4081 Kobil Systems GmbH mIDentity Basic/Classic (installationless)
+and will be switched to:
+  ID 0d46:4001 Kobil Systems GmbH mIDentity Basic/Classic (composite device)
+
+
+Bus 005 Device 016: ID 0d46:4081 Kobil Systems GmbH mIDentity Basic/Classic (installationless)
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               2.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0d46 Kobil Systems GmbH
+  idProduct          0x4081 mIDentity Basic/Classic (installationless)
+  bcdDevice            0.00
+  iManufacturer           1 KOBIL Systems
+  iProduct                2 mIDentity M 
+  iSerial                 3 SN_K_05C901085
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength           57
+    bNumInterfaces          2
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              400mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass         8 Mass Storage
+      bInterfaceSubClass      6 SCSI
+      bInterfaceProtocol     80 Bulk (Zip)
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0200  1x 512 bytes
+        bInterval               0
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x86  EP 6 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0200  1x 512 bytes
+        bInterval               0
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         3 Human Interface Devices
+      bInterfaceSubClass      1 Boot Interface Subclass
+      bInterfaceProtocol      0 None
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval               8
+        UNRECOGNIZED:  09 21 00 01 00 01 22 22 00
+Device Qualifier (for other device speed):
+  bLength                10
+  bDescriptorType         6
+  bcdUSB               2.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  bNumConfigurations      1
+Device Status:     0x0002
+  (Bus Powered)
+  Remote Wakeup Enabled
+
+
+Bus 005 Device 015: ID 0d46:4001 Kobil Systems GmbH mIDentity Basic/Classic (composite device)
+Device Descriptor:
+  bLength                18
+  bDescriptorType         1
+  bcdUSB               2.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  idVendor           0x0d46 Kobil Systems GmbH
+  idProduct          0x4001 mIDentity Basic/Classic (composite device)
+  bcdDevice            0.00
+  iManufacturer           1 KOBIL Systems
+  iProduct                2 mIDentity M 
+  iSerial                 3 SN_K_05C901085
+  bNumConfigurations      1
+  Configuration Descriptor:
+    bLength                 9
+    bDescriptorType         2
+    wTotalLength          134
+    bNumInterfaces          3
+    bConfigurationValue     1
+    iConfiguration          0 
+    bmAttributes         0x80
+      (Bus Powered)
+    MaxPower              400mA
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        0
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass         8 Mass Storage
+      bInterfaceSubClass      6 SCSI
+      bInterfaceProtocol     80 Bulk (Zip)
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x02  EP 2 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0200  1x 512 bytes
+        bInterval               0
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x86  EP 6 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0200  1x 512 bytes
+        bInterval               0
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        1
+      bAlternateSetting       0
+      bNumEndpoints           2
+      bInterfaceClass        11 Chip/SmartCard
+      bInterfaceSubClass      0 
+      bInterfaceProtocol      0 
+      iInterface              0 
+      ChipCard Interface Descriptor:
+        bLength                54
+        bDescriptorType        33
+        bcdCCID              1.00
+        nMaxSlotIndex           0
+        bVoltageSupport         7  5.0V 3.0V 1.8V 
+        dwProtocols             3  T=0 T=1
+        dwDefaultClock       4000
+        dwMaxiumumClock      4000
+        bNumClockSupported      0
+        dwDataRate          10752 bps
+        dwMaxDataRate      250000 bps
+        bNumDataRatesSupp.      0
+        dwMaxIFSD             254
+        dwSyncProtocols  00000000 
+        dwMechanical     00000000 
+        dwFeatures       000206BA
+          Auto configuration based on ATR
+          Auto voltage selection
+          Auto clock change
+          Auto baud rate change
+          Auto PPS made by CCID
+          NAD value other than 0x00 accpeted
+          Auto IFSD exchange
+          Short APDU level exchange
+        dwMaxCCIDMsgLen       271
+        bClassGetResponse    echo
+        bClassEnvelope       echo
+        wlcdLayout           none
+        bPINSupport             0 
+        bMaxCCIDBusySlots       1
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x04  EP 4 OUT
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0200  1x 512 bytes
+        bInterval               0
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x88  EP 8 IN
+        bmAttributes            2
+          Transfer Type            Bulk
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0200  1x 512 bytes
+        bInterval               0
+    Interface Descriptor:
+      bLength                 9
+      bDescriptorType         4
+      bInterfaceNumber        2
+      bAlternateSetting       0
+      bNumEndpoints           1
+      bInterfaceClass         3 Human Interface Devices
+      bInterfaceSubClass      1 Boot Interface Subclass
+      bInterfaceProtocol      0 None
+      iInterface              0 
+      Endpoint Descriptor:
+        bLength                 7
+        bDescriptorType         5
+        bEndpointAddress     0x81  EP 1 IN
+        bmAttributes            3
+          Transfer Type            Interrupt
+          Synch Type               None
+          Usage Type               Data
+        wMaxPacketSize     0x0040  1x 64 bytes
+        bInterval              10
+        UNRECOGNIZED:  09 21 00 01 00 01 22 22 00
+Device Qualifier (for other device speed):
+  bLength                10
+  bDescriptorType         6
+  bcdUSB               2.00
+  bDeviceClass            0 (Defined at Interface level)
+  bDeviceSubClass         0 
+  bDeviceProtocol         0 
+  bMaxPacketSize0        64
+  bNumConfigurations      1
+Device Status:     0x0002
+  (Bus Powered)
+  Remote Wakeup Enabled

Added: trunk/Drivers/ccid/contrib/midswitch/midswitch.c
===================================================================
--- trunk/Drivers/ccid/contrib/midswitch/midswitch.c	2007-02-23 17:09:49 UTC (rev 2430)
+++ trunk/Drivers/ccid/contrib/midswitch/midswitch.c	2007-02-24 17:41:24 UTC (rev 2431)
@@ -0,0 +1,199 @@
+/*
+    Activate the smartcard interface on the kobil midentity usb device
+    Copyright (C) 2006  Norbert Federa <norbert.federa at neoware.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Author:	Norbert Federa <norbert.federa at neoware.com>
+Date:   2006-04-06
+
+
+Description:
+
+This tool is needed to activate the smartcard interface on the kobil midentity
+usb device (vendor 0x04D6 id 0x4081)
+
+Kobil's own implementation was a kernel usb driver which did just send a
+usb_control_msg in the probe routine.
+
+We do the same via libusb and call this program from our /sbin/hotblug script
+if the mIDentity gets added.
+
+The kobil switcher driver was found inside this zip ...
+http://www.kobil.com/download/partner/KOBIL_mIDentity_SDK_Build_20060320_RELEASE.zip
+... under Interfaces/Linux/module_with_binary_final.tar.gz.
+
+Here the interesting part of the kernel driver inside the probe function:
+
+        if (dev->descriptor.idVendor == KOBIL_VENDOR_ID){
+                printk("!!!!! DEVICE FOUND !!! !\n");
+		ret = usb_control_msg(dev,
+		send_pipe,
+		0x09,
+		0x22,
+		0x0200,
+		0x0001,
+		switchCmd,
+		sizeof(switchCmd),
+		5000);
+	}
+
+Initally the it did not work with libusb because the ioctl gets ignored with
+the used RequestType of 0x22 in combination with index 0x0001, but index 0x0002
+worked.  See usb/devio.c functions  proc_control() ->  check_ctrlrecip() ->
+findintfep() in order to understand why.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <usb.h>
+#include <errno.h>
+
+
+#define KOBIL_VENDOR_ID		0x0D46
+#define MID_DEVICE_ID 		0x4081
+#define KOBIL_TIMEOUT		5000
+#define VAL_STARTUP_4080        1
+#define VAL_STARTUP_4000        2
+#define VAL_STARTUP_4020        3
+#define VAL_STARTUP_40A0        4
+#define HIDCMD_SWITCH_DEVICE    0x0004
+
+#define bmRequestType           0x22
+#define bRequest                0x09
+#define wValue                  0x0200
+#define wIndex                  0x0002  // this was originally 0x0001
+
+
+static int kobil_midentity_control_msg(usb_dev_handle *usb)
+{
+    int ret;
+
+    char switchCmd[10];
+
+    unsigned char Sleep = 1;
+    unsigned char hardDisk = 1;
+
+    unsigned char param = ((hardDisk)<<4) | (Sleep);
+
+    memset(switchCmd, 0x0, sizeof(switchCmd));
+    switchCmd[0] = HIDCMD_SWITCH_DEVICE>>8;
+    switchCmd[1] = HIDCMD_SWITCH_DEVICE;
+    switchCmd[5] = VAL_STARTUP_4000;
+    switchCmd[9] = param;
+
+	ret = usb_control_msg(usb, bmRequestType, bRequest, wValue, wIndex,
+		switchCmd, sizeof(switchCmd), KOBIL_TIMEOUT);
+
+    return(!(ret==sizeof(switchCmd)));
+}
+
+
+static int kobil_midentity_claim_interface(usb_dev_handle *usb, int ifnum)
+{
+    int rv;
+
+    printf("claiming interface #%d ...\n", ifnum);
+    rv = usb_claim_interface(usb, ifnum);
+    if (rv == 0)
+	{
+		printf("success\n");
+		return(rv);
+    }
+
+    printf("failed with error %d, trying to detach kernel driver ....\n", rv);
+    rv = usb_detach_kernel_driver_np(usb, ifnum);
+    if (rv == 0)
+    {
+		printf("success, claiming interface again ...");
+		rv = usb_claim_interface(usb, ifnum);
+		if (rv == 0)
+		{
+			printf("success\n");
+			return(rv);
+		}
+    }
+    printf("failed with error %d, giving up.\n", rv);
+    return(rv);
+}
+
+
+int main(int argc, char *argv[])
+{
+    struct usb_bus *bus;
+    struct usb_device *dev = NULL;
+    struct usb_device *found_dev = NULL;
+    usb_dev_handle *usb = NULL;
+    int rv;
+
+    usb_init();
+
+    usb_find_busses();
+    usb_find_devices();
+
+	for (bus = usb_busses; bus; bus = bus->next)
+	{
+		for (dev = bus->devices; dev; dev = dev->next)
+		{
+			printf("vendor/product: %04X %04X\n",
+				dev->descriptor.idVendor, dev->descriptor.idProduct);
+			if (dev->descriptor.idVendor == KOBIL_VENDOR_ID
+				&& dev->descriptor.idProduct ==MID_DEVICE_ID)
+			{
+				found_dev = dev;
+			}
+		}
+	}
+
+    if (found_dev == NULL)
+	{
+		printf("device not found. aborting.\n");
+		exit(1);
+    }
+
+	printf("Device found, opening ... ");
+	usb = usb_open(found_dev);
+	if (!usb)
+	{
+		printf("failed, aborting.\n");
+		exit(2);
+	}
+	printf("success\n");
+
+	rv = kobil_midentity_claim_interface(usb, 0);
+	if (rv < 0)
+	{
+		usb_close(usb);
+		exit(3);
+	}
+	rv = kobil_midentity_claim_interface(usb, 1);
+	if (rv < 0)
+	{
+		usb_close(usb);
+		exit(3);
+	}
+
+	printf("Activating the CCID configuration .... ");
+	rv = kobil_midentity_control_msg(usb);
+	if (rv == 0)
+		printf("success\n");
+	else
+		printf("failed with error %d, giving up.\n", rv);
+
+    usb_close(usb);
+
+    return 0;
+}
+




More information about the Pcsclite-cvs-commit mailing list