From bd7a5606d22c5d0a30d4dc692f60112053c5453e Mon Sep 17 00:00:00 2001 From: aeb Date: Thu, 16 Mar 2000 22:22:05 +0000 Subject: [PATCH] Added FCP monitoring test. git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@15 53a565d1-3bb7-0310-b661-cf11e63c67ab --- src/fcp.c | 8 ++++---- src/testlibraw.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/fcp.c b/src/fcp.c index e3c0800..2c56027 100644 --- a/src/fcp.c +++ b/src/fcp.c @@ -6,7 +6,7 @@ #include "kernel-raw1394.h" #include "raw1394_private.h" -static int do_fcp_listen(struct raw1394_handle *handle) +static int do_fcp_listen(struct raw1394_handle *handle, int startstop) { struct sync_cb_data sd = { 0, 0 }; struct raw1394_reqhandle rh = { (req_callback_t)_raw1394_sync_cb, &sd }; @@ -16,7 +16,7 @@ static int do_fcp_listen(struct raw1394_handle *handle) CLEAR_REQ(req); req->type = RAW1394_REQ_FCP_LISTEN; req->generation = handle->generation; - req->misc = 0; + req->misc = startstop; req->tag = (unsigned long)&rh; req->recvb = handle->buffer; req->length = 512; @@ -44,10 +44,10 @@ static int do_fcp_listen(struct raw1394_handle *handle) int raw1394_start_fcp_listen(struct raw1394_handle *handle) { - return do_fcp_listen(handle); + return do_fcp_listen(handle, 1); } int raw1394_stop_fcp_listen(struct raw1394_handle *handle) { - return do_fcp_listen(handle); + return do_fcp_listen(handle, 0); } diff --git a/src/testlibraw.c b/src/testlibraw.c index f1128dd..e18db62 100644 --- a/src/testlibraw.c +++ b/src/testlibraw.c @@ -1,6 +1,7 @@ #include #include +#include #include "raw1394.h" #include "csr.h" @@ -17,13 +18,12 @@ const char not_loaded[] = "\ This probably means that you don't have raw1394 support in the kernel or that you haven't loaded the raw1394 module.\n"; - quadlet_t buffer; int my_tag_handler(raw1394handle_t handle, unsigned long tag, int error) { if (error < 0) { - printf("completed with error %d\n", error); + printf("failed with error %d\n", error); } else { printf("completed with 0x%08x, value 0x%08x\n", error, buffer); } @@ -31,6 +31,20 @@ int my_tag_handler(raw1394handle_t handle, unsigned long tag, int error) return 0; } +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); + + while (length) { + printf(" %02x", *data); + data++; + length--; + } + + printf("\n"); +} int main(int argc, char **argv) @@ -41,7 +55,9 @@ int main(int argc, char **argv) tag_handler_t std_handler; int retval; - + + struct pollfd pfd; + unsigned char fcp_test[] = { 0x1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; handle = raw1394_get_handle(); @@ -115,5 +131,28 @@ int main(int argc, char **argv) } } + printf("\ntesting FCP monitoring on local node\n"); + raw1394_set_fcp_handler(handle, my_fcp_handler); + raw1394_start_fcp_listen(handle); + retval = raw1394_write(handle, raw1394_get_local_id(handle), + CSR_REGISTER_BASE + CSR_FCP_COMMAND, sizeof(fcp_test), + (quadlet_t *)fcp_test); + retval = raw1394_write(handle, raw1394_get_local_id(handle), + CSR_REGISTER_BASE + CSR_FCP_RESPONSE, sizeof(fcp_test), + (quadlet_t *)fcp_test); + + printf("\npolling for leftover messages\n"); + pfd.fd = raw1394_get_fd(handle); + pfd.events = POLLIN; + pfd.revents = 0; + while (1) { + if (poll(&pfd, 1, 10) < 1) break; + raw1394_loop_iterate(handle); + } + + if (retval < 0) { + perror("poll failed"); + } + exit(0); }