Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am beginner in smart card world and hope someone here with
more experience will help me shed light on some doubts I have.

I have a Mifare card and a omnikey reader.
I know there exists Win 32 API for communicating with smart
card, with functions like: SCardEstablishContext, etc.

I am interested, say I write a Hello World program which
talks to my smart cards using above API (I also use this document:
http://www.hidglobal.com/sites/hidglobal.com/files/omnikey_contactless_developer_guide.pdf[^]), does
this mean my program will be able to talk to smart cards using ONLY using omnikey readers? Or other readers also?
Posted

1 solution

You should be able to use the code with any reader that complies with the SmartCard standards, which is most (if not all of them). Just call SCardListReaders to get a list of readers that are plugged into the PC. Call it once with a NULL parameter for the data (to get the length), then allocate a data storage area based on that length and call SCardListReaders again with this data store as a parameter. Use one of the names returned to call SCardConnect.
 
Share this answer
 
Comments
_coder 11-Sep-13 6:45am    
Thanks.

Can you explain why this is needed:

"Call it once with a NULL parameter for the data (to get the length), then allocate a data storage area based on that length and call SCardListReaders again with this data store as a parameter. Use one of the names returned to call SCardConnect."

?
Anorexic Tribble 11-Sep-13 10:15am    
SCardListReaders returns a string of unknown length. It depends on what readers you have attached (and potentially how many). You could guess how long the string is likely to be and pass a pointer to the start of the storage area. However if that string length was exceeded then you start writing over other variables or even your stack, which would produce interesting results!!

The first call (passing NULL for the storage area) says "Don't write any data, just tell me how many characters long the string would have been.". You can then allocate a character buffer that long (plus one for the null terminator) and pass the pointer to that buffer in the second call. It's a common mechanism for returning a data set of unknown length.
_coder 11-Sep-13 10:43am    
Anorexic thanks for reply, I will look into it. I also have one question hope you can help as I could not find much info on the net. Like I said above as I understood we can use Win32 API functions like SCardListReaders to communicate with Mifare smart cards. The thing is, I have Mifare Plus card. Now, the developer guide: http://www.hidglobal.com/sites/hidglobal.com/files/omnikey_contactless_developer_guide.pdf, in Section 6.2 says that if the card is in security layer 1 or 2 application can't use direct card communication. And in that case they suggest use of some kind of HID proprietary transparent channel. My confusion is that if I use this proprietary channel, then will OTHER readers be able to communicate with the smart card?? How should one communicate with Mifare Plus if the latter is in security layer 1 or 2. Thank you in advance.
Anorexic Tribble 12-Sep-13 4:28am    
At the lowest level you communicate with SmartCards using packets called APDUs (See http://en.wikipedia.org/wiki/Smart_card_application_protocol_data_unit). Most cards will initially only recognise a small subset of commands until you establish secure communications with them, usually using a standard APDU. The command SCardTransmit is used to send the APDU. Of course you have to implement the higher protocol at the PC end yourself if you are going at such a low level. There are libraries / drivers etc that will implement the higher level protocols for you. At the other end the higher level protocol is either implemented in the reader or the card itself. If you just want to talk to the card in terms of APDUs then most (if not all smartcard readers) will implement the ISO/IEC 7816-4 standard. If you want to talk to a smartcard at a higher level then you will need a reader that understands the protocol or a smartcard that understands the protocol. If you have a reader that talks to the card using something other than ISO/IEC 7816-4 then you will need obviously need a reader that will talk to cards using that standard. I am not really familiar with Mifare Plus or the higher level functions of the smartcard services, so I can not advise on those. Hope that helps. In summary you need to find out what protocols you need to talk to the card and reader and then find readers / cards / software / driver that will allow you to talk to them using those protocols.
_coder 13-Sep-13 3:50am    
Hi Anorexic, thanks. Honestly speaking, I didn't understand to what you are referring to using "higher" protocols?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900