diff --git a/ioc/lw35-tool/main.c b/ioc/lw35-tool/main.c new file mode 100644 index 0000000..be75e45 --- /dev/null +++ b/ioc/lw35-tool/main.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include + +#define IOCTL_SET_MODE 42 +enum lw35ioc_state {PASSIVE = 0, PROG_KBD, PROG_PRI, BYPASS, ACTIVE, STATE_COUNT}; + +int f; + +static void help(int argc, char *argv[]) +{ + fprintf(stderr, + "usage: %s \n\n" + " command: set-mode \n" + " mode: passive, active, rfu-kbd, rfu-pri, bypass\n", + argv[0]); +} + +static int set_mode(int argc, char *argv[]) +{ + int mode = -1; + + if (argc < 3) { + help(argc, argv); + return 10; + } + + if (!strcmp(argv[2], "passive")) + mode = PASSIVE; + else if (!strcmp(argv[2], "rfu-kbd")) + mode = PROG_KBD; + else if (!strcmp(argv[2], "rfu-pri")) + mode = PROG_PRI; + else if (!strcmp(argv[2], "bypass")) + mode = BYPASS; + else if (!strcmp(argv[2], "active")) + mode = ACTIVE; + + if (mode == -1) { + fprintf(stderr, "Error: Invalid mode.\n"); + return 10; + } + + ioctl(f, IOCTL_SET_MODE, mode); + + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret; + + if (argc < 2) { + help(argc, argv); + return 1; + } + + f = open("/dev/lw35", O_RDWR); + if (f == -1) { + fprintf(stderr, "Error opening lw35ioc device.\n"); + return 3; + } + + if (!strcmp(argv[1], "set-mode")) { + ret = set_mode(argc, argv); + } else { + fprintf(stderr, "Unknown command.\n"); + ret = 2; + } + + close(f); + + return ret; +}