ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/dummy/ether_dummy.cpp
Revision: 1.11
Committed: 2008-01-01T09:40:34Z (16 years, 4 months ago) by gbeauche
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * ether_dummy.cpp - Ethernet device driver, dummy implementation
3 *
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
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 return true;
56 }
57
58
59 /*
60 * Deinitialization
61 */
62
63 void ether_exit(void)
64 {
65 }
66
67
68 /*
69 * Reset
70 */
71
72 void ether_reset(void)
73 {
74 }
75
76
77 /*
78 * Add multicast address
79 */
80
81 int16 ether_add_multicast(uint32 pb)
82 {
83 return noErr;
84 }
85
86
87 /*
88 * Delete multicast address
89 */
90
91 int16 ether_del_multicast(uint32 pb)
92 {
93 return noErr;
94 }
95
96
97 /*
98 * Attach protocol handler
99 */
100
101 int16 ether_attach_ph(uint16 type, uint32 handler)
102 {
103 return noErr;
104 }
105
106
107 /*
108 * Detach protocol handler
109 */
110
111 int16 ether_detach_ph(uint16 type)
112 {
113 return noErr;
114 }
115
116
117 /*
118 * Transmit raw ethernet packet
119 */
120
121 int16 ether_write(uint32 wds)
122 {
123 // Set source address
124 uint32 hdr = ReadMacInt32(wds + 2);
125 memcpy(Mac2HostAddr(hdr + 6), ether_addr, 6);
126 return noErr;
127 }
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 }