Exemplo n.º 1
0
static void
list_dev(int fd)
{
    struct fw_devlstreq *data;
    struct fw_devinfo *devinfo;
    struct eui64 eui;
    char addr[EUI64_SIZ], hostname[40];
    int i;

    data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
    if (data == NULL)
        err(EX_SOFTWARE, "%s:data malloc", __func__);
    get_dev(fd, data);
    printf("%d devices (info_len=%d)\n", data->n, data->info_len);
    printf("node           EUI64          status    hostname\n");
    for (i = 0; i < data->info_len; i++) {
        devinfo = &data->dev[i];
        fweui2eui64(&devinfo->eui, &eui);
        eui64_ntoa(&eui, addr, sizeof(addr));
        if (eui64_ntohost(hostname, sizeof(hostname), &eui))
            hostname[0] = 0;
        printf("%4d  %s %6d    %s\n",
               (devinfo->status || i == 0) ? devinfo->dst : -1,
               addr,
               devinfo->status,
               hostname
              );
    }
    free((void *)data);
}
Exemplo n.º 2
0
static void
set_pri_req(int fd, u_int32_t 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;

    data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
    if (data == NULL)
        err(EX_SOFTWARE, "%s:data malloc", __func__);
    get_dev(fd, data);
#define BUGET_REG 0xf0000218
    for (i = 0; i < data->info_len; i++) {
        devinfo = &data->dev[i];
        if (!devinfo->status)
            continue;
        reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0);
        fweui2eui64(&devinfo->eui, &eui);
        eui64_ntoa(&eui, addr, sizeof(addr));
        printf("%d %s, %08x",
               devinfo->dst, addr, reg);
        if (reg > 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, devinfo->eui, BUGET_REG, 0, pri_req);
        } else {
Exemplo n.º 3
0
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.
	 */
#ifdef __HAIKU__
	if (eui64_aton(nodestr, &eui) != 0)
#else
	if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0)
#endif
		return (-1);

	data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq));
	if (data == NULL)
		err(EX_SOFTWARE, "%s: data malloc", __func__);
	get_dev(fd,data);

	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;
			free(data);
			goto gotnode;
		}
	}
	if (i >= data->info_len) {
		if (data != NULL)
			free(data);
		return (-1);
	}

gotnode:
	if (node < 0 || node > 63)
		return (-1);
	else
		return (node);
}