summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2005-10-22 18:12:48 +0000
committerlaforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede>2005-10-22 18:12:48 +0000
commit852829c4ab597ce137bac4bb9b612fd57b1dd282 (patch)
treef8f440953bfb901ada92241e75b8caf35572b8f3
parent09a3dd030ddac3875b865be72e91d8326367dd4c (diff)
add convenience functions to set lock bits
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1553 e0336214-984f-0b4b-a45f-81c69e1f0ede
-rw-r--r--include/rfid/rfid_protocol_mifare_ul.h6
-rw-r--r--openct-escape.c29
-rw-r--r--rfid_proto_mifare_ul.c28
3 files changed, 61 insertions, 2 deletions
diff --git a/include/rfid/rfid_protocol_mifare_ul.h b/include/rfid/rfid_protocol_mifare_ul.h
index 6cdec22..74972ee 100644
--- a/include/rfid/rfid_protocol_mifare_ul.h
+++ b/include/rfid/rfid_protocol_mifare_ul.h
@@ -9,7 +9,13 @@
#define MIFARE_UL_RESP_NAK 0x00
#define MIFARE_UL_PAGE_MAX 15
+#define MIFARE_UL_PAGE_LOCK 2
+#define MIFARE_UL_PAGE_OTP 3
struct rfid_protocol rfid_protocol_mful;
+
+extern int rfid_mful_lock_page(struct rfid_protocol_handle *ph, unsigned int page);
+extern int rfid_mful_lock_otp(struct rfid_protocol_handle *ph);
+
#endif
diff --git a/openct-escape.c b/openct-escape.c
index ecdb2d9..7085fc7 100644
--- a/openct-escape.c
+++ b/openct-escape.c
@@ -237,6 +237,28 @@ iso7816_read_ef(u_int16_t fid, unsigned char *buf, unsigned int *len)
}
int
+mifare_ulight_write(struct rfid_protocol_handle *ph)
+{
+ unsigned char buf[4] = { 0xa1, 0xa2, 0xa3, 0xa4 };
+
+ return rfid_protocol_write(ph, 20, buf, 4);
+}
+
+int
+mifare_ulight_blank(struct rfid_protocol_handle *ph)
+{
+ unsigned char buf[4] = { 0x00, 0x00, 0x00, 0x00 };
+ int i, ret;
+
+ for (i = 4; i <= MIFARE_UL_PAGE_MAX; i++) {
+ ret = rfid_protocol_write(ph, i, buf, 4);
+ if (ret < 0)
+ return ret;
+ }
+ return 0;
+}
+
+int
mifare_ulight_read(struct rfid_protocol_handle *ph)
{
unsigned char buf[20];
@@ -244,7 +266,7 @@ mifare_ulight_read(struct rfid_protocol_handle *ph)
int ret;
int i;
- for (i = 0; i < 7; i++) {
+ for (i = 0; i <= MIFARE_UL_PAGE_MAX; i++) {
ret = rfid_protocol_read(ph, i, buf, &len);
if (ret < 0)
return ret;
@@ -264,7 +286,7 @@ int main(int argc, char **argv)
exit(1);
protocol = RFID_PROTOCOL_MIFARE_UL;
- protocol = RFID_PROTOCOL_TCL;
+// protocol = RFID_PROTOCOL_TCL;
if (l3(protocol) < 0)
exit(1);
@@ -287,6 +309,9 @@ int main(int argc, char **argv)
break;
case RFID_PROTOCOL_MIFARE_UL:
mifare_ulight_read(ph);
+ //mifare_ulight_blank(ph);
+ mifare_ulight_write(ph);
+ mifare_ulight_read(ph);
break;
}
diff --git a/rfid_proto_mifare_ul.c b/rfid_proto_mifare_ul.c
index 1d80702..e420fcf 100644
--- a/rfid_proto_mifare_ul.c
+++ b/rfid_proto_mifare_ul.c
@@ -136,3 +136,31 @@ struct rfid_protocol rfid_protocol_mful = {
.fini = &mful_fini,
},
};
+
+/* Functions below are not (yet? covered in the generic librfid api */
+
+
+/* lock a certain page */
+int rfid_mful_lock_page(struct rfid_protocol_handle *ph, unsigned int page)
+{
+ unsigned char buf[4] = { 0x00, 0x00, 0x00, 0x00 };
+
+ if (ph->proto != &rfid_protocol_mful)
+ return -EINVAL;
+
+ if (page < 3 || page > 15)
+ return -EINVAL;
+
+ if (page > 8)
+ buf[2] = (1 << page);
+ else
+ buf[3] = (1 << (page - 8));
+
+ return mful_write(ph, MIFARE_UL_PAGE_LOCK, buf, sizeof(buf));
+}
+
+/* convenience wrapper to lock the otp page */
+int rfid_mful_lock_otp(struct rfid_protocol_handle *ph)
+{
+ return rfid_mful_lock_page(ph, MIFARE_UL_PAGE_OTP);
+}
personal git repositories of Harald Welte. Your mileage may vary