diff options
Diffstat (limited to 'src/cnetz/main.c')
-rw-r--r-- | src/cnetz/main.c | 122 |
1 files changed, 84 insertions, 38 deletions
diff --git a/src/cnetz/main.c b/src/cnetz/main.c index 77459e1..f3b58c7 100644 --- a/src/cnetz/main.c +++ b/src/cnetz/main.c @@ -24,7 +24,7 @@ #include <errno.h> #include "../libsample/sample.h" #include "../libmobile/main_mobile.h" -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../libmobile/call.h" #include "../anetz/freiton.h" #include "../anetz/besetztton.h" @@ -44,19 +44,20 @@ enum cnetz_chan_type chan_type[MAX_SENDER] = { CHAN_TYPE_OGK_SPK }; int measure_speed = 0; double clock_speed[2] = { 0.0, 0.0 }; int set_clock_speed = 0; -const char *flip_polarity = "auto"; +const char *flip_polarity = ""; int ms_power = 6; /* 1..8 */ int warteschlange = 1; int challenge_valid; uint64_t challenge; int response_valid; uint64_t response; -uint8_t timeslot = 0; +uint32_t timeslots = 4; /* 1 up to 8 */ uint8_t fuz_nat = 1; uint8_t fuz_fuvst = 4; uint8_t fuz_rest = 66; const char *fuz_name = NULL; uint8_t kennung_fufst = 1; /* normal prio */ +uint8_t bahn_bs = 0; /* normal */ uint8_t authentifikationsbit = 0; uint8_t ws_kennung = 0; /* no queue */ uint8_t fuvst_sperren = 0; /* no blocking registration/calls */ @@ -72,9 +73,11 @@ uint8_t reduzierung = 0; /* factor 4 */ uint8_t nachbar_prio = 0; int8_t futln_sperre_start = -1; /* no blocking */ int8_t futln_sperre_end = -1; /* no range */ +int meldeinterval = 120; /* when to ask the phone about beeing alive */ +int meldeaufrufe = 3; /* how many times to ask phone about beeing alive */ enum demod_type demod = FSK_DEMOD_AUTO; int metering = 20; -double speech_deviation = 4000.0; /* best results with all my equipment */ +double speech_deviation = 2400.0; /* best results with older equipment (not C5) */ void print_help(const char *arg0) { @@ -82,6 +85,10 @@ void print_help(const char *arg0) /* - - */ printf(" -T --channel-type <channel type> | list\n"); printf(" Give channel type, use 'list' to get a list. (default = '%s')\n", chan_type_short_name(chan_type[0])); + printf(" You must define at least one OgK at channel 131. This channel may be a\n"); + printf(" a combined OgK+SpK channel, but this works with older phones only.\n"); + printf(" You must define additionally one or more SpK, in order to make calls.\n"); + printf(" You may define alternative OgK, the phones will attach to it then.\n"); printf(" -M --measure-speed\n"); printf(" Measures clock speed. THIS IS REQUIRED! See documentation!\n"); printf(" -C --clock-speed <rx ppm>,<tx ppm>\n"); @@ -95,8 +102,8 @@ void print_help(const char *arg0) printf(" generates a negative signal rather than a positive one. If auto, the\n"); printf(" base station uses double time slots with alternating polarity.\n"); printf(" Once a mobile registers, the correct polarity is selected and used.\n"); - printf(" (default = %s)\n", flip_polarity); - printf(" Note: This has no effect with SDR.\n"); + printf(" (default = %s)\n", (flip_polarity[0]) ? flip_polarity : "auto"); + printf(" Note: Correct polarity is selected for SDR by default.\n"); printf(" -P --ms-power <power level>\n"); printf(" Give power level of the mobile station: 1, 2, 4, 6, 8 (default = '%d')\n", ms_power); printf(" 1 = 7.5-20 W; 2 = 4-8 W; 4 = 0.5-1 W; 6 = 50-125 mW; 8 = 2-10 mW\n"); @@ -115,17 +122,18 @@ void print_help(const char *arg0) printf(" Enable queue support. If no channel is available, calls will be kept\n"); printf(" in a queue for maximum of 60 seconds. (default = %d)\n", warteschlange); printf(" -G --gebuehren <seconds> | 0\n"); - printf(" Increment metering counter every given number of seconds.\n"); + printf(" Increment metering counter every given number of seconds.\n"); printf(" To turn off, use 0. (default = %d)\n", metering); + printf(" If metering pulses are sent via Osmo-CC interface, pulses are always\n"); + printf(" increment metering counter. This overrides this option.\n"); printf(" -V --voice-deviation <2400..4000 Hz>\n"); - printf(" It is unclear what the actual voice deviation is. Please decrease, if\n"); - printf(" mobile's microphone is too loud and speaker is too quiet.\n"); + printf(" It is unclear what the actual voice deviation is. Please increase, if\n"); + printf(" mobile's earpiece is too quiet and the microphone is too loud.\n"); printf(" (default = %.0f)\n", speech_deviation); - printf(" -S --sysinfo timeslot=<0..31>\n"); - printf(" Set time slot of OgK broadcast. There are 32 time slots, but every 8th\n"); - printf(" slot is used. This means if you select time slot 0, also slots 8, 16\n"); - printf(" and 24 will be used. If you select slot 14, also slots 6, 22 and 30\n"); - printf(" will be used. (default = %d)\n", timeslot); + printf(" -S --sysinfo timeslots=1|2|4|8\n"); + printf(" Set number of timeslots of OgK broadcast. There are 32 time slots per\n"); + printf(" frame, but only up to 8 slots can be used, because of processing\n"); + printf(" delay. (default = %d)\n", timeslots); printf(" -S --sysinfo fuz-nat=<nat>\n"); printf(" Set country ID of base station. All IDs were used inside Germany only.\n"); printf(" (default = %d)\n", fuz_nat); @@ -145,6 +153,12 @@ void print_help(const char *arg0) printf(" 2 = Higher priority base station.\n"); printf(" 3 = Highest priority base station.\n"); printf(" Note: Priority has no effect, because there is only one base station.\n"); + printf(" -S --sysinfo bahn-bs=<value>\n"); + printf(" Set special tunnel base station mode for train mobile phones only.\n"); + printf(" (default = %d)\n", kennung_fufst); + printf(" 0 = Disable (every phone is allowed)\n"); + printf(" 1 = Enable (only train phones are allowed)\n"); + printf(" Note: Enableing this will force priority to 0 (Test base station).\n"); printf(" -S --sysinfo auth=<auth>\n"); printf(" Enable authentication flag on the base station. Since we cannot\n"); printf(" authenticate, because we don't know the secret key and the algorithm,\n"); @@ -217,6 +231,12 @@ void print_help(const char *arg0) } else { printf(" (default = %d-%d)\n", futln_sperre_start, futln_sperre_end); } + printf(" -S --sysinfo meldeinterval=<seconds>\n"); + printf(" Time to wait until pinging the phone wether it is still available.\n"); + printf(" (default = %d)\n", meldeinterval); + printf(" -S --sysinfo meldeaufrufe=<count>\n"); + printf(" Number of times we try to ping mobile until we assume it is gone.\n"); + printf(" Use '0' for infinite tries. (default = %d)\n", meldeaufrufe); printf(" -D --demod auto | slope | level\n"); printf(" Adjust demodulation algorithm. Use 'slope' to detect a level change\n"); printf(" by finding the highest slope of a bit transition. It is useful, if\n"); @@ -226,8 +246,7 @@ void print_help(const char *arg0) printf(" requires a DC coupled signal, which is produced by SDR.\n"); printf(" Use 'auto' to select 'slope' for sound card input and 'level' for SDR\n"); printf(" input. (default = '%s')\n", (demod == FSK_DEMOD_LEVEL) ? "level" : (demod == FSK_DEMOD_SLOPE) ? "slope" : "auto"); - printf("\nstation-id: Give 7 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(); printf("Press 'i' key to dump list of currently attached subscribers.\n"); } @@ -347,8 +366,8 @@ static int handle_options(int short_option, int argi, char **argv) return -EINVAL; } p++; - if (!strncasecmp(argv[argi], "timeslot=", p - argv[argi])) { - timeslot = atoi_limit(p, 0, 31); + if (!strncasecmp(argv[argi], "timeslots=", p - argv[argi])) { + timeslots = atoi_limit(p, 1, 8); } else if (!strncasecmp(argv[argi], "fuz-nat=", p - argv[argi])) { fuz_nat = atoi_limit(p, 0, 7); @@ -381,6 +400,9 @@ error_fuz: if (!strncasecmp(argv[argi], "kennung-fufst=", p - argv[argi])) { kennung_fufst = atoi_limit(p, 0, 3); } else + if (!strncasecmp(argv[argi], "bahn-bs=", p - argv[argi])) { + bahn_bs = atoi_limit(p, 0, 1); + } else if (!strncasecmp(argv[argi], "auth=", p - argv[argi])) { authentifikationsbit = atoi_limit(p, 0, 1); } else @@ -434,6 +456,12 @@ error_fuz: futln_sperre_end = atoi(q) & 0xf; } } else + if (!strncasecmp(argv[argi], "meldeinterval=", p - argv[argi])) { + meldeinterval = atoi_limit(p, 1, 20 * 60); + } else + if (!strncasecmp(argv[argi], "meldeaufrufe=", p - argv[argi])) { + meldeaufrufe = atoi_limit(p, 0, 1000000); + } else { fprintf(stderr, "Given sysinfo parameter '%s' unknown, use '-h' for help!\n", argv[argi]); return -EINVAL; @@ -458,10 +486,24 @@ error_fuz: 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; - const char *station_id = ""; + const char *station_id = NULL; int mandatory = 0; int polarity; int teilnehmergruppensperre = 0; @@ -475,7 +517,7 @@ int main(int argc, char *argv[]) init_station(); - main_mobile_init(); + main_mobile_init("0123456789", number_lengths, number_prefixes, cnetz_number_valid); /* handle options / config file */ add_options(); @@ -488,10 +530,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; } /* resolve name of base station */ @@ -510,18 +551,16 @@ int main(int argc, char *argv[]) return -EINVAL; } } - /* set or complete name (in case of prefix was given) */ - fuz_name = get_station_name(fuz_nat, fuz_fuvst, fuz_rest); if (!num_kanal) { - printf("No channel (\"Kanal\") is specified, I suggest channel %d.\n\n", CNETZ_OGK_KANAL); + printf("No channel (\"Kanal\") is specified, I suggest channel %d.\n\n", CNETZ_STD_OGK_KANAL); mandatory = 1; } if (use_sdr) { - /* set audiodev */ + /* set device */ for (i = 0; i < num_kanal; i++) - audiodev[i] = "sdr"; - num_audiodev = num_kanal; + dsp_device[i] = "sdr"; + num_device = num_kanal; /* set channel types for more than 1 channel */ if (num_kanal > 1 && num_chan_type == 0) { chan_type[0] = CHAN_TYPE_OGK; @@ -530,9 +569,9 @@ int main(int argc, char *argv[]) num_chan_type = num_kanal; } } - if (num_kanal == 1 && num_audiodev == 0) - num_audiodev = 1; /* use default */ - if (num_kanal != num_audiodev) { + if (num_kanal == 1 && num_device == 0) + num_device = 1; /* use default */ + if (num_kanal != num_device) { fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); exit(0); } @@ -565,7 +604,13 @@ int main(int argc, char *argv[]) } if (anzahl_gesperrter_teilnehmergruppen) printf("Blocked subscriber with number's last 4 bits from 0x%x to 0x%x\n", teilnehmergruppensperre, (teilnehmergruppensperre + anzahl_gesperrter_teilnehmergruppen - 1) & 0xf); - init_sysinfo(timeslot, fuz_nat, fuz_fuvst, fuz_rest, kennung_fufst, authentifikationsbit, ws_kennung, fuvst_sperren, grenz_einbuchen, grenz_umschalten, grenz_ausloesen, mittel_umschalten, mittel_ausloesen, genauigkeit, bewertung, entfernung, reduzierung, nachbar_prio, teilnehmergruppensperre, anzahl_gesperrter_teilnehmergruppen); + switch(timeslots) { + case 1: timeslots=0x00000001; break; + case 2: timeslots=0x00010001; break; + case 4: timeslots=0x01010101; break; + default: timeslots=0x11111111; + } + init_sysinfo(timeslots, fuz_nat, fuz_fuvst, fuz_rest, kennung_fufst, bahn_bs, authentifikationsbit, ws_kennung, fuvst_sperren, grenz_einbuchen, grenz_umschalten, grenz_ausloesen, mittel_umschalten, mittel_ausloesen, genauigkeit, bewertung, entfernung, reduzierung, nachbar_prio, teilnehmergruppensperre, anzahl_gesperrter_teilnehmergruppen, meldeinterval, meldeaufrufe); dsp_init(); rc = init_telegramm(); if (rc < 0) { @@ -575,7 +620,7 @@ int main(int argc, char *argv[]) init_coding(); cnetz_init(); - /* check for mandatory OgK */ + /* check for mandatory standard OgK */ for (i = 0; i < num_kanal; i++) { if (chan_type[i] == CHAN_TYPE_OGK || chan_type[i] == CHAN_TYPE_OGK_SPK) break; @@ -619,7 +664,7 @@ int main(int argc, char *argv[]) polarity = 1; /* positive */ if (!strcmp(flip_polarity, "yes")) polarity = -1; /* negative */ - if (use_sdr && polarity == 0) + if (use_sdr && !flip_polarity[0]) polarity = 1; /* SDR is always positive */ /* demodulation algorithm */ @@ -635,7 +680,7 @@ int main(int argc, char *argv[]) /* create transceiver instance */ for (i = 0; i < num_kanal; i++) { - rc = cnetz_create(kanal[i], chan_type[i], audiodev[i], use_sdr, demod, samplerate, rx_gain, tx_gain, challenge_valid, challenge, response_valid, response, warteschlange, metering, speech_deviation, ms_power, (i == 0) ? measure_speed : 0, clock_speed, polarity, do_pre_emphasis, do_de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback); + rc = cnetz_create(kanal[i], chan_type[i], dsp_device[i], use_sdr, demod, dsp_samplerate, rx_gain, tx_gain, challenge_valid, challenge, response_valid, response, warteschlange, metering, speech_deviation, ms_power, (i == 0) ? measure_speed : 0, clock_speed, polarity, do_pre_emphasis, do_de_emphasis, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback); if (rc < 0) { fprintf(stderr, "Failed to create \"Sender\" instance. Quitting!\n"); goto fail; @@ -647,7 +692,7 @@ int main(int argc, char *argv[]) } } - main_mobile("cnetz", &quit, latency, interval, NULL, station_id, 7); + main_mobile_loop("cnetz", &quit, NULL, station_id); fail: flush_db(); @@ -657,6 +702,7 @@ fail: cnetz_destroy(sender_head); /* exits */ + main_mobile_exit(); fm_exit(); options_free(); |