usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / usbmodeswitch / usb_modeswitch.h
blobb0363f5c7e5e321958d30fbdba621d953af027d6
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.2.6, 2013/06/02
6 Copyright (C) 2007 - 2013 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
26 #include <stdlib.h>
27 #include <libusb.h>
29 void readConfigFile(const char *configFilename);
30 void printConfig();
31 int switchSendMessage();
32 int switchConfiguration();
33 int switchAltSetting();
34 void switchHuaweiMode();
35 void switchSierraMode();
36 void switchGCTMode();
37 int switchKobilMode();
38 int switchQisdaMode();
39 void switchQuantaMode();
40 int switchSequansMode();
41 int switchActionMode();
42 int switchSonyMode();
43 int switchCiscoMode();
44 int detachDriver();
45 int checkSuccess();
46 int sendMessage(char* message, int count);
47 int write_bulk(int endpoint, char *message, int length);
48 int read_bulk(int endpoint, char *buffer, int length);
49 void release_usb_device(int dummy);
50 struct libusb_device* search_devices( int *numFound, int vendor, int product, char* productList,
51 int targetClass, int configuration, int mode);
52 int find_first_bulk_output_endpoint(struct libusb_device *dev);
53 int find_first_bulk_input_endpoint(struct libusb_device *dev);
54 int get_current_configuration(struct libusb_device_handle* devh);
55 int get_interface_class(struct libusb_config_descriptor *cfg, int ifcNumber);
56 char* ReadParseParam(const char* FileName, char *VariableName);
57 int hex2num(char c);
58 int hex2byte(const char *hex);
59 int hexstr2bin(const char *hex, char *buffer, int len);
60 void printVersion();
61 void printHelp();
62 int readArguments(int argc, char **argv);
63 void deviceDescription();
64 int deviceInquire();
65 void resetUSB();
66 void release_usb_device(int dummy);
67 int findMBIMConfig(int vendor, int product, int mode);
70 // Boolean
71 #define and &&
72 #define or ||
73 #define not !
75 // Bitwise
76 #define bitand &
77 #define bitor |
78 #define compl ~
79 #define xor ^
81 // Equals
82 #define and_eq &=
83 #define not_eq !=
84 #define or_eq |=
85 #define xor_eq ^=
87 extern char* ReadParseParam(const char* FileName, char *VariableName);
89 extern char *TempPP;
91 #define ParseParamString(ParamFileName, Str) \
92 if ((TempPP=ReadParseParam((ParamFileName), #Str))!=NULL) \
93 strcpy(Str, TempPP); else Str[0]='\0'
95 #define ParseParamInt(ParamFileName, Int) \
96 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
97 Int=atoi(TempPP)
99 #define ParseParamHex(ParamFileName, Int) \
100 if ((TempPP=ReadParseParam((ParamFileName), #Int))!=NULL) \
101 Int=strtol(TempPP, NULL, 16)
103 #define ParseParamFloat(ParamFileName, Flt) \
104 if ((TempPP=ReadParseParam((ParamFileName), #Flt))!=NULL) \
105 Flt=atof(TempPP)
107 #define ParseParamBool(ParamFileName, B) \
108 if ((TempPP=ReadParseParam((ParamFileName), #B))!=NULL) \
109 B=(toupper(TempPP[0])=='Y' || toupper(TempPP[0])=='T'|| TempPP[0]=='1'); else B=0