usb_modeswitch ver. 2.4.0 with data package 2016-06-12
[tomato.git] / release / src / router / usbmodeswitch / usb_modeswitch.h
blobf40796f3691ba02516b9c63c1261b2c14edf5333
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.4.0, 2016/06/12
6 Copyright (C) 2007 - 2016 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, unsigned char *message, int length);
50 int read_bulk(int endpoint, unsigned 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_config_value();
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, unsigned char *buffer, int len);
61 void printVersion();
62 void printHelp();
63 void close_all();
64 void abortExit();
65 int readArguments(int argc, char **argv);
66 void deviceDescription();
67 void resetUSB();
68 void release_usb_device(int dummy);
69 int findMBIMConfig(int vendor, int product, int mode);
72 // Boolean
73 #define and &&
74 #define or ||
75 #define not !
77 // Bitwise
78 #define bitand &
79 #define bitor |
80 #define compl ~
81 #define xor ^
83 // Equals
84 #define and_eq &=
85 #define not_eq !=
86 #define or_eq |=
87 #define xor_eq ^=
89 extern char* ReadParseParam(const char* FileName, char *VariableName);
91 extern char *TempPP;
93 #define ParseParamString(ParamFileName, Str) \
94 if ((TempPP=ReadParseParam((ParamFileName), #Str))!=NULL) \
95 strcpy(Str, TempPP); else Str[0]='\0'
97 #define ParseParamInt(ParamFileName, Int) \
98 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
99 Int=atoi(TempPP)
101 #define ParseParamHex(ParamFileName, Int) \
102 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
103 Int=strtol(TempPP, NULL, 16)
105 #define ParseParamFloat(ParamFileName, Flt) \
106 if ((TempPP=ReadParseParam((ParamFileName), #Flt))!=NULL) \
107 Flt=atof(TempPP)
109 #define ParseParamBool(ParamFileName, B) \
110 if ((TempPP=ReadParseParam((ParamFileName), #B))!=NULL) \
111 B=(toupper(TempPP[0])=='Y' || toupper(TempPP[0])=='T'|| TempPP[0]=='1'); else B=0
113 #define ParseParamBoolMap(ParamFileName, B, M, Const) \
114 if ((TempPP=ReadParseParam((ParamFileName), #B))!=NULL) \
115 if (toupper(TempPP[0])=='Y' || toupper(TempPP[0])=='T'|| TempPP[0]=='1') \
116 M=M+Const