?? dec5502_esam.c
字號:
/******************************************************************************/
/* Copyright 2004 by SEED Electronic Technology LTD. */
/* All rights reserved. SEED Electronic Technology LTD. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/* */
/******************************************************************************/
/* MODULE NAME... UART and ESAM */
/* FILENAME...... DEC5502_ESAM.c */
/* DATE CREATED.. Wed 10/21/2004 */
/* PROJECT....... Communicate between ESAM and on-chip UART of 5502 */
/* COMPONENT..... */
/* PREREQUISITS.. */
/*----------------------------------------------------------------------------*/
/* DESCRIPTION: */
/* */
/* This is an example of communication between ESAM and on-chip UART of 5502 */
/******************************************************************************/
#include <stdio.h>
#include <csl.h>
#include <csl_pll.h>
#include <csl_chip.h>
#include <csl_irq.h>
#include <csl_uart.h>
#include "Esam_Function.h"
#include "Uart_Function.h"
#include "DEC5502_MAC.h"
#include "DEC5502_DES.h"
#include "Emif.h"
#include "Timer.h"
Uint16 MK[8] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
Uint16 CSK[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
Uint16 MK16[16] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,
0xAA,0xBB,0xCC,0xDD,0xEE,0xFF,0x11,0x22};
Uint16 i;
Uint16 Temp;
Uint16 SerialNum[8]; // 存儲ESAM復位后獲取的序列號
Uint16 RandomData[8]; // 存儲取得的隨機數
Uint16 Input[48];
Uint16 Output[48];
/* 外部認證密鑰 */
//Uint16 AuthenKey[16] = {0x57,0x41,0x54,0x43,0x48,0x44,0x41,0x54,
// 0x41,0x54,0x69,0x6D,0x65,0x43,0x4F,0x53};
/* 操作的返回狀態 */
Uint16 FeedState = 0x00;
void main(void)
{
Uint16 i;
/* Initialize CSL library - This is REQUIRED !!! */
CSL_init();
/* 設置鎖相環 */
PLL_setFreq(1, // PLL mode
0xF, // Multiply factor, Valid values are (multiply by)10
0, // Sysclk 0 Divide Down
1, // Sysclk1 Divider 150MHz
3, // Sysclk2 Divider 75MHz
3, // Sysclk3 Divider
0); // DSP core clock 300MHz,單指令執行時間為3.33納秒
/* 清空序列號 */
for(i=0; i<8; i++)
{
SerialNum[i] = 0;
}
/* 配置EMIF */
Emif_Config();
/* 配置定時器 */
Config_Timer();
/* Configure UART registers */
Uart_Config();
/* 填寫欲寫入的數據,清空接收數據緩沖區 */
for(i=0; i<0x30; i++)
{
Input[i] = i+1;
Output[i] = 0;
}
/* 復位ESAM卡,用來獲取ESAM卡的序列號*/
FeedState = Reset_Esam(SerialNum);
/* 利用MK和序列號作DES加密運算來獲取CSK */
//Des8(SerialNum,MK,CSK,EN0,1);
/* 向ESAM發取隨機數命令,獲取隨機數 */
//FeedState = Get_Random(RandomData, 0x08);
/* 主控密鑰的外部認證 */
//FeedState = Extern_Authen(RandomData,0x00,CSK,DES8);
/* 刪除目錄 */
//FeedState = Del_Direct();
/* 建立Key文件 */
//FeedState = Create_Keyfile(0x0000, 0x50, 0xF0);
/* 建立主控密鑰,密鑰標識為0x00 */
//FeedState = Increase_Key(0x00, 0x39, 0xF0, 0xF0, 0x0A, 0xFF, CSK, DES8);
/* 建立線路保護加密密鑰,密鑰標識為0x01 */
//FeedState = Increase_Key(0x01, 0x36, 0xF0, 0xEF, 0xFF, 0xFF, MK, DES8);
/* 建立線路保護加密密鑰,密鑰標識為0x02 */
//FeedState = Increase_Key(0x02, 0x36, 0xF0, 0xEF, 0xFF, 0xFF, MK16, DES16);
/* 建立第1個線路加密和MAC保護二進制文件,文件標識為0x3F01,線路保護密鑰為0x01 */
//FeedState = Create_Binaryfile(0x3F01, 0x0050, 0xF0, 0xF0, 0x01);
/* 建立第2個線路加密和MAC保護二進制文件,文件標識為0x3F02,線路保護密鑰為0x01 */
// 通過外部認證之后才能建立文件
//FeedState = Create_Binaryfile(0x3F02, 0x0400, 0xF0, 0xF0, 0x01);
/* 建立第3個線路加密和MAC保護二進制文件,文件標識為0x3F03,線路保護密鑰為0x02 */
// 通過外部認證之后才能建立文件
//FeedState = Create_Binaryfile(0x3F03, 0x0400, 0xF0, 0xF0, 0x02);
/* 選擇該二進制文件 */
//FeedState = Select_File(0x3F03);
/* 寫二進制文件 */
//FeedState = Write_Binaryfile(Input,0x30, 0x0000, MK16, DES16);
/* 讀二進制文件 */
//FeedState = Read_Binaryfile(0x0000, 0x30, MK16, Output, DES16);
/*建立第4個線路加密和MAC保護二進制文件,文件標識為0x3F04,線路保護密鑰為0x02,
讀權限為F9,寫權限為FA,長度為1K */
//FeedState = Create_Binaryfile(0x3F04, 0x0400, 0xF9, 0xFA, 0x02);
/* 建立外部認證密鑰,密鑰標識為0x04,后續狀態為0x0B */
//FeedState = Increase_Key(0x04, 0x39, 0xF0, 0xF0, 0x0B, 0xFF, MK, DES8);
/* 復位ESAM卡,用來獲取ESAM卡的序列號*/
//FeedState = Reset_Esam(SerialNum);
/* 利用MK和序列號作DES加密運算來獲取CSK */
//Des8(SerialNum,MK,CSK,EN0,1);
/* 向ESAM發取隨機數命令,獲取隨機數 */
//FeedState = Get_Random(RandomData, 0x08);
/* 主控密鑰的外部認證 */
//FeedState = Extern_Authen(RandomData,0x00,CSK,DES8);
/* 選擇該二進制文件 */
//FeedState = Select_File(0x3F04);
/* 向ESAM發取隨機數命令,獲取隨機數 */
//FeedState = Get_Random(RandomData, 0x08);
/* 外部認證密鑰的外部認證 */
//FeedState = Extern_Authen(RandomData,0x04,MK,DES8);
/* 寫二進制文件 */
//FeedState = Write_Binaryfile(Input,0x30, 0x0000, MK16, DES16);
/* 讀二進制文件 */
//FeedState = Read_Binaryfile(0x0000, 0x30, MK16, Output, DES16);
}
/******************************************************************************/
/* No more */
/******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -