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:
@@ -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? */
|
||||
|
@@ -22,6 +22,7 @@ typedef struct fuvst {
|
||||
struct SysMeld SM; /* collects alarm messages */
|
||||
} fuvst_t;
|
||||
|
||||
const char *cnetz_number_valid(const char *number);
|
||||
int fuvst_create(const char *kanal, enum fuvst_chan_type chan_type, const char *audiodev, int samplerate, double rx_gain, double tx_gain, const char *write_rx_wave, const char *write_tx_wave, const char *read_rx_wave, const char *read_tx_wave, int loopback, int ignore_link_failure, uint8_t sio, uint16_t local_pc, uint16_t remove_pc);
|
||||
void fuvst_destroy(sender_t *sender);
|
||||
void add_emergency(const char *number);
|
||||
|
@@ -73,6 +73,7 @@ void print_help(const char *arg0)
|
||||
printf(" Don't do any link error checking at MTP.\n");
|
||||
printf(" -C --bs-config <filename>\n");
|
||||
printf(" Give DKO config file (6 KBytes tape file) to be loaded at boot time.\n");
|
||||
main_mobile_print_station_id();
|
||||
main_mobile_print_hotkeys();
|
||||
}
|
||||
|
||||
@@ -154,6 +155,20 @@ static int handle_options(int short_option, int argi, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct number_lengths number_lengths[] = {
|
||||
{ 7, "regular number format" },
|
||||
{ 8, "extended number format" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const char *number_prefixes[] = {
|
||||
"0161xxxxxxx",
|
||||
"0161xxxxxxxx",
|
||||
"+49161xxxxxxx",
|
||||
"+49161xxxxxxxx",
|
||||
NULL
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc, argi;
|
||||
@@ -166,10 +181,11 @@ int main(int argc, char *argv[])
|
||||
init_besetzton();
|
||||
init_ansage();
|
||||
|
||||
/* init mobile interface */
|
||||
allow_sdr = 0;
|
||||
uses_emphasis = 0;
|
||||
check_channel = 0;
|
||||
main_mobile_init();
|
||||
main_mobile_init("0123456789", number_lengths, number_prefixes, cnetz_number_valid);
|
||||
|
||||
config_init();
|
||||
|
||||
@@ -189,10 +205,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 7 digits\n", station_id);
|
||||
return 0;
|
||||
}
|
||||
rc = main_mobile_number_ask(station_id, "station ID");
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (num_kanal == 1 && num_device == 0)
|
||||
@@ -270,7 +285,7 @@ int main(int argc, char *argv[])
|
||||
if (config_loaded)
|
||||
printf("BS-Config: %s\n", config_name);
|
||||
|
||||
main_mobile("fuvst", &quit, NULL, station_id, 7);
|
||||
main_mobile_loop("fuvst", &quit, NULL, station_id);
|
||||
fail:
|
||||
|
||||
/* destroy transceiver instance */
|
||||
|
@@ -179,10 +179,11 @@ int main(int argc, char *argv[])
|
||||
func_mtp_receive_lssu = receive_lssu;
|
||||
func_mtp_receive_msu = receive_msu;
|
||||
|
||||
/* init mobile interface */
|
||||
allow_sdr = 0;
|
||||
uses_emphasis = 0;
|
||||
check_channel = 0;
|
||||
main_mobile_init();
|
||||
main_mobile_init(NULL, NULL, NULL, NULL);
|
||||
|
||||
/* handle options / config file */
|
||||
add_options();
|
||||
@@ -225,7 +226,7 @@ int main(int argc, char *argv[])
|
||||
goto fail;
|
||||
}
|
||||
|
||||
main_mobile(NULL, &quit, NULL, NULL, 0);
|
||||
main_mobile_loop(NULL, &quit, NULL, NULL);
|
||||
|
||||
fail:
|
||||
/* destroy transceiver instance */
|
||||
|
Reference in New Issue
Block a user