More magstripe work, new tool dmsr206.pl
Sep 27th, 2007 by dmess0r
Over the last few days I have been working hard on an application to easily interface with my MSR206. Essentially the idea is to create a cross platform tool which enables the user to send commands, read/write from/to the device. I am codifying the programmers manual. The language of choice on this go-around is Perl, using Device::SerialPort.
My initial development berth was MacOS X on a Macbook Pro, using a Keyspan USA 19-QW. Unfortunately there is an undocumented bug with port->write() under OS X at this time, so I had to switch over to Linux on standard hardware with a legitimate RS232 port.
For your enjoyment, here is the help output of the app thus far:
[evan@serv2 ~]$ ./dmsr206.pl dmsr206.pl v0.1a - Evan Brewer- Tool for communicating with a Unitech MSR206-3HL via RS-232. - Conforms to ISO/IEC 7811-6 - NOTE: ALL OPTIONS MUTUALLY EXCLUSIVE EXCEPT --device - NOTE: Busted under MacOS X (bug Device::SerialPort author) Usage: ./dmsr206.pl [command] --device= Options: --device= Specify device. Mandatory. --debug Put ./dmsr206.pl into debug mode. * --reset Reset the MSR206 to an initial state. --all_led_off Turn off all LEDs. --all_led_on Turn on all LEDs. --red_led_on Turn on red LED. --green_led_on Turn on green LED. --yellow_led_on Turn on yellow LED. --read_raw_data Read swipe without ASCII decode. --read Read swiped card and return data with ASCII decode. --set_high_co Set High-Co. --set_low_co Set Low-Co. * --write_raw_data Write data to swiped card. * --write Write data block to swiped card. * --sensor_test Verify card sensing circuit, Either swipe, or send reset. * --ram_test Test onboard RAM. * --set_leading_zero=XX Set leading zero pad value before card data starts. [pad] * 25.4 / BPI (75 or 210)mm Default: [3D] or [16] TK1 & TK3: [3D] means leading zero=61 TK2: [16] means leading zero=22 * --check_leading_zero Query for current pad value. * --erase_tracks=
The text is a bit small, but I wanted to ensure that it looked right on the blog. As you can see, the application is command-line, and is passed arguments to control the device.
Next I’ll give a demo of how the application might be used:
$ ./dmsr206.pl –device=/dev/ttyS0 –set_high_co
$ ./dmsr206.pl –device=/dev/ttyS0 –read_raw_device > stripe.out
Through the magic of Device::SerialPort, I am able to talk to the MSR206, set the coercivity to high, and run a card for reading raw output. The MSR spits back formatted data to STDOUT and we capture that output to the file stripe.out.
You might ask yourself, “Well if we’re reading raw output, then why do you say it is formatted?” The answer is relatively simple. After hexdump’ing the output , the only way you’re going to know where the data on Track[123] begins/ends, you’ll need some kind of delimeter, or sentinel, as the terminology goes in the magstripe world. The MSR outputs begin/end sentinels inside the output so that one may discern the boundaries as well as whatever data may be laying in Track[123].
I am in the process of ensuring clean output, but from the results so far, the “–read” and “–read_raw_data” logic seems to be working pretty well.
I originally had some concerns that multiple passes against a single card would result in inconsistent data, so I used the following technique to attempt to ascertain consistency:
$ diff -u <(hexdump stripe.pass.1) <(hexdump stripe.pass.2)
Thankfully the passes are mostly identical, at least up until the end sentinel produced by the MSR. Periodically, after the end sentinel there is junk data. We really don’t care about the junk data because that is what for are the sentinels. *grin*
The next bit of work is to ensure that the “–reset” command works as expected. Right now it simply sends an \x73\x61\r, without then following up with the appropriate \x73\x65\r, read for response, and send another \x73\x61\r.
I will probably work on both the “–reset” as well as attempting beginning another tool to break apart the MSR formatting and reveal the raw track data.
More to come.
you are the man, would you mind sharing your perl application code?
I have a MSE-730 mag stripe reader/writer, it supports MSR206 and MSE-630A emulation modes, but hell im not good at coding and stuff, thats not my thing.. i’m using linux and i can’t stand booting windows just for a stupid 1mb software that im sure could be bridged to linux..
so you perl script seems to be the glory of rome
my mail is if you could contact i would appreciate
sincerly, Nathaniel
Hi Nathaniel,
dmsr206.pl isn’t quite ready yet. It has several logic bugs which have to be worked out as well as ensuring the write functionality works as expected. One of the potential issues you may have is that the MSE-730 may or may not fully support the whole command-set of the MSR-206. If it does, then good, and the app might work for you. I don’t plan on releasing this thing into the wild until the command-set is complete, as well as the code is cleaned up. Right now the script is clunky and full of debug statements. It will be released, with time.
- dmess0r
Hi dmess0r,
nice work there! Love to see the code as Nathaniel, even in it’s primative state (so i can play around myself). Cool stuff.
J-
Hi dmess0r,
looks really neat! when will this be finished and could i try it out? i’ve got a MSR-206 myself
Greetz,
Jeff
[...] more on the magstripe project with my MSR206. Instead of going hog-wild and finishing/polishing dmsr206.pl reference tool like in a previous post, I decided to just make a few scripts with rudimentary functionality. With this dmsr-2.1.tar.bz2 [...]