1 |
/* |
---|
2 |
* Copyright (C) 2007 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This library is free software; you can redistribute it and/or |
---|
10 |
* modify it under the terms of the GNU Lesser General Public |
---|
11 |
* License version 2.1, as published by the Free Software Foundation; |
---|
12 |
* |
---|
13 |
* This library is distributed in the hope that it will be useful, |
---|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 |
* Lesser General Public License for more details. |
---|
17 |
* |
---|
18 |
* You should have received a copy of the GNU Lesser General Public |
---|
19 |
* License along with this library; if not, write to the Free Software |
---|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
---|
21 |
* MA 02110-1301 USA |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#include "efc_cmd.h" |
---|
25 |
#include "efc_cmds_hardware.h" |
---|
26 |
|
---|
27 |
#include <netinet/in.h> |
---|
28 |
#include <iostream> |
---|
29 |
|
---|
30 |
using namespace std; |
---|
31 |
|
---|
32 |
namespace FireWorks { |
---|
33 |
|
---|
34 |
IMPL_DEBUG_MODULE( EfcCmd, EfcCmd, DEBUG_LEVEL_NORMAL ); |
---|
35 |
|
---|
36 |
// static int to keep track of the sequence index |
---|
37 |
uint32_t EfcCmd::m_seqnum = 1; |
---|
38 |
|
---|
39 |
EfcCmd::EfcCmd(uint32_t cat, uint32_t cmd) |
---|
40 |
: m_length ( 0 ) |
---|
41 |
, m_category_id ( cat ) |
---|
42 |
, m_command_id ( cmd ) |
---|
43 |
{ |
---|
44 |
memset(&m_header,0,sizeof(m_header)); |
---|
45 |
} |
---|
46 |
|
---|
47 |
EfcCmd::~EfcCmd() |
---|
48 |
{ |
---|
49 |
} |
---|
50 |
|
---|
51 |
bool |
---|
52 |
EfcCmd::serialize( Util::IOSSerialize& se ) |
---|
53 |
{ |
---|
54 |
bool result=true; |
---|
55 |
|
---|
56 |
result &= se.write(htonl(m_length), "EFC length"); |
---|
57 |
|
---|
58 |
unsigned int i=0; |
---|
59 |
|
---|
60 |
// assign the category and the command |
---|
61 |
m_header.category=m_category_id; |
---|
62 |
m_header.command=m_command_id; |
---|
63 |
|
---|
64 |
// set the sequence number |
---|
65 |
m_header.seqnum=m_seqnum++; |
---|
66 |
|
---|
67 |
// serialize the header |
---|
68 |
quadlet_t *header_as_quadlets=(quadlet_t *)&m_header; |
---|
69 |
result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header version"); i++; |
---|
70 |
result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header seqnum"); i++; |
---|
71 |
result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header category"); i++; |
---|
72 |
result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header command"); i++; |
---|
73 |
result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header return value"); i++; |
---|
74 |
|
---|
75 |
return result; |
---|
76 |
} |
---|
77 |
|
---|
78 |
bool |
---|
79 |
EfcCmd::deserialize( Util::IISDeserialize& de ) |
---|
80 |
{ |
---|
81 |
bool result=true; |
---|
82 |
|
---|
83 |
result &= de.read(&m_length); |
---|
84 |
m_length=ntohl(m_length); |
---|
85 |
|
---|
86 |
// read the EFC header |
---|
87 |
quadlet_t *header_as_quadlets=(quadlet_t *)&m_header; |
---|
88 |
for (unsigned int i=0; i<sizeof(m_header)/4; i++) { |
---|
89 |
result &= de.read((header_as_quadlets+i)); |
---|
90 |
*(header_as_quadlets+i)=ntohl(*(header_as_quadlets+i)); |
---|
91 |
} |
---|
92 |
|
---|
93 |
// check the EFC version |
---|
94 |
if(m_header.version > 1) { |
---|
95 |
debugError("Unsupported EFC version: %d\n", m_header.version); |
---|
96 |
return false; |
---|
97 |
} |
---|
98 |
|
---|
99 |
// check whether the category and command of the response are valid |
---|
100 |
if (m_header.category != m_category_id) { |
---|
101 |
debugError("Invalid category response: %d != %d", m_header.category, m_category_id); |
---|
102 |
return false; |
---|
103 |
} |
---|
104 |
if (m_header.command != m_command_id) { |
---|
105 |
debugError("Invalid command response: %d != %d", m_header.command, m_command_id); |
---|
106 |
return false; |
---|
107 |
} |
---|
108 |
|
---|
109 |
// // delete a previous command/response if present |
---|
110 |
// if(m_response) { |
---|
111 |
// delete m_response; |
---|
112 |
// m_response=NULL; |
---|
113 |
// } |
---|
114 |
// |
---|
115 |
// // now figure out what command it is |
---|
116 |
// switch (m_header.category) { |
---|
117 |
// case EFC_CAT_HARDWARE_INFO: |
---|
118 |
// switch(m_header.command) { |
---|
119 |
// case EFC_CMD_HW_HWINFO_GET_CAPS: |
---|
120 |
// m_response=new EfcHardwareInfoCmd(); |
---|
121 |
// if (!m_response) { |
---|
122 |
// debugError("Could not allocate response\n"); |
---|
123 |
// return false; |
---|
124 |
// } |
---|
125 |
// result &= m_command->deserialize( de ); |
---|
126 |
// case EFC_CMD_HW_GET_POLLED: |
---|
127 |
// debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command); |
---|
128 |
// return false; |
---|
129 |
// case EFC_CMD_HW_SET_EFR_ADDRESS: |
---|
130 |
// debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command); |
---|
131 |
// return false; |
---|
132 |
// case EFC_CMD_HW_READ_SESSION_BLOCK: |
---|
133 |
// debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command); |
---|
134 |
// return false; |
---|
135 |
// case EFC_CMD_HW_GET_DEBUG_INFO: |
---|
136 |
// debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command); |
---|
137 |
// return false; |
---|
138 |
// case EFC_CMD_HW_SET_DEBUG_TRACKING: |
---|
139 |
// debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command); |
---|
140 |
// return false; |
---|
141 |
// default: |
---|
142 |
// debugError("Invalid EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command); |
---|
143 |
// return false; |
---|
144 |
// } |
---|
145 |
// break; |
---|
146 |
// case EFC_CAT_FLASH: |
---|
147 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
148 |
// return false; |
---|
149 |
// case EFC_CAT_TRANSPORT: |
---|
150 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
151 |
// return false; |
---|
152 |
// case EFC_CAT_HARDWARE_CONTROL: |
---|
153 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
154 |
// return false; |
---|
155 |
// case EFC_CAT_PHYSICAL_OUTPUT_MIX: |
---|
156 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
157 |
// return false; |
---|
158 |
// case EFC_CAT_PHYSICAL_INPUT_MIX: |
---|
159 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
160 |
// return false; |
---|
161 |
// case EFC_CAT_PLAYBACK_MIX: |
---|
162 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
163 |
// return false; |
---|
164 |
// case EFC_CAT_RECORD_MIX: |
---|
165 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
166 |
// return false; |
---|
167 |
// case EFC_CAT_MONITOR_MIX: |
---|
168 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
169 |
// return false; |
---|
170 |
// case EFC_CAT_IO_CONFIG: |
---|
171 |
// debugError("Unsupported EFC category: %d\n", m_header.category); |
---|
172 |
// return false; |
---|
173 |
// default: |
---|
174 |
// debugError("Invalid EFC category: %d\n", m_header.category); |
---|
175 |
// return false; |
---|
176 |
// } |
---|
177 |
|
---|
178 |
return result; |
---|
179 |
} |
---|
180 |
|
---|
181 |
void |
---|
182 |
EfcCmd::showEfcCmd() |
---|
183 |
{ |
---|
184 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC Length: %d\n", m_length); |
---|
185 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC Header:\n"); |
---|
186 |
debugOutput(DEBUG_LEVEL_NORMAL, " Version : 0x%08X\n", m_header.version); |
---|
187 |
debugOutput(DEBUG_LEVEL_NORMAL, " Sequence number : 0x%08X\n", m_header.seqnum); |
---|
188 |
debugOutput(DEBUG_LEVEL_NORMAL, " Category : 0x%08X\n", m_header.category); |
---|
189 |
debugOutput(DEBUG_LEVEL_NORMAL, " Command : 0x%08X\n", m_header.command); |
---|
190 |
debugOutput(DEBUG_LEVEL_NORMAL, " Return Value : 0x%08X\n", m_header.retval); |
---|
191 |
} |
---|
192 |
|
---|
193 |
} // namespace FireWorks |
---|