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

@@ -98,9 +98,7 @@ void print_help(const char *arg0)
printf(" and stays below this level, the connection is released.\n");
printf(" Use 'auto' to do automatic noise floor calibration to detect loss.\n");
printf(" Only works with SDR! (disabled by default)\n");
printf("\nstation-id: Give 7 digits of Radio Unit's prefix/ident, you don't need to\n");
printf(" enter it for every start of this program.\n");
main_mobile_print_station_id();
main_mobile_print_hotkeys();
printf("Press 'i' key to dump list of seen Radio Units.\n");
}
@@ -252,6 +250,11 @@ sysdef_oor:
return 1;
}
static const struct number_lengths number_lengths[] = {
{ 7, "number 'pppiiii' (prefix, ident)" },
{ 0, NULL },
};
int main(int argc, char *argv[])
{
int rc, argi;
@@ -264,8 +267,8 @@ int main(int argc, char *argv[])
init_besetzton();
// init_ansage();
console_digits = "0123456789*#";
main_mobile_init();
/* init mobile interface */
main_mobile_init("0123456789", number_lengths, NULL, mpt1327_number_valid);
/* handle options / config file */
add_options();
@@ -278,10 +281,9 @@ int main(int argc, char *argv[])
if (argi < argc) {
station_id = argv[argi];
if (strlen(station_id) != 7) {
printf("Given station ID '%s' does not have 4 digits\n", station_id);
return 0;
}
rc = main_mobile_number_ask(station_id, "station ID");
if (rc)
return rc;
}
if (!num_kanal) {
@@ -380,7 +382,7 @@ int main(int argc, char *argv[])
mpt1327_check_channels();
main_mobile("mpt1327", &quit, NULL, station_id, 7);
main_mobile_loop("mpt1327", &quit, NULL, station_id);
fail:
/* destroy transceiver instance */

View File

@@ -80,6 +80,7 @@
#include "dsp.h"
#include "message.h"
/* Timers and counters */
#define RESPONSE_TIMEOUT 1.0
#define REPEAT_GTC 1
@@ -88,8 +89,30 @@
#define REPEAT_AHYX 3
#define REPEAT_CLEAR 3
/* Sysdef
*
/* check if number is a valid station ID */
const char *mpt1327_number_valid(const char *number)
{
int value;
static char error[256];
/* assume that the number has valid length(s) and digits */
value = (number[0] - '0') * 100 + (number[1] - '0') * 10 + (number[2] - '0');
if (value > 127) {
sprintf(error, "Prefix '%03d' is not in range 000..127.", value);
return error;
}
value = atoi(number + 3);
if (value > 8100 || value < 1) {
sprintf(error, "Ident '%04d' is not in range 0001..8100.", value);
return error;
}
return NULL;
}
/*
* Sysdef
*/
static mpt1327_sysdef_t sysdef;
@@ -1536,28 +1559,10 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
mpt1327_t *tc;
uint8_t prefix;
uint16_t ident;
int i;
/* 1. check if number is invalid, return INVALNUMBER */
if (strlen(dialing) != 7) {
inval:
PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing);
return -CAUSE_INVALNUMBER;
}
for (i = 0; i < 7; i++) {
if (dialing[i] < '0' || dialing[i] > '9')
goto inval;
}
/* 1. split number into prefix and ident */
prefix = (dialing[0] - '0') * 100 + (dialing[1] - '0') * 10 + (dialing[2] - '0');
if (prefix > 127) {
PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing call to invalid Prefix '%03d' in number '%s', rejecting! (Prefix must be 000..127)\n", prefix, dialing);
return -CAUSE_INVALNUMBER;
}
ident = atoi(dialing + 3);
if (ident > 8100 || ident < 1) {
PDEBUG(DMPT1327, DEBUG_NOTICE, "Outgoing call to invalid Ident '%04d' in number '%s', rejecting! (Ident must be 0001..8100)\n", ident, dialing);
return -CAUSE_INVALNUMBER;
}
/* 2. check if given number is already in a call, return BUSY */
unit = get_unit(prefix, ident);

View File

@@ -139,6 +139,7 @@ typedef struct mpt1327 {
void init_sysdef (uint16_t sys, int wt, int per, int pon, int timeout);
void flush_units(void);
double mpt1327_channel2freq(enum mpt1327_band band, int channel, int uplink);
const char *mpt1327_number_valid(const char *number);
const char *mpt1327_band_name(enum mpt1327_band band);
void mpt1327_band_list(void);
int mpt1327_band_by_short_name(const char *short_name);