2007-04-23 10:23:40 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include "context.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "serial.h"
|
|
|
|
|
|
|
|
static struct option opts[] = {
|
2007-05-02 21:52:00 +02:00
|
|
|
{"config", 1, 0, 'c'},
|
2007-05-02 20:32:36 +02:00
|
|
|
{"device", 1, 0, 'd'},
|
2007-05-02 21:52:00 +02:00
|
|
|
{"firmware", 1, 0, 'f'},
|
|
|
|
{"slow", 0, 0, 's'},
|
2007-04-23 10:23:40 +02:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2007-05-02 20:32:36 +02:00
|
|
|
char *devicename = NULL, *filename = NULL;
|
2007-05-02 21:52:00 +02:00
|
|
|
int code, arg = 0, flags = FLAG_SPEEDUP;
|
2007-04-23 10:23:40 +02:00
|
|
|
|
|
|
|
do {
|
2007-05-02 21:52:00 +02:00
|
|
|
code = getopt_long(argc, argv, "c:d:f:s", opts, &arg);
|
2007-04-23 10:23:40 +02:00
|
|
|
|
|
|
|
switch (code) {
|
2007-05-02 21:52:00 +02:00
|
|
|
case 'c': filename = optarg;
|
|
|
|
flags |= FLAG_CONFIG;
|
|
|
|
break;
|
|
|
|
|
2007-05-02 20:32:36 +02:00
|
|
|
case 'd': devicename = optarg;
|
2007-04-23 10:23:40 +02:00
|
|
|
break;
|
|
|
|
|
2007-05-02 20:32:36 +02:00
|
|
|
case 'f': filename = optarg;
|
2007-05-02 21:52:00 +02:00
|
|
|
flags |= FLAG_FIRMWARE;
|
2007-04-23 10:23:40 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h': /* help */
|
2007-05-02 21:52:00 +02:00
|
|
|
printf("Usage: zyxel-revert -d <device> [-s] [ -f <file> | -c <file> ]\n");
|
2007-04-23 10:23:40 +02:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
|
2007-05-02 21:52:00 +02:00
|
|
|
case 's': flags &= ~FLAG_SPEEDUP;
|
|
|
|
break;
|
|
|
|
|
2007-04-23 10:23:40 +02:00
|
|
|
case '?': /* error */
|
|
|
|
exit(-1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* unknown / all options parsed */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (code != -1);
|
|
|
|
|
2007-05-02 21:52:00 +02:00
|
|
|
if (devicename == NULL || filename == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2007-05-02 20:42:12 +02:00
|
|
|
struct context *ctx = create_context(filename);
|
|
|
|
if (ctx == NULL)
|
2007-04-23 10:23:40 +02:00
|
|
|
exit(1);
|
|
|
|
|
2007-05-02 21:52:00 +02:00
|
|
|
ctx->flags = flags;
|
|
|
|
|
|
|
|
if (serial_init(ctx, devicename)) {
|
2007-04-23 10:23:40 +02:00
|
|
|
context_close();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_loop();
|
|
|
|
|
|
|
|
context_close();
|
|
|
|
return 0;
|
|
|
|
}
|