Skip to content

Output in binary  #3

@GoogleCodeExporter

Description

@GoogleCodeExporter
I have put together the code (below) to get the card data in raw binary form, 
but i get incorrect results by referencing to a known Start Sentinel.
Changing the bits per character gives me different results.
Any idea whats wrong?

#include <sys/types.h>

#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <strings.h>
#include <termios.h>
#include <err.h>
#include <string.h>

#include "libmsr.h"
#include "serialio.h"
#include "msr206.h"

int
dumpbits (uint8_t * buf, int len)
{
    int     bytes, i;
    for (bytes = 0; bytes < len; bytes++) {
        /* for (i = 0; i < 8; i++) { */
        for (i = 7; i > -1; i--) {
            if (buf[bytes] & (1 << i))
                printf("1");
            else
                printf("0");
        }
    }
    printf ("\n");
    return (0);
}

int main(int argc, char * argv[])
{
    int fd = -1;
    int serial;
    msr_tracks_t tracks;
    int i;

    /* Default device selection per platform */
#ifdef __linux__ 
    char *device = "/dev/ttyUSB0";
#else
    char *device = "/dev/cuaU0";
#endif

    if (argv[1] != NULL)
        device = argv[1];
    else
        printf ("no device specified, defaulting to %s\n", device);

    serial = serial_open (device, &fd, MSR_BLOCKING, MSR_BAUD);

    if (serial == -1) {
        err(1, "Serial open of %s failed", device);
        exit(1);
    }

    /* Prepare the reader with a reset */
    msr_init (fd);

    /* Get the device model */
    msr_model (fd);
    /* Get the firmware version information */
    msr_fwrev (fd);

    /* Set the reader into Lo-Co mode */
    msr_set_lo_co (fd);

    /* Prepare the reader with a reset */
    msr_init (fd);

    msr_set_bpi(fd, 210);
    msr_init (fd);
    msr_set_bpc(fd, 6, 6, 6);
    msr_zeros (fd);

do {
    bzero ((char *)&tracks, sizeof(tracks));

    for (i = 0; i < MSR_MAX_TRACKS; i++)
        tracks.msr_tracks[i].msr_tk_len = MSR_MAX_TRACK_LEN;

    printf("Ready to do a raw read. Please slide a card.\n");
    msr_raw_read (fd, &tracks);

        /* If we didn't get any data, don't do this next part */
    for (i = 0; i < MSR_MAX_TRACKS; i++) {
        printf("track%d [%d]: ", i, tracks.msr_tracks[i].msr_tk_len);
        dumpbits (tracks.msr_tracks[i].msr_tk_data,
            tracks.msr_tracks[i].msr_tk_len);
    }

} while (1);

    /* We're finished */
    serial_close (fd);
    exit(0);
}


Original issue reported on code.google.com by jokesare...@gmail.com on 27 Jun 2010 at 2:07

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions