Exemple #1
0
int set_network(const char *ifname, int id, const char *field,
		const char *value)
{
	char buf[200];
	snprintf(buf, sizeof(buf), "SET_NETWORK %d %s %s", id, field, value);
	return wpa_command(ifname, buf);
}
Exemple #2
0
static void
wpa_handle_messages(STATE *state, WPA_INTERFACE *iface)
{
	char buffer[BUFFER_SIZE];
	char params[512];
	int nbytes, idx = -1;
	WPA_ACTION handle;
	
	WPA_ACTION handles[TYPES_NUM][NETMAN_NUM_STATES] = {{0}};
	handles[CE_CON][NETMAN_STATE_CONNECTING] = netman_exit;
	handles[CR_PASS][NETMAN_STATE_CONNECTING] = prompt_password;
	
	wpa_command(iface, "ATTACH");
	for (;;) {
		nbytes = read(iface->messages.socket, buffer, BUFFER_SIZE);
		/* remove trailing newline */
		buffer[nbytes] = 0;
		DEBUG("> %s\n", buffer);
		if (buffer[0] != '<') continue;
		idx = get_type(buffer+PLEVEL_LEN);

		if (idx < 0) continue;
		
		handle = handles[idx][state->state];
		if (handle) {
			get_param_str(buffer+PLEVEL_LEN, params, idx);
			handle(state, iface, params);
		}
	}
}
Exemple #3
0
int set_cred_quoted(const char *ifname, int id, const char *field,
		    const char *value)
{
	char buf[200];
	snprintf(buf, sizeof(buf), "SET_CRED %d %s \"%s\"",
		 id, field, value);
	return wpa_command(ifname, buf);
}
Exemple #4
0
static void
wpa_configure_network(WPA_INTERFACE *iface, WPA_NETWORK *network)
{
	KEYVALUE *kv;
	for (kv = network->options; kv; kv = kv->next) {
		/* TODO: failure */
		wpa_command(iface, "SET_NETWORK %d %s %s", network->id, kv->key, kv->value.str);
	}
}
static void process_cmd(struct sigma_dut *dut, struct sigma_conn *conn,
			char *buf)
{
	struct sigma_cmd_handler *h;
	struct sigma_cmd c;
	char *cmd, *pos, *pos2;
	int len;
	char txt[200];
	int res;

	while (*buf == '\r' || *buf == '\n' || *buf == '\t' || *buf == ' ')
		buf++;
	len = strlen(buf);
	while (len > 0 && buf[len - 1] == ' ') {
		buf[len - 1] = '\0';
		len--;
	}

	sigma_dut_print( DUT_MSG_INFO, "cmd: %s", buf);
	snprintf(txt, sizeof(txt), "NOTE CAPI:%s", buf);
	txt[sizeof(txt) - 1] = '\0';
	wpa_command(get_main_ifname(), txt);

	memset(&c, 0, sizeof(c));
	cmd = buf;
	pos = strchr(cmd, ',');
	if (pos) {
		*pos++ = '\0';
		if (strcasecmp(cmd, "AccessPoint") == 0 ||
		    strcasecmp(cmd, "PowerSwitch") == 0) {
			pos2 = strchr(pos, ',');
			if (pos2 == NULL)
				goto invalid_params;
			c.params[c.count] = pos;
			c.values[c.count] = pos2;
			c.count++;
			pos = strchr(pos2, ',');
			if (pos)
				*pos++ = '\0';
		}
		while (pos) {
			pos2 = strchr(pos, ',');
			if (pos2 == NULL)
				goto invalid_params;
			*pos2++ = '\0';
			if (c.count == MAX_PARAMS) {
				sigma_dut_print( DUT_MSG_INFO, "Too many "
						"parameters");
				goto invalid_params;
			}
			c.params[c.count] = pos;
			c.values[c.count] = pos2;
			c.count++;
			pos = strchr(pos2, ',');
			if (pos)
				*pos++ = '\0';
		}
	}
	h = dut->cmds;
	while (h) {
		if (strcasecmp(cmd, h->cmd) == 0)
			break;
		h = h->next;
	}

	if (h == NULL) {
		sigma_dut_print( DUT_MSG_INFO, "Unknown command: '%s'",
				cmd);
		send_resp(dut, conn, SIGMA_INVALID,
			  "errorCode,Unknown command");
		return;
	}

	if (h->validate && h->validate(&c) < 0) {
	invalid_params:
		sigma_dut_print( DUT_MSG_INFO, "Invalid parameters");
		send_resp(dut, conn, SIGMA_INVALID, "errorCode,Invalid "
			  "parameters");
		return;
	}

	send_resp(dut, conn, SIGMA_RUNNING, NULL);
	sigma_dut_print( DUT_MSG_INFO, "Run command: %s", cmd);
	res = h->process(dut, conn, &c);
	if (res == -2)
		send_resp(dut, conn, SIGMA_ERROR, NULL);
	else if (res == -1)
		send_resp(dut, conn, SIGMA_INVALID, NULL);
	else if (res == 1)
		send_resp(dut, conn, SIGMA_COMPLETE, NULL);
}
Exemple #6
0
static void
wpa_enable_network(WPA_INTERFACE *iface, WPA_NETWORK *network)
{
	wpa_command(iface, "ENABLE_NETWORK %d", network->id);
}