1 /* 2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 6239117 6470320 27 * @summary test if transmitControlCommand() works 28 * @author Andreas Sterbenz 29 * @run main/manual TestControl 30 */ 31 32 // This test requires special hardware. 33 34 import javax.smartcardio.Card; 35 import javax.smartcardio.CardException; 36 import javax.smartcardio.CardTerminal; 37 38 public class TestControl extends Utils { 39 40 private static final int IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE = 0x42000000 + 1; 41 42 public static void main(String[] args) throws Exception { 43 CardTerminal terminal = getTerminal(args); 44 45 // establish a connection with the card 46 Card card = terminal.connect("T=0"); 47 System.out.println("card: " + card); 48 49 byte[] data = new byte[] {2}; 50 // byte[] data = new byte[] {6, 0, 10, 1, 1, 16, 0}; 51 52 try { 53 byte[] resp = card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, data); 54 System.out.println("Firmware: " + toString(resp)); 55 throw new Exception(); 56 } catch (CardException e) { 57 // we currently don't know of any control commands that work with 58 // our readers. call the function just to make sure we don't crash 59 // or throw the wrong exception 60 System.out.println("OK: " + e); 61 e.printStackTrace(System.out); 62 } 63 try { 64 card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, null); 65 } catch (NullPointerException e) { 66 System.out.println("OK: " + e); 67 } 68 69 // disconnect 70 card.disconnect(true); 71 72 System.out.println("OK."); 73 } 74 75 }