blob: 899645847798e74e7613a7eda10eac14be715286 [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#define LOG_TAG "mtp_usb"
18#include "cutils/log.h"
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <sys/types.h>
23#include <fcntl.h>
24
25#include "MtpServer.h"
26#include "MtpStorage.h"
27
28
29static void enable_usb_function(const char* name, bool enable) {
30 char path[PATH_MAX];
31
32 snprintf(path, sizeof(path), "/sys/class/usb_composite/%s/enable", name);
33 int fd = open(path, O_RDWR);
34 if (fd < 0) {
35 fprintf(stderr, "could not open %s in enable_usb_function\n", path);
36 exit(1);
37 }
38 write(fd, enable ? "1" : "0", 2);
39 close(fd);
40}
41
42int main() {
43 // first disable UMS and enable MTP USB functions
44 enable_usb_function("usb_mass_storage", false);
45 enable_usb_function("mtp", true);
46
47 int fd = open("/dev/mtp_usb", O_RDWR);
48 printf("open returned %d\n", fd);
49 if (fd < 0) {
50 fprintf(stderr, "could not open MTP driver\n");
51 return -1;
52 }
53
54 MtpServer server(fd, "/data/data/mtp/mtp.db");
55 server.addStorage("/sdcard");
56 server.scanStorage();
57 server.run();
58
59 close(fd);
60 return 0;
61}
62