Desarrollo una aplicacion Pc/Sc , establesco el contexto, la conexion y obtengo el ATR perfectamente, pero cuando inicio la trasmision en vez de devolverme (SW1=90 SW2=00) me devuelve (SW1=69 SW2=00) CodigoSnipe
class MaxSmartCard
{
private UInt32 LONGITUD = 0xFF;
private const UInt32 T0 = 0x01; private const UInt32 T1 = 0x02 ;
private const UInt32 EXCLUSIVE = 0x01; private const UInt32 SHARED = 0x02;
private SCARD_IO_REQUEST request = new SCARD_IO_REQUEST();
[DllImport("Winscard.dll")]
private extern static int SCardTransmit(
[In] IntPtr cardHandle,
IntPtr sendPci,
Byte [] sendBuffer,
UInt32 sbLength,
[In, Out] SCARD_IO_REQUEST recvPci,
[In, Out] Byte[] recvBuffer,
[In, Out] UInt32 rbLength);
[DllImport("kernel32.dll", SetLastError = true)]
private extern static IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
private extern static void FreeLibrary(IntPtr handle);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr handle, string procName);
[StructLayout(LayoutKind.Sequential)]
public struct SCARD_IO_REQUEST
{
public UInt32 pciProt; public UInt32 pciLen;
public SCARD_IO_REQUEST (UInt32 a, UInt32 b)
{ this.pciProt = a; this.pciLen = b; }
}
public MaxSmartCard() { this.request = new SCARD_IO_REQUEST(0x00,0xFF); }
public void EstablecerContexto() { this.rContex = SCardEstablishContext(0x00, IntPtr.Zero, IntPtr.Zero, out this.hContext); }
public void InformacionLectores()
{
UInt32 _pcchReaders = 0;
this.rReader = SCardListReaders(this.hContext, null, null, ref _pcchReaders);
Byte[] byteLectores = new Byte[_pcchReaders];
this.rReader2 = SCardListReaders(this.hContext, null, byteLectores, ref _pcchReaders);
ASCIIEncoding ascii = new ASCIIEncoding();
this.miLector = ascii.GetString(byteLectores);
}
public void EstablecerConexion() { this.rConnect = SCardConnect(this.hContext, miLector, EXCLUSIVE,T1, ref this.hContext, ref ActiveProtocol); }
public void AtributosCard()
{
this.vectorAttr = new Byte[22];
IntPtr pcbAttrLen = new IntPtr(vectorAttr.Length);
this.rAtributo = SCardGetAttrib(this.hContext, SCARD_ATTR_ATR_STRING, vectorAttr, ref pcbAttrLen);
}
public void Trasmision()
{
Byte[] vectorSend = { 0x00, 0xA4, 0x04, 0x00, 0x00};
UInt32 inT2 = (UInt32)vectorSend.Length;
vectorIn = new Byte[2];
UInt32 inT = (UInt32)vectorIn.Length;
IntPtr IOPCI = GetPciT1();
this.rTransmit = SCardTransmit(this.hContext, IOPCI, vectorSend, inT2, request, vectorIn, inT);
}
public IntPtr GetPciT1()
{
IntPtr handle = LoadLibrary("Winscard.dll");
IntPtr pci = GetProcAddress(handle, "g_rgSCardT1Pci");
FreeLibrary(handle);
return pci;
}
}
y desde este boton invoco los metodos de la clase
private void button9_Click(object sender, EventArgs e)
{
Byte[] v; Int64 Exito = 0X00;
textBox1.Text = "";
Metodo.EstablecerContexto(); if (Metodo.RContext() != Exito) { MessageBox.Show("CONTEXTO NO ESTABLECIDO, ERROR " + Metodo.RContext().ToString("X2"), "INFORMACION DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
Metodo.InformacionLectores();
if (Metodo.RReader() != Exito) { MessageBox.Show("1era LLAMADA AL LECTOR FALLIDA", "INFORMACION DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (Metodo.RReader2() != Exito) { MessageBox.Show("2da LLAMADA AL LECTOR FALLIDA", "INFORMACION DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
textBox1.Text = "NOMBRE DEL LECTOR " + Metodo.MiLector();
Metodo.EstablecerConexion(); if (Metodo.RConnect() != Exito) { MessageBox.Show("CONEXION NO ESTABLECIDA, ERROR " + Metodo.RConnect().ToString("X2"), "INFORMACION DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
Metodo.AtributosCard(); if (Metodo.RAtributo() != Exito) { MessageBox.Show("OBTENCION DE ATRIBUTO FALLIDA, ERROR " + Metodo.RAtributo().ToString("X2"), "INFORMACION DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
v = Metodo.VectorAtributo();
textBox1.Text = textBox1.Text + Environment.NewLine + "ATR ";
for (int i = 0; i <= v.Length - 1; i++) { textBox1.Text = textBox1.Text + v[i].ToString("X2") + " "; }
textBox1.Text = textBox1.Text + Environment.NewLine + "MODELO TARJETA " + Metodo.CadenaHexArray(v, false);
Metodo.Trasmision(); if (Metodo.RTransmit() != Exito) { MessageBox.Show("TRASMISION FALLIDA, ERROR " + Metodo.RTransmit().ToString("X2"), "INFORMACION DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
v = Metodo.VectorSalida();
textBox1.Text = textBox1.Text + Environment.NewLine + "SW1=" + v[0].ToString("X2") + " " + "SW2=" + v[1].ToString("X2");
Metodo.Desconectar();
}