diff options
Diffstat (limited to 'apps/iap/iap-lingo4.c')
-rw-r--r-- | apps/iap/iap-lingo4.c | 3153 |
1 files changed, 3153 insertions, 0 deletions
diff --git a/apps/iap/iap-lingo4.c b/apps/iap/iap-lingo4.c new file mode 100644 index 0000000000..fa0196645b --- /dev/null +++ b/apps/iap/iap-lingo4.c | |||
@@ -0,0 +1,3153 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr & Nick Robinson | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ******************************************************************************/ | ||
19 | |||
20 | #include "iap-core.h" | ||
21 | #include "iap-lingo.h" | ||
22 | #include "dir.h" | ||
23 | #include "settings.h" | ||
24 | #include "filetree.h" | ||
25 | #include "wps.h" | ||
26 | #include "playback.h" | ||
27 | |||
28 | /* | ||
29 | * This macro is meant to be used inside an IAP mode message handler. | ||
30 | * It is passed the expected minimum length of the message buffer. | ||
31 | * If the buffer does not have the required lenght an ACK | ||
32 | * packet with a Bad Parameter error is generated. | ||
33 | */ | ||
34 | #define CHECKLEN(x) do { \ | ||
35 | if (len < (x)) { \ | ||
36 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); \ | ||
37 | return; \ | ||
38 | }} while(0) | ||
39 | |||
40 | /* Check for authenticated state, and return an ACK Not | ||
41 | * Authenticated on failure. | ||
42 | */ | ||
43 | #define CHECKAUTH do { \ | ||
44 | if (!DEVICE_AUTHENTICATED) { \ | ||
45 | cmd_ack(cmd, IAP_ACK_NO_AUTHEN); \ | ||
46 | return; \ | ||
47 | }} while(0) | ||
48 | |||
49 | /* Used to remember the last Type and Record requested */ | ||
50 | static char cur_dbrecord[5] = {0}; | ||
51 | |||
52 | /* Used to remember the total number of filtered database records */ | ||
53 | static unsigned long dbrecordcount = 0; | ||
54 | |||
55 | /* Used to remember the LAST playlist selected */ | ||
56 | static unsigned long last_selected_playlist = 0; | ||
57 | |||
58 | static void cmd_ack(const unsigned int cmd, const unsigned char status) | ||
59 | { | ||
60 | IAP_TX_INIT4(0x04, 0x0001); | ||
61 | IAP_TX_PUT(status); | ||
62 | IAP_TX_PUT_U16(cmd); | ||
63 | iap_send_tx(); | ||
64 | } | ||
65 | |||
66 | #define cmd_ok(cmd) cmd_ack((cmd), IAP_ACK_OK) | ||
67 | |||
68 | static void get_playlist_name(unsigned char *dest, | ||
69 | unsigned long item_offset, | ||
70 | size_t max_length) | ||
71 | { | ||
72 | if (item_offset == 0) return; | ||
73 | DIR* dp; | ||
74 | struct dirent* playlist_file = NULL; | ||
75 | |||
76 | dp = opendir(global_settings.playlist_catalog_dir); | ||
77 | |||
78 | char *extension; | ||
79 | unsigned long nbr = 0; | ||
80 | while ((nbr < item_offset) && ((playlist_file = readdir(dp)) != NULL)) | ||
81 | { | ||
82 | /*Increment only if there is a playlist extension*/ | ||
83 | if ((extension=strrchr(playlist_file->d_name, '.')) != NULL){ | ||
84 | if ((strcmp(extension, ".m3u") == 0 || | ||
85 | strcmp(extension, ".m3u8") == 0)) | ||
86 | nbr++; | ||
87 | } | ||
88 | } | ||
89 | if (playlist_file != NULL) { | ||
90 | strlcpy(dest, playlist_file->d_name, max_length); | ||
91 | } | ||
92 | closedir(dp); | ||
93 | } | ||
94 | |||
95 | static void seek_to_playlist(unsigned long index) | ||
96 | { | ||
97 | unsigned char selected_playlist | ||
98 | [sizeof(global_settings.playlist_catalog_dir) | ||
99 | + 1 | ||
100 | + MAX_PATH] = {0}; | ||
101 | |||
102 | strcpy(selected_playlist, | ||
103 | global_settings.playlist_catalog_dir); | ||
104 | int len = strlen(selected_playlist); | ||
105 | selected_playlist[len] = '/'; | ||
106 | get_playlist_name (selected_playlist + len + 1, | ||
107 | index, | ||
108 | MAX_PATH); | ||
109 | ft_play_playlist(selected_playlist, | ||
110 | global_settings.playlist_catalog_dir, | ||
111 | strrchr(selected_playlist, '/') + 1); | ||
112 | |||
113 | } | ||
114 | |||
115 | static unsigned long nbr_total_playlists(void) | ||
116 | { | ||
117 | DIR* dp; | ||
118 | unsigned long nbr_total_playlists = 0; | ||
119 | struct dirent* playlist_file = NULL; | ||
120 | char *extension; | ||
121 | dp = opendir(global_settings.playlist_catalog_dir); | ||
122 | while ((playlist_file = readdir(dp)) != NULL) | ||
123 | { | ||
124 | /*Increment only if there is a playlist extension*/ | ||
125 | if ((extension=strrchr(playlist_file->d_name, '.')) != NULL) | ||
126 | { | ||
127 | if ((strcmp(extension, ".m3u") == 0 || | ||
128 | strcmp(extension, ".m3u8") == 0)) | ||
129 | { | ||
130 | nbr_total_playlists++; | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | closedir(dp); | ||
135 | return nbr_total_playlists; | ||
136 | } | ||
137 | |||
138 | void iap_handlepkt_mode4(const unsigned int len, const unsigned char *buf) | ||
139 | { | ||
140 | unsigned int cmd = (buf[1] << 8) | buf[2]; | ||
141 | /* Lingo 0x04 commands are at least 3 bytes in length */ | ||
142 | CHECKLEN(3); | ||
143 | |||
144 | /* Lingo 0x04 must have been negotiated */ | ||
145 | if (!DEVICE_LINGO_SUPPORTED(0x04)) { | ||
146 | #ifdef LOGF_ENABLE | ||
147 | logf("iap: Mode04 Not Negotiated"); | ||
148 | #endif | ||
149 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | /* All these commands require extended interface mode */ | ||
154 | if (interface_state != IST_EXTENDED) { | ||
155 | #ifdef LOGF_ENABLE | ||
156 | logf("iap: Not in Mode04 Extended Mode"); | ||
157 | #endif | ||
158 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
159 | return; | ||
160 | } | ||
161 | switch (cmd) | ||
162 | { | ||
163 | case 0x0001: /* CmdAck. See above cmd_ack() */ | ||
164 | /* | ||
165 | * The following is the description for the Apple Firmware | ||
166 | * The iPod sends this telegram to acknowledge the receipt of a | ||
167 | * command and return the command status. The command ID field | ||
168 | * indicates the device command for which the response is being | ||
169 | * sent. The command status indicates the results of the command | ||
170 | * (success or failure). | ||
171 | * | ||
172 | * Byte Value Meaning | ||
173 | * 0 0xFF Sync byte (required only for UART serial) | ||
174 | * 1 0x55 Start of telegram | ||
175 | * 2 0x06 Telegram payload length | ||
176 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
177 | * 4 0x00 Command ID (bits 15:8) | ||
178 | * 5 0x01 Command ID (bits 7:0) | ||
179 | * 6 0xNN Command result status. Possible values are: | ||
180 | * 0x00 = Success (OK) | ||
181 | * 0x01 = ERROR: Unknown database category | ||
182 | * 0x02 = ERROR: Command failed | ||
183 | * 0x03 = ERROR: Out of resources | ||
184 | * 0x04 = ERROR: Bad parameter | ||
185 | * 0x05 = ERROR: Unknown ID | ||
186 | * 0x06 = Reserved | ||
187 | * 0x07 = Accessory not authenticated | ||
188 | * 0x08 - 0xFF = Reserved | ||
189 | * 7 0xNN The ID of the command being acknowledged (bits 15:8). | ||
190 | * 8 0xNN The ID of the command being acknowledged (bits 7:0). | ||
191 | * 9 0xNN Telegram payload checksum byte | ||
192 | */ | ||
193 | { | ||
194 | /* We should NEVER receive this command so ERROR if we do */ | ||
195 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
196 | break; | ||
197 | } | ||
198 | case 0x0002: /* GetCurrentPlayingTrackChapterInfo */ | ||
199 | /* The following is the description for the Apple Firmware | ||
200 | * Requests the chapter information of the currently playing track. | ||
201 | * In response, the iPod sends a | ||
202 | * Command 0x0003: ReturnCurrentPlayingTrackChapterInfo | ||
203 | * telegram to the device. | ||
204 | * Note: The returned track index is valid only when there is a | ||
205 | * currently playing or paused track. | ||
206 | * | ||
207 | * Byte Value Meaning | ||
208 | * 0 0xFF Sync byte (required only for UART serial) | ||
209 | * 1 0x55 Start of telegram | ||
210 | * 2 0x03 Telegram payload length | ||
211 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
212 | * 4 0x00 Command ID (bits 15:8) | ||
213 | * 5 0x02 Command ID (bits 7:0) | ||
214 | * 6 0xF7 Telegram payload checksum byte | ||
215 | * | ||
216 | * We Return that the track does not have chapter information by | ||
217 | * returning chapter index -1 (0xFFFFFFFF) and chapter count 0 | ||
218 | * (0x00000000) | ||
219 | */ | ||
220 | { | ||
221 | unsigned char data[] = {0x04, 0x00, 0x03, | ||
222 | 0xFF, 0xFF, 0xFF, 0xFF, | ||
223 | 0x00, 0x00, 0x00, 0x00}; | ||
224 | iap_send_pkt(data, sizeof(data)); | ||
225 | break; | ||
226 | } | ||
227 | case 0x0003: /* ReturnCurrentPlayingTrackChapterInfo. See Above */ | ||
228 | /* The following is the description for the Apple Firmware | ||
229 | * | ||
230 | * Returns the chapter information of the currently playing track. | ||
231 | * The iPod sends this telegramin response to the | ||
232 | * Command 0x0002: GetCurrentPlayingTrackChapterInfo | ||
233 | * telegram from the device. The track chapter information includes | ||
234 | * the currently playingtrack's chapter index,as well as the | ||
235 | * total number of chapters in the track. The track chapter and the | ||
236 | * total number of chapters are 32-bit signed integers. The chapter | ||
237 | * index of the firstchapter is always 0x00000000. If the track does | ||
238 | * not have chapter information, a chapter index of -1(0xFFFFFFFF) | ||
239 | * and a chapter count of 0 (0x00000000) are returned. | ||
240 | * | ||
241 | * Byte Value Meaning | ||
242 | * 0 0xFF Sync byte (required only for UART serial) | ||
243 | * 1 0x55 Start of telegram | ||
244 | * 2 0x0B Telegram payload length | ||
245 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
246 | * 4 0x00 Command ID (bits 15:8) | ||
247 | * 5 0x03 Command ID (bits 7:0) | ||
248 | * 6 0xNN Current chapter index (bits 31:24) | ||
249 | * 7 0xNN Current chapter index (bits 23:16) | ||
250 | * 8 0xNN Current chapter index (bits 15:8) | ||
251 | * 9 0xNN Current chapter index (bits 7:0) | ||
252 | * 10 0xNN Chapter count (bits 31:24) | ||
253 | * 11 0xNN Chapter count (bits 23:16) | ||
254 | * 12 0xNN Chapter count (bits 15:8) | ||
255 | * 13 0xNN Chapter count (bits 7:0) | ||
256 | * 14 0xNN Telegram payload checksum byte | ||
257 | */ | ||
258 | { | ||
259 | /* We should NEVER receive this command so ERROR if we do */ | ||
260 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
261 | break; | ||
262 | } | ||
263 | case 0x0004: /* SetCurrentPlayingTrackChapter */ | ||
264 | /* The following is the description for the Apple Firmware | ||
265 | * | ||
266 | * Sets the currently playing track chapter.You can send the Command | ||
267 | * 0x0002: GetCurrentPlayingTrackChapterInfo telegram to get the | ||
268 | * chapter count and the index of the currently playing chapter in | ||
269 | * the current track. In response to the command | ||
270 | * SetCurrentPlayingTrackChapter, the iPod sends an ACK telegram | ||
271 | * with the command status. | ||
272 | * | ||
273 | * Note: This command should be used only when the iPod is in a | ||
274 | * playing or paused state. The command fails if the iPod is stopped | ||
275 | * or if the track does not contain chapter information. | ||
276 | * | ||
277 | * Byte Value Meaning | ||
278 | * 0 0xFF Sync byte (required only for UART serial) | ||
279 | * 1 0x55 Start of telegram | ||
280 | * 2 0x07 Telegram payload length | ||
281 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
282 | * 4 0x00 Command ID (bits 15:8) | ||
283 | * 5 0x04 Command ID (bits 7:0) | ||
284 | * 6 0xNN Chapter index (bits 31:24) | ||
285 | * 7 0xNN Chapter index (bits 23:16) | ||
286 | * 8 0xNN Chapter index (bits 15:8) | ||
287 | * 9 0xNN Chapter index (bits 7:0) | ||
288 | * 10 0xNN Telegram payload checksum byte | ||
289 | * | ||
290 | * We don't do anything with this as we don't support chapters, | ||
291 | * so just return BAD_PARAM | ||
292 | */ | ||
293 | { | ||
294 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
295 | break; | ||
296 | } | ||
297 | case 0x0005: /* GetCurrentPlayingTrackChapterPlayStatus */ | ||
298 | /* The following is the description for the Apple Firmware | ||
299 | * | ||
300 | * Requests the chapter playtime status of the currently playing | ||
301 | * track. The status includes the chapter length and the time | ||
302 | * elapsed within that chapter. In response to a valid telegram, the | ||
303 | * iPod sends a Command 0x0006: | ||
304 | * ReturnCurrentPlayingTrackChapterPlayStatus telegram to the | ||
305 | * device. | ||
306 | * | ||
307 | * Note: If the telegram length or chapter index is invalid for | ||
308 | * instance, if the track does not contain chapter information the | ||
309 | * iPod responds with an ACK telegram including the specific error | ||
310 | * status. | ||
311 | * | ||
312 | * Byte Value Meaning | ||
313 | * 0 0xFF Sync byte (required only for UART serial) | ||
314 | * 1 0x55 Start of telegram | ||
315 | * 2 0x07 Telegram payload length | ||
316 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
317 | * 4 0x00 Command ID (bits 15:8) | ||
318 | * 5 0x05 Command ID (bits 7:0) | ||
319 | * 6 0xNN Currently playingchapter index (bits31:24) | ||
320 | * 7 0xNN Currently playingchapter index (bits23:16) | ||
321 | * 8 0xNN Currently playing chapter index (bits 15:8) | ||
322 | * 9 0xNN Currently playing chapter index (bits 7:0) | ||
323 | * 10 0xNN Telegram payload checksum byte | ||
324 | * | ||
325 | * The returned data includes 4 bytes for Chapter Length followed | ||
326 | * by 4 bytes of elapsed time If there is no currently playing | ||
327 | * chapter, length and elapsed are 0 | ||
328 | * We don't do anything with this as we don't support chapters, | ||
329 | * so just return BAD_PARAM | ||
330 | */ | ||
331 | { | ||
332 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
333 | break; | ||
334 | } | ||
335 | case 0x0006: /* ReturnCurrentPlayingTrackChapterPlayStatus. See Above */ | ||
336 | /* The following is the description for the Apple Firmware | ||
337 | * | ||
338 | * Returns the play status of the currently playing track chapter. | ||
339 | * The iPod sends this telegram in response to the Command 0x0005: | ||
340 | * GetCurrentPlayingTrackChapterPlayStatus telegram from the device. | ||
341 | * The returned information includes the chapter length and elapsed | ||
342 | * time, in milliseconds. If there is no currently playing chapter, | ||
343 | * the chapter length and elapsed time are zero. | ||
344 | * | ||
345 | * Byte Value Meaning | ||
346 | * 0 0xFF Sync byte (required only for UART serial) | ||
347 | * 1 0x55 Start of telegram | ||
348 | * 2 0x0B Telegram payload length | ||
349 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
350 | * 4 0x00 Command ID (bits 15:8) | ||
351 | * 5 0x06 Command ID (bits 7:0) | ||
352 | * 6 0xNN Chapter length in milliseconds (bits 31:24) | ||
353 | * 7 0xNN Chapter length in milliseconds (bits 23:16) | ||
354 | * 8 0xNN Chapter length in milliseconds (bits 15:8) | ||
355 | * 9 0xNN Chapter length in milliseconds (bits 7:0) | ||
356 | * 10 0xNN Elapsed time in chapter, in milliseconds (bits 31:24) | ||
357 | * 11 0xNN Elapsed time in chapter, in milliseconds (bits 23:16) | ||
358 | * 12 0xNN Elapsed time in chapter, in milliseconds (bits 15:8) | ||
359 | * 13 0xNN Elapsed time in chapter, in milliseconds (bits 7:0) | ||
360 | * 14 0xNN Telegram payload checksum byte | ||
361 | */ | ||
362 | { | ||
363 | /* We should NEVER receive this command so ERROR if we do */ | ||
364 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
365 | break; | ||
366 | } | ||
367 | case 0x0007: /* GetCurrentPlayingTrackChapterName */ | ||
368 | /* The following is the description for the Apple Firmware | ||
369 | * | ||
370 | * Requests a chapter name in the currently playing track. In | ||
371 | * response to a valid telegram, the iPod sends a Command 0x0008: | ||
372 | * ReturnCurrentPlayingTrackChapterName telegram to the device. | ||
373 | * | ||
374 | * Note: If the received telegram length or track index is invalid | ||
375 | * for instance, if the track does not have chapter information or | ||
376 | * is not a part of the Audiobook category, the iPod responds with | ||
377 | * an ACK telegram including the specific error status. | ||
378 | * | ||
379 | * Byte Value Meaning | ||
380 | * 0 0xFF Sync byte (required only for UART serial) | ||
381 | * 1 0x55 Start of telegram | ||
382 | * 2 0x07 Telegram payload length | ||
383 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
384 | * 4 0x00 Command ID (bits 15:8) | ||
385 | * 5 0x07 Command ID (bits 7:0) | ||
386 | * 6 0xNN Chapter index (bits 31:24) | ||
387 | * 7 0xNN Chapter index (bits 23:16) | ||
388 | * 8 0xNN Chapter index (bits 15:8) | ||
389 | * 9 0xNN Chapter index (bits 7:0) | ||
390 | * 10 0xNN Telegram payload checksum byte | ||
391 | * | ||
392 | * We don't do anything with this as we don't support chapters, | ||
393 | * so just return BAD_PARAM | ||
394 | */ | ||
395 | { | ||
396 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
397 | break; | ||
398 | } | ||
399 | case 0x0008: /* ReturnCurrentPlayingTrackChapterName. See Above */ | ||
400 | /* The following is the description for the Apple Firmware | ||
401 | * | ||
402 | * Returns a chapter name in the currently playing track. The iPod | ||
403 | * sends this telegram in response to a valid Command 0x0007: | ||
404 | * GetCurrentPlayingTrackChapterName telegram from the | ||
405 | * device. The chapter name is encoded as a null-terminated UTF-8 | ||
406 | * character array. | ||
407 | * | ||
408 | * Note: The chapter name string is not limited to 252 characters; | ||
409 | * it may be sent in small or large telegram format depending on | ||
410 | * the string length. The small telegram format is shown. | ||
411 | * | ||
412 | * Byte Value Meaning | ||
413 | * 0 0xFF Sync byte (required only for UART serial) | ||
414 | * 1 0x55 Start of telegram | ||
415 | * 2 0xNN Telegram payload length | ||
416 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
417 | * 4 0x00 Command ID (bits 15:8) | ||
418 | * 5 0x08 Command ID (bits 7:0) | ||
419 | * 6-N 0xNN Chapter name as UTF-8 character array | ||
420 | *(last byte) 0xNN Telegram payload checksum byte | ||
421 | * | ||
422 | */ | ||
423 | { | ||
424 | /* We should NEVER receive this command so ERROR if we do */ | ||
425 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
426 | break; | ||
427 | } | ||
428 | case 0x0009: /* GetAudioBookSpeed */ | ||
429 | /* The following is the description for the Apple Firmware | ||
430 | * | ||
431 | * Requests the current iPod audiobook speed state. The iPod | ||
432 | * responds with the “Command 0x000A: ReturnAudiobookSpeed” | ||
433 | * telegram indicating the current audiobook speed. | ||
434 | * | ||
435 | * Byte Value Meaning | ||
436 | * 0 0xFF Sync byte (required only for UART serial) | ||
437 | * 1 0x55 Start of telegram | ||
438 | * 2 0x03 Telegram payload length | ||
439 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
440 | * 4 0x00 Command ID (bits 15:8) | ||
441 | * 5 0x09 Command ID (bits 7:0) | ||
442 | * 6 0xF0 Telegram payload checksum byte | ||
443 | * | ||
444 | * ReturnAudioBookSpeed | ||
445 | * 0x00 = Normal, 0xFF = Slow, 0x01 = Fast | ||
446 | * We always respond with Normal speed | ||
447 | */ | ||
448 | { | ||
449 | unsigned char data[] = {0x04, 0x00, 0x0A, 0x00}; | ||
450 | iap_send_pkt(data, sizeof(data)); | ||
451 | break; | ||
452 | } | ||
453 | case 0x000A: /* ReturnAudioBookSpeed. See Above */ | ||
454 | /* The following is the description for the Apple Firmware | ||
455 | * | ||
456 | * Returns the current audiobook speed setting. The iPod sends | ||
457 | * this telegram in response to the Command 0x0009: | ||
458 | * GetAudiobookSpeed command from the device. | ||
459 | * | ||
460 | * Byte Value Meaning | ||
461 | * 0 0xFF Sync byte (required only for UART serial) | ||
462 | * 1 0x55 Start of telegram | ||
463 | * 2 0x04 Telegram payload length | ||
464 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
465 | * 4 0x00 Command ID (bits 15:8) | ||
466 | * 5 0x0A Command ID (bits 7:0) | ||
467 | * 6 0xNN Audiobook speed status code. | ||
468 | * 0xFF Slow (-1) | ||
469 | * 0x00 Normal | ||
470 | * 0x01 Fast (+1) | ||
471 | * 7 0xNN Telegram payload checksum byte | ||
472 | * | ||
473 | */ | ||
474 | { | ||
475 | /* We should NEVER receive this command so ERROR if we do */ | ||
476 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
477 | break; | ||
478 | } | ||
479 | case 0x000B: /* SetAudioBookSpeed */ | ||
480 | /* The following is the description for the Apple Firmware | ||
481 | * Sets the speed of audiobook playback. The iPod audiobook speed | ||
482 | * states are listed above. This telegram has two modes: one to | ||
483 | * set the speed of the currently playing audiobook and a second | ||
484 | * to set the audiobook speed for all audiobooks. Byte number 7 | ||
485 | * is an optional byte; devices should not send this byte if they | ||
486 | * want to set the speed only of the currently playing audiobook. | ||
487 | * If devices want to set the global audiobook speed setting then | ||
488 | * they must use byte number 7. This is the Restore on Exit byte; | ||
489 | * a nonzero value restores the original audiobook speed setting | ||
490 | * when the accessory is detached. If this byte is zero, the | ||
491 | * audiobook speed setting set by the accessory is saved and | ||
492 | * persists after the accessory is detached from the iPod. See below | ||
493 | * for the telegram format used when including the Restore on Exit | ||
494 | * byte. | ||
495 | * In response to this command, the iPod sends an ACK telegram with | ||
496 | * the command status. | ||
497 | * | ||
498 | * Note: Accessory developers are encouraged to always use the | ||
499 | * Restore on Exit byte with a nonzero value, to restore any of the | ||
500 | * user's iPod settings that were modified by the accessory. | ||
501 | * | ||
502 | * Byte Value Meaning (Cuurent audiobook only | ||
503 | * 0 0xFF Sync byte (required only for UART serial) | ||
504 | * 1 0x55 Start of telegram | ||
505 | * 2 0x04 Telegram payload length | ||
506 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
507 | * 4 0x00 Command ID (bits 15:8) | ||
508 | * 5 0x0B Command ID (bits 7:0) | ||
509 | * 6 0xNN New audiobook speed code. | ||
510 | * 7 0xNN Telegram payload checksum byte | ||
511 | * | ||
512 | * | ||
513 | * SetAudiobookSpeed telegram to set the global audiobook speed | ||
514 | * Byte Value Meaning | ||
515 | * 0 0xFF Sync byte (required only for UART serial) | ||
516 | * 1 0x55 Start of telegram | ||
517 | * 2 0x05 Telegram payload length | ||
518 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
519 | * 4 0x00 Command ID (bits 15:8) | ||
520 | * 5 0x0B Command ID (bits 7:0) | ||
521 | * 6 0xNN Global audiobook speed code. | ||
522 | * 7 0xNN Restore on Exit byte. | ||
523 | * If 1, the original setting is restored on detach; | ||
524 | * if 0, the newsetting persists after accessory detach. | ||
525 | * 8 0xNN Telegram payload checksum byte | ||
526 | * | ||
527 | * | ||
528 | * We don't do anything with this as we don't support chapters, | ||
529 | * so just return BAD_PARAM | ||
530 | */ | ||
531 | { | ||
532 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
533 | break; | ||
534 | } | ||
535 | case 0x000C: /* GetIndexedPlayingTrackInfo */ | ||
536 | /* The following is the description for the Apple Firmware | ||
537 | * | ||
538 | * Gets track information for the track at the specified index. | ||
539 | * The track info type field specifies the type of information to be | ||
540 | * returned, such as song lyrics, podcast name, episode date, and | ||
541 | * episode description. In response, the iPod sends the Command | ||
542 | * 0x000D: ReturnIndexedPlayingTrackInfo command with the requested | ||
543 | * track information. If the information type is invalid or does not | ||
544 | * apply to the selected track, the iPod returns an ACK with an | ||
545 | * error status. | ||
546 | * | ||
547 | * Byte Value Meaning | ||
548 | * 0 0xFF Sync byte (required only for UART serial) | ||
549 | * 1 0x55 Start of telegram | ||
550 | * 2 0x0A Telegram payload length | ||
551 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
552 | * 4 0x00 Command ID (bits 15:8) | ||
553 | * 5 0x0C Command ID (bits 7:0) | ||
554 | * 6 0xNN Track info type. See Below | ||
555 | * 7 0xNN Track index (bits 31:24) | ||
556 | * 8 0xNN Track index (bits 23:16) | ||
557 | * 9 0xNN Track index (bits 15:8) | ||
558 | * 10 0xNN Track index (bits 7:0) | ||
559 | * 11 0xNN Chapter index (bits 15:8) | ||
560 | * 12 0xNN Chapter index (bits 7:0) | ||
561 | * (last byte)0xNN Telegram payload checksum byte | ||
562 | * | ||
563 | * Track Info Types: Return Data | ||
564 | * 0x00 Track Capabilities. 10byte data | ||
565 | * 0x01 Podcast Name UTF-8 String | ||
566 | * 0x02 Track Release Date 7Byte Data All 0 if invalid | ||
567 | * 0x03 Track Description UTF-8 String | ||
568 | * 0x04 Track Song Lyrics UTF-8 String | ||
569 | * 0x05 Track Genre UTF-8 String | ||
570 | * 0x06 Track Composer UTF-8 String | ||
571 | * 0x07 Track Artwork Count 2byte formatID and 2byte count of images | ||
572 | * 0x08-0xff Reserved | ||
573 | * | ||
574 | * Track capabilities | ||
575 | * 0x00-0x03 | ||
576 | * Bit0 is Audiobook | ||
577 | * Bit1 has chapters | ||
578 | * Bit2 has album art | ||
579 | * Bit3 has lyrics | ||
580 | * Bit4 is podcast episode | ||
581 | * Bit5 has Release Date | ||
582 | * Bit6 has Decription | ||
583 | * Bit7 Contains Video | ||
584 | * Bit8 Play as Video | ||
585 | * Bit9+ Reserved | ||
586 | * 0x04-0x07 Total Track Length in ms | ||
587 | * 0x08-0x09 Chapter Count | ||
588 | * | ||
589 | * Track Release Date Encoding | ||
590 | * 0x00 Seconds 0-59 | ||
591 | * 0x01 Minutes 0-59 | ||
592 | * 0x02 Hours 0-23 | ||
593 | * 0x03 Day Of Month 1-31 | ||
594 | * 0x04 Month 1-12 | ||
595 | * 0x05 Year Bits 15:8 2006 = 2006AD | ||
596 | * 0x06 Year Bits 7:0 | ||
597 | * 0x07 Weekday 0-6 where 0=Sunday 6=Saturday | ||
598 | * | ||
599 | * | ||
600 | */ | ||
601 | { | ||
602 | if (len < (10)) | ||
603 | { | ||
604 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
605 | break; | ||
606 | } | ||
607 | struct mp3entry *id3 = audio_current_track(); | ||
608 | |||
609 | switch(buf[3]) | ||
610 | { | ||
611 | case 0x01: /* Podcast Not Supported */ | ||
612 | case 0x04: /* Lyrics Not Supported */ | ||
613 | case 0x03: /* Description */ | ||
614 | case 0x05: /* Genre */ | ||
615 | case 0x06: /* Composer */ | ||
616 | { | ||
617 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
618 | break; | ||
619 | } | ||
620 | default: | ||
621 | { | ||
622 | IAP_TX_INIT4(0x04, 0x000D); | ||
623 | IAP_TX_PUT(buf[3]); | ||
624 | switch(buf[3]) | ||
625 | { | ||
626 | case 0x00: | ||
627 | { | ||
628 | /* Track Capabilities 10Bytes Data */ | ||
629 | IAP_TX_PUT_U32(0); /* Track Capabilities. */ | ||
630 | /* Currently None Supported*/ | ||
631 | IAP_TX_PUT_U32(id3->length); /* Track Length */ | ||
632 | IAP_TX_PUT_U16(0x00); /* Chapter Count */ | ||
633 | break; | ||
634 | } | ||
635 | case 0x02: | ||
636 | { | ||
637 | /* Track Release Date 7 Bytes Data | ||
638 | * Currently only returns a fixed value, | ||
639 | * Sunday 1st Feb 2011 3Hr 4Min 5Secs | ||
640 | */ | ||
641 | IAP_TX_PUT(5); /* Seconds 0-59 */ | ||
642 | IAP_TX_PUT(4); /* Minutes 0-59 */ | ||
643 | IAP_TX_PUT(3); /* Hours 0-23 */ | ||
644 | IAP_TX_PUT(1); /* Day Of Month 1-31 */ | ||
645 | IAP_TX_PUT(2); /* Month 1-12 */ | ||
646 | IAP_TX_PUT_U16(2011); /* Year */ | ||
647 | IAP_TX_PUT(0); /* Day 0=Sunday */ | ||
648 | break; | ||
649 | } | ||
650 | case 0x07: | ||
651 | { | ||
652 | /* Track Artwork Count */ | ||
653 | /* Currently not supported */ | ||
654 | IAP_TX_PUT_U16(0x00); /* Format ID */ | ||
655 | IAP_TX_PUT_U16(0x00); /* Image Count */ | ||
656 | break; | ||
657 | } | ||
658 | } | ||
659 | iap_send_tx(); | ||
660 | break; | ||
661 | } | ||
662 | } | ||
663 | break; | ||
664 | } | ||
665 | case 0x000D: /* ReturnIndexedPlayingTrackInfo. See Above */ | ||
666 | /* The following is the description for the Apple Firmware | ||
667 | * | ||
668 | * Returns the requested track information type and data. The iPod | ||
669 | * sends this command in response to the Command 0x000C: | ||
670 | * GetIndexedPlayingTrackInfo command. | ||
671 | * Data returned as strings are encoded as null-terminated UTF-8 | ||
672 | * character arrays. | ||
673 | * If the track information string does not exist, a null UTF-8 | ||
674 | * string is returned. If the track has no release date, then the | ||
675 | * returned release date has all bytes zeros. Track song lyrics and | ||
676 | * the track description are sent in a large or small telegram | ||
677 | * format with an incrementing packet index field, spanning | ||
678 | * multiple packets if needed. | ||
679 | * | ||
680 | * Below is the packet format for the | ||
681 | * ReturnIndexedPlayingTrackInfo telegram sent in response to a | ||
682 | * request for information types 0x00 to 0x02. | ||
683 | * | ||
684 | * Byte Value Meaning | ||
685 | * 0 0xFF Sync byte | ||
686 | * 1 0x55 Start of telegram | ||
687 | * 2 0xNN Telegram payload length | ||
688 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
689 | * 4 0x00 Command ID (bits 15:8) | ||
690 | * 5 0x0D Command ID (bits 7:0) | ||
691 | * 6 0xNN Track info type. See | ||
692 | * 7-N 0xNN Track information. The data format is specific | ||
693 | * to the track info type. | ||
694 | * NN 0xNN Telegram payload checksum byte | ||
695 | * | ||
696 | * Below is the large packet format for the | ||
697 | * ReturnIndexedPlayingTrackInfo telegram sent in response to a | ||
698 | * request for information types 0x03 to 0x04. The small telegram | ||
699 | * format is not shown. | ||
700 | * | ||
701 | * Byte Value Meaning | ||
702 | * 0 0xFF Sync byte | ||
703 | * 1 0x55 Start of telegram | ||
704 | * 2 0x00 Telegram payload marker (large format) | ||
705 | * 3 0xNN Large telegram payload length (bits 15:8) | ||
706 | * 4 0xNN Large telegram payload length (bits 7:0) | ||
707 | * 5 0x04 Lingo ID (Extended Interface lingo) | ||
708 | * 6 0x00 Command ID (bits 15:8) | ||
709 | * 7 0x0D Command ID (bits 7:0) | ||
710 | * 8 0xNN Track info type. | ||
711 | * 9 0xNN Packet information bits. If set, | ||
712 | * these bits have the following meanings: | ||
713 | * Bit 0: Indicates that there are multiple packets. | ||
714 | * Bit 1: This is the last packet. Applicable only if | ||
715 | * bit 0 is set. | ||
716 | * Bit 31:2 Reserved | ||
717 | * 10 0xNN Packet Index (bits 15:8) | ||
718 | * 11 0xNN Packet Index (bits 7:0) | ||
719 | * 12-N 0xNN Track information as a UTF-8 string. | ||
720 | * NN 0xNN Telegram payload checksum byte | ||
721 | * | ||
722 | * Track info types and return data | ||
723 | * Info Type Code Data Format | ||
724 | * 0x00 Track Capabilities and Information 10-byte data. | ||
725 | * 0x01 PodcastName UTF-8 string | ||
726 | * 0x02 Track Release Date 7-byte data. | ||
727 | * 0x03 Track Description UTF-8 string | ||
728 | * 0x04 Track Song Lyrics UTF-8 string | ||
729 | * 0x05 TrackGenre UTF-8 string | ||
730 | * 0x06 Track Composer UTF-8 string | ||
731 | * 0x07 Track Artwork Count Artwork count data. The | ||
732 | * artwork count is a sequence of 4-byte records; each record | ||
733 | * consists of a 2-byte format ID value followed by a 2-byte | ||
734 | * count of images in that format for this track. For more | ||
735 | * information about formatID and chapter index values, see | ||
736 | * commands 0x000E-0x0011 and 0x002A-0x002B. | ||
737 | * 0x08-0xFF Reserved | ||
738 | * | ||
739 | * Track Capabilities and Information encoding | ||
740 | * Byte Code | ||
741 | * 0x00-0x03 Track Capability bits. If set, these bits have the | ||
742 | * following meanings: | ||
743 | * Bit 0: Track is audiobook | ||
744 | * Bit 1: Track has chapters | ||
745 | * Bit 2: Track has album artwork | ||
746 | * Bit 3: Track has song lyrics | ||
747 | * Bit 4: Track is a podcast episode | ||
748 | * Bit 5: Track has release date | ||
749 | * Bit 6: Track has description | ||
750 | * Bit 7: Track contains video (a video podcast, music | ||
751 | * video, movie, or TV show) | ||
752 | * Bit 8: Track is currently queued to play as a video | ||
753 | * Bit 31:9: Reserved | ||
754 | * 0x04 Total track length, in milliseconds (bits 31:24) | ||
755 | * 0x05 Total track length, in milliseconds (bits 23:16) | ||
756 | * 0x06 Total track length, in milliseconds (bits 15:8) | ||
757 | * 0x07 Total track length, in milliseconds (bits 7:0) | ||
758 | * 0x08 Chapter count (bits 15:8) | ||
759 | * 0x09 Chapter count (bits 7:0) | ||
760 | * | ||
761 | * Track Release Date encoding | ||
762 | * Byte Code | ||
763 | * 0x00 Seconds (0-59) | ||
764 | * 0x01 Minutes (0-59) | ||
765 | * 0x02 Hours (0-23) | ||
766 | * 0x03 Day of themonth(1-31) | ||
767 | * 0x04 Month (1-12) | ||
768 | * 0x05 Year (bits 15:8). For example, 2006 signifies the year 2006 | ||
769 | * 0x06 Year (bits 7:0) | ||
770 | * 0x07 Weekday (0-6, where 0 = Sunday and 6 = Saturday) | ||
771 | * | ||
772 | */ | ||
773 | { | ||
774 | /* We should NEVER receive this command so ERROR if we do */ | ||
775 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
776 | break; | ||
777 | } | ||
778 | case 0x000E: /* GetArtworkFormats */ | ||
779 | /* The following is the description for the Apple Firmware | ||
780 | * | ||
781 | * The device sends this command to obtain the list of supported | ||
782 | * artwork formats on the iPod. No parameters are sent. | ||
783 | * | ||
784 | * Byte Value Comment | ||
785 | * 0 0xFF Sync byte (required only for UART serial) | ||
786 | * 1 0x55 Start of telegram | ||
787 | * 2 0x03 Length of packet | ||
788 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
789 | * 4 0x00 Command ID (bits 15:8) | ||
790 | * 5 0x0E Command ID (bits 7:0) | ||
791 | * 6 0xEB Checksum/ | ||
792 | * | ||
793 | * Returned Artwork Formats are a 7byte record. | ||
794 | * formatID:2 | ||
795 | * pixelFormat:1 | ||
796 | * width:2 | ||
797 | * height:2 | ||
798 | */ | ||
799 | { | ||
800 | unsigned char data[] = {0x04, 0x00, 0x0F, | ||
801 | 0x04, 0x04, /* FormatID */ | ||
802 | 0x02, /* PixelFormat*/ | ||
803 | 0x00, 0x64, /* 100 pixels */ | ||
804 | 0x00, 0x64, /* 100 pixels */ | ||
805 | 0x04, 0x05, /* FormatID */ | ||
806 | 0x02, /* PixelFormat*/ | ||
807 | 0x00, 0xC8, /* 200 pixels */ | ||
808 | 0x00, 0xC8 /* 200 pixels */ | ||
809 | }; | ||
810 | iap_send_pkt(data, sizeof(data)); | ||
811 | break; | ||
812 | } | ||
813 | case 0x000F: /* RetArtworkFormats. See Above */ | ||
814 | /* The following is the description for the Apple Firmware | ||
815 | * | ||
816 | * The iPod sends this command to the device, giving it the list | ||
817 | * of supported artwork formats. Each format is described in a | ||
818 | * 7-byte record (formatID:2, pixelFormat:1, width:2, height:2). | ||
819 | * The formatID is used when sending GetTrackArtworkTimes. | ||
820 | * The device may return zero records. | ||
821 | * | ||
822 | * Byte Value Comment | ||
823 | * 0 0xFF Sync byte (required only for UART serial) | ||
824 | * 1 0x55 Start of telegram | ||
825 | * 2 0xNN Length of packet | ||
826 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
827 | * 4 0x00 Command ID (bits 15:8) | ||
828 | * 5 0x0F Command ID (bits 7:0) | ||
829 | * NN 0xNN formatID (15:8) iPod-assigned value for this format | ||
830 | * NN 0xNN formatID (7:0) | ||
831 | * NN 0xNN pixelFormat. Same as from SetDisplayImage | ||
832 | * NN 0xNN imageWidth(15:8).Number of pixels widefor eachimage. | ||
833 | * NN 0xNN imageWidth (7:0) | ||
834 | * NN 0xNN imageHeight (15:8). Number of pixels high for each | ||
835 | * NN 0xNN imageHeight (7:0). image | ||
836 | * Previous 7 bytes may be repeated NN times | ||
837 | * NN 0xNN Checksum | ||
838 | * | ||
839 | */ | ||
840 | { | ||
841 | /* We should NEVER receive this command so ERROR if we do */ | ||
842 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
843 | break; | ||
844 | } | ||
845 | case 0x0010: /* GetTrackArtworkData */ | ||
846 | /* The following is the description for the Apple Firmware | ||
847 | * The device sends this command to the iPod to request data for a | ||
848 | * given trackIndex, formatID, and artworkIndex. The time offset | ||
849 | * from track start is the value returned by GetTrackArtworkTimes | ||
850 | * | ||
851 | * Byte Value Comment | ||
852 | * 0 0xFF Sync byte (required only for UART serial) | ||
853 | * 1 0x55 Start of telegram | ||
854 | * 2 0x0D Length of packet | ||
855 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
856 | * 4 0x00 Command ID (bits 15:8) | ||
857 | * 5 0x10 Command ID (bits 7:0) | ||
858 | * 6 0xNN trackIndex (31:24). | ||
859 | * 7 0xNN trackIndex(23:16) | ||
860 | * 8 0xNN trackIndex (15:8) | ||
861 | * 9 0xNN trackIndex (7:0) | ||
862 | * 10 0xNN formatID (15:8) | ||
863 | * 11 0xNN formatID (7:0) | ||
864 | * 12 0xNN time offset from track start, in ms (31:24) | ||
865 | * 13 0xNN time offset from track start, in ms (23:16) | ||
866 | * 14 0xNN time offset from track start, in ms (15:8) | ||
867 | * 15 0xNN time offset from track start, in ms (7:0) | ||
868 | * 16 0xNN Checksum | ||
869 | * | ||
870 | * Returned data is | ||
871 | * DescriptorTelegramIndex: 2 | ||
872 | * pixelformatcode: 1 | ||
873 | * ImageWidthPixels: 2 | ||
874 | * ImageHeightPixels: 2 | ||
875 | * InsetRectangleTopLeftX: 2 | ||
876 | * InsetRectangleTopLeftY: 2 | ||
877 | * InsetRectangleBotRightX: 2 | ||
878 | * InsetRectangleBotRightY: 2 | ||
879 | * RowSizeInBytes: 4 | ||
880 | * ImagePixelData:VariableLength | ||
881 | * Subsequent packets omit bytes 8 - 24 | ||
882 | */ | ||
883 | { | ||
884 | unsigned char data[] = {0x04, 0x00, 0x11, | ||
885 | 0x00, 0x00, /* DescriptorIndex */ | ||
886 | 0x00, /* PixelFormat */ | ||
887 | 0x00, 0x00, /* ImageWidthPixels*/ | ||
888 | 0x00, 0x00, /* ImageHeightPixels*/ | ||
889 | 0x00, 0x00, /* InsetRectangleTopLeftX*/ | ||
890 | 0x00, 0x00, /* InsetRectangleTopLeftY*/ | ||
891 | 0x00, 0x00, /* InsetRectangleBotRightX*/ | ||
892 | 0x00, 0x00, /* InsetRectangleBotRoghtY*/ | ||
893 | 0x00, 0x00, 0x00, 0x00,/* RowSize*/ | ||
894 | 0x00 /* ImagePixelData Var Length*/ | ||
895 | }; | ||
896 | iap_send_pkt(data, sizeof(data)); | ||
897 | break; | ||
898 | } | ||
899 | case 0x0011: /* RetTrackArtworkData. See Abobe */ | ||
900 | /* The following is the description for the Apple Firmware | ||
901 | * | ||
902 | * The iPod sends the requested artwork to the accessory. Multiple | ||
903 | * RetTrackArtworkData commands may be necessary to transfer all | ||
904 | * the data because it will be too much to fit into a single packet. | ||
905 | * This command uses nearly the same format as the SetDisplayImage | ||
906 | * command (command 0x0032). The only difference is the addition | ||
907 | * of 2 coordinates; they define an inset rectangle that describes | ||
908 | * any padding that may have been added to the image. The | ||
909 | * coordinates consist of two x,y pairs. Each x or y value is 2 | ||
910 | * bytes, so the total size of the coordinate set is 8 bytes. | ||
911 | * | ||
912 | * Byte Value Comment | ||
913 | * 0 0xFF Sync byte (required only for UART serial) | ||
914 | * 1 0x55 Start of telegram | ||
915 | * 2 0xNN Length of packet | ||
916 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
917 | * 4 0x00 Command ID (bits 15:8) | ||
918 | * 5 0x11 Command ID (bits 7:0) | ||
919 | * 6 0x00 Descriptor telegram index (15:8). | ||
920 | * These fields uniquely identify each packet in the | ||
921 | * RetTrackArtworkData transaction. The first telegram | ||
922 | * is the descriptor telegram, which always starts with | ||
923 | * an index of 0x0000. | ||
924 | * 7 0x00 Descriptor telegram index (7:0) | ||
925 | * 8 0xNN Display pixel format code. | ||
926 | * 9 0xNN Imagewidth in pixels (15:8) | ||
927 | * 10 0xNN Image width in pixels (7:0) | ||
928 | * 11 0xNN Image height in pixels (15:8) | ||
929 | * 12 0xNN Image height in pixels (7:0) | ||
930 | * 13 0xNN Inset rectangle, top-left point, x value (15:8) | ||
931 | * 14 0xNN Inset rectangle, top-left point, x value (7:0) | ||
932 | * 15 0xNN Inset rectangle, top-left point, y value (15:8) | ||
933 | * 16 0xNN Inset rectangle, top-left point, y value (7:0) | ||
934 | * 17 0xNN Inset rectangle,bottom-rightpoint,xvalue(15:8) | ||
935 | * 18 0xNN Inset rectangle,bottom-rightpoint, x value(7:0) | ||
936 | * 19 0xNN Inset rectangle,bottom-rightpoint,y value(15:8) | ||
937 | * 20 0xNN Inset rectangle, bottom-right point, y value(7:0) | ||
938 | * 21 0xNN Rowsize in bytes (31:24) | ||
939 | * 22 0xNN Rowsize in bytes (23:16) | ||
940 | * 23 0xNN Row size in bytes (15:8) | ||
941 | * 24 0xNN Row size in bytes (7:0) | ||
942 | * 25-NN 0xNN Image pixel data (variable length) | ||
943 | * NN 0xNN Checksum | ||
944 | * | ||
945 | * In subsequent packets in the sequence, bytes 8 through 24 are | ||
946 | * omitted. | ||
947 | */ | ||
948 | { | ||
949 | /* We should NEVER receive this command so ERROR if we do */ | ||
950 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
951 | break; | ||
952 | } | ||
953 | case 0x0012: /* RequestProtocolVersion */ | ||
954 | /* The following is the description for the Apple Firmware | ||
955 | * | ||
956 | * This command is deprecated. | ||
957 | * | ||
958 | * Requests the version of the running protocol from the iPod. | ||
959 | * The iPod responds with a Command 0x0013:ReturnProtocolVersion | ||
960 | * command. | ||
961 | * | ||
962 | * Note: This command requests the Extended Interface protocol | ||
963 | * version, not the iPod software version. | ||
964 | * | ||
965 | * Byte Value Meaning | ||
966 | * 0 0xFF Sync byte (required only for UART serial) | ||
967 | * 1 0x55 Start of telegram | ||
968 | * 2 0x03 Telegram payload length | ||
969 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
970 | * 4 0x00 Command ID (bits 15:8) | ||
971 | * 5 0x12 Command ID (bits 7:0) | ||
972 | * 6 0xE7 Telegram payload checksum byte | ||
973 | * | ||
974 | */ | ||
975 | { | ||
976 | IAP_TX_INIT4(0x04, 0x0013); | ||
977 | IAP_TX_PUT(LINGO_MAJOR(0x04)); | ||
978 | IAP_TX_PUT(LINGO_MINOR(0x04)); | ||
979 | iap_send_tx(); | ||
980 | break; | ||
981 | } | ||
982 | case 0x0013: /* ReturnProtocolVersion. See Above */ | ||
983 | /* The following is the description for the Apple Firmware | ||
984 | * This command is deprecated. | ||
985 | * Sent from the iPod to the device | ||
986 | * Returns the iPod Extended Interface protocol version number. | ||
987 | * The iPod sends this command in response to the Command 0x0012: | ||
988 | * RequestProtocolVersion command from the device. The major | ||
989 | * version number specifies the protocol version digits to the left | ||
990 | * of the decimal point; the minor version number specifies the | ||
991 | * digits to the right of the decimal point. For example, a major | ||
992 | * version number of 0x01 and a minor version number of 0x08 | ||
993 | * represents an Extended Interface protocol version of 1.08. This | ||
994 | * protocol information is also available through the General lingo | ||
995 | * (lingo 0x00) command RequestLingoProtocolVersion when passing | ||
996 | * lingo 0x04 as the lingo parameter. | ||
997 | * | ||
998 | * Note: This command returns the Extended Interface protocol | ||
999 | * version, not the iPod software version. | ||
1000 | * | ||
1001 | * Byte Value Meaning | ||
1002 | * 0 0xFF Sync byte (required only for UART serial) | ||
1003 | * 1 0x55 Start of telegram | ||
1004 | * 2 0x05 Telegram payload length | ||
1005 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1006 | * 4 0x00 Command ID (bits 15:8) | ||
1007 | * 5 0x13 Command ID (bits 7:0) | ||
1008 | * 6 0xNN Protocol major version number | ||
1009 | * 7 0xNN Protocol minor version number | ||
1010 | * 8 0xNN Telegram payload checksum byte | ||
1011 | * | ||
1012 | */ | ||
1013 | { | ||
1014 | /* We should NEVER receive this command so ERROR if we do */ | ||
1015 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1016 | break; | ||
1017 | } | ||
1018 | case 0x0014: /* RequestiPodName */ | ||
1019 | /* The following is the description for the Apple Firmware | ||
1020 | * This command is deprecated. | ||
1021 | * Retrieves the name of the iPod | ||
1022 | * | ||
1023 | * Returns the name of the user's iPod or 'iPod' if the iPod name | ||
1024 | * is undefined. This allows the iPod name to be shown in the | ||
1025 | * human-machineinterface(HMI) of the interfacingbody. The iPod | ||
1026 | * responds with the Command 0x0015: ReturniPodName command | ||
1027 | * containing the iPod name text string. | ||
1028 | * | ||
1029 | * Byte Value Meaning | ||
1030 | * 0 0xFF Sync byte (required only for UART serial) | ||
1031 | * 1 0x55 Start of telegram | ||
1032 | * 2 0x03 Telegram payload length | ||
1033 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1034 | * 4 0x00 Command ID (bits 15:8) | ||
1035 | * 5 0x14 Command ID (bits 7:0) | ||
1036 | * 6 0xE5 Telegram payload checksum byte | ||
1037 | * | ||
1038 | * We return ROCKBOX, should this be definable? | ||
1039 | * Should it be Volume Name? | ||
1040 | */ | ||
1041 | { | ||
1042 | IAP_TX_INIT4(0x04, 0x0015); | ||
1043 | IAP_TX_PUT_STRING("ROCKBOX"); | ||
1044 | iap_send_tx(); | ||
1045 | break; | ||
1046 | } | ||
1047 | case 0x0015: /* ReturniPodName. See Above */ | ||
1048 | /* The following is the description for the Apple Firmware | ||
1049 | * This command is deprecated. | ||
1050 | * Sent from the iPod to the device | ||
1051 | * | ||
1052 | * The iPod sends this command in response to the Command 0x0014: | ||
1053 | * RequestiPodName telegram from the device. The iPod name is | ||
1054 | * encoded as a null-terminated UTF-8 character array. The iPod | ||
1055 | * name string is not limited to 252 characters; it may be sent | ||
1056 | * in small or large telegram format. The small telegram format | ||
1057 | * is shown. | ||
1058 | * | ||
1059 | * Note: Starting with version 1.07 of the Extended Interface lingo, | ||
1060 | * the ReturniPodName command on Windows-formatted iPods returns the | ||
1061 | * iTunes name of the iPod instead of the Windows volume name. | ||
1062 | * | ||
1063 | * Byte Value Meaning | ||
1064 | * 0 0xFF Sync byte (required only for UART serial) | ||
1065 | * 1 0x55 Start of telegram | ||
1066 | * 2 0xNN Telegram payload length | ||
1067 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1068 | * 4 0x00 Command ID (bits 15:8) | ||
1069 | * 5 0x15 Command ID (bits 7:0) | ||
1070 | * 6-N 0xNN iPod name as UTF-8 character array | ||
1071 | * NN 0xNN Telegram payload checksum byte | ||
1072 | * | ||
1073 | */ | ||
1074 | { | ||
1075 | /* We should NEVER receive this command so ERROR if we do */ | ||
1076 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1077 | break; | ||
1078 | } | ||
1079 | case 0x0016: /* ResetDBSelection */ | ||
1080 | /* The following is the description for the Apple Firmware | ||
1081 | * | ||
1082 | * Resets the current database selection to an empty state and | ||
1083 | * invalidates the category entry count that is, sets the count | ||
1084 | * to 0, for all categories except the playlist category. This is | ||
1085 | * analogous to pressing the Menu button repeatedly to get to the | ||
1086 | * topmost iPod HMI menu. Any previously selected database items | ||
1087 | * are deselected. The command has no effect on the playback engine | ||
1088 | * In response, the iPod sends an ACK telegram with the command | ||
1089 | * status. Once the accessory has reset the database selection, | ||
1090 | * it must initialize the category count before it can select | ||
1091 | * database records. Please refer to Command 0x0018: | ||
1092 | * GetNumberCategorizedDBRecords and Command 0x0017: | ||
1093 | * SelectDBRecord for details. | ||
1094 | * | ||
1095 | * Note: Starting with protocol version 1.07, the ResetDBSelection | ||
1096 | * command clears the sort order. | ||
1097 | * | ||
1098 | * Byte Value Meaning | ||
1099 | * 0 0xFF Sync byte (required only for UART serial) | ||
1100 | * 1 0x55 Start of telegram | ||
1101 | * 2 0x03 Telegram payload length | ||
1102 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1103 | * 4 0x00 Command ID (bits 15:8) | ||
1104 | * 5 0x16 Command ID (bits 7:0) | ||
1105 | * 6 0xE3 Telegram payload checksum byte | ||
1106 | * | ||
1107 | * | ||
1108 | * Reset the DB Record Type | ||
1109 | * Hierarchy is as follows | ||
1110 | * All = 0 | ||
1111 | * Playlist = 1 | ||
1112 | * Artist = 2 | ||
1113 | * Album = 3 | ||
1114 | * Genre = 4 | ||
1115 | * Tracks = 5 | ||
1116 | * Composers = 6 | ||
1117 | * Audiobooks = 7 | ||
1118 | * Podcasts = 8 | ||
1119 | * | ||
1120 | */ | ||
1121 | { | ||
1122 | cur_dbrecord[0] = 0; | ||
1123 | put_u32(&cur_dbrecord[1],0); | ||
1124 | /* respond with cmd ok packet */ | ||
1125 | cmd_ok(cmd); | ||
1126 | break; | ||
1127 | } | ||
1128 | case 0x0017: /* SelectDBRecord */ | ||
1129 | /* The following is the description for the Apple Firmware | ||
1130 | * Selects one or more records in the Database Engine, based on a | ||
1131 | * category relative index. For example, selecting category two | ||
1132 | * (artist) and record index one results in a list of selected | ||
1133 | * tracks (or database records) from the second artist in the | ||
1134 | * artist list. | ||
1135 | * Selections are additive and limited by the category hierarchy; | ||
1136 | * Subsequent selections are made based on the subset of records | ||
1137 | * resulting from the previous selections and not from the entire | ||
1138 | * database. | ||
1139 | * Note that the selection of a single record automatically passes | ||
1140 | * it to the Playback Engine and starts its playback. Record indices | ||
1141 | * consist of a 32-bit signed integer. To select database records | ||
1142 | * with a specific sort order, use | ||
1143 | * Command 0x0038: SelectSortDBRecord | ||
1144 | * SelectDBRecord should be called only once a category count has | ||
1145 | * been initialized through a call to Command 0x0018: | ||
1146 | * GetNumberCategorizedDBRecords. Without a valid category count, | ||
1147 | * the SelectDBRecord call cannot select a database record and will | ||
1148 | * fail with a command failed ACK. Accessories that make use of | ||
1149 | * Command 0x0016: ResetDBSelection must always initialize the | ||
1150 | * category count before selecting a new database record using | ||
1151 | * SelectDBRecord. | ||
1152 | * Accessories should pay close attention to the ACK returned by the | ||
1153 | * SelectDBRecord command. Ignoring errors may cause unexpected | ||
1154 | * behavior. | ||
1155 | * To undo a database selection, send the SelectDBRecord telegram | ||
1156 | * with the current category selected in theDatabase Engine and a | ||
1157 | * record index of -1 (0xFFFFFFFF). This has the same effect as | ||
1158 | * pressing the iPod Menu button once and moves the database | ||
1159 | * selection up to the next highest menu level. For example, if a | ||
1160 | * device selected artist number three and then album number one, | ||
1161 | * it could use the SelectDBRecord(Album, -1) telegram to return | ||
1162 | * to the database selection of artist number three. If multiple | ||
1163 | * database selections have been made, devices can use any of the | ||
1164 | * previously used categories to return to the next highest database | ||
1165 | * selection. If the category used in one of these SelectDBRecord | ||
1166 | * telegrams has not been used in a previous database selection | ||
1167 | * then the command is treated as a no-op. | ||
1168 | * Sending a SelectDBRecord telegram with the Track category and a | ||
1169 | * record index of -1 is invalid, because the previous database | ||
1170 | * selection made with the Track category and a valid index passes | ||
1171 | * the database selection to the Playback Engine. | ||
1172 | * Sending a SelectDBRecord(Track, -1) telegram returns a parameter | ||
1173 | * error. The iPod also returns a bad parameter error ACK when | ||
1174 | * devices send the SelectDBRecord telegram with an invalid category | ||
1175 | * type, or with the Track category and an index greater than the | ||
1176 | * total number of tracks available on the iPod. | ||
1177 | * | ||
1178 | * Note: Selecting a podcast always selects from the main podcast | ||
1179 | * library regardless of the current category context of the iPod. | ||
1180 | * | ||
1181 | * To immediately go to the topmost iPod menu level and reset all | ||
1182 | * database selections, send the ResetDBSelection telegram to the | ||
1183 | * iPod. | ||
1184 | * | ||
1185 | * Byte Value Meaning | ||
1186 | * 0 0xFF Sync byte (required only for UART serial) | ||
1187 | * 1 0x55 Start of telegram | ||
1188 | * 2 0x08 Telegram payload length | ||
1189 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1190 | * 4 0x00 Command ID (bits 15:8) | ||
1191 | * 5 0x17 Command ID (bits 7:0) | ||
1192 | * 6 0xNN Database category type. See | ||
1193 | * 7 0xNN Database record index (bits 31:24) | ||
1194 | * 8 0xNN Database record index (bits 23:16) | ||
1195 | * 9 0xNN Database record index (bits 15:8) | ||
1196 | * 10 0xNN Database record index (bits 7:0) | ||
1197 | * 11 0xNN Telegram payload checksum byte | ||
1198 | * | ||
1199 | * The valid database categories are listed below | ||
1200 | * | ||
1201 | * Category Code Protocol version | ||
1202 | * Reserved 0x00 N/A | ||
1203 | * Playlist 0x01 1.00 | ||
1204 | * Artist 0x02 1.00 | ||
1205 | * Album 0x03 1.00 | ||
1206 | * Genre 0x04 1.00 | ||
1207 | * Track 0x05 1.00 | ||
1208 | * Composer 0x06 1.00 | ||
1209 | * Audiobook0x07 1.06 | ||
1210 | * Podcast 0x08 1.08 | ||
1211 | * Reserved 0x09+ N/A | ||
1212 | * | ||
1213 | * cur_dbrecord[0] is the record type | ||
1214 | * cur_dbrecord[1-4] is the u32 of the record number requested | ||
1215 | * which might be a playlist or a track number depending on | ||
1216 | * the value of cur_dbrecord[0] | ||
1217 | */ | ||
1218 | { | ||
1219 | memcpy(cur_dbrecord, buf + 3, 5); | ||
1220 | |||
1221 | int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE)); | ||
1222 | uint32_t index; | ||
1223 | uint32_t trackcount; | ||
1224 | index = get_u32(&cur_dbrecord[1]); | ||
1225 | trackcount = playlist_amount(); | ||
1226 | if ((cur_dbrecord[0] == 5) && (index > trackcount)) | ||
1227 | { | ||
1228 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1229 | break; | ||
1230 | } | ||
1231 | if ((cur_dbrecord[0] == 1) && (index > (nbr_total_playlists() + 1))) | ||
1232 | { | ||
1233 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1234 | break; | ||
1235 | } | ||
1236 | audio_pause(); | ||
1237 | switch (cur_dbrecord[0]) | ||
1238 | { | ||
1239 | case 0x01: /* Playlist*/ | ||
1240 | { | ||
1241 | if (index != 0x00) /* 0x00 is the On-The-Go Playlist and | ||
1242 | we do nothing with it */ | ||
1243 | { | ||
1244 | last_selected_playlist = index; | ||
1245 | audio_skip(-iap_get_trackindex()); | ||
1246 | seek_to_playlist(last_selected_playlist); | ||
1247 | } | ||
1248 | break; | ||
1249 | } | ||
1250 | case 0x02: /* Artist */ | ||
1251 | case 0x03: /* Album */ | ||
1252 | case 0x04: /* Genre */ | ||
1253 | case 0x05: /* Track */ | ||
1254 | case 0x06: /* Composer */ | ||
1255 | { | ||
1256 | audio_skip(index - playlist_next(0)); | ||
1257 | break; | ||
1258 | } | ||
1259 | default: | ||
1260 | { | ||
1261 | /* We don't do anything with the other selections. | ||
1262 | * YET. | ||
1263 | */ | ||
1264 | break; | ||
1265 | } | ||
1266 | } | ||
1267 | if (!paused) | ||
1268 | audio_resume(); | ||
1269 | /* respond with cmd ok packet */ | ||
1270 | cmd_ok(cmd); | ||
1271 | break; | ||
1272 | } | ||
1273 | case 0x0018: /* GetNumberCategorizedDBRecords */ | ||
1274 | /* The following is the description for the Apple Firmware | ||
1275 | * | ||
1276 | * Retrieves the number of records in a particular database | ||
1277 | * category. | ||
1278 | * For example, a device can get the number of artists or albums | ||
1279 | * present in the database. The category types are described above. | ||
1280 | * The iPod responds with a Command 0x0019: | ||
1281 | * ReturnNumberCategorizedDBRecords telegram indicating the number | ||
1282 | * of records present for this category. | ||
1283 | * GetNumberCategorizedDBRecords must be called to initialize the | ||
1284 | * category count before selecting a database record using Command | ||
1285 | * 0x0017: SelectDBRecord or Command 0x0038: SelectSortDBRecord | ||
1286 | * commands. A category’s record count can change based on the prior | ||
1287 | * categories selected and the database hierarchy. The accessory | ||
1288 | * is expected to call GetNumberCategorizedDBRecords in order to | ||
1289 | * get the valid range of category entries before selecting a | ||
1290 | * record in that category. | ||
1291 | * | ||
1292 | * Note: The record count returned by this command depends on the | ||
1293 | * database state before this command is sent. If the database has | ||
1294 | * been reset using Command 0x0016: ResetDBSelection this command | ||
1295 | * returns the total number of records for a given category. | ||
1296 | * However, if this command is sent after one or more categories | ||
1297 | * are selected, the record count is the subset of records that are | ||
1298 | * members of all the categories selected prior to this command. | ||
1299 | * | ||
1300 | * Byte Value Meaning | ||
1301 | * 0 0xFF Sync byte (required only for UART serial) | ||
1302 | * 1 0x55 Start of telegram | ||
1303 | * 2 0x04 Telegram payload length | ||
1304 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1305 | * 4 0x00 Command ID (bits 15:8) | ||
1306 | * 5 0x18 Command ID (bits 7:0) | ||
1307 | * 6 0xNN Database category type. See above | ||
1308 | * 7 0xNN Telegram payload checksum byte | ||
1309 | * | ||
1310 | * This is the actual number of available records for that category | ||
1311 | * some head units (Alpine CDE-103BT) use this command before | ||
1312 | * requesting records and then hang if not enough records are | ||
1313 | * returned. | ||
1314 | */ | ||
1315 | { | ||
1316 | unsigned char data[] = {0x04, 0x00, 0x19, | ||
1317 | 0x00, 0x00, 0x00, 0x00}; | ||
1318 | switch(buf[3]) /* type number */ | ||
1319 | { | ||
1320 | case 0x01: /* total number of playlists */ | ||
1321 | dbrecordcount = nbr_total_playlists() + 1; | ||
1322 | break; | ||
1323 | case 0x05: /* total number of Tracks */ | ||
1324 | case 0x02: /* total number of Artists */ | ||
1325 | case 0x03: /* total number of Albums */ | ||
1326 | /* We don't sort on the above but some Head Units | ||
1327 | * require at least one to exist so we just return | ||
1328 | * the number of tracks in the playlist. */ | ||
1329 | dbrecordcount = playlist_amount(); | ||
1330 | break; | ||
1331 | case 0x04: /* total number of Genres */ | ||
1332 | case 0x06: /* total number of Composers */ | ||
1333 | case 0x07: /* total number of AudioBooks */ | ||
1334 | case 0x08: /* total number of Podcasts */ | ||
1335 | /* We don't support the above so just return that | ||
1336 | there are none available. */ | ||
1337 | dbrecordcount = 0; | ||
1338 | break; | ||
1339 | } | ||
1340 | put_u32(&data[3], dbrecordcount); | ||
1341 | iap_send_pkt(data, sizeof(data)); | ||
1342 | break; | ||
1343 | } | ||
1344 | case 0x0019: /* ReturnNumberCategorizedDBRecords. See Above */ | ||
1345 | /* The following is the description for the Apple Firmware | ||
1346 | * | ||
1347 | * Returns the number of database records matching the specified | ||
1348 | * database category. The iPod sends this telegram in response to | ||
1349 | * the Command 0x0018: GetNumberCategorizedDBRecords telegram from | ||
1350 | * the device. Individual records can then be extracted by sending | ||
1351 | * Command 0x001A: RetrieveCategorizedDatabaseRecords to the iPod. | ||
1352 | * If no matching database records are found, a record count of | ||
1353 | * zero is returned. Category types are described above. | ||
1354 | * After selecting the podcast category, the number of artist, | ||
1355 | * album, composer, genre, and audiobook records is always zero. | ||
1356 | * | ||
1357 | * Byte Value Meaning | ||
1358 | * 0 0xFF Sync byte (required only for UART serial) | ||
1359 | * 1 0x55 Start of telegram | ||
1360 | * 2 0x07 Telegram payload length | ||
1361 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1362 | * 4 0x00 Command ID (bits 15:8) | ||
1363 | * 5 0x19 Command ID (bits 7:0) | ||
1364 | * 6 0xNN Database record count (bits 31:24) | ||
1365 | * 7 0xNN Database record count (bits 23:16) | ||
1366 | * 8 0xNN Database record count (bits 15:8) | ||
1367 | * 9 0xNN Database record count (bits 7:0) | ||
1368 | * 10 0xNN Telegram payload checksum byte | ||
1369 | * | ||
1370 | */ | ||
1371 | { | ||
1372 | /* We should NEVER receive this command so ERROR if we do */ | ||
1373 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1374 | break; | ||
1375 | } | ||
1376 | case 0x001A: /* RetrieveCategorizedDatabaseRecords */ | ||
1377 | /* The following is the description for the Apple Firmware | ||
1378 | * | ||
1379 | * Retrieves one or more database records from the iPod, | ||
1380 | * typically based on the results from the Command 0x0018: | ||
1381 | * GetNumberCategorizedDBRecords query. The database | ||
1382 | * category types are described above. This telegram | ||
1383 | * specifies the starting record index and the number of | ||
1384 | * records to retrieve (the record count). This allows a device | ||
1385 | * to retrieve an individual record or the entire set of records | ||
1386 | * for a category. The record start index and record count consist | ||
1387 | * of 32-bit signed integers. To retrieve all records from a given | ||
1388 | * starting record index, set the record count to -1 (0xFFFFFFFF). | ||
1389 | * The iPod responds to this telegram with a separate Command | ||
1390 | * 0x001B: ReturnCategorizedDatabaseRecord telegram FOR EACH record | ||
1391 | * matching the specified criteria (category and record index | ||
1392 | * range). | ||
1393 | * | ||
1394 | * Byte Value Meaning | ||
1395 | * 0 0xFF Sync byte (required only for UART serial) | ||
1396 | * 1 0x55 Start of telegram | ||
1397 | * 2 0x0C Telegram payload length | ||
1398 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1399 | * 4 0x00 Command ID (bits 15:8) | ||
1400 | * 5 0x1A Command ID (bits 7:0) | ||
1401 | * 6 0xNN Database category type. See above | ||
1402 | * 7 0xNN Database record start index (bits 31:24) | ||
1403 | * 8 0xNN Database record start index (bits 23:16) | ||
1404 | * 9 0xNN Database record start index (bits 15:8) | ||
1405 | * 10 0xNN Database record start index (bits 7:0) | ||
1406 | * 11 0xNN Database record read count (bits 31:24) | ||
1407 | * 12 0xNN Database record read count (bits 23:16) | ||
1408 | * 13 0xNN Database record read count (bits 15:8) | ||
1409 | * 14 0xNN Database record read count (bits 7:0) | ||
1410 | * 15 0xNN Telegram payload checksum byte | ||
1411 | |||
1412 | * The returned data | ||
1413 | * contains information for a single database record. The iPod sends | ||
1414 | * one or more of these telegrams in response to the Command 0x001A: | ||
1415 | * RetrieveCategorizedDatabaseRecords telegram from the device. The | ||
1416 | * category record index is included to allow the device to | ||
1417 | * determine which record has been sent. The record data is sent as | ||
1418 | * a null-terminated UTF-8 encoded data array. | ||
1419 | */ | ||
1420 | { | ||
1421 | unsigned char data[7 + MAX_PATH] = | ||
1422 | {0x04, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, | ||
1423 | 'O','n','-','T','h','e','-','G','o','\0'}; | ||
1424 | struct playlist_track_info track; | ||
1425 | struct mp3entry id3; | ||
1426 | |||
1427 | unsigned long start_index = get_u32(&buf[4]); | ||
1428 | unsigned long read_count = get_u32(&buf[8]); | ||
1429 | unsigned long counter = 0; | ||
1430 | unsigned int number_of_playlists = nbr_total_playlists(); | ||
1431 | uint32_t trackcount; | ||
1432 | trackcount = playlist_amount(); | ||
1433 | size_t len; | ||
1434 | |||
1435 | if ((buf[3] == 0x05) && ((start_index + read_count ) > trackcount)) | ||
1436 | { | ||
1437 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1438 | break; | ||
1439 | } | ||
1440 | if ((buf[3] == 0x01) && ((start_index + read_count) > (number_of_playlists + 1))) | ||
1441 | { | ||
1442 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1443 | break; | ||
1444 | } | ||
1445 | for (counter=0;counter<read_count;counter++) | ||
1446 | { | ||
1447 | switch(buf[3]) /* type number */ | ||
1448 | { | ||
1449 | case 0x01: /* Playlists */ | ||
1450 | get_playlist_name(data +7,start_index+counter, MAX_PATH); | ||
1451 | /*Remove file extension*/ | ||
1452 | char *dot=NULL; | ||
1453 | dot = (strrchr(data+7, '.')); | ||
1454 | if (dot != NULL) | ||
1455 | *dot = '\0'; | ||
1456 | break; | ||
1457 | case 0x05: /* Tracks */ | ||
1458 | case 0x02: /* Artists */ | ||
1459 | case 0x03: /* Albums */ | ||
1460 | case 0x04: /* Genre */ | ||
1461 | case 0x06: /* Composer */ | ||
1462 | playlist_get_track_info(NULL, start_index + counter, | ||
1463 | &track); | ||
1464 | iap_get_trackinfo(start_index + counter, &id3); | ||
1465 | switch(buf[3]) | ||
1466 | { | ||
1467 | case 0x05: | ||
1468 | len = strlcpy((char *)&data[7], id3.title,64); | ||
1469 | break; | ||
1470 | case 0x02: | ||
1471 | len = strlcpy((char *)&data[7], id3.artist,64); | ||
1472 | break; | ||
1473 | case 0x03: | ||
1474 | len = strlcpy((char *)&data[7], id3.album,64); | ||
1475 | break; | ||
1476 | case 0x04: | ||
1477 | case 0x06: | ||
1478 | len = strlcpy((char *)&data[7], "Not Supported",14); | ||
1479 | break; | ||
1480 | } | ||
1481 | break; | ||
1482 | } | ||
1483 | put_u32(&data[3], start_index+counter); | ||
1484 | iap_send_pkt(data, 7 + strlen(data+7) + 1); | ||
1485 | yield(); | ||
1486 | } | ||
1487 | break; | ||
1488 | } | ||
1489 | case 0x001B: /* ReturnCategorizedDatabaseRecord. See Above */ | ||
1490 | /* The following is the description for the Apple Firmware | ||
1491 | * | ||
1492 | * Contains information for a single database record. The iPod sends | ||
1493 | * ONE OR MORE of these telegrams in response to the Command 0x001A: | ||
1494 | * RetrieveCategorizedDatabaseRecords telegram from the device. The | ||
1495 | * category record index is included to allow the device to | ||
1496 | * determine which record has been sent. The record data is sent | ||
1497 | * as a null-terminated UTF-8 encoded data array. | ||
1498 | * | ||
1499 | * Note: The database record string is not limited to 252 characters | ||
1500 | * it may be sent in small or large telegram format, depending on | ||
1501 | * the record size. The small telegram format is shown. | ||
1502 | * | ||
1503 | * Byte Value Meaning | ||
1504 | * 0 0xFF Sync byte (required only for UART serial) | ||
1505 | * 1 0x55 Start of telegram | ||
1506 | * 2 0xNN Telegram payload length | ||
1507 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1508 | * 4 0x00 Command ID (bits 15:8) | ||
1509 | * 5 0x1B Command ID (bits 7:0) | ||
1510 | * 6 0xNN Database record category index (bits 31:24) | ||
1511 | * 7 0xNN Database record category index (bits 23:16) | ||
1512 | * 8 0xNN Database record category index (bits 15:8) | ||
1513 | * 9 0xNN Database record category index (bits 7:0) | ||
1514 | * 10-N 0xNN Database record as a UTF-8 character array. | ||
1515 | * NN 0xNN Telegram payload checksum byte | ||
1516 | * | ||
1517 | */ | ||
1518 | { | ||
1519 | /* We should NEVER receive this command so ERROR if we do */ | ||
1520 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1521 | break; | ||
1522 | } | ||
1523 | case 0x001C: /* GetPlayStatus */ | ||
1524 | /* The following is the description for the Apple Firmware | ||
1525 | * | ||
1526 | * Requests the current iPod playback status, allowing the | ||
1527 | * device to display feedback to the user. In response, the | ||
1528 | * iPod sends a Command 0x001D: ReturnPlayStatus telegram | ||
1529 | * with the current playback status. | ||
1530 | * | ||
1531 | * Byte Value Meaning | ||
1532 | * 0 0xFF Sync byte (required only for UART serial) | ||
1533 | * 1 0x55 Start of telegram | ||
1534 | * 2 0x03 Telegram payload length | ||
1535 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1536 | * 4 0x00 Command ID (bits 15:8) | ||
1537 | * 5 0x1C Command ID (bits 7:0) | ||
1538 | * 6 0xDD Telegram payload checksum byte | ||
1539 | * | ||
1540 | */ | ||
1541 | { | ||
1542 | unsigned char data[] = {0x04, 0x00, 0x1D, | ||
1543 | 0x00, 0x00, 0x00, 0x00, | ||
1544 | 0x00, 0x00, 0x00, 0x00, | ||
1545 | 0x00}; | ||
1546 | struct mp3entry *id3 = audio_current_track(); | ||
1547 | unsigned long time_total = id3->length; | ||
1548 | unsigned long time_elapsed = id3->elapsed; | ||
1549 | int status = audio_status(); | ||
1550 | put_u32(&data[3], time_total); | ||
1551 | put_u32(&data[7], time_elapsed); | ||
1552 | if (status == AUDIO_STATUS_PLAY) | ||
1553 | data[11] = 0x01; /* play */ | ||
1554 | else if (status & AUDIO_STATUS_PAUSE) | ||
1555 | data[11] = 0x02; /* pause */ | ||
1556 | iap_send_pkt(data, sizeof(data)); | ||
1557 | break; | ||
1558 | } | ||
1559 | case 0x001D: /* ReturnPlayStatus. See Above */ | ||
1560 | /* The following is the description for the Apple Firmware | ||
1561 | * | ||
1562 | * Returns the current iPod playback status. The iPod sends this | ||
1563 | * telegram in response to the Command 0x001C: GetPlayStatus | ||
1564 | * telegram from the device. The information returned includes the | ||
1565 | * current track length, track position, and player state. | ||
1566 | * | ||
1567 | * Note: The track length and track position fields are valid only | ||
1568 | * if the player state is Playing or Paused. For other player | ||
1569 | * states, these fields should be ignored. | ||
1570 | * | ||
1571 | * Byte Value Meaning | ||
1572 | * 0 0xFF Sync byte (required only for UART serial) | ||
1573 | * 1 0x55 Start of telegram | ||
1574 | * 2 0x0C Telegram payload length | ||
1575 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1576 | * 4 0x00 Command ID (bits 15:8) | ||
1577 | * 5 0x1D Command ID (bits 7:0) | ||
1578 | * 6 0xNN Track length in milliseconds (bits 31:24) | ||
1579 | * 7 0xNN Track length in milliseconds (bits 23:16) | ||
1580 | * 8 0xNN Track length in milliseconds (bits 15:8) | ||
1581 | * 9 0xNN Track length in milliseconds (bits 7:0) | ||
1582 | * 10 0xNN Track position in milliseconds (bits 31:24) | ||
1583 | * 11 0xNN Track position in milliseconds (bits 23:16) | ||
1584 | * 12 0xNN Track position in milliseconds (bits 15:8) | ||
1585 | * 13 0xNN Track position in milliseconds (bits 7:0) | ||
1586 | * 14 0xNN Player state. Possible values are: | ||
1587 | * 0x00 = Stopped | ||
1588 | * 0x01 = Playing | ||
1589 | * 0x02 = Paused | ||
1590 | * 0x03 - 0xFE = Reserved | ||
1591 | * 0xFF = Error | ||
1592 | * 15 0xNN Telegram payload checksum byte | ||
1593 | * | ||
1594 | */ | ||
1595 | { | ||
1596 | /* We should NEVER receive this command so ERROR if we do */ | ||
1597 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1598 | break; | ||
1599 | } | ||
1600 | case 0x001E: /* GetCurrentPlayingTrackIndex */ | ||
1601 | /* The following is the description for the Apple Firmware | ||
1602 | * | ||
1603 | * Requests the playback engine index of the currently playing | ||
1604 | * track. In response, the iPod sends a Command 0x001F: | ||
1605 | * ReturnCurrentPlayingTrackIndex telegram to the device. | ||
1606 | * | ||
1607 | * Note: The track index returned is valid only if there is | ||
1608 | * currently a track playing or paused. | ||
1609 | * | ||
1610 | * Byte Value Meaning | ||
1611 | * 0 0xFF Sync byte (required only for UART serial) | ||
1612 | * 1 0x55 Start of telegram | ||
1613 | * 2 0x03 Telegram payload length | ||
1614 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1615 | * 4 0x00 Command ID (bits 15:8) | ||
1616 | * 5 0x1E Command ID (bits 7:0) | ||
1617 | * 6 0xDB Telegram payload checksum byte | ||
1618 | * | ||
1619 | */ | ||
1620 | { | ||
1621 | unsigned char data[] = {0x04, 0x00, 0x1F, | ||
1622 | 0xFF, 0xFF, 0xFF, 0xFF}; | ||
1623 | long playlist_pos = playlist_next(0); | ||
1624 | int status = audio_status(); | ||
1625 | playlist_pos -= playlist_get_first_index(NULL); | ||
1626 | if(playlist_pos < 0) | ||
1627 | playlist_pos += playlist_amount(); | ||
1628 | if ((status == AUDIO_STATUS_PLAY) || (status & AUDIO_STATUS_PAUSE)) | ||
1629 | put_u32(&data[3], playlist_pos); | ||
1630 | iap_send_pkt(data, sizeof(data)); | ||
1631 | break; | ||
1632 | } | ||
1633 | case 0x001F: /* ReturnCurrentPlayingTrackIndex. See Above */ | ||
1634 | /* The following is the description for the Apple Firmware | ||
1635 | * | ||
1636 | * Returns the playback engine index of the current playing track in | ||
1637 | * response to the Command 0x001E: GetCurrentPlayingTrackIndex | ||
1638 | * telegram from the device. The track index is a 32-bit signed | ||
1639 | * integer. | ||
1640 | * If there is no track currently playing or paused, an index of -1 | ||
1641 | * (0xFFFFFFFF) is returned. | ||
1642 | * | ||
1643 | * Byte Value Meaning | ||
1644 | * 0 0xFF Sync byte (required only for UART serial) | ||
1645 | * 1 0x55 Start of telegram | ||
1646 | * 2 0x07 Telegram payload length | ||
1647 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1648 | * 4 0x00 Command ID (bits 15:8) | ||
1649 | * 5 0x1F Command ID (bits 7:0) | ||
1650 | * 6 0xNN Playback track index (bits 31:24) | ||
1651 | * 7 0xNN Playback track index (bits 23:16) | ||
1652 | * 8 0xNN Playback track index (bits 15:8) | ||
1653 | * 9 0xNN Playback track index (bits 7:0) | ||
1654 | * 10 0xNN Telegram payload checksum byte | ||
1655 | * | ||
1656 | */ | ||
1657 | { | ||
1658 | /* We should NEVER receive this command so ERROR if we do */ | ||
1659 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1660 | break; | ||
1661 | } | ||
1662 | case 0x0020: /* GetIndexedPlayingTrackTitle. See 0x0024 below */ | ||
1663 | /* The following is the description for the Apple Firmware | ||
1664 | * | ||
1665 | * Requests the title name of the indexed playing track from the | ||
1666 | * iPod. In response to a valid telegram, the iPod sends a | ||
1667 | * Command 0x0021: ReturnIndexedPlayingTrackTitle telegram to the | ||
1668 | * device. | ||
1669 | * | ||
1670 | * Note: If the telegram length or playing track index is invalid, | ||
1671 | * the iPod responds with an ACK telegram including the specific | ||
1672 | * error status. | ||
1673 | * | ||
1674 | * Byte Value Meaning | ||
1675 | * 0 0xFF Sync byte (required only for UART serial) | ||
1676 | * 1 0x55 Start of telegram | ||
1677 | * 2 0x07 Telegram payload length | ||
1678 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1679 | * 4 0x00 Command ID (bits 15:8) | ||
1680 | * 5 0x20 Command ID (bits 7:0) | ||
1681 | * 6 0xNN Playback track index (bits 31:24) | ||
1682 | * 7 0xNN Playback track index (bits 23:16) | ||
1683 | * 8 0xNN Playback track index (bits 15:8) | ||
1684 | * 9 0xNN Playback track index (bits 7:0) | ||
1685 | * 10 0xNN Telegram payload checksum byte | ||
1686 | * | ||
1687 | */ | ||
1688 | case 0x0021: /* ReturnIndexedPlayingTrackTitle. See 0x0024 Below */ | ||
1689 | /* The following is the description for the Apple Firmware | ||
1690 | * | ||
1691 | * Returns the title of the indexed playing track in response to | ||
1692 | * a valid Command 0x0020 GetIndexedPlayingTrackTitle telegram from | ||
1693 | * the device. The track title is encoded as a null-terminated UTF-8 | ||
1694 | * character array. | ||
1695 | * | ||
1696 | * Note: The track title string is not limited to 252 characters; | ||
1697 | * it may be sent in small or large telegram format, depending on | ||
1698 | * the string length. The small telegram format is shown. | ||
1699 | * | ||
1700 | * Byte Value Meaning | ||
1701 | * 0 0xFF Sync byte (required only for UART serial) | ||
1702 | * 1 0x55 Start of telegram | ||
1703 | * 2 0xNN Telegram payload length | ||
1704 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1705 | * 4 0x00 Command ID (bits 15:8) | ||
1706 | * 5 0x21 Command ID (bits 7:0) | ||
1707 | * 6-N 0xNN Track title as a UTF-8 character array | ||
1708 | * NN 0xNN Telegram payload checksum byte | ||
1709 | * | ||
1710 | */ | ||
1711 | case 0x0022: /* GetIndexedPlayingTrackArtistName. See 0x0024 Below */ | ||
1712 | /* The following is the description for the Apple Firmware | ||
1713 | * | ||
1714 | * Requests the name of the artist of the indexed playing track | ||
1715 | * In response to a valid telegram, the iPod sends a | ||
1716 | * Command 0x0023: ReturnIndexedPlayingTrackArtistName telegram to | ||
1717 | * the device. | ||
1718 | * | ||
1719 | * Note: If the telegram length or playing track index is invalid, | ||
1720 | * the iPod responds with an ACK telegram including the specific | ||
1721 | * error status. | ||
1722 | * | ||
1723 | * Byte Value Meaning | ||
1724 | * 0 0xFF Sync byte (required only for UART serial) | ||
1725 | * 1 0x55 Start of telegram | ||
1726 | * 2 0x07 Telegram payload length | ||
1727 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1728 | * 4 0x00 Command ID (bits 15:8) | ||
1729 | * 5 0x22 Command ID (bits 7:0) | ||
1730 | * 6 0xNN Playback track index (bits 31:24) | ||
1731 | * 7 0xNN Playback track index (bits 23:16) | ||
1732 | * 8 0xNN Playback track index (bits 15:8) | ||
1733 | * 9 0xNN Playback track index (bits 7:0) | ||
1734 | * 10 0xNN Telegram payload checksum byte | ||
1735 | * | ||
1736 | */ | ||
1737 | case 0x0023: /* ReturnIndexedPlayingTrackArtistName. See 0x0024 Below */ | ||
1738 | /* The following is the description for the Apple Firmware | ||
1739 | * | ||
1740 | * Returns the artist name of the indexed playing track in response | ||
1741 | * to a valid Command 0x0022 GetIndexedPlayingTrackArtistName | ||
1742 | * telegram from the device. The track artist name is encoded as a | ||
1743 | * null-terminated UTF-8 character array. | ||
1744 | * | ||
1745 | * Note: The artist name string is not limited to 252 characters; | ||
1746 | * it may be sent in small or large telegram format, depending on | ||
1747 | * the string length. The small telegram format is shown. | ||
1748 | * | ||
1749 | * Byte Value Meaning | ||
1750 | * 0 0xFF Sync byte (required only for UART serial) | ||
1751 | * 1 0x55 Start of telegram | ||
1752 | * 2 0xNN Telegram payload length | ||
1753 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1754 | * 4 0x00 Command ID (bits 15:8) | ||
1755 | * 5 0x23 Command ID (bits 7:0) | ||
1756 | * 6-N 0xNN Track Artist as a UTF-8 character array | ||
1757 | * NN 0xNN Telegram payload checksum byte | ||
1758 | * | ||
1759 | */ | ||
1760 | case 0x0024: /* GetIndexedPlayingTrackAlbumName AND | ||
1761 | * GetIndexedPlayingTrackTitle AND | ||
1762 | * AND GetIndexedPlayingTrackArtistName. */ | ||
1763 | /* The following is the description for the Apple Firmware | ||
1764 | * | ||
1765 | * Requests the album name of the indexed playing track | ||
1766 | * In response to a valid telegram, the iPod sends a | ||
1767 | * Command 0x0025: ReturnIndexedPlayingTrackAlbumName telegram to | ||
1768 | * the device. | ||
1769 | * | ||
1770 | * Note: If the telegram length or playing track index is invalid, | ||
1771 | * the iPod responds with an ACK telegram including the specific | ||
1772 | * error status. | ||
1773 | * | ||
1774 | * Byte Value Meaning | ||
1775 | * 0 0xFF Sync byte (required only for UART serial) | ||
1776 | * 1 0x55 Start of telegram | ||
1777 | * 2 0x07 Telegram payload length | ||
1778 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1779 | * 4 0x00 Command ID (bits 15:8) | ||
1780 | * 5 0x24 Command ID (bits 7:0) | ||
1781 | * 6 0xNN Playback track index (bits 31:24) | ||
1782 | * 7 0xNN Playback track index (bits 23:16) | ||
1783 | * 8 0xNN Playback track index (bits 15:8) | ||
1784 | * 9 0xNN Playback track index (bits 7:0) | ||
1785 | * 10 0xNN Telegram payload checksum byte | ||
1786 | * | ||
1787 | */ | ||
1788 | { | ||
1789 | unsigned char data[70] = {0x04, 0x00, 0xFF}; | ||
1790 | struct mp3entry id3; | ||
1791 | int fd; | ||
1792 | size_t len; | ||
1793 | long tracknum = get_u32(&buf[3]); | ||
1794 | |||
1795 | data[2] = cmd + 1; | ||
1796 | memcpy(&id3, audio_current_track(), sizeof(id3)); | ||
1797 | tracknum += playlist_get_first_index(NULL); | ||
1798 | if(tracknum >= playlist_amount()) | ||
1799 | tracknum -= playlist_amount(); | ||
1800 | /* If the tracknumber is not the current one, | ||
1801 | read id3 from disk */ | ||
1802 | if(playlist_next(0) != tracknum) | ||
1803 | { | ||
1804 | struct playlist_track_info info; | ||
1805 | playlist_get_track_info(NULL, tracknum, &info); | ||
1806 | fd = open(info.filename, O_RDONLY); | ||
1807 | memset(&id3, 0, sizeof(struct mp3entry)); | ||
1808 | get_metadata(&id3, fd, info.filename); | ||
1809 | close(fd); | ||
1810 | } | ||
1811 | /* Return the requested track data */ | ||
1812 | switch(cmd) | ||
1813 | { | ||
1814 | case 0x20: | ||
1815 | len = strlcpy((char *)&data[3], id3.title, 64); | ||
1816 | iap_send_pkt(data, 4+len); | ||
1817 | break; | ||
1818 | case 0x22: | ||
1819 | len = strlcpy((char *)&data[3], id3.artist, 64); | ||
1820 | iap_send_pkt(data, 4+len); | ||
1821 | break; | ||
1822 | case 0x24: | ||
1823 | len = strlcpy((char *)&data[3], id3.album, 64); | ||
1824 | iap_send_pkt(data, 4+len); | ||
1825 | break; | ||
1826 | } | ||
1827 | break; | ||
1828 | } | ||
1829 | case 0x0025: /* ReturnIndexedPlayingTrackAlbumName. See 0x0024 Above */ | ||
1830 | /* The following is the description for the Apple Firmware | ||
1831 | * | ||
1832 | * Returns the album name of the indexed playing track in response | ||
1833 | * to a valid Command 0x0024 GetIndexedPlayingTrackAlbumName | ||
1834 | * telegram from the device. The track artist name is encoded as a | ||
1835 | * null-terminated UTF-8 character array. | ||
1836 | * | ||
1837 | * Note: The album name string is not limited to 252 characters; | ||
1838 | * it may be sent in small or large telegram format, depending on | ||
1839 | * the string length. The small telegram format is shown. | ||
1840 | * | ||
1841 | * Byte Value Meaning | ||
1842 | * 0 0xFF Sync byte (required only for UART serial) | ||
1843 | * 1 0x55 Start of telegram | ||
1844 | * 2 0xNN Telegram payload length | ||
1845 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1846 | * 4 0x00 Command ID (bits 15:8) | ||
1847 | * 5 0x25 Command ID (bits 7:0) | ||
1848 | * 6-N 0xNN Track Album as a UTF-8 character array | ||
1849 | * NN 0xNN Telegram payload checksum byte | ||
1850 | * | ||
1851 | */ | ||
1852 | { | ||
1853 | /* We should NEVER receive this command so ERROR if we do */ | ||
1854 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
1855 | break; | ||
1856 | } | ||
1857 | case 0x0026: /* SetPlayStatusChangeNotification */ | ||
1858 | /* The following is the description for the Apple Firmware | ||
1859 | * Sets the state of play status change notifications from the iPod | ||
1860 | * to the device. Notification of play status changes can be | ||
1861 | * globally enabled or disabled. If notifications are enabled, the | ||
1862 | * iPod sends a Command 0x0027: PlayStatusChangeNotification | ||
1863 | * telegram to the device each time the play status changes, until | ||
1864 | * the device sends this telegram again with the disable | ||
1865 | * notification option. In response, the iPod sends an ACK telegram | ||
1866 | * indicating the status of the SetPlayStatusChangeNotification | ||
1867 | * command. | ||
1868 | * | ||
1869 | * Byte Value Meaning | ||
1870 | * 0 0xFF Sync byte (required only for UART serial) | ||
1871 | * 1 0x55 Start of telegram | ||
1872 | * 2 0x04 Telegram payload length | ||
1873 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1874 | * 4 0x00 Command ID (bits 15:8) | ||
1875 | * 5 0x26 Command ID (bits 7:0) | ||
1876 | * 6 0xNN The state of play status change notifications. | ||
1877 | * Possible values are: | ||
1878 | * 0x00 = Disable all change notification | ||
1879 | * 0x01 = Enable all change notification | ||
1880 | * 0x02 - 0xFF = Reserved | ||
1881 | * 7 0xNN Telegram payload checksum byte | ||
1882 | */ | ||
1883 | { | ||
1884 | device.do_notify = buf[3] ? true : false; | ||
1885 | /* respond with cmd ok packet */ | ||
1886 | cmd_ok(cmd); | ||
1887 | break; | ||
1888 | } | ||
1889 | case 0x0027: /* PlayStatusChangeNotification */ | ||
1890 | /* This response is handled by iap_track_changed() and iap_periodic() | ||
1891 | * within iap-core.c | ||
1892 | * The following is the description for the Apple Firmware | ||
1893 | * | ||
1894 | * The iPod sends this telegram to the device when the iPod play status | ||
1895 | * changes, if the device has previously enabled notifications using | ||
1896 | * Command 0x0026: SetPlayStatusChangeNotification . This telegram | ||
1897 | * contains details about the new play status. Notification telegrams | ||
1898 | * for changes in track position occur approximately every 500 | ||
1899 | * milliseconds while the iPod is playing. Notification telegrams are | ||
1900 | * sent from the iPod until the device sends the | ||
1901 | * SetPlayStatusChangeNotification telegram with the option to disable | ||
1902 | * all notifications. | ||
1903 | * Some notifications include additional data about the new play status. | ||
1904 | * | ||
1905 | * PlayStatusChangeNotification telegram: notifications 0x00, 0x02, 0x03 | ||
1906 | * Byte Value Meaning | ||
1907 | * 0 0xFF Sync byte (required only for UART serial) | ||
1908 | * 1 0x55 Start of telegram | ||
1909 | * 2 0x04 Telegram payload length | ||
1910 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1911 | * 4 0x00 Command ID (bits 15:8) | ||
1912 | * 5 0x27 Command ID (bits 7:0) | ||
1913 | * 6 0xNN New play status. See Below. | ||
1914 | * 7 0xNN Telegram payload checksum byte | ||
1915 | * | ||
1916 | * Play Status Change Code Extended Status Data (if | ||
1917 | * any) | ||
1918 | * Playback stopped 0x00 None | ||
1919 | * Playback track changed 0x01 New track record index | ||
1920 | * (32 bits) | ||
1921 | * Playback forward seek stop 0x02 None | ||
1922 | * Playback backward seek stop 0x03 None | ||
1923 | * Playback track position 0x04 New track position in | ||
1924 | * milliseconds (32 bits) | ||
1925 | * Playback chapter changed 0x05 New chapter index (32 | ||
1926 | * bits) | ||
1927 | * Reserved 0x06 - 0xFF N/A | ||
1928 | * | ||
1929 | * Playback track changed (code 0x01) | ||
1930 | * Byte Value Meaning | ||
1931 | * 0 0xFF Sync byte (required only for UART serial) | ||
1932 | * 1 0x55 Start of telegram | ||
1933 | * 2 0x08 Telegram payload length | ||
1934 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1935 | * 4 0x00 Command ID (bits 15:8) | ||
1936 | * 5 0x27 Command ID (bits 7:0) | ||
1937 | * 6 0x01 New status: Playback track changed | ||
1938 | * 7 0xNN New playback track index (bits 31:24) | ||
1939 | * 8 0xNN New playback track index (bits 23:16) | ||
1940 | * 9 0xNN New playback track index (bits 15:8) | ||
1941 | * 10 0xNN New playback track index (bits 7:0) | ||
1942 | * 11 0xNN Telegram payload checksum byte | ||
1943 | * | ||
1944 | * Playback track position changed (code 0x04) | ||
1945 | * Byte Value Meaning | ||
1946 | * 0 0xFF Sync byte (required only for UART serial) | ||
1947 | * 1 0x55 Start of telegram | ||
1948 | * 2 0x08 Telegram payload length | ||
1949 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1950 | * 4 0x00 Command ID (bits 15:8) | ||
1951 | * 5 0x27 Command ID (bits 7:0) | ||
1952 | * 6 0x04 New status: Playback track position changed | ||
1953 | * 7 0xNN New track position in milliseconds (bits 31:24) | ||
1954 | * 8 0xNN New track position in milliseconds (bits 23:16) | ||
1955 | * 9 0xNN New track position in milliseconds (bits 15:8) | ||
1956 | * 10 0xNN New track position in milliseconds (bits 7:0) | ||
1957 | * 11 0xNN Telegram payload checksum byte | ||
1958 | * | ||
1959 | * Playback chapter changed (code 0x05) | ||
1960 | * Byte Value Meaning | ||
1961 | * 0 0xFF Sync byte (required only for UART serial) | ||
1962 | * 1 0x55 Start of telegram | ||
1963 | * 2 0x08 Telegram payload length | ||
1964 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1965 | * 4 0x00 Command ID (bits 15:8) | ||
1966 | * 5 0x27 Command ID (bits 7:0) | ||
1967 | * 6 0x05 New status: Playback chapter changed | ||
1968 | * 7 0xNN New track chapter index (bits 31:24) | ||
1969 | * 8 0xNN New track chapter index (bits 23:16) | ||
1970 | * 9 0xNN New track chapter index (bits 15:8) | ||
1971 | * 10 0xNN New track chapter index (bits 7:0) | ||
1972 | * 11 0xNN Telegram payload checksum byte | ||
1973 | * | ||
1974 | */ | ||
1975 | case 0x0028: /* PlayCurrentSelection */ | ||
1976 | /* The following is the description for the Apple Firmware | ||
1977 | * | ||
1978 | * Requests playback of the currently selected track or list of | ||
1979 | * tracks. The currently selected tracks are placed in the Now | ||
1980 | * Playing playlist, where they are optionally shuffled (if the | ||
1981 | * shuffle feature is enabled). Finally, the specified track record | ||
1982 | * index is passed to the player to play. Note that if the track | ||
1983 | * index is -1(0xFFFFFFFF), the first track after the shuffle is | ||
1984 | * complete is played first. If a track index of n is sent, the nth | ||
1985 | * track of the selected tracks is played first, regardless of | ||
1986 | * where it is located in the Now Playing playlist after the shuffle | ||
1987 | * is performed (assuming that shuffle is on). In response, the iPod | ||
1988 | * sends an ACK telegram indicating the status of the command. | ||
1989 | * | ||
1990 | * Byte Value Meaning | ||
1991 | * 0 0xFF Sync byte (required only for UART serial) | ||
1992 | * 1 0x55 Start of telegram | ||
1993 | * 2 0x07 Telegram payload length | ||
1994 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
1995 | * 4 0x00 Command ID (bits 15:8) | ||
1996 | * 5 0x28 Command ID (bits 7:0) | ||
1997 | * 6 0xNN Selection track record index (bits 31:24) | ||
1998 | * 7 0xNN Selection track record index (bits 23:16) | ||
1999 | * 8 0xNN Selection track record index (bits 15:8) | ||
2000 | * 9 0xNN Selection track record index (bits 7:0) | ||
2001 | * 10 0xNN Telegram payload checksum byte | ||
2002 | * | ||
2003 | */ | ||
2004 | { | ||
2005 | int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE)); | ||
2006 | uint32_t index; | ||
2007 | uint32_t trackcount; | ||
2008 | index = get_u32(&buf[3]); | ||
2009 | trackcount = playlist_amount(); | ||
2010 | if (index >= trackcount) | ||
2011 | { | ||
2012 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2013 | break; | ||
2014 | } | ||
2015 | audio_pause(); | ||
2016 | if(global_settings.playlist_shuffle) | ||
2017 | { | ||
2018 | playlist_randomise(NULL, current_tick, true); | ||
2019 | } | ||
2020 | else | ||
2021 | { | ||
2022 | playlist_sort(NULL, true); | ||
2023 | } | ||
2024 | audio_skip(index - playlist_next(0)); | ||
2025 | if (!paused) | ||
2026 | audio_resume(); | ||
2027 | /* respond with cmd ok packet */ | ||
2028 | cmd_ok(cmd); | ||
2029 | break; | ||
2030 | } | ||
2031 | case 0x0029: /* PlayControl */ | ||
2032 | { | ||
2033 | /* The following is the description for the Apple Firmware | ||
2034 | * | ||
2035 | * Sets the new play state of the iPod. The play control command | ||
2036 | * codes are shown below. In response, the iPod sends an ACK | ||
2037 | * telegram indicating the status of the command. | ||
2038 | * | ||
2039 | * Note: If a remote device requests the Next or Previous Chapter | ||
2040 | * for a track that does not contain chapters, the iPod returns a | ||
2041 | * command failed ACK. | ||
2042 | * | ||
2043 | * Byte Value Meaning | ||
2044 | * 0 0xFF Sync byte (required only for UART serial) | ||
2045 | * 1 0x55 Start of telegram | ||
2046 | * 2 0x04 Telegram payload length | ||
2047 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2048 | * 4 0x00 Command ID (bits 15:8) | ||
2049 | * 5 0x29 Command ID (bits 7:0) | ||
2050 | * 6 0xNN Play control command code. | ||
2051 | * 7 0xNN Telegram payload checksum byte | ||
2052 | * | ||
2053 | * Play Control Command Code Protocol version | ||
2054 | * Reserved 0x00 N/A | ||
2055 | * Toggle Play/Pause 0x01 1.00 | ||
2056 | * Stop 0x02 1.00 | ||
2057 | * Next Track 0x03 1.00 | ||
2058 | * Previous Track 0x04 1.00 | ||
2059 | * StartFF 0x05 1.00 | ||
2060 | * StartRew 0x06 1.00 | ||
2061 | * EndFFRew 0x07 1.00 | ||
2062 | * NextChapter 0x08 1.06 | ||
2063 | * Previous Chapter 0x09 1.06 | ||
2064 | * Reserved 0x0A - 0xFF | ||
2065 | * | ||
2066 | */ | ||
2067 | switch(buf[3]) | ||
2068 | { | ||
2069 | case 0x01: /* play/pause */ | ||
2070 | iap_remotebtn = BUTTON_RC_PLAY; | ||
2071 | iap_repeatbtn = 2; | ||
2072 | break; | ||
2073 | case 0x02: /* stop */ | ||
2074 | iap_remotebtn = BUTTON_RC_PLAY|BUTTON_REPEAT; | ||
2075 | iap_repeatbtn = 2; | ||
2076 | break; | ||
2077 | case 0x03: /* skip++ */ | ||
2078 | iap_remotebtn = BUTTON_RC_RIGHT; | ||
2079 | iap_repeatbtn = 2; | ||
2080 | break; | ||
2081 | case 0x04: /* skip-- */ | ||
2082 | iap_remotebtn = BUTTON_RC_LEFT; | ||
2083 | iap_repeatbtn = 2; | ||
2084 | break; | ||
2085 | case 0x05: /* ffwd */ | ||
2086 | iap_remotebtn = BUTTON_RC_RIGHT; | ||
2087 | break; | ||
2088 | case 0x06: /* frwd */ | ||
2089 | iap_remotebtn = BUTTON_RC_LEFT; | ||
2090 | break; | ||
2091 | case 0x07: /* end ffwd/frwd */ | ||
2092 | iap_remotebtn = BUTTON_NONE; | ||
2093 | break; | ||
2094 | } | ||
2095 | /* respond with cmd ok packet */ | ||
2096 | cmd_ok(cmd); | ||
2097 | break; | ||
2098 | } | ||
2099 | case 0x002A: /* GetTrackArtworkTimes */ | ||
2100 | /* The following is the description for the Apple Firmware | ||
2101 | * | ||
2102 | * The device sends this command to the iPod to request the list of | ||
2103 | * artwork time locations for a track. A 4-byte track Index | ||
2104 | * specifies which track from the Playback Engine is to be selected. | ||
2105 | * A 2-byte formatID indicates which type of artwork is desired. | ||
2106 | * The 2-byte artworkIndex specifies at which index to begin | ||
2107 | * searching for artwork. A value of 0 indicates that the iPod | ||
2108 | * should start with the first available artwork. | ||
2109 | * The 2-byte artworkCount specifies the maximum number of times | ||
2110 | * (artwork locations) to be returned. A value of -1 (0xFFFF) | ||
2111 | * indicates that there is no preferred limit. Note that podcasts | ||
2112 | * may have a large number of associated images. | ||
2113 | * | ||
2114 | * Byte Value Comment | ||
2115 | * 0 0xFF Sync byte (required only for UART serial) | ||
2116 | * 1 0x55 Start of telegram | ||
2117 | * 2 0x0D Length of packet | ||
2118 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2119 | * 4 0x00 Command ID (bits 15:8) | ||
2120 | * 5 0x2A Command ID (bits 7:0) | ||
2121 | * 6 0xNN trackIndex(31:24) | ||
2122 | * 7 0xNN trackIndex(23:16) | ||
2123 | * 8 0xNN trackIndex (15:8) | ||
2124 | * 9 0xNN trackIndex (7:0) | ||
2125 | * 10 0xNN formatID (15:8) | ||
2126 | * 11 0xNN formatID (7:0) | ||
2127 | * 12 0xNN artworkIndex (15:8) | ||
2128 | * 13 0xNN artworkIndex (7:0) | ||
2129 | * 14 0xNN artworkCount (15:8) | ||
2130 | * 15 0xNN artworkCount (7:0) | ||
2131 | * 16 0xNN Checksum | ||
2132 | * | ||
2133 | */ | ||
2134 | { | ||
2135 | unsigned char data[] = {0x04, 0x00, 0x2B, | ||
2136 | 0x00, 0x00, 0x00, 0x00}; | ||
2137 | iap_send_pkt(data, sizeof(data)); | ||
2138 | break; | ||
2139 | } | ||
2140 | case 0x002B: /* ReturnTrackArtworkTimes. See Above */ | ||
2141 | /* The following is the description for the Apple Firmware | ||
2142 | * | ||
2143 | * The iPod sends this command to the device to return the list of | ||
2144 | * artwork times for a given track. The iPod returns zero or more | ||
2145 | * 4-byte times, one for each piece of artwork associated with the | ||
2146 | * track and format specified by GetTrackArtworkTimes. | ||
2147 | * The number of records returned will be no greater than the number | ||
2148 | * specified in the GetTrackArtworkTimes command. It may however, be | ||
2149 | * less than requested. This can happen if there are fewer pieces of | ||
2150 | * artwork available than were requested, or if the iPod is unable | ||
2151 | * to place the full number in a single packet. Check the number of | ||
2152 | * records returned against the results of | ||
2153 | * RetIndexedPlayingTrackInfo with infoType 7 to ensure that all | ||
2154 | * artwork has been received. | ||
2155 | * | ||
2156 | * Byte Value Comment | ||
2157 | * 0 0xFF Sync byte (required only for UART serial) | ||
2158 | * 1 0x55 Start of telegram | ||
2159 | * 2 0xNN Length of packet | ||
2160 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2161 | * 4 0x00 Command ID (bits 15:8) | ||
2162 | * 5 0x2B Command ID (bits 7:0) | ||
2163 | * 6 0xNN time offset from track start in ms (31:24) | ||
2164 | * 7 0xNN time offset from track start in ms (23:16) | ||
2165 | * 8 0xNN time offset from track start in ms (15:8) | ||
2166 | * 9 0xNN time offset from track start in ms (7:0) | ||
2167 | * Preceding 4 bytes may be repeated NN times | ||
2168 | * NN 0xNN Checksum | ||
2169 | * | ||
2170 | */ | ||
2171 | { | ||
2172 | /* We should NEVER receive this command so ERROR if we do */ | ||
2173 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2174 | break; | ||
2175 | } | ||
2176 | case 0x002C: /* GetShuffle */ | ||
2177 | { | ||
2178 | /* The following is the description for the Apple Firmware | ||
2179 | * | ||
2180 | * Requests the current state of the iPod shuffle setting. The iPod | ||
2181 | * responds with the Command0x002D: ReturnShuffle telegram. | ||
2182 | * | ||
2183 | * Byte Value Meaning | ||
2184 | * 0 0xFF Sync byte (required only for UART serial) | ||
2185 | * 1 0x55 Start of telegram | ||
2186 | * 2 0x03 Telegram payload length | ||
2187 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2188 | * 4 0x00 Command ID (bits 15:8) | ||
2189 | * 5 0x2C Command ID (bits 7:0) | ||
2190 | * 6 0xCD Telegram payload checksum byte | ||
2191 | * | ||
2192 | */ | ||
2193 | unsigned char data[] = {0x04, 0x00, 0x2D, | ||
2194 | 0x00}; | ||
2195 | data[3] = global_settings.playlist_shuffle ? 1 : 0; | ||
2196 | iap_send_pkt(data, sizeof(data)); | ||
2197 | break; | ||
2198 | } | ||
2199 | case 0x002D: /* ReturnShuffle. See Above */ | ||
2200 | /* The following is the description for the Apple Firmware | ||
2201 | * | ||
2202 | * Returns the current state of the shuffle setting. The iPod sends | ||
2203 | * this telegram in response to the Command 0x002C: GetShuffle | ||
2204 | * telegram from the device. | ||
2205 | * | ||
2206 | * Byte Value Meaning | ||
2207 | * 0 0xFF Sync byte (required only for UART serial) | ||
2208 | * 1 0x55 Start of telegram | ||
2209 | * 2 0x04 Telegram payload length | ||
2210 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2211 | * 4 0x00 Command ID (bits 15:8) | ||
2212 | * 5 0x2D Command ID (bits 7:0) | ||
2213 | * 6 0xNN Shuffle mode. See Below. | ||
2214 | * 7 0xNN Telegram payload checksum byte | ||
2215 | * | ||
2216 | * Possible values of the shufflemode. | ||
2217 | * Value Meaning | ||
2218 | * 0x00 Shuffle off | ||
2219 | * 0x01 Shuffle tracks | ||
2220 | * 0x02 Shuffle albums | ||
2221 | * 0x03 – 0xFF Reserved | ||
2222 | * | ||
2223 | */ | ||
2224 | { | ||
2225 | /* We should NEVER receive this command so ERROR if we do */ | ||
2226 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2227 | break; | ||
2228 | } | ||
2229 | case 0x002E: /* SetShuffle */ | ||
2230 | { | ||
2231 | /* The following is the description for the Apple Firmware | ||
2232 | * | ||
2233 | * Sets the iPod shuffle mode. The iPod shuffle modes are listed | ||
2234 | * below. In response, the iPod sends an ACK telegram with the | ||
2235 | * command status. | ||
2236 | * This telegram has an optional byte, byte 0x07, called the | ||
2237 | * RestoreonExit byte. This byte can be used to restore the | ||
2238 | * original shuffle setting in use when the accessory was attached | ||
2239 | * to the iPod. A non zero value restores the original shuffle | ||
2240 | * setting of the iPod when the accessory is detached. If this byte | ||
2241 | * is zero, the shuffle setting set by the accessory overwrites the | ||
2242 | * original setting and persists after the accessory is detached | ||
2243 | * from the iPod. | ||
2244 | * Accessory engineers should note that the shuffle mode affects | ||
2245 | * items only in the playback engine. The shuffle setting does not | ||
2246 | * affect the order of tracks in the database engine, so calling | ||
2247 | * Command 0x001A: RetrieveCategorizedDatabaseRecords on a database | ||
2248 | * selection with the shuffle mode set returns a list of unshuffled | ||
2249 | * tracks. To get the shuffled playlist, an accessory must query the | ||
2250 | * playback engine by calling Command 0x0020 | ||
2251 | * GetIndexedPlayingTrackTitle. | ||
2252 | * Shuffling tracks does not affect the track index, just the track | ||
2253 | * at that index. If an unshuffled track at playback index 1 is | ||
2254 | * shuffled, a new track is placed into index 1. The playback | ||
2255 | * indexes themselves are not shuffled. | ||
2256 | * When shuffle mode is enabled, tracks that are marked 'skip when | ||
2257 | * shuffling' are filtered from the database selection. This affects | ||
2258 | * all audiobooks and all tracks that the user has marked in iTunes. | ||
2259 | * It also affects all podcasts unless their default 'skip when | ||
2260 | * shuffling' markings have been deliberately removed. To apply the | ||
2261 | * filter to the playback engine, the accessory should send | ||
2262 | * Command 0x0017: SelectDBRecord or | ||
2263 | * Command 0x0028: PlayCurrentSelection after enabling shuffle mode. | ||
2264 | * | ||
2265 | * Note: Accessory developers are encouraged to always use the | ||
2266 | * Restore on Exit byte with a nonzero value to restore any settings | ||
2267 | * modified by the accessory upon detach. | ||
2268 | * | ||
2269 | * SetShuffle telegram with Restore on Exit byte | ||
2270 | * Byte Value Meaning | ||
2271 | * 0 0xFF Sync byte (required only for UART serial) | ||
2272 | * 1 0x55 Start of telegram | ||
2273 | * 2 0x05 Telegram payload length | ||
2274 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2275 | * 4 0x00 Command ID (bits 15:8) | ||
2276 | * 5 0x2E Command ID (bits 7:0) | ||
2277 | * 6 0xNN New shuffle mode. See above . | ||
2278 | * 7 0xNN Restore on Exit byte. If 1, the orig setting is | ||
2279 | * restored on detach; if 0, the newsetting persists | ||
2280 | * after accessory detach. | ||
2281 | * 8 0xNN Telegram payload checksum byte | ||
2282 | * | ||
2283 | * SetShuffle setting persistent after the accessory detach. | ||
2284 | * Byte Value Meaning | ||
2285 | * 0 0xFF Sync byte (required only for UART serial) | ||
2286 | * 1 0x55 Start of telegram | ||
2287 | * 2 0x04 Telegram payload length | ||
2288 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2289 | * 4 0x00 Command ID (bits 15:8) | ||
2290 | * 5 0x2E Command ID (bits 7:0) | ||
2291 | * 6 0xNN New shuffle mode. See above. | ||
2292 | * 7 0xNN Telegram payload checksum byte | ||
2293 | * | ||
2294 | */ | ||
2295 | if(buf[3] && !global_settings.playlist_shuffle) | ||
2296 | { | ||
2297 | global_settings.playlist_shuffle = 1; | ||
2298 | settings_save(); | ||
2299 | if (audio_status() & AUDIO_STATUS_PLAY) | ||
2300 | playlist_randomise(NULL, current_tick, true); | ||
2301 | } | ||
2302 | else if(!buf[3] && global_settings.playlist_shuffle) | ||
2303 | { | ||
2304 | global_settings.playlist_shuffle = 0; | ||
2305 | settings_save(); | ||
2306 | if (audio_status() & AUDIO_STATUS_PLAY) | ||
2307 | playlist_sort(NULL, true); | ||
2308 | } | ||
2309 | |||
2310 | /* respond with cmd ok packet */ | ||
2311 | cmd_ok(cmd); | ||
2312 | break; | ||
2313 | } | ||
2314 | case 0x002F: /* GetRepeat */ | ||
2315 | { | ||
2316 | /* The following is the description for the Apple Firmware | ||
2317 | * | ||
2318 | * Requests the track repeat state of the iPod. In response, the | ||
2319 | * iPod sends a Command 0x0030: ReturnRepeat telegram | ||
2320 | * to the device. | ||
2321 | * | ||
2322 | * Byte Value Meaning | ||
2323 | * 0 0xFF Sync byte (required only for UART serial) | ||
2324 | * 1 0x55 Start of telegram | ||
2325 | * 2 0x03 Telegram payload length | ||
2326 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2327 | * 4 0x00 Command ID (bits 15:8) | ||
2328 | * 5 0x2F Command ID (bits 7:0) | ||
2329 | * 6 0xCA Telegram payload checksum byte | ||
2330 | * | ||
2331 | */ | ||
2332 | unsigned char data[] = {0x04, 0x00, 0x30, 0x00}; | ||
2333 | if(global_settings.repeat_mode == REPEAT_OFF) | ||
2334 | data[3] = 0; | ||
2335 | else if(global_settings.repeat_mode == REPEAT_ONE) | ||
2336 | data[3] = 1; | ||
2337 | else | ||
2338 | data[3] = 2; | ||
2339 | iap_send_pkt(data, sizeof(data)); | ||
2340 | break; | ||
2341 | } | ||
2342 | case 0x0030: /* ReturnRepeat. See Above */ | ||
2343 | /* The following is the description for the Apple Firmware | ||
2344 | * | ||
2345 | * Returns the current iPod track repeat state to the device. | ||
2346 | * The iPod sends this telegram in response to the Command | ||
2347 | * 0x002F:GetRepeat command. | ||
2348 | * | ||
2349 | * Byte Value Meaning | ||
2350 | * 0 0xFF Sync byte (required only for UART serial) | ||
2351 | * 1 0x55 Start of telegram | ||
2352 | * 2 0x04 Telegram payload length | ||
2353 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2354 | * 4 0x00 Command ID (bits 15:8) | ||
2355 | * 5 0x30 Command ID (bits 7:0) | ||
2356 | * 6 0xNN Repeat state. See Below. | ||
2357 | * 7 0xNN Telegram payload checksum byte | ||
2358 | * | ||
2359 | * Repeat state values | ||
2360 | * Value Meaning | ||
2361 | * 0x00 Repeat off | ||
2362 | * 0x01 Repeat one track | ||
2363 | * 0x02 Repeat all tracks | ||
2364 | * 0x03 - 0xFF Reserved | ||
2365 | * | ||
2366 | */ | ||
2367 | { | ||
2368 | /* We should NEVER receive this command so ERROR if we do */ | ||
2369 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2370 | break; | ||
2371 | } | ||
2372 | case 0x0031: /* SetRepeat */ | ||
2373 | { | ||
2374 | /* The following is the description for the Apple Firmware | ||
2375 | * | ||
2376 | * Sets the repeat state of the iPod. The iPod track repeat modes | ||
2377 | * are listed above. In response, the iPod sends an ACK telegram | ||
2378 | * with the command status. | ||
2379 | * | ||
2380 | * This telegram has an optional byte, byte 0x07, called the | ||
2381 | * RestoreonExitbyte. This byte can be used to restore the original | ||
2382 | * repeat setting in use when the accessory was attached to the | ||
2383 | * iPod. A nonzero value restores the original repeat setting of | ||
2384 | * the iPod when the accessory is detached. If this byte is zero, | ||
2385 | * the repeat setting set by the accessory overwrites the original | ||
2386 | * setting and persists after the accessory is detached from the | ||
2387 | * iPod. | ||
2388 | * | ||
2389 | * Note: Accessory developers are encouraged to always use the | ||
2390 | * Restore on Exit byte with a nonzero value to restore any | ||
2391 | * settings modified by the accessory upon detach. | ||
2392 | * | ||
2393 | * SetRepeat telegram with Restore on Exit byte | ||
2394 | * Byte Value Meaning | ||
2395 | * 0 0xFF Sync byte (required only for UART serial) | ||
2396 | * 1 0x55 Start of telegram | ||
2397 | * 2 0x05 Telegram payload length | ||
2398 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2399 | * 4 0x00 Command ID (bits 15:8) | ||
2400 | * 5 0x31 Command ID (bits 7:0) | ||
2401 | * 6 0xNN New repeat state. See above. | ||
2402 | * 7 0xNN Restore on Exit byte. If 1, the original setting is | ||
2403 | * restored on detach; if 0, the newsetting persists | ||
2404 | * after accessory detach. | ||
2405 | * 8 0xNN Telegram payload checksum byte | ||
2406 | * | ||
2407 | * SetRepeat setting persistent after the accessory detach. | ||
2408 | * Byte Value Meaning | ||
2409 | * 0 0xFF Sync byte (required only for UART serial) | ||
2410 | * 1 0x55 Start of telegram | ||
2411 | * 2 0x04 Telegram payload length | ||
2412 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2413 | * 4 0x00 Command ID (bits 15:8) | ||
2414 | * 5 0x31 Command ID (bits 7:0) | ||
2415 | * 6 0xNN New repeat state. See above. | ||
2416 | * 7 0xNN Telegram payload checksum byte | ||
2417 | * | ||
2418 | */ | ||
2419 | int oldmode = global_settings.repeat_mode; | ||
2420 | if (buf[3] == 0) | ||
2421 | global_settings.repeat_mode = REPEAT_OFF; | ||
2422 | else if (buf[3] == 1) | ||
2423 | global_settings.repeat_mode = REPEAT_ONE; | ||
2424 | else if (buf[3] == 2) | ||
2425 | global_settings.repeat_mode = REPEAT_ALL; | ||
2426 | |||
2427 | if (oldmode != global_settings.repeat_mode) | ||
2428 | { | ||
2429 | settings_save(); | ||
2430 | if (audio_status() & AUDIO_STATUS_PLAY) | ||
2431 | audio_flush_and_reload_tracks(); | ||
2432 | } | ||
2433 | /* respond with cmd ok packet */ | ||
2434 | cmd_ok(cmd); | ||
2435 | break; | ||
2436 | } | ||
2437 | case 0x0032: /* SetDisplayImage */ | ||
2438 | { | ||
2439 | /* The following is the description for the Apple Firmware | ||
2440 | * This sets a bitmap image | ||
2441 | * that is displayed on the iPod display when connected to the | ||
2442 | * device. It replaces the default checkmark bitmap image that is | ||
2443 | * displayed when iPod is connected to an external device | ||
2444 | * | ||
2445 | * Sets a bitmap image that is shown on the iPod display when it is | ||
2446 | * connected to the device. The intent is to allow third party | ||
2447 | * branding when the iPod is communicating with an external device. | ||
2448 | * An image downloaded using this mechanism replaces the default | ||
2449 | * checkmark bitmap image that is displayed when iPod is connected | ||
2450 | * to an external device. The new bitmap is retained in RAM for as | ||
2451 | * long as the iPod remains powered. After a system reset or deep | ||
2452 | * sleep state, the new bitmap is lost and the checkmark image | ||
2453 | * restored as the default when the iPod next enters Extended | ||
2454 | * Interface mode after power-up. | ||
2455 | * Before setting a monochrome display image, the device can send | ||
2456 | * the Command 0x0033: GetMonoDisplayImageLimits telegram to obtain | ||
2457 | * the current iPod display width, height and pixel format.The | ||
2458 | * monochrome display information returned in the Command 0x0034: | ||
2459 | * ReturnMonoDisplayImageLimits telegram can be useful to the | ||
2460 | * device in deciding which type of display image format is suitable | ||
2461 | * for downloading to the iPod. | ||
2462 | * On iPods withcolor displays, devices can send the Command 0x0039: | ||
2463 | * GetColorDisplayImageLimits telegram to obtain the iPod color | ||
2464 | * display width,height,and pixel formats. The color display | ||
2465 | * information is returned in the Command 0x003A: | ||
2466 | * ReturnColorDisplayImageLimits” telegram. | ||
2467 | * To set a display image, the device must successfully send | ||
2468 | * SetDisplayImage descriptor and data telegrams to the iPod. The | ||
2469 | * SetDisplayImage descriptor telegram (telegram index 0x0000) must | ||
2470 | * be sent first, as it gives the iPod a description of the image | ||
2471 | * to be downloaded. This telegram is shown in below. The image | ||
2472 | * descriptor telegram includes image pixel format, image width and | ||
2473 | * height, and display row size (stride) in bytes. Optionally, the | ||
2474 | * descriptor telegram may also contain the beginning data of the | ||
2475 | * display image, as long as it remains within the maximum length | ||
2476 | * limits of the telegram. | ||
2477 | * Following the descriptor telegram, the SetDisplayImage data | ||
2478 | * telegrams (telegram index 0x0001 - 0xNNNN) should be sent using | ||
2479 | * sequential telegram indices until the entire image has been sent | ||
2480 | * to the iPod. | ||
2481 | * | ||
2482 | * Note: The SetDisplayImage telegram payload length is limited to | ||
2483 | * 500 bytes. This telegram length limit and the size and format of | ||
2484 | * the display image generally determine the minimum number of | ||
2485 | * telegrams that are required to set a display image. | ||
2486 | * | ||
2487 | * Note: Starting with the second generation iPod nano with version | ||
2488 | * 1.1.2 firmware, the use of the SetDisplayImage command is | ||
2489 | * limited to once every 15 seconds over USB transport. The iPod | ||
2490 | * classic and iPod 3G nano apply this restriction to both USB and | ||
2491 | * UART transports. Calls made to SetDisplayImage more frequently | ||
2492 | * than every 15 seconds will return a successful ACK command, but | ||
2493 | * the bitmap will not be displayed on the iPod’s screen. Hence use | ||
2494 | * of the SetDisplayImage command should be limited to drawing one | ||
2495 | * bitmap image per accessory connect. The iPod touch will accept | ||
2496 | * the SetDisplayImage command but will not draw it on the iPod’s | ||
2497 | * screen. | ||
2498 | * | ||
2499 | * Below shows the format of a descriptor telegram. This example | ||
2500 | * assumes the display image descriptor data exceeds the small | ||
2501 | * telegram payload capacity; a large telegram format is shown. | ||
2502 | * | ||
2503 | * SetDisplayImage descriptor telegram (telegram index = 0x0000) | ||
2504 | * Byte Value Meaning | ||
2505 | * 0 0xFF Sync byte (required only for UART serial) | ||
2506 | * 1 0x55 Start of telegram | ||
2507 | * 2 0x00 Telegram payload marker (large format) | ||
2508 | * 3 0xNN Large telegram payload length (bits 15:8) | ||
2509 | * 4 0xNN Large telegram payload length (bits 7:0) | ||
2510 | * 5 0x04 Lingo ID: Extended Interface lingo | ||
2511 | * 6 0x00 Command ID (bits 15:8) | ||
2512 | * 7 0x32 Command ID (bits 7:0) | ||
2513 | * 8 0x00 Descriptor telegram index (bits 15:8). These fields | ||
2514 | * uniquely identify each packet in the SetDisplayImage | ||
2515 | * transaction. The first telegram is the Descriptor | ||
2516 | * telegram and always starts with an index of 0x0000. | ||
2517 | * 9 0x00 Descriptor telegram index (bits 7:0) | ||
2518 | * 10 0xNN Display pixel format code. See Below. | ||
2519 | * 11 0xNN Imagewidth in pixels (bits 15:8). The number of | ||
2520 | * pixels, from left to right, per row. | ||
2521 | * 12 0xNN Image width in pixels (bits 7:0) | ||
2522 | * 13 0xNN Image height in pixels (bits 15:8). The number of | ||
2523 | * rows, from top to bottom, in the image. | ||
2524 | * 14 0xNN Image height in pixels (bits 7:0) | ||
2525 | * 15 0xNN Row size (stride) in bytes (bits 31:24). The number of | ||
2526 | * bytes representing one row of pixels. Each row is | ||
2527 | * zero-padded to end on a 32-bit boundary. The | ||
2528 | * cumulative size, in bytes, of the image data, | ||
2529 | * transferred across all telegrams in this transaction | ||
2530 | * is effectively (Row Size * Image Height). | ||
2531 | * 16 0xNN Row size (stride) in bytes (bits 23:16) | ||
2532 | * 17 0xNN Row size (stride) in bytes (bits 15:8) | ||
2533 | * 18 0xNN Row size (stride) in bytes (bits 7:0) | ||
2534 | * 19–N 0xNN Display image pixel data | ||
2535 | * NN 0xNN Telegram payload checksum byte | ||
2536 | * | ||
2537 | * SetDisplayImage data telegram (telegram index = 0x0001 - 0xNNNN) | ||
2538 | * Byte Value Meaning | ||
2539 | * 0 0xFF Sync byte (required only for UART serial) | ||
2540 | * 1 0x55 Start of telegram | ||
2541 | * 2 0x00 Telegram payload marker (large format) | ||
2542 | * 3 0xNN Large telegram payload length (bits 15:8) | ||
2543 | * 4 0xNN Large telegram payload length (bits 7:0) | ||
2544 | * 5 0x04 Lingo ID: Extended Interface lingo | ||
2545 | * 6 0x00 Command ID (bits 15:8) | ||
2546 | * 7 0x32 Command ID (bits 7:0) | ||
2547 | * 8 0xNN Descriptor telegram index (bits 15:8). These fields | ||
2548 | * uniquely identify each packet in the SetDisplayImage | ||
2549 | * transaction. The first telegram is the descriptor | ||
2550 | * telegram, shown in Table 6-68 (page 97). The | ||
2551 | * remaining n-1 telegrams are simply data telegrams, | ||
2552 | * where n is determined by the size of the image. | ||
2553 | * 9 0xNN Descriptor telegram index (bits 7:0) | ||
2554 | * 10–N 0xNN Display image pixel data | ||
2555 | * NN 0xNN Telegram payload checksum byte | ||
2556 | * | ||
2557 | * Note: A known issue causes SetDisplayImage data telegram | ||
2558 | * lengths less than 11 bytes to return a bad parameter error (0x04) | ||
2559 | * ACK on 3G iPods. | ||
2560 | * | ||
2561 | * The iPod display is oriented as a rectangular grid of pixels. In | ||
2562 | * the horizontal direction (x-coordinate), the pixel columns are | ||
2563 | * numbered, left to right, from 0 to Cmax. In the vertical | ||
2564 | * direction (y-coordinate), the pixel rows are numbered, top to | ||
2565 | * bottom, from 0 to Rmax. Therefore, an (x,y) coordinate of (0,0) | ||
2566 | * represents the upper-leftmost pixel on the display and | ||
2567 | * (Cmax,Rmax) represents the lower-rightmost pixel on the display. | ||
2568 | * A portion of the iPod display pixel layout is shown below, where | ||
2569 | * x is the column number, y is the row number, and (Cmax,Rmax) | ||
2570 | * represents the maximum row and column numbers. | ||
2571 | * | ||
2572 | * Pixel layout | ||
2573 | * x | ||
2574 | * y 0,0 1,0 2,0 3,0 4,0 5,0 6,0 7,0 - Cmax,0 | ||
2575 | * 0,1 1,1 2,1 3,1 4,1 5,1 6,1 7,1 - Cmax,1 | ||
2576 | * 0,2 1,2 2,2 3,2 4,2 5,2 6,2 7,2 - Cmax,2 | ||
2577 | * 0,3 1,3 2,3 3,3 4,3 5,3 6,3 7,3 - Cmax,3 | ||
2578 | * 0,4 1,4 2,4 3,4 4,4 5,4 6,4 7,4 - Cmax,4 | ||
2579 | * 0,5 1,5 2,5 3,5 4,5 5,5 6,5 7,5 - Cmax,5 | ||
2580 | * 0,6 1,6 2,6 3,6 4,6 5,6 6,6 7,6 - Cmax,6 | ||
2581 | * 0,7 1,7 2,7 3,7 4,7 5,7 6,7 7,7 - Cmax,7 | ||
2582 | * " " " " " " " " " " | ||
2583 | * 0, 1, 2, 3, 4, 5, 6, 7, - Cmax, | ||
2584 | * RmaxRmaxRmaxRmaxRmaxRmaxRmaxRmax Rmax | ||
2585 | * | ||
2586 | * Display pixel format codes | ||
2587 | * Display pixel format Code Protocol version | ||
2588 | * Reserved 0x00 N/A | ||
2589 | * Monochrome, 2 bits per pixel 0x01 1.01 | ||
2590 | * RGB 565 color, little-endian, 16 bpp 0x02 1.09 | ||
2591 | * RGB 565 color, big-endian, 16 bpp 0x03 1.09 | ||
2592 | * Reserved 0x04-0xFF N/A | ||
2593 | * | ||
2594 | * iPods with color screens support all three image formats. All | ||
2595 | * other iPods support only display pixel format 0x01 (monochrome, | ||
2596 | * 2 bpp). | ||
2597 | * | ||
2598 | * Display Pixel Format 0x01 | ||
2599 | * Display pixel format 0x01 (monochrome, 2 bits per pixel) is the | ||
2600 | * pixel format supported by all iPods. Each pixel consists of 2 | ||
2601 | * bits that control the pixel intensity. The pixel intensities and | ||
2602 | * associated binary codes are listed below. | ||
2603 | * | ||
2604 | * 2 bpp monochrome pixel intensities | ||
2605 | * Pixel Intensity Binary Code | ||
2606 | * Pixel off (not visible) 00b | ||
2607 | * Pixel on 25% (light grey) 01b | ||
2608 | * Pixel on 50% (dark grey) 10b | ||
2609 | * Pixel on 100% (black) 11b | ||
2610 | * | ||
2611 | * Each byte of image data contains four packed pixels. The pixel | ||
2612 | * ordering within bytes and the byte ordering within 32 bits is | ||
2613 | * shown below. | ||
2614 | * | ||
2615 | * Image Data Byte 0x0000 | ||
2616 | * Pixel0 Pixel1 Pixel2 Pixel3 | ||
2617 | * 7 6 5 4 3 2 1 0 | ||
2618 | * | ||
2619 | * Image Data Byte 0x0001 | ||
2620 | * Pixel4 Pixel5 Pixel6 Pixel7 | ||
2621 | * 7 6 5 4 3 2 1 0 | ||
2622 | * | ||
2623 | * Image Data Byte 0x0002 | ||
2624 | * Pixel8 Pixel9 Pixel10 Pixel11 | ||
2625 | * 7 6 5 4 3 2 1 0 | ||
2626 | * | ||
2627 | * Image Data Byte 0x0003 | ||
2628 | * Pixel12 Pixel13 Pixel14 Pixel15 | ||
2629 | * 7 6 5 4 3 2 1 0 | ||
2630 | * | ||
2631 | * Image Data Byte 0xNNNN | ||
2632 | * PixelN PixelN+1 PixelN+2 PixelN+3 | ||
2633 | * 7 6 5 4 3 2 1 0 | ||
2634 | * | ||
2635 | * Display Pixel Formats 0x02 and 0x03 | ||
2636 | * Display pixel format 0x02 (RGB 565, little-endian) and display | ||
2637 | * pixel format 0x03 (RGB 565, big-endian) are available for use | ||
2638 | * in all iPods with color screens. Each pixel consists of 16 bits | ||
2639 | * that control the pixel intensity for the colors red, green, and | ||
2640 | * blue. | ||
2641 | * It takes two bytes to represent a single pixel. Red is | ||
2642 | * represented by 5 bits, green is represented by 6 bits, and blue | ||
2643 | * by the final 5 bits. A 32-bit sequence represents 2 pixels. The | ||
2644 | * pixel ordering within bytes and the byte ordering within 32 bits | ||
2645 | * for display format 0x02 (RGB 565, little-endian) is shown below. | ||
2646 | * | ||
2647 | * Image Data Byte 0x0000 | ||
2648 | * Pixel 0, lower 3 bits of green Pixel 0, all 5 bits of blue | ||
2649 | * 7 6 5 4 3 2 1 0 | ||
2650 | * Image Data Byte 0x0001 | ||
2651 | * Pixel 0, all 5 bits of red Pixel 0,upper 3 bits of green | ||
2652 | * 7 6 5 4 3 2 1 0 | ||
2653 | * | ||
2654 | * Image Data Byte 0x0002 | ||
2655 | * Pixel 1, lower 3 bits of green Pixel 1, all 5 bits of blue | ||
2656 | * 7 6 5 4 3 2 1 0 | ||
2657 | * | ||
2658 | * Image Data Byte 0x0003 | ||
2659 | * Pixel 1, all 5 bits of red Pixel 1, upper 3 bits of green | ||
2660 | * 7 6 5 4 3 2 1 0 | ||
2661 | * | ||
2662 | * The format for display pixel format 0x03 (RGB 565, big-endian, 16 | ||
2663 | * bpp) is almost identical, with the exception that bytes 0 and 1 | ||
2664 | * are swapped and bytes 2 and 3 are swapped. | ||
2665 | * | ||
2666 | */ | ||
2667 | cmd_ok(cmd); | ||
2668 | break; | ||
2669 | } | ||
2670 | case 0x0033: /* GetMonoDisplayImageLimits */ | ||
2671 | |||
2672 | { | ||
2673 | /* The following is the description for the Apple Firmware | ||
2674 | * | ||
2675 | * Requests the limiting characteristics of the monochrome image | ||
2676 | * that can be sent to the iPod for display while it is connected | ||
2677 | * to the device. It can be used to determine the display pixel | ||
2678 | * format and maximum width and height of a monochrome image to be | ||
2679 | * set using the Command 0x0032: SetDisplayImage telegram. In | ||
2680 | * response, the iPod sends a Command 0x0034: | ||
2681 | * ReturnMonoDisplayImageLimits telegram to the device with the | ||
2682 | * requested display information. The GetMonoDisplayImageLimits | ||
2683 | * command is supported by iPods with either monochrome or color | ||
2684 | * displays. To obtain color display image limits, use Command | ||
2685 | * 0x0039: GetColorDisplayImageLimits. | ||
2686 | * | ||
2687 | * Byte Value Meaning | ||
2688 | * 0 0xFF Sync byte (required only for UART serial) | ||
2689 | * 1 0x55 Start of telegram | ||
2690 | * 2 0x03 Telegram payload length | ||
2691 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2692 | * 4 0x00 Command ID (bits 15:8) | ||
2693 | * 5 0x33 Command ID (bits 7:0) | ||
2694 | * 6 0xC6 Telegram payload checksum byte | ||
2695 | * | ||
2696 | */ | ||
2697 | unsigned char data[] = {0x04, 0x00, 0x34, | ||
2698 | LCD_WIDTH >> 8, LCD_WIDTH & 0xff, | ||
2699 | LCD_HEIGHT >> 8, LCD_HEIGHT & 0xff, | ||
2700 | 0x01}; | ||
2701 | iap_send_pkt(data, sizeof(data)); | ||
2702 | break; | ||
2703 | } | ||
2704 | case 0x0034: /* ReturnMonoDisplayImageLimits. See Above*/ | ||
2705 | /* The following is the description for the Apple Firmware | ||
2706 | * | ||
2707 | * Returns the limiting characteristics of the monochrome image that | ||
2708 | * can be sent to the iPod for display while it is connected to the | ||
2709 | * device. The iPod sends this telegram in response to the Command | ||
2710 | * 0x0033: GetMonoDisplayImageLimits telegram. Monochrome display | ||
2711 | * characteristics include maximum image width and height and the | ||
2712 | * display pixel format. | ||
2713 | * | ||
2714 | * Byte Value Meaning | ||
2715 | * 0 0xFF Sync byte (required only for UART serial) | ||
2716 | * 1 0x55 Start of telegram | ||
2717 | * 2 0xNN Telegram payload length | ||
2718 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2719 | * 4 0x00 Command ID (bits 15:8) | ||
2720 | * 5 0x34 Command ID (bits 7:0) | ||
2721 | * 6 0xNN Maximum image width in pixels (bits 15:8) | ||
2722 | * 7 0xNN Maximum image width in pixels (bits 7:0) | ||
2723 | * 8 0xNN Maximum image height in pixels (bits 15:8) | ||
2724 | * 9 0xNN Maximumimage height in pixels (bits 7:0) | ||
2725 | * 10 0xNN Display pixel format (see Table 6-70 (page 99)). | ||
2726 | * 11 0xNN Telegram payload checksum byte | ||
2727 | * | ||
2728 | */ | ||
2729 | { | ||
2730 | /* We should NEVER receive this command so ERROR if we do */ | ||
2731 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2732 | break; | ||
2733 | } | ||
2734 | case 0x0035: /* GetNumPlayingTracks */ | ||
2735 | { | ||
2736 | /* The following is the description for the Apple Firmware | ||
2737 | * | ||
2738 | * Requests the number of tracks in the list of tracks queued to | ||
2739 | * play on the iPod. In response, the iPod sends a Command 0x0036: | ||
2740 | * ReturnNumPlayingTracks telegram with the count of tracks queued | ||
2741 | * to play. | ||
2742 | * | ||
2743 | * Byte Value Meaning | ||
2744 | * 0 0xFF Sync byte (required only for UART serial) | ||
2745 | * 1 0x55 Start of telegram | ||
2746 | * 2 0x03 Telegram payload length | ||
2747 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2748 | * 4 0x00 Command ID (bits 15:8) | ||
2749 | * 5 0x35 Command ID (bits 7:0) | ||
2750 | * 6 0xC4 Telegram payload checksum byte | ||
2751 | * | ||
2752 | */ | ||
2753 | unsigned char data[] = {0x04, 0x00, 0x36, | ||
2754 | 0x00, 0x00, 0x00, 0x00}; | ||
2755 | unsigned long playlist_amt = playlist_amount(); | ||
2756 | put_u32(&data[3], playlist_amt); | ||
2757 | iap_send_pkt(data, sizeof(data)); | ||
2758 | break; | ||
2759 | } | ||
2760 | case 0x0036: /* ReturnNumPlayingTracks. See Above */ | ||
2761 | /* The following is the description for the Apple Firmware | ||
2762 | * | ||
2763 | * Returns the number of tracks in the actual list of tracks queued | ||
2764 | * to play, including the currently playing track (if any). The | ||
2765 | * iPod sends this telegram in response to the Command 0x0035: | ||
2766 | * GetNumPlayingTracks telegram. | ||
2767 | * | ||
2768 | * Byte Value Meaning | ||
2769 | * 0 0xFF Sync byte (required only for UART serial) | ||
2770 | * 1 0x55 Start of telegram | ||
2771 | * 2 0x07 Telegram payload length | ||
2772 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2773 | * 4 0x00 Command ID (bits 15:8) | ||
2774 | * 5 0x36 Command ID (bits 7:0) | ||
2775 | * 6 0xNN Number of tracks playing(bits 31:24) | ||
2776 | * 7 0xNN Number of tracks playing(bits 23:16) | ||
2777 | * 8 0xNN Number of tracks playing (bits 15:8) | ||
2778 | * 9 0xNN Number of tracks playing (bits 7:0) | ||
2779 | * 10 0xNN Telegram payload checksum byte | ||
2780 | * | ||
2781 | */ | ||
2782 | { | ||
2783 | /* We should NEVER receive this command so ERROR if we do */ | ||
2784 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2785 | break; | ||
2786 | } | ||
2787 | case 0x0037: /* SetCurrentPlayingTrack */ | ||
2788 | /* The following is the description for the Apple Firmware | ||
2789 | * | ||
2790 | * Sets the index of the track to play in the Now Playing playlist | ||
2791 | * on the iPod. The index that is specified here is obtained by | ||
2792 | * sending the Command 0x0035: GetNumPlayingTracks and Command | ||
2793 | * 0x001E: GetCurrentPlayingTrackIndex telegrams to obtain the | ||
2794 | * number of playing tracks and the current playing track index, | ||
2795 | * respectively. In response, the iPod sends an ACK telegram | ||
2796 | * indicating the status of the command. | ||
2797 | * | ||
2798 | * Note: The behavior of this command has changed. Before the | ||
2799 | * 2G nano, if this command was sent with the current playing track | ||
2800 | * index the iPod would pause playback momentarily and then resume. | ||
2801 | * Starting with the 2G nano, the iPod restarts playback of the | ||
2802 | * current track from the beginning. Older iPods will not be | ||
2803 | * updated to the new behavior. | ||
2804 | * | ||
2805 | * Note: This command is usable only when the iPod is in a playing | ||
2806 | * or paused state. If the iPod is stopped, this command fails. | ||
2807 | * | ||
2808 | * Byte Value Meaning | ||
2809 | * 0 0xFF Sync byte (required only for UART serial) | ||
2810 | * 1 0x55 Start of telegram | ||
2811 | * 2 0x07 Telegram payload length | ||
2812 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2813 | * 4 0x00 Command ID (bits 15:8) | ||
2814 | * 5 0x37 Command ID (bits 7:0) | ||
2815 | * 6 0xNN New current playing track index (bits 31:24) | ||
2816 | * 7 0xNN New current playing track index (bits 23:16) | ||
2817 | * 8 0xNN New current playing track index (bits 15:8) | ||
2818 | * 9 0xNN New current playing track index (bits 7:0) | ||
2819 | * 10 0xNN Telegram payload checksum byte | ||
2820 | * | ||
2821 | */ | ||
2822 | { | ||
2823 | int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE)); | ||
2824 | long tracknum = get_u32(&buf[3]); | ||
2825 | |||
2826 | audio_pause(); | ||
2827 | audio_skip(tracknum - playlist_next(0)); | ||
2828 | if (!paused) | ||
2829 | audio_resume(); | ||
2830 | |||
2831 | /* respond with cmd ok packet */ | ||
2832 | cmd_ok(cmd); | ||
2833 | break; | ||
2834 | } | ||
2835 | case 0x0038: /* SelectSortDBRecord */ | ||
2836 | /* The following is the description for the Apple Firmware | ||
2837 | * | ||
2838 | * Selects one or more records in the iPod database, based on a | ||
2839 | * category-relative index. For example, selecting category 2 | ||
2840 | * (Artist), record index 1, and sort order 3 (Album) results in a | ||
2841 | * list of selected tracks (records) from the second artist in the | ||
2842 | * artist list, sorted by album name. Selections are additive and | ||
2843 | * limited by the category hierarchy. Subsequent selections are | ||
2844 | * made based on the subset of records resulting from previous | ||
2845 | * selections and not from the entire database. The database | ||
2846 | * category types are shown above. The sort order options and codes | ||
2847 | * are shown below. | ||
2848 | * | ||
2849 | * SelectSortDBRecord telegram | ||
2850 | * Byte Value Meaning | ||
2851 | * 0 0xFF Sync byte (required only for UART serial) | ||
2852 | * 1 0x55 Start of telegram | ||
2853 | * 2 0x09 Telegram payload length | ||
2854 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
2855 | * 4 0x00 Command ID (bits 15:8) | ||
2856 | * 5 0x38 Command ID (bits 7:0) | ||
2857 | * 6 0xNN Database category type. | ||
2858 | * 7 0xNN Category record index (bits 31:24) | ||
2859 | * 8 0xNN Category record index (bits 23:16) | ||
2860 | * 9 0xNN Category record index (bits 15:8) | ||
2861 | * 10 0xNN Category record index (bits 7:0) | ||
2862 | * 11 0xNN Database sort type. | ||
2863 | * 12 0xNN Telegram payload checksum byte | ||
2864 | * | ||
2865 | * Database sort order options | ||
2866 | * Sort Order Code Protocol version | ||
2867 | * Sort by genre 0x00 1.00 | ||
2868 | * Sort by artist 0x01 1.00 | ||
2869 | * Sort by composer 0x02 1.00 | ||
2870 | * Sort by album 0x03 1.00 | ||
2871 | * Sort by name 0x04 1.00 | ||
2872 | * Sort by playlist 0x05 1.00 | ||
2873 | * Sort by release date 0x06 1.08 | ||
2874 | * Reserved 0x07 - 0xFE N/A | ||
2875 | * Use default sort type 0xFF 1.00 | ||
2876 | * | ||
2877 | * The default order of song and audiobook tracks on the iPod is | ||
2878 | * alphabetical by artist, then alphabetical by that artist's | ||
2879 | * albums, then ordered according to the order of the tracks on the | ||
2880 | * album. | ||
2881 | * For podcasts, the default order of episode tracks is reverse | ||
2882 | * chronological. That is, the newest ones are first,then | ||
2883 | * alphabetical by podcast name. | ||
2884 | * The SelectSortDBRecord command can be used to sort all the song | ||
2885 | * and audiobook tracks on the iPod alphabetically as follows: | ||
2886 | * 1. Command 0x0016: ResetDBSelection | ||
2887 | * 2. Command 0x0018: GetNumberCategorizedDBRecords for the Playlist | ||
2888 | * category. | ||
2889 | * 3. SelectSortDBRecord based on the Playlist category, using a | ||
2890 | * record index of 0 to select the All Tracks | ||
2891 | * playlist and the sort by name (0x04) sort | ||
2892 | * order. | ||
2893 | * 4. GetNumberCategorizedDBRecords for the Track category. | ||
2894 | * 5. Command 0x001A :RetrieveCategorizedDatabaseRecords based on | ||
2895 | * the Track category, using a start index of 0 | ||
2896 | * and an end index of the number of records | ||
2897 | * returned by the call to | ||
2898 | * GetNumberCategorizedDBRecords in step 4. | ||
2899 | * | ||
2900 | * The sort order of artist names ignores certain articles such | ||
2901 | * that the artist “The Doors” is sorted under the letter ‘D’ and | ||
2902 | * not ‘T’; this matches the behavior of iTunes. The sort order is | ||
2903 | * different depending on the language setting used in the iPod. | ||
2904 | * The list of ignored articles may change in the future without | ||
2905 | * notice. | ||
2906 | * The SelectDBRecord command may also be used to select a database | ||
2907 | * record with the default sort order. | ||
2908 | * | ||
2909 | * Note: The sort order field is ignored for the Audiobook category. | ||
2910 | * Audiobooks are automatically sorted by track title. The sort | ||
2911 | * order for podcast tracks defaults to release date, with the | ||
2912 | * newest track coming first. | ||
2913 | * | ||
2914 | * Selects one or more records in the iPod database, based on a | ||
2915 | * category-relative index. This appears to be hardcoded hierarchy | ||
2916 | * decided by Apple that the external devices follow. | ||
2917 | * This is as follows for all except podcasts, | ||
2918 | * | ||
2919 | * All (highest level), | ||
2920 | * Playlist, | ||
2921 | * Genre or Media Kind, | ||
2922 | * Artist or Composer, | ||
2923 | * Album, | ||
2924 | * Track or Audiobook (lowest) | ||
2925 | * | ||
2926 | * for Podcasts, the order is | ||
2927 | * | ||
2928 | * All (highest), | ||
2929 | * Podcast, | ||
2930 | * Episode | ||
2931 | * Track (lowest) | ||
2932 | * | ||
2933 | * Categories are | ||
2934 | * | ||
2935 | * 0x00 Reserved | ||
2936 | * 0x01 Playlist | ||
2937 | * 0x02 Artist | ||
2938 | * 0x03 Album | ||
2939 | * 0x04 Genre | ||
2940 | * 0x05 Track | ||
2941 | * 0x06 Composer | ||
2942 | * 0x07 Audiobook | ||
2943 | * 0x08 Podcast | ||
2944 | * 0x09 - 0xff Reserved | ||
2945 | * | ||
2946 | * Sort Order optiona and codes are | ||
2947 | * | ||
2948 | * 0x00 Sort by Genre | ||
2949 | * 0x01 Sort by Artist | ||
2950 | * 0x02 Sort by Composer | ||
2951 | * 0x03 Sort by Album | ||
2952 | * 0x04 Sort by Name (Song Title) | ||
2953 | * 0x05 Sort by Playlist | ||
2954 | * 0x06 Sort by Release Date | ||
2955 | * 0x07 - 0xfe Reserved | ||
2956 | * 0xff Use default Sort Type | ||
2957 | * | ||
2958 | * Packet format (offset in data[]: Description) | ||
2959 | * 0x00: Lingo ID: Extended Interface Protocol Lingo, always 0x04 | ||
2960 | * 0x01-0x02: Command, always 0x0038 | ||
2961 | * 0x03: Database Category Type | ||
2962 | * 0x04-0x07: Category Record Index | ||
2963 | * 0x08 Database Sort Type | ||
2964 | * | ||
2965 | * On Rockbox, if the recordtype is playlist, we load the selected | ||
2966 | * playlist and start playing from the first track. | ||
2967 | * If the recordtype is track, we play that track from the current | ||
2968 | * playlist. | ||
2969 | * On anything else we just play the current track from the current | ||
2970 | * playlist. | ||
2971 | * cur_dbrecord[0] is the recordtype | ||
2972 | * cur_dbrecord[1-4] is the u32 of the record number requested | ||
2973 | * which might be a playlist or a track number depending on | ||
2974 | * the value of cur_dbrecord[0] | ||
2975 | */ | ||
2976 | { | ||
2977 | memcpy(cur_dbrecord, buf + 3, 5); | ||
2978 | |||
2979 | int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE)); | ||
2980 | unsigned int number_of_playlists = nbr_total_playlists(); | ||
2981 | uint32_t index; | ||
2982 | uint32_t trackcount; | ||
2983 | index = get_u32(&cur_dbrecord[1]); | ||
2984 | trackcount = playlist_amount(); | ||
2985 | if ((cur_dbrecord[0] == 0x05) && (index > trackcount)) | ||
2986 | { | ||
2987 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2988 | break; | ||
2989 | } | ||
2990 | if ((cur_dbrecord[0] == 0x01) && (index > (number_of_playlists + 1))) | ||
2991 | { | ||
2992 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
2993 | break; | ||
2994 | } | ||
2995 | switch (cur_dbrecord[0]) | ||
2996 | { | ||
2997 | case 0x01: /* Playlist*/ | ||
2998 | { | ||
2999 | if (index != 0x00) /* 0x00 is the On-The-Go Playlist and | ||
3000 | we do nothing with it */ | ||
3001 | { | ||
3002 | audio_pause(); | ||
3003 | audio_skip(-iap_get_trackindex()); | ||
3004 | playlist_sort(NULL, true); | ||
3005 | last_selected_playlist = index; | ||
3006 | seek_to_playlist(last_selected_playlist); | ||
3007 | } | ||
3008 | break; | ||
3009 | } | ||
3010 | case 0x02: /* Artist Do Nothing */ | ||
3011 | case 0x03: /* Album Do Nothing */ | ||
3012 | case 0x04: /* Genre Do Nothing */ | ||
3013 | case 0x06: /* Composer Do Nothing */ | ||
3014 | break; | ||
3015 | case 0x05: /* Track*/ | ||
3016 | { | ||
3017 | audio_pause(); | ||
3018 | audio_skip(-iap_get_trackindex()); | ||
3019 | playlist_sort(NULL, true); | ||
3020 | audio_skip(index - playlist_next(0)); | ||
3021 | break; | ||
3022 | } | ||
3023 | } | ||
3024 | if (!paused) | ||
3025 | audio_resume(); | ||
3026 | /* respond with cmd ok packet */ | ||
3027 | cmd_ok(cmd); | ||
3028 | break; | ||
3029 | } | ||
3030 | case 0x0039: /* GetColorDisplayImageLimits */ | ||
3031 | /* The following is the description for the Apple Firmware | ||
3032 | * | ||
3033 | * Requests the limiting characteristics of the color image that | ||
3034 | * can be sent to the iPod for display while it is connected to | ||
3035 | * the device. It can be used to determine the display pixel format | ||
3036 | * and maximum width and height of a color image to be set using | ||
3037 | * the Command 0x0032: SetDisplayImage telegram. In response, the | ||
3038 | * iPod sends a Command 0x003A: ReturnColorDisplayImageLimits | ||
3039 | * telegram to the device with the requested display information. | ||
3040 | * This command is supported only by iPods with color displays. | ||
3041 | * | ||
3042 | * Byte Value Meaning | ||
3043 | * 0 0xFF Sync byte (required only for UART serial) | ||
3044 | * 1 0x55 Start of telegram | ||
3045 | * 2 0x03 Telegram payload length | ||
3046 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
3047 | * 4 0x00 Command ID (bits 15:8) | ||
3048 | * 5 0x39 Command ID (bits 7:0) | ||
3049 | * 6 0xC0 Telegram payload checksum byte | ||
3050 | * | ||
3051 | */ | ||
3052 | { | ||
3053 | /* Set the same as the ReturnMonoDisplayImageLimits */ | ||
3054 | unsigned char data[] = {0x04, 0x00, 0x3A, | ||
3055 | LCD_WIDTH >> 8, LCD_WIDTH & 0xff, | ||
3056 | LCD_HEIGHT >> 8, LCD_HEIGHT & 0xff, | ||
3057 | 0x01}; | ||
3058 | iap_send_pkt(data, sizeof(data)); | ||
3059 | break; | ||
3060 | } | ||
3061 | case 0x003A: /* ReturnColorDisplayImageLimits See Above */ | ||
3062 | /* The following is the description for the Apple Firmware | ||
3063 | * | ||
3064 | * Returns the limiting characteristics of the color image that can | ||
3065 | * be sent to the iPod for display while it is connected to the | ||
3066 | * device. The iPod sends this telegram in response to the Command | ||
3067 | * 0x0039: GetColorDisplayImageLimits telegram. Display | ||
3068 | * characteristics include maximum image width and height and the | ||
3069 | * display pixel format. | ||
3070 | * | ||
3071 | * Note: If the iPod supports multiple display image formats, a five | ||
3072 | * byte block of additional image width, height, and pixel format | ||
3073 | * information is appended to the payload for each supported display | ||
3074 | * format. The list of supported color display image formats | ||
3075 | * returned by the iPod may change in future software versions. | ||
3076 | * Devices must be able to parse a variable length list of supported | ||
3077 | * color display formats to search for compatible formats. | ||
3078 | * | ||
3079 | * Byte Value Meaning | ||
3080 | * 0 0xFF Sync byte (required only for UART serial) | ||
3081 | * 1 0x55 Start of telegram | ||
3082 | * 2 0xNN Telegram payload length | ||
3083 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
3084 | * 4 0x00 Command ID (bits 15:8) | ||
3085 | * 5 0x3A Command ID (bits 7:0) | ||
3086 | * 6 0xNN Maximum image width in pixels (bits 15:8) | ||
3087 | * 7 0xNN Maximum image width in pixels (bits 7:0) | ||
3088 | * 8 0xNN Maximum image height in pixels (bits 15:8) | ||
3089 | * 9 0xNN Maximum image height in pixels (bits 7:0) | ||
3090 | * 10 0xNN Display pixel format (see Table 6-70 (page 99)). | ||
3091 | * 11-N 0xNN Optional display image width, height, and pixel format | ||
3092 | * for the second to nth supported display formats, | ||
3093 | * if present. | ||
3094 | * NN 0xNN Telegram payload checksum byte | ||
3095 | * | ||
3096 | */ | ||
3097 | { | ||
3098 | /* We should NEVER receive this command so ERROR if we do */ | ||
3099 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
3100 | break; | ||
3101 | } | ||
3102 | case 0x003B: /* ResetDBSelectionHierarchy */ | ||
3103 | { | ||
3104 | /* The following is the description for the Apple Firmware | ||
3105 | * | ||
3106 | * This command carries a single byte in its payload (byte 6). A | ||
3107 | * hierarchy selection value of 0x01 means that the accessory wants | ||
3108 | * to navigate the music hierarchy; a hierarchy selection value of | ||
3109 | * 0x02 means that the accessory wants to navigate the video | ||
3110 | * hierarchy. | ||
3111 | * | ||
3112 | * Byte Value Meaning | ||
3113 | * 0 0xFF Sync byte (required only for UART serial) | ||
3114 | * 1 0x55 Start of telegram | ||
3115 | * 2 0x04 Telegram payload length | ||
3116 | * 3 0x04 Lingo ID: Extended Interface lingo | ||
3117 | * 4 0x00 Command ID (bits 15:8) | ||
3118 | * 5 0x3B Command ID (bits 7:0) | ||
3119 | * 6 0x01 or 0x02 Hierarchy selection | ||
3120 | * 7 0xNN Telegram payload checksum byte | ||
3121 | * | ||
3122 | * Note: The iPod will return an error if a device attempts to | ||
3123 | * enable an unsupported hierarchy, such as a video hierarchy on an | ||
3124 | * iPod model that does not support video. | ||
3125 | */ | ||
3126 | dbrecordcount = 0; | ||
3127 | cur_dbrecord[0] = 0; | ||
3128 | put_u32(&cur_dbrecord[1],0); | ||
3129 | switch (buf[3]) | ||
3130 | { | ||
3131 | case 0x01: /* Music */ | ||
3132 | { | ||
3133 | cmd_ok(cmd); | ||
3134 | break; | ||
3135 | } | ||
3136 | default: /* Anything else */ | ||
3137 | { | ||
3138 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
3139 | break; | ||
3140 | } | ||
3141 | } | ||
3142 | } | ||
3143 | default: | ||
3144 | { | ||
3145 | #ifdef LOGF_ENABLE | ||
3146 | logf("iap: Unsupported Mode04 Command"); | ||
3147 | #endif | ||
3148 | /* The default response is IAP_ACK_BAD_PARAM */ | ||
3149 | cmd_ack(cmd, IAP_ACK_BAD_PARAM); | ||
3150 | break; | ||
3151 | } | ||
3152 | } | ||
3153 | } | ||