Ignore:
Timestamp:
2024-12-13T08:44:05Z (15 months ago)
Author:
Nataliia Korop <n.corop08@…>
Children:
f08447b
Parents:
59fe16d
git-author:
Nataliia Korop <n.corop08@…> (2024-10-28 09:57:08)
git-committer:
Nataliia Korop <n.corop08@…> (2024-12-13 08:44:05)
Message:

refactoring after 23.10

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcap/src/pcapdump_iface.c

    r59fe16d r03cd7a9e  
    3838#include <async.h>
    3939#include <errno.h>
     40#include <stdlib.h>
    4041#include <fibril_synch.h>
     42#include <str.h>
    4143
    4244#include "pcapdump_iface.h"
    4345
    44 FIBRIL_MUTEX_INITIALIZE(to_dump_mutex);
    45 
    46 static void pcapdump_start_srv(ipc_call_t *icall, pcap_iface_t *iface)
     46static void pcapdump_start_srv(ipc_call_t *icall, pcap_dumper_t *dumper)
    4747{
    4848        char *data;
    4949        size_t size;
    50         errno_t rc = async_data_write_accept((void **) &data, false, 0, 0, 0, &size);
     50        errno_t rc = async_data_write_accept((void **) &data, true, 0, 0, 0, &size);
    5151        if (rc != EOK) {
    5252                async_answer_0(icall, rc);
     
    5454        }
    5555
    56         /** When try to start when already started, close current and starts new */
    57         if (iface->to_dump == true) {
    58                 iface->fini();
     56        assert(str_length(data) == size && "Data were damaged during transmission.\n");
     57
     58        rc = pcap_dumper_start(dumper, (const char *)data);
     59        free(data);
     60        if (rc != EOK)
     61        {
     62                //TODO what?
    5963        }
    60         iface->init((const char *)data);
    61 
    62         fibril_mutex_lock(&to_dump_mutex);
    63         iface->to_dump = true;
    64         fibril_mutex_unlock(&to_dump_mutex);
    65 
    66         async_answer_0(icall, rc);
     64        async_answer_0(icall, EOK);
    6765}
    6866
    69 static void pcapdump_stop_srv(ipc_call_t *icall, pcap_iface_t *iface)
     67static void pcapdump_stop_srv(ipc_call_t *icall, pcap_dumper_t *dumper)
    7068{
    71         /** If want to stop, when already stopped, do nothing */
    72         if (iface->to_dump == false) {
    73                 async_answer_0(icall, EOK);
    74                 return;
    75         }
    76 
    77         fibril_mutex_lock(&to_dump_mutex);
    78         iface->to_dump = false;
    79         fibril_mutex_unlock(&to_dump_mutex);
    80 
    81         iface->fini();
     69        pcap_dumper_stop(dumper);
    8270        async_answer_0(icall, EOK);
    8371}
     
    8573void pcapdump_conn(ipc_call_t *icall, void *arg)
    8674{
    87         pcap_iface_t *iface = (pcap_iface_t *)arg;
    88         printf("pcapdump_conn\n");
    89         assert((iface != NULL) && "pcapdump requires pcap interface\n");
     75        pcap_dumper_t *dumper = (pcap_dumper_t *)arg;
     76
     77        assert((dumper != NULL) && "pcapdump requires pcap dumper\n");
    9078
    9179        /* Accept connection */
     
    10391                switch (method) {
    10492                case PCAP_CONTROL_SET_START:
    105                         pcapdump_start_srv(&call, iface);
     93                        pcapdump_start_srv(&call, dumper);
    10694                        break;
    10795                case PCAP_CONTROL_SET_STOP:
    108                         pcapdump_stop_srv(&call, iface);
     96                        pcapdump_stop_srv(&call, dumper);
    10997                        break;
    11098                default:
     
    115103}
    116104
    117 errno_t pcapdump_init(pcap_iface_t *iface)
     105errno_t pcapdump_init(pcap_dumper_t *dumper)
    118106{
    119107        port_id_t port;
    120108        errno_t rc;
    121109
    122         rc = pcap_iface_init(iface);
     110        rc = pcap_dumper_init(dumper);
    123111
    124112        if (rc != EOK) {
     
    128116
    129117        rc = async_create_port(INTERFACE_PCAP_CONTROL,
    130             pcapdump_conn, iface, &port);
     118            pcapdump_conn, dumper, &port);
    131119        if (rc != EOK) {
    132120                return rc;
     
    139127 * Called every time, the packet is sent/recieved by the device
    140128 *
    141  * @param iface Dumping interface
     129 * @param dumper Dumping interface
    142130 * @param data The packet
    143131 * @param size Size of the packet
    144132 *
    145133 */
    146 void pcapdump_packet(pcap_iface_t *iface, const void *data, size_t size)
     134void pcapdump_packet(pcap_dumper_t *dumper, const void *data, size_t size)
    147135{
    148136
    149         if (iface == NULL) {
     137        if (dumper == NULL) {
    150138                return;
    151139        }
    152140
    153         if (!iface->to_dump) {
    154                 return;
    155         }
    156 
    157         iface->add_packet(data, size);
     141        pcap_dumper_add_packet(dumper, data, size);
    158142}
    159143
Note: See TracChangeset for help on using the changeset viewer.