示例#1
0
struct wtp_radio* wtp_radio_create_phy(void) {
	struct wtp_radio* radio;

	/* Create disabled radio */
	radio = (struct wtp_radio*)capwap_array_get_item_pointer(g_wtp.radios, g_wtp.radios->count);
	radio->radioid = (uint8_t)g_wtp.radios->count;
	radio->status = WTP_RADIO_DISABLED;

	/* Init configuration radio */
	radio->wlan = capwap_array_create(sizeof(struct wtp_radio_wlan), 0, 1);
	radio->antenna.selections = capwap_array_create(sizeof(uint8_t), 0, 1);
	return radio;
}
示例#2
0
void wtp_radio_init(void) {
	g_wtp.radios = capwap_array_create(sizeof(struct wtp_radio), 0, 1);

	g_wtp.defaultaclstations = WTP_RADIO_ACL_STATION_ALLOW;
	g_wtp.aclstations = capwap_hash_create(WTP_RADIO_ACL_HASH_SIZE);
	g_wtp.aclstations->item_gethash = wtp_radio_acl_item_gethash;
	g_wtp.aclstations->item_getkey = wtp_radio_acl_item_getkey;
	g_wtp.aclstations->item_cmp = wtp_radio_acl_item_cmp;
}
示例#3
0
struct capwap_array* capwap_array_clone(struct capwap_array* array) {
	struct capwap_array* clone;

	ASSERT (array != NULL);

	/* Clone array e items */
	clone = capwap_array_create(array->itemsize, array->count, array->zeroed);
	memcpy(clone->buffer, array->buffer, array->itemsize * array->count);

