libmsr  dc2dc9c
Classes | Macros | Typedefs | Functions
libmsr.h File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdint.h>
Include dependency graph for libmsr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  msr_cmd
 Represents a command issued to the MSR device. More...
 
struct  msr_end
 Represents the end of a read/write command. More...
 
struct  msr_lz
 Represents leading zero counts on a card. More...
 
struct  msr_model
 Represents the MSR's model. More...
 
struct  msr_bpc
 Represents the MSR's BPC settings for each track. More...
 
struct  msr_track
 Represents a single track on a magnetic card. More...
 
struct  msr_tracks
 Represents all tracks on a magnetic card. More...
 

Macros

#define LIBMSR_ERR_OK   0x0
 
#define LIBMSR_ERR_GENERIC   0x1000
 
#define LIBMSR_ERR_ISO   0x1100
 
#define LIBMSR_ERR_DEVICE   0x2000
 
#define LIBMSR_ERR_SERIAL   0x4000
 
#define MSR_MAX_TRACK_LEN   255
 
#define MSR_MAX_TRACKS   3
 
#define MSR_BLOCKING   O_NONBLOCK
 
#define MSR_BAUD   B9600
 
#define MSR_ESC   0x1B
 
#define MSR_FS   0x1C
 
#define MSR_STS_OK   0x30
 
#define MSR_STS_ERR   0x41
 
#define MSR_CMD_READ   0x72
 
#define MSR_CMD_WRITE   0x77
 
#define MSR_CMD_RAW_READ   0x6D
 
#define MSR_CMD_RAW_WRITE   0x6E
 
#define MSR_STS_RW_ERR   0x31
 
#define MSR_STS_RW_CMDFMT_ERR   0x32
 
#define MSR_STS_RW_CMDBAD_ERR   0x34
 
#define MSR_STS_RW_SWIPEBAD_ERR   0x39
 
#define MSR_RW_START   0x73 /* 's' */
 
#define MSR_RW_END   0x3F /* '?' */
 
#define MSR_RW_BAD   0x2A /* '*' */
 
#define MSR_RW_EMPTY   0x2B /* '+' */
 
#define MSR_CMD_DIAG_COMM   0x65
 
#define MSR_STS_COMM_OK   0x79
 
#define MSR_CMD_DIAG_SENSOR   0x86
 
#define MSR_STS_SENSOR_OK   MSR_STS_OK
 
#define MSR_CMD_DIAG_RAM   0x87
 
#define MSR_STS_RAM_OK   MSR_STS_OK
 
#define MSR_STS_RAM_ERR   MSR_STS_ERR
 
#define MSR_CMD_SLZ   0x7A
 
#define MSR_STS_SLZ_OK   MSR_STS_OK
 
#define MSR_STS_SLZ_ERR   MSR_STS_ERR
 
#define MSR_CMD_CLZ   0x6C
 
#define MSR_CMD_ERASE   0x63
 
#define MSR_STS_ERASE_OK   MSR_STS_OK
 
#define MSR_STS_ERASE_ERR   MSR_STS_ERR
 
#define MSR_ERASE_TK1   0x00
 
#define MSR_ERASE_TK2   0x02
 
#define MSR_ERASE_TK3   0x04
 
#define MSR_ERASE_TK1_TK2   0x03
 
#define MSR_ERASE_TK1_TK3   0x05
 
#define MSR_ERASE_TK2_TK3   0x06
 
#define MSR_ERASE_ALL   0x07
 
#define MSR_CMD_SETBPI   0x62
 
#define MSR_STS_BPI_OK   MSR_STS_OK
 
#define MSR_STS_BPI_ERR   MSR_STS_ERR
 
#define MSR_CMD_MODEL   0x74
 
#define MSR_STS_MODEL_OK   0x53
 
#define MSR_MODEL_MSR206_1   0x31
 
#define MSR_MODEL_MSR206_2   0x32
 
#define MSR_MODEL_MSR206_3   0x33
 
#define MSR_MODEL_MSR206_5   0x35
 
#define MSR_CMD_FWREV   0x76
 
#define MSR_FWREV_FMT   "REV?X.XX"
 
