summaryrefslogtreecommitdiffstats
path: root/usr.sbin/fwcontrol/fwcontrol.c
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2004-05-26 22:59:55 +0000
committerbrooks <brooks@FreeBSD.org>2004-05-26 22:59:55 +0000
commit5b46c790ee2be794d0ddffea63668fec51c8f260 (patch)
tree911a427f57cebda0e7dc45f2fcb3047e0dfcc019 /usr.sbin/fwcontrol/fwcontrol.c
parent5ae1bd47055bb0a8824b70db8ecac0a96fa662c1 (diff)
downloadFreeBSD-src-5b46c790ee2be794d0ddffea63668fec51c8f260.zip
FreeBSD-src-5b46c790ee2be794d0ddffea63668fec51c8f260.tar.gz
Use new eui64(3) functions to print EUI-64s and to allow access to nodes
by EUI-64 and name. Reviewed by: simokawa
Diffstat (limited to 'usr.sbin/fwcontrol/fwcontrol.c')
-rw-r--r--usr.sbin/fwcontrol/fwcontrol.c86
1 files changed, 74 insertions, 12 deletions
diff --git a/usr.sbin/fwcontrol/fwcontrol.c b/usr.sbin/fwcontrol/fwcontrol.c
index 99c13a6..c250723 100644
--- a/usr.sbin/fwcontrol/fwcontrol.c
+++ b/usr.sbin/fwcontrol/fwcontrol.c
@@ -39,6 +39,7 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
+#include <sys/eui64.h>
#include <dev/firewire/firewire.h>
#include <dev/firewire/iec13213.h>
#include <dev/firewire/fwphyreg.h>
@@ -76,6 +77,13 @@ usage(void)
exit(0);
}
+static void
+fweui2eui64(const struct fw_eui64 *fweui, struct eui64 *eui)
+{
+ *(u_int32_t*)&(eui->octet[0]) = htonl(fweui->hi);
+ *(u_int32_t*)&(eui->octet[4]) = htonl(fweui->lo);
+}
+
static struct fw_devlstreq *
get_dev(int fd)
{
@@ -90,22 +98,68 @@ get_dev(int fd)
return data;
}
+static int
+str2node(int fd, const char *nodestr)
+{
+ struct eui64 eui, tmpeui;
+ struct fw_devlstreq *data;
+ char *endptr;
+ int i, node;
+
+ if (nodestr == '\0')
+ return (-1);
+
+ /*
+ * Deal with classic node specifications.
+ */
+ node = strtol(nodestr, &endptr, 0);
+ if (*endptr == '\0')
+ goto gotnode;
+
+ /*
+ * Try to get an eui and match it against available nodes.
+ */
+ if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
+ return (-1);
+
+ data = get_dev(fd);
+
+ for (i = 0; i < data->info_len; i++) {
+ fweui2eui64(&data->dev[i].eui, &tmpeui);
+ if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) {
+ node = data->dev[i].dst;
+ goto gotnode;
+ }
+ }
+ if (i >= data->info_len)
+ return (-1);
+
+gotnode:
+ if (node < 0 || node > 63)
+ return (-1);
+ else
+ return (node);
+}
+
static void
list_dev(int fd)
{
struct fw_devlstreq *data;
struct fw_devinfo *devinfo;
+ struct eui64 eui;
+ char addr[EUI64_SIZ];
int i;
data = get_dev(fd);
printf("%d devices (info_len=%d)\n", data->n, data->info_len);
- printf("node EUI64 status\n");
+ printf("node EUI64 status\n");
for (i = 0; i < data->info_len; i++) {
devinfo = &data->dev[i];
- printf("%4d 0x%08x%08x %6d\n",
+ fweui2eui64(&devinfo->eui, &eui);
+ eui64_ntoa(&eui, addr, sizeof(addr));
+ printf("%4d %s %6d\n",
(devinfo->status || i == 0) ? devinfo->dst : -1,
- devinfo->eui.hi,
- devinfo->eui.lo,
+ addr,
devinfo->status
);
}
@@ -220,6 +274,8 @@ set_pri_req(int fd, int pri_req)
{
struct fw_devlstreq *data;
struct fw_devinfo *devinfo;
+ struct eui64 eui;
+ char addr[EUI64_SIZ];
u_int32_t max, reg, old;
int i;
@@ -230,8 +286,10 @@ set_pri_req(int fd, int pri_req)
if (!devinfo->status)
continue;
reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0);
- printf("%d %08x:%08x, %08x",
- devinfo->dst, devinfo->eui.hi, devinfo->eui.lo, reg);
+ fweui2eui64(&devinfo->eui, &eui);
+ eui64_ntoa(&eui, addr, sizeof(addr));
+ printf("%d %s, %08x",
+ devinfo->dst, addr, reg);
if (reg > 0 && pri_req >= 0) {
old = (reg & 0x3f);
max = (reg & 0x3f00) >> 8;
@@ -250,19 +308,23 @@ static void
parse_bus_info_block(u_int32_t *p, int info_len)
{
int i;
+ char addr[EUI64_SIZ];
struct bus_info *bi;
+ struct eui64 eui;
bi = (struct bus_info *)p;
+ fweui2eui64(&bi->eui64, &eui);
+ eui64_ntoa(&eui, addr, sizeof(addr));
printf("bus_name: 0x%04x\n"
"irmc:%d cmc:%d isc:%d bmc:%d pmc:%d\n"
"cyc_clk_acc:%d max_rec:%d max_rom:%d\n"
"generation:%d link_spd:%d\n"
- "EUI64: 0x%08x 0x%08x\n",
+ "EUI64: %s\n",
bi->bus_name,
bi->irmc, bi->cmc, bi->isc, bi->bmc, bi->pmc,
bi->cyc_clk_acc, bi->max_rec, bi->max_rom,
bi->generation, bi->link_spd,
- bi->eui64.hi, bi->eui64.lo);
+ addr);
}
static int
@@ -555,14 +617,14 @@ main(int argc, char **argv)
set_pri_req(fd, tmp);
break;
case 'c':
- tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
+ tmp = str2node(fd, optarg);
get_crom(fd, tmp, crom_buf, len);
show_crom(crom_buf);
break;
case 'd':
- tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
+ tmp = str2node(fd, optarg);
get_crom(fd, tmp, crom_buf, len);
dump_crom(crom_buf);
break;
@@ -576,8 +638,8 @@ main(int argc, char **argv)
show_crom(crom_buf);
break;
case 'o':
- tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
+ tmp = str2node(fd, optarg);
send_link_on(fd, tmp);
break;
case 'p':
@@ -590,8 +652,8 @@ main(int argc, char **argv)
err(1, "ioctl");
break;
case 's':
- tmp = strtol(optarg, NULL, 0);
open_dev(&fd, devbase);
+ tmp = str2node(fd, optarg);
reset_start(fd, tmp);
break;
case 't':
OpenPOWER on IntegriCloud