modem-modeswitch.c revision 181368a3b26329f77a93b06a5d2b285d4bf5f8e3
/*
* Modem mode switcher
*
* Copyright (C) 2008 Dan Williams <dcbw@redhat.com>
* Copyright (C) 2008 Peter Henn <support@option.com>
*
* Heavily based on the 'ozerocdoff' tool by Peter Henn.
*
* 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:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <stdarg.h>
#include <getopt.h>
#include <usb.h>
#include "utils.h"
#include "ma8280p_us.h"
#include "option.h"
typedef enum {
ST_UNKNOWN = 0,
} SwitchType;
typedef struct SwitchEntry {
const char *clopt;
} SwitchEntry;
static SwitchEntry switch_types[] = {
};
static struct usb_device *
{
struct usb_device *dev;
return dev;
}
}
}
return NULL;
}
static void
release_usb_device (int param)
{
usb_release_interface (handle, 0);
}
static void
print_usage (void)
{
printf ("Usage: modem-modeswitch [-hdq] [-l <file>] -v <vendor-id> -p <product-id> -t <type>\n"
" -h, --help show this help message\n"
" -v, --vendor <n> target USB vendor ID\n"
" -p, --product <n> target USB product ID\n"
" -t, --type <type> type of switch to attempt, varies by device:\n"
" option-zerocd - For many newer Option N.V. devices\n"
" mobile-action-8280p - For Mobile Action 8xxxP USB cables\n"
" -l, --log <file> log output to a file\n"
" -q, --quiet don't print anything to stdout\n"
" -d, --debug display debugging messages\n\n"
"Examples:\n"
" modem-modeswitch -v 0x0af0 -p 0xc031 -t option-zerocd\n");
}
static SwitchEntry *
parse_type (const char *s)
{
return entry;
entry++;
}
return NULL;
}
static void
{
log_shutdown ();
}
{
};
struct usb_device *dev;
char buffer[256];
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'v':
break;
case 'p':
break;
case 't':
if (!sentry) {
print_usage ();
exit (1);
}
break;
case 'l':
break;
case 'q':
quiet = 1;
break;
case 'd':
debug = 1;
break;
case 'h':
default:
print_usage ();
exit (1);
}
}
exit (2);
}
if (!sentry) {
if (!quiet)
print_usage ();
else
error ("missing device switch type.");
do_exit (3);
}
if (!quiet)
print_usage ();
else
error ("missing vendor and device IDs.");
do_exit (3);
}
usb_init();
if (usb_find_busses() < 0) {
error ("no USB busses found.");
do_exit (4);
}
if (usb_find_devices() < 0) {
error ("no USB devices found.");
do_exit (4);
}
else
error ("no device found.");
do_exit (5);
}
error ("%s: could not access the device.",
do_exit (6);
}
/* detach running default driver */
if (ret == 0) {
if (ret != 0) {
do_exit (7);
}
}
if (ret != 0) {
debug ("%s: couldn't claim device's USB interface: %d.",
do_exit (8);
}
if (ret < 0) {
usb_release_interface (handle, 0);
do_exit(9);
}
usb_release_interface (handle, 0);
if (ret < 0)
do_exit (0);
return 0;
}