heres the method that write when readWrite arg of method is false n reads
when true....verifies PIN in both cases:
public byte[] runAppliCommands(byte[] data, int lengthOfData,boolean
readWrite)
{
ResponseAPDU resp = null;
try
{
// Send commands to the applet 'process' method
// <PLACE THE APDU COMMANDS HERE>
System.out.println("Enter into Run Application Commands
Function");
/* ----- Example implementing APDU exchange -----*/
byte[] data1 = null;
byte[] data2 =
{(byte)0x44,(byte)0x43,(byte)0x42,(byte)0x41,(byte)0x40};
byte[] data3 =
{(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x0
9,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x09,(byte)0x
09,(byte)0x09};
byte[] buffer = { (byte) 0x80, // CLA
(byte) 0xDA, // INS
(byte) 0x00, // P1
(byte) 0x00, // P2
(byte) 0x05, // LC
(byte) 0x08 , // Data
(byte) 0x7F // LE
};
if (!loadPackage) {
CommandAPDU cmd = new CommandAPDU(buffer);
/*************** pin
*****************************/
byte [] pwd =
{(byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x0
7,(byte)0x08};
resp =
serv.sendCommandAPDU(false,false,(byte)0x80,(byte)0x20,(byte)0x00,(byte)0x00
,8,pwd,0x00,"WriteData");
cmd = new CommandAPDU(pwd);
displayAPDU( cmd,resp);
if (resp.sw() != 36864) {
System.out.println("Wrong PIN");
return null;
}
if (!readWrite) {
/*********************write data*******************/
System.out.println("WRITE");
int dataLen = lengthOfData;
byte chunk255[]= new byte[255] ;
int idx=0;
int j=0;
int count=0;
int flag = 0;
//Here picks chunks of 255 since only 255 bytes can be sent.
for (idx=0; idx<lengthOfData+1; idx++)
{
if ((count < 255) )
{
if (idx != lengthOfData){
chunk255[j] = data[idx];
j++;
count++;
}
else{
byte chk[] = new byte[dataLen];
for (int i=0; i<dataLen; i++)
{
chk[i] = chunk255[i];
}
cmd = new CommandAPDU(chk);
resp =
serv.sendCommandAPDU(false,false,(byte)0x80,(byte)0xDA,(byte)0x00,(byte)0x00
,dataLen,data,(byte)0x00,"WriteData");
displayAPDU(cmd, resp);
System.out.println("Send22..");
}
}
else
{
j=0;
count=0;
System.out.println("Send11..");
cmd = new CommandAPDU(chunk255);
resp =
serv.sendCommandAPDU(false,false,(byte)0x80,(byte)0xDA,(byte)0x00,(byte)0x00
,255,chunk255,(byte)0x00,"WriteData");
displayAPDU(cmd, resp);
dataLen=dataLen-255;
}
}
} else
{
System.out.println("READ");
/*
cmd = new CommandAPDU(data2);
resp =
serv.sendCommandAPDU(false,false,(byte)0x80,(byte)0xCA,(byte)0x00,(byte)0x00
,(byte) 0x00, data1,(byte)0x02,"ReadData");
displayAPDU(cmd, resp);
byte[] myData = resp.data();
int first = (int) myData[0] - 48;
int second = (int) myData[1] - 48;
String sizeOfData = Integer.toString(first) +
Integer.toString(second) ;
int dataLength = Integer.parseInt(sizeOfData) + 4;
byte dLength = (byte)dataLength;
/***************RESET Command
/********* 0x80 0x28 00 00
*/
/******************read data******/
byte[] dataOnCard = null;
resp =
serv.sendCommandAPDU(false,false,(byte)0x80,(byte)0xCA,(byte)0x00,(byte)0x00
,(byte) 0x00, dataOnCard,lengthOfData+1,"ReadData");
cmd = new CommandAPDU(data3);
displayAPDU(cmd, resp);
}
} // end if loadPackage
}
catch(Exception ex)
{
System.out.println("Exception caught in runAppliCommands : " +
ex.getMessage() );
}
return resp.data();
}
It was working fine. As i continue to test it with increasing data it
started to act up.
Now even if i send 3 bytes only it doesnot write and response APDU produces
following error code 6F 00 which is 'no specific diagnosis'.
Im using a gemPC410 reader n gemxpresso 211 Javacard.
read can read from the card nicely.
regards,
-Saira
-----Original Message-----
From: Sean Graham [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 21, 2001 5:29 PM
To: Saira Bhatti; [EMAIL PROTECTED]
Subject: Re: [OCF] can any one explain this!
Can you read from the card fine? Can you send a code snippet showing where
the error occurs? You say that sometimes you can write, but sometimes
not? Or is it that a different part of code can write, but this one
can't? Please give specific details, as much as you can think of.
-- Sean
At 05:18 PM 3/21/01 +0500, you wrote:
>what can b concluded by the Exception below?
>
>Exception caught in runAppliCommands :
>com.gemplus.opencard.terminal.GemcoreFami
>lyException: com.gemplus.opencard.terminal.GemcoreFamilyException:
>com.gemplus.o
>pencard.terminal.GemcoreFamilyException:
>com.gemplus.opencard.terminal.GemcoreFa
>milyException: error in communication
>
>it comes whenever i try to write to card.
>
>this exception sometimes arises and at times write is successful without
the
>above exception!
>
>rgds,
>-Saira
>
>
>
>---
> > Visit the OpenCard web site at http://www.opencard.org/ for more
> > information on OpenCard---binaries, source code, documents.
> > This list is being archived at http://www.opencard.org/archive/opencard/
>
>! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
>! to
>! [EMAIL PROTECTED]
>! containing the word
>! unsubscribe
>! in the body.
---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/
! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
! [EMAIL PROTECTED]
! containing the word
! unsubscribe
! in the body.
---
> Visit the OpenCard web site at http://www.opencard.org/ for more
> information on OpenCard---binaries, source code, documents.
> This list is being archived at http://www.opencard.org/archive/opencard/
! To unsubscribe from the [EMAIL PROTECTED] mailing list send an email
! to
! [EMAIL PROTECTED]
! containing the word
! unsubscribe
! in the body.