Exemplo n.º 1
0
static void effects_monitor_param_cb(proto_t *proto)
{
    int resp;
    if (monitor_status())
        resp = effects_monitor_parameter(atoi(proto->list[1]), proto->list[2],
                                         proto->list[3], atof(proto->list[4]));
    else
        resp = -1;

    char buffer[128];
    sprintf(buffer, "resp %i", resp);
    protocol_response(buffer, proto);
}
Exemplo n.º 2
0
int do_one_xcvr(int skfd)
{
	u16 *data = (u16 *)(&ifr.ifr_data);
	u32 *data32 = (u32 *)(&ifr.ifr_data);
	unsigned phy_id = data[0];

	if (override_phy >= 0) {
		printf("Using the specified MII PHY index %d.\n", override_phy);
		phy_id = override_phy;
	}

	if (opt_g || opt_G || msg_level >= 0) {
		if (ioctl(skfd, SIOCGPARAMS, &ifr) < 0) {
			fprintf(stderr, "SIOCGPARAMS on %s failed: %s\n", ifr.ifr_name,
					strerror(errno));
			return -1;
		}
	}
	if (opt_g) {
		int i;
		printf("Driver general parameter settings:");
		for (i = 0; i*sizeof(u32) < sizeof(ifr.ifr_ifru); i++) {
			printf(" %d", data32[i]);
		}
		printf(".\n");
	}
	if (opt_G) {
		/* Set up to four arbitrary driver parameters from the -G parameter.
		   The format is comma separated integers, with a missing element
		   retaining the previous value.
		*/
		char *str = opt_G_string;
		int i;
		for (i = 0; str && i < 4; i++) {
			char *endstr;
			u32 newval = strtol(str, &endstr, 0);
			if (debug)
				printf(" parse string '%s'  value %d end '%s'.\n",
					   str, newval, endstr);
			if (str == endstr) {
				if (endstr[0] == ',') /* No parameter */
					str = endstr+1;
				else {
					fprintf(stderr, "Invalid driver parameter '%s'.\n", str);
					str = index(str, ',');
				}
			} else if (endstr[0] == ',') {
				data32[i] = newval;
				str = endstr + 1;
			} else if (endstr[0] == 0) {
				data32[i] = newval;
				break;
			}
		}
		printf("Setting new driver general parameters:");
		for (i = 0; i*sizeof(u32) < sizeof(ifr.ifr_ifru); i++) {
			printf(" %d", data32[i]);
		}
		printf(".\n");
		if (ioctl(skfd, SIOCSPARAMS, &ifr) < 0) {
			fprintf(stderr, "SIOCSPARAMS on %s failed: %s\n", ifr.ifr_name,
					strerror(errno));
			return -1;
		}
	}
	if (msg_level >= 0) {
		data32[0] = msg_level;
		if (ioctl(skfd, SIOCSPARAMS, &ifr) < 0) {
			fprintf(stderr, "SIOCSPARAMS on %s failed: %s\n", ifr.ifr_name,
					strerror(errno));
			return -1;
		}
	}

	if (opt_reset) {
		printf("Resetting the transceiver...\n");
		mdio_write(skfd, phy_id, 0, 0x8000);
	}
	/* Note: PHY addresses > 32 are pseudo-MII devices, usually built-in. */
	if (phy_id < 64  &&  nway_advertise > 0) {
		printf(" Setting the media capability advertisement register of "
			   "PHY #%d to 0x%4.4x.\n", phy_id, nway_advertise | 1);
		mdio_write(skfd, phy_id, 4, nway_advertise | 1);
		mdio_write(skfd, phy_id, 0, 0x1000);
	}

	if (opt_restart) {
		printf("Restarting negotiation...\n");
		mdio_write(skfd, phy_id, 0, 0x0000);
		mdio_write(skfd, phy_id, 0, 0x1200);
	}
	/* To force 100baseTx-HD do  mdio_write(skfd, phy_id, 0, 0x2000); */
	if (fixed_speed >= 0) {
		int reg0_val = 0;
		if (fixed_speed & 0x0180) 		/* 100mpbs */
			reg0_val |=  0x2000;
		if ((fixed_speed & 0x0140) &&		/* A full duplex type and */
			! (fixed_speed & 0x0820)) 		/* no half duplex types. */
			reg0_val |= 0x0100;
		printf("Setting the speed to \"fixed\", Control register %4.4x.\n",
			   reg0_val);
		mdio_write(skfd, phy_id, 0, reg0_val);
	}
	if (set_BMCR >= 0) {
		printf("Setting the Basic Mode Control Register to 0x%4.4x.\n",
			   set_BMCR);
		mdio_write(skfd, phy_id, 0, set_BMCR);
	}

	if (opt_watch && opt_status)
		monitor_status(skfd, phy_id);

	show_basic_mii(skfd, phy_id);
#ifdef LIBMII
	if (verbose)
		show_mii_details(skfd, phy_id);
#else
	if (verbose || debug) {
		int mii_reg, mii_val;
		printf(" MII PHY #%d transceiver registers:", phy_id);
		for (mii_reg = 0; mii_reg < 32; mii_reg++) {
			mii_val = mdio_read(skfd, phy_id, mii_reg);
			printf("%s %4.4x", (mii_reg % 8) == 0 ? "\n  " : "",
				   mii_val);
		}
		printf("\n");
	}
#endif

	if (opt_watch)
		monitor_mii(skfd, phy_id);
	if (opt_status &&
		(mdio_read(skfd, phy_id, 1) & 0x0004) == 0)
		exit(2);
	return 0;
}
Exemplo n.º 3
0
int main (int argc, char *argv[]) {
	const char *options = "VHaslpmfe:v:hin:o:";
	char *endptr;
	int opt;
	int votes = 0;
	int ret = 0;
	uint32_t nodeid = 0;
	uint32_t nodeid_set = 0;
	nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL;
	name_format_t address_format = ADDRESS_FORMAT_NAME;
	command_t command_opt = CMD_SHOWSTATUS;
	sorttype_t sort_opt = SORT_ADDR;
	char sortchar;
	long int l;

	if (init_all()) {
		close_all();
		exit(1);
	}

	while ( (opt = getopt(argc, argv, options)) != -1 ) {
		switch (opt) {
		case 'f':
			if (using_votequorum() > 0) {
				command_opt = CMD_UNREGISTER_QDEVICE;
			} else {
				fprintf(stderr, "You cannot unregister quorum device, corosync is not using votequorum\n");
				exit(2);
			}
			break;
		case 's':
			command_opt = CMD_SHOWSTATUS;
			break;
		case 'a':
			g_show_all_addrs = 1;
			break;
		case 'm':
			command_opt = CMD_MONITOR;
			break;
		case 'i':
			address_format = ADDRESS_FORMAT_IP;
			break;
		case 'H':
			nodeid_format = NODEID_FORMAT_HEX;
			break;
		case 'l':
			command_opt = CMD_SHOWNODES;
			break;
		case 'p':
			machine_parsable = 1;
			break;
		case 'e':
			if (using_votequorum() > 0) {
				votes = strtol(optarg, &endptr, 0);
				if ((votes == 0 && endptr == optarg) || votes <= 0) {
					fprintf(stderr, "New expected votes value was not valid, try a positive number\n");
				} else {
					command_opt = CMD_SETEXPECTED;
				}
			} else {
				fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n");
				exit(2);
			}
			break;
		case 'n':
			l = strtol(optarg, &endptr, 0);
			if ((l == 0 && endptr == optarg) || l < 0) {
				fprintf(stderr, "The nodeid was not valid, try a positive number\n");
				exit(2);
			}
			nodeid = l;
			nodeid_set = 1;
			break;
		case 'v':
			if (using_votequorum() > 0) {
				votes = strtol(optarg, &endptr, 0);
				if ((votes == 0 && endptr == optarg) || votes < 0) {
					fprintf(stderr, "New votes value was not valid, try a positive number or zero\n");
					exit(2);
				} else {
					command_opt = CMD_SETVOTES;
				}
			}
			else {
				fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n");
				exit(2);
			}
			break;
		case 'o':
			sortchar = optarg[0];
			switch (sortchar) {
			        case 'a': sort_opt = SORT_ADDR;
					break;
			        case 'i': sort_opt = SORT_NODEID;
					break;
			        case 'n': sort_opt = SORT_NODENAME;
					break;
			        default:
					fprintf(stderr, "Invalid ordering option. valid orders are a(address), i(node ID) or n(name)\n");
					exit(2);
					break;
			}
			break;
		case 'V':
			printf("corosync-quorumtool version: %s\n", VERSION);
			exit(0);
		case ':':
		case 'h':
		case '?':
		default:
			command_opt = CMD_UNKNOWN;
			break;
		}
	}

	switch (command_opt) {
	case CMD_UNKNOWN:
		show_usage(argv[0]);
		ret = -1;
		break;
	case CMD_SHOWNODES:
		ret = show_nodes(nodeid_format, address_format, sort_opt);
		break;
	case CMD_SHOWSTATUS:
		ret = show_status(nodeid_format, address_format, sort_opt);
		break;
	case CMD_SETVOTES:
		if (!nodeid_set) {
			nodeid = our_nodeid;
		}
		ret = set_votes(nodeid, votes);
		break;
	case CMD_SETEXPECTED:
		ret = set_expected(votes);
		break;
	case CMD_MONITOR:
		ret = monitor_status(nodeid_format, address_format, sort_opt);
		break;
	case CMD_UNREGISTER_QDEVICE:
		ret = unregister_qdevice();
		break;
	}

	close_all();

	return (ret);
}