Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Oct 2008 09:37:14 -0700
From:      Sean Bruno <sbruno@miralink.com>
To:        freebsd@sopwith.solgatos.com
Cc:        freebsd-firewire@freebsd.org
Subject:   Re: patch for fwcontrol
Message-ID:  <4905EE3A.1050506@miralink.com>
In-Reply-To: <200809250040.AAA28891@sopwith.solgatos.com>
References:  <200809250040.AAA28891@sopwith.solgatos.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------090904020605060401030902
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Dieter wrote:
> The patch below:
>
> 	Fixes several err() vs errx() errors
> 	Improves some range checks
> 	Improves some messages
> 	Supports NetBSD in addition to FreeBSD
>   
Ok, slightly reworked patch.  Seems to work fine for me.  Comments?

-- 
Sean Bruno
MiraLink Corporation
6015 NE 80th Ave, Ste 100
Portland, OR 97218
Phone 503-621-5143
Fax 503-621-5199
MSN: sbruno@miralink.com
Google:  seanwbruno@gmail.com
Yahoo:  sean_bruno@yahoo.com


--------------090904020605060401030902
Content-Type: text/plain;
 name="fwcontrol.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fwcontrol.diff"

Index: fwmpegts.c
===================================================================
--- fwmpegts.c	(revision 184344)
+++ fwmpegts.c	(working copy)
@@ -52,9 +52,17 @@
 #include <string.h>
 #include <sysexits.h>
 
+#if defined(__FreeBSD__)
 #include <dev/firewire/firewire.h>
 #include <dev/firewire/iec68113.h>
+#elif defined(__NetBSD__)
+#include <dev/ieee1394/firewire.h>
+#include <dev/ieee1394/iec68113.h>
+#else
+#warning "You need to add support for your OS"
+#endif
 
+
 #include "fwmethods.h"
 
 #define	DEBUG 0
Index: fwcontrol.c
===================================================================
--- fwcontrol.c	(revision 184344)
+++ fwcontrol.c	(working copy)
@@ -32,8 +32,10 @@
  * SUCH DAMAGE.
  */
 
+#if defined(__FreeBSD__)
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
+#endif
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -42,12 +44,23 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/errno.h>
+#if defined(__FreeBSD__)
 #include <sys/eui64.h>
 #include <dev/firewire/firewire.h>
 #include <dev/firewire/iec13213.h>
 #include <dev/firewire/fwphyreg.h>
 #include <dev/firewire/iec68113.h>
+#elif defined(__NetBSD__)
+#include "eui64.h"
+#include <dev/ieee1394/firewire.h>
+#include <dev/ieee1394/iec13213.h>
+#include <dev/ieee1394/fwphyreg.h>
+#include <dev/ieee1394/iec68113.h>
+#else
+#warning "You need to add support for your OS"
+#endif
 
+
 #include <netinet/in.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -66,7 +79,7 @@
 usage(void)
 {
 	fprintf(stderr,
-		"fwcontrol [-u bus_num] [-prt] [-c node] [-d node] [-o node] [-s node]\n"
+		"%s [-u bus_num] [-prt] [-c node] [-d node] [-o node] [-s node]\n"
 		"\t  [-l file] [-g gap_count] [-f force_root ] [-b pri_req]\n"
 		"\t  [-M mode] [-R filename] [-S filename] [-m EUI64 | hostname]\n"
 		"\t-u: specify bus number\n"
@@ -78,13 +91,14 @@
 		"\t-o: send link-on packet to the node\n"
 		"\t-s: write RESET_START register on the node\n"
 		"\t-l: load and parse hex dump file of configuration ROM\n"
-		"\t-g: broadcast gap_count by phy_config packet\n"
-		"\t-f: broadcast force_root by phy_config packet\n"
+		"\t-g: set gap count\n"
+		"\t-f: force root node\n"
 		"\t-b: set PRIORITY_BUDGET register on all supported nodes\n"
 		"\t-M: specify dv or mpeg\n"
 		"\t-R: Receive DV or MPEG TS stream\n"
 		"\t-S: Send DV stream\n"
-		"\t-m: set fwmem target\n");
+		"\t-m: set fwmem target\n"
+		, getprogname() );
 	exit(EX_USAGE);
 }
 
@@ -488,7 +502,7 @@
 	int len=1024, i;
 
 	if ((file = fopen(filename, "r")) == NULL)
