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

@@ -247,6 +247,11 @@ static int handle_options(int short_option, int argi, char **argv)
return 1;
}
static const struct number_lengths number_lengths[] = {
{ 9, "number 'trrrnnnnn' (type, relais, number)" },
{ 0, NULL }
};
int main(int argc, char *argv[])
{
int rc, argi;
@@ -257,7 +262,8 @@ int main(int argc, char *argv[])
/* init tones */
init_radiocom_tones();
main_mobile_init();
/* init mobile interface */
main_mobile_init("0123456789", number_lengths, NULL, r2000_number_valid);
/* handle options / config file */
add_options();
@@ -270,10 +276,9 @@ int main(int argc, char *argv[])
if (argi < argc) {
station_id = argv[argi];
if (strlen(station_id) != 9) {
printf("Given station ID '%s' does not have 9 digits\n", station_id);
return 0;
}
rc = main_mobile_number_ask(station_id, "station ID");
if (rc)
return rc;
}
if (!num_kanal) {
@@ -363,7 +368,7 @@ int main(int argc, char *argv[])
r2000_check_channels();
main_mobile("radiocom2000", &quit, NULL, station_id, 9);
main_mobile_loop("radiocom2000", &quit, NULL, station_id);
fail:
/* destroy transceiver instance */

View File

@@ -120,6 +120,21 @@ double r2000_channel2freq(int band, int channel, int uplink)
return freq * 1e6;
}
/* check if number is a valid station ID */
const char *r2000_number_valid(const char *number)
{
/* assume that the number has valid length(s) and digits */
if ((number[0] - '0') > 7)
return "Digit 1 (station mobile type) exceeds 7.";
if ((number[1] - '0') * 100 + (number[2] - '0') * 10 + (number[3] - '0') > 511)
return "Digit 2 to 5 (relais number) exceeds 511.";
if (atoi(number + 4) > 65535)
return "Digit 6 to 9 (mobile number) exceeds 65535.";
return NULL;
}
const char *r2000_state_name(enum r2000_state state)
{
static char invalid[16];
@@ -289,49 +304,10 @@ static const char *subscriber2string(r2000_subscriber_t *subscr)
/* convert 9-digits dial string to station mobile data */
static int string2subscriber(const char *dialstring, r2000_subscriber_t *subscr)
{
char check[6];
int type, relais, mor;
int i;
subscr->type = dialstring[0] - '0';
subscr->relais = (dialstring[1] - '0') * 100 + (dialstring[2] - '0') * 10 + (dialstring[3] - '0');
subscr->mor = atoi(dialstring + 4);
if (strlen(dialstring) != 9) {
PDEBUG(DR2000, DEBUG_NOTICE, "Wrong number of digits, use 9 digits: TRRRXXXXX (T=type, R=relais, X=mobile number)\n");
return -1;
}
for (i = 0; i < (int)strlen(dialstring); i++) {
if (dialstring[i] < '0' || dialstring[i] > '9') {
PDEBUG(DR2000, DEBUG_NOTICE, "Invalid digit in dial string, use only 0..9.\n");
return -1;
}
}
memcpy(check, dialstring, 1);
check[1] = '\0';
type = atoi(check);
if (type < 1 || type > 511) {
PDEBUG(DR2000, DEBUG_NOTICE, "Invalid station type in dial string, use 0..7 as station mobile type.\n");
return -1;
}
memcpy(check, dialstring + 1, 3);
check[3] = '\0';
relais = atoi(check);
if (relais < 1 || relais > 511) {
PDEBUG(DR2000, DEBUG_NOTICE, "Invalid relais number in dial string, use 000..511 as relais number.\n");
return -1;
}
memcpy(check, dialstring + 4, 5);
check[5] = '\0';
mor = atoi(check);
if (mor > 65535) {
PDEBUG(DR2000, DEBUG_NOTICE, "Invalid mobile number in dial string, use 00000..65535 as mobile number.\n");
return -1;
}
subscr->type = type;
subscr->relais = relais;
subscr->mor = mor;
return 0;
}

View File

@@ -129,6 +129,7 @@ void r2000_destroy(sender_t *sender);
void r2000_go_idle(r2000_t *r2000);
void r2000_band_list(void);
double r2000_channel2freq(int band, int channel, int uplink);
const char *r2000_number_valid(const char *number);
const char *r2000_get_frame(r2000_t *r2000);
void r2000_receive_frame(r2000_t *r2000, const char *bits, double quality, double level);
void r2000_receive_super(r2000_t *r2000, uint8_t super, double quality, double level);