Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[buteo-mtp] Add support for android.com 1.0 MTP extension. Fixes JB#4…
…9409

It is not possible to copy/move files within device via linux desktop file
browser such as nautilus. This is because libmtp based backend implements
these features using android.com 1.0 MTP extension instead of older / more
standard Copy/MoveObject commands, and while the latter is supported by
buteo-mtp, former is not.

Implement BeginEditObject, SendPartialObject64, EndEditObject,
GetPartialObject64 and TruncateObject64 commands.

Update file reading and transmitting logic so that it supports 64 bit
offsets required by GetPartialObject64 command.

Implement file update/overwriting logic that supports 64 bit offsets
required by SendPartialObject64.

Omit ObjectChanged notifications during object editing sessions to avoid
excess interrupt endpoint transfers.

Flush object property caches after ending object edit session to avoid
feeding stale data to initiator.

Update deviceinfo configuration file template to match implementation and
relax configuration parsing to keep devices that already have existing
configuration files derived from old templates functioning as expected.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Aug 20, 2020
1 parent bb80513 commit 2b880d6
Show file tree
Hide file tree
Showing 12 changed files with 797 additions and 293 deletions.
12 changes: 11 additions & 1 deletion mts/common/mtptypes.h
@@ -1,7 +1,9 @@
/*
* This file is part of libmeegomtp package
*
* Copyright (C) 2010 Nokia Corporation. All rights reserved.
* Copyright (c) 2010 Nokia Corporation. All rights reserved.
* Copyright (c) 2013 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
*
* Contact: Santosh Puranik <santosh.puranik@nokia.com>
*
Expand Down Expand Up @@ -119,6 +121,11 @@ typedef quint16 MTPDataType;
#define MTP_OP_CopyObject 0x101A
#define MTP_OP_GetPartialObject 0x101B
#define MTP_OP_InitiateOpenCapture 0x101C
#define MTP_OP_ANDROID_GetPartialObject64 0x95C1
#define MTP_OP_ANDROID_SendPartialObject64 0x95C2
#define MTP_OP_ANDROID_TruncateObject64 0x95C3
#define MTP_OP_ANDROID_BeginEditObject 0x95C4
#define MTP_OP_ANDROID_EndEditObject 0x95C5
#define MTP_OP_GetObjectPropsSupported 0x9801
#define MTP_OP_GetObjectPropDesc 0x9802
#define MTP_OP_GetObjectPropValue 0x9803
Expand Down Expand Up @@ -217,6 +224,9 @@ typedef quint16 MTPContainerType;
(1 * sizeof(quint32)) +\
(2 * sizeof(quint8)) +\
(3 * sizeof(quint16)))
#define MTP_MAX_PACKET_SIZE 0xffffffff
#define MTP_MAX_CONTENT_SIZE (MTP_MAX_PACKET_SIZE - MTP_HEADER_SIZE)


#define MTP_PROTECTION_NoProtection 0x0000
#define MTP_PROTECTION_ReadOnly 0x0001
Expand Down
7 changes: 6 additions & 1 deletion mts/deviceinfo.xml
Expand Up @@ -34,7 +34,7 @@
<StdVersion>100</StdVersion><!--Standard Version-->
<MTPVendorExtn>0x00000006</MTPVendorExtn><!--MTP Vendor Extension ID-->
<MTPVersion>100</MTPVersion><!--MTP Version-->
<MTPExtn>microsoft.com:1.0; microsoft.com/WMPPD:11.0; </MTPExtn><!--MTP Extensions-->
<MTPExtn>microsoft.com:1.0; microsoft.com/WMPPD:11.0; android.com: 1.0;</MTPExtn> <!--MTP Extensions-->
<FnMode>0x8000</FnMode><!--Functional Mode-->
<Manufacturer>Nemo</Manufacturer><!--Manufacturer-->
<Model>Unconfigured Device</Model><!--Model-->
Expand Down Expand Up @@ -73,6 +73,11 @@
<OpCode>0x9810</OpCode><!--GetObjectReferences-->
<OpCode>0x9811</OpCode><!--SetObjectReferences-->

<OpCode>0x95c1</OpCode> <!--Get Partial Object (64bit Offset)-->
<OpCode>0x95c2</OpCode> <!--Send Partial Object (64bit Offset)-->
<OpCode>0x95c3</OpCode> <!--Truncate Object (64bit Offset)-->
<OpCode>0x95c4</OpCode> <!--Begin Edit Object-->
<OpCode>0x95c5</OpCode> <!--End Edit Object-->
</OperationsSupported>

<EventsSupported>
Expand Down
32 changes: 24 additions & 8 deletions mts/platform/deviceinfo/deviceinfo.cpp
@@ -1,7 +1,9 @@
/*
* This file is part of libmeegomtp package
*
* Copyright (C) 2010 Nokia Corporation. All rights reserved.
* Copyright (c) 2010 Nokia Corporation. All rights reserved.
* Copyright (c) 2013 - 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
*
* Contact: Deepak Kodihalli <deepak.kodihalli@nokia.com>
*
Expand Down Expand Up @@ -50,7 +52,7 @@ using namespace meegomtp1dot0;
#define VENDOREXTN_DEFAULT 0x00000006
#define DEVTYPE_DEFAULT 0x00000003
#define MTPVER_DEFAULT 100
#define MTPEXTN_DEFAULT "microsoft.com: 1.0; microsoft.com/WMPPD: 11.0; "
#define MTPEXTN_DEFAULT "microsoft.com: 1.0; microsoft.com/WMPPD: 11.0; android.com: 1.0;"
#define FNMODE_DEFAULT 0
#define MFR_DEFAULT "Nemo"
#define MODEL_DEFAULT "Nemo"
Expand Down Expand Up @@ -96,7 +98,12 @@ quint16 DeviceInfo::m_operationsSupportedTable[] = {
MTP_OP_GetObjectPropValue,
MTP_OP_SetObjectPropValue,
MTP_OP_GetObjectReferences,
MTP_OP_SetObjectReferences
MTP_OP_SetObjectReferences,
MTP_OP_ANDROID_GetPartialObject64,
MTP_OP_ANDROID_SendPartialObject64,
MTP_OP_ANDROID_TruncateObject64,
MTP_OP_ANDROID_BeginEditObject,
MTP_OP_ANDROID_EndEditObject,
};

quint16 DeviceInfo::m_audChannelTable[] = {
Expand Down Expand Up @@ -306,14 +313,18 @@ DeviceInfo::DeviceInfo( QObject *parent ) :
xmlReader.setErrorHandler(&handler);
m_xmlOk = false;

/* Note: The way deviceinfo.xml file is generated, updated and used makes it
* more like a hindrance rather than a useful feature. It contains things that
* are clearly dependant on buteo-mtp version (e.g. supported commands, events,
* formats) but the content of the file gets locked to whatever template was
* installed in the device on the first time mtp mode got activated. For this
* reason the config is augmented at runtime instead of being used as-is.
*/

if(0 == xmlReader.parse(&source))
{
MTP_LOG_CRITICAL("Failure reading deviceinfo.xml, using default hard-coded values\n");
//FIXME Hard code the QVectors themselves by default? Then we can avoid the memcpy.
for( quint32 i = 0 ; i < sizeof(m_operationsSupportedTable)/sizeof(m_operationsSupportedTable[0]); i++ )
{
m_mtpOperationsSupported.append( m_operationsSupportedTable[i] );
}
for( quint32 i = 0 ; i < sizeof(m_eventsSupportedTable)/sizeof(m_eventsSupportedTable[0]); i++ )
{
m_mtpEventsSupported.append( m_eventsSupportedTable[i] );
Expand All @@ -340,8 +351,13 @@ DeviceInfo::DeviceInfo( QObject *parent ) :
m_xmlOk = true;
}

/* The supported object formats specified in the configuration file
/* The supported opcodes, object formats, etc specified in the configuration file
* are used to augment the built-in configuration, not to override it. */
for( quint32 i = 0 ; i < sizeof(m_operationsSupportedTable)/sizeof(m_operationsSupportedTable[0]); i++ )
{
if( !m_mtpOperationsSupported.contains(m_operationsSupportedTable[i]) )
m_mtpOperationsSupported.append(m_operationsSupportedTable[i]);
}
for( quint32 i = 0 ; i < sizeof(m_commonFormatsTable)/sizeof(m_commonFormatsTable[0]); i++ )
{
if( !m_commonFormats.contains(m_commonFormatsTable[i]) )
Expand Down
17 changes: 15 additions & 2 deletions mts/platform/deviceinfo/xmlhandler.cpp
@@ -1,7 +1,9 @@
/*
* This file is part of libmeegomtp package
*
* Copyright (C) 2010 Nokia Corporation. All rights reserved.
* Copyright (c) 2010 Nokia Corporation. All rights reserved.
* Copyright (c) 2020 Jolla Ltd.
* Copyright (c) 2020 Open Mobile Platform LLC.
*
* Contact: Deepak Kodihalli <deepak.kodihalli@nokia.com>
*
Expand Down Expand Up @@ -278,7 +280,18 @@ bool XMLHandler::characters(const QString& aStr)
result = ok;
break;
case MTPEXTN:
m_devInfo->m_mtpExtension = aStr;
/* What extensions buteo-mtp can support depends on code.
*
* Adding new extensions manually does not actually make
* them supported, and already existing config files based
* on old templates might not list all extensions buteo-mtp
* currently supports -> better ignore this configuration
* element altogether.
*/
if( m_devInfo->m_mtpExtension != aStr ) {
MTP_LOG_INFO("Ignoring configured mtp extensions:" << aStr
<< "Using built in defaults:" << m_devInfo->m_mtpExtension);
}
result = true;
break;
case FNMODE:
Expand Down

0 comments on commit 2b880d6

Please sign in to comment.