static int testMTZ(void) { uchar ucData[2]; int ret; ucData[0] = 0x5a; ucData[1] = 0xa5; ret = cm_WriteConfigZone(DEFAULT_ADDRESS, 0x0A, ucData, 2, FALSE); if(0!=ret) { printf("write MTZ fail....ret=0x%x\n",ret); return -1; } ucData[0] = 0x00; ucData[1] = 0x00; ret = cm_ReadConfigZone(DEFAULT_ADDRESS, 0x0A, ucData, 2); if(0!=ret) { printf("read MTZ fail....ret=0x%x\n",ret); return -1; } if(ucData[0] != 0x5a || ucData[1] != 0xa5) { printf("testMTZ Error!! : %d : %d\n", ucData[0], ucData[1]); return -1; } return 0; }
/*********************************************************************** 函数名称: E2PROM_ReadConfigZone 函数说明: 读取配置区的数据 修改记录: 日 期 作 者 修定 --------- --------- ----- ************************************************************************/ sint E2PROM_ReadConfigZone(uchar Addr, uchar *Buffer, uchar NumberToWrite ) { sint NVMError = 0; sint CallError = 0; cm_InitI2c(); CallError = cm_ReadConfigZone( Addr,Buffer,NumberToWrite); CallError = CallError; cm_TermI2c(); return NVMError; }
// Read Checksum uchar cm_ReadChecksum(uchar ucChipAddr, puchar pucChkSum) { uchar ucDCR[1]; uchar ucReturn; ucCmdRdChk[0] = (0x6 | ((ucChipAddr & 0xf) << 4)); // 20 0x00s (10 0x00s, ignore first byte, 5 0x00s, ignore second byte, 5 0x00s cm_GPAGenN(20); // Read the checksum if ((ucReturn = cm_ReadCommand(ucCmdRdChk, pucChkSum, 2)) != SUCCESS) return ucReturn; // Check if unlimited reads allowed if ((ucReturn = cm_ReadConfigZone(ucChipAddr, DCR_ADDR, ucDCR, 1)) != SUCCESS) return ucReturn; if ((ucDCR[0] & DCR_UCR)) cm_ResetCrypto(); return SUCCESS; }
static int at88_config_unlock(void) { unsigned char tempData; unsigned char ucData[3]; RETURN_CODE ucReturn; tempData =0x00; int ret = cm_ReadConfigZone(DEFAULT_ADDRESS, 0xE8, &tempData, 1); if(ret != 0) { printf("cm_ReadConfigZone PAC7 fail!\n"); return -1; } if(tempData==0x00) { printf("\nPAC7 =0x%x\n",tempData); printf("\n at88 has been permantly locked, please change chip..\n"); return -1; } if(tempData!=0xff) { printf("\nPAC7 =0x%x\n",tempData); } ucData[0] = 0x22; ucData[1] = 0xE8; ucData[2] = 0x3F; ucReturn = cm_VerifyPassword(DEFAULT_ADDRESS, ucData,7, 0); if (ucReturn != SUCCESS) { printf("\ncm_VerifyPassword fail ...ret=0x%x\n",ucReturn); return -1; } return 0; }
static int at88_rwead_aac(void) { int ret; unsigned char tempData; //dcr , device addr 0x0b tempData=0x00; ret = cm_ReadConfigZone(DEFAULT_ADDRESS, 0x18, &tempData, 1); if(ret != 0) { printf("cm_ReadConfigZone reg 0x18 fail\n"); return -1; } //printf("DCR = 0x%2x\n", tempData); if(tempData!=0xeb) { tempData=0xeb;//clear etr ret = cm_WriteConfigZone(DEFAULT_ADDRESS, 0x18, &tempData, 1, FALSE); if (ret != SUCCESS) { printf("cm_WriteConfigZone reg 0x18 fail!\n"); return -1; } } tempData=0x00; ret = cm_ReadConfigZone(DEFAULT_ADDRESS, 0x60, &tempData, 1); if(ret != 0) { printf("cm_ReadConfigZone run wrong!!\n"); return -1; } //printf("AAC1 = 0x%2x\n", tempData); if(tempData!=0xff) { tempData = 0xff; ret = cm_WriteConfigZone(DEFAULT_ADDRESS, 0x60, &tempData, 1, FALSE); if (ret != SUCCESS) { printf("cm_WriteConfigZone run wrong!\n"); return -1; } } unsigned char init_cryptogram_data[7]; init_cryptogram_data[0]=0x22; init_cryptogram_data[1]=0x22; init_cryptogram_data[2]=0x22; init_cryptogram_data[3]=0x22; init_cryptogram_data[4]=0x22; init_cryptogram_data[5]=0x22; init_cryptogram_data[6]=0x22; ret = cm_WriteConfigZone(DEFAULT_ADDRESS, 0x61, init_cryptogram_data, 7, FALSE); if (ret != SUCCESS) { printf("cm_WriteConfigZone init_cryptogram_data fail !\n"); return -1; } return 0; }