📄 iccapp.lst
字号:
863 1 command.Le = 0x10;
864 1
865 1 if(!SamSendCommand(&command, &response))
866 1 return -1;
867 1 else
868 1 {
869 2 memcpy(outbuf, response.DAT, response.len);
870 2 return response.ISW;
871 2 }
872 1
873 1 }
874 /*****************************************
875 * Initialize for purchase(初始化消费) *
876 * CLA: 80, INS: 50 *
877 * Secret and protect mode: NO *
878 * Suport: PBOC *
879 * ED_EP: 钱包或存折 *
880 * transinfo: 交易信息 *
881 * 密钥索引*1 + 交易金额*4 + 终端机编号*6*
882 * outbuf: 输出数据 *
883 * 旧余额*4 + 交易序号*2 + 透支限额*3 *
884 * + 密钥版本*1 + 密钥算法*1 + 伪随机数*4*
885 *****************************************/
886 int ICC_init_for_purchase(unsigned char ED_EP ,unsigned char *transinfo, char *outbuf)
887 {
888 1 command.CLA = 0x80;
889 1 command.INS = 0x50;
890 1 command.P1 = 01;
891 1 command.P2 = ED_EP;
892 1 command.Lc = 0x0b;
893 1 command.DAT = transinfo;
894 1 command.Le = 0x10;
895 1
896 1 if(!SamSendCommand(&command, &response))
897 1 return -1;
898 1 else
899 1 {
900 2 memcpy(outbuf, response.DAT, response.len);
901 2 return response.ISW;
902 2 }
903 1
904 1 }
905
906 /*****************************************
907 * Credit for load *
908 * CLA: 80, INS: 52 *
909 * Secret and protect mode: NO *
910 * Suport: PBOC *
911 * inbuf: 交易日期*4 + 交易时间*2 + MAC2*4 *
912 * outbuf: TAC * 4 *
913 *******************************************/
914 int ICC_credit_for_load(char *inbuf, char *outbuf)
915 {
916 1
917 1 command.CLA = 0x80;
918 1 command.INS = 0x52;
919 1 command.P1 = 0;
920 1 command.P2 = 0;
921 1 command.Lc = 0x0b;
922 1 command.DAT = inbuf;
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 16
923 1 command.Le = 0x04;
924 1
925 1 if(!SamSendCommand(&command, &response))
926 1 return -1;
927 1 else
928 1 {
929 2 memcpy(outbuf, response.DAT, response.len);
930 2 return response.ISW;
931 2 }
932 1 }
933
934 /*****************************************
935 * Case withdraw *
936 * CLA: 80, INS: 54 *
937 * Secret and protect mode: NO *
938 * Suport: PBOC *
939 * transinfo: 交易信息:交易序号*4 *
940 * 交易日期*4 + 交易时间*3 + MAC1*4 *
941 * outbuf: 输出,TAC*4 + MAC*4 *
942 *****************************************/
943 int ICC_case_withdraw(char *transinfo, char *outbuf)
944 {
945 1 command.CLA = 0x80;
946 1 command.INS = 0x54;
947 1 command.P1 = 1;
948 1 command.P2 = 0;
949 1 command.Lc = 0x0f;
950 1 command.DAT = transinfo;
951 1 command.Le = 0x8;
952 1
953 1 if(!SamSendCommand(&command, &response))
954 1 return -1;
955 1 else
956 1 {
957 2 memcpy(outbuf, response.DAT, response.len);
958 2 return response.ISW;
959 2 }
960 1 }
961
962 /*****************************************
963 * Case withdraw *
964 * CLA: 80, INS: 54 *
965 * Secret and protect mode: NO *
966 * Suport: PBOC *
967 * transinfo: 交易信息:交易序号*4 *
968 * 交易日期*4 + 交易时间*3 + MAC1*4 *
969 * outbuf: 输出,TAC*4 + MAC*4 *
970 *****************************************/
971 int ICC_debit_for_purchase(char *transinfo, char *outbuf)
972 {
973 1 command.CLA = 0x80;
974 1 command.INS = 0x54;
975 1 command.P1 = 1;
976 1 command.P2 = 0;
977 1 command.Lc = 0x0f;
978 1 command.DAT = transinfo;
979 1 command.Le = 0x8;
980 1
981 1 if(!SamSendCommand(&command, &response))
982 1 return -1;
983 1 else
984 1 {
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 17
985 2 memcpy(outbuf, response.DAT, response.len);
986 2 return response.ISW;
987 2 }
988 1 }
989
990 /*****************************************
991 * update overdraw limit (修改透支金额)*
992 * CLA: 80, INS: 58 *
993 * Secret and protect mode: NO *
994 * Suport: PBOC *
995 * 参数1:交易信息:透支限额(3字节)+ 日期(4字节)+ 时间(3字节)+ MAC2*
996 * 参数1:输出交易TAC 码 *
997 *****************************************/
998 int ICC_update_overdraw_limit(unsigned char *transinfo,unsigned char *TAC)
999 {
1000 1 command.CLA = 0x80;
1001 1 command.INS = 0x58;
1002 1 command.P1 = 0;
1003 1 command.P2 = 0;
1004 1 command.Lc = 0x0a;
1005 1 command.DAT = transinfo;
1006 1 command.Le = 0x4;
1007 1
1008 1 if(!SamSendCommand(&command, &response))
1009 1 return -1;
1010 1 else
1011 1 {
1012 2 memcpy(TAC, response.DAT, response.len);
1013 2 return response.ISW;
1014 2 }
1015 1 }
1016
1017
1018
1019 /*****************************************
1020 * Get balance *
1021 * CLA: 80, INS: 5c *
1022 * Secret and protect mode: NO *
1023 * Suport: PBOC *
1024 * ed_ep: 01-ed(电子钱包), 02-ep(存折)*
1025 * balance: 余额 *
1026 *****************************************/
1027 int ICC_get_balance(char ed_ep, char *balance)
1028 {
1029 1 command.CLA = 80;
1030 1 command.INS = 0x5c;
1031 1 command.P1 = 0;
1032 1 command.P2 = ed_ep;
1033 1 command.Lc = 0;
1034 1 command.DAT = NULL;
1035 1 command.Le = 0x04;
1036 1
1037 1 if(!SamSendCommand(&command, &response))
1038 1 return -1;
1039 1 else
1040 1 {
1041 2 memcpy(balance, response.DAT, response.len);
1042 2 return response.ISW;
1043 2 }
1044 1 }
1045
1046 /*****************************************
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 18
1047 * Reload/change pin *
1048 * CLA: 80, INS: 5e *
1049 * Secret and protect mode: NO *
1050 * Suport: PBOC *
1051 *参数1:Reload/change(0/1);参数2:信息长度;参数3:PIN信息 *
1052 *****************************************/
1053 int ICC_reload_pin(char R_C,char len ,char *PIN_info)
1054 {
1055 1 command.CLA = 80;
1056 1 command.INS = 0x5e;
1057 1 command.P1 = 0;
1058 1 command.P2 = R_C;
1059 1 command.Lc = len;
1060 1 command.DAT =PIN_info;
1061 1 command.Le = 0;
1062 1
1063 1 if(!SamSendCommand(&command, &response))
1064 1 return -1;
1065 1 else
1066 1 {
1067 2 return response.ISW;
1068 2 }
1069 1 }
1070
1071 /*****************************************
1072 * Append record 增加记录 *
1073 * CLA: 00, INS: E2 *
1074 * Secret and protect mode: YES *
1075 * Suport: ISO ****
1076 * para2: 短文件标识或当前文件(b4~b8 || 00) *
1077 * len: 待写入的长度 *
1078 * buf: 待写入的数据 *
1079 ********************************************/
1080 int ICC_append_record(unsigned char para2, char *buf, unsigned char len)
1081 {
1082 1 command.CLA = 00;
1083 1 command.INS = 0xe2;
1084 1 command.P1 = 00;
1085 1 command.P2 = para2;
1086 1 command.Lc = len;
1087 1 command.DAT = buf;
1088 1 command.Le = 0;
1089 1
1090 1 if(!SamSendCommand(&command, &response))
1091 1 return -1;
1092 1 else
1093 1 {
1094 2 return response.ISW;
1095 2 }
1096 1 }
1097
1098 /*****************************************
1099 * DES *
1100 * use internal auth command *
1101 *****************************************/
1102 int ICC_DES(unsigned char *inblock, unsigned char *outblock, int wkeyid, int flag)
1103 {
1104 1 int iret;
1105 1
1106 1 if(flag > 1) return -1;
1107 1
1108 1 if(!flag)
C51 COMPILER V7.07 ICCAPP 12/06/2003 18:49:10 PAGE 19
1109 1 iret = ICC_internal_auth(inblock, 8, outblock, wkeyid, EN0);
1110 1 else
1111 1 iret = ICC_internal_auth(inblock, 8, outblock, wkeyid, DE1);
1112 1
1113 1 return iret;
1114 1 }
1115
1116 /*****************************************
1117 * DES *
1118 * use internal auth command *
1119 *****************************************/
1120 int ICC_MAC(unsigned char *inblock, int len, unsigned char *outblock, int keyid)
1121 {
1122 1 return ICC_internal_auth(inblock, len, outblock, keyid, DOMAC);
1123 1 }
1124
1125 /*****************************************
1126 * get command result when it has *
1127 * data in response apdu, return length *
1128 *****************************************/
1129 int ICC_get_cmd_data(unsigned char *buf)
1130 {
1131 1 memcpy(buf, response.DAT, response.len);
1132 1 return response.len;
1133 1 }
1134
1135
1136 #if 0 // the functions below are all be undefined.
/*****************************************
* update key or add key(write key) *
* CLA: 80, INS: D4 *
* Secret and protect mode: YES *
* Suport: TimeCOS only *
*****************************************/
int ICC_write_key(KEY *key, int flag)
{
command.CLA = 0x80;
command.INS = 0xd4;
if(flag == LOAD)
{
command.P1 = 0x01;
command.Lc = key->keylen + 5;
command.DAT = (char *)key;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -