Blame view

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