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