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

📄 ds8007.lst

📁 dallas公司的ds8007芯片源代码。绝对好用。可以兼容tda8007.
💻 LST
📖 第 1 页 / 共 5 页
字号:
 756   5                                              if ((curByte != 0x3f) && (curByte != 0x3b))
 757   5                                              {
 758   6                                                      dssc_powerdown();
 759   6                                                      return ERR_POWERUP_ATR_INVALID;
 760   6                                              }
 761   5                                              check = 0;
 762   5                                      }
 763   4                                      else
 764   4                                              check ^= curByte;
 765   4                                      if (index == 2)
 766   4                                      {
 767   5                                              historicalBytes = curByte & 0x0F;
 768   5                                              expectedCharacters = curByte & 0xF0;
 769   5                                              lastATR[currentSlot].T0 = curByte;
 770   5                                      }
 771   4                                      if (index > 2)
 772   4                                      {
 773   5                                              switch(expectedCharacters)
 774   5                                              {
 775   6                                              case 0x00:
 776   6                                                      // Historical characters
 777   6                                                      historicalBytes--;
 778   6                                                      lastATR[currentSlot].Historical[lastATR[currentSlot].HistoricalLength++] = curByte;
 779   6                                                      if (historicalBytes == 0)
 780   6                                      {
 781   7                                              if (T==0)
 782   7                                                              {
 783   8                                                                      done = 1;
 784   8                                              }
 785   7                                                              else
 786   7                                                                      expectedCharacters = 0x01;  // Go to checksum state
 787   7                                      }
 788   6                                                      break;
 789   6                                              case 0x01:
 790   6                                                      // TCK case
 791   6                                                      lastATR[currentSlot].TCK = curByte;
 792   6                                              done = 1;
 793   6                                                      break;
 794   6      
 795   6                                              case 0x10:
 796   6                                              case 0x30:
 797   6                                              case 0x50:
 798   6                                              case 0x70:
C51 COMPILER V8.08   DS8007                                                                10/26/2007 09:32:25 PAGE 14  

 799   6                                              case 0x90:
 800   6                                              case 0xB0:
 801   6                                              case 0xD0:
 802   6                                              case 0xF0:
 803   6                                                      // TA case
 804   6                                              expectedCharacters &= 0xE0;
 805   6                                                      lastATR[currentSlot].TA[interfaceIteration] = curByte;
 806   6                                                      break;
 807   6      
 808   6                                              case 0x20:
 809   6                                              case 0x60:
 810   6                                              case 0xA0:
 811   6                                              case 0xE0:
 812   6                                                      // TB case
 813   6                                                      expectedCharacters &= 0xD0;
 814   6      
 815   6                                                      lastATR[currentSlot].TB[interfaceIteration] = curByte;
 816   6                                                      break;
 817   6      
 818   6                                              case 0x40:
 819   6                                              case 0xC0:
 820   6                                                      // TC case
 821   6                                                      expectedCharacters &= 0xB0;
 822   6                                                      lastATR[currentSlot].TC[interfaceIteration] = curByte;
 823   6                                                      break;
 824   6      
 825   6                                              case 0x80:
 826   6                                                      // TD case
 827   6                                                      expectedCharacters=(curByte&0xF0);
 828   6                                                      // Handle zero historical characters
 829   6                                                      if ((expectedCharacters == 0x00) && (historicalBytes == 0))
 830   6                                                      {
 831   7                                                              if (T==0)
 832   7                                                              {
 833   8                                                                      done = 1;
 834   8                                                              }
 835   7                                                              else
 836   7                                                                      expectedCharacters = 0x01;
 837   7                                                      }
 838   6                                                      lastATR[currentSlot].TD[interfaceIteration] = curByte;
 839   6                                                      // If we get TD1, we have the first protocol selection
 840   6                                                      if ((interfaceIteration==1))
 841   6                                                      {
 842   7                                                              T=curByte & 0x0F;
 843   7                                                      }
 844   6                                                      else
 845   6                                                      {
 846   7                                                              // Changing protocols is only valid under ISO (not allowed in EMV)
 847   7                                                              if (mode == POWERUP_ISO)
 848   7                                                              {
 849   8                                                                      if ((curByte & 0x0F) != T)
 850   8                                                                      {
 851   9                                                                              T=curByte & 0x0F;
 852   9                                                      }
 853   8                                                              }
 854   7                                                              else
 855   7                                                                      return ERR_POWERUP_ATR_INVALID;  // You cannot change T protocol under EMV
 856   7                                                      }
 857   6                                                      interfaceIteration++;
 858   6                                                      break;
 859   6                                              default:
 860   6                                                      dssc_powerdown();
C51 COMPILER V8.08   DS8007                                                                10/26/2007 09:32:25 PAGE 15  

 861   6                                                      return ERR_POWERUP_ATR_INVALID;
 862   6                                      break;
 863   6                                              }
 864   5                                      }
 865   4      
 866   4                              if (mode == POWERUP_ISO)
 867   4                  {
 868   5                                      // Reset timer for 9600 etu between characters in ATR
 869   5                                      dssc_writeregister(TOC,0x00);
 870   5                                      dssc_writeregister(TOR3,0x25);
 871   5                              dssc_writeregister(TOR2,0x80);
 872   5                                      dssc_writeregister(TOR1,0x00);
 873   5                                      // Start timer
 874   5                                      dssc_writeregister(TOC,0x61);
 875   5                              }
 876   4                      else  // mode is EMV
 877   4                      {
 878   5                                      // Set up timer for 9600 etu between characters in ATR
 879   5                                      // Don't modify TOR1 as it is in auto-reload mode.
 880   5                                      dssc_writeregister(TOC,0x05);
 881   5                                      dssc_writeregister(TOR3,0x25);
 882   5                                      dssc_writeregister(TOR2,0x80);
 883   5      
 884   5                                      // Start timer
 885   5                                      dssc_writeregister(TOC,0x65);
 886   5                      }
 887   4              }
 888   3          }
 889   2      
 890   2              // Read Timer status
 891   2              if (USRval & USR_TOL3_MASK)
 892   2              {
 893   3                      dssc_powerdown();
 894   3                      return ERR_POWERUP_ATR_TIMEOUT;
 895   3              }
 896   2              if ((mode == POWERUP_EMV) && (USRval & USR_TOL1_MASK))
 897   2              {
 898   3                      // If 192 ETU rollover, increment total count
 899   3                      etucount++;
 900   3                      // If we exceed 192 * 100 or 19200 etu, we fail as the whole ATR has not come
 901   3                      if (etucount > 100)
 902   3                      {
 903   4                              dssc_powerdown();
 904   4                              return ERR_POWERUP_ATR_TIMEOUT;
 905   4                      }
 906   3              }
 907   2              }
 908   1      
 909   1              // If we are in T=1 protocol, we get a LRC (xor checksum) at the end
 910   1              if (T==1)
 911   1              {
 912   2                      if (check != 0)
 913   2                      {
 914   3                              dssc_powerdown();
 915   3                              return ERR_POWERUP_ATR_CRC_FAILURE;
 916   3                      }
 917   2              }
 918   1      
 919   1              // Set ATR length for the ATR received
 920   1              ATRLength[currentSlot] = index;
 921   1              // Set T protocol mode
 922   1              TMode[currentSlot] = T;
