summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/iap.c115
-rw-r--r--firmware/drivers/tuner/ipod_remote_tuner.c21
-rw-r--r--firmware/export/ipod_remote_tuner.h4
3 files changed, 76 insertions, 64 deletions
diff --git a/apps/iap.c b/apps/iap.c
index 4d8a34fa57..eaee21bc89 100644
--- a/apps/iap.c
+++ b/apps/iap.c
@@ -241,16 +241,18 @@ static void cmd_ok_mode0(unsigned char cmd)
241 iap_send_pkt(data, sizeof(data)); 241 iap_send_pkt(data, sizeof(data));
242} 242}
243 243
244static void iap_handlepkt_mode0(void) 244static void iap_handlepkt_mode0(unsigned int len, const unsigned char *buf)
245{ 245{
246 unsigned int cmd = serbuf[2]; 246 (void)len; /* len currently unused */
247
248 unsigned int cmd = buf[1];
247 switch (cmd) { 249 switch (cmd) {
248 /* Identify */ 250 /* Identify */
249 case 0x01: 251 case 0x01:
250 { 252 {
251 /* FM transmitter sends this: */ 253 /* FM transmitter sends this: */
252 /* FF 55 06 00 01 05 00 02 01 F1 (mode switch) */ 254 /* FF 55 06 00 01 05 00 02 01 F1 (mode switch) */
253 if(serbuf[3] == 0x05) 255 if(buf[2] == 0x05)
254 { 256 {
255 sleep(HZ/3); 257 sleep(HZ/3);
256 /* RF Transmitter: Begin transmission */ 258 /* RF Transmitter: Begin transmission */
@@ -259,7 +261,7 @@ static void iap_handlepkt_mode0(void)
259 } 261 }
260 /* FM remote sends this: */ 262 /* FM remote sends this: */
261 /* FF 55 03 00 01 02 FA (1st thing sent) */ 263 /* FF 55 03 00 01 02 FA (1st thing sent) */
262 else if(serbuf[3] == 0x02) 264 else if (buf[2] == 0x02)
263 { 265 {
264 /* useful only for apple firmware */ 266 /* useful only for apple firmware */
265 } 267 }
@@ -312,7 +314,7 @@ static void iap_handlepkt_mode0(void)
312 { 314 {
313 /* ReturnLingoProtocolVersion */ 315 /* ReturnLingoProtocolVersion */
314 unsigned char data[] = {0x00, 0x10, 0x00, 0x01, 0x05}; 316 unsigned char data[] = {0x00, 0x10, 0x00, 0x01, 0x05};
315 data[2] = serbuf[3]; 317 data[2] = buf[2];
316 iap_send_pkt(data, sizeof(data)); 318 iap_send_pkt(data, sizeof(data));
317 break; 319 break;
318 } 320 }
@@ -322,7 +324,7 @@ static void iap_handlepkt_mode0(void)
322 { 324 {
323 cmd_ok_mode0(cmd); 325 cmd_ok_mode0(cmd);
324 326
325 uint32_t lingoes = get_u32(&serbuf[3]); 327 uint32_t lingoes = get_u32(&buf[2]);
326 328
327 if (lingoes == 0x35) 329 if (lingoes == 0x35)
328 /* FM transmitter sends this: */ 330 /* FM transmitter sends this: */
@@ -396,28 +398,28 @@ static void iap_handlepkt_mode0(void)
396 } 398 }
397} 399}
398 400
399static void iap_handlepkt_mode2(void) 401static void iap_handlepkt_mode2(unsigned int len, const unsigned char *buf)
400{ 402{
401 if(serbuf[2] != 0) return; 403 if(buf[1] != 0) return;
402 iap_remotebtn = BUTTON_NONE; 404 iap_remotebtn = BUTTON_NONE;
403 iap_remotetick = false; 405 iap_remotetick = false;
404 406
405 if(serbuf[0] >= 3 && serbuf[3] != 0) 407 if(len >= 3 && buf[2] != 0)
406 { 408 {
407 if(serbuf[3] & 1) 409 if(buf[2] & 1)
408 iap_remotebtn |= BUTTON_RC_PLAY; 410 iap_remotebtn |= BUTTON_RC_PLAY;
409 if(serbuf[3] & 2) 411 if(buf[2] & 2)
410 iap_remotebtn |= BUTTON_RC_VOL_UP; 412 iap_remotebtn |= BUTTON_RC_VOL_UP;
411 if(serbuf[3] & 4) 413 if(buf[2] & 4)
412 iap_remotebtn |= BUTTON_RC_VOL_DOWN; 414 iap_remotebtn |= BUTTON_RC_VOL_DOWN;
413 if(serbuf[3] & 8) 415 if(buf[2] & 8)
414 iap_remotebtn |= BUTTON_RC_RIGHT; 416 iap_remotebtn |= BUTTON_RC_RIGHT;
415 if(serbuf[3] & 16) 417 if(buf[2] & 16)
416 iap_remotebtn |= BUTTON_RC_LEFT; 418 iap_remotebtn |= BUTTON_RC_LEFT;
417 } 419 }
418 else if(serbuf[0] >= 4 && serbuf[4] != 0) 420 else if(len >= 4 && buf[3] != 0)
419 { 421 {
420 if(serbuf[4] & 1) /* play */ 422 if(buf[3] & 1) /* play */
421 { 423 {
422 if (audio_status() != AUDIO_STATUS_PLAY) 424 if (audio_status() != AUDIO_STATUS_PLAY)
423 { 425 {
@@ -427,7 +429,7 @@ static void iap_handlepkt_mode2(void)
427 iap_changedctr = 1; 429 iap_changedctr = 1;
428 } 430 }
429 } 431 }
430 if(serbuf[4] & 2) /* pause */ 432 if(buf[3] & 2) /* pause */
431 { 433 {
432 if (audio_status() == AUDIO_STATUS_PLAY) 434 if (audio_status() == AUDIO_STATUS_PLAY)
433 { 435 {
@@ -437,7 +439,7 @@ static void iap_handlepkt_mode2(void)
437 iap_changedctr = 1; 439 iap_changedctr = 1;
438 } 440 }
439 } 441 }
440 if((serbuf[4] & 128) && !iap_btnshuffle) /* shuffle */ 442 if((buf[3] & 128) && !iap_btnshuffle) /* shuffle */
441 { 443 {
442 iap_btnshuffle = true; 444 iap_btnshuffle = true;
443 if(!global_settings.playlist_shuffle) 445 if(!global_settings.playlist_shuffle)
@@ -458,9 +460,9 @@ static void iap_handlepkt_mode2(void)
458 else 460 else
459 iap_btnshuffle = false; 461 iap_btnshuffle = false;
460 } 462 }
461 else if(serbuf[0] >= 5 && serbuf[5] != 0) 463 else if(len >= 5 && buf[4] != 0)
462 { 464 {
463 if((serbuf[5] & 1) && !iap_btnrepeat) /* repeat */ 465 if((buf[4] & 1) && !iap_btnrepeat) /* repeat */
464 { 466 {
465 int oldmode = global_settings.repeat_mode; 467 int oldmode = global_settings.repeat_mode;
466 iap_btnrepeat = true; 468 iap_btnrepeat = true;
@@ -479,20 +481,22 @@ static void iap_handlepkt_mode2(void)
479 else 481 else
480 iap_btnrepeat = false; 482 iap_btnrepeat = false;
481 483
482 if(serbuf[5] & 16) /* ffwd */ 484 if(buf[4] & 16) /* ffwd */
483 { 485 {
484 iap_remotebtn |= BUTTON_RC_RIGHT; 486 iap_remotebtn |= BUTTON_RC_RIGHT;
485 } 487 }
486 if(serbuf[5] & 32) /* frwd */ 488 if(buf[4] & 32) /* frwd */
487 { 489 {
488 iap_remotebtn |= BUTTON_RC_LEFT; 490 iap_remotebtn |= BUTTON_RC_LEFT;
489 } 491 }
490 } 492 }
491} 493}
492 494
493static void iap_handlepkt_mode3(void) 495static void iap_handlepkt_mode3(unsigned int len, const unsigned char *buf)
494{ 496{
495 unsigned int cmd = serbuf[2]; 497 (void)len; /* len currently unused */
498
499 unsigned int cmd = buf[1];
496 switch (cmd) 500 switch (cmd)
497 { 501 {
498 /* GetCurrentEQProfileIndex */ 502 /* GetCurrentEQProfileIndex */
@@ -517,7 +521,7 @@ static void iap_handlepkt_mode3(void)
517 case 0x0C: 521 case 0x0C:
518 { 522 {
519 /* request ipod volume */ 523 /* request ipod volume */
520 if (serbuf[3] == 0x04) 524 if (buf[2] == 0x04)
521 { 525 {
522 iap_set_remote_volume(); 526 iap_set_remote_volume();
523 } 527 }
@@ -527,8 +531,8 @@ static void iap_handlepkt_mode3(void)
527 /* SetiPodStateInfo */ 531 /* SetiPodStateInfo */
528 case 0x0E: 532 case 0x0E:
529 { 533 {
530 if (serbuf[3] == 0x04) 534 if (buf[2] == 0x04)
531 global_settings.volume = (-58)+((int)serbuf[5]+1)/4; 535 global_settings.volume = (-58)+((int)buf[4]+1)/4;
532 sound_set_volume(global_settings.volume); /* indent BUG? */ 536 sound_set_volume(global_settings.volume); /* indent BUG? */
533 break; 537 break;
534 } 538 }
@@ -570,9 +574,11 @@ static void get_playlist_name(unsigned char *dest,
570 closedir(dp); 574 closedir(dp);
571} 575}
572 576
573static void iap_handlepkt_mode4(void) 577static void iap_handlepkt_mode4(unsigned int len, const unsigned char *buf)
574{ 578{
575 unsigned int cmd = (serbuf[2] << 8) | serbuf[3]; 579 (void)len; /* len currently unused */
580
581 unsigned int cmd = (buf[1] << 8) | buf[2];
576 switch (cmd) 582 switch (cmd)
577 { 583 {
578 /* GetAudioBookSpeed */ 584 /* GetAudioBookSpeed */
@@ -588,7 +594,7 @@ static void iap_handlepkt_mode4(void)
588 /* SetAudioBookSpeed */ 594 /* SetAudioBookSpeed */
589 case 0x000B: 595 case 0x000B:
590 { 596 {
591 iap_updateflag = serbuf[4] ? 0 : 1; 597 iap_updateflag = buf[3] ? 0 : 1;
592 /* respond with cmd ok packet */ 598 /* respond with cmd ok packet */
593 cmd_ok_mode4(cmd); 599 cmd_ok_mode4(cmd);
594 break; 600 break;
@@ -606,7 +612,7 @@ static void iap_handlepkt_mode4(void)
606 /* SelectDBRecord */ 612 /* SelectDBRecord */
607 case 0x0017: 613 case 0x0017:
608 { 614 {
609 memcpy(cur_dbrecord, serbuf + 4, 5); 615 memcpy(cur_dbrecord, buf + 3, 5);
610 cmd_ok_mode4(cmd); 616 cmd_ok_mode4(cmd);
611 break; 617 break;
612 } 618 }
@@ -623,7 +629,7 @@ static void iap_handlepkt_mode4(void)
623 struct dirent* playlist_file = NULL; 629 struct dirent* playlist_file = NULL;
624 char *extension; 630 char *extension;
625 631
626 switch(serbuf[4]) /* type number */ 632 switch(buf[3]) /* type number */
627 { 633 {
628 case 0x01: /* total number of playlists */ 634 case 0x01: /* total number of playlists */
629 dp = opendir(global_settings.playlist_catalog_dir); 635 dp = opendir(global_settings.playlist_catalog_dir);
@@ -658,7 +664,7 @@ static void iap_handlepkt_mode4(void)
658 {0x04, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 664 {0x04, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00,
659 'R', 'O', 'C', 'K', 'B', 'O', 'X', '\0'}; 665 'R', 'O', 'C', 'K', 'B', 'O', 'X', '\0'};
660 666
661 unsigned long item_offset = get_u32(&serbuf[5]); 667 unsigned long item_offset = get_u32(&buf[4]);
662 668
663 get_playlist_name(data + 7, item_offset, MAX_PATH); 669 get_playlist_name(data + 7, item_offset, MAX_PATH);
664 /*Remove file extension*/ 670 /*Remove file extension*/
@@ -715,7 +721,7 @@ static void iap_handlepkt_mode4(void)
715 struct mp3entry id3; 721 struct mp3entry id3;
716 int fd; 722 int fd;
717 size_t len; 723 size_t len;
718 long tracknum = get_u32(&serbuf[4]); 724 long tracknum = get_u32(&buf[3]);
719 725
720 data[2] = cmd + 1; 726 data[2] = cmd + 1;
721 memcpy(&id3, audio_current_track(), sizeof(id3)); 727 memcpy(&id3, audio_current_track(), sizeof(id3));
@@ -757,7 +763,7 @@ static void iap_handlepkt_mode4(void)
757 /* SetPlayStatusChangeNotification */ 763 /* SetPlayStatusChangeNotification */
758 case 0x0026: 764 case 0x0026:
759 { 765 {
760 iap_pollspeed = serbuf[4] ? 1 : 0; 766 iap_pollspeed = buf[3] ? 1 : 0;
761 /* respond with cmd ok packet */ 767 /* respond with cmd ok packet */
762 cmd_ok_mode4(cmd); 768 cmd_ok_mode4(cmd);
763 break; 769 break;
@@ -797,7 +803,7 @@ static void iap_handlepkt_mode4(void)
797 /* PlayControl */ 803 /* PlayControl */
798 case 0x0029: 804 case 0x0029:
799 { 805 {
800 switch(serbuf[4]) 806 switch(buf[3])
801 { 807 {
802 case 0x01: /* play/pause */ 808 case 0x01: /* play/pause */
803 iap_remotebtn = BUTTON_RC_PLAY; 809 iap_remotebtn = BUTTON_RC_PLAY;
@@ -855,14 +861,14 @@ static void iap_handlepkt_mode4(void)
855 /* SetShuffle */ 861 /* SetShuffle */
856 case 0x002E: 862 case 0x002E:
857 { 863 {
858 if(serbuf[4] && !global_settings.playlist_shuffle) 864 if(buf[3] && !global_settings.playlist_shuffle)
859 { 865 {
860 global_settings.playlist_shuffle = 1; 866 global_settings.playlist_shuffle = 1;
861 settings_save(); 867 settings_save();
862 if (audio_status() & AUDIO_STATUS_PLAY) 868 if (audio_status() & AUDIO_STATUS_PLAY)
863 playlist_randomise(NULL, current_tick, true); 869 playlist_randomise(NULL, current_tick, true);
864 } 870 }
865 else if(!serbuf[4] && global_settings.playlist_shuffle) 871 else if(!buf[3] && global_settings.playlist_shuffle)
866 { 872 {
867 global_settings.playlist_shuffle = 0; 873 global_settings.playlist_shuffle = 0;
868 settings_save(); 874 settings_save();
@@ -894,11 +900,11 @@ static void iap_handlepkt_mode4(void)
894 case 0x0031: 900 case 0x0031:
895 { 901 {
896 int oldmode = global_settings.repeat_mode; 902 int oldmode = global_settings.repeat_mode;
897 if (serbuf[4] == 0) 903 if (buf[3] == 0)
898 global_settings.repeat_mode = REPEAT_OFF; 904 global_settings.repeat_mode = REPEAT_OFF;
899 else if (serbuf[4] == 1) 905 else if (buf[3] == 1)
900 global_settings.repeat_mode = REPEAT_ONE; 906 global_settings.repeat_mode = REPEAT_ONE;
901 else if (serbuf[4] == 2) 907 else if (buf[3] == 2)
902 global_settings.repeat_mode = REPEAT_ALL; 908 global_settings.repeat_mode = REPEAT_ALL;
903 909
904 if (oldmode != global_settings.repeat_mode) 910 if (oldmode != global_settings.repeat_mode)
@@ -940,7 +946,7 @@ static void iap_handlepkt_mode4(void)
940 case 0x0037: 946 case 0x0037:
941 { 947 {
942 int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE)); 948 int paused = (is_wps_fading() || (audio_status() & AUDIO_STATUS_PAUSE));
943 long tracknum = get_u32(&serbuf[4]); 949 long tracknum = get_u32(&buf[3]);
944 950
945 audio_pause(); 951 audio_pause();
946 audio_skip(tracknum - playlist_next(0)); 952 audio_skip(tracknum - playlist_next(0));
@@ -961,9 +967,9 @@ static void iap_handlepkt_mode4(void)
961 } 967 }
962} 968}
963 969
964static void iap_handlepkt_mode7(void) 970static void iap_handlepkt_mode7(unsigned int len, const unsigned char *buf)
965{ 971{
966 unsigned int cmd = serbuf[2]; 972 unsigned int cmd = buf[1];
967 switch (cmd) 973 switch (cmd)
968 { 974 {
969 /* RetTunerCaps */ 975 /* RetTunerCaps */
@@ -983,14 +989,14 @@ static void iap_handlepkt_mode7(void)
983 /* TunerSeekDone */ 989 /* TunerSeekDone */
984 case 0x13: 990 case 0x13:
985 { 991 {
986 rmt_tuner_freq(serbuf); 992 rmt_tuner_freq(len, buf);
987 break; 993 break;
988 } 994 }
989 995
990 /* RdsReadyNotify, RDS station name 0x21 1E 00 + ASCII text*/ 996 /* RdsReadyNotify, RDS station name 0x21 1E 00 + ASCII text*/
991 case 0x21: 997 case 0x21:
992 { 998 {
993 rmt_tuner_rds_data(serbuf); 999 rmt_tuner_rds_data(len, buf);
994 break; 1000 break;
995 } 1001 }
996 } 1002 }
@@ -998,7 +1004,6 @@ static void iap_handlepkt_mode7(void)
998 1004
999void iap_handlepkt(void) 1005void iap_handlepkt(void)
1000{ 1006{
1001
1002 if(!iap_setupflag) return; 1007 if(!iap_setupflag) return;
1003 if(serbuf[0] == 0) return; 1008 if(serbuf[0] == 0) return;
1004 1009
@@ -1010,13 +1015,17 @@ void iap_handlepkt(void)
1010 return; 1015 return;
1011 } 1016 }
1012 1017
1013 unsigned char mode = serbuf[1]; 1018 /* get length and payload from serbuf */
1019 unsigned int len = serbuf[0];
1020 unsigned char *payload = &serbuf[1];
1021
1022 unsigned char mode = payload[0];
1014 switch (mode) { 1023 switch (mode) {
1015 case 0: iap_handlepkt_mode0(); break; 1024 case 0: iap_handlepkt_mode0(len, payload); break;
1016 case 2: iap_handlepkt_mode2(); break; 1025 case 2: iap_handlepkt_mode2(len, payload); break;
1017 case 3: iap_handlepkt_mode3(); break; 1026 case 3: iap_handlepkt_mode3(len, payload); break;
1018 case 4: iap_handlepkt_mode4(); break; 1027 case 4: iap_handlepkt_mode4(len, payload); break;
1019 case 7: iap_handlepkt_mode7(); break; 1028 case 7: iap_handlepkt_mode7(len, payload); break;
1020 } 1029 }
1021 1030
1022 serbuf[0] = 0; 1031 serbuf[0] = 0;
diff --git a/firmware/drivers/tuner/ipod_remote_tuner.c b/firmware/drivers/tuner/ipod_remote_tuner.c
index a7a16c5217..ad84cb9890 100644
--- a/firmware/drivers/tuner/ipod_remote_tuner.c
+++ b/firmware/drivers/tuner/ipod_remote_tuner.c
@@ -52,13 +52,16 @@ static void rmt_tuner_signal_power(unsigned char value)
52 tuner_signal_power = (int)(value); 52 tuner_signal_power = (int)(value);
53} 53}
54 54
55void rmt_tuner_freq(const unsigned char *serbuf) 55void rmt_tuner_freq(unsigned int len, const unsigned char *buf)
56{ 56{
57 unsigned int khz = (serbuf[3] << 24) | (serbuf[4] << 16) | 57 /* length currently unused */
58 (serbuf[5] << 8) | serbuf[6]; 58 (void)len;
59
60 unsigned int khz = (buf[2] << 24) | (buf[3] << 16) |
61 (buf[4] << 8) | buf[5];
59 tuner_frequency = khz *1000 ; 62 tuner_frequency = khz *1000 ;
60 radio_tuned = true; 63 radio_tuned = true;
61 rmt_tuner_signal_power(serbuf[7]); 64 rmt_tuner_signal_power(buf[6]);
62} 65}
63 66
64static void rmt_tuner_set_freq(int curr_freq) 67static void rmt_tuner_set_freq(int curr_freq)
@@ -270,15 +273,15 @@ static bool reply_timeout(void)
270 return (timeout >= TIMEOUT_VALUE); 273 return (timeout >= TIMEOUT_VALUE);
271} 274}
272 275
273void rmt_tuner_rds_data(const unsigned char *serbuf) 276void rmt_tuner_rds_data(unsigned int len, const unsigned char *buf)
274{ 277{
275 if (serbuf[3] == 0x1E) 278 if (buf[2] == 0x1E)
276 { 279 {
277 strlcpy(rds_radioname,serbuf+5,8); 280 strlcpy(rds_radioname,buf+4,8);
278 } 281 }
279 else if(serbuf[3] == 0x04) 282 else if(buf[2] == 0x04)
280 { 283 {
281 strlcpy(rds_radioinfo,serbuf+5,(serbuf[0]-4)); 284 strlcpy(rds_radioinfo,buf+4,len-4);
282 } 285 }
283 rds_event = true; 286 rds_event = true;
284} 287}
diff --git a/firmware/export/ipod_remote_tuner.h b/firmware/export/ipod_remote_tuner.h
index e87b967193..30c83a4135 100644
--- a/firmware/export/ipod_remote_tuner.h
+++ b/firmware/export/ipod_remote_tuner.h
@@ -28,8 +28,8 @@
28 28
29extern int radio_present; 29extern int radio_present;
30 30
31extern void rmt_tuner_freq(const unsigned char *serbuf); 31extern void rmt_tuner_freq(unsigned int len, const unsigned char *buf);
32extern void rmt_tuner_rds_data(const unsigned char *serbuf); 32extern void rmt_tuner_rds_data(unsigned int len, const unsigned char *buf);
33 33
34int ipod_rmt_tuner_set(int setting, int value); 34int ipod_rmt_tuner_set(int setting, int value);
35int ipod_rmt_tuner_get(int setting); 35int ipod_rmt_tuner_get(int setting);