+static char *l2_names[] = {
+ [RFID_LAYER2_ISO14443A] = "iso14443a",
+ [RFID_LAYER2_ISO14443B] = "iso14443b",
+ [RFID_LAYER2_ISO15693] = "iso15693",
+ [RFID_LAYER2_ICODE1] = "icode1",
+};
+
+static int l2_by_name(const char *name)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(l2_names); i++) {
+ if (l2_names[i] == NULL)
+ continue;
+ if (!strcasecmp(name, l2_names[i]))
+ return i;
+ }
+ return -1;
+}
+
+static int do_scan(int first)
+{
+ int rc;
+ unsigned int size;
+ unsigned int size_len = sizeof(size);
+
+ if (first) {
+ unsigned int opt;
+ unsigned int optlen = sizeof(opt);
+
+ /* turn off RF */
+ opt = 1;
+ rfid_reader_setopt(rh, RFID_OPT_RDR_RF_KILL, &opt, optlen);
+
+ usleep(10*1000);
+
+ /* turn on RF */
+ opt = 0;
+ rfid_reader_setopt(rh, RFID_OPT_RDR_RF_KILL, &opt, optlen);
+ }
+ printf("scanning for RFID token...\n");
+ rc = rfid_scan(rh, &l2h, &ph);
+ if (rc >= 2) {
+ unsigned char uid_buf[16];
+ unsigned int uid_len = sizeof(uid_buf);
+ rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID, &uid_buf,
+ &uid_len);
+ printf("Layer 2 success (%s): %s\n", rfid_layer2_name(l2h),
+ hexdump(uid_buf, uid_len));
+ }
+ if (rc >= 3) {
+ printf("Protocol success (%s)\n", rfid_protocol_name(ph));
+
+ if (rfid_protocol_getopt(ph, RFID_OPT_PROTO_SIZE,
+ &size, &size_len) == 0)
+ printf("Size: %u bytes\n", size);
+ }
+
+ return rc;
+}
+
+static void do_endless_scan()
+{
+ int rc;
+ int first = 1;
+
+ while (1) {
+ if (first)
+ putc('\n', stdout);
+ printf("==> doing %s scan\n", first ? "first" : "successive");
+ rc = do_scan(first);
+ if (rc >= 3) {
+ printf("closing proto\n");
+ rfid_protocol_close(ph);
+ }
+ if (rc >= 2) {
+ printf("closing layer2\n");
+ rfid_layer2_close(l2h);
+ first = 0;
+ } else
+ first = 1;
+ }
+}
+
+static void do_regdump(void)
+{
+ u_int8_t buffer[0xff];
+ int i;
+
+ printf("dumping rc632 regs...\n");
+
+ rc632_register_dump(rh->ah, buffer);
+
+ printf("\n ");
+ for (i=0; i<=0x0f; i++)
+ printf(" 0x_%01X",i);
+ printf("\n-----------------------------------------------------------------------------------\n");
+
+ for (i=0; i <= 0x3f; i++) {
+ if ((i % 0x10) == 0)
+ printf("0x%01X_:",i/0x10);
+ printf(" 0x%02X", buffer[i]);
+ if ((i% 0x10) == 0x0f)
+ printf("\n");
+ }
+
+ /* print regdump as c-style array*/
+ printf("u_int8_t rc632_regs[] = {");
+ for (i = 0; i <= 0x3f; i++) {
+ if (((i+1) % 0x08) == 1) {
+ if (i > 7)
+ printf("//%2d..%2d",i-8,i-1);
+ printf("\n\t");
+ }
+ printf(" 0x%02X, ",buffer[i]);
+ }
+ printf("//%2d..%2d\n\t 0 };\n",i-8,i-1);
+
+}
+
+static void do_enum(int layer2)