You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libraw1394/libraw1394-2.0.0-git-update...

994 lines
29 KiB

Makefile.am | 23 ----
src/arm.c | 2 -
src/dispatch.c | 102 ++++++++++---------
src/eventloop.c | 2 +-
src/fw-iso.c | 40 ++++++--
src/fw.c | 143 +++++---------------------
src/fw.h | 7 +-
src/main.c | 2 -
src/raw1394.h | 2 +-
tools/testlibraw.c | 285 ++++++++++++++++++++++++++++++----------------------
10 files changed, 279 insertions(+), 329 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index f48af74..bf094f0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,28 +23,5 @@ htmldoc:
.PHONY: doc psdoc pdfdoc htmldoc
-# make required device file
-dev:
- mknod -m 600 /dev/raw1394 c 171 0
- chown root.root /dev/raw1394
- @echo
- @echo "/dev/raw1394 created"
- @echo "It is owned by root with permissions 600. You may want to fix"
- @echo "the group/permission to something appropriate for you."
- @echo "Note however that anyone who can open raw1394 can access all"
- @echo "devices on all connected 1394 buses unrestricted, including"
- @echo "harddisks and other probably sensitive devices."
- @echo
-
-install-exec-hook:
- @if [ ! -c /dev/raw1394 ]; then \
- echo; \
- echo "********************************************"; \
- echo "Required /dev/raw1394 device file not found."; \
- echo "Run 'make dev' to create it."; \
- echo "********************************************"; \
- echo; \
- fi
-
dist-hook:
git log >$(distdir)/ChangeLog
diff --git a/src/arm.c b/src/arm.c
index c523c00..27ad762 100644
--- a/src/arm.c
+++ b/src/arm.c
@@ -109,7 +109,6 @@ int ieee1394_arm_set_buf (struct ieee1394_handle *handle, nodeaddr_t start,
size_t length, void *buf)
{
struct raw1394_request req;
- int status;
CLEAR_REQ(&req);
@@ -139,7 +138,6 @@ int ieee1394_arm_get_buf (struct ieee1394_handle *handle, nodeaddr_t start,
size_t length, void *buf)
{
struct raw1394_request req;
- int status;
CLEAR_REQ(&req);
diff --git a/src/dispatch.c b/src/dispatch.c
index b15e8c5..49ceca2 100644
--- a/src/dispatch.c
+++ b/src/dispatch.c
@@ -24,33 +24,35 @@ int raw1394_errcode_to_errno(raw1394_errcode_t errcode)
raw1394handle_t raw1394_new_handle(void)
{
- ieee1394handle_t ieee1394_handle = ieee1394_new_handle();
- fw_handle_t fw_handle = NULL;
- raw1394handle_t handle = NULL;
+ ieee1394handle_t ieee1394_handle;
+ fw_handle_t fw_handle;
+ raw1394handle_t handle;
+ struct raw1394_portinfo port;
- if (ieee1394_handle) {
- struct raw1394_portinfo port;
- if (ieee1394_get_port_info(ieee1394_handle, &port, 1) < 1) {
- ieee1394_destroy_handle(ieee1394_handle);
- ieee1394_handle = NULL;
- fw_handle = fw_new_handle();
- }
- }
- else {
- fw_handle = fw_new_handle();
- }
- if (ieee1394_handle || fw_handle) {
- handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
- if (ieee1394_handle && handle) {
- handle->is_fw = 0;
- handle->mode.ieee1394 = ieee1394_handle;
- }
- else if (handle) {
- handle->is_fw = 1;
- handle->mode.fw = fw_handle;
- }
- }
- return handle;
+ handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
+ if (!handle)
+ return NULL;
+
+ ieee1394_handle = ieee1394_new_handle();
+ if (!ieee1394_handle)
+ goto try_fw;
+
+ if (ieee1394_get_port_info(ieee1394_handle, &port, 1) >= 1) {
+ handle->is_fw = 0;
+ handle->mode.ieee1394 = ieee1394_handle;
+ return handle;
+ }
+ ieee1394_destroy_handle(ieee1394_handle);
+try_fw:
+ fw_handle = fw_new_handle();
+ if (fw_handle) {
+ handle->is_fw = 1;
+ handle->mode.fw = fw_handle;
+ return handle;
+ }
+
+ free(handle);
+ return NULL;
}
void raw1394_destroy_handle(raw1394handle_t handle)
@@ -61,30 +63,36 @@ void raw1394_destroy_handle(raw1394handle_t handle)
if (handle->is_fw)
fw_destroy_handle(handle->mode.fw);
else
- ieee1394_destroy_handle(handle->mode.ieee1394);;
+ ieee1394_destroy_handle(handle->mode.ieee1394);
+ free(handle);
}
raw1394handle_t raw1394_new_handle_on_port(int port)
{
- ieee1394handle_t ieee1394_handle = ieee1394_new_handle_on_port(port);
- fw_handle_t fw_handle = NULL;
- raw1394handle_t handle = NULL;
+ ieee1394handle_t ieee1394_handle;
+ fw_handle_t fw_handle;
+ raw1394handle_t handle;
+
+ handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
+ if (!handle)
+ return NULL;
+ ieee1394_handle = ieee1394_new_handle_on_port(port);
if (ieee1394_handle) {
- handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
- if (handle) {
- handle->is_fw = 0;
- handle->mode.ieee1394 = ieee1394_handle;
- }
+ handle->is_fw = 0;
+ handle->mode.ieee1394 = ieee1394_handle;
+ return handle;
}
- else if (fw_handle = fw_new_handle_on_port(port)) {
- handle = (raw1394handle_t) malloc(sizeof(struct raw1394_handle));
- if (handle) {
- handle->is_fw = 1;
- handle->mode.fw = fw_handle;
- }
+
+ fw_handle = fw_new_handle_on_port(port);
+ if (fw_handle) {
+ handle->is_fw = 1;
+ handle->mode.fw = fw_handle;
+ return handle;
}
- return handle;
+
+ free(handle);
+ return NULL;
}
int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch)
@@ -533,10 +541,7 @@ int raw1394_bandwidth_modify (raw1394handle_t handle, unsigned int bandwidth,
errno = EINVAL;
return -1;
}
- if (handle->is_fw)
- return fw_bandwidth_modify(handle, bandwidth, mode);
- else
- return ieee1394_bandwidth_modify(handle, bandwidth, mode);
+ return ieee1394_bandwidth_modify(handle, bandwidth, mode);
}
int raw1394_channel_modify (raw1394handle_t handle, unsigned int channel,
@@ -546,10 +551,7 @@ int raw1394_channel_modify (raw1394handle_t handle, unsigned int channel,
errno = EINVAL;
return -1;
}
- if (handle->is_fw)
- return fw_channel_modify(handle, channel, mode);
- else
- return ieee1394_channel_modify(handle, channel, mode);
+ return ieee1394_channel_modify(handle, channel, mode);
}
int raw1394_iso_xmit_init(raw1394handle_t handle,
diff --git a/src/eventloop.c b/src/eventloop.c
index 43a9519..81bb881 100644
--- a/src/eventloop.c
+++ b/src/eventloop.c
@@ -32,7 +32,7 @@ int ieee1394_loop_iterate(struct raw1394_handle *handle)
{
struct raw1394_request req;
ieee1394handle_t ihandle = handle->mode.ieee1394;
- int retval = 0, channel;
+ int retval = 0;
while (read(ihandle->fd, &req, sizeof(req)) < 0) {
if (errno != EINTR) return -1;
diff --git a/src/fw-iso.c b/src/fw-iso.c
index f493444..6a84662 100644
--- a/src/fw-iso.c
+++ b/src/fw-iso.c
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 8 -*-
*
- * raw1394-iso.c -- Emulation of the raw1394 rawiso API on the firewire stack
+ * fw-iso.c -- Emulation of the raw1394 rawiso API on the firewire stack
*
* Copyright (C) 2007 Kristian Hoegsberg <krh@bitplanet.net>
*
@@ -76,6 +76,7 @@ queue_packet(fw_handle_t handle,
if (err < 0)
return -1;
}
+ return 0;
}
static int
@@ -84,7 +85,9 @@ queue_xmit_packets(raw1394handle_t handle, int limit)
fw_handle_t fwhandle = handle->mode.fw;
enum raw1394_iso_disposition d;
unsigned char tag, sy;
- int len, cycle, dropped;
+ unsigned int len;
+ int cycle = -1;
+ unsigned int dropped = 0;
if (fwhandle->iso.xmit_handler == NULL)
return 0;
@@ -138,7 +141,14 @@ int fw_iso_xmit_start(raw1394handle_t handle, int start_on_cycle,
return retval;
}
- return queue_xmit_packets(handle, fwhandle->iso.buf_packets);
+ retval = queue_xmit_packets(handle, fwhandle->iso.buf_packets);
+
+ if (retval)
+ return -1;
+ else
+ fwhandle->iso.state = ISO_ACTIVE;
+
+ return 0;
}
static int
@@ -221,7 +231,12 @@ int fw_iso_recv_start(fw_handle_t handle, int start_on_cycle,
start_iso.sync = 0;
start_iso.handle = 0;
- return ioctl(handle->iso.fd, FW_CDEV_IOC_START_ISO, &start_iso);
+ if (ioctl(handle->iso.fd, FW_CDEV_IOC_START_ISO, &start_iso))
+ return -1;
+ else
+ handle->iso.state = ISO_ACTIVE;
+
+ return 0;
}
static int handle_iso_event(raw1394handle_t handle,
@@ -256,9 +271,8 @@ int fw_iso_xmit_write(raw1394handle_t handle, unsigned char *data,
unsigned char sy)
{
fw_handle_t fwhandle = handle->mode.fw;
- struct fw_cdev_queue_iso queue_iso;
struct fw_cdev_start_iso start_iso;
- struct fw_cdev_iso_packet *p;
+ int retval;
if (len > fwhandle->iso.max_packet_size) {
errno = EINVAL;
@@ -283,10 +297,10 @@ int fw_iso_xmit_write(raw1394handle_t handle, unsigned char *data,
start_iso.cycle = fwhandle->iso.start_on_cycle;
start_iso.handle = 0;
- len = ioctl(fwhandle->iso.fd,
+ retval = ioctl(fwhandle->iso.fd,
FW_CDEV_IOC_START_ISO, &start_iso);
- if (len < 0)
- return len;
+ if (retval < 0)
+ return retval;
}
return 0;
@@ -443,6 +457,7 @@ iso_init(fw_handle_t handle, int type,
handle->iso.head = handle->iso.buffer;
handle->iso.tail = handle->iso.buffer;
handle->iso.first_payload = handle->iso.buffer;
+ handle->iso.state = ISO_STOPPED;
return 0;
}
@@ -519,15 +534,20 @@ void fw_iso_stop(fw_handle_t handle)
handle->iso.first_payload = handle->iso.buffer;
handle->iso.packet_phase = 0;
handle->iso.packet_count = 0;
+ handle->iso.packet_index = 0;
+ handle->iso.state = ISO_STOPPED;
}
void fw_iso_shutdown(fw_handle_t handle)
{
munmap(handle->iso.buffer,
handle->iso.buf_packets * handle->iso.max_packet_size);
+ if (handle->iso.state != ISO_STOPPED)
+ fw_iso_stop(handle);
close(handle->iso.fd);
free(handle->iso.packets);
handle->iso.packets = NULL;
+ handle->iso.fd = -1;
}
int fw_read_cycle_timer(fw_handle_t handle,
@@ -537,7 +557,7 @@ int fw_read_cycle_timer(fw_handle_t handle,
int err;
struct fw_cdev_get_cycle_timer ctr = { 0 };
- err = ioctl(handle->iso.fd, FW_CDEV_IOC_GET_CYCLE_TIMER, &ctr);
+ err = ioctl(handle->local_fd, FW_CDEV_IOC_GET_CYCLE_TIMER, &ctr);
if (!err) {
*cycle_timer = ctr.cycle_timer;
*local_time = ctr.local_time;
diff --git a/src/fw.c b/src/fw.c
index 3c61385..03e34a7 100644
--- a/src/fw.c
+++ b/src/fw.c
@@ -125,7 +125,7 @@ scan_devices(fw_handle_t handle)
char filename[32];
struct fw_cdev_get_info get_info;
struct fw_cdev_event_bus_reset reset;
- int fd, err, i;
+ int fd, err, i, fname_str_sz;
struct port *ports;
ports = handle->ports;
@@ -162,8 +162,9 @@ scan_devices(fw_handle_t handle)
continue;
if (i < MAX_PORTS && reset.node_id == reset.local_node_id) {
- strncpy(ports[i].device_file, filename,
- sizeof ports[i].device_file);
+ fname_str_sz = sizeof(ports[i].device_file) - 1;
+ strncpy(ports[i].device_file, filename, fname_str_sz);
+ ports[i].device_file[fname_str_sz] = '\0';
ports[i].node_count = (reset.root_node_id & 0x3f) + 1;
ports[i].card = get_info.card;
i++;
@@ -315,7 +316,7 @@ handle_inotify(raw1394handle_t handle, struct epoll_closure *ec,
struct fw_cdev_get_info info;
struct fw_cdev_event_bus_reset reset;
struct epoll_event ep;
- int i, len, fd, phy_id;
+ int i, len, fd, phy_id, fname_str_sz;
event = (struct inotify_event *) fwhandle->buffer;
len = read(fwhandle->inotify_fd, event, BUFFER_SIZE);
@@ -365,8 +366,9 @@ handle_inotify(raw1394handle_t handle, struct epoll_closure *ec,
fwhandle->devices[i].node_id = reset.node_id;
fwhandle->devices[i].generation = reset.generation;
fwhandle->devices[i].fd = fd;
- strncpy(fwhandle->devices[i].filename, filename,
- sizeof fwhandle->devices[i].filename);
+ fname_str_sz = sizeof(fwhandle->devices[i].filename) - 1;
+ strncpy(fwhandle->devices[i].filename, filename, fname_str_sz);
+ fwhandle->devices[i].filename[fname_str_sz] = '\0';
fwhandle->devices[i].closure.func = handle_device_event;
ep.events = EPOLLIN;
ep.data.ptr = &fwhandle->devices[i].closure;
@@ -501,8 +503,10 @@ fw_handle_t fw_new_handle_on_port(int port)
if (handle == NULL)
return NULL;
- if (fw_set_port(handle, port) < 0)
+ if (fw_set_port(handle, port) < 0) {
+ fw_destroy_handle(handle);
return NULL;
+ }
return handle;
}
@@ -538,15 +542,17 @@ int fw_get_port_info(fw_handle_t handle,
struct raw1394_portinfo *pinf,
int maxports)
{
- int i;
+ int i, port_name_sz;
if (maxports >= handle->port_count)
maxports = handle->port_count;
for (i = 0; i < maxports; i++) {
pinf[i].nodes = handle->ports[i].node_count;
+ port_name_sz = sizeof(pinf[i].name) - 1;
strncpy(pinf[i].name, handle->ports[i].device_file,
- sizeof pinf[i].name);
+ port_name_sz);
+ pinf[i].name[port_name_sz] = '\0';
}
return handle->port_count;
@@ -560,7 +566,7 @@ int fw_set_port(fw_handle_t handle, int port)
struct dirent *de;
char filename[32];
DIR *dir;
- int i, fd, phy_id;
+ int i, fd, phy_id, fname_str_sz;
if (port >= handle->port_count) {
errno = EINVAL;
@@ -606,8 +612,9 @@ int fw_set_port(fw_handle_t handle, int port)
handle->devices[i].node_id = reset.node_id;
handle->devices[i].generation = reset.generation;
handle->devices[i].fd = fd;
- strncpy(handle->devices[i].filename, filename,
- sizeof handle->devices[i].filename);
+ fname_str_sz = sizeof(handle->devices[i].filename) -1;
+ strncpy(handle->devices[i].filename, filename, fname_str_sz);
+ handle->devices[i].filename[fname_str_sz] = '\0';
handle->devices[i].closure.func = handle_device_event;
memset(&ep, 0, sizeof(ep));
@@ -623,8 +630,9 @@ int fw_set_port(fw_handle_t handle, int port)
if (reset.node_id == reset.local_node_id) {
memcpy(&handle->reset, &reset, sizeof handle->reset);
handle->local_fd = fd;
- strncpy(handle->local_filename, filename,
- sizeof handle->local_filename);
+ fname_str_sz = sizeof(handle->local_filename) -1;
+ strncpy(handle->local_filename, filename, fname_str_sz);
+ handle->local_filename[fname_str_sz] = '\0';
}
i++;
@@ -765,10 +773,12 @@ handle_arm_request(raw1394handle_t handle, struct address_closure *ac,
}
rrb->request.generation = fwhandle->reset.generation;
rrb->request.buffer_length = in_length;
+ rrb->request.buffer = rrb->data;
memcpy(rrb->request.buffer, request->data, in_length);
rrb->response.response_code = response.rcode;
rrb->response.buffer_length = response.length;
+ rrb->response.buffer = rrb->data + in_length;
memcpy(rrb->response.buffer,
allocation->data + offset, response.length);
@@ -1174,14 +1184,14 @@ fw_lock(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
quadlet_t *result)
{
quadlet_t buffer[2];
- size_t length;
+ ssize_t length;
length = setup_lock(extcode, data, arg, buffer);
if (length < 0)
return length;
return send_request_sync(handle, 16 + extcode, node, addr,
- length, buffer, result);
+ (size_t) length, buffer, result);
}
int
@@ -1190,14 +1200,14 @@ fw_lock64(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
octlet_t *result)
{
octlet_t buffer[2];
- size_t length;
+ ssize_t length;
length = setup_lock64(extcode, data, arg, buffer);
if (length < 0)
return length;
return send_request_sync(handle, 16 + extcode, node, addr,
- length, buffer, result);
+ (size_t) length, buffer, result);
}
int
@@ -1283,100 +1293,3 @@ fw_get_config_rom(fw_handle_t handle, quadlet_t *buffer,
return 0;
}
-
-#define MAXIMUM_BANDWIDTH 4915
-
-int
-fw_bandwidth_modify (raw1394handle_t handle,
- unsigned int bandwidth,
- enum raw1394_modify_mode mode)
-{
- quadlet_t buffer, compare, swap;
- nodeaddr_t addr;
- int result;
-
- if (bandwidth == 0)
- return 0;
-
- addr = CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE;
- /* Read current bandwidth usage from IRM. */
- result = raw1394_read (handle, raw1394_get_irm_id (handle), addr,
- sizeof buffer, &buffer);
- if (result < 0)
- return -1;
-
- compare = ntohl (buffer);
- switch (mode) {
- case RAW1394_MODIFY_ALLOC:
- swap = compare - bandwidth;
- if (swap < 0)
- return -1;
- break;
-
- case RAW1394_MODIFY_FREE:
- swap = compare + bandwidth;
- if (swap > MAXIMUM_BANDWIDTH)
- swap = MAXIMUM_BANDWIDTH;
- break;
-
- default:
- return -1;
- }
-
- result = raw1394_lock(handle, raw1394_get_irm_id (handle), addr,
- RAW1394_EXTCODE_COMPARE_SWAP,
- htonl(swap), htonl(compare), &buffer);
- if (result < 0 || ntohl(buffer) != compare)
- return -1;
-
- return 0;
-}
-
-int
-fw_channel_modify (raw1394handle_t handle,
- unsigned int channel,
- enum raw1394_modify_mode mode)
-{
- quadlet_t buffer, compare, swap, bit;
- nodeaddr_t addr;
- int result;
-
- if (channel >= 64)
- return -1;
- addr = CSR_REGISTER_BASE +
- CSR_CHANNELS_AVAILABLE_HI + 4 * (channel / 32);
- /* Read currently available channels from IRM. */
- result = raw1394_read(handle, raw1394_get_irm_id (handle), addr,
- sizeof buffer, &buffer);
- if (result < 0)
- return -1;
-
- /* IEEE numbers bits from MSB (0) to LSB (31). */
- bit = 1 << (31 - (channel & 31));
- compare = ntohl(buffer);
- switch (mode) {
- case RAW1394_MODIFY_ALLOC:
- if ((compare & bit) == 0)
- return -1;
- swap = buffer & ~bit;
- break;
-
- case RAW1394_MODIFY_FREE:
- if ((buffer & bit) != 0)
- return -1;
- swap = buffer | bit;
- break;
-
- default:
- return -1;
- }
-
- result = raw1394_lock (handle, raw1394_get_irm_id (handle), addr,
- RAW1394_EXTCODE_COMPARE_SWAP,
- htonl(swap), htonl(compare), &buffer);
-
- if (result < 0 || ntohl(buffer) != compare)
- return -1;
-
- return 0;
-}
diff --git a/src/fw.h b/src/fw.h
index 4ee9017..56b59d9 100644
--- a/src/fw.h
+++ b/src/fw.h
@@ -129,6 +129,7 @@ struct fw_handle {
int prebuffer;
int start_on_cycle;
enum raw1394_iso_dma_recv_mode recv_mode;
+ enum { ISO_STOPPED, ISO_ACTIVE } state;
raw1394_iso_xmit_handler_t xmit_handler;
raw1394_iso_recv_handler_t recv_handler;
unsigned char *buffer, *buffer_end, *head;
@@ -211,12 +212,6 @@ int fw_update_config_rom(fw_handle_t handle, const quadlet_t *new_rom,
int fw_get_config_rom(fw_handle_t handle, quadlet_t *buffer,
size_t buffersize, size_t *rom_size,
unsigned char *rom_version);
-int fw_bandwidth_modify (raw1394handle_t handle,
- unsigned int bandwidth,
- enum raw1394_modify_mode mode);
-int fw_channel_modify (raw1394handle_t handle,
- unsigned int channel,
- enum raw1394_modify_mode mode);
int fw_iso_xmit_start(raw1394handle_t handle, int start_on_cycle,
int prebuffer_packets);
diff --git a/src/main.c b/src/main.c
index 55b4fbc..d83256e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -253,9 +253,7 @@ void *raw1394_get_userdata(struct raw1394_handle *handle)
int ieee1394_get_port_info(struct ieee1394_handle *handle,
struct raw1394_portinfo *pinf, int maxports)
{
- int num;
struct raw1394_request req;
- struct raw1394_khost_list *khl;
CLEAR_REQ(&req);
req.type = RAW1394_REQ_LIST_CARDS;
diff --git a/src/raw1394.h b/src/raw1394.h
index c489c20..7bfeb05 100644
--- a/src/raw1394.h
+++ b/src/raw1394.h
@@ -1203,7 +1203,7 @@ raw1394_bandwidth_modify (raw1394handle_t handle, unsigned int bandwidth,
enum raw1394_modify_mode mode);
/**
- * raw1394_bandwidth_modify - allocate or release isochronous channel
+ * raw1394_channel_modify - allocate or release isochronous channel
* @handle: a libraw1394 handle
* @channel: isochronous channel
* @mode: whether to allocate or free
diff --git a/tools/testlibraw.c b/tools/testlibraw.c
index efd87ad..82b8ee5 100644
--- a/tools/testlibraw.c
+++ b/tools/testlibraw.c
@@ -14,6 +14,7 @@
#include <string.h>
#include <sys/poll.h>
#include <stdlib.h>
+#include <time.h>
#include <arpa/inet.h>
#include "../src/raw1394.h"
@@ -53,8 +54,8 @@ static const unsigned char fcp_data[] =
int my_fcp_handler(raw1394handle_t handle, nodeid_t nodeid, int response,
size_t length, unsigned char *data)
{
- printf("got fcp %s from node %d of %d bytes:",
- (response ? "response" : "command"), nodeid & 0x3f, length);
+ printf(" got fcp %s from node %d of %d bytes:",
+ (response ? "response" : "command"), nodeid & 0x3f, length);
if (memcmp(fcp_data, data, sizeof fcp_data) != 0)
printf("ERROR: fcp payload not correct\n");
@@ -73,7 +74,7 @@ int my_fcp_handler(raw1394handle_t handle, nodeid_t nodeid, int response,
static void
test_fcp(raw1394handle_t handle)
{
- printf("\ntesting FCP monitoring on local node\n");
+ printf("\n - testing FCP monitoring on local node\n");
raw1394_set_fcp_handler(handle, my_fcp_handler);
raw1394_start_fcp_listen(handle);
raw1394_write(handle, raw1394_get_local_id(handle),
@@ -95,142 +96,188 @@ read_topology_map(raw1394handle_t handle)
retval = raw1394_read(handle, local_id,
CSR_REGISTER_BASE + CSR_TOPOLOGY_MAP, 12, &map[0]);
- if (retval < 0)
- perror("topology map: raw1394_read failed with error");
-
+ if (retval < 0) {
+ perror("\n - topology map: raw1394_read failed with error");
+ return;
+ }
+
self_id_count = ntohl(map[2]) & 0xffff;
node_count = ntohl(map[2]) >> 16;
retval = raw1394_read(handle, local_id,
CSR_REGISTER_BASE + CSR_TOPOLOGY_MAP + 12,
self_id_count * sizeof map[0], &map[3]);
- if (retval < 0)
- perror("topology map: raw1394_read failed with error");
+ if (retval < 0) {
+ perror("\n - topology map: raw1394_read failed with error");
+ return;
+ }
- printf("topology map: %d nodes, %d self ids, generation %d\n",
+ printf("\n - topology map: %d nodes, %d self ids, generation %d\n",
node_count, self_id_count, ntohl(map[1]));
for (i = 0; i < self_id_count; i++)
- printf(" 0x%08x\n", ntohl(map[3 + i]));
+ printf(" 0x%08x\n", ntohl(map[3 + i]));
}
-int main(int argc, char **argv)
+static void
+test_config_rom(raw1394handle_t handle)
{
- raw1394handle_t handle;
- int i, numcards;
- struct raw1394_portinfo pinf[16];
-
- tag_handler_t std_handler;
- int retval;
-
- struct pollfd pfd;
- quadlet_t rom[0x100];
- size_t rom_size;
- unsigned char rom_version;
-
- handle = raw1394_new_handle();
-
- if (!handle) {
- if (!errno) {
- printf(not_compatible);
- } else {
- perror("couldn't get handle");
- printf(not_loaded);
- }
- exit(1);
- }
-
- printf("successfully got handle\n");
- printf("current generation number: %d\n", raw1394_get_generation(handle));
-
- numcards = raw1394_get_port_info(handle, pinf, 16);
- if (numcards < 0) {
- perror("couldn't get card info");
- exit(1);
- } else {
- printf("%d card(s) found\n", numcards);
- }
-
- if (!numcards) {
- exit(0);
- }
-
- for (i = 0; i < numcards; i++) {
- printf(" nodes on bus: %2d, card name: %s\n", pinf[i].nodes,
- pinf[i].name);
- }
-
- if (raw1394_set_port(handle, 0) < 0) {
- perror("couldn't set port");
- exit(1);
- }
+ quadlet_t rom[0x100] = { 0, };
+ size_t rom_size;
+ unsigned char rom_version;
+ int i, retval;
+
+ printf("\n - testing config rom\n");
+ retval = raw1394_get_config_rom(handle, rom, 0x100,
+ &rom_size, &rom_version);
+ printf(" get_config_rom returned %d, romsize %d, rom_version %d\n",
+ retval, rom_size, rom_version);
+ printf(" here are the first 10 quadlets:\n");
+ for (i = 0; i < 10; i++)
+ printf(" 0x%08x\n", i, rom[i]);
+
+ retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version);
+ printf(" update_config_rom returned %d\n", retval);
+}
- printf("using first card found: %d nodes on bus, local ID is %d, IRM is %d\n",
- raw1394_get_nodecount(handle),
- raw1394_get_local_id(handle) & 0x3f,
- raw1394_get_irm_id(handle) & 0x3f);
-
- printf("\ndoing transactions with custom tag handler\n");
- std_handler = raw1394_set_tag_handler(handle, my_tag_handler);
- for (i = 0; i < pinf[0].nodes; i++) {
- printf("trying to send read request to node %d... ", i);
- fflush(stdout);
- buffer = 0;
-
- if (raw1394_start_read(handle, 0xffc0 | i, TESTADDR, 4,
- &buffer, 0) < 0) {
- perror("failed");
- continue;
- }
- raw1394_loop_iterate(handle);
- }
+static void
+read_cycle_timer(raw1394handle_t handle)
+{
+ u_int32_t ct;
+ u_int64_t local_time;
+ time_t seconds;
+ int retval;
+
+ retval = raw1394_read_cycle_timer(handle, &ct, &local_time);
+ if (retval < 0) {
+ perror("\n - raw1394_read_cycle_timer failed with error");
+ return;
+ }
+
+ printf("\n - cycle timer: %d seconds, %d cycles, %d sub-cycles\n",
+ ct >> 25, (ct >> 12) & 0x1fff, ct & 0xfff);
+ seconds = local_time / 1000000;
+ printf(" local time: %lld us = %s",
+ (unsigned long long)local_time, ctime(&seconds));
+}
- printf("\nusing standard tag handler and synchronous calls\n");
- raw1394_set_tag_handler(handle, std_handler);
- for (i = 0; i < pinf[0].nodes; i++) {
- printf("trying to read from node %d... ", i);
- fflush(stdout);
- buffer = 0;
-
- retval = raw1394_read(handle, 0xffc0 | i, TESTADDR, 4, &buffer);
- if (retval < 0) {
- perror("failed with error");
- } else {
- printf("completed with value 0x%08x\n", buffer);
- }
- }
+int test_card(int card)
+{
+ raw1394handle_t handle;
+ struct raw1394_portinfo pinf;
+ tag_handler_t std_handler;
+ struct pollfd pfd;
+ int i, n, numcards, retval;
+
+ handle = raw1394_new_handle();
+
+ if (!handle) {
+ if (!errno) {
+ printf(not_compatible);
+ } else {
+ perror("couldn't get handle");
+ printf(not_loaded);
+ }
+ return -1;
+ }
+
+ if (card == 0) {
+ printf("successfully got handle\n");
+ printf("current generation number: %d\n",
+ raw1394_get_generation(handle));
+ }
+
+ numcards = raw1394_get_port_info(handle, &pinf, 1);
+ if (numcards < card)
+ perror("couldn't get card info");
+ else if (card == 0)
+ printf("%d card%s found\n",
+ numcards, numcards == 1 ? "" : "s");
+
+ if (numcards <= card)
+ goto out;
+
+ printf("\ncard %d, name: %s\n", card, pinf.name);
+
+ if (raw1394_set_port(handle, card) < 0) {
+ perror("couldn't set port");
+ goto out;
+ }
+
+ n = raw1394_get_nodecount(handle);
+ printf("%d nodes on bus, local ID is %d, IRM is %d\n",
+ n,
+ raw1394_get_local_id(handle) & 0x3f,
+ raw1394_get_irm_id(handle) & 0x3f);
+
+ if (n > 0) {
+ printf("\n - doing transactions with custom tag handler\n");
+ std_handler = raw1394_set_tag_handler(handle, my_tag_handler);
+ }
+ for (i = 0; i < n; i++) {
+ printf(" read from node %d... ", i);
+ fflush(stdout);
+ buffer = 0;
+
+ if (raw1394_start_read(handle, 0xffc0 | i, TESTADDR, 4,
+ &buffer, 0) < 0) {
+ perror("failed");
+ continue;
+ }
+ if (raw1394_loop_iterate(handle))
+ perror("failed");
+ }
+
+ if (n > 0) {
+ printf("\n - using standard tag handler and synchronous calls\n");
+ raw1394_set_tag_handler(handle, std_handler);
+ }
+ for (i = 0; i < n; i++) {
+ printf(" read from node %d... ", i);
+ fflush(stdout);
+ buffer = 0;
+
+ retval = raw1394_read(handle, 0xffc0 | i, TESTADDR, 4, &buffer);
+ if (retval < 0)
+ perror("failed with error");
+ else
+ printf("completed with value 0x%08x\n", buffer);
+ }
test_fcp(handle);
read_topology_map(handle);
+ test_config_rom(handle);
+ read_cycle_timer(handle);
- printf("testing config rom stuff\n");
- memset(rom, 0, sizeof(rom));
- retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version);
- printf("get_config_rom returned %d, romsize %d, rom_version %d\n",retval,rom_size,rom_version);
- printf("here are the first 10 quadlets:\n");
- for (i = 0; i < 10; i++)
- printf("%d. quadlet: 0x%08x\n",i,rom[i]);
-
- /* some manipulation */
-/* printf("incrementing 2nd quadlet\n");
- rom[0x02/4]++;
-*/
- retval=raw1394_update_config_rom(handle, rom, rom_size, rom_version);
- printf("update_config_rom returned %d\n",retval);
-
- printf("\nposting 0xdeadbeef as an echo request\n");
+ printf("\n - posting 0xdeadbeef as an echo request\n");
raw1394_echo_request(handle, 0xdeadbeef);
- printf("polling for leftover messages\n");
- pfd.fd = raw1394_get_fd(handle);
- pfd.events = POLLIN;
- pfd.revents = 0;
- while (1) {
- retval = poll(&pfd, 1, 10);
- if (retval < 1) break;
+ printf(" polling for leftover messages\n");
+ pfd.fd = raw1394_get_fd(handle);
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ while (1) {
+ retval = poll(&pfd, 1, 10);
+ if (retval < 1)
+ break;
retval = raw1394_loop_iterate(handle);
if (retval != 0)
- printf("raw1394_loop_iterate() returned 0x%08x\n", retval);
- }
+ printf(" raw1394_loop_iterate() returned 0x%08x\n",
+ retval);
+ }
+
+ if (retval < 0)
+ perror("poll failed");
+out:
+ raw1394_destroy_handle(handle);
+ return numcards;
+}
+
+int main(int argc, char **argv)
+{
+ int card = 0, numcards;
+
+ do
+ numcards = test_card(card);
+ while (++card < numcards);
- if (retval < 0) perror("poll failed");
- exit(0);
+ return numcards < 0;
}