2 * Copyright (C) 2016 Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, visit the http://fsf.org website.
23 #include <sys/ioctl.h>
30 #define PREFIX "/sys/class/android_usb/android0/"
32 int do_write(char *fname, char *text)
35 fd = open(fname, O_WRONLY);
36 write(fd, text, strlen(text));
41 int do_read(char *fname, char *buffer, size_t len)
45 fd = open(fname, O_RDONLY);
46 r = read(fd, buffer, len);
51 int main(int argc, char **argv)
59 fprintf(stderr, "failed to mount devtmpfs, proceeding anyway\n");
61 r = sysfsmount_setup();
63 fprintf(stderr, "failed to mount sysfs, proceeding anyway\n");
65 do_write(PREFIX "/enable", "0");
66 do_write(PREFIX "/idVendor", "04E8");
67 do_write(PREFIX "/idProduct", "6860");
68 do_write(PREFIX "/f_acm/acm_transports", "tty");
69 do_write(PREFIX "/functions", "acm");
70 do_write(PREFIX "/enable", "1");
71 while (do_read("/sys/class/tty/ttyGS0/dev", dev, sizeof(dev)) < 0) {
74 sscanf(dev, "%d:%d", &maj, &min);
75 mknod("/dev/ttyGS0", 0666 | S_IFCHR, makedev(maj, min));
76 fd = open("/dev/ttyGS0", O_RDWR);
78 write(fd, "Hello World!\n", 13);