📄 onewirecontainer16.java
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */// OneWireContainer16.javapackage com.dalsemi.onewire.container;import java.io.*;import java.util.*;import com.dalsemi.onewire.*;import com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.adapter.*;/** * <P> 1-Wire container for Java-powered iButton, DS195X. This container * encapsulates the functionality of the iButton family type * <B>16</B> and <B>96</B> (hex)</P> * * <H3> Features </H3> * <UL> * <LI> Java Card™ 2.0-compliant * <LI> True 32-bit Java integers for straightforward computation * <LI> Automatic garbage collection for efficient reuse of memory space * <LI> Resizable scratchpad optimizes memory usage and allows large atomic transactions * <LI> Dynamic applet capability for post-issuance updates * <LI> up to 64-kbyte ROM for Java VM and operating system * <LI> 6-kbyte NV SRAM杦rites in 100 nanoseconds杝upports multiple applications * <LI> Java-accessible True Time Clock time-stamps transactions * <LI> Java-accessible random number generator for cryptographic keys * <LI> JavaCardX.Crypto, SHA-1, RSA DES, triple DES cryptographic classes for secret key digital signatures * <LI> PKI support: PKCS # 11(Netscape®), CSP (Microsoft®), X509 certificates * <LI> Support for Win2000 log-on * <LI> Physically secure iButtonTM case zeroizes contents on tampering * <LI> 3V to 5V operating range * <LI> ESD protection >25,000V * <LI> Over 10 years of data retention * </UL> * * <H3> Usage </H3> * * <DL> * <DD> See the usage examples in * {@link com.dalsemi.onewire.container.CommandAPDU CommandAPDU} * to create <code>CommandAPDU</code>. * <DD> See the usage examples in * {@link com.dalsemi.onewire.container.ResponseAPDU ResponseAPDU} * to create <code>ResponseAPDU</code>. * </DL> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://www.ibutton.com/ibuttons/java.html"> * http://www.ibutton.com/ibuttons/java.html</A> * </DL> * * @see com.dalsemi.onewire.container.CommandAPDU * @see com.dalsemi.onewire.container.ResponseAPDU * * @version 0.00, 28 Aug 2000 * @author YL */public class OneWireContainer16 extends OneWireContainer{ /** CLA byte in the <code>CommandAPDU</code> header. */ static final byte CLA = ( byte ) 0xD0; /** INS byte in the <code>CommandAPDU</code> header. */ static final byte INS = ( byte ) 0x95; /** size of password length in byte */ public static final int PASSWORD_LENGTH_SIZE = 1; /** maximum length of password in byte */ public static final int PASSWORD_SIZE = 8; /** size of AID length in byte */ public static final int AID_LENGTH_SIZE = 1; /** maximum length of AID in byte */ public static final int AID_SIZE = 16; /** offset of AID length in applet APDU data stream */ public static final int AID_LENGTH_OFFSET = PASSWORD_LENGTH_SIZE + PASSWORD_SIZE; /** offset of AID name in applet APDU data stream */ public static final int AID_NAME_OFFSET = PASSWORD_LENGTH_SIZE + PASSWORD_SIZE + AID_LENGTH_SIZE; /** size of applet file header in byte */ public static final int APPLET_FILE_HEADER_SIZE = PASSWORD_LENGTH_SIZE + PASSWORD_SIZE + AID_LENGTH_SIZE + AID_SIZE; /** default APDU data packet length in byte */ public static int APDU_PACKET_LENGTH = 64; /** password */ private String password; /** current CommandaAPDU sent */ private CommandAPDU capdu = null; /** current <code>ResponseAPDU</code> received */ private ResponseAPDU rapdu = null; /** JibComm object for communicating with adapter */ private JibComm jibComm; /** default JibComm run time */ private int runTime = 0; /** * Default JibComm run time for select operations. These operations need * special consideration because the select operation could take longer * depending on what kind of APDU processing needs to be done. */ private int selectRunTime = 1; /** * Default JibComm run time for the last loadApplet packet. This packet * requires special consideration because extra processing is done after the * packet is loaded. */ private int loadRunTime = 2; /** * Creates an empty OneWireContainer16. Must call <code>setupContainer()</code> * method before using this new container.<p> * * This is one of the methods to construct a OneWireContainer16. The * others are through creating a OneWireContainer16 with parameters. * * @see #OneWireContainer16(DSPortAdapter,byte[]) * @see #OneWireContainer16(DSPortAdapter,long) * @see #OneWireContainer16(DSPortAdapter,String) * @see #setupContainer(DSPortAdapter,byte[]) * @see #setupContainer(DSPortAdapter,long) * @see #setupContainer(DSPortAdapter,String) */ public OneWireContainer16 () { super(); } // OneWireContainer16() /** * Creates a OneWireContainer16 with the provided adapter object * and the address of this Java iButton. * * This is one of the methods to construct a OneWireContainer16. The * others are through creating a OneWireContainer16 with different parameters * types. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this Java iButton * * @see com.dalsemi.onewire.utils.Address * @see #OneWireContainer16() * @see #OneWireContainer16(DSPortAdapter,long) * @see #OneWireContainer16(DSPortAdapter,String) */ public OneWireContainer16 (DSPortAdapter sourceAdapter, byte[] newAddress) { super(sourceAdapter, newAddress); } /** * Creates a OneWireContainer16 with the provided adapter object * and the address of this Java iButton. * * This is one of the methods to construct a OneWireContainer16. The * others are through creating a OneWireContainer16 with different parameters * types. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this Java iButton * * @see com.dalsemi.onewire.utils.Address * @see #OneWireContainer16() * @see #OneWireContainer16(DSPortAdapter,byte[]) * @see #OneWireContainer16(DSPortAdapter,String) */ public OneWireContainer16 (DSPortAdapter sourceAdapter, long newAddress) { super(sourceAdapter, newAddress); } /** * Creates a OneWireContainer16 with the provided adapter object * and the address of this Java iButton. * * This is one of the methods to construct a OneWireContainer16. The * others are through creating a OneWireContainer16 with different parameters * types. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this Java iButton * * @see com.dalsemi.onewire.utils.Address * @see #OneWireContainer16() * @see #OneWireContainer16(DSPortAdapter,byte[]) * @see #OneWireContainer16(DSPortAdapter,long) */ public OneWireContainer16 (DSPortAdapter sourceAdapter, String newAddress) { super(sourceAdapter, newAddress); } //------------------------------------------------------------------------- //-------- Methods //------------------------------------------------------------------------- //------------------------------------------------------------------------- /** Gets the Dallas Semiconductor part number of this Java iButton * as a string. For example "DS195X". * * @return string represetation of this Java iButton name */ public String getName () { return "DS195X"; } // getName() /** Gets the alternate Dallas Semiconductor part numbers or names. * A 'family' of One-Wire devices may have more than one part number * depending on packaging. There can also be nicknames such as * 'Crypto iButton'. * * @return string represetation of the alternate names */ public String getAlternateNames () { return "Java iButton, Cryptographic iButton"; } // getAlternateNames /** Gets a short description of the function of this Java iButton. * * @return string represetation of the function description */ public String getDescription () { return "JavaCard 2.0 compliant device."; } // getDescription() /** * Provides an adapter object to access this Java iButton. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this One-Wire device as a byte array. * * @see Address */ public void setupContainer (DSPortAdapter sourceAdapter, byte[] newAddress) { super.setupContainer(sourceAdapter, newAddress); setupJibComm(adapter, address); } /** * Provides an adapter object to access this Java iButton. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this One-Wire device as a long * * @see Address */ public void setupContainer (DSPortAdapter sourceAdapter, long newAddress) { super.setupContainer(sourceAdapter, newAddress); setupJibComm(adapter, address); } /** * Provides an adapter object to access this Java iButton. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this One-Wire device as a string * * @see Address */ public void setupContainer (DSPortAdapter sourceAdapter, String newAddress) { super.setupContainer(sourceAdapter, newAddress); setupJibComm(adapter, address); } /** * Provides an <code>JibComm</code> object to communicate * with this Java iButton. * * @param sourceAdapter adapter object required to communicate with * this Java iButton * @param newAddress address of this One-Wire device as a byte array * * @see Address */ public void setupJibComm (DSPortAdapter sourceAdapter, byte[] newAddress) { // JibComm has to communicate at OVERDRIVE speed. speed = adapter.SPEED_OVERDRIVE; speedFallBackOK = false; jibComm = new JibComm(this, sourceAdapter, newAddress); } /** * Gets the maximum speed this One-Wire device can communicate at. * * @return maximum speed of this One-Wire device */ public int getMaxSpeed () { return adapter.SPEED_OVERDRIVE; } /** * Gets the current <code>CommandAPDU</code> sent to this Java iButton * * @return current <code>CommandAPDU</code> sent to this Java iButton */ public CommandAPDU getCommandAPDUInfo () {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -