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