Thread: sending APDU command to smart card

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    22

    sending APDU command to smart card

    are there any library or tutorial on how to send APDU command to smart card using C?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Can we assume that you know what "APDU's" are and how to construct them in C, and all you need to know is how to get them from your program onto your smart card?

    Like which OS and compiler do you have?
    Is the card plugged into a card reader?
    Is that card reader connected via serial / parallel / USB / something else to your PC?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    i usually do the back end programming like handling the APDUs in the card.so i'm new in the front end side.thats why i'm searching for tutorial.so i think just assume that i know what APDUs but don't know how to construct it in C.I use C to write application in the card that handle the incoming APDU's.but now i'm required to write APIs for sending the APDU to the card.

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    EDIT: Scrap that... I just looked up what they are... Sending them shouldn't be that hard... if you can already connect to recieve signals.

    And constructing them should be as simple as reading them, probably using a structure in order to gather all the data and header and what not, then sending it.
    Last edited by Wraithan; 10-06-2006 at 09:12 PM.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    where can i get reference?or sample code? plus i don't know how to connect to the card.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Like which OS and compiler do you have?
    Is the card plugged into a card reader?
    Is that card reader connected via serial / parallel / USB / something else to your PC?

    It gets real old, REAL fast when people can't be arsed to even read the whole post and respond to it.

    I mean, is it even worth saying
    Code:
    unsigned char APDU[APDU_PACKET_SIZE];
    APDU[0] = AN_OPCODE;
    APDU[1] = AN_OPCODE_LEN;
    // yada yada
    someMagicSendToDevice( APDU );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    -pc os win xp, card os multos
    -smartdeck c compiler
    -yes the card will be slot into the reader
    -reader via usb/serial

    and one more thing, i will be using 2 reader that is for authentication card with SAM
    Last edited by nurulhafiz; 10-07-2006 at 02:48 AM.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Care to fill in some missing blanks?
    Code:
    +===========+                             +===========+
    |           |                             |           |
    |Application|                             |Application|
    | Written in|                             |Written in |
    |Smartdeck C|                             |    ???    |
    |           |                             |           |
    +===========+                             +===========+
          |                                         |
    +===========+                             +===========+
    |           |                             |           |
    |  Multos   |                             |  Win32    |
    |    API    |                             |   API     |
    |           |                             |           |
    |           |                             |           |
    +===========+                             +===========+
          ^                                         ^
          |                                         |
          |             +===========+               |
          |             |           |               |
          |             |  Card     |               |
          +------------>|  Reader   |<--------------+
                        |           |      USB Interface
                        |           |
                        +===========+
    Like which bit of software you're writing, and where you want the information to go, and what is going to deal with that information when it gets there.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    i have managed to write the application on the card using smartdeck C.

    now my task is write the Win32 API in C++ dll/C lib which will construct all the APDUs that are going to be send to the card. for example if i want to write the name of the card owner into the card. my API will construct the write binary instruction and send it to the card and before the construction could take place the API should first detect the card reader and wether the card have being slot into the reader. If this succeed then can begin constructing and sending the APDUs to the card.

    after that i should write a demo application in VB that will call the API to do the transaction with the card like personalize the card or audating data in the card.this part i can do it.only the API part i can't because i have to connect to the reader, constrict the APDU and send it.
    Last edited by nurulhafiz; 10-08-2006 at 12:52 AM.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Which compiler are you using on your XP box?

    When you plug in the card reader, does XP automatically recognise it?


    Here's some information on USB
    http://www.lvr.com/usb.htm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    for the API and VB application i will use VStudio 6.0.

    yes after installing the driver XP automatically recognise it coz it is pc/sc reader..

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So does XP recognise it as say a "file" device, which explorer can drag and drop files to?

    Or something else?

    If you can just write files to it, then that's dead easy using any kind of C or C++ program to create files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    no..it just detect it as card reader.

    if we want to read, write or other transaction to the card we have to send APDU command to that reader like writing to a port in case if we're using a serial reader which i don't know how.

    if using application in VB we can use winscard.dll to do this but now i have to make an API using C or C++ which will do the same thing like the winscard.dll only that the constructing APDU will be in the API too.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  2. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  3. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 03:21 AM
  4. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 08:07 PM
  5. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 01:25 PM