1 /* 2 * --------- 3 * |.##> <##.| Open Smart Card Development Platform (www.openscdp.org) 4 * |# #| 5 * |# #| Copyright (c) 1999-2006 CardContact Software & System Consulting 6 * |'##> <##'| Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de) 7 * --------- 8 * 9 * This file is part of OpenSCDP. 10 * 11 * OpenSCDP is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License version 2 as 13 * published by the Free Software Foundation. 14 * 15 * OpenSCDP is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with OpenSCDP; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 // 26 // Example how to use Java classes from within scripts 27 // Use 14443 low level commands with CT-API card reader 28 // 29 30 // 1. Get CardTerminalRegistry from OpenCard Framework 31 32 var ctr = Packages.opencard.core.terminal.CardTerminalRegistry.getRegistry(); 33 34 // 2. Get CardTerminal instance for a given name 35 36 if (_scsh3.reader) { 37 var ct = ctr.cardTerminalForName(_scsh3.reader); 38 } 39 40 // 3. Turn of antenna power 41 var cmd = new ByteString("poff", ASCII); 42 43 var apdu = new ByteBuffer("8070", HEX); 44 apdu.append(cmd.length); 45 apdu.append(0x00); 46 apdu.append(cmd.length); 47 apdu.append(cmd); 48 49 var response = ct.sendTerminalCommand(apdu.toByteString()); 50 print(response); 51 52 53 // 4. Select type A 54 var cmd = new ByteString("oa", ASCII); 55 56 var apdu = new ByteBuffer("8070", HEX); 57 apdu.append(cmd.length); 58 apdu.append(0x00); 59 apdu.append(cmd.length); 60 apdu.append(cmd); 61 62 var response = ct.sendTerminalCommand(apdu.toByteString()); 63 print(response); 64 65 66 // 5. Send REQA 67 var cmd = new ByteString("26", HEX); 68 69 var apdu = new ByteBuffer("8074E300", HEX); 70 apdu.append(cmd.length); 71 apdu.append(cmd); 72 73 var response = ct.sendTerminalCommand(apdu.toByteString()); 74 print(response); 75 76 77 78 // 6. Send 1st SELECT 79 var cmd = new ByteString("9320", HEX); 80 81 var apdu = new ByteBuffer("80740300", HEX); 82 apdu.append(cmd.length); 83 apdu.append(cmd); 84 85 var response = ct.sendTerminalCommand(apdu.toByteString()); 86 print(response); 87 88 var uid = response.bytes(0, response.length - 2); 89 print("UID=" + uid.toString(HEX)); 90 91 92 // 7. Send 2nd SELECT 93 var cmd = new ByteString("9370", HEX); 94 95 var apdu = new ByteBuffer("80740F00", HEX); 96 apdu.append(cmd.length + uid.length); 97 apdu.append(cmd); 98 apdu.append(uid); 99 100 var response = ct.sendTerminalCommand(apdu.toByteString()); 101 print(response); 102 103 104 // 8. Send RATS 105 var cmd = new ByteString("E080", HEX); 106 107 var apdu = new ByteBuffer("80740F00", HEX); 108 apdu.append(cmd.length); 109 apdu.append(cmd); 110 111 var response = ct.sendTerminalCommand(apdu.toByteString()); 112 print(response); 113 114