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:
@@ -262,6 +262,21 @@ double imts_is_canada_only(const char *kanal)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check if number is a valid station ID */
|
||||
const char *mts_number_valid(const char *number)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* assume that the number has valid length(s) and digits */
|
||||
|
||||
for (i = 0; number[i]; i++) {
|
||||
if (number[i] == '1')
|
||||
return "Digits value '1' is not allowed within MTS number.";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* global init */
|
||||
int imts_init(void)
|
||||
{
|
||||
@@ -274,7 +289,7 @@ static void imts_paging(imts_t *imts, const char *dial_string, int loopback);
|
||||
static void imts_detector_test(imts_t *imts, double length_1, double length_2, double length_3);
|
||||
|
||||
/* Create transceiver instance and link to a list. */
|
||||
int imts_create(const char *kanal, const char *device, int use_sdr, int samplerate, double rx_gain, double tx_gain, int pre_emphasis, int de_emphasis, const char *write_rx_wave, const char *write_tx_wave, const char *read_rx_wave, const char *read_tx_wave, int loopback, double squelch_db, int ptt, int station_length, double fast_seize, enum mode mode, const char *operator, double length_1, double length_2, double length_3)
|
||||
int imts_create(const char *kanal, const char *device, int use_sdr, int samplerate, double rx_gain, double tx_gain, int pre_emphasis, int de_emphasis, const char *write_rx_wave, const char *write_tx_wave, const char *read_rx_wave, const char *read_tx_wave, int loopback, double squelch_db, int ptt, double fast_seize, enum mode mode, const char *operator, double length_1, double length_2, double length_3)
|
||||
{
|
||||
imts_t *imts;
|
||||
int rc;
|
||||
@@ -309,7 +324,6 @@ int imts_create(const char *kanal, const char *device, int use_sdr, int samplera
|
||||
|
||||
PDEBUG(DIMTS, DEBUG_DEBUG, "Creating 'IMTS' instance for channel = %s (sample rate %d).\n", kanal, samplerate);
|
||||
|
||||
imts->station_length = station_length;
|
||||
imts->fast_seize = fast_seize;
|
||||
imts->mode = mode;
|
||||
imts->operator = operator;
|
||||
@@ -809,8 +823,9 @@ static void ani_after_digit(imts_t *imts)
|
||||
/* update status while receiving station ID */
|
||||
imts_display_status();
|
||||
/* if all digits have been received */
|
||||
if (imts->rx_ani_index == imts->station_length) {
|
||||
if (imts->rx_ani_index == 7) {
|
||||
PDEBUG_CHAN(DIMTS, DEBUG_INFO, "ANI '%s' complete, sending dial tone.\n", imts->station_id);
|
||||
dt:
|
||||
imts_set_dsp_mode(imts, DSP_MODE_TONE, TONE_DIALTONE, 0.0, 0);
|
||||
timer_start(&imts->timer, DIALTONE_TO);
|
||||
imts->dial_number[0] = '\0';
|
||||
@@ -821,6 +836,11 @@ static void ani_after_digit(imts_t *imts)
|
||||
}
|
||||
timer_start(&imts->timer, ANI_TO);
|
||||
} else {
|
||||
/* if only 5 digits have been received */
|
||||
if (imts->rx_ani_index == 5) {
|
||||
PDEBUG_CHAN(DIMTS, DEBUG_INFO, "ANI '%s' (5 digits) complete, sending dial tone.\n", imts->station_id);
|
||||
goto dt;
|
||||
}
|
||||
PDEBUG_CHAN(DIMTS, DEBUG_NOTICE, "Timeout receiving ANI from mobile phone, releasing!\n");
|
||||
imts_release(imts);
|
||||
}
|
||||
@@ -1144,7 +1164,6 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
|
||||
char number[8];
|
||||
sender_t *sender;
|
||||
imts_t *imts;
|
||||
int i;
|
||||
|
||||
/* 1. check if given number is already in a call, return BUSY */
|
||||
for (sender = sender_head; sender; sender = sender->next) {
|
||||
@@ -1168,31 +1187,15 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
|
||||
return -CAUSE_NOCHANNEL;
|
||||
}
|
||||
|
||||
/* 3. check if number is invalid, return INVALNUMBER */
|
||||
if (strlen(dialing) == 12 && !strncmp(dialing, "+1", 2))
|
||||
dialing += 2;
|
||||
if (strlen(dialing) == 11 && !strncmp(dialing, "1", 1))
|
||||
dialing += 1;
|
||||
if (strlen(dialing) == 10 && imts->station_length == 7) {
|
||||
/* 3. convert 10 digit numbers to 7 digit station ID */
|
||||
if (strlen(dialing) == 10) {
|
||||
strncpy(number, dialing, 3);
|
||||
strcpy(number + 3, dialing + 6);
|
||||
dialing = number;
|
||||
}
|
||||
if (strlen(dialing) == 10 && imts->station_length == 5)
|
||||
dialing += 5;
|
||||
if ((int)strlen(dialing) != imts->station_length) {
|
||||
inval:
|
||||
PDEBUG(DIMTS, DEBUG_NOTICE, "Outgoing call to invalid number '%s', rejecting!\n", dialing);
|
||||
return -CAUSE_INVALNUMBER;
|
||||
}
|
||||
for (i = 0; i < (int)strlen(dialing); i++) {
|
||||
if (dialing[i] < '0' || dialing[i] > '9')
|
||||
goto inval;
|
||||
}
|
||||
|
||||
PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Call to mobile station, paging number: %s\n", dialing);
|
||||
|
||||
/* 4. trying to page mobile station */
|
||||
PDEBUG_CHAN(DIMTS, DEBUG_INFO, "Call to mobile station, paging number: %s\n", dialing);
|
||||
imts->callref = callref;
|
||||
imts_paging(imts, dialing, 0);
|
||||
|
||||
|
@@ -60,7 +60,6 @@ typedef struct imts {
|
||||
emphasis_t estate;
|
||||
int callref; /* call reference */
|
||||
char station_id[11]; /* current station ID (also used for test pattern) */
|
||||
int station_length; /* digit length of station ID */
|
||||
char dial_number[33]; /* number dialing */
|
||||
struct timer timer;
|
||||
int last_tone; /* last tone received */
|
||||
@@ -126,10 +125,11 @@ typedef struct imts {
|
||||
} imts_t;
|
||||
|
||||
|
||||
const char *mts_number_valid(const char *number);
|
||||
void imts_list_channels(void);
|
||||
double imts_channel2freq(const char *kanal, int uplink);
|
||||
int imts_init(void);
|
||||
int imts_create(const char *channel, const char *device, int use_sdr, int samplerate, double rx_gain, double tx_gain, int pre_emphasis, int de_emphasis, const char *write_rx_wave, const char *write_tx_wave, const char *read_rx_wave, const char *read_tx_wave, int loopback, double squelch_db, int ptt, int station_length, double fast_seize, enum mode mode, const char *operator, double length_1, double length_2, double length_3);
|
||||
int imts_create(const char *channel, const char *device, int use_sdr, int samplerate, double rx_gain, double tx_gain, int pre_emphasis, int de_emphasis, const char *write_rx_wave, const char *write_tx_wave, const char *read_rx_wave, const char *read_tx_wave, int loopback, double squelch_db, int ptt, double fast_seize, enum mode mode, const char *operator, double length_1, double length_2, double length_3);
|
||||
void imts_destroy(sender_t *sender);
|
||||
void imts_loss_indication(imts_t *imts, double loss_time);
|
||||
void imts_signal_indication(imts_t *imts);
|
||||
|
@@ -40,7 +40,6 @@
|
||||
/* settings */
|
||||
static double squelch_db = -INFINITY;
|
||||
static int ptt = 0;
|
||||
static int station_length = 0; /* defined by mode */
|
||||
static double fast_seize = 0.0;
|
||||
static enum mode mode = MODE_IMTS;
|
||||
static char operator[32] = "010";
|
||||
@@ -62,9 +61,6 @@ void print_help(const char *arg0)
|
||||
printf(" This adds extra delay to received audio, to eliminate noise when the\n");
|
||||
printf(" transmitter of the phone is turned off. Also this disables release on\n");
|
||||
printf(" loss of RF signal. (Squelch is required for this to operate.)\n");
|
||||
printf(" -5 --five\n");
|
||||
printf(" -7 --seven\n");
|
||||
printf(" Force station ID length (default is 7 for IMTS, 5 for MTS)\n");
|
||||
printf(" -F --fast-seize <delay in ms>\n");
|
||||
printf(" To compensate audio processing latency, give delay when to respond,\n");
|
||||
printf(" after detection of Guard tone from mobile phone.\n");
|
||||
@@ -89,8 +85,7 @@ void print_help(const char *arg0)
|
||||
printf(" Give length of 600/1500 Hz and silence in seconds. Listen to it with\n");
|
||||
printf(" a radio receiver. To exclude an element, set its length to '0'.\n");
|
||||
printf(" Example: '-D 0.5 0.5 0' plays alternating 600/1500 Hz tone.\n");
|
||||
printf("\nstation-id: Give %d digits of station-id, you don't need to enter it after\n", station_length);
|
||||
printf(" every start of this program.\n");
|
||||
main_mobile_print_station_id();
|
||||
main_mobile_print_hotkeys();
|
||||
}
|
||||
|
||||
@@ -99,8 +94,6 @@ static void add_options(void)
|
||||
main_mobile_add_options();
|
||||
option_add('S', "squelch", 1);
|
||||
option_add('P', "push-to-talk", 0);
|
||||
option_add('5', "five", 0);
|
||||
option_add('7', "seven", 0);
|
||||
option_add('F', "fast-seize", 1);
|
||||
option_add('D', "decoder-test", 3);
|
||||
option_add('M', "mts", 0);
|
||||
@@ -119,12 +112,6 @@ static int handle_options(int short_option, int argi, char **argv)
|
||||
case 'P':
|
||||
ptt = 1;
|
||||
break;
|
||||
case '5':
|
||||
station_length = 5;
|
||||
break;
|
||||
case '7':
|
||||
station_length = 7;
|
||||
break;
|
||||
case 'F':
|
||||
fast_seize = atof(argv[argi]) / 1000.0;
|
||||
if (fast_seize < 0.0)
|
||||
@@ -150,6 +137,19 @@ static int handle_options(int short_option, int argi, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct number_lengths number_lengths[] = {
|
||||
{ 5, "MTS number format" },
|
||||
{ 7, "IMTS number format" },
|
||||
{ 10, "IMTS number (digits 4..6 will br removed)" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const char *number_prefixes[] = {
|
||||
"1xxxxxxxxxx",
|
||||
"+1xxxxxxxxxx",
|
||||
NULL
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc, argi;
|
||||
@@ -163,7 +163,8 @@ int main(int argc, char *argv[])
|
||||
init_invalidnumber();
|
||||
init_congestion();
|
||||
|
||||
main_mobile_init();
|
||||
/* init mobile interface */
|
||||
main_mobile_init("0123456789", number_lengths, number_prefixes, NULL);
|
||||
|
||||
/* handle options / config file */
|
||||
add_options();
|
||||
@@ -174,19 +175,15 @@ int main(int argc, char *argv[])
|
||||
if (argi <= 0)
|
||||
return argi;
|
||||
|
||||
if (!station_length) {
|
||||
if (mode == MODE_IMTS)
|
||||
station_length = 7;
|
||||
else
|
||||
station_length = 5;
|
||||
}
|
||||
/* set check for MTS mode */
|
||||
if (mode == MODE_MTS)
|
||||
main_mobile_set_number_check_valid(mts_number_valid);
|
||||
|
||||
if (argi < argc) {
|
||||
station_id = argv[argi];
|
||||
if ((int)strlen(station_id) != station_length) {
|
||||
printf("Given station ID '%s' does not have %d digits\n", station_id, station_length);
|
||||
return 0;
|
||||
}
|
||||
rc = main_mobile_number_ask(station_id, "station ID");
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!num_kanal) {
|
||||
@@ -266,7 +263,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* create transceiver instance */
|
||||
for (i = 0; i < num_kanal; i++) {
|
||||
rc = imts_create(kanal[i], dsp_device[i], use_sdr, dsp_samplerate, rx_gain, tx_gain, do_pre_emphasis, do_de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, squelch_db, ptt, station_length, fast_seize, mode, operator, detector_test_length_1, detector_test_length_2, detector_test_length_3);
|
||||
rc = imts_create(kanal[i], dsp_device[i], use_sdr, dsp_samplerate, rx_gain, tx_gain, do_pre_emphasis, do_de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, squelch_db, ptt, fast_seize, mode, operator, detector_test_length_1, detector_test_length_2, detector_test_length_3);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Failed to create \"Sender\" instance. Quitting!\n");
|
||||
goto fail;
|
||||
@@ -274,7 +271,7 @@ int main(int argc, char *argv[])
|
||||
printf("Base station on channel %s ready, please tune transmitter to %.3f MHz and receiver to %.3f MHz. (%.3f MHz offset)\n", kanal[i], imts_channel2freq(kanal[i], 0) / 1e6, imts_channel2freq(kanal[i], 1) / 1e6, imts_channel2freq(kanal[i], 2) / 1e6);
|
||||
}
|
||||
|
||||
main_mobile((mode == MODE_IMTS) ? "imts" : "mts", &quit, NULL, station_id, station_length);
|
||||
main_mobile_loop((mode == MODE_IMTS) ? "imts" : "mts", &quit, NULL, station_id);
|
||||
|
||||
fail:
|
||||
/* destroy transceiver instance */
|
||||
|
Reference in New Issue
Block a user