X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=src%2Frfid_proto_tcl.c;h=cfde04b29f688c6b8a8ff42d2c961b7f7ec716f6;hb=refs%2Fheads%2Fsmartx;hp=e6735a8eab69a5f55f168e5caa351f7e481ca878;hpb=52f7a5374c6ca58a47dc12c553a66a9f04535bc6;p=librfid diff --git a/src/rfid_proto_tcl.c b/src/rfid_proto_tcl.c index e6735a8..cfde04b 100644 --- a/src/rfid_proto_tcl.c +++ b/src/rfid_proto_tcl.c @@ -1,6 +1,6 @@ /* ISO 14443-4 (T=CL) implementation, PCD side. * - * (C) 2005 by Harald Welte + * (C) 2005-2006 by Harald Welte * */ @@ -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 @@ -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; } @@ -259,7 +262,9 @@ tcl_do_pps(struct rfid_protocol_handle *h) { int ret; unsigned char ppss[3]; - unsigned char pps_response[1]; + /* FIXME: this stinks like hell. IF we reduce pps_response size to one, + we'll get stack corruption! */ + unsigned char pps_response[10]; unsigned int rx_len = 1; unsigned char Dr, Ds, DrI, DsI; unsigned int speed; @@ -735,13 +740,13 @@ tcl_init(struct rfid_layer2_handle *l2h) struct rfid_protocol_handle *th; unsigned int mru = l2h->rh->ah->mru; - th = malloc(sizeof(struct rfid_protocol_handle) + mru); + th = malloc_protocol_handle(sizeof(struct rfid_protocol_handle)); if (!th) return NULL; /* FIXME: mru should be attribute of layer2 (in case it adds/removes * some overhead */ - memset(th, 0, sizeof(struct rfid_protocol_handle) + mru); + memset(th, 0, sizeof(struct rfid_protocol_handle)); /* maximum received ats length equals mru of asic/reader */ th->priv.tcl.state = TCL_STATE_INITIAL; @@ -756,11 +761,50 @@ tcl_init(struct rfid_layer2_handle *l2h) static int tcl_fini(struct rfid_protocol_handle *ph) { - free(ph); + free_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; } -struct rfid_protocol rfid_protocol_tcl = { +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", .fn = { @@ -769,5 +813,7 @@ struct rfid_protocol rfid_protocol_tcl = { .transceive = &tcl_transceive, .close = &tcl_deselect, .fini = &tcl_fini, + .getopt = &tcl_getopt, + .setopt = &tcl_setopt, }, };