1 |
/* |
2 |
* ether_dummy.cpp - Ethernet device driver, dummy implementation |
3 |
* |
4 |
* Basilisk II (C) 1997-2001 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 |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
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" |
31 |
#include "prefs.h" |
32 |
#include "user_strings.h" |
33 |
#include "ether.h" |
34 |
#include "ether_defs.h" |
35 |
|
36 |
#define DEBUG 0 |
37 |
#include "debug.h" |
38 |
|
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 |
bool ether_init(void) |
54 |
{ |
55 |
} |
56 |
|
57 |
|
58 |
/* |
59 |
* Deinitialization |
60 |
*/ |
61 |
|
62 |
void ether_exit(void) |
63 |
{ |
64 |
} |
65 |
|
66 |
|
67 |
/* |
68 |
* Reset |
69 |
*/ |
70 |
|
71 |
void ether_reset(void) |
72 |
{ |
73 |
} |
74 |
|
75 |
|
76 |
/* |
77 |
* Add multicast address |
78 |
*/ |
79 |
|
80 |
int16 ether_add_multicast(uint32 pb) |
81 |
{ |
82 |
return noErr; |
83 |
} |
84 |
|
85 |
|
86 |
/* |
87 |
* Delete multicast address |
88 |
*/ |
89 |
|
90 |
int16 ether_del_multicast(uint32 pb) |
91 |
{ |
92 |
return noErr; |
93 |
} |
94 |
|
95 |
|
96 |
/* |
97 |
* Attach protocol handler |
98 |
*/ |
99 |
|
100 |
int16 ether_attach_ph(uint16 type, uint32 handler) |
101 |
{ |
102 |
return noErr; |
103 |
} |
104 |
|
105 |
|
106 |
/* |
107 |
* Detach protocol handler |
108 |
*/ |
109 |
|
110 |
int16 ether_detach_ph(uint16 type) |
111 |
{ |
112 |
return noErr; |
113 |
} |
114 |
|
115 |
|
116 |
/* |
117 |
* Transmit raw ethernet packet |
118 |
*/ |
119 |
|
120 |
int16 ether_write(uint32 wds) |
121 |
{ |
122 |
// Set source address |
123 |
uint32 hdr = ReadMacInt32(wds + 2); |
124 |
memcpy(Mac2HostAddr(hdr + 6), ether_addr, 6); |
125 |
return noErr; |
126 |
} |
127 |
|
128 |
|
129 |
/* |
130 |
* Start UDP packet reception thread |
131 |
*/ |
132 |
|
133 |
bool ether_start_udp_thread(int socket_fd) |
134 |
{ |
135 |
#if SUPPORTS_UDP_TUNNEL |
136 |
fd = socket_fd; |
137 |
udp_tunnel_active = true; |
138 |
return true; |
139 |
#else |
140 |
return false; |
141 |
#endif |
142 |
} |
143 |
|
144 |
|
145 |
/* |
146 |
* Stop UDP packet reception thread |
147 |
*/ |
148 |
|
149 |
void ether_stop_udp_thread(void) |
150 |
{ |
151 |
#if SUPPORTS_UDP_TUNNEL |
152 |
udp_tunnel_active = false; |
153 |
#endif |
154 |
} |
155 |
|
156 |
|
157 |
/* |
158 |
* Ethernet interrupt - activate deferred tasks to call IODone or protocol handlers |
159 |
*/ |
160 |
|
161 |
void EtherInterrupt(void) |
162 |
{ |
163 |
#if SUPPORTS_UDP_TUNNEL |
164 |
if (udp_tunnel_active) { |
165 |
uint8 packet[1514]; |
166 |
ssize_t length; |
167 |
|
168 |
// Read packets from socket and hand to ether_udp_read() for processing |
169 |
while (true) { |
170 |
struct sockaddr_in from; |
171 |
socklen_t from_len = sizeof(from); |
172 |
length = recvfrom(fd, packet, 1514, 0, (struct sockaddr *)&from, &from_len); |
173 |
if (length < 14) |
174 |
break; |
175 |
ether_udp_read(packet, length, &from); |
176 |
} |
177 |
} |
178 |
#endif |
179 |
} |