blob: 641a4fc8d396c59fd92f78c8053b67e2f8d6d88a [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -05005 * you may not use this file except in compliance with the License.
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04006 * You may obtain a copy of the License at
7 *
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -05008 * http://www.apache.org/licenses/LICENSE-2.0
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -04009 *
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.
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040015 */
16
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050017#define LOG_TAG "MtpResponsePacket"
18
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040019#include <stdio.h>
20#include <sys/types.h>
21#include <fcntl.h>
22
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050023#include "IMtpHandle.h"
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040024#include "MtpResponsePacket.h"
25
26#include <usbhost/usbhost.h>
27
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040028MtpResponsePacket::MtpResponsePacket()
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050029 : MtpPacket(512)
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040030{
31}
32
33MtpResponsePacket::~MtpResponsePacket() {
34}
35
36#ifdef MTP_DEVICE
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050037int MtpResponsePacket::write(IMtpHandle *h) {
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040038 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
39 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE);
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -050040 int ret = h->write(mBuffer, mPacketSize);
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040041 return (ret < 0 ? ret : 0);
42}
43#endif
44
45#ifdef MTP_HOST
46int MtpResponsePacket::read(struct usb_request *request) {
47 request->buffer = mBuffer;
48 request->buffer_length = mBufferSize;
49 int ret = transfer(request);
50 if (ret >= 0)
51 mPacketSize = ret;
52 else
53 mPacketSize = 0;
54 return ret;
55}
56#endif
57