Smartcard access library

Hi,

As I just started to check out the features the Arduino provides and after finishing several LED, Shift Register etc. projects the time had come for a more demanding project ... And after disassembling a old settop box a Smart Card access lib was started. It is based on the TDA8024T smart card interface chip, which is more or less just a "electrical" protection device and has only minor effect on the communication, it should be also possible to connect the Arduino directly to the smart card contacts (Which I never has tried, but this should work as the eletrical parameters match).

Currently it is able to communication (send / receive) to synchronous (2wire) and asynchronous cards, has autodetection of card type and can be compiled to support only one or the other type.

The checked card base is not representiv as I only could get my hands on the "smart cards" in my wallet ... All of them worked, but only up to a certain level, as most of the communication requires registration for specifications ... The german "Krankenversichertenkarte" is working greatly (Synchronous card - 256Byte EEPROM Card with an open specification).

The next steps I want to take are to remove the "interface chip" (Just buy me a card slot, without any additional hardware) and check out some other cards I can get my hands on, optimizing the library and all the other things a developer does in his spare time :smiley:

The current version is attached and updates can be found on sourceforge (Smartcard Lib for Arduino compat. boards download | SourceForge.net)

Regards

angus

sclib_v0.0.2.zip.zip (9.29 KB)

Hi,
i'm a little confused about your library. Is it designed to work with the TDA8024 interface IC or can it be used to communicate directly between the arduino and the smart card. Secondly some form of schematic as to its connection (if we are connecting directly to the smart card) would help.
thanks.

Hi,

To answer your question in a short way .. It's designed to work with the TDA8024 as this IC was available to me, but as the TDA8024 is mainly used to "decouple" the controling curcit and the smartcard it should be able to communicate directly to the smartcard from the Arduino.

A description "how to connect" the TDA8024 / smart card can be found in the wiki page on sourceforge (Smartcard Lib for Arduino compat. boards / Wiki / Home). I hope this helps ... If more information is needed or you have any comments ... Just let me know

regards

angus

Thanks alot, i'm trying to use your library for a smartcard implementation, i'll sure be in touch if i have more questions.
thanks

Hi Angus,
I'm trying to use your library for a project. I am connecting the smartcard (an ACOS3 contact card 64KB EEPROM) directly to the Arduino without any chip. I want to know which mode, synchronous or asynchronus mode is suitable for the card?
A schematic for direct connecting of the contact pins to the Arduino would be of help too.The card is ISO7816-1,2,3 compliant 8-contact module supporting T=0 direct protocol.

Thanks a lot.
Niyi.

Hi Niyi,

For the mentioned card it should be okay to use it with in asynchronus mode, as it supports the T=0 protocol, which is defined to be asynchronus.

As there is a popular demand for a direct connection of smartcards to the arduino board, I will modify the code / description to reflect the needed wiring, when I'm able to get my hands on a smartcard slot. (I think one of my old set-top boxes is missing it's smart card slot in a minute. So if I'm not burning myself, unsoldering the smart card slot, I will start right away doing the needed modifications.)

If a SCLib version is available I will post an update here (But this might take a week or two :)).

regards

Angus

Hi,

As promised I updated the SCLib to be able to talk directly to a smartcard, without the need to have any interface chip (Just be carefull not to fry any 3.3V GSM cards etc., as currently it works with 5V).

The updated release (0.0.4) can be found here Smartcard Lib for Arduino compat. boards / Wiki / Home. I also provided a schematic how to connect a smartcard slot to the Arduino.

Regards

Angus

Hi Angus,

I'm trying to use your library with the Arduino Mega. Unfortunately so far, I wasn't able to receive the correct ATR.
I'm able to detect when the card is inserted, but then during the cold reset the ATR received isn't the one I'm supposed to received.
And also, each time I reset then plugged I got a different ATR.
I only change PIN CLK by PIN 20.
Do you have some advise?

Thanks,

Hi quertyn,

Nice to hear that you are actually using the Lib. As you are using the Arduino Mega the change to the PIN 20 for the CLK generation might be the problem. I've checked the pin mapping sheet for the Mega (http://arduino.cc/en/Hacking/PinMapping2560) and the digital PIN 20 can not be used as "Timer/Counter OutputCompare Match Output". In my case "OC1A", which is mapped to digital PIN 11 on the Arduino Mega.

First I would recommend to use digital pin 11 as CLK (Currently the use of OC1A is hardcoded, as I didn't found a fast way to determine if a counter is attached to the choosen CLK pin and how to configure it, so that it works all the time). I will look into this problem, but in your case it should work, if you use digital pin 11 and put the Vcc function to another pin.

Secondly. Which version are you using? Currently 0.0.7rc2 is the lastest and releases before 0.0.7 have problems getting certain cards recognized. This process is much more secure in 0.0.7rc2.

Please let me know if this helps.

regards

Angus

Hi Angus,

Sorry for the late reply, i didn't receive any info from the forum about your answer.
Anyway it was very helpful. I made the change using the PIN11 for the CLK.
Now i'm able to retrieve ATR. XD
Thanks for your help.

Quertyn

Hi,
I'm doing a work with SIM card, i want to copy the entire phonebook and message from one sim to another with arduino. Is it possible to use this library for the purpose?? how can i access and copy the phonebook and message location in the sim card?
plz help me
thank you :slight_smile:

Hi s_premkumar999,

In general this should be possible with the library, but first you should check out the voltage used by the SIM card you are talking to, as the Arduino might use a voltage a little bit to high, if the SIM card is connected directly to the Arduino.

It should be possible to generate the needed APDU commands (Select File, Get Response etc.) to retrieve the data from the SIM cards, but I can't help you with the commands needed to retrieve the information. You need to check the documentation online available regarding the SIM card protocol and file layout.

Are you able to retrieve the ATR (Answer to reset) message from your SIM card? This is normally a good starting point for finding out, what protocol is supported (T=0 or T=1) and what communication parameters are needed.

I would recommend the "apdu_t0_communication" example in the latest release (0.0.7rc3) as a starting point, this should give a framework for further experiments.

With kind regards

Angus

Hi Angus,
do you have a schematic on how to connect the TDA8024T in between?
Thanks,
Michael.

Thank you Angus :slight_smile:

I'll try these thing and will tell u the details soon.

i have one more doubt, i found some IC like, DS8007 (The DS8007 and Smart Card Interface Fundamentals | Analog Devices), TDA 8024 actually what is the function of these ICs when connecting with a microcontroller??
you said that with the library you given we can directly connect the card with arduino so if i'm using 3.7v SIM cards, to match the voltage can we connect the sim card to the arduino through a buffer like CD4050? is that enough??

Hi s_premkumar999, Hi mkroll

As both of you have similar questions, I will try to answer them in one post.

@s_premkumar999

If I understand the datasheets I found for the CD4050 correctly, this is a "one way" level shifter, which will not help you in this case as at least the C7 (I/O) contact of the smart/sim card is driven by both communications partners. What you might need is a transceiver, which works in both ways. (This is actually what the TDA8024, TDA8035, DS8024 or DS8113 are doing + additional smart/sim card features). So the CD4050 won't work in my opinion in this case.

The chips you found or the ones I've mentioned above are in my opinion just level shifter (The DS8113 supports 5V, 3.3V and 1.8V smart/sim cards). They just take care of the conversion of the voltage levels between modern MCU (Mostly 3.3V or 5V) and smart / sim cards, they also provide some convenience functions, like correct reset timing etc. and last but not least as you can not control what card a use might insert, they protect the MCU against the "outside" world. So for actual products I would recommend using this chips. If you just want to learn how the smart / sim card functions work or have a controlled environment, you can connect your 3.3V SIM (I'm not sure what you meant by 3.7v as I wasn't able t find information's about 3.7v SIM cards, so I thought it's just a typo and you meant a 3.3Volt SIM card) card directly to an Arduino supporting 3.3V (Like the new DUE or a lot of the Mega Version, which support 3.3V / 5V logic).

@mkroll

I don't have a schematic how to connect the TDA8024 with the Arduino, as I've reused a old smart card slot of a set-top box I had laying around. This Smart Card slot is based on a TDA8024, but if you google NXP TDA8024 or NXP TDA8035 you will find a lot information right on the NXP site (there is also a application note AN11058 on how to replace a TDA8024 with a TDA8035). Also Maxim provides a lot information about there maxim DS8024 or maxim DS8113 chips and about the underlying communication protocols. If you read the data sheets closely it talks a lot about high frequency problems and there avoidance, which is quite out of my scope, but with the data from the NXP/MAXIM datasheets it should be possible to build quite decent shields / smart card interfaces.

With kind regards

Angus

PS: I wasn't sure about giving direct links to the data on the NXP or Maxim sites, so I used the "google" way, which in my case led to very useful links on the first page ...

Hello Angus,

Thanks for your replay, i was checking the things you said. You explained things very nicely. This library works perfect for SIM cards, Thanks a lot..... :slight_smile: :slight_smile:
without any interfacing IC you said, i'm able to connect the sim card directly to the arduino and getting the ATR response. I'm attaching the screenshot plz check it, is that working correctly??
I have some doubts...
I want to read the complete phone book and the messages stored in the sim card and save in a memory card(not needed to display as characters in the mmc file just want to dump as a cache)and then write this to another sim card. Is it possible with this library? how to access the phone book and the message stored location in the sim card?? and which function is used to write thing to the sim card?

atr.bmp (659 KB)

Hi s_premkumar999,

I checked the ATR and at least it's valid from an ATR standpoint, but as you've said you are talking to a SIM Card, the communication flow might be different than the one defined in the test you've used. I assume you used the "apdu_t0_communication" example, which just checks a apdu / T0 communication. Based on the ATR you've provided and the result code found in the screenshot, the basic communication worked, but the smart card was not able to "SELECT" the file requested.

This is perfectly normal in your case and now the "fun" part starts :slight_smile:

I'm using the smart card lib currently for accessing normal memory cards and no SIM cards, so I can't help you with the communication sequence needed to access the Phone Book etc. of a sim card, but I think the "GSM 11.11" standard might be a good starting point to understand the communication between the mobile phone and the sim card, so that you can read the needed data.

The wikipedia article about the "Subscriber identity module" might also give a lot of hints to further information (The "Design" and "Data" sections of the english version mentions ETSI TS 102 223, ETSI TS 102 241, ETSI TS 102 588 and ETSI TS 131 111 and the above mentioned GSM 11.11)

Just let me know if you have any success, otherwise I have to check one of my old mobiles for a SIM card to check with :wink:

Hope this helps

Angus

Ya Angus, you really helping me a lot....I'll surely update you the progress.....
Thank you
Prem

hello Angus,

If one changes the clock pin on Arduino mega to 11 the what will vcc be for the smartcard?

Hi!

Using the latest version, with the example called: "apdu_t0_communication", I cant get anything else but this:

Waiting for Smartcard
Smartcard found
Received ATR ...
00|3B 79 94 00 00 F7 04 01 01 03 80 01 02 A9       ';y..............'
SELECT FILE Command ...
Received ... 6A82

The card It's a sle4432 I guess, also i think it hasn't any protection (0xFFF...)

Can anyone help me? How should I send the commands?

How can I know which byte correspond to a specific value? (for example time or money remaining)

Thank you :slight_smile: