This file is indexed.

/usr/include/barry18/barry/usbwrap.h is in libbarry-dev 0.18.5-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
///
/// \file	usbwrap.h
///		USB API wrapper
///

/*
    Copyright (C) 2005-2013, Chris Frey
    Portions Copyright (C) 2011, RealVNC Ltd.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    See the GNU General Public License in the COPYING file at the
    root directory of this project for more details.
*/


#ifndef __SB_USBWRAP_H__
#define __SB_USBWRAP_H__

#include "dll.h"

#include <memory>
#include <tr1/memory>
#include <vector>
#include <map>
#include "error.h"

#define USBWRAP_DEFAULT_TIMEOUT	30000

// Matches any product ID when calling DeviceList::MatchDevices
#define PRODUCT_ANY             0x10000
// Indicates an unknown product ID
#define PRODUCT_UNKNOWN         0x20000

namespace Barry { class Data; }

/// Namespace for the libusb-related wrapper classes.  This namespace
/// may change in the future.
namespace Usb {

/// \addtogroup exceptions
/// @{

/// Thrown on low level USB errors.
class BXEXPORT Error : public Barry::Error
{
	int m_libusb_errcode;

public:
	Error(const std::string &str);
	Error(int libusb_errcode, const std::string &str);

	// can return 0 in some case, if unknown error code
	int libusb_errcode() const { return m_libusb_errcode; }

	// returns a translated system error code when using libusb 1.0
	// returns 0 if unknown or unable to translate
	int system_errcode() const;
};

class BXEXPORT Timeout : public Error
{
public:
	Timeout(const std::string &str) : Error(str) {}
	Timeout(int errcode, const std::string &str)
		: Error(errcode, str) {}
};

/// @}

// Private struct for holding library specific
// a unique identifier to a connected device.
class DeviceIDImpl;

class BXEXPORT DeviceID
{
public:
	std::tr1::shared_ptr<DeviceIDImpl> m_impl;
public:
	// Takes ownership of impl
	DeviceID(DeviceIDImpl* impl = NULL);
	~DeviceID();
	const char* GetBusName() const;
	uint16_t GetNumber() const;
	const char* GetFilename() const;
	uint16_t GetIdProduct() const;

	// Utility function: returns a string that uniquely identifies
	// the bus and device, regardless of which libusb you're using
	std::string GetUsbName() const;
};

// Private struct for holding a library specific
// device handle
struct DeviceHandle;

// Static functions for setting up USB
// The interface that usbwrap.cc uses
// to interact with the USB library
class BXEXPORT LibraryInterface
{
public:
	static std::string GetLastErrorString(int libusb_errcode);

	/// Returns 0 if unable to translate libusb error code.
	/// Note that this function assumes you already know that libusb_errcode
	/// contains an actual error code, and so returns 0 (success)
	/// for an unknown error.  This means that "success" means error
	/// if you use this function correctly, but if you pass in a success
	/// code (>= 0) it will always return 0 as well.
	static int TranslateErrcode(int libusb_errcode);

	/// Returns true on success... pass in a pointer to int
	/// if the low level error code is important to you.
	static bool Init(int *libusb_errno = 0);
	static void Uninit();
	static void SetDataDump(bool data_dump_mode);
};

// Forward declaration of descriptor types.
class BXEXPORT DeviceDescriptor;
class BXEXPORT ConfigDescriptor;
class BXEXPORT InterfaceDescriptor;

// Private struct for holding library specific
// information about endpoint descriptors
struct EndpointDescriptorImpl;

// Encapsulates an endpoint descriptor
class BXEXPORT EndpointDescriptor
{
public:
	enum EpType
	{
		ControlType = 0,
		IsochronousType = 1,
		BulkType = 2,
		InterruptType = 3,
		InvalidType = 0xff
	};
private:
	const std::auto_ptr<EndpointDescriptorImpl> m_impl;
	bool m_read;
	uint8_t m_addr;
	EpType m_type;
private:
	EndpointDescriptor(const EndpointDescriptor& rhs); // Prevent copying
public:
	EndpointDescriptor(InterfaceDescriptor& dev, int endpoint);
	~EndpointDescriptor();
	bool IsRead() const;
	uint8_t GetAddress() const;
	EpType GetType() const;
};

// Private struct for holding library specific
// information about interface descriptors
struct InterfaceDescriptorImpl;

// Encapsulates an interface descriptor
//
// The inherited vector methods look up endpoints
class BXEXPORT InterfaceDescriptor : public std::vector<EndpointDescriptor*>
{
	friend class EndpointDescriptor;
public:
	typedef std::vector<EndpointDescriptor*> base_type;
private:
	const std::auto_ptr<InterfaceDescriptorImpl> m_impl;
private:
	InterfaceDescriptor(const InterfaceDescriptor& rhs); // Prevent copying
public:
	InterfaceDescriptor(ConfigDescriptor& cfgdesc,
			    int iface, int altsetting);
	~InterfaceDescriptor();
	uint8_t GetClass() const;
	uint8_t GetNumber() const;
	uint8_t GetAltSetting() const;
};

// Private struct for holding library specific
// information about config descriptors

struct ConfigDescriptorImpl;

// Encapsulates a configuration descriptor
//
// The inherited map methods look up interface descriptors
class BXEXPORT ConfigDescriptor : public std::map<int, InterfaceDescriptor*>
{
	friend class InterfaceDescriptor;
public:
	typedef std::map<int, InterfaceDescriptor*> base_type;
private:
	const std::auto_ptr<ConfigDescriptorImpl> m_impl;
private:
	ConfigDescriptor(const ConfigDescriptor& rhs); // Prevent copying
public:
	ConfigDescriptor(DeviceDescriptor& dev, int cfgnumber);
	~ConfigDescriptor();
	uint8_t GetNumber() const;
};

// Private struct for holding library specific
// information about a device descriptor
struct DeviceDescriptorImpl;

// Encapsulates a device descriptor
//
// The inherited map methods look up config descriptors
class BXEXPORT DeviceDescriptor : public std::map<int, ConfigDescriptor*>
{
	friend class ConfigDescriptor;
public:
	typedef std::map<int, ConfigDescriptor*> base_type;
private:
	const std::auto_ptr<DeviceDescriptorImpl> m_impl;
private:
	DeviceDescriptor(const DeviceDescriptor& rhs); // Prevent copying
public:
	DeviceDescriptor(DeviceID& devid);
	~DeviceDescriptor();
};

// Private struct for holding library specific
// information for devices.
struct DeviceListImpl;

class BXEXPORT DeviceList
{
private:
	// Private implementation structure
	const std::auto_ptr<DeviceListImpl> m_impl;
private:
	DeviceList(const DeviceList& rhs); // Prevent copying
public:
	DeviceList();
	~DeviceList();

