BUGFIX: l3_init can fail on desfire ev3 and produce SIGSEGV
[librfid] / src / rfid_proto_tcl.c
index d00e966..cfde04b 100644 (file)
@@ -16,7 +16,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
 #include <stdio.h>
@@ -122,7 +122,8 @@ tcl_parse_ats(struct rfid_protocol_handle *h,
                } else {
                        /* Section 7.2: fwi for type B is always in ATQB */
                        /* Value is assigned in tcl_connect() */
-                       /* This function is never called for Type B, since it has no (R)ATS */
+                       /* This function is never called for Type B, 
+                        * since Type B has no (R)ATS */
                }
                return 0;
        }
@@ -163,6 +164,8 @@ tcl_parse_ats(struct rfid_protocol_handle *h,
 
        h->priv.tcl.historical_len = (ats+len) - cur;
        h->priv.tcl.historical_bytes = cur;
+       
+       DEBUGP("ATS parsed: %s\n", rfid_hexdump(ats, size));
 
        return 0;
 }
@@ -762,6 +765,45 @@ tcl_fini(struct rfid_protocol_handle *ph)
        return 0;
 }
 
+int 
+tcl_getopt(struct rfid_protocol_handle *h, int optname, void *optval,
+          unsigned int *optlen)
+{
+       u_int8_t *opt_str = optval;
+
+       switch (optname) {
+       case RFID_OPT_P_TCL_ATS:
+               if (h->priv.tcl.ats_len < *optlen)
+                       *optlen = h->priv.tcl.ats_len;
+               memcpy(opt_str, h->priv.tcl.ats, *optlen);
+               break;
+       case RFID_OPT_P_TCL_ATS_LEN:
+               if (*optlen < sizeof(u_int8_t))
+                       return -E2BIG;
+               *optlen = sizeof(u_int8_t);
+               *opt_str = h->priv.tcl.ats_len & 0xff;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+int
+tcl_setopt(struct rfid_protocol_handle *h, int optname, const void *optval,
+          unsigned int optlen)
+{
+       int ret = -EINVAL;
+
+       switch (optname) {
+       default:
+               break;
+       }
+
+       return ret;
+}
+
 const struct rfid_protocol rfid_protocol_tcl = {
        .id     = RFID_PROTOCOL_TCL,
        .name   = "ISO 14443-4 / T=CL",
@@ -771,5 +813,7 @@ const struct rfid_protocol rfid_protocol_tcl = {
                .transceive = &tcl_transceive,
                .close = &tcl_deselect,
                .fini = &tcl_fini,
+               .getopt = &tcl_getopt,
+               .setopt = &tcl_setopt,
        },
 };