changeset 53:fbedb67d234f

serial: fix parity for inverse coding convention Important note: it is my (Mother Mychaela's) understanding that SIM cards with inverse coding convention are extremely rare, and I have never seen such a card. Therefore, our support for the inverse coding convention will likely remain forever untested.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Mar 2021 20:46:09 +0000
parents 0fec41a10131
children 812779459ddd
files serial/atrmain.c serial/main.c serial/serport.c serial/spenh.c
diffstat 4 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/serial/atrmain.c	Sun Mar 21 19:38:27 2021 +0000
+++ b/serial/atrmain.c	Sun Mar 21 20:46:09 2021 +0000
@@ -18,7 +18,7 @@
 	}
 	open_serial_port(argv[1]);
 	parse_baud_spenh_arg(argv[2]);
-	set_serial_params(baud_base);
+	set_serial_params(baud_base, -1);
 	set_serial_nonblock(0);
 	serial_card_reset();
 	rc = collect_atr();
--- a/serial/main.c	Sun Mar 21 19:38:27 2021 +0000
+++ b/serial/main.c	Sun Mar 21 20:46:09 2021 +0000
@@ -6,6 +6,7 @@
 #include <stdlib.h>
 
 extern unsigned baud_base, baud_spenh;
+extern int inverse_coding;
 
 main(argc, argv)
 	char **argv;
@@ -20,13 +21,14 @@
 	}
 	open_serial_port(argv[1]);
 	parse_baud_spenh_arg(argv[2]);
-	set_serial_params(baud_base);
+	set_serial_params(baud_base, -1);
 	set_serial_nonblock(0);
 	serial_card_reset();
 	rc = collect_atr();
 	if (rc < 0)
 		exit(1);
 	print_atr("A");
+	set_serial_params(baud_base, inverse_coding);
 	if (baud_spenh)
 		spenh_logic();
 	putchar('\n');
--- a/serial/serport.c	Sun Mar 21 19:38:27 2021 +0000
+++ b/serial/serport.c	Sun Mar 21 20:46:09 2021 +0000
@@ -29,18 +29,20 @@
 	return 0;
 }
 
-set_serial_params(br)
+set_serial_params(bps, parity)
 {
 	struct termios2 target_termios;
 
-	target_termios.c_iflag = IGNBRK;
+	target_termios.c_iflag = IGNBRK|IGNPAR;
 	target_termios.c_oflag = 0;
 	target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8|CSTOPB|PARENB;
+	if (parity == 1)
+		target_termios.c_cflag |= PARODD;
 	target_termios.c_lflag = 0;
 	target_termios.c_cc[VMIN] = 1;
 	target_termios.c_cc[VTIME] = 0;
-	target_termios.c_ispeed = br;
-	target_termios.c_ospeed = br;
+	target_termios.c_ispeed = bps;
+	target_termios.c_ospeed = bps;
 	if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) {
 		perror("TCSETSF2");
 		exit(1);
--- a/serial/spenh.c	Sun Mar 21 19:38:27 2021 +0000
+++ b/serial/spenh.c	Sun Mar 21 20:46:09 2021 +0000
@@ -9,6 +9,7 @@
 
 extern u_char atr_buf[];
 extern unsigned baud_spenh, spenh_host_max;
+extern int inverse_coding;
 
 void
 spenh_logic()
@@ -67,6 +68,6 @@
 		fprintf(stderr, "error: PTS response does not match request\n");
 		exit(1);
 	}
-	set_serial_params(baud_spenh * use_spenh);
+	set_serial_params(baud_spenh * use_spenh, inverse_coding);
 	printf("X Using F=512 D=%u speed enhancement\n", use_spenh * 8);
 }