![](/img/trans.png)
[英]Configure MIFARE DESFire EV1 as NFC Forum Type 4 Tag for NDEF
[英]How to set and unset password on a MIFARE Ultralight EV1 tag?
我希望能夠使用NfcA?
在MIFARE Ultralight EV1(MFOUL21)標簽上設置和取消密碼保護NfcA?
Android上的標記技術。
我知道我會使用nfcA.transceive()
方法,但我不確定該方法的參數是什么,所以任何人都可以提供代碼片段來設置和取消設置密碼嗎?
更新:
關於TapLinx庫,我基本上喜歡nfcA.transceive(...)
代碼片段等價於:
ultralightEV1.programPwd(passwordBytes);
ultralightEV1.programPack(packBytes);
ultralightEV1.enablePasswordProtection(enabled, fromPageNum);
ultralightEV1.authenticatePwd(passwordBytes);
ultralightEV1.authenticatePwd(passwordBytes);
要使用MIFARE Ultralight EV1標簽(或NTAG21x)的密碼進行身份驗證,您需要發送PWD_AUTH(0x1B)命令(並可能驗證PACK響應是否符合您的預期):
byte[] pass = { (byte)0x12, (byte)0x34, (byte)0x56, (byte)0x78 };
byte[] pack = { (byte)0x9A, (byte)0xBC };
byte[] response = nfc.transceive(new byte[] {
(byte) 0x1B, // PWD_AUTH
pass[0], pass[1], pass[2], pass[3]
});
if ((response != null) && (response.length >= 2)) {
// success
byte[] packReceived = Arrays.copyOf(response, 2);
if (Arrays.equal(packReceived, pack)) {
// PACK verified, so tag is authentic (not really, but that whole
// PWD_AUTH/PACK authentication mechanism was not really meant to
// bring much security, I hope; same with the NTAG signature btw.)
}
}
ultralightEV1.programPwd(passwordBytes); ultralightEV1.programPack(packBytes);
對於MF0UL11,密碼位於第0x12頁,密碼確認(PACK)位於第0x13頁(配置頁面從0x10開始)。 對於MF0UL21,密碼位於第0x27頁,密碼確認(PACK)位於第0x28頁(配置頁面從0x25開始)。
為了動態地找出您的標簽是MF0UL11還是MF0UL21,您可以發送GET_VERSION(0x60)命令:
int cfgOffset = -1;
byte[] response = nfc.transceive(new byte[] {
(byte) 0x60 // GET_VERSION
});
if ((response != null) && (response.length >= 8)) {
// success
if ((response[0] == (byte)0x00) && (response[1] == (byte)0x04)) {
// tag is from NXP
if (response[2] == (byte)0x03) {
// MIFARE Ultralight
if ((response[4] == (byte)0x01) && (response[5] == (byte)0x00) {
// MIFARE Ultralight EV1 (V0)
switch (response[6]) {
case (byte)0x0B:
// MF0UL11
cfgOffset = 0x010;
break;
case (byte)0x0E:
// MF0UL11
cfgOffset = 0x025;
break;
default:
// unknown
break;
}
}
}
}
}
找到配置頁面的開頭后,可以使用WRITE(0xA2)命令更新這些頁面的值(假設您使用當前密碼進行身份驗證otr,配置頁面不受保護):
byte[] response = nfc.transceive(new byte[] {
(byte) 0xA2, // WRITE
(byte)((cfgOffset + 2) & 0x0FF), // page address
pass[0], pass[1], pass[2], pass[3] // new page data
});
response = nfc.transceive(new byte[] {
(byte) 0xA2, // WRITE
(byte)((cfgOffset + 3) & 0x0FF), // page address
pack[0], pack[1], (byte)0x00, (byte)0x00 // new page data (always need to write full page)
});
ultralightEV1.enablePasswordProtection(啟用,fromPageNum);
為了啟用密碼保護,您需要配置需要密碼的第一頁(AUTH0,第1,010頁上的字節3(對於MF0UL11 /第0x25頁MF0UL21),您需要配置保護模式(PROT,字節0的第7位) MF0UL11 /頁0x26 MF0UL21)的第0x11頁。
您通常首先讀取(READ(0x30)命令)這些頁面的舊值,更新受影響的位和字節,並將新值寫入標記:
int fromPageNum = 4;
boolean enableProtection = true;
boolean enableReadProtection = true;
byte[] response = nfc.transceive(new byte[] {
(byte) 0x30, // READ
(byte)(cfgOffset & 0x0FF) // page address
});
if ((response != null) && (response.length >= 16)) {
// success
// NOTE that READ will return *4 pages* starting at page address
byte auth0 = (byte)0xFF;
if (enableProtection || enableReadProtection) {
auth0 = (byte)(fromPageNum & 0x0FF);
}
byte[] writeResponse = nfc.transceive(new byte[] {
(byte) 0xA2, // WRITE
(byte)((cfgOffset + 0) & 0x0FF), // page address
response[0], response[1], response[2], auth0 // new page data
});
byte access = (byte)(response[4] & 0x07F);
if (enableProtection && enableReadProtection) {
access |= (byte)0x80;
}
byte[] writeResponse = nfc.transceive(new byte[] {
(byte) 0xA2, // WRITE
(byte)((cfgOffset + 1) & 0x0FF), // page address
access, response[5], response[6], response[7], // new page data
});
}
您可以使用恩智浦的TapLinx庫(可從https://www.mifare.net/en/products/tools/taplinx/獲得 )以抽象的方式與MIFARE Ultralight EV1進行通信。
要使用“收發”,根據http://www.advanide.com/wp-content/uploads/products/rfid/UltraLight%20EV1_MF0ULX1.pdf上提供的數據表,需要使用WRITE命令(A2)和地址25-28h。
更新:要發送的命令應該是(對於MFOUL21):
ultralightEV1.programPwd(passwordBytes); A227AABBCCDD(密碼AABBCCDD)
ultralightEV1.programPack(packBytes); A228EEFF0000(適用於PACK 0000)
ultralightEV1.enablePasswordProtection(啟用,fromPageNum); A225xx0000yy(其中xx是調制模式; 00..strong mod。禁用; 01..strong mod啟用; yy =密碼保護開始的頁面)
ultralightEV1.authenticatePwd(passwordBytes); 1BAABBCCDD
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.