make "frametype" a parameter of transcieve functions
[librfid] / rfid_proto_tcl.c
index 82a6acf..8590fd4 100644 (file)
@@ -165,7 +165,8 @@ tcl_request_ats(struct rfid_protocol_handle *h)
        rats[1] = (h->priv.tcl.cid & 0x0f) | ((fsdi << 4) & 0xf0);
 
        /* transcieve (with CRC) */
-       ret = h->l2h->l2->fn.transcieve(h->l2h, rats, 2, h->priv.tcl.ats,
+       ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
+                                       rats, 2, h->priv.tcl.ats,
                                       &h->priv.tcl.ats_len, activation_fwt(h),
                                       TCL_TRANSP_F_TX_CRC);
        if (ret < 0) {
@@ -215,6 +216,7 @@ static unsigned char d_to_di(struct rfid_protocol_handle *h, unsigned char D)
 static int 
 tcl_do_pps(struct rfid_protocol_handle *h)
 {
+#if 0
        int ret;
        unsigned char ppss[3];
        unsigned char pps_response[1];
@@ -256,7 +258,7 @@ tcl_do_pps(struct rfid_protocol_handle *h)
        }
        
        h->priv.tcl.state = TCL_STATE_ESTABLISHED;
-
+#endif
        return 0;
 }
 
@@ -396,7 +398,7 @@ tcl_connect(struct rfid_protocol_handle *h)
                }
 
                /* PUPI will be presented as ATS/historical bytes */
-               memcpy(h->priv.tcl.ats, h->l2h->priv.iso14443b.pupi, 4);
+               memcpy(h->priv.tcl.ats, h->l2h->uid, 4);
                h->priv.tcl.ats_len = 4;
                h->priv.tcl.historical_bytes = h->priv.tcl.ats;
 
@@ -431,7 +433,8 @@ tcl_deselect(struct rfid_protocol_handle *h)
        if (ret < 0)
                return ret;
 
-       ret = h->l2h->l2->fn.transcieve(h->l2h, frame, prlg_len, rx,
+       ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
+                                       frame, prlg_len, rx,
                                     &rx_len, deactivation_fwt(h),
                                     TCL_TRANSP_F_TX_CRC);
        if (ret < 0) {
@@ -462,6 +465,8 @@ tcl_transcieve(struct rfid_protocol_handle *h,
        unsigned char *_tx;
        unsigned int _tx_len, _timeout;
        unsigned char wtx_resp[3];
+       unsigned char ack[10];
+       unsigned int ack_len;
 
        if (tx_len > max_net_tx_framesize(th)) {
                /* slow path: we need to use chaining */
@@ -491,8 +496,10 @@ tcl_transcieve(struct rfid_protocol_handle *h,
        _timeout = th->fwt;
 
 do_tx:
-       ret = h->l2h->l2->fn.transcieve(h->l2h, _tx, _tx_len,
+       ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR,
+                                       _tx, _tx_len,
                                        rx_buf, rx_len, _timeout, 0);
+       DEBUGP("l2 transcieve finished\n");
        if (ret < 0)
                goto out_rxb;
 
@@ -501,11 +508,9 @@ do_tx:
                goto out_rxb;
        }
 
-       //if (*rx_len )
-       //
-
        if (is_r_block(*rx_buf)) {
                unsigned int txed = _tx - tx_buf;
+               DEBUGP("R-Block\n");
                /* Handle ACK frame in case of chaining */
                if (*rx_buf & TCL_PCB_CID_FOLLOWING) {
                        if (*(rx_buf+1) != h->priv.tcl.cid) {
@@ -536,6 +541,7 @@ do_tx:
                unsigned char inf;
                unsigned int prlg_len;
 
+               DEBUGP("S-Block\n");
                /* Handle Wait Time Extension */
                if (*rx_buf & TCL_PCB_CID_FOLLOWING) {
                        if (*rx_len < 3) {
@@ -580,6 +586,7 @@ do_tx:
                unsigned char *inf = rx_buf+1;
                /* we're actually receiving payload data */
 
+               DEBUGP("I-Block\n");
                if (*rx_buf & TCL_PCB_CID_FOLLOWING) {
                        if (*(rx_buf+1) != h->priv.tcl.cid) {
                                DEBUGP("CID %u is not valid\n", *(rx_buf)+1);
@@ -593,7 +600,12 @@ do_tx:
                memcpy(rx_data, inf, *rx_len - (inf - rx_buf));
 
                if (*rx_buf & 0x10) {
-                       /* we're not the last frame in the chain, continue */
+                       /* we're not the last frame in the chain, continue rx */
+                       DEBUGP("we're not the last frame in the chain, continue\n");
+                       ack_len = sizeof(ack);
+                       tcl_build_prologue_r(&h->priv.tcl, ack, &ack_len, 0);
+                       _tx = ack;
+                       _tx_len = ack_len;
                        goto do_tx;
                }
        }
@@ -638,8 +650,6 @@ tcl_init(struct rfid_layer2_handle *l2h)
        th->priv.tcl.state = TCL_STATE_INITIAL;
        th->priv.tcl.ats_len = mru;
        th->priv.tcl.toggle = 1;
-       th->l2h = l2h;
-       th->proto = &rfid_protocol_tcl;
 
        th->priv.tcl.fsd = iso14443_fsd_approx(mru);