From 486d2d5dbeaff62e9701589e73f64122e4bdd516 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 11 Nov 2017 08:10:37 +0100 Subject: [PATCH] NMT: Fixup assign traffic channel dms_call state now belongs to transaction, so it is kept while switching to traffic channel. --- src/nmt/dsp.c | 2 +- src/nmt/nmt.c | 44 ++++++++++++++++++++++++------------------- src/nmt/nmt.h | 1 - src/nmt/transaction.h | 3 ++- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c index 9ce6ba8..37c1688 100644 --- a/src/nmt/dsp.c +++ b/src/nmt/dsp.c @@ -183,7 +183,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level) nmt->rx_bits_count++; - if (nmt->dms_call) + if (nmt->trans && nmt->trans->dms_call) fsk_receive_bit_dms(nmt, bit, quality, level); // printf("bit=%d quality=%.4f\n", bit, quality); diff --git a/src/nmt/nmt.c b/src/nmt/nmt.c index bd5f912..997e849 100644 --- a/src/nmt/nmt.c +++ b/src/nmt/nmt.c @@ -245,7 +245,8 @@ static inline int is_chan_class_cc(enum nmt_chan_type chan_type) { if (chan_type == CHAN_TYPE_CC || chan_type == CHAN_TYPE_CCA - || chan_type == CHAN_TYPE_CCB) + || chan_type == CHAN_TYPE_CCB + || chan_type == CHAN_TYPE_CC_TC) return 1; return 0; @@ -440,7 +441,6 @@ void nmt_destroy(sender_t *sender) void nmt_go_idle(nmt_t *nmt) { timer_stop(&nmt->timer); - nmt->dms_call = 0; dms_reset(nmt); sms_reset(nmt); @@ -454,7 +454,6 @@ void nmt_go_idle(nmt_t *nmt) /* go active for loopback tests */ nmt_new_state(nmt, STATE_ACTIVE); nmt_set_dsp_mode(nmt, DSP_MODE_AUDIO); - nmt->dms_call = 1; #endif } @@ -501,14 +500,16 @@ static void nmt_page(transaction_t *trans, int try) } } -static nmt_t *search_free_tc(void) +static nmt_t *search_free_tc(nmt_t *own) { sender_t *sender; nmt_t *nmt, *cc_tc = NULL; for (sender = sender_head; sender; sender = sender->next) { nmt = (nmt_t *) sender; - if (nmt->state != STATE_IDLE) + /* if our CC is used, we don't care about busy state, + * because it can be used, if it is CC/TC type */ + if (nmt != own && nmt->state != STATE_IDLE) continue; /* remember combined voice/control/paging channel as second alternative */ if (nmt->sysinfo.chan_type == CHAN_TYPE_CC_TC) @@ -915,7 +916,7 @@ static void rx_mo_dialing(nmt_t *nmt, frame_t *frame) if (!strcmp(nmt->dialing, nmt->smsc_number)) { /* SMS */ PDEBUG(DNMT, DEBUG_INFO, "Setup call to SMSC.\n"); - nmt->dms_call = 1; + trans->dms_call = 1; } else { int callref = ++new_callref; int rc; @@ -955,6 +956,8 @@ not_consistent_digit: static void tx_mo_complete(nmt_t *nmt, frame_t *frame) { + transaction_t *trans = nmt->trans; + if (++nmt->tx_frame_count <= 4) { set_line_signal(nmt, frame, 6); if (nmt->tx_frame_count == 1) @@ -971,7 +974,7 @@ static void tx_mo_complete(nmt_t *nmt, frame_t *frame) nmt_new_state(nmt, STATE_ACTIVE); nmt->active_state = ACTIVE_STATE_VOICE; nmt_set_dsp_mode(nmt, DSP_MODE_AUDIO); - if (nmt->supervisory && !nmt->dms_call) { + if (nmt->supervisory && !trans->dms_call) { super_reset(nmt); timer_start(&nmt->timer, SUPERVISORY_TO1); } @@ -1032,7 +1035,7 @@ static void rx_mt_paging(nmt_t *nmt, frame_t *frame) break; PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received call acknowledgment from subscriber %c,%s.\n", trans->subscriber.country, trans->subscriber.number); if (trans->sms_string[0]) - nmt->dms_call = 1; + trans->dms_call = 1; timer_stop(&trans->timer); nmt_new_state(nmt, STATE_MT_CHANNEL); trans->nmt = nmt; @@ -1057,7 +1060,7 @@ static void tx_mt_channel(nmt_t *nmt, frame_t *frame) nmt_t *tc; /* get free channel (after releasing all channels) */ - tc = search_free_tc(); + 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"); @@ -1069,11 +1072,14 @@ static void tx_mt_channel(nmt_t *nmt, frame_t *frame) return; } - /* link trans and tc together, so we can continue with channel assignment */ - PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Switching to TC channel #%d.\n", tc->sender.kanal); - nmt_new_state(nmt, STATE_IDLE); - tc->trans = trans; - trans->nmt = tc; + if (nmt != tc) { + /* link trans and tc together, so we can continue with channel assignment */ + PDEBUG_CHAN(DNMT, DEBUG_NOTICE, "Switching to TC channel #%d.\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 #%d.\n", tc->sender.kanal); nmt_new_state(tc, STATE_MT_IDENT); /* assign channel on 'nmt' to 'tc' */ @@ -1111,7 +1117,7 @@ static void rx_mt_ident(nmt_t *nmt, frame_t *frame) break; nmt_value2digits(frame->ms_password, trans->subscriber.password, 3); PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received identity (password %s).\n", trans->subscriber.password); - if (nmt->dms_call) { + if (trans->dms_call) { nmt_new_state(nmt, STATE_MT_AUTOANSWER); nmt->wait_autoanswer = 1; nmt->tx_frame_count = 0; @@ -1252,7 +1258,7 @@ static void tx_mt_complete(nmt_t *nmt, frame_t *frame) transaction_t *trans = nmt->trans; ++nmt->tx_frame_count; - if (nmt->compandor && !nmt->dms_call) { + if (nmt->compandor && !trans->dms_call) { if (nmt->tx_frame_count == 1) PDEBUG_CHAN(DNMT, DEBUG_INFO, "Send 'compandor in'.\n"); set_line_signal(nmt, frame, 5); @@ -1263,11 +1269,11 @@ static void tx_mt_complete(nmt_t *nmt, frame_t *frame) nmt_new_state(nmt, STATE_ACTIVE); nmt->active_state = ACTIVE_STATE_VOICE; nmt_set_dsp_mode(nmt, DSP_MODE_AUDIO); - if (nmt->supervisory && !nmt->dms_call) { + if (nmt->supervisory && !trans->dms_call) { super_reset(nmt); timer_start(&nmt->timer, SUPERVISORY_TO1); } - if (nmt->dms_call) { + if (trans->dms_call) { time_t ti = time(NULL); sms_deliver(nmt, sms_ref, trans->caller_id, trans->caller_type, SMS_PLAN_ISDN_TEL, ti, trans->sms_string); } @@ -1755,7 +1761,7 @@ inval: PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing call, but no free calling channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } - if (!search_free_tc()) { + if (!search_free_tc(NULL)) { PDEBUG(DNMT, DEBUG_NOTICE, "Outgoing call, but no free traffic channel, rejecting!\n"); return -CAUSE_NOCHANNEL; } diff --git a/src/nmt/nmt.h b/src/nmt/nmt.h index 4d472d2..335efde 100644 --- a/src/nmt/nmt.h +++ b/src/nmt/nmt.h @@ -128,7 +128,6 @@ typedef struct nmt { /* DMS/SMS states */ dms_t dms; /* DMS states */ - int dms_call; /* indicates that this call is a DMS call */ sms_t sms; /* SMS states */ char smsc_number[33]; /* digits to match SMSC */ struct timer sms_timer; diff --git a/src/nmt/transaction.h b/src/nmt/transaction.h index e7f7bf1..6af4501 100644 --- a/src/nmt/transaction.h +++ b/src/nmt/transaction.h @@ -21,7 +21,8 @@ typedef struct transaction { char caller_id[33]; /* caller id digits */ enum number_type caller_type; /* caller id type */ - /* SMS */ + /* DMS/SMS */ + int dms_call; /* indicates to use DMS (used for SMS) */ char sms_string[256]; /* current string to deliver */ } transaction_t;