view calypso/caltest.c @ 78:f6d5cff989d6

fc-uicc-tool batch stdin mode implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 09 Apr 2021 02:47:21 +0000
parents 0a21a7ffe144
children
line wrap: on
line source

#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int target_fd;

open_serial_port(ttyport)
	char *ttyport;
{
	target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
	if (target_fd < 0) {
		perror(ttyport);
		exit(1);
	}
	ioctl(target_fd, TIOCEXCL);
	return 0;
}

set_termios()
{
	struct termios target_termios;

	target_termios.c_iflag = IGNBRK;
	target_termios.c_oflag = 0;
	target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
	target_termios.c_lflag = 0;
	target_termios.c_cc[VMIN] = 1;
	target_termios.c_cc[VTIME] = 0;
	cfsetispeed(&target_termios, B115200);
	cfsetospeed(&target_termios, B115200);
	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
		perror("tcsetattr");
		exit(1);
	}
	return 0;
}

main(argc, argv)
	char **argv;
{
	char c_arg[16];

	if (argc != 3) {
		fprintf(stderr, "usage: %s ttyport second-prog\n", argv[0]);
		exit(1);
	}
	open_serial_port(argv[1]);
	set_termios();
	sprintf(c_arg, "-C%d", target_fd);
	execl(argv[2], argv[2], c_arg, (char *) 0);
	perror(argv[2]);
	exit(1);
}