Newer
Older
package uicc.hci.test.framework.api_1_hme_mty;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import uicc.hci.framework.HCIDevice;
import uicc.hci.framework.HCIException;
import uicc.hci.framework.HCIListener;
import uicc.hci.framework.HCIMessage;
import uicc.hci.services.cardemulation.CardEmulationListener;
import uicc.hci.services.cardemulation.CardEmulationMessage;
import uicc.hci.services.cardemulation.CardEmulationService;
/**
* The method with the following header shall be compliant to its definition in the API.
* <code>byte getType()</code>
*/
public class Api_1_Hme_Mty_1 extends Applet implements MultiSelectable, CardEmulationListener {
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Define HCI specific variables
*/
private CardEmulationService ceService;
/**
* byte 0 - HCIMessage.isHeading() result
* byte 1 - HCIMessage.isComplete() result
* byte 2 - HCIMessage.getType() result
* byte 3 - HCIMessage.getInstruction() result
* byte 4, 5 - HCIMessage.getReceiveOffset() result
* byte 6, 7 - HCIMessage.getReceiveLength() result
* byte 8, 9 - SW
*/
private byte[] exceptions;
private byte sentOnce;
private boolean isSet;
/**
* Applet tests HCIMessage commands
*/
private Api_1_Hme_Mty_1() {
/*
* JavaCard applet register
*/
register();
/*
* HCI listener register
*/
try {
ceService = (CardEmulationService) HCIDevice.getHCIService(HCIDevice.CARD_EMULATION_SERVICE_ID);
ceService.register(this);
ceService.activateEvent(EVENT_ON_SEND_DATA);
} catch (HCIException e) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
exceptions = new byte[10];
sentOnce = 0x00;
isSet = false;
}
/**
* To create an instance of the <code>Applet</code> subclass, the Java Card
* runtime environment will call this static method first.
*
* @see Applet#install(byte[], short, byte)
*/
public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException {
new Api_1_Hme_Mty_1();
}
/**
* This method is called by the HCI framework to inform the Listener Object
* about a specific event and pass the corresponding HCIMessage to the
* Listener Object.
*
* @see HCIListener#onCallback(byte, HCIMessage)
*/
public void onCallback(byte event, HCIMessage hcimessage) {
CardEmulationMessage message = (CardEmulationMessage) hcimessage;
exceptions[8] = (byte) 0x90;
exceptions[9] = 0;
switch(event){
case EVENT_ON_SEND_DATA:
if (sentOnce == 0x00) {
sentOnce = 0x01;
message.prepareAndSendSendDataEvent(exceptions, (short) 8, (short)2);
return;
}
if (!isSet){ //only the result of the fist call should be analyzed
exceptions[2] = message.getType();
isSet = true;
}
message.prepareAndSendSendDataEvent(exceptions, (short) 0, (short) 10);
// fall through
default:
return;
}
}
/**
* Not used.<br />
* Called by the Java Card runtime environment to process an incoming APDU
* command.
*
* @see Applet#process(APDU)
*/
public void process(APDU arg0) throws ISOException {
}
public coid deselect(boolean arg0){
}
public boolean select(boolean arg0){
return true;
}