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

@@ -52,6 +52,28 @@ extern int alarms;
extern int authentication;
extern int warmstart;
/* check if number is a valid station ID */
const char *cnetz_number_valid(const char *number)
{
/* assume that the number has valid length(s) and digits */
if (number[0] > '7')
return "Digit 1 (mobile country code) exceeds 7.";
if (number[7]) {
if ((number[1] - '0') == 0)
return "Digit 2 and 3 (mobile network code) of 8-digit number must be at least 10.";
if ((number[1] - '0') * 10 + (number[2] - '0') > 31)
return "Digit 2 and 3 (mobile network code) of 8-digit number exceed 31.";
if (atoi(number + 3) > 65535)
return "Digit 4 to 8 (mobile subscriber suffix) of 8-digit number exceed 65535.";
} else {
if (atoi(number + 2) > 65535)
return "Digit 3 to 7 (mobile subscriber suffix) of 7-digit number exceed 65535.";
}
return NULL;
}
static int send_bit(void *inst)
{
fuvst_t *fuvst = (fuvst_t *)inst;
@@ -1286,41 +1308,18 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
uint8_t futln_fuvst;
int futln_rest; /* use int for checking size > 65535 */
int len;
int i;
transaction_t *trans;
uint8_t ident;
uint8_t opcode, *data;
/* 1. check if number is invalid, return INVALNUMBER */
len = strlen(dialing);
if (len >= 11 && !strncmp(dialing, "0161", 4)) {
dialing += 4;
len -= 4;
}
if (len < 7 || len > 8) {
inval:
PDEBUG(DCNETZ, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing);
return -CAUSE_INVALNUMBER;
}
for (i = 0; i < len; i++) {
if (dialing[i] < '0' || dialing[i] > '9')
goto inval;
}
/* 1. split number into elements */
futln_nat = dialing[0] - '0';
if (len == 7)
futln_fuvst = dialing[1] - '0';
else {
if (dialing[7]) {
futln_fuvst = (dialing[1] - '0') * 10 + (dialing[2] - '0');
if (futln_fuvst > 31) {
PDEBUG(DCNETZ, DEBUG_NOTICE, "Digit 2 and 3 '%02d' must not exceed '31', but they do!\n", futln_fuvst);
goto inval;
}
}
futln_rest = atoi(dialing + len - 5);
if (futln_rest > 65535) {
PDEBUG(DCNETZ, DEBUG_NOTICE, "Last 5 digits '%05d' must not exceed '65535', but they do!\n", futln_rest);
goto inval;
futln_rest = atoi(dialing + 3);
} else {
futln_fuvst = dialing[1] - '0';
futln_rest = atoi(dialing + 2);
}
/* 2. base station ready? */