bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -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"); |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 5 | * you may not use this file except in compliance with the License. |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 6 | * You may obtain a copy of the License at |
| 7 | * |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 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. |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 15 | */ |
| 16 | |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 17 | #define LOG_TAG "MtpResponsePacket" |
| 18 | |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <fcntl.h> |
| 22 | |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 23 | #include "IMtpHandle.h" |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 24 | #include "MtpResponsePacket.h" |
| 25 | |
| 26 | #include <usbhost/usbhost.h> |
| 27 | |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 28 | MtpResponsePacket::MtpResponsePacket() |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 29 | : MtpPacket(512) |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
| 33 | MtpResponsePacket::~MtpResponsePacket() { |
| 34 | } |
| 35 | |
| 36 | #ifdef MTP_DEVICE |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 37 | int MtpResponsePacket::write(IMtpHandle *h) { |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 38 | putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); |
| 39 | putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE); |
bigbiff bigbiff | af32bb9 | 2018-12-18 18:39:53 -0500 | [diff] [blame] | 40 | int ret = h->write(mBuffer, mPacketSize); |
bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 41 | return (ret < 0 ? ret : 0); |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | #ifdef MTP_HOST |
| 46 | int 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 | |