Changeset 87b490e3 in mainline for uspace/lib/pcap/src
- Timestamp:
- 2024-12-13T08:44:05Z (10 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/lib/pcap/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
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.