File: Request.h

package info (click to toggle)
android-file-transfer 4.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,496 kB
  • sloc: cpp: 12,909; python: 140; lex: 47; xml: 26; sh: 13; makefile: 6
file content (173 lines) | stat: -rw-r--r-- 4,327 bytes parent folder | download | duplicates (3)
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
/*
    This file is part of Android File Transfer For Linux.
    Copyright (C) 2015-2020  Vladimir Menshakov

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

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this library; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef AFTL_MTP_USB_REQUEST_H
#define AFTL_MTP_USB_REQUEST_H

#include <mtp/types.h>
#include <mtp/ByteArray.h>

namespace mtp { namespace usb
{
	class Device;
	DECLARE_PTR(Device);

	enum struct RequestType : u8
	{
		HostToDevice		= 0x00,
		DeviceToHost		= 0x80,

		Standard			= 0x00,
		Class				= 0x20,
		Vendor				= 0x40,

		Device				= 0x00,
		Interface			= 0x01,
		Endpoint			= 0x02,
		Other				= 0x03
	};

	constexpr RequestType operator | (RequestType r1, RequestType r2)
	{ return static_cast<RequestType>(static_cast<u8>(r1) | static_cast<u8>(r2)); };

	class BaseRequest //! Base USB Standard Request
	{
	public:
		static const int DefaultTimeout = 1000;

		BaseRequest(const DevicePtr & device, int timeout = DefaultTimeout);
		~BaseRequest();

	protected:
		DevicePtr	_device;
		int			_timeout;
	};

	enum struct DescriptorType : u8
	{
		Device						= 1,
		Configuration				= 2,
		String						= 3,
		Interface					= 4,
		Endpoint					= 5,
		DeviceQualifier				= 6,
		OtherSpeedConfiguration		= 7,
		InterfacePower				= 8,
		OnTheGo						= 9
	};

	struct DeviceRequest : BaseRequest //! USB Standard Request for Device
	{
		using BaseRequest::BaseRequest;

		enum struct Type : u8
		{
			DeviceOut	= static_cast<u8>(RequestType::HostToDevice | RequestType::Standard | RequestType::Device),
			DeviceIn	= static_cast<u8>(RequestType::DeviceToHost | RequestType::Standard | RequestType::Device)
		};

		enum struct Request : u8
		{
			GetStatus				= 0,
			ClearFeature			= 1,
			SetFeature				= 3,
			SetAddress				= 5,
			GetDescriptor			= 6,
			SetDescriptor			= 7,
			GetConfiguration		= 8,
			SetConfiguration		= 9,
			GetOSStringDescriptor  	= 0xee
		};

		u16 GetStatus();

		void ClearFeature(u16 feature);
		void SetFeature(u16 feature);

		void SetAddress(u16 address);

		ByteArray GetDescriptor(DescriptorType type, u8 index, u16 lang = 0);
		void SetDescriptor(DescriptorType type, u8 index, u16 lang, const ByteArray &data);
		u8 GetConfiguration();
		void SetConfiguration(u8 index);
	};

	class InterfaceRequest : public BaseRequest //! USB Standard Request for Interface
	{
		u16 _interface;
	public:

		enum struct Type : u8
		{
			InterfaceOut	= static_cast<u8>(RequestType::HostToDevice | RequestType::Standard | RequestType::Interface),
			InterfaceIn		= static_cast<u8>(RequestType::DeviceToHost | RequestType::Standard | RequestType::Interface)
		};

		enum struct Request : u8
		{
			GetStatus			= 0,
			ClearFeature		= 1,
			SetFeature			= 3,
			GetInterface		= 10,
			SetInterface		= 17
		};

		InterfaceRequest(const DevicePtr & device, u16 interface, int timeout = DefaultTimeout);

		u16 GetStatus();

		void ClearFeature(u16 feature);
		void SetFeature(u16 feature);

		u8 GetInterface();
		void SetInterface(u8 alt);
	};

	class EndpointRequest : public BaseRequest //! USB Standard Request for Endpoint
	{
		u16 _endpoint;

	public:
		enum struct Type : u8
		{
			EnpointOut		= static_cast<u8>(RequestType::HostToDevice | RequestType::Standard | RequestType::Endpoint),
			EnpointIn		= static_cast<u8>(RequestType::DeviceToHost | RequestType::Standard | RequestType::Endpoint)
		};

		enum struct Request : u8
		{
			GetStatus			= 0,
			ClearFeature		= 1,
			SetFeature			= 3,
			SynchFrame			= 18
		};

		EndpointRequest(const DevicePtr & device, u16 endpoint, int timeout = DefaultTimeout);

		u16 GetStatus();

		void ClearFeature(u16 feature);
		void SetFeature(u16 feature);

		void SynchFrame(u16 frameIndex);
	};

}}

#endif