Mifare Ultralight: Block specific pages

I got a link to this link ( Mifare Ultralight C Lock ) to make all pages in Mifare Ultralight tags read-only.

I can write a message on the Mifare Ultralight shortcut on Android. Now I want to block pages 4 through 7 (or any specific page). The link above shows how to block all pages. How can I block certain pages?

This code blocks all pages:

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;
}
+5
source share
1 answer

MIFARE Ultralight . , 3 , .

  • 2 ( 2): 3-7 3-7. , 3 3, 4 4 .. . 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 ( UNLOCKED).

. , i LOCKED (, 3 <= <= 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)
});
+4

Source: https://habr.com/ru/post/1619341/


All Articles