Changeset 7743
- Timestamp:
- 10/17/12 07:14:45 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/ifd_sci.c
r7718 r7743 100 100 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); 101 101 int32_t TDi = buf[n]; 102 int32_t historicalbytes = TDi &0x0F; 103 rdr_debug_mask(reader, D_IFD, "ATR historicalbytes should be: %d", historicalbytes); 102 int32_t historicalbytes = TDi&0x0F; 103 rdr_debug_mask(reader, D_ATR, "ATR historicalbytes should be: %d", historicalbytes); 104 rdr_debug_mask(reader, D_ATR, "Fetching global interface characters for protocol T0"); // protocol T0 always aboard! 104 105 n++; 106 107 int32_t protocols = 1, tck = 0, protocol, protocolnumber; // protocols = total protocols on card, tck = checksum byte present, protocol = mandatory protocol 108 int32_t D = 0; // protocolnumber = TDi uses protocolnumber 109 105 110 while (n < SCI_MAX_ATR_SIZE){ 106 if ((TDi | 0xEF) == 0xFF){ //TA Present 111 if (TDi&0x10){ //TA Present: //The value of TA(i) is always interpreted as XI || UI if i > 2 and T = 15 ='F'in TD(i1) 112 if (IO_Serial_Read(reader, timeout, 1, buf+n)) break; //In this case, TA(i) contains the clock stop indicator XI, which indicates the logical 113 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); //state the clockline must assume when the clock is stopped, and the class indicator UI, 114 rdr_debug_mask(reader, D_ATR, "TA%d: %02X",protocols,buf[n]); //which specifies the supply voltage class. 115 if ((protocols >2) && ((TDi&0x0F)==0x0F)){ // Protocol T15 does not exists, it means mandatory on all ATRs 116 if((buf[n]&0xC0) == 0xC0) rdr_debug_mask(reader, D_ATR, "Clockline low or high on clockstop"); 117 if((buf[n]&0xC0) == 0x00) rdr_debug_mask(reader, D_ATR, "Clockline not supported on clockstop"); 118 if((buf[n]&0xC0) == 0x40) rdr_debug_mask(reader, D_ATR, "Clockline should be low on clockstop"); 119 if((buf[n]&0xC0) == 0x80) rdr_debug_mask(reader, D_ATR, "Clockline should be high on clockstop"); 120 if((buf[n]&0x3F) == 0x01) rdr_debug_mask(reader, D_ATR, "Voltage class A 4.5~5.5V"); 121 if((buf[n]&0x3F) == 0x02) rdr_debug_mask(reader, D_ATR, "Voltage class B 2.7~3.3V"); 122 if((buf[n]&0x3F) == 0x03) rdr_debug_mask(reader, D_ATR, "Voltage class A 4.5~5.5V and class B 2.7~3.3V"); 123 if((buf[n]&0x3F) == 0x04) rdr_debug_mask(reader, D_ATR, "Voltage RFU"); 124 } 125 if ((protocols >2) && ((TDi&0x0F)==0x01)){ // Protocol T1 specfic (There is always an obsolete T0 protocol!) 126 int32_t ifsc = buf[n]; 127 if (ifsc == 0x00) ifsc = 32; //default is 32 128 rdr_debug_mask(reader, D_ATR, "Maximum information field length this card can receive is %d bytes (IFSC)", ifsc); 129 } 130 else { 131 int32_t FI = (buf[n]>>4); // FI is high nibble ***** work ETU = (1/D)*(Frequencydivider/cardfrequency) (in seconds!) 132 int32_t F = atr_f_table[FI]; // lookup the frequency divider 133 float fmax = atr_fs_table[FI]; // lookup the max frequency ***** initial ETU = 372 / initial frequency during atr (in seconds!) 134 135 int32_t DI = (buf[n]&0x0F); // DI is low nibble 136 D = atr_d_table[DI]; // lookup the bitrate adjustment (yeah there are floats in it, but in iso only integers!?) 137 rdr_debug_mask(reader, D_ATR, "Advertised max cardfrequency is %.2f (Fmax), frequency divider is %d (F)", fmax/1000000L, F); // High nibble TA1 contains cardspeed 138 rdr_debug_mask(reader, D_ATR, "Bitrate adjustment is %d (D)", D); // Low nibble TA1 contains Bitrateadjustment 139 rdr_debug_mask(reader, D_ATR, "Work ETU = %d nanoseconds", (long int) ((1/D)*(F/fmax)*1000000L)); // And display it... 140 rdr_debug_mask(reader, D_ATR, "Initial ETU = %d nanoseconds", (long int) (372/fmax)*1000000L); // And display it... since D=1 and frequency during ATR fetch might be different! 141 } 142 if (protocols == 2){ 143 if((buf[n]&0x80)==0x80) rdr_debug_mask(reader, D_ATR, "Switching between negotiable mode and specific mode is not possible"); 144 else { 145 rdr_debug_mask(reader, D_ATR, "Switching between negotiable mode and specific mode is possible"); 146 int32_t PPS = 1; 147 } 148 if((buf[n]&0x01)==0x01) rdr_debug_mask(reader, D_ATR, "Transmission parameters implicitly defined in the interface characters."); 149 else rdr_debug_mask(reader, D_ATR, "Transmission parameters explicitly defined in the interface characters."); 150 151 protocol = buf[n]&0x0F; 152 if(protocol) rdr_debug_mask(reader, D_ATR, "Protocol T = %d is to be used!", protocol); 153 } 154 n++; // next interface character 155 } 156 if (TDi&0x20){ //TB Present 107 157 if (IO_Serial_Read(reader, timeout, 1, buf+n)) break; 108 158 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); 109 rdr_debug_mask(reader, D_IFD, "TA: %02X",buf[n]); 110 n++; 111 } 112 if ((TDi | 0xDF) == 0xFF){ //TB Present 159 rdr_debug_mask(reader, D_ATR, "TB%d: %02X",protocols,buf[n]); 160 if ((protocols >2) && ((TDi&0x0F)==0x01)){ // Protocol T1 specfic (There is always an obsolete T0 protocol!) 161 int32_t CWI = (buf[n]&0x0F); // low nibble contains CWI code for the character waiting time CWT 162 int32_t BWI = (buf[n]>>4); // high nibble contains BWI code for the block waiting time BWT 163 int32_t CWT = (1<<CWI) + 11; // in work etu *** 2^CWI + 11 work etu *** 164 rdr_debug_mask(reader, D_ATR, "Protocol T1: Character waiting time is %d work etu (CWT)", CWT); 165 int32_t BWT = (int) ((1<<BWI) * 960L * 372L); // divided by frequency and add with 11 work etu *** 2^BWI*960*372/f + 11 work etu *** 166 rdr_debug_mask(reader, D_ATR, "Protocol T1: Block waiting time is %d divided by actual cardfrequency + 11 work etu (BWI)", BWI); 167 } 168 169 n++; // next interface character 170 } 171 if (TDi&0x40){ //TC Present 113 172 if (IO_Serial_Read(reader, timeout, 1, buf+n)) break; 114 173 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); 115 rdr_debug_mask(reader, D_IFD, "TB: %02X",buf[n]); 116 n++; 117 } 118 if ((TDi | 0xBF) == 0xFF){ //TC Present 174 rdr_debug_mask(reader, D_ATR, "TC%d: %02X",protocols, buf[n]); 175 if ((protocols == 2) && ((TDi&0x0F)==0x00)){ 176 int32_t WI = buf[n]; 177 rdr_debug_mask(reader, D_ATR, "Protocol T0: work wait time is %d work etu (WWT)", (int) (960*D*WI)); 178 } 179 if ((protocols == 2) && ((TDi&0x0F)==0x01)){ 180 if(buf[n]&0x01) rdr_debug_mask(reader, D_ATR, "Protocol T1: CRC is used to compute the error detection code"); 181 else rdr_debug_mask(reader, D_ATR, "Protocol T1: LRC is used to compute the error detection code"); 182 } 183 if(buf[n]<0xFF) rdr_debug_mask(reader, D_ATR, "Extra guardtime of %d ETU (N)", (int) buf[n]); 184 if(buf[n]==0xFF) rdr_debug_mask(reader, D_ATR, "Protocol T1: Standard 2 ETU guardtime is lowered to 1 ETU"); 185 186 n++; // next interface character 187 } 188 if (TDi&0x80){ //TD Present? Get next TDi there will be a next protocol 119 189 if (IO_Serial_Read(reader, timeout, 1, buf+n)) break; 120 190 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); 121 rdr_debug_mask(reader, D_IFD, "TC: %02X",buf[n]); 122 n++; 123 } 124 if ((TDi | 0x7F) == 0xFF){ //TD Present, more than 1 protocol? 125 if (IO_Serial_Read(reader, timeout, 1, buf+n)) break; 126 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); 127 rdr_debug_mask(reader, D_IFD, "TDi %02X",buf[n]); 191 rdr_debug_mask(reader, D_ATR, "TD%d %02X",protocols,buf[n]); 128 192 TDi = buf[n]; 129 n++; 193 protocolnumber = TDi&0x0F; 194 if (protocolnumber != 0x01) tck = 1; 195 rdr_debug_mask(reader, D_ATR, "Fetching global interface characters for protocol T%d:", (TDi&0x0F)); // lower nibble contains protocol number 196 protocols++; // there is always 1 protocol T0 in every ATR as per iso defined, max is 16 (numbered 0..15) 197 198 n++; // next interface character 130 199 } 131 200 else break; … … 134 203 atrlength += n; 135 204 atrlength += historicalbytes; 136 rdr_debug_mask(reader, D_IFD, "Total ATR Length including %d historical bytes should be: %d",historicalbytes,atrlength); 137 138 while(n<atrlength){ 205 rdr_debug_mask(reader, D_ATR, "Total ATR Length including %d historical bytes should be %d",historicalbytes,atrlength); 206 rdr_debug_mask(reader, D_ATR, "Total protocols in this ATR is %d",protocols); 207 208 while(n < atrlength + tck){ // read all the rest and mandatory tck byte if other protocol than T0 is used. 139 209 if (IO_Serial_Read(reader, timeout, 1, buf+n)) break; 140 210 if (inverse) buf[n] = ~(INVERT_BYTE (buf[n])); … … 142 212 } 143 213 144 if (n!=atrlength ) cs_log("Warning reader %s: Total ATR characters received is: %d instead of expected %d", reader->label, n, atrlength);214 if (n!=atrlength+tck) cs_log("Warning reader %s: Total ATR characters received is: %d instead of expected %d", reader->label, n, atrlength+tck); 145 215 146 216 if ((buf[0] !=0x3B) && (buf[0] != 0x3F) && (n>9 && !memcmp(buf+4, "IRDETO", 6))) //irdeto S02 reports FD as first byte on dreambox SCI, not sure about SH4 or phoenix
Note:
See TracChangeset
for help on using the changeset viewer.