blob: 0e96309cc39ccc9d1b4568d4692103192e685f09 [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
Mike Lockwood335dd2b2010-05-19 10:33:39 -040020#include "MtpTypes.h"
Mike Lockwood16864ba2010-05-11 17:16:59 -040021
Daichi Hirono8a7ffae2015-08-20 15:13:40 +090022struct usb_device;
Mike Lockwood42d0b792011-01-04 14:48:57 -050023struct usb_request;
Mike Lockwood7850ef92010-05-14 10:10:36 -040024
25namespace android {
26
Mike Lockwood16864ba2010-05-11 17:16:59 -040027class MtpPacket {
28
29protected:
30 uint8_t* mBuffer;
31 // current size of the buffer
Mike Lockwoodab063842014-11-12 14:20:06 -080032 size_t mBufferSize;
Mike Lockwood16864ba2010-05-11 17:16:59 -040033 // number of bytes to add when resizing the buffer
Mike Lockwoodab063842014-11-12 14:20:06 -080034 size_t mAllocationIncrement;
Mike Lockwood16864ba2010-05-11 17:16:59 -040035 // size of the data in the packet
Mike Lockwoodab063842014-11-12 14:20:06 -080036 size_t mPacketSize;
Mike Lockwood16864ba2010-05-11 17:16:59 -040037
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
Mike Lockwoodab063842014-11-12 14:20:06 -080045 void allocate(size_t length);
Mike Lockwood16864ba2010-05-11 17:16:59 -040046 void dump();
Mike Lockwoodf7454622010-12-09 18:34:18 -080047 void copyFrom(const MtpPacket& src);
Mike Lockwood16864ba2010-05-11 17:16:59 -040048
49 uint16_t getContainerCode() const;
50 void setContainerCode(uint16_t code);
51
Mike Lockwoodf7454622010-12-09 18:34:18 -080052 uint16_t getContainerType() const;
53
Mike Lockwood16864ba2010-05-11 17:16:59 -040054 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
Mike Lockwood42d0b792011-01-04 14:48:57 -050061 int transfer(struct usb_request* request);
Mike Lockwood16864ba2010-05-11 17:16:59 -040062#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
Mike Lockwood7850ef92010-05-14 10:10:36 -040071}; // namespace android
72
Mike Lockwood16864ba2010-05-11 17:16:59 -040073#endif // _MTP_PACKET_H