1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* Copyright (C) 2005-2008 by Daniel Wagner |
---|
4 |
* |
---|
5 |
* This file is part of FFADO |
---|
6 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
7 |
* |
---|
8 |
* FFADO is based upon FreeBoB |
---|
9 |
* |
---|
10 |
* This program is free software: you can redistribute it and/or modify |
---|
11 |
* it under the terms of the GNU General Public License as published by |
---|
12 |
* the Free Software Foundation, either version 2 of the License, or |
---|
13 |
* (at your option) version 3 of the License. |
---|
14 |
* |
---|
15 |
* This program is distributed in the hope that it will be useful, |
---|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 |
* GNU General Public License for more details. |
---|
19 |
* |
---|
20 |
* You should have received a copy of the GNU General Public License |
---|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
22 |
* |
---|
23 |
*/ |
---|
24 |
|
---|
25 |
#include "avc_descriptor_cmd.h" |
---|
26 |
#include "avc_descriptor.h" |
---|
27 |
#include "libutil/cmd_serialize.h" |
---|
28 |
#include "libieee1394/ieee1394service.h" |
---|
29 |
|
---|
30 |
#include "libutil/ByteSwap.h" |
---|
31 |
#include <iostream> |
---|
32 |
#include <cstring> |
---|
33 |
|
---|
34 |
using namespace std; |
---|
35 |
|
---|
36 |
namespace AVC { |
---|
37 |
|
---|
38 |
OpenDescriptorCmd::OpenDescriptorCmd(Ieee1394Service& ieee1394service) |
---|
39 |
: AVCCommand( ieee1394service, AVC1394_CMD_OPEN_DESCRIPTOR ) |
---|
40 |
, m_specifier( NULL ) |
---|
41 |
, m_mode( eClose ) |
---|
42 |
, m_status ( 0xFF ) |
---|
43 |
, m_reserved ( 0x00 ) |
---|
44 |
, m_locked_node_id ( 0xFFFF ) |
---|
45 |
{ |
---|
46 |
} |
---|
47 |
|
---|
48 |
OpenDescriptorCmd::~OpenDescriptorCmd() |
---|
49 |
{ |
---|
50 |
} |
---|
51 |
|
---|
52 |
bool |
---|
53 |
OpenDescriptorCmd::clear() |
---|
54 |
{ |
---|
55 |
m_status = 0xFF; |
---|
56 |
m_reserved = 0x00; |
---|
57 |
m_locked_node_id = 0xFFFF; |
---|
58 |
return true; |
---|
59 |
} |
---|
60 |
|
---|
61 |
bool |
---|
62 |
OpenDescriptorCmd::serialize( Util::Cmd::IOSSerialize& se ) |
---|
63 |
{ |
---|
64 |
AVCCommand::serialize( se ); |
---|
65 |
|
---|
66 |
if(m_specifier==NULL) { |
---|
67 |
debugError("m_specifier==NULL\n"); |
---|
68 |
return false; |
---|
69 |
} |
---|
70 |
|
---|
71 |
m_specifier->serialize( se ); |
---|
72 |
|
---|
73 |
switch (getCommandType()) { |
---|
74 |
case eCT_Status: |
---|
75 |
se.write( (byte_t)m_status, "OpenDescriptorCmd status" ); |
---|
76 |
se.write( (byte_t)m_reserved, "OpenDescriptorCmd reserved" ); |
---|
77 |
se.write( (uint16_t)m_locked_node_id, "OpenDescriptorCmd node_id" ); |
---|
78 |
break; |
---|
79 |
case eCT_Control: |
---|
80 |
se.write( (byte_t)m_mode, "OpenDescriptorCmd subfunction" ); |
---|
81 |
se.write( (byte_t)m_reserved, "OpenDescriptorCmd reserved" ); |
---|
82 |
break; |
---|
83 |
default: |
---|
84 |
debugError("Unsupported type for this command: %02X\n", getCommandType()); |
---|
85 |
return false; |
---|
86 |
} |
---|
87 |
return true; |
---|
88 |
} |
---|
89 |
|
---|
90 |
bool |
---|
91 |
OpenDescriptorCmd::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
92 |
{ |
---|
93 |
AVCCommand::deserialize( de ); |
---|
94 |
|
---|
95 |
if(m_specifier==NULL) { |
---|
96 |
debugError("m_specifier==NULL\n"); |
---|
97 |
return false; |
---|
98 |
} |
---|
99 |
|
---|
100 |
m_specifier->deserialize( de ); |
---|
101 |
|
---|
102 |
switch ( getCommandType() ) { |
---|
103 |
case eCT_Status: |
---|
104 |
de.read( &m_status ); |
---|
105 |
de.read( &m_reserved ); |
---|
106 |
de.read( &m_locked_node_id ); |
---|
107 |
|
---|
108 |
break; |
---|
109 |
case eCT_Control: |
---|
110 |
de.read( &m_status ); |
---|
111 |
de.read( &m_reserved ); |
---|
112 |
switch (m_status) { |
---|
113 |
case (byte_t)eClose: m_mode=eClose; break; |
---|
114 |
case (byte_t)eRead: m_mode=eRead; break; |
---|
115 |
case (byte_t)eWrite: m_mode=eWrite; break; |
---|
116 |
default: |
---|
117 |
debugError("Unknown response subfunction 0x%02X\n", m_status); |
---|
118 |
} |
---|
119 |
|
---|
120 |
break; |
---|
121 |
default: |
---|
122 |
debugError("Can't handle command type %s\n", getCommandType()); |
---|
123 |
return false; |
---|
124 |
} |
---|
125 |
|
---|
126 |
|
---|
127 |
return true; |
---|
128 |
} |
---|
129 |
|
---|
130 |
// |
---|
131 |
|
---|
132 |
ReadDescriptorCmd::ReadDescriptorCmd(Ieee1394Service& ieee1394service) |
---|
133 |
: AVCCommand( ieee1394service, AVC1394_CMD_READ_DESCRIPTOR ) |
---|
134 |
, m_status ( 0xFF ) |
---|
135 |
, m_reserved ( 0xFF ) |
---|
136 |
, m_data_length ( 0 ) |
---|
137 |
, m_address ( 0 ) |
---|
138 |
, m_data ( NULL ) |
---|
139 |
, m_specifier( NULL ) |
---|
140 |
{ |
---|
141 |
} |
---|
142 |
|
---|
143 |
ReadDescriptorCmd::~ReadDescriptorCmd() |
---|
144 |
{ |
---|
145 |
delete[] m_data; |
---|
146 |
} |
---|
147 |
|
---|
148 |
bool |
---|
149 |
ReadDescriptorCmd::clear() |
---|
150 |
{ |
---|
151 |
m_status = 0xFF; |
---|
152 |
m_reserved = 0x00; |
---|
153 |
m_data_length = 0x0000; |
---|
154 |
m_address = 0x0000; |
---|
155 |
delete[] m_data; |
---|
156 |
m_data = NULL; |
---|
157 |
return true; |
---|
158 |
} |
---|
159 |
|
---|
160 |
bool |
---|
161 |
ReadDescriptorCmd::serialize( Util::Cmd::IOSSerialize& se ) |
---|
162 |
{ |
---|
163 |
AVCCommand::serialize( se ); |
---|
164 |
|
---|
165 |
if(m_specifier==NULL) { |
---|
166 |
debugError("m_specifier==NULL\n"); |
---|
167 |
return false; |
---|
168 |
} |
---|
169 |
|
---|
170 |
m_specifier->serialize( se ); |
---|
171 |
|
---|
172 |
switch (getCommandType()) { |
---|
173 |
case eCT_Control: |
---|
174 |
se.write( (byte_t)m_status, "ReadDescriptorCmd read_result_status" ); |
---|
175 |
se.write( (byte_t)m_reserved, "ReadDescriptorCmd reserved" ); |
---|
176 |
se.write( (uint16_t)m_data_length, "ReadDescriptorCmd data_length" ); |
---|
177 |
se.write( (uint16_t)m_address, "ReadDescriptorCmd address" ); |
---|
178 |
|
---|
179 |
break; |
---|
180 |
default: |
---|
181 |
debugError("Unsupported type for this command: %02X\n", getCommandType()); |
---|
182 |
return false; |
---|
183 |
} |
---|
184 |
return true; |
---|
185 |
} |
---|
186 |
|
---|
187 |
bool |
---|
188 |
ReadDescriptorCmd::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
189 |
{ |
---|
190 |
AVCCommand::deserialize( de ); |
---|
191 |
|
---|
192 |
if(m_specifier==NULL) { |
---|
193 |
debugError("m_specifier==NULL\n"); |
---|
194 |
return false; |
---|
195 |
} |
---|
196 |
|
---|
197 |
m_specifier->deserialize( de ); |
---|
198 |
|
---|
199 |
switch (getCommandType()) { |
---|
200 |
case eCT_Control: |
---|
201 |
de.read( (byte_t *)&m_status ); |
---|
202 |
de.read( (byte_t *)&m_reserved ); |
---|
203 |
de.read( (uint16_t *)&m_data_length ); |
---|
204 |
de.read( (uint16_t *)&m_address ); |
---|
205 |
|
---|
206 |
if (getResponse()==eR_Accepted) { |
---|
207 |
if (m_data_length>0) { |
---|
208 |
// the pointer returned by de.read is not valid outside this function |
---|
209 |
// hence we copy the data to an internal buffer |
---|
210 |
m_data = new byte_t[m_data_length]; |
---|
211 |
if(m_data == NULL) { |
---|
212 |
debugError("Could not allocate memory for payload data\n"); |
---|
213 |
return false; |
---|
214 |
} |
---|
215 |
char * cmd_data = NULL; |
---|
216 |
if (!de.read( (char **)&cmd_data, m_data_length )) { |
---|
217 |
delete[] m_data; |
---|
218 |
m_data = NULL; |
---|
219 |
debugError("Could not read payload data\n"); |
---|
220 |
return false; |
---|
221 |
} |
---|
222 |
memcpy(m_data, cmd_data, m_data_length); |
---|
223 |
|
---|
224 |
} else { |
---|
225 |
debugWarning("Read descriptor command accepted but no payload data returned.\n"); |
---|
226 |
m_data=NULL; |
---|
227 |
} |
---|
228 |
} |
---|
229 |
break; |
---|
230 |
default: |
---|
231 |
debugError("Unsupported type for this command: %02X\n", getCommandType()); |
---|
232 |
return false; |
---|
233 |
} |
---|
234 |
|
---|
235 |
return true; |
---|
236 |
} |
---|
237 |
|
---|
238 |
enum ReadDescriptorCmd::EReadStatus |
---|
239 |
ReadDescriptorCmd::getStatus() |
---|
240 |
{ |
---|
241 |
switch(m_status) { |
---|
242 |
case 0x10: return eComplete; |
---|
243 |
case 0x11: return eMoreToRead; |
---|
244 |
case 0x12: return eTooLarge; |
---|
245 |
default: return eInvalid; |
---|
246 |
} |
---|
247 |
} |
---|
248 |
|
---|
249 |
} |
---|