Refactoring validity check and prefix processing of dialed number

Command line help shows how many digits and what prefixes can be dialed.

Giving a station ID via command line will be checked for being valid.

The number to call the mobile statione will be checked for being valid.

Prefixes that are defined for a nework will be removed from station ID
automatically.

Multiple station ID lengths are supported:
 * C-Netz: 7 or 8 digits, depending on area code length
 * A-Netz: 5 or 7 digits; number is truncated to last 5 digits.
 * IMTS/MTS: 5 or 7 digits, depending on phone's selector switch.
This commit is contained in:
Andreas Eversberg
2021-10-07 19:35:56 +02:00
parent 3a73f31d7e
commit 423bc42429
41 changed files with 662 additions and 429 deletions

View File

@@ -893,30 +893,8 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
transaction_t *trans;
uint32_t min1;
uint16_t min2;
int i;
/* 1. check if number is invalid, return INVALNUMBER */
if (!tacs) {
if (strlen(dialing) == 12 && !strncmp(dialing, "+1", 2))
dialing += 2;
if (strlen(dialing) == 11 && !strncmp(dialing, "1", 1))
dialing += 1;
} else if (!jtacs) {
if (strlen(dialing) == 14 && !strncmp(dialing, "+44", 3))
dialing += 3;
if (strlen(dialing) == 11 && !strncmp(dialing, "0", 1))
dialing += 1;
}
if (strlen(dialing) != 10) {
inval:
PDEBUG(DAMPS, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing);
return -CAUSE_INVALNUMBER;
}
for (i = 0; i < 10; i++) {
if (dialing[i] < '0' || dialing[i] > '9')
goto inval;
}
/* 1. split number into area code and number */
amps_number2min(dialing, &min1, &min2);
/* 2. check if the subscriber is attached */

View File

@@ -99,8 +99,7 @@ void print_help(const char *arg0)
printf(" If 1, be sure to have a round-trip delay (latency) not more than 5 ms\n");
printf(" -O --tolerant\n");
printf(" Be more tolerant when hunting for sync sequence\n");
printf("\nstation-id: Give 10 digit station-id, you don't need to enter it for every\n");
printf(" start of this program.\n");
main_mobile_print_station_id();
main_mobile_print_hotkeys();
}
@@ -227,6 +226,11 @@ static int handle_options(int short_option, int argi, char **argv)
return 1;
}
static const struct number_lengths number_lengths[] = {
{ 10, "AMPS number" },
{ 0, NULL }
};
int main_amps_tacs(const char *name, int argc, char *argv[])
{
int rc, argi;
@@ -237,7 +241,7 @@ int main_amps_tacs(const char *name, int argc, char *argv[])
/* override default */
dsp_samplerate = 96000;
main_mobile_init();
main_mobile_init("0123456789", number_lengths, number_prefixes, NULL);
/* handle options / config file */
add_options();
@@ -257,10 +261,9 @@ int main_amps_tacs(const char *name, int argc, char *argv[])
if (argi < argc) {
station_id = argv[argi];
if (strlen(station_id) != 10) {
printf("Given station ID '%s' does not have 10 digits\n", station_id);
return 0;
}
rc = main_mobile_number_ask(station_id, "station ID");
if (rc)
return rc;
}
if (!num_kanal) {
@@ -392,7 +395,7 @@ int main_amps_tacs(const char *name, int argc, char *argv[])
printf("Base station on channel %s ready (%s), please tune transmitter to %.4f MHz and receiver to %.4f MHz. (%.3f MHz offset)\n", kanal[i], chan_type_long_name(chan_type[i]), amps_channel2freq(atoi(kanal[i]), 0) / 1e6, amps_channel2freq(atoi(kanal[i]), 1) / 1e6, amps_channel2freq(atoi(kanal[i]), 2) / 1e6);
}
main_mobile(name, &quit, NULL, station_id, 10);
main_mobile_loop(name, &quit, NULL, station_id);
fail:
/* destroy transceiver instance */

View File

@@ -1,3 +1,4 @@
#include <stdio.h>
#include "main.h"
#include "tones.h"
#include "noanswer.h"
@@ -8,6 +9,12 @@
const int tacs = 0;
const int jtacs = 0;
const char *number_prefixes[] = {
"1xxxxxxxxxx",
"+1xxxxxxxxxx",
NULL
};
int main(int argc, char *argv[])
{
/* init common tones */

View File

@@ -2,5 +2,7 @@
extern const int tacs;
extern const int jtacs;
extern const char *number_prefixes[];
int main_amps_tacs(const char *name, int argc, char *argv[]);