![](/img/trans.png)
[英]How do I permanently lock specific data pages in a MIFARE Ultralight C tag?
[英]Mifare Ultralight: lock specific pages
我從這個鏈接( Mifare Ultralight C Lock )中獲得了參考,使Mifare Ultralight標簽上的所有頁面都是只讀的。
我可以在Android上成功在Mifare Ultralight標簽上寫一條消息。 現在我要鎖定第4到7頁(或任何特定頁面)。 以上鏈接僅顯示如何鎖定所有頁面。 我如何鎖定特定頁面?
此代碼鎖定所有頁面:
mifare.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x02, /* PAGE = 2 */
(byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF /* DATA = lock pages 3..15*/
});
public static boolean writeOnMifareUltralight(Context _context, Tag tag,String pageData, int i) {
byte[]result;
MifareUltralight mifare = null;
try {
mifare = MifareUltralight.get(tag);
mifare.connect();
mifare.writePage(i, pageData.getBytes(Charset.forName("US-ASCII")));
mifare.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x02, /* PAGE = 2 */
(byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF/* DATA = lock pages 3..15*/
});
} catch (Exception ex) {
ex.printStackTrace();
Log.d("mtw", ex.getMessage());
// return false;
} finally {
try {
mifare.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return true;
}
MIFARE Ultralight的鎖定字節使用一位來鎖定一個塊。 此外,它們包含3個塊鎖定位,用於控制鎖定字節本身的鎖定狀態。
字節2(第2頁):第3-7位是第3-7頁的鎖定位。 因此,第3位鎖定第3頁,第4位鎖定第4頁,等等。低3位是塊鎖定位。 位0鎖定第3頁的鎖定位,第1位鎖定第4-9頁的鎖定位,第2位鎖定第10-15頁的鎖定位。
字節3(第2頁):第0-7位是第8-15頁的鎖定位。 因此,位0鎖定頁面8,位1鎖定頁面9等。
因此,例如,要鎖定4-7頁,您可以使用以下命令:
mifare.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x02, /* PAGE = 2 */
(byte)0x00, (byte)0x00, (byte)0xF0, (byte)0x00 /* DATA = lock pages 4..7*/
});
注意,代替mifare.transceive()
你也可以簡單地使用mifare.writePage()
mifare.writePage(2, new byte[] {
(byte)0x00, (byte)0x00, (byte)0xF0, (byte)0x00 /* DATA = lock pages 4..7*/
});
請記住,鎖定位是一次性可編程的。 因此,一旦鎖定位被設置為邏輯1(即LOCKED),它就不能被反轉為邏輯0(即,未鎖定)。
這也允許您一次設置一個鎖定位。 例如,要設置頁面i
LOCKED( 其中3 <= i <= 15 !!! ),這樣的東西應該工作:
mifare.transceive(new byte[] {
(byte)0xA2, /* CMD = WRITE */
(byte)0x02, /* PAGE = 2 */
(byte)0x00, (byte)0x00, (byte)((1<<i) & 0x0FF), (byte)(((1<<i)>>>8) & 0x0FF)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.