123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*******************************************************************
- * id.c
- *
- ********************************************************************/
- #include <includes.h>
- #define ID_BASE_ADDR (0x1FFFF7E8ul)
- unsigned char g_ucRand=0;
- //
- //unsigned char aucSTM32ID1[12];
- //unsigned char aucSTM32SN1[12];
- //unsigned char aucSTM32ID2[12];
- //unsigned char aucSTM32SN2[12];
- //unsigned char aucSTM32ID3[12];
- //unsigned char aucSTM32SN3[12];
- //unsigned char g_aucSTM32ID[12];
- //
- ///***************************************************************
- //*
- //***************************************************************/
- //static const u32 apulSTM32IDAddr1[3]={
- // 0x115a7ef8ul,0x1F00123ul,ID_BASE_ADDR
- //};
- //static const unsigned char apucSNTab1[12]={
- // 0x12,0x98,0x32,0x76,0xa1,0x8b,0xf1,0x13,0x5a,0x21,0x01,0x32
- //};
- ///*
- //index must be 1
- //*/
- //void GetSTM32ID1(int index)
- //{
- // int i=index;
- // int j=i+1;
- // unsigned char data;
- // unsigned char *p;
- // u32 addr=apulSTM32IDAddr1[j];
- // for(i=0;i<12;i++){
- // p= (unsigned char *)addr;
- // data=*p;
- // aucSTM32ID1[i]=data ^ apucSNTab1[i];
- // p++;
- // }
- //}
- //void CheckSTM32ID1(void)
- //{
- // int i;
- // //read from eeprom
- //// EEPROM_ReadS(EEPROM_ID_SN1,aucSTM32SN1,12);
- // //check
- // for(i=0;i<12;i++){
- // if(aucSTM32SN1[i]!=aucSTM32ID1[i])break;
- // }
- // if(i!=12){
- // //while(1);
- // for(i=0;i<1000;i++){
- // if(i==900)i=0;
- // }
- // }
- //}
- //
- //
- //
- //
- //void GetSTM32ID(unsigned char *pID);
- //void CreateKey(unsigned char *pKey, unsigned char *pID);
- //unsigned char SaveKey(unsigned char *pKey);
- /***********************************************************
- * 函数:GetSTM32ID
- * 参数:1、*pID 读取的ID存放指针,12字节ID
- * 功能:获取本芯片内部出厂绑定的ID
- ***********************************************************/
- void GetSTM32ID(unsigned char *pID)
- {
- unsigned char i = 0;
- u32 addr = ID_BASE_ADDR;
- for(i = 0; i < 12; i++)
- {
- *pID = *(u32 *)addr;
- pID++;
- addr++;
- }
- }
- /************************************************************
- *
- *************************************************************/
- unsigned char GetRandBySTM32ID(void)
- {
- unsigned char id[12];
- unsigned char rand=0x58;//种子
- int i;
- GetSTM32ID(id);
- for(i=0;i<12;i++){
- rand^=id[i];
- }
- if(rand==0x00)rand=0x58;
- if(rand==0xff)rand=0x85;
- return rand;
- }
- /*********************************************************************/
|