// Read Configuration Zone
//

// CryptoMemory Library Include Files
#include "CM_LIB.h"
#include "CM_I2C.h"
#include "CM_I2C_L.h"
#include "CM_GPA.h"

// Read Configuration Zone
uint8_t cm_ReadConfigZone(uint8_t ucCryptoAddr, uint8_t * pucBuffer, uint8_t ucCount)
{
    uint8_t ucReturn, ucEncrypt;

    ucCM_InsBuff[0] = 0xb6;
    ucCM_InsBuff[1] = 0x00;
    ucCM_InsBuff[2] = ucCryptoAddr;
    ucCM_InsBuff[3] = ucCount;
    
    // Three bytes of the command must be included in the polynominals
    cm_GPAcmd2(ucCM_InsBuff);
    
    // Do the read
    if ((ucReturn = cm_ReadCommand(ucCM_InsBuff, pucBuffer, ucCount)) != SUCCESS) return ucReturn;
	
    // Only password zone is ever encrypted
    ucEncrypt = ((ucCryptoAddr>= CM_PSW) && ucCM_Encrypt);

    // Include the data in the polynominals and decrypt if required
    cm_GPAdecrypt(ucEncrypt, pucBuffer, ucCount); 

    // Done
    return SUCCESS;
}
