direct-usb-protocol.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. *****************************
  2. * Direct Cable(tm) protocol *
  3. * by roms 2006 *
  4. *****************************
  5. Based on preliminary work made by "Drake Wilson" <drake@libcom.com>. Thanks !
  6. The initialization sequence for the direct USB cable seems to always
  7. be setting the alternate interface to 0 and the configuration to 1.
  8. The endpoints used are 0x02 (for computer to calculator messages) and
  9. 0x81 (for calculator to computer messages). All messages are sent via
  10. bulk transfer.
  11. Data are sent on a per-block basis (URB = Usb Request Block).
  12. Block length is 256 bytes for TI84+ and Titanium.
  13. Please note this is different of packets below because URBs are managed by driver
  14. or lower layers (at least for Titanium).
  15. Packet length (chunck) is:
  16. - 255 bytes on TI84+,
  17. - 1023 bytes on Titanium.
  18. Clearly:
  19. - on TI84+, a packet is always contained in an URBs (255 < 256),
  20. - on Titanium, a packet may be contained in one or more URBs (1023 > 256).
  21. If this is not clear for you, take a look at screenshot.log (SniffUsb) and screenshot.pkt.
  22. 0°) Introduction
  23. ----------------
  24. The generic format for packets is below:
  25. | packet header | data (250/1018 bytes max) |
  26. | | or |
  27. | size | ty | size | code | data (246/1012 bytes) |
  28. | | | | | |
  29. | 00 00 00 10 | 04 | 00 00 00 0A | 00 01 | 00 03 00 01 00 00 00 00 07 D0 |
  30. The following notation will be used in this doc:
  31. aabbccdd (type) xxyyzztt {code} [pure data]
  32. Note: on Titanium, the data part usually follows the packet header but it may be sent in
  33. another URB (fragmented) when the data part is huge (> 1012). In this case, the packet
  34. header is sent alone in URB and is next followed by a 1023-bytes chunk of data in a second URB.
  35. TI seems not to like easy things :-(
  36. 1°) Packet Header (5 bytes)
  37. ---------------------------
  38. Each packet starts with the following header (packet header):
  39. HH HL LH LL = four-byte big-endian length of non-header part
  40. of packet (after opcode)
  41. OO = one-byte packet type
  42. ...
  43. Packets will be represented as "(opcode) data" in the following text.
  44. Types of packets include:
  45. 01 = handshake (HSK)
  46. 02 = handshake response (ANS)
  47. 03 = data packet (DATA)
  48. 04 = last data packet (LAST)
  49. 05 = acknowledgement (ACK)
  50. The handshake consists of:
  51. -> 00000004 (01) [00 00 04 00]
  52. <- 00000004 (02) [00 00 00 fa] TI84+
  53. <- 00000004 (02) [00 00 03 ff] Titanium
  54. The acknowledgment (ACK) packet is packet type 05. The data of the
  55. ACK packet is always E0 00 (if successful):
  56. -> 00000002 (05) [E0 00]
  57. Types 01,02 have 4 bytes of data, type 05 has 2 bytes only.
  58. 2°) Data header (6 bytes)
  59. -------------------------
  60. When sending any piece of data, the following header (data header) is
  61. prepended on the _first_ data packet:
  62. HH HL LH LL = four-byte big-endian length of non-header part
  63. of data (after opcode)
  64. OO OO = two-byte opcode
  65. ...
  66. On TI84+, the data is sent in 245-bytes chunks for the first packet or in 250-bytes
  67. chunks for the others. If data is greater than 245 bytes, then data is sent in several
  68. packets (several data/ack steps).
  69. On Titanium, the data is sent in 1012-bytes chunks for the first packet or in 1018-bytes
  70. chunks for the others. If data is greater than 1012 bytes, then data is sent in several
  71. packets (several data/ack steps).
  72. Packet type 03 is used for each of the packet except the last, and packet
  73. type 04 is used for the last packet. Each data packet is acknowledged
  74. with packet type 05. Thus, you have, for short data:
  75. -> (04) header, data...
  76. <- ACK
  77. And for longer data, you might have:
  78. -> (03) header, data...
  79. <- ACK
  80. -> (03) data...
  81. <- ACK
  82. -> (04) last part of data...
  83. <- ACK
  84. Note: usually, the data header size is 7 bytes greater than the size of real data because
  85. 7 bytes are prepended to data (4 bytes of request and 3 bytes of data size).
  86. 3°) Type IDs (tid)
  87. ------------------
  88. - 0022: screen
  89. - 0024: related to clock (???)
  90. - 0025: clock value
  91. - 0027: date format
  92. - 0028: time format (am/pm or 24h)
  93. 4°) Op-codes (opc)
  94. ------------------
  95. Data opcodes include:
  96. 0001 = unknown request (data = 00 03 00 01 00 00 00 00 07 D0)
  97. Reply with opcode 0012 and data = 00 00 07 D0
  98. Same for all calcs. Is an echo ?
  99. 0012 = ???
  100. Answer of 0001
  101. 0007 = request (REQ)
  102. The format seems to be the following:
  103. 00 NN tid1 tid2 ... tidN where NN is the number of requests and tidI the request on 2 bytes)
  104. Replied with opcode 0008 below.
  105. - screenshot with data = 00 01 00 22
  106. - clock with data = 00 04 00 25 00 27 00 28 00 24
  107. 0008 = request answer (VAR)
  108. The format seems to be the following:
  109. 00 NN [tid1 size1 data1] [tid2 size2 data2] ... [tidN sizeN dataN]
  110. where:
  111. - NN is the number of request
  112. - tidI is the previous request tidI (2 bytes)
  113. - sizeI is the size of data following (3 bytes)
  114. - dataI is the data request by tidI (sizeI bytes)
  115. and so on...
  116. 000e = request to send (RTS)
  117. The format is the following: tid size data
  118. where tid is the type id, size is the size of data
  119. aa00 = clear to send (CTS)
  120. 01
  121. bb00 = clear to receive (CTR)
  122. 00 01 d4 c0
  123. dd00 = end of transmission (EOT)
  124. no data
  125. ee00 = error
  126. data = CC CC where CCCC is a two-byte error code
  127. Error codes include:
  128. 00 08 = transmission error or invalid code?
  129. 00 0c = out of memory?
  130. 00 0e = invalid name?
  131. ////
  132. 0009 = Request directory from calculator
  133. 00 00 00 06 00 02 00 03 00 05 00 01 00 41 00 42
  134. 00 01 00 01 00 01 01
  135. 000a = Directory entry
  136. LL LL name... = big-endian length of name, followed by name
  137. 00 00 06 00 02 00
  138. 00 04 f0 07 00
  139. TT = type of variable
  140. 00 03 00 00 01
  141. FF = some kind of flags?
  142. bit 0 (0x01) = archived
  143. 00 05
  144. GG = more flags?
  145. bit 0 (0x01) = auxiliary data present
  146. If auxiliary data present:
  147. LL LL data... = big-endian length of data, followed by data
  148. 00 01 00 00 04
  149. SS SS SS SS = big-endian size of variable in bytes
  150. 00 04 01 00 42 01
  151. 000b = Send variable to calculator
  152. LL LL name... = big-endian length of name, followed by name
  153. 00
  154. SS SS SS SS = big-endian size of variable in bytes
  155. 01 00
  156. FF = not sure what this is...
  157. FF = 0x03 for lists and programs
  158. 0x02 for flash applications
  159. 00 02 00 04 f0 07
  160. 00
  161. TT = type of variable
  162. 00 03 00 01 00
  163. 00 08 00 04 00 = don't know what this means?
  164. 00 00 00
  165. ( The last 8 bytes did not appear during flash application
  166. transfer, but they did during list and program transfer. )
  167. 000c = Request variable from calculator
  168. LL LL name... = big-endian length of name, followed by name
  169. 00 01 ff ff ff ff
  170. 00 02 00 03 00 08
  171. 00 01 00 11 00 04
  172. f0 07 00
  173. TT = type of variable
  174. 00 00
  175. 000d = Variable data being transferred
  176. (Format depends on type of variable; seems to be related to the
  177. .8x? file types)
  178. Programs:
  179. SS SS = little-endian size of data in bytes
  180. ... = tokenized data
  181. Lists:
  182. LL LL = little-endian length of list in elements
  183. ... = packed real numbers in TI-83+ BCD format
  184. 0010 = Delete variable from calculator
  185. LL LL name... = big-endian length of name, followed by name
  186. 00 00 02 00 01 00
  187. f0 07 00
  188. TT = type of variable?
  189. 00 13 00 01 00 01
  190. 00 00 00 00
  191. 0011 = ?
  192. 0012 = ?
  193. 00 00 07 D0
  194. Answer of opcode 0001 (data contains the last 4 bytes of opcode 0001 ?!)
  195. dd00 = End of transmission (EOT)
  196. (no data)
  197. 4°) Communication Flow
  198. ----------------------
  199. Communication flow for requesting directory from calculator:
  200. -> Request directory
  201. <- ACK
  202. (
  203. <- Directory entry | EOT
  204. -> ACK
  205. )*
  206. Communication flow for sending variable to calculator:
  207. -> Send variable
  208. <- ACK
  209. <- CTS | Error
  210. -> ACK
  211. -> Variable data
  212. <- ACK
  213. <- CTS
  214. -> ACK
  215. ( Maybe jump back to earlier stage here if sending more
  216. than one variable simultaneously? )
  217. -> EOT
  218. <- ACK
  219. Communication flow for requesting variable from calculator:
  220. -> Request variable
  221. <- ACK
  222. <- Directory entry
  223. -> ACK
  224. <- Variable data
  225. -> ACK
  226. ( The USB endpoints were always reset after this transction, so
  227. it's hard to tell whether there was supposed to be anything else
  228. after this. )
  229. Communication flow for deleting variable from calculator:
  230. -> Delete variable
  231. <- ACK
  232. <- CTS
  233. -> ACK
  234. ( USB endpoints reset after this... ? )
  235. 10°) Unknown (all calcs)
  236. -----------------------
  237. This step is systematically done at startup after the HSK/RES.
  238. Moreover, it's needed for TI84+ else any other commands is rejected with error code 0008.
  239. PC: Data {0001} 00 03 00 01 00 00 00 00 07 D0
  240. TI: Ack
  241. TI: Data {0012} 00 00 07 D0
  242. PC: Ack
  243. 5°) Screenshot (on Titanium)
  244. ----------------------------
  245. Communication flow for requesting a screenshot (TI <-/-> PC):
  246. PC: Handshake
  247. TI: Response
  248. PC: Data {0007} 00 01 00 22
  249. TI: Ack
  250. ---- 84+ ----
  251. TI: Data {bb00} 00 01 D4 C0
  252. PC: Ack
  253. ---- 84+ ----
  254. TI: Data {0008} 00 01 00 22 00 0F 00 [3840 bytes of screen] (*)
  255. PC: Ack
  256. TI: Data [3840 bytes of screen]
  257. PC: Ack
  258. TI: Data [3840 bytes of screen]
  259. PC: Ack
  260. TI: Last [3840 bytes of screen]
  261. PC: Ack
  262. (*) 00 0F = 3840 bytes -> size of screen
  263. 6°) Getting clock (on TI84+)
  264. ----------------------------
  265. Communication flow for requesting a screenshot (TI <-/-> PC):
  266. PC: Handshake
  267. TI: Response
  268. PC: Data {0007} 00 04 00 25 00 27 00 28 00 24
  269. TI: Ack
  270. ---- 84+ ----
  271. TI: Data {bb00} 00 01 D4 C0
  272. PC: Ack
  273. ---- 84+ ----
  274. TI: Last {0008} 00 04 00 25 00 00 04 10 15 16 74 00 27 00 00 01 01 00 28 00 00 01 00 00 24 00 00 01 01 (*)
  275. PC: Ack
  276. (*)
  277. 24 is followed by ???
  278. 25 is followed by the the clock value
  279. 27 is followed by the date formatting (1: MDY, 2: DMY, 0:YMD)
  280. 28 is followed by the clock mode (0: am/pm or 1: 24h)
  281. 7°) Setting clock (on TI84+)
  282. ----------------------------
  283. PC: Handshake
  284. TI: Response
  285. PC: Data {000e} 00 25 00 04 10 15 17 01
  286. TI: Ack
  287. ---- 84+ ----
  288. TI: Data {aa00} 01
  289. PC: Ack
  290. ---- 84+ ----
  291. PC: Data {000e} 00 27 00 01 01
  292. TI: Ack
  293. ---- 84+ ----
  294. TI: Data {aa00} 01
  295. PC: Ack
  296. ---- 84+ ----
  297. PC: Data {000e} 00 28 00 01 00
  298. TI: Ack
  299. ---- 84+ ----
  300. TI: Data {aa00} 01
  301. PC: Ack
  302. ---- 84+ ----
  303. PC: Data {000e} 00 24 00 01 01
  304. TI: Ack
  305. ---- 84+ ----
  306. TI: Data {aa00} 01
  307. PC: Ack
  308. ---- 84+ ----