C51 COMPILER V8.08   DS8007                                                                10/26/2007 09:32:25 PAGE 16  

 923   1      
 924   1              // Set the DS8007 UCR1.PROT mode according to T value
 925   1              val = dssc_readregister(UCR1);
 926   1              if (T == 0)
 927   1                      dssc_writeregister(UCR1,val & ~UCR1_PROT_MASK);
 928   1              else
 929   1                      dssc_writeregister(UCR1,val | UCR1_PROT_MASK);
 930   1      
 931   1              // Set extra guard time if present in TC1, else use guard time of 0
 932   1              if (lastATR[currentSlot].TC[1] != -1)
 933   1              dssc_writeregister(GTR,lastATR[currentSlot].TC[1]);
 934   1              else
 935   1                      dssc_writeregister(GTR,0x00);
 936   1      
 937   1              // Set the EDC type (either LRC or CRC)
 938   1              EDCtype[currentSlot] = EDC_TYPE_LRC;  // Default to LRC if not told otherwise.
 939   1              for (i = 3;i < 8;i++)
 940   1              {
 941   2                      if (lastATR[currentSlot].TC[3] != -1)
 942   2                  { 
 943   3                              EDCtype[currentSlot] = (lastATR[currentSlot].TC[3] & 0x01)?EDC_TYPE_CRC:EDC_TYPE_LRC;
 944   3                      }
 945   2              }
 946   1      
 947   1              // Set IFSC (max segment size of card) if TA3 present (only used for T=1 protocol)
 948   1              if (lastATR[currentSlot].TA[3] != -1)
 949   1              {
 950   2                      val = lastATR[currentSlot].TA[3];
 951   2                      if ((val < 0x10) || (val == 0xFF))
 952   2                      {
 953   3                              dssc_powerdown();
 954   3                              return ERR_POWERUP_ATR_INVALID;
 955   3                      }
 956   2                      IFSC[currentSlot] = val;
 957   2              }
 958   1              else
 959   1                      IFSC[currentSlot] = 0x20;  // Default for IFSC is 0x20 according to EMV 4.1 8.3.3.9 and ISO7816 9.5.2.1
 960   1      
 961   1              // Set WWT if present in TC2 (only used for T=0), ISO7816 8.2
 962   1              if (lastATR[currentSlot].TC[2] != -1)
 963   1                      WWT[currentSlot] = lastATR[currentSlot].TC[2] * 960;
 964   1              else
 965   1                      WWT[currentSlot] = 960 * 10;
 966   1      
 967   1              if (mode == POWERUP_EMV)
 968   1              {
 969   2                      if (lastATR[currentSlot].TB[3] == -1)
 970   2                      {
 971   3                              dssc_powerdown();
 972   3                              return ERR_POWERUP_ATR_INVALID;
 973   3                      }
 974   2              else
 975   2                      {
 976   3                              val = lastATR[currentSlot].TB[i] & 0x0F;
 977   3                              // Fail if CWI is out of range
 978   3                              if (val > 5)
 979   3                              {
 980   4                                      dssc_powerdown();
 981   4                                      return ERR_POWERUP_ATR_INVALID;
 982   4                              }
 983   3                              val = (lastATR[currentSlot].TB[i] & 0x0F) >> 4;
 984   3                              // Fail if BWI is out of range
C51 COMPILER V8.08   DS8007                                                                10/26/2007 09:32:25 PAGE 17  

 985   3                              if (val > 4)
 986   3                              {
 987   4                              dssc_powerdown();
 988   4                              return ERR_POWERUP_ATR_INVALID;
 989   4                              }
 990   3                      }
 991   2              }
 992   1      
 993   1              // Set default values for CWT and BWT, ISO7816 9.5.3.1 and 9.5.3.2
 994   1              CWT[currentSlot] = 11 + (1 << 13);
 995   1              BWT[currentSlot] = 11 + (1 << 4) * 960;
 996   1              for (i = 3;i < 8;i++)
 997   1              {
 998   2                      // Set CWT and BWT if present in TBi
 999   2                  if (lastATR[currentSlot].TB[i] != -1)
1000   2                      {
1001   3                              val = lastATR[currentSlot].TB[i] & 0x0F;
1002   3                              CWT[currentSlot] = 11 + (1 << val);
1003   3                              val = (lastATR[currentSlot].TB[i] & 0x0F) >> 4;
1004   3                              if (val > 9)
1005   3                              {
1006   4                                      dssc_powerdown();
1007   4                                      return ERR_POWERUP_ATR_INVALID;
1008   4                              }
1009   3                              BWT[currentSlot] = 11 + (1 << val) * 960;
1010   3                              break;

⌨️ 快捷键说明

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