Commit | Line | Data |
---|---|---|
196ba1fc PH |
1 | /* sim_ether.h: OS-dependent network information\r |
2 | ------------------------------------------------------------------------------\r | |
3 | \r | |
4 | Copyright (c) 2002-2005, David T. Hittner\r | |
5 | \r | |
6 | Permission is hereby granted, free of charge, to any person obtaining a\r | |
7 | copy of this software and associated documentation files (the "Software"),\r | |
8 | to deal in the Software without restriction, including without limitation\r | |
9 | the rights to use, copy, modify, merge, publish, distribute, sublicense,\r | |
10 | and/or sell copies of the Software, and to permit persons to whom the\r | |
11 | Software is furnished to do so, subject to the following conditions:\r | |
12 | \r | |
13 | The above copyright notice and this permission notice shall be included in\r | |
14 | all copies or substantial portions of the Software.\r | |
15 | \r | |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r | |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r | |
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r | |
19 | THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r | |
20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r | |
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r | |
22 | \r | |
23 | Except as contained in this notice, the name of the author shall not be\r | |
24 | used in advertising or otherwise to promote the sale, use or other dealings\r | |
25 | in this Software without prior written authorization from the author.\r | |
26 | \r | |
27 | ------------------------------------------------------------------------------\r | |
28 | \r | |
29 | Modification history:\r | |
30 | \r | |
31 | 30-Nov-05 DTH Added CRC length to packet and more field comments\r | |
32 | 04-Feb-04 DTH Added debugging information\r | |
33 | 14-Jan-04 MP Generalized BSD support issues\r | |
34 | 05-Jan-04 DTH Added eth_mac_scan\r | |
35 | 26-Dec-03 DTH Added ethernet show and queue functions from pdp11_xq\r | |
36 | 23-Dec-03 DTH Added status to packet\r | |
37 | 01-Dec-03 DTH Added reflections, tweaked decnet fix items\r | |
38 | 25-Nov-03 DTH Verified DECNET_FIX, reversed ifdef to mainstream code\r | |
39 | 14-Nov-03 DTH Added #ifdef DECNET_FIX for problematic duplicate detection code\r | |
40 | 07-Jun-03 MP Added WIN32 support for DECNET duplicate address detection.\r | |
41 | 05-Jun-03 DTH Added used to struct eth_packet\r | |
42 | 01-Feb-03 MP Changed some uint8 strings to char* to reflect usage \r | |
43 | 22-Oct-02 DTH Added all_multicast and promiscuous support\r | |
44 | 21-Oct-02 DTH Corrected copyright again\r | |
45 | 16-Oct-02 DTH Fixed copyright\r | |
46 | 08-Oct-02 DTH Integrated with 2.10-0p4, added variable vector and copyrights\r | |
47 | 03-Oct-02 DTH Beta version of xq/sim_ether released for SIMH 2.09-11\r | |
48 | 15-Aug-02 DTH Started XQ simulation\r | |
49 | \r | |
50 | ------------------------------------------------------------------------------\r | |
51 | */\r | |
52 | \r | |
53 | #ifndef _SIM_ETHER_H\r | |
54 | #define _SIM_ETHER_H\r | |
55 | \r | |
56 | #include "sim_defs.h"\r | |
57 | \r | |
58 | /* make common BSD code a bit easier to read in this file */\r | |
59 | /* OS/X seems to define and compile using one of these BSD types */\r | |
60 | #if defined(__NetBSD__) || defined (__OpenBSD__) || defined (__FreeBSD__)\r | |
61 | #define xBSD 1\r | |
62 | #endif\r | |
63 | #if !defined(__FreeBSD__) && !defined(_WIN32) && !defined(VMS)\r | |
64 | #define USE_SETNONBLOCK 1\r | |
65 | #endif\r | |
66 | \r | |
67 | #if defined(__sun__) && defined(__i386__)\r | |
68 | #define USE_READER_THREAD 1\r | |
69 | #endif\r | |
70 | \r | |
71 | /* make common winpcap code a bit easier to read in this file */\r | |
72 | #if defined(_WIN32) || defined(VMS)\r | |
73 | #define PCAP_READ_TIMEOUT -1\r | |
74 | #else\r | |
75 | #define PCAP_READ_TIMEOUT 1\r | |
76 | #endif\r | |
77 | \r | |
78 | /* set related values to have correct relationships */\r | |
79 | #if defined (USE_READER_THREAD)\r | |
80 | #if defined (USE_SETNONBLOCK)\r | |
81 | #undef USE_SETNONBLOCK\r | |
82 | #endif\r | |
83 | #undef PCAP_READ_TIMEOUT\r | |
84 | #define PCAP_READ_TIMEOUT 15\r | |
85 | #if !defined (xBSD) && !defined(_WIN32) && !defined(VMS)\r | |
86 | #define MUST_DO_SELECT\r | |
87 | #endif\r | |
88 | #endif\r | |
89 | \r | |
90 | /*\r | |
91 | USE_BPF is defined to let this code leverage the libpcap/OS kernel provided \r | |
92 | BPF packet filtering. This generally will enhance performance. It may not \r | |
93 | be available in some environments and/or it may not work correctly, so \r | |
94 | undefining this will still provide working code here.\r | |
95 | */\r | |
96 | #define USE_BPF 1\r | |
97 | \r | |
98 | #if defined (USE_READER_THREAD)\r | |
99 | #include <pthread.h>\r | |
100 | #endif\r | |
101 | \r | |
102 | /* structure declarations */\r | |
103 | \r | |
104 | #define ETH_PROMISC 1 /* promiscuous mode = true */\r | |
105 | #define ETH_TIMEOUT -1 /* read timeout in milliseconds (immediate) */\r | |
106 | #define ETH_FILTER_MAX 20 /* maximum address filters */\r | |
107 | #define ETH_DEV_NAME_MAX 256 /* maximum device name size */\r | |
108 | #define ETH_DEV_DESC_MAX 256 /* maximum device description size */\r | |
109 | #define ETH_MIN_PACKET 60 /* minimum ethernet packet size */\r | |
110 | #define ETH_MAX_PACKET 1514 /* maximum ethernet packet size */\r | |
111 | #define ETH_MAX_DEVICE 10 /* maximum ethernet devices */\r | |
112 | #define ETH_CRC_SIZE 4 /* ethernet CRC size */\r | |
113 | #define ETH_FRAME_SIZE 1518 /* ethernet maximum frame size */\r | |
114 | \r | |
115 | #define DECNET_SELF_FRAME(dnet_mac, msg) \\r | |
116 | ((memcmp(dnet_mac, msg , 6) == 0) && \\r | |
117 | (memcmp(dnet_mac, msg+6, 6) == 0))\r | |
118 | \r | |
119 | struct eth_packet {\r | |
120 | uint8 msg[ETH_FRAME_SIZE]; /* ethernet frame (message) */\r | |
121 | int len; /* packet length without CRC */\r | |
122 | int used; /* bytes processed (used in packet chaining) */\r | |
123 | int status; /* transmit/receive status */\r | |
124 | int crc_len; /* packet length with CRC */\r | |
125 | };\r | |
126 | \r | |
127 | struct eth_item {\r | |
128 | int type; /* receive (0=setup, 1=loopback, 2=normal) */\r | |
129 | struct eth_packet packet;\r | |
130 | };\r | |
131 | \r | |
132 | struct eth_queue {\r | |
133 | int max;\r | |
134 | int count;\r | |
135 | int head;\r | |
136 | int tail;\r | |
137 | int loss;\r | |
138 | int high;\r | |
139 | struct eth_item* item;\r | |
140 | };\r | |
141 | \r | |
142 | struct eth_list {\r | |
143 | int num;\r | |
144 | char name[ETH_DEV_NAME_MAX];\r | |
145 | char desc[ETH_DEV_DESC_MAX];\r | |
146 | };\r | |
147 | \r | |
148 | typedef int ETH_BOOL;\r | |
149 | typedef unsigned char ETH_MAC[6];\r | |
150 | typedef struct eth_packet ETH_PACK;\r | |
151 | typedef void (*ETH_PCALLBACK)(int status);\r | |
152 | typedef struct eth_list ETH_LIST;\r | |
153 | typedef struct eth_queue ETH_QUE;\r | |
154 | typedef struct eth_item ETH_ITEM;\r | |
155 | \r | |
156 | struct eth_device {\r | |
157 | char* name; /* name of ethernet device */\r | |
158 | void* handle; /* handle of implementation-specific device */\r | |
159 | ETH_PCALLBACK read_callback; /* read callback function */\r | |
160 | ETH_PCALLBACK write_callback; /* write callback function */\r | |
161 | ETH_PACK* read_packet; /* read packet */\r | |
162 | ETH_PACK* write_packet; /* write packet */\r | |
163 | ETH_MAC filter_address[ETH_FILTER_MAX]; /* filtering addresses */\r | |
164 | int addr_count; /* count of filtering addresses */\r | |
165 | ETH_BOOL promiscuous; /* promiscuous mode flag */\r | |
166 | ETH_BOOL all_multicast; /* receive all multicast messages */\r | |
167 | int32 decnet_self_sent; /* loopback packets sent but not seen */\r | |
168 | ETH_MAC decnet_addr; /* decnet address of interface */\r | |
169 | DEVICE* dptr; /* device ethernet is attached to */\r | |
170 | uint32 dbit; /* debugging bit */\r | |
171 | int reflections; /* packet reflections on interface */\r | |
172 | int need_crc; /* device needs CRC (Cyclic Redundancy Check) */\r | |
173 | #if defined (USE_READER_THREAD)\r | |
174 | ETH_QUE read_queue;\r | |
175 | pthread_mutex_t lock;\r | |
176 | pthread_t reader_thread; /* Reader Thread Id */\r | |
177 | #endif\r | |
178 | };\r | |
179 | \r | |
180 | typedef struct eth_device ETH_DEV;\r | |
181 | \r | |
182 | /* prototype declarations*/\r | |
183 | \r | |
184 | t_stat eth_open (ETH_DEV* dev, char* name, /* open ethernet interface */\r | |
185 | DEVICE* dptr, uint32 dbit);\r | |
186 | t_stat eth_close (ETH_DEV* dev); /* close ethernet interface */\r | |
187 | t_stat eth_write (ETH_DEV* dev, ETH_PACK* packet, /* write sychronous packet; */\r | |
188 | ETH_PCALLBACK routine); /* callback when done */\r | |
189 | t_stat eth_read (ETH_DEV* dev, ETH_PACK* packet, /* read single packet; */\r | |
190 | ETH_PCALLBACK routine); /* callback when done*/\r | |
191 | t_stat eth_filter (ETH_DEV* dev, int addr_count, /* set filter on incoming packets */\r | |
192 | ETH_MAC* addresses,\r | |
193 | ETH_BOOL all_multicast,\r | |
194 | ETH_BOOL promiscuous);\r | |
195 | int eth_devices (int max, ETH_LIST* dev); /* get ethernet devices on host */\r | |
196 | void eth_setcrc (ETH_DEV* dev, int need_crc); /* enable/disable CRC mode */\r | |
197 | \r | |
198 | void eth_packet_trace (ETH_DEV* dev, const uint8 *msg, int len, char* txt); /* trace ethernet packet */\r | |
199 | t_stat eth_show (FILE* st, UNIT* uptr, /* show ethernet devices */\r | |
200 | int32 val, void* desc);\r | |
201 | \r | |
202 | void eth_mac_fmt (ETH_MAC* add, char* buffer); /* format ethernet mac address */\r | |
203 | t_stat eth_mac_scan (ETH_MAC* mac, char* strmac); /* scan string for mac, put in mac */\r | |
204 | \r | |
205 | t_stat ethq_init (ETH_QUE* que, int max); /* initialize FIFO queue */\r | |
206 | void ethq_clear (ETH_QUE* que); /* clear FIFO queue */\r | |
207 | void ethq_remove (ETH_QUE* que); /* remove item from FIFO queue */\r | |
208 | void ethq_insert (ETH_QUE* que, int32 type, /* insert item into FIFO queue */\r | |
209 | ETH_PACK* packet, int32 status);\r | |
210 | \r | |
211 | \r | |
212 | #endif /* _SIM_ETHER_H */\r |