Mike Lockwood | be125a5 | 2010-07-12 18:54:16 -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 | |
| 17 | #define LOG_TAG "MtpEventPacket" |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <fcntl.h> |
| 22 | #include <sys/ioctl.h> |
| 23 | |
| 24 | #include <f_mtp.h> |
| 25 | |
| 26 | #include "MtpEventPacket.h" |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | MtpEventPacket::MtpEventPacket() |
| 31 | : MtpPacket(512) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | MtpEventPacket::~MtpEventPacket() { |
| 36 | } |
| 37 | |
| 38 | #ifdef MTP_DEVICE |
| 39 | int MtpEventPacket::write(int fd) { |
| 40 | struct mtp_event event; |
| 41 | |
| 42 | putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); |
| 43 | putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_EVENT); |
| 44 | |
| 45 | event.data = mBuffer; |
| 46 | event.length = mPacketSize; |
| 47 | int ret = ::ioctl(fd, MTP_SEND_EVENT, (unsigned long)&event); |
| 48 | return (ret < 0 ? ret : 0); |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | #ifdef MTP_HOST |
| 53 | // read our buffer from the given endpoint |
| 54 | int MtpEventPacket::read(struct usb_endpoint *ep) { |
| 55 | int ret = transfer(ep, mBuffer, mBufferSize); |
| 56 | if (ret >= 0) |
| 57 | mPacketSize = ret; |
| 58 | else |
| 59 | mPacketSize = 0; |
| 60 | return ret; |
| 61 | } |
| 62 | #endif |
| 63 | |
| 64 | } // namespace android |
| 65 | |