diff options
author | simokawa <simokawa@FreeBSD.org> | 2003-01-25 14:47:33 +0000 |
---|---|---|
committer | simokawa <simokawa@FreeBSD.org> | 2003-01-25 14:47:33 +0000 |
commit | ea028a97eca8c07525da7487f7d0ee2e909f78b8 (patch) | |
tree | a7d9817a446ea43a90a137c6f9c6ac4f9116a388 /usr.sbin/fwcontrol | |
parent | bd84d01eeac47ef04237e8993ab6d653caa88493 (diff) | |
download | FreeBSD-src-ea028a97eca8c07525da7487f7d0ee2e909f78b8.zip FreeBSD-src-ea028a97eca8c07525da7487f7d0ee2e909f78b8.tar.gz |
Change API of FW_GDEVLST ioctl.
- include information about itself.
- define struct fw_devinfo and use it in struct fw_devlstreq.
- unify EUI64 representation using struct fw_eui64.
Diffstat (limited to 'usr.sbin/fwcontrol')
-rw-r--r-- | usr.sbin/fwcontrol/fwcontrol.c | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/usr.sbin/fwcontrol/fwcontrol.c b/usr.sbin/fwcontrol/fwcontrol.c index 08e0a55..9783a57 100644 --- a/usr.sbin/fwcontrol/fwcontrol.c +++ b/usr.sbin/fwcontrol/fwcontrol.c @@ -72,32 +72,40 @@ usage(void) exit(0); } -static void -get_num_of_dev(int fd, struct fw_devlstreq *data) +static struct fw_devlstreq * +get_dev(int fd) { - data->n = 64; + struct fw_devlstreq *data; + + data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); + if (data == NULL) + err(1, "malloc"); if( ioctl(fd, FW_GDEVLST, data) < 0) { err(1, "ioctl"); } + return data; } static void list_dev(int fd) { - struct fw_devlstreq data; + struct fw_devlstreq *data; + struct fw_devinfo *devinfo; int i; - get_num_of_dev(fd, &data); - printf("%d devices\n", data.n); - for (i = 0; i < data.n; i++) { + data = get_dev(fd); + printf("%d devices (info_len=%d)\n", data->n, data->info_len); + for (i = 0; i < data->info_len; i++) { + devinfo = &data->dev[i]; printf("%d node %d eui:%08x%08x status:%d\n", i, - data.dst[i], - data.eui[i].hi, - data.eui[i].lo, - data.status[i] + devinfo->dst, + devinfo->eui.hi, + devinfo->eui.lo, + devinfo->status ); } + free((void *)data); } static u_int32_t @@ -165,29 +173,32 @@ send_phy_config(int fd, int root_node, int gap_count) static void set_pri_req(int fd, int pri_req) { - struct fw_devlstreq data; + struct fw_devlstreq *data; + struct fw_devinfo *devinfo; u_int32_t max, reg, old; int i; - get_num_of_dev(fd, &data); + data = get_dev(fd); #define BUGET_REG 0xf0000218 - for (i = 0; i < data.n; i++) { - if (!data.status[i]) + for (i = 0; i < data->info_len; i++) { + devinfo = &data->dev[i]; + if (!devinfo->status) continue; - reg = read_write_quad(fd, data.eui[i], BUGET_REG, 1, 0); + reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0); printf("%d %08x:%08x, %08x", - data.dst[i], data.eui[i].hi, data.eui[i].lo, reg); + devinfo->dst, devinfo->eui.hi, devinfo->eui.lo, reg); if (reg > 0 && pri_req >= 0) { old = (reg & 0x3f); max = (reg & 0x3f00) >> 8; if (pri_req > max) pri_req = max; printf(" 0x%x -> 0x%x\n", old, pri_req); - read_write_quad(fd, data.eui[i], BUGET_REG, 0, pri_req); + read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req); } else { printf("\n"); } } + free((void *)data); } static void @@ -204,26 +215,29 @@ static int get_crom(int fd, int node, void *crom_buf, int len) { struct fw_crom_buf buf; - int i, error; - struct fw_devlstreq data; + int i, n, error; + struct fw_devlstreq *data; - get_num_of_dev(fd, &data); + data = get_dev(fd); - for (i = 0; i < data.n; i++) { - if (data.dst[i] == node && data.eui[i].lo != 0) + for (i = 0; i < data->info_len; i++) { + if (data->dev[i].dst == node && data->dev[i].eui.lo != 0) break; } - if (i != data.n) { - buf.eui = data.eui[i]; - } else { - err(1, "no such node: %d\n", node); - } + if (i == data->info_len) + errx(1, "no such node %d.", node); + else if (i == 0) + errx(1, "node %d is myself.", node); + else + buf.eui = data->dev[i].eui; + free((void *)data); buf.len = len; buf.ptr = crom_buf; if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) { err(1, "ioctl"); } + return error; } |