-		err(1, "load_crom");
+	  err(1, "load_crom %s", filename);
 	for (i = 0; i < len/(4*8); i ++) {
 		fscanf(file, DUMP_FORMAT,
 			p, p+1, p+2, p+3, p+4, p+5, p+6, p+7);
@@ -691,7 +705,7 @@
 	 */
 	len = read(fd, buf, RECV_NUM_PACKET * RECV_PACKET_SZ);
 	if (len < 0)
-		err(EX_IOERR, "%s: error reading from device\n", __func__);
+		err(EX_IOERR, "%s: error reading from device", __func__);
 	ptr = (u_int32_t *) buf;
 	ciph = (struct ciphdr *)(ptr + 1);
 
@@ -777,7 +791,7 @@
 		case 'b':
 			priority_budget = strtol(optarg, NULL, 0);
 			if (priority_budget < 0 || priority_budget > INT32_MAX)
-				errx(EX_USAGE, "%s: invalid number: %s", __func__, optarg);
+				errx(EX_USAGE, "%s: priority_budget out of range: %s", __func__, optarg);
 			command_set = true;
 			open_needed = true;
 			display_board_only = false;
@@ -787,7 +801,7 @@
 			if (crom_string == NULL)
 				err(EX_SOFTWARE, "%s:crom_string malloc", __func__);
 			if ( (strtol(crom_string, NULL, 0) < 0) || strtol(crom_string, NULL, 0) > MAX_BOARDS)
-				err(EX_USAGE, "%s:Invalid value for node", __func__);
+				errx(EX_USAGE, "%s:Invalid value for node", __func__);
 			strcpy(crom_string, optarg);
 			display_crom = 1;
 			open_needed = true;
@@ -808,7 +822,7 @@
 #define MAX_PHY_CONFIG 0x3f
 			set_root_node = strtol(optarg, NULL, 0);
 			if ( (set_root_node < 0) || (set_root_node > MAX_PHY_CONFIG) )
-				err(EX_USAGE, "%s:set_root_node out of range", __func__);
+				errx(EX_USAGE, "%s:set_root_node out of range", __func__);
 			open_needed = true;
 			command_set = true;
 			display_board_only = false;
@@ -816,7 +830,7 @@
 		case 'g':
 			set_gap_count = strtol(optarg, NULL, 0);
 			if ( (set_gap_count < 0) || (set_gap_count > MAX_PHY_CONFIG) )
-				err(EX_USAGE, "%s:set_gap_count out of range", __func__);
+				errx(EX_USAGE, "%s:set_gap_count out of range", __func__);
 			open_needed = true;
 			command_set = true;
 			display_board_only = false;
@@ -834,12 +848,12 @@
 			display_board_only = false;
 			if (eui64_hostton(optarg, &target) != 0 &&
 			    eui64_aton(optarg, &target) != 0)
-				err(EX_USAGE, "%s: invalid target: %s", __func__, optarg);
+				errx(EX_USAGE, "%s: invalid target: %s", __func__, optarg);
 			break;
 		case 'o':
 			send_link_on = str2node(fd, optarg);
-			if ( (send_link_on < 0) || (send_link_on > INT32_MAX) )
-				err(EX_USAGE, "%s: node out of range: %s\n",__func__, optarg);
+			if ( (send_link_on < 0) || (send_link_on > MAX_PHY_CONFIG) )
+				errx(EX_USAGE, "%s: node out of range: %s\n",__func__, optarg);
 			open_needed = true;
 			command_set = true;
 			display_board_only = false;
@@ -858,8 +872,8 @@
 			break;
 		case 's':
 			send_reset_start  = str2node(fd, optarg);
-			if ( (send_reset_start < 0) || (send_reset_start > INT32_MAX) )
-				err(EX_USAGE, "%s: node out of range: %s\n", __func__, optarg);
+			if ( (send_reset_start < 0) || (send_reset_start > MAX_PHY_CONFIG) )
+				errx(EX_USAGE, "%s: node out of range: %s\n", __func__, optarg);
 			open_needed = true;
 			command_set = true;
 			display_board_only = false;
@@ -926,7 +940,7 @@
 	if(open_needed){
 		snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board);
 		if (open_dev(&fd, devbase) < 0) {
-			errx(EX_IOERR, "%s: Error opening board #%d\n", __func__, current_board);
+		  err(EX_IOERR, "%s: Error opening firewire controller #%d %s", __func__, current_board, devbase);
 		}
 	}
 	/*
@@ -996,8 +1010,16 @@
 	if (set_fwmem_target) {
 		eui.hi = ntohl(*(u_int32_t*)&(target.octet[0]));
 		eui.lo = ntohl(*(u_int32_t*)&(target.octet[4]));
+#if defined(__FreeBSD__)
 		sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi);
 		sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo);
+#elif defined(__NetBSD__)
+		sysctl_set_int("hw.fwmem.eui64_hi", eui.hi);
+		sysctl_set_int("hw.fwmem.eui64_lo", eui.lo);
+#else
+#warning "You need to add support for your OS"
+#endif
+
 	}
 
 	/*
@@ -1030,7 +1052,7 @@
 		}
 		snprintf(devbase, sizeof(devbase), "%s%d", device_string, current_board);
 		if (open_dev(&fd, devbase) < 0)
-			errx(EX_IOERR, "%s: Error opening board #%d in recv_data\n", __func__, current_board);
+		  err(EX_IOERR, "%s: Error opening firewire controller #%d %s in recv_data\n", __func__, current_board, devbase);
 		(*recvfn)(fd, recv_data, TAG | CHANNEL, -1);
 		free(recv_data);
 	}

--------------090904020605060401030902--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4905EE3A.1050506>