APDU script question

Hi

I'm trying to simulate a SIM card using cref in Java card kit 2.2.1, but I have some trouble editing the .scr-file.

According to the Java card user guide, the steps are as follows:

powerup;

* Select the installer applet

* CAP begin

...

* CAP end

* Create Applet APDU Command

* Select APDU Command

powerdown;

Right?

I've studied the HelloWorld example in the Java Card user guide, but I don't understand how they put together the "create applet" apdu.

In HelloWorld, the applet AID is: 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1:0x1

The create HelloWorld apdu-statement is:

0x80 0xB8 0x00 0x00 0x0b 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x03;

0x01 0x00 0x7F;

According to user guide, Create Applet APDU Command is composed of: 0x8x(0?), 0xb8, 0x00, 0x00, Lc field, AID length field, AID field, parameter length field, [parameters], Le field

Can someone please explain this for me? I need to understand this so I can make my own APDU script

[1060 byte] By [MrHyylja] at [2007-11-26 19:13:15]
# 1

To clarify a bit, I think I understand most of the fields in the APDU script. But there are a couple of things I don't understand completely:

The Applet AID and the parameter field in the HelloWorld example.

I can't find a connection between the Applet AID defined in the Converter-command in the HelloWorld example and the Applet AID wrapped inside the APDU script. (listed in the previous post). I don't find an explanation of the parameter field either.

I know this topic has been discussed before in this forum, but I've read through all of them, and couldn't find what I was looking for..

MrHyylja at 2007-7-9 21:12:39 > top of Java-index,Java Mobility Forums,Consumer and Commerce...
# 2

I've finally got my own simulator to work, but I was never able to solve the HelloWorld example-problem presented in the previous post. I suspect there is something wrong with the APDUs in that example..

However, I will post my own solution here, since there are likely that others might face the same problems as I did.. My code is partly based on the JavaLoyalty-sample included in the java card kit.

I'm using Java card kit 2.2.1, eclipse 3.2 with EclipseME 1.6.0 and Jdk1.3 (It took me several hours to discover that the class files had to be compiled with java 1.3 or lower..)

//Step 1: Convert applet class to CAP-files:

converter -applet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x5:1 SIMCardApplet.CardTest -classdir <yourClassDirHere> -exportpath c:\java_card_kit_2.2.1\api_export_files <thePackageName> 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x5 1.0

//Step 2: Generate the scr-file:

scriptgen -o SIMCardApplet.scr <pathToCapFile>

//Step 3: Edit the output of step 2 (the scr-file):

//This must be the first statement in the scr-file!

powerup;

// Select the installer applet (I think this already exist in .scr-file

0x00 0xA4 0x04 0x00 0x09 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0x08 0x01 0x7F;

//CAP begin (this already exists in your cap-file)

0x80 0xB0 0x00 0x00 0x00 0x7F;

//Place the Generated CAP-stuff here

//CAP end (Also exists in your cap-file)

0x80 0xBA 0x00 0x00 0x00 0x7F;

// create Applet

0x80 0xB8 0x00 0x00 0x0c 0x0a 0xa0 0x00 0x0x 0x00 0x00 0x62 0x03 0x01 0x0c 0x05 0x01 0x00 0x7F;

// Select Applet

0x00 0xa4 0x04 0x00 0x0a 0xa0 0x00 0x00 0x00 0x62 0x03 0x01 0xc 0x05 0x01 0x7F;

powerdown;

//Step 4: Start simulator and initialize eeprom-output file:

start cref -o SIMCardApplet.eeprom

//Step5: Load the scr-file onto the eeprom-file:

apdutool SIMCardApplet.scr

//Step 6: Run the simulator with eeprom as input. (-e prints exceptions to screen):

start cref -e -i SIMCardApplet.eeprom

A good tip is to create small .bat scripts (windows) with the steps above. This will save you a lot of time!

If everything worked well, the simulator is now listening to default port 9025, waiting for requests from your application.

Set up connection with this AID: (simplified code)

..

String AID = "apdu:0;target=a0.00.00.00.62.03.01.0c.05.01";

apduConnection = (APDUConnection)Connector.open(AID);

response = apduConnection.exchangeAPDU(apdu);

..

Hope this helps other java card newbies :)

Regards

Haavard, Norway

MrHyylja at 2007-7-9 21:12:39 > top of Java-index,Java Mobility Forums,Consumer and Commerce...