blob: d65845db4aeea16f3e12ca2dc58642b7796d8727 [file] [log] [blame]
Mike Lockwood56118b52010-05-11 17:16:59 -04001/*
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#include <stdio.h>
18#include <stdlib.h>
19#include <sys/types.h>
20#include <sys/ioctl.h>
21#include <sys/stat.h>
22#include <fcntl.h>
23#include <errno.h>
Mike Lockwoodccb6e962010-09-13 17:15:58 -040024#include <sys/stat.h>
25#include <dirent.h>
Mike Lockwood56118b52010-05-11 17:16:59 -040026
Mike Lockwood622ccdc2010-06-14 17:58:08 -070027#include <cutils/properties.h>
28
Mike Lockwood9f679242010-09-23 22:32:05 -040029#define LOG_TAG "MtpServer"
30
Mike Lockwood56118b52010-05-11 17:16:59 -040031#include "MtpDebug.h"
Mike Lockwoodc5c78532010-07-09 10:45:22 -040032#include "MtpDatabase.h"
Mike Lockwood767c5e42010-06-30 17:00:35 -040033#include "MtpProperty.h"
Mike Lockwood56118b52010-05-11 17:16:59 -040034#include "MtpServer.h"
35#include "MtpStorage.h"
36#include "MtpStringBuffer.h"
Mike Lockwood56118b52010-05-11 17:16:59 -040037
Mike Lockwood9c7fdf52010-07-15 13:36:52 -040038#include <linux/usb/f_mtp.h>
Mike Lockwood56118b52010-05-11 17:16:59 -040039
Mike Lockwood8d3257a2010-05-14 10:10:36 -040040namespace android {
41
Mike Lockwood56118b52010-05-11 17:16:59 -040042static const MtpOperationCode kSupportedOperationCodes[] = {
43 MTP_OPERATION_GET_DEVICE_INFO,
44 MTP_OPERATION_OPEN_SESSION,
45 MTP_OPERATION_CLOSE_SESSION,
46 MTP_OPERATION_GET_STORAGE_IDS,
47 MTP_OPERATION_GET_STORAGE_INFO,
48 MTP_OPERATION_GET_NUM_OBJECTS,
49 MTP_OPERATION_GET_OBJECT_HANDLES,
50 MTP_OPERATION_GET_OBJECT_INFO,
51 MTP_OPERATION_GET_OBJECT,
52// MTP_OPERATION_GET_THUMB,
53 MTP_OPERATION_DELETE_OBJECT,
54 MTP_OPERATION_SEND_OBJECT_INFO,
55 MTP_OPERATION_SEND_OBJECT,
56// MTP_OPERATION_INITIATE_CAPTURE,
57// MTP_OPERATION_FORMAT_STORE,
58// MTP_OPERATION_RESET_DEVICE,
59// MTP_OPERATION_SELF_TEST,
60// MTP_OPERATION_SET_OBJECT_PROTECTION,
61// MTP_OPERATION_POWER_DOWN,
Mike Lockwood59e3f0d2010-09-02 14:57:30 -040062 MTP_OPERATION_GET_DEVICE_PROP_DESC,
Mike Lockwood828d19d2010-08-10 15:20:35 -040063 MTP_OPERATION_GET_DEVICE_PROP_VALUE,
64 MTP_OPERATION_SET_DEVICE_PROP_VALUE,
65 MTP_OPERATION_RESET_DEVICE_PROP_VALUE,
Mike Lockwood56118b52010-05-11 17:16:59 -040066// MTP_OPERATION_TERMINATE_OPEN_CAPTURE,
67// MTP_OPERATION_MOVE_OBJECT,
68// MTP_OPERATION_COPY_OBJECT,
Mike Lockwood44e82dd2010-11-23 09:08:01 -050069 MTP_OPERATION_GET_PARTIAL_OBJECT,
Mike Lockwood56118b52010-05-11 17:16:59 -040070// MTP_OPERATION_INITIATE_OPEN_CAPTURE,
71 MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED,
Mike Lockwood828d19d2010-08-10 15:20:35 -040072 MTP_OPERATION_GET_OBJECT_PROP_DESC,
Mike Lockwoodd3bfecb2010-09-23 23:04:28 -040073 MTP_OPERATION_GET_OBJECT_PROP_VALUE,
74 MTP_OPERATION_SET_OBJECT_PROP_VALUE,
Mike Lockwoode2ad6ec2010-10-14 18:03:25 -040075 MTP_OPERATION_GET_OBJECT_PROP_LIST,
76// MTP_OPERATION_SET_OBJECT_PROP_LIST,
77// MTP_OPERATION_GET_INTERDEPENDENT_PROP_DESC,
78// MTP_OPERATION_SEND_OBJECT_PROP_LIST,
Mike Lockwood9a2046f2010-08-03 15:30:09 -040079 MTP_OPERATION_GET_OBJECT_REFERENCES,
80 MTP_OPERATION_SET_OBJECT_REFERENCES,
Mike Lockwood56118b52010-05-11 17:16:59 -040081// MTP_OPERATION_SKIP,
82};
83
Mike Lockwoodbe125a52010-07-12 18:54:16 -040084static const MtpEventCode kSupportedEventCodes[] = {
85 MTP_EVENT_OBJECT_ADDED,
86 MTP_EVENT_OBJECT_REMOVED,
87};
88
Mike Lockwoodd21eac92010-07-03 00:44:05 -040089MtpServer::MtpServer(int fd, MtpDatabase* database,
Mike Lockwooddad69272010-07-02 15:15:07 -040090 int fileGroup, int filePerm, int directoryPerm)
Mike Lockwood56118b52010-05-11 17:16:59 -040091 : mFD(fd),
Mike Lockwoodd21eac92010-07-03 00:44:05 -040092 mDatabase(database),
Mike Lockwooddad69272010-07-02 15:15:07 -040093 mFileGroup(fileGroup),
94 mFilePermission(filePerm),
95 mDirectoryPermission(directoryPerm),
Mike Lockwood56118b52010-05-11 17:16:59 -040096 mSessionID(0),
97 mSessionOpen(false),
98 mSendObjectHandle(kInvalidObjectHandle),
Mike Lockwoodd815f792010-07-12 08:49:01 -040099 mSendObjectFormat(0),
Mike Lockwood56118b52010-05-11 17:16:59 -0400100 mSendObjectFileSize(0)
101{
Mike Lockwood56118b52010-05-11 17:16:59 -0400102}
103
104MtpServer::~MtpServer() {
105}
106
107void MtpServer::addStorage(const char* filePath) {
108 int index = mStorages.size() + 1;
109 index |= index << 16; // set high and low part to our index
110 MtpStorage* storage = new MtpStorage(index, filePath, mDatabase);
111 addStorage(storage);
112}
113
114MtpStorage* MtpServer::getStorage(MtpStorageID id) {
Mike Lockwood365e03e2010-12-08 16:08:01 -0800115 if (id == 0)
116 return mStorages[0];
Mike Lockwood56118b52010-05-11 17:16:59 -0400117 for (int i = 0; i < mStorages.size(); i++) {
Mike Lockwood365e03e2010-12-08 16:08:01 -0800118 MtpStorage* storage = mStorages[i];
Mike Lockwood56118b52010-05-11 17:16:59 -0400119 if (storage->getStorageID() == id)
120 return storage;
121 }
122 return NULL;
123}
124
Mike Lockwood56118b52010-05-11 17:16:59 -0400125void MtpServer::run() {
126 int fd = mFD;
127
Mike Lockwood767c5e42010-06-30 17:00:35 -0400128 LOGV("MtpServer::run fd: %d\n", fd);
Mike Lockwood56118b52010-05-11 17:16:59 -0400129
130 while (1) {
131 int ret = mRequest.read(fd);
132 if (ret < 0) {
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400133 LOGE("request read returned %d, errno: %d", ret, errno);
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400134 if (errno == ECANCELED) {
135 // return to top of loop and wait for next command
136 continue;
137 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400138 break;
139 }
140 MtpOperationCode operation = mRequest.getOperationCode();
141 MtpTransactionID transaction = mRequest.getTransactionID();
142
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400143 LOGV("operation: %s", MtpDebug::getOperationCodeName(operation));
Mike Lockwood56118b52010-05-11 17:16:59 -0400144 mRequest.dump();
145
146 // FIXME need to generalize this
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400147 bool dataIn = (operation == MTP_OPERATION_SEND_OBJECT_INFO
Mike Lockwood828d19d2010-08-10 15:20:35 -0400148 || operation == MTP_OPERATION_SET_OBJECT_REFERENCES
149 || operation == MTP_OPERATION_SET_OBJECT_PROP_VALUE
150 || operation == MTP_OPERATION_SET_DEVICE_PROP_VALUE);
Mike Lockwood56118b52010-05-11 17:16:59 -0400151 if (dataIn) {
152 int ret = mData.read(fd);
153 if (ret < 0) {
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400154 LOGE("data read returned %d, errno: %d", ret, errno);
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400155 if (errno == ECANCELED) {
156 // return to top of loop and wait for next command
157 continue;
158 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400159 break;
160 }
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400161 LOGV("received data:");
Mike Lockwood56118b52010-05-11 17:16:59 -0400162 mData.dump();
163 } else {
164 mData.reset();
165 }
166
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400167 if (handleRequest()) {
168 if (!dataIn && mData.hasData()) {
169 mData.setOperationCode(operation);
170 mData.setTransactionID(transaction);
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400171 LOGV("sending data:");
Mike Lockwooddb774312010-10-11 17:31:44 -0400172 mData.dump();
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400173 ret = mData.write(fd);
174 if (ret < 0) {
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400175 LOGE("request write returned %d, errno: %d", ret, errno);
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400176 if (errno == ECANCELED) {
177 // return to top of loop and wait for next command
178 continue;
179 }
180 break;
181 }
182 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400183
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400184 mResponse.setTransactionID(transaction);
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400185 LOGV("sending response %04X", mResponse.getResponseCode());
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400186 ret = mResponse.write(fd);
Mike Lockwooddb774312010-10-11 17:31:44 -0400187 mResponse.dump();
Mike Lockwood56118b52010-05-11 17:16:59 -0400188 if (ret < 0) {
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400189 LOGE("request write returned %d, errno: %d", ret, errno);
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400190 if (errno == ECANCELED) {
191 // return to top of loop and wait for next command
192 continue;
193 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400194 break;
195 }
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400196 } else {
Mike Lockwood767c5e42010-06-30 17:00:35 -0400197 LOGV("skipping response\n");
Mike Lockwood56118b52010-05-11 17:16:59 -0400198 }
199 }
Mike Lockwood2837eef2010-08-31 16:25:12 -0400200
201 if (mSessionOpen)
202 mDatabase->sessionEnded();
Mike Lockwood56118b52010-05-11 17:16:59 -0400203}
204
Mike Lockwoodbe125a52010-07-12 18:54:16 -0400205void MtpServer::sendObjectAdded(MtpObjectHandle handle) {
Mike Lockwooddc453d42010-07-19 14:29:58 -0400206 if (mSessionOpen) {
207 LOGD("sendObjectAdded %d\n", handle);
208 mEvent.setEventCode(MTP_EVENT_OBJECT_ADDED);
209 mEvent.setTransactionID(mRequest.getTransactionID());
210 mEvent.setParameter(1, handle);
211 int ret = mEvent.write(mFD);
212 LOGD("mEvent.write returned %d\n", ret);
213 }
Mike Lockwoodbe125a52010-07-12 18:54:16 -0400214}
215
216void MtpServer::sendObjectRemoved(MtpObjectHandle handle) {
Mike Lockwooddc453d42010-07-19 14:29:58 -0400217 if (mSessionOpen) {
218 LOGD("sendObjectRemoved %d\n", handle);
219 mEvent.setEventCode(MTP_EVENT_OBJECT_REMOVED);
220 mEvent.setTransactionID(mRequest.getTransactionID());
221 mEvent.setParameter(1, handle);
222 int ret = mEvent.write(mFD);
223 LOGD("mEvent.write returned %d\n", ret);
224 }
Mike Lockwoodbe125a52010-07-12 18:54:16 -0400225}
226
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400227bool MtpServer::handleRequest() {
Mike Lockwood56118b52010-05-11 17:16:59 -0400228 MtpOperationCode operation = mRequest.getOperationCode();
229 MtpResponseCode response;
230
231 mResponse.reset();
232
233 if (mSendObjectHandle != kInvalidObjectHandle && operation != MTP_OPERATION_SEND_OBJECT) {
234 // FIXME - need to delete mSendObjectHandle from the database
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400235 LOGE("expected SendObject after SendObjectInfo");
Mike Lockwood56118b52010-05-11 17:16:59 -0400236 mSendObjectHandle = kInvalidObjectHandle;
237 }
238
239 switch (operation) {
240 case MTP_OPERATION_GET_DEVICE_INFO:
241 response = doGetDeviceInfo();
242 break;
243 case MTP_OPERATION_OPEN_SESSION:
244 response = doOpenSession();
245 break;
246 case MTP_OPERATION_CLOSE_SESSION:
247 response = doCloseSession();
248 break;
249 case MTP_OPERATION_GET_STORAGE_IDS:
250 response = doGetStorageIDs();
251 break;
252 case MTP_OPERATION_GET_STORAGE_INFO:
253 response = doGetStorageInfo();
254 break;
255 case MTP_OPERATION_GET_OBJECT_PROPS_SUPPORTED:
256 response = doGetObjectPropsSupported();
257 break;
258 case MTP_OPERATION_GET_OBJECT_HANDLES:
259 response = doGetObjectHandles();
260 break;
Mike Lockwood7a047c82010-08-02 10:52:20 -0400261 case MTP_OPERATION_GET_NUM_OBJECTS:
262 response = doGetNumObjects();
263 break;
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400264 case MTP_OPERATION_GET_OBJECT_REFERENCES:
265 response = doGetObjectReferences();
266 break;
267 case MTP_OPERATION_SET_OBJECT_REFERENCES:
268 response = doSetObjectReferences();
269 break;
Mike Lockwood56118b52010-05-11 17:16:59 -0400270 case MTP_OPERATION_GET_OBJECT_PROP_VALUE:
271 response = doGetObjectPropValue();
272 break;
Mike Lockwood828d19d2010-08-10 15:20:35 -0400273 case MTP_OPERATION_SET_OBJECT_PROP_VALUE:
274 response = doSetObjectPropValue();
275 break;
276 case MTP_OPERATION_GET_DEVICE_PROP_VALUE:
277 response = doGetDevicePropValue();
278 break;
279 case MTP_OPERATION_SET_DEVICE_PROP_VALUE:
280 response = doSetDevicePropValue();
281 break;
282 case MTP_OPERATION_RESET_DEVICE_PROP_VALUE:
283 response = doResetDevicePropValue();
284 break;
Mike Lockwoode2ad6ec2010-10-14 18:03:25 -0400285 case MTP_OPERATION_GET_OBJECT_PROP_LIST:
286 response = doGetObjectPropList();
287 break;
Mike Lockwood56118b52010-05-11 17:16:59 -0400288 case MTP_OPERATION_GET_OBJECT_INFO:
289 response = doGetObjectInfo();
290 break;
291 case MTP_OPERATION_GET_OBJECT:
292 response = doGetObject();
293 break;
Mike Lockwood44e82dd2010-11-23 09:08:01 -0500294 case MTP_OPERATION_GET_PARTIAL_OBJECT:
295 response = doGetPartialObject();
296 break;
Mike Lockwood56118b52010-05-11 17:16:59 -0400297 case MTP_OPERATION_SEND_OBJECT_INFO:
298 response = doSendObjectInfo();
299 break;
300 case MTP_OPERATION_SEND_OBJECT:
301 response = doSendObject();
302 break;
303 case MTP_OPERATION_DELETE_OBJECT:
304 response = doDeleteObject();
305 break;
306 case MTP_OPERATION_GET_OBJECT_PROP_DESC:
Mike Lockwood767c5e42010-06-30 17:00:35 -0400307 response = doGetObjectPropDesc();
308 break;
Mike Lockwood59e3f0d2010-09-02 14:57:30 -0400309 case MTP_OPERATION_GET_DEVICE_PROP_DESC:
310 response = doGetDevicePropDesc();
311 break;
Mike Lockwood56118b52010-05-11 17:16:59 -0400312 default:
Mike Lockwood9f679242010-09-23 22:32:05 -0400313 LOGE("got unsupported command %s", MtpDebug::getOperationCodeName(operation));
Mike Lockwood56118b52010-05-11 17:16:59 -0400314 response = MTP_RESPONSE_OPERATION_NOT_SUPPORTED;
315 break;
316 }
317
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400318 if (response == MTP_RESPONSE_TRANSACTION_CANCELLED)
319 return false;
Mike Lockwood56118b52010-05-11 17:16:59 -0400320 mResponse.setResponseCode(response);
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400321 return true;
Mike Lockwood56118b52010-05-11 17:16:59 -0400322}
323
324MtpResponseCode MtpServer::doGetDeviceInfo() {
325 MtpStringBuffer string;
Mike Lockwood622ccdc2010-06-14 17:58:08 -0700326 char prop_value[PROPERTY_VALUE_MAX];
Mike Lockwood56118b52010-05-11 17:16:59 -0400327
Mike Lockwood4b322ce2010-08-10 07:37:50 -0400328 MtpObjectFormatList* playbackFormats = mDatabase->getSupportedPlaybackFormats();
329 MtpObjectFormatList* captureFormats = mDatabase->getSupportedCaptureFormats();
330 MtpDevicePropertyList* deviceProperties = mDatabase->getSupportedDeviceProperties();
331
Mike Lockwood56118b52010-05-11 17:16:59 -0400332 // fill in device info
333 mData.putUInt16(MTP_STANDARD_VERSION);
334 mData.putUInt32(6); // MTP Vendor Extension ID
335 mData.putUInt16(MTP_STANDARD_VERSION);
336 string.set("microsoft.com: 1.0;");
337 mData.putString(string); // MTP Extensions
338 mData.putUInt16(0); //Functional Mode
339 mData.putAUInt16(kSupportedOperationCodes,
340 sizeof(kSupportedOperationCodes) / sizeof(uint16_t)); // Operations Supported
Mike Lockwoodbe125a52010-07-12 18:54:16 -0400341 mData.putAUInt16(kSupportedEventCodes,
342 sizeof(kSupportedEventCodes) / sizeof(uint16_t)); // Events Supported
Mike Lockwood4b322ce2010-08-10 07:37:50 -0400343 mData.putAUInt16(deviceProperties); // Device Properties Supported
344 mData.putAUInt16(captureFormats); // Capture Formats
345 mData.putAUInt16(playbackFormats); // Playback Formats
Mike Lockwood56118b52010-05-11 17:16:59 -0400346 // FIXME
347 string.set("Google, Inc.");
348 mData.putString(string); // Manufacturer
Mike Lockwood622ccdc2010-06-14 17:58:08 -0700349
350 property_get("ro.product.model", prop_value, "MTP Device");
351 string.set(prop_value);
Mike Lockwood56118b52010-05-11 17:16:59 -0400352 mData.putString(string); // Model
353 string.set("1.0");
354 mData.putString(string); // Device Version
Mike Lockwood622ccdc2010-06-14 17:58:08 -0700355
356 property_get("ro.serialno", prop_value, "????????");
357 string.set(prop_value);
Mike Lockwood56118b52010-05-11 17:16:59 -0400358 mData.putString(string); // Serial Number
359
Mike Lockwood4b322ce2010-08-10 07:37:50 -0400360 delete playbackFormats;
361 delete captureFormats;
362 delete deviceProperties;
363
Mike Lockwood56118b52010-05-11 17:16:59 -0400364 return MTP_RESPONSE_OK;
365}
366
367MtpResponseCode MtpServer::doOpenSession() {
368 if (mSessionOpen) {
369 mResponse.setParameter(1, mSessionID);
370 return MTP_RESPONSE_SESSION_ALREADY_OPEN;
371 }
372 mSessionID = mRequest.getParameter(1);
373 mSessionOpen = true;
Mike Lockwood2837eef2010-08-31 16:25:12 -0400374
375 mDatabase->sessionStarted();
376
Mike Lockwood56118b52010-05-11 17:16:59 -0400377 return MTP_RESPONSE_OK;
378}
379
380MtpResponseCode MtpServer::doCloseSession() {
381 if (!mSessionOpen)
382 return MTP_RESPONSE_SESSION_NOT_OPEN;
383 mSessionID = 0;
384 mSessionOpen = false;
Mike Lockwood2837eef2010-08-31 16:25:12 -0400385 mDatabase->sessionEnded();
Mike Lockwood56118b52010-05-11 17:16:59 -0400386 return MTP_RESPONSE_OK;
387}
388
389MtpResponseCode MtpServer::doGetStorageIDs() {
390 if (!mSessionOpen)
391 return MTP_RESPONSE_SESSION_NOT_OPEN;
392
393 int count = mStorages.size();
394 mData.putUInt32(count);
395 for (int i = 0; i < count; i++)
396 mData.putUInt32(mStorages[i]->getStorageID());
397
398 return MTP_RESPONSE_OK;
399}
400
401MtpResponseCode MtpServer::doGetStorageInfo() {
402 MtpStringBuffer string;
403
404 if (!mSessionOpen)
405 return MTP_RESPONSE_SESSION_NOT_OPEN;
406 MtpStorageID id = mRequest.getParameter(1);
407 MtpStorage* storage = getStorage(id);
408 if (!storage)
409 return MTP_RESPONSE_INVALID_STORAGE_ID;
410
411 mData.putUInt16(storage->getType());
412 mData.putUInt16(storage->getFileSystemType());
413 mData.putUInt16(storage->getAccessCapability());
414 mData.putUInt64(storage->getMaxCapacity());
415 mData.putUInt64(storage->getFreeSpace());
416 mData.putUInt32(1024*1024*1024); // Free Space in Objects
417 string.set(storage->getDescription());
418 mData.putString(string);
419 mData.putEmptyString(); // Volume Identifier
420
421 return MTP_RESPONSE_OK;
422}
423
424MtpResponseCode MtpServer::doGetObjectPropsSupported() {
425 if (!mSessionOpen)
426 return MTP_RESPONSE_SESSION_NOT_OPEN;
427 MtpObjectFormat format = mRequest.getParameter(1);
Mike Lockwood4cb956c2010-12-07 10:51:20 -0800428 MtpObjectPropertyList* properties = mDatabase->getSupportedObjectProperties(format);
Mike Lockwood4b322ce2010-08-10 07:37:50 -0400429 mData.putAUInt16(properties);
Mike Lockwood33ea5a42010-08-10 15:11:32 -0400430 delete properties;
Mike Lockwood56118b52010-05-11 17:16:59 -0400431 return MTP_RESPONSE_OK;
432}
433
434MtpResponseCode MtpServer::doGetObjectHandles() {
435 if (!mSessionOpen)
436 return MTP_RESPONSE_SESSION_NOT_OPEN;
437 MtpStorageID storageID = mRequest.getParameter(1); // 0xFFFFFFFF for all storage
Mike Lockwood37433652010-05-19 15:12:14 -0400438 MtpObjectFormat format = mRequest.getParameter(2); // 0 for all formats
Mike Lockwood56118b52010-05-11 17:16:59 -0400439 MtpObjectHandle parent = mRequest.getParameter(3); // 0xFFFFFFFF for objects with no parent
440 // 0x00000000 for all objects?
Mike Lockwoodd21eac92010-07-03 00:44:05 -0400441 if (parent == 0xFFFFFFFF)
442 parent = 0;
Mike Lockwood56118b52010-05-11 17:16:59 -0400443
444 MtpObjectHandleList* handles = mDatabase->getObjectList(storageID, format, parent);
445 mData.putAUInt32(handles);
446 delete handles;
447 return MTP_RESPONSE_OK;
448}
449
Mike Lockwood7a047c82010-08-02 10:52:20 -0400450MtpResponseCode MtpServer::doGetNumObjects() {
451 if (!mSessionOpen)
452 return MTP_RESPONSE_SESSION_NOT_OPEN;
453 MtpStorageID storageID = mRequest.getParameter(1); // 0xFFFFFFFF for all storage
454 MtpObjectFormat format = mRequest.getParameter(2); // 0 for all formats
455 MtpObjectHandle parent = mRequest.getParameter(3); // 0xFFFFFFFF for objects with no parent
456 // 0x00000000 for all objects?
457 if (parent == 0xFFFFFFFF)
458 parent = 0;
459
460 int count = mDatabase->getNumObjects(storageID, format, parent);
461 if (count >= 0) {
462 mResponse.setParameter(1, count);
463 return MTP_RESPONSE_OK;
464 } else {
465 mResponse.setParameter(1, 0);
466 return MTP_RESPONSE_INVALID_OBJECT_HANDLE;
467 }
468}
469
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400470MtpResponseCode MtpServer::doGetObjectReferences() {
471 if (!mSessionOpen)
472 return MTP_RESPONSE_SESSION_NOT_OPEN;
473 MtpStorageID handle = mRequest.getParameter(1);
Mike Lockwood828d19d2010-08-10 15:20:35 -0400474
475 // FIXME - check for invalid object handle
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400476 MtpObjectHandleList* handles = mDatabase->getObjectReferences(handle);
Mike Lockwood828d19d2010-08-10 15:20:35 -0400477 if (handles) {
478 mData.putAUInt32(handles);
479 delete handles;
480 } else {
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400481 mData.putEmptyArray();
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400482 }
Mike Lockwood9a2046f2010-08-03 15:30:09 -0400483 return MTP_RESPONSE_OK;
484}
485
486MtpResponseCode MtpServer::doSetObjectReferences() {
487 if (!mSessionOpen)
488 return MTP_RESPONSE_SESSION_NOT_OPEN;
489 MtpStorageID handle = mRequest.getParameter(1);
490 MtpObjectHandleList* references = mData.getAUInt32();
491 MtpResponseCode result = mDatabase->setObjectReferences(handle, references);
492 delete references;
493 return result;
494}
495
Mike Lockwood56118b52010-05-11 17:16:59 -0400496MtpResponseCode MtpServer::doGetObjectPropValue() {
497 MtpObjectHandle handle = mRequest.getParameter(1);
498 MtpObjectProperty property = mRequest.getParameter(2);
Mike Lockwood828d19d2010-08-10 15:20:35 -0400499 LOGD("GetObjectPropValue %d %s\n", handle,
500 MtpDebug::getObjectPropCodeName(property));
Mike Lockwood56118b52010-05-11 17:16:59 -0400501
Mike Lockwood828d19d2010-08-10 15:20:35 -0400502 return mDatabase->getObjectPropertyValue(handle, property, mData);
503}
504
505MtpResponseCode MtpServer::doSetObjectPropValue() {
506 MtpObjectHandle handle = mRequest.getParameter(1);
507 MtpObjectProperty property = mRequest.getParameter(2);
508 LOGD("SetObjectPropValue %d %s\n", handle,
509 MtpDebug::getObjectPropCodeName(property));
510
511 return mDatabase->setObjectPropertyValue(handle, property, mData);
512}
513
514MtpResponseCode MtpServer::doGetDevicePropValue() {
515 MtpDeviceProperty property = mRequest.getParameter(1);
516 LOGD("GetDevicePropValue %s\n",
517 MtpDebug::getDevicePropCodeName(property));
518
519 return mDatabase->getDevicePropertyValue(property, mData);
520}
521
522MtpResponseCode MtpServer::doSetDevicePropValue() {
523 MtpDeviceProperty property = mRequest.getParameter(1);
524 LOGD("SetDevicePropValue %s\n",
525 MtpDebug::getDevicePropCodeName(property));
526
527 return mDatabase->setDevicePropertyValue(property, mData);
528}
529
530MtpResponseCode MtpServer::doResetDevicePropValue() {
531 MtpDeviceProperty property = mRequest.getParameter(1);
532 LOGD("ResetDevicePropValue %s\n",
533 MtpDebug::getDevicePropCodeName(property));
534
535 return mDatabase->resetDeviceProperty(property);
Mike Lockwood56118b52010-05-11 17:16:59 -0400536}
537
Mike Lockwoode2ad6ec2010-10-14 18:03:25 -0400538MtpResponseCode MtpServer::doGetObjectPropList() {
539
540 MtpObjectHandle handle = mRequest.getParameter(1);
Mike Lockwood7d7fb632010-12-01 18:46:23 -0500541 // use uint32_t so we can support 0xFFFFFFFF
542 uint32_t format = mRequest.getParameter(2);
543 uint32_t property = mRequest.getParameter(3);
Mike Lockwoode2ad6ec2010-10-14 18:03:25 -0400544 int groupCode = mRequest.getParameter(4);
Mike Lockwoode3634c32010-11-23 18:45:25 -0500545 int depth = mRequest.getParameter(5);
Mike Lockwoode2ad6ec2010-10-14 18:03:25 -0400546 LOGD("GetObjectPropList %d format: %s property: %s group: %d depth: %d\n",
547 handle, MtpDebug::getFormatCodeName(format),
548 MtpDebug::getObjectPropCodeName(property), groupCode, depth);
549
550 return mDatabase->getObjectPropertyList(handle, format, property, groupCode, depth, mData);
551}
552
Mike Lockwood56118b52010-05-11 17:16:59 -0400553MtpResponseCode MtpServer::doGetObjectInfo() {
554 MtpObjectHandle handle = mRequest.getParameter(1);
555 return mDatabase->getObjectInfo(handle, mData);
556}
557
558MtpResponseCode MtpServer::doGetObject() {
559 MtpObjectHandle handle = mRequest.getParameter(1);
Mike Lockwood42dbfa52010-06-22 15:03:53 -0400560 MtpString pathBuf;
Mike Lockwood56118b52010-05-11 17:16:59 -0400561 int64_t fileLength;
Mike Lockwood365e03e2010-12-08 16:08:01 -0800562 MtpObjectFormat format;
563 int result = mDatabase->getObjectFilePath(handle, pathBuf, fileLength, format);
Mike Lockwood59c777a2010-08-02 10:37:41 -0400564 if (result != MTP_RESPONSE_OK)
565 return result;
Mike Lockwood56118b52010-05-11 17:16:59 -0400566
Mike Lockwood59c777a2010-08-02 10:37:41 -0400567 const char* filePath = (const char *)pathBuf;
Mike Lockwood56118b52010-05-11 17:16:59 -0400568 mtp_file_range mfr;
Mike Lockwood42dbfa52010-06-22 15:03:53 -0400569 mfr.fd = open(filePath, O_RDONLY);
570 if (mfr.fd < 0) {
571 return MTP_RESPONSE_GENERAL_ERROR;
572 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400573 mfr.offset = 0;
574 mfr.length = fileLength;
575
576 // send data header
577 mData.setOperationCode(mRequest.getOperationCode());
578 mData.setTransactionID(mRequest.getTransactionID());
Mike Lockwooddb774312010-10-11 17:31:44 -0400579 mData.writeDataHeader(mFD, fileLength + MTP_CONTAINER_HEADER_SIZE);
Mike Lockwood56118b52010-05-11 17:16:59 -0400580
581 // then transfer the file
582 int ret = ioctl(mFD, MTP_SEND_FILE, (unsigned long)&mfr);
Mike Lockwood42dbfa52010-06-22 15:03:53 -0400583 close(mfr.fd);
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400584 if (ret < 0) {
585 if (errno == ECANCELED)
586 return MTP_RESPONSE_TRANSACTION_CANCELLED;
587 else
588 return MTP_RESPONSE_GENERAL_ERROR;
589 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400590 return MTP_RESPONSE_OK;
591}
592
Mike Lockwood44e82dd2010-11-23 09:08:01 -0500593MtpResponseCode MtpServer::doGetPartialObject() {
594 MtpObjectHandle handle = mRequest.getParameter(1);
595 uint32_t offset = mRequest.getParameter(2);
596 uint32_t length = mRequest.getParameter(3);
597 MtpString pathBuf;
598 int64_t fileLength;
Mike Lockwood365e03e2010-12-08 16:08:01 -0800599 MtpObjectFormat format;
600 int result = mDatabase->getObjectFilePath(handle, pathBuf, fileLength, format);
Mike Lockwood44e82dd2010-11-23 09:08:01 -0500601 if (result != MTP_RESPONSE_OK)
602 return result;
603 if (offset + length > fileLength)
604 length = fileLength - offset;
605
606 const char* filePath = (const char *)pathBuf;
607 mtp_file_range mfr;
608 mfr.fd = open(filePath, O_RDONLY);
609 if (mfr.fd < 0) {
610 return MTP_RESPONSE_GENERAL_ERROR;
611 }
612 mfr.offset = offset;
613 mfr.length = length;
614 mResponse.setParameter(1, length);
615
616 // send data header
617 mData.setOperationCode(mRequest.getOperationCode());
618 mData.setTransactionID(mRequest.getTransactionID());
619 mData.writeDataHeader(mFD, length + MTP_CONTAINER_HEADER_SIZE);
620
621 // then transfer the file
622 int ret = ioctl(mFD, MTP_SEND_FILE, (unsigned long)&mfr);
623 close(mfr.fd);
624 if (ret < 0) {
625 if (errno == ECANCELED)
626 return MTP_RESPONSE_TRANSACTION_CANCELLED;
627 else
628 return MTP_RESPONSE_GENERAL_ERROR;
629 }
630 return MTP_RESPONSE_OK;
631}
632
Mike Lockwood56118b52010-05-11 17:16:59 -0400633MtpResponseCode MtpServer::doSendObjectInfo() {
634 MtpString path;
635 MtpStorageID storageID = mRequest.getParameter(1);
636 MtpStorage* storage = getStorage(storageID);
637 MtpObjectHandle parent = mRequest.getParameter(2);
638 if (!storage)
639 return MTP_RESPONSE_INVALID_STORAGE_ID;
640
641 // special case the root
Mike Lockwoodd21eac92010-07-03 00:44:05 -0400642 if (parent == MTP_PARENT_ROOT) {
Mike Lockwood56118b52010-05-11 17:16:59 -0400643 path = storage->getPath();
Mike Lockwoodd21eac92010-07-03 00:44:05 -0400644 parent = 0;
645 } else {
Mike Lockwood365e03e2010-12-08 16:08:01 -0800646 int64_t length;
647 MtpObjectFormat format;
648 int result = mDatabase->getObjectFilePath(parent, path, length, format);
Mike Lockwood59c777a2010-08-02 10:37:41 -0400649 if (result != MTP_RESPONSE_OK)
650 return result;
Mike Lockwood365e03e2010-12-08 16:08:01 -0800651 if (format != MTP_FORMAT_ASSOCIATION)
652 return MTP_RESPONSE_INVALID_PARENT_OBJECT;
Mike Lockwood56118b52010-05-11 17:16:59 -0400653 }
654
655 // read only the fields we need
656 mData.getUInt32(); // storage ID
657 MtpObjectFormat format = mData.getUInt16();
658 mData.getUInt16(); // protection status
659 mSendObjectFileSize = mData.getUInt32();
660 mData.getUInt16(); // thumb format
661 mData.getUInt32(); // thumb compressed size
662 mData.getUInt32(); // thumb pix width
663 mData.getUInt32(); // thumb pix height
664 mData.getUInt32(); // image pix width
665 mData.getUInt32(); // image pix height
666 mData.getUInt32(); // image bit depth
667 mData.getUInt32(); // parent
668 uint16_t associationType = mData.getUInt16();
669 uint32_t associationDesc = mData.getUInt32(); // association desc
670 mData.getUInt32(); // sequence number
671 MtpStringBuffer name, created, modified;
672 mData.getString(name); // file name
673 mData.getString(created); // date created
674 mData.getString(modified); // date modified
675 // keywords follow
676
Mike Lockwood0b58c192010-11-17 15:42:09 -0500677 LOGD("name: %s format: %04X\n", (const char *)name, format);
Mike Lockwoodd0782672010-05-14 15:35:17 -0400678 time_t modifiedTime;
Mike Lockwood56118b52010-05-11 17:16:59 -0400679 if (!parseDateTime(modified, modifiedTime))
680 modifiedTime = 0;
Mike Lockwood56118b52010-05-11 17:16:59 -0400681
682 if (path[path.size() - 1] != '/')
683 path += "/";
684 path += (const char *)name;
685
Mike Lockwood365e03e2010-12-08 16:08:01 -0800686 // file should not already exist
687 if (access(path, R_OK) == 0)
688 return MTP_RESPONSE_GENERAL_ERROR;
689
Mike Lockwoodd815f792010-07-12 08:49:01 -0400690 MtpObjectHandle handle = mDatabase->beginSendObject((const char*)path,
691 format, parent, storageID, mSendObjectFileSize, modifiedTime);
Mike Lockwoodd0782672010-05-14 15:35:17 -0400692 if (handle == kInvalidObjectHandle) {
Mike Lockwood56118b52010-05-11 17:16:59 -0400693 return MTP_RESPONSE_GENERAL_ERROR;
Mike Lockwoodd0782672010-05-14 15:35:17 -0400694 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400695
696 if (format == MTP_FORMAT_ASSOCIATION) {
697 mode_t mask = umask(0);
Mike Lockwooddad69272010-07-02 15:15:07 -0400698 int ret = mkdir((const char *)path, mDirectoryPermission);
Mike Lockwood56118b52010-05-11 17:16:59 -0400699 umask(mask);
700 if (ret && ret != -EEXIST)
701 return MTP_RESPONSE_GENERAL_ERROR;
Mike Lockwooddad69272010-07-02 15:15:07 -0400702 chown((const char *)path, getuid(), mFileGroup);
Mike Lockwood56118b52010-05-11 17:16:59 -0400703 } else {
704 mSendObjectFilePath = path;
705 // save the handle for the SendObject call, which should follow
706 mSendObjectHandle = handle;
Mike Lockwoodd815f792010-07-12 08:49:01 -0400707 mSendObjectFormat = format;
Mike Lockwood56118b52010-05-11 17:16:59 -0400708 }
709
710 mResponse.setParameter(1, storageID);
Mike Lockwood828d19d2010-08-10 15:20:35 -0400711 mResponse.setParameter(2, parent);
Mike Lockwood56118b52010-05-11 17:16:59 -0400712 mResponse.setParameter(3, handle);
713
714 return MTP_RESPONSE_OK;
715}
716
717MtpResponseCode MtpServer::doSendObject() {
Mike Lockwoodd815f792010-07-12 08:49:01 -0400718 MtpResponseCode result = MTP_RESPONSE_OK;
719 mode_t mask;
720 int ret;
Mike Lockwood413577d2010-11-16 17:38:43 -0500721 uint64_t actualSize = -1;
Mike Lockwoodd815f792010-07-12 08:49:01 -0400722
Mike Lockwood56118b52010-05-11 17:16:59 -0400723 if (mSendObjectHandle == kInvalidObjectHandle) {
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400724 LOGE("Expected SendObjectInfo before SendObject");
Mike Lockwoodd815f792010-07-12 08:49:01 -0400725 result = MTP_RESPONSE_NO_VALID_OBJECT_INFO;
726 goto done;
Mike Lockwood56118b52010-05-11 17:16:59 -0400727 }
728
729 // read the header
Mike Lockwoodd815f792010-07-12 08:49:01 -0400730 ret = mData.readDataHeader(mFD);
Mike Lockwood56118b52010-05-11 17:16:59 -0400731 // FIXME - check for errors here.
732
733 // reset so we don't attempt to send this back
734 mData.reset();
735
736 mtp_file_range mfr;
Mike Lockwood42dbfa52010-06-22 15:03:53 -0400737 mfr.fd = open(mSendObjectFilePath, O_RDWR | O_CREAT | O_TRUNC);
738 if (mfr.fd < 0) {
Mike Lockwoodd815f792010-07-12 08:49:01 -0400739 result = MTP_RESPONSE_GENERAL_ERROR;
740 goto done;
Mike Lockwood42dbfa52010-06-22 15:03:53 -0400741 }
Mike Lockwooddad69272010-07-02 15:15:07 -0400742 fchown(mfr.fd, getuid(), mFileGroup);
743 // set permissions
Mike Lockwoodd815f792010-07-12 08:49:01 -0400744 mask = umask(0);
Mike Lockwooddad69272010-07-02 15:15:07 -0400745 fchmod(mfr.fd, mFilePermission);
746 umask(mask);
747
Mike Lockwood56118b52010-05-11 17:16:59 -0400748 mfr.offset = 0;
749 mfr.length = mSendObjectFileSize;
750
Mike Lockwood0b58c192010-11-17 15:42:09 -0500751 LOGD("receiving %s\n", (const char *)mSendObjectFilePath);
Mike Lockwood56118b52010-05-11 17:16:59 -0400752 // transfer the file
753 ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr);
Mike Lockwood42dbfa52010-06-22 15:03:53 -0400754 close(mfr.fd);
Mike Lockwooddad69272010-07-02 15:15:07 -0400755
Mike Lockwood3e6616d2010-06-29 18:11:52 -0400756 LOGV("MTP_RECEIVE_FILE returned %d", ret);
Mike Lockwood56118b52010-05-11 17:16:59 -0400757
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400758 if (ret < 0) {
759 unlink(mSendObjectFilePath);
760 if (errno == ECANCELED)
Mike Lockwoodd815f792010-07-12 08:49:01 -0400761 result = MTP_RESPONSE_TRANSACTION_CANCELLED;
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400762 else
Mike Lockwoodd815f792010-07-12 08:49:01 -0400763 result = MTP_RESPONSE_GENERAL_ERROR;
Mike Lockwood413577d2010-11-16 17:38:43 -0500764 } else if (mSendObjectFileSize == 0xFFFFFFFF) {
765 // actual size is likely > 4 gig so stat the file to compute actual length
766 struct stat s;
767 if (lstat(mSendObjectFilePath, &s) == 0) {
768 actualSize = s.st_size;
769 LOGD("actualSize: %lld\n", actualSize);
770 }
Mike Lockwooda82d3c52010-06-04 09:49:21 -0400771 }
Mike Lockwoodd815f792010-07-12 08:49:01 -0400772
773done:
774 mDatabase->endSendObject(mSendObjectFilePath, mSendObjectHandle, mSendObjectFormat,
Mike Lockwood413577d2010-11-16 17:38:43 -0500775 actualSize, result == MTP_RESPONSE_OK);
Mike Lockwoodd815f792010-07-12 08:49:01 -0400776 mSendObjectHandle = kInvalidObjectHandle;
777 mSendObjectFormat = 0;
778 return result;
Mike Lockwood56118b52010-05-11 17:16:59 -0400779}
780
Mike Lockwoodccb6e962010-09-13 17:15:58 -0400781static void deleteRecursive(const char* path) {
782 char pathbuf[PATH_MAX];
783 int pathLength = strlen(path);
784 if (pathLength >= sizeof(pathbuf) - 1) {
785 LOGE("path too long: %s\n", path);
786 }
787 strcpy(pathbuf, path);
788 if (pathbuf[pathLength - 1] != '/') {
789 pathbuf[pathLength++] = '/';
790 }
791 char* fileSpot = pathbuf + pathLength;
792 int pathRemaining = sizeof(pathbuf) - pathLength - 1;
793
794 DIR* dir = opendir(path);
795 if (!dir) {
796 LOGE("opendir %s failed: %s", path, strerror(errno));
797 return;
798 }
799
800 struct dirent* entry;
801 while ((entry = readdir(dir))) {
802 const char* name = entry->d_name;
803
804 // ignore "." and ".."
805 if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) {
806 continue;
807 }
808
809 int nameLength = strlen(name);
810 if (nameLength > pathRemaining) {
811 LOGE("path %s/%s too long\n", path, name);
812 continue;
813 }
814 strcpy(fileSpot, name);
815
816 int type = entry->d_type;
817 if (entry->d_type == DT_DIR) {
818 deleteRecursive(pathbuf);
819 rmdir(pathbuf);
820 } else {
821 unlink(pathbuf);
822 }
823 }
Mike Lockwooda108b2f2010-11-11 11:22:32 -0500824 closedir(dir);
Mike Lockwoodccb6e962010-09-13 17:15:58 -0400825}
826
827static void deletePath(const char* path) {
828 struct stat statbuf;
829 if (stat(path, &statbuf) == 0) {
830 if (S_ISDIR(statbuf.st_mode)) {
831 deleteRecursive(path);
832 rmdir(path);
833 } else {
834 unlink(path);
835 }
836 } else {
837 LOGE("deletePath stat failed for %s: %s", path, strerror(errno));
838 }
839}
840
Mike Lockwood56118b52010-05-11 17:16:59 -0400841MtpResponseCode MtpServer::doDeleteObject() {
842 MtpObjectHandle handle = mRequest.getParameter(1);
Mike Lockwoodccb6e962010-09-13 17:15:58 -0400843 MtpObjectFormat format = mRequest.getParameter(2);
Mike Lockwood56118b52010-05-11 17:16:59 -0400844 // FIXME - support deleting all objects if handle is 0xFFFFFFFF
845 // FIXME - implement deleting objects by format
Mike Lockwood56118b52010-05-11 17:16:59 -0400846
847 MtpString filePath;
848 int64_t fileLength;
Mike Lockwood365e03e2010-12-08 16:08:01 -0800849 int result = mDatabase->getObjectFilePath(handle, filePath, fileLength, format);
Mike Lockwood59c777a2010-08-02 10:37:41 -0400850 if (result == MTP_RESPONSE_OK) {
851 LOGV("deleting %s", (const char *)filePath);
Mike Lockwoodccb6e962010-09-13 17:15:58 -0400852 deletePath((const char *)filePath);
Mike Lockwood59c777a2010-08-02 10:37:41 -0400853 return mDatabase->deleteFile(handle);
854 } else {
855 return result;
856 }
Mike Lockwood56118b52010-05-11 17:16:59 -0400857}
858
859MtpResponseCode MtpServer::doGetObjectPropDesc() {
Mike Lockwood767c5e42010-06-30 17:00:35 -0400860 MtpObjectProperty propCode = mRequest.getParameter(1);
Mike Lockwood56118b52010-05-11 17:16:59 -0400861 MtpObjectFormat format = mRequest.getParameter(2);
Mike Lockwood828d19d2010-08-10 15:20:35 -0400862 LOGD("GetObjectPropDesc %s %s\n", MtpDebug::getObjectPropCodeName(propCode),
863 MtpDebug::getFormatCodeName(format));
864 MtpProperty* property = mDatabase->getObjectPropertyDesc(propCode, format);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400865 if (!property)
866 return MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED;
Mike Lockwood767c5e42010-06-30 17:00:35 -0400867 property->write(mData);
Mike Lockwood828d19d2010-08-10 15:20:35 -0400868 delete property;
869 return MTP_RESPONSE_OK;
870}
871
872MtpResponseCode MtpServer::doGetDevicePropDesc() {
873 MtpDeviceProperty propCode = mRequest.getParameter(1);
874 LOGD("GetDevicePropDesc %s\n", MtpDebug::getDevicePropCodeName(propCode));
875 MtpProperty* property = mDatabase->getDevicePropertyDesc(propCode);
876 if (!property)
877 return MTP_RESPONSE_DEVICE_PROP_NOT_SUPPORTED;
878 property->write(mData);
879 delete property;
Mike Lockwood767c5e42010-06-30 17:00:35 -0400880 return MTP_RESPONSE_OK;
Mike Lockwood56118b52010-05-11 17:16:59 -0400881}
Mike Lockwood8d3257a2010-05-14 10:10:36 -0400882
883} // namespace android