static void* ac_json_80211_ofdmcontrol_createmessageelement(struct json_object* jsonparent, uint16_t radioid) {
	struct json_object* jsonitem;
	struct capwap_80211_ofdmcontrol_element* ofdmcontrol;

	ofdmcontrol = (struct capwap_80211_ofdmcontrol_element*)capwap_alloc(sizeof(struct capwap_80211_ofdmcontrol_element));
	memset(ofdmcontrol, 0, sizeof(struct capwap_80211_ofdmcontrol_element));
	ofdmcontrol->radioid = radioid;

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "CurrentChan");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		ofdmcontrol->currentchannel = (uint8_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(ofdmcontrol);
		return NULL;
	}

	jsonitem = compat_json_object_object_get(jsonparent, "BandSupport");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		ofdmcontrol->bandsupport = (uint8_t)json_object_get_int(jsonitem) & CAPWAP_OFDMCONTROL_BAND_MASK;
	} else {
		capwap_free(ofdmcontrol);
		return NULL;
	}

	jsonitem = compat_json_object_object_get(jsonparent, "TIThreshold");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		ofdmcontrol->tithreshold = (uint32_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(ofdmcontrol);
		return NULL;
	}

	return ofdmcontrol;
}
static void* ac_json_80211_wtpradiofailalarm_createmessageelement(struct json_object* jsonparent, uint16_t radioid) {
	struct json_object* jsonitem;
	struct capwap_80211_wtpradiofailalarm_element* wtpradiofailalarm;

	wtpradiofailalarm = (struct capwap_80211_wtpradiofailalarm_element*)capwap_alloc(sizeof(struct capwap_80211_wtpradiofailalarm_element));
	memset(wtpradiofailalarm, 0, sizeof(struct capwap_80211_wtpradiofailalarm_element));
	wtpradiofailalarm->radioid = radioid;

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "Type");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		wtpradiofailalarm->type = (uint8_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(wtpradiofailalarm);
		return NULL;
	}

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "Status");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		wtpradiofailalarm->status = (uint8_t)json_object_get_int(jsonitem);
	} else {
		capwap_free(wtpradiofailalarm);
		return NULL;
	}

	return wtpradiofailalarm;
}
static void capwap_80211_ie_element_free(void* data) {
	struct capwap_80211_ie_element* element = (struct capwap_80211_ie_element*)data;

	ASSERT(data != NULL);

	capwap_free(element->ie);
	capwap_free(data);
}
Beispiel #4
0
void capwap_array_free(struct capwap_array* array) {
	ASSERT(array != NULL);

	if (array->buffer) {
		capwap_free(array->buffer);
	}

	capwap_free(array);
}
Beispiel #5
0
void capwap_itemlist_free(struct capwap_list_item* item) {
	ASSERT(item != NULL);
	ASSERT(item->item != NULL);

	if (item->autodelete) {
		capwap_free(item->item);
	}

	capwap_free(item);
}
Beispiel #6
0
void capwap_hash_free(struct capwap_hash* hash) {
	ASSERT(hash != NULL);

	/* Delete all items */
	capwap_hash_deleteall(hash);

	/* Free */
	capwap_free(hash->items);
	capwap_free(hash);
}
static void capwap_datatransferdata_element_free(void* data) {
	struct capwap_datatransferdata_element* element = (struct capwap_datatransferdata_element*)data;

	ASSERT(data != NULL);

	if (element->data) {
		capwap_free(element->data);
	}

	capwap_free(data);
}
static void capwap_acname_element_free(void* data) {
	struct capwap_acname_element* element = (struct capwap_acname_element*)data;

	ASSERT(data != NULL);

	if (element->name) {
		capwap_free(element->name);
	}

	capwap_free(data);
}
static void capwap_location_element_free(void* data) {
	struct capwap_location_element* element = (struct capwap_location_element*)data;

	ASSERT(data != NULL);

	if (element->value) {
		capwap_free(element->value);
	}

	capwap_free(data);
}
static void capwap_duplicateipv6_element_free(void* data) {
	struct capwap_duplicateipv6_element* element = (struct capwap_duplicateipv6_element*)data;

	ASSERT(data != NULL);

	if (element->macaddress) {
		capwap_free(element->macaddress);
	}

	capwap_free(data);
}
static void capwap_addmacacl_element_free(void* data) {
	struct capwap_addmacacl_element* element = (struct capwap_addmacacl_element*)data;

	ASSERT(data != NULL);

	if (element->address) {
		capwap_free(element->address);
	}

	capwap_free(data);
}
Beispiel #12
0
static void ac_execute_free_fdspool(struct ac_fds* fds) {
	ASSERT(fds != NULL);

	if (fds->fdspoll) {
		capwap_free(fds->fdspoll);
	}

	if (fds->kmodevents) {
		capwap_free(fds->kmodevents);
	}
}
Beispiel #13
0
int ac_execute_update_fdspool(struct ac_fds* fds) {
	int totalcount;
	int kmodcount;
	struct pollfd* fdsbuffer;

	ASSERT(fds != NULL);

	/* Retrieve number of Dynamic File Descriptor Event */
	kmodcount = ac_kmod_getfd(NULL, NULL, 0);
	if (kmodcount < 0) {
		return -1;
	}

	/* Kernel Module Events Callback */
	fds->kmodeventsstartpos = -1;
	if (kmodcount != fds->kmodeventscount) {
		if (fds->kmodevents) {
			capwap_free(fds->kmodevents);
		}

		/* */
		fds->kmodeventscount = kmodcount;
		fds->kmodevents = (struct ac_kmod_event*)((kmodcount > 0) ? capwap_alloc(sizeof(struct ac_kmod_event) * kmodcount) : NULL);
	}

	/* Resize poll */
	totalcount = fds->fdsnetworkcount + fds->msgqueuecount + fds->kmodeventscount;
	if (fds->fdstotalcount != totalcount) {
		fdsbuffer = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * totalcount);
		if (fds->fdspoll) {
			int count = fds->fdsnetworkcount + fds->msgqueuecount;
			if (count > 0) {
				memcpy(fdsbuffer, fds->fdspoll, sizeof(struct pollfd) * count);
			}

			capwap_free(fds->fdspoll);
		}

		/* */
		fds->fdspoll = fdsbuffer;
		fds->fdstotalcount = totalcount;
	}

	/* Retrieve File Descriptor Kernel Module Event */
	if (fds->kmodeventscount > 0) {
		fds->kmodeventsstartpos = fds->fdsnetworkcount + fds->msgqueuecount;
		ac_kmod_getfd(&fds->fdspoll[fds->kmodeventsstartpos], fds->kmodevents, fds->kmodeventscount);
	}

	return fds->fdstotalcount;
}
static void capwap_addstation_element_free(void* data) {
	struct capwap_addstation_element* element = (struct capwap_addstation_element*)data;

	ASSERT(data != NULL);

	if (element->vlan) {
		capwap_free(element->vlan);
	}

	if (element->address) {
		capwap_free(element->address);
	}

	capwap_free(element);
}
static void capwap_80211_addwlan_element_free(void* data) {
	struct capwap_80211_addwlan_element* element = (struct capwap_80211_addwlan_element*)data;

	ASSERT(data != NULL);

	if (element->ssid) {
		capwap_free(element->ssid);
	}

	if (element->key) {
		capwap_free(element->key);
	}

	capwap_free(data);
}
Beispiel #16
0
void capwap_timeout_free(struct capwap_timeout* timeout) {
	ASSERT(timeout != NULL);

	capwap_hash_free(timeout->itemsreference);
	capwap_list_free(timeout->itemstimeout);
	capwap_free(timeout);
}
Beispiel #17
0
static int ac_execute_init_fdspool(struct ac_fds* fds, struct capwap_network* net, int fdmsgqueue) {
	ASSERT(fds != NULL);
	ASSERT(net != NULL);
	ASSERT(fdmsgqueue > 0);

	/* */
	memset(fds, 0, sizeof(struct ac_fds));
	fds->fdsnetworkcount = capwap_network_set_pollfd(net, NULL, 0);
	fds->msgqueuecount = 1;
	fds->fdspoll = (struct pollfd*)capwap_alloc(sizeof(struct pollfd) * (fds->fdsnetworkcount + fds->msgqueuecount));

	/* Retrive all socket for polling */
	fds->fdstotalcount = capwap_network_set_pollfd(net, fds->fdspoll, fds->fdsnetworkcount);
	if (fds->fdsnetworkcount != fds->fdstotalcount) {
		capwap_free(fds->fdspoll);
		return -1;
	}

	/* Unix socket message queue */
	fds->msgqueuestartpos = fds->fdsnetworkcount;
	fds->fdspoll[fds->msgqueuestartpos].events = POLLIN | POLLERR | POLLHUP | POLLNVAL;
	fds->fdspoll[fds->msgqueuestartpos].fd = fdmsgqueue;
	fds->fdstotalcount += fds->msgqueuecount;

	return ac_execute_update_fdspool(fds);
}
Beispiel #18
0
void capwap_array_resize(struct capwap_array* array, unsigned long count) {
	int newcount;
	void* newbuffer = NULL;

	ASSERT(array != NULL);
	ASSERT(array->itemsize > 0);

	if (array->count == count) {
		return;
	}

	newcount = min(array->count, count);

	if (count > 0) {
		newbuffer = capwap_alloc(array->itemsize * count);

		/* Zeroed new items */
		if (array->zeroed && (count > newcount)) {
			memset(newbuffer + array->itemsize * newcount, 0, array->itemsize * (count - newcount));
		}
	}

	if (array->buffer) {
		if ((newbuffer != NULL) && (newcount > 0)) {
			memcpy(newbuffer, array->buffer, array->itemsize * newcount);
		}

		capwap_free(array->buffer);
	}

	array->buffer = newbuffer;
	array->count = count;
}
Beispiel #19
0
static void capwap_acipv6list_element_free(void* data) {
	struct capwap_acipv6list_element* element = (struct capwap_acipv6list_element*)data;

	ASSERT(data != NULL);
	
	capwap_array_free(element->addresses);
	capwap_free(data);
}
Beispiel #20
0
int capwap_decrypt_packet(struct capwap_dtls* dtls, void* encrybuffer, int size, void* plainbuffer, int maxsize) {
	int sslerror;
	int result = -1;
	char* clone = NULL;
	
	ASSERT(dtls != NULL);
	ASSERT(dtls->enable != 0);
	ASSERT((dtls->action == CAPWAP_DTLS_ACTION_HANDSHAKE) || (dtls->action == CAPWAP_DTLS_ACTION_DATA));
	ASSERT(dtls->buffer == NULL);
	ASSERT(dtls->length == 0);
	ASSERT(encrybuffer != NULL);
	ASSERT(size > 0);
	ASSERT(maxsize > 0);

	/* */
	if (!plainbuffer) {
		clone = capwap_clone(encrybuffer, size);
	}

	dtls->buffer = (clone ? clone : encrybuffer);
	dtls->length = size;

	/* */	
	if (dtls->action == CAPWAP_DTLS_ACTION_HANDSHAKE) {
		if (capwap_crypt_handshake(dtls) == CAPWAP_HANDSHAKE_ERROR) {
			capwap_logging_debug("Error in DTLS handshake");
			result = CAPWAP_ERROR_CLOSE;			/* Error handshake */
		} else {
			result = CAPWAP_ERROR_AGAIN;			/* Don't parsing DTLS packet */
		}
	} else if (dtls->action == CAPWAP_DTLS_ACTION_DATA) {
		result = CyaSSL_read((CYASSL*)dtls->sslsession, (plainbuffer ? plainbuffer : encrybuffer), maxsize);
		if (!result) {
			dtls->action = CAPWAP_DTLS_ACTION_SHUTDOWN;
			result = CAPWAP_ERROR_SHUTDOWN;
		} else if (result < 0) {
			/* Check error */
			sslerror = CyaSSL_get_error((CYASSL*)dtls->sslsession, 0);
			if ((sslerror == SSL_ERROR_WANT_READ) || (sslerror == SSL_ERROR_WANT_WRITE)) {
				result = CAPWAP_ERROR_AGAIN;			/* DTLS Renegotiation */
			} else {
				result = CAPWAP_ERROR_CLOSE;
			}
		}
	}

	/* Verify BIO read */
	ASSERT(dtls->buffer == NULL);
	ASSERT(dtls->length == 0);

	/* Free clone */
	if (clone) {
		capwap_free(clone);
	}
	
	return result;
}
static void capwap_80211_antenna_element_free(void* data) {
	struct capwap_80211_antenna_element* element = (struct capwap_80211_antenna_element*)data;

	ASSERT(data != NULL);
	ASSERT(element->selections != NULL);

	capwap_array_free(element->selections);
	capwap_free(data);
}
Beispiel #22
0
static void capwap_hash_free_item(struct capwap_hash* hash, struct capwap_hash_item* item) {
	ASSERT(hash != NULL);
	ASSERT(item != NULL);

	if (item->data && hash->item_free) {
		hash->item_free(item->data);
	}

	capwap_free(item);
}
Beispiel #23
0
static unsigned int capwap_crypt_psk_to_bin(char* pskkey, unsigned char** pskbin) {
	int i, j;
	int length;
	int result;
	unsigned char* buffer;

	/* Convert string to hex */
	length = strlen(pskkey);
	if (!length || (length % 2)) {
		return 0;
	}

	/* */
	result = length / 2;
	buffer = (unsigned char*)capwap_alloc(result);
	for (i = 0, j = 0; i < length; i += 2, j++) {
		char valuehi = pskkey[i] - 48;
		char valuelo = pskkey[i + 1] - 48;

		/* Check value */
		if ((valuehi < 0) || (valuehi >= g_char2hex_length) || (valuelo < 0) || (valuelo >= g_char2hex_length)) {
			capwap_free(buffer);
			return 0;
		}

		/* */
		valuehi  = g_char2hex[(int)valuehi];
		valuelo = g_char2hex[(int)valuelo];

		/* Check value */
		if ((valuehi < 0) || (valuelo < 0)) {
			capwap_free(buffer);
			return 0;
		}

		/* */
		buffer[j] = (unsigned char)(((unsigned char)valuehi << 4) | (unsigned char)valuelo);
	}

	/* */
	*pskbin = buffer;
	return result;
}
Beispiel #24
0
static void capwap_acdescriptor_element_free(void* data) {
	int i;
	struct capwap_acdescriptor_element* element = (struct capwap_acdescriptor_element*)data;

	ASSERT(element != NULL);
	ASSERT(element->descsubelement != NULL);

	/* */
	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);

		if (desc->data) {
			capwap_free(desc->data);
		}
	}

	capwap_array_free(element->descsubelement);
	capwap_free(data);
}
Beispiel #25
0
void capwap_crypt_freecontext(struct capwap_dtls_context* dtlscontext) {
	ASSERT(dtlscontext != NULL);

	/* */
	if (dtlscontext->mode == CAPWAP_DTLS_MODE_PRESHAREDKEY) {
		if (dtlscontext->presharedkey.identity) {
			capwap_free(dtlscontext->presharedkey.identity);
		}

		if (dtlscontext->presharedkey.pskkey) {
			capwap_free(dtlscontext->presharedkey.pskkey);
		}
	}

	/* Free context */	
	if (dtlscontext->sslcontext) {
		CyaSSL_CTX_free((CYASSL_CTX*)dtlscontext->sslcontext);
	}

	memset(dtlscontext, 0, sizeof(struct capwap_dtls_context));
}
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* ac_json_80211_wtpradioinformation_createmessageelement(struct json_object* jsonparent, uint16_t radioid) {
	struct json_object* jsonitem;
	struct capwap_80211_wtpradioinformation_element* wtpradioinformation;

	wtpradioinformation = (struct capwap_80211_wtpradioinformation_element*)capwap_alloc(sizeof(struct capwap_80211_wtpradioinformation_element));
	memset(wtpradioinformation, 0, sizeof(struct capwap_80211_wtpradioinformation_element));
	wtpradioinformation->radioid = radioid;

	/* */
	jsonitem = compat_json_object_object_get(jsonparent, "Mode");
	if (jsonitem && (json_object_get_type(jsonitem) == json_type_int)) {
		wtpradioinformation->radiotype = (uint32_t)json_object_get_int(jsonitem) & CAPWAP_RADIO_TYPE_MASK;
	} else {
		capwap_free(wtpradioinformation);
		return NULL;
	}

	return wtpradioinformation;
}
Beispiel #28
0
static struct ac_soap_response* ac_session_action_authorizestation_request(struct ac_session_t* session, uint8_t radioid, uint8_t wlanid, uint8_t* address) {
	const char* jsonmessage;
	char* base64confstatus;
	struct json_object* jsonparam;
	struct ac_soap_response* response;
	char addrtext[CAPWAP_MACADDRESS_EUI48_BUFFER];

	/* Create SOAP request with JSON param
		{
			RadioID: [int],
			WLANID: [int],
			Station: [string],
		}
	*/

	/* */
	jsonparam = json_object_new_object();

	/* RadioID */
	json_object_object_add(jsonparam, "RadioID", json_object_new_int((int)radioid));

	/* WLANID */
	json_object_object_add(jsonparam, "WLANID", json_object_new_int((int)wlanid));

	/* Station */
	json_object_object_add(jsonparam, "Station", json_object_new_string(capwap_printf_macaddress(addrtext, address, MACADDRESS_EUI48_LENGTH)));

	/* Get JSON param and convert base64 */
	jsonmessage = json_object_to_json_string(jsonparam);
	base64confstatus = capwap_alloc(AC_BASE64_ENCODE_LENGTH(strlen(jsonmessage)));
	ac_base64_string_encode(jsonmessage, base64confstatus);

	/* Send message */
	response = ac_soap_authorizestation(session, session->wtpid, base64confstatus);

	/* Free JSON */
	json_object_put(jsonparam);
	capwap_free(base64confstatus);

	return response;
}
static void capwap_80211_ofdmcontrol_element_free(void* data) {
	ASSERT(data != NULL);
	
	capwap_free(data);
}
static void capwap_80211_updatestationqos_element_free(void* data) {
	ASSERT(data != NULL);
	
	capwap_free(data);
}