示例#1
0
static void wpa_driver_ndis_event_process(struct wpa_driver_ndis_data *drv,
					  u8 *buf, size_t len)
{
	u8 *pos, *data = NULL;
	enum event_types type;
	size_t data_len = 0;

	wpa_hexdump(MSG_MSGDUMP, "NDIS: received event data", buf, len);
	if (len < sizeof(int))
		return;
	type = *((int *) buf);
	pos = buf + sizeof(int);
	wpa_printf(MSG_DEBUG, "NDIS: event - type %d", type);

	if (buf + len - pos > 2) {
		data_len = (int) *pos++ << 8;
		data_len += *pos++;
		if (data_len > (size_t) (buf + len - pos)) {
			wpa_printf(MSG_DEBUG, "NDIS: event data overflow");
			return;
		}
		data = pos;
		wpa_hexdump(MSG_MSGDUMP, "NDIS: event data", data, data_len);
	}

	switch (type) {
	case EVENT_CONNECT:
		wpa_driver_ndis_event_connect(drv);
		break;
	case EVENT_DISCONNECT:
		wpa_driver_ndis_event_disconnect(drv);
		break;
	case EVENT_MEDIA_SPECIFIC:
		wpa_driver_ndis_event_media_specific(drv, data, data_len);
		break;
	case EVENT_ADAPTER_ARRIVAL:
		wpa_driver_ndis_event_adapter_arrival(drv);
		break;
	case EVENT_ADAPTER_REMOVAL:
		wpa_driver_ndis_event_adapter_removal(drv);
		break;
	}
}
示例#2
0
static void wpa_driver_ndis_event_cb(int sock, void *eloop_ctx, void *sock_ctx)
{
	struct wpa_driver_ndis_data *drv = eloop_ctx;
	u8 buf[512], *pos, *data = NULL;
	int res, i, desc_len;
	enum event_types type;
	unsigned char instance_len;
	char *instance;
	size_t data_len = 0;

	res = recv(sock, buf, sizeof(buf), 0);
	if (res < 0) {
		perror("wpa_driver_ndis_event_cb - recv");
		return;
	}
	wpa_hexdump(MSG_MSGDUMP, "NDIS: received event data", buf, res);
	if (res < sizeof(int) + 1)
		return;
	type = *((int *) buf);
	pos = buf + sizeof(int);
	wpa_printf(MSG_DEBUG, "NDIS: event - type %d", type);
	instance_len = *pos++;
	if (instance_len > buf + res - pos) {
		wpa_printf(MSG_DEBUG, "NDIS: event InstanceName overflow");
		return;
	}
	instance = pos;
	pos += instance_len;
	wpa_hexdump_ascii(MSG_MSGDUMP, "NDIS: event InstanceName",
			  instance, instance_len);

	if (buf + res - pos > 1) {
		data_len = *pos++;
		if (data_len > buf + res - pos) {
			wpa_printf(MSG_DEBUG, "NDIS: event data overflow");
			return;
		}
		data = pos;
		wpa_hexdump(MSG_MSGDUMP, "NDIS: event data", data, data_len);
	}

	if (drv->adapter_desc) {
		desc_len = strlen(drv->adapter_desc);
		if (instance_len < desc_len ||
		    strncmp(drv->adapter_desc, instance, desc_len)) {
			wpa_printf(MSG_DEBUG, "NDIS: ignored event for "
				   "another adapter");
			return;
		}

		/* InstanceName:
		 * <driver desc> #<num>
		 * <driver desc> #<num> - <intermediate drv name> Miniport
		 */
		for (i = desc_len + 1; i < instance_len; i++) {
			if (instance[i] == '-') {
				wpa_printf(MSG_DEBUG, "NDIS: ignored event "
					   "for intermediate miniport");
				return;
			}
		}
	}

	switch (type) {
	case EVENT_CONNECT:
		wpa_driver_ndis_event_connect(drv);
		break;
	case EVENT_DISCONNECT:
		wpa_driver_ndis_event_disconnect(drv);
		break;
	case EVENT_MEDIA_SPECIFIC:
		wpa_driver_ndis_event_media_specific(drv, data, data_len);
		break;
	}
}