Discussion:
[gphoto-devel] Question about Linux and PTP over USB spec support
Patrick Laplante
2006-03-05 14:20:35 UTC
Permalink
All,



I have tons of experience with DSC (PTP over USB) on NetBSD (also
Pictbridge). Like you all know PictBridge involves lots of sending to the
camera. Now the PTP over USB spec stated that if the data being sent to the
camera is a multiplier of the bulk fifo size, the pc must send a zero length
packet. Well on BSD, the only way to easy do that was writing a kernel
driver (easy to do).



Now, on Linux, I don't see any specific driver. I am wondering how is the
zero length packet being sent to the device. Is it part of the usb stact
default behavior? How can it know if a packet is the last one?



Just wondering.





Pat Laplante
Principal Engineer

Vanteon Corporation
2851 Clover Street
Pittsford, NY 14534-1711
Office: (585) 248-0510 x298
Fax: (585) 248-0537
www.vanteon.com <http://www.vanteon.com> - Embedded for Your Future
Patrick Laplante
2006-03-06 00:55:08 UTC
Permalink
I did some research today and discovered:



The linux usb host stack use URB to allow user land app to read and write to
a usb device. One of the flag is to specify sending a ZEROLENGTH packet to
the device. Now looking at the libusb source code, I can't find anywhere in
the linux.c file where they are doing that. Is this on by default in the
kernel or is it a bug in libusb or am I missing something?



Thanks



Pat



_____

From: gphoto-devel-***@lists.sourceforge.net
[mailto:gphoto-devel-***@lists.sourceforge.net] On Behalf Of Patrick
Laplante
Sent: Sunday, March 05, 2006 9:21 AM
To: gphoto-***@lists.sourceforge.net
Subject: [gphoto-devel] Question about Linux and PTP over USB spec support



All,



I have tons of experience with DSC (PTP over USB) on NetBSD (also
Pictbridge). Like you all know PictBridge involves lots of sending to the
camera. Now the PTP over USB spec stated that if the data being sent to the
camera is a multiplier of the bulk fifo size, the pc must send a zero length
packet. Well on BSD, the only way to easy do that was writing a kernel
driver (easy to do).



Now, on Linux, I don't see any specific driver. I am wondering how is the
zero length packet being sent to the device. Is it part of the usb stact
default behavior? How can it know if a packet is the last one?



Just wondering.





Pat Laplante
Principal Engineer

Vanteon Corporation
2851 Clover Street
Pittsford, NY 14534-1711
Office: (585) 248-0510 x298
Fax: (585) 248-0537
www.vanteon.com <http://www.vanteon.com> - Embedded for Your Future
Marcus Meissner
2006-03-06 06:32:46 UTC
Permalink
Post by Patrick Laplante
The linux usb host stack use URB to allow user land app to read and write to
a usb device. One of the flag is to specify sending a ZEROLENGTH packet to
the device. Now looking at the libusb source code, I can't find anywhere in
the linux.c file where they are doing that. Is this on by default in the
kernel or is it a bug in libusb or am I missing something?
It is a missing feature in libusb.

However I think it is possible to send a 0 sized URB to the kernel
folllowing the codepaths, which might have the same effect.

Ciao, Marcus
Marcus Meissner
2006-03-06 06:31:58 UTC
Permalink
Post by Patrick Laplante
All,
I have tons of experience with DSC (PTP over USB) on NetBSD (also
Pictbridge). Like you all know PictBridge involves lots of sending to the
camera. Now the PTP over USB spec stated that if the data being sent to the
camera is a multiplier of the bulk fifo size, the pc must send a zero length
packet. Well on BSD, the only way to easy do that was writing a kernel
driver (easy to do).
Actuallay they also mention "short writes" ?
Post by Patrick Laplante
Now, on Linux, I don't see any specific driver. I am wondering how is the
zero length packet being sent to the device. Is it part of the usb stact
default behavior? How can it know if a packet is the last one?
Most PTP cameras do not care about it, so they work fine.

MTP devices on the other hand have problems with it.

Ciao, Marcus
Marcus Meissner
2006-03-06 20:56:33 UTC
Permalink
Post by Patrick Laplante
Marcus,
Thanks for the reply!
Yeah short write really is a way to tell the camera that you are done
sending data to it. A camera that follows the DSC (Digital Still Camera)
USB spec should treat short packet as the end of a PTP phase (Command or
Data). But sometime if the amount of data being sent is the exact size or a
multiplier of the fifo, then you need a way to tell the camera that you are
done sending data (that is per spec) which is where the zero length packet
comes into play.
Yes. I think the reason why we are not seeing this with normal cameras
is that we never send such packages. (for cameras we send command packets,
all smaller than 64? 512? bytes, and property values, same).

MTP devices have more sizes to send, thats why we are seeing more problems there
I think.
Post by Patrick Laplante
I did lots of PTP work with probably most if not all of the Kodak camera and
they all (or most of them) require that short packet. It was also an issue
with Pictbridge camera (I did lots of works with the PictBridge protocol on
the Initiator side of the world 'printer').
So if I hear you correctly, I will need to add a feature to the libusb
write. Probably a flag that specifies whether a short packet needs to be
sent after the write completes.
I think so, or a null packet.

Your help there would be very useful.
Post by Patrick Laplante
I am asking because I am starting a new project where I need to implement
the PictBridge print part on a device running Linux (no gphoto involve in
this). But I was thinking of using libptp for the ptp stack.
You could just involve libgphoto2, but libptp might be more useful, especially
when runnining it in a some kind of polling mode.

Ciao, Marcus
Patrick Laplante
2006-03-06 15:05:36 UTC
Permalink
Marcus,

Thanks for the reply!

Yeah short write really is a way to tell the camera that you are done
sending data to it. A camera that follows the DSC (Digital Still Camera)
USB spec should treat short packet as the end of a PTP phase (Command or
Data). But sometime if the amount of data being sent is the exact size or a
multiplier of the fifo, then you need a way to tell the camera that you are
done sending data (that is per spec) which is where the zero length packet
comes into play.

I did lots of PTP work with probably most if not all of the Kodak camera and
they all (or most of them) require that short packet. It was also an issue
with Pictbridge camera (I did lots of works with the PictBridge protocol on
the Initiator side of the world 'printer').

So if I hear you correctly, I will need to add a feature to the libusb
write. Probably a flag that specifies whether a short packet needs to be
sent after the write completes.

I am asking because I am starting a new project where I need to implement
the PictBridge print part on a device running Linux (no gphoto involve in
this). But I was thinking of using libptp for the ptp stack.

Anyway, Thanks for your help.


-----Original Message-----
From: Marcus Meissner [mailto:***@jet.franken.de]
Sent: Monday, March 06, 2006 1:32 AM
To: Patrick Laplante
Cc: gphoto-***@lists.sourceforge.net
Subject: Re: [gphoto-devel] Question about Linux and PTP over USB spec
support
Post by Patrick Laplante
All,
I have tons of experience with DSC (PTP over USB) on NetBSD (also
Pictbridge). Like you all know PictBridge involves lots of sending to the
camera. Now the PTP over USB spec stated that if the data being sent to
the
Post by Patrick Laplante
camera is a multiplier of the bulk fifo size, the pc must send a zero
length
Post by Patrick Laplante
packet. Well on BSD, the only way to easy do that was writing a kernel
driver (easy to do).
Actuallay they also mention "short writes" ?
Post by Patrick Laplante
Now, on Linux, I don't see any specific driver. I am wondering how is the
zero length packet being sent to the device. Is it part of the usb stact
default behavior? How can it know if a packet is the last one?
Most PTP cameras do not care about it, so they work fine.

MTP devices on the other hand have problems with it.

Ciao, Marcus
Patrick Laplante
2006-03-06 21:30:02 UTC
Permalink
Marcus,

I'll be happy to add the zero length stuff to libusb and libptp....

I have a camera where I can do some custom PTP command on it to try it out.

Once I have something working, I'll let you guys know.

Pat

-----Original Message-----
From: Marcus Meissner [mailto:***@jet.franken.de]
Sent: Monday, March 06, 2006 3:57 PM
To: Patrick Laplante
Cc: gphoto-***@lists.sourceforge.net
Subject: Re: [gphoto-devel] Question about Linux and PTP over USB spec
support
Post by Patrick Laplante
Marcus,
Thanks for the reply!
Yeah short write really is a way to tell the camera that you are done
sending data to it. A camera that follows the DSC (Digital Still Camera)
USB spec should treat short packet as the end of a PTP phase (Command or
Data). But sometime if the amount of data being sent is the exact size or
a
Post by Patrick Laplante
multiplier of the fifo, then you need a way to tell the camera that you
are
Post by Patrick Laplante
done sending data (that is per spec) which is where the zero length packet
comes into play.
Yes. I think the reason why we are not seeing this with normal cameras
is that we never send such packages. (for cameras we send command packets,
all smaller than 64? 512? bytes, and property values, same).

MTP devices have more sizes to send, thats why we are seeing more problems
there
I think.
Post by Patrick Laplante
I did lots of PTP work with probably most if not all of the Kodak camera
and
Post by Patrick Laplante
they all (or most of them) require that short packet. It was also an
issue
Post by Patrick Laplante
with Pictbridge camera (I did lots of works with the PictBridge protocol
on
Post by Patrick Laplante
the Initiator side of the world 'printer').
So if I hear you correctly, I will need to add a feature to the libusb
write. Probably a flag that specifies whether a short packet needs to be
sent after the write completes.
I think so, or a null packet.

Your help there would be very useful.
Post by Patrick Laplante
I am asking because I am starting a new project where I need to implement
the PictBridge print part on a device running Linux (no gphoto involve in
this). But I was thinking of using libptp for the ptp stack.
You could just involve libgphoto2, but libptp might be more useful,
especially
when runnining it in a some kind of polling mode.

Ciao, Marcus
Patrick Laplante
2006-03-06 22:58:24 UTC
Permalink
One Important thing is getting the device FIFO size. This is available in
the USB Device descriptor.

-----Original Message-----
From: gphoto-devel-***@lists.sourceforge.net
[mailto:gphoto-devel-***@lists.sourceforge.net] On Behalf Of Patrick
Laplante
Sent: Monday, March 06, 2006 4:30 PM
To: 'Marcus Meissner'
Cc: gphoto-***@lists.sourceforge.net
Subject: RE: [gphoto-devel] Question about Linux and PTP over USB spec
support

Marcus,

I'll be happy to add the zero length stuff to libusb and libptp....

I have a camera where I can do some custom PTP command on it to try it out.

Once I have something working, I'll let you guys know.

Pat

-----Original Message-----
From: Marcus Meissner [mailto:***@jet.franken.de]
Sent: Monday, March 06, 2006 3:57 PM
To: Patrick Laplante
Cc: gphoto-***@lists.sourceforge.net
Subject: Re: [gphoto-devel] Question about Linux and PTP over USB spec
support
Post by Patrick Laplante
Marcus,
Thanks for the reply!
Yeah short write really is a way to tell the camera that you are done
sending data to it. A camera that follows the DSC (Digital Still Camera)
USB spec should treat short packet as the end of a PTP phase (Command or
Data). But sometime if the amount of data being sent is the exact size or
a
Post by Patrick Laplante
multiplier of the fifo, then you need a way to tell the camera that you
are
Post by Patrick Laplante
done sending data (that is per spec) which is where the zero length packet
comes into play.
Yes. I think the reason why we are not seeing this with normal cameras
is that we never send such packages. (for cameras we send command packets,
all smaller than 64? 512? bytes, and property values, same).

MTP devices have more sizes to send, thats why we are seeing more problems
there
I think.
Post by Patrick Laplante
I did lots of PTP work with probably most if not all of the Kodak camera
and
Post by Patrick Laplante
they all (or most of them) require that short packet. It was also an
issue
Post by Patrick Laplante
with Pictbridge camera (I did lots of works with the PictBridge protocol
on
Post by Patrick Laplante
the Initiator side of the world 'printer').
So if I hear you correctly, I will need to add a feature to the libusb
write. Probably a flag that specifies whether a short packet needs to be
sent after the write completes.
I think so, or a null packet.

Your help there would be very useful.
Post by Patrick Laplante
I am asking because I am starting a new project where I need to implement
the PictBridge print part on a device running Linux (no gphoto involve in
this). But I was thinking of using libptp for the ptp stack.
You could just involve libgphoto2, but libptp might be more useful,
especially
when runnining it in a some kind of polling mode.

Ciao, Marcus



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Sean Hsu
2016-06-01 09:05:41 UTC
Permalink
Hi guys:
After reading your guys' post, I hope I can get some feedback here.
My goal is to establish a connection between freescale iMX6qdl-sabresd Linux
OS device and Windows PC using PTP(Picture Transfer Protocol) with USB
cable. However, I do not even know how to start. I list my questions as
below, please let me know if any of you knows the answer.
1. If any of you are familiar with freescale board, local.conf is the file
that is used to add packages.
If what I need is to import some packages, what packages should I
include? gphoto2, libptp? etc,. ?
2. I know now PTP is the transport layer above the USB-IF physical layer.
What should I do to enable the USB-IF and send PTP protocol? This involves a
lot of self-coding. The best way is to find a library or packages that I can
import to the freescale board and start using the PTP.
3. If what I am trying to do is too complicated, I am not insist on doing
it. However, I do want a linux and Windows connection with PTP or MTP using
USB cable. Importing packages or libraries seem to be the best way to get
started.

Any ideas or concepts about what I mentioned above will be welcomed. Thank
you.



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Question-about-Linux-and-PTP-over-USB-spec-support-tp4944p16226.html
Sent from the gphoto-devel mailing list archive at Nabble.com.
Marcus Meissner
2016-06-01 13:21:36 UTC
Permalink
Post by Sean Hsu
After reading your guys' post, I hope I can get some feedback here.
My goal is to establish a connection between freescale iMX6qdl-sabresd Linux
OS device and Windows PC using PTP(Picture Transfer Protocol) with USB
cable. However, I do not even know how to start. I list my questions as
below, please let me know if any of you knows the answer.
1. If any of you are familiar with freescale board, local.conf is the file
that is used to add packages.
If what I need is to import some packages, what packages should I
include? gphoto2, libptp? etc,. ?
Note that libgphoto2 is the initiator side, not the responder side.

For the intiator side the packages needed are usually gphoto2, libgphoto2,
and libusb at least. (libptp is not relevant.)
Post by Sean Hsu
2. I know now PTP is the transport layer above the USB-IF physical layer.
What should I do to enable the USB-IF and send PTP protocol? This involves a
lot of self-coding. The best way is to find a library or packages that I can
import to the freescale board and start using the PTP.
The userspace interface library used by libgphoto2 is usually libusb.

The kernel, whatever this board runs, needs to support userland USB.
Post by Sean Hsu
3. If what I am trying to do is too complicated, I am not insist on doing
it. However, I do want a linux and Windows connection with PTP or MTP using
USB cable. Importing packages or libraries seem to be the best way to get
started.
Any ideas or concepts about what I mentioned above will be welcomed. Thank
you.
If you want to create the device side, there are some responder implementations
in code.

Ciao, Marcus
Sean Hsu
2016-06-02 07:25:21 UTC
Permalink
Hi Marcus:

Thanks for replying.

Note that libgphoto2 is the initiator side, not the responder side.

For the intiator side the packages needed are usually gphoto2, libgphoto2,
and libusb at least. (libptp is not relevant.)

===>does it mean that the freescale iMX6sabresd Linux-based OS board is the
initiator side that initiates the connection by opening a session and the
windows PC acts as a response side all the time in PTP protocol?
The Linux board is the device(usb-wise) and windows PC is the host(usb-wise)
in PTP world?
Normally, if connecting a digital camera to a windows PC using USB cable by
PTP protocol, which one is the initiator? the digital camera or the windows
PC? who is the one sending the command who is the one responding?

I am trying to get the idea right. Thanks for replying.



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Question-about-Linux-and-PTP-over-USB-spec-support-tp4944p16228.html
Sent from the gphoto-devel mailing list archive at Nabble.com.
Marcus Meissner
2016-06-02 08:55:34 UTC
Permalink
Post by Sean Hsu
Thanks for replying.
Note that libgphoto2 is the initiator side, not the responder side.
For the intiator side the packages needed are usually gphoto2, libgphoto2,
and libusb at least. (libptp is not relevant.)
===>does it mean that the freescale iMX6sabresd Linux-based OS board is the
initiator side that initiates the connection by opening a session and the
windows PC acts as a response side all the time in PTP protocol?
The Linux board is the device(usb-wise) and windows PC is the host(usb-wise)
in PTP world?
Normally, if connecting a digital camera to a windows PC using USB cable by
PTP protocol, which one is the initiator? the digital camera or the windows
PC? who is the one sending the command who is the one responding?
I am trying to get the idea right. Thanks for replying.
Your Linux board would simulate being the Device.

I had to look it up again, its confusing a bit.

In ISO 17540 / PTP standard speak:

Device == Responder (your Linux board)
Client == Initiator (your Windows System)

libgphoto2 provides a client/initiator implementation, but as you need
the responder side, it will not be much useful for you I am afraid.


There were some PTP/MTP responder source bases, although a quick google
search does not find them again :(

Ciao, Marcus
Stefan Peter
2016-06-02 09:36:22 UTC
Permalink
Hi Marcus
Post by Marcus Meissner
There were some PTP/MTP responder source bases, although a quick google
search does not find them again :(
CHDK (http://chdk.wikia.com/wiki/CHDK) may have an implementation.

Regards

Stefan Peter
Marcus Meissner
2016-06-02 09:40:22 UTC
Permalink
Post by Sean Hsu
Hi Marcus
Post by Marcus Meissner
There were some PTP/MTP responder source bases, although a quick google
search does not find them again :(
CHDK (http://chdk.wikia.com/wiki/CHDK) may have an implementation.
They hook into the Canon PTP stack AFAIK.

Ciao, Marcus
Sean Hsu
2016-06-02 08:46:40 UTC
Permalink
Hi Marcus:

I see what you meant. For libgphoto2 to work, the linux side should be the
host side. However, I am connecting the board to the PC. The PC is the host,
the board has to be the device. I will take a look at the link that you
provided. If you have any further idea that might help me, please let me
know. Thanks a lot.

BR
Sean Hsu



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Question-about-Linux-and-PTP-over-USB-spec-support-tp4944p16232.html
Sent from the gphoto-devel mailing list archive at Nabble.com.
Sean Hsu
2016-06-14 01:45:04 UTC
Permalink
Hi Marcus:

Sorry I couldn't find anything. I have couple of questions as below:

1. for PTP connection, what should I do to let Windows PC recognize the
linux board as a device? For example, I connect PC to linux using mass
storage, and after the USB connection, the linux side recognizes PC and PC
recognizes the linux.

2. for PTP connection, do I need to set the command that enables the mass
storage protocol? In other words, can PTP and mass storage coexist?

3. Is there any open source code example or packages for imx freescale board
that implement the daemon side user code that calls PTP level API and PTP
code calls USB level API? and most importantly, it has to be the responder
side(PC as host, linux as device).

I really stuck here for a while now. If you can provide me anything that is
more useful that I really get started with my process, I really appreciate.
Thank you for replying.

BR
Sean Hsu



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Question-about-Linux-and-PTP-over-USB-spec-support-tp4944p16237.html
Sent from the gphoto-devel mailing list archive at Nabble.com.
Sean Hsu
2016-06-27 01:54:54 UTC
Permalink
Hi Marcus:

Any idea of what what I need to do? Any documents, even better sample codes
about how to implement PTP side, USB side? Thanks for replying.

BR
Sean Hsu



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/Question-about-Linux-and-PTP-over-USB-spec-support-tp4944p16254.html
Sent from the gphoto-devel mailing list archive at Nabble.com.

Loading...