Exemplo n.º 1
0
void CEmulatorCmd::PrintAvailableCmds()
{
	LOG_SCREEN("\n");
	LOG_SCREEN("q - Quit the emulator program\n");
	LOG_SCREEN("p - Print the current Emulator database\n");
	LOG_SCREEN("s - Send indication to specific group\n");
	LOG_SCREEN("d - Disconnect any connected client\n");
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// PUBLIC FUNCTIONS /////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
int EDT_StartThirdPartyLog()
{
	LOG(EDT_LINE_BREAK);
	LOG(L"<EDT_THIRDPARTYLOG_START>\n");
	LOG(EDT_LINE_BREAK);
	LOG_SCREEN(L"searching for related processes...\r\n");

	processPresenceMap mapProcessPresence; 
	mapProcessPresence.insert(processPresenceItem(L"accoca.exe",false));
	mapProcessPresence.insert(processPresenceItem(L"pthosttr.exe",false));
	mapProcessPresence.insert(processPresenceItem(L"accrdsub.exe",false));
	mapProcessPresence.insert(processPresenceItem(L"acevents.exe",false));
	mapProcessPresence.insert(processPresenceItem(L"asghost.exe",false));
	mapProcessPresence.insert(processPresenceItem(L"ac_sharedstore.exe",false));
	mapProcessPresence.insert(processPresenceItem(L"beid35xsign.exe",false));

	int iReturnCode = EDT_process_logList(&mapProcessPresence);

	if (iReturnCode==EDT_OK)
	{
		LOG(L"HP Protect Tools Processes:\n");
		LogIncIndent();
		EDT_process_logProcessPresenceMap(&mapProcessPresence);
		LogDecIndent();
	}
	LOG(EDT_LINE_BREAK);
	LOG(L"<EDT_THIRDPARTYLOG_STOP>\n");
	LOG(EDT_LINE_BREAK);

	return iReturnCode;
}
static void* accept_callback(void *context)
{
	int return_value = 0;
	sensor_context *sensor = NULL;
	peer *client = NULL;

	sensor = (sensor_context*)context;

	client = (peer*)malloc(sizeof(peer));
	if(!client)
	{
		LOG_DEBUG(("DEBUG: Out of memory\n"));
		return (NULL);
	}

	client->sensor = context;
	client->comm_socket_fd = accept(sensor->server_socket_fd, (struct sockaddr*)NULL, NULL);
	if(client->comm_socket_fd < 0)
	{
		LOG_ERROR(("ERROR: Accept call failed\n"));
		free(client);
		return NULL;
	}

	sensor->recv_peer[sensor->recv_peer_count] = client;
	sensor->recv_peer_count++;

	/* add socket to network read thread */
	return_value = add_socket(sensor->network_thread, client->comm_socket_fd,  (void*)client, &read_callback_peer);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: add_socket() failed\n"));
		free(client);
		return (NULL);
	}
	//client->connection_state = 1;

	LOG_SCREEN(("INFO: All Peers connected successfully\n"));

	if(sensor->send_peer_count == 2 && sensor->recv_peer_count == 2)
	{
		pthread_create(&sensor->set_value_thread, NULL, &set_value_thread, sensor);
	}

	return (NULL);
}
Exemplo n.º 4
0
////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// PUBLIC FUNCTIONS /////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
int EDT_StartCSPLog()
{
	int iReturnCode = EDT_OK;
	int iFunctionCode = EDT_OK;
	bool pkcs11Available = false;
	LOG(EDT_LINE_BREAK);
	LOG(L"<EDT_CSPLOG_START>\n");
	LOG(EDT_LINE_BREAK);
	LOG_SCREEN(L"testing csp...\r\n");

	LOG(L"CSP test\n");
	iReturnCode = EDT_CSP_EnumProviders();

	iFunctionCode = EDT_CSP_FindCards();
	if( (iReturnCode == EDT_OK) && (iFunctionCode!=EDT_OK) )
		iReturnCode = iFunctionCode;

	LOG(EDT_LINE_BREAK);
	LOG(L"<EDT_CSPLOG_STOP>\n");
	LOG(EDT_LINE_BREAK);

	return iReturnCode;
}
Exemplo n.º 5
0
void CEmulatorCmd::StartLoop()
{
	static CString msg("Enter command: [Press '?' for list of available commands]\n");
	static CString input;
	while(true)
	{
		CUtils::WaitForInput(input, msg, false);
		input.ToLower();
		if(input == "q"){
			break;
		}else if(input == "?"){
			PrintAvailableCmds();
		}else if(input == "p"){
			CEIBEmulator::GetInstance().GetDB().Print();
		}else if(input == "s"){
			HandleSendCommand();
		}else if (input == "d"){
			CEIBEmulator::GetInstance().GetHandler().DisconnectClients();
		}else{
			LOG_SCREEN("Unknown command. [Press '?' for list of available commands]\n");
		}

	}
}
Exemplo n.º 6
0
void CEIBRelayServer::InteractiveConf()
{
	START_TRY
		_conf.Load(RELAY_CONF_FILE_NAME);
	END_TRY_START_CATCH_ANY
		_conf.Init();
	END_CATCH

	LOG_SCREEN("*******************************************\n");
	LOG_SCREEN("EIB Relay Server Interactive configuration:\n");
	LOG_SCREEN("*******************************************\n");

	CString sval;
	int ival;
	bool bval;
	if(ConsoleCLI::GetCString("Initial Encryption/Decryption key?",sval, _conf.GetInitialKey())){
		_conf.SetInitialKey(sval);
	}
	if(ConsoleCLI::Getbool("Auto detect EIBServer on local network?",bval,_conf.GetAutoDiscoverEibServer())){
		_conf.SetAutoDiscoverEibServer(bval);
		if(!bval){
			if(ConsoleCLI::GetCString("EIBServer IP Address?",sval,_conf.GetEibIPAddress())){
				_conf.SetEibIPAddress(sval);
			}
			if(ConsoleCLI::Getint("EIB Server port?",ival, _conf.GetEibPort())){
				_conf.SetEibPort(ival);
			}
		}
	}
	
	if(ConsoleCLI::Getint("KNXNet/IP Listening port?",ival, _conf.GetKnxIpPort())){
		_conf.SetKnxIpPort(ival);
	}

	if(ConsoleCLI::GetCString("RELAY Server user name (used to connect to EIB Server)?",sval, _conf.GetName())){
		_conf.SetName(sval);
	}
	if(ConsoleCLI::GetCString("RELAY Server password (used to connect to EIB Server)?",sval, _conf.GetPassword())){
		_conf.SetPassword(sval);
	}

	map<int,CString> map1;
	map1.insert(map1.end(),pair<int,CString>(LOG_LEVEL_ERROR,"ERROR"));
	map1.insert(map1.end(),pair<int,CString>(LOG_LEVEL_INFO,"INFO"));
	map1.insert(map1.end(),pair<int,CString>(LOG_LEVEL_DEBUG,"DEBUG"));
	if(ConsoleCLI::GetStrOption("Program Logging Level?", map1, ival, _conf.GetLogLevel())){
		_conf.SetLogLevel(ival);
	}

	map<CString,CString> map2;
	
#ifdef WIN32
	if(CUtils::EnumNics(map2) && ConsoleCLI::GetStrOption("Choose Interface to listen for new KNX/IP connections", map2, sval, CString(_conf.GetListenInterface()))){
		_conf.SetListenInterface(sval.ToInt());
	}
#else
	if(CUtils::EnumNics(map2) && ConsoleCLI::GetStrOption("Choose Interface to listen for new KNX/IP connections", map2, sval, _conf.GetListenInterface())){
		_conf.SetListenInterface(sval);
	}
#endif
	LOG_SCREEN("Saving configuration to %s...", RELAY_CONF_FILE_NAME);
	if(!_conf.Save(RELAY_CONF_FILE_NAME)){
		throw CEIBException(FileError, "Cannot save configuration to file \"%s\"", RELAY_CONF_FILE_NAME);
	}
	LOG_SCREEN(" [OK]\n");
	_log.SetConsoleColor(GREEN);
	LOG_SCREEN("\nNow you can run EIBRelay Server. the new file will be loaded automatically.");
	_log.SetConsoleColor(WHITE);
	LOG_SCREEN("\n\n");
}
int main(int argc, char*argv[])
{
	char *conf_file_name = NULL;
	FILE *conf_file_pointer = NULL;
	char line[LINE_MAX] = {'\0'};
	char *tokens[TOKEN_MAX] = {NULL};
	int count = 0;
	gateway_create_params gateway_device = {NULL, NULL};
	gateway_handle gateway = NULL;
	int return_value = E_FAILURE;

	LOG_DEBUG(("DEBUG: Number of arguments are: %d\n", argc));

	if(argc<3)
	{
		LOG_ERROR(("ERROR: Please provide configuration file name\n"));
		return (0);
	}

	conf_file_name = argv[1];

	LOG_DEBUG(("DEBUG: Configuration File Name is %s\n", conf_file_name));

	conf_file_pointer = fopen(conf_file_name, "r");
	if(!conf_file_pointer)
	{
		LOG_ERROR(("ERROR: Error in opening configuration file\n"));
		return (0);
	}

	return_value = log_open_output_file(argv[2]);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Unable to open the file for writing\n"));
		return (0);
	}

	/* Read line */
	if(fgets(line, LINE_MAX, conf_file_pointer) == NULL)
	{
		LOG_DEBUG(("DEBUG: Cleanup and return\n"));
		fclose(conf_file_pointer);
		LOG_ERROR(("ERROR: Wrong configuration file\n"));
		return (0);
	}
	str_tokenize(line, ":\n\r", tokens, &count);
	if(count<2)
	{
		LOG_ERROR(("Wrong configuration file\n"));
		fclose(conf_file_pointer);
		return (0);
	}

	str_copy(&gateway_device.gateway_ip_address, tokens[0]);
	str_copy(&gateway_device.gateway_port_no, tokens[1]);
	LOG_DEBUG(("IP Address: %s\n", gateway_device.gateway_ip_address));
	LOG_DEBUG(("Port No: %s\n", gateway_device.gateway_port_no));

	return_value = create_gateway(&gateway, &gateway_device);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Unable to create gateway\n"));
		free(gateway_device.gateway_ip_address);
		free(gateway_device.gateway_port_no);
		fclose(conf_file_pointer);
		return (0);
	}

	LOG_SCREEN(("INFO: Gateway Front End started successfully\n"));
	LOG_SCREEN(("INFO: Output is Redirected to: %s\n", argv[2]));

	char choice;
	printf("Press any key to exit...\n");
	scanf("%c", &choice);

	delete_gateway(gateway);

	free(gateway_device.gateway_ip_address);
	free(gateway_device.gateway_port_no);
	fclose(conf_file_pointer);
	logger_close();
	return (0);
}
void* set_value_thread(void *context)
{
	sensor_context *sensor = NULL;
	message msg;
	int return_value;
	char *tokens[10];
	char line[LINE_MAX];
	int count = 0;
	int start, end, value;

	sensor = (sensor_context*)context;

	msg.type = CURRENT_VALUE;
	while(sensor->run)
	{
		if(!(start <= sensor->clock && sensor->clock < end))
		{
			/* Figure out the value from file */
			if(fgets(line, LINE_MAX, sensor->sensor_value_file_pointer) == NULL)
			{
				LOG_DEBUG(("DEBUG: Seeking to beginning of file"));
				rewind(sensor->sensor_value_file_pointer);
				sensor->clock = 0;
				continue;
			}

			str_tokenize(line, ";\n\r", tokens, &count);
			if(count != 3)
			{
				LOG_ERROR(("ERROR: Wrong sensor temperature value file\n"));
				break;
			}

			start = atoi(tokens[0]);
			end = atoi(tokens[1]);
			if(strcmp (tokens[2], "true") == 0)
			{
				value = 1; 
			}
			else
			{
				value = 0;
			}
			sensor->value = value;
		}

		msg.u.value = sensor->value;
		msg.timestamp = time(NULL);

		pthread_mutex_lock(&sensor->mutex_lock);

		sensor->logical_clock[2]++;
		LOG_SCREEN(("INFO: Event Sent, "));
		LOG_INFO(("INFO: Event Sent, "));
		print_logical_clock_to_screen(sensor->logical_clock);
		print_logical_clock(sensor->logical_clock);
		LOG_INFO(("timestamp: %lu, Motion: %s\n", msg.timestamp, tokens[2]));
		LOG_SCREEN(("timestamp: %lu, Motion: %s\n", msg.timestamp, tokens[2]));
		return_value = write_message(sensor->socket_fd, sensor->logical_clock, &msg);
		if(E_SUCCESS != return_value)
		{
			LOG_ERROR(("ERROR: Error in sending sensor temperature value to gateway\n"));
		}

		for(int index=0; index<sensor->send_peer_count; index++)
		{
			return_value = write_message(sensor->send_peer[index]->comm_socket_fd,
					sensor->logical_clock,
					&msg);
			if(E_SUCCESS != return_value)
			{
				LOG_ERROR(("ERROR: Error in sending sensor temperature value to peer\n"));
			}
		}
		pthread_mutex_unlock(&sensor->mutex_lock);

		sleep(sensor->interval);
		sensor->clock += sensor->interval;
	}

	LOG_DEBUG(("Exiting SetValueThread...\n"));
	return (NULL);
}
int create_sensor(sensor_handle *handle, sensor_create_params *params)
{
	sensor_context *sensor = NULL;
	int return_value = E_FAILURE;

	sensor = (sensor_context*)malloc(sizeof(sensor_context));
	if(NULL == sensor)
	{
		delete_sensor((sensor_handle)sensor);
		LOG_ERROR(("ERROR: Out of memory\n"));
		return (E_OUT_OF_MEMORY);
	}

	memset(sensor, 0, sizeof(sensor_context));
	sensor->interval = 5;
	sensor->sensor_params = params;
	sensor->clock = 0;
	sensor->value = 0;
	sensor->run = 1;
	sensor->recv_peer_count = 0;
	sensor->send_peer_count = 0;

	pthread_mutex_init(&sensor->mutex_lock, NULL);

	sensor->sensor_value_file_pointer = fopen(params->sensor_value_file_name, "r");
	if(!sensor->sensor_value_file_pointer)
	{
		LOG_ERROR(("Unable to open sensor value input file\n"));
		delete_sensor(sensor);
		return (E_FAILURE);
	}

	/* create network read thread */
	return_value = create_network_thread(&sensor->network_thread, params->sensor_ip_address);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Error in creating n/w read thread\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* create connection to server */
	return_value = create_server_socket(&sensor->server_socket_fd, params->sensor_ip_address, params->sensor_port_no);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Error in creating the socket\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* add socket to network read thread */
	return_value = add_socket(sensor->network_thread, sensor->server_socket_fd,  (void*)sensor, &accept_callback);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: add_socket() failed\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* create connection to server */
	return_value = create_socket(&sensor->socket_fd, params->gateway_ip_address, params->gateway_port_no);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Connection to Server failed\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	/* add socket to network read thread */
	return_value = add_socket(sensor->network_thread, sensor->socket_fd,  (void*)sensor, &read_callback);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: add_socket() filed\n"));
		delete_sensor((sensor_handle)sensor);
		return (return_value);
	}

	message msg;

	/* register sensor with gateway */
	msg.type = REGISTER;
	msg.u.s.type = KEY_CHAIN_SENSOR;
	msg.u.s.ip_address = sensor->sensor_params->sensor_ip_address;
	msg.u.s.port_no = sensor->sensor_params->sensor_port_no;
	msg.u.s.area_id = sensor->sensor_params->sensor_area_id;

	return_value = write_message(sensor->socket_fd, sensor->logical_clock, &msg);
	if(E_SUCCESS != return_value)
	{
		LOG_ERROR(("ERROR: Error in registering sensor\n"));
		return (E_FAILURE);
	}

	struct sigaction        actions;
	memset(&actions, 0, sizeof(actions));
	sigemptyset(&actions.sa_mask);
	actions.sa_flags = 0;
	actions.sa_handler = sighand;
	sigaction(SIGALRM,&actions,NULL);

	*handle = sensor;

	LOG_SCREEN(("INFO: Waiting for Peers to connect...\n"));

	return (E_SUCCESS);
}