#include #include #include #include #ifndef N_TTY #define N_TTY 0 #endif #ifndef N_TIHTC #define N_TIHTC 17 #endif /* stolen from HCIUART set/get protocol ioctls */ #define TIHTCSETCHAN _IOW('U', 200, int) #define TIHTCGETCHAN _IOR('U', 201, int) int main(int argc, char *argv[]) { int fd, ldisc, channel = 0; if (argc < 2) { printf("Usage: %s \n", argv[0]); return -1; } fd = open(argv[1], O_RDONLY); if (fd < 0) { printf("Can't open %s\n", argv[1]); return -1; } /* Set TTY to N_TIHTC line discipline */ ldisc = N_TIHTC; if (ioctl (fd, TIOCSETD, &ldisc) < 0) { perror("Can't set line discipline"); return -1; } /* Set DEBUG channel */ channel = 0x12; if (ioctl(fd, TIHTCSETCHAN, channel) < 0) { perror("Can't set channel"); return -1; } while (1) { char buf[1024]; int n; n = read(fd, buf, 2048); if (n < 0) { perror("Read error\n"); break; } buf[n] = '\0'; if (n>0) { while (--n) if (buf[n] == '\r') buf[n] = '\n'; printf("%s", buf); fflush(stdout); } } close(fd); return 0; }