From 912d24fcd318dfb5b615a2d2857fa7e5611fd5ff Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 2 Jun 2007 11:43:55 +0000 Subject: implement manual override for vendor/machine type git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@2127 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/gsmd.c | 20 ++++++++++++++++---- src/gsmd/machine.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/gsmd/gsmd.c b/src/gsmd/gsmd.c index 12c7c3f..27bf8d9 100644 --- a/src/gsmd/gsmd.c +++ b/src/gsmd/gsmd.c @@ -158,15 +158,17 @@ static struct option opts[] = { { "logfile", 1, NULL, 'l' }, { "hwflow", 0, NULL, 'F' }, { "leak-report", 0, NULL, 'L' }, + { "vendor", 1, NULL, 'v' }, + { "machine", 1, NULL, 'm' }, { 0, 0, 0, 0 } }; static void print_help(void) { - printf("gsmd - (C) 2006 by Harald Welte \n" + printf("gsmd - (C) 2006-2007 by Harald Welte \n" "This program is FREE SOFTWARE under the terms of GNU GPL\n\n" "Usage:\n" - "\t-v\t--version\tDisplay program version\n" + "\t-V\t--version\tDisplay program version\n" "\t-d\t--daemon\tDeamonize\n" "\t-h\t--help\t\tDisplay this help message\n" "\t-p dev\t--device dev\tSpecify serial device to be used\n" @@ -174,6 +176,8 @@ static void print_help(void) "\t-F\t--hwflow\tHardware Flow Control (RTS/CTS)\n" "\t-L\t--leak-report\tLeak Report of talloc memory allocator\n" "\t-l file\t--logfile file\tSpecify a logfile to log to\n" + "\t-v\t--vendor v\tSpecify GSM modem vendor plugin\n" + "\t-m\t--machine m\tSpecify GSM modem machine plugin\n" ); } @@ -200,6 +204,8 @@ int main(int argc, char **argv) int hwflow = 0; char *device = "/dev/ttyUSB0"; char *logfile = "syslog"; + char *vendor_name = NULL; + char *machine_name = NULL; signal(SIGTERM, sig_handler); signal(SIGINT, sig_handler); @@ -209,7 +215,7 @@ int main(int argc, char **argv) gsmd_tallocs = talloc_named_const(NULL, 1, "GSMD"); /*FIXME: parse commandline, set daemonize, device, ... */ - while ((argch = getopt_long(argc, argv, "FVLdhp:s:l:", opts, NULL)) != -1) { + while ((argch = getopt_long(argc, argv, "FVLdhp:s:l:v:m:", opts, NULL)) != -1) { switch (argch) { case 'V': /* FIXME */ @@ -240,6 +246,12 @@ int main(int argc, char **argv) exit(2); } break; + case 'v': + vendor_name = optarg; + break; + case 'm': + machine_name = optarg; + break; } } @@ -261,7 +273,7 @@ int main(int argc, char **argv) exit(1); } - if (gsmd_machine_plugin_init(&g) < 0) { + if (gsmd_machine_plugin_init(&g, machine_name, vendor_name) < 0) { fprintf(stderr, "no machine plugins found\n"); exit(1); } diff --git a/src/gsmd/machine.c b/src/gsmd/machine.c index 40c08cb..8db210b 100644 --- a/src/gsmd/machine.c +++ b/src/gsmd/machine.c @@ -102,11 +102,11 @@ struct machines { { NULL, NULL, NULL }, }; -int gsmd_machine_plugin_init(struct gsmd *g, int fd) +int gsmd_machine_plugin_init(struct gsmd *g, char *machine_name, char *vendor_name) { FILE *cpuinfo; char buf[1024]; - char *line, *machine = NULL; + char *line, *hw = NULL; int i, rc; cpuinfo = fopen("/proc/cpuinfo", "r"); @@ -117,23 +117,46 @@ int gsmd_machine_plugin_init(struct gsmd *g, int fd) line = strtok(buf, "\n"); while (line = strtok(NULL, "\n")) { if (strncmp(line, "Hardware\t: ", 11) == 0) { - machine = line+11; + hw = line+11; break; } } - /* FIXME: do this dynamically */ - for (i = 0; machines[i].cpuinfo; i++) { - if (machine && strcmp(machine, machines[i].cpuinfo) == 0) { - DEBUGP("detected %s\n", machine); - rc = gsmd_machine_plugin_load(machines[i].machine); - rc |= gsmd_vendor_plugin_load(machines[i].vendor); - return rc; + + if (hw) { + /* FIXME: do this dynamically */ + for (i = 0; machines[i].cpuinfo; i++) { + if (strcmp(hw, machines[i].cpuinfo) == 0) { + DEBUGP("detected '%s' hardware\n", hw); + if (machine_name) + DEBUGP("warning: auto-detected machine '%s', " + "but user override to '%s'\n", + machines[i].machine, machine_name); + else + machine_name = machines[i].machine; + + if (vendor_name) + DEBUGP("wanring: auto-detected vendor '%s', " + "but user override to '%s'\m", + machines[i].vendor, vendor_name); + else + vendor_name = machines[i].vendor; + break; + } } } - /* load generic machine and all vendor plugins */ - rc = gsmd_machine_plugin_load("generic"); - gsmd_vendor_plugin_load("ti"); - gsmd_vendor_plugin_load("tihtc"); - gsmd_vendor_plugin_load("qc"); + + if (machine_name) + rc = gsmd_machine_plugin_load(machine_name); + else + rc = gsmd_machine_plugin_load("generic"); + + if (vendor_name) + gsmd_vendor_plugin_load(vendor_name); + else { + gsmd_vendor_plugin_load("ti"); + gsmd_vendor_plugin_load("tihtc"); + gsmd_vendor_plugin_load("qc"); + } + return rc; } -- cgit v1.2.3