1
votes

I am using ACS-ACR88 smart card reader. I am trying to read Smart Card serial number using SCardGetAttrib function in Winscard.dll, but it always returns error 50. 50 is not defined at Smart Card Return Values. Error 50 is 0x32, and it could be ERROR_NOT_SUPPORTED.

I looked for what possibly it means, and found that it could mean the driver of the card reader! Here is a link of the answer: Re: SCardGetAttrib, SERIAL_NO, error 50.

I have updated the driver with no luck. Here's what I've done so far:

private static UInt32 SCardAttrValue(UInt32 attrClass, UInt32 val)
{
    return (attrClass) * (2 << 16) | val;
}

private const uint SCARD_CLASS_VENDOR_DEFINED = 7;

public static UInt32 VENDOR_NAME { get { return SCardAttrValue(SCARD_CLASS_VENDOR_DEFINED, 0x100); } }

private void button2_Click(object sender, EventArgs e)
{
    var lReturn = GetAttribute((uint)hCard, VENDOR_NAME);
    lblData.Text = lReturn.ToString();    
}

public byte[] GetAttribute(uint m_hCard, UInt32 AttribId)
{
    byte[] attr = new byte[] { };// null;
    UInt32 attrLen = 0;
    attr.Initialize();
    int m_nLastError = ModWinsCard.SCardGetAttrib(m_hCard, AttribId, attr, out attrLen); //====    error 50 occurs here
    if (m_nLastError == 0)
    {
        if (attrLen != 0)
        {
            attr = new byte[attrLen];
            m_nLastError = ModWinsCard.SCardGetAttrib(m_hCard, AttribId, attr, out attrLen);
            if (m_nLastError != 0)
            {
                string msg = "SCardGetAttr error: " + m_nLastError;
                throw new Exception(msg);
            }
        }
    }
    else
    {
        string msg = "SCardGetAttr error: " + m_nLastError;
        throw new Exception(msg);
    }
}

Why am I receiving an error using SCardGetAttrib, and how do I fix it?

1
Unfortunately the command to return the serial number of a smart card is not standardized. Therefore it is unlikely that this can be fixed with another reader or reader driver. Get a manual of the card you use, look up the necessary command and send this APDU instead of queying the attribute. Alternatively, if you work in a project with a technical specification: take a look into the project specification; frequently there is stated, where the serial number shall be stored from which directly follows, how to get it.guidot
@guidot - Re: the command to return the serial number of a smart card is not standardized". I thought SCARD_ATTR_VENDOR_IFD_SERIAL_NO is the standard function to return the serial number. What does it return?jww
@jww It may work, if the OS recognises the card type and therefore knows the corresponding APDU. For an arbitrary card I would expect an error code otherwise.guidot

1 Answers

2
votes

Maybe it's too late but i think your AttribId value was wrong. You can look up AttribId value in the link below instead of converting from hexa to decimal by yourself

http://pyscard.sourceforge.net/epydoc/smartcard.scard.scard-module.html