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
|
/*
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
*
* Copyright (C) 1999,2000 Andreas Bombe
*
* 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.
*/
#include <config.h>
#include <unistd.h>
#include <byteswap.h>
#include "raw1394.h"
#include "kernel-raw1394.h"
#include "raw1394_private.h"
int raw1394_loop_iterate(struct raw1394_handle *handle)
{
struct raw1394_request *req = &handle->req;
int retval = 0, channel;
if (read(handle->fd, req, sizeof(*req)) < 0) {
return -1;
}
switch (req->type) {
case RAW1394_REQ_BUS_RESET:
handle->generation = req->generation;
if (handle->protocol_version == 3) {
handle->num_of_nodes = req->misc & 0xffff;
handle->local_id = req->misc >> 16;
} else {
handle->num_of_nodes = req->misc & 0xff;
handle->irm_id = ((req->misc >> 8) & 0xff) | 0xffc0;
handle->local_id = req->misc >> 16;
}
if (handle->bus_reset_handler) {
retval = handle->bus_reset_handler(handle);
}
break;
case RAW1394_REQ_ISO_RECEIVE:
channel = (handle->buffer[0] >> 8) & 0x3f;
#ifndef WORDS_BIGENDIAN
handle->buffer[0] = bswap_32(handle->buffer[0]);
#endif
if (handle->iso_handler[channel]) {
retval = handle->iso_handler[channel](handle, channel,
req->length,
handle->buffer);
}
break;
case RAW1394_REQ_FCP_REQUEST:
if (handle->fcp_handler) {
retval = handle->fcp_handler(handle, req->misc & 0xffff,
req->misc >> 16,
req->length,
(char *)handle->buffer);
}
break;
default:
if (handle->tag_handler) {
retval = handle->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;
old = handle->bus_reset_handler;
handle->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;
old = handle->tag_handler;
handle->tag_handler = new;
return old;
}
iso_handler_t raw1394_set_iso_handler(struct raw1394_handle *handle,
unsigned int channel, iso_handler_t new)
{
if (channel >= 64) {
return (iso_handler_t)-1;
}
if (new == NULL) {
iso_handler_t old = handle->iso_handler[channel];
handle->iso_handler[channel] = NULL;
return old;
}
if (handle->iso_handler[channel] != NULL) {
return (iso_handler_t)-1;
}
handle->iso_handler[channel] = new;
return NULL;
}
fcp_handler_t raw1394_set_fcp_handler(struct raw1394_handle *handle,
fcp_handler_t new)
{
fcp_handler_t old;
old = handle->fcp_handler;
handle->fcp_handler = new;
return old;
}
|