#define MSR_CMD_SETBPC   0x6F
 
#define MSR_STS_BPC_OK   MSR_STS_OK
 
#define MSR_STS_BPC_ERR   MSR_STS_ERR
 
#define MSR_CMD_SETCO_HI   0x78
 
#define MSR_CMD_SETCO_LO   0x79
 
#define MSR_STS_CO_OK   MSR_STS_OK
 
#define MSR_STS_CO_ERR   MSR_STS_ERR
 
#define MSR_CMD_GETCO   0x64
 
#define MSR_CO_HI   0x68
 
#define MSR_CO_LO   0x6C
 
#define MSR_CMD_RESET   0x61
 
#define MSR_CMD_LED_OFF   0x81
 
#define MSR_CMD_LED_ON   0x82
 
#define MSR_CMD_LED_GRN_ON   0x83
 
#define MSR_CMD_LED_YLW_ON   0x84
 
#define MSR_CMD_LED_RED_ON   0x85
 

Typedefs

typedef struct msr_cmd msr_cmd_t
 Represents a command issued to the MSR device. More...
 
typedef struct msr_end msr_end_t
 Represents the end of a read/write command. More...
 
typedef struct msr_lz msr_lz_t
 Represents leading zero counts on a card. More...
 
typedef struct msr_model msr_model_t
 Represents the MSR's model. More...
 
typedef struct msr_bpc msr_bpc_t
 Represents the MSR's BPC settings for each track. More...
 
typedef struct msr_track msr_track_t
 Represents a single track on a magnetic card. More...
 
typedef struct msr_tracks msr_tracks_t
 Represents all tracks on a magnetic card. More...
 

Functions

int msr_serial_open (char *path, int *fd, int blocking, speed_t baud)
 Open a serial connection to the MSR device. More...
 
int msr_serial_close (int fd)
 Close a serial connection to the MSR device. More...
 
int msr_serial_readchar (int fd, uint8_t *c)
 Read a single character from the MSR device. More...
 
int msr_serial_write (int fd, void *buf, size_t len)
 Write a series of bytes to the MSR device. More...
 
int msr_serial_read (int fd, void *buf, size_t len)
 Read a series of bytes from the MSR device. More...
 
int msr_zeros (int fd, msr_lz_t *lz)
 Get the MSR device's current leading-zero setting. More...
 
int msr_commtest (int fd)
 Perform a communications test. More...
 
int msr_init (int fd)
 Initialize the MSR device. More...
 
int msr_fwrev (int fd, uint8_t *buf)
 Check the device's firmware revision. More...
 
int msr_model (int fd, uint8_t *buf)
 Check the device's model. More...
 
int msr_sensor_test (int fd)
 Check the device's sensor. More...
 
int msr_ram_test (int fd)
 Check the device's RAM. More...
 
int msr_get_co (int fd)
 Get the device's coercivity level. More...
 
int msr_set_hi_co (int fd)
 Set the device's coercivity to high. More...
 
int msr_set_lo_co (int fd)
 Set the device's coercivity to low. More...
 
int msr_reset (int fd)
 Reset the MSR device. More...
 
int msr_iso_read (int fd, msr_tracks_t *tracks)
 Read an ISO formatted card. More...
 
int msr_iso_write (int fd, msr_tracks_t *tracks)
 Write an ISO formatted card. More...
 
int msr_raw_read (int fd, msr_tracks_t *tracks)
 Read raw data from a card. More...
 
int msr_raw_write (int fd, msr_tracks_t *tracks)
 Write raw data to a card. More...
 
int msr_erase (int fd, uint8_t tracks)
 Erase one or more tracks on a card. More...
 
int msr_flash_led (int fd, uint8_t led)
 Toggle the LEDs on the MSR device. More...
 
int msr_set_bpi (int fd, uint8_t bpi)
 Set the MSR device's BPI value. More...
 
int msr_set_bpc (int fd, uint8_t bpc1, uint8_t bpc2, uint8_t bpc3)
 Set the MSR device's BPC value for each track. More...
 
int msr_reverse_tracks (msr_tracks_t *tracks)
 Reverse a msr_tracks_t structure in-place. More...
 
int msr_reverse_track (msr_track_t *track)
 Reverse a msr_track_t structure in-place. More...
 
void msr_pretty_output_hex (int fd, msr_tracks_t tracks)
 Dump a "pretty" hexadecimal representation of tracks to a fd. More...
 
void msr_pretty_output_string (int fd, msr_tracks_t tracks)
 Dump a "pretty" string representation of tracks to a fd. More...
 
void msr_pretty_output_bits (int fd, msr_tracks_t tracks)
 Dump a "pretty" binary representation of tracks to a fd. More...
 
void msr_pretty_printer_hex (msr_tracks_t tracks)
 Dump a "pretty" hexadecimal representation of tracks to stdout. More...
 
void msr_pretty_printer_string (msr_tracks_t tracks)
 Dump a "pretty" string representation of tracks to stdout. More...
 
void msr_pretty_printer_bits (msr_tracks_t tracks)
 Dump a "pretty" binary representation of tracks to stdout. More...
 
const unsigned char msr_reverse_byte (const unsigned char byte)
 Reverse a single byte. More...
 

Macro Definition Documentation

◆ LIBMSR_ERR_DEVICE

#define LIBMSR_ERR_DEVICE   0x2000

Returned on error with device control.

◆ LIBMSR_ERR_GENERIC

#define LIBMSR_ERR_GENERIC   0x1000

Returned on generic error.

◆ LIBMSR_ERR_ISO

#define LIBMSR_ERR_ISO   0x1100

Returned on error with ISO-formatted card.

◆ LIBMSR_ERR_OK

#define LIBMSR_ERR_OK   0x0

Returned on operation success.

◆ LIBMSR_ERR_SERIAL

#define LIBMSR_ERR_SERIAL   0x4000

Returned on error in serial I/O.

◆ MSR_BAUD

#define MSR_BAUD   B9600

◆ MSR_BLOCKING

#define MSR_BLOCKING   O_NONBLOCK

◆ MSR_CMD_CLZ

#define MSR_CMD_CLZ   0x6C

Request a leading-zero check on a card.

See also
msr_lz_t

◆ MSR_CMD_DIAG_COMM

#define MSR_CMD_DIAG_COMM   0x65

Request a communications test.

◆ MSR_CMD_DIAG_RAM

#define MSR_CMD_DIAG_RAM   0x87

Request a RAM test.

◆ MSR_CMD_DIAG_SENSOR

#define MSR_CMD_DIAG_SENSOR   0x86

Request a sensor test.

◆ MSR_CMD_ERASE

#define MSR_CMD_ERASE   0x63

Request a track erasure.

◆ MSR_CMD_FWREV

#define MSR_CMD_FWREV   0x76

Request the MSR device's firmware revision.

◆ MSR_CMD_GETCO

#define MSR_CMD_GETCO   0x64

Request the MSR device's current coercivity setting.

See also
msr_get_co()

◆ MSR_CMD_LED_GRN_ON

#define MSR_CMD_LED_GRN_ON   0x83

Request that the MSR device turn on the green LED.

See also
msr_flash_led()

◆ MSR_CMD_LED_OFF

#define MSR_CMD_LED_OFF   0x81

Request that the MSR device turn off all LEDs.

See also
msr_flash_led()

◆ MSR_CMD_LED_ON

#define MSR_CMD_LED_ON   0x82

Request that the MSR device turn on all LEDs.

See also
msr_flash_led()

◆ MSR_CMD_LED_RED_ON

#define MSR_CMD_LED_RED_ON   0x85

Request that the MSR device turn on the red LED.

See also
msr_flash_led()

◆ MSR_CMD_LED_YLW_ON

#define MSR_CMD_LED_YLW_ON   0x84

Request that the MSR device turn on the yellow LED.

See also
msr_flash_led()

◆ MSR_CMD_MODEL

#define MSR_CMD_MODEL   0x74

Request the MSR device's model number.

◆ MSR_CMD_RAW_READ

#define MSR_CMD_RAW_READ   0x6D

Request a raw read from the MSR device.

◆ MSR_CMD_RAW_WRITE

#define MSR_CMD_RAW_WRITE   0x6E

Request a raw write from the MSR device.

