1 |
|
/* |
2 |
|
* ether_dummy.cpp - Ethernet device driver, dummy implementation |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2000 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2008 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
19 |
|
*/ |
20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
+ |
|
23 |
+ |
#if SUPPORTS_UDP_TUNNEL |
24 |
+ |
#include <netinet/in.h> |
25 |
+ |
#include <sys/socket.h> |
26 |
+ |
#endif |
27 |
+ |
|
28 |
|
#include "cpu_emulation.h" |
29 |
|
#include "main.h" |
30 |
|
#include "macos_util.h" |
39 |
|
#define MONITOR 0 |
40 |
|
|
41 |
|
|
42 |
+ |
// Global variables |
43 |
+ |
#if SUPPORTS_UDP_TUNNEL |
44 |
+ |
static int fd = -1; // UDP tunnel socket fd |
45 |
+ |
static bool udp_tunnel_active = false; |
46 |
+ |
#endif |
47 |
+ |
|
48 |
+ |
|
49 |
|
/* |
50 |
|
* Initialization |
51 |
|
*/ |
52 |
|
|
53 |
< |
void EtherInit(void) |
53 |
> |
bool ether_init(void) |
54 |
|
{ |
55 |
+ |
return true; |
56 |
|
} |
57 |
|
|
58 |
|
|
60 |
|
* Deinitialization |
61 |
|
*/ |
62 |
|
|
63 |
< |
void EtherExit(void) |
63 |
> |
void ether_exit(void) |
64 |
|
{ |
65 |
|
} |
66 |
|
|
69 |
|
* Reset |
70 |
|
*/ |
71 |
|
|
72 |
< |
void EtherReset(void) |
72 |
> |
void ether_reset(void) |
73 |
|
{ |
74 |
|
} |
75 |
|
|
128 |
|
|
129 |
|
|
130 |
|
/* |
131 |
+ |
* Start UDP packet reception thread |
132 |
+ |
*/ |
133 |
+ |
|
134 |
+ |
bool ether_start_udp_thread(int socket_fd) |
135 |
+ |
{ |
136 |
+ |
#if SUPPORTS_UDP_TUNNEL |
137 |
+ |
fd = socket_fd; |
138 |
+ |
udp_tunnel_active = true; |
139 |
+ |
return true; |
140 |
+ |
#else |
141 |
+ |
return false; |
142 |
+ |
#endif |
143 |
+ |
} |
144 |
+ |
|
145 |
+ |
|
146 |
+ |
/* |
147 |
+ |
* Stop UDP packet reception thread |
148 |
+ |
*/ |
149 |
+ |
|
150 |
+ |
void ether_stop_udp_thread(void) |
151 |
+ |
{ |
152 |
+ |
#if SUPPORTS_UDP_TUNNEL |
153 |
+ |
udp_tunnel_active = false; |
154 |
+ |
#endif |
155 |
+ |
} |
156 |
+ |
|
157 |
+ |
|
158 |
+ |
/* |
159 |
|
* Ethernet interrupt - activate deferred tasks to call IODone or protocol handlers |
160 |
|
*/ |
161 |
|
|
162 |
|
void EtherInterrupt(void) |
163 |
|
{ |
164 |
+ |
#if SUPPORTS_UDP_TUNNEL |
165 |
+ |
if (udp_tunnel_active) { |
166 |
+ |
EthernetPacket ether_packet; |
167 |
+ |
uint32 packet = ether_packet.addr(); |
168 |
+ |
ssize_t length; |
169 |
+ |
|
170 |
+ |
// Read packets from socket and hand to ether_udp_read() for processing |
171 |
+ |
while (true) { |
172 |
+ |
struct sockaddr_in from; |
173 |
+ |
socklen_t from_len = sizeof(from); |
174 |
+ |
length = recvfrom(fd, Mac2HostAddr(packet), 1514, 0, (struct sockaddr *)&from, &from_len); |
175 |
+ |
if (length < 14) |
176 |
+ |
break; |
177 |
+ |
ether_udp_read(packet, length, &from); |
178 |
+ |
} |
179 |
+ |
} |
180 |
+ |
#endif |
181 |
|
} |