Changeset 87b490e3 in mainline
- Timestamp:
- 2024-12-13T08:44:05Z (15 months ago)
- Children:
- 420b13d
- Parents:
- fb31682
- git-author:
- Nataliia Korop <n.corop08@…> (2024-11-30 19:08:32)
- git-committer:
- Nataliia Korop <n.corop08@…> (2024-12-13 08:44:05)
- Location:
- uspace
- Files:
-
- 12 edited
-
app/pcapctl/main.c (modified) (9 diffs)
-
lib/pcap/include/pcap.h (modified) (5 diffs)
-
lib/pcap/include/pcap_dumper.h (modified) (3 diffs)
-
lib/pcap/include/pcapdump_client.h (modified) (2 diffs)
-
lib/pcap/include/pcapdump_drv_iface.h (modified) (1 diff)
-
lib/pcap/include/pcapdump_ipc.h (modified) (1 diff)
-
lib/pcap/include/pcapdump_srv.h (modified) (1 diff)
-
lib/pcap/src/pcap.c (modified) (3 diffs)
-
lib/pcap/src/pcap_dumper.c (modified) (18 diffs)
-
lib/pcap/src/pcapdump_client.c (modified) (9 diffs)
-
lib/pcap/src/pcapdump_drv_iface.c (modified) (3 diffs)
-
lib/pcap/src/pcapdump_srv.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapctl/main.c
rfb31682 r87b490e3 30 30 * @{ 31 31 */ 32 /** @file pcapctl app32 /** @file pcapctl command-line utility. 33 33 */ 34 34 … … 42 42 #include "pcapdump_client.h" 43 43 44 #define NAME "pcapctl" 45 #define DEFAULT_DEV_NUM 0 46 #define DECIMAL_SYSTEM 10 47 48 #define DEFAULT_FILE_OPS 0 49 #define SHORT_FILE_OPS 1 50 #define APPEND_FILE_OPS 2 51 #define USB_FILE_OPS 3 52 44 #define NAME "pcapctl" 45 #define DEFAULT_DEV_NUM 0 46 #define DECIMAL_SYSTEM 10 47 48 /* Default writer operations for dumper, must be consistent with array defined in /uspace/lib/pcap/pcap_dumper.c */ 49 #define DEFAULT_FILE_OPS 0 50 #define SHORT_FILE_OPS 1 51 #define APPEND_FILE_OPS 2 52 #define USB_FILE_OPS 3 53 54 /** Create async session and send start request. 55 * @param dev_number index of the device that can dump packets. 56 * @param name of the output buffer. 57 * @param ops_index index of the writer operations for the dumper. 58 * @return EOK if all parameters are valid and start request was sent successfully, error code otherwise. 59 */ 53 60 static errno_t start_dumping(int *dev_number, const char *name, int *ops_index) 54 61 { … … 77 84 } 78 85 86 /** Create async session and send stop dumping request. 87 * @param dev_numbe index of the device on which the dumping will be stopped. 88 * @return EOK if request was sent successfully, error code otherwise. 89 */ 79 90 static errno_t stop_dumping(int *dev_number) 80 91 { … … 92 103 } 93 104 105 /** Print devices that can dump packets. */ 94 106 static void list_devs(void) 95 107 { … … 101 113 */ 102 114 static const struct option opts[] = { 103 { "append", required_argument, 0, 'A' }, / / file as argument and ops 0 if not exist and 2 if exists104 { "new", required_argument, 0, 'N' }, / / file name as argument115 { "append", required_argument, 0, 'A' }, /* file as argument and ops 0 if not exist and 2 if exists */ 116 { "new", required_argument, 0, 'N' }, /* file name as argument */ 105 117 { "truncated", required_argument, 0, 'T' }, // truncated ops 106 118 { "usb", required_argument, 0, 'U' }, //?? … … 116 128 }; 117 129 130 /** Check if the file exists. 131 * @param path of the file to check. 132 * @return true if exists, false otherwise. 133 */ 118 134 static bool file_exists(const char *path) 119 135 { … … 128 144 static void usage(void) 129 145 { 130 printf("Usage:\n" 146 printf("HelenOS Packet Dumping utility.\n" 147 "Usage:\n" 131 148 NAME " --list | -l \n" 132 149 "\tList of devices\n" … … 218 235 } 219 236 220 printf("%s: HelenOS Packet Dumping utility: device - %d, ops - %d.\n", NAME, dev_number, ops_number);221 222 237 if (start) { 223 238 … … 227 242 } 228 243 244 printf("Sarting dumping on device - %d, ops - %d.\n", dev_number, ops_number); 245 229 246 /* start with dev number and name */ 230 247 start_dumping(&dev_number, output_file_name, &ops_number); 231 248 } else if (stop) { 232 249 /* stop with dev number */ 250 printf("Stopping dumping on device - %d, ops - %d.\n", dev_number, ops_number); 233 251 stop_dumping(&dev_number); 234 252 } else { -
uspace/lib/pcap/include/pcap.h
rfb31682 r87b490e3 33 33 /** 34 34 * @file 35 * @brief Headers and functions for .pcap file and packets to be dumped35 * @brief Headers and functions for PCAP format and packets to be dumped. 36 36 */ 37 37 … … 46 46 #include <errno.h> 47 47 48 #define PCAP_MAGIC_MICRO 0xA1B2C3D4 49 #define PCAP_MAGIC_NANO 0xA1B23C4D 50 #define PCAP_MAJOR_VERSION 0x0002 51 #define PCAP_MINOR_VERSION 0x0004 52 #define PCAP_SNAP_LEN 0x00040000 48 #define PCAP_MAGIC_MICRO 0xA1B2C3D4 /** Sets time in seconds and microseconds in packet records. */ 49 #define PCAP_MAGIC_NANO 0xA1B23C4D /** Sets time in seconds and nanoseconds in packet records. */ 50 #define PCAP_MAJOR_VERSION 0x0002 /** Major version of the PCAP format. */ 51 #define PCAP_MINOR_VERSION 0x0004 /** Miner version of the PCAP format. */ 52 #define PCAP_SNAP_LEN 0x00040000 /** Maximum number of bytes that can be captured for one packet record. */ 53 53 54 54 #define PCAP_LINKTYPE_ETHERNET 1 /* IEEE 802.3 Ethernet */ … … 56 56 #define PCAP_LINKTYPE_IEEE802_11_RADIO 127 57 57 #define PCAP_LINKTYPE_USB_LINUX_MMAPPED 220 58 #define WIRESHARK_EX 0xc59 #define WIRESHARK_SNAPLEN 0xffff60 58 61 59 /** Header of the .pcap file. */ … … 80 78 typedef struct pcap_writer pcap_writer_t; 81 79 82 /** Operations for dumper. */80 /** Writing operations for destination buffer. */ 83 81 typedef struct { 84 82 errno_t (*open)(pcap_writer_t *, const char *); … … 89 87 } pcap_writer_ops_t; 90 88 91 /** Interface for working with .pcap file. */89 /** Structure for writing data to the destination buffer. */ 92 90 struct pcap_writer { 91 /** Writing buffer. */ 93 92 void *data; 93 /** Writing operations for working with the buffer. */ 94 94 pcap_writer_ops_t *ops; 95 95 }; -
uspace/lib/pcap/include/pcap_dumper.h
rfb31682 r87b490e3 30 30 * @{ 31 31 */ 32 /** @file pcap interface32 /** @file Pcap dumper. Structure is a part of every device that is in category PCAP and can dump packets. 33 33 */ 34 34 … … 40 40 #include "pcap.h" 41 41 42 /** Packet dumper structure that is responsible for dumping packets. */ 42 43 typedef struct pcap_dumper { 43 44 fibril_mutex_t mutex; 45 /** Flag that indicates, whether the packet should be dumped or ignored. */ 44 46 bool to_dump; 47 /** Writer structure that is responsible for writing data to the destination buffer. */ 45 48 pcap_writer_t writer; 46 49 } pcap_dumper_t; … … 53 56 54 57 #endif 58 55 59 /** @} 56 60 */ -
uspace/lib/pcap/include/pcapdump_client.h
rfb31682 r87b490e3 32 32 */ 33 33 /** 34 * @file 34 * @file Client side of the IPC communication for pcapctl. 35 35 * 36 36 */ … … 45 45 #include <fibril_synch.h> 46 46 47 /** IPC session structure for pcapctl utility. */ 47 48 typedef struct { 48 49 async_sess_t *sess; -
uspace/lib/pcap/include/pcapdump_drv_iface.h
rfb31682 r87b490e3 32 32 */ 33 33 /** 34 * @file 34 * @file Driver interface. Functions that are used in drivers that can dump packets. 35 35 * 36 36 */ -
uspace/lib/pcap/include/pcapdump_ipc.h
rfb31682 r87b490e3 41 41 #include <ipc/common.h> 42 42 43 /** IPC requests for INTERFACE_PCAP_CONTROL interface. */ 43 44 typedef enum { 44 45 PCAP_CONTROL_SET_START = IPC_FIRST_USER_METHOD, -
uspace/lib/pcap/include/pcapdump_srv.h
rfb31682 r87b490e3 32 32 */ 33 33 /** 34 * @file 34 * @file Server side of the IPC communication for dumping packets framework. 35 35 * 36 36 */ -
uspace/lib/pcap/src/pcap.c
rfb31682 r87b490e3 1 1 /* 2 * Copyright (c) 202 3Nataliia Korop2 * Copyright (c) 2024 Nataliia Korop 3 3 * All rights reserved. 4 4 * … … 53 53 /** Add pcap file header to the new .pcap file. 54 54 * 55 * @param writer writer that has destination buffer and ops to write to destination buffer. 56 * 55 * @param writer Writer that has destination buffer and ops to write to destination buffer. 56 * @param linktype Linktype for the file header. 57 * @param nano True for nanoseconds, false for microseconds in timestamp. 57 58 */ 58 59 void pcap_writer_add_header(pcap_writer_t *writer, uint32_t linktype, bool nano) … … 69 70 /** Add packet to the .pcap file. 70 71 * 71 * @param writer 72 * @param captured_packet Packet to be dumped73 * @param size Size of the captured packet72 * @param writer Writer that has destination buffer and ops to write to destination buffer. 73 * @param captured_packet Packet to be dumped 74 * @param size Size of the captured packet 74 75 * 75 76 */ -
uspace/lib/pcap/src/pcap_dumper.c
rfb31682 r87b490e3 30 30 * @{ 31 31 */ 32 /** @file 33 * @brief pcap inteface: Dumping interface for the device which packets we want to dump 32 /** @file Pcap dumper. Structure is a part of every device that is in category PCAP and can dump packets. 34 33 */ 35 34 … … 43 42 /** Initialize writing to .pcap file. 44 43 * 45 * @param writer Interface for w orking with .pcap file.44 * @param writer Interface for writing data. 46 45 * @param filename Name of the file for dumping packets. 47 * @return EOK on success oran error code.46 * @return EOK on success, otherwise an error code. 48 47 * 49 48 */ … … 66 65 } 67 66 67 /** Open file for appending to the end of it. 68 * @param writer Interface for writing data. 69 * @param filename Path to the file. 70 * @return EOK on success, error code otherwise. 71 */ 68 72 static errno_t pcap_writer_to_file_init_append(pcap_writer_t *writer, const char *filename) 69 73 { … … 76 80 } 77 81 82 /** Initialize file for dumping usb packets. 83 * @param writer Interface for writing data. 84 * @param filename Path to the file. 85 * @return EOK on success, error code otherwise. 86 */ 78 87 static errno_t pcap_writer_to_file_usb_init(pcap_writer_t *writer, const char *filename) 79 88 { … … 94 103 } 95 104 105 /** Write 4B to the file. 106 * @param writer Interface for writing data. 107 * @param data Bytes to write. 108 * @return Size of successfully witten data. 109 */ 96 110 static size_t pcap_file_w32(pcap_writer_t *writer, uint32_t data) 97 111 { … … 99 113 } 100 114 115 /** Write 2B to the file. 116 * @param writer Interface for writing data. 117 * @param data Bytes to write. 118 * @return Size of successfully witten data. 119 */ 101 120 static size_t pcap_file_w16(pcap_writer_t *writer, uint16_t data) 102 121 { … … 104 123 } 105 124 125 /** Write block of bytes to the file. 126 * @param writer Interface for writing data. 127 * @param data Bytes to write. 128 * @param size Size of block of bytes. 129 * @return Size of successfully witten data. 130 */ 106 131 static size_t pcap_file_wbuffer(pcap_writer_t *writer, const void *data, size_t size) 107 132 { … … 110 135 } 111 136 137 /** Close file for writing. 138 * @param writer Interaface for writing data. 139 */ 112 140 static void pcap_file_close(pcap_writer_t *writer) 113 141 { … … 116 144 } 117 145 146 /** Write <= 60B of block of bytes. 147 * @param writer Interface for writing data. 148 * @param data Bytes to write. 149 * @param size Size of block of bytes. 150 * @return Size of successfully witten data. 151 */ 118 152 static size_t pcap_short_file_wbuffer(pcap_writer_t *writer, const void *data, size_t size) 119 153 { … … 121 155 } 122 156 157 /** Standard writer operations for writing data to a newly created file. */ 123 158 static const pcap_writer_ops_t file_ops = { 124 159 .open = &pcap_writer_to_file_init, … … 129 164 }; 130 165 166 /** Truncated writer operations. Only first 60 bytes of the packet are written. */ 131 167 static const pcap_writer_ops_t short_file_ops = { 132 168 .open = &pcap_writer_to_file_init, … … 138 174 }; 139 175 176 /** Append writer operations. Instead of creating new file open existing file and append packets. */ 140 177 static const pcap_writer_ops_t append_file_ops = { 141 178 .open = &pcap_writer_to_file_init_append, … … 146 183 }; 147 184 185 /** USB writer operations. Writing USB packets to the file. */ 148 186 static const pcap_writer_ops_t usb_file_ops = { 149 187 .open = &pcap_writer_to_file_usb_init, … … 154 192 }; 155 193 194 /** Default array of operations. Must be consistens with constants in /uspace/app/pcapctl/main.c */ 156 195 static pcap_writer_ops_t ops[4] = { file_ops, short_file_ops, append_file_ops, usb_file_ops }; 157 196 197 /** Get number of writer operations in @ref ops */ 158 198 int pcap_dumper_get_ops_number(void) 159 199 { … … 161 201 } 162 202 203 /** Open destination buffer for writing and set flag for dumping. 204 * @param dumper Structure responsible for dumping packets. Part of the driver. 205 * @param name Name of the destination buffer to dump packets to. 206 * @return EOK if successful, erro code otherwise. 207 */ 163 208 errno_t pcap_dumper_start(pcap_dumper_t *dumper, const char *name) 164 209 { … … 174 219 } 175 220 221 /** Set writer options for the writer. 222 * @param dumper Structure responsible for dumping packets. Part of the driver. 223 * @param index Index of the writer operations from array @ref ops. 224 * @return EOK if successful, erro code otherwise. 225 */ 176 226 errno_t pcap_dumper_set_ops(pcap_dumper_t *dumper, int index) 177 227 { … … 183 233 } 184 234 235 /** Write packet to destination buffer. 236 * @param dumper Structure responsible for dumping packets. Part of the driver. 237 * @param data Packet data to write. 238 * @param size Size of the packet. 239 */ 185 240 void pcap_dumper_add_packet(pcap_dumper_t *dumper, const void *data, size_t size) 186 241 { … … 196 251 } 197 252 253 /** Close destination buffer for writing and unset flag for dumping. 254 * @param dumper Structure responsible for dumping packets. Part of the driver. 255 */ 198 256 void pcap_dumper_stop(pcap_dumper_t *dumper) 199 257 { -
uspace/lib/pcap/src/pcapdump_client.c
rfb31682 r87b490e3 30 30 * @{ 31 31 */ 32 /** @file 33 * @brief Client side of the pcapctl. Functions are called from the app pcapctl 32 /** @file Client side of the pcapctl. Functions are called from the app pcapctl. 34 33 */ 35 34 … … 52 51 } 53 52 53 /** Get service based on the index of the device. 54 * @param index of the device. 55 * @param svc placeholder for service ide. 56 * @return EOK if successful, error code otherwise. 57 */ 54 58 static errno_t pcapctl_cat_get_svc(int *index, service_id_t *svc) 55 59 { … … 80 84 } 81 85 86 /** Check if the index is an index of valid device. 87 * @param index to check. 88 * @return EOK if device is valid, error code otherwise. 89 */ 82 90 errno_t pcapctl_is_valid_device(int *index) 83 91 { … … 105 113 } 106 114 115 /** Check if the index is an index of valid writer operations. 116 * @param index to check. 117 * @param sess pcapctl session for IPC communictaion. 118 */ 107 119 errno_t pcapctl_is_valid_ops_number(int *index, pcapctl_sess_t *sess) 108 120 { … … 127 139 } 128 140 129 /** 130 * 131 */ 141 /** Get all devices that can dump packets. */ 132 142 errno_t pcapctl_list(void) 133 143 { … … 160 170 } 161 171 162 /** 163 * 172 /** Start pcapctl IPC session. 173 * @param index index of the device which can dump packets. 174 * @param rsess placeholder for the session. 175 * @return EOK if successful, error code otherwise. 164 176 */ 165 177 errno_t pcapctl_dump_open(int *index, pcapctl_sess_t **rsess) … … 196 208 } 197 209 198 /** 199 * 210 /** Close pcapctl IPC session. 211 * @param sess Session to close. 212 * @return EOK if successful, error code otherwise. 200 213 */ 201 214 errno_t pcapctl_dump_close(pcapctl_sess_t *sess) … … 205 218 } 206 219 207 /** S tarting a new session for pcapctl208 * 209 * @param name Name of the file to dump packets to210 * @param sess session to start211 * @return EOK on success or an error code220 /** Send start request via IPC to start dumping. 221 * 222 * @param name Name of the destination buffer to dump packets to. 223 * @param sess Session that is used for communication. 224 * @return EOK on success or an error code. 212 225 */ 213 226 errno_t pcapctl_dump_start(const char *name, int *ops_index, pcapctl_sess_t *sess) … … 233 246 } 234 247 235 /** Finish current session for pcapctl236 * 237 * @param sess Session to finish238 * @return EOK on success or an error code248 /** Send stop request via IPC to start dumping. 249 * 250 * @param sess Session that is used for communication. 251 * @return EOK on success or an error code. 239 252 */ 240 253 errno_t pcapctl_dump_stop(pcapctl_sess_t *sess) -
uspace/lib/pcap/src/pcapdump_drv_iface.c
rfb31682 r87b490e3 48 48 #define NAME "pcap" 49 49 50 /** Initialize interface for dumping packets 51 * 52 * @param dumper Device dumping interface 53 * 50 /** Initialize interface for dumping packets. 51 * @param dumper Device dumping interface. 52 * @return EOK if successful, error code otherwise. 54 53 */ 55 54 static errno_t pcapdump_drv_dumper_init(pcap_dumper_t *dumper) … … 67 66 } 68 67 68 /** Initialize driver dumping functionality. 69 * @param dumper Dumping interface of the driver. 70 * @return EOK if successful, error code otherwise. 71 */ 69 72 errno_t pcapdump_init(pcap_dumper_t *dumper) 70 73 { … … 86 89 } 87 90 88 /** Dumping function for driver 91 /** Dumping function for driver. 89 92 * 90 * Called every time, the packet is sent/recieved by the device 93 * Called every time, the packet is sent/recieved by the device. 91 94 * 92 * @param dumper Dumping interface93 * @param data The packet94 * @param size Size of the packet95 * @param dumper Dumping interface. 96 * @param data The packet 97 * @param size Size of the packet. 95 98 * 96 99 */ -
uspace/lib/pcap/src/pcapdump_srv.c
rfb31682 r87b490e3 47 47 #include "pcapdump_ipc.h" 48 48 49 /** Start dumping. 50 * @param icall IPC call with request to start. 51 * @param dumper Dumping interface of the driver. 52 */ 49 53 static void pcapdump_start_srv(ipc_call_t *icall, pcap_dumper_t *dumper) 50 54 { … … 84 88 } 85 89 90 /** Stop dumping 91 * @param icall IPC call with request to stop. 92 * @param dumper Dumping interface of the driver. 93 */ 86 94 static void pcapdump_stop_srv(ipc_call_t *icall, pcap_dumper_t *dumper) 87 95 { … … 90 98 } 91 99 100 /** Get number of accessibke writer operations. 101 * @param icall IPC call with request to get number of accessible writer operations. 102 */ 92 103 static void pcapdump_get_ops_num_srv(ipc_call_t *icall) 93 104 { … … 99 110 } 100 111 112 /** Callback connection function. Accepts requests and processes them. 113 * @param icall IPC call with request. 114 * @param arg Dumping interface of the driver. 115 */ 101 116 void pcapdump_conn(ipc_call_t *icall, void *arg) 102 117 {
Note:
See TracChangeset
for help on using the changeset viewer.
