Sample script for sending APDU?

I see there is some code for sending APDUs and CWLite has smartcard connector. Some posts mention it as well.

However I couldn’t find any example anywhere of how to use it. Also since CW301 is no longer in production and doesn’t have schematics, I had to guess where to connect the measure - to Vcc.

The rest is connected to the J6 and J7 connectors. BTW which is the right one? I’d guess the one from FPGA (J6) since it sets the clock.

Can anyone paste an example of how to send an APDU please?

OK I found some sample script in CW 3.5.3 and it also has the schematics for the multitarget board.

Though does anyone have a sample script for 4.x?

Still struggling with settings, like what should be the clock for smartcards? Docs say somewhere between 1 MHz and 5 MHz, which is not helpful. Also not sure if it can change.

Do I use the for connection or do I have to specify different target. There seems to be a separate GUI component in the sources, a descendant of TargetTemplate, but not sure how to use it.

EDIT: so after connecting to oscilloscope it seems the card reader tries 4.7 V and 3.75 MHz. Not sure though if a modern smartcard would work with 3.3V.

EDIT2: after mucking a lot with CW 3.5.3 and 4.0.4 I finally found where the option for smartcard target and settings are. But the target won’t connect:

Traceback (most recent call last):
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/ui/”, line 159, in doConDisTarget
if self.api.connectTarget():
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/common/api/”, line 288, in connectTarget
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/targets/”, line 66, in con
self._con(scope, **kwargs)
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/targets/”, line 76, in _con
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/targets/smartcard_readers/”, line 134, in con
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/targets/smartcard_readers/”, line 144, in reset
self.atr = self.usbcon.readCtrl(self.REQ_CFG, self.REQ_CFG_ATR, 55)
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/hardware/naeusb/”, line 216, in readCtrl
return self.usbdev().ctrl_transfer(0xC1, cmd, value, 0, dlen, timeout=self._timeout)
File “build/bdist.linux-x86_64/egg/usb/”, line 1043, in ctrl_transfer
File “build/bdist.linux-x86_64/egg/usb/backend/”, line 593, in ctrl_transfer
File “build/bdist.linux-x86_64/egg/usb/backend/”, line 431, in _check
raise USBError(errmsg, ret)
USBError: [Errno None] error sending control message: Broken pipe

Tried setting the clock to 3.75 MHz, but I don’t understand why can’t I set it before connecting. But any attempt to get ATR or send APDU fails with the above message.

After just connecting (selecting “ChipWhisperer/OpenADC” scope and “Smart Card” target and pressing connect on the Master button), I always get this error, both in 3.5.3 and in 4.0.4 which seems like a bug, but not sure:

Traceback (most recent call last):
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/ui/”, line 168, in doConDis
if self.api.connect():
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/common/api/”, line 305, in connect
return self.connectScope() and self.connectTarget()
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/common/api/”, line 288, in connectTarget
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/targets/”, line 66, in con
self._con(scope, **kwargs)
File “/home/ondro/.local/lib/python2.7/site-packages/chipwhisperer-4.0.2-py2.7.egg/chipwhisperer/capture/targets/”, line 76, in _con
AttributeError: ‘NoneType’ object has no attribute ‘con’

Tried both J6 and J7 connectors. I am absolutely lost and have no idea what is causing this.


The smartcard module for ChipWhisperer is pretty old and isn’t a commonly used part of the software so it hasn’t been kept up to date with the rest of the software. Judging by some of the errors you’re getting, I’d guess that it didn’t survive the transition from ChipWhipserer 3 to ChipWhipserer 4, which had major changes to the API.

It’ll probably be a while (if at all) before we start working on it, but you’re always welcome to take a crack at it yourself. You should be able to find the relevant files in chipwhisperer/software/capture/targets.


I tried the 3.5.x version as well. Same error. I’d guess there is something wrong with the clock. Since I saw it when I had clock wrong for other MCUs (STM32F3/4 I think).

So if you could give me an example that works for last 3.5.x (3.5.3 was it?) and tell me how to connect it, I can start from there. For instance, with 3.5, if I try to connect to smartcard - connect scope, then select the target as SmartCard and JCard in the options, I will still get the same exception.

What confuses me most is a) how come CW301 multi-board doesn’t use either J6 or J7 b) how to set the correct clock? We measured 3.75 MHz for the clock on oscilloscope, one of the examples I found used 3.579 MHz. I have also CW 308 UFO board and CW506 voltage translation if it’s necessary.

The 3.5.3 used was from the VirtualBox image to make sure I don’t mix the installed python packages.

I looked at the docs, the schematics, but guessing it is quite hard when I don’t know at least quite specific area of things that can be wrong with it. A lot of the smartcard stuff has TODOs and generally missing description.

I checked the CWLite wiki page and it seems that there’s no firmware support for the smartcard connection, which would explain why you were having issues! The Rev 2 it seems did have support for it, which explains the forum posts and the old target module.

Adding smartcard support is pretty far down the list of priorities right now, so it’s a ways off unless someone wants to start developing it. The SAM3U does have smartcard support, so both it and the FPGA will work for development, though I’d imagine that the SAM3U might be a bit easier to use.