blob: be3db3091d82ffeb8d93d9275a5e3ea30b9830ec [file] [log] [blame]
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++
17 */
18
19#ifndef _MTP_PACKET_H
20#define _MTP_PACKET_H
21
22#include "MtpTypes.h"
23
24struct usb_request;
25
26
27class MtpPacket {
28
29protected:
30 uint8_t* mBuffer;
31 // current size of the buffer
32 int mBufferSize;
33 // number of bytes to add when resizing the buffer
34 int mAllocationIncrement;
35 // size of the data in the packet
36 unsigned mPacketSize;
37
38public:
39 MtpPacket(int bufferSize);
40 virtual ~MtpPacket();
41
42 // sets packet size to the default container size and sets buffer to zero
43 virtual void reset();
44
45 void allocate(int length);
46 void dump();
47 void copyFrom(const MtpPacket& src);
48
49 uint16_t getContainerCode() const;
50 void setContainerCode(uint16_t code);
51
52 uint16_t getContainerType() const;
53
54 MtpTransactionID getTransactionID() const;
55 void setTransactionID(MtpTransactionID id);
56
57 uint32_t getParameter(int index) const;
58 void setParameter(int index, uint32_t value);
59
60#ifdef MTP_HOST
61 int transfer(struct usb_request* request);
62#endif
63
64protected:
65 uint16_t getUInt16(int offset) const;
66 uint32_t getUInt32(int offset) const;
67 void putUInt16(int offset, uint16_t value);
68 void putUInt32(int offset, uint32_t value);
69};
70
71
72#endif // _MTP_PACKET_H