diff options
author | Andreas Eversberg <jolly@eversberg.eu> | 2024-01-05 14:20:36 +0100 |
---|---|---|
committer | Andreas Eversberg <jolly@eversberg.eu> | 2024-02-18 16:23:29 +0100 |
commit | 3158c483653871f708a732eacec36adb3c59b165 (patch) | |
tree | b30450f51299b88060f39bc013763c8157ed88a3 /src | |
parent | 6cd2c3e323b5f8e873d986a78ee56e67e41e242e (diff) |
Move from local to external osmo* libraries
src/libdebug -> libosmocore
src/libselect -> libosmocore
src/libtimer -> libosmocore
src/libosmocc -> libosmo-cc
src/libg711 -> libosmo-cc
Diffstat (limited to 'src')
192 files changed, 4082 insertions, 12511 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a3fbe66..7e88735 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,8 +1,8 @@ AUTOMAKE_OPTIONS = foreign SUBDIRS = \ + liblogging \ liboptions \ - libdebug \ libmobile \ libdisplay \ libsample \ @@ -14,9 +14,6 @@ SUBDIRS = \ libsquelch \ libhagelbarger \ libdtmf \ - libtimer \ - libselect \ - libph_socket \ libsamplerate \ libscrambler \ libemphasis \ @@ -30,8 +27,6 @@ SUBDIRS = \ libserial \ libv27 \ libmtp \ - libosmocc \ - libg711 \ libaaimage if HAVE_ALSA diff --git a/src/amps/Makefile.am b/src/amps/Makefile.am index 5c4439a..475d733 100644 --- a/src/amps/Makefile.am +++ b/src/amps/Makefile.am @@ -31,23 +31,21 @@ amps_LDADD = \ libamps.a \ libusatone.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA @@ -76,23 +74,21 @@ tacs_LDADD = \ $(COMMON_LA) \ libamps.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA @@ -120,23 +116,21 @@ jtacs_LDADD = \ $(COMMON_LA) \ libamps.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/amps/amps.c b/src/amps/amps.c index 1dacd1b..9872da9 100644 --- a/src/amps/amps.c +++ b/src/amps/amps.c @@ -43,10 +43,10 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "amps.h" #include "dsp.h" #include "frame.h" @@ -57,15 +57,15 @@ /* Uncomment this to test SAT via loopback */ //#define DEBUG_VC -#define SAT_TO1 5.0 /* 5 sec to detect after setup */ -#define SAT_TO2 5.0 /* 5 sec lost until abort (specs say 5) */ -#define PAGE_TRIES 2 /* how many times to page the phone */ -#define PAGE_TO1 8.0 /* max time to wait for paging reply */ -#define PAGE_TO2 4.0 /* max time to wait for last paging reply */ -#define ALERT_TRIES 3 /* how many times to alert the phone */ -#define ALERT_TO 0.6 /* max time to wait for alert confirm */ -#define ANSWER_TO 60.0 /* max time to wait for answer */ -#define RELEASE_TIMER 5.0 /* max time to send release messages */ +#define SAT_TO1 5,0 /* 5 sec to detect after setup */ +#define SAT_TO2 5,0 /* 5 sec lost until abort (specs say 5) */ +#define PAGE_TRIES 2 /* how many times to page the phone */ +#define PAGE_TO1 8,0 /* max time to wait for paging reply */ +#define PAGE_TO2 4,0 /* max time to wait for last paging reply */ +#define ALERT_TRIES 3 /* how many times to alert the phone */ +#define ALERT_TO 0,600000 /* max time to wait for alert confirm */ +#define ANSWER_TO 60,0 /* max time to wait for answer */ +#define RELEASE_TIMER 5,0 /* max time to send release messages */ /* Convert channel number to frequency number of base station. Set 'uplink' to 1 to get frequency of mobile station. */ @@ -395,7 +395,7 @@ static void amps_new_state(amps_t *amps, enum amps_state new_state) { if (amps->state == new_state) return; - PDEBUG_CHAN(DAMPS, DEBUG_DEBUG, "State change: %s -> %s\n", amps_state_name(amps->state), amps_state_name(new_state)); + LOGP_CHAN(DAMPS, LOGL_DEBUG, "State change: %s -> %s\n", amps_state_name(amps->state), amps_state_name(new_state)); amps->state = new_state; amps_display_status(); } @@ -429,7 +429,7 @@ int amps_channel_by_short_name(const char *short_name) for (i = 0; amps_channels[i].short_name; i++) { if (!strcasecmp(amps_channels[i].short_name, short_name)) { - PDEBUG(DAMPS, DEBUG_INFO, "Selecting channel '%s' = %s\n", amps_channels[i].short_name, amps_channels[i].long_name); + LOGP(DAMPS, LOGL_INFO, "Selecting channel '%s' = %s\n", amps_channels[i].short_name, amps_channels[i].long_name); return amps_channels[i].chan_type; } } @@ -528,15 +528,15 @@ int amps_create(const char *kanal, enum amps_chan_type chan_type, const char *de /* check for channel number */ if (amps_channel2freq(atoi(kanal), 0) == 0) { - PDEBUG(DAMPS, DEBUG_ERROR, "Channel number %s invalid.\n", kanal); + LOGP(DAMPS, LOGL_ERROR, "Channel number %s invalid.\n", kanal); if (jtacs) - PDEBUG(DAMPS, DEBUG_ERROR, "Try an even channel number, like 440.\n"); + LOGP(DAMPS, LOGL_ERROR, "Try an even channel number, like 440.\n"); return -EINVAL; } /* no paging channel (without control channel) support */ if (chan_type == CHAN_TYPE_PC) { - PDEBUG(DAMPS, DEBUG_ERROR, "Dedicated paging channel currently not supported. Please select CC/PC or CC/PC/VC instead.\n"); + LOGP(DAMPS, LOGL_ERROR, "Dedicated paging channel currently not supported. Please select CC/PC or CC/PC/VC instead.\n"); return -EINVAL; } @@ -545,7 +545,7 @@ int amps_create(const char *kanal, enum amps_chan_type chan_type, const char *de for (sender = sender_head; sender; sender = sender->next) { amps = (amps_t *)sender; if (amps->chan_type == CHAN_TYPE_PC || amps->chan_type == CHAN_TYPE_CC_PC || amps->chan_type == CHAN_TYPE_CC_PC_VC) { - PDEBUG(DAMPS, DEBUG_ERROR, "Only one paging channel is currently supported. Please check your channel types.\n"); + LOGP(DAMPS, LOGL_ERROR, "Only one paging channel is currently supported. Please check your channel types.\n"); return -EINVAL; } } @@ -554,51 +554,51 @@ int amps_create(const char *kanal, enum amps_chan_type chan_type, const char *de /* check if channel type matches channel number */ ct = amps_channel2type(atoi(kanal)); if (ct == CHAN_TYPE_CC && chan_type != CHAN_TYPE_PC && chan_type != CHAN_TYPE_CC_PC && chan_type != CHAN_TYPE_CC_PC_VC) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Channel number %s belongs to a control channel, but your channel type '%s' requires to be on a voice channel number. Some phone may reject this, but all my phones don't.\n", kanal, chan_type_long_name(chan_type)); + LOGP(DAMPS, LOGL_NOTICE, "Channel number %s belongs to a control channel, but your channel type '%s' requires to be on a voice channel number. Some phone may reject this, but all my phones don't.\n", kanal, chan_type_long_name(chan_type)); } if (ct == CHAN_TYPE_VC && chan_type != CHAN_TYPE_VC) { - PDEBUG(DAMPS, DEBUG_ERROR, "Channel number %s belongs to a voice channel, but your channel type '%s' requires to be on a control channel number. Please use correct channel.\n", kanal, chan_type_long_name(chan_type)); + LOGP(DAMPS, LOGL_ERROR, "Channel number %s belongs to a voice channel, but your channel type '%s' requires to be on a control channel number. Please use correct channel.\n", kanal, chan_type_long_name(chan_type)); return -EINVAL; } /* only even channels */ if (jtacs && chan_type != CHAN_TYPE_VC && (atoi(kanal) & 1)) { - PDEBUG(DAMPS, DEBUG_ERROR, "Control channel on JTACS system seem not to work with odd channel numbers. Please use even channel number.\n"); + LOGP(DAMPS, LOGL_ERROR, "Control channel on JTACS system seem not to work with odd channel numbers. Please use even channel number.\n"); return -EINVAL; } /* check if sid machtes channel band */ band = amps_channel2band(atoi(kanal)); if (band[0] == 'A' && (sid & 1) == 0 && chan_type != CHAN_TYPE_VC) { - PDEBUG(DAMPS, DEBUG_ERROR, "Channel number %s belongs to system A, but your %s %d is even and belongs to system B. Please give odd %s.\n", kanal, (!tacs) ? "SID" : "AID", sid, (!tacs) ? "SID" : "AID"); + LOGP(DAMPS, LOGL_ERROR, "Channel number %s belongs to system A, but your %s %d is even and belongs to system B. Please give odd %s.\n", kanal, (!tacs) ? "SID" : "AID", sid, (!tacs) ? "SID" : "AID"); return -EINVAL; } if (band[0] == 'B' && (sid & 1) == 1 && chan_type != CHAN_TYPE_VC) { - PDEBUG(DAMPS, DEBUG_ERROR, "Channel number %s belongs to system B, but your %s %d is odd and belongs to system A. Please give even %s.\n", kanal, (!tacs) ? "SID" : "AID", sid, (!tacs) ? "SID" : "AID"); + LOGP(DAMPS, LOGL_ERROR, "Channel number %s belongs to system B, but your %s %d is odd and belongs to system A. Please give even %s.\n", kanal, (!tacs) ? "SID" : "AID", sid, (!tacs) ? "SID" : "AID"); return -EINVAL; } /* check if we use combined voice channel hack */ if (chan_type == CHAN_TYPE_CC_PC_VC) { - PDEBUG(DAMPS, DEBUG_NOTICE, "You selected '%s'. This is a hack, but the only way to use control channel and voice channel on one transceiver. Some phones may reject this, but all my phones don't.\n", chan_type_long_name(chan_type)); + LOGP(DAMPS, LOGL_NOTICE, "You selected '%s'. This is a hack, but the only way to use control channel and voice channel on one transceiver. Some phones may reject this, but all my phones don't.\n", chan_type_long_name(chan_type)); } /* check if we selected a voice channel that i outside 20 MHz band */ if (chan_type == CHAN_TYPE_VC && atoi(kanal) > 666) { - PDEBUG(DAMPS, DEBUG_NOTICE, "You selected '%s' on channel #%s. Older phones do not support channels above #666.\n", chan_type_long_name(chan_type), kanal); + LOGP(DAMPS, LOGL_NOTICE, "You selected '%s' on channel #%s. Older phones do not support channels above #666.\n", chan_type_long_name(chan_type), kanal); } amps = calloc(1, sizeof(amps_t)); if (!amps) { - PDEBUG(DAMPS, DEBUG_ERROR, "No memory!\n"); + LOGP(DAMPS, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DAMPS, DEBUG_DEBUG, "Creating 'AMPS' instance for channel = %s of band %s (sample rate %d).\n", kanal, band, samplerate); + LOGP(DAMPS, LOGL_DEBUG, "Creating 'AMPS' instance for channel = %s of band %s (sample rate %d).\n", kanal, band, samplerate); /* init general part of transceiver */ rc = sender_create(&s->sender, kanal, amps_channel2freq(atoi(kanal), 0), amps_channel2freq(atoi(kanal), 1), device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DAMPS, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DAMPS, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } @@ -619,7 +619,7 @@ int amps_create(const char *kanal, enum amps_chan_type chan_type, const char *de /* init audio processing */ rc = dsp_init_sender(amps, tolerant); if (rc < 0) { - PDEBUG(DAMPS, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DAMPS, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } @@ -634,7 +634,7 @@ int amps_create(const char *kanal, enum amps_chan_type chan_type, const char *de // amps_new_state(amps, STATE_BUSY); #endif - PDEBUG(DAMPS, DEBUG_NOTICE, "Created channel #%s (System %s) of type '%s' = %s\n", kanal, band, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); + LOGP(DAMPS, LOGL_NOTICE, "Created channel #%s (System %s) of type '%s' = %s\n", kanal, band, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); return 0; @@ -650,11 +650,11 @@ void amps_destroy(sender_t *sender) amps_t *amps = (amps_t *) sender; transaction_t *trans; - PDEBUG(DAMPS, DEBUG_DEBUG, "Destroying 'AMPS' instance for channel = %s.\n", sender->kanal); + LOGP(DAMPS, LOGL_DEBUG, "Destroying 'AMPS' instance for channel = %s.\n", sender->kanal); while ((trans = amps->trans_list)) { const char *number = amps_min2number(trans->min1, trans->min2); - PDEBUG(DAMPS, DEBUG_NOTICE, "Removing pending transaction for subscriber '%s'\n", number); + LOGP(DAMPS, LOGL_NOTICE, "Removing pending transaction for subscriber '%s'\n", number); destroy_transaction(trans); } @@ -672,7 +672,7 @@ void amps_go_idle(amps_t *amps) return; if (amps->trans_list) { - PDEBUG(DAMPS, DEBUG_ERROR, "Releasing but still having transaction, please fix!\n"); + LOGP(DAMPS, LOGL_ERROR, "Releasing but still having transaction, please fix!\n"); if (amps->trans_list->callref) call_up_release(amps->trans_list->callref, CAUSE_NORMAL); destroy_transaction(amps->trans_list); @@ -681,14 +681,14 @@ void amps_go_idle(amps_t *amps) amps_new_state(amps, STATE_IDLE); if (amps->chan_type != CHAN_TYPE_VC) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Entering IDLE state, sending Overhead/Filler frames on %s.\n", chan_type_long_name(amps->chan_type)); + LOGP_CHAN(DAMPS, LOGL_INFO, "Entering IDLE state, sending Overhead/Filler frames on %s.\n", chan_type_long_name(amps->chan_type)); if (amps->sender.loopback) frame_length = 441; /* bits after sync (FOCC) */ else frame_length = 247; /* bits after sync (RECC) */ amps_set_dsp_mode(amps, DSP_MODE_FRAME_RX_FRAME_TX, frame_length); } else { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Entering IDLE state (sending silence / no RF) on %s.\n", chan_type_long_name(amps->chan_type)); + LOGP_CHAN(DAMPS, LOGL_INFO, "Entering IDLE state (sending silence / no RF) on %s.\n", chan_type_long_name(amps->chan_type)); amps_set_dsp_mode(amps, DSP_MODE_OFF, 0); } } @@ -698,8 +698,8 @@ static void amps_release(transaction_t *trans, uint8_t cause) { amps_t *amps = trans->amps; - timer_stop(&trans->timer); - timer_start(&trans->timer, RELEASE_TIMER); + osmo_timer_del(&trans->timer); + osmo_timer_schedule(&trans->timer, RELEASE_TIMER); trans_new_state(trans, TRANS_CALL_RELEASE); trans->chan = 0; trans->msg_type = 0; @@ -722,14 +722,14 @@ void amps_rx_signaling_tone(amps_t *amps, int tone, double quality) { transaction_t *trans = amps->trans_list; if (trans == NULL) { - PDEBUG_CHAN(DAMPS, DEBUG_ERROR, "Signaling Tone without transaction, please fix!\n"); + LOGP_CHAN(DAMPS, LOGL_ERROR, "Signaling Tone without transaction, please fix!\n"); return; } if (tone) - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Detected Signaling Tone with quality=%.0f.\n", quality * 100.0); + LOGP_CHAN(DAMPS, LOGL_INFO, "Detected Signaling Tone with quality=%.0f.\n", quality * 100.0); else - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Lost Signaling Tone signal\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Lost Signaling Tone signal\n"); switch (trans->state) { case TRANS_CALL_MO_ASSIGN_CONFIRM: // should not happen @@ -740,7 +740,7 @@ void amps_rx_signaling_tone(amps_t *amps, int tone, double quality) case TRANS_CALL_RELEASE: case TRANS_CALL_RELEASE_SEND: /* also loosing singaling tone indicates release confirm (after alerting) */ - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); if (trans->callref) call_up_release(trans->callref, CAUSE_NORMAL); destroy_transaction(trans); @@ -751,24 +751,24 @@ void amps_rx_signaling_tone(amps_t *amps, int tone, double quality) case TRANS_CALL_MT_ALERT_SEND: // should not happen case TRANS_CALL_MT_ALERT_CONFIRM: if (tone) { - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); call_up_alerting(trans->callref); amps_set_dsp_mode(amps, DSP_MODE_AUDIO_RX_AUDIO_TX, 0); trans_new_state(trans, TRANS_CALL_MT_ANSWER_WAIT); - timer_start(&trans->timer, ANSWER_TO); + osmo_timer_schedule(&trans->timer, ANSWER_TO); } break; case TRANS_CALL_MT_ANSWER_WAIT: if (!tone) { - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); if (!trans->sat_detected) - timer_start(&trans->timer, SAT_TO1); + osmo_timer_schedule(&trans->timer, SAT_TO1); call_up_answer(trans->callref, amps_min2number(trans->min1, trans->min2)); trans_new_state(trans, TRANS_CALL); } break; default: - PDEBUG_CHAN(DAMPS, DEBUG_ERROR, "Signaling Tone without active call, please fix!\n"); + LOGP_CHAN(DAMPS, LOGL_ERROR, "Signaling Tone without active call, please fix!\n"); } } @@ -776,7 +776,7 @@ void amps_rx_sat(amps_t *amps, int tone, double quality) { transaction_t *trans = amps->trans_list; if (trans == NULL) { - PDEBUG_CHAN(DAMPS, DEBUG_ERROR, "SAT signal without transaction, please fix!\n"); + LOGP_CHAN(DAMPS, LOGL_ERROR, "SAT signal without transaction, please fix!\n"); return; } @@ -793,40 +793,40 @@ void amps_rx_sat(amps_t *amps, int tone, double quality) && trans->state != TRANS_CALL_MT_ALERT_CONFIRM && trans->state != TRANS_CALL_MT_ANSWER_WAIT && trans->state != TRANS_CALL) { - PDEBUG_CHAN(DAMPS, DEBUG_ERROR, "SAT signal without active call, please fix!\n"); + LOGP_CHAN(DAMPS, LOGL_ERROR, "SAT signal without active call, please fix!\n"); return; } if (tone) { - PDEBUG(DAMPS, DEBUG_INFO, "Detected SAT signal with quality=%.0f.\n", quality * 100.0); + LOGP(DAMPS, LOGL_INFO, "Detected SAT signal with quality=%.0f.\n", quality * 100.0); trans->sat_detected = 1; } else { - PDEBUG(DAMPS, DEBUG_INFO, "Lost SAT signal\n"); + LOGP(DAMPS, LOGL_INFO, "Lost SAT signal\n"); trans->sat_detected = 0; } /* initial SAT received */ if (tone && trans->state == TRANS_CALL_MO_ASSIGN_CONFIRM) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Confirm from mobile (SAT) received\n"); - timer_stop(&trans->timer); + LOGP_CHAN(DAMPS, LOGL_INFO, "Confirm from mobile (SAT) received\n"); + osmo_timer_del(&trans->timer); trans_new_state(trans, TRANS_CALL); amps_set_dsp_mode(amps, DSP_MODE_AUDIO_RX_AUDIO_TX, 0); } if (tone && trans->state == TRANS_CALL_MT_ASSIGN_CONFIRM) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Confirm from mobile (SAT) received\n"); - timer_stop(&trans->timer); + LOGP_CHAN(DAMPS, LOGL_INFO, "Confirm from mobile (SAT) received\n"); + osmo_timer_del(&trans->timer); trans->alert_retry = 1; trans_new_state(trans, TRANS_CALL_MT_ALERT); amps_set_dsp_mode(amps, DSP_MODE_AUDIO_RX_FRAME_TX, 0); } if (tone) { - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); } else { if (!trans->dtx) - timer_start(&trans->timer, SAT_TO2); + osmo_timer_schedule(&trans->timer, SAT_TO2); else - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); } if (amps->sender.loopback) @@ -843,50 +843,50 @@ void amps_rx_recc(amps_t *amps, uint8_t scm, uint8_t mpci, uint32_t esn, uint32_ /* check if we are busy, so we ignore all signaling */ if (amps->state == STATE_BUSY) { - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Ignoring RECC messages from phone while using this channel for voice.\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Ignoring RECC messages from phone while using this channel for voice.\n"); return; } if (order == 13 && (ordq == 0 || ordq == 1 || ordq == 2 || ordq == 3) && msg_type == 0) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Registration %s (ESN = %s, %s, %s)\n", callerid, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); + LOGP_CHAN(DAMPS, LOGL_INFO, "Registration %s (ESN = %s, %s, %s)\n", callerid, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); _register: numbering(callerid, &carrier, &country, &national_number); if (carrier) - PDEBUG_CHAN(DAMPS, DEBUG_INFO, " -> Home carrier: %s\n", carrier); + LOGP_CHAN(DAMPS, LOGL_INFO, " -> Home carrier: %s\n", carrier); if (country) - PDEBUG_CHAN(DAMPS, DEBUG_INFO, " -> Home country: %s\n", country); + LOGP_CHAN(DAMPS, LOGL_INFO, " -> Home country: %s\n", country); if (national_number) - PDEBUG_CHAN(DAMPS, DEBUG_INFO, " -> Home number: %s\n", national_number); + LOGP_CHAN(DAMPS, LOGL_INFO, " -> Home number: %s\n", national_number); trans = create_transaction(amps, TRANS_REGISTER_ACK, min1, min2, esn, msg_type, ordq, order, 0); if (!trans) { - PDEBUG(DAMPS, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DAMPS, LOGL_ERROR, "Failed to create transaction\n"); return; } } else if (order == 13 && ordq == 3 && msg_type == 1) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Registration - Power Down %s (ESN = %s, %s, %s)\n", callerid, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); + LOGP_CHAN(DAMPS, LOGL_INFO, "Registration - Power Down %s (ESN = %s, %s, %s)\n", callerid, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); goto _register; } else if (order == 0 && ordq == 0 && msg_type == 0) { if (!dialing) - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Paging reply %s (ESN = %s, %s, %s)\n", callerid, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); + LOGP_CHAN(DAMPS, LOGL_INFO, "Paging reply %s (ESN = %s, %s, %s)\n", callerid, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); else - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Call %s -> %s (ESN = %s, %s, %s)\n", callerid, dialing, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); + LOGP_CHAN(DAMPS, LOGL_INFO, "Call %s -> %s (ESN = %s, %s, %s)\n", callerid, dialing, esn_to_string(esn), amps_scm(scm), amps_mpci(mpci)); trans = search_transaction_number(amps, min1, min2); if (!trans && !dialing) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Paging reply, but call is already gone, rejecting call\n"); + LOGP(DAMPS, LOGL_NOTICE, "Paging reply, but call is already gone, rejecting call\n"); goto reject; } if (trans && dialing) - PDEBUG(DAMPS, DEBUG_NOTICE, "There is already a transaction for this phone. Cloning?\n"); + LOGP(DAMPS, LOGL_NOTICE, "There is already a transaction for this phone. Cloning?\n"); vc = search_free_vc(); if (!vc) { - PDEBUG(DAMPS, DEBUG_NOTICE, "No free channel, rejecting call\n"); + LOGP(DAMPS, LOGL_NOTICE, "No free channel, rejecting call\n"); reject: if (!trans) { trans = create_transaction(amps, TRANS_CALL_REJECT, min1, min2, esn, 0, 0, 3, 0); if (!trans) { - PDEBUG(DAMPS, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DAMPS, LOGL_ERROR, "Failed to create transaction\n"); return; } } else { @@ -902,7 +902,7 @@ reject: trans = create_transaction(amps, TRANS_CALL_MO_ASSIGN, min1, min2, esn, 0, 0, 0, atoi(vc->sender.kanal)); strncpy(trans->dialing, dialing, sizeof(trans->dialing) - 1); if (!trans) { - PDEBUG(DAMPS, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DAMPS, LOGL_ERROR, "Failed to create transaction\n"); return; } } else { @@ -912,13 +912,13 @@ reject: /* if we support DTX and also the phone does, we set DTX state of transaction */ if (amps->si.word2.dtx) { if ((scm & 4)) { - PDEBUG(DAMPS, DEBUG_INFO, " -> Use DTX for this call\n"); + LOGP(DAMPS, LOGL_INFO, " -> Use DTX for this call\n"); trans->dtx = 1; } else - PDEBUG(DAMPS, DEBUG_INFO, " -> Requested DTX, but not supported by phone\n"); + LOGP(DAMPS, LOGL_INFO, " -> Requested DTX, but not supported by phone\n"); } } else - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Unsupported RECC messages: ORDER: %d ORDQ: %d MSG TYPE: %d (See Table 4 of specs.)\n", order, ordq, msg_type); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Unsupported RECC messages: ORDER: %d ORDQ: %d MSG TYPE: %d (See Table 4 of specs.)\n", order, ordq, msg_type); } /* @@ -939,7 +939,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 2. check if the subscriber is attached */ // if (!find_db(min1, min2)) { -// PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing call to not attached subscriber, rejecting!\n"); +// LOGP(DAMPS, LOGL_NOTICE, "Outgoing call to not attached subscriber, rejecting!\n"); // return -CAUSE_OUTOFORDER; // } @@ -952,29 +952,29 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (sender) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DAMPS, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } /* 4. check if all senders are busy, return NOCHANNEL */ if (!search_free_vc()) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DAMPS, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } /* 5. check if we have (currently) no paging channel, return NOCHANNEL */ amps = search_pc(); if (!amps) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing call, but paging channel (control channel) is currently busy, rejecting!\n"); + LOGP(DAMPS, LOGL_NOTICE, "Outgoing call, but paging channel (control channel) is currently busy, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Call to mobile station, paging station id '%s'\n", dialing); + LOGP_CHAN(DAMPS, LOGL_INFO, "Call to mobile station, paging station id '%s'\n", dialing); /* 6. trying to page mobile station */ trans = create_transaction(amps, TRANS_PAGE, min1, min2, 0, 0, 0, 0, 0); if (!trans) { - PDEBUG(DAMPS, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DAMPS, LOGL_ERROR, "Failed to create transaction\n"); return -CAUSE_TEMPFAIL; } trans->callref = callref; @@ -1002,7 +1002,7 @@ void call_down_disconnect(int callref, int cause) amps_t *amps; transaction_t *trans; - PDEBUG(DAMPS, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DAMPS, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { amps = (amps_t *) sender; @@ -1012,7 +1012,7 @@ void call_down_disconnect(int callref, int cause) break; } if (!sender) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DAMPS, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1027,12 +1027,12 @@ void call_down_disconnect(int callref, int cause) || trans->state == TRANS_CALL_MT_ALERT_SEND || trans->state == TRANS_CALL_MT_ALERT_CONFIRM || trans->state == TRANS_CALL_MT_ANSWER_WAIT) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Call control disconnect on voice channel while alerting, releasing towards mobile station.\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Call control disconnect on voice channel while alerting, releasing towards mobile station.\n"); amps_release(trans, cause); } return; default: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Call control disconnects on control channel, removing transaction.\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Call control disconnects on control channel, removing transaction.\n"); call_up_release(callref, cause); trans->callref = 0; destroy_transaction(trans); @@ -1047,7 +1047,7 @@ void call_down_release(int callref, int cause) amps_t *amps; transaction_t *trans; - PDEBUG(DAMPS, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DAMPS, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { amps = (amps_t *) sender; @@ -1057,7 +1057,7 @@ void call_down_release(int callref, int cause) break; } if (!sender) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DAMPS, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -1068,11 +1068,11 @@ void call_down_release(int callref, int cause) case DSP_MODE_AUDIO_RX_SILENCE_TX: case DSP_MODE_AUDIO_RX_AUDIO_TX: case DSP_MODE_AUDIO_RX_FRAME_TX: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Call control releases on voice channel, releasing towards mobile station.\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Call control releases on voice channel, releasing towards mobile station.\n"); amps_release(trans, cause); break; default: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Call control releases on control channel, removing transaction.\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Call control releases on control channel, removing transaction.\n"); destroy_transaction(trans); amps_go_idle(amps); } @@ -1109,47 +1109,47 @@ void transaction_timeout(void *data) switch (trans->state) { case TRANS_CALL_MO_ASSIGN_CONFIRM: case TRANS_CALL_MT_ASSIGN_CONFIRM: - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Timeout after %.0f seconds not receiving initial SAT signal.\n", trans->timer.duration); - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Release call towards network.\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Timeout after %ld seconds not receiving initial SAT signal.\n", trans->timer.timeout.tv_sec); + LOGP_CHAN(DAMPS, LOGL_INFO, "Release call towards network.\n"); amps_release(amps->trans_list, CAUSE_TEMPFAIL); break; case TRANS_CALL: - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Timeout after %.0f seconds loosing SAT signal.\n", trans->timer.duration); - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Release call towards network.\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Timeout after %ld seconds loosing SAT signal.\n", trans->timer.timeout.tv_sec); + LOGP_CHAN(DAMPS, LOGL_INFO, "Release call towards network.\n"); amps_release(amps->trans_list, CAUSE_TEMPFAIL); break; case TRANS_CALL_RELEASE: case TRANS_CALL_RELEASE_SEND: - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Release timeout, destroying transaction\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Release timeout, destroying transaction\n"); destroy_transaction(trans); amps_go_idle(amps); break; case TRANS_CALL_MT_ALERT_SEND: case TRANS_CALL_MT_ALERT_CONFIRM: if (trans->alert_retry++ == ALERT_TRIES) { - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Phone does not respond to alert order, destroying transaction\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Phone does not respond to alert order, destroying transaction\n"); amps_release(trans, CAUSE_TEMPFAIL); } else { - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Phone does not respond to alert order, retrying\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Phone does not respond to alert order, retrying\n"); trans_new_state(trans, TRANS_CALL_MT_ALERT); amps_set_dsp_mode(amps, DSP_MODE_AUDIO_RX_FRAME_TX, 0); } break; case TRANS_CALL_MT_ANSWER_WAIT: - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Alerting timeout, destroying transaction\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Alerting timeout, destroying transaction\n"); amps_release(trans, CAUSE_NOANSWER); break; case TRANS_PAGE_REPLY: if (trans->page_retry++ == PAGE_TRIES) { - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Paging timeout, destroying transaction\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Paging timeout, destroying transaction\n"); amps_release(trans, CAUSE_OUTOFORDER); } else { - PDEBUG_CHAN(DAMPS, DEBUG_NOTICE, "Paging timeout, retrying\n"); + LOGP_CHAN(DAMPS, LOGL_NOTICE, "Paging timeout, retrying\n"); trans_new_state(trans, TRANS_PAGE); } break; default: - PDEBUG_CHAN(DAMPS, DEBUG_ERROR, "Timeout unhandled in state %d\n", trans->state); + LOGP_CHAN(DAMPS, LOGL_ERROR, "Timeout unhandled in state %d\n", trans->state); } } @@ -1161,18 +1161,18 @@ static amps_t *assign_voice_channel(transaction_t *trans) vc = search_channel(trans->chan); if (!vc) { - PDEBUG(DAMPS, DEBUG_NOTICE, "Channel %d is not free anymore, rejecting call\n", trans->chan); + LOGP(DAMPS, LOGL_NOTICE, "Channel %d is not free anymore, rejecting call\n", trans->chan); amps_release(trans, CAUSE_NOCHANNEL); return NULL; } if (vc == amps) - PDEBUG(DAMPS, DEBUG_INFO, "Staying on combined control + voice channel %s\n", vc->sender.kanal); + LOGP(DAMPS, LOGL_INFO, "Staying on combined control + voice channel %s\n", vc->sender.kanal); else - PDEBUG(DAMPS, DEBUG_INFO, "Moving to voice channel %s\n", vc->sender.kanal); + LOGP(DAMPS, LOGL_INFO, "Moving to voice channel %s\n", vc->sender.kanal); /* switch channel... */ - timer_start(&trans->timer, SAT_TO1); + osmo_timer_schedule(&trans->timer, SAT_TO1); /* make channel busy */ amps_new_state(vc, STATE_BUSY); /* relink */ @@ -1185,7 +1185,7 @@ static amps_t *assign_voice_channel(transaction_t *trans) char esn_text[16]; sprintf(esn_text, "%u", trans->esn); /* setup call */ - PDEBUG(DAMPS, DEBUG_INFO, "Setup call to network.\n"); + LOGP(DAMPS, LOGL_INFO, "Setup call to network.\n"); trans->callref = call_up_setup(callerid, trans->dialing, OSMO_CC_NETWORK_AMPS_ESN, esn_text); } @@ -1204,52 +1204,55 @@ again: switch (trans->state) { case TRANS_REGISTER_ACK: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Sending Register acknowledge\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Sending Register acknowledge\n"); trans_new_state(trans, TRANS_REGISTER_ACK_SEND); return trans; case TRANS_REGISTER_ACK_SEND: destroy_transaction(trans); goto again; case TRANS_CALL_REJECT: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Rejecting call from mobile station\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Rejecting call from mobile station\n"); trans_new_state(trans, TRANS_CALL_REJECT_SEND); return trans; case TRANS_CALL_REJECT_SEND: destroy_transaction(trans); goto again; case TRANS_CALL_MO_ASSIGN: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Assigning channel to call from mobile station\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Assigning channel to call from mobile station\n"); trans_new_state(trans, TRANS_CALL_MO_ASSIGN_SEND); return trans; case TRANS_CALL_MO_ASSIGN_SEND: vc = assign_voice_channel(trans); if (vc) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Assignment complete, voice connected\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Assignment complete, voice connected\n"); /* timer and other things are processed at assign_voice_channel() */ trans_new_state(trans, TRANS_CALL_MO_ASSIGN_CONFIRM); amps_set_dsp_mode(vc, DSP_MODE_AUDIO_RX_SILENCE_TX, 0); } return NULL; case TRANS_CALL_MT_ASSIGN: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Assigning channel to call to mobile station\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Assigning channel to call to mobile station\n"); trans_new_state(trans, TRANS_CALL_MT_ASSIGN_SEND); return trans; case TRANS_CALL_MT_ASSIGN_SEND: vc = assign_voice_channel(trans); if (vc) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Assignment complete, waiting for SAT on VC\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Assignment complete, waiting for SAT on VC\n"); /* timer and other things are processed at assign_voice_channel() */ trans_new_state(trans, TRANS_CALL_MT_ASSIGN_CONFIRM); amps_set_dsp_mode(vc, DSP_MODE_AUDIO_RX_SILENCE_TX, 0); } return NULL; case TRANS_PAGE: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Paging the phone\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Paging the phone\n"); trans_new_state(trans, TRANS_PAGE_SEND); return trans; case TRANS_PAGE_SEND: trans_new_state(trans, TRANS_PAGE_REPLY); - timer_start(&trans->timer, (trans->page_retry == PAGE_TRIES) ? PAGE_TO2 : PAGE_TO1); + if (trans->page_retry == PAGE_TRIES) + osmo_timer_schedule(&trans->timer, PAGE_TO2); + else + osmo_timer_schedule(&trans->timer, PAGE_TO1); return NULL; default: return NULL; @@ -1266,11 +1269,11 @@ transaction_t *amps_tx_frame_fvc(amps_t *amps) switch (trans->state) { case TRANS_CALL_RELEASE: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Releasing call towards mobile station\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Releasing call towards mobile station\n"); trans_new_state(trans, TRANS_CALL_RELEASE_SEND); return trans; case TRANS_CALL_RELEASE_SEND: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Release call was sent, continue sending release\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Release call was sent, continue sending release\n"); return trans; case TRANS_CALL_MT_ALERT: trans->chan = 0; @@ -1278,17 +1281,17 @@ transaction_t *amps_tx_frame_fvc(amps_t *amps) trans->ordq = 0; // "Alert with caller ID" causes older phones to interrupt the connection for some reason, therefore we don't use order 17 when no caller ID is set if (amps->send_callerid && trans->alert_retry == 1 && trans->caller_id[0]) { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Sending alerting with caller ID\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Sending alerting with caller ID\n"); trans->order = 17; } else { - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Sending alerting\n"); + LOGP_CHAN(DAMPS, LOGL_INFO, "Sending alerting\n"); trans->order = 1; } trans_new_state(trans, TRANS_CALL_MT_ALERT_SEND); return trans; case TRANS_CALL_MT_ALERT_SEND: - PDEBUG_CHAN(DAMPS, DEBUG_INFO, "Alerting was sent, continue waiting for ST or timeout\n"); - timer_start(&trans->timer, ALERT_TO); + LOGP_CHAN(DAMPS, LOGL_INFO, "Alerting was sent, continue waiting for ST or timeout\n"); + osmo_timer_schedule(&trans->timer, ALERT_TO); amps_set_dsp_mode(amps, DSP_MODE_AUDIO_RX_SILENCE_TX, 0); trans_new_state(trans, TRANS_CALL_MT_ALERT_CONFIRM); return NULL; diff --git a/src/amps/amps.h b/src/amps/amps.h index 53e6fea..c74be61 100644 --- a/src/amps/amps.h +++ b/src/amps/amps.h @@ -1,6 +1,6 @@ #include "../libgoertzel/goertzel.h" #include "../libmobile/sender.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../libcompandor/compandor.h" typedef struct amps amps_t; #include "sysinfo.h" diff --git a/src/amps/dsp.c b/src/amps/dsp.c index 8b6f7e6..a4b2a83 100644 --- a/src/amps/dsp.c +++ b/src/amps/dsp.c @@ -82,8 +82,9 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" +#include "../libmobile/get_time.h" #include "amps.h" #include "frame.h" #include "dsp.h" @@ -146,7 +147,7 @@ void dsp_init(void) int i; double s; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table for SAT signal.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine table for SAT signal.\n"); for (i = 0; i < 65536; i++) { s = sin((double)i / 65536.0 * 2.0 * PI); dsp_sine_sat[i] = s * ((!tacs) ? AMPS_SAT_DEVIATION : TACS_SAT_DEVIATION); @@ -171,7 +172,7 @@ static void dsp_init_ramp(amps_t *amps) double c; int i; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating smooth ramp table.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating smooth ramp table.\n"); for (i = 0; i < 256; i++) { c = cos((double)i / 256.0 * PI); #if 0 @@ -198,7 +199,7 @@ int dsp_init_sender(amps_t *amps, int tolerant) /* attack (3ms) and recovery time (13.5ms) according to amps specs */ setup_compandor(&s->cstate, 8000, 3.0, 13.5); - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for transceiver.\n"); /* set modulation parameters */ sender_set_fm(&s->sender, @@ -208,18 +209,18 @@ int dsp_init_sender(amps_t *amps, int tolerant) (!tacs) ? AMPS_MAX_DISPLAY : TACS_MAX_DISPLAY); if (amps->sender.samplerate < 96000) { - PDEBUG(DDSP, DEBUG_ERROR, "Sample rate must be at least 96000 Hz to process FSK and SAT signals.\n"); + LOGP(DDSP, LOGL_ERROR, "Sample rate must be at least 96000 Hz to process FSK and SAT signals.\n"); return -EINVAL; } amps->fsk_bitduration = (double)amps->sender.samplerate / (double)((!tacs) ? AMPS_BITRATE : TACS_BITRATE); amps->fsk_bitstep = 1.0 / amps->fsk_bitduration; - PDEBUG(DDSP, DEBUG_DEBUG, "Use %.4f samples for full bit duration @ %d.\n", amps->fsk_bitduration, amps->sender.samplerate); + LOGP(DDSP, LOGL_DEBUG, "Use %.4f samples for full bit duration @ %d.\n", amps->fsk_bitduration, amps->sender.samplerate); amps->fsk_tx_buffer_size = amps->fsk_bitduration + 10; /* 10 extra to avoid overflow due to rounding */ spl = calloc(sizeof(*spl), amps->fsk_tx_buffer_size); if (!spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP(DDSP, LOGL_ERROR, "No memory!\n"); rc = -ENOMEM; goto error; } @@ -230,12 +231,12 @@ int dsp_init_sender(amps_t *amps, int tolerant) amps->fsk_rx_window_begin = half >> 1; amps->fsk_rx_window_half = half; amps->fsk_rx_window_end = amps->fsk_rx_window_length - (half >> 1); - PDEBUG(DDSP, DEBUG_DEBUG, "Bit window length: %d\n", amps->fsk_rx_window_length); - PDEBUG(DDSP, DEBUG_DEBUG, " -> Samples in window to analyse level left of edge: %d..%d\n", amps->fsk_rx_window_begin, amps->fsk_rx_window_half - 1); - PDEBUG(DDSP, DEBUG_DEBUG, " -> Samples in window to analyse level right of edge: %d..%d\n", amps->fsk_rx_window_half, amps->fsk_rx_window_end - 1); + LOGP(DDSP, LOGL_DEBUG, "Bit window length: %d\n", amps->fsk_rx_window_length); + LOGP(DDSP, LOGL_DEBUG, " -> Samples in window to analyse level left of edge: %d..%d\n", amps->fsk_rx_window_begin, amps->fsk_rx_window_half - 1); + LOGP(DDSP, LOGL_DEBUG, " -> Samples in window to analyse level right of edge: %d..%d\n", amps->fsk_rx_window_half, amps->fsk_rx_window_end - 1); spl = calloc(sizeof(*amps->fsk_rx_window), amps->fsk_rx_window_length); if (!spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP(DDSP, LOGL_ERROR, "No memory!\n"); rc = -ENOMEM; goto error; } @@ -252,10 +253,10 @@ int dsp_init_sender(amps_t *amps, int tolerant) amps->sat_samples = (int)((double)amps->sender.samplerate * (1.0 / (SAT_BANDWIDTH / 2.0)) + 0.5); spl = calloc(sizeof(*spl), amps->sat_samples); if (!spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP(DDSP, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DDSP, DEBUG_DEBUG, "Sat detection interval is %d ms.\n", amps->sat_samples * 1000 / amps->sender.samplerate); + LOGP(DDSP, LOGL_DEBUG, "Sat detection interval is %d ms.\n", amps->sat_samples * 1000 / amps->sender.samplerate); amps->sat_filter_spl = spl; /* count SAT tones */ @@ -289,7 +290,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_sender(amps_t *amps) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for treansceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for treansceiver.\n"); if (amps->fsk_tx_buffer) free(amps->fsk_tx_buffer); @@ -770,7 +771,7 @@ static void sat_decode(amps_t *amps, sample_t *samples, int length) /* debug SAT */ if (++amps->sat_print == SAT_PRINT) { - PDEBUG_CHAN(DDSP, DEBUG_NOTICE, "SAT level %.2f%% quality %.0f%%\n", sat_level * 100.0, sat_quality * 100.0); + LOGP_CHAN(DDSP, LOGL_NOTICE, "SAT level %.2f%% quality %.0f%%\n", sat_level * 100.0, sat_quality * 100.0); amps->sat_print = 0; } @@ -779,8 +780,8 @@ static void sat_decode(amps_t *amps, sample_t *samples, int length) display_measurements_update(amps->dmp_sat_quality, sat_quality * 100.0, 0.0); /* debug signaling tone */ - if (amps->sender.loopback || debuglevel == DEBUG_DEBUG) { - PDEBUG_CHAN(DDSP, debuglevel, "Signaling Tone level %.2f%% quality %.0f%%\n", sig_level * 100.0, sig_quality * 100.0); + if (amps->sender.loopback || loglevel == LOGL_DEBUG) { + LOGP_CHAN(DDSP, loglevel, "Signaling Tone level %.2f%% quality %.0f%%\n", sig_level * 100.0, sig_quality * 100.0); } /* mute if SAT quality or level is below threshold */ @@ -796,7 +797,7 @@ static void sat_decode(amps_t *amps, sample_t *samples, int length) if (amps->sat_detect_count == SAT_DETECT_COUNT) { amps->sat_detected = 1; amps->sat_detect_count = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "SAT signal detected with level=%.0f%%, quality=%.0f%%.\n", sat_level * 100.0, sat_quality * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "SAT signal detected with level=%.0f%%, quality=%.0f%%.\n", sat_level * 100.0, sat_quality * 100.0); amps_rx_sat(amps, 1, sat_quality); } } else @@ -807,7 +808,7 @@ static void sat_decode(amps_t *amps, sample_t *samples, int length) if (amps->sat_detect_count == SAT_LOST_COUNT) { amps->sat_detected = 0; amps->sat_detect_count = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "SAT signal lost.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "SAT signal lost.\n"); amps_rx_sat(amps, 0, 0.0); } } else @@ -821,7 +822,7 @@ static void sat_decode(amps_t *amps, sample_t *samples, int length) if (amps->sig_detect_count == SIG_DETECT_COUNT) { amps->sig_detected = 1; amps->sig_detect_count = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Signaling Tone detected with level=%.0f%%, quality=%.0f%%.\n", sig_level * 100.0, sig_quality * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Signaling Tone detected with level=%.0f%%, quality=%.0f%%.\n", sig_level * 100.0, sig_quality * 100.0); amps_rx_signaling_tone(amps, 1, sig_quality); } } else @@ -832,7 +833,7 @@ static void sat_decode(amps_t *amps, sample_t *samples, int length) if (amps->sig_detect_count == SIG_LOST_COUNT) { amps->sig_detected = 0; amps->sig_detect_count = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Signaling Tone lost.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Signaling Tone lost.\n"); amps_rx_signaling_tone(amps, 0, 0.0); } } else @@ -918,7 +919,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double __at /* Reset SAT detection states, so ongoing tone will be detected again. */ static void sat_reset(amps_t *amps, const char *reason) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "SAT detector reset: %s.\n", reason); + LOGP_CHAN(DDSP, LOGL_DEBUG, "SAT detector reset: %s.\n", reason); amps->sat_detected = 0; amps->sat_detect_count = 0; amps->sig_detected = 0; @@ -935,28 +936,28 @@ void amps_set_dsp_mode(amps_t *amps, enum dsp_mode mode, int frame_length) if (mode == DSP_MODE_FRAME_RX_FRAME_TX) { /* reset SAT detection */ sat_reset(amps, "Change to FOCC"); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Change mode to FOCC\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Change mode to FOCC\n"); amps->tx_focc_debugged = 0; } if (amps->dsp_mode == DSP_MODE_FRAME_RX_FRAME_TX && (mode == DSP_MODE_AUDIO_RX_AUDIO_TX || mode == DSP_MODE_AUDIO_RX_FRAME_TX || mode == DSP_MODE_AUDIO_RX_SILENCE_TX)) { /* reset SAT detection */ sat_reset(amps, "Change from FOCC to FVC"); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Change mode from FOCC to FVC\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Change mode from FOCC to FVC\n"); } if (amps->dsp_mode == DSP_MODE_OFF && (mode == DSP_MODE_AUDIO_RX_AUDIO_TX || mode == DSP_MODE_AUDIO_RX_FRAME_TX || mode == DSP_MODE_AUDIO_RX_SILENCE_TX)) { /* reset SAT detection */ sat_reset(amps, "Enable FVC"); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Change mode from OFF to FVC\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Change mode from OFF to FVC\n"); } if (mode == DSP_MODE_OFF) { /* reset SAT detection */ sat_reset(amps, "Disable FVC"); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Change mode from FVC to OFF\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Change mode from FVC to OFF\n"); } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Reset FSK frame transmitter, due to setting dsp mode.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Reset FSK frame transmitter, due to setting dsp mode.\n"); amps->dsp_mode = mode; if (frame_length) diff --git a/src/amps/esn.c b/src/amps/esn.c index 462ad74..5f3cbab 100644 --- a/src/amps/esn.c +++ b/src/amps/esn.c @@ -22,10 +22,10 @@ #include <string.h> #include <pthread.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "amps.h" #include "esn.h" diff --git a/src/amps/frame.c b/src/amps/frame.c index e89f3d5..14bd856 100644 --- a/src/amps/frame.c +++ b/src/amps/frame.c @@ -27,7 +27,8 @@ #include <math.h> #include <inttypes.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" +#include "../libmobile/get_time.h" #include "amps.h" #include "dsp.h" #include "frame.h" @@ -2719,7 +2720,7 @@ static uint64_t amps_encode_word(frame_t *frame, struct def_word *w, int debug) sum_bits += w->ie[i].bits; if (debug) - PDEBUG(DFRAME, DEBUG_INFO, "Transmit: %s\n", w->name); + LOGP(DFRAME, LOGL_INFO, "Transmit: %s\n", w->name); word = 0; for (i = 0; w->ie[i].name; i++) { bits = w->ie[i].bits; @@ -2730,9 +2731,9 @@ static uint64_t amps_encode_word(frame_t *frame, struct def_word *w, int debug) word = (word << bits) | (value & cut_bits[bits]); if (debug) { if (amps_ie_desc[w->ie[i].ie].decoder) - PDEBUG(DFRAME, DEBUG_DEBUG, " %s%s: %" PRIu64 " = %s (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].decoder(value), amps_ie_desc[w->ie[i].ie].desc); + LOGP(DFRAME, LOGL_DEBUG, " %s%s: %" PRIu64 " = %s (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].decoder(value), amps_ie_desc[w->ie[i].ie].desc); else - PDEBUG(DFRAME, DEBUG_DEBUG, " %s%s: %" PRIu64 " (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].desc); + LOGP(DFRAME, LOGL_DEBUG, " %s%s: %" PRIu64 " (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].desc); } /* show result for 3 IEs of table 4 */ if (w->ie[i].ie == AMPS_IE_LOCAL_MSG_TYPE || w->ie[i].ie == AMPS_IE_ORDQ || w->ie[i].ie == AMPS_IE_ORDER) @@ -2740,7 +2741,7 @@ static uint64_t amps_encode_word(frame_t *frame, struct def_word *w, int debug) if (t4 == 3) { t4 = 0; if (debug) - PDEBUG(DFRAME, DEBUG_DEBUG, " %s--> %s\n", spaces, amps_table4_name(frame->ie[AMPS_IE_LOCAL_MSG_TYPE], frame->ie[AMPS_IE_ORDQ], frame->ie[AMPS_IE_ORDER])); + LOGP(DFRAME, LOGL_DEBUG, " %s--> %s\n", spaces, amps_table4_name(frame->ie[AMPS_IE_LOCAL_MSG_TYPE], frame->ie[AMPS_IE_ORDQ], frame->ie[AMPS_IE_ORDER])); } } @@ -3070,22 +3071,22 @@ static frame_t *amps_decode_word(uint64_t word, struct def_word *w) for (i = 0; w->ie[i].name; i++) bits_left += w->ie[i].bits; - PDEBUG(DFRAME, DEBUG_INFO, "Received: %s\n", w->name); + LOGP(DFRAME, LOGL_INFO, "Received: %s\n", w->name); for (i = 0; w->ie[i].name; i++) { bits = w->ie[i].bits; bits_left -= bits; value = (word >> bits_left) & cut_bits[bits]; frame.ie[w->ie[i].ie] = value; if (amps_ie_desc[w->ie[i].ie].decoder) - PDEBUG(DFRAME, DEBUG_DEBUG, " %s%s: %" PRIu64 " = %s (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].decoder(value), amps_ie_desc[w->ie[i].ie].desc); + LOGP(DFRAME, LOGL_DEBUG, " %s%s: %" PRIu64 " = %s (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].decoder(value), amps_ie_desc[w->ie[i].ie].desc); else - PDEBUG(DFRAME, DEBUG_DEBUG, " %s%s: %" PRIu64 " (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].desc); + LOGP(DFRAME, LOGL_DEBUG, " %s%s: %" PRIu64 " (%s)\n", spaces + strlen(w->ie[i].name), w->ie[i].name, value, amps_ie_desc[w->ie[i].ie].desc); /* show result for 3 IEs of table 4 */ if (w->ie[i].ie == AMPS_IE_LOCAL_MSG_TYPE || w->ie[i].ie == AMPS_IE_ORDQ || w->ie[i].ie == AMPS_IE_ORDER) t4++; if (t4 == 3) { t4 = 0; - PDEBUG(DFRAME, DEBUG_DEBUG, " %s--> %s\n", spaces, amps_table4_name(frame.ie[AMPS_IE_LOCAL_MSG_TYPE], frame.ie[AMPS_IE_ORDQ], frame.ie[AMPS_IE_ORDER])); + LOGP(DFRAME, LOGL_DEBUG, " %s--> %s\n", spaces, amps_table4_name(frame.ie[AMPS_IE_LOCAL_MSG_TYPE], frame.ie[AMPS_IE_ORDQ], frame.ie[AMPS_IE_ORDER])); } } @@ -3103,7 +3104,7 @@ static void amps_decode_word_focc(amps_t *amps, uint64_t word) /* control message */ if (t1t2 != 3) { - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "Received Mobile Station Control Message (T1T2 = %d)\n", t1t2); + LOGP_CHAN(DFRAME, LOGL_INFO, "Received Mobile Station Control Message (T1T2 = %d)\n", t1t2); if (t1t2 == 1) amps->rx_focc_word_count = 1; if (t1t2 == 0 || t1t2 == 1) { @@ -3120,7 +3121,7 @@ static void amps_decode_word_focc(amps_t *amps, uint64_t word) w = &word2_extended_address_word_b; goto decode; } - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "Decoding of more than 2 Control messages not supported\n"); + LOGP_CHAN(DFRAME, LOGL_INFO, "Decoding of more than 2 Control messages not supported\n"); } return; } @@ -3188,14 +3189,14 @@ static void amps_decode_word_focc(amps_t *amps, uint64_t word) decode: if (!w) { - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "Received Illegal Overhead Message\n"); + LOGP_CHAN(DFRAME, LOGL_INFO, "Received Illegal Overhead Message\n"); return; } frame = amps_decode_word(word, w); /* show control filler delay */ if (amps->sender.loopback && ohd == 1) - PDEBUG_CHAN(DDSP, DEBUG_NOTICE, "Round trip delay is %.3f seconds\n", amps->when_received - amps->when_transmitted[frame->ie[AMPS_IE_1111]]); + LOGP_CHAN(DDSP, LOGL_NOTICE, "Round trip delay is %.3f seconds\n", amps->when_received - amps->when_transmitted[frame->ie[AMPS_IE_1111]]); } /* get word from data bits and call decoder function @@ -3214,24 +3215,24 @@ static int amps_decode_word_recc(amps_t *amps, uint64_t word, int first) amps->rx_recc_word_count = 0; amps->rx_recc_nawc = nawc; if (f == 0) { - PDEBUG_CHAN(DFRAME, DEBUG_NOTICE, "Received first word, but F bit is not set.\n"); + LOGP_CHAN(DFRAME, LOGL_NOTICE, "Received first word, but F bit is not set.\n"); return 0; } } else { if (f == 1) { - PDEBUG_CHAN(DFRAME, DEBUG_NOTICE, "Received additional word, but F bit is set.\n"); + LOGP_CHAN(DFRAME, LOGL_NOTICE, "Received additional word, but F bit is set.\n"); return 0; } amps->rx_recc_nawc--; if (amps->rx_recc_nawc != nawc) { - PDEBUG_CHAN(DFRAME, DEBUG_NOTICE, "Received additional word with NAWC mismatch!\n"); + LOGP_CHAN(DFRAME, LOGL_NOTICE, "Received additional word with NAWC mismatch!\n"); } } msg_count = amps->rx_recc_word_count; if (msg_count == 8) { - PDEBUG_CHAN(DFRAME, DEBUG_NOTICE, "Received too many words.\n"); + LOGP_CHAN(DFRAME, LOGL_NOTICE, "Received too many words.\n"); return 0; } @@ -3268,7 +3269,7 @@ static int amps_decode_word_recc(amps_t *amps, uint64_t word, int first) if (!w) { - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "Received Illegal RECC Message\n"); + LOGP_CHAN(DFRAME, LOGL_INFO, "Received Illegal RECC Message\n"); goto done; } @@ -3333,7 +3334,7 @@ static int amps_decode_word_recc(amps_t *amps, uint64_t word, int first) amps->rx_recc_dialing[31] = digit2number[frame->ie[AMPS_IE_DIGIT_32]]; } - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "expecting %d more word(s) to come\n", amps->rx_recc_nawc); + LOGP_CHAN(DFRAME, LOGL_INFO, "expecting %d more word(s) to come\n", amps->rx_recc_nawc); if (msg_count >= 3 && amps->rx_recc_nawc == 0) { /* if no digit messages are present, send NULL as dial string (paging reply) */ @@ -3400,16 +3401,16 @@ static void amps_encode_focc_bits(uint64_t word_a, uint64_t word_b, char *bits) bits[k] = '\0'; #ifdef BIT_DEBUGGING - if (debuglevel == DEBUG_DEBUG) { + if (loglevel == LOGL_DEBUG) { char text[64]; strncpy(text, bits, 23); text[23] = '\0'; - PDEBUG(DFRAME, DEBUG_INFO, "TX FOCC: %s\n", text); + LOGP(DFRAME, LOGL_INFO, "TX FOCC: %s\n", text); for (i = 0; i < 10; i++) { strncpy(text, bits + 23 + i * 44, 44); text[44] = '\0'; - PDEBUG(DFRAME, DEBUG_DEBUG, " word %c - %s\n", (i & 1) ? 'b' : 'a', text); + LOGP(DFRAME, LOGL_DEBUG, " word %c - %s\n", (i & 1) ? 'b' : 'a', text); } } #endif @@ -3440,8 +3441,8 @@ static void amps_encode_fvc_bits(uint64_t word_a, char *bits) bits[k] = '\0'; #ifdef BIT_DEBUGGING - if (debuglevel == DEBUG_DEBUG) { - PDEBUG(DFRAME, DEBUG_INFO, "TX FVC: %s\n", bits); + if (loglevel == LOGL_DEBUG) { + LOGP(DFRAME, LOGL_INFO, "TX FVC: %s\n", bits); } #endif } @@ -3511,7 +3512,7 @@ int amps_encode_frame_focc(amps_t *amps, char *bits) if (++amps->tx_focc_frame_count >= amps->si.overhead_repeat) amps->tx_focc_frame_count = 0; if (debug) - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "Subsequent system/filler frames are not show, to prevent flooding the output.\n"); + LOGP_CHAN(DFRAME, LOGL_INFO, "Subsequent system/filler frames are not show, to prevent flooding the output.\n"); amps->tx_focc_debugged = 1; send: @@ -3626,17 +3627,17 @@ static void amps_decode_bits_focc(amps_t *amps, const char *bits) else idle = 0; - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "RX FOCC: B/I = %s\n", (idle) ? "idle" : "busy"); - if (debuglevel == DEBUG_DEBUG) { + LOGP_CHAN(DFRAME, LOGL_INFO, "RX FOCC: B/I = %s\n", (idle) ? "idle" : "busy"); + if (loglevel == LOGL_DEBUG) { char text[64]; for (i = 0; i < 10; i++) { strncpy(text, bits + i * 44, 44); text[44] = '\0'; if ((i & 1) == 0) - PDEBUG_CHAN(DFRAME, DEBUG_DEBUG, " word a - %s%s\n", text, (crc_a_ok[i >> 1]) ? " ok" : " BAD CRC!"); + LOGP_CHAN(DFRAME, LOGL_DEBUG, " word a - %s%s\n", text, (crc_a_ok[i >> 1]) ? " ok" : " BAD CRC!"); else - PDEBUG_CHAN(DFRAME, DEBUG_DEBUG, " word b - %s%s\n", text, (crc_b_ok[i >> 1]) ? " ok" : " BAD CRC!"); + LOGP_CHAN(DFRAME, LOGL_DEBUG, " word b - %s%s\n", text, (crc_b_ok[i >> 1]) ? " ok" : " BAD CRC!"); } } @@ -3712,7 +3713,7 @@ static int amps_decode_bits_recc(amps_t *amps, const char *bits, int first) crc_ok++; } if (crc_ok) { - PDEBUG_CHAN(DFRAME, DEBUG_NOTICE, "Seems we RX FOCC frame due to loopback, ignoring!\n"); + LOGP_CHAN(DFRAME, LOGL_NOTICE, "Seems we RX FOCC frame due to loopback, ignoring!\n"); return 0; } bits_ -= 221; @@ -3724,24 +3725,24 @@ static int amps_decode_bits_recc(amps_t *amps, const char *bits, int first) } if (first) { - if (debuglevel == DEBUG_DEBUG || crc_ok_count > 0) { - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "RX RECC: DCC=%d (%d of 5 CRCs are ok)\n", dcc, crc_ok_count); + if (loglevel == LOGL_DEBUG || crc_ok_count > 0) { + LOGP_CHAN(DFRAME, LOGL_INFO, "RX RECC: DCC=%d (%d of 5 CRCs are ok)\n", dcc, crc_ok_count); if (dcc != amps->si.dcc) { - PDEBUG(DFRAME, DEBUG_INFO, "received DCC=%d mismatches the base station's DCC=%d\n", dcc, amps->si.dcc); + LOGP(DFRAME, LOGL_INFO, "received DCC=%d mismatches the base station's DCC=%d\n", dcc, amps->si.dcc); return 0; } } } else { - if (debuglevel == DEBUG_DEBUG || crc_ok_count > 0) - PDEBUG_CHAN(DFRAME, DEBUG_INFO, "RX RECC: (%d of 5 CRCs are ok)\n", crc_ok_count); + if (loglevel == LOGL_DEBUG || crc_ok_count > 0) + LOGP_CHAN(DFRAME, LOGL_INFO, "RX RECC: (%d of 5 CRCs are ok)\n", crc_ok_count); } - if (debuglevel == DEBUG_DEBUG) { + if (loglevel == LOGL_DEBUG) { char text[64]; for (i = 0; i < 5; i++) { strncpy(text, bits + i * 48, 48); text[48] = '\0'; - PDEBUG_CHAN(DFRAME, DEBUG_DEBUG, " word - %s%s\n", text, (crc_a_ok[i]) ? " ok" : " BAD CRC!"); + LOGP_CHAN(DFRAME, LOGL_DEBUG, " word - %s%s\n", text, (crc_a_ok[i]) ? " ok" : " BAD CRC!"); } } @@ -3756,7 +3757,7 @@ int amps_decode_frame(amps_t *amps, const char *bits, int count, double level, d /* not if additional words are received without sync */ if (count != 240) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RX Level: %.0f%% Quality: %.0f%% Polarity: %s\n", level * 100.0, quality * 100.0, (negative) ? "NEGATIVE" : "POSITIVE"); + LOGP_CHAN(DDSP, LOGL_INFO, "RX Level: %.0f%% Quality: %.0f%% Polarity: %s\n", level * 100.0, quality * 100.0, (negative) ? "NEGATIVE" : "POSITIVE"); } if (count == 441) { amps_decode_bits_focc(amps, bits); @@ -3765,7 +3766,7 @@ int amps_decode_frame(amps_t *amps, const char *bits, int count, double level, d } else if (count == 240) { more = amps_decode_bits_recc(amps, bits, 0); } else { - PDEBUG_CHAN(DFRAME, DEBUG_ERROR, "Frame with unknown length = %d, please fix!\n", count); + LOGP_CHAN(DFRAME, LOGL_ERROR, "Frame with unknown length = %d, please fix!\n", count); } return more; diff --git a/src/amps/main_common.c b/src/amps/main_common.c index d7a5ed5..17bb41e 100644 --- a/src/amps/main_common.c +++ b/src/amps/main_common.c @@ -24,7 +24,7 @@ #include <errno.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../liboptions/options.h" #include "../libfm/fm.h" @@ -423,6 +423,7 @@ fail: amps_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/amps/transaction.c b/src/amps/transaction.c index f8a4aee..1abd403 100644 --- a/src/amps/transaction.c +++ b/src/amps/transaction.c @@ -21,7 +21,7 @@ #include <stdint.h> #include <stdlib.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" #include "amps.h" @@ -133,7 +133,7 @@ transaction_t *create_transaction(amps_t *amps, enum amps_trans_state state, uin const char *number = amps_min2number(trans->min1, trans->min2); int old_callref = trans->callref; amps_t *old_amps = trans->amps; - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s', deleting!\n", number); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s', deleting!\n", number); destroy_transaction(trans); if (old_amps) /* should be... */ amps_go_idle(old_amps); @@ -143,11 +143,11 @@ transaction_t *create_transaction(amps_t *amps, enum amps_trans_state state, uin trans = calloc(1, sizeof(*trans)); if (!trans) { - PDEBUG(DTRANS, DEBUG_ERROR, "No memory!\n"); + LOGP(DTRANS, LOGL_ERROR, "No memory!\n"); return NULL; } - timer_init(&trans->timer, transaction_timeout, trans); + osmo_timer_setup(&trans->timer, transaction_timeout, trans); trans_new_state(trans, state); trans->min1 = min1; @@ -159,7 +159,7 @@ transaction_t *create_transaction(amps_t *amps, enum amps_trans_state state, uin trans->chan = chan; const char *number = amps_min2number(trans->min1, trans->min2); - PDEBUG(DTRANS, DEBUG_INFO, "Created transaction for subscriber '%s'\n", number); + LOGP(DTRANS, LOGL_INFO, "Created transaction for subscriber '%s'\n", number); link_transaction(trans, amps); @@ -172,9 +172,9 @@ void destroy_transaction(transaction_t *trans) unlink_transaction(trans); const char *number = amps_min2number(trans->min1, trans->min2); - PDEBUG(DTRANS, DEBUG_INFO, "Destroying transaction for subscriber '%s'\n", number); + LOGP(DTRANS, LOGL_INFO, "Destroying transaction for subscriber '%s'\n", number); - timer_exit(&trans->timer); + osmo_timer_del(&trans->timer); trans_new_state(trans, 0); @@ -187,7 +187,7 @@ void link_transaction(transaction_t *trans, amps_t *amps) transaction_t **transp; /* attach to end of list, so first transaction is served first */ - PDEBUG(DTRANS, DEBUG_DEBUG, "Linking transaction %p to amps %p\n", trans, amps); + LOGP(DTRANS, LOGL_DEBUG, "Linking transaction %p to amps %p\n", trans, amps); trans->amps = amps; trans->next = NULL; transp = &s->trans_list; @@ -203,12 +203,12 @@ void unlink_transaction(transaction_t *trans) transaction_t **transp; /* unlink */ - PDEBUG(DTRANS, DEBUG_DEBUG, "Unlinking transaction %p from amps %p\n", trans, trans->amps); + LOGP(DTRANS, LOGL_DEBUG, "Unlinking transaction %p from amps %p\n", trans, trans->amps); transp = &trans->amps->trans_list; while (*transp && *transp != trans) transp = &((*transp)->next); if (!(*transp)) { - PDEBUG(DTRANS, DEBUG_ERROR, "Transaction not in list, please fix!!\n"); + LOGP(DTRANS, LOGL_ERROR, "Transaction not in list, please fix!!\n"); abort(); } *transp = trans->next; @@ -224,7 +224,7 @@ transaction_t *search_transaction_number(amps_t *amps, uint32_t min1, uint16_t m if (trans->min1 == min1 && trans->min2 == min2) { const char *number = amps_min2number(trans->min1, trans->min2); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", number); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", number); return trans; } trans = trans->next; @@ -243,7 +243,7 @@ transaction_t *search_transaction_callref(amps_t *amps, int callref) while (trans) { if (trans->callref == callref) { const char *number = amps_min2number(trans->min1, trans->min2); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", number); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", number); return trans; } trans = trans->next; @@ -254,7 +254,7 @@ transaction_t *search_transaction_callref(amps_t *amps, int callref) void trans_new_state(transaction_t *trans, int state) { - PDEBUG(DTRANS, DEBUG_INFO, "Transaction state %s -> %s\n", trans_state_name(trans->state), trans_state_name(state)); + LOGP(DTRANS, LOGL_INFO, "Transaction state %s -> %s\n", trans_state_name(trans->state), trans_state_name(state)); trans->state = state; amps_display_status(); } @@ -263,12 +263,12 @@ void amps_flush_other_transactions(amps_t *amps, transaction_t *trans) { /* flush after this very trans */ while (trans->next) { - PDEBUG(DTRANS, DEBUG_NOTICE, "Kicking other pending transaction\n"); + LOGP(DTRANS, LOGL_NOTICE, "Kicking other pending transaction\n"); destroy_transaction(trans->next); } /* flush before this very trans */ while (amps->trans_list != trans) { - PDEBUG(DTRANS, DEBUG_NOTICE, "Kicking other pending transaction\n"); + LOGP(DTRANS, LOGL_NOTICE, "Kicking other pending transaction\n"); destroy_transaction(amps->trans_list); } } diff --git a/src/amps/transaction.h b/src/amps/transaction.h index 33f8393..29da337 100644 --- a/src/amps/transaction.h +++ b/src/amps/transaction.h @@ -39,7 +39,7 @@ typedef struct transaction { char caller_id[33]; /* id of calling phone */ char dialing[33]; /* number dialed by the phone */ enum amps_trans_state state; /* state of transaction */ - struct timer timer; /* for varous timeouts */ + struct osmo_timer_list timer; /* for varous timeouts */ int sat_detected; /* state if we detected SAT */ int dtx; /* if set, DTX is used with this call */ } transaction_t; diff --git a/src/anetz/Makefile.am b/src/anetz/Makefile.am index a9a6503..8a4e1f3 100644 --- a/src/anetz/Makefile.am +++ b/src/anetz/Makefile.am @@ -19,23 +19,21 @@ anetz_LDADD = \ $(COMMON_LA) \ libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/anetz/anetz.c b/src/anetz/anetz.c index d77484e..06e257b 100644 --- a/src/anetz/anetz.c +++ b/src/anetz/anetz.c @@ -25,17 +25,17 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "anetz.h" #include "dsp.h" /* Timers */ -#define PAGING_TO 30 /* Nach dieser Zeit ist der Operator genervt... */ -#define RELEASE_TO 3 /* Release time, so station keeps blocked for a while */ +#define PAGING_TO 30,0 /* Nach dieser Zeit ist der Operator genervt... */ +#define RELEASE_TO 3,0 /* Release time, so station keeps blocked for a while */ const char *anetz_state_name(enum anetz_state state) { @@ -77,7 +77,7 @@ static void anetz_new_state(anetz_t *anetz, enum anetz_state new_state) { if (anetz->state == new_state) return; - PDEBUG_CHAN(DANETZ, DEBUG_DEBUG, "State change: %s -> %s\n", anetz_state_name(anetz->state), anetz_state_name(new_state)); + LOGP_CHAN(DANETZ, LOGL_DEBUG, "State change: %s -> %s\n", anetz_state_name(anetz->state), anetz_state_name(new_state)); anetz->state = new_state; anetz_display_status(); } @@ -141,7 +141,7 @@ static double *anetz_nummer2freq(const char *nummer) /* get decade */ dekade = anetz_gruppenkennziffer[*nummer - '0'].dekade; - PDEBUG(DANETZ, DEBUG_DEBUG, "Dekaden: %d %d %d %d\n", dekade[0], dekade[1], dekade[2], dekade[3]); + LOGP(DANETZ, LOGL_DEBUG, "Dekaden: %d %d %d %d\n", dekade[0], dekade[1], dekade[2], dekade[3]); nummer++; /* get 4 frequencies out of decades */ @@ -161,7 +161,7 @@ static double *anetz_nummer2freq(const char *nummer) } } - PDEBUG(DANETZ, DEBUG_DEBUG, "Frequencies: F%d=%.1f F%d=%.1f F%d=%.1f F%d=%.1f\n", f[0], freq[0], f[1], freq[1], f[2], freq[2], f[3], freq[3]); + LOGP(DANETZ, LOGL_DEBUG, "Frequencies: F%d=%.1f F%d=%.1f F%d=%.1f F%d=%.1f\n", f[0], freq[0], f[1], freq[1], f[2], freq[2], f[3], freq[3]); return freq; } @@ -196,40 +196,40 @@ int anetz_create(const char *kanal, const char *device, int use_sdr, int sampler int rc; if (atoi(kanal) < 30 || atoi(kanal) > 63) { - PDEBUG(DANETZ, DEBUG_ERROR, "Channel ('Kanal') number %s invalid.\n", kanal); + LOGP(DANETZ, LOGL_ERROR, "Channel ('Kanal') number %s invalid.\n", kanal); return -EINVAL; } anetz = calloc(1, sizeof(anetz_t)); if (!anetz) { - PDEBUG(DANETZ, DEBUG_ERROR, "No memory!\n"); + LOGP(DANETZ, LOGL_ERROR, "No memory!\n"); return -EIO; } anetz->operator = operator; - PDEBUG(DANETZ, DEBUG_DEBUG, "Creating 'A-Netz' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DANETZ, LOGL_DEBUG, "Creating 'A-Netz' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&anetz->sender, kanal, anetz_kanal2freq(atoi(kanal), 0), anetz_kanal2freq(atoi(kanal), 1), device, use_sdr, samplerate, rx_gain, tx_gain, pre_emphasis, de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DANETZ, DEBUG_ERROR, "Failed to init 'Sender' processing!\n"); + LOGP(DANETZ, LOGL_ERROR, "Failed to init 'Sender' processing!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(anetz, page_gain, page_sequence, squelch_db); if (rc < 0) { - PDEBUG(DANETZ, DEBUG_ERROR, "Failed to init signal processing!\n"); + LOGP(DANETZ, LOGL_ERROR, "Failed to init signal processing!\n"); goto error; } - timer_init(&anetz->timer, anetz_timeout, anetz); + osmo_timer_setup(&anetz->timer, anetz_timeout, anetz); /* go into idle state */ anetz_go_idle(anetz); - PDEBUG(DANETZ, DEBUG_NOTICE, "Created 'Kanal' #%s\n", kanal); + LOGP(DANETZ, LOGL_NOTICE, "Created 'Kanal' #%s\n", kanal); return 0; @@ -244,9 +244,9 @@ void anetz_destroy(sender_t *sender) { anetz_t *anetz = (anetz_t *) sender; - PDEBUG(DANETZ, DEBUG_DEBUG, "Destroying 'A-Netz' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DANETZ, LOGL_DEBUG, "Destroying 'A-Netz' instance for 'Kanal' = %s.\n", sender->kanal); - timer_exit(&anetz->timer); + osmo_timer_del(&anetz->timer); dsp_cleanup_sender(anetz); sender_destroy(&anetz->sender); free(sender); @@ -255,9 +255,9 @@ void anetz_destroy(sender_t *sender) /* Abort connection towards mobile station by sending idle tone. */ static void anetz_go_idle(anetz_t *anetz) { - timer_stop(&anetz->timer); + osmo_timer_del(&anetz->timer); - PDEBUG(DANETZ, DEBUG_INFO, "Entering IDLE state on channel %s, sending 2280 Hz tone.\n", anetz->sender.kanal); + LOGP(DANETZ, LOGL_INFO, "Entering IDLE state on channel %s, sending 2280 Hz tone.\n", anetz->sender.kanal); anetz->station_id[0] = '\0'; /* remove station ID before state change, so status is shown correctly */ anetz_new_state(anetz, ANETZ_FREI); /* also reset detector, so if there is a new call it is answered */ @@ -267,31 +267,31 @@ static void anetz_go_idle(anetz_t *anetz) /* Release connection towards mobile station by sending idle tone for a while. */ static void anetz_release(anetz_t *anetz) { - timer_stop(&anetz->timer); + osmo_timer_del(&anetz->timer); - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "Sending 2280 Hz release tone.\n"); + LOGP_CHAN(DANETZ, LOGL_INFO, "Sending 2280 Hz release tone.\n"); anetz->station_id[0] = '\0'; /* remove station ID before state change, so status is shown correctly */ anetz_new_state(anetz, ANETZ_AUSLOESEN); anetz_set_dsp_mode(anetz, DSP_MODE_TONE, 0); - timer_start(&anetz->timer, RELEASE_TO); + osmo_timer_schedule(&anetz->timer, RELEASE_TO); } /* Enter paging state and transmit 4 paging tones. */ static void anetz_page(anetz_t *anetz, const char *dial_string, double *freq) { - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "Entering paging state, sending 'Selektivruf' to '%s'.\n", dial_string); + LOGP_CHAN(DANETZ, LOGL_INFO, "Entering paging state, sending 'Selektivruf' to '%s'.\n", dial_string); strcpy(anetz->station_id, dial_string); /* set station ID before state change, so status is shown correctly */ anetz_new_state(anetz, ANETZ_ANRUF); anetz_set_dsp_mode(anetz, DSP_MODE_PAGING, 0); dsp_set_paging(anetz, freq); - timer_start(&anetz->timer, PAGING_TO); + osmo_timer_schedule(&anetz->timer, PAGING_TO); } /* Loss of signal was detected, release active call. */ void anetz_loss_indication(anetz_t *anetz, double loss_time) { if (anetz->state == ANETZ_GESPRAECH) { - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Detected loss of signal after %.1f seconds, releasing.\n", loss_time); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Detected loss of signal after %.1f seconds, releasing.\n", loss_time); anetz_release(anetz); call_up_release(anetz->callref, CAUSE_TEMPFAIL); anetz->callref = 0; @@ -302,9 +302,9 @@ void anetz_loss_indication(anetz_t *anetz, double loss_time) void anetz_receive_tone(anetz_t *anetz, int tone) { if (tone >= 0) - PDEBUG_CHAN(DANETZ, DEBUG_DEBUG, "Received contiuous %d Hz tone.\n", (tone) ? 1750 : 2280); + LOGP_CHAN(DANETZ, LOGL_DEBUG, "Received contiuous %d Hz tone.\n", (tone) ? 1750 : 2280); else - PDEBUG_CHAN(DANETZ, DEBUG_DEBUG, "Continuous tone is gone.\n"); + LOGP_CHAN(DANETZ, LOGL_DEBUG, "Continuous tone is gone.\n"); /* skip any handling in loopback mode */ if (anetz->sender.loopback) @@ -318,7 +318,7 @@ void anetz_receive_tone(anetz_t *anetz, int tone) case ANETZ_FREI: /* initiate call on calling tone */ if (tone == 1) { - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "Received 1750 Hz calling signal from mobile station, removing idle signal.\n"); + LOGP_CHAN(DANETZ, LOGL_INFO, "Received 1750 Hz calling signal from mobile station, removing idle signal.\n"); strcpy(anetz->station_id, "unknown"); /* set station ID before state change, so status is shown correctly */ anetz_new_state(anetz, ANETZ_GESPRAECH); @@ -330,17 +330,17 @@ void anetz_receive_tone(anetz_t *anetz, int tone) /* throughconnect speech when calling/answer tone is gone */ if (tone != 1) { if (!anetz->callref) { - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "1750 Hz signal from mobile station is gone, setup call.\n"); + LOGP_CHAN(DANETZ, LOGL_INFO, "1750 Hz signal from mobile station is gone, setup call.\n"); anetz->callref = call_up_setup(NULL, anetz->operator, OSMO_CC_NETWORK_ANETZ_NONE, ""); } else { - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "1750 Hz signal from mobile station is gone, answer call.\n"); + LOGP_CHAN(DANETZ, LOGL_INFO, "1750 Hz signal from mobile station is gone, answer call.\n"); call_up_answer(anetz->callref, anetz->station_id); } anetz_set_dsp_mode(anetz, DSP_MODE_AUDIO, 0); } /* release call */ if (tone == 1) { - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "Received 1750 Hz release signal from mobile station, sending release tone.\n"); + LOGP_CHAN(DANETZ, LOGL_INFO, "Received 1750 Hz release signal from mobile station, sending release tone.\n"); anetz_release(anetz); call_up_release(anetz->callref, CAUSE_NORMAL); anetz->callref = 0; @@ -350,8 +350,8 @@ void anetz_receive_tone(anetz_t *anetz, int tone) case ANETZ_ANRUF: /* answer call on answer tone */ if (tone == 1) { - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "Received 1750 Hz answer signal from mobile station, removing paging tones.\n"); - timer_stop(&anetz->timer); + LOGP_CHAN(DANETZ, LOGL_INFO, "Received 1750 Hz answer signal from mobile station, removing paging tones.\n"); + osmo_timer_del(&anetz->timer); anetz_new_state(anetz, ANETZ_GESPRAECH); anetz_set_dsp_mode(anetz, DSP_MODE_SILENCE, 0); break; @@ -368,7 +368,7 @@ static void anetz_timeout(void *data) switch (anetz->state) { case ANETZ_ANRUF: - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Timeout while waiting for answer, releasing.\n"); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Timeout while waiting for answer, releasing.\n"); anetz_go_idle(anetz); call_up_release(anetz->callref, CAUSE_NOANSWER); anetz->callref = 0; @@ -391,8 +391,8 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 1. determine paging frequencies */ freq = anetz_nummer2freq(dialing); if (!freq) { - PDEBUG(DANETZ, DEBUG_NOTICE, "Number invalid: %s\n", anetz_nummer2freq_error); - PDEBUG(DANETZ, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing); + LOGP(DANETZ, LOGL_NOTICE, "Number invalid: %s\n", anetz_nummer2freq_error); + LOGP(DANETZ, LOGL_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing); return -CAUSE_INVALNUMBER; } @@ -405,7 +405,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (sender) { - PDEBUG(DANETZ, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DANETZ, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } @@ -416,13 +416,13 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (!sender) { - PDEBUG(DANETZ, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DANETZ, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG_CHAN(DANETZ, DEBUG_INFO, "Call to mobile station, paging with tones: %.1f %.1f %.1f %.1f\n", freq[0], freq[1], freq[2], freq[3]); + LOGP_CHAN(DANETZ, LOGL_INFO, "Call to mobile station, paging with tones: %.1f %.1f %.1f %.1f\n", freq[0], freq[1], freq[2], freq[3]); if (anetz->page_sequence) - PDEBUG(DANETZ, DEBUG_NOTICE, "Sending paging tones in sequence.\n"); + LOGP(DANETZ, LOGL_NOTICE, "Sending paging tones in sequence.\n"); /* 4. trying to page mobile station */ anetz->callref = callref; @@ -446,7 +446,7 @@ void call_down_disconnect(int callref, int cause) sender_t *sender; anetz_t *anetz; - PDEBUG(DANETZ, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DANETZ, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { anetz = (anetz_t *) sender; @@ -454,7 +454,7 @@ void call_down_disconnect(int callref, int cause) break; } if (!sender) { - PDEBUG(DANETZ, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DANETZ, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -464,7 +464,7 @@ void call_down_disconnect(int callref, int cause) return; switch (anetz->state) { case ANETZ_ANRUF: - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Outgoing disconnect, during alerting, going idle!\n"); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Outgoing disconnect, during alerting, going idle!\n"); anetz_go_idle(anetz); break; default: @@ -483,7 +483,7 @@ void call_down_release(int callref, __attribute__((unused)) int cause) sender_t *sender; anetz_t *anetz; - PDEBUG(DANETZ, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DANETZ, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { anetz = (anetz_t *) sender; @@ -491,7 +491,7 @@ void call_down_release(int callref, __attribute__((unused)) int cause) break; } if (!sender) { - PDEBUG(DANETZ, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DANETZ, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -500,11 +500,11 @@ void call_down_release(int callref, __attribute__((unused)) int cause) switch (anetz->state) { case ANETZ_GESPRAECH: - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Outgoing release, during call, sending release tone!\n"); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Outgoing release, during call, sending release tone!\n"); anetz_release(anetz); break; case ANETZ_ANRUF: - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Outgoing release, during alerting, going idle!\n"); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Outgoing release, during alerting, going idle!\n"); anetz_go_idle(anetz); break; default: diff --git a/src/anetz/anetz.h b/src/anetz/anetz.h index fc04d95..fcb7a61 100644 --- a/src/anetz/anetz.h +++ b/src/anetz/anetz.h @@ -24,7 +24,7 @@ typedef struct anetz { enum anetz_state state; /* current sender's state */ int callref; /* call reference */ char station_id[8]; /* current station ID */ - struct timer timer; + struct osmo_timer_list timer; /* display measurements */ dispmeasparam_t *dmp_tone_level; diff --git a/src/anetz/dsp.c b/src/anetz/dsp.c index e9a4dbb..61b785f 100644 --- a/src/anetz/dsp.c +++ b/src/anetz/dsp.c @@ -26,8 +26,8 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "anetz.h" #include "dsp.h" @@ -68,7 +68,7 @@ void dsp_init(void) int i; double s; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine tables.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine tables.\n"); for (i = 0; i < 65536; i++) { s = sin((double)i / 65536.0 * 2.0 * PI); dsp_sine_tone[i] = s * TX_PEAK_TONE; @@ -83,7 +83,7 @@ int dsp_init_sender(anetz_t *anetz, double page_gain, int page_sequence, double int i; double tone; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for 'Sender'.\n"); /* init squelch */ squelch_init(&anetz->squelch, anetz->sender.kanal, squelch_db, MUTE_TIME, LOSS_TIME); @@ -95,10 +95,10 @@ int dsp_init_sender(anetz_t *anetz, double page_gain, int page_sequence, double anetz->page_sequence = page_sequence; anetz->samples_per_chunk = anetz->sender.samplerate * CHUNK_DURATION; - PDEBUG(DDSP, DEBUG_DEBUG, "Using %d samples per filter chunk duration.\n", anetz->samples_per_chunk); + LOGP(DDSP, LOGL_DEBUG, "Using %d samples per filter chunk duration.\n", anetz->samples_per_chunk); spl = calloc(anetz->samples_per_chunk, sizeof(sample_t)); if (!spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP(DDSP, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } anetz->fsk_filter_spl = spl; @@ -119,7 +119,7 @@ int dsp_init_sender(anetz_t *anetz, double page_gain, int page_sequence, double /* Cleanup transceiver instance. */ void dsp_cleanup_sender(anetz_t *anetz) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for 'Sender'.\n"); if (anetz->fsk_filter_spl) { free(anetz->fsk_filter_spl); @@ -133,7 +133,7 @@ static void fsk_receive_tone(anetz_t *anetz, int tone, int goodtone, double leve /* lost tone because it is not good anymore or has changed */ if (!goodtone || tone != anetz->tone_detected) { if (anetz->tone_count >= TONE_DETECT_TH) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Lost %.0f Hz tone after %.0f ms.\n", fsk_tones[anetz->tone_detected], 1000.0 * CHUNK_DURATION * anetz->tone_count); + LOGP_CHAN(DDSP, LOGL_INFO, "Lost %.0f Hz tone after %.0f ms.\n", fsk_tones[anetz->tone_detected], 1000.0 * CHUNK_DURATION * anetz->tone_count); anetz_receive_tone(anetz, -1); } if (goodtone) @@ -148,7 +148,7 @@ static void fsk_receive_tone(anetz_t *anetz, int tone, int goodtone, double leve anetz->tone_count++; if (anetz->tone_count == TONE_DETECT_TH) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Detecting continuous %.0f Hz tone. (level = %.0f%%, quality =%.0f%%)\n", fsk_tones[anetz->tone_detected], level * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "Detecting continuous %.0f Hz tone. (level = %.0f%%, quality =%.0f%%)\n", fsk_tones[anetz->tone_detected], level * 100.0, quality * 100.0); anetz_receive_tone(anetz, anetz->tone_detected); } } @@ -171,7 +171,7 @@ static void fsk_decode_chunk(anetz_t *anetz, sample_t *spl, int max) display_measurements_update(anetz->dmp_tone_level, level * 100.0, 0.0); display_measurements_update(anetz->dmp_tone_quality, quality[1] * 100.0, 0.0); if ((level > TONE_THRESHOLD && quality[1] > QUAL_THRESHOLD) || anetz->sender.loopback) - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Tone %.0f: Level=%3.0f%% Quality=%3.0f%%\n", fsk_tones[1], level * 100.0, quality[1] * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "Tone %.0f: Level=%3.0f%% Quality=%3.0f%%\n", fsk_tones[1], level * 100.0, quality[1] * 100.0); /* adjust level, so we get peak of sine curve */ /* indicate detected tone */ @@ -403,7 +403,7 @@ const char *anetz_dsp_mode_name(enum dsp_mode mode) void anetz_set_dsp_mode(anetz_t *anetz, enum dsp_mode mode, int detect_reset) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", anetz_dsp_mode_name(anetz->dsp_mode), anetz_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", anetz_dsp_mode_name(anetz->dsp_mode), anetz_dsp_mode_name(mode)); anetz->dsp_mode = mode; /* reset sequence paging */ anetz->paging_tone = 0; diff --git a/src/anetz/main.c b/src/anetz/main.c index cd6f015..8286f71 100644 --- a/src/anetz/main.c +++ b/src/anetz/main.c @@ -25,8 +25,8 @@ #include <math.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "../liboptions/options.h" #include "../libfm/fm.h" @@ -198,6 +198,7 @@ fail: anetz_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/bnetz/Makefile.am b/src/bnetz/Makefile.am index 7f98e09..8171a01 100644 --- a/src/bnetz/Makefile.am +++ b/src/bnetz/Makefile.am @@ -16,14 +16,10 @@ bnetz_LDADD = \ $(COMMON_LA) \ ../anetz/libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfsk/libfsk.a \ @@ -31,8 +27,10 @@ bnetz_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm bnetz_dialer_SOURCES = \ @@ -41,12 +39,14 @@ bnetz_dialer_SOURCES = \ bnetz_dialer_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libfsk/libfsk.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ $(ALSA_LIBS) -lm diff --git a/src/bnetz/bnetz.c b/src/bnetz/bnetz.c index 5eb1410..1cd758f 100644 --- a/src/bnetz/bnetz.c +++ b/src/bnetz/bnetz.c @@ -25,30 +25,31 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include "../libmobile/get_time.h" +#include <osmocom/cc/message.h> #include "bnetz.h" #include "telegramm.h" #include "dsp.h" /* mobile originating call */ -#define CARRIER_TO 0.08 /* 80 ms search for carrier */ -#define DIALING_TO 3.8 /* timeout after channel allocation "Kanalbelegung" (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.8) */ -#define DIALING_TO2 0.5 /* timeout while receiving digits */ +#define CARRIER_TO 0.080000 /* 80 ms search for carrier */ +#define DIALING_TO 3,800000 /* timeout after channel allocation "Kanalbelegung" (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.8) */ +#define DIALING_TO2 0,500000 /* timeout while receiving digits */ /* mobile terminating call */ -#define ALERTING_TO 60 /* timeout after 60 seconds alerting the MS (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.7) */ -#define PAGING_TO 2.1 /* 700..2100 ms timeout after paging "Selektivruf" (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.4.3) */ -#define PAGE_TRIES 2 /* two tries (see Clause 3.2.2.2.4.3) */ -#define SWITCH19_TIME 1.0 /* time to switch channel (radio should be tansmitting after that) */ -#define SWITCHBACK_TIME 0.1 /* time to wait until switching back (latency of sound device shall be lower) */ +#define ALERTING_TO 60,0 /* timeout after 60 seconds alerting the MS (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.7) */ +#define PAGING_TO 2,100000 /* 700..2100 ms timeout after paging "Selektivruf" (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.4.3) */ +#define PAGE_TRIES 2 /* two tries (see Clause 3.2.2.2.4.3) */ +#define SWITCH19_TIME 1,0 /* time to switch channel (radio should be tansmitting after that) */ +#define SWITCHBACK_TIME 0,100000 /* time to wait until switching back (latency of sound device shall be lower) */ -#define TRENN_COUNT 5 /* min. 720 ms release 'Trennsignal' (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.6) */ +#define TRENN_COUNT 5 /* min. 720 ms release 'Trennsignal' (according to FTZ 1727 Pfl 32 Clause 3.2.2.2.6) */ -#define METERING_DURATION 0.140 /* duration of metering pulse (according to FTZ 1727 Pfl 32 Clause 3.2.6.6.1) */ -#define METERING_START 1.0 /* start metering 1 second after call start */ +#define METERING_DURATION 0,140000 /* duration of metering pulse (according to FTZ 1727 Pfl 32 Clause 3.2.6.6.1) */ +#define METERING_START 1,0 /* start metering 1 second after call start */ const char *bnetz_state_name(enum bnetz_state state) { @@ -99,7 +100,7 @@ static void bnetz_new_state(bnetz_t *bnetz, enum bnetz_state new_state) { if (bnetz->state == new_state) return; - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "State change: %s -> %s\n", bnetz_state_name(bnetz->state), bnetz_state_name(new_state)); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "State change: %s -> %s\n", bnetz_state_name(bnetz->state), bnetz_state_name(new_state)); bnetz->state = new_state; bnetz_display_status(); } @@ -133,7 +134,7 @@ static void switch_channel_19(bnetz_t *bnetz, int on) fp = fopen(bnetz->paging_file, "w"); if (!fp) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Failed to open file '%s' to switch channel 19!\n", bnetz->paging_file); + LOGP(DBNETZ, LOGL_ERROR, "Failed to open file '%s' to switch channel 19!\n", bnetz->paging_file); return; } fprintf(fp, "%s\n", (on) ? bnetz->paging_on : bnetz->paging_off); @@ -162,22 +163,22 @@ int bnetz_create(const char *kanal, const char *device, int use_sdr, int sampler int rc; if (!(atoi(kanal) >= 1 && atoi(kanal) <= 39) && !(atoi(kanal) >= 50 && atoi(kanal) <= 86)) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Channel ('Kanal') number %s invalid.\n", kanal); + LOGP(DBNETZ, LOGL_ERROR, "Channel ('Kanal') number %s invalid.\n", kanal); return -EINVAL; } if (atoi(kanal) == 19) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Selected calling channel ('Rufkanal') number %s can't be used as traffic channel.\n", kanal); + LOGP(DBNETZ, LOGL_ERROR, "Selected calling channel ('Rufkanal') number %s can't be used as traffic channel.\n", kanal); return -EINVAL; } if (atoi(kanal) >= 38 && atoi(kanal) <= 39) - PDEBUG(DBNETZ, DEBUG_NOTICE, "Selected channel ('Kanal') number %s may not be supported by older B1-Network phones.\n", kanal); + LOGP(DBNETZ, LOGL_NOTICE, "Selected channel ('Kanal') number %s may not be supported by older B1-Network phones.\n", kanal); if (atoi(kanal) >= 50) - PDEBUG(DBNETZ, DEBUG_NOTICE, "Selected channel ('Kanal') number %s belongs to B2-Network and is not supported by B1 phones.\n", kanal); + LOGP(DBNETZ, LOGL_NOTICE, "Selected channel ('Kanal') number %s belongs to B2-Network and is not supported by B1 phones.\n", kanal); if ((gfs < 1 || gfs > 19)) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Given 'Gruppenfreisignal' %d invalid.\n", gfs); + LOGP(DBNETZ, LOGL_ERROR, "Given 'Gruppenfreisignal' %d invalid.\n", gfs); return -EINVAL; } @@ -199,7 +200,7 @@ int bnetz_create(const char *kanal, const char *device, int use_sdr, int sampler p = strchr(paging_file, '='); if (!p) { error_paging: - PDEBUG(DBNETZ, DEBUG_ERROR, "Given paging file (to switch to channel 19) is missing parameters. Use <file>=<on>:<off> format!\n"); + LOGP(DBNETZ, LOGL_ERROR, "Given paging file (to switch to channel 19) is missing parameters. Use <file>=<on>:<off> format!\n"); return -EINVAL; } *p++ = '\0'; @@ -213,16 +214,16 @@ error_paging: bnetz = calloc(1, sizeof(bnetz_t)); if (!bnetz) { - PDEBUG(DBNETZ, DEBUG_ERROR, "No memory!\n"); + LOGP(DBNETZ, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DBNETZ, DEBUG_DEBUG, "Creating 'B-Netz' instance for 'Kanal' = %s 'Gruppenfreisignal' = %d (sample rate %d).\n", kanal, gfs, samplerate); + LOGP(DBNETZ, LOGL_DEBUG, "Creating 'B-Netz' instance for 'Kanal' = %s 'Gruppenfreisignal' = %d (sample rate %d).\n", kanal, gfs, samplerate); /* init general part of transceiver */ rc = sender_create(&bnetz->sender, kanal, bnetz_kanal2freq(atoi(kanal), 0), bnetz_kanal2freq(atoi(kanal), 1), device, use_sdr, samplerate, rx_gain, tx_gain, pre_emphasis, de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, paging_signal); if (rc < 0) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DBNETZ, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } bnetz->sender.ruffrequenz = bnetz_kanal2freq(19, 0); @@ -230,7 +231,7 @@ error_paging: /* init audio processing */ rc = dsp_init_sender(bnetz, squelch_db); if (rc < 0) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DBNETZ, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } @@ -239,13 +240,13 @@ error_paging: strncpy(bnetz->paging_file, paging_file, sizeof(bnetz->paging_file) - 1); strncpy(bnetz->paging_on, paging_on, sizeof(bnetz->paging_on) - 1); strncpy(bnetz->paging_off, paging_off, sizeof(bnetz->paging_off) - 1); - timer_init(&bnetz->timer, bnetz_timeout, bnetz); + osmo_timer_setup(&bnetz->timer, bnetz_timeout, bnetz); /* go into idle state */ bnetz_go_idle(bnetz); - PDEBUG(DBNETZ, DEBUG_NOTICE, "Created 'Kanal' #%s\n", kanal); - PDEBUG(DBNETZ, DEBUG_NOTICE, " -> Using station ID (Gruppenfreisignal) %d\n", gfs); + LOGP(DBNETZ, LOGL_NOTICE, "Created 'Kanal' #%s\n", kanal); + LOGP(DBNETZ, LOGL_NOTICE, " -> Using station ID (Gruppenfreisignal) %d\n", gfs); return 0; @@ -260,10 +261,10 @@ void bnetz_destroy(sender_t *sender) { bnetz_t *bnetz = (bnetz_t *) sender; - PDEBUG(DBNETZ, DEBUG_DEBUG, "Destroying 'B-Netz' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DBNETZ, LOGL_DEBUG, "Destroying 'B-Netz' instance for 'Kanal' = %s.\n", sender->kanal); switch_channel_19(bnetz, 0); dsp_cleanup_sender(bnetz); - timer_exit(&bnetz->timer); + osmo_timer_del(&bnetz->timer); sender_destroy(&bnetz->sender); free(bnetz); } @@ -271,9 +272,9 @@ void bnetz_destroy(sender_t *sender) /* releaseing connection towards mobile station by sending idle digits. */ static void bnetz_go_idle(bnetz_t *bnetz) { - timer_stop(&bnetz->timer); + osmo_timer_del(&bnetz->timer); - PDEBUG(DBNETZ, DEBUG_INFO, "Entering IDLE state on channel %s, sending 'Gruppenfreisignal' %d.\n", bnetz->sender.kanal, bnetz->gfs); + LOGP(DBNETZ, LOGL_INFO, "Entering IDLE state on channel %s, sending 'Gruppenfreisignal' %d.\n", bnetz->sender.kanal, bnetz->gfs); bnetz->station_id[0] = '\0'; /* remove station ID before state change, so status is shown correctly */ bnetz_new_state(bnetz, BNETZ_FREI); bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); @@ -283,9 +284,9 @@ static void bnetz_go_idle(bnetz_t *bnetz) /* Release connection towards mobile station by sending release digits. */ static void bnetz_release(bnetz_t *bnetz, int trenn_count) { - timer_stop(&bnetz->timer); + osmo_timer_del(&bnetz->timer); - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Entering release state, sending 'Trennsignal' (%d times).\n", trenn_count); + LOGP_CHAN(DBNETZ, LOGL_INFO, "Entering release state, sending 'Trennsignal' (%d times).\n", trenn_count); bnetz->station_id[0] = '\0'; /* remove station ID before state change, so status is shown correctly */ bnetz_new_state(bnetz, BNETZ_TRENNEN); bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); @@ -296,14 +297,14 @@ static void bnetz_release(bnetz_t *bnetz, int trenn_count) /* Enter paging state and transmit station ID. */ static void bnetz_page(bnetz_t *bnetz, const char *dial_string, int try) { - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Entering paging state (try %d), sending 'Selektivruf' to '%s'.\n", try, dial_string); - strcpy(bnetz->station_id, dial_string); /* set station ID before state change, so status is shown correctly */ + LOGP_CHAN(DBNETZ, LOGL_INFO, "Entering paging state (try %d), sending 'Selektivruf' to '%s'.\n", try, dial_string); + memmove(bnetz->station_id, dial_string, strlen(dial_string) + 1); /* set station ID before state change, so status is shown correctly */ bnetz->station_id_pos = 0; bnetz_new_state(bnetz, BNETZ_SELEKTIVRUF_EIN); bnetz_set_dsp_mode(bnetz, DSP_MODE_0); bnetz->page_mode = PAGE_MODE_NUMBER; bnetz->page_try = try; - timer_start(&bnetz->timer, SWITCH19_TIME); + osmo_timer_schedule(&bnetz->timer, SWITCH19_TIME); switch_channel_19(bnetz, 1); } @@ -332,10 +333,10 @@ const char *bnetz_get_telegramm(bnetz_t *bnetz) break; case BNETZ_SELEKTIVRUF_EIN: if (bnetz->page_mode == PAGE_MODE_KANALBEFEHL) { - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Paging mobile station %s complete, waiting for answer.\n", bnetz->station_id); + LOGP_CHAN(DBNETZ, LOGL_INFO, "Paging mobile station %s complete, waiting for answer.\n", bnetz->station_id); bnetz_new_state(bnetz, BNETZ_SELEKTIVRUF_AUS); bnetz_set_dsp_mode(bnetz, DSP_MODE_SILENCE); - timer_start(&bnetz->timer, SWITCHBACK_TIME); + osmo_timer_schedule(&bnetz->timer, SWITCHBACK_TIME); return NULL; } if (bnetz->station_id_pos == 5) { @@ -347,7 +348,7 @@ const char *bnetz_get_telegramm(bnetz_t *bnetz) break; case BNETZ_TRENNEN: if (bnetz->trenn_count-- == 0) { - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "Maximum number of release digits sent, going idle.\n"); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "Maximum number of release digits sent, going idle.\n"); bnetz_go_idle(bnetz); return NULL; } @@ -360,7 +361,7 @@ const char *bnetz_get_telegramm(bnetz_t *bnetz) if (!it) abort(); - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "Sending telegramm '%s'.\n", it->description); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "Sending telegramm '%s'.\n", it->description); return it->sequence; } @@ -369,7 +370,7 @@ void bnetz_loss_indication(bnetz_t *bnetz, double loss_time) { if (bnetz->state == BNETZ_GESPRAECH || bnetz->state == BNETZ_RUFHALTUNG) { - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Detected loss of signal after %.1f seconds, releasing.\n", loss_time); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Detected loss of signal after %.1f seconds, releasing.\n", loss_time); bnetz_release(bnetz, TRENN_COUNT); call_up_release(bnetz->callref, CAUSE_TEMPFAIL); bnetz->callref = 0; @@ -380,9 +381,9 @@ void bnetz_loss_indication(bnetz_t *bnetz, double loss_time) void bnetz_receive_tone(bnetz_t *bnetz, int bit) { if (bit >= 0) - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "Received continuous %d Hz tone.\n", (bit)?1950:2070); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "Received continuous %d Hz tone.\n", (bit)?1950:2070); else - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "Continuous tone is gone.\n"); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "Continuous tone is gone.\n"); if (bnetz->sender.loopback) { return; @@ -391,11 +392,11 @@ void bnetz_receive_tone(bnetz_t *bnetz, int bit) switch (bnetz->state) { case BNETZ_FREI: if (bit == 0) { - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Received signal 'Kanalbelegung' from mobile station, sending signal 'Wahlabruf'.\n"); + LOGP_CHAN(DBNETZ, LOGL_INFO, "Received signal 'Kanalbelegung' from mobile station, sending signal 'Wahlabruf'.\n"); bnetz_new_state(bnetz, BNETZ_WAHLABRUF); bnetz->dial_mode = DIAL_MODE_START; bnetz_set_dsp_mode(bnetz, DSP_MODE_1); - timer_start(&bnetz->timer, DIALING_TO); + osmo_timer_schedule(&bnetz->timer, DIALING_TO); /* must reset, so we will not get corrupt first digit */ bnetz->rx_telegramm = bnetz->tone_detected * 0xffff; break; @@ -403,24 +404,24 @@ void bnetz_receive_tone(bnetz_t *bnetz, int bit) break; case BNETZ_RUFBESTAETIGUNG: if (bit == 1) { - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Received signal 'Rufbestaetigung' from mobile station, sending signal 'Rufhaltung'. (call is ringing)\n"); - timer_stop(&bnetz->timer); + LOGP_CHAN(DBNETZ, LOGL_INFO, "Received signal 'Rufbestaetigung' from mobile station, sending signal 'Rufhaltung'. (call is ringing)\n"); + osmo_timer_del(&bnetz->timer); bnetz_new_state(bnetz, BNETZ_RUFHALTUNG); bnetz_set_dsp_mode(bnetz, DSP_MODE_1); call_up_alerting(bnetz->callref); - timer_start(&bnetz->timer, ALERTING_TO); + osmo_timer_schedule(&bnetz->timer, ALERTING_TO); break; } break; case BNETZ_RUFHALTUNG: if (bit == 0) { - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Received signal 'Beginnsignal' from mobile station, call establised.\n"); - timer_stop(&bnetz->timer); + LOGP_CHAN(DBNETZ, LOGL_INFO, "Received signal 'Beginnsignal' from mobile station, call establised.\n"); + osmo_timer_del(&bnetz->timer); bnetz_new_state(bnetz, BNETZ_GESPRAECH); bnetz_set_dsp_mode(bnetz, DSP_MODE_AUDIO); /* start metering pulses if forced */ if (bnetz->metering < 0) - timer_start(&bnetz->timer, METERING_START); + osmo_timer_schedule(&bnetz->timer, METERING_START); call_up_answer(bnetz->callref, bnetz->station_id); break; } @@ -438,22 +439,22 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) it = bnetz_telegramm2digit(telegramm); if (it) { digit = it->digit; - PDEBUG(DBNETZ, (bnetz->sender.loopback) ? DEBUG_NOTICE : DEBUG_INFO, "Received telegramm '%s'\n", it->description); + LOGP(DBNETZ, (bnetz->sender.loopback) ? LOGL_NOTICE : LOGL_INFO, "Received telegramm '%s'\n", it->description); } else { - PDEBUG(DBNETZ, DEBUG_DEBUG, "Received unknown telegramm digit '0x%04x' (might be radio noise)\n", telegramm); + LOGP(DBNETZ, LOGL_DEBUG, "Received unknown telegramm digit '0x%04x' (might be radio noise)\n", telegramm); return; } if (bnetz->sender.loopback) { if (digit >= '0' && digit <= '9') { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Round trip delay is %.3f seconds\n", get_time() - bnetz->loopback_time[digit - '0'] - 0.160); + LOGP(DBNETZ, LOGL_NOTICE, "Round trip delay is %.3f seconds\n", get_time() - bnetz->loopback_time[digit - '0'] - 0.160); } return; } switch (bnetz->state) { case BNETZ_WAHLABRUF: - timer_start(&bnetz->timer, DIALING_TO2); + osmo_timer_schedule(&bnetz->timer, DIALING_TO2); switch (bnetz->dial_mode) { case DIAL_MODE_START: switch (digit) { @@ -467,7 +468,7 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) bnetz->dial_type = DIAL_TYPE_METER_MUENZ; break; default: - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received digit that is not a start digit ('Funkwahl'), releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received digit that is not a start digit ('Funkwahl'), releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } @@ -477,7 +478,7 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) break; case DIAL_MODE_STATIONID: if (digit < '0' || digit > '9') { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received message that is not a valid station id digit, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received message that is not a valid station id digit, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } @@ -485,29 +486,29 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) /* update status while receiving station ID */ bnetz_display_status(); if (bnetz->dial_pos == 5) { - PDEBUG(DBNETZ, DEBUG_INFO, "Received station id from mobile phone: %s\n", bnetz->station_id); + LOGP(DBNETZ, LOGL_INFO, "Received station id from mobile phone: %s\n", bnetz->station_id); bnetz->dial_mode = DIAL_MODE_NUMBER; memset(bnetz->dial_number, 0, sizeof(bnetz->dial_number)); bnetz->dial_pos = 0; /* reply station ID */ - PDEBUG(DBNETZ, DEBUG_INFO, "Sending station id back to phone: %s.\n", bnetz->station_id); + LOGP(DBNETZ, LOGL_INFO, "Sending station id back to phone: %s.\n", bnetz->station_id); bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); bnetz->station_id_pos = 0; } break; case DIAL_MODE_NUMBER: if (digit == 'e') { - PDEBUG(DBNETZ, DEBUG_INFO, "Received number from mobile phone: %s\n", bnetz->dial_number); + LOGP(DBNETZ, LOGL_INFO, "Received number from mobile phone: %s\n", bnetz->dial_number); bnetz->dial_mode = DIAL_MODE_START2; break; } if (digit < '0' || digit > '9') { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received message that is not a valid number digit, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received message that is not a valid number digit, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } if (bnetz->dial_pos == sizeof(bnetz->dial_number) - 1) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received too many number digits, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received too many number digits, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } @@ -517,27 +518,27 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) switch (digit) { case 's': if (bnetz->dial_type != DIAL_TYPE_NOMETER) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Repeated start message ('Funkwahl') does not match first one (no metering support), releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Repeated start message ('Funkwahl') does not match first one (no metering support), releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } break; case 'S': if (bnetz->dial_type != DIAL_TYPE_METER) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Repeated start message ('Funkwahl') does not match first one (metering support), releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Repeated start message ('Funkwahl') does not match first one (metering support), releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } break; case 'M': if (bnetz->dial_type != DIAL_TYPE_METER_MUENZ) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Repeated start message ('Funkwahl') does not match first one (metering support, payphone), releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Repeated start message ('Funkwahl') does not match first one (metering support, payphone), releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } break; default: - PDEBUG(DBNETZ, DEBUG_NOTICE, "Repeated digit is not a start digit ('Funkwahl'), releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Repeated digit is not a start digit ('Funkwahl'), releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } @@ -546,12 +547,12 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) break; case DIAL_MODE_STATIONID2: if (digit < '0' || digit > '9') { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received message that is not a valid station id digit, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received message that is not a valid station id digit, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } if (bnetz->station_id[bnetz->dial_pos++] != digit) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Repeated station id does not match the first one, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Repeated station id does not match the first one, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } @@ -567,43 +568,43 @@ void bnetz_receive_telegramm(bnetz_t *bnetz, uint16_t telegramm) strcpy(dialing + 1, bnetz->dial_number); if (bnetz->dial_pos != (int)strlen(bnetz->dial_number)) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received too few repeated number digits, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received too few repeated number digits, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } if (!strncmp(dialing, "0110", 4)) { - PDEBUG(DBNETZ, DEBUG_INFO, "Translating emergency number to '110'.\n"); + LOGP(DBNETZ, LOGL_INFO, "Translating emergency number to '110'.\n"); strcpy(dialing, "110"); } if (!strncmp(dialing, "0112", 4)) { - PDEBUG(DBNETZ, DEBUG_INFO, "Translating emergency number to '112'.\n"); + LOGP(DBNETZ, LOGL_INFO, "Translating emergency number to '112'.\n"); strcpy(dialing, "112"); } - PDEBUG(DBNETZ, DEBUG_INFO, "Dialing complete %s->%s, call established.\n", bnetz->station_id, dialing); - timer_stop(&bnetz->timer); + LOGP(DBNETZ, LOGL_INFO, "Dialing complete %s->%s, call established.\n", bnetz->station_id, dialing); + osmo_timer_del(&bnetz->timer); bnetz_set_dsp_mode(bnetz, DSP_MODE_AUDIO); bnetz_new_state(bnetz, BNETZ_GESPRAECH); /* start metering pulses if enabled and supported by phone or if forced */ if (bnetz->metering < 0 || (bnetz->metering > 0 && (bnetz->dial_type == DIAL_TYPE_METER || bnetz->dial_type == DIAL_TYPE_METER_MUENZ))) - timer_start(&bnetz->timer, METERING_START); + osmo_timer_schedule(&bnetz->timer, METERING_START); /* setup call */ - PDEBUG(DBNETZ, DEBUG_INFO, "Setup call to network.\n"); + LOGP(DBNETZ, LOGL_INFO, "Setup call to network.\n"); bnetz->callref = call_up_setup(bnetz->station_id, dialing, OSMO_CC_NETWORK_BNETZ_MUENZ, (bnetz->dial_type == DIAL_TYPE_METER_MUENZ) ? "MUENZ" : ""); break; } if (digit < '0' || digit > '9') { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received message that is not a valid number digit, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received message that is not a valid number digit, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } if (bnetz->dial_pos == (int)strlen(bnetz->dial_number)) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received too many number digits, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received too many number digits, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } if (bnetz->dial_number[bnetz->dial_pos++] != digit) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Repeated number does not match the first one, releaseing.\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Repeated number does not match the first one, releaseing.\n"); bnetz_release(bnetz, TRENN_COUNT); return; } @@ -618,7 +619,7 @@ lets see, if noise will not generate a release signal.... return; #endif if (digit == 't') { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Received 'Schlusssignal' from mobile station\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Received 'Schlusssignal' from mobile station\n"); bnetz_release(bnetz, TRENN_COUNT); call_up_release(bnetz->callref, CAUSE_NORMAL); bnetz->callref = 0; @@ -637,32 +638,32 @@ static void bnetz_timeout(void *data) switch (bnetz->state) { case BNETZ_WAHLABRUF: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Timeout while receiving call setup from mobile station, releasing.\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Timeout while receiving call setup from mobile station, releasing.\n"); bnetz_release(bnetz, TRENN_COUNT); break; case BNETZ_SELEKTIVRUF_EIN: - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "Transmitter switched to channel 19, starting paging telegramms.\n"); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "Transmitter switched to channel 19, starting paging telegramms.\n"); bnetz_set_dsp_mode(bnetz, DSP_MODE_TELEGRAMM); break; case BNETZ_SELEKTIVRUF_AUS: - PDEBUG_CHAN(DBNETZ, DEBUG_DEBUG, "Transmitter switched back to channel %s, waiting for paging response.\n", bnetz->sender.kanal); + LOGP_CHAN(DBNETZ, LOGL_DEBUG, "Transmitter switched back to channel %s, waiting for paging response.\n", bnetz->sender.kanal); bnetz_new_state(bnetz, BNETZ_RUFBESTAETIGUNG); switch_channel_19(bnetz, 0); - timer_start(&bnetz->timer, PAGING_TO); + osmo_timer_schedule(&bnetz->timer, PAGING_TO); break; case BNETZ_RUFBESTAETIGUNG: if (bnetz->page_try == PAGE_TRIES) { - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Timeout while waiting for call acknowledge from mobile station, releasing.\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Timeout while waiting for call acknowledge from mobile station, releasing.\n"); bnetz_release(bnetz, TRENN_COUNT); call_up_release(bnetz->callref, CAUSE_OUTOFORDER); bnetz->callref = 0; break; } - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Timeout while waiting for call acknowledge from mobile station, trying again.\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Timeout while waiting for call acknowledge from mobile station, trying again.\n"); bnetz_page(bnetz, bnetz->station_id, bnetz->page_try + 1); break; case BNETZ_RUFHALTUNG: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Timeout while waiting for answer of mobile station, releasing.\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Timeout while waiting for answer of mobile station, releasing.\n"); bnetz_release(bnetz, TRENN_COUNT); call_up_release(bnetz->callref, CAUSE_NOANSWER); bnetz->callref = 0; @@ -672,12 +673,12 @@ static void bnetz_timeout(void *data) case DSP_MODE_AUDIO: /* turn on merting pulse */ bnetz_set_dsp_mode(bnetz, DSP_MODE_AUDIO_METER); - timer_start(&bnetz->timer, METERING_DURATION); + osmo_timer_schedule(&bnetz->timer, METERING_DURATION); break; case DSP_MODE_AUDIO_METER: /* turn off and wait given seconds for next metering cycle */ bnetz_set_dsp_mode(bnetz, DSP_MODE_AUDIO); - timer_start(&bnetz->timer, (double)abs(bnetz->metering) - METERING_DURATION); + osmo_timer_schedule(&bnetz->timer, (double)abs(bnetz->metering) - METERING_DURATION); break; default: break; @@ -701,7 +702,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (sender) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } @@ -712,11 +713,11 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (!sender) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Call to mobile station, paging station id '%s'\n", dialing); + LOGP_CHAN(DBNETZ, LOGL_INFO, "Call to mobile station, paging station id '%s'\n", dialing); /* 3. trying to page mobile station */ bnetz->callref = callref; @@ -738,7 +739,7 @@ void call_down_disconnect(int callref, int cause) sender_t *sender; bnetz_t *bnetz; - PDEBUG(DBNETZ, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DBNETZ, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { bnetz = (bnetz_t *) sender; @@ -746,7 +747,7 @@ void call_down_disconnect(int callref, int cause) break; } if (!sender) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -758,11 +759,11 @@ void call_down_disconnect(int callref, int cause) case BNETZ_SELEKTIVRUF_EIN: case BNETZ_SELEKTIVRUF_AUS: case BNETZ_RUFBESTAETIGUNG: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Outgoing disconnect, during paging, releasing!\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Outgoing disconnect, during paging, releasing!\n"); bnetz_release(bnetz, TRENN_COUNT); break; case BNETZ_RUFHALTUNG: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Outgoing disconnect, during alerting, releasing!\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Outgoing disconnect, during alerting, releasing!\n"); bnetz_release(bnetz, TRENN_COUNT); break; default: @@ -780,7 +781,7 @@ void call_down_release(int callref, int __attribute__((unused)) cause) sender_t *sender; bnetz_t *bnetz; - PDEBUG(DBNETZ, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DBNETZ, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { bnetz = (bnetz_t *) sender; @@ -788,7 +789,7 @@ void call_down_release(int callref, int __attribute__((unused)) cause) break; } if (!sender) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -797,17 +798,17 @@ void call_down_release(int callref, int __attribute__((unused)) cause) switch (bnetz->state) { case BNETZ_GESPRAECH: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Outgoing release, during call, releasing!\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Outgoing release, during call, releasing!\n"); bnetz_release(bnetz, TRENN_COUNT); break; case BNETZ_SELEKTIVRUF_EIN: case BNETZ_SELEKTIVRUF_AUS: case BNETZ_RUFBESTAETIGUNG: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Outgoing release, during paging, releasing!\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Outgoing release, during paging, releasing!\n"); bnetz_release(bnetz, TRENN_COUNT); break; case BNETZ_RUFHALTUNG: - PDEBUG_CHAN(DBNETZ, DEBUG_NOTICE, "Outgoing release, during alerting, releasing!\n"); + LOGP_CHAN(DBNETZ, LOGL_NOTICE, "Outgoing release, during alerting, releasing!\n"); bnetz_release(bnetz, TRENN_COUNT); break; default: diff --git a/src/bnetz/bnetz.h b/src/bnetz/bnetz.h index fa19cd0..3995744 100644 --- a/src/bnetz/bnetz.h +++ b/src/bnetz/bnetz.h @@ -1,7 +1,7 @@ #include "../libsquelch/squelch.h" #include "../libfsk/fsk.h" #include "../libmobile/sender.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> /* fsk modes of transmission */ enum dsp_mode { @@ -74,7 +74,7 @@ typedef struct bnetz { int station_id_pos; /* position while transmitting */ enum page_mode page_mode; /* sub state while paging */ int page_try; /* try number (1 or 2) */ - struct timer timer; + struct osmo_timer_list timer; int trenn_count; /* count number of release messages */ /* display measurements */ diff --git a/src/bnetz/dialer.c b/src/bnetz/dialer.c index ab625b6..bfe252d 100644 --- a/src/bnetz/dialer.c +++ b/src/bnetz/dialer.c @@ -26,7 +26,7 @@ #include "../libsample/sample.h" #include "../libfsk/fsk.h" #include "../libwave/wave.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #ifdef HAVE_ALSA #include "../libsound/sound.h" #endif @@ -161,13 +161,13 @@ static int fsk_send_bit(void __attribute__((unused)) *inst) if (!tx_telegramm || tx_telegramm_pos == 16) { switch (funkwahl[digit_pos]) { case '\0': - PDEBUG(DBNETZ, DEBUG_INFO, "Done sending dialing sequence\n"); + LOGP(DBNETZ, LOGL_INFO, "Done sending dialing sequence\n"); tx_mode = TX_MODE_SILENCE; tx_silence_count = 0; return -1; case 'w': if (!tx_telegramm) - PDEBUG(DBNETZ, DEBUG_INFO, "Sending channel allocation tone ('Kanalbelegung')\n"); + LOGP(DBNETZ, LOGL_INFO, "Sending channel allocation tone ('Kanalbelegung')\n"); tx_telegramm = "0000000000000000"; tx_telegramm_pos = 0; digit_pos++; @@ -175,23 +175,23 @@ static int fsk_send_bit(void __attribute__((unused)) *inst) default: switch (funkwahl[digit_pos]) { case 's': - PDEBUG(DBNETZ, DEBUG_INFO, "Sending start digit (no charging meater on board)\n"); + LOGP(DBNETZ, LOGL_INFO, "Sending start digit (no charging meater on board)\n"); break; case 'S': - PDEBUG(DBNETZ, DEBUG_INFO, "Sending start digit (with charging meater on board)\n"); + LOGP(DBNETZ, LOGL_INFO, "Sending start digit (with charging meater on board)\n"); break; case 'M': - PDEBUG(DBNETZ, DEBUG_INFO, "Sending start digit (Phone is a coin box.)\n"); + LOGP(DBNETZ, LOGL_INFO, "Sending start digit (Phone is a coin box.)\n"); break; case 'e': - PDEBUG(DBNETZ, DEBUG_INFO, "Sending stop digit\n"); + LOGP(DBNETZ, LOGL_INFO, "Sending stop digit\n"); break; default: - PDEBUG(DBNETZ, DEBUG_INFO, "Sending digit '%c'\n", funkwahl[digit_pos]); + LOGP(DBNETZ, LOGL_INFO, "Sending digit '%c'\n", funkwahl[digit_pos]); } impulstelegramm = bnetz_digit2telegramm(funkwahl[digit_pos]); if (!impulstelegramm) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Illegal digit '%c', please fix!\n", funkwahl[digit_pos]); + LOGP(DBNETZ, LOGL_ERROR, "Illegal digit '%c', please fix!\n", funkwahl[digit_pos]); abort(); } tx_telegramm = impulstelegramm->sequence; @@ -252,7 +252,7 @@ static void process_signal(int buffer_size) count = dsp_samplerate / 1000; #endif if (count < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); + LOGP(DDSP, LOGL_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); break; } @@ -267,7 +267,7 @@ static void process_signal(int buffer_size) /* write audio */ rc = sound_write(audio, samples, power, count, NULL, NULL, 1); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); + LOGP(DDSP, LOGL_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); break; } #endif @@ -340,7 +340,7 @@ int main(int argc, char *argv[]) /* init fsk */ if (fsk_mod_init(&fsk_mod, NULL, fsk_send_bit, dsp_samplerate, BIT_RATE, F0, F1, 1.0, 0, 0) < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP(DDSP, LOGL_ERROR, "FSK init failed!\n"); goto exit; } @@ -348,7 +348,7 @@ int main(int argc, char *argv[]) /* init sound */ audio = sound_open(dsp_audiodev, NULL, NULL, NULL, 1, 0.0, dsp_samplerate, buffer_size, 1.0, 1.0, 4000.0, 2.0); if (!audio) { - PDEBUG(DBNETZ, DEBUG_ERROR, "No sound device!\n"); + LOGP(DBNETZ, LOGL_ERROR, "No sound device!\n"); goto exit; } #endif @@ -357,13 +357,13 @@ int main(int argc, char *argv[]) if (write_tx_wave) { rc = wave_create_record(&wave_tx_rec, write_tx_wave, dsp_samplerate, 1, 1.0); if (rc < 0) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DBNETZ, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); goto exit; } } #ifndef HAVE_ALSA else { - PDEBUG(DBNETZ, DEBUG_ERROR, "No sound support compiled in, so you need to write to a wave file. See help!\n"); + LOGP(DBNETZ, LOGL_ERROR, "No sound support compiled in, so you need to write to a wave file. See help!\n"); goto exit; } #endif @@ -373,7 +373,7 @@ int main(int argc, char *argv[]) sound_start(audio); #endif - PDEBUG(DBNETZ, DEBUG_ERROR, "Start audio after pause...\n"); + LOGP(DBNETZ, LOGL_ERROR, "Start audio after pause...\n"); process_signal(buffer_size); diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c index 5305183..fe99c22 100644 --- a/src/bnetz/dsp.c +++ b/src/bnetz/dsp.c @@ -26,7 +26,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "bnetz.h" #include "dsp.h" @@ -70,7 +70,7 @@ void dsp_init(void) { int i; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table for metering tone.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine table for metering tone.\n"); for (i = 0; i < 65536; i++) dsp_metering[i] = sin((double)i / 65536.0 * 2.0 * PI) * TX_PEAK_METER; } @@ -81,10 +81,10 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level); /* Init transceiver instance. */ int dsp_init_sender(bnetz_t *bnetz, double squelch_db) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for 'Sender'.\n"); if (TONE_DETECT_CNT > sizeof(bnetz->rx_tone_quality) / sizeof(bnetz->rx_tone_quality[0])) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "buffer for tone quality is too small, please fix!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "buffer for tone quality is too small, please fix!\n"); return -EINVAL; } @@ -94,15 +94,15 @@ int dsp_init_sender(bnetz_t *bnetz, double squelch_db) /* set modulation parameters */ sender_set_fm(&bnetz->sender, MAX_DEVIATION, MAX_MODULATION, SPEECH_DEVIATION, MAX_DISPLAY); - PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation @ 2000 Hz)\n", TX_PEAK_FSK, 4.0); + LOGP(DDSP, LOGL_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation @ 2000 Hz)\n", TX_PEAK_FSK, 4.0); /* init fsk */ if (fsk_mod_init(&bnetz->fsk_mod, bnetz, fsk_send_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 0, 0) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } if (fsk_demod_init(&bnetz->fsk_demod, bnetz, fsk_receive_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, BIT_ADJUST) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } @@ -124,7 +124,7 @@ int dsp_init_sender(bnetz_t *bnetz, double squelch_db) /* Cleanup transceiver instance. */ void dsp_cleanup_sender(bnetz_t *bnetz) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for 'Sender'.\n"); fsk_mod_cleanup(&bnetz->fsk_mod); fsk_demod_cleanup(&bnetz->fsk_demod); @@ -148,7 +148,7 @@ static void fsk_receive_tone(bnetz_t *bnetz, int tone, int goodtone, double leve /* set duration to TONE_DETECT_CNT, because it took that long to detect the tone */ bnetz->tone_duration = TONE_DETECT_CNT; bnetz->tone_detected = tone; - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Detecting continuous tone: F%d Level=%3.0f%% (threshold %3.0f%%) standard deviation=%.0f%% (threshold=%.0f%%) Quality=%3.0f%%\n", bnetz->tone_detected, level_avg * 100.0, TONE_LEVEL_TH * 100.0, level_stddev / level_avg * 100.0, TONE_STDDEV_TH * 100.0, quality_avg * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "Detecting continuous tone: F%d Level=%3.0f%% (threshold %3.0f%%) standard deviation=%.0f%% (threshold=%.0f%%) Quality=%3.0f%%\n", bnetz->tone_detected, level_avg * 100.0, TONE_LEVEL_TH * 100.0, level_stddev / level_avg * 100.0, TONE_STDDEV_TH * 100.0, quality_avg * 100.0); bnetz_receive_tone(bnetz, bnetz->tone_detected); } } @@ -158,7 +158,7 @@ static void fsk_receive_tone(bnetz_t *bnetz, int tone, int goodtone, double leve bnetz->tone_count++; if (bnetz->tone_count == TONE_LOST_CNT) { /* subtract TONE_LOST_CNT from duration, because it took that long to detect loss of tone */ - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Lost F%d tone after %.2f seconds.\n", bnetz->tone_detected, (double)(bnetz->tone_duration - TONE_LOST_CNT) / 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "Lost F%d tone after %.2f seconds.\n", bnetz->tone_detected, (double)(bnetz->tone_duration - TONE_LOST_CNT) / 100.0); bnetz->tone_detected = -1; bnetz_receive_tone(bnetz, -1); } @@ -250,7 +250,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) j++; } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "FSK Valid bits: %d/%d Level: %.0f%% (threshold %.0f%%) Stddev: %.0f%% (threshold %.0f%%)\n", j, 16, level_avg * 100.0, TONE_LEVEL_TH * 100.0, level_stddev / level_avg * 100.0, TONE_STDDEV_TH * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "FSK Valid bits: %d/%d Level: %.0f%% (threshold %.0f%%) Stddev: %.0f%% (threshold %.0f%%)\n", j, 16, level_avg * 100.0, TONE_LEVEL_TH * 100.0, level_stddev / level_avg * 100.0, TONE_STDDEV_TH * 100.0); /* drop any telegramm that is too bad */ if (level_stddev / level_avg > TONE_STDDEV_TH || j < 16) @@ -261,7 +261,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) display_measurements_update(bnetz->dmp_frame_stddev, level_stddev / level_avg * 100.0, 0.0); display_measurements_update(bnetz->dmp_frame_quality, quality_avg * 100.0, 0.0); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Telegramm RX Level: average=%.0f%% (threshold %.0f%%) standard deviation=%.0f%% (threshold %.0f%%) Quality: %.0f%%\n", level_avg * 100.0, TONE_LEVEL_TH * 100.0, level_stddev / level_avg * 100.0, TONE_STDDEV_TH * 100.0, quality_avg * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "Telegramm RX Level: average=%.0f%% (threshold %.0f%%) standard deviation=%.0f%% (threshold %.0f%%) Quality: %.0f%%\n", level_avg * 100.0, TONE_LEVEL_TH * 100.0, level_stddev / level_avg * 100.0, TONE_STDDEV_TH * 100.0, quality_avg * 100.0); /* receive telegramm */ bnetz_receive_telegramm(bnetz, bnetz->rx_telegramm); @@ -320,7 +320,7 @@ static int fsk_send_bit(void *inst) /* request frame */ bnetz->tx_telegramm = bnetz_get_telegramm(bnetz); if (!bnetz->tx_telegramm) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Stop sending 'Telegramm'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Stop sending 'Telegramm'.\n"); return -1; } bnetz->tx_telegramm_pos = 0; @@ -423,7 +423,7 @@ void bnetz_set_dsp_mode(bnetz_t *bnetz, enum dsp_mode mode) fsk_mod_reset(&bnetz->fsk_mod); } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", bnetz_dsp_mode_name(bnetz->dsp_mode), bnetz_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", bnetz_dsp_mode_name(bnetz->dsp_mode), bnetz_dsp_mode_name(mode)); bnetz->dsp_mode = mode; } diff --git a/src/bnetz/main.c b/src/bnetz/main.c index a82e412..0a5fa4f 100644 --- a/src/bnetz/main.c +++ b/src/bnetz/main.c @@ -24,7 +24,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../anetz/freiton.h" @@ -218,6 +218,7 @@ fail: bnetz_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/cnetz/Makefile.am b/src/cnetz/Makefile.am index 7975c7c..5b29c0b 100644 --- a/src/cnetz/Makefile.am +++ b/src/cnetz/Makefile.am @@ -24,14 +24,10 @@ cnetz_LDADD = \ ../anetz/libgermanton.a \ libcnetztones.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libscrambler/libscrambler.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ @@ -39,8 +35,10 @@ cnetz_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/cnetz/cnetz.c b/src/cnetz/cnetz.c index 83099f6..704d965 100644 --- a/src/cnetz/cnetz.c +++ b/src/cnetz/cnetz.c @@ -143,10 +143,11 @@ #include <math.h> #include <inttypes.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include "../libmobile/get_time.h" +#include <osmocom/cc/message.h> #include "cnetz.h" #include "database.h" #include "sysinfo.h" @@ -157,6 +158,8 @@ /* uncomment this to do echo debugging (-l) on Speech Channel */ //#define DEBUG_SPK +#define FLOAT_TO_TIMEOUT(f) floor(f), ((f) - floor(f)) * 1000000 + #define CUT_OFF_EMPHASIS_CNETZ 796.0 /* 200 uS time constant */ /* OgK list of alternative channels, NOT including 131 */ @@ -263,7 +266,7 @@ static void cnetz_new_state(cnetz_t *cnetz, enum cnetz_state new_state) { if (cnetz->state == new_state) return; - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "State change: %s -> %s\n", cnetz_state_name(cnetz->state), cnetz_state_name(new_state)); + LOGP_CHAN(DCNETZ, LOGL_INFO, "State change: %s -> %s\n", cnetz_state_name(cnetz->state), cnetz_state_name(new_state)); cnetz->state = new_state; cnetz_display_status(); } @@ -301,51 +304,51 @@ int cnetz_create(const char *kanal_name, enum cnetz_chan_type chan_type, const c kanal = atoi(kanal_name); if ((kanal & 1) && (kanal < 3 || kanal > 1147)) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Channel ('Kanal') number %d invalid. For odd channel numbers, use channel 3 ... 1147.\n", kanal); + LOGP(DCNETZ, LOGL_ERROR, "Channel ('Kanal') number %d invalid. For odd channel numbers, use channel 3 ... 1147.\n", kanal); return -EINVAL; } if ((kanal & 1) && kanal > 947) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "You defined an extended frequency channel %d, only newer phones support this!\n", kanal); + LOGP(DCNETZ, LOGL_NOTICE, "You defined an extended frequency channel %d, only newer phones support this!\n", kanal); } if (!(kanal & 1) && (kanal < 4 || kanal > 918)) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Channel ('Kanal') number %d invalid. For even channel numbers, use channel 4 ... 918.\n", kanal); + LOGP(DCNETZ, LOGL_ERROR, "Channel ('Kanal') number %d invalid. For even channel numbers, use channel 4 ... 918.\n", kanal); return -EINVAL; } if (!(kanal & 1) && kanal > 758) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "You defined an extended frequency channel %d, only newer phones support this!\n", kanal); + LOGP(DCNETZ, LOGL_NOTICE, "You defined an extended frequency channel %d, only newer phones support this!\n", kanal); } /* SpK must be on channel other than 131 */ if (chan_type == CHAN_TYPE_SPK && kanal == CNETZ_STD_OGK_KANAL) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "You must not use channel %d for traffic channel!\n", CNETZ_STD_OGK_KANAL); + LOGP(DCNETZ, LOGL_NOTICE, "You must not use channel %d for traffic channel!\n", CNETZ_STD_OGK_KANAL); return -EINVAL; } /* warn if we combine SpK and OgK, this is not supported by standard */ if (chan_type == CHAN_TYPE_OGK_SPK) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "You selected channel %d ('Orga-Kanal') for combined control + traffic channel. Some phones will reject this.\n", kanal); + LOGP(DCNETZ, LOGL_NOTICE, "You selected channel %d ('Orga-Kanal') for combined control + traffic channel. Some phones will reject this.\n", kanal); } for (sender = sender_head; sender; sender = sender->next) { cnetz = (cnetz_t *)sender; if (!!strcmp(sender->device, device)) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "To be able to sync multiple channels, all channels must be on the same sound device!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "To be able to sync multiple channels, all channels must be on the same sound device!\n"); return -EINVAL; } } cnetz = calloc(1, sizeof(cnetz_t)); if (!cnetz) { - PDEBUG(DCNETZ, DEBUG_ERROR, "No memory!\n"); + LOGP(DCNETZ, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DCNETZ, DEBUG_DEBUG, "Creating 'C-Netz' instance for 'Kanal' = %d (sample rate %d).\n", kanal, samplerate); + LOGP(DCNETZ, LOGL_DEBUG, "Creating 'C-Netz' instance for 'Kanal' = %d (sample rate %d).\n", kanal, samplerate); cnetz->kanal = kanal; if ((chan_type == CHAN_TYPE_OGK || chan_type == CHAN_TYPE_OGK_SPK) && kanal != CNETZ_STD_OGK_KANAL) { if (ogk_list_count == 16) { - PDEBUG(DCNETZ, DEBUG_ERROR, "No more than 16 non-standard OGK are allowed!\n"); + LOGP(DCNETZ, LOGL_ERROR, "No more than 16 non-standard OGK are allowed!\n"); rc = -EINVAL; goto error; } @@ -356,7 +359,7 @@ int cnetz_create(const char *kanal_name, enum cnetz_chan_type chan_type, const c /* do not enable emphasis, since it is done by cnetz code, not by common sender code */ rc = sender_create(&cnetz->sender, kanal_name, cnetz_kanal2freq(kanal, 0), cnetz_kanal2freq(kanal, 1), device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } @@ -371,7 +374,7 @@ int cnetz_create(const char *kanal_name, enum cnetz_chan_type chan_type, const c /* init audio processing */ rc = dsp_init_sender(cnetz, measure_speed, clock_speed, demod, speech_deviation); if (rc < 0) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to init signal processing!\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to init signal processing!\n"); goto error; } @@ -444,10 +447,10 @@ int cnetz_create(const char *kanal_name, enum cnetz_chan_type chan_type, const c cnetz_flush_other_transactions(cnetz, trans2); #endif - PDEBUG(DCNETZ, DEBUG_NOTICE, "Created 'Kanal' #%d of type '%s' = %s\n", kanal, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); + LOGP(DCNETZ, LOGL_NOTICE, "Created 'Kanal' #%d of type '%s' = %s\n", kanal, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); const char *name, *long_name; name = get_station_name(si.fuz_nat, si.fuz_fuvst, si.fuz_rest, &long_name); - PDEBUG(DCNETZ, DEBUG_NOTICE, " -> Using cell ID: Nat=%d FuVst=%d Rest=%d Name='%s' Long Name='%s'\n", si.fuz_nat, si.fuz_fuvst, si.fuz_rest, name, long_name); + LOGP(DCNETZ, LOGL_NOTICE, " -> Using cell ID: Nat=%d FuVst=%d Rest=%d Name='%s' Long Name='%s'\n", si.fuz_nat, si.fuz_fuvst, si.fuz_rest, name, long_name); return 0; @@ -463,11 +466,11 @@ void cnetz_destroy(sender_t *sender) cnetz_t *cnetz = (cnetz_t *) sender; transaction_t *trans; - PDEBUG(DCNETZ, DEBUG_DEBUG, "Destroying 'C-Netz' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DCNETZ, LOGL_DEBUG, "Destroying 'C-Netz' instance for 'Kanal' = %s.\n", sender->kanal); while ((trans = search_transaction(cnetz, ~0))) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DCNETZ, DEBUG_NOTICE, "Removing pending transaction for subscriber '%s'\n", rufnummer); + LOGP(DCNETZ, LOGL_NOTICE, "Removing pending transaction for subscriber '%s'\n", rufnummer); destroy_transaction(trans); } @@ -534,13 +537,13 @@ void cnetz_go_idle(cnetz_t *cnetz) return; if (cnetz->trans_list) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Releasing but still having transaction, please fix!\n"); + LOGP(DCNETZ, LOGL_ERROR, "Releasing but still having transaction, please fix!\n"); if (cnetz->trans_list->callref) call_up_release(cnetz->trans_list->callref, CAUSE_NORMAL); destroy_transaction(cnetz->trans_list); } - PDEBUG(DCNETZ, DEBUG_INFO, "Entering IDLE state on channel %s.\n", cnetz->sender.kanal); + LOGP(DCNETZ, LOGL_INFO, "Entering IDLE state on channel %s.\n", cnetz->sender.kanal); cnetz_new_state(cnetz, CNETZ_IDLE); cnetz->sched_lr_debugged = 0; cnetz->sched_mlr_debugged = 0; @@ -558,10 +561,10 @@ void cnetz_go_idle(cnetz_t *cnetz) /* check for first phone in queue and trigger completion of call (becoming idle means that SpK is now available) */ trans = search_transaction_queue(); if (trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Now channel is available for queued subscriber '%s'.\n", transaction2rufnummer(trans)); + LOGP(DCNETZ, LOGL_NOTICE, "Now channel is available for queued subscriber '%s'.\n", transaction2rufnummer(trans)); trans_new_state(trans, (trans->state == TRANS_MT_QUEUE) ? TRANS_MT_DELAY : TRANS_MO_DELAY); - timer_stop(&trans->timer); - timer_start(&trans->timer, 3.0); /* Wait at least one frame cycles until timeout */ + osmo_timer_del(&trans->timer); + osmo_timer_schedule(&trans->timer, 3,0); /* Wait at least one frame cycles (2.4s) until timeout */ } } @@ -572,7 +575,7 @@ static void cnetz_release(transaction_t *trans, uint8_t cause) trans->repeat = 0; trans->release_cause = cause; trans->cnetz->sched_dsp_mode_ts = -1; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); } /* Receive audio from call instance. */ @@ -621,21 +624,21 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 2. check if the subscriber is attached */ rc = find_db(futln_nat, futln_fuvst, futln_rest, &ogk_kanal, NULL, &extended); if (rc < 0) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call to not attached subscriber, rejecting!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call to not attached subscriber, rejecting!\n"); return -CAUSE_OUTOFORDER; } /* 3. check if given number is already in a call, return BUSY */ trans = search_transaction_number_global(futln_nat, futln_fuvst, futln_rest); if (trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } /* 4. check if we have no OgK, return NOCHANNEL */ ogk = search_ogk(ogk_kanal); if (!ogk) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call, but OgK is currently busy, rejecting!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call, but OgK is currently busy, rejecting!\n"); return -CAUSE_NOCHANNEL; } @@ -643,18 +646,18 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, spk = search_free_spk(extended); if (!spk) { if (!ogk->warteschlange) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } else - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call, but no free channel, queuing call!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call, but no free channel, queuing call!\n"); } - PDEBUG(DCNETZ, DEBUG_INFO, "Call to mobile station, paging station id '%s'\n", dialing); + LOGP(DCNETZ, LOGL_INFO, "Call to mobile station, paging station id '%s'\n", dialing); /* 6. trying to page mobile station */ trans = create_transaction(ogk, (spk) ? TRANS_VAK : TRANS_WSK, futln_nat, futln_fuvst, futln_rest, -1, -1, NAN); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); return -CAUSE_TEMPFAIL; } trans->callref = callref; @@ -677,7 +680,7 @@ void call_down_disconnect(int callref, int cause) cnetz_t *cnetz; transaction_t *trans; - PDEBUG(DCNETZ, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { cnetz = (cnetz_t *) sender; @@ -687,7 +690,7 @@ void call_down_disconnect(int callref, int cause) break; } if (!sender) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -698,13 +701,13 @@ void call_down_disconnect(int callref, int cause) case DSP_MODE_SPK_V: return; case DSP_MODE_SPK_K: - PDEBUG(DCNETZ, DEBUG_INFO, "Call control disconnects on speech channel, releasing towards mobile station.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call control disconnects on speech channel, releasing towards mobile station.\n"); cnetz_release(trans, cnetz_cause_isdn2cnetz(cause)); call_up_release(callref, cause); trans->callref = 0; break; default: - PDEBUG(DCNETZ, DEBUG_INFO, "Call control disconnects on organisation channel, removing transaction.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call control disconnects on organisation channel, removing transaction.\n"); call_up_release(callref, cause); trans->callref = 0; if (trans->state == TRANS_MT_QUEUE || trans->state == TRANS_MT_DELAY) { @@ -724,7 +727,7 @@ void call_down_release(int callref, int cause) cnetz_t *cnetz; transaction_t *trans; - PDEBUG(DCNETZ, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { cnetz = (cnetz_t *) sender; @@ -734,7 +737,7 @@ void call_down_release(int callref, int cause) break; } if (!sender) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -744,11 +747,11 @@ void call_down_release(int callref, int cause) switch (cnetz->dsp_mode) { case DSP_MODE_SPK_K: case DSP_MODE_SPK_V: - PDEBUG(DCNETZ, DEBUG_INFO, "Call control releases on speech channel, releasing towards mobile station.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call control releases on speech channel, releasing towards mobile station.\n"); cnetz_release(trans, cnetz_cause_isdn2cnetz(cause)); break; default: - PDEBUG(DCNETZ, DEBUG_INFO, "Call control releases on organisation channel, removing transaction.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call control releases on organisation channel, removing transaction.\n"); if (trans->state == TRANS_MT_QUEUE) { cnetz_release(trans, cnetz_cause_isdn2cnetz(cause)); } else { @@ -765,12 +768,12 @@ int cnetz_meldeaufruf(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_res cnetz = search_ogk(ogk_kanal); if (!cnetz) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "'Meldeaufruf', but OgK is currently busy!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "'Meldeaufruf', but OgK is currently busy!\n"); return -CAUSE_NOCHANNEL; } trans = create_transaction(cnetz, TRANS_MA, futln_nat, futln_fuvst, futln_rest, -1, -1, NAN); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); return -CAUSE_TEMPFAIL; } @@ -842,13 +845,13 @@ void transaction_timeout(void *data) switch (trans->state) { case TRANS_MT_QUEUE: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Phone in queue, but still no channel available, releasing call!\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Phone in queue, but still no channel available, releasing call!\n"); call_up_release(trans->callref, CAUSE_NOCHANNEL); trans->callref = 0; cnetz_release(trans, CNETZ_CAUSE_GASSENBESETZT); break; case TRANS_MO_QUEUE: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Phone in queue, but still no channel available, releasing!\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Phone in queue, but still no channel available, releasing!\n"); cnetz_release(trans, CNETZ_CAUSE_GASSENBESETZT); break; case TRANS_MT_DELAY: @@ -858,12 +861,12 @@ void transaction_timeout(void *data) trans_new_state(trans, TRANS_VAG); break; case TRANS_BQ: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after channel allocation 'Belegung Quittung'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after channel allocation 'Belegung Quittung'\n"); trans_new_state(trans, TRANS_AF); trans->repeat = 0; break; case TRANS_ZFZ: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after sending random number 'Zufallszahl'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after sending random number 'Zufallszahl'\n"); if (trans->callref) { call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; @@ -871,7 +874,7 @@ void transaction_timeout(void *data) cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); break; case TRANS_AP: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after waiting for challenge response 'Autorisierungsparameter'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after waiting for challenge response 'Autorisierungsparameter'\n"); if (trans->callref) { call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; @@ -881,9 +884,9 @@ void transaction_timeout(void *data) case TRANS_VHQ_K: case TRANS_VHQ_V: if (cnetz->dsp_mode != DSP_MODE_SPK_V) - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response while holding call 'Quittung Verbindung halten'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response while holding call 'Quittung Verbindung halten'\n"); else - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Lost signal from 'FuTln' (mobile station)\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Lost signal from 'FuTln' (mobile station)\n"); if (trans->callref) { call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; @@ -891,25 +894,25 @@ void transaction_timeout(void *data) cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); break; case TRANS_DS: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after connect 'Durchschalten'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after connect 'Durchschalten'\n"); call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); break; case TRANS_RTA: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after ringing order 'Rufton anschalten'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after ringing order 'Rufton anschalten'\n"); call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); break; case TRANS_AHQ: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after answer 'Abhebequittung'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after answer 'Abhebequittung'\n"); call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); break; default: - PDEBUG_CHAN(DCNETZ, DEBUG_ERROR, "Timeout unhandled in state %" PRIu64 "\n", trans->state); + LOGP_CHAN(DCNETZ, LOGL_ERROR, "Timeout unhandled in state %" PRIu64 "\n", trans->state); } } @@ -941,13 +944,13 @@ void cnetz_sync_frame(cnetz_t *cnetz, double sync, int block) } /* if more than +- one bit out of sync */ if (offset < -0.5 || offset > 0.5) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Frame sync offset = %.2f, correcting!\n", offset); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Frame sync offset = %.2f, correcting!\n", offset); fsk_correct_sync(&cnetz->fsk_demod, offset); return; } /* resync by some fraction of received sync error */ - PDEBUG_CHAN(DCNETZ, DEBUG_DEBUG, "Frame sync offset = %.2f, correcting.\n", offset); + LOGP_CHAN(DCNETZ, LOGL_DEBUG, "Frame sync offset = %.2f, correcting.\n", offset); fsk_correct_sync(&cnetz->fsk_demod, offset / 2.0); } @@ -994,18 +997,18 @@ const telegramm_t *cnetz_transmit_telegramm_rufblock(cnetz_t *cnetz) telegramm.ausloesegrund = trans->release_cause; switch (trans->state) { case TRANS_EM: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending acknowledgment 'Einbuchquittung' to Attachment request.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending acknowledgment 'Einbuchquittung' to Attachment request.\n"); telegramm.opcode = OPCODE_EBQ_R; destroy_transaction(trans); break; case TRANS_UM: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending acknowledgment 'Umbuchquittung' to Roaming requuest.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending acknowledgment 'Umbuchquittung' to Roaming requuest.\n"); telegramm.opcode = OPCODE_UBQ_R; destroy_transaction(trans); break; case TRANS_WBN: wbn: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending call reject 'Wahlbestaetigung negativ'.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending call reject 'Wahlbestaetigung negativ'.\n"); telegramm.opcode = OPCODE_WBN_R; destroy_transaction(trans); cnetz_go_idle(cnetz); @@ -1014,17 +1017,17 @@ wbn: spk = search_free_spk(trans->extended); /* Accept call if channel available, otherwise reject or queue call */ if (spk) { - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending call accept 'Wahlbestaetigung positiv'.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending call accept 'Wahlbestaetigung positiv'.\n"); telegramm.opcode = OPCODE_WBP_R; trans_new_state(trans, TRANS_VAG); } else if (cnetz->warteschlange) { /* queue call if no channel is available, but queue allowed */ - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "No free channel, sending call accept in queue 'Wahlbestaetigung positiv in Warteschlage'.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "No free channel, sending call accept in queue 'Wahlbestaetigung positiv in Warteschlage'.\n"); telegramm.opcode = OPCODE_WWBP_R; trans_new_state(trans, TRANS_MO_QUEUE); - timer_start(&trans->timer, T_VAG2); /* Maximum time to hold queue */ + osmo_timer_schedule(&trans->timer, T_VAG2); /* Maximum time to hold queue */ } else { - PDEBUG(DCNETZ, DEBUG_NOTICE, "No free channel anymore, rejecting call!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "No free channel anymore, rejecting call!\n"); trans_new_state(trans, TRANS_WBN); goto wbn; } @@ -1033,27 +1036,27 @@ wbn: case TRANS_VAK: vak: if (trans->state == TRANS_VAG) { - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending channel assignment 'Verbindungsaufbau gehend'.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending channel assignment 'Verbindungsaufbau gehend'.\n"); telegramm.opcode = OPCODE_VAG_R; } else { - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending channel assignment 'Verbindungsaufbau kommend'.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending channel assignment 'Verbindungsaufbau kommend'.\n"); telegramm.opcode = OPCODE_VAK_R; } trans_new_state(trans, TRANS_BQ); trans->repeat = 0; - timer_start(&trans->timer, 0.150 + 0.0375 * F_BQ); /* two slots + F_BQ frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.150 + 0.0375 * F_BQ)); /* two slots + F_BQ frames */ /* select channel */ spk = search_free_spk(trans->extended); if (!spk) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "No free channel anymore, rejecting call!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "No free channel anymore, rejecting call!\n"); destroy_transaction(trans); cnetz_go_idle(cnetz); break; } if (spk == cnetz) { - PDEBUG(DCNETZ, DEBUG_INFO, "Staying on combined control + traffic channel %s\n", spk->sender.kanal); + LOGP(DCNETZ, LOGL_INFO, "Staying on combined control + traffic channel %s\n", spk->sender.kanal); } else { - PDEBUG(DCNETZ, DEBUG_INFO, "Assigning phone to traffic channel %s\n", spk->sender.kanal); + LOGP(DCNETZ, LOGL_INFO, "Assigning phone to traffic channel %s\n", spk->sender.kanal); /* sync RX time to current OgK time */ fsk_copy_sync(&spk->fsk_demod, &cnetz->fsk_demod); } @@ -1071,12 +1074,12 @@ vak: break; case TRANS_ATQ: case TRANS_ATQ_IDLE: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending acknowledgment 'Quittung fuer Ausloesen des FuTelG im OgK-Betrieb' to release request.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending acknowledgment 'Quittung fuer Ausloesen des FuTelG im OgK-Betrieb' to release request.\n"); telegramm.opcode = OPCODE_ATQ_R; destroy_transaction(trans); break; case TRANS_VA: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Vorzeitiges Ausloesen' to queued mobile station\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Vorzeitiges Ausloesen' to queued mobile station\n"); telegramm.opcode = OPCODE_VA_R; destroy_transaction(trans); break; @@ -1087,10 +1090,10 @@ vak: trans_new_state(trans, TRANS_VAK); goto vak; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "No free channel, sending incoming call in queue 'Warteschglange kommend'.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "No free channel, sending incoming call in queue 'Warteschglange kommend'.\n"); telegramm.opcode = OPCODE_WSK_R; trans_new_state(trans, TRANS_MT_QUEUE); - timer_start(&trans->timer, T_VAK); /* Maximum time to hold queue */ + osmo_timer_schedule(&trans->timer, T_VAK); /* Maximum time to hold queue */ call_up_alerting(trans->callref); default: ; /* LR */ @@ -1127,7 +1130,7 @@ next_candidate: switch (trans->state) { case TRANS_WAF: /* no response to dial request (try again or drop connection) */ - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after dialing request 'Wahlaufforderung'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after dialing request 'Wahlaufforderung'\n"); if (trans->try == N) { trans_new_state(trans, TRANS_WBN); goto next_candidate; @@ -1136,7 +1139,7 @@ next_candidate: trans_new_state(trans, TRANS_VWG); /* FALLTHRU */ case TRANS_VWG: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending acknowledgment 'Wahlaufforderung' to outging call\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending acknowledgment 'Wahlaufforderung' to outging call\n"); telegramm.opcode = OPCODE_WAF_M; telegramm.futln_nationalitaet = trans->futln_nat; telegramm.futln_heimat_fuvst_nr = trans->futln_fuvst; @@ -1144,7 +1147,7 @@ next_candidate: trans_new_state(trans, TRANS_WAF); break; case TRANS_MA: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending keepalive request 'Meldeaufruf'\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending keepalive request 'Meldeaufruf'\n"); telegramm.opcode = OPCODE_MA_M; telegramm.futln_nationalitaet = trans->futln_nat; telegramm.futln_heimat_fuvst_nr = trans->futln_fuvst; @@ -1153,7 +1156,7 @@ next_candidate: break; case TRANS_MFT: /* no response to availability check */ - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "No response after keepalive order 'Meldeaufruf'\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "No response after keepalive order 'Meldeaufruf'\n"); trans->page_failed = 1; destroy_transaction(trans); goto next_candidate; @@ -1178,18 +1181,18 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo break; rufnummer = telegramm2rufnummer(telegramm); if (si.authentifikationsbit && telegramm->chipkarten_futelg_bit) - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received Attachment 'Einbuchen' message from Subscriber '%s' with chip card's ID %d (vendor id %d, hardware version %d, software version %d)\n", rufnummer, telegramm->kartenkennung, telegramm->herstellerkennung, telegramm->hardware_des_futelg, telegramm->software_des_futelg); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received Attachment 'Einbuchen' message from Subscriber '%s' with chip card's ID %d (vendor id %d, hardware version %d, software version %d)\n", rufnummer, telegramm->kartenkennung, telegramm->herstellerkennung, telegramm->hardware_des_futelg, telegramm->software_des_futelg); else - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received Attachment 'Einbuchen' message from Subscriber '%s' with %s card's security code %d\n", rufnummer, (telegramm->chipkarten_futelg_bit) ? "chip":"magnet", telegramm->sicherungs_code); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received Attachment 'Einbuchen' message from Subscriber '%s' with %s card's security code %d\n", rufnummer, (telegramm->chipkarten_futelg_bit) ? "chip":"magnet", telegramm->sicherungs_code); if (telegramm->erweitertes_frequenzbandbit) - PDEBUG(DCNETZ, DEBUG_INFO, " -> Phone supports extended frequency band\n"); + LOGP(DCNETZ, LOGL_INFO, " -> Phone supports extended frequency band\n"); if (cnetz->state != CNETZ_IDLE) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Ignoring Attachment from subscriber '%s', because we are busy becoming SpK.\n", rufnummer); + LOGP(DCNETZ, LOGL_NOTICE, "Ignoring Attachment from subscriber '%s', because we are busy becoming SpK.\n", rufnummer); break; } trans = create_transaction(cnetz, TRANS_EM, telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr, telegramm->chipkarten_futelg_bit, telegramm->erweitertes_frequenzbandbit, cnetz->rf_level_db); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); break; } cnetz = trans->cnetz; /* cnetz may change, due to stronger reception on different OgK */ @@ -1200,18 +1203,18 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo break; rufnummer = telegramm2rufnummer(telegramm); if (si.authentifikationsbit && telegramm->chipkarten_futelg_bit) - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received Roaming 'Umbuchen' message from Subscriber '%s' with chip card's ID %d (vendor id %d, hardware version %d, software version %d)\n", rufnummer, telegramm->kartenkennung, telegramm->herstellerkennung, telegramm->hardware_des_futelg, telegramm->software_des_futelg); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received Roaming 'Umbuchen' message from Subscriber '%s' with chip card's ID %d (vendor id %d, hardware version %d, software version %d)\n", rufnummer, telegramm->kartenkennung, telegramm->herstellerkennung, telegramm->hardware_des_futelg, telegramm->software_des_futelg); else - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received Roaming 'Umbuchen' message from Subscriber '%s' with %s card's security code %d\n", rufnummer, (telegramm->chipkarten_futelg_bit) ? "chip":"magnet", telegramm->sicherungs_code); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received Roaming 'Umbuchen' message from Subscriber '%s' with %s card's security code %d\n", rufnummer, (telegramm->chipkarten_futelg_bit) ? "chip":"magnet", telegramm->sicherungs_code); if (telegramm->erweitertes_frequenzbandbit) - PDEBUG(DCNETZ, DEBUG_INFO, " -> Phone supports extended frequency band\n"); + LOGP(DCNETZ, LOGL_INFO, " -> Phone supports extended frequency band\n"); if (cnetz->state != CNETZ_IDLE) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Ignoring Roaming from subscriber '%s', because we are busy becoming SpK.\n", rufnummer); + LOGP(DCNETZ, LOGL_NOTICE, "Ignoring Roaming from subscriber '%s', because we are busy becoming SpK.\n", rufnummer); break; } trans = create_transaction(cnetz, TRANS_UM, telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr, telegramm->chipkarten_futelg_bit, telegramm->erweitertes_frequenzbandbit, cnetz->rf_level_db); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); break; } cnetz = trans->cnetz; /* cnetz may change, due to stronger reception on different OgK */ @@ -1222,7 +1225,7 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo if (!match_fuz(telegramm)) break; rufnummer = telegramm2rufnummer(telegramm); - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received Roaming request 'Umbuchantrag' message from Subscriber '%s' on queue\n", rufnummer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received Roaming request 'Umbuchantrag' message from Subscriber '%s' on queue\n", rufnummer); break; case OPCODE_VWG_R: case OPCODE_SRG_R: @@ -1231,18 +1234,18 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo break; rufnummer = telegramm2rufnummer(telegramm); if (opcode == OPCODE_VWG_R) - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received outgoing Call 'Verbindungswunsch gehend' message from Subscriber '%s'\n", rufnummer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received outgoing Call 'Verbindungswunsch gehend' message from Subscriber '%s'\n", rufnummer); else if (opcode == OPCODE_SRG_R) - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received outgoing emergency Call 'Sonderruf gehend' message from Subscriber '%s'\n", rufnummer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received outgoing emergency Call 'Sonderruf gehend' message from Subscriber '%s'\n", rufnummer); else - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received outgoing Call 'Verbindungswunsch gehend bei Nachbarschaftsunterstuetzung' message from Subscriber '%s'\n", rufnummer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received outgoing Call 'Verbindungswunsch gehend bei Nachbarschaftsunterstuetzung' message from Subscriber '%s'\n", rufnummer); if (cnetz->state != CNETZ_IDLE) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Ignoring Call from subscriber '%s', because we are busy becoming SpK.\n", rufnummer); + LOGP(DCNETZ, LOGL_NOTICE, "Ignoring Call from subscriber '%s', because we are busy becoming SpK.\n", rufnummer); break; } trans = create_transaction(cnetz, TRANS_VWG, telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr, -1, telegramm->erweitertes_frequenzbandbit, cnetz->rf_level_db); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); break; } cnetz = trans->cnetz; /* cnetz may change, due to stronger reception on different OgK */ @@ -1252,13 +1255,13 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo case OPCODE_WUE_M: trans = search_transaction(cnetz, TRANS_WAF | TRANS_WBP | TRANS_VAG | TRANS_MO_QUEUE); if (!trans) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received dialing digits 'Wahluebertragung' message without transaction (on this OgK), ignoring!\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received dialing digits 'Wahluebertragung' message without transaction (on this OgK), ignoring!\n"); break; } rufnummer = transaction2rufnummer(trans); strncpy(trans->dialing, telegramm->wahlziffern, sizeof(trans->dialing) - 1); - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received dialing digits 'Wahluebertragung' message from Subscriber '%s' to Number '%s'\n", rufnummer, trans->dialing); - timer_stop(&trans->timer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received dialing digits 'Wahluebertragung' message from Subscriber '%s' to Number '%s'\n", rufnummer, trans->dialing); + osmo_timer_del(&trans->timer); trans_new_state(trans, TRANS_WBP); trans->try = 1; /* try */ valid_frame = 1; @@ -1267,31 +1270,31 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo if (!match_fuz(telegramm)) break; rufnummer = telegramm2rufnummer(telegramm); - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received release 'Ausloesen des FuTelG im OgK-Betrieb bei WS' message from Subscriber '%s'\n", rufnummer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received release 'Ausloesen des FuTelG im OgK-Betrieb bei WS' message from Subscriber '%s'\n", rufnummer); trans = search_transaction_number_global(telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr); if (!trans) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "There is no transaction, so we assume that the phone did not receive previous release.\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "There is no transaction, so we assume that the phone did not receive previous release.\n"); /* create transaction, in case the phone repeats the release after we have acked it */ trans = create_transaction(cnetz, TRANS_ATQ_IDLE, telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr, -1, -1, cnetz->rf_level_db); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); break; } cnetz = trans->cnetz; /* cnetz may change, due to stronger reception on different OgK */ } else { if (cnetz == trans->cnetz) { - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); trans_new_state(trans, TRANS_ATQ); } else if (trans->state == TRANS_ATQ_IDLE) { trans = create_transaction(cnetz, TRANS_ATQ_IDLE, telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr, -1, -1, cnetz->rf_level_db); if (!trans) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to create transaction\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to create transaction\n"); break; } cnetz = trans->cnetz; /* cnetz may change, due to stronger reception on different OgK */ } else - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received release 'Ausloesen des FuTelG im OgK-Betrieb bei WS' message without transaction (on this OgK), ignoring!\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received release 'Ausloesen des FuTelG im OgK-Betrieb bei WS' message without transaction (on this OgK), ignoring!\n"); } valid_frame = 1; break; @@ -1300,16 +1303,16 @@ void cnetz_receive_telegramm_ogk(cnetz_t *cnetz, telegramm_t *telegramm, int blo break; trans = search_transaction_number(cnetz, telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr); if (!trans) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received acknowledge 'Meldung Funktelefonteilnehmer' message without transaction (on this OgK), ignoring!\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received acknowledge 'Meldung Funktelefonteilnehmer' message without transaction (on this OgK), ignoring!\n"); break; } rufnummer = transaction2rufnummer(trans); - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received acknowledge 'Meldung Funktelefonteilnehmer' message from Subscriber '%s'\n", rufnummer); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received acknowledge 'Meldung Funktelefonteilnehmer' message from Subscriber '%s'\n", rufnummer); destroy_transaction(trans); valid_frame = 1; break; default: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received unexpected Telegramm (opcode %d = %s)\n", opcode, telegramm_name(opcode)); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received unexpected Telegramm (opcode %d = %s)\n", opcode, telegramm_name(opcode)); } if (cnetz->sender.loopback) { @@ -1355,89 +1358,89 @@ const telegramm_t *cnetz_transmit_telegramm_spk_k(cnetz_t *cnetz) switch (trans->state) { case TRANS_BQ: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Belegungsquittung' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Belegungsquittung' on traffic channel\n"); telegramm.opcode = OPCODE_BQ_K; - if (++trans->repeat >= 8 && !timer_running(&trans->timer)) { + if (++trans->repeat >= 8 && !osmo_timer_pending(&trans->timer)) { if (cnetz->challenge_valid) { if (si.authentifikationsbit == 0) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Cannot authenticate, because base station does not support it. (Authentication disabled in sysinfo.)\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Cannot authenticate, because base station does not support it. (Authentication disabled in sysinfo.)\n"); goto no_auth; } if (trans->futelg_bit == 0) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Cannot authenticate, because mobile station does not support it. (Mobile station has magnetic card.)\n"); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Cannot authenticate, because mobile station does not support it. (Mobile station has magnetic card.)\n"); goto no_auth; } - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Perform authentication with subscriber's card, use challenge: 0x%016" PRIx64 "\n", telegramm.zufallszahl); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Perform authentication with subscriber's card, use challenge: 0x%016" PRIx64 "\n", telegramm.zufallszahl); trans_new_state(trans, TRANS_ZFZ); - timer_start(&trans->timer, 0.0375 * F_ZFZ); /* F_ZFZ frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.0375 * F_ZFZ)); /* F_ZFZ frames */ } else { no_auth: trans_new_state(trans, TRANS_VHQ_K); - timer_start(&trans->timer, 0.0375 * F_VHQK); /* F_VHQK frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.0375 * F_VHQK)); /* F_VHQK frames */ } trans->repeat = 0; } break; case TRANS_ZFZ: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Zufallszahl' on traffic channel (0x%016" PRIx64 ").\n", telegramm.zufallszahl); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Zufallszahl' on traffic channel (0x%016" PRIx64 ").\n", telegramm.zufallszahl); telegramm.opcode = OPCODE_ZFZ_K; break; case TRANS_AP: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Quittung Verbindung halten' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Quittung Verbindung halten' on traffic channel\n"); telegramm.opcode = OPCODE_VHQ_K; break; case TRANS_VHQ_K: if (!cnetz->sender.loopback) - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Quittung Verbindung halten' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Quittung Verbindung halten' on traffic channel\n"); telegramm.opcode = OPCODE_VHQ_K; /* continue until next sub frame, so we send DS from first block of next sub frame. */ - if (!cnetz->sender.loopback && (cnetz->sched_ts & 7) == 7 && cnetz->sched_r_m && !timer_running(&trans->timer)) { + if (!cnetz->sender.loopback && (cnetz->sched_ts & 7) == 7 && cnetz->sched_r_m && !osmo_timer_pending(&trans->timer)) { /* next sub frame */ if (trans->mo_call) { trans->callref = call_up_setup(transaction2rufnummer(trans), trans->dialing, OSMO_CC_NETWORK_CNETZ_NONE, ""); trans_new_state(trans, TRANS_DS); trans->repeat = 0; - timer_start(&trans->timer, 0.0375 * F_DS); /* F_DS frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.0375 * F_DS)); /* F_DS frames */ } if (trans->mt_call) { trans_new_state(trans, TRANS_RTA); - timer_start(&trans->timer, 0.0375 * F_RTA); /* F_RTA frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.0375 * F_RTA)); /* F_RTA frames */ trans->repeat = 0; call_up_alerting(trans->callref); } } break; case TRANS_DS: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Durchschalten' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Durchschalten' on traffic channel\n"); telegramm.opcode = OPCODE_DSB_K; /* send exactly a sub frame (8 time slots) */ - if ((cnetz->sched_ts & 7) == 7 && cnetz->sched_r_m && !timer_running(&trans->timer)) { + if ((cnetz->sched_ts & 7) == 7 && cnetz->sched_r_m && !osmo_timer_pending(&trans->timer)) { /* next sub frame */ trans_new_state(trans, TRANS_VHQ_V); trans->repeat = 0; cnetz_set_sched_dsp_mode(cnetz, DSP_MODE_SPK_V, (cnetz->sched_ts + 1) & 31); #ifndef DEBUG_SPK - timer_start(&trans->timer, 0.075 + 0.6 * F_VHQ); /* one slot + F_VHQ frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.075 + 0.6 * F_VHQ)); /* one slot + F_VHQ frames */ #endif } break; case TRANS_RTA: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Rufton anschalten' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Rufton anschalten' on traffic channel\n"); telegramm.opcode = OPCODE_RTA_K; break; case TRANS_AHQ: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Abhebe Quittung' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Abhebe Quittung' on traffic channel\n"); telegramm.opcode = OPCODE_AHQ_K; if ((cnetz->sched_ts & 7) == 7 && cnetz->sched_r_m) { /* next sub frame */ trans_new_state(trans, TRANS_VHQ_V); trans->repeat = 0; cnetz_set_sched_dsp_mode(cnetz, DSP_MODE_SPK_V, (cnetz->sched_ts + 1) & 31); - timer_start(&trans->timer, 0.075 + 0.6 * F_VHQ); /* one slot + F_VHQ frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.075 + 0.6 * F_VHQ)); /* one slot + F_VHQ frames */ } break; case TRANS_AF: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Ausloesen durch FuFSt' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Ausloesen durch FuFSt' on traffic channel\n"); telegramm.opcode = OPCODE_AF_K; if (++trans->repeat < N_AFKT) break; @@ -1448,7 +1451,7 @@ no_auth: break; } if (trans->try == N) { - PDEBUG(DCNETZ, DEBUG_INFO, "Maximum retries, removing transaction\n"); + LOGP(DCNETZ, LOGL_INFO, "Maximum retries, removing transaction\n"); /* no response to incomming call */ trans->page_failed = 1; cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); @@ -1466,12 +1469,12 @@ no_auth: /* alloc ogk again */ rc = find_db(trans->futln_nat, trans->futln_fuvst, trans->futln_rest, &ogk_kanal, NULL, NULL); if (rc < 0) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Cannot find subscriber in database anymore, releasing!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Cannot find subscriber in database anymore, releasing!\n"); goto no_ogk; } ogk = search_ogk(ogk_kanal); if (!ogk) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Cannot retry, because currently no OgK available (busy)\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Cannot retry, because currently no OgK available (busy)\n"); no_ogk: cnetz_release(trans, CNETZ_CAUSE_FUNKTECHNISCH); if (trans->callref) @@ -1480,7 +1483,7 @@ no_ogk: destroy_transaction(trans); break; } - PDEBUG(DCNETZ, DEBUG_INFO, "Retry to assign channel.\n"); + LOGP(DCNETZ, LOGL_INFO, "Retry to assign channel.\n"); /* attach call to OgK */ link_transaction(trans, ogk); /* change state */ @@ -1491,7 +1494,7 @@ no_ogk: trans->try++; break; case TRANS_AT: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Auslosen durch FuFst' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Auslosen durch FuFst' on traffic channel\n"); telegramm.opcode = OPCODE_AF_K; if (++trans->repeat == 1) { destroy_transaction(trans); @@ -1521,11 +1524,11 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) if (!match_futln(telegramm, trans->futln_nat, trans->futln_fuvst, trans->futln_rest)) { break; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received allocation 'Belegung' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received allocation 'Belegung' message.\n"); valid_frame = 1; if (trans->state != TRANS_BQ) break; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); trans->try = 0; break; case OPCODE_DSQ_K: @@ -1535,35 +1538,35 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) if (!match_futln(telegramm, trans->futln_nat, trans->futln_fuvst, trans->futln_rest)) { break; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received assignment confirm 'Durchschaltung Quittung' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received assignment confirm 'Durchschaltung Quittung' message.\n"); valid_frame = 1; if (trans->state != TRANS_DS) break; cnetz->scrambler = telegramm->betriebs_art; cnetz->scrambler_switch = 0; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); break; case OPCODE_ZFZQ_K: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received random number acknowledge 'Zufallszahlquittung' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received random number acknowledge 'Zufallszahlquittung' message.\n"); valid_frame = 1; if (trans->state != TRANS_ZFZ) break; if (cnetz->challenge != telegramm->zufallszahl) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received random number acknowledge (0x%016" PRIx64 ") does not match the transmitted one (0x%016" PRIx64 "), ignoring!\n", telegramm->zufallszahl, cnetz->challenge); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received random number acknowledge (0x%016" PRIx64 ") does not match the transmitted one (0x%016" PRIx64 "), ignoring!\n", telegramm->zufallszahl, cnetz->challenge); break; } - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); trans_new_state(trans, TRANS_AP); - timer_start(&trans->timer, T_AP); /* 750 milliseconds */ + osmo_timer_schedule(&trans->timer, T_AP); /* 750 milliseconds */ break; case OPCODE_AP_K: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received challenge response 'Autorisierungsparameter' message (0x%016" PRIx64 ").\n", telegramm->authorisierungsparameter); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received challenge response 'Autorisierungsparameter' message (0x%016" PRIx64 ").\n", telegramm->authorisierungsparameter); valid_frame = 1; if (trans->state != TRANS_AP) break; /* if authentication response from card does not match */ if (cnetz->response_valid && telegramm->authorisierungsparameter != cnetz->response) { - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received challenge response (0x%016" PRIx64 ") does not match the expected one (0x%016" PRIx64 "), releasing!\n", telegramm->authorisierungsparameter, cnetz->response); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received challenge response (0x%016" PRIx64 ") does not match the expected one (0x%016" PRIx64 "), releasing!\n", telegramm->authorisierungsparameter, cnetz->response); if (trans->callref) { call_up_release(trans->callref, CAUSE_TEMPFAIL); /* jolly guesses that */ trans->callref = 0; @@ -1571,10 +1574,10 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) cnetz_release(trans, CNETZ_CAUSE_GASSENBESETZT); /* when authentication is not valid */ break; } - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Completed authentication with subscriber's card, challenge response: 0x%016" PRIx64 "\n", telegramm->authorisierungsparameter); - timer_stop(&trans->timer); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Completed authentication with subscriber's card, challenge response: 0x%016" PRIx64 "\n", telegramm->authorisierungsparameter); + osmo_timer_del(&trans->timer); trans_new_state(trans, TRANS_VHQ_K); - timer_start(&trans->timer, 0.0375 * F_VHQK); /* F_VHQK frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.0375 * F_VHQK)); /* F_VHQK frames */ break; case OPCODE_VH_K: if (!match_fuz(telegramm)) { @@ -1583,11 +1586,11 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) if (!match_futln(telegramm, trans->futln_nat, trans->futln_fuvst, trans->futln_rest)) { break; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received connection hold 'Verbindung halten' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received connection hold 'Verbindung halten' message.\n"); valid_frame = 1; if (trans->state != TRANS_VHQ_K) break; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); break; case OPCODE_RTAQ_K: if (!match_fuz(telegramm)) { @@ -1597,10 +1600,10 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) break; } valid_frame = 1; - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received ringback 'Rufton anschalten Quittung' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received ringback 'Rufton anschalten Quittung' message.\n"); if (trans->state != TRANS_RTA) break; - timer_start(&trans->timer, 0.0375 * F_RTA); /* F_RTA frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.0375 * F_RTA)); /* F_RTA frames */ break; case OPCODE_AH_K: if (!match_fuz(telegramm)) { @@ -1609,7 +1612,7 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) if (!match_futln(telegramm, trans->futln_nat, trans->futln_fuvst, trans->futln_rest)) { break; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received answer frame 'Abheben' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received answer frame 'Abheben' message.\n"); valid_frame = 1; /* if already received this frame, or if we are already on VHQ or if we are releasing */ if (trans->state == TRANS_AHQ || trans->state == TRANS_VHQ_K || trans->state == TRANS_VHQ_V || trans->state == TRANS_AF) @@ -1618,7 +1621,7 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) cnetz->scrambler_switch = 0; trans_new_state(trans, TRANS_AHQ); trans->repeat = 0; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); call_up_answer(trans->callref, transaction2rufnummer(trans)); break; case OPCODE_AT_K: @@ -1628,21 +1631,21 @@ void cnetz_receive_telegramm_spk_k(cnetz_t *cnetz, telegramm_t *telegramm) if (!match_futln(telegramm, trans->futln_nat, trans->futln_fuvst, trans->futln_rest)) { break; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received release frame 'Ausloesen durch FuTln' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received release frame 'Ausloesen durch FuTln' message.\n"); valid_frame = 1; /* if already received this frame, if we are releasing */ if (trans->state == TRANS_AT || trans->state == TRANS_AF) break; trans_new_state(trans, TRANS_AT); trans->repeat = 0; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); if (trans->callref) { call_up_release(trans->callref, CAUSE_NORMAL); trans->callref = 0; } break; default: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received unexpected Telegramm (opcode %d = %s)\n", opcode, telegramm_name(opcode)); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received unexpected Telegramm (opcode %d = %s)\n", opcode, telegramm_name(opcode)); } if (valid_frame) @@ -1687,15 +1690,15 @@ const telegramm_t *cnetz_transmit_telegramm_spk_v(cnetz_t *cnetz) switch (trans->state) { case TRANS_VHQ_V: if ((cnetz->sched_ts & 8) == 0) { /* sub frame 1 and 3 */ - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Quittung Verbindung halten 1' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Quittung Verbindung halten 1' on traffic channel\n"); telegramm.opcode = OPCODE_VHQ1_V; } else { /* sub frame 2 and 4 */ - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Quittung Verbindung halten 2' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Quittung Verbindung halten 2' on traffic channel\n"); telegramm.opcode = OPCODE_VHQ2_V; } break; case TRANS_AF: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending 'Ausloesen durch FuFSt' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending 'Ausloesen durch FuFSt' on traffic channel\n"); telegramm.opcode = OPCODE_AF_V; if (++trans->repeat == N_AFV) { destroy_transaction(trans); @@ -1703,7 +1706,7 @@ const telegramm_t *cnetz_transmit_telegramm_spk_v(cnetz_t *cnetz) } break; case TRANS_AT: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Sending acknowledge to 'Ausloesen durch FuTln' on traffic channel\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Sending acknowledge to 'Ausloesen durch FuTln' on traffic channel\n"); telegramm.opcode = OPCODE_AF_V; if (++trans->repeat == 1) { destroy_transaction(trans); @@ -1737,16 +1740,16 @@ void cnetz_receive_telegramm_spk_v(cnetz_t *cnetz, telegramm_t *telegramm) } if (trans->state != TRANS_VHQ_V) break; - timer_start(&trans->timer, 0.6 * F_VHQ); /* F_VHQ frames */ + osmo_timer_schedule(&trans->timer, FLOAT_TO_TIMEOUT(0.6 * F_VHQ)); /* F_VHQ frames */ switch (opcode) { case OPCODE_VH_V: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received supervisory frame 'Verbindung halten' message%s.\n", (telegramm->test_telefonteilnehmer_geraet) ? ", phone is a test-phone" : ""); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received supervisory frame 'Verbindung halten' message%s.\n", (telegramm->test_telefonteilnehmer_geraet) ? ", phone is a test-phone" : ""); break; case OPCODE_USAI_V: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received internal handover request frame 'Umschaltantrag intern' message%s.\n", (telegramm->test_telefonteilnehmer_geraet) ? ", phone is a test-phone" : ""); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received internal handover request frame 'Umschaltantrag intern' message%s.\n", (telegramm->test_telefonteilnehmer_geraet) ? ", phone is a test-phone" : ""); break; case OPCODE_USAE_V: - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received external handover request frame 'Umschaltantrag extern' message%s.\n", (telegramm->test_telefonteilnehmer_geraet) ? ", phone is a test-phone" : ""); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received external handover request frame 'Umschaltantrag extern' message%s.\n", (telegramm->test_telefonteilnehmer_geraet) ? ", phone is a test-phone" : ""); break; } valid_frame = 1; @@ -1767,21 +1770,21 @@ void cnetz_receive_telegramm_spk_v(cnetz_t *cnetz, telegramm_t *telegramm) if (!match_futln(telegramm, trans->futln_nat, trans->futln_fuvst, trans->futln_rest)) { break; } - PDEBUG_CHAN(DCNETZ, DEBUG_INFO, "Received release frame 'Ausloesen durch FuTln' message.\n"); + LOGP_CHAN(DCNETZ, LOGL_INFO, "Received release frame 'Ausloesen durch FuTln' message.\n"); valid_frame = 1; /* if already received this frame, if we are releasing */ if (trans->state == TRANS_AT || trans->state == TRANS_AF) break; trans_new_state(trans, TRANS_AT); trans->repeat = 0; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); if (trans->callref) { call_up_release(trans->callref, CAUSE_NORMAL); trans->callref = 0; } break; default: - PDEBUG_CHAN(DCNETZ, DEBUG_NOTICE, "Received unexpected Telegramm (opcode %d = %s)\n", opcode, telegramm_name(opcode)); + LOGP_CHAN(DCNETZ, LOGL_NOTICE, "Received unexpected Telegramm (opcode %d = %s)\n", opcode, telegramm_name(opcode)); } if (valid_frame) diff --git a/src/cnetz/cnetz.h b/src/cnetz/cnetz.h index 2033907..5cba73a 100644 --- a/src/cnetz/cnetz.h +++ b/src/cnetz/cnetz.h @@ -1,5 +1,5 @@ #include "../libcompandor/compandor.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../libmobile/sender.h" #include "../libscrambler/scrambler.h" typedef struct cnetz cnetz_t; @@ -40,9 +40,9 @@ enum cnetz_state { #define N_AFKT 6 /* number of release frames to send during concentrated signaling */ #define N_AFV 4 /* number of release frames to send during distributed signaling */ #define N 3 /* now many times we repeat a message on OgK */ -#define T_VAG2 180 /* time on outgoing queue */ -#define T_VAK 60 /* time on incoming queue */ -#define T_AP 750 /* Time to wait for SIM card's authentication reply */ +#define T_VAG2 180,0 /* time on outgoing queue */ +#define T_VAK 60,0 /* time on incoming queue */ +#define T_AP 0,750000 /* Time to wait for SIM card's authentication reply */ /* clear causes */ #define CNETZ_CAUSE_GASSENBESETZT 0 /* network congested */ diff --git a/src/cnetz/database.c b/src/cnetz/database.c index 0046973..4bdfb2c 100644 --- a/src/cnetz/database.c +++ b/src/cnetz/database.c @@ -22,7 +22,8 @@ #include <stdlib.h> #include <string.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" +#include "../libmobile/get_time.h" #include "cnetz.h" #include "database.h" #include "sysinfo.h" @@ -45,7 +46,7 @@ typedef struct cnetz_database { int eingebucht; /* set if still available */ double last_seen; int busy; /* set if currently in a call */ - struct timer timer; /* timer for next availability check */ + struct osmo_timer_list timer; /* timer for next availability check */ int retry; /* counts number of retries */ } cnetz_db_t; @@ -72,14 +73,14 @@ static void remove_db(cnetz_db_t *db) while (*dbp && *dbp != db) dbp = &((*dbp)->next); if (!(*dbp)) { - PDEBUG(DDB, DEBUG_ERROR, "Subscriber not in list, please fix!!\n"); + LOGP(DDB, LOGL_ERROR, "Subscriber not in list, please fix!!\n"); abort(); } *dbp = db->next; - PDEBUG(DDB, DEBUG_INFO, "Removing subscriber '%d,%d,%05d' from database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_INFO, "Removing subscriber '%d,%d,%05d' from database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); - timer_exit(&db->timer); + osmo_timer_del(&db->timer); free(db); } @@ -90,15 +91,15 @@ static void db_timeout(void *data) cnetz_db_t *db = data; int rc; - PDEBUG(DDB, DEBUG_INFO, "Check, if subscriber '%d,%d,%05d' is still available.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_INFO, "Check, if subscriber '%d,%d,%05d' is still available.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); rc = cnetz_meldeaufruf(db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal); if (rc < 0) { /* OgK is used for speech, but this never happens in a real * network. We just assume that the phone has responded and * assume we had a response. */ - PDEBUG(DDB, DEBUG_INFO, "OgK busy, so we assume a positive response.\n"); - timer_start(&db->timer, si.meldeinterval); /* when to check avaiability again */ + LOGP(DDB, LOGL_INFO, "OgK busy, so we assume a positive response.\n"); + osmo_timer_schedule(&db->timer, si.meldeinterval,0); /* when to check avaiability again */ db->retry = 0; } } @@ -120,10 +121,10 @@ int update_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_rest, int o if (!db) { db = calloc(1, sizeof(*db)); if (!db) { - PDEBUG(DDB, DEBUG_ERROR, "No memory!\n"); + LOGP(DDB, LOGL_ERROR, "No memory!\n"); return 0; } - timer_init(&db->timer, db_timeout, db); + osmo_timer_setup(&db->timer, db_timeout, db); db->eingebucht = 1; db->futln_nat = futln_nat; @@ -136,7 +137,7 @@ int update_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_rest, int o dbp = &((*dbp)->next); *dbp = db; - PDEBUG(DDB, DEBUG_INFO, "Adding subscriber '%d,%d,%05d' to database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_INFO, "Adding subscriber '%d,%d,%05d' to database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); } if (ogk_kanal) @@ -150,23 +151,23 @@ int update_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_rest, int o db->busy = busy; if (busy) { - PDEBUG(DDB, DEBUG_INFO, "Subscriber '%d,%d,%05d' on OGK channel #%d is busy now.\n", db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal); - timer_stop(&db->timer); + LOGP(DDB, LOGL_INFO, "Subscriber '%d,%d,%05d' on OGK channel #%d is busy now.\n", db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal); + osmo_timer_del(&db->timer); } else if (!failed) { - PDEBUG(DDB, DEBUG_INFO, "Subscriber '%d,%d,%05d' on OGK channel #%d is idle now.\n", db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal); - timer_start(&db->timer, si.meldeinterval); /* when to check avaiability (again) */ + LOGP(DDB, LOGL_INFO, "Subscriber '%d,%d,%05d' on OGK channel #%d is idle now.\n", db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal); + osmo_timer_schedule(&db->timer, si.meldeinterval,0); /* when to check avaiability (again) */ db->retry = 0; db->eingebucht = 1; db->last_seen = get_time(); } else { db->retry++; - PDEBUG(DDB, DEBUG_NOTICE, "Paging subscriber '%d,%d,%05d' on OGK channel #%d failed (try %d of %s).\n", db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal, db->retry, print_meldeaufrufe(si.meldeaufrufe)); + LOGP(DDB, LOGL_NOTICE, "Paging subscriber '%d,%d,%05d' on OGK channel #%d failed (try %d of %s).\n", db->futln_nat, db->futln_fuvst, db->futln_rest, db->ogk_kanal, db->retry, print_meldeaufrufe(si.meldeaufrufe)); if (si.meldeaufrufe && db->retry == si.meldeaufrufe) { - PDEBUG(DDB, DEBUG_INFO, "Marking subscriber as gone.\n"); + LOGP(DDB, LOGL_INFO, "Marking subscriber as gone.\n"); db->eingebucht = 0; return db->extended; } - timer_start(&db->timer, (si.meldeinterval < MELDE_WIEDERHOLUNG) ? si.meldeinterval : MELDE_WIEDERHOLUNG); /* when to do retry */ + osmo_timer_schedule(&db->timer, (si.meldeinterval < MELDE_WIEDERHOLUNG) ? si.meldeinterval : MELDE_WIEDERHOLUNG,0); /* when to do retry */ } if (futelg_bit) @@ -211,18 +212,18 @@ void dump_db(void) int last; char attached[16]; - PDEBUG(DDB, DEBUG_NOTICE, "Dump of subscriber database:\n"); + LOGP(DDB, LOGL_NOTICE, "Dump of subscriber database:\n"); if (!db) { - PDEBUG(DDB, DEBUG_NOTICE, " - No subscribers attached!\n"); + LOGP(DDB, LOGL_NOTICE, " - No subscribers attached!\n"); return; } - PDEBUG(DDB, DEBUG_NOTICE, "Subscriber\tAttached\tBusy\t\tLast seen\tMeldeaufrufe\n"); - PDEBUG(DDB, DEBUG_NOTICE, "-------------------------------------------------------------------------------\n"); + LOGP(DDB, LOGL_NOTICE, "Subscriber\tAttached\tBusy\t\tLast seen\tMeldeaufrufe\n"); + LOGP(DDB, LOGL_NOTICE, "-------------------------------------------------------------------------------\n"); while (db) { last = (db->busy) ? 0 : (uint32_t)(now - db->last_seen); sprintf(attached, "YES (OGK %d)", db->ogk_kanal); - PDEBUG(DDB, DEBUG_NOTICE, "%d,%d,%05d\t%s\t%s\t\t%02d:%02d:%02d \t%d/%s\n", db->futln_nat, db->futln_fuvst, db->futln_rest, (db->eingebucht) ? attached : "-no-\t", (db->busy) ? "YES" : "-no-", last / 3600, (last / 60) % 60, last % 60, db->retry, print_meldeaufrufe(si.meldeaufrufe)); + LOGP(DDB, LOGL_NOTICE, "%d,%d,%05d\t%s\t%s\t\t%02d:%02d:%02d \t%d/%s\n", db->futln_nat, db->futln_fuvst, db->futln_rest, (db->eingebucht) ? attached : "-no-\t", (db->busy) ? "YES" : "-no-", last / 3600, (last / 60) % 60, last % 60, db->retry, print_meldeaufrufe(si.meldeaufrufe)); db = db->next; } } diff --git a/src/cnetz/dsp.c b/src/cnetz/dsp.c index 4d5e518..33ea019 100644 --- a/src/cnetz/dsp.c +++ b/src/cnetz/dsp.c @@ -26,8 +26,9 @@ #include <math.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" +#include "../libmobile/get_time.h" #include "cnetz.h" #include "sysinfo.h" #include "telegramm.h" @@ -84,7 +85,7 @@ static void dsp_init_ramp(cnetz_t *cnetz) double c; int i; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating smooth ramp table.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating smooth ramp table.\n"); for (i = 0; i < 256; i++) { /* use square-root of cosine ramp. tests showed that phones are more * happy with that. (This is not correct pulse shaping!) */ @@ -104,7 +105,7 @@ int dsp_init_sender(cnetz_t *cnetz, int measure_speed, double clock_speed[2], en int rc = 0; double size; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init FSK for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init FSK for 'Sender'.\n"); /* set modulation parameters */ sender_set_fm(&cnetz->sender, MAX_DEVIATION, MAX_MODULATION, speech_deviation, MAX_DISPLAY); @@ -115,20 +116,20 @@ int dsp_init_sender(cnetz_t *cnetz, int measure_speed, double clock_speed[2], en } if (clock_speed[0] > 1000 || clock_speed[0] < -1000 || clock_speed[1] > 1000 || clock_speed[1] < -1000) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Clock speed %.1f,%.1f ppm out of range! Please use range between +-1000 ppm!\n", clock_speed[0], clock_speed[1]); + LOGP_CHAN(DDSP, LOGL_ERROR, "Clock speed %.1f,%.1f ppm out of range! Please use range between +-1000 ppm!\n", clock_speed[0], clock_speed[1]); return -EINVAL; } - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Using clock speed of %.1f ppm (RX) and %.1f ppm (TX) to correct sound card's clock.\n", clock_speed[0], clock_speed[1]); + LOGP_CHAN(DDSP, LOGL_INFO, "Using clock speed of %.1f ppm (RX) and %.1f ppm (TX) to correct sound card's clock.\n", clock_speed[0], clock_speed[1]); cnetz->fsk_bitduration = (double)cnetz->sender.samplerate / ((double)BITRATE / (1.0 + clock_speed[1] / 1000000.0)); cnetz->fsk_tx_bitstep = 1.0 / cnetz->fsk_bitduration; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Use %.4f samples for one bit duration @ %d.\n", cnetz->fsk_bitduration, cnetz->sender.samplerate); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Use %.4f samples for one bit duration @ %d.\n", cnetz->fsk_bitduration, cnetz->sender.samplerate); size = cnetz->fsk_bitduration * (double)BLOCK_BITS * 16.0; /* 16 blocks for distributed frames */ cnetz->fsk_tx_buffer_size = size * 1.1; /* more to compensate clock speed */ cnetz->fsk_tx_buffer = calloc(sizeof(sample_t), cnetz->fsk_tx_buffer_size); if (!cnetz->fsk_tx_buffer) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "No memory!\n"); rc = -ENOMEM; goto error; } @@ -143,7 +144,7 @@ int dsp_init_sender(cnetz_t *cnetz, int measure_speed, double clock_speed[2], en /* create speech buffer */ cnetz->dsp_speech_buffer = calloc(sizeof(sample_t), (int)(cnetz->fsk_bitduration * 70.0)); /* more to compensate clock speed. we just need it to fill 62 bits (60 bits, including pause bits). */ if (!cnetz->dsp_speech_buffer) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "No memory!\n"); rc = -ENOMEM; goto error; } @@ -169,7 +170,7 @@ int dsp_init_sender(cnetz_t *cnetz, int measure_speed, double clock_speed[2], en #ifdef TEST_SCRAMBLE rc = jitter_create(&scrambler_test_jb, "scramble", cnetz->sender.samplerate, sizeof(sample_t), JITTER_AUDIO); if (rc < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Failed to init jitter buffer for scrambler test!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "Failed to init jitter buffer for scrambler test!\n"); exit(0); } scrambler_setup(&scrambler_test_scrambler1, cnetz->sender.samplerate); @@ -188,7 +189,7 @@ error: void dsp_cleanup_sender(cnetz_t *cnetz) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup FSK for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup FSK for 'Sender'.\n"); if (cnetz->fsk_tx_buffer) { free(cnetz->fsk_tx_buffer); @@ -256,7 +257,7 @@ void calc_clock_speed(cnetz_t *cnetz, double samples, int tx, int result) speed_ppm_avg[index] += cs->speed_ppm[index][(cs->idx[index] - i - 1) & 0xff]; speed_ppm_avg[index] /= (double)cs->num[index]; } - PDEBUG_CHAN(DDSP, DEBUG_NOTICE, "Clock: RX=%.3f TX=%.3f; Signal: RX=%.3f TX=%.3f ppm\n", speed_ppm_avg[0], speed_ppm_avg[1], speed_ppm_avg[2], speed_ppm_avg[3]); + LOGP_CHAN(DDSP, LOGL_NOTICE, "Clock: RX=%.3f TX=%.3f; Signal: RX=%.3f TX=%.3f ppm\n", speed_ppm_avg[0], speed_ppm_avg[1], speed_ppm_avg[2], speed_ppm_avg[3]); } static int fsk_nothing_encode(cnetz_t *cnetz) @@ -642,10 +643,10 @@ again: * because one has a phase wrap before and the other after a sample. * then we do it next super frame cycle */ if (master->frame_last_scount == cnetz->fsk_tx_scount) { - PDEBUG(DDSP, DEBUG_DEBUG, "Sync phase of slave to master: master=%.15f, slave=%.15f, diff=%.15f\n", master->frame_last_phase, cnetz->fsk_tx_phase, master->frame_last_phase - cnetz->fsk_tx_phase); + LOGP(DDSP, LOGL_DEBUG, "Sync phase of slave to master: master=%.15f, slave=%.15f, diff=%.15f\n", master->frame_last_phase, cnetz->fsk_tx_phase, master->frame_last_phase - cnetz->fsk_tx_phase); cnetz->fsk_tx_phase = master->frame_last_phase; } else { - PDEBUG(DDSP, DEBUG_DEBUG, "Not sync phase of slave to master: Sample counts during frame change are different, ignoring this time!\n"); + LOGP(DDSP, LOGL_DEBUG, "Not sync phase of slave to master: Sample counts during frame change are different, ignoring this time!\n"); } } } @@ -654,7 +655,7 @@ again: if (cnetz->sched_dsp_mode_ts >= 0 && cnetz->sched_r_m == 0) { if (cnetz->sched_dsp_mode_ts == cnetz->sched_ts) { /* OgK / SpK(K) / SpK(V) */ - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Now switching channel mode to %s at timeslot %d\n", cnetz_dsp_mode_name(cnetz->sched_dsp_mode), cnetz->sched_dsp_mode_ts); + LOGP_CHAN(DDSP, LOGL_INFO, "Now switching channel mode to %s at timeslot %d\n", cnetz_dsp_mode_name(cnetz->sched_dsp_mode), cnetz->sched_dsp_mode_ts); cnetz->sched_dsp_mode_ts = -1; cnetz_set_dsp_mode(cnetz, cnetz->sched_dsp_mode); } @@ -671,14 +672,14 @@ again: cnetz->sched_last_ts = cnetz->sched_ts; bits = cnetz_encode_telegramm(cnetz); if (bits) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Transmitting 'Rufblock' at timeslot %d\n", cnetz->sched_ts); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Transmitting 'Rufblock' at timeslot %d\n", cnetz->sched_ts); fsk_block_encode(cnetz, bits, 1); } else fsk_nothing_encode(cnetz); } else { bits = cnetz_encode_telegramm(cnetz); if (bits) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Transmitting 'Meldeblock' at timeslot %d\n", cnetz->sched_ts); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Transmitting 'Meldeblock' at timeslot %d\n", cnetz->sched_ts); fsk_block_encode(cnetz, bits, 1); } else fsk_nothing_encode(cnetz); @@ -690,7 +691,7 @@ again: case DSP_MODE_SPK_K: bits = cnetz_encode_telegramm(cnetz); if (bits) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Transmitting 'Konzentrierte Signalisierung' at timeslot %d.%d\n", cnetz->sched_ts, cnetz->sched_r_m * 5); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Transmitting 'Konzentrierte Signalisierung' at timeslot %d.%d\n", cnetz->sched_ts, cnetz->sched_r_m * 5); fsk_block_encode(cnetz, bits, 0); } else fsk_nothing_encode(cnetz); @@ -698,7 +699,7 @@ again: case DSP_MODE_SPK_V: bits = cnetz_encode_telegramm(cnetz); if (bits) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Transmitting 'Verteilte Signalisierung' starting at timeslot %d\n", cnetz->sched_ts); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Transmitting 'Verteilte Signalisierung' starting at timeslot %d\n", cnetz->sched_ts); fsk_distributed_encode(cnetz, bits); } else fsk_nothing_encode(cnetz); @@ -860,7 +861,7 @@ void unshrink_speech(cnetz_t *cnetz, sample_t *speech_buffer, int count) void cnetz_set_dsp_mode(cnetz_t *cnetz, enum dsp_mode mode) { if (mode != cnetz->dsp_mode) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "DSP mode %s -> %s\n", cnetz_dsp_mode_name(cnetz->dsp_mode), cnetz_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_INFO, "DSP mode %s -> %s\n", cnetz_dsp_mode_name(cnetz->dsp_mode), cnetz_dsp_mode_name(mode)); cnetz->dsp_mode = mode; } /* we must get rid of partly received frame */ @@ -870,10 +871,10 @@ void cnetz_set_dsp_mode(cnetz_t *cnetz, enum dsp_mode mode) void cnetz_set_sched_dsp_mode(cnetz_t *cnetz, enum dsp_mode mode, int timeslot) { if (cnetz->sched_dsp_mode_ts < 0 && mode == cnetz->dsp_mode) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Schedule DSP mode %s not required, we are already in that mode\n", cnetz_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_INFO, "Schedule DSP mode %s not required, we are already in that mode\n", cnetz_dsp_mode_name(mode)); return; } - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Schedule DSP mode %s -> %s at timeslot %d\n", cnetz_dsp_mode_name(cnetz->dsp_mode), cnetz_dsp_mode_name(mode), timeslot); + LOGP_CHAN(DDSP, LOGL_INFO, "Schedule DSP mode %s -> %s at timeslot %d\n", cnetz_dsp_mode_name(cnetz->dsp_mode), cnetz_dsp_mode_name(mode), timeslot); cnetz->sched_dsp_mode = mode; cnetz->sched_dsp_mode_ts = timeslot; } diff --git a/src/cnetz/fsk_demod.c b/src/cnetz/fsk_demod.c index a1acd70..9386b60 100644 --- a/src/cnetz/fsk_demod.c +++ b/src/cnetz/fsk_demod.c @@ -132,7 +132,7 @@ static int debug = 0; #include <string.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "cnetz.h" #include "dsp.h" #include "telegramm.h" @@ -143,7 +143,7 @@ int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitr memset(fsk, 0, sizeof(*fsk)); if (samplerate < 48000) { - PDEBUG(DDSP, DEBUG_ERROR, "Sample rate must be at least 48000 Hz!\n"); + LOGP(DDSP, LOGL_ERROR, "Sample rate must be at least 48000 Hz!\n"); return -1; } @@ -152,13 +152,13 @@ int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitr switch (demod) { case FSK_DEMOD_SLOPE: - PDEBUG(DDSP, DEBUG_INFO, "Detecting level change by looking at slope (good for sound cards)\n"); + LOGP(DDSP, LOGL_INFO, "Detecting level change by looking at slope (good for sound cards)\n"); break; case FSK_DEMOD_LEVEL: - PDEBUG(DDSP, DEBUG_INFO, "Detecting level change by looking zero crosssing (good for SDR)\n"); + LOGP(DDSP, LOGL_INFO, "Detecting level change by looking zero crosssing (good for SDR)\n"); break; default: - PDEBUG(DDSP, DEBUG_ERROR, "Wrong demod type, please fix!\n"); + LOGP(DDSP, LOGL_ERROR, "Wrong demod type, please fix!\n"); abort(); } @@ -166,7 +166,7 @@ int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitr half = (int)((double)samplerate / bitrate / 2.0 + 0.5); fsk->bit_buffer_spl = calloc(sizeof(fsk->bit_buffer_spl[0]), len); if (!fsk->bit_buffer_spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No mem!\n"); + LOGP(DDSP, LOGL_ERROR, "No mem!\n"); goto error; } @@ -177,7 +177,7 @@ int fsk_fm_init(fsk_fm_demod_t *fsk, cnetz_t *cnetz, int samplerate, double bitr fsk->speech_size = samplerate * 60 / bitrate + 10; /* 60 bits duration, add 10 to be safe */ fsk->speech_buffer = calloc(sizeof(fsk->speech_buffer[0]), fsk->speech_size); if (!fsk->speech_buffer) { - PDEBUG(DDSP, DEBUG_ERROR, "No mem!\n"); + LOGP(DDSP, LOGL_ERROR, "No mem!\n"); goto error; } diff --git a/src/cnetz/main.c b/src/cnetz/main.c index 27c2a02..dd4e663 100644 --- a/src/cnetz/main.c +++ b/src/cnetz/main.c @@ -24,7 +24,7 @@ #include <errno.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../anetz/freiton.h" #include "../anetz/besetztton.h" @@ -700,6 +700,7 @@ fail: cnetz_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/cnetz/telegramm.c b/src/cnetz/telegramm.c index 82a6cd8..0525f8a 100644 --- a/src/cnetz/telegramm.c +++ b/src/cnetz/telegramm.c @@ -27,7 +27,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "cnetz.h" #include "dsp.h" #include "sysinfo.h" @@ -510,13 +510,13 @@ static int encode_dialstring(uint64_t *value, const char *number) max = strlen(number); if (max > 16) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Given number '%s' has more than 16 digits\n", number); + LOGP(DFRAME, LOGL_NOTICE, "Given number '%s' has more than 16 digits\n", number); return -EINVAL; } if (max == 16) { if (number[0] != '0') { - PDEBUG(DFRAME, DEBUG_NOTICE, "Given 16 digit number '%s' does not start with '0'\n", number); + LOGP(DFRAME, LOGL_NOTICE, "Given 16 digit number '%s' does not start with '0'\n", number); return -EINVAL; } *value = 0; @@ -575,7 +575,7 @@ int match_fuz(telegramm_t *telegramm) if (telegramm->fuz_nationalitaet != si.fuz_nat || telegramm->fuz_fuvst_nr != si.fuz_fuvst || telegramm->fuz_rest_nr != si.fuz_rest) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Ignoring message from mobile phone %d,%d,%d: Cell 'Funkzelle' does not match!\n", telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr); + LOGP(DFRAME, LOGL_NOTICE, "Ignoring message from mobile phone %d,%d,%d: Cell 'Funkzelle' does not match!\n", telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr); return 0; } @@ -587,7 +587,7 @@ int match_futln(telegramm_t *telegramm, uint8_t futln_nat, uint8_t futln_fuvst, if (telegramm->futln_nationalitaet != futln_nat || telegramm->futln_heimat_fuvst_nr != futln_fuvst || telegramm->futln_rest_nr != futln_rest) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Ignoring message from mobile phone %d,%d,%d: Mobile station 'Funktelefongeraet' does not match!\n", telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr); + LOGP(DFRAME, LOGL_NOTICE, "Ignoring message from mobile phone %d,%d,%d: Mobile station 'Funktelefongeraet' does not match!\n", telegramm->futln_nationalitaet, telegramm->futln_heimat_fuvst_nr, telegramm->futln_rest_nr); return 0; } @@ -600,19 +600,19 @@ static void debug_parameter(char digit, uint64_t value) parameter = get_parameter(digit); if (!parameter) { - PDEBUG(DFRAME, DEBUG_ERROR, "Digit '%c' not found in definition_parameter list, please fix!\n", digit); + LOGP(DFRAME, LOGL_ERROR, "Digit '%c' not found in definition_parameter list, please fix!\n", digit); abort(); } if (parameter->value_names) - PDEBUG(DFRAME, DEBUG_DEBUG, " (%c) %s : %s\n", digit, parameter->param_name, parameter->value_names[value]); + LOGP(DFRAME, LOGL_DEBUG, " (%c) %s : %s\n", digit, parameter->param_name, parameter->value_names[value]); else if (parameter->bits == 64) - PDEBUG(DFRAME, DEBUG_DEBUG, " (%c) %s : 0x%016" PRIx64 "\n", digit, parameter->param_name, value); + LOGP(DFRAME, LOGL_DEBUG, " (%c) %s : 0x%016" PRIx64 "\n", digit, parameter->param_name, value); else if (digit == 'X') { char wahlziffern[17]; decode_dialstring(wahlziffern, value); - PDEBUG(DFRAME, DEBUG_DEBUG, " (%c) %s : '%s'\n", digit, parameter->param_name, wahlziffern); + LOGP(DFRAME, LOGL_DEBUG, " (%c) %s : '%s'\n", digit, parameter->param_name, wahlziffern); } else - PDEBUG(DFRAME, DEBUG_DEBUG, " (%c) %s : %" PRIu64 "\n", digit, parameter->param_name, value); + LOGP(DFRAME, LOGL_DEBUG, " (%c) %s : %" PRIu64 "\n", digit, parameter->param_name, value); } /* encode telegram to 70 bits @@ -628,12 +628,12 @@ static char *assemble_telegramm(const telegramm_t *telegramm, int debug) int rc; if (telegramm->opcode >= 64) { - PDEBUG(DFRAME, DEBUG_ERROR, "Opcode '0x%x' exceeds bit range, please fix!\n", telegramm->opcode); + LOGP(DFRAME, LOGL_ERROR, "Opcode '0x%x' exceeds bit range, please fix!\n", telegramm->opcode); abort(); } if (debug) - PDEBUG(DFRAME, DEBUG_INFO, "Coding %s %s\n", definition_opcode[telegramm->opcode].message_name, definition_opcode[telegramm->opcode].message_text); + LOGP(DFRAME, LOGL_INFO, "Coding %s %s\n", definition_opcode[telegramm->opcode].message_name, definition_opcode[telegramm->opcode].message_text); /* copy opcode */ for (i = 0; i < 6; i++) @@ -717,7 +717,7 @@ static char *assemble_telegramm(const telegramm_t *telegramm, int debug) case 'X': rc = encode_dialstring(&value, telegramm->wahlziffern); if (rc < 0) { - PDEBUG(DFRAME, DEBUG_ERROR, "Illegal dial string '%s', please fix!\n", telegramm->wahlziffern); + LOGP(DFRAME, LOGL_ERROR, "Illegal dial string '%s', please fix!\n", telegramm->wahlziffern); abort(); } break; @@ -806,10 +806,10 @@ static char *assemble_telegramm(const telegramm_t *telegramm, int debug) value = telegramm->illegaler_opcode; break; default: - PDEBUG(DFRAME, DEBUG_ERROR, "Parameter '%c' does not exist, please fix!\n", parameter); + LOGP(DFRAME, LOGL_ERROR, "Parameter '%c' does not exist, please fix!\n", parameter); abort(); } - if (debug && debuglevel <= DEBUG_DEBUG) + if (debug && loglevel <= LOGL_DEBUG) debug_parameter(parameter, value); val = value; for (j = 0; string[63 - i - j] == parameter; j++) { @@ -817,14 +817,14 @@ static char *assemble_telegramm(const telegramm_t *telegramm, int debug) val >>= 1; } if (val) - PDEBUG(DFRAME, DEBUG_ERROR, "Parameter '%c' value '0x%" PRIx64 "' exceeds bit range!\n", parameter, value); + LOGP(DFRAME, LOGL_ERROR, "Parameter '%c' value '0x%" PRIx64 "' exceeds bit range!\n", parameter, value); i += j - 1; } bits[70] = '\0'; if (debug) { - PDEBUG(DFRAME, DEBUG_DEBUG, "OOOOOO%s\n", string); - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", bits); + LOGP(DFRAME, LOGL_DEBUG, "OOOOOO%s\n", string); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", bits); } return bits; @@ -848,7 +848,7 @@ static void disassemble_telegramm(telegramm_t *telegramm, const char *bits, int value = (value << 1) | (bits[i] == '1'); telegramm->opcode = value; - PDEBUG(DFRAME, DEBUG_INFO, "Decoding %s %s\n", definition_opcode[telegramm->opcode].message_name, definition_opcode[telegramm->opcode].message_text); + LOGP(DFRAME, LOGL_INFO, "Decoding %s %s\n", definition_opcode[telegramm->opcode].message_name, definition_opcode[telegramm->opcode].message_text); /* copy parameters */ if (auth && bits[1]) /* auth flag and chip card flag */ @@ -864,7 +864,7 @@ static void disassemble_telegramm(telegramm_t *telegramm, const char *bits, int value = (value >> 1) | ((uint64_t)(bits[69 - i - j] == '1') << 63); value >>= 64 - j; i += j - 1; - if (debuglevel <= DEBUG_DEBUG) + if (loglevel <= LOGL_DEBUG) debug_parameter(parameter, value); switch (parameter) { case 'A': @@ -1021,18 +1021,18 @@ static void disassemble_telegramm(telegramm_t *telegramm, const char *bits, int telegramm->illegaler_opcode = value; break; default: - PDEBUG(DFRAME, DEBUG_ERROR, "Parameter '%c' does not exist, please fix!\n", parameter); + LOGP(DFRAME, LOGL_ERROR, "Parameter '%c' does not exist, please fix!\n", parameter); abort(); } } - if (debuglevel <= DEBUG_DEBUG) { + if (loglevel <= LOGL_DEBUG) { char debug_bits[71]; memcpy(debug_bits, bits, 70); debug_bits[70] = '\0'; - PDEBUG(DFRAME, DEBUG_DEBUG, "OOOOOO%s\n", string); - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", debug_bits); + LOGP(DFRAME, LOGL_DEBUG, "OOOOOO%s\n", string); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", debug_bits); } } @@ -1392,11 +1392,11 @@ static const char *decode(const char *input, int *_bit_errors) fail_str[10] = '\0'; if (failed) - PDEBUG(DFRAME, DEBUG_DEBUG, "Received Telegram with these block errors: '%s' (X = uncorrectable)\n", fail_str); + LOGP(DFRAME, LOGL_DEBUG, "Received Telegram with these block errors: '%s' (X = uncorrectable)\n", fail_str); else if (warn) - PDEBUG(DFRAME, DEBUG_DEBUG, "Received Telegram with these block errors: '%s' (1 / 2 = correctable)\n", fail_str); + LOGP(DFRAME, LOGL_DEBUG, "Received Telegram with these block errors: '%s' (1 / 2 = correctable)\n", fail_str); else - PDEBUG(DFRAME, DEBUG_DEBUG, "Received Telegram with no block errors.\n"); + LOGP(DFRAME, LOGL_DEBUG, "Received Telegram with no block errors.\n"); if (failed) return NULL; @@ -1496,13 +1496,13 @@ void cnetz_decode_telegramm(cnetz_t *cnetz, const char *bits, double level, doub break; } if (i == 70) { - PDEBUG(DFRAME, DEBUG_INFO, "Ignoring mysterious unmodulated telegramm (noise from phone's transmitter)\n"); + LOGP(DFRAME, LOGL_INFO, "Ignoring mysterious unmodulated telegramm (noise from phone's transmitter)\n"); return; } - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF level: %.1f dB RX Level: %.0f%% Standard deviation: %.0f%% Sync Time: %.2f (TS %.2f) %s\n", cnetz->rf_level_db, fabs(level) / cnetz->fsk_deviation * 100.0, stddev / fabs(level) * 100.0, sync_time, sync_time / 396.0, (level < 0) ? "NEGATIVE (phone's mode)" : "POSITIVE (base station's mode)"); + LOGP_CHAN(DDSP, LOGL_INFO, "RF level: %.1f dB RX Level: %.0f%% Standard deviation: %.0f%% Sync Time: %.2f (TS %.2f) %s\n", cnetz->rf_level_db, fabs(level) / cnetz->fsk_deviation * 100.0, stddev / fabs(level) * 100.0, sync_time, sync_time / 396.0, (level < 0) ? "NEGATIVE (phone's mode)" : "POSITIVE (base station's mode)"); if (bit_errors) - PDEBUG_CHAN(DDSP, DEBUG_INFO, " -> Frame has %d bit errors.\n", bit_errors); + LOGP_CHAN(DDSP, LOGL_INFO, " -> Frame has %d bit errors.\n", bit_errors); disassemble_telegramm(&telegramm, bits, si.authentifikationsbit); opcode = telegramm.opcode; @@ -1510,18 +1510,18 @@ void cnetz_decode_telegramm(cnetz_t *cnetz, const char *bits, double level, doub telegramm.sync_time = sync_time; if (cnetz->sender.loopback) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received Telegramm in loopback test mode (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); + LOGP(DFRAME, LOGL_NOTICE, "Received Telegramm in loopback test mode (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); cnetz_sync_frame(cnetz, sync_time, -1); return; } if (opcode >= 32) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received Telegramm that is not used by mobile station, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); + LOGP(DFRAME, LOGL_NOTICE, "Received Telegramm that is not used by mobile station, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); return; } if (definition_opcode[opcode].block == BLOCK_I) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received Telegramm that is an illegal opcode, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); + LOGP(DFRAME, LOGL_NOTICE, "Received Telegramm that is an illegal opcode, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); return; } @@ -1544,7 +1544,7 @@ void cnetz_decode_telegramm(cnetz_t *cnetz, const char *bits, double level, doub switch (cnetz->dsp_mode) { case DSP_MODE_OGK: if (definition_opcode[opcode].block != BLOCK_R && definition_opcode[opcode].block != BLOCK_M) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received Telegramm that is not used OgK channel signaling, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); + LOGP(DFRAME, LOGL_NOTICE, "Received Telegramm that is not used OgK channel signaling, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); return; } /* determine block by last timeslot sent and by message type @@ -1557,14 +1557,14 @@ void cnetz_decode_telegramm(cnetz_t *cnetz, const char *bits, double level, doub break; case DSP_MODE_SPK_K: if (definition_opcode[opcode].block != BLOCK_K) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received Telegramm that is not used for concentrated signaling, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); + LOGP(DFRAME, LOGL_NOTICE, "Received Telegramm that is not used for concentrated signaling, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); return; } cnetz_receive_telegramm_spk_k(cnetz, &telegramm); break; case DSP_MODE_SPK_V: if (definition_opcode[opcode].block != BLOCK_V) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received Telegramm that is not used for distributed signaling, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); + LOGP(DFRAME, LOGL_NOTICE, "Received Telegramm that is not used for distributed signaling, ignoring! (opcode %d = %s)\n", opcode, definition_opcode[opcode].message_name); return; } cnetz_receive_telegramm_spk_v(cnetz, &telegramm); @@ -1622,7 +1622,7 @@ const char *cnetz_encode_telegramm(cnetz_t *cnetz) cnetz->sched_lr_debugged = 1; if (opcode == OPCODE_MLR_M && !cnetz->sched_mlr_debugged) { cnetz->sched_mlr_debugged = 1; - PDEBUG(DFRAME, DEBUG_INFO, "Subsequent IDLE frames are not show, to prevent flooding the output.\n"); + LOGP(DFRAME, LOGL_INFO, "Subsequent IDLE frames are not show, to prevent flooding the output.\n"); } return bits; diff --git a/src/cnetz/transaction.c b/src/cnetz/transaction.c index b0a4989..f89718b 100644 --- a/src/cnetz/transaction.c +++ b/src/cnetz/transaction.c @@ -22,7 +22,7 @@ #include <stdlib.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" #include "cnetz.h" @@ -54,7 +54,7 @@ transaction_t *create_transaction(cnetz_t *cnetz, uint64_t state, uint8_t futln_ if ((trans->state & state & (TRANS_EM | TRANS_UM | TRANS_VWG | TRANS_ATQ_IDLE))) { if (!isnan(trans->rf_level_db) && !isnan(rf_level_db) && trans->cnetz->kanal != cnetz->kanal) { if (rf_level_db > trans->rf_level_db) { - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s' on channel #%d, but this message on channel #%d is stronger, so we move to that channel!\n", rufnummer, trans->cnetz->kanal, cnetz->kanal); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s' on channel #%d, but this message on channel #%d is stronger, so we move to that channel!\n", rufnummer, trans->cnetz->kanal, cnetz->kanal); trans->rf_level_db = rf_level_db; unlink_transaction(trans); link_transaction(trans, cnetz); @@ -62,14 +62,14 @@ transaction_t *create_transaction(cnetz_t *cnetz, uint64_t state, uint8_t futln_ return trans; } if (rf_level_db < trans->rf_level_db) { - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s' on channel #%d, but this message on channel #%d is weaker, so we ignore that channel!\n", rufnummer, trans->cnetz->kanal, cnetz->kanal); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s' on channel #%d, but this message on channel #%d is weaker, so we ignore that channel!\n", rufnummer, trans->cnetz->kanal, cnetz->kanal); return trans; } } - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s' on channel #%d, but this message on channel #%d is also received. Try to avoid multiple OgK channels!\n", rufnummer, trans->cnetz->kanal, cnetz->kanal); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s' on channel #%d, but this message on channel #%d is also received. Try to avoid multiple OgK channels!\n", rufnummer, trans->cnetz->kanal, cnetz->kanal); return trans; } - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s', deleting!\n", rufnummer); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s', deleting!\n", rufnummer); destroy_transaction(trans); if (old_cnetz) /* should be... */ cnetz_go_idle(old_cnetz); @@ -79,11 +79,11 @@ transaction_t *create_transaction(cnetz_t *cnetz, uint64_t state, uint8_t futln_ trans = calloc(1, sizeof(*trans)); if (!trans) { - PDEBUG(DTRANS, DEBUG_ERROR, "No memory!\n"); + LOGP(DTRANS, LOGL_ERROR, "No memory!\n"); return NULL; } - timer_init(&trans->timer, transaction_timeout, trans); + osmo_timer_setup(&trans->timer, transaction_timeout, trans); trans_new_state(trans, state); trans->futln_nat = futln_nat; @@ -96,7 +96,7 @@ transaction_t *create_transaction(cnetz_t *cnetz, uint64_t state, uint8_t futln_ trans->mt_call = 1; const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_INFO, "Created transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_INFO, "Created transaction for subscriber '%s'\n", rufnummer); link_transaction(trans, cnetz); @@ -119,9 +119,9 @@ void destroy_transaction(transaction_t *trans) unlink_transaction(trans); const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_INFO, "Destroying transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_INFO, "Destroying transaction for subscriber '%s'\n", rufnummer); - timer_exit(&trans->timer); + osmo_timer_del(&trans->timer); trans_new_state(trans, 0); @@ -134,7 +134,7 @@ void link_transaction(transaction_t *trans, cnetz_t *cnetz) transaction_t **transp; /* attach to end of list, so first transaction is served first */ - PDEBUG(DTRANS, DEBUG_DEBUG, "Linking transaction %p to cnetz %p\n", trans, cnetz); + LOGP(DTRANS, LOGL_DEBUG, "Linking transaction %p to cnetz %p\n", trans, cnetz); trans->cnetz = cnetz; trans->next = NULL; transp = &cnetz->trans_list; @@ -150,12 +150,12 @@ void unlink_transaction(transaction_t *trans) transaction_t **transp; /* unlink */ - PDEBUG(DTRANS, DEBUG_DEBUG, "Unlinking transaction %p from cnetz %p\n", trans, trans->cnetz); + LOGP(DTRANS, LOGL_DEBUG, "Unlinking transaction %p from cnetz %p\n", trans, trans->cnetz); transp = &trans->cnetz->trans_list; while (*transp && *transp != trans) transp = &((*transp)->next); if (!(*transp)) { - PDEBUG(DTRANS, DEBUG_ERROR, "Transaction not in list, please fix!!\n"); + LOGP(DTRANS, LOGL_ERROR, "Transaction not in list, please fix!!\n"); abort(); } *transp = trans->next; @@ -170,7 +170,7 @@ transaction_t *search_transaction(cnetz_t *cnetz, uint64_t state_mask) while (trans) { if ((trans->state & state_mask)) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); return trans; } trans = trans->next; @@ -188,7 +188,7 @@ transaction_t *search_transaction_number(cnetz_t *cnetz, uint8_t futln_nat, uint && trans->futln_fuvst == futln_fuvst && trans->futln_rest == futln_rest) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); return trans; } trans = trans->next; @@ -224,7 +224,7 @@ transaction_t *search_transaction_callref(cnetz_t *cnetz, int callref) while (trans) { if (trans->callref == callref) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); return trans; } trans = trans->next; @@ -262,7 +262,7 @@ transaction_t *search_transaction_queue(void) if (found) { const char *rufnummer = transaction2rufnummer(found); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found oldest transaction in queue for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found oldest transaction in queue for subscriber '%s'\n", rufnummer); return found; } @@ -386,7 +386,7 @@ const char *trans_short_state_name(uint64_t state) void trans_new_state(transaction_t *trans, uint64_t state) { - PDEBUG(DTRANS, DEBUG_INFO, "Transaction (%s) state %s -> %s\n", transaction2rufnummer(trans), trans_state_name(trans->state), trans_state_name(state)); + LOGP(DTRANS, LOGL_INFO, "Transaction (%s) state %s -> %s\n", transaction2rufnummer(trans), trans_state_name(trans->state), trans_state_name(state)); trans->state = state; /* in case of a queue, set new positon */ if (!trans->queue_position && (state == TRANS_MO_QUEUE || state == TRANS_MT_QUEUE)) @@ -398,12 +398,12 @@ void cnetz_flush_other_transactions(cnetz_t *cnetz, transaction_t *trans) { /* flush after this very trans */ while (trans->next) { - PDEBUG(DTRANS, DEBUG_NOTICE, "Kicking other pending transaction\n"); + LOGP(DTRANS, LOGL_NOTICE, "Kicking other pending transaction\n"); destroy_transaction(trans->next); } /* flush before this very trans */ while (cnetz->trans_list != trans) { - PDEBUG(DTRANS, DEBUG_NOTICE, "Kicking other pending transaction\n"); + LOGP(DTRANS, LOGL_NOTICE, "Kicking other pending transaction\n"); destroy_transaction(cnetz->trans_list); } } diff --git a/src/cnetz/transaction.h b/src/cnetz/transaction.h index 85019f1..a0189a4 100644 --- a/src/cnetz/transaction.h +++ b/src/cnetz/transaction.h @@ -50,7 +50,7 @@ typedef struct transaction { int8_t release_cause; /* reason for release, (c-netz coding) */ int try; /* counts resending messages */ int repeat; /* counts repeating messages */ - struct timer timer; /* for varous timeouts */ + struct osmo_timer_list timer; /* for varous timeouts */ int mo_call; /* flags a moile originating call */ int mt_call; /* flags a moile terminating call */ int page_failed; /* failed to get a response from MS */ diff --git a/src/datenklo/Makefile.am b/src/datenklo/Makefile.am index 0676d23..1361c3d 100644 --- a/src/datenklo/Makefile.am +++ b/src/datenklo/Makefile.am @@ -12,15 +12,15 @@ datenklo_SOURCES = \ datenklo_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libfsk/libfsk.a \ - $(top_builddir)/src/libtimer/libtimer.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libsound/libsound.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libsample/libsample.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ $(ALSA_LIBS) \ $(FUSE_LIBS) \ -lm diff --git a/src/datenklo/am791x.c b/src/datenklo/am791x.c index 8a29047..f2ddf1d 100644 --- a/src/datenklo/am791x.c +++ b/src/datenklo/am791x.c @@ -75,12 +75,14 @@ #include <string.h> #include <errno.h> #include <math.h> -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libsample/sample.h" #include "../libfsk/fsk.h" #include "am791x.h" +#define FLOAT_TO_TIMEOUT(f) floor(f), ((f) - floor(f)) * 1000000 + #define db2level(db) pow(10, (double)(db) / 20.0) #define level2db(level) (20 * log10(level)) @@ -373,19 +375,19 @@ static int fsk_send_bit(void *inst) /* main channel returns TD */ if (!am791x->block_td) { #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, "Modulating bit '%d' for MAIN channel\n", bit); + LOGP(DDSP, LOGL_DEBUG, "Modulating bit '%d' for MAIN channel\n", bit); #endif return bit; } /* back channel returns BTD */ if (!am791x->block_btd) { #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, "Modulating bit '%d' for BACK channel\n", bbit); + LOGP(DDSP, LOGL_DEBUG, "Modulating bit '%d' for BACK channel\n", bbit); #endif return bbit; } #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, "Modulating bit '1', because TD & BTD is ignored\n"); + LOGP(DDSP, LOGL_DEBUG, "Modulating bit '1', because TD & BTD is ignored\n"); #endif return 1; } @@ -399,7 +401,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) int *block, *cd; #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, "Demodulated bit '%d' (level = %.0f dBm, quality = %%%.0f)\n", bit, level2db(level), quality * 100.0); + LOGP(DDSP, LOGL_DEBUG, "Demodulated bit '%d' (level = %.0f dBm, quality = %%%.0f)\n", bit, level2db(level), quality * 100.0); #endif if (!am791x->rx_back_channel) { @@ -416,12 +418,12 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) handle_rx_state(am791x); } else if (!(*block) && !(*cd) && level > am791x->cd_on && quality >= RX_QUALITY) { - PDEBUG(DDSP, DEBUG_DEBUG, "Good quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0); + LOGP(DDSP, LOGL_DEBUG, "Good quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0); *cd = 1; handle_rx_state(am791x); } else if (*cd && (level < am791x->cd_off || quality < RX_QUALITY)) { - PDEBUG(DDSP, DEBUG_DEBUG, "Bad quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0); + LOGP(DDSP, LOGL_DEBUG, "Bad quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0); *cd = 0; handle_rx_state(am791x); } @@ -437,24 +439,24 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) /* main channel forwards bit to RD */ if (!am791x->block_rd) { #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '%d' to MAIN channel\n", bit); + LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '%d' to MAIN channel\n", bit); #endif am791x->rd_cb(am791x->inst, bit, quality * 100.0, level2db(level)); } else { #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '1' to MAIN channel, because RD is set to MARK\n"); + LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '1' to MAIN channel, because RD is set to MARK\n"); #endif am791x->rd_cb(am791x->inst, 1, NAN, NAN); } /* main channel forwards bit to RD */ if (!am791x->block_brd) { #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '%d' to BACK channel\n", bit); + LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '%d' to BACK channel\n", bit); #endif am791x->brd_cb(am791x->inst, bit, quality * 100.0, level2db(level)); } else { #ifdef HEAVY_DEBUG - PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '1' to BACK channel, because BRD is set to MARK\n"); + LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '1' to BACK channel, because BRD is set to MARK\n"); #endif am791x->brd_cb(am791x->inst, 1, NAN, NAN); } @@ -529,9 +531,9 @@ static void set_filters(am791x_t *am791x) /* transmitter used */ if (f0_tx > 0 && am791x->f0_tx == 0) { - PDEBUG(DDSP, DEBUG_DEBUG, "Setting modulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_tx, f0_tx, f1_tx, am791x->tx_baud); + LOGP(DDSP, LOGL_DEBUG, "Setting modulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_tx, f0_tx, f1_tx, am791x->tx_baud); if (fsk_mod_init(&am791x->fsk_tx, am791x, fsk_send_bit, am791x->samplerate, am791x->tx_baud, (double)f0_tx, (double)f1_tx, am791x->tx_level, 0, 1) < 0) - PDEBUG(DDSP, DEBUG_ERROR, "FSK RX init failed!\n"); + LOGP(DDSP, LOGL_ERROR, "FSK RX init failed!\n"); else { am791x->f0_tx = f0_tx; am791x->f1_tx = f1_tx; @@ -548,9 +550,9 @@ static void set_filters(am791x_t *am791x) /* receiver used */ if (f0_rx > 0 && am791x->f0_rx == 0) { - PDEBUG(DDSP, DEBUG_DEBUG, "Setting demodulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_rx, f0_rx, f1_rx, am791x->rx_baud); + LOGP(DDSP, LOGL_DEBUG, "Setting demodulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_rx, f0_rx, f1_rx, am791x->rx_baud); if (fsk_demod_init(&am791x->fsk_rx, am791x, fsk_receive_bit, am791x->samplerate, am791x->rx_baud, (double)f0_rx, (double)f1_rx, BIT_ADJUST) < 0) - PDEBUG(DDSP, DEBUG_ERROR, "FSK RX init failed!\n"); + LOGP(DDSP, LOGL_ERROR, "FSK RX init failed!\n"); else { am791x->f0_rx = f0_rx; am791x->f1_rx = f1_rx; @@ -562,14 +564,14 @@ static void set_filters(am791x_t *am791x) static void new_tx_state(am791x_t *am791x, enum am791x_st state) { if (am791x->tx_state != state) - PDEBUG(DAM791X, DEBUG_DEBUG, "Change TX state %s -> %s\n", am791x_state_names[am791x->tx_state], am791x_state_names[state]); + LOGP(DAM791X, LOGL_DEBUG, "Change TX state %s -> %s\n", am791x_state_names[am791x->tx_state], am791x_state_names[state]); am791x->tx_state = state; } static void new_rx_state(am791x_t *am791x, enum am791x_st state) { if (am791x->rx_state != state) - PDEBUG(DAM791X, DEBUG_DEBUG, "Change RX state %s -> %s\n", am791x_state_names[am791x->rx_state], am791x_state_names[state]); + LOGP(DAM791X, LOGL_DEBUG, "Change RX state %s -> %s\n", am791x_state_names[am791x->rx_state], am791x_state_names[state]); am791x->rx_state = state; } @@ -577,7 +579,7 @@ static void new_rx_state(am791x_t *am791x, enum am791x_st state) static void set_flag(int *flag_p, int value, const char *name) { if (*flag_p != value) { - PDEBUG(DAM791X, DEBUG_DEBUG, " -> %s\n", name); + LOGP(DAM791X, LOGL_DEBUG, " -> %s\n", name); *flag_p = value; } } @@ -588,7 +590,7 @@ static void set_flag(int *flag_p, int value, const char *name) static void go_main_channel_tx(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Enable transmitter on main channel\n"); + LOGP(DAM791X, LOGL_DEBUG, "Enable transmitter on main channel\n"); /* only block RD, if not full duplex and not 4-wire (loopback mode) */ if (!am791x->fullduplex && !am791x->loopback_main) { @@ -599,7 +601,7 @@ static void go_main_channel_tx(am791x_t *am791x) /* activate TD now and set CTS timer (RCON) */ set_flag(&am791x->block_td, 0, "TD RELEASED"); set_flag(&am791x->tx_silence, 0, "RESET SILENCE"); - timer_start(&am791x->tx_timer, am791x->t_rcon); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_rcon)); new_tx_state(am791x, AM791X_STATE_RCON); set_filters(am791x); /* check CD to be blocked */ @@ -613,7 +615,7 @@ static void go_main_channel_tx(am791x_t *am791x) static void rcon_release_rts(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "RTS was released\n"); + LOGP(DAM791X, LOGL_DEBUG, "RTS was released\n"); set_flag(&am791x->block_td, 1, "TD IGNORED"); set_flag(&am791x->tx_silence, 1, "SET SILENCE"); @@ -629,7 +631,7 @@ static void rcon_release_rts(am791x_t *am791x) static void rcon_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission started\n"); + LOGP(DAM791X, LOGL_DEBUG, "Transmission started\n"); new_tx_state(am791x, AM791X_STATE_DATA); /* CTS on */ @@ -638,7 +640,7 @@ static void rcon_done(am791x_t *am791x) static void tx_data_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "RTS was released\n"); + LOGP(DAM791X, LOGL_DEBUG, "RTS was released\n"); new_tx_state(am791x, AM791X_STATE_RCOFF); set_flag(&am791x->block_td, 1, "TD IGNORED"); @@ -650,12 +652,12 @@ static void tx_data_done(am791x_t *am791x) if (!am791x->fullduplex) { set_flag(&am791x->squelch, 1, "SET SQUELCH (ON)"); } - timer_start(&am791x->tx_timer, am791x->t_rcoff); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_rcoff)); } static void rcoff_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission over\n"); + LOGP(DAM791X, LOGL_DEBUG, "Transmission over\n"); /* CTS off */ am791x->cts_cb(am791x->inst, 0); @@ -665,17 +667,17 @@ static void rcoff_done(am791x_t *am791x) return; } if (!am791x->sto) { - timer_start(&am791x->tx_timer, am791x->t_sq - am791x->t_rcoff); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_sq - am791x->t_rcoff)); new_tx_state(am791x, AM791X_STATE_SQ_OFF); return; } - timer_start(&am791x->tx_timer, am791x->t_sto - am791x->t_rcoff); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_sto - am791x->t_rcoff)); new_tx_state(am791x, AM791X_STATE_STO_OFF); } static void sq_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Squelch over\n"); + LOGP(DAM791X, LOGL_DEBUG, "Squelch over\n"); set_flag(&am791x->block_cd, 0, "CD RELEASED"); new_tx_state(am791x, AM791X_STATE_INIT); @@ -690,16 +692,16 @@ static void sq_done(am791x_t *am791x) static void sto_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "STO over\n"); + LOGP(DAM791X, LOGL_DEBUG, "STO over\n"); set_flag(&am791x->tx_sto, 0, "stop STO"); - timer_start(&am791x->tx_timer, am791x->t_sq - am791x->t_sto); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_sq - am791x->t_sto)); new_tx_state(am791x, AM791X_STATE_SQ_OFF); } static void go_back_channel_tx(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Enable transmitter on back channel\n"); + LOGP(DAM791X, LOGL_DEBUG, "Enable transmitter on back channel\n"); if (!am791x->loopback_back) { set_flag(&am791x->block_brd, 1, "BRD = MARK"); @@ -709,7 +711,7 @@ static void go_back_channel_tx(am791x_t *am791x) /* activate BTD now and set BCTS timer (BRCON) */ set_flag(&am791x->block_btd, 0, "BTD RELEASED"); set_flag(&am791x->tx_silence, 0, "RESET SILENCE"); - timer_start(&am791x->tx_timer, am791x->t_brcon); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_brcon)); new_tx_state(am791x, AM791X_STATE_BRCON); set_filters(am791x); /* check BCD to be blocked */ @@ -723,7 +725,7 @@ static void go_back_channel_tx(am791x_t *am791x) static void brcon_release_brts(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "BRTS was released\n"); + LOGP(DAM791X, LOGL_DEBUG, "BRTS was released\n"); set_flag(&am791x->tx_silence, 1, "SET SILENCE"); new_tx_state(am791x, AM791X_STATE_INIT); @@ -732,7 +734,7 @@ static void brcon_release_brts(am791x_t *am791x) static void brcon_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission started\n"); + LOGP(DAM791X, LOGL_DEBUG, "Transmission started\n"); new_tx_state(am791x, AM791X_STATE_BDATA); /* BCTS on */ @@ -741,16 +743,16 @@ static void brcon_done(am791x_t *am791x) static void tx_bdata_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "BRTS was released\n"); + LOGP(DAM791X, LOGL_DEBUG, "BRTS was released\n"); set_flag(&am791x->block_btd, 1, "BTD IGNORED"); set_flag(&am791x->tx_silence, 1, "SET SILENCE"); - timer_start(&am791x->tx_timer, am791x->t_brcoff); + osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_brcoff)); } static void brcoff_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission over\n"); + LOGP(DAM791X, LOGL_DEBUG, "Transmission over\n"); /* BCTS off */ am791x->bcts_cb(am791x->inst, 0); @@ -791,7 +793,7 @@ static void handle_tx_state(am791x_t *am791x) rcon_release_rts(am791x); break; } - if (!timer_running(&am791x->tx_timer)) { + if (!osmo_timer_pending(&am791x->tx_timer)) { rcon_done(am791x); break; } @@ -803,19 +805,19 @@ static void handle_tx_state(am791x_t *am791x) } break; case AM791X_STATE_RCOFF: - if (!timer_running(&am791x->tx_timer)) { + if (!osmo_timer_pending(&am791x->tx_timer)) { rcoff_done(am791x); break; } break; case AM791X_STATE_STO_OFF: - if (!timer_running(&am791x->tx_timer)) { + if (!osmo_timer_pending(&am791x->tx_timer)) { sto_done(am791x); break; } break; case AM791X_STATE_SQ_OFF: - if (!timer_running(&am791x->tx_timer)) { + if (!osmo_timer_pending(&am791x->tx_timer)) { sq_done(am791x); break; } @@ -826,7 +828,7 @@ static void handle_tx_state(am791x_t *am791x) brcon_release_brts(am791x); break; } - if (!timer_running(&am791x->tx_timer)) { + if (!osmo_timer_pending(&am791x->tx_timer)) { brcon_done(am791x); break; } @@ -838,27 +840,27 @@ static void handle_tx_state(am791x_t *am791x) } break; case AM791X_STATE_BRCOFF: - if (!timer_running(&am791x->tx_timer)) { + if (!osmo_timer_pending(&am791x->tx_timer)) { brcoff_done(am791x); break; } break; default: - PDEBUG(DAM791X, DEBUG_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]); + LOGP(DAM791X, LOGL_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]); } } static void go_main_channel_rx(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Enable receiver on main channel\n"); + LOGP(DAM791X, LOGL_DEBUG, "Enable receiver on main channel\n"); - timer_start(&am791x->rx_timer, am791x->t_cdon); + osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_cdon)); new_rx_state(am791x, AM791X_STATE_CDON); } static void cdon_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Reception started\n"); + LOGP(DAM791X, LOGL_DEBUG, "Reception started\n"); set_flag(&am791x->block_rd, 0, "RD RELEASED"); new_rx_state(am791x, AM791X_STATE_DATA); @@ -872,23 +874,23 @@ static void cdon_done(am791x_t *am791x) static void cdon_no_cd(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier is gone\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier is gone\n"); - timer_stop(&am791x->rx_timer); + osmo_timer_del(&am791x->rx_timer); new_rx_state(am791x, AM791X_STATE_INIT); } static void rx_data_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier lost\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier lost\n"); - timer_start(&am791x->rx_timer, am791x->t_cdoff); + osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_cdoff)); new_rx_state(am791x, AM791X_STATE_CDOFF); } static void cdoff_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Reception finished\n"); + LOGP(DAM791X, LOGL_DEBUG, "Reception finished\n"); set_flag(&am791x->block_rd, 1, "RD = MARK"); new_rx_state(am791x, AM791X_STATE_INIT); @@ -902,23 +904,23 @@ static void cdoff_done(am791x_t *am791x) static void cdoff_cd(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier recovered\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier recovered\n"); - timer_stop(&am791x->rx_timer); + osmo_timer_del(&am791x->rx_timer); new_rx_state(am791x, AM791X_STATE_DATA); } static void go_back_channel_rx(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Enable receiver on back channel\n"); + LOGP(DAM791X, LOGL_DEBUG, "Enable receiver on back channel\n"); - timer_start(&am791x->rx_timer, am791x->t_bcdon); + osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_bcdon)); new_rx_state(am791x, AM791X_STATE_BCDON); } static void bcdon_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier was detected\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier was detected\n"); set_flag(&am791x->block_brd, 0, "BRD RELEASED"); new_rx_state(am791x, AM791X_STATE_BDATA); @@ -932,23 +934,23 @@ static void bcdon_done(am791x_t *am791x) static void bcdon_no_cd(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier is gone\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier is gone\n"); - timer_stop(&am791x->rx_timer); + osmo_timer_del(&am791x->rx_timer); new_rx_state(am791x, AM791X_STATE_INIT); } static void rx_bdata_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier lost\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier lost\n"); - timer_start(&am791x->rx_timer, am791x->t_bcdoff); + osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_bcdoff)); new_rx_state(am791x, AM791X_STATE_BCDOFF); } static void bcdoff_done(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Reception finished\n"); + LOGP(DAM791X, LOGL_DEBUG, "Reception finished\n"); if (!am791x->bell_202) set_flag(&am791x->block_brd, 1, "BRD = MARK"); @@ -963,9 +965,9 @@ static void bcdoff_done(am791x_t *am791x) static void bcdoff_cd(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier recovered\n"); + LOGP(DAM791X, LOGL_DEBUG, "Carrier recovered\n"); - timer_stop(&am791x->rx_timer); + osmo_timer_del(&am791x->rx_timer); new_rx_state(am791x, AM791X_STATE_BDATA); } @@ -992,7 +994,7 @@ static void handle_rx_state(am791x_t *am791x) break; /* all main channel states ... */ case AM791X_STATE_CDON: - if (!timer_running(&am791x->rx_timer)) { + if (!osmo_timer_pending(&am791x->rx_timer)) { cdon_done(am791x); break; } @@ -1008,7 +1010,7 @@ static void handle_rx_state(am791x_t *am791x) } break; case AM791X_STATE_CDOFF: - if (!timer_running(&am791x->rx_timer)) { + if (!osmo_timer_pending(&am791x->rx_timer)) { cdoff_done(am791x); break; } @@ -1019,7 +1021,7 @@ static void handle_rx_state(am791x_t *am791x) break; /* all back channel states ... */ case AM791X_STATE_BCDON: - if (!timer_running(&am791x->rx_timer)) { + if (!osmo_timer_pending(&am791x->rx_timer)) { bcdon_done(am791x); break; } @@ -1035,7 +1037,7 @@ static void handle_rx_state(am791x_t *am791x) } break; case AM791X_STATE_BCDOFF: - if (!timer_running(&am791x->rx_timer)) { + if (!osmo_timer_pending(&am791x->rx_timer)) { bcdoff_done(am791x); break; } @@ -1045,7 +1047,7 @@ static void handle_rx_state(am791x_t *am791x) } break; default: - PDEBUG(DAM791X, DEBUG_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]); + LOGP(DAM791X, LOGL_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]); } } @@ -1086,10 +1088,10 @@ int am791x_init(am791x_t *am791x, void *inst, enum am791x_type type, uint8_t mc, memset(am791x, 0, sizeof(*am791x)); /* init timers */ - timer_init(&am791x->tx_timer, tx_timeout, am791x); - timer_init(&am791x->rx_timer, rx_timeout, am791x); + osmo_timer_setup(&am791x->tx_timer, tx_timeout, am791x); + osmo_timer_setup(&am791x->rx_timer, rx_timeout, am791x); - PDEBUG(DAM791X, DEBUG_DEBUG, "Initializing instance of AM791%d:\n", type); + LOGP(DAM791X, LOGL_DEBUG, "Initializing instance of AM791%d:\n", type); am791x->inst = inst; am791x->type = type; @@ -1119,13 +1121,13 @@ int am791x_init(am791x_t *am791x, void *inst, enum am791x_type type, uint8_t mc, /* exit routine, must be called when exit */ void am791x_exit(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Exit instance of AM791%d:\n", am791x->type); + LOGP(DAM791X, LOGL_DEBUG, "Exit instance of AM791%d:\n", am791x->type); /* bring to reset state, be sure to clean FSK processes */ am791x_reset(am791x); - timer_exit(&am791x->tx_timer); - timer_exit(&am791x->rx_timer); + osmo_timer_del(&am791x->tx_timer); + osmo_timer_del(&am791x->rx_timer); } /* get some default baud rate for each mode, before IOCTL sets it (if it sets it) */ @@ -1149,8 +1151,8 @@ int am791x_mc(am791x_t *am791x, uint8_t mc, int samplerate, double tx_baud, doub if (!((am791x->type) ? am791x_modes[mc].sup_7911 : am791x_modes[mc].sup_7910)) rc = -EINVAL; - PDEBUG(DAM791X, DEBUG_INFO, "Setting mode %d: %s\n", mc, am791x_modes[mc].description); - PDEBUG(DAM791X, DEBUG_DEBUG, " -> Baud rate: %.1f/%.1f\n", rx_baud, tx_baud); + LOGP(DAM791X, LOGL_INFO, "Setting mode %d: %s\n", mc, am791x_modes[mc].description); + LOGP(DAM791X, LOGL_DEBUG, " -> Baud rate: %.1f/%.1f\n", rx_baud, tx_baud); am791x->mc = mc; am791x->samplerate = samplerate; @@ -1187,10 +1189,10 @@ int am791x_mc(am791x_t *am791x, uint8_t mc, int samplerate, double tx_baud, doub /* reset at any time, may be called any time by upper layer */ void am791x_reset(am791x_t *am791x) { - PDEBUG(DAM791X, DEBUG_INFO, "Reset!\n"); + LOGP(DAM791X, LOGL_INFO, "Reset!\n"); - timer_stop(&am791x->tx_timer); - timer_stop(&am791x->rx_timer); + osmo_timer_del(&am791x->tx_timer); + osmo_timer_del(&am791x->rx_timer); if (am791x->f0_tx) { fsk_mod_cleanup(&am791x->fsk_tx); @@ -1228,7 +1230,7 @@ void am791x_reset(am791x_t *am791x) /* change input lines */ void am791x_dtr(am791x_t *am791x, int dtr) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal is%s ready!\n", (dtr) ? "" : " not"); + LOGP(DAM791X, LOGL_DEBUG, "Terminal is%s ready!\n", (dtr) ? "" : " not"); /* set filters, if DTR becomes on */ if (!am791x->line_dtr && dtr) { @@ -1242,7 +1244,7 @@ void am791x_dtr(am791x_t *am791x, int dtr) void am791x_rts(am791x_t *am791x, int rts) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal %s RTS.\n", (rts) ? "sets" : "clears"); + LOGP(DAM791X, LOGL_DEBUG, "Terminal %s RTS.\n", (rts) ? "sets" : "clears"); am791x->line_rts = rts; handle_state(am791x); @@ -1250,7 +1252,7 @@ void am791x_rts(am791x_t *am791x, int rts) void am791x_brts(am791x_t *am791x, int rts) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal %s BRTS.\n", (rts) ? "sets" : "clears"); + LOGP(DAM791X, LOGL_DEBUG, "Terminal %s BRTS.\n", (rts) ? "sets" : "clears"); am791x->line_brts = rts; handle_state(am791x); @@ -1258,7 +1260,7 @@ void am791x_brts(am791x_t *am791x, int rts) void am791x_ring(am791x_t *am791x, int ring) { - PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal %s RING.\n", (ring) ? "sets" : "clears"); + LOGP(DAM791X, LOGL_DEBUG, "Terminal %s RING.\n", (ring) ? "sets" : "clears"); am791x->line_ring = ring; handle_state(am791x); diff --git a/src/datenklo/am791x.h b/src/datenklo/am791x.h index a75f736..163c1d2 100644 --- a/src/datenklo/am791x.h +++ b/src/datenklo/am791x.h @@ -67,7 +67,7 @@ typedef struct am791x { int f0_rx, f1_rx; /* timers */ - struct timer tx_timer, rx_timer; + struct osmo_timer_list tx_timer, rx_timer; double t_rcon; double t_rcoff; double t_brcon; diff --git a/src/datenklo/datenklo.c b/src/datenklo/datenklo.c index aea44a6..9a5ff82 100644 --- a/src/datenklo/datenklo.c +++ b/src/datenklo/datenklo.c @@ -32,12 +32,14 @@ #include <fcntl.h> #include <math.h> #include "../libsample/sample.h" -#include "../libtimer/timer.h" +#include <osmocom/core/select.h> +#include <osmocom/core/timer.h> #include "../libfsk/fsk.h" #include "../libsound/sound.h" #include "../libwave/wave.h" #include "../libdisplay/display.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" +#include "../libmobile/get_time.c" #include "device.h" #include "am791x.h" #include "uart.h" @@ -217,7 +219,7 @@ static void cts(void *inst, int cts) return; if (datenklo->auto_rts) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Received CTS=%d in Automatic RTS Mode.\n", cts); + LOGP(DDATENKLO, LOGL_INFO, "Received CTS=%d in Automatic RTS Mode.\n", cts); datenklo->auto_rts_cts = cts; return; } @@ -226,7 +228,7 @@ static void cts(void *inst, int cts) datenklo->lines |= TIOCM_CTS; else datenklo->lines &= ~TIOCM_CTS; - PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that CTS is %s\n", (cts) ? "on" : "off"); + LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that CTS is %s\n", (cts) ? "on" : "off"); } /* modem changes CTS state (back channel) */ @@ -238,7 +240,7 @@ static void bcts(void *inst, int cts) return; if (datenklo->auto_rts) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Received BCTS=%d in Automatic RTS Mode.\n", cts); + LOGP(DDATENKLO, LOGL_INFO, "Received BCTS=%d in Automatic RTS Mode.\n", cts); datenklo->auto_rts_cts = cts; return; } @@ -247,7 +249,7 @@ static void bcts(void *inst, int cts) datenklo->lines |= TIOCM_CTS; else datenklo->lines &= ~TIOCM_CTS; - PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that BCTS is %s\n", (cts) ? "on" : "off"); + LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that BCTS is %s\n", (cts) ? "on" : "off"); } /* modem changes CD state */ @@ -259,7 +261,7 @@ static void cd(void *inst, int cd) return; if (datenklo->auto_rts) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Received CD=%d in Automatic RTS Mode.\n", cd); + LOGP(DDATENKLO, LOGL_INFO, "Received CD=%d in Automatic RTS Mode.\n", cd); datenklo->auto_rts_cd = cd; return; } @@ -268,7 +270,7 @@ static void cd(void *inst, int cd) datenklo->lines |= TIOCM_CD; else datenklo->lines &= ~TIOCM_CD; - PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that CD is %s\n", (cd) ? "on" : "off"); + LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that CD is %s\n", (cd) ? "on" : "off"); } /* modem changes CD state (back channel) */ @@ -280,7 +282,7 @@ static void bcd(void *inst, int cd) return; if (datenklo->auto_rts) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Received BCD=%d in Automatic RTS Mode.\n", cd); + LOGP(DDATENKLO, LOGL_INFO, "Received BCD=%d in Automatic RTS Mode.\n", cd); datenklo->auto_rts_cd = cd; return; } @@ -289,7 +291,7 @@ static void bcd(void *inst, int cd) datenklo->lines |= TIOCM_CD; else datenklo->lines &= ~TIOCM_CD; - PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that BCD is %s\n", (cd) ? "on" : "off"); + LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that BCD is %s\n", (cd) ? "on" : "off"); } /* modem request bit */ @@ -405,7 +407,7 @@ static int tx(void *inst) if (datenklo->onlcr_char) { datenklo->onlcr_char = 0; data = '\n'; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "ONLCR: sending NL\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "ONLCR: sending NL\n"); goto out; } @@ -414,7 +416,7 @@ again: if (fill == (size_t)datenklo->tx_fifo_full) { /* tell cuse to write again */ - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Set POLLOUT!\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Set POLLOUT!\n"); datenklo->revents |= POLLOUT; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -424,12 +426,12 @@ again: datenklo->auto_rts_on = 0; if (datenklo->tcsetsw) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Transmission finished, applying termios now.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Transmission finished, applying termios now.\n"); memcpy(&datenklo->termios, &datenklo->tcsetsw_termios, sizeof(datenklo->termios)); if (datenklo->tcsetsw == 2) { flush_rx(datenklo); if ((datenklo->revents & POLLIN)) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLIN (flushed)\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLIN (flushed)\n"); datenklo->revents &= ~POLLIN; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -450,26 +452,26 @@ again: /* process output features */ if (datenklo->opost) { if (datenklo->olcuc) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "OLCUC: 0x%02x -> 0x%02x\n", data, toupper(data)); + LOGP(DDATENKLO, LOGL_DEBUG, "OLCUC: 0x%02x -> 0x%02x\n", data, toupper(data)); data = toupper(data); } if (datenklo->onlret && data == '\r') { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "ONLRET: ignore CR\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "ONLRET: ignore CR\n"); goto again; } if (datenklo->ocrnl && data == '\r') { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "OCRNL: CR -> NL\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "OCRNL: CR -> NL\n"); data = '\n'; } if (datenklo->onlcr && data == '\n') { datenklo->onlcr_char = 1; data = '\r'; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "ONLCR: sending CR\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "ONLCR: sending CR\n"); } } out: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Transmitting byte 0x%02x to UART.\n", data); + LOGP(DDATENKLO, LOGL_DEBUG, "Transmitting byte 0x%02x to UART.\n", data); return data; } @@ -480,35 +482,35 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags) datenklo_t *datenklo = (datenklo_t *)inst; size_t space; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Received byte 0x%02x ('%c') from UART.\n", data, (data >= 32 && data <= 126) ? data : '.'); + LOGP(DDATENKLO, LOGL_DEBUG, "Received byte 0x%02x ('%c') from UART.\n", data, (data >= 32 && data <= 126) ? data : '.'); /* process input features */ if (datenklo->ignbrk && (flags & UART_BREAK)) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "IGNBRK: ignore BREAK\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "IGNBRK: ignore BREAK\n"); return; } if (datenklo->istrip && (data & 0x80)) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "ISTRIP: 0x%02x -> 0x%02x\n", data, data & 0x7f); + LOGP(DDATENKLO, LOGL_DEBUG, "ISTRIP: 0x%02x -> 0x%02x\n", data, data & 0x7f); data &= 0x7f; } if (datenklo->inlcr && data == '\n') { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "INLCR: NL -> CR\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "INLCR: NL -> CR\n"); data = '\r'; } if (datenklo->igncr && data == '\r') { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "IGNCR: ignore CR\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "IGNCR: ignore CR\n"); return; } if (datenklo->icrnl && data == '\r') { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "ICRNL: CR -> NL\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "ICRNL: CR -> NL\n"); data = '\n'; } if (datenklo->iuclc) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "IUCLC: 0x%02x -> 0x%02x\n", data, tolower(data)); + LOGP(DDATENKLO, LOGL_DEBUG, "IUCLC: 0x%02x -> 0x%02x\n", data, tolower(data)); data = tolower(data); } if (datenklo->echo) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "ECHO: write to output\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "ECHO: write to output\n"); space = (datenklo->tx_fifo_out - datenklo->tx_fifo_in - 1 + datenklo->tx_fifo_size) % datenklo->tx_fifo_size; if (space) { datenklo->tx_fifo[datenklo->tx_fifo_in++] = data; @@ -519,7 +521,7 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags) /* empty buffer gets data */ if (datenklo->rx_fifo_out == datenklo->rx_fifo_in) { /* tell cuse to read again */ - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Set POLLIN!\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Set POLLIN!\n"); datenklo->revents |= POLLIN; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -528,13 +530,13 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags) if (!space) { err_overflow: - PDEBUG(DDATENKLO, DEBUG_NOTICE, "RX buffer overflow, dropping!\n"); + LOGP(DDATENKLO, LOGL_NOTICE, "RX buffer overflow, dropping!\n"); return; } if (datenklo->parmrk) { if ((flags & (UART_BREAK | UART_PARITY_ERROR))) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "PARMRK: 0x%02x -> 0xff,0x00,0x%02x\n", data, data); + LOGP(DDATENKLO, LOGL_DEBUG, "PARMRK: 0x%02x -> 0xff,0x00,0x%02x\n", data, data); if (space < 3) goto err_overflow; datenklo->rx_fifo[datenklo->rx_fifo_in++] = 0xff; @@ -544,7 +546,7 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags) datenklo->rx_fifo_in %= datenklo->rx_fifo_size; space--; } else if (data == 0xff) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "PARMRK: 0xff -> 0xff,0xff\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "PARMRK: 0xff -> 0xff,0xff\n"); if (space < 2) goto err_overflow; datenklo->rx_fifo[datenklo->rx_fifo_in++] = 0xff; @@ -567,18 +569,18 @@ static void set_lines(datenklo_t *datenklo, int new) int old = datenklo->lines; if (!(old & TIOCM_DTR) && (new & TIOCM_DTR)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns DTR on\n"); + LOGP(DDATENKLO, LOGL_INFO, "Terminal turns DTR on\n"); flush_tx(datenklo); flush_rx(datenklo); am791x_dtr(&datenklo->am791x, 1); } if ((old & TIOCM_DTR) && !(new & TIOCM_DTR)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns DTR off\n"); + LOGP(DDATENKLO, LOGL_INFO, "Terminal turns DTR off\n"); am791x_dtr(&datenklo->am791x, 0); } if (!(old & TIOCM_RTS) && (new & TIOCM_RTS)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns RTS on\n"); + LOGP(DDATENKLO, LOGL_INFO, "Terminal turns RTS on\n"); if (datenklo->auto_rts) new |= TIOCM_CTS | TIOCM_CD; else { @@ -589,7 +591,7 @@ static void set_lines(datenklo_t *datenklo, int new) } } if ((old & TIOCM_RTS) && !(new & TIOCM_RTS)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns RTS off\n"); + LOGP(DDATENKLO, LOGL_INFO, "Terminal turns RTS off\n"); if (datenklo->auto_rts) new &= ~(TIOCM_CTS | TIOCM_CD); else { @@ -609,7 +611,7 @@ static void process_auto_rts(datenklo_t *datenklo) if (!datenklo->auto_rts) return; if (datenklo->auto_rts_on && !datenklo->auto_rts_rts && !datenklo->auto_rts_cd) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Automatically raising RTS.\n"); + LOGP(DDATENKLO, LOGL_INFO, "Automatically raising RTS.\n"); datenklo->auto_rts_rts = 1; if (!datenklo->tx_back) am791x_rts(&datenklo->am791x, 1); @@ -617,7 +619,7 @@ static void process_auto_rts(datenklo_t *datenklo) am791x_brts(&datenklo->am791x, 1); } if (!datenklo->auto_rts_on && datenklo->auto_rts_rts) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Automatically dropping RTS.\n"); + LOGP(DDATENKLO, LOGL_INFO, "Automatically dropping RTS.\n"); datenklo->auto_rts_rts = 0; if (!datenklo->tx_back) am791x_rts(&datenklo->am791x, 0); @@ -634,7 +636,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz) ssize_t rc = 0; #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been read for ioctl (cmd = %d, size = %zu).\n", cmd, out_bufsz); + LOGP(DDATENKLO, LOGL_DEBUG, "Device has been read for ioctl (cmd = %d, size = %zu).\n", cmd, out_bufsz); #endif switch (cmd) { @@ -643,7 +645,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz) if (!out_bufsz) break; #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests termios.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests termios.\n"); #endif memcpy(buf, &datenklo->termios, rc); break; @@ -652,7 +654,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz) if (!out_bufsz) break; #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests line states.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests line states.\n"); #endif status = datenklo->lines | TIOCM_LE | TIOCM_DSR; memcpy(buf, &status, rc); @@ -662,7 +664,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz) if (!out_bufsz) break; #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests window size.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests window size.\n"); #endif struct winsize *winsize = (struct winsize *)buf; winsize->ws_row = 25; @@ -677,7 +679,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz) status = (datenklo->rx_fifo_in - datenklo->rx_fifo_out + datenklo->rx_fifo_size) % datenklo->rx_fifo_size; memcpy(buf, &status, rc); #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests RX buffer fill states.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests RX buffer fill states.\n"); #endif break; case TIOCOUTQ: @@ -685,7 +687,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz) if (!out_bufsz) break; #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests TX buffer fill states.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests TX buffer fill states.\n"); #endif status = (datenklo->tx_fifo_in - datenklo->tx_fifo_out + datenklo->tx_fifo_size) % datenklo->tx_fifo_size; memcpy(buf, &status, rc); @@ -786,15 +788,15 @@ static void set_termios(datenklo_t *datenklo, const void *buf) new_echo = !!(datenklo->termios.c_lflag & ECHO); if (old_baud != new_baud && (!datenklo->force_tx_baud || !datenklo->force_rx_baud)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal changes baud rate to %.1f Baud.\n", new_baud); + LOGP(DDATENKLO, LOGL_INFO, "Terminal changes baud rate to %.1f Baud.\n", new_baud); if ((datenklo->lines & TIOCM_DTR) && !new_baud) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Baudrate is set to 0, we drop DTR\n"); + LOGP(DDATENKLO, LOGL_INFO, "Baudrate is set to 0, we drop DTR\n"); am791x_dtr(&datenklo->am791x, 0); } datenklo->baudrate = new_baud; am791x_mc(&datenklo->am791x, datenklo->mc, datenklo->samplerate, tx_baud_rate(datenklo), rx_baud_rate(datenklo)); if ((datenklo->lines & TIOCM_DTR) && !old_baud) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Baudrate is set from 0, we raise DTR\n"); + LOGP(DDATENKLO, LOGL_INFO, "Baudrate is set from 0, we raise DTR\n"); am791x_dtr(&datenklo->am791x, 1); } } @@ -802,10 +804,10 @@ static void set_termios(datenklo_t *datenklo, const void *buf) if (old_databits != new_databits || old_parity != new_parity || old_stopbits != new_stopbits) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal changes serial mode to %d%c%d.\n", cflag2databits(datenklo->termios.c_cflag), parity2char(cflag2parity(datenklo->termios.c_cflag)), cflag2stopbits(datenklo->termios.c_cflag)); + LOGP(DDATENKLO, LOGL_INFO, "Terminal changes serial mode to %d%c%d.\n", cflag2databits(datenklo->termios.c_cflag), parity2char(cflag2parity(datenklo->termios.c_cflag)), cflag2stopbits(datenklo->termios.c_cflag)); rc = uart_init(&datenklo->uart, datenklo, cflag2databits(datenklo->termios.c_cflag), cflag2parity(datenklo->termios.c_cflag), cflag2stopbits(datenklo->termios.c_cflag), tx, rx); if (rc < 0) - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to initialize UART.\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to initialize UART.\n"); } if (old_stopbits != new_stopbits @@ -835,8 +837,8 @@ static void set_termios(datenklo_t *datenklo, const void *buf) datenklo->onlret = new_onlret; datenklo->olcuc = new_olcuc; datenklo->echo = new_echo; - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal sets serial flags:\n"); - PDEBUG(DDATENKLO, DEBUG_INFO, "%cignbrk %cparmrk %cistrip %cinlcr %cigncr %cicrnl %ciuclc %copost %conlcr %cocrnl %conlret %colcuc %cecho\n", + LOGP(DDATENKLO, LOGL_INFO, "Terminal sets serial flags:\n"); + LOGP(DDATENKLO, LOGL_INFO, "%cignbrk %cparmrk %cistrip %cinlcr %cigncr %cicrnl %ciuclc %copost %conlcr %cocrnl %conlret %colcuc %cecho\n", (datenklo->ignbrk) ? '+' : '-', (datenklo->parmrk) ? '+' : '-', (datenklo->istrip) ? '+' : '-', @@ -862,7 +864,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs size_t space; #ifdef HEAVY_DEBUG - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been written for ioctl (cmd = %d, size = %zu).\n", cmd, in_bufsz); + LOGP(DDATENKLO, LOGL_DEBUG, "Device has been written for ioctl (cmd = %d, size = %zu).\n", cmd, in_bufsz); #endif switch (cmd) { @@ -870,7 +872,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs rc = sizeof(datenklo->termios); if (!in_bufsz) break; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets termios now.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets termios now.\n"); set_termios(datenklo, buf); break; case TCSETSW: @@ -878,9 +880,9 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs rc = sizeof(datenklo->termios); if (!in_bufsz) break; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets termios after draining output buffer.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets termios after draining output buffer.\n"); if (1 || datenklo->tx_fifo_out == datenklo->tx_fifo_in) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Output buffer empty, applying termios now.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Output buffer empty, applying termios now.\n"); set_termios(datenklo, buf); break; } @@ -895,12 +897,12 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs if (!in_bufsz) break; memcpy(&status, buf, rc); - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal flushes buffer (status = %d).\n", status); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal flushes buffer (status = %d).\n", status); if (status == TCIOFLUSH || status == TCOFLUSH) { flush_tx(datenklo); if (!(datenklo->revents & POLLOUT)) { /* tell cuse to write again */ - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Set POLLOUT (flushed)\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Set POLLOUT (flushed)\n"); datenklo->revents |= POLLOUT; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -908,7 +910,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs if (status == TCIOFLUSH || status == TCIFLUSH) { flush_rx(datenklo); if ((datenklo->revents & POLLIN)) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLIN (flushed)\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLIN (flushed)\n"); datenklo->revents &= ~POLLIN; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -916,7 +918,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs break; case TCSBRK: rc = 0; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sends break\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sends break\n"); datenklo->break_bits = tx_baud_rate(datenklo) * 3 / 10; break; case TCSBRKP: @@ -924,7 +926,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs if (!in_bufsz) break; memcpy(&status, buf, rc); - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sends break (duration = %d).\n", status); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sends break (duration = %d).\n", status); if (status == 0) status = 3; if (status > 30) @@ -933,12 +935,12 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs break; case TIOCSBRK: rc = 0; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns break on\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns break on\n"); datenklo->break_on = 1; break; case TIOCCBRK: rc = 0; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns break off\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns break off\n"); datenklo->break_on = 0; break; case TIOCMBIS: @@ -946,7 +948,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs if (!in_bufsz) break; memcpy(&status, buf, rc); - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets line status (0x%x).\n", status); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets line status (0x%x).\n", status); status = datenklo->lines | status; set_lines(datenklo, status); break; @@ -955,7 +957,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs if (!in_bufsz) break; memcpy(&status, buf, rc); - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal clears line status (0x%x).\n", status); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal clears line status (0x%x).\n", status); status = datenklo->lines & ~status; set_lines(datenklo, status); break; @@ -964,30 +966,30 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs if (!in_bufsz) break; memcpy(&status, buf, rc); - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal specifies line status (0x%x).\n", status); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal specifies line status (0x%x).\n", status); set_lines(datenklo, status); break; case TIOCGSID: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOGSID -> ENOTTY\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "TIOGSID -> ENOTTY\n"); rc = -ENOTTY; break; case TIOCGPGRP: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOCGPGRP -> ENOTTY\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "TIOCGPGRP -> ENOTTY\n"); rc = -ENOTTY; break; case TIOCSCTTY: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOCSCTTY -> ENOTTY\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "TIOCSCTTY -> ENOTTY\n"); rc = -ENOTTY; break; case TIOCSPGRP: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOCSPGRP -> ENOTTY\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "TIOCSPGRP -> ENOTTY\n"); rc = -ENOTTY; break; case TIOCSWINSZ: rc = sizeof(struct winsize); if (!in_bufsz) break; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets window size.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets window size.\n"); break; case TCXONC: rc = sizeof(status); @@ -996,15 +998,15 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs memcpy(&status, buf, rc); switch (status) { case TCOOFF: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns off output.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns off output.\n"); datenklo->output_off = 1; break; case TCOON: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns on output.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns on output.\n"); datenklo->output_off = 0; break; case TCIOFF: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns off input.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns off input.\n"); space = (datenklo->rx_fifo_out - datenklo->rx_fifo_in - 1 + datenklo->rx_fifo_size) % datenklo->rx_fifo_size; if (space < 1) break; @@ -1012,7 +1014,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs datenklo->rx_fifo_in %= datenklo->rx_fifo_size; break; case TCION: - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns on input.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns on input.\n"); space = (datenklo->rx_fifo_out - datenklo->rx_fifo_in - 1 + datenklo->rx_fifo_size) % datenklo->rx_fifo_size; if (space < 1) break; @@ -1034,12 +1036,12 @@ static int dk_open(void *inst, int flags) datenklo_t *datenklo = (datenklo_t *)inst; if (datenklo->open_count) { - PDEBUG(DDATENKLO, DEBUG_NOTICE, "Device is busy.\n"); + LOGP(DDATENKLO, LOGL_NOTICE, "Device is busy.\n"); return -EBUSY; } datenklo->open_count++; datenklo->flags = flags; - PDEBUG(DDATENKLO, DEBUG_INFO, "Device has been opened.\n"); + LOGP(DDATENKLO, LOGL_INFO, "Device has been opened.\n"); int status = datenklo->lines | TIOCM_DTR | TIOCM_RTS; set_lines(datenklo, status); @@ -1051,7 +1053,7 @@ static void dk_close(void *inst) { datenklo_t *datenklo = (datenklo_t *)inst; - PDEBUG(DDATENKLO, DEBUG_INFO, "Device has been closed.\n"); + LOGP(DDATENKLO, LOGL_INFO, "Device has been closed.\n"); datenklo->open_count--; int status = datenklo->lines & ~(TIOCM_DTR | TIOCM_RTS); set_lines(datenklo, status); @@ -1071,7 +1073,7 @@ static void debug_data(const char *buf, int count) count--; } text[i] = '\0'; - PDEBUG(DDATENKLO, DEBUG_DEBUG, " \"%s\"\n", text); + LOGP(DDATENKLO, LOGL_DEBUG, " \"%s\"\n", text); } } @@ -1091,7 +1093,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags) if (vmin && vtime) { /* first: start timer */ if (!datenklo->vtimeout) - timer_start(&datenklo->vtimer, (double)vtime * 0.1); + osmo_timer_schedule(&datenklo->vtimer, vtime/10,(vtime % 10) * 100000); /* no data: block (in blocking IO) */ if (fill == 0) { /* special value to tell device there is no data right now, we have to block */ @@ -1104,7 +1106,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags) } /* enough data or timeout or nonblocking IO: stop timer and return what we have */ datenklo->vtimeout = 0; - timer_stop(&datenklo->vtimer); + osmo_timer_del(&datenklo->vtimer); } /* both MIN and TIME are zero */ if (!vmin && !vtime) { @@ -1117,7 +1119,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags) if (!vmin && vtime) { /* first: start timer */ if (!datenklo->vtimeout) - timer_start(&datenklo->vtimer, (double)vtime * 0.1); + osmo_timer_schedule(&datenklo->vtimer, vtime/10,(vtime % 10) * 100000); if (fill == 0) { /* no data and no timeout: block (in blocking IO) */ if (!datenklo->vtimeout) { @@ -1130,7 +1132,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags) } /* data: stop timer and return what we have */ datenklo->vtimeout = 0; - timer_stop(&datenklo->vtimer); + osmo_timer_del(&datenklo->vtimer); } /* MIN is nonzero, TIME is zero */ if (vmin && !vtime) { @@ -1142,7 +1144,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags) /* enough data in buffer: return what we have */ } - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been read from. (fill = %zu)\n", fill); + LOGP(DDATENKLO, LOGL_DEBUG, "Device has been read from. (fill = %zu)\n", fill); /* get data from fifo */ count = 0; @@ -1160,7 +1162,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags) if (!fill) { /* tell cuse not to read anymore */ if ((datenklo->revents & POLLIN)) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLIN (now empty)!\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLIN (now empty)!\n"); datenklo->revents &= ~POLLIN; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -1177,17 +1179,17 @@ static ssize_t dk_write(void *inst, const char *buf, size_t size, int __attribut size_t i; if (!(datenklo->lines & TIOCM_DTR)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Dropping data, DTR is off!\n"); + LOGP(DDATENKLO, LOGL_INFO, "Dropping data, DTR is off!\n"); return -EIO; } if (!(datenklo->lines & TIOCM_RTS)) { - PDEBUG(DDATENKLO, DEBUG_INFO, "Dropping data, RTS is off!\n"); + LOGP(DDATENKLO, LOGL_INFO, "Dropping data, RTS is off!\n"); return -EIO; } if (size > (size_t)datenklo->tx_fifo_size - 1) { - PDEBUG(DDATENKLO, DEBUG_NOTICE, "Device sends us too many data. (size = %zu)\n", size); + LOGP(DDATENKLO, LOGL_NOTICE, "Device sends us too many data. (size = %zu)\n", size); return -EIO; } @@ -1199,7 +1201,7 @@ static ssize_t dk_write(void *inst, const char *buf, size_t size, int __attribut return -EAGAIN; } - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been written to. (space = %zu)\n", space); + LOGP(DDATENKLO, LOGL_DEBUG, "Device has been written to. (space = %zu)\n", space); debug_data(buf, size); if (datenklo->auto_rts) @@ -1215,7 +1217,7 @@ static ssize_t dk_write(void *inst, const char *buf, size_t size, int __attribut if ((datenklo->revents & POLLOUT) && fill >= (size_t)datenklo->tx_fifo_full) { /* tell cuse not to write */ - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLOUT (buffer full)\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLOUT (buffer full)\n"); datenklo->revents &= ~POLLOUT; device_set_poll_events(datenklo->device, datenklo->revents); } @@ -1227,7 +1229,7 @@ static void dk_flush_tx(void *inst) { datenklo_t *datenklo = (datenklo_t *)inst; - PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal sends interrupt while writing, flushing TX buffer\n"); + LOGP(DDATENKLO, LOGL_INFO, "Terminal sends interrupt while writing, flushing TX buffer\n"); flush_tx(datenklo); } @@ -1270,7 +1272,7 @@ static void vtime_timeout(void *data) void datenklo_init_global(void) { if (pthread_mutex_init(&mutex, NULL)) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to init mutex.\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to init mutex.\n"); exit(0); } } @@ -1282,7 +1284,7 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a tcflag_t flag; cc_t *cc; - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Creating Datenklo instance.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Creating Datenklo instance.\n"); memset(datenklo, 0, sizeof(*datenklo)); @@ -1332,7 +1334,7 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a datenklo->device = device_init(datenklo, dev_name, dk_open, dk_close, dk_read, dk_write, dk_ioctl_get, dk_ioctl_set, dk_flush_tx, dk_lock, dk_unlock); if (!datenklo->device) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to attach virtual device '%s' using cuse.\n", dev_name); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to attach virtual device '%s' using cuse.\n", dev_name); rc = -errno; goto error; } @@ -1342,7 +1344,7 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a datenklo->baudrate = cflag2baud(datenklo->termios.c_cflag); rc = am791x_init(&datenklo->am791x, datenklo, am791x_type, datenklo->mc, datenklo->samplerate, tx_baud_rate(datenklo), rx_baud_rate(datenklo), cts, bcts, cd, bcd, td, btd, rd, brd); if (rc < 0) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to initialize AM791X modem chip.\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to initialize AM791X modem chip.\n"); goto error; } @@ -1352,16 +1354,16 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a datenklo->tx_fifo = calloc(datenklo->tx_fifo_size, 1); datenklo->rx_fifo = calloc(datenklo->rx_fifo_size, 1); if (!datenklo->tx_fifo || !datenklo->rx_fifo) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "No mem!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "No mem!\n"); rc = -ENOMEM; goto error; } - timer_init(&datenklo->vtimer, vtime_timeout, datenklo); + osmo_timer_setup(&datenklo->vtimer, vtime_timeout, datenklo); rc = uart_init(&datenklo->uart, datenklo, cflag2databits(datenklo->termios.c_cflag), cflag2parity(datenklo->termios.c_cflag), cflag2stopbits(datenklo->termios.c_cflag), tx, rx); if (rc < 0) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to initialize UART.\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to initialize UART.\n"); goto error; } @@ -1397,7 +1399,7 @@ int datenklo_open_audio(datenklo_t *datenklo, const char *audiodev, int buffer, /* init sound */ datenklo->audio = sound_open(audiodev, NULL, NULL, NULL, channels, 0.0, datenklo->samplerate, datenklo->buffer_size, 1.0, 1.0, 4000.0, 2.0); if (!datenklo->audio) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "No sound device!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "No sound device!\n"); return -EIO; } #endif @@ -1405,28 +1407,28 @@ int datenklo_open_audio(datenklo_t *datenklo, const char *audiodev, int buffer, if (write_rx_wave) { rc = wave_create_record(&datenklo->wave_rx_rec, write_rx_wave, datenklo->samplerate, channels, 1.0); if (rc < 0) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); return rc; } } if (write_tx_wave) { rc = wave_create_record(&datenklo->wave_tx_rec, write_tx_wave, datenklo->samplerate, channels, 1.0); if (rc < 0) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); return rc; } } if (read_rx_wave) { rc = wave_create_playback(&datenklo->wave_rx_play, read_rx_wave, &datenklo->samplerate, &channels, 1.0); if (rc < 0) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); return rc; } } if (read_tx_wave) { rc = wave_create_playback(&datenklo->wave_tx_play, read_tx_wave, &datenklo->samplerate, &channels, 1.0); if (rc < 0) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); return rc; } } @@ -1521,14 +1523,14 @@ void datenklo_main(datenklo_t *datenklo, int loopback) process_auto_rts(datenklo->slave); /* process timers */ - process_timer(); + osmo_select_main(1); #ifdef HAVE_ALSA count = sound_read(datenklo->audio, samples, datenklo->buffer_size, num_chan, rf_level_db); if (count < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to read RX data from audio device (rc = %d)\n", count); + LOGP(DDSP, LOGL_ERROR, "Failed to read RX data from audio device (rc = %d)\n", count); if (count == -EPIPE) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Trying to recover!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Trying to recover!\n"); continue; } break; @@ -1561,9 +1563,9 @@ void datenklo_main(datenklo_t *datenklo, int loopback) count = samplerate / 1000; #endif if (count < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); + LOGP(DDSP, LOGL_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); if (count == -EPIPE) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Trying to recover!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Trying to recover!\n"); continue; } break; @@ -1611,9 +1613,9 @@ void datenklo_main(datenklo_t *datenklo, int loopback) /* write audio */ rc = sound_write(datenklo->audio, samples, power, count, NULL, NULL, num_chan); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); + LOGP(DDSP, LOGL_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); if (rc == -EPIPE) { - PDEBUG(DDATENKLO, DEBUG_ERROR, "Trying to recover!\n"); + LOGP(DDATENKLO, LOGL_ERROR, "Trying to recover!\n"); continue; } break; @@ -1625,8 +1627,6 @@ next_char: switch (c) { case 3: /* quit */ - if (clear_console_text) - clear_console_text(); printf("CTRL+c received, quitting!\n"); quit = 1; goto next_char; @@ -1655,10 +1655,6 @@ next_char: pthread_mutex_lock(&mutex); } - /* get rid of last entry */ - if (clear_console_text) - clear_console_text(); - /* reset terminal */ tcsetattr(0, TCSANOW, &term_orig); @@ -1674,9 +1670,9 @@ next_char: /* cleanup function */ void datenklo_exit(datenklo_t *datenklo) { - PDEBUG(DDATENKLO, DEBUG_DEBUG, "Destroying Datenklo instance.\n"); + LOGP(DDATENKLO, LOGL_DEBUG, "Destroying Datenklo instance.\n"); - timer_exit(&datenklo->vtimer); + osmo_timer_del(&datenklo->vtimer); /* exit device */ if (datenklo->device) diff --git a/src/datenklo/datenklo.h b/src/datenklo/datenklo.h index 31acf72..4094338 100644 --- a/src/datenklo/datenklo.h +++ b/src/datenklo/datenklo.h @@ -52,7 +52,7 @@ typedef struct datenklo { int auto_rts_cts; /* CTS was indicated */ int auto_rts_cd; /* CD was indicated */ int output_off; /* output stopped by flow control */ - struct timer vtimer; /* VTIME timer */ + struct osmo_timer_list vtimer; /* VTIME timer */ int vtimeout; /* when timeout has fired */ /* data fifos */ diff --git a/src/datenklo/device.c b/src/datenklo/device.c index 3379da0..765e184 100644 --- a/src/datenklo/device.c +++ b/src/datenklo/device.c @@ -27,7 +27,7 @@ #include <string.h> #include <unistd.h> #include <errno.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #define __USE_GNU #include <pthread.h> #include <signal.h> @@ -122,7 +122,7 @@ static void cuse_read_interrupt(fuse_req_t req, void *data) if (!device->read_locked) device->lock_cb(); - PDEBUG(DDEVICE, DEBUG_DEBUG, "%s received interrupt from client!\n", device->name); + LOGP(DDEVICE, LOGL_DEBUG, "%s received interrupt from client!\n", device->name); if (device->read_req) { device->read_req = NULL; @@ -167,7 +167,7 @@ static void cuse_device_read(fuse_req_t req, size_t size, off_t off, struct fuse if (device->read_req) { device->unlock_cb(); - PDEBUG(DDEVICE, DEBUG_ERROR, "%s: Got another read(), while first read() has not been replied, please fix.\n", device->name); + LOGP(DDEVICE, LOGL_ERROR, "%s: Got another read(), while first read() has not been replied, please fix.\n", device->name); fuse_reply_err(req, EBUSY); return; } @@ -182,7 +182,7 @@ static void cuse_device_read(fuse_req_t req, size_t size, off_t off, struct fuse /* this means that we block until modem's read() returns 0 or positive value (in nonblocking io, we return -EAGAIN) */ if (!(fi->flags & O_NONBLOCK) && count == -EAGAIN) { - PDEBUG(DDEVICE, DEBUG_DEBUG, "%s has no data available, waiting for data, timer or interrupt.\n", device->name); + LOGP(DDEVICE, LOGL_DEBUG, "%s has no data available, waiting for data, timer or interrupt.\n", device->name); device->read_req = req; device->read_size = size; @@ -216,7 +216,7 @@ static void cuse_write_interrupt(fuse_req_t req, void *data) if (!device->write_locked) device->lock_cb(); - PDEBUG(DDEVICE, DEBUG_DEBUG, "%s received interrupt from client!\n", device->name); + LOGP(DDEVICE, LOGL_DEBUG, "%s received interrupt from client!\n", device->name); if (device->write_req) { device->write_req = NULL; @@ -262,7 +262,7 @@ static void cuse_device_write(fuse_req_t req, const char *buf, size_t size, off_ if (device->write_req) { device->unlock_cb(); - PDEBUG(DDEVICE, DEBUG_ERROR, "%s: Got another write(), while first write() has not been replied, please fix.\n", device->name); + LOGP(DDEVICE, LOGL_ERROR, "%s: Got another write(), while first write() has not been replied, please fix.\n", device->name); fuse_reply_err(req, EBUSY); return; } @@ -271,13 +271,13 @@ static void cuse_device_write(fuse_req_t req, const char *buf, size_t size, off_ /* this means that we block until modem's write() returns 0 or positive value (in nonblocking io, we return -EAGAIN) */ if (!(fi->flags & O_NONBLOCK) && count == -EAGAIN) { - PDEBUG(DDEVICE, DEBUG_DEBUG, "%s has no buffer space available, waiting for space or interrupt.\n", device->name); + LOGP(DDEVICE, LOGL_DEBUG, "%s has no buffer space available, waiting for space or interrupt.\n", device->name); device->write_req = req; device->write_size = size; device->write_buf = malloc(size); if (!buf) { - PDEBUG(DDEVICE, DEBUG_ERROR, "No memory!\n"); + LOGP(DDEVICE, LOGL_ERROR, "No memory!\n"); exit(0); } memcpy(device->write_buf, buf, size); @@ -376,7 +376,7 @@ static void cuse_device_ioctl(fuse_req_t req, int cmd, void *arg, struct fuse_fi } break; default: - PDEBUG(DDEVICE, DEBUG_NOTICE, "%s: receives unknown ioctl: 0x%x\n", device->name, cmd); + LOGP(DDEVICE, LOGL_NOTICE, "%s: receives unknown ioctl: 0x%x\n", device->name, cmd); fuse_reply_err(req, EINVAL); } } @@ -432,7 +432,7 @@ static void cuse_device_flush(fuse_req_t req, struct fuse_file_info *fi) (void)req; (void)fi; device_t *device = get_device_by_thread(); - PDEBUG(DDEVICE, DEBUG_NOTICE, "%s: unhandled flush\n", device->name); + LOGP(DDEVICE, LOGL_NOTICE, "%s: unhandled flush\n", device->name); } static void cuse_device_fsync(fuse_req_t req, int datasync, struct fuse_file_info *fi) @@ -441,7 +441,7 @@ static void cuse_device_fsync(fuse_req_t req, int datasync, struct fuse_file_inf (void)datasync; (void)fi; device_t *device = get_device_by_thread(); - PDEBUG(DDEVICE, DEBUG_NOTICE, "%s: unhandled fsync\n", device->name); + LOGP(DDEVICE, LOGL_NOTICE, "%s: unhandled fsync\n", device->name); } @@ -478,9 +478,9 @@ static void *device_child(void *arg) device->thread_started = 1; - PDEBUG(DDEVICE, DEBUG_INFO, "Device '%s' started.\n", device->name); + LOGP(DDEVICE, LOGL_INFO, "Device '%s' started.\n", device->name); cuse_lowlevel_main(argc, argv, &ci, &cuse_device_clop, NULL); - PDEBUG(DDEVICE, DEBUG_INFO, "Device '%s' terminated.\n", device->name); + LOGP(DDEVICE, LOGL_INFO, "Device '%s' terminated.\n", device->name); device->thread_stopped = 1; @@ -496,7 +496,7 @@ void *device_init(void *inst, const char *name, int (*open)(void *inst, int flag device = calloc(1, sizeof(*device)); if (!device) { - PDEBUG(DDEVICE, DEBUG_ERROR, "No memory!\n"); + LOGP(DDEVICE, LOGL_ERROR, "No memory!\n"); errno = ENOMEM; goto error; } @@ -514,7 +514,7 @@ void *device_init(void *inst, const char *name, int (*open)(void *inst, int flag rc = pthread_create(&device->thread, NULL, device_child, device); if (rc < 0) { - PDEBUG(DDEVICE, DEBUG_ERROR, "Failed to create device thread!\n"); + LOGP(DDEVICE, LOGL_ERROR, "Failed to create device thread!\n"); errno = -rc; goto error; } diff --git a/src/datenklo/main.c b/src/datenklo/main.c index 43a0b74..5a3fb5e 100644 --- a/src/datenklo/main.c +++ b/src/datenklo/main.c @@ -26,9 +26,9 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../liboptions/options.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libfsk/fsk.h" #include "../libwave/wave.h" #include "../libdisplay/display.h" @@ -80,6 +80,7 @@ void print_help(const char *arg0) printf(" --config [~/]<path to config file>\n"); printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n"); printf(" Each line in config file is one option, '-' or '--' must not be given!\n"); + logging_print_help(); printf(" -T --am791x-type 7910 | 7911\n"); printf(" Give modem chip type. (Default = 791%d)\n", am791x_type); printf(" -M --mc <mode>\n"); @@ -158,13 +159,11 @@ static int handle_options(int short_option, int argi, char **argv) print_help(argv[0]); return 0; case 'v': - if (!strcasecmp(argv[argi], "list")) { - debug_list_cat(); + rc = parse_logging_opt(argv[argi]); + if (rc > 0) return 0; - } - rc = parse_debug_opt(argv[argi]); if (rc < 0) { - fprintf(stderr, "Failed to parse debug option, please use -h for help.\n"); + fprintf(stderr, "Failed to parse logging option, please use -h for help.\n"); return rc; } break; @@ -265,6 +264,8 @@ int main(int argc, char *argv[]) int rc, argi; int i; + logging_init(); + /* handle options / config file */ add_options(); rc = options_config_file(argc, argv, "~/.osmocom/analog/datenklo.conf", handle_options); @@ -325,3 +326,5 @@ fail: return 0; } +void osmo_cc_set_log_cat(void) {} + diff --git a/src/datenklo/uart.c b/src/datenklo/uart.c index 1521410..b45f44a 100644 --- a/src/datenklo/uart.c +++ b/src/datenklo/uart.c @@ -21,7 +21,7 @@ #include <stdint.h> #include <string.h> #include <stdlib.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "uart.h" static uint32_t calc_parity(uint32_t data, uint8_t data_bits, enum uart_parity parity) @@ -56,13 +56,13 @@ int uart_init(uart_t *uart, void *inst, uint8_t data_bits, enum uart_parity pari uart->rx_cb = rx_cb; uart->data_bits = data_bits; if (uart->data_bits > 9) { - PDEBUG(DUART, DEBUG_ERROR, "Illegal number of data bits, please fix!\n"); + LOGP(DUART, LOGL_ERROR, "Illegal number of data bits, please fix!\n"); abort(); } uart->parity = parity; uart->stop_bits = stop_bits; if (uart->stop_bits < 1 || uart->stop_bits > 2) { - PDEBUG(DUART, DEBUG_ERROR, "Illegal number of stop bits, please fix!\n"); + LOGP(DUART, LOGL_ERROR, "Illegal number of stop bits, please fix!\n"); abort(); } uart->tx_pos = -1; diff --git a/src/dcf77/Makefile.am b/src/dcf77/Makefile.am index ce23ac8..5b7fa22 100644 --- a/src/dcf77/Makefile.am +++ b/src/dcf77/Makefile.am @@ -13,13 +13,14 @@ dcf77_SOURCES = \ dcf77_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ $(top_builddir)/src/libsound/libsound.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ $(ALSA_LIBS) \ -lm endif diff --git a/src/dcf77/dcf77.c b/src/dcf77/dcf77.c index 5314803..3e7d9bb 100644 --- a/src/dcf77/dcf77.c +++ b/src/dcf77/dcf77.c @@ -26,7 +26,7 @@ #include <inttypes.h> #include <stdlib.h> #include <math.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "dcf77.h" #include "weather.h" @@ -380,7 +380,7 @@ dcf77_t *dcf77_create(int samplerate, int use_tx, int use_rx, int test_tone) dcf77 = calloc(1, sizeof(*dcf77)); if (!dcf77) { - PDEBUG(DDCF77, DEBUG_ERROR, "No mem!\n"); + LOGP(DDCF77, LOGL_ERROR, "No mem!\n"); return NULL; } tx = &dcf77->tx; @@ -429,7 +429,7 @@ dcf77_t *dcf77_create(int samplerate, int use_tx, int use_rx, int test_tone) rx->delay_size = ceil((double)SAMPLE_CLOCK * 0.1); rx->delay_buffer = calloc(rx->delay_size, sizeof(*rx->delay_buffer)); if (!rx->delay_buffer) { - PDEBUG(DDCF77, DEBUG_ERROR, "No mem!\n"); + LOGP(DDCF77, LOGL_ERROR, "No mem!\n"); return NULL; } @@ -444,9 +444,9 @@ dcf77_t *dcf77_create(int samplerate, int use_tx, int use_rx, int test_tone) } if (tx->enable) - PDEBUG(DDCF77, DEBUG_INFO, "DCF77 transmitter has been created.\n"); + LOGP(DDCF77, LOGL_INFO, "DCF77 transmitter has been created.\n"); if (rx->enable) - PDEBUG(DDCF77, DEBUG_INFO, "DCF77 receiver has been created.\n"); + LOGP(DDCF77, LOGL_INFO, "DCF77 receiver has been created.\n"); #if 0 void rx_frame_test(dcf77_t *dcf77, const char *string); @@ -467,7 +467,7 @@ void dcf77_destroy(dcf77_t *dcf77) free(dcf77); } - PDEBUG(DDCF77, DEBUG_INFO, "DCF77 has been destroyed.\n"); + LOGP(DDCF77, LOGL_INFO, "DCF77 has been destroyed.\n"); } static void display_weather_temperature(const char *desc, uint32_t weather) @@ -512,7 +512,7 @@ time_t dcf77_start_weather(time_t timestamp, int region, int offset) hour = (19 + (region - 60) / 20) % 24; } min = (region % 20) * 3; - PDEBUG(DDCF77, DEBUG_INFO, "Setting UTC time for region %d to %02d:%02d minutes.\n", region, hour, min); + LOGP(DDCF77, LOGL_INFO, "Setting UTC time for region %d to %02d:%02d minutes.\n", region, hour, min); /* reset to 0:00 UTC at same day */ timestamp -= (timestamp % 86400); @@ -521,7 +521,7 @@ time_t dcf77_start_weather(time_t timestamp, int region, int offset) timestamp += hour * 3600 + min * 60; /* substract offset */ - PDEBUG(DDCF77, DEBUG_INFO, "Setting timestamp offset to %d minutes.\n", offset); + LOGP(DDCF77, LOGL_INFO, "Setting timestamp offset to %d minutes.\n", offset); timestamp -= 60 * offset; return timestamp; @@ -576,7 +576,7 @@ static uint64_t generate_weather(time_t timestamp, int minute, int utc_hour, int /* generate weather data */ timestamp -= 120; weather = 0; - PDEBUG(DFRAME, DEBUG_INFO, "Encoding weather for dataset %d/480\n", dataset); + LOGP(DFRAME, LOGL_INFO, "Encoding weather for dataset %d/480\n", dataset); printf("Peparing Weather INFO\n"); printf("---------------------\n"); printf("Time (UTC): %02d:%02d\n", (int)(timestamp / 3600) % 24, (int)(timestamp / 60) % 60); @@ -694,14 +694,14 @@ static uint16_t tx_weather(dcf77_tx_t *tx, time_t timestamp, int minute, int hou utc_hour += 24; /* in index 0 we transmit minute + 1 (next minute), so we substract 1 */ tx->weather_cipher = generate_weather(timestamp, (minute + 59) % 60, utc_hour, tx->weather_day, tx->weather_night, tx->extreme, tx->rain, tx->wind_dir, tx->wind_bft, tx->temperature_day, tx->temperature_night); - PDEBUG(DFRAME, DEBUG_INFO, "Transmitting first chunk of weather info.\n"); + LOGP(DFRAME, LOGL_INFO, "Transmitting first chunk of weather info.\n"); chunk = (tx->weather_cipher & 0x3f) << 1; /* bit 2-7 */ chunk |= (tx->weather_cipher & 0x0fc0) << 2; /* bit 9-14 */ tx->weather_cipher >>= 12; return chunk; } - PDEBUG(DFRAME, DEBUG_INFO, "Transmitting %s chunk of weather info.\n", (index == 1) ? "second" : "third"); + LOGP(DFRAME, LOGL_INFO, "Transmitting %s chunk of weather info.\n", (index == 1) ? "second" : "third"); chunk = tx->weather_cipher & 0x3fff; tx->weather_cipher >>= 14; return chunk; @@ -759,7 +759,7 @@ static char tx_symbol(dcf77_t *dcf77, time_t timestamp, int second) else zone = 2; - PDEBUG(DDCF77, DEBUG_NOTICE, "The time transmitting: %s %s %d %02d:%02d:%02d %s %02d\n", week_day[wday], month_name[tm->tm_mon + 1], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, time_zone[zone], tm->tm_year + 1900); + LOGP(DDCF77, LOGL_NOTICE, "The time transmitting: %s %s %d %02d:%02d:%02d %s %02d\n", week_day[wday], month_name[tm->tm_mon + 1], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, time_zone[zone], tm->tm_year + 1900); if ((tm->tm_isdst > 0) != (isdst_next_hour > 0)) frame |= (uint64_t)1 << 16; @@ -808,9 +808,9 @@ static char tx_symbol(dcf77_t *dcf77, time_t timestamp, int second) tx->data_string[j++] = '0' + ((frame >> i) & 1); } tx->data_string[j] = '\0'; - PDEBUG(DDSP, DEBUG_INFO, "Start transmission of frame:\n"); - PDEBUG(DDSP, DEBUG_INFO, "0 Wetterdaten Info 1 Minute P StundeP Tag WoT Monat Jahr P\n"); - PDEBUG(DDSP, DEBUG_INFO, "%s\n", tx->data_string); + LOGP(DDSP, LOGL_INFO, "Start transmission of frame:\n"); + LOGP(DDSP, LOGL_INFO, "0 Wetterdaten Info 1 Minute P StundeP Tag WoT Monat Jahr P\n"); + LOGP(DDSP, LOGL_INFO, "%s\n", tx->data_string); } if (second == 59) @@ -818,7 +818,7 @@ static char tx_symbol(dcf77_t *dcf77, time_t timestamp, int second) else symbol = ((tx->data_frame >> second) & 1) + '0'; - PDEBUG(DDSP, DEBUG_DEBUG, "Trasmitting symbol '%c' (Bit %d)\n", symbol, second); + LOGP(DDSP, LOGL_DEBUG, "Trasmitting symbol '%c' (Bit %d)\n", symbol, second); return symbol; } @@ -910,7 +910,7 @@ static void display_weather(uint32_t weather, int minute, int utc_hour) int dataset = ((utc_hour + 2) % 24) * 20 + (minute / 3); /* data sets since 22:00 UTC */ int value; - PDEBUG(DFRAME, DEBUG_INFO, "Decoding weather for dataset %d/480\n", dataset); + LOGP(DFRAME, LOGL_INFO, "Decoding weather for dataset %d/480\n", dataset); printf("Received Weather INFO\n"); printf("---------------------\n"); printf("Time (UTC): %02d:%02d\n", utc_hour, minute); @@ -985,7 +985,7 @@ static void rx_weather(dcf77_rx_t *rx, int minute, int hour, int zone, uint64_t int32_t weather; if (rx->weather_index == 0 && index != 0) { - PDEBUG(DFRAME, DEBUG_INFO, "Skipping weather info chunk, waiting for new start of weather info.\n"); + LOGP(DFRAME, LOGL_INFO, "Skipping weather info chunk, waiting for new start of weather info.\n"); return; } @@ -995,15 +995,15 @@ static void rx_weather(dcf77_rx_t *rx, int minute, int hour, int zone, uint64_t rx->weather_cipher |= (frame >> 3) & 0x0fc0; /* bit 9-14 */ rx->weather_index++; if (((frame & 0x0002)) || ((frame & 0x0100)) || !rx->weather_cipher) { - PDEBUG(DFRAME, DEBUG_INFO, "There is no weather info in this received minute.\n"); + LOGP(DFRAME, LOGL_INFO, "There is no weather info in this received minute.\n"); rx_weather_reset(rx); return; } - PDEBUG(DFRAME, DEBUG_INFO, "Got first chunk of weather info.\n"); + LOGP(DFRAME, LOGL_INFO, "Got first chunk of weather info.\n"); return; } if (rx->weather_index == 1 && index == 1) { - PDEBUG(DFRAME, DEBUG_INFO, "Got second chunk of weather info.\n"); + LOGP(DFRAME, LOGL_INFO, "Got second chunk of weather info.\n"); rx->weather_cipher |= (frame << 11) & 0x3fff000; /* bit 1-14 */ rx->weather_key |= (frame >> 21) & 0x7f; rx->weather_key |= ((frame >> 29) & 0x3f) << 8; @@ -1015,11 +1015,11 @@ static void rx_weather(dcf77_rx_t *rx, int minute, int hour, int zone, uint64_t return; } if (rx->weather_index == 2 && index == 2) { - PDEBUG(DFRAME, DEBUG_INFO, "Got third chunk of weather info.\n"); + LOGP(DFRAME, LOGL_INFO, "Got third chunk of weather info.\n"); rx->weather_cipher |= (frame << 25) & 0xfffc000000; /* bit 1-14 */ weather = weather_decode(rx->weather_cipher, rx->weather_key); if (weather < 0) - PDEBUG(DFRAME, DEBUG_NOTICE, "Failed to decrypt weather info, checksum error.\n"); + LOGP(DFRAME, LOGL_NOTICE, "Failed to decrypt weather info, checksum error.\n"); else { /* convert hour to UTC */ utc_hour = hour - 1; @@ -1035,7 +1035,7 @@ static void rx_weather(dcf77_rx_t *rx, int minute, int hour, int zone, uint64_t } rx_weather_reset(rx); - PDEBUG(DFRAME, DEBUG_INFO, "Got weather info chunk out of order, waiting for new start of weather info.\n"); + LOGP(DFRAME, LOGL_INFO, "Got weather info chunk out of order, waiting for new start of weather info.\n"); } /* decode time from received data */ @@ -1050,14 +1050,14 @@ static void rx_frame(dcf77_rx_t *rx, uint64_t frame) int year_one, year_ten, year = -1; uint64_t p; - PDEBUG(DFRAME, DEBUG_INFO, "Bit 0 is '0'? : %s\n", ((frame >> 0) & 1) ? "no" : "yes"); - PDEBUG(DFRAME, DEBUG_INFO, "Bits 1..14 : 0x%04x\n", (int)(frame >> 1) & 0x3fff); - PDEBUG(DFRAME, DEBUG_INFO, "Call Bit : %d\n", (int)(frame >> 15) & 1); - PDEBUG(DFRAME, DEBUG_INFO, "Change Time Zone : %s\n", ((frame >> 16) & 1) ? "yes" : "no"); + LOGP(DFRAME, LOGL_INFO, "Bit 0 is '0'? : %s\n", ((frame >> 0) & 1) ? "no" : "yes"); + LOGP(DFRAME, LOGL_INFO, "Bits 1..14 : 0x%04x\n", (int)(frame >> 1) & 0x3fff); + LOGP(DFRAME, LOGL_INFO, "Call Bit : %d\n", (int)(frame >> 15) & 1); + LOGP(DFRAME, LOGL_INFO, "Change Time Zone : %s\n", ((frame >> 16) & 1) ? "yes" : "no"); zone = ((frame >> 17) & 3); - PDEBUG(DFRAME, DEBUG_INFO, "Time Zone : %s\n", time_zone[zone]); - PDEBUG(DFRAME, DEBUG_INFO, "Add Leap Second : %s\n", ((frame >> 19) & 1) ? "yes" : "no"); - PDEBUG(DFRAME, DEBUG_INFO, "Bit 20 is '1'? : %s\n", ((frame >> 20) & 1) ? "yes" : "no"); + LOGP(DFRAME, LOGL_INFO, "Time Zone : %s\n", time_zone[zone]); + LOGP(DFRAME, LOGL_INFO, "Add Leap Second : %s\n", ((frame >> 19) & 1) ? "yes" : "no"); + LOGP(DFRAME, LOGL_INFO, "Bit 20 is '1'? : %s\n", ((frame >> 20) & 1) ? "yes" : "no"); minute_one = (frame >> 21 & 0xf); minute_ten = ((frame >> 25) & 0x7); @@ -1066,10 +1066,10 @@ static void rx_frame(dcf77_rx_t *rx, uint64_t frame) p = p ^ (p >> 2); p = p ^ (p >> 1); if (minute_one > 9 || minute_ten > 5 || (p & 1)) - PDEBUG(DFRAME, DEBUG_INFO, "Minute : ???\n"); + LOGP(DFRAME, LOGL_INFO, "Minute : ???\n"); else { minute = minute_ten * 10 + minute_one; - PDEBUG(DFRAME, DEBUG_INFO, "Minute : %02d\n", minute); + LOGP(DFRAME, LOGL_INFO, "Minute : %02d\n", minute); } hour_one = (frame >> 29 & 0xf); @@ -1079,10 +1079,10 @@ static void rx_frame(dcf77_rx_t *rx, uint64_t frame) p = p ^ (p >> 2); p = p ^ (p >> 1); if (hour_one > 9 || hour_ten > 2 || (hour_ten == 2 && hour_one > 3) || (p & 1)) - PDEBUG(DFRAME, DEBUG_INFO, "Hour : ???\n"); + LOGP(DFRAME, LOGL_INFO, "Hour : ???\n"); else { hour = hour_ten * 10 + hour_one; - PDEBUG(DFRAME, DEBUG_INFO, "Hour : %02d\n", hour); + LOGP(DFRAME, LOGL_INFO, "Hour : %02d\n", hour); } day_one = (frame >> 36 & 0xf); @@ -1099,34 +1099,34 @@ static void rx_frame(dcf77_rx_t *rx, uint64_t frame) p = p ^ (p >> 2); p = p ^ (p >> 1); if (day_one > 9 || day_ten > 3 || (day_ten == 3 && day_one > 1) || (day_ten == 0 && day_one == 0) || (p & 1)) - PDEBUG(DFRAME, DEBUG_INFO, "Day : ???\n"); + LOGP(DFRAME, LOGL_INFO, "Day : ???\n"); else { day = day_ten * 10 + day_one; - PDEBUG(DFRAME, DEBUG_INFO, "Day : %d\n", day); + LOGP(DFRAME, LOGL_INFO, "Day : %d\n", day); } if (wday < 1 || wday > 7 || (p & 1)) { - PDEBUG(DFRAME, DEBUG_INFO, "Week Day : ???\n"); + LOGP(DFRAME, LOGL_INFO, "Week Day : ???\n"); wday = -1; } else - PDEBUG(DFRAME, DEBUG_INFO, "Week Day : %s\n", week_day[wday]); + LOGP(DFRAME, LOGL_INFO, "Week Day : %s\n", week_day[wday]); if (month_one > 9 || month_ten > 1 || (month_ten == 1 && month_one > 2) || (month_ten == 0 && month_one == 0) || (p & 1)) - PDEBUG(DFRAME, DEBUG_INFO, "Month : ???\n"); + LOGP(DFRAME, LOGL_INFO, "Month : ???\n"); else { month = month_ten * 10 + month_one; - PDEBUG(DFRAME, DEBUG_INFO, "Month : %d\n", month); + LOGP(DFRAME, LOGL_INFO, "Month : %d\n", month); } if (year_one > 9 || year_ten > 9 || (p & 1)) - PDEBUG(DFRAME, DEBUG_INFO, "Year : ???\n"); + LOGP(DFRAME, LOGL_INFO, "Year : ???\n"); else { year = year_ten * 10 + year_one; - PDEBUG(DFRAME, DEBUG_INFO, "Year : %02d\n", year); + LOGP(DFRAME, LOGL_INFO, "Year : %02d\n", year); } if (minute >= 0 && hour >= 0 && day >= 0 && wday >= 0 && month >= 0 && year >= 0) { - PDEBUG(DDCF77, DEBUG_NOTICE, "The received time is: %s %s %d %02d:%02d:00 %s 20%02d\n", week_day[wday], month_name[month], day, hour, minute, time_zone[zone], year); + LOGP(DDCF77, LOGL_NOTICE, "The received time is: %s %s %d %02d:%02d:00 %s 20%02d\n", week_day[wday], month_name[month], day, hour, minute, time_zone[zone], year); rx_weather(rx, minute, hour, zone, frame); } else { - PDEBUG(DDCF77, DEBUG_NOTICE, "The received time is invalid!\n"); + LOGP(DDCF77, LOGL_NOTICE, "The received time is invalid!\n"); rx_weather_reset(rx); } } @@ -1151,11 +1151,11 @@ static void rx_symbol(dcf77_t *dcf77, char symbol) dcf77_rx_t *rx = &dcf77->rx; double second = -NAN; - PDEBUG(DDSP, DEBUG_DEBUG, "Received symbol '%c'\n", symbol); + LOGP(DDSP, LOGL_DEBUG, "Received symbol '%c'\n", symbol); if (!rx->data_receive) { if (symbol == 'm') { - PDEBUG(DDSP, DEBUG_INFO, "Reception of frame has started\n"); + LOGP(DDSP, LOGL_INFO, "Reception of frame has started\n"); rx->data_receive = 1; rx->data_index = 0; rx->string_index = 0; @@ -1167,20 +1167,20 @@ static void rx_symbol(dcf77_t *dcf77, char symbol) rx->data_string[rx->string_index] = '\0'; rx->data_index = 0; rx->string_index = 0; - PDEBUG(DDSP, DEBUG_INFO, "Received complete frame:\n"); - PDEBUG(DDSP, DEBUG_INFO, "0 Wetterdaten Info 1 Minute P StundeP Tag WoT Monat Jahr P\n"); - PDEBUG(DDSP, DEBUG_INFO, "%s\n", rx->data_string); + LOGP(DDSP, LOGL_INFO, "Received complete frame:\n"); + LOGP(DDSP, LOGL_INFO, "0 Wetterdaten Info 1 Minute P StundeP Tag WoT Monat Jahr P\n"); + LOGP(DDSP, LOGL_INFO, "%s\n", rx->data_string); rx_frame(rx, rx->data_frame); second = 0; } else { - PDEBUG(DDSP, DEBUG_INFO, "Short read, frame too short\n"); + LOGP(DDSP, LOGL_INFO, "Short read, frame too short\n"); rx->data_index = 0; rx->string_index = 0; rx_weather_reset(rx); } } else { if (rx->data_index == 59) { - PDEBUG(DDSP, DEBUG_INFO, "Long read, frame too long\n"); + LOGP(DDSP, LOGL_INFO, "Long read, frame too long\n"); rx->data_receive = 0; rx_weather_reset(rx); } else { @@ -1312,5 +1312,3 @@ void dcf77_decode(dcf77_t *dcf77, sample_t *samples, int length) } } - - diff --git a/src/dcf77/main.c b/src/dcf77/main.c index c9d4dcc..8a59ea6 100755 --- a/src/dcf77/main.c +++ b/src/dcf77/main.c @@ -28,7 +28,7 @@ #include <sched.h> #include <time.h> #include <math.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "../libsample/sample.h" #include "../libsound/sound.h" @@ -146,7 +146,7 @@ void print_help(void) printf(" --config [~/]<path to config file>\n"); printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n"); printf(" Each line in config file is one option, '-' or '--' must not be given!\n"); - debug_print_help(); + logging_print_help(); printf(" -a --audio-device hw:<card>,<device>\n"); printf(" Sound card and device number (default = '%s')\n", dsp_device); printf(" -s --samplerate <rate>\n"); @@ -253,13 +253,11 @@ static int handle_options(int short_option, int argi, char **argv) print_help(); return 0; case 'v': - if (!strcasecmp(argv[argi], "list")) { - debug_list_cat(); + rc = parse_logging_opt(argv[argi]); + if (rc > 0) return 0; - } - rc = parse_debug_opt(argv[argi]); if (rc < 0) { - fprintf(stderr, "Failed to parse debug option, please use -h for help.\n"); + fprintf(stderr, "Failed to parse logging option, please use -h for help.\n"); return rc; } break; @@ -416,14 +414,14 @@ static int get_char() int soundif_open(const char *audiodev, int samplerate, int buffer_size) { if (!audiodev || !audiodev[0]) { - PDEBUG(DDSP, DEBUG_ERROR, "No audio device given!\n"); + LOGP(DDSP, LOGL_ERROR, "No audio device given!\n"); return -EINVAL; } /* open audiodev */ soundif = sound_open(audiodev, NULL, NULL, NULL, (double_amplitude) ? 2 : 1, 0.0, samplerate, buffer_size, 1.0, 1.0, 0.0, 2.0); if (!soundif) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to open sound device!\n"); + LOGP(DDSP, LOGL_ERROR, "Failed to open sound device!\n"); return -EIO; } @@ -433,7 +431,7 @@ int soundif_open(const char *audiodev, int samplerate, int buffer_size) void soundif_start(void) { sound_start(soundif); - PDEBUG(DDSP, DEBUG_DEBUG, "Starting audio stream!\n"); + LOGP(DDSP, LOGL_DEBUG, "Starting audio stream!\n"); } void soundif_close(void) @@ -456,7 +454,7 @@ void soundif_work(int buffer_size) /* encode and write */ count = sound_get_tosend(soundif, buffer_size); if (count < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); + LOGP(DDSP, LOGL_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); return; } if (count) { @@ -467,7 +465,7 @@ void soundif_work(int buffer_size) } rc = sound_write(soundif, samples, NULL, count, NULL, NULL, (double_amplitude) ? 2 : 1); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); + LOGP(DDSP, LOGL_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); return; } } @@ -475,7 +473,7 @@ void soundif_work(int buffer_size) /* read */ count = sound_read(soundif, samples, buffer_size, 1, rf_level_db); if (count < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to read from audio device (rc = %d)!\n", count); + LOGP(DDSP, LOGL_ERROR, "Failed to read from audio device (rc = %d)!\n", count); return; } @@ -491,6 +489,8 @@ int main(int argc, char *argv[]) double begin_time, now, sleep; char c; + logging_init(); + /* handle options / config file */ add_options(); rc = options_config_file(argc, argv, "~/.osmocom/dcf77/dcf77.conf", handle_options); @@ -642,3 +642,5 @@ error: return 0; } +void osmo_cc_set_log_cat(void) {} + diff --git a/src/dcf77/weather.c b/src/dcf77/weather.c index 41b7824..e893ce3 100644 --- a/src/dcf77/weather.c +++ b/src/dcf77/weather.c @@ -7,7 +7,7 @@ https://github.com/tobozo/esp32-dcf77-weatherman/blob/master/dcf77.cpp #include <stdio.h> #include <stdint.h> #include <endian.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "weather.h" /// Container zum Konvertieren zwischen 4 Bytes und Uint. @@ -536,9 +536,9 @@ int32_t weather_decode(uint64_t cipher, uint64_t key) weather = GetWeatherFromPlain(PlainBytes); #ifdef DEBUG_CIPER - printf("cipher=%s\n", debug_hex(CipherBytes, 5)); - printf("key =%s\n", debug_hex(KeyBytes, 5)); - printf("plain =%s\n", debug_hex(PlainBytes, 5)); + printf("cipher=%s\n", osmo_hexdump(CipherBytes, 5)); + printf("key =%s\n", osmo_hexdump(KeyBytes, 5)); + printf("plain =%s\n", osmo_hexdump(PlainBytes, 5)); if (weather < 0) printf("weather=error\n"); else @@ -569,9 +569,9 @@ uint64_t weather_encode(uint32_t weather, uint64_t key) CipherBytes = Encrypt(PlainBytes, KeyBytes); #ifdef DEBUG_CIPER - printf("plain =%s\n", debug_hex(PlainBytes, 5)); - printf("key =%s\n", debug_hex(KeyBytes, 5)); - printf("cipher=%s\n", debug_hex(CipherBytes, 5)); + printf("plain =%s\n", osmo_hexdump(PlainBytes, 5)); + printf("key =%s\n", osmo_hexdump(KeyBytes, 5)); + printf("cipher=%s\n", osmo_hexdump(CipherBytes, 5)); #endif for (i = 0; i < 5; i++) diff --git a/src/eurosignal/Makefile.am b/src/eurosignal/Makefile.am index ab7b654..d16abc0 100644 --- a/src/eurosignal/Makefile.am +++ b/src/eurosignal/Makefile.am @@ -16,13 +16,9 @@ eurosignal_LDADD = \ $(COMMON_LA) \ ../anetz/libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfsk/libfsk.a \ @@ -30,8 +26,10 @@ eurosignal_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/eurosignal/dsp.c b/src/eurosignal/dsp.c index dc8bf92..1e2dc10 100644 --- a/src/eurosignal/dsp.c +++ b/src/eurosignal/dsp.c @@ -26,7 +26,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "eurosignal.h" #include "dsp.h" @@ -105,11 +105,11 @@ void dsp_init(int samplerate) { int i; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating phase shiftings for tones.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating phase shiftings for tones.\n"); for (i = 0; dsp_digits[i].digit; i++) dsp_digits[i].phaseshift65536 = 65536.0 / ((double)samplerate / dsp_digits[i].frequency); - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table for tones.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine table for tones.\n"); for (i = 0; i < 65536; i++) dsp_tone[i] = sin((double)i / 65536.0 * 2.0 * PI); } @@ -119,7 +119,7 @@ int dsp_init_sender(euro_t *euro, int samplerate, int fm) { int rc = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for 'Sender'.\n"); /* set modulation parameters */ if (fm) @@ -154,7 +154,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_sender(euro_t *euro) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for 'Sender'.\n"); /* cleanup demodulator */ fm_demod_exit(&euro->rx_demod); @@ -201,7 +201,7 @@ static void tone_decode(euro_t *euro, sample_t *samples, int length) case 'I': /* pause tone */ if (euro->rx_digit_count == DIGIT_DETECT) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected Idle tone, starting.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected Idle tone, starting.\n"); euro->rx_digit_receiving = 1; euro->rx_digit_index = 0; euro->rx_timeout_count = 0; @@ -213,7 +213,7 @@ static void tone_decode(euro_t *euro, sample_t *samples, int length) break; if (euro->rx_digit_count == DIGIT_DETECT) { /* out of range tone */ - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected tone out of range, aborting.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected tone out of range, aborting.\n"); euro->rx_digit_receiving = 0; } break; @@ -225,7 +225,7 @@ static void tone_decode(euro_t *euro, sample_t *samples, int length) if (euro->rx_digit_count == DIGIT_DETECT) { double level; level = sqrt(I[i] * I[i] + Q[i] * Q[i]) * 2; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected digit '%s' (level = %.0f%%)\n", digit_to_name(digit), level * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected digit '%s' (level = %.0f%%)\n", digit_to_name(digit), level * 100.0); display_measurements_update(euro->dmp_tone_level, level * 100.0, 0.0); euro->rx_digits[euro->rx_digit_index] = digit; euro->rx_digit_index++; @@ -243,7 +243,7 @@ static void tone_decode(euro_t *euro, sample_t *samples, int length) if (euro->rx_digit_receiving && euro->rx_digit_index) { euro->rx_timeout_count++; if (euro->rx_timeout_count == TIMEOUT_DETECT) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Timeout receiving, aborting.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Timeout receiving, aborting.\n"); euro->rx_digit_receiving = 0; } } @@ -280,18 +280,18 @@ static void tone_send(euro_t *euro, sample_t *samples, int length) euro->tx_time -= PAUSE_DURATION; euro_get_id(euro, euro->tx_digits); euro->tx_digit_index = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Sending digit '%s'\n", digit_to_name(euro->tx_digits[0])); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Sending digit '%s'\n", digit_to_name(euro->tx_digits[0])); euro->tx_phaseshift65536 = digit_to_phaseshift65536(euro->tx_digits[0]); } } else { if (euro->tx_time >= DIGIT_DURATION) { euro->tx_time -= DIGIT_DURATION; if (++euro->tx_digit_index == 6) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Sending Idle tone'\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Sending Idle tone'\n"); euro->tx_digits[0] = '\0'; euro->tx_phaseshift65536 = digit_to_phaseshift65536('I'); } else { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Sending digit '%s'\n", digit_to_name(euro->tx_digits[euro->tx_digit_index])); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Sending digit '%s'\n", digit_to_name(euro->tx_digits[euro->tx_digit_index])); euro->tx_phaseshift65536 = digit_to_phaseshift65536(euro->tx_digits[euro->tx_digit_index]); } } diff --git a/src/eurosignal/eurosignal.c b/src/eurosignal/eurosignal.c index d23a500..e09b91c 100644 --- a/src/eurosignal/eurosignal.c +++ b/src/eurosignal/eurosignal.c @@ -26,22 +26,22 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "eurosignal.h" #include "dsp.h" /* announcement timers */ -#define ANSWER_TIME 1.0 /* wait after answer */ -#define OOO_TIME 3.8 /* announcement 1.7 s, pause 2.1 s */ -#define UNASSIGNED_TIME1 2.2 /* announcement 2.2 s s */ -#define UNASSIGNED_TIME2 2.9 /* announcement 2.2 s, pause 0.7 s */ -#define DEGRADED_TIME 4.95 /* announcement 2.25 s, pause 2.7 s */ -#define ACKNOWLEDGE_TIME1 2.8 /* announcement 1.7 s, pause 1.1 s */ -#define ACKNOWLEDGE_TIME2 4.6 /* announcement 1.7 s, pause 2.9 s */ -#define BEEP_TIME 4.0 /* beep after answer */ +#define ANSWER_TIME 1,0 /* wait after answer */ +#define OOO_TIME 3,800000 /* announcement 1.7 s, pause 2.1 s */ +#define UNASSIGNED_TIME1 2,200000 /* announcement 2.2 s s */ +#define UNASSIGNED_TIME2 2,900000 /* announcement 2.2 s, pause 0.7 s */ +#define DEGRADED_TIME 4,950000 /* announcement 2.25 s, pause 2.7 s */ +#define ACKNOWLEDGE_TIME1 2,800000 /* announcement 1.7 s, pause 1.1 s */ +#define ACKNOWLEDGE_TIME2 4,600000 /* announcement 1.7 s, pause 2.9 s */ +#define BEEP_TIME 4,000000 /* beep after answer */ /* these calls are not associated with a transmitter */ euro_call_t *ooo_call_list = NULL; @@ -149,7 +149,7 @@ static void call_new_state(euro_call_t *call, enum euro_call_state new_state) { if (call->state == new_state) return; - PDEBUG(DEURO, DEBUG_DEBUG, "State change: %s -> %s\n", call_state_name(call->state), call_state_name(new_state)); + LOGP(DEURO, LOGL_DEBUG, "State change: %s -> %s\n", call_state_name(call->state), call_state_name(new_state)); call->state = new_state; euro_display_status(); } @@ -243,29 +243,29 @@ int euro_create(const char *kanal, const char *device, int use_sdr, int samplera int rc; if (euro_kanal2freq(kanal, 0) == 0.0) { - PDEBUG(DEURO, DEBUG_ERROR, "Channel ('Kanal') number %s invalid, use 'list' to get a list.\n", kanal); + LOGP(DEURO, LOGL_ERROR, "Channel ('Kanal') number %s invalid, use 'list' to get a list.\n", kanal); return -EINVAL; } euro = calloc(1, sizeof(*euro)); if (!euro) { - PDEBUG(DEURO, DEBUG_ERROR, "No memory!\n"); + LOGP(DEURO, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DEURO, DEBUG_DEBUG, "Creating 'Eurosignal' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DEURO, LOGL_DEBUG, "Creating 'Eurosignal' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&euro->sender, kanal, euro_kanal2freq(kanal, fm), euro_kanal2freq(kanal, fm), device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DEURO, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DEURO, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(euro, samplerate, fm); if (rc < 0) { - PDEBUG(DEURO, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DEURO, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } @@ -279,7 +279,7 @@ int euro_create(const char *kanal, const char *device, int use_sdr, int samplera euro_display_status(); - PDEBUG(DEURO, DEBUG_NOTICE, "Created 'Kanal' %s\n", kanal); + LOGP(DEURO, LOGL_NOTICE, "Created 'Kanal' %s\n", kanal); return 0; @@ -294,7 +294,7 @@ void euro_destroy(sender_t *sender) { euro_t *euro = (euro_t *) sender; - PDEBUG(DEURO, DEBUG_DEBUG, "Destroying 'Eurosignal' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DEURO, LOGL_DEBUG, "Destroying 'Eurosignal' instance for 'Kanal' = %s.\n", sender->kanal); while (euro->call_list) euro_call_destroy(euro->call_list); @@ -308,12 +308,12 @@ static euro_call_t *euro_call_create(euro_t *euro, uint32_t callref, const char { euro_call_t *call, **callp; - PDEBUG(DEURO, DEBUG_INFO, "Creating call instance to page ID '%s'.\n", id); + LOGP(DEURO, LOGL_INFO, "Creating call instance to page ID '%s'.\n", id); /* create */ call = calloc(1, sizeof(*call)); if (!call) { - PDEBUG(DEURO, DEBUG_ERROR, "No mem!\n"); + LOGP(DEURO, LOGL_ERROR, "No mem!\n"); abort(); } @@ -322,8 +322,8 @@ static euro_call_t *euro_call_create(euro_t *euro, uint32_t callref, const char strcpy(call->station_id, id); if (euro) call->page_count = euro->repeat; - timer_init(&call->timer, call_timeout, call); - timer_start(&call->timer, ANSWER_TIME); + osmo_timer_setup(&call->timer, call_timeout, call); + osmo_timer_schedule(&call->timer, ANSWER_TIME); /* link */ call->euro = euro; @@ -347,7 +347,7 @@ static void euro_call_destroy(euro_call_t *call) (*callp) = call->next; /* cleanup */ - timer_exit(&call->timer); + osmo_timer_del(&call->timer); /* destroy */ free(call); @@ -364,12 +364,12 @@ void euro_get_id(euro_t *euro, char *id) if (euro->scan_from < euro->scan_to) { sprintf(id, "%06d", euro->scan_from++); - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Transmitting ID '%s'.\n", id); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Transmitting ID '%s'.\n", id); goto encode; } if (euro->sender.loopback) { - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Transmitting test ID '123456'.\n"); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Transmitting test ID '123456'.\n"); memcpy(id, "123456", 6); goto encode; } @@ -377,7 +377,7 @@ void euro_get_id(euro_t *euro, char *id) for (call = euro->call_list; call; call = call->next) { if ((call->state == EURO_CALL_ACKNOWLEDGE || call->state == EURO_CALL_RELEASED) && call->page_count) { call->page_count--; - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Transmitting ID '%s'.\n", call->station_id); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Transmitting ID '%s'.\n", call->station_id); memcpy(id, call->station_id, 6); if (call->page_count == 0 && call->state == EURO_CALL_RELEASED) euro_call_destroy(call); @@ -400,15 +400,15 @@ void euro_get_id(euro_t *euro, char *id) memcpy(id, euro->random_id, 6); euro->random_count--; if (id[0] == 'R') { - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Randomly transmitting Idle sequence.\n"); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Randomly transmitting Idle sequence.\n"); return; } - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Randomly transmitting ID '%s'.\n", euro->random_id); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Randomly transmitting ID '%s'.\n", euro->random_id); goto encode; } if (!call) { - PDEBUG_CHAN(DEURO, DEBUG_DEBUG, "Transmitting Idle sequence.\n"); + LOGP_CHAN(DEURO, LOGL_DEBUG, "Transmitting Idle sequence.\n"); memcpy(id, "RIIIII", 6); return; } @@ -432,7 +432,7 @@ void euro_receive_id(euro_t *euro, char *id) int count = 0; if (id[0] == 'R') { - PDEBUG_CHAN(DEURO, DEBUG_DEBUG, "Received Idle sequence'\n"); + LOGP_CHAN(DEURO, LOGL_DEBUG, "Received Idle sequence'\n"); return; } @@ -444,7 +444,7 @@ void euro_receive_id(euro_t *euro, char *id) /* loopback display */ if (euro->sender.loopback) { - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Received ID '%s'\n", id); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Received ID '%s'\n", id); return; } @@ -452,12 +452,12 @@ void euro_receive_id(euro_t *euro, char *id) if (id_list) { count = search_id(id); if (!count) { - PDEBUG_CHAN(DEURO, DEBUG_INFO, "Received ID '%s' is not for us.\n", id); + LOGP_CHAN(DEURO, LOGL_INFO, "Received ID '%s' is not for us.\n", id); return; } } - PDEBUG_CHAN(DEURO, DEBUG_NOTICE, "Received ID '%s'\n", id); + LOGP_CHAN(DEURO, LOGL_NOTICE, "Received ID '%s'\n", id); /* we want to send beep via MNCC */ if (id_list) { @@ -475,7 +475,7 @@ void euro_receive_id(euro_t *euro, char *id) return; /* create call and send setup */ - PDEBUG_CHAN(DEURO, DEBUG_INFO, "Sending setup towards network.'\n"); + LOGP_CHAN(DEURO, LOGL_INFO, "Sending setup towards network.'\n"); sprintf(dialing, "%d", count); callref = call_up_setup(call->station_id, dialing, OSMO_CC_NETWORK_EUROSIGNAL_NONE, ""); call = euro_call_create(NULL, callref, id); @@ -557,43 +557,43 @@ static void call_timeout(void *data) case EURO_CALL_ANSWER: /* if no station is linked to the call, we are out-of-order */ if (!call->euro) { - PDEBUG(DEURO, DEBUG_INFO, "Station is unavailable, playing announcement.\n"); + LOGP(DEURO, LOGL_INFO, "Station is unavailable, playing announcement.\n"); call->announcement_spl = es_ges_spl; call->announcement_size = es_ges_size; call->announcement_index = 0; - timer_start(&call->timer, OOO_TIME); + osmo_timer_schedule(&call->timer, OOO_TIME); call_new_state(call, EURO_CALL_OUTOFORDER); break; } /* if subcriber list is available, but ID is not found, we are unassigned */ if (id_list && !search_id(call->station_id)) { - PDEBUG(DEURO, DEBUG_INFO, "Subscriber unknown, playing announcement.\n"); + LOGP(DEURO, LOGL_INFO, "Subscriber unknown, playing announcement.\n"); call->announcement_spl = es_kaudn_spl; call->announcement_size = es_kaudn_size; call->announcement_index = 0; call->announcement_count = 1; - timer_start(&call->timer, UNASSIGNED_TIME1); + osmo_timer_schedule(&call->timer, UNASSIGNED_TIME1); call_new_state(call, EURO_CALL_UNASSIGNED); break; } /* if station is degraded, play that announcement */ if (call->euro->degraded) { - PDEBUG(DEURO, DEBUG_INFO, "Station is degraded, playing announcement.\n"); + LOGP(DEURO, LOGL_INFO, "Station is degraded, playing announcement.\n"); call->announcement_spl = es_teilges_spl; call->announcement_size = es_teilges_size; call->announcement_index = 0; - timer_start(&call->timer, DEGRADED_TIME); + osmo_timer_schedule(&call->timer, DEGRADED_TIME); call_new_state(call, EURO_CALL_DEGRADED); break; } /* fall through */ case EURO_CALL_DEGRADED: - PDEBUG(DEURO, DEBUG_INFO, "Station acknowledges, playing announcement.\n"); + LOGP(DEURO, LOGL_INFO, "Station acknowledges, playing announcement.\n"); call->announcement_spl = es_mitte_spl; call->announcement_size = es_mitte_size; call->announcement_index = 0; call->announcement_count = 1; - timer_start(&call->timer, ACKNOWLEDGE_TIME1); + osmo_timer_schedule(&call->timer, ACKNOWLEDGE_TIME1); call_new_state(call, EURO_CALL_ACKNOWLEDGE); break; case EURO_CALL_ACKNOWLEDGE: @@ -602,22 +602,22 @@ static void call_timeout(void *data) call->announcement_size = es_mitte_size; call->announcement_index = 0; call->announcement_count = 2; - timer_start(&call->timer, ACKNOWLEDGE_TIME2); + osmo_timer_schedule(&call->timer, ACKNOWLEDGE_TIME2); break; } if (call->page_count) { - PDEBUG(DEURO, DEBUG_INFO, "Announcement played, receiver has not been paged yet, releasing call.\n"); + LOGP(DEURO, LOGL_INFO, "Announcement played, receiver has not been paged yet, releasing call.\n"); call_up_release(call->callref, CAUSE_NORMAL); call->callref = 0; call_new_state(call, EURO_CALL_RELEASED); break; } - PDEBUG(DEURO, DEBUG_INFO, "Announcement played, receiver has been paged, releasing call.\n"); + LOGP(DEURO, LOGL_INFO, "Announcement played, receiver has been paged, releasing call.\n"); call_up_release(call->callref, CAUSE_NORMAL); euro_call_destroy(call); break; case EURO_CALL_OUTOFORDER: - PDEBUG(DEURO, DEBUG_INFO, "Announcement played, releasing call.\n"); + LOGP(DEURO, LOGL_INFO, "Announcement played, releasing call.\n"); call_up_release(call->callref, CAUSE_NORMAL); euro_call_destroy(call); break; @@ -627,18 +627,18 @@ static void call_timeout(void *data) call->announcement_size = es_kaudn_size; call->announcement_index = 0; call->announcement_count = 2; - timer_start(&call->timer, UNASSIGNED_TIME2); + osmo_timer_schedule(&call->timer, UNASSIGNED_TIME2); break; } - PDEBUG(DEURO, DEBUG_INFO, "Announcement played, playing again.\n"); + LOGP(DEURO, LOGL_INFO, "Announcement played, playing again.\n"); call->announcement_spl = es_kaudn_spl; call->announcement_size = es_kaudn_size; call->announcement_index = 0; call->announcement_count = 1; - timer_start(&call->timer, UNASSIGNED_TIME1); + osmo_timer_schedule(&call->timer, UNASSIGNED_TIME1); break; case EURO_CALL_BEEPING: - PDEBUG(DEURO, DEBUG_INFO, "Beep played, releasing.\n"); + LOGP(DEURO, LOGL_INFO, "Beep played, releasing.\n"); call_up_release(call->callref, CAUSE_NORMAL); call->callref = 0; euro_call_destroy(call); @@ -670,9 +670,9 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* just (ab)use busy signal when no station is available */ if (!sender) { if (channel) - PDEBUG(DEURO, DEBUG_NOTICE, "Cannot page receiver, because given station not available, rejecting!\n"); + LOGP(DEURO, LOGL_NOTICE, "Cannot page receiver, because given station not available, rejecting!\n"); else - PDEBUG(DEURO, DEBUG_NOTICE, "Cannot page receiver, no station not available, rejecting!\n"); + LOGP(DEURO, LOGL_NOTICE, "Cannot page receiver, no station not available, rejecting!\n"); euro = NULL; } @@ -688,19 +688,19 @@ void call_down_answer(int __attribute__((unused)) callref) { euro_call_t *call; - PDEBUG(DEURO, DEBUG_INFO, "Call has been answered by network.\n"); + LOGP(DEURO, LOGL_INFO, "Call has been answered by network.\n"); for (call = ooo_call_list; call; call = call->next) { if (call->callref == callref) break; } if (!call) { - PDEBUG(DEURO, DEBUG_NOTICE, "Answer from network, but no callref!\n"); + LOGP(DEURO, LOGL_NOTICE, "Answer from network, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } - timer_start(&call->timer, BEEP_TIME); + osmo_timer_schedule(&call->timer, BEEP_TIME); } static void _release(int callref, int __attribute__((unused)) cause) @@ -709,7 +709,7 @@ static void _release(int callref, int __attribute__((unused)) cause) euro_t *euro; euro_call_t *call; - PDEBUG(DEURO, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DEURO, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { euro = (euro_t *) sender; @@ -727,7 +727,7 @@ static void _release(int callref, int __attribute__((unused)) cause) } } if (!call) { - PDEBUG(DEURO, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DEURO, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } diff --git a/src/eurosignal/eurosignal.h b/src/eurosignal/eurosignal.h index bcb2bc1..92dbaba 100644 --- a/src/eurosignal/eurosignal.h +++ b/src/eurosignal/eurosignal.h @@ -1,6 +1,6 @@ #include "../libfm/fm.h" #include "../libmobile/sender.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> /* current state of transmitter */ enum euro_health_state { @@ -30,7 +30,7 @@ typedef struct euro_call { int callref; /* call reference */ char station_id[7]; /* current station ID */ int page_count; /* number of transmissions left */ - struct timer timer; + struct osmo_timer_list timer; enum euro_call_state state; /* current state */ int announcement_count; /* used to replay annoucements */ int16_t *announcement_spl; /* current sample */ diff --git a/src/eurosignal/main.c b/src/eurosignal/main.c index 8d0b5bc..32681f3 100644 --- a/src/eurosignal/main.c +++ b/src/eurosignal/main.c @@ -23,7 +23,7 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../liboptions/options.h" @@ -247,6 +247,7 @@ fail: euro_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); euro_exit(); diff --git a/src/fuenf/Makefile.am b/src/fuenf/Makefile.am index 9b123f5..59f2f6e 100644 --- a/src/fuenf/Makefile.am +++ b/src/fuenf/Makefile.am @@ -12,22 +12,20 @@ bin_PROGRAMS = \ $(COMMON_LA) \ ../anetz/libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/fuenf/dsp.c b/src/fuenf/dsp.c index 7985fb9..c587711 100644 --- a/src/fuenf/dsp.c +++ b/src/fuenf/dsp.c @@ -26,7 +26,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "fuenf.h" #include "dsp.h" @@ -106,7 +106,7 @@ int dsp_init_sender(fuenf_t *fuenf, int samplerate, double max_deviation, double sample_t *spl; int len; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for transceiver.\n"); /* set modulation parameters */ sender_set_fm(&fuenf->sender, max_deviation, MAX_MODULATION, signal_deviation, MAX_DISPLAY); @@ -129,7 +129,7 @@ int dsp_init_sender(fuenf_t *fuenf, int samplerate, double max_deviation, double len = (int)(8000.0 * (1.0 / RX_TOL_TONE_FREQ) + 0.5); spl = calloc(1, len * sizeof(*spl)); if (!spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP(DDSP, LOGL_ERROR, "No memory!\n"); goto error; } fuenf->rx_tone_filter_spl = spl; @@ -154,7 +154,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_sender(fuenf_t *fuenf) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for transceiver.\n"); /* free tone buffers */ if (fuenf->rx_tone_filter_spl) @@ -228,7 +228,7 @@ static void digit_decode(fuenf_t *fuenf, sample_t *samples, int length) break; /* check if we have enought silence */ if (fuenf->rx_digit_count == RX_MIN_PREAMBLE) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected silence, waiting for digits.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected silence, waiting for digits.\n"); fuenf->rx_state = RX_STATE_IDLE; break; } @@ -237,7 +237,7 @@ static void digit_decode(fuenf_t *fuenf, sample_t *samples, int length) /* wait for digit */ if (d < 0) break; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "We have some tone, start receiving digits.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "We have some tone, start receiving digits.\n"); fuenf->rx_callsign_count = 0; fuenf->rx_callsign[fuenf->rx_callsign_count] = d; fuenf->rx_state = RX_STATE_DIGIT; @@ -247,18 +247,18 @@ static void digit_decode(fuenf_t *fuenf, sample_t *samples, int length) if (!change) { if (fuenf->rx_digit_count == RX_LEN_DIGIT_TH) { if (d < 0) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Not enough digits received, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Not enough digits received, waiting for next transmission.\n"); fuenf->rx_function = 0; fuenf->rx_function_count = 0; fuenf->rx_state = RX_STATE_RESET; break; } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected digit #%d (amplitude = %.0f%%)\n", d + 1, sqrt(a) * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected digit #%d (amplitude = %.0f%%)\n", d + 1, sqrt(a) * 100.0); display_measurements_update(fuenf->dmp_digit_level, sqrt(a) * 100.0, 0.0); break; } if (fuenf->rx_digit_count == RX_LEN_DIGIT_MAX) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected digit too long, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected digit too long, waiting for next transmission.\n"); fuenf->rx_state = RX_STATE_RESET; break; } @@ -272,7 +272,7 @@ static void digit_decode(fuenf_t *fuenf, sample_t *samples, int length) } /* if counter (when changed) was too low */ if (change_count < RX_LEN_DIGIT_MIN) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected digit too short, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected digit too short, waiting for next transmission.\n"); fuenf->rx_state = RX_STATE_RESET; break; } @@ -284,7 +284,7 @@ static void digit_decode(fuenf_t *fuenf, sample_t *samples, int length) for (i = 0; i < 5; i++) { if (fuenf->rx_callsign[i] == REPEAT_DIGIT) { if (i == 0) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "First digit is a repeat digit, this is not allowed, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "First digit is a repeat digit, this is not allowed, waiting for next transmission.\n"); fuenf->rx_state = RX_STATE_RESET; break; } @@ -298,7 +298,7 @@ static void digit_decode(fuenf_t *fuenf, sample_t *samples, int length) fuenf->rx_callsign[i] = '\0'; if (i < 5) break; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Complete call sign '%s' received, waiting for signal tone(s).\n", fuenf->rx_callsign); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Complete call sign '%s' received, waiting for signal tone(s).\n", fuenf->rx_callsign); fuenf_rx_callsign(fuenf, fuenf->rx_callsign); fuenf->rx_function_count = 0; /* must reset, so we can detect timeout */ fuenf->rx_state = RX_STATE_WAIT_SIGNAL; @@ -362,7 +362,7 @@ static void tone_decode(fuenf_t *fuenf, sample_t *samples, int length) /* wait for signal */ if (!funktion) { if (fuenf->rx_function_count >= RX_WAIT_TONE_MAX) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "There is no double tone, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "There is no double tone, waiting for next transmission.\n"); fuenf->rx_state = RX_STATE_RESET; break; } @@ -376,13 +376,13 @@ static void tone_decode(fuenf_t *fuenf, sample_t *samples, int length) case RX_STATE_SIGNAL: /* if signal ceases too early */ if (funktion != fuenf->rx_function) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Signal tones ceased to early, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Signal tones ceased to early, waiting for next transmission.\n"); fuenf->rx_state = RX_STATE_RESET; break; } if (fuenf->rx_function_count >= RX_LEN_TONE_MIN) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected tones %.0f+%.0f Hz (amplitude = %.0f%%+%.0f%%)\n", tone_freq[tone1], tone_freq[tone2], fuenf->rx_tone_levels[tone1] * 100.0, fuenf->rx_tone_levels[tone2] * 100.0); - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Signal tones detected, done, waiting for next transmission.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected tones %.0f+%.0f Hz (amplitude = %.0f%%+%.0f%%)\n", tone_freq[tone1], tone_freq[tone2], fuenf->rx_tone_levels[tone1] * 100.0, fuenf->rx_tone_levels[tone2] * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Signal tones detected, done, waiting for next transmission.\n"); fuenf_rx_function(fuenf, fuenf->rx_function); fuenf->rx_state = RX_STATE_RESET; break; @@ -435,11 +435,11 @@ int dsp_setup(fuenf_t *fuenf, const char *rufzeichen, enum fuenf_funktion funkti fuenf->tx_seq_length = 0; if (strlen(rufzeichen) != 5) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Given call sign has invalid length.\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "Given call sign has invalid length.\n"); return -EINVAL; } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Generating sequence for call sign '%s' and function code '%d'.\n", rufzeichen, funktion); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Generating sequence for call sign '%s' and function code '%d'.\n", rufzeichen, funktion); /* add preamble */ seq[index].phasestep1 = 0; @@ -451,7 +451,7 @@ int dsp_setup(fuenf_t *fuenf, const char *rufzeichen, enum fuenf_funktion funkti tone_index = index; for (i = 0; rufzeichen[i]; i++) { if (rufzeichen[i] < '0' || rufzeichen[i] > '9') { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Given call sign has invalid digit '%c'.\n", rufzeichen[i]); + LOGP_CHAN(DDSP, LOGL_ERROR, "Given call sign has invalid digit '%c'.\n", rufzeichen[i]); return -EINVAL; } if (rufzeichen[i] == '0') @@ -461,9 +461,9 @@ int dsp_setup(fuenf_t *fuenf, const char *rufzeichen, enum fuenf_funktion funkti /* use repeat digit, if two subsequent digits are the same */ if (i > 0 && seq[index - 1].phasestep1 == seq[index].phasestep1) { seq[index].phasestep1 = 2.0 * M_PI * digit_freq[REPEAT_DIGIT] * fuenf->sample_duration; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, " -> Adding digit '%c' as tone with %.0f Hz.\n", rufzeichen[i], digit_freq[REPEAT_DIGIT]); + LOGP_CHAN(DDSP, LOGL_DEBUG, " -> Adding digit '%c' as tone with %.0f Hz.\n", rufzeichen[i], digit_freq[REPEAT_DIGIT]); } else - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, " -> Adding digit '%c' as tone with %.0f Hz.\n", rufzeichen[i], digit_freq[rufzeichen[i] - '0']); + LOGP_CHAN(DDSP, LOGL_DEBUG, " -> Adding digit '%c' as tone with %.0f Hz.\n", rufzeichen[i], digit_freq[rufzeichen[i] - '0']); seq[index].phasestep2 = 0; seq[index].duration = TX_LEN_DIGIT; index++; @@ -493,7 +493,7 @@ int dsp_setup(fuenf_t *fuenf, const char *rufzeichen, enum fuenf_funktion funkti #ifndef DEBUG if (funktion == FUENF_FUNKTION_RUF) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, " -> Adding call signal of %.0f Hz.\n", digit_freq[REPEAT_DIGIT]); + LOGP_CHAN(DDSP, LOGL_DEBUG, " -> Adding call signal of %.0f Hz.\n", digit_freq[REPEAT_DIGIT]); for (i = 0; i < TX_NUM_KANAL; i++) { /* add tone (double volume) */ seq[index].phasestep1 = 2.0 * M_PI * digit_freq[REPEAT_DIGIT] * fuenf->sample_duration; @@ -522,7 +522,7 @@ int dsp_setup(fuenf_t *fuenf, const char *rufzeichen, enum fuenf_funktion funkti if (signals[i].funktion == funktion) break; } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, " -> Adding call signal of %.0f Hz and %.0f Hz.\n", tone_freq[signals[i].tone1], tone_freq[signals[i].tone2]); + LOGP_CHAN(DDSP, LOGL_DEBUG, " -> Adding call signal of %.0f Hz and %.0f Hz.\n", tone_freq[signals[i].tone1], tone_freq[signals[i].tone2]); seq[index].phasestep1 = 2.0 * M_PI * tone_freq[signals[i].tone1] * fuenf->sample_duration; seq[index].phasestep2 = 2.0 * M_PI * tone_freq[signals[i].tone2] * fuenf->sample_duration; seq[index].duration = TX_LEN_SIGNAL; @@ -532,7 +532,7 @@ int dsp_setup(fuenf_t *fuenf, const char *rufzeichen, enum fuenf_funktion funkti /* check array overflow, if it did not already crashed before */ if (index > (int)(sizeof(fuenf->tx_seq) / sizeof(fuenf->tx_seq[0]))) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Array size of tx_seq too small, please fix!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "Array size of tx_seq too small, please fix!\n"); abort(); } diff --git a/src/fuenf/fuenf.c b/src/fuenf/fuenf.c index 4466094..1fb66a6 100644 --- a/src/fuenf/fuenf.c +++ b/src/fuenf/fuenf.c @@ -26,10 +26,10 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "../liboptions/options.h" #include "fuenf.h" #include "dsp.h" @@ -149,7 +149,7 @@ void fuenf_new_state(fuenf_t *fuenf, enum fuenf_state new_state) { if (fuenf->state == new_state) return; - PDEBUG_CHAN(DFUENF, DEBUG_DEBUG, "State change: %s -> %s\n", fuenf_state_name[fuenf->state], fuenf_state_name[new_state]); + LOGP_CHAN(DFUENF, LOGL_DEBUG, "State change: %s -> %s\n", fuenf_state_name[fuenf->state], fuenf_state_name[new_state]); fuenf->state = new_state; fuenf_display_status(); } @@ -160,13 +160,13 @@ static int fuenf_scan_or_loopback(fuenf_t *fuenf) if (fuenf->scan_from < fuenf->scan_to) { sprintf(rufzeichen, "%05d", fuenf->scan_from++); - PDEBUG_CHAN(DFUENF, DEBUG_NOTICE, "Transmitting ID '%s'.\n", rufzeichen); + LOGP_CHAN(DFUENF, LOGL_NOTICE, "Transmitting ID '%s'.\n", rufzeichen); dsp_setup(fuenf, rufzeichen, fuenf->default_funktion); return 1; } if (fuenf->sender.loopback) { - PDEBUG(DFUENF, DEBUG_INFO, "Sending 5-Ton-Ruf for loopback test.\n"); + LOGP(DFUENF, LOGL_INFO, "Sending 5-Ton-Ruf for loopback test.\n"); dsp_setup(fuenf, "10357", FUENF_FUNKTION_FEUER); return 1; } @@ -182,23 +182,23 @@ int fuenf_create(const char *kanal, double frequency, const char *device, int us fuenf = calloc(1, sizeof(*fuenf)); if (!fuenf) { - PDEBUG(DFUENF, DEBUG_ERROR, "No memory!\n"); + LOGP(DFUENF, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DFUENF, DEBUG_DEBUG, "Creating '5-Ton-Folge' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DFUENF, LOGL_DEBUG, "Creating '5-Ton-Folge' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&fuenf->sender, kanal, frequency, frequency, device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DFUENF, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DFUENF, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(fuenf, samplerate, max_deviation, signal_deviation); if (rc < 0) { - PDEBUG(DFUENF, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DFUENF, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } @@ -210,7 +210,7 @@ int fuenf_create(const char *kanal, double frequency, const char *device, int us fuenf_display_status(); - PDEBUG(DFUENF, DEBUG_NOTICE, "Created 'Kanal' %s\n", kanal); + LOGP(DFUENF, LOGL_NOTICE, "Created 'Kanal' %s\n", kanal); /* start scanning, if enabled, otherwise send loopback sequence, if enabled */ fuenf_scan_or_loopback(fuenf); @@ -228,7 +228,7 @@ void fuenf_destroy(sender_t *sender) { fuenf_t *fuenf = (fuenf_t *) sender; - PDEBUG(DFUENF, DEBUG_DEBUG, "Destroying '5-Ton-Folge' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DFUENF, LOGL_DEBUG, "Destroying '5-Ton-Folge' instance for 'Kanal' = %s.\n", sender->kanal); dsp_cleanup_sender(fuenf); sender_destroy(&fuenf->sender); @@ -238,7 +238,7 @@ void fuenf_destroy(sender_t *sender) /* call sign was transmitted */ void fuenf_tx_done(fuenf_t *fuenf) { - PDEBUG_CHAN(DFUENF, DEBUG_INFO, "Done sending 5-Ton-Ruf.\n"); + LOGP_CHAN(DFUENF, LOGL_INFO, "Done sending 5-Ton-Ruf.\n"); /* start scanning, if enabled, otherwise send loopback sequence, if enabled */ if (fuenf_scan_or_loopback(fuenf)) { @@ -247,7 +247,7 @@ void fuenf_tx_done(fuenf_t *fuenf) /* go talker state */ if (fuenf->callref && fuenf->tx_funktion == FUENF_FUNKTION_RUF) { - PDEBUG_CHAN(DFUENF, DEBUG_INFO, "Caller may talk now.\n"); + LOGP_CHAN(DFUENF, LOGL_INFO, "Caller may talk now.\n"); fuenf_new_state(fuenf, FUENF_STATE_DURCHSAGE); return; } @@ -255,19 +255,19 @@ void fuenf_tx_done(fuenf_t *fuenf) /* go idle */ fuenf_new_state(fuenf, FUENF_STATE_IDLE); if (fuenf->callref) { - PDEBUG_CHAN(DFUENF, DEBUG_INFO, "Releasing call toward network.\n"); + LOGP_CHAN(DFUENF, LOGL_INFO, "Releasing call toward network.\n"); call_up_release(fuenf->callref, CAUSE_NORMAL); } } void fuenf_rx_callsign(fuenf_t *fuenf, const char *callsign) { - PDEBUG_CHAN(DFUENF, DEBUG_INFO, "Received 5-Ton-Ruf with call sign '%s'.\n", callsign); + LOGP_CHAN(DFUENF, LOGL_INFO, "Received 5-Ton-Ruf with call sign '%s'.\n", callsign); } void fuenf_rx_function(fuenf_t *fuenf, enum fuenf_funktion funktion) { - PDEBUG_CHAN(DFUENF, DEBUG_INFO, "Received function '%s'.\n", fuenf_funktion_name[funktion]); + LOGP_CHAN(DFUENF, LOGL_INFO, "Received function '%s'.\n", fuenf_funktion_name[funktion]); } void call_down_clock(void) @@ -298,9 +298,9 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, } if (!sender) { if (channel) - PDEBUG(DFUENF, DEBUG_NOTICE, "Cannot page, because given station not available, rejecting!\n"); + LOGP(DFUENF, LOGL_NOTICE, "Cannot page, because given station not available, rejecting!\n"); else - PDEBUG(DFUENF, DEBUG_NOTICE, "Cannot page, no trasmitting station idle, rejecting!\n"); + LOGP(DFUENF, LOGL_NOTICE, "Cannot page, no trasmitting station idle, rejecting!\n"); return -CAUSE_NOCHANNEL; } @@ -335,7 +335,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, return -CAUSE_INVALNUMBER; } - PDEBUG_CHAN(DFUENF, DEBUG_INFO, "Sending 5-Ton-Ruf with call sign '%s' and function '%s'.\n", rufzeichen, fuenf_funktion_name[funktion]); + LOGP_CHAN(DFUENF, LOGL_INFO, "Sending 5-Ton-Ruf with call sign '%s' and function '%s'.\n", rufzeichen, fuenf_funktion_name[funktion]); dsp_setup(fuenf, rufzeichen, funktion); @@ -357,7 +357,7 @@ static void _release(int __attribute__((unused)) callref, int __attribute__((unu sender_t *sender; fuenf_t *fuenf; - PDEBUG(DFUENF, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DFUENF, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { fuenf = (fuenf_t *) sender; @@ -365,7 +365,7 @@ static void _release(int __attribute__((unused)) callref, int __attribute__((unu break; } if (!sender) { - PDEBUG(DBNETZ, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DBNETZ, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } diff --git a/src/fuenf/main.c b/src/fuenf/main.c index 77c73cd..1dcef11 100644 --- a/src/fuenf/main.c +++ b/src/fuenf/main.c @@ -27,7 +27,7 @@ #include <sys/stat.h> #include <fcntl.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../liboptions/options.h" @@ -259,6 +259,7 @@ fail: fuenf_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); fuenf_exit(); diff --git a/src/fuvst/Makefile.am b/src/fuvst/Makefile.am index f7c73f4..73a7708 100644 --- a/src/fuvst/Makefile.am +++ b/src/fuvst/Makefile.am @@ -15,14 +15,10 @@ fuvst_LDADD = \ ../anetz/libgermanton.a \ ../cnetz/libcnetztones.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ @@ -32,8 +28,10 @@ fuvst_LDADD = \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ $(top_builddir)/src/libsound/libsound.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ $(ALSA_LIBS) \ -lm @@ -42,14 +40,10 @@ fuvst_sniffer_SOURCES = \ fuvst_sniffer_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ @@ -59,8 +53,10 @@ fuvst_sniffer_LDADD = \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ $(top_builddir)/src/libsound/libsound.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ $(ALSA_LIBS) \ -lm diff --git a/src/fuvst/fuvst.c b/src/fuvst/fuvst.c index ae825fc..0871116 100755 --- a/src/fuvst/fuvst.c +++ b/src/fuvst/fuvst.c @@ -35,12 +35,14 @@ #include <time.h> #include <inttypes.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libtimer/timer.h" -#include "../libosmocc/message.h" +#include "../libmobile/get_time.h" +#include <osmocom/core/timer.h> +#include <osmocom/core/utils.h> +#include <osmocom/cc/message.h> #include "fuvst.h" /* digital loopback test */ @@ -120,21 +122,21 @@ int config_file(const char *filename) uint8_t byte; if (!fp) { - PDEBUG(DTRANS, DEBUG_ERROR, "Failed to open data base file: '%s'\n", filename); + LOGP(DTRANS, LOGL_ERROR, "Failed to open data base file: '%s'\n", filename); return -EIO; } rc = fread(conf.data, 1, sizeof(conf.data), fp); if (rc < (int)sizeof(conf.data)) { fclose(fp); - PDEBUG(DTRANS, DEBUG_ERROR, "Data base file shorter than %d bytes. This seems not to be a valid config file.\n", (int)sizeof(conf.data)); + LOGP(DTRANS, LOGL_ERROR, "Data base file shorter than %d bytes. This seems not to be a valid config file.\n", (int)sizeof(conf.data)); return -EIO; } rc = fread(&byte, 1, 1, fp); if (rc == 1) { fclose(fp); - PDEBUG(DTRANS, DEBUG_ERROR, "Data base file larger than %d bytes. (Don't use the EEPROM config format, use the MSC config format.)\n", (int)sizeof(conf.data)); + LOGP(DTRANS, LOGL_ERROR, "Data base file larger than %d bytes. (Don't use the EEPROM config format, use the MSC config format.)\n", (int)sizeof(conf.data)); return -EIO; } @@ -156,10 +158,10 @@ static void config_send(uint8_t ident, uint8_t job, uint16_t offset, uint16_t le uint32_t checksum = 0; uint8_t rc = 1; /* Auftrag angenommen */ - PDEBUG(DCNETZ, DEBUG_NOTICE, "MSC requests data base block. (offset=%d, length=%d)\n", offset, length); + LOGP(DCNETZ, LOGL_NOTICE, "MSC requests data base block. (offset=%d, length=%d)\n", offset, length); if (!conf.loaded) { - PDEBUG(DCNETZ, DEBUG_ERROR, "MSC requests data base, but no file name given. Please give file name!\n"); + LOGP(DCNETZ, LOGL_ERROR, "MSC requests data base, but no file name given. Please give file name!\n"); error: /* return error */ len = encode_xedbu_1(&opcode, &data, 16, job, 0); @@ -168,7 +170,7 @@ error: } if (offset + length > sizeof(conf.data)) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Requested date out of range!\n"); + LOGP(DCNETZ, LOGL_ERROR, "Requested date out of range!\n"); goto error; } @@ -262,7 +264,7 @@ void add_emergency(const char *number) emerg = calloc(1, sizeof(*emerg)); if (!emerg) { - PDEBUG(DTRANS, DEBUG_ERROR, "No memory!\n"); + LOGP(DTRANS, LOGL_ERROR, "No memory!\n"); return; } @@ -288,7 +290,7 @@ static int check_emerg(const char *number) if (!emerg) return 0; - PDEBUG(DCNETZ, DEBUG_NOTICE, "Emergency call, matching prefix '%s' in list of emergency numbers.\n", emerg->number); + LOGP(DCNETZ, LOGL_NOTICE, "Emergency call, matching prefix '%s' in list of emergency numbers.\n", emerg->number); return 1; } @@ -337,12 +339,12 @@ static void remove_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_res while (*dbp && *dbp != db) dbp = &((*dbp)->next); if (!(*dbp)) { - PDEBUG(DDB, DEBUG_ERROR, "Subscriber not in list, please fix!!\n"); + LOGP(DDB, LOGL_ERROR, "Subscriber not in list, please fix!!\n"); abort(); } *dbp = db->next; - PDEBUG(DDB, DEBUG_INFO, "Removing subscriber '%d,%d,%d' from database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_INFO, "Removing subscriber '%d,%d,%d' from database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); /* remove */ free(db); @@ -353,7 +355,7 @@ static void flush_db(void) cnetz_db_t *db; while ((db = cnetz_db_head)) { - PDEBUG(DDB, DEBUG_INFO, "Removing subscriber '%d,%d,%d' from database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_INFO, "Removing subscriber '%d,%d,%d' from database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); cnetz_db_head = db->next; free(db); } @@ -370,7 +372,7 @@ static void add_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_rest, /* add */ db = calloc(1, sizeof(*db)); if (!db) { - PDEBUG(DDB, DEBUG_ERROR, "No memory!\n"); + LOGP(DDB, LOGL_ERROR, "No memory!\n"); return; } db->futln_nat = futln_nat; @@ -378,7 +380,7 @@ static void add_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_rest, db->futln_rest = futln_rest; db->chip = chip; - PDEBUG(DDB, DEBUG_INFO, "Adding subscriber '%d,%d,%d' to database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_INFO, "Adding subscriber '%d,%d,%d' to database.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); /* attach to end of list */ dbp = &cnetz_db_head; @@ -392,7 +394,7 @@ static void add_db(uint8_t futln_nat, uint8_t futln_fuvst, uint16_t futln_rest, */ /* Release timeout */ -#define RELEASE_TO 3.0 +#define RELEASE_TO 3,0 /* BSC originated Ident-Numbers */ #define IDENT_BSC_FROM 0x9f @@ -425,7 +427,7 @@ typedef struct transaction { fuvst_t *spk; /* assigned SPK */ char number[17]; /* dialed by mobile */ int sonderruf; /* an emergency call */ - struct timer timer; /* release timer */ + struct osmo_timer_list timer; /* release timer */ } transaction_t; transaction_t *trans_list = NULL; @@ -500,7 +502,7 @@ static void new_call_state(transaction_t *trans, enum call_state new_state) { if (trans->state == new_state) return; - PDEBUG(DTRANS, DEBUG_INFO, "State change: %s -> %s\n", state_name(trans->state), state_name(new_state)); + LOGP(DTRANS, LOGL_INFO, "State change: %s -> %s\n", state_name(trans->state), state_name(new_state)); trans->state = new_state; display_status(); } @@ -514,7 +516,7 @@ transaction_t *search_transaction_number(uint8_t futln_nat, uint8_t futln_fuvst, && trans->futln_fuvst == futln_fuvst && trans->futln_rest == futln_rest) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); return trans; } trans = trans->next; @@ -530,7 +532,7 @@ transaction_t *search_transaction_ident(uint8_t ident) while (trans) { if (trans->ident == ident) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); return trans; } trans = trans->next; @@ -549,7 +551,7 @@ transaction_t *search_transaction_callref(int callref) while (trans) { if (trans->callref == callref) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_DEBUG, "Found transaction for subscriber '%s'\n", rufnummer); return trans; } trans = trans->next; @@ -564,9 +566,9 @@ static void destroy_transaction(transaction_t *trans) transaction_t **transp; const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_INFO, "Destroying transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_INFO, "Destroying transaction for subscriber '%s'\n", rufnummer); - timer_exit(&trans->timer); + osmo_timer_del(&trans->timer); /* check for old callref (before removal) then detach SPK * if SPK has been reused by BS, our old callref will not match, @@ -580,7 +582,7 @@ static void destroy_transaction(transaction_t *trans) while (*transp && *transp != trans) transp = &((*transp)->next); if (!(*transp)) { - PDEBUG(DTRANS, DEBUG_ERROR, "Transaction not in list, please fix!!\n"); + LOGP(DTRANS, LOGL_ERROR, "Transaction not in list, please fix!!\n"); abort(); } *transp = trans->next; @@ -595,7 +597,7 @@ void trans_timeout(void *data) { transaction_t *trans = data; - PDEBUG(DTRANS, DEBUG_NOTICE, "Releasing transaction due to timeout.\n"); + LOGP(DTRANS, LOGL_NOTICE, "Releasing transaction due to timeout.\n"); if (trans->callref) call_up_release(trans->callref, CAUSE_NORMAL); trans->callref = 0; @@ -611,7 +613,7 @@ static transaction_t *create_transaction(uint8_t ident, uint8_t futln_nat, uint8 trans = search_transaction_number(futln_nat, futln_fuvst, futln_rest); if (trans && mo) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s', dropping that!\n", rufnummer); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s', dropping that!\n", rufnummer); if (trans->callref) call_up_release(trans->callref, CAUSE_NORMAL); trans->callref = 0; @@ -620,13 +622,13 @@ static transaction_t *create_transaction(uint8_t ident, uint8_t futln_nat, uint8 } if (trans) { const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_NOTICE, "Found already pending transaction for subscriber '%s', we are busy!\n", rufnummer); + LOGP(DTRANS, LOGL_NOTICE, "Found already pending transaction for subscriber '%s', we are busy!\n", rufnummer); return NULL; } trans = calloc(1, sizeof(*trans)); if (!trans) { - PDEBUG(DTRANS, DEBUG_ERROR, "No memory!\n"); + LOGP(DTRANS, LOGL_ERROR, "No memory!\n"); return NULL; } @@ -636,10 +638,10 @@ static transaction_t *create_transaction(uint8_t ident, uint8_t futln_nat, uint8 trans->futln_fuvst = futln_fuvst; trans->futln_rest = futln_rest; - timer_init(&trans->timer, trans_timeout, trans); + osmo_timer_setup(&trans->timer, trans_timeout, trans); const char *rufnummer = transaction2rufnummer(trans); - PDEBUG(DTRANS, DEBUG_INFO, "Creating transaction for subscriber '%s'\n", rufnummer); + LOGP(DTRANS, LOGL_INFO, "Creating transaction for subscriber '%s'\n", rufnummer); /* attach to end of list, so first transaction is served first */ transp = &trans_list; @@ -763,14 +765,14 @@ static int message_send(uint8_t ident, uint8_t opcode, uint8_t *data, int len) if (!zzk) zzk = get_zzk(0); if (!zzk) { - PDEBUG(DCNETZ, DEBUG_ERROR, "No ZZK or link down!\n"); + LOGP(DCNETZ, LOGL_ERROR, "No ZZK or link down!\n"); return -EIO; } uint8_t buffer[len + 2]; - if (debuglevel == DEBUG_DEBUG || opcode != OPCODE_XEDBU) - PDEBUG(DCNETZ, DEBUG_INFO, "TX Message to BS: link=%s ident=0x%02x OP=%02XH %s\n", zzk->sender.kanal, ident, opcode, debug_hex(data, len)); + if (loglevel == LOGL_DEBUG || opcode != OPCODE_XEDBU) + LOGP(DCNETZ, LOGL_INFO, "TX Message to BS: link=%s ident=0x%02x OP=%02XH %s\n", zzk->sender.kanal, ident, opcode, osmo_hexdump(data, len)); /* assemble Ident, swap Opcode and add data */ slc = ident & 0xf; @@ -808,25 +810,25 @@ static void release_for_emergency(void) /* found idle channel */ if (sender) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Emergency call received. We have a free channel available.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Emergency call received. We have a free channel available.\n"); return; } /* found no normal call (no emergency) */ if (!last_trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Emergency call received. We cannot free a channel, because there is no non-emergency call.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Emergency call received. We cannot free a channel, because there is no non-emergency call.\n"); return; } /* releasing the last call in list */ - PDEBUG(DCNETZ, DEBUG_NOTICE, "Emergency call received. We free a channel.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Emergency call received. We free a channel.\n"); len = encode_aau(&opcode, &data, trans->spk_nr, 0, cnetz_cause2futln(CAUSE_NORMAL)); message_send(trans->ident, opcode, data, len); call_up_release(trans->callref, CAUSE_NORMAL); trans->callref = 0; new_call_state(trans, STATE_RELEASE); - timer_start(&trans->timer, RELEASE_TO); + osmo_timer_schedule(&trans->timer, RELEASE_TO); } /* MTP data message from lower layer */ @@ -851,8 +853,8 @@ static void message_receive(fuvst_t *zzk, uint8_t ident, uint8_t opcode, uint8_t int i, num; char number[17]; - if (debuglevel == DEBUG_DEBUG || opcode != OPCODE_YLSMF) - PDEBUG(DCNETZ, DEBUG_INFO, "RX Message from BS: link=%s ident=0x%02x OP=%02XH %s\n", zzk->sender.kanal, ident, opcode, debug_hex(data, len)); + if (loglevel == LOGL_DEBUG || opcode != OPCODE_YLSMF) + LOGP(DCNETZ, LOGL_INFO, "RX Message from BS: link=%s ident=0x%02x OP=%02XH %s\n", zzk->sender.kanal, ident, opcode, osmo_hexdump(data, len)); switch (opcode) { case OPCODE_SWAF: /* BS restarts */ @@ -866,7 +868,7 @@ static void message_receive(fuvst_t *zzk, uint8_t ident, uint8_t opcode, uint8_t message_send(5, opcode, NULL, 0); #endif if (warmstart) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Forcing a warm start and load the config...\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Forcing a warm start and load the config...\n"); warmstart = 0; len = encode_yaaau(&opcode, &data, 42); message_send(0, opcode, data, len); @@ -932,11 +934,11 @@ static void message_receive(fuvst_t *zzk, uint8_t ident, uint8_t opcode, uint8_t break; case OPCODE_GVAF: /* MO call */ decode_gvaf(data, len, &T, &U, &N, number); - PDEBUG(DCNETZ, DEBUG_INFO, "Call from mobile.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call from mobile.\n"); goto outgoing; case OPCODE_GVWAF: /* MO call (queue) */ decode_gvaf(data, len, &T, &U, &N, number); - PDEBUG(DCNETZ, DEBUG_INFO, "Call from mobile (queue).\n"); + LOGP(DCNETZ, LOGL_INFO, "Call from mobile (queue).\n"); outgoing: trans = create_transaction(ident, N, U, T, 1); if (!trans) { @@ -958,7 +960,7 @@ outgoing: trans = search_transaction_ident(ident); if (!trans) break; - PDEBUG(DCNETZ, DEBUG_INFO, "Call to mobile is alerting (queue).\n"); + LOGP(DCNETZ, LOGL_INFO, "Call to mobile is alerting (queue).\n"); new_call_state(trans, STATE_MT_QUEUE); if (trans->callref) call_up_alerting(trans->callref); @@ -968,7 +970,7 @@ outgoing: trans = search_transaction_ident(ident); if (!trans) break; - PDEBUG(DCNETZ, DEBUG_INFO, "Call to mobile has been answered.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call to mobile has been answered.\n"); new_call_state(trans, STATE_MT_CONNECT); if (trans->callref) call_up_answer(trans->callref, transaction2rufnummer(trans)); @@ -986,7 +988,7 @@ outgoing: trans->spk_nr = Q; /* SPK not exist, release */ if (!trans->spk) { - PDEBUG(DCNETZ, DEBUG_ERROR, "SpK '%d' requested by BS not configured, please configure all SpK that base station has available!\n", Q); + LOGP(DCNETZ, LOGL_ERROR, "SpK '%d' requested by BS not configured, please configure all SpK that base station has available!\n", Q); len = encode_stnqu(&opcode, &data, Q); message_send(ident, opcode, data, len); if (trans->callref) @@ -1002,22 +1004,22 @@ outgoing: message_send(ident, opcode, data, len); /* no callref == outgoing call */ if (!trans->callref) { - PDEBUG(DCNETZ, DEBUG_INFO, "Setup call to network. (Ident = %d, FuTln=%s, number=%s)\n", ident, transaction2rufnummer(trans), trans->number); + LOGP(DCNETZ, LOGL_INFO, "Setup call to network. (Ident = %d, FuTln=%s, number=%s)\n", ident, transaction2rufnummer(trans), trans->number); trans->callref = trans->old_callref = call_up_setup(transaction2rufnummer(trans), trans->number, OSMO_CC_NETWORK_CNETZ_NONE, ""); } else { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Call to mobile is alerting.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Call to mobile is alerting.\n"); new_call_state(trans, STATE_MT_ALERTING); call_up_alerting(trans->callref); } trans->spk->callref = trans->callref; - PDEBUG(DCNETZ, DEBUG_INFO, "Assigned SpK %d to call.\n", trans->spk_nr); + LOGP(DCNETZ, LOGL_INFO, "Assigned SpK %d to call.\n", trans->spk_nr); break; case OPCODE_APF: /* auth response */ decode_apf(data, len, &Q, &a); break; case OPCODE_FAF: /* MCID request */ decode_faf(data, len); - PDEBUG(DCNETZ, DEBUG_NOTICE, "Fangen (MCID) was activated by BS.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Fangen (MCID) was activated by BS.\n"); break; case OPCODE_NAF: /* incoming release (before SPK assignment) */ decode_naf(data, len, &X); @@ -1027,7 +1029,7 @@ outgoing: trans = search_transaction_ident(ident); if (!trans) break; - PDEBUG(DCNETZ, DEBUG_NOTICE, "Call released by BS.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Call released by BS.\n"); new_call_state(trans, STATE_RELEASE); if (trans->callref) call_up_release(trans->callref, cnetz_fufst2cause(X)); @@ -1057,7 +1059,7 @@ outgoing: message_send(ident, opcode, data, len); if (trans->callref) call_up_release(trans->callref, cnetz_fufst2cause(X)); - PDEBUG(DCNETZ, DEBUG_NOTICE, "Call released by BS.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Call released by BS.\n"); new_call_state(trans, STATE_RELEASE); trans->callref = 0; destroy_transaction(trans); @@ -1087,7 +1089,7 @@ outgoing: message_send(ident, opcode, data, len); break; default: - PDEBUG(DCNETZ, DEBUG_INFO, "RX Message from BS with unknown OPcode: %02XH\n", opcode); + LOGP(DCNETZ, LOGL_INFO, "RX Message from BS with unknown OPcode: %02XH\n", opcode); } } @@ -1123,25 +1125,25 @@ static void mtp_receive(void *inst, enum mtp_prim prim, uint8_t slc, uint8_t *da default: cause_text = "MTP link '%s' failed! Trying again.\n"; } - PDEBUG(DCNETZ, DEBUG_NOTICE, cause_text, zzk->sender.kanal); + LOGP(DCNETZ, LOGL_NOTICE, cause_text, zzk->sender.kanal); mtp_send(&zzk->mtp, MTP_PRIM_START, 0, NULL, 0); zzk->link = 0; display_status(); break; case MTP_PRIM_IN_SERVICE: - PDEBUG(DCNETZ, DEBUG_NOTICE, "Link '%s' established.\n", zzk->sender.kanal); + LOGP(DCNETZ, LOGL_NOTICE, "Link '%s' established.\n", zzk->sender.kanal); zzk->link = 1; display_status(); break; case MTP_PRIM_REMOTE_PROCESSOR_OUTAGE: - PDEBUG(DCNETZ, DEBUG_NOTICE, "Link '%s' indicates remote processor outage.\n", zzk->sender.kanal); + LOGP(DCNETZ, LOGL_NOTICE, "Link '%s' indicates remote processor outage.\n", zzk->sender.kanal); break; case MTP_PRIM_REMOTE_PROCESSOR_RECOVERED: - PDEBUG(DCNETZ, DEBUG_NOTICE, "Link '%s' indicates remote processor outage is recovered.\n", zzk->sender.kanal); + LOGP(DCNETZ, LOGL_NOTICE, "Link '%s' indicates remote processor outage is recovered.\n", zzk->sender.kanal); break; case MTP_PRIM_DATA: if (len < 2) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "No Opcode, message too short!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "No Opcode, message too short!\n"); return; } @@ -1172,17 +1174,17 @@ int fuvst_create(const char *kanal, enum fuvst_chan_type chan_type, const char * fuvst = calloc(1, sizeof(fuvst_t)); if (!fuvst) { - PDEBUG(DCNETZ, DEBUG_ERROR, "No memory!\n"); + LOGP(DCNETZ, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DCNETZ, DEBUG_DEBUG, "Creating 'C-Netz' instance for 'Kanal' = %s (sample rate %d).\n", chan_name, samplerate); + LOGP(DCNETZ, LOGL_DEBUG, "Creating 'C-Netz' instance for 'Kanal' = %s (sample rate %d).\n", chan_name, samplerate); /* init general part of transceiver */ /* do not enable emphasis, since it is done by fuvst code, not by common sender code */ rc = sender_create(&fuvst->sender, options_strdup(chan_name), 0, 0, audiodev, 0, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DCNETZ, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } fuvst->chan_num = atoi(kanal); @@ -1208,7 +1210,7 @@ int fuvst_create(const char *kanal, enum fuvst_chan_type chan_type, const char * goto error; } - PDEBUG(DCNETZ, DEBUG_NOTICE, "Created 'Kanal' %s\n", chan_name); + LOGP(DCNETZ, LOGL_NOTICE, "Created 'Kanal' %s\n", chan_name); display_status(); @@ -1225,7 +1227,7 @@ void fuvst_destroy(sender_t *sender) { fuvst_t *fuvst = (fuvst_t *) sender; - PDEBUG(DCNETZ, DEBUG_DEBUG, "Destroying 'C-Netz' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DCNETZ, LOGL_DEBUG, "Destroying 'C-Netz' instance for 'Kanal' = %s.\n", sender->kanal); if (fuvst->chan_type == CHAN_TYPE_ZZK) { mtp_exit(&fuvst->mtp); @@ -1325,19 +1327,19 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 2. base station ready? */ if (!base_station_ready) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call not possible, base station not ready, rejecting!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call not possible, base station not ready, rejecting!\n"); return -CAUSE_TEMPFAIL; } /* 3. create transaction */ ident = get_free_ident(); if (!ident) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call not possible, no free Ident code?? What the hack?\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call not possible, no free Ident code?? What the hack?\n"); return -CAUSE_TEMPFAIL; } trans = create_transaction(ident, futln_nat, futln_fuvst, futln_rest, 0); if (!trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call not possible, Transaction already exists: Subscriber busy!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing call not possible, Transaction already exists: Subscriber busy!\n"); return -CAUSE_BUSY; } trans->callref = trans->old_callref = callref; @@ -1345,7 +1347,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 4. start call */ len = encode_kvau(&opcode, &data, futln_rest, futln_fuvst, futln_nat, 0, authentication); message_send(trans->ident, opcode, data, len); - PDEBUG(DCNETZ, DEBUG_INFO, "Send call for mobile towards BS. (Ident = %d, FuTln=%s)\n", ident, transaction2rufnummer(trans)); + LOGP(DCNETZ, LOGL_INFO, "Send call for mobile towards BS. (Ident = %d, FuTln=%s)\n", ident, transaction2rufnummer(trans)); new_call_state(trans, STATE_MT); return 0; @@ -1359,7 +1361,7 @@ void call_down_answer(int callref) trans = search_transaction_callref(callref); if (!trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Answer to unknown callref.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Answer to unknown callref.\n"); return; } @@ -1387,7 +1389,7 @@ static void _disconnect_release(transaction_t *trans, int callref, int cause) call_up_release(callref, cause); trans->callref = 0; new_call_state(trans, STATE_RELEASE); - timer_start(&trans->timer, RELEASE_TO); + osmo_timer_schedule(&trans->timer, RELEASE_TO); } /* Call control sends disconnect (with tones). @@ -1398,11 +1400,11 @@ void call_down_disconnect(int callref, int cause) { transaction_t *trans; - PDEBUG(DCNETZ, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call has been disconnected by network.\n"); trans = search_transaction_callref(callref); if (!trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing disconnect to unknown callref.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing disconnect to unknown callref.\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1422,11 +1424,11 @@ void call_down_release(int callref, int cause) { transaction_t *trans; - PDEBUG(DCNETZ, DEBUG_INFO, "Call has been released by network.\n"); + LOGP(DCNETZ, LOGL_INFO, "Call has been released by network.\n"); trans = search_transaction_callref(callref); if (!trans) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing released to unknown callref.\n"); + LOGP(DCNETZ, LOGL_NOTICE, "Outgoing released to unknown callref.\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1438,14 +1440,14 @@ void dump_info(void) { cnetz_db_t *db = cnetz_db_head; - PDEBUG(DDB, DEBUG_NOTICE, "Dump of subscriber database:\n"); + LOGP(DDB, LOGL_NOTICE, "Dump of subscriber database:\n"); if (!db) { - PDEBUG(DDB, DEBUG_NOTICE, " - No subscribers attached!\n"); + LOGP(DDB, LOGL_NOTICE, " - No subscribers attached!\n"); return; } while (db) { - PDEBUG(DDB, DEBUG_NOTICE, " - Subscriber '%d,%d,%d' is attached.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); + LOGP(DDB, LOGL_NOTICE, " - Subscriber '%d,%d,%d' is attached.\n", db->futln_nat, db->futln_fuvst, db->futln_rest); db = db->next; } } diff --git a/src/fuvst/main.c b/src/fuvst/main.c index 7a18da0..0a8ab58 100755 --- a/src/fuvst/main.c +++ b/src/fuvst/main.c @@ -23,10 +23,10 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../liboptions/options.h" #include "../libfm/fm.h" #include "../anetz/freiton.h" @@ -293,6 +293,7 @@ fail: fuvst_destroy(sender_head); /* exits */ + main_mobile_exit(); // zeit_exit(); fm_exit(); diff --git a/src/fuvst/mup.c b/src/fuvst/mup.c index 7224fb4..d462d37 100755 --- a/src/fuvst/mup.c +++ b/src/fuvst/mup.c @@ -23,7 +23,8 @@ #include <string.h> #include <time.h> #include <inttypes.h> -#include "../libdebug/debug.h" +#include <osmocom/core/utils.h> +#include "../liblogging/logging.h" #include "mup.h" #include "systemmeldungen.h" @@ -291,7 +292,7 @@ static const char *futln_cause(uint8_t Y) void decode_swaf(uint8_t *data, int len, uint8_t *V, uint8_t *N, uint8_t *U, uint8_t *F, uint8_t *C, uint8_t *B) { if (len < 6) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -302,7 +303,7 @@ void decode_swaf(uint8_t *data, int len, uint8_t *V, uint8_t *N, uint8_t *U, uin *C = data[4]; *B = data[5]; - PDEBUG(DMUP, DEBUG_INFO, "(BS SWAF) Wiederanlauf der BS: version=%d (%s) FuFSt=%d,%d,%d chip=%d (%s) beacon=%d (%s)\n", *V, version_string(*V), *N, *U, *F, *C, chip_string(*C), *B, beacon_string(*B)); + LOGP(DMUP, LOGL_INFO, "(BS SWAF) Wiederanlauf der BS: version=%d (%s) FuFSt=%d,%d,%d chip=%d (%s) beacon=%d (%s)\n", *V, version_string(*V), *N, *U, *F, *C, chip_string(*C), *B, beacon_string(*B)); } /* ack to base station boot */ @@ -310,7 +311,7 @@ int encode_swqu(uint8_t *opcode, uint8_t **data, uint8_t A) { static uint8_t buffer[1]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SWQU) Wiederanlaufquittung des MSC: aktivdatei=%d (%s)\n", A, aktivdatei_string(A)); + LOGP(DMUP, LOGL_INFO, "(MSC SWQU) Wiederanlaufquittung des MSC: aktivdatei=%d (%s)\n", A, aktivdatei_string(A)); *opcode = OPCODE_SWQU; buffer[0] = A; @@ -323,7 +324,7 @@ int encode_swqu(uint8_t *opcode, uint8_t **data, uint8_t A) void decode_suaf(uint8_t *data, int len, uint8_t *V, uint8_t *N, uint8_t *U, uint8_t *F, uint8_t *C, uint8_t *B) { if (len < 6) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -334,7 +335,7 @@ void decode_suaf(uint8_t *data, int len, uint8_t *V, uint8_t *N, uint8_t *U, uin *C = data[4]; *B = data[5]; - PDEBUG(DMUP, DEBUG_INFO, "(BS SUAF) Datum-Uhrzeit-Anforderung der BS: version=%d (%s) FuFSt=%d,%d,%d chip=%d (%s) beacon=%d (%s)\n", *V, version_string(*V), *N, *U, *F, *C, chip_string(*C), *B, beacon_string(*B)); + LOGP(DMUP, LOGL_INFO, "(BS SUAF) Datum-Uhrzeit-Anforderung der BS: version=%d (%s) FuFSt=%d,%d,%d chip=%d (%s) beacon=%d (%s)\n", *V, version_string(*V), *N, *U, *F, *C, chip_string(*C), *B, beacon_string(*B)); } /* ack to time request */ @@ -355,7 +356,7 @@ int encode_suqu(uint8_t *opcode, uint8_t **data, uint8_t Q, uint8_t N, time_t no m = tm->tm_min; s = tm->tm_sec; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SUQU) Datum-Uhrzeit-Quittung des MSC: Q=%d (%s) Widerholung=%d (%s) Wochentag=%d (%s) Datum: %d.%d.%d %d:%02d:%02d\n", Q, qualitaet_string(Q), N, wiederholung_string(N), W, woche_string(W), D, M, J, h, m, s); + LOGP(DMUP, LOGL_INFO, "(MSC SUQU) Datum-Uhrzeit-Quittung des MSC: Q=%d (%s) Widerholung=%d (%s) Wochentag=%d (%s) Datum: %d.%d.%d %d:%02d:%02d\n", Q, qualitaet_string(Q), N, wiederholung_string(N), W, woche_string(W), D, M, J, h, m, s); *opcode = OPCODE_SUQU; buffer[0] = Q | (N << 1) | (R << 2); @@ -380,7 +381,7 @@ void decode_sssaf(uint8_t *data, int len) int i, start_i = 0, stop_i = 0; if (len < 11) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -388,9 +389,9 @@ void decode_sssaf(uint8_t *data, int len) A = data[1] | (data[2] << 8); E = data[3] | (data[4] << 8); - PDEBUG(DMUP, DEBUG_INFO, "(BS SSSAF) Sprechkanal-Sammel-Sperrauftrag der BS: Liste-Ende=%d Anfang=%d Ende=%d\n", E_, A, E); + LOGP(DMUP, LOGL_INFO, "(BS SSSAF) Sprechkanal-Sammel-Sperrauftrag der BS: Liste-Ende=%d Anfang=%d Ende=%d\n", E_, A, E); if (E - A + 1 > 6 * 8) { - PDEBUG(DMUP, DEBUG_INFO, " -> Bereich zu gross für Nachricht!\n"); + LOGP(DMUP, LOGL_INFO, " -> Bereich zu gross für Nachricht!\n"); return; } if ((int)E - (int)A < 0) @@ -411,9 +412,9 @@ void decode_sssaf(uint8_t *data, int len) if (i > 0 && S != last_S) { end: if (start_i == stop_i) - PDEBUG(DMUP, DEBUG_INFO, " -> SpK #%d=%d (%s)\n", start_i + A, last_S, (last_S) ? "gesperrt" : "frei"); + LOGP(DMUP, LOGL_INFO, " -> SpK #%d=%d (%s)\n", start_i + A, last_S, (last_S) ? "gesperrt" : "frei"); else - PDEBUG(DMUP, DEBUG_INFO, " -> SpK #%d..%d=%d (%s)\n", start_i + A, stop_i + A, last_S, (last_S) ? "gesperrt" : "frei"); + LOGP(DMUP, LOGL_INFO, " -> SpK #%d..%d=%d (%s)\n", start_i + A, stop_i + A, last_S, (last_S) ? "gesperrt" : "frei"); /* new start */ start_i = stop_i = i; } @@ -425,20 +426,20 @@ end: void encode_sssqu(uint8_t *opcode) { *opcode = OPCODE_SSSQU; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SSSQU) Sprechkanal-Sammel-Sperrquittung des MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC SSSQU) Sprechkanal-Sammel-Sperrquittung des MSC\n"); } /* base station locks a voice channel */ void decode_ssaf(uint8_t *data, int len, uint8_t *S) { if (len < 1) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } *S = data[0]; - PDEBUG(DMUP, DEBUG_INFO, "(BS SSAF) Sprechkanal-Sperr-Auftrag der BS: SPK=%d\n", *S); + LOGP(DMUP, LOGL_INFO, "(BS SSAF) Sprechkanal-Sperr-Auftrag der BS: SPK=%d\n", *S); } /* ack to lockeed voice channel */ @@ -446,7 +447,7 @@ int encode_ssqu(uint8_t *opcode, uint8_t **data, uint8_t S) { static uint8_t buffer[1]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SSQU) Sprechkanal-Sperr-Quittung von der MSC: SPK=%d\n", S); + LOGP(DMUP, LOGL_INFO, "(MSC SSQU) Sprechkanal-Sperr-Quittung von der MSC: SPK=%d\n", S); *opcode = OPCODE_SSQU; buffer[0] = S; @@ -459,13 +460,13 @@ int encode_ssqu(uint8_t *opcode, uint8_t **data, uint8_t S) void decode_sfaf(uint8_t *data, int len, uint8_t *S) { if (len < 1) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } *S = data[0]; - PDEBUG(DMUP, DEBUG_INFO, "(BS SFAF) Sprechkanal-Freigabe-Auftrag der BS: SPK=%d\n", *S); + LOGP(DMUP, LOGL_INFO, "(BS SFAF) Sprechkanal-Freigabe-Auftrag der BS: SPK=%d\n", *S); } /* ack to unlockeed voice channel */ @@ -473,7 +474,7 @@ int encode_sfqu(uint8_t *opcode, uint8_t **data, uint8_t S) { static uint8_t buffer[1]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SFQU) Sprechkanal-Freigabe-Quittung von der MSC: SPK=%d\n", S); + LOGP(DMUP, LOGL_INFO, "(MSC SFQU) Sprechkanal-Freigabe-Quittung von der MSC: SPK=%d\n", S); *opcode = OPCODE_SFQU; buffer[0] = S; @@ -485,13 +486,13 @@ int encode_sfqu(uint8_t *opcode, uint8_t **data, uint8_t S) /* base station ready */ void decode_svaf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS SVAF) Vermittlungsfaehig-Auftrag der BS\n"); + LOGP(DMUP, LOGL_INFO, "(BS SVAF) Vermittlungsfaehig-Auftrag der BS\n"); } /* ack to base station ready */ int encode_svqu(uint8_t *opcode, uint8_t **data) { - PDEBUG(DMUP, DEBUG_INFO, "(MSC SVQU) Vermittlungsfaehig-Quittung des MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC SVQU) Vermittlungsfaehig-Quittung des MSC\n"); *opcode = OPCODE_SVQU; *data = NULL; @@ -501,13 +502,13 @@ int encode_svqu(uint8_t *opcode, uint8_t **data) /* base station requests alarm messages */ void decode_ylsaf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS YLSAF) Systemmeldungsanforderung an MSC\n"); + LOGP(DMUP, LOGL_INFO, "(BS YLSAF) Systemmeldungsanforderung an MSC\n"); } /* ack to base stations alarm request */ int encode_ylsmu(uint8_t *opcode, uint8_t **data) { - PDEBUG(DMUP, DEBUG_INFO, "(MSC YLSMU) Systemmeldungsbestaetigung vom MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC YLSMU) Systemmeldungsbestaetigung vom MSC\n"); *opcode = OPCODE_YLSMU; *data = NULL; @@ -518,7 +519,7 @@ int encode_ylsmu(uint8_t *opcode, uint8_t **data) void decode_ylsmf(uint8_t *data, int len, uint8_t *N, uint8_t *C, struct SysMeld *SM) { if (len < 9) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -578,7 +579,7 @@ void decode_ylsmf(uint8_t *data, int len, uint8_t *N, uint8_t *C, struct SysMeld indizien[strlen(indizien)] = ' '; } - PDEBUG(DMUP, DEBUG_INFO, "SM: %03d %02d.%02d %02d:%02d %s%02d %c H\"%04X %02d H\"%sH\"%02X%02X%02X%02X\n", *C, + LOGP(DMUP, LOGL_INFO, "SM: %03d %02d.%02d %02d:%02d %s%02d %c H\"%04X %02d H\"%sH\"%02X%02X%02X%02X\n", *C, SM->Monat, SM->Tag, SM->Stunde, SM->Minute, einrichtrungstyp_string(SM->Einrichtungstyp), SM->Einrichtungsnr, SM->ASCII_Typ ? : '0', SM->Systemmeldungsnr, @@ -590,13 +591,13 @@ void decode_ylsmf(uint8_t *data, int len, uint8_t *N, uint8_t *C, struct SysMeld /* base station ends list of alarm messages */ void decode_ylsef(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS YLSEF) Systemmeldungsuebertragungsende an MSC\n"); + LOGP(DMUP, LOGL_INFO, "(BS YLSEF) Systemmeldungsuebertragungsende an MSC\n"); } /* base station requests billing info */ void decode_stdaf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS STDAF) Tarifdatenauftrag der BS\n"); + LOGP(DMUP, LOGL_INFO, "(BS STDAF) Tarifdatenauftrag der BS\n"); } /* reply to billing info */ @@ -606,7 +607,7 @@ int encode_xgtau(uint8_t *opcode, uint8_t **data, uint8_t Z, uint32_t T, uint8_t // Example from UeLE-ROM = { 0xff, 0x00, 0x01, 0xec, 0x3f, 0x01, 0x31, 0x1c, 0x03 }; // { 0xff, 0x00, 0x01, 0xec, 0x3f, 0x01, 0x41, 0x1c, 0x03 }; - PDEBUG(DMUP, DEBUG_INFO, "(MSC XGTAU) Tarifdatensignalisierung vom MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC XGTAU) Tarifdatensignalisierung vom MSC\n"); *opcode = OPCODE_XGTAU; buffer[0] = 0xff; @@ -627,7 +628,7 @@ int encode_xgtau(uint8_t *opcode, uint8_t **data, uint8_t Z, uint32_t T, uint8_t void decode_ebaf(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t *N, uint16_t *s, uint8_t *u, uint8_t *b, uint8_t *l) { if (len < 6) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -639,13 +640,13 @@ void decode_ebaf(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t *N, ui *b = (data[5] >> 6) & 0x1; *l = data[5] >> 7; - PDEBUG(DMUP, DEBUG_INFO, "(BS EBAF) Einbuchauftrag: FuTln=%d,%d,%d (0161-%d%d%05d)\n", *N, *U, *T, *N, *U, *T); + LOGP(DMUP, LOGL_INFO, "(BS EBAF) Einbuchauftrag: FuTln=%d,%d,%d (0161-%d%d%05d)\n", *N, *U, *T, *N, *U, *T); } /* ack to inscription */ int encode_ebpqu(uint8_t *opcode, uint8_t **data) { - PDEBUG(DMUP, DEBUG_INFO, "(MSC EBPQU) Einbuchungs-Positiv-Quittiung vom MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC EBPQU) Einbuchungs-Positiv-Quittiung vom MSC\n"); *opcode = OPCODE_EBPQU; *data = NULL; @@ -656,7 +657,7 @@ int encode_ebpqu(uint8_t *opcode, uint8_t **data) void decode_abaf(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t *N) { if (len < 3) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -664,7 +665,7 @@ void decode_abaf(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t *N) *U = data[2] & 0x1f; *N = data[2] >> 5; - PDEBUG(DMUP, DEBUG_INFO, "(BS ABAF) Ausbuchung-Auftrag der BS: FuTln=%d,%d,%d (0161-%d%d%05d)\n", *N, *U, *T, *N, *U, *T); + LOGP(DMUP, LOGL_INFO, "(BS ABAF) Ausbuchung-Auftrag der BS: FuTln=%d,%d,%d (0161-%d%d%05d)\n", *N, *U, *T, *N, *U, *T); } static char digit2char[16] = "0123456789a*#bcd"; @@ -675,7 +676,7 @@ void _decode_outgoing(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t * int i; if (len < 11) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -709,14 +710,14 @@ void decode_gvaf(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t *N, ch { _decode_outgoing(data, len, T, U , N, number); - PDEBUG(DMUP, DEBUG_INFO, "(BS GVAF) Gehender Verbindungs-Auftrag der BS: FuTln=%d,%d,%d (0161-%d%d%05d) number=%s\n", *N, *U, *T, *N, *U, *T, number); + LOGP(DMUP, LOGL_INFO, "(BS GVAF) Gehender Verbindungs-Auftrag der BS: FuTln=%d,%d,%d (0161-%d%d%05d) number=%s\n", *N, *U, *T, *N, *U, *T, number); } void decode_gvwaf(uint8_t *data, int len, uint16_t *T, uint8_t *U, uint8_t *N, char *number) { _decode_outgoing(data, len, T, U , N, number); - PDEBUG(DMUP, DEBUG_INFO, "(BS GVWAF) Gehender Verbindungs-Warteschlange-Auftrag der BS: FuTln=%d,%d,%d (0161-%d%d%05d) number=%s\n", *N, *U, *T, *N, *U, *T, number); + LOGP(DMUP, LOGL_INFO, "(BS GVWAF) Gehender Verbindungs-Warteschlange-Auftrag der BS: FuTln=%d,%d,%d (0161-%d%d%05d) number=%s\n", *N, *U, *T, *N, *U, *T, number); } /* ack to MO call */ @@ -724,7 +725,7 @@ int encode_gvpqu(uint8_t *opcode, uint8_t **data, uint8_t P, uint8_t e) { static uint8_t buffer[2]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC GVPQU) Verbindungs-Positiv-Quittiung vom MSC: Prio=%d (%s) AP-Pruefung=%d\n", P, prio_string(P), e); + LOGP(DMUP, LOGL_INFO, "(MSC GVPQU) Verbindungs-Positiv-Quittiung vom MSC: Prio=%d (%s) AP-Pruefung=%d\n", P, prio_string(P), e); *opcode = OPCODE_GVNQU; buffer[0] = P; @@ -739,7 +740,7 @@ int encode_gvnqu(uint8_t *opcode, uint8_t **data, uint8_t X, uint8_t Y) { static uint8_t buffer[2]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC GVNQU) Verbindungs-Negativ-Quittiung vom MSC: Grund=%d (%s) Grund(FuTlg)=%d (%s)\n", X, fufst_cause(X), Y, futln_cause(Y)); + LOGP(DMUP, LOGL_INFO, "(MSC GVNQU) Verbindungs-Negativ-Quittiung vom MSC: Grund=%d (%s) Grund(FuTlg)=%d (%s)\n", X, fufst_cause(X), Y, futln_cause(Y)); *opcode = OPCODE_GVNQU; buffer[0] = X; @@ -754,7 +755,7 @@ int encode_kvau(uint8_t *opcode, uint8_t **data, uint16_t T, uint8_t U, uint8_t { static uint8_t buffer[5]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC KVAU) Kommender Verbindungs-Auftrag vom MSC: FuTln=%d,%d,%d (0161-%d%d%05d) Rufzeitbegrenzung=%d (%s) AP-Pruefung=%d\n", N, U, T, N, U, T, F, rufzeit_string(F), e); + LOGP(DMUP, LOGL_INFO, "(MSC KVAU) Kommender Verbindungs-Auftrag vom MSC: FuTln=%d,%d,%d (0161-%d%d%05d) Rufzeitbegrenzung=%d (%s) AP-Pruefung=%d\n", N, U, T, N, U, T, F, rufzeit_string(F), e); *opcode = OPCODE_KVAU; buffer[0] = T; @@ -770,20 +771,20 @@ int encode_kvau(uint8_t *opcode, uint8_t **data, uint16_t T, uint8_t U, uint8_t /* ack to MT call on queue */ void decode_kvwqf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS KVWQF) Kommende Verbindungs-Warteschalngen-Quittung der BS\n"); + LOGP(DMUP, LOGL_INFO, "(BS KVWQF) Kommende Verbindungs-Warteschalngen-Quittung der BS\n"); } /* answer of MT call */ void decode_kvbaf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS KVBAF) Kommende Verbindungs-Beginn-Auftrag der BS\n"); + LOGP(DMUP, LOGL_INFO, "(BS KVBAF) Kommende Verbindungs-Beginn-Auftrag der BS\n"); } /* loop test request */ void decode_staf(uint8_t *data, int len, uint8_t *Q, uint8_t *V, uint8_t *e, uint64_t *n) { if (len < 10) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -799,7 +800,7 @@ void decode_staf(uint8_t *data, int len, uint8_t *Q, uint8_t *V, uint8_t *e, uin *n |= (uint64_t)data[8] << 48; *n |= (uint64_t)data[9] << 56; - PDEBUG(DMUP, DEBUG_INFO, "(BS STAF) Schleifentest-Auftrag der BS: SPK=%d Typ=%d (%s) AP-Pruefung=%d Random=0x%016" PRIx64 "\n", *Q, *V, typ_string(*V), *e, *n); + LOGP(DMUP, LOGL_INFO, "(BS STAF) Schleifentest-Auftrag der BS: SPK=%d Typ=%d (%s) AP-Pruefung=%d Random=0x%016" PRIx64 "\n", *Q, *V, typ_string(*V), *e, *n); } /* loop test positive */ @@ -807,7 +808,7 @@ int encode_stpqu(uint8_t *opcode, uint8_t **data, uint8_t Q, uint8_t A, uint8_t { static uint8_t buffer[7]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC STPQU) Schleifentest-Positiv-Quittiung vom MSC: SPK=%d\n", Q); + LOGP(DMUP, LOGL_INFO, "(MSC STPQU) Schleifentest-Positiv-Quittiung vom MSC: SPK=%d\n", Q); *opcode = OPCODE_STPQU; buffer[0] = Q; @@ -827,7 +828,7 @@ int encode_stnqu(uint8_t *opcode, uint8_t **data, uint8_t Q) { static uint8_t buffer[1]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC STNQU) Schleifentest-Negativ-Quittiung vom MSC: SPK=%d\n", Q); + LOGP(DMUP, LOGL_INFO, "(MSC STNQU) Schleifentest-Negativ-Quittiung vom MSC: SPK=%d\n", Q); *opcode = OPCODE_STNQU; buffer[0] = Q; @@ -840,7 +841,7 @@ int encode_stnqu(uint8_t *opcode, uint8_t **data, uint8_t Q) void decode_apf(uint8_t *data, int len, uint8_t *Q, uint64_t *a) { if (len < 9) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -854,7 +855,7 @@ void decode_apf(uint8_t *data, int len, uint8_t *Q, uint64_t *a) *a |= (uint64_t)data[7] << 48; *a |= (uint64_t)data[8] << 56; - PDEBUG(DMUP, DEBUG_INFO, "(BS APF) Autorisierunsparameter FUKO: SPK=%d AP=0x%016" PRIx64 "\n", *Q, *a); + LOGP(DMUP, LOGL_INFO, "(BS APF) Autorisierunsparameter FUKO: SPK=%d AP=0x%016" PRIx64 "\n", *Q, *a); } /* start metering pulses (answer to call) */ @@ -862,7 +863,7 @@ int encode_gstau(uint8_t *opcode, uint8_t **data, uint8_t Q, uint16_t G, uint8_t { static uint8_t buffer[6]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC GSTAU) Gebuehren-Start-Auftrag vom MSC: SPK=%d\n", Q); + LOGP(DMUP, LOGL_INFO, "(MSC GSTAU) Gebuehren-Start-Auftrag vom MSC: SPK=%d\n", Q); *opcode = OPCODE_GSTAU; buffer[0] = Q; @@ -879,26 +880,26 @@ int encode_gstau(uint8_t *opcode, uint8_t **data, uint8_t Q, uint16_t G, uint8_t /* MCID */ void decode_faf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS FAF) Fang-Auftrag der BS\n"); + LOGP(DMUP, LOGL_INFO, "(BS FAF) Fang-Auftrag der BS\n"); } /* release by base station (before SPK assignment) */ void decode_naf(uint8_t *data, int len, uint8_t *X) { if (len < 1) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } *X = data[0]; - PDEBUG(DMUP, DEBUG_INFO, "(BS AAF) Negativ-Auftrag der BS: Grund=%d (%s)\n", *X, fufst_cause(*X)); + LOGP(DMUP, LOGL_INFO, "(BS AAF) Negativ-Auftrag der BS: Grund=%d (%s)\n", *X, fufst_cause(*X)); } /* release by base station ack (before SPK assignment) */ int encode_equ(uint8_t *opcode, uint8_t **data) { - PDEBUG(DMUP, DEBUG_INFO, "(MSC AQU) Ende-Quittung vom MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC AQU) Ende-Quittung vom MSC\n"); *opcode = OPCODE_EQU; *data = NULL; @@ -909,14 +910,14 @@ int encode_equ(uint8_t *opcode, uint8_t **data) void decode_aaf(uint8_t *data, int len, uint8_t *Q, uint8_t *X) { if (len < 2) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } *Q = data[0]; *X = data[1]; - PDEBUG(DMUP, DEBUG_INFO, "(BS AAF) Ausloese-Auftrag der BS: SPK=%d, Grund=%d (%s)\n", *Q, *X, fufst_cause(*X)); + LOGP(DMUP, LOGL_INFO, "(BS AAF) Ausloese-Auftrag der BS: SPK=%d, Grund=%d (%s)\n", *Q, *X, fufst_cause(*X)); } /* release by base station ack (after SPK assignment) */ @@ -924,7 +925,7 @@ int encode_aqu(uint8_t *opcode, uint8_t **data, uint8_t Q) { static uint8_t buffer[1]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC AQU) Ausloese-Quittung vom MSC: SPK=%d\n", Q); + LOGP(DMUP, LOGL_INFO, "(MSC AQU) Ausloese-Quittung vom MSC: SPK=%d\n", Q); *opcode = OPCODE_AQU; buffer[0] = Q; @@ -938,7 +939,7 @@ int encode_nau(uint8_t *opcode, uint8_t **data, uint8_t X, uint8_t Y) { static uint8_t buffer[2]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC NAU) Negativ-Auftrag vom MSC: Grund=%d (%s) Grund(FuTlg)=%d (%s)\n", X, fufst_cause(X), Y, futln_cause(Y)); + LOGP(DMUP, LOGL_INFO, "(MSC NAU) Negativ-Auftrag vom MSC: Grund=%d (%s) Grund(FuTlg)=%d (%s)\n", X, fufst_cause(X), Y, futln_cause(Y)); *opcode = OPCODE_NAU; buffer[0] = X; @@ -951,7 +952,7 @@ int encode_nau(uint8_t *opcode, uint8_t **data, uint8_t X, uint8_t Y) /* release by network ack (before SPK assignment) */ void decode_eqf(uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { - PDEBUG(DMUP, DEBUG_INFO, "(BS EQF) Ende-Quittung der BS\n"); + LOGP(DMUP, LOGL_INFO, "(BS EQF) Ende-Quittung der BS\n"); } /* release by network (after SPK assignment) */ @@ -959,7 +960,7 @@ int encode_aau(uint8_t *opcode, uint8_t **data, uint8_t Q, uint8_t X, uint8_t Y) { static uint8_t buffer[3]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC AAU) Ausloese-Auftrag vom MSC: SPK=%d, Grund=%d (%s) Grund(FuTlg)=%d (%s)\n", Q, X, fufst_cause(X), Y, futln_cause(Y)); + LOGP(DMUP, LOGL_INFO, "(MSC AAU) Ausloese-Auftrag vom MSC: SPK=%d, Grund=%d (%s) Grund(FuTlg)=%d (%s)\n", Q, X, fufst_cause(X), Y, futln_cause(Y)); *opcode = OPCODE_AAU; buffer[0] = Q; @@ -974,20 +975,20 @@ int encode_aau(uint8_t *opcode, uint8_t **data, uint8_t Q, uint8_t X, uint8_t Y) void decode_aqf(uint8_t *data, int len, uint8_t *Q) { if (len < 1) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } *Q = data[0]; - PDEBUG(DMUP, DEBUG_INFO, "(BS AQF) Ausloese-Quittung der BS: SPK=%d\n", *Q); + LOGP(DMUP, LOGL_INFO, "(BS AQF) Ausloese-Quittung der BS: SPK=%d\n", *Q); } /* request data base block */ void decode_xadbf(uint8_t *data, int len, uint8_t *PJ, uint16_t *D, uint16_t *L) { if (len < 6) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -995,7 +996,7 @@ void decode_xadbf(uint8_t *data, int len, uint8_t *PJ, uint16_t *D, uint16_t *L) *D = data[2] | (data[3] << 8); *L = data[4] | (data[5] << 8); - PDEBUG(DMUP, DEBUG_INFO, "(BS XADBF) Auftragssign. Anfordern BS-DB-Datenblock am MSC: job=%d, offset=0x%02x length=0x%02x\n", *PJ, *D, *L); + LOGP(DMUP, LOGL_INFO, "(BS XADBF) Auftragssign. Anfordern BS-DB-Datenblock am MSC: job=%d, offset=0x%02x length=0x%02x\n", *PJ, *D, *L); } /* transfer data base block */ @@ -1003,7 +1004,7 @@ int encode_xedbu_1(uint8_t *opcode, uint8_t **data, uint8_t R, uint8_t PJ, uint1 { static uint8_t buffer[4]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (header): return=%d job=%d frames=%d\n", R, PJ, A); + LOGP(DMUP, LOGL_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (header): return=%d job=%d frames=%d\n", R, PJ, A); *opcode = OPCODE_XEDBU; buffer[0] = R; @@ -1018,10 +1019,10 @@ int encode_xedbu_2(uint8_t *opcode, uint8_t **data, uint8_t S, uint8_t PJ, uint8 { static uint8_t buffer[11]; - if (debuglevel == DEBUG_DEBUG) - PDEBUG(DMUP, DEBUG_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (data): count=%d job=%d data=%s\n", S, PJ, debug_hex(P, 9)); + if (loglevel == LOGL_DEBUG) + LOGP(DMUP, LOGL_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (data): count=%d job=%d data=%s\n", S, PJ, osmo_hexdump(P, 9)); else if (S == 1) - PDEBUG(DMUP, DEBUG_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (data): Messages are not shown, due to heavy debug output!\n"); + LOGP(DMUP, LOGL_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (data): Messages are not shown, due to heavy debug output!\n"); *opcode = OPCODE_XEDBU; buffer[0] = S; @@ -1035,7 +1036,7 @@ int encode_xedbu_3(uint8_t *opcode, uint8_t **data, uint8_t S, uint8_t PJ, uint1 { static uint8_t buffer[9]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (footer): count=%d job=%d offset=0x%02x length=0x%02x checksum=0x%06x\n", S, PJ, D, L, CS); + LOGP(DMUP, LOGL_INFO, "(MSC XEDBU) Ergebnissignal. Transfer BS-DB-Datenblock (footer): count=%d job=%d offset=0x%02x length=0x%02x checksum=0x%06x\n", S, PJ, D, L, CS); *opcode = OPCODE_XEDBU; buffer[0] = S; @@ -1057,7 +1058,7 @@ int encode_yaaau(uint8_t *opcode, uint8_t **data, uint8_t J) { static uint8_t buffer[2]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC YAAAU) Auftrag Initialisieren BS des MSC: job=%d\n", J); + LOGP(DMUP, LOGL_INFO, "(MSC YAAAU) Auftrag Initialisieren BS des MSC: job=%d\n", J); *opcode = OPCODE_YAAAU; buffer[0] = 0xff; @@ -1072,7 +1073,7 @@ int encode_swau(uint8_t *opcode, uint8_t **data, uint8_t V) { static uint8_t buffer[1]; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SWAU) Wiederanlaufauftrag des MSC: version=%d (%s)\n", V, version_string(V)); + LOGP(DMUP, LOGL_INFO, "(MSC SWAU) Wiederanlaufauftrag des MSC: version=%d (%s)\n", V, version_string(V)); *opcode = OPCODE_SWAU; buffer[0] = V; @@ -1085,7 +1086,7 @@ int encode_swau(uint8_t *opcode, uint8_t **data, uint8_t V) void decode_swqf(uint8_t *data, int len, uint8_t *V, uint8_t *N, uint8_t *U, uint8_t *F, uint8_t *C, uint8_t *B) { if (len < 6) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return; } @@ -1096,14 +1097,14 @@ void decode_swqf(uint8_t *data, int len, uint8_t *V, uint8_t *N, uint8_t *U, uin *C = data[4]; *B = data[5]; - PDEBUG(DMUP, DEBUG_INFO, "(BS SWQF) Wiederanlauf-Quittung der BS: version=%d (%s) FuFSt=%d,%d,%d chip=%d (%s) beacon=%d (%s)\n", *V, version_string(*V), *N, *U, *F, *C, chip_string(*C), *B, beacon_string(*B)); + LOGP(DMUP, LOGL_INFO, "(BS SWQF) Wiederanlauf-Quittung der BS: version=%d (%s) FuFSt=%d,%d,%d chip=%d (%s) beacon=%d (%s)\n", *V, version_string(*V), *N, *U, *F, *C, chip_string(*C), *B, beacon_string(*B)); } /* request "Aktivdatei" (inscripted substribers) */ void encode_sadau(uint8_t *opcode) { *opcode = OPCODE_SADAU; - PDEBUG(DMUP, DEBUG_INFO, "(MSC SADAU) Aktivdatei-Auftrag vom MSC\n"); + LOGP(DMUP, LOGL_INFO, "(MSC SADAU) Aktivdatei-Auftrag vom MSC\n"); } /* ack "Aktivdatei" */ @@ -1112,7 +1113,7 @@ int decode_sadqf(uint8_t *data, int len, uint16_t *S, uint8_t *E, uint8_t *l, ui int i, n = 0; if (len < 11) { - PDEBUG(DMUP, DEBUG_NOTICE, "Message too short!\n"); + LOGP(DMUP, LOGL_NOTICE, "Message too short!\n"); return 0; } @@ -1127,9 +1128,9 @@ int decode_sadqf(uint8_t *data, int len, uint16_t *S, uint8_t *E, uint8_t *l, ui n++; } - PDEBUG(DMUP, DEBUG_INFO, "(BS SADQF) Aktivdateiquittung der BS:\n"); + LOGP(DMUP, LOGL_INFO, "(BS SADQF) Aktivdateiquittung der BS:\n"); for (i = 0; i < n; i++) - PDEBUG(DMUP, DEBUG_INFO, " %d: FuTln=%d,%d,%d (0161-%d%d%05d)\n", i + 1, N[i], U[i], T[i], N[i], U[i], T[i]); + LOGP(DMUP, LOGL_INFO, " %d: FuTln=%d,%d,%d (0161-%d%d%05d)\n", i + 1, N[i], U[i], T[i], N[i], U[i], T[i]); return n; } diff --git a/src/fuvst/sniffer.c b/src/fuvst/sniffer.c index f7fd656..90e1e07 100644 --- a/src/fuvst/sniffer.c +++ b/src/fuvst/sniffer.c @@ -23,8 +23,9 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libtimer/timer.h" -#include "../libdebug/debug.h" +#include <osmocom/core/timer.h> +#include <osmocom/core/utils.h> +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../liboptions/options.h" @@ -72,7 +73,7 @@ static void receive_fisu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, uint { sniffer_t *sniffer = (sniffer_t *)mtp->inst; - PDEBUG(DMTP3, (fsn == sniffer->last_fsn) ? DEBUG_INFO : DEBUG_NOTICE, "%s FISU Frame: FSN=%d FIB=%d BSN=%d BIB=%d\n", mtp->name, fsn, fib, bsn, bib); + LOGP(DMTP3, (fsn == sniffer->last_fsn) ? LOGL_INFO : LOGL_NOTICE, "%s FISU Frame: FSN=%d FIB=%d BSN=%d BIB=%d\n", mtp->name, fsn, fib, bsn, bib); /* store current FSN */ sniffer->last_fsn = fsn; @@ -83,7 +84,7 @@ static void receive_lssu(mtp_t *mtp, uint8_t fsn, uint8_t bib, uint8_t status) { sniffer_t *sniffer = (sniffer_t *)mtp->inst; - PDEBUG(DMTP3, DEBUG_INFO, "%s LSSU Frame: FSN=%d BIB=%d status=%d\n", mtp->name, fsn, bib, status); + LOGP(DMTP3, LOGL_INFO, "%s LSSU Frame: FSN=%d BIB=%d status=%d\n", mtp->name, fsn, bib, status); /* store initial FSN */ sniffer->last_fsn = fsn; @@ -98,17 +99,17 @@ static void receive_msu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, uint8 uint8_t ident, opcode; if (len < 4) { - PDEBUG(DMTP3, DEBUG_NOTICE, "Short frame from layer 2 (len=%d)\n", len); + LOGP(DMTP3, LOGL_NOTICE, "Short frame from layer 2 (len=%d)\n", len); return; } if (fsn == sniffer->last_fsn) { - PDEBUG(DMTP3, DEBUG_INFO, "%s MSU Frame: FSN=%d FIB=%d BSN=%d BIB=%d data: %02x %s\n", mtp->name, fsn, fib, bsn, bib, sio, debug_hex(data, len)); + LOGP(DMTP3, LOGL_INFO, "%s MSU Frame: FSN=%d FIB=%d BSN=%d BIB=%d data: %02x %s\n", mtp->name, fsn, fib, bsn, bib, sio, osmo_hexdump(data, len)); return; } if (len < 6) { - PDEBUG(DMTP3, DEBUG_NOTICE, "Frame from layer 2 too short to carry an Opcode (len=%d)\n", len); + LOGP(DMTP3, LOGL_NOTICE, "Frame from layer 2 too short to carry an Opcode (len=%d)\n", len); return; } @@ -126,9 +127,9 @@ static void receive_msu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, uint8 len -= 6; if (sio == 0xcd) - PDEBUG(DMTP3, DEBUG_NOTICE, "%s MuP Frame: FSN=%d FIB=%d BSN=%d BIB=%d SIO=0x%02x DCP=%d OCP=%d Ident=0x%02x OP=%02XH %s\n", mtp->name, fsn, fib, bsn, bib, sio, dcp, ocp, ident, opcode, debug_hex(data, len)); + LOGP(DMTP3, LOGL_NOTICE, "%s MuP Frame: FSN=%d FIB=%d BSN=%d BIB=%d SIO=0x%02x DCP=%d OCP=%d Ident=0x%02x OP=%02XH %s\n", mtp->name, fsn, fib, bsn, bib, sio, dcp, ocp, ident, opcode, osmo_hexdump(data, len)); else - PDEBUG(DMTP3, DEBUG_NOTICE, "%s MSU Frame: FSN=%d FIB=%d BSN=%d BIB=%d SIO=0x%02x DCP=%d OCP=%d SLC=%d H2/H1=0x%02x %02x %s\n", mtp->name, fsn, fib, bsn, bib, sio, dcp, ocp, slc, h2h1, data[-1], debug_hex(data, len)); + LOGP(DMTP3, LOGL_NOTICE, "%s MSU Frame: FSN=%d FIB=%d BSN=%d BIB=%d SIO=0x%02x DCP=%d OCP=%d SLC=%d H2/H1=0x%02x %02x %s\n", mtp->name, fsn, fib, bsn, bib, sio, dcp, ocp, slc, h2h1, data[-1], osmo_hexdump(data, len)); /* store current FSN */ sniffer->last_fsn = fsn; @@ -158,7 +159,7 @@ void sniffer_destroy(sender_t *sender) { sniffer_t *sniffer = (sniffer_t *) sender; - PDEBUG(DCNETZ, DEBUG_DEBUG, "Destroying 'Sniffer' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DCNETZ, LOGL_DEBUG, "Destroying 'Sniffer' instance for 'Kanal' = %s.\n", sender->kanal); mtp_exit(&sniffer->mtp); @@ -202,11 +203,11 @@ int main(int argc, char *argv[]) if (num_device <= 1) dsp_device[1] = dsp_device[0]; for (i = 0; i < num_kanal; i++) { - PDEBUG(DCNETZ, DEBUG_DEBUG, "Creating 'Sniffer' instance for 'Kanal' = %s (sample rate %d).\n", kanal[i], dsp_samplerate); + LOGP(DCNETZ, LOGL_DEBUG, "Creating 'Sniffer' instance for 'Kanal' = %s (sample rate %d).\n", kanal[i], dsp_samplerate); sniffer = calloc(1, sizeof(sniffer_t)); if (!sniffer) { - PDEBUG(DCNETZ, DEBUG_ERROR, "No memory!\n"); + LOGP(DCNETZ, LOGL_ERROR, "No memory!\n"); goto fail; } rc = sender_create(&sniffer->sender, kanal[i], 131, 131, dsp_device[i], 0, dsp_samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); @@ -234,6 +235,7 @@ fail: sniffer_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); return 0; diff --git a/src/fuvst/systemmeldungen.c b/src/fuvst/systemmeldungen.c index 1d801ee..504a4aa 100644 --- a/src/fuvst/systemmeldungen.c +++ b/src/fuvst/systemmeldungen.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <inttypes.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "systemmeldungen.h" static struct systemmeldungen { @@ -21894,8 +21894,8 @@ void print_systemmeldung(uint16_t code, int bytes, uint8_t *ind) if (i == ii) return; - PDEBUG(DMUP, DEBUG_INFO, " -> %s\n", systemmeldungen[i].desc); + LOGP(DMUP, LOGL_INFO, " -> %s\n", systemmeldungen[i].desc); for (j = 0; j < systemmeldungen[i].bytes; j++) - PDEBUG(DMUP, DEBUG_INFO, " Byte %d = %02Xh: %s\n", j, ind[j], systemmeldungen[i].ind[j]); + LOGP(DMUP, LOGL_INFO, " Byte %d = %02Xh: %s\n", j, ind[j], systemmeldungen[i].ind[j]); } diff --git a/src/golay/Makefile.am b/src/golay/Makefile.am index 9375968..1bde6cc 100644 --- a/src/golay/Makefile.am +++ b/src/golay/Makefile.am @@ -12,21 +12,19 @@ golay_LDADD = \ $(COMMON_LA) \ ../amps/libusatone.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/golay/dsp.c b/src/golay/dsp.c index 3a264c0..224ecbd 100644 --- a/src/golay/dsp.c +++ b/src/golay/dsp.c @@ -27,7 +27,7 @@ #include <math.h> #include <sys/param.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "golay.h" #include "dsp.h" @@ -39,7 +39,7 @@ static void dsp_init_ramp(gsc_t *gsc) double c; int i; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Generating cosine shaped ramp table.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Generating cosine shaped ramp table.\n"); for (i = 0; i < 256; i++) { /* This is mathematically incorrect... */ if (i < 64) @@ -58,7 +58,7 @@ int dsp_init_sender(gsc_t *gsc, int samplerate, double deviation, double polarit { int rc; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for transceiver.\n"); /* set modulation parameters */ // NOTE: baudrate equals modulation, because we have a raised cosine ramp of beta = 0.5 @@ -66,12 +66,12 @@ int dsp_init_sender(gsc_t *gsc, int samplerate, double deviation, double polarit gsc->fsk_bitduration = (double)samplerate / 600.0; gsc->fsk_bitstep = 1.0 / gsc->fsk_bitduration; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Use %.4f samples for one bit duration @ %d.\n", gsc->fsk_bitduration, gsc->sender.samplerate); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Use %.4f samples for one bit duration @ %d.\n", gsc->fsk_bitduration, gsc->sender.samplerate); gsc->fsk_tx_buffer_size = gsc->fsk_bitduration + 10; /* 1 bit, add some extra to prevent short buffer due to rounding */ gsc->fsk_tx_buffer = calloc(sizeof(sample_t), gsc->fsk_tx_buffer_size); if (!gsc->fsk_tx_buffer) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "No memory!\n"); rc = -ENOMEM; goto error; } @@ -93,7 +93,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_sender(gsc_t *gsc) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for transceiver.\n"); if (gsc->fsk_tx_buffer) { free(gsc->fsk_tx_buffer); @@ -202,7 +202,7 @@ again: } samplerate_upsample(&gsc->wave_tx_upsample, wave_samples[0], wave_num, samples, length); if (!gsc->wave_tx_play.left) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Voice message sent.\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Voice message sent.\n"); wave_destroy_playback(&gsc->wave_tx_play); return; } @@ -221,9 +221,9 @@ again: rc = wave_create_playback(&gsc->wave_tx_play, gsc->wave_tx_filename, &gsc->wave_tx_samplerate, &gsc->wave_tx_channels, gsc->fsk_deviation); if (rc < 0) { gsc->wave_tx_play.left = 0; - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Failed to open wave file '%s' for voice message.\n", gsc->wave_tx_filename); + LOGP_CHAN(DDSP, LOGL_ERROR, "Failed to open wave file '%s' for voice message.\n", gsc->wave_tx_filename); } else { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Sending wave file '%s' for voice message after 2 seconds.\n", gsc->wave_tx_filename); + LOGP_CHAN(DDSP, LOGL_INFO, "Sending wave file '%s' for voice message after 2 seconds.\n", gsc->wave_tx_filename); init_samplerate(&gsc->wave_tx_upsample, gsc->wave_tx_samplerate, gsc->sender.samplerate, VOICE_BANDWIDTH); } } diff --git a/src/golay/golay.c b/src/golay/golay.c index 789b287..c79a9dc 100644 --- a/src/golay/golay.c +++ b/src/golay/golay.c @@ -34,7 +34,7 @@ #include <sys/types.h> #include <sys/param.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../libmobile/cause.h" @@ -49,30 +49,30 @@ int golay_create(const char *kanal, double frequency, const char *device, int us gsc = calloc(1, sizeof(*gsc)); if (!gsc) { - PDEBUG(DGOLAY, DEBUG_ERROR, "No memory!\n"); + LOGP(DGOLAY, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DGOLAY, DEBUG_DEBUG, "Creating 'GOLAY' instance for frequency = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DGOLAY, LOGL_DEBUG, "Creating 'GOLAY' instance for frequency = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&gsc->sender, kanal, frequency, frequency, device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DGOLAY, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DGOLAY, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(gsc, samplerate, deviation, polarity); if (rc < 0) { - PDEBUG(DGOLAY, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DGOLAY, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } gsc->tx = 1; gsc->default_message = message; - PDEBUG(DGOLAY, DEBUG_NOTICE, "Created transmitter for frequency %s\n", kanal); + LOGP(DGOLAY, LOGL_NOTICE, "Created transmitter for frequency %s\n", kanal); return 0; @@ -89,7 +89,7 @@ void golay_destroy(sender_t *sender) { gsc_t *gsc = (gsc_t *) sender; - PDEBUG(DGOLAY, DEBUG_DEBUG, "Destroying 'GOLAY' instance for frequency = %s.\n", sender->kanal); + LOGP(DGOLAY, LOGL_DEBUG, "Destroying 'GOLAY' instance for frequency = %s.\n", sender->kanal); while (gsc->msg_list) golay_msg_destroy(gsc, gsc->msg_list); @@ -104,11 +104,11 @@ static gsc_msg_t *golay_msg_create(gsc_t *gsc, const char *address, const char * gsc_msg_t *msg, **msgp; if (strlen(address) != sizeof(msg->address) - 1) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Address has incorrect length, cannot page!\n"); + LOGP(DGOLAY, LOGL_NOTICE, "Address has incorrect length, cannot page!\n"); return NULL; } if (strlen(text) > sizeof(msg->data) - 1) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Given test is too long, cannot page!\n"); + LOGP(DGOLAY, LOGL_NOTICE, "Given test is too long, cannot page!\n"); return NULL; } @@ -126,18 +126,18 @@ static gsc_msg_t *golay_msg_create(gsc_t *gsc, const char *address, const char * case '9': type = TYPE_TONE; break; case '0': type = TYPE_TONE; break; default: - PDEBUG(DGOLAY, DEBUG_NOTICE, "Illegal function suffix '%c' in last address digit.\n", address[6]); + LOGP(DGOLAY, LOGL_NOTICE, "Illegal function suffix '%c' in last address digit.\n", address[6]); return NULL; } } else - PDEBUG(DGOLAY, DEBUG_INFO, "Overriding message type as defined by sender.\n"); + LOGP(DGOLAY, LOGL_INFO, "Overriding message type as defined by sender.\n"); - PDEBUG(DGOLAY, DEBUG_INFO, "Creating msg instance to page address '%s'.\n", address); + LOGP(DGOLAY, LOGL_INFO, "Creating msg instance to page address '%s'.\n", address); /* create */ msg = calloc(1, sizeof(*msg)); if (!msg) { - PDEBUG(DGOLAY, DEBUG_ERROR, "No mem!\n"); + LOGP(DGOLAY, LOGL_ERROR, "No mem!\n"); abort(); } @@ -281,27 +281,27 @@ static char encode_alpha(char c) switch (c) { case 0x0a: case 0x0d: - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> CR/LF character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> CR/LF character.\n"); c = 0x3c; break; case '{': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = 0x3b; break; case '}': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = 0x3d; break; case '\\': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = 0x20; break; default: if (c < 0x20 || c > 0x5d) { - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> ' ' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> ' ' character.\n"); c = 0x20; } else { - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = c - 0x20; } } @@ -314,93 +314,93 @@ static char encode_numeric(char c) switch (c) { case 'u': case 'U': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'U' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'U' character.\n"); c = 0xb; break; case ' ': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = 0xc; break; case '-': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = 0xd; break; case '=': case '*': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '*' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> '*' character.\n"); c = 0xe; break; case 'a': case 'A': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'A' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'A' character.\n"); c = 0xf0; break; case 'b': case 'B': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'B' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'B' character.\n"); c = 0xf1; break; case 'c': case 'C': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'C' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'C' character.\n"); c = 0xf2; break; case 'd': case 'D': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'D' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'D' character.\n"); c = 0xf3; break; case 'e': case 'E': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'E' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'E' character.\n"); c = 0xf4; break; case 'f': case 'F': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'F' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'F' character.\n"); c = 0xf6; break; case 'g': case 'G': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'G' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'G' character.\n"); c = 0xf7; break; case 'h': case 'H': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'H' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'H' character.\n"); c = 0xf8; break; case 'j': case 'J': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'J' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'J' character.\n"); c = 0xf9; break; case 'l': case 'L': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'L' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'L' character.\n"); c = 0xfb; break; case 'n': case 'N': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'N' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'N' character.\n"); c = 0xfc; break; case 'p': case 'P': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'P' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'P' character.\n"); c = 0xfd; break; case 'r': case 'R': - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> 'r' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> 'r' character.\n"); c = 0xfe; break; default: if (c >= '0' && c <= '9') { - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> '%c' character.\n", c); + LOGP(DGOLAY, LOGL_DEBUG, " -> '%c' character.\n", c); c = c - '0'; } else { - PDEBUG(DGOLAY, DEBUG_DEBUG, " -> ' ' character.\n"); + LOGP(DGOLAY, LOGL_DEBUG, " -> ' ' character.\n"); c = 0xc; } } @@ -419,7 +419,7 @@ static int encode_address(const char *code, int *preamble, uint16_t *word1, uint break; } if (code[i]) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Invalid functional address character. Only 0..9 are allowed.\n"); + LOGP(DGOLAY, LOGL_NOTICE, "Invalid functional address character. Only 0..9 are allowed.\n"); return -EINVAL; } @@ -457,7 +457,7 @@ static int encode_address(const char *code, int *preamble, uint16_t *word1, uint break; } if (i < 16) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Functional address has invlid value '%03d' for last three characters.\n", a2a1a0); + LOGP(DGOLAY, LOGL_NOTICE, "Functional address has invlid value '%03d' for last three characters.\n", a2a1a0); return -EINVAL; } } else { @@ -466,7 +466,7 @@ static int encode_address(const char *code, int *preamble, uint16_t *word1, uint break; } if (i < 7) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Functional address has invlid value '%03d' for last three characters.\n", a2a1a0); + LOGP(DGOLAY, LOGL_NOTICE, "Functional address has invlid value '%03d' for last three characters.\n", a2a1a0); return -EINVAL; } } @@ -528,7 +528,7 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, /* check address length */ if (!address || strlen(address) != 7) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Invalid functional address '%s' size. Only 7 digits are allowed.\n", address); + LOGP(DGOLAY, LOGL_NOTICE, "Invalid functional address '%s' size. Only 7 digits are allowed.\n", address); return -EINVAL; } @@ -550,24 +550,24 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, case '9': function = 0; break; case '0': function = 1; break; default: - PDEBUG(DGOLAY, DEBUG_NOTICE, "Illegal function suffix '%c' in last address digit.\n", address[6]); + LOGP(DGOLAY, LOGL_NOTICE, "Illegal function suffix '%c' in last address digit.\n", address[6]); return -EINVAL; } switch (type) { case TYPE_ALPHA: case TYPE_NUMERIC: - PDEBUG(DGOLAY, DEBUG_INFO, "Coding text message for functional address '%s' and message '%s'.\n", address, message); + LOGP(DGOLAY, LOGL_INFO, "Coding text message for functional address '%s' and message '%s'.\n", address, message); break; case TYPE_VOICE: - PDEBUG(DGOLAY, DEBUG_INFO, "Coding voice message for functional address %s with wave file '%s'.\n", address, message); + LOGP(DGOLAY, LOGL_INFO, "Coding voice message for functional address %s with wave file '%s'.\n", address, message); break; default: - PDEBUG(DGOLAY, DEBUG_INFO, "Coding tone only message for functional address %s.\n", address); + LOGP(DGOLAY, LOGL_INFO, "Coding tone only message for functional address %s.\n", address); } /* encode preamble and store */ - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding preamble '%d'.\n", preamble); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding preamble '%d'.\n", preamble); golay = calc_golay(preamble_values[preamble]); queue_comma(gsc, 28, golay & 1); for (i = 0; i < 18; i++) { @@ -575,7 +575,7 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, } /* encode start code and store */ - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding start code.\n"); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding start code.\n"); golay = calc_golay(start_code); queue_comma(gsc, 28, golay & 1); queue_dup(gsc, golay, 23); @@ -584,7 +584,7 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, queue_dup(gsc, golay, 23); /* encode address and store */ - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding address words '%d' and '%d'.\n", word1, word2); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding address words '%d' and '%d'.\n", word1, word2); golay = calc_golay(word1); if (function & 0x2) golay ^= 0x7fffff; @@ -599,10 +599,10 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, /* encode message */ switch (type) { case TYPE_ALPHA: - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding %d alphanumeric digits.\n", (int)strlen(message)); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding %d alphanumeric digits.\n", (int)strlen(message)); for (i = 0; *message; i++) { if (i == MAX_ADB) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Message overflows %d characters, cropping message.\n", MAX_ADB * 8); + LOGP(DGOLAY, LOGL_NOTICE, "Message overflows %d characters, cropping message.\n", MAX_ADB * 8); } for (j = 0; *message && j < 8; j++) { msg[j] = encode_alpha(*message++); @@ -635,11 +635,11 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, } break; case TYPE_NUMERIC: - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding %d numeric digits.\n", (int)strlen(message)); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding %d numeric digits.\n", (int)strlen(message)); shifted = 0; for (i = 0; *message; i++) { if (i == MAX_NDB) { - PDEBUG(DGOLAY, DEBUG_NOTICE, "Message overflows %d characters, cropping message.\n", MAX_NDB * 12); + LOGP(DGOLAY, LOGL_NOTICE, "Message overflows %d characters, cropping message.\n", MAX_NDB * 12); } for (j = 0; *message && j < 12; j++) { /* get next digit or shifted digit */ @@ -690,7 +690,7 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, /* store bit number for activation code. this is used to play the AC again after voice message. */ gsc->bit_ac = gsc->bit_num; /* encode activation code and store */ - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding activation code.\n"); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding activation code.\n"); golay = calc_golay(activation_code); queue_comma(gsc, 28, golay & 1); queue_dup(gsc, golay, 23); @@ -700,13 +700,13 @@ static int queue_batch(gsc_t *gsc, const char *address, enum gsc_msg_type type, break; default: /* encode comma after message and store */ - PDEBUG(DGOLAY, DEBUG_DEBUG, "Encoding 'comma' sequence after message.\n"); + LOGP(DGOLAY, LOGL_DEBUG, "Encoding 'comma' sequence after message.\n"); queue_comma(gsc, 121 * 8, 1); } /* check overflow */ if (gsc->bit_overflow) { - PDEBUG(DGOLAY, DEBUG_ERROR, "Bit stream (%d bits) overflows bit buffer size (%d bits), please fix!\n", gsc->bit_num, (int)sizeof(gsc->bit)); + LOGP(DGOLAY, LOGL_ERROR, "Bit stream (%d bits) overflows bit buffer size (%d bits), please fix!\n", gsc->bit_num, (int)sizeof(gsc->bit)); return -EOVERFLOW; } @@ -741,7 +741,7 @@ int8_t get_bit(gsc_t *gsc) return 2; } queue_reset(gsc); - PDEBUG(DGOLAY, DEBUG_INFO, "Done transmitting message.\n"); + LOGP(DGOLAY, LOGL_INFO, "Done transmitting message.\n"); goto next_msg; } return gsc->bit[gsc->bit_index++]; @@ -757,7 +757,7 @@ next_msg: /* encode first message in queue */ rc = queue_batch(gsc, msg->address, msg->type, msg->data); if (rc >= 0) - PDEBUG(DGOLAY, DEBUG_INFO, "Transmitting message to address '%s'.\n", msg->address); + LOGP(DGOLAY, LOGL_INFO, "Transmitting message to address '%s'.\n", msg->address); golay_msg_destroy(gsc, msg); if (rc < 0) goto next_msg; @@ -823,9 +823,9 @@ int call_down_setup(int __attribute__((unused)) callref, const char *caller_id, } if (!sender) { if (channel) - PDEBUG(DGOLAY, DEBUG_NOTICE, "Cannot page, because given station not available, rejecting!\n"); + LOGP(DGOLAY, LOGL_NOTICE, "Cannot page, because given station not available, rejecting!\n"); else - PDEBUG(DGOLAY, DEBUG_NOTICE, "Cannot page, no trasmitting station available, rejecting!\n"); + LOGP(DGOLAY, LOGL_NOTICE, "Cannot page, no trasmitting station available, rejecting!\n"); return -CAUSE_NOCHANNEL; } @@ -852,7 +852,7 @@ void call_down_answer(int __attribute__((unused)) callref) static void _release(int __attribute__((unused)) callref, int __attribute__((unused)) cause) { - PDEBUG(DGOLAY, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DGOLAY, LOGL_INFO, "Call has been disconnected by network.\n"); } void call_down_disconnect(int callref, int cause) diff --git a/src/golay/main.c b/src/golay/main.c index 4b595c2..1f16797 100644 --- a/src/golay/main.c +++ b/src/golay/main.c @@ -27,7 +27,7 @@ #include <sys/stat.h> #include <fcntl.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../liboptions/options.h" @@ -172,7 +172,7 @@ static void myhandler(void) if (tx) golay_msg_send(buffer); else - PDEBUG(DGOLAY, DEBUG_ERROR, "Failed to send message, transmitter is not enabled!\n"); + LOGP(DGOLAY, LOGL_ERROR, "Failed to send message, transmitter is not enabled!\n"); } } } @@ -294,6 +294,7 @@ fail: golay_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/imts/Makefile.am b/src/imts/Makefile.am index 9cfc677..fb617e6 100644 --- a/src/imts/Makefile.am +++ b/src/imts/Makefile.am @@ -13,22 +13,20 @@ imts_LDADD = \ $(COMMON_LA) \ ../amps/libusatone.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm imts_dialer_SOURCES = \ @@ -37,9 +35,10 @@ imts_dialer_SOURCES = \ imts_dialer_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ -lm if HAVE_ALSA diff --git a/src/imts/dialer.c b/src/imts/dialer.c index f7f2edb..b00b4b9 100644 --- a/src/imts/dialer.c +++ b/src/imts/dialer.c @@ -26,7 +26,7 @@ #include <errno.h> #include "../libsample/sample.h" #include "../libwave/wave.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #ifdef HAVE_ALSA #include "../libsound/sound.h" #endif @@ -186,7 +186,7 @@ static void process_signal(int buffer_size) count = dsp_samplerate / 1000; #endif if (count < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); + LOGP(DDSP, LOGL_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); break; } @@ -201,7 +201,7 @@ static void process_signal(int buffer_size) /* write audio */ rc = sound_write(audio, samples, power, count, NULL, NULL, 1); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); + LOGP(DDSP, LOGL_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); break; } #endif @@ -309,7 +309,7 @@ int main(int argc, char *argv[]) /* init sound */ audio = sound_open(dsp_audiodev, NULL, NULL, NULL, 1, 0.0, dsp_samplerate, dsp_buffer, 1.0, 1.0, 4000.0, 2.0); if (!audio) { - PDEBUG(DBNETZ, DEBUG_ERROR, "No sound device!\n"); + LOGP(DBNETZ, LOGL_ERROR, "No sound device!\n"); goto exit; } #endif @@ -318,13 +318,13 @@ int main(int argc, char *argv[]) if (write_tx_wave) { rc = wave_create_record(&wave_tx_rec, write_tx_wave, dsp_samplerate, 1, 1.0); if (rc < 0) { - PDEBUG(DBNETZ, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DBNETZ, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); goto exit; } } #ifndef HAVE_ALSA else { - PDEBUG(DBNETZ, DEBUG_ERROR, "No sound support compiled in, so you need to write to a wave file. See help!\n"); + LOGP(DBNETZ, LOGL_ERROR, "No sound support compiled in, so you need to write to a wave file. See help!\n"); goto exit; } #endif @@ -334,7 +334,7 @@ int main(int argc, char *argv[]) sound_start(audio); #endif - PDEBUG(DBNETZ, DEBUG_ERROR, "Start audio after pause...\n"); + LOGP(DBNETZ, LOGL_ERROR, "Start audio after pause...\n"); process_signal(buffer_size); diff --git a/src/imts/dsp.c b/src/imts/dsp.c index 9e08da2..5435fe5 100644 --- a/src/imts/dsp.c +++ b/src/imts/dsp.c @@ -26,8 +26,8 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "imts.h" #include "dsp.h" @@ -111,7 +111,7 @@ void dsp_init(void) int i; double s; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine tables.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine tables.\n"); for (i = 0; i < 65536; i++) { s = sin((double)i / 65536.0 * 2.0 * PI); dsp_sine_tone[i] = s * TX_PEAK_TONE; @@ -123,7 +123,7 @@ int dsp_init_transceiver(imts_t *imts, double squelch_db, int ptt) { int rc = -1; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for Transceiver.\n"); imts->sample_duration = 1.0 / (double)imts->sender.samplerate; @@ -164,11 +164,11 @@ int dsp_init_transceiver(imts_t *imts, double squelch_db, int ptt) /* delay buffer */ if (ptt) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Push to talk: Adding delay buffer to remove noise when signal gets lost.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Push to talk: Adding delay buffer to remove noise when signal gets lost.\n"); imts->delay_max = (int)((double)imts->sender.samplerate * DELAY_TIME); imts->delay_spl = calloc(imts->delay_max, sizeof(*imts->delay_spl)); if (!imts->delay_spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No mem for delay buffer!\n"); + LOGP(DDSP, LOGL_ERROR, "No mem for delay buffer!\n"); goto error; } } @@ -186,7 +186,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_transceiver(imts_t *imts) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for Transceiver.\n"); fm_demod_exit(&imts->demod); if (imts->delay_spl) { @@ -221,7 +221,7 @@ static int generate_tone(imts_t *imts, sample_t *samples, int length) case TONE_SILENCE: break; default: - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "Software error, unsupported tone, please fix!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "Software error, unsupported tone, please fix!\n"); return length; } @@ -386,7 +386,7 @@ static void tone_demod(imts_t *imts, sample_t *samples, int length) printf("decoder debug: %s detected, waiting to sustain\n", tone_names[tone]); #endif if (imts->demod_sig_tone) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Lost %s (duration %.0f ms)\n", tone_names[imts->demod_current_tone], imts->demod_duration * 1000.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Lost %s (duration %.0f ms)\n", tone_names[imts->demod_current_tone], imts->demod_duration * 1000.0); imts_lost_tone(imts, imts->demod_current_tone, imts->demod_duration); imts->demod_sig_tone = 0; } @@ -406,7 +406,7 @@ static void tone_demod(imts_t *imts, sample_t *samples, int length) amp = amplitude[i]; imts->demod_sig_tone = 0; } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Detected %s (level %.0f%%)\n", tone_names[imts->demod_current_tone], amp * 100); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Detected %s (level %.0f%%)\n", tone_names[imts->demod_current_tone], amp * 100); imts_receive_tone(imts, imts->demod_current_tone, imts->demod_duration, amp); imts->demod_last_tone = imts->demod_current_tone; imts->demod_duration = imts->demod_sustain; @@ -419,7 +419,7 @@ static void tone_demod(imts_t *imts, sample_t *samples, int length) double quality = 1.0 - imts->demod_quality_value / (double)imts->demod_quality_count * 2.0; if (quality < 0) quality = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Quality: %.0f%%\n", quality * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Quality: %.0f%%\n", quality * 100.0); display_measurements_update(imts->dmp_tone_quality, quality * 100.0, 0.0); } } @@ -465,7 +465,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double rf_l /* FALLTHRU */ case SQUELCH_MUTE: if (imts->mode == MODE_MTS && !imts->is_mute) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Low RF level, muting.\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Low RF level, muting.\n"); memset(imts->delay_spl, 0, sizeof(*samples) * imts->delay_max); imts->is_mute = 1; } @@ -475,7 +475,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double rf_l break; default: if (imts->is_mute) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "High RF level, unmuting.\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "High RF level, unmuting.\n"); imts->is_mute = 0; } /* detect signal, if it is steady for a while */ @@ -550,15 +550,15 @@ void imts_set_dsp_mode(imts_t *imts, enum dsp_mode mode, int tone, double durati } if (imts->dsp_mode != mode) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", imts_dsp_mode_name(imts->dsp_mode), imts_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", imts_dsp_mode_name(imts->dsp_mode), imts_dsp_mode_name(mode)); imts->dsp_mode = mode; } if (mode == DSP_MODE_TONE) { if (duration) - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Start sending %s for %.3f seconds.\n", tone_names[tone], duration); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Start sending %s for %.3f seconds.\n", tone_names[tone], duration); else - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Start sending %s continuously.\n", tone_names[tone]); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Start sending %s continuously.\n", tone_names[tone]); imts->tone = tone; imts->tone_duration = duration * (double)imts->sender.samplerate; } diff --git a/src/imts/imts.c b/src/imts/imts.c index 90b4820..c96447c 100644 --- a/src/imts/imts.c +++ b/src/imts/imts.c @@ -39,11 +39,12 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include "../libmobile/get_time.h" +#include <osmocom/cc/message.h> #include "imts.h" #include "dsp.h" @@ -127,37 +128,37 @@ void imts_list_channels(void) } /* Timers */ -#define PAGING_TO 4.0 /* Time to wait for the phone to respond */ -#define RINGING_TO 45.0 /* Time to wait for the mobile user to answer */ -#define SEIZE_TO 1.0 /* Time to wait for the phone to seize (Connect tone) */ -#define ANI_TO 1.000 /* Time to wait for first / next digit */ -#define DIALTONE_TO 10.0 /* Time to wait until dialing must be performed */ -#define DIALING_TO 3.0 /* Time to wait until number is recognized as complete */ -#define RELEASE_TO 0.350 /* Time to turn off transmitter before going idle ".. for about 300 ms .." */ -#define ANI_PULSE_TO 0.100 /* Time to detect end of digit */ -#define DIAL_PULSE_TO 0.200 /* Time to detect end of digit */ -#define DISC_PULSE_TO 0.100 /* Time until aborting disconnect detection */ -#define PAGE_PULSE_TO 0.200 /* Time to detect end of digit */ +#define PAGING_TO 4,0 /* Time to wait for the phone to respond */ +#define RINGING_TO 45,0 /* Time to wait for the mobile user to answer */ +#define SEIZE_TO 1,0 /* Time to wait for the phone to seize (Connect tone) */ +#define ANI_TO 1,0 /* Time to wait for first / next digit */ +#define DIALTONE_TO 10,0 /* Time to wait until dialing must be performed */ +#define DIALING_TO 3,0 /* Time to wait until number is recognized as complete */ +#define RELEASE_TO 0,350000 /* Time to turn off transmitter before going idle ".. for about 300 ms .." */ +#define ANI_PULSE_TO 0,100000 /* Time to detect end of digit */ +#define DIAL_PULSE_TO 0,200000 /* Time to detect end of digit */ +#define DISC_PULSE_TO 0.1 /* Time until aborting disconnect detection */ +#define PAGE_PULSE_TO 0.2 /* Time to detect end of digit */ /* Counters */ -#define DISC_COUNT 2 /* Number of pulses to detect disconnect (100 ms) */ -#define RING_PULSES 40 /* 2 seconds ringer on */ +#define DISC_COUNT 2 /* Number of pulses to detect disconnect (100 ms) */ +#define RING_PULSES 40 /* 2 seconds ringer on */ /* Durations */ -#define IDLE_DETECT 0.500 /* Time to detect Idle signal (loopback) */ -#define PAGE_SEIZE 0.400 /* Time to seize channel until start paging pulses FIXME */ -#define PAGE_PAUSE 0.225 /* Time to pause after each digit */ -#define PAGE_MARK 0.050 /* Mark duration of page pulse */ -#define PAGE_SPACE 0.050 /* Space duration of page pulse */ -#define PAGE_PULSE 0.100 /* Duration of a complete pulse (MTS) */ -#define RING_MARK 0.025 /* Mark duration of ring pulse */ -#define RING_SPACE 0.025 /* Space duration of ring pulse */ -#define RING_OFF 4.0 /* 4 seconds ringer off */ -#define GUARD_TIME 0.200 /* Time until detecting Guard tone from mobile */ -#define SEIZE_TIME 0.300 /* Time until sending Seize tone >= 250 */ -#define SEIZE_LENGTH 0.250 /* Length of Seize */ -#define RECEIVE_TIME 0.200 /* Time until detecting receive signal (Guard tone) from mobile */ -#define ANSWER_TIME 0.200 /* Time until detecting answer signal (Connect tone) from mobile */ +#define IDLE_DETECT 0,500000 /* Time to detect Idle signal (loopback) */ +#define PAGE_SEIZE 0.400 /* Time to seize channel until start paging pulses FIXME */ +#define PAGE_PAUSE 0.225 /* Time to pause after each digit */ +#define PAGE_MARK 0.050 /* Mark duration of page pulse */ +#define PAGE_SPACE 0.050 /* Space duration of page pulse */ +#define PAGE_PULSE 0.100 /* Duration of a complete pulse (MTS) */ +#define RING_MARK 0.025 /* Mark duration of ring pulse */ +#define RING_SPACE 0.025 /* Space duration of ring pulse */ +#define RING_OFF 4.0 /* 4 seconds ringer off */ +#define GUARD_TIME 0.200 /* Time until detecting Guard tone from mobile */ +#define SEIZE_TIME 0,300000 /* Time until sending Seize tone >= 250 */ +#define SEIZE_LENGTH 0.250 /* Length of Seize */ +#define RECEIVE_TIME 0.200 /* Time until detecting receive signal (Guard tone) from mobile */ +#define ANSWER_TIME 0.200 /* Time until detecting answer signal (Connect tone) from mobile */ const char *imts_state_name(enum imts_state state) { @@ -213,7 +214,7 @@ static void imts_new_state(imts_t *imts, enum imts_state new_state) { if (imts->state == new_state) return; - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "State change: %s -> %s\n", imts_state_name(imts->state), imts_state_name(new_state)); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "State change: %s -> %s\n", imts_state_name(imts->state), imts_state_name(new_state)); imts->state = new_state; imts_display_status(); } @@ -295,34 +296,34 @@ int imts_create(const char *kanal, const char *device, int use_sdr, int samplera int rc; if (imts_channel2freq(kanal, 0) == 0.0) { - PDEBUG(DIMTS, DEBUG_ERROR, "Channel number %s invalid.\n", kanal); + LOGP(DIMTS, LOGL_ERROR, "Channel number %s invalid.\n", kanal); return -EINVAL; } if (imts_is_canada_only(kanal)) { - PDEBUG(DIMTS, DEBUG_NOTICE, "*******************************************************************************\n"); - PDEBUG(DIMTS, DEBUG_NOTICE, "Given channel '%s' was only available in Canada with Canadian phones.\n", kanal); - PDEBUG(DIMTS, DEBUG_NOTICE, "*******************************************************************************\n"); + LOGP(DIMTS, LOGL_NOTICE, "*******************************************************************************\n"); + LOGP(DIMTS, LOGL_NOTICE, "Given channel '%s' was only available in Canada with Canadian phones.\n", kanal); + LOGP(DIMTS, LOGL_NOTICE, "*******************************************************************************\n"); } if (mode == MODE_IMTS && imts_channel2band(kanal) == VHF_LOW) { - PDEBUG(DIMTS, DEBUG_NOTICE, "*******************************************************************************\n"); - PDEBUG(DIMTS, DEBUG_NOTICE, "Given channel '%s' was only available at MTS network.\n", kanal); - PDEBUG(DIMTS, DEBUG_NOTICE, "*******************************************************************************\n"); + LOGP(DIMTS, LOGL_NOTICE, "*******************************************************************************\n"); + LOGP(DIMTS, LOGL_NOTICE, "Given channel '%s' was only available at MTS network.\n", kanal); + LOGP(DIMTS, LOGL_NOTICE, "*******************************************************************************\n"); return -EINVAL; } if (mode == MODE_MTS && imts_channel2band(kanal) == UHF) { - PDEBUG(DIMTS, DEBUG_NOTICE, "*******************************************************************************\n"); - PDEBUG(DIMTS, DEBUG_NOTICE, "Given channel '%s' was only available at IMTS network.\n", kanal); - PDEBUG(DIMTS, DEBUG_NOTICE, "*******************************************************************************\n"); + LOGP(DIMTS, LOGL_NOTICE, "*******************************************************************************\n"); + LOGP(DIMTS, LOGL_NOTICE, "Given channel '%s' was only available at IMTS network.\n", kanal); + LOGP(DIMTS, LOGL_NOTICE, "*******************************************************************************\n"); return -EINVAL; } imts = calloc(1, sizeof(imts_t)); if (!imts) { - PDEBUG(DIMTS, DEBUG_ERROR, "No memory!\n"); + LOGP(DIMTS, LOGL_ERROR, "No memory!\n"); return -EIO; } - PDEBUG(DIMTS, DEBUG_DEBUG, "Creating 'IMTS' instance for channel = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DIMTS, LOGL_DEBUG, "Creating 'IMTS' instance for channel = %s (sample rate %d).\n", kanal, samplerate); imts->fast_seize = fast_seize; imts->mode = mode; @@ -333,18 +334,18 @@ int imts_create(const char *kanal, const char *device, int use_sdr, int samplera /* do not enable emphasis, since it is done by imts code, not by common sender code */ rc = sender_create(&imts->sender, kanal, imts_channel2freq(kanal, 0), imts_channel2freq(kanal, 1), device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DIMTS, DEBUG_ERROR, "Failed to init 'Sender' processing!\n"); + LOGP(DIMTS, LOGL_ERROR, "Failed to init 'Sender' processing!\n"); goto error; } /* init audio processing */ rc = dsp_init_transceiver(imts, squelch_db, ptt); if (rc < 0) { - PDEBUG(DIMTS, DEBUG_ERROR, "Failed to init signal processing!\n"); + LOGP(DIMTS, LOGL_ERROR, "Failed to init signal processing!\n"); goto error; } - timer_init(&imts->timer, imts_timeout, imts); + osmo_timer_setup(&imts->timer, imts_timeout, imts); imts->pre_emphasis = pre_emphasis; imts->de_emphasis = de_emphasis; @@ -363,7 +364,7 @@ int imts_create(const char *kanal, const char *device, int use_sdr, int samplera imts_go_idle(imts); } - PDEBUG(DIMTS, DEBUG_NOTICE, "Created channel #%s\n", kanal); + LOGP(DIMTS, LOGL_NOTICE, "Created channel #%s\n", kanal); return 0; @@ -378,9 +379,9 @@ void imts_destroy(sender_t *sender) { imts_t *imts = (imts_t *) sender; - PDEBUG(DIMTS, DEBUG_DEBUG, "Destroying 'IMTS' instance for channel = %s.\n", sender->kanal); + LOGP(DIMTS, LOGL_DEBUG, "Destroying 'IMTS' instance for channel = %s.\n", sender->kanal); - timer_exit(&imts->timer); + osmo_timer_del(&imts->timer); dsp_cleanup_transceiver(imts); sender_destroy(&imts->sender); free(sender); @@ -392,7 +393,7 @@ static void imts_go_idle(imts_t *imts) sender_t *sender; imts_t *idle; - timer_stop(&imts->timer); + osmo_timer_del(&imts->timer); imts->station_id[0] = '\0'; /* remove station ID before state change, so status is shown correctly */ for (sender = sender_head; sender; sender = sender->next) { @@ -403,17 +404,17 @@ static void imts_go_idle(imts_t *imts) break; } if (sender) { - PDEBUG(DIMTS, DEBUG_INFO, "Entering IDLE state on channel %s, turning transmitter off.\n", imts->sender.kanal); + LOGP(DIMTS, LOGL_INFO, "Entering IDLE state on channel %s, turning transmitter off.\n", imts->sender.kanal); imts_new_state(imts, IMTS_OFF); imts_set_dsp_mode(imts, DSP_MODE_OFF, 0, 0.0, 0); } else { if (imts->mode == MODE_IMTS) { - PDEBUG(DIMTS, DEBUG_INFO, "Entering IDLE state on channel %s, sending 2000 Hz tone.\n", imts->sender.kanal); + LOGP(DIMTS, LOGL_INFO, "Entering IDLE state on channel %s, sending 2000 Hz tone.\n", imts->sender.kanal); imts_new_state(imts, IMTS_IDLE); /* also reset detector, so if there is a new call it is answered */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, 0.0, 1); } else { - PDEBUG(DIMTS, DEBUG_INFO, "Entering IDLE state on channel %s, sending 600 Hz tone.\n", imts->sender.kanal); + LOGP(DIMTS, LOGL_INFO, "Entering IDLE state on channel %s, sending 600 Hz tone.\n", imts->sender.kanal); imts_new_state(imts, IMTS_IDLE); /* also reset detector, so if there is a new call it is answered */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_600, 0.0, 1); @@ -435,13 +436,13 @@ static void imts_activate_idle(void) if (sender) imts_go_idle(idle); else - PDEBUG(DIMTS, DEBUG_INFO, "All channels are busy now, cannot activate any other channel.\n"); + LOGP(DIMTS, LOGL_INFO, "All channels are busy now, cannot activate any other channel.\n"); } /* Release connection towards mobile station by sending pause for a while. */ static void imts_release(imts_t *imts) { - timer_stop(&imts->timer); + osmo_timer_del(&imts->timer); /* remove station ID before state change, so status is shown correctly */ imts->station_id[0] = '\0'; @@ -455,22 +456,22 @@ static void imts_release(imts_t *imts) tone = TONE_600; else tone = TONE_1500; - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Sending pulse to stop ringing of the phone.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Sending pulse to stop ringing of the phone.\n"); imts_new_state(imts, IMTS_RELEASE); imts_set_dsp_mode(imts, DSP_MODE_TONE, tone, PAGE_PAUSE, 0); } else { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Turing transmitter off.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Turing transmitter off.\n"); if (imts->state != IMTS_RELEASE) imts_new_state(imts, IMTS_RELEASE); imts_set_dsp_mode(imts, DSP_MODE_OFF, 0, 0.0, 0); - timer_start(&imts->timer, RELEASE_TO); + osmo_timer_schedule(&imts->timer, RELEASE_TO); } } /* Enter detector test state */ static void imts_detector_test(imts_t *imts, double length_1, double length_2, double length_3) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Entering detector test state, sending test sequence.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Entering detector test state, sending test sequence.\n"); imts->detector_test_length_1 = length_1; imts->detector_test_length_2 = length_2; imts->detector_test_length_3 = length_3; @@ -483,12 +484,12 @@ static void imts_detector_test(imts_t *imts, double length_1, double length_2, d static void imts_paging(imts_t *imts, const char *dial_string, int loopback) { /* stop timer, since it may be running while measuring Guard tone at IDLE state */ - timer_stop(&imts->timer); + osmo_timer_del(&imts->timer); if (loopback) - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Entering paging test state, sending digits %s.\n", dial_string); + LOGP_CHAN(DIMTS, LOGL_INFO, "Entering paging test state, sending digits %s.\n", dial_string); else - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Entering paging state, sending phone's ID '%s'.\n", dial_string); + LOGP_CHAN(DIMTS, LOGL_INFO, "Entering paging state, sending phone's ID '%s'.\n", dial_string); /* set station ID before state change, so status is shown correctly */ strncpy(imts->station_id, dial_string, sizeof(imts->station_id) - 1); imts->tx_page_index = 0; @@ -509,18 +510,18 @@ static void imts_paging(imts_t *imts, const char *dial_string, int loopback) /* Enter ringing state */ static void imts_ringing(imts_t *imts) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received response from mobile phone, ringing.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received response from mobile phone, ringing.\n"); imts->tx_ring_pulse = 0; imts_new_state(imts, IMTS_RINGING); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, RING_MARK, 0); - timer_start(&imts->timer, RINGING_TO); + osmo_timer_schedule(&imts->timer, RINGING_TO); } /* Enter conversation state */ static void imts_answer(imts_t *imts) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received answer from mobile phone, conversation started.\n"); - timer_stop(&imts->timer); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received answer from mobile phone, conversation started.\n"); + osmo_timer_del(&imts->timer); imts_new_state(imts, IMTS_CONVERSATION); imts_set_dsp_mode(imts, DSP_MODE_AUDIO, 0, 0.0, 0); imts->rx_disc_pulse = 0; @@ -531,10 +532,10 @@ void imts_loss_indication(imts_t *imts, double loss_time) { /* stop timer */ if (imts->mode == MODE_MTS && (imts->state == IMTS_IDLE || imts->state == IMTS_RINGING)) - timer_stop(&imts->timer); + osmo_timer_del(&imts->timer); if (!imts->ptt && imts->state == IMTS_CONVERSATION) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Detected loss of signal after %.1f seconds, releasing.\n", loss_time); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Detected loss of signal after %.1f seconds, releasing.\n", loss_time); imts_release(imts); call_up_release(imts->callref, CAUSE_TEMPFAIL); imts->callref = 0; @@ -546,7 +547,7 @@ void imts_signal_indication(imts_t *imts) { /* setup a call from mobile to base station */ if (imts->mode == MODE_MTS && imts->state == IMTS_IDLE) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Detects RF signal in IDLE mode, calling the opterator at '%s'.\n", imts->operator); + LOGP_CHAN(DIMTS, LOGL_INFO, "Detects RF signal in IDLE mode, calling the opterator at '%s'.\n", imts->operator); imts->callref = call_up_setup(NULL, imts->operator, OSMO_CC_NETWORK_MTS_NONE, ""); imts_new_state(imts, IMTS_CONVERSATION); imts_set_dsp_mode(imts, DSP_MODE_AUDIO, 0, 0.0, 0); @@ -554,7 +555,7 @@ void imts_signal_indication(imts_t *imts) /* answer a call from base station to mobile */ if (imts->mode == MODE_MTS && imts->state == IMTS_RINGING) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Detected RF signal, mobile is now transmitting.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Detected RF signal, mobile is now transmitting.\n"); call_up_answer(imts->callref, imts->station_id); imts_answer(imts); } @@ -564,26 +565,26 @@ void imts_signal_indication(imts_t *imts) static void imts_receive_seize(imts_t *imts, int tone) { /* other tone stops IDLE / GUARD timer */ - timer_stop(&imts->timer); + osmo_timer_del(&imts->timer); switch (tone) { case TONE_IDLE: case TONE_600: - timer_start(&imts->timer, IDLE_DETECT); + osmo_timer_schedule(&imts->timer, IDLE_DETECT); break; case TONE_GUARD: imts->rx_guard_timestamp = get_time(); if (imts->fast_seize) - timer_start(&imts->timer, imts->fast_seize); + osmo_timer_schedule(&imts->timer, 0,imts->fast_seize * 1000000); break; case TONE_CONNECT: if (imts->last_tone == TONE_GUARD && imts->rx_guard_duration >= GUARD_TIME) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received seize (Guard + Connect tone) from mobile phone.\n"); - PDEBUG_CHAN(DIMTS, DEBUG_INFO, " -> Guard tone duration: %.0f ms (level %.0f%%)\n", (get_time() - imts->rx_guard_timestamp) * 1000.0, imts->last_sigtone_amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received seize (Guard + Connect tone) from mobile phone.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, " -> Guard tone duration: %.0f ms (level %.0f%%)\n", (get_time() - imts->rx_guard_timestamp) * 1000.0, imts->last_sigtone_amplitude * 100.0); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SILENCE, 0.0, 0); imts_new_state(imts, IMTS_SEIZE); imts_activate_idle(); /* must activate another channel right after station is not idle anymore */ - timer_start(&imts->timer, SEIZE_TIME); + osmo_timer_schedule(&imts->timer, SEIZE_TIME); } break; default: @@ -604,34 +605,34 @@ static void imts_receive_ani(imts_t *imts, int tone) imts->rx_ani_pulse++; imts->rx_ani_totpulses++; if (imts->rx_ani_pulse > 10) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received too many pulses, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received too many pulses, releasing!\n"); imts_release(imts); break; } - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Detected ANI pulse #%d.\n", imts->rx_ani_pulse); - timer_start(&imts->timer, ANI_PULSE_TO); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Detected ANI pulse #%d.\n", imts->rx_ani_pulse); + osmo_timer_schedule(&imts->timer, ANI_PULSE_TO); break; case TONE_GUARD: /* even pulse completed */ if ((imts->rx_ani_totpulses & 1)) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Parity error: Received Guard tone after %d (odd) pulses, releasing!\n", imts->rx_ani_totpulses); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Parity error: Received Guard tone after %d (odd) pulses, releasing!\n", imts->rx_ani_totpulses); imts_release(imts); break; } - timer_start(&imts->timer, ANI_PULSE_TO); + osmo_timer_schedule(&imts->timer, ANI_PULSE_TO); break; case TONE_SILENCE: /* odd pulse completed */ if (!(imts->rx_ani_totpulses & 1)) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Parity error: Received silence after %d (even) pulses, releasing!\n", imts->rx_ani_totpulses); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Parity error: Received silence after %d (even) pulses, releasing!\n", imts->rx_ani_totpulses); imts_release(imts); break; } - timer_start(&imts->timer, ANI_PULSE_TO); + osmo_timer_schedule(&imts->timer, ANI_PULSE_TO); break; default: /* received noise */ - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received noise while dialing, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received noise while dialing, releasing!\n"); imts_release(imts); } } @@ -647,23 +648,23 @@ static void imts_receive_dialing(imts_t *imts, int tone) /* pulse detected */ imts->rx_dial_pulse++; if (imts->rx_dial_pulse > 10) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received too many pulses, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received too many pulses, releasing!\n"); imts_release(imts); break; } - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Detected dialing pulse #%d.\n", imts->rx_dial_pulse); - timer_start(&imts->timer, DIAL_PULSE_TO); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Detected dialing pulse #%d.\n", imts->rx_dial_pulse); + osmo_timer_schedule(&imts->timer, DIAL_PULSE_TO); break; case TONE_GUARD: /* pulse completed */ if (imts->rx_dial_pulse) - timer_start(&imts->timer, DIAL_PULSE_TO); + osmo_timer_schedule(&imts->timer, DIAL_PULSE_TO); break; default: ; #if 0 /* received noise */ - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received noise while dialing, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received noise while dialing, releasing!\n"); imts_release(imts); #endif } @@ -675,7 +676,7 @@ static void imts_receive_disconnect(imts_t *imts, int tone, double elapsed, doub /* reset disc counter on timeout */ if (elapsed > DISC_PULSE_TO) { if (imts->rx_disc_pulse) { - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Timeout Disconnect sequence\n"); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Timeout Disconnect sequence\n"); imts->rx_disc_pulse = 0; } return; @@ -684,11 +685,11 @@ static void imts_receive_disconnect(imts_t *imts, int tone, double elapsed, doub switch (tone) { case TONE_DISCONNECT: imts->rx_disc_pulse++; - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Detected Disconnect pulse #%d.\n", imts->rx_disc_pulse); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Detected Disconnect pulse #%d.\n", imts->rx_disc_pulse); break; case TONE_GUARD: if (imts->rx_disc_pulse == DISC_COUNT) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received disconnect sequence from mobile phone (level %.0f%%).\n", amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received disconnect sequence from mobile phone (level %.0f%%).\n", amplitude * 100.0); if (imts->state == IMTS_SEIZE || imts->state == IMTS_ANI || imts->state == IMTS_DIALING @@ -704,7 +705,7 @@ static void imts_receive_disconnect(imts_t *imts, int tone, double elapsed, doub break; default: if (imts->rx_disc_pulse) { - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Disconnect sequence not detected anymore\n"); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Disconnect sequence not detected anymore\n"); imts->rx_disc_pulse = 0; } } @@ -717,15 +718,15 @@ static void receive_page_imts(imts_t *imts, int tone) case TONE_IDLE: /* pulse detected */ imts->rx_page_pulse++; - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Detected page test pulse #%d.\n", imts->rx_page_pulse); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Detected page test pulse #%d.\n", imts->rx_page_pulse); if (imts->rx_page_pulse > 10) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received too many pulses!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received too many pulses!\n"); } - timer_start(&imts->timer, PAGE_PULSE_TO); // use for page test timeout + osmo_timer_schedule(&imts->timer, 0,PAGE_PULSE_TO * 1000000); // use for page test timeout break; case TONE_SEIZE: /* pulse completed */ - timer_start(&imts->timer, PAGE_PULSE_TO); // use for page test timeout + osmo_timer_schedule(&imts->timer, 0,PAGE_PULSE_TO * 1000000); // use for page test timeout break; default: ; @@ -738,11 +739,11 @@ static void receive_page_mts(imts_t *imts, int tone) if (tone == TONE_600 || tone == TONE_1500) { /* pulse detected */ imts->rx_page_pulse++; - PDEBUG_CHAN(DIMTS, DEBUG_DEBUG, "Detected page test pulse #%d.\n", imts->rx_page_pulse); + LOGP_CHAN(DIMTS, LOGL_DEBUG, "Detected page test pulse #%d.\n", imts->rx_page_pulse); if (imts->rx_page_pulse > 10) { - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received too many pulses!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received too many pulses!\n"); } - timer_start(&imts->timer, PAGE_PULSE_TO); // use for page test timeout + osmo_timer_schedule(&imts->timer, 0,PAGE_PULSE_TO * 1000000); // use for page test timeout } } @@ -784,12 +785,12 @@ void imts_lost_tone(imts_t *imts, int tone, double elapsed) { switch (imts->state) { case IMTS_IDLE: - timer_stop(&imts->timer); + osmo_timer_del(&imts->timer); imts->rx_guard_duration = elapsed; break; case IMTS_PAGING: - if (elapsed >= 0.300 && tone == TONE_GUARD && timer_running(&imts->timer)) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received acknowledge (Guard tone) from mobile phone (level %.0f%%).\n", imts->last_sigtone_amplitude * 100.0); + if (elapsed >= 0.300 && tone == TONE_GUARD && osmo_timer_pending(&imts->timer)) { + LOGP_CHAN(DIMTS, LOGL_INFO, "Received acknowledge (Guard tone) from mobile phone (level %.0f%%).\n", imts->last_sigtone_amplitude * 100.0); call_up_alerting(imts->callref); imts_ringing(imts); break; @@ -797,7 +798,7 @@ void imts_lost_tone(imts_t *imts, int tone, double elapsed) break; case IMTS_RINGING: if (elapsed >= 0.190 && tone == TONE_CONNECT) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received answer (Connect tone) from mobile phone (level %.0f%%).\n", imts->last_sigtone_amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received answer (Connect tone) from mobile phone (level %.0f%%).\n", imts->last_sigtone_amplitude * 100.0); call_up_answer(imts->callref, imts->station_id); imts_answer(imts); break; @@ -818,30 +819,30 @@ static void ani_after_digit(imts_t *imts) imts->rx_ani_pulse = 0; imts->station_id[imts->rx_ani_index] = imts->rx_ani_pulse + '0'; imts->rx_ani_pulse = 0; - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received ANI digit '%c' from mobile phone (level %.0f%%).\n", imts->station_id[imts->rx_ani_index], imts->last_sigtone_amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received ANI digit '%c' from mobile phone (level %.0f%%).\n", imts->station_id[imts->rx_ani_index], imts->last_sigtone_amplitude * 100.0); imts->station_id[++imts->rx_ani_index] = '\0'; /* update status while receiving station ID */ imts_display_status(); /* if all digits have been received */ if (imts->rx_ani_index == 7) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "ANI '%s' complete, sending dial tone.\n", imts->station_id); + LOGP_CHAN(DIMTS, LOGL_INFO, "ANI '%s' complete, sending dial tone.\n", imts->station_id); dt: imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_DIALTONE, 0.0, 0); - timer_start(&imts->timer, DIALTONE_TO); + osmo_timer_schedule(&imts->timer, DIALTONE_TO); imts->dial_number[0] = '\0'; imts->rx_dial_index = 0; imts->rx_dial_pulse = 0; imts_new_state(imts, IMTS_DIALING); return; } - timer_start(&imts->timer, ANI_TO); + osmo_timer_schedule(&imts->timer, ANI_TO); } else { /* if only 5 digits have been received */ if (imts->rx_ani_index == 5) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "ANI '%s' (5 digits) complete, sending dial tone.\n", imts->station_id); + LOGP_CHAN(DIMTS, LOGL_INFO, "ANI '%s' (5 digits) complete, sending dial tone.\n", imts->station_id); goto dt; } - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Timeout receiving ANI from mobile phone, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Timeout receiving ANI from mobile phone, releasing!\n"); imts_release(imts); } } @@ -850,7 +851,7 @@ static void dial_after_digit(imts_t *imts) { /* special case where nothing happens after dial tone */ if (!imts->rx_dial_pulse && !imts->rx_dial_index) { - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Mobile phone does not start dialing, releasing!\n"); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Mobile phone does not start dialing, releasing!\n"); imts_release(imts); return; } @@ -860,7 +861,7 @@ static void dial_after_digit(imts_t *imts) */ if (imts->rx_dial_pulse) { if (imts->rx_dial_index == sizeof(imts->dial_number) - 1) { - PDEBUG_CHAN(DANETZ, DEBUG_NOTICE, "Mobile phone dials too many digits, releasing!\n"); + LOGP_CHAN(DANETZ, LOGL_NOTICE, "Mobile phone dials too many digits, releasing!\n"); imts_release(imts); return; } @@ -868,11 +869,11 @@ static void dial_after_digit(imts_t *imts) imts->rx_dial_pulse = 0; imts->dial_number[imts->rx_dial_index] = imts->rx_dial_pulse + '0'; imts->rx_dial_pulse = 0; - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received dial digit '%c' from mobile phone. (level %.0f%%)\n", imts->dial_number[imts->rx_dial_index], imts->last_sigtone_amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received dial digit '%c' from mobile phone. (level %.0f%%)\n", imts->dial_number[imts->rx_dial_index], imts->last_sigtone_amplitude * 100.0); imts->dial_number[++imts->rx_dial_index] = '\0'; - timer_start(&imts->timer, DIALING_TO); + osmo_timer_schedule(&imts->timer, DIALING_TO); } else { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Timeout receiving dialing from mobile phone, number complete.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Timeout receiving dialing from mobile phone, number complete.\n"); imts->callref = call_up_setup(imts->station_id, imts->dial_number, OSMO_CC_NETWORK_IMTS_NONE, ""); imts_new_state(imts, IMTS_CONVERSATION); imts_set_dsp_mode(imts, DSP_MODE_AUDIO, 0, 0.0, 0); @@ -892,7 +893,7 @@ static void page_after_digit(imts_t *imts) imts->rx_page_pulse = 0; digit = imts->rx_page_pulse + '0'; delay = get_time() - imts->tx_page_timestamp - PAGE_PULSE_TO; - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Received paging test digit '%c' (level %.0f%% delay %.0f ms).\n", digit, imts->last_sigtone_amplitude * 100.0, delay * 1000.0); + LOGP_CHAN(DIMTS, LOGL_INFO, "Received paging test digit '%c' (level %.0f%% delay %.0f ms).\n", digit, imts->last_sigtone_amplitude * 100.0, delay * 1000.0); } imts->rx_page_pulse = 0; } @@ -907,29 +908,29 @@ static void imts_timeout(void *data) case IMTS_IDLE: switch (imts->last_tone) { case TONE_IDLE: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received idle tone (level of %.0f%%), loopback?\n", imts->last_sigtone_amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received idle tone (level of %.0f%%), loopback?\n", imts->last_sigtone_amplitude * 100.0); /* trigger reset of decoder to force detection again and again */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, 0.0, 1); break; case TONE_600: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received 600 Hz tone with level of %.0f%%, loopback?\n", imts->last_sigtone_amplitude * 100.0); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received 600 Hz tone with level of %.0f%%, loopback?\n", imts->last_sigtone_amplitude * 100.0); /* trigger reset of decoder to force detection again and again */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_600, 0.0, 1); break; case TONE_GUARD: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Received Guard tone, turning off IDLE tone\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Received Guard tone, turning off IDLE tone\n"); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SILENCE, 0.5, 0); break; } break; case IMTS_PAGING: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "No response from mobile phone.\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "No response from mobile phone.\n"); imts_go_idle(imts); call_up_release(imts->callref, CAUSE_OUTOFORDER); imts->callref = 0; break; case IMTS_RINGING: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "No answer from mobile phone's user, releasing.\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "No answer from mobile phone's user, releasing.\n"); imts_release(imts); call_up_release(imts->callref, CAUSE_NOANSWER); imts->callref = 0; @@ -938,9 +939,9 @@ static void imts_timeout(void *data) imts_go_idle(imts); break; case IMTS_SEIZE: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending Seize to mobile phone.\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending Seize to mobile phone.\n"); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SEIZE, SEIZE_LENGTH, 0); - timer_start(&imts->timer, SEIZE_LENGTH + ANI_TO); + osmo_timer_schedule(&imts->timer, SEIZE_LENGTH + ANI_TO); imts->station_id[0] = '\0'; imts->rx_ani_index = 0; imts->rx_ani_pulse = 0; @@ -973,7 +974,7 @@ static void paging_pulses_imts(imts_t *imts, int tone) if (tone == TONE_SEIZE) { if (imts->tx_page_pulse == 0) - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Sending paging digit '%c' as pulses.\n", imts->station_id[imts->tx_page_index]); + LOGP_CHAN(DIMTS, LOGL_INFO, "Sending paging digit '%c' as pulses.\n", imts->station_id[imts->tx_page_index]); /* send mark (pulse start) */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, PAGE_MARK, 0); imts->tx_page_pulse++; @@ -993,7 +994,7 @@ static void paging_pulses_imts(imts_t *imts, int tone) duration = PAGE_PAUSE; else { duration = 0; - timer_start(&imts->timer, PAGING_TO); + osmo_timer_schedule(&imts->timer, PAGING_TO); } } imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SEIZE, duration, 0); @@ -1015,7 +1016,7 @@ static void paging_pulses_mts(imts_t *imts, int tone) tone = TONE_1500; if (imts->tx_page_pulse == 0) { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Sending paging digit '%c' as pulses.\n", imts->station_id[imts->tx_page_index]); + LOGP_CHAN(DIMTS, LOGL_INFO, "Sending paging digit '%c' as pulses.\n", imts->station_id[imts->tx_page_index]); } imts->tx_page_pulse++; if (imts->tx_page_pulse < pulses) @@ -1030,7 +1031,7 @@ static void paging_pulses_mts(imts_t *imts, int tone) if (imts->station_id[imts->tx_page_index]) duration = PAGE_PAUSE; else { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Digits complete, assuming the phone is ringing.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Digits complete, assuming the phone is ringing.\n"); duration = 0; imts_new_state(imts, IMTS_RINGING); call_up_alerting(imts->callref); @@ -1044,7 +1045,7 @@ static void ringing_pulses(imts_t *imts, int tone) { if (tone == TONE_IDLE) { if (imts->tx_ring_pulse == 0) - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Sending ringing signal as pulses.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Sending ringing signal as pulses.\n"); /* send space (pulse end) */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SEIZE, RING_SPACE, 0); imts->tx_ring_pulse++; @@ -1053,7 +1054,7 @@ static void ringing_pulses(imts_t *imts, int tone) /* send mark (pulse start) */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, RING_MARK, 0); } else { - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Sending pause after ringing.\n"); + LOGP_CHAN(DIMTS, LOGL_INFO, "Sending pause after ringing.\n"); /* send long space after last pulse */ imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SEIZE, RING_OFF, 0); imts->tx_ring_pulse = 0; @@ -1077,21 +1078,21 @@ static void detector_test_imts(imts_t *imts, int tone) tone_idle: if (imts->detector_test_length_1 <= 0) goto tone_seize; - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending %.3fs IDLE tone.\n", imts->detector_test_length_1); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending %.3fs IDLE tone.\n", imts->detector_test_length_1); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, imts->detector_test_length_1, 0); break; case TONE_IDLE: tone_seize: if (imts->detector_test_length_2 <= 0) goto tone_silence; - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending %.3fs SEIZE tone.\n", imts->detector_test_length_2); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending %.3fs SEIZE tone.\n", imts->detector_test_length_2); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SEIZE, imts->detector_test_length_2, 0); break; case TONE_SEIZE: tone_silence: if (imts->detector_test_length_3 <= 0) goto tone_idle; - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending %.3fs SILENCE.\n", imts->detector_test_length_3); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending %.3fs SILENCE.\n", imts->detector_test_length_3); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SILENCE, imts->detector_test_length_3, 0); break; } @@ -1103,21 +1104,21 @@ static void detector_test_mts(imts_t *imts, int tone) tone_idle: if (imts->detector_test_length_1 <= 0) goto tone_seize; - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending %.3fs 600 Hz tone.\n", imts->detector_test_length_1); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending %.3fs 600 Hz tone.\n", imts->detector_test_length_1); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_600, imts->detector_test_length_1, 0); break; case TONE_600: tone_seize: if (imts->detector_test_length_2 <= 0) goto tone_silence; - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending %.3fs 1500 Hz tone.\n", imts->detector_test_length_2); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending %.3fs 1500 Hz tone.\n", imts->detector_test_length_2); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_1500, imts->detector_test_length_2, 0); break; case TONE_1500: tone_silence: if (imts->detector_test_length_3 <= 0) goto tone_idle; - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Sending %.3fs SILENCE.\n", imts->detector_test_length_3); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Sending %.3fs SILENCE.\n", imts->detector_test_length_3); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_SILENCE, imts->detector_test_length_3, 0); break; } @@ -1128,7 +1129,7 @@ void imts_tone_sent(imts_t *imts, int tone) { switch (imts->state) { case IMTS_IDLE: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "No Seize tone after Guard tone, turning on IDLE tone\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "No Seize tone after Guard tone, turning on IDLE tone\n"); imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_IDLE, 0.0, 0); break; case IMTS_ANI: @@ -1172,7 +1173,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (sender) { - PDEBUG(DIMTS, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DIMTS, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } @@ -1183,7 +1184,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (!sender) { - PDEBUG(DIMTS, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DIMTS, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } @@ -1195,7 +1196,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, } /* 4. trying to page mobile station */ - PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Call to mobile station, paging number: %s\n", dialing); + LOGP_CHAN(DIMTS, LOGL_INFO, "Call to mobile station, paging number: %s\n", dialing); imts->callref = callref; imts_paging(imts, dialing, 0); @@ -1215,7 +1216,7 @@ void call_down_disconnect(int callref, int cause) sender_t *sender; imts_t *imts; - PDEBUG(DIMTS, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DIMTS, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { imts = (imts_t *) sender; @@ -1223,7 +1224,7 @@ void call_down_disconnect(int callref, int cause) break; } if (!sender) { - PDEBUG(DIMTS, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DIMTS, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1234,7 +1235,7 @@ void call_down_disconnect(int callref, int cause) switch (imts->state) { case IMTS_PAGING: case IMTS_RINGING: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Outgoing disconnect, during paging/alerting, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Outgoing disconnect, during paging/alerting, releasing!\n"); imts_release(imts); break; default: @@ -1253,7 +1254,7 @@ void call_down_release(int callref, __attribute__((unused)) int cause) sender_t *sender; imts_t *imts; - PDEBUG(DIMTS, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DIMTS, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { imts = (imts_t *) sender; @@ -1261,7 +1262,7 @@ void call_down_release(int callref, __attribute__((unused)) int cause) break; } if (!sender) { - PDEBUG(DIMTS, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DIMTS, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -1270,12 +1271,12 @@ void call_down_release(int callref, __attribute__((unused)) int cause) switch (imts->state) { case IMTS_CONVERSATION: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Outgoing release, during call, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Outgoing release, during call, releasing!\n"); imts_release(imts); break; case IMTS_PAGING: case IMTS_RINGING: - PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Outgoing release, during paging/alerting, releasing!\n"); + LOGP_CHAN(DIMTS, LOGL_NOTICE, "Outgoing release, during paging/alerting, releasing!\n"); imts_release(imts); break; default: diff --git a/src/imts/imts.h b/src/imts/imts.h index d754c90..b0d261a 100644 --- a/src/imts/imts.h +++ b/src/imts/imts.h @@ -61,7 +61,7 @@ typedef struct imts { int callref; /* call reference */ char station_id[11]; /* current station ID (also used for test pattern) */ char dial_number[33]; /* number dialing */ - struct timer timer; + struct osmo_timer_list timer; int last_tone; /* last tone received */ double last_sigtone_amplitude; /* amplitude of last signaling tone received */ double fast_seize; /* fast seize: guard-length - roundtrip-delay */ diff --git a/src/imts/main.c b/src/imts/main.c index dace347..5dd3365 100644 --- a/src/imts/main.c +++ b/src/imts/main.c @@ -25,8 +25,8 @@ #include <math.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "../liboptions/options.h" #include "../amps/tones.h" @@ -279,6 +279,7 @@ fail: imts_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/jolly/Makefile.am b/src/jolly/Makefile.am index f78fb49..2595394 100644 --- a/src/jolly/Makefile.am +++ b/src/jolly/Makefile.am @@ -12,23 +12,21 @@ jollycom_LDADD = \ $(COMMON_LA) \ ../anetz/libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ $(top_builddir)/src/libdtmf/libdtmf.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ $(top_builddir)/src/libfm/libfm.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/jolly/dsp.c b/src/jolly/dsp.c index 7bb3aee..90159da 100644 --- a/src/jolly/dsp.c +++ b/src/jolly/dsp.c @@ -27,8 +27,8 @@ #include <math.h> #include "../libsample/sample.h" -#include "../libtimer/timer.h" -#include "../libdebug/debug.h" +#include <osmocom/core/timer.h> +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "jolly.h" #include "dsp.h" @@ -63,7 +63,7 @@ void dsp_init(void) int i; double s; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine tables.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine tables.\n"); for (i = 0; i < 65536; i++) { s = sin((double)i / 65536.0 * 2.0 * M_PI); dsp_info_tone[i] = s * TX_INFO_TONE; @@ -92,7 +92,7 @@ int dsp_init_sender(jolly_t *jolly, int nbfm, double squelch_db, int repeater) * also we allow a minimum of -30 dB for each tone. */ rc = dtmf_decode_init(&jolly->dtmf, jolly, jolly_receive_dtmf, 8000, db2level(6.0), db2level(-30.0)); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to init DTMF decoder!\n"); + LOGP(DDSP, LOGL_ERROR, "Failed to init DTMF decoder!\n"); goto error; } @@ -106,7 +106,7 @@ int dsp_init_sender(jolly_t *jolly, int nbfm, double squelch_db, int repeater) jolly->delay_max = (int)((double)jolly->sender.samplerate * DELAY_TIME); jolly->delay_spl = calloc(jolly->delay_max, sizeof(*jolly->delay_spl)); if (!jolly->delay_spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No mem for delay buffer!\n"); + LOGP(DDSP, LOGL_ERROR, "No mem for delay buffer!\n"); goto error; } @@ -115,7 +115,7 @@ int dsp_init_sender(jolly_t *jolly, int nbfm, double squelch_db, int repeater) jolly->repeater_max = (int)((double)jolly->sender.samplerate * REPEATER_TIME); rc = jitter_create(&jolly->repeater_dejitter, "repeater", jolly->sender.samplerate, sizeof(sample_t), 0.050, 0.500, JITTER_FLAG_NONE); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to create and init repeater buffer!\n"); + LOGP(DDSP, LOGL_ERROR, "Failed to create and init repeater buffer!\n"); goto error; } @@ -174,25 +174,25 @@ again: spl = jolly_voice.spl[10]; size = jolly_voice.size[10]; if (!jolly->speech_pos) - PDEBUG(DDSP, DEBUG_DEBUG, "speaking 'incoming'.\n"); + LOGP(DDSP, LOGL_DEBUG, "speaking 'incoming'.\n"); break; case 'o': spl = jolly_voice.spl[11]; size = jolly_voice.size[11]; if (!jolly->speech_pos) - PDEBUG(DDSP, DEBUG_DEBUG, "speaking 'outgoing'.\n"); + LOGP(DDSP, LOGL_DEBUG, "speaking 'outgoing'.\n"); break; case 'r': spl = jolly_voice.spl[12]; size = jolly_voice.size[12]; if (!jolly->speech_pos) - PDEBUG(DDSP, DEBUG_DEBUG, "speaking 'released'.\n"); + LOGP(DDSP, LOGL_DEBUG, "speaking 'released'.\n"); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': spl = jolly_voice.spl[jolly->speech_string[jolly->speech_digit] - '0']; size = jolly_voice.size[jolly->speech_string[jolly->speech_digit] - '0']; if (!jolly->speech_pos) - PDEBUG(DDSP, DEBUG_DEBUG, "speaking digit '%c'.\n", jolly->speech_string[jolly->speech_digit]); + LOGP(DDSP, LOGL_DEBUG, "speaking digit '%c'.\n", jolly->speech_string[jolly->speech_digit]); break; default: jolly->speech_digit++; @@ -292,7 +292,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double rf_l case SQUELCH_LOSS: case SQUELCH_MUTE: if (!jolly->is_mute) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "Low RF level, muting.\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "Low RF level, muting.\n"); jolly->ack_count = jolly->ack_max; jolly->repeater_count = jolly->repeater_max; } @@ -301,7 +301,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double rf_l break; default: if (jolly->is_mute) - PDEBUG_CHAN(DDSP, DEBUG_INFO, "High RF level, unmuting; turning transmitter on.\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "High RF level, unmuting; turning transmitter on.\n"); jolly->is_mute = 0; break; } @@ -355,7 +355,7 @@ void sender_send(sender_t *sender, sample_t *samples, uint8_t *power, int length if (jolly->repeater_count) { jolly->repeater_count -= length; if (jolly->repeater_count < 0) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "turning transmitter off.\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "turning transmitter off.\n"); jolly->repeater_count = 0; } } diff --git a/src/jolly/jolly.c b/src/jolly/jolly.c index daf59d9..48e47db 100644 --- a/src/jolly/jolly.c +++ b/src/jolly/jolly.c @@ -134,11 +134,11 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "jolly.h" #include "dsp.h" #include "voice.h" @@ -146,12 +146,12 @@ #define db2level(db) pow(10, (double)db / 20.0) /* Timers */ -#define T_DIAL 6 /* Time between digits */ -#define T_DIAL2 1.5 /* Time between digits during call*/ -#define T_PAGING 30 /* How long do we page the mobile party */ -#define SPEECH_DELAY_PAGING 1.0 /* time before speaking paging sequence */ -#define SPEECH_DELAY_VERIFY 2.0 /* time before speaking verifying sequence */ -#define SPEECH_DELAY_RELEASE 2.0/* time before speaking release sequence */ +#define T_DIAL 6,0 /* Time between digits */ +#define T_DIAL2 1,500000 /* Time between digits during call*/ +#define T_PAGING 30,0 /* How long do we page the mobile party */ +#define SPEECH_DELAY_PAGING 1,0 /* time before speaking paging sequence */ +#define SPEECH_DELAY_VERIFY 2,0 /* time before speaking verifying sequence */ +#define SPEECH_DELAY_RELEASE 2,0 /* time before speaking release sequence */ const char *jolly_state_name(enum jolly_state state) { @@ -199,7 +199,7 @@ static void jolly_new_state(jolly_t *jolly, enum jolly_state new_state) { if (jolly->state == new_state) return; - PDEBUG_CHAN(DJOLLY, DEBUG_DEBUG, "State change: %s -> %s\n", jolly_state_name(jolly->state), jolly_state_name(new_state)); + LOGP_CHAN(DJOLLY, LOGL_DEBUG, "State change: %s -> %s\n", jolly_state_name(jolly->state), jolly_state_name(new_state)); jolly->state = new_state; jolly_display_status(); } @@ -216,11 +216,11 @@ int jolly_create(const char *kanal, double dl_freq, double ul_freq, double step, jolly = calloc(1, sizeof(jolly_t)); if (!jolly) { - PDEBUG(DJOLLY, DEBUG_ERROR, "No memory!\n"); + LOGP(DJOLLY, LOGL_ERROR, "No memory!\n"); return -EIO; } - PDEBUG(DJOLLY, DEBUG_DEBUG, "Creating 'JollyCom' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DJOLLY, LOGL_DEBUG, "Creating 'JollyCom' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); dl_freq = dl_freq * 1e6 + step * 1e3 * (double)atoi(kanal); ul_freq = ul_freq * 1e6 + step * 1e3 * (double)atoi(kanal); @@ -228,25 +228,25 @@ int jolly_create(const char *kanal, double dl_freq, double ul_freq, double step, /* init general part of transceiver */ rc = sender_create(&jolly->sender, kanal, dl_freq, ul_freq, device, use_sdr, samplerate, rx_gain, tx_gain, pre_emphasis, de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DJOLLY, DEBUG_ERROR, "Failed to init 'Sender' processing!\n"); + LOGP(DJOLLY, LOGL_ERROR, "Failed to init 'Sender' processing!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(jolly, nbfm, squelch_db, repeater); if (rc < 0) { - PDEBUG(DANETZ, DEBUG_ERROR, "Failed to init signal processing!\n"); + LOGP(DANETZ, LOGL_ERROR, "Failed to init signal processing!\n"); goto error; } /* timers */ - timer_init(&jolly->timer, jolly_timeout, jolly); - timer_init(&jolly->speech_timer, jolly_speech_timeout, jolly); + osmo_timer_setup(&jolly->timer, jolly_timeout, jolly); + osmo_timer_setup(&jolly->speech_timer, jolly_speech_timeout, jolly); /* go into idle state */ jolly_go_idle(jolly); - PDEBUG(DJOLLY, DEBUG_NOTICE, "Created 'Kanal' #%s\n", kanal); + LOGP(DJOLLY, LOGL_NOTICE, "Created 'Kanal' #%s\n", kanal); return 0; @@ -261,11 +261,11 @@ void jolly_destroy(sender_t *sender) { jolly_t *jolly = (jolly_t *) sender; - PDEBUG(DJOLLY, DEBUG_DEBUG, "Destroying 'JollyCom' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DJOLLY, LOGL_DEBUG, "Destroying 'JollyCom' instance for 'Kanal' = %s.\n", sender->kanal); dsp_cleanup_sender(jolly); - timer_exit(&jolly->timer); - timer_exit(&jolly->speech_timer); + osmo_timer_del(&jolly->timer); + osmo_timer_del(&jolly->speech_timer); sender_destroy(&jolly->sender); free(sender); } @@ -273,11 +273,11 @@ void jolly_destroy(sender_t *sender) /* Abort connection towards mobile station changing to IDLE state */ static void jolly_go_idle(jolly_t *jolly) { - timer_stop(&jolly->timer); - timer_stop(&jolly->speech_timer); + osmo_timer_del(&jolly->timer); + osmo_timer_del(&jolly->speech_timer); reset_speech_string(jolly); - PDEBUG(DJOLLY, DEBUG_INFO, "Entering IDLE state on channel %s.\n", jolly->sender.kanal); + LOGP(DJOLLY, LOGL_INFO, "Entering IDLE state on channel %s.\n", jolly->sender.kanal); jolly->dialing[0] = '\0'; jolly->station_id[0] = '\0'; /* remove station ID before state change, so status is shown correctly */ jolly_new_state(jolly, STATE_IDLE); @@ -286,35 +286,35 @@ static void jolly_go_idle(jolly_t *jolly) /* Release connection towards mobile station by sending idle tone for a while. */ static void jolly_release(jolly_t *jolly) { - timer_stop(&jolly->timer); - timer_stop(&jolly->speech_timer); + osmo_timer_del(&jolly->timer); + osmo_timer_del(&jolly->speech_timer); reset_speech_string(jolly); - PDEBUG(DJOLLY, DEBUG_INFO, "Sending Release sequence on channel %s.\n", jolly->sender.kanal); - timer_start(&jolly->speech_timer, SPEECH_DELAY_RELEASE); + LOGP(DJOLLY, LOGL_INFO, "Sending Release sequence on channel %s.\n", jolly->sender.kanal); + osmo_timer_schedule(&jolly->speech_timer, SPEECH_DELAY_RELEASE); jolly_new_state(jolly, STATE_RELEASED); } /* Enter paging state and transmit 4 paging tones. */ static void jolly_page(jolly_t *jolly, const char *dial_string) { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Entering paging state, sending paging sequence to '%s'.\n", dial_string); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Entering paging state, sending paging sequence to '%s'.\n", dial_string); /* set station ID before state change, so status is shown correctly */ strncpy(jolly->station_id, dial_string, sizeof(jolly->station_id) - 1); - timer_start(&jolly->timer, T_PAGING); - timer_start(&jolly->speech_timer, SPEECH_DELAY_PAGING); + osmo_timer_schedule(&jolly->timer, T_PAGING); + osmo_timer_schedule(&jolly->speech_timer, SPEECH_DELAY_PAGING); jolly_new_state(jolly, STATE_IN_PAGING); } void speech_finished(jolly_t *jolly) { - PDEBUG(DJOLLY, DEBUG_DEBUG, "speaking finished.\n"); + LOGP(DJOLLY, LOGL_DEBUG, "speaking finished.\n"); switch (jolly->state) { case STATE_OUT_VERIFY: - timer_start(&jolly->timer, T_DIAL); + osmo_timer_schedule(&jolly->timer, T_DIAL); break; case STATE_IN_PAGING: - timer_start(&jolly->speech_timer, SPEECH_DELAY_PAGING); + osmo_timer_schedule(&jolly->speech_timer, SPEECH_DELAY_PAGING); break; case STATE_RELEASED: jolly_go_idle(jolly); @@ -331,7 +331,7 @@ void jolly_receive_dtmf(void *priv, char digit, dtmf_meas_t *meas) { jolly_t *jolly = (jolly_t *) priv; - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received dtmf digit '%c' frequency %.1f %.1f amplitude %.1f %.1f dB.\n", + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received dtmf digit '%c' frequency %.1f %.1f amplitude %.1f %.1f dB.\n", digit, meas->frequency_low, meas->frequency_high, level2db(meas->amplitude_low), level2db(meas->amplitude_high)); @@ -343,68 +343,68 @@ void jolly_receive_dtmf(void *priv, char digit, dtmf_meas_t *meas) switch (jolly->state) { case STATE_IDLE: if (digit == '*') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received start digit, entering dialing state.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received start digit, entering dialing state.\n"); jolly->dialing[0] = '\0'; - timer_start(&jolly->timer, T_DIAL); + osmo_timer_schedule(&jolly->timer, T_DIAL); jolly_new_state(jolly, STATE_OUT_DIALING); break; } break; case STATE_OUT_DIALING: if (digit == '*') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received start digit again, resetting dialing state.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received start digit again, resetting dialing state.\n"); jolly->dialing[0] = '\0'; - timer_start(&jolly->timer, T_DIAL); + osmo_timer_schedule(&jolly->timer, T_DIAL); break; } if (digit >= '0' && digit <= '9' && strlen(jolly->dialing) < sizeof(jolly->dialing) - 1) { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received dialed digit '%c'\n", digit); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received dialed digit '%c'\n", digit); jolly->dialing[strlen(jolly->dialing) + 1] = '\0'; jolly->dialing[strlen(jolly->dialing)] = digit; - timer_start(&jolly->timer, T_DIAL); + osmo_timer_schedule(&jolly->timer, T_DIAL); break; } if (digit == '#') { - timer_stop(&jolly->timer); + osmo_timer_del(&jolly->timer); if (!jolly->dialing[0]) { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received stop digit but no dial string, entering idle state.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received stop digit but no dial string, entering idle state.\n"); jolly_go_idle(jolly); break; } - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received stop digit, entering verify state.\n"); - timer_start(&jolly->speech_timer, SPEECH_DELAY_VERIFY); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received stop digit, entering verify state.\n"); + osmo_timer_schedule(&jolly->speech_timer, SPEECH_DELAY_VERIFY); jolly_new_state(jolly, STATE_OUT_VERIFY); break; } break; case STATE_OUT_VERIFY: if (digit == '*') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received start digit, entering dialing state.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received start digit, entering dialing state.\n"); reset_speech_string(jolly); jolly->dialing[0] = '\0'; - timer_start(&jolly->timer, T_DIAL); + osmo_timer_schedule(&jolly->timer, T_DIAL); jolly_new_state(jolly, STATE_OUT_DIALING); break; } if (digit == '#') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received ack digit, entering call state.\n"); - timer_stop(&jolly->timer); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received ack digit, entering call state.\n"); + osmo_timer_del(&jolly->timer); jolly->callref = call_up_setup(NULL, jolly->dialing, OSMO_CC_NETWORK_JOLLYCOM_NONE, ""); jolly_new_state(jolly, STATE_CALL); } break; case STATE_CALL: if (digit == '*') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received start digit, entering call dialing state.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received start digit, entering call dialing state.\n"); jolly->dialing[0] = '\0'; - timer_start(&jolly->timer, T_DIAL2); + osmo_timer_schedule(&jolly->timer, T_DIAL2); jolly_new_state(jolly, STATE_CALL_DIALING); break; } break; case STATE_CALL_DIALING: if (digit == '#') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received stop digit, going idle.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received stop digit, going idle.\n"); call_up_release(jolly->callref, CAUSE_NORMAL); jolly->callref = 0; jolly_release(jolly); @@ -413,7 +413,7 @@ void jolly_receive_dtmf(void *priv, char digit, dtmf_meas_t *meas) break; case STATE_IN_PAGING: if (digit == '#') { - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Received answer digit, entering call state.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Received answer digit, entering call state.\n"); call_up_answer(jolly->callref, jolly->station_id); jolly_new_state(jolly, STATE_CALL); break; @@ -431,19 +431,19 @@ static void jolly_timeout(void *data) switch (jolly->state) { case STATE_OUT_DIALING: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Timeout while dialing, going idle.\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Timeout while dialing, going idle.\n"); jolly_go_idle(jolly); break; case STATE_OUT_VERIFY: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Timeout while verifying, going idle.\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Timeout while verifying, going idle.\n"); jolly_go_idle(jolly); break; case STATE_CALL_DIALING: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Timeout while dialing during call.\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Timeout while dialing during call.\n"); jolly_new_state(jolly, STATE_CALL); break; case STATE_IN_PAGING: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Timeout while paging, going idle.\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Timeout while paging, going idle.\n"); call_up_release(jolly->callref, CAUSE_NOANSWER); jolly->callref = 0; jolly_go_idle(jolly); @@ -459,15 +459,15 @@ static void jolly_speech_timeout(void *data) switch (jolly->state) { case STATE_OUT_VERIFY: - PDEBUG_CHAN(DJOLLY, DEBUG_DEBUG, "Start verifying speech.\n"); + LOGP_CHAN(DJOLLY, LOGL_DEBUG, "Start verifying speech.\n"); set_speech_string(jolly, 'o', jolly->dialing); break; case STATE_IN_PAGING: - PDEBUG_CHAN(DJOLLY, DEBUG_DEBUG, "Start paging speech.\n"); + LOGP_CHAN(DJOLLY, LOGL_DEBUG, "Start paging speech.\n"); set_speech_string(jolly, 'i', jolly->station_id); break; case STATE_RELEASED: - PDEBUG_CHAN(DJOLLY, DEBUG_DEBUG, "Start release speech.\n"); + LOGP_CHAN(DJOLLY, LOGL_DEBUG, "Start release speech.\n"); set_speech_string(jolly, 'r', ""); default: break; @@ -487,7 +487,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (sender) { - PDEBUG(DJOLLY, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DJOLLY, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } @@ -498,11 +498,11 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (!sender) { - PDEBUG(DJOLLY, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DJOLLY, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG_CHAN(DJOLLY, DEBUG_INFO, "Call to mobile station.\n"); + LOGP_CHAN(DJOLLY, LOGL_INFO, "Call to mobile station.\n"); /* 3. trying to page mobile station */ jolly->callref = callref; @@ -526,7 +526,7 @@ void call_down_disconnect(int callref, int cause) sender_t *sender; jolly_t *jolly; - PDEBUG(DJOLLY, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DJOLLY, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { jolly = (jolly_t *) sender; @@ -534,7 +534,7 @@ void call_down_disconnect(int callref, int cause) break; } if (!sender) { - PDEBUG(DJOLLY, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DJOLLY, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -544,7 +544,7 @@ void call_down_disconnect(int callref, int cause) return; switch (jolly->state) { case STATE_IN_PAGING: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Outgoing disconnect, during paging, releaseing.\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Outgoing disconnect, during paging, releaseing.\n"); jolly_go_idle(jolly); break; default: @@ -563,7 +563,7 @@ void call_down_release(int callref, __attribute__((unused)) int cause) sender_t *sender; jolly_t *jolly; - PDEBUG(DJOLLY, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DJOLLY, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { jolly = (jolly_t *) sender; @@ -571,7 +571,7 @@ void call_down_release(int callref, __attribute__((unused)) int cause) break; } if (!sender) { - PDEBUG(DJOLLY, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DJOLLY, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -581,11 +581,11 @@ void call_down_release(int callref, __attribute__((unused)) int cause) switch (jolly->state) { case STATE_CALL: case STATE_CALL_DIALING: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Outgoing release, during call, releasing\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Outgoing release, during call, releasing\n"); jolly_release(jolly); break; case STATE_IN_PAGING: - PDEBUG_CHAN(DJOLLY, DEBUG_NOTICE, "Outgoing release, during paging, releaseing.\n"); + LOGP_CHAN(DJOLLY, LOGL_NOTICE, "Outgoing release, during paging, releaseing.\n"); jolly_go_idle(jolly); break; default: diff --git a/src/jolly/jolly.h b/src/jolly/jolly.h index 226cb61..1b61371 100644 --- a/src/jolly/jolly.h +++ b/src/jolly/jolly.h @@ -21,7 +21,7 @@ typedef struct jolly { int callref; /* call reference */ char station_id[32]; /* current station ID */ char dialing[32]; /* dial string */ - struct timer timer; + struct osmo_timer_list timer; /* display measurements */ dispmeasparam_t *dmp_dtmf_low; @@ -41,7 +41,7 @@ typedef struct jolly { double ack_phase65536; /* current phase */ int ack_count; /* counter to count down while playing ack tone */ int ack_max; /* duration in samples */ - struct timer speech_timer; + struct osmo_timer_list speech_timer; char speech_string[40]; /* speech string */ int speech_digit; /* counts digits */ int speech_pos; /* counts samples */ diff --git a/src/jolly/main.c b/src/jolly/main.c index 254337b..3c009ab 100644 --- a/src/jolly/main.c +++ b/src/jolly/main.c @@ -29,8 +29,8 @@ #include <sys/stat.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../anetz/freiton.h" #include "../anetz/besetztton.h" #include "../liboptions/options.h" @@ -210,6 +210,7 @@ fail: jolly_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/libdebug/Makefile.am b/src/libdebug/Makefile.am deleted file mode 100644 index 210a097..0000000 --- a/src/libdebug/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) - -noinst_LIBRARIES = libdebug.a - -libdebug_a_SOURCES = \ - debug.c - diff --git a/src/libdebug/debug.c b/src/libdebug/debug.c deleted file mode 100755 index 22811e2..0000000 --- a/src/libdebug/debug.c +++ /dev/null @@ -1,331 +0,0 @@ -/* Simple debug functions for level and category filtering - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <stdint.h> -#include <errno.h> -#include <math.h> -#include <time.h> -#include <pthread.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include "debug.h" - -const char *debug_level[] = { - "debug ", - "info ", - "notice ", - "error ", - NULL, -}; - -struct debug_cat { - const char *name; - const char *color; -} debug_cat[] = { - { "options", "\033[0;33m" }, - { "sender", "\033[1;33m" }, - { "sound", "\033[0;35m" }, - { "dsp", "\033[0;31m" }, - { "anetz", "\033[1;34m" }, - { "bnetz", "\033[1;34m" }, - { "cnetz", "\033[1;34m" }, - { "nmt", "\033[1;34m" }, - { "amps", "\033[1;34m" }, - { "r2000", "\033[1;34m" }, - { "imts", "\033[1;34m" }, - { "mpt1327", "\033[1;34m" }, - { "jollycom", "\033[1;34m" }, - { "eurosignal", "\033[1;34m" }, - { "pocsag", "\033[1;34m" }, - { "golay", "\033[1;34m" }, - { "5-ton-folge", "\033[1;34m" }, - { "frame", "\033[0;36m" }, - { "call", "\033[0;37m" }, - { "cc", "\033[1;32m" }, - { "database", "\033[0;33m" }, - { "transaction", "\033[0;32m" }, - { "dms", "\033[0;33m" }, - { "sms", "\033[1;37m" }, - { "sdr", "\033[1;31m" }, - { "uhd", "\033[1;35m" }, - { "soapy", "\033[1;35m" }, - { "wave", "\033[1;33m" }, - { "radio", "\033[1;34m" }, - { "am791x", "\033[0;31m" }, - { "uart", "\033[0;32m" }, - { "device", "\033[0;33m" }, - { "datenklo", "\033[1;34m" }, - { "zeit", "\033[1;34m" }, - { "sim layer 1", "\033[0;31m" }, - { "sim layer 2", "\033[0;33m" }, - { "sim ICL layer", "\033[0;36m" }, - { "sim layer 7", "\033[0;37m" }, - { "mtp layer 2", "\033[1;33m" }, - { "mtp layer 3", "\033[1;36m" }, - { "MuP", "\033[1;37m" }, - { "router", "\033[1;35m" }, - { "stderr", "\033[1;37m" }, - { "ss5", "\033[1;34m" }, - { "r1", "\033[1;34m" }, - { "isdn", "\033[1;35m" }, - { "misdn", "\033[0;34m" }, - { "dss1", "\033[1;34m" }, - { "sip", "\033[1;35m" }, - { "telephone", "\033[1;34m" }, - { "uk0", "\033[1;34m" }, - { "ph", "\033[0;33m" }, - { "dcf77", "\033[1;34m" }, - { "jitter", "\033[0;36m" }, - { NULL, NULL } -}; - -int debuglevel = DEBUG_INFO; -int debug_date = 0; -uint64_t debug_mask[2] = { ~0, ~0 }; -extern int num_kanal; - -void (*clear_console_text)(void) = NULL; -void (*print_console_text)(void) = NULL; - -int debug_limit_scroll = 0; - -static int lock_initialized = 0; -static pthread_mutex_t debug_mutex; - -void lock_debug(void) -{ - int rc; - - if (!lock_initialized) { - rc = pthread_mutex_init(&debug_mutex, NULL); - if (rc == 0) - lock_initialized = 1; - } - if (lock_initialized) - pthread_mutex_lock(&debug_mutex); -} - -void unlock_debug(void) -{ - if (lock_initialized) - pthread_mutex_unlock(&debug_mutex); -} - -void get_win_size(int *w, int *h) -{ - struct winsize win; - int rc; - - rc = ioctl(0, TIOCGWINSZ, &win); - if (rc) { - *w = 80; - *h = 25; - return; - } - - *h = win.ws_row; - *w = win.ws_col; -} - -void _printdebug(const char *file, const char __attribute__((unused)) *function, int line, int cat, int level, const char *kanal, const char *fmt, ...) -{ - char buffer[4096], *b = buffer; - int s = sizeof(buffer) - 1; - const char *p; - va_list args; - int w, h = 0; // make GCC happy - - if (debuglevel > level) - return; - - if (!(debug_mask[cat >> 6] & ((uint64_t)1 << (cat & 63)))) - return; - - lock_debug(); - - buffer[sizeof(buffer) - 1] = '\0'; - - /* if kanal is used, prefix the channel number */ - if (num_kanal > 1 && kanal) { - sprintf(buffer, "(chan %s) ", kanal); - b = strchr(buffer, '\0'); - s -= strlen(buffer); - } - - va_start(args, fmt); - vsnprintf(b, s, fmt, args); - va_end(args); - - while ((p = strchr(file, '/'))) - file = p + 1; - if (clear_console_text) - clear_console_text(); - if (debug_limit_scroll) { - get_win_size(&w, &h); - printf("\0337\033[%d;%dr\0338", debug_limit_scroll + 1, h); - } - if (debug_date) { - struct timeval tv; - struct tm *tm; - - gettimeofday(&tv, NULL); - tm = localtime(&tv.tv_sec); - - printf("%04d-%02d-%02d %02d:%02d:%02d.%03d ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 10000.0)); - } - printf("%s%s %4d %s-%s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_cat[cat].name, debug_level[level], buffer); - if (debug_limit_scroll) - printf("\0337\033[%d;%dr\0338", 1, h); - if (print_console_text) - print_console_text(); - fflush(stdout); - - unlock_debug(); -} - -const char *debug_amplitude(double level) -{ - static char text[42]; - - strcpy(text, " : "); - if (level > 1.0) - level = 1.0; - if (level < -1.0) - level = -1.0; - text[20 + (int)(level * 20)] = '*'; - - return text; -} - -#define level2db(level) (20 * log10(level)) - -const char *debug_db(double level_db) -{ - static char text[128]; - int l; - - strcpy(text, ": . : . : . : . : . : . : . : . | . : . : . : . : . : . : . : . :"); - if (level_db <= 0.0) - return text; - l = (int)round(level2db(level_db)); - if (l > 48) - return text; - if (l < -48) - return text; - text[l + 48] = '*'; - - return text; -} - -void debug_print_help(void) -{ - printf(" -v --verbose <level> | <level>,<category>[,<category>[,...]] | list\n"); - printf(" Use 'list' to get a list of all levels and categories\n"); - printf(" Verbose level: digit of debug level (default = '%d')\n", debuglevel); - printf(" Verbose level+category: level digit followed by one or more categories\n"); - printf(" -> If no category is specified, all categories are selected\n"); - printf(" -v --verbose date\n"); - printf(" Show date with debug output\n"); -} - -void debug_list_cat(void) -{ - int i; - - printf("Give number of debug level:\n"); - for (i = 0; debug_level[i]; i++) - printf(" %d = %s\n", i, debug_level[i]); - printf("\n"); - - printf("Give name(s) of debug category:\n"); - for (i = 0; debug_cat[i].name; i++) - printf(" %s%s\033[0;39m\n", debug_cat[i].color, debug_cat[i].name); - printf("\n"); -} - -int parse_debug_opt(const char *optarg) -{ - int i, max_level = 0; - char *dup, *dstring, *p; - - if (!strcasecmp(optarg, "date")) { - debug_date = 1; - return 0; - } - - for (i = 0; debug_level[i]; i++) - max_level = i; - - dup = dstring = strdup(optarg); - p = strsep(&dstring, ","); - for (i = 0; i < p[i]; i++) { - if (p[i] < '0' || p[i] > '9') { - fprintf(stderr, "Only digits are allowed for debug level!\n"); - free(dup); - return -EINVAL; - } - } - debuglevel = atoi(p); - if (debuglevel > max_level) { - fprintf(stderr, "Debug level too high, use 'list' to show available levels!\n"); - free(dup); - return -EINVAL; - } - if (dstring) - memset(debug_mask, 0, sizeof(debug_mask)); - while((p = strsep(&dstring, ","))) { - for (i = 0; debug_cat[i].name; i++) { - if (!strcasecmp(p, debug_cat[i].name)) - break; - } - if (!debug_cat[i].name) { - fprintf(stderr, "Given debug category '%s' unknown, use 'list' to show available categories!\n", p); - free(dup); - return -EINVAL; - } - debug_mask[i >> 6] |= ((uint64_t)1 << (i & 63)); - } - - free(dup); - return 0; -} - -const char *debug_hex(const uint8_t *data, int len) -{ - static char *text = NULL; - char *p; - int i; - - if (text) - free(text); - p = text = calloc(1, len * 3 + 1); - for (i = 0; i < len; i++) { - sprintf(p, "%02x ", *data++); - p += 3; - } - if (text[0]) - p[-1] = '\0'; - - return text; -} - diff --git a/src/libdebug/debug.h b/src/libdebug/debug.h deleted file mode 100644 index 3554af5..0000000 --- a/src/libdebug/debug.h +++ /dev/null @@ -1,94 +0,0 @@ - -#define DEBUG_DEBUG 0 /* debug info, not for normal use */ -#define DEBUG_INFO 1 /* all info about process */ -#define DEBUG_NOTICE 2 /* something unexpected happens */ -#define DEBUG_ERROR 3 /* there is an error with this software */ - -#define DOPTIONS 0 -#define DSENDER 1 -#define DSOUND 2 -#define DDSP 3 -#define DANETZ 4 -#define DBNETZ 5 -#define DCNETZ 6 -#define DNMT 7 -#define DAMPS 8 -#define DR2000 9 -#define DIMTS 10 -#define DMPT1327 11 -#define DJOLLY 12 -#define DEURO 13 -#define DPOCSAG 14 -#define DGOLAY 15 -#define DFUENF 16 -#define DFRAME 17 -#define DCALL 18 -#define DCC 19 -#define DDB 20 -#define DTRANS 21 -#define DDMS 22 -#define DSMS 23 -#define DSDR 24 -#define DUHD 25 -#define DSOAPY 26 -#define DWAVE 27 -#define DRADIO 28 -#define DAM791X 29 -#define DUART 30 -#define DDEVICE 31 -#define DDATENKLO 32 -#define DZEIT 33 -#define DSIM1 34 -#define DSIM2 35 -#define DSIMI 36 -#define DSIM7 37 -#define DMTP2 38 -#define DMTP3 39 -#define DMUP 40 -#define DROUTER 41 -#define DSTDERR 42 -#define DSS5 43 -#define DR1 44 -#define DISDN 45 -#define DMISDN 46 -#define DDSS1 47 -#define DSIP 48 -#define DTEL 49 -#define DUK0 50 -#define DPH 51 -#define DDCF77 52 -#define DJITTER 53 -//NOTE: increment mask array, if 127 is exceeded - -void lock_debug(void); -void unlock_debug(void); - -void get_win_size(int *w, int *h); - -#define PDEBUG(cat, level, fmt, arg...) _printdebug(__FILE__, __FUNCTION__, __LINE__, cat, level, NULL, fmt, ## arg) -#define PDEBUG_CHAN(cat, level, fmt, arg...) _printdebug(__FILE__, __FUNCTION__, __LINE__, cat, level, CHAN, fmt, ## arg) -void _printdebug(const char *file, const char *function, int line, int cat, int level, const char *chan_str, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 7, 8))); - -const char *debug_amplitude(double level); -const char *debug_db(double level_db); - -void debug_print_help(void); -void debug_list_cat(void); -int parse_debug_opt(const char *opt); - -extern int debuglevel; - -extern void (*clear_console_text)(void); -extern void (*print_console_text)(void); - -extern int debug_limit_scroll; - -const char *debug_hex(const uint8_t *data, int len); - -#define LOGP PDEBUG -#define LOGL_DEBUG DEBUG_DEBUG -#define LOGL_INFO DEBUG_INFO -#define LOGL_NOTICE DEBUG_NOTICE -#define LOGL_ERROR DEBUG_ERROR -#define osmo_hexdump debug_hex - diff --git a/src/libdisplay/display_iq.c b/src/libdisplay/display_iq.c index 83cec6e..7e9e74c 100644 --- a/src/libdisplay/display_iq.c +++ b/src/libdisplay/display_iq.c @@ -24,7 +24,7 @@ #include <pthread.h> #include <stdlib.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libdisplay/display.h" /* must be odd value! */ @@ -60,14 +60,16 @@ void display_iq_on(int on) if (iq_on) { memset(&screen, ' ', sizeof(screen)); memset(&screen_history, 0, sizeof(screen_history)); - lock_debug(); + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (j = 0; j < SIZE; j++) { screen[j][w] = '\0'; puts(screen[j]); } printf("\0338"); fflush(stdout); - unlock_debug(); + enable_limit_scroll(true); + unlock_logging(); } if (on < 0) { @@ -77,9 +79,9 @@ void display_iq_on(int on) iq_on = on; if (iq_on) - debug_limit_scroll = SIZE; + logging_limit_scroll_top(SIZE); else - debug_limit_scroll = 0; + logging_limit_scroll_top(0); } /* @@ -116,8 +118,6 @@ void display_iq(float *samples, int length) if (!iq_on) return; - lock_debug(); - get_win_size(&width, &h); if (width > MAX_DISPLAY_WIDTH - 1) width = MAX_DISPLAY_WIDTH - 1; @@ -235,6 +235,8 @@ cont: else sprintf(screen[0], "(IQ log %.0f dB", db); *strchr(screen[0], '\0') = ')'; + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (j = 0; j < SIZE; j++) { for (k = 0; k < width; k++) { @@ -271,12 +273,12 @@ cont: } /* reset color and position */ printf("\033[0;39m\0338"); fflush(stdout); + enable_limit_scroll(true); + unlock_logging(); } } disp.interval_pos = pos; - - unlock_debug(); } diff --git a/src/libdisplay/display_measurements.c b/src/libdisplay/display_measurements.c index 543ca1c..84a88bc 100644 --- a/src/libdisplay/display_measurements.c +++ b/src/libdisplay/display_measurements.c @@ -26,7 +26,7 @@ #include <math.h> #include <sys/param.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libdisplay/display.h" #define MAX_NAME_LEN 16 @@ -111,10 +111,10 @@ static void print_measurements(int on) if (bar_width < 1) return; - lock_debug(); - lines_total = 0; color = -1; + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (disp = meas_head; disp; disp = disp->next) { memset(line, ' ', width); @@ -253,10 +253,10 @@ static void print_measurements(int on) } /* reset color and position */ printf("\033[0;39m\0338"); fflush(stdout); - - debug_limit_scroll = lines_total; - - unlock_debug(); + enable_limit_scroll(true); + unlock_logging(); + /* Set new limit. */ + logging_limit_scroll_top(lines_total); } void display_measurements_on(int on) @@ -269,7 +269,7 @@ void display_measurements_on(int on) else measurements_on = on; - debug_limit_scroll = 0; + logging_limit_scroll_top(0); } /* add new parameter on startup to the list of measurements */ diff --git a/src/libdisplay/display_spectrum.c b/src/libdisplay/display_spectrum.c index b0f30f4..efd3be9 100644 --- a/src/libdisplay/display_spectrum.c +++ b/src/libdisplay/display_spectrum.c @@ -24,7 +24,7 @@ #include <math.h> #include "../libsample/sample.h" #include "../libfft/fft.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libdisplay/display.h" #define HEIGHT 20 @@ -101,14 +101,16 @@ void display_spectrum_on(int on) if (spectrum_on) { memset(&screen, ' ', sizeof(screen)); memset(&buffer_hold, 0, sizeof(buffer_hold)); - lock_debug(); + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (j = 0; j < HEIGHT; j++) { screen[j][w] = '\0'; puts(screen[j]); } printf("\0338"); fflush(stdout); - unlock_debug(); + enable_limit_scroll(true); + unlock_logging(); } if (on < 0) { @@ -118,9 +120,9 @@ void display_spectrum_on(int on) spectrum_on = on; if (spectrum_on) - debug_limit_scroll = HEIGHT; + logging_limit_scroll_top(HEIGHT); else - debug_limit_scroll = 0; + logging_limit_scroll_top(0); } /* @@ -142,8 +144,6 @@ void display_spectrum(float *samples, int length) if (!spectrum_on) return; - lock_debug(); - get_win_size(&width, &h); if (width > MAX_DISPLAY_WIDTH - 1) width = MAX_DISPLAY_WIDTH - 1; @@ -390,6 +390,8 @@ void display_spectrum(float *samples, int length) screen_color[0][j-1] = 7; screen_color[0][j+1] = 7; /* display buffer */ + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (j = 0; j < HEIGHT; j++) { for (k = 0; k < width; k++) { @@ -403,12 +405,11 @@ void display_spectrum(float *samples, int length) } /* reset color and position */ printf("\033[0;39m\0338"); fflush(stdout); + enable_limit_scroll(true); + unlock_logging(); } } disp.interval_pos = pos; - - unlock_debug(); } - diff --git a/src/libdisplay/display_status.c b/src/libdisplay/display_status.c index de38c9e..400e3e9 100644 --- a/src/libdisplay/display_status.c +++ b/src/libdisplay/display_status.c @@ -23,7 +23,7 @@ #include <pthread.h> #include <sys/ioctl.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libdisplay/display.h" static int status_on = 0; @@ -46,7 +46,8 @@ static void print_status(int on) if (h > lines_total) h = lines_total; - lock_debug(); + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H\033[1;37m"); for (i = 0; i < h; i++) { j = 0; @@ -60,7 +61,8 @@ static void print_status(int on) putchar('\n'); } printf("\0338"); fflush(stdout); - unlock_debug(); + enable_limit_scroll(true); + unlock_logging(); } void display_status_on(int on) @@ -77,9 +79,9 @@ void display_status_on(int on) print_status(1); if (status_on) - debug_limit_scroll = lines_total; + logging_limit_scroll_top(lines_total); else - debug_limit_scroll = 0; + logging_limit_scroll_top(0); } /* start status display */ @@ -139,7 +141,7 @@ void display_status_end(void) /* set new total lines */ lines_total = line_count; if (status_on) - debug_limit_scroll = lines_total; + logging_limit_scroll_top(lines_total); } diff --git a/src/libdisplay/display_wave.c b/src/libdisplay/display_wave.c index 713873f..2d54bf7 100644 --- a/src/libdisplay/display_wave.c +++ b/src/libdisplay/display_wave.c @@ -24,7 +24,7 @@ #include <math.h> #include <sys/ioctl.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libdisplay/display.h" #define HEIGHT 11 @@ -52,7 +52,8 @@ void display_wave_on(int on) if (wave_on) { memset(&screen, ' ', sizeof(screen)); - lock_debug(); + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (i = 0; i < num_sender; i++) { for (j = 0; j < HEIGHT; j++) { @@ -61,7 +62,8 @@ void display_wave_on(int on) } } printf("\0338"); fflush(stdout); - unlock_debug(); + enable_limit_scroll(true); + unlock_logging(); } if (on < 0) @@ -70,9 +72,9 @@ void display_wave_on(int on) wave_on = on; if (wave_on) - debug_limit_scroll = HEIGHT * num_sender; + logging_limit_scroll_top(HEIGHT * num_sender); else - debug_limit_scroll = 0; + logging_limit_scroll_top(0); } /* @@ -104,8 +106,6 @@ void display_wave(dispwav_t *disp, sample_t *samples, int length, double range) if (!wave_on) return; - lock_debug(); - get_win_size(&width, &h); if (width > MAX_DISPLAY_WIDTH - 1) width = MAX_DISPLAY_WIDTH - 1; @@ -208,6 +208,8 @@ void display_wave(dispwav_t *disp, sample_t *samples, int length, double range) } sprintf(screen[0], "(chan %s", disp->kanal); *strchr(screen[0], '\0') = ')'; + lock_logging(); + enable_limit_scroll(false); printf("\0337\033[H"); for (j = 0; j < disp->offset; j++) puts(""); @@ -241,12 +243,12 @@ void display_wave(dispwav_t *disp, sample_t *samples, int length, double range) } /* reset color and position */ printf("\033[0;39m\0338"); fflush(stdout); + enable_limit_scroll(true); + unlock_logging(); } } disp->interval_pos = pos; - - unlock_debug(); } diff --git a/src/libdtmf/dtmf_decode.c b/src/libdtmf/dtmf_decode.c index 8270ae3..b1c30aa 100644 --- a/src/libdtmf/dtmf_decode.c +++ b/src/libdtmf/dtmf_decode.c @@ -22,10 +22,10 @@ #include <string.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "dtmf_decode.h" -//#define DEBUG +//#define DEBUG_DTMF #define level2db(level) (20 * log10(level)) #define db2level(db) pow(10, (double)db / 20.0) @@ -133,7 +133,7 @@ void dtmf_decode(dtmf_dec_t *dtmf, sample_t *samples, int length) dtmf_decode_filter(dtmf, samples, length, frequency_low, frequency_high, amplitude_low, amplitude_high); for (i = 0; i < length; i++) { -#ifdef DEBUG +#ifdef DEBUG_DTMF // printf("%s %.5f\n", debug_amplitude(samples[i]/2.0), samples[i]/2.0); #endif /* get frequency of low frequencies, correct amplitude drop at cutoff point */ @@ -194,7 +194,7 @@ void dtmf_decode(dtmf_dec_t *dtmf, sample_t *samples, int length) /* check for limits */ if (amplitude_low[i] <= max_amplitude && amplitude_low[i] >= min_amplitude && amplitude_high[i] <= max_amplitude && amplitude_high[i] >= min_amplitude) { amplitude_ok = 1; -#ifdef DEBUG +#ifdef DEBUG_DTMF printf("%.1f %.1f (limits %.1f .. %.1f) %.1f\n", level2db(amplitude_low[i]), level2db(amplitude_high[i]), level2db(min_amplitude), level2db(max_amplitude), level2db(amplitude_high[i] / amplitude_low[i])); #endif if (amplitude_high[i] / amplitude_low[i] <= forward_twist && amplitude_low[i] / amplitude_high[i] <= reverse_twist) @@ -231,14 +231,14 @@ void dtmf_decode(dtmf_dec_t *dtmf, sample_t *samples, int length) count++; if (count >= time_pause) { detected = 0; -#ifdef DEBUG +#ifdef DEBUG_DTMF printf("lost!\n"); #endif } } else count = 0; } -#ifdef DEBUG +#ifdef DEBUG_DTMF if (digit) printf("DTMF tone='%c' diff frequency=%.1f %.1f amplitude=%.1f %.1f dB (%s) twist=%.1f dB (%s)\n", digit, f1, f2, level2db(amplitude_low[i]), level2db(amplitude_high[i]), (amplitude_ok) ? "OK" : "nok", level2db(amplitude_high[i] / amplitude_low[i]), (twist_ok) ? "OK" : "nok"); #endif diff --git a/src/libfsk/fsk.c b/src/libfsk/fsk.c index dcc437d..2d8879e 100644 --- a/src/libfsk/fsk.c +++ b/src/libfsk/fsk.c @@ -24,7 +24,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "fsk.h" #define PI M_PI @@ -51,7 +51,7 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa int i; int rc; - PDEBUG(DDSP, DEBUG_DEBUG, "Setup FSK for Transmitter. (F0 = %.1f, F1 = %.1f, peak = %.1f)\n", f0, f1, level); + LOGP(DDSP, LOGL_DEBUG, "Setup FSK for Transmitter. (F0 = %.1f, F1 = %.1f, peak = %.1f)\n", f0, f1, level); memset(fsk, 0, sizeof(*fsk)); @@ -79,12 +79,12 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa } fsk->bits65536_per_sample = (double)bitrate / (double)samplerate * 65536.0; - PDEBUG(DDSP, DEBUG_DEBUG, "Bitduration of %.4f bits per sample @ %d.\n", fsk->bits65536_per_sample / 65536.0, samplerate); + LOGP(DDSP, LOGL_DEBUG, "Bitduration of %.4f bits per sample @ %d.\n", fsk->bits65536_per_sample / 65536.0, samplerate); fsk->phaseshift65536[0] = f0 / (double)samplerate * 65536.0; fsk->phaseshift65536[1] = f1 / (double)samplerate * 65536.0; - PDEBUG(DDSP, DEBUG_DEBUG, "F0 = %.0f Hz (phaseshift65536[0] = %.4f)\n", f0, fsk->phaseshift65536[0]); - PDEBUG(DDSP, DEBUG_DEBUG, "F1 = %.0f Hz (phaseshift65536[1] = %.4f)\n", f1, fsk->phaseshift65536[1]); + LOGP(DDSP, LOGL_DEBUG, "F0 = %.0f Hz (phaseshift65536[0] = %.4f)\n", f0, fsk->phaseshift65536[0]); + LOGP(DDSP, LOGL_DEBUG, "F1 = %.0f Hz (phaseshift65536[1] = %.4f)\n", f1, fsk->phaseshift65536[1]); /* use ffsk modulation, i.e. each bit has an integer number of * half waves and starts/ends at zero crossing @@ -93,12 +93,12 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa double waves; if (filter) { - PDEBUG(DDSP, DEBUG_ERROR, "Cannot use FFSK with filter.\n"); + LOGP(DDSP, LOGL_ERROR, "Cannot use FFSK with filter.\n"); rc = -EINVAL; goto error; } - PDEBUG(DDSP, DEBUG_DEBUG, "enable FFSK modulation mode\n"); + LOGP(DDSP, LOGL_DEBUG, "enable FFSK modulation mode\n"); fsk->ffsk = 1; waves = (f0 / bitrate); if (fabs(round(waves * 2) - (waves * 2)) > 0.001) { @@ -116,8 +116,8 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa fsk->cycles_per_bit65536[0] = f0 / bitrate * 65536.0; fsk->cycles_per_bit65536[1] = f1 / bitrate * 65536.0; } - PDEBUG(DDSP, DEBUG_DEBUG, "F0 = %.0f Hz (cycles_per_bit65536[0] = %.4f)\n", f0, fsk->cycles_per_bit65536[0]); - PDEBUG(DDSP, DEBUG_DEBUG, "F1 = %.0f Hz (cycles_per_bit65536[1] = %.4f)\n", f1, fsk->cycles_per_bit65536[1]); + LOGP(DDSP, LOGL_DEBUG, "F0 = %.0f Hz (cycles_per_bit65536[0] = %.4f)\n", f0, fsk->cycles_per_bit65536[0]); + LOGP(DDSP, LOGL_DEBUG, "F1 = %.0f Hz (cycles_per_bit65536[1] = %.4f)\n", f1, fsk->cycles_per_bit65536[1]); /* if filter is enabled, use a cosine shaped curve to change the phase each sample */ if (filter) { @@ -138,7 +138,7 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa #endif } - PDEBUG(DDSP, DEBUG_DEBUG, "Enable filter to smooth FSK transmission.\n"); + LOGP(DDSP, LOGL_DEBUG, "Enable filter to smooth FSK transmission.\n"); fsk->filter = 1; } @@ -155,7 +155,7 @@ error: /* Cleanup transceiver instance. */ void fsk_mod_cleanup(fsk_mod_t *fsk) { - PDEBUG(DDSP, DEBUG_DEBUG, "Cleanup FSK for Transmitter.\n"); + LOGP(DDSP, LOGL_DEBUG, "Cleanup FSK for Transmitter.\n"); if (fsk->sin_tab) { free(fsk->sin_tab); @@ -314,7 +314,7 @@ int fsk_demod_init(fsk_demod_t *fsk, void *inst, void (*receive_bit)(void *inst, double bandwidth; int rc; - PDEBUG(DDSP, DEBUG_DEBUG, "Setup FSK for Receiver. (F0 = %.1f, F1 = %.1f)\n", f0, f1); + LOGP(DDSP, LOGL_DEBUG, "Setup FSK for Receiver. (F0 = %.1f, F1 = %.1f)\n", f0, f1); memset(fsk, 0, sizeof(*fsk)); @@ -341,7 +341,7 @@ int fsk_demod_init(fsk_demod_t *fsk, void *inst, void (*receive_bit)(void *inst, goto error; fsk->bits_per_sample = (double)bitrate / (double)samplerate; - PDEBUG(DDSP, DEBUG_DEBUG, "Bitduration of %.4f bits per sample @ %d.\n", fsk->bits_per_sample, samplerate); + LOGP(DDSP, LOGL_DEBUG, "Bitduration of %.4f bits per sample @ %d.\n", fsk->bits_per_sample, samplerate); return 0; @@ -353,7 +353,7 @@ error: /* Cleanup transceiver instance. */ void fsk_demod_cleanup(fsk_demod_t *fsk) { - PDEBUG(DDSP, DEBUG_DEBUG, "Cleanup FSK for Receiver.\n"); + LOGP(DDSP, LOGL_DEBUG, "Cleanup FSK for Receiver.\n"); fm_demod_exit(&fsk->demod); } diff --git a/src/libg711/Makefile.am b/src/libg711/Makefile.am deleted file mode 100644 index 15223bf..0000000 --- a/src/libg711/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) - -noinst_LIBRARIES = libg711.a - -libg711_a_SOURCES = \ - g711.c - diff --git a/src/libg711/g711.c b/src/libg711/g711.c deleted file mode 100644 index 92404c1..0000000 --- a/src/libg711/g711.c +++ /dev/null @@ -1,537 +0,0 @@ -/*****************************************************************************\ -** ** -** PBX4Linux ** -** ** -**---------------------------------------------------------------------------** -** Copyright: Andreas Eversberg (GPL) ** -** ** -** audio conversions for alaw and ulaw ** -** ** -\*****************************************************************************/ - -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> - -/* ulaw -> signed 16-bit */ -static int16_t g711_ulaw_to_linear[256] = -{ - 0x8284, 0x8684, 0x8a84, 0x8e84, 0x9284, 0x9684, 0x9a84, 0x9e84, - 0xa284, 0xa684, 0xaa84, 0xae84, 0xb284, 0xb684, 0xba84, 0xbe84, - 0xc184, 0xc384, 0xc584, 0xc784, 0xc984, 0xcb84, 0xcd84, 0xcf84, - 0xd184, 0xd384, 0xd584, 0xd784, 0xd984, 0xdb84, 0xdd84, 0xdf84, - 0xe104, 0xe204, 0xe304, 0xe404, 0xe504, 0xe604, 0xe704, 0xe804, - 0xe904, 0xea04, 0xeb04, 0xec04, 0xed04, 0xee04, 0xef04, 0xf004, - 0xf0c4, 0xf144, 0xf1c4, 0xf244, 0xf2c4, 0xf344, 0xf3c4, 0xf444, - 0xf4c4, 0xf544, 0xf5c4, 0xf644, 0xf6c4, 0xf744, 0xf7c4, 0xf844, - 0xf8a4, 0xf8e4, 0xf924, 0xf964, 0xf9a4, 0xf9e4, 0xfa24, 0xfa64, - 0xfaa4, 0xfae4, 0xfb24, 0xfb64, 0xfba4, 0xfbe4, 0xfc24, 0xfc64, - 0xfc94, 0xfcb4, 0xfcd4, 0xfcf4, 0xfd14, 0xfd34, 0xfd54, 0xfd74, - 0xfd94, 0xfdb4, 0xfdd4, 0xfdf4, 0xfe14, 0xfe34, 0xfe54, 0xfe74, - 0xfe8c, 0xfe9c, 0xfeac, 0xfebc, 0xfecc, 0xfedc, 0xfeec, 0xfefc, - 0xff0c, 0xff1c, 0xff2c, 0xff3c, 0xff4c, 0xff5c, 0xff6c, 0xff7c, - 0xff88, 0xff90, 0xff98, 0xffa0, 0xffa8, 0xffb0, 0xffb8, 0xffc0, - 0xffc8, 0xffd0, 0xffd8, 0xffe0, 0xffe8, 0xfff0, 0xfff8, 0xffff, - 0x7d7c, 0x797c, 0x757c, 0x717c, 0x6d7c, 0x697c, 0x657c, 0x617c, - 0x5d7c, 0x597c, 0x557c, 0x517c, 0x4d7c, 0x497c, 0x457c, 0x417c, - 0x3e7c, 0x3c7c, 0x3a7c, 0x387c, 0x367c, 0x347c, 0x327c, 0x307c, - 0x2e7c, 0x2c7c, 0x2a7c, 0x287c, 0x267c, 0x247c, 0x227c, 0x207c, - 0x1efc, 0x1dfc, 0x1cfc, 0x1bfc, 0x1afc, 0x19fc, 0x18fc, 0x17fc, - 0x16fc, 0x15fc, 0x14fc, 0x13fc, 0x12fc, 0x11fc, 0x10fc, 0x0ffc, - 0x0f3c, 0x0ebc, 0x0e3c, 0x0dbc, 0x0d3c, 0x0cbc, 0x0c3c, 0x0bbc, - 0x0b3c, 0x0abc, 0x0a3c, 0x09bc, 0x093c, 0x08bc, 0x083c, 0x07bc, - 0x075c, 0x071c, 0x06dc, 0x069c, 0x065c, 0x061c, 0x05dc, 0x059c, - 0x055c, 0x051c, 0x04dc, 0x049c, 0x045c, 0x041c, 0x03dc, 0x039c, - 0x036c, 0x034c, 0x032c, 0x030c, 0x02ec, 0x02cc, 0x02ac, 0x028c, - 0x026c, 0x024c, 0x022c, 0x020c, 0x01ec, 0x01cc, 0x01ac, 0x018c, - 0x0174, 0x0164, 0x0154, 0x0144, 0x0134, 0x0124, 0x0114, 0x0104, - 0x00f4, 0x00e4, 0x00d4, 0x00c4, 0x00b4, 0x00a4, 0x0094, 0x0084, - 0x0078, 0x0070, 0x0068, 0x0060, 0x0058, 0x0050, 0x0048, 0x0040, - 0x0038, 0x0030, 0x0028, 0x0020, 0x0018, 0x0010, 0x0008, 0x0000 -}; - -/* alaw -> signed 16-bit */ -static int16_t g711_alaw_flipped_to_linear[256] = -{ - 0x13fc, 0xec04, 0x0144, 0xfebc, 0x517c, 0xae84, 0x051c, 0xfae4, - 0x0a3c, 0xf5c4, 0x0048, 0xffb8, 0x287c, 0xd784, 0x028c, 0xfd74, - 0x1bfc, 0xe404, 0x01cc, 0xfe34, 0x717c, 0x8e84, 0x071c, 0xf8e4, - 0x0e3c, 0xf1c4, 0x00c4, 0xff3c, 0x387c, 0xc784, 0x039c, 0xfc64, - 0x0ffc, 0xf004, 0x0104, 0xfefc, 0x417c, 0xbe84, 0x041c, 0xfbe4, - 0x083c, 0xf7c4, 0x0008, 0xfff8, 0x207c, 0xdf84, 0x020c, 0xfdf4, - 0x17fc, 0xe804, 0x018c, 0xfe74, 0x617c, 0x9e84, 0x061c, 0xf9e4, - 0x0c3c, 0xf3c4, 0x0084, 0xff7c, 0x307c, 0xcf84, 0x030c, 0xfcf4, - 0x15fc, 0xea04, 0x0164, 0xfe9c, 0x597c, 0xa684, 0x059c, 0xfa64, - 0x0b3c, 0xf4c4, 0x0068, 0xff98, 0x2c7c, 0xd384, 0x02cc, 0xfd34, - 0x1dfc, 0xe204, 0x01ec, 0xfe14, 0x797c, 0x8684, 0x07bc, 0xf844, - 0x0f3c, 0xf0c4, 0x00e4, 0xff1c, 0x3c7c, 0xc384, 0x03dc, 0xfc24, - 0x11fc, 0xee04, 0x0124, 0xfedc, 0x497c, 0xb684, 0x049c, 0xfb64, - 0x093c, 0xf6c4, 0x0028, 0xffd8, 0x247c, 0xdb84, 0x024c, 0xfdb4, - 0x19fc, 0xe604, 0x01ac, 0xfe54, 0x697c, 0x9684, 0x069c, 0xf964, - 0x0d3c, 0xf2c4, 0x00a4, 0xff5c, 0x347c, 0xcb84, 0x034c, 0xfcb4, - 0x12fc, 0xed04, 0x0134, 0xfecc, 0x4d7c, 0xb284, 0x04dc, 0xfb24, - 0x09bc, 0xf644, 0x0038, 0xffc8, 0x267c, 0xd984, 0x026c, 0xfd94, - 0x1afc, 0xe504, 0x01ac, 0xfe54, 0x6d7c, 0x9284, 0x06dc, 0xf924, - 0x0dbc, 0xf244, 0x00b4, 0xff4c, 0x367c, 0xc984, 0x036c, 0xfc94, - 0x0f3c, 0xf0c4, 0x00f4, 0xff0c, 0x3e7c, 0xc184, 0x03dc, 0xfc24, - 0x07bc, 0xf844, 0x0008, 0xfff8, 0x1efc, 0xe104, 0x01ec, 0xfe14, - 0x16fc, 0xe904, 0x0174, 0xfe8c, 0x5d7c, 0xa284, 0x05dc, 0xfa24, - 0x0bbc, 0xf444, 0x0078, 0xff88, 0x2e7c, 0xd184, 0x02ec, 0xfd14, - 0x14fc, 0xeb04, 0x0154, 0xfeac, 0x557c, 0xaa84, 0x055c, 0xfaa4, - 0x0abc, 0xf544, 0x0058, 0xffa8, 0x2a7c, 0xd584, 0x02ac, 0xfd54, - 0x1cfc, 0xe304, 0x01cc, 0xfe34, 0x757c, 0x8a84, 0x075c, 0xf8a4, - 0x0ebc, 0xf144, 0x00d4, 0xff2c, 0x3a7c, 0xc584, 0x039c, 0xfc64, - 0x10fc, 0xef04, 0x0114, 0xfeec, 0x457c, 0xba84, 0x045c, 0xfba4, - 0x08bc, 0xf744, 0x0018, 0xffe8, 0x227c, 0xdd84, 0x022c, 0xfdd4, - 0x18fc, 0xe704, 0x018c, 0xfe74, 0x657c, 0x9a84, 0x065c, 0xf9a4, - 0x0cbc, 0xf344, 0x0094, 0xff6c, 0x327c, 0xcd84, 0x032c, 0xfcd4 -}; - -/* Xlaw -> signed 16-bit */ -static int16_t g711_alaw_to_linear[256]; -static int16_t g711_ulaw_flipped_to_linear[256]; - -/* signed 16-bit -> Xlaw */ -static uint8_t g711_linear_to_alaw_flipped[65536]; -static uint8_t g711_linear_to_ulaw_flipped[65536]; -static uint8_t g711_linear_to_alaw[65536]; -static uint8_t g711_linear_to_ulaw[65536]; - -/* transcode */ -static uint8_t g711_alaw_to_ulaw[256]; -static uint8_t g711_ulaw_to_alaw[256]; -static uint8_t g711_alaw_flipped_to_ulaw[256]; -static uint8_t g711_ulaw_flipped_to_alaw[256]; -static uint8_t g711_alaw_to_ulaw_flipped[256]; -static uint8_t g711_ulaw_to_alaw_flipped[256]; - -/* table is used to generate linear_to_alaw */ -static int16_t g711_alaw_relations[] = -{ - 0x8684, 0x55, 0x8a84, 0xd5, 0x8e84, 0x15, 0x9284, 0x95, - 0x9684, 0x75, 0x9a84, 0xf5, 0x9e84, 0x35, 0xa284, 0xb5, - 0xa684, 0x45, 0xaa84, 0xc5, 0xae84, 0x05, 0xb284, 0x85, - 0xb684, 0x65, 0xba84, 0xe5, 0xbe84, 0x25, 0xc184, 0xa5, - 0xc384, 0x5d, 0xc584, 0xdd, 0xc784, 0x1d, 0xc984, 0x9d, - 0xcb84, 0x7d, 0xcd84, 0xfd, 0xcf84, 0x3d, 0xd184, 0xbd, - 0xd384, 0x4d, 0xd584, 0xcd, 0xd784, 0x0d, 0xd984, 0x8d, - 0xdb84, 0x6d, 0xdd84, 0xed, 0xdf84, 0x2d, 0xe104, 0xad, - 0xe204, 0x51, 0xe304, 0xd1, 0xe404, 0x11, 0xe504, 0x91, - 0xe604, 0x71, 0xe704, 0xf1, 0xe804, 0x31, 0xe904, 0xb1, - 0xea04, 0x41, 0xeb04, 0xc1, 0xec04, 0x01, 0xed04, 0x81, - 0xee04, 0x61, 0xef04, 0xe1, 0xf004, 0x21, 0xf0c4, 0x59, - 0xf0c4, 0xa1, 0xf144, 0xd9, 0xf1c4, 0x19, 0xf244, 0x99, - 0xf2c4, 0x79, 0xf344, 0xf9, 0xf3c4, 0x39, 0xf444, 0xb9, - 0xf4c4, 0x49, 0xf544, 0xc9, 0xf5c4, 0x09, 0xf644, 0x89, - 0xf6c4, 0x69, 0xf744, 0xe9, 0xf7c4, 0x29, 0xf844, 0x57, - 0xf844, 0xa9, 0xf8a4, 0xd7, 0xf8e4, 0x17, 0xf924, 0x97, - 0xf964, 0x77, 0xf9a4, 0xf7, 0xf9e4, 0x37, 0xfa24, 0xb7, - 0xfa64, 0x47, 0xfaa4, 0xc7, 0xfae4, 0x07, 0xfb24, 0x87, - 0xfb64, 0x67, 0xfba4, 0xe7, 0xfbe4, 0x27, 0xfc24, 0x5f, - 0xfc24, 0xa7, 0xfc64, 0x1f, 0xfc64, 0xdf, 0xfc94, 0x9f, - 0xfcb4, 0x7f, 0xfcd4, 0xff, 0xfcf4, 0x3f, 0xfd14, 0xbf, - 0xfd34, 0x4f, 0xfd54, 0xcf, 0xfd74, 0x0f, 0xfd94, 0x8f, - 0xfdb4, 0x6f, 0xfdd4, 0xef, 0xfdf4, 0x2f, 0xfe14, 0x53, - 0xfe14, 0xaf, 0xfe34, 0x13, 0xfe34, 0xd3, 0xfe54, 0x73, - 0xfe54, 0x93, 0xfe74, 0x33, 0xfe74, 0xf3, 0xfe8c, 0xb3, - 0xfe9c, 0x43, 0xfeac, 0xc3, 0xfebc, 0x03, 0xfecc, 0x83, - 0xfedc, 0x63, 0xfeec, 0xe3, 0xfefc, 0x23, 0xff0c, 0xa3, - 0xff1c, 0x5b, 0xff2c, 0xdb, 0xff3c, 0x1b, 0xff4c, 0x9b, - 0xff5c, 0x7b, 0xff6c, 0xfb, 0xff7c, 0x3b, 0xff88, 0xbb, - 0xff98, 0x4b, 0xffa8, 0xcb, 0xffb8, 0x0b, 0xffc8, 0x8b, - 0xffd8, 0x6b, 0xffe8, 0xeb, 0xfff8, 0x2b, 0xfff8, 0xab, - 0x0008, 0x2a, 0x0008, 0xaa, 0x0018, 0xea, 0x0028, 0x6a, - 0x0038, 0x8a, 0x0048, 0x0a, 0x0058, 0xca, 0x0068, 0x4a, - 0x0078, 0xba, 0x0084, 0x3a, 0x0094, 0xfa, 0x00a4, 0x7a, - 0x00b4, 0x9a, 0x00c4, 0x1a, 0x00d4, 0xda, 0x00e4, 0x5a, - 0x00f4, 0xa2, 0x0104, 0x22, 0x0114, 0xe2, 0x0124, 0x62, - 0x0134, 0x82, 0x0144, 0x02, 0x0154, 0xc2, 0x0164, 0x42, - 0x0174, 0xb2, 0x018c, 0x32, 0x018c, 0xf2, 0x01ac, 0x72, - 0x01ac, 0x92, 0x01cc, 0x12, 0x01cc, 0xd2, 0x01ec, 0x52, - 0x01ec, 0xae, 0x020c, 0x2e, 0x022c, 0xee, 0x024c, 0x6e, - 0x026c, 0x8e, 0x028c, 0x0e, 0x02ac, 0xce, 0x02cc, 0x4e, - 0x02ec, 0xbe, 0x030c, 0x3e, 0x032c, 0xfe, 0x034c, 0x7e, - 0x036c, 0x9e, 0x039c, 0x1e, 0x039c, 0xde, 0x03dc, 0x5e, - 0x03dc, 0xa6, 0x041c, 0x26, 0x045c, 0xe6, 0x049c, 0x66, - 0x04dc, 0x86, 0x051c, 0x06, 0x055c, 0xc6, 0x059c, 0x46, - 0x05dc, 0xb6, 0x061c, 0x36, 0x065c, 0xf6, 0x069c, 0x76, - 0x06dc, 0x96, 0x071c, 0x16, 0x075c, 0xd6, 0x07bc, 0x56, - 0x07bc, 0xa8, 0x083c, 0x28, 0x08bc, 0xe8, 0x093c, 0x68, - 0x09bc, 0x88, 0x0a3c, 0x08, 0x0abc, 0xc8, 0x0b3c, 0x48, - 0x0bbc, 0xb8, 0x0c3c, 0x38, 0x0cbc, 0xf8, 0x0d3c, 0x78, - 0x0dbc, 0x98, 0x0e3c, 0x18, 0x0ebc, 0xd8, 0x0f3c, 0x58, - 0x0f3c, 0xa0, 0x0ffc, 0x20, 0x10fc, 0xe0, 0x11fc, 0x60, - 0x12fc, 0x80, 0x13fc, 0x00, 0x14fc, 0xc0, 0x15fc, 0x40, - 0x16fc, 0xb0, 0x17fc, 0x30, 0x18fc, 0xf0, 0x19fc, 0x70, - 0x1afc, 0x90, 0x1bfc, 0x10, 0x1cfc, 0xd0, 0x1dfc, 0x50, - 0x1efc, 0xac, 0x207c, 0x2c, 0x227c, 0xec, 0x247c, 0x6c, - 0x267c, 0x8c, 0x287c, 0x0c, 0x2a7c, 0xcc, 0x2c7c, 0x4c, - 0x2e7c, 0xbc, 0x307c, 0x3c, 0x327c, 0xfc, 0x347c, 0x7c, - 0x367c, 0x9c, 0x387c, 0x1c, 0x3a7c, 0xdc, 0x3c7c, 0x5c, - 0x3e7c, 0xa4, 0x417c, 0x24, 0x457c, 0xe4, 0x497c, 0x64, - 0x4d7c, 0x84, 0x517c, 0x04, 0x557c, 0xc4, 0x597c, 0x44, - 0x5d7c, 0xb4, 0x617c, 0x34, 0x657c, 0xf4, 0x697c, 0x74, - 0x6d7c, 0x94, 0x717c, 0x14, 0x757c, 0xd4, 0x797c, 0x54 -}; - -uint8_t g711_flip[256]; - -static int g711_initialized = 0; - -/* generate tables - */ -void g711_init(void) -{ - int i, j; - - /* flip tables */ - for (i = 0; i < 256; i++) { - g711_flip[i] - = ((i & 1) << 7) - + ((i & 2) << 5) - + ((i & 4) << 3) - + ((i & 8) << 1) - + ((i & 16) >> 1) - + ((i & 32) >> 3) - + ((i & 64) >> 5) - + ((i & 128) >> 7); - g711_alaw_to_linear[i] = g711_alaw_flipped_to_linear[g711_flip[i]]; - g711_ulaw_flipped_to_linear[i] = g711_ulaw_to_linear[g711_flip[i]]; - } - - /* linear to alaw tables */ - i = j = 0; - while(i < 65536) { - if (i - 32768 > g711_alaw_relations[j << 1]) - j++; - if (j > 255) - j = 255; - g711_linear_to_alaw_flipped[(i - 32768) & 0xffff] = g711_alaw_relations[(j << 1) | 1]; - g711_linear_to_alaw[(i - 32768) & 0xffff] = g711_flip[g711_alaw_relations[(j << 1) | 1]]; - i++; - } - - /* linear to ulaw tables */ - i = j = 0; - while(i < 32768) { - if (i - 32768 > g711_ulaw_to_linear[j]) - j++; - g711_linear_to_ulaw[(i - 32768) & 0xffff] = j; - g711_linear_to_ulaw_flipped[(i - 32768) & 0xffff] = g711_flip[j]; - i++; - } - j = 255; - while(i < 65536) { - if (i - 32768 > g711_ulaw_to_linear[j]) - j--; - g711_linear_to_ulaw[(i - 32768) & 0xffff] = j; - g711_linear_to_ulaw_flipped[(i - 32768) & 0xffff] = g711_flip[j]; - i++; - } - - /* transcode */ - for (i = 0; i < 256; i++) { - g711_alaw_to_ulaw[i] = g711_linear_to_ulaw[(uint16_t)g711_alaw_to_linear[i]]; - g711_ulaw_to_alaw[i] = g711_linear_to_alaw[(uint16_t)g711_ulaw_to_linear[i]]; - g711_alaw_flipped_to_ulaw[i] = g711_linear_to_ulaw[(uint16_t)g711_alaw_to_linear[g711_flip[i]]]; - g711_ulaw_flipped_to_alaw[i] = g711_linear_to_alaw[(uint16_t)g711_ulaw_to_linear[g711_flip[i]]]; - g711_alaw_to_ulaw_flipped[i] = g711_flip[g711_linear_to_ulaw[(uint16_t)g711_alaw_to_linear[i]]]; - g711_ulaw_to_alaw_flipped[i] = g711_flip[g711_linear_to_alaw[(uint16_t)g711_ulaw_to_linear[i]]]; - } - - g711_initialized = 1; -} - -void g711_encode_alaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - int16_t *src = (int16_t *)src_data; - uint8_t *dst; - int len = src_len / 2, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_linear_to_alaw_flipped[(uint16_t)src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_encode_ulaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - int16_t *src = (int16_t *)src_data; - uint8_t *dst; - int len = src_len / 2, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_linear_to_ulaw_flipped[(uint16_t)src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_decode_alaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data; - int16_t *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len * 2); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_alaw_flipped_to_linear[src[i]]; - *dst_data = (uint8_t *)dst; - *dst_len = len * 2; -} - -void g711_decode_ulaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data; - int16_t *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len * 2); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_ulaw_flipped_to_linear[src[i]]; - *dst_data = (uint8_t *)dst; - *dst_len = len * 2; -} - -void g711_encode_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - int16_t *src = (int16_t *)src_data; - uint8_t *dst; - int len = src_len / 2, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_linear_to_alaw[(uint16_t)src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_encode_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - int16_t *src = (int16_t *)src_data; - uint8_t *dst; - int len = src_len / 2, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_linear_to_ulaw[(uint16_t)src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_decode_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data; - int16_t *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len * 2); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_alaw_to_linear[src[i]]; - *dst_data = (uint8_t *)dst; - *dst_len = len * 2; -} - -void g711_decode_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data; - int16_t *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len * 2); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_ulaw_to_linear[src[i]]; - *dst_data = (uint8_t *)dst; - *dst_len = len * 2; -} - -void g711_transcode_alaw_to_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_alaw_to_ulaw[src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_transcode_alaw_flipped_to_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_alaw_flipped_to_ulaw[src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_transcode_alaw_to_ulaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_alaw_to_ulaw_flipped[src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_transcode_ulaw_to_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_ulaw_to_alaw[src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_transcode_ulaw_flipped_to_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_ulaw_flipped_to_alaw[src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_transcode_ulaw_to_alaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_ulaw_to_alaw_flipped[src[i]]; - *dst_data = dst; - *dst_len = len; -} - -void g711_transcode_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void __attribute__((unused)) *priv) -{ - uint8_t *src = src_data, *dst; - int len = src_len, i; - - if (!g711_initialized) { - fprintf(stderr, "G711 codec not initialized! Please fix!\n"); - abort(); - } - - dst = malloc(len); - if (!dst) - return; - for (i = 0; i < len; i++) - dst[i] = g711_flip[src[i]]; - *dst_data = dst; - *dst_len = len; -} - diff --git a/src/libg711/g711.h b/src/libg711/g711.h deleted file mode 100644 index 389daa9..0000000 --- a/src/libg711/g711.h +++ /dev/null @@ -1,17 +0,0 @@ -void g711_init(void); -void g711_encode_alaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_encode_ulaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_decode_alaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_decode_ulaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_encode_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_encode_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_decode_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_decode_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_alaw_to_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_alaw_flipped_to_ulaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_alaw_to_ulaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_ulaw_to_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_ulaw_flipped_to_alaw(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_ulaw_to_alaw_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -void g711_transcode_flipped(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); - diff --git a/src/libgoertzel/goertzel.c b/src/libgoertzel/goertzel.c index d928175..f3e6030 100644 --- a/src/libgoertzel/goertzel.c +++ b/src/libgoertzel/goertzel.c @@ -23,7 +23,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "goertzel.h" /* diff --git a/src/libjitter/jitter.c b/src/libjitter/jitter.c index 1de03c2..bcf27ac 100644 --- a/src/libjitter/jitter.c +++ b/src/libjitter/jitter.c @@ -77,7 +77,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "jitter.h" #define INITIAL_DELAY_INTERVAL 0.5 @@ -104,7 +104,7 @@ int jitter_create(jitter_t *jb, const char *name, double samplerate, int sample_ jb->extra_size = (int)(EXTRA_BUFFER * samplerate); jb->extra_samples = calloc(sample_size, jb->extra_size); if (!jb->extra_samples) { - PDEBUG(DJITTER, DEBUG_ERROR, "No memory for frame.\n"); + LOGP(DJITTER, LOGL_ERROR, "No memory for frame.\n"); rc = -ENOMEM; goto error; } @@ -118,7 +118,7 @@ int jitter_create(jitter_t *jb, const char *name, double samplerate, int sample_ jitter_reset(jb); - PDEBUG(DJITTER, DEBUG_INFO, "%sCreated jitter buffer. (samplerate=%.0f, target_window=%.0fms, max_window=%.0fms, flag:latency=%s flag:repeat=%s)\n", jb->name, samplerate, target_window_duration * 1000.0, max_window_duration * 1000.0, (window_flags & JITTER_FLAG_LATENCY) ? "true" : "false", (window_flags & JITTER_FLAG_REPEAT) ? "true" : "false"); + LOGP(DJITTER, LOGL_INFO, "%sCreated jitter buffer. (samplerate=%.0f, target_window=%.0fms, max_window=%.0fms, flag:latency=%s flag:repeat=%s)\n", jb->name, samplerate, target_window_duration * 1000.0, max_window_duration * 1000.0, (window_flags & JITTER_FLAG_LATENCY) ? "true" : "false", (window_flags & JITTER_FLAG_REPEAT) ? "true" : "false"); error: if (rc) @@ -139,7 +139,7 @@ void jitter_reset(jitter_t *jb) { jitter_frame_t *jf, *temp; - PDEBUG(DJITTER, DEBUG_INFO, "%sReset jitter buffer.\n", jb->name); + LOGP(DJITTER, LOGL_INFO, "%sReset jitter buffer.\n", jb->name); /* jitter buffer locked */ jb->unlocked = 0; @@ -172,7 +172,7 @@ void jitter_destroy(jitter_t *jb) { jitter_reset(jb); - PDEBUG(DJITTER, DEBUG_INFO, "%sDestroying jitter buffer.\n", jb->name); + LOGP(DJITTER, LOGL_INFO, "%sDestroying jitter buffer.\n", jb->name); if (jb->extra_samples) { free(jb->extra_samples); @@ -201,7 +201,7 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint /* generate sequence and timestamp automatically, if enabled */ if (!has_sequence) { #ifdef DEBUG_JITTER - PDEBUG(DJITTER, DEBUG_DEBUG, "%sSave frame of %d samples (no seqence).\n", jb->name, length); + LOGP(DJITTER, LOGL_DEBUG, "%sSave frame of %d samples (no seqence).\n", jb->name, length); #endif sequence = jb->next_sequence; jb->next_sequence++; @@ -210,7 +210,7 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint ssrc = jb->window_ssrc; } else { #ifdef HEAVY_DEBUG - PDEBUG(DJITTER, DEBUG_DEBUG, "%sSave frame of %d samples (seqence=%u timestamp=%u ssrc=0x%02x).\n", jb->name, length, sequence, timestamp, ssrc); + LOGP(DJITTER, LOGL_DEBUG, "%sSave frame of %d samples (seqence=%u timestamp=%u ssrc=0x%02x).\n", jb->name, length, sequence, timestamp, ssrc); #endif jb->next_sequence = sequence + 1; jb->next_timestamp = timestamp + length; @@ -219,9 +219,9 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint /* first packet (with this ssrc) sets window size to target_window_size */ if (!jb->window_valid || jb->window_ssrc != ssrc) { if (!jb->window_valid) - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Initial frame after init or reset.\n", jb->name); + LOGP(DJITTER, LOGL_DEBUG, "%s Initial frame after init or reset.\n", jb->name); else - PDEBUG(DJITTER, DEBUG_DEBUG, "%s SSRC changed.\n", jb->name); + LOGP(DJITTER, LOGL_DEBUG, "%s SSRC changed.\n", jb->name); // NOTE: Reset must be called before finding the frame location below, because there will be no frame in list anymore! jitter_reset(jb); jb->unlocked = 1; @@ -241,7 +241,7 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint offset_sequence = (int16_t)(sequence - (*jfp)->sequence); /* found double entry */ if (offset_sequence == 0) { - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Dropping double packet (sequence = %d)\n", jb->name, sequence); + LOGP(DJITTER, LOGL_DEBUG, "%s Dropping double packet (sequence = %d)\n", jb->name, sequence); return; } /* offset is negative, so we found the position to insert frame */ @@ -252,7 +252,7 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint offset_timestamp = timestamp - jb->window_timestamp; #ifdef HEAVY_DEBUG - PDEBUG(DJITTER, DEBUG_DEBUG, "%sFrame has offset of %.0fms in jitter buffer.\n", jb->name, (double)offset_timestamp * jb->sample_duration * 1000.0); + LOGP(DJITTER, LOGL_DEBUG, "%sFrame has offset of %.0fms in jitter buffer.\n", jb->name, (double)offset_timestamp * jb->sample_duration * 1000.0); #endif /* measure delay */ @@ -262,11 +262,11 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint /* if frame is too early (delay ceases), shift window to the future */ if (offset_timestamp > jb->max_window_size) { if ((jb->window_flags & JITTER_FLAG_LATENCY)) { - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Frame too early: Shift jitter buffer to the future, to make the frame fit to the end. (offset_timestamp(%d) > max_window_size(%d))\n", jb->name, offset_timestamp, jb->max_window_size); + LOGP(DJITTER, LOGL_DEBUG, "%s Frame too early: Shift jitter buffer to the future, to make the frame fit to the end. (offset_timestamp(%d) > max_window_size(%d))\n", jb->name, offset_timestamp, jb->max_window_size); /* shift window so it fits to the end of window */ jb->window_timestamp = timestamp - jb->max_window_size; } else { - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Frame too early: Shift jitter buffer to the future, to make the frame fit to the target delay. (offset_timestamp(%d) > max_window_size(%d))\n", jb->name, offset_timestamp, jb->max_window_size); + LOGP(DJITTER, LOGL_DEBUG, "%s Frame too early: Shift jitter buffer to the future, to make the frame fit to the target delay. (offset_timestamp(%d) > max_window_size(%d))\n", jb->name, offset_timestamp, jb->max_window_size); /* shift window so frame fits to the start of window + target delay */ jb->window_timestamp = timestamp - (uint32_t)(jb->target_window_size); } @@ -275,11 +275,11 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint /* is frame is too late, shift window to the past. */ if (offset_timestamp < 0) { if ((jb->window_flags & JITTER_FLAG_LATENCY)) { - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Frame too late: Shift jitter buffer to the past, and add target window size. (offset_timestamp(%d) < 0)\n", jb->name, offset_timestamp); + LOGP(DJITTER, LOGL_DEBUG, "%s Frame too late: Shift jitter buffer to the past, and add target window size. (offset_timestamp(%d) < 0)\n", jb->name, offset_timestamp); /* shift window so frame fits to the start of window + half of target delay */ jb->window_timestamp = timestamp - (uint32_t)(jb->target_window_size) / 2; } else { - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Frame too late: Shift jitter buffer to the past, and add half target window size. (offset_timestamp(%d) < 0)\n", jb->name, offset_timestamp); + LOGP(DJITTER, LOGL_DEBUG, "%s Frame too late: Shift jitter buffer to the past, and add half target window size. (offset_timestamp(%d) < 0)\n", jb->name, offset_timestamp); /* shift window so frame fits to the start of window + target delay */ jb->window_timestamp = timestamp - (uint32_t)(jb->target_window_size); } @@ -287,11 +287,11 @@ void jitter_save(jitter_t *jb, void *samples, int length, int has_sequence, uint /* insert or append frame */ #ifdef HEAVY_DEBUG - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Store frame\n", jb->name); + LOGP(DJITTER, LOGL_DEBUG, "%s Store frame\n", jb->name); #endif jf = malloc(sizeof(*jf) + length * jb->sample_size); if (!jf) { - PDEBUG(DJITTER, DEBUG_ERROR, "No memory for frame.\n"); + LOGP(DJITTER, LOGL_ERROR, "No memory for frame.\n"); return; } memset(jf, 0, sizeof(*jf)); // note: clear header only @@ -311,7 +311,7 @@ void jitter_load(jitter_t *jb, void *samples, int length) int32_t count, count2, index; #ifdef HEAVY_DEBUG - PDEBUG(DJITTER, DEBUG_DEBUG, "%sLoad chunk of %d samples.\n", jb->name, length); + LOGP(DJITTER, LOGL_DEBUG, "%sLoad chunk of %d samples.\n", jb->name, length); #endif /* now unlock jitter buffer */ @@ -321,10 +321,10 @@ void jitter_load(jitter_t *jb, void *samples, int length) jb->delay_counter += jb->sample_duration * (double)length; if (jb->delay_counter >= jb->delay_interval) { if (jb->min_delay_value >= 0) - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Statistics: target_window_delay=%.0fms max_window_delay=%.0fms current min_delay=%.0fms\n", jb->name, (double)jb->target_window_size * jb->sample_duration * 1000.0, (double)jb->max_window_size * jb->sample_duration * 1000.0, (double)jb->min_delay_value * jb->sample_duration * 1000.0); + LOGP(DJITTER, LOGL_DEBUG, "%s Statistics: target_window_delay=%.0fms max_window_delay=%.0fms current min_delay=%.0fms\n", jb->name, (double)jb->target_window_size * jb->sample_duration * 1000.0, (double)jb->max_window_size * jb->sample_duration * 1000.0, (double)jb->min_delay_value * jb->sample_duration * 1000.0); /* delay reduction, if maximum delay is greater than target jitter window size */ if ((jb->window_flags & JITTER_FLAG_LATENCY) && jb->min_delay_value > jb->target_window_size) { - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Reducing current minimum delay of %.0fms, because maximum delay is greater than target window size of %.0fms.\n", jb->name, (double)jb->min_delay_value * jb->sample_duration * 1000.0, (double)jb->target_window_size * jb->sample_duration * 1000.0); + LOGP(DJITTER, LOGL_DEBUG, "%s Reducing current minimum delay of %.0fms, because maximum delay is greater than target window size of %.0fms.\n", jb->name, (double)jb->min_delay_value * jb->sample_duration * 1000.0, (double)jb->target_window_size * jb->sample_duration * 1000.0); /* only reduce delay to half of the target window size */ jb->window_timestamp += jb->min_delay_value - jb->target_window_size / 2; @@ -349,9 +349,9 @@ void jitter_load(jitter_t *jb, void *samples, int length) if (count > 0) { #ifdef HEAVY_DEBUG if (jf) - PDEBUG(DJITTER, DEBUG_DEBUG, "%s There is a frame ahead in buffer after %d samples. Interpolating gap.\n", jb->name, jf->timestamp - jb->window_timestamp); + LOGP(DJITTER, LOGL_DEBUG, "%s There is a frame ahead in buffer after %d samples. Interpolating gap.\n", jb->name, jf->timestamp - jb->window_timestamp); else - PDEBUG(DJITTER, DEBUG_DEBUG, "%s There is no frame ahead in buffer. Interpolating gap.\n", jb->name); + LOGP(DJITTER, LOGL_DEBUG, "%s There is no frame ahead in buffer. Interpolating gap.\n", jb->name); #endif /* extrapolate by playing the extrapolation buffer */ while (count) { @@ -366,7 +366,7 @@ void jitter_load(jitter_t *jb, void *samples, int length) jb->extra_timeout_count++; if (jb->extra_timeout_count == jb->extra_timeout_max) { #ifdef HEAVY_DEBUG - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Repeated jitter buffer enough, clearing to silence.\n", jb->name); + LOGP(DJITTER, LOGL_DEBUG, "%s Repeated jitter buffer enough, clearing to silence.\n", jb->name); #endif clear_extra_buffer(jb); } @@ -393,7 +393,7 @@ void jitter_load(jitter_t *jb, void *samples, int length) count = jb->extra_size - jb->extra_index; /* copy samples from packet to play out, increment sample pointer and decrement length */ #ifdef HEAVY_DEBUG - PDEBUG(DJITTER, DEBUG_DEBUG, "%s Copy data (offset=%u count=%u) from frame (sequence=%u timestamp=%u length=%u).\n", jb->name, index, count, jf->sequence, jf->timestamp, jf->length); + LOGP(DJITTER, LOGL_DEBUG, "%s Copy data (offset=%u count=%u) from frame (sequence=%u timestamp=%u length=%u).\n", jb->name, index, count, jf->sequence, jf->timestamp, jf->length); #endif memcpy(samples, (uint8_t *)jf->samples + index * jb->sample_size, count * jb->sample_size); samples = (uint8_t *)samples + count * jb->sample_size; diff --git a/src/liblogging/Makefile.am b/src/liblogging/Makefile.am new file mode 100644 index 0000000..a1b1e18 --- /dev/null +++ b/src/liblogging/Makefile.am @@ -0,0 +1,8 @@ +AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) + +noinst_LIBRARIES = liblogging.a + +liblogging_a_SOURCES = \ + logging.c \ + categories.c + diff --git a/src/liblogging/categories.c b/src/liblogging/categories.c new file mode 100644 index 0000000..b98a998 --- /dev/null +++ b/src/liblogging/categories.c @@ -0,0 +1,227 @@ + +#include <osmocom/core/utils.h> +#include <osmocom/core/logging.h> +#include "categories.h" + +/* All logging categories used by this project. */ + +struct log_info_cat log_categories[] = { + [DLCC] = { + .name = "DLCC", + .description = "libosmo-cc CC Layer", + .color = "\033[0;37m", + }, + [DOPTIONS] = { + .name = "DOPTIONS", + .description = "config options", + .color = "\033[0;33m", + }, + [DSENDER] = { + .name = "DSENDER", + .description = "transceiver instance", + .color = "\033[1;33m", + }, + [DSOUND] = { + .name = "DSOUND", + .description = "sound io", + .color = "\033[0;35m", + }, + [DDSP] = { + .name = "DDSP", + .description = "digital signal processing", + .color = "\033[0;31m", + }, + [DANETZ] = { + .name = "DANETZ", + .description = "A-Netz", + .color = "\033[1;34m", + }, + [DBNETZ] = { + .name = "DBNETZ", + .description = "B-Netz", + .color = "\033[1;34m", + }, + [DCNETZ] = { + .name = "DCNETZ", + .description = "C-Netz", + .color = "\033[1;34m", + }, + [DNMT] = { + .name = "DNMT", + .description = "Norisk Mobil Telefoni", + .color = "\033[1;34m", + }, + [DAMPS] = { + .name = "DAMPS", + .description = "Advanced Mobile Phone Service", + .color = "\033[1;34m", + }, + [DR2000] = { + .name = "DR2000", + .description = "Radiocom 2000", + .color = "\033[1;34m", + }, + [DIMTS] = { + .name = "DIMTS", + .description = "Improved Mobile Telephone Service", + .color = "\033[1;34m", + }, + [DMPT1327] = { + .name = "DMPT1327", + .description = "MPT-1327", + .color = "\033[1;34m", + }, + [DJOLLY] = { + .name = "DJOLLY", + .description = "Jolly-Com", + .color = "\033[1;34m", + }, + [DEURO] = { + .name = "DEUROSIGNAL", + .description = "Eurosignal", + .color = "\033[1;34m", + }, + [DPOCSAG] = { + .name = "DPOCSAG", + .description = "POCSAG", + .color = "\033[1;34m", + }, + [DGOLAY] = { + .name = "DGOLAY", + .description = "Golay", + .color = "\033[1;34m", + }, + [DFUENF] = { + .name = "DFUENF", + .description = "5-Ton-Folge", + .color = "\033[1;34m", + }, + [DFRAME] = { + .name = "DFRAME", + .description = "message frame", + .color = "\033[0;36m", + }, + [DCALL] = { + .name = "DCALL", + .description = "call processing", + .color = "\033[0;37m", + }, + [DDB] = { + .name = "DDB", + .description = "database access", + .color = "\033[0;33m", + }, + [DTRANS] = { + .name = "DTRANS", + .description = "transaction handing", + .color = "\033[0;32m", + }, + [DDMS] = { + .name = "DDMS", + .description = "DMS layer of NMT", + .color = "\033[0;33m", + }, + [DSMS] = { + .name = "DSMS", + .description = "SMS layer of NMT", + .color = "\033[1;37m", + }, + [DSDR] = { + .name = "DSDR", + .description = "Software Defined Radio", + .color = "\033[1;31m", + }, + [DUHD] = { + .name = "DUHD", + .description = "UHD interface", + .color = "\033[1;35m", + }, + [DSOAPY] = { + .name = "DSOAPY", + .description = "Soapy interface", + .color = "\033[1;35m", + }, + [DWAVE] = { + .name = "DWAVE", + .description = "WAVE file handling", + .color = "\033[1;33m", + }, + [DRADIO] = { + .name = "DRADIO", + .description = "Radio application", + .color = "\033[1;34m", + }, + [DAM791X] = { + .name = "DAM791X", + .description = "AM791x modem chip emulation", + .color = "\033[0;31m", + }, + [DUART] = { + .name = "DUART", + .description = "UART emulation", + .color = "\033[0;32m", + }, + [DDEVICE] = { + .name = "DDEVICE", + .description = "CUSE device emulation", + .color = "\033[0;33m", + }, + [DDATENKLO] = { + .name = "DDATENKLO", + .description = "Das Datenklo", + .color = "\033[1;34m", + }, + [DZEIT] = { + .name = "DZEIT", + .description = "Zeitansage", + .color = "\033[1;34m", + }, + [DSIM1] = { + .name = "DSIM1", + .description = "C-Netz SIM layer 1", + .color = "\033[0;31m", + }, + [DSIM2] = { + .name = "DSIM2", + .description = "C-Netz SIM layer 2", + .color = "\033[0;33m", + }, + [DSIMI] = { + .name = "DSIMI", + .description = "C-Netz SIM ICL layer", + .color = "\033[0;36m", + }, + [DSIM7] = { + .name = "DSIM7", + .description = "C-Netz SIM layer 7", + .color = "\033[0;37m", + }, + [DMTP2] = { + .name = "DMTP LAYER 2", + .description = "MTP layer 2", + .color = "\033[1;33m", + }, + [DMTP3] = { + .name = "DMTP LAYER 3", + .description = "MTP layer 3", + .color = "\033[1;36m", + }, + [DMUP] = { + .name = "DMUP", + .description = "C-Netz Mobile User Part", + .color = "\033[1;37m", + }, + [DDCF77] = { + .name = "DDCF77", + .description = "DCF77 Radio Clock", + .color = "\033[1;34m", + }, + [DJITTER] = { + .name = "DJITTER", + .description = "jitter buffer handling", + .color = "\033[0;36m", + }, +}; + +size_t log_categories_size = ARRAY_SIZE(log_categories); + diff --git a/src/liblogging/categories.h b/src/liblogging/categories.h new file mode 100644 index 0000000..c7ca7f8 --- /dev/null +++ b/src/liblogging/categories.h @@ -0,0 +1,50 @@ + +enum { + DLCC, + DOPTIONS, + DSENDER, + DSOUND, + DDSP, + DANETZ, + DBNETZ, + DCNETZ, + DNMT, + DAMPS, + DR2000, + DIMTS, + DMPT1327, + DJOLLY, + DEURO, + DPOCSAG, + DGOLAY, + DFUENF, + DFRAME, + DCALL, + DDB, + DTRANS, + DDMS, + DSMS, + DSDR, + DUHD, + DSOAPY, + DWAVE, + DRADIO, + DAM791X, + DUART, + DDEVICE, + DDATENKLO, + DZEIT, + DSIM1, + DSIM2, + DSIMI, + DSIM7, + DMTP2, + DMTP3, + DMUP, + DDCF77, + DJITTER, +}; + +extern struct log_info_cat log_categories[]; +extern size_t log_categories_size; + diff --git a/src/liblogging/logging.c b/src/liblogging/logging.c new file mode 100644 index 0000000..4268c06 --- /dev/null +++ b/src/liblogging/logging.c @@ -0,0 +1,264 @@ +/* Logging (on segmented part of the window) + * + * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> + * All Rights Reserved + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <sys/ioctl.h> +#include <math.h> +#include <errno.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/application.h> +#include <osmocom/cc/misc.h> +#include "logging.h" + +int loglevel = LOGL_INFO; + +static int scroll_window_start = 0; +static int scroll_window_end = 0; +static int scroll_window_height = 0; + +void lock_logging(void) +{ + log_tgt_mutex_lock(); +} + +void unlock_logging(void) +{ + log_tgt_mutex_unlock(); +} + +void get_win_size(int *w, int *h) +{ + struct winsize win; + int rc; + + rc = ioctl(0, TIOCGWINSZ, &win); + if (rc) { + *w = 80; + *h = 25; + return; + } + + if (h) + *h = win.ws_row; + if (w) + *w = win.ws_col; +} + +void enable_limit_scroll(bool enable) +{ + /* Before the window is set, keep scrolling everything. */ + if (scroll_window_height == 0) + return; + + /* If window is too small. */ + if (scroll_window_end - scroll_window_start <= 0) + return; + + if (enable) { + printf("\0337\033[%d;%dr\0338", scroll_window_start, scroll_window_end); + } else + printf("\0337\033[%d;%dr\0338", 1, scroll_window_height); + fflush(stdout); +} + +void logging_limit_scroll_top(int lines) +{ + lock_logging(); + + get_win_size(NULL, &scroll_window_height); + scroll_window_start = lines + 1; + if (scroll_window_end == 0) + scroll_window_end = scroll_window_height; + + enable_limit_scroll(true); + + unlock_logging(); +} + +void logging_limit_scroll_bottom(int lines) +{ + int i; + + lock_logging(); + + get_win_size(NULL, &scroll_window_height); + scroll_window_end = scroll_window_height - lines; + if (scroll_window_start == 0) + scroll_window_start = 1; + + /* Make space by adding empty lines. */ + for (i = scroll_window_end; i < scroll_window_height; i++) + printf("\n"); + /* Go up by number of lines to be in window. */ + printf("\033[%dA", scroll_window_height - scroll_window_end); + /* Enable window. */ + enable_limit_scroll(true); + + unlock_logging(); +} + +const char *debug_amplitude(double level) +{ + static char text[42]; + + strcpy(text, " : "); + if (level > 1.0) + level = 1.0; + if (level < -1.0) + level = -1.0; + text[20 + (int)(level * 20)] = '*'; + + return text; +} + +#define level2db(level) (20 * log10(level)) + +const char *debug_db(double level_db) +{ + static char text[128]; + int l; + + strcpy(text, ": . : . : . : . : . : . : . : . | . : . : . : . : . : . : . : . :"); + if (level_db <= 0.0) + return text; + l = (int)round(level2db(level_db)); + if (l > 48) + return text; + if (l < -48) + return text; + text[l + 48] = '*'; + + return text; +} + +void logging_print_help(void) +{ + printf(" -v --verbose <level> | <level>,<category>[,<category>[,...]] | list\n"); + printf(" Use 'list' to get a list of all levels and categories.\n"); + printf(" Verbose level: digit of debug level (default = '%d')\n", loglevel); + printf(" Verbose level+category: level digit followed by one or more categories\n"); + printf(" -> If no category is specified, all categories are selected\n"); + printf(" -v --verbose date\n"); + printf(" Show date with debug output\n"); +} + +static unsigned char log_levels[] = { LOGL_DEBUG, LOGL_INFO, LOGL_NOTICE, LOGL_ERROR }; +static char *log_level_names[] = { "debug", "info", "notice", "error" }; + +static void list_cat(void) +{ + int i; + + printf("Give number of debug level:\n"); + for (i = 0; i < (int)sizeof(log_levels); i++) + printf(" %d = %s\n", log_levels[i], log_level_names[i]); + printf("\n"); + + printf("Give name(s) of debug category:\n"); + for (i = 0; i < (int)log_categories_size; i++) { + if (!log_categories[i].name) + continue; + printf(" "); + if (log_categories[i].color) + printf("%s", log_categories[i].color); + if (log_categories[i].name) + printf("%s\033[0;39m = %s\n", log_categories[i].name, log_categories[i].description); + } + printf("\n"); +} + +int parse_logging_opt(const char *optarg) +{ + int i; + char *dup, *dstring, *p; + + if (!strcasecmp(optarg, "list")) { + list_cat(); + return 1; + } + + if (!strcasecmp(optarg, "date")) { + log_set_print_timestamp(osmo_stderr_target, 1); + return 0; + } + + dup = dstring = strdup(optarg); + p = strsep(&dstring, ","); + for (i = 0; i < p[i]; i++) { + if (p[i] < '0' || p[i] > '9') { + fprintf(stderr, "Only digits are allowed for debug level!\n"); + free(dup); + return -EINVAL; + } + } + loglevel = atoi(p); + for (i = 0; i < (int)sizeof(log_levels); i++) { + if (log_levels[i] == loglevel) + break; + } + if (i == (int)sizeof(log_levels)) { + fprintf(stderr, "Logging level does not exist, use '-v list' to show available levels!\n"); + free(dup); + return -EINVAL; + } + /* Set loglevel and enable all categories, if dstring is not set. Else set loglevel and disable all categories. */ + for (i = 0; i < (int)log_categories_size; i++) + log_set_category_filter(osmo_stderr_target, i, (!dstring), loglevel); + /* Enable each given category. */ + while((p = strsep(&dstring, ","))) { + for (i = 0; i < (int)log_categories_size; i++) { + if (!log_category_name(i)) + continue; + if (!strcasecmp(p, log_category_name(i))) + break; + } + if (i == (int)log_categories_size) { + fprintf(stderr, "Given logging category '%s' unknown, use '-v list' to show available categories!\n", p); + free(dup); + return -EINVAL; + } + log_set_category_filter(osmo_stderr_target, i, 1, loglevel); + } + + free(dup); + return 0; +} + +/* Call after configuation above. */ +void logging_init(void) +{ + int i; + + struct log_info log_info = { + .cat = log_categories, + .num_cat = log_categories_size, + }; + + osmo_cc_set_log_cat(DLCC); + + osmo_init_logging2(NULL, &log_info); + log_set_print_timestamp(osmo_stderr_target, 0); + log_set_print_level(osmo_stderr_target, 1); + log_set_print_category_hex(osmo_stderr_target, 0); + log_set_print_category(osmo_stderr_target, 1); + + /* Set loglevel and enable all categories. */ + for (i = 0; i < (int)log_categories_size; i++) + log_set_category_filter(osmo_stderr_target, i, 1, loglevel); +} + diff --git a/src/liblogging/logging.h b/src/liblogging/logging.h new file mode 100644 index 0000000..67f1434 --- /dev/null +++ b/src/liblogging/logging.h @@ -0,0 +1,21 @@ +#pragma once + +#include <osmocom/core/logging.h> +#include "categories.h" + +extern int loglevel; + +#define LOGP_CHAN(cat, level, fmt, arg...) LOGP(cat, level, "(chan %s) " fmt, CHAN, ## arg) + +void get_win_size(int *w, int *h); +void lock_logging(void); +void unlock_logging(void); +void enable_limit_scroll(bool enable); +void logging_limit_scroll_top(int lines); +void logging_limit_scroll_bottom(int lines); +const char *debug_amplitude(double level); +const char *debug_db(double level_db); +void logging_print_help(void); +int parse_logging_opt(const char *optarg); +void logging_init(void); + diff --git a/src/libmobile/Makefile.am b/src/libmobile/Makefile.am index 2f03688..28c7f42 100644 --- a/src/libmobile/Makefile.am +++ b/src/libmobile/Makefile.am @@ -8,6 +8,7 @@ libmobile_a_SOURCES = \ console.c \ testton.c \ cause.c \ + get_time.c \ main_mobile.c if HAVE_ALSA diff --git a/src/libmobile/call.c b/src/libmobile/call.c index 853a628..d12e5ca 100644 --- a/src/libmobile/call.c +++ b/src/libmobile/call.c @@ -26,19 +26,20 @@ #include <sys/time.h> #include <arpa/inet.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libosmocc/endpoint.h" -#include "../libosmocc/helper.h" -#include "../libg711/g711.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> +#include <osmocom/core/select.h> +#include <osmocom/cc/endpoint.h> +#include <osmocom/cc/helper.h> +#include <osmocom/cc/g711.h> +#include <osmocom/cc/rtp.h> #include "cause.h" #include "sender.h" #include "call.h" #include "main_mobile.h" #include "console.h" -#define DISC_TIMEOUT 30 +#define DISC_TIMEOUT 30, 0 //#define DEBUG_LEVEL @@ -254,7 +255,7 @@ typedef struct process { enum audio_pattern pattern; int audio_pos; uint8_t cause; - struct timer timer; + struct osmo_timer_list timer; osmo_cc_session_t *session; osmo_cc_session_codec_t *codec; /* codec to send */ } process_t; @@ -270,10 +271,10 @@ static process_t *create_process(int callref, enum process_state state) process = calloc(sizeof(*process), 1); if (!process) { - PDEBUG(DCALL, DEBUG_ERROR, "No memory!\n"); + LOGP(DCALL, LOGL_ERROR, "No memory!\n"); abort(); } - timer_init(&process->timer, process_timeout, process); + osmo_timer_setup(&process->timer, process_timeout, process); process->next = process_head; process_head = process; @@ -291,7 +292,7 @@ static void destroy_process(int callref) while (process) { if (process->callref == callref) { *process_p = process->next; - timer_exit(&process->timer); + osmo_timer_del(&process->timer); if (process->session) osmo_cc_free_session(process->session); free(process); @@ -300,7 +301,7 @@ static void destroy_process(int callref) process_p = &process->next; process = process->next; } - PDEBUG(DCALL, DEBUG_ERROR, "Process with callref %d not found!\n", callref); + LOGP(DCALL, LOGL_ERROR, "Process with callref %d not found!\n", callref); } static process_t *get_process(int callref) @@ -320,10 +321,10 @@ static void new_state_process(int callref, enum process_state state) process_t *process = get_process(callref); if (!process) { - PDEBUG(DCALL, DEBUG_ERROR, "Process with callref %d not found!\n", callref); + LOGP(DCALL, LOGL_ERROR, "Process with callref %d not found!\n", callref); return; } - PDEBUG(DCALL, DEBUG_DEBUG, "Changing state for callref %d %d->%d\n", callref, process->state, state); + LOGP(DCALL, LOGL_DEBUG, "Changing state for callref %d %d->%d\n", callref, process->state, state); process->state = state; } @@ -332,7 +333,7 @@ static void set_pattern_process(int callref, enum audio_pattern pattern) process_t *process = get_process(callref); if (!process) { - PDEBUG(DCALL, DEBUG_ERROR, "Process with callref %d not found!\n", callref); + LOGP(DCALL, LOGL_ERROR, "Process with callref %d not found!\n", callref); return; } process->pattern = pattern; @@ -345,14 +346,14 @@ static void disconnect_process(int callref, int cause) process_t *process = get_process(callref); if (!process) { - PDEBUG(DCALL, DEBUG_ERROR, "Process with callref %d not found!\n", callref); + LOGP(DCALL, LOGL_ERROR, "Process with callref %d not found!\n", callref); return; } process->pattern = cause2pattern(cause); process->audio_disconnected = 1; process->audio_pos = 0; process->cause = cause; - timer_start(&process->timer, DISC_TIMEOUT); + osmo_timer_schedule(&process->timer, DISC_TIMEOUT); } static void get_process_patterns(process_t *process, int16_t *samples, int length) @@ -382,7 +383,7 @@ static void process_timeout(void *data) { /* announcement timeout */ if (process->state == PROCESS_DISCONNECT) { - PDEBUG(DCALL, DEBUG_INFO, "Call released toward mobile network (after timeout)\n"); + LOGP(DCALL, LOGL_INFO, "Call released toward mobile network (after timeout)\n"); call_down_release(process->callref, process->cause); } indicate_disconnect_release(process->callref, process->cause, OSMO_CC_MSG_REL_IND); @@ -425,7 +426,7 @@ static void indicate_setup(process_t *process, const char *callerid, const char /* sdp offer */ process->session = osmo_cc_helper_audio_offer(&ep->session_config, process, codecs + no_l16, down_audio, msg, 1); - PDEBUG(DCALL, DEBUG_INFO, "Indicate OSMO-CC setup towards fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Indicate OSMO-CC setup towards fixed network\n"); osmo_cc_ll_msg(ep, process->callref, msg); } @@ -441,7 +442,7 @@ static void indicate_proceeding(int callref, const char *sdp) /* progress information */ osmo_cc_add_ie_progress(msg, OSMO_CC_CODING_ITU_T, OSMO_CC_LOCATION_BEYOND_INTERWORKING, OSMO_CC_PROGRESS_INBAND_INFO_AVAILABLE); - PDEBUG(DCALL, DEBUG_INFO, "Indicate OSMO-CC call confirm towards fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Indicate OSMO-CC call confirm towards fixed network\n"); osmo_cc_ll_msg(ep, callref, msg); } @@ -451,7 +452,7 @@ static void indicate_alerting(int callref) msg = osmo_cc_new_msg(OSMO_CC_MSG_ALERT_IND); - PDEBUG(DCALL, DEBUG_INFO, "Indicate OSMO-CC alerting towards fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Indicate OSMO-CC alerting towards fixed network\n"); osmo_cc_ll_msg(ep, callref, msg); } @@ -468,7 +469,7 @@ static void indicate_answer(int callref, const char *sdp, const char *connectid) if (sdp) osmo_cc_add_ie_sdp(msg, sdp); - PDEBUG(DCALL, DEBUG_INFO, "Indicate OSMO-CC answer towards fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Indicate OSMO-CC answer towards fixed network\n"); osmo_cc_ll_msg(ep, callref, msg); } @@ -478,7 +479,7 @@ static void indicate_answer_ack(int callref) msg = osmo_cc_new_msg(OSMO_CC_MSG_SETUP_COMP_IND); - PDEBUG(DCALL, DEBUG_INFO, "Indicate OSMO-CC setup complete towards fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Indicate OSMO-CC setup complete towards fixed network\n"); osmo_cc_ll_msg(ep, callref, msg); } @@ -495,7 +496,7 @@ static void indicate_disconnect_release(int callref, int cause, uint8_t msg_type if (msg_type == OSMO_CC_MSG_DISC_IND) osmo_cc_add_ie_progress(msg, OSMO_CC_CODING_ITU_T, OSMO_CC_LOCATION_BEYOND_INTERWORKING, OSMO_CC_PROGRESS_INBAND_INFO_AVAILABLE); - PDEBUG(DCALL, DEBUG_INFO, "%s OSMO-CC %s towards fixed network\n", (msg_type == OSMO_CC_MSG_REL_CNF) ? "Confirm" : "Indicated", (msg_type == OSMO_CC_MSG_DISC_IND) ? "disconnect" : "release"); + LOGP(DCALL, LOGL_INFO, "%s OSMO-CC %s towards fixed network\n", (msg_type == OSMO_CC_MSG_REL_CNF) ? "Confirm" : "Indicated", (msg_type == OSMO_CC_MSG_DISC_IND) ? "disconnect" : "release"); osmo_cc_ll_msg(ep, callref, msg); } @@ -505,9 +506,9 @@ int call_up_setup(const char *callerid, const char *dialing, uint8_t network, co osmo_cc_call_t *call; process_t *process; - PDEBUG(DCALL, DEBUG_INFO, "Incoming call from '%s' to '%s'\n", callerid ? : "unknown", dialing); + LOGP(DCALL, LOGL_INFO, "Incoming call from '%s' to '%s'\n", callerid ? : "unknown", dialing); if (!strcmp(dialing, "010")) - PDEBUG(DCALL, DEBUG_INFO, " -> Call to Operator '%s'\n", dialing); + LOGP(DCALL, LOGL_INFO, " -> Call to Operator '%s'\n", dialing); call = osmo_cc_call_new(ep); @@ -522,11 +523,11 @@ int call_up_setup(const char *callerid, const char *dialing, uint8_t network, co void call_up_alerting(int callref) { if (!callref) { - PDEBUG(DCALL, DEBUG_DEBUG, "Ignoring alerting, because callref not set. (not for us)\n"); + LOGP(DCALL, LOGL_DEBUG, "Ignoring alerting, because callref not set. (not for us)\n"); return; } - PDEBUG(DCALL, DEBUG_INFO, "Call is alerting\n"); + LOGP(DCALL, LOGL_INFO, "Call is alerting\n"); if (!connect_on_setup) indicate_alerting(callref); @@ -544,11 +545,11 @@ void call_up_early(int callref) void call_up_answer(int callref, const char *connect_id) { if (!callref) { - PDEBUG(DCALL, DEBUG_DEBUG, "Ignoring answer, because callref not set. (not for us)\n"); + LOGP(DCALL, LOGL_DEBUG, "Ignoring answer, because callref not set. (not for us)\n"); return; } - PDEBUG(DCALL, DEBUG_INFO, "Call has been answered by '%s'\n", connect_id); + LOGP(DCALL, LOGL_INFO, "Call has been answered by '%s'\n", connect_id); if (!connect_on_setup) indicate_answer(callref, NULL, connect_id); @@ -562,11 +563,11 @@ void call_up_release(int callref, int cause) process_t *process; if (!callref) { - PDEBUG(DCALL, DEBUG_DEBUG, "Ignoring release, because callref not set. (not for us)\n"); + LOGP(DCALL, LOGL_DEBUG, "Ignoring release, because callref not set. (not for us)\n"); return; } - PDEBUG(DCALL, DEBUG_INFO, "Call has been released with cause=%d\n", cause); + LOGP(DCALL, LOGL_INFO, "Call has been released with cause=%d\n", cause); process = get_process(callref); if (process) { @@ -673,7 +674,7 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, else { /* release collisions is not forbidden */ if (msg->type != OSMO_CC_MSG_REL_REQ) - PDEBUG(DCALL, DEBUG_ERROR, "No process!\n"); + LOGP(DCALL, LOGL_ERROR, "No process!\n"); osmo_cc_free_msg(msg); return; } @@ -685,8 +686,8 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, rc = osmo_cc_get_ie_cause(msg, 0, &location, &isdn_cause, &sip_cause, &socket_cause); if (rc < 0) isdn_cause = OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR; - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC disconnect from fixed network with cause %d\n", isdn_cause); - PDEBUG(DCALL, DEBUG_INFO, "Call disconnected, releasing!\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC disconnect from fixed network with cause %d\n", isdn_cause); + LOGP(DCALL, LOGL_INFO, "Call disconnected, releasing!\n"); destroy_process(callref); indicate_disconnect_release(callref, isdn_cause, OSMO_CC_MSG_REL_IND); break; @@ -694,8 +695,8 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, rc = osmo_cc_get_ie_cause(msg, 0, &location, &isdn_cause, &sip_cause, &socket_cause); if (rc < 0) isdn_cause = OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR; - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC release from fixed network with cause %d\n", isdn_cause); - PDEBUG(DCALL, DEBUG_INFO, "Call released\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC release from fixed network with cause %d\n", isdn_cause); + LOGP(DCALL, LOGL_INFO, "Call released\n"); destroy_process(callref); indicate_disconnect_release(callref, isdn_cause, OSMO_CC_MSG_REL_CNF); break; @@ -744,14 +745,14 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, rc = osmo_cc_get_ie_called(msg, 0, &type, &plan, number, sizeof(number)); if (rc < 0) number[0] = '\0'; - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC call from fixed network '%s' to mobile '%s'\n", caller_id, number); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC call from fixed network '%s' to mobile '%s'\n", caller_id, number); if (!connect_on_setup) indicate_proceeding(callref, sdp); else { - PDEBUG(DCALL, DEBUG_DEBUG, "Early connecting after setup\n"); + LOGP(DCALL, LOGL_DEBUG, "Early connecting after setup\n"); indicate_answer(callref, sdp, number); } - PDEBUG(DCALL, DEBUG_INFO, "Outgoing call from '%s' to '%s'\n", caller_id, number); + LOGP(DCALL, LOGL_INFO, "Outgoing call from '%s' to '%s'\n", caller_id, number); /* insert '+' for international dialing */ if (type == OSMO_CC_TYPE_INTERNATIONAL && number[0] != '+') { @@ -765,10 +766,10 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, /* check suffix length */ invalid = mobile_number_check_length(suffix); if (invalid) { - PDEBUG(DCALL, DEBUG_NOTICE, "Mobile number '%s' has invalid length: %s\n", suffix, invalid); + LOGP(DCALL, LOGL_NOTICE, "Mobile number '%s' has invalid length: %s\n", suffix, invalid); disconnect_process(callref, OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); if (!connect_on_setup) { - PDEBUG(DCALL, DEBUG_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); + LOGP(DCALL, LOGL_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); indicate_disconnect_release(callref, OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT, OSMO_CC_MSG_DISC_IND); } break; @@ -777,10 +778,10 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, /* check suffix digits */ invalid = mobile_number_check_digits(suffix); if (invalid) { - PDEBUG(DCALL, DEBUG_NOTICE, "Mobile number '%s' has invalid digit: %s.\n", suffix, invalid); + LOGP(DCALL, LOGL_NOTICE, "Mobile number '%s' has invalid digit: %s.\n", suffix, invalid); disconnect_process(callref, OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); if (!connect_on_setup) { - PDEBUG(DCALL, DEBUG_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); + LOGP(DCALL, LOGL_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); indicate_disconnect_release(callref, OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT, OSMO_CC_MSG_DISC_IND); } break; @@ -790,10 +791,10 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, if (mobile_number_check_valid) { invalid = mobile_number_check_valid(suffix); if (invalid) { - PDEBUG(DCALL, DEBUG_NOTICE, "Mobile number '%s' is invalid for this network: %s\n", suffix, invalid); + LOGP(DCALL, LOGL_NOTICE, "Mobile number '%s' is invalid for this network: %s\n", suffix, invalid); disconnect_process(callref, OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); if (!connect_on_setup) { - PDEBUG(DCALL, DEBUG_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); + LOGP(DCALL, LOGL_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT); indicate_disconnect_release(callref, OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT, OSMO_CC_MSG_DISC_IND); } break; @@ -803,9 +804,9 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, /* setup call */ rc = call_down_setup(callref, caller_id, caller_type, suffix); if (rc < 0) { - PDEBUG(DCALL, DEBUG_NOTICE, "Call rejected, cause %d\n", -rc); + LOGP(DCALL, LOGL_NOTICE, "Call rejected, cause %d\n", -rc); if (!connect_on_setup) { - PDEBUG(DCALL, DEBUG_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", -rc); + LOGP(DCALL, LOGL_INFO, "Disconnecting OSMO-CC call towards fixed network (cause=%d)\n", -rc); indicate_disconnect_release(callref, -rc, OSMO_CC_MSG_DISC_IND); } disconnect_process(callref, -rc); @@ -814,44 +815,44 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, break; } case OSMO_CC_MSG_SETUP_ACK_REQ: - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC overlap from fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC overlap from fixed network\n"); rc = osmo_cc_helper_audio_negotiate(msg, &process->session, &process->codec); if (rc < 0) { nego_failed: - PDEBUG(DCALL, DEBUG_INFO, "Releasing, because codec negotiation failed.\n"); + LOGP(DCALL, LOGL_INFO, "Releasing, because codec negotiation failed.\n"); destroy_process(callref); indicate_disconnect_release(callref, 47, OSMO_CC_MSG_REL_IND); - PDEBUG(DCALL, DEBUG_INFO, "Call released toward mobile network\n"); + LOGP(DCALL, LOGL_INFO, "Call released toward mobile network\n"); call_down_release(callref, 47); break; } break; case OSMO_CC_MSG_PROC_REQ: - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC proceeding from fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC proceeding from fixed network\n"); rc = osmo_cc_helper_audio_negotiate(msg, &process->session, &process->codec); if (rc < 0) goto nego_failed; break; case OSMO_CC_MSG_PROGRESS_REQ: - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC progress from fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC progress from fixed network\n"); rc = osmo_cc_helper_audio_negotiate(msg, &process->session, &process->codec); if (rc < 0) goto nego_failed; break; case OSMO_CC_MSG_ALERT_REQ: - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC alerting from fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC alerting from fixed network\n"); rc = osmo_cc_helper_audio_negotiate(msg, &process->session, &process->codec); if (rc < 0) goto nego_failed; new_state_process(callref, PROCESS_ALERTING_RO); break; case OSMO_CC_MSG_SETUP_RSP: - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC answer from fixed network\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC answer from fixed network\n"); rc = osmo_cc_helper_audio_negotiate(msg, &process->session, &process->codec); if (rc < 0) goto nego_failed; new_state_process(callref, PROCESS_CONNECT); - PDEBUG(DCALL, DEBUG_INFO, "Call answered\n"); + LOGP(DCALL, LOGL_INFO, "Call answered\n"); call_down_answer(callref); indicate_answer_ack(callref); break; @@ -865,22 +866,22 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, rc = osmo_cc_get_ie_progress(msg, 0, &coding, &location, &progress); if (rc < 0) progress = 0; - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC disconnect from fixed network with cause %d\n", isdn_cause); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC disconnect from fixed network with cause %d\n", isdn_cause); if (release_on_disconnect || (progress != 1 && progress != 8)) { - PDEBUG(DCALL, DEBUG_INFO, "Releasing, because we don't send disconnect tones to mobile phone\n"); + LOGP(DCALL, LOGL_INFO, "Releasing, because we don't send disconnect tones to mobile phone\n"); destroy_process(callref); indicate_disconnect_release(callref, isdn_cause, OSMO_CC_MSG_REL_IND); - PDEBUG(DCALL, DEBUG_INFO, "Call released toward mobile network\n"); + LOGP(DCALL, LOGL_INFO, "Call released toward mobile network\n"); call_down_release(callref, isdn_cause); break; } new_state_process(callref, PROCESS_DISCONNECT); - PDEBUG(DCALL, DEBUG_INFO, "Call disconnected\n"); + LOGP(DCALL, LOGL_INFO, "Call disconnected\n"); call_down_disconnect(callref, isdn_cause); /* we might get released during disconnect handling!!! */ process = get_process(callref); if (process && process->state == PROCESS_DISCONNECT) - timer_start(&process->timer, DISC_TIMEOUT); + osmo_timer_schedule(&process->timer, DISC_TIMEOUT); break; case OSMO_CC_MSG_REJ_REQ: case OSMO_CC_MSG_REL_REQ: @@ -889,11 +890,11 @@ void ll_msg_cb(osmo_cc_endpoint_t __attribute__((unused)) *ep, uint32_t callref, isdn_cause = OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR; destroy_process(callref); if (msg->type == OSMO_CC_MSG_REL_REQ) { - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC release from fixed network with cause %d\n", isdn_cause); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC release from fixed network with cause %d\n", isdn_cause); indicate_disconnect_release(callref, isdn_cause, OSMO_CC_MSG_REL_CNF); } else - PDEBUG(DCALL, DEBUG_INFO, "Received OSMO-CC reject from fixed network with cause %d\n", isdn_cause); - PDEBUG(DCALL, DEBUG_INFO, "Call released toward mobile network\n"); + LOGP(DCALL, LOGL_INFO, "Received OSMO-CC reject from fixed network with cause %d\n", isdn_cause); + LOGP(DCALL, LOGL_INFO, "Call released toward mobile network\n"); call_down_release(callref, isdn_cause); break; } diff --git a/src/libmobile/console.c b/src/libmobile/console.c index 9526e21..a21f3fa 100755 --- a/src/libmobile/console.c +++ b/src/libmobile/console.c @@ -24,14 +24,16 @@ #include <stdlib.h> #include <errno.h> #include <sys/time.h> +#include <sys/param.h> #include "../libsample/sample.h" #include "../libsamplerate/samplerate.h" #include "../libjitter/jitter.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libosmocc/endpoint.h" -#include "../libosmocc/helper.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> +#include <osmocom/core/select.h> +#include <osmocom/cc/endpoint.h> +#include <osmocom/cc/helper.h> +#include <osmocom/cc/rtp.h> #include "testton.h" #include "../libmobile/main_mobile.h" #include "console.h" @@ -127,7 +129,7 @@ static void get_test_patterns(int16_t *samples, int length) static void console_new_state(enum console_state state) { - PDEBUG(DCC, DEBUG_DEBUG, "Call state '%s' -> '%s'\n", console_state_name[console.state], console_state_name[state]); + LOGP(DCALL, LOGL_DEBUG, "Call state '%s' -> '%s'\n", console_state_name[console.state], console_state_name[state]); console.state = state; console.test_audio_pos = 0; } @@ -227,7 +229,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) int rc; if (msg->type != OSMO_CC_MSG_SETUP_IND && console.callref != call->callref) { - PDEBUG(DCC, DEBUG_ERROR, "invalid call ref %u (msg=0x%02x).\n", call->callref, msg->type); + LOGP(DCALL, LOGL_ERROR, "invalid call ref %u (msg=0x%02x).\n", call->callref, msg->type); request_disconnect_release_reject(call->callref, CAUSE_INVALCALLREF, OSMO_CC_MSG_REL_REQ); osmo_cc_free_msg(msg); return; @@ -244,10 +246,10 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) rc = osmo_cc_get_ie_called(msg, 0, &type, &plan, number, sizeof(number)); if (rc < 0) number[0] = '\0'; - PDEBUG(DCC, DEBUG_INFO, "Incoming call from '%s'\n", caller_id); + LOGP(DCALL, LOGL_INFO, "Incoming call from '%s'\n", caller_id); /* setup is also allowed on disconnected call */ if (console.state == CONSOLE_DISCONNECT_RO) { - PDEBUG(DCC, DEBUG_INFO, "Releasing pending disconnected call\n"); + LOGP(DCALL, LOGL_INFO, "Releasing pending disconnected call\n"); if (console.callref) { request_disconnect_release_reject(console.callref, CAUSE_NORMAL, OSMO_CC_MSG_REL_REQ); free_console(); @@ -255,7 +257,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) console_new_state(CONSOLE_IDLE); } if (console.state != CONSOLE_IDLE) { - PDEBUG(DCC, DEBUG_NOTICE, "We are busy, rejecting.\n"); + LOGP(DCALL, LOGL_NOTICE, "We are busy, rejecting.\n"); request_disconnect_release_reject(console.callref, CAUSE_NORMAL, OSMO_CC_MSG_REJ_REQ); osmo_cc_free_msg(msg); return; @@ -264,7 +266,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) /* sdp accept */ sdp = osmo_cc_helper_audio_accept(&ep->session_config, NULL, codecs, up_audio, msg, &console.session, &console.codec, 0); if (!sdp) { - PDEBUG(DCC, DEBUG_NOTICE, "Cannot accept codec, rejecting.\n"); + LOGP(DCALL, LOGL_NOTICE, "Cannot accept codec, rejecting.\n"); request_disconnect_release_reject(console.callref, CAUSE_RESOURCE_UNAVAIL, OSMO_CC_MSG_REJ_REQ); osmo_cc_free_msg(msg); return; @@ -276,7 +278,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) strncpy(console.dialing, number, sizeof(console.dialing) - 1); console.dialing[sizeof(console.dialing) - 1] = '\0'; console_new_state(CONSOLE_CONNECT); - PDEBUG(DCC, DEBUG_INFO, "Call automatically answered\n"); + LOGP(DCALL, LOGL_INFO, "Call automatically answered\n"); request_answer(console.callref, number, sdp); break; } @@ -285,7 +287,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) osmo_cc_helper_audio_negotiate(msg, &console.session, &console.codec); break; case OSMO_CC_MSG_ALERT_IND: - PDEBUG(DCC, DEBUG_INFO, "Call alerting\n"); + LOGP(DCALL, LOGL_INFO, "Call alerting\n"); osmo_cc_helper_audio_negotiate(msg, &console.session, &console.codec); console_new_state(CONSOLE_ALERTING_RT); break; @@ -295,7 +297,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) rc = osmo_cc_get_ie_calling(msg, 0, &type, &plan, &present, &screen, caller_id, sizeof(caller_id)); if (rc < 0) caller_id[0] = '\0'; - PDEBUG(DCC, DEBUG_INFO, "Call connected to '%s'\n", caller_id); + LOGP(DCALL, LOGL_INFO, "Call connected to '%s'\n", caller_id); osmo_cc_helper_audio_negotiate(msg, &console.session, &console.codec); console_new_state(CONSOLE_CONNECT); if (caller_id[0]) { @@ -314,11 +316,11 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) rc = osmo_cc_get_ie_progress(msg, 0, &coding, &location, &progress); osmo_cc_helper_audio_negotiate(msg, &console.session, &console.codec); if (rc >= 0 && (progress == 1 || progress == 8)) { - PDEBUG(DCC, DEBUG_INFO, "Call disconnected with audio (%s)\n", cause_name(isdn_cause)); + LOGP(DCALL, LOGL_INFO, "Call disconnected with audio (%s)\n", cause_name(isdn_cause)); console_new_state(CONSOLE_DISCONNECT_RO); console.disc_cause = isdn_cause; } else { - PDEBUG(DCC, DEBUG_INFO, "Call disconnected without audio (%s)\n", cause_name(isdn_cause)); + LOGP(DCALL, LOGL_INFO, "Call disconnected without audio (%s)\n", cause_name(isdn_cause)); request_disconnect_release_reject(console.callref, isdn_cause, OSMO_CC_MSG_REL_REQ); console_new_state(CONSOLE_IDLE); free_console(); @@ -329,7 +331,7 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) rc = osmo_cc_get_ie_cause(msg, 0, &location, &isdn_cause, &sip_cause, &socket_cause); if (rc < 0) isdn_cause = OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR; - PDEBUG(DCC, DEBUG_INFO, "Call released (%s)\n", cause_name(isdn_cause)); + LOGP(DCALL, LOGL_INFO, "Call released (%s)\n", cause_name(isdn_cause)); console_new_state(CONSOLE_IDLE); free_console(); break; @@ -338,29 +340,8 @@ void console_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) } static char console_text[256]; -static char console_clear[256]; static int console_len = 0; -static void _clear_console_text(void) -{ - if (!console_len) - return; - - fwrite(console_clear, console_len, 1, stdout); - // note: fflused by user of this function - console_len = 0; -} - -static void _print_console_text(void) -{ - if (!console_len) - return; - - printf("\033[1;37m"); - fwrite(console_text, console_len, 1, stdout); - printf("\033[0;39m"); -} - int console_init(const char *audiodev, int samplerate, int buffer, int loopback, int echo_test, const char *digits, const struct number_lengths *lengths, const char *station_id) { int rc = 0; @@ -368,8 +349,8 @@ int console_init(const char *audiodev, int samplerate, int buffer, int loopback, init_testton(); - clear_console_text = _clear_console_text; - print_console_text = _print_console_text; + /* Put scrolling window one line above bottom. */ + logging_limit_scroll_bottom(1); memset(&console, 0, sizeof(console)); strncpy(console.audiodev, audiodev, sizeof(console.audiodev) - 1); @@ -393,13 +374,13 @@ int console_init(const char *audiodev, int samplerate, int buffer, int loopback, rc = init_samplerate(&console.srstate, 8000.0, (double)samplerate, 3300.0); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to init sample rate conversion!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to init sample rate conversion!\n"); goto error; } rc = jitter_create(&console.dejitter, "console", 8000, sizeof(sample_t), 0.050, 0.200, JITTER_FLAG_NONE); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create and init dejitter buffer!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create and init dejitter buffer!\n"); goto error; } @@ -420,11 +401,11 @@ int console_open_audio(int __attribute__((unused)) buffer_size, double __attribu /* use factor 1.4 of speech level for complete range of sound card */ console.sound = sound_open(console.audiodev, NULL, NULL, NULL, 1, 0.0, console.samplerate, buffer_size, interval, 1.4, 4000.0, 2.0); if (!console.sound) { - PDEBUG(DSENDER, DEBUG_ERROR, "No sound device!\n"); + LOGP(DSENDER, LOGL_ERROR, "No sound device!\n"); return -EIO; } #else - PDEBUG(DSENDER, DEBUG_ERROR, "No sound card support compiled in!\n"); + LOGP(DSENDER, LOGL_ERROR, "No sound card support compiled in!\n"); return -ENOTSUP; #endif @@ -468,7 +449,7 @@ void console_cleanup(void) static void process_ui(int c) { char text[256] = ""; - int len; + int len, w, h; int i; switch (console.state) { @@ -491,7 +472,7 @@ dial_after_hangup: break; } if (c == 'd' && console.number_lengths[i].usage) { - PDEBUG(DCC, DEBUG_INFO, "Outgoing call to '%s'\n", console.station_id); + LOGP(DCALL, LOGL_INFO, "Outgoing call to '%s'\n", console.station_id); console.dialing[0] = '\0'; console_new_state(CONSOLE_SETUP_RT); console.callref = osmo_cc_new_callref(); @@ -506,11 +487,11 @@ dial_after_hangup: } if (console.number_lengths[i].usage) { if (console.number_lengths[i + 1].usage) - sprintf(strchr(text, '\0'), "(enter digits %s or press d=dial)\r", console.digits); + sprintf(strchr(text, '\0'), "(enter digits %s or press d=dial)", console.digits); else - sprintf(strchr(text, '\0'), "(press d=dial)\r"); + sprintf(strchr(text, '\0'), "(press d=dial)"); } else - sprintf(strchr(text, '\0'), "(enter digits %s)\r", console.digits); + sprintf(strchr(text, '\0'), "(enter digits %s)", console.digits); break; case CONSOLE_SETUP_RO: case CONSOLE_SETUP_RT: @@ -520,7 +501,7 @@ dial_after_hangup: case CONSOLE_DISCONNECT_RO: if (c > 0) { if (c == 'h' || (c == 'd' && console.state == CONSOLE_DISCONNECT_RO)) { - PDEBUG(DCC, DEBUG_INFO, "Call hangup\n"); + LOGP(DCALL, LOGL_INFO, "Call hangup\n"); if (console.callref) { if (console.state == CONSOLE_SETUP_RO) request_disconnect_release_reject(console.callref, CAUSE_NORMAL, OSMO_CC_MSG_REJ_REQ); @@ -534,32 +515,46 @@ dial_after_hangup: } } if (console.state == CONSOLE_SETUP_RT) - sprintf(text, "call setup: %s (press h=hangup)\r", console.station_id); + sprintf(text, "call setup: %s (press h=hangup)", console.station_id); if (console.state == CONSOLE_ALERTING_RT) - sprintf(text, "call ringing: %s (press h=hangup)\r", console.station_id); + sprintf(text, "call ringing: %s (press h=hangup)", console.station_id); if (console.state == CONSOLE_CONNECT) { if (console.dialing[0]) - sprintf(text, "call active: %s->%s (press h=hangup)\r", console.station_id, console.dialing); + sprintf(text, "call active: %s->%s (press h=hangup)", console.station_id, console.dialing); else - sprintf(text, "call active: %s (press h=hangup)\r", console.station_id); + sprintf(text, "call active: %s (press h=hangup)", console.station_id); } if (console.state == CONSOLE_DISCONNECT_RO) - sprintf(text, "call disconnected: %s (press h=hangup d=redial)\r", cause_name(console.disc_cause)); + sprintf(text, "call disconnected: %s (press h=hangup d=redial)", cause_name(console.disc_cause)); break; } /* skip if nothing has changed */ len = strlen(text); if (console_len == len && !memcmp(console_text, text, len)) return; - clear_console_text(); + /* lock logging */ + lock_logging(); + /* disable window */ + enable_limit_scroll(false); + /* geht height */ + get_win_size(&w, &h); + /* save cursor go to bottom, use white color */ + printf("\0337\033[%d;1H\033[1;37m", h); + /* copy text and pad with spaces */ console_len = len; - memcpy(console_text, text, len); - if (len) { - memset(console_clear, ' ', len - 1); - console_clear[len - 1] = '\r'; - } - print_console_text(); + memcpy(console_text, text, console_len); + if (console_len < (int)MIN(sizeof(console_text), w)) + memset(console_text + console_len, ' ', MIN(sizeof(console_text), w) - console_len); + /* write text */ + fwrite(console_text, MIN(sizeof(console_text), w), 1, stdout); + /* reset color, go back to previous line, flush */ + printf("\033[0;39m\0338"); + /* flush output */ fflush(stdout); + /* enable window */ + enable_limit_scroll(true); + /* unlock logging */ + unlock_logging(); } /* get keys from keyboard to control call via console @@ -581,9 +576,9 @@ void process_console(int c) count = sound_get_tosend(console.sound, console.buffer_size); if (count < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to get samples in buffer (rc = %d)!\n", count); + LOGP(DSENDER, LOGL_ERROR, "Failed to get samples in buffer (rc = %d)!\n", count); if (count == -EPIPE) - PDEBUG(DSENDER, DEBUG_ERROR, "Trying to recover.\n"); + LOGP(DSENDER, LOGL_ERROR, "Trying to recover.\n"); return; } if (count > 0) { @@ -596,18 +591,18 @@ void process_console(int c) power_list[0] = NULL; rc = sound_write(console.sound, samples_list, power_list, count, NULL, NULL, 1); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to write TX data to sound device (rc = %d)\n", rc); + LOGP(DSENDER, LOGL_ERROR, "Failed to write TX data to sound device (rc = %d)\n", rc); if (rc == -EPIPE) - PDEBUG(DSENDER, DEBUG_ERROR, "Trying to recover.\n"); + LOGP(DSENDER, LOGL_ERROR, "Trying to recover.\n"); return; } } samples_list[0] = samples; count = sound_read(console.sound, samples_list, console.buffer_size, 1, NULL); if (count < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to read from sound device (rc = %d)!\n", count); + LOGP(DSENDER, LOGL_ERROR, "Failed to read from sound device (rc = %d)!\n", count); if (count == -EPIPE) - PDEBUG(DSENDER, DEBUG_ERROR, "Trying to recover.\n"); + LOGP(DSENDER, LOGL_ERROR, "Trying to recover.\n"); return; } if (count) { diff --git a/src/libmobile/get_time.c b/src/libmobile/get_time.c new file mode 100644 index 0000000..85305a1 --- /dev/null +++ b/src/libmobile/get_time.c @@ -0,0 +1,13 @@ +#include <time.h> + +#include "get_time.h" + +double get_time(void) +{ + static struct timespec tv; + + clock_gettime(CLOCK_REALTIME, &tv); + + return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000.0; +} + diff --git a/src/libmobile/get_time.h b/src/libmobile/get_time.h new file mode 100644 index 0000000..1bd0c0b --- /dev/null +++ b/src/libmobile/get_time.h @@ -0,0 +1,3 @@ + +double get_time(void); + diff --git a/src/libmobile/main_mobile.c b/src/libmobile/main_mobile.c index a27acb8..487fe9e 100644 --- a/src/libmobile/main_mobile.c +++ b/src/libmobile/main_mobile.c @@ -29,13 +29,14 @@ #include <errno.h> #include "../libsample/sample.h" #include "main_mobile.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "sender.h" -#include "../libtimer/timer.h" -#include "../libselect/select.h" +#include <osmocom/core/timer.h> +#include <osmocom/core/select.h> #include "call.h" -#include "../libosmocc/endpoint.h" +#include <osmocom/cc/endpoint.h> #include "console.h" +#include "get_time.h" #ifdef HAVE_SDR #include "../libsdr/sdr.h" #include "../libsdr/sdr_config.h" @@ -167,6 +168,8 @@ const char *(*mobile_number_check_valid)(const char *); void main_mobile_init(const char *digits, const struct number_lengths lengths[], const char *prefixes[], const char *(*check_valid)(const char *)) { + logging_init(); + cc_argv[cc_argc++] = options_strdup("remote auto"); number_digits = digits; @@ -180,6 +183,14 @@ void main_mobile_init(const char *digits, const struct number_lengths lengths[], #endif } +void main_mobile_exit(void) +{ + if (got_init) { + enable_limit_scroll(false); + printf("\n\n"); + } +} + void main_mobile_set_number_check_valid(const char *(*check_valid)(const char *)) { mobile_number_check_valid = check_valid; @@ -230,7 +241,7 @@ void main_mobile_print_help(const char *arg0, const char *ext_usage) printf(" --config [~/]<path to config file>\n"); printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n"); printf(" Each line in config file is one option, '-' or '--' must not be given!\n"); - debug_print_help(); + logging_print_help(); printf(" -k --kanal <channel>\n"); printf(" -k --channel <channel>\n"); printf(" Channel (German = Kanal) number of \"Sender\" (German = Transceiver)\n"); @@ -414,13 +425,11 @@ int main_mobile_handle_options(int short_option, int argi, char **argv) print_help(argv[0]); return 0; case 'v': - if (!strcasecmp(argv[argi], "list")) { - debug_list_cat(); + rc = parse_logging_opt(argv[argi]); + if (rc > 0) return 0; - } - rc = parse_debug_opt(argv[argi]); if (rc < 0) { - fprintf(stderr, "Failed to parse debug option, please use -h for help.\n"); + fprintf(stderr, "Failed to parse logging option, please use -h for help.\n"); return rc; } break; @@ -577,8 +586,6 @@ void sighandler(int sigset) if (sigset == SIGPIPE) return; - if (clear_console_text) - clear_console_text(); printf("Signal received: %d\n", sigset); quit = 1; @@ -731,9 +738,6 @@ void main_mobile_loop(const char *name, int *quit, void (*myhandler)(void), cons process_sender_audio(sender, quit, buffer_size); } - /* process timers */ - process_timer(); - /* process audio for call instances */ now = get_time(); if (now - last_time_call >= 0.1) @@ -749,8 +753,6 @@ next_char: switch (c) { case 3: /* quit */ - if (clear_console_text) - clear_console_text(); printf("CTRL+c received, quitting!\n"); *quit = 1; goto next_char; @@ -787,6 +789,8 @@ next_char: #ifdef HAVE_SDR case 'q': /* toggle IQ display */ + if (!use_sdr) + goto next_char; display_wave_on(0); display_status_on(0); display_measurements_on(0); @@ -795,6 +799,8 @@ next_char: goto next_char; case 's': /* toggle spectrum display */ + if (!use_sdr) + goto next_char; display_wave_on(0); display_status_on(0); display_measurements_on(0); @@ -817,8 +823,7 @@ next_char: do { work = 0; work |= osmo_cc_handle(); - work |= (process_timer() == 0.0); - work |= osmo_fd_select(0.0); + work |= osmo_select_main(1); } while (work); if (!use_osmocc_sock) @@ -846,10 +851,6 @@ next_char: signal(SIGTERM, SIG_DFL); signal(SIGPIPE, SIG_DFL); - /* get rid of last entry */ - if (clear_console_text) - clear_console_text(); - /* reset terminal */ tcsetattr(0, TCSANOW, &term_orig); diff --git a/src/libmobile/main_mobile.h b/src/libmobile/main_mobile.h index c0fe797..29ae00d 100644 --- a/src/libmobile/main_mobile.h +++ b/src/libmobile/main_mobile.h @@ -35,6 +35,7 @@ extern const char *(*mobile_number_check_valid)(const char *); int main_mobile_number_ask(const char *number, const char *what); void main_mobile_init(const char *digits, const struct number_lengths lengths[], const char *prefixes[], const char *(*check_valid)(const char *)); +void main_mobile_exit(void); void main_mobile_set_number_check_valid(const char *(*check_valid)(const char *)); void main_mobile_print_help(const char *arg0, const char *ext_usage); void main_mobile_print_hotkeys(void); diff --git a/src/libmobile/sender.c b/src/libmobile/sender.c index 8b62f3c..5ef31c0 100644 --- a/src/libmobile/sender.c +++ b/src/libmobile/sender.c @@ -25,9 +25,9 @@ #include <errno.h> #include <string.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "sender.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #ifdef HAVE_SDR #include "../libsdr/sdr_config.h" #endif @@ -69,12 +69,12 @@ int sender_create(sender_t *sender, const char *kanal, double sendefrequenz, dou } if (samplerate < 8000) { - PDEBUG(DSENDER, DEBUG_NOTICE, "Given sample rate is below 8 KHz. Please use higher sample rate!\n"); + LOGP(DSENDER, LOGL_NOTICE, "Given sample rate is below 8 KHz. Please use higher sample rate!\n"); rc = -EINVAL; goto error; } - PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Creating 'Sender' instance\n"); + LOGP_CHAN(DSENDER, LOGL_DEBUG, "Creating 'Sender' instance\n"); /* if we find a channel that uses the same device as we do, * we will link us as slave to this master channel. then we @@ -83,27 +83,27 @@ int sender_create(sender_t *sender, const char *kanal, double sendefrequenz, dou */ for (master = sender_head; master; master = master->next) { if (!strcmp(master->kanal, kanal)) { - PDEBUG(DSENDER, DEBUG_ERROR, "Channel %s may not be defined for multiple transceivers!\n", kanal); + LOGP(DSENDER, LOGL_ERROR, "Channel %s may not be defined for multiple transceivers!\n", kanal); rc = -EIO; goto error; } if (check_channel && abs(atoi(master->kanal) - atoi(kanal)) == 1) { - PDEBUG(DSENDER, DEBUG_NOTICE, "------------------------------------------------------------------------\n"); - PDEBUG(DSENDER, DEBUG_NOTICE, "NOTE: Channel %s is next to channel %s. This will cause interferences.\n", kanal, master->kanal); - PDEBUG(DSENDER, DEBUG_NOTICE, "Please use at least one channel distance to avoid that.\n"); - PDEBUG(DSENDER, DEBUG_NOTICE, "------------------------------------------------------------------------\n"); + LOGP(DSENDER, LOGL_NOTICE, "------------------------------------------------------------------------\n"); + LOGP(DSENDER, LOGL_NOTICE, "NOTE: Channel %s is next to channel %s. This will cause interferences.\n", kanal, master->kanal); + LOGP(DSENDER, LOGL_NOTICE, "Please use at least one channel distance to avoid that.\n"); + LOGP(DSENDER, LOGL_NOTICE, "------------------------------------------------------------------------\n"); } if (!strcmp(master->device, device)) break; } if (master) { if (master->paging_signal != PAGING_SIGNAL_NONE && !use_sdr) { - PDEBUG(DSENDER, DEBUG_ERROR, "Cannot share audio device with channel %s, because its second audio channel is used for paging signal! Use different audio device.\n", master->kanal); + LOGP(DSENDER, LOGL_ERROR, "Cannot share audio device with channel %s, because its second audio channel is used for paging signal! Use different audio device.\n", master->kanal); rc = -EBUSY; goto error; } if (paging_signal != PAGING_SIGNAL_NONE && !use_sdr) { - PDEBUG(DSENDER, DEBUG_ERROR, "Cannot share audio device with channel %s, because we need a second audio channel for paging signal! Use different audio device.\n", master->kanal); + LOGP(DSENDER, LOGL_ERROR, "Cannot share audio device with channel %s, because we need a second audio channel for paging signal! Use different audio device.\n", master->kanal); rc = -EBUSY; goto error; } @@ -136,7 +136,7 @@ int sender_create(sender_t *sender, const char *kanal, double sendefrequenz, dou sender->audio_write = sound_write; sender->audio_get_tosend = sound_get_tosend; #else - PDEBUG(DSENDER, DEBUG_ERROR, "No sound card support compiled in!\n"); + LOGP(DSENDER, LOGL_ERROR, "No sound card support compiled in!\n"); rc = -ENOTSUP; goto error; #endif @@ -145,19 +145,19 @@ int sender_create(sender_t *sender, const char *kanal, double sendefrequenz, dou rc = init_samplerate(&sender->srstate, 8000.0, (double)samplerate, 3300.0); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to init sample rate conversion!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to init sample rate conversion!\n"); goto error; } rc = jitter_create(&sender->dejitter, sender->kanal, 8000, sizeof(sample_t), JITTER_AUDIO); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create and init audio buffer!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create and init audio buffer!\n"); goto error; } rc = jitter_create(&sender->loop_dejitter, sender->kanal, samplerate, sizeof(sample_t), JITTER_AUDIO); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create and init audio buffer!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create and init audio buffer!\n"); goto error; } @@ -208,28 +208,28 @@ int sender_open_audio(int buffer_size, double interval) if (master->write_rx_wave) { rc = wave_create_record(&master->wave_rx_rec, master->write_rx_wave, master->samplerate, channels, (master->max_deviation) ?: 1.0); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); return rc; } } if (master->write_tx_wave) { rc = wave_create_record(&master->wave_tx_rec, master->write_tx_wave, master->samplerate, channels, (master->max_deviation) ?: 1.0); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); return rc; } } if (master->read_rx_wave) { rc = wave_create_playback(&master->wave_rx_play, master->read_rx_wave, &master->samplerate, &channels, (master->max_deviation) ?: 1.0); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); return rc; } } if (master->read_tx_wave) { rc = wave_create_playback(&master->wave_tx_play, master->read_tx_wave, &master->samplerate, &channels, (master->max_deviation) ?: 1.0); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DSENDER, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); return rc; } } @@ -237,7 +237,7 @@ int sender_open_audio(int buffer_size, double interval) /* open device */ master->audio = master->audio_open(master->device, tx_f, rx_f, am, channels, paging_frequency, master->samplerate, buffer_size, interval, (master->max_deviation) ?: 1.0, master->max_modulation, master->modulation_index); if (!master->audio) { - PDEBUG(DSENDER, DEBUG_ERROR, "No device for transceiver!\n"); + LOGP(DSENDER, LOGL_ERROR, "No device for transceiver!\n"); return -EIO; } } @@ -273,7 +273,7 @@ int sender_start_audio(void) /* Destroy transceiver instance and unlink from list. */ void sender_destroy(sender_t *sender) { - PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Destroying 'Sender' instance\n"); + LOGP_CHAN(DSENDER, LOGL_DEBUG, "Destroying 'Sender' instance\n"); sender_tailp = &sender_head; while (*sender_tailp) { @@ -305,8 +305,8 @@ void sender_set_fm(sender_t *sender, double max_deviation, double max_modulation sender->speech_deviation = speech_deviation; sender->max_display = max_display; - PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Maximum deviation: %.1f kHz, Maximum modulation: %.1f kHz\n", max_deviation / 1000.0, max_modulation / 1000.0); - PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Deviation at speech level: %.1f kHz\n", speech_deviation / 1000.0); + LOGP_CHAN(DSENDER, LOGL_DEBUG, "Maximum deviation: %.1f kHz, Maximum modulation: %.1f kHz\n", max_deviation / 1000.0, max_modulation / 1000.0); + LOGP_CHAN(DSENDER, LOGL_DEBUG, "Deviation at speech level: %.1f kHz\n", speech_deviation / 1000.0); } /* set amplitude modulation and parameters */ @@ -319,7 +319,7 @@ void sender_set_am(sender_t *sender, double max_modulation, double speech_level, sender->max_display = max_display; sender->modulation_index = modulation_index; - PDEBUG_CHAN(DSENDER, DEBUG_DEBUG, "Modulation degree: %.0f %%, Maximum modulation: %.1f kHz\n", modulation_index / 100.0, max_modulation / 1000.0); + LOGP_CHAN(DSENDER, LOGL_DEBUG, "Modulation degree: %.0f %%, Maximum modulation: %.1f kHz\n", modulation_index / 100.0, max_modulation / 1000.0); } static void gain_samples(sample_t *samples, int length, double gain) @@ -357,15 +357,15 @@ void process_sender_audio(sender_t *sender, int *quit, int buffer_size) #endif count = sender->audio_get_tosend(sender->audio, buffer_size); if (count < 0) { - PDEBUG_CHAN(DSENDER, DEBUG_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); + LOGP_CHAN(DSENDER, LOGL_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count); if (count == -EPIPE) { if (cant_recover) { cant_recover: - PDEBUG(DSENDER, DEBUG_ERROR, "Cannot recover due to measurements, quitting!\n"); + LOGP(DSENDER, LOGL_ERROR, "Cannot recover due to measurements, quitting!\n"); *quit = 1; return; } - PDEBUG(DSENDER, DEBUG_ERROR, "Trying to recover!\n"); + LOGP(DSENDER, LOGL_ERROR, "Trying to recover!\n"); } return; } @@ -411,11 +411,11 @@ cant_recover: rc = sender->audio_write(sender->audio, samples, power, count, paging_signal, on, num_chan); if (rc < 0) { - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); + LOGP(DSENDER, LOGL_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc); if (rc == -EPIPE) { if (cant_recover) goto cant_recover; - PDEBUG(DSENDER, DEBUG_ERROR, "Trying to recover!\n"); + LOGP(DSENDER, LOGL_ERROR, "Trying to recover!\n"); } return; } @@ -431,11 +431,11 @@ cant_recover: *quit = 1; return; } - PDEBUG(DSENDER, DEBUG_ERROR, "Failed to read from audio device (rc = %d)!\n", count); + LOGP(DSENDER, LOGL_ERROR, "Failed to read from audio device (rc = %d)!\n", count); if (count == -EPIPE) { if (cant_recover) goto cant_recover; - PDEBUG(DSENDER, DEBUG_ERROR, "Trying to recover!\n"); + LOGP(DSENDER, LOGL_ERROR, "Trying to recover!\n"); } return; } diff --git a/src/libmtp/layer2.c b/src/libmtp/layer2.c index 42fc9ce..32774d6 100755 --- a/src/libmtp/layer2.c +++ b/src/libmtp/layer2.c @@ -33,8 +33,10 @@ #include <string.h> #include <errno.h> #include <stdlib.h> -#include "../libtimer/timer.h" -#include "../libdebug/debug.h" +#include <math.h> +#include <osmocom/core/timer.h> +#include <osmocom/core/utils.h> +#include "../liblogging/logging.h" #include "crc16.h" #include "mtp.h" @@ -67,6 +69,8 @@ #define T ((mtp->bitrate >= 64000) ? T_64k : T_4k8) #define D 256 +#define FLOAT_TO_TIMEOUT(f) floor(f), ((f) - floor(f)) * 1000000 + const char *mtp_sf_names[8] = { "SIO (Out of alignment)", "SIN (Normal alignment)", @@ -124,7 +128,7 @@ void mtp_l2_new_state(mtp_t *mtp, enum mtp_l2state state) { if (mtp->l2_state == state) return; - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Change state '%s' -> '%s'\n", mtp_state_names[mtp->l2_state], mtp_state_names[state]); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Change state '%s' -> '%s'\n", mtp_state_names[mtp->l2_state], mtp_state_names[state]); mtp->l2_state = state; } @@ -135,12 +139,12 @@ static void mtp_stop(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uin mtp_flush(mtp); /* Send SIOS */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Now sending SIOS\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Now sending SIOS\n"); mtp->tx_lssu = STATUS_OS; /* Cancel processor outage */ if (mtp->remote_outage) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Cancel remote processor outage\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Cancel remote processor outage\n"); mtp->remote_outage = 0; } @@ -148,21 +152,21 @@ static void mtp_stop(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uin mtp->remote_emergency = 0; /* stop all timers */ - if (timer_running(&mtp->t1)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T1\n"); - timer_stop(&mtp->t1); + if (osmo_timer_pending(&mtp->t1)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T1\n"); + osmo_timer_del(&mtp->t1); } - if (timer_running(&mtp->t2)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T2\n"); - timer_stop(&mtp->t2); + if (osmo_timer_pending(&mtp->t2)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T2\n"); + osmo_timer_del(&mtp->t2); } - if (timer_running(&mtp->t3)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T3\n"); - timer_stop(&mtp->t3); + if (osmo_timer_pending(&mtp->t3)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T3\n"); + osmo_timer_del(&mtp->t3); } - if (timer_running(&mtp->t4)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T4\n"); - timer_stop(&mtp->t4); + if (osmo_timer_pending(&mtp->t4)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T4\n"); + osmo_timer_del(&mtp->t4); } /* reset sequence numbers */ @@ -180,12 +184,12 @@ static void mtp_stop(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uin static void mtp_l3_start(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { /* Send SIO */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Now sending SIO\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Now sending SIO\n"); mtp->tx_lssu = STATUS_O; /* Start T2 */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T2 for %.3f seconds\n", T2); - timer_start(&mtp->t2, T2); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T2 for %.3f seconds\n", T2); + osmo_timer_schedule(&mtp->t2, FLOAT_TO_TIMEOUT(T2)); /* reset monitor counters */ mtp->proving_errors = 0; @@ -204,20 +208,20 @@ static void mtp_t2_timeout(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri mtp_stop(mtp, prim, data, len); /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 that we are out of service because of alignment failure\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 that we are out of service because of alignment failure\n"); mtp_l2l3(mtp, MTP_PRIM_OUT_OF_SERVICE, 0, &cause, 1); } static void mtp_go_aligned(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { /* stop timers */ - if (timer_running(&mtp->t2)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T2\n"); - timer_stop(&mtp->t2); + if (osmo_timer_pending(&mtp->t2)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T2\n"); + osmo_timer_del(&mtp->t2); } - if (timer_running(&mtp->t4)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T4\n"); - timer_stop(&mtp->t4); + if (osmo_timer_pending(&mtp->t4)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T4\n"); + osmo_timer_del(&mtp->t4); } if (prim == MTP_PRIM_SIE) { @@ -227,17 +231,17 @@ static void mtp_go_aligned(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri if (mtp->local_emergency) { /* Send SIE */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Now sending SIE\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Now sending SIE\n"); mtp->tx_lssu = STATUS_E; } else { /* Send SIN */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Now sending SIN\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Now sending SIN\n"); mtp->tx_lssu = STATUS_N; } /* Start T3 */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T3 for %.3f seconds\n", T3); - timer_start(&mtp->t3, T3); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T3 for %.3f seconds\n", T3); + osmo_timer_schedule(&mtp->t3, FLOAT_TO_TIMEOUT(T3)); /* Aligned */ mtp_l2_new_state(mtp, MTP_L2STATE_ALIGNED); @@ -251,9 +255,9 @@ static void mtp_go_proving(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri } /* stop timer */ - if (timer_running(&mtp->t3)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T3\n"); - timer_stop(&mtp->t3); + if (osmo_timer_pending(&mtp->t3)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T3\n"); + osmo_timer_del(&mtp->t3); } /* reset proving try counter M */ @@ -264,11 +268,11 @@ static void mtp_go_proving(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri /* Start T4 */ if (mtp->local_emergency || mtp->remote_emergency) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); - timer_start(&mtp->t4, T4e); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4e)); } else { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4n); - timer_start(&mtp->t4, T4n); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4n); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4n)); } /* Proving */ @@ -297,7 +301,7 @@ static void mtp_align_fail(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri mtp_stop(mtp, prim, data, len); /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 that we are out of service because of alignment failure\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 that we are out of service because of alignment failure\n"); mtp_l2l3(mtp, MTP_PRIM_OUT_OF_SERVICE, 0, &cause, 1); } @@ -308,9 +312,9 @@ static void mtp_correct_su(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri return; /* Stop T4 */ - if (timer_running(&mtp->t4)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T4\n"); - timer_stop(&mtp->t4); + if (osmo_timer_pending(&mtp->t4)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T4\n"); + osmo_timer_del(&mtp->t4); } /* Cancel further proving */ @@ -318,11 +322,11 @@ static void mtp_correct_su(mtp_t *mtp, enum mtp_prim __attribute__((unused)) pri /* Start T4 */ if (mtp->local_emergency || mtp->remote_emergency) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); - timer_start(&mtp->t4, T4e); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4e)); } else { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4n); - timer_start(&mtp->t4, T4n); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4n); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4n)); } } @@ -335,29 +339,29 @@ static void mtp_align_complete(mtp_t *mtp, enum mtp_prim __attribute__((unused)) /* Start T4 */ if (mtp->local_emergency || mtp->remote_emergency) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); - timer_start(&mtp->t4, T4e); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4e)); } else { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4n); - timer_start(&mtp->t4, T4n); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4n); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4n)); } return; } /* Start T1 */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T1 for %.3f seconds\n", T1); - timer_start(&mtp->t1, T1); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T1 for %.3f seconds\n", T1); + osmo_timer_schedule(&mtp->t1, FLOAT_TO_TIMEOUT(T1)); if (mtp->local_outage) { /* Send SIPO */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Local processor outage, now sending SIPO\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Local processor outage, now sending SIPO\n"); mtp->tx_lssu = STATUS_PO; /* Aligned */ mtp_l2_new_state(mtp, MTP_L2STATE_ALIGNED_NOT_READY); } else { /* Send FISU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "No local processor outage, now sending FISU\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "No local processor outage, now sending FISU\n"); mtp->tx_lssu = -1; /* Aligned */ @@ -373,7 +377,7 @@ static void mtp_abort_proving(mtp_t *mtp, enum mtp_prim __attribute__((unused)) return; } - PDEBUG_CHAN(DMTP2, DEBUG_NOTICE, "Proving failed, try again!\n"); + LOGP_CHAN(DMTP2, LOGL_NOTICE, "Proving failed, try again!\n"); /* Mark further proving */ mtp->further_proving = 1; @@ -383,23 +387,23 @@ static void mtp_proving_emerg(mtp_t *mtp, enum mtp_prim __attribute__((unused)) { if (prim == MTP_PRIM_EMERGENCY) { /* Send SIE */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Now sending SIE\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Now sending SIE\n"); mtp->tx_lssu = STATUS_E; } if (!mtp->local_emergency && !mtp->remote_emergency) { /* Stop T4 */ - if (timer_running(&mtp->t4)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T4\n"); - timer_stop(&mtp->t4); + if (osmo_timer_pending(&mtp->t4)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T4\n"); + osmo_timer_del(&mtp->t4); } /* Cancel further proving */ mtp->further_proving = 0; /* Sart T4 */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); - timer_start(&mtp->t4, T4e); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start timer T4 for %.3f seconds\n", T4e); + osmo_timer_schedule(&mtp->t4, FLOAT_TO_TIMEOUT(T4e)); } if (prim == MTP_PRIM_EMERGENCY) @@ -432,35 +436,35 @@ static void mtp_link_failure(mtp_t *mtp, enum mtp_prim __attribute__((unused)) p else cause = MTP_CAUSE_LINK_FAILURE_REMOTE; /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 that we are out of service because of link failure\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 that we are out of service because of link failure\n"); mtp_l2l3(mtp, MTP_PRIM_OUT_OF_SERVICE, 0, &cause, 1); } static void mtp_remote_outage(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { mtp->remote_outage = 1; - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Set remote processor outage\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Set remote processor outage\n"); /* Stop T1 */ - if (timer_running(&mtp->t1)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T1\n"); - timer_stop(&mtp->t1); + if (osmo_timer_pending(&mtp->t1)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T1\n"); + osmo_timer_del(&mtp->t1); } /* Processor outage */ mtp_l2_new_state(mtp, MTP_L2STATE_PROCESSOR_OUTAGE); /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 about remote processor outage\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 about remote processor outage\n"); mtp_l2l3(mtp, MTP_PRIM_REMOTE_PROCESSOR_OUTAGE, 0, NULL, 0); } static void mtp_fisu_msu(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, uint8_t __attribute__((unused)) *data, int __attribute__((unused)) len) { /* Stop T1 */ - if (timer_running(&mtp->t1)) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop timer T1\n"); - timer_stop(&mtp->t1); + if (osmo_timer_pending(&mtp->t1)) { + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop timer T1\n"); + osmo_timer_del(&mtp->t1); } if (mtp->l2_state == MTP_L2STATE_ALIGNED_READY) { @@ -472,7 +476,7 @@ static void mtp_fisu_msu(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, } /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 that we are in service\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 that we are in service\n"); mtp_l2l3(mtp, MTP_PRIM_IN_SERVICE, 0, NULL, 0); } @@ -481,7 +485,7 @@ static void mtp_aligned_outage(mtp_t *mtp, enum mtp_prim __attribute__((unused)) mtp->local_outage = 1; /* Send SIPO */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Local processor outage, now sending SIPO\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Local processor outage, now sending SIPO\n"); mtp->tx_lssu = STATUS_PO; /* Aligned not ready */ @@ -493,7 +497,7 @@ static void mtp_not_aligned_recovered(mtp_t *mtp, enum mtp_prim __attribute__((u mtp->local_outage = 0; /* Send FISU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "No local processor outage, now sending FISU\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "No local processor outage, now sending FISU\n"); mtp->tx_lssu = -1; /* Aligned ready */ @@ -505,7 +509,7 @@ static void mtp_in_service_outage(mtp_t *mtp, enum mtp_prim __attribute__((unuse mtp->local_outage = 1; /* Send SIPO */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Local processor outage, now sending SIPO\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Local processor outage, now sending SIPO\n"); mtp->tx_lssu = STATUS_PO; /* Processor outage */ @@ -519,7 +523,7 @@ static void mtp_outage(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, u mtp->local_outage = 1; /* Send SIPO */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Local processor outage, now sending SIPO\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Local processor outage, now sending SIPO\n"); mtp->tx_lssu = STATUS_PO; } @@ -528,27 +532,27 @@ static void mtp_outage(mtp_t *mtp, enum mtp_prim __attribute__((unused)) prim, u mtp->local_outage = 0; /* Send FISU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "No local processor outage, now sending FISU\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "No local processor outage, now sending FISU\n"); mtp->tx_lssu = -1; } /* remote outage */ if (prim == MTP_PRIM_SIPO && !mtp->remote_outage) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Set remote processor outage\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Set remote processor outage\n"); mtp->remote_outage = 1; /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 about remote processor outage\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 about remote processor outage\n"); mtp_l2l3(mtp, MTP_PRIM_REMOTE_PROCESSOR_OUTAGE, 0, NULL, 0); } /* remote recovered */ if ((prim == MTP_PRIM_FISU || prim == MTP_PRIM_MSU) && mtp->remote_outage) { mtp->remote_outage = 0; - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Cancel remote processor outage\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Cancel remote processor outage\n"); /* send message to upper layer */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Telling L3 about remote processor recovered\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Telling L3 about remote processor recovered\n"); mtp_l2l3(mtp, MTP_PRIM_REMOTE_PROCESSOR_RECOVERED, 0, NULL, 0); } @@ -701,7 +705,7 @@ static void handle_event(mtp_t *mtp, enum mtp_prim prim, uint8_t *data, int len) { int i; - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Handling message '%s' in state '%s'\n", mtp_prim_names[prim], mtp_state_names[mtp->l2_state]); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Handling message '%s' in state '%s'\n", mtp_prim_names[prim], mtp_state_names[mtp->l2_state]); /* Find function for current state and message */ for (i = 0; i < (int)STATEMACHINE_LEN; i++) @@ -709,7 +713,7 @@ static void handle_event(mtp_t *mtp, enum mtp_prim prim, uint8_t *data, int len) && ((1 << mtp->l2_state) & statemachine_list[i].states)) break; if (i == STATEMACHINE_LEN) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Message '%s' unhandled at state '%s'\n", mtp_prim_names[prim], mtp_state_names[mtp->l2_state]); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Message '%s' unhandled at state '%s'\n", mtp_prim_names[prim], mtp_state_names[mtp->l2_state]); return; } @@ -727,11 +731,11 @@ int mtp_l3l2(mtp_t *mtp, enum mtp_prim prim, uint8_t sio, uint8_t *data, int len } if (mtp->l2_state != MTP_L2STATE_IN_SERVICE) { - PDEBUG_CHAN(DMTP2, DEBUG_ERROR, "Rejecting data message in state '%s'\n", mtp_state_names[mtp->l2_state]); + LOGP_CHAN(DMTP2, LOGL_ERROR, "Rejecting data message in state '%s'\n", mtp_state_names[mtp->l2_state]); return -EIO; } - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Queueing data message.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Queueing data message.\n"); /* go to end of queue */ tailp = &mtp->tx_queue; @@ -741,7 +745,7 @@ int mtp_l3l2(mtp_t *mtp, enum mtp_prim prim, uint8_t sio, uint8_t *data, int len /* add new message to queue */ msg = calloc(sizeof(*msg) + len, 1); if (!msg) { - PDEBUG_CHAN(DMTP2, DEBUG_ERROR, "No mem!\n"); + LOGP_CHAN(DMTP2, LOGL_ERROR, "No mem!\n"); abort(); } mtp->tx_queue_seq = (mtp->tx_queue_seq + 1) & 0x7f; @@ -807,7 +811,7 @@ static int mtp_send_msu(mtp_t *mtp, uint8_t *bsn, uint8_t *bib, uint8_t *fsn, ui msg = msg->next; } if (i == 128) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Cannot send MSU, because more than 127 unacknowledged messages have been sent.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Cannot send MSU, because more than 127 unacknowledged messages have been sent.\n"); return 0; } @@ -833,7 +837,7 @@ static int mtp_send_msu(mtp_t *mtp, uint8_t *bsn, uint8_t *bib, uint8_t *fsn, ui *fib = mtp->fib; *sio = msg->sio; if (msg->len > max) { - PDEBUG_CHAN(DMTP2, DEBUG_ERROR, "Message from layer 3 tructated, because of length %d.\n", msg->len); + LOGP_CHAN(DMTP2, LOGL_ERROR, "Message from layer 3 tructated, because of length %d.\n", msg->len); msg->len = max; } memcpy(data, msg->data, msg->len); @@ -862,14 +866,14 @@ static int ack_msg(mtp_t *mtp, uint8_t bsn) /* remove all messages up to the one found */ while (mtp->tx_queue != msg) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "ACK: Message with sequence number %d has been acked and is removed.\n", mtp->tx_queue->sequence); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "ACK: Message with sequence number %d has been acked and is removed.\n", mtp->tx_queue->sequence); temp = mtp->tx_queue; mtp->tx_queue = temp->next; free(temp); } /* remove the message found */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "ACK: Message with sequence number %d has been acked and is removed.\n", mtp->tx_queue->sequence); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "ACK: Message with sequence number %d has been acked and is removed.\n", mtp->tx_queue->sequence); mtp->tx_queue = msg->next; free(msg); @@ -896,7 +900,7 @@ static int nack_msg(mtp_t *mtp, uint8_t bsn, uint8_t bib) return 0; /* rewind tx_seq to retransmit */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "NACK: Lost messages, retransmitting from sequence number %d.\n", (bsn + 1) & 0x7f); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "NACK: Lost messages, retransmitting from sequence number %d.\n", (bsn + 1) & 0x7f); mtp->tx_seq = bsn; /* flip bit */ @@ -947,7 +951,7 @@ static void mtp_receive_fisu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, /* reject, if local outage */ if (mtp->local_outage) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Ignoring, we have local outage.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Ignoring, we have local outage.\n"); return; } @@ -963,7 +967,7 @@ static void mtp_receive_fisu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, /* if the FSN is different and received FIB equals last BIB sent */ if (fsn != mtp->rx_seq && fib == mtp->bib) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Send nack, because we missed a frame and FIB equals last transmitted BIB.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Send nack, because we missed a frame and FIB equals last transmitted BIB.\n"); /* schedule NACK */ mtp->tx_nack = 1; } @@ -980,7 +984,7 @@ static void mtp_receive_msu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, u /* reject, if local outage */ if (mtp->local_outage) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Ignoring, we have local outage.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Ignoring, we have local outage.\n"); return; } @@ -995,7 +999,7 @@ static void mtp_receive_msu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, u /* i) if sequence equals last received, drop it, regardless of FIB */ if (fsn == mtp->rx_seq) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Ignoring, because sequence number did not increase.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Ignoring, because sequence number did not increase.\n"); return; } @@ -1003,13 +1007,13 @@ static void mtp_receive_msu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, u if (fsn == ((mtp->rx_seq + 1) & 0x7f)) { /* if FIB equals last BIB */ if (fib == mtp->bib) { - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Accepting, because sequence number increases.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Accepting, because sequence number increases.\n"); mtp_l2l3(mtp, MTP_PRIM_DATA, sio, data, len); /* acknowledge */ mtp->rx_seq = fsn; } else { /* discard if not equal */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Ignoring, because FIB does not equal last transmitted BIB.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Ignoring, because FIB does not equal last transmitted BIB.\n"); } return; } @@ -1018,10 +1022,10 @@ static void mtp_receive_msu(mtp_t *mtp, uint8_t bsn, uint8_t bib, uint8_t fsn, u * a NACK is sent, if FIB equals last BIB */ if (fib == mtp->bib) { /* schedule NACK */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Send nack, because we missed a frame and FIB equals last transmitted BIB.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Send nack, because we missed a frame and FIB equals last transmitted BIB.\n"); mtp->tx_nack = 1; } else - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> Ignoring, because we missed a frame and FIB dos not equal last transmitted BIB.\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> Ignoring, because we missed a frame and FIB dos not equal last transmitted BIB.\n"); } /* @@ -1037,21 +1041,21 @@ static int mtp_send_frame(mtp_t *mtp, uint8_t *data, int max) if (mtp_send_lssu(mtp, &bsn, &bib, &fsn, &fib, &sf)) { /* transmit LSSU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Sending LSSU with status flag '%s'\n", mtp_sf_names[sf]); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Sending LSSU with status flag '%s'\n", mtp_sf_names[sf]); data[3] = sf; len = 1; } else if ((len = mtp_send_msu(mtp, &bsn, &bib, &fsn, &fib, &sio, data + 4, max - 5, &resending))) { /* transmit MSU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "%sSending MSU with SIO '%02x' data '%s'\n", (resending) ? "Re-" : "", sio, debug_hex(data + 4, len)); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "%sSending MSU with SIO '%02x' data '%s'\n", (resending) ? "Re-" : "", sio, osmo_hexdump(data + 4, len)); data[3] = sio; len++; } else { /* transmit FISU */ mtp_send_fisu(mtp, &bsn, &bib, &fsn, &fib); - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Sending FISU\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Sending FISU\n"); len = 0; } - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); data[0] = (bsn & 0x7f) | (bib << 7); data[1] = (fsn & 0x7f) | (fib << 7); data[2] = (len > 63) ? 63 : len; @@ -1076,7 +1080,7 @@ static int mtp_receive_frame(mtp_t *mtp, uint8_t *data, int len) if (len < 5) { /* frame too short */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving frame is too short (got: %d bytes)\n", len); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving frame is too short (got: %d bytes)\n", len); return -EINVAL; } len -= 5; @@ -1089,34 +1093,34 @@ static int mtp_receive_frame(mtp_t *mtp, uint8_t *data, int len) if (li != len && (li != 63 || len <= 63)) { /* frame wrong length */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving frame has wrong length (got %d bytes, length %d bytes)\n", li, len); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving frame has wrong length (got %d bytes, length %d bytes)\n", li, len); return -EINVAL; } crc = calc_crc16(data, len + 3); if (data[3 + len] != (crc & 0xff) || data[4 + len] != (crc >> 8)) { /* crc error */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving frame has wrong CRC\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving frame has wrong CRC\n"); return -EINVAL; } if (len == 1) - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving LSSU (length = %d) with status flag 0x%02x (%s)\n", len, data[3], mtp_sf_names[data[3] & 0x7]); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving LSSU (length = %d) with status flag 0x%02x (%s)\n", len, data[3], mtp_sf_names[data[3] & 0x7]); if (len == 2) - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving LSSU (length = %d) with status flag 0x%04x (%s)\n", len, data[3] | (data[4] << 8), mtp_sf_names[data[3] & 0x7]); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving LSSU (length = %d) with status flag 0x%04x (%s)\n", len, data[3] | (data[4] << 8), mtp_sf_names[data[3] & 0x7]); if (len == 1 || len == 2) { /* receive LSSU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); func_mtp_receive_lssu(mtp, fsn, bib, data[3] & 0x7); } else if (len > 2) { /* receive MSU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving MSU with SIO '%02x' data '%s'\n", data[3], debug_hex(data + 4, len - 1)); - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving MSU with SIO '%02x' data '%s'\n", data[3], osmo_hexdump(data + 4, len - 1)); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); func_mtp_receive_msu(mtp, bsn, bib, fsn, fib, data[3], data + 4, len - 1); } else { /* receive FISU */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Receiving FISU\n"); - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Receiving FISU\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, " -> FSN %d, FIB %d, BSN %d, BIB %d\n", fsn, fib, bsn, bib); func_mtp_receive_fisu(mtp, bsn, bib, fsn, fib); } @@ -1194,9 +1198,9 @@ static void mtp_monitor(mtp_t *mtp, int bad) /* raise error count auntil Ti has been reached */ mtp->proving_errors++; if (bad == MONITOR_BAD) - PDEBUG(DMTP2, DEBUG_NOTICE, "Proving counter raises to %d/%d due to frame error\n", mtp->proving_errors, Ti); + LOGP(DMTP2, LOGL_NOTICE, "Proving counter raises to %d/%d due to frame error\n", mtp->proving_errors, Ti); else - PDEBUG(DMTP2, DEBUG_NOTICE, "Proving counter raises to %d/%d due to octet counting\n", mtp->proving_errors, Ti); + LOGP(DMTP2, LOGL_NOTICE, "Proving counter raises to %d/%d due to octet counting\n", mtp->proving_errors, Ti); if (mtp->proving_errors == Ti) { mtp->proving_errors = 0; handle_event(mtp, MTP_PRIM_ABORT_PROVING, NULL, 0); @@ -1212,16 +1216,16 @@ static void mtp_monitor(mtp_t *mtp, int bad) mtp->monitor_good = 0; if (mtp->monitor_errors > 0) { mtp->monitor_errors--; - PDEBUG(DMTP2, DEBUG_NOTICE, "Link error counter reduces to %d/%d\n", mtp->monitor_errors, T); + LOGP(DMTP2, LOGL_NOTICE, "Link error counter reduces to %d/%d\n", mtp->monitor_errors, T); } } } else { /* raise error count auntil T has been reached */ mtp->monitor_errors++; if (bad == MONITOR_BAD) - PDEBUG(DMTP2, DEBUG_NOTICE, "Link error counter raises to %d/%d due to frame error\n", mtp->monitor_errors, T); + LOGP(DMTP2, LOGL_NOTICE, "Link error counter raises to %d/%d due to frame error\n", mtp->monitor_errors, T); else - PDEBUG(DMTP2, DEBUG_NOTICE, "Link error counter raises to %d/%d due to octet counting\n", mtp->monitor_errors, T); + LOGP(DMTP2, LOGL_NOTICE, "Link error counter raises to %d/%d due to octet counting\n", mtp->monitor_errors, T); if (mtp->monitor_errors == T) { mtp->monitor_errors = 0; handle_event(mtp, MTP_PRIM_LINK_FAILURE, NULL, 0); @@ -1246,7 +1250,7 @@ void mtp_receive_bit(mtp_t *mtp, uint8_t bit) if (mtp->rx_octet_counting) { if (++mtp->rx_octet_count == 8 * N) { /* octet counter hits */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Octet counter hits!\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Octet counter hits!\n"); mtp->rx_octet_count = 0; mtp_monitor(mtp, MONITOR_OCTET_COUNTING); } @@ -1268,13 +1272,13 @@ void mtp_receive_bit(mtp_t *mtp, uint8_t bit) } if (rc == 0 && mtp->rx_octet_counting) { /* stop octet counting */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Stop Octet counting, due to correctly received frame\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Stop Octet counting, due to correctly received frame\n"); mtp->rx_octet_counting = 0; } mtp->rx_flag_count = 0; } else { if (++mtp->rx_flag_count == 100) - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Continuously receiving HDLC flags (\"01111110\"), remote link seems to be down!\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Continuously receiving HDLC flags (\"01111110\"), remote link seems to be down!\n"); } mtp->rx_byte_count = 0; mtp->rx_bit_count = 0; @@ -1287,7 +1291,7 @@ void mtp_receive_bit(mtp_t *mtp, uint8_t bit) if (mtp->rx_octet_counting) return; /* start octet counting */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start Octet counting, due to 7 consecutive bits\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start Octet counting, due to 7 consecutive bits\n"); mtp->rx_octet_counting = 1; mtp->rx_octet_count = 0; return; @@ -1306,7 +1310,7 @@ void mtp_receive_bit(mtp_t *mtp, uint8_t bit) if (mtp->rx_byte_count == (int)sizeof(mtp->rx_frame)) { mtp->rx_receiving = 0; /* start octet counting */ - PDEBUG_CHAN(DMTP2, DEBUG_DEBUG, "Start Octet counting, due to frame oversize\n"); + LOGP_CHAN(DMTP2, LOGL_DEBUG, "Start Octet counting, due to frame oversize\n"); mtp->rx_octet_counting = 1; mtp->rx_octet_count = 0; return; diff --git a/src/libmtp/layer3.c b/src/libmtp/layer3.c index 7726bd5..2259518 100644 --- a/src/libmtp/layer3.c +++ b/src/libmtp/layer3.c @@ -29,8 +29,9 @@ #include <string.h> #include <errno.h> #include <stdlib.h> -#include "../libtimer/timer.h" -#include "../libdebug/debug.h" +#include <osmocom/core/timer.h> +#include <osmocom/core/utils.h> +#include "../liblogging/logging.h" #include "mtp.h" /* message from layer 4 */ @@ -39,7 +40,7 @@ int mtp_send(mtp_t *mtp, enum mtp_prim prim, uint8_t slc, uint8_t *data, int len uint8_t buffer[len + 4]; if (prim == MTP_PRIM_DATA) { - PDEBUG_CHAN(DMTP3, DEBUG_DEBUG, "Send frame to remote: SIO=0x%02x DPC=%d OPC=%d SLC=%d %s\n", mtp->sio, mtp->remote_pc, mtp->local_pc, slc, debug_hex(data, len)); + LOGP_CHAN(DMTP3, LOGL_DEBUG, "Send frame to remote: SIO=0x%02x DPC=%d OPC=%d SLC=%d %s\n", mtp->sio, mtp->remote_pc, mtp->local_pc, slc, osmo_hexdump(data, len)); /* add header */ buffer[0] = mtp->remote_pc; buffer[1] = (mtp->remote_pc >> 8) & 0x3f; @@ -67,7 +68,7 @@ void mtp_l2l3(mtp_t *mtp, enum mtp_prim prim, uint8_t sio, uint8_t *data, int le if (prim == MTP_PRIM_DATA) { if (len < 4) { - PDEBUG_CHAN(DMTP3, DEBUG_NOTICE, "Short frame from layer 2 (len=%d)\n", len); + LOGP_CHAN(DMTP3, LOGL_NOTICE, "Short frame from layer 2 (len=%d)\n", len); return; } @@ -81,18 +82,18 @@ void mtp_l2l3(mtp_t *mtp, enum mtp_prim prim, uint8_t sio, uint8_t *data, int le data += 4; len -= 4; - PDEBUG_CHAN(DMTP3, DEBUG_DEBUG, "Received frame from remote: SIO=0x%02x DPC=%d OPC=%d SLC=%d %s\n", sio, dpc, opc, slc, debug_hex(data, len)); + LOGP_CHAN(DMTP3, LOGL_DEBUG, "Received frame from remote: SIO=0x%02x DPC=%d OPC=%d SLC=%d %s\n", sio, dpc, opc, slc, osmo_hexdump(data, len)); if (dpc != mtp->local_pc || opc != mtp->remote_pc) { - PDEBUG_CHAN(DMTP3, DEBUG_NOTICE, "Received message with wrong point codes: %d->%d but expecting %d->%d\n", opc, dpc, mtp->remote_pc, mtp->local_pc); + LOGP_CHAN(DMTP3, LOGL_NOTICE, "Received message with wrong point codes: %d->%d but expecting %d->%d\n", opc, dpc, mtp->remote_pc, mtp->local_pc); return; } if ((sio & 0x0f) == 0x0 && len >= 1) { - PDEBUG_CHAN(DMTP3, DEBUG_NOTICE, "MGMT message received: SLC=%d H0=%d H1=%d %s\n", slc, data[0] & 0xf, data[0] >> 4, debug_hex(data + 1, len - 1)); + LOGP_CHAN(DMTP3, LOGL_NOTICE, "MGMT message received: SLC=%d H0=%d H1=%d %s\n", slc, data[0] & 0xf, data[0] >> 4, osmo_hexdump(data + 1, len - 1)); return; } if (sio != mtp->sio) { - PDEBUG_CHAN(DMTP3, DEBUG_NOTICE, "Received message with wrong SIO: 0x%02x but expecting 0x%02x\n", sio, mtp->sio); + LOGP_CHAN(DMTP3, LOGL_NOTICE, "Received message with wrong SIO: 0x%02x but expecting 0x%02x\n", sio, mtp->sio); return; } } diff --git a/src/libmtp/mtp.c b/src/libmtp/mtp.c index 3ae4811..7cd67aa 100644 --- a/src/libmtp/mtp.c +++ b/src/libmtp/mtp.c @@ -25,8 +25,8 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include "../libtimer/timer.h" -#include "../libdebug/debug.h" +#include <osmocom/core/timer.h> +#include "../liblogging/logging.h" #include "mtp.h" static void mtp_t1(void *data) @@ -73,10 +73,10 @@ int mtp_init(mtp_t *mtp, const char *name, void *inst, void (*mtp_receive)(void mtp->sio = sio; mtp->local_pc = local_pc; mtp->remote_pc = remote_pc; - timer_init(&mtp->t1, mtp_t1, mtp); - timer_init(&mtp->t2, mtp_t2, mtp); - timer_init(&mtp->t3, mtp_t3, mtp); - timer_init(&mtp->t4, mtp_t4, mtp); + osmo_timer_setup(&mtp->t1, mtp_t1, mtp); + osmo_timer_setup(&mtp->t2, mtp_t2, mtp); + osmo_timer_setup(&mtp->t3, mtp_t3, mtp); + osmo_timer_setup(&mtp->t4, mtp_t4, mtp); return 0; } @@ -86,10 +86,10 @@ void mtp_exit(mtp_t *mtp) if (!mtp) return; - timer_exit(&mtp->t1); - timer_exit(&mtp->t2); - timer_exit(&mtp->t3); - timer_exit(&mtp->t4); + osmo_timer_del(&mtp->t1); + osmo_timer_del(&mtp->t2); + osmo_timer_del(&mtp->t3); + osmo_timer_del(&mtp->t4); mtp_flush(mtp); } diff --git a/src/libmtp/mtp.h b/src/libmtp/mtp.h index d1f7ac7..6d44d81 100644 --- a/src/libmtp/mtp.h +++ b/src/libmtp/mtp.h @@ -70,10 +70,10 @@ typedef struct mtp { int local_outage; /* current local processor outage */ int remote_outage; /* current remote processor outage */ int tx_lssu; /* what LSSU status to transmit (-1 for nothing) */ - struct timer t1; /* timer "alignment ready" */ - struct timer t2; /* timer "not aligned" */ - struct timer t3; /* timer "aligned" */ - struct timer t4; /* proving period timer */ + struct osmo_timer_list t1; /* timer "alignment ready" */ + struct osmo_timer_list t2; /* timer "not aligned" */ + struct osmo_timer_list t3; /* timer "aligned" */ + struct osmo_timer_list t4; /* proving period timer */ int proving_try; /* counts number of proving attempts */ int further_proving;/* flag that indicates another proving attempt */ diff --git a/src/liboptions/options.c b/src/liboptions/options.c index d49e698..cc19b89 100644 --- a/src/liboptions/options.c +++ b/src/liboptions/options.c @@ -23,7 +23,7 @@ #include <stdlib.h> #include <errno.h> #include "options.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" typedef struct option { struct option *next; @@ -47,7 +47,7 @@ char *options_strdup(const char *s) o = malloc(sizeof(struct options_strdup_entry) + strlen(s)); if (!o) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "No mem!\n"); + LOGP(DOPTIONS, LOGL_ERROR, "No mem!\n"); abort(); } o->next = options_strdup_list; @@ -64,19 +64,19 @@ void option_add(int short_option, const char *long_option, int parameter_count) /* check if option already exists or is not allowed */ for (option = option_head; option; option = option->next) { if (!strcmp(option->long_option, "config")) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Option '%s' is not allowed to add, please fix!\n", option->long_option); + LOGP(DOPTIONS, LOGL_ERROR, "Option '%s' is not allowed to add, please fix!\n", option->long_option); abort(); } if (option->short_option == short_option || !strcmp(option->long_option, long_option)) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Option '%s' added twice, please fix!\n", option->long_option); + LOGP(DOPTIONS, LOGL_ERROR, "Option '%s' added twice, please fix!\n", option->long_option); abort(); } } option = calloc(1, sizeof(*option)); if (!option) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "No mem!\n"); + LOGP(DOPTIONS, LOGL_ERROR, "No mem!\n"); abort(); } @@ -115,7 +115,7 @@ int options_config_file(int argc, char *argv[], const char *config_file, int (*h /* open config file */ fp = fopen(config, "r"); if (!fp) { - PDEBUG(DOPTIONS, DEBUG_INFO, "Config file '%s' seems not to exist, using command line options only.\n", config); + LOGP(DOPTIONS, LOGL_INFO, "Config file '%s' seems not to exist, using command line options only.\n", config); return 1; } @@ -201,21 +201,21 @@ int options_config_file(int argc, char *argv[], const char *config_file, int (*h /* search option */ for (option = option_head; option; option = option->next) { if (opt[0] == option->short_option && opt[1] == '\0') { - PDEBUG(DOPTIONS, DEBUG_INFO, "Config file option '%s' ('%s'), parameter%s\n", opt, option->long_option, params); + LOGP(DOPTIONS, LOGL_INFO, "Config file option '%s' ('%s'), parameter%s\n", opt, option->long_option, params); break; } if (!strcmp(opt, option->long_option)) { - PDEBUG(DOPTIONS, DEBUG_INFO, "Config file option '%s', parameter%s\n", opt, params); + LOGP(DOPTIONS, LOGL_INFO, "Config file option '%s', parameter%s\n", opt, params); break; } } if (!option) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given option '%s' in config file '%s' at line %d is not a valid option, use '-h' for help!\n", opt, config_file, line); + LOGP(DOPTIONS, LOGL_ERROR, "Given option '%s' in config file '%s' at line %d is not a valid option, use '-h' for help!\n", opt, config_file, line); rc = -EINVAL; goto done; } if (option->parameter_count != i) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given option '%s' in config file '%s' at line %d requires %d parameter(s), use '-h' for help!\n", opt, config_file, line, option->parameter_count); + LOGP(DOPTIONS, LOGL_ERROR, "Given option '%s' in config file '%s' at line %d requires %d parameter(s), use '-h' for help!\n", opt, config_file, line, option->parameter_count); return -EINVAL; } rc = handle_options(option->short_option, 0, args); @@ -242,11 +242,11 @@ int options_command_line(int argc, char *argv[], int (*handle_options)(int short /* --config */ if (!strcmp(argv[argi], "--config")) { if (argi > 1) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given command line option '%s' must be the first option specified, use '-h' for help!\n", argv[argi]); + LOGP(DOPTIONS, LOGL_ERROR, "Given command line option '%s' must be the first option specified, use '-h' for help!\n", argv[argi]); return -EINVAL; } if (argc <= 2) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given command line option '%s' requires 1 parameter, use '-h' for help!\n", argv[argi]); + LOGP(DOPTIONS, LOGL_ERROR, "Given command line option '%s' requires 1 parameter, use '-h' for help!\n", argv[argi]); return -EINVAL; } argi += 1; @@ -255,7 +255,7 @@ int options_command_line(int argc, char *argv[], int (*handle_options)(int short if (argv[argi][0] == '-') { if (argv[argi][1] != '-') { if (strlen(argv[argi]) != 2) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given command line option '%s' exceeds one character, use '-h' for help!\n", argv[argi]); + LOGP(DOPTIONS, LOGL_ERROR, "Given command line option '%s' exceeds one character, use '-h' for help!\n", argv[argi]); return -EINVAL; } /* -x */ @@ -265,9 +265,9 @@ int options_command_line(int argc, char *argv[], int (*handle_options)(int short params[0] = '\0'; for (i = 0; i < option->parameter_count; i++) sprintf(strchr(params, '\0'), " '%s'", argv[argi + 1 + i]); - PDEBUG(DOPTIONS, DEBUG_INFO, "Command line option '%s' ('--%s'), parameter%s\n", argv[argi], option->long_option, params); + LOGP(DOPTIONS, LOGL_INFO, "Command line option '%s' ('--%s'), parameter%s\n", argv[argi], option->long_option, params); } else - PDEBUG(DOPTIONS, DEBUG_INFO, "Command line option '%s' ('--%s')\n", argv[argi], option->long_option); + LOGP(DOPTIONS, LOGL_INFO, "Command line option '%s' ('--%s')\n", argv[argi], option->long_option); break; } } @@ -279,19 +279,19 @@ int options_command_line(int argc, char *argv[], int (*handle_options)(int short params[0] = '\0'; for (i = 0; i < option->parameter_count; i++) sprintf(strchr(params, '\0'), " '%s'", argv[argi + 1 + i]); - PDEBUG(DOPTIONS, DEBUG_INFO, "Command line option '%s', parameter%s\n", argv[argi], params); + LOGP(DOPTIONS, LOGL_INFO, "Command line option '%s', parameter%s\n", argv[argi], params); } else - PDEBUG(DOPTIONS, DEBUG_INFO, "Command line option '%s'\n", argv[argi]); + LOGP(DOPTIONS, LOGL_INFO, "Command line option '%s'\n", argv[argi]); break; } } } if (!option) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given command line option '%s' is not a valid option, use '-h' for help!\n", argv[argi]); + LOGP(DOPTIONS, LOGL_ERROR, "Given command line option '%s' is not a valid option, use '-h' for help!\n", argv[argi]); return -EINVAL; } if (argi + option->parameter_count >= argc) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given command line option '%s' requires %d parameter(s), use '-h' for help!\n", argv[argi], option->parameter_count); + LOGP(DOPTIONS, LOGL_ERROR, "Given command line option '%s' requires %d parameter(s), use '-h' for help!\n", argv[argi], option->parameter_count); return -EINVAL; } rc = handle_options(option->short_option, argi + 1, argv); @@ -306,7 +306,7 @@ int options_command_line(int argc, char *argv[], int (*handle_options)(int short /* no more options, so we check if there is an option after a non-option parameter */ for (i = argi; i < argc; i++) { if (argv[i][0] == '-') { - PDEBUG(DOPTIONS, DEBUG_ERROR, "Given command line option '%s' behind command line parameter '%s' not allowed! Please put all command line options before command line parameter(s).\n", argv[i], argv[argi]); + LOGP(DOPTIONS, LOGL_ERROR, "Given command line option '%s' behind command line parameter '%s' not allowed! Please put all command line options before command line parameter(s).\n", argv[i], argv[argi]); return -EINVAL; } } diff --git a/src/libosmocc/Makefile.am b/src/libosmocc/Makefile.am deleted file mode 100644 index 27c0f6c..0000000 --- a/src/libosmocc/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) - -noinst_LIBRARIES = libosmocc.a - -libosmocc_a_SOURCES = \ - message.c \ - socket.c \ - cause.c \ - screen.c \ - endpoint.c \ - session.c \ - sdp.c \ - rtp.c \ - helper.c - diff --git a/src/libosmocc/cause.c b/src/libosmocc/cause.c deleted file mode 100644 index df2b07b..0000000 --- a/src/libosmocc/cause.c +++ /dev/null @@ -1,251 +0,0 @@ -/* OSMO-CC Processing: convert causes - * - * (C) 2019 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdint.h> -#include <arpa/inet.h> -#include "message.h" -#include "cause.h" - -/* stolen from freeswitch, did some corrections */ -/* map sip responses to QSIG cause codes ala RFC4497 section 8.4.4 */ -static uint8_t status2isdn_cause(uint16_t status) -{ - switch (status) { - case 200: - return 16; //SWITCH_CAUSE_NORMAL_CLEARING; - case 401: - case 402: - case 403: - case 407: - case 603: - return 21; //SWITCH_CAUSE_CALL_REJECTED; - case 404: - case 485: - case 604: - return 1; //SWITCH_CAUSE_UNALLOCATED_NUMBER; - case 408: - case 504: - return 102; //SWITCH_CAUSE_RECOVERY_ON_TIMER_EXPIRE; - case 410: - return 22; //SWITCH_CAUSE_NUMBER_CHANGED; - case 413: - case 414: - case 416: - case 420: - case 421: - case 423: - case 505: - case 513: - return 127; //SWITCH_CAUSE_INTERWORKING; - case 480: - return 18; //SWITCH_CAUSE_NO_USER_RESPONSE; - case 400: - case 481: - case 500: - case 503: - return 41; //SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE; - case 486: - case 600: - return 17; //SWITCH_CAUSE_USER_BUSY; - case 484: - return 28; //SWITCH_CAUSE_INVALID_NUMBER_FORMAT; - case 488: - case 606: - return 65; //SWITCH_CAUSE_BERER_CAPABILITY_NOT_IMPLEMENTED; - case 502: - return 38; //SWITCH_CAUSE_NETWORK_OUT_OF_ORDER; - case 405: - return 63; //SWITCH_CAUSE_SERVICE_UNAVAILABLE; - case 406: - case 415: - case 501: - return 79; //SWITCH_CAUSE_SERVICE_NOT_IMPLEMENTED; - case 482: - case 483: - return 25; //SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR; - case 487: - return 31; //??? SWITCH_CAUSE_ORIGINATOR_CANCEL; (not specified) - default: - return 31; //SWITCH_CAUSE_NORMAL_UNSPECIFIED; - } -} - -static uint16_t isdn2status_cause(uint8_t cause, uint8_t location) -{ - switch (cause) { - case 1: - return 404; - case 2: - return 404; - case 3: - return 404; - case 17: - return 486; - case 18: - return 408; - case 19: - return 480; - case 20: - return 480; - case 21: - if (location == OSMO_CC_LOCATION_USER) - return 603; - return 403; - case 22: - //return 301; - return 410; - case 23: - return 410; - case 26: - return 404; - case 27: - return 502; - case 28: - return 484; - case 29: - return 501; - case 31: - return 480; - case 34: - return 503; - case 38: - return 503; - case 41: - return 503; - case 42: - return 503; - case 47: - return 503; - case 55: - return 403; - case 57: - return 403; - case 58: - return 503; - case 65: - return 488; - case 69: - return 501; - case 70: - return 488; - case 79: - return 501; - case 87: - return 403; - case 88: - return 503; - case 102: - return 504; - case 111: - return 500; - case 127: - return 500; - default: - return 468; - } -} - -static uint8_t socket2isdn_cause(uint8_t sock) -{ - switch (sock) { - case OSMO_CC_SOCKET_CAUSE_FAILED: - return 47; - case OSMO_CC_SOCKET_CAUSE_BROKEN_PIPE: - return 41; - case OSMO_CC_SOCKET_CAUSE_VERSION_MISMATCH: - return 38; - case OSMO_CC_SOCKET_CAUSE_TIMEOUT: - return 41; - default: - return 31; - } -} - -void osmo_cc_convert_cause(struct osmo_cc_ie_cause *cause) -{ - /* complete cause, from socket cause */ - if (cause->socket_cause && cause->isdn_cause == 0 && ntohs(cause->sip_cause_networkorder) == 0) - cause->isdn_cause = socket2isdn_cause(cause->socket_cause); - - /* convert ISDN cause to SIP cause */ - if (cause->isdn_cause && ntohs(cause->sip_cause_networkorder) == 0) { - cause->sip_cause_networkorder = htons(isdn2status_cause(cause->isdn_cause, cause->location)); - } - - /* convert SIP cause to ISDN cause */ - if (ntohs(cause->sip_cause_networkorder) && cause->isdn_cause == 0) { - cause->isdn_cause = status2isdn_cause(ntohs(cause->sip_cause_networkorder)); - } - - /* no cause at all: use Normal Call Clearing */ - if (cause->isdn_cause == 0 && ntohs(cause->sip_cause_networkorder) == 0) { - cause->isdn_cause = OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR; - cause->sip_cause_networkorder = htons(486); - } -} - -void osmo_cc_convert_cause_msg(osmo_cc_msg_t *msg) -{ - void *ie; - uint8_t type; - uint16_t length; - void *value; - - /* search for (all) cause IE and convert the values, if needed */ - ie = msg->data; - while ((value = osmo_cc_msg_sep_ie(msg, &ie, &type, &length))) { - if (type == OSMO_CC_IE_CAUSE && length >= sizeof(struct osmo_cc_ie_cause)) { - osmo_cc_convert_cause(value); - } - } -} - -uint8_t osmo_cc_collect_cause(uint8_t old_cause, uint8_t new_cause) -{ - /* first cause */ - if (old_cause == 0) - return new_cause; - - /* first prio: return 17 */ - if (old_cause == OSMO_CC_ISDN_CAUSE_USER_BUSY - || new_cause == OSMO_CC_ISDN_CAUSE_USER_BUSY) - return OSMO_CC_ISDN_CAUSE_USER_BUSY; - - /* second prio: return 21 */ - if (old_cause == OSMO_CC_ISDN_CAUSE_CALL_REJECTED - || new_cause == OSMO_CC_ISDN_CAUSE_CALL_REJECTED) - return OSMO_CC_ISDN_CAUSE_CALL_REJECTED; - - /* third prio: return other than 88 and 18 (what ever was first) */ - if (old_cause != OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST - && old_cause != OSMO_CC_ISDN_CAUSE_USER_NOTRESPOND) - return old_cause; - if (new_cause != OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST - && new_cause != OSMO_CC_ISDN_CAUSE_USER_NOTRESPOND) - return new_cause; - - /* fourth prio: return 88 */ - if (old_cause == OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST - || new_cause == OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST) - return OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST; - - /* fith prio: return 18 */ - return OSMO_CC_ISDN_CAUSE_USER_NOTRESPOND; -} - diff --git a/src/libosmocc/cause.h b/src/libosmocc/cause.h deleted file mode 100644 index 22319f4..0000000 --- a/src/libosmocc/cause.h +++ /dev/null @@ -1,5 +0,0 @@ - -void osmo_cc_convert_cause(struct osmo_cc_ie_cause *cause); -void osmo_cc_convert_cause_msg(osmo_cc_msg_t *msg); -uint8_t osmo_cc_collect_cause(uint8_t old_cause, uint8_t new_cause); - diff --git a/src/libosmocc/endpoint.c b/src/libosmocc/endpoint.c deleted file mode 100644 index e78b3ed..0000000 --- a/src/libosmocc/endpoint.c +++ /dev/null @@ -1,1585 +0,0 @@ -/* Endpoint and call process handling - * - * (C) 2019 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include <arpa/inet.h> -#include <unistd.h> -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libdebug/debug.h" -#include "endpoint.h" - -osmo_cc_endpoint_t *osmo_cc_endpoint_list = NULL; - -static osmo_cc_call_t *call_new(osmo_cc_endpoint_t *ep, uint32_t callref) -{ - osmo_cc_call_t *call, **cp; - - call = calloc(1, sizeof(*call)); - if (!call) { - LOGP(DCC, LOGL_ERROR, "No memory for call process instance.\n"); - abort(); - } - - LOGP(DCC, LOGL_DEBUG, "Creating new call with callref %u.\n", callref); - - call->ep = ep; - call->callref = callref; - - /* attach to call process list */ - cp = &ep->call_list; - while (*cp) - cp = &((*cp)->next); - *cp = call; - - /* return new entry */ - return call; -} - -static void call_delete(osmo_cc_call_t *call) -{ - osmo_cc_call_t **cp; - - LOGP(DCC, LOGL_DEBUG, "Destroying call with callref %u.\n", call->callref); - - /* detach from call process list */ - cp = &call->ep->call_list; - while (*cp != call) - cp = &((*cp)->next); - *cp = call->next; - - /* flush message queue */ - while (call->sock_queue) { - osmo_cc_msg_t *msg = osmo_cc_msg_list_dequeue(&call->sock_queue, NULL); - osmo_cc_free_msg(msg); - } - - /* free remote peer */ - free((char *)call->attached_name); - free((char *)call->attached_host); - - free(call); -} - -static const char *state_names[] = { - "IDLE", - "INIT-OUT", - "INIT-IN", - "OVERLAP-OUT", - "OVERLAP-IN", - "PROCEEDING-OUT", - "PROCEEDING-IN", - "ALERTING-OUT", - "ALERTING-IN", - "CONNECTING-OUT", - "CONNECTING-IN", - "ACTIVE", - "DISCONNECTING-OUT", - "DISCONNECTING-IN", - "DISCONNECT-COLLISION", - "RELEASING-OUT", - "ATTACH-SENT", - "ATTACH-OUT", - "ATTACH-WAIT", - "ATTACH-IN", -}; - -static void new_call_state(osmo_cc_call_t *call, enum osmo_cc_state new_state) -{ - LOGP(DCC, LOGL_DEBUG, "Changing call state with callref %u from %s to %s.\n", call->callref, state_names[call->state], state_names[new_state]); - call->state = new_state; -} - -/* helper to forward message to lower layer */ -static void forward_to_ll(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - if (call->lower_layer_released) - return; - - if (msg->type == OSMO_CC_MSG_SETUP_REQ - || msg->type == OSMO_CC_MSG_SETUP_RSP) { - /* screen towards lower layer */ - msg = osmo_cc_screen_msg(call->ep, msg, 0, NULL); - } - - osmo_cc_msg_list_enqueue(&call->ep->ll_queue, msg, call->callref); -} - -static void sock_reject_msg(osmo_cc_socket_t *os, uint32_t callref, uint8_t location, uint8_t socket_cause, uint8_t isdn_cause, uint16_t sip_cause) -{ - osmo_cc_msg_t *msg; - - /* create message */ - msg = osmo_cc_new_msg(OSMO_CC_MSG_REJ_IND); - - /* add cause */ - osmo_cc_add_ie_cause(msg, location, isdn_cause, sip_cause, socket_cause); - osmo_cc_convert_cause_msg(msg); - - /* message to socket */ - osmo_cc_sock_send_msg(os, callref, msg, NULL, 0); -} - -static void ll_reject_msg(osmo_cc_call_t *call, uint8_t location, uint8_t socket_cause, uint8_t isdn_cause, uint16_t sip_cause) -{ - osmo_cc_msg_t *msg; - - /* create message */ - msg = osmo_cc_new_msg(OSMO_CC_MSG_REJ_REQ); - - /* add cause */ - osmo_cc_add_ie_cause(msg, location, isdn_cause, sip_cause, socket_cause); - osmo_cc_convert_cause_msg(msg); - - /* message to lower layer */ - forward_to_ll(call, msg); -} - -static int split_address(const char *address, const char **host_p, uint16_t *port_p) -{ - const char *portstring; - - *host_p = osmo_cc_host_of_address(address); - if (!(*host_p)) { - LOGP(DCC, LOGL_ERROR, "Host IP in given address '%s' is invalid.\n", address); - return -EINVAL; - } - portstring = osmo_cc_port_of_address(address); - if (!portstring) { - LOGP(DCC, LOGL_ERROR, "Port number in given address '%s' is not specified or invalid.\n", address); - return -EINVAL; - } - *port_p = atoi(portstring); - - return 0; -} - - -osmo_cc_call_t *osmo_cc_get_attached_interface(osmo_cc_endpoint_t *ep, const char *interface) -{ - osmo_cc_call_t *att; - - for (att = ep->call_list; att; att = att->next) { - if (att->state != OSMO_CC_STATE_ATTACH_IN) - continue; - /* no interface given, just use the attached peer */ - if (!interface[0]) - break; - /* no interface name given on attached peer, ignore it */ - if (!att->attached_name || !att->attached_name[0]) - continue; - /* interface given, use the attached peer with the same interface name */ - if (!strcmp(interface, att->attached_name)) - break; - } - - return att; -} -/* helper to forward message to upper layer */ -static void forward_to_ul(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - const char *address = NULL, *host = NULL; - uint16_t port; - int rc; - - if (call->upper_layer_released) - return; - - if (msg->type == OSMO_CC_MSG_SETUP_IND - || msg->type == OSMO_CC_MSG_SETUP_CNF) { - /* screen towards upper layer */ - msg = osmo_cc_screen_msg(call->ep, msg, 1, &address); - } - - /* no socket: forward message to upper layer */ - if (call->ep->ul_msg_cb) { - call->ep->ul_msg_cb(call, msg); - return; - } - - /* if remote peer is included in the setup message */ - if (address && msg->type == OSMO_CC_MSG_SETUP_IND) { - rc = split_address(address, &host, &port); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "Given remote peer's address '%s' in setup message is invalid, rejecting call.\n", address); -reject: - /* reject, due to error */ - osmo_cc_free_msg(msg); - new_call_state(call, OSMO_CC_STATE_IDLE); - ll_reject_msg(call, call->ep->serving_location, 0, OSMO_CC_ISDN_CAUSE_DEST_OOO, 0); - call_delete(call); - return; - } - LOGP(DCC, LOGL_DEBUG, "Using host IP '%s' and port '%d' from setup message.\n", host, port); - } - - /* for attach message, use remote peer */ - if (msg->type == OSMO_CC_MSG_ATTACH_IND) { - host = call->ep->remote_host; - port = call->ep->remote_port; - LOGP(DCC, LOGL_DEBUG, "Using host IP '%s' and port '%d' from remote address for attach message.\n", host, port); - } - - /* if there is no remote peer in the setup message, use remote peer */ - if (!address && msg->type == OSMO_CC_MSG_SETUP_IND && call->ep->remote_host) { - host = call->ep->remote_host; - port = call->ep->remote_port; - LOGP(DCC, LOGL_DEBUG, "Using host IP '%s' and port '%d' from remote address for setup message.\n", host, port); - } - - /* if there is no remote peer set, try to use the interface name */ - if (!host && msg->type == OSMO_CC_MSG_SETUP_IND) { - char interface[256]; - osmo_cc_call_t *att; - - rc = osmo_cc_get_ie_called_interface(msg, 0, interface, sizeof(interface)); - if (rc < 0) - interface[0] = '\0'; - /* check for incoming attachment */ - att = osmo_cc_get_attached_interface(call->ep, interface); - if (!att && !interface[0]) { - LOGP(DCC, LOGL_ERROR, "No remote peer attached, rejecting call.\n"); - goto reject; - } - if (!att) { - LOGP(DCC, LOGL_ERROR, "No remote peer attached for given interface '%s', rejecting call.\n", interface); - goto reject; - } - host = att->attached_host; - port = att->attached_port; - LOGP(DCC, LOGL_DEBUG, "Using host IP '%s' and port '%d' from attached peer for setup message.\n", host, port); - } - - /* add local interface name to setup message */ - // FIXME: should we do that if there is already an interface name given? - if (msg->type == OSMO_CC_MSG_SETUP_IND && call->ep->local_name) - osmo_cc_add_ie_calling_interface(msg, call->ep->local_name); - - /* forward message to socket */ - osmo_cc_sock_send_msg(&call->ep->os, call->callref, msg, host, port); -} - -/* send attach indication to socket */ -void send_attach_ind(void *data) -{ - osmo_cc_endpoint_t *ep = data; - osmo_cc_call_t *call; - osmo_cc_msg_t *msg; - - LOGP(DCC, LOGL_DEBUG, "Trying to attach to remote peer \"%s\".\n", ep->remote_host); - - /* create new call for attachment */ - call = osmo_cc_call_new(ep); - - /* create attach message */ - msg = osmo_cc_new_msg(OSMO_CC_MSG_ATTACH_IND); - - /* set interface name and address */ - osmo_cc_add_ie_calling_interface(msg, ep->local_name); - osmo_cc_add_ie_socket_address(msg, ep->local_address); - - /* message to socket */ - forward_to_ul(call, msg); - - /* set state */ - new_call_state(call, OSMO_CC_STATE_ATTACH_SENT); -} - -void attach_rsp(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - LOGP(DCC, LOGL_INFO, "Attached to remote peer \"%s\".\n", call->ep->remote_address); - - /* set state */ - new_call_state(call, OSMO_CC_STATE_ATTACH_OUT); - - /* drop message */ - osmo_cc_free_msg(msg); -} - -void attach_rel(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* (re-)start timer for next attachment */ - if (call->state == OSMO_CC_STATE_ATTACH_SENT - || call->state == OSMO_CC_STATE_ATTACH_OUT) { - timer_start(&call->ep->attach_timer, OSMO_CC_ATTACH_TIMER); - LOGP(DCC, LOGL_INFO, "Attachment to remote peer \"%s\" failed, retrying.\n", call->ep->remote_address); - } - - if (call->attached_name) - LOGP(DCC, LOGL_INFO, "Peer with remote interface \"%s\" detached from us.\n", call->attached_name); - - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* unset interface */ - free((char *)call->attached_name); - call->attached_name = NULL; - free((char *)call->attached_host); - call->attached_host = NULL; - - /* drop message */ - osmo_cc_free_msg(msg); - - /* destroy */ - call_delete(call); -} - -void attach_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - char address[256]; - char interface[256]; - const char *host; - uint16_t port; - int rc; - - /* get peer from message */ - rc = osmo_cc_get_ie_socket_address(msg, 0, address, sizeof(address)); - if (rc < 0) - address[0] = '\0'; - if (!address[0]) { - LOGP(DCC, LOGL_ERROR, "Attachment request from remote peer has no remote address set, rejecting.\n"); - -rel: - /* change to REL_REQ */ - msg->type = OSMO_CC_MSG_REL_IND; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - - /* message to socket */ - forward_to_ul(call, msg); - - /* destroy */ - call_delete(call); - - return; - } - rc = split_address(address, &host, &port); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "Given remote peer's address '%s' in attach message is invalid, rejecting call.\n", address); - goto rel; - } - free((char *)call->attached_host); - call->attached_host = strdup(host); - call->attached_port = port; - - rc = osmo_cc_get_ie_calling_interface(msg, 0, interface, sizeof(interface)); - if (rc < 0) - interface[0] = '\0'; - if (interface[0]) { - free((char *)call->attached_name); - call->attached_name = strdup(interface); - } - - LOGP(DCC, LOGL_INFO, "Remote peer with socket address '%s' and port '%d' and interface '%s' attached to us.\n", call->attached_host, call->attached_port, call->attached_name); - - /* changing to confirm message */ - msg->type = OSMO_CC_MSG_ATTACH_CNF; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - - /* message to socket */ - forward_to_ul(call, msg); - - /* set state */ - new_call_state(call, OSMO_CC_STATE_ATTACH_IN); -} - -static void setup_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_INIT_OUT); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void setup_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_INIT_IN); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void rej_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* to lower layer */ - forward_to_ll(call, msg); - - /* destroy */ - call_delete(call); -} - -static void rej_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* to upper layer */ - forward_to_ul(call, msg); - - /* destroy */ - call_delete(call); -} - -static void setup_ack_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_OVERLAP_IN); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void setup_ack_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_OVERLAP_OUT); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void proc_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_PROCEEDING_IN); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void proc_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_PROCEEDING_OUT); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void alert_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_ALERTING_IN); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void alert_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_ALERTING_OUT); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void setup_rsp(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_CONNECTING_IN); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void setup_cnf(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_CONNECTING_OUT); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void setup_comp_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_ACTIVE); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void setup_comp_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_ACTIVE); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void info_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void info_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void progress_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void progress_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void notify_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void notify_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void modify_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void modify_cnf(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void modify_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void modify_rsp(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void disc_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_DISCONNECTING_OUT); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void disc_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_DISCONNECTING_IN); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void rel_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* terminate process, if there is no lower layer anmore */ - if (call->lower_layer_released) { - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* drop message */ - osmo_cc_free_msg(msg); - - /* destroy */ - call_delete(call); - - return; - } - - /* change state */ - new_call_state(call, OSMO_CC_STATE_RELEASING_OUT); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void rel_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* to upper layer */ - forward_to_ul(call, msg); - - /* destroy */ - call_delete(call); -} - -static void rel_cnf(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* drop message */ - osmo_cc_free_msg(msg); - - /* destroy */ - call_delete(call); -} - -static void disc_collision_ind(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* release to lower layer wheen there is no upper layer */ - if (call->upper_layer_released) { - /* change state */ - new_call_state(call, OSMO_CC_STATE_RELEASING_OUT); - - /* change to REL_REQ */ - msg->type = OSMO_CC_MSG_REL_REQ; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - - /* to lower layer */ - forward_to_ll(call, msg); - - return; - } - - /* change state */ - new_call_state(call, OSMO_CC_STATE_DISC_COLLISION); - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void disc_collision_req(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* release to upper layer wheen there is no lower layer */ - if (call->lower_layer_released) { - /* change to REL_REQ */ - msg->type = OSMO_CC_MSG_REL_IND; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - - /* to upper layer */ - forward_to_ul(call, msg); - - /* destroy */ - call_delete(call); - - return; - } - - /* change state */ - new_call_state(call, OSMO_CC_STATE_DISC_COLLISION); - - /* to lower layer */ - forward_to_ll(call, msg); -} - -static void rel_collision(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - if (call->state != OSMO_CC_STATE_IDLE) - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* drop message */ - osmo_cc_free_msg(msg); - - /* destroy */ - call_delete(call); -} - -static void rej_ind_disc(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* change to REL_IND */ - msg->type = OSMO_CC_MSG_REL_IND; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - - /* to upper layer */ - forward_to_ul(call, msg); - - /* destroy */ - call_delete(call); -} - -static void rej_req_disc(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - /* change state */ - new_call_state(call, OSMO_CC_STATE_IDLE); - - /* change to REL_REQ */ - msg->type = OSMO_CC_MSG_REL_REQ; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - - /* to lower layer */ - forward_to_ll(call, msg); - - /* destroy */ - call_delete(call); -} - -static void rel_ind_other(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - // FIXME: does this event really happens in this state? - // just to be safe we handle it - /* if thereis no upper layer, we are done */ - if (call->upper_layer_released) { - /* drop message */ - osmo_cc_free_msg(msg); - - /* destroy */ - call_delete(call); - - return; - } - - /* change state */ - new_call_state(call, OSMO_CC_STATE_DISCONNECTING_IN); - - /* change to DISC_IND */ - msg->type = OSMO_CC_MSG_DISC_IND; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - call->lower_layer_released = 1; - - /* to upper layer */ - forward_to_ul(call, msg); -} - -static void rel_req_other(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - // FIXME: does this event really happens in this state? - // just to be safe we handle it - /* if thereis no lower layer, we are done */ - if (call->lower_layer_released) { - /* drop message */ - osmo_cc_free_msg(msg); - - /* destroy */ - call_delete(call); - - return; - } - - /* change state */ - new_call_state(call, OSMO_CC_STATE_DISCONNECTING_OUT); - - /* change to DISC_REQ */ - msg->type = OSMO_CC_MSG_DISC_REQ; - LOGP(DCC, LOGL_INFO, "Changing message to %s.\n", osmo_cc_msg_value2name(msg->type)); - call->upper_layer_released = 1; - - /* to lower layer */ - forward_to_ll(call, msg); -} - -#define SBIT(a) (1 << a) -#define ALL_STATES (~0) - -static struct statemachine { - uint32_t states; - int type; - void (*action)(osmo_cc_call_t *call, osmo_cc_msg_t *msg); -} statemachine_list[] = { - /* attachment states */ - {SBIT(OSMO_CC_STATE_ATTACH_SENT), - OSMO_CC_MSG_ATTACH_RSP, attach_rsp}, - {SBIT(OSMO_CC_STATE_ATTACH_OUT) | SBIT(OSMO_CC_STATE_ATTACH_SENT), - OSMO_CC_MSG_REL_REQ, attach_rel}, - {SBIT(OSMO_CC_STATE_IDLE), - OSMO_CC_MSG_ATTACH_REQ, attach_req}, - {SBIT(OSMO_CC_STATE_ATTACH_IN), - OSMO_CC_MSG_REL_REQ, attach_rel}, - - /* call setup toward lower layer protocol */ - {SBIT(OSMO_CC_STATE_IDLE), - OSMO_CC_MSG_SETUP_REQ, setup_req}, - {SBIT(OSMO_CC_STATE_INIT_OUT), - OSMO_CC_MSG_SETUP_ACK_IND, setup_ack_ind}, - {SBIT(OSMO_CC_STATE_INIT_OUT) | SBIT(OSMO_CC_STATE_OVERLAP_OUT), - OSMO_CC_MSG_PROC_IND, proc_ind}, - {SBIT(OSMO_CC_STATE_INIT_OUT) | SBIT(OSMO_CC_STATE_OVERLAP_OUT) | - SBIT(OSMO_CC_STATE_PROCEEDING_OUT), - OSMO_CC_MSG_ALERT_IND, alert_ind}, - {SBIT(OSMO_CC_STATE_INIT_OUT) | SBIT(OSMO_CC_STATE_OVERLAP_OUT) | - SBIT(OSMO_CC_STATE_PROCEEDING_OUT) | SBIT(OSMO_CC_STATE_ALERTING_OUT), - OSMO_CC_MSG_SETUP_CNF, setup_cnf}, - {SBIT(OSMO_CC_STATE_OVERLAP_OUT) | SBIT(OSMO_CC_STATE_PROCEEDING_OUT) | - SBIT(OSMO_CC_STATE_ALERTING_OUT), - OSMO_CC_MSG_PROGRESS_IND, progress_ind}, - {SBIT(OSMO_CC_STATE_OVERLAP_OUT), - OSMO_CC_MSG_INFO_REQ, info_req}, - {SBIT(OSMO_CC_STATE_PROCEEDING_OUT) | SBIT(OSMO_CC_STATE_ALERTING_OUT), - OSMO_CC_MSG_NOTIFY_IND, notify_ind}, - {SBIT(OSMO_CC_STATE_CONNECTING_OUT), - OSMO_CC_MSG_SETUP_COMP_REQ, setup_comp_req}, - - /* call setup from lower layer protocol */ - {SBIT(OSMO_CC_STATE_IDLE), - OSMO_CC_MSG_SETUP_IND, setup_ind}, - {SBIT(OSMO_CC_STATE_INIT_IN), - OSMO_CC_MSG_SETUP_ACK_REQ, setup_ack_req}, - {SBIT(OSMO_CC_STATE_INIT_IN) | SBIT(OSMO_CC_STATE_OVERLAP_IN), - OSMO_CC_MSG_PROC_REQ, proc_req}, - {SBIT(OSMO_CC_STATE_INIT_IN) | SBIT(OSMO_CC_STATE_OVERLAP_IN) | - SBIT(OSMO_CC_STATE_PROCEEDING_IN), - OSMO_CC_MSG_ALERT_REQ, alert_req}, - {SBIT(OSMO_CC_STATE_INIT_IN) | SBIT(OSMO_CC_STATE_OVERLAP_IN) | - SBIT(OSMO_CC_STATE_PROCEEDING_IN) | SBIT(OSMO_CC_STATE_ALERTING_IN), - OSMO_CC_MSG_SETUP_RSP, setup_rsp}, - {SBIT(OSMO_CC_STATE_OVERLAP_IN) | SBIT(OSMO_CC_STATE_PROCEEDING_IN) | - SBIT(OSMO_CC_STATE_ALERTING_IN), - OSMO_CC_MSG_PROGRESS_REQ, progress_req}, - {SBIT(OSMO_CC_STATE_OVERLAP_IN), - OSMO_CC_MSG_INFO_IND, info_ind}, - {SBIT(OSMO_CC_STATE_PROCEEDING_IN) | SBIT(OSMO_CC_STATE_ALERTING_IN), - OSMO_CC_MSG_NOTIFY_REQ, notify_req}, - {SBIT(OSMO_CC_STATE_CONNECTING_IN), - OSMO_CC_MSG_SETUP_COMP_IND, setup_comp_ind}, - - /* active state */ - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_NOTIFY_IND, notify_ind}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_NOTIFY_REQ, notify_req}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_INFO_IND, info_ind}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_INFO_REQ, info_req}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_MODIFY_REQ, modify_req}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_MODIFY_CNF, modify_cnf}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_MODIFY_IND, modify_ind}, - {SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_MODIFY_RSP, modify_rsp}, - - /* call release */ - {SBIT(OSMO_CC_STATE_INIT_OUT) | SBIT(OSMO_CC_STATE_INIT_IN) | - SBIT(OSMO_CC_STATE_OVERLAP_OUT) | SBIT(OSMO_CC_STATE_OVERLAP_IN) | - SBIT(OSMO_CC_STATE_PROCEEDING_OUT) | SBIT(OSMO_CC_STATE_PROCEEDING_IN) | - SBIT(OSMO_CC_STATE_ALERTING_OUT) | SBIT(OSMO_CC_STATE_ALERTING_IN) | - SBIT(OSMO_CC_STATE_CONNECTING_OUT) | SBIT(OSMO_CC_STATE_CONNECTING_IN) | - SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_DISC_REQ, disc_req}, - {SBIT(OSMO_CC_STATE_INIT_OUT) | SBIT(OSMO_CC_STATE_INIT_IN) | - SBIT(OSMO_CC_STATE_OVERLAP_OUT) | SBIT(OSMO_CC_STATE_OVERLAP_IN) | - SBIT(OSMO_CC_STATE_PROCEEDING_OUT) | SBIT(OSMO_CC_STATE_PROCEEDING_IN) | - SBIT(OSMO_CC_STATE_ALERTING_OUT) | SBIT(OSMO_CC_STATE_ALERTING_IN) | - SBIT(OSMO_CC_STATE_CONNECTING_OUT) | SBIT(OSMO_CC_STATE_CONNECTING_IN) | - SBIT(OSMO_CC_STATE_ACTIVE), - OSMO_CC_MSG_DISC_IND, disc_ind}, - {SBIT(OSMO_CC_STATE_INIT_OUT), - OSMO_CC_MSG_REJ_IND, rej_ind}, - {SBIT(OSMO_CC_STATE_INIT_IN), - OSMO_CC_MSG_REJ_REQ, rej_req}, - {SBIT(OSMO_CC_STATE_DISCONNECTING_OUT), - OSMO_CC_MSG_REL_IND, rel_ind}, - {SBIT(OSMO_CC_STATE_DISCONNECTING_IN), - OSMO_CC_MSG_REL_REQ, rel_req}, - {SBIT(OSMO_CC_STATE_RELEASING_OUT), - OSMO_CC_MSG_REL_CNF, rel_cnf}, - - /* race condition where disconnect is received after disconnecting (disconnect collision) */ - {SBIT(OSMO_CC_STATE_DISCONNECTING_OUT), - OSMO_CC_MSG_DISC_IND, disc_collision_ind}, - {SBIT(OSMO_CC_STATE_DISCONNECTING_IN), - OSMO_CC_MSG_DISC_REQ, disc_collision_req}, - {SBIT(OSMO_CC_STATE_DISC_COLLISION), - OSMO_CC_MSG_REL_IND, rel_ind}, - {SBIT(OSMO_CC_STATE_DISC_COLLISION), - OSMO_CC_MSG_REL_REQ, rel_req}, - - /* race condition where release is received after releasing (release collision) */ - {SBIT(OSMO_CC_STATE_RELEASING_OUT), - OSMO_CC_MSG_REL_IND, rel_collision}, - {SBIT(OSMO_CC_STATE_IDLE), - OSMO_CC_MSG_REL_REQ, rel_collision}, - - /* race condition where reject is received after disconnecting */ - {SBIT(OSMO_CC_STATE_DISCONNECTING_OUT), - OSMO_CC_MSG_REJ_IND, rej_ind_disc}, - {SBIT(OSMO_CC_STATE_DISCONNECTING_IN), - OSMO_CC_MSG_REJ_REQ, rej_req_disc}, - - /* turn release into disconnect, so release is possible in any state */ - {ALL_STATES, - OSMO_CC_MSG_REL_IND, rel_ind_other}, - {ALL_STATES, - OSMO_CC_MSG_REL_REQ, rel_req_other}, -}; - -#define STATEMACHINE_LEN \ - (sizeof(statemachine_list) / sizeof(struct statemachine)) - -static void handle_msg(osmo_cc_call_t *call, osmo_cc_msg_t *msg) -{ - int i; - - /* Find function for current state and message */ - for (i = 0; i < (int)STATEMACHINE_LEN; i++) - if ((msg->type == statemachine_list[i].type) - && ((1 << call->state) & statemachine_list[i].states)) - break; - if (i == STATEMACHINE_LEN) { - LOGP(DCC, LOGL_INFO, "Message %s unhandled at state %s (callref %d)\n", - osmo_cc_msg_value2name(msg->type), state_names[call->state], call->callref); - osmo_cc_free_msg(msg); - return; - } - - LOGP(DCC, LOGL_INFO, "Handle message %s at state %s (callref %d)\n", - osmo_cc_msg_value2name(msg->type), state_names[call->state], call->callref); - if (debuglevel <= LOGL_INFO) - osmo_cc_debug_ie(msg, LOGL_INFO); - statemachine_list[i].action(call, msg); -} - -static int handle_call(osmo_cc_call_t *call) -{ - /* may handle only one message, since call may be destroyed when handling */ - if (call->sock_queue) { - osmo_cc_msg_t *msg = osmo_cc_msg_list_dequeue(&call->sock_queue, NULL); - handle_msg(call, msg); - return 1; - } - - return 0; -} - -static int osmo_cc_handle_endpoint(osmo_cc_endpoint_t *ep) -{ - int work = 0; - uint32_t callref; - osmo_cc_call_t *call; - - /* may handle only one message, since call may be destroyed when handling */ - if (ep->ll_queue) { - osmo_cc_msg_t *msg = osmo_cc_msg_list_dequeue(&ep->ll_queue, &callref); - ep->ll_msg_cb(ep, callref, msg); - work |= 1; - } - - /* handle only one call, because it might have been removed */ - for (call = ep->call_list; call; call = call->next) { - work |= handle_call(call); - if (work) - break; - } - - return work; -} - -/* main handler - * note that it must be called in a loop (with other handlers) until no work was done - */ -int osmo_cc_handle(void) -{ - int work = 0; - osmo_cc_endpoint_t *ep; - - for (ep = osmo_cc_endpoint_list; ep; ep = ep->next) { - work |= osmo_cc_handle_endpoint(ep); - work |= osmo_cc_handle_socket(&ep->os); - } - - return work; -} - -osmo_cc_call_t *osmo_cc_call_by_callref(osmo_cc_endpoint_t *ep, uint32_t callref) -{ - osmo_cc_call_t *call; - - if (!callref) - return NULL; - - for (call = ep->call_list; call; call = call->next) { - if (call->callref == callref) { - return call; - } - } - - return NULL; -} - - -void osmo_cc_ll_msg(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg) -{ - osmo_cc_call_t *call; - - if (!(msg->type & 1)) { - LOGP(DCC, LOGL_ERROR, "Received message from lower layer that is not an _IND nor _CNF, please fix!\n"); - osmo_cc_free_msg(msg); - return; - } - - call = osmo_cc_call_by_callref(ep, callref); - if (call) { - /* complete cause */ - osmo_cc_convert_cause_msg(msg); - handle_msg(call, msg); - return; - } - - /* if no ref exists */ -} - -/* message from upper layer (socket) */ -void osmo_cc_ul_msg(void *priv, uint32_t callref, osmo_cc_msg_t *msg) -{ - osmo_cc_endpoint_t *ep = priv; - osmo_cc_call_t *call; - - if ((msg->type & 1)) { - LOGP(DCC, LOGL_ERROR, "Received message from socket that is not an _REQ nor _RSP, please fix!\n"); - osmo_cc_free_msg(msg); - return; - } - - call = osmo_cc_call_by_callref(ep, callref); - if (call) { - /* if we are not in INIT-IN state, we change a CC-REJ-REQ into CC-REL_REQ. - * this happens, if the socket fails. - */ - if (call->state != OSMO_CC_STATE_INIT_IN - && msg->type == OSMO_CC_MSG_REJ_REQ) - msg->type = OSMO_CC_MSG_REL_REQ; - - osmo_cc_msg_list_enqueue(&call->sock_queue, msg, call->callref); - return; - } - - /* if no ref exists */ - - /* reject and release are ignored */ - if (msg->type == OSMO_CC_MSG_REJ_REQ - || msg->type == OSMO_CC_MSG_REL_REQ) { - osmo_cc_free_msg(msg); - return; - } - - /* reject if not a setup/attach or release message */ - if (msg->type != OSMO_CC_MSG_SETUP_REQ - && msg->type != OSMO_CC_MSG_ATTACH_REQ) { - sock_reject_msg(&ep->os, callref, ep->serving_location, 0, OSMO_CC_ISDN_CAUSE_INVAL_CALLREF, 0); - osmo_cc_free_msg(msg); - return; - } - - /* create call instance with one socket reference */ - call = call_new(ep, callref); - - osmo_cc_msg_list_enqueue(&call->sock_queue, msg, call->callref); -} - -static void osmo_cc_help_name(void) -{ - printf("Name options:\n\n"); - - printf("name <name>\n"); - - printf("Allows to override endpoint name given by application.\n"); -} - -static int osmo_cc_set_name(osmo_cc_endpoint_t *ep, const char *text) -{ - if (!strncasecmp(text, "name", 4)) { - text += 4; - /* remove spaces after keyword */ - while (*text) { - if (*text > 32) - break; - text++; - } - } else { - LOGP(DCC, LOGL_ERROR, "Invalid name definition '%s'\n", text); - return -EINVAL; - } - - free((char *)ep->local_name); - ep->local_name = strdup(text); - - return 0; -} - -static void osmo_cc_help_address(void) -{ - printf("Address options:\n\n"); - - printf("local <IPv4 address>:<port>\n"); - printf("local [<IPv6 address>]:<port>\n"); - printf("remote <IPv4 address>:<port>\n"); - printf("remote [<IPv6 address>]:<port>\n\n"); - printf("remote auto\n\n"); - printf("remote none\n\n"); - - printf("These options can be used to define local and remote IP and port for the socket\n"); - printf("interface. Note that IPv6 addresses must be enclosed by '[' and ']'.\n\n"); - - printf("If no local address was given, the IPv4 loopback IP and port %d is used. If\n", OSMO_CC_DEFAULT_PORT); - printf("this port is already in use, the first free higher port is used.\n\n"); - - printf("If no remote address is given, the local IP is used. If the local port is %d,\n", OSMO_CC_DEFAULT_PORT); - printf("the remote port will be %d. If not, the remote port will be %d. This way it is\n", OSMO_CC_DEFAULT_PORT + 1, OSMO_CC_DEFAULT_PORT); - printf("possible to link two interfaces without any IP configuration required.\n\n"); - - printf("Use 'remote auto' to enable and 'remote none' to disable. This can be useful to\n"); - printf("override application default.\n\n"); -} - -static int osmo_cc_set_address(osmo_cc_endpoint_t *ep, const char *text) -{ - const char **address_p, **host_p; - uint16_t *port_p; - int local = 0; - int rc; - - if (!strncasecmp(text, "local", 5)) { - text += 5; - /* remove spaces after keyword */ - while (*text) { - if (*text > 32) - break; - text++; - } - address_p = &ep->local_address; - host_p = &ep->local_host; - port_p = &ep->local_port; - local = 1; - } else if (!strncasecmp(text, "remote", 6)) { - text += 6; - /* remove spaces after keyword */ - while (*text) { - if (*text > 32) - break; - text++; - } - if (!strcasecmp(text, "auto")) { - LOGP(DCC, LOGL_DEBUG, "setting automatic remote peer selection\n"); - ep->remote_auto = 1; - return 0; - } - if (!strcasecmp(text, "none")) { - LOGP(DCC, LOGL_DEBUG, "disable automatic remote peer selection\n"); - ep->remote_auto = 0; - return 0; - } - ep->remote_auto = 0; - address_p = &ep->remote_address; - host_p = &ep->remote_host; - port_p = &ep->remote_port; - } else { - LOGP(DCC, LOGL_ERROR, "Invalid local or remote address definition '%s'\n", text); - return -EINVAL; - } - - if (*address_p) { - free((char *)*address_p); - *address_p = NULL; - } - if (*host_p) { - free((char *)*host_p); - *host_p = NULL; - } - rc = split_address(text, host_p, port_p); - if (rc < 0) { - /* unset, so that this is not treated with free() */ - *host_p = NULL; - return rc; - } - *address_p = strdup(text); - *host_p = strdup(*host_p); - - if (local) { - enum osmo_cc_session_addrtype addrtype; - addrtype = osmo_cc_address_type(*host_p); - if (addrtype == osmo_cc_session_addrtype_unknown) { - LOGP(DCC, LOGL_ERROR, "Given local address '%s' is invalid.\n", *host_p); - return -EINVAL; - } - osmo_cc_set_local_peer(&ep->session_config, osmo_cc_session_nettype_inet, addrtype, *host_p); - return 0; - } - - return 0; -} - -static void osmo_cc_help_rtp(void) -{ - printf("RTP options:\n\n"); - - printf("rtp-peer <IPv4 address>\n"); - printf("rtp-peer <IPv6 address>\n"); - printf("rtp-ports <first> <last>\n\n"); - - printf("These options can be used to alter the local IP and port range for RTP traffic.\n"); - printf("By default the local peer is used, which is loopback by default. To connect\n"); - printf("interfaces, between machines, local machine's IP must be given.\n\n"); -} - -static int osmo_cc_set_rtp(osmo_cc_endpoint_t *ep, const char *text) -{ - int peer = 0, ports = 0; - - if (!strncasecmp(text, "rtp-peer", 8)) { - text += 8; - peer = 1; - } else if (!strncasecmp(text, "rtp-ports", 9)) { - text += 9; - ports = 1; - } else { - LOGP(DCC, LOGL_ERROR, "Invalid RTP definition '%s'\n", text); - return -EINVAL; - } - - /* remove spaces after keyword */ - while (*text) { - if (*text > 32) - break; - text++; - } - - if (peer) { - enum osmo_cc_session_addrtype addrtype; - addrtype = osmo_cc_address_type(text); - if (addrtype == osmo_cc_session_addrtype_unknown) { - LOGP(DCC, LOGL_ERROR, "Given RTP address '%s' is invalid.\n", text); - return -EINVAL; - } - osmo_cc_set_local_peer(&ep->session_config, osmo_cc_session_nettype_inet, addrtype, text); - return 0; - } - - if (ports) { - int from = 0, to = 0; - - /* from port */ - while (*text > ' ') { - if (*text < '0' || *text > '9') { - LOGP(DCC, LOGL_ERROR, "Given 'from' port in '%s' is invalid.\n", text); - return -EINVAL; - } - from = from * 10 + *text - '0'; - text++; - } - - /* remove spaces after keyword */ - while (*text) { - if (*text > 32) - break; - text++; - } - - /* to port */ - while (*text > ' ') { - if (*text < '0' || *text > '9') { - LOGP(DCC, LOGL_ERROR, "Given 'to' port in '%s' is invalid.\n", text); - return -EINVAL; - } - to = to * 10 + *text - '0'; - text++; - } - - osmo_cc_set_rtp_ports(&ep->session_config, from, to); - return 0; - } - - return -EINVAL; -} - -void osmo_cc_help(void) -{ - osmo_cc_help_name(); - osmo_cc_help_address(); - osmo_cc_help_rtp(); - osmo_cc_help_screen(); -} - -/* create a new endpoint instance */ -int osmo_cc_new(osmo_cc_endpoint_t *ep, const char *version, const char *name, uint8_t serving_location, void (*ll_msg_cb)(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg), void (*ul_msg_cb)(osmo_cc_call_t *call, osmo_cc_msg_t *msg), void *priv, int argc, const char *argv[]) -{ - osmo_cc_endpoint_t **epp; - int rc; - int i; - - LOGP(DCC, LOGL_DEBUG, "Creating new endpoint instance.\n"); - - if (!!strcmp(version, OSMO_CC_VERSION)) { - LOGP(DCC, LOGL_ERROR, "Application was compiled for different Osmo-CC version.\n"); - return OSMO_CC_RC_VERSION_MISMATCH; - } - - memset(ep, 0, sizeof(*ep)); - - /* attach to list */ - epp = &osmo_cc_endpoint_list; - while (*epp) - epp = &((*epp)->next); - *epp = ep; - - if (name) - ep->local_name = strdup(name); - ep->ll_msg_cb = ll_msg_cb; - ep->ul_msg_cb = ul_msg_cb; - ep->serving_location = serving_location; - ep->priv = priv; - - osmo_cc_set_local_peer(&ep->session_config, osmo_cc_session_nettype_inet, osmo_cc_session_addrtype_ipv4, "127.0.0.1"); - osmo_cc_set_rtp_ports(&ep->session_config, 16384, 32767); - - /* apply args */ - for (i = 0; i < argc; i++) { - if (!strncasecmp(argv[i], "name", 4)) { - rc = osmo_cc_set_name(ep, argv[i]); - if (rc < 0) { - return rc; - } - } else - if (!strncasecmp(argv[i], "local", 5)) { - rc = osmo_cc_set_address(ep, argv[i]); - if (rc < 0) { - return rc; - } - } else - if (!strncasecmp(argv[i], "remote", 6)) { - rc = osmo_cc_set_address(ep, argv[i]); - if (rc < 0) { - return rc; - } - } else - if (!strncasecmp(argv[i], "rtp", 3)) { - rc = osmo_cc_set_rtp(ep, argv[i]); - if (rc < 0) { - return rc; - } - } else - if (!strncasecmp(argv[i], "screen", 6)) { - rc = osmo_cc_add_screen(ep, argv[i]); - if (rc < 0) { - return rc; - } - } else { - LOGP(DCC, LOGL_ERROR, "Unknown osmo-cc argument \"%s\"\n", argv[i]); - return -EINVAL; - } - } - - /* open socket */ - if (!ul_msg_cb) { - char address[256]; - const char *host; - uint16_t port; - enum osmo_cc_session_addrtype addrtype; - - host = ep->local_host; - port = ep->local_port; - if (!host) { - host = "127.0.0.1"; - LOGP(DCC, LOGL_DEBUG, "No local peer set, using default \"%s\"\n", host); - } - rc = osmo_cc_open_socket(&ep->os, host, port, ep, osmo_cc_ul_msg, serving_location); - if (rc < 0) { - return rc; - } - port = rc; - if (!ep->local_host) { - ep->local_host = strdup(host); - /* create address string */ - addrtype = osmo_cc_address_type(host); - if (addrtype == osmo_cc_session_addrtype_ipv6) - sprintf(address, "[%s]:%d", host, port); - else - sprintf(address, "%s:%d", host, port); - ep->local_address = strdup(address); - } - ep->local_port = port; - /* auto configure */ - if (ep->remote_auto) { - free((char *)ep->remote_host); - ep->remote_host = strdup(ep->local_host); - LOGP(DCC, LOGL_DEBUG, "Remote peer set to auto, using local peer's host \"%s\" for remote peer.\n", ep->remote_host); - if (rc == OSMO_CC_DEFAULT_PORT) - ep->remote_port = OSMO_CC_DEFAULT_PORT + 1; - else - ep->remote_port = OSMO_CC_DEFAULT_PORT; - LOGP(DCC, LOGL_DEBUG, " -> Using remote port %d.\n", ep->remote_port); - /* create address string */ - free((char *)ep->remote_address); - addrtype = osmo_cc_address_type(ep->remote_host); - if (addrtype == osmo_cc_session_addrtype_ipv6) - sprintf(address, "[%s]:%d", ep->remote_host, ep->remote_port); - else - sprintf(address, "%s:%d", ep->remote_host, ep->remote_port); - ep->remote_address = strdup(address); - } - /* attach to remote host */ - timer_init(&ep->attach_timer, send_attach_ind, ep); - if (ep->remote_host) { - send_attach_ind(ep->attach_timer.data); - } - } - - return 0; -} - -/* destroy an endpoint instance */ -void osmo_cc_delete(osmo_cc_endpoint_t *ep) -{ - osmo_cc_endpoint_t **epp; - - LOGP(DCC, LOGL_DEBUG, "Destroying endpoint instance.\n"); - - /* detach from list >*/ - epp = &osmo_cc_endpoint_list; - while (*epp && *epp != ep) - epp = &((*epp)->next); - if (*epp) - *epp = ep->next; - - /* remove timer */ - timer_exit(&ep->attach_timer); - - /* flush screen lists */ - osmo_cc_flush_screen(ep->screen_calling_in); - osmo_cc_flush_screen(ep->screen_called_in); - osmo_cc_flush_screen(ep->screen_calling_out); - osmo_cc_flush_screen(ep->screen_called_out); - - /* free local and remote peer */ - free((char *)ep->local_name); - free((char *)ep->local_address); - free((char *)ep->local_host); - free((char *)ep->remote_address); - free((char *)ep->remote_host); - - /* destroying all child callesses (calls) */ - while(ep->call_list) - call_delete(ep->call_list); - - /* flush message queue */ - while(ep->ll_queue) { - osmo_cc_msg_t *msg = osmo_cc_msg_list_dequeue(&ep->ll_queue, NULL); - osmo_cc_free_msg(msg); - } - - /* remove socket */ - osmo_cc_close_socket(&ep->os); - - memset(ep, 0, sizeof(*ep)); -} - -/* create new call instance */ -osmo_cc_call_t *osmo_cc_call_new(osmo_cc_endpoint_t *ep) -{ - return call_new(ep, osmo_cc_new_callref()); -} - -/* destroy call instance */ -void osmo_cc_call_delete(osmo_cc_call_t *call) -{ - call_delete(call); -} - -/* check valid IP and return address type (protocol) */ -enum osmo_cc_session_addrtype osmo_cc_address_type(const char *address) -{ - struct sockaddr_storage sa; - int rc; - - rc = inet_pton(AF_INET, address, &sa); - if (rc > 0) - return osmo_cc_session_addrtype_ipv4; - rc = inet_pton(AF_INET6, address, &sa); - if (rc > 0) - return osmo_cc_session_addrtype_ipv6; - - return osmo_cc_session_addrtype_unknown; -} - -/* get host from address */ -const char *osmo_cc_host_of_address(const char *address) -{ - static char host[256]; - char *p; - - if (strlen(address) >= sizeof(host)) { - LOGP(DCC, LOGL_ERROR, "String way too long!\n"); - return NULL; - } - - if (address[0] == '[' && (p = strchr(address, ']'))) { - memcpy(host, address + 1, p - address - 1); - host[p - address - 1] = '\0'; - return host; - } - - strcpy(host, address); - if ((p = strchr(host, ':'))) - *p = '\0'; - - return host; -} - -/* get port from address */ -const char *osmo_cc_port_of_address(const char *address) -{ - const char *p; - int i; - - if (address[0] == '[' && (p = strchr(address, ']'))) - address = p + 1; - - if (!(p = strchr(address, ':'))) - return NULL; - p++; - - /* check for zero */ - if (p[0] == '0') - return NULL; - - /* check for digits */ - for (i = 0; i < (int)strlen(p); i++) { - if (p[i] < '0' || p[i] > '9') - return NULL; - } - - /* check for magnitude */ - if (atoi(p) > 65535) - return NULL; - - return p; -} - diff --git a/src/libosmocc/endpoint.h b/src/libosmocc/endpoint.h deleted file mode 100644 index 4425532..0000000 --- a/src/libosmocc/endpoint.h +++ /dev/null @@ -1,131 +0,0 @@ -#ifndef OSMO_CC_ENDPOINT_H -#define OSMO_CC_ENDPOINT_H - -#include "message.h" -#include "socket.h" -#include "cause.h" - -/* special osmo-cc error codes */ -#define OSMO_CC_RC_SEE_ERRNO -1 -#define OSMO_CC_RC_VERSION_MISMATCH 1 - -#define OSMO_CC_ATTACH_TIMER 2 - -/* call control state */ -enum osmo_cc_state { - OSMO_CC_STATE_IDLE = 0, - /* call states */ - OSMO_CC_STATE_INIT_OUT, /* outgoing CC-SETUP-REQ sent */ - OSMO_CC_STATE_INIT_IN, /* incoming CC-SETUP-IND received */ - OSMO_CC_STATE_OVERLAP_OUT, /* received CC-SETUP-ACK-IND on outgoing call */ - OSMO_CC_STATE_OVERLAP_IN, /* sent CC-SETUP-ACK-REQ on incoming call */ - OSMO_CC_STATE_PROCEEDING_OUT, /* received CC-PROC-IND on outgoing call */ - OSMO_CC_STATE_PROCEEDING_IN, /* sent CC-PROC-REQ on incoming call */ - OSMO_CC_STATE_ALERTING_OUT, /* received CC-ALERT-IND on outgoing call */ - OSMO_CC_STATE_ALERTING_IN, /* sent CC-ALERT-REQ on incoming call */ - OSMO_CC_STATE_CONNECTING_OUT, /* received CC-SETUP-CNF on outgoing call */ - OSMO_CC_STATE_CONNECTING_IN, /* sent CC-SETUP-RSP on incoming call */ - OSMO_CC_STATE_ACTIVE, /* received or sent CC-SETUP-COMPL-* */ - OSMO_CC_STATE_DISCONNECTING_OUT, /* sent CC-DISC-REQ */ - OSMO_CC_STATE_DISCONNECTING_IN, /* received CC-DISC-IND */ - OSMO_CC_STATE_DISC_COLLISION, /* received CC-DISC-IND after sending CC-DISC_REQ */ - OSMO_CC_STATE_RELEASING_OUT, /* sent CC-REL-REQ */ - /* attachment states */ - OSMO_CC_STATE_ATTACH_SENT, /* outgoing CC-ATT-REQ sent to socket */ - OSMO_CC_STATE_ATTACH_OUT, /* received CC-ATT-RSP on outgoing socket */ - OSMO_CC_STATE_ATTACH_WAIT, /* wait for outgoing attachment after failure */ - OSMO_CC_STATE_ATTACH_IN, /* incoming CC-ATT-REQ received from socket*/ -}; - -/* sample type */ -typedef int16_t osmo_cc_sample_t; - -#define OSMO_CC_SAMPLE_MILLIWATT 23170 /* peak sine at -3 dB of full sample range */ -#define OSMO_CC_SAMPLE_SPEECH 3672 /* peak speech at -16 dB of milliwatt */ -#define OSMO_CC_SAMPLE_MIN -32768 /* lowest level */ -#define OSMO_CC_SAMPLE_MAX 32767 /* highest level */ - -#include "session.h" - -struct osmo_cc_call; - -typedef struct osmo_cc_screen_list { - struct osmo_cc_screen_list *next; - int has_from_type; - uint8_t from_type; - int has_from_present; - uint8_t from_present; - char from[128]; - int has_to_type; - uint8_t to_type; - int has_to_present; - uint8_t to_present; - char to[128]; -} osmo_cc_screen_list_t; - -/* endpoint instance */ -typedef struct osmo_cc_endpoint { - struct osmo_cc_endpoint *next; - void *priv; - void (*ll_msg_cb)(struct osmo_cc_endpoint *ep, uint32_t callref, osmo_cc_msg_t *msg); - void (*ul_msg_cb)(struct osmo_cc_call *call, osmo_cc_msg_t *msg); - osmo_cc_msg_list_t *ll_queue; /* messages towards lower layer */ - struct osmo_cc_call *call_list; - const char *local_name; /* name of interface */ - const char *local_address; /* host+port */ - const char *local_host; - uint16_t local_port; - const char *remote_address; /* host+port */ - const char *remote_host; - uint16_t remote_port; - uint8_t serving_location; - osmo_cc_socket_t os; - osmo_cc_screen_list_t *screen_calling_in; - osmo_cc_screen_list_t *screen_called_in; - osmo_cc_screen_list_t *screen_calling_out; - osmo_cc_screen_list_t *screen_called_out; - int remote_auto; /* automatic remote address */ - struct timer attach_timer; /* timer to retry attachment */ - osmo_cc_session_config_t session_config; /* SDP/RTP default configuration */ -} osmo_cc_endpoint_t; - -extern osmo_cc_endpoint_t *osmo_cc_endpoint_list; - -/* call process */ -typedef struct osmo_cc_call { - struct osmo_cc_call *next; - osmo_cc_endpoint_t *ep; - enum osmo_cc_state state; - int lower_layer_released; /* when lower layer sent release, while upper layer gets a disconnect */ - int upper_layer_released; /* when upper layer sent release, while lower layer gets a disconnect */ - uint32_t callref; - osmo_cc_msg_list_t *sock_queue; /* messages from socket */ - const char *attached_host; /* host and port from remote peer that attached to us */ - uint16_t attached_port; - const char *attached_name; /* interface name from remote peer that attached to us */ -} osmo_cc_call_t; - -/* returns 0 if ok - * returns <0 for error as indicated - * returns >=1 to indicate osmo-cc error code - */ - -void osmo_cc_help(void); -int osmo_cc_new(osmo_cc_endpoint_t *ep, const char *version, const char *name, uint8_t serving_location, void (*ll_msg_cb)(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg), void (*ul_msg_cb)(osmo_cc_call_t *call, osmo_cc_msg_t *msg), void *priv, int argc, const char *argv[]); -void osmo_cc_delete(struct osmo_cc_endpoint *ep); -int osmo_cc_handle(void); -osmo_cc_call_t *osmo_cc_call_by_callref(osmo_cc_endpoint_t *ep, uint32_t callref); -osmo_cc_call_t *osmo_cc_get_attached_interface(osmo_cc_endpoint_t *ep, const char *interface); -void osmo_cc_ll_msg(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg); -void osmo_cc_ul_msg(void *priv, uint32_t callref, osmo_cc_msg_t *msg); -osmo_cc_call_t *osmo_cc_call_new(osmo_cc_endpoint_t *ep); -void osmo_cc_call_delete(struct osmo_cc_call *call); -enum osmo_cc_session_addrtype osmo_cc_address_type(const char *address); -const char *osmo_cc_host_of_address(const char *address); -const char *osmo_cc_port_of_address(const char *address); - -#include "rtp.h" -#include "sdp.h" -#include "screen.h" - -#endif /* OSMO_CC_ENDPOINT_H */ diff --git a/src/libosmocc/helper.c b/src/libosmocc/helper.c deleted file mode 100644 index 468eca0..0000000 --- a/src/libosmocc/helper.c +++ /dev/null @@ -1,223 +0,0 @@ -/* Osmo-CC: helpers to simplify Osmo-CC usage - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <string.h> -#include <stdint.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/time.h> -#include <inttypes.h> -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libdebug/debug.h" -#include "session.h" -#include "message.h" -#include "rtp.h" -#include "helper.h" - -osmo_cc_session_t *osmo_cc_helper_audio_offer(osmo_cc_session_config_t *conf, void *priv, struct osmo_cc_helper_audio_codecs *codecs, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), osmo_cc_msg_t *msg, int debug) -{ - osmo_cc_session_t *session; - osmo_cc_session_media_t *media; - const char *sdp; - int i; - - session = osmo_cc_new_session(conf, priv, NULL, NULL, NULL, 0, 0, NULL, NULL, debug); - if (!session) - return NULL; - - media = osmo_cc_add_media(session, 0, 0, NULL, osmo_cc_session_media_type_audio, 0, osmo_cc_session_media_proto_rtp, 1, 1, receiver, debug); - osmo_cc_rtp_open(media); - - for (i = 0; codecs[i].payload_name; i++) { - osmo_cc_add_codec(media, codecs[i].payload_name, codecs[i].payload_rate, codecs[i].payload_channels, codecs[i].encoder, codecs[i].decoder, debug); - } - - sdp = osmo_cc_session_send_offer(session); - osmo_cc_add_ie_sdp(msg, sdp); - - return session; -} - -const char *osmo_cc_helper_audio_accept(osmo_cc_session_config_t *conf, void *priv, struct osmo_cc_helper_audio_codecs *codecs, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p, int force_our_codec) -{ - return osmo_cc_helper_audio_accept_te(conf, priv, codecs, receiver, msg, session_p, codec_p, NULL, force_our_codec); -} - -const char *osmo_cc_helper_audio_accept_te(osmo_cc_session_config_t *conf, void *priv, struct osmo_cc_helper_audio_codecs *codecs, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p, osmo_cc_session_codec_t **telephone_event_p, int force_our_codec) -{ - char offer_sdp[65536]; - const char *accept_sdp; - osmo_cc_session_media_t *media, *selected_media; - osmo_cc_session_codec_t *codec, *selected_codec, *telephone_event; - int rc; - int i, selected_codec_i, telephone_event_i; - - if (*session_p) { - LOGP(DCC, LOGL_ERROR, "Session already set, please fix!\n"); - abort(); - } - if (*codec_p) { - LOGP(DCC, LOGL_ERROR, "Codec already set, please fix!\n"); - abort(); - } - - /* SDP IE */ - rc = osmo_cc_get_ie_sdp(msg, 0, offer_sdp, sizeof(offer_sdp)); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "There is no SDP included in setup request.\n"); - return NULL; - } - - *session_p = osmo_cc_session_receive_offer(conf, priv, offer_sdp); - if (!*session_p) { - LOGP(DCC, LOGL_ERROR, "Failed to parse SDP.\n"); - return NULL; - } - - selected_media = NULL; - osmo_cc_session_for_each_media((*session_p)->media_list, media) { - /* only audio */ - if (media->description.type != osmo_cc_session_media_type_audio) - continue; - selected_codec_i = -1; - selected_codec = NULL; - telephone_event_i = -1; - telephone_event = NULL; - osmo_cc_session_for_each_codec(media->codec_list, codec) { - if (!!strcasecmp(codec->payload_name, "telephone-event")) { - for (i = 0; codecs[i].payload_name; i++) { - if (osmo_cc_session_if_codec(codec, codecs[i].payload_name, codecs[i].payload_rate, codecs[i].payload_channels)) { - /* select the first matchting codec or the one we prefer */ - if (selected_codec_i < 0 || i < selected_codec_i) { - selected_codec = codec; - selected_codec_i = i; - selected_media = media; - } - /* if we don't force our preferred codec, use the preferred one from the remote */ - if (!force_our_codec) - break; - } - } - } else { - /* special case: add telephone-event, if supported */ - for (i = 0; codecs[i].payload_name; i++) { - if (!!strcasecmp(codecs[i].payload_name, "telephone-event")) - continue; - telephone_event = codec; - telephone_event_i = i; - break; - } - } - } - /* codec is selected within this media, we are done */ - if (selected_codec) - break; - } - if (!selected_codec) { - LOGP(DCC, LOGL_ERROR, "No codec found in setup message that we support.\n"); - osmo_cc_free_session(*session_p); - *session_p = NULL; - return NULL; - } - osmo_cc_session_accept_codec(selected_codec, codecs[selected_codec_i].encoder, codecs[selected_codec_i].decoder); - if (telephone_event) - osmo_cc_session_accept_codec(telephone_event, codecs[telephone_event_i].encoder, codecs[telephone_event_i].decoder); - osmo_cc_session_accept_media(selected_media, 0, 0, NULL, 1, 1, receiver); - osmo_cc_rtp_open(selected_media); - osmo_cc_rtp_connect(selected_media); - *codec_p = selected_codec; - if (telephone_event_p) - *telephone_event_p = telephone_event; - - accept_sdp = osmo_cc_session_send_answer(*session_p); - if (!accept_sdp) { - osmo_cc_free_session(*session_p); - *session_p = NULL; - return NULL; - } - - return accept_sdp; -} - -int osmo_cc_helper_audio_negotiate(osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p) -{ - return osmo_cc_helper_audio_negotiate_te(msg, session_p, codec_p, NULL); -} - -int osmo_cc_helper_audio_negotiate_te(osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p, osmo_cc_session_codec_t **telephone_event_p) -{ - char sdp[65536]; - osmo_cc_session_media_t *media; - osmo_cc_session_codec_t *codec; - int rc; - - if (!(*session_p)) { - LOGP(DCC, LOGL_ERROR, "Session not set, please fix!\n"); - abort(); - } - - /* SDP IE */ - rc = osmo_cc_get_ie_sdp(msg, 0, sdp, sizeof(sdp)); - if (rc < 0) - return 0; // no reply in this message - - rc = osmo_cc_session_receive_answer(*session_p, sdp); - if (rc < 0) - return rc; - - osmo_cc_session_for_each_media((*session_p)->media_list, media) { - /* skip not accepted medias */ - if (!media->accepted) - continue; - /* only audio */ - if (media->description.type != osmo_cc_session_media_type_audio) - continue; - osmo_cc_session_for_each_codec(media->codec_list, codec) { - /* skip not accepted codecs */ - if (!codec->accepted) - continue; - if (!!strcasecmp(codec->payload_name, "telephone-event")) { - /* select first codec, if one was accpeted */ - if (!(*codec_p)) { - LOGP(DCC, LOGL_DEBUG, "Select codec '%s'.\n", codec->payload_name); - *codec_p = codec; - } - } else { - if (telephone_event_p && !(*telephone_event_p)) { - LOGP(DCC, LOGL_DEBUG, "select telephone event codec.\n"); - *telephone_event_p = codec; - } - } - } - if (*codec_p) { - osmo_cc_rtp_connect(media); - /* no more media streams */ - break; - } - } - if (!(*codec_p)) { - LOGP(DCC, LOGL_ERROR, "No codec found in setup reply message that we support.\n"); - return -EIO; - } - - return 0; -} - diff --git a/src/libosmocc/helper.h b/src/libosmocc/helper.h deleted file mode 100644 index a48bd8e..0000000 --- a/src/libosmocc/helper.h +++ /dev/null @@ -1,15 +0,0 @@ - -struct osmo_cc_helper_audio_codecs { - const char *payload_name; - uint32_t payload_rate; - int payload_channels; - void (*encoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); - void (*decoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); -}; - -osmo_cc_session_t *osmo_cc_helper_audio_offer(osmo_cc_session_config_t *conf, void *priv, struct osmo_cc_helper_audio_codecs *codecs, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), osmo_cc_msg_t *msg, int debug); -const char *osmo_cc_helper_audio_accept(osmo_cc_session_config_t *conf, void *priv, struct osmo_cc_helper_audio_codecs *codecs, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p, int force_our_codec); -const char *osmo_cc_helper_audio_accept_te(osmo_cc_session_config_t *conf, void *priv, struct osmo_cc_helper_audio_codecs *codecs, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p, osmo_cc_session_codec_t **telephone_event_p, int force_our_codec); -int osmo_cc_helper_audio_negotiate(osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p); -int osmo_cc_helper_audio_negotiate_te(osmo_cc_msg_t *msg, osmo_cc_session_t **session_p, osmo_cc_session_codec_t **codec_p, osmo_cc_session_codec_t **telephone_event_p); - diff --git a/src/libosmocc/message.c b/src/libosmocc/message.c deleted file mode 100644 index 8f83343..0000000 --- a/src/libosmocc/message.c +++ /dev/null @@ -1,1294 +0,0 @@ -/* Osmo-CC: Message handling - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <arpa/inet.h> -#include "../libdebug/debug.h" -#include "message.h" - -#define _OSMO_CC_VALUE2NAME(array) { \ - if (value < 0 || (size_t)value >= (sizeof(array) / sizeof(array[0])) || array[value] == NULL) \ - return "<unknown>"; \ - else \ - return array[value]; \ -} - -#define _OSMO_CC_NAME2VALUE(array) { \ - int value; \ - for (value = 0; (size_t)value < (sizeof(array) / sizeof(array[0])); value++) { \ - if (!array[value]) \ - continue; \ - if (!strcasecmp(array[value], name)) \ - return value; \ - } \ - return -1; \ -} - -static const char *osmo_cc_msg_name[OSMO_CC_MSG_NUM] = { - [OSMO_CC_MSG_SETUP_REQ] = "CC-SETUP-REQ", - [OSMO_CC_MSG_SETUP_IND] = "CC-SETUP-IND", - [OSMO_CC_MSG_REJ_REQ] = "CC-REJ-REQ", - [OSMO_CC_MSG_REJ_IND] = "CC-REJ-IND", - [OSMO_CC_MSG_SETUP_ACK_REQ] = "CC-SETUP-ACK-REQ", - [OSMO_CC_MSG_SETUP_ACK_IND] = "CC-SETUP-ACK-IND", - [OSMO_CC_MSG_PROC_REQ] = "CC-PROC-REQ", - [OSMO_CC_MSG_PROC_IND] = "CC-PROC-IND", - [OSMO_CC_MSG_ALERT_REQ] = "CC-ALERT-REQ", - [OSMO_CC_MSG_ALERT_IND] = "CC-ALERT-IND", - [OSMO_CC_MSG_SETUP_RSP] = "CC-SETUP-RSP", - [OSMO_CC_MSG_SETUP_CNF] = "CC-SETUP-CNF", - [OSMO_CC_MSG_SETUP_COMP_REQ] = "CC-SETUP-COMP-REQ", - [OSMO_CC_MSG_SETUP_COMP_IND] = "CC-SETUP-COMP-IND", - [OSMO_CC_MSG_DISC_REQ] = "CC-DISC-REQ", - [OSMO_CC_MSG_DISC_IND] = "CC-DISC-IND", - [OSMO_CC_MSG_REL_REQ] = "CC-REL-REQ", - [OSMO_CC_MSG_REL_CNF] = "CC-REL-CNF", - [OSMO_CC_MSG_REL_IND] = "CC-REL-IND", - [OSMO_CC_MSG_PROGRESS_REQ] = "CC-PROGRESS-REQ", - [OSMO_CC_MSG_PROGRESS_IND] = "CC-PROGRESS-IND", - [OSMO_CC_MSG_NOTIFY_REQ] = "CC-NOTIFY-REQ", - [OSMO_CC_MSG_NOTIFY_IND] = "CC-NOTIFY-IND", - [OSMO_CC_MSG_INFO_REQ] = "CC-INFO-REQ", - [OSMO_CC_MSG_INFO_IND] = "CC-INFO-IND", - [OSMO_CC_MSG_ATTACH_REQ] = "CC-ATTACH-REQ", - [OSMO_CC_MSG_ATTACH_IND] = "CC-ATTACH-IND", - [OSMO_CC_MSG_ATTACH_RSP] = "CC-ATTACH-RSP", - [OSMO_CC_MSG_ATTACH_CNF] = "CC-ATTACH-CNF", -}; - -const char *osmo_cc_msg_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_msg_name) -int osmo_cc_msg_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_msg_name) - -static const char *osmo_cc_ie_name[OSMO_CC_IE_NUM] = { - [OSMO_CC_IE_CALLED] = "IE_CALLED", - [OSMO_CC_IE_CALLED_SUB] = "IE_CALLED_SUB", - [OSMO_CC_IE_CALLED_NAME] = "IE_CALLED_NAME", - [OSMO_CC_IE_CALLED_INTERFACE] = "IE_CALLED_INTERFACE", - [OSMO_CC_IE_DTMF] = "IE_DTMF", - [OSMO_CC_IE_KEYPAD] = "IE_KEYPAD", - [OSMO_CC_IE_COMPLETE] = "IE_COMPLETE", - [OSMO_CC_IE_CALLING] = "IE_CALLING", - [OSMO_CC_IE_CALLING_SUB] = "IE_CALLING_SUB", - [OSMO_CC_IE_CALLING_NAME] = "IE_CALLING_NAME", - [OSMO_CC_IE_CALLING_INTERFACE] = "IE_CALLING_INTERFACE", - [OSMO_CC_IE_CALLING_NETWORK] = "IE_CALLING_NETWORK", - [OSMO_CC_IE_REDIR] = "IE_REDIR", - [OSMO_CC_IE_PROGRESS] = "IE_PROGRESS", - [OSMO_CC_IE_NOTIFY] = "IE_NOTIFY", - [OSMO_CC_IE_DISPLAY] = "IE_DISPLAY", - [OSMO_CC_IE_CAUSE] = "IE_CAUSE", - [OSMO_CC_IE_BEARER] = "IE_BEARER", - [OSMO_CC_IE_SDP] = "IE_SDP", - [OSMO_CC_IE_SOCKET_ADDRESS] = "IE_SOCKET_ADDRESS", - [OSMO_CC_IE_PRIVATE] = "IE_PRIVATE", -}; - -const char *osmo_cc_ie_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_ie_name) -int osmo_cc_ie_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_ie_name) - -static const char *osmo_cc_type_name[OSMO_CC_TYPE_NUM] = { - [OSMO_CC_TYPE_UNKNOWN] = "unknown", - [OSMO_CC_TYPE_INTERNATIONAL] = "international", - [OSMO_CC_TYPE_NATIONAL] = "national", - [OSMO_CC_TYPE_NETWORK] = "network", - [OSMO_CC_TYPE_SUBSCRIBER] = "subscriber", - [OSMO_CC_TYPE_ABBREVIATED] = "abbreviated", - [OSMO_CC_TYPE_RESERVED] = "reserved", -}; - -const char *osmo_cc_type_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_type_name) -int osmo_cc_type_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_type_name) - -static const char *osmo_cc_plan_name[OSMO_CC_PLAN_NUM] = { - [OSMO_CC_PLAN_UNKNOWN] = "unknown", - [OSMO_CC_PLAN_TELEPHONY] = "telephony", - [OSMO_CC_PLAN_DATA] = "data", - [OSMO_CC_PLAN_TTY] = "tty", - [OSMO_CC_PLAN_NATIONAL_STANDARD] = "national standard", - [OSMO_CC_PLAN_PRIVATE] = "private", - [OSMO_CC_PLAN_RESERVED] = "reserved", -}; - -const char *osmo_cc_plan_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_plan_name) -int osmo_cc_plan_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_plan_name) - -static const char *osmo_cc_present_name[OSMO_CC_PRESENT_NUM] = { - [OSMO_CC_PRESENT_ALLOWED] = "allowed", - [OSMO_CC_PRESENT_RESTRICTED] = "restricted", - [OSMO_CC_PRESENT_NOT_AVAIL] = "not available", - [OSMO_CC_PRESENT_RESERVED] = "reserved", -}; - -const char *osmo_cc_present_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_present_name) -int osmo_cc_present_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_present_name) - -static const char *osmo_cc_screen_name[OSMO_CC_SCREEN_NUM] = { - [OSMO_CC_SCREEN_USER_UNSCREENED] = "unscreened", - [OSMO_CC_SCREEN_USER_VERIFIED_PASSED] = "user provided and passed", - [OSMO_CC_SCREEN_USER_VERIFIED_FAILED] = "user provided an failed", - [OSMO_CC_SCREEN_NETWORK] = "network provided", -}; - -const char *osmo_cc_screen_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_screen_name) -int osmo_cc_screen_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_screen_name) - -static const char *osmo_cc_redir_reason_name[OSMO_CC_REDIR_REASON_NUM] = { - [OSMO_CC_REDIR_REASON_UNKNOWN] = "unknown", - [OSMO_CC_REDIR_REASON_CFB] = "call forward busy", - [OSMO_CC_REDIR_REASON_CFNR] = "call forward no response", - [OSMO_CC_REDIR_REASON_CD] = "call deflect", - [OSMO_CC_REDIR_REASON_CF_OUTOFORDER] = "call forward out of order", - [OSMO_CC_REDIR_REASON_CF_BY_DTE] = "call froward by dte", - [OSMO_CC_REDIR_REASON_CFU] = "call forward unconditional", -}; - -const char *osmo_cc_redir_reason_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_redir_reason_name) -int osmo_cc_redir_reason_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_redir_reason_name) - -static const char *osmo_cc_notify_name[OSMO_CC_NOTIFY_NUM] = { - [OSMO_CC_NOTIFY_USER_SUSPENDED] = "user suspended", - [OSMO_CC_NOTIFY_USER_RESUMED] = "user resumed", - [OSMO_CC_NOTIFY_BEARER_SERVICE_CHANGE] = "bearer service change", - [OSMO_CC_NOTIFY_CALL_COMPLETION_DELAY] = "call completion delay", - [OSMO_CC_NOTIFY_CONFERENCE_ESTABLISHED] = "conference established", - [OSMO_CC_NOTIFY_CONFERENCE_DISCONNECTED] = "conference disconnected", - [OSMO_CC_NOTIFY_OTHER_PARTY_ADDED] = "ohter party added", - [OSMO_CC_NOTIFY_ISOLATED] = "isolated", - [OSMO_CC_NOTIFY_REATTACHED] = "reattached", - [OSMO_CC_NOTIFY_OTHER_PARTY_ISOLATED] = "ohter party isolated", - [OSMO_CC_NOTIFY_OTHER_PARTY_REATTACHED] = "ohter party reattached", - [OSMO_CC_NOTIFY_OTHER_PARTY_SPLIT] = "other party split", - [OSMO_CC_NOTIFY_OTHER_PARTY_DISCONNECTED] = "other party disconnected", - [OSMO_CC_NOTIFY_CONFERENCE_FLOATING] = "confernce floating", - [OSMO_CC_NOTIFY_CONFERENCE_DISC_PREEMPT] = "confernce disconnect preemption", - [OSMO_CC_NOTIFY_CONFERENCE_FLOATING_SUP] = "conference floating sup", - [OSMO_CC_NOTIFY_CALL_IS_A_WAITING_CALL] = "call is a waiting call", - [OSMO_CC_NOTIFY_DIVERSION_ACTIVATED] = "diversion activated", - [OSMO_CC_NOTIFY_RESERVED_CT_1] = "reserved CT 1", - [OSMO_CC_NOTIFY_RESERVED_CT_2] = "reserved CT 2", - [OSMO_CC_NOTIFY_REVERSE_CHARGING] = "reverse charging", - [OSMO_CC_NOTIFY_REMOTE_HOLD] = "remote hold", - [OSMO_CC_NOTIFY_REMOTE_RETRIEVAL] = "remote retrieval", - [OSMO_CC_NOTIFY_CALL_IS_DIVERTING] = "call is diverting", -}; - -const char *osmo_cc_notify_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_notify_name) -int osmo_cc_notify_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_notify_name) - -static const char *osmo_cc_coding_name[OSMO_CC_CODING_NUM] = { - [OSMO_CC_CODING_ITU_T] = "ITU-T", - [OSMO_CC_CODING_ISO_IEC] = "ISO/IEC", - [OSMO_CC_CODING_NATIONAL] = "national", - [OSMO_CC_CODING_STANDARD_SPECIFIC] = "standard specific", -}; - -const char *osmo_cc_coding_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_coding_name) -int osmo_cc_coding_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_coding_name) - -static const char *osmo_cc_isdn_cause_name[OSMO_CC_ISDN_CAUSE_NUM] = { - [0] = "unset", - [OSMO_CC_ISDN_CAUSE_UNASSIGNED_NR] = "unsassigned number", - [OSMO_CC_ISDN_CAUSE_NO_ROUTE_TRANSIT] = "no route to transit network", - [OSMO_CC_ISDN_CAUSE_NO_ROUTE] = "no route", - [OSMO_CC_ISDN_CAUSE_CHAN_UNACCEPT] = "channel unacceptable", - [OSMO_CC_ISDN_CAUSE_OP_DET_BARRING] = "detected barring", - [OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR] = "normal call clearing", - [OSMO_CC_ISDN_CAUSE_USER_BUSY] = "user busy", - [OSMO_CC_ISDN_CAUSE_USER_NOTRESPOND] = "user not responding", - [OSMO_CC_ISDN_CAUSE_USER_ALERTING_NA] = "user does not answer", - [OSMO_CC_ISDN_CAUSE_CALL_REJECTED] = "call rejected", - [OSMO_CC_ISDN_CAUSE_NUMBER_CHANGED] = "number changed", - [OSMO_CC_ISDN_CAUSE_PRE_EMPTION] = "pre-emption", - [OSMO_CC_ISDN_CAUSE_NONSE_USER_CLR] = "non-selected user clearing", - [OSMO_CC_ISDN_CAUSE_DEST_OOO] = "destination out-of-order", - [OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT] = "invalid number format", - [OSMO_CC_ISDN_CAUSE_FACILITY_REJ] = "facility rejected", - [OSMO_CC_ISDN_CAUSE_RESP_STATUS_INQ] = "response to status enquiery", - [OSMO_CC_ISDN_CAUSE_NORMAL_UNSPEC] = "normal, uspecified", - [OSMO_CC_ISDN_CAUSE_NO_CIRCUIT_CHAN] = "no circuit/channel available", - [OSMO_CC_ISDN_CAUSE_NETWORK_OOO] = "network out of order", - [OSMO_CC_ISDN_CAUSE_TEMP_FAILURE] = "temporary failure", - [OSMO_CC_ISDN_CAUSE_SWITCH_CONG] = "switching equipment congested", - [OSMO_CC_ISDN_CAUSE_ACC_INF_DISCARD] = "access information discarded", - [OSMO_CC_ISDN_CAUSE_REQ_CHAN_UNAVAIL] = "requested circuit/channel unavailable", - [OSMO_CC_ISDN_CAUSE_RESOURCE_UNAVAIL] = "resource unavailable", - [OSMO_CC_ISDN_CAUSE_QOS_UNAVAIL] = "quality of service unavailable", - [OSMO_CC_ISDN_CAUSE_REQ_FAC_NOT_SUBSC] = "requested facility not subscribed", - [OSMO_CC_ISDN_CAUSE_INC_BARRED_CUG] = "inc barred in closed user group", - [OSMO_CC_ISDN_CAUSE_BEARER_CAP_UNAUTH] = "bearer capability unauthorized", - [OSMO_CC_ISDN_CAUSE_BEARER_CA_UNAVAIL] = "bearer capability not available", - [OSMO_CC_ISDN_CAUSE_SERV_OPT_UNAVAIL] = "service or option not available", - [OSMO_CC_ISDN_CAUSE_BEARERSERV_UNIMPL] = "bearer service unimplemented", - [OSMO_CC_ISDN_CAUSE_ACM_GE_ACM_MAX] = "acm ge ach max", - [OSMO_CC_ISDN_CAUSE_REQ_FAC_NOTIMPL] = "requrested facility not implemented", - [OSMO_CC_ISDN_CAUSE_RESTR_BCAP_AVAIL] = "restricted bearer capabilitey available", - [OSMO_CC_ISDN_CAUSE_SERV_OPT_UNIMPL] = "service or option unimplemented", - [OSMO_CC_ISDN_CAUSE_INVAL_CALLREF] = "invalid call reference", - [OSMO_CC_ISDN_CAUSE_USER_NOT_IN_CUG] = "user not in closed user group", - [OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST] = "incompatible destination", - [OSMO_CC_ISDN_CAUSE_INVAL_TRANS_NET] = "invalid transit network", - [OSMO_CC_ISDN_CAUSE_SEMANTIC_INCORR] = "semantically incorrect", - [OSMO_CC_ISDN_CAUSE_INVAL_MAND_INF] = "invalid mandatory information", - [OSMO_CC_ISDN_CAUSE_MSGTYPE_NOTEXIST] = "message type does not exist", - [OSMO_CC_ISDN_CAUSE_MSGTYPE_INCOMPAT] = "message type incompatible", - [OSMO_CC_ISDN_CAUSE_IE_NOTEXIST] = "informaton element does not exits", - [OSMO_CC_ISDN_CAUSE_COND_IE_ERR] = "conditional information element error", - [OSMO_CC_ISDN_CAUSE_MSG_INCOMP_STATE] = "message at incompatlible state", - [OSMO_CC_ISDN_CAUSE_RECOVERY_TIMER] = "recovery on time expiery", - [OSMO_CC_ISDN_CAUSE_PROTO_ERR] = "protocol error", - [OSMO_CC_ISDN_CAUSE_INTERWORKING] = "interworking, unspecified", -}; - -const char *osmo_cc_isdn_cause_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_isdn_cause_name) -int osmo_cc_isdn_cause_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_isdn_cause_name) - -static const char *osmo_cc_location_name[OSMO_CC_LOCATION_NUM] = { - [OSMO_CC_LOCATION_USER] = "user", - [OSMO_CC_LOCATION_PRIV_SERV_LOC_USER] = "private network serving local user", - [OSMO_CC_LOCATION_PUB_SERV_LOC_USER] = "public network serving local user", - [OSMO_CC_LOCATION_TRANSIT] = "transit network", - [OSMO_CC_LOCATION_PUB_SERV_REM_USER] = "public network serving remote user", - [OSMO_CC_LOCATION_PRIV_SERV_REM_USER] = "private network serving remote user", - [OSMO_CC_LOCATION_BEYOND_INTERWORKING] = "beyond interworking", -}; - -const char *osmo_cc_location_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_location_name) -int osmo_cc_location_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_location_name) - -static const char *osmo_cc_progress_name[OSMO_CC_PROGRESS_NUM] = { - [OSMO_CC_PROGRESS_NOT_END_TO_END_ISDN] = "not end-to-end ISDN", - [OSMO_CC_PROGRESS_DEST_NOT_ISDN] = "destination not ISDN", - [OSMO_CC_PROGRESS_ORIG_NOT_ISDN] = "originator not ISDN", - [OSMO_CC_PROGRESS_RETURN_TO_ISDN] = "return to ISDN", - [OSMO_CC_PROGRESS_INTERWORKING] = "interworking", - [OSMO_CC_PROGRESS_INBAND_INFO_AVAILABLE] = "inmand information available (audio)", -}; - -const char *osmo_cc_progress_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_progress_name) -int osmo_cc_progress_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_progress_name) - -static const char *osmo_cc_capability_name[OSMO_CC_CAPABILITY_NUM] = { - [OSMO_CC_CAPABILITY_SPEECH] = "speech", - [OSMO_CC_CAPABILITY_DATA] = "data", - [OSMO_CC_CAPABILITY_DATA_RESTRICTED] = "data restricted", - [OSMO_CC_CAPABILITY_AUDIO] = "audio", - [OSMO_CC_CAPABILITY_DATA_WITH_TONES] = "data with tones", - [OSMO_CC_CAPABILITY_VIDEO] = "video", -}; - -const char *osmo_cc_capability_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_capability_name) -int osmo_cc_capability_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_capability_name) - -static const char *osmo_cc_mode_name[OSMO_CC_MODE_NUM] = { - [OSMO_CC_MODE_CIRCUIT] = "circuit", - [OSMO_CC_MODE_PACKET] = "packet", -}; - -const char *osmo_cc_mode_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_mode_name) -int osmo_cc_mode_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_mode_name) - -static const char *osmo_cc_dtmf_mode_name[OSMO_CC_DTMF_MODE_NUM] = { - [OSMO_CC_DTMF_MODE_OFF] = "off", - [OSMO_CC_DTMF_MODE_ON] = "on", - [OSMO_CC_DTMF_MODE_DIGITS] = "digit", -}; - -const char *osmo_cc_dtmf_mode_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_dtmf_mode_name) -int osmo_cc_dtmf_mode_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_dtmf_mode_name) - -static const char *osmo_cc_socket_cause_name[OSMO_CC_SOCKET_CAUSE_NUM] = { - [0] = "unset", - [OSMO_CC_SOCKET_CAUSE_VERSION_MISMATCH] = "version mismatch", - [OSMO_CC_SOCKET_CAUSE_FAILED] = "socket failed", - [OSMO_CC_SOCKET_CAUSE_BROKEN_PIPE] = "broken pipe", - [OSMO_CC_SOCKET_CAUSE_TIMEOUT] = "keepalive timeout", -}; - -const char *osmo_cc_socket_cause_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_socket_cause_name) -int osmo_cc_socket_cause_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_socket_cause_name) - -static const char *osmo_cc_network_name[OSMO_CC_NETWORK_NUM] = { - [OSMO_CC_NETWORK_UNDEFINED] = "undefined", - [OSMO_CC_NETWORK_ALSA_NONE] = "alsa", - [OSMO_CC_NETWORK_POTS_NONE] = "pots", - [OSMO_CC_NETWORK_ISDN_NONE] = "isdn", - [OSMO_CC_NETWORK_SIP_NONE] = "sip", - [OSMO_CC_NETWORK_GSM_IMSI] = "gsm-imsi", - [OSMO_CC_NETWORK_GSM_IMEI] = "gsm-imei", - [OSMO_CC_NETWORK_WEB_NONE] = "web", - [OSMO_CC_NETWORK_DECT_NONE] = "decs", - [OSMO_CC_NETWORK_BLUETOOTH_NONE] = "bluetooth", - [OSMO_CC_NETWORK_SS5_NONE] = "ss5", - [OSMO_CC_NETWORK_R1_NONE] = "r1", - [OSMO_CC_NETWORK_ANETZ_NONE] = "anetz", - [OSMO_CC_NETWORK_BNETZ_MUENZ] = "bnetz", - [OSMO_CC_NETWORK_CNETZ_NONE] = "cnetz", - [OSMO_CC_NETWORK_NMT_NONE] = "nmt", - [OSMO_CC_NETWORK_R2000_NONE] = "radiocom2000", - [OSMO_CC_NETWORK_AMPS_ESN] = "amps", - [OSMO_CC_NETWORK_MTS_NONE] = "mts", - [OSMO_CC_NETWORK_IMTS_NONE] = "imts", - [OSMO_CC_NETWORK_EUROSIGNAL_NONE] = "eurosignal", - [OSMO_CC_NETWORK_JOLLYCOM_NONE] = "jollycom", - [OSMO_CC_NETWORK_MPT1327_PSTN] = "mpt1327-pstn", - [OSMO_CC_NETWORK_MPT1327_PBX] = "mpt1327-pbx", -}; - -const char *osmo_cc_network_value2name(int value) _OSMO_CC_VALUE2NAME(osmo_cc_network_name) -int osmo_cc_network_name2value(const char *name) _OSMO_CC_NAME2VALUE(osmo_cc_network_name) - -/* - * - */ - -static uint32_t new_callref = 0; - -uint32_t osmo_cc_new_callref(void) -{ - return (++new_callref); -} - -/* create message with maximum size */ -osmo_cc_msg_t *osmo_cc_new_msg(uint8_t msg_type) -{ - osmo_cc_msg_t *msg; - - /* allocate message */ - msg = calloc(1, sizeof(*msg) + 65535); - if (!msg) { - LOGP(DCC, LOGL_ERROR, "No memory\n"); - abort(); - } - /* set message type and zero length */ - msg->type = msg_type; - msg->length_networkorder = htons(0); - - return msg; -} - -/* clone message */ -osmo_cc_msg_t *osmo_cc_clone_msg(osmo_cc_msg_t *msg) -{ - osmo_cc_msg_t *new_msg; - - new_msg = osmo_cc_new_msg(msg->type); - new_msg->length_networkorder = msg->length_networkorder; - memcpy(new_msg->data, msg->data, ntohs(msg->length_networkorder)); - - return new_msg; -} - -osmo_cc_msg_t *osmo_cc_msg_list_dequeue(osmo_cc_msg_list_t **mlp, uint32_t *callref_p) -{ - osmo_cc_msg_list_t *ml; - osmo_cc_msg_t *msg; - - ml = *mlp; - msg = ml->msg; - if (callref_p) - *callref_p = ml->callref; - *mlp = ml->next; - free(ml); - - return msg; -} - -osmo_cc_msg_list_t *osmo_cc_msg_list_enqueue(osmo_cc_msg_list_t **mlp, osmo_cc_msg_t *msg, uint32_t callref) -{ - osmo_cc_msg_list_t *ml; - - ml = calloc(1, sizeof(*ml)); - ml->msg = msg; - ml->callref = callref; - while (*mlp) - mlp = &((*mlp)->next); - *mlp = ml; - - return ml; -} - -/* destroy message */ -void osmo_cc_free_msg(osmo_cc_msg_t *msg) -{ - free(msg); -} - -void osmo_cc_debug_ie(osmo_cc_msg_t *msg, int level) -{ - uint16_t msg_len, len; - uint8_t *p; - osmo_cc_ie_t *ie; - int rc; - int ie_repeat[256]; - uint8_t type, plan, present, screen, coding, capability, mode, progress, reason, duration_ms, pause_ms, dtmf_mode, location, notify, isdn_cause, socket_cause; - uint16_t sip_cause; - uint32_t unique; - char string[65536]; - int i; - - memset(ie_repeat, 0, sizeof(ie_repeat)); - - msg_len = ntohs(msg->length_networkorder); - p = msg->data; - - while (msg_len) { - ie = (osmo_cc_ie_t *)p; - /* check for minimum IE length */ - if (msg_len < sizeof(*ie)) { - LOGP(DCC, level, "****** Rest of message is too short for an IE: value=%s\n", debug_hex(p, msg_len)); - return; - } - /* get actual IE length */ - len = ntohs(ie->length_networkorder); - /* check if IE length does not exceed message */ - if (msg_len < sizeof(*ie) + len) { - LOGP(DCC, level, "****** IE: type=0x%02x length=%d would exceed the rest length of message (%d bytes left)\n", ie->type, len, msg_len - (int)sizeof(*ie)); - return; - } - switch (ie->type) { - case OSMO_CC_IE_CALLED: - rc = osmo_cc_get_ie_called(msg, ie_repeat[ie->type], &type, &plan, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s type=%d(%s) plan=%d(%s) number='%s'\n", osmo_cc_ie_value2name(ie->type), type, osmo_cc_type_value2name(type), plan, osmo_cc_plan_value2name(plan), string); - break; - case OSMO_CC_IE_CALLED_SUB: - rc = osmo_cc_get_ie_called_sub(msg, ie_repeat[ie->type], &type, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s type=%d(%s) number='%s'\n", osmo_cc_ie_value2name(ie->type), type, osmo_cc_type_value2name(type), string); - break; - case OSMO_CC_IE_CALLED_NAME: - rc = osmo_cc_get_ie_called_name(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s name='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_CALLED_INTERFACE: - rc = osmo_cc_get_ie_called_interface(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s name='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_COMPLETE: - rc = osmo_cc_get_ie_complete(msg, ie_repeat[ie->type]); - if (rc < 0) - break; - LOGP(DCC, level, " %s\n", osmo_cc_ie_value2name(ie->type)); - break; - case OSMO_CC_IE_CALLING: - rc = osmo_cc_get_ie_calling(msg, ie_repeat[ie->type], &type, &plan, &present, &screen, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s type=%d(%s) plan=%d(%s), presentation=%d(%s), screening=%d(%s), number='%s'\n", osmo_cc_ie_value2name(ie->type), type, osmo_cc_type_value2name(type), plan, osmo_cc_plan_value2name(plan), present, osmo_cc_present_value2name(present), screen, osmo_cc_screen_value2name(screen), string); - break; - case OSMO_CC_IE_CALLING_SUB: - rc = osmo_cc_get_ie_calling_sub(msg, ie_repeat[ie->type], &type, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s type=%d(%s) number='%s'\n", osmo_cc_ie_value2name(ie->type), type, osmo_cc_type_value2name(type), string); - break; - case OSMO_CC_IE_CALLING_NAME: - rc = osmo_cc_get_ie_calling_name(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s name='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_CALLING_INTERFACE: - rc = osmo_cc_get_ie_calling_interface(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s name='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_CALLING_NETWORK: - rc = osmo_cc_get_ie_calling_network(msg, ie_repeat[ie->type], &type, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s type=%d(%s) id='%s'\n", osmo_cc_ie_value2name(ie->type), type, osmo_cc_network_value2name(type), string); - break; - case OSMO_CC_IE_BEARER: - rc = osmo_cc_get_ie_bearer(msg, ie_repeat[ie->type], &coding, &capability, &mode); - if (rc < 0) - break; - LOGP(DCC, level, " %s coding=%d(%s) capability=%d(%s) mode=%d(%s)\n", osmo_cc_ie_value2name(ie->type), coding, osmo_cc_coding_value2name(coding), capability, osmo_cc_capability_value2name(capability), mode, osmo_cc_mode_value2name(mode)); - break; - case OSMO_CC_IE_REDIR: - rc = osmo_cc_get_ie_redir(msg, ie_repeat[ie->type], &type, &plan, &present, &screen, &reason, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s type=%d(%s) plan=%d(%s) presentation=%d(%s) screening=%d(%s) reason=%d(%s) number='%s'\n", osmo_cc_ie_value2name(ie->type), type, osmo_cc_type_value2name(type), plan, osmo_cc_plan_value2name(plan), present, osmo_cc_present_value2name(present), screen, osmo_cc_screen_value2name(screen), reason, osmo_cc_redir_reason_value2name(reason), string); - break; - case OSMO_CC_IE_DTMF: - rc = osmo_cc_get_ie_dtmf(msg, ie_repeat[ie->type], &duration_ms, &pause_ms, &dtmf_mode, string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s duration=%dms pause=%dms mode=%d(%s)\n", osmo_cc_ie_value2name(ie->type), duration_ms, pause_ms, dtmf_mode, osmo_cc_dtmf_mode_value2name(dtmf_mode)); - break; - case OSMO_CC_IE_KEYPAD: - rc = osmo_cc_get_ie_keypad(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s digits='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_PROGRESS: - rc = osmo_cc_get_ie_progress(msg, ie_repeat[ie->type], &coding, &location, &progress); - if (rc < 0) - break; - LOGP(DCC, level, " %s coding=%d(%s) location=%d(%s) progress=%d(%s)\n", osmo_cc_ie_value2name(ie->type), coding, osmo_cc_coding_value2name(coding), location, osmo_cc_location_value2name(location), progress, osmo_cc_progress_value2name(progress)); - break; - case OSMO_CC_IE_NOTIFY: - rc = osmo_cc_get_ie_notify(msg, ie_repeat[ie->type], ¬ify); - if (rc < 0) - break; - LOGP(DCC, level, " %s indicator=%d(%s)\n", osmo_cc_ie_value2name(ie->type), notify, osmo_cc_notify_value2name(notify)); - break; - case OSMO_CC_IE_CAUSE: - rc = osmo_cc_get_ie_cause(msg, ie_repeat[ie->type], &location, &isdn_cause, &sip_cause, &socket_cause); - if (rc < 0) - break; - LOGP(DCC, level, " %s location=%d(%s) isdn_cause=%d(%s) sip_cause=%d socket_cause=%d(%s)\n", osmo_cc_ie_value2name(ie->type), location, osmo_cc_location_value2name(location), isdn_cause, osmo_cc_isdn_cause_value2name(isdn_cause), sip_cause, socket_cause, osmo_cc_socket_cause_value2name(socket_cause)); - break; - case OSMO_CC_IE_DISPLAY: - rc = osmo_cc_get_ie_display(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s info='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_SDP: - rc = osmo_cc_get_ie_sdp(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - for (i = 0; string[i]; i++) { - if (string[i] == '\r') - string[i] = '\\'; - if (string[i] == '\n') - string[i] = 'n'; - } - LOGP(DCC, level, " %s payload=%s\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_SOCKET_ADDRESS: - rc = osmo_cc_get_ie_socket_address(msg, ie_repeat[ie->type], string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s address='%s'\n", osmo_cc_ie_value2name(ie->type), string); - break; - case OSMO_CC_IE_PRIVATE: - rc = osmo_cc_get_ie_private(msg, ie_repeat[ie->type], &unique, (uint8_t *)string, sizeof(string)); - if (rc < 0) - break; - LOGP(DCC, level, " %s unique=%u=0x%08x private=%s\n", osmo_cc_ie_value2name(ie->type), unique, unique, debug_hex((uint8_t *)string, rc)); - break; - default: - LOGP(DCC, level, " %s type=0x%02x length=%d value=%s\n", osmo_cc_ie_value2name(ie->type), ie->type, len, debug_hex(ie->data, len)); - } - ie_repeat[ie->type]++; - p += sizeof(*ie) + len; - msg_len -= sizeof(*ie) + len; - } -} - -/* search and return information element - * we give the IE type we are searching for - * we also give the repetition, to find IE that is repeated - * the result is stored in *ie_data - * the return length is the length that exceeds the given ie_len - * if there is an error, a value < 0 is returned - */ -int osmo_cc_get_ie_struct(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat, int ie_len, const osmo_cc_ie_t **ie_struct) -{ - uint16_t msg_len, len; - uint8_t *p; - osmo_cc_ie_t *ie; - - msg_len = ntohs(msg->length_networkorder); - p = msg->data; - - while (msg_len) { - ie = (osmo_cc_ie_t *)p; - /* check for minimum IE length */ - if (msg_len < sizeof(*ie)) { - LOGP(DCC, LOGL_ERROR, "MSG short read\n"); - osmo_cc_debug_ie(msg, LOGL_ERROR); - return -EINVAL; - } - /* get actual IE length */ - len = ntohs(ie->length_networkorder); - /* check if IE length does not exceed message */ - if (msg_len < sizeof(*ie) + len) { - LOGP(DCC, LOGL_ERROR, "MSG short read\n"); - osmo_cc_debug_ie(msg, LOGL_ERROR); - return -EINVAL; - } - /* check if IE matches the one that is searched for */ - if (ie->type != ie_type) { - p += sizeof(*ie) + len; - msg_len -= sizeof(*ie) + len; - continue; - } - /* check if IE repetition exists */ - if (ie_repeat) { - --ie_repeat; - p += sizeof(*ie) + len; - msg_len -= sizeof(*ie) + len; - continue; - } - /* return IE and indicate how many bytes we have more than the given length*/ - if (ntohs(ie->length_networkorder) < ie_len) { - LOGP(DCC, LOGL_ERROR, "IE 0x%02d has length of %d, but we expect it to have at least %d!\n", ie_type, ntohs(ie->length_networkorder), ie_len); - return -EINVAL; - } - *ie_struct = ie; - return ntohs(ie->length_networkorder) - ie_len; - } - - /* IE not found */ - return -EINVAL; -} - -/* as above, but return data of IE only */ -int osmo_cc_get_ie_data(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat, int ie_len, const void **ie_data) -{ - const osmo_cc_ie_t *ie; - int rc; - - rc = osmo_cc_get_ie_struct(msg, ie_type, ie_repeat, ie_len, &ie); - if (rc >= 0) - *ie_data = ie->data; - - return rc; -} - -/* as above, but return 1 if IE exists */ -int osmo_cc_has_ie(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat) -{ - const osmo_cc_ie_t *ie; - int rc; - - rc = osmo_cc_get_ie_struct(msg, ie_type, ie_repeat, 0, &ie); - if (rc >= 0) - return 1; - - return 0; -} - -/* remove IE from message */ -int osmo_cc_remove_ie(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat) -{ - const osmo_cc_ie_t *ie; - int rc; - int msg_len, before_ie, ie_size, after_ie; - - rc = osmo_cc_get_ie_struct(msg, ie_type, ie_repeat, 0, &ie); - if (rc < 0) - return rc; - - msg_len = ntohs(msg->length_networkorder); - before_ie = (void *)ie - (void *)msg->data; - ie_size = sizeof(*ie) + ntohs(ie->length_networkorder); - after_ie = msg_len - ie_size - before_ie; - if (after_ie) - memcpy(msg->data + before_ie, msg->data + before_ie + ie_size, after_ie); - msg->length_networkorder = htons(msg_len - ie_size); - - return 0; -} - -/* add information element - * the type is given by ie_type and length is given by ie_len - * the return value is a pointer to the data of the IE - */ -void *osmo_cc_add_ie(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_len) -{ - uint16_t msg_len; - int new_msg_len; - uint8_t *p; - osmo_cc_ie_t *ie; - - /* get pointer to first IE, if any */ - p = msg->data; - /* expand messasge */ - msg_len = ntohs(msg->length_networkorder); - new_msg_len = msg_len + sizeof(*ie) + ie_len; - if (new_msg_len > 65535) { - LOGP(DCC, LOGL_ERROR, "MSG overflow\n"); - return NULL; - } - msg->length_networkorder = htons(new_msg_len); - /* go to end of (unexpanded) message */ - ie = (osmo_cc_ie_t *)(p + msg_len); - /* add ie */ - ie->type = ie_type; - ie->length_networkorder = htons(ie_len); - memset(ie->data, 0, ie_len); /* just in case there is something, but it shouldn't */ - - return ie->data; -} - -/* gets the information element's data that *iep points to and returns that ie. - * if *iep points to msg->data, the first IE's data is returned. (must be set before first call.) - * if *iep points to the end of the message, NULL is returned. - * if there is no next IE, *iep is set to point to the end of message. - */ -void *osmo_cc_msg_sep_ie(osmo_cc_msg_t *msg, void **iep, uint8_t *ie_type, uint16_t *ie_length) -{ - uint16_t msg_len; - osmo_cc_ie_t *ie; - - /* in case that *iep points to start of message, make it point to first IE */ - if (*iep == msg) - *iep = msg->data; - /* case IE */ - ie = *iep; - /* check if it is NULL */ - if (ie == NULL) - return NULL; - /* check if it points to the end of message or there is not at least an IE header */ - msg_len = ntohs(msg->length_networkorder); - if ((int)((uint8_t *)ie - msg->data) > (int)(msg_len - sizeof(*ie))) - return NULL; - /* increment iep and return IE */ - *ie_type = ie->type; - *ie_length = ntohs(ie->length_networkorder); - *iep = (uint8_t *)ie + sizeof(*ie) + *ie_length; - return ie->data; -} - -/* copy given block to given string with given size */ -static void _ie2string(char *string, size_t string_size, const char *ie_string, int ie_size) -{ - int copy_size; - - copy_size = string_size - 1; - if (ie_size < copy_size) - copy_size = ie_size; - memcpy(string, ie_string, copy_size); - string[copy_size] = '\0'; -} - -/* helper to encode called party number (dialing) */ -void osmo_cc_add_ie_called(osmo_cc_msg_t *msg, uint8_t type, uint8_t plan, const char *dialing) -{ - struct osmo_cc_ie_called *ie_called; - - ie_called = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLED, sizeof(*ie_called) + strlen(dialing)); - ie_called->type = type; - ie_called->plan = plan; - memcpy(ie_called->digits, dialing, strlen(dialing)); -} - -/* helper to decode called party number (dialing) */ -int osmo_cc_get_ie_called(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, uint8_t *plan, char *dialing, size_t dialing_size) -{ - struct osmo_cc_ie_called *ie_called; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLED, ie_repeat, sizeof(*ie_called), (const void **)&ie_called); - if (rc < 0) - return rc; - *type = ie_called->type; - *plan = ie_called->plan; - _ie2string(dialing, dialing_size, ie_called->digits, rc); - return rc; -} - -/* helper to encode called party sub address (dialing) */ -void osmo_cc_add_ie_called_sub(osmo_cc_msg_t *msg, uint8_t type, const char *dialing) -{ - struct osmo_cc_ie_called_sub *ie_called_sub; - - ie_called_sub = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLED_SUB, sizeof(*ie_called_sub) + strlen(dialing)); - ie_called_sub->type = type; - memcpy(ie_called_sub->digits, dialing, strlen(dialing)); -} - -/* helper to decode called party sub address (dialing) */ -int osmo_cc_get_ie_called_sub(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, char *dialing, size_t dialing_size) -{ - struct osmo_cc_ie_called_sub *ie_called_sub; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLED_SUB, ie_repeat, sizeof(*ie_called_sub), (const void **)&ie_called_sub); - if (rc < 0) - return rc; - *type = ie_called_sub->type; - _ie2string(dialing, dialing_size, ie_called_sub->digits, rc); - return rc; -} - -/* helper to encode called party name (dialing) */ -void osmo_cc_add_ie_called_name(osmo_cc_msg_t *msg, const char *name) -{ - struct osmo_cc_ie_called_name *ie_called_name; - - ie_called_name = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLED_NAME, sizeof(*ie_called_name) + strlen(name)); - memcpy(ie_called_name->name, name, strlen(name)); -} - -/* helper to decode called party name (dialing) */ -int osmo_cc_get_ie_called_name(osmo_cc_msg_t *msg, int ie_repeat, char *name, size_t name_size) -{ - struct osmo_cc_ie_called_name *ie_called_name; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLED_NAME, ie_repeat, sizeof(*ie_called_name), (const void **)&ie_called_name); - if (rc < 0) - return rc; - _ie2string(name, name_size, ie_called_name->name, rc); - return rc; -} - -/* helper to encode called interface name */ -void osmo_cc_add_ie_called_interface(osmo_cc_msg_t *msg, const char *interface) -{ - struct osmo_cc_ie_called_interface *ie_interface; - - ie_interface = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLED_INTERFACE, sizeof(*ie_interface) + strlen(interface)); - memcpy(ie_interface->name, interface, strlen(interface)); -} - -/* helper to decode called interface name */ -int osmo_cc_get_ie_called_interface(osmo_cc_msg_t *msg, int ie_repeat, char *interface, size_t interface_size) -{ - struct osmo_cc_ie_called_interface *ie_interface; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLED_INTERFACE, ie_repeat, sizeof(*ie_interface), (const void **)&ie_interface); - if (rc < 0) - return rc; - _ie2string(interface, interface_size, ie_interface->name, rc); - return rc; -} - -/* helper to encode complete IE */ -void osmo_cc_add_ie_complete(osmo_cc_msg_t *msg) -{ - osmo_cc_add_ie(msg, OSMO_CC_IE_COMPLETE, 0); -} - -/* helper to decode complete IE */ -int osmo_cc_get_ie_complete(osmo_cc_msg_t *msg, int ie_repeat) -{ - int rc; - void *ie_complete; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_COMPLETE, ie_repeat, 0, (const void **)&ie_complete); - return rc; -} - -/* helper to encode calling/connected party number (caller ID or connected ID) */ -void osmo_cc_add_ie_calling(osmo_cc_msg_t *msg, uint8_t type, uint8_t plan, uint8_t present, uint8_t screen, const char *callerid) -{ - struct osmo_cc_ie_calling *ie_calling; - - ie_calling = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLING, sizeof(*ie_calling) + strlen(callerid)); - ie_calling->type = type; - ie_calling->plan = plan; - ie_calling->present = present; - ie_calling->screen = screen; - memcpy(ie_calling->digits, callerid, strlen(callerid)); -} - -/* helper to decode calling/connected party number (caller ID or connected ID) */ -int osmo_cc_get_ie_calling(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, uint8_t *plan, uint8_t *present, uint8_t *screen, char *callerid, size_t callerid_size) -{ - struct osmo_cc_ie_calling *ie_calling; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLING, ie_repeat, sizeof(*ie_calling), (const void **)&ie_calling); - if (rc < 0) - return rc; - *type = ie_calling->type; - *plan = ie_calling->plan; - *present = ie_calling->present; - *screen = ie_calling->screen; - _ie2string(callerid, callerid_size, ie_calling->digits, rc); - return rc; -} - -/* helper to encode calling/connected sub address (caller ID or connected ID) */ -void osmo_cc_add_ie_calling_sub(osmo_cc_msg_t *msg, uint8_t type, const char *callerid) -{ - struct osmo_cc_ie_calling_sub *ie_calling_sub; - - ie_calling_sub = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLING_SUB, sizeof(*ie_calling_sub) + strlen(callerid)); - ie_calling_sub->type = type; - memcpy(ie_calling_sub->digits, callerid, strlen(callerid)); -} - -/* helper to decode calling/connected sub address (caller ID or connected ID) */ -int osmo_cc_get_ie_calling_sub(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, char *callerid, size_t callerid_size) -{ - struct osmo_cc_ie_calling_sub *ie_calling_sub; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLING_SUB, ie_repeat, sizeof(*ie_calling_sub), (const void **)&ie_calling_sub); - if (rc < 0) - return rc; - *type = ie_calling_sub->type; - _ie2string(callerid, callerid_size, ie_calling_sub->digits, rc); - return rc; -} - -/* helper to encode calling/connected name (caller ID or connected ID) */ -void osmo_cc_add_ie_calling_name(osmo_cc_msg_t *msg, const char *name) -{ - struct osmo_cc_ie_calling_name *ie_calling_name; - - ie_calling_name = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLING_NAME, sizeof(*ie_calling_name) + strlen(name)); - memcpy(ie_calling_name->name, name, strlen(name)); -} - -/* helper to decode calling/connected name address (caller ID or connected ID) */ -int osmo_cc_get_ie_calling_name(osmo_cc_msg_t *msg, int ie_repeat, char *name, size_t name_size) -{ - struct osmo_cc_ie_calling_name *ie_calling_name; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLING_NAME, ie_repeat, sizeof(*ie_calling_name), (const void **)&ie_calling_name); - if (rc < 0) - return rc; - _ie2string(name, name_size, ie_calling_name->name, rc); - return rc; -} - -/* helper to encode calling interface name */ -void osmo_cc_add_ie_calling_interface(osmo_cc_msg_t *msg, const char *interface) -{ - struct osmo_cc_ie_calling_interface *ie_interface; - - ie_interface = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLING_INTERFACE, sizeof(*ie_interface) + strlen(interface)); - memcpy(ie_interface->name, interface, strlen(interface)); -} - -/* helper to decode calling interface name */ -int osmo_cc_get_ie_calling_interface(osmo_cc_msg_t *msg, int ie_repeat, char *interface, size_t interface_size) -{ - struct osmo_cc_ie_calling_interface *ie_interface; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLING_INTERFACE, ie_repeat, sizeof(*ie_interface), (const void **)&ie_interface); - if (rc < 0) - return rc; - _ie2string(interface, interface_size, ie_interface->name, rc); - return rc; -} - -/* helper to encode network specific caller/connected ID */ -void osmo_cc_add_ie_calling_network(osmo_cc_msg_t *msg, uint8_t type, const char *networkid) -{ - struct osmo_cc_ie_network *ie_network; - - ie_network = osmo_cc_add_ie(msg, OSMO_CC_IE_CALLING_NETWORK, sizeof(*ie_network) + strlen(networkid)); - ie_network->type = type; - memcpy(ie_network->id, networkid, strlen(networkid)); -} - -/* helper to encode network specific caller/connected ID */ -int osmo_cc_get_ie_calling_network(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, char *networkid, size_t networkid_size) -{ - struct osmo_cc_ie_network *ie_network; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CALLING_NETWORK, ie_repeat, sizeof(*ie_network), (const void **)&ie_network); - if (rc < 0) - return rc; - *type = ie_network->type; - _ie2string(networkid, networkid_size, ie_network->id, rc); - return rc; -} - -/* helper to encode bearer capability */ -void osmo_cc_add_ie_bearer(osmo_cc_msg_t *msg, uint8_t coding, uint8_t capability, uint8_t mode) -{ - struct osmo_cc_ie_bearer *ie_bearer; - - ie_bearer = osmo_cc_add_ie(msg, OSMO_CC_IE_BEARER, sizeof(*ie_bearer)); - ie_bearer->coding = coding; - ie_bearer->capability = capability; - ie_bearer->mode = mode; -} - -/* helper to decode bearer capability */ -int osmo_cc_get_ie_bearer(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *coding, uint8_t *capability, uint8_t *mode) -{ - struct osmo_cc_ie_bearer *ie_bearer; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_BEARER, ie_repeat, sizeof(*ie_bearer), (const void **)&ie_bearer); - if (rc < 0) - return rc; - *coding = ie_bearer->coding; - *capability = ie_bearer->capability; - *mode = ie_bearer->mode; - return rc; -} - -/* helper to encode redirection and redirecting number */ -void osmo_cc_add_ie_redir(osmo_cc_msg_t *msg, uint8_t type, uint8_t plan, uint8_t present, uint8_t screen, uint8_t redir_reason, const char *callerid) -{ - struct osmo_cc_ie_redir *ie_redir; - - ie_redir = osmo_cc_add_ie(msg, OSMO_CC_IE_REDIR, sizeof(*ie_redir) + strlen(callerid)); - ie_redir->type = type; - ie_redir->plan = plan; - ie_redir->present = present; - ie_redir->screen = screen; - ie_redir->redir_reason = redir_reason; - memcpy(ie_redir->digits, callerid, strlen(callerid)); -} - -/* helper to decode redirection and redirecting number */ -int osmo_cc_get_ie_redir(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, uint8_t *plan, uint8_t *present, uint8_t *screen, uint8_t *reason, char *callerid, size_t callerid_size) -{ - struct osmo_cc_ie_redir *ie_redir; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_REDIR, ie_repeat, sizeof(*ie_redir), (const void **)&ie_redir); - if (rc < 0) - return rc; - *type = ie_redir->type; - *plan = ie_redir->plan; - *present = ie_redir->present; - *screen = ie_redir->screen; - *reason = ie_redir->redir_reason; - _ie2string(callerid, callerid_size, ie_redir->digits, rc); - return rc; -} - -/* helper to encode DTMF tones */ -void osmo_cc_add_ie_dtmf(osmo_cc_msg_t *msg, uint8_t duration_ms, uint8_t pause_ms, uint8_t dtmf_mode, const char *digits) -{ - struct osmo_cc_ie_dtmf *ie_dtmf; - - ie_dtmf = osmo_cc_add_ie(msg, OSMO_CC_IE_DTMF, sizeof(*ie_dtmf) + strlen(digits)); - ie_dtmf->duration_ms = duration_ms; - ie_dtmf->pause_ms = pause_ms; - ie_dtmf->dtmf_mode = dtmf_mode; - memcpy(ie_dtmf->digits, digits, strlen(digits)); -} - -/* helper to decode DTMF tones */ -int osmo_cc_get_ie_dtmf(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *duration_ms, uint8_t *pause_ms, uint8_t *dtmf_mode, char *digits, size_t digits_size) -{ - struct osmo_cc_ie_dtmf *ie_dtmf; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_DTMF, ie_repeat, sizeof(*ie_dtmf), (const void **)&ie_dtmf); - if (rc < 0) - return rc; - *duration_ms = ie_dtmf->duration_ms; - *pause_ms = ie_dtmf->pause_ms; - *dtmf_mode = ie_dtmf->dtmf_mode; - _ie2string(digits, digits_size, ie_dtmf->digits, rc); - return rc; -} - -/* helper to encode keypad press */ -void osmo_cc_add_ie_keypad(osmo_cc_msg_t *msg, const char *digits) -{ - struct osmo_cc_ie_keypad *ie_keypad; - - ie_keypad = osmo_cc_add_ie(msg, OSMO_CC_IE_KEYPAD, sizeof(*ie_keypad) + strlen(digits)); - memcpy(ie_keypad->digits, digits, strlen(digits)); -} - -/* helper to decode keypad press */ -int osmo_cc_get_ie_keypad(osmo_cc_msg_t *msg, int ie_repeat, char *digits, size_t digits_size) -{ - struct osmo_cc_ie_keypad *ie_keypad; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_KEYPAD, ie_repeat, sizeof(*ie_keypad), (const void **)&ie_keypad); - if (rc < 0) - return rc; - _ie2string(digits, digits_size, ie_keypad->digits, rc); - return rc; -} - -/* helper to encode call progress information */ -void osmo_cc_add_ie_progress(osmo_cc_msg_t *msg, uint8_t coding, uint8_t location, uint8_t progress) -{ - struct osmo_cc_ie_progress *ie_progress; - - ie_progress = osmo_cc_add_ie(msg, OSMO_CC_IE_PROGRESS, sizeof(*ie_progress)); - ie_progress->coding = coding; - ie_progress->location = location; - ie_progress->progress = progress; -} - -/* helper to decode call progress information */ -int osmo_cc_get_ie_progress(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *coding, uint8_t *location, uint8_t *progress) -{ - struct osmo_cc_ie_progress *ie_progress; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_PROGRESS, ie_repeat, sizeof(*ie_progress), (const void **)&ie_progress); - if (rc < 0) - return rc; - *coding = ie_progress->coding; - *location = ie_progress->location; - *progress = ie_progress->progress; - return rc; -} - -/* helper to encode notification */ -void osmo_cc_add_ie_notify(osmo_cc_msg_t *msg, uint8_t notify) -{ - struct osmo_cc_ie_notify *ie_notify; - - ie_notify = osmo_cc_add_ie(msg, OSMO_CC_IE_NOTIFY, sizeof(*ie_notify)); - ie_notify->notify = notify; -} - -/* helper to decode notification */ -int osmo_cc_get_ie_notify(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *notify) -{ - struct osmo_cc_ie_notify *ie_notify; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_NOTIFY, ie_repeat, sizeof(*ie_notify), (const void **)&ie_notify); - if (rc < 0) - return rc; - *notify = ie_notify->notify; - return rc; -} - -/* helper to encode cause */ -void osmo_cc_add_ie_cause(osmo_cc_msg_t *msg, uint8_t location, uint8_t isdn_cause, uint16_t sip_cause, uint8_t socket_cause) -{ - struct osmo_cc_ie_cause *ie_cause; - - ie_cause = osmo_cc_add_ie(msg, OSMO_CC_IE_CAUSE, sizeof(*ie_cause)); - ie_cause->location = location; - ie_cause->isdn_cause = isdn_cause; - ie_cause->sip_cause_networkorder = htons(sip_cause); - ie_cause->socket_cause = socket_cause; -} - -/* helper to deccode cause */ -int osmo_cc_get_ie_cause(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *location, uint8_t *isdn_cause, uint16_t *sip_cause, uint8_t *socket_cause) -{ - struct osmo_cc_ie_cause *ie_cause; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_CAUSE, ie_repeat, sizeof(*ie_cause), (const void **)&ie_cause); - if (rc < 0) - return rc; - *location = ie_cause->location; - *isdn_cause = ie_cause->isdn_cause; - *sip_cause = ntohs(ie_cause->sip_cause_networkorder); - *socket_cause = ie_cause->socket_cause; - return rc; -} - -/* helper to encode DISPLAY information */ -void osmo_cc_add_ie_display(osmo_cc_msg_t *msg, const char *text) -{ - struct osmo_cc_ie_display *ie_display; - - ie_display = osmo_cc_add_ie(msg, OSMO_CC_IE_DISPLAY, sizeof(*ie_display) + strlen(text)); - memcpy(ie_display->text, text, strlen(text)); -} - -/* helper to decode DISPLAY information */ -int osmo_cc_get_ie_display(osmo_cc_msg_t *msg, int ie_repeat, char *text, size_t text_size) -{ - struct osmo_cc_ie_display *ie_display; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_DISPLAY, ie_repeat, sizeof(*ie_display), (const void **)&ie_display); - if (rc < 0) - return rc; - _ie2string(text, text_size, ie_display->text, rc); - return rc; -} - -/* helper to encode SDP */ -void osmo_cc_add_ie_sdp(osmo_cc_msg_t *msg, const char *sdp) -{ - struct osmo_cc_ie_sdp *ie_sdp; - - ie_sdp = osmo_cc_add_ie(msg, OSMO_CC_IE_SDP, sizeof(*ie_sdp) + strlen(sdp)); - memcpy(ie_sdp->sdp, sdp, strlen(sdp)); -} - -/* helper to decode SDP */ -int osmo_cc_get_ie_sdp(osmo_cc_msg_t *msg, int ie_repeat, char *sdp, size_t sdp_size) -{ - struct osmo_cc_ie_sdp *ie_sdp; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_SDP, ie_repeat, sizeof(*ie_sdp), (const void **)&ie_sdp); - if (rc < 0) - return rc; - _ie2string(sdp, sdp_size, ie_sdp->sdp, rc); - return rc; -} - -/* helper to encode socket address */ -void osmo_cc_add_ie_socket_address(osmo_cc_msg_t *msg, const char *address) -{ - struct osmo_cc_ie_socket_address *ie_socket_address; - - ie_socket_address = osmo_cc_add_ie(msg, OSMO_CC_IE_SOCKET_ADDRESS, sizeof(*ie_socket_address) + strlen(address)); - memcpy(ie_socket_address->address, address, strlen(address)); -} - -/* helper to decode socket address */ -int osmo_cc_get_ie_socket_address(osmo_cc_msg_t *msg, int ie_repeat, char *address, size_t address_size) -{ - struct osmo_cc_ie_socket_address *ie_socket_address; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_SOCKET_ADDRESS, ie_repeat, sizeof(*ie_socket_address), (const void **)&ie_socket_address); - if (rc < 0) - return rc; - _ie2string(address, address_size, ie_socket_address->address, rc); - return rc; -} - -/* helper to encode private information element */ -void osmo_cc_add_ie_private(osmo_cc_msg_t *msg, uint32_t unique, const uint8_t *data, size_t data_size) -{ - struct osmo_cc_ie_private *ie_private; - - ie_private = osmo_cc_add_ie(msg, OSMO_CC_IE_PRIVATE, sizeof(*ie_private) + data_size); - ie_private->unique_networkorder = htonl(unique); - memcpy(ie_private->data, data, data_size); -} - -/* helper to decode private information element */ -int osmo_cc_get_ie_private(osmo_cc_msg_t *msg, int ie_repeat, uint32_t *unique, uint8_t *data, size_t data_size) -{ - struct osmo_cc_ie_private *ie_private; - int rc; - - rc = osmo_cc_get_ie_data(msg, OSMO_CC_IE_PRIVATE, ie_repeat, sizeof(*ie_private), (const void **)&ie_private); - if (rc < 0) - return rc; - *unique = ntohl(ie_private->unique_networkorder); - if (rc > (int)data_size) - rc = data_size; - memcpy(data, ie_private->data, rc); - return rc; -} - diff --git a/src/libosmocc/message.h b/src/libosmocc/message.h deleted file mode 100644 index 2d7b39b..0000000 --- a/src/libosmocc/message.h +++ /dev/null @@ -1,513 +0,0 @@ -#ifndef OSMO_CC_MSG_H -#define OSMO_CC_MSG_H - -#define OSMO_CC_VERSION "OSMOCCv1" - -/* call control messages types */ -enum osmo_cc_msg_type { - OSMO_CC_MSG_SETUP_REQ = 0x00, - OSMO_CC_MSG_SETUP_IND = 0x01, - OSMO_CC_MSG_REJ_REQ = 0x10, - OSMO_CC_MSG_REJ_IND = 0x11, - OSMO_CC_MSG_SETUP_ACK_REQ = 0x20, - OSMO_CC_MSG_SETUP_ACK_IND = 0x21, - OSMO_CC_MSG_PROC_REQ = 0x30, - OSMO_CC_MSG_PROC_IND = 0x31, - OSMO_CC_MSG_ALERT_REQ = 0x40, - OSMO_CC_MSG_ALERT_IND = 0x41, - OSMO_CC_MSG_SETUP_RSP = 0x02, - OSMO_CC_MSG_SETUP_CNF = 0x03, - OSMO_CC_MSG_SETUP_COMP_REQ = 0x50, - OSMO_CC_MSG_SETUP_COMP_IND = 0x51, - OSMO_CC_MSG_DISC_REQ = 0x60, - OSMO_CC_MSG_DISC_IND = 0x61, - OSMO_CC_MSG_REL_REQ = 0x70, - OSMO_CC_MSG_REL_CNF = 0x73, - OSMO_CC_MSG_REL_IND = 0x71, - OSMO_CC_MSG_PROGRESS_REQ = 0x80, - OSMO_CC_MSG_PROGRESS_IND = 0x81, - OSMO_CC_MSG_NOTIFY_REQ = 0x84, - OSMO_CC_MSG_NOTIFY_IND = 0x85, - OSMO_CC_MSG_INFO_REQ = 0x88, - OSMO_CC_MSG_INFO_IND = 0x89, - OSMO_CC_MSG_MODIFY_REQ = 0x90, - OSMO_CC_MSG_MODIFY_IND = 0x91, - OSMO_CC_MSG_MODIFY_RSP = 0x92, - OSMO_CC_MSG_MODIFY_CNF = 0x93, - OSMO_CC_MSG_ATTACH_REQ = 0xf8, - OSMO_CC_MSG_ATTACH_IND = 0xf9, - OSMO_CC_MSG_ATTACH_RSP = 0xfa, - OSMO_CC_MSG_ATTACH_CNF = 0xfb, - OSMO_CC_MSG_DUMMY_REQ = 0xfc, -}; -#define OSMO_CC_MSG_NUM 0x100 - -#define OSMO_CC_MSG_MASK 0x03, -#define OSMO_CC_MSG_REQ 0x00, -#define OSMO_CC_MSG_IND 0x01, -#define OSMO_CC_MSG_RSP 0x02, -#define OSMO_CC_MSG_CNF 0x03, - -const char *osmo_cc_msg_value2name(int value); -int osmo_cc_msg_name2value(const char *name); - -/* information elements */ -enum osmo_cc_ie_type { - OSMO_CC_IE_CALLED = 0x11, - OSMO_CC_IE_CALLED_SUB = 0x12, - OSMO_CC_IE_CALLED_NAME = 0x13, - OSMO_CC_IE_CALLED_INTERFACE = 0x14, - OSMO_CC_IE_DTMF = 0x1d, - OSMO_CC_IE_KEYPAD = 0x1e, - OSMO_CC_IE_COMPLETE = 0x1f, - OSMO_CC_IE_CALLING = 0x21, - OSMO_CC_IE_CALLING_SUB = 0x22, - OSMO_CC_IE_CALLING_NAME = 0x23, - OSMO_CC_IE_CALLING_INTERFACE = 0x24, - OSMO_CC_IE_CALLING_NETWORK = 0x2f, - OSMO_CC_IE_REDIR = 0x31, - OSMO_CC_IE_PROGRESS = 0x32, - OSMO_CC_IE_NOTIFY = 0x33, - OSMO_CC_IE_DISPLAY = 0x34, - OSMO_CC_IE_CAUSE = 0x41, - OSMO_CC_IE_BEARER = 0x51, - OSMO_CC_IE_SDP = 0x52, - OSMO_CC_IE_SOCKET_ADDRESS = 0x5e, - OSMO_CC_IE_PRIVATE = 0x5f, -}; -#define OSMO_CC_IE_NUM 0x100 - -const char *osmo_cc_ie_value2name(int value); -int osmo_cc_ie_name2value(const char *name); - -/* type of number, see ITU-T Rec. Q.931 */ -#define OSMO_CC_TYPE_UNKNOWN 0 -#define OSMO_CC_TYPE_INTERNATIONAL 1 -#define OSMO_CC_TYPE_NATIONAL 2 -#define OSMO_CC_TYPE_NETWORK 3 -#define OSMO_CC_TYPE_SUBSCRIBER 4 -#define OSMO_CC_TYPE_ABBREVIATED 5 -#define OSMO_CC_TYPE_RESERVED 7 -#define OSMO_CC_TYPE_NUM 8 - -const char *osmo_cc_type_value2name(int value); -int osmo_cc_type_name2value(const char *name); - -/* numbering plan, see ITU-T Rec. Q.931 */ -#define OSMO_CC_PLAN_UNKNOWN 0 -#define OSMO_CC_PLAN_TELEPHONY 1 -#define OSMO_CC_PLAN_DATA 3 -#define OSMO_CC_PLAN_TTY 4 -#define OSMO_CC_PLAN_NATIONAL_STANDARD 8 -#define OSMO_CC_PLAN_PRIVATE 9 -#define OSMO_CC_PLAN_RESERVED 15 -#define OSMO_CC_PLAN_NUM 16 - -const char *osmo_cc_plan_value2name(int value); -int osmo_cc_plan_name2value(const char *name); - -/* presentation indicator, see ITU-T Rec. Q.931 */ -#define OSMO_CC_PRESENT_ALLOWED 0 -#define OSMO_CC_PRESENT_RESTRICTED 1 -#define OSMO_CC_PRESENT_NOT_AVAIL 2 -#define OSMO_CC_PRESENT_RESERVED 3 -#define OSMO_CC_PRESENT_NUM 4 - -const char *osmo_cc_present_value2name(int value); -int osmo_cc_present_name2value(const char *name); - -/* screening indicator, see ITU-T Rec. Q.931 */ -#define OSMO_CC_SCREEN_USER_UNSCREENED 0 -#define OSMO_CC_SCREEN_USER_VERIFIED_PASSED 1 -#define OSMO_CC_SCREEN_USER_VERIFIED_FAILED 2 -#define OSMO_CC_SCREEN_NETWORK 3 -#define OSMO_CC_SCREEN_NUM 4 - -const char *osmo_cc_screen_value2name(int value); -int osmo_cc_screen_name2value(const char *name); - -/* screening indicator, see ITU-T Rec. Q.931 */ -#define OSMO_CC_REDIR_REASON_UNKNOWN 0 -#define OSMO_CC_REDIR_REASON_CFB 1 -#define OSMO_CC_REDIR_REASON_CFNR 2 -#define OSMO_CC_REDIR_REASON_CD 4 -#define OSMO_CC_REDIR_REASON_CF_OUTOFORDER 9 -#define OSMO_CC_REDIR_REASON_CF_BY_DTE 10 -#define OSMO_CC_REDIR_REASON_CFU 15 -#define OSMO_CC_REDIR_REASON_NUM 16 - -const char *osmo_cc_redir_reason_value2name(int value); -int osmo_cc_redir_reason_name2value(const char *name); - -/* notification indicator, see ITU-T Rec. Q.931 ff. */ -#define OSMO_CC_NOTIFY_USER_SUSPENDED 0x00 -#define OSMO_CC_NOTIFY_USER_RESUMED 0x01 -#define OSMO_CC_NOTIFY_BEARER_SERVICE_CHANGE 0x02 -#define OSMO_CC_NOTIFY_CALL_COMPLETION_DELAY 0x03 -#define OSMO_CC_NOTIFY_CONFERENCE_ESTABLISHED 0x42 -#define OSMO_CC_NOTIFY_CONFERENCE_DISCONNECTED 0x43 -#define OSMO_CC_NOTIFY_OTHER_PARTY_ADDED 0x44 -#define OSMO_CC_NOTIFY_ISOLATED 0x45 -#define OSMO_CC_NOTIFY_REATTACHED 0x46 -#define OSMO_CC_NOTIFY_OTHER_PARTY_ISOLATED 0x47 -#define OSMO_CC_NOTIFY_OTHER_PARTY_REATTACHED 0x48 -#define OSMO_CC_NOTIFY_OTHER_PARTY_SPLIT 0x49 -#define OSMO_CC_NOTIFY_OTHER_PARTY_DISCONNECTED 0x4a -#define OSMO_CC_NOTIFY_CONFERENCE_FLOATING 0x4b -#define OSMO_CC_NOTIFY_CONFERENCE_DISC_PREEMPT 0x4c /* disconnect preemted */ -#define OSMO_CC_NOTIFY_CONFERENCE_FLOATING_SUP 0x4f /* served user preemted */ -#define OSMO_CC_NOTIFY_CALL_IS_A_WAITING_CALL 0x60 -#define OSMO_CC_NOTIFY_DIVERSION_ACTIVATED 0x68 -#define OSMO_CC_NOTIFY_RESERVED_CT_1 0x69 -#define OSMO_CC_NOTIFY_RESERVED_CT_2 0x6a -#define OSMO_CC_NOTIFY_REVERSE_CHARGING 0x6e -#define OSMO_CC_NOTIFY_REMOTE_HOLD 0x79 -#define OSMO_CC_NOTIFY_REMOTE_RETRIEVAL 0x7a -#define OSMO_CC_NOTIFY_CALL_IS_DIVERTING 0x7b -#define OSMO_CC_NOTIFY_NUM 0x100 - -const char *osmo_cc_notify_value2name(int value); -int osmo_cc_notify_name2value(const char *name); - -/* coding standard, see ITU-T Rec. Q.931 */ -#define OSMO_CC_CODING_ITU_T 0 -#define OSMO_CC_CODING_ISO_IEC 1 -#define OSMO_CC_CODING_NATIONAL 2 -#define OSMO_CC_CODING_STANDARD_SPECIFIC 3 -#define OSMO_CC_CODING_NUM 4 - -const char *osmo_cc_coding_value2name(int value); -int osmo_cc_coding_name2value(const char *name); - -/* cause, see ITU-T Rec. Q.850 */ -#define OSMO_CC_ISDN_CAUSE_UNASSIGNED_NR 1 -#define OSMO_CC_ISDN_CAUSE_NO_ROUTE_TRANSIT 2 -#define OSMO_CC_ISDN_CAUSE_NO_ROUTE 3 -#define OSMO_CC_ISDN_CAUSE_CHAN_UNACCEPT 6 -#define OSMO_CC_ISDN_CAUSE_OP_DET_BARRING 8 -#define OSMO_CC_ISDN_CAUSE_NORM_CALL_CLEAR 16 -#define OSMO_CC_ISDN_CAUSE_USER_BUSY 17 -#define OSMO_CC_ISDN_CAUSE_USER_NOTRESPOND 18 -#define OSMO_CC_ISDN_CAUSE_USER_ALERTING_NA 19 -#define OSMO_CC_ISDN_CAUSE_CALL_REJECTED 21 -#define OSMO_CC_ISDN_CAUSE_NUMBER_CHANGED 22 -#define OSMO_CC_ISDN_CAUSE_PRE_EMPTION 25 -#define OSMO_CC_ISDN_CAUSE_NONSE_USER_CLR 26 -#define OSMO_CC_ISDN_CAUSE_DEST_OOO 27 -#define OSMO_CC_ISDN_CAUSE_INV_NR_FORMAT 28 -#define OSMO_CC_ISDN_CAUSE_FACILITY_REJ 29 -#define OSMO_CC_ISDN_CAUSE_RESP_STATUS_INQ 30 -#define OSMO_CC_ISDN_CAUSE_NORMAL_UNSPEC 31 -#define OSMO_CC_ISDN_CAUSE_NO_CIRCUIT_CHAN 34 -#define OSMO_CC_ISDN_CAUSE_NETWORK_OOO 38 -#define OSMO_CC_ISDN_CAUSE_TEMP_FAILURE 41 -#define OSMO_CC_ISDN_CAUSE_SWITCH_CONG 42 -#define OSMO_CC_ISDN_CAUSE_ACC_INF_DISCARD 43 -#define OSMO_CC_ISDN_CAUSE_REQ_CHAN_UNAVAIL 44 -#define OSMO_CC_ISDN_CAUSE_RESOURCE_UNAVAIL 47 -#define OSMO_CC_ISDN_CAUSE_QOS_UNAVAIL 49 -#define OSMO_CC_ISDN_CAUSE_REQ_FAC_NOT_SUBSC 50 -#define OSMO_CC_ISDN_CAUSE_INC_BARRED_CUG 55 -#define OSMO_CC_ISDN_CAUSE_BEARER_CAP_UNAUTH 57 -#define OSMO_CC_ISDN_CAUSE_BEARER_CA_UNAVAIL 58 -#define OSMO_CC_ISDN_CAUSE_SERV_OPT_UNAVAIL 63 -#define OSMO_CC_ISDN_CAUSE_BEARERSERV_UNIMPL 65 -#define OSMO_CC_ISDN_CAUSE_ACM_GE_ACM_MAX 68 -#define OSMO_CC_ISDN_CAUSE_REQ_FAC_NOTIMPL 69 -#define OSMO_CC_ISDN_CAUSE_RESTR_BCAP_AVAIL 70 -#define OSMO_CC_ISDN_CAUSE_SERV_OPT_UNIMPL 79 -#define OSMO_CC_ISDN_CAUSE_INVAL_CALLREF 81 -#define OSMO_CC_ISDN_CAUSE_USER_NOT_IN_CUG 87 -#define OSMO_CC_ISDN_CAUSE_INCOMPAT_DEST 88 -#define OSMO_CC_ISDN_CAUSE_INVAL_TRANS_NET 91 -#define OSMO_CC_ISDN_CAUSE_SEMANTIC_INCORR 95 -#define OSMO_CC_ISDN_CAUSE_INVAL_MAND_INF 96 -#define OSMO_CC_ISDN_CAUSE_MSGTYPE_NOTEXIST 97 -#define OSMO_CC_ISDN_CAUSE_MSGTYPE_INCOMPAT 98 -#define OSMO_CC_ISDN_CAUSE_IE_NOTEXIST 99 -#define OSMO_CC_ISDN_CAUSE_COND_IE_ERR 100 -#define OSMO_CC_ISDN_CAUSE_MSG_INCOMP_STATE 101 -#define OSMO_CC_ISDN_CAUSE_RECOVERY_TIMER 102 -#define OSMO_CC_ISDN_CAUSE_PROTO_ERR 111 -#define OSMO_CC_ISDN_CAUSE_INTERWORKING 127 -#define OSMO_CC_ISDN_CAUSE_NUM 128 - -const char *osmo_cc_isdn_cause_value2name(int value); -int osmo_cc_isdn_cause_name2value(const char *name); - -/* location, see ITU-T Rec. Q.931 */ -#define OSMO_CC_LOCATION_USER 0 -#define OSMO_CC_LOCATION_PRIV_SERV_LOC_USER 1 -#define OSMO_CC_LOCATION_PUB_SERV_LOC_USER 2 -#define OSMO_CC_LOCATION_TRANSIT 3 -#define OSMO_CC_LOCATION_PUB_SERV_REM_USER 4 -#define OSMO_CC_LOCATION_PRIV_SERV_REM_USER 5 -#define OSMO_CC_LOCATION_BEYOND_INTERWORKING 10 -#define OSMO_CC_LOCATION_NUM 16 - -const char *osmo_cc_location_value2name(int value); -int osmo_cc_location_name2value(const char *name); - -/* progress description, see ITU-T Rec. Q.931 */ -#define OSMO_CC_PROGRESS_NOT_END_TO_END_ISDN 1 -#define OSMO_CC_PROGRESS_DEST_NOT_ISDN 2 -#define OSMO_CC_PROGRESS_ORIG_NOT_ISDN 3 -#define OSMO_CC_PROGRESS_RETURN_TO_ISDN 4 -#define OSMO_CC_PROGRESS_INTERWORKING 5 -#define OSMO_CC_PROGRESS_INBAND_INFO_AVAILABLE 8 -#define OSMO_CC_PROGRESS_NUM 16 - -const char *osmo_cc_progress_value2name(int value); -int osmo_cc_progress_name2value(const char *name); - -/* information transfer capability, see ITU-T Rec. Q.931 */ -#define OSMO_CC_CAPABILITY_SPEECH 0 -#define OSMO_CC_CAPABILITY_DATA 8 -#define OSMO_CC_CAPABILITY_DATA_RESTRICTED 9 -#define OSMO_CC_CAPABILITY_AUDIO 16 -#define OSMO_CC_CAPABILITY_DATA_WITH_TONES 17 -#define OSMO_CC_CAPABILITY_VIDEO 24 -#define OSMO_CC_CAPABILITY_NUM 32 - -const char *osmo_cc_capability_value2name(int value); -int osmo_cc_capability_name2value(const char *name); - -/* transfer mode, see ITU-T Rec. Q.931 */ -#define OSMO_CC_MODE_CIRCUIT 0 -#define OSMO_CC_MODE_PACKET 2 -#define OSMO_CC_MODE_NUM 4 - -const char *osmo_cc_mode_value2name(int value); -int osmo_cc_mode_name2value(const char *name); - -#define OSMO_CC_DTMF_MODE_OFF 0 /* stop tone */ -#define OSMO_CC_DTMF_MODE_ON 1 /* start tone */ -#define OSMO_CC_DTMF_MODE_DIGITS 2 /* play tone(s) with duration and pauses */ -#define OSMO_CC_DTMF_MODE_NUM 3 - -const char *osmo_cc_dtmf_mode_value2name(int value); -int osmo_cc_dtmf_mode_name2value(const char *name); - -#define OSMO_CC_SOCKET_CAUSE_VERSION_MISMATCH 1 /* version mismatch */ -#define OSMO_CC_SOCKET_CAUSE_FAILED 2 /* connection failed */ -#define OSMO_CC_SOCKET_CAUSE_BROKEN_PIPE 3 /* connected socket failed */ -#define OSMO_CC_SOCKET_CAUSE_TIMEOUT 4 /* keepalive packets timeout */ -// if you add causes here, add them in process_cause.c also! -#define OSMO_CC_SOCKET_CAUSE_NUM 5 - -const char *osmo_cc_socket_cause_value2name(int value); -int osmo_cc_socket_cause_name2value(const char *name); - -/* network type (network IE) and meaning of 'id' */ -#define OSMO_CC_NETWORK_UNDEFINED 0x00 -#define OSMO_CC_NETWORK_ALSA_NONE 0x01 -#define OSMO_CC_NETWORK_POTS_NONE 0x02 -#define OSMO_CC_NETWORK_ISDN_NONE 0x03 -#define OSMO_CC_NETWORK_SIP_NONE 0x04 -#define OSMO_CC_NETWORK_GSM_IMSI 0x05 /* id has decimal IMSI */ -#define OSMO_CC_NETWORK_GSM_IMEI 0x06 /* id has decimal IMEI */ -#define OSMO_CC_NETWORK_WEB_NONE 0x07 -#define OSMO_CC_NETWORK_DECT_NONE 0x08 -#define OSMO_CC_NETWORK_BLUETOOTH_NONE 0x09 -#define OSMO_CC_NETWORK_SS5_NONE 0x0a -#define OSMO_CC_NETWORK_R1_NONE 0x0b -#define OSMO_CC_NETWORK_ANETZ_NONE 0x80 -#define OSMO_CC_NETWORK_BNETZ_MUENZ 0x81 /* id starts with 'M' */ -#define OSMO_CC_NETWORK_CNETZ_NONE 0x82 -#define OSMO_CC_NETWORK_NMT_NONE 0x83 /* id has decimal password */ -#define OSMO_CC_NETWORK_R2000_NONE 0x84 -#define OSMO_CC_NETWORK_AMPS_ESN 0x85 /* if has decimal ESN (TACS also) */ -#define OSMO_CC_NETWORK_MTS_NONE 0x86 -#define OSMO_CC_NETWORK_IMTS_NONE 0x87 -#define OSMO_CC_NETWORK_EUROSIGNAL_NONE 0x88 -#define OSMO_CC_NETWORK_JOLLYCOM_NONE 0x89 /* call from JollyCom... */ -#define OSMO_CC_NETWORK_MPT1327_PSTN 0x8a /* call from MPT1327 */ -#define OSMO_CC_NETWORK_MPT1327_PBX 0x8b /* id is selected PBX number */ -#define OSMO_CC_NETWORK_NUM 0x100 - -const char *osmo_cc_network_value2name(int value); -int osmo_cc_network_name2value(const char *name); - -typedef struct osmo_cc_msg { - uint8_t type; - uint16_t length_networkorder; - uint8_t data[0]; -} __attribute__((packed)) osmo_cc_msg_t; - -typedef struct osmo_cc_msg_list { - struct osmo_cc_msg_list *next; - struct osmo_cc_msg *msg; - uint32_t callref; - char host[128]; - uint16_t port; -} osmo_cc_msg_list_t; - -typedef struct osmo_cc_ie { - uint8_t type; - uint16_t length_networkorder; - uint8_t data[0]; -} __attribute__((packed)) osmo_cc_ie_t; - -struct osmo_cc_ie_called { - uint8_t type; - uint8_t plan; - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_called_sub { - uint8_t type; - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_called_name { - char name[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_called_interface { - char name[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_calling { - uint8_t type; - uint8_t plan; - uint8_t present; - uint8_t screen; - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_calling_sub { - uint8_t type; - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_calling_name { - char name[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_calling_interface { - char name[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_network { - uint8_t type; - char id[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_bearer { - uint8_t coding; - uint8_t capability; - uint8_t mode; -} __attribute__((packed)); - -struct osmo_cc_ie_redir { - uint8_t type; - uint8_t plan; - uint8_t present; - uint8_t screen; - uint8_t redir_reason; - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_dtmf { - uint8_t duration_ms; - uint8_t pause_ms; - uint8_t dtmf_mode; - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_keypad { - char digits[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_progress { - uint8_t coding; - uint8_t location; - uint8_t progress; -} __attribute__((packed)); - -struct osmo_cc_ie_notify { - uint8_t notify; -} __attribute__((packed)); - -struct osmo_cc_ie_cause { - uint8_t location; - uint8_t isdn_cause; - uint16_t sip_cause_networkorder; - uint8_t socket_cause; -} __attribute__((packed)); - -struct osmo_cc_ie_display { - char text[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_sdp { - char sdp[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_socket_address { - char address[0]; -} __attribute__((packed)); - -struct osmo_cc_ie_private { - uint32_t unique_networkorder; - uint8_t data[0]; -} __attribute__((packed)); - -uint32_t osmo_cc_new_callref(void); -osmo_cc_msg_t *osmo_cc_new_msg(uint8_t msg_type); -osmo_cc_msg_t *osmo_cc_clone_msg(osmo_cc_msg_t *msg); -osmo_cc_msg_t *osmo_cc_msg_list_dequeue(osmo_cc_msg_list_t **mlp, uint32_t *callref_p); -osmo_cc_msg_list_t *osmo_cc_msg_list_enqueue(osmo_cc_msg_list_t **mlp, osmo_cc_msg_t *msg, uint32_t callref); -void osmo_cc_free_msg(osmo_cc_msg_t *msg); -void osmo_cc_debug_ie(osmo_cc_msg_t *msg, int level); -int osmo_cc_get_ie_struct(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat, int ie_len, const osmo_cc_ie_t **ie_struct); -int osmo_cc_get_ie_data(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat, int ie_len, const void **ie_data); -int osmo_cc_has_ie(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat); -int osmo_cc_remove_ie(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_repeat); -void *osmo_cc_add_ie(osmo_cc_msg_t *msg, uint8_t ie_type, int ie_len); -void *osmo_cc_msg_sep_ie(osmo_cc_msg_t *msg, void **iep, uint8_t *ie_type, uint16_t *ie_length); - -void osmo_cc_add_ie_called(osmo_cc_msg_t *msg, uint8_t type, uint8_t plan, const char *dialing); -int osmo_cc_get_ie_called(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, uint8_t *plan, char *dialing, size_t dialing_size); -void osmo_cc_add_ie_called_sub(osmo_cc_msg_t *msg, uint8_t type, const char *dialing); -int osmo_cc_get_ie_called_sub(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, char *dialing, size_t dialing_size); -void osmo_cc_add_ie_called_name(osmo_cc_msg_t *msg, const char *name); -int osmo_cc_get_ie_called_name(osmo_cc_msg_t *msg, int ie_repeat, char *name, size_t name_size); -void osmo_cc_add_ie_called_interface(osmo_cc_msg_t *msg, const char *interface); -int osmo_cc_get_ie_called_interface(osmo_cc_msg_t *msg, int ie_repeat, char *interface, size_t interface_size); -void osmo_cc_add_ie_complete(osmo_cc_msg_t *msg); -int osmo_cc_get_ie_complete(osmo_cc_msg_t *msg, int ie_repeat); -void osmo_cc_add_ie_calling(osmo_cc_msg_t *msg, uint8_t type, uint8_t plan, uint8_t present, uint8_t screen, const char *callerid); -int osmo_cc_get_ie_calling(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, uint8_t *plan, uint8_t *present, uint8_t *screen, char *callerid, size_t callerid_size); -void osmo_cc_add_ie_calling_sub(osmo_cc_msg_t *msg, uint8_t type, const char *callerid); -int osmo_cc_get_ie_calling_sub(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, char *callerid, size_t callerid_size); -void osmo_cc_add_ie_calling_name(osmo_cc_msg_t *msg, const char *name); -int osmo_cc_get_ie_calling_name(osmo_cc_msg_t *msg, int ie_repeat, char *name, size_t name_size); -void osmo_cc_add_ie_calling_interface(osmo_cc_msg_t *msg, const char *interface); -int osmo_cc_get_ie_calling_interface(osmo_cc_msg_t *msg, int ie_repeat, char *interface, size_t interface_size); -void osmo_cc_add_ie_calling_network(osmo_cc_msg_t *msg, uint8_t type, const char *networkid); -int osmo_cc_get_ie_calling_network(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, char *networkid, size_t networkid_size); -void osmo_cc_add_ie_bearer(osmo_cc_msg_t *msg, uint8_t coding, uint8_t capability, uint8_t mode); -int osmo_cc_get_ie_bearer(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *coding, uint8_t *capability, uint8_t *mode); -void osmo_cc_add_ie_redir(osmo_cc_msg_t *msg, uint8_t type, uint8_t plan, uint8_t present, uint8_t screen, uint8_t redir_reason, const char *callerid); -int osmo_cc_get_ie_redir(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *type, uint8_t *plan, uint8_t *present, uint8_t *screen, uint8_t *reason, char *callerid, size_t callerid_size); -void osmo_cc_add_ie_dtmf(osmo_cc_msg_t *msg, uint8_t duration_ms, uint8_t pause_ms, uint8_t dtmf_mode, const char *digits); -int osmo_cc_get_ie_dtmf(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *duration_ms, uint8_t *pause_ms, uint8_t *dtmf_mode, char *digits, size_t digits_size); -void osmo_cc_add_ie_keypad(osmo_cc_msg_t *msg, const char *digits); -int osmo_cc_get_ie_keypad(osmo_cc_msg_t *msg, int ie_repeat, char *digits, size_t digits_size); -void osmo_cc_add_ie_progress(osmo_cc_msg_t *msg, uint8_t coding, uint8_t location, uint8_t progress); -int osmo_cc_get_ie_progress(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *coding, uint8_t *location, uint8_t *progress); -void osmo_cc_add_ie_notify(osmo_cc_msg_t *msg, uint8_t notify); -int osmo_cc_get_ie_notify(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *notify); -void osmo_cc_add_ie_cause(osmo_cc_msg_t *msg, uint8_t location, uint8_t isdn_cause, uint16_t sip_cause, uint8_t socket_cause); -int osmo_cc_get_ie_cause(osmo_cc_msg_t *msg, int ie_repeat, uint8_t *location, uint8_t *isdn_cause, uint16_t *sip_cause, uint8_t *socket_cause); -void osmo_cc_add_ie_display(osmo_cc_msg_t *msg, const char *text); -int osmo_cc_get_ie_display(osmo_cc_msg_t *msg, int ie_repeat, char *text, size_t text_size); -void osmo_cc_add_ie_sdp(osmo_cc_msg_t *msg, const char *sdp); -int osmo_cc_get_ie_sdp(osmo_cc_msg_t *msg, int ie_repeat, char *sdp, size_t sdp_size); -void osmo_cc_add_ie_socket_address(osmo_cc_msg_t *msg, const char *address); -int osmo_cc_get_ie_socket_address(osmo_cc_msg_t *msg, int ie_repeat, char *address, size_t address_size); -void osmo_cc_add_ie_private(osmo_cc_msg_t *msg, uint32_t unique, const uint8_t *data, size_t data_size); -int osmo_cc_get_ie_private(osmo_cc_msg_t *msg, int ie_repeat, uint32_t *unique, uint8_t *data, size_t data_size); - -#endif /* OSMO_CC_MSG_H */ diff --git a/src/libosmocc/rtp.c b/src/libosmocc/rtp.c deleted file mode 100644 index 84f15a7..0000000 --- a/src/libosmocc/rtp.c +++ /dev/null @@ -1,508 +0,0 @@ -/* Osmo-CC: RTP handling - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <arpa/inet.h> -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "endpoint.h" - -#define RTP_VERSION 2 - -void osmo_cc_set_rtp_ports(osmo_cc_session_config_t *conf, uint16_t from, uint16_t to) -{ - conf->rtp_port_next = from; - conf->rtp_port_from = from; - conf->rtp_port_to = to; -} - -struct rtp_hdr { - uint8_t byte0; - uint8_t byte1; - uint16_t sequence; - uint32_t timestamp; - uint32_t ssrc; -} __attribute__((packed)); - -struct rtp_x_hdr { - uint16_t by_profile; - uint16_t length; -} __attribute__((packed)); - -static int rtp_receive(struct sockaddr_storage *sa, socklen_t *slen, int sock, uint8_t **payload_p, int *payload_len_p, uint8_t *marker_p, uint8_t *pt_p, uint16_t *sequence_p, uint32_t *timestamp_p, uint32_t *ssrc_p) -{ - static uint8_t data[2048]; - int len; - struct rtp_hdr *rtph = (struct rtp_hdr *)data; - uint8_t version, padding, extension, csrc_count, marker, payload_type; - struct rtp_x_hdr *rtpxh; - uint8_t *payload; - int payload_len; - int x_len; - - len = recvfrom(sock, data, sizeof(data), 0, (struct sockaddr *)sa, slen); - if (len < 0) { - if (errno == EAGAIN) - return -EAGAIN; - LOGP(DCC, LOGL_DEBUG, "Read errno = %d (%s)\n", errno, strerror(errno)); - return -EIO; - } - if (len < 12) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame too short (len = %d).\n", len); - return -EINVAL; - } - - version = rtph->byte0 >> 6; - padding = (rtph->byte0 >> 5) & 1; - extension = (rtph->byte0 >> 4) & 1; - csrc_count = rtph->byte0 & 0x0f; - marker = rtph->byte1 >> 7; - payload_type = rtph->byte1 & 0x7f; - *sequence_p = ntohs(rtph->sequence); - *timestamp_p = ntohl(rtph->timestamp); - *ssrc_p = ntohl(rtph->ssrc); - - if (version != RTP_VERSION) { - LOGP(DCC, LOGL_NOTICE, "Received RTP version %d not supported.\n", version); - return -EINVAL; - } - - payload = data + sizeof(*rtph) + (csrc_count << 2); - payload_len = len - sizeof(*rtph) - (csrc_count << 2); - if (payload_len < 0) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame too short (len = %d, csrc count = %d).\n", len, csrc_count); - return -EINVAL; - } - - if (extension) { - if (payload_len < (int)sizeof(*rtpxh)) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame too short for extension header.\n"); - return -EINVAL; - } - rtpxh = (struct rtp_x_hdr *)payload; - x_len = ntohs(rtpxh->length) * 4 + sizeof(*rtpxh); - payload += x_len; - payload_len -= x_len; - if (payload_len < (int)sizeof(*rtpxh)) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame too short, extension header exceeds frame length.\n"); - return -EINVAL; - } - } - - if (padding) { - if (payload_len < 1) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame too short for padding length.\n"); - return -EINVAL; - } - payload_len -= payload[payload_len - 1]; - if (payload_len < 0) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame padding is greater than payload.\n"); - return -EINVAL; - } - } - - *payload_p = payload; - *payload_len_p = payload_len; - *marker_p = marker; - *pt_p = payload_type; - - return 0; -} - -static int rtcp_receive(struct sockaddr_storage *sa, socklen_t *slen, int sock) -{ - static uint8_t data[2048]; - int len; - - len = recvfrom(sock, data, sizeof(data), 0, (struct sockaddr *)sa, slen); - if (len < 0) { - if (errno == EAGAIN) - return -EAGAIN; - LOGP(DCC, LOGL_DEBUG, "Read errno = %d (%s)\n", errno, strerror(errno)); - return -EIO; - } - - return 0; -} - -static void rtp_send(struct sockaddr_storage *sa, socklen_t slen, int sock, uint8_t *payload, int payload_len, uint8_t marker, uint8_t pt, uint16_t sequence, uint32_t timestamp, uint32_t ssrc) -{ - struct rtp_hdr *rtph; - char data[sizeof(*rtph) + payload_len]; - int len, rc; - - rtph = (struct rtp_hdr *)data; - len = sizeof(*rtph); - rtph->byte0 = RTP_VERSION << 6; - rtph->byte1 = pt | (marker << 7); - rtph->sequence = htons(sequence); - rtph->timestamp = htonl(timestamp); - rtph->ssrc = htonl(ssrc); - len += payload_len; - if (len > (int)sizeof(data)) { - LOGP(DCC, LOGL_NOTICE, "Buffer overflow, please fix!.\n"); - abort(); - } - memcpy(data + sizeof(*rtph), payload, payload_len); - - rc = sendto(sock, data, len, 0, (struct sockaddr *)sa, slen); - if (rc < 0) - LOGP(DCC, LOGL_DEBUG, "sendto errno = %d (%s)\n", errno, strerror(errno)); -} - -static int rtp_listen_cb(struct osmo_fd *ofd, unsigned int when); -static int rtcp_listen_cb(struct osmo_fd *ofd, unsigned int when); - -/* open and bind RTP - * set local port to what we bound - */ -int osmo_cc_rtp_open(osmo_cc_session_media_t *media) -{ - osmo_cc_session_config_t *conf = media->session->config; - int domain = 0; // make GCC happy - uint16_t start_port; - struct sockaddr_storage sa; - socklen_t slen = 0; // make GCC happy - struct sockaddr_in6 *sa6; - struct sockaddr_in *sa4; - uint16_t *sport; - int flags; - int rc; - - media->tx_ssrc = rand(); - - osmo_cc_rtp_close(media); - - switch (media->connection_data_local.addrtype) { - case osmo_cc_session_addrtype_ipv4: - domain = AF_INET; - memset(&sa, 0, sizeof(sa)); - sa4 = (struct sockaddr_in *)&sa; - sa4->sin_family = domain; - rc = inet_pton(AF_INET, media->connection_data_local.address, &sa4->sin_addr); - if (rc < 1) { -pton_error: - LOGP(DCC, LOGL_NOTICE, "Cannot bind to address '%s'.\n", media->connection_data_local.address); - return -EINVAL; - } - sport = &sa4->sin_port; - slen = sizeof(*sa4); - break; - case osmo_cc_session_addrtype_ipv6: - domain = AF_INET6; - memset(&sa, 0, sizeof(sa)); - sa6 = (struct sockaddr_in6 *)&sa; - sa6->sin6_family = domain; - rc = inet_pton(AF_INET6, media->connection_data_local.address, &sa6->sin6_addr); - if (rc < 1) - goto pton_error; - sport = &sa6->sin6_port; - slen = sizeof(*sa6); - break; - case osmo_cc_session_addrtype_unknown: - LOGP(DCC, LOGL_NOTICE, "Unsupported address type '%s'.\n", media->connection_data_local.addrtype_name); - return -EINVAL; - } - - /* rtp_port_from/rtp_port_to may be changed at run time, so rtp_port_next can become out of range. */ - if (conf->rtp_port_next < conf->rtp_port_from || conf->rtp_port_next > conf->rtp_port_to) - conf->rtp_port_next = conf->rtp_port_from; - start_port = conf->rtp_port_next; - while (1) { - /* open sockets */ - rc = socket(domain, SOCK_DGRAM, IPPROTO_UDP); - if (rc < 0) { -socket_error: - LOGP(DCC, LOGL_ERROR, "Cannot create socket (domain=%d, errno=%d(%s))\n", domain, errno, strerror(errno)); - osmo_cc_rtp_close(media); - return -EIO; - } - media->rtp_ofd.fd = rc; - media->rtp_ofd.cb = rtp_listen_cb; - media->rtp_ofd.data = media; - media->rtp_ofd.when = OSMO_FD_READ; - osmo_fd_register(&media->rtp_ofd); - rc = socket(domain, SOCK_DGRAM, IPPROTO_UDP); - if (rc < 0) - goto socket_error; - media->rtcp_ofd.fd = rc; - media->rtcp_ofd.cb = rtcp_listen_cb; - media->rtcp_ofd.data = media; - media->rtcp_ofd.when = OSMO_FD_READ; - osmo_fd_register(&media->rtcp_ofd); - - /* bind sockets */ - *sport = htons(conf->rtp_port_next); - rc = bind(media->rtp_ofd.fd, (struct sockaddr *)&sa, slen); - if (rc < 0) { -bind_error: - osmo_cc_rtp_close(media); - conf->rtp_port_next = (conf->rtp_port_next + 2 > conf->rtp_port_to) ? conf->rtp_port_from : conf->rtp_port_next + 2; - if (conf->rtp_port_next == start_port) { - LOGP(DCC, LOGL_ERROR, "Cannot bind socket (errno=%d(%s))\n", errno, strerror(errno)); - return -EIO; - } - continue; - } - *sport = htons(conf->rtp_port_next + 1); - rc = bind(media->rtcp_ofd.fd, (struct sockaddr *)&sa, slen); - if (rc < 0) - goto bind_error; - media->description.port_local = conf->rtp_port_next; - conf->rtp_port_next = (conf->rtp_port_next + 2 > conf->rtp_port_to) ? conf->rtp_port_from : conf->rtp_port_next + 2; - /* set nonblocking io, to prevent write to block */ - flags = fcntl(media->rtp_ofd.fd, F_GETFL); - flags |= O_NONBLOCK; - fcntl(media->rtp_ofd.fd, F_SETFL, flags); - flags = fcntl(media->rtcp_ofd.fd, F_GETFL); - flags |= O_NONBLOCK; - fcntl(media->rtcp_ofd.fd, F_SETFL, flags); - break; - } - - LOGP(DCC, LOGL_DEBUG, "Opening media port %d\n", media->description.port_local); - - return 0; -} - -/* connect RTP - * use remote port to connect to - */ -int osmo_cc_rtp_connect(osmo_cc_session_media_t *media) -{ - struct sockaddr_in6 *sa6; - struct sockaddr_in *sa4; - int rc; - - LOGP(DCC, LOGL_DEBUG, "Connecting media port %d->%d (remote %s)\n", media->description.port_local, media->description.port_remote, media->connection_data_remote.address); - - switch (media->connection_data_remote.addrtype) { - case osmo_cc_session_addrtype_ipv4: - memset(&media->rtp_sa, 0, sizeof(media->rtp_sa)); - sa4 = (struct sockaddr_in *)&media->rtp_sa; - sa4->sin_family = AF_INET; - rc = inet_pton(AF_INET, media->connection_data_remote.address, &sa4->sin_addr); - if (rc < 1) { -pton_error: - LOGP(DCC, LOGL_NOTICE, "Cannot connect to address '%s'.\n", media->connection_data_remote.address); - return -EINVAL; - } - media->rtp_sport = &sa4->sin_port; - media->rtp_slen = sizeof(*sa4); - memcpy(&media->rtcp_sa, &media->rtp_sa, sizeof(*sa4)); - sa4 = (struct sockaddr_in *)&media->rtcp_sa; - media->rtcp_sport = &sa4->sin_port; - media->rtcp_slen = sizeof(*sa4); - break; - case osmo_cc_session_addrtype_ipv6: - memset(&media->rtp_sa, 0, sizeof(media->rtp_sa)); - sa6 = (struct sockaddr_in6 *)&media->rtp_sa; - sa6->sin6_family = AF_INET6; - rc = inet_pton(AF_INET6, media->connection_data_remote.address, &sa6->sin6_addr); - if (rc < 1) - goto pton_error; - media->rtp_sport = &sa6->sin6_port; - media->rtp_slen = sizeof(*sa6); - memcpy(&media->rtcp_sa, &media->rtp_sa, sizeof(*sa6)); - sa6 = (struct sockaddr_in6 *)&media->rtcp_sa; - media->rtcp_sport = &sa6->sin6_port; - media->rtcp_slen = sizeof(*sa6); - break; - case osmo_cc_session_addrtype_unknown: - LOGP(DCC, LOGL_NOTICE, "Unsupported address type '%s'.\n", media->connection_data_local.addrtype_name); - return -EINVAL; - } - - *media->rtp_sport = htons(media->description.port_remote); - *media->rtcp_sport = htons(media->description.port_remote + 1); - - return 0; -} - -/* send rtp data with given codec */ -void osmo_cc_rtp_send(osmo_cc_session_codec_t *codec, uint8_t *data, int len, uint8_t marker, int inc_sequence, int inc_timestamp, void *priv) -{ - uint8_t *payload = NULL; - int payload_len = 0; - - if (!codec || !codec->media->rtp_ofd.fd) - return; - - if (codec->encoder) - codec->encoder(data, len, &payload, &payload_len, priv); - else { - payload = data; - payload_len = len; - } - - rtp_send(&codec->media->rtp_sa, codec->media->rtp_slen, codec->media->rtp_ofd.fd, payload, payload_len, marker, codec->payload_type_remote, codec->media->tx_sequence, codec->media->tx_timestamp, codec->media->tx_ssrc); - codec->media->tx_sequence += inc_sequence; - codec->media->tx_timestamp += inc_timestamp; - - if (codec->encoder) - free(payload); -} - -/* dito, but with absolute sequence and timestamp */ -void osmo_cc_rtp_send_ts(osmo_cc_session_codec_t *codec, uint8_t *data, int len, uint8_t marker, uint16_t tx_sequence, uint32_t tx_timestamp, void *priv) -{ - uint8_t *payload = NULL; - int payload_len = 0; - - if (!codec || !codec->media->rtp_ofd.fd) - return; - - if (codec->encoder) - codec->encoder(data, len, &payload, &payload_len, priv); - else { - payload = data; - payload_len = len; - } - - rtp_send(&codec->media->rtp_sa, codec->media->rtp_slen, codec->media->rtp_ofd.fd, payload, payload_len, marker, codec->payload_type_remote, tx_sequence, tx_timestamp, codec->media->tx_ssrc); - codec->media->tx_sequence = tx_sequence; - codec->media->tx_timestamp = tx_timestamp; - - if (codec->encoder) - free(payload); -} - -static void check_port_translation(struct sockaddr_storage *sa, struct sockaddr_storage *media_sa, const char *what) -{ - struct sockaddr_in6 *sa6, *sa6_2; - struct sockaddr_in *sa4, *sa4_2; - int from = 0, to = 0; - - if (sa->ss_family != media_sa->ss_family) - return; - - switch (sa->ss_family) { - case AF_INET: - sa4 = (struct sockaddr_in *)sa; - sa4_2 = (struct sockaddr_in *)media_sa; - if (sa4->sin_port != sa4_2->sin_port) { - if (!!memcmp(&sa4->sin_addr, &sa4_2->sin_addr, sizeof(struct in_addr))) - break; - from = ntohs(sa4_2->sin_port); - to = ntohs(sa4->sin_port); - sa4_2->sin_port = sa4->sin_port; - } - break; - case AF_INET6: - sa6 = (struct sockaddr_in6 *)sa; - sa6_2 = (struct sockaddr_in6 *)media_sa; - if (sa6->sin6_port != sa6_2->sin6_port) { - if (!!memcmp(&sa6->sin6_addr, &sa6_2->sin6_addr, sizeof(struct in6_addr))) - break; - from = ntohs(sa6_2->sin6_port); - to = ntohs(sa6->sin6_port); - sa6_2->sin6_port = sa6->sin6_port; - } - break; - } - - if (from) - LOGP(DCC, LOGL_NOTICE, "Remote sends with different %s port, changing from %d to %d!\n", what, from, to); -} - -static int rtp_listen_cb(struct osmo_fd *ofd, unsigned int when) -{ - osmo_cc_session_media_t *media = ofd->data; - int rc; - uint8_t *payload = NULL; - int payload_len = 0; - uint8_t marker; - uint8_t payload_type; - osmo_cc_session_codec_t *codec; - uint8_t *data; - int len; - struct sockaddr_storage sa; - socklen_t slen = sizeof(sa); // must be initialized and will be overwritten - - if (when & OSMO_FD_READ) { - rc = rtp_receive(&sa, &slen, media->rtp_ofd.fd, &payload, &payload_len, &marker, &payload_type, &media->rx_sequence, &media->rx_timestamp, &media->rx_ssrc); - if (rc < 0) - return rc; - check_port_translation(&sa, &media->rtp_sa, "RTP"); - - /* search for codec */ - for (codec = media->codec_list; codec; codec = codec->next) { - if (codec->payload_type_local == payload_type) - break; - } - if (!codec) { - LOGP(DCC, LOGL_NOTICE, "Received RTP frame for unknown codec (payload_type = %d).\n", payload_type); - return 0; - } - - if (codec->decoder) - codec->decoder(payload, payload_len, &data, &len, media->session->priv); - else { - data = payload; - len = payload_len; - } - - if (codec->media->receive) - codec->media->receiver(codec, marker, media->rx_sequence, media->rx_timestamp, media->rx_ssrc, data, len); - - if (codec->decoder) - free(data); - } - - return 0; -} - -static int rtcp_listen_cb(struct osmo_fd *ofd, unsigned int when) -{ - osmo_cc_session_media_t *media = ofd->data; - int rc; - struct sockaddr_storage sa; - socklen_t slen = sizeof(sa); // must be initialized and will be overwritten - - if (when & OSMO_FD_READ) { - rc = rtcp_receive(&sa, &slen, media->rtcp_ofd.fd); - if (rc < 0) - return rc; - check_port_translation(&sa, &media->rtcp_sa, "RTCP"); - } - - return 0; -} - -void osmo_cc_rtp_close(osmo_cc_session_media_t *media) -{ - if (media->rtp_ofd.fd) { - osmo_fd_unregister(&media->rtp_ofd); - close(media->rtp_ofd.fd); - media->rtp_ofd.fd = 0; - } - if (media->rtcp_ofd.fd) { - osmo_fd_unregister(&media->rtcp_ofd); - close(media->rtcp_ofd.fd); - media->rtcp_ofd.fd = 0; - } -} - diff --git a/src/libosmocc/rtp.h b/src/libosmocc/rtp.h deleted file mode 100644 index 854c253..0000000 --- a/src/libosmocc/rtp.h +++ /dev/null @@ -1,8 +0,0 @@ - -void osmo_cc_set_rtp_ports(osmo_cc_session_config_t *conf, uint16_t from, uint16_t to); -int osmo_cc_rtp_open(osmo_cc_session_media_t *media); -int osmo_cc_rtp_connect(osmo_cc_session_media_t *media); -void osmo_cc_rtp_send(osmo_cc_session_codec_t *codec, uint8_t *data, int len, uint8_t marker, int inc_sequence, int inc_timestamp, void *priv); -void osmo_cc_rtp_send_ts(osmo_cc_session_codec_t *codec, uint8_t *data, int len, uint8_t marker, uint16_t tx_sequence, uint32_t tx_timestamp, void *priv); -void osmo_cc_rtp_close(osmo_cc_session_media_t *media); - diff --git a/src/libosmocc/screen.c b/src/libosmocc/screen.c deleted file mode 100644 index be12f08..0000000 --- a/src/libosmocc/screen.c +++ /dev/null @@ -1,694 +0,0 @@ -/* Endpoint and call process handling - * - * (C) 2019 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> -#include <arpa/inet.h> -#include <unistd.h> -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libdebug/debug.h" -#include "endpoint.h" -#include "message.h" - -#define SCREEN_QUESTIONMARK 1 -#define SCREEN_STAR 2 -#define SCREEN_AT 3 - -void osmo_cc_help_screen(void) -{ - printf("Screening options:\n\n"); - - printf("screen-calling-in [attrs] <current caller ID> [attrs] <new caller ID>\n"); - printf("screen-called-in [attrs] <current dialed number> [attrs] <new dialed number>\n"); - printf("screen-calling-out [attrs] <current caller ID> [attrs] <new caller ID>\n"); - printf("screen-called-out [attrs] <current dialed number> [attrs] <new dialed number>\n\n"); - - printf("These options allow to screen an incoming or outgoing caller ID or dialed\n"); - printf("number. If 'the current caller ID' or 'current dialed number' matches, it will\n"); - printf("be replaced by 'new caller ID' or 'new dialed number'. 'incoming' means from\n"); - printf(" the interface and 'outgoing' means towards the interface.\n\n"); - - printf("Attributes prior 'current caller ID' or 'new dialed number' may be used to\n"); - printf("perform screening only if the attribute match. Attributes prior\n"); - printf("'new caller ID' or 'new dialed number' may be used to alter them. Attribute to\n"); - printf("define the type of number can be: 'unknown', 'international', 'national',\n"); - printf("'network', 'subscriber', 'abbreviated' Attribute to define the restriction of a\n"); - printf("caller ID: 'allowed', 'restricted'\n\n"); - - printf("The current caller ID or dialed number may contain one or more '?', to allow\n"); - printf("any digit to match. The current caller ID or dialed number may contain a '*',\n"); - printf("to allow any suffix to match from now on. The new caller ID or dialed number\n"); - printf("may contain a '*', to append the suffix from the current caller ID or dialed\n"); - printf("number.\n\n"); - - printf("When screening an incoming caller ID or dialed number, the '@' can be appended\n"); - printf("to the 'new caller ID', followed by a 'host:port', to route call to a special\n"); - printf("Osmo-CC endpoint. This way it is possible to do simple routing.\n\n"); -} - -char *osmo_cc_strtok_quotes(const char **text_p) -{ - static char token[1024]; - const char *text = *text_p; - int i, quote; - - /* skip spaces */ - while (*text) { - if (*text > 32) - break; - text++; - } - - /* if eol, return NULL */ - if (!(*text)) - return NULL; - - i = 0; - quote = 0; - while (*text) { - /* escape allows all following characters */ - if (*text == '\\') { - text++; - if (*text) - token[i++] = *text++; - continue; - } - /* no quote, check for them or break on white space */ - if (quote == 0) { - if (*text == '\'') { - quote = 1; - text++; - continue; - } - if (*text == '\"') { - quote = 2; - text++; - continue; - } - if (*text <= ' ') - break; - } - /* single quote, check for unquote */ - if (quote == 1 && *text == '\'') { - quote = 0; - text++; - continue; - } - /* double quote, check for unquote */ - if (quote == 2 && *text == '\"') { - quote = 0; - text++; - continue; - } - /* copy character */ - token[i++] = *text++; - } - token[i] = '\0'; - - *text_p = text; - return token; -} - -int osmo_cc_add_screen(osmo_cc_endpoint_t *ep, const char *text) -{ - osmo_cc_screen_list_t **list_p = NULL, *list; - const char *token; - int no_present = 0, calling_in = 0, star_used, at_used; - int i, j; - - star_used = 0; - if (!strncasecmp(text, "screen-calling-in", 17)) { - text += 17; - list_p = &ep->screen_calling_in; - no_present = 1; - calling_in = 1; - } else if (!strncasecmp(text, "screen-called-in", 16)) { - text += 16; - list_p = &ep->screen_called_in; - calling_in = 1; - } else if (!strncasecmp(text, "screen-calling-out", 18)) { - text += 18; - list_p = &ep->screen_calling_out; - no_present = 1; - } else if (!strncasecmp(text, "screen-called-out", 17)) { - text += 17; - list_p = &ep->screen_called_out; - } else { - LOGP(DCC, LOGL_ERROR, "Invalid screening definition \"%s\". It must start with 'screen-calling-in' or 'screen-called-in' or 'screen-calling-out' or 'screen-called-out'\n", text); - return -EINVAL; - } - - /* skip space behind screen list string */ - while (*text) { - if (*text > 32) - break; - text++; - } - - list = calloc(1, sizeof(*list)); - if (!list) - return -ENOMEM; - -next_from: - token = osmo_cc_strtok_quotes(&text); - if (!token) { - free(list); - LOGP(DCC, LOGL_ERROR, "Missing 'from' string in screening definition \"%s\". If the string shall be empty, use double quotes. (\'\' or \"\")\n", text); - return -EINVAL; - } - if (!strcasecmp(token, "unknown")) { - list->has_from_type = 1; - list->from_type = OSMO_CC_TYPE_UNKNOWN; - goto next_from; - } else - if (!strcasecmp(token, "international")) { - list->has_from_type = 1; - list->from_type = OSMO_CC_TYPE_INTERNATIONAL; - goto next_from; - } else - if (!strcasecmp(token, "national")) { - list->has_from_type = 1; - list->from_type = OSMO_CC_TYPE_NATIONAL; - goto next_from; - } else - if (!strcasecmp(token, "network")) { - list->has_from_type = 1; - list->from_type = OSMO_CC_TYPE_NETWORK; - goto next_from; - } else - if (!strcasecmp(token, "subscriber")) { - list->has_from_type = 1; - list->from_type = OSMO_CC_TYPE_SUBSCRIBER; - goto next_from; - } else - if (!strcasecmp(token, "abbreviated")) { - list->has_from_type = 1; - list->from_type = OSMO_CC_TYPE_ABBREVIATED; - goto next_from; - } else - if (!strcasecmp(token, "allowed")) { - if (no_present) { -no_present_error: - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "Keyword '%s' not allowed in screen entry for called number\n", token); - return -EINVAL; - } - list->has_from_present = 1; - list->from_present = OSMO_CC_PRESENT_ALLOWED; - goto next_from; - } else - if (!strcasecmp(token, "restricted")) { - if (no_present) - goto no_present_error; - list->has_from_present = 1; - list->from_present = OSMO_CC_PRESENT_RESTRICTED; - goto next_from; - } else { - star_used = 0; - for (i = j = 0; token[i] && j < (int)sizeof(list->from) - 1; i++, j++) { - if (token[i] == '?') - list->from[j] = SCREEN_QUESTIONMARK; - else - if (token[i] == '*') { - if (star_used) { - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "The '*' may be used only once.\n"); - return -EINVAL; - } - list->from[j] = SCREEN_STAR; - star_used = 1; - } else - if (token[i] == '\\' && token[i + 1] != '\0') - list->from[j] = token[++i]; - else - list->from[j] = token[i]; - } - list->from[j] = '\0'; - } - -next_to: - token = osmo_cc_strtok_quotes(&text); - if (!token) { - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "Missing screening result. If the string shall be empty, use double quotes. (\'\' or \"\")\n"); - return -EINVAL; - } - if (!strcasecmp(token, "unknown")) { - list->has_to_type = 1; - list->to_type = OSMO_CC_TYPE_UNKNOWN; - goto next_to; - } else - if (!strcasecmp(token, "international")) { - list->has_to_type = 1; - list->to_type = OSMO_CC_TYPE_INTERNATIONAL; - goto next_to; - } else - if (!strcasecmp(token, "national")) { - list->has_to_type = 1; - list->to_type = OSMO_CC_TYPE_NATIONAL; - goto next_to; - } else - if (!strcasecmp(token, "network")) { - list->has_to_type = 1; - list->to_type = OSMO_CC_TYPE_NETWORK; - goto next_to; - } else - if (!strcasecmp(token, "subscriber")) { - list->has_to_type = 1; - list->to_type = OSMO_CC_TYPE_SUBSCRIBER; - goto next_to; - } else - if (!strcasecmp(token, "abbreviated")) { - list->has_to_type = 1; - list->to_type = OSMO_CC_TYPE_ABBREVIATED; - goto next_to; - } else - if (!strcasecmp(token, "allowed")) { - if (no_present) - goto no_present_error; - list->has_to_present = 1; - list->to_present = OSMO_CC_PRESENT_ALLOWED; - goto next_to; - } else - if (!strcasecmp(token, "restricted")) { - if (no_present) - goto no_present_error; - list->has_to_present = 1; - list->to_present = OSMO_CC_PRESENT_RESTRICTED; - goto next_to; - } else { - at_used = star_used = 0; - for (i = j = 0; token[i] && j < (int)sizeof(list->to) - 1; i++, j++) { - if (token[i] == '*') { - if (star_used) { - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "The '*' may be used only once.\n"); - return -EINVAL; - } - list->to[j] = SCREEN_STAR; - star_used = 1; - } else - if (token[i] == '@') { - if (!calling_in) { - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "The '@' may be used only for incoming calls from interface.\n"); - return -EINVAL; - } - if (at_used) { - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "The '@' may be used only once.\n"); - return -EINVAL; - } - list->to[j] = SCREEN_AT; - at_used = 1; - } else - if (token[i] == '\\' && token[i + 1] != '\0') - list->to[j] = token[++i]; - else - list->to[j] = token[i]; - } - list->to[j] = '\0'; - } - - token = osmo_cc_strtok_quotes(&text); - if (token) { - free(list); - LOGP(DCC, LOGL_ERROR, "Error in screening definition '%s'.\n", text); - LOGP(DCC, LOGL_ERROR, "Got garbage behind screening result.\n"); - return -EINVAL; - } - - /* attach screen entry to list */ - while (*list_p) - list_p = &((*list_p)->next); - *list_p = list; - - return 0; -} - -void osmo_cc_flush_screen(osmo_cc_screen_list_t *list) -{ - osmo_cc_screen_list_t *temp; - - while (list) { - temp = list; - list = list->next; - free(temp); - } -} - -const char *print_rule_string(const char *input) -{ - static char output[256]; - int i; - - for (i = 0; *input && i < (int)sizeof(output) - 1; i++, input++) { - switch (*input) { - case SCREEN_QUESTIONMARK: - output[i] = '?'; - break; - case SCREEN_STAR: - output[i] = '*'; - break; - case SCREEN_AT: - output[i] = '@'; - break; - default: - output[i] = *input; - } - } - - output[i] = '\0'; - return output; -} - -static int osmo_cc_screen(const char *what, osmo_cc_screen_list_t *list, uint8_t *type, uint8_t *present, char *id_to, int id_to_size, const char *id_from, const char **routing_p) -{ - const char *suffix; - int i, j, rule; - - LOGP(DCC, LOGL_INFO, "Screening %s '%s':\n", what, id_from); - switch (*type) { - case OSMO_CC_TYPE_UNKNOWN: - LOGP(DCC, LOGL_INFO, " -> type = unknown\n"); - break; - case OSMO_CC_TYPE_INTERNATIONAL: - LOGP(DCC, LOGL_INFO, " -> type = international\n"); - break; - case OSMO_CC_TYPE_NATIONAL: - LOGP(DCC, LOGL_INFO, " -> type = national\n"); - break; - case OSMO_CC_TYPE_NETWORK: - LOGP(DCC, LOGL_INFO, " -> type = network\n"); - break; - case OSMO_CC_TYPE_SUBSCRIBER: - LOGP(DCC, LOGL_INFO, " -> type = subscriber\n"); - break; - case OSMO_CC_TYPE_ABBREVIATED: - LOGP(DCC, LOGL_INFO, " -> type = abbreviated\n"); - break; - } - if (present) switch (*present) { - case OSMO_CC_PRESENT_ALLOWED: - LOGP(DCC, LOGL_INFO, " -> present = allowed\n"); - break; - case OSMO_CC_PRESENT_RESTRICTED: - LOGP(DCC, LOGL_INFO, " -> present = restricted\n"); - break; - } - - rule = 0; - while (list) { - rule++; - LOGP(DCC, LOGL_INFO, "Comparing with rule #%d: '%s':\n", rule, print_rule_string(list->from)); - if (list->has_from_type) switch (list->from_type) { - case OSMO_CC_TYPE_UNKNOWN: - LOGP(DCC, LOGL_INFO, " -> type = unknown\n"); - break; - case OSMO_CC_TYPE_INTERNATIONAL: - LOGP(DCC, LOGL_INFO, " -> type = international\n"); - break; - case OSMO_CC_TYPE_NATIONAL: - LOGP(DCC, LOGL_INFO, " -> type = national\n"); - break; - case OSMO_CC_TYPE_NETWORK: - LOGP(DCC, LOGL_INFO, " -> type = network\n"); - break; - case OSMO_CC_TYPE_SUBSCRIBER: - LOGP(DCC, LOGL_INFO, " -> type = subscriber\n"); - break; - case OSMO_CC_TYPE_ABBREVIATED: - LOGP(DCC, LOGL_INFO, " -> type = abbreviated\n"); - break; - } - if (list->has_from_present) switch (list->from_present) { - case OSMO_CC_PRESENT_ALLOWED: - LOGP(DCC, LOGL_INFO, " -> present = allowed\n"); - break; - case OSMO_CC_PRESENT_RESTRICTED: - LOGP(DCC, LOGL_INFO, " -> present = restricted\n"); - break; - } - suffix = NULL; - /* attributes do not match */ - if (list->has_from_type && list->from_type != *type) { - LOGP(DCC, LOGL_INFO, "Rule does not match, because 'type' is different.\n"); - continue; - } - if (present && list->has_from_present && list->from_present != *present) { - LOGP(DCC, LOGL_INFO, "Rule does not match, because 'present' is different.\n"); - continue; - } - for (i = 0; list->from[i] && id_from[i]; i++) { - /* '?' means: any digit, so it machtes */ - if (list->from[i] == SCREEN_QUESTIONMARK) { - continue; - } - /* '*' means: anything may follow, so it machtes */ - if (list->from[i] == SCREEN_STAR) { - suffix = id_from + i; - break; - } - /* check if digit doesn't matches */ - if (list->from[i] != id_from[i]) - break; - } - /* if last checked digit is '*', we have a match */ - /* also if we hit EOL at id_from and next check digit is '*' */ - if (list->from[i] == SCREEN_STAR) - break; - /* if all digits have matched */ - if (list->from[i] == '\0' && id_from[i] == '\0') - break; - LOGP(DCC, LOGL_INFO, "Rule does not match, because %s is different.\n", what); - list = list->next; - } - - /* if no list entry matches */ - if (!list) - return -1; - - /* replace ID */ - if (list->has_to_type) { - *type = list->to_type; - } - if (present && list->has_to_present) { - *present = list->to_present; - } - for (i = j = 0; list->to[i]; i++) { - if (j == id_to_size - 1) - break; - /* '*' means to use suffix of input string */ - if (list->to[i] == SCREEN_STAR && suffix) { - while (*suffix) { - id_to[j++] = *suffix++; - if (j == id_to_size - 1) - break; - } - continue; - /* '@' means to stop and return routing also */ - } else if (list->to[i] == SCREEN_AT) { - if (routing_p) - *routing_p = &list->to[i + 1]; - break; - } - /* copy output digit */ - id_to[j++] = list->to[i]; - } - id_to[j] = '\0'; - - LOGP(DCC, LOGL_INFO, "Rule matches, changing %s to '%s'.\n", what, print_rule_string(id_to)); - if (list->has_to_type) switch (list->to_type) { - case OSMO_CC_TYPE_UNKNOWN: - LOGP(DCC, LOGL_INFO, " -> type = unknown\n"); - break; - case OSMO_CC_TYPE_INTERNATIONAL: - LOGP(DCC, LOGL_INFO, " -> type = international\n"); - break; - case OSMO_CC_TYPE_NATIONAL: - LOGP(DCC, LOGL_INFO, " -> type = national\n"); - break; - case OSMO_CC_TYPE_NETWORK: - LOGP(DCC, LOGL_INFO, " -> type = network\n"); - break; - case OSMO_CC_TYPE_SUBSCRIBER: - LOGP(DCC, LOGL_INFO, " -> type = subscriber\n"); - break; - case OSMO_CC_TYPE_ABBREVIATED: - LOGP(DCC, LOGL_INFO, " -> type = abbreviated\n"); - break; - } - if (list->has_to_present) switch (list->to_present) { - case OSMO_CC_PRESENT_ALLOWED: - LOGP(DCC, LOGL_INFO, " -> present = allowed\n"); - break; - case OSMO_CC_PRESENT_RESTRICTED: - LOGP(DCC, LOGL_INFO, " -> present = restricted\n"); - break; - } - if (routing_p && *routing_p) - LOGP(DCC, LOGL_INFO, " -> remote = %s\n", *routing_p); - - return 0; -} - -osmo_cc_msg_t *osmo_cc_screen_msg(osmo_cc_endpoint_t *ep, osmo_cc_msg_t *old_msg, int in, const char **routing_p) -{ - osmo_cc_msg_t *new_msg; - char id[256], calling[256], called[256], redir[256]; - uint8_t calling_type, calling_plan, calling_present, calling_screen; - uint8_t called_type, called_plan; - uint8_t redir_type, redir_plan, redir_present, redir_screen, redir_reason; - int calling_status = 0, called_status = 0, redir_status = 0; - int rc; - void *ie, *to_ie; - uint8_t ie_type; - uint16_t ie_length; - void *ie_value; - - if (in && ep->screen_calling_in) { - rc = osmo_cc_get_ie_calling(old_msg, 0, &calling_type, &calling_plan, &calling_present, &calling_screen, id, sizeof(id)); - if (rc >= 0) { - rc = osmo_cc_screen("incoming caller ID", ep->screen_calling_in, &calling_type, &calling_present, calling, sizeof(calling), id, routing_p); - if (rc >= 0) - calling_status = 1; - } else { - calling_type = OSMO_CC_TYPE_UNKNOWN; - calling_plan = OSMO_CC_PLAN_TELEPHONY; - calling_present = OSMO_CC_PRESENT_ALLOWED; - calling_screen = OSMO_CC_SCREEN_NETWORK; - rc = osmo_cc_screen("incoming caller ID", ep->screen_calling_in, &calling_type, &calling_present, calling, sizeof(calling), "", routing_p); - if (rc >= 0) - calling_status = 1; - } - rc = osmo_cc_get_ie_redir(old_msg, 0, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, id, sizeof(id)); - if (rc >= 0) { - rc = osmo_cc_screen("incoming redirecting number", ep->screen_calling_in, &redir_type, &redir_present, redir, sizeof(redir), id, NULL); - if (rc >= 0) - redir_status = 1; - } - } - if (in && ep->screen_called_in) { - rc = osmo_cc_get_ie_called(old_msg, 0, &called_type, &called_plan, id, sizeof(id)); - if (rc >= 0) { - rc = osmo_cc_screen("incoming dialed number", ep->screen_called_in, &called_type, NULL, called, sizeof(called), id, routing_p); - if (rc >= 0) - called_status = 1; - } else { - called_type = OSMO_CC_TYPE_UNKNOWN; - called_plan = OSMO_CC_PLAN_TELEPHONY; - rc = osmo_cc_screen("incoming dialed number", ep->screen_called_in, &called_type, NULL, called, sizeof(called), "", routing_p); - if (rc >= 0) - called_status = 1; - } - } - if (!in && ep->screen_calling_out) { - rc = osmo_cc_get_ie_calling(old_msg, 0, &calling_type, &calling_plan, &calling_present, &calling_screen, id, sizeof(id)); - if (rc >= 0) { - rc = osmo_cc_screen("outgoing caller ID", ep->screen_calling_out, &calling_type, &calling_present, calling, sizeof(calling), id, NULL); - if (rc >= 0) - calling_status = 1; - } else { - calling_type = OSMO_CC_TYPE_UNKNOWN; - calling_plan = OSMO_CC_PLAN_TELEPHONY; - calling_present = OSMO_CC_PRESENT_ALLOWED; - calling_screen = OSMO_CC_SCREEN_NETWORK; - rc = osmo_cc_screen("outgoing caller ID", ep->screen_calling_out, &calling_type, &calling_present, calling, sizeof(calling), "", NULL); - if (rc >= 0) - calling_status = 1; - } - rc = osmo_cc_get_ie_redir(old_msg, 0, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, id, sizeof(id)); - if (rc >= 0) { - rc = osmo_cc_screen("outgoing redirecting number", ep->screen_calling_out, &redir_type, &redir_present, redir, sizeof(redir), id, NULL); - if (rc >= 0) - redir_status = 1; - } - } - if (!in && ep->screen_called_out) { - rc = osmo_cc_get_ie_called(old_msg, 0, &called_type, &called_plan, id, sizeof(id)); - if (rc >= 0) { - rc = osmo_cc_screen("outgoing dialed number", ep->screen_called_out, &called_type, NULL, called, sizeof(called), id, NULL); - if (rc >= 0) - called_status = 1; - } else { - called_type = OSMO_CC_TYPE_UNKNOWN; - called_plan = OSMO_CC_PLAN_TELEPHONY; - rc = osmo_cc_screen("outgoing dialed number", ep->screen_called_out, &called_type, NULL, called, sizeof(called), "", NULL); - if (rc >= 0) - called_status = 1; - } - } - - /* nothing screened */ - if (!calling_status && !called_status && !redir_status) - return old_msg; - - new_msg = osmo_cc_new_msg(old_msg->type); - - /* copy and replace */ - ie = old_msg->data; - while ((ie_value = osmo_cc_msg_sep_ie(old_msg, &ie, &ie_type, &ie_length))) { - switch (ie_type) { - case OSMO_CC_IE_CALLING: - if (calling_status) { - osmo_cc_add_ie_calling(new_msg, calling_type, calling_plan, calling_present, calling_screen, calling); - calling_status = 0; - break; - } - goto copy; - case OSMO_CC_IE_CALLED: - if (called_status) { - osmo_cc_add_ie_called(new_msg, called_type, called_plan, called); - called_status = 0; - break; - } - goto copy; - case OSMO_CC_IE_REDIR: - if (redir_status) { - osmo_cc_add_ie_redir(new_msg, redir_type, redir_plan, redir_present, redir_screen, redir_reason, redir); - redir_status = 0; - break; - } - goto copy; - default: - copy: - to_ie = osmo_cc_add_ie(new_msg, ie_type, ie_length); - memcpy(to_ie, ie_value, ie_length); - } - } - - /* applend, if not yet in message (except redir, since it must exist) */ - if (calling_status) - osmo_cc_add_ie_calling(new_msg, calling_type, calling_plan, calling_present, calling_screen, calling); - if (called_status) - osmo_cc_add_ie_called(new_msg, called_type, called_plan, called); - - free(old_msg); - return new_msg; -} - diff --git a/src/libosmocc/screen.h b/src/libosmocc/screen.h deleted file mode 100644 index 29f4515..0000000 --- a/src/libosmocc/screen.h +++ /dev/null @@ -1,7 +0,0 @@ - -void osmo_cc_help_screen(void); -char *osmo_cc_strtok_quotes(const char **text_p); -int osmo_cc_add_screen(osmo_cc_endpoint_t *ep, const char *text); -void osmo_cc_flush_screen(osmo_cc_screen_list_t *list); -osmo_cc_msg_t *osmo_cc_screen_msg(osmo_cc_endpoint_t *ep, osmo_cc_msg_t *old_msg, int in, const char **routing_p); - diff --git a/src/libosmocc/sdp.c b/src/libosmocc/sdp.c deleted file mode 100644 index f1497e9..0000000 --- a/src/libosmocc/sdp.c +++ /dev/null @@ -1,556 +0,0 @@ -/* Session Description Protocol parsing and generator - * This shall be simple and is incomplete. - * - * (C) 2019 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdint.h> -#include <errno.h> -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "endpoint.h" -#include "sdp.h" - -#define strncat_printf(sdp, fmt, arg...) \ - { \ - snprintf(sdp + strlen(sdp), sizeof(sdp) - strlen(sdp), fmt, ## arg); \ - sdp[sizeof(sdp) - 1] = '\0'; \ - } - -/* generate SDP from session structure */ -char *osmo_cc_session_gensdp(osmo_cc_session_t *session, int accepted_only) -{ - /* calc max size of SDP: quick an dirty (close to max UDP payload size) */ - static char sdp[65000]; - const char *username, *sess_id, *sess_version, *nettype, *addrtype, *unicast_address; - const char *session_name; - int individual_connection_data = 1; /* in case there is no media, there is no connection data */ - int individual_send_receive = 1; /* in case there is no media, there is no send/receive attribute */ - struct osmo_cc_session_media *media; - struct osmo_cc_session_codec *codec; - - sdp[0] = 0; - - /* Version */ - strncat_printf(sdp, "v=0\r\n"); - - /* Origin */ - username = session->origin_local.username; - sess_id = session->origin_local.sess_id; - sess_version = session->origin_local.sess_version; - nettype = session->origin_local.nettype; - addrtype = session->origin_local.addrtype; - unicast_address = session->origin_local.unicast_address; - strncat_printf(sdp, "o=%s %s %s %s %s %s\r\n", username, sess_id, sess_version, nettype, addrtype, unicast_address); - - /* Session */ - session_name = session->name; - strncat_printf(sdp, "s=%s\r\n", session_name); - - /* Connection Data (if all media have the same data) */ - if (session->media_list) { - osmo_cc_session_for_each_media(session->media_list->next, media) { - if (accepted_only && !media->accepted) - continue; - if (session->media_list->connection_data_local.nettype != media->connection_data_local.nettype) - break; - if (session->media_list->connection_data_local.addrtype != media->connection_data_local.addrtype) - break; - if (!!strcmp(session->media_list->connection_data_local.address, media->connection_data_local.address)) - break; - } - if (!media) - individual_connection_data = 0; - } - if (!individual_connection_data) - strncat_printf(sdp, "c=%s %s %s\r\n", osmo_cc_session_nettype2string(session->media_list->connection_data_local.nettype), osmo_cc_session_addrtype2string(session->media_list->connection_data_local.addrtype), session->media_list->connection_data_local.address); - - /* timestamp */ - strncat_printf(sdp, "t=0 0\r\n"); - - /* sendonly /recvonly (if all media have the same data) */ - if (session->media_list) { - osmo_cc_session_for_each_media(session->media_list->next, media) { - if (accepted_only && !media->accepted) - continue; - if (session->media_list->send != media->send) - break; - if (session->media_list->receive != media->receive) - break; - } - if (!media) - individual_send_receive = 0; - } - if (!individual_send_receive) { - if (session->media_list->send && !session->media_list->receive) - strncat_printf(sdp, "a=sendonly\r\n"); - if (!session->media_list->send && session->media_list->receive) - strncat_printf(sdp, "a=recvonly\r\n"); - if (!session->media_list->send && !session->media_list->receive) - strncat_printf(sdp, "a=inactive\r\n"); - } - - /* media */ - osmo_cc_session_for_each_media(session->media_list, media) { - if (accepted_only && !media->accepted) - continue; - strncat_printf(sdp, "m=%s %u %s", - osmo_cc_session_media_type2string(media->description.type) ? : media->description.type_name, - media->description.port_local, - osmo_cc_session_media_proto2string(media->description.proto) ? : media->description.proto_name); - osmo_cc_session_for_each_codec(media->codec_list, codec) { - if (accepted_only && !codec->accepted) - continue; - strncat_printf(sdp, " %u", codec->payload_type_local); - } - strncat_printf(sdp, "\r\n"); - /* don't list rtpmap when session was canceled by setting port to 0 */ - if (media->description.port_local == 0) - continue; - if (individual_connection_data) - strncat_printf(sdp, "c=%s %s %s\r\n", osmo_cc_session_nettype2string(media->connection_data_local.nettype), osmo_cc_session_addrtype2string(media->connection_data_local.addrtype), media->connection_data_local.address); - osmo_cc_session_for_each_codec(media->codec_list, codec) { - if (accepted_only && !codec->accepted) - continue; - strncat_printf(sdp, "a=rtpmap:%u %s/%d", codec->payload_type_local, codec->payload_name, codec->payload_rate); - if (codec->payload_channels >= 2) - strncat_printf(sdp, "/%d", codec->payload_channels); - strncat_printf(sdp, "\r\n"); - } - if (individual_send_receive) { - if (media->send && !media->receive) - strncat_printf(sdp, "a=sendonly\r\n"); - if (!media->send && media->receive) - strncat_printf(sdp, "a=recvonly\r\n"); - if (!media->send && !media->receive) - strncat_printf(sdp, "a=inactive\r\n"); - } - } - - /* check for overflow and return */ - if (strlen(sdp) == sizeof(sdp) - 1) { - LOGP(DCC, LOGL_ERROR, "Fatal error: Allocated SDP buffer with %d bytes is too small, please fix!\n", (int)sizeof(sdp)); - return NULL; - } - return sdp; -} - -/* separate a word from string that is delimited with one or more space characters */ -static char *wordsep(char **text_p) -{ - char *text = *text_p; - static char word[256]; - int i; - - /* no text */ - if (text == NULL || *text == '\0') - return NULL; - /* skip spaces before text */ - while (*text && *text <= ' ') - text++; - /* copy content */ - i = 0; - while (*text > ' ' && i < (int)sizeof(word)) - word[i++] = *text++; - word[i] = '\0'; - /* set next */ - *text_p = text; - return word; -} - -/* - * codecs and their default values - * - * if format is -1, payload type is dynamic - * if rate is 0, rate may be any rate - */ -struct codec_defaults { - int fmt; - char *name; - uint32_t rate; - int channels; -} codec_defaults[] = { - { 0, "PCMU", 8000, 1 }, - { 3, "GSM", 8000, 1 }, - { 4, "G723", 8000, 1 }, - { 5, "DVI4", 8000, 1 }, - { 6, "DVI4", 16000, 1 }, - { 7, "LPC", 8000, 1 }, - { 8, "PCMA", 8000, 1 }, - { 9, "G722", 8000, 1 }, - { 10, "L16", 44100, 2 }, - { 11, "L16", 44100, 1 }, - { 12, "QCELP", 8000, 1 }, - { 13, "CN", 8000, 1 }, - { 14, "MPA", 90000, 1 }, - { 15, "G728", 8000, 1 }, - { 16, "DVI4", 11025, 1 }, - { 17, "DVI4", 22050, 1 }, - { 18, "G729", 8000, 1 }, - { 25, "CELB", 90000, 0 }, - { 26, "JPEG", 90000, 0 }, - { 28, "nv", 90000, 0 }, - { 31, "H261", 90000, 0 }, - { 32, "MPV", 90000, 0 }, - { 33, "MP2T", 90000, 0 }, - { 34, "H263", 90000, 0 }, - { -1, NULL, 0, 0 }, -}; - -static void complete_codec_by_fmt(uint8_t fmt, const char **name, uint32_t *rate, int *channels) -{ - int i; - - for (i = 0; codec_defaults[i].name; i++) { - if (codec_defaults[i].fmt == fmt) - break; - } - if (!codec_defaults[i].name) - return; - - free((char *)*name); - *name = strdup(codec_defaults[i].name); - *rate = codec_defaults[i].rate; - *channels = codec_defaults[i].channels; -} - -int osmo_cc_payload_type_by_attrs(uint8_t *fmt, const char *name, uint32_t *rate, int *channels) -{ - int i; - - for (i = 0; codec_defaults[i].name; i++) { - if (!strcmp(codec_defaults[i].name, name) - && (*rate == 0 || codec_defaults[i].rate == *rate) - && (*channels == 0 || codec_defaults[i].channels == *channels)) - break; - } - if (!codec_defaults[i].name) - return -EINVAL; - - *fmt = codec_defaults[i].fmt; - *rate = codec_defaults[i].rate; - *channels = codec_defaults[i].channels; - - return 0; -} - -/* parses data and codec list from SDP - * - * sdp = given SDP text - * return: SDP session description structure */ -struct osmo_cc_session *osmo_cc_session_parsesdp(osmo_cc_session_config_t *conf, void *priv, const char *_sdp) -{ - char buffer[strlen(_sdp) + 1], *sdp = buffer; - char *line, *p, *word, *next_word; - int line_no = 0; - struct osmo_cc_session_connection_data ccd, *cd; - int csend = 1, creceive = 1; /* common default */ - struct osmo_cc_session *session = NULL; - struct osmo_cc_session_media *media = NULL; - struct osmo_cc_session_codec *codec = NULL; - - /* prepare data */ - strcpy(sdp, _sdp); - memset(&ccd, 0, sizeof(ccd)); - - /* create SDP session description */ - session = osmo_cc_new_session(conf, priv, NULL, NULL, NULL, 0, 0, NULL, NULL, 0); - - /* check every line of SDP and parse its data */ - while(*sdp) { - if ((p = strchr(sdp, '\r'))) { - *p++ = '\0'; - if (*p == '\n') - p++; - line = sdp; - sdp = p; - } else if ((p = strchr(sdp, '\n'))) { - *p++ = '\0'; - line = sdp; - sdp = p; - } else { - line = sdp; - sdp = strchr(sdp, '\0'); - } - next_word = line + 2; - line_no++; - - if (line[0] == '\0') - continue; - - if (line[1] != '=') { - LOGP(DCC, LOGL_NOTICE, "SDP line %d = '%s' is garbage, expecting '=' as second character.\n", line_no, line); - continue; - } - - switch(line[0]) { - case 'v': - LOGP(DCC, LOGL_DEBUG, " -> Version: %s\n", next_word); - if (atoi(next_word) != 0) { - LOGP(DCC, LOGL_NOTICE, "SDP line %d = '%s' describes unsupported version.\n", line_no, line); - osmo_cc_free_session(session); - return NULL; - } - break; - case 'o': - LOGP(DCC, LOGL_DEBUG, " -> Originator: %s\n", next_word); - /* Originator */ - word = wordsep(&next_word); - if (!word) - break; - free((char *)session->origin_remote.username); // if already set - session->origin_remote.username = strdup(word); - word = wordsep(&next_word); - if (!word) - break; - free((char *)session->origin_remote.sess_id); // if already set - session->origin_remote.sess_id = strdup(word); - word = wordsep(&next_word); - if (!word) - break; - free((char *)session->origin_remote.sess_version); // if already set - session->origin_remote.sess_version = strdup(word); - word = wordsep(&next_word); - if (!word) - break; - free((char *)session->origin_remote.nettype); // if already set - session->origin_remote.nettype = strdup(word); - word = wordsep(&next_word); - if (!word) - break; - free((char *)session->origin_remote.addrtype); // if already set - session->origin_remote.addrtype = strdup(word); - word = wordsep(&next_word); - if (!word) - break; - free((char *)session->origin_remote.unicast_address); // if already set - session->origin_remote.unicast_address = strdup(word); - break; - case 's': - /* Session Name */ - LOGP(DCC, LOGL_DEBUG, " -> Session Name: %s\n", next_word); - free((char *)session->name); // if already set - session->name = strdup(next_word); - break; - case 'c': /* Connection Data */ - LOGP(DCC, LOGL_DEBUG, " -> Connection Data: %s\n", next_word); - if (media) - cd = &media->connection_data_remote; - else - cd = &ccd; - /* network type */ - if (!(word = wordsep(&next_word))) - break; - if (!strcmp(word, "IN")) - cd->nettype = osmo_cc_session_nettype_inet; - else { - LOGP(DCC, LOGL_NOTICE, "Unsupported network type '%s' in SDP line %d = '%s'\n", word, line_no, line); - break; - } - /* address type */ - if (!(word = wordsep(&next_word))) - break; - if (!strcmp(word, "IP4")) { - cd->addrtype = osmo_cc_session_addrtype_ipv4; - LOGP(DCC, LOGL_DEBUG, " -> Address Type = IPv4\n"); - } else - if (!strcmp(word, "IP6")) { - cd->addrtype = osmo_cc_session_addrtype_ipv6; - LOGP(DCC, LOGL_DEBUG, " -> Address Type = IPv6\n"); - } else { - LOGP(DCC, LOGL_NOTICE, "Unsupported address type '%s' in SDP line %d = '%s'\n", word, line_no, line); - break; - } - /* connection address */ - if (!(word = wordsep(&next_word))) - break; - if ((p = strchr(word, '/'))) - *p++ = '\0'; - free((char *)cd->address); // in case of multiple lines of 'c' - cd->address = strdup(word); - LOGP(DCC, LOGL_DEBUG, " -> Address = %s\n", word); - break; - case 'm': /* Media Description */ - LOGP(DCC, LOGL_DEBUG, " -> Media Description: %s\n", next_word); - /* add media description */ - media = osmo_cc_add_media(session, 0, 0, NULL, 0, 0, 0, csend, creceive, NULL, 0); - /* copy common connection data from common connection, if exists */ - cd = &media->connection_data_remote; - memcpy(cd, &ccd, sizeof(*cd)); - /* media type */ - if (!(word = wordsep(&next_word))) - break; - if (!strcmp(word, "audio")) - media->description.type = osmo_cc_session_media_type_audio; - else - if (!strcmp(word, "video")) - media->description.type = osmo_cc_session_media_type_video; - else { - media->description.type = osmo_cc_session_media_type_unknown; - media->description.type_name = strdup(word); - LOGP(DCC, LOGL_DEBUG, "Unsupported media type in SDP line %d = '%s'\n", line_no, line); - } - /* port */ - if (!(word = wordsep(&next_word))) - break; - media->description.port_remote = atoi(word); - /* proto */ - if (!(word = wordsep(&next_word))) - break; - if (!strcmp(word, "RTP/AVP")) - media->description.proto = osmo_cc_session_media_proto_rtp; - else { - media->description.proto = osmo_cc_session_media_proto_unknown; - media->description.proto_name = strdup(word); - LOGP(DCC, LOGL_NOTICE, "Unsupported protocol type in SDP line %d = '%s'\n", line_no, line); - break; - } - /* create codec description for each codec and link */ - while ((word = wordsep(&next_word))) { - /* create codec */ - codec = osmo_cc_add_codec(media, NULL, 0, 1, NULL, NULL, 0); - /* fmt */ - codec->payload_type_remote = atoi(word); - complete_codec_by_fmt(codec->payload_type_remote, &codec->payload_name, &codec->payload_rate, &codec->payload_channels); - LOGP(DCC, LOGL_DEBUG, " -> payload type = %d\n", codec->payload_type_remote); - if (codec->payload_name) - LOGP(DCC, LOGL_DEBUG, " -> payload name = %s\n", codec->payload_name); - if (codec->payload_rate) - LOGP(DCC, LOGL_DEBUG, " -> payload rate = %d\n", codec->payload_rate); - if (codec->payload_channels) - LOGP(DCC, LOGL_DEBUG, " -> payload channels = %d\n", codec->payload_channels); - } - break; - case 'a': - LOGP(DCC, LOGL_DEBUG, " -> Attribute: %s\n", next_word); - word = wordsep(&next_word); - if (!strcmp(word, "sendrecv")) { - if (media) { - media->receive = 1; - media->send = 1; - } else { - creceive = 1; - csend = 1; - } - break; - } else - if (!strcmp(word, "recvonly")) { - if (media) { - media->receive = 1; - media->send = 0; - } else { - creceive = 1; - csend = 0; - } - break; - } else - if (!strcmp(word, "sendonly")) { - if (media) { - media->receive = 0; - media->send = 1; - } else { - creceive = 0; - csend = 1; - } - break; - } else - if (!strcmp(word, "inactive")) { - if (media) { - media->receive = 0; - media->send = 0; - } else { - creceive = 0; - csend = 0; - } - break; - } else - if (!media) { - LOGP(DCC, LOGL_NOTICE, "Attribute without previously defined media in SDP line %d = '%s'\n", line_no, line); - break; - } - if (!strncmp(word, "rtpmap:", 7)) { - int fmt = atoi(word + 7); - osmo_cc_session_for_each_codec(media->codec_list, codec) { - if (codec->payload_type_remote == fmt) - break; - } - if (!codec) { - LOGP(DCC, LOGL_NOTICE, "Attribute without previously defined codec in SDP line %d = '%s'\n", line_no, line); - break; - } - LOGP(DCC, LOGL_DEBUG, " -> (rtpmap) payload type = %d\n", codec->payload_type_remote); - if (!(word = wordsep(&next_word))) - goto rtpmap_done; - if ((p = strchr(word, '/'))) - *p++ = '\0'; - free((char *)codec->payload_name); // in case it is already set above - codec->payload_name = strdup(word); - LOGP(DCC, LOGL_DEBUG, " -> (rtpmap) payload name = %s\n", codec->payload_name); - if (!(word = p)) - goto rtpmap_done; - if ((p = strchr(word, '/'))) - *p++ = '\0'; - codec->payload_rate = atoi(word); - LOGP(DCC, LOGL_DEBUG, " -> (rtpmap) payload rate = %d\n", codec->payload_rate); - if (!(word = p)) { - /* if no channel is given and no default was specified, we must set 1 channel */ - if (!codec->payload_channels) - codec->payload_channels = 1; - goto rtpmap_done; - } - codec->payload_channels = atoi(word); - LOGP(DCC, LOGL_DEBUG, " -> (rtpmap) payload channels = %d\n", codec->payload_channels); - rtpmap_done: - if (!codec->payload_name || !codec->payload_rate || !codec->payload_channels) { - LOGP(DCC, LOGL_NOTICE, "Broken 'rtpmap' definition in SDP line %d = '%s' Skipping codec!\n", line_no, line); - osmo_cc_free_codec(codec); - } - } - break; - } - } - - /* if something is incomplete, abort here */ - if (osmo_cc_session_check(session, 1)) { - LOGP(DCC, LOGL_NOTICE, "Parsing SDP failed.\n"); - osmo_cc_free_session(session); - return NULL; - } - - return session; -} - -void osmo_cc_debug_sdp(const char *_sdp) -{ - const unsigned char *sdp = (const unsigned char *)_sdp; - char text[256]; - int i; - - while (*sdp) { - for (i = 0; *sdp > 0 && *sdp >= 32 && i < (int)sizeof(text) - 1; i++) - text[i] = *sdp++; - text[i] = '\0'; - LOGP(DCC, LOGL_DEBUG, " | %s\n", text); - while (*sdp > 0 && *sdp < 32) - sdp++; - } -} - diff --git a/src/libosmocc/sdp.h b/src/libosmocc/sdp.h deleted file mode 100644 index 540af08..0000000 --- a/src/libosmocc/sdp.h +++ /dev/null @@ -1,6 +0,0 @@ - -char *osmo_cc_session_gensdp(struct osmo_cc_session *session, int accepted_only); -struct osmo_cc_session *osmo_cc_session_parsesdp(osmo_cc_session_config_t *conf, void *priv, const char *_sdp); -int osmo_cc_payload_type_by_attrs(uint8_t *fmt, const char *name, uint32_t *rate, int *channels); -void osmo_cc_debug_sdp(const char *sdp); - diff --git a/src/libosmocc/session.c b/src/libosmocc/session.c deleted file mode 100644 index 911fbb2..0000000 --- a/src/libosmocc/session.c +++ /dev/null @@ -1,606 +0,0 @@ -/* Osmo-CC: Media Session handling - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <string.h> -#include <stdint.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/time.h> -#include <inttypes.h> -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libdebug/debug.h" -#include "../liboptions/options.h" -#include "endpoint.h" - -#define NTP_OFFSET 2208988800U - -void osmo_cc_set_local_peer(osmo_cc_session_config_t *conf, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *address) -{ - conf->default_nettype = nettype; - conf->default_addrtype = addrtype; - conf->default_unicast_address = options_strdup(address); -} - -osmo_cc_session_t *osmo_cc_new_session(osmo_cc_session_config_t *conf, void *priv, const char *username, const char *sess_id, const char *sess_version, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *unicast_address, const char *session_name, int debug) -{ - osmo_cc_session_t *session; - - if (debug) LOGP(DCC, LOGL_DEBUG, "Creating session structure.\n"); - - session = calloc(1, sizeof(*session)); - if (!session) { - LOGP(DCC, LOGL_ERROR, "No mem!\n"); - abort(); - } - session->config = conf; - session->priv = priv; - if (username) { - int i; - for (i = 0; username[i]; i++) { - if ((uint8_t)username[i] < 33) { - LOGP(DCC, LOGL_ERROR, "Fatal error: SDP's originator (username) uses invalid characters, please fix!\n"); - abort(); - } - } - session->origin_local.username = strdup(username); - } - if (!username) - session->origin_local.username = strdup("-"); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> user name = %s\n", session->origin_local.username); - if (sess_id) - session->origin_local.sess_id = strdup(sess_id); - if (sess_version) - session->origin_local.sess_version = strdup(sess_version); - if (!sess_id || !sess_version) { - struct timeval tv; - char ntp_timestamp[32]; - /* get time NTP format time stamp (time since 1900) */ - gettimeofday(&tv, NULL); - sprintf(ntp_timestamp, "%" PRIu64, (uint64_t)tv.tv_sec + NTP_OFFSET); - if (!sess_id) - session->origin_local.sess_id = strdup(ntp_timestamp); - if (!sess_version) - session->origin_local.sess_version = strdup(ntp_timestamp); - } - if (debug) LOGP(DCC, LOGL_DEBUG, " -> session ID = %s\n", session->origin_local.sess_id); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> session version = %s\n", session->origin_local.sess_version); - if (nettype) - session->origin_local.nettype = strdup(osmo_cc_session_nettype2string(nettype)); - else - session->origin_local.nettype = strdup(osmo_cc_session_nettype2string(conf->default_nettype)); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> network type = %s\n", session->origin_local.nettype); - if (addrtype) - session->origin_local.addrtype = strdup(osmo_cc_session_addrtype2string(addrtype)); - else - session->origin_local.addrtype = strdup(osmo_cc_session_addrtype2string(conf->default_addrtype)); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> address type = %s\n", session->origin_local.addrtype); - if (unicast_address) - session->origin_local.unicast_address = strdup(unicast_address); - else - session->origin_local.unicast_address = strdup(conf->default_unicast_address); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> unicast address = %s\n", session->origin_local.unicast_address); - if (session_name) - session->name = strdup(session_name); - if (!session_name) - session->name = strdup("-"); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> session name = %s\n", session->name); - - return session; -} - -void osmo_cc_free_session(osmo_cc_session_t *session) -{ - LOGP(DCC, LOGL_DEBUG, "Free session structure.\n"); - - free((char *)session->origin_local.username); - free((char *)session->origin_local.sess_id); - free((char *)session->origin_local.sess_version); - free((char *)session->origin_local.nettype); - free((char *)session->origin_local.addrtype); - free((char *)session->origin_local.unicast_address); - free((char *)session->origin_remote.username); - free((char *)session->origin_remote.sess_id); - free((char *)session->origin_remote.sess_version); - free((char *)session->origin_remote.nettype); - free((char *)session->origin_remote.addrtype); - free((char *)session->origin_remote.unicast_address); - free((char *)session->name); - while (session->media_list) - osmo_cc_free_media(session->media_list); - free(session); -} - -osmo_cc_session_media_t *osmo_cc_add_media(osmo_cc_session_t *session, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *address, enum osmo_cc_session_media_type type, uint16_t port, enum osmo_cc_session_media_proto proto, int send, int receive, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), int debug) -{ - osmo_cc_session_config_t *conf = session->config; - osmo_cc_session_media_t *media, **mediap; - - media = calloc(1, sizeof(*media)); - if (!media) { - LOGP(DCC, LOGL_ERROR, "No mem!\n"); - abort(); - } - media->session = session; - if (nettype) - media->connection_data_local.nettype = nettype; - else - media->connection_data_local.nettype = conf->default_nettype; - if (addrtype) - media->connection_data_local.addrtype = addrtype; - else - media->connection_data_local.addrtype = conf->default_addrtype; - if (address) - media->connection_data_local.address = strdup(address); - else - media->connection_data_local.address = strdup(conf->default_unicast_address); - media->description.type = type; - media->description.port_local = port; - media->description.proto = proto; - media->send = send; - media->receive = receive; - media->receiver = receiver; - media->tx_sequence = random(); - media->tx_timestamp = random(); - mediap = &media->session->media_list; - while (*mediap) - mediap = &((*mediap)->next); - *mediap = media; - - if (debug) LOGP(DCC, LOGL_DEBUG, "Adding session media.\n"); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> network type = %s\n", osmo_cc_session_nettype2string(media->connection_data_local.nettype)); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> address type = %s\n", osmo_cc_session_addrtype2string(media->connection_data_local.addrtype)); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> address = %s\n", media->connection_data_local.address); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> media type = %s\n", osmo_cc_session_media_type2string(media->description.type)); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> media port = %d\n", media->description.port_local); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> media proto = %s\n", osmo_cc_session_media_proto2string(media->description.proto)); - if (debug) LOGP(DCC, LOGL_DEBUG, "Opening and binding media port %d\n", media->description.port_local); - - return media; -} - -void osmo_cc_free_media(osmo_cc_session_media_t *media) -{ - osmo_cc_session_media_t **mediap; - - LOGP(DCC, LOGL_DEBUG, "Free session media.\n"); - - osmo_cc_rtp_close(media); - free((char *)media->connection_data_local.nettype_name); - free((char *)media->connection_data_local.addrtype_name); - free((char *)media->connection_data_local.address); - free((char *)media->connection_data_remote.nettype_name); - free((char *)media->connection_data_remote.addrtype_name); - free((char *)media->connection_data_remote.address); - while (media->codec_list) - osmo_cc_free_codec(media->codec_list); - mediap = &media->session->media_list; - while (*mediap != media) - mediap = &((*mediap)->next); - *mediap = media->next; - free(media); -} - -osmo_cc_session_codec_t *osmo_cc_add_codec(osmo_cc_session_media_t *media, const char *payload_name, uint32_t payload_rate, int payload_channels, void (*encoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv), void (*decoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv), int debug) -{ - osmo_cc_session_codec_t *codec, **codecp; - int rc; - - codec = calloc(1, sizeof(*codec)); - if (!codec) { - LOGP(DCC, LOGL_ERROR, "No mem!\n"); - abort(); - } - codec->media = media; - if (payload_name) { - codec->payload_name = strdup(payload_name); - codec->payload_rate = payload_rate; - codec->payload_channels = payload_channels; - rc = osmo_cc_payload_type_by_attrs(&codec->payload_type_local, payload_name, &payload_rate, &payload_channels); - if (rc < 0) { - /* hunt for next free dynamic payload type */ - uint8_t fmt = 96; - osmo_cc_session_codec_t *c; - osmo_cc_session_for_each_codec(media->codec_list, c) { - if (c->payload_type_local >= fmt) - fmt = c->payload_type_local + 1; - } - codec->payload_type_local = fmt; - } - } - codec->encoder = encoder; - codec->decoder = decoder; - codecp = &codec->media->codec_list; - while (*codecp) - codecp = &((*codecp)->next); - *codecp = codec; - - if (debug) LOGP(DCC, LOGL_DEBUG, "Adding session codec.\n"); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> payload type = %d\n", codec->payload_type_local); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> payload name = %s\n", codec->payload_name); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> payload rate = %d\n", codec->payload_rate); - if (debug) LOGP(DCC, LOGL_DEBUG, " -> payload channels = %d\n", codec->payload_channels); - - return codec; -} - -void osmo_cc_free_codec(osmo_cc_session_codec_t *codec) -{ - osmo_cc_session_codec_t **codecp; - - LOGP(DCC, LOGL_DEBUG, "Free session codec.\n"); - - free((char *)codec->payload_name); - codecp = &codec->media->codec_list; - while (*codecp != codec) - codecp = &((*codecp)->next); - *codecp = codec->next; - free(codec); -} - -int osmo_cc_session_check(osmo_cc_session_t *session, int remote) -{ - struct osmo_cc_session_origin *orig; - struct osmo_cc_session_media *media; - struct osmo_cc_session_connection_data *cd; - struct osmo_cc_session_media_description *md; - struct osmo_cc_session_codec *codec; - int i, j; - - if (remote) - orig = &session->origin_remote; - else - orig = &session->origin_local; - if (!orig->username - || !orig->sess_id - || !orig->sess_version - || !orig->nettype - || !orig->addrtype - || !orig->unicast_address) { - LOGP(DCC, LOGL_NOTICE, "Missing data in session origin\n"); - return -EINVAL; - } - if (!session->name) { - LOGP(DCC, LOGL_NOTICE, "Missing data in session origin\n"); - return -EINVAL; - } - if (!session->media_list) { - LOGP(DCC, LOGL_NOTICE, "Missing media session\n"); - return -EINVAL; - } - i = 0; - osmo_cc_session_for_each_media(session->media_list, media) { - i++; - if (remote) - cd = &media->connection_data_remote; - else - cd = &media->connection_data_local; - if (!cd->nettype && !cd->nettype_name) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d is missing connection network type\n", i); - return -EINVAL; - } - if (!cd->addrtype && !cd->addrtype_name) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d is missing connection address type\n", i); - return -EINVAL; - } - if (!cd->address) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d is missing connection address\n", i); - return -EINVAL; - } - md = &media->description; - if (!md->type && !md->type_name) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d is missing media type\n", i); - return -EINVAL; - } - if (!md->proto && !md->proto_name) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d is missing protocol\n", i); - return -EINVAL; - } - j = 0; - osmo_cc_session_for_each_codec(media->codec_list, codec) { - j++; - if (!codec->payload_name) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d, codec #%d is missing name\n", i, j); - return -EINVAL; - } - if (!codec->payload_rate) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d, codec #%d is missing rate\n", i, j); - return -EINVAL; - } - if (!codec->payload_channels) { - LOGP(DCC, LOGL_NOTICE, "Session with media #%d, codec #%d is missing channel count\n", i, j); - return -EINVAL; - } - } - } - - return 0; -} - -/* check session description and generate SDP */ -const char *osmo_cc_session_send_offer(osmo_cc_session_t *session) -{ - const char *sdp; - int rc; - - LOGP(DCC, LOGL_DEBUG, "Generating session offer and opening RTP stream.\n"); - - rc = osmo_cc_session_check(session, 0); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "Please fix!\n"); - abort(); - } - - sdp = osmo_cc_session_gensdp(session, 0); - osmo_cc_debug_sdp(sdp); - - return sdp; -} - -osmo_cc_session_t *osmo_cc_session_receive_offer(osmo_cc_session_config_t *conf, void *priv, const char *sdp) -{ - osmo_cc_session_t *session; - int rc; - - LOGP(DCC, LOGL_DEBUG, "Parsing session offer.\n"); - - osmo_cc_debug_sdp(sdp); - session = osmo_cc_session_parsesdp(conf, priv, sdp); - if (!session) - return NULL; - - rc = osmo_cc_session_check(session, 0); - if (rc < 0) { - osmo_cc_free_session(session); - return NULL; - } - - return session; -} - -void osmo_cc_session_accept_media(osmo_cc_session_media_t *media, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *address, int send, int receive, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len)) -{ - osmo_cc_session_config_t *conf = media->session->config; - - media->accepted = 1; - if (nettype) - media->connection_data_local.nettype = nettype; - else - media->connection_data_local.nettype = conf->default_nettype; - if (addrtype) - media->connection_data_local.addrtype = addrtype; - else - media->connection_data_local.addrtype = conf->default_addrtype; - free((char *)media->connection_data_local.address); - if (address) - media->connection_data_local.address = strdup(address); - else - media->connection_data_local.address = strdup(conf->default_unicast_address); - media->send = send; - media->receive = receive; - media->receiver = receiver; - - LOGP(DCC, LOGL_DEBUG, "Accepting session media.\n"); - LOGP(DCC, LOGL_DEBUG, " -> network type = %s\n", osmo_cc_session_nettype2string(media->connection_data_local.nettype)); - LOGP(DCC, LOGL_DEBUG, " -> address type = %s\n", osmo_cc_session_addrtype2string(media->connection_data_local.addrtype)); - LOGP(DCC, LOGL_DEBUG, " -> address = %s\n", media->connection_data_local.address); -} - - -void osmo_cc_session_accept_codec(osmo_cc_session_codec_t *codec, void (*encoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv), void (*decoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv)) -{ - codec->accepted = 1; - codec->encoder = encoder; - codec->decoder = decoder; - /* when we accept a codec, we just use the same payload type as the remote */ - codec->payload_type_local = codec->payload_type_remote; - - LOGP(DCC, LOGL_DEBUG, "Accepting session codec.\n"); - LOGP(DCC, LOGL_DEBUG, " -> payload type = %d\n", codec->payload_type_local); - LOGP(DCC, LOGL_DEBUG, " -> payload name = %s\n", codec->payload_name); - LOGP(DCC, LOGL_DEBUG, " -> payload rate = %d\n", codec->payload_rate); - LOGP(DCC, LOGL_DEBUG, " -> payload channels = %d\n", codec->payload_channels); -} - -const char *osmo_cc_session_send_answer(osmo_cc_session_t *session) -{ - const char *sdp; - int rc; - - LOGP(DCC, LOGL_DEBUG, "Generating session answer.\n"); - - rc = osmo_cc_session_check(session, 0); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "Please fix!\n"); - abort(); - } - - sdp = osmo_cc_session_gensdp(session, 1); - osmo_cc_debug_sdp(sdp); - - return sdp; -} - -/* Apply remote session description to local session description. - * If remote media's port is 0, remove from local session description. - * If codecs in the remote session description are missing, remove from local session description. - */ -static int osmo_cc_session_negotiate(osmo_cc_session_t *session_local, struct osmo_cc_session *session_remote) -{ - osmo_cc_session_media_t *media_local, *media_remote, **media_local_p; - osmo_cc_session_codec_t *codec_local, *codec_remote, **codec_local_p; - int rc; - - LOGP(DCC, LOGL_DEBUG, "Negotiating session.\n"); - - /* copy remote session information */ - session_local->origin_remote.username = strdup(session_remote->origin_remote.username); - session_local->origin_remote.sess_id = strdup(session_remote->origin_remote.sess_id); - session_local->origin_remote.sess_version = strdup(session_remote->origin_remote.sess_version); - session_local->origin_remote.nettype = strdup(session_remote->origin_remote.nettype); - session_local->origin_remote.addrtype = strdup(session_remote->origin_remote.addrtype); - session_local->origin_remote.unicast_address = strdup(session_remote->origin_remote.unicast_address); - - /* loop all media */ - for (media_local = session_local->media_list, media_remote = session_remote->media_list; media_local && media_remote; media_local = media_local->next, media_remote = media_remote->next) { - /* copy remote media information */ - media_local->connection_data_remote.nettype = media_remote->connection_data_remote.nettype; - if (media_remote->connection_data_remote.nettype_name) - media_local->connection_data_remote.nettype_name = strdup(media_remote->connection_data_remote.nettype_name); - media_local->connection_data_remote.addrtype = media_remote->connection_data_remote.addrtype; - if (media_remote->connection_data_remote.addrtype_name) - media_local->connection_data_remote.addrtype_name = strdup(media_remote->connection_data_remote.addrtype_name); - if (media_remote->connection_data_remote.address) - media_local->connection_data_remote.address = strdup(media_remote->connection_data_remote.address); - media_local->description.port_remote = media_remote->description.port_remote; - media_local->send = media_remote->send; - media_local->receive = media_remote->receive; - /* loop all codecs and remove if they are not found in local session description */ - codec_local_p = &media_local->codec_list; - codec_local = *codec_local_p; - while (codec_local) { - /* search for equal codec, payload type may differe for each direction */ - osmo_cc_session_for_each_codec(media_remote->codec_list, codec_remote) { - if (!strcmp(codec_local->payload_name, codec_remote->payload_name) - && codec_local->payload_rate == codec_remote->payload_rate - && codec_local->payload_channels == codec_remote->payload_channels) - break; - } - if (codec_remote) { - /* mark as accepted, copy remote codec information */ - codec_local->accepted = 1; - codec_local->payload_type_remote = codec_remote->payload_type_remote; - } else { - /* mark as not accepted, in case it was accepted in earlier response */ - codec_local->accepted = 0; - } - codec_local_p = &codec_local->next; - codec_local = *codec_local_p; - } - } - if (media_local) { - LOGP(DCC, LOGL_NOTICE, "Negotiation failed, because remote endpoint returns less media streams than we offered.\n"); - return -EINVAL; - } - if (media_remote) { - LOGP(DCC, LOGL_NOTICE, "Negotiation failed, because remote endpoint returns more media streams than we offered.\n"); - return -EINVAL; - } - - /* mark media as accepted, if there is a remote port and there is at least one codec */ - media_local_p = &session_local->media_list; - media_local = *media_local_p; - while (media_local) { - if (media_local->description.port_remote && media_local->codec_list) { - /* mark as accepted */ - media_local->accepted = 1; - } else { - /* mark as not accepted, in case it was accepted in earlier response */ - media_local->accepted = 0; - } - media_local_p = &media_local->next; - media_local = *media_local_p; - } - - rc = osmo_cc_session_check(session_local, 1); - if (rc < 0) - return rc; - - return 0; -} - -int osmo_cc_session_receive_answer(osmo_cc_session_t *session, const char *sdp) -{ - osmo_cc_session_t *session_remote; - int rc; - - LOGP(DCC, LOGL_DEBUG, "Parsing session answer.\n"); - - osmo_cc_debug_sdp(sdp); - session_remote = osmo_cc_session_parsesdp(session->config, NULL, sdp); - if (!session_remote) - return -EINVAL; - - rc = osmo_cc_session_check(session_remote, 1); - if (rc < 0) { - osmo_cc_free_session(session_remote); - return rc; - } - rc = osmo_cc_session_negotiate(session, session_remote); - if (rc < 0) { - osmo_cc_free_session(session_remote); - return rc; - } - osmo_cc_free_session(session_remote); - - return 0; -} - -const char *osmo_cc_session_nettype2string(enum osmo_cc_session_nettype nettype) -{ - switch (nettype) { - case osmo_cc_session_nettype_inet: - return "IN"; - default: - return NULL; - } -} - -const char *osmo_cc_session_addrtype2string(enum osmo_cc_session_addrtype addrtype) -{ - switch (addrtype) { - case osmo_cc_session_addrtype_ipv4: - return "IP4"; - case osmo_cc_session_addrtype_ipv6: - return "IP6"; - default: - return NULL; - } -} - -const char *osmo_cc_session_media_type2string(enum osmo_cc_session_media_type media_type) -{ - switch (media_type) { - case osmo_cc_session_media_type_audio: - return "audio"; - case osmo_cc_session_media_type_video: - return "video"; - default: - return NULL; - } -} - -const char *osmo_cc_session_media_proto2string(enum osmo_cc_session_media_proto media_proto) -{ - switch (media_proto) { - case osmo_cc_session_media_proto_rtp: - return "RTP/AVP"; - default: - return NULL; - } -} - -int osmo_cc_session_if_codec(osmo_cc_session_codec_t *codec, const char *name, uint32_t rate, int channels) -{ - return (!strcmp(codec->payload_name, name) - && codec->payload_rate == rate - && codec->payload_channels == channels); -} - diff --git a/src/libosmocc/session.h b/src/libosmocc/session.h deleted file mode 100644 index 1317f4c..0000000 --- a/src/libosmocc/session.h +++ /dev/null @@ -1,134 +0,0 @@ -#include <sys/socket.h> - -/* configuration */ - -enum osmo_cc_session_nettype { - osmo_cc_session_nettype_unknown = 0, - osmo_cc_session_nettype_inet, -}; - -enum osmo_cc_session_addrtype { - osmo_cc_session_addrtype_unknown = 0, - osmo_cc_session_addrtype_ipv4, - osmo_cc_session_addrtype_ipv6, -}; - -typedef struct osmo_cc_session_config { - enum osmo_cc_session_nettype default_nettype; - enum osmo_cc_session_addrtype default_addrtype; - const char *default_unicast_address; - uint16_t rtp_port_next; - uint16_t rtp_port_from; - uint16_t rtp_port_to; -} osmo_cc_session_config_t; - -/* session description, global part: */ - -typedef struct osmo_cc_session_origin { - const char *username; - const char *sess_id; - const char *sess_version; - const char *nettype; - const char *addrtype; - const char *unicast_address; -} osmo_cc_session_origin_t; - -/* session instance */ -typedef struct osmo_cc_session { - osmo_cc_session_config_t *config; - void *priv; - osmo_cc_session_origin_t origin_local, origin_remote; - const char *name; - struct osmo_cc_session_media *media_list; -} osmo_cc_session_t; - -/* connection description: */ - -typedef struct osmo_cc_session_connection_data { - enum osmo_cc_session_nettype nettype; - const char *nettype_name; - enum osmo_cc_session_addrtype addrtype; - const char *addrtype_name; - const char *address; -} osmo_cc_session_connection_data_t; - -/* one media of session description: */ - -enum osmo_cc_session_media_type { - osmo_cc_session_media_type_unknown, - osmo_cc_session_media_type_audio, - osmo_cc_session_media_type_video, -}; - -enum osmo_cc_session_media_proto { - osmo_cc_session_media_proto_unknown, - osmo_cc_session_media_proto_rtp, -}; - -typedef struct osmo_cc_session_media_description { - enum osmo_cc_session_media_type type; - const char *type_name; - uint16_t port_local, port_remote; - enum osmo_cc_session_media_proto proto; - const char *proto_name; -} osmo_cc_session_media_description_t; - -/* media entry */ -typedef struct osmo_cc_session_media { - struct osmo_cc_session_media *next; - osmo_cc_session_t *session; - osmo_cc_session_media_description_t description; - osmo_cc_session_connection_data_t connection_data_local, connection_data_remote; - struct osmo_cc_session_codec *codec_list; - int send, receive; - void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len); - struct sockaddr_storage rtp_sa, rtcp_sa; - socklen_t rtp_slen, rtcp_slen; - uint16_t *rtp_sport, *rtcp_sport; // pointers to the port inside sa sockaddr - struct osmo_fd rtp_ofd; - struct osmo_fd rtcp_ofd; - uint32_t tx_ssrc, rx_ssrc; - uint16_t tx_sequence, rx_sequence; - uint32_t tx_timestamp, rx_timestamp; - int accepted; -} osmo_cc_session_media_t; - -/* codec entry */ -typedef struct osmo_cc_session_codec { - struct osmo_cc_session_codec *next; - osmo_cc_session_media_t *media; - uint8_t payload_type_local, payload_type_remote; /* local = towards local, remote = toward remote */ - const char *payload_name; - uint32_t payload_rate; - int payload_channels; - void (*encoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); - void (*decoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv); - int accepted; -} osmo_cc_session_codec_t; - -#define osmo_cc_session_for_each_media(head, m) \ - for (m = (head); m; m = m->next) - -#define osmo_cc_session_for_each_codec(head, c) \ - for (c = (head); c; c = c->next) - -void osmo_cc_set_local_peer(osmo_cc_session_config_t *conf, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *address); -osmo_cc_session_t *osmo_cc_new_session(osmo_cc_session_config_t *conf, void *priv, const char *username, const char *sess_id, const char *sess_version, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *unicast_address, const char *session_name, int debug); -void osmo_cc_free_session(osmo_cc_session_t *session); -osmo_cc_session_media_t *osmo_cc_add_media(osmo_cc_session_t *session, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *address, enum osmo_cc_session_media_type type, uint16_t port, enum osmo_cc_session_media_proto proto, int send, int receive, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len), int debug); -void osmo_cc_free_media(osmo_cc_session_media_t *media); -osmo_cc_session_codec_t *osmo_cc_add_codec(osmo_cc_session_media_t *media, const char *playload_name, uint32_t playload_rate, int playload_channels, void (*encoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv), void (*decoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv), int debug); -void osmo_cc_free_codec(osmo_cc_session_codec_t *codec); -int osmo_cc_session_check(struct osmo_cc_session *session, int remote); -const char *osmo_cc_session_send_offer(osmo_cc_session_t *session); -osmo_cc_session_t *osmo_cc_session_receive_offer(osmo_cc_session_config_t *conf, void *priv, const char *sdp); -void osmo_cc_session_accept_media(osmo_cc_session_media_t *media, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *address, int send, int receive, void (*receiver)(struct osmo_cc_session_codec *codec, uint8_t marker, uint16_t sequence_number, uint32_t timestamp, uint32_t ssrc, uint8_t *data, int len)); -void osmo_cc_session_accept_codec(osmo_cc_session_codec_t *codec, void (*encoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv), void (*decoder)(uint8_t *src_data, int src_len, uint8_t **dst_data, int *dst_len, void *priv)); -const char *osmo_cc_session_send_answer(osmo_cc_session_t *session); -int osmo_cc_session_receive_answer(osmo_cc_session_t *session, const char *sdp); -const char *osmo_cc_session_nettype2string(enum osmo_cc_session_nettype nettype); -const char *osmo_cc_session_addrtype2string(enum osmo_cc_session_addrtype addrtype); -const char *osmo_cc_session_media_type2string(enum osmo_cc_session_media_type media_type); -const char *osmo_cc_session_media_proto2string(enum osmo_cc_session_media_proto media_proto); -int osmo_cc_session_if_codec(osmo_cc_session_codec_t *codec, const char *name, uint32_t rate, int channels); - diff --git a/src/libosmocc/socket.c b/src/libosmocc/socket.c deleted file mode 100644 index 9d8f30a..0000000 --- a/src/libosmocc/socket.c +++ /dev/null @@ -1,619 +0,0 @@ -/* Osmo-CC: Socket handling - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <sys/socket.h> -#include <netdb.h> -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "message.h" -#include "cause.h" -#include "socket.h" - -static const char version_string[] = OSMO_CC_VERSION; - -static int _getaddrinfo(const char *host, uint16_t port, struct addrinfo **result) -{ - char portstr[8]; - struct addrinfo hints; - int rc; - - sprintf(portstr, "%d", port); - - /* bind socket */ - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - hints.ai_protocol = 0; - hints.ai_canonname = NULL; - hints.ai_addr = NULL; - hints.ai_next = NULL; - - rc = getaddrinfo(host, portstr, &hints, result); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "Failed to create socket for host '%s', port '%d': %s.\n", host, port, gai_strerror(rc)); - return rc; - } - return rc; -} - -/* send a reject message toward CC process. - * the CC process will change the reject message to a release message when not in INIT_IN state - */ -static void rej_msg(osmo_cc_socket_t *os, uint32_t callref, uint8_t socket_cause, uint8_t isdn_cause, uint16_t sip_cause) -{ - osmo_cc_msg_t *msg; - - /* create message */ - msg = osmo_cc_new_msg(OSMO_CC_MSG_REJ_REQ); - if (!msg) - abort(); - - /* add cause */ - osmo_cc_add_ie_cause(msg, os->location, isdn_cause, sip_cause, socket_cause); - osmo_cc_convert_cause_msg(msg); - - /* message down */ - os->recv_msg_cb(os->priv, callref, msg); -} - -static void tx_keepalive_timeout(void *data) -{ - osmo_cc_conn_t *conn = data; - osmo_cc_msg_t *msg; - - /* send keepalive message */ - msg = osmo_cc_new_msg(OSMO_CC_MSG_DUMMY_REQ); - osmo_cc_msg_list_enqueue(&conn->os->write_list, msg, conn->callref); - timer_start(&conn->tx_keepalive_timer, OSMO_CC_SOCKET_TX_KEEPALIVE); -} - -static void close_conn(osmo_cc_conn_t *conn, uint8_t socket_cause); - -static void rx_keepalive_timeout(void *data) -{ - osmo_cc_conn_t *conn = data; - - LOGP(DCC, LOGL_ERROR, "OsmoCC-Socket failed due to timeout.\n"); - close_conn(conn, OSMO_CC_SOCKET_CAUSE_TIMEOUT); -} - -static int socket_listen_cb(struct osmo_fd *ofd, unsigned int when); - -/* create socket process and bind socket */ -int osmo_cc_open_socket(osmo_cc_socket_t *os, const char *host, uint16_t port, void *priv, void (*recv_msg_cb)(void *priv, uint32_t callref, osmo_cc_msg_t *msg), uint8_t location) -{ - int try = 0, auto_port = 0; - struct addrinfo *result, *rp; - int rc, sock; - - memset(os, 0, sizeof(*os)); - -try_again: - /* check for given port, if NULL, autoselect port */ - if (!port || auto_port) { - port = OSMO_CC_DEFAULT_PORT + try; - try++; - auto_port = 1; - } - - LOGP(DCC, LOGL_DEBUG, "Create socket for host %s port %d.\n", host, port); - - rc = _getaddrinfo(host, port, &result); - if (rc < 0) - return rc; - for (rp = result; rp; rp = rp->ai_next) { - int on = 1; - sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (sock < 0) - continue; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (unsigned char *)&on, sizeof(on)); - rc = bind(sock, rp->ai_addr, rp->ai_addrlen); - if (rc == 0) - break; - close(sock); - } - freeaddrinfo(result); - if (rp == NULL) { - if (auto_port && port < OSMO_CC_DEFAULT_PORT_MAX) { - LOGP(DCC, LOGL_DEBUG, "Failed to bind host %s port %d, trying again.\n", host, port); - goto try_again; - } - LOGP(DCC, LOGL_ERROR, "Failed to bind given host %s port %d.\n", host, port); - return -EIO; - } - - /* listen to socket */ - rc = listen(sock, 10); - if (rc < 0) { - LOGP(DCC, LOGL_ERROR, "Failed to listen on socket.\n"); - close(sock); - return rc; - } - - /* register */ - os->ofd.fd = sock; - os->ofd.cb = socket_listen_cb; - os->ofd.data = os; - os->ofd.when = OSMO_FD_READ; - osmo_fd_register(&os->ofd); - os->recv_msg_cb = recv_msg_cb; - os->priv = priv; - os->location = location; - - return port; -} - -static int socket_conn_cb(struct osmo_fd *ofd, unsigned int when); - -/* create a connection */ -static osmo_cc_conn_t *open_conn(osmo_cc_socket_t *os, int sock, uint32_t callref, int read_setup) -{ - osmo_cc_conn_t *conn, **connp; - - /* create connection */ - conn = calloc(1, sizeof(*conn)); - if (!conn) { - LOGP(DCC, LOGL_ERROR, "No mem!\n"); - abort(); - } - conn->os = os; - conn->ofd.fd = sock; - conn->ofd.cb = socket_conn_cb; - conn->ofd.data = conn; - conn->ofd.when = OSMO_FD_READ; - osmo_fd_register(&conn->ofd); - conn->read_version = 1; - conn->write_version = 1; - conn->read_setup = read_setup; - if (callref) - conn->callref = callref; - else - conn->callref = osmo_cc_new_callref(); - - timer_init(&conn->tx_keepalive_timer, tx_keepalive_timeout, conn); - timer_init(&conn->rx_keepalive_timer, rx_keepalive_timeout, conn); - timer_start(&conn->tx_keepalive_timer, OSMO_CC_SOCKET_TX_KEEPALIVE); - timer_start(&conn->rx_keepalive_timer, OSMO_CC_SOCKET_RX_KEEPALIVE); - - LOGP(DCC, LOGL_DEBUG, "New socket connection (callref %d).\n", conn->callref); - - /* attach to list */ - connp = &os->conn_list; - while (*connp) - connp = &((*connp)->next); - *connp = conn; - - return conn; -} - -/* remove a connection */ -static void close_conn(osmo_cc_conn_t *conn, uint8_t socket_cause) -{ - osmo_cc_conn_t **connp; - osmo_cc_msg_list_t *ml; - - /* detach connection first, to prevent a destruction during message handling (double free) */ - connp = &conn->os->conn_list; - while (*connp != conn) - connp = &((*connp)->next); - *connp = conn->next; - /* send reject message, if socket_cause is set */ - if (socket_cause && !conn->read_setup) { - /* receive a release or reject (depending on state), but only if we sent a setup */ - rej_msg(conn->os, conn->callref, socket_cause, 0, 0); - } - - LOGP(DCC, LOGL_DEBUG, "Destroy socket connection (callref %d).\n", conn->callref); - - /* close socket */ - if (conn->ofd.fd) { - osmo_fd_unregister(&conn->ofd); - close(conn->ofd.fd); - } - /* free partly received message */ - if (conn->read_msg) - osmo_cc_free_msg(conn->read_msg); - /* free send queue */ - while ((ml = conn->write_list)) { - osmo_cc_free_msg(ml->msg); - conn->write_list = ml->next; - free(ml); - } - /* free timers */ - timer_exit(&conn->tx_keepalive_timer); - timer_exit(&conn->rx_keepalive_timer); - /* free connection (already detached above) */ - free(conn); -} - -/* close socket and remove */ -void osmo_cc_close_socket(osmo_cc_socket_t *os) -{ - osmo_cc_msg_list_t *ml; - - LOGP(DCC, LOGL_DEBUG, "Destroy socket.\n"); - - /* free all connections */ - while (os->conn_list) - close_conn(os->conn_list, 0); - /* close socket */ - if (os->ofd.fd > 0) { - osmo_fd_unregister(&os->ofd); - close(os->ofd.fd); - os->ofd.fd = 0; - } - /* free send queue */ - while ((ml = os->write_list)) { - osmo_cc_free_msg(ml->msg); - os->write_list = ml->next; - free(ml); - } -} - -/* send message to send_queue of sock instance */ -int osmo_cc_sock_send_msg(osmo_cc_socket_t *os, uint32_t callref, osmo_cc_msg_t *msg, const char *host, uint16_t port) -{ - osmo_cc_msg_list_t *ml; - - /* turn _IND into _REQ and _CNF into _RSP */ - msg->type &= ~1; - - /* create list entry */ - ml = osmo_cc_msg_list_enqueue(&os->write_list, msg, callref); - if (host) - strncpy(ml->host, host, sizeof(ml->host) - 1); - ml->port = port; - - return 0; -} - -/* receive message - * return 1 if work was done. - */ -static int receive_conn(osmo_cc_conn_t *conn) -{ - uint8_t socket_cause = OSMO_CC_SOCKET_CAUSE_BROKEN_PIPE; - int rc; - osmo_cc_msg_t *msg; - uint8_t msg_type; - int len; - int work = 0; - - /* get version from remote */ - if (conn->read_version) { - rc = recv(conn->ofd.fd, conn->read_version_string + conn->read_version_pos, strlen(version_string) - conn->read_version_pos, 0); - if (rc < 0 && errno == EAGAIN) - return work; - work = 1; - if (rc <= 0) { - goto close; - } - conn->read_version_pos += rc; - if (conn->read_version_pos == strlen(version_string)) { - conn->read_version = 0; - if (!!memcmp(conn->read_version_string, version_string, strlen(version_string) - 1)) { - LOGP(DCC, LOGL_NOTICE, "Remote does not seem to be an Osmo-CC socket, rejecting!\n"); - socket_cause = OSMO_CC_SOCKET_CAUSE_FAILED; - goto close; - } - if (conn->read_version_string[strlen(version_string) - 1] != version_string[strlen(version_string) - 1]) { - LOGP(DCC, LOGL_NOTICE, "Remote Osmo-CC socket has wrong version (local=%s, remote=%s), rejecting!\n", version_string, conn->read_version_string); - socket_cause = OSMO_CC_SOCKET_CAUSE_VERSION_MISMATCH; - goto close; - } - } else - return work; - } - -try_next_message: - /* read message header from remote */ - if (!conn->read_msg) { - rc = recv(conn->ofd.fd, ((uint8_t *)&conn->read_hdr) + conn->read_pos, sizeof(conn->read_hdr) - conn->read_pos, 0); - if (rc < 0 && errno == EAGAIN) - return work; - work = 1; - if (rc <= 0) { - goto close; - } - conn->read_pos += rc; - if (conn->read_pos == sizeof(conn->read_hdr)) { - conn->read_msg = osmo_cc_new_msg(conn->read_hdr.type); - if (!conn->read_msg) - abort(); - conn->read_msg->length_networkorder = conn->read_hdr.length_networkorder; - /* prepare for reading message */ - conn->read_pos = 0; - } else - return work; - } - - /* read message data from remote */ - msg = conn->read_msg; - len = ntohs(msg->length_networkorder); - if (len == 0) - goto empty_message; - rc = recv(conn->ofd.fd, msg->data + conn->read_pos, len - conn->read_pos, 0); - if (rc < 0 && errno == EAGAIN) - return work; - work = 1; - if (rc <= 0) { - goto close; - } - conn->read_pos += rc; - if (conn->read_pos == len) { -empty_message: - /* start RX keepalive timeer, if not already */ - timer_start(&conn->rx_keepalive_timer, OSMO_CC_SOCKET_RX_KEEPALIVE); - /* we got our setup message, so we clear the flag */ - conn->read_setup = 0; - /* prepare for reading header */ - conn->read_pos = 0; - /* detach message first, because the connection might be destroyed during message handling */ - msg_type = conn->read_msg->type; - conn->read_msg = NULL; - /* drop dummy or forward message */ - if (msg_type == OSMO_CC_MSG_DUMMY_REQ) - osmo_cc_free_msg(msg); - else - conn->os->recv_msg_cb(conn->os->priv, conn->callref, msg); - if (msg_type == OSMO_CC_MSG_REL_REQ || msg_type == OSMO_CC_MSG_REJ_REQ) { - LOGP(DCC, LOGL_DEBUG, "closing socket because we received a release or reject message.\n"); - close_conn(conn, 0); - return 1; /* conn removed */ - } - goto try_next_message; - } - return work; - -close: - LOGP(DCC, LOGL_ERROR, "OsmoCC-Socket failed, socket cause %d.\n", socket_cause); - close_conn(conn, socket_cause); - return work; /* conn removed */ -} - -/* transmit message - * return 1 if work was done. - */ -static int transmit_conn(osmo_cc_conn_t *conn) -{ - uint8_t socket_cause = OSMO_CC_SOCKET_CAUSE_BROKEN_PIPE; - int rc; - osmo_cc_msg_t *msg; - int len; - osmo_cc_msg_list_t *ml; - int work = 0; - - /* send socket version to remote */ - if (conn->write_version) { - rc = write(conn->ofd.fd, version_string, strlen(version_string)); - if (rc < 0 && errno == EAGAIN) - return work; - work = 1; - if (rc <= 0) { - goto close; - } - if (rc != strlen(version_string)) { - LOGP(DCC, LOGL_ERROR, "short write, please fix handling!\n"); - abort(); - } - conn->write_version = 0; - } - - /* send message to remote */ - while (conn->write_list) { - timer_stop(&conn->tx_keepalive_timer); - msg = conn->write_list->msg; - len = sizeof(*msg) + ntohs(msg->length_networkorder); - rc = write(conn->ofd.fd, msg, len); - if (rc < 0 && errno == EAGAIN) - return work; - work = 1; - if (rc <= 0) { - goto close; - } - if (rc != len) { - LOGP(DCC, LOGL_ERROR, "short write, please fix handling!\n"); - abort(); - } - /* close socket after sending release/reject message */ - if (msg->type == OSMO_CC_MSG_REL_REQ || msg->type == OSMO_CC_MSG_REJ_REQ) { - LOGP(DCC, LOGL_DEBUG, "closing socket because we sent a release or reject message.\n"); - close_conn(conn, 0); - return work; /* conn removed */ - } - /* free message after sending */ - ml = conn->write_list; - conn->write_list = ml->next; - osmo_cc_free_msg(msg); - free(ml); - } - - /* start TX keepalive timeer, if not already - * because we stop at every message above, we actually restart the timer here. - * only if there is no message for the amount of time, the timer fires. - */ - if (!timer_running(&conn->tx_keepalive_timer)) - timer_start(&conn->tx_keepalive_timer, OSMO_CC_SOCKET_TX_KEEPALIVE); - - return work; - -close: - LOGP(DCC, LOGL_NOTICE, "OsmoCC-Socket failed.\n"); - close_conn(conn, socket_cause); - return work; /* conn removed */ -} - -/* handle all sockets of a socket interface - * return 1 if work was done. - */ -int osmo_cc_handle_socket(osmo_cc_socket_t *os) -{ - int sock; - osmo_cc_conn_t *conn; - osmo_cc_msg_list_t *ml, **mlp; - int flags; - struct addrinfo *result, *rp; - int rc; - int work = 0; - - /* handle messages in send queue */ - while ((ml = os->write_list)) { - work = 1; - /* detach list entry */ - os->write_list = ml->next; - ml->next = NULL; - /* search for socket connection */ - for (conn = os->conn_list; conn; conn=conn->next) { - if (conn->callref == ml->callref) - break; - } - if (conn) { - /* attach to list */ - mlp = &conn->write_list; - while (*mlp) - mlp = &((*mlp)->next); - *mlp = ml; - conn->ofd.when |= OSMO_FD_WRITE; - /* done with message */ - continue; - } - - /* reject and release are ignored */ - if (ml->msg->type == OSMO_CC_MSG_REJ_REQ - || ml->msg->type == OSMO_CC_MSG_REL_REQ) { - /* drop message */ - osmo_cc_free_msg(ml->msg); - free(ml); - /* done with message */ - continue; - } - - /* reject, if this is not a setup message */ - if (ml->msg->type != OSMO_CC_MSG_SETUP_REQ - && ml->msg->type != OSMO_CC_MSG_ATTACH_REQ) { - LOGP(DCC, LOGL_ERROR, "Message with unknown callref.\n"); - rej_msg(os, ml->callref, 0, OSMO_CC_ISDN_CAUSE_INVAL_CALLREF, 0); - /* drop message */ - osmo_cc_free_msg(ml->msg); - free(ml); - /* done with message */ - continue; - } - /* connect to remote */ - rc = _getaddrinfo(ml->host, ml->port, &result); - if (rc < 0) { - rej_msg(os, ml->callref, OSMO_CC_SOCKET_CAUSE_FAILED, 0, 0); - /* drop message */ - osmo_cc_free_msg(ml->msg); - free(ml); - /* done with message */ - continue; - } - for (rp = result; rp; rp = rp->ai_next) { - sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (sock < 0) - continue; - /* set nonblocking io, to prevent connect() and subsequent reads from blocking */ - flags = fcntl(sock, F_GETFL); - flags |= O_NONBLOCK; - fcntl(sock, F_SETFL, flags); - /* connect */ - rc = connect(sock, rp->ai_addr, rp->ai_addrlen); - if (rc == 0 || errno == EINPROGRESS) - break; - close(sock); - } - freeaddrinfo(result); - if (rp == NULL) { - LOGP(DCC, LOGL_ERROR, "Failed to connect to given host %s port %d.\n", ml->host, ml->port); - rej_msg(os, ml->callref, OSMO_CC_SOCKET_CAUSE_FAILED, 0, 0); - /* drop message */ - osmo_cc_free_msg(ml->msg); - free(ml); - /* done with message */ - continue; - } - /* create connection */ - conn = open_conn(os, sock, ml->callref, 0); - /* attach to list */ - conn->write_list = ml; - conn->ofd.when |= OSMO_FD_WRITE; - /* done with (setup) message */ - } - - return work; -} - -static int socket_listen_cb(struct osmo_fd *ofd, unsigned int when) -{ - osmo_cc_socket_t *os = ofd->data; - struct sockaddr_storage sa; - socklen_t slen = sizeof(sa); - int sock; - int flags; - - if (when & OSMO_FD_READ) { - /* handle new socket connection */ - if ((sock = accept(os->ofd.fd, (struct sockaddr *)&sa, &slen)) > 0) { - /* set nonblocking io, to prevent subsequent reads from blocking */ - flags = fcntl(sock, F_GETFL); - flags |= O_NONBLOCK; - fcntl(sock, F_SETFL, flags); - /* create connection */ - open_conn(os, sock, 0, 1); - } - } - - return 0; -} - -static int socket_conn_cb(struct osmo_fd *ofd, unsigned int when) -{ - osmo_cc_conn_t *conn = ofd->data; - int work; - - if (when & OSMO_FD_READ) { - /* check for rx */ - work = receive_conn(conn); - /* if "change" is set, connection list might have changed, so we restart processing the list */ - if (work) - return 0; - } - if (when & OSMO_FD_WRITE) { - /* check for tx */ - work = transmit_conn(conn); - /* if "change" is set, connection list might have changed, so we restart processing the list */ - if (work) - return 0; - else - conn->ofd.when &= ~OSMO_FD_WRITE; - } - - return 0; -} - diff --git a/src/libosmocc/socket.h b/src/libosmocc/socket.h deleted file mode 100644 index a3cc046..0000000 --- a/src/libosmocc/socket.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef OSMO_CC_SOCKET_H -#define OSMO_CC_SOCKET_H - -#define OSMO_CC_DEFAULT_PORT 4200 -#define OSMO_CC_DEFAULT_PORT_MAX 4219 - -#define OSMO_CC_SOCKET_TX_KEEPALIVE 10.0 -#define OSMO_CC_SOCKET_RX_KEEPALIVE 20.0 - -struct osmo_cc_socket; - -typedef struct osmo_cc_conn { - struct osmo_cc_conn *next; - struct osmo_cc_socket *os; - struct osmo_fd ofd; - uint32_t callref; - int read_setup; - int read_version; - char read_version_string[sizeof(OSMO_CC_VERSION)]; /* must include 0-termination */ - int read_version_pos; - int write_version; - osmo_cc_msg_t read_hdr; - osmo_cc_msg_t *read_msg; - int read_pos; - osmo_cc_msg_list_t *write_list; - struct timer tx_keepalive_timer; - struct timer rx_keepalive_timer; -} osmo_cc_conn_t; - -typedef struct osmo_cc_socket { - struct osmo_fd ofd; - osmo_cc_conn_t *conn_list; - osmo_cc_msg_list_t *write_list; - void (*recv_msg_cb)(void *priv, uint32_t callref, osmo_cc_msg_t *msg); - void *priv; - uint8_t location; -} osmo_cc_socket_t; - -int osmo_cc_open_socket(osmo_cc_socket_t *os, const char *host, uint16_t port, void *priv, void (*recv_msg_cb)(void *priv, uint32_t callref, osmo_cc_msg_t *msg), uint8_t location); -void osmo_cc_close_socket(osmo_cc_socket_t *os); -int osmo_cc_sock_send_msg(osmo_cc_socket_t *os, uint32_t callref, osmo_cc_msg_t *msg, const char *host, uint16_t port); -int osmo_cc_handle_socket(osmo_cc_socket_t *os); - -#endif /* OSMO_CC_SOCKET_H */ diff --git a/src/libph_socket/Makefile.am b/src/libph_socket/Makefile.am deleted file mode 100644 index 60fa592..0000000 --- a/src/libph_socket/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) - -noinst_LIBRARIES = libph_socket.a - -libph_socket_a_SOURCES = \ - ph_socket.c - diff --git a/src/libph_socket/ph_socket.c b/src/libph_socket/ph_socket.c deleted file mode 100644 index 28ec30f..0000000 --- a/src/libph_socket/ph_socket.c +++ /dev/null @@ -1,339 +0,0 @@ -/* PH-socket, a lightweight ISDN physical layer interface - * - * (C) 2022 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <stdint.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/socket.h> -#include "../libtimer/timer.h" -#include "../libselect/select.h" -#include "../libdebug/debug.h" -#include "ph_socket.h" - -static int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what); -static int ph_socket_connect_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what); -static void ph_socket_timeout_cb(void *data); - -static void open_connection(ph_socket_t *s) -{ - uint8_t enable = PH_CTRL_UNBLOCK; - int rc, flags; - - if (s->connect_ofd.fd > 0) - return; - - LOGP(DPH, LOGL_DEBUG, "Trying to connect to PH-socket server.\n"); - rc = socket(PF_UNIX, SOCK_STREAM, 0); - if (rc < 0) { - LOGP(DPH, LOGL_ERROR, "Failed to create UNIX socket.\n"); - osmo_timer_schedule(&s->retry_timer, SOCKET_RETRY_TIMER, 0); - return; - } - s->connect_ofd.fd = rc; - s->connect_ofd.data = s; - s->connect_ofd.when = BSC_FD_READ; - s->connect_ofd.cb = ph_socket_connect_cb; - osmo_fd_register(&s->connect_ofd); - /* set nonblocking io, because we do multiple reads when handling read event */ - flags = fcntl(s->connect_ofd.fd, F_GETFL); - flags |= O_NONBLOCK; - fcntl(s->connect_ofd.fd, F_SETFL, flags); - /* connect */ - rc = connect(s->connect_ofd.fd, (struct sockaddr *)&s->sock_address, sizeof(s->sock_address)); - if (rc < 0 && errno != EAGAIN) { - if (!s->connect_failed) - LOGP(DPH, LOGL_NOTICE, "Failed to connect UNIX socket, retrying...\n"); - close(s->connect_ofd.fd); - s->connect_failed = 1; - osmo_fd_unregister(&s->connect_ofd); - s->connect_ofd.fd = 0; - osmo_timer_schedule(&s->retry_timer, SOCKET_RETRY_TIMER, 0); - return; - } - s->connect_failed = 0; - LOGP(DPH, LOGL_INFO, "Connection to PH-socket server.\n"); - /* reset rx buffer */ - s->rx_header_index = 0; - s->rx_data_index = 0; - /* indicate established socket connection */ - s->ph_socket_rx_msg(s, 0, PH_PRIM_CTRL_IND, &enable, 1); -} - -static void close_connection(ph_socket_t *s) -{ - struct socket_msg_list *ml; - uint8_t disable = PH_CTRL_BLOCK; - - if (s->connect_ofd.fd <= 0) - return; - - LOGP(DPH, LOGL_INFO, "Connection from PH-socket closed.\n"); - - /* indicate loss of socket connection */ - s->ph_socket_rx_msg(s, 0, (s->listen_ofd.fd > 0) ? PH_PRIM_CTRL_REQ : PH_PRIM_CTRL_IND, &disable, 1); - - osmo_fd_unregister(&s->connect_ofd); - close(s->connect_ofd.fd); - s->connect_ofd.fd = 0; - - while ((ml = s->tx_list)) { - s->tx_list = ml->next; - free(ml); - } - s->tx_list_tail = &s->tx_list; - if (s->rx_msg) { - free(s->rx_msg); - s->rx_msg = NULL; - } - - if (s->listen_ofd.fd <= 0) { - /* set timer, so that retry is delayed */ - osmo_timer_schedule(&s->retry_timer, SOCKET_RETRY_TIMER, 0); - } -} - -int ph_socket_init(ph_socket_t *s, void (*ph_socket_rx_msg)(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, - int length), void *priv, const char *socket_name, int server) -{ - int rc; - - memset(s, 0, sizeof(*s)); - s->name = socket_name; - s->ph_socket_rx_msg = ph_socket_rx_msg; - s->priv = priv; - s->tx_list_tail = &s->tx_list; - - memset(&s->sock_address, 0, sizeof(s->sock_address)); - s->sock_address.sun_family = AF_UNIX; - strcpy(s->sock_address.sun_path+1, socket_name); - - s->retry_timer.data = s; - s->retry_timer.cb = ph_socket_timeout_cb; - - if (server) { - rc = socket(PF_UNIX, SOCK_STREAM, 0); - if (rc < 0) { - LOGP(DPH, LOGL_ERROR, "Failed to create UNIX socket.\n"); - return rc; - } - s->listen_ofd.fd = rc; - s->listen_ofd.data = s; - s->listen_ofd.when = BSC_FD_READ; - s->listen_ofd.cb = ph_socket_listen_cb; - osmo_fd_register(&s->listen_ofd); - - rc = bind(s->listen_ofd.fd, (struct sockaddr *)(&s->sock_address), sizeof(s->sock_address)); - if (rc < 0) { - LOGP(DPH, LOGL_ERROR, "Failed to bind UNIX socket with path '%s' (errno = %d (%s)).\n", - s->name, errno, strerror(errno)); - return rc; - } - - rc = listen(s->listen_ofd.fd, 1); - if (rc < 0) { - LOGP(DPH, LOGL_ERROR, "Failed to listen to UNIX socket with path '%s' (errno = %d (%s)).\n", - s->name, errno, strerror(errno)); - return rc; - } - } else - open_connection(s); - - LOGP(DPH, LOGL_INFO, "Created PH-socket at '%s'.\n", s->name); - - return 0; -} - -void ph_socket_exit(ph_socket_t *s) -{ - LOGP(DPH, LOGL_INFO, "Destroyed PH-socket.\n"); - - close_connection(s); - if (s->listen_ofd.fd > 0) { - osmo_fd_unregister(&s->listen_ofd); - close(s->listen_ofd.fd); - s->listen_ofd.fd = 0; - } - - if (osmo_timer_pending(&s->retry_timer)) - osmo_timer_del(&s->retry_timer); -} - -static int ph_socket_listen_cb(struct osmo_fd *ofd, unsigned int __attribute__((unused)) what) -{ - ph_socket_t *s = ofd->data; - struct sockaddr_un sock_address; - uint8_t enable = PH_CTRL_UNBLOCK; - int rc, flags; - - socklen_t sock_len = sizeof(sock_address); - /* see if there is an incoming connection */ - rc = accept(s->listen_ofd.fd, (struct sockaddr *)&sock_address, &sock_len); - if (rc > 0) { - if (s->connect_ofd.fd > 0) { - LOGP(DPH, LOGL_ERROR, "Rejecting incoming connection, because we already have a client " - "connected!\n"); - close(rc); - } else { - LOGP(DPH, LOGL_INFO, "Connection from PH-socket client.\n"); - s->connect_ofd.fd = rc; - s->connect_ofd.data = s; - s->connect_ofd.when = BSC_FD_READ; - s->connect_ofd.cb = ph_socket_connect_cb; - osmo_fd_register(&s->connect_ofd); - /* set nonblocking io, because we do multiple reads when handling read event */ - flags = fcntl(s->connect_ofd.fd, F_GETFL); - flags |= O_NONBLOCK; - fcntl(s->connect_ofd.fd, F_SETFL, flags); - /* reset rx buffer */ - s->rx_header_index = 0; - s->rx_data_index = 0; - /* indicate established socket connection */ - s->ph_socket_rx_msg(s, 0, PH_PRIM_CTRL_REQ, &enable, 1); - } - } - - return 0; -} - -static int ph_socket_connect_cb(struct osmo_fd *ofd, unsigned __attribute__((unused)) int what) -{ - ph_socket_t *s = ofd->data; - int rc; - - if (what & BSC_FD_READ) { -rx_again: - if (!s->rx_msg) - s->rx_msg = calloc(1, sizeof(*s->rx_msg)); - if (s->rx_header_index < (int)sizeof(s->rx_msg->msg.header)) { - /* read header until complete */ - rc = recv(s->connect_ofd.fd, ((uint8_t *)&s->rx_msg->msg.header) + s->rx_header_index, - sizeof(s->rx_msg->msg.header) - s->rx_header_index, 0); - if (rc > 0) { - s->rx_header_index += rc; - goto rx_again; - } else if (rc == 0 || errno != EAGAIN) { - close_connection(s); - return 0; - } - } else if (s->rx_data_index < s->rx_msg->msg.header.length) { - /* read data until complete */ - rc = recv(s->connect_ofd.fd, s->rx_msg->msg.data + s->rx_data_index, - s->rx_msg->msg.header.length - s->rx_data_index, 0); - if (rc > 0) { - s->rx_data_index += rc; - goto rx_again; - } else if (rc == 0 || errno != EAGAIN) { - close_connection(s); - return 0; - } - } else { - /* process and free message */ - if (s->rx_msg->msg.header.prim != PH_PRIM_DATA_REQ - && s->rx_msg->msg.header.prim != PH_PRIM_DATA_IND - && s->rx_msg->msg.header.prim != PH_PRIM_DATA_CNF) { - LOGP(DPH, LOGL_DEBUG, "message 0x%02x channel %d from socket\n", - s->rx_msg->msg.header.prim, s->rx_msg->msg.header.channel); - if (s->rx_msg->msg.header.length) - LOGP(DPH, LOGL_DEBUG, " -> data:%s\n", osmo_hexdump(s->rx_msg->msg.data, - s->rx_msg->msg.header.length)); - } - s->ph_socket_rx_msg(s, s->rx_msg->msg.header.channel, s->rx_msg->msg.header.prim, - s->rx_msg->msg.data, s->rx_msg->msg.header.length); - free(s->rx_msg); - s->rx_msg = NULL; - /* reset rx buffer */ - s->rx_header_index = 0; - s->rx_data_index = 0; - } - } - - if (what & BSC_FD_WRITE) { - if (s->tx_list) { - /* some frame in tx list, so try sending it */ - rc = send(s->connect_ofd.fd, ((uint8_t *)&s->tx_list->msg.header), - sizeof(s->tx_list->msg.header) + s->tx_list->msg.header.length, 0); - if (rc > 0) { - struct socket_msg_list *ml; - if (rc != (int)sizeof(s->tx_list->msg.header) + s->tx_list->msg.header.length) { - LOGP(DPH, LOGL_ERROR, "Short write, please fix handling!\n"); - } - /* remove list entry */ - ml = s->tx_list; - s->tx_list = ml->next; - if (s->tx_list == NULL) - s->tx_list_tail = &s->tx_list; - free(ml); - } else if (rc == 0 || errno != EAGAIN) { - close_connection(s); - return 0; - } - } else - s->connect_ofd.when &= ~BSC_FD_WRITE; - } - - return 0; -} - -static void ph_socket_timeout_cb(void *data) -{ - ph_socket_t *s = data; - - open_connection(s); -} - -void ph_socket_tx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length) -{ - struct socket_msg_list *tx_msg; - - if (prim != PH_PRIM_DATA_REQ - && prim != PH_PRIM_DATA_IND - && prim != PH_PRIM_DATA_CNF) { - LOGP(DPH, LOGL_DEBUG, "message 0x%02x channel %d to socket\n", prim, channel); - if (length) - LOGP(DPH, LOGL_DEBUG, " -> data:%s\n", osmo_hexdump(data, length)); - } - - if (length > (int)sizeof(tx_msg->msg.data)) { - LOGP(DPH, LOGL_NOTICE, "Frame from HDLC process too large for socket, dropping!\n"); - return; - } - - if (s->connect_ofd.fd <= 0) { - LOGP(DPH, LOGL_NOTICE, "Dropping message for socket, socket is closed!\n"); - return; - } - - tx_msg = calloc(1, sizeof(*tx_msg)); - tx_msg->msg.header.channel = channel; - tx_msg->msg.header.prim = prim; - if (length) { - tx_msg->msg.header.length = length; - memcpy(tx_msg->msg.data, data, length); - } - /* move message to list */ - *s->tx_list_tail = tx_msg; - s->tx_list_tail = &tx_msg->next; - s->connect_ofd.when |= BSC_FD_WRITE; -} - diff --git a/src/libph_socket/ph_socket.h b/src/libph_socket/ph_socket.h deleted file mode 100644 index 97293c3..0000000 --- a/src/libph_socket/ph_socket.h +++ /dev/null @@ -1,107 +0,0 @@ - -#include <sys/un.h> - -/* - * Procedure: - * - * If socket connection is establised, a PH_PRIM_CTRL_REQ message with - * PH_CTRL_ENABLE information is received by the socket server user. - * If the socket connection is lost, a PH_PRIM_CTRL_REQ message with - * PH_CTRL_DISABLE information is received by the user. - * - * If socket connection is establised, a PH_PRIM_CTRL_IND message with - * PH_CTRL_ENABLE information is received by the socket client user. - * If the socket connection is lost, a PH_PRIM_CTRL_IND message with - * PH_CTRL_DISABLE information is received by the user. - * - * The socket server should enable or disable interface depending on - * the PH_CTRL_ENABLE / PH_CTRL_DISABLE information. - * - * The socket client user shall keep track of last PH_PRIM_ACT_IND / - * PH_PRIM_DEACT_IND message and treat a PH_PRIM_CTRL_IND message with - * PH_CTRL_DISABLE information as a deactivation of all channels that - * were activated. Also it shall reject every PH_RIM_ACT_REQ with a - * PH_PRIM_DACT_IND, if the socket is currently unavailable. - * - * PH_PRIM_CTRL_REQ and PH_PRIM_CTRL_IND messages with PH_CTRL_ENABLE - * and PH_CTRL_DISABLE informations are not assoicated with a channel - * number. The socket sender shall set it to 0, the receiver shall - * ignore it. - * - * A missing MODE in PH_PRIM_ACT_REQ is interepreted as default: - * HDLC on D-channel, TRANS on B-channel. - * - * Each packet on the socket shall have the follwoing header: - * uint8_t channel; - * uint8_t prim; - * uint16_t length; - * - * The length shall be in host's endian on UN sockets and in network - * endian on TCP sockets and not being transmitted on UDP sockets. - * - * 0 to 65535 bytes shall follow the header, depending on the length - * information field. - */ - -/* all primitives */ -#define PH_PRIM_DATA_REQ 0x00 /* any data sent to channel from upper layer */ -#define PH_PRIM_DATA_IND 0x01 /* any data received from channel to upper layer */ -#define PH_PRIM_DATA_CNF 0x02 /* confirm data sent to channel */ - -#define PH_PRIM_CTRL_REQ 0x04 /* implementation specific requests towards interface */ -#define PH_PRIM_CTRL_IND 0x05 /* implementation specific indications from interface */ - -#define PH_PRIM_ACT_REQ 0x08 /* activation request of channel, mode is given as payload */ -#define PH_PRIM_ACT_IND 0x09 /* activation indication that the channel is now active */ - -#define PH_PRIM_DACT_REQ 0x0c /* deactivation request of channel */ -#define PH_PRIM_DACT_IND 0x0d /* deactivation indication that the channel is now inactive */ - -/* one byte sent activation request */ -#define PH_MODE_TRANS 0x00 /* raw data is sent via B-channel */ -#define PH_MODE_HDLC 0x01 /* HDLC transcoding is performed via B-channel */ - -/* one byte sent with control messages */ -#define PH_CTRL_BLOCK 0x00 /* disable (block) interface, when socket is disconnected */ -#define PH_CTRL_UNBLOCK 0x01 /* enable (unblock) interface, when socket is connected */ -#define PH_CTRL_LOOP_DISABLE 0x04 /* disable loopback */ -#define PH_CTRL_LOOP1_ENABLE 0x05 /* enable LT transceier loopback */ -#define PH_CTRL_LOOP2_ENABLE 0x06 /* enable NT transceier loopback */ -#define PH_CTRL_LOOP_ERROR 0x10 /* frame error report (loopback test) */ -#define PH_CTRL_VIOLATION_LT 0x11 /* code violation received by LT */ -#define PH_CTRL_VIOLATION_NT 0x12 /* code violation received by NT */ - -struct socket_msg { - struct { - uint8_t channel; - uint8_t prim; - uint16_t length; - } header; - uint8_t data[65536]; -} __attribute__((packed)); - -struct socket_msg_list { - struct socket_msg_list *next; - struct socket_msg msg; -}; - -#define SOCKET_RETRY_TIMER 2 - -typedef struct ph_socket { - const char *name; - void (*ph_socket_rx_msg)(struct ph_socket *s, int channel, uint8_t prim, uint8_t *data, int length); - void *priv; - struct sockaddr_un sock_address; - struct osmo_fd listen_ofd; /* socket to listen to incoming connections */ - struct osmo_fd connect_ofd; /* socket of incoming connection */ - int connect_failed; /* used to print a failure only once */ - struct osmo_timer_list retry_timer; /* timer to connect again */ - struct socket_msg_list *tx_list, **tx_list_tail; - struct socket_msg_list *rx_msg; - int rx_header_index; - int rx_data_index; -} ph_socket_t; - -int ph_socket_init(ph_socket_t *s, void (*ph_socket_rx_msg)(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length), void *priv, const char *socket_name, int server); -void ph_socket_exit(ph_socket_t *s); -void ph_socket_tx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length); diff --git a/src/libsdr/sdr.c b/src/libsdr/sdr.c index 43e04c7..50659ed 100644 --- a/src/libsdr/sdr.c +++ b/src/libsdr/sdr.c @@ -31,7 +31,7 @@ enum paging_signal; #include "../libsample/sample.h" #include "../libfm/fm.h" #include "../libam/am.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../libmobile/sender.h" #include "sdr_config.h" #include "sdr.h" @@ -41,7 +41,7 @@ enum paging_signal; #ifdef HAVE_SOAPY #include "soapy.h" #endif -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" /* enable to debug buffer handling */ //#define DEBUG_BUFFER @@ -130,11 +130,11 @@ static void show_spectrum(const char *direction, double halfbandwidth, double ce text[x] = 'P'; } - PDEBUG(DSDR, DEBUG_INFO, "%s Spectrum:\n%s\n---------------------------------------+---------------------------------------\n", direction, text); + LOGP(DSDR, LOGL_INFO, "%s Spectrum:\n%s\n---------------------------------------+---------------------------------------\n", direction, text); for (i = 0; i < num; i++) - PDEBUG(DSDR, DEBUG_INFO, "Frequency %c = %.4f MHz\n", '1' + i, frequency[i] / 1e6); + LOGP(DSDR, LOGL_INFO, "Frequency %c = %.4f MHz\n", '1' + i, frequency[i] / 1e6); if (paging_frequency) - PDEBUG(DSDR, DEBUG_INFO, "Frequency P = %.4f MHz (Paging Frequency)\n", paging_frequency / 1e6); + LOGP(DSDR, LOGL_INFO, "Frequency P = %.4f MHz (Paging Frequency)\n", paging_frequency / 1e6); } void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_frequency, double *rx_frequency, int *am, int channels, double paging_frequency, int samplerate, int buffer_size, double interval, double max_deviation, double max_modulation, double modulation_index) @@ -146,17 +146,17 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque int rc; int c; - PDEBUG(DSDR, DEBUG_DEBUG, "Open SDR device\n"); + LOGP(DSDR, LOGL_DEBUG, "Open SDR device\n"); if (sdr_config->samplerate != samplerate) { if (samplerate > sdr_config->samplerate) { - PDEBUG(DSDR, DEBUG_ERROR, "SDR sample rate must be greater than audio sample rate!\n"); - PDEBUG(DSDR, DEBUG_ERROR, "You selected an SDR rate of %d and an audio rate of %d.\n", sdr_config->samplerate, samplerate); + LOGP(DSDR, LOGL_ERROR, "SDR sample rate must be greater than audio sample rate!\n"); + LOGP(DSDR, LOGL_ERROR, "You selected an SDR rate of %d and an audio rate of %d.\n", sdr_config->samplerate, samplerate); return NULL; } if ((sdr_config->samplerate % samplerate)) { - PDEBUG(DSDR, DEBUG_ERROR, "SDR sample rate must be a multiple of audio sample rate!\n"); - PDEBUG(DSDR, DEBUG_ERROR, "You selected an SDR rate of %d and an audio rate of %d.\n", sdr_config->samplerate, samplerate); + LOGP(DSDR, LOGL_ERROR, "SDR sample rate must be a multiple of audio sample rate!\n"); + LOGP(DSDR, LOGL_ERROR, "You selected an SDR rate of %d and an audio rate of %d.\n", sdr_config->samplerate, samplerate); return NULL; } oversample = sdr_config->samplerate / samplerate; @@ -165,11 +165,11 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque bandwidth = 2.0 * (max_deviation + max_modulation); if (bandwidth) - PDEBUG(DSDR, DEBUG_INFO, "Require bandwidth of each channel is 2 * (%.1f deviation + %.1f modulation) = %.1f KHz\n", max_deviation / 1e3, max_modulation / 1e3, bandwidth / 1e3); + LOGP(DSDR, LOGL_INFO, "Require bandwidth of each channel is 2 * (%.1f deviation + %.1f modulation) = %.1f KHz\n", max_deviation / 1e3, max_modulation / 1e3, bandwidth / 1e3); sdr = calloc(sizeof(*sdr), 1); if (!sdr) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } sdr->channels = channels; @@ -185,12 +185,12 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque sdr->thread_read.buffer_size = sdr->buffer_size * 2 * sdr->oversample + 2; sdr->thread_read.buffer = calloc(sdr->thread_read.buffer_size, sizeof(*sdr->thread_read.buffer)); if (!sdr->thread_read.buffer) { - PDEBUG(DSDR, DEBUG_ERROR, "No mem!\n"); + LOGP(DSDR, LOGL_ERROR, "No mem!\n"); goto error; } sdr->thread_read.buffer2 = calloc(sdr->thread_read.buffer_size, sizeof(*sdr->thread_read.buffer2)); if (!sdr->thread_read.buffer2) { - PDEBUG(DSDR, DEBUG_ERROR, "No mem!\n"); + LOGP(DSDR, LOGL_ERROR, "No mem!\n"); goto error; } sdr->thread_read.in = sdr->thread_read.out = 0; @@ -202,12 +202,12 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque sdr->thread_write.buffer_size = sdr->buffer_size * 2 + 2; sdr->thread_write.buffer = calloc(sdr->thread_write.buffer_size, sizeof(*sdr->thread_write.buffer)); if (!sdr->thread_write.buffer) { - PDEBUG(DSDR, DEBUG_ERROR, "No mem!\n"); + LOGP(DSDR, LOGL_ERROR, "No mem!\n"); goto error; } sdr->thread_write.buffer2 = calloc(sdr->thread_write.buffer_size * sdr->oversample, sizeof(*sdr->thread_write.buffer2)); if (!sdr->thread_write.buffer2) { - PDEBUG(DSDR, DEBUG_ERROR, "No mem!\n"); + LOGP(DSDR, LOGL_ERROR, "No mem!\n"); goto error; } sdr->thread_write.in = sdr->thread_write.out = 0; @@ -220,32 +220,32 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque /* alloc fm modulation buffers */ sdr->modbuff = calloc(sdr->buffer_size * 2, sizeof(*sdr->modbuff)); if (!sdr->modbuff) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } sdr->modbuff_I = calloc(sdr->buffer_size, sizeof(*sdr->modbuff_I)); if (!sdr->modbuff_I) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } sdr->modbuff_Q = calloc(sdr->buffer_size, sizeof(*sdr->modbuff_Q)); if (!sdr->modbuff_Q) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } sdr->modbuff_carrier = calloc(sdr->buffer_size, sizeof(*sdr->modbuff_carrier)); if (!sdr->modbuff_carrier) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } sdr->wavespl0 = calloc(sdr->buffer_size, sizeof(*sdr->wavespl0)); if (!sdr->wavespl0) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } sdr->wavespl1 = calloc(sdr->buffer_size, sizeof(*sdr->wavespl1)); if (!sdr->wavespl1) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } @@ -259,7 +259,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque if (channels) { sdr->chan = calloc(sizeof(*sdr->chan), channels + (sdr->paging_channel != 0)); if (!sdr->chan) { - PDEBUG(DSDR, DEBUG_ERROR, "NO MEM!\n"); + LOGP(DSDR, LOGL_ERROR, "NO MEM!\n"); goto error; } } @@ -267,7 +267,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque /* swap links, if required */ if (sdr_config->swap_links) { double *temp; - PDEBUG(DSDR, DEBUG_NOTICE, "Sapping RX and TX frequencies!\n"); + LOGP(DSDR, LOGL_NOTICE, "Sapping RX and TX frequencies!\n"); temp = rx_frequency; rx_frequency = tx_frequency; tx_frequency = temp; @@ -304,7 +304,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque This is correct, since there is no bandwidth below new center frequency. */ - PDEBUG(DSDR, DEBUG_INFO, "We shift center frequency %.0f KHz down (half bandwidth), to prevent channel from overlap with DC level.\n", bandwidth / 2.0 / 1e3); + LOGP(DSDR, LOGL_INFO, "We shift center frequency %.0f KHz down (half bandwidth), to prevent channel from overlap with DC level.\n", bandwidth / 2.0 / 1e3); } else { /* find two channels that are aside the center */ double low_dist = 0, high_dist = 0, dist; @@ -342,7 +342,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque tx_center_frequency = ((sdr->chan[low_c].tx_frequency) + (sdr->chan[high_c].tx_frequency)) / 2.0; - PDEBUG(DSDR, DEBUG_INFO, "We move center freqeuency between the two channels in the middle, to prevent them from overlap with DC level.\n"); + LOGP(DSDR, LOGL_INFO, "We move center freqeuency between the two channels in the middle, to prevent them from overlap with DC level.\n"); } } @@ -354,20 +354,20 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque low_side = (tx_center_frequency - tx_low_frequency) + bandwidth / 2.0; high_side = (tx_high_frequency - tx_center_frequency) + bandwidth / 2.0; range = ((low_side > high_side) ? low_side : high_side) * 2.0; - PDEBUG(DSDR, DEBUG_INFO, "Total bandwidth (two side bands) for all TX Frequencies: %.0f Hz\n", range); + LOGP(DSDR, LOGL_INFO, "Total bandwidth (two side bands) for all TX Frequencies: %.0f Hz\n", range); if (range > samplerate * USABLE_BANDWIDTH) { - PDEBUG(DSDR, DEBUG_NOTICE, "*******************************************************************************\n"); - PDEBUG(DSDR, DEBUG_NOTICE, "The required bandwidth of %.0f Hz exceeds %.0f%% of the sample rate.\n", range, USABLE_BANDWIDTH * 100.0); - PDEBUG(DSDR, DEBUG_NOTICE, "Please increase samplerate!\n"); - PDEBUG(DSDR, DEBUG_NOTICE, "*******************************************************************************\n"); + LOGP(DSDR, LOGL_NOTICE, "*******************************************************************************\n"); + LOGP(DSDR, LOGL_NOTICE, "The required bandwidth of %.0f Hz exceeds %.0f%% of the sample rate.\n", range, USABLE_BANDWIDTH * 100.0); + LOGP(DSDR, LOGL_NOTICE, "Please increase samplerate!\n"); + LOGP(DSDR, LOGL_NOTICE, "*******************************************************************************\n"); goto error; } - PDEBUG(DSDR, DEBUG_INFO, "Using center frequency: TX %.6f MHz\n", tx_center_frequency / 1e6); + LOGP(DSDR, LOGL_INFO, "Using center frequency: TX %.6f MHz\n", tx_center_frequency / 1e6); /* set offsets to center frequency */ for (c = 0; c < channels; c++) { double tx_offset; tx_offset = sdr->chan[c].tx_frequency - tx_center_frequency; - PDEBUG(DSDR, DEBUG_DEBUG, "Frequency #%d: TX offset: %.6f MHz\n", c, tx_offset / 1e6); + LOGP(DSDR, LOGL_DEBUG, "Frequency #%d: TX offset: %.6f MHz\n", c, tx_offset / 1e6); sdr->chan[c].am = am[c]; if (am[c]) { double gain, bias; @@ -382,18 +382,18 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque if (sdr->paging_channel) { double tx_offset; tx_offset = sdr->chan[sdr->paging_channel].tx_frequency - tx_center_frequency; - PDEBUG(DSDR, DEBUG_DEBUG, "Paging Frequency: TX offset: %.6f MHz\n", tx_offset / 1e6); + LOGP(DSDR, LOGL_DEBUG, "Paging Frequency: TX offset: %.6f MHz\n", tx_offset / 1e6); rc = fm_mod_init(&sdr->chan[sdr->paging_channel].fm_mod, samplerate, tx_offset, sdr->amplitude); if (rc < 0) goto error; } /* show gain */ - PDEBUG(DSDR, DEBUG_INFO, "Using gain: TX %.1f dB\n", sdr_config->tx_gain); + LOGP(DSDR, LOGL_INFO, "Using gain: TX %.1f dB\n", sdr_config->tx_gain); /* open wave */ if (sdr_config->write_iq_tx_wave) { rc = wave_create_record(&sdr->wave_tx_rec, sdr_config->write_iq_tx_wave, samplerate, 2, 1.0); if (rc < 0) { - PDEBUG(DSDR, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DSDR, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); goto error; } } @@ -401,7 +401,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque int two = 2; rc = wave_create_playback(&sdr->wave_tx_play, sdr_config->read_iq_tx_wave, &samplerate, &two, 1.0); if (rc < 0) { - PDEBUG(DSDR, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DSDR, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); goto error; } } @@ -430,7 +430,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque This is correct, since there is no bandwidth below new center frequency. */ - PDEBUG(DSDR, DEBUG_INFO, "We shift center frequency %.0f KHz down (half bandwidth), to prevent channel from overlap with DC level.\n", bandwidth / 2.0 / 1e3); + LOGP(DSDR, LOGL_INFO, "We shift center frequency %.0f KHz down (half bandwidth), to prevent channel from overlap with DC level.\n", bandwidth / 2.0 / 1e3); } else { /* find two channels that are aside the center */ double low_dist, high_dist, dist; @@ -454,7 +454,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque rx_center_frequency = ((sdr->chan[low_c].rx_frequency) + (sdr->chan[high_c].rx_frequency)) / 2.0; - PDEBUG(DSDR, DEBUG_INFO, "We move center freqeuency between the two channels in the middle, to prevent them from overlap with DC level.\n"); + LOGP(DSDR, LOGL_INFO, "We move center freqeuency between the two channels in the middle, to prevent them from overlap with DC level.\n"); } } @@ -466,20 +466,20 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque low_side = (rx_center_frequency - rx_low_frequency) + bandwidth / 2.0; high_side = (rx_high_frequency - rx_center_frequency) + bandwidth / 2.0; range = ((low_side > high_side) ? low_side : high_side) * 2.0; - PDEBUG(DSDR, DEBUG_INFO, "Total bandwidth (two side bands) for all RX Frequencies: %.0f Hz\n", range); + LOGP(DSDR, LOGL_INFO, "Total bandwidth (two side bands) for all RX Frequencies: %.0f Hz\n", range); if (range > samplerate * USABLE_BANDWIDTH) { - PDEBUG(DSDR, DEBUG_NOTICE, "*******************************************************************************\n"); - PDEBUG(DSDR, DEBUG_NOTICE, "The required bandwidth of %.0f Hz exceeds %.0f%% of the sample rate.\n", range, USABLE_BANDWIDTH * 100.0); - PDEBUG(DSDR, DEBUG_NOTICE, "Please increase samplerate!\n"); - PDEBUG(DSDR, DEBUG_NOTICE, "*******************************************************************************\n"); + LOGP(DSDR, LOGL_NOTICE, "*******************************************************************************\n"); + LOGP(DSDR, LOGL_NOTICE, "The required bandwidth of %.0f Hz exceeds %.0f%% of the sample rate.\n", range, USABLE_BANDWIDTH * 100.0); + LOGP(DSDR, LOGL_NOTICE, "Please increase samplerate!\n"); + LOGP(DSDR, LOGL_NOTICE, "*******************************************************************************\n"); goto error; } - PDEBUG(DSDR, DEBUG_INFO, "Using center frequency: RX %.6f MHz\n", rx_center_frequency / 1e6); + LOGP(DSDR, LOGL_INFO, "Using center frequency: RX %.6f MHz\n", rx_center_frequency / 1e6); /* set offsets to center frequency */ for (c = 0; c < channels; c++) { double rx_offset; rx_offset = sdr->chan[c].rx_frequency - rx_center_frequency; - PDEBUG(DSDR, DEBUG_DEBUG, "Frequency #%d: RX offset: %.6f MHz\n", c, rx_offset / 1e6); + LOGP(DSDR, LOGL_DEBUG, "Frequency #%d: RX offset: %.6f MHz\n", c, rx_offset / 1e6); sdr->chan[c].am = am[c]; if (am[c]) rc = am_demod_init(&sdr->chan[c].am_demod, samplerate, rx_offset, bandwidth, 1.0 / modulation_index); @@ -489,12 +489,12 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque goto error; } /* show gain */ - PDEBUG(DSDR, DEBUG_INFO, "Using gain: RX %.1f dB\n", sdr_config->rx_gain); + LOGP(DSDR, LOGL_INFO, "Using gain: RX %.1f dB\n", sdr_config->rx_gain); /* open wave */ if (sdr_config->write_iq_rx_wave) { rc = wave_create_record(&sdr->wave_rx_rec, sdr_config->write_iq_rx_wave, samplerate, 2, 1.0); if (rc < 0) { - PDEBUG(DSDR, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n"); + LOGP(DSDR, LOGL_ERROR, "Failed to create WAVE recoding instance!\n"); goto error; } } @@ -502,7 +502,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque int two = 2; rc = wave_create_playback(&sdr->wave_rx_play, sdr_config->read_iq_rx_wave, &samplerate, &two, 1.0); if (rc < 0) { - PDEBUG(DSDR, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DSDR, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); goto error; } } @@ -522,7 +522,7 @@ void *sdr_open(const char __attribute__((__unused__)) *device, double *tx_freque display_iq_init(samplerate); display_spectrum_init(samplerate, rx_center_frequency); - PDEBUG(DSDR, DEBUG_INFO, "Using local oscillator offseet: %.0f Hz\n", sdr_config->lo_offset); + LOGP(DSDR, LOGL_INFO, "Using local oscillator offseet: %.0f Hz\n", sdr_config->lo_offset); #ifdef HAVE_UHD if (sdr_config->uhd) { @@ -570,7 +570,7 @@ static void sdr_bias(float *buffer, int count) if (bias_count >= sdr_config->samplerate) { bias_I /= bias_count; bias_Q /= bias_count; - PDEBUG(DSDR, DEBUG_INFO, "DC bias calibration finished.\n"); + LOGP(DSDR, LOGL_INFO, "DC bias calibration finished.\n"); } } else { for (i = 0; i < count; i++) { @@ -625,7 +625,7 @@ static void *sdr_write_child(void *arg) usleep(sdr->interval * 1000.0); } - PDEBUG(DSDR, DEBUG_DEBUG, "Thread received exit!\n"); + LOGP(DSDR, LOGL_DEBUG, "Thread received exit!\n"); sdr->thread_write.exit = 1; return NULL; } @@ -677,7 +677,7 @@ static void *sdr_read_child(void *arg) usleep(sdr->interval * 1000.0); } - PDEBUG(DSDR, DEBUG_DEBUG, "Thread received exit!\n"); + LOGP(DSDR, LOGL_DEBUG, "Thread received exit!\n"); sdr->thread_read.exit = 1; return NULL; } @@ -704,13 +704,13 @@ int sdr_start(void *inst) pthread_t tid; char tname[64]; - PDEBUG(DSDR, DEBUG_DEBUG, "Create threads!\n"); + LOGP(DSDR, LOGL_DEBUG, "Create threads!\n"); sdr->thread_write.running = 1; sdr->thread_write.exit = 0; rc = pthread_create(&tid, NULL, sdr_write_child, inst); if (rc < 0) { sdr->thread_write.running = 0; - PDEBUG(DSDR, DEBUG_ERROR, "Failed to create thread!\n"); + LOGP(DSDR, LOGL_ERROR, "Failed to create thread!\n"); return rc; } pthread_getname_np(tid, tname, sizeof(tname)); @@ -722,7 +722,7 @@ int sdr_start(void *inst) rc = pthread_create(&tid, NULL, sdr_read_child, inst); if (rc < 0) { sdr->thread_read.running = 0; - PDEBUG(DSDR, DEBUG_ERROR, "Failed to create thread!\n"); + LOGP(DSDR, LOGL_ERROR, "Failed to create thread!\n"); return rc; } pthread_getname_np(tid, tname, sizeof(tname)); @@ -738,17 +738,17 @@ void sdr_close(void *inst) { sdr_t *sdr = (sdr_t *)inst; - PDEBUG(DSDR, DEBUG_DEBUG, "Close SDR device\n"); + LOGP(DSDR, LOGL_DEBUG, "Close SDR device\n"); if (sdr->threads) { if (sdr->thread_write.running) { - PDEBUG(DSDR, DEBUG_DEBUG, "Thread sending exit!\n"); + LOGP(DSDR, LOGL_DEBUG, "Thread sending exit!\n"); sdr->thread_write.running = 0; while (sdr->thread_write.exit == 0) usleep(1000); } if (sdr->thread_read.running) { - PDEBUG(DSDR, DEBUG_DEBUG, "Thread sending exit!\n"); + LOGP(DSDR, LOGL_DEBUG, "Thread sending exit!\n"); sdr->thread_read.running = 0; while (sdr->thread_read.exit == 0) usleep(1000); @@ -805,6 +805,15 @@ void sdr_close(void *inst) display_spectrum_exit(); } +static double get_time(void) +{ + static struct timespec tv; + + clock_gettime(CLOCK_REALTIME, &tv); + + return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000.0; +} + int sdr_write(void *inst, sample_t **samples, uint8_t **power, int num, enum paging_signal __attribute__((unused)) *paging_signal, int *on, int channels) { sdr_t *sdr = (sdr_t *)inst; @@ -817,7 +826,7 @@ int sdr_write(void *inst, sample_t **samples, uint8_t **power, int num, enum pag abort(); } if (channels != sdr->channels && channels != 0) { - PDEBUG(DSDR, DEBUG_ERROR, "Invalid number of channels, please fix!\n"); + LOGP(DSDR, LOGL_ERROR, "Invalid number of channels, please fix!\n"); abort(); } @@ -872,11 +881,11 @@ int sdr_write(void *inst, sample_t **samples, uint8_t **power, int num, enum pag delay = (double)sdr->thread_write.max_fill / 2.0 / (double)sdr->samplerate; sdr->thread_write.max_fill = 0; sdr->thread_write.max_fill_timer += 1.0; - PDEBUG(DSDR, DEBUG_DEBUG, "write delay = %.3f ms\n", delay * 1000.0); + LOGP(DSDR, LOGL_DEBUG, "write delay = %.3f ms\n", delay * 1000.0); } if (space < num * 2) { - PDEBUG(DSDR, DEBUG_ERROR, "Write SDR buffer overflow!\n"); + LOGP(DSDR, LOGL_ERROR, "Write SDR buffer overflow!\n"); num = space / 2; } #ifdef DEBUG_BUFFER @@ -940,7 +949,7 @@ int sdr_read(void *inst, sample_t **samples, int num, int channels, double *rf_l delay = (double)sdr->thread_read.max_fill / 2.0 / (double)sdr_config->samplerate; sdr->thread_read.max_fill = 0; sdr->thread_read.max_fill_timer += 1.0; - PDEBUG(DSDR, DEBUG_DEBUG, "read delay = %.3f ms\n", delay * 1000.0); + LOGP(DSDR, LOGL_DEBUG, "read delay = %.3f ms\n", delay * 1000.0); } if (fill / 2 / sdr->oversample < num) @@ -972,7 +981,7 @@ int sdr_read(void *inst, sample_t **samples, int num, int channels, double *rf_l } if (sdr_rx_overflow) { - PDEBUG(DSDR, DEBUG_ERROR, "SDR RX overflow!\n"); + LOGP(DSDR, LOGL_ERROR, "SDR RX overflow!\n"); sdr_rx_overflow = 0; } diff --git a/src/libsdr/soapy.c b/src/libsdr/soapy.c index e5586d7..07d7007 100644 --- a/src/libsdr/soapy.c +++ b/src/libsdr/soapy.c @@ -45,7 +45,7 @@ #include <SoapySDR/Device.h> #include <SoapySDR/Formats.h> #include "soapy.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" extern int sdr_rx_overflow; @@ -72,7 +72,7 @@ static int parse_args(SoapySDRKwargs *args, const char *_args_string) key = args_string; val = strchr(key, '='); if (!val) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Error parsing SDR args: No '=' after key\n"); + LOGP(DSOAPY, LOGL_ERROR, "Error parsing SDR args: No '=' after key\n"); soapy_close(); return -EIO; } @@ -80,7 +80,7 @@ static int parse_args(SoapySDRKwargs *args, const char *_args_string) args_string = strchr(val, ','); if (args_string) *args_string++ = '\0'; - PDEBUG(DSOAPY, DEBUG_DEBUG, "SDR device args: key='%s' value='%s'\n", key, val); + LOGP(DSOAPY, LOGL_DEBUG, "SDR device args: key='%s' value='%s'\n", key, val); SoapySDRKwargs_set(args, key, val); } @@ -99,22 +99,22 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg use_time_stamps = timestamps; if (use_time_stamps && (1000000000LL % (long long)rate)) { - PDEBUG(DSOAPY, DEBUG_ERROR, "The given sample duration is not a multiple of a nano second. I.e. we can't divide 10^9 by sample rate of %.0f. Please choose a different sample rate for time stamp support!\n", rate); + LOGP(DSOAPY, LOGL_ERROR, "The given sample duration is not a multiple of a nano second. I.e. we can't divide 10^9 by sample rate of %.0f. Please choose a different sample rate for time stamp support!\n", rate); use_time_stamps = 0; } Ns_per_sample = 1000000000LL / (long long)rate; samplerate = rate; /* parsing ARGS */ - PDEBUG(DSOAPY, DEBUG_INFO, "Using device args \"%s\"\n", _device_args); + LOGP(DSOAPY, LOGL_INFO, "Using device args \"%s\"\n", _device_args); rc = parse_args(&device_args, _device_args); if (rc < 0) return rc; - PDEBUG(DSOAPY, DEBUG_INFO, "Using stream args \"%s\"\n", _stream_args); + LOGP(DSOAPY, LOGL_INFO, "Using stream args \"%s\"\n", _stream_args); rc = parse_args(&stream_args, _stream_args); if (rc < 0) return rc; - PDEBUG(DSOAPY, DEBUG_INFO, "Using tune args \"%s\"\n", _tune_args); + LOGP(DSOAPY, LOGL_INFO, "Using tune args \"%s\"\n", _tune_args); rc = parse_args(&tune_args, _tune_args); if (rc < 0) return rc; @@ -129,7 +129,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* create SoapySDR device */ sdr = SoapySDRDevice_make(&device_args); if (!sdr) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to create SoapySDR\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to create SoapySDR\n"); soapy_close(); return -EIO; } @@ -142,29 +142,29 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg int i; clocks = SoapySDRDevice_listClockSources(sdr, &clocks_length); if (!clocks) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to request list of clock sources!\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to request list of clock sources!\n"); soapy_close(); return -EIO; } if (clocks_length) { for (i = 0; i < (int)clocks_length; i++) - PDEBUG(DSOAPY, DEBUG_NOTICE, "Clock source: '%s'\n", clocks[i]); + LOGP(DSOAPY, LOGL_NOTICE, "Clock source: '%s'\n", clocks[i]); got_clock = SoapySDRDevice_getClockSource(sdr); - PDEBUG(DSOAPY, DEBUG_NOTICE, "Default clock source: '%s'\n", got_clock); + LOGP(DSOAPY, LOGL_NOTICE, "Default clock source: '%s'\n", got_clock); } else - PDEBUG(DSOAPY, DEBUG_NOTICE, "There are no clock sources configurable for this device.\n"); + LOGP(DSOAPY, LOGL_NOTICE, "There are no clock sources configurable for this device.\n"); soapy_close(); return 1; } if (SoapySDRDevice_setClockSource(sdr, clock_source) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set clock source to '%s'\n", clock_source); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set clock source to '%s'\n", clock_source); soapy_close(); return -EIO; } got_clock = SoapySDRDevice_getClockSource(sdr); if (!!strcasecmp(clock_source, got_clock)) { - PDEBUG(DSOAPY, DEBUG_NOTICE, "Given clock source '%s' was accepted, but driver claims to use '%s'\n", clock_source, got_clock); + LOGP(DSOAPY, LOGL_NOTICE, "Given clock source '%s' was accepted, but driver claims to use '%s'\n", clock_source, got_clock); soapy_close(); return -EINVAL; } @@ -173,9 +173,9 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg if (rx_frequency) { /* get number of channels and check if requested channel is in range */ num_channels = SoapySDRDevice_getNumChannels(sdr, SOAPY_SDR_RX); - PDEBUG(DSOAPY, DEBUG_DEBUG, "We have %d RX channel, selecting channel #%d\n", (int)num_channels, (int)channel); + LOGP(DSOAPY, LOGL_DEBUG, "We have %d RX channel, selecting channel #%d\n", (int)num_channels, (int)channel); if (channel >= num_channels) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Requested channel #%d (capable of RX) does not exist. Please select channel %d..%d!\n", (int)channel, 0, (int)num_channels - 1); + LOGP(DSOAPY, LOGL_ERROR, "Requested channel #%d (capable of RX) does not exist. Please select channel %d..%d!\n", (int)channel, 0, (int)num_channels - 1); soapy_close(); return -EIO; } @@ -188,26 +188,26 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg int i; antennas = SoapySDRDevice_listAntennas(sdr, SOAPY_SDR_RX, channel, &antennas_length); if (!antennas) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to request list of RX antennas!\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to request list of RX antennas!\n"); soapy_close(); return -EIO; } for (i = 0; i < (int)antennas_length; i++) - PDEBUG(DSOAPY, DEBUG_NOTICE, "RX Antenna: '%s'\n", antennas[i]); + LOGP(DSOAPY, LOGL_NOTICE, "RX Antenna: '%s'\n", antennas[i]); got_antenna = SoapySDRDevice_getAntenna(sdr, SOAPY_SDR_RX, channel); - PDEBUG(DSOAPY, DEBUG_NOTICE, "Default RX Antenna: '%s'\n", got_antenna); + LOGP(DSOAPY, LOGL_NOTICE, "Default RX Antenna: '%s'\n", got_antenna); soapy_close(); return 1; } if (SoapySDRDevice_setAntenna(sdr, SOAPY_SDR_RX, channel, rx_antenna) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set RX antenna to '%s'\n", rx_antenna); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set RX antenna to '%s'\n", rx_antenna); soapy_close(); return -EIO; } got_antenna = SoapySDRDevice_getAntenna(sdr, SOAPY_SDR_RX, channel); if (!!strcasecmp(rx_antenna, got_antenna)) { - PDEBUG(DSOAPY, DEBUG_NOTICE, "Given RX antenna '%s' was accepted, but driver claims to use '%s'\n", rx_antenna, got_antenna); + LOGP(DSOAPY, LOGL_NOTICE, "Given RX antenna '%s' was accepted, but driver claims to use '%s'\n", rx_antenna, got_antenna); soapy_close(); return -EINVAL; } @@ -215,7 +215,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* set rate */ if (SoapySDRDevice_setSampleRate(sdr, SOAPY_SDR_RX, channel, rate) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set RX rate to %.0f Hz\n", rate); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set RX rate to %.0f Hz\n", rate); soapy_close(); return -EIO; } @@ -223,7 +223,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what rate actually is */ got_rate = SoapySDRDevice_getSampleRate(sdr, SOAPY_SDR_RX, channel); if (fabs(got_rate - rate) > 1.0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Given RX rate %.3f Hz is not supported, try %.3f Hz\n", rate, got_rate); + LOGP(DSOAPY, LOGL_ERROR, "Given RX rate %.3f Hz is not supported, try %.3f Hz\n", rate, got_rate); soapy_close(); return -EINVAL; } @@ -231,7 +231,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg if (rx_gain) { /* set gain */ if (SoapySDRDevice_setGain(sdr, SOAPY_SDR_RX, channel, rx_gain) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set RX gain to %.0f\n", rx_gain); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set RX gain to %.0f\n", rx_gain); soapy_close(); return -EIO; } @@ -239,7 +239,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what gain actually is */ got_gain = SoapySDRDevice_getGain(sdr, SOAPY_SDR_RX, channel); if (fabs(got_gain - rx_gain) > 0.001) { - PDEBUG(DSOAPY, DEBUG_NOTICE, "Given RX gain %.3f is not supported, we use %.3f\n", rx_gain, got_gain); + LOGP(DSOAPY, LOGL_NOTICE, "Given RX gain %.3f is not supported, we use %.3f\n", rx_gain, got_gain); rx_gain = got_gain; } } @@ -250,7 +250,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* set frequency */ if (SoapySDRDevice_setFrequency(sdr, SOAPY_SDR_RX, channel, rx_frequency, &tune_args) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set RX frequency to %.0f Hz\n", rx_frequency); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set RX frequency to %.0f Hz\n", rx_frequency); soapy_close(); return -EIO; } @@ -258,14 +258,14 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what frequency actually is */ got_frequency = SoapySDRDevice_getFrequency(sdr, SOAPY_SDR_RX, channel); if (fabs(got_frequency - rx_frequency) > 100.0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Given RX frequency %.0f Hz is not supported, try %.0f Hz\n", rx_frequency, got_frequency); + LOGP(DSOAPY, LOGL_ERROR, "Given RX frequency %.0f Hz is not supported, try %.0f Hz\n", rx_frequency, got_frequency); soapy_close(); return -EINVAL; } /* set bandwidth */ if (SoapySDRDevice_setBandwidth(sdr, SOAPY_SDR_RX, channel, bandwidth) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); soapy_close(); return -EIO; } @@ -273,7 +273,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what bandwidth actually is */ got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_RX, channel); if (fabs(got_bandwidth - bandwidth) > 100.0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); + LOGP(DSOAPY, LOGL_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); soapy_close(); return -EINVAL; } @@ -285,7 +285,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg if (SoapySDRDevice_setupStream(sdr, &rxStream, SOAPY_SDR_RX, SOAPY_SDR_CF32, &channel, 1, &stream_args) != 0) #endif { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set RX streamer args\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set RX streamer args\n"); soapy_close(); return -EIO; } @@ -293,7 +293,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* get buffer sizes */ rx_samps_per_buff = SoapySDRDevice_getStreamMTU(sdr, rxStream); if (rx_samps_per_buff == 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to get RX streamer sample buffer\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to get RX streamer sample buffer\n"); soapy_close(); return -EIO; } @@ -302,9 +302,9 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg if (tx_frequency) { /* get number of channels and check if requested channel is in range */ num_channels = SoapySDRDevice_getNumChannels(sdr, SOAPY_SDR_TX); - PDEBUG(DSOAPY, DEBUG_DEBUG, "We have %d TX channel, selecting channel #%d\n", (int)num_channels, (int)channel); + LOGP(DSOAPY, LOGL_DEBUG, "We have %d TX channel, selecting channel #%d\n", (int)num_channels, (int)channel); if (channel >= num_channels) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Requested channel #%d (capable of TX) does not exist. Please select channel %d..%d!\n", (int)channel, 0, (int)num_channels - 1); + LOGP(DSOAPY, LOGL_ERROR, "Requested channel #%d (capable of TX) does not exist. Please select channel %d..%d!\n", (int)channel, 0, (int)num_channels - 1); soapy_close(); return -EIO; } @@ -317,26 +317,26 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg int i; antennas = SoapySDRDevice_listAntennas(sdr, SOAPY_SDR_TX, channel, &antennas_length); if (!antennas) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to request list of TX antennas!\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to request list of TX antennas!\n"); soapy_close(); return -EIO; } for (i = 0; i < (int)antennas_length; i++) - PDEBUG(DSOAPY, DEBUG_NOTICE, "TX Antenna: '%s'\n", antennas[i]); + LOGP(DSOAPY, LOGL_NOTICE, "TX Antenna: '%s'\n", antennas[i]); got_antenna = SoapySDRDevice_getAntenna(sdr, SOAPY_SDR_TX, channel); - PDEBUG(DSOAPY, DEBUG_NOTICE, "Default TX Antenna: '%s'\n", got_antenna); + LOGP(DSOAPY, LOGL_NOTICE, "Default TX Antenna: '%s'\n", got_antenna); soapy_close(); return 1; } if (SoapySDRDevice_setAntenna(sdr, SOAPY_SDR_TX, channel, tx_antenna) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set TX antenna to '%s'\n", tx_antenna); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set TX antenna to '%s'\n", tx_antenna); soapy_close(); return -EIO; } got_antenna = SoapySDRDevice_getAntenna(sdr, SOAPY_SDR_TX, channel); if (!!strcasecmp(tx_antenna, got_antenna)) { - PDEBUG(DSOAPY, DEBUG_NOTICE, "Given TX antenna '%s' was accepted, but driver claims to use '%s'\n", tx_antenna, got_antenna); + LOGP(DSOAPY, LOGL_NOTICE, "Given TX antenna '%s' was accepted, but driver claims to use '%s'\n", tx_antenna, got_antenna); soapy_close(); return -EINVAL; } @@ -344,7 +344,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* set rate */ if (SoapySDRDevice_setSampleRate(sdr, SOAPY_SDR_TX, channel, rate) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set TX rate to %.0f Hz\n", rate); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set TX rate to %.0f Hz\n", rate); soapy_close(); return -EIO; } @@ -352,7 +352,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what rate actually is */ got_rate = SoapySDRDevice_getSampleRate(sdr, SOAPY_SDR_TX, channel); if (fabs(got_rate - rate) > 1.0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Given TX rate %.3f Hz is not supported, try %.3f Hz\n", rate, got_rate); + LOGP(DSOAPY, LOGL_ERROR, "Given TX rate %.3f Hz is not supported, try %.3f Hz\n", rate, got_rate); soapy_close(); return -EINVAL; } @@ -360,7 +360,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg if (tx_gain) { /* set gain */ if (SoapySDRDevice_setGain(sdr, SOAPY_SDR_TX, channel, tx_gain) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set TX gain to %.0f\n", tx_gain); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set TX gain to %.0f\n", tx_gain); soapy_close(); return -EIO; } @@ -368,14 +368,14 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what gain actually is */ got_gain = SoapySDRDevice_getGain(sdr, SOAPY_SDR_TX, channel); if (fabs(got_gain - tx_gain) > 0.001) { - PDEBUG(DSOAPY, DEBUG_NOTICE, "Given TX gain %.3f is not supported, we use %.3f\n", tx_gain, got_gain); + LOGP(DSOAPY, LOGL_NOTICE, "Given TX gain %.3f is not supported, we use %.3f\n", tx_gain, got_gain); tx_gain = got_gain; } } /* set frequency */ if (SoapySDRDevice_setFrequency(sdr, SOAPY_SDR_TX, channel, tx_frequency, &tune_args) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set TX frequency to %.0f Hz\n", tx_frequency); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set TX frequency to %.0f Hz\n", tx_frequency); soapy_close(); return -EIO; } @@ -383,14 +383,14 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what frequency actually is */ got_frequency = SoapySDRDevice_getFrequency(sdr, SOAPY_SDR_TX, channel); if (fabs(got_frequency - tx_frequency) > 100.0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Given TX frequency %.0f Hz is not supported, try %.0f Hz\n", tx_frequency, got_frequency); + LOGP(DSOAPY, LOGL_ERROR, "Given TX frequency %.0f Hz is not supported, try %.0f Hz\n", tx_frequency, got_frequency); soapy_close(); return -EINVAL; } /* set bandwidth */ if (SoapySDRDevice_setBandwidth(sdr, SOAPY_SDR_TX, channel, bandwidth) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); soapy_close(); return -EIO; } @@ -398,7 +398,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* see what bandwidth actually is */ got_bandwidth = SoapySDRDevice_getBandwidth(sdr, SOAPY_SDR_TX, channel); if (fabs(got_bandwidth - bandwidth) > 100.0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); + LOGP(DSOAPY, LOGL_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); soapy_close(); return -EINVAL; } @@ -410,7 +410,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg if (SoapySDRDevice_setupStream(sdr, &txStream, SOAPY_SDR_TX, SOAPY_SDR_CF32, &channel, 1, &stream_args) != 0) #endif { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to set TX streamer args\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to set TX streamer args\n"); soapy_close(); return -EIO; } @@ -418,7 +418,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* get buffer sizes */ tx_samps_per_buff = SoapySDRDevice_getStreamMTU(sdr, txStream); if (tx_samps_per_buff == 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to get TX streamer sample buffer\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to get TX streamer sample buffer\n"); soapy_close(); return -EIO; } @@ -427,7 +427,7 @@ int soapy_open(size_t channel, const char *_device_args, const char *_stream_arg /* create mutex for time stamp protection */ rc = pthread_mutex_init(×tamp_mutex, NULL); if (rc < 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Mutex init failed!\n"); + LOGP(DSOAPY, LOGL_ERROR, "Mutex init failed!\n"); return rc; } @@ -439,13 +439,13 @@ int soapy_start(void) { /* enable rx stream */ if (SoapySDRDevice_activateStream(sdr, rxStream, 0, 0, 0) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to issue RX stream command\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to issue RX stream command\n"); return -EIO; } /* enable tx stream */ if (SoapySDRDevice_activateStream(sdr, txStream, 0, 0, 0) != 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "Failed to issue TX stream command\n"); + LOGP(DSOAPY, LOGL_ERROR, "Failed to issue TX stream command\n"); return -EIO; } return 0; @@ -453,7 +453,7 @@ int soapy_start(void) void soapy_close(void) { - PDEBUG(DSOAPY, DEBUG_DEBUG, "Clean up SoapySDR\n"); + LOGP(DSOAPY, LOGL_DEBUG, "Clean up SoapySDR\n"); if (txStream) { SoapySDRDevice_deactivateStream(sdr, txStream, 0, 0); SoapySDRDevice_closeStream(sdr, txStream); @@ -488,12 +488,12 @@ int soapy_send(float *buff, int num) flags |= SOAPY_SDR_HAS_TIME; count = SoapySDRDevice_writeStream(sdr, txStream, buffs_ptr, chunk, &flags, tx_timeNs, 1000000); if (count <= 0) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to write to TX streamer (error=%d)\n", count); + LOGP(DUHD, LOGL_ERROR, "Failed to write to TX streamer (error=%d)\n", count); break; } /* process TX time stamp */ if (!tx_valid) - PDEBUG(DSOAPY, DEBUG_ERROR, "SDR TX: tosend() was not called before, prease fix!\n"); + LOGP(DSOAPY, LOGL_ERROR, "SDR TX: tosend() was not called before, prease fix!\n"); else { pthread_mutex_lock(×tamp_mutex); tx_timeNs += count * Ns_per_sample; @@ -528,7 +528,7 @@ int soapy_receive(float *buff, int max) if (count > 0) { if (!use_time_stamps || !(flags & SOAPY_SDR_HAS_TIME)) { if (use_time_stamps) { - PDEBUG(DSOAPY, DEBUG_ERROR, "SDR RX: No time stamps available. This may cause little gaps and problems with time slot based networks, like C-Netz.\n"); + LOGP(DSOAPY, LOGL_ERROR, "SDR RX: No time stamps available. This may cause little gaps and problems with time slot based networks, like C-Netz.\n"); use_time_stamps = 0; } timeNs = rx_timeNs; @@ -540,7 +540,7 @@ int soapy_receive(float *buff, int max) } pthread_mutex_lock(×tamp_mutex); if (rx_timeNs != timeNs) - PDEBUG(DSOAPY, DEBUG_ERROR, "SDR RX overflow, seems we are too slow. Use lower SDR sample rate, if this happens too often.\n"); + LOGP(DSOAPY, LOGL_ERROR, "SDR RX overflow, seems we are too slow. Use lower SDR sample rate, if this happens too often.\n"); rx_timeNs = timeNs + count * Ns_per_sample; pthread_mutex_unlock(×tamp_mutex); /* commit received data to buffer */ @@ -579,7 +579,7 @@ int soapy_get_tosend(int buffer_size) /* in case of underrun */ if (tosend > buffer_size) { - PDEBUG(DSOAPY, DEBUG_ERROR, "SDR TX underrun, seems we are too slow. Use lower SDR sample rate.\n"); + LOGP(DSOAPY, LOGL_ERROR, "SDR TX underrun, seems we are too slow. Use lower SDR sample rate.\n"); tosend = buffer_size; } diff --git a/src/libsdr/uhd.c b/src/libsdr/uhd.c index c601828..0ffc90e 100644 --- a/src/libsdr/uhd.c +++ b/src/libsdr/uhd.c @@ -25,7 +25,7 @@ #include <uhd.h> #include <uhd/usrp/usrp.h> #include "uhd.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" extern int sdr_rx_overflow; @@ -56,15 +56,15 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, samplerate = rate; tx_timestamps = timestamps; - PDEBUG(DUHD, DEBUG_INFO, "Using device args \"%s\"\n", _device_args); - PDEBUG(DUHD, DEBUG_INFO, "Using stream args \"%s\"\n", _stream_args); - PDEBUG(DUHD, DEBUG_INFO, "Using tune args \"%s\"\n", _tune_args); + LOGP(DUHD, LOGL_INFO, "Using device args \"%s\"\n", _device_args); + LOGP(DUHD, LOGL_INFO, "Using stream args \"%s\"\n", _stream_args); + LOGP(DUHD, LOGL_INFO, "Using tune args \"%s\"\n", _tune_args); /* create USRP */ - PDEBUG(DUHD, DEBUG_INFO, "Creating USRP with args \"%s\"...\n", _device_args); + LOGP(DUHD, LOGL_INFO, "Creating USRP with args \"%s\"...\n", _device_args); error = uhd_usrp_make(&usrp, _device_args); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to create USRP\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to create USRP\n"); uhd_close(); return -EIO; } @@ -78,13 +78,13 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, error = uhd_string_vector_make(&clocks); if (error) { clock_vector_error: - PDEBUG(DUHD, DEBUG_ERROR, "Failed to handle UHD vector, please fix!\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to handle UHD vector, please fix!\n"); uhd_close(); return -EIO; } error = uhd_usrp_get_clock_sources(usrp, 0, &clocks); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to request list of clock sources!\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to request list of clock sources!\n"); uhd_close(); return -EIO; } @@ -95,33 +95,33 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, error = uhd_string_vector_at(clocks, i, got_clock, sizeof(got_clock)); if (error) goto clock_vector_error; - PDEBUG(DUHD, DEBUG_NOTICE, "Clock source: '%s'\n", got_clock); + LOGP(DUHD, LOGL_NOTICE, "Clock source: '%s'\n", got_clock); } uhd_string_vector_free(&clocks); error = uhd_usrp_get_clock_source(usrp, 0, got_clock, sizeof(got_clock)); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get clock source\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get clock source\n"); uhd_close(); return -EINVAL; } - PDEBUG(DUHD, DEBUG_NOTICE, "Default clock source: '%s'\n", got_clock); + LOGP(DUHD, LOGL_NOTICE, "Default clock source: '%s'\n", got_clock); uhd_close(); return 1; } error = uhd_usrp_set_clock_source(usrp, clock_source, 0); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set clock source to '%s'\n", clock_source); + LOGP(DUHD, LOGL_ERROR, "Failed to set clock source to '%s'\n", clock_source); uhd_close(); return -EIO; } error = uhd_usrp_get_clock_source(usrp, 0, got_clock, sizeof(got_clock)); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get clock source\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get clock source\n"); uhd_close(); return -EINVAL; } if (!!strcasecmp(clock_source, got_clock)) { - PDEBUG(DUHD, DEBUG_NOTICE, "Given clock source '%s' was accepted, but driver claims to use '%s'\n", clock_source, got_clock); + LOGP(DUHD, LOGL_NOTICE, "Given clock source '%s' was accepted, but driver claims to use '%s'\n", clock_source, got_clock); uhd_close(); return -EINVAL; } @@ -137,13 +137,13 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, error = uhd_string_vector_make(&antennas); if (error) { tx_vector_error: - PDEBUG(DUHD, DEBUG_ERROR, "Failed to handle UHD vector, please fix!\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to handle UHD vector, please fix!\n"); uhd_close(); return -EIO; } error = uhd_usrp_get_tx_antennas(usrp, channel, &antennas); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to request list of TX antennas!\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to request list of TX antennas!\n"); uhd_close(); return -EIO; } @@ -154,33 +154,33 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, error = uhd_string_vector_at(antennas, i, got_antenna, sizeof(got_antenna)); if (error) goto tx_vector_error; - PDEBUG(DUHD, DEBUG_NOTICE, "TX Antenna: '%s'\n", got_antenna); + LOGP(DUHD, LOGL_NOTICE, "TX Antenna: '%s'\n", got_antenna); } uhd_string_vector_free(&antennas); error = uhd_usrp_get_tx_antenna(usrp, channel, got_antenna, sizeof(got_antenna)); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX antenna\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX antenna\n"); uhd_close(); return -EINVAL; } - PDEBUG(DUHD, DEBUG_NOTICE, "Default TX Antenna: '%s'\n", got_antenna); + LOGP(DUHD, LOGL_NOTICE, "Default TX Antenna: '%s'\n", got_antenna); uhd_close(); return 1; } error = uhd_usrp_set_tx_antenna(usrp, tx_antenna, channel); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX antenna to '%s'\n", tx_antenna); + LOGP(DUHD, LOGL_ERROR, "Failed to set TX antenna to '%s'\n", tx_antenna); uhd_close(); return -EIO; } error = uhd_usrp_get_tx_antenna(usrp, channel, got_antenna, sizeof(got_antenna)); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX antenna\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX antenna\n"); uhd_close(); return -EINVAL; } if (!!strcasecmp(tx_antenna, got_antenna)) { - PDEBUG(DUHD, DEBUG_NOTICE, "Given TX antenna '%s' was accepted, but driver claims to use '%s'\n", tx_antenna, got_antenna); + LOGP(DUHD, LOGL_NOTICE, "Given TX antenna '%s' was accepted, but driver claims to use '%s'\n", tx_antenna, got_antenna); uhd_close(); return -EINVAL; } @@ -189,7 +189,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* create streamers */ error = uhd_tx_streamer_make(&tx_streamer); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to create TX streamer\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to create TX streamer\n"); uhd_close(); return -EIO; } @@ -197,7 +197,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* set rate */ error = uhd_usrp_set_tx_rate(usrp, rate, channel); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX rate to %.0f Hz\n", rate); + LOGP(DUHD, LOGL_ERROR, "Failed to set TX rate to %.0f Hz\n", rate); uhd_close(); return -EIO; } @@ -205,12 +205,12 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what rate actually is */ error = uhd_usrp_get_tx_rate(usrp, channel, &got_rate); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX rate\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX rate\n"); uhd_close(); return -EIO; } if (fabs(got_rate - rate) > 1.0) { - PDEBUG(DUHD, DEBUG_ERROR, "Given TX rate %.0f Hz is not supported, try %.0f Hz\n", rate, got_rate); + LOGP(DUHD, LOGL_ERROR, "Given TX rate %.0f Hz is not supported, try %.0f Hz\n", rate, got_rate); uhd_close(); return -EINVAL; } @@ -218,7 +218,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* set gain */ error = uhd_usrp_set_tx_gain(usrp, tx_gain, channel, ""); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX gain to %.0f\n", tx_gain); + LOGP(DUHD, LOGL_ERROR, "Failed to set TX gain to %.0f\n", tx_gain); uhd_close(); return -EIO; } @@ -226,12 +226,12 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what gain actually is */ error = uhd_usrp_get_tx_gain(usrp, channel, "", &got_gain); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX gain\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX gain\n"); uhd_close(); return -EIO; } if (fabs(got_gain - tx_gain) > 0.001) { - PDEBUG(DUHD, DEBUG_NOTICE, "Given TX gain %.0f is not supported, we use %.0f\n", tx_gain, got_gain); + LOGP(DUHD, LOGL_NOTICE, "Given TX gain %.0f is not supported, we use %.0f\n", tx_gain, got_gain); tx_gain = got_gain; } @@ -247,7 +247,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, tune_request.args = options_strdup(_tune_args); error = uhd_usrp_set_tx_freq(usrp, &tune_request, channel, &tune_result); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX frequency to %.0f Hz\n", tx_frequency); + LOGP(DUHD, LOGL_ERROR, "Failed to set TX frequency to %.0f Hz\n", tx_frequency); uhd_close(); return -EIO; } @@ -255,19 +255,19 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what frequency actually is */ error = uhd_usrp_get_tx_freq(usrp, channel, &got_frequency); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX frequency\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX frequency\n"); uhd_close(); return -EIO; } if (fabs(got_frequency - tx_frequency) > 100.0) { - PDEBUG(DUHD, DEBUG_ERROR, "Given TX frequency %.0f Hz is not supported, try %.0f Hz\n", tx_frequency, got_frequency); + LOGP(DUHD, LOGL_ERROR, "Given TX frequency %.0f Hz is not supported, try %.0f Hz\n", tx_frequency, got_frequency); uhd_close(); return -EINVAL; } /* set bandwidth */ if (uhd_usrp_set_tx_bandwidth(usrp, bandwidth, channel) != 0) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); + LOGP(DUHD, LOGL_ERROR, "Failed to set TX bandwidth to %.0f Hz\n", bandwidth); uhd_close(); return -EIO; } @@ -275,12 +275,12 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what bandwidth actually is */ error = uhd_usrp_get_tx_bandwidth(usrp, channel, &got_bandwidth); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX bandwidth\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX bandwidth\n"); uhd_close(); return -EIO; } if (fabs(got_bandwidth - bandwidth) > 100.0) { - PDEBUG(DUHD, DEBUG_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); + LOGP(DUHD, LOGL_ERROR, "Given TX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); uhd_close(); return -EINVAL; } @@ -294,7 +294,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, stream_args.n_channels = 1; error = uhd_usrp_get_tx_stream(usrp, &stream_args, tx_streamer); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX streamer args\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to set TX streamer args\n"); uhd_close(); return -EIO; } @@ -302,7 +302,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* get buffer sizes */ error = uhd_tx_streamer_max_num_samps(tx_streamer, &tx_samps_per_buff); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get TX streamer sample buffer\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get TX streamer sample buffer\n"); uhd_close(); return -EIO; } @@ -318,13 +318,13 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, error = uhd_string_vector_make(&antennas); if (error) { rx_vector_error: - PDEBUG(DUHD, DEBUG_ERROR, "Failed to handle UHD vector, please fix!\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to handle UHD vector, please fix!\n"); uhd_close(); return -EIO; } error = uhd_usrp_get_rx_antennas(usrp, channel, &antennas); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to request list of RX antennas!\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to request list of RX antennas!\n"); uhd_close(); return -EIO; } @@ -335,33 +335,33 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, error = uhd_string_vector_at(antennas, i, got_antenna, sizeof(got_antenna)); if (error) goto rx_vector_error; - PDEBUG(DUHD, DEBUG_NOTICE, "RX Antenna: '%s'\n", got_antenna); + LOGP(DUHD, LOGL_NOTICE, "RX Antenna: '%s'\n", got_antenna); } uhd_string_vector_free(&antennas); error = uhd_usrp_get_rx_antenna(usrp, channel, got_antenna, sizeof(got_antenna)); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX antenna\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX antenna\n"); uhd_close(); return -EINVAL; } - PDEBUG(DUHD, DEBUG_NOTICE, "Default RX Antenna: '%s'\n", got_antenna); + LOGP(DUHD, LOGL_NOTICE, "Default RX Antenna: '%s'\n", got_antenna); uhd_close(); return 1; } error = uhd_usrp_set_rx_antenna(usrp, rx_antenna, channel); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX antenna to '%s'\n", rx_antenna); + LOGP(DUHD, LOGL_ERROR, "Failed to set RX antenna to '%s'\n", rx_antenna); uhd_close(); return -EIO; } error = uhd_usrp_get_rx_antenna(usrp, channel, got_antenna, sizeof(got_antenna)); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX antenna\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX antenna\n"); uhd_close(); return -EINVAL; } if (!!strcasecmp(rx_antenna, got_antenna)) { - PDEBUG(DUHD, DEBUG_NOTICE, "Given RX antenna '%s' was accepted, but driver claims to use '%s'\n", rx_antenna, got_antenna); + LOGP(DUHD, LOGL_NOTICE, "Given RX antenna '%s' was accepted, but driver claims to use '%s'\n", rx_antenna, got_antenna); uhd_close(); return -EINVAL; } @@ -369,7 +369,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* create streamers */ error = uhd_rx_streamer_make(&rx_streamer); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to create RX streamer\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to create RX streamer\n"); uhd_close(); return -EIO; } @@ -377,7 +377,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* create metadata */ error = uhd_rx_metadata_make(&rx_metadata); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to create RX metadata\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to create RX metadata\n"); uhd_close(); return -EIO; } @@ -385,7 +385,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* set rate */ error = uhd_usrp_set_rx_rate(usrp, rate, channel); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX rate to %.0f Hz\n", rate); + LOGP(DUHD, LOGL_ERROR, "Failed to set RX rate to %.0f Hz\n", rate); uhd_close(); return -EIO; } @@ -393,12 +393,12 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what rate actually is */ error = uhd_usrp_get_rx_rate(usrp, channel, &got_rate); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX rate\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX rate\n"); uhd_close(); return -EIO; } if (fabs(got_rate - rate) > 1.0) { - PDEBUG(DUHD, DEBUG_ERROR, "Given RX rate %.0f Hz is not supported, try %.0f Hz\n", rate, got_rate); + LOGP(DUHD, LOGL_ERROR, "Given RX rate %.0f Hz is not supported, try %.0f Hz\n", rate, got_rate); uhd_close(); return -EINVAL; } @@ -406,7 +406,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* set gain */ error = uhd_usrp_set_rx_gain(usrp, rx_gain, channel, ""); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX gain to %.0f\n", rx_gain); + LOGP(DUHD, LOGL_ERROR, "Failed to set RX gain to %.0f\n", rx_gain); uhd_close(); return -EIO; } @@ -414,12 +414,12 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what gain actually is */ error = uhd_usrp_get_rx_gain(usrp, channel, "", &got_gain); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX gain\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX gain\n"); uhd_close(); return -EIO; } if (fabs(got_gain - rx_gain) > 0.001) { - PDEBUG(DUHD, DEBUG_NOTICE, "Given RX gain %.3f is not supported, we use %.3f\n", rx_gain, got_gain); + LOGP(DUHD, LOGL_NOTICE, "Given RX gain %.3f is not supported, we use %.3f\n", rx_gain, got_gain); rx_gain = got_gain; } @@ -435,7 +435,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, tune_request.args = options_strdup(_tune_args); error = uhd_usrp_set_rx_freq(usrp, &tune_request, channel, &tune_result); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX frequency to %.0f Hz\n", rx_frequency); + LOGP(DUHD, LOGL_ERROR, "Failed to set RX frequency to %.0f Hz\n", rx_frequency); uhd_close(); return -EIO; } @@ -443,19 +443,19 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what frequency actually is */ error = uhd_usrp_get_rx_freq(usrp, channel, &got_frequency); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX frequency\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX frequency\n"); uhd_close(); return -EIO; } if (fabs(got_frequency - rx_frequency) > 100.0) { - PDEBUG(DUHD, DEBUG_ERROR, "Given RX frequency %.0f Hz is not supported, try %.0f Hz\n", rx_frequency, got_frequency); + LOGP(DUHD, LOGL_ERROR, "Given RX frequency %.0f Hz is not supported, try %.0f Hz\n", rx_frequency, got_frequency); uhd_close(); return -EINVAL; } /* set bandwidth */ if (uhd_usrp_set_rx_bandwidth(usrp, bandwidth, channel) != 0) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); + LOGP(DUHD, LOGL_ERROR, "Failed to set RX bandwidth to %.0f Hz\n", bandwidth); uhd_close(); return -EIO; } @@ -463,12 +463,12 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* see what bandwidth actually is */ error = uhd_usrp_get_rx_bandwidth(usrp, channel, &got_bandwidth); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX bandwidth\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX bandwidth\n"); uhd_close(); return -EIO; } if (fabs(got_bandwidth - bandwidth) > 100.0) { - PDEBUG(DUHD, DEBUG_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); + LOGP(DUHD, LOGL_ERROR, "Given RX bandwidth %.0f Hz is not supported, try %.0f Hz\n", bandwidth, got_bandwidth); uhd_close(); return -EINVAL; } @@ -482,7 +482,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, stream_args.n_channels = 1; error = uhd_usrp_get_rx_stream(usrp, &stream_args, rx_streamer); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX streamer args\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to set RX streamer args\n"); uhd_close(); return -EIO; } @@ -490,7 +490,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args, /* get buffer sizes */ error = uhd_rx_streamer_max_num_samps(rx_streamer, &rx_samps_per_buff); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to get RX streamer sample buffer\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to get RX streamer sample buffer\n"); uhd_close(); return -EIO; } @@ -510,7 +510,7 @@ int uhd_start(void) stream_cmd.stream_now = true; error = uhd_rx_streamer_issue_stream_cmd(rx_streamer, &stream_cmd); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to issue RX stream command\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to issue RX stream command\n"); return -EIO; } return 0; @@ -518,7 +518,7 @@ int uhd_start(void) void uhd_close(void) { - PDEBUG(DUHD, DEBUG_DEBUG, "Clean up UHD\n"); + LOGP(DUHD, LOGL_DEBUG, "Clean up UHD\n"); if (tx_metadata) uhd_tx_metadata_free(&tx_metadata); if (rx_metadata) @@ -548,12 +548,12 @@ int uhd_send(float *buff, int num) else error = uhd_tx_metadata_make(&tx_metadata, false, 0, 0.0, false, false); if (error) - PDEBUG(DUHD, DEBUG_ERROR, "Failed to create TX metadata\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to create TX metadata\n"); buffs_ptr[0] = buff; count = 0; error = uhd_tx_streamer_send(tx_streamer, buffs_ptr, chunk, &tx_metadata, 1.0, &count); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to write to TX streamer\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to write to TX streamer\n"); break; } if (count == 0) @@ -595,7 +595,7 @@ int uhd_receive(float *buff, int max) count = 0; error = uhd_rx_streamer_recv(rx_streamer, buffs_ptr, rx_samps_per_buff, &rx_metadata, 0.0, false, &count); if (error) { - PDEBUG(DUHD, DEBUG_ERROR, "Failed to read from UHD device.\n"); + LOGP(DUHD, LOGL_ERROR, "Failed to read from UHD device.\n"); break; } if (count) { @@ -605,7 +605,7 @@ int uhd_receive(float *buff, int max) if (rc == 0 && has_time_spec) rc = uhd_rx_metadata_time_spec(rx_metadata, &rx_time_secs, &rx_time_fract_sec); if (rc < 0 || !has_time_spec) { - PDEBUG(DSOAPY, DEBUG_ERROR, "SDR RX: No time stamps available. This may cuse little gaps and problems with time slot based networks, like C-Netz.\n"); + LOGP(DSOAPY, LOGL_ERROR, "SDR RX: No time stamps available. This may cuse little gaps and problems with time slot based networks, like C-Netz.\n"); tx_timestamps = 0; } } @@ -657,7 +657,7 @@ int uhd_get_tosend(int buffer_size) advance = ((double)tx_time_secs + tx_time_fract_sec) - ((double)rx_time_secs + rx_time_fract_sec); /* in case of underrun: */ if (advance < 0) { - PDEBUG(DSOAPY, DEBUG_ERROR, "SDR TX underrun, seems we are too slow. Use lower SDR sample rate.\n"); + LOGP(DSOAPY, LOGL_ERROR, "SDR TX underrun, seems we are too slow. Use lower SDR sample rate.\n"); advance = 0; } tosend = buffer_size - (int)(advance * samplerate); diff --git a/src/libselect/Makefile.am b/src/libselect/Makefile.am deleted file mode 100644 index 76ff4d6..0000000 --- a/src/libselect/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) - -noinst_LIBRARIES = libselect.a - -libselect_a_SOURCES = \ - select.c diff --git a/src/libselect/select.c b/src/libselect/select.c deleted file mode 100644 index 3a4c0b1..0000000 --- a/src/libselect/select.c +++ /dev/null @@ -1,168 +0,0 @@ -/* Timer handling - * - * (C) 2023 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * Inspired by libosmocore - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <math.h> -#include <errno.h> -#include <string.h> -#include <sys/select.h> -#include <sys/time.h> -#include "select.h" - -//#define DEBUG - -#define MAX_OFD 1024 - -struct osmo_fd *ofd_list = NULL; -int ofd_changed = 0; - -int osmo_fd_register(struct osmo_fd *ofd) -{ - struct osmo_fd **ofdp; - - /* attach to list, if not already */ - ofdp = &ofd_list; - while (*ofdp) { - if (*ofdp == ofd) - break; - ofdp = &((*ofdp)->next); - } - if (!*ofdp) { -#ifdef DEBUG - fprintf(stderr, "%s: ofd=%p fd=%d registers.\n", __func__, ofd, ofd->fd); -#endif - ofd->next = NULL; - *ofdp = ofd; - ofd_changed = 1; - } - - return 0; -} - -void osmo_fd_unregister(struct osmo_fd *ofd) -{ - struct osmo_fd **ofdp; - - /* detach from list, if not already */ - ofdp = &ofd_list; - while (*ofdp) { - if (*ofdp == ofd) - break; - ofdp = &((*ofdp)->next); - } - if (*ofdp) { -#ifdef DEBUG - fprintf(stderr, "%s: ofd=%p fd=%d unregisters.\n", __func__, ofd, ofd->fd); -#endif - *ofdp = ofd->next; - ofd->next = NULL; - ofd_changed = 1; - } -} - -int osmo_fd_select(double timeout) -{ - fd_set readset; - fd_set writeset; - fd_set exceptset; - struct osmo_fd *ofd; - struct timeval tv; - int max_fd; - unsigned int what; - int work = 0; - int rc; - - /* init event sets */ - FD_ZERO(&readset); - FD_ZERO(&writeset); - FD_ZERO(&exceptset); - - /* populate event set with all file descriptios */ - ofd = ofd_list; - max_fd = 0; - while (ofd) { - if (ofd->fd > max_fd) - max_fd = ofd->fd; - if (ofd->when & OSMO_FD_READ) - FD_SET(ofd->fd, &readset); - if (ofd->when & OSMO_FD_WRITE) - FD_SET(ofd->fd, &writeset); - if (ofd->when & OSMO_FD_EXCEPT) - FD_SET(ofd->fd, &exceptset); - ofd = ofd->next; - } - - if (timeout >= 0) { - /* prepare timeout */ - tv.tv_sec = floor(timeout); - tv.tv_usec = (timeout - tv.tv_sec) * 1000000.0; - /* wait for event or timeout */ - rc = select(max_fd + 1, &readset, &writeset, &exceptset, &tv); - } else { - /* wait for event */ - rc = select(max_fd + 1, &readset, &writeset, &exceptset, NULL); - } - if (rc < 0) { - if (errno != EINTR) - fprintf(stderr, "%s: select() failed: '%d' with errno %d (%s) Please fix!\n", __func__, rc, errno, strerror(errno)); - return 0; - } - -again: - /* check the result and call handler */ - ofd_changed = 0; - ofd = ofd_list; - while (ofd) { - what = 0; - if (FD_ISSET(ofd->fd, &readset)) { -#ifdef DEBUG - fprintf(stderr, "%s: ofd=%p fd=%d get READ event.\n", __func__, ofd, ofd->fd); -#endif - what |= OSMO_FD_READ; - FD_CLR(ofd->fd, &readset); - } - if (FD_ISSET(ofd->fd, &writeset)) { -#ifdef DEBUG - fprintf(stderr, "%s: ofd=%p fd=%d get WRITE event.\n", __func__, ofd, ofd->fd); -#endif - what |= OSMO_FD_WRITE; - FD_CLR(ofd->fd, &writeset); - } - if (FD_ISSET(ofd->fd, &exceptset)) { -#ifdef DEBUG - fprintf(stderr, "%s: ofd=%p fd=%d get EXCEPTION event.\n", __func__, ofd, ofd->fd); -#endif - what |= OSMO_FD_EXCEPT; - FD_CLR(ofd->fd, &exceptset); - } - if (what) { - work = 1; - ofd->cb(ofd, what); - /* list has changed */ - if (ofd_changed) - goto again; - } - ofd = ofd->next; - } - - return work; -} - diff --git a/src/libselect/select.h b/src/libselect/select.h deleted file mode 100644 index def1000..0000000 --- a/src/libselect/select.h +++ /dev/null @@ -1,20 +0,0 @@ - -#define OSMO_FD_READ 0x0001 -#define OSMO_FD_WRITE 0x0002 -#define OSMO_FD_EXCEPT 0x0004 -#define BSC_FD_READ 0x0001 -#define BSC_FD_WRITE 0x0002 -#define BSC_FD_EXCEPT 0x0004 - -struct osmo_fd { - struct osmo_fd *next; - int fd; - unsigned int when; - int (*cb)(struct osmo_fd *fd, unsigned int what); - void *data; -}; - -int osmo_fd_register(struct osmo_fd *ofd); -void osmo_fd_unregister(struct osmo_fd *ofd); -int osmo_fd_select(double timeout); - diff --git a/src/libsound/sound_alsa.c b/src/libsound/sound_alsa.c index bb7151b..ca743f1 100644 --- a/src/libsound/sound_alsa.c +++ b/src/libsound/sound_alsa.c @@ -22,7 +22,7 @@ #include <math.h> #include <alsa/asoundlib.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #ifdef HAVE_MOBILE #include "../libmobile/sender.h" #else @@ -54,42 +54,42 @@ static int set_hw_params(snd_pcm_t *handle, int samplerate, int *channels) rc = snd_pcm_hw_params_malloc(&hw_params); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to allocate hw_params! (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "Failed to allocate hw_params! (%s)\n", snd_strerror(rc)); goto error; } rc = snd_pcm_hw_params_any(handle, hw_params); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot initialize hardware parameter structure (%s)\n", snd_strerror(rc)); goto error; } rc = snd_pcm_hw_params_set_rate_resample(handle, hw_params, 0); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot set real hardware rate (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot set real hardware rate (%s)\n", snd_strerror(rc)); goto error; } rc = snd_pcm_hw_params_set_access (handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot set access to interleaved (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot set access to interleaved (%s)\n", snd_strerror(rc)); goto error; } rc = snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot set sample format (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot set sample format (%s)\n", snd_strerror(rc)); goto error; } rrate = samplerate; rc = snd_pcm_hw_params_set_rate_near(handle, hw_params, &rrate, 0); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot set sample rate (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot set sample rate (%s)\n", snd_strerror(rc)); goto error; } if ((int)rrate != samplerate) { - PDEBUG(DSOUND, DEBUG_ERROR, "Rate doesn't match (requested %dHz, get %dHz)\n", samplerate, rrate); + LOGP(DSOUND, LOGL_ERROR, "Rate doesn't match (requested %dHz, get %dHz)\n", samplerate, rrate); rc = -EIO; goto error; } @@ -100,14 +100,14 @@ static int set_hw_params(snd_pcm_t *handle, int samplerate, int *channels) *channels = 2; rc = snd_pcm_hw_params_set_channels(handle, hw_params, *channels); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot set channel count to 1 nor 2 (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot set channel count to 1 nor 2 (%s)\n", snd_strerror(rc)); goto error; } } rc = snd_pcm_hw_params(handle, hw_params); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot set parameters (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot set parameters (%s)\n", snd_strerror(rc)); goto error; } @@ -130,51 +130,51 @@ static int dev_open(sound_t *sound) rc_play = snd_pcm_open(&sound->phandle, sound->audiodev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); rc_rec = snd_pcm_open(&sound->chandle, sound->audiodev, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); if (rc_play < 0 && rc_rec < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to open '%s'! (%s)\n", sound->audiodev, snd_strerror(rc_play)); - PDEBUG(DSOUND, DEBUG_ERROR, "Run 'aplay -l' to get a list of available cards and devices.\n"); - PDEBUG(DSOUND, DEBUG_ERROR, "Then use 'hw:<card>:<device>' for audio device.\n"); + LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s'! (%s)\n", sound->audiodev, snd_strerror(rc_play)); + LOGP(DSOUND, LOGL_ERROR, "Run 'aplay -l' to get a list of available cards and devices.\n"); + LOGP(DSOUND, LOGL_ERROR, "Then use 'hw:<card>:<device>' for audio device.\n"); return rc_play; } if (rc_play < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to open '%s' for playback! (%s) Please select a device that supports both direction audio.\n", sound->audiodev, snd_strerror(rc_play)); + LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s' for playback! (%s) Please select a device that supports both direction audio.\n", sound->audiodev, snd_strerror(rc_play)); return rc_play; } if (rc_rec < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to open '%s' for capture! (%s) Please select a device that supports both direction audio.\n", sound->audiodev, snd_strerror(rc_rec)); + LOGP(DSOUND, LOGL_ERROR, "Failed to open '%s' for capture! (%s) Please select a device that supports both direction audio.\n", sound->audiodev, snd_strerror(rc_rec)); return rc_rec; } rc = set_hw_params(sound->phandle, sound->samplerate, &sound->pchannels); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to set playback hw params\n"); + LOGP(DSOUND, LOGL_ERROR, "Failed to set playback hw params\n"); return rc; } if (sound->pchannels < sound->channels) { - PDEBUG(DSOUND, DEBUG_ERROR, "Sound card only supports %d channel for playback.\n", sound->pchannels); + LOGP(DSOUND, LOGL_ERROR, "Sound card only supports %d channel for playback.\n", sound->pchannels); return rc; } - PDEBUG(DSOUND, DEBUG_DEBUG, "Playback with %d channels.\n", sound->pchannels); + LOGP(DSOUND, LOGL_DEBUG, "Playback with %d channels.\n", sound->pchannels); rc = set_hw_params(sound->chandle, sound->samplerate, &sound->cchannels); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to set capture hw params\n"); + LOGP(DSOUND, LOGL_ERROR, "Failed to set capture hw params\n"); return rc; } if (sound->cchannels < sound->channels) { - PDEBUG(DSOUND, DEBUG_ERROR, "Sound card only supports %d channel for capture.\n", sound->cchannels); + LOGP(DSOUND, LOGL_ERROR, "Sound card only supports %d channel for capture.\n", sound->cchannels); return -EIO; } - PDEBUG(DSOUND, DEBUG_DEBUG, "Capture with %d channels.\n", sound->cchannels); + LOGP(DSOUND, LOGL_DEBUG, "Capture with %d channels.\n", sound->cchannels); rc = snd_pcm_prepare(sound->phandle); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(rc)); return rc; } rc = snd_pcm_prepare(sound->chandle); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "cannot prepare audio interface for use (%s)\n", snd_strerror(rc)); return rc; } @@ -196,13 +196,13 @@ void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_freque int rc; if (channels < 1 || channels > 2) { - PDEBUG(DSOUND, DEBUG_ERROR, "Cannot use more than two channels with the same sound card!\n"); + LOGP(DSOUND, LOGL_ERROR, "Cannot use more than two channels with the same sound card!\n"); return NULL; } sound = calloc(1, sizeof(sound_t)); if (!sound) { - PDEBUG(DSOUND, DEBUG_ERROR, "Failed to alloc memory!\n"); + LOGP(DSOUND, LOGL_ERROR, "Failed to alloc memory!\n"); return NULL; } @@ -234,7 +234,7 @@ void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_freque if ((env = getenv("KEEP_FRAMES"))) { KEEP_FRAMES = atoi(env); - PDEBUG(DSOUND, DEBUG_NOTICE, "KEEP %d samples in RX buffer, to prevent corrupt read.\n", KEEP_FRAMES); + LOGP(DSOUND, LOGL_NOTICE, "KEEP %d samples in RX buffer, to prevent corrupt read.\n", KEEP_FRAMES); } return sound; @@ -377,7 +377,7 @@ int sound_write(void *inst, sample_t **samples, uint8_t __attribute__((unused)) rc = snd_pcm_writei(sound->phandle, buff, num); if (rc < 0) { - PDEBUG(DSOUND, DEBUG_ERROR, "failed to write audio to interface (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "failed to write audio to interface (%s)\n", snd_strerror(rc)); if (rc == -EPIPE) { dev_close(sound); rc = dev_open(sound); @@ -390,7 +390,7 @@ int sound_write(void *inst, sample_t **samples, uint8_t __attribute__((unused)) } if (rc != num) - PDEBUG(DSOUND, DEBUG_ERROR, "short write to audio interface, written %d bytes, got %d bytes\n", num, rc); + LOGP(DSOUND, LOGL_ERROR, "short write to audio interface, written %d bytes, got %d bytes\n", num, rc); return rc; } @@ -423,7 +423,7 @@ int sound_read(void *inst, sample_t **samples, int num, int channels, double *rf if (rc < 0) { if (errno == EAGAIN) return 0; - PDEBUG(DSOUND, DEBUG_ERROR, "failed to read audio from interface (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "failed to read audio from interface (%s)\n", snd_strerror(rc)); /* recover read */ if (rc == -EPIPE) { dev_close(sound); @@ -505,9 +505,9 @@ int sound_get_tosend(void *inst, int buffer_size) rc = snd_pcm_delay(sound->phandle, &delay); if (rc < 0) { if (rc == -32) - PDEBUG(DSOUND, DEBUG_ERROR, "Buffer underrun: Please use higher buffer and enable real time scheduling\n"); + LOGP(DSOUND, LOGL_ERROR, "Buffer underrun: Please use higher buffer and enable real time scheduling\n"); else - PDEBUG(DSOUND, DEBUG_ERROR, "failed to get delay from interface (%s)\n", snd_strerror(rc)); + LOGP(DSOUND, LOGL_ERROR, "failed to get delay from interface (%s)\n", snd_strerror(rc)); if (rc == -EPIPE) { dev_close(sound); rc = dev_open(sound); diff --git a/src/libsquelch/squelch.c b/src/libsquelch/squelch.c index ced2a79..5402ebb 100644 --- a/src/libsquelch/squelch.c +++ b/src/libsquelch/squelch.c @@ -20,7 +20,7 @@ #include <string.h> #include <math.h> #include <stdint.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "squelch.h" #define CHAN squelch->kanal @@ -59,11 +59,11 @@ void squelch_init(squelch_t *squelch, const char *kanal, double threshold_db, do /* measure noise floor for auto threshold mode */ if (threshold_db == 0.0) { /* automatic threshold */ - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal squelch: Use automatic threshold\n"); + LOGP_CHAN(DDSP, LOGL_INFO, "RF signal squelch: Use automatic threshold\n"); squelch->auto_state = 1; } else if (!isinf(threshold_db)) { /* preset threshold */ - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal squelch: Use preset threshold of %.1f dB\n", threshold_db); + LOGP_CHAN(DDSP, LOGL_INFO, "RF signal squelch: Use preset threshold of %.1f dB\n", threshold_db); } /* squelch is mute on init */ squelch->mute_time = mute_time; @@ -97,7 +97,7 @@ enum squelch_result squelch(squelch_t *squelch, double rf_level_db, double durat /* must be 0.1 dB smaller, so we prevent repeated debugging message with similar value */ if (threshold_db < squelch->threshold_db - 0.1) { squelch->threshold_db = threshold_db; - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal measurement: %.1f dB noise floor, using squelch threshold of %.1f dB\n", noise_db, threshold_db); + LOGP_CHAN(DDSP, LOGL_INFO, "RF signal measurement: %.1f dB noise floor, using squelch threshold of %.1f dB\n", noise_db, threshold_db); } squelch->auto_count = 0.0; squelch->auto_level_count = 0; @@ -110,7 +110,7 @@ enum squelch_result squelch(squelch_t *squelch, double rf_level_db, double durat squelch->mute_count -= duration; if (squelch->mute_count <= 0.0) { if (squelch->mute_state) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal strong: Unmuting audio (RF %.1f >= %.1f dB)\n", rf_level_db, squelch->threshold_db); + LOGP_CHAN(DDSP, LOGL_INFO, "RF signal strong: Unmuting audio (RF %.1f >= %.1f dB)\n", rf_level_db, squelch->threshold_db); squelch->mute_state = 0; } squelch->mute_count = 0.0; @@ -120,7 +120,7 @@ enum squelch_result squelch(squelch_t *squelch, double rf_level_db, double durat squelch->mute_count += duration; if (squelch->mute_count >= squelch->mute_time) { if (!squelch->mute_state) { - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RF signal weak: Muting audio (RF %.1f < %.1f dB)\n", rf_level_db, squelch->threshold_db); + LOGP_CHAN(DDSP, LOGL_INFO, "RF signal weak: Muting audio (RF %.1f < %.1f dB)\n", rf_level_db, squelch->threshold_db); squelch->mute_state = 1; } squelch->mute_count = squelch->mute_time; @@ -132,7 +132,7 @@ enum squelch_result squelch(squelch_t *squelch, double rf_level_db, double durat squelch->loss_count += duration; if (squelch->loss_count >= squelch->loss_time) { if (!squelch->loss_state) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "RF signal loss detected after %.1f seconds\n", squelch->loss_time); + LOGP_CHAN(DDSP, LOGL_DEBUG, "RF signal loss detected after %.1f seconds\n", squelch->loss_time); squelch->loss_state = 1; return SQUELCH_LOSS; } diff --git a/src/libtimer/Makefile.am b/src/libtimer/Makefile.am deleted file mode 100644 index 538670a..0000000 --- a/src/libtimer/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -AM_CPPFLAGS = -Wall -Wextra -g $(all_includes) - -noinst_LIBRARIES = libtimer.a - -libtimer_a_SOURCES = \ - timer.c diff --git a/src/libtimer/timer.c b/src/libtimer/timer.c deleted file mode 100644 index a5fa85c..0000000 --- a/src/libtimer/timer.c +++ /dev/null @@ -1,165 +0,0 @@ -/* Timer handling - * - * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu> - * All Rights Reserved - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -//#include <sys/time.h> -#include <time.h> -#include <errno.h> -#include "timer.h" - -//#define DEBUG - -static struct timer *timer_head = NULL; -static struct timer **timer_tail_p = &timer_head; - -double get_time(void) -{ - static struct timespec tv; - - clock_gettime(CLOCK_REALTIME, &tv); - - return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000.0; -} - -void timer_init(struct timer *timer, void (*fn)(void *data), void *priv) -{ - if (timer->linked) { - fprintf(stderr, "Timer is already initialized, aborting!\n"); - abort(); - } - - timer->timeout = 0; - timer->cb = fn; - timer->data = priv; - timer->next = NULL; - *timer_tail_p = timer; - timer_tail_p = &timer->next; - timer->linked = 1; -#ifdef DEBUG - fprintf(stderr, "%s: timer=%p linked.\n", __func__, timer); -#endif -} - -void timer_exit(struct timer *timer) -{ - timer_tail_p = &timer_head; - while (*timer_tail_p) { - if (timer == *timer_tail_p) - *timer_tail_p = (*timer_tail_p)->next; - else - timer_tail_p = &((*timer_tail_p)->next); - } - timer->linked = 0; -#ifdef DEBUG - fprintf(stderr, "%s: timer=%p unlinked.\n", __func__, timer); -#endif -} - -void timer_start(struct timer *timer, double duration) -{ - if (!timer->linked) { - fprintf(stderr, "Timer is not initialized, aborting!\n"); - abort(); - } - - timer->duration = duration; - timer->timeout = get_time() + duration; -#ifdef DEBUG - fprintf(stderr, "%s: timer=%p started %.3f seconds.\n", __func__, timer, duration); -#endif -} - -void timer_stop(struct timer *timer) -{ - if (!timer->linked) { - fprintf(stderr, "Timer is not initialized, aborting!\n"); - abort(); - } - - timer->timeout = 0; -#ifdef DEBUG - fprintf(stderr, "%s: timer=%p stopped.\n", __func__, timer); -#endif -} - -int timer_running(struct timer *timer) -{ - if (!timer->linked) { - fprintf(stderr, "Timer is not initialized, aborting!\n"); - abort(); - } - - return (timer->timeout != 0); -} - -double process_timer(void) -{ - struct timer *timer; - double now, timeout = -1.0; - - now = get_time(); - -again: - timer = timer_head; - while (timer) { - if (timer->linked && timer->timeout > 0) { - /* timeout, handle it, set timeout to 0 */ - if (now >= timer->timeout) { - timer->timeout = 0; -#ifdef DEBUG - fprintf(stderr, "%s: timer=%p fired.\n", __func__, timer); -#endif - if (!timer->cb) - abort(); - timer->cb(timer->data); - timeout = 0.0; - goto again; - } - /* in the future, set timeout to future */ - if (timeout < 0.0 || (timer->timeout - now) < timeout) - timeout = timer->timeout - now; - } - timer = timer->next; - } - - return timeout; -} - -void osmo_timer_schedule(struct osmo_timer_list *ti, time_t sec, suseconds_t usec) -{ - if (!ti->linked) - timer_init(ti, ti->cb, ti->data); - timer_start(ti, (double)sec + (double)usec / 1000000.0); -} - -void osmo_timer_del(struct osmo_timer_list *ti) -{ - timer_exit(ti); -} - -int osmo_timer_pending(struct osmo_timer_list *ti) -{ - if (!ti->linked) - return 0; - return (ti->timeout != 0); -} - diff --git a/src/libtimer/timer.h b/src/libtimer/timer.h deleted file mode 100644 index f7dbbbc..0000000 --- a/src/libtimer/timer.h +++ /dev/null @@ -1,23 +0,0 @@ - -struct timer { - struct timer *next; - int linked; /* set is timer is initialized and linked */ - double duration; - double timeout; - void (*cb)(void *data); - void *data; -}; - -double get_time(void); -void timer_init(struct timer *timer, void (*fn)(void *data), void *priv); -void timer_exit(struct timer *timer); -void timer_start(struct timer *timer, double duration); -void timer_stop(struct timer *timer); -int timer_running(struct timer *timer); -double process_timer(void); - -#define osmo_timer_list timer -void osmo_timer_schedule(struct osmo_timer_list *ti, time_t sec, long usec); -void osmo_timer_del(struct osmo_timer_list *ti); -int osmo_timer_pending(struct osmo_timer_list *ti); - diff --git a/src/libv27/modem.c b/src/libv27/modem.c index fbcd448..aba8b97 100644 --- a/src/libv27/modem.c +++ b/src/libv27/modem.c @@ -20,7 +20,7 @@ #include <stdio.h> #include <stdint.h> #include <string.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libsample/sample.h" #include "modem.h" diff --git a/src/libv27/psk.c b/src/libv27/psk.c index c20f286..a98f154 100644 --- a/src/libv27/psk.c +++ b/src/libv27/psk.c @@ -23,7 +23,7 @@ #include <string.h> #include <errno.h> #include <math.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libsample/sample.h" #include "psk.h" @@ -93,18 +93,18 @@ int psk_mod_init(psk_mod_t *psk, void *inst, int (*send_bit)(void *inst), int sa sample_t spl; if (samplerate != 48000) { - PDEBUG(DDSP, DEBUG_NOTICE, "Sampling rate for PSK encoder must be exactly 48000 Hz!\n"); + LOGP(DDSP, LOGL_NOTICE, "Sampling rate for PSK encoder must be exactly 48000 Hz!\n"); return -EINVAL; } if (symbolrate != 1600) { - PDEBUG(DDSP, DEBUG_NOTICE, "Symbol rate for PSK encoder must be exactly 1600 Hz!\n"); + LOGP(DDSP, LOGL_NOTICE, "Symbol rate for PSK encoder must be exactly 1600 Hz!\n"); return -EINVAL; } cutoff = 3300.0; transitionband = 200; psk->lp[0] = fir_lowpass_init((double)samplerate, cutoff, transitionband); - PDEBUG(DDSP, DEBUG_DEBUG, "Cut off frequency is at %.1f Hz and %.1f Hz.\n", TX_CARRIER + cutoff, TX_CARRIER - cutoff); + LOGP(DDSP, LOGL_DEBUG, "Cut off frequency is at %.1f Hz and %.1f Hz.\n", TX_CARRIER + cutoff, TX_CARRIER - cutoff); /* interpolate symbol table from 9600 Hz to 48000 Hz */ for (i = 0; i < 8; i++) { @@ -119,7 +119,7 @@ int psk_mod_init(psk_mod_t *psk, void *inst, int (*send_bit)(void *inst), int sa } #else if (samplerate < 48000) { - PDEBUG(DDSP, DEBUG_NOTICE, "Sampling rate for PSK encoder must be 48000 Hz minimum!\n"); + LOGP(DDSP, LOGL_NOTICE, "Sampling rate for PSK encoder must be 48000 Hz minimum!\n"); return -EINVAL; } @@ -128,13 +128,13 @@ int psk_mod_init(psk_mod_t *psk, void *inst, int (*send_bit)(void *inst), int sa transitionband = 200; psk->lp[0] = fir_lowpass_init((double)samplerate, cutoff, transitionband); psk->lp[1] = fir_lowpass_init((double)samplerate, cutoff, transitionband); - PDEBUG(DDSP, DEBUG_DEBUG, "Cut off frequency is at %.1f Hz and %.1f Hz.\n", TX_CARRIER + cutoff, TX_CARRIER - cutoff); + LOGP(DDSP, LOGL_DEBUG, "Cut off frequency is at %.1f Hz and %.1f Hz.\n", TX_CARRIER + cutoff, TX_CARRIER - cutoff); psk->symbols_per_sample = symbolrate / (double)samplerate; - PDEBUG(DDSP, DEBUG_DEBUG, "Symbol duration of %.4f symbols per sample @ %d.\n", psk->symbols_per_sample, samplerate); + LOGP(DDSP, LOGL_DEBUG, "Symbol duration of %.4f symbols per sample @ %d.\n", psk->symbols_per_sample, samplerate); psk->carrier_phaseshift = 2.0 * M_PI * TX_CARRIER / (double)samplerate; - PDEBUG(DDSP, DEBUG_DEBUG, "Carrier phase shift of %.4f per sample @ %d.\n", psk->carrier_phaseshift, samplerate); + LOGP(DDSP, LOGL_DEBUG, "Carrier phase shift of %.4f per sample @ %d.\n", psk->carrier_phaseshift, samplerate); #endif return 0; @@ -237,7 +237,7 @@ int psk_demod_init(psk_demod_t *psk, void *inst, void (*receive_bit)(void *inst, double cutoff, transitionband; if (samplerate < 48000) { - PDEBUG(DDSP, DEBUG_NOTICE, "Sampling rate for PSK decoder must be 48000 Hz minimum!\n"); + LOGP(DDSP, LOGL_NOTICE, "Sampling rate for PSK decoder must be 48000 Hz minimum!\n"); return -EINVAL; } @@ -256,10 +256,10 @@ int psk_demod_init(psk_demod_t *psk, void *inst, void (*receive_bit)(void *inst, iir_lowpass_init(&psk->lp_error[1], 50.0, samplerate, 2); iir_bandpass_init(&psk->lp_clock, symbolrate, samplerate, 40); psk->sample_delay = (int)floor((double)samplerate / symbolrate * 0.25); /* percent of sine duration behind zero crossing */ - PDEBUG(DDSP, DEBUG_DEBUG, "Cut off frequency is at %.1f Hz and %.1f Hz.\n", RX_CARRIER + cutoff, RX_CARRIER - cutoff); + LOGP(DDSP, LOGL_DEBUG, "Cut off frequency is at %.1f Hz and %.1f Hz.\n", RX_CARRIER + cutoff, RX_CARRIER - cutoff); psk->carrier_phaseshift = 2.0 * M_PI * -RX_CARRIER / (double)samplerate; - PDEBUG(DDSP, DEBUG_DEBUG, "Carrier phase shift of %.4f per sample @ %d.\n", psk->carrier_phaseshift, samplerate); + LOGP(DDSP, LOGL_DEBUG, "Carrier phase shift of %.4f per sample @ %d.\n", psk->carrier_phaseshift, samplerate); return 0; } diff --git a/src/libwave/wave.c b/src/libwave/wave.c index 50c2c96..57cd7b3 100644 --- a/src/libwave/wave.c +++ b/src/libwave/wave.c @@ -25,7 +25,7 @@ #include <unistd.h> #include <pthread.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "wave.h" /* NOTE: No locking required for writing and reading buffer pointers, since 'int' is atomic on >=32 bit machines */ @@ -52,7 +52,7 @@ static void *record_child(void *arg) /* quit on error */ if (len < 0) { error: - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to write to recording WAVE file! (errno %d)\n", errno); + LOGP(DWAVE, LOGL_ERROR, "Failed to write to recording WAVE file! (errno %d)\n", errno); rec->finish = 1; return NULL; } @@ -88,7 +88,7 @@ static void *playback_child(void *arg) len = fread(play->buffer + play->buffer_writep, 1, to_read, play->fp); /* quit on error */ if (len < 0) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to read from playback WAVE file! (errno %d)\n", errno); + LOGP(DWAVE, LOGL_ERROR, "Failed to read from playback WAVE file! (errno %d)\n", errno); play->finish = 1; return NULL; } @@ -129,7 +129,7 @@ int wave_create_record(wave_rec_t *rec, const char *filename, int samplerate, in rec->fp = fopen(filename, "w"); if (!rec->fp) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to open recording file '%s'! (errno %d)\n", filename, errno); + LOGP(DWAVE, LOGL_ERROR, "Failed to open recording file '%s'! (errno %d)\n", filename, errno); return -errno; } @@ -139,18 +139,18 @@ int wave_create_record(wave_rec_t *rec, const char *filename, int samplerate, in rec->buffer_size = samplerate * 2 * channels; rec->buffer = calloc(rec->buffer_size, 1); if (!rec->buffer) { - PDEBUG(DWAVE, DEBUG_NOTICE, "No mem!\n"); + LOGP(DWAVE, LOGL_NOTICE, "No mem!\n"); rc = ENOMEM; goto error; } rc = pthread_create(&rec->tid, NULL, record_child, rec); if (rc < 0) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to create thread to record WAVE file! (errno %d)\n", errno); + LOGP(DWAVE, LOGL_ERROR, "Failed to create thread to record WAVE file! (errno %d)\n", errno); goto error; } - PDEBUG(DWAVE, DEBUG_NOTICE, "*** Writing WAVE file to %s.\n", filename); + LOGP(DWAVE, LOGL_NOTICE, "*** Writing WAVE file to %s.\n", filename); return 0; @@ -180,50 +180,50 @@ int wave_create_playback(wave_play_t *play, const char *filename, int *samplerat play->fp = fopen(filename, "r"); if (!play->fp) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to open playback file '%s'! (errno %d)\n", filename, errno); + LOGP(DWAVE, LOGL_ERROR, "Failed to open playback file '%s'! (errno %d)\n", filename, errno); return -errno; } len = fread(buffer, 1, 12, play->fp); if (len != 12) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to read RIFF header!\n"); + LOGP(DWAVE, LOGL_ERROR, "Failed to read RIFF header!\n"); rc = -EIO; goto error; } if (!!strncmp((char *)buffer, "RIFF", 4)) { - PDEBUG(DWAVE, DEBUG_ERROR, "Missing RIFF header, seems that this is no WAVE file!\n"); + LOGP(DWAVE, LOGL_ERROR, "Missing RIFF header, seems that this is no WAVE file!\n"); rc = -EINVAL; goto error; } size = buffer[4] + (buffer[5] << 8) + (buffer[6] << 16) + (buffer[7] << 24); if (!!strncmp((char *)buffer + 8, "WAVE", 4)) { - PDEBUG(DWAVE, DEBUG_ERROR, "Missing WAVE header, seems that this is no WAVE file!\n"); + LOGP(DWAVE, LOGL_ERROR, "Missing WAVE header, seems that this is no WAVE file!\n"); rc = -EINVAL; goto error; } size -= 4; while (size) { if (size < 8) { - PDEBUG(DWAVE, DEBUG_ERROR, "Short read of WAVE file!\n"); + LOGP(DWAVE, LOGL_ERROR, "Short read of WAVE file!\n"); rc = -EINVAL; goto error; } len = fread(buffer, 1, 8, play->fp); if (len != 8) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to read chunk of WAVE file!\n"); + LOGP(DWAVE, LOGL_ERROR, "Failed to read chunk of WAVE file!\n"); rc = -EIO; goto error; } chunk = buffer[4] + (buffer[5] << 8) + (buffer[6] << 16) + (buffer[7] << 24); size -= 8 + chunk; if (size < 0) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: Chunk '%c%c%c%c' overflows file size!\n", buffer[4], buffer[5], buffer[6], buffer[7]); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: Chunk '%c%c%c%c' overflows file size!\n", buffer[4], buffer[5], buffer[6], buffer[7]); rc = -EIO; goto error; } if (!strncmp((char *)buffer, "fmt ", 4)) { if (chunk < 16 || chunk > (int)sizeof(buffer)) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: Short or corrupt 'fmt' chunk!\n"); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: Short or corrupt 'fmt' chunk!\n"); rc = -EINVAL; goto error; } @@ -238,7 +238,7 @@ int wave_create_playback(wave_play_t *play, const char *filename, int *samplerat } else if (!strncmp((char *)buffer, "data", 4)) { if (!gotfmt) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: 'data' without 'fmt' chunk!\n"); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: 'data' without 'fmt' chunk!\n"); rc = -EINVAL; goto error; } @@ -255,42 +255,42 @@ int wave_create_playback(wave_play_t *play, const char *filename, int *samplerat } if (!gotfmt || !gotdata) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: Missing 'data' or 'fmt' chunk!\n"); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: Missing 'data' or 'fmt' chunk!\n"); rc = -EINVAL; goto error; } if (fmt.format != 1) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: We support only PCM files!\n"); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: We support only PCM files!\n"); rc = -EINVAL; goto error; } if (*channels_p == 0) *channels_p = fmt.channels; if (fmt.channels != *channels_p) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: We expect %d cannel(s), but wave file only has %d channel(s)\n", *channels_p, fmt.channels); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: We expect %d cannel(s), but wave file only has %d channel(s)\n", *channels_p, fmt.channels); rc = -EINVAL; goto error; } if (*samplerate_p == 0) *samplerate_p = fmt.sample_rate; if ((int)fmt.sample_rate != *samplerate_p) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: The WAVE file's sample rate (%d) does not match our sample rate (%d)!\n", fmt.sample_rate, *samplerate_p); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: The WAVE file's sample rate (%d) does not match our sample rate (%d)!\n", fmt.sample_rate, *samplerate_p); rc = -EINVAL; goto error; } if ((int)fmt.data_rate != 2 * *channels_p * *samplerate_p) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: The WAVE file's data rate is only %d bytes per second, but we expect %d bytes per second (2 bytes per sample * channels * samplerate)!\n", fmt.data_rate, 2 * *channels_p * *samplerate_p); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: The WAVE file's data rate is only %d bytes per second, but we expect %d bytes per second (2 bytes per sample * channels * samplerate)!\n", fmt.data_rate, 2 * *channels_p * *samplerate_p); rc = -EINVAL; goto error; } if (fmt.bytes_sample != 2 * *channels_p) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: The WAVE file's bytes per sample is only %d, but we expect %d bytes sample (2 bytes per sample * channels)!\n", fmt.bytes_sample, 2 * *channels_p); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: The WAVE file's bytes per sample is only %d, but we expect %d bytes sample (2 bytes per sample * channels)!\n", fmt.bytes_sample, 2 * *channels_p); rc = -EINVAL; goto error; } if (fmt.bits_sample != 16) { - PDEBUG(DWAVE, DEBUG_ERROR, "WAVE error: We support only 16 bit files!\n"); + LOGP(DWAVE, LOGL_ERROR, "WAVE error: We support only 16 bit files!\n"); rc = -EINVAL; goto error; } @@ -301,18 +301,18 @@ int wave_create_playback(wave_play_t *play, const char *filename, int *samplerat play->buffer_size = *samplerate_p * 2 * *channels_p; play->buffer = calloc(play->buffer_size, 1); if (!play->buffer) { - PDEBUG(DWAVE, DEBUG_ERROR, "No mem!\n"); + LOGP(DWAVE, LOGL_ERROR, "No mem!\n"); rc = -ENOMEM; goto error; } rc = pthread_create(&play->tid, NULL, playback_child, play); if (rc < 0) { - PDEBUG(DWAVE, DEBUG_ERROR, "Failed to create thread to playback WAVE file! (errno %d)\n", errno); + LOGP(DWAVE, LOGL_ERROR, "Failed to create thread to playback WAVE file! (errno %d)\n", errno); goto error; } - PDEBUG(DWAVE, DEBUG_NOTICE, "*** Reading WAVE file from %s.\n", filename); + LOGP(DWAVE, LOGL_NOTICE, "*** Reading WAVE file from %s.\n", filename); return 0; @@ -344,7 +344,7 @@ int wave_write(wave_rec_t *rec, sample_t **samples, int length) to_write = (rec->buffer_size + rec->buffer_readp - rec->buffer_writep - 1) % rec->buffer_size; to_write /= 2 * rec->channels; if (to_write < length) - PDEBUG(DWAVE, DEBUG_NOTICE, "Record WAVE buffer overflow.\n"); + LOGP(DWAVE, LOGL_NOTICE, "Record WAVE buffer overflow.\n"); else to_write = length; if (to_write == 0) @@ -398,7 +398,7 @@ read_empty: if (to_read == 0 && play->finish) { if (play->left) { - PDEBUG(DWAVE, DEBUG_NOTICE, "*** Finished reading WAVE file. (short read)\n"); + LOGP(DWAVE, LOGL_NOTICE, "*** Finished reading WAVE file. (short read)\n"); play->left = 0; } goto read_empty; @@ -418,7 +418,7 @@ read_empty: play->left -= to_read; if (!play->left) - PDEBUG(DWAVE, DEBUG_NOTICE, "*** Finished reading WAVE file.\n"); + LOGP(DWAVE, LOGL_NOTICE, "*** Finished reading WAVE file.\n"); if (to_read < length) goto read_empty; @@ -499,7 +499,7 @@ void wave_destroy_record(wave_rec_t *rec) fclose(rec->fp); rec->fp = NULL; - PDEBUG(DWAVE, DEBUG_NOTICE, "*** WAVE file written.\n"); + LOGP(DWAVE, LOGL_NOTICE, "*** WAVE file written.\n"); } void wave_destroy_playback(wave_play_t *play) diff --git a/src/magnetic/Makefile.am b/src/magnetic/Makefile.am index f5e9f83..6f9dcf7 100644 --- a/src/magnetic/Makefile.am +++ b/src/magnetic/Makefile.am @@ -10,10 +10,11 @@ cnetz_magnetic_SOURCES = \ cnetz_magnetic_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/liboptions/liboptions.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ -lm if HAVE_ALSA diff --git a/src/magnetic/main.c b/src/magnetic/main.c index 2d32231..fc757d8 100644 --- a/src/magnetic/main.c +++ b/src/magnetic/main.c @@ -29,7 +29,7 @@ #include "../libsample/sample.h" #include "../libsound/sound.h" #include "../libwave/wave.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "../libaaimage/aaimage.h" #include "iso7811.h" @@ -64,7 +64,7 @@ void print_help(const char *arg0) printf(" --config [~/]<path to config file>\n"); printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n"); printf(" Each line in config file is one option, '-' or '--' must not be given!\n"); - debug_print_help(); + logging_print_help(); printf(" -a --audio-device hw:<card>,<device>\n"); printf(" Input audio from sound card's device number\n"); printf(" -s --samplerate <sample rate>\n"); @@ -101,13 +101,11 @@ int handle_options(int short_option, int argi, char **argv) print_help(argv[0]); return 0; case 'v': - if (!strcasecmp(argv[argi], "list")) { - debug_list_cat(); + rc = parse_logging_opt(argv[argi]); + if (rc > 0) return 0; - } - rc = parse_debug_opt(argv[argi]); if (rc < 0) { - fprintf(stderr, "Failed to parse debug option, please use -h for help.\n"); + fprintf(stderr, "Failed to parse logging option, please use -h for help.\n"); return rc; } break; @@ -154,7 +152,8 @@ int main(int argc, char *argv[]) int rc, argi; int i, j; - debuglevel = DEBUG_INFO; + loglevel = LOGL_INFO; + logging_init(); add_options(); rc = options_config_file(argc, argv, "~/.osmocom/analog/magnetic.conf", handle_options); @@ -244,9 +243,9 @@ inval_number: } memset(silence, 0, sizeof(silence)); - PDEBUG(DDSP, DEBUG_INFO, "Total bits: %d\n", length * 5); - PDEBUG(DDSP, DEBUG_INFO, "Samples per bit: %d\n", samples_per_halfbit * 2); - PDEBUG(DDSP, DEBUG_INFO, "Total samples: %d (duration: %.3f seconds)\n", total_samples, (double)total_samples / (double)dsp_samplerate); + LOGP(DDSP, LOGL_INFO, "Total bits: %d\n", length * 5); + LOGP(DDSP, LOGL_INFO, "Samples per bit: %d\n", samples_per_halfbit * 2); + LOGP(DDSP, LOGL_INFO, "Total samples: %d (duration: %.3f seconds)\n", total_samples, (double)total_samples / (double)dsp_samplerate); if (wave_file) { wave_rec_t wave_rec; @@ -254,7 +253,7 @@ inval_number: /* open wave file */ rc = wave_create_record(&wave_rec, wave_file, dsp_samplerate, 1, 1.0); if (rc < 0) { - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to create WAVE record instance!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to create WAVE record instance!\n"); goto error; } samples[0] = silence; @@ -272,12 +271,12 @@ inval_number: sound = sound_open(dsp_audiodev, NULL, NULL, NULL, 1, 0.0, dsp_samplerate, buffer_size, 1.0, 1.0, 0.0, 2.0); if (!sound) { rc = -EIO; - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to open sound device!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to open sound device!\n"); goto error; } #else rc = -ENOTSUP; - PDEBUG(DRADIO, DEBUG_ERROR, "No sound card support compiled in!\n"); + LOGP(DRADIO, LOGL_ERROR, "No sound card support compiled in!\n"); goto error; #endif @@ -365,4 +364,6 @@ done: return 0; } +void osmo_cc_set_log_cat(void) {} + #endif /* ARDUINO */ diff --git a/src/mpt1327/Makefile.am b/src/mpt1327/Makefile.am index cfc2b1a..9ed25ab 100644 --- a/src/mpt1327/Makefile.am +++ b/src/mpt1327/Makefile.am @@ -12,15 +12,11 @@ mpt1327_LDADD = \ $(COMMON_LA) \ ../anetz/libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libsquelch/libsquelch.a \ $(top_builddir)/src/libdtmf/libdtmf.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfsk/libfsk.a \ @@ -28,8 +24,10 @@ mpt1327_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/mpt1327/dsp.c b/src/mpt1327/dsp.c index 066ce55..a402fbf 100644 --- a/src/mpt1327/dsp.c +++ b/src/mpt1327/dsp.c @@ -27,8 +27,8 @@ #include <math.h> #include "../libsample/sample.h" #include "../libmobile/call.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "mpt1327.h" #include "dsp.h" #include "message.h" @@ -61,7 +61,7 @@ int dsp_init_sender(mpt1327_t *mpt1327, double squelch_db) { int rc; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for Transceiver.\n"); /* init squelch */ squelch_init(&mpt1327->squelch, mpt1327->sender.kanal, squelch_db, MUTE_TIME, MUTE_TIME); @@ -69,15 +69,15 @@ int dsp_init_sender(mpt1327_t *mpt1327, double squelch_db) /* set modulation parameters */ sender_set_fm(&mpt1327->sender, MAX_DEVIATION, MAX_MODULATION, SPEECH_DEVIATION, MAX_DISPLAY); - PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation)\n", TX_PEAK_FSK, SPEECH_DEVIATION * TX_PEAK_FSK / 1e3); + LOGP(DDSP, LOGL_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation)\n", TX_PEAK_FSK, SPEECH_DEVIATION * TX_PEAK_FSK / 1e3); /* init fsk */ if (fsk_mod_init(&mpt1327->fsk_mod, mpt1327, fsk_send_bit, mpt1327->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 1, 0) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } if (fsk_demod_init(&mpt1327->fsk_demod, mpt1327, fsk_receive_bit, mpt1327->sender.samplerate, BIT_RATE, F0, F1, BIT_ADJUST) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } @@ -87,7 +87,7 @@ int dsp_init_sender(mpt1327_t *mpt1327, double squelch_db) /* repeater */ rc = jitter_create(&mpt1327->repeater_dejitter, "repeater", mpt1327->sender.samplerate, sizeof(sample_t), 0.050, 0.500, JITTER_FLAG_NONE); if (rc < 0) { - PDEBUG(DDSP, DEBUG_ERROR, "Failed to create and init repeater buffer!\n"); + LOGP(DDSP, LOGL_ERROR, "Failed to create and init repeater buffer!\n"); goto error; } return 0; @@ -100,7 +100,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_sender(mpt1327_t *mpt1327) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for Transceiver.\n"); fsk_mod_cleanup(&mpt1327->fsk_mod); fsk_demod_cleanup(&mpt1327->fsk_demod); @@ -163,7 +163,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) /* check parity */ if (mpt1327_checkbits(mpt1327->rx_bits, NULL) != (mpt1327->rx_bits & 0xffff)) { - PDEBUG(DDSP, DEBUG_NOTICE, "Received corrupt codeword or noise.\n"); + LOGP(DDSP, LOGL_NOTICE, "Received corrupt codeword or noise.\n"); mpt1327->rx_in_sync = 0; mpt1327->rx_mute = 0; return; @@ -339,7 +339,7 @@ void mpt1327_set_dsp_mode(mpt1327_t *mpt1327, enum dsp_mode mode, int repeater) jitter_reset(&mpt1327->repeater_dejitter); mpt1327->repeater = repeater; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", mpt1327_dsp_mode_name(mpt1327->dsp_mode), mpt1327_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", mpt1327_dsp_mode_name(mpt1327->dsp_mode), mpt1327_dsp_mode_name(mode)); mpt1327->dsp_mode = mode; } diff --git a/src/mpt1327/main.c b/src/mpt1327/main.c index 13393c1..b8b017b 100644 --- a/src/mpt1327/main.c +++ b/src/mpt1327/main.c @@ -29,8 +29,8 @@ #include <sys/stat.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../anetz/freiton.h" #include "../anetz/besetztton.h" #include "../liboptions/options.h" @@ -390,6 +390,7 @@ fail: mpt1327_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); flush_units(); diff --git a/src/mpt1327/message.c b/src/mpt1327/message.c index c850594..729cee1 100644 --- a/src/mpt1327/message.c +++ b/src/mpt1327/message.c @@ -23,7 +23,7 @@ #include <string.h> #include <errno.h> #include <inttypes.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "message.h" static struct mpt1327_parameter_names { @@ -411,7 +411,7 @@ static void debug_codeword(const char *prefix, int i, uint64_t bits, int enc) int column; int b; - if (debuglevel > DEBUG_INFO) + if (loglevel > LOGL_INFO) return; switch (mpt1327_definitions[i].type) { @@ -431,13 +431,13 @@ static void debug_codeword(const char *prefix, int i, uint64_t bits, int enc) case MPT_BCAST3: case MPT_BCAST4: case MPT_BCAST5: - if (enc && debuglevel > DEBUG_DEBUG) + if (enc && loglevel > LOGL_DEBUG) return; default: ; } - PDEBUG(DFRAME, DEBUG_INFO, "%s Codeword %s: %s\n", prefix, mpt1327_definitions[i].short_name, mpt1327_definitions[i].long_name); + LOGP(DFRAME, LOGL_INFO, "%s Codeword %s: %s\n", prefix, mpt1327_definitions[i].short_name, mpt1327_definitions[i].long_name); column = 0; for (b = 0; b < 64; b++) { /* if we have first parameter or we swith to next parameter */ @@ -461,7 +461,7 @@ static void debug_codeword(const char *prefix, int i, uint64_t bits, int enc) #endif } text[column] = '\0'; - PDEBUG(DFRAME, DEBUG_INFO, "%s\n", text); + LOGP(DFRAME, LOGL_INFO, "%s\n", text); } uint64_t mpt1327_encode_codeword(mpt1327_codeword_t *codeword) @@ -541,11 +541,11 @@ int mpt1327_decode_codeword(mpt1327_codeword_t *codeword, int specific, enum mpt } if (i == _NUM_MPT_DEFINITIONS) { char debug[256]; - PDEBUG(DFRAME, DEBUG_NOTICE, "Received unknown codeword or loopback from transmitter side.\n"); + LOGP(DFRAME, LOGL_NOTICE, "Received unknown codeword or loopback from transmitter side.\n"); for (b = 0; b < 64; b++) debug[b] = ((bits >> (63 - b)) & 1) + '0'; debug[b] = '\0'; - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", debug); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", debug); return -EINVAL; } codeword->type = mpt1327_definitions[i].type; diff --git a/src/mpt1327/mpt1327.c b/src/mpt1327/mpt1327.c index 820845c..7b0e303 100755 --- a/src/mpt1327/mpt1327.c +++ b/src/mpt1327/mpt1327.c @@ -71,18 +71,18 @@ #include <math.h> #include <inttypes.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" -#include "../libtimer/timer.h" +#include "../liblogging/logging.h" +#include <osmocom/core/timer.h> #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "mpt1327.h" #include "dsp.h" #include "message.h" /* Timers and counters */ -#define RESPONSE_TIMEOUT 1.0 +#define RESPONSE_TIMEOUT 1,0 #define REPEAT_GTC 1 #define REPEAT_AHY 1 #define REPEAT_AHYC 1 @@ -195,7 +195,7 @@ const char *unit_state_name(uint64_t state) void unit_new_state(mpt1327_unit_t *unit, uint64_t new_state) { - PDEBUG(DMPT1327, DEBUG_DEBUG, "Radio Unit (Prefix:%d Ident:%d) state: %s -> %s\n", unit->prefix, unit->ident, unit_state_name(unit->state), unit_state_name(new_state)); + LOGP(DMPT1327, LOGL_DEBUG, "Radio Unit (Prefix:%d Ident:%d) state: %s -> %s\n", unit->prefix, unit->ident, unit_state_name(unit->state), unit_state_name(new_state)); unit->state = new_state; } @@ -212,9 +212,9 @@ mpt1327_unit_t *get_unit(uint8_t prefix, uint16_t ident) } if (!(*unitp)) { - PDEBUG(DDB, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) added to database\n", prefix, ident); + LOGP(DDB, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) added to database\n", prefix, ident); *unitp = calloc(1, sizeof(mpt1327_unit_t)); - timer_init(&(*unitp)->timer, unit_timeout, (*unitp)); + osmo_timer_setup(&(*unitp)->timer, unit_timeout, (*unitp)); (*unitp)->state = UNIT_IDLE; (*unitp)->prefix = prefix; (*unitp)->ident = ident; @@ -262,11 +262,11 @@ static void unit_timeout(void *data) case UNIT_CALLING_SAMIS: if (unit->repeat) { --unit->repeat; - PDEBUG(DMPT1327, DEBUG_INFO, "Resend AHYC, because unit timed out.\n"); + LOGP(DMPT1327, LOGL_INFO, "Resend AHYC, because unit timed out.\n"); unit_new_state(unit, UNIT_CALLING_AHYC); break; } - PDEBUG(DMPT1327, DEBUG_INFO, "Unit failed to respond to AHYC, releasing...\n"); + LOGP(DMPT1327, LOGL_INFO, "Unit failed to respond to AHYC, releasing...\n"); mpt1327_release(unit); if (unit->callref) { call_up_release(unit->callref, CAUSE_NORMAL); @@ -276,11 +276,11 @@ static void unit_timeout(void *data) case UNIT_CALLED_ACK: if (unit->repeat) { --unit->repeat; - PDEBUG(DMPT1327, DEBUG_INFO, "Resend AHY, because unit timed out.\n"); + LOGP(DMPT1327, LOGL_INFO, "Resend AHY, because unit timed out.\n"); unit_new_state(unit, UNIT_CALLED_AHY); break; } - PDEBUG(DMPT1327, DEBUG_INFO, "Unit failed to respond to AHY, releasing...\n"); + LOGP(DMPT1327, LOGL_INFO, "Unit failed to respond to AHY, releasing...\n"); mpt1327_release(unit); if (unit->callref) { call_up_release(unit->callref, CAUSE_NORMAL); @@ -288,7 +288,7 @@ static void unit_timeout(void *data) } break; case UNIT_CALL: - PDEBUG(DMPT1327, DEBUG_NOTICE, "Release call, because unit timed out.\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Release call, because unit timed out.\n"); mpt1327_release(unit); if (unit->callref) { call_up_release(unit->callref, CAUSE_NORMAL); @@ -296,7 +296,7 @@ static void unit_timeout(void *data) } break; default: - PDEBUG(DMPT1327, DEBUG_ERROR, "Unknown timeout at state 0x%" PRIx64 ", please fix!\n", unit->state); + LOGP(DMPT1327, LOGL_ERROR, "Unknown timeout at state 0x%" PRIx64 ", please fix!\n", unit->state); break; } @@ -308,7 +308,7 @@ void flush_units(void) while (unit_list) { next = unit_list->next; - timer_exit(&unit_list->timer); + osmo_timer_del(&unit_list->timer); free(unit_list); unit_list = next; } @@ -318,14 +318,14 @@ void dump_units(void) { mpt1327_unit_t *unit = unit_list; - PDEBUG(DDB, DEBUG_NOTICE, "Dump of Radio Unit list:\n"); + LOGP(DDB, LOGL_NOTICE, "Dump of Radio Unit list:\n"); if (!unit) { - PDEBUG(DDB, DEBUG_NOTICE, " - No Radio Unit seen yet!\n"); + LOGP(DDB, LOGL_NOTICE, " - No Radio Unit seen yet!\n"); return; } while (unit) { - PDEBUG(DDB, DEBUG_NOTICE, " - Radio Unit (Prefix:%d Ident:%d) seen on this TSC.\n", unit->prefix, unit->ident); + LOGP(DDB, LOGL_NOTICE, " - Radio Unit (Prefix:%d Ident:%d) seen on this TSC.\n", unit->prefix, unit->ident); unit = unit->next; } } @@ -469,7 +469,7 @@ int mpt1327_channel_by_short_name(const char *short_name) for (i = 0; mpt1327_channels[i].short_name; i++) { if (!strcasecmp(mpt1327_channels[i].short_name, short_name)) { - PDEBUG(DMPT1327, DEBUG_INFO, "Selecting channel '%s' = %s\n", mpt1327_channels[i].short_name, mpt1327_channels[i].long_name); + LOGP(DMPT1327, LOGL_INFO, "Selecting channel '%s' = %s\n", mpt1327_channels[i].short_name, mpt1327_channels[i].long_name); return mpt1327_channels[i].chan_type; } } @@ -582,7 +582,7 @@ static void mpt1327_new_state(mpt1327_t *mpt1327, enum mpt1327_state new_state, { if (mpt1327->state == new_state) return; - PDEBUG_CHAN(DMPT1327, DEBUG_DEBUG, "State change: %s -> %s\n", mpt1327_state_name(mpt1327->state), mpt1327_state_name(new_state)); + LOGP_CHAN(DMPT1327, LOGL_DEBUG, "State change: %s -> %s\n", mpt1327_state_name(mpt1327->state), mpt1327_state_name(new_state)); /* unlink unit, if linked */ if (mpt1327->unit) { @@ -617,52 +617,52 @@ int mpt1327_create(enum mpt1327_band band, const char *kanal, enum mpt1327_chan_ mpt1327 = (mpt1327_t *)sender; if ((mpt1327->chan_type == CHAN_TYPE_CC || mpt1327->chan_type == CHAN_TYPE_CC_TC) && (chan_type == CHAN_TYPE_CC || chan_type == CHAN_TYPE_CC_TC)) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "More than one control channel is not supported, please define other channels as traffic channels!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "More than one control channel is not supported, please define other channels as traffic channels!\n"); return -EINVAL; } } mpt1327 = calloc(1, sizeof(mpt1327_t)); if (!mpt1327) { - PDEBUG(DMPT1327, DEBUG_ERROR, "No memory!\n"); + LOGP(DMPT1327, LOGL_ERROR, "No memory!\n"); return -EIO; } - PDEBUG(DMPT1327, DEBUG_DEBUG, "Creating 'MPT1327' instance for Channel %s on Band %s (sample rate %d).\n", kanal, mpt1327_band_def[band].name, samplerate); + LOGP(DMPT1327, LOGL_DEBUG, "Creating 'MPT1327' instance for Channel %s on Band %s (sample rate %d).\n", kanal, mpt1327_band_def[band].name, samplerate); /* init general part of transceiver */ rc = sender_create(&mpt1327->sender, kanal, mpt1327_channel2freq(band, atoi(kanal), 0), mpt1327_channel2freq(band, atoi(kanal), 1), device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DMPT1327, DEBUG_ERROR, "Failed to init 'Sender' processing!\n"); + LOGP(DMPT1327, LOGL_ERROR, "Failed to init 'Sender' processing!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(mpt1327, squelch_db); if (rc < 0) { - PDEBUG(DANETZ, DEBUG_ERROR, "Failed to init signal processing!\n"); + LOGP(DANETZ, LOGL_ERROR, "Failed to init signal processing!\n"); goto error; } /* timers */ - timer_init(&mpt1327->timer, mpt1327_timeout, mpt1327); + osmo_timer_setup(&mpt1327->timer, mpt1327_timeout, mpt1327); mpt1327->band = band; mpt1327->chan_type = chan_type; /* only accept these valued */ if (sysdef.framelength != 1 && sysdef.framelength != 3 && sysdef.framelength != 6) { - PDEBUG(DMPT1327, DEBUG_ERROR, "Invalid frame length %d, please fix!\n", sysdef.framelength); + LOGP(DMPT1327, LOGL_ERROR, "Invalid frame length %d, please fix!\n", sysdef.framelength); abort(); } if (sysdef.wt != 5 && sysdef.wt != 10 && sysdef.wt != 15) { - PDEBUG(DMPT1327, DEBUG_ERROR, "Invalid WT value %d, please fix!\n", sysdef.wt); + LOGP(DMPT1327, LOGL_ERROR, "Invalid WT value %d, please fix!\n", sysdef.wt); abort(); } /* go into idle state */ mpt1327_go_idle(mpt1327); - PDEBUG(DMPT1327, DEBUG_NOTICE, "Created channel #%s of type '%s' = %s\n", kanal, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); + LOGP(DMPT1327, LOGL_NOTICE, "Created channel #%s of type '%s' = %s\n", kanal, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); return 0; @@ -691,21 +691,21 @@ void mpt1327_check_channels(void) } } if (cc && !tc) { - PDEBUG(DMPT1327, DEBUG_NOTICE, "\n"); - PDEBUG(DMPT1327, DEBUG_NOTICE, "*** Selected channel(s) can be used for control only.\n"); - PDEBUG(DMPT1327, DEBUG_NOTICE, "*** No call is possible.\n"); - PDEBUG(DMPT1327, DEBUG_NOTICE, "*** Use at least one 'TC'!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "\n"); + LOGP(DMPT1327, LOGL_NOTICE, "*** Selected channel(s) can be used for control only.\n"); + LOGP(DMPT1327, LOGL_NOTICE, "*** No call is possible.\n"); + LOGP(DMPT1327, LOGL_NOTICE, "*** Use at least one 'TC'!\n"); note = 1; } if (tc && !cc) { - PDEBUG(DMPT1327, DEBUG_NOTICE, "\n"); - PDEBUG(DMPT1327, DEBUG_NOTICE, "*** Selected channel(s) can be used for traffic only.\n"); - PDEBUG(DMPT1327, DEBUG_NOTICE, "*** No call to the mobile phone is possible.\n"); - PDEBUG(DMPT1327, DEBUG_NOTICE, "*** Use one 'CC'!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "\n"); + LOGP(DMPT1327, LOGL_NOTICE, "*** Selected channel(s) can be used for traffic only.\n"); + LOGP(DMPT1327, LOGL_NOTICE, "*** No call to the mobile phone is possible.\n"); + LOGP(DMPT1327, LOGL_NOTICE, "*** Use one 'CC'!\n"); note = 1; } if (note) - PDEBUG(DMPT1327, DEBUG_NOTICE, "\n"); + LOGP(DMPT1327, LOGL_NOTICE, "\n"); } /* Destroy transceiver instance and unlink from list. */ @@ -713,10 +713,10 @@ void mpt1327_destroy(sender_t *sender) { mpt1327_t *mpt1327 = (mpt1327_t *) sender; - PDEBUG(DMPT1327, DEBUG_DEBUG, "Destroying 'MPT1327' instance for channel = %s.\n", sender->kanal); + LOGP(DMPT1327, LOGL_DEBUG, "Destroying 'MPT1327' instance for channel = %s.\n", sender->kanal); dsp_cleanup_sender(mpt1327); - timer_exit(&mpt1327->timer); + osmo_timer_del(&mpt1327->timer); sender_destroy(&mpt1327->sender); free(sender); } @@ -724,10 +724,10 @@ void mpt1327_destroy(sender_t *sender) /* Abort connection towards mobile station changing to IDLE state */ static void mpt1327_go_idle(mpt1327_t *mpt1327) { - timer_stop(&mpt1327->timer); + osmo_timer_del(&mpt1327->timer); mpt1327->pressel_on = 0; - PDEBUG(DMPT1327, DEBUG_INFO, "Entering IDLE state on channel %s.\n", mpt1327->sender.kanal); + LOGP(DMPT1327, LOGL_INFO, "Entering IDLE state on channel %s.\n", mpt1327->sender.kanal); mpt1327_new_state(mpt1327, STATE_IDLE, NULL); memset(&mpt1327->tx_sched, 0, sizeof(mpt1327->tx_sched)); switch (mpt1327->chan_type) { @@ -745,7 +745,7 @@ static void mpt1327_go_idle(mpt1327_t *mpt1327) static void mpt1327_release(mpt1327_unit_t *unit) { - timer_stop(&unit->timer); + osmo_timer_del(&unit->timer); if (unit->state == UNIT_CALL && unit->tc) { /* release all units on traffic channel */ @@ -815,7 +815,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_PFIX] = 0x2a; /* just some alternating pattern (ignored) */ codeword->params[MPT_IDENT1] = IDENT_DUMMYI; codeword->params[MPT_IDENT2] = IDENT_DUMMYI; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending dummy AHY, to prevent random access while receiving SAMIS\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending dummy AHY, to prevent random access while receiving SAMIS\n"); } else { unit = find_unit_state(UNIT_REGISTER_ACK | UNIT_DIVERSION_REJ | UNIT_CALLING_REJ | UNIT_CALLING_AHYC | UNIT_CALLED_AHY | UNIT_GTC_P | UNIT_GTC_A | UNIT_GTC_B | UNIT_CANCEL_ACK | UNIT_CALLED_AHYX, NULL); if (!unit) { @@ -851,7 +851,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT2] = unit->ident; codeword->params[MPT_QUAL] = 0; unit_new_state(unit, UNIT_IDLE); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); break; case UNIT_DIVERSION_REJ: /* reject diversion */ codeword->type = MPT_ACKX; @@ -859,7 +859,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT1] = unit->called_ident; codeword->params[MPT_IDENT2] = unit->ident; codeword->params[MPT_QUAL] = 0; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending negative acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending negative acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); if (unit->repeat) { --unit->repeat; break; @@ -874,7 +874,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT1] = unit->called_ident; codeword->params[MPT_IDENT2] = unit->ident; codeword->params[MPT_QUAL] = 1; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending negative acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending negative acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); if (unit->repeat) { --unit->repeat; break; @@ -907,15 +907,15 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_DESC] = 0x2; break; default: - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Want to send AHYC, but called_type not set correctly, please fix!\n"); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Want to send AHYC, but called_type not set correctly, please fix!\n"); abort(); } unit_new_state(unit, UNIT_CALLING_SAMIS); mpt1327->rx_sched.data_prefix = unit->prefix; mpt1327->rx_sched.data_ident = unit->ident; - PDEBUG_CHAN(DMPT1327, DEBUG_DEBUG, "Starting timer, waiting for response\n"); - timer_start(&unit->timer, RESPONSE_TIMEOUT); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending AHYC, to request SAMIS from Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_DEBUG, "Starting timer, waiting for response\n"); + osmo_timer_schedule(&unit->timer, RESPONSE_TIMEOUT); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending AHYC, to request SAMIS from Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); break; case UNIT_CALLED_AHY: /* call to unit and request ACK from unit */ codeword->type = MPT_AHY; @@ -928,9 +928,9 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_E] = 0; /* no emergency call */ codeword->params[MPT_AD] = 0; /* no appended data */ unit_new_state(unit, UNIT_CALLED_ACK); - PDEBUG_CHAN(DMPT1327, DEBUG_DEBUG, "Starting timer, waiting for response\n"); - timer_start(&unit->timer, RESPONSE_TIMEOUT); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending AHY, to request ACK from Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_DEBUG, "Starting timer, waiting for response\n"); + osmo_timer_schedule(&unit->timer, RESPONSE_TIMEOUT); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending AHY, to request ACK from Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); break; case UNIT_GTC_P: /* channel assignment to unit itself and called unit */ codeword->type = MPT_GTC; @@ -938,7 +938,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT1] = unit->called_ident; codeword->params[MPT_IDENT2] = unit->ident; codeword->params[MPT_CHAN] = mpt1327_channel2chan(unit->tc->band, atoi(unit->tc->sender.kanal)); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending channel assignment to calling and called Radio Units (Prefix:%d Ident:%d and Ident:%d)\n", unit->prefix, unit->ident, unit->called_ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending channel assignment to calling and called Radio Units (Prefix:%d Ident:%d and Ident:%d)\n", unit->prefix, unit->ident, unit->called_ident); if (unit->repeat) { --unit->repeat; break; @@ -946,7 +946,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo unit_new_state(unit, UNIT_CALL); mpt1327_set_dsp_mode(unit->tc, DSP_MODE_TRAFFIC, 1); if (sysdef.timeout) - timer_start(&unit->timer, sysdef.timeout); + osmo_timer_schedule(&unit->timer, sysdef.timeout,0); break; case UNIT_GTC_B: /* channel assignment to called unit */ /* NOTE GTC to called unit must be sent before GTC to calling unit (1.3.5.3) */ @@ -955,7 +955,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT1] = unit->called_ident; codeword->params[MPT_IDENT2] = IDENT_DUMMYI; codeword->params[MPT_CHAN] = mpt1327_channel2chan(unit->tc->band, atoi(unit->tc->sender.kanal)); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending channel assignment to called Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending channel assignment to called Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); if (unit->repeat) { --unit->repeat; break; @@ -969,7 +969,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT1] = IDENT_DUMMYI; codeword->params[MPT_IDENT2] = unit->ident; codeword->params[MPT_CHAN] = mpt1327_channel2chan(unit->tc->band, atoi(unit->tc->sender.kanal)); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending channel assignment to calling Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending channel assignment to calling Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); if (unit->repeat) { --unit->repeat; break; @@ -977,7 +977,7 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo unit_new_state(unit, UNIT_CALL); mpt1327_set_dsp_mode(unit->tc, DSP_MODE_TRAFFIC, 1); if (sysdef.timeout) - timer_start(&unit->timer, sysdef.timeout); + osmo_timer_schedule(&unit->timer, sysdef.timeout,0); break; case UNIT_CANCEL_ACK: codeword->type = MPT_ACK; @@ -986,14 +986,14 @@ int mpt1327_send_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *codewo codeword->params[MPT_IDENT2] = unit->ident; codeword->params[MPT_QUAL] = 1; unit_new_state(unit, UNIT_IDLE); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending acknowledge to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); break; case UNIT_CALLED_AHYX: /* cancel call towards unit */ codeword->type = MPT_AHYX; codeword->params[MPT_PFIX] = unit->prefix; codeword->params[MPT_IDENT1] = unit->ident; codeword->params[MPT_IDENT2] = IDENT_PABXI; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending AHYX, to cancel call to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending AHYX, to cancel call to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); if (unit->repeat) { --unit->repeat; break; @@ -1047,7 +1047,7 @@ int mpt1327_send_codeword_traffic(mpt1327_t *mpt1327, mpt1327_codeword_t __attri switch (unit->state) { case UNIT_CALL_CLEAR: /* release channel */ if (!unit->repeat) { - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Done sending clear down on traffic channel, releasing\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Done sending clear down on traffic channel, releasing\n"); unit_new_state(unit, UNIT_IDLE); mpt1327_go_idle(mpt1327); return -1; @@ -1072,7 +1072,7 @@ int mpt1327_send_codeword_traffic(mpt1327_t *mpt1327, mpt1327_codeword_t __attri cc = search_cc(); if (cc) codeword->params[MPT_CONT] = mpt1327_channel2chan(cc->band, atoi(cc->sender.kanal)); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Sending clear down on traffic channel\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Sending clear down on traffic channel\n"); } mpt1327->tx_sched.state = SCHED_STATE_TC_ADDR; break; @@ -1115,7 +1115,7 @@ static void out_setup(mpt1327_unit_t *unit, uint8_t network_type, int network_id char caller_id[32], id[16]; /* setup call */ - PDEBUG(DMPT1327, DEBUG_INFO, "Setup call to network.\n"); + LOGP(DMPT1327, LOGL_INFO, "Setup call to network.\n"); sprintf(caller_id, "%03d%04d", unit->prefix, unit->ident); if (network_id) sprintf(id, "%d", network_id); @@ -1126,9 +1126,9 @@ static void out_setup(mpt1327_unit_t *unit, uint8_t network_type, int network_id static void _cancel_pending_call(mpt1327_t *mpt1327, mpt1327_unit_t *unit) { - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "We are already in a call, the phone might have restarted, so we free old channel first.\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, "We are already in a call, the phone might have restarted, so we free old channel first.\n"); mpt1327_go_idle(unit->tc); - timer_stop(&unit->timer); + osmo_timer_del(&unit->timer); if (unit->callref) { call_up_release(unit->callref, CAUSE_NORMAL); unit->callref = 0; @@ -1144,7 +1144,7 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co case MPT_RQR: /* register */ mpt1327_reset_sync(mpt1327); /* message complete */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT1]); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) registers\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) registers\n", unit->prefix, unit->ident); if (unit->tc) _cancel_pending_call(mpt1327, unit); unit_new_state(unit, UNIT_REGISTER_ACK); @@ -1153,10 +1153,10 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co mpt1327_reset_sync(mpt1327); /* message complete */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT2]); unit->called_ident = codeword->params[MPT_IDENT1]; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) requests diversion\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) requests diversion\n", unit->prefix, unit->ident); if (unit->tc) _cancel_pending_call(mpt1327, unit); - PDEBUG_CHAN(DMPT1327, DEBUG_NOTICE, "Diversion not supported by TSC, rejecting...\n"); + LOGP_CHAN(DMPT1327, LOGL_NOTICE, "Diversion not supported by TSC, rejecting...\n"); unit_new_state(unit, UNIT_DIVERSION_REJ); break; case MPT_RQS: /* simple call */ @@ -1164,13 +1164,13 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co mpt1327_reset_sync(mpt1327); /* message complete */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT2]); unit->called_ident = codeword->params[MPT_IDENT1]; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Ident:%d%s\n", unit->prefix, unit->ident, unit->called_ident, (codeword->type == MPT_RQE) ? " (emergency)" : ""); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Ident:%d%s\n", unit->prefix, unit->ident, unit->called_ident, (codeword->type == MPT_RQE) ? " (emergency)" : ""); if (unit->tc) _cancel_pending_call(mpt1327, unit); tc = search_free_tc(); if (!tc) { unit_new_state(unit, UNIT_CALLING_REJ); - PDEBUG_CHAN(DMPT1327, DEBUG_NOTICE, "No free Traffic Channel, call is rejected.\n"); + LOGP_CHAN(DMPT1327, LOGL_NOTICE, "No free Traffic Channel, call is rejected.\n"); break; } if (codeword->params[MPT_EXT]) { @@ -1178,79 +1178,79 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co unit->called_type = CALLED_TYPE_PBX_SHORT; sprintf(unit->called_number, "%d", unit->called_ident); exchange = ((codeword->params[MPT_FLAG1] << 1) | codeword->params[MPT_FLAG2]) + 1; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to PBX exchange %d, Number %s\n", exchange, unit->called_number); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to PBX exchange %d, Number %s\n", exchange, unit->called_number); unit_new_state(unit, UNIT_GTC_A); unit->repeat = REPEAT_GTC; out_setup(unit, OSMO_CC_NETWORK_MPT1327_PBX, exchange); } else if (unit->called_ident >= IDENT_PSTNSI1 && unit->called_ident < IDENT_PSTNSI1 + 15) { unit->called_type = CALLED_TYPE_PSTN_PRE; sprintf(unit->called_number, "%d", unit->called_ident - IDENT_PSTNSI1 + 1); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to PSTN with pre-arranged Number %s\n", unit->called_number); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to PSTN with pre-arranged Number %s\n", unit->called_number); unit_new_state(unit, UNIT_GTC_A); unit->repeat = REPEAT_GTC; out_setup(unit, OSMO_CC_NETWORK_MPT1327_PSTN, 0); } else switch (unit->called_ident) { case IDENT_IPFIXI: unit->called_type = CALLED_TYPE_INTERPFX; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to Unit/Group %d with different Prefix\n", unit->called_ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to Unit/Group %d with different Prefix\n", unit->called_ident); unit_new_state(unit, UNIT_CALLING_AHYC); unit->repeat = REPEAT_AHYC; break; case IDENT_ALLI: unit->called_type = CALLED_TYPE_SYSTEM; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> System wide Call\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> System wide Call\n"); unit_new_state(unit, UNIT_GTC_P); unit->repeat = REPEAT_GTC; break; case IDENT_PSTNGI: if (codeword->params[MPT_FLAG1]) { unit->called_type = CALLED_TYPE_PSTN_LONG2; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to PSTN with long Number (10..31 Digits)\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to PSTN with long Number (10..31 Digits)\n"); } else { unit->called_type = CALLED_TYPE_PSTN_LONG1; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to PSTN with long Number (1..9 Digits)\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to PSTN with long Number (1..9 Digits)\n"); } unit_new_state(unit, UNIT_CALLING_AHYC); unit->repeat = REPEAT_AHYC; break; case IDENT_PABXI: unit->called_type = CALLED_TYPE_PBX_LONG; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to PBX (long number)\n"); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to PBX (long number)\n"); unit_new_state(unit, UNIT_CALLING_AHYC); unit->repeat = REPEAT_AHYC; break; default: unit->called_type = CALLED_TYPE_UNIT; unit->called_prefix = unit->prefix; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, " -> Call to Unit/Group %d (same Prefix)\n", unit->called_ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, " -> Call to Unit/Group %d (same Prefix)\n", unit->called_ident); unit_new_state(unit, UNIT_GTC_P); unit->repeat = REPEAT_GTC; } - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Allocating Traffic Channel %s\n", tc->sender.kanal); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Allocating Traffic Channel %s\n", tc->sender.kanal); mpt1327_new_state(tc, STATE_BUSY, unit); break; case MPT_SAMIS: /* SAMIS response */ unit = get_unit(mpt1327->rx_sched.data_prefix, mpt1327->rx_sched.data_ident); if (unit->state != UNIT_CALLING_SAMIS) { - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Radio Unit (Prefix:%d Ident:%d) sends SAMIS, but not requested\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Radio Unit (Prefix:%d Ident:%d) sends SAMIS, but not requested\n", unit->prefix, unit->ident); break; } switch (unit->called_type) { case CALLED_TYPE_INTERPFX: if (codeword->params[MPT_DESC] != 0x0) { - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Expecting DESC=%d from Radio Unit, but got DESC=%d, dropping!\n", 0x0, (int)codeword->params[MPT_DESC]); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Expecting DESC=%d from Radio Unit, but got DESC=%d, dropping!\n", 0x0, (int)codeword->params[MPT_DESC]); return; } unit->called_prefix = codeword->params[MPT_PARAMETERS1] >> 13; unit->called_ident = codeword->params[MPT_PARAMETERS1] & 0x1fff; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Prefix:%d Ident:%d\n", unit->prefix, unit->ident, unit->called_prefix, unit->called_ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Prefix:%d Ident:%d\n", unit->prefix, unit->ident, unit->called_prefix, unit->called_ident); unit_new_state(unit, UNIT_GTC_B); unit->repeat = REPEAT_GTC; break; case CALLED_TYPE_PSTN_LONG1: case CALLED_TYPE_PSTN_LONG2: if (codeword->params[MPT_DESC] != 0x1) { - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Expecting DESC=%d from Radio Unit, but got DESC=%d, dropping!\n", 0x1, (int)codeword->params[MPT_DESC]); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Expecting DESC=%d from Radio Unit, but got DESC=%d, dropping!\n", 0x1, (int)codeword->params[MPT_DESC]); return; } unit->called_number[0] = '0'; @@ -1269,8 +1269,8 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co mpt1327->rx_sched.data_count = 0; mpt1327->rx_sched.data_word = MPT_SAMIS_DT; if (mpt1327->rx_sched.data_num == 0) { - timer_stop(&unit->timer); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); + osmo_timer_del(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); out_setup(unit, OSMO_CC_NETWORK_MPT1327_PSTN, 0); unit_new_state(unit, UNIT_GTC_A); unit->repeat = REPEAT_GTC; @@ -1278,7 +1278,7 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co break; case CALLED_TYPE_PBX_LONG: if (codeword->params[MPT_DESC] != 0x2) { - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Expecting DESC=%d from Radio Unit, but got DESC=%d, dropping!\n", 0x2, (int)codeword->params[MPT_DESC]); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Expecting DESC=%d from Radio Unit, but got DESC=%d, dropping!\n", 0x2, (int)codeword->params[MPT_DESC]); return; } unit->called_number[0] = '0'; @@ -1292,21 +1292,21 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co unit->called_number[8] = mpt1327_bcd[(codeword->params[MPT_PARAMETERS2] >> 4) & 0xf]; unit->called_number[9] = mpt1327_bcd[(codeword->params[MPT_PARAMETERS2] >> 0) & 0xf]; unit->called_number[10] = '\0'; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); - timer_stop(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); + osmo_timer_del(&unit->timer); out_setup(unit, OSMO_CC_NETWORK_MPT1327_PBX, 0); unit_new_state(unit, UNIT_GTC_A); unit->repeat = REPEAT_GTC; break; default: - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Want to receive SAMIS, but called_type not set correctly, please fix!\n"); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Want to receive SAMIS, but called_type not set correctly, please fix!\n"); abort(); } break; case MPT_SAMIS_DT: unit = get_unit(mpt1327->rx_sched.data_prefix, mpt1327->rx_sched.data_ident); if (unit->state != UNIT_CALLING_SAMIS) { - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Radio Unit (Prefix:%d Ident:%d) sends SAMIS, but not requested\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Radio Unit (Prefix:%d Ident:%d) sends SAMIS, but not requested\n", unit->prefix, unit->ident); break; } if (mpt1327->rx_sched.data_count == 1) { @@ -1323,8 +1323,8 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co unit->called_number[20] = mpt1327_bcd[(codeword->params[MPT_BCD11] >> 0) & 0xf]; unit->called_number[21] = '\0'; if (mpt1327->rx_sched.data_num == 1) { - timer_stop(&unit->timer); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); + osmo_timer_del(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); out_setup(unit, OSMO_CC_NETWORK_MPT1327_PSTN, 0); unit_new_state(unit, UNIT_GTC_A); unit->repeat = REPEAT_GTC; @@ -1343,8 +1343,8 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co unit->called_number[31] = mpt1327_bcd[(codeword->params[MPT_BCD11] >> 0) & 0xf]; unit->called_number[32] = '\0'; mpt1327->rx_sched.data_num = 0; /* just in case it is more than 2 data words */ - timer_stop(&unit->timer); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); + osmo_timer_del(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) calls Number %s\n", unit->prefix, unit->ident, unit->called_number); out_setup(unit, OSMO_CC_NETWORK_MPT1327_PSTN, 0); unit_new_state(unit, UNIT_GTC_A); unit->repeat = REPEAT_GTC; @@ -1353,30 +1353,30 @@ void mpt1327_receive_codeword_control(mpt1327_t *mpt1327, mpt1327_codeword_t *co case MPT_RQX: /* call cancel */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT2]); unit->called_ident = codeword->params[MPT_IDENT1]; - timer_stop(&unit->timer); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) cancels call to %d\n", unit->prefix, unit->ident, unit->called_ident); + osmo_timer_del(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) cancels call to %d\n", unit->prefix, unit->ident, unit->called_ident); unit_new_state(unit, UNIT_CANCEL_ACK); if (unit->tc) { - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Free Traffic Channel %s, because unit cancels on control channel\n", unit->tc->sender.kanal); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Free Traffic Channel %s, because unit cancels on control channel\n", unit->tc->sender.kanal); mpt1327_go_idle(unit->tc); } break; case MPT_ACKI: /* ack from unit (not ready, wait for RQQ) */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT1]); - timer_stop(&unit->timer); + osmo_timer_del(&unit->timer); if (unit->state == UNIT_CALLED_ACK) { - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) acknowledges call (not yet ready, waiting for RQQ\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) acknowledges call (not yet ready, waiting for RQQ\n", unit->prefix, unit->ident); if (unit->callref) call_up_alerting(unit->callref); break; } - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Radio Unit (Prefix:%d Ident:%d) acknowledges, no call\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Radio Unit (Prefix:%d Ident:%d) acknowledges, no call\n", unit->prefix, unit->ident); break; case MPT_ACK: /* ack from unit */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT1]); - timer_stop(&unit->timer); + osmo_timer_del(&unit->timer); if (unit->state == UNIT_CALLED_ACK) { - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) acknowledges call\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) acknowledges call\n", unit->prefix, unit->ident); answer: if (unit->callref) { char connected_id[32]; @@ -1387,22 +1387,22 @@ answer: unit->repeat = REPEAT_GTC; break; } - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Radio Unit (Prefix:%d Ident:%d) acknowledges, no call\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Radio Unit (Prefix:%d Ident:%d) acknowledges, no call\n", unit->prefix, unit->ident); break; case MPT_RQQ: /* status from radio */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT2]); - timer_stop(&unit->timer); - PDEBUG_CHAN(DMPT1327, DEBUG_ERROR, "Radio Unit (Prefix:%d Ident:%d) sends RRQ with STATUS=%d\n", unit->prefix, unit->ident, (int)codeword->params[MPT_STATUS]); + osmo_timer_del(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_ERROR, "Radio Unit (Prefix:%d Ident:%d) sends RRQ with STATUS=%d\n", unit->prefix, unit->ident, (int)codeword->params[MPT_STATUS]); switch (codeword->params[MPT_STATUS]) { case 0x00: if (unit->state == UNIT_CALLED_ACK) { - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) answers call\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) answers call\n", unit->prefix, unit->ident); // NOTE: GTC acknowledges RQQ goto answer; } break; case 0x1f: - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) rejects call, releasing\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) rejects call, releasing\n", unit->prefix, unit->ident); // NOTE: AHYX acknowledges RQQ mpt1327_release(unit); if (unit->callref) { @@ -1427,7 +1427,7 @@ answer: default: if (mpt1327->sender.loopback) return; - PDEBUG_CHAN(DMPT1327, DEBUG_NOTICE, "Received unsupported codeword '%s' = '%s' on control channel\n", codeword->short_name, codeword->long_name); + LOGP_CHAN(DMPT1327, LOGL_NOTICE, "Received unsupported codeword '%s' = '%s' on control channel\n", codeword->short_name, codeword->long_name); } } @@ -1439,34 +1439,34 @@ void mpt1327_receive_codeword_traffic(mpt1327_t *mpt1327, mpt1327_codeword_t *co case MPT_MAINT: /* maintenance message */ unit = get_unit(codeword->params[MPT_PFIX], codeword->params[MPT_IDENT1]); if (codeword->params[MPT_CHAN] != mpt1327_channel2chan(mpt1327->band, atoi(mpt1327->sender.kanal))) { - PDEBUG_CHAN(DMPT1327, DEBUG_NOTICE, "Radio Unit (Prefix:%d Ident:%d) sends maintenance message on wrong channel %d, ignoring!\n", unit->prefix, unit->ident, (int)codeword->params[MPT_CHAN]); + LOGP_CHAN(DMPT1327, LOGL_NOTICE, "Radio Unit (Prefix:%d Ident:%d) sends maintenance message on wrong channel %d, ignoring!\n", unit->prefix, unit->ident, (int)codeword->params[MPT_CHAN]); return; } if (!unit->tc) { - PDEBUG_CHAN(DMPT1327, DEBUG_NOTICE, "Radio Unit (Prefix:%d Ident:%d) sends maintenance, but it has no channel assigned, ignoring!\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_NOTICE, "Radio Unit (Prefix:%d Ident:%d) sends maintenance, but it has no channel assigned, ignoring!\n", unit->prefix, unit->ident); return; } switch (codeword->params[MPT_OPER]) { case OPER_PRESSEL_ON: if (sysdef.timeout) - timer_start(&unit->timer, sysdef.timeout); + osmo_timer_schedule(&unit->timer, sysdef.timeout,0); mpt1327->pressel_on = 1; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) starts transmission\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) starts transmission\n", unit->prefix, unit->ident); break; case OPER_PRESSEL_OFF: if (sysdef.timeout) - timer_start(&unit->timer, sysdef.timeout); + osmo_timer_schedule(&unit->timer, sysdef.timeout,0); mpt1327->pressel_on = 0; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) stops transmission\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) stops transmission\n", unit->prefix, unit->ident); break; case OPER_DISCONNECT: /* ignore while we send clear message */ if (unit->state == UNIT_CALL_CLEAR) return; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) disconnects from channel\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) disconnects from channel\n", unit->prefix, unit->ident); if (unit->state == UNIT_CALL) { - timer_stop(&unit->timer); - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Free Traffic Channel %s, because the initiator goes on-hook\n", unit->tc->sender.kanal); + osmo_timer_del(&unit->timer); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Free Traffic Channel %s, because the initiator goes on-hook\n", unit->tc->sender.kanal); mpt1327_go_idle(unit->tc); if (unit->callref) { call_up_release(unit->callref, CAUSE_NORMAL); @@ -1477,16 +1477,16 @@ void mpt1327_receive_codeword_traffic(mpt1327_t *mpt1327, mpt1327_codeword_t *co break; case OPER_PERIODIC: if (sysdef.timeout) - timer_start(&unit->timer, sysdef.timeout); + osmo_timer_schedule(&unit->timer, sysdef.timeout,0); mpt1327->pressel_on = 1; - PDEBUG_CHAN(DMPT1327, DEBUG_INFO, "Radio Unit (Prefix:%d Ident:%d) sends periodic message\n", unit->prefix, unit->ident); + LOGP_CHAN(DMPT1327, LOGL_INFO, "Radio Unit (Prefix:%d Ident:%d) sends periodic message\n", unit->prefix, unit->ident); break; } break; default: if (mpt1327->sender.loopback) return; - PDEBUG_CHAN(DMPT1327, DEBUG_NOTICE, "Received unsupported codeword '%s' = '%s' on traffic channel\n", codeword->short_name, codeword->long_name); + LOGP_CHAN(DMPT1327, LOGL_NOTICE, "Received unsupported codeword '%s' = '%s' on traffic channel\n", codeword->short_name, codeword->long_name); } } @@ -1495,7 +1495,7 @@ void mpt1327_receive_codeword(mpt1327_t *mpt1327, uint64_t bits, double quality, mpt1327_codeword_t codeword; int rc; - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RX Level: %.0f%% Quality=%.0f%%\n", level * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "RX Level: %.0f%% Quality=%.0f%%\n", level * 100.0, quality * 100.0); rc = mpt1327_decode_codeword(&codeword, (mpt1327->rx_sched.data_num) ? mpt1327->rx_sched.data_word : -1, (mpt1327->sender.loopback) ? MPT_DOWN : MPT_UP, bits); if (rc < 0) { @@ -1533,7 +1533,7 @@ void mpt1327_signal_indication(mpt1327_t *mpt1327) /* restart timer, if enabled */ if (mpt1327->unit && mpt1327->unit->state == UNIT_CALL) { if (sysdef.timeout) - timer_start(&mpt1327->unit->timer, sysdef.timeout); + osmo_timer_schedule(&mpt1327->unit->timer, sysdef.timeout,0); } } @@ -1567,18 +1567,18 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 2. check if given number is already in a call, return BUSY */ unit = get_unit(prefix, ident); if (unit->state != UNIT_IDLE) { - PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing call to busy Radio Unit, rejecting!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Outgoing call to busy Radio Unit, rejecting!\n"); return -CAUSE_BUSY; } /* 3. check if all channels are busy, return NOCHANNEL */ tc = search_free_tc(); if (!tc) { - PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Outgoing call, but no free channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG(DMPT1327, DEBUG_INFO, "Outgoing call to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); + LOGP(DMPT1327, LOGL_INFO, "Outgoing call to Radio Unit (Prefix:%d Ident:%d)\n", unit->prefix, unit->ident); /* 4. trying to reach radio unit */ unit->callref = callref; @@ -1603,11 +1603,11 @@ void call_down_disconnect(int callref, int cause) { mpt1327_unit_t *unit; - PDEBUG(DMPT1327, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DMPT1327, LOGL_INFO, "Call has been disconnected by network.\n"); unit = find_unit_callref(callref); if (!unit) { - PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing disconnect, but no unit for callref!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Outgoing disconnect, but no unit for callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1615,7 +1615,7 @@ void call_down_disconnect(int callref, int cause) /* Release when not active */ if (unit->state == UNIT_CALL) return; - PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing disconnect, but no call, releasing!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Outgoing disconnect, but no call, releasing!\n"); mpt1327_release(unit); unit->callref = 0; @@ -1627,16 +1627,16 @@ void call_down_release(int callref, __attribute__((unused)) int cause) { mpt1327_unit_t *unit; - PDEBUG(DMPT1327, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DMPT1327, LOGL_INFO, "Call has been released by network, releasing call.\n"); unit = find_unit_callref(callref); if (!unit) { - PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing release, but no unit for callref!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Outgoing release, but no unit for callref!\n"); /* don't send release, because caller already released */ return; } - PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing release, releasing!\n"); + LOGP(DMPT1327, LOGL_NOTICE, "Outgoing release, releasing!\n"); mpt1327_release(unit); unit->callref = 0; } diff --git a/src/mpt1327/mpt1327.h b/src/mpt1327/mpt1327.h index 18af5e1..5cf1d10 100755 --- a/src/mpt1327/mpt1327.h +++ b/src/mpt1327/mpt1327.h @@ -84,7 +84,7 @@ typedef struct mpt1327_unit { struct mpt1327_unit *next; uint64_t state; int repeat; /* number of repeating messages / retries after timeout */ - struct timer timer; /* timeout waiting for unit response */ + struct osmo_timer_list timer; /* timeout waiting for unit response */ struct mpt1327 *tc; /* link to transceiver */ uint8_t prefix; /* unit's prefix */ uint16_t ident; /* unit's ident */ @@ -102,7 +102,7 @@ typedef struct mpt1327 { /* sender's states */ enum mpt1327_state state; /* current sender's state */ - struct timer timer; /* inactivity timer to clear channel */ + struct osmo_timer_list timer; /* inactivity timer to clear channel */ mpt1327_unit_t *unit; /* link to unit */ /* display measurements */ diff --git a/src/nmt/Makefile.am b/src/nmt/Makefile.am index 17a733a..a5d7b8a 100644 --- a/src/nmt/Makefile.am +++ b/src/nmt/Makefile.am @@ -23,17 +23,13 @@ nmt_LDADD = \ $(COMMON_LA) \ libdmssms.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libhagelbarger/libhagelbarger.a \ $(top_builddir)/src/libdtmf/libdtmf.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfsk/libfsk.a \ @@ -41,8 +37,10 @@ nmt_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/nmt/dms.c b/src/nmt/dms.c index 82d5174..07cad7d 100644 --- a/src/nmt/dms.c +++ b/src/nmt/dms.c @@ -22,7 +22,8 @@ #include <stdlib.h> #include <string.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" +#include "../libmobile/get_time.h" #include "nmt.h" #define MUTE_DURATION 0.300 /* 200ms, and about 95ms for the frame itself */ @@ -110,7 +111,7 @@ void link_dms_frame(nmt_t *nmt, struct dms_frame *frame) dms_t *dms = &nmt->dms; struct dms_frame **framep; - PDEBUG(DDMS, DEBUG_DEBUG, "link DMS frame\n"); + LOGP(DDMS, LOGL_DEBUG, "link DMS frame\n"); /* attach to end of list */ framep = &dms->state.frame_list; @@ -125,14 +126,14 @@ void unlink_dms_frame(nmt_t *nmt, struct dms_frame *frame) dms_t *dms = &nmt->dms; struct dms_frame **framep; - PDEBUG(DDMS, DEBUG_DEBUG, "unlink DMS frame\n"); + LOGP(DDMS, LOGL_DEBUG, "unlink DMS frame\n"); /* unlink */ framep = &dms->state.frame_list; while (*framep && *framep != frame) framep = &((*framep)->next); if (!(*framep)) { - PDEBUG(DTRANS, DEBUG_ERROR, "Frame not in list, please fix!!\n"); + LOGP(DTRANS, LOGL_ERROR, "Frame not in list, please fix!!\n"); abort(); } *framep = frame->next; @@ -146,7 +147,7 @@ static void dms_frame_add(nmt_t *nmt, int s, const uint8_t *data) dms_frame = calloc(1, sizeof(*dms_frame)); if (!dms_frame) { - PDEBUG(DDMS, DEBUG_ERROR, "No memory!\n"); + LOGP(DDMS, LOGL_ERROR, "No memory!\n"); return; } @@ -155,7 +156,7 @@ static void dms_frame_add(nmt_t *nmt, int s, const uint8_t *data) dms->state.n_count = (dms->state.n_count + 1) & 7; memcpy(dms_frame->data, data, 8); - PDEBUG(DDMS, DEBUG_DEBUG, "add DMS %cT(%d) frame to queue\n", dms_frame->s + 'C', dms_frame->n); + LOGP(DDMS, LOGL_DEBUG, "add DMS %cT(%d) frame to queue\n", dms_frame->s + 'C', dms_frame->n); link_dms_frame(nmt, dms_frame); } @@ -163,7 +164,7 @@ static void dms_frame_add(nmt_t *nmt, int s, const uint8_t *data) /* delete DMS frame from list of TX frames */ static void dms_frame_delete(nmt_t *nmt, struct dms_frame *dms_frame) { - PDEBUG(DDMS, DEBUG_DEBUG, "delete DMS frame %cT(%d) from queue\n", dms_frame->s + 'C', dms_frame->n); + LOGP(DDMS, LOGL_DEBUG, "delete DMS frame %cT(%d) from queue\n", dms_frame->s + 'C', dms_frame->n); unlink_dms_frame(nmt, dms_frame); @@ -248,7 +249,7 @@ static void dms_encode_dt(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n, uint8_t * uint16_t crc; int i, j; - PDEBUG(DDMS, DEBUG_INFO, "Sending DMS frame: %s\n", print_ct_dt(s, n, _data, dms->state.eight_bits)); + LOGP(DDMS, LOGL_INFO, "Sending DMS frame: %s\n", print_ct_dt(s, n, _data, dms->state.eight_bits)); /* generate label */ data[0] = (d << 6) | (s << 5) | (3 << 3) | n; @@ -354,7 +355,7 @@ void trigger_frame_transmission(nmt_t *nmt) /* check for RR first, because high priority */ if (dms->state.send_rr) { - PDEBUG(DDMS, DEBUG_DEBUG, "Found pending RR(%d) frame, sending.\n", dms->state.n_r); + LOGP(DDMS, LOGL_DEBUG, "Found pending RR(%d) frame, sending.\n", dms->state.n_r); dms->state.send_rr = 0; dms_encode_rr(nmt, dms->state.dir ^ 1, 1, dms->state.n_r); return; @@ -374,7 +375,7 @@ void trigger_frame_transmission(nmt_t *nmt) /* check if outstanding frame */ if (!dms_frame) { - PDEBUG(DDMS, DEBUG_DEBUG, "No pending RR/CT/DT frame found.\n"); + LOGP(DDMS, LOGL_DEBUG, "No pending RR/CT/DT frame found.\n"); if (dms->state.tx_pending) { dms->state.tx_pending = 0; dms_all_sent(nmt); @@ -382,7 +383,7 @@ void trigger_frame_transmission(nmt_t *nmt) return; } - PDEBUG(DDMS, DEBUG_DEBUG, "Found pending %cT(%d) frame, sending.\n", dms_frame->s + 'C', dms_frame->n); + LOGP(DDMS, LOGL_DEBUG, "Found pending %cT(%d) frame, sending.\n", dms_frame->s + 'C', dms_frame->n); /* sent next send state to next frame in buffer. * if there is no next frame, set it to the first frame (cycle). @@ -390,19 +391,19 @@ void trigger_frame_transmission(nmt_t *nmt) */ if (!dms_frame->next) { dms->state.n_s = dms->state.frame_list->n; - PDEBUG(DDMS, DEBUG_DEBUG, " -> Next sequence number is %d, because this was the last frame in queue.\n", dms->state.n_s); + LOGP(DDMS, LOGL_DEBUG, " -> Next sequence number is %d, because this was the last frame in queue.\n", dms->state.n_s); } else if (!dms->state.established && dms_frame->next->s == 1) { dms->state.n_s = dms->state.frame_list->n; - PDEBUG(DDMS, DEBUG_DEBUG, " -> Next sequence number is %d, because this was the last frame before DT queue, and RAND has not been acked yet.\n", dms->state.n_s); + LOGP(DDMS, LOGL_DEBUG, " -> Next sequence number is %d, because this was the last frame before DT queue, and RAND has not been acked yet.\n", dms->state.n_s); } else if (i == 3) { dms->state.n_s = dms->state.frame_list->n; - PDEBUG(DDMS, DEBUG_DEBUG, " -> Next sequence number is %d, because we reached max number of unacknowledged frames.\n", dms->state.n_s); + LOGP(DDMS, LOGL_DEBUG, " -> Next sequence number is %d, because we reached max number of unacknowledged frames.\n", dms->state.n_s); } else if (!dms->state.established && dms_frame->next->s == 0) { dms->state.n_s = dms_frame->next->n; - PDEBUG(DDMS, DEBUG_DEBUG, " -> Next sequence number is %d, because this is the next CT frame in queue.\n", dms->state.n_s); + LOGP(DDMS, LOGL_DEBUG, " -> Next sequence number is %d, because this is the next CT frame in queue.\n", dms->state.n_s); } else { dms->state.n_s = dms_frame->next->n; - PDEBUG(DDMS, DEBUG_DEBUG, " -> Next sequence number is %d, because this is the next frame in queue.\n", dms->state.n_s); + LOGP(DDMS, LOGL_DEBUG, " -> Next sequence number is %d, because this is the next frame in queue.\n", dms->state.n_s); } dms_encode_dt(nmt, dms->state.dir ^ 1, dms_frame->s, dms_frame->n, dms_frame->data); @@ -438,7 +439,7 @@ static void dms_rx_dt(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n, uint8_t *data /* start transfer */ if (!dms->state.started) { - PDEBUG(DDMS, DEBUG_INFO, "Starting DMS transfer (mobile originated)\n"); + LOGP(DDMS, LOGL_INFO, "Starting DMS transfer (mobile originated)\n"); dms->state.started = 1; dms->state.established = 0; dms->state.dir = d; @@ -451,15 +452,15 @@ static void dms_rx_dt(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n, uint8_t *data if (dms->state.dir != d && !dms_allow_loopback) { /* drop frames with wrong direction indicator */ - PDEBUG(DDMS, DEBUG_INFO, "DMS frame ignored, direction indicator mismatch!\n"); + LOGP(DDMS, LOGL_INFO, "DMS frame ignored, direction indicator mismatch!\n"); return; } if (dms->state.n_r != n) { /* ignore out of sequence frames */ - PDEBUG(DDMS, DEBUG_DEBUG, "DMS frame number mismatch (due to resending)\n"); + LOGP(DDMS, LOGL_DEBUG, "DMS frame number mismatch (due to resending)\n"); } else { - PDEBUG(DDMS, DEBUG_INFO, "Received valid DMS frame: %s\n", print_ct_dt(s, n, data, dms->state.eight_bits)); + LOGP(DDMS, LOGL_INFO, "Received valid DMS frame: %s\n", print_ct_dt(s, n, data, dms->state.eight_bits)); /* cycle sequence */ dms->state.n_r = (n + 1) % 8; @@ -470,7 +471,7 @@ static void dms_rx_dt(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n, uint8_t *data case 73: /* ID */ break; case 82: /* RAND */ - PDEBUG(DDMS, DEBUG_DEBUG, "RAND frame has been received, so we can send/receive DT frame\n"); + LOGP(DDMS, LOGL_DEBUG, "RAND frame has been received, so we can send/receive DT frame\n"); /* when we sent RAND, we do not resend it again, this would be wrong */ if (!dms->state.rand_sent) { dms_frame_add_rand(nmt, data[7]); @@ -484,7 +485,7 @@ static void dms_rx_dt(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n, uint8_t *data } } else { if (!dms->state.established) - PDEBUG(DDMS, DEBUG_NOTICE, "Received DT frame, but RAND frame has not been received yet\n"); + LOGP(DDMS, LOGL_NOTICE, "Received DT frame, but RAND frame has not been received yet\n"); else { if (!dms->state.eight_bits) length = 8; @@ -526,7 +527,7 @@ static void dms_rx_rr(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n) if (dms->state.dir != d && !dms_allow_loopback) { /* drop frames with wrong direction indicator */ - PDEBUG(DDMS, DEBUG_INFO, "DMS frame ignored, direction indicator mismatch!\n"); + LOGP(DDMS, LOGL_INFO, "DMS frame ignored, direction indicator mismatch!\n"); return; } @@ -541,17 +542,17 @@ static void dms_rx_rr(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n) /* if we don't find a frame, it must have been already acked, so we ignore RR */ if (!dms_frame || i == 4) { - PDEBUG(DDMS, DEBUG_DEBUG, "Received already acked DMS frame: RR(%d) (s = %d), ignoring\n", n, s); + LOGP(DDMS, LOGL_DEBUG, "Received already acked DMS frame: RR(%d) (s = %d), ignoring\n", n, s); return; } - PDEBUG(DDMS, DEBUG_INFO, "Received valid DMS frame: RR(%d) (s = %d)\n", n, s); + LOGP(DDMS, LOGL_INFO, "Received valid DMS frame: RR(%d) (s = %d)\n", n, s); /* flush all acked frames. */ dms_frame = dms->state.frame_list; for (j = 0; j <= i; j++) { if (dms_frame->data[0] == 82) { /* RAND */ - PDEBUG(DDMS, DEBUG_DEBUG, "RAND frame has been acknowledged, so we can continue to send DT frame\n"); + LOGP(DDMS, LOGL_DEBUG, "RAND frame has been acknowledged, so we can continue to send DT frame\n"); dms->state.established = 1; } /* increment ack counter */ @@ -559,9 +560,9 @@ static void dms_rx_rr(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n) /* raise send counter if required */ if (dms->state.n_s == dms_frame->n) { dms->state.n_s = dms->state.n_a; - PDEBUG(DDMS, DEBUG_DEBUG, "Raising next frame to send to #%d\n", dms->state.n_s); + LOGP(DDMS, LOGL_DEBUG, "Raising next frame to send to #%d\n", dms->state.n_s); } - PDEBUG(DDMS, DEBUG_DEBUG, "Removing acked frame #%d\n", dms_frame->n); + LOGP(DDMS, LOGL_DEBUG, "Removing acked frame #%d\n", dms_frame->n); dms_frame_next = dms_frame->next; dms_frame_delete(nmt, dms_frame); dms_frame = dms_frame_next; @@ -581,11 +582,11 @@ static void dms_rx_nr(nmt_t *nmt, uint8_t d, uint8_t s, uint8_t n) if (dms->state.dir != d && !dms_allow_loopback) { /* drop frames with wrong direction indicator */ - PDEBUG(DDMS, DEBUG_INFO, "DMS frame ignored, direction indicator mismatch!\n"); + LOGP(DDMS, LOGL_INFO, "DMS frame ignored, direction indicator mismatch!\n"); return; } - PDEBUG(DDMS, DEBUG_INFO, "Received valid DMS frame: NR(%d) (s = %d)\n", n, s); + LOGP(DDMS, LOGL_INFO, "Received valid DMS frame: NR(%d) (s = %d)\n", n, s); // FIXME: support NR @@ -624,7 +625,7 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) if (quality < 0.65) return; - PDEBUG(DDSP, DEBUG_DEBUG, "DMS sync RX Level: %.0f%% Quality=%.0f\n", level * 100.0 + 0.5, quality * 100.0 + 0.5); + LOGP(DDSP, LOGL_DEBUG, "DMS sync RX Level: %.0f%% Quality=%.0f\n", level * 100.0 + 0.5, quality * 100.0 + 0.5); /* rest sync register */ dms->rx_sync = 0; @@ -657,10 +658,10 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) dms->rx_label.s = (dms->rx_frame[0] >> 5) & 0x1; dms->rx_label.p = (dms->rx_frame[0] >> 3) & 0x3; dms->rx_label.n = dms->rx_frame[0] & 0x7; - PDEBUG(DDMS, DEBUG_DEBUG, "Got DMS label (d = %d, s = %d, p = %d, n = %d)\n", dms->rx_label.d,dms->rx_label.s,dms->rx_label.p,dms->rx_label.n); + LOGP(DDMS, LOGL_DEBUG, "Got DMS label (d = %d, s = %d, p = %d, n = %d)\n", dms->rx_label.d,dms->rx_label.s,dms->rx_label.p,dms->rx_label.n); dms->rx_frame_count++; if (dms->rx_label.p == 0) { - PDEBUG(DDMS, DEBUG_DEBUG, "Spare prefix '00' ignoring!\n"); + LOGP(DDMS, LOGL_DEBUG, "Spare prefix '00' ignoring!\n"); dms->rx_in_sync = 0; } } @@ -673,7 +674,7 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) if (dms->rx_bit_count == 9) { dms->rx_bit_count = 0; uint8_t c = dms->rx_frame[dms->rx_frame_count]; - PDEBUG(DDMS, DEBUG_DEBUG, "Got DMS word 0x%02x (%c)\n", c, (c >= 32 && c <= 126) ? c : '.'); + LOGP(DDMS, LOGL_DEBUG, "Got DMS word 0x%02x (%c)\n", c, (c >= 32 && c <= 126) ? c : '.'); dms->rx_frame_count++; } return; @@ -681,7 +682,7 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) if (dms->rx_frame_count <= 10) { if (dms->rx_bit_count == 9) { dms->rx_bit_count = 0; - PDEBUG(DDMS, DEBUG_DEBUG, "Got DMS CRC 0x%02x\n", dms->rx_frame[dms->rx_frame_count]); + LOGP(DDMS, LOGL_DEBUG, "Got DMS CRC 0x%02x\n", dms->rx_frame[dms->rx_frame_count]); dms->rx_frame_count++; } return; @@ -691,7 +692,7 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) uint8_t bits[63 + 16]; int i, j; dms->rx_bit_count = 0; - PDEBUG(DDMS, DEBUG_DEBUG, "Got DMS CRC 0x%x\n", dms->rx_frame[dms->rx_frame_count]); + LOGP(DDMS, LOGL_DEBUG, "Got DMS CRC 0x%x\n", dms->rx_frame[dms->rx_frame_count]); crc_got = (dms->rx_frame[9] << 9) | (dms->rx_frame[10] << 2) | dms->rx_frame[11]; for (i = 0; i < 9; i++) { for (j = 0; j < 7; j++) @@ -700,7 +701,7 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) for (i = 0; i < 16; i++) bits[63 + i] = 0; crc_calc = crc16(bits, 63 + 16); - PDEBUG(DDMS, DEBUG_DEBUG, "DMS CRC = 0x%04x %s\n", crc_got, (crc_calc == crc_got) ? "(OK)" : "(CRC error)"); + LOGP(DDMS, LOGL_DEBUG, "DMS CRC = 0x%04x %s\n", crc_got, (crc_calc == crc_got) ? "(OK)" : "(CRC error)"); if (crc_calc == crc_got) dms_rx_dt(nmt, dms->rx_label.d, dms->rx_label.s, dms->rx_label.n, dms->rx_frame + 1); dms->rx_in_sync = 0; @@ -713,12 +714,12 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) if (dms->rx_bit_count == 9) { dms->rx_bit_count = 0; if (dms->rx_frame[0] != dms->rx_frame[1]) { - PDEBUG(DDMS, DEBUG_DEBUG, "Repeated DMS label mismatches!\n"); + LOGP(DDMS, LOGL_DEBUG, "Repeated DMS label mismatches!\n"); dms->rx_in_sync = 0; return; } dms->rx_frame_count++; - PDEBUG(DDMS, DEBUG_DEBUG, "Repeated label matches\n"); + LOGP(DDMS, LOGL_DEBUG, "Repeated label matches\n"); } return; } @@ -727,13 +728,13 @@ void fsk_receive_bit_dms(nmt_t *nmt, int bit, double quality, double level) int i; dms->rx_bit_count = 0; parity_got = dms->rx_frame[2]; - PDEBUG(DDMS, DEBUG_DEBUG, "Got DMS parity 0x%x\n", dms->rx_frame[dms->rx_frame_count]); + LOGP(DDMS, LOGL_DEBUG, "Got DMS parity 0x%x\n", dms->rx_frame[dms->rx_frame_count]); for (i = 0; i < 7; i++) { bit = (dms->rx_frame[0] >> i) & 1; if (bit) parity_calc ^= 0x3; } - PDEBUG(DDMS, DEBUG_DEBUG, "DMS parity %s\n", (parity_calc == parity_got) ? "(OK)" : "(parity error)"); + LOGP(DDMS, LOGL_DEBUG, "DMS parity %s\n", (parity_calc == parity_got) ? "(OK)" : "(parity error)"); if (parity_calc == parity_got) { if (dms->rx_label.p == 1) dms_rx_rr(nmt, dms->rx_label.d, dms->rx_label.s, dms->rx_label.n); @@ -758,18 +759,18 @@ void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits) uint8_t frame[8]; int i, copied; - PDEBUG(DDMS, DEBUG_DEBUG, "Received message with %d digits of %d bits\n", length, (eight_bits) ? 8 : 7); + LOGP(DDMS, LOGL_DEBUG, "Received message with %d digits of %d bits\n", length, (eight_bits) ? 8 : 7); /* active connection */ if (dms->state.started) { if (dms->state.eight_bits != eight_bits) { - PDEBUG(DDMS, DEBUG_ERROR, "DMS session active, but upper layer sends wrong bit format!\n"); + LOGP(DDMS, LOGL_ERROR, "DMS session active, but upper layer sends wrong bit format!\n"); return; } } if (!dms->state.started) { - PDEBUG(DDMS, DEBUG_DEBUG, "Transfer not started, so we send ID + RAND first\n"); + LOGP(DDMS, LOGL_DEBUG, "Transfer not started, so we send ID + RAND first\n"); dms->state.started = 1; dms->state.established = 0; dms->state.eight_bits = eight_bits; @@ -783,7 +784,7 @@ void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits) dms->state.rand_sent = 1; } - PDEBUG(DDMS, DEBUG_DEBUG, "Queueing message data as DT frames...\n"); + LOGP(DDMS, LOGL_DEBUG, "Queueing message data as DT frames...\n"); while (length) { if (eight_bits) { /* copy what we have */ @@ -837,7 +838,7 @@ void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits) void dms_reset(nmt_t *nmt) { dms_t *dms = &nmt->dms; - PDEBUG(DDMS, DEBUG_DEBUG, "Resetting DMS states\n"); + LOGP(DDMS, LOGL_DEBUG, "Resetting DMS states\n"); dms->rx_in_sync = 0; memset(&dms->state, 0, sizeof(dms->state)); diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c index d51bc69..e3d5184 100644 --- a/src/nmt/dsp.c +++ b/src/nmt/dsp.c @@ -26,7 +26,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "nmt.h" #include "transaction.h" #include "dsp.h" @@ -89,7 +89,7 @@ void dsp_init(void) int i; double s; - PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table for supervisory signal and dial tone.\n"); + LOGP(DDSP, LOGL_DEBUG, "Generating sine table for supervisory signal and dial tone.\n"); for (i = 0; i < 65536; i++) { s = sin((double)i / 65536.0 * 2.0 * PI); /* supervisor sine */ @@ -113,21 +113,21 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor) /* attack (3ms) and recovery time (13.5ms) according to NMT specs */ setup_compandor(&nmt->cstate, 8000, 3.0, 13.5); - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for Transceiver.\n"); /* set modulation parameters */ sender_set_fm(&nmt->sender, MAX_DEVIATION * deviation_factor, MAX_MODULATION * deviation_factor, SPEECH_DEVIATION * deviation_factor, MAX_DISPLAY); - PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation @ 1500 Hz)\n", TX_PEAK_FSK * deviation_factor, 3.5 * deviation_factor); - PDEBUG(DDSP, DEBUG_DEBUG, "Using Supervisory level of %.3f (%.3f KHz deviation @ 4015 Hz)\n", TX_PEAK_SUPER * deviation_factor, 0.3 * deviation_factor); + LOGP(DDSP, LOGL_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation @ 1500 Hz)\n", TX_PEAK_FSK * deviation_factor, 3.5 * deviation_factor); + LOGP(DDSP, LOGL_DEBUG, "Using Supervisory level of %.3f (%.3f KHz deviation @ 4015 Hz)\n", TX_PEAK_SUPER * deviation_factor, 0.3 * deviation_factor); /* init fsk */ if (fsk_mod_init(&nmt->fsk_mod, nmt, fsk_send_bit, nmt->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 1, 0) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } if (fsk_demod_init(&nmt->fsk_demod, nmt, fsk_receive_bit, nmt->sender.samplerate, BIT_RATE, F0, F1, BIT_ADJUST) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } @@ -138,7 +138,7 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor) nmt->super_samples = (int)((double)nmt->sender.samplerate * (1.0 / (SUPER_BANDWIDTH / 2)) + 0.5); spl = calloc(1, nmt->super_samples * sizeof(*spl)); if (!spl) { - PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP(DDSP, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } nmt->super_filter_spl = spl; @@ -170,7 +170,7 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor) /* Cleanup transceiver instance. */ void dsp_cleanup_sender(nmt_t *nmt) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for Transceiver.\n"); fsk_mod_cleanup(&nmt->fsk_mod); fsk_demod_cleanup(&nmt->fsk_demod); @@ -283,7 +283,7 @@ static void super_decode(nmt_t *nmt, sample_t *samples, int length) if (nmt->state == STATE_ACTIVE) { if (++nmt->super_print == SUPER_PRINT) { nmt->super_print = 0; - PDEBUG_CHAN(DDSP, DEBUG_NOTICE, "Supervisory level %.0f%% quality %.0f%%\n", level * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_NOTICE, "Supervisory level %.0f%% quality %.0f%%\n", level * 100.0, quality * 100.0); } /* update measurements (if dmp_* params are NULL, we omit this) */ display_measurements_update(nmt->dmp_super_level, level * 100.0, 0.0); @@ -296,7 +296,7 @@ static void super_decode(nmt_t *nmt, sample_t *samples, int length) if (nmt->super_detect_count == SUPER_DETECT_COUNT) { nmt->super_detected = 1; nmt->super_detect_count = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Supervisory signal detected with level=%.0f%%, quality=%.0f%%.\n", result[0] / 0.63662 / TX_PEAK_SUPER * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Supervisory signal detected with level=%.0f%%, quality=%.0f%%.\n", result[0] / 0.63662 / TX_PEAK_SUPER * 100.0, quality * 100.0); nmt_rx_super(nmt, 1, quality); } } else @@ -307,7 +307,7 @@ static void super_decode(nmt_t *nmt, sample_t *samples, int length) if (nmt->super_detect_count == SUPER_LOST_COUNT) { nmt->super_detected = 0; nmt->super_detect_count = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Supervisory signal lost.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Supervisory signal lost.\n"); nmt_rx_super(nmt, 0, 0.0); } } else @@ -318,7 +318,7 @@ static void super_decode(nmt_t *nmt, sample_t *samples, int length) /* Reset supervisory detection states, so ongoing tone will be detected again. */ void super_reset(nmt_t *nmt) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Supervisory detector reset.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Supervisory detector reset.\n"); nmt->super_detected = 0; nmt->super_detect_count = 0; } @@ -395,7 +395,7 @@ static int fsk_send_bit(void *inst) frame = nmt_get_frame(nmt); if (!frame) { nmt->tx_frame_length = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Stop sending frames.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Stop sending frames.\n"); return -1; } memcpy(nmt->tx_frame, frame, 166); @@ -521,7 +521,7 @@ void nmt_set_dsp_mode(nmt_t *nmt, enum dsp_mode mode) nmt->tx_frame_length = 0; } - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", nmt_dsp_mode_name(nmt->dsp_mode), nmt_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", nmt_dsp_mode_name(nmt->dsp_mode), nmt_dsp_mode_name(mode)); nmt->dsp_mode = mode; } diff --git a/src/nmt/frame.c b/src/nmt/frame.c index 999efdd..cf0707b 100644 --- a/src/nmt/frame.c +++ b/src/nmt/frame.c @@ -23,7 +23,7 @@ #include <string.h> #include <inttypes.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libhagelbarger/hagelbarger.h" #include "nmt.h" #include "frame.h" @@ -854,7 +854,7 @@ int init_frame(void) for (i = 0; nmt_frame[i].digits; i++) { /* check message type */ if ((int)nmt_frame[i].message_type != i) { - PDEBUG(DFRAME, DEBUG_ERROR, "Message type at message index #%d does not have a value of %d, but has %d, please fix!\n", i, i + 1, nmt_frame[i].message_type); + LOGP(DFRAME, LOGL_ERROR, "Message type at message index #%d does not have a value of %d, but has %d, please fix!\n", i, i + 1, nmt_frame[i].message_type); return -1; } /* check IEs */ @@ -867,7 +867,7 @@ int init_frame(void) break; } if (!nmt_parameter[k].digit) { - PDEBUG(DFRAME, DEBUG_ERROR, "Digit '%c' in message index %d does not exist, please fix!\n", digit, i); + LOGP(DFRAME, LOGL_ERROR, "Digit '%c' in message index %d does not exist, please fix!\n", digit, i); return -1; } } @@ -894,7 +894,7 @@ static void disassemble_frame(int nmt_system, frame_t *frame, const uint8_t *dig /* update direction */ direction = nmt_frame[mt].direction; - PDEBUG(DFRAME, DEBUG_DEBUG, "Decoding %s %s %s\n", nmt_dir_name(direction), nmt_frame[mt].nr, nmt_frame[mt].description); + LOGP(DFRAME, LOGL_DEBUG, "Decoding %s %s %s\n", nmt_dir_name(direction), nmt_frame[mt].nr, nmt_frame[mt].description); for (i = 0; i < 16; i++) { digit = nmt_frame[mt].digits[i]; @@ -983,28 +983,28 @@ static void disassemble_frame(int nmt_system, frame_t *frame, const uint8_t *dig frame->waiting_info = value; break; default: - PDEBUG(DFRAME, DEBUG_ERROR, "Digit '%c' does not exist, please fix!\n", digit); + LOGP(DFRAME, LOGL_ERROR, "Digit '%c' does not exist, please fix!\n", digit); abort(); } - if (debuglevel <= DEBUG_DEBUG) { + if (loglevel <= LOGL_DEBUG) { for (j = 0; nmt_parameter[j].digit; j++) { if (nmt_parameter[j].system != 0 && nmt_parameter[j].system != nmt_system) continue; if (nmt_parameter[j].digit == digit) { - PDEBUG(DFRAME, DEBUG_DEBUG, " %c: %s\n", digit, nmt_parameter[j].decoder(value, ndigits, direction)); + LOGP(DFRAME, LOGL_DEBUG, " %c: %s\n", digit, nmt_parameter[j].decoder(value, ndigits, direction)); } } } } - if (debuglevel <= DEBUG_DEBUG) { + if (loglevel <= LOGL_DEBUG) { char debug_digits[17]; for (i = 0; i < 16; i++) debug_digits[i] = "0123456789abcdef"[digits[i]]; debug_digits[i] = '\0'; - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", nmt_frame[mt].digits); - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", debug_digits); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", nmt_frame[mt].digits); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", debug_digits); } } @@ -1020,7 +1020,7 @@ static void assemble_frame(int nmt_system, frame_t *frame, uint8_t *digits, int mt = frame->mt; if ((int)mt >= num_frames) { - PDEBUG(DFRAME, DEBUG_ERROR, "Frame mt %d out of range (0..%d), please fix!\n", mt, num_frames - 1); + LOGP(DFRAME, LOGL_ERROR, "Frame mt %d out of range (0..%d), please fix!\n", mt, num_frames - 1); abort(); } @@ -1031,7 +1031,7 @@ static void assemble_frame(int nmt_system, frame_t *frame, uint8_t *digits, int direction = nmt_frame[mt].direction; if (debug) - PDEBUG(DFRAME, DEBUG_DEBUG, "Coding %s %s %s\n", nmt_dir_name(direction), nmt_frame[mt].nr, nmt_frame[mt].description); + LOGP(DFRAME, LOGL_DEBUG, "Coding %s %s %s\n", nmt_dir_name(direction), nmt_frame[mt].nr, nmt_frame[mt].description); for (i = 15; i >= 0; i--) { digit = nmt_frame[mt].digits[i]; @@ -1113,7 +1113,7 @@ static void assemble_frame(int nmt_system, frame_t *frame, uint8_t *digits, int value = frame->waiting_info; break; default: - PDEBUG(DFRAME, DEBUG_ERROR, "Digit '%c' does not exist, please fix!\n", digit); + LOGP(DFRAME, LOGL_ERROR, "Digit '%c' does not exist, please fix!\n", digit); abort(); } @@ -1127,7 +1127,7 @@ static void assemble_frame(int nmt_system, frame_t *frame, uint8_t *digits, int i--; } } - if (debug && debuglevel <= DEBUG_DEBUG) { + if (debug && loglevel <= LOGL_DEBUG) { char debug_digits[17]; int ndigits; @@ -1148,7 +1148,7 @@ static void assemble_frame(int nmt_system, frame_t *frame, uint8_t *digits, int if (nmt_parameter[j].system != 0 && nmt_parameter[j].system != nmt_system) continue; if (nmt_parameter[j].digit == digit) { - PDEBUG(DFRAME, DEBUG_DEBUG, " %c: %s\n", digit, nmt_parameter[j].decoder(value, ndigits, direction)); + LOGP(DFRAME, LOGL_DEBUG, " %c: %s\n", digit, nmt_parameter[j].decoder(value, ndigits, direction)); } } } @@ -1156,8 +1156,8 @@ static void assemble_frame(int nmt_system, frame_t *frame, uint8_t *digits, int for (i = 0; i < 16; i++) debug_digits[i] = "0123456789abcdef"[digits[i]]; debug_digits[i] = '\0'; - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", nmt_frame[mt].digits); - PDEBUG(DFRAME, DEBUG_DEBUG, "%s\n", debug_digits); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", nmt_frame[mt].digits); + LOGP(DFRAME, LOGL_DEBUG, "%s\n", debug_digits); } } diff --git a/src/nmt/main.c b/src/nmt/main.c index f6ea447..5a5715e 100644 --- a/src/nmt/main.c +++ b/src/nmt/main.c @@ -28,7 +28,7 @@ #include <sys/stat.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "nmt.h" #include "frame.h" @@ -432,6 +432,7 @@ fail: nmt_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/nmt/nmt.c b/src/nmt/nmt.c index 9694372..ece75cc 100644 --- a/src/nmt/nmt.c +++ b/src/nmt/nmt.c @@ -26,9 +26,10 @@ #include <errno.h> #include <time.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include "../libmobile/get_time.h" +#include <osmocom/cc/message.h> #include "nmt.h" #include "transaction.h" #include "dsp.h" @@ -51,13 +52,13 @@ static int sms_ref = 0; /* Timers */ -#define PAGING_TO 1.0 /* wait for paging response: fictive value */ -#define RELEASE_TO 2.0 /* how long do we wait for release guard of the phone */ -#define DIALING_TO 1.0 /* if we have a pause during dialing, we abort the call */ -#define CHANNEL_TO 2.0 /* how long do we wait for phone to appear on assigned channel */ -#define RINGING_TO 60.0 /* how long may the phone ring */ -#define SUPERVISORY_TO1 3.0 /* 3 sec to detect after setup */ -#define SUPERVISORY_TO2 20.0 /* 20 sec lost until abort */ +#define PAGING_TO 1,0 /* wait for paging response: fictive value */ +#define RELEASE_TO 2,0 /* how long do we wait for release guard of the phone */ +#define DIALING_TO 1,0 /* if we have a pause during dialing, we abort the call */ +#define CHANNEL_TO 2,0 /* how long do we wait for phone to appear on assigned channel */ +#define RINGING_TO 60,0 /* how long may the phone ring */ +#define SUPERVISORY_TO1 3 /* 3 sec to detect after setup */ +#define SUPERVISORY_TO2 20,0 /* 20 sec lost until abort */ #define DTMF_DURATION 0.1 /* 100ms */ /* Counters */ @@ -127,7 +128,7 @@ static void nmt_new_state(nmt_t *nmt, enum nmt_state new_state) { if (nmt->state == new_state) return; - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "State change: %s -> %s\n", nmt_state_name(nmt->state), nmt_state_name(new_state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "State change: %s -> %s\n", nmt_state_name(nmt->state), nmt_state_name(new_state)); nmt->state = new_state; nmt_display_status(); } @@ -226,11 +227,11 @@ const char *nmt_dir_name(enum nmt_direction dir) static int dialstring2number(const char *dialstring, char *ms_country, char *ms_number) { if (strlen(dialstring) != 7) { - PDEBUG(DNMT, DEBUG_NOTICE, "Wrong number of digits, use 7 digits: ZXXXXXX (Z=country, X=mobile number)\n"); + LOGP(DNMT, LOGL_NOTICE, "Wrong number of digits, use 7 digits: ZXXXXXX (Z=country, X=mobile number)\n"); return -1; } if (dialstring[0] < '0' || dialstring[0] > '9') { - PDEBUG(DNMT, DEBUG_NOTICE, "Invalid country digit (first digit) of dial string\n"); + LOGP(DNMT, LOGL_NOTICE, "Invalid country digit (first digit) of dial string\n"); return -1; } *ms_country = dialstring[0]; @@ -272,46 +273,46 @@ int nmt_create(int nmt_system, const char *country, const char *kanal, enum nmt_ /* check channel matching and set deviation factor */ if (nmt_channel2freq(nmt_system, country, atoi(kanal), 0, &deviation_factor, &scandinavia, &tested) == 0.0) { - PDEBUG(DNMT, DEBUG_NOTICE, "Channel number %s invalid, use '-Y list' to get a list of available channels.\n", kanal); + LOGP(DNMT, LOGL_NOTICE, "Channel number %s invalid, use '-Y list' to get a list of available channels.\n", kanal); return -EINVAL; } if (!tested) { - PDEBUG(DNMT, DEBUG_NOTICE, "*** The given NMT country has not been tested yet. Please tell the Author, if it works.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** The given NMT country has not been tested yet. Please tell the Author, if it works.\n"); } if (scandinavia && atoi(kanal) >= 201) { - PDEBUG(DNMT, DEBUG_NOTICE, "*** Channels numbers above 200 have been specified, but never used. These 'interleaved channels are probably not supports by the phone.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Channels numbers above 200 have been specified, but never used. These 'interleaved channels are probably not supports by the phone.\n"); } if (scandinavia && atoi(kanal) >= 181 && atoi(kanal) <= 200) { - PDEBUG(DNMT, DEBUG_NOTICE, "Extended channel numbers (181..200) have been specified, but never been supported for sure. There is no phone to test with, so don't use it!\n"); + LOGP(DNMT, LOGL_NOTICE, "Extended channel numbers (181..200) have been specified, but never been supported for sure. There is no phone to test with, so don't use it!\n"); } if (chan_type == CHAN_TYPE_TEST && !loopback) { - PDEBUG(DNMT, DEBUG_NOTICE, "*** Selected channel can be used for nothing but testing signal decoder.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Selected channel can be used for nothing but testing signal decoder.\n"); } if (chan_type == CHAN_TYPE_CC_TC && send_clock) { - PDEBUG(DNMT, DEBUG_NOTICE, "*** Sending clock on combined CC + TC is not applicable.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Sending clock on combined CC + TC is not applicable.\n"); } nmt = calloc(1, sizeof(nmt_t)); if (!nmt) { - PDEBUG(DNMT, DEBUG_ERROR, "No memory!\n"); + LOGP(DNMT, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DNMT, DEBUG_DEBUG, "Creating 'NMT' instance for channel = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DNMT, LOGL_DEBUG, "Creating 'NMT' instance for channel = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&nmt->sender, kanal, nmt_channel2freq(nmt_system, country, atoi(kanal), 0, NULL, NULL, NULL), nmt_channel2freq(nmt_system, country, atoi(kanal), 1, NULL, NULL, NULL), device, use_sdr, samplerate, rx_gain, tx_gain, pre_emphasis, de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DNMT, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DNMT, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } - timer_init(&nmt->timer, nmt_timeout, nmt); + osmo_timer_setup(&nmt->timer, nmt_timeout, nmt); nmt->sysinfo.system = nmt_system; nmt->sysinfo.chan_type = chan_type; nmt->sysinfo.ms_power = ms_power; @@ -326,35 +327,35 @@ int nmt_create(int nmt_system, const char *country, const char *kanal, enum nmt_ /* init audio processing */ rc = dsp_init_sender(nmt, deviation_factor); if (rc < 0) { - PDEBUG(DNMT, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DNMT, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } /* init DMS processing */ rc = dms_init_sender(nmt); if (rc < 0) { - PDEBUG(DNMT, DEBUG_ERROR, "Failed to init DMS processing!\n"); + LOGP(DNMT, LOGL_ERROR, "Failed to init DMS processing!\n"); goto error; } /* init SMS processing */ rc = sms_init_sender(nmt); if (rc < 0) { - PDEBUG(DNMT, DEBUG_ERROR, "Failed to init SMS processing!\n"); + LOGP(DNMT, LOGL_ERROR, "Failed to init SMS processing!\n"); goto error; } /* go into idle state */ nmt_go_idle(nmt); - PDEBUG(DNMT, DEBUG_NOTICE, "Created channel #%s of type '%s' = %s\n", kanal, chan_type_short_name(nmt_system, chan_type), chan_type_long_name(nmt_system, chan_type)); + LOGP(DNMT, LOGL_NOTICE, "Created channel #%s of type '%s' = %s\n", kanal, chan_type_short_name(nmt_system, chan_type), chan_type_long_name(nmt_system, chan_type)); if (nmt_long_name_by_short_name(nmt_system, country)) - PDEBUG(DNMT, DEBUG_NOTICE, " -> Using country '%s'\n", nmt_long_name_by_short_name(nmt_system, country)); - PDEBUG(DNMT, DEBUG_NOTICE, " -> Using traffic area %d,%d and area no %d\n", traffic_area >> 4, (nmt_system == 450) ? nmt_flip_ten((traffic_area & 0xf)) : (traffic_area & 0xf), area_no); + LOGP(DNMT, LOGL_NOTICE, " -> Using country '%s'\n", nmt_long_name_by_short_name(nmt_system, country)); + LOGP(DNMT, LOGL_NOTICE, " -> Using traffic area %d,%d and area no %d\n", traffic_area >> 4, (nmt_system == 450) ? nmt_flip_ten((traffic_area & 0xf)) : (traffic_area & 0xf), area_no); if (nmt->supervisory) - PDEBUG(DNMT, DEBUG_NOTICE, " -> Using supervisory signal %d\n", supervisory); + LOGP(DNMT, LOGL_NOTICE, " -> Using supervisory signal %d\n", supervisory); else - PDEBUG(DNMT, DEBUG_NOTICE, " -> Using no supervisory signal\n"); + LOGP(DNMT, LOGL_NOTICE, " -> Using no supervisory signal\n"); return 0; @@ -392,35 +393,35 @@ void nmt_check_channels(int __attribute__((unused)) nmt_system) } } if ((cca || ccb) && !tc) { - PDEBUG(DNMT, DEBUG_NOTICE, "\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Selected channel(s) can be used for control only.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** No registration and no call is possible.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Use at least one 'TC' or use combined 'CC/TC'!\n"); + LOGP(DNMT, LOGL_NOTICE, "\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Selected channel(s) can be used for control only.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** No registration and no call is possible.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Use at least one 'TC' or use combined 'CC/TC'!\n"); note = 1; } if (tc && !(cca || ccb)) { - PDEBUG(DNMT, DEBUG_NOTICE, "\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Selected channel(s) can be used for traffic only.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** No call to the mobile phone is possible.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Use one 'CC' or use combined 'CC/TC'!\n"); + LOGP(DNMT, LOGL_NOTICE, "\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Selected channel(s) can be used for traffic only.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** No call to the mobile phone is possible.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Use one 'CC' or use combined 'CC/TC'!\n"); note = 1; } if (cca && !ccb) { - PDEBUG(DNMT, DEBUG_NOTICE, "\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Selected channel(s) can be used for control of MS type A only.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** No call to the MS type B phone is possible.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Use one 'CC' instead!\n"); + LOGP(DNMT, LOGL_NOTICE, "\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Selected channel(s) can be used for control of MS type A only.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** No call to the MS type B phone is possible.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Use one 'CC' instead!\n"); note = 1; } if (!cca && ccb) { - PDEBUG(DNMT, DEBUG_NOTICE, "\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Selected channel(s) can be used for control of MS type B only.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** No call to the MS type A phone is possible.\n"); - PDEBUG(DNMT, DEBUG_NOTICE, "*** Use one 'CC' instead!\n"); + LOGP(DNMT, LOGL_NOTICE, "\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Selected channel(s) can be used for control of MS type B only.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** No call to the MS type A phone is possible.\n"); + LOGP(DNMT, LOGL_NOTICE, "*** Use one 'CC' instead!\n"); note = 1; } if (note) - PDEBUG(DNMT, DEBUG_NOTICE, "\n"); + LOGP(DNMT, LOGL_NOTICE, "\n"); } /* Destroy transceiver instance and unlink from list. */ @@ -428,11 +429,11 @@ void nmt_destroy(sender_t *sender) { nmt_t *nmt = (nmt_t *) sender; - PDEBUG(DNMT, DEBUG_DEBUG, "Destroying 'NMT' instance for channel = %s.\n", sender->kanal); + LOGP(DNMT, LOGL_DEBUG, "Destroying 'NMT' instance for channel = %s.\n", sender->kanal); dsp_cleanup_sender(nmt); dms_cleanup_sender(nmt); sms_cleanup_sender(nmt); - timer_exit(&nmt->timer); + osmo_timer_del(&nmt->timer); sender_destroy(&nmt->sender); free(nmt); } @@ -440,11 +441,11 @@ void nmt_destroy(sender_t *sender) /* Abort connection towards mobile station by sending idle digits. */ void nmt_go_idle(nmt_t *nmt) { - timer_stop(&nmt->timer); + osmo_timer_del(&nmt->timer); dms_reset(nmt); sms_reset(nmt); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Entering IDLE state, sending idle frames on %s.\n", chan_type_long_name(nmt->sysinfo.system, nmt->sysinfo.chan_type)); + LOGP_CHAN(DNMT, LOGL_INFO, "Entering IDLE state, sending idle frames on %s.\n", chan_type_long_name(nmt->sysinfo.system, nmt->sysinfo.chan_type)); nmt->trans = NULL; /* remove transaction before state change, so status is shown correctly */ nmt_new_state(nmt, STATE_IDLE); nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); @@ -462,17 +463,17 @@ static void nmt_release(nmt_t *nmt) { transaction_t *trans = nmt->trans; - timer_stop(&nmt->timer); + osmo_timer_del(&nmt->timer); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Releasing connection towards mobile station.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Releasing connection towards mobile station.\n"); if (trans->callref) { - PDEBUG_CHAN(DNMT, DEBUG_ERROR, "Callref already set, please fix!\n"); + LOGP_CHAN(DNMT, LOGL_ERROR, "Callref already set, please fix!\n"); abort(); } nmt_new_state(nmt, STATE_MT_RELEASE); nmt->tx_frame_count = 0; nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); - timer_start(&nmt->timer, RELEASE_TO); + osmo_timer_schedule(&nmt->timer, RELEASE_TO); } /* Enter paging state and transmit phone's number on calling channel */ @@ -481,9 +482,9 @@ static void nmt_page(transaction_t *trans, int try) sender_t *sender; nmt_t *nmt; - PDEBUG(DNMT, DEBUG_INFO, "Entering paging state (try %d), sending call to '%c,%s'.\n", try, trans->subscriber.country, trans->subscriber.number); + LOGP(DNMT, LOGL_INFO, "Entering paging state (try %d), sending call to '%c,%s'.\n", try, trans->subscriber.country, trans->subscriber.number); trans->page_try = try; - timer_start(&trans->timer, PAGING_TO); + osmo_timer_schedule(&trans->timer, PAGING_TO); /* page on all CC (CC/TC) */ for (sender = sender_head; sender; sender = sender->next) { nmt = (nmt_t *)sender; @@ -492,7 +493,7 @@ static void nmt_page(transaction_t *trans, int try) /* page on all idle channels and on channels we previously paged */ if (nmt->state != STATE_IDLE && nmt->trans != trans) continue; - PDEBUG(DNMT, DEBUG_INFO, "Paging on channel %s.\n", sender->kanal); + LOGP(DNMT, LOGL_INFO, "Paging on channel %s.\n", sender->kanal); nmt->trans = trans; /* add transaction before state change, so status is shown correctly */ nmt_new_state(nmt, STATE_MT_PAGING); nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); @@ -535,12 +536,12 @@ static int match_channel(nmt_t *nmt, frame_t *frame) /* check channel match */ rc = nmt_decode_channel(nmt->sysinfo.system, frame->channel_no, &channel, &power); if (rc < 0) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Frame with illegal encoded channel received, ignoring.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Frame with illegal encoded channel received, ignoring.\n"); return 0; } /* in case of interleaved channel, ignore the missing upper bit */ if ((channel % 1024) != (atoi(nmt->sender.kanal) % 1024)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Frame for different channel %d received, ignoring.\n", channel); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Frame for different channel %d received, ignoring.\n", channel); return 0; } @@ -559,13 +560,13 @@ static int match_area(nmt_t *nmt, frame_t *frame) if (area_no == 0 && nmt->sysinfo.area_no != 0) area_no = 4; if (area_no != nmt->sysinfo.area_no) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Received area no (%d) does not match the base station's area no (%d), ignoring.\n", area_no, nmt->sysinfo.area_no); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Received area no (%d) does not match the base station's area no (%d), ignoring.\n", area_no, nmt->sysinfo.area_no); return 0; } traffic_area = ((frame->area_info & 0x3) << 4) | frame->traffic_area; if (nmt->sysinfo.traffic_area != 0 && (nmt->sysinfo.traffic_area & 0x3f) != traffic_area) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Received 6 bits of traffic area (0x%02x) does not match the 6 bits of base station's traffic area (0x%02x), ignoring.\n", nmt->sysinfo.traffic_area & 0x3f, traffic_area); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Received 6 bits of traffic area (0x%02x) does not match the 6 bits of base station's traffic area (0x%02x), ignoring.\n", nmt->sysinfo.traffic_area & 0x3f, traffic_area); return 0; } skip_area: @@ -577,11 +578,11 @@ skip_area: static int match_subscriber(transaction_t *trans, frame_t *frame) { if (nmt_digits2value(&trans->subscriber.country, 1) != frame->ms_country) { - PDEBUG(DNMT, DEBUG_NOTICE, "Received non matching subscriber counrtry, ignoring.\n"); + LOGP(DNMT, LOGL_NOTICE, "Received non matching subscriber counrtry, ignoring.\n"); return 0; } if (nmt_digits2value(trans->subscriber.number, 6) != frame->ms_number) { - PDEBUG(DNMT, DEBUG_NOTICE, "Received non matching subscriber number, ignoring.\n"); + LOGP(DNMT, LOGL_NOTICE, "Received non matching subscriber number, ignoring.\n"); return 0; } @@ -692,12 +693,12 @@ static void rx_idle(nmt_t *nmt, frame_t *frame) nmt_value2digits(frame->ms_country, &subscr.country, 1); nmt_value2digits(frame->ms_number, subscr.number, 6); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received roaming seizure from subscriber %c,%s\n", subscr.country, subscr.number); + LOGP_CHAN(DNMT, LOGL_INFO, "Received roaming seizure from subscriber %c,%s\n", subscr.country, subscr.number); /* create transaction */ trans = create_transaction(&subscr); if (!trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "Failed to create transaction!\n"); + LOGP(DNMT, LOGL_NOTICE, "Failed to create transaction!\n"); break; } @@ -722,12 +723,12 @@ static void rx_idle(nmt_t *nmt, frame_t *frame) if (frame->mt == NMT_MESSAGE_12) subscr.coinbox = 1; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received call from subscriber %c,%s%s\n", subscr.country, subscr.number, (subscr.coinbox) ? " (coinbox)" : ""); + LOGP_CHAN(DNMT, LOGL_INFO, "Received call from subscriber %c,%s%s\n", subscr.country, subscr.number, (subscr.coinbox) ? " (coinbox)" : ""); /* create transaction */ trans = create_transaction(&subscr); if (!trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "Failed to create transaction!\n"); + LOGP(DNMT, LOGL_NOTICE, "Failed to create transaction!\n"); break; } @@ -742,7 +743,7 @@ static void rx_idle(nmt_t *nmt, frame_t *frame) case NMT_MESSAGE_13a: /* line signal */ break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -753,10 +754,10 @@ static void rx_idle(nmt_t *nmt, frame_t *frame) static void tx_roaming_ident(nmt_t *nmt, frame_t *frame) { if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Sending identity request.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Sending identity request.\n"); tx_ident(nmt, frame); if (nmt->tx_frame_count == 8) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout waiting for identity reply\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout waiting for identity reply\n"); nmt_release(nmt); } } @@ -774,16 +775,16 @@ static void rx_roaming_ident(nmt_t *nmt, frame_t *frame) if (!match_subscriber(trans, frame)) break; if (nmt->rx_frame_count < 2) { - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Skipping second seizure frame\n"); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Skipping second seizure frame\n"); break; } nmt_value2digits(frame->ms_password, trans->subscriber.password, 3); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received identity confirm (password %s).\n", trans->subscriber.password); + LOGP_CHAN(DNMT, LOGL_INFO, "Received identity confirm (password %s).\n", trans->subscriber.password); nmt_new_state(nmt, STATE_ROAMING_CONFIRM); nmt->tx_frame_count = 0; break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -791,7 +792,7 @@ static void tx_roaming_confirm(nmt_t *nmt, frame_t *frame) { set_line_signal(nmt, frame, 3); if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'Roaming updating confirmation'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'Roaming updating confirmation'.\n"); if (nmt->tx_frame_count == 2) nmt_release(nmt); /* continue with this frame, then release */ } @@ -800,7 +801,7 @@ static void rx_roaming_confirm(nmt_t *nmt, frame_t *frame) { switch (frame->mt) { default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -811,10 +812,10 @@ static void rx_roaming_confirm(nmt_t *nmt, frame_t *frame) static void tx_mo_ident(nmt_t *nmt, frame_t *frame) { if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Sending identity request.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Sending identity request.\n"); tx_ident(nmt, frame); if (nmt->tx_frame_count == 8) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout waiting for identity reply\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout waiting for identity reply\n"); nmt_release(nmt); } } @@ -831,16 +832,16 @@ static void rx_mo_ident(nmt_t *nmt, frame_t *frame) if (!match_subscriber(trans, frame)) break; if (nmt->rx_frame_count < 2) { - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Skipping second seizure frame\n"); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Skipping second seizure frame\n"); break; } nmt_value2digits(frame->ms_password, trans->subscriber.password, 3); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received identity confirm (password %s).\n", trans->subscriber.password); + LOGP_CHAN(DNMT, LOGL_INFO, "Received identity confirm (password %s).\n", trans->subscriber.password); nmt_new_state(nmt, STATE_MO_CONFIRM); nmt->tx_frame_count = 0; break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -849,13 +850,13 @@ static void tx_mo_confirm(nmt_t *nmt, frame_t *frame) set_line_signal(nmt, frame, 3); if (++nmt->tx_frame_count <= 2) { if (nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'Proceed to send'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'Proceed to send'.\n"); } else { if (nmt->tx_frame_count == 3) { - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send dial tone.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send dial tone.\n"); nmt_new_state(nmt, STATE_MO_DIALING); nmt_set_dsp_mode(nmt, DSP_MODE_DIALTONE); - timer_start(&nmt->timer, DIALING_TO); + osmo_timer_schedule(&nmt->timer, DIALING_TO); } } } @@ -873,7 +874,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) break; if (!match_subscriber(trans, frame)) break; - timer_start(&nmt->timer, DIALING_TO); + osmo_timer_schedule(&nmt->timer, DIALING_TO); /* max digits received */ if (len + 1 == sizeof(nmt->dialing)) break; @@ -894,7 +895,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) goto not_consistent_digit; nmt->dialing[len] = nmt_value2digit(frame->digit); nmt->dialing[len + 1] = '\0'; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (odd) digit %c.\n", nmt->dialing[len]); + LOGP_CHAN(DNMT, LOGL_INFO, "Received (odd) digit %c.\n", nmt->dialing[len]); nmt->rx_frame_count = 0; /* finish dial tone after first digit */ if (!len) @@ -907,7 +908,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) break; if (!match_subscriber(trans, frame)) break; - timer_start(&nmt->timer, DIALING_TO); + osmo_timer_schedule(&nmt->timer, DIALING_TO); /* max digits received */ if (len + 1 == sizeof(nmt->dialing)) break; @@ -931,7 +932,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) goto not_consistent_digit; nmt->dialing[len] = nmt_value2digit(frame->digit); nmt->dialing[len + 1] = '\0'; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (even) digit %c.\n", nmt->dialing[len]); + LOGP_CHAN(DNMT, LOGL_INFO, "Received (even) digit %c.\n", nmt->dialing[len]); nmt->rx_frame_count = 0; break; case NMT_MESSAGE_15: /* idle */ @@ -939,7 +940,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) break; if (nmt->dialing[0] == 'A') { nmt->dialing[0] = '+'; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Dialing includes international '+' sign at the beginning.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Dialing includes international '+' sign at the beginning.\n"); } if (nmt->dialing[0] == 'B') { const char *code = NULL; @@ -979,42 +980,42 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) break; } if (code) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Dialing includes service code: '%c%c' = '%s'\n", nmt->dialing[0], nmt->dialing[1], code); + LOGP_CHAN(DNMT, LOGL_INFO, "Dialing includes service code: '%c%c' = '%s'\n", nmt->dialing[0], nmt->dialing[1], code); } - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Dialing complete %s->%s, call established.\n", &trans->subscriber.country, nmt->dialing); + LOGP_CHAN(DNMT, LOGL_INFO, "Dialing complete %s->%s, call established.\n", &trans->subscriber.country, nmt->dialing); if (nmt->dialing[0] == 'B') nmt->dialing[0] = '+'; /* setup call */ if (!strcmp(nmt->dialing, nmt->smsc_number)) { /* SMS */ - PDEBUG(DNMT, DEBUG_INFO, "Setup call to SMSC.\n"); + LOGP(DNMT, LOGL_INFO, "Setup call to SMSC.\n"); trans->dms_call = 1; } else { - PDEBUG(DNMT, DEBUG_INFO, "Setup call to network.\n"); + LOGP(DNMT, LOGL_INFO, "Setup call to network.\n"); trans->callref = call_up_setup(&trans->subscriber.country, nmt->dialing, OSMO_CC_NETWORK_NMT_NONE, ""); } - timer_stop(&nmt->timer); + osmo_timer_del(&nmt->timer); nmt_new_state(nmt, STATE_MO_COMPLETE); nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); nmt->tx_frame_count = 0; break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } return; missing_digit: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Missing digit, aborting.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Missing digit, aborting.\n"); nmt_release(nmt); return; not_right_position: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Position information of digit does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Position information of digit does not match, ignoring due to corrupt frame.\n"); return; not_consistent_digit: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Digit repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Digit repetition in frame does not match, ignoring due to corrupt frame.\n"); return; } @@ -1025,22 +1026,22 @@ static void tx_mo_complete(nmt_t *nmt, frame_t *frame) if (++nmt->tx_frame_count <= 4) { set_line_signal(nmt, frame, 6); if (nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'address complete'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'address complete'.\n"); } else { if (nmt->compandor) { set_line_signal(nmt, frame, 5); if (nmt->tx_frame_count == 5) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'compandor in'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'compandor in'.\n"); } else frame->mt = NMT_MESSAGE_6; if (nmt->tx_frame_count == 9) { - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Connect audio.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Connect audio.\n"); nmt_new_state(nmt, STATE_ACTIVE); nmt->active_state = ACTIVE_STATE_VOICE; nmt_set_dsp_mode(nmt, DSP_MODE_AUDIO); if (nmt->supervisory && !trans->dms_call) { super_reset(nmt); - timer_start(&nmt->timer, SUPERVISORY_TO1); + osmo_timer_schedule(&nmt->timer, SUPERVISORY_TO1,0); } } } @@ -1048,9 +1049,9 @@ static void tx_mo_complete(nmt_t *nmt, frame_t *frame) static void timeout_mo_dialing(nmt_t *nmt) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout while receiving digits.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout while receiving digits.\n"); nmt_release(nmt); - PDEBUG(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP(DNMT, LOGL_INFO, "Release call towards network.\n"); } /* @@ -1067,16 +1068,16 @@ static void tx_mt_paging(nmt_t *nmt, frame_t *frame) frame->ms_number = nmt_digits2value(trans->subscriber.number, 6); frame->additional_info = nmt_encode_area_no(nmt->sysinfo.area_no); if (++nmt->tx_frame_count == 1) { - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send call to mobile.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send call to mobile.\n"); } else tx_idle(nmt, frame); } void timeout_mt_paging(transaction_t *trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "No answer from mobile phone (try %d).\n", trans->page_try); + LOGP(DNMT, LOGL_NOTICE, "No answer from mobile phone (try %d).\n", trans->page_try); if (trans->page_try == PAGE_TRIES) { - PDEBUG(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP(DNMT, LOGL_INFO, "Release call towards network.\n"); call_up_release(trans->callref, CAUSE_OUTOFORDER); destroy_transaction(trans); return; @@ -1097,10 +1098,10 @@ static void rx_mt_paging(nmt_t *nmt, frame_t *frame) break; if (!match_subscriber(trans, frame)) break; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received call acknowledgment from subscriber %c,%s.\n", trans->subscriber.country, trans->subscriber.number); + LOGP_CHAN(DNMT, LOGL_INFO, "Received call acknowledgment from subscriber %c,%s.\n", trans->subscriber.country, trans->subscriber.number); if (trans->sms_string[0]) trans->dms_call = 1; - timer_stop(&trans->timer); + osmo_timer_del(&trans->timer); nmt_new_state(nmt, STATE_MT_CHANNEL); trans->nmt = nmt; nmt->tx_frame_count = 0; @@ -1114,7 +1115,7 @@ static void rx_mt_paging(nmt_t *nmt, frame_t *frame) } break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -1126,8 +1127,8 @@ static void tx_mt_channel(nmt_t *nmt, frame_t *frame) /* get free channel (after releasing all channels) */ tc = search_free_tc(nmt); if (!tc) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "TC is not free anymore.\n"); - PDEBUG(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "TC is not free anymore.\n"); + LOGP(DNMT, LOGL_INFO, "Release call towards network.\n"); call_up_release(trans->callref, CAUSE_NOCHANNEL); trans->callref = 0; nmt_release(nmt); @@ -1138,12 +1139,12 @@ static void tx_mt_channel(nmt_t *nmt, frame_t *frame) if (nmt != tc) { /* link trans and tc together, so we can continue with channel assignment */ - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Switching to TC channel #%s.\n", tc->sender.kanal); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Switching to TC channel #%s.\n", tc->sender.kanal); nmt_go_idle(nmt); tc->trans = trans; trans->nmt = tc; } else - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Staying on CC/TC channel #%s.\n", tc->sender.kanal); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Staying on CC/TC channel #%s.\n", tc->sender.kanal); nmt_new_state(tc, STATE_MT_IDENT); tc->tx_frame_count = 0; @@ -1154,7 +1155,7 @@ static void tx_mt_channel(nmt_t *nmt, frame_t *frame) frame->ms_country = nmt_digits2value(&trans->subscriber.country, 1); frame->ms_number = nmt_digits2value(trans->subscriber.number, 6); frame->tc_no = nmt_encode_tc(tc->sysinfo.system, atoi(tc->sender.kanal), tc->sysinfo.ms_power); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send channel activation to mobile.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send channel activation to mobile.\n"); } static void tx_mt_ident(nmt_t *nmt, frame_t *frame) @@ -1162,11 +1163,11 @@ static void tx_mt_ident(nmt_t *nmt, frame_t *frame) transaction_t *trans = nmt->trans; if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Sending identity request.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Sending identity request.\n"); tx_ident(nmt, frame); if (nmt->tx_frame_count == 8) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout waiting for identity reply\n"); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout waiting for identity reply\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Release call towards network.\n"); call_up_release(trans->callref, CAUSE_TEMPFAIL); destroy_transaction(trans); } @@ -1181,7 +1182,7 @@ static void rx_mt_ident(nmt_t *nmt, frame_t *frame) if (!match_subscriber(trans, frame)) break; nmt_value2digits(frame->ms_password, trans->subscriber.password, 3); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received identity (password %s).\n", trans->subscriber.password); + LOGP_CHAN(DNMT, LOGL_INFO, "Received identity (password %s).\n", trans->subscriber.password); if (trans->dms_call) { nmt_new_state(nmt, STATE_MT_AUTOANSWER); nmt->wait_autoanswer = 1; @@ -1196,12 +1197,12 @@ static void rx_mt_ident(nmt_t *nmt, frame_t *frame) nmt->tx_frame_count = 0; nmt->tx_callerid_count = 0; } - timer_start(&nmt->timer, RINGING_TO); + osmo_timer_schedule(&nmt->timer, RINGING_TO); call_up_alerting(trans->callref); } break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -1215,14 +1216,14 @@ static void tx_mt_autoanswer(nmt_t *nmt, frame_t *frame) return; } if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'autoanswer order'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'autoanswer order'.\n"); set_line_signal(nmt, frame, 12); if (nmt->tx_frame_count == 4) { - PDEBUG_CHAN(DNMT, DEBUG_INFO, "No reaction to autoanswer, proceed with ringing.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "No reaction to autoanswer, proceed with ringing.\n"); nmt_new_state(nmt, STATE_MT_RINGING); nmt->tx_frame_count = 0; nmt->tx_callerid_count = 0; - timer_start(&nmt->timer, RINGING_TO); + osmo_timer_schedule(&nmt->timer, RINGING_TO); call_up_alerting(trans->callref); } } @@ -1244,18 +1245,18 @@ static void rx_mt_autoanswer(nmt_t *nmt, frame_t *frame) || ((frame->line_signal >> 12) & 0xf) != ((frame->line_signal >> 8) & 0xf) || ((frame->line_signal >> 8) & 0xf) != ((frame->line_signal >> 4) & 0xf) || ((frame->line_signal >> 4) & 0xf) != (frame->line_signal & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); break; } if ((frame->line_signal & 0xf) != 12) break; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received acknowledge to autoanswer.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Received acknowledge to autoanswer.\n"); nmt_new_state(nmt, STATE_MT_COMPLETE); nmt->tx_frame_count = 0; call_up_answer(trans->callref, &trans->subscriber.country); break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -1265,11 +1266,11 @@ static void tx_mt_ringing(nmt_t *nmt, frame_t *frame) set_line_signal(nmt, frame, 9); if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'ringing order'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'ringing order'.\n"); if (nmt->tx_frame_count >= 4) { if (nmt->tx_callerid_count) { if (nmt->tx_frame_count == 5) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'A-number'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'A-number'.\n"); nmt_encode_a_number(frame, nmt->tx_frame_count - 4, trans->caller_type, trans->caller_id, nmt->sysinfo.system, atoi(nmt->sender.kanal), nmt->sysinfo.ms_power, nmt->sysinfo.traffic_area); } else frame->mt = NMT_MESSAGE_6; @@ -1302,19 +1303,19 @@ static void rx_mt_ringing(nmt_t *nmt, frame_t *frame) || ((frame->line_signal >> 12) & 0xf) != ((frame->line_signal >> 8) & 0xf) || ((frame->line_signal >> 8) & 0xf) != ((frame->line_signal >> 4) & 0xf) || ((frame->line_signal >> 4) & 0xf) != (frame->line_signal & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); break; } if ((frame->line_signal & 0xf) != 14) break; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received 'answer' from phone.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Received 'answer' from phone.\n"); nmt_new_state(nmt, STATE_MT_COMPLETE); nmt->tx_frame_count = 0; - timer_stop(&nmt->timer); + osmo_timer_del(&nmt->timer); call_up_answer(trans->callref, &trans->subscriber.country); break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -1325,18 +1326,18 @@ static void tx_mt_complete(nmt_t *nmt, frame_t *frame) ++nmt->tx_frame_count; if (nmt->compandor && !trans->dms_call) { if (nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'compandor in'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'compandor in'.\n"); set_line_signal(nmt, frame, 5); } else frame->mt = NMT_MESSAGE_6; if (nmt->tx_frame_count == 5) { - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Connect audio.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Connect audio.\n"); nmt_new_state(nmt, STATE_ACTIVE); nmt->active_state = ACTIVE_STATE_VOICE; nmt_set_dsp_mode(nmt, DSP_MODE_AUDIO); if (nmt->supervisory && !trans->dms_call) { super_reset(nmt); - timer_start(&nmt->timer, SUPERVISORY_TO1); + osmo_timer_schedule(&nmt->timer, SUPERVISORY_TO1,0); } if (trans->dms_call) { time_t ti = time(NULL); @@ -1349,8 +1350,8 @@ static void timeout_mt_ringing(nmt_t *nmt) { transaction_t *trans = nmt->trans; - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout while waiting for answer of the phone.\n"); - PDEBUG(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout while waiting for answer of the phone.\n"); + LOGP(DNMT, LOGL_INFO, "Release call towards network.\n"); call_up_release(trans->callref, CAUSE_NOANSWER); trans->callref = 0; nmt_release(nmt); @@ -1366,7 +1367,7 @@ static void tx_mo_release(nmt_t *nmt, frame_t *frame) set_line_signal(nmt, frame, 15); if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send release.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send release.\n"); if (nmt->tx_frame_count == 4) destroy_transaction(trans); /* continue with this frame, then go idle */ } @@ -1379,7 +1380,7 @@ static void tx_mt_release(nmt_t *nmt, frame_t *frame) { set_line_signal(nmt, frame, 15); if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send release.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send release.\n"); } static void rx_mt_release(nmt_t *nmt, frame_t *frame) @@ -1396,17 +1397,17 @@ static void rx_mt_release(nmt_t *nmt, frame_t *frame) || ((frame->line_signal >> 12) & 0xf) != ((frame->line_signal >> 8) & 0xf) || ((frame->line_signal >> 8) & 0xf) != ((frame->line_signal >> 4) & 0xf) || ((frame->line_signal >> 4) & 0xf) != (frame->line_signal & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); break; } if ((frame->line_signal & 0xf) != 1) break; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received release guard.\n"); - timer_stop(&nmt->timer); + LOGP_CHAN(DNMT, LOGL_INFO, "Received release guard.\n"); + osmo_timer_del(&nmt->timer); destroy_transaction(trans); break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -1414,7 +1415,7 @@ static void timeout_mt_release(nmt_t *nmt) { transaction_t *trans = nmt->trans; - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout while releasing.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout while releasing.\n"); destroy_transaction(trans); } @@ -1425,9 +1426,9 @@ static void timeout_mt_release(nmt_t *nmt) void nmt_rx_super(nmt_t *nmt, int tone, double quality) { if (tone) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Detected supervisory signal with quality=%.0f.\n", quality * 100.0); + LOGP_CHAN(DNMT, LOGL_INFO, "Detected supervisory signal with quality=%.0f.\n", quality * 100.0); else - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Lost supervisory signal\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Lost supervisory signal\n"); if (nmt->sender.loopback) return; @@ -1437,20 +1438,20 @@ void nmt_rx_super(nmt_t *nmt, int tone, double quality) return; if (tone) - timer_stop(&nmt->timer); + osmo_timer_del(&nmt->timer); else - timer_start(&nmt->timer, SUPERVISORY_TO2); + osmo_timer_schedule(&nmt->timer, SUPERVISORY_TO2); } -static void timeout_active(nmt_t *nmt, double duration) +static void timeout_active(nmt_t *nmt, int duration) { transaction_t *trans = nmt->trans; if (duration == SUPERVISORY_TO1) - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout after %.0f seconds not receiving supervisory signal.\n", duration); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout after %d seconds not receiving supervisory signal.\n", duration); else - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Timeout after %.0f seconds loosing supervisory signal.\n", duration); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Timeout after %d seconds loosing supervisory signal.\n", duration); + LOGP_CHAN(DNMT, LOGL_INFO, "Release call towards network.\n"); call_up_release(trans->callref, CAUSE_TEMPFAIL); trans->callref = 0; nmt_release(nmt); @@ -1463,7 +1464,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame) /* restart timer on every reception of frame */ if (nmt->supervisory) - timer_start(&nmt->timer, SUPERVISORY_TO2); + osmo_timer_schedule(&nmt->timer, SUPERVISORY_TO2); switch (frame->mt) { case NMT_MESSAGE_13a: /* line signal */ @@ -1475,17 +1476,17 @@ static void rx_active(nmt_t *nmt, frame_t *frame) || ((frame->line_signal >> 12) & 0xf) != ((frame->line_signal >> 8) & 0xf) || ((frame->line_signal >> 8) & 0xf) != ((frame->line_signal >> 4) & 0xf) || ((frame->line_signal >> 4) & 0xf) != (frame->line_signal & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); break; } switch ((frame->line_signal & 0xf)) { case 5: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Register Recall is not supported.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Register Recall is not supported.\n"); break; case 8: if (nmt->active_state != ACTIVE_STATE_VOICE) break; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received 'MFT in' request.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Received 'MFT in' request.\n"); nmt->active_state = ACTIVE_STATE_MFT_IN; nmt->tx_frame_count = 0; nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); @@ -1494,7 +1495,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame) case 7: if (nmt->active_state != ACTIVE_STATE_MFT) break; - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received 'MFT out' request.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Received 'MFT out' request.\n"); nmt->active_state = ACTIVE_STATE_MFT_OUT; nmt->tx_frame_count = 0; nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); @@ -1511,17 +1512,17 @@ static void rx_active(nmt_t *nmt, frame_t *frame) if ((nmt->mft_num & 1)) break; if ((frame->digit >> 12) != 0x00) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Position information of digit does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Position information of digit does not match, ignoring due to corrupt frame.\n"); break; } if (((frame->digit >> 8) & 0xf) != ((frame->digit >> 4) & 0xf) || ((frame->digit >> 4) & 0xf) != (frame->digit & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Digit repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Digit repetition in frame does not match, ignoring due to corrupt frame.\n"); break; } digit = nmt_value2digit(frame->digit); dtmf_encode_set_tone(&nmt->dtmf, digit, DTMF_DURATION, 0.0); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (odd) digit %c.\n", digit); + LOGP_CHAN(DNMT, LOGL_INFO, "Received (odd) digit %c.\n", digit); nmt->mft_num++; break; case NMT_MESSAGE_14b: /* digits */ @@ -1534,21 +1535,21 @@ static void rx_active(nmt_t *nmt, frame_t *frame) if (!(nmt->mft_num & 1)) break; if ((frame->digit >> 12) != 0xff) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Position information of digit does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Position information of digit does not match, ignoring due to corrupt frame.\n"); break; } if (((frame->digit >> 8) & 0xf) != ((frame->digit >> 4) & 0xf) || ((frame->digit >> 4) & 0xf) != (frame->digit & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Digit repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Digit repetition in frame does not match, ignoring due to corrupt frame.\n"); break; } digit = nmt_value2digit(frame->digit); dtmf_encode_set_tone(&nmt->dtmf, digit, DTMF_DURATION, 0.0); - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (even) digit %c.\n", digit); + LOGP_CHAN(DNMT, LOGL_INFO, "Received (even) digit %c.\n", digit); nmt->mft_num++; break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame->mt), nmt_state_name(nmt->state)); } } @@ -1558,7 +1559,7 @@ static void tx_active(nmt_t *nmt, frame_t *frame) case ACTIVE_STATE_MFT_IN: set_line_signal(nmt, frame, 4); if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'MFT in acknowledge'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'MFT in acknowledge'.\n"); if (nmt->tx_frame_count > 4) { nmt->active_state = ACTIVE_STATE_MFT; nmt_set_dsp_mode(nmt, DSP_MODE_DTMF); @@ -1567,7 +1568,7 @@ static void tx_active(nmt_t *nmt, frame_t *frame) case ACTIVE_STATE_MFT_OUT: set_line_signal(nmt, frame, 10); if (++nmt->tx_frame_count == 1) - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'MFT out acknowledge'.\n"); + LOGP_CHAN(DNMT, LOGL_INFO, "Send 'MFT out acknowledge'.\n"); if (nmt->tx_frame_count > 4) { nmt->active_state = ACTIVE_STATE_VOICE; nmt_set_dsp_mode(nmt, DSP_MODE_AUDIO); @@ -1589,18 +1590,18 @@ void nmt_receive_frame(nmt_t *nmt, const char *bits, double quality, double leve frame_t frame; int rc; - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RX Level: %.0f%% Quality=%.0f%%\n", level * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "RX Level: %.0f%% Quality=%.0f%%\n", level * 100.0, quality * 100.0); rc = decode_frame(nmt->sysinfo.system, &frame, bits, (nmt->sender.loopback) ? MTX_TO_XX : XX_TO_MTX, (nmt->state == STATE_MT_PAGING)); if (rc < 0) { - PDEBUG_CHAN(DNMT, (nmt->sender.loopback) ? DEBUG_NOTICE : DEBUG_DEBUG, "Received invalid frame.\n"); + LOGP_CHAN(DNMT, (nmt->sender.loopback) ? LOGL_NOTICE : LOGL_DEBUG, "Received invalid frame.\n"); return; } /* frame counter */ nmt->rx_frame_count += frames_elapsed; - PDEBUG_CHAN(DNMT, (nmt->sender.loopback) ? DEBUG_NOTICE : DEBUG_DEBUG, "Received frame %s\n", nmt_frame_name(frame.mt)); + LOGP_CHAN(DNMT, (nmt->sender.loopback) ? LOGL_NOTICE : LOGL_DEBUG, "Received frame %s\n", nmt_frame_name(frame.mt)); if (nmt->sender.loopback) return; @@ -1619,15 +1620,15 @@ void nmt_receive_frame(nmt_t *nmt, const char *bits, double quality, double leve || ((frame.line_signal >> 12) & 0xf) != ((frame.line_signal >> 8) & 0xf) || ((frame.line_signal >> 8) & 0xf) != ((frame.line_signal >> 4) & 0xf) || ((frame.line_signal >> 4) & 0xf) != (frame.line_signal & 0xf)) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Line signal repetition in frame does not match, ignoring due to corrupt frame.\n"); return; } - PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received clearing by mobile phone in state %s.\n", nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_INFO, "Received clearing by mobile phone in state %s.\n", nmt_state_name(nmt->state)); nmt_new_state(nmt, STATE_MO_RELEASE); nmt->tx_frame_count = 0; nmt_set_dsp_mode(nmt, DSP_MODE_FRAME); if (nmt->trans->callref) { - PDEBUG(DNMT, DEBUG_INFO, "Release call towards network.\n"); + LOGP(DNMT, LOGL_INFO, "Release call towards network.\n"); call_up_release(nmt->trans->callref, CAUSE_NORMAL); nmt->trans->callref = 0; } @@ -1672,7 +1673,7 @@ void nmt_receive_frame(nmt_t *nmt, const char *bits, double quality, double leve rx_active(nmt, &frame); break; default: - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame.mt), nmt_state_name(nmt->state)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Dropping message %s in state %s\n", nmt_frame_name(frame.mt), nmt_state_name(nmt->state)); } } @@ -1692,7 +1693,7 @@ static void nmt_timeout(void *data) timeout_mt_release(nmt); break; case STATE_ACTIVE: - timeout_active(nmt, nmt->timer.duration); + timeout_active(nmt, nmt->timer.timeout.tv_sec); break; default: break; @@ -1785,9 +1786,9 @@ const char *nmt_get_frame(nmt_t *nmt) bits = encode_frame(nmt->sysinfo.system, &frame, debug); if (debug) - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Sending frame %s.\n", nmt_frame_name(frame.mt)); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Sending frame %s.\n", nmt_frame_name(frame.mt)); if (debug && nmt->tx_last_frame_idle) - PDEBUG_CHAN(DNMT, DEBUG_DEBUG, "Subsequent IDLE frames are not show, to prevent flooding the output.\n"); + LOGP_CHAN(DNMT, LOGL_DEBUG, "Subsequent IDLE frames are not show, to prevent flooding the output.\n"); return bits; } @@ -1807,14 +1808,14 @@ int _out_setup(int callref, const char *caller_id, enum number_type caller_type, /* 1. split number into country and subscriber parts */ if (dialstring2number(dialing, &subscr.country, subscr.number)) { - PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing); + LOGP(DNMT, LOGL_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing); return -CAUSE_INVALNUMBER; } /* 2. check if given number is already in a call, return BUSY */ trans = get_transaction_by_number(&subscr); if (trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DNMT, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } @@ -1827,20 +1828,20 @@ int _out_setup(int callref, const char *caller_id, enum number_type caller_type, break; } if (!sender) { - PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing call, but no free calling channel, rejecting!\n"); + LOGP(DNMT, LOGL_NOTICE, "Outgoing call, but no free calling channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } if (!search_free_tc(NULL)) { - PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing call, but no free traffic channel, rejecting!\n"); + LOGP(DNMT, LOGL_NOTICE, "Outgoing call, but no free traffic channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG(DNMT, DEBUG_INFO, "Call to mobile station, paging station id '%c%s'\n", subscr.country, subscr.number); + LOGP(DNMT, LOGL_INFO, "Call to mobile station, paging station id '%c%s'\n", subscr.country, subscr.number); /* 4. trying to page mobile station */ trans = create_transaction(&subscr); if (!trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "Failed to create transaction, rejecting!\n"); + LOGP(DNMT, LOGL_NOTICE, "Failed to create transaction, rejecting!\n"); return -CAUSE_TEMPFAIL; } trans->callref = callref; @@ -1879,11 +1880,11 @@ void call_down_disconnect(int callref, int cause) transaction_t *trans; nmt_t *nmt; - PDEBUG(DNMT, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DNMT, LOGL_INFO, "Call has been disconnected by network.\n"); trans = get_transaction_by_callref(callref); if (!trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DNMT, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1901,12 +1902,12 @@ void call_down_disconnect(int callref, int cause) return; switch (nmt->state) { case STATE_MT_RINGING: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Outgoing disconnect, during ringing, releasing!\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Outgoing disconnect, during ringing, releasing!\n"); trans->callref = 0; nmt_release(nmt); break; default: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Outgoing disconnect, when phone is in call setup, releasing!\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Outgoing disconnect, when phone is in call setup, releasing!\n"); trans->callref = 0; nmt_release(nmt); break; @@ -1921,11 +1922,11 @@ void call_down_release(int callref, int __attribute__((unused)) cause) transaction_t *trans; nmt_t *nmt; - PDEBUG(DNMT, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DNMT, LOGL_INFO, "Call has been released by network, releasing call.\n"); trans = get_transaction_by_callref(callref); if (!trans) { - PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DNMT, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -1940,15 +1941,15 @@ void call_down_release(int callref, int __attribute__((unused)) cause) switch (nmt->state) { case STATE_ACTIVE: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Outgoing release, during active call, releasing!\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Outgoing release, during active call, releasing!\n"); nmt_release(nmt); break; case STATE_MT_RINGING: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Outgoing release, during ringing, releasing!\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Outgoing release, during ringing, releasing!\n"); nmt_release(nmt); break; default: - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Outgoing release, when phone is in call setup, releasing!\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Outgoing release, when phone is in call setup, releasing!\n"); nmt_release(nmt); break; } @@ -1983,7 +1984,7 @@ void call_down_clock(void) {} /* SMS layer releases */ void sms_release(nmt_t *nmt) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Outgoing release, by SMS layer!\n"); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Outgoing release, by SMS layer!\n"); nmt_release(nmt); } @@ -1994,7 +1995,7 @@ int sms_submit(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t __attr if (!orig_address[0]) orig_address = &nmt->trans->subscriber.country; - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Received SMS from '%s' to '%s' (ref=%d)\n", orig_address, dest_address, ref); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Received SMS from '%s' to '%s' (ref=%d)\n", orig_address, dest_address, ref); printf("SMS received '%s' -> '%s': %s\n", orig_address, dest_address, message); snprintf(sms, sizeof(sms) - 1, "%s,%s,%s", orig_address, dest_address, message); sms[sizeof(sms) - 1] = '\0'; @@ -2004,7 +2005,7 @@ int sms_submit(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t __attr void sms_deliver_report(nmt_t *nmt, uint8_t ref, int error, uint8_t cause) { - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Got SMS deliver report (ref=%d)\n", ref); + LOGP_CHAN(DNMT, LOGL_NOTICE, "Got SMS deliver report (ref=%d)\n", ref); if (error) printf("SMS failed! (cause=%d)\n", cause); else { @@ -2026,11 +2027,11 @@ void deliver_sms(const char *sms) message = p; if (!caller_id || !number || !message) { inval: - PDEBUG(DNMT, DEBUG_NOTICE, "Given SMS MUST be in the following format: [i|n|s|u]<caller ID>,<7 digits number>,<message with comma and spaces> (i, n, s, u indicate the type of number)\n"); + LOGP(DNMT, LOGL_NOTICE, "Given SMS MUST be in the following format: [i|n|s|u]<caller ID>,<7 digits number>,<message with comma and spaces> (i, n, s, u indicate the type of number)\n"); return; } if (strlen(number) != 7) { - PDEBUG(DNMT, DEBUG_NOTICE, "Given number must be 7 digits\n"); + LOGP(DNMT, LOGL_NOTICE, "Given number must be 7 digits\n"); goto inval; } @@ -2058,12 +2059,12 @@ inval: caller_type = TYPE_UNKNOWN; } - PDEBUG(DNMT, DEBUG_INFO, "SMS from '%s' for subscriber '%s' with message '%s'\n", caller_id, number, message); + LOGP(DNMT, LOGL_INFO, "SMS from '%s' for subscriber '%s' with message '%s'\n", caller_id, number, message); printf("SMS sending '%s' -> '%s': %s\n", caller_id, number, message); rc = sms_out_setup(number, caller_id, caller_type, message); if (rc < 0) { - PDEBUG(DNMT, DEBUG_INFO, "SMS delivery failed with cause '%d'\n", -rc); + LOGP(DNMT, LOGL_INFO, "SMS delivery failed with cause '%d'\n", -rc); return; } } diff --git a/src/nmt/nmt.h b/src/nmt/nmt.h index 566ba97..6a77431 100644 --- a/src/nmt/nmt.h +++ b/src/nmt/nmt.h @@ -1,5 +1,5 @@ #include "../libmobile/sender.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../libcompandor/compandor.h" #include "../libdtmf/dtmf_encode.h" #include "../libmobile/call.h" @@ -85,7 +85,7 @@ struct nmt { enum nmt_state state; int wait_autoanswer; /* wait for frame 15 before we can send autoanswer */ enum nmt_active_state active_state; - struct timer timer; + struct osmo_timer_list timer; int rx_frame_count; /* receive frame counter */ int tx_frame_count; /* transmit frame counter */ int tx_callerid_count; /* counter for caller ID repetition */ @@ -138,7 +138,7 @@ struct nmt { dms_t dms; /* DMS states */ sms_t sms; /* SMS states */ char smsc_number[33]; /* digits to match SMSC */ - struct timer sms_timer; + struct osmo_timer_list sms_timer; }; void nmt_channel_list(int nmt_system); diff --git a/src/nmt/sms.c b/src/nmt/sms.c index f774fde..1b1a7de 100644 --- a/src/nmt/sms.c +++ b/src/nmt/sms.c @@ -24,11 +24,11 @@ #include <time.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "nmt.h" -#define SMS_RECEIVE_TO 5.0 -#define SMS_RELEASE_TO 2.0 +#define SMS_RECEIVE_TO 5,0 +#define SMS_RELEASE_TO 2,0 /* TP-Message-Type-Indicator (TP-MTI) */ #define MTI_SMS_DELIVER 0x00 /* SC -> MS */ @@ -99,7 +99,7 @@ static void sms_timeout(void *data); /* init instance */ int sms_init_sender(nmt_t *nmt) { - timer_init(&nmt->sms_timer, sms_timeout, nmt); + osmo_timer_setup(&nmt->sms_timer, sms_timeout, nmt); return 0; } @@ -108,7 +108,7 @@ int sms_init_sender(nmt_t *nmt) void sms_cleanup_sender(nmt_t *nmt) { sms_reset(nmt); - timer_exit(&nmt->sms_timer); + osmo_timer_del(&nmt->sms_timer); } /* @@ -130,7 +130,7 @@ static int encode_address(uint8_t *data, const char *address, uint8_t type, uint uint8_t digit; int i, j; - PDEBUG(DSMS, DEBUG_DEBUG, "Encode SC->MS header\n"); + LOGP(DSMS, LOGL_DEBUG, "Encode SC->MS header\n"); data[length++] = 0x80 | (type << 4) | plan; j = 0; @@ -170,7 +170,7 @@ static int encode_time(uint8_t *data, time_t timestamp, int local) uint8_t digit1, digit2; int quarters, sign; - PDEBUG(DSMS, DEBUG_DEBUG, "Encode time stamp '%02d.%02d.%02d %02d:%02d:%02d'\n", tm->tm_mday, tm->tm_mon + 1, tm->tm_year % 100, tm->tm_hour, tm->tm_min, tm->tm_sec); + LOGP(DSMS, LOGL_DEBUG, "Encode time stamp '%02d.%02d.%02d %02d:%02d:%02d'\n", tm->tm_mday, tm->tm_mon + 1, tm->tm_year % 100, tm->tm_hour, tm->tm_min, tm->tm_sec); /* year */ digit1 = (tm->tm_year % 100) / 10; @@ -247,7 +247,7 @@ static int encode_userdata(uint8_t *data, const char *message) uint8_t character; int i, j, pos; - PDEBUG(DSMS, DEBUG_DEBUG, "Encode user data '%s'\n", message); + LOGP(DSMS, LOGL_DEBUG, "Encode user data '%s'\n", message); j = 0; pos = 0; @@ -293,17 +293,17 @@ int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_ int orig_len; int msg_len; - PDEBUG(DSMS, DEBUG_INFO, "Delivering SMS from upper layer\n"); + LOGP(DSMS, LOGL_INFO, "Delivering SMS from upper layer\n"); orig_len = strlen(orig_address); msg_len = strlen(message); if (orig_len > 24) { - PDEBUG(DSMS, DEBUG_NOTICE, "Originator Address too long (%d characters)\n", orig_len); + LOGP(DSMS, LOGL_NOTICE, "Originator Address too long (%d characters)\n", orig_len); return -EINVAL; } if (msg_len > 140) { - PDEBUG(DSMS, DEBUG_NOTICE, "Message too long (%d characters)\n", msg_len); + LOGP(DSMS, LOGL_NOTICE, "Message too long (%d characters)\n", msg_len); return -EINVAL; } @@ -326,13 +326,13 @@ int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_ /* RP length */ *tpdu_length = length - (uint8_t)(tpdu_length - data) - 1; - PDEBUG(DSMS, DEBUG_DEBUG, " -> TPDU length = %d\n", *tpdu_length); + LOGP(DSMS, LOGL_DEBUG, " -> TPDU length = %d\n", *tpdu_length); nmt->sms.mt = 1; dms_send(nmt, data, length, 1); /* start timer */ - timer_start(&nmt->sms_timer, SMS_RECEIVE_TO); + osmo_timer_schedule(&nmt->sms_timer, SMS_RECEIVE_TO); return 0; } @@ -343,7 +343,7 @@ static void sms_submit_report(nmt_t *nmt, uint8_t ref, int error) uint8_t data[64]; int length = 0; - PDEBUG(DSMS, DEBUG_INFO, "Sending Submit Report (%s)\n", (error) ? "error" : "ok"); + LOGP(DSMS, LOGL_INFO, "Sending Submit Report (%s)\n", (error) ? "error" : "ok"); /* HEADER */ length = encode_header(data); @@ -417,7 +417,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* do we have originator address length ? */ if (length < 2) { - PDEBUG(DSMS, DEBUG_DEBUG, "SMS still incomplete, waiting for originator address\n"); + LOGP(DSMS, LOGL_DEBUG, "SMS still incomplete, waiting for originator address\n"); return 0; } orig_data = 2 + data; @@ -426,7 +426,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) orig_plan = data[1] & 0x0f; orig_len = (orig_digits + 1) >> 1; if (length < 2 + orig_len) { - PDEBUG(DSMS, DEBUG_DEBUG, "SMS still incomplete, waiting for originator address digits (got %d of %d)\n", length - 1, orig_len); + LOGP(DSMS, LOGL_DEBUG, "SMS still incomplete, waiting for originator address digits (got %d of %d)\n", length - 1, orig_len); return 0; } data += 2 + orig_len; @@ -434,17 +434,17 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* do we have user data IE ? */ if (length < 2) { - PDEBUG(DSMS, DEBUG_DEBUG, "SMS still incomplete, waiting for user data IE\n"); + LOGP(DSMS, LOGL_DEBUG, "SMS still incomplete, waiting for user data IE\n"); return 0; } if (data[0] != RP_IE_USER_DATA) { - PDEBUG(DSMS, DEBUG_NOTICE, "missing user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "missing user data IE\n"); return -FSC_ERROR_IN_MS; } tpdu_len = data[1]; tpdu_data = 2 + data; if (length < 2 + tpdu_len) { - PDEBUG(DSMS, DEBUG_DEBUG, "SMS still incomplete, waiting for TPDU to be complete\n"); + LOGP(DSMS, LOGL_DEBUG, "SMS still incomplete, waiting for TPDU to be complete\n"); return 0; } data += 2 + tpdu_len; @@ -453,7 +453,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* decode orig address */ char orig_address[orig_digits + 1]; decode_address(orig_data, orig_digits, orig_address); - PDEBUG(DSMS, DEBUG_DEBUG, "Decoded originating address: '%s'\n", orig_address); + LOGP(DSMS, LOGL_DEBUG, "Decoded originating address: '%s'\n", orig_address); /* go into TP */ data = tpdu_data; @@ -461,11 +461,11 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* check msg_type */ if (length < 1) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } if ((data[0] & MTI_MASK) != MTI_SMS_SUBMIT) { - PDEBUG(DSMS, DEBUG_NOTICE, "especting SUBMIT MTI, but got 0x%02x\n", data[0]); + LOGP(DSMS, LOGL_NOTICE, "especting SUBMIT MTI, but got 0x%02x\n", data[0]); return -FSC_ERROR_IN_MS; } if ((data[0] & VPF_MASK)) @@ -475,7 +475,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* decode msg ref */ if (length < 1) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } msg_ref = data[0]; @@ -484,7 +484,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* decode dest address */ if (length < 2) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } dest_data = 2 + data; @@ -493,18 +493,18 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) dest_plan = data[1] & 0x0f; dest_len = (dest_digits + 1) >> 1; if (length < 2 + dest_len) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } data += 2 + dest_len; length -= 2 + dest_len; char dest_address[dest_digits + 1]; decode_address(dest_data, dest_digits, dest_address); - PDEBUG(DSMS, DEBUG_DEBUG, "Decoded destination address: '%s'\n", dest_address); + LOGP(DSMS, LOGL_DEBUG, "Decoded destination address: '%s'\n", dest_address); /* skip above protocol identifier */ if (length < 1) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read above protocol identifier IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read above protocol identifier IE\n"); return -FSC_ERROR_IN_MS; } data++; @@ -512,17 +512,17 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* decode data coding scheme */ if (length < 1) { - PDEBUG(DSMS, DEBUG_NOTICE, "short data coding scheme IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short data coding scheme IE\n"); return -FSC_ERROR_IN_MS; } if (data[0] == 0x00) { - PDEBUG(DSMS, DEBUG_DEBUG, "SMS coding is 7 bits (got 0x%02x)\n", data[0]); + LOGP(DSMS, LOGL_DEBUG, "SMS coding is 7 bits (got 0x%02x)\n", data[0]); coding = 7; } else if ((data[0] & 0xf0) == 0x30) { - PDEBUG(DSMS, DEBUG_DEBUG, "SMS coding is 8 bits (got 0x%02x)\n", data[0]); + LOGP(DSMS, LOGL_DEBUG, "SMS coding is 8 bits (got 0x%02x)\n", data[0]); coding = 8; } else { - PDEBUG(DSMS, DEBUG_NOTICE, "SMS coding unsupported (got 0x%02x)\n", data[0]); + LOGP(DSMS, LOGL_NOTICE, "SMS coding unsupported (got 0x%02x)\n", data[0]); return -FSC_ERROR_IN_MS; } data++; @@ -531,7 +531,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* skip validity period */ if (tp_vpf_present) { if (length < 1) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read validity period IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read validity period IE\n"); return -FSC_ERROR_IN_MS; } data++; @@ -540,7 +540,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) /* decode data message text */ if (length < 1) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } msg_data = data + 1; @@ -550,20 +550,20 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) else msg_len = msg_chars; if (length < 1 + msg_len) { - PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); + LOGP(DSMS, LOGL_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } char message[msg_chars + 1]; if (coding == 7) { decode_message_7(msg_data, msg_len, message); - PDEBUG(DSMS, DEBUG_DEBUG, "Decoded message: '%s'\n", message); + LOGP(DSMS, LOGL_DEBUG, "Decoded message: '%s'\n", message); } else { memcpy(message, msg_data, msg_len); message[msg_len] = '\0'; - PDEBUG(DSMS, DEBUG_DEBUG, "Included message: '%s'\n", message); + LOGP(DSMS, LOGL_DEBUG, "Included message: '%s'\n", message); } - PDEBUG(DSMS, DEBUG_INFO, "Submitting SMS to upper layer\n"); + LOGP(DSMS, LOGL_INFO, "Submitting SMS to upper layer\n"); rc = sms_submit(nmt, ref, orig_address, orig_type, orig_plan, msg_ref, dest_address, dest_type, dest_plan, message); if (rc < 0) @@ -584,18 +584,18 @@ static int decode_deliver_report(nmt_t *nmt, const uint8_t *data, int length) if ((data[0] & RP_MTI_MASK) == RP_MT_ERROR) { error = 1; if (length < 4) { - PDEBUG(DSMS, DEBUG_DEBUG, "deliver report still incomplete, waiting for cause IE\n"); + LOGP(DSMS, LOGL_DEBUG, "deliver report still incomplete, waiting for cause IE\n"); return 0; } if (length < 4 + data[3]) { - PDEBUG(DSMS, DEBUG_DEBUG, "deliver report still incomplete, waiting for cause IE content\n"); + LOGP(DSMS, LOGL_DEBUG, "deliver report still incomplete, waiting for cause IE content\n"); return 0; } if (data[2] == RP_IE_CAUSE && data[3] > 0) cause = data[4]; - PDEBUG(DSMS, DEBUG_INFO, "Received Delivery report: ERROR, cause=%d\n", cause); + LOGP(DSMS, LOGL_INFO, "Received Delivery report: ERROR, cause=%d\n", cause); } else - PDEBUG(DSMS, DEBUG_INFO, "Received Delivery report: OK\n"); + LOGP(DSMS, LOGL_INFO, "Received Delivery report: OK\n"); sms_deliver_report(nmt, ref, error, cause); @@ -616,21 +616,21 @@ void dms_receive(nmt_t *nmt, const uint8_t *data, int length, int __attribute__( debug_text[length * 5] = '\0'; /* restart timer */ - timer_start(&nmt->sms_timer, SMS_RECEIVE_TO); + osmo_timer_schedule(&nmt->sms_timer, SMS_RECEIVE_TO); - PDEBUG(DSMS, DEBUG_DEBUG, "Received %d bytes from DMS layer:%s\n", length, debug_text); + LOGP(DSMS, LOGL_DEBUG, "Received %d bytes from DMS layer:%s\n", length, debug_text); if (sms->mt && !sms->data_sent) { - PDEBUG(DSMS, DEBUG_NOTICE, "Ignoring data while we transmit data\n"); + LOGP(DSMS, LOGL_NOTICE, "Ignoring data while we transmit data\n"); return; } /* append received data */ space = sizeof(sms->rx_buffer) - sms->rx_count; if (space < length) { - PDEBUG(DSMS, DEBUG_NOTICE, "Received message exceeds RX buffer, terminating call!\n"); + LOGP(DSMS, LOGL_NOTICE, "Received message exceeds RX buffer, terminating call!\n"); release: - timer_start(&nmt->sms_timer, SMS_RELEASE_TO); + osmo_timer_schedule(&nmt->sms_timer, SMS_RELEASE_TO); return; } memcpy(sms->rx_buffer + sms->rx_count, data, length); @@ -661,12 +661,12 @@ release: rc = 0; break; case RP_SM_READY_TO_RECEIVE: - PDEBUG(DSMS, DEBUG_NOTICE, "Received READY-TO-RECEVIE message.\n"); + LOGP(DSMS, LOGL_NOTICE, "Received READY-TO-RECEVIE message.\n"); data += length; length -= length; break; default: - PDEBUG(DSMS, DEBUG_NOTICE, "Received unknown RP message type %d.\n", data[0]); + LOGP(DSMS, LOGL_NOTICE, "Received unknown RP message type %d.\n", data[0]); rc = -1; } if (rc) @@ -689,11 +689,11 @@ void dms_all_sent(nmt_t *nmt) if (!sms->data_sent) { if (!sms->mt) { - PDEBUG(DSMS, DEBUG_DEBUG, "Done sending submit report, releasing.\n"); - timer_start(&nmt->sms_timer, SMS_RELEASE_TO); + LOGP(DSMS, LOGL_DEBUG, "Done sending submit report, releasing.\n"); + osmo_timer_schedule(&nmt->sms_timer, SMS_RELEASE_TO); } sms->data_sent = 1; - PDEBUG(DSMS, DEBUG_DEBUG, "DMS layer indicates acknowledge of sent data\n"); + LOGP(DSMS, LOGL_DEBUG, "DMS layer indicates acknowledge of sent data\n"); } } @@ -701,9 +701,8 @@ void sms_reset(nmt_t *nmt) { sms_t *sms = &nmt->sms; - PDEBUG(DSMS, DEBUG_DEBUG, "Resetting SMS states\n"); - if (nmt->sms_timer.linked) - timer_stop(&nmt->sms_timer); + LOGP(DSMS, LOGL_DEBUG, "Resetting SMS states\n"); + osmo_timer_del(&nmt->sms_timer); memset(sms, 0, sizeof(*sms)); } diff --git a/src/nmt/transaction.c b/src/nmt/transaction.c index 3e4ef89..000d8e8 100644 --- a/src/nmt/transaction.c +++ b/src/nmt/transaction.c @@ -22,7 +22,7 @@ #include <stdlib.h> #include <string.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "nmt.h" #include "transaction.h" @@ -35,7 +35,7 @@ static void link_transaction(transaction_t *trans) transaction_t **transp; /* attach to end of list, so first transaction is served first */ - PDEBUG(DTRANS, DEBUG_DEBUG, "Linking transaction %p to list\n", trans); + LOGP(DTRANS, LOGL_DEBUG, "Linking transaction %p to list\n", trans); trans->next = NULL; transp = &trans_list; while (*transp) @@ -51,12 +51,12 @@ static void unlink_transaction(transaction_t *trans) nmt_t *nmt; /* unlink */ - PDEBUG(DTRANS, DEBUG_DEBUG, "Unlinking transaction %p from list\n", trans); + LOGP(DTRANS, LOGL_DEBUG, "Unlinking transaction %p from list\n", trans); transp = &trans_list; while (*transp && *transp != trans) transp = &((*transp)->next); if (!(*transp)) { - PDEBUG(DTRANS, DEBUG_ERROR, "Transaction not in list, please fix!!\n"); + LOGP(DTRANS, LOGL_ERROR, "Transaction not in list, please fix!!\n"); abort(); } *transp = trans->next; @@ -78,15 +78,15 @@ transaction_t *create_transaction(struct nmt_subscriber *subscr) trans = calloc(1, sizeof(*trans)); if (!trans) { - PDEBUG(DTRANS, DEBUG_ERROR, "No memory!\n"); + LOGP(DTRANS, LOGL_ERROR, "No memory!\n"); return NULL; } - timer_init(&trans->timer, transaction_timeout, trans); + osmo_timer_setup(&trans->timer, transaction_timeout, trans); memcpy(&trans->subscriber, subscr, sizeof(struct nmt_subscriber)); - PDEBUG(DTRANS, DEBUG_INFO, "Created transaction for subscriber '%c,%s'\n", subscr->country, subscr->number); + LOGP(DTRANS, LOGL_INFO, "Created transaction for subscriber '%c,%s'\n", subscr->country, subscr->number); link_transaction(trans); @@ -98,9 +98,9 @@ void destroy_transaction(transaction_t *trans) { unlink_transaction(trans); - PDEBUG(DTRANS, DEBUG_INFO, "Destroying transaction for subscriber '%c,%s'\n", trans->subscriber.country, trans->subscriber.number); + LOGP(DTRANS, LOGL_INFO, "Destroying transaction for subscriber '%c,%s'\n", trans->subscriber.country, trans->subscriber.number); - timer_exit(&trans->timer); + osmo_timer_del(&trans->timer); free(trans); } diff --git a/src/nmt/transaction.h b/src/nmt/transaction.h index 6af4501..fcfc4d8 100644 --- a/src/nmt/transaction.h +++ b/src/nmt/transaction.h @@ -14,7 +14,7 @@ typedef struct transaction { nmt_t *nmt; /* pointer to nmt instance, if bound to a channel */ int callref; /* callref for transaction */ struct nmt_subscriber subscriber; - struct timer timer; + struct osmo_timer_list timer; int page_try; /* number of paging try */ /* caller ID */ diff --git a/src/pocsag/Makefile.am b/src/pocsag/Makefile.am index f5c7a41..e8d7509 100644 --- a/src/pocsag/Makefile.am +++ b/src/pocsag/Makefile.am @@ -13,21 +13,19 @@ pocsag_LDADD = \ $(COMMON_LA) \ ../anetz/libgermanton.a \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/pocsag/dsp.c b/src/pocsag/dsp.c index af1a80b..4d8b1df 100644 --- a/src/pocsag/dsp.c +++ b/src/pocsag/dsp.c @@ -26,7 +26,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "pocsag.h" #include "frame.h" #include "dsp.h" @@ -40,7 +40,7 @@ static void dsp_init_ramp(pocsag_t *pocsag) double c; int i; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Generating cosine shaped ramp table.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Generating cosine shaped ramp table.\n"); for (i = 0; i < 256; i++) { /* This is mathematically incorrect... */ if (i < 64) @@ -59,7 +59,7 @@ int dsp_init_sender(pocsag_t *pocsag, int samplerate, int baudrate, double devia { int rc; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for transceiver.\n"); /* set modulation parameters */ // NOTE: baudrate equals modulation, because we have a raised cosine ramp of beta = 0.5 @@ -67,12 +67,12 @@ int dsp_init_sender(pocsag_t *pocsag, int samplerate, int baudrate, double devia pocsag->fsk_bitduration = (double)samplerate / (double)baudrate; pocsag->fsk_bitstep = 1.0 / pocsag->fsk_bitduration; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Use %.4f samples for one bit duration @ %d.\n", pocsag->fsk_bitduration, pocsag->sender.samplerate); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Use %.4f samples for one bit duration @ %d.\n", pocsag->fsk_bitduration, pocsag->sender.samplerate); pocsag->fsk_tx_buffer_size = pocsag->fsk_bitduration * 32.0 + 10; /* 32 bit, add some extra to prevent short buffer due to rounding */ pocsag->fsk_tx_buffer = calloc(sizeof(sample_t), pocsag->fsk_tx_buffer_size); if (!pocsag->fsk_tx_buffer) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "No memory!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "No memory!\n"); rc = -ENOMEM; goto error; } @@ -94,7 +94,7 @@ error: /* Cleanup transceiver instance. */ void dsp_cleanup_sender(pocsag_t *pocsag) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for transceiver.\n"); if (pocsag->fsk_tx_buffer) { free(pocsag->fsk_tx_buffer); @@ -180,7 +180,7 @@ static void fsk_block_decode(pocsag_t *pocsag, uint8_t bit) pocsag->fsk_rx_index = 0; } else if (pocsag->fsk_rx_word == (uint32_t)(~CODEWORD_SYNC)) - PDEBUG_CHAN(DDSP, DEBUG_NOTICE, "Received inverted sync, caused by wrong polarity or by radio noise. Verify correct polarity!\n"); + LOGP_CHAN(DDSP, LOGL_NOTICE, "Received inverted sync, caused by wrong polarity or by radio noise. Verify correct polarity!\n"); } else { pocsag->fsk_rx_word = (pocsag->fsk_rx_word << 1) | bit; if (++pocsag->fsk_rx_index == 32) { diff --git a/src/pocsag/frame.c b/src/pocsag/frame.c index 12ccd10..531dc6d 100644 --- a/src/pocsag/frame.c +++ b/src/pocsag/frame.c @@ -23,7 +23,7 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "pocsag.h" #include "frame.h" @@ -103,29 +103,29 @@ static uint32_t pocsag_parity(uint32_t word) static int debug_word(uint32_t word, int slot) { if (pocsag_crc(word >> 11) != ((word >> 1) & 0x3ff)) { - PDEBUG(DPOCSAG, DEBUG_NOTICE, "CRC error in codeword 0x%08x.\n", word); + LOGP(DPOCSAG, LOGL_NOTICE, "CRC error in codeword 0x%08x.\n", word); return -EINVAL; } if (pocsag_parity(word)) { - PDEBUG(DPOCSAG, DEBUG_NOTICE, "Parity error in codeword 0x%08x.\n", word); + LOGP(DPOCSAG, LOGL_NOTICE, "Parity error in codeword 0x%08x.\n", word); return -EINVAL; } if (word == CODEWORD_SYNC) { - PDEBUG(DPOCSAG, DEBUG_DEBUG, "-> valid sync word\n"); + LOGP(DPOCSAG, LOGL_DEBUG, "-> valid sync word\n"); return 0; } if (word == CODEWORD_IDLE) { - PDEBUG(DPOCSAG, DEBUG_DEBUG, "-> valid idle word\n"); + LOGP(DPOCSAG, LOGL_DEBUG, "-> valid idle word\n"); return 0; } if (!(word & 0x80000000)) { - PDEBUG(DPOCSAG, DEBUG_DEBUG, "-> valid address word: RIC = '%d', function = '%d' (%s)\n", ((word >> 10) & 0x1ffff8) + slot, (word >> 11) & 0x3, pocsag_function_name[(word >> 11) & 0x3]); + LOGP(DPOCSAG, LOGL_DEBUG, "-> valid address word: RIC = '%d', function = '%d' (%s)\n", ((word >> 10) & 0x1ffff8) + slot, (word >> 11) & 0x3, pocsag_function_name[(word >> 11) & 0x3]); } else { - PDEBUG(DPOCSAG, DEBUG_DEBUG, "-> valid message word: message = '0x%05x'\n", (word >> 11) & 0xfffff); + LOGP(DPOCSAG, LOGL_DEBUG, "-> valid message word: message = '0x%05x'\n", (word >> 11) & 0xfffff); } return 0; @@ -303,9 +303,9 @@ int64_t get_codeword(pocsag_t *pocsag) return -1; case POCSAG_PREAMBLE: if (!pocsag->word_count) - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, "Sending preamble.\n"); + LOGP_CHAN(DPOCSAG, LOGL_INFO, "Sending preamble.\n"); /* transmit preamble */ - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Sending 32 bits of preamble pattern 0x%08x.\n", CODEWORD_PREAMBLE); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Sending 32 bits of preamble pattern 0x%08x.\n", CODEWORD_PREAMBLE); if (++pocsag->word_count == PREAMBLE_COUNT) { pocsag_new_state(pocsag, POCSAG_MESSAGE); pocsag->word_count = 0; @@ -315,10 +315,10 @@ int64_t get_codeword(pocsag_t *pocsag) break; case POCSAG_MESSAGE: if (!pocsag->word_count) - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, "Sending batch.\n"); + LOGP_CHAN(DPOCSAG, LOGL_INFO, "Sending batch.\n"); /* send sync */ if (pocsag->word_count == 0) { - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Sending 32 bits of sync pattern 0x%08x.\n", CODEWORD_SYNC); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Sending 32 bits of sync pattern 0x%08x.\n", CODEWORD_SYNC); /* count codewords */ ++pocsag->word_count; word = CODEWORD_SYNC; @@ -352,7 +352,7 @@ int64_t get_codeword(pocsag_t *pocsag) } /* prevent 'use-after-free' from this point on */ msg = NULL; - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Sending 32 bits of message codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Sending 32 bits of message codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); /* count codewords */ if (++pocsag->word_count == 17) pocsag->word_count = 0; @@ -365,7 +365,7 @@ int64_t get_codeword(pocsag_t *pocsag) break; } if (msg) { - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, "Sending message to RIC '%d' / function '%d' (%s)\n", msg->ric, msg->function, pocsag_function_name[msg->function]); + LOGP_CHAN(DPOCSAG, LOGL_INFO, "Sending message to RIC '%d' / function '%d' (%s)\n", msg->ric, msg->function, pocsag_function_name[msg->function]); /* reset idle counter */ pocsag->idle_count = 0; /* encode address */ @@ -375,7 +375,7 @@ int64_t get_codeword(pocsag_t *pocsag) char text[msg->data_length + 1]; memcpy(text, msg->data, msg->data_length); text[msg->data_length] = '\0'; - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, " -> Message text is \"%s\".\n", text); + LOGP_CHAN(DPOCSAG, LOGL_INFO, " -> Message text is \"%s\".\n", text); pocsag->current_msg = msg; msg->data_index = 0; msg->bit_index = 0; @@ -390,21 +390,21 @@ int64_t get_codeword(pocsag_t *pocsag) /* prevent 'use-after-free' from this point on */ msg = NULL; } - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Sending 32 bits of address codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Sending 32 bits of address codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); /* count codewords */ if (++pocsag->word_count == 17) pocsag->word_count = 0; break; } /* no message, so we send idle pattern */ - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Sending 32 bits of idle pattern 0x%08x (frame %d.%d).\n", CODEWORD_IDLE, slot, subslot); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Sending 32 bits of idle pattern 0x%08x (frame %d.%d).\n", CODEWORD_IDLE, slot, subslot); /* count codewords */ if (++pocsag->word_count == 17) { pocsag->word_count = 0; /* if no message has been scheduled during transmission and idle counter is reached, stop transmitter */ if (!pocsag->msg_list && pocsag->idle_count++ == IDLE_BATCHES) { - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, "Transmission done.\n"); - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Reached %d of idle batches, turning transmitter off.\n", IDLE_BATCHES); + LOGP_CHAN(DPOCSAG, LOGL_INFO, "Transmission done.\n"); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Reached %d of idle batches, turning transmitter off.\n", IDLE_BATCHES); pocsag_new_state(pocsag, POCSAG_IDLE); } } @@ -425,7 +425,7 @@ static void done_rx_msg(pocsag_t *pocsag) pocsag->rx_msg_valid = 0; - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, "Received message from RIC '%d' / function '%d' (%s)\n", pocsag->rx_msg_ric, pocsag->rx_msg_function, pocsag_function_name[pocsag->rx_msg_function]); + LOGP_CHAN(DPOCSAG, LOGL_INFO, "Received message from RIC '%d' / function '%d' (%s)\n", pocsag->rx_msg_ric, pocsag->rx_msg_function, pocsag_function_name[pocsag->rx_msg_function]); { char text[pocsag->rx_msg_data_length * 5 + 1]; int i, j; @@ -442,7 +442,7 @@ static void done_rx_msg(pocsag_t *pocsag) } text[j] = '\0'; if ((pocsag->rx_msg_function == POCSAG_FUNCTION_NUMERIC || pocsag->rx_msg_function == POCSAG_FUNCTION_ALPHA) && text[0]) - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, " -> Message text is \"%s\".\n", text); + LOGP_CHAN(DPOCSAG, LOGL_INFO, " -> Message text is \"%s\".\n", text); pocsag_msg_receive(pocsag->language, pocsag->sender.kanal, pocsag->rx_msg_ric, pocsag->rx_msg_function, text); } } @@ -452,17 +452,17 @@ void put_codeword(pocsag_t *pocsag, uint32_t word, int8_t slot, int8_t subslot) int rc; if (slot < 0 && word == CODEWORD_SYNC) { - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Received 32 bits of sync pattern 0x%08x.\n", CODEWORD_SYNC); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Received 32 bits of sync pattern 0x%08x.\n", CODEWORD_SYNC); return; } if (word == CODEWORD_IDLE) { - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Received 32 bits of idle pattern 0x%08x.\n", CODEWORD_IDLE); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Received 32 bits of idle pattern 0x%08x.\n", CODEWORD_IDLE); } else if (!(word & 0x80000000)) - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Received 32 bits of address codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Received 32 bits of address codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); else - PDEBUG_CHAN(DPOCSAG, DEBUG_DEBUG, "Received 32 bits of message codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); + LOGP_CHAN(DPOCSAG, LOGL_DEBUG, "Received 32 bits of message codeword 0x%08x (frame %d.%d).\n", word, slot, subslot); rc = debug_word(word, slot); if (rc < 0) { done_rx_msg(pocsag); diff --git a/src/pocsag/main.c b/src/pocsag/main.c index d18b99f..2a7342a 100644 --- a/src/pocsag/main.c +++ b/src/pocsag/main.c @@ -27,7 +27,7 @@ #include <sys/stat.h> #include <fcntl.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../liboptions/options.h" @@ -220,7 +220,7 @@ static void myhandler(void) if (tx) pocsag_msg_send(language, buffer); else - PDEBUG(DPOCSAG, DEBUG_ERROR, "Failed to send message, transmitter is not enabled!\n"); + LOGP(DPOCSAG, LOGL_ERROR, "Failed to send message, transmitter is not enabled!\n"); } } } @@ -362,6 +362,7 @@ fail: pocsag_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); pocsag_exit(); diff --git a/src/pocsag/pocsag.c b/src/pocsag/pocsag.c index 40da522..4689387 100644 --- a/src/pocsag/pocsag.c +++ b/src/pocsag/pocsag.c @@ -28,10 +28,10 @@ #include <sys/time.h> #include <time.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "pocsag.h" #include "frame.h" #include "dsp.h" @@ -195,7 +195,7 @@ void pocsag_new_state(pocsag_t *pocsag, enum pocsag_state new_state) { if (pocsag->state == new_state) return; - PDEBUG(DPOCSAG, DEBUG_DEBUG, "State change: %s -> %s\n", pocsag_state_name[pocsag->state], pocsag_state_name[new_state]); + LOGP(DPOCSAG, LOGL_DEBUG, "State change: %s -> %s\n", pocsag_state_name[pocsag->state], pocsag_state_name[new_state]); pocsag->state = new_state; pocsag_display_status(); } @@ -205,16 +205,16 @@ static pocsag_msg_t *pocsag_msg_create(pocsag_t *pocsag, uint32_t callref, uint3 { pocsag_msg_t *msg, **msgp; - PDEBUG(DPOCSAG, DEBUG_INFO, "Creating msg instance to page RIC '%d' / function '%d' (%s).\n", ric, function, pocsag_function_name[function]); + LOGP(DPOCSAG, LOGL_INFO, "Creating msg instance to page RIC '%d' / function '%d' (%s).\n", ric, function, pocsag_function_name[function]); /* create */ msg = calloc(1, sizeof(*msg)); if (!msg) { - PDEBUG(DPOCSAG, DEBUG_ERROR, "No mem!\n"); + LOGP(DPOCSAG, LOGL_ERROR, "No mem!\n"); abort(); } if (strlen(text) > sizeof(msg->data)) { - PDEBUG(DPOCSAG, DEBUG_ERROR, "Text too long!\n"); + LOGP(DPOCSAG, LOGL_ERROR, "Text too long!\n"); return NULL; } @@ -280,14 +280,14 @@ static int pocsag_scan_or_loopback(pocsag_t *pocsag) default: message[0] = '\0'; } - PDEBUG_CHAN(DPOCSAG, DEBUG_NOTICE, "Transmitting %s message '%s' with RIC '%d'.\n", pocsag_function_name[pocsag->default_function], message, pocsag->scan_from); + LOGP_CHAN(DPOCSAG, LOGL_NOTICE, "Transmitting %s message '%s' with RIC '%d'.\n", pocsag_function_name[pocsag->default_function], message, pocsag->scan_from); pocsag_msg_create(pocsag, 0, pocsag->scan_from, pocsag->default_function, message); pocsag->scan_from++; return 1; } if (pocsag->sender.loopback) { - PDEBUG(DPOCSAG, DEBUG_INFO, "Sending message for loopback test.\n"); + LOGP(DPOCSAG, LOGL_INFO, "Sending message for loopback test.\n"); pocsag_msg_create(pocsag, 0, 1234567, POCSAG_FUNCTION_NUMERIC, "1234"); return 1; } @@ -344,23 +344,23 @@ int pocsag_create(const char *kanal, double frequency, const char *device, int u pocsag = calloc(1, sizeof(*pocsag)); if (!pocsag) { - PDEBUG(DPOCSAG, DEBUG_ERROR, "No memory!\n"); + LOGP(DPOCSAG, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DPOCSAG, DEBUG_DEBUG, "Creating 'POCSAG' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DPOCSAG, LOGL_DEBUG, "Creating 'POCSAG' instance for 'Kanal' = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&pocsag->sender, kanal, frequency, frequency, device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DPOCSAG, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DPOCSAG, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } /* init audio processing */ rc = dsp_init_sender(pocsag, samplerate, (double)baudrate, deviation, polarity); if (rc < 0) { - PDEBUG(DPOCSAG, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DPOCSAG, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } @@ -374,7 +374,7 @@ int pocsag_create(const char *kanal, double frequency, const char *device, int u pocsag_display_status(); - PDEBUG(DPOCSAG, DEBUG_NOTICE, "Created 'Kanal' %s\n", kanal); + LOGP(DPOCSAG, LOGL_NOTICE, "Created 'Kanal' %s\n", kanal); pocsag_scan_or_loopback(pocsag); @@ -391,7 +391,7 @@ void pocsag_destroy(sender_t *sender) { pocsag_t *pocsag = (pocsag_t *) sender; - PDEBUG(DPOCSAG, DEBUG_DEBUG, "Destroying 'POCSAG' instance for 'Kanal' = %s.\n", sender->kanal); + LOGP(DPOCSAG, LOGL_DEBUG, "Destroying 'POCSAG' instance for 'Kanal' = %s.\n", sender->kanal); while (pocsag->msg_list) pocsag_msg_destroy(pocsag->msg_list); @@ -417,29 +417,29 @@ void pocsag_msg_send(enum pocsag_language language, const char *text) if (!ric_string || !function_string) { inval: - PDEBUG(DNMT, DEBUG_NOTICE, "Given message MUST be in the following format: RIC,function[,<message with comma and spaces>] (function must be A = 0 = numeric, B = 1 or C = 2 = beep, D = 3 = alphanumeric)\n"); + LOGP(DNMT, LOGL_NOTICE, "Given message MUST be in the following format: RIC,function[,<message with comma and spaces>] (function must be A = 0 = numeric, B = 1 or C = 2 = beep, D = 3 = alphanumeric)\n"); return; } ric = atoi(ric_string); if (ric > 2097151) { - PDEBUG(DNMT, DEBUG_NOTICE, "Illegal RIC %d. Maximum allowed RIC is (2^21)-1. (2097151)\n", ric); + LOGP(DNMT, LOGL_NOTICE, "Illegal RIC %d. Maximum allowed RIC is (2^21)-1. (2097151)\n", ric); goto inval; } if (ric == 1003832) { - PDEBUG(DNMT, DEBUG_NOTICE, "Illegal RIC 1003832. (Used as idle codeword)\n"); + LOGP(DNMT, LOGL_NOTICE, "Illegal RIC 1003832. (Used as idle codeword)\n"); goto inval; } rc = pocsag_function_name2value(function_string); if (rc < 0) { - PDEBUG(DNMT, DEBUG_NOTICE, "Illegal function '%s'.\n", function_string); + LOGP(DNMT, LOGL_NOTICE, "Illegal function '%s'.\n", function_string); goto inval; } function = rc; if (message && (function == 1 || function == 2)) { - PDEBUG(DNMT, DEBUG_NOTICE, "Message text is not allowed with function %d.\n", function); + LOGP(DNMT, LOGL_NOTICE, "Message text is not allowed with function %d.\n", function); goto inval; } @@ -470,7 +470,7 @@ inval: if (!message) message=""; - PDEBUG(DNMT, DEBUG_INFO, "Message for ID '%d/%d' with text '%s'\n", ric, function, message); + LOGP(DNMT, LOGL_INFO, "Message for ID '%d/%d' with text '%s'\n", ric, function, message); pocsag = (pocsag_t *) sender_head; pocsag_msg_create(pocsag, 0, ric, function, message); @@ -505,9 +505,9 @@ int call_down_setup(int callref, const char *caller_id, enum number_type __attri } if (!sender) { if (channel) - PDEBUG(DPOCSAG, DEBUG_NOTICE, "Cannot page, because given station not available, rejecting!\n"); + LOGP(DPOCSAG, LOGL_NOTICE, "Cannot page, because given station not available, rejecting!\n"); else - PDEBUG(DPOCSAG, DEBUG_NOTICE, "Cannot page, no trasmitting station available, rejecting!\n"); + LOGP(DPOCSAG, LOGL_NOTICE, "Cannot page, no trasmitting station available, rejecting!\n"); return -CAUSE_NOCHANNEL; } @@ -548,7 +548,7 @@ void call_down_answer(int __attribute__((unused)) callref) static void _release(int __attribute__((unused)) callref, int __attribute__((unused)) cause) { - PDEBUG(DPOCSAG, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DPOCSAG, LOGL_INFO, "Call has been disconnected by network.\n"); } void call_down_disconnect(int callref, int cause) diff --git a/src/r2000/Makefile.am b/src/r2000/Makefile.am index 6b52ff1..0ae463e 100644 --- a/src/r2000/Makefile.am +++ b/src/r2000/Makefile.am @@ -13,15 +13,11 @@ radiocom2000_SOURCES = \ radiocom2000_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libcompandor/libcompandor.a \ $(top_builddir)/src/libjitter/libjitter.a \ $(top_builddir)/src/libhagelbarger/libhagelbarger.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfsk/libfsk.a \ @@ -29,8 +25,10 @@ radiocom2000_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA diff --git a/src/r2000/dsp.c b/src/r2000/dsp.c index 6254ca9..a32f6e8 100644 --- a/src/r2000/dsp.c +++ b/src/r2000/dsp.c @@ -26,7 +26,7 @@ #include <errno.h> #include <math.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "r2000.h" #include "dsp.h" @@ -78,20 +78,20 @@ int dsp_init_sender(r2000_t *r2000) /* attack (3ms) and recovery time (13.5ms) according to NMT specs */ setup_compandor(&r2000->cstate, 8000, 3.0, 13.5); - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for Transceiver.\n"); /* set modulation parameters */ sender_set_fm(&r2000->sender, MAX_DEVIATION, MAX_MODULATION, SPEECH_DEVIATION, MAX_DISPLAY); - PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f\n", TX_PEAK_FSK); + LOGP(DDSP, LOGL_DEBUG, "Using FSK level of %.3f\n", TX_PEAK_FSK); /* init fsk */ if (fsk_mod_init(&r2000->fsk_mod, r2000, fsk_send_bit, r2000->sender.samplerate, FSK_BIT_RATE, FSK_F0, FSK_F1, TX_PEAK_FSK, 1, 0) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } if (fsk_demod_init(&r2000->fsk_demod, r2000, fsk_receive_bit, r2000->sender.samplerate, FSK_BIT_RATE, FSK_F0, FSK_F1, FSK_BIT_ADJUST) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } if (r2000->sender.loopback) @@ -101,11 +101,11 @@ int dsp_init_sender(r2000_t *r2000) /* init supervisorty fsk */ if (fsk_mod_init(&r2000->super_fsk_mod, r2000, super_send_bit, r2000->sender.samplerate, SUPER_BIT_RATE, SUPER_F0, SUPER_F1, TX_PEAK_SUPER, 0, 0) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } if (fsk_demod_init(&r2000->super_fsk_demod, r2000, super_receive_bit, r2000->sender.samplerate, SUPER_BIT_RATE, SUPER_F0, SUPER_F1, SUPER_BIT_ADJUST) < 0) { - PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n"); + LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n"); return -EINVAL; } @@ -129,7 +129,7 @@ int dsp_init_sender(r2000_t *r2000) /* Cleanup transceiver instance. */ void dsp_cleanup_sender(r2000_t *r2000) { - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for Transceiver.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for Transceiver.\n"); fsk_mod_cleanup(&r2000->fsk_mod); fsk_demod_cleanup(&r2000->fsk_demod); @@ -309,7 +309,7 @@ static int fsk_send_bit(void *inst) frame = r2000_get_frame(r2000); if (!frame) { r2000->tx_frame_length = 0; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Stop sending frames.\n"); + LOGP_CHAN(DDSP, LOGL_DEBUG, "Stop sending frames.\n"); return -1; } memcpy(r2000->tx_frame, frame, 208); @@ -416,9 +416,9 @@ void r2000_set_dsp_mode(r2000_t *r2000, enum dsp_mode mode, int super) r2000->super_tx_word = 0x40101 | ((super & 0x7f) << 1); /* clear pending data in rx word */ r2000->super_rx_word = 0x00000; - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s (super = 0x%05x)\n", r2000_dsp_mode_name(r2000->dsp_mode), r2000_dsp_mode_name(mode), r2000->super_tx_word); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s (super = 0x%05x)\n", r2000_dsp_mode_name(r2000->dsp_mode), r2000_dsp_mode_name(mode), r2000->super_tx_word); } else if (r2000->dsp_mode != mode) - PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", r2000_dsp_mode_name(r2000->dsp_mode), r2000_dsp_mode_name(mode)); + LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", r2000_dsp_mode_name(r2000->dsp_mode), r2000_dsp_mode_name(mode)); r2000->dsp_mode = mode; } diff --git a/src/r2000/frame.c b/src/r2000/frame.c index b231041..88f56e0 100644 --- a/src/r2000/frame.c +++ b/src/r2000/frame.c @@ -23,7 +23,7 @@ #include <stdlib.h> #include <errno.h> #include <inttypes.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libhagelbarger/hagelbarger.h" #include "frame.h" @@ -208,11 +208,11 @@ static void print_element(char element, uint64_t value, int dir, int debug) decoder = (dir == REL_TO_SM) ? r2000_element[i].decoder_rel : r2000_element[i].decoder_sm; if (!r2000_element[i].element) - PDEBUG(DFRAME, debug, "Element '%c' %" PRIu64 " [Unknown]\n", element, value); + LOGP(DFRAME, debug, "Element '%c' %" PRIu64 " [Unknown]\n", element, value); else if (!decoder) - PDEBUG(DFRAME, debug, "Element '%c' %" PRIu64 " [%s]\n", element, value, r2000_element[i].name); + LOGP(DFRAME, debug, "Element '%c' %" PRIu64 " [%s]\n", element, value, r2000_element[i].name); else - PDEBUG(DFRAME, debug, "Element '%c' %" PRIu64 "=%s [%s]\n", element, value, decoder(value), r2000_element[i].name); + LOGP(DFRAME, debug, "Element '%c' %" PRIu64 "=%s [%s]\n", element, value, decoder(value), r2000_element[i].name); } static void store_element(frame_t *frame, char element, uint64_t value) @@ -413,17 +413,17 @@ static void display_bits(const char *def, const uint8_t *message, int num, int d char dispbits[num + 1]; int i; - if (debuglevel > debug) + if (loglevel > debug) return; /* display bits */ if (def) - PDEBUG(DFRAME, debug, "%s\n", def); + LOGP(DFRAME, debug, "%s\n", def); for (i = 0; i < num; i++) { dispbits[i] = ((message[i / 8] >> (7 - (i & 7))) & 1) + '0'; } dispbits[i] = '\0'; - PDEBUG(DFRAME, debug, "%s\n", dispbits); + LOGP(DFRAME, debug, "%s\n", dispbits); } static int dissassemble_frame(frame_t *frame, const uint8_t *message, int num) @@ -438,12 +438,12 @@ static int dissassemble_frame(frame_t *frame, const uint8_t *message, int num) frame->message = message[2] & 0x1f; def = get_frame_def(frame->message, dir); if (!def) { - PDEBUG(DFRAME, DEBUG_NOTICE, "Received unknown message type %d (maybe radio noise)\n", frame->message); - display_bits(NULL, message, num, DEBUG_NOTICE); + LOGP(DFRAME, LOGL_NOTICE, "Received unknown message type %d (maybe radio noise)\n", frame->message); + display_bits(NULL, message, num, LOGL_NOTICE); return -EINVAL; } - PDEBUG(DFRAME, DEBUG_DEBUG, "Decoding frame %s %s\n", r2000_dir_name(dir), r2000_frame_name(frame->message, dir)); + LOGP(DFRAME, LOGL_DEBUG, "Decoding frame %s %s\n", r2000_dir_name(dir), r2000_frame_name(frame->message, dir)); /* disassemble elements elements */ value = 0; @@ -451,14 +451,14 @@ static int dissassemble_frame(frame_t *frame, const uint8_t *message, int num) value = (value << 1) | ((message[i / 8] >> (7 - (i & 7))) & 1); if (def[i + 1] != def[i]) { if (def[i] != '-') { - print_element(def[i], value, dir, DEBUG_DEBUG); + print_element(def[i], value, dir, LOGL_DEBUG); store_element(frame, def[i], value); } value = 0; } } - display_bits(def, message, num, DEBUG_DEBUG); + display_bits(def, message, num, LOGL_DEBUG); return 0; } @@ -473,13 +473,13 @@ static int assemble_frame(frame_t *frame, uint8_t *message, int num, int debug) def = get_frame_def(frame->message, dir); if (!def) { - PDEBUG(DFRAME, DEBUG_ERROR, "Cannot assemble unknown message type %d, please define/fix!\n", frame->message); + LOGP(DFRAME, LOGL_ERROR, "Cannot assemble unknown message type %d, please define/fix!\n", frame->message); abort(); } memset(message, 0, (num + 7) / 8); if (debug) - PDEBUG(DFRAME, DEBUG_DEBUG, "Ccoding frame %s %s\n", r2000_dir_name(dir), r2000_frame_name(frame->message, dir)); + LOGP(DFRAME, LOGL_DEBUG, "Ccoding frame %s %s\n", r2000_dir_name(dir), r2000_frame_name(frame->message, dir)); /* assemble elements elements */ element = 0; @@ -505,11 +505,11 @@ static int assemble_frame(frame_t *frame, uint8_t *message, int num, int debug) for (i = 0; i < num; i++) { if (def[i + 1] != def[i] && def[i] != '-' && def[i] != '+') { value = fetch_element(frame, def[i]); - print_element(def[i], value, dir, DEBUG_DEBUG); + print_element(def[i], value, dir, LOGL_DEBUG); } } - display_bits(def, message, num, DEBUG_DEBUG); + display_bits(def, message, num, LOGL_DEBUG); } return 0; diff --git a/src/r2000/main.c b/src/r2000/main.c index 5aed476..891211f 100644 --- a/src/r2000/main.c +++ b/src/r2000/main.c @@ -28,7 +28,7 @@ #include <sys/stat.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "r2000.h" #include "dsp.h" @@ -376,6 +376,7 @@ fail: r2000_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); diff --git a/src/r2000/r2000.c b/src/r2000/r2000.c index 0b7b5cf..a0193ae 100644 --- a/src/r2000/r2000.c +++ b/src/r2000/r2000.c @@ -26,25 +26,25 @@ #include <errno.h> #include <time.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/cause.h" -#include "../libosmocc/message.h" +#include <osmocom/cc/message.h> #include "r2000.h" //#include "transaction.h" #include "frame.h" #include "dsp.h" -#define CUT_OFF_EMPHASIS_R2000 300 //FIXME: use real cut-off / time constant +#define CUT_OFF_EMPHASIS_R2000 300 //FIXME: use real cut-off / time constant -#define PAGE_TRIES 3 /* how many times trying to page */ -#define IDENT_TIME 3.0 /* time to wait for identity response */ -#define ALERT_TIME 60.0 /* time to wait for party to answer */ -#define DIAL1_TIME 1.0 /* time to wait for party to dial digits 1..10 */ -#define DIAL2_TIME 0.5 /* time to wait for party to dial digits 11..20 */ -#define SUSPEND_TIME 1.0 /* time to wait for suspend response */ -#define SUPER_TIME1 4.0 /* time to release if not receiving initial supervisory signal */ -#define SUPER_TIME2 20.0 /* time to release after loosing supervisory signal */ -#define RELEASE_TIME 2.0 /* time to wait for release response */ +#define PAGE_TRIES 3 /* how many times trying to page */ +#define IDENT_TIME 3,0 /* time to wait for identity response */ +#define ALERT_TIME 60,0 /* time to wait for party to answer */ +#define DIAL1_TIME 1,0 /* time to wait for party to dial digits 1..10 */ +#define DIAL2_TIME 0,500000 /* time to wait for party to dial digits 11..20 */ +#define SUSPEND_TIME 1,0 /* time to wait for suspend response */ +#define SUPER_TIME1 4,0 /* time to release if not receiving initial supervisory signal */ +#define SUPER_TIME2 20,0 /* time to release after loosing supervisory signal */ +#define RELEASE_TIME 2,0 /* time to wait for release response */ /* definition of bands and channels */ #define CHANNEL_SPACING 0.0125 @@ -101,12 +101,12 @@ double r2000_channel2freq(int band, int channel, int uplink) } if (!r2000_bands[i].name) { - PDEBUG(DR2000, DEBUG_NOTICE, "Given band number is invalid! (use '-B list' for valid bands)\n"); + LOGP(DR2000, LOGL_NOTICE, "Given band number is invalid! (use '-B list' for valid bands)\n"); return 0.0; } if (channel < 0 || channel > r2000_bands[i].channels - 1) { - PDEBUG(DR2000, DEBUG_NOTICE, "Given channel number %d invalid! (use '-B list' for valid channels)\n", channel); + LOGP(DR2000, LOGL_NOTICE, "Given channel number %d invalid! (use '-B list' for valid channels)\n", channel); return 0.0; } @@ -231,7 +231,7 @@ int r2000_channel_by_short_name(const char *short_name) for (i = 0; r2000_channels[i].short_name; i++) { if (!strcasecmp(r2000_channels[i].short_name, short_name)) { - PDEBUG(DR2000, DEBUG_INFO, "Selecting channel '%s' = %s\n", r2000_channels[i].short_name, r2000_channels[i].long_name); + LOGP(DR2000, LOGL_INFO, "Selecting channel '%s' = %s\n", r2000_channels[i].short_name, r2000_channels[i].long_name); return r2000_channels[i].chan_type; } } @@ -267,7 +267,7 @@ static void r2000_new_state(r2000_t *r2000, enum r2000_state new_state) { if (r2000->state == new_state) return; - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "State change: %s -> %s\n", r2000_state_name(r2000->state), r2000_state_name(new_state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "State change: %s -> %s\n", r2000_state_name(r2000->state), r2000_state_name(new_state)); r2000->state = new_state; r2000_display_status(); r2000->tx_frame_count = 0; @@ -314,11 +314,11 @@ static int string2subscriber(const char *dialstring, r2000_subscriber_t *subscr) static int match_voie(r2000_t *r2000, frame_t *frame, uint8_t voie) { if (frame->voie == 0 && voie == 1) { - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Frame for control channel, but expecting traffic channel, ignoring. (maybe radio noise)\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Frame for control channel, but expecting traffic channel, ignoring. (maybe radio noise)\n"); return 0; } if (frame->voie == 1 && voie == 0) { - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Frame for traffic channel, but expecting control channel, ignoring. (maybe radio noise)\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Frame for traffic channel, but expecting control channel, ignoring. (maybe radio noise)\n"); return 0; } @@ -328,7 +328,7 @@ static int match_voie(r2000_t *r2000, frame_t *frame, uint8_t voie) static int match_channel(r2000_t *r2000, frame_t *frame) { if (frame->channel != atoi(r2000->sender.kanal)) { - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Frame for different channel %d received, ignoring.\n", frame->channel); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Frame for different channel %d received, ignoring.\n", frame->channel); return 0; } @@ -338,7 +338,7 @@ static int match_channel(r2000_t *r2000, frame_t *frame) static int match_relais(r2000_t *r2000, frame_t *frame) { if (frame->relais != r2000->sysinfo.relais) { - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Frame for different relais %d received, ignoring.\n", frame->relais); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Frame for different relais %d received, ignoring.\n", frame->relais); return 0; } @@ -353,7 +353,7 @@ static int match_subscriber(r2000_t *r2000, frame_t *frame) if (r2000->subscriber.relais != frame->sm_relais || r2000->subscriber.mor != frame->sm_mor) { - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Frame for different subscriber '%s' received, ignoring.\n", print_subscriber_frame(frame)); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Frame for different subscriber '%s' received, ignoring.\n", print_subscriber_frame(frame)); return 0; } @@ -377,7 +377,7 @@ uint8_t r2000_encode_super(r2000_t *r2000) | ((relais << 2) & 0x10) | (relais & 0x08); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "TX Supervisory: NCONV: %d relais (4 lowest bits): %d\n", nconv, relais); + LOGP_CHAN(DDSP, LOGL_INFO, "TX Supervisory: NCONV: %d relais (4 lowest bits): %d\n", nconv, relais); return super ^ 0x7f; } @@ -399,27 +399,27 @@ int r2000_create(int band, const char *kanal, enum r2000_chan_type chan_type, co r2000 = (r2000_t *)sender; if ((r2000->sysinfo.chan_type == CHAN_TYPE_CC || r2000->sysinfo.chan_type == CHAN_TYPE_CC_TC) && (chan_type == CHAN_TYPE_CC || chan_type == CHAN_TYPE_CC_TC)) { - PDEBUG(DCNETZ, DEBUG_NOTICE, "More than one control channel is not supported, please define other channels as traffic channels!\n"); + LOGP(DCNETZ, LOGL_NOTICE, "More than one control channel is not supported, please define other channels as traffic channels!\n"); return -EINVAL; } } r2000 = calloc(1, sizeof(r2000_t)); if (!r2000) { - PDEBUG(DR2000, DEBUG_ERROR, "No memory!\n"); + LOGP(DR2000, LOGL_ERROR, "No memory!\n"); return -ENOMEM; } - PDEBUG(DR2000, DEBUG_DEBUG, "Creating 'Radiocom 2000' instance for channel = %s (sample rate %d).\n", kanal, samplerate); + LOGP(DR2000, LOGL_DEBUG, "Creating 'Radiocom 2000' instance for channel = %s (sample rate %d).\n", kanal, samplerate); /* init general part of transceiver */ rc = sender_create(&r2000->sender, kanal, r2000_channel2freq(band, atoi(kanal), 0), r2000_channel2freq(band, atoi(kanal), 1), device, use_sdr, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE); if (rc < 0) { - PDEBUG(DR2000, DEBUG_ERROR, "Failed to init transceiver process!\n"); + LOGP(DR2000, LOGL_ERROR, "Failed to init transceiver process!\n"); goto error; } - timer_init(&r2000->timer, r2000_timeout, r2000); + osmo_timer_setup(&r2000->timer, r2000_timeout, r2000); r2000->sysinfo.relais = relais; r2000->sysinfo.chan_type = chan_type; r2000->sysinfo.deport = deport; @@ -430,7 +430,7 @@ int r2000_create(int band, const char *kanal, enum r2000_chan_type chan_type, co r2000->sysinfo.nconv = nconv; r2000->sysinfo.recall = recall; if (crins == 3 && destruction != 2342) { - PDEBUG(DR2000, DEBUG_ERROR, "Crins is 3, but destruction is not confirmed, please fix!\n"); + LOGP(DR2000, LOGL_ERROR, "Crins is 3, but destruction is not confirmed, please fix!\n"); abort(); } r2000->compandor = 1; @@ -445,14 +445,14 @@ int r2000_create(int band, const char *kanal, enum r2000_chan_type chan_type, co /* init audio processing */ rc = dsp_init_sender(r2000); if (rc < 0) { - PDEBUG(DR2000, DEBUG_ERROR, "Failed to init audio processing!\n"); + LOGP(DR2000, LOGL_ERROR, "Failed to init audio processing!\n"); goto error; } /* go into idle state */ r2000_go_idle(r2000); - PDEBUG(DR2000, DEBUG_NOTICE, "Created channel #%s of type '%s' = %s\n", kanal, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); + LOGP(DR2000, LOGL_NOTICE, "Created channel #%s of type '%s' = %s\n", kanal, chan_type_short_name(chan_type), chan_type_long_name(chan_type)); return 0; @@ -481,18 +481,18 @@ void r2000_check_channels(void) } } if (cc && !tc) { - PDEBUG(DR2000, DEBUG_NOTICE, "*** Selected channel(s) can be used for control only.\n"); - PDEBUG(DR2000, DEBUG_NOTICE, "*** No call is possible at all!\n"); - PDEBUG(DR2000, DEBUG_NOTICE, "*** Use combined 'CC/TC' instead!\n"); + LOGP(DR2000, LOGL_NOTICE, "*** Selected channel(s) can be used for control only.\n"); + LOGP(DR2000, LOGL_NOTICE, "*** No call is possible at all!\n"); + LOGP(DR2000, LOGL_NOTICE, "*** Use combined 'CC/TC' instead!\n"); } if (tc && !cc) { - PDEBUG(DR2000, DEBUG_NOTICE, "*** Selected channel(s) can be used for traffic only.\n"); - PDEBUG(DR2000, DEBUG_NOTICE, "*** No register/call is possible at all!\n"); - PDEBUG(DR2000, DEBUG_NOTICE, "*** Use combined 'CC/TC' instead!\n"); + LOGP(DR2000, LOGL_NOTICE, "*** Selected channel(s) can be used for traffic only.\n"); + LOGP(DR2000, LOGL_NOTICE, "*** No register/call is possible at all!\n"); + LOGP(DR2000, LOGL_NOTICE, "*** Use combined 'CC/TC' instead!\n"); } if (combined) { - PDEBUG(DR2000, DEBUG_NOTICE, "*** Selected (non standard) combined 'CC/TC'.\n"); - PDEBUG(DR2000, DEBUG_NOTICE, "Phones might reject this, but non of my phones does, so it's ok.\n"); + LOGP(DR2000, LOGL_NOTICE, "*** Selected (non standard) combined 'CC/TC'.\n"); + LOGP(DR2000, LOGL_NOTICE, "Phones might reject this, but non of my phones does, so it's ok.\n"); } } @@ -501,9 +501,9 @@ void r2000_destroy(sender_t *sender) { r2000_t *r2000 = (r2000_t *) sender; - PDEBUG(DR2000, DEBUG_DEBUG, "Destroying 'Radiocom 2000' instance for channel = %s.\n", sender->kanal); + LOGP(DR2000, LOGL_DEBUG, "Destroying 'Radiocom 2000' instance for channel = %s.\n", sender->kanal); dsp_cleanup_sender(r2000); - timer_exit(&r2000->timer); + osmo_timer_del(&r2000->timer); sender_destroy(&r2000->sender); free(r2000); } @@ -511,19 +511,19 @@ void r2000_destroy(sender_t *sender) /* go idle and return to frame mode */ void r2000_go_idle(r2000_t *r2000) { - timer_stop(&r2000->timer); + osmo_timer_del(&r2000->timer); if (r2000->callref) { - PDEBUG(DR2000, DEBUG_ERROR, "Going idle, but still having callref, please fix!\n"); + LOGP(DR2000, LOGL_ERROR, "Going idle, but still having callref, please fix!\n"); call_up_release(r2000->callref, CAUSE_NORMAL); r2000->callref = 0; } if (r2000->sysinfo.chan_type == CHAN_TYPE_TC) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Entering IDLE state, no transmission at relais %d on %s.\n", r2000->sysinfo.relais, chan_type_long_name(r2000->sysinfo.chan_type)); + LOGP_CHAN(DR2000, LOGL_INFO, "Entering IDLE state, no transmission at relais %d on %s.\n", r2000->sysinfo.relais, chan_type_long_name(r2000->sysinfo.chan_type)); r2000_set_dsp_mode(r2000, DSP_MODE_OFF, -1); } else { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Entering IDLE state, sending idle frames at relais %d on %s.\n", r2000->sysinfo.relais, chan_type_long_name(r2000->sysinfo.chan_type)); + LOGP_CHAN(DR2000, LOGL_INFO, "Entering IDLE state, sending idle frames at relais %d on %s.\n", r2000->sysinfo.relais, chan_type_long_name(r2000->sysinfo.chan_type)); r2000_set_dsp_mode(r2000, DSP_MODE_FRAME, (r2000->sender.loopback) ? r2000_encode_super(r2000) : -1); } r2000_new_state(r2000, STATE_IDLE); @@ -541,18 +541,18 @@ void r2000_release(r2000_t *r2000) || r2000->state == STATE_RECALL_WAIT) { /* release on CC */ r2000_new_state(r2000, STATE_RELEASE_CC); - timer_start(&r2000->timer, RELEASE_TIME); + osmo_timer_schedule(&r2000->timer, RELEASE_TIME); } else { /* release on TC */ r2000_new_state(r2000, STATE_RELEASE_TC); - timer_start(&r2000->timer, RELEASE_TIME); + osmo_timer_schedule(&r2000->timer, RELEASE_TIME); } r2000_set_dsp_mode(r2000, DSP_MODE_FRAME, -1); } static void r2000_page(r2000_t *r2000, int try, enum r2000_state state) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Entering paging state (try %d), sending 'Appel' to '%s'.\n", try, print_subscriber_subscr(&r2000->subscriber)); + LOGP_CHAN(DR2000, LOGL_INFO, "Entering paging state (try %d), sending 'Appel' to '%s'.\n", try, print_subscriber_subscr(&r2000->subscriber)); r2000_new_state(r2000, state); r2000->page_try = try; } @@ -586,13 +586,13 @@ static r2000_t *move_call_to_chan(r2000_t *old_r2000, enum r2000_chan_type chan_ /* no free channel, reuse combined channel, if possible, or release call */ if (!new_r2000 && old_r2000->sysinfo.chan_type == CHAN_TYPE_CC_TC) { - PDEBUG(DR2000, DEBUG_NOTICE, "No %s found, straying on %s!\n", chan_type_long_name(chan_type), chan_type_long_name(old_r2000->sysinfo.chan_type)); + LOGP(DR2000, LOGL_NOTICE, "No %s found, straying on %s!\n", chan_type_long_name(chan_type), chan_type_long_name(old_r2000->sysinfo.chan_type)); return old_r2000; } if (!new_r2000) { - PDEBUG(DR2000, DEBUG_NOTICE, "Cannot move us to %s, because there is no free channel!\n", chan_type_long_name(chan_type)); + LOGP(DR2000, LOGL_NOTICE, "Cannot move us to %s, because there is no free channel!\n", chan_type_long_name(chan_type)); if (old_r2000->callref) { - PDEBUG(DR2000, DEBUG_NOTICE, "Failed to assign channel, releasing towards network\n"); + LOGP(DR2000, LOGL_NOTICE, "Failed to assign channel, releasing towards network\n"); call_up_release(old_r2000->callref, CAUSE_NOCHANNEL); old_r2000->callref = 0; } @@ -651,11 +651,11 @@ static void rx_idle(r2000_t *r2000, frame_t *frame) r2000->subscriber.relais = frame->sm_relais; r2000->subscriber.mor = frame->sm_mor; - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received inscription from station mobile '%s'\n", print_subscriber_subscr(&r2000->subscriber)); - PDEBUG_CHAN(DR2000, DEBUG_INFO, " -> Mobile Type: %d'\n", r2000->subscriber.type); - PDEBUG_CHAN(DR2000, DEBUG_INFO, " -> Home Relais: %d'\n", r2000->subscriber.relais); - PDEBUG_CHAN(DR2000, DEBUG_INFO, " -> Mobile ID: %d'\n", r2000->subscriber.mor); - PDEBUG_CHAN(DR2000, DEBUG_INFO, " (Use '%s' as dial string to call the station mobile.)'\n", subscriber2string(&r2000->subscriber)); + LOGP_CHAN(DR2000, LOGL_INFO, "Received inscription from station mobile '%s'\n", print_subscriber_subscr(&r2000->subscriber)); + LOGP_CHAN(DR2000, LOGL_INFO, " -> Mobile Type: %d'\n", r2000->subscriber.type); + LOGP_CHAN(DR2000, LOGL_INFO, " -> Home Relais: %d'\n", r2000->subscriber.relais); + LOGP_CHAN(DR2000, LOGL_INFO, " -> Mobile ID: %d'\n", r2000->subscriber.mor); + LOGP_CHAN(DR2000, LOGL_INFO, " (Use '%s' as dial string to call the station mobile.)'\n", subscriber2string(&r2000->subscriber)); r2000_new_state(r2000, STATE_INSCRIPTION); break; @@ -666,18 +666,18 @@ static void rx_idle(r2000_t *r2000, frame_t *frame) r2000->subscriber.relais = frame->sm_relais; r2000->subscriber.mor = frame->sm_mor; - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received outgoing call from station mobile '%s'\n", print_subscriber_frame(frame)); + LOGP_CHAN(DR2000, LOGL_INFO, "Received outgoing call from station mobile '%s'\n", print_subscriber_frame(frame)); r2000_t *tc = get_free_chan(CHAN_TYPE_TC); if (!tc) { - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Rejecting mobile originated call, no free traffic channel\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Rejecting mobile originated call, no free traffic channel\n"); r2000_release(r2000); return; } r2000_new_state(r2000, STATE_OUT_ASSIGN); break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); } } @@ -691,7 +691,7 @@ static void tx_inscription(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; frame->crins = r2000->sysinfo.crins; - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending inscription acknowledge\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending inscription acknowledge\n"); r2000_go_idle(r2000); } @@ -721,10 +721,10 @@ static void tx_out_assign(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; frame->chan_assign = atoi(tc->sender.kanal); - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending outgoing assignment from channel %s to %s\n", r2000->sender.kanal, tc->sender.kanal); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending outgoing assignment from channel %s to %s\n", r2000->sender.kanal, tc->sender.kanal); r2000_new_state(tc, (tc->state == STATE_OUT_ASSIGN) ? STATE_OUT_IDENT : STATE_RECALL_IDENT); - timer_start(&tc->timer, IDENT_TIME); + osmo_timer_schedule(&tc->timer, IDENT_TIME); } /* page phone, assign incoming call */ @@ -748,10 +748,10 @@ static void tx_in_assign(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; frame->chan_assign = atoi(tc->sender.kanal); - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending incoming assignment from channel %s to %s\n", r2000->sender.kanal, tc->sender.kanal); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending incoming assignment from channel %s to %s\n", r2000->sender.kanal, tc->sender.kanal); r2000_new_state(tc, STATE_IN_IDENT); - timer_start(&tc->timer, IDENT_TIME); + osmo_timer_schedule(&tc->timer, IDENT_TIME); } /* @@ -768,7 +768,7 @@ static void tx_ident(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; if (r2000->tx_frame_count == 1) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending identity request\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending identity request\n"); } /* receive identity response */ @@ -786,38 +786,38 @@ static void rx_ident(r2000_t *r2000, frame_t *frame) switch(frame->message) { case 16: /* identity response */ - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received identity response from station mobile '%s'\n", print_subscriber_frame(frame)); + LOGP_CHAN(DR2000, LOGL_INFO, "Received identity response from station mobile '%s'\n", print_subscriber_frame(frame)); switch (r2000->state) { case STATE_IN_IDENT: /* alert the phone */ r2000_new_state(r2000, STATE_IN_ALERT); - timer_start(&r2000->timer, ALERT_TIME); + osmo_timer_schedule(&r2000->timer, ALERT_TIME); call_up_alerting(r2000->callref); break; case STATE_RECALL_IDENT: /* alert the phone */ r2000_new_state(r2000, STATE_RECALL_ALERT); - timer_start(&r2000->timer, ALERT_TIME); + osmo_timer_schedule(&r2000->timer, ALERT_TIME); break; case STATE_OUT_IDENT: /* request dial string */ r2000_new_state(r2000, STATE_OUT_DIAL1); - timer_start(&r2000->timer, DIAL1_TIME); + osmo_timer_schedule(&r2000->timer, DIAL1_TIME); break; default: break; } break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); } } /* no identity response from phone */ static void timeout_out_ident(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout receiving identity (outgoing call)\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout receiving identity (outgoing call)\n"); r2000_go_idle(r2000); } @@ -825,9 +825,9 @@ static void timeout_out_ident(r2000_t *r2000) static void timeout_in_ident(r2000_t *r2000) { if (r2000->state == STATE_IN_IDENT) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout receiving identity (incoming call)\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout receiving identity (incoming call)\n"); else - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout receiving identity (recalling outgoing call)\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout receiving identity (recalling outgoing call)\n"); /* move us back to cc */ r2000 = move_call_to_chan(r2000, CHAN_TYPE_CC); @@ -841,7 +841,7 @@ static void timeout_in_ident(r2000_t *r2000) } /* ... or release */ - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Phone does not response, releasing towards network\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Phone does not response, releasing towards network\n"); call_up_release(r2000->callref, CAUSE_OUTOFORDER); r2000->callref = 0; r2000_release(r2000); @@ -868,13 +868,13 @@ static void tx_alert(r2000_t *r2000, frame_t *frame) tx_invitation(r2000, frame, 3, r2000->sysinfo.nconv); if (r2000->tx_frame_count == 1) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending answer invitation to station mobile\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending answer invitation to station mobile\n"); } static int setup_call(r2000_t *r2000) { /* make call toward network */ - PDEBUG(DR2000, DEBUG_INFO, "Setup call to network.\n"); + LOGP(DR2000, LOGL_INFO, "Setup call to network.\n"); r2000->callref = call_up_setup(subscriber2string(&r2000->subscriber), r2000->subscriber.dialing, OSMO_CC_NETWORK_R2000_NONE, ""); return 0; @@ -895,12 +895,12 @@ static void rx_alert(r2000_t *r2000, frame_t *frame) switch(frame->message) { case 17: /* answer */ - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received answer from station mobile '%s'\n", print_subscriber_frame(frame)); + LOGP_CHAN(DR2000, LOGL_INFO, "Received answer from station mobile '%s'\n", print_subscriber_frame(frame)); switch (r2000->state) { case STATE_IN_ALERT: /* answer incoming call */ - PDEBUG(DR2000, DEBUG_INFO, "Answer call to network.\n"); + LOGP(DR2000, LOGL_INFO, "Answer call to network.\n"); call_up_answer(r2000->callref, subscriber2string(&r2000->subscriber)); break; case STATE_OUT_ALERT: @@ -914,23 +914,23 @@ static void rx_alert(r2000_t *r2000, frame_t *frame) break; } /* go active */ - timer_stop(&r2000->timer); + osmo_timer_del(&r2000->timer); r2000_new_state(r2000, STATE_ACTIVE); r2000_set_dsp_mode(r2000, DSP_MODE_AUDIO_TX, r2000_encode_super(r2000)); /* start supervisory timer */ - timer_start(&r2000->timer, SUPER_TIME1); + osmo_timer_schedule(&r2000->timer, SUPER_TIME1); break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); } } /* no answer */ static void timeout_alert(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout while alerting\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout while alerting\n"); - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Phone does not response, releasing towards network\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Phone does not response, releasing towards network\n"); if (r2000->callref) { call_up_release(r2000->callref, CAUSE_NOANSWER); r2000->callref = 0; @@ -948,7 +948,7 @@ static void tx_out_dial(r2000_t *r2000, frame_t *frame) tx_invitation(r2000, frame, 10, 0); if (r2000->tx_frame_count == 1) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending dialing invitation to station mobile\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending dialing invitation to station mobile\n"); } /* receive digits */ @@ -970,20 +970,20 @@ static void rx_out_dial1(r2000_t *r2000, frame_t *frame) r2000->subscriber.dialing[i] = frame->digit[i] + '0'; r2000->subscriber.dialing[10] = '\0'; - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received digits 1..10 from station mobile: %s\n", r2000->subscriber.dialing); + LOGP_CHAN(DR2000, LOGL_INFO, "Received digits 1..10 from station mobile: %s\n", r2000->subscriber.dialing); r2000_new_state(r2000, STATE_OUT_DIAL2); - timer_start(&r2000->timer, DIAL2_TIME); + osmo_timer_schedule(&r2000->timer, DIAL2_TIME); break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); } } /* no digits */ static void timeout_out_dial1(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout while receiving digits (outgoing call)\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout while receiving digits (outgoing call)\n"); r2000_release(r2000); } @@ -1007,34 +1007,34 @@ static void rx_out_dial2(r2000_t *r2000, frame_t *frame) r2000->subscriber.dialing[i + 10] = frame->digit[i] + '0'; r2000->subscriber.dialing[20] = '\0'; - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received digits 11..20 from station mobile: %s\n", r2000->subscriber.dialing); + LOGP_CHAN(DR2000, LOGL_INFO, "Received digits 11..20 from station mobile: %s\n", r2000->subscriber.dialing); if (r2000->sysinfo.recall) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Suspending call until called party has answered\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Suspending call until called party has answered\n"); r2000_new_state(r2000, STATE_SUSPEND); - timer_start(&r2000->timer, SUSPEND_TIME); + osmo_timer_schedule(&r2000->timer, SUSPEND_TIME); } else { r2000_new_state(r2000, STATE_OUT_ALERT); - timer_start(&r2000->timer, ALERT_TIME); + osmo_timer_schedule(&r2000->timer, ALERT_TIME); } break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); } } /* no additional digits */ static void timeout_out_dial2(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Phone does not send digits 11..20\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Phone does not send digits 11..20\n"); if (r2000->sysinfo.recall) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Suspending call until called party has answered\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Suspending call until called party has answered\n"); r2000_new_state(r2000, STATE_SUSPEND); - timer_start(&r2000->timer, SUSPEND_TIME); + osmo_timer_schedule(&r2000->timer, SUSPEND_TIME); } else { r2000_new_state(r2000, STATE_OUT_ALERT); - timer_start(&r2000->timer, ALERT_TIME); + osmo_timer_schedule(&r2000->timer, ALERT_TIME); } } @@ -1048,7 +1048,7 @@ static void tx_suspend(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; if (r2000->tx_frame_count == 1) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending suspend frame\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending suspend frame\n"); } /* release response */ @@ -1066,9 +1066,9 @@ static void rx_suspend(r2000_t *r2000, frame_t *frame) switch(frame->message) { case 26: /* suspend ack */ - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received suspend response from station mobile '%s'\n", print_subscriber_frame(frame)); + LOGP_CHAN(DR2000, LOGL_INFO, "Received suspend response from station mobile '%s'\n", print_subscriber_frame(frame)); - timer_stop(&r2000->timer); + osmo_timer_del(&r2000->timer); /* move us back to cc */ r2000 = move_call_to_chan(r2000, CHAN_TYPE_CC); if (!r2000) @@ -1079,14 +1079,14 @@ static void rx_suspend(r2000_t *r2000, frame_t *frame) return; break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame->message, SM_TO_REL), r2000_state_name(r2000->state)); } } /* response to accept frame */ static void timeout_suspend(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Phone does not respond to suspend frame\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Phone does not respond to suspend frame\n"); r2000_release(r2000); } @@ -1097,7 +1097,7 @@ static void timeout_suspend(r2000_t *r2000) static void timeout_active(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout after loosing supervisory signal, releasing call\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout after loosing supervisory signal, releasing call\n"); call_up_release(r2000->callref, CAUSE_TEMPFAIL); r2000->callref = 0; @@ -1117,12 +1117,12 @@ static void tx_release_cc(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; if (r2000->tx_frame_count == 1) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending release towards station mobile\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending release towards station mobile\n"); } static void timeout_release_cc(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Done sending release, going idle\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Done sending release, going idle\n"); r2000_go_idle(r2000); } @@ -1136,13 +1136,13 @@ static void tx_release_tc(r2000_t *r2000, frame_t *frame) frame->sm_mor = r2000->subscriber.mor; if (r2000->tx_frame_count == 1) - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Sending release towards station mobile\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Sending release towards station mobile\n"); } static void timeout_release_tc(r2000_t *r2000) { - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Timeout while sending release, going idle\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Timeout while sending release, going idle\n"); r2000_go_idle(r2000); } @@ -1223,9 +1223,9 @@ const char *r2000_get_frame(r2000_t *r2000) bits = encode_frame(&frame, debug); if (debug) - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Sending frame %s.\n", r2000_frame_name(frame.message, REL_TO_SM)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Sending frame %s.\n", r2000_frame_name(frame.message, REL_TO_SM)); if (debug && r2000->tx_last_frame_idle) - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Subsequent IDLE frames are not show, to prevent flooding the output.\n"); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Subsequent IDLE frames are not show, to prevent flooding the output.\n"); return bits; } @@ -1234,18 +1234,18 @@ void r2000_receive_frame(r2000_t *r2000, const char *bits, double quality, doubl frame_t frame; int rc; - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RX Level: %.0f%% Quality=%.0f\n", level * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "RX Level: %.0f%% Quality=%.0f\n", level * 100.0, quality * 100.0); rc = decode_frame(&frame, bits); if (rc < 0) { - PDEBUG_CHAN(DR2000, (r2000->sender.loopback) ? DEBUG_NOTICE : DEBUG_DEBUG, "Received invalid frame.\n"); + LOGP_CHAN(DR2000, (r2000->sender.loopback) ? LOGL_NOTICE : LOGL_DEBUG, "Received invalid frame.\n"); return; } if (r2000->sender.loopback) - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Received frame %s\n", r2000_frame_name(frame.message, REL_TO_SM)); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Received frame %s\n", r2000_frame_name(frame.message, REL_TO_SM)); else - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Received frame %s\n", r2000_frame_name(frame.message, SM_TO_REL)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Received frame %s\n", r2000_frame_name(frame.message, SM_TO_REL)); if (r2000->sender.loopback) return; @@ -1263,7 +1263,7 @@ void r2000_receive_frame(r2000_t *r2000, const char *bits, double quality, doubl if (!match_subscriber(r2000, &frame)) return; - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Received release from station mobile\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Received release from station mobile\n"); if (r2000->callref) { call_up_release(r2000->callref, CAUSE_NORMAL); @@ -1297,7 +1297,7 @@ void r2000_receive_frame(r2000_t *r2000, const char *bits, double quality, doubl rx_alert(r2000, &frame); break; default: - PDEBUG_CHAN(DR2000, DEBUG_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame.message, SM_TO_REL), r2000_state_name(r2000->state)); + LOGP_CHAN(DR2000, LOGL_DEBUG, "Dropping frame %s in state %s\n", r2000_frame_name(frame.message, SM_TO_REL), r2000_state_name(r2000->state)); } } @@ -1318,7 +1318,7 @@ void r2000_receive_super(r2000_t *r2000, uint8_t super, double quality, double l | ((super >> 2) & 0x04) | (super & 0x08); - PDEBUG_CHAN(DDSP, DEBUG_INFO, "RX Supervisory: NCONV: %d Relais (4 lowest bits): %d RX Level: %.0f%% Quality=%.0f\n", nconv, relais, level * 100.0, quality * 100.0); + LOGP_CHAN(DDSP, LOGL_INFO, "RX Supervisory: NCONV: %d Relais (4 lowest bits): %d RX Level: %.0f%% Quality=%.0f\n", nconv, relais, level * 100.0, quality * 100.0); if (r2000->sender.loopback) return; @@ -1333,7 +1333,7 @@ void r2000_receive_super(r2000_t *r2000, uint8_t super, double quality, double l r2000_set_dsp_mode(r2000, DSP_MODE_AUDIO_TX_RX, -1); /* reset supervisory timer */ - timer_start(&r2000->timer, SUPER_TIME2); + osmo_timer_schedule(&r2000->timer, SUPER_TIME2); } /* Timeout handling */ @@ -1392,7 +1392,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, /* 1. convert number to station mobile identification, return INVALNUMBER */ if (string2subscriber(dialing, &subscr)) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing); + LOGP(DR2000, LOGL_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing); return -CAUSE_INVALNUMBER; } @@ -1405,23 +1405,23 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, break; } if (sender) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing call to busy number, rejecting!\n"); + LOGP(DR2000, LOGL_NOTICE, "Outgoing call to busy number, rejecting!\n"); return -CAUSE_BUSY; } /* 3. check if all paging (control) channels are busy, return NOCHANNEL */ r2000 = get_free_chan(CHAN_TYPE_CC); if (!r2000) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing call, but no free control channel, rejecting!\n"); + LOGP(DR2000, LOGL_NOTICE, "Outgoing call, but no free control channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } tc = get_free_chan(CHAN_TYPE_TC); if (!tc) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing call, but no free traffic channel, rejecting!\n"); + LOGP(DR2000, LOGL_NOTICE, "Outgoing call, but no free traffic channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - PDEBUG(DR2000, DEBUG_INFO, "Call to station mobile, paging station id '%s'\n", print_subscriber_subscr(&subscr)); + LOGP(DR2000, LOGL_INFO, "Call to station mobile, paging station id '%s'\n", print_subscriber_subscr(&subscr)); /* 4. trying to page station mobile */ memcpy(&r2000->subscriber, &subscr, sizeof(r2000_subscriber_t)); @@ -1443,14 +1443,14 @@ void call_down_answer(int callref) break; } if (!sender) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing answer, but no callref!\n"); + LOGP(DR2000, LOGL_NOTICE, "Outgoing answer, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } switch (r2000->state) { case STATE_RECALL_WAIT: - PDEBUG_CHAN(DR2000, DEBUG_INFO, "Call has been answered by network, recalling station mobile.\n"); + LOGP_CHAN(DR2000, LOGL_INFO, "Call has been answered by network, recalling station mobile.\n"); r2000_page(r2000, PAGE_TRIES, STATE_RECALL_ASSIGN); call_tone_recall(callref, 1); break; @@ -1468,7 +1468,7 @@ void call_down_disconnect(int callref, int __attribute__((unused)) cause) sender_t *sender; r2000_t *r2000; - PDEBUG(DR2000, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DR2000, LOGL_INFO, "Call has been disconnected by network.\n"); for (sender = sender_head; sender; sender = sender->next) { r2000 = (r2000_t *) sender; @@ -1476,7 +1476,7 @@ void call_down_disconnect(int callref, int __attribute__((unused)) cause) break; } if (!sender) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DR2000, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } @@ -1486,7 +1486,7 @@ void call_down_disconnect(int callref, int __attribute__((unused)) cause) return; switch (r2000->state) { default: - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Outgoing disconnect, during call setup, releasing!\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Outgoing disconnect, during call setup, releasing!\n"); r2000->callref = 0; r2000_release(r2000); break; @@ -1501,7 +1501,7 @@ void call_down_release(int callref, int __attribute__((unused)) cause) sender_t *sender; r2000_t *r2000; - PDEBUG(DR2000, DEBUG_INFO, "Call has been released by network, releasing call.\n"); + LOGP(DR2000, LOGL_INFO, "Call has been released by network, releasing call.\n"); for (sender = sender_head; sender; sender = sender->next) { r2000 = (r2000_t *) sender; @@ -1509,7 +1509,7 @@ void call_down_release(int callref, int __attribute__((unused)) cause) break; } if (!sender) { - PDEBUG(DR2000, DEBUG_NOTICE, "Outgoing release, but no callref!\n"); + LOGP(DR2000, LOGL_NOTICE, "Outgoing release, but no callref!\n"); /* don't send release, because caller already released */ return; } @@ -1518,11 +1518,11 @@ void call_down_release(int callref, int __attribute__((unused)) cause) switch (r2000->state) { case STATE_ACTIVE: - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Outgoing release, during ringing, releasing!\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Outgoing release, during ringing, releasing!\n"); r2000_release(r2000); break; default: - PDEBUG_CHAN(DR2000, DEBUG_NOTICE, "Outgoing release, during call setup, releasing!\n"); + LOGP_CHAN(DR2000, LOGL_NOTICE, "Outgoing release, during call setup, releasing!\n"); r2000_release(r2000); break; } diff --git a/src/r2000/r2000.h b/src/r2000/r2000.h index 2d9d07c..b1bb03a 100644 --- a/src/r2000/r2000.h +++ b/src/r2000/r2000.h @@ -1,5 +1,5 @@ #include "../libcompandor/compandor.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> #include "../libmobile/sender.h" #include "../libmobile/call.h" #include "../libfsk/fsk.h" @@ -69,7 +69,7 @@ typedef struct r2000 { /* sender's states */ enum r2000_state state; int callref; - struct timer timer; + struct osmo_timer_list timer; r2000_subscriber_t subscriber; int page_try; /* the try number of calling the mobile */ int tx_frame_count; /* to count repeated frames */ diff --git a/src/radio/Makefile.am b/src/radio/Makefile.am index a96e3bb..97a9077 100644 --- a/src/radio/Makefile.am +++ b/src/radio/Makefile.am @@ -11,7 +11,6 @@ osmoradio_SOURCES = \ osmoradio_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ $(top_builddir)/src/libsdr/libsdr.a \ @@ -24,7 +23,8 @@ osmoradio_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libfft/libfft.a \ - $(top_builddir)/src/libtimer/libtimer.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ $(UHD_LIBS) \ $(SOAPY_LIBS) \ -lm diff --git a/src/radio/main.c b/src/radio/main.c index b58108f..eb4ad93 100644 --- a/src/radio/main.c +++ b/src/radio/main.c @@ -31,7 +31,7 @@ enum paging_signal; #include <termios.h> #include <unistd.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libsdr/sdr_config.h" #include "../libsdr/sdr.h" #include "../liboptions/options.h" @@ -299,7 +299,8 @@ int main(int argc, char *argv[]) int c; int buffer_size; - debuglevel = 0; + loglevel = LOGL_DEBUG; + logging_init(); sdr_config_init(DEFAULT_LO_OFFSET); @@ -528,3 +529,5 @@ error: return 0; } +void osmo_cc_set_log_cat(void) {} + diff --git a/src/radio/radio.c b/src/radio/radio.c index cf2c233..25da26b 100644 --- a/src/radio/radio.c +++ b/src/radio/radio.c @@ -25,7 +25,7 @@ #include <errno.h> #include <pthread.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libsound/sound.h" #include "../libclipper/clipper.h" #include "radio.h" @@ -75,7 +75,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->signal_bandwidth = bandwidth; break; case MODULATION_NONE: - PDEBUG(DRADIO, DEBUG_ERROR, "Wrong modulation, please fix!\n"); + LOGP(DRADIO, LOGL_ERROR, "Wrong modulation, please fix!\n"); goto error; } @@ -85,12 +85,12 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->tx_audio_channels = 0; rc = wave_create_playback(&radio->wave_tx_play, tx_wave_file, &_samplerate, &radio->tx_audio_channels, 1.0); if (rc < 0) { - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to create WAVE playback instance!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to create WAVE playback instance!\n"); goto error; } if (radio->tx_audio_channels != 1 && radio->tx_audio_channels != 2) { - PDEBUG(DRADIO, DEBUG_ERROR, "WAVE file must have one or two channels!\n"); + LOGP(DRADIO, LOGL_ERROR, "WAVE file must have one or two channels!\n"); goto error; } radio->tx_audio_samplerate = _samplerate; @@ -103,7 +103,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->tx_sound = sound_open(tx_audiodev, NULL, NULL, NULL, radio->tx_audio_channels, 0.0, radio->tx_audio_samplerate, radio->buffer_size, 1.0, 1.0, 0.0, 2.0); if (!radio->tx_sound) { rc = -EIO; - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to open sound device!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to open sound device!\n"); goto error; } jitter_create(&radio->tx_dejitter[0], "left", radio->tx_audio_samplerate, sizeof(sample_t), 0.050, 0.500, JITTER_FLAG_NONE); @@ -111,7 +111,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->tx_audio_mode = AUDIO_MODE_AUDIODEV; #else rc = -ENOTSUP; - PDEBUG(DRADIO, DEBUG_ERROR, "No sound card support compiled in!\n"); + LOGP(DRADIO, LOGL_ERROR, "No sound card support compiled in!\n"); goto error; #endif } else { @@ -124,7 +124,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->testtone[0] = calloc(radio->testtone_length * 2, sizeof(sample_t)); if (!radio->testtone[0]) { rc = -ENOMEM; - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to allocate test sound buffer!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to allocate test sound buffer!\n"); goto error; } radio->testtone[1] = radio->testtone[0] + radio->testtone_length; @@ -153,7 +153,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->rx_audio_channels = (radio->stereo) ? 2 : 1; rc = wave_create_record(&radio->wave_rx_rec, rx_wave_file, radio->rx_audio_samplerate, radio->rx_audio_channels, 1.0); if (rc < 0) { - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to create WAVE record instance!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to create WAVE record instance!\n"); goto error; } radio->rx_audio_mode |= AUDIO_MODE_WAVEFILE; @@ -170,7 +170,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->rx_sound = sound_open(rx_audiodev, NULL, NULL, NULL, radio->rx_audio_channels, 0.0, radio->rx_audio_samplerate, radio->buffer_size, 1.0, 1.0, 0.0, 2.0); if (!radio->rx_sound) { rc = -EIO; - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to open sound device!\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to open sound device!\n"); goto error; } jitter_create(&radio->rx_dejitter[0], "left", radio->rx_audio_samplerate, sizeof(sample_t), 0.050, 0.500, JITTER_FLAG_NONE); @@ -178,7 +178,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->rx_audio_mode |= AUDIO_MODE_AUDIODEV; #else rc = -ENOTSUP; - PDEBUG(DRADIO, DEBUG_ERROR, "No sound card support compiled in!\n"); + LOGP(DRADIO, LOGL_ERROR, "No sound card support compiled in!\n"); goto error; #endif } @@ -191,20 +191,20 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency /* check if sample rate is too low */ if (radio->tx_audio_samplerate > radio->signal_samplerate) { rc = -EINVAL; - PDEBUG(DRADIO, DEBUG_ERROR, "You have selected a signal processing sample rate of %.0f. Your audio sample rate is %.0f.\n", radio->signal_samplerate, radio->tx_audio_samplerate); - PDEBUG(DRADIO, DEBUG_ERROR, "Please select a sample rate that is higher or equal the audio sample rate!\n"); + LOGP(DRADIO, LOGL_ERROR, "You have selected a signal processing sample rate of %.0f. Your audio sample rate is %.0f.\n", radio->signal_samplerate, radio->tx_audio_samplerate); + LOGP(DRADIO, LOGL_ERROR, "Please select a sample rate that is higher or equal the audio sample rate!\n"); goto error; } if (radio->rx_audio_samplerate > radio->signal_samplerate) { rc = -EINVAL; - PDEBUG(DRADIO, DEBUG_ERROR, "You have selected a signal processing sample rate of %.0f. Your audio sample rate is %.0f.\n", radio->signal_samplerate, radio->rx_audio_samplerate); - PDEBUG(DRADIO, DEBUG_ERROR, "Please select a sample rate that is higher or equal the audio sample rate!\n"); + LOGP(DRADIO, LOGL_ERROR, "You have selected a signal processing sample rate of %.0f. Your audio sample rate is %.0f.\n", radio->signal_samplerate, radio->rx_audio_samplerate); + LOGP(DRADIO, LOGL_ERROR, "Please select a sample rate that is higher or equal the audio sample rate!\n"); goto error; } if (radio->signal_samplerate < radio->signal_bandwidth * 2 / 0.75) { rc = -EINVAL; - PDEBUG(DRADIO, DEBUG_ERROR, "You have selected a signal processing sample rate of %.0f. Your signal's bandwidth %.0f.\n", radio->signal_samplerate, radio->signal_bandwidth); - PDEBUG(DRADIO, DEBUG_ERROR, "Your signal processing sample rate must be at least one third greater than the signal's double bandwidth. Use at least %.0f.\n", radio->signal_bandwidth * 2.0 / 0.75); + LOGP(DRADIO, LOGL_ERROR, "You have selected a signal processing sample rate of %.0f. Your signal's bandwidth %.0f.\n", radio->signal_samplerate, radio->signal_bandwidth); + LOGP(DRADIO, LOGL_ERROR, "Your signal processing sample rate must be at least one third greater than the signal's double bandwidth. Use at least %.0f.\n", radio->signal_bandwidth * 2.0 / 0.75); goto error; } @@ -244,7 +244,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency if (time_constant_us > 0.0) { radio->emphasis = 1; /* time constant */ - PDEBUG(DRADIO, DEBUG_INFO, "Using emphasis cut-off at %.0f Hz.\n", timeconstant2cutoff(time_constant_us)); + LOGP(DRADIO, LOGL_INFO, "Using emphasis cut-off at %.0f Hz.\n", timeconstant2cutoff(time_constant_us)); rc = init_emphasis(&radio->fm_emphasis[0], radio->signal_samplerate, timeconstant2cutoff(time_constant_us), DC_CUTOFF, radio->audio_bandwidth); if (rc < 0) goto error; @@ -296,21 +296,21 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency } if (radio->tx_audio_mode) - PDEBUG(DRADIO, DEBUG_INFO, "Bandwidth of audio source is %.0f Hz.\n", radio->tx_audio_samplerate / 2.0); + LOGP(DRADIO, LOGL_INFO, "Bandwidth of audio source is %.0f Hz.\n", radio->tx_audio_samplerate / 2.0); if (radio->rx_audio_mode) - PDEBUG(DRADIO, DEBUG_INFO, "Bandwidth of audio sink is %.0f Hz.\n", radio->rx_audio_samplerate / 2.0); - PDEBUG(DRADIO, DEBUG_INFO, "Bandwidth of audio signal is %.0f Hz.\n", radio->audio_bandwidth); - PDEBUG(DRADIO, DEBUG_INFO, "Bandwidth of modulated signal is %.0f Hz.\n", radio->signal_bandwidth); + LOGP(DRADIO, LOGL_INFO, "Bandwidth of audio sink is %.0f Hz.\n", radio->rx_audio_samplerate / 2.0); + LOGP(DRADIO, LOGL_INFO, "Bandwidth of audio signal is %.0f Hz.\n", radio->audio_bandwidth); + LOGP(DRADIO, LOGL_INFO, "Bandwidth of modulated signal is %.0f Hz.\n", radio->signal_bandwidth); if (radio->tx_audio_mode) - PDEBUG(DRADIO, DEBUG_INFO, "Sample rate of audio source is %.0f Hz.\n", radio->tx_audio_samplerate); + LOGP(DRADIO, LOGL_INFO, "Sample rate of audio source is %.0f Hz.\n", radio->tx_audio_samplerate); if (radio->rx_audio_mode) - PDEBUG(DRADIO, DEBUG_INFO, "Sample rate of audio sink is %.0f Hz.\n", radio->rx_audio_samplerate); - PDEBUG(DRADIO, DEBUG_INFO, "Sample rate of signal is %.0f Hz.\n", radio->signal_samplerate); + LOGP(DRADIO, LOGL_INFO, "Sample rate of audio sink is %.0f Hz.\n", radio->rx_audio_samplerate); + LOGP(DRADIO, LOGL_INFO, "Sample rate of signal is %.0f Hz.\n", radio->signal_samplerate); /* one or two audio channels */ if (radio->tx_audio_channels != 1 && radio->tx_audio_channels != 2) { - PDEBUG(DRADIO, DEBUG_ERROR, "Wrong number of audio channels, please fix!\n"); + LOGP(DRADIO, LOGL_ERROR, "Wrong number of audio channels, please fix!\n"); goto error; } @@ -323,7 +323,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->audio_buffer_size = rx_size; radio->audio_buffer = calloc(radio->audio_buffer_size * 2, sizeof(*radio->audio_buffer)); if (!radio->audio_buffer) { - PDEBUG(DRADIO, DEBUG_ERROR, "No memory!!\n"); + LOGP(DRADIO, LOGL_ERROR, "No memory!!\n"); rc = -ENOMEM; goto error; } @@ -333,7 +333,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->signal_buffer = calloc(radio->signal_buffer_size * 3, sizeof(*radio->signal_buffer)); radio->signal_power_buffer = calloc(radio->signal_buffer_size, sizeof(*radio->signal_power_buffer)); if (!radio->signal_buffer || !radio->signal_power_buffer) { - PDEBUG(DRADIO, DEBUG_ERROR, "No memory!!\n"); + LOGP(DRADIO, LOGL_ERROR, "No memory!!\n"); rc = -ENOMEM; goto error; } @@ -343,7 +343,7 @@ int radio_init(radio_t *radio, int buffer_size, int samplerate, double frequency radio->Q_buffer = calloc(buffer_size, sizeof(*radio->Q_buffer)); radio->carrier_buffer = calloc(buffer_size, sizeof(*radio->carrier_buffer)); if (!radio->I_buffer || !radio->Q_buffer || !radio->carrier_buffer) { - PDEBUG(DRADIO, DEBUG_ERROR, "No memory!!\n"); + LOGP(DRADIO, LOGL_ERROR, "No memory!!\n"); rc = -ENOMEM; goto error; } @@ -444,14 +444,14 @@ int radio_tx(radio_t *radio, float *baseband, int signal_num) uint8_t *signal_power; if (signal_num > radio->buffer_size) { - PDEBUG(DRADIO, DEBUG_ERROR, "signal_num > buffer_size, please fix!.\n"); + LOGP(DRADIO, LOGL_ERROR, "signal_num > buffer_size, please fix!.\n"); abort(); } /* audio buffers: how many sample for audio (rounded down) */ audio_num = (int)((double)signal_num / radio->tx_resampler[0].factor); if (audio_num > radio->audio_buffer_size) { - PDEBUG(DRADIO, DEBUG_ERROR, "audio_num > audio_buffer_size, please fix!.\n"); + LOGP(DRADIO, LOGL_ERROR, "audio_num > audio_buffer_size, please fix!.\n"); abort(); } audio_samples[0] = radio->audio_buffer; @@ -460,7 +460,7 @@ int radio_tx(radio_t *radio, float *baseband, int signal_num) /* signal buffers: a bit more samples to be safe */ signal_num = (int)((double)audio_num * radio->tx_resampler[0].factor + 0.5) + 10; if (signal_num > radio->signal_buffer_size) { - PDEBUG(DRADIO, DEBUG_ERROR, "signal_num > signal_buffer_size, please fix!.\n"); + LOGP(DRADIO, LOGL_ERROR, "signal_num > signal_buffer_size, please fix!.\n"); abort(); } signal_samples[0] = radio->signal_buffer; @@ -479,7 +479,7 @@ int radio_tx(radio_t *radio, float *baseband, int signal_num) wave_destroy_playback(&radio->wave_tx_play); rc = wave_create_playback(&radio->wave_tx_play, radio->tx_wave_file, &_samplerate, &radio->tx_audio_channels, 1.0); if (rc < 0) { - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to re-open wave file.\n"); + LOGP(DRADIO, LOGL_ERROR, "Failed to re-open wave file.\n"); return rc; } } @@ -488,9 +488,9 @@ int radio_tx(radio_t *radio, float *baseband, int signal_num) case AUDIO_MODE_AUDIODEV: rc = sound_read(radio->tx_sound, audio_samples, radio->audio_buffer_size, radio->tx_audio_channels, NULL); if (rc < 0) { - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to read from sound device (rc = %d)!\n", audio_num); + LOGP(DRADIO, LOGL_ERROR, "Failed to read from sound device (rc = %d)!\n", audio_num); if (rc == -EPIPE) - PDEBUG(DRADIO, DEBUG_ERROR, "Trying to recover.\n"); + LOGP(DRADIO, LOGL_ERROR, "Trying to recover.\n"); else return 0; } @@ -510,7 +510,7 @@ int radio_tx(radio_t *radio, float *baseband, int signal_num) } break; default: - PDEBUG(DRADIO, DEBUG_ERROR, "Wrong audio mode, please fix!\n"); + LOGP(DRADIO, LOGL_ERROR, "Wrong audio mode, please fix!\n"); return -EINVAL; } @@ -618,12 +618,12 @@ int radio_rx(radio_t *radio, float *baseband, int signal_num) double p; if (signal_num > radio->buffer_size) { - PDEBUG(DRADIO, DEBUG_ERROR, "signal_num > buffer_size, please fix!.\n"); + LOGP(DRADIO, LOGL_ERROR, "signal_num > buffer_size, please fix!.\n"); abort(); } if (signal_num > radio->signal_buffer_size) { - PDEBUG(DRADIO, DEBUG_ERROR, "signal_num > signal_buffer_size, please fix!.\n"); + LOGP(DRADIO, LOGL_ERROR, "signal_num > signal_buffer_size, please fix!.\n"); abort(); } samples[0] = radio->signal_buffer; @@ -737,9 +737,9 @@ int radio_rx(radio_t *radio, float *baseband, int signal_num) jitter_load(&radio->rx_dejitter[1], samples[1], audio_num); audio_num = sound_write(radio->rx_sound, samples, NULL, audio_num, NULL, NULL, radio->rx_audio_channels); if (audio_num < 0) { - PDEBUG(DRADIO, DEBUG_ERROR, "Failed to write to sound device (rc = %d)!\n", audio_num); + LOGP(DRADIO, LOGL_ERROR, "Failed to write to sound device (rc = %d)!\n", audio_num); if (audio_num == -EPIPE) - PDEBUG(DRADIO, DEBUG_ERROR, "Trying to recover.\n"); + LOGP(DRADIO, LOGL_ERROR, "Trying to recover.\n"); else return 0; } diff --git a/src/sim/Makefile.am b/src/sim/Makefile.am index 975de70..cffc9d7 100644 --- a/src/sim/Makefile.am +++ b/src/sim/Makefile.am @@ -11,9 +11,10 @@ cnetz_sim_SOURCES = \ cnetz_sim_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/liboptions/liboptions.a \ $(top_builddir)/src/libserial/libserial.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ -lm diff --git a/src/sim/main.c b/src/sim/main.c index fc7a7ef..aa6137f 100644 --- a/src/sim/main.c +++ b/src/sim/main.c @@ -30,7 +30,7 @@ #include <unistd.h> #include <inttypes.h> #include <sys/time.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "../libserial/serial.h" #include "../libaaimage/aaimage.h" @@ -72,7 +72,7 @@ void print_help(const char *arg0) printf(" --config [~/]<path to config file>\n"); printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n"); printf(" Each line in config file is one option, '-' or '--' must not be given!\n"); - debug_print_help(); + logging_print_help(); printf(" -s --serial-device <device>\n"); printf(" Serial device (default = '%s')\n", serialdev); printf(" -b --baud-rate <baud>\n"); @@ -140,13 +140,11 @@ int handle_options(int short_option, int argi, char **argv) print_help(argv[0]); return 0; case 'v': - if (!strcasecmp(argv[argi], "list")) { - debug_list_cat(); + rc = parse_logging_opt(argv[argi]); + if (rc > 0) return 0; - } - rc = parse_debug_opt(argv[argi]); if (rc < 0) { - fprintf(stderr, "Failed to parse debug option, please use -h for help.\n"); + fprintf(stderr, "Failed to parse logging option, please use -h for help.\n"); return rc; } break; @@ -337,7 +335,8 @@ int main(int argc, char *argv[]) int sniffer = 0; int i; - debuglevel = DEBUG_INFO; + loglevel = LOGL_INFO; + logging_init(); add_options(); rc = options_config_file(argc, argv, "~/.osmocom/analog/sim.conf", handle_options); @@ -366,13 +365,13 @@ int main(int argc, char *argv[]) rc = fread(eeprom_memory(), eeprom_length(), 1, fp); fclose(fp); } else - PDEBUG(DOPTIONS, DEBUG_INFO, "EEPROM file '%s' does not exist yet.\n", eeprom_file); + LOGP(DOPTIONS, LOGL_INFO, "EEPROM file '%s' does not exist yet.\n", eeprom_file); } /* check version */ if (eeprom_read(EEPROM_MAGIC + 0) != 'C' || eeprom_read(EEPROM_MAGIC + 1) != '0' + EEPROM_VERSION) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "EEPROM file '%s' is not compatible with this version of program, please remove it!\n", eeprom_file); + LOGP(DOPTIONS, LOGL_ERROR, "EEPROM file '%s' is not compatible with this version of program, please remove it!\n", eeprom_file); return 1; } @@ -400,7 +399,7 @@ int main(int argc, char *argv[]) eeprom_write(EEPROM_WARTUNG_L, ebdt_data[8]); if (pin) { if (strlen(pin) < 4 || strlen(pin) > 8) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given PIN '%s' has invalid length. (Must be 4 .. 8)\n", pin); + LOGP(DSIM7, LOGL_NOTICE, "Given PIN '%s' has invalid length. (Must be 4 .. 8)\n", pin); return 0; } eeprom_write(EEPROM_FLAGS, (strlen(pin) << EEPROM_FLAG_PIN_LEN) | (MAX_PIN_TRY << EEPROM_FLAG_PIN_TRY)); @@ -488,9 +487,9 @@ int main(int argc, char *argv[]) if (fp) { fwrite(eeprom_memory(), eeprom_length(), 1, fp); fclose(fp); - PDEBUG(DOPTIONS, DEBUG_INFO, "EEPROM file '%s' written.\n", eeprom_file); + LOGP(DOPTIONS, LOGL_INFO, "EEPROM file '%s' written.\n", eeprom_file); } else - PDEBUG(DOPTIONS, DEBUG_INFO, "EEPROM file '%s' cannot be written. (errno = %d)\n", eeprom_file, errno); + LOGP(DOPTIONS, LOGL_INFO, "EEPROM file '%s' cannot be written. (errno = %d)\n", eeprom_file, errno); } error: @@ -502,4 +501,6 @@ error: return 0; } +void osmo_cc_set_log_cat(void) {} + #endif /* ARDUINO */ diff --git a/src/sim/sim.c b/src/sim/sim.c index 56549ee..086519e 100644 --- a/src/sim/sim.c +++ b/src/sim/sim.c @@ -23,13 +23,13 @@ #include <stdint.h> #include <errno.h> #ifndef ARDUINO -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #endif #include "sim.h" #include "eeprom.h" #ifdef ARDUINO -#define PDEBUG(cat, level, fmt, arg...) while(0) +#define LOGP(cat, level, fmt, arg...) while(0) #define EINVAL 22 static uint32_t my_strtoul(const char *nptr, char **endptr, int base) { @@ -112,11 +112,11 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c if (futln) { temp = strlen(futln); if (temp < 7 || temp > 8) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given FUTLN '%s' invalid length. (Must be 7 or 8 Digits)\n", futln); + LOGP(DSIM7, LOGL_NOTICE, "Given FUTLN '%s' invalid length. (Must be 7 or 8 Digits)\n", futln); return -EINVAL; } if (futln[0] < '0' || futln[0] > '7') { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given FUTLN '%s' has invalid first digit. (Must be '0' .. '7')\n", futln); + LOGP(DSIM7, LOGL_NOTICE, "Given FUTLN '%s' has invalid first digit. (Must be '0' .. '7')\n", futln); return -EINVAL; } data[0] = (futln[0] - '0') << 5; @@ -125,7 +125,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c /* 8 digits */ temp = (futln[0] - '0') * 10 + (futln[1] - '0'); if (futln[0] < '0' || futln[0] > '9' || futln[1] < '0' || futln[1] > '9' || temp > 31) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given FUTLN '%s' has invalid second and third digit. (Must be '00' .. '31')\n", futln); + LOGP(DSIM7, LOGL_NOTICE, "Given FUTLN '%s' has invalid second and third digit. (Must be '00' .. '31')\n", futln); return -EINVAL; } data[0] |= temp; @@ -133,7 +133,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c } else { /* 7 digits */ if (futln[0] < '0' || futln[0] > '9') { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given FUTLN '%s' has invalid second digit. (Must be '0' .. '9')\n", futln); + LOGP(DSIM7, LOGL_NOTICE, "Given FUTLN '%s' has invalid second digit. (Must be '0' .. '9')\n", futln); return -EINVAL; } data[0] |= (futln[0] - '0'); @@ -145,7 +145,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c } temp = my_strtoul(futln, NULL, 0); if (i < 5 || temp > 65535) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given FUTLN '%s' has invalid last digits. (Must be '00000' .. '65535')\n", futln); + LOGP(DSIM7, LOGL_NOTICE, "Given FUTLN '%s' has invalid last digits. (Must be '00000' .. '65535')\n", futln); return -EINVAL; } data[1] = temp >> 8; @@ -155,7 +155,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c if (sicherung) { temp = my_strtoul(sicherung, NULL, 0); if (temp > 65535) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given security code '%s' has invalid digits. (Must be '0' .. '65535')\n", sicherung); + LOGP(DSIM7, LOGL_NOTICE, "Given security code '%s' has invalid digits. (Must be '0' .. '65535')\n", sicherung); return -EINVAL; } data[3] = temp >> 8; @@ -165,7 +165,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c if (karten) { temp = my_strtoul(karten, NULL, 0); if (temp > 7) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given card number '%s' has invalid digit. (Must be '0' .. '7')\n", karten); + LOGP(DSIM7, LOGL_NOTICE, "Given card number '%s' has invalid digit. (Must be '0' .. '7')\n", karten); return -EINVAL; } data[5] = (data[5] & 0x1f) | ((karten[0] - '0') << 5); @@ -174,7 +174,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c if (sonder) { temp = my_strtoul(sonder, NULL, 0); if (temp > 8191) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given spacial code '%s' has invalid digits. (Must be '0' .. '8191')\n", sonder); + LOGP(DSIM7, LOGL_NOTICE, "Given spacial code '%s' has invalid digits. (Must be '0' .. '8191')\n", sonder); return -EINVAL; } data[5] = (data[5] & 0xe0) | (temp >> 8); @@ -184,7 +184,7 @@ int encode_ebdt(uint8_t *data, const char *futln, const char *sicherung, const c if (wartung) { temp = my_strtoul(wartung, NULL, 0); if (temp > 65535) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given maintenance code '%s' has invalid digits. (Must be '0' .. '65535')\n", wartung); + LOGP(DSIM7, LOGL_NOTICE, "Given maintenance code '%s' has invalid digits. (Must be '0' .. '65535')\n", wartung); return -EINVAL; } data[7] = temp >> 8; @@ -240,7 +240,7 @@ int save_directory(int location, uint8_t *data) size = directory_size(); if (location < 1 || location >= size) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given location for phone number '%d' is out of range. (Must be '01' .. '%02d')\n", location, size - 1); + LOGP(DSIM7, LOGL_NOTICE, "Given location for phone number '%d' is out of range. (Must be '01' .. '%02d')\n", location, size - 1); return -EINVAL; } @@ -278,7 +278,7 @@ int encode_directory(uint8_t *data, const char *number, const char *name) len = strlen(number); if (len > 16) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given phone number '%s' has too many digits. (Must be <= 16)\n", number); + LOGP(DSIM7, LOGL_NOTICE, "Given phone number '%s' has too many digits. (Must be <= 16)\n", number); return -EINVAL; } @@ -286,7 +286,7 @@ int encode_directory(uint8_t *data, const char *number, const char *name) memset(data + 8, ' ', 16); for (i = 0; i < len; i++) { if (number[i] < '0' || number[i] > '9') { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given phone number '%s' has illegal digits. (Must be '0' .. '9')\n", number); + LOGP(DSIM7, LOGL_NOTICE, "Given phone number '%s' has illegal digits. (Must be '0' .. '9')\n", number); return -EINVAL; } pos = 16 - len + i; @@ -370,7 +370,7 @@ static int validate_pin(sim_sim_t *sim, uint8_t *data, int length) valid = 1; if (data[3] > '0') sim->card = data[3] - '1'; - PDEBUG(DSIM1, DEBUG_INFO, "System PIN '000%c' entered. Selecting card #%d.\n", data[3], sim->card + 1); + LOGP(DSIM1, LOGL_INFO, "System PIN '000%c' entered. Selecting card #%d.\n", data[3], sim->card + 1); } /* programming mode */ @@ -379,7 +379,7 @@ static int validate_pin(sim_sim_t *sim, uint8_t *data, int length) valid = 1; if (data[3] > '0') sim->card = data[3] - '1'; - PDEBUG(DSIM1, DEBUG_INFO, "Configuration PIN '999%c' entered. Selecting card #%d in configuration mode.\n", data[3], sim->card + 1); + LOGP(DSIM1, LOGL_INFO, "Configuration PIN '999%c' entered. Selecting card #%d in configuration mode.\n", data[3], sim->card + 1); } /* if not 'program mode' and PIN matches EEPROM */ @@ -390,7 +390,7 @@ static int validate_pin(sim_sim_t *sim, uint8_t *data, int length) } if (i == length) { valid = 1; - PDEBUG(DSIM1, DEBUG_INFO, "Correct PIN was entered. Selecting card #%d.\n", sim->card + 1); + LOGP(DSIM1, LOGL_INFO, "Correct PIN was entered. Selecting card #%d.\n", sim->card + 1); } } @@ -405,7 +405,7 @@ static int validate_pin(sim_sim_t *sim, uint8_t *data, int length) sim->program_mode = 1; return 0; } else { - PDEBUG(DSIM1, DEBUG_INFO, "Wrong PIN was entered.\n"); + LOGP(DSIM1, LOGL_INFO, "Wrong PIN was entered.\n"); #ifndef ARDUINO /* decrement error counter */ if (sim->pin_try) { @@ -424,7 +424,7 @@ uint8_t *alloc_msg(sim_sim_t *sim, int size) { /* we add 4, because we push 4 bytes (ICL and L2 header later) */ if (size + 4 > (int)sizeof(sim->block_tx_data)) - PDEBUG(DSIM1, DEBUG_NOTICE, "TX buffer overflow: size+4=%d > buffer size (%d)\n", size + 4, (int)sizeof(sim->block_tx_data)); + LOGP(DSIM1, LOGL_NOTICE, "TX buffer overflow: size+4=%d > buffer size (%d)\n", size + 4, (int)sizeof(sim->block_tx_data)); return sim->block_tx_data; } @@ -463,7 +463,7 @@ static void sl_appl(sim_sim_t *sim, uint8_t *data, int length) uint8_t app; if (length < 11) { - PDEBUG(DSIM7, DEBUG_NOTICE, "SL-APPL too short\n"); + LOGP(DSIM7, LOGL_NOTICE, "SL-APPL too short\n"); return_error(sim); return; } @@ -473,11 +473,11 @@ static void sl_appl(sim_sim_t *sim, uint8_t *data, int length) app += (data[7] - '0') * 10; app += data[8] - '0'; - PDEBUG(DSIM7, DEBUG_INFO, " SL-APPL app %d\n", app); + LOGP(DSIM7, LOGL_INFO, " SL-APPL app %d\n", app); /* check and set application */ if (app != APP_NETZ_C && app != APP_RUFN_GEBZ) { - PDEBUG(DSIM7, DEBUG_NOTICE, "SL-APPL invalid app %d\n", sim->app); + LOGP(DSIM7, LOGL_NOTICE, "SL-APPL invalid app %d\n", sim->app); return_error(sim); return; } @@ -499,7 +499,7 @@ static void cl_appl(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " CL-APPL\n"); + LOGP(DSIM7, LOGL_INFO, " CL-APPL\n"); /* remove app */ sim->app = 0; @@ -514,7 +514,7 @@ static void sh_appl(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " SH-APPL\n"); + LOGP(DSIM7, LOGL_INFO, " SH-APPL\n"); /* respond */ data = alloc_msg(sim, 33); @@ -546,7 +546,7 @@ static void chk_kon(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " CHK-KON\n"); + LOGP(DSIM7, LOGL_INFO, " CHK-KON\n"); /* respond */ data = alloc_msg(sim, 0); @@ -558,7 +558,7 @@ static void rd_ebdt(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " RD-EBDT\n"); + LOGP(DSIM7, LOGL_INFO, " RD-EBDT\n"); /* respond */ data = alloc_msg(sim, 9); @@ -594,12 +594,12 @@ static void rd_rufn(sim_sim_t *sim, uint8_t *data, int length) int size; if (length < 1) { - PDEBUG(DSIM7, DEBUG_NOTICE, "RD_RUFN too short\n"); + LOGP(DSIM7, LOGL_NOTICE, "RD_RUFN too short\n"); return_error(sim); return; } - PDEBUG(DSIM7, DEBUG_INFO, " RD-RUFN (loc=%d)\n", rufn); + LOGP(DSIM7, LOGL_INFO, " RD-RUFN (loc=%d)\n", rufn); /* SERVICE MODE */ if (sim->program_mode) { @@ -619,34 +619,34 @@ static void rd_rufn(sim_sim_t *sim, uint8_t *data, int length) data[2] = eeprom_read(EEPROM_FUTLN_L + sim->card); decode_ebdt(data, number, NULL, NULL, NULL, NULL); encode_directory(data, number, "FUTLN"); - PDEBUG(DSIM7, DEBUG_INFO, "service mode: FUTLN = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: FUTLN = %s\n", number); break; case 2: /* security code */ data[3] = eeprom_read(EEPROM_SICH_H + sim->card); data[4] = eeprom_read(EEPROM_SICH_L + sim->card); decode_ebdt(data, NULL, number, NULL, NULL, NULL); encode_directory(data, number, "Sicherungscode"); - PDEBUG(DSIM7, DEBUG_INFO, "service mode: security = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: security = %s\n", number); break; case 3: /* card ID */ data[5] = eeprom_read(EEPROM_SONDER_H + sim->card); decode_ebdt(data, NULL, NULL, number, NULL, NULL); encode_directory(data, number, "Kartenkennung"); - PDEBUG(DSIM7, DEBUG_INFO, "service mode: card = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: card = %s\n", number); break; case 4: /* special key */ data[5] = eeprom_read(EEPROM_SONDER_H + sim->card); data[6] = eeprom_read(EEPROM_SONDER_L + sim->card); decode_ebdt(data, NULL, NULL, NULL, number, NULL); encode_directory(data, number, "Sonderheitsschl."); - PDEBUG(DSIM7, DEBUG_INFO, "service mode: special = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: special = %s\n", number); break; case 5: /* maintenance key */ data[7] = eeprom_read(EEPROM_WARTUNG_H + sim->card); data[8] = eeprom_read(EEPROM_WARTUNG_L + sim->card); decode_ebdt(data, NULL, NULL, NULL, NULL, number); encode_directory(data, number, "Wartungsschl."); - PDEBUG(DSIM7, DEBUG_INFO, "service mode: maintenance = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: maintenance = %s\n", number); break; } tx_sdu(sim, 0, data, 24); @@ -655,9 +655,9 @@ static void rd_rufn(sim_sim_t *sim, uint8_t *data, int length) size = directory_size(); /* first entry (0) is used as allocation map */ - PDEBUG(DSIM7, DEBUG_INFO, " %d numbers can be stored in EEPROM\n", size - 1); + LOGP(DSIM7, LOGL_INFO, " %d numbers can be stored in EEPROM\n", size - 1); if (rufn >= size) { - PDEBUG(DSIM7, DEBUG_NOTICE, "RD_RUFN entry #%d out of range\n", rufn); + LOGP(DSIM7, LOGL_NOTICE, "RD_RUFN entry #%d out of range\n", rufn); return_error(sim); return; } @@ -674,12 +674,12 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) uint8_t rufn = data[0]; if (length < 25) { - PDEBUG(DSIM7, DEBUG_NOTICE, "WT_RUFN too short\n"); + LOGP(DSIM7, LOGL_NOTICE, "WT_RUFN too short\n"); return_error(sim); return; } - PDEBUG(DSIM7, DEBUG_INFO, " WT-RUFN (loc=%d)\n", rufn); + LOGP(DSIM7, LOGL_INFO, " WT-RUFN (loc=%d)\n", rufn); /* SERVICE MODE */ if (sim->program_mode) { @@ -692,7 +692,7 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) goto respond; switch (rufn) { case 1: /* FUTLN */ - PDEBUG(DSIM7, DEBUG_INFO, "service mode: FUTLN = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: FUTLN = %s\n", number); rc = encode_ebdt(data, number, NULL, NULL, NULL, NULL); if (rc < 0) break; @@ -701,7 +701,7 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) eeprom_write(EEPROM_FUTLN_L + sim->card, data[2]); break; case 2: /* security code */ - PDEBUG(DSIM7, DEBUG_INFO, "service mode: security = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: security = %s\n", number); rc = encode_ebdt(data, NULL, number, NULL, NULL, NULL); if (rc < 0) break; @@ -709,7 +709,7 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) eeprom_write(EEPROM_SICH_L + sim->card, data[4]); break; case 3: /* card ID */ - PDEBUG(DSIM7, DEBUG_INFO, "service mode: card = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: card = %s\n", number); data[5] = eeprom_read(EEPROM_SONDER_H + sim->card); rc = encode_ebdt(data, NULL, NULL, number, NULL, NULL); if (rc < 0) @@ -717,7 +717,7 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) eeprom_write(EEPROM_SONDER_H + sim->card, data[5]); break; case 4: /* special key */ - PDEBUG(DSIM7, DEBUG_INFO, "service mode: special = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: special = %s\n", number); data[5] = eeprom_read(EEPROM_SONDER_H + sim->card); rc = encode_ebdt(data, NULL, NULL, NULL, number, NULL); if (rc < 0) @@ -726,7 +726,7 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) eeprom_write(EEPROM_SONDER_L + sim->card, data[6]); break; case 5: /* maintenance key */ - PDEBUG(DSIM7, DEBUG_INFO, "service mode: maintenance = %s\n", number); + LOGP(DSIM7, LOGL_INFO, "service mode: maintenance = %s\n", number); rc = encode_ebdt(data, NULL, NULL, NULL, NULL, number); if (rc < 0) break; @@ -739,7 +739,7 @@ static void wt_rufn(sim_sim_t *sim, uint8_t *data, int length) } if (rufn >= directory_size() || rufn < 1) { - PDEBUG(DSIM7, DEBUG_NOTICE, "WT_RUFN entry #%d out of range\n", rufn); + LOGP(DSIM7, LOGL_NOTICE, "WT_RUFN entry #%d out of range\n", rufn); return_error(sim); return; } @@ -757,10 +757,10 @@ static void chk_pin(sim_sim_t *sim, uint8_t *data, int length) { int rc; - PDEBUG(DSIM7, DEBUG_INFO, " CHK-PIN\n"); + LOGP(DSIM7, LOGL_INFO, " CHK-PIN\n"); if (length < 4 || length > 8) { - PDEBUG(DSIM7, DEBUG_NOTICE, "SET-PIN wrong length: %d\n", length); + LOGP(DSIM7, LOGL_NOTICE, "SET-PIN wrong length: %d\n", length); return_error(sim); return; } @@ -785,10 +785,10 @@ static void set_pin(sim_sim_t *sim, uint8_t *data, int length) int i; int rc; - PDEBUG(DSIM7, DEBUG_INFO, " SET-PIN\n"); + LOGP(DSIM7, LOGL_INFO, " SET-PIN\n"); if (length < 1) { - PDEBUG(DSIM7, DEBUG_NOTICE, "SET-PIN too short\n"); + LOGP(DSIM7, LOGL_NOTICE, "SET-PIN too short\n"); return_error(sim); return; } @@ -798,7 +798,7 @@ static void set_pin(sim_sim_t *sim, uint8_t *data, int length) len_new = length - len_old - 1; pin_new = data + 1 + len_old; if (len_new < 4 || len_new > 8) { - PDEBUG(DSIM7, DEBUG_NOTICE, "New PIN wrong length %d!\n", len_new); + LOGP(DSIM7, LOGL_NOTICE, "New PIN wrong length %d!\n", len_new); return_error(sim); return; } @@ -826,10 +826,10 @@ static void eh_gebz(sim_sim_t *sim, uint8_t *data, int length) { uint32_t gebz; - PDEBUG(DSIM7, DEBUG_INFO, " EH-GEBZ\n"); + LOGP(DSIM7, LOGL_INFO, " EH-GEBZ\n"); if (length < 1) { - PDEBUG(DSIM7, DEBUG_NOTICE, "EH-GEBZ wrong length: %d\n", length); + LOGP(DSIM7, LOGL_NOTICE, "EH-GEBZ wrong length: %d\n", length); return_error(sim); return; } @@ -853,7 +853,7 @@ static void cl_gebz(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " CL-GEBZ\n"); + LOGP(DSIM7, LOGL_INFO, " CL-GEBZ\n"); /* clear counter */ eeprom_write(EEPROM_GEBZ_H, 0); @@ -870,7 +870,7 @@ static void rd_gebz(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " RD-GEBZ\n"); + LOGP(DSIM7, LOGL_INFO, " RD-GEBZ\n"); /* respond */ data = alloc_msg(sim, 3); @@ -885,7 +885,7 @@ static void sp_gzrv(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " SP-GZRV\n"); + LOGP(DSIM7, LOGL_INFO, " SP-GZRV\n"); sim->gebz_locked = 1; write_flags(sim); @@ -900,7 +900,7 @@ static void fr_gzrv(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " FR-GZRV\n"); + LOGP(DSIM7, LOGL_INFO, " FR-GZRV\n"); sim->gebz_locked = 0; write_flags(sim); @@ -916,7 +916,7 @@ static void aut_1(sim_sim_t *sim) uint8_t *data; int i; - PDEBUG(DSIM7, DEBUG_INFO, " AUTH-1\n"); + LOGP(DSIM7, LOGL_INFO, " AUTH-1\n"); /* respond */ data = alloc_msg(sim, 1); @@ -930,7 +930,7 @@ static void rd_f4(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " RD-F4\n"); + LOGP(DSIM7, LOGL_INFO, " RD-F4\n"); /* respond */ data = alloc_msg(sim, 2); @@ -944,7 +944,7 @@ static void rd_f5(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " RD-F5\n"); + LOGP(DSIM7, LOGL_INFO, " RD-F5\n"); /* respond */ data = alloc_msg(sim, 0); @@ -956,7 +956,7 @@ static void rd_04(sim_sim_t *sim) { uint8_t *data; - PDEBUG(DSIM7, DEBUG_INFO, " RD-04\n"); + LOGP(DSIM7, LOGL_INFO, " RD-04\n"); /* respond */ data = alloc_msg(sim, 25); @@ -971,13 +971,13 @@ static void rx_sdu(sim_sim_t *sim, uint8_t *data, int length) uint8_t cla, ins, dlng; if (length < 3) { - PDEBUG(DSIM7, DEBUG_NOTICE, "SDU too short\n"); + LOGP(DSIM7, LOGL_NOTICE, "SDU too short\n"); return; } /* skip all responses, because we don't send commands */ if (*data & CCRC_IDENT) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Skipping SDU with response\n"); + LOGP(DSIM7, LOGL_NOTICE, "Skipping SDU with response\n"); return; } @@ -989,7 +989,7 @@ static void rx_sdu(sim_sim_t *sim, uint8_t *data, int length) /* check length */ if (dlng != length) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Skipping SDU with invalid length\n"); + LOGP(DSIM7, LOGL_NOTICE, "Skipping SDU with invalid length\n"); return; } @@ -1044,7 +1044,7 @@ static void rx_sdu(sim_sim_t *sim, uint8_t *data, int length) } /* unsupported message */ - PDEBUG(DSIM7, DEBUG_NOTICE, "CLA 0x%02x INS 0x%02x unknown\n", cla, ins); + LOGP(DSIM7, LOGL_NOTICE, "CLA 0x%02x INS 0x%02x unknown\n", cla, ins); data = alloc_msg(sim, 0); tx_sdu(sim, CCRC_ERROR, data, 0); } @@ -1075,7 +1075,7 @@ static void rx_pdu(sim_sim_t *sim, uint8_t *data, int length) if (length < 1) { too_short: - PDEBUG(DSIMI, DEBUG_NOTICE, "PDU too short\n"); + LOGP(DSIMI, LOGL_NOTICE, "PDU too short\n"); return; } @@ -1125,24 +1125,24 @@ static void rx_block(sim_sim_t *sim) /* NOTE: This procedure is simplified, it does not comply with the specs. */ - PDEBUG(DSIM2, DEBUG_INFO, "RX message\n"); + LOGP(DSIM2, LOGL_INFO, "RX message\n"); sim->addr_src = sim->block_address >> 4; sim->addr_dst = sim->block_address & 0xf; if (sim->block_checksum != 0) { - PDEBUG(DSIM2, DEBUG_NOTICE, "Checksum error!\n"); + LOGP(DSIM2, LOGL_NOTICE, "Checksum error!\n"); goto reject; } if ((sim->block_control & 0x11) == 0x00) { ns = (sim->block_control >> 1) & 7; nr = sim->block_control >> 5; - PDEBUG(DSIM2, DEBUG_INFO, " control I: N(S)=%d N(R)=%d\n", ns, nr); + LOGP(DSIM2, LOGL_INFO, " control I: N(S)=%d N(R)=%d\n", ns, nr); if (ns == sim->vr && nr == sim->vs) { /* receive data */ sim->vr = (sim->vr + 1) & 0x7; rx_pdu(sim, sim->block_rx_data, sim->block_rx_length); return; } else { - PDEBUG(DSIM2, DEBUG_NOTICE, "Seqeuence error!\n"); + LOGP(DSIM2, LOGL_NOTICE, "Seqeuence error!\n"); reject: /* reject (or send resync after 3 times) */ data = alloc_msg(sim, 0); @@ -1158,7 +1158,7 @@ reject: } if ((sim->block_control & 0x1f) == 0x09) { nr = sim->block_control >> 5; - PDEBUG(DSIM2, DEBUG_INFO, " control REJ: N(R)=%d\n", nr); + LOGP(DSIM2, LOGL_INFO, " control REJ: N(R)=%d\n", nr); /* repeat last message */ if (sim->block_tx_length) { tx_block(sim, L2_I, sim->block_tx_data, sim->block_tx_length); @@ -1170,7 +1170,7 @@ reject: return; } if (sim->block_control == 0xef) { - PDEBUG(DSIM2, DEBUG_INFO, " control RES\n"); + LOGP(DSIM2, LOGL_INFO, " control RES\n"); sim->vr = sim->vs = 0; sim->reject_count = 0; if (sim->resync_sent == 0) { @@ -1201,7 +1201,7 @@ static int rx_char(sim_sim_t *sim, uint8_t c) case BLOCK_STATE_LENGTH: if (c > sizeof(sim->block_rx_data)) { c = sizeof(sim->block_rx_data); - PDEBUG(DSIM1, DEBUG_NOTICE, "RX buffer overflow: length=%d > buffer size (%d)\n", c, (int)sizeof(sim->block_rx_data)); + LOGP(DSIM1, LOGL_NOTICE, "RX buffer overflow: length=%d > buffer size (%d)\n", c, (int)sizeof(sim->block_rx_data)); } sim->block_rx_length = c; sim->block_count = 0; @@ -1225,24 +1225,24 @@ static int rx_char(sim_sim_t *sim, uint8_t c) /* create layer 2 message for layer 1 */ static void tx_block(sim_sim_t *sim, enum l2_cmd cmd, uint8_t __attribute__((unused)) *data, int length) { - PDEBUG(DSIM2, DEBUG_INFO, "TX response\n"); + LOGP(DSIM2, LOGL_INFO, "TX response\n"); /* header */ sim->block_address = (sim->addr_dst << 4) | sim->addr_src; switch (cmd) { case L2_I: - PDEBUG(DSIM2, DEBUG_INFO, " control I: N(S)=%d N(R)=%d\n", sim->vs, sim->vr); + LOGP(DSIM2, LOGL_INFO, " control I: N(S)=%d N(R)=%d\n", sim->vs, sim->vr); sim->block_control = (sim->vr << 5) | (sim->vs << 1); sim->vs = (sim->vs + 1) & 0x7; sim->resync_sent = 0; break; case L2_REJ: - PDEBUG(DSIM2, DEBUG_INFO, " control REJ: N(R)=%d\n", sim->vr); + LOGP(DSIM2, LOGL_INFO, " control REJ: N(R)=%d\n", sim->vr); sim->block_control = (sim->vr << 5) | 0x09; sim->resync_sent = 0; break; case L2_RES: - PDEBUG(DSIM2, DEBUG_INFO, " control RES\n"); + LOGP(DSIM2, LOGL_INFO, " control RES\n"); sim->block_control = 0xef; sim->resync_sent = 1; break; @@ -1367,7 +1367,7 @@ void sim_reset(sim_sim_t *sim, int reset) int i; char pin[8]; - PDEBUG(DSIM1, DEBUG_INFO, "Reset signal %s\n", (reset) ? "on (low)" : "off (high)"); + LOGP(DSIM1, LOGL_INFO, "Reset signal %s\n", (reset) ? "on (low)" : "off (high)"); memset(sim, 0, sizeof(*sim)); if (reset) @@ -1386,10 +1386,10 @@ void sim_reset(sim_sim_t *sim, int reset) sim->pin_required = 0; if (pin[3] > '0') sim->card = pin[3] - '1'; - PDEBUG(DSIM1, DEBUG_INFO, "Card has disabled PIN (system PIN '000%c') Selecting card #%d.\n", pin[3], sim->card + 1); + LOGP(DSIM1, LOGL_INFO, "Card has disabled PIN (system PIN '000%c') Selecting card #%d.\n", pin[3], sim->card + 1); } - PDEBUG(DSIM1, DEBUG_INFO, "Sending ATR\n"); + LOGP(DSIM1, LOGL_INFO, "Sending ATR\n"); sim->l1_state = L1_STATE_ATR; } @@ -1397,7 +1397,7 @@ int sim_rx(sim_sim_t *sim, uint8_t c) { int rc = -1; - PDEBUG(DSIM1, DEBUG_DEBUG, "Serial RX '0x%02x'\n", c); + LOGP(DSIM1, LOGL_DEBUG, "Serial RX '0x%02x'\n", c); switch (sim->l1_state) { case L1_STATE_IDLE: @@ -1408,7 +1408,7 @@ int sim_rx(sim_sim_t *sim, uint8_t c) rc = rx_char(sim, c); break; case L1_STATE_COMPLETE: - PDEBUG(DSIM1, DEBUG_NOTICE, "Received garbage after message!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Received garbage after message!\n"); sim->l1_state = L1_STATE_GARBAGE; default: break; @@ -1433,7 +1433,7 @@ int sim_tx(sim_sim_t *sim) } if (c >= 0) - PDEBUG(DSIM1, DEBUG_DEBUG, "Serial TX '0x%02x'\n", c); + LOGP(DSIM1, LOGL_DEBUG, "Serial TX '0x%02x'\n", c); return c; } @@ -1442,19 +1442,19 @@ void sim_timeout(sim_sim_t *sim) { switch (sim->l1_state) { case L1_STATE_ATR: - PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while transmitting ATR!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Timeout while transmitting ATR!\n"); sim->l1_state = L1_STATE_RESET; break; case L1_STATE_RECEIVE: - PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while receiving message!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Timeout while receiving message!\n"); sim->block_state = BLOCK_STATE_ADDRESS; break; case L1_STATE_GARBAGE: - PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout after skipping garbage!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Timeout after skipping garbage!\n"); sim->l1_state = L1_STATE_IDLE; break; case L1_STATE_SEND: - PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while sending message!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Timeout while sending message!\n"); sim->l1_state = L1_STATE_IDLE; break; case L1_STATE_COMPLETE: diff --git a/src/sim/sniffer.c b/src/sim/sniffer.c index 34a2e4c..89684aa 100644 --- a/src/sim/sniffer.c +++ b/src/sim/sniffer.c @@ -22,7 +22,7 @@ #include <stdio.h> #include <string.h> #include <stdint.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "sim.h" #include "sniffer.h" @@ -37,7 +37,7 @@ static void rx_icl_sdu(uint8_t *data, int length) int i; if (length < 3) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Message too short\n"); + LOGP(DSIM7, LOGL_NOTICE, "Message too short\n"); return; } @@ -47,146 +47,146 @@ static void rx_icl_sdu(uint8_t *data, int length) dlng = *data++; length -= 3; - PDEBUG(DSIM7, DEBUG_INFO, "Layer 7:\n"); + LOGP(DSIM7, LOGL_INFO, "Layer 7:\n"); if (I == 0) { - PDEBUG(DSIM7, DEBUG_INFO, " I = Command\n"); - PDEBUG(DSIM7, DEBUG_INFO, " CLA = 0x%02x\n", cla_ccrc); + LOGP(DSIM7, LOGL_INFO, " I = Command\n"); + LOGP(DSIM7, LOGL_INFO, " CLA = 0x%02x\n", cla_ccrc); switch (cla_ccrc) { case CLA_CNTR: - PDEBUG(DSIM7, DEBUG_INFO, " -> CNTR (Control Class)\n"); + LOGP(DSIM7, LOGL_INFO, " -> CNTR (Control Class)\n"); break; case CLA_STAT: - PDEBUG(DSIM7, DEBUG_INFO, " -> STAT (Status Class)\n"); + LOGP(DSIM7, LOGL_INFO, " -> STAT (Status Class)\n"); break; case CLA_WRTE: - PDEBUG(DSIM7, DEBUG_INFO, " -> WRTE (Write Class)\n"); + LOGP(DSIM7, LOGL_INFO, " -> WRTE (Write Class)\n"); break; case CLA_READ: - PDEBUG(DSIM7, DEBUG_INFO, " -> READ (Read Class)\n"); + LOGP(DSIM7, LOGL_INFO, " -> READ (Read Class)\n"); break; case CLA_EXEC: - PDEBUG(DSIM7, DEBUG_INFO, " -> EXEC (Execute Class)\n"); + LOGP(DSIM7, LOGL_INFO, " -> EXEC (Execute Class)\n"); break; case CLA_AUTO: - PDEBUG(DSIM7, DEBUG_INFO, " -> AUTO (Authentication Class)\n"); + LOGP(DSIM7, LOGL_INFO, " -> AUTO (Authentication Class)\n"); break; default: - PDEBUG(DSIM7, DEBUG_INFO, " -> unknown class\n"); + LOGP(DSIM7, LOGL_INFO, " -> unknown class\n"); break; } - PDEBUG(DSIM7, DEBUG_INFO, " INS = 0x%02x\n", ins_aprc); + LOGP(DSIM7, LOGL_INFO, " INS = 0x%02x\n", ins_aprc); switch (cla_ccrc) { case CLA_CNTR: switch (ins_aprc) { case SL_APPL: - PDEBUG(DSIM7, DEBUG_INFO, " -> SL-APPL (Select Application)\n"); + LOGP(DSIM7, LOGL_INFO, " -> SL-APPL (Select Application)\n"); break; case CL_APPL: - PDEBUG(DSIM7, DEBUG_INFO, " -> CL-APPL (Close Application)\n"); + LOGP(DSIM7, LOGL_INFO, " -> CL-APPL (Close Application)\n"); break; case SH_APPL: - PDEBUG(DSIM7, DEBUG_INFO, " -> SH-APPL (Show Application)\n"); + LOGP(DSIM7, LOGL_INFO, " -> SH-APPL (Show Application)\n"); break; } break; case CLA_STAT: switch (ins_aprc) { case CHK_KON: - PDEBUG(DSIM7, DEBUG_INFO, " -> CHK-KCON (Consistency Check)\n"); + LOGP(DSIM7, LOGL_INFO, " -> CHK-KCON (Consistency Check)\n"); break; } break; case CLA_WRTE: switch (ins_aprc) { case WT_RUFN: - PDEBUG(DSIM7, DEBUG_INFO, " -> WR-RUFN (Write Rufnummernsatz)\n"); + LOGP(DSIM7, LOGL_INFO, " -> WR-RUFN (Write Rufnummernsatz)\n"); break; } break; case CLA_READ: switch (ins_aprc) { case RD_EBDT: - PDEBUG(DSIM7, DEBUG_INFO, " -> RD-EBDT (Read Einbuchdaten)\n"); + LOGP(DSIM7, LOGL_INFO, " -> RD-EBDT (Read Einbuchdaten)\n"); break; case RD_RUFN: - PDEBUG(DSIM7, DEBUG_INFO, " -> RD-RUFN (Read Rufnummernsatz)\n"); + LOGP(DSIM7, LOGL_INFO, " -> RD-RUFN (Read Rufnummernsatz)\n"); break; case RD_GEBZ: - PDEBUG(DSIM7, DEBUG_INFO, " -> RD-GEBZ (Read Gebuehrenzaehler)\n"); + LOGP(DSIM7, LOGL_INFO, " -> RD-GEBZ (Read Gebuehrenzaehler)\n"); break; } break; case CLA_EXEC: switch (ins_aprc) { case CHK_PIN: - PDEBUG(DSIM7, DEBUG_INFO, " -> CHK-PIN (Check PIN)\n"); + LOGP(DSIM7, LOGL_INFO, " -> CHK-PIN (Check PIN)\n"); break; case SET_PIN: - PDEBUG(DSIM7, DEBUG_INFO, " -> SET-PIN (Set PIN)\n"); + LOGP(DSIM7, LOGL_INFO, " -> SET-PIN (Set PIN)\n"); break; case EH_GEBZ: - PDEBUG(DSIM7, DEBUG_INFO, " -> EH-GEBZ (Increment Gebuehrenzaehler)\n"); + LOGP(DSIM7, LOGL_INFO, " -> EH-GEBZ (Increment Gebuehrenzaehler)\n"); break; case CL_GEBZ: - PDEBUG(DSIM7, DEBUG_INFO, " -> CL-GEBZ (Clear Gebuehrenzaehler)\n"); + LOGP(DSIM7, LOGL_INFO, " -> CL-GEBZ (Clear Gebuehrenzaehler)\n"); break; } break; case CLA_AUTO: switch (ins_aprc) { case AUT_1: - PDEBUG(DSIM7, DEBUG_INFO, " -> AUTO-1 (Authorization)\n"); + LOGP(DSIM7, LOGL_INFO, " -> AUTO-1 (Authorization)\n"); break; } break; } } else { - PDEBUG(DSIM7, DEBUG_INFO, " I = Response\n"); - PDEBUG(DSIM7, DEBUG_INFO, " CCRC = 0x%02x\n", cla_ccrc); + LOGP(DSIM7, LOGL_INFO, " I = Response\n"); + LOGP(DSIM7, LOGL_INFO, " CCRC = 0x%02x\n", cla_ccrc); if (cla_ccrc & CCRC_PIN_NOK) - PDEBUG(DSIM7, DEBUG_INFO, " -> PIN-NOT-OK\n"); + LOGP(DSIM7, LOGL_INFO, " -> PIN-NOT-OK\n"); if (cla_ccrc & CCRC_AFBZ_NULL) - PDEBUG(DSIM7, DEBUG_INFO, " -> AFBZ = NULL\n"); + LOGP(DSIM7, LOGL_INFO, " -> AFBZ = NULL\n"); if (cla_ccrc & CCRC_APRC_VALID) - PDEBUG(DSIM7, DEBUG_INFO, " -> APRC valid\n"); + LOGP(DSIM7, LOGL_INFO, " -> APRC valid\n"); if (cla_ccrc & 0x08) - PDEBUG(DSIM7, DEBUG_INFO, " -> reserved\n"); + LOGP(DSIM7, LOGL_INFO, " -> reserved\n"); if (cla_ccrc & 0x10) - PDEBUG(DSIM7, DEBUG_INFO, " -> reserved\n"); + LOGP(DSIM7, LOGL_INFO, " -> reserved\n"); if (cla_ccrc & 0x20) - PDEBUG(DSIM7, DEBUG_INFO, " -> reserved\n"); + LOGP(DSIM7, LOGL_INFO, " -> reserved\n"); if (cla_ccrc & CCRC_ERROR) - PDEBUG(DSIM7, DEBUG_INFO, " -> GENERAL ERROR\n"); - PDEBUG(DSIM7, DEBUG_INFO, " APRC = 0x%02x\n", ins_aprc); + LOGP(DSIM7, LOGL_INFO, " -> GENERAL ERROR\n"); + LOGP(DSIM7, LOGL_INFO, " APRC = 0x%02x\n", ins_aprc); if (ins_aprc & APRC_PIN_REQ) - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 2 = 1:PIN-Check required\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 2 = 1:PIN-Check required\n"); else - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 2 = 0:PIN-Check not required\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 2 = 0:PIN-Check not required\n"); if (ins_aprc & APRC_APP_LOCKED) - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 3 = 1:Application locked\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 3 = 1:Application locked\n"); else - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 3 = 0:Application unlocked\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 3 = 0:Application unlocked\n"); if (ins_aprc & APRC_GEBZ_LOCK) - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 5 = 1:GEBZ/RUFN locked\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 5 = 1:GEBZ/RUFN locked\n"); else - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 5 = 0:GEBZ/RUFN unlocked\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 5 = 0:GEBZ/RUFN unlocked\n"); if (ins_aprc & APRC_GEBZ_FULL) - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 6 = 1:GEBZ full\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 6 = 1:GEBZ full\n"); else - PDEBUG(DSIM7, DEBUG_INFO, " -> Bit 6 = 0:GEBZ not full\n"); + LOGP(DSIM7, LOGL_INFO, " -> Bit 6 = 0:GEBZ not full\n"); } if (dlng == 255) { - PDEBUG(DSIM7, DEBUG_NOTICE, " Unsupported length 255!\n"); + LOGP(DSIM7, LOGL_NOTICE, " Unsupported length 255!\n"); return; } - PDEBUG(DSIM7, DEBUG_INFO, " DLNG = %d\n", dlng); + LOGP(DSIM7, LOGL_INFO, " DLNG = %d\n", dlng); if (dlng != length) { - PDEBUG(DSIM7, DEBUG_NOTICE, " DLNG does not match message body!\n"); + LOGP(DSIM7, LOGL_NOTICE, " DLNG does not match message body!\n"); return; } for (i = 0; i < length; i++) { - PDEBUG(DSIM7, DEBUG_INFO, " DATA(%d) = 0x%02x '%c' %d\n", i, data[i], (data[i] >= 32 && data[i] <= 126) ? data[i] : '.', data[i]); + LOGP(DSIM7, LOGL_INFO, " DATA(%d) = 0x%02x '%c' %d\n", i, data[i], (data[i] >= 32 && data[i] <= 126) ? data[i] : '.', data[i]); } } @@ -198,43 +198,43 @@ static void rx_icl_pdu(uint8_t *data, int length) if (ext) { if (length < 1) { - PDEBUG(DSIMI, DEBUG_NOTICE, "Message too short\n"); + LOGP(DSIMI, LOGL_NOTICE, "Message too short\n"); return; } - PDEBUG(DSIMI, DEBUG_INFO, "Interface control layer ICB1:\n"); + LOGP(DSIMI, LOGL_INFO, "Interface control layer ICB1:\n"); if (*data & ICB1_ONLINE) - PDEBUG(DSIMI, DEBUG_INFO, " ON-LINE-BIT: 1 = On-line data\n"); + LOGP(DSIMI, LOGL_INFO, " ON-LINE-BIT: 1 = On-line data\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " ON-LINE-BIT: 0 = Off-line data\n"); + LOGP(DSIMI, LOGL_INFO, " ON-LINE-BIT: 0 = Off-line data\n"); if (*data & ICB1_CONFIRM) - PDEBUG(DSIMI, DEBUG_INFO, " CONFIRM-BIT: 1 = Confirmation\n"); + LOGP(DSIMI, LOGL_INFO, " CONFIRM-BIT: 1 = Confirmation\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " CONFIRM-BIT: 0 = No meaning\n"); + LOGP(DSIMI, LOGL_INFO, " CONFIRM-BIT: 0 = No meaning\n"); if (*data & ICB1_MASTER) - PDEBUG(DSIMI, DEBUG_INFO, " MASTER/SLAVE-BIT: 1 = Sender is master\n"); + LOGP(DSIMI, LOGL_INFO, " MASTER/SLAVE-BIT: 1 = Sender is master\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " MASTER/SLAVE-BIT: 0 = Sender is slave\n"); + LOGP(DSIMI, LOGL_INFO, " MASTER/SLAVE-BIT: 0 = Sender is slave\n"); if (*data & ICB1_WT_EXT) - PDEBUG(DSIMI, DEBUG_INFO, " WT-EXTENSION-BIT: 1 = Request for WT-Extension\n"); + LOGP(DSIMI, LOGL_INFO, " WT-EXTENSION-BIT: 1 = Request for WT-Extension\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " WT-EXTENSION-BIT: 0 = No request for WT-Extension\n"); + LOGP(DSIMI, LOGL_INFO, " WT-EXTENSION-BIT: 0 = No request for WT-Extension\n"); if (*data & ICB1_ABORT) - PDEBUG(DSIMI, DEBUG_INFO, " ABORT/TERMINATE-BIT: 1 = Abort/Terminate request\n"); + LOGP(DSIMI, LOGL_INFO, " ABORT/TERMINATE-BIT: 1 = Abort/Terminate request\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " ABORT/TERMINATE-BIT: 0 = No meaning\n"); + LOGP(DSIMI, LOGL_INFO, " ABORT/TERMINATE-BIT: 0 = No meaning\n"); if (*data & ICB1_ERROR) - PDEBUG(DSIMI, DEBUG_INFO, " ERROR-BIT: 1 = Error\n"); + LOGP(DSIMI, LOGL_INFO, " ERROR-BIT: 1 = Error\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " ERROR-BIT: 0 = No meaning\n"); + LOGP(DSIMI, LOGL_INFO, " ERROR-BIT: 0 = No meaning\n"); if (*data & ICB1_CHAINING) - PDEBUG(DSIMI, DEBUG_INFO, " CHAINING-BIT: 1 = More ICL data follows\n"); + LOGP(DSIMI, LOGL_INFO, " CHAINING-BIT: 1 = More ICL data follows\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " CHAINING-BIT: 0 = No more ICL data follows\n"); + LOGP(DSIMI, LOGL_INFO, " CHAINING-BIT: 0 = No more ICL data follows\n"); if (*data & ICB_EXT) - PDEBUG(DSIMI, DEBUG_INFO, " ICB-EXTENSION-BIT: 1 = ICB2 follows\n"); + LOGP(DSIMI, LOGL_INFO, " ICB-EXTENSION-BIT: 1 = ICB2 follows\n"); else { - PDEBUG(DSIMI, DEBUG_INFO, " ICB-EXTENSION-BIT: 0 = no ICB follows\n"); + LOGP(DSIMI, LOGL_INFO, " ICB-EXTENSION-BIT: 0 = no ICB follows\n"); ext = 0; } data++; @@ -243,27 +243,27 @@ static void rx_icl_pdu(uint8_t *data, int length) if (ext) { if (length < 1) { - PDEBUG(DSIMI, DEBUG_NOTICE, "Message too short\n"); + LOGP(DSIMI, LOGL_NOTICE, "Message too short\n"); return; } - PDEBUG(DSIMI, DEBUG_INFO, "Interface control layer ICB2:\n"); + LOGP(DSIMI, LOGL_INFO, "Interface control layer ICB2:\n"); if (*data & ICB2_DYNAMIC) - PDEBUG(DSIMI, DEBUG_INFO, " DYN-BUFFER-SIZE-BIT: 1 = Buffer size %d\n", (*data & ICB2_BUFFER) * 8); + LOGP(DSIMI, LOGL_INFO, " DYN-BUFFER-SIZE-BIT: 1 = Buffer size %d\n", (*data & ICB2_BUFFER) * 8); else - PDEBUG(DSIMI, DEBUG_INFO, " DYN-BUFFER-SIZE-BIT: 0 = No meaning\n"); + LOGP(DSIMI, LOGL_INFO, " DYN-BUFFER-SIZE-BIT: 0 = No meaning\n"); if (*data & ICB2_ISO_L2) - PDEBUG(DSIMI, DEBUG_INFO, " ISO-7816-BLOCK-BIT: 1 = Compatible\n"); + LOGP(DSIMI, LOGL_INFO, " ISO-7816-BLOCK-BIT: 1 = Compatible\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " ISO-7816-BLOCK-BIT: 0 = Incompatible\n"); + LOGP(DSIMI, LOGL_INFO, " ISO-7816-BLOCK-BIT: 0 = Incompatible\n"); if (*data & ICB2_PRIVATE) - PDEBUG(DSIMI, DEBUG_INFO, " PRIVATE-USE-BIT: 1 = Private use layer 7 protocol\n"); + LOGP(DSIMI, LOGL_INFO, " PRIVATE-USE-BIT: 1 = Private use layer 7 protocol\n"); else - PDEBUG(DSIMI, DEBUG_INFO, " PRIVATE-USE-BIT: 0 = No meaning\n"); + LOGP(DSIMI, LOGL_INFO, " PRIVATE-USE-BIT: 0 = No meaning\n"); if (*data & ICB_EXT) - PDEBUG(DSIMI, DEBUG_INFO, " ICB-EXTENSION-BIT: 1 = ICB3 follows\n"); + LOGP(DSIMI, LOGL_INFO, " ICB-EXTENSION-BIT: 1 = ICB3 follows\n"); else { - PDEBUG(DSIMI, DEBUG_INFO, " ICB-EXTENSION-BIT: 0 = no ICB follows\n"); + LOGP(DSIMI, LOGL_INFO, " ICB-EXTENSION-BIT: 0 = no ICB follows\n"); ext = 0; } data++; @@ -273,12 +273,12 @@ static void rx_icl_pdu(uint8_t *data, int length) icb_count = 2; while (ext) { if (length < 1) { - PDEBUG(DSIMI, DEBUG_NOTICE, "Message too short\n"); + LOGP(DSIMI, LOGL_NOTICE, "Message too short\n"); return; } - PDEBUG(DSIMI, DEBUG_INFO, "Interface control layer ICB%d:\n", ++icb_count); - PDEBUG(DSIMI, DEBUG_INFO, " Value: 0x%02x\n", *data); + LOGP(DSIMI, LOGL_INFO, "Interface control layer ICB%d:\n", ++icb_count); + LOGP(DSIMI, LOGL_INFO, " Value: 0x%02x\n", *data); if (!(*data & 0x80)) ext = 0; data++; @@ -301,7 +301,7 @@ static uint8_t flip(uint8_t c) void sniffer_reset(sim_sniffer_t *sim) { - PDEBUG(DSIM1, DEBUG_INFO, "Resetting sniffer\n"); + LOGP(DSIM1, LOGL_INFO, "Resetting sniffer\n"); memset(sim, 0, sizeof(*sim)); } @@ -380,47 +380,47 @@ static void decode_ta1(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, in } if (fi > 0) - PDEBUG(DSIM2, DEBUG_INFO, " TA%d Fi = %d, f(max.) = %.1f MHz\n", count, fi, fmax); + LOGP(DSIM2, LOGL_INFO, " TA%d Fi = %d, f(max.) = %.1f MHz\n", count, fi, fmax); else - PDEBUG(DSIM2, DEBUG_INFO, " TA%d Fi = RFU\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d Fi = RFU\n", count); if (di > 0) - PDEBUG(DSIM2, DEBUG_INFO, " TA%d Di = %d\n", count, di); + LOGP(DSIM2, LOGL_INFO, " TA%d Di = %d\n", count, di); else - PDEBUG(DSIM2, DEBUG_INFO, " TA%d Di = RFU\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d Di = RFU\n", count); } static void decode_ta2(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { - PDEBUG(DSIM2, DEBUG_INFO, " TA%d T = %d\n", count, c & 0xf); + LOGP(DSIM2, LOGL_INFO, " TA%d T = %d\n", count, c & 0xf); if (!(c & 0x10)) - PDEBUG(DSIM2, DEBUG_INFO, " TA%d : Fi and Di by TA1 shall apply.\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d : Fi and Di by TA1 shall apply.\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TA%d : Implicit values (and not Di / Di by TA1) sall apply.\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d : Implicit values (and not Di / Di by TA1) sall apply.\n", count); if (!(c & 0x80)) - PDEBUG(DSIM2, DEBUG_INFO, " TA%d : Capable to change negotiable/specific mode.\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d : Capable to change negotiable/specific mode.\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TA%d : Unable to change negotiable/specific mode.\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d : Unable to change negotiable/specific mode.\n", count); } static void decode_tai(sim_sniffer_t *sim, uint8_t c, int count) { if ((sim->atr_td & 0xf) != 14) { - PDEBUG(DSIM2, DEBUG_INFO, " TA%d Value = 0x%02x\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TA%d Value = 0x%02x\n", count, c); return; } if (count == 3) { switch (c & 0xf) { case 0: - PDEBUG(DSIM2, DEBUG_INFO, " TA%d fsmin = Default\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d fsmin = Default\n", count); break; case 1: case 2: case 3: - PDEBUG(DSIM2, DEBUG_INFO, " TA%d fsmin = %d MHz\n", count, c & 0xf); + LOGP(DSIM2, LOGL_INFO, " TA%d fsmin = %d MHz\n", count, c & 0xf); break; default: - PDEBUG(DSIM2, DEBUG_INFO, " TA%d fsmin = reserved\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d fsmin = reserved\n", count); break; } @@ -429,110 +429,110 @@ static void decode_tai(sim_sniffer_t *sim, uint8_t c, int count) case 1: case 2: case 3: - PDEBUG(DSIM2, DEBUG_INFO, " TA%d fsmax = reserved\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d fsmax = reserved\n", count); break; case 5: - PDEBUG(DSIM2, DEBUG_INFO, " TA%d fsmax = 5 MHz (Default)\n", count); + LOGP(DSIM2, LOGL_INFO, " TA%d fsmax = 5 MHz (Default)\n", count); break; default: - PDEBUG(DSIM2, DEBUG_INFO, " TA%d fsmax = %d MHz\n", count, c >> 4); + LOGP(DSIM2, LOGL_INFO, " TA%d fsmax = %d MHz\n", count, c >> 4); break; } } else { - PDEBUG(DSIM2, DEBUG_INFO, " TA%d Block Waiting Time = %d\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TA%d Block Waiting Time = %d\n", count, c); } } static void decode_tb1(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { if ((c & 0x1f) == 0) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d PI1=0: VPP not connected\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d PI1=0: VPP not connected\n", count); else if ((c & 0x1f) == 5) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d PI1=5: VPP is 5 Volts (default)\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d PI1=5: VPP is 5 Volts (default)\n", count); else if ((c & 0x1f) >= 6 && (c & 0x1f) <= 25) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d PI1=%d: VPP is %d Volts\n", count, c & 0x1f, (c & 0x1f) - 1); + LOGP(DSIM2, LOGL_INFO, " TB%d PI1=%d: VPP is %d Volts\n", count, c & 0x1f, (c & 0x1f) - 1); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d PI1=%d: not defined\n", count, c & 0x1f); - PDEBUG(DSIM2, DEBUG_INFO, " TB%d II = %d\n", count, (c >> 5) & 0x3); + LOGP(DSIM2, LOGL_INFO, " TB%d PI1=%d: not defined\n", count, c & 0x1f); + LOGP(DSIM2, LOGL_INFO, " TB%d II = %d\n", count, (c >> 5) & 0x3); } static void decode_tb2(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Value = 0x%02x\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TB%d Value = 0x%02x\n", count, c); } static void decode_tbi(sim_sniffer_t *sim, uint8_t c, int count) { if ((sim->atr_td & 0xf) != 14) { - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Value = 0x%02x\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TB%d Value = 0x%02x\n", count, c); return; } if (count == 3) { - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Maximum block size = %d\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TB%d Maximum block size = %d\n", count, c); } else { if (!(c & 0x01)) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d XOR Checksum\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d XOR Checksum\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d CRC Checksum\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d CRC Checksum\n", count); if (!(c & 0x02)) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d 12-etu frame\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d 12-etu frame\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d 11-etu frame\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d 11-etu frame\n", count); if (!(c & 0x04)) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d No Chaining in ICL-Layer-Protocol\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d No Chaining in ICL-Layer-Protocol\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Chaining in ICL-Layer-Protocol\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d Chaining in ICL-Layer-Protocol\n", count); if (!(c & 0x08)) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Incompatible to ISO 7816 (Character Protocol)\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d Incompatible to ISO 7816 (Character Protocol)\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Compatible to ISO 7816 (Character Protocol)\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d Compatible to ISO 7816 (Character Protocol)\n", count); if (!(c & 0x10)) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d No private in ICL-Layer-Protocol\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d No private in ICL-Layer-Protocol\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d Private in ICL-Layer-Protocol\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d Private in ICL-Layer-Protocol\n", count); if (!(c & 0x20)) - PDEBUG(DSIM2, DEBUG_INFO, " TB%d No ICB-Extension in ICL-Layer-Protocol\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d No ICB-Extension in ICL-Layer-Protocol\n", count); else - PDEBUG(DSIM2, DEBUG_INFO, " TB%d ICB-Extension in ICL-Layer-Protocol\n", count); + LOGP(DSIM2, LOGL_INFO, " TB%d ICB-Extension in ICL-Layer-Protocol\n", count); } } static void decode_tc1(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { - PDEBUG(DSIM2, DEBUG_INFO, " TC%d N = %d\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TC%d N = %d\n", count, c); } static void decode_tc2(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { - PDEBUG(DSIM2, DEBUG_INFO, " TC%d Value = 0x%02x\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TC%d Value = 0x%02x\n", count, c); } static void decode_tci(sim_sniffer_t *sim, uint8_t c, int count) { if ((sim->atr_td & 0xf) != 14) { - PDEBUG(DSIM2, DEBUG_INFO, " TC%d Value = 0x%02x\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TC%d Value = 0x%02x\n", count, c); return; } - PDEBUG(DSIM2, DEBUG_INFO, " TC%d Character Waiting Time = %d\n", count, c); + LOGP(DSIM2, LOGL_INFO, " TC%d Character Waiting Time = %d\n", count, c); } static void decode_td(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { switch (c & 0xf) { case 0: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=1: Half-duplex transmission of characters (ISO 7816).\n", count); + LOGP(DSIM2, LOGL_INFO, " TD%d T=1: Half-duplex transmission of characters (ISO 7816).\n", count); break; case 1: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=1: Half-duplex transmission of blocks (ISO 7816).\n", count); + LOGP(DSIM2, LOGL_INFO, " TD%d T=1: Half-duplex transmission of blocks (ISO 7816).\n", count); break; case 2: case 3: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=%d: Reserved for future full-duplex operations.\n", count, c & 0xf); + LOGP(DSIM2, LOGL_INFO, " TD%d T=%d: Reserved for future full-duplex operations.\n", count, c & 0xf); break; case 4: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=4: Reserved for an enhanced half-duplex transmission of characters.\n", count); + LOGP(DSIM2, LOGL_INFO, " TD%d T=4: Reserved for an enhanced half-duplex transmission of characters.\n", count); break; case 5: case 6: @@ -543,13 +543,13 @@ static void decode_td(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int case 11: case 12: case 13: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=%d: Reserved for future use by ISO/IEC JTC 1/SC 17.\n", count, c & 0xf); + LOGP(DSIM2, LOGL_INFO, " TD%d T=%d: Reserved for future use by ISO/IEC JTC 1/SC 17.\n", count, c & 0xf); break; case 14: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=14: Refers to transmission protocols not standardized by ISO/IEC JTC 1/SC 17.\n", count); + LOGP(DSIM2, LOGL_INFO, " TD%d T=14: Refers to transmission protocols not standardized by ISO/IEC JTC 1/SC 17.\n", count); break; case 15: - PDEBUG(DSIM2, DEBUG_INFO, " TD%d T=15: Does not refer to a transmission protocol, but only qualifies global interface bytes.\n", count); + LOGP(DSIM2, LOGL_INFO, " TD%d T=15: Does not refer to a transmission protocol, but only qualifies global interface bytes.\n", count); break; } } @@ -589,26 +589,26 @@ static void decode_if(sim_sniffer_t *sim, int count) } if ((sim->atr_td >> 4)) - PDEBUG(DSIM2, DEBUG_INFO, "----------------------------------------\n"); + LOGP(DSIM2, LOGL_INFO, "----------------------------------------\n"); } static void decode_hist(sim_sniffer_t __attribute__((unused)) *sim, uint8_t c, int count) { - PDEBUG(DSIM2, DEBUG_INFO, " History byte #%d: 0x%02x\n", count, c); + LOGP(DSIM2, LOGL_INFO, " History byte #%d: 0x%02x\n", count, c); } static void rx_atr(sim_sniffer_t *sim, uint8_t c) { /* TS */ if (sim->atr_count == 0) { - PDEBUG(DSIM1, DEBUG_INFO, "----------------------------------------\n"); + LOGP(DSIM1, LOGL_INFO, "----------------------------------------\n"); switch (c) { case 0x3f: - PDEBUG(DSIM2, DEBUG_INFO, "Reading ATR inverse bit order:\n"); + LOGP(DSIM2, LOGL_INFO, "Reading ATR inverse bit order:\n"); sim->inverse_order = 1; break; case 0x3b: - PDEBUG(DSIM2, DEBUG_INFO, "Reading ATR normal bit order:\n"); + LOGP(DSIM2, LOGL_INFO, "Reading ATR normal bit order:\n"); sim->inverse_order = 0; break; default: @@ -689,14 +689,14 @@ static void rx_atr(sim_sniffer_t *sim, uint8_t c) } if (sim->atr_tck == 0) - PDEBUG(DSIM2, DEBUG_INFO, " Checksum 0x%02x ok.\n", c); + LOGP(DSIM2, LOGL_INFO, " Checksum 0x%02x ok.\n", c); else - PDEBUG(DSIM2, DEBUG_NOTICE, " Checksum 0x%02x error!\n", c); + LOGP(DSIM2, LOGL_NOTICE, " Checksum 0x%02x error!\n", c); sim->l1_state = L1_STATE_RECEIVE; sim->block_state = BLOCK_STATE_ADDRESS; - PDEBUG(DSIM2, DEBUG_INFO, "ATR done!\n"); + LOGP(DSIM2, LOGL_INFO, "ATR done!\n"); } static void rx_char(sim_sniffer_t *sim, uint8_t c) @@ -714,7 +714,7 @@ static void rx_char(sim_sniffer_t *sim, uint8_t c) sniffer_rx(sim, c); return; } - PDEBUG(DSIM1, DEBUG_INFO, "----------------------------------------\n"); + LOGP(DSIM1, LOGL_INFO, "----------------------------------------\n"); sim->block_address = c; sim->block_state = BLOCK_STATE_CONTROL; sim->block_checksum = c; @@ -733,17 +733,17 @@ static void rx_char(sim_sniffer_t *sim, uint8_t c) sim->block_data[sim->block_count++] = c; return; } - PDEBUG(DSIM2, DEBUG_INFO, "Layer 2:\n"); - PDEBUG(DSIM2, DEBUG_INFO, " source %d -> to %d\n", sim->block_address >> 4, sim->block_address & 0xf); + LOGP(DSIM2, LOGL_INFO, "Layer 2:\n"); + LOGP(DSIM2, LOGL_INFO, " source %d -> to %d\n", sim->block_address >> 4, sim->block_address & 0xf); if ((sim->block_control & 0x11) == 0x00) - PDEBUG(DSIM2, DEBUG_INFO, " control I: N(S)=%d N(R)=%d\n", (sim->block_control >> 1) & 7, sim->block_control >> 5); + LOGP(DSIM2, LOGL_INFO, " control I: N(S)=%d N(R)=%d\n", (sim->block_control >> 1) & 7, sim->block_control >> 5); else if ((sim->block_control & 0x1f) == 0x09) - PDEBUG(DSIM2, DEBUG_INFO, " control REJ: N(R)=%d\n", sim->block_control >> 5); + LOGP(DSIM2, LOGL_INFO, " control REJ: N(R)=%d\n", sim->block_control >> 5); else if (sim->block_control == 0xef) - PDEBUG(DSIM2, DEBUG_INFO, " control RES\n"); + LOGP(DSIM2, LOGL_INFO, " control RES\n"); else - PDEBUG(DSIM2, DEBUG_INFO, " control unknown 0x%02x\n", sim->block_control); - PDEBUG(DSIM2, DEBUG_INFO, " length %d\n", sim->block_length); + LOGP(DSIM2, LOGL_INFO, " control unknown 0x%02x\n", sim->block_control); + LOGP(DSIM2, LOGL_INFO, " length %d\n", sim->block_length); if (sim->block_checksum == 0) { FILE *fp; if (write_pdu_file && (fp = fopen(write_pdu_file, "a"))) { @@ -756,7 +756,7 @@ static void rx_char(sim_sniffer_t *sim, uint8_t c) } rx_icl_pdu(sim->block_data, sim->block_length); } else - PDEBUG(DSIM2, DEBUG_NOTICE, "Received message with checksum error!\n"); + LOGP(DSIM2, LOGL_NOTICE, "Received message with checksum error!\n"); sim->block_state = BLOCK_STATE_ADDRESS; } } @@ -764,12 +764,12 @@ static void rx_char(sim_sniffer_t *sim, uint8_t c) void sniffer_rx(sim_sniffer_t *sim, uint8_t c) { - PDEBUG(DSIM1, DEBUG_DEBUG, "Serial RX '0x%02x'\n", c); + LOGP(DSIM1, LOGL_DEBUG, "Serial RX '0x%02x'\n", c); switch (sim->l1_state) { case L1_STATE_RESET: if (c != 0x3f && c != 0x3b) { - PDEBUG(DSIM1, DEBUG_INFO, "Received garbage '0x%02x' while waiting for ATR\n", c); + LOGP(DSIM1, LOGL_INFO, "Received garbage '0x%02x' while waiting for ATR\n", c); break; } sim->l1_state = L1_STATE_ATR; @@ -792,13 +792,13 @@ void sniffer_timeout(sim_sniffer_t *sim) case L1_STATE_RESET: case L1_STATE_ATR: if (sim->l1_state == L1_STATE_ATR && sim->atr_count) - PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while receiving ATR!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Timeout while receiving ATR!\n"); sim->l1_state = L1_STATE_ATR; sim->atr_count = 0; break; case L1_STATE_RECEIVE: if (sim->block_state != BLOCK_STATE_ADDRESS) - PDEBUG(DSIM1, DEBUG_NOTICE, "Timeout while receiving message!\n"); + LOGP(DSIM1, LOGL_NOTICE, "Timeout while receiving message!\n"); sim->block_state = BLOCK_STATE_ADDRESS; break; default: diff --git a/src/test/Makefile.am b/src/test/Makefile.am index b6d8349..dd5b11a 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -17,9 +17,11 @@ test_filter_SOURCES = test_filter.c dummy.c test_filter_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/liboptions/liboptions.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCC_LIBS) \ + $(LIBOSMOCORE_LIBS) \ -lm test_sendevolumenregler_SOURCES = test_sendevolumenregler.c @@ -40,10 +42,12 @@ test_emphasis_SOURCES = test_emphasis.c dummy.c test_emphasis_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/liboptions/liboptions.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCC_LIBS) \ + $(LIBOSMOCORE_LIBS) \ -lm test_dtmf_SOURCES = dummy.x test_dtmf.c @@ -59,22 +63,20 @@ test_dms_SOURCES = test_dms.c dummy.c test_dms_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/liboptions/liboptions.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/nmt/libdmssms.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA @@ -97,22 +99,20 @@ test_sms_SOURCES = dummy.c test_sms.c test_sms_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/liboptions/liboptions.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/nmt/libdmssms.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ -lm if HAVE_ALSA @@ -157,8 +157,10 @@ test_goertzel_SOURCES = test_goertzel.c dummy.c test_goertzel_LDADD = \ $(COMMON_LA) \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libgoertzel/libgoertzel.a \ $(top_builddir)/src/liboptions/liboptions.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCC_LIBS) \ + $(LIBOSMOCORE_LIBS) \ -lm diff --git a/src/test/test_dms.c b/src/test/test_dms.c index 23a91db..f73f735 100644 --- a/src/test/test_dms.c +++ b/src/test/test_dms.c @@ -5,7 +5,7 @@ #include <string.h> #include <unistd.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../nmt/nmt.h" extern int dms_allow_loopback; @@ -80,9 +80,10 @@ int main(void) int i, j; /* this is never called, it forces the linker to add mobile functions */ - if (debuglevel == -1000) main_mobile_loop(); + if (loglevel == -1000) main_mobile_loop(); - debuglevel = DEBUG_DEBUG; + loglevel = LOGL_DEBUG; + logging_init(); dms_allow_loopback = 1; nmt = alloc_nmt(); @@ -199,7 +200,7 @@ int main(void) ok(); - debuglevel = DEBUG_INFO; + loglevel = LOGL_INFO; /* test again with pseudo random packet dropps */ srandom(0); diff --git a/src/test/test_dtmf.c b/src/test/test_dtmf.c index f26ae3b..6cf8ebe 100644 --- a/src/test/test_dtmf.c +++ b/src/test/test_dtmf.c @@ -2,7 +2,7 @@ #include <stdint.h> #include <math.h> #include <string.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libsample/sample.h" #include "../libdtmf/dtmf_decode.h" #include "../libdtmf/dtmf_encode.h" diff --git a/src/test/test_emphasis.c b/src/test/test_emphasis.c index aea6356..ab78ee9 100644 --- a/src/test/test_emphasis.c +++ b/src/test/test_emphasis.c @@ -5,7 +5,7 @@ #include "../libsample/sample.h" #include "../libfilter/iir_filter.h" #include "../libemphasis/emphasis.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #define level2db(level) (20 * log10(level)) #define db2level(db) pow(10, (double)db / 20.0) diff --git a/src/test/test_filter.c b/src/test/test_filter.c index ceaa463..f1fe5cc 100644 --- a/src/test/test_filter.c +++ b/src/test/test_filter.c @@ -5,7 +5,7 @@ #include "../libsample/sample.h" #include "../libfilter/iir_filter.h" #include "../libfilter/fir_filter.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #define level2db(level) (20 * log10(level)) #define db2level(db) pow(10, (double)db / 20.0) diff --git a/src/test/test_goertzel.c b/src/test/test_goertzel.c index ee1ba0f..656f31e 100644 --- a/src/test/test_goertzel.c +++ b/src/test/test_goertzel.c @@ -4,7 +4,7 @@ #include <string.h> #include "../libsample/sample.h" #include "../libgoertzel/goertzel.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #define level2db(level) (20 * log10(level)) #define db2level(db) pow(10, (double)db / 20.0) diff --git a/src/test/test_performance.c b/src/test/test_performance.c index a045eee..ae10930 100644 --- a/src/test/test_performance.c +++ b/src/test/test_performance.c @@ -6,7 +6,7 @@ #include "../libsample/sample.h" #include "../libfilter/iir_filter.h" #include "../libfm/fm.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" struct timeval start_tv, tv; double duration; diff --git a/src/test/test_sms.c b/src/test/test_sms.c index 36c892b..2ffe805 100644 --- a/src/test/test_sms.c +++ b/src/test/test_sms.c @@ -5,7 +5,7 @@ #include <string.h> #include <unistd.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../nmt/nmt.h" static const uint8_t test_mo_sms_data1[] = { @@ -107,9 +107,10 @@ int main(void) int rc; /* this is never called, it forces the linker to add mobile functions */ - if (debuglevel == -1000) main_mobile_loop(); + if (loglevel == -1000) main_mobile_loop(); - debuglevel = DEBUG_DEBUG; + loglevel = LOGL_DEBUG; + logging_init(); nmt = calloc(sizeof(*nmt), 1); sms_init_sender(nmt); diff --git a/src/tv/Makefile.am b/src/tv/Makefile.am index 7fe03b8..ada0fdf 100644 --- a/src/tv/Makefile.am +++ b/src/tv/Makefile.am @@ -19,12 +19,13 @@ osmotv_SOURCES = \ osmotv_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libimage/libimage.a \ $(top_builddir)/src/libfm/libfm.a \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ $(ALSA_LIBS) \ $(IMAGEMAGICK_LIBS) \ -lm @@ -36,8 +37,7 @@ osmotv_LDADD += \ endif osmotv_LDADD += \ - $(top_builddir)/src/libdisplay/libdisplay.a \ - $(top_builddir)/src/libtimer/libtimer.a + $(top_builddir)/src/libdisplay/libdisplay.a if HAVE_SDR osmotv_LDADD += \ diff --git a/src/tv/main.c b/src/tv/main.c index 0bb6aca..74f40a9 100644 --- a/src/tv/main.c +++ b/src/tv/main.c @@ -33,7 +33,7 @@ enum paging_signal; #include "../libfm/fm.h" #include "../libwave/wave.h" #include "../libimage/img.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #ifdef HAVE_SDR #include "../libsdr/sdr_config.h" #include "../libsdr/sdr.h" @@ -495,7 +495,8 @@ int main(int argc, char *argv[]) { int __attribute__((__unused__)) rc, argi; - debuglevel = 0; + loglevel = LOGL_DEBUG; + logging_init(); #ifdef HAVE_SDR sdr_config_init(DEFAULT_LO_OFFSET); @@ -568,3 +569,5 @@ int main(int argc, char *argv[]) return 0; } +void osmo_cc_set_log_cat(void) {} + diff --git a/src/zeitansage/Makefile.am b/src/zeitansage/Makefile.am index 38883d8..8451c41 100644 --- a/src/zeitansage/Makefile.am +++ b/src/zeitansage/Makefile.am @@ -11,13 +11,9 @@ zeitansage_SOURCES = \ zeitansage_LDADD = \ $(COMMON_LA) \ $(top_builddir)/src/liboptions/liboptions.a \ - $(top_builddir)/src/libdebug/libdebug.a \ $(top_builddir)/src/libmobile/libmobile.a \ - $(top_builddir)/src/libosmocc/libosmocc.a \ $(top_builddir)/src/libdisplay/libdisplay.a \ $(top_builddir)/src/libjitter/libjitter.a \ - $(top_builddir)/src/libtimer/libtimer.a \ - $(top_builddir)/src/libselect/libselect.a \ $(top_builddir)/src/libsamplerate/libsamplerate.a \ $(top_builddir)/src/libemphasis/libemphasis.a \ $(top_builddir)/src/libfsk/libfsk.a \ @@ -25,8 +21,10 @@ zeitansage_LDADD = \ $(top_builddir)/src/libfilter/libfilter.a \ $(top_builddir)/src/libwave/libwave.a \ $(top_builddir)/src/libsample/libsample.a \ - $(top_builddir)/src/libg711/libg711.a \ $(top_builddir)/src/libaaimage/libaaimage.a \ + $(top_builddir)/src/liblogging/liblogging.a \ + $(LIBOSMOCORE_LIBS) \ + $(LIBOSMOCC_LIBS) \ $(ALSA_LIBS) \ -lm diff --git a/src/zeitansage/main.c b/src/zeitansage/main.c index 7112f7f..d4fbb0a 100644 --- a/src/zeitansage/main.c +++ b/src/zeitansage/main.c @@ -23,7 +23,7 @@ #include <string.h> #include <errno.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/main_mobile.h" #include "../liboptions/options.h" diff --git a/src/zeitansage/zeitansage.c b/src/zeitansage/zeitansage.c index 6b3b0ed..a251721 100644 --- a/src/zeitansage/zeitansage.c +++ b/src/zeitansage/zeitansage.c @@ -25,9 +25,10 @@ #include <math.h> #include <time.h> #include "../libsample/sample.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../libmobile/cause.h" +#include "../libmobile/get_time.h" #include "zeitansage.h" #define db2level(db) pow(10, (double)(db) / 20.0) @@ -96,7 +97,7 @@ static void call_new_state(zeit_call_t *call, enum zeit_call_state new_state) { if (call->state == new_state) return; - PDEBUG(DZEIT, DEBUG_DEBUG, "State change: %s -> %s\n", call_state_name(call->state), call_state_name(new_state)); + LOGP(DZEIT, LOGL_DEBUG, "State change: %s -> %s\n", call_state_name(call->state), call_state_name(new_state)); call->state = new_state; zeit_display_status(); } @@ -133,7 +134,7 @@ int zeit_init(double audio_level_dBm, int alerting) } sekunden_time += minuten_time; - PDEBUG(DZEIT, DEBUG_DEBUG, "Total time to play announcement, starting with beep: %.2f seconds\n", (double)sekunden_time / 8000.0); + LOGP(DZEIT, LOGL_DEBUG, "Total time to play announcement, starting with beep: %.2f seconds\n", (double)sekunden_time / 8000.0); return 0; } @@ -156,11 +157,13 @@ static void zeit_calc_time(zeit_call_t *call, time_t time_sec) call->m = tm->tm_min; call->s = tm->tm_sec; - PDEBUG(DZEIT, DEBUG_INFO, "The time at the next beep is: %d:%02d:%02d\n", call->h, call->m, call->s); + LOGP(DZEIT, LOGL_INFO, "The time at the next beep is: %d:%02d:%02d\n", call->h, call->m, call->s); } static void call_timeout(void *data); +#define FLOAT_TO_TIMEOUT(f) floor(f), ((f) - floor(f)) * 1000000 + /* Create call instance */ static zeit_call_t *zeit_call_create(uint32_t callref, const char *id) { @@ -168,25 +171,25 @@ static zeit_call_t *zeit_call_create(uint32_t callref, const char *id) double now, time_offset; time_t time_sec; - PDEBUG(DZEIT, DEBUG_INFO, "Creating call instance to play time for caller '%s'.\n", id); + LOGP(DZEIT, LOGL_INFO, "Creating call instance to play time for caller '%s'.\n", id); /* create */ call = calloc(1, sizeof(*call)); if (!call) { - PDEBUG(DZEIT, DEBUG_ERROR, "No mem!\n"); + LOGP(DZEIT, LOGL_ERROR, "No mem!\n"); abort(); } /* init */ call->callref = callref; strncpy(call->caller_id, id, sizeof(call->caller_id) - 1); - timer_init(&call->timer, call_timeout, call); + osmo_timer_setup(&call->timer, call_timeout, call); now = get_time(); time_offset = fmod(now, 10.0); time_sec = (int)floor(now / 10.0) * 10; call->spl_time = (int)(time_offset * 8000.0); zeit_calc_time(call, time_sec); - timer_start(&call->timer, 10.0 - time_offset); + osmo_timer_schedule(&call->timer, FLOAT_TO_TIMEOUT(10.0 - time_offset)); /* link */ callp = &zeit_call_list; @@ -209,7 +212,7 @@ static void zeit_call_destroy(zeit_call_t *call) (*callp) = call->next; /* cleanup */ - timer_exit(&call->timer); + osmo_timer_del(&call->timer); /* destroy */ free(call); @@ -323,7 +326,7 @@ static void call_timeout(void *data) double now, time_offset; time_t time_sec; - PDEBUG(DZEIT, DEBUG_INFO, "Beep!\n"); + LOGP(DZEIT, LOGL_INFO, "Beep!\n"); now = get_time(); @@ -336,7 +339,7 @@ static void call_timeout(void *data) } call->spl_time = 0; zeit_calc_time(call, time_sec); - timer_start(&call->timer, 10.0 - time_offset); + osmo_timer_schedule(&call->timer, FLOAT_TO_TIMEOUT(10.0 - time_offset)); } /* Call control starts call towards clock */ @@ -363,14 +366,14 @@ static void _release(int callref, int __attribute__((unused)) cause) { zeit_call_t *call; - PDEBUG(DZEIT, DEBUG_INFO, "Call has been disconnected by network.\n"); + LOGP(DZEIT, LOGL_INFO, "Call has been disconnected by network.\n"); for (call = zeit_call_list; call; call = call->next) { if (call->callref == callref) break; } if (!call) { - PDEBUG(DZEIT, DEBUG_NOTICE, "Outgoing disconnect, but no callref!\n"); + LOGP(DZEIT, LOGL_NOTICE, "Outgoing disconnect, but no callref!\n"); call_up_release(callref, CAUSE_INVALCALLREF); return; } diff --git a/src/zeitansage/zeitansage.h b/src/zeitansage/zeitansage.h index 64dd986..b9492a4 100644 --- a/src/zeitansage/zeitansage.h +++ b/src/zeitansage/zeitansage.h @@ -1,6 +1,6 @@ #include "../libfm/fm.h" #include "../libmobile/sender.h" -#include "../libtimer/timer.h" +#include <osmocom/core/timer.h> /* current state of incoming call */ enum zeit_call_state { @@ -17,7 +17,7 @@ enum zeit_call_state { typedef struct zeit_call { struct zeit_call *next; int callref; /* call reference */ - struct timer timer; + struct osmo_timer_list timer; enum zeit_call_state state; /* current state */ char caller_id[32]; /* caller id to be displayed */ int spl_time; /* sample offset within 10 seconds */ |