usb-modeswitch version 1.1.2 update
[tomato.git] / release / src / router / usbmodeswitch / usb_modeswitch.h
blob34ad0cb58df1549f2e32ba32d839441f09e9f004
1 /*
2 This file is part of usb-modeswitch, a mode switching tool for controlling
3 flip flop (multiple device) USB gear
5 Version 1.1.2, 2010/04/18
6 Copyright (C) 2007, 2008, 2009, 2010 Josua Dietze
9 Created with help from usbsnoop2libusb.pl (http://iki.fi/lindi/usb/usbsnoop2libusb.pl)
11 Config file parsing stuff borrowed from Guillaume Dargaud
12 (http://www.gdargaud.net/Hack/SourceCode.html)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details:
24 http://www.gnu.org/licenses/gpl.txt
29 #include <stdlib.h>
30 #include <usb.h>
32 void readConfigFile(const char *configFilename);
33 void printConfig();
34 int switchSendMessage();
35 int switchConfiguration();
36 int switchAltSetting();
37 void switchHuaweiMode();
38 void switchSierraMode();
39 void switchGCTMode();
40 void switchAVMMode();
41 int switchSonyMode();
42 int detachDriver();
43 int checkSuccess();
44 int sendMessage(char* message, int count);
45 int write_bulk(int endpoint, char *message, int length);
46 int read_bulk(int endpoint, char *buffer, int length);
47 void release_usb_device(int dummy);
48 struct usb_device* search_devices( int *numFound, int vendor, int product, char* productList, int targetClass, int mode);
49 int find_first_bulk_output_endpoint(struct usb_device *dev);
50 int find_first_bulk_input_endpoint(struct usb_device *dev);
51 char* ReadParseParam(const char* FileName, char *VariableName);
52 int hex2num(char c);
53 int hex2byte(const char *hex);
54 int hexstr2bin(const char *hex, char *buffer, int len);
55 void printVersion();
56 int readArguments(int argc, char **argv);
57 void deviceDescription();
58 int deviceInquire();
59 void resetUSB();
60 void release_usb_device(int dummy);
62 // Boolean
63 #define and &&
64 #define or ||
65 #define not !
67 // Bitwise
68 #define bitand &
69 #define bitor |
70 #define compl ~
71 #define xor ^
73 // Equals
74 #define and_eq &=
75 #define not_eq !=
76 #define or_eq |=
77 #define xor_eq ^=
79 extern char* ReadParseParam(const char* FileName, char *VariableName);
81 extern char *TempPP;
83 #define ParseParamString(ParamFileName, Str) \
84 if ((TempPP=ReadParseParam((ParamFileName), #Str))!=NULL) \
85 strcpy(Str, TempPP); else Str[0]='\0'
87 #define ParseParamInt(ParamFileName, Int) \
88 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
89 Int=atoi(TempPP)
91 #define ParseParamHex(ParamFileName, Int) \
92 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
93 Int=strtol(TempPP, NULL, 16)
95 #define ParseParamFloat(ParamFileName, Flt) \
96 if ((TempPP=ReadParseParam((ParamFileName), #Flt))!=NULL) \
97 Flt=atof(TempPP)
99 #define ParseParamBool(ParamFileName, B) \
100 if ((TempPP=ReadParseParam((ParamFileName), #B))!=NULL) \
101 B=(toupper(TempPP[0])=='Y' || toupper(TempPP[0])=='T'|| TempPP[0]=='1'); else B=0