usb_modeswitch: ver 2.2.5 with data package 2015-06-27
[tomato.git] / release / src / router / usbmodeswitch / usb_modeswitch.h
blob1c28ef9df644bc571609e6104af8bc282c844b8d
1 /*
2 This file is part of usb_modeswitch, a mode switching tool for controlling
3 the mode of 'multi-state' USB devices
5 Version 2.2.5, 2015/07/16
6 Copyright (C) 2007 - 2015 Josua Dietze
8 Config file parsing stuff borrowed from Guillaume Dargaud
9 (http://www.gdargaud.net/Hack/SourceCode.html)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details:
21 http://www.gnu.org/licenses/gpl.txt
25 #include <stdlib.h>
26 #include <libusb.h>
28 void readConfigFile(const char *configFilename);
29 void printConfig();
30 int switchSendMessage();
31 int switchConfiguration();
32 int switchAltSetting();
33 void switchHuaweiMode();
35 void switchSierraMode();
36 void switchGCTMode();
37 void switchKobilMode();
38 void switchQisdaMode();
39 void switchQuantaMode();
40 void switchSequansMode();
41 void switchActionMode();
42 void switchBlackberryMode();
43 void switchPantechMode();
44 void switchCiscoMode();
45 int switchSonyMode();
46 int detachDriver();
47 int checkSuccess();
48 int sendMessage(char* message, int count);
49 int write_bulk(int endpoint, char *message, int length);
50 int read_bulk(int endpoint, char *buffer, int length);
51 void release_usb_device(int dummy);
52 struct libusb_device* search_devices( int *numFound, int vendor, char* productList,
53 int targetClass, int configuration, int mode);
54 int find_first_bulk_endpoint(int direction);
55 int get_current_configuration();
56 int get_interface_class();
57 char* ReadParseParam(const char* FileName, char *VariableName);
58 int hex2num(char c);
59 int hex2byte(const char *hex);
60 int hexstr2bin(const char *hex, char *buffer, int len);
61 void printVersion();
62 void printHelp();
63 void close_all();
64 void abort();
65 int readArguments(int argc, char **argv);
66 void deviceDescription();
67 int deviceInquire();
68 void resetUSB();
69 void release_usb_device(int dummy);
70 int findMBIMConfig(int vendor, int product, int mode);
73 // Boolean
74 #define and &&
75 #define or ||
76 #define not !
78 // Bitwise
79 #define bitand &
80 #define bitor |
81 #define compl ~
82 #define xor ^
84 // Equals
85 #define and_eq &=
86 #define not_eq !=
87 #define or_eq |=
88 #define xor_eq ^=
90 extern char* ReadParseParam(const char* FileName, char *VariableName);
92 extern char *TempPP;
94 #define ParseParamString(ParamFileName, Str) \
95 if ((TempPP=ReadParseParam((ParamFileName), #Str))!=NULL) \
96 strcpy(Str, TempPP); else Str[0]='\0'
98 #define ParseParamInt(ParamFileName, Int) \
99 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
100 Int=atoi(TempPP)
102 #define ParseParamHex(ParamFileName, Int) \
103 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
104 Int=strtol(TempPP, NULL, 16)
106 #define ParseParamFloat(ParamFileName, Flt) \
107 if ((TempPP=ReadParseParam((ParamFileName), #Flt))!=NULL) \
108 Flt=atof(TempPP)
110 #define ParseParamBool(ParamFileName, B) \
111 if ((TempPP=ReadParseParam((ParamFileName), #B))!=NULL) \
112 B=(toupper(TempPP[0])=='Y' || toupper(TempPP[0])=='T'|| TempPP[0]=='1'); else B=0
114 #define ParseParamBoolMap(ParamFileName, B, M, Const) \
115 if ((TempPP=ReadParseParam((ParamFileName), #B))!=NULL) \
116 if (toupper(TempPP[0])=='Y' || toupper(TempPP[0])=='T'|| TempPP[0]=='1') \
117 M=M+Const