Permalink
Browse files

Added Felica support.

  • Loading branch information...
hiroyuki
hiroyuki committed Oct 25, 2009
1 parent 23cdfc3 commit f1f0ab0d6e69f48edf608d46e974f4bed9da6c02
Showing with 123 additions and 3 deletions.
  1. +3 −0 Manifest.txt
  2. +1 −0 ext/nfc/nfc.c
  3. +1 −0 ext/nfc/nfc.h
  4. +10 −2 ext/nfc/nfc_device.c
  5. +62 −0 ext/nfc/nfc_felica.c
  6. +10 −0 ext/nfc/nfc_felica.h
  7. +2 −1 lib/nfc.rb
  8. +34 −0 lib/nfc/felica.rb
View
@@ -11,7 +11,10 @@ ext/nfc/nfc_device.c
ext/nfc/nfc_device.h
ext/nfc/nfc_iso14443a.c
ext/nfc/nfc_iso14443a.h
+ext/nfc/nfc_felica.h
+ext/nfc/nfc_felica.c
lib/nfc.rb
lib/nfc/device.rb
+lib/nfc/felica.rb
lib/nfc/iso14443a.rb
test/test_nfc.rb
View
@@ -8,4 +8,5 @@ void Init_nfc()
init_device();
init_iso14443a();
+ init_felica();
}
View
@@ -8,5 +8,6 @@ extern VALUE cNfc;
#include <nfc_device.h>
#include <nfc_iso14443a.h>
+#include <nfc_felica.h>
#endif
View
@@ -1,5 +1,7 @@
#include <nfc_device.h>
+static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
+
/*
* call-seq:
* connect
@@ -66,9 +68,15 @@ static VALUE dev_select(VALUE self, VALUE tag)
tag_info * ti = calloc(1, sizeof(tag_info));
- nfc_initiator_select_tag(dev, IM_ISO14443A_106, NULL, 0, ti);
+ if (nfc_initiator_select_tag(dev, IM_FELICA_212, abtFelica, 5, ti) ||
+ nfc_initiator_select_tag(dev, IM_FELICA_424, abtFelica, 5, ti)) {
+ return Data_Wrap_Struct(cNfcFelica, 0, free, ti);
+ }
+
+ if (nfc_initiator_select_tag(dev, IM_ISO14443A_106, NULL, 0, ti) ) {
+ return Data_Wrap_Struct(cNfcISO14443A, 0, free, ti);
+ }
- return Data_Wrap_Struct(cNfcISO14443A, 0, free, ti);
}
/*
View
@@ -0,0 +1,62 @@
+#include <nfc_felica.h>
+
+VALUE cNfcFelica;
+
+/*
+ * uint32_t uiLen;
+ * byte_t btResCode;
+ * byte_t abtId[8];
+ * byte_t abtPad[8];
+ * byte_t abtSysCode[2];
+ */
+
+static VALUE uiLen(VALUE self)
+{
+ tag_info_felica * tag;
+ Data_Get_Struct(self, tag_info_felica, tag);
+
+ return INT2NUM(tag->uiLen);
+}
+
+static VALUE btResCode(VALUE self)
+{
+ tag_info_felica * tag;
+ Data_Get_Struct(self, tag_info_felica, tag);
+
+ return INT2NUM(tag->btResCode);
+}
+
+static VALUE abtId(VALUE self)
+{
+ tag_info_felica * tag;
+ Data_Get_Struct(self, tag_info_felica, tag);
+
+ return rb_str_new(tag->abtId, 8 );
+}
+
+static VALUE abtPad(VALUE self)
+{
+ tag_info_felica * tag;
+ Data_Get_Struct(self, tag_info_felica, tag);
+
+ return rb_str_new(tag->abtPad, 8 );
+}
+
+static VALUE abtSysCode(VALUE self)
+{
+ tag_info_felica * tag;
+ Data_Get_Struct(self, tag_info_felica, tag);
+
+ return rb_str_new(tag->abtSysCode, 2 );
+}
+
+void init_felica()
+{
+ cNfcFelica = rb_define_class_under(cNfc, "Felica", rb_cObject);
+
+ rb_define_method(cNfcFelica, "uiLen", uiLen, 0);
+ rb_define_method(cNfcFelica, "btResCode", btResCode, 0);
+ rb_define_method(cNfcFelica, "abtId", abtId, 0);
+ rb_define_private_method(cNfcFelica, "abtPad", abtPad, 0);
+ rb_define_private_method(cNfcFelica, "abtSysCode", abtSysCode, 0);
+}
View
@@ -0,0 +1,10 @@
+#ifndef NFC_Felica
+#define NFC_Felica
+
+#include <nfc.h>
+
+extern VALUE cNfcFelica;
+
+void init_felica();
+
+#endif
View
@@ -3,13 +3,14 @@
require 'nfc/nfc'
require 'nfc/device'
require 'nfc/iso14443a'
+require 'nfc/felica'
###
# NFC is a class for dealing with Near Field Communication systems. This
# library will read RFID tags from an RFID reader. You should start by reading
# NFC#find
class NFC
- VERSION = '2.0.1'
+ VERSION = '2.0.2'
include Singleton
View
@@ -0,0 +1,34 @@
+class NFC
+ class Felica
+
+ def uid
+ abtId.unpack 'C*'
+ end
+
+ def pad
+ abtPad.unpack 'C*'
+ end
+
+ def sys_code
+ abtSysCode.unpack 'C*'
+ end
+
+ def to_s join_string = ''
+ sprintf((['%02x'] * 8 ).join(join_string), * uid).upcase
+ end
+
+ def inspect
+# 78 printf("The following (NFC) Felica tag was found:\n\n");
+# 79 printf("%18s","ID (NFCID2): "); print_hex(ti.tif.abtId,8);
+# 80 printf("%18s","Parameter (PAD): "); print_hex(ti.tif.abtPad,8);
+ pad = sprintf( (['%02x'] * 8 ).join(' '), *self.pad)
+ string_ary = [
+ "(NFC) Felica Tag",
+ "ID (NFCID2): #{to_s ' '}",
+ "Parameter(PAD): #{pad}"
+ ]
+ string_ary.join "\n"
+ end
+
+ end
+end

0 comments on commit f1f0ab0

Please sign in to comment.