⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commtran.lst

📁 此程序为13.56MHz的RFID底层读写卡程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
1030   4      	                  key_index=0;
1031   4      	          }
1032   3      	         if(key_index==0)
1033   3      	         {
1034   4      	            SendResponse(COS_CLA_ERROR,1,buf);
1035   4      	         }
1036   3      	         if(ComBuffer[1]==9)       // ComBuffer[1]==6
1037   3      	         {
1038   4      	            len_index=1;
1039   4      	         }
1040   3      	         else len_index=0;
1041   3      
1042   3                       len_x=ComBuffer[8+2]+2;
1043   3                       len_y=ComBuffer[5+2];
1044   3                       i=0;
1045   3      
1046   3                      Status=cpucard_send(ComBuffer[4+2],(void*)(send_option[cardsequ]));
1047   3                      Status=cpucard_send(ComBuffer[5+2],(void*)(send_option[cardsequ]));
1048   3                      Status=cpucard_send(ComBuffer[6+2],(void*)(send_option[cardsequ]));
1049   3                      Status=cpucard_send(ComBuffer[7+2],(void*)(send_option[cardsequ]));
C51 COMPILER V4.01,  COMMTRAN                                                              19/08/04  14:33:24  PAGE 17  

1050   3                      Status=cpucard_send(ComBuffer[8+2],(void*)(send_option[cardsequ]));
1051   3      
1052   3                       if(len_index==1)
1053   3                       {
1054   4      	           Status=cpucard_rec(&sw1,(void*)(rec_option[cardsequ]));
1055   4                         if(sw1!=len_y)
1056   4                          {
1057   5                             Status=cpucard_rec(&sw2,(void*)(rec_option[cardsequ]));
1058   5                             buf[0]=sw1;
1059   5                             buf[1]=sw2;
1060   5                             SendResponse(0x01,3,buf);
1061   5                             return;
1062   5                          }
1063   4      
1064   4             		    while(i<len_x)
1065   4                          {
1066   5                             Status=cpucard_rec(CosBuffer+i,(void*)(rec_option[cardsequ]));
1067   5                             if(Status)  break;
1068   5                             i++;
1069   5                          }
1070   4                          memcpy(ComBuffer+9,CosBuffer,len_x);
1071   4                          SendResponse(0x01,i+1+17,buf);
1072   4                          return;
1073   4                       }
1074   3      
1075   3                       Status=cpucard_rec(&sw1,(void*)(rec_option[cardsequ]));
1076   3                       for(i=0;i<60;i++)
1077   3                       {
1078   4                         ;
1079   4                       }
1080   3      
1081   3                       for(i=9+2;i<(ComBuffer[1]+2);i++)     //i=8   test
1082   3                       {
1083   4                          Status=cpucard_send(ComBuffer[i],(void*)(send_option[cardsequ]));
1084   4                       }
1085   3      
1086   3                        Status=cpucard_rec(&sw1,(void*)(rec_option[cardsequ]));
1087   3                        Status=cpucard_rec(&sw2,(void*)(rec_option[cardsequ]));
1088   3                       if(sw1!=0x61)
1089   3                       {
1090   4                          buf[0]=sw1;
1091   4                          buf[1]=sw2;
1092   4                          SendResponse(0x01,3,buf);
1093   4                          return;
1094   4                       }
1095   3      
1096   3                       for(i=0;i<60;i++)
1097   3                       {
1098   4                         ;
1099   4                       }
1100   3      
1101   3                       len_y=sw2+2;
1102   3      	         i=0;
1103   3      
1104   3                         Status=cpucard_send(0x00, (void*)(send_option[cardsequ]));
1105   3                         Status=cpucard_send(0x0c0,(void*)(send_option[cardsequ]));
1106   3                         Status=cpucard_send(0x00, (void*)(send_option[cardsequ]));
1107   3                         Status=cpucard_send(0x00, (void*)(send_option[cardsequ]));
1108   3                         Status=cpucard_send(sw2,  (void*)(send_option[cardsequ]));
1109   3      
1110   3                       Status=cpucard_rec(&sw1,(void*)(rec_option[cardsequ]));
1111   3         	         while(i<len_y)
1112   3      	         {
1113   4                          Status=cpucard_rec(CosBuffer+i,(void*)(rec_option[cardsequ]));
1114   4                          if(Status)  break;
1115   4                          i++;
C51 COMPILER V4.01,  COMMTRAN                                                              19/08/04  14:33:24  PAGE 18  

1116   4          	         }
1117   3                       memcpy(ComBuffer+9,CosBuffer,len_y);
1118   3                       SendResponse(0x01,1+len_y+17,buf);
1119   3      
1120   3                   }
1121   2      
1122   2                    else if(ICProtol==0x01)
1123   2                     {
1124   3                       LEN1=ComBuffer[8] ;           //T=1 协议  2003.02.21
1125   3                       for(i=0;i<ComBuffer[8]+4;i++)
1126   3                       {
1127   4                        Status=cpucard_send(ComBuffer[i+6],(void*)(send_option[cardsequ]));
1128   4                       }
1129   3                       Status=cpucard_rec(ComBuffer+9,(void*)(rec_option[cardsequ]));//NAD
1130   3                       Status=cpucard_rec(ComBuffer+10,(void*)(rec_option[cardsequ]));//PCB
1131   3                       Status=cpucard_rec(ComBuffer+11,(void*)(rec_option[cardsequ]));//LEN
1132   3                       for(i=0;i<ComBuffer[11]+1;i++)
1133   3                       {
1134   4                        Status=cpucard_rec(ComBuffer+12+i,(void*)(rec_option[cardsequ]));
1135   4                       }
1136   3                       SendResponse(0x01,1+3+i+17,buf);
1137   3                     }
1138   2                    break;
1139   2       /******************************************************************************/
1140   2      	  case 0x71:                         //RESET ICSLOT OR OPEN ICSLOT/
1141   2                        W_DOG();
1142   2                        cardsequ=select_sen_refunc();
1143   2                        if(ComBuffer[3]==1)  slot1_baud=ComBuffer[4]-1;
1144   2      
1145   2                       Reset(ComBuffer[3]-1);
1146   2                       i=0;
1147   2                	 while(1)
1148   2      		 {
1149   3                         Status=cpucard_rec(ComBuffer+9+i,(void*)(rec_option[cardsequ]));
1150   3                         if(Status)  break;
1151   3                         i++;
1152   3      		 }
1153   2      
1154   2                      if(i<3)                  //look as error
1155   2                       {
1156   3                        SendResponse(0x80,1+i+17,buf);
1157   3                        return;
1158   3                       }
1159   2                       SendResponse(0x01,1+i+17,buf);
1160   2                       break;
1161   2      /*********************************************************************************/
1162   2      
1163   2                case 0x51:     //DecrementPurse
1164   2                case 0x52:     //DecrementPurseFile
1165   2                       block_n=(sector_n<<2)+1;
1166   2                       *(uchar *)&money1=ComBuffer[6];
1167   2                       *((uchar *)&money1+1)=ComBuffer[7];
1168   2                       *((uchar *)&money1+2)=ComBuffer[8];
1169   2                       *((uchar *)&money1+3)=ComBuffer[9];
1170   2                       Status=MF1_read(keytest,block_n,buf);//
1171   2                       if(Status==MI_OK)
1172   2                       {
1173   3                            *(uchar *)&money2=buf[3];
1174   3                            *((uchar *)&money2+1)=buf[2];
1175   3                            *((uchar *)&money2+2)=buf[1];
1176   3                            *((uchar *)&money2+3)=buf[0];
1177   3                            if(money1>money2)
1178   3                            {
1179   4                                SendResponse(0xA0,1,buf); //not enough money
1180   4                                return;
1181   4                            }
C51 COMPILER V4.01,  COMMTRAN                                                              19/08/04  14:33:24  PAGE 19  

1182   3                            money2=money2-money1;
1183   3                            temp[3]=*((uchar *)&money2);
1184   3                            temp[2]=*((uchar *)&money2+1);
1185   3                            temp[1]=*((uchar *)&money2+2);
1186   3                            temp[0]=*((uchar *)&money2+3);
1187   3      
1188   3                            *(uchar *)&money2=*((uchar *)&money1+3);
1189   3                            *((uchar *)&money2+1)=*((uchar *)&money1+2);
1190   3                            *((uchar *)&money2+2)=*((uchar *)&money1+1);
1191   3                            *((uchar *)&money2+3)=*((uchar *)&money1);
1192   3      
1193   3                            Status=Mf500PiccValue(PICC_DECREMENT,block_n,(uchar *)&money2,block_n); //PI
1194   3      
1195   3                                if(Status==MI_OK)
1196   3                                {
1197   4                                     Status=MF1_read(keytest,block_n,buf);
1198   4                                     if(Status==MI_OK)
1199   4                                     {
1200   5                                        if(memcmp(temp,buf,4)==0)
1201   5                                        {
1202   6                                           SendResponse(0x01,5,buf);
1203   6                                           return;
1204   6                                        }
1205   5                                     }
1206   4                                }
1207   3      
1208   3                       }
1209   2                       SendResponse(0xA1,1,buf);
1210   2                       break;
1211   2      
1212   2                 /***********************************************************/
1213   2             case 0x59:     //IncrementPurse              2002.7.17
1214   2             case 0x60:     //IncrementPurseFile
1215   2                       block_n=(sector_n<<2)+1;
1216   2                       *(uchar *)&money1=ComBuffer[6];
1217   2                       *((uchar *)&money1+1)=ComBuffer[7];
1218   2                       *((uchar *)&money1+2)=ComBuffer[8];
1219   2                       *((uchar *)&money1+3)=ComBuffer[9];
1220   2                       Status=MF1_read(keytest,block_n,buf);
1221   2                       if(Status==MI_OK)
1222   2                       {
1223   3                            *(uchar *)&money2=buf[3];
1224   3                            *((uchar *)&money2+1)=buf[2];
1225   3                            *((uchar *)&money2+2)=buf[1];
1226   3                            *((uchar *)&money2+3)=buf[0];
1227   3      
1228   3                            money2=money2+money1;
1229   3                            temp[3]=*((uchar *)&money2);
1230   3                            temp[2]=*((uchar *)&money2+1);
1231   3                            temp[1]=*((uchar *)&money2+2);
1232   3                            temp[0]=*((uchar *)&money2+3);
1233   3                     /****************************************************************/
1234   3                            *(uchar *)&money2=*((uchar *)&money1+3);
1235   3                            *((uchar *)&money2+1)=*((uchar *)&money1+2);
1236   3                            *((uchar *)&money2+2)=*((uchar *)&money1+1);
1237   3                            *((uchar *)&money2+3)=*((uchar *)&money1);
1238   3      
1239   3      
1240   3                            Status=Mf500PiccValue(PICC_INCREMENT,block_n,(uchar *)&money2,block_n);
1241   3      
1242   3                                if(Status==MI_OK)
1243   3                                {
1244   4                                     Status=MF1_read(keytest,block_n,buf);
1245   4                                     if(Status==MI_OK)
1246   4                                     {
1247   5                                        if(memcmp(temp,buf,4)==0)
C51 COMPILER V4.01,  COMMTRAN                                                              19/08/04  14:33:24  PAGE 20  

1248   5                                        {
1249   6                                           SendResponse(0x01,5,buf);
1250   6                                           return;
1251   6                                        }
1252   5                                     }
1253   4                                }
1254   3      
1255   3                       }
1256   2                       SendResponse(0xA1,1,buf);
1257   2                       break;
1258   2           /************************************************************************/
1259   2               case 0x53:     //CheckPurseFormat
1260   2               case 0x54:     //CheckPurseFileFormat
1261   2                              //"ComBuffer[6]为钱包类型 主钱包0x00备份钱包0x01
1262   2                       block_n=(sector_n<<2)+1+ComBuffer[6];
1263   2                       Status=MF1_read(keytest,block_n,buf);
1264   2                       if(Status!=MI_OK)
1265   2                       {
1266   3                          SendResponse(0x80,1,buf);
1267   3                          return;
1268   3                       }
1269   2                       if((buf[0]==~buf[4])&&(buf[1]==~buf[5])&&(buf[2]==~buf[6])&&(buf[3]==~buf[7]))
1270   2                       {
1271   3                            SendResponse(0x01,5,buf);
1272   3                       }
1273   2                       else
1274   2                       {
1275   3                            SendResponse(0xA2,1,buf); //PurseFormatError
1276   3                       }
1277   2                       break;
1278   2               /*****************************************************************************/
1279   2               case 0x55:     //RestorePurse
1280   2               case 0x56:     //RestorePurseFile
1281   2                              //"ComBuffer[6]为钱包类型 主钱包0x00,备份钱包0x01
1282   2                       if(ComBuffer[6]==0x01)
1283   2                       {
1284

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -