📄 shaibuttonuser.java
字号:
* * @param ibc the OneWireContainer whose account info is checked * @return whether or not the device is initialized properly */ protected synchronized boolean checkAccountPageInfo(OneWireContainer ibc) { //this flag should only be set if there is valid data if(accountPageNumber<=0) { try { //create a file object representing service file OWFile owf = new OWFile(ibc, strServiceFilename); //check to see if file exists if(!owf.exists()) return false; //get the page number for the file //this.accountPageNumber = owf.getPageList()[0]; this.accountPageNumber = owf.getStartPage(); //close the file owf.close(); //mark the cache as dirty this.accountData[0] = 0; //clear the write cycle counter this.writeCycleCounter = -1; } catch(Exception e) { this.accountPageNumber=-1; if(DEBUG) { e.printStackTrace(); } } } return (this.accountPageNumber>0); } // *************************************************************** // // Begin Abstract Methods for SHAiButtonUser // // *************************************************************** // /** * <P>Modifies this SHA iButton so that it refers to another device. * If this object already has an appropriate instance of OneWireContainer, * that instance is updated with the new address.</P> * * @param adapter The adapter that the device can be found on. * @param address The address of the 1-Wire device * * @return <code>true</code> if a valid account service file exists on * this <code>OneWireContainer18</code>. * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ public abstract boolean setiButtonUser(DSPortAdapter adapter, byte[] address) throws OneWireException, OneWireIOException; /** * <P>Modifies this SHA iButton so that it refers to another device. * If this object does not already has an appropriate instance of * OneWireContainer, it returns false immediately, because there is * no adapter info available. Otherwise, it reuses the same adapter.</P> * * @param address The address of the 1-Wire device * * @return <code>true</code> if a valid account service file exists on * this <code>OneWireContainer18</code>. * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ public abstract boolean setiButtonUser(byte[] address) throws OneWireException, OneWireIOException; /** * <P>Returns the value of the write cycle counter for the * page where the account data is stored. If the write * cycle counter has ever been retrieved, this returns the * cached value. Otherwise, this method reads the value * from the part.</P> * * <P>For devices that do not support write cycle counters, * this method always returns -1.</P> * * @return the value of the write cycle counter for the * account data page. * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ public abstract int getWriteCycleCounter() throws OneWireException, OneWireIOException; /** * <P>Returns <code>true</code> if this buttons account data is stored * on a page that has a write cycle counter.</P> * * @return <code>true</code> if account page has write cycle counter. */ public abstract boolean hasWriteCycleCounter(); /** * <P>This function creates the full 15-byte binding data for the * coprocessor to use to recreate this user's secret on the copr's * workspace page. This function is located in the SHAiButtonUser * class to support binding codes for user buttons who use alternate * techniques (such as the DS1961S) for secret computation.</P> * * @param bindCode the 7-byte binding code from coprocessor's service file * @param fullBindCode the 15-byte full binding code to to be copied into * the coprocessor's scratchpad. There should be 15 * bytes available starting from the offset. * @param offset the offset into fullBindCode where copying should begin. * */ public abstract void getFullBindCode(byte[] l_fullBindCode, int offset); /** * <P>Returns a byte representing the appropriate authorization command * for the coprocessor to use to authenticate this user. For a DS1961S, * the authentication command is AUTH_HOST, but for a DS1963S, the * authentication command is VALIDATE_PAGE.</P> * * @return byte indicating appropriate command for authenticating user * */ public abstract byte getAuthorizationCommand(); /** * <P>Writes the account data to the SHAiButton. First, this function * asserts that the account page number is known. The account data is * copied from dataBuffer starting at the offset. If there are less * than 32 bytes available to copy, this function only copies the bytes * that are available.</P> * * @param dataBuffer the buffer to copy the account data from * @param offset the index into the buffer where copying should begin * @return whether or not the data write succeeded * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ public abstract boolean writeAccountData(byte[] dataBuffer, int offset) throws OneWireException, OneWireIOException; /** * <P>Reads the account data off the SHAiButton using a standard READ * command. First, this function asserts that the account page number is * known as well as the length of the account file. The 32 byte account * data page is copied into dataBuffer starting at the given offset.</P> * * @param dataBuffer the buffer to copy the account data into * @param offset the index into the buffer where copying should begin * @return whether or not the read was successful * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ public abstract boolean readAccountData(byte[] dataBuffer, int offset) throws OneWireException, OneWireIOException; /** * <P>Reads the account data off the SHAiButton using a READ_AUTHENTICATE * command. First, this function asserts that the account page number is * known as well as the length of the account file. Then it copies the * 3 byte challenge to the scratchpad before sending the command for * READ_AUTHENTICATE. The 32 byte account data page is copied into * dataBuffer starting at dataStart.</P> * * <P>In addition to the account data, this function also returns a * calculated MAC. The MAC requires 20 bytes after the start index. * The return value is the write cycle counter value for the account * data page<p> * * @param chlg the buffer containing a 3-byte random challenge. * @param chlgStart the index into the buffer where the 3 byte * challenge begins. * @param dataBuffer the buffer to copy the account data into * @param dataStart the index into the buffer where copying should begin * @param mac the buffer to copy the resulting Message Authentication Code * @param macStart the index into the mac buffer to start copying * * @return the value of the write cycle counter for the page * * @throws OneWireIOException on a 1-Wire communication error such as * reading an incorrect CRC from a 1-Wire device. This could be * caused by a physical interruption in the 1-Wire Network due to * shorts or a newly arriving 1-Wire device issuing a 'presence pulse'. * @throws OneWireException on a communication or setup error with the 1-Wire * adapter */ public abstract int readAccountData(byte[] chlg, int chlgStart, byte[] dataBuffer, int dataStart, byte[] mac, int macStart) throws OneWireException, OneWireIOException; // *************************************************************** // // End Abstract Methods for SHAiButtonUser // // *************************************************************** // /** * Refreshes eeprom SHA devices in case of weakly-programmed bits on * the account page. * * @return true if the refresh was successful */ public boolean refreshDevice() throws OneWireException,OneWireIOException { // no-op by default return true; } /** * <P>Returns a string representing this SHAiButton.</P> * * @return a string containing the 8-byte address of this 1-Wire device. */ public String toString () { StringBuffer sb = new StringBuffer(100); sb.append("USER: "); sb.append(Address.toString(this.address)); sb.append(", service: "); sb.append(this.strServiceFilename); sb.append(", acctPageNum: "); sb.append(this.accountPageNumber); return sb.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -