Merge branch 'master' of https://github.com/OBattler/86Box
This commit is contained in:
@@ -29,11 +29,18 @@
|
||||
#include "network.h"
|
||||
|
||||
|
||||
static void *pcap_handle; /* handle to WinPcap DLL */
|
||||
static pcap_t *pcap; /* handle to WinPcap library */
|
||||
static thread_t *poll_tid;
|
||||
static NETRXCB poll_rx; /* network RX function to call */
|
||||
static void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
void *pcap_handle; /* handle to WinPcap DLL */
|
||||
static volatile
|
||||
pcap_t *pcap; /* handle to WinPcap library */
|
||||
static volatile
|
||||
thread_t *poll_tid;
|
||||
static volatile
|
||||
NETRXCB poll_rx; /* network RX function to call */
|
||||
static volatile
|
||||
void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
event_t *thread_started;
|
||||
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
@@ -72,6 +79,8 @@ poll_thread(void *arg)
|
||||
uint16_t mac_cmp16[2];
|
||||
event_t *evt;
|
||||
|
||||
thread_set_event((event_t *) thread_started);
|
||||
|
||||
pclog("PCAP: polling thread started, arg %08lx\n", arg);
|
||||
|
||||
/* Create a waitable event. */
|
||||
@@ -84,7 +93,7 @@ poll_thread(void *arg)
|
||||
network_wait_for_poll();
|
||||
|
||||
/* Wait for the next packet to arrive. */
|
||||
data = f_pcap_next(pcap, &h);
|
||||
data = f_pcap_next((pcap_t *) pcap, &h);
|
||||
if (data != NULL) {
|
||||
/* Received MAC. */
|
||||
mac_cmp32[0] = *(uint32_t *)(data+6);
|
||||
@@ -96,7 +105,7 @@ poll_thread(void *arg)
|
||||
if ((mac_cmp32[0] != mac_cmp32[1]) ||
|
||||
(mac_cmp16[0] != mac_cmp16[1])) {
|
||||
if (poll_rx != NULL)
|
||||
poll_rx(poll_arg, (uint8_t *)data, h.caplen);
|
||||
poll_rx((void *) poll_arg, (uint8_t *)data, h.caplen);
|
||||
} else {
|
||||
/* Mark as invalid packet. */
|
||||
data = NULL;
|
||||
@@ -111,7 +120,6 @@ poll_thread(void *arg)
|
||||
}
|
||||
|
||||
thread_destroy_event(evt);
|
||||
poll_tid = NULL;
|
||||
|
||||
pclog("PCAP: polling stopped.\n");
|
||||
}
|
||||
@@ -224,15 +232,15 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter(pcap, &fp) == -1) {
|
||||
if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) {
|
||||
pclog(" Error installing filter (%s) !\n", filter_exp);
|
||||
f_pcap_close(pcap);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
pclog(" Could not compile filter (%s) !\n", filter_exp);
|
||||
f_pcap_close(pcap);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -245,6 +253,8 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
pclog(" Starting thread..\n");
|
||||
poll_tid = thread_create(poll_thread, mac);
|
||||
|
||||
thread_wait_event((event_t *) thread_started, -1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -253,13 +263,15 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
void
|
||||
network_pcap_close(void)
|
||||
{
|
||||
pcap_t *pc;
|
||||
volatile pcap_t *pc;
|
||||
|
||||
if (pcap != NULL) {
|
||||
pclog("Closing WinPcap\n");
|
||||
|
||||
/* Tell the polling thread to shut down. */
|
||||
pc = pcap; pcap = NULL;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* Terminate the polling thread. */
|
||||
if (poll_tid != NULL) {
|
||||
@@ -271,14 +283,32 @@ network_pcap_close(void)
|
||||
while (poll_tid != NULL)
|
||||
;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Tell the thread to terminate. */
|
||||
if (poll_tid != NULL) {
|
||||
network_busy(0);
|
||||
|
||||
pclog("Waiting for network thread to end...\n");
|
||||
/* Wait for the end event. */
|
||||
network_wait_for_end((void *) poll_tid);
|
||||
pclog("Network thread ended\n");
|
||||
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
if (thread_started) {
|
||||
thread_destroy_event((event_t *) thread_started);
|
||||
thread_started = NULL;
|
||||
}
|
||||
|
||||
/* OK, now shut down WinPcap itself. */
|
||||
f_pcap_close(pc);
|
||||
f_pcap_close((pcap_t *) pc);
|
||||
pc = pcap = NULL;
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
}
|
||||
@@ -291,12 +321,12 @@ void
|
||||
network_pcap_stop(void)
|
||||
{
|
||||
/* OK, now shut down WinPcap itself. */
|
||||
f_pcap_close(pcap);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
pcap = NULL;
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
}
|
||||
@@ -344,7 +374,7 @@ network_pcap_test(void)
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
|
||||
@@ -365,7 +395,7 @@ network_pcap_test(void)
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
|
||||
@@ -377,8 +407,8 @@ network_pcap_test(void)
|
||||
"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )",
|
||||
0, 1, 2, 3, 4, 5,
|
||||
0, 1, 2, 3, 4, 5);
|
||||
if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter(pcap, &fp) == -1) {
|
||||
if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) {
|
||||
pclog(" Error installing filter (%s) !\n", filter_exp);
|
||||
network_pcap_stop();
|
||||
return 0;
|
||||
@@ -402,7 +432,7 @@ network_pcap_in(uint8_t *bufp, int len)
|
||||
if (pcap != NULL) {
|
||||
network_busy(1);
|
||||
|
||||
f_pcap_sendpacket(pcap, bufp, len);
|
||||
f_pcap_sendpacket((pcap_t *) pcap, bufp, len);
|
||||
|
||||
network_busy(0);
|
||||
}
|
||||
|
||||
@@ -29,10 +29,16 @@
|
||||
#include "network.h"
|
||||
|
||||
|
||||
static queueADT slirpq; /* SLiRP library handle */
|
||||
static thread_t *poll_tid;
|
||||
static NETRXCB poll_rx; /* network RX function to call */
|
||||
static void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
queueADT slirpq; /* SLiRP library handle */
|
||||
static volatile
|
||||
thread_t *poll_tid;
|
||||
static volatile
|
||||
NETRXCB poll_rx; /* network RX function to call */
|
||||
static volatile
|
||||
void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
event_t *thread_started;
|
||||
|
||||
|
||||
|
||||
@@ -75,6 +81,8 @@ poll_thread(void *arg)
|
||||
struct queuepacket *qp;
|
||||
event_t *evt;
|
||||
|
||||
thread_set_event((event_t *) thread_started);
|
||||
|
||||
pclog("SLiRP: polling thread started, arg %08lx\n", arg);
|
||||
|
||||
/* Create a waitable event. */
|
||||
@@ -92,6 +100,8 @@ poll_thread(void *arg)
|
||||
if (QueuePeek(slirpq) == 0) {
|
||||
/* If we did not get anything, wait a while. */
|
||||
thread_wait_event(evt, 10);
|
||||
|
||||
network_mutex_wait(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -103,7 +113,7 @@ poll_thread(void *arg)
|
||||
#endif
|
||||
|
||||
if (poll_rx != NULL)
|
||||
poll_rx(poll_arg, (uint8_t *)&qp->data, qp->len);
|
||||
poll_rx((void *) poll_arg, (uint8_t *)&qp->data, qp->len);
|
||||
|
||||
/* Done with this one. */
|
||||
free(qp);
|
||||
@@ -112,7 +122,6 @@ poll_thread(void *arg)
|
||||
}
|
||||
|
||||
thread_destroy_event(evt);
|
||||
evt = poll_tid = NULL;
|
||||
|
||||
pclog("SLiRP: polling stopped.\n");
|
||||
}
|
||||
@@ -141,6 +150,8 @@ network_slirp_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
pclog("SLiRP: starting thread..\n");
|
||||
poll_tid = thread_create(poll_thread, mac);
|
||||
|
||||
thread_wait_event((event_t *) thread_started, -1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -155,6 +166,8 @@ network_slirp_close(void)
|
||||
|
||||
/* Tell the polling thread to shut down. */
|
||||
sl = slirpq; slirpq = NULL;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* Terminate the polling thread. */
|
||||
if (poll_tid != NULL) {
|
||||
@@ -166,6 +179,24 @@ network_slirp_close(void)
|
||||
while (poll_tid != NULL)
|
||||
;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Tell the thread to terminate. */
|
||||
if (poll_tid != NULL) {
|
||||
network_busy(0);
|
||||
|
||||
pclog("Waiting for network thread to end...\n");
|
||||
/* Wait for the end event. */
|
||||
network_wait_for_end((void *) poll_tid);
|
||||
pclog("Network thread ended\n");
|
||||
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
if (thread_started) {
|
||||
thread_destroy_event((event_t *) thread_started);
|
||||
thread_started = NULL;
|
||||
}
|
||||
|
||||
/* OK, now shut down SLiRP itself. */
|
||||
QueueDestroy(sl);
|
||||
|
||||
@@ -87,8 +87,25 @@ void
|
||||
network_wait_for_poll()
|
||||
{
|
||||
while (poll_data.busy)
|
||||
thread_wait_event((event_t *) poll_data.poll_complete, -1);
|
||||
thread_reset_event((event_t *) poll_data.poll_complete);
|
||||
thread_wait_event((event_t *) poll_data.wake_poll_thread, -1);
|
||||
thread_reset_event((event_t *) poll_data.wake_poll_thread);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
network_wait_for_end(void *handle)
|
||||
{
|
||||
thread_wait((event_t *) handle, -1);
|
||||
|
||||
if (poll_data.wake_poll_thread) {
|
||||
thread_destroy_event((event_t *) poll_data.wake_poll_thread);
|
||||
poll_data.wake_poll_thread = NULL;
|
||||
}
|
||||
|
||||
if (poll_data.poll_complete) {
|
||||
thread_destroy_event((event_t *) poll_data.poll_complete);
|
||||
poll_data.poll_complete = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +121,13 @@ network_busy(uint8_t set)
|
||||
{
|
||||
poll_data.busy = !!set;
|
||||
if (!set)
|
||||
thread_set_event((event_t *) poll_data.wake_poll_thread);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
network_end(void)
|
||||
{
|
||||
thread_set_event((event_t *) poll_data.poll_complete);
|
||||
}
|
||||
|
||||
@@ -182,6 +206,8 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx)
|
||||
void
|
||||
network_close(void)
|
||||
{
|
||||
thread_close_mutex((mutex_t *) netMutex);
|
||||
|
||||
switch(network_type) {
|
||||
case NET_TYPE_PCAP:
|
||||
network_pcap_close();
|
||||
@@ -191,8 +217,6 @@ network_close(void)
|
||||
network_slirp_close();
|
||||
break;
|
||||
}
|
||||
|
||||
thread_close_mutex((event_t *) netMutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,10 +58,11 @@ extern char network_pcap[512];
|
||||
/* Function prototypes. */
|
||||
extern void network_mutex_wait(uint8_t wait);
|
||||
extern void network_wait_for_poll(void);
|
||||
extern void network_wait_for_end(void *handle);
|
||||
extern void network_mutex_init(void);
|
||||
extern void network_mutex_close(void);
|
||||
extern void network_thread_init(void);
|
||||
extern void network_busy(uint8_t set);
|
||||
extern void network_end(void);
|
||||
|
||||
extern void network_init(void);
|
||||
extern int network_attach(void *, uint8_t *, NETRXCB);
|
||||
|
||||
Reference in New Issue
Block a user