Handle more corner case during convertion from nfc_* types to available pn53x_* types

This commit is contained in:
Romuald Conty 2010-10-20 09:28:36 +00:00
parent 311471024a
commit 72d7b66d2b
2 changed files with 53 additions and 9 deletions

View file

@ -497,7 +497,11 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
size_t szTargetsData; size_t szTargetsData;
byte_t abtTargetsData[MAX_FRAME_LEN]; byte_t abtTargetsData[MAX_FRAME_LEN];
pn53x_modulation_t pm = pn53x_nm_to_pm(nm); const pn53x_modulation_t pm = pn53x_nm_to_pm(nm);
if (PM_UNDEFINED == pm) {
pnd->iLastError = DENOTSUP;
return false;
}
if (!pn53x_InListPassiveTarget (pnd, pm, 1, pbtInitData, szInitData, abtTargetsData, &szTargetsData)) if (!pn53x_InListPassiveTarget (pnd, pm, 1, pbtInitData, szInitData, abtTargetsData, &szTargetsData))
return false; return false;
@ -525,8 +529,13 @@ pn53x_initiator_poll_targets (nfc_device_t * pnd,
size_t szTargetTypes = 0; size_t szTargetTypes = 0;
pn53x_target_type_t apttTargetTypes[32]; pn53x_target_type_t apttTargetTypes[32];
for (size_t n=0; n<szModulations; n++) { for (size_t n=0; n<szModulations; n++) {
apttTargetTypes[szTargetTypes] = pn53x_nm_to_ptt(pnmModulations[n]); const pn53x_target_type_t ptt = pn53x_nm_to_ptt(pnmModulations[n]);
if ((pnd->bAutoIso14443_4) && (apttTargetTypes[szTargetTypes] == PTT_MIFARE)) { // Hack to have ATS if (PTT_UNDEFINED == ptt) {
pnd->iLastError = DENOTSUP;
return false;
}
apttTargetTypes[szTargetTypes] = ptt;
if ((pnd->bAutoIso14443_4) && (ptt == PTT_MIFARE)) { // Hack to have ATS
apttTargetTypes[szTargetTypes] = PTT_ISO14443_4A_106; apttTargetTypes[szTargetTypes] = PTT_ISO14443_4A_106;
szTargetTypes++; szTargetTypes++;
apttTargetTypes[szTargetTypes] = PTT_MIFARE; apttTargetTypes[szTargetTypes] = PTT_MIFARE;
@ -962,6 +971,12 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
case NBR_424: case NBR_424:
abtCmd[3] = 0x02; // baud rate is 424 kbps abtCmd[3] = 0x02; // baud rate is 424 kbps
break; break;
case NBR_847:
case NBR_UNDEFINED:
// XXX Maybe we should put a "syntax error" or sth like that
pnd->iLastError = DENOTSUP;
return false;
break;
} }
if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */ if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */
@ -977,6 +992,12 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5); memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5);
offset += 5; offset += 5;
break; break;
case NBR_847:
case NBR_UNDEFINED:
// XXX Maybe we should put a "syntax error" or sth like that
pnd->iLastError = DENOTSUP;
return false;
break;
} }
} }
@ -1156,7 +1177,7 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_t * pnt, byte_t * pbtRx, size_
case NMT_DEP: case NMT_DEP:
pn53x_set_parameter(pnd, PARAM_AUTO_ATR_RES, true); pn53x_set_parameter(pnd, PARAM_AUTO_ATR_RES, true);
ptm = PTM_DEP_ONLY; ptm = PTM_DEP_ONLY;
if (pnt->nti.ndi.ndm = NDM_PASSIVE) { if (pnt->nti.ndi.ndm == NDM_PASSIVE) {
ptm |= PTM_PASSIVE_ONLY; // We add passive mode restriction ptm |= PTM_PASSIVE_ONLY; // We add passive mode restriction
} }
break; break;
@ -1501,7 +1522,6 @@ pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t
return true; return true;
} }
// FIXME How to handle corner case ?
const pn53x_modulation_t const pn53x_modulation_t
pn53x_nm_to_pm(const nfc_modulation_t nm) pn53x_nm_to_pm(const nfc_modulation_t nm)
{ {
@ -1525,7 +1545,7 @@ pn53x_nm_to_pm(const nfc_modulation_t nm)
return PM_ISO14443B_847; return PM_ISO14443B_847;
break; break;
case NBR_UNDEFINED: case NBR_UNDEFINED:
// XXX What to do ? // Nothing to do...
break; break;
} }
break; break;
@ -1543,15 +1563,19 @@ pn53x_nm_to_pm(const nfc_modulation_t nm)
return PM_FELICA_424; return PM_FELICA_424;
break; break;
case NBR_106: case NBR_106:
case NBR_847:
case NBR_UNDEFINED: case NBR_UNDEFINED:
// XXX What to do ? // Nothing to do...
break; break;
} }
break; break;
case NMT_DEP:
// Nothing to do...
break;
} }
return PM_UNDEFINED;
} }
// FIXME How to handle corner case ?
const nfc_modulation_t const nfc_modulation_t
pn53x_ptt_to_nm( const pn53x_target_type_t ptt ) pn53x_ptt_to_nm( const pn53x_target_type_t ptt )
{ {
@ -1559,6 +1583,7 @@ pn53x_ptt_to_nm( const pn53x_target_type_t ptt )
case PTT_GENERIC_PASSIVE_106: case PTT_GENERIC_PASSIVE_106:
case PTT_GENERIC_PASSIVE_212: case PTT_GENERIC_PASSIVE_212:
case PTT_GENERIC_PASSIVE_424: case PTT_GENERIC_PASSIVE_424:
case PTT_UNDEFINED:
// XXX This should not happend, how handle it cleanly ? // XXX This should not happend, how handle it cleanly ?
break; break;
@ -1598,7 +1623,6 @@ pn53x_ptt_to_nm( const pn53x_target_type_t ptt )
} }
} }
// FIXME How to handle corner case ?
const pn53x_target_type_t const pn53x_target_type_t
pn53x_nm_to_ptt(const nfc_modulation_t nm) pn53x_nm_to_ptt(const nfc_modulation_t nm)
{ {
@ -1613,6 +1637,12 @@ pn53x_nm_to_ptt(const nfc_modulation_t nm)
case NBR_106: case NBR_106:
return PTT_ISO14443_4B_106; return PTT_ISO14443_4B_106;
break; break;
case NBR_UNDEFINED:
case NBR_212:
case NBR_424:
case NBR_847:
// Nothing to do...
break;
} }
break; break;
@ -1628,8 +1658,18 @@ pn53x_nm_to_ptt(const nfc_modulation_t nm)
case NBR_424: case NBR_424:
return PTT_FELICA_424; return PTT_FELICA_424;
break; break;
} case NBR_UNDEFINED:
case NBR_106:
case NBR_847:
// Nothing to do...
break; break;
} }
break;
case NMT_DEP:
// Nothing to do...
break;
}
return PTT_UNDEFINED;
} }

View file

@ -101,6 +101,8 @@
* @brief NFC modulation * @brief NFC modulation
*/ */
typedef enum { typedef enum {
/** Undefined modulation */
PM_UNDEFINED = -1,
/** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */ /** ISO14443-A (NXP MIFARE) http://en.wikipedia.org/wiki/MIFARE */
PM_ISO14443A_106 = 0x00, PM_ISO14443A_106 = 0x00,
/** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */
@ -124,6 +126,8 @@ typedef enum {
* @brief NFC target type enumeration * @brief NFC target type enumeration
*/ */
typedef enum { typedef enum {
/** Undefined target type */
PTT_UNDEFINED = -1,
/** Generic passive 106 kbps (ISO/IEC14443-4A, mifare, DEP) */ /** Generic passive 106 kbps (ISO/IEC14443-4A, mifare, DEP) */
PTT_GENERIC_PASSIVE_106 = 0x00, PTT_GENERIC_PASSIVE_106 = 0x00,
/** Generic passive 212 kbps (FeliCa, DEP) */ /** Generic passive 212 kbps (FeliCa, DEP) */