Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 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 Zhang | 487be61 | 2016-10-24 12:10:41 -0700 | [diff] [blame] | 20 | #include <android-base/macros.h> |
| 21 | |
Jerry Zhang | bc1d4b4 | 2018-03-27 15:25:03 -0700 | [diff] [blame^] | 22 | #include "MtpDebug.h" |
Mike Lockwood | 335dd2b | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 23 | #include "MtpTypes.h" |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 24 | |
Daichi Hirono | 8a7ffae | 2015-08-20 15:13:40 +0900 | [diff] [blame] | 25 | struct usb_device; |
Mike Lockwood | 42d0b79 | 2011-01-04 14:48:57 -0500 | [diff] [blame] | 26 | struct usb_request; |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 30 | class MtpPacket { |
| 31 | |
| 32 | protected: |
| 33 | uint8_t* mBuffer; |
| 34 | // current size of the buffer |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 35 | size_t mBufferSize; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 36 | // number of bytes to add when resizing the buffer |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 37 | size_t mAllocationIncrement; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 38 | // size of the data in the packet |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 39 | size_t mPacketSize; |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 40 | |
| 41 | public: |
Chih-Hung Hsieh | a039c88 | 2016-08-09 14:16:10 -0700 | [diff] [blame] | 42 | explicit MtpPacket(int bufferSize); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 43 | virtual ~MtpPacket(); |
| 44 | |
| 45 | // sets packet size to the default container size and sets buffer to zero |
| 46 | virtual void reset(); |
| 47 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 48 | void allocate(size_t length); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 49 | void dump(); |
Mike Lockwood | f745462 | 2010-12-09 18:34:18 -0800 | [diff] [blame] | 50 | void copyFrom(const MtpPacket& src); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 51 | |
| 52 | uint16_t getContainerCode() const; |
| 53 | void setContainerCode(uint16_t code); |
| 54 | |
Mike Lockwood | f745462 | 2010-12-09 18:34:18 -0800 | [diff] [blame] | 55 | uint16_t getContainerType() const; |
| 56 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 57 | 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 Lockwood | 42d0b79 | 2011-01-04 14:48:57 -0500 | [diff] [blame] | 64 | int transfer(struct usb_request* request); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 65 | #endif |
| 66 | |
| 67 | protected: |
| 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 Zhang | 487be61 | 2016-10-24 12:10:41 -0700 | [diff] [blame] | 72 | |
| 73 | DISALLOW_COPY_AND_ASSIGN(MtpPacket); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 74 | }; |
| 75 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 76 | }; // namespace android |
| 77 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 78 | #endif // _MTP_PACKET_H |