summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/man/msr606.1105
-rw-r--r--bin/msr606.c274
2 files changed, 0 insertions, 379 deletions
diff --git a/bin/man/msr606.1 b/bin/man/msr606.1
deleted file mode 100644
index fc18635b..00000000
--- a/bin/man/msr606.1
+++ /dev/null
@@ -1,105 +0,0 @@
-.Dd November 7, 2018
-.Dt MSR606 1
-.Os "Causal Agency"
-.
-.Sh NAME
-.Nm msr606
-.Nd magnetic stripe card reader/writer
-.
-.Sh SYNOPSIS
-.Nm
-.Op Fl RTWchiltwz
-.Op Fl L Ar led
-.Op Fl Z Ar zero
-.Op Fl b Ar bpc
-.Op Fl e Ar track
-.Op Fl f Ar tty
-.
-.Sh DESCRIPTION
-.Nm
-operates the MSR606 magnetic stripe card reader/writer.
-.
-.Pp
-The arguments are as follows:
-.Bl -tag -width Ds
-.
-.It Fl L Ar led
-Set LEDs.
-The values for
-.Ar led
-are:
-.Sy n
-for none,
-.Sy a
-for all,
-.Sy g
-for green,
-.Sy y
-for yellow,
-.Sy r
-for red.
-.
-.It Fl R
-Read raw data from a card to standard output.
-.
-.It Fl T
-Perform a sensor test.
-.
-.It Fl W
-Write raw data to a card from standard input.
-.
-.It Fl Z Ar zero
-Set leading zero.
-.Ar zero
-is a comma-separated list of two numbers
-indicating the leading zero setting
-for tracks 1 & 3
-and track 2,
-respectively.
-.
-.It Fl b Ar bpc
-Set bits per character for each track.
-.Ar bpc
-is a comma-separated list of 3 numbers
-indicating the BPC for each track.
-Valid values range from 5 to 8.
-.
-.It Fl c
-Print the coercivity status.
-.
-.It Fl e Ar track
-Erase a card.
-.Ar track
-is a number from 1 to 7
-representing a 3-bit set
-of tracks to erase.
-.
-.It Fl f Ar tty
-Open the device
-.Ar tty .
-The default device is
-.Pa /dev/ttyUSB0 .
-.
-.It Fl h
-Set high coercivity.
-.
-.It Fl i
-Reset the device.
-.
-.It Fl l
-Set low coercivity.
-.
-.It Fl r
-Read ISO format data from card to standard output.
-.
-.It Fl t
-Perform communication and RAM tests.
-Print the hardware model and firmware version.
-This is the default operation.
-.
-.It Fl w
-Write ISO format data to card from standard input.
-.
-.It Fl z
-Print the leading zero setting.
-.El
diff --git a/bin/msr606.c b/bin/msr606.c
deleted file mode 100644
index e7c7e9b0..00000000
--- a/bin/msr606.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/* Copyright (C) 2018  Curtis McEnroe <june@causal.agency>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <err.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sysexits.h>
-#include <termios.h>
-#include <unistd.h>
-
-enum {
-	Esc = 0x1B,
-	FS  = 0x1C,
-};
-
-static const char *path = "/dev/ttyUSB0";
-static FILE *tty;
-
-static char ttyGet(void) {
-	int ch = fgetc(tty);
-	if (ferror(tty)) err(EX_IOERR, "%s", path);
-	if (ch == EOF) errx(EX_PROTOCOL, "unexpected EOF");
-	return ch;
-}
-
-static void ttyPut(char ch) {
-	fputc(ch, tty);
-	if (ferror(tty)) err(EX_IOERR, "%s", path);
-}
-
-static void msrReq(char req) {
-	ttyPut(Esc);
-	ttyPut(req);
-}
-static char msrRes(void) {
-	char esc = ttyGet();
-	if (esc != Esc) errx(EX_PROTOCOL, "response fail %hhX", esc);
-	return ttyGet();
-}
-static char msr(char req) {
-	msrReq(req);
-	return msrRes();
-}
-
-static void msrReset(void) {
-	msrReq('a');
-}
-
-static void msrTest(void) {
-	char test = msr('e');
-	if (test != 'y') errx(EX_PROTOCOL, "test fail %hhX", test);
-
-	char ram = msr(0x87);
-	if (ram != '0') errx(EX_PROTOCOL, "ram fail %hhX", ram);
-
-	msrReq('t');
-	printf("model: %c%c\n", msrRes(), ttyGet());
-
-	printf("firmware: %hhu\n", msr('v'));
-}
-
-static void msrSensorTest(void) {
-	char test = msr(0x86);
-	if (test != '0') errx(EX_PROTOCOL, "sensor fail %hhX", test);
-}
-
-static void msrLED(char led) {
-	switch (led) {
-		break; case 'a': msrReq(0x82);
-		break; case 'g': msrReq(0x83);
-		break; case 'y': msrReq(0x84);
-		break; case 'r': msrReq(0x85);
-		break; default:  msrReq(0x81);
-	}
-}
-
-static void msrSetZero(char track1, char track2) {
-	msrReq('z');
-	ttyPut(track1);
-	ttyPut(track2);
-	char zero = msrRes();
-	if (zero != '0') errx(EX_PROTOCOL, "set leading zero fail %hhX", zero);
-}
-
-static void msrGetZero(void) {
-	char track1 = msr('l');
-	char track2 = ttyGet();
-	printf("leading zero: %hhu,%hhu\n", track1, track2);
-}
-
-static void msrSetBPI(char track1, char track2, char track3) {
-	msrReq('b');
-	switch (track) {
-		break; case 1: ttyPut(bpi == 210 ? 0xA1 : 0xA0);
-		break; case 2: ttyPut(bpi == 210 ? 0xD2 : 0x4B);
-		break; case 3: ttyPut(bpi == 210 ? 0xC1 : 0xC0);
-		break; default: ttyPut(0);
-	}
-	char set = msrRes();
-	if (set != '0') errx(EX_PROTOCOL, "set BPI fail %hhX", set);
-}
-
-static void msrSetBPC(char track1, char track2, char track3) {
-	msrReq('o');
-	ttyPut(track1);
-	ttyPut(track2);
-	ttyPut(track3);
-	char bpc = msrRes();
-	if (bpc != '0') errx(EX_PROTOCOL, "set BPC fail %hhX", bpc);
-	track1 = ttyGet();
-	track2 = ttyGet();
-	track3 = ttyGet();
-	printf("BPC: %hhu,%hhu,%hhu\n", track1, track2, track3);
-}
-
-static void msrHiCo(void) {
-	char co = msr('x');
-	if (co != '0') errx(EX_PROTOCOL, "hi-co fail %hhX", co);
-}
-
-static void msrLoCo(void) {
-	char co = msr('y');
-	if (co != '0') errx(EX_PROTOCOL, "lo-co fail %hhX", co);
-}
-
-static void msrGetCo(void) {
-	char co = msr('d');
-	switch (co) {
-		break; case 'h': printf("hi-co\n");
-		break; case 'l': printf("lo-co\n");
-		break; default:  errx(EX_PROTOCOL, "get co fail %hhX", co);
-	}
-}
-
-static void msrStatus(void) {
-	char status = msrRes();
-	switch (status) {
-		case '0': return;
-		case '1': errx(EX_DATAERR, "read/write error");
-		case '2': errx(EX_DATAERR, "command format error");
-		case '4': errx(EX_DATAERR, "invalid command");
-		case '9': errx(EX_DATAERR, "invalid card swipe");
-		default: errx(EX_PROTOCOL, "status fail %hhX", status);
-	}
-}
-
-static void msrRead(void) {
-	char read = msr('r');
-	if (read != 's') errx(EX_PROTOCOL, "read fail %hhX", read);
-	for (;;) {
-		read = ttyGet();
-		if (read == '?') {
-			read = ttyGet();
-			if (read == FS) break;
-			printf("?");
-		}
-		printf("%c", read);
-	}
-	msrStatus();
-}
-
-static void msrWrite(void) {
-	msrReq('w');
-	msrReq('s');
-	int write;
-	while (EOF != (write = getchar())) {
-		ttyPut(write);
-	}
-	ttyPut('?');
-	ttyPut(FS);
-	msrStatus();
-}
-
-static void msrErase(char track) {
-	msrReq('c');
-	ttyPut(track);
-	char erase = msrRes();
-	if (erase != '0') errx(EX_PROTOCOL, "erase fail %hhX", erase);
-}
-
-static void msrReadRaw(void) {
-	char read = msr('m');
-	if (read != 's') errx(EX_PROTOCOL, "read raw fail %hhX", read);
-	for (;;) {
-		read = ttyGet();
-		if (read == '?') {
-			read = ttyGet();
-			if (read == FS) break;
-			printf("?");
-		}
-		printf("%c", read);
-	}
-	msrStatus();
-}
-
-static void msrWriteRaw(void) {
-	msrReq('n');
-	msrReq('s');
-	int write;
-	while (EOF != (write = getchar())) {
-		ttyPut(write);
-	}
-	ttyPut('?');
-	ttyPut(FS);
-	msrStatus();
-}
-
-static char parse(char **arg) {
-	char n = strtoul(*arg, arg, 0);
-	if ((*arg)[0]) (*arg)++;
-	return n;
-}
-
-int main(int argc, char *argv[]) {
-	char func = 't';
-	char *arg = NULL;
-
-	int opt;
-	while (0 < (opt = getopt(argc, argv, "L:RTWZ:b:cd:e:f:hilrtwz"))) {
-		switch (opt) {
-			break; case 'f': path = optarg;
-			break; case '?': return EX_USAGE;
-			break; default:  func = opt; arg = optarg;
-		}
-	}
-
-	int fd = open(path, O_RDWR);
-	if (fd < 0) err(EX_NOINPUT, "%s", path);
-
-	struct termios attr;
-	int error = tcgetattr(fd, &attr);
-	if (error) err(EX_IOERR, "tcgetattr");
-
-	cfmakeraw(&attr);
-	error = tcsetattr(fd, TCSANOW, &attr);
-	if (error) err(EX_IOERR, "tcsetattr");
-
-	tty = fdopen(fd, "r+");
-	if (!tty) err(EX_IOERR, "fdopen");
-
-	switch (func) {
-		break; case 'L': msrLED(arg[0]);
-		break; case 'R': msrReadRaw();
-		break; case 'T': msrSensorTest();
-		break; case 'W': msrWriteRaw();
-		break; case 'Z': msrSetZero(parse(&arg), parse(&arg));
-		break; case 'b': msrSetBPC(parse(&arg), parse(&arg), parse(&arg));
-		break; case 'c': msrGetCo();
-		break; case 'd': msrSetBPI(parse(&arg), parse(&arg));
-		break; case 'e': msrErase(arg[0] - '0');
-		break; case 'h': msrHiCo();
-		break; case 'i': msrReset();
-		break; case 'l': msrLoCo();
-		break; case 'r': msrRead();
-		break; case 't': msrTest();
-		break; case 'w': msrWrite();
-		break; case 'z': msrGetZero();
-		break; default:  return EX_USAGE;
-	}
-}
8-04-02 23:30:44 +0800'>2018-04-02builtin: Fix echo performance regressionHerbert Xu The commit d6c0e1e2ffbf7913ab69d51cc794d48d41c8fcb1 ("[BUILTIN] Handle embedded NULs correctly in printf") caused a performance regression in the echo built-in because every echo call now goes through the printf %b slow path where the string is always printed twice to ensure the space padding is correct in the presence of NUL characters. In fact this regression applies to printf %b as well. This is easily fixed by making printf %b take the fast path when no precision/field width modifiers are present. This patch also changes the second strchurnul call to strspn which generates slightly better code. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-04-02expand: Fix ghost fields with unquoted $@/$*Herbert Xu Harald van Dijk <harald@gigawatt.nl> wrote: > On 22/03/2018 22:38, Martijn Dekker wrote: >> Op 22-03-18 om 20:28 schreef Harald van Dijk: >>> On 22/03/2018 03:40, Martijn Dekker wrote: >>>> This patch fixes the bug that, given no positional parameters, unquoted >>>> $@ and $* incorrectly generate one empty field (they should generate no >>>> fields). Apparently that was a side effect of the above. >>> >>> This seems weird though. If you want to remove the recording of empty >>> regions because they are pointless, then how does removing them fix a >>> bug? Doesn't this show that empty regions do have an effect? Perhaps >>> they're not supposed to have any effect, perhaps it's a specific >>> combination of empty regions and something else that triggers some bug, >>> and perhaps that combination can no longer occur with your patch. >> >> The latter is my guess, but I haven't had time to investigate it. > > Looking into it again: > > When IFS is set to an empty string, sepc is set to '\0' in varvalue(). > This then causes *quotedp to be set to true, meaning evalvar()'s quoted > variable is turned on. quoted is then passed to recordregion() as the > nulonly parameter. > > ifsp->nulonly has a bigger effect than merely selecting whether to use > $IFS or whether to only split on null bytes: in ifsbreakup(), nulonly > also causes string termination to be suppressed. That's correct: that > special treatment is required to preserve empty fields in "$@" > expansion. But it should *only* be used when $@ is quoted: ifsbreakup() > takes nulonly from the last IFS region, even if it's empty, so having an > additional zero-length region with nulonly enabled causes confusion. > > Passing quoted by value to varvalue() and not attempting to modify it > should therefore, and in my quick testing does, also work to fix the > original $@ bug. You're right. The proper fix to this is to ensure that nulonly is not set in varvalue for $*. It should only be set for $@ when it's inside double quotes. In fact there is another bug while we're playing with $@/$*. When IFS is set to a non-whitespace character such as :, $* outside quotes won't remove empty fields as it should. This patch fixes both problems. Reported-by: Martijn Dekker <martijn@inlv.org> Suggested-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-04-02parser: Allow newlines within parameter substitutionHerbert Xu On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote: > On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote: > > > > Okay, it can be trivially modified to something that does work in other > > shells (even if it were actually executed), but gets rejected at parse time > > by dash: > > > > if false; then > > : ${$+ > > } > > fi > > That's just a bug in dash's parser with ${} in general, because > it bombs out without the if clause too: > > : ${$+ > } This patch fixes the parsing of newlines with parameter substitution. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-04-02expand: Fix bugs with words connected to the right of $@Herbert Xu On Sun, Mar 04, 2018 at 12:44:59PM +0100, Harald van Dijk wrote: > > command: set -- a ""; space=" "; printf "<%s>" "$@"$space > bash: <a><> > dash 0.5.8: <a>< > > dash 0.5.9.1: <a>< > > dash patched: <a><> This is actually composed of two bugs. First of all our tracking of quotemark is wrong so anything after "$@" becomes quoted. Once we fix that then the problem is that the first space character after "$@" is not recognised as an IFS. This patch fixes both. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-03-25Revert "[BUILTIN] Remove unnecessary restoration of format string in printf"Herbert Xu This reverts commit 7bb413255368e94395237d789f522891093c5774. The commit breaks printf with more than argument. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-03-22parser: Fix backquote support in here-document EOF markHerbert Xu