ioc: lw35-tool: Add tool to configure IOC mode
This commit is contained in:
parent
6e1a771862
commit
0da970d40f
76
ioc/lw35-tool/main.c
Normal file
76
ioc/lw35-tool/main.c
Normal file
@ -0,0 +1,76 @@
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user