pcap.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2019
  4. * Ramon Fried <rfried.dev@gmail.com>
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <net.h>
  9. #include <net/pcap.h>
  10. static int do_pcap_init(struct cmd_tbl *cmdtp, int flag, int argc,
  11. char *const argv[])
  12. {
  13. phys_addr_t addr;
  14. unsigned int size;
  15. if (argc != 3)
  16. return CMD_RET_USAGE;
  17. addr = hextoul(argv[1], NULL);
  18. size = dectoul(argv[2], NULL);
  19. return pcap_init(addr, size) ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
  20. }
  21. static int do_pcap_start(struct cmd_tbl *cmdtp, int flag, int argc,
  22. char *const argv[])
  23. {
  24. return pcap_start_stop(true) ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
  25. }
  26. static int do_pcap_stop(struct cmd_tbl *cmdtp, int flag, int argc,
  27. char *const argv[])
  28. {
  29. return pcap_start_stop(false) ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
  30. }
  31. static int do_pcap_status(struct cmd_tbl *cmdtp, int flag, int argc,
  32. char *const argv[])
  33. {
  34. return pcap_print_status() ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
  35. }
  36. static int do_pcap_clear(struct cmd_tbl *cmdtp, int flag, int argc,
  37. char *const argv[])
  38. {
  39. return pcap_clear() ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
  40. }
  41. static char pcap_help_text[] =
  42. "- network packet capture\n\n"
  43. "pcap\n"
  44. "pcap init\t\t\t<addr> <max_size>\n"
  45. "pcap start\t\t\tstart capture\n"
  46. "pcap stop\t\t\tstop capture\n"
  47. "pcap status\t\t\tprint status\n"
  48. "pcap clear\t\t\tclear capture buffer\n"
  49. "\n"
  50. "With:\n"
  51. "\t<addr>: user address to which pcap will be stored (hexedcimal)\n"
  52. "\t<max_size>: Maximum size of pcap file (decimal)\n"
  53. "\n";
  54. U_BOOT_CMD_WITH_SUBCMDS(pcap, "pcap", pcap_help_text,
  55. U_BOOT_SUBCMD_MKENT(init, 3, 0, do_pcap_init),
  56. U_BOOT_SUBCMD_MKENT(start, 1, 0, do_pcap_start),
  57. U_BOOT_SUBCMD_MKENT(stop, 1, 0, do_pcap_stop),
  58. U_BOOT_SUBCMD_MKENT(status, 1, 0, do_pcap_status),
  59. U_BOOT_SUBCMD_MKENT(clear, 1, 0, do_pcap_clear),
  60. );