aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJassi Brar <jaswinder.singh@linaro.org>2015-05-27 13:07:13 +0530
committerJassi Brar <jaswinder.singh@linaro.org>2015-05-27 13:07:13 +0530
commit104e1bcd69910c50bad44f98b3c952bd5f1e7316 (patch)
treeeb1c445b4970b4e7f274d413a0c08762892adb8e
parent68c96e906dc527f580893d430afb261ec6a9a52b (diff)
Customize for headless platforms
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
-rw-r--r--CMakeLists.txt5
-rw-r--r--README50
-rw-r--r--server/CMakeLists.txt1
-rw-r--r--server/server.cpp229
-rw-r--r--src/MtpServer.cpp12
5 files changed, 99 insertions, 198 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0757e39..f6c5709 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,6 +6,7 @@ include(FindPkgConfig)
include(GNUInstallDirs)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+SET(CMAKE_INSTALL_PREFIX "./install")
add_definitions(-DMTP_DEVICE -DMTP_HOST)
@@ -14,7 +15,6 @@ set(MTP_VERSION_MINOR 0)
set(MTP_VERSION_PATCH 0)
find_package(Boost REQUIRED COMPONENTS thread system filesystem unit_test_framework)
-pkg_check_modules(DBUSCPP REQUIRED dbus-cpp)
pkg_check_modules(GLOG REQUIRED libglog)
set(
@@ -61,7 +61,6 @@ include_directories(
include/
libusbhost/include
${Boost_INCLUDE_DIRS}
- ${DBUSCPP_INCLUDE_DIRS}
)
add_library(
@@ -71,9 +70,7 @@ add_library(
target_link_libraries(
mtpserver
- android-properties
${GLOG_LIBRARIES}
- ${DBUSCPP_LIBRARIES}
)
set_target_properties(
diff --git a/README b/README
new file mode 100644
index 0000000..6df73a5
--- /dev/null
+++ b/README
@@ -0,0 +1,50 @@
+To Build And Install
+********************
+// cmake can't do 'distclean' so a separate directory
+// to just do 'rm -rf build/*'
+$ cd build/
+
+// do the configure
+$ cmake ../
+
+// package will be installed in 'build/install/' because we add
+// SET(CMAKE_INSTALL_PREFIX "./install") in CMakeLists.txt
+$ make install
+
+// go back to source directory
+$ cd ../
+
+// to do "distclean"
+$ rm -rf build/*
+
+
+Run
+***
+1) The MTP function needs to be setup over Configfs before it could be
+ enumerated by the host. Do as follows:
+
+ target$ mount -t configfs none /sys/kernel/config/
+ target$ cd /sys/kernel/config/usb_gadget/
+ target$ mkdir mtp
+ target$ cd mtp
+ target$ echo 0x0101 > bcdUSB
+ target$ echo 0xabcd > idVendor
+ target$ echo 0x1234 > idProduct
+ target$ echo 0x0232 > bcdDevice
+ target$ mkdir -p strings/0x409
+ target$ echo "1122334455" > strings/0x409/serialnumber
+ target$ echo "Socionext" > strings/0x409/manufacturer
+ target$ echo "SN-MTP" > strings/0x409/product
+ target$ mkdir -p functions/mtp.usb0
+ target$ mkdir -p configs/c.1/strings/0x409
+ target$ echo "MTP" > configs/c.1/strings/0x409/configuration
+ target$ echo 250 > configs/c.1/MaxPower
+ target$ ln -s functions/mtp.usb0 configs/c.1/
+ target$ ls /sys/class/udc > UDC
+
+2) Make sure you export the colon seperated list of directories to be
+ exported over MTP as 'MTP_EXPORT_DIRS'. Also make sure the directory
+ names don't clash.
+
+ target$ export MTP_EXPORT_DIRS=exportA:exportB:exportC
+ target$ mtp-server &
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index 411ff46..9acb974 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -11,7 +11,6 @@ target_link_libraries(
mtp-server
mtpserver
usbhost
- android-properties
${Boost_LIBRARIES}
${Boost_thread_LIBRARIES}
${Boost_system_LIBRARIES}
diff --git a/server/server.cpp b/server/server.cpp
index 9335f1d..b57983d 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -20,7 +20,10 @@
#include <MtpServer.h>
#include <MtpStorage.h>
+#include <cstdlib>
#include <iostream>
+#include <sstream>
+#include <string>
#include <signal.h>
#include <sys/types.h>
@@ -31,101 +34,21 @@
#include <libintl.h>
#include <locale.h>
-#include <hybris/properties/properties.h>
#include <glog/logging.h>
-#include <core/dbus/bus.h>
-#include <core/dbus/object.h>
-#include <core/dbus/property.h>
-#include <core/dbus/service.h>
-#include <core/dbus/signal.h>
-
-#include <core/dbus/asio/executor.h>
-#include <core/dbus/types/stl/tuple.h>
-#include <core/dbus/types/stl/vector.h>
-#include <core/dbus/types/struct.h>
-
-
-namespace dbus = core::dbus;
using namespace android;
-namespace core
-{
-dbus::Bus::Ptr the_session_bus()
-{
- static dbus::Bus::Ptr session_bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::session);
- return session_bus;
-}
-
-struct UnityGreeter
-{
- struct Properties
- {
- struct IsActive
- {
- inline static std::string name()
- {
- return "IsActive";
- };
- typedef UnityGreeter Interface;
- typedef bool ValueType;
- static const bool readable = true;
- static const bool writable = false;
- };
- };
-};
-}
-
-namespace core
-{
-namespace dbus
-{
-namespace traits
-{
-template<>
-struct Service<core::UnityGreeter>
-{
- inline static const std::string& interface_name()
- {
- static const std::string s
- {
- "com.canonical.UnityGreeter"
- };
- return s;
- }
-};
-}
-}
-}
-
-namespace
-{
-struct FileSystemConfig
-{
- static const int file_perm = 0664;
- static const int directory_perm = 0755;
-};
-
-}
-
class MtpDaemon
{
private:
struct passwd *userdata;
- dbus::Bus::Ptr bus;
- boost::thread dbus_thread;
// Mtp stuff
MtpServer* server;
MtpStorage* home_storage;
- MtpStorage* sd_card;
MtpDatabase* mtp_database;
- // Security
- std::shared_ptr<core::dbus::Property<core::UnityGreeter::Properties::IsActive> > is_active;
- bool screen_locked = true;
-
// inotify stuff
boost::thread notifier_thread;
boost::thread io_service_thread;
@@ -142,7 +65,6 @@ private:
// storage
std::map<std::string, std::tuple<MtpStorage*, bool> > removables;
- bool home_storage_added;
void add_removable_storage(const char *path, const char *name)
{
@@ -158,18 +80,14 @@ private:
storageID++;
- if (!screen_locked) {
mtp_database->addStoragePath(path,
std::string(),
removable->getStorageID(),
true);
server->addStorage(removable);
- }
removables.insert(std::pair<std::string, std::tuple<MtpStorage*, bool> >
- (name,
- std::make_tuple(removable,
- screen_locked ? false : true)));
+ (name, std::make_tuple(removable, true)));
}
void add_mountpoint_watch(const std::string& path)
@@ -240,17 +158,6 @@ private:
read_more_notify();
}
- void drive_bus()
- {
- try {
- bus->run();
- }
- catch (...) {
- PLOG(ERROR) << "There was an unexpected error in DBus; terminating.";
- server->stop();
- }
- }
-
public:
MtpDaemon(int fd):
@@ -270,60 +177,49 @@ public:
notifier_thread = boost::thread(&MtpDaemon::read_more_notify, this);
io_service_thread = boost::thread(boost::bind(&asio::io_service::run, &io_svc));
-
// MTP database.
mtp_database = new UbuntuMtpDatabase();
-
// MTP server
server = new MtpServer(
fd,
mtp_database,
false,
userdata->pw_gid,
- FileSystemConfig::file_perm,
- FileSystemConfig::directory_perm);
-
- // security / screen locking
- bus = core::the_session_bus();
- bus->install_executor(core::dbus::asio::make_executor(bus));
- dbus_thread = boost::thread(&MtpDaemon::drive_bus, this);
- auto greeter_service = dbus::Service::use_service(bus, "com.canonical.UnityGreeter");
- dbus::Object::Ptr greeter = greeter_service->object_for_path(dbus::types::ObjectPath("/"));
-
- is_active = greeter->get_property<core::UnityGreeter::Properties::IsActive>();
+ 0664,
+ 0755);
}
- void initStorage()
+ void run()
{
- char product_name[PROP_VALUE_MAX];
- // Local storage
- property_get ("ro.product.model", product_name, "Ubuntu Touch device");
+ std::istringstream ss(getenv("MTP_EXPORT_DIRS"));
+ std::string token;
home_storage = new MtpStorage(
MTP_STORAGE_FIXED_RAM,
userdata->pw_dir,
- product_name,
+ "exported_storage",
1024 * 1024 * 100, /* 100 MB reserved space, to avoid filling the disk */
false,
1024 * 1024 * 1024 * 2 /* 2GB arbitrary max file size */);
- mtp_database->addStoragePath(std::string(userdata->pw_dir) + "/Documents",
- gettext("Documents"),
- MTP_STORAGE_FIXED_RAM, false);
- mtp_database->addStoragePath(std::string(userdata->pw_dir) + "/Music",
- gettext("Music"),
- MTP_STORAGE_FIXED_RAM, false);
- mtp_database->addStoragePath(std::string(userdata->pw_dir) + "/Videos",
- gettext("Videos"),
- MTP_STORAGE_FIXED_RAM, false);
- mtp_database->addStoragePath(std::string(userdata->pw_dir) + "/Pictures",
- gettext("Pictures"),
- MTP_STORAGE_FIXED_RAM, false);
- mtp_database->addStoragePath(std::string(userdata->pw_dir) + "/Downloads",
- gettext("Downloads"),
- MTP_STORAGE_FIXED_RAM, false);
- home_storage_added = false;
+
+ while(getline(ss, token, ':')) {
+ path loc(token);
+ if (exists(loc)) {
+ char sep = '/';
+ std::string name;
+ size_t i = token.rfind(sep, token.length());
+
+ if (i != std::string::npos)
+ name = token.substr(i+1, token.length() - i);
+ else
+ name = "";
+
+ mtp_database->addStoragePath(token, name,
+ MTP_STORAGE_FIXED_RAM, false);
+ }
+ }
// Get any already-mounted removable storage.
path p(std::string("/media/") + userdata->pw_name);
@@ -343,6 +239,24 @@ public:
IN_CREATE | IN_DELETE);
}
+ if (home_storage)
+ server->addStorage(home_storage);
+
+ BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) {
+ auto t = removables.at(name);
+ MtpStorage *storage = std::get<0>(t);
+ bool added = std::get<1>(t);
+ if (!added) {
+ mtp_database->addStoragePath(storage->getPath(),
+ std::string(),
+ storage->getStorageID(),
+ true);
+ server->addStorage(storage);
+ }
+ }
+
+ // start the MtpServer main loop
+ server->run();
}
~MtpDaemon()
@@ -350,62 +264,10 @@ public:
// Cleanup
inotify_rm_watch(inotify_fd, watch_fd);
io_svc.stop();
- dbus_thread.detach();
notifier_thread.detach();
io_service_thread.join();
close(inotify_fd);
}
-
- void run()
- {
- if (is_active->get()) {
- is_active->changed().connect([this](bool active)
- {
- if (!active) {
- screen_locked = active;
- VLOG(2) << "device was unlocked, adding storage";
- if (home_storage && !home_storage_added) {
- server->addStorage(home_storage);
- home_storage_added = true;
- }
- BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) {
- auto t = removables.at(name);
- MtpStorage *storage = std::get<0>(t);
- bool added = std::get<1>(t);
- if (!added) {
- mtp_database->addStoragePath(storage->getPath(),
- std::string(),
- storage->getStorageID(),
- true);
- server->addStorage(storage);
- }
- }
- }
- });
- } else {
- screen_locked = false;
- VLOG(2) << "device is not locked, adding storage";
- if (home_storage) {
- server->addStorage(home_storage);
- home_storage_added = true;
- }
- BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) {
- auto t = removables.at(name);
- MtpStorage *storage = std::get<0>(t);
- bool added = std::get<1>(t);
- if (!added) {
- mtp_database->addStoragePath(storage->getPath(),
- std::string(),
- storage->getStorageID(),
- true);
- server->addStorage(storage);
- }
- }
- }
-
- // start the MtpServer main loop
- server->run();
- }
};
int main(int argc, char** argv)
@@ -428,7 +290,6 @@ int main(int argc, char** argv)
try {
MtpDaemon *d = new MtpDaemon(fd);
- d->initStorage();
d->run();
delete d;
diff --git a/src/MtpServer.cpp b/src/MtpServer.cpp
index 9df14ae..c5f1ca4 100644
--- a/src/MtpServer.cpp
+++ b/src/MtpServer.cpp
@@ -40,8 +40,6 @@
#include <linux/usb/f_mtp.h>
-#include <hybris/properties/properties.h>
-
#include <glog/logging.h>
namespace android {
@@ -455,7 +453,6 @@ bool MtpServer::handleRequest() {
MtpResponseCode MtpServer::doGetDeviceInfo() {
VLOG(1) << __PRETTY_FUNCTION__;
MtpStringBuffer string;
- char prop_value[PROP_VALUE_MAX];
MtpObjectFormatList* playbackFormats = mDatabase->getSupportedPlaybackFormats();
MtpObjectFormatList* captureFormats = mDatabase->getSupportedCaptureFormats();
@@ -487,18 +484,15 @@ MtpResponseCode MtpServer::doGetDeviceInfo() {
mData.putAUInt16(captureFormats); // Capture Formats
mData.putAUInt16(playbackFormats); // Playback Formats
- property_get("ro.product.manufacturer", prop_value, "unknown manufacturer");
- string.set(prop_value);
+ string.set("Socionext");
mData.putString(string); // Manufacturer
- property_get("ro.product.model", prop_value, "MTP Device");
- string.set(prop_value);
+ string.set("M8M");
mData.putString(string); // Model
string.set("1.0");
mData.putString(string); // Device Version
- property_get("ro.serialno", prop_value, "????????");
- string.set(prop_value);
+ string.set("1020304050");
mData.putString(string); // Serial Number
delete playbackFormats;