# probe.h

Go to the documentation of this file.

    00001 ///
    00002 /// \file       probe.h
    00003 ///             USB Blackberry detection routines
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00008
    00009     This program is free software; you can redistribute it and/or modify
    00010     it under the terms of the GNU General Public License as published by
    00011     the Free Software Foundation; either version 2 of the License, or
    00012     (at your option) any later version.
    00013
    00014     This program is distributed in the hope that it will be useful,
    00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00017
    00018     See the GNU General Public License in the COPYING file at the
    00019     root directory of this project for more details.
    00020 */
    00021
    00022 #ifndef __BARRY_PROBE_H__
    00023 #define __BARRY_PROBE_H__
    00024
    00025 #include "dll.h"
    00026 #include "usbwrap.h"
    00027 #include "pin.h"
    00028 #include <vector>
    00029 #include <iosfwd>
    00030 #include <stdint.h>
    00031
    00032 namespace Barry {
    00033
    00034 class Probe;
    00035
    00036 struct BXEXPORT ProbeResult
    00037 {
    00038         friend class Probe;
    00039
    00040         Usb::DeviceIDType m_dev;
    00041         unsigned char m_interface;
    00042         Barry::Pin m_pin;
    00043         Usb::EndpointPair m_ep;
    00044         Usb::EndpointPair m_epModem;
    00045         // Specifies if it's necessary to clear halt on the
    00046         // endpoints before using them. On some devices such
    00047         // as the 8830 it's essential to clear halt. On other
    00048         // devices such as the Curve 8520 calling clear halt
    00049         // can cause them to get into a state where they drop
    00050         // packets.
    00051         bool m_needClearHalt;
    00052         // Specifies if it's necessary to call usb_set_altinterface()
    00053         // before attempting to use the end points for this device.
    00054         //
    00055         // This can help to re-synchronize the state between the USB
    00056         // host and the device. However it can also cause usb-storage
    00057         // URBs to be lost on some device, so it's only used as a
    00058         // last resort.
    00059         bool m_needSetAltInterface;
    00060         uint8_t m_zeroSocketSequence;
    00061         std::string m_description;
    00062
    00063         // data from a possible ConfigFile (filled in automatically by
    00064         // the probe code if available)
    00065         std::string m_cfgDeviceName;
    00066
    00067 private:
    00068         // All ProbeResult objects should come from Probe, therefore
    00069         // this constructor is private to force the issue.
    00070         ProbeResult()
    00071                 : m_dev(0), m_interface(0), m_pin(0)
    00072                 , m_needClearHalt(false), m_needSetAltInterface(false)
    00073                 , m_zeroSocketSequence(0)
    00074                 {}
    00075
    00076 public:
    00077         void DumpAll(std::ostream &os) const;
    00078         bool HasIpModem() const { return m_epModem.IsComplete(); }
    00079
    00080         bool operator==(const Barry::Pin &pin) const
    00081         {
    00082                 return m_pin == pin;
    00083         }
    00084 };
    00085
    00086 BXEXPORT std::ostream& operator<< (std::ostream &os, const ProbeResult &pr);
    00087
    00088
    00089 class BXEXPORT Probe
    00090 {
    00091 public:
    00092         typedef std::vector<ProbeResult>                Results;
    00093
    00094 private:
    00095         Results m_results;
    00096
    00097         std::vector<std::string> m_fail_msgs;
    00098         int m_fail_count;
    00099
    00100         bool m_epp_override;
    00101         Usb::EndpointPair m_epp;
    00102
    00103         BXLOCAL bool CheckSize(const Data &data, unsigned int required);
    00104         BXLOCAL bool ParsePIN(const Data &data, uint32_t &pin);
    00105         BXLOCAL bool ParseDesc(const Data &data, std::string &desc);
    00106
    00107 protected:
    00108         void ProbeMatching(int vendor, int product,
    00109                 const char *busname, const char *devname);
    00110         void ProbeDevice(Usb::DeviceIDType devid);
    00111         void ProbeDeviceEndpoints(Usb::Device &dev, Usb::EndpointDiscovery &ed, ProbeResult &result);
    00112         bool ProbePair(Usb::Device &dev, const Usb::EndpointPair &ep,
    00113                 uint32_t &pin, std::string &desc, uint8_t &zeroSocketSequence,
    00114                 bool &needClearHalt);
    00115         bool ProbeModem(Usb::Device &dev, const Usb::EndpointPair &ep);
    00116
    00117 public:
    00118         Probe(const char *busname = 0, const char *devname = 0,
    00119                 const Usb::EndpointPair *epp = 0);
    00120
    00121         const Results& GetResults() const { return m_results; }
    00122
    00123         int GetCount() const { return m_results.size(); }
    00124         int GetFailCount() const { return m_fail_count; }
    00125
    00126         const std::string& GetFailMsg(int index) const { return m_fail_msgs.at(index); }
    00127         const ProbeResult& Get(int index) const { return m_results.at(index); }
    00128
    00129         int FindActive(Barry::Pin pin = 0) const; // returns -1 if pin not found
    00130                                                 // or if no devices
    00131         static int FindActive(const Results &results, Barry::Pin pin = 0);
    00132         static int Find(const Results &results, Barry::Pin pin = 0);
    00133 };
    00134
    00135
    00136 } // namespace Barry
    00137
    00138 #endif
    00139