	std::vector<DeviceID> MatchDevices(int vendor, int product,
					   const char *busname, const char *devname);

};

struct PrivateDeviceData;

class BXEXPORT Device
{
private:
	Usb::DeviceID m_id;
	const std::auto_ptr<Usb::DeviceHandle> m_handle;

	int m_timeout;
	int m_lasterror;
private:
	Device(const Device& rhs); // Prevent copying
public:
	Device(const Usb::DeviceID& id, int timeout = USBWRAP_DEFAULT_TIMEOUT);
	~Device();

	/////////////////////////////
	// Data access

	const Usb::DeviceID& GetID() const { return m_id; }
	const Usb::DeviceHandle* GetHandle() const { return &*m_handle; }
	int GetLastError() const { return m_lasterror; } //< not thread safe...
		//< use the error code stored in the exceptions to track
		//< errors in threaded usage
	void SetLastError(int err) { m_lasterror = err; }
	int GetDefaultTimeout() const { return m_timeout; }

	/////////////////////////////
	// Device information

	int GetPowerLevel();
	int FindInterface(int ifaceClass);
	std::string GetSimpleSerialNumber();

	/////////////////////////////
	// Device manipulation

	bool SetConfiguration(unsigned char cfg);
	bool ClearHalt(int ep);
	bool Reset();
	bool IsAttachKernelDriver(int iface);
	bool DetachKernelDriver(int iface);

	/////////////////////////////
	// IO functions

	bool BulkRead(int ep, Barry::Data &data, int timeout = -1);
	bool BulkWrite(int ep, const Barry::Data &data, int timeout = -1);
	bool BulkWrite(int ep, const void *data, size_t size, int timeout = -1);
	bool InterruptRead(int ep, Barry::Data &data, int timeout = -1);
	bool InterruptWrite(int ep, const Barry::Data &data, int timeout = -1);

	void BulkDrain(int ep, int timeout = 100);

	bool ControlMsg(int requesttype, int request, int value,
			int index, char *bytes, int size, int timeout);

	/////////////////////////////
	// Combo functions

	bool GetConfiguration(unsigned char &cfg);
};

class BXEXPORT Interface
{
	Device &m_dev;
	int m_iface;
public:
	Interface(Device &dev, int iface);
	~Interface();
	bool SetAltInterface(int altSetting);
};

// Map of Endpoint numbers (not indexes) to endpoint descriptors
struct BXEXPORT EndpointPair
{
	unsigned char read;
	unsigned char write;
	EndpointDescriptor::EpType type;

	EndpointPair();
	bool IsTypeSet() const;
	bool IsComplete() const;
	bool IsBulk() const;
};

class BXEXPORT EndpointPairings : public std::vector<EndpointPair>
{
public:
	typedef std::vector<EndpointPair> base_type;
private:
	bool m_valid;
public:
	EndpointPairings(const std::vector<EndpointDescriptor*>& eps);
	~EndpointPairings();
	bool IsValid() const;
};

class BXEXPORT Match
{
private:
	std::vector<DeviceID> m_list;
	std::vector<DeviceID>::iterator m_iter;
public:
	// Due to USB libraries having different ownership ideas
	// about device IDs, Match objects must be constructed
	// with a device list.
	Match(DeviceList& devices,
	      int vendor, int product,
	      const char *busname = 0, const char *devname = 0);	
	~Match();

	// searches for next match, and if found, fills devid with
	// something you can pass on to DeviceDiscover, etc
	// returns true if next is found, false if no more
	bool next_device(Usb::DeviceID& devid);
};

}

#endif