blob: 9842b28b815855b0d9313119b2abb0b2e74a98a0 [file] [log] [blame]
Mike Lockwood16864ba2010-05-11 17:16:59 -04001/*
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
Jerry Zhang487be612016-10-24 12:10:41 -070020#include <android-base/macros.h>
21
Jerry Zhangbc1d4b42018-03-27 15:25:03 -070022#include "MtpDebug.h"
Mike Lockwood335dd2b2010-05-19 10:33:39 -040023#include "MtpTypes.h"
Mike Lockwood16864ba2010-05-11 17:16:59 -040024
Daichi Hirono8a7ffae2015-08-20 15:13:40 +090025struct usb_device;
Mike Lockwood42d0b792011-01-04 14:48:57 -050026struct usb_request;
Mike Lockwood7850ef92010-05-14 10:10:36 -040027
28namespace android {
29
Mike Lockwood16864ba2010-05-11 17:16:59 -040030class MtpPacket {
31
32protected:
33 uint8_t* mBuffer;
34 // current size of the buffer
Mike Lockwoodab063842014-11-12 14:20:06 -080035 size_t mBufferSize;
Mike Lockwood16864ba2010-05-11 17:16:59 -040036 // number of bytes to add when resizing the buffer
Mike Lockwoodab063842014-11-12 14:20:06 -080037 size_t mAllocationIncrement;
Mike Lockwood16864ba2010-05-11 17:16:59 -040038 // size of the data in the packet
Mike Lockwoodab063842014-11-12 14:20:06 -080039 size_t mPacketSize;
Mike Lockwood16864ba2010-05-11 17:16:59 -040040
41public:
Chih-Hung Hsieha039c882016-08-09 14:16:10 -070042 explicit MtpPacket(int bufferSize);
Mike Lockwood16864ba2010-05-11 17:16:59 -040043 virtual ~MtpPacket();
44
45 // sets packet size to the default container size and sets buffer to zero
46 virtual void reset();
47
Mike Lockwoodab063842014-11-12 14:20:06 -080048 void allocate(size_t length);
Mike Lockwood16864ba2010-05-11 17:16:59 -040049 void dump();
Mike Lockwoodf7454622010-12-09 18:34:18 -080050 void copyFrom(const MtpPacket& src);
Mike Lockwood16864ba2010-05-11 17:16:59 -040051
52 uint16_t getContainerCode() const;
53 void setContainerCode(uint16_t code);
54
Mike Lockwoodf7454622010-12-09 18:34:18 -080055 uint16_t getContainerType() const;
56
Mike Lockwood16864ba2010-05-11 17:16:59 -040057 MtpTransactionID getTransactionID() const;
58 void setTransactionID(MtpTransactionID id);
59
60 uint32_t getParameter(int index) const;
61 void setParameter(int index, uint32_t value);
62
63#ifdef MTP_HOST
Mike Lockwood42d0b792011-01-04 14:48:57 -050064 int transfer(struct usb_request* request);
Mike Lockwood16864ba2010-05-11 17:16:59 -040065#endif
66
67protected:
68 uint16_t getUInt16(int offset) const;
69 uint32_t getUInt32(int offset) const;
70 void putUInt16(int offset, uint16_t value);
71 void putUInt32(int offset, uint32_t value);
Jerry Zhang487be612016-10-24 12:10:41 -070072
73 DISALLOW_COPY_AND_ASSIGN(MtpPacket);
Mike Lockwood16864ba2010-05-11 17:16:59 -040074};
75
Mike Lockwood7850ef92010-05-14 10:10:36 -040076}; // namespace android
77
Mike Lockwood16864ba2010-05-11 17:16:59 -040078#endif // _MTP_PACKET_H