示例#1
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;
}
示例#2
0
static struct ac_soap_response* ac_dfa_state_join_parsing_request(struct ac_session_t* session, struct capwap_parsed_packet* packet) {
	int i;
	const char* jsonmessage;
	char* base64confstatus;
	struct json_object* jsonarray;
	struct json_object* jsonparam;
	struct json_object* jsonhash;
	struct ac_soap_response* response;
	struct capwap_location_element* location;
	struct capwap_wtpboarddata_element* wtpboarddata;
	struct capwap_wtpdescriptor_element* wtpdescriptor;
	struct capwap_wtpname_element* wtpname;
	struct capwap_wtpframetunnelmode_element* wtpframetunnelmode;
	struct capwap_wtpmactype_element* wtpmactype;
	struct capwap_ecnsupport_element* ecnsupport;
	struct capwap_localipv4_element* localipv4;
	struct capwap_localipv6_element* localipv6;
	struct capwap_wtprebootstat_element* wtprebootstat;
	unsigned short binding = GET_WBID_HEADER(packet->rxmngpacket->header);

	/* Create SOAP request with JSON param
		{
			Binding: {
				Type: [int]
			}
			LocationData: {
				Location: [string]
			},
			WTPBoardData: {
				VendorIdentifier: [int],
				BoardDataSubElement: [
					{
						BoardDataType: [int],
						BoardDataValue: [base64]
					}
				]
			},
			WTPDescriptor: {
				MaxRadios: [int],
				RadiosInUse: [int],
				EncryptionSubElement: [
					{
						WBID: [int],
						EncryptionCapabilities: [int]
					}
				],
				DescriptorSubElement: [
					{
						DescriptorVendorIdentifier: [int],
						DescriptorType: [int],
						DescriptorData: [string]
					}
				]
			},
			WTPName: {
				Name: [string]
			},
			WTPFrameTunnelMode: {
				NativeFrameTunnel: [bool]
				FrameTunnelMode8023: [bool],
				LocalBridge: [bool]
			},
			WTPMACType: {
				Type: [int]
			},
			<IEEE 802.11 BINDING>
			WTPRadio: [
				{
					RadioID: [int],
					IEEE80211WTPRadioInformation: {
						Mode: [int]
					}
				}
			]
			ECNSupport: {
				Mode: [int]
			}
			CAPWAPLocalIPv4Address: {
				Address: [string]
			},
			CAPWAPLocalIPv6Address: {
				Address: [string]
			},
			WTPRebootStatistics: {
				RebootCount: [int],
				ACInitiatedCount: [int],
				LinkFailureCount: [int],
				SWFailureCount: [int],
				HWFailureCount: [int],
				OtherFailureCount: [int],
				UnknownFailureCount: [int],
				LastFailureType: [int]
			}
		}
	*/

	/* */
	jsonparam = json_object_new_object();

	/* Binding */
	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "Type", json_object_new_int((int)binding));
	json_object_object_add(jsonparam, "Binding", jsonhash);

	/* LocationData */
	location = (struct capwap_location_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_LOCATION);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "Location", json_object_new_string((char*)location->value));
	json_object_object_add(jsonparam, "LocationData", jsonhash);

	/* WTPBoardData */
	wtpboarddata = (struct capwap_wtpboarddata_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPBOARDDATA);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "VendorIdentifier", json_object_new_int((int)wtpboarddata->vendor));

	jsonarray = json_object_new_array();
	for (i = 0; i < wtpboarddata->boardsubelement->count; i++) {
		char* base64data;
		int base64length;
		struct json_object* jsonboard;
		struct capwap_wtpboarddata_board_subelement* wtpboarddata_board = (struct capwap_wtpboarddata_board_subelement*)capwap_array_get_item_pointer(wtpboarddata->boardsubelement, i);

		/* Encoded base64 board data */
		base64data = (char*)capwap_alloc(AC_BASE64_ENCODE_LENGTH((int)wtpboarddata_board->length));
		base64length = ac_base64_binary_encode((const char*)wtpboarddata_board->data, (int)wtpboarddata_board->length, base64data);
		base64data[base64length] = 0;

		jsonboard = json_object_new_object();
		json_object_object_add(jsonboard, "BoardDataType", json_object_new_int((int)wtpboarddata_board->type));
		json_object_object_add(jsonboard, "BoardDataValue", json_object_new_string(base64data));
		json_object_array_add(jsonarray, jsonboard);

		capwap_free(base64data);
	}

	json_object_object_add(jsonhash, "BoardDataSubElement", jsonarray);
	json_object_object_add(jsonparam, "WTPBoardData", jsonhash);

	/* WTPDescriptor */
	wtpdescriptor = (struct capwap_wtpdescriptor_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPDESCRIPTOR);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "MaxRadios", json_object_new_int((int)wtpdescriptor->maxradios));
	json_object_object_add(jsonhash, "RadiosInUse", json_object_new_int((int)wtpdescriptor->radiosinuse));

	jsonarray = json_object_new_array();
	for (i = 0; i < wtpdescriptor->encryptsubelement->count; i++) {
		struct json_object* jsonencrypt;
		struct capwap_wtpdescriptor_encrypt_subelement* wtpdescriptor_encrypt = (struct capwap_wtpdescriptor_encrypt_subelement*)capwap_array_get_item_pointer(wtpdescriptor->encryptsubelement, i);

		jsonencrypt = json_object_new_object();
		json_object_object_add(jsonencrypt, "WBID", json_object_new_int((int)wtpdescriptor_encrypt->wbid));
		json_object_object_add(jsonencrypt, "EncryptionCapabilities", json_object_new_int((int)wtpdescriptor_encrypt->capabilities));
		json_object_array_add(jsonarray, jsonencrypt);
	}

	json_object_object_add(jsonhash, "EncryptionSubElement", jsonarray);

	jsonarray = json_object_new_array();
	for (i = 0; i < wtpdescriptor->descsubelement->count; i++) {
		struct json_object* jsondesc;
		struct capwap_wtpdescriptor_desc_subelement* wtpdescriptor_desc = (struct capwap_wtpdescriptor_desc_subelement*)capwap_array_get_item_pointer(wtpdescriptor->descsubelement, i);

		jsondesc = json_object_new_object();
		json_object_object_add(jsondesc, "DescriptorVendorIdentifier", json_object_new_int((int)wtpdescriptor_desc->vendor));
		json_object_object_add(jsondesc, "DescriptorType", json_object_new_int((int)wtpdescriptor_desc->type));
		json_object_object_add(jsondesc, "DescriptorData", json_object_new_string((char*)wtpdescriptor_desc->data));
		json_object_array_add(jsonarray, jsondesc);
	}

	json_object_object_add(jsonhash, "DescriptorSubElement", jsonarray);
	json_object_object_add(jsonparam, "WTPDescriptor", jsonhash);

	/* WTPName */
	wtpname = (struct capwap_wtpname_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPNAME);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "Name", json_object_new_string((char*)wtpname->name));
	json_object_object_add(jsonparam, "WTPName", jsonhash);

	/* WTPFrameTunnelMode */
	wtpframetunnelmode = (struct capwap_wtpframetunnelmode_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPFRAMETUNNELMODE);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "NativeFrameTunnel", json_object_new_boolean(((wtpframetunnelmode->mode & CAPWAP_WTP_NATIVE_FRAME_TUNNEL) ? 1 : 0)));
	json_object_object_add(jsonhash, "FrameTunnelMode8023", json_object_new_boolean(((wtpframetunnelmode->mode & CAPWAP_WTP_8023_FRAME_TUNNEL) ? 1 : 0)));
	json_object_object_add(jsonhash, "LocalBridge", json_object_new_boolean(((wtpframetunnelmode->mode & CAPWAP_WTP_LOCAL_BRIDGING) ? 1 : 0)));
	json_object_object_add(jsonparam, "WTPFrameTunnelMode", jsonhash);

	/* WTPMACType */
	wtpmactype = (struct capwap_wtpmactype_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPMACTYPE);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "Type", json_object_new_int((int)wtpmactype->type));
	json_object_object_add(jsonparam, "WTPMACType", jsonhash);

	/* Binding message */
	if (binding == CAPWAP_WIRELESS_BINDING_IEEE80211) {
		struct ac_json_ieee80211_wtpradio wtpradio;
		struct capwap_list_item* search = packet->messages->first;

		/* Reording message by radioid and management */
		ac_json_ieee80211_init(&wtpradio);

		while (search) {
			struct capwap_message_element_itemlist* messageelement = (struct capwap_message_element_itemlist*)search->item;

			/* Parsing only IEEE 802.11 message element */
			if (IS_80211_MESSAGE_ELEMENTS(messageelement->type)) {
				if (!ac_json_ieee80211_parsingmessageelement(&wtpradio, messageelement)) {
					json_object_put(jsonparam);
					return NULL;
				}
			}

			/* Next */
			search = search->next;
		}

		/* Generate JSON tree */
		jsonarray = ac_json_ieee80211_getjson(&wtpradio);
		json_object_object_add(jsonparam, IEEE80211_BINDING_JSON_ROOT, jsonarray);

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

	/* ECNSupport */
	ecnsupport = (struct capwap_ecnsupport_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_ECNSUPPORT);

	jsonhash = json_object_new_object();
	json_object_object_add(jsonhash, "Mode", json_object_new_int((int)ecnsupport->flag));
	json_object_object_add(jsonparam, "ECNSupport", jsonhash);

	/* CAPWAPLocalIPv4Address */
	localipv4 = (struct capwap_localipv4_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_LOCALIPV4);
	if (localipv4) {
		char ipbuffer[INET_ADDRSTRLEN];

		jsonhash = json_object_new_object();
		json_object_object_add(jsonhash, "Address", json_object_new_string(inet_ntop(AF_INET, (void*)&localipv4->address, ipbuffer, INET_ADDRSTRLEN)));
		json_object_object_add(jsonparam, "CAPWAPLocalIPv4Address", jsonhash);
	}

	/* CAPWAPLocalIPv6Address */
	localipv6 = (struct capwap_localipv6_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_LOCALIPV6);
	if (localipv6) {
		char ipbuffer[INET6_ADDRSTRLEN];

		jsonhash = json_object_new_object();
		json_object_object_add(jsonhash, "Address", json_object_new_string(inet_ntop(AF_INET6, (void*)&localipv6->address, ipbuffer, INET6_ADDRSTRLEN)));
		json_object_object_add(jsonparam, "CAPWAPLocalIPv6Address", jsonhash);
	}

	/* WTPRebootStatistics */
	wtprebootstat = (struct capwap_wtprebootstat_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPREBOOTSTAT);
	if (wtprebootstat) {
		jsonhash = json_object_new_object();
		json_object_object_add(jsonhash, "RebootCount", json_object_new_int((int)wtprebootstat->rebootcount));
		json_object_object_add(jsonhash, "ACInitiatedCount", json_object_new_int((int)wtprebootstat->acinitiatedcount));
		json_object_object_add(jsonhash, "LinkFailureCount", json_object_new_int((int)wtprebootstat->linkfailurecount));
		json_object_object_add(jsonhash, "SWFailureCount", json_object_new_int((int)wtprebootstat->swfailurecount));
		json_object_object_add(jsonhash, "HWFailureCount", json_object_new_int((int)wtprebootstat->hwfailurecount));
		json_object_object_add(jsonhash, "OtherFailureCount", json_object_new_int((int)wtprebootstat->otherfailurecount));
		json_object_object_add(jsonhash, "UnknownFailureCount", json_object_new_int((int)wtprebootstat->unknownfailurecount));
		json_object_object_add(jsonhash, "LastFailureType", json_object_new_int((int)wtprebootstat->lastfailuretype));
		json_object_object_add(jsonparam, "WTPRebootStatistics", jsonhash);
	}

	/* 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_joinwtpsession(session, session->wtpid, base64confstatus);

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

	return response;
}