116864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood/*
216864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * Copyright (C) 2010 The Android Open Source Project
316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood *
416864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * Licensed under the Apache License, Version 2.0 (the "License");
516864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * you may not use this file except in compliance with the License.
616864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * You may obtain a copy of the License at
716864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood *
816864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood *      http://www.apache.org/licenses/LICENSE-2.0
916864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood *
1016864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * Unless required by applicable law or agreed to in writing, software
1116864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * distributed under the License is distributed on an "AS IS" BASIS,
1216864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * See the License for the specific language governing permissions and
1416864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood * limitations under the License.
1516864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood */
1616864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
1716864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood#ifndef _MTP_PACKET_H
1816864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood#define _MTP_PACKET_H
1916864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
20487be61fb0a38873aec1d12da92437fba5e728f2Jerry Zhang#include <android-base/macros.h>
21487be61fb0a38873aec1d12da92437fba5e728f2Jerry Zhang
22335dd2be955607f2632eabc25045857f2cc8b674Mike Lockwood#include "MtpTypes.h"
2316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
248a7ffae09a019de7109b30c505561c453910bde1Daichi Hironostruct usb_device;
2542d0b79a787814d42e4c6f9dfe14f13cc0f6a758Mike Lockwoodstruct usb_request;
267850ef999740f214a1990a9c090d3f3865d435aaMike Lockwood
277850ef999740f214a1990a9c090d3f3865d435aaMike Lockwoodnamespace android {
287850ef999740f214a1990a9c090d3f3865d435aaMike Lockwood
2916864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwoodclass MtpPacket {
3016864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
3116864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwoodprotected:
3216864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    uint8_t*            mBuffer;
3316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    // current size of the buffer
34ab063847e6e893740749029a04cce1f6b7345ed5Mike Lockwood    size_t              mBufferSize;
3516864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    // number of bytes to add when resizing the buffer
36ab063847e6e893740749029a04cce1f6b7345ed5Mike Lockwood    size_t              mAllocationIncrement;
3716864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    // size of the data in the packet
38ab063847e6e893740749029a04cce1f6b7345ed5Mike Lockwood    size_t              mPacketSize;
3916864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
4016864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwoodpublic:
41a039c883c593b2ebbca6d32282cbd855b5bec19fChih-Hung Hsieh    explicit            MtpPacket(int bufferSize);
4216864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    virtual             ~MtpPacket();
4316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
4416864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    // sets packet size to the default container size and sets buffer to zero
4516864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    virtual void        reset();
4616864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
47ab063847e6e893740749029a04cce1f6b7345ed5Mike Lockwood    void                allocate(size_t length);
4816864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    void                dump();
49f7454622eaac287d20ab43013d7015fe42b894f8Mike Lockwood    void                copyFrom(const MtpPacket& src);
5016864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
5116864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    uint16_t            getContainerCode() const;
5216864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    void                setContainerCode(uint16_t code);
5316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
54f7454622eaac287d20ab43013d7015fe42b894f8Mike Lockwood    uint16_t            getContainerType() const;
55f7454622eaac287d20ab43013d7015fe42b894f8Mike Lockwood
5616864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    MtpTransactionID    getTransactionID() const;
5716864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    void                setTransactionID(MtpTransactionID id);
5816864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
5916864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    uint32_t            getParameter(int index) const;
6016864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    void                setParameter(int index, uint32_t value);
6116864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
6216864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood#ifdef MTP_HOST
6342d0b79a787814d42e4c6f9dfe14f13cc0f6a758Mike Lockwood    int                 transfer(struct usb_request* request);
6416864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood#endif
6516864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
6616864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwoodprotected:
6716864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    uint16_t            getUInt16(int offset) const;
6816864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    uint32_t            getUInt32(int offset) const;
6916864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    void                putUInt16(int offset, uint16_t value);
7016864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood    void                putUInt32(int offset, uint32_t value);
71487be61fb0a38873aec1d12da92437fba5e728f2Jerry Zhang
72487be61fb0a38873aec1d12da92437fba5e728f2Jerry Zhang    DISALLOW_COPY_AND_ASSIGN(MtpPacket);
7316864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood};
7416864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood
757850ef999740f214a1990a9c090d3f3865d435aaMike Lockwood}; // namespace android
767850ef999740f214a1990a9c090d3f3865d435aaMike Lockwood
7716864bae0f51c32c456da2c43adf7a057c0c4882Mike Lockwood#endif // _MTP_PACKET_H
78