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:
@@ -693,22 +693,8 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
|
||||
{
|
||||
sender_t *sender;
|
||||
bnetz_t *bnetz;
|
||||
int i;
|
||||
|
||||
/* 1. check if number is invalid, return INVALNUMBER */
|
||||
if (strlen(dialing) == 7 && dialing[0] == '0' && dialing[1] == '5')
|
||||
dialing += 2;
|
||||
else if (strlen(dialing) != 5) {
|
||||
inval:
|
||||
PDEBUG(DBNETZ, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing);
|
||||
return -CAUSE_INVALNUMBER;
|
||||
}
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (dialing[i] < '0' || dialing[i] > '9')
|
||||
goto inval;
|
||||
}
|
||||
|
||||
/* 2. check if given number is already in a call, return BUSY */
|
||||
/* 1. check if given number is already in a call, return BUSY */
|
||||
for (sender = sender_head; sender; sender = sender->next) {
|
||||
bnetz = (bnetz_t *) sender;
|
||||
if (!strcmp(bnetz->station_id, dialing))
|
||||
@@ -719,7 +705,7 @@ inval:
|
||||
return -CAUSE_BUSY;
|
||||
}
|
||||
|
||||
/* 3. check if all senders are busy, return NOCHANNEL */
|
||||
/* 2. check if all senders are busy, return NOCHANNEL */
|
||||
for (sender = sender_head; sender; sender = sender->next) {
|
||||
bnetz = (bnetz_t *) sender;
|
||||
if (bnetz->state == BNETZ_FREI)
|
||||
@@ -732,7 +718,7 @@ inval:
|
||||
|
||||
PDEBUG_CHAN(DBNETZ, DEBUG_INFO, "Call to mobile station, paging station id '%s'\n", dialing);
|
||||
|
||||
/* 4. trying to page mobile station */
|
||||
/* 3. trying to page mobile station */
|
||||
bnetz->callref = callref;
|
||||
bnetz_page(bnetz, dialing, 1);
|
||||
|
||||
|
@@ -74,8 +74,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 5 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();
|
||||
}
|
||||
|
||||
@@ -124,6 +123,16 @@ static int handle_options(int short_option, int argi, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct number_lengths number_lengths[] = {
|
||||
{ 5, "B-Netz number" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const char *number_prefixes[] = {
|
||||
"05xxxxx",
|
||||
NULL
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc, argi;
|
||||
@@ -135,7 +144,7 @@ int main(int argc, char *argv[])
|
||||
init_besetzton();
|
||||
init_ansage();
|
||||
|
||||
main_mobile_init();
|
||||
main_mobile_init("0123456789", number_lengths, number_prefixes, NULL);
|
||||
|
||||
/* handle options / config file */
|
||||
add_options();
|
||||
@@ -148,10 +157,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (argi < argc) {
|
||||
station_id = argv[argi];
|
||||
if (strlen(station_id) != 5) {
|
||||
printf("Given station ID '%s' does not have 5 digits\n", station_id);
|
||||
return 0;
|
||||
}
|
||||
rc = main_mobile_number_ask(station_id, "station ID");
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!num_kanal) {
|
||||
@@ -202,7 +210,7 @@ int main(int argc, char *argv[])
|
||||
printf("To call phone, switch transmitter (using paging signal) to %.3f MHz.\n", bnetz_kanal2freq(19, 0) / 1e6);
|
||||
}
|
||||
|
||||
main_mobile("bnetz", &quit, NULL, station_id, 5);
|
||||
main_mobile_loop("bnetz", &quit, NULL, station_id);
|
||||
|
||||
fail:
|
||||
/* destroy transceiver instance */
|
||||
|
Reference in New Issue
Block a user