	return clone;
}
static void* capwap_wtpboarddata_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
	struct capwap_wtpboarddata_element* data;

	ASSERT(handle != NULL);
	ASSERT(func != NULL);

	if (func->read_ready(handle) < 14) {
		capwap_logging_debug("Invalid WTP Board Data element: underbuffer");
		return NULL;
	}

	/* */
	data = (struct capwap_wtpboarddata_element*)capwap_alloc(sizeof(struct capwap_wtpboarddata_element));
	data->boardsubelement = capwap_array_create(sizeof(struct capwap_wtpboarddata_board_subelement), 0, 1);

	/* Retrieve data */
	func->read_u32(handle, &data->vendor);
	if (!data->vendor) {
		capwap_wtpboarddata_element_free((void*)data);
		capwap_logging_debug("Invalid WTP Board Data element: invalid vendor");
		return NULL;
	}

	/* WTP Board Data Subelement */
	while (func->read_ready(handle) > 0) {
		unsigned short length;
		struct capwap_wtpboarddata_board_subelement* desc = (struct capwap_wtpboarddata_board_subelement*)capwap_array_get_item_pointer(data->boardsubelement, data->boardsubelement->count);

		/* */
		func->read_u16(handle, &desc->type);
		func->read_u16(handle, &desc->length);

		if ((desc->type < CAPWAP_BOARD_SUBELEMENT_TYPE_FIRST) || (desc->type > CAPWAP_BOARD_SUBELEMENT_TYPE_LAST)) {
			capwap_logging_debug("Invalid WTP Board Data element: invalid type");
			capwap_wtpboarddata_element_free(data);
			return NULL;
		}

		/* Check buffer size */
		length = func->read_ready(handle);
		if (!length || (length > CAPWAP_BOARD_SUBELEMENT_MAXDATA) || (length < desc->length)) {
			capwap_logging_debug("Invalid WTP Board Data element: invalid length");
			capwap_wtpboarddata_element_free(data);
			return NULL;
		}

		desc->data = (uint8_t*)capwap_alloc(desc->length);
		func->read_block(handle, desc->data, desc->length);
	}

	return data;
}
static void* capwap_80211_antenna_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
	int i;
	uint8_t count;
	unsigned short length;
	struct capwap_80211_antenna_element* data;

	ASSERT(handle != NULL);
	ASSERT(func != NULL);

	length = func->read_ready(handle);
	if (length < 5) {
		capwap_logging_debug("Invalid IEEE 802.11 Antenna element");
		return NULL;
	}

	length -= 4;
	if (length > CAPWAP_ANTENNASELECTIONS_MAXLENGTH) {
		capwap_logging_debug("Invalid IEEE 802.11 Antenna element");
		return NULL;
	}

	/* */
	data = (struct capwap_80211_antenna_element*)capwap_alloc(sizeof(struct capwap_80211_antenna_element));
	memset(data, 0, sizeof(struct capwap_80211_antenna_element));
	data->selections = capwap_array_create(sizeof(uint8_t), 0, 1);

	/* Retrieve data */
	func->read_u8(handle, &data->radioid);
	if (!IS_VALID_RADIOID(data->radioid)) {
		capwap_80211_antenna_element_free((void*)data);
		capwap_logging_debug("Invalid IEEE 802.11 Antenna element element: invalid radio");
		return NULL;
	}

	func->read_u8(handle, &data->diversity);
	func->read_u8(handle, &data->combiner);
	func->read_u8(handle, &count);

	/* Check */
	if (count != length) {
		capwap_logging_debug("Invalid IEEE 802.11 Antenna element");
		capwap_free(data);
		return NULL;
	}

	for (i = 0; i < count; i++) {
		func->read_u8(handle, (uint8_t*)capwap_array_get_item_pointer(data->selections, i));
	}

	return data;
}
static void* capwap_80211_antenna_element_clone(void* data) {
	int i;
	struct capwap_80211_antenna_element* cloneelement;
	struct capwap_80211_antenna_element* element = (struct capwap_80211_antenna_element*)data;

	ASSERT(data != NULL);

	cloneelement = capwap_clone(data, sizeof(struct capwap_80211_antenna_element));
	cloneelement->selections = capwap_array_create(sizeof(uint8_t), 0, 1);
	for (i = 0; i < element->selections->count; i++) {
		memcpy(capwap_array_get_item_pointer(cloneelement->selections, i), capwap_array_get_item_pointer(element->selections, i), sizeof(uint8_t));
	}

	return cloneelement;
}
示例#7
0
static void* capwap_acipv6list_element_clone(void* data) {
	int i;
	struct capwap_acipv6list_element* cloneelement;
	struct capwap_acipv6list_element* element = (struct capwap_acipv6list_element*)data;

	ASSERT(data != NULL);

	cloneelement = capwap_clone(data, sizeof(struct capwap_acipv6list_element));
	cloneelement->addresses = capwap_array_create(sizeof(struct in6_addr), 0, 0);
	for (i = 0; i < element->addresses->count; i++) {
		memcpy(capwap_array_get_item_pointer(cloneelement->addresses, i), capwap_array_get_item_pointer(element->addresses, i), sizeof(struct in6_addr));
	}

	return cloneelement;
}
示例#8
0
static void* capwap_acdescriptor_element_clone(void* data) {
	int i;
	struct capwap_acdescriptor_element* cloneelement;
	struct capwap_acdescriptor_element* element = (struct capwap_acdescriptor_element*)data;

	ASSERT(data != NULL);

	cloneelement = capwap_clone(data, sizeof(struct capwap_acdescriptor_element));
	cloneelement->descsubelement = capwap_array_create(sizeof(struct capwap_acdescriptor_desc_subelement), 0, 1);
	for (i = 0; i < element->descsubelement->count; i++) {
		struct capwap_acdescriptor_desc_subelement* desc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(element->descsubelement, i);
		struct capwap_acdescriptor_desc_subelement* clonedesc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(cloneelement->descsubelement, i);

		memcpy(clonedesc, desc, sizeof(struct capwap_acdescriptor_desc_subelement));
		if (desc->length) {
			clonedesc->data = capwap_clone(desc->data, desc->length);
		}
	}

	return cloneelement;
}
void capwap_element_80211_antenna_copy(struct capwap_80211_antenna_element* dst, struct capwap_80211_antenna_element* src) {
	int i;

	ASSERT(dst != NULL);
	ASSERT(src != NULL);

	if (dst->selections) {
		capwap_array_resize(dst->selections, 0);
	} else {
		dst->selections = capwap_array_create(sizeof(uint8_t), 0, 1);
	}

	dst->radioid = src->radioid;
	dst->diversity = src->diversity;
	dst->combiner = src->combiner;

	if (src->selections) {
		for (i = 0; i < src->selections->count; i++) {
			uint8_t* value = (uint8_t*)capwap_array_get_item_pointer(dst->selections, i);
			*value = *(uint8_t*)capwap_array_get_item_pointer(src->selections, i);
		}
	}
}
示例#10
0
static void* capwap_acipv6list_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
	uint16_t length;
	struct capwap_acipv6list_element* data;

	ASSERT(handle != NULL);
	ASSERT(func != NULL);

	length = func->read_ready(handle);
	if ((length >= 16) && (length <= CAPWAP_ACIPV4LIST_MAX_ELEMENTS * 16) && (length % 16)) {
		log_printf(LOG_DEBUG, "Invalid AC IPv6 List element: underbuffer");
		return NULL;
	}

	/* Retrieve data */
	data = (struct capwap_acipv6list_element*)capwap_alloc(sizeof(struct capwap_acipv6list_element));
	data->addresses = capwap_array_create(sizeof(struct in6_addr), 0, 0);
	while (length > 0) {
		struct in6_addr* address = (struct in6_addr*)capwap_array_get_item_pointer(data->addresses, data->addresses->count);
		func->read_block(handle, (uint8_t*)address, sizeof(struct in6_addr));
		length -= 16;
	}

	return data;
}
示例#11
0
int capwap_parsing_packet(struct capwap_packet_rxmng* rxmngpacket, struct capwap_parsed_packet* packet) {
	unsigned short binding;
	unsigned short bodylength;

	ASSERT(rxmngpacket != NULL);
	ASSERT(packet != NULL);

	/* */
	memset(packet, 0, sizeof(struct capwap_parsed_packet));
	packet->rxmngpacket = rxmngpacket;
	packet->messages = capwap_list_create();

	binding = GET_WBID_HEADER(packet->rxmngpacket->header);

	/* Position reader to capwap body */
	memcpy(&rxmngpacket->readpos, &rxmngpacket->readbodypos, sizeof(struct read_block_from_pos));

	/* */
	bodylength = rxmngpacket->ctrlmsg.length - CAPWAP_CONTROL_MESSAGE_MIN_LENGTH;
	while (bodylength > 0) {
		struct capwap_message_element_id id = { .vendor = 0 };
		uint16_t msglength;
		struct capwap_list_item* itemlist;
		struct capwap_message_element_itemlist* messageelement;
		void *element;
		const struct capwap_message_elements_ops* read_ops;

		/* Get type and length */
		rxmngpacket->readerpacketallowed = sizeof(struct capwap_message_element);
		if (rxmngpacket->read_ops.read_u16((capwap_message_elements_handle)rxmngpacket, &id.type) != sizeof(uint16_t) ||
		    rxmngpacket->read_ops.read_u16((capwap_message_elements_handle)rxmngpacket, &msglength) != sizeof(uint16_t) ||
		    msglength > bodylength)
			return INVALID_MESSAGE_ELEMENT;

		/* Allowed to parsing only the size of message element */
		rxmngpacket->readerpacketallowed = msglength;

		/* Check binding */
		if (IS_80211_MESSAGE_ELEMENTS(id) &&
		    (binding != CAPWAP_WIRELESS_BINDING_IEEE80211))
			return UNRECOGNIZED_MESSAGE_ELEMENT;

		log_printf(LOG_DEBUG, "MESSAGE ELEMENT: %d", id.type);

		if (id.type == CAPWAP_ELEMENT_VENDORPAYLOAD_TYPE) {
			struct capwap_message_element_id vendor_id;

			if (msglength < 7) {
				log_printf(LOG_DEBUG, "Invalid Vendor Specific Payload element: underbuffer");
				return INVALID_MESSAGE_ELEMENT;
			}
			if ((msglength - 6) > CAPWAP_VENDORPAYLOAD_MAXLENGTH) {
				log_printf(LOG_DEBUG, "Invalid Vendor Specific Payload element: overbuffer");
				return INVALID_MESSAGE_ELEMENT;
			}

			rxmngpacket->read_ops.read_u32((capwap_message_elements_handle)rxmngpacket, &vendor_id.vendor);
			rxmngpacket->read_ops.read_u16((capwap_message_elements_handle)rxmngpacket, &vendor_id.type);

			log_printf(LOG_DEBUG, "VENDOR MESSAGE ELEMENT: %06x:%d", vendor_id.vendor, vendor_id.type);

			read_ops = capwap_get_message_element_ops(vendor_id);
			log_printf(LOG_DEBUG, "vendor read_ops: %p", read_ops);
			if (read_ops) {
				id = vendor_id;
				element = read_ops->parse((capwap_message_elements_handle)rxmngpacket, &rxmngpacket->read_ops);
			} else {
				read_ops = capwap_get_message_element_ops(id);
				element = capwap_unknown_vendorpayload_element_parsing((capwap_message_elements_handle)rxmngpacket,
										       &rxmngpacket->read_ops, msglength - 6, vendor_id);
			}
		} else {
			/* Reader function */
			read_ops = capwap_get_message_element_ops(id);
			log_printf(LOG_DEBUG, "read_ops: %p", read_ops);

			if (!read_ops)
				return UNRECOGNIZED_MESSAGE_ELEMENT;

			/* Get message element */
			element = read_ops->parse((capwap_message_elements_handle)rxmngpacket, &rxmngpacket->read_ops);
		}

		if (!element)
			return INVALID_MESSAGE_ELEMENT;

		/* */
		itemlist = capwap_get_message_element(packet, id);
		if (read_ops->category == CAPWAP_MESSAGE_ELEMENT_SINGLE) {
			/* Check for multiple message element */
			if (itemlist) {
				return INVALID_MESSAGE_ELEMENT;
			}

			/* Create new message element */
			itemlist = capwap_itemlist_create(sizeof(struct capwap_message_element_itemlist));
			messageelement = (struct capwap_message_element_itemlist*)itemlist->item;
			messageelement->id = id;
			messageelement->category = CAPWAP_MESSAGE_ELEMENT_SINGLE;
			messageelement->data = element;

			/* */
			capwap_itemlist_insert_after(packet->messages, NULL, itemlist);
		}
		else if (read_ops->category == CAPWAP_MESSAGE_ELEMENT_ARRAY) {
			struct capwap_array* arraymessageelement;

			if (itemlist) {
				messageelement = (struct capwap_message_element_itemlist*)itemlist->item;
				arraymessageelement = (struct capwap_array*)messageelement->data;
			} else {
				arraymessageelement = capwap_array_create(sizeof(void*), 0, 0);

				/* */
				itemlist = capwap_itemlist_create(sizeof(struct capwap_message_element_itemlist));
				messageelement = (struct capwap_message_element_itemlist*)itemlist->item;
				messageelement->id = id;
				messageelement->category = CAPWAP_MESSAGE_ELEMENT_ARRAY;
				messageelement->data = (void*)arraymessageelement;

				/* */
				capwap_itemlist_insert_after(packet->messages, NULL, itemlist);
			}

			/* */
			*(void **)capwap_array_get_item_pointer(arraymessageelement, arraymessageelement->count) = element;
		}

		/* Check if read all data of message element */
		if (rxmngpacket->readerpacketallowed) {
			return INVALID_MESSAGE_ELEMENT;
		}

		/* */
		bodylength -= (msglength + sizeof(struct capwap_message_element));
	}

	return PARSING_COMPLETE;
}

/* */
int capwap_validate_parsed_packet(struct capwap_parsed_packet* packet, struct capwap_array* returnedmessage) {
	unsigned short binding;
	struct capwap_resultcode_element* resultcode;

	ASSERT(packet != NULL);
	ASSERT(packet->rxmngpacket != NULL);

	binding = GET_WBID_HEADER(packet->rxmngpacket->header);

	switch (packet->rxmngpacket->ctrlmsg.type) {
		case CAPWAP_DISCOVERY_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_DISCOVERYTYPE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPBOARDDATA) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPDESCRIPTOR) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPFRAMETUNNELMODE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPMACTYPE)) {

				if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
					if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION)) {
						return 0;
					}
				} else {
					return 0;
				}
			}

			break;
		}

		case CAPWAP_DISCOVERY_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ACDESCRIPTION) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ACNAME) &&
				(capwap_get_message_element(packet, CAPWAP_ELEMENT_CONTROLIPV4) || capwap_get_message_element(packet, CAPWAP_ELEMENT_CONTROLIPV6))) {
				return 0;
			}

			/* Check if packet contains Result Code with Error Message */
			resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
			if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
				return 0;
			}

			break;
		}

		case CAPWAP_JOIN_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_LOCATION) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPBOARDDATA) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPDESCRIPTOR) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPNAME) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_SESSIONID) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPFRAMETUNNELMODE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPMACTYPE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ECNSUPPORT) &&
				(capwap_get_message_element(packet, CAPWAP_ELEMENT_LOCALIPV4) || capwap_get_message_element(packet, CAPWAP_ELEMENT_LOCALIPV6))) {

				if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
					if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION)) {
						return 0;
					}
				} else {
					return 0;
				}
			}

			break;
		}

		case CAPWAP_JOIN_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ACDESCRIPTION) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ACNAME) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ECNSUPPORT) &&
				(capwap_get_message_element(packet, CAPWAP_ELEMENT_CONTROLIPV4) || capwap_get_message_element(packet, CAPWAP_ELEMENT_CONTROLIPV6)) &&
				(capwap_get_message_element(packet, CAPWAP_ELEMENT_LOCALIPV4) || capwap_get_message_element(packet, CAPWAP_ELEMENT_LOCALIPV6))) {
				return 0;
			}

			/* Check if packet contains Result Code with Error Message */
			resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
			if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
				return 0;
			}

			break;
		}

		case CAPWAP_CONFIGURATION_STATUS_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ACNAME) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_RADIOADMSTATE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_STATISTICSTIMER) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPREBOOTSTAT)) {

				if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
					if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION)) {
						return 0;
					}
				} else {
					return 0;
				}
			}

			break;
		}

		case CAPWAP_CONFIGURATION_STATUS_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_TIMERS) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_DECRYPTERRORREPORTPERIOD) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_IDLETIMEOUT) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPFALLBACK) &&
				(capwap_get_message_element(packet, CAPWAP_ELEMENT_ACIPV4LIST) || capwap_get_message_element(packet, CAPWAP_ELEMENT_ACIPV6LIST))) {

				return 0;
			}

			/* Check if packet contains Result Code with Error Message */
			resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
			if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
				return 0;
			}

			break;
		}

		case CAPWAP_CONFIGURATION_UPDATE_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ACNAMEPRIORITY) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ACTIMESTAMP) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ADDMACACL) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_TIMERS) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_DECRYPTERRORREPORTPERIOD) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_DELETEMACACL) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_IDLETIMEOUT) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_LOCATION) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_RADIOADMSTATE) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_STATISTICSTIMER) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPFALLBACK) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPNAME) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPSTATICIPADDRESS) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_IMAGEIDENTIFIER) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_VENDORPAYLOAD)) {

				return 0;
			}

			break;
		}

		case CAPWAP_CONFIGURATION_UPDATE_RESPONSE: {
			return 0;
		}

		case CAPWAP_WTP_EVENT_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_DECRYPTERRORREPORTPERIOD) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_DUPLICATEIPV4) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_DUPLICATEIPV6) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPRADIOSTAT) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPREBOOTSTAT) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_DELETESTATION) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_VENDORPAYLOAD)) {

				return 0;
			}

			break;
		}

		case CAPWAP_WTP_EVENT_RESPONSE: {
			return 0;
		}

		case CAPWAP_CHANGE_STATE_EVENT_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RADIOOPRSTATE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE)) {

				return 0;
			}

			break;
		}

		case CAPWAP_CHANGE_STATE_EVENT_RESPONSE: {
			return 0;
		}

		case CAPWAP_ECHO_REQUEST: {
			return 0;
		}

		case CAPWAP_ECHO_RESPONSE: {
			return 0;
		}

		case CAPWAP_IMAGE_DATA_REQUEST: {
			return 0;
		}

		case CAPWAP_IMAGE_DATA_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE)) {
				return 0;
			}

			break;
		}

		case CAPWAP_RESET_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_IMAGEIDENTIFIER)) {
				return 0;
			}

			break;
		}

		case CAPWAP_RESET_RESPONSE: {
			return 0;
		}

		case CAPWAP_PRIMARY_DISCOVERY_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_DISCOVERYTYPE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPBOARDDATA) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPDESCRIPTOR) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPFRAMETUNNELMODE) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_WTPMACTYPE)) {

				if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
					if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION)) {
						return 0;
					}
				} else {
					return 0;
				}
			}

			break;
		}

		case CAPWAP_PRIMARY_DISCOVERY_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ACDESCRIPTION) &&
				capwap_get_message_element(packet, CAPWAP_ELEMENT_ACNAME) &&
				(capwap_get_message_element(packet, CAPWAP_ELEMENT_CONTROLIPV4) || capwap_get_message_element(packet, CAPWAP_ELEMENT_CONTROLIPV6))) {
				return 0;
			}

			/* Check if packet contains Result Code with Error Message */
			resultcode = (struct capwap_resultcode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_RESULTCODE);
			if (resultcode && !CAPWAP_RESULTCODE_OK(resultcode->code)) {
				return 0;
			}

			break;
		}

		case CAPWAP_DATA_TRANSFER_REQUEST: {
			/* TODO */
			break;
		}

		case CAPWAP_DATA_TRANSFER_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE)) {
				return 0;
			}

			break;
		}

		case CAPWAP_CLEAR_CONFIGURATION_REQUEST: {
			return 0;
		}

		case CAPWAP_CLEAR_CONFIGURATION_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE)) {
				return 0;
			}

			break;
		}

		case CAPWAP_STATION_CONFIGURATION_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_ADDSTATION)) {
				if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
					if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_STATION)) {
						return 0;
					}
				} else {
					return 0;
				}
			} else if (capwap_get_message_element(packet, CAPWAP_ELEMENT_DELETESTATION)) {
				return 0;
			}

			break;
		}

		case CAPWAP_STATION_CONFIGURATION_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE)) {
				return 0;
			}

			break;
		}

		case CAPWAP_IEEE80211_WLAN_CONFIGURATION_REQUEST: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_ADD_WLAN) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_UPDATE_WLAN) ||
				capwap_get_message_element(packet, CAPWAP_ELEMENT_80211_DELETE_WLAN)) {

				return 0;
			}

			break;
		}

		case CAPWAP_IEEE80211_WLAN_CONFIGURATION_RESPONSE: {
			if (capwap_get_message_element(packet, CAPWAP_ELEMENT_RESULTCODE)) {
				return 0;
			}

			break;
		}
	}

	return -1;
}
示例#12
0
static void* capwap_acdescriptor_element_parsing(capwap_message_elements_handle handle, struct capwap_read_message_elements_ops* func) {
	struct capwap_acdescriptor_element* data;

	ASSERT(handle != NULL);
	ASSERT(func != NULL);

	if (func->read_ready(handle) < 12) {
		log_printf(LOG_DEBUG, "Invalid AC Descriptor element: underbuffer");
		return NULL;
	}

	/* */
	data = (struct capwap_acdescriptor_element*)capwap_alloc(sizeof(struct capwap_acdescriptor_element));
	memset(data, 0, sizeof(struct capwap_acdescriptor_element));
	data->descsubelement = capwap_array_create(sizeof(struct capwap_acdescriptor_desc_subelement), 0, 1);

	/* Retrieve data */
	func->read_u16(handle, &data->stations);
	func->read_u16(handle, &data->stationlimit);
	func->read_u16(handle, &data->activewtp);
	func->read_u16(handle, &data->maxwtp);

	/* Check */
	if (data->stations > data->stationlimit) {
		log_printf(LOG_DEBUG, "Invalid AC Descriptor element: stations > stationlimit");
		capwap_acdescriptor_element_free(data);
		return NULL;
	} else if (data->activewtp > data->maxwtp) {
		log_printf(LOG_DEBUG, "Invalid AC Descriptor element: activewtp > maxwtp");
		capwap_acdescriptor_element_free(data);
		return NULL;
	}

	/* */
	func->read_u8(handle, &data->security);
	func->read_u8(handle, &data->rmacfield);
	func->read_u8(handle, NULL);
	func->read_u8(handle, &data->dtlspolicy);

	/* */
	if (data->security & ~CAPWAP_ACDESC_SECURITY_MASK) {
		log_printf(LOG_DEBUG, "Invalid AC Descriptor element: security");
		capwap_acdescriptor_element_free(data);
		return NULL;
	} else if (data->dtlspolicy & ~CAPWAP_ACDESC_DTLS_POLICY_MASK) {
		log_printf(LOG_DEBUG, "Invalid AC Descriptor element: dtlspolicy");
		capwap_acdescriptor_element_free(data);
		return NULL;
	} else if ((data->rmacfield != CAPWAP_ACDESC_RMACFIELD_SUPPORTED) && (data->rmacfield != CAPWAP_ACDESC_RMACFIELD_NOTSUPPORTED)) {
		log_printf(LOG_DEBUG, "Invalid AC Descriptor element: rmacfield");
		capwap_acdescriptor_element_free(data);
		return NULL;
	}

	/* Description Subelement */
	while (func->read_ready(handle) > 0) {
		unsigned short length;
		struct capwap_acdescriptor_desc_subelement* desc = (struct capwap_acdescriptor_desc_subelement*)capwap_array_get_item_pointer(data->descsubelement, data->descsubelement->count);

		/* */
		func->read_u32(handle, &desc->vendor);
		func->read_u16(handle, &desc->type);
		func->read_u16(handle, &desc->length);

		if ((desc->type != CAPWAP_ACDESC_SUBELEMENT_HARDWAREVERSION) && (desc->type != CAPWAP_ACDESC_SUBELEMENT_SOFTWAREVERSION)) {
			log_printf(LOG_DEBUG, "Invalid AC Descriptor subelement: type");
			capwap_acdescriptor_element_free(data);
			return NULL;
		}

		/* Check buffer size */
		length = func->read_ready(handle);
		if ((length > CAPWAP_ACDESC_SUBELEMENT_MAXDATA) || (length < desc->length)) {
			log_printf(LOG_DEBUG, "Invalid AC Descriptor subelement: length");
			capwap_acdescriptor_element_free(data);
			return NULL;
		}

		desc->data = (uint8_t*)capwap_alloc(desc->length + 1);
		func->read_block(handle, desc->data, desc->length);
		desc->data[desc->length] = 0;
	}

	return data;
}
示例#13
0
int wtp_radio_setconfiguration(struct capwap_parsed_packet* packet)
{
	int i;
	int result = 0;
	struct capwap_array* updateitems;

	ASSERT(packet != NULL);

	/* */
	updateitems = capwap_array_create(sizeof(struct wtp_update_configuration_item), 0, 1);

	/* */
	switch (GET_WBID_HEADER(packet->rxmngpacket->header)) {
	case CAPWAP_WIRELESS_BINDING_IEEE80211:
		wtp_radio_setconfiguration_80211(packet, updateitems);
		break;
	}

	log_printf(LOG_DEBUG, "wtp_radio_setconfiguration result #1: %d", result);

	/* Update radio frequency */
	for (i = 0; (i < updateitems->count) && !result; i++) {
		struct wtp_update_configuration_item* item =
			(struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, i);

		switch (item->type) {
		case WTP_UPDATE_FREQUENCY_DSSS:
			result = wifi_device_setfrequency(item->radio->devicehandle, WIFI_BAND_2GHZ,
							  item->radio->radioinformation.radiotype,
							  item->radio->directsequencecontrol.currentchannel);
			break;

		case WTP_UPDATE_FREQUENCY_OFDM:
			result = wifi_device_setfrequency(item->radio->devicehandle, WIFI_BAND_5GHZ,
							  item->radio->radioinformation.radiotype,
							  item->radio->ofdmcontrol.currentchannel);
			break;
		}
	}

	log_printf(LOG_DEBUG, "wtp_radio_setconfiguration result #2: %d", result);

	/* Update radio configuration */
	for (i = 0; (i < updateitems->count) && !result; i++) {
		struct wtp_update_configuration_item* item =
			(struct wtp_update_configuration_item*)capwap_array_get_item_pointer(updateitems, i);

		switch (item->type) {
		case WTP_UPDATE_RATES:
			result = wifi_device_updaterates(item->radio->devicehandle,
							 item->radio->rateset.rateset,
							 item->radio->rateset.ratesetcount);
			break;

		case WTP_UPDATE_CONFIGURATION: {
			struct device_setconfiguration_params params;

			memset(&params, 0, sizeof(struct device_setconfiguration_params));
			params.shortpreamble = ((item->radio->radioconfig.shortpreamble == CAPWAP_WTP_RADIO_CONF_SHORTPREAMBLE_ENABLE) ? 1 : 0);
			params.maxbssid = item->radio->radioconfig.maxbssid;
			params.dtimperiod = item->radio->radioconfig.dtimperiod;
			memcpy(params.bssid, item->radio->radioconfig.bssid, ETH_ALEN);
			params.beaconperiod = item->radio->radioconfig.beaconperiod;
			memcpy(params.country, item->radio->radioconfig.country, WIFI_COUNTRY_LENGTH);
			result = wifi_device_setconfiguration(item->radio->devicehandle, &params);
			break;
		}

		case WTP_UPDATE_TX_QUEUE:
			result = wifi_device_settxqueue(item->radio->devicehandle, &item->radio->qos);
			break;
		}
	}

	log_printf(LOG_DEBUG, "wtp_radio_setconfiguration result #3: %d", result);

	/* */
	capwap_array_free(updateitems);
	return result;
}
示例#14
0
static uint32_t ac_dfa_state_join_create_response(struct ac_session_t* session, struct capwap_parsed_packet* packet, struct ac_soap_response* response, struct capwap_packet_txmng* txmngpacket) {
	int i;
	int j;
	int length;
	struct json_object* jsonroot;
	struct json_object* jsonelement;
	struct capwap_list* controllist;
	struct capwap_list_item* item;
	unsigned short binding = GET_WBID_HEADER(packet->rxmngpacket->header);

	/* Receive SOAP response with JSON result
		{
			WTPRadioInformation: [
				<IEEE 802.11 BINDING>
				IEEE80211WTPRadioInformation: {
					RadioID: [int],
					Mode: [int]
				}
			]
			ACIPv4List: [
				{
					ACIPAddress: [string]
				}
			],
			ACIPv6List: [
				{
					ACIPAddress: [string]
				}
			]
			<IEEE 802.11 BINDING>
			WTPRadio: [
				{
					RadioID: [int],
					IEEE80211WTPRadioInformation: {
						Mode: [int]
					}
				}
			]
		}
	*/

	/* Add message elements response, every local value can be overwrite from backend server */
	jsonroot = ac_soapclient_parse_json_response(response);
	if (!jsonroot) {
		return CAPWAP_RESULTCODE_FAILURE;
	}

	/* AC Descriptor */
	ac_update_statistics();
	capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ACDESCRIPTION, &g_ac.descriptor);

	/* AC Name */
	capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ACNAME, &g_ac.acname);

	/* WTP Radio Information */
	if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
		struct ac_json_ieee80211_wtpradio wtpradio;
		struct capwap_array* wtpradioinformation = (struct capwap_array*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION);

		/* */
		ac_json_ieee80211_init(&wtpradio);

		/* */
		jsonelement = compat_json_object_object_get(jsonroot, IEEE80211_BINDING_JSON_ROOT);
		if (jsonelement) {
			ac_json_ieee80211_parsingjson(&wtpradio, jsonelement);
		}

		/* Copy WTP Radio Information if not present into SOAP response */
		for (i = 0; i < wtpradioinformation->count; i++) {
			ac_json_ieee80211_addmessageelement(&wtpradio, CAPWAP_ELEMENT_80211_WTPRADIOINFORMATION, *(struct capwap_80211_wtpradioinformation_element**)capwap_array_get_item_pointer(wtpradioinformation, i), 0);
		}

		/* */
		ac_json_ieee80211_buildpacket(&wtpradio, txmngpacket);

		/* Free resource */
		ac_json_ieee80211_free(&wtpradio);
	}

	/* ECN Support */
	capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ECNSUPPORT, &session->dfa.ecn);

	/* Get information from any local address */
	controllist = capwap_list_create();
	ac_get_control_information(controllist);

	/* CAPWAP Control IP Address */
	for (item = controllist->first; item != NULL; item = item->next) {
		struct ac_session_control* sessioncontrol = (struct ac_session_control*)item->item;

		if (sessioncontrol->localaddress.ss.ss_family == AF_INET) {
			struct capwap_controlipv4_element element;

			memcpy(&element.address, &((struct sockaddr_in*)&sessioncontrol->localaddress)->sin_addr, sizeof(struct in_addr));
			element.wtpcount = sessioncontrol->count;
			capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_CONTROLIPV4, &element);
		} else if (sessioncontrol->localaddress.ss.ss_family == AF_INET6) {
			struct capwap_controlipv6_element element;

			memcpy(&element.address, &((struct sockaddr_in6*)&sessioncontrol->localaddress)->sin6_addr, sizeof(struct in6_addr));
			element.wtpcount = sessioncontrol->count;
			capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_CONTROLIPV6, &element);
		}
	}

	capwap_list_free(controllist);

	/* CAPWAP Local IP Address */
	if (session->dtls.localaddr.ss.ss_family == AF_INET) {
		struct capwap_localipv4_element addr;

		memcpy(&addr.address, &session->dtls.localaddr.sin.sin_addr, sizeof(struct in_addr));
		capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_LOCALIPV4, &addr);
	} else if (session->dtls.localaddr.ss.ss_family == AF_INET6) {
		struct capwap_localipv6_element addr;

		memcpy(&addr.address, &session->dtls.localaddr.sin6.sin6_addr, sizeof(struct in6_addr));
		capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_LOCALIPV6, &addr);
	}

	/* ACIPv4List */
	jsonelement = NULL;
	if (jsonroot) {
		jsonelement = compat_json_object_object_get(jsonroot, "ACIPv4List");
		if (jsonelement && (json_object_get_type(jsonelement) == json_type_array)) {
			length = json_object_array_length(jsonelement);
		} else {
			jsonelement = NULL;
		}
	}

	if (jsonelement) {
		struct capwap_acipv4list_element* responseacipv4list;

		responseacipv4list = (struct capwap_acipv4list_element*)capwap_alloc(sizeof(struct capwap_acipv4list_element));
		responseacipv4list->addresses = capwap_array_create(sizeof(struct in_addr), 0, 0);

		for (j = 0; j < length; j++) {
			struct json_object* jsonvalue = json_object_array_get_idx(jsonelement, j);
			if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_object)) {
				struct json_object* jsonitem;

				/* ACIPAddress */
				jsonitem = compat_json_object_object_get(jsonvalue, "ACIPAddress");
				if (jsonitem && (json_object_get_type(jsonitem) == json_type_string)) {
					const char* value = json_object_get_string(jsonitem);
					if (value) {
						union sockaddr_capwap address;
						if (capwap_address_from_string(value, &address)) {
							/* Accept only IPv4 address */
							if (address.ss.ss_family == AF_INET) {
								struct in_addr* responseaddress_in = (struct in_addr*)capwap_array_get_item_pointer(responseacipv4list->addresses, responseacipv4list->addresses->count);
								memcpy(responseaddress_in, &address.sin.sin_addr, sizeof(struct in_addr));
							}
						}
					}
				}
			}
		}

		if (responseacipv4list->addresses->count > 0) {
			capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ACIPV4LIST, responseacipv4list);
		}

		capwap_array_free(responseacipv4list->addresses);
		capwap_free(responseacipv4list);
	} else if (session->dfa.acipv4list.addresses->count > 0) {
		capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ACIPV4LIST, &session->dfa.acipv4list);
	}

	/* ACIPv6List */
	jsonelement = NULL;
	if (jsonroot) {
		jsonelement = compat_json_object_object_get(jsonroot, "ACIPv6List");
		if (jsonelement && (json_object_get_type(jsonelement) == json_type_array)) {
			length = json_object_array_length(jsonelement);
		} else {
			jsonelement = NULL;
		}
	}

	if (jsonelement) {
		int j;
		struct capwap_acipv6list_element* responseacipv6list;

		responseacipv6list = (struct capwap_acipv6list_element*)capwap_alloc(sizeof(struct capwap_acipv6list_element));
		responseacipv6list->addresses = capwap_array_create(sizeof(struct in6_addr), 0, 0);

		for (j = 0; j < length; j++) {
			struct json_object* jsonvalue = json_object_array_get_idx(jsonelement, j);
			if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_object)) {
				struct json_object* jsonitem;

				/* ACIPAddress */
				jsonitem = compat_json_object_object_get(jsonvalue, "ACIPAddress");
				if (jsonitem && (json_object_get_type(jsonitem) == json_type_string)) {
					const char* value = json_object_get_string(jsonitem);
					if (value) {
						union sockaddr_capwap address;
						if (capwap_address_from_string(value, &address)) {
							/* Accept only IPv6 address */
							if (address.ss.ss_family == AF_INET6) {
								struct in6_addr* responseaddress_in6 = (struct in6_addr*)capwap_array_get_item_pointer(responseacipv6list->addresses, responseacipv6list->addresses->count);
								memcpy(responseaddress_in6, &address.sin6.sin6_addr, sizeof(struct in6_addr));
							}
						}
					}
				}
			}
		}

		if (responseacipv6list->addresses->count > 0) {
			capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ACIPV6LIST, responseacipv6list);
		}

		capwap_array_free(responseacipv6list->addresses);
		capwap_free(responseacipv6list);
	} else if (session->dfa.acipv6list.addresses->count > 0) {
		capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ACIPV6LIST, &session->dfa.acipv6list);
	}

	/* CAPWAP Transport Protocol */
	capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_TRANSPORT, &session->dfa.transport);

	/* CAPWAP_ELEMENT_IMAGEIDENTIFIER */				/* TODO */
	/* CAPWAP_ELEMENT_MAXIMUMLENGTH */					/* TODO */
	/* CAPWAP_ELEMENT_VENDORPAYLOAD */					/* TODO */

	if (jsonroot) {
		json_object_put(jsonroot);
	}

	return CAPWAP_RESULTCODE_SUCCESS;
}