Exemplo n.º 1
0
void config_writeconfigfile(void) {
	GError *error = NULL;
	FILE *f;
	gsize size;
	char *data = NULL;

	if (config_configfilename == NULL) {
		console_log("config error: no config file name given\n");
		return;
	}

	pthread_mutex_lock(&config_mutex);

	data = g_key_file_to_data(keyfile, &size, &error);
	if (!error && data != NULL) {
		f = fopen(config_configfilename, "w");
		if (f) {
			fwrite(data, 1, size, f);
			fclose(f);
		} else
			console_log("config error: can't save, file %s is not writable\n", config_configfilename);
	} else
		console_log("config error: can't save\n");

	if (data)
		free(data);

	pthread_mutex_unlock(&config_mutex);
}
Exemplo n.º 2
0
void snmp_start_read_rssi(char *host) {
	struct snmp_pdu *pdu;
	struct snmp_session session;
	const char *community = "public";

	if (oid_rssi_ts1_length == 0 || oid_rssi_ts2_length == 0)
		return;

	snmp_rssi_received = 0;

	if (snmp_session_rssi != NULL) {
		snmp_close(snmp_session_rssi);
		snmp_session_rssi = NULL;
	}

	snmp_sess_init(&session);
	session.version = SNMP_VERSION_1;
	session.peername = strdup(host);
	session.community = (unsigned char *)strdup(community);
	session.community_len = strlen(community);
	session.callback = snmp_get_rssi_cb;
	if (!(snmp_session_rssi = snmp_open(&session))) {
		console_log("snmp error: error opening session to host %s\n", host);
		return;
	}

	pdu = snmp_pdu_create(SNMP_MSG_GET);
	snmp_add_null_var(pdu, oid_rssi_ts1, oid_rssi_ts1_length);
	snmp_add_null_var(pdu, oid_rssi_ts2, oid_rssi_ts2_length);
	if (!snmp_send(snmp_session_rssi, pdu))
		console_log("snmp error: error sending rssi request to host %s\n", host);
	free(session.peername);
	free(session.community);
}
Exemplo n.º 3
0
int
login (void *ctx, char *username, char *ipaddr)
{
	assert(ctx);
	assert(username);
	assert(ipaddr);
	assert(strlen(username) > 0);
	assert(strlen(ipaddr) > 0);

	console_log("Sending login request...\n");

	void *sock = zmq_socket(ctx, ZMQ_REQ);
	zmq_connect(sock, "tcp://127.0.0.1:5555");

	char cmd_msg[250];	//$$ Longer than length will crash
	sprintf(cmd_msg, "login\n%s\n%s", username, ipaddr);
	int num_bytes_sent = s_send(sock, cmd_msg);
	if (num_bytes_sent == -1) {
		console_log("Error sending login request\n");

		zmq_close(sock);
		return -1;
	}

	console_log("Waiting for login reply...\n");
	char *reply_msg = s_recv(sock);
	if (reply_msg != NULL) {
		console_log("Received reply: '%s'\n", reply_msg);
		free(reply_msg);
	}

	zmq_close(sock);
	return 0;
}
Exemplo n.º 4
0
void voicestreams_printlist(void) {
	voicestream_t *vs;

	if (voicestreams == NULL) {
		console_log("no voice streams loaded.\n");
		return;
	}
	console_log("voice streams:\n");

	vs = voicestreams;
	while (vs != NULL) {
		console_log("%s: enabled: %u rptrhosts: %s ts: %u quality: %u savedir: %s saveraw: %u savedecodedraw: %u savedecodedmp3: %u\n", vs->name,
			vs->enabled,
			vs->repeaterhosts,
			vs->timeslot,
			vs->decodequality,
			(strlen(vs->savefiledir) == 0 ? "." : vs->savefiledir),
			vs->savetorawambefile,
			vs->savedecodedtorawfile,
			vs->savedecodedtomp3file);
		console_log("   minmp3br: %u mp3br: %u mp3quality: %u mp3vbr: %u rmsminsampval: %f\n",
			vs->minmp3bitrate,
			vs->mp3bitrate,
			vs->mp3quality,
			vs->mp3vbr,
			vs->rmsminsamplevalue);
		console_log("   callstartfile: %s (%f) callendfile: %s (%f)\n",
			vs->playrawfileatcallstart,
			vs->rawfileatcallstartgain,
			vs->playrawfileatcallend,
			vs->rawfileatcallendgain);

		vs = vs->next;
	}
}
Exemplo n.º 5
0
int
query_users (void *ctx, char *filter)
{
	assert(ctx);
	assert(filter);

	console_log("Sending query users request...\n");

	void *sock = zmq_socket(ctx, ZMQ_REQ);
	zmq_connect(sock, "tcp://127.0.0.1:5555");

	char cmd_msg[250];	//$$ Longer than length will crash
	sprintf(cmd_msg, "users\n%s", filter);
	int num_bytes_sent = s_send(sock, cmd_msg);
	if (num_bytes_sent == -1) {
		console_log("Error sending query users request\n");

		zmq_close(sock);
		return -1;
	}

	console_log("Waiting for query users reply...\n");
	char *reply_msg = s_recv(sock);
	if (reply_msg != NULL) {
		console_log("Received reply: '%s'\n", reply_msg);
		free(reply_msg);
	}

	zmq_close(sock);
	return 0;
}
Exemplo n.º 6
0
void data_packet_txbuf_add(flag_t broadcast_to_all_repeaters, repeater_t *repeater, dmr_timeslot_t ts, dmrpacket_data_packet_t *data_packet) {
	data_packet_txbuf_t *new_data_packet_txbuf_entry;

	if (data_packet == NULL)
		return;

	new_data_packet_txbuf_entry = (data_packet_txbuf_t *)calloc(1, sizeof(data_packet_txbuf_t));
	if (new_data_packet_txbuf_entry == NULL) {
		console_log("  error: can't allocate memory for new data packet tx buffer entry\n");
		return;
	}

	memcpy(&new_data_packet_txbuf_entry->data_packet, data_packet, sizeof(dmrpacket_data_packet_t));
	new_data_packet_txbuf_entry->added_at = time(NULL);
	new_data_packet_txbuf_entry->broadcast_to_all_repeaters = broadcast_to_all_repeaters;
	new_data_packet_txbuf_entry->repeater = repeater;
	new_data_packet_txbuf_entry->ts = ts;

	console_log(LOGLEVEL_DATAQ "data packet txbuf: adding new entry:\n");
	data_packet_txbuf_print_entry(new_data_packet_txbuf_entry);

	if (data_packet_txbuf_last_entry == NULL) {
		data_packet_txbuf_last_entry = data_packet_txbuf_first_entry = new_data_packet_txbuf_entry;
	} else {
		// Putting the new entry to the end of the linked list.
		data_packet_txbuf_last_entry->next = new_data_packet_txbuf_entry;
		data_packet_txbuf_last_entry = new_data_packet_txbuf_entry;
	}
	daemon_poll_setmaxtimeout(0);
}
Exemplo n.º 7
0
void aprs_deinit(void) {
	void *status = NULL;
	aprs_obj_t *next_obj;

	console_log("aprs: deinit\n");
	aprs_enabled = 0;

	// Waking up the thread if it's sleeping.
	pthread_mutex_lock(&aprs_mutex_wakeup);
	pthread_cond_signal(&aprs_cond_wakeup);
	pthread_mutex_unlock(&aprs_mutex_wakeup);

	pthread_mutex_lock(&aprs_mutex_thread_should_stop);
	aprs_thread_should_stop = 1;
	pthread_mutex_unlock(&aprs_mutex_thread_should_stop);
	console_log("aprs: waiting for aprs thread to exit\n");
	pthread_join(aprs_thread, &status);

	while (aprs_objs_first_entry) {
		next_obj = aprs_objs_first_entry->next;
		free(aprs_objs_first_entry->callsign);
		free(aprs_objs_first_entry->description);
		free(aprs_objs_first_entry);
		aprs_objs_first_entry = next_obj;
	}

	pthread_mutex_destroy(&aprs_mutex_thread_should_stop);
	pthread_mutex_destroy(&aprs_mutex_wakeup);
	pthread_mutex_destroy(&aprs_mutex_queue);
}
Exemplo n.º 8
0
void aprs_add_to_queue_msg(char *dst_callsign, char *src_callsign, char *msg, char *repeater_callsign) {
	aprs_queue_t *new_entry;
	uint8_t i;
	uint8_t len;

	if (dst_callsign == NULL || src_callsign == NULL || msg == NULL || repeater_callsign == NULL || repeater_callsign[0] == 0)
		return;

	new_entry = (aprs_queue_t *)calloc(1, sizeof(aprs_queue_t));
	if (new_entry == NULL) {
		console_log("aprs error: can't allocate memory for new msg entry in the queue\n");
		return;
	}
	new_entry->type = APRS_QUEUE_ENTRY_TYPE_MSG;
	strncpy(new_entry->repeater_callsign, repeater_callsign, sizeof(new_entry->repeater_callsign));
	len = min(strlen(dst_callsign), sizeof(new_entry->u.msg.dst_callsign)-1);
	for (i = 0; i < len; i++)
		new_entry->u.msg.dst_callsign[i] = toupper(dst_callsign[i]);
	len = min(strlen(src_callsign), sizeof(new_entry->u.msg.src_callsign)-1);
	for (i = 0; i < len; i++)
		new_entry->u.msg.src_callsign[i] = toupper(src_callsign[i]);
	strncpy(new_entry->u.msg.msg, msg, sizeof(new_entry->u.msg.msg));

	aprs_add_entry_to_queue(new_entry);

	console_log(LOGLEVEL_APRS "aprs queue: added entry: repeater: %s dst: %s src: %s msg: %s\n", new_entry->repeater_callsign,
		new_entry->u.msg.dst_callsign, new_entry->u.msg.src_callsign, new_entry->u.msg.msg);
}
Exemplo n.º 9
0
// Sends given raw IPSC packet to the given repeater.
static flag_t repeaters_send_raw_ipsc_packet(repeater_t *repeater, ipscpacket_raw_t *ipscpacket_raw) {
	struct sockaddr_in sin;
	int sockfd;

	if (repeater == NULL || ipscpacket_raw == NULL)
		return 0;

	// Need to use raw socket here, because if the master software is running,
	// we can't bind to the source port to set it in our UDP packet.
	if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) == -1) {
		console_log(LOGLEVEL_REPEATERS LOGLEVEL_DEBUG "repeaters [%s]: can't create raw socket for sending an udp packet\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
		return 0;
	}

	memset(&sin, 0, sizeof(struct sockaddr_in));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(62006);
	memcpy(&sin.sin_addr, &repeater->ipaddr, sizeof(struct in_addr));

	errno = 0;
	if (sendto(sockfd, ipscpacket_raw->bytes, sizeof(ipscpacket_raw_t), MSG_DONTWAIT, (struct sockaddr *)&sin, sizeof(struct sockaddr_in)) != sizeof(ipscpacket_raw_t)) {
		console_log(LOGLEVEL_REPEATERS LOGLEVEL_DEBUG "repeaters [%s]: can't send udp packet: %s\n", repeaters_get_display_string_for_ip(&repeater->ipaddr), strerror(errno));
		close(sockfd);
		return 0;
	}
	close(sockfd);
	return 1;
}
Exemplo n.º 10
0
void repeaters_store_voice_frame_to_echo_buf(repeater_t *repeater, ipscpacket_t *ipscpacket) {
	repeater_echo_buf_t *new_echo_buf_entry;
	dmrpacket_payload_voice_bits_t *voice_bits;

	if (repeater == NULL || ipscpacket == NULL)
		return;

	new_echo_buf_entry = (repeater_echo_buf_t *)malloc(sizeof(repeater_echo_buf_t));
	if (new_echo_buf_entry == NULL) {
		console_log("  error: can't allocate memory for new echo buffer entry\n");
		return;
	}

	console_log(LOGLEVEL_REPEATERS LOGLEVEL_DEBUG "repeaters [%s]: storing ts%u voice frame to echo buf\n", repeaters_get_display_string_for_ip(&repeater->ipaddr),
		ipscpacket->timeslot);

	voice_bits = dmrpacket_extract_voice_bits(&ipscpacket->payload_bits);
	base_bitstobytes(voice_bits->raw.bits, sizeof(dmrpacket_payload_voice_bits_t), new_echo_buf_entry->voice_bytes.bytes, sizeof(dmrpacket_payload_voice_bits_t)/8);
	new_echo_buf_entry->next = NULL;

	if (repeater->slot[ipscpacket->timeslot-1].echo_buf_last_entry == NULL) {
		repeater->slot[ipscpacket->timeslot-1].echo_buf_last_entry = repeater->slot[ipscpacket->timeslot-1].echo_buf_first_entry = new_echo_buf_entry;
	} else {
		// Putting the new entry to the end of the linked list.
		repeater->slot[ipscpacket->timeslot-1].echo_buf_last_entry->next = new_echo_buf_entry;
		repeater->slot[ipscpacket->timeslot-1].echo_buf_last_entry = new_echo_buf_entry;
	}
}
Exemplo n.º 11
0
void repeaters_add_to_ipsc_packet_buffer(repeater_t *repeater, dmr_timeslot_t ts, ipscpacket_raw_t *ipscpacket_raw, flag_t nowait) {
	ipscrawpacketbuf_t *newpbentry;
	ipscrawpacketbuf_t *pbentry;

	if (repeater == NULL || ipscpacket_raw == NULL)
		return;

	console_log(LOGLEVEL_REPEATERS LOGLEVEL_DEBUG "repeaters [%s]: adding entry to ts%u ipsc packet buffer\n", repeaters_get_display_string_for_ip(&repeater->ipaddr), ts+1);

	newpbentry = (ipscrawpacketbuf_t *)calloc(1, sizeof(ipscrawpacketbuf_t));
	if (newpbentry == NULL) {
		console_log(LOGLEVEL_REPEATERS "repeaters [%s] error: couldn't allocate memory for new ipsc packet buffer entry\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
		return;
	}

	memcpy(&newpbentry->ipscpacket_raw, ipscpacket_raw, sizeof(ipscpacket_raw_t));
	newpbentry->nowait = nowait;

	pbentry = repeater->slot[ts].ipsc_tx_rawpacketbuf;
	if (pbentry == NULL)
		repeater->slot[ts].ipsc_tx_rawpacketbuf = newpbentry;
	else {
		// Searching for the last element in the packet buffer.
		while (pbentry->next)
			pbentry = pbentry->next;
		pbentry->next = newpbentry;
	}

	daemon_poll_setmaxtimeout(0);
}
Exemplo n.º 12
0
void repeaters_list(void) {
	repeater_t *repeater = repeaters;
	int i = 1;
	flag_t master;

	if (repeaters == NULL) {
		console_log("no repeaters found yet\n");
		return;
	}

	console_log("repeaters:\n");
	console_log("      nr              ip     id  callsign  act  lstinf         type        fwver    dlfreq    ulfreq snmp ts1/ts2 streams\n");
	while (repeater) {
		master = comm_is_masteripaddr(&repeater->ipaddr);
		console_log("  #%4u: %15s %6u %9s %4u  %6u %12s %12s %9u %9u    %u %s / %s\n",
			i++,
			comm_get_ip_str(&repeater->ipaddr),
			repeater->id,
			master ? "master" : repeater->callsign,
			master ? 0 : time(NULL)-repeater->last_active_time,
			master ? 0 : time(NULL)-repeater->last_repeaterinfo_request_time,
			repeater->type,
			repeater->fwversion,
			repeater->dlfreq,
			repeater->ulfreq,
			!repeater->snmpignored,
			repeater->slot[0].voicestream != NULL ? repeater->slot[0].voicestream->name : "n/a",
			repeater->slot[1].voicestream != NULL ? repeater->slot[1].voicestream->name : "n/a");

		repeater = repeater->next;
	}
}
Exemplo n.º 13
0
static int usbhub_detach(usbdev_t *dev)
{
    usbhub_softc_t *hub;
    usbdev_t *deldev;
    int idx;

    if (!IS_HUB(dev)) return 0;		/* should not happen */

    hub = dev->ud_private;
    for (idx = 0; idx < UHUB_MAX_DEVICES; idx++) {
	deldev = hub->uhub_devices[idx];
	if (deldev) {
	    console_log("USB: Removing device attached to bus %d hub %d port %d",
		   dev->ud_bus->ub_num,
		   dev->ud_address,idx+1);
	    if (deldev->ud_drv) {
		(*(deldev->ud_drv->udrv_detach))(deldev);
		}
	    else {
		if (usb_noisy > 0) {
		    console_log("USB: Detached device on bus %d hub %d port %d "
			   "has no methods",
			   dev->ud_bus->ub_num,
			   dev->ud_address,idx+1);
		    }
		}
	    if (deldev->ud_cfgdescr) KFREE(deldev->ud_cfgdescr);
	    usb_destroy_device(deldev);
	    }
	}

    KFREE(hub);				/* remove softc */

    return 0;
}
Exemplo n.º 14
0
static void golay_20_8_check_and_repair_parity(flag_t bits[20]) {
	uint16_t row;
	uint8_t col;
	uint8_t weight = 0;
	uint8_t minweight = 0xff;
	uint16_t minweightrow = 0;
	golay_20_8_parity_bits_t syndrome;
	golay_20_8_parity_bits_t error_vector;
	golay_20_8_parity_bits_t *parity_bits;

	// Calculating the syndrome
	parity_bits = golay_20_8_get_parity_bits(bits);
	for (col = 0; col < 12; col++) {
		syndrome.bits[col] = (parity_bits->bits[col] + bits[col+8]) % 2;
		if (syndrome.bits[col])
			weight++;
	}

	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "    golay: trying to repair parity bits\n");
	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "                     syndrome: ");
	golay_20_8_print_bits(syndrome.bits, 12, 0);
	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "                       weight: %u\n", weight);

	if (weight == 0) {
		console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "      no errors found\n");
		return;
	}

	for (col = 0; col < 12; col++)
		error_vector.bits[col] = (bits[col+8] + syndrome.bits[col]) % 2;

	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "                 error vector: ");
	golay_20_8_print_bits(error_vector.bits, 12, 0);

	// Searching for the minimum weight data parity syndrome in the precalculated data parity syndrome list.
	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "                               searching for minimum weight\n");
	for (row = 0; row < 256; row++) {
		weight = 0;
		for (col = 0; col < 12; col++) {
			if (golay_20_8_data_parity_syndromes[row].bits[col] != error_vector.bits[col])
				weight++;
		}

		if (weight < minweight) {
			minweight = weight;
			minweightrow = row;
		}
	}

	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "                               minimum weight %u found in row %u\n", minweight, minweightrow);
	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "        minimum weight parity: ");
	golay_20_8_print_bits(error_vector.bits, 12, 0);

	memcpy(&bits[8], golay_20_8_data_parity_syndromes[minweightrow].bits, 12);

	console_log(LOGLEVEL_COMM_DMR "    golay: parity errors found and repaired\n");
	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "                        final: ");
	golay_20_8_print_bits(bits, 20, 1);
}
Exemplo n.º 15
0
repeater_t *repeaters_add(struct in_addr *ipaddr) {
	flag_t error = 0;
	repeater_t *repeater = repeaters_findbyip(ipaddr);

	if (ipaddr == NULL)
		return NULL;

	if (repeater == NULL) {
		repeater = (repeater_t *)calloc(sizeof(repeater_t), 1);
		if (repeater == NULL) {
			console_log("repeaters [%s]: can't add new repeater, not enough memory\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
			return NULL;
		}
		memcpy(&repeater->ipaddr, ipaddr, sizeof(struct in_addr));

		// Expecting 8 rows of variable length BPTC coded embedded LC data.
		// It will contain 77 data bits (without the Hamming (16,11) checksums
		// and the last row of parity bits).
		if (!vbptc_16_11_init(&repeater->slot[0].emb_sig_lc_vbptc_storage, 8))
			error = 1;
		else {
			if (!vbptc_16_11_init(&repeater->slot[1].emb_sig_lc_vbptc_storage, 8)) {
				vbptc_16_11_free(&repeater->slot[0].emb_sig_lc_vbptc_storage);
				error = 1;
			}
		}
		if (error) {
			console_log("repeaters [%s]: can't add, not enough memory for embedded signalling lc storage\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
			free(repeater);
			return NULL;
		}

		if (repeaters_issnmpignoredforip(ipaddr))
			repeater->snmpignored = 1;

		repeater->slot[0].voicestream = voicestreams_get_stream_for_repeater(ipaddr, 1);
#ifdef AMBEDECODEVOICE
		voicestreams_decode_ambe_init(repeater->slot[0].voicestream);
#endif
		repeater->slot[1].voicestream = voicestreams_get_stream_for_repeater(ipaddr, 2);
#ifdef AMBEDECODEVOICE
		voicestreams_decode_ambe_init(repeater->slot[1].voicestream);
#endif
		if (repeaters != NULL) {
			repeaters->prev = repeater;
			repeater->next = repeaters;
		}
		repeaters = repeater;

		console_log("repeaters [%s]: added, snmp ignored: %u ts1 stream: %s ts2 stream: %s\n",
			repeaters_get_display_string_for_ip(&repeater->ipaddr), repeater->snmpignored,
			repeater->slot[0].voicestream != NULL ? repeater->slot[0].voicestream->name : "no stream defined",
			repeater->slot[1].voicestream != NULL ? repeater->slot[1].voicestream->name : "no stream defined");
	}
	repeater->last_active_time = time(NULL);

	return repeater;
}
Exemplo n.º 16
0
void
console_cmd_send_specified         (char *__cmd)
{
  console_cmd_line_push (__cmd);
  console_log (">> %s\n", __cmd);
  if (console_proc_exec (__cmd))
    console_log ("Unknown command %s\n", __cmd);
  console_cmd_line_set ("");
}
Exemplo n.º 17
0
void aprs_init(void) {
	char **objnames = config_aprsobjs_get_objnames();
	char **objnames_i = objnames;
	pthread_attr_t attr;
	char *host = NULL;
	aprs_obj_t *newobj;
	uint8_t i;
	uint8_t length;

	console_log("aprs: init\n");

	host = config_get_aprsserverhost();
	if (strlen(host) != 0) {
		aprs_enabled = 1;

		while (*objnames_i != NULL) {
			if (config_aprsobjs_get_enabled(*objnames_i)) {
				console_log("  initializing %s...\n", *objnames_i);

				newobj = (aprs_obj_t *)calloc(1, sizeof(aprs_obj_t));

				newobj->callsign = strdup(*(objnames_i)+8); // +8 - cutting out string "aprsobj-"
				length = strlen(newobj->callsign);
				for (i = 0; i < length; i++)
					newobj->callsign[i] = toupper(newobj->callsign[i]);
				newobj->latitude = config_aprsobjs_get_latitude(*objnames_i);
				newobj->latitude_ch = config_aprsobjs_get_latitude_ch(*objnames_i);
				newobj->longitude = config_aprsobjs_get_longitude(*objnames_i);
				newobj->longitude_ch = config_aprsobjs_get_longitude_ch(*objnames_i);
				newobj->description = config_aprsobjs_get_description(*objnames_i);
				newobj->table_ch = config_aprsobjs_get_table_ch(*objnames_i);
				newobj->symbol_ch = config_aprsobjs_get_symbol_ch(*objnames_i);

				if (aprs_objs_first_entry == NULL)
					aprs_objs_first_entry = newobj;
				else {
					newobj->next = aprs_objs_first_entry;
					aprs_objs_first_entry = newobj;
				}
			}

			objnames_i++;
		}
		config_aprsobjs_free_objnames(objnames);

		console_log("aprs: starting thread for aprs\n");

		// Explicitly creating the thread as joinable to be compatible with other systems.
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
		pthread_create(&aprs_thread, &attr, aprs_thread_init, NULL);
	} else
		console_log("aprs: no server configured\n");
	free(host);
}
Exemplo n.º 18
0
void snmp_init(void) {
	console_log("snmp: init\n");

	init_snmp(APPNAME);
	conv_utf16_utf8 = iconv_open("UTF-8","UTF-16LE");

	oid_rssi_ts1_length = MAX_OID_LEN;
	if (!read_objid(OID_RSSI_TS1, oid_rssi_ts1, &oid_rssi_ts1_length))
		console_log("snmp error: can't parse ts1 rssi oid (%s)\n", OID_RSSI_TS1);
	oid_rssi_ts2_length = MAX_OID_LEN;
	if (!read_objid(OID_RSSI_TS2, oid_rssi_ts2, &oid_rssi_ts2_length))
		console_log("snmp error: can't parse ts2 rssi oid (%s)\n", OID_RSSI_TS2);

	oid_id_length = MAX_OID_LEN;
	if (!read_objid(OID_ID, oid_id, &oid_id_length))
		console_log("snmp error: can't parse id oid (%s)\n", OID_ID);
	oid_repeatertype_length = MAX_OID_LEN;
	if (!read_objid(OID_REPEATERTYPE, oid_repeatertype, &oid_repeatertype_length))
		console_log("snmp error: can't parse repeatertype oid (%s)\n", OID_REPEATERTYPE);
	oid_fwversion_length = MAX_OID_LEN;
	if (!read_objid(OID_FWVERSION, oid_fwversion, &oid_fwversion_length))
		console_log("snmp error: can't parse fwversion oid (%s)\n", OID_FWVERSION);
	oid_callsign_length = MAX_OID_LEN;
	if (!read_objid(OID_CALLSIGN, oid_callsign, &oid_callsign_length))
		console_log("snmp error: can't parse callsign oid (%s)\n", OID_CALLSIGN);
	oid_dlfreq_length = MAX_OID_LEN;
	if (!read_objid(OID_DLFREQ, oid_dlfreq, &oid_dlfreq_length))
		console_log("snmp error: can't parse callsign oid (%s)\n", OID_DLFREQ);
	oid_ulfreq_length = MAX_OID_LEN;
	if (!read_objid(OID_ULFREQ, oid_ulfreq, &oid_ulfreq_length))
		console_log("snmp error: can't parse callsign oid (%s)\n", OID_ULFREQ);
}
Exemplo n.º 19
0
static void repeaters_process_ipsc_tx_rawpacketbuf(repeater_t *repeater) {
	struct timeval currtime = {0,};
	struct timeval difftime = {0,};
	ipscrawpacketbuf_t *ipsc_tx_rawpacketbuf_entry_to_send;
	dmr_timeslot_t ts;
	flag_t nowait = 0;

	if (repeater == NULL)
		return;

	if (repeater->slot[0].ipsc_tx_rawpacketbuf != NULL || repeater->slot[1].ipsc_tx_rawpacketbuf != NULL)
		daemon_poll_setmaxtimeout(0);

	if (repeater->last_ipsc_packet_sent_from_slot == 1)
		ts = 0;
	else
		ts = 1;

	gettimeofday(&currtime, NULL);
	timersub(&currtime, &repeater->last_ipsc_packet_sent_time, &difftime);
	if (difftime.tv_sec*1000+difftime.tv_usec/1000 < IPSC_PACKET_SEND_INTERVAL_IN_MS)
		return;

	if (repeater->slot[ts].ipsc_tx_rawpacketbuf != NULL && repeater->slot[ts].ipsc_tx_rawpacketbuf->nowait)
		nowait = 1;

	if (nowait == 0)
		repeater->last_ipsc_packet_sent_from_slot = ts;

	if (repeater->slot[ts].ipsc_tx_rawpacketbuf == NULL) {
		gettimeofday(&repeater->last_ipsc_packet_sent_time, NULL);
		return;
	}

	if (repeaters_is_there_a_call_not_for_us_or_by_us(repeater, ts))
		return;

	ipsc_tx_rawpacketbuf_entry_to_send = repeater->slot[ts].ipsc_tx_rawpacketbuf;

	console_log(LOGLEVEL_REPEATERS "repeaters [%s]: sending ipsc packet from tx buffer\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
	if (repeaters_send_raw_ipsc_packet(repeater, &ipsc_tx_rawpacketbuf_entry_to_send->ipscpacket_raw)) {
		// Sending the packet to our IPSC processing loop too.
		//ipsc_processpacket(&ipsc_tx_rawpacketbuf_entry_to_send->ipscpacket_raw, sizeof(ipscpacket_raw_t));

		// Shifting the buffer.
		repeater->slot[ts].ipsc_tx_rawpacketbuf = repeater->slot[ts].ipsc_tx_rawpacketbuf->next;
		free(ipsc_tx_rawpacketbuf_entry_to_send);
	}
	if (nowait == 0)
		gettimeofday(&repeater->last_ipsc_packet_sent_time, NULL);
	if (repeater->slot[ts].ipsc_tx_rawpacketbuf == NULL)
		console_log(LOGLEVEL_REPEATERS "repeaters [%s]: tx packet buffer got empty\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
}
Exemplo n.º 20
0
void repeaters_process(void) {
	repeater_t *repeater = repeaters;
	repeater_t *repeater_to_remove;
	struct timeval currtime = {0,};
	struct timeval difftime = {0,};

	while (repeater) {
		if (repeater->slot[0].state != REPEATER_SLOT_STATE_IDLE || repeater->slot[1].state != REPEATER_SLOT_STATE_IDLE)
			daemon_poll_setmaxtimeout(IPSC_PACKET_SEND_INTERVAL_IN_MS);

		repeaters_process_ipsc_tx_rawpacketbuf(repeater);

		if (!comm_is_masteripaddr(&repeater->ipaddr) && time(NULL)-repeater->last_active_time > config_get_repeaterinactivetimeoutinsec()) {
			console_log(LOGLEVEL_REPEATERS "repeaters [%s]: timed out\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
			repeater_to_remove = repeater;
			repeater = repeater->next;
			repeaters_remove(repeater_to_remove);
			continue;
		}

		if (!repeater->snmpignored && config_get_repeaterinfoupdateinsec() > 0 && time(NULL)-repeater->last_repeaterinfo_request_time > config_get_repeaterinfoupdateinsec()) {
			console_log(LOGLEVEL_REPEATERS LOGLEVEL_DEBUG "repeaters [%s]: sending snmp info update request\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
			snmp_start_read_repeaterinfo(comm_get_ip_str(&repeater->ipaddr));
			repeater->last_repeaterinfo_request_time = time(NULL);
		}

		if (repeater->slot[0].state == REPEATER_SLOT_STATE_VOICE_CALL_RUNNING && time(NULL)-repeater->slot[0].last_call_or_data_packet_received_at > config_get_calltimeoutinsec())
			dmr_handle_voice_call_timeout(repeater, 0);

		if (repeater->slot[1].state == REPEATER_SLOT_STATE_VOICE_CALL_RUNNING && time(NULL)-repeater->slot[1].last_call_or_data_packet_received_at > config_get_calltimeoutinsec())
			dmr_handle_voice_call_timeout(repeater, 1);

		if (repeater->auto_rssi_update_enabled_at > 0 && repeater->auto_rssi_update_enabled_at <= time(NULL)) {
			if (config_get_rssiupdateduringcallinmsec() > 0) {
				gettimeofday(&currtime, NULL);
				timersub(&currtime, &repeater->last_rssi_request_time, &difftime);
				if (difftime.tv_sec*1000+difftime.tv_usec/1000 > config_get_rssiupdateduringcallinmsec()) {
					snmp_start_read_repeaterstatus(comm_get_ip_str(&repeater->ipaddr));
					repeater->last_rssi_request_time = currtime;
				}
			}
		}

		if (repeater->slot[0].state == REPEATER_SLOT_STATE_DATA_CALL_RUNNING && time(NULL)-repeater->slot[0].last_call_or_data_packet_received_at > config_get_datatimeoutinsec())
			dmr_handle_data_call_timeout(repeater, 0);

		if (repeater->slot[1].state == REPEATER_SLOT_STATE_DATA_CALL_RUNNING && time(NULL)-repeater->slot[1].last_call_or_data_packet_received_at > config_get_datatimeoutinsec())
			dmr_handle_data_call_timeout(repeater, 1);

		repeater = repeater->next;
	}
}
Exemplo n.º 21
0
void repeaters_state_change(repeater_t *repeater, dmr_timeslot_t timeslot, repeater_slot_state_t new_state) {
	console_log(LOGLEVEL_REPEATERS "repeaters [%s]: slot %u state change from %s to %s\n",
		repeaters_get_display_string_for_ip(&repeater->ipaddr), timeslot+1, repeaters_get_readable_slot_state(repeater->slot[timeslot].state),
		repeaters_get_readable_slot_state(new_state));
	repeater->slot[timeslot].state = new_state;

	if (repeater->auto_rssi_update_enabled_at != 0 &&
		repeater->slot[0].state != REPEATER_SLOT_STATE_VOICE_CALL_RUNNING &&
		repeater->slot[1].state != REPEATER_SLOT_STATE_VOICE_CALL_RUNNING) {
			console_log(LOGLEVEL_SNMP "repeaters [%s]: stopping auto repeater status update\n", repeaters_get_display_string_for_ip(&repeater->ipaddr));
			repeater->auto_rssi_update_enabled_at = 0;
	}
}
Exemplo n.º 22
0
void data_packet_txbuf_print(void) {
	data_packet_txbuf_t *entry = data_packet_txbuf_first_entry;

	if (entry == NULL) {
		console_log("data packet txbuf: empty\n");
		return;
	}
	console_log("data packet txbuf:\n");
	while (entry) {
		data_packet_txbuf_print_entry(entry);
		entry = entry->next;
	}
}
Exemplo n.º 23
0
static void golay_20_8_print_bits(flag_t *bits, uint8_t count, flag_t leave_space) {
	uint8_t i;
	loglevel_t loglevel = console_get_loglevel();

	if (!loglevel.flags.debug || !loglevel.flags.comm_dmr)
		return;

	for (i = 0; i < count; i++) {
		if (i == 8 && leave_space) // Leave out a space between 8 bit data and 12 bit parity fields.
			console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR " ");
		console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "%u", bits[i]);
	}
	console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "\n");
}
Exemplo n.º 24
0
bool connmgr_add_local_connection(struct conn_manager* self, struct filesystem* base, struct console* console)
{
        struct conn_local* conn = conn_local_create(console, base);
        if (!conn) {
                const char* base_info = filesys_2string(base);
                console_log(console, ConsoleLogSevere, "Failed to create local connection on %s",
                            base_info), free((void*) base_info);
                return false;
        }
        connmgr_remove_connection(self, conn->__parent.id);
        __connmgr_add_connection(self, &conn->__parent);
        console_log(console, ConsoleLogNormal, "Local Connection %s", conn_local_2string(conn));
        return true;
}
Exemplo n.º 25
0
void jarvisNodeTestApp::connectNodeSignals(sJarvisNode* node)
{
    connect(node,SIGNAL(tx()),&m_rxWidget,SLOT(tx()));
    connect(node,SIGNAL(rx()),&m_rxWidget,SLOT(rx()));
    connect(node,SIGNAL(rawInput(QByteArray)),this,SLOT(console_log(QByteArray)));
    connect(node,SIGNAL(writeData(QByteArray)),this,SLOT(console_log(QByteArray)));
    connect(node,SIGNAL(incomingEvent(QString,jarvisEvents,QStringList)),this,SLOT(eventLog(QString,jarvisEvents,QStringList)));
    //connect(node,SIGNAL(newComponent(sJarvisNodeComponent*)),this,SLOT(addComponent(sJarvisNodeComponent*)));
    //connect(&m_sensorsTimer,SIGNAL(timeout()),this,SLOT(timedCmd()));
    connect(node,SIGNAL(sensorReads(QVector<QString>,QVector<double>)),this,SLOT(sensorRead(QVector<QString>,QVector<double>)));
    connect(node,SIGNAL(ready()),this,SLOT(nodeConnected()));
    connect(node,SIGNAL(disconnected()),this,SLOT(nodeDisconnected()));
    connect(ui->sliderUpdateInterval,SIGNAL(sliderMoved(int)),node,SLOT(setUpdateInterval(int)));
    connect(ui->btnReset,SIGNAL(clicked()),node,SLOT(resetNode()));
}
Exemplo n.º 26
0
static int usbhub_detach(usbdev_t *dev)
{
    usbhub_softc_t *hub;
    usbdev_t *deldev;
    int idx;

    if (!IS_HUB(dev)) return 0;		/* should not happen */

    hub = dev->ud_private;
    for (idx = 0; idx < UHUB_MAX_DEVICES; idx++) {
	deldev = hub->uhub_devices[idx];
	if (deldev) {
	    if (usb_noisy > 0)
		console_log("USB: Removing device attached to bus %d hub %d port %d",
			    dev->ud_bus->ub_num,
			    dev->ud_address,idx+1);
	    if (deldev->ud_drv) {
		/* close open pipes, cancel reqs */
		usb_destroy_all_pipes(deldev);
		/* 
		 * Try to process the done queue.  This will complete any
		 * requests that made it out of the pipes while we were
		 * doing the stuff above.
		 */
		usb_poll(deldev->ud_bus);
		/* Call detach method, clean up device softc */
		(*(deldev->ud_drv->udrv_detach))(deldev);
		}
	    else {
		if (usb_noisy > 0) {
		    console_log("USB: Detached device on bus %d hub %d port %d "
			   "has no methods",
			   dev->ud_bus->ub_num,
			   dev->ud_address,idx+1);
		    }
		}
	    if (deldev->ud_cfgdescr) usb_dma_free(deldev->ud_cfgdescr);
	    usb_destroy_device(deldev);
	    }
	}

    if (hub->uhub_imsg != NULL) {
	usb_dma_free(hub->uhub_imsg);
	}
    KFREE(hub);				/* remove softc */

    return 0;
}
Exemplo n.º 27
0
/***************************************************************************
 * Function Name: send_headers
 * Description  : This function sends an HTTP response to the browser.
 * Returns      : None.
 ***************************************************************************/
static void send_headers( int s, int status, char* title, char* extra_header,
    char* mime_type )
{
    int tcpret = 0;
    unsigned char buf[128];
    unsigned long secs = (unsigned long) cfe_ticks / CFE_HZ;

    sprintf( buf, "%s %d %s\r\n", PROTOCOL, status, title );
    tcpret = tcp_send( s, buf, strlen(buf) );
    sprintf( buf, "Server: %s\r\n", SERVER_NAME );
    tcpret = tcp_send( s, buf, strlen(buf) );
    sprintf( buf, "Date: Thu, 01 Jan 1970 %2.2d:%2.2d:%2.2d GMT\r\n",
        secs / 3600, (secs % 3600) / 60, secs % 60 );
    tcpret = tcp_send( s, buf, strlen(buf) );
    if ( extra_header != (char*) 0 )
    {
        sprintf( buf, "%s\r\n", extra_header );
        tcpret = tcp_send( s, buf, strlen(buf) );
    }
    if ( mime_type != (char*) 0 )
    {
        sprintf( buf, "Content-Type: %s\r\n", mime_type );
        tcpret = tcp_send( s, buf, strlen(buf) );
    }
    tcpret = tcp_send( s, "Connection: close\r\n\r\n",
        strlen("Connection: close\r\n\r\n") );

    if( tcpret < 0 )
        console_log("web error: TCP write error sending header.");
} /* send_headers */
Exemplo n.º 28
0
static int temp_showtemp(int noisy)
{
    int local,remote,status;
    char statstr[50];

    local  = temp_smbus_read(TEMPSENSOR_SMBUS_CHAN,TEMPSENSOR_SMBUS_DEV,0);
    remote = temp_smbus_read(TEMPSENSOR_SMBUS_CHAN,TEMPSENSOR_SMBUS_DEV,1);
    status = temp_smbus_read(TEMPSENSOR_SMBUS_CHAN,TEMPSENSOR_SMBUS_DEV,2);

    if ((local < 0) || (remote < 0) || (status < 0)) {
	if (noisy) printf("Temperature sensor device did not respond\n");
	return -1;
	}

    if (noisy || (local != temp_prev_local) || (remote != temp_prev_remote)) {
	statstr[0] = 0;
	if (status & 0x80) strcat(statstr,"Busy ");
	if (status & 0x40) strcat(statstr,"HiTempLcl ");
	if (status & 0x20) strcat(statstr,"LoTempLcl ");
	if (status & 0x10) strcat(statstr,"HiTempRem ");
	if (status & 0x08) strcat(statstr,"LoTempRem ");
	if (status & 0x04) strcat(statstr,"Fault ");

	if (noisy || !(status & 0x80)) {	
	    /* don't display if busy, always display if noisy */
	    console_log("Temperature:  CPU: %dC  Board: %dC  Status:%02X [ %s]",
		    remote,local,status,statstr);
	    }
	}

    temp_prev_local = local;
    temp_prev_remote = remote;

    return 0;
}
Exemplo n.º 29
0
/***************************************************************************
 * Function Name: read_post_data
 * Description  : This function reads HTTP POST data which is the contents of
 *                a new image to write to flash memory.
 * Returns      : UPLOAD_OK - all data read
 *                UPLOAD_PENDING - not all data read
 *                UPLOAD_TCP_ERROR - TCP error
 ***************************************************************************/
static char read_post_data( int s, unsigned char *post_data_start,
    int content_length, int *post_data_idx_ptr )
{
    char ret = UPLOAD_PENDING;
    int post_data_idx = *post_data_idx_ptr;
    int len;

    do
    {
        len = tcp_recv( s, post_data_start + post_data_idx,
            content_length - post_data_idx );
        post_data_idx += len;
        POLL();
        cfe_web_listen( &g_listen_idx );
    } while( len > 0 && post_data_idx < content_length );

    *post_data_idx_ptr = post_data_idx;

    if( len < 0 )
    {
        console_log("web error: TCP read error receiving post data.");
        ret = UPLOAD_TCP_ERROR;
    }
    else
        if( post_data_idx == content_length )
            ret = UPLOAD_OK;

    return( ret );
} /* read_post_data */
Exemplo n.º 30
0
// Decodes the UDP packet given in udp_packet to ipsc_packet,
// returns 1 if decoding was successful, otherwise returns 0.
flag_t ipscpacket_decode(struct udphdr *udppacket, ipscpacket_t *ipscpacket) {
	ipscpacket_raw_t *ipscpacket_raw = (ipscpacket_raw_t *)((uint8_t *)udppacket + sizeof(struct udphdr));
	int ipscpacket_raw_length = 0;
	int i;
	loglevel_t loglevel;

	// Length in UDP header contains length of the UDP header too, so we are substracting it.
	ipscpacket_raw_length = ntohs(udppacket->len)-sizeof(struct udphdr);
	if (ipscpacket_raw_length != IPSC_PACKET_SIZE1 && ipscpacket_raw_length != IPSC_PACKET_SIZE2) {
		//console_log(LOGLEVEL_DEBUG "ipscpacket: decode failed, packet size is %u not %u or %u bytes.\n",
		//	ipscpacket_raw_length, IPSC_PACKET_SIZE1, IPSC_PACKET_SIZE2);
		return 0;
	}

	loglevel = console_get_loglevel();
	if (loglevel.flags.debug && loglevel.flags.comm_dmr) {
		console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "ipscpacket: decoding: ");
		for (i = 0; i < ipscpacket_raw_length; i++)
			console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "%.2x ", *((uint8_t *)ipscpacket_raw+i));
		console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "\n");
	}

	/*if (ipscpacket_raw->delimiter != 0x1111) {
		console_log(LOGLEVEL_DEBUG "ipscpacket: decode failed, delimiter mismatch (it's %.4x, should be 0x1111)\n",
			ipscpacket_raw->delimiter);
		return 0;
	}*/

	ipscpacket->packet_type = ipscpacket_raw->packet_type;
	if (ipscpacket_raw->timeslot_raw == 0x1111)
		ipscpacket->timeslot = 1;
	else if (ipscpacket_raw->timeslot_raw == 0x2222)
		ipscpacket->timeslot = 2;
	else {
		console_log(LOGLEVEL_DEBUG LOGLEVEL_COMM_DMR "ipscpacket: decode failed, invalid timeslot (%.4x)\n", ipscpacket_raw->timeslot_raw);
		return 0;
	}

	ipscpacket->slot_type = ipscpacket_raw->slot_type;
	ipscpacket->frame_type = ipscpacket_raw->frame_type;
	ipscpacket->call_type = ipscpacket_raw->calltype;
	ipscpacket->dst_id = ipscpacket_raw->dst_id_raw3 << 16 | ipscpacket_raw->dst_id_raw2 << 8 | ipscpacket_raw->dst_id_raw1;
	ipscpacket->src_id = ipscpacket_raw->src_id_raw3 << 16 | ipscpacket_raw->src_id_raw2 << 8 | ipscpacket_raw->src_id_raw1;
	memcpy(ipscpacket->payload, (uint8_t *)ipscpacket_raw->payload, IPSCPACKET_PAYLOAD_SIZE);

	return 1;
}