1 /* 2 * Copyright (c) 2005, 2016, 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 if (terminal == null) { 45 System.out.println("Skipping the test: " + 46 "no card terminals available"); 47 return; 48 } 49 50 // establish a connection with the card 51 Card card = terminal.connect("T=0"); 52 System.out.println("card: " + card); 53 54 byte[] data = new byte[] {2}; 55 // byte[] data = new byte[] {6, 0, 10, 1, 1, 16, 0}; 56 57 try { 58 byte[] resp = card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, data); 59 System.out.println("Firmware: " + toString(resp)); 60 throw new Exception(); 61 } catch (CardException e) { 62 // we currently don't know of any control commands that work with 63 // our readers. call the function just to make sure we don't crash 64 // or throw the wrong exception 65 System.out.println("OK: " + e); 66 e.printStackTrace(System.out); 67 } 68 try { 69 card.transmitControlCommand(IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE, null); 70 } catch (NullPointerException e) { 71 System.out.println("OK: " + e); 72 } 73 74 // disconnect 75 card.disconnect(true); 76 77 System.out.println("OK."); 78 } 79 80 }