From 80bb5a41e46144ce1f5015f7b85124164dddd250 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 23 Nov 2014 17:16:44 +0200 Subject: [PATCH] uaenet.device slirp support fix. --- a2065.cpp | 9 ++++++--- ethernet.cpp | 17 ++++++++++++----- include/ethernet.h | 6 +++--- od-win32/win32_uaenet.h | 4 ++-- sana2.cpp | 13 ++++++++----- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/a2065.cpp b/a2065.cpp index 1cde6348..0e0b78d0 100644 --- a/a2065.cpp +++ b/a2065.cpp @@ -264,7 +264,7 @@ static int mcfilter (const uae_u8 *data) return 1; // just allow everything } -static void gotfunc (struct s2devstruct *dev, const uae_u8 *databuf, int len) +static void gotfunc (void *devv, const uae_u8 *databuf, int len) { int i; int size, insize, first; @@ -274,6 +274,7 @@ static void gotfunc (struct s2devstruct *dev, const uae_u8 *databuf, int len) uae_u32 crc32; uae_u8 tmp[MAX_PACKET_SIZE], *data; const uae_u8 *dstmac, *srcmac; + struct s2devstruct *dev = (struct s2devstruct*)devv; if (log_a2065 > 1 && log_receive) { dstmac = databuf; @@ -422,8 +423,10 @@ static void gotfunc (struct s2devstruct *dev, const uae_u8 *databuf, int len) rethink_a2065 (); } -static int getfunc (struct s2devstruct *dev, uae_u8 *d, int *len) +static int getfunc (void *devv, uae_u8 *d, int *len) { + struct s2devstruct *dev = (struct s2devstruct*)devv; + if (transmitlen <= 0) return 0; if (transmitlen > *len) { @@ -523,7 +526,7 @@ static void do_transmit (void) (d[12] << 8) | d[13], outsize); } } - ethernet_trigger (sysdata); + ethernet_trigger (td, sysdata); } csr[0] |= CSR0_TINT; rethink_a2065 (); diff --git a/ethernet.cpp b/ethernet.cpp index 862af88c..45ec498f 100644 --- a/ethernet.cpp +++ b/ethernet.cpp @@ -14,6 +14,7 @@ struct ethernet_data { ethernet_gotfunc *gotfunc; ethernet_getfunc *getfunc; + void *userdata; }; #define SLIRP_PORT_OFFSET 0 @@ -52,13 +53,13 @@ void slirp_output (const uint8 *pkt, int pkt_len) if (!slirp_data) return; uae_sem_wait (&slirp_sem1); - slirp_data->gotfunc (NULL, pkt, pkt_len); + slirp_data->gotfunc (slirp_data->userdata, pkt, pkt_len); uae_sem_post (&slirp_sem1); } -void ethernet_trigger (void *vsd) +void ethernet_trigger (struct netdriverdata *ndd, void *vsd) { - switch (netmode) + switch (ndd->type) { case UAENET_SLIRP: case UAENET_SLIRP_INBOUND: @@ -69,7 +70,7 @@ void ethernet_trigger (void *vsd) int len = sizeof pkt; int v; uae_sem_wait (&slirp_sem1); - v = slirp_data->getfunc(NULL, pkt, &len); + v = slirp_data->getfunc(ed->userdata, pkt, &len); uae_sem_post (&slirp_sem1); if (v) { uae_sem_wait (&slirp_sem2); @@ -97,6 +98,7 @@ int ethernet_open (struct netdriverdata *ndd, void *vsd, void *user, ethernet_go struct ethernet_data *ed = (struct ethernet_data*)vsd; ed->gotfunc = gotfunc; ed->getfunc = getfunc; + ed->userdata = user; slirp_data = ed; uae_sem_init (&slirp_sem1, 0, 1); uae_sem_init (&slirp_sem2, 0, 1); @@ -133,12 +135,17 @@ int ethernet_open (struct netdriverdata *ndd, void *vsd, void *user, ethernet_go slirp_redir (0, port + SLIRP_PORT_OFFSET, a, port); } } + netmode = ndd->type; slirp_start (); } return 1; #ifdef WITH_UAENET_PCAP case UAENET_PCAP: - return uaenet_open (vsd, ndd, user, gotfunc, getfunc, promiscuous); + if (uaenet_open (vsd, ndd, user, gotfunc, getfunc, promiscuous)) { + netmode = ndd->type; + return 1; + } + return 0; #endif } return 0; diff --git a/include/ethernet.h b/include/ethernet.h index 684d9e27..77465ef7 100644 --- a/include/ethernet.h +++ b/include/ethernet.h @@ -17,8 +17,8 @@ struct netdriverdata }; -typedef void (ethernet_gotfunc)(struct s2devstruct *dev, const uae_u8 *data, int len); -typedef int (ethernet_getfunc)(struct s2devstruct *dev, uae_u8 *d, int *len); +typedef void (ethernet_gotfunc)(void *dev, const uae_u8 *data, int len); +typedef int (ethernet_getfunc)(void *dev, uae_u8 *d, int *len); extern bool ethernet_enumerate (struct netdriverdata **, const TCHAR *name); extern void ethernet_enumerate_free (void); @@ -30,7 +30,7 @@ extern int ethernet_open (struct netdriverdata *ndd, void*, void*, ethernet_gotf extern void ethernet_close (struct netdriverdata *ndd, void*); extern void ethernet_gotdata (struct s2devstruct *dev, const uae_u8 *data, int len); extern int ethernet_getdata (struct s2devstruct *dev, uae_u8 *d, int *len); -extern void ethernet_trigger (void*); +extern void ethernet_trigger (struct netdriverdata *ndd, void*); extern bool slirp_start (void); extern void slirp_end (void); diff --git a/od-win32/win32_uaenet.h b/od-win32/win32_uaenet.h index 493e2354..2465020d 100644 --- a/od-win32/win32_uaenet.h +++ b/od-win32/win32_uaenet.h @@ -1,8 +1,8 @@ #include "ethernet.h" -typedef void (uaenet_gotfunc)(struct s2devstruct *dev, const uae_u8 *data, int len); -typedef int (uaenet_getfunc)(struct s2devstruct *dev, uae_u8 *d, int *len); +typedef void (uaenet_gotfunc)(void *dev, const uae_u8 *data, int len); +typedef int (uaenet_getfunc)(void *dev, uae_u8 *d, int *len); extern struct netdriverdata *uaenet_enumerate (const TCHAR *name); extern void uaenet_enumerate_free (void); diff --git a/sana2.cpp b/sana2.cpp index 65a1b2d9..e4f10c2d 100644 --- a/sana2.cpp +++ b/sana2.cpp @@ -32,8 +32,8 @@ #endif #include "execio.h" -void uaenet_gotdata (struct s2devstruct *dev, const uae_u8 *data, int len); -int uaenet_getdata (struct s2devstruct *dev, uae_u8 *d, int *len); +static void uaenet_gotdata (void *dev, const uae_u8 *data, int len); +static int uaenet_getdata (void *dev, uae_u8 *d, int *len); #define SANA2NAME _T("uaenet.device") @@ -801,11 +801,12 @@ static int handleread (TrapContext *ctx, struct priv_s2devstruct *pdev, uaecptr return 1; } -void uaenet_gotdata (struct s2devstruct *dev, const uae_u8 *d, int len) +static void uaenet_gotdata (void *devv, const uae_u8 *d, int len) { uae_u16 type; struct mcast *mc; struct s2packet *s2p; + struct s2devstruct *dev = (struct s2devstruct*)devv; if (!dev->online) return; @@ -888,10 +889,11 @@ static struct s2packet *createwritepacket (TrapContext *ctx, uaecptr request) return s2p; } -int uaenet_getdata (struct s2devstruct *dev, uae_u8 *d, int *len) +static int uaenet_getdata (void *devv, uae_u8 *d, int *len) { int gotit; struct asyncreq *ar; + struct s2devstruct *dev = (struct s2devstruct*)devv; uae_sem_wait (&async_sem); ar = dev->ar; @@ -1363,8 +1365,9 @@ static void *dev_thread (void *devs) uae_ReplyMsg (request); rem_async_packet (dev, request); } else { + struct priv_s2devstruct *pdev = getps2devstruct (request); add_async_request (dev, request); - ethernet_trigger (dev->sysdata); + ethernet_trigger (pdev->td, dev->sysdata); } uae_sem_post (&change_sem); } -- 2.47.3