
/*---------------------------------------------------------------------------
 * 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.
 *---------------------------------------------------------------------------
 */

package com.dalsemi.onewire.container;

// imports
import com.dalsemi.onewire.adapter.DSPortAdapter;
import java.util.Vector;
import java.util.Enumeration;


/**
 * iButton container for iButton family type 13 (hex), DS1983/DS2503. <p>
 *
 *  @version    0.00, 28 Aug 2000
 *  @author     DS
 */
public class OneWireContainer13
   extends OneWireContainer
{

   //--------
   //-------- Constructors
   //--------

   /**
    * Default constructor
    */
   public OneWireContainer13 ()
   {
      super();
   }

   /**
    * Create a container with a provided adapter object
    * and the address of the iButton or 1-Wire device.
    *
    * @param  sourceAdapter     adapter object required to communicate with
    * this iButton.
    * @param  newAddress        address of this 1-Wire device
    */
   public OneWireContainer13 (DSPortAdapter sourceAdapter, byte[] newAddress)
   {
      super(sourceAdapter, newAddress);
   }

   /**
    * Create a container with a provided adapter object
    * and the address of the iButton or 1-Wire device.
    *
    * @param  sourceAdapter     adapter object required to communicate with
    * this iButton.
    * @param  newAddress        address of this 1-Wire device
    */
   public OneWireContainer13 (DSPortAdapter sourceAdapter, long newAddress)
   {
      super(sourceAdapter, newAddress);
   }

   /**
    * Create a container with a provided adapter object
    * and the address of the iButton or 1-Wire device.
    *
    * @param  sourceAdapter     adapter object required to communicate with
    * this iButton.
    * @param  newAddress        address of this 1-Wire device
    */
   public OneWireContainer13 (DSPortAdapter sourceAdapter, String newAddress)
   {
      super(sourceAdapter, newAddress);
   }

   //--------
   //-------- Methods
   //--------

   /**
    * Retrieve the Dallas Semiconductor part number of the iButton
    * as a string.  For example 'DS1992'.
    *
    * @return string represetation of the iButton name.
    */
   public String getName ()
   {
      return "DS1983";
   }

   /**
    * Retrieve the alternate Dallas Semiconductor part numbers or names.
    * A 'family' of MicroLAN 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 "DS2503";
   }

   /**
    * Retrieve a short description of the function of the iButton type.
    *
    * @return string represetation of the function description.
    */
   public String getDescription ()
   {
      return "4096 bit Electrically Programmable Read Only Memory "
             + "(EPROM) partitioned into sixteen 256 bit pages."
             + "Each memory page can be permanently write-protected "
             + "to prevent tampering.  Architecture allows software "
             + "to patch data by supersending a used page in favor of "
             + "a newly programmed page.";
   }

   /**
    * Return an enumeration of memory banks. Look at the
    * MemoryBank, PagedMemoryBank and OTPMemoryBank classes.
    */
   public Enumeration getMemoryBanks ()
   {
      Vector bank_vector = new Vector(6);

      // Address number in read-only-memory
      bank_vector.addElement(new MemoryBankROM(this));

      // EPROM main bank
      MemoryBankEPROM mn = new MemoryBankEPROM(this);

      mn.numberPages = 16;
      mn.size        = 512;

      bank_vector.addElement(mn);

      // EPROM status write protect pages bank
      MemoryBankEPROM wp = new MemoryBankEPROM(this);

      wp.bankDescription      = "Write protect pages";
      wp.numberPages          = 1;
      wp.size                 = 8;
      wp.pageLength           = 8;
      wp.generalPurposeMemory = false;
      wp.extraInfo            = false;
      wp.extraInfoLength      = 0;
      wp.extraInfoDescription = null;
      wp.crcAfterAddress      = false;
      wp.READ_PAGE_WITH_CRC   = MemoryBankEPROM.STATUS_READ_PAGE_COMMAND;
      wp.WRITE_MEMORY_COMMAND = MemoryBankEPROM.STATUS_WRITE_COMMAND;

      bank_vector.addElement(wp);

      // EPROM status write protect redirection bank
      MemoryBankEPROM wpr = new MemoryBankEPROM(this);

      wpr.bankDescription      = "Write protect redirection";
      wpr.numberPages          = 1;
      wpr.size                 = 8;
      wpr.pageLength           = 8;
      wpr.generalPurposeMemory = false;
      wpr.extraInfo            = false;
      wpr.extraInfoLength      = 0;
      wpr.extraInfoDescription = null;
      wpr.crcAfterAddress      = false;
      wpr.READ_PAGE_WITH_CRC   = MemoryBankEPROM.STATUS_READ_PAGE_COMMAND;
      wpr.WRITE_MEMORY_COMMAND = MemoryBankEPROM.STATUS_WRITE_COMMAND;
      wpr.startPhysicalAddress = 32;

      bank_vector.addElement(wpr);

      // EPROM status bitmap
      MemoryBankEPROM bm = new MemoryBankEPROM(this);

      bm.bankDescription      = "Bitmap of used pages for file structure";
      bm.numberPages          = 1;
      bm.size                 = 8;
      bm.pageLength           = 8;
      bm.generalPurposeMemory = false;
      bm.extraInfo            = false;
      bm.extraInfoLength      = 0;
      bm.extraInfoDescription = null;
      bm.crcAfterAddress      = false;
      bm.startPhysicalAddress = 64;
      bm.READ_PAGE_WITH_CRC   = MemoryBankEPROM.STATUS_READ_PAGE_COMMAND;
      bm.WRITE_MEMORY_COMMAND = MemoryBankEPROM.STATUS_WRITE_COMMAND;

      bank_vector.addElement(bm);

      // EPROM status redirection
      MemoryBankEPROM rd = new MemoryBankEPROM(this);

      rd.bankDescription      = "Page redirection bytes";
      rd.generalPurposeMemory = false;
      rd.numberPages          = 2;
      rd.size                 = 16;
      rd.pageLength           = 8;
      rd.extraInfo            = false;
      rd.extraInfoLength      = 0;
      rd.extraInfoDescription = null;
      rd.crcAfterAddress      = false;
      rd.startPhysicalAddress = 256;
      rd.READ_PAGE_WITH_CRC   = MemoryBankEPROM.STATUS_READ_PAGE_COMMAND;
      rd.WRITE_MEMORY_COMMAND = MemoryBankEPROM.STATUS_WRITE_COMMAND;

      bank_vector.addElement(rd);

      // setup OTP features in main memory
      mn.mbLock           = wp;
      mn.mbRedirect       = rd;
      mn.mbLockRedirect   = wpr;
      mn.redirectPage     = true;
      mn.lockPage         = true;
      mn.lockRedirectPage = true;

      return bank_vector.elements();
   }
}
