Example #1
0
static 
int gct_config_parse_int(const struct parse_data *data,
				struct gct_config *config,
				int line, const char *value)
{
	int *dst;

	dst = (int *) (((u8 *) config) + (long) data->param1);
	*dst = atoi(value);
	wmlog_msg(4, "%s=%d (0x%x)", data->name, *dst, *dst);

	if (data->param3 && *dst < (long) data->param3) {
		wmlog_msg(0, "E: Line %d: too small %s (value=%d "
			   "min_value=%ld)", line, data->name, *dst,
			   (long) data->param3);
		*dst = (long) data->param3;
		return -1;
	}

	if (data->param4 && *dst > (long) data->param4) {
		wmlog_msg(0, "E: Line %d: too large %s (value=%d "
			   "max_value=%ld)", line, data->name, *dst,
			   (long) data->param4);
		*dst = (long) data->param4;
		return -1;
	}

	return 0;
}
Example #2
0
static
int gct_config_set(struct gct_config *config, const char *var, const char *value,
		   int line)
{
	size_t i;
	int ret = 0;

	if (config == NULL || var == NULL || value == NULL)
		return -1;

	for (i = 0; i < NUM_SSID_FIELDS; i++) {
		const struct parse_data *field = &ssid_fields[i];
		if (strcmp(var, field->name) != 0)
			continue;

		if (field->parser(field, config, line, value)) {
			if (line) {
				wmlog_msg(0, "E: Line %d: failed to "
					   "parse %s '%s'.", line, var, value);
			}
			ret = -1;
		}
		break;
	}
	if (i == NUM_SSID_FIELDS) {
		if (line) {
			wmlog_msg(0, "E: Line %d: unknown network field "
				   "'%s'.", line, var);
		}
		ret = -1;
	}

	return ret;
}
Example #3
0
static
int gct_config_read_network(struct gct_config *config, FILE *f, int *line)
{
	int errors = 0;
	char buf[256], *pos, *pos2;

	while (gct_config_get_line(buf, sizeof(buf), f, line, &pos)) {
	
		pos2 = strchr(pos, '=');
		if (pos2 == NULL) {
			wmlog_msg(0, "E: Line %d: Invalid CFG line "
				   "'%s'.", *line, pos);
			errors++;
			continue;
		}	
	
		*pos2++ = '\0';
		if (*pos2 == '"') {
			if (strchr(pos2 + 1, '"') == NULL) {
				wmlog_msg(0, "E: Line %d: invalid "
					   "quotation '%s'.", *line, pos2);
				errors++;
				continue;
			}
		}
		
		if (gct_config_set(config, pos, pos2, *line) < 0)
			errors++;	
		
	}
	
	errors += gct_config_validate_network(config);	
	
	return errors;
}
Example #4
0
struct gct_config * gct_config_read(const char *name)
{
	FILE *f;
//	char buf[256], *pos;
	int errors = 0, line = 0;
	struct gct_config *config;
	
	config = gct_config_alloc_empty();
	if (config == NULL)
		return NULL;
	if (eap_peer_register_methods() < 0)
		return NULL;
	wmlog_msg(3, "Reading configuration file '%s'", name);
	f = fopen(name, "r");
	if (f == NULL) {
		free(config);
		wmlog_msg(0, "Configuration file error: %s",strerror(errno));
		return NULL;
	}

//	while (gct_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
		errors += gct_config_read_network(config, f, &line);
//	}
	
	fclose(f);
	
	if (errors) {
		gct_config_free(config);
		config = NULL;
	}
	eap_peer_unregister_methods();
	return config;
}
Example #5
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;
}
Example #6
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;
}
Example #7
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");
	}
}
Example #8
0
/* brings interface down and runs a user-supplied script */
static int if_release()
{
	wmlog_msg(2, "Starting if-release script...");
	raise_event("if-release");
	tap_close(tap_fd, tap_dev);
	return 0;
}
Example #9
0
/* brings interface up and runs a user-supplied script */
static int if_up()
{
	tap_bring_up(tap_fd, tap_dev);
	wmlog_msg(2, "Starting if-up script...");
	raise_event("if-up");
	tap_if_up = 1;
	return 0;
}
Example #10
0
static int scan_loop(void)
{
	unsigned char req_data[MAX_PACKET_LEN];
	int len;

	while (1)
	{
		if (wd_status.link_status == 0) {
			len = fill_find_network_req(req_data, 1);
			set_data(req_data, len);

			process_events_by_mask(5000, WDS_LINK_STATUS);

			if (wd_status.link_status == 0) {
				wmlog_msg(2, "Network not found.");
			} else {
				wmlog_msg(2, "Network found.");
			}
		} else {
			len = fill_connection_params_req(req_data);
			set_data(req_data, len);

			process_events_by_mask(500, WDS_RSSI | WDS_CINR | WDS_TXPWR | WDS_FREQ | WDS_BSID);

			wmlog_msg(2, "RSSI: %d   CINR: %f   TX Power: %d   Frequency: %d", wd_status.rssi, wd_status.cinr, wd_status.txpwr, wd_status.freq);
			wmlog_msg(2, "BSID: %02x:%02x:%02x:%02x:%02x:%02x", wd_status.bsid[0], wd_status.bsid[1], wd_status.bsid[2], wd_status.bsid[3], wd_status.bsid[4], wd_status.bsid[5]);

			len = fill_state_req(req_data);
			set_data(req_data, len);

			process_events_by_mask(500, WDS_STATE);

			wmlog_msg(2, "State: %s   Number: %d   Response: %d", wimax_states[wd_status.state], wd_status.state, wd_status.link_status);

			if (first_nego_flag) {
				first_nego_flag = 0;
				len = fill_find_network_req(req_data, 2);
				set_data(req_data, len);
			}

			process_events_by_mask(5000, WDS_LINK_STATUS);
		}
	}

	return 0;
}
Example #11
0
static struct libusb_device_handle* find_wimax_device(void)
{
	struct libusb_device **devs;
	struct libusb_device *found = NULL;
	struct libusb_device *dev;
	struct libusb_device_handle *handle = NULL;
	int i = 0;
	int r;

	if (libusb_get_device_list(ctx, &devs) < 0)
		return NULL;

	while (!found && (dev = devs[i++]) != NULL) {
		struct libusb_device_descriptor desc;
		unsigned int j = 0;
		unsigned short dev_vid, dev_pid;

		r = libusb_get_device_descriptor(dev, &desc);
		if (r < 0) {
			continue;
		}
		dev_vid = libusb_le16_to_cpu(desc.idVendor);
		dev_pid = libusb_le16_to_cpu(desc.idProduct);
		wmlog_msg(1, "Bus %03d Device %03d: ID %04x:%04x", libusb_get_bus_number(dev), libusb_get_device_address(dev), dev_vid, dev_pid);
		switch (match_method) {
			case MATCH_BY_LIST: {
				for (j = 0; j < sizeof(wimax_dev_ids) / sizeof(usb_device_id_t); j++) {
					if (dev_vid == wimax_dev_ids[j].vendorID && dev_pid == wimax_dev_ids[j].productID) {
						found = dev;
						break;
					}
				}
				break;
			}
			case MATCH_BY_VID_PID: {
				if (dev_vid == match_params.vid && dev_pid == match_params.pid) {
					found = dev;
				}
				break;
			}
			case MATCH_BY_BUS_DEV: {
				if (libusb_get_bus_number(dev) == match_params.bus && libusb_get_device_address(dev) == match_params.dev) {
					found = dev;
				}
				break;
			}
		}
	}

	if (found) {
		r = libusb_open(found, &handle);
		if (r < 0)
			handle = NULL;
	}

	libusb_free_device_list(devs, 1);
	return handle;
}
Example #12
0
/* brings interface up and runs a user-supplied script */
static int if_create()
{
	tap_fd = tap_open(tap_dev);
	if (tap_fd < 0) {
		wmlog_msg(0, "failed to allocate tap interface");
		wmlog_msg(0,
				"You should have TUN/TAP driver compiled in the kernel or as a kernel module.\n"
				"If 'modprobe tun' doesn't help then recompile your kernel.");
		exit_release_resources(1);
	}
	tap_set_hwaddr(tap_fd, tap_dev, wd_status.mac);
	tap_set_mtu(tap_fd, tap_dev, 1386);
	set_coe(tap_fd);
	wmlog_msg(0, "Allocated tap interface: %s", tap_dev);
	wmlog_msg(2, "Starting if-create script...");
	raise_event("if-create");
	return 0;
}
Example #13
0
/* brings interface down and runs a user-supplied script */
static int if_down()
{
	if (!tap_if_up) return 0;
	tap_if_up = 0;
	wmlog_msg(2, "Starting if-down script...");
	raise_event("if-down");
	tap_bring_down(tap_fd, tap_dev);
	return 0;
}
Example #14
0
/* set close-on-exec flag on the file descriptor */
int set_coe(int fd)
{
	int flags;

	flags = fcntl(fd, F_GETFD);
	if (flags == -1)
	{
		wmlog_msg(1, "failed to set close-on-exec flag on fd %d", fd);
		return -1;
	}
	flags |= FD_CLOEXEC;
	if (fcntl(fd, F_SETFD, flags) == -1)
	{
		wmlog_msg(1, "failed to set close-on-exec flag on fd %d", fd);
		return -1;
	}

	return 0;
}
Example #15
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;
}
Example #16
0
/* brings interface up and runs a user-supplied script */
static int if_create()
{
	tap_fd = tap_open(tap_dev);
	if (tap_fd < 0) {
		wmlog_msg(0, "failed to allocate tap interface");
		wmlog_msg(0,
				"You should have TUN/TAP driver compiled in the kernel or as a kernel module.\n"
				"If 'modprobe tun' doesn't help then recompile your kernel.");
		exit_release_resources(1);
	}
	tap_set_hwaddr(tap_fd, tap_dev, wd_status.mac);
	tap_set_mtu(tap_fd, tap_dev, 1386);
	set_coe(tap_fd);
  
  //tap_dev pointed now to correct interface so we are free to update stistics paths
  sprintf(stat_rx_total_path, "/sys/class/net/%s/statistics/rx_bytes", tap_dev);
  sprintf(stat_tx_total_path, "/sys/class/net/%s/statistics/tx_bytes", tap_dev);
  
	wmlog_msg(0, "Allocated tap interface: %s", tap_dev);
	wmlog_msg(2, "Starting if-create script...");
	raise_event("if-create");
	return 0;
}
Example #17
0
/* run specified script */
static int raise_event(char *event)
{
	int pid = fork();

	if(pid < 0) { // error
		return -1;
	} else if (pid > 0) { // parent
		return pid;
	} else { // child
wmlog_msg(0, "raise_event: %s %s.", event, tap_dev);
		char *args[] = {event_script, event, tap_dev, NULL};
		char *env[1] = {NULL};
		// run the program
		execve(args[0], args, env);
		exit(1);
	}//*/
	return 0;
}
Example #18
0
int load_config(unsigned char *mac, char *ifname, struct device_config *cfg)
{
	char macbuf[18];
	lua_State *L = lua_open();	/* open Lua */
	luaL_openlibs(L);		/* open libs */

	wmlog_msg(1, "Loading config...");

	snprintf(macbuf, sizeof(macbuf), "%02x:%02x:%02x:%02x:%02x:%02x",
			mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
	lua_pushstring(L, macbuf);
	lua_setglobal(L, "mac");

	lua_pushstring(L, ifname);
	lua_setglobal(L, "ifname");

	if (luaL_loadfile(L, SYSCONFDIR "/config.lua") || lua_pcall(L, 0, 0, 0)) {
		wmlog_msg(0, "cannot run configuration file: %s", lua_tostring(L, -1));
		return 1;
	}

	lua_getglobal(L, "diode_on");
	lua_getglobal(L, "realm");

	if (lua_isnumber(L, -2)) {
		cfg->diode_on = (int) lua_tonumber(L, -2);
		wmlog_msg(2, "cfg->diode_on = %d", cfg->diode_on);
	} else
		wmlog_msg(2, "cfg->diode_on = nil");

	if (lua_isstring(L, -1)) {
		cfg->realm = strdup(lua_tostring(L, -1));
		wmlog_msg(2, "cfg->realm = %s", cfg->realm);
	} else
		wmlog_msg(2, "cfg->realm = nil");

	lua_close(L);
	return 0;
}
Example #19
0
static void sighandler_wait_child(int signum) {
	int status;
	wait3(&status, WNOHANG, NULL);
	wmlog_msg(2, "Child exited with status %d", status);
}
Example #20
0
int main(int argc, char **argv)
{
	struct sigaction sigact;
	int r = 1;

	parse_args(argc, argv);

	sigact.sa_handler = sighandler_exit;
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = 0;
	sigaction(SIGINT, &sigact, NULL);
	sigaction(SIGTERM, &sigact, NULL);
	sigaction(SIGQUIT, &sigact, NULL);
	sigact.sa_handler = sighandler_wait_child;
	sigaction(SIGCHLD, &sigact, NULL);

	if (logfile != NULL) {
		set_wmlogger(argv[0], WMLOGGER_FILE, logfile);
	} else if (daemonize) {
		set_wmlogger(argv[0], WMLOGGER_SYSLOG, NULL);
	} else {
		set_wmlogger(argv[0], WMLOGGER_FILE, stderr);
	}

	if (daemonize) {
		daemon(0, 0);
	}

	r = libusb_init(&ctx);
	if (r < 0) {
		wmlog_msg(0, "failed to initialise libusb");
		exit_release_resources(1);
	}

	devh = find_wimax_device();
	if (devh == NULL) {
		wmlog_msg(0, "Could not find/open device");
		exit_release_resources(1);
	}

	wmlog_msg(0, "Device found");

	if (detach_dvd && libusb_kernel_driver_active(devh, IF_DVD) == 1) {
		r = libusb_detach_kernel_driver(devh, IF_DVD);
		if (r < 0) {
			wmlog_msg(0, "kernel driver detach error %d", r);
		} else {
			wmlog_msg(0, "detached pseudo-DVD kernel driver");
		}
	}

	if (libusb_kernel_driver_active(devh, IF_MODEM) == 1) {
		kernel_driver_active = 1;
		r = libusb_detach_kernel_driver(devh, IF_MODEM);
		if (r < 0) {
			wmlog_msg(0, "kernel driver detach error %d", r);
		} else {
			wmlog_msg(0, "detached modem kernel driver");
		}
	}

	r = libusb_claim_interface(devh, IF_MODEM);
	if (r < 0) {
		wmlog_msg(0, "Claim usb interface error %d", r);
		exit_release_resources(1);
	}
	wmlog_msg(0, "Claimed interface");

	alloc_fds();
	libusb_set_pollfd_notifiers(ctx, cb_add_pollfd, cb_remove_pollfd, NULL);

	r = init();
	if (r < 0) {
		wmlog_msg(0, "init error %d", r);
		exit_release_resources(1);
	}

	if_create();
	cb_add_pollfd(tap_fd, POLLIN, NULL);

	r = scan_loop();
	if (r < 0) {
		wmlog_msg(0, "scan_loop error %d", r);
		exit_release_resources(1);
	}

	exit_release_resources(0);
	return 0;
}
Example #21
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;
}
Example #22
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;
}
Example #23
0
int main(int argc, char **argv)
{
	struct sigaction sigact;
  struct sigevent sev;
  struct itimerspec its;
	int r = 1;

	parse_args(argc, argv);

	sigact.sa_handler = sighandler_exit;
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = 0;
	sigaction(SIGINT, &sigact, NULL);
	sigaction(SIGTERM, &sigact, NULL);
	sigaction(SIGQUIT, &sigact, NULL);
	sigact.sa_handler = sighandler_wait_child;
	sigaction(SIGCHLD, &sigact, NULL);
  sigact.sa_handler = sighandler_stats;
  sigfillset(&sigact.sa_mask);
  if (stats_period == 0)
    sigaction(SIGUSR1, &sigact, NULL);

	if (logfile != NULL) {
		set_wmlogger(argv[0], WMLOGGER_FILE, logfile);
	} else if (daemonize) {
		set_wmlogger(argv[0], WMLOGGER_SYSLOG, NULL);
	} else {
		set_wmlogger(argv[0], WMLOGGER_FILE, stderr);
	}

	if (daemonize) {
		daemon(0, 0);
	}
	
	if (stats_period != 0) {
    sigemptyset(&sigact.sa_mask);
    sigaction(SIGRTMIN, &sigact, NULL);
    
    // create the POSIX timer 
    sev.sigev_notify = SIGEV_SIGNAL;
    sev.sigev_signo = SIGRTMIN;
    sev.sigev_value.sival_ptr = (void *) &timerid;
    if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == 0) {
        // start the POSIX timer
        its.it_value.tv_sec = stats_period;
        its.it_value.tv_nsec = 0;
        its.it_interval.tv_sec = its.it_value.tv_sec;
        its.it_interval.tv_nsec = its.it_value.tv_nsec;
        timer_settime(timerid, 0, &its, NULL);
    }
  }

	r = libusb_init(&ctx);
	if (r < 0) {
		wmlog_msg(0, "failed to initialise libusb");
		exit_release_resources(1);
	}
	
	if (pid_fname && !write_pidfile(pid_fname)) {
    wmlog_msg(0, "failed to create pid file %s", pid_fname);
    exit_release_resources(1);
  }

	devh = find_wimax_device();
	if (devh == NULL) {
		wmlog_msg(0, "Could not find/open device");
		exit_release_resources(1);
	}

	wmlog_msg(0, "Device found");

	if (detach_dvd && libusb_kernel_driver_active(devh, IF_DVD) == 1) {
		r = libusb_detach_kernel_driver(devh, IF_DVD);
		if (r < 0) {
			wmlog_msg(0, "kernel driver detach error %d", r);
		} else {
			wmlog_msg(0, "detached pseudo-DVD kernel driver");
		}
	}

	if (libusb_kernel_driver_active(devh, IF_MODEM) == 1) {
		kernel_driver_active = 1;
		r = libusb_detach_kernel_driver(devh, IF_MODEM);
		if (r < 0) {
			wmlog_msg(0, "kernel driver detach error %d", r);
		} else {
			wmlog_msg(0, "detached modem kernel driver");
		}
	}

	r = libusb_claim_interface(devh, IF_MODEM);
	if (r < 0) {
		wmlog_msg(0, "Claim usb interface error %d", r);
		exit_release_resources(1);
	}
	wmlog_msg(0, "Claimed interface");

	alloc_fds();
	libusb_set_pollfd_notifiers(ctx, cb_add_pollfd, cb_remove_pollfd, NULL);

	r = init();
	if (r < 0) {
		wmlog_msg(0, "init error %d", r);
		exit_release_resources(1);
	}

	if_create();
	cb_add_pollfd(tap_fd, POLLIN, NULL);

	r = scan_loop();
	if (r < 0) {
		wmlog_msg(0, "scan_loop error %d", r);
		exit_release_resources(1);
	}

	exit_release_resources(0);
	return 0;
}
Example #24
0
static int init(void)
{
	unsigned char req_data[MAX_PACKET_LEN];
	int len;
	int r;

	alloc_transfers();

	wmlog_msg(2, "Continuous async read start...");
	CHECK_DISCONNECTED(libusb_submit_transfer(req_transfer));

	len = fill_protocol_info_req(req_data,
			USB_HOST_SUPPORT_SELECTIVE_SUSPEND | USB_HOST_SUPPORT_DL_SIX_BYTES_HEADER |
			USB_HOST_SUPPORT_UL_SIX_BYTES_HEADER | USB_HOST_SUPPORT_DL_MULTI_PACKETS);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_PROTO_FLAGS);

	len = fill_mac_lowlevel_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_OTHER);

	len = fill_init_cmd(req_data);
	set_data(req_data, len);

	len = fill_string_info_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_CHIP | WDS_FIRMWARE);

	wmlog_msg(1, "Chip info: %s", wd_status.chip);
	wmlog_msg(1, "Firmware info: %s", wd_status.firmware);

	len = fill_diode_control_cmd(req_data, diode_on);
	set_data(req_data, len);

	len = fill_mac_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_MAC);

	wmlog_msg(1, "MAC: %02x:%02x:%02x:%02x:%02x:%02x", wd_status.mac[0], wd_status.mac[1], wd_status.mac[2], wd_status.mac[3], wd_status.mac[4], wd_status.mac[5]);

	len = fill_string_info_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_CHIP | WDS_FIRMWARE);

	len = fill_auth_policy_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_OTHER);

	len = fill_auth_method_req(req_data);
	set_data(req_data, len);

	process_events_by_mask(500, WDS_OTHER);

	len = fill_auth_set_cmd(req_data, ssid);
	set_data(req_data, len);

	return 0;
}
Example #25
0
static int scan_loop(void)
{
	unsigned char req_data[MAX_PACKET_LEN];
	int len;
	DIR *wimax_dir;
	FILE *wimax_file;

	while (1)
	{
		if((wimax_dir = opendir("/tmp/wimax")) == NULL)
			mkdir("/tmp/wimax", 0777);
		else
			closedir(wimax_dir);

		if (wd_status.link_status == 0) {
			len = fill_find_network_req(req_data, 1);
			set_data(req_data, len);

			process_events_by_mask(5000, WDS_LINK_STATUS);

			if((wimax_file = fopen("/tmp/wimax/link_status", "w+")) != NULL){
				fprintf(wimax_file, "%d", wd_status.link_status);
				fclose(wimax_file);
			}

			wmlog_msg(2, "Network not found.");
		} else {
			len = fill_connection_params_req(req_data);
			set_data(req_data, len);

			process_events_by_mask(500, WDS_RSSI | WDS_CINR | WDS_TXPWR | WDS_FREQ | WDS_BSID);

			wmlog_msg(0, "RSSI: %d   CINR: %f   TX Power: %d   Frequency: %d", wd_status.rssi, wd_status.cinr, wd_status.txpwr, wd_status.freq);
			wmlog_msg(0, "BSID: %02x:%02x:%02x:%02x:%02x:%02x", wd_status.bsid[0], wd_status.bsid[1], wd_status.bsid[2], wd_status.bsid[3], wd_status.bsid[4], wd_status.bsid[5]);

			if((wimax_file = fopen("/tmp/wimax/link_status", "w+")) != NULL){
				fprintf(wimax_file, "%d", wd_status.link_status);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/mac", "w+")) != NULL){
				fprintf(wimax_file, "%02x:%02x:%02x:%02x:%02x:%02x", wd_status.mac[0], wd_status.mac[1], wd_status.mac[2], wd_status.mac[3], wd_status.mac[4], wd_status.mac[5]);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/rssi", "w+")) != NULL){
				fprintf(wimax_file, "%hd", wd_status.rssi);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/cinr", "w+")) != NULL){
				fprintf(wimax_file, "%f", wd_status.cinr);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/bsid", "w+")) != NULL){
				fprintf(wimax_file, "%02x:%02x:%02x:%02x:%02x:%02x", wd_status.bsid[0], wd_status.bsid[1], wd_status.bsid[2], wd_status.bsid[3], wd_status.bsid[4], wd_status.bsid[5]);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/txpwr", "w+")) != NULL){
				fprintf(wimax_file, "%hu", wd_status.txpwr);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/freq", "w+")) != NULL){
				fprintf(wimax_file, "%u", wd_status.freq);
				fclose(wimax_file);
			}

			if((wimax_file = fopen("/tmp/wimax/state", "w+")) != NULL){
				fprintf(wimax_file, "%d", wd_status.state);
				fclose(wimax_file);
			}

			len = fill_state_req(req_data);
			set_data(req_data, len);

			process_events_by_mask(500, WDS_STATE);

			wmlog_msg(2, "State: %s   Number: %d   Response: %d", wimax_states[wd_status.state], wd_status.state, wd_status.link_status);

			if (first_nego_flag) {
				first_nego_flag = 0;
				len = fill_find_network_req(req_data, 2);
				set_data(req_data, len);
			}

			process_events_by_mask(5000, WDS_LINK_STATUS);
		}
		
		sleep(SCAN_INTERVAL);
	}

	return 0;
}