Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

New on java Card

843851Feb 15 2010 — edited Feb 17 2010
HI all !

I'm new on java card technology and would like to compil my first cardlet :)

I'm getting problem while charging my cardlet into my chip, Eclipse does not generate the cap file.

I'm using Eclipse 3.3.1 and JCop Tools 3.2.7.

I created a Java card projet and a Java card Applet file and here is my code :
package pck_calculator;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;


public class Calculator extends Applet
{
	private static final byte[] CALC = { //
	(byte) 0x63, // c
	(byte) 0x61, // a
	(byte) 0x6c, // l
	(byte) 0x63, // c
	(byte) 0x75, // u
	(byte) 0x6c, // l
	(byte) 0x61, // a
	(byte) 0x74, // t
	(byte) 0x72, // r
	(byte) 0x69, // i
	(byte) 0x63, // c
	(byte) 0x65  // e
	}; // Tableau de bytes (code ASCII) qui va être renvoyé si on envoit l'INS 0x00
	
	
	//methode d'installation de l'applet dans la carte
	public static void install(byte[] bArray, short bOffset, byte bLength)
	{
		// Enregistrement de l'applet (méthode register()) auprès du JCRE
		// Lors de la création de l'applet (new)
		new Calculator().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
	}
	
	public void process(APDU apdu)
	{
		//pour verifier que cette applet n'est pas entrain d'être sélectionné
		if (selectingApplet())
		{
			return;
		}
		
		//réception de la commande APDU
		byte[] buf = apdu.getBuffer();
		
		switch (buf[ISO7816.OFFSET_INS])
		{
			case (byte) 0x00 :
				Util.arrayCopy(CALC, (short) 0, buf, (short) 0, (short) CALC.length);
				apdu.setOutgoingAndSend((short) 0, (short) CALC.length);
				return;
				// Ici, on copie le tableau (défini en haut) dans le buffer et on l'envoi sur la sortie
				// En précisant la taille du champ de données
			
			case (byte) 0x01 :
				buf[0] = (byte) (buf[ISO7816.OFFSET_P1] + buf[ISO7816.OFFSET_P2]);
				// Ici, on additionne P1 et P2
				break;
				
			case (byte) 0x02 :
				//Soustraction de P1 et P2
				buf[0] = (byte) (buf[ISO7816.OFFSET_P1] - buf[ISO7816.OFFSET_P2]);
				break;
				
			case (byte) 0x03 :
				//Multiplication
				buf[0] = (byte) (buf[ISO7816.OFFSET_P1] * buf[ISO7816.OFFSET_P2]);
				break;
				
			case (byte) 0x04 :
				//Division
				if (buf[ISO7816.OFFSET_P2] == 0)
				{
					//Test de la division par 0
					ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
					//Envoie de l'exception "mauvais paramètres"
				}
				buf[0] = (byte) (buf[ISO7816.OFFSET_P1] / buf[ISO7816.OFFSET_P2]);
				break;
				
			case (byte) 0x05 :
				//Somme du champ de données de la commande APDU
				short n = (short) (ISO7816.OFFSET_CDATA + apdu.setIncomingAndReceive());
				byte sum = 0;
				
				while (n-- > ISO7816.OFFSET_CDATA)
				{
					sum += buf[n];
				}
				
				buf[0] = sum;
				break;
			
			default :
				//Envoie de l'exception "mauvais champ INS"
				ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
		}
		//Pour tous les cas la réponse APDU a des données de 1 octet
		//Sauf pour le cas INS = 00
		
		apdu.setOutgoingAndSend((short) 0, (short) 1);
	}
}
It's a simple calculator :)

To compile, I use right click on the projet => debug as... => Open debug dialog
and I set the correct AID of the package and class in the "Package upload".

Then I start debug and here is the problem :
The .cap is never created (cm> upload -d -b 250 path/file.cap)

The comunication with the card is ok because it answers some request like /card-info.

Do you have any idea about a step I forget or anything else ??

Thanks a lot :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 17 2010
Added on Feb 15 2010
19 comments
697 views