use defined hexdump istead of rfid_hexdump
[librfid] / pegoda / pegoda.c
index 2eaa61e..7422efe 100644 (file)
@@ -12,7 +12,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
  */
 
 
@@ -65,7 +65,7 @@ struct usb_device *find_device(u_int16_t vendor, u_int16_t device)
        return NULL;
 }
 
-int pegoda_transcieve(struct pegoda_handle *ph,
+int pegoda_transceive(struct pegoda_handle *ph,
                      u_int8_t cmd, unsigned char *tx, unsigned int tx_len,
                      unsigned char *rx, unsigned int *rx_len)
 {
@@ -118,7 +118,7 @@ int pegoda_transcieve(struct pegoda_handle *ph,
 
        memcpy(rx, rxbuf+sizeof(*rxhdr), rc-sizeof(*rxhdr));
 
-       return 0;
+       return rxhdr->cmd;
 }
 
 struct pegoda_handle *pegoda_open(void)
@@ -171,7 +171,7 @@ struct pegoda_handle *pegoda_open(void)
 
        printf("alt setting 1 selected\n");
 
-       pegoda_transcieve(ph, PEGODA_CMD_PCD_CONFIG, NULL, 0, rbuf, &rlen);
+       pegoda_transceive(ph, PEGODA_CMD_PCD_CONFIG, NULL, 0, rbuf, &rlen);
 
        return ph;
 out_free:
@@ -207,7 +207,7 @@ static int pegoda_auth_e2(struct pegoda_handle *ph,
        buf[1] = keynr;         /* key number */
        buf[2] = sector;        /* sector */
        rlen = sizeof(rbuf);
-       pegoda_transcieve(ph, PEGODA_CMD_PICC_AUTH, buf, 3, rbuf, &rlen);
+       pegoda_transceive(ph, PEGODA_CMD_PICC_AUTH, buf, 3, rbuf, &rlen);
 
        /* FIXME: check response */
 
@@ -226,7 +226,7 @@ static int pegoda_auth_key(struct pegoda_handle *ph,
        mifare_transform_key(key6, buf+5);
        buf[17] = sector;
 
-       pegoda_transcieve(ph, PEGODA_CMD_PICC_AUTH_KEY, buf, 18, rbuf, &rlen);
+       pegoda_transceive(ph, PEGODA_CMD_PICC_AUTH_KEY, buf, 18, rbuf, &rlen);
 
        /* FIXME: check response */
 
@@ -239,7 +239,7 @@ static int pegoda_read16(struct pegoda_handle *ph,
        int rc;
        unsigned int rlen = 16;
 
-       rc = pegoda_transcieve(ph, PEGODA_CMD_PICC_READ,
+       rc = pegoda_transceive(ph, PEGODA_CMD_PICC_READ,
                                &page, 1, rx, &rlen);
        if (rlen != 16)
                return -EIO;
@@ -253,6 +253,7 @@ int main(int argc, char **argv)
        unsigned char rbuf[256];
        unsigned int rlen = sizeof(rbuf);
        struct pegoda_handle *ph;
+       int i;
 
        ph = pegoda_open();
        if (!ph)
@@ -261,19 +262,19 @@ int main(int argc, char **argv)
        /* LED off */
        buf[0] = 0x00;
        rlen = sizeof(rbuf);
-       pegoda_transcieve(ph, PEGODA_CMD_SWITCH_LED, buf, 1, rbuf, &rlen);
+       pegoda_transceive(ph, PEGODA_CMD_SWITCH_LED, buf, 1, rbuf, &rlen);
 
        /* anticollision */
 
        buf[0] = 0x26;
        rlen = sizeof(rbuf);
-       pegoda_transcieve(ph, PEGODA_CMD_PICC_COMMON_REQUEST, 
+       pegoda_transceive(ph, PEGODA_CMD_PICC_COMMON_REQUEST, 
                          buf, 1, rbuf, &rlen);
 
        buf[0] = 0x93;
        memset(buf+1, 0, 5);
        rlen = sizeof(rbuf);
-       pegoda_transcieve(ph, PEGODA_CMD_PICC_CASC_ANTICOLL, 
+       pegoda_transceive(ph, PEGODA_CMD_PICC_CASC_ANTICOLL, 
                          buf, 6, rbuf, &rlen);
 
        memcpy(ph->snr, rbuf, 4);
@@ -281,12 +282,17 @@ int main(int argc, char **argv)
        buf[0] = 0x93;
        memcpy(buf+1, ph->snr, 4);
        rlen = sizeof(rbuf);
-       pegoda_transcieve(ph, PEGODA_CMD_PICC_CASC_SELECT, 
+       pegoda_transceive(ph, PEGODA_CMD_PICC_CASC_SELECT, 
                          buf, 5, rbuf, &rlen);
 
-       pegoda_auth_key(ph, 0, "\xff\xff\xff\xff\xff\xff");
-       pegoda_read16(ph, 0, rbuf);
-       printf("read16 = %s\n", hexdump(rbuf, 16));
+       for (i = 0; i < 16; i++) {
+               int j;
+               pegoda_auth_key(ph, i, "\xff\xff\xff\xff\xff\xff");
+               for (j = 0; j < 4; j++) {
+                       pegoda_read16(ph, (i*4)+j, rbuf);
+                       printf("read16[%u:%u] = %s\n", i,j,hexdump(rbuf, 16));
+               }
+       }
        
        exit(0);
 }