1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/*
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
*
* Copyright (C) 1999,2000,2001,2002 Andreas Bombe
* 2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
* 2002 Christian Toegel <christian.toegel@gmx.at>
* Copyright (C) 2022 Peter McGoron <code@mcgoron.com>
*
* This library is licensed under the GNU Lesser General Public License (LGPL),
* version 2.1 or later. See the file COPYING.LIB in the distribution for
* details.
*
*
* Contributions:
*
* Manfred Weihs <weihs@ict.tuwien.ac.at>
* address range mapping
* Christian Toegel <christian.toegel@gmx.at>
* address range mapping
*/
#include <config.h>
#include <unistd.h>
#include <byteswap.h>
#include <errno.h>
#include "raw1394.h"
#include "kernel-raw1394.h"
#include "raw1394_private.h"
int ieee1394_loop_iterate(struct raw1394_handle *handle)
{
struct raw1394_request req;
ieee1394handle_t ihandle = handle->mode.ieee1394;
int retval = 0;
while (read(ihandle->fd, &req, sizeof(req)) < 0) {
if (errno != EINTR) return -1;
}
switch (req.type) {
case RAW1394_REQ_BUS_RESET:
if (ihandle->protocol_version == 3) {
ihandle->num_of_nodes = req.misc & 0xffff;
ihandle->local_id = req.misc >> 16;
} else {
ihandle->num_of_nodes = req.misc & 0xff;
ihandle->irm_id = ((req.misc >> 8) & 0xff) | 0xffc0;
ihandle->local_id = req.misc >> 16;
}
if (ihandle->bus_reset_handler) {
retval = ihandle->bus_reset_handler(handle,
req.generation);
}
break;
case RAW1394_REQ_FCP_REQUEST:
if (ihandle->fcp_handler) {
retval = ihandle->fcp_handler(handle, req.misc & 0xffff,
req.misc >> 16,
req.length,
(unsigned char *)ihandle->buffer);
}
break;
case RAW1394_REQ_ARM:
/* FIXME: implement new ARM for raw1394 */
#if 0
if (ihandle->arm_tag_handler) {
retval = ihandle->arm_tag_handler(handle, req.tag,
(req.misc & (0xFF)),
((req.misc >> 16) & (0xFFFF)),
int2ptr(req.recvb));
}
#endif
break;
case RAW1394_REQ_ECHO:
retval=req.misc;
break;
case RAW1394_REQ_RAWISO_ACTIVITY:
retval = _ieee1394_iso_iterate(handle);
break;
default:
if (ihandle->tag_handler) {
retval = ihandle->tag_handler(handle, req.tag,
req.error);
}
break;
}
return retval;
}
bus_reset_handler_t raw1394_set_bus_reset_handler(struct raw1394_handle *handle,
bus_reset_handler_t new)
{
bus_reset_handler_t old;
if (!handle) {
errno = EINVAL;
return NULL;
}
if (handle->is_fw) {
old = handle->mode.fw->bus_reset_handler;
handle->mode.fw->bus_reset_handler = new;
}
else {
old = handle->mode.ieee1394->bus_reset_handler;
handle->mode.ieee1394->bus_reset_handler = new;
}
return old;
}
tag_handler_t raw1394_set_tag_handler(struct raw1394_handle *handle,
tag_handler_t new)
{
tag_handler_t old;
if (!handle) {
errno = EINVAL;
return NULL;
}
if (handle->is_fw) {
old = handle->mode.fw->tag_handler;
handle->mode.fw->tag_handler = new;
}
else {
old = handle->mode.ieee1394->tag_handler;
handle->mode.ieee1394->tag_handler = new;
}
return old;
}
arm_tag_handler_t raw1394_set_arm_tag_handler(struct raw1394_handle *handle,
arm_tag_handler_t new)
{
arm_tag_handler_t old;
if (!handle) {
errno = EINVAL;
return NULL;
}
if (handle->is_fw) {
old = handle->mode.fw->arm_tag_handler;
handle->mode.fw->arm_tag_handler = new;
}
else {
old = handle->mode.ieee1394->arm_tag_handler;
handle->mode.ieee1394->arm_tag_handler = new;
}
return old;
}
fcp_handler_t raw1394_set_fcp_handler(struct raw1394_handle *handle,
fcp_handler_t new)
{
fcp_handler_t old;
if (!handle) {
errno = EINVAL;
return NULL;
}
if (handle->is_fw) {
old = handle->mode.fw->fcp_handler;
handle->mode.fw->fcp_handler = new;
}
else {
old = handle->mode.ieee1394->fcp_handler;
handle->mode.ieee1394->fcp_handler = new;
}
return old;
}
|