77 lines
1.3 KiB
C
77 lines
1.3 KiB
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stropts.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <fcntl.h>
|
||
|
|
||
|
#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 <command>\n\n"
|
||
|
" command: set-mode <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;
|
||
|
}
|