◆ MSR_CMD_READ

#define MSR_CMD_READ   0x72

Request a formatted read from the MSR device.

◆ MSR_CMD_RESET

#define MSR_CMD_RESET   0x61

Request a reset from the MSR device.

See also
msr_reset() and msr_init()

◆ MSR_CMD_SETBPC

#define MSR_CMD_SETBPC   0x6F

Request a change in the MSR device's BPC settings.

◆ MSR_CMD_SETBPI

#define MSR_CMD_SETBPI   0x62

Request a change in the MSR device's bits-per-inch (BPI) setting.

◆ MSR_CMD_SETCO_HI

#define MSR_CMD_SETCO_HI   0x78

Request that the MSR device change into Hi-Co mode.

See also
msr_set_hi_co()

◆ MSR_CMD_SETCO_LO

#define MSR_CMD_SETCO_LO   0x79

Request that the MSR device change into Lo-Co mode.

See also
msr_set_lo_co()

◆ MSR_CMD_SLZ

#define MSR_CMD_SLZ   0x7A

Request a set-leading-zero count change on a card.

◆ MSR_CMD_WRITE

#define MSR_CMD_WRITE   0x77

Request a formatted write from the MSR device.

◆ MSR_CO_HI

#define MSR_CO_HI   0x68

The response when the MSR device is in Hi-Co mode.

◆ MSR_CO_LO

#define MSR_CO_LO   0x6C

The response when the MSR device is in Lo-Co mode.

◆ MSR_ERASE_ALL

#define MSR_ERASE_ALL   0x07

Erase all three tracks.

◆ MSR_ERASE_TK1

#define MSR_ERASE_TK1   0x00

Erase only track 1.

◆ MSR_ERASE_TK1_TK2

#define MSR_ERASE_TK1_TK2   0x03

Erase track 1 and track 2.

◆ MSR_ERASE_TK1_TK3

#define MSR_ERASE_TK1_TK3   0x05

Erase track 1 and track 3.

◆ MSR_ERASE_TK2

#define MSR_ERASE_TK2   0x02

Erase only track 2.

◆ MSR_ERASE_TK2_TK3

#define MSR_ERASE_TK2_TK3   0x06

Erase track 2 and track 3.

◆ MSR_ERASE_TK3

#define MSR_ERASE_TK3   0x04

Erase only track 3.

◆ MSR_ESC

#define MSR_ESC   0x1B

ESC is frequently used as a start delimiter character.

◆ MSR_FS

#define MSR_FS   0x1C

ASCII file separator character is used to separate track data.

◆ MSR_FWREV_FMT

#define MSR_FWREV_FMT   "REV?X.XX"

The format of the firmware revision response.

◆ MSR_MAX_TRACK_LEN

#define MSR_MAX_TRACK_LEN   255

The maximum length, in bytes, of a track.

◆ MSR_MAX_TRACKS

#define MSR_MAX_TRACKS   3

The maximum number of tracks on a card.

◆ MSR_MODEL_MSR206_1

#define MSR_MODEL_MSR206_1   0x31

◆ MSR_MODEL_MSR206_2

#define MSR_MODEL_MSR206_2   0x32

◆ MSR_MODEL_MSR206_3

#define MSR_MODEL_MSR206_3   0x33

◆ MSR_MODEL_MSR206_5

#define MSR_MODEL_MSR206_5   0x35

◆ MSR_RW_BAD

#define MSR_RW_BAD   0x2A /* '*' */

◆ MSR_RW_EMPTY

#define MSR_RW_EMPTY   0x2B /* '+' */

◆ MSR_RW_END

#define MSR_RW_END   0x3F /* '?' */

◆ MSR_RW_START

#define MSR_RW_START   0x73 /* 's' */

◆ MSR_STS_BPC_ERR

#define MSR_STS_BPC_ERR   MSR_STS_ERR

The response to a failed BPC change request.

◆ MSR_STS_BPC_OK

#define MSR_STS_BPC_OK   MSR_STS_OK

The response to a successful BPC change request.

◆ MSR_STS_BPI_ERR

#define MSR_STS_BPI_ERR   MSR_STS_ERR

The response to a failed BPI change.

◆ MSR_STS_BPI_OK

#define MSR_STS_BPI_OK   MSR_STS_OK

The response to a successful BPI change.

◆ MSR_STS_CO_ERR

#define MSR_STS_CO_ERR   MSR_STS_ERR

The response to a failed coercivity change request.

◆ MSR_STS_CO_OK

#define MSR_STS_CO_OK   MSR_STS_OK

The response to a successful coercivity change request.

◆ MSR_STS_COMM_OK

#define MSR_STS_COMM_OK   0x79

The response to a successful communications test.

◆ MSR_STS_ERASE_ERR

#define MSR_STS_ERASE_ERR   MSR_STS_ERR

The response to a failed track erasure.

◆ MSR_STS_ERASE_OK

#define MSR_STS_ERASE_OK   MSR_STS_OK

The response to a successful track erasure.

◆ MSR_STS_ERR

#define MSR_STS_ERR   0x41

A generic error status sent by the MSR device.

◆ MSR_STS_MODEL_OK

#define MSR_STS_MODEL_OK   0x53

The response to a successful model number request.

◆ MSR_STS_OK

#define MSR_STS_OK   0x30

A generic success status sent by the MSR device.

◆ MSR_STS_RAM_ERR

#define MSR_STS_RAM_ERR   MSR_STS_ERR

The response to a failed RAM test.

◆ MSR_STS_RAM_OK

#define MSR_STS_RAM_OK   MSR_STS_OK

The response to a successful RAM test.

◆ MSR_STS_RW_CMDBAD_ERR

#define MSR_STS_RW_CMDBAD_ERR   0x34

An invalid command issued during read/write.

◆ MSR_STS_RW_CMDFMT_ERR

#define MSR_STS_RW_CMDFMT_ERR   0x32

An error in command formatting during read/write.

◆ MSR_STS_RW_ERR

#define MSR_STS_RW_ERR   0x31

A generic read/write error.

◆ MSR_STS_RW_SWIPEBAD_ERR

#define MSR_STS_RW_SWIPEBAD_ERR   0x39

A bad card swipe during write.

◆ MSR_STS_SENSOR_OK

#define MSR_STS_SENSOR_OK   MSR_STS_OK

The response to a successful sensor test.

◆ MSR_STS_SLZ_ERR

#define MSR_STS_SLZ_ERR   MSR_STS_ERR

The response to a failed SLZ change.

◆ MSR_STS_SLZ_OK

#define MSR_STS_SLZ_OK   MSR_STS_OK

The response to a successful SLZ change.

Typedef Documentation

◆ msr_bpc_t

typedef struct msr_bpc msr_bpc_t

Represents the MSR's BPC settings for each track.

◆ msr_cmd_t

typedef struct msr_cmd msr_cmd_t

Represents a command issued to the MSR device.

A MSR command consists of two bytes - an ASCII escape byte (MSR_ESC) and the command byte.

◆ msr_end_t

typedef struct msr_end msr_end_t

Represents the end of a read/write command.

Note
Currently unused.

◆ msr_lz_t

typedef struct msr_lz msr_lz_t

Represents leading zero counts on a card.

◆ msr_model_t

typedef struct msr_model msr_model_t

Represents the MSR's model.

Note
Currently unused.

◆ msr_track_t

typedef struct msr_track msr_track_t

Represents a single track on a magnetic card.

◆ msr_tracks_t

typedef struct msr_tracks msr_tracks_t

Represents all tracks on a magnetic card.

Function Documentation

◆ msr_commtest()

int msr_commtest ( int  fd)

Perform a communications test.

This function issues an MSR_CMD_DIAG_COMM command to the device to perform a communications diagnostic test. After issuing this command, the device will respond with an MSR_STS_COMM_OK byte if the test passes.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_SERIAL on serial I/O failure.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_erase()

int msr_erase ( int  fd,
uint8_t  tracks 
)

Erase one or more tracks on a card.

This routine issues an MSR_CMD_ERASE command to the device to read erase a magstripe card. After the command is issued, the user must swipe a card through the MSR206. The function will block until the device returns a response code indicating that the erase operation completed successfully.

This function can erase various combinations of tracks, or erase all of them, depending on the tracks value specified:

MSR_ERASE_TK1 erase track 1 only

MSR_ERASE_TK2 erase track 2 only

MSR_ERASE_TK3 erase track 3 only

MSR_ERASE_TK1_TK2 erase tracks 1 and 2

MSR_ERASE_TK1_TK3 erase tracks 1 and 3

MSR_ERASE_TK2_TK3 erase tracks 2 and 3

MSR_ERASE_ALL erase all tracks

Parameters
fdThe device's fd.
tracksThe tracks to delete.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_flash_led()

int msr_flash_led ( int  fd,
uint8_t  led 
)

Toggle the LEDs on the MSR device.

This function is used to manually control the LEDs on the MSR206. The device has one green, one yellow and one red LED mounted in it. A given LED is controlled by specifying led as follows:

MSR_CMD_LED_GRN_ON - turn on green LED

MSR_CMD_LED_YLW_ON - turn on yellow LED

MSR_CMD_LED_RED_ON - turn on red LED

MSR_CMD_LED_OFF - turn all LEDs off

After an LED control command is issued to the device, the routine will pause for a tenth of a second to allow time for the command to be processed and the LED to light up.

Parameters
fdThe device's fd.
ledThe LED to control.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_SERIAL | LIBMSR_ERR_DEVICE on error.

◆ msr_fwrev()

int msr_fwrev ( int  fd,
uint8_t *  buf 
)

Check the device's firmware revision.

This function issues an MSR_CMD_FWREV command to the device to retrieve its firmware revision code. The revision is saved in the supplied buffer, which must be at least 9 bytes.

Parameters
fdThe device's fd.
bufThe buffer to write the revision to.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_SERIAL on serial I/O failure.

◆ msr_get_co()

int msr_get_co ( int  fd)

Get the device's coercivity level.

This function issues an MSR_CMD_GETCO command to retrieve the device's current coercivity setting, which is either MSR_CO_HI ('H') or MSR_CO_LO ('L').

Parameters
fdThe device's fd.
Returns
MSR_CO_HI if the device is in hi-co mode.
MSR_CO_LO if the device is in lo-co mode.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_init()

int msr_init ( int  fd)

Initialize the MSR device.

This function issues a reset command to the MSR206 device, and then performs a communications diagnostic test. If the test succeeds, another reset is issued to ready the device for a read or write operation. Typically, msr_init() must be called before any significant operation, including reading and writing cards.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_iso_read()

int msr_iso_read ( int  fd,
msr_tracks_t tracks 
)

Read an ISO formatted card.

This routine issues an MSR_CMD_READ command to the device to read an ISO formatted magstripe card. After the command is issued, the user must swipe a card through the MSR206. The function will block until the card is read and the MSR206 is ready to return data from the tracks. The caller must allocate a pointer to an msr_tracks_t structure and supply a pointer to this structure via the tracks argument.

Parameters
fdThe device's fd.
tracksA pointer to the msr_tracks_t to populate.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_SERIAL on serial I/O failure.

◆ msr_iso_write()

int msr_iso_write ( int  fd,
msr_tracks_t tracks 
)

Write an ISO formatted card.

This routine issues an MSR_CMD_WRITE command to the device to write to an ISO formatted magstripe card. The card does not need to be erased (any existing data is overwritten). The caller must allocate an msr_tracks_t structure and populate it with the data to be written to the card, then supply a pointer to this structure via the tracks argument. The data in the tracks must meet the ISO requirements.

After the write command is issued and the track data is written to the device, the function will block until a status code is read from the device.

Parameters
fdThe device's fd.
tracksA pointer to the msr_tracks_t data to write.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_model()

int msr_model ( int  fd,
uint8_t *  buf 
)

Check the device's model.

This function issues an MSR_CMD_MODEL command to the device to retrieve its model code. The model code is saved in the supplied buffer, which must be at least 10 bytes.

Parameters
fdThe device's fd.
bufThe buffer to write the model to.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_pretty_output_bits()

void msr_pretty_output_bits ( int  fd,
msr_tracks_t  tracks 
)

Dump a "pretty" binary representation of tracks to a fd.

Parameters
fdThe fd to write to.
tracksThe tracks to dump.

◆ msr_pretty_output_hex()

void msr_pretty_output_hex ( int  fd,
msr_tracks_t  tracks 
)

Dump a "pretty" hexadecimal representation of tracks to a fd.

Parameters
fdThe fd to write to.
tracksThe tracks to dump.

◆ msr_pretty_output_string()

void msr_pretty_output_string ( int  fd,
msr_tracks_t  tracks 
)

Dump a "pretty" string representation of tracks to a fd.

Parameters
fdThe fd to write to.
tracksThe tracks to dump.

◆ msr_pretty_printer_bits()

void msr_pretty_printer_bits ( msr_tracks_t  tracks)

Dump a "pretty" binary representation of tracks to stdout.

Parameters
tracksThe tracks to dump.

◆ msr_pretty_printer_hex()

void msr_pretty_printer_hex ( msr_tracks_t  tracks)

Dump a "pretty" hexadecimal representation of tracks to stdout.

Parameters
tracksThe tracks to dump.

◆ msr_pretty_printer_string()

void msr_pretty_printer_string ( msr_tracks_t  tracks)

Dump a "pretty" string representation of tracks to stdout.

Parameters
tracksThe tracks to dump.

◆ msr_ram_test()

int msr_ram_test ( int  fd)

Check the device's RAM.

This function issues an MSR_CMD_DIAG_RAM command to perform a diagnostic sense on the MSR206's internal RAM. If the RAM checks good, the device will return a status code of MSR_STS_RAM_OK.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_raw_read()

int msr_raw_read ( int  fd,
msr_tracks_t tracks 
)

Read raw data from a card.

This routine issues an MSR_CMD_RAW_READ command to the device to read arbitrary data from 3 tracks on a magstripe card. After the command is issued, the user must swipe a card through the MSR206. The function will block until the card is read and the MSR206 is ready to return data from the tracks. The caller must allocate a pointer to an msr_tracks_t structure and supply a pointer to this structure via the tracks argument.

Unlike the msr_iso_read() function, this routine bypasses the MSR206's internal data parser and returns data representing the raw bit pattern on the magnetic media. It is up to the caller to decode this data into a useful form.

Parameters
fdThe device's fd.
tracksA pointer to the msr_tracks_t to populate.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_raw_write()

int msr_raw_write ( int  fd,
msr_tracks_t tracks 
)

Write raw data to a card.

This routine issues an MSR_CMD_RAW_WRITE command to the device to write arbitrary data to a magstripe card. The card does not need to be erased (any existing data is overwritten). The caller must allocate an msr_tracks_t structure and populate it with the data to be written to the card, then supply a pointer to this structure via the tracks argument. The data can be in any format.

After the write command is issued and the track data is written to the device, the function will block until a status code is read from the device.

Unlike the msr_iso_write() routine, this function bypasses the MSR206's internal parser and writes the bit pattern represented by the track data unmodified to the card. It's up to the caller to format the data in a meaningful way.

Parameters
fdThe device's fd.
tracksA pointer to the msr_tracks_t data to write.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_reset()

int msr_reset ( int  fd)

Reset the MSR device.

This function issues an MSR_CMD_RESET command to reset the device. This command does not return a status code. The routine pauses for a tenth of a second to wait for the reset to complete.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK.

◆ msr_reverse_byte()

const unsigned char msr_reverse_byte ( const unsigned char  byte)

Reverse a single byte.

Parameters
byteThe byte to reverse.
Returns
The reversed byte.

◆ msr_reverse_track()

int msr_reverse_track ( msr_track_t track)

Reverse a msr_track_t structure in-place.

Parameters
trackA point to the msr_track_t to reverse.
Returns
LIBMSR_ERR_OK

◆ msr_reverse_tracks()

int msr_reverse_tracks ( msr_tracks_t tracks)

Reverse a msr_tracks_t structure in-place.

Parameters
tracksA pointer to the msr_tracks_t to reverse.
Returns
LIBMSR_ERR_OK

◆ msr_sensor_test()

int msr_sensor_test ( int  fd)

Check the device's sensor.

This function issues an MSR_CMD_DIAG_SENSOR command to perform a diagnostic sense on the mechanical card sensor in the MSR206. After issuing the command, the user is instructed to slide a card through the reader. No actual read is performed, however the hardware tests to verify that the card sensor registers the presence of the card in the track. If the card registers correctly, the device will return a status code of MSR_STS_SENSOR_OK.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_serial_close()

int msr_serial_close ( int  fd)

Close a serial connection to the MSR device.

Parameters
fdThe file descriptor to close.
Returns
LIBMSR_ERR_OK

◆ msr_serial_open()

int msr_serial_open ( char *  path,
int *  fd,
int  blocking,
speed_t  baud 
)

Open a serial connection to the MSR device.

Parameters
pathThe path to the serial device.
fdThe int pointer to store the file descriptor in.
blockingThe blocking flag (e.g., MSR_BLOCKING)
baudThe baud rate of the serial device (e.g., MSR_BAUD)
Returns
LIBMSR_ERR_OK on success
LIBMSR_ERR_SERIAL on failure

◆ msr_serial_read()

int msr_serial_read ( int  fd,
void *  buf,
size_t  len 
)

Read a series of bytes from the MSR device.

Parameters
fdThe file descriptor to read from.
bufThe buffer to read into.
lenThe length of the buffer.
Returns
LIBMSR_ERR_OK

◆ msr_serial_readchar()

int msr_serial_readchar ( int  fd,
uint8_t *  c 
)

Read a single character from the MSR device.

Parameters
fdThe file descriptor to read from.
cA pointer to write the character into.
Returns
The character read

◆ msr_serial_write()

int msr_serial_write ( int  fd,
void *  buf,
size_t  len 
)

Write a series of bytes to the MSR device.

Parameters
fdThe file descriptor to write to.
bufThe buffer to write.
lenThe length of the buffer.
Returns
The number of bytes written, or -1 on error.

◆ msr_set_bpc()

int msr_set_bpc ( int  fd,
uint8_t  bpc1,
uint8_t  bpc2,
uint8_t  bpc3 
)

Set the MSR device's BPC value for each track.

This function issues an MSR_CMD_SETBPC command to bits per character configuration for all 3 tracks. (This command has no effect for other tracks.) It is assumed that this command only has meaning when using ISO read or write commands. The MSR206 supports writing data with BPC values from 5 to 8.

Parameters
fdThe device's fd.
bpc1The new BPC value for track 1.
bpc2The new BPC value for track 2.
bpc3The new BPC value for track 3.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_set_bpi()

int msr_set_bpi ( int  fd,
uint8_t  bpi 
)

Set the MSR device's BPI value.

This function issues an MSR_CMD_SETBPI command to set the bits per inch configuration for track 2. (This command has no effect for other tracks.) It is assumed that this command only has meaning when writing data. The MSR206 supports writing data on track 2 with bpi values. Valid options are either 75 or 210 bits per inch.

Parameters
fdThe device's fd.
bpiThe new BPI value.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_set_hi_co()

int msr_set_hi_co ( int  fd)

Set the device's coercivity to high.

This function issues an MSR_CMD_SETCO_HI command to switch the device to high coercivity mode. It is unclear if this affects both the read and write operations, though presumably it only affects writes by channeling more power to the write head so that it can update high-coercivity media.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_set_lo_co()

int msr_set_lo_co ( int  fd)

Set the device's coercivity to low.

This function issues an MSR_CMD_SETCO_LO command to switch the device to low coercivity mode. It is unclear if this affects both the read and write operations, though presumably it only affects writes by channeling less power to the write head so that it can update low-coercivity media.

Parameters
fdThe device's fd.
Returns
LIBMSR_ERR_OK on success.
LIBMSR_ERR_DEVICE on device failure.

◆ msr_zeros()

int msr_zeros ( int  fd,
msr_lz_t lz 
)

Get the MSR device's current leading-zero setting.

The leading-zero setting is used by the device to determine how many leading zeros to write when writing ISO-formatted tracks. There are two values to the setting: one for tracks 1 and 3, and one for track 2.

Parameters
fdThe device's fd.
lzA pointer to the msr_lz_t to populate.
Returns
LIBMSR_ERR_OK