blob: b7570917f654b32a12b37980ae2e75740a5ce6c8 [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
17#ifndef _MTP_PACKET_H
18#define _MTP_PACKET_H
19
20#include <android-base/macros.h>
21
22#include "MtpDebug.h"
23#include "MtpTypes.h"
24
25struct usb_device;
26struct usb_request;
27
28class MtpPacket {
29
30protected:
31 uint8_t* mBuffer;
32 // current size of the buffer
33 size_t mBufferSize;
34 // number of bytes to add when resizing the buffer
35 size_t mAllocationIncrement;
36 // size of the data in the packet
37 size_t mPacketSize;
38
39public:
40 explicit MtpPacket(int bufferSize);
41 virtual ~MtpPacket();
42
43 // sets packet size to the default container size and sets buffer to zero
44 virtual void reset();
45
46 void allocate(size_t length);
47 void dump();
48 void copyFrom(const MtpPacket& src);
49
50 uint16_t getContainerCode() const;
51 void setContainerCode(uint16_t code);
52
53 uint16_t getContainerType() const;
54
55 MtpTransactionID getTransactionID() const;
56 void setTransactionID(MtpTransactionID id);
57
58 uint32_t getParameter(int index) const;
59 void setParameter(int index, uint32_t value);
60
61#ifdef MTP_HOST
62 int transfer(struct usb_request* request);
63#endif
64
65protected:
66 uint16_t getUInt16(int offset) const;
67 uint32_t getUInt32(int offset) const;
68 void putUInt16(int offset, uint16_t value);
69 void putUInt32(int offset, uint32_t value);
70
71 DISALLOW_COPY_AND_ASSIGN(MtpPacket);
72};
73
74#endif // _MTP_PACKET_H