@@ -580,8 +580,8 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type
580580
581581 case NMT_ISO14443BICLASS :
582582 // Store the UID
583- for (uint8_t i = 0 ; i < 8 ; ++ i )
584- pnti -> nhi .abtUID [7 - i ]= pbtRawData [i ];
583+ for (uint8_t i = 0 ; i < 8 ; ++ i )
584+ pnti -> nhi .abtUID [7 - i ] = pbtRawData [i ];
585585 break ;
586586
587587 case NMT_ISO14443B2CT :
@@ -1060,51 +1060,51 @@ pn53x_initiator_init(struct nfc_device *pnd)
10601060// iclass requires special modulation settings
10611061void pn53x_initiator_init_iclass_modulation (struct nfc_device * pnd )
10621062{
1063- // send a bunch of low level commands reverse engineered from a working iClass reader
1064- // original device was using a PN512
1065- //
1066- // // TxModeReg - Defines the data rate and framing during transmission.
1067- //// set bit 4 for target mode? - RxWaitRF Set to logic 1, the counter for RxWait starts only if an external RF field is detected in Target mode for NFCIP-1 or in Card Communication mode
1068- //pn512_write_register(0x12, "\x03", 1, false);
1069- pn53x_WriteRegister (pnd , PN53X_REG_CIU_TxMode , 0x03 );
1070- //
1071- // // RxModeReg - Defines the data rate and framing during reception.
1072- //pn512_write_register(0x13, "\x03", 1, false);
1073- // addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
1074- //pn512_write_register(0x13, "\x0B", 1, false);
1075- pn53x_WriteRegister (pnd , PN53X_REG_CIU_RxMode , 0x0B );
1076-
1077- // ManualRCVReg - Allows manual fine tuning of the internal receiver.
1078- //pn512_write_register(0x1d, "\x10", 1, false);
1079- pn53x_WriteRegister (pnd , PN53X_REG_CIU_ManualRCV , 0x10 );
1080-
1081- // RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
1082- //pn512_write_register(0x26, "\x70", 1, false);
1083- pn53x_WriteRegister (pnd , PN53X_REG_CIU_RFCfg , 0x70 );
1084-
1085- // GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
1086- //pn512_write_register(0x23, "\x88", 1, false);
1087- pn53x_WriteRegister (pnd , PN53X_REG_CIU_GsNOFF , 0x88 );
1088-
1089- // GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
1090- //pn512_write_register(0x27, "\xf8", 1, false);
1091- pn53x_WriteRegister (pnd , PN53X_REG_CIU_GsNOn , 0xf8 );
1092-
1093- // CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
1094- //pn512_write_register(0x28, "\x3f", 1, false);
1095- pn53x_WriteRegister (pnd , PN53X_REG_CIU_CWGsP , 0x3f );
1096-
1097- // ModGsPReg - Defines the driver P-output conductance during modulation.
1098- //pn512_write_register(0x29, "\x10", 1, false);
1099- pn53x_WriteRegister (pnd , PN53X_REG_CIU_ModGsP , 0x10 );
1100-
1101- // TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
1102- //pn512_write_register(0x2c, "\x69", 1, false);
1103- pn53x_WriteRegister (pnd , PN53X_REG_CIU_TReloadVal_hi , 0x69 );
1104-
1105- // TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
1106- //pn512_write_register(0x2d, "\xf0", 1, false);
1107- pn53x_WriteRegister (pnd , PN53X_REG_CIU_TReloadVal_lo , 0xf0 );
1063+ // send a bunch of low level commands reverse engineered from a working iClass reader
1064+ // original device was using a PN512
1065+ //
1066+ // // TxModeReg - Defines the data rate and framing during transmission.
1067+ //// set bit 4 for target mode? - RxWaitRF Set to logic 1, the counter for RxWait starts only if an external RF field is detected in Target mode for NFCIP-1 or in Card Communication mode
1068+ //pn512_write_register(0x12, "\x03", 1, false);
1069+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_TxMode , 0x03 );
1070+ //
1071+ // // RxModeReg - Defines the data rate and framing during reception.
1072+ //pn512_write_register(0x13, "\x03", 1, false);
1073+ // addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
1074+ //pn512_write_register(0x13, "\x0B", 1, false);
1075+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_RxMode , 0x0B );
1076+
1077+ // ManualRCVReg - Allows manual fine tuning of the internal receiver.
1078+ //pn512_write_register(0x1d, "\x10", 1, false);
1079+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_ManualRCV , 0x10 );
1080+
1081+ // RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
1082+ //pn512_write_register(0x26, "\x70", 1, false);
1083+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_RFCfg , 0x70 );
1084+
1085+ // GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
1086+ //pn512_write_register(0x23, "\x88", 1, false);
1087+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_GsNOFF , 0x88 );
1088+
1089+ // GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
1090+ //pn512_write_register(0x27, "\xf8", 1, false);
1091+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_GsNOn , 0xf8 );
1092+
1093+ // CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
1094+ //pn512_write_register(0x28, "\x3f", 1, false);
1095+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_CWGsP , 0x3f );
1096+
1097+ // ModGsPReg - Defines the driver P-output conductance during modulation.
1098+ //pn512_write_register(0x29, "\x10", 1, false);
1099+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_ModGsP , 0x10 );
1100+
1101+ // TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
1102+ //pn512_write_register(0x2c, "\x69", 1, false);
1103+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_TReloadVal_hi , 0x69 );
1104+
1105+ // TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
1106+ //pn512_write_register(0x2d, "\xf0", 1, false);
1107+ pn53x_WriteRegister (pnd , PN53X_REG_CIU_TReloadVal_lo , 0xf0 );
11081108}
11091109
11101110int
@@ -1202,10 +1202,10 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
12021202 }
12031203 szTargetsData = 6 ; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
12041204 } else if (nm .nmt == NMT_ISO14443BICLASS ) {
1205- pn53x_initiator_init_iclass_modulation (pnd );
1206- //
1205+ pn53x_initiator_init_iclass_modulation (pnd );
1206+ //
12071207 // Some work to do before getting the UID...
1208- // send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
1208+ // send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
12091209 uint8_t abtReqt [] = { 0x0a }; // iClass ACTIVATE_ALL
12101210 uint8_t abtAnticol [11 ];
12111211 if ((res = pn53x_initiator_transceive_bytes (pnd , abtReqt , sizeof (abtReqt ), NULL , 0 , timeout )) < 0 ) {
@@ -1214,35 +1214,35 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
12141214 // continue;
12151215 //} else
12161216 // return res;
1217- }
1218- // do select - returned anticol contains 'handle' for tag if present
1219- abtReqt [0 ]= 0x0c ; // iClass SELECT
1220- abtAnticol [0 ]= 0x81 ; // iClass ANTICOL
1217+ }
1218+ // do select - returned anticol contains 'handle' for tag if present
1219+ abtReqt [0 ] = 0x0c ; // iClass SELECT
1220+ abtAnticol [0 ] = 0x81 ; // iClass ANTICOL
12211221 if ((res = pn53x_initiator_transceive_bytes (pnd , abtReqt , sizeof (abtReqt ), & abtAnticol [1 ], sizeof (abtAnticol ) - 1 , timeout )) < 0 ) {
12221222 log_put (LOG_GROUP , LOG_CATEGORY , NFC_LOG_PRIORITY_DEBUG , "timeout on iClass anticol" );
12231223 return res ;
1224- }
1225- // write back anticol handle to get UID
1224+ }
1225+ // write back anticol handle to get UID
12261226 if ((res = pn53x_initiator_transceive_bytes (pnd , abtAnticol , 9 , abtTargetsData , 10 , timeout )) < 0 ) {
12271227 log_put (LOG_GROUP , LOG_CATEGORY , NFC_LOG_PRIORITY_DEBUG , "timeout on iClass get UID" );
12281228 return res ;
1229- }
1229+ }
12301230 log_put (LOG_GROUP , LOG_CATEGORY , NFC_LOG_PRIORITY_DEBUG , "iClass raw UID: %02x %02x %02x %02x %02x %02x %02x %02x" , abtTargetsData [0 ], abtTargetsData [1 ], abtTargetsData [2 ], abtTargetsData [3 ], abtTargetsData [4 ], abtTargetsData [5 ], abtTargetsData [6 ], abtTargetsData [7 ]);
1231- szTargetsData = 8 ;
1232- nttmp .nm = nm ;
1233- if ((res = pn53x_decode_target_data (abtTargetsData , szTargetsData , CHIP_DATA (pnd )-> type , nm .nmt , & (nttmp .nti ))) < 0 ) {
1234- return res ;
1235- }
1236- } else {
1237-
1238- if ((res = pn53x_initiator_transceive_bytes (pnd , pbtInitData , szInitData , abtTargetsData , sizeof (abtTargetsData ), timeout )) < 0 ) {
1239- if ((res == NFC_ERFTRANS ) && (CHIP_DATA (pnd )-> last_status_byte == 0x01 )) { // Chip timeout
1240- continue ;
1241- } else
1231+ szTargetsData = 8 ;
1232+ nttmp .nm = nm ;
1233+ if ((res = pn53x_decode_target_data (abtTargetsData , szTargetsData , CHIP_DATA (pnd )-> type , nm .nmt , & (nttmp .nti ))) < 0 ) {
12421234 return res ;
1235+ }
1236+ } else {
1237+
1238+ if ((res = pn53x_initiator_transceive_bytes (pnd , pbtInitData , szInitData , abtTargetsData , sizeof (abtTargetsData ), timeout )) < 0 ) {
1239+ if ((res == NFC_ERFTRANS ) && (CHIP_DATA (pnd )-> last_status_byte == 0x01 )) { // Chip timeout
1240+ continue ;
1241+ } else
1242+ return res ;
1243+ }
1244+ szTargetsData = (size_t )res ;
12431245 }
1244- szTargetsData = (size_t )res ;
1245- }
12461246
12471247 nttmp .nm = nm ;
12481248 if ((res = pn53x_decode_target_data (abtTargetsData , szTargetsData , CHIP_DATA (pnd )-> type , nm .nmt , & (nttmp .nti ))) < 0 ) {
@@ -2249,7 +2249,7 @@ static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd)
22492249
22502250static int pn53x_ISO14443B_ICLASS_is_present (struct nfc_device * pnd )
22512251{
2252- int timeout = 300 ;
2252+ int timeout = 300 ;
22532253 log_put (LOG_GROUP , LOG_CATEGORY , NFC_LOG_PRIORITY_DEBUG , "%s" , "target_is_present(): Ping B iClass" );
22542254 pn53x_initiator_init_iclass_modulation (pnd );
22552255 //
@@ -2261,8 +2261,8 @@ static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
22612261 log_put (LOG_GROUP , LOG_CATEGORY , NFC_LOG_PRIORITY_DEBUG , "got expected timeout on iClass activate all" );
22622262 }
22632263 // do select - returned anticol contains 'handle' for tag if present
2264- abtReqt [0 ]= 0x0c ; // iClass SELECT
2265- abtAnticol [0 ]= 0x81 ; // iClass ANTICOL
2264+ abtReqt [0 ] = 0x0c ; // iClass SELECT
2265+ abtAnticol [0 ] = 0x81 ; // iClass ANTICOL
22662266 if (pn53x_initiator_transceive_bytes (pnd , abtReqt , sizeof (abtReqt ), & abtAnticol [1 ], sizeof (abtAnticol ) - 1 , timeout ) < 0 ) {
22672267 log_put (LOG_GROUP , LOG_CATEGORY , NFC_LOG_PRIORITY_DEBUG , "timeout on iClass anticol" );
22682268 return NFC_ETGRELEASED ;;
0 commit comments