3 /// USB Blackberry detection routines
7 Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_PROBE_H__
23 #define __BARRY_PROBE_H__
36 struct BXEXPORT ProbeResult
41 unsigned char m_interface
;
42 unsigned char m_altsetting
;
44 Usb::EndpointPair m_ep
;
45 Usb::EndpointPair m_epModem
;
46 // Specifies if it's necessary to clear halt on the
47 // endpoints before using them. On some devices such
48 // as the 8830 it's essential to clear halt. On other
49 // devices such as the Curve 8520 calling clear halt
50 // can cause them to get into a state where they drop
53 // Specifies if it's necessary to call usb_set_altinterface()
54 // before attempting to use the end points for this device.
56 // This can help to re-synchronize the state between the USB
57 // host and the device. However it can also cause usb-storage
58 // URBs to be lost on some device, so it's only used as a
60 bool m_needSetAltInterface
;
61 uint8_t m_zeroSocketSequence
;
62 std::string m_description
;
64 // data from a possible ConfigFile (filled in automatically by
65 // the probe code if available)
66 std::string m_cfgDeviceName
;
69 // All ProbeResult objects should come from Probe, therefore
70 // this constructor is private to force the issue.
72 : m_dev(0), m_interface(0), m_pin(0)
73 , m_needClearHalt(false), m_needSetAltInterface(false)
74 , m_zeroSocketSequence(0)
78 void DumpAll(std::ostream
&os
) const;
79 bool HasIpModem() const { return m_epModem
.IsComplete(); }
81 bool operator==(const Barry::Pin
&pin
) const
87 BXEXPORT
std::ostream
& operator<< (std::ostream
&os
, const ProbeResult
&pr
);
93 typedef std::vector
<ProbeResult
> Results
;
96 Usb::DeviceList m_devices
;
99 std::vector
<std::string
> m_fail_msgs
;
103 Usb::EndpointPair m_epp
;
105 BXLOCAL
bool CheckSize(const Data
&data
, unsigned int required
);
106 BXLOCAL
bool ParsePIN(const Data
&data
, uint32_t &pin
);
107 BXLOCAL
bool ParseDesc(const Data
&data
, std::string
&desc
);
110 void ProbeMatching(int vendor
, int product
,
111 const char *busname
, const char *devname
);
112 void ProbeDevice(Usb::DeviceID
& devid
);
113 void ProbeDeviceEndpoints(Usb::Device
&dev
, Usb::EndpointPairings
&ed
, ProbeResult
&result
);
114 bool ProbePair(Usb::Device
&dev
, const Usb::EndpointPair
&ep
,
115 uint32_t &pin
, std::string
&desc
, uint8_t &zeroSocketSequence
,
116 bool &needClearHalt
);
117 bool ProbeModem(Usb::Device
&dev
, const Usb::EndpointPair
&ep
);
120 Probe(const char *busname
= 0, const char *devname
= 0,
121 const Usb::EndpointPair
*epp
= 0);
123 const Results
& GetResults() const { return m_results
; }
125 int GetCount() const { return m_results
.size(); }
126 int GetFailCount() const { return m_fail_count
; }
128 const std::string
& GetFailMsg(int index
) const { return m_fail_msgs
.at(index
); }
129 const ProbeResult
& Get(int index
) const { return m_results
.at(index
); }
131 int FindActive(Barry::Pin pin
= 0) const; // returns -1 if pin not found
133 static int FindActive(const Results
&results
, Barry::Pin pin
= 0);
134 static int Find(const Results
&results
, Barry::Pin pin
= 0);