Home

angus71


Discussion

  • angus71
    angus71
    2012-01-20

    Welcome to the Smartcard Lib for Arduino compatible boards wiki.

    Currently this is a project I'm working on to learn more about the Ardunio programming and interfacing to external hardware.

    As it might be quite hard to setup a complete smart card reader for the Arduino from scratch, I just looked around and found a old settop box, which had a seperate module to interface with the smart card.

    All the documentation and data sheets I read, had a lot to say about high frequency and other effects, you can face if you use chips like the TDA 8204T to interface with a smart card.

    This library can be used to talk to a directly to the Arduino board connected smartcard or a smartcard connected via a TDA 8204T (or compatible).

    Per default the library behaves, like the smartcard is directly connected to the Ardunio board, as this is the default for the most people (The connection is described in the schematic attached to a post below).

    I that you actually don't need a TDA 8204T or any other chip to talk to a smart card, as you can connect the smart card directly to the I/O pins of the Arduino board, but with the interface chip it's just safer for my Arduino board and my smart cards.

    Setup

    As per release 0.0.4, the default behaviour is changed to a directly connected smartcard and the TDA 8204T interface needs to be activated via a define in the code.

    See the attached schematic, how the signals need to be connected to the Arduino board.

    Smartcard Arduino UNO
    C1(Vcc) D11
    C2(RST) D7
    C3(CLK) D9
    C4(AUX1) N.C.
    C5(GND) GND
    C6(Vpp) N.C
    C7(I/O) D10
    C8(AUX2) N.C.
    SWITCH D8

    Currently the C3(CLK) - D9 connection is hard coded, as I didn't found a way to get the timer associated with a pin and access the registers. The D9 pin is used to generate a clock signal for the smart card.

    To have defined values for the C3(RST) and C7(I/O) signales I used 100k pull-up resistors and a 100k pull-down resistor for the switch signaling that the smardcard is inserted into the smartcard slot

    If USE_DEBUG_PIN is enabled, which is by default, the D13 is used to signal changes in the internal state machines. Used to trigger my logic state analyser.

    It is also possible to minimize the binary size, by enable synchronous or asynchronous communication in the header file.

     
    Last edit: angus71 2012-07-22
  • angus71
    angus71
    2012-02-07

    The easiest way to get to this information would be the article about smart cards in wikipedia. In the english version is a pin out given and with the provided table it should be possible to connect it directly to the arduino board (See attached schematic)

    Smart Card Arduino (Based on the above given table)
    C1 - VCC D11 (!CMDVCC) *
    C2 - RST D7 (RSTIN)
    C3 - CLK D9 (XTAL1)
    C4 - Not Connected
    C5 - GND GND
    C6 - VPP Not Connected
    C7 - I/O D10 (I/OUC)
    C8 - Not Connected

    * With the new release 0.0.4 this works right out of the box, as direct connection is the default.

     
    Last edit: angus71 2012-07-22
  • tavovalencia
    tavovalencia
    2013-01-21

    Hi Angus, I'm really very interested in this project!! Thanks

    I have a doubt. My SC Connection switch is always closed and opens when the card is inserted, thereby if I connect the switch in a pull-down, it thinks that there are no-card-inserted when there actually is. I modified my connection to pull-up resistor by connecting as follow:

    * SWITCH 1 to GND
    * SWITCH 2 to (between D8 and 1K resistor that goes to 5V).
    

    Now it tries to read the card every-time I insert a card. However, each time I have inserted a card the following pattern happens:

    * Waiting for Smartcard
    * Smartcard found
    * Unable to identify card ... Please remove
    

    Not really sure what I'm doing wrong!

     
    Last edit: tavovalencia 2013-01-21
    • angus71
      angus71
      2013-01-21

      Hi tavovalencia,

      I think you should try a revision >= 20 from the trunk SCLib.h & SCLib.cpp as I added a feature to invert the card recognition (Parameter off_invert of the constructer set to true) after I've purchased a smartcard slot with the same switch behaviour as yours. That should do the trick, if go back to the pull down configuration.

      If you have further question just send me a mail.

       
      • tavovalencia
        tavovalencia
        2013-01-21

        Hi Angus,
        I don't know your email, so I'll continue with this thread.

        After I downloaded both files, I tried both ways with the pull-down (left on the attached image), It continuously said "waiting for Smartcard" (not recognizing it), and with pull-up (right on the attached image).

        It appears that the original circuit (on the left) can't work with my socket, not even with the new libraries, however, I kind of had a better result with the other schem:

        I started with the SCTest. -> The card was now found and the serial monitor showed:

        //Inserted CARD #1
        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        //After a couple of seconds repeats the same
        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        // Here I changed the cards (2nd)
        Smartcard found
        00|92 23 10 91 '.#..............'

        Waiting for Smartcard

        // Here I changed the cards (3rd)
        Smartcard found
        00|07 8E 07 8D '................'

        Waiting for Smartcard

        The good news is that three different smartcards were apparently recognized with 4-bytes each. But it kind of crashes after the 4th byte. I have to take the card out and re-enter it.

        When testing on the SCTest2 the thing is different. Once I entered the SC in the socket it read the card once and printed into serial monitor:

        Smartcard found
        Received ATR ...
        00|0C 02 0C 01 '................'
        SELECT FILE Command ...
        Received ... 0
        Waiting for Smartcard

        This happened VERY fast I tested this several times and after the "Waiting for Smartcard" print, I couldn't change the smartcard and have new readings without reseting the Arduino.

        I'm not sure but in both cases it seems like only the first 4 bytes are transmitted, then the program continues the loop without delays or without prompting anything... Is this right?

        PS> Link to Attached Image

         
        Last edit: tavovalencia 2013-01-21
        Attachments
        • angus71
          angus71
          2013-01-22

          Hi tavovalencia,

          If the ATR's you receive are correct, they lead to the point that you are using synchronus cards, as they normaly only have a 4 byte ATR. .. Like SL4432/SL4442 or other memory cards, which can be found often as keycards in hotels, member cards etc.

          Do you have additional information regarding the type of the card? I think, if the cards you used are synchrous, everything worked fine and now the protocol implementation has to be done to support the card type you want to use.
          I'm currently implementin a SL4432/SL4442 support class, which provides all the features of this card type for easy usage.

          So to have your problems fixed I think i have to ask some questions ;-.)

          1. What kind of Arduino are you using?

          There might be a problem, when using a Arduino Mega compatible board as the CLK Pin has to be moved from Digital 9 to Digital 11 and the function of the Digital 11 (Vcc) can be moved to every other digital pin avaialable (The CLK pin is tied to the TIMER1A and the output pin of the timer was moved).

          1. Do you have more information regarding the type and protocol of the cards you want to use?

          The SCTest2 is only working with asynchrous cards of protocol type T=0, that's the reason, why you might get the "Received .. 0" as the APDU command format is not supported by all the synchronous cards I know :-(

          I will have a look into the problem of the need to reset the Arduino this condition, that should not happen and I will rename/comment the examples a little bit better to have them more intuitive.

          Can you please send me the answers via the "Send me a message" form on my users page or open a discussion in the genral discusion form, as I don't think tha communication through the wiki is a good idea ;-.)

          regards,

          Angus

           
          • Stellaras
            Stellaras
            2014-08-24

            Hi Angus, when you say "Arduino Mega compatible boards" those boards include only Arduino Mega AKD and 2560? or any board that uses the ATmega processor?
            For example in wiki (http://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems ) I see that Arduino Uno is listed under the arduino format even though it is using at atmega processor. Is that what you mean?

            I would like to apologize in advance for asking such a basic question. Thank you for your time and help.

             
            Last edit: Stellaras 2014-08-26
            • angus71
              angus71
              2014-09-08

              Hi Stellaras,

              The only "processor" specific feature the code uses of an ATmega processor is the Timer feature, to create the clock for the smart card communication and that is more or less the only feature that limits the usage of this lib to the ATmega compatible boards, if the clock generation is exchanged with a mechanism available on a different platfrom, it should be portable to nearly any other platform ... (As long as the supporting features of the Arduino development environment are available or replaced with suiteble libs.)

              So if I unsderstood your question correctly, the anser is the ATMega processor is needed, due to the Timer feature. The Arduino UNO board might work, but there isn't much memory / flash left for your own code.

              With kind regards

              Angus

               
  • Prem
    Prem
    2013-02-21

    Hi Angus,
    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 :)

     
  • pedro
    pedro
    2013-11-26

    Oi amigos, pode me ajudar como faço para ler minha lista telefonica com arduino, o codigo fonte ja funciona mas agenda do sim card teria como ler?

     
    Last edit: pedro 2013-11-26
  • heringer
    heringer
    2015-03-14

    hello angun71.
    First I want to thank for his work on this lib Arduino, was very good to make the smart card reading. I wonder if you can make a sniffer smartcard with this lib if possivem is how you make an example.
    thank you.

     
    • angus71
      angus71
      2015-03-18

      Hi Heringer,

      In principle this will work, but the lib won't be much of a help, as it was designed to provide a "Smart Card Reader" interface to the Arduino ..

      The effort needed might depend on your approach, to actually sniff the communication won't be hard and might be done with the low level "bit-reading" functions, but still a lot of modification will be needed to "convert" the SCLib into a "protocol decoder".

      An easier way might be to use a logic analyzer, as most of them have protocol decoders available .. I use a Open Logic Sniffer from dangerous prototypes (inexpensive compared to other devices, but limited in the sample time).

      A more interesting approach might be a "man-in-the-middle" setup, one side connected to the SmartCard the other side connected to the "original" Smart Card Reader, this would give you more options for debugging and testing, but this might be hard to be done with a classic "Arduino" based board ... A fair amount of multitasking is needed for this and this might be accomplished with a more "capable" hardware / OS ... The PRU of the "BeagleBoneBlack" might be a good starting point or any other Embedded board (Raspberry etc.)

      Regards

      Angus

       
  • Andon
    Andon
    2015-03-29

    Good day!

    I was poking around Futurlec and came across some smart cards, and of course wished to utilize them with Arduino. Did a quick search, and came across your wonderful little library here.

    However, I noted that neither of the cards on Futurlec (link: http://www.futurlec.com/Smart_Cards.shtml ) are listed in the supported cards list. I am curious if either of them would work, or if they could be made to work. I doubt the AT24C64 would work, given that it looks like it's a completely different thing, but I was hoping the SLE4428 could be made to work.

    Alternately, where would be a place that I could acquire a compatible card for a decent price?

     
    • angus71
      angus71
      2015-04-09

      Hi Andon,

      Sorry for the late answer, but I was busy in the last weeks to to my "normal" job .. :-)

      It should not be a problem to make the SLE4428 work, as there is already a support class for the SLE44x2 cards. It had a "really" quick look on the data sheet for the SLE44x8 and they look quite similar, but some changes might be needed ... So it will not work right out of the box :-( but it is definitely possible.

      With the AT24C64 you are right, they might be "plugged" into the sclib, but this would be more of rewrite, maybe something for the future :-). These cards are accessed via a TWI (I2C) and it should be quite simple to access them via the appropriate Ardunio libraries.

      If you still are looking for compatible cards I would recommend SLE4442 (or compatible cards), they should be in the same price section, as the ones you found from Futurlec, but still they need to fit your project / security requirements (But they should work right out of the box).

      Regards

      Angus

       
  • adruha
    adruha
    2015-04-15

    Hi Angus! Can you tell me? How to reset the error the wrong password for the smart card SLE4442? After several attempts to write to the card I have wrong password, and now the card is locked. Perhaps you could add this feature to your library?

     
    Last edit: adruha 2015-04-15