/** * Initialize a DS1963S as a fresh user iButton for a given SHA service. This constructor not only * creates the service file for the user iButton using the TMEX file structure, but it also * installs the master authentication secret and binds it to the iButton (making it unique for a * particular button). Optionally, the device can be formatted before the service file is * installed. * * @param coprBindData The Coprocessor Bind Data, used to create a unique secret for this user * token. * @param coprBindCode The Coprocessor Bind Code without the user-specific information, used to * create a unique secret for this user token. * @param fileName The file name for the account info. * @param fileNameExt The file extenstion for the account info * @param owc The DS1963S iButton that this object will refer to. * @param formatDevice If <code>true</code>, the TMEX filesystem will be formatted before the * account service file is created. * @param authSecret The master authentication secret for the systm. * @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 * @see #SHAiButtonUser18(SHAiButtonCopr,OneWireContainer18) * @see #SHAiButtonUser18(SHAiButtonCopr) */ public SHAiButtonUser18( byte[] coprBindData, byte[] coprBindCode, byte[] fileName, int fileNameExt, OneWireContainer18 owc, boolean formatDevice, byte[] authSecret) throws OneWireException, OneWireIOException { // hold container reference this.ibc = owc; // and address this.address = owc.getAddress(); System.arraycopy(fileName, 0, this.serviceFile, 0, 4); // create string representation of service filename this.strServiceFilename = new String(fileName) + "." + (int) fileNameExt; if (!createServiceFile(owc, strServiceFilename, formatDevice)) throw new OneWireException("Failed to create service file."); // save a copy of the binding code System.arraycopy(coprBindCode, 0, this.fullBindCode, 0, 7); System.arraycopy(this.fullBindCode, 4, this.fullBindCode, 12, 3); // setup the fullBindCode with rest of info this.fullBindCode[4] = (byte) this.accountPageNumber; System.arraycopy(this.address, 0, this.fullBindCode, 5, 7); if (!owc.installMasterSecret(accountPageNumber, authSecret, accountPageNumber & 7)) throw new OneWireException("Install Master Secret failed"); // not in critical path, so getBindBlah() is okay. if (!owc.bindSecretToiButton( accountPageNumber, coprBindData, this.fullBindCode, accountPageNumber & 7)) throw new OneWireException("Bind Secret to iButton failed"); // \\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ if (DEBUG) { IOHelper.writeLine("------------------------------------"); IOHelper.writeLine("Initialized User"); IOHelper.writeLine("address"); IOHelper.writeBytesHex(owc.getAddress()); IOHelper.writeLine("serviceFilename: " + strServiceFilename); IOHelper.writeLine("accountPageNumber: " + accountPageNumber); IOHelper.writeLine("authSecret"); IOHelper.writeBytesHex(authSecret); IOHelper.writeLine("bindCode"); IOHelper.writeBytesHex(coprBindCode); IOHelper.writeLine("------------------------------------"); } // \\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ }