From 4dd3322f63b663b46c120130fcefafdb90c7c7ef Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Wed, 7 Oct 2009 18:47:53 +0200 Subject: Don't send busy tone after clear-back (ss5). modified: ss5.cpp --- ss5.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ss5.cpp') diff --git a/ss5.cpp b/ss5.cpp index 40eb540..0d453e4 100644 --- a/ss5.cpp +++ b/ss5.cpp @@ -227,13 +227,13 @@ static void ss5_trace_header(struct mISDNport *mISDNport, class PmISDN *port, un /* - * changes release tone int busy signal - * this makes the line more authentic + * changes release tone into silence + * this makes the line sound more authentic */ void Pss5::set_tone(const char *dir, const char *name) { if (name && !strcmp(name, "cause_10")) - name = "busy"; + name = NULL; PmISDN::set_tone(dir, name); } -- cgit v1.2.3-55-g7522 From b987a1bbbcabbf183ebe009903778671a1591337 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Tue, 27 Oct 2009 07:53:27 +0100 Subject: Fixes and improves parsing of config file. Last character of unterminated line was ignored. Minor bug fix in 2600 Hz pulse dialing. modified: README modified: action_vbox.cpp modified: crypt.cpp modified: extension.c modified: gsm_conf.c modified: interface.c modified: macro.h modified: route.c modified: ss5.cpp modified: ss5.h --- README | 1 + action_vbox.cpp | 5 +---- crypt.cpp | 2 +- extension.c | 20 +++++--------------- gsm_conf.c | 4 +--- interface.c | 4 +--- macro.h | 18 +++++++++++++++++- route.c | 4 +--- ss5.cpp | 8 ++++---- ss5.h | 2 +- 10 files changed, 33 insertions(+), 35 deletions(-) (limited to 'ss5.cpp') diff --git a/README b/README index 85e8d96..f423b62 100644 --- a/README +++ b/README @@ -520,6 +520,7 @@ Changes after Version 1.6 -> Just add 'extern' right below your external interface definition, or give external interface name in routing.conf: ": extern interfaces=XXXXX" - Added experimental CCITT No. 5 signalling system. (for educational purpose) +- Fixed/simplyfied config parser. The last digit of the last line was ignored. diff --git a/action_vbox.cpp b/action_vbox.cpp index 2426610..e325c0f 100644 --- a/action_vbox.cpp +++ b/action_vbox.cpp @@ -142,10 +142,7 @@ void EndpointAppPBX::vbox_index_read(int num) fduse++; i = 0; - while((fgets(buffer,sizeof(buffer),fp))) { - buffer[sizeof(buffer)-1] = '\0'; - if (buffer[0]) buffer[strlen(buffer)-1] = '\0'; - + while((GETLINE(buffer, fp))) { name[0] = callerid[0] = '\0'; mon = mday = hour = min = 0; sscanf(buffer, "%s %d %d %d %d %d %s", name, &year, &mon, &mday, &hour, &min, callerid); diff --git a/crypt.cpp b/crypt.cpp index ee8e7cc..44e901c 100644 --- a/crypt.cpp +++ b/crypt.cpp @@ -216,7 +216,7 @@ static unsigned int get_bogomips(void) } fduse++; buffer[sizeof(buffer-1)] = '\0'; - while(fgets(buffer, sizeof(buffer)-1, fp)) { + while(GETLINE(buffer, fp)) { if (!!strncmp(buffer, "bogomips", 8)) continue; if (!strchr(buffer, ':')) diff --git a/extension.c b/extension.c index a1c3aa7..00e5326 100644 --- a/extension.c +++ b/extension.c @@ -68,10 +68,8 @@ int read_extension(struct extension *ext, char *num) ext->vbox_codec = CODEC_MONO; line=0; - while((fgets(buffer, sizeof(buffer), fp))) { + while((GETLINE(buffer, fp))) { line++; - buffer[sizeof(buffer)-1] = '\0'; - if (buffer[0]) buffer[strlen(buffer)-1] = '\0'; p = buffer; while(*p <= 32) { /* skip spaces */ @@ -1228,10 +1226,8 @@ int parse_phonebook(char *number, char **abbrev_pointer, char **phone_pointer, c } line=0; - while((fgets(buffer, sizeof(buffer), fp))) { + while((GETLINE(buffer, fp))) { line++; - buffer[sizeof(buffer)-1] = '\0'; - if (buffer[0]) buffer[strlen(buffer)-1] = '\0'; p = buffer; while(*p <= 32) { /* skip spaces */ @@ -1351,10 +1347,8 @@ int parse_secrets(char *number, char *remote_id, char **auth_pointer, char **cry } line=0; - while((fgets(buffer, sizeof(buffer), fp))) { + while((GETLINE(buffer, fp))) { line++; - buffer[sizeof(buffer)-1] = '\0'; - if (buffer[0]) buffer[strlen(buffer)-1] = '\0'; p = buffer; while(*p <= 32) { /* skip spaces */ @@ -1476,10 +1470,8 @@ char *parse_directory(char *number, int type) } line=0; - while((fgets(buffer, sizeof(buffer), fp))) { + while((GETLINE(buffer, fp))) { line++; - buffer[sizeof(buffer)-1] = '\0'; - if (buffer[0]) buffer[strlen(buffer)-1] = '\0'; p = buffer; while(*p <= 32) { /* skip spaces */ @@ -1611,10 +1603,8 @@ int parse_callbackauth(char *number, struct caller_info *callerinfo) } line=0; - while((fgets(buffer, sizeof(buffer), fp))) { + while((GETLINE(buffer, fp))) { line++; - buffer[sizeof(buffer)-1] = '\0'; - if (buffer[0]) buffer[strlen(buffer)-1] = '\0'; p = buffer; while(*p <= 32) { /* skip spaces */ diff --git a/gsm_conf.c b/gsm_conf.c index 9957b86..082a6ed 100644 --- a/gsm_conf.c +++ b/gsm_conf.c @@ -47,10 +47,8 @@ int gsm_conf(struct gsm_conf *gsm_conf) } line=0; - while((fgets(buffer,sizeof(buffer),fp))) { + while((GETLINE(buffer, fp))) { line++; - buffer[sizeof(buffer)-1]=0; - if (buffer[0]) buffer[strlen(buffer)-1]=0; p=buffer; while(*p <= 32) { /* skip spaces */ diff --git a/interface.c b/interface.c index 42f409c..8e21c75 100644 --- a/interface.c +++ b/interface.c @@ -1148,9 +1148,7 @@ struct interface *read_interfaces(void) } line=0; - while((fgets(buffer,sizeof(buffer),fp))) { - buffer[sizeof(buffer)-1]=0; - if (buffer[0]) buffer[strlen(buffer)-1]=0; + while((GETLINE(buffer, fp))) { p=buffer; line++; diff --git a/macro.h b/macro.h index 29b2794..9e4bcd1 100644 --- a/macro.h +++ b/macro.h @@ -92,7 +92,7 @@ static inline void *_malloc(unsigned int size, const char *function, int line) if (!addr) fatal(function, line, "No memory for %d bytes.\n", size); memset(addr, 0, size); - return(addr); + return addr; } /* memory freeing with clearing memory to prevent using freed memory */ @@ -104,4 +104,20 @@ static inline void _free(void *addr, int size) free(addr); } +/* fill buffer and be sure that it's result is 0-terminated, also remove newline */ +#define GETLINE(buffer, fp) _getline(buffer, sizeof(buffer), fp) +static inline char *_getline(char *buffer, int size, FILE *fp) +{ + if (!fgets(buffer, size-1, fp)) + return NULL; + buffer[size-1] = '\0'; + if (!buffer[0]) + return buffer; + if (buffer[strlen(buffer)-1] == '\n') + buffer[strlen(buffer)-1] = '\0'; + if (buffer[strlen(buffer)-1] == '\r') + buffer[strlen(buffer)-1] = '\0'; + return buffer; +} + diff --git a/route.c b/route.c index d47f8c2..4fecf38 100644 --- a/route.c +++ b/route.c @@ -839,11 +839,9 @@ struct route_ruleset *ruleset_parse(void) go_leaf: line[nesting]=0; go_root: - while((fgets(buffer,sizeof(buffer),fp[nesting]))) + while((GETLINE(buffer, fp[nesting]))) { line[nesting]++; - buffer[sizeof(buffer)-1]=0; - if (buffer[0]) buffer[strlen(buffer)-1]=0; p = buffer; /* remove tabs */ diff --git a/ss5.cpp b/ss5.cpp index 0d453e4..164ef0c 100644 --- a/ss5.cpp +++ b/ss5.cpp @@ -1347,7 +1347,7 @@ void Pss5::digit_ind(char digit) end_trace(); new_ss5_state(SS5_STATE_IDLE); - do_setup(dial); + do_setup(dial, 1); new_state(PORT_STATE_IN_PROCEEDING); } @@ -1392,7 +1392,7 @@ void Pss5::pulse_ind(int on) } if (p_state == PORT_STATE_IN_SETUP) { /* sending digit as setup */ - do_setup(dial); /* include 'a' == KP1 */ + do_setup(dial, 0); /* include 'a' == KP1 */ new_state(PORT_STATE_IN_OVERLAP); } else { /* sending digit as information */ @@ -1618,13 +1618,13 @@ void Pss5::do_release(int cause, int location) /* * create endpoint and send setup */ -void Pss5::do_setup(char *dial) +void Pss5::do_setup(char *dial, int complete) { class Endpoint *epoint; struct lcr_msg *message; SCPY(p_dialinginfo.id, dial); - p_dialinginfo.sending_complete = 1; + p_dialinginfo.sending_complete = complete; p_callerinfo.present = INFO_PRESENT_NOTAVAIL; p_callerinfo.screen = INFO_SCREEN_NETWORK; p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT; diff --git a/ss5.h b/ss5.h index 6897abd..238501f 100644 --- a/ss5.h +++ b/ss5.h @@ -57,7 +57,7 @@ class Pss5 : public PmISDN void start_signal(int); void start_outgoing(void); void do_release(int cause, int location); - void do_setup(char *digit); + void do_setup(char *digit, int complete); void seizing_ind(void); void digit_ind(char digit); -- cgit v1.2.3-55-g7522 From 21b4f371239a701575a1f46f739b6a33ccbea702 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 13 Dec 2009 14:06:01 +0100 Subject: Added protection against false tone detection. modified: ss5.cpp modified: ss5.h --- ss5.cpp | 19 ++++++++++++++++++- ss5.h | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'ss5.cpp') diff --git a/ss5.cpp b/ss5.cpp index 164ef0c..5f4d706 100644 --- a/ss5.cpp +++ b/ss5.cpp @@ -346,6 +346,7 @@ Pss5::Pss5(int type, struct mISDNport *mISDNport, char *portname, struct port_se p_m_s_digit_i = 0; p_m_s_pulsecount = 0; p_m_s_last_digit = ' '; + p_m_s_last_digit_used = ' '; p_m_s_signal_loss = 0; p_m_s_decoder_count = 0; //p_m_s_decoder_buffer; @@ -428,7 +429,7 @@ void Pss5::inband_receive(unsigned char *buffer, int len) PDEBUG(DEBUG_SS5, "%s: detecting signal '%c' start (state=%s signal=%s)\n", p_name, digit, ss5_state_name[p_m_s_state], ss5_signal_name[p_m_s_signal]); #endif - /* ignore short loss of signal */ + /* ignore short loss of signal, or change within one decode window */ if (p_m_s_signal_loss) { if (digit == ' ') { /* still lost */ @@ -460,11 +461,19 @@ void Pss5::inband_receive(unsigned char *buffer, int len) p_m_s_last_digit = digit; /* starting to loose signal */ p_m_s_signal_loss = SS5_DECODER_NPOINTS; + } else if (digit != p_m_s_last_digit) { + /* digit changes, but we keep old digit until it is detected twice */ +#ifdef DEBUG_DETECT + PDEBUG(DEBUG_SS5, "%s: signal '%c' changes to '%c'\n", p_name, p_m_s_last_digit, digit); +#endif + p_m_s_last_digit = digit; + digit = p_m_s_last_digit_used; } else { /* storing last signal, in case it is lost */ p_m_s_last_digit = digit; } } + p_m_s_last_digit_used = digit; /* update mute */ if ((p_m_mISDNport->ss5 & SS5_FEATURE_SUPPRESS)) { @@ -1597,6 +1606,8 @@ void Pss5::do_release(int cause, int location) { struct lcr_msg *message; + p_m_s_timer = 0.0; + /* sending release to endpoint */ while(p_epointlist) { message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE); @@ -1926,6 +1937,8 @@ if (0 || p_type==PORT_TYPE_SS5_OUT) { /* outgoing exchange */ start_signal(SS5_STATE_CLEAR_BACK); new_state(PORT_STATE_OUT_DISCONNECT); +// p_m_s_timer_fn = &Pss5::register_timeout; +// p_m_s_timer = now + 30.0; } /* MESSAGE_RELEASE */ @@ -1934,6 +1947,10 @@ void Pss5::message_release(unsigned int epoint_id, int message_id, union paramet do_release(param->disconnectinfo.cause, param->disconnectinfo.location); } +void Pss5::register_timeout(void) +{ + do_release(CAUSE_NORMAL, LOCATION_BEYOND); +} /* * endpoint sends messages to the port diff --git a/ss5.h b/ss5.h index 238501f..b1cc215 100644 --- a/ss5.h +++ b/ss5.h @@ -34,7 +34,8 @@ class Pss5 : public PmISDN char p_m_s_dial[64]; /* current dialing register */ int p_m_s_digit_i; /* current digit of register counter */ int p_m_s_pulsecount; /* counts pule dialing half cycles */ - char p_m_s_last_digit; /* stores last digit to fill short signal losses */ + char p_m_s_last_digit; /* stores last digit that was detected, to fill short signal losses */ + char p_m_s_last_digit_used; /* stores last digit that was used, to ignore short changes of signal due to noise */ int p_m_s_signal_loss; /* sample counter for loss of signal check */ int p_m_s_decoder_count; /* samples currently decoded */ unsigned char p_m_s_decoder_buffer[SS5_DECODER_NPOINTS]; /* buffer for storing one goertzel window */ @@ -76,6 +77,8 @@ class Pss5 : public PmISDN void message_disconnect(unsigned int epoint_id, int message_id, union parameter *param); void message_release(unsigned int epoint_id, int message_id, union parameter *param); + void register_timeout(void); + }; #define new_ss5_state(a) _new_ss5_state(a, __FUNCTION__, __LINE__) -- cgit v1.2.3-55-g7522