diff options
Diffstat (limited to 'src/sim/main.c')
-rw-r--r-- | src/sim/main.c | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/sim/main.c b/src/sim/main.c index 17ebb32..147967a 100644 --- a/src/sim/main.c +++ b/src/sim/main.c @@ -30,10 +30,11 @@ #include <unistd.h> #include <inttypes.h> #include <sys/time.h> -#include "../libdebug/debug.h" +#include "../liblogging/logging.h" #include "../liboptions/options.h" #include "../libserial/serial.h" -#include "../libmobile/image.h" +#include "../libaaimage/aaimage.h" +#include <osmocom/cc/misc.h> #include "sim.h" #include "sniffer.h" #include "eeprom.h" @@ -62,7 +63,7 @@ static const char *auth = NULL; #define TIMEOUT 0.2 -void print_help(const char *arg0) +static void print_help(const char *arg0) { printf("Usage: %s [options] <command>\n", arg0); /* - - */ @@ -72,11 +73,7 @@ void print_help(const char *arg0) printf(" --config [~/]<path to config file>\n"); printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n"); printf(" Each line in config file is one option, '-' or '--' must not be given!\n"); - printf(" -v --verbose <level> | <level>,<category>[,<category>[,...]] | list\n"); - printf(" Use 'list' to get a list of all levels and categories\n"); - printf(" Verbose level: digit of debug level (default = '%d')\n", debuglevel); - printf(" Verbose level+category: level digit followed by one or more categories\n"); - printf(" -> If no category is specified, all categories are selected\n"); + logging_print_help(); printf(" -s --serial-device <device>\n"); printf(" Serial device (default = '%s')\n", serialdev); printf(" -b --baud-rate <baud>\n"); @@ -117,7 +114,7 @@ void print_help(const char *arg0) #define OPT_SONDER 258 #define OPT_WARTUNG 259 -void add_options(void) +static void add_options(void) { option_add('h', "help", 0); option_add('v', "debug", 1); @@ -135,7 +132,7 @@ void add_options(void) option_add('A', "auth", 1); }; -int handle_options(int short_option, int argi, char **argv) +static int handle_options(int short_option, int argi, char **argv) { int rc; @@ -144,13 +141,11 @@ int handle_options(int short_option, int argi, char **argv) print_help(argv[0]); return 0; case 'v': - if (!strcasecmp(argv[argi], "list")) { - debug_list_cat(); + rc = parse_logging_opt(argv[argi]); + if (rc > 0) return 0; - } - rc = parse_debug_opt(argv[argi]); if (rc < 0) { - fprintf(stderr, "Failed to parse debug option, please use -h for help.\n"); + fprintf(stderr, "Failed to parse logging option, please use -h for help.\n"); return rc; } break; @@ -234,7 +229,7 @@ size_t eeprom_length(void) /* main loop for interfacing serial with sim / sniffer */ -int main_loop(serial_t *serial, int sniffer) +static int main_loop(serial_t *serial, int sniffer) { int rc, cts = 0, last_cts = 0; uint8_t byte; @@ -318,7 +313,7 @@ int main_loop(serial_t *serial, int sniffer) return quit; } -void sighandler(int sigset) +static void sighandler(int sigset) { if (sigset == SIGHUP) return; @@ -341,7 +336,8 @@ int main(int argc, char *argv[]) int sniffer = 0; int i; - debuglevel = DEBUG_INFO; + loglevel = LOGL_INFO; + logging_init(); add_options(); rc = options_config_file(argc, argv, "~/.osmocom/analog/sim.conf", handle_options); @@ -370,13 +366,13 @@ int main(int argc, char *argv[]) rc = fread(eeprom_memory(), eeprom_length(), 1, fp); fclose(fp); } else - PDEBUG(DOPTIONS, DEBUG_INFO, "EEPROM file '%s' does not exist yet.\n", eeprom_file); + LOGP(DOPTIONS, LOGL_INFO, "EEPROM file '%s' does not exist yet.\n", eeprom_file); } /* check version */ if (eeprom_read(EEPROM_MAGIC + 0) != 'C' || eeprom_read(EEPROM_MAGIC + 1) != '0' + EEPROM_VERSION) { - PDEBUG(DOPTIONS, DEBUG_ERROR, "EEPROM file '%s' is not compatible with this version of program, please remove it!\n", eeprom_file); + LOGP(DOPTIONS, LOGL_ERROR, "EEPROM file '%s' is not compatible with this version of program, please remove it!\n", eeprom_file); return 1; } @@ -404,7 +400,7 @@ int main(int argc, char *argv[]) eeprom_write(EEPROM_WARTUNG_L, ebdt_data[8]); if (pin) { if (strlen(pin) < 4 || strlen(pin) > 8) { - PDEBUG(DSIM7, DEBUG_NOTICE, "Given PIN '%s' has invalid length. (Must be 4 .. 8)\n", pin); + LOGP(DSIM7, LOGL_NOTICE, "Given PIN '%s' has invalid length. (Must be 4 .. 8)\n", pin); return 0; } eeprom_write(EEPROM_FLAGS, (strlen(pin) << EEPROM_FLAG_PIN_LEN) | (MAX_PIN_TRY << EEPROM_FLAG_PIN_TRY)); @@ -449,7 +445,7 @@ int main(int argc, char *argv[]) printf("SIM analyzer ready, please start the phone!\n"); else { char temp[5][16]; - print_image(); + print_aaimage(); decode_ebdt(ebdt_data, temp[0], temp[1], temp[2], temp[3], temp[4]); printf("FUTLN=%s, Sicherungscode=%s, Kartekennung=%s, Sonderheitenschluessel=%s, Wartungsschluessel=%s\n", temp[0], temp[1], temp[2], temp[3], temp[4]); for (i = 0; i < 8; i++) @@ -492,9 +488,9 @@ int main(int argc, char *argv[]) if (fp) { fwrite(eeprom_memory(), eeprom_length(), 1, fp); fclose(fp); - PDEBUG(DOPTIONS, DEBUG_INFO, "EEPROM file '%s' written.\n", eeprom_file); + LOGP(DOPTIONS, LOGL_INFO, "EEPROM file '%s' written.\n", eeprom_file); } else - PDEBUG(DOPTIONS, DEBUG_INFO, "EEPROM file '%s' cannot be written. (errno = %d)\n", eeprom_file, errno); + LOGP(DOPTIONS, LOGL_INFO, "EEPROM file '%s' cannot be written. (errno = %d)\n", eeprom_file, errno); } error: @@ -506,4 +502,6 @@ error: return 0; } +void osmo_cc_set_log_cat(int __attribute__((unused)) cc_log_cat) {} + #endif /* ARDUINO */ |