Esempio n. 1
0
static int read_tap()
{
	unsigned char buf[MAX_PACKET_LEN];
	int hlen = get_header_len();
	int r;
	int len;

	r = tap_read(tap_fd, buf + hlen, MAX_PACKET_LEN - hlen);

	if (r < 0)
	{
		wmlog_msg(1, "Error while reading from TAP interface");
		return r;
	}

	if (r == 0)
	{
		return 0;
	}
	
	stat_speed_out_mbit += r;

	len = fill_data_packet_header(buf, r);
	wmlog_dumphexasc(4, buf, len, "Outgoing packet:");
	r = set_data(buf, len);

	return r;
}
Esempio n. 2
0
static 
int gct_config_parse_str(const struct parse_data *data,
				struct gct_config *config,
				int line, const char *value)
{
	size_t res_len, *dst_len;
	char **dst, *tmp;

	if (strcmp(value, "NULL") == 0) {
		wmlog_msg(4, "Unset configuration string '%s'",
			   data->name);
		tmp = NULL;
		res_len = 0;
		goto set;
	}

	tmp = gct_config_parse_string(value, &res_len);
	if (tmp == NULL) {
		wmlog_msg(0, "Line %d: failed to parse %s '%s'.",
			   line, data->name,
			   data->key_data ? "[KEY DATA REMOVED]" : value);
		return -1;
	}
	wmlog_dumphexasc(4, (u8 *) tmp, res_len, "%s", data->name);
/*
	if (data->key_data) {
		gct_hexdump_ascii_key(MSG_MSGDUMP, data->name,
				      (u8 *) tmp, res_len);
	} else {
		gct_hexdump_ascii(MSG_MSGDUMP, data->name,
				  (u8 *) tmp, res_len);
	}
*/
	if (data->param3 && res_len < (size_t) data->param3) {
		wmlog_msg(0, "E: Line %d: too short %s (len=%lu "
			   "min_len=%ld)", line, data->name,
			   (unsigned long) res_len, (long) data->param3);
		free(tmp);
		return -1;
	}

	if (data->param4 && res_len > (size_t) data->param4) {
		wmlog_msg(0, "E: Line %d: too long %s (len=%lu "
			   "max_len=%ld)", line, data->name,
			   (unsigned long) res_len, (long) data->param4);
		free(tmp);
		return -1;
	}

set:
	dst = (char **) (((u8 *) config) + (long) data->param1);
	dst_len = (size_t *) (((u8 *) config) + (long) data->param2);
	free(*dst);
	*dst = tmp;
	if (data->param2)
		*dst_len = res_len;

	return 0;
}
Esempio n. 3
0
static void cb_req(struct libusb_transfer *transfer)
{
	if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
		wmlog_msg(1, "async bulk read error %d", transfer->status);
		if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) {
			device_disconnected = 1;
			return;
		}
	} else {
		wmlog_dumphexasc(3, transfer->buffer, transfer->actual_length, "Async read:");
		process_response(&wd_status, transfer->buffer, transfer->actual_length);
	}
	if (libusb_submit_transfer(req_transfer) < 0) {
		wmlog_msg(1, "async read transfer sumbit failed");
	}
}
Esempio n. 4
0
static int set_data(unsigned char* data, int size)
{
	int r;
	int transferred;

	wmlog_dumphexasc(3, data, size, "Bulk write:");

	r = libusb_bulk_transfer(devh, EP_OUT, data, size, &transferred, 0);
	if (r < 0) {
		wmlog_msg(1, "bulk write error %d", r);
		if (r == LIBUSB_ERROR_NO_DEVICE) {
			exit_release_resources(0);
		}
		return r;
	}
	if (transferred < size) {
		wmlog_msg(1, "short write (%d)", r);
		return -1;
	}
	return r;
}
Esempio n. 5
0
static 
int gct_config_parse_password(const struct parse_data *data,
				     struct gct_config *config, int line,
				     const char *value)
{
	u8 *hash;

	if (strcmp(value, "NULL") == 0) {
		wmlog_msg(4, "Unset configuration string 'password'\n");
		free(config->password);
		config->password = NULL;
		config->password_len = 0;
		return 0;
	}

	if (strncmp(value, "hash:", 5) != 0) {
		char *tmp;
		size_t res_len;

		tmp = gct_config_parse_string(value, &res_len);
		if (tmp == NULL) {
			wmlog_msg(0, "E: Line %d: failed to parse "
				   "password.", line);
			return -1;
		}
		wmlog_dumphexasc(4, (u8 *) tmp, res_len,"%s",data->name);
//		gct_hexdump_ascii_key(MSG_MSGDUMP, data->name,
//				      (u8 *) tmp, res_len);

		free(config->password);
		config->password = (u8 *) tmp;
		config->password_len = res_len;
		config->flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;

		return 0;
	}


	/* NtPasswordHash: hash:<32 hex digits> */
	if (strlen(value + 5) != 2 * 16) {
		wmlog_msg(0, "E: Line %d: Invalid password hash length "
			   "(expected 32 hex digits)", line);
		return -1;
	}

	hash = malloc(16);
	if (hash == NULL)
		return -1;

	if (hexstr2bin(value + 5, hash, 16)) {
		free(hash);
		wmlog_msg(0, "E: Line %d: Invalid password hash", line);
		return -1;
	}

	wmlog_dumphexasc(4,	hash, 16,"%s",data->name);
//	gct_hexdump_key(MSG_MSGDUMP, data->name, hash, 16);

	free(config->password);
	config->password = hash;
	config->password_len = 16;
	config->flags |= EAP_CONFIG_FLAGS_PASSWORD_NTHASH;

	return 0;
}
Esempio n. 6
0
static 
int gct_config_parse_eap(const struct parse_data *data,
				struct gct_config *config, int line,
				const char *value)
{
	int last, errors = 0;
	char *start, *end, *buf;
	struct eap_method_type *methods = NULL, *tmp;
	size_t num_methods = 0;

	buf = strdup(value);
	if (buf == NULL)
		return -1;
	start = buf;

	while (*start != '\0') {
		while (*start == ' ' || *start == '\t')
			start++;
		if (*start == '\0')
			break;
		end = start;
		while (*end != ' ' && *end != '\t' && *end != '\0')
			end++;
		last = *end == '\0';
		*end = '\0';
		tmp = methods;
		methods = realloc(methods,
				     (num_methods + 1) * sizeof(*methods));
		if (methods == NULL) {
			free(tmp);
			free(buf);
			return -1;
		}
		methods[num_methods].method = eap_peer_get_type(
			start, &methods[num_methods].vendor);
		if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
		    methods[num_methods].method == EAP_TYPE_NONE) {
			wmlog_msg(0, "Line %d: unknown EAP method "
				   "'%s'", line, start);
			wmlog_msg(0, "You may need to add support for"
				   " this EAP method during wpa_supplicant\n"
				   "build time configuration.\n"
				   "See README for more information.");
			errors++;
		}/* else if (methods[num_methods].vendor == EAP_VENDOR_IETF &&
			   methods[num_methods].method == EAP_TYPE_LEAP)
			ssid->leap++;
		else
			ssid->non_leap++;*/
		num_methods++;
		if (last)
			break;
		start = end + 1;
	}
	free(buf);

	tmp = methods;
	methods = realloc(methods, (num_methods + 1) * sizeof(*methods));
	if (methods == NULL) {
		free(tmp);
		return -1;
	}
	methods[num_methods].vendor = EAP_VENDOR_IETF;
	methods[num_methods].method = EAP_TYPE_NONE;
	num_methods++;

	wmlog_dumphexasc(4, (u8 *) methods, 
		num_methods * sizeof(*methods),"eap methods");
	config->eap_methods = methods;
	return errors ? -1 : 0;
}