blob: f186b378b4e16ba79f20de2869cf44170b8c3972 [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
Mike Lockwoodb14e5882010-06-29 18:11:52 -040017#define LOG_TAG "MtpResponsePacket"
18
Mike Lockwood16864ba2010-05-11 17:16:59 -040019#include <stdio.h>
20#include <sys/types.h>
21#include <fcntl.h>
22
Jerry Zhang487be612016-10-24 12:10:41 -070023#include "IMtpHandle.h"
Mike Lockwood16864ba2010-05-11 17:16:59 -040024#include "MtpResponsePacket.h"
25
Mike Lockwood42d0b792011-01-04 14:48:57 -050026#include <usbhost/usbhost.h>
27
Mike Lockwood7850ef92010-05-14 10:10:36 -040028namespace android {
29
Mike Lockwood16864ba2010-05-11 17:16:59 -040030MtpResponsePacket::MtpResponsePacket()
31 : MtpPacket(512)
32{
33}
34
35MtpResponsePacket::~MtpResponsePacket() {
36}
37
38#ifdef MTP_DEVICE
Jerry Zhang487be612016-10-24 12:10:41 -070039int MtpResponsePacket::write(IMtpHandle *h) {
Mike Lockwood16864ba2010-05-11 17:16:59 -040040 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
41 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE);
Jerry Zhang487be612016-10-24 12:10:41 -070042 int ret = h->write(mBuffer, mPacketSize);
Mike Lockwood16864ba2010-05-11 17:16:59 -040043 return (ret < 0 ? ret : 0);
44}
45#endif
46
47#ifdef MTP_HOST
Mike Lockwood42d0b792011-01-04 14:48:57 -050048int MtpResponsePacket::read(struct usb_request *request) {
49 request->buffer = mBuffer;
50 request->buffer_length = mBufferSize;
51 int ret = transfer(request);
Mike Lockwood16864ba2010-05-11 17:16:59 -040052 if (ret >= 0)
53 mPacketSize = ret;
54 else
55 mPacketSize = 0;
56 return ret;
57}
58#endif
59
Mike Lockwood7850ef92010-05-14 10:10:36 -040060} // namespace android
Mike Lockwood16864ba2010-05-11 17:16:59 -040061