📄 testpad03.c
字号:
if (usRet != ICCER_OK)
{
return usRet;
}
GetMifErrMessage(ucStatus, szErrMessage);
PubDisplays(1, 1, "%s\n", szErrMessage);
for (i = 0; i < 16; i++)
{
PubDisplays(1, 1, "%02X ", ucTmpBuf[i]);
}
/*
//准备写数据
ucSector = 8;
for(i=0; i<16; i++ )
ucTmpBuf[i] = i;
PubDisplays(1, 1, "MifWrite...... " );
usRet = MifWrite(hCT, (uchar)(4*ucSector+1), ucTmpBuf, &ucStatus);
if (usRet != ICCER_OK ) return usRet;
GetMifErrMessage(ucStatus, szErrMessage);
PubDisplays(1, 1, "%s\n", szErrMessage);
//读数据
PubDisplays(1, 1, "MifRead...........");
usRet = MifRead(hCT, (uchar)(4*ucSector+1), ucTmpBuf, &ucStatus);
if (usRet != ICCER_OK ) return usRet;
GetMifErrMessage(ucStatus, szErrMessage);
PubDisplays(1, 1, "%s\n", szErrMessage);
//准备数值块
PubDisplays(1, 1, "MifWrite..........");
memcpy(ucTmpBuf, "\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\xff\x00\xff", 16 );
usRet = MifWrite(hCT, (uchar)(4*ucSector+1), ucTmpBuf, &ucStatus);
if (usRet != ICCER_OK ) return usRet;
GetMifErrMessage(ucStatus, szErrMessage);
PubDisplays(1, 1, "%s\n", szErrMessage);
PubDisplays(1, 1, "IncSector10.......");
ucStatus = IncSector(hCT, 10, (uchar)(4*ucSector+1));
GetMifErrMessage(ucStatus, szErrMessage);
PubDisplays(1, 1, "%s\n", szErrMessage);
//读数据
usRet = MifRead(hCT, (uchar)(4*ucSector+1), ucTmpBuf, &ucStatus);
if (usRet != ICCER_OK ) return usRet;
for ( i=0; i<16; i++ )
PubDisplays(1, 1, "%02X ", ucTmpBuf[i] );
PubDisplays(1, 1, "\nDecSector9........");
ucStatus = DecSector(hCT, 9, (uchar)(4*ucSector+1));
GetMifErrMessage(ucStatus, szErrMessage);
PubDisplays(1, 1, "%s\n", szErrMessage);
//读数据
usRet = MifRead(hCT, (uchar)(4*ucSector+1), ucTmpBuf, &ucStatus);
if (usRet != ICCER_OK ) return usRet;
for ( i=0; i<16; i++ )
PubDisplays(1, 1, "%02X ", ucTmpBuf[i] );
*/
return 0;
}
void test_pinpad(void)
{
char c = 0;
char szBuf[100];
char mac_data[512];
unsigned char ucMasterKeyID = 5;
unsigned char ucWorkKeyID = 5;
unsigned char ucMacKeyID = 5;
unsigned char ucLen = 0;
printf("Beginning test of PinPad API...\n");
c = EA_ucSelectKey(EM_pin_WORKKEY, ucWorkKeyID);
printf("EA_ucSelectKey status = [%c]\n", c);
c = EA_ucReadPinpadNew(0, EM_pin_KEYOFF, EM_pin_ENCRYPTON, &ucLen, szBuf);
printf("Input Pin [%c] Len=%d\n", c, ucLen);
debug_disps(1, szBuf, 16);
memset(szBuf, 0, sizeof(szBuf));
c = EA_ucGetPinVer(EM_pin_USERVER, szBuf);
displays ( 5, 1, "%s\n", szBuf );
c = EA_vPinpadBeep(50);
printf("EA_vPinpadBeep status = [%c]\n", c);
c = reset_pinpad();
printf("reset pinpad status = [%c]\n", c);
//显示
c = display_752(1, "123456789");
printf("display_752 status = [%c]\n", c);
c = display_pinpad("Pls Input Pin");
printf("display_pinpad status = [%c]\n", c);
if (c == 'C')
{
return;
}
//密码输入
c = load_card_no("12345678");
printf("load_card_no status = [%c]\n", c);
printf("Pls Input Key......\n");
//输入密码的超时需要在函数外面设置(缺省60s)
SetPadTimeout(1, 122000);
memset(szBuf, 0, sizeof(szBuf));
c = read_pinpad(6, 1, 1, szBuf);
if (c == 'C')
{
//通信超时退出
reset_pinpad();
}
printf("read_pinpad status = [%c]\n", c);
debug_disps(1, szBuf, 16);
//用户数据加密, 使用workkey加密
memset(szBuf, 0, sizeof(szBuf));
c = load_card_no("12345678");
user_encrypt("123456", szBuf);
debug_disps(1, szBuf, 16);
c = load_master_key(0, "11111111");
printf("load_master_key status = [%c]\n", c);
//下载主密钥
c = select_master_key(0);
printf("select_master_key status = [%c]\n", c);
c = load_workkey("\x65\x5E\xA6\x28\xCF\x62\x58\x5F");
printf("load_workkey status = [%c]\n", c);
c = select_master_key(0);
c = load_mac_key("\x65\x5E\xA6\x28\xCF\x62\x58\x5F");
printf("load_mac_key status = [%c]\n", c);
//MAC计算
memset(mac_data, 0x55, sizeof(mac_data));
c = load_mac_data(mac_data, szBuf, 248);
printf("load_mac_data status = [%c]\n", c);
debug_disps(1, szBuf, 8);
//下载主密钥
c = EA_ucLoadKey(EM_pin_MASTERKEY, ucMasterKeyID, 8, "11111111");
printf("EA_ucLoadKey status = [%c]\n", c);
//选择主密钥
c = EA_ucSelectKey(EM_pin_MASTERKEY, ucMasterKeyID);
printf("EA_ucSelectKey status = [%c]\n", c);
//下载工作密钥
c = EA_ucLoadKey(EM_pin_WORKKEY, ucWorkKeyID, 8, "\x65\x5E\xA6\x28\xCF\x62\x58\x5F");
printf("EA_ucLoadKey status = [%c]\n", c);
//下载Mac密钥
c = EA_ucSelectKey(EM_pin_MASTERKEY, ucMasterKeyID);
c = EA_ucLoadKey(EM_pin_MACKEY, ucMacKeyID, 8, "\x65\x5E\xA6\x28\xCF\x62\x58\x5F");
printf("EA_ucLoadKey status = [%c]\n", c);
//检查密钥
c = EA_ucCheckKeyNew(EM_pin_MACKEY, ucMacKeyID);
printf("EA_ucCheckKeyNew status = [%c]\n", c);
c = EA_ucCheckKeyNew(EM_pin_MACKEY, ucMacKeyID + 1);
printf("EA_ucCheckKeyNew status = [%c]\n", c);
c = EA_ucCheckKeyNew(EM_pin_WORKKEY, ucWorkKeyID);
printf("EA_ucCheckKeyNew status = [%c]\n", c);
c = EA_ucCheckKeyNew(EM_pin_WORKKEY, ucWorkKeyID + 1);
printf("EA_ucCheckKeyNew status = [%c]\n", c);
//PIN输入
c = EA_ucSelectKey(EM_pin_WORKKEY, ucWorkKeyID);
printf("EA_ucSelectKey status = [%c]\n", c);
c = EA_ucReadPinpadNew(0, EM_pin_KEYOFF, EM_pin_ENCRYPTON, &ucLen, szBuf);
printf("Input Pin [%c] Len=%d\n", c, ucLen);
debug_disps(1, szBuf, 16);
c = display_730(1, "测试结束End");
printf("display_730 status = [%c]\n", c);
return;
//关闭通讯口1
}
short test_key_system(unsigned char hd_no)
{
short ret;
unsigned char origin_key[9];
unsigned char m_key[13], tmp[16], data1[16], key_16[17];
unsigned char tmp_data[100], tmp_data1[100];
unsigned char random[50];
unsigned char tmp_str[100];
char err_str[100];
unsigned char pin_key[] = "22345678", mac_key[] = "\a\0\0\0\0\0\0\0";
unsigned char file_key[] = "\1\0\0\0\0\0\0\0";
memset(tmp_str, 0, sizeof(tmp_str));
memcpy(tmp_str, "123456", 6);
ret = Encrypt_data(hd_no, "_PWD", tmp_str, tmp_data, DES_E);
/* origin_key must be same with 750's origin_key */
memcpy(origin_key, "\x11\x45\xf9\x5b\x87\xa3\x00\xcd", 8);
memcpy(m_key, "\x01\x02\x03\x04\x05\x06\x07\x08", 8);
memcpy(data1, m_key, 8);
//DES ( origin_key, data1, data1 );
//DES ( m_key, m_key, tmp );
//只有STAR-750p STAR-752P才能使用该函数
ret = write_mast(hd_no, 1, data1, tmp);
if (ret != SUCC)
{
display(1, "(write_mast):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
//DES ( m_key, mac_key, data1 );
//DES ( mac_key, mac_key, tmp );
ret = write_key(hd_no, 1, "_MAC", data1, tmp);
if (ret != SUCC)
{
display(1, "(write_key):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
ret = write_user_key(hd_no, "_MAC", mac_key);
if (ret != SUCC)
{
display(1, "(write_user_key):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
ret = write_user_key(hd_no, "FILE", file_key);
if (ret != SUCC)
{
display(1, "(write_user_key):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
ret = del_work_key(hd_no, "PIN_");
if (ret != SUCC)
{
displays(1, 1, "(del_work_key):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
//DES ( mac_key, pin_key, tmp );
ret = write_work(hd_no, "_PIN", tmp, "_MAC");
if (ret != SUCC)
{
displays(1, 1, "(write_work):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
// test encrypt function
memcpy(tmp_str, "11111111", 8);
ret = Encrypt_data(hd_no, "_MAC", tmp_str, tmp_data, DES_E);
if (ret != SUCC)
{
display(1, "(Encrypt_data):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
inkey(0);
}
memcpy(random, "\0\0\0\0\0\0\0\0", 8);
ret = gen_MAC(hd_no, "_MAC", random, 8, tmp_str, tmp_data1);
//genmac( mac_key, random, 8, tmp_str, tmp_data);
if (memcmp(tmp_data1, tmp_data, 8))
{
return FAIL;
}
//DES ( mac_key, tmp_str, tmp_data1 );
if (memcmp(tmp_data1, tmp_data, 8))
{
return FAIL;
}
//test triple_des
cls();
displays(1, 1, "triple_des function\n");
memcpy(key_16, mac_key, 8);
memcpy(key_16 + 8, pin_key, 8);
ret = write_user_key(hd_no, "KEYL", key_16);
if (ret != SUCC)
{
display(1, "(write_user_key):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
return (FAIL);
}
ret = write_user_key(hd_no, "KEYR", key_16 + 8);
if (ret != SUCC)
{
displays(1, 1, "(write_user_key):");
GetErrorMessage(ret, err_str);
display(2, "%s", err_str);
return (FAIL);
}
displays(7, 1, "End Testing Key System\n");
displays(8, 1, "Press any key to continue\n");
inkey(0);
cls();
return SUCC;
}
void Test711F(void)
{
HICC hCT;
WORD usRet = 0;
//建立物理端口(COM1)与读写器711F之间通讯的逻辑句柄
usRet = Mif_PortInit("COM1", &hCT, 9600);
if ( usRet != 0 )
{
PubDisplays(1, 1, "Mif_PortInit Error %x", usRet );
usRet = Mif_Close ( hCT );
return ;
}
TestProCard(hCT);
usRet = SetLed(hCT, 0, 1);
usRet = SetLed(hCT, 0, 0);
usRet = SetLed(hCT, 1, 1);
usRet = SetLed(hCT, 1, 0);
usRet = BuzzerMs(hCT, 4);
if ( usRet != 0 )
{
PubDisplays(1, 1, "BuzzerMs Error %x", usRet );
usRet = Mif_Close ( hCT );
return ;
}
usRet = Mif_Close ( hCT );
return;
}
int main(int argc, char *argv[])
{
char port_name[12], c;
short ret = 0;
unsigned char hd_no = 1, tmp_str[100];
unsigned int uiLen;
//用于711F读写器操作
return (Test711F());
strcpy(port_name, "COM1");
//ret = SPOS_ICCGetCardType("COM1", port_name, tmp_str);
//ret = init_port(port_name, PAD28800);
//test_4428(1);
#ifdef _POS_
do
{
#endif
//758密码键盘测试
//InitPad(port_name);
//test_pinpad();
//closecom(hd_no);
displays(1, 1, "Beginning test of Pad03...\n");
//对于7100用参数=0, 对于750,用参数=1000或=2000(750早期版本)
SetInitDelayTime(2000);
//设置通信协议 0--ASCII 1--BCD
SetCommuMode(0);
//strcpy(port_name, "/dev/ttyS1");
ret = init_port(port_name, PAD28800);
c = reset_pad(hd_no);
display_pad(hd_no, 1, "西安市");
if (ret != 0)
{
displays(2, 1, "PinPad Not Ready![%d]\n", ret);
goto prg_end;
}
displays(2, 1, "Open Serial port Sucessful! \n");
ret = ReadVersionPad(hd_no, tmp_str);
if (ret == 0)
{
displays(4, 1, "PinPad's Version is: ");
printf("%s\n", tmp_str);
if (!memcmp(tmp_str, "STAR-752", 8))
{
reader_type = READER_STAR752;
}
if (!memcmp(tmp_str, "STAR-750", 8))
{
reader_type = READER_STAR750;
}
if (!memcmp(tmp_str, "SCE-7100", 8))
{
reader_type = READER_STAR7100;
}
displays(8, 1, "Press any key to continue\n");
inkey(0);
cls();
}
//test_input_key(hd_no);
//return;
//密码键盘
//test_pinpad();
if (reader_type == READER_STAR7100)
{
//磁卡
if (test_magcard(hd_no) != 0)
{
return FAIL;
}
//读写参数
ret = WritePara(hd_no, 0, 10, "0123456789");
ret = ReadPara(hd_no, 0, 10, &uiLen, tmp_str);
}
//PAD03密钥系统
//test_key_system(hd_no);
//TestMifCard(hd_no);
//TestProCard(hd_no);
//测试存储卡
//test_4442(hd_no);
//test_4428(hd_no);
//键盘测试
test_input_key(hd_no);
//测试CPU卡
//test_cpu_card(hd_no);
//显示
test_display(hd_no);
displays(1, 1, "\nBegin test input key from PINPAD......! \n");
closecom(hd_no);
displays(7, 1, "End All Testing \n");
displays(8, 1, "Press any key to continue\n");
inkey(0);
cls();
prg_end:
#ifdef _POS_
;
} while (1);
#else
return SUCC;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -