/******************************************************************************
*                                                                             *
*              Copyright (C),  Philips Semiconductors SLH                     *
*                                                                             *
*  All rights are reserved. Reproduction in whole or in part is prohibited    *
*           without the written consent of the copyright owner.               *
*                                                                             *
*  Philips reserves the right to make changes without notice at any time.     *
* Philips makes no warranty, expressed, implied or statutory, including but   *
* not limited to any implied warranty of merchantibility or fitness for any   *
*   particular purpose, or that the use will not infringe any third party     *
* patent, copyright or trademark. Philips must not be liable for any loss or  *
*                      damage arising from its use.                           *
*                                                                             *
*******************************************************************************
*                                                                             *
*       Project: 336355/105 - Control SW Library for HTRC110/HTRC120/HITAG2   *
*                                                                             *
*       File: CO_GETV.C                                                       *
*       Author: F. Boeh                                                       *
*               S. de Zeeuw                                                   *
*                                                                             *
*******************************************************************************
*      DATE      *          CHANGES DONE                         *    BY      *
*******************************************************************************
*                *                                               *            *
*  Apr 27,1998   * Version 2.0, release                          * DE ZEEUW   *
*                *                                               *            *
*******************************************************************************/

#include "HTRC120.H"
#include "portab.h"


#pragma regparms


unsigned char Crypt_Get_Version( unsigned char idata * addr, 
                                 unsigned char version_length )
/******************************************************************************
*                                                                             *
* Description:                                                                *
* The procedure sends the get_version command and a serial (dummy) number to  *
* the co-processor. Afterwards it reads the version data from the HTRC120.    *
*                                                                             *
* Parameters:                                                                 *
*   addr:      memory address where the version data shall be stored          *
*   version_length:                                                           * 
*              LONG_VERSION, if 33 bytes shall be stored.                     *
*              SHORT_VERSION, if only the first 2 Bytes have to be stored     *
* Return:                                                                     *
*   FALSE      in case  no error occured                                      *
*   TRUE       in case of an error occured                                    *
*                                                                             *
******************************************************************************/
{
   init_copro();              /* reset co-processor */


   *addr = CMD_GET_VERSION;                  /* set command get_version */
   if (send_copro ( addr, 8 )) return TRUE;  /* send command            */

   *addr = 0xFF;                             /* create dummy byte to transmit */
   if (send_copro ( addr, 8 )) return TRUE;  /* send serial number to         */
   if (send_copro ( addr, 8 )) return TRUE;  /* cp-processor                  */
   if (send_copro ( addr, 8 )) return TRUE;
   if (send_copro ( addr, 8 )) return TRUE;

   if (receive_copro ( addr, 16 )) return TRUE; /* receive first 2 byte of */ 
                                                /* the version number      */

   if (version_length == LONG_VERSION) 
   {
     if (receive_copro (addr+2,240)) return TRUE;
   }

   return FALSE;
}

 
