rendered paste body/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <asm/types.h>#include <sys/signal.h>#include <linux/hiddev.h>#include <sys/ioctl.h>#include <argp.h>#include "config.h"enum Commands { Confirm, EmailOff, EmailOn, EmailPulse, EmailFlash, ImOff, ImOn, ImPulse, ImFlash, None };unsigned char confirm[6] = { 0x01, 0x80, 0x52, 0x00, 0x00, 0x00 };unsigned char email_off[6] = { 0x01, 0x80, 0x52, 0x06, 0x00, 0x00 };unsigned char email_on[6] = { 0x01, 0x80, 0x52, 0x05, 0x00, 0x00 };unsigned char email_pulse[6] = { 0x01, 0x80, 0x52, 0x04, 0x00, 0x00 };unsigned char email_flash[6] = { 0x01, 0x80, 0x52, 0x03, 0x00, 0x00 };unsigned char email_instanton[6] = { 0x01, 0x80, 0x52, 0x02, 0x00, 0x00 };unsigned char email_instantoff[6] = { 0x01, 0x80, 0x52, 0x01, 0x00, 0x00 };unsigned char im_off[6] = { 0x01, 0x80, 0x52, 0x00, 0x06, 0x00 };unsigned char im_on[6] = { 0x01, 0x80, 0x52, 0x00, 0x05, 0x00 };unsigned char im_pulse[6] = { 0x01, 0x80, 0x52, 0x00, 0x04, 0x00 };unsigned char im_flash[6] = { 0x01, 0x80, 0x52, 0x00, 0x03, 0x00 };unsigned char im_instantoff[6] = { 0x01, 0x80, 0x52, 0x00, 0x01, 0x00 };unsigned char im_instanton[6] = { 0x01, 0x80, 0x52, 0x00, 0x02, 0x00 };int do_cmd(char* devnode, enum Commands cmd){ int fd; struct hiddev_usage_ref usage_ref; struct hiddev_report_info rep_info; unsigned int alv; if ((fd = open(devnode, O_RDONLY)) < 0) { perror("hiddev open"); exit(1); } /* Initialise the internal report structures */ if (ioctl(fd, HIDIOCINITREPORT, 0) < 0) { exit(1); } /* transmit */ unsigned char *command; switch (cmd) { case Confirm: command = confirm; break; case EmailOff: command = email_off; break; case EmailOn: command = email_on; break; case EmailFlash: command = email_flash; break; case EmailPulse: command = email_pulse; break; case ImOff: command = im_off; break; case ImOn: command = im_on; break; case ImFlash: command = im_flash; break; case ImPulse: command = im_pulse; break; default: command = confirm; printf("Unhandled value: %i\n", cmd); }; for (alv = 0; alv < 6; ++alv) { usage_ref.report_type = HID_REPORT_TYPE_OUTPUT; usage_ref.report_id = 0x10; usage_ref.field_index = 0; usage_ref.usage_code = 0xff000001; usage_ref.usage_index = alv; usage_ref.value = (unsigned char) command[alv]; int ret = ioctl(fd, HIDIOCSUSAGE, &usage_ref); if ( ret < 0 ) printf("Error (SUSAGE) while talking to the Mouse: %i\n", ret); usage_ref.usage_index++; } rep_info.report_type = HID_REPORT_TYPE_OUTPUT; rep_info.report_id = 0x10; rep_info.num_fields = 1; if (ioctl(fd, HIDIOCSREPORT, &rep_info) < 0) { printf("Error (SREPORT) while talking to the Mouse\n"); return -1; } /* this delay is a bit arbitrary */ usleep(20*1000); return 0;}const char *argp_program_version = PACKAGE_VERSION;const char *argp_program_bug_address = PACKAGE_BUGREPORT;const char args_doc[] = "devicenode";static struct argp_option options[] = { {"email-on", 'e', 0, 0, "This command turns on the email lamp", 0}, {"email-off", 'o', 0, 0, "This command turns off the email lamp", 0}, {"email-pulse", 'p', 0, 0, "This command makes the email lamp pulse", 0}, {"email-flash", 'f', 0, 0, "This command makes the email lamp flash", 0}, {"im-on", 'i', 0, 0, "This command turns on the instant messaging lamp", 0}, {"im-off", 'O', 0, 0, "This command turns on the instant messaging lamp", 0}, {"im-pulse", 'P', 0, 0, "This command makes the instant messaging lamp pulse", 0}, {"im-flash", 'F', 0, 0, "This command makes the instant messaging lamp flash", 0}, {0, 0, 0, 0, 0, 0}};struct arguments{ char *device_node; enum Commands emailCommand; enum Commands imCommand;};static error_tdo_parse (int key, char *arg, struct argp_state *state){ struct arguments *arguments = state->input; switch (key) { case 'e': arguments->emailCommand = EmailOn; break; case 'i': arguments->imCommand = ImOn; break; case 'o': arguments->emailCommand = EmailOff; break; case 'O': arguments->imCommand = ImOff; break; case 'p': arguments->emailCommand = EmailPulse; break; case 'f': arguments->emailCommand = EmailFlash; break; case 'P': arguments->imCommand = ImPulse; break; case 'F': arguments->imCommand = ImFlash; break; case ARGP_KEY_ARG: if (state->arg_num > 1) /* Too many arguments. */ argp_usage (state); arguments->device_node = arg; break; case ARGP_KEY_END: if (state->arg_num < 1) argp_usage (state); break; default: return ARGP_ERR_UNKNOWN; } return 0;}static struct argp argparser = {options, do_parse, args_doc, PACKAGE_STRING " - a utility for MX610 exploration", 0, 0, 0}; int main (int argc, char **argv) { int retval = 0; struct arguments arguments; arguments.device_node = 0; arguments.emailCommand = None; arguments.imCommand = None; argp_parse(&argparser, argc, argv, 0, 0, &arguments); if (arguments.emailCommand != None) { do_cmd(arguments.device_node, arguments.emailCommand); do_cmd(arguments.device_node, Confirm); } if (arguments.imCommand != None) { do_cmd(arguments.device_node, arguments.imCommand); do_cmd(arguments.device_node, Confirm); } fflush(stdout); exit(retval);}