📄 memorybankscratchshaee.java
字号:
* @param writeBuf byte array containing data to write * @param offset offset into writeBuf to get data * @param len length in bytes to write * * @throws OneWireIOException * @throws OneWireException */ public void write (int addr, byte[] writeBuf, int offset, int len) throws OneWireIOException, OneWireException { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) { Debug.debug("-----------------------------------------------------------"); Debug.debug("MemoryBankScratchSHAEE.write(int, byte[], int, int) called"); Debug.debug(" romID="+owc33.getAddressAsString()); Debug.debug(" addr=0x" + Convert.toHexString((byte)addr)); Debug.debug(" writeBuf", writeBuf, offset, len); } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// writeScratchpad(addr, writeBuf, offset, len); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("-----------------------------------------------------------"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// } /** * Load First Secret for the DS2432. Loads the specified data * to the specified location. If the address is data memory * (instead of secret memory), this command must have been preceded by * a Refresh Scratchpad command for it to be successful. * * @param addr the address to write the data to * @param data the data to 'load' with the Load First Secret command * @param offset the offset to use for reading the data byte[] * * @throws OneWireIOException * @throws OneWireException */ public void loadFirstSecret(int addr, byte[] data, int offset) throws OneWireIOException, OneWireException { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) { Debug.debug("-----------------------------------------------------------"); Debug.debug("MemoryBankScratchSHAEE.loadFirstSecret(int, byte[], int) called"); Debug.debug(" romID="+owc33.getAddressAsString()); Debug.debug(" addr=0x" + Convert.toHexString(addr)); Debug.debug(" data", data, offset, 8); } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// writeScratchpad(addr, data, offset, 8); loadFirstSecret(addr); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("-----------------------------------------------------------"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// } /** * Load First Secret for the DS2432. Loads current contents of the * scratchpad to the specified location. If the address is data memory * (instead of secret memory), this command must have been preceded by * a Refresh Scratchpad command for it to be successful. * * @param addr the address to write the data to * * @throws OneWireIOException * @throws OneWireException */ public void loadFirstSecret(int addr) throws OneWireIOException, OneWireException { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) { Debug.debug("-----------------------------------------------------------"); Debug.debug("MemoryBankScratchSHAEE.loadFirstSecret(int) called"); Debug.debug(" romID="+owc33.getAddressAsString()); Debug.debug(" addr=0x" + Convert.toHexString((byte)addr)); } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// byte[] send_block = new byte[4]; checkSpeed(); // access the device if (ib.adapter.select(ib.getAddress())) { send_block [0] = LOAD_FIRST_SECRET; send_block [1] = ( byte ) (addr & 0x00FF); send_block [2] = ( byte ) ((addr >>> 8) & 0x00FF); send_block [3] = ( byte ) ((addr + 7) & 0x01F); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ if(DEBUG) Debug.debug("send_block", send_block, 0, 4); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ // now send the block ib.adapter.dataBlock(send_block,0,3); // provide strong pull-up for load ib.adapter.setPowerDuration(DSPortAdapter.DELIVERY_INFINITE); ib.adapter.startPowerDelivery(DSPortAdapter.CONDITION_AFTER_BYTE); ib.adapter.putByte(send_block[3]); try { Thread.sleep(20); } catch (InterruptedException e){} ib.adapter.setPowerNormal(); byte test = ( byte ) ib.adapter.getByte(); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ if(DEBUG) Debug.debug("result=" + Convert.toHexString(test)); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ if((test != (byte) 0xAA) && (test != (byte) 0x55)) throw new OneWireException("Error due to invalid load."); // if data is loaded to secrets memory, lets read it so we can // set the container secret if(addr==0x080) { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ if(DEBUG) Debug.debug("reading scratchpad and setting container secret"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\ byte[] secret = new byte[8]; readScratchpad(secret, 0, 8, null); owc33.setContainerSecret(secret, 0); } } else throw new OneWireIOException("Device select failed."); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("-----------------------------------------------------------"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// } /** * Computes the next secret. * * @param addr the physical address of the page to use for secret computation * @param partialsecret byte array containing next partial secret for writing to the scratchpad * * @throws OneWireIOException * @throws OneWireException */ public void computeNextSecret(int addr) throws OneWireIOException, OneWireException { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) { Debug.debug("-----------------------------------------------------------"); Debug.debug("MemoryBankScratchSHAEE.computeNextSecret(int) called"); Debug.debug(" romID="+owc33.getAddressAsString()); Debug.debug(" addr=0x" + Convert.toHexString((byte)addr)); } //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// byte[] send_block = new byte [3]; byte[] scratch = new byte [8]; byte[] next_secret = null; // check to see if secret is set if(owc33.isContainerSecretSet()) { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("Calculating next secret for container"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// byte[] memory = new byte [32]; byte[] secret = new byte [8]; byte[] MT = new byte [64]; readMemory(addr&0xE0, false, memory, 0, 32); owc33.getContainerSecret(secret, 0); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("currentSecret", secret, 0, 8); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// System.arraycopy(secret,0,MT,0,4); System.arraycopy(memory,0,MT,4,32); System.arraycopy(ffBlock,0,MT,36,4); readScratchpad(MT, 40, 8, null); MT[40] = ( byte ) (MT[40] & ( byte ) 0x3F); System.arraycopy(secret,4,MT,48,4); System.arraycopy(ffBlock,0,MT,52,3); // message padding MT[55] = ( byte ) 0x80; System.arraycopy(zeroBlock,0,MT,56,6); MT[62] = ( byte ) 0x01; MT[63] = ( byte ) 0xB8; //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("MT", MT, 0, 64); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// int[] AtoE = new int [5]; SHA.ComputeSHA(MT,AtoE); //copy E into secret for(int temp=AtoE[4],i=0;i<4;i++) { secret[i] = (byte)(temp & 0x0FF); temp >>= 8; } //copy D into secret for(int temp=AtoE[3],i=4;i<8;i++) { secret[i] = (byte)(temp & 0x0FF); temp >>= 8; } next_secret = secret; //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("nextSecret", secret, 0, 8); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// } checkSpeed(); // access the device if (ib.adapter.select(ib.getAddress())) { // Next Secret command send_block[0] = COMPUTE_NEXT_SECRET; // address 1 send_block[1] = ( byte ) (addr & 0xFF); // address 2 send_block[2] = ( byte ) (((addr & 0xFFFF) >>> 8) & 0xFF); // now send the block ib.adapter.dataBlock(send_block,0,2); // provide strong pull-up for compute next secret ib.adapter.setPowerDuration(DSPortAdapter.DELIVERY_INFINITE); ib.adapter.startPowerDelivery(DSPortAdapter.CONDITION_AFTER_BYTE); ib.adapter.putByte(send_block[2]); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("sendblock ", send_block, 0, 3); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// try { Thread.sleep(14); } catch (InterruptedException e){} ib.adapter.setPowerNormal(); readScratchpad(scratch,0,8,null); for(int i=0;i<8;i++) { if(scratch[i] != ( byte ) 0xAA) { throw new OneWireIOException("Next secret not calculated."); } } if(next_secret!=null) { //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("setting container secret", next_secret, 0, 8); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// owc33.setContainerSecret(next_secret, 0); } } else throw new OneWireIOException("Device select failed."); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// if(DEBUG) Debug.debug("-----------------------------------------------------------"); //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// } /** * Computes the next secret. * * @param addr the physical address of the page to use for secret computation * @param partialsecret byte array containing next partial secret for writing to the scratchpad * @param offset into partialsecret byte array to start reading * * @throws OneWireIOException * @throws OneWireException */ public void computeNextSecret(int addr, byte[] partialsecret, int offset) throws OneWireIOException, OneWireException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -