| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>PTP/IP protocol - briefly reverse engineered</title> |
| 4 |
<meta name="keywords" content="gphoto libgphoto2 linux ptpip ptp/ip ptp"> |
| 5 |
</head> |
| 6 |
<body> |
| 7 |
|
| 8 |
<h1>PTP/IP</h1> |
| 9 |
<hr> |
| 10 |
This document briefly describes the PTP/IP transfer layer, as reverse |
| 11 |
engineered from ethereal packet dumps and glanced from the sparely available |
| 12 |
online documentation. |
| 13 |
<p> |
| 14 |
It operates on top of a normal IP networkstack, the connections |
| 15 |
are simple TCP/IP socket connection. |
| 16 |
<p> |
| 17 |
Default port is 15740 (same as the ISO standard number for PTP). |
| 18 |
<p> |
| 19 |
There are 2 connections used:<br> |
| 20 |
<ul> |
| 21 |
<li>control & data connection (Initiator (computer) driven) |
| 22 |
<li>event connection (Responder (camera) driven) |
| 23 |
</ul> |
| 24 |
<p> |
| 25 |
The participants communicate in packets, their layout is: |
| 26 |
|
| 27 |
<table border=1> |
| 28 |
<tr><th>Length</th><th>Variable</th><th>Notes</th></tr> |
| 29 |
<tr><td>4</td><td>length (little endian)</td><td>Length of the whole packet including the header</td></tr> |
| 30 |
<tr><td>4</td><td>type (little endian)</td><td>Type, listed below</td></tr> |
| 31 |
<tr><td>length - 8</td><td>data</td><td>specific on type</td></tr> |
| 32 |
</table> |
| 33 |
<p> |
| 34 |
Observed types: |
| 35 |
<p> |
| 36 |
<table border=1> |
| 37 |
<tr><th>Type</th><th>Direction</th><th>Name</th><th>Next reply(s)</th><th>Payload</th></tr> |
| 38 |
<tr> |
| 39 |
<td>1</td> |
| 40 |
<td>I->R</td> |
| 41 |
<td>Init_Command_Request</td> |
| 42 |
<td>2 or 5</td> |
| 43 |
<td><ul> |
| 44 |
<li>16 byte GUID |
| 45 |
<li>xx byte WCHAR computername with terminating \0 |
| 46 |
</ul> |
| 47 |
</td> |
| 48 |
</tr> |
| 49 |
<tr> |
| 50 |
<td>2</td> |
| 51 |
<td>R->I</td> |
| 52 |
<td>Init_Command_Ack</td> |
| 53 |
<td>5 or MAINLOOP</td> |
| 54 |
<td><ul> |
| 55 |
<li>4 byte ID (session id, to be used for event connection startup) |
| 56 |
<li>16 byte GUID (MAC is used here for my camera, and repeated) |
| 57 |
<li>xx byte WCHAR Camera Name with terminating \0 |
| 58 |
</td> |
| 59 |
</tr> |
| 60 |
<tr> |
| 61 |
<td>3</td> |
| 62 |
<td>I->R</td> |
| 63 |
<td>Init_Event_Request</td> |
| 64 |
<td>4 or 5</td> |
| 65 |
<td><ul><li>4 byte ID (from Init_Command_Ack)</ul></td> |
| 66 |
</tr> |
| 67 |
<tr> |
| 68 |
<td>4</td> |
| 69 |
<td>R->I</td> |
| 70 |
<td>Init_Event_Ack</td> |
| 71 |
<td>EVENTLOOP</td> |
| 72 |
<td><ul><li>No payload.</ul></td> |
| 73 |
</tr> |
| 74 |
<tr> |
| 75 |
<td>5</td> |
| 76 |
<td>I->R</td> |
| 77 |
<td>Init_Fail</td> |
| 78 |
<td>End of communication</td> |
| 79 |
<td><ul><li>4 byte error code (unclear meaning)</ul></td> |
| 80 |
</tr> |
| 81 |
<tr> |
| 82 |
<td>6</td> |
| 83 |
<td>I->R</td> |
| 84 |
<td>Cmd_Request</td> |
| 85 |
<td>9 -> A/C or 7</td> |
| 86 |
<td><ul> |
| 87 |
<li>4 byte unknown. set to 1 currently. |
| 88 |
<li>2 byte PTP command code |
| 89 |
<li>4 byte Transaction ID |
| 90 |
<li>n x 4 byte PTP command arguments |
| 91 |
</ul></td> |
| 92 |
</tr> |
| 93 |
<tr> |
| 94 |
<td>7</td> |
| 95 |
<td>R->I</td> |
| 96 |
<td>Cmd_Response</td> |
| 97 |
<td>MAINLOOP</td> |
| 98 |
<td><ul> |
| 99 |
<li>2 bytes PTP response code |
| 100 |
<li>4 bytes Transaction ID |
| 101 |
<li>nr*4 bytes arguments (depending on length of response) |
| 102 |
</ul></td> |
| 103 |
</tr> |
| 104 |
<tr> |
| 105 |
<td>8</td> |
| 106 |
<td>R->I</td> |
| 107 |
<td>Event</td> |
| 108 |
<td>EVENTLOOP</td> |
| 109 |
<td> |
| 110 |
<ul> |
| 111 |
<li>2 byte PTP event code |
| 112 |
<li>... |
| 113 |
</ul> |
| 114 |
Not fully investigated, but similar to PTP event. |
| 115 |
</td> |
| 116 |
</tr> |
| 117 |
<tr> |
| 118 |
<td>9</td> |
| 119 |
<td>R<->I</td> |
| 120 |
<td>Start_Data_Packet</td> |
| 121 |
<td>10,12</td> |
| 122 |
<td><ul> |
| 123 |
<li>4 byte Transaction ID |
| 124 |
<li>4 byte Total data download size (without headers) |
| 125 |
</ul></td> |
| 126 |
</tr> |
| 127 |
<tr> |
| 128 |
<td>10</td> |
| 129 |
<td>R<->I</td> |
| 130 |
<td>Data_Packet</td> |
| 131 |
<td>10,12</td> |
| 132 |
<td><ul> |
| 133 |
<li>4 byte Transaction ID |
| 134 |
<li>length-4-8 bytes payload data |
| 135 |
</ul></td> |
| 136 |
</tr> |
| 137 |
<tr> |
| 138 |
<td>11</td> |
| 139 |
<td>I->R</td> |
| 140 |
<td>Cancel_Transaction</td> |
| 141 |
<td>7 ?</td> |
| 142 |
<td>(Untested yet.)<ul> |
| 143 |
<li>4 bytes Transaction ID |
| 144 |
</ul></td> |
| 145 |
</tr> |
| 146 |
<tr> |
| 147 |
<td>12</td> |
| 148 |
<td>R<->I</td> |
| 149 |
<td>End_Data_Packet</td> |
| 150 |
<td>7 ?</td> |
| 151 |
<td><ul> |
| 152 |
<li>4 byte Transaction ID |
| 153 |
<li>length-4-8 bytes payload data |
| 154 |
</ul></td> |
| 155 |
</tr> |
| 156 |
<tr> |
| 157 |
<td>13</td> |
| 158 |
<td>R<->I</td> |
| 159 |
<td>Ping</td> |
| 160 |
<td>14</td> |
| 161 |
<td><ul><li>No payload.</ul></td> |
| 162 |
</tr> |
| 163 |
<tr> |
| 164 |
<td>13</td> |
| 165 |
<td>R<->I</td> |
| 166 |
<td>Pong</td> |
| 167 |
<td>EVENTLOOP</td> |
| 168 |
<td><ul><li>No payload.</ul></td> |
| 169 |
</tr> |
| 170 |
</table> |
| 171 |
<p> |
| 172 |
State transitions: |
| 173 |
<p> |
| 174 |
Initial Phase: |
| 175 |
<p> |
| 176 |
Command Connection: |
| 177 |
<table border=1> |
| 178 |
<tr><td>1</td><td>-> 2</td><td>-> MAINLOOP</td></tr> |
| 179 |
<tr><td> </td><td> \ 5</td><td>-> EXIT</td><tr> |
| 180 |
</table> |
| 181 |
<p> |
| 182 |
Event Connection: |
| 183 |
<table border=1> |
| 184 |
<tr><td>3</td><td>-> 4</td><td>-> EVENTLOOP</td></tr> |
| 185 |
<tr><td> </td><td> \ 5</td><td>-> EXIT</td><tr> |
| 186 |
</table> |
| 187 |
Cameras using PTP/IP: |
| 188 |
<ul> |
| 189 |
<li>Nikon CoolPix P1 |
| 190 |
<li>Nikon CoolPix P2 |
| 191 |
<li>Nikon CoolPix P3 |
| 192 |
<li>Nikon CoolPix P4 |
| 193 |
<li>Nikon CoolPix S6 |
| 194 |
<li>Kodak EasyShare One |
| 195 |
<li>Canon PowerShot SD430 |
| 196 |
</ul> |
| 197 |
</body> |
| 198 |
</html> |