make "frametype" a parameter of transcieve functions
[librfid] / rfid_layer2_iso14443b.c
index d36b5da..f874071 100644 (file)
@@ -36,7 +36,7 @@
 static inline int
 fwi_to_fwt(struct rfid_layer2_handle *h, unsigned int *fwt, unsigned int fwi)
 {
-       unsigned int multiplier;
+       unsigned int multiplier, tmp;
 
        /* 15 is RFU */
        if (fwi > 14)
@@ -52,7 +52,9 @@ fwi_to_fwt(struct rfid_layer2_handle *h, unsigned int *fwt, unsigned int fwi)
 
        multiplier = 1 << fwi;          /* 2 to the power of fwi */
 
-       return (1000000 * 256 * 16 / h->rh->ah->asic->fc) * multiplier
+       tmp = (unsigned int) 1000000 * 256 * 16;
+
+       return (tmp / h->rh->ah->asic->fc) * multiplier;
 }
 
 static int
@@ -87,8 +89,8 @@ parse_atqb(struct rfid_layer2_handle *h, struct iso14443b_atqb *atqb)
 
        /* FIXME: speed capability */
 
-       memcpy(h->priv.iso14443b.pupi, atqb->pupi,
-               sizeof(h->priv.iso14443b.pupi));
+       memcpy(h->uid, atqb->pupi, sizeof(atqb->pupi));
+       h->uid_len = sizeof(atqb->pupi);
 
        return 0;
 }
@@ -110,9 +112,10 @@ send_reqb(struct rfid_layer2_handle *h, unsigned char afi,
             num_slot_idx++) {
                reqb[2] = num_slot_idx & 0x07;
                if (is_wup)
-                       reqb[2] |= 0x80;
+                       reqb[2] |= 0x08;
 
-               ret = h->rh->reader->transcieve(h->rh, reqb, sizeof(reqb),
+               ret = h->rh->reader->transcieve(h->rh, RFID_14443B_FRAME_REGULAR,
+                                               reqb, sizeof(reqb),
                                                 (unsigned char *)&atqb, 
                                                 &atqb_len, ATQB_TIMEOUT, 0);
                h->priv.iso14443b.state = ISO14443B_STATE_REQB_SENT;
@@ -124,7 +127,7 @@ send_reqb(struct rfid_layer2_handle *h, unsigned char afi,
                /* FIXME: send N-1 slot marker frames */
        
                if (atqb_len != sizeof(atqb)) {
-                       DEBUGP("error: atqb_len = %u instead of %u\n",
+                       DEBUGP("error: atqb_len = %u instead of %Zu\n",
                                atqb_len, sizeof(atqb));
                        continue;
                }
@@ -179,7 +182,7 @@ transcieve_attrib(struct rfid_layer2_handle *h, const unsigned char *inf,
                memcpy((unsigned char *)attrib+sizeof(*attrib), inf, inf_len);
 
        attrib->one_d = 0x1d;
-       memcpy(attrib->identifier, h->priv.iso14443b.pupi, 4);
+       memcpy(attrib->identifier, h->uid, 4);
 
        /* FIXME: do we want to change TR0/TR1 from its default ? */
        /* FIXME: do we want to change SOF/EOF from its default ? */
@@ -197,7 +200,8 @@ transcieve_attrib(struct rfid_layer2_handle *h, const unsigned char *inf,
                attrib->param3.protocol_type = 0x1;
 
        *rx_len = *rx_len + 1;
-       ret = h->rh->reader->transcieve(h->rh, (unsigned char *) attrib,
+       ret = h->rh->reader->transcieve(h->rh, RFID_14443B_FRAME_REGULAR,
+                                       (unsigned char *) attrib,
                                        sizeof(*attrib)+inf_len,
                                        rx_buf, rx_len, h->priv.iso14443b.fwt,
                                        0);
@@ -238,9 +242,10 @@ iso14443b_hltb(struct rfid_layer2_handle *h)
        unsigned int hltb_len = 1;
 
        hltb[0] = 0x50;
-       memcpy(hltb+1, h->priv.iso14443b.pupi, 4);
+       memcpy(hltb+1, h->uid, 4);
 
-       ret = h->rh->reader->transcieve(h->rh, hltb, 5,
+       ret = h->rh->reader->transcieve(h->rh, RFID_14443B_FRAME_REGULAR,
+                                       hltb, 5,
                                        hltb_resp, &hltb_len,
                                        h->priv.iso14443b.fwt, 0);
        h->priv.iso14443b.state = ISO14443B_STATE_HLTB_SENT;
@@ -263,7 +268,7 @@ iso14443b_anticol(struct rfid_layer2_handle *handle)
 {
        unsigned char afi = 0; /* FIXME */
        int ret;
-       char buf[255];
+       unsigned char buf[255];
        unsigned int buf_len = sizeof(buf);
 
        ret = send_reqb(handle, afi, 0, 0);
@@ -315,11 +320,14 @@ iso14443b_fini(struct rfid_layer2_handle *handle)
 
 static int
 iso14443b_transcieve(struct rfid_layer2_handle *handle,
+                    enum rfid_frametype frametype,
                     const unsigned char *tx_buf, unsigned int tx_len,
                     unsigned char *rx_buf, unsigned int *rx_len,
-                    unsigned int timeout, unsigned int flags)
+                    u_int64_t timeout, unsigned int flags)
 {
-       return handle->rh->reader->transcieve(handle->rh, tx_buf, tx_len,
+       DEBUGP("transcieving %u bytes, expecting max %u\n", tx_len, *rx_len);
+       return handle->rh->reader->transcieve(handle->rh, frametype,
+                                             tx_buf, tx_len,
                                              rx_buf, rx_len, timeout, flags);
 }
 
@@ -334,4 +342,3 @@ struct rfid_layer2 rfid_layer2_iso14443b = {
                .fini           = &iso14443b_fini,
        },
 };
-