summaryrefslogtreecommitdiff
path: root/apps/iap/iap-lingo1.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/iap/iap-lingo1.c')
-rw-r--r--apps/iap/iap-lingo1.c218
1 files changed, 218 insertions, 0 deletions
diff --git a/apps/iap/iap-lingo1.c b/apps/iap/iap-lingo1.c
new file mode 100644
index 0000000000..5702500f23
--- /dev/null
+++ b/apps/iap/iap-lingo1.c
@@ -0,0 +1,218 @@
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/* Lingo 0x01: Microphone Lingo
21 */
22
23#include "iap-core.h"
24#include "iap-lingo.h"
25
26/*
27 * This macro is meant to be used inside an IAP mode message handler.
28 * It is passed the expected minimum length of the message buffer.
29 * If the buffer does not have the required lenght an ACK
30 * packet with a Bad Parameter error is generated.
31 */
32#define CHECKLEN(x) do { \
33 if (len < (x)) { \
34 cmd_ack(cmd, IAP_ACK_BAD_PARAM); \
35 return; \
36 }} while(0)
37
38/* Check for authenticated state, and return an ACK Not
39 * Authenticated on failure.
40 */
41#define CHECKAUTH do { \
42 if (!DEVICE_AUTHENTICATED) { \
43 cmd_ack(cmd, IAP_ACK_NO_AUTHEN); \
44 return; \
45 }} while(0)
46
47static void cmd_ack(const unsigned char cmd, const unsigned char status)
48{
49 IAP_TX_INIT(0x03, 0x00);
50 IAP_TX_PUT(status);
51 IAP_TX_PUT(cmd);
52
53 iap_send_tx();
54}
55
56/* returns record status */
57bool iap_record(bool onoff)
58{
59 if (!DEVICE_LINGO_SUPPORTED(0x01))
60 return false;
61
62 /* iPodModeChange */
63 IAP_TX_INIT(0x01, 0x06);
64 IAP_TX_PUT(onoff ? 0x00 : 0x01);
65 iap_send_tx();
66
67 return onoff;
68}
69
70void iap_handlepkt_mode1(const unsigned int len, const unsigned char *buf)
71{
72 unsigned int cmd = buf[1];
73
74 /* Lingo 0x04 commands are at least 4 bytes in length */
75 CHECKLEN(4);
76
77 /* Lingo 0x01 must have been negotiated */
78 if (!DEVICE_LINGO_SUPPORTED(0x01)) {
79 cmd_ack(cmd, IAP_ACK_BAD_PARAM);
80 return;
81 }
82
83 /* Authentication required for all commands */
84 CHECKAUTH;
85
86 switch (cmd)
87 {
88 /* BeginRecord (0x00) Deprecated
89 *
90 * Sent from the iPod to the device
91 */
92
93 /* EndRecord (0x01) Deprecated
94 *
95 * Sent from the iPod to the device
96 */
97
98 /* BeginPlayback (0x02) Deprecated
99 *
100 * Sent from the iPod to the device
101 */
102
103 /* EndPlayback (0x03) Deprecated
104 *
105 * Sent from the iPod to the device
106 */
107
108 /* ACK (0x04)
109 *
110 * The device sends an ACK response when a command
111 * that does not return any data has completed.
112 *
113 * Packet format (offset in buf[]: Description)
114 * 0x00: Lingo ID: Microphone Lingo, always 0x01
115 * 0x01: Command, always 0x04
116 * 0x02: The command result status
117 * 0x03: The ID of the command for which the
118 * response is being sent
119 *
120 * Returns: (none)
121 */
122 case 0x04:
123#ifdef LOGF_ENABLE
124 if (buf[2] != 0x00)
125 logf("iap: Mode1 Command ACK error: "
126 "0x%02x 0x%02x", buf[2], buf[3]);
127#endif
128 break;
129
130 /* GetDevAck (0x05)
131 *
132 * Sent from the iPod to the device
133 */
134
135 /* iPodModeChange (0x06)
136 *
137 * Sent from the iPod to the device
138 */
139
140 /* GetDevCaps (0x07)
141 *
142 * Sent from the iPod to the device
143 */
144
145 /* RetDevCaps (0x08)
146 *
147 * The microphone device returns the payload
148 * indicating which capabilities it supports.
149 *
150 * Packet format (offset in buf[]: Description)
151 * 0x00: Lingo ID: Microphone Lingo, always 0x01
152 * 0x01: Command, always 0x08
153 * 0x02: Device capabilities (bits 31:24)
154 * 0x03: Device capabilities (bits 23:16)
155 * 0x04: Device capabilities (bits 15:8)
156 * 0x05: Device capabilities (bits 7:0)
157 *
158 * Returns:
159 * SetDevCtrl, sets stereo line input when supported
160 */
161 case 0x08:
162 CHECKLEN(6);
163
164 if ((buf[5] & 3) == 3) {
165 /* SetDevCtrl, set stereo line-in */
166 IAP_TX_INIT(0x01, 0x0B);
167 IAP_TX_PUT(0x01);
168 IAP_TX_PUT(0x01);
169
170 iap_send_tx();
171 }
172
173 /* TODO?: configure recording level/limiter controls
174 when supported by the device */
175
176 break;
177
178 /* GetDevCtrl (0x09)
179 *
180 * Sent from the iPod to the device
181 */
182
183 /* RetDevCaps (0x0A)
184 *
185 * The device returns the current control state
186 * for the specified control type.
187 *
188 * Packet format (offset in buf[]: Description)
189 * 0x00: Lingo ID: Microphone Lingo, always 0x01
190 * 0x01: Command, always 0x0A
191 * 0x02: The control type
192 * 0x03: The control data
193 */
194 case 0x0A:
195 switch (buf[2])
196 {
197 case 0x01: /* stereo/mono line-in control */
198 case 0x02: /* recording level control */
199 case 0x03: /* recording level limiter control */
200 break;
201 }
202 break;
203
204 /* SetDevCtrl (0x0B)
205 *
206 * Sent from the iPod to the device
207 */
208
209 /* The default response is IAP_ACK_BAD_PARAM */
210 default:
211 {
212#ifdef LOGF_ENABLE
213 logf("iap: Unsupported Mode1 Command");
214#endif
215 break;
216 }
217 }
218}