ES-2024 reverter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.3KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <getopt.h>
  6. #include "context.h"
  7. #include "event.h"
  8. #include "serial.h"
  9. static struct option opts[] = {
  10. {"config", 1, 0, 'c'},
  11. {"device", 1, 0, 'd'},
  12. {"firmware", 1, 0, 'f'},
  13. {"slow", 0, 0, 's'},
  14. {0, 0, 0, 0}
  15. };
  16. int main(int argc, char *argv[])
  17. {
  18. char *devicename = NULL, *filename = NULL;
  19. int code, arg = 0, flags = FLAG_SPEEDUP;
  20. do {
  21. code = getopt_long(argc, argv, "c:d:f:s", opts, &arg);
  22. switch (code) {
  23. case 'c': filename = optarg;
  24. flags |= FLAG_CONFIG;
  25. break;
  26. case 'd': devicename = optarg;
  27. break;
  28. case 'f': filename = optarg;
  29. flags |= FLAG_FIRMWARE;
  30. break;
  31. case 'h': /* help */
  32. printf("Usage: zyxel-revert -d <device> [-s] [ -f <file> | -c <file> ]\n");
  33. exit(0);
  34. break;
  35. case 's': flags &= ~FLAG_SPEEDUP;
  36. break;
  37. case '?': /* error */
  38. exit(-1);
  39. break;
  40. default: /* unknown / all options parsed */
  41. break;
  42. }
  43. } while (code != -1);
  44. if (devicename == NULL || filename == NULL)
  45. return -1;
  46. struct context *ctx = create_context(filename);
  47. if (ctx == NULL)
  48. exit(1);
  49. ctx->flags = flags;
  50. if (serial_init(ctx, devicename)) {
  51. context_close();
  52. exit(1);
  53. }
  54. event_loop();
  55. context_close();
  56. return 0;
  57. }