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 | |
Mike Lockwood | b14e588 | 2010-06-29 18:11:52 -0400 | [diff] [blame] | 17 | #define LOG_TAG "MtpResponsePacket" |
| 18 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <fcntl.h> |
| 22 | |
Jerry Zhang | 487be61 | 2016-10-24 12:10:41 -0700 | [diff] [blame] | 23 | #include "IMtpHandle.h" |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 24 | #include "MtpResponsePacket.h" |
| 25 | |
Mike Lockwood | 42d0b79 | 2011-01-04 14:48:57 -0500 | [diff] [blame] | 26 | #include <usbhost/usbhost.h> |
| 27 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 30 | MtpResponsePacket::MtpResponsePacket() |
| 31 | : MtpPacket(512) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | MtpResponsePacket::~MtpResponsePacket() { |
| 36 | } |
| 37 | |
| 38 | #ifdef MTP_DEVICE |
Jerry Zhang | 487be61 | 2016-10-24 12:10:41 -0700 | [diff] [blame] | 39 | int MtpResponsePacket::write(IMtpHandle *h) { |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 40 | putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); |
| 41 | putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE); |
Jerry Zhang | 487be61 | 2016-10-24 12:10:41 -0700 | [diff] [blame] | 42 | int ret = h->write(mBuffer, mPacketSize); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 43 | return (ret < 0 ? ret : 0); |
| 44 | } |
| 45 | #endif |
| 46 | |
| 47 | #ifdef MTP_HOST |
Mike Lockwood | 42d0b79 | 2011-01-04 14:48:57 -0500 | [diff] [blame] | 48 | int MtpResponsePacket::read(struct usb_request *request) { |
| 49 | request->buffer = mBuffer; |
| 50 | request->buffer_length = mBufferSize; |
| 51 | int ret = transfer(request); |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 52 | if (ret >= 0) |
| 53 | mPacketSize = ret; |
| 54 | else |
| 55 | mPacketSize = 0; |
| 56 | return ret; |
| 57 | } |
| 58 | #endif |
| 59 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 60 | } // namespace android |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 61 | |