Exemple #1
0
void CRemoteHandler::link(const wxString& callsign, RECONNECT reconnect, const wxString& reflector, bool respond)
{
	CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(callsign);
	if (repeater == NULL) {
		m_handler.sendNAK(wxT("Invalid repeater callsign"));
		return;
	}

	repeater->link(reconnect, reflector);

	if (respond){
	    m_handler.sendACK();
	}

}
Exemple #2
0
void CRemoteHandler::sendRepeater(const wxString& callsign)
{
	CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(callsign);
	if (repeater == NULL) {
		m_handler.sendNAK(wxT("Invalid repeater callsign"));
		return;
	}

	CRemoteRepeaterData* data = repeater->getInfo();
	if (data != NULL) {
		CDExtraHandler::getInfo(repeater, *data);
		CDPlusHandler::getInfo(repeater, *data);
		CDCSHandler::getInfo(repeater, *data);

		m_handler.sendRepeater(*data);
	}

	delete data;
}
CDDData* CDDHandler::read()
{
	// If we're not initialised, return immediately
	if (m_maxRoutes == 0U)
		return NULL;

#if defined(WIN32)
	return NULL;
#else
	// Check that the read() won't block
	fd_set readFds;
	FD_ZERO(&readFds);
#if defined(__WINDOWS__)
	FD_SET((unsigned int)m_fd, &readFds);
#else
	FD_SET(m_fd, &readFds);
#endif

	// Return immediately
	timeval tv;
	tv.tv_sec  = 0L;
	tv.tv_usec = 0L;

	int ret = ::select(m_fd + 1, &readFds, NULL, NULL, &tv);
	if (ret < 0) {
		wxLogError(wxT("Error returned from select()"));
		return NULL;
	}

#if defined(__WINDOWS__)
	if (!FD_ISSET((unsigned int)m_fd, &readFds))
		return NULL;
#else
	if (!FD_ISSET(m_fd, &readFds))
		return NULL;
#endif

	// Ensure that the minimum length is padded with 0x00s
	::memset(m_buffer, 0x00U, MINIMUM_DD_FRAME_LENGTH);

	ssize_t len = ::read(m_fd, (char*)m_buffer, BUFFER_LENGTH);
	if (len <= 0) {
		wxLogError(wxT("Error returned from read()"));
		return NULL;
	}

	// There seems to be a minimum size with DD mode, so pad with zeroes if it's not reached
	if (len < MINIMUM_DD_FRAME_LENGTH)
		len = MINIMUM_DD_FRAME_LENGTH;

	// Point to the destination ethernet address
	unsigned char* address = m_buffer + 0U;

	// Do destination address to callsign lookup
	CEthernet* ethernet = NULL;
	for (unsigned int i = 0U; i < m_maxRoutes; i++) {
		if (m_list[i] != NULL) {
			unsigned char* addr = m_list[i]->getAddress();

			if (::memcmp(addr, address, ETHERNET_ADDRESS_LENGTH) == 0) {
				ethernet = m_list[i];
				break;
			}
		}
	}

	if (ethernet == NULL) {
		wxLogWarning(wxT("Cannot find the ethernet address of %02X:%02X:%02X:%02X:%02X:%02X in the ethernet list"), address[0], address[1], address[2], address[3], address[4], address[5]);
		return NULL;
	}

	CRepeaterHandler* handler = CRepeaterHandler::findDDRepeater();
	if (handler == NULL) {
		wxLogWarning(wxT("Incoming DD data to unknown repeater"));
		return NULL;
	}

	// wxLogMessage(wxT("Mapping ethernet address %02X:%02X:%02X:%02X:%02X:%02X to user %s"),
	//				address[0], address[1], address[2], address[3], address[4], address[5],
	//				ethernet->getCallsign().c_str());

	if (m_logEnabled)
		writeStatus(*ethernet);

	CDDData* data = new CDDData;
	data->setEthernetFrame(m_buffer, len);
	data->setYourCall(ethernet->getCallsign());

	handler->process(*data);

	return data;
#endif
}
Exemple #4
0
void CG2Handler::process(CHeaderData& header)
{
	// Is this a busy reply?
	unsigned char flag1 = header.getFlag1();
	if (flag1 == 0x01) {
		// Don't check the incoming stream
		// wxLogMessage(wxT("G2 busy message received"));
		return;
	}

	// Check to see if this is for StarNet
	CStarNetHandler* handler = CStarNetHandler::findStarNet(header);
	if (handler != NULL) {
		// Write to Header.log if it's enabled
		if (m_headerLogger != NULL)
			m_headerLogger->write(wxT("StarNet"), header);

		handler->process(header);
		return;
	}

	// No need to go any further
	if (m_maxRoutes == 0U)
		return;

	in_addr address = header.getYourAddress();
	unsigned int id = header.getId();

	for (unsigned int i = 0U; i < m_maxRoutes; i++) {
		CG2Handler* route = m_routes[i];
		if (route != NULL) {
			// Is this a duplicate header, ignore it
			if (route->m_id == id)
				return;
		}
	}	

	// Find the destination repeater
	CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(header.getRptCall2());
	if (repeater == NULL) {
		wxLogMessage(wxT("Incoming G2 header from %s to unknown repeater - %s"), header.getMyCall1().c_str(), header.getRptCall2().c_str());
		return;		// Not found, ignore
	}

	CG2Handler* route = new CG2Handler(repeater, address, id);

	for (unsigned int i = 0U; i < m_maxRoutes; i++) {
		if (m_routes[i] == NULL) {
			m_routes[i] = route;

			// Write to Header.log if it's enabled
			if (m_headerLogger != NULL)
				m_headerLogger->write(wxT("G2"), header);

			repeater->process(header, DIR_INCOMING, AS_G2);
			return;
		}
	}

	wxLogMessage(wxT("No space to add new G2 route, ignoring"));

	delete route;
}
void CIRCDDBGatewayThread::processRepeater(IRepeaterProtocolHandler* handler)
{
	for (;;) {
		REPEATER_TYPE type = handler->read();

		switch (type) {
			case RT_POLL: {
					CPollData* poll = handler->readPoll();
					if (poll != NULL) {
						CRepeaterHandler* handler = CRepeaterHandler::findRepeater(*poll);
						if (handler != NULL)
							handler->processRepeater(*poll);
						else
							CRepeaterHandler::pollAllIcom(*poll);

						delete poll;
					}
				}
				break;

			case RT_HEARD: {
					CHeardData* heard = handler->readHeard();
					if (heard != NULL) {
						wxString user = heard->getUser();
						wxString repeater = heard->getRepeater();

						// Internal controller heard have identical user and repeater values
						if (!repeater.IsSameAs(user)) {
							CRepeaterHandler* handler = CRepeaterHandler::findDVRepeater(repeater);
							if (handler == NULL)
								wxLogMessage(wxT("Heard received from unknown repeater, %s"), repeater.c_str());
							else
								handler->processRepeater(*heard);

							delete heard;
						}
					}
				}
				break;

			case RT_HEADER: {
					CHeaderData* header = handler->readHeader();
					if (header != NULL) {
						// wxLogMessage(wxT("Repeater header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*header);
						if (repeater == NULL)
							wxLogMessage(wxT("Header received from unknown repeater, %s"), header->getRptCall1().c_str());
						else
							repeater->processRepeater(*header);

						delete header;
					}
				}
				break;

			case RT_AMBE: {
					CAMBEData* data = handler->readAMBE();
					if (data != NULL) {
						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*data, false);
						if (repeater != NULL)
							repeater->processRepeater(*data);

						delete data;
					}
				}
				break;

			case RT_BUSY_HEADER: {
					CHeaderData* header = handler->readBusyHeader();
					if (header != NULL) {
						// wxLogMessage(wxT("Repeater busy header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());

						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*header);
						if (repeater == NULL)
							wxLogMessage(wxT("Busy header received from unknown repeater, %s"), header->getRptCall1().c_str());
						else
							repeater->processBusy(*header);

						delete header;
					}
				}
				break;

			case RT_BUSY_AMBE: {
					CAMBEData* data = handler->readBusyAMBE();
					if (data != NULL) {
						CRepeaterHandler* repeater = CRepeaterHandler::findDVRepeater(*data, true);
						if (repeater != NULL)
							repeater->processBusy(*data);

						delete data;
					}
				}
				break;

			case RT_DD: {
					CDDData* data = handler->readDD();
					if (data != NULL) {
						// wxLogMessage(wxT("DD header - My: %s/%s  Your: %s  Rpt1: %s  Rpt2: %s  Flags: %02X %02X %02X"), data->getMyCall1().c_str(), data->getMyCall2().c_str(), data->getYourCall().c_str(), data->getRptCall1().c_str(), data->getRptCall2().c_str(), data->getFlag1(), data->getFlag2(), data->getFlag3());

						CRepeaterHandler* repeater = CRepeaterHandler::findDDRepeater();
						if (repeater == NULL)
							wxLogMessage(wxT("DD data received from unknown DD repeater, %s"), data->getRptCall1().c_str());
						else
							repeater->processRepeater(*data);

						delete data;
					}
				}
				break;

			default:
				return;
		}
	}
}