📄 m500aucend.lst
字号:
1003 ///////////////////////////////////////////////////////////////////////
1004 char M500PiccAuthE2( unsigned char auth_mode,unsigned char *snr,
1005 unsigned char keynr,unsigned char block)
1006
1007 {
1008 char idata status = MI_OK;
1009 unsigned int e2addr = 0x80 + keynr * 0x18;
1010 //unsigned char *e2addrbuf = (unsigned char*)&e2addr;
1011 unsigned char *e2addrbuf;
1012
1013 e2addrbuf = (unsigned char *)&e2addr;
1014 if (auth_mode == PICC_AUTHENT1B)
1015 {
1016 e2addr += 12;
1017 }
1018 FlushFIFO();
1019 ResetInfo(MInfo);
1020
1021 memcpy(SerBuffer,e2addrbuf,2);
1022 SerBuffer[2] = SerBuffer[0];
1023 SerBuffer[0] = SerBuffer[1];
1024 SerBuffer[1] = SerBuffer[2];
1025 MInfo.nBytesToSend = 2;
1026 if ((status=M500PcdCmd(PCD_LOADKEYE2,SerBuffer,&MInfo)) == MI_OK)
1027 {
1028 status = M500PiccAuthState(auth_mode,snr,block); //11.9
1029 }
1030 return status;
1031 }
1032
1033 ///////////////////////////////////////////////////////////////////////
1034 // Authentication key coding
1035 ///////////////////////////////////////////////////////////////////////
1036 char M500HostCodeKey( unsigned char *uncoded, unsigned char *coded)
1037 {
1038 char idata status = MI_OK;
1039 unsigned char idata cnt = 0;
1040 unsigned char idata ln = 0;
1041 unsigned char idata hn = 0;
1042 for (cnt = 0; cnt < 6; cnt++)
1043 {
1044 ln = uncoded[cnt] & 0x0F;
1045 hn = uncoded[cnt] >> 4;
1046 coded[cnt * 2 + 1] = (~ln << 4) | ln;
1047 coded[cnt * 2 ] = (~hn << 4) | hn;
1048 }
1049 return MI_OK;
1050 }
1051
1052 ///////////////////////////////////////////////////////////////////
1053 // Authentication with direct key loading from the uC
1054 // 直接校验密码
1055 //////////////////////////////////////////////////////////////////
1056 char M500PiccAuthKey( unsigned char auth_mode,
1057 unsigned char *snr,
1058 unsigned char *keys,
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 20
1059 unsigned char block)
1060 {
1061 char idata status = MI_OK;
1062 //PcdSetTmo(2);
1063 FlushFIFO();
1064 ResetInfo(MInfo);
1065 memcpy(SerBuffer,keys,12);
1066 MInfo.nBytesToSend = 12;
1067 if ((status=M500PcdCmd(PCD_LOADKEY,SerBuffer,&MInfo)) == MI_OK)
1068 {
1069 status = M500PiccAuthState(auth_mode,snr,block);
1070 }
1071 return status;
1072 }
1073
1074 ///////////////////////////////////////////////////////////////////////
1075 ///////////////////////////////////////////////////////////////////////
1076 char M500PiccAuthState( unsigned char auth_mode,unsigned char *snr,unsigned char block)
1077 {
1078 char idata status = MI_OK;
1079 unsigned char idata i = 0;
1080
1081 status = ReadIO(RegErrorFlag);
1082 if (status != MI_OK)
1083 {
1084 if (status & 0x40)
1085 {
1086 status = MI_KEYERR;
1087 }
1088 else
1089 {
1090 status = MI_AUTHERR;
1091 }
1092 }
1093 else
1094 {
1095 SerBuffer[0] = auth_mode;
1096
1097 SerBuffer[1] = block;
1098 memcpy(SerBuffer + 2,snr,4);
1099 ResetInfo(MInfo);
1100 MInfo.nBytesToSend = 6;
1101 if ((status = M500PcdCmd(PCD_AUTHENT1,SerBuffer,&MInfo)) == MI_OK)
1102 {
1103 if (ReadIO(RegSecondaryStatus) & 0x07)
1104 {
1105 status = MI_BITCOUNTERR;
1106 }
1107 else
1108 {
1109 ResetInfo(MInfo);
1110 MInfo.nBytesToSend = 0;
1111 if ((status = M500PcdCmd(PCD_AUTHENT2,
1112 SerBuffer,
1113 &MInfo)) == MI_OK)
1114 {
1115 if ( ReadIO(RegControl) & 0x08 )
1116 {
1117 status = MI_OK;
1118 }
1119 else
1120 {
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 21
1121 status = MI_AUTHERR;
1122 }
1123 }
1124 }
1125 }
1126 }
1127 return status;
1128 }
1129
1130 ////////////////////////////////////////////////////////////////
1131 // Read the mifare card
1132 // 读卡
1133 ////////////////////////////////////////////////////////////////
1134 char M500PiccRead(unsigned char addr,unsigned char *_data)
1135 {
1136 char idata status = MI_OK;
1137 char idata tmp = 0;
1138
1139 FlushFIFO();
1140
1141 M500PcdSetTmo(3);
1142 WriteIO(RegChannelRedundancy,0x0F);
1143 ResetInfo(MInfo);
1144 SerBuffer[0] = PICC_READ;
1145 SerBuffer[1] = addr;
1146 MInfo.nBytesToSend = 2;
1147 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1148
1149 if (status != MI_OK)
1150 {
1151 if (status != MI_NOTAGERR )
1152 {
1153 if (MInfo.nBitsReceived == 4)
1154 {
1155 SerBuffer[0] &= 0x0f;
1156 if ((SerBuffer[0] & 0x0a) == 0)
1157 {
1158 status = MI_NOTAUTHERR;
1159 }
1160 else
1161 {
1162 status = MI_CODEERR;
1163 }
1164 }
1165 }
1166 memcpy(_data,"0000000000000000",16);
1167 }
1168 else // Response Processing
1169 {
1170 if (MInfo.nBytesReceived != 16)
1171 {
1172 status = MI_BYTECOUNTERR;
1173 memcpy(_data,"0000000000000000",16);
1174 }
1175 else
1176 {
1177 memcpy(_data,SerBuffer,16);
1178 }
1179 }
1180 M500PcdSetTmo(1);
1181 return status;
1182 }
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 22
1183
1184 ////////////////////////////////////////////////////////////////
1185 // Write the mifare card
1186 // 写卡 下载密码
1187 ////////////////////////////////////////////////////////////////
1188 char M500PiccWrite( unsigned char addr,unsigned char *_data)
1189 {
1190 char idata status = MI_OK;
1191
1192 ResetInfo(MInfo);
1193 SerBuffer[0] = PICC_WRITE;
1194 SerBuffer[1] = addr;
1195 MInfo.nBytesToSend = 2;
1196 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1197
1198 if (status != MI_NOTAGERR)
1199 {
1200 if (MInfo.nBitsReceived != 4)
1201 {
1202 status = MI_BITCOUNTERR;
1203 }
1204 else
1205 {
1206 SerBuffer[0] &= 0x0f;
1207 if ((SerBuffer[0] & 0x0a) == 0)
1208 {
1209 status = MI_NOTAUTHERR;
1210 }
1211 else
1212 {
1213 if (SerBuffer[0] == 0x0a)
1214 {
1215 status = MI_OK;
1216 }
1217 else
1218 {
1219 status = MI_CODEERR;
1220 }
1221 }
1222 }
1223 }
1224
1225 if ( status == MI_OK)
1226 {
1227 M500PcdSetTmo(3);
1228
1229 ResetInfo(MInfo);
1230 memcpy(SerBuffer,_data,16);
1231 MInfo.nBytesToSend = 16;
1232 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1233
1234 if (status & 0x80)
1235 {
1236 status = MI_NOTAGERR;
1237 }
1238 else
1239 {
1240 if (MInfo.nBitsReceived != 4)
1241 {
1242 status = MI_BITCOUNTERR;
1243 }
1244 else
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 23
1245 {
1246 SerBuffer[0] &= 0x0f;
1247 if ((SerBuffer[0] & 0x0a) == 0)
1248 {
1249 status = MI_WRITEERR;
1250 }
1251 else
1252 {
1253 if (SerBuffer[0] == 0x0a)
1254 {
1255 status = MI_OK;
1256 }
1257 else
1258 {
1259 status = MI_CODEERR;
1260 }
1261 }
1262 }
1263 }
1264 M500PcdSetTmo(1);
1265 }
1266 return status;
1267 }
1268
1269 ///////////////////////////////////////////////////////////////////////
1270 // Reset Rf Card
1271 ///////////////////////////////////////////////////////////////////////
1272 char M500PcdRfReset(unsigned char ms)
1273 {
1274 char idata status = MI_OK;
1275
1276 if(ms)
1277 {
1278 ClearBitMask(RegTxControl,0x03);
1279 delay_1ms(2);
1280 SetBitMask(RegTxControl,0x03);
1281 }
1282 else
1283
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -