⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipcevents.c

📁 linux 下通过802.1认证的安装包
💻 C
字号:
/**
 * Licensed under the dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \file ipcevents.c
 *
 * \author chris@open1x.org
 *
 * $Id: ipcevents.c,v 1.1.2.28 2008/01/21 22:51:50 chessing Exp $
 * $Date: 2008/01/21 22:51:50 $
 **/

#ifndef WINDOWS
#include <string.h>
#include <unistd.h>
#endif

#include <libxml/parser.h>

#include <xsupgui.h>
#include <xsupgui_xml_common.h>
#include <xsupgui_request.h>
#include <xsupgui_events.h>
#include <xsupgui_events_state.h>
#include "../../src/ipc_events_index.h"

#ifdef WINDOWS
#include <windows.h>
#endif

void state_transition(char *intf, int sm, int oldstate, int newstate)
{
	char *state = NULL, *oldstatestr = NULL, *newstatestr = NULL;

	state = xsupgui_events_state_get_statemachine_str(sm);

	switch (sm)
	{
	case IPC_STATEMACHINE_PHYSICAL:
		oldstatestr = xsupgui_events_state_get_wireless_state_str(oldstate);
		newstatestr = xsupgui_events_state_get_wireless_state_str(newstate);
		break;

	case IPC_STATEMACHINE_8021X:
		oldstatestr = xsupgui_events_state_get_8021X_state_str(oldstate);
		newstatestr = xsupgui_events_state_get_8021X_state_str(newstate);
		break;

	case IPC_STATEMACHINE_8021X_BACKEND:
		oldstatestr = xsupgui_events_state_get_8021Xbe_state_str(oldstate);
		newstatestr = xsupgui_events_state_get_8021Xbe_state_str(newstate);
		break;

	case IPC_STATEMACHINE_EAP:
		oldstatestr = xsupgui_events_state_get_eap_state_str(oldstate);
		newstatestr = xsupgui_events_state_get_eap_state_str(newstate);
		break;

	default:
		oldstatestr = NULL;
		newstatestr = NULL;
		break;
	}

	printf("%s state machine transitioned from %s to %s on interface %s.\n\n", 
		state, oldstatestr, newstatestr, intf);

	free(state);
	free(oldstatestr);
	free(newstatestr);
}

/**
 * \brief Parse the TNC UI batch event, and display it's information.
 **/
void ipcevents_parse_tnc_ui_batch_request_event()
{
	uint32_t oui, msgid, imcID, connID;
	tnc_msg_batch *data;
	int i = 0;

	if (xsupgui_events_get_tnc_ui_batch_request_event(&imcID, &connID, &oui, &msgid, &data) == 0)
	{
		printf("Got a message from OUI %d with message ID of %d.\n", oui, msgid);

		if (data == NULL)
		{
			printf("Didn't get an data!?\n");
			return;
		}

		while (data[i].oui != 0)
		{
			printf("\tIMC ID        : %d\n", data[i].imcID);
			printf("\tConnection ID : %d\n", data[i].connectionID);
			printf("\tMessage OUI   : %d\n", data[i].oui);
			printf("\tMessage ID    : %d\n", data[i].msgid);
			printf("\tParameter     : %s\n", data[i].parameter);
			printf("\n");
			i++;
		}

		xsupgui_events_free_tnc_msg_batch_data(&data);
	}
}

int ipcevents_get_ui_string(int uievt, char **desc)
{
	switch (uievt)
	{
	case IPC_EVENT_UI_IP_ADDRESS_SET:
		(*desc) = strdup("An interface has had it's IP address set!\n");
		break;

	case IPC_EVENT_INTERFACE_INSERTED:
		(*desc) = strdup("An interface has been inserted.\n");
		break;

	case IPC_EVENT_INTERFACE_REMOVED:
		(*desc) = strdup("An interface has been removed.\n");
		break;

	case IPC_EVENT_SIGNAL_STRENGTH:
		(*desc) = strdup("Signal strength was updated.\n");
		break;

	default:
		(*desc) = strdup("An unknown UI event occurred.\n");
		break;
	}

	return 0;
}


int main()
{
	long int result = 0;
	char *logline, *ints, *connname, *eapmethod, *chalstr, *arg;
	int cur_debug_level = 10;   ///< The user defined debug level in use.
	int sm = 0, oldstate = 0, newstate = 0, evttype = 0;
	uint32_t value321, value322, value323, value324, tncconnectionid;
	int uievt;
	int count = 0;

	printf("Attempting to connect to the supplicant event listener.\n");

	while (xsupgui_connect_event_listener() != 0)
	{
		printf("Supplicant doesn't appear to be alive.  Will check again in 1 second.\n");
#ifdef WINDOWS
		Sleep(1000);
#else
		sleep(1);
#endif
	}

	printf("\n\nWaiting for events. . . .\n\n");

	// -1 is a parser error, -2 means the connection was terminated.
	while (result >= -1)
	{
		result = xsupgui_process(&evttype);

		if (result != REQUEST_SUCCESS)
		{
			printf("Error getting data : %d\n", result);
		}

		if (result == REQUEST_SUCCESS)
		{
			switch (evttype)
			{
			case IPC_EVENT_LOG:
				// Process a log message.
				result = xsupgui_events_generate_log_string(&ints, &logline);
				if ((result <= cur_debug_level) && (result == REQUEST_SUCCESS))
				{
					printf("Log event for interface %s :\n", ints);
					printf("\t%s\n\n", logline);
				}

				if (ints != NULL) free(ints);
				if (logline != NULL) free(logline);			
				break;

			case IPC_EVENT_ERROR:
				// Process an error message.
				result = xsupgui_events_get_error(&uievt, &logline);
				if (result == 0)
				{
					printf("Error (%d) : %s\n", uievt, logline);
					free(logline);
				}
				break;

			case IPC_EVENT_UI:
				// Process a UI event.
				result = xsupgui_events_get_ui_event(&uievt, &ints, &arg); 
				if (result == 0)
				{
					result = ipcevents_get_ui_string(uievt, &logline);
					if (result == 0)
					{
						printf("Got UI Event : %s\n", logline);
						if (uievt == IPC_EVENT_SIGNAL_STRENGTH)
						{
							printf("\tSignal Strength : %s%%\n", arg);
						}	

						free(logline);
					}
					else
					{
						printf("Couldn't get UI event string!\n");
					}

					if (ints != NULL) free(ints);
					if (arg != NULL) free(arg);
				}
				else
				{
					printf("Couldn't parse UI event!\n");
				}
				break;

			case IPC_EVENT_STATEMACHINE:
				// Process a state machine message.
				result = xsupgui_events_get_state_change(&ints, &sm, &oldstate, &newstate, &tncconnectionid);
				state_transition(ints, sm, oldstate, newstate);
				free(ints);
				ints = NULL;
				break;

			case IPC_EVENT_SCAN_COMPLETE:
				// Process a scan complete event.
				result = xsupgui_events_get_scan_complete_interface(&ints);
				printf("Scan complete on interface %s.\n", ints);
				free(ints);
				ints = NULL;
				break;

			case IPC_EVENT_REQUEST_PWD:
				// Process a password request event.
				result = xsupgui_events_get_passwd_challenge(&connname, &eapmethod, &chalstr);
				printf("Password requested for connection '%s'!\n", connname);
				printf("\tEAP method       : %s\n", eapmethod);
				printf("\tChallenge String : %s\n", chalstr);
				free(connname);
				free(eapmethod);
				free(chalstr);
				break;

			case IPC_EVENT_TNC_UI:
				if (xsupgui_events_get_tnc_ui_event(&value321, &value322) == 0)
				{
					printf("Got a TNC UI event.\n");
					printf("\tOUI          : %d\n", value321);
					printf("\tNotification : %d\n", value322);
				}
				break;

			case IPC_EVENT_TNC_UI_REQUEST:
				if (xsupgui_events_get_tnc_ui_request_event(&value321, &value322, &value323, &value324) == 0)
				{
					printf("Got a TNC UI request response event.\n");
					printf("IMC ID          : %d\n", value321);
					printf("Connection ID   : %d\n", value322);
					printf("OUI             : %d\n", value323);
					printf("Request         : %d\n", value324);
				}
				break;

			case IPC_EVENT_TNC_UI_BATCH_REQUEST:
				ipcevents_parse_tnc_ui_batch_request_event();
				break;

			case IPC_EVENT_COM_BROKEN:
				printf("Communication with the supplicant has been broken.\n");
				result = -2;  // To break out of the loop.
				break;

			default:
				printf("Unknown event received!  (Event : %ld)\n", result);
				break;
			}

			xsupgui_free_event_doc();
		}

		count++;
	}

	printf("Pipe was disconnected, or got an error.\n");
	xsupgui_disconnect_event_listener();

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -