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.connectivity.ConnectivityListener;
import uicc.hci.services.connectivity.ConnectivityService;
/**
* 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_2 extends Applet implements MultiSelectable, ConnectivityListener {
19
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Define specific SWs
*/
private static final short SW_EVENT_NOT_TRIGGERED = ISO7816.SW_UNKNOWN + (short) 1;
/*
* Define specific INS bytes
*/
private final static byte INS_CHECK_VB = (byte) 0x01;
/*
* Define HCI specific variables
*/
private ConnectivityService cnnService;
/**
* 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
*/
private byte[] exceptions;
/**
* Applet tests HCIMessage commands
*/
private Api_1_Hme_Mty_2() {
/*
* JavaCard applet register
*/
register();
/*
* HCI listener register
*/
try {
cnnService = (ConnectivityService) HCIDevice.getHCIService(HCIDevice.CONNECTIVITY_SERVICE_ID);
cnnService.register(this);
cnnService.activateEvent(EVENT_STAND_BY);
} catch (HCIException e) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
exceptions = new byte[8];
}
/**
* 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_2();
}
/**
* 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) {
switch (event) {
case EVENT_STAND_BY:
exceptions[2] = hcimessage.getType();
// 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 apdu) throws ISOException {
/*
* Check for SELECT command
*/
if (selectingApplet())
return;
/*
* analyze incoming data
*/
byte buffer[] = apdu.getBuffer();
switch (buffer[ISO7816.OFFSET_INS]) {
/*
* HCIServce.activateEvent()
*/
case INS_CHECK_VB:
if ((exceptions[2] & 0xFF) != 0x40)
ISOException.throwIt(SW_EVENT_NOT_TRIGGERED);
return;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
public coid deselect(boolean arg0){
}
public boolean select(boolean arg0){
return true;
}