|
|
1.1 root 1: #ifndef _CHAOS_
2: #define _CHAOS_
3: /*
4: * Accomodate Ritchie C compiler...
5: */
6: #ifdef pdp11
7: #ifndef lint
8: #ifndef void
9: #define void int
10: #endif
11: #endif
12: #endif
13: #include "../chaos/constants.h"
14: /*
15: * System and device independent include file for the Chaosnet NCP
16: */
17:
18: /*
19: * A chaos index - a hosts connection identifier
20: */
21: typedef union {
22: unsigned short ci_idx; /* Index as a whole */
23: struct {
24: unsigned char ci_Tidx; /* Connection table index */
25: unsigned char ci_Uniq; /* Uniquizer for table slot */
26: } ci_bytes;
27: } chindex;
28: #define ci_uniq ci_bytes.ci_Uniq
29: #define ci_tidx ci_bytes.ci_Tidx
30:
31: /*
32: * A chaos network address.
33: */
34: typedef union {
35: unsigned short ch_addr; /* Address as a whole */
36: struct {
37: unsigned char ch_Host; /* Host number on subnet */
38: unsigned char ch_Subnet; /* Subnet number */
39: } ch_bytes;
40: } chaddr;
41: #define ch_subnet ch_bytes.ch_Subnet
42: #define ch_host ch_bytes.ch_Host
43: /*
44: * A chaosnet clock time - wrapsaround
45: */
46: typedef unsigned short chtime;
47: /*
48: * This is the part of the packet which is only for use by the ncp.
49: * It is not transmitted over the network
50: * NOTE that this structure is assumed to be at least 8 bytes by
51: * the Interlan Ethernet driver, and assumed to be at most 8 bytes
52: * by the storage allocator!!!!! GGAAAAAAAAAAAGGGHHH
53: */
54: struct ncp_header {
55: struct packet *nh_next; /* Link to next packet on this list */
56: chtime nh_time; /* Last time packet was processed */
57: chaddr nh_xdest; /* Routed destination address */
58: };
59: /*
60: * This is the part of the packet header that is transmitted over the
61: * network, thus must have fixed, portable format from ncp to ncp
62: */
63: struct pkt_header {
64: unsigned char ph_type; /* Protocol type */
65: unsigned char ph_op; /* Opcode of the packet */
66: union {
67: unsigned short ph_lfcwhole;
68: struct {
69: unsigned short ph_Len:12; /* Length of packet */
70: unsigned short ph_fcount:4; /* Forwarding count */
71: } ph_lfcparts;
72: } ph_lenfc;
73: chaddr ph_daddr; /* Destination address */
74: chindex ph_didx; /* Destination index */
75: chaddr ph_saddr; /* Source address */
76: chindex ph_sidx; /* Source index */
77: unsigned short ph_pkn; /* Packet number */
78: unsigned short ph_ackn; /* Acknowledged packet number */
79: };
80: #define ph_len ph_lenfc.ph_lfcparts.ph_Len
81: /* This is the actual structure of a packet in core */
82: struct packet {
83: struct ncp_header pk_nhead; /* NCP specific information */
84: struct pkt_header pk_phead; /* Network header */
85: union {
86: char pk_Cdata[sizeof(short)];/* Character data */
87: short pk_Idata[1]; /* word data */
88: long pk_Ldata[1]; /* long data */
89: struct sts_data { /* data of STS packets */
90: unsigned short pk_Receipt;
91: unsigned short pk_Rwsize;
92: } pk_stsdata;
93: struct rut_data { /* data of RUT packets */
94: unsigned short pk_subnet;
95: unsigned short pk_cost;
96: } pk_Rutdata[1];
97: struct status {
98: #define CHSTNAME 32
99: char sb_name[CHSTNAME];
100: struct statdata {
101: struct stathead {
102: unsigned short sb_Ident;
103: unsigned short sb_Nshorts;
104: } sb_head;
105: union {
106: struct statxcvr {
107: long sx_Rcvd;
108: long sx_Xmtd;
109: long sx_Abrt;
110: long sx_Lost;
111: long sx_Crcr;
112: long sx_Crci;
113: long sx_Leng;
114: long sx_Rej;
115: } sb_Xstat;
116: } sb_union;
117: } sb_data[1];
118: } pk_Status;
119: } pk_data;
120: };
121:
122: #define NOPKT ((struct packet *)0)
123: #define CHHEADSIZE (sizeof(struct ncp_header)+sizeof(struct pkt_header))
124: #define pkalloc(x,y) ((struct packet *)ch_alloc((x)+CHHEADSIZE,(y)))
125: /*
126: * Allocate an NCP packet given the number of shorts in the received packet.
127: */
128: #define hpkalloc(nshorts) ((struct packet *)ch_alloc((int) \
129: ((nshorts) /* * sizeof(short) */ << 1) + \
130: sizeof(struct ncp_header), 1))
131:
132: /* macros for accessing packets fields */
133: #define pk_next pk_nhead.nh_next
134: #define pk_time pk_nhead.nh_time
135: #define pk_xdest pk_nhead.nh_xdest.ch_addr
136: #define pk_type pk_phead.ph_type
137: #define pk_op pk_phead.ph_op
138: #define pk_len pk_phead.ph_len
139: #define pk_fc pk_phead.ph_lenfc.ph_lfcparts.ph_fcount
140: #define pk_lenword pk_phead.ph_lenfc.ph_lfcwhole
141: #define pk_daddr pk_phead.ph_daddr.ch_addr
142: #define pk_dhost pk_phead.ph_daddr.ch_host
143: #define pk_dsubnet pk_phead.ph_daddr.ch_subnet
144: #define pk_didx pk_phead.ph_didx.ci_idx
145: #define pk_dtindex pk_phead.ph_didx.ci_tidx
146: #define pk_saddr pk_phead.ph_saddr.ch_addr
147: #define pk_shost pk_phead.ph_saddr.ch_host
148: #define pk_ssubnet pk_phead.ph_saddr.ch_subnet
149: #define pk_sidx pk_phead.ph_sidx.ci_idx
150: #define pk_stindex pk_phead.ph_sidx.ci_tidx
151: #define pk_suniq pk_phead.ph_sidx.ci_uniq
152: #define pk_pkn pk_phead.ph_pkn
153: #define pk_ackn pk_phead.ph_ackn
154: #define pk_cdata pk_data.pk_Cdata
155: #define pk_idata pk_data.pk_Idata
156: #define pk_ldata pk_data.pk_Ldata
157: #define pk_receipt pk_data.pk_stsdata.pk_Receipt
158: #define pk_rwsize pk_data.pk_stsdata.pk_Rwsize
159: #define pk_rutdata pk_data.pk_Rutdata
160: #define pk_status pk_data.pk_Status
161: #define sb_ident sb_head.sb_Ident
162: #define sb_nshorts sb_head.sb_Nshorts
163: #define sb_xstat sb_union.sb_Xstat
164:
165: #define ISDATOP(pkt) (((pkt)->pk_op & DATOP) != 0)
166: #define CONTPKT(pkt) (ISDATOP(pkt) || (pkt)->pk_op == RFCOP || \
167: (pkt)->pk_op == OPNOP || (pkt)->pk_op == EOFOP)
168: /* Here are the packet types */
169: #define PKNML 00 /* Normal */
170: #define PKLSN 01 /* Listen list packet */
171: /*
172: * This is the connection structure. These are allocated in a packet of the
173: * appropriate size
174: */
175: struct connection {
176: struct csys_header cn_syshead; /* System dependent info */
177: unsigned char cn_flags; /* Random flags */
178: unsigned char cn_state; /* State of the connection */
179: chtime cn_active; /* Last time connection was active */
180: chaddr cn_Faddr; /* Foreign address */
181: chindex cn_Fidx; /* Foreign index */
182: chindex cn_Lidx; /* Local index */
183:
184: /* transmit side state */
185: unsigned short cn_twsize; /* Transmit window size */
186: unsigned short cn_tlast; /* Last packet we sent */
187: unsigned short cn_trecvd; /* Last pkt receipted by him */
188: unsigned short cn_tacked; /* Last pkt acked by him */
189: struct packet *cn_thead; /* Head of list of pkts transmitted */
190: struct packet *cn_ttail; /* Tail of list of pkts transmitted */
191: #ifdef CHSTRCODE
192: struct packet *cn_toutput; /* Pkt being filled for output */
193: /* NOT a list, just one packet */
194: unsigned short cn_troom; /* Room left in cn_toutput packet */
195: /* pk_len shows current fill level */
196: #endif
197: /* receive side state */
198: unsigned short cn_rwsize; /* Receive window size */
199: unsigned short cn_rlast; /* Last pkt rcvd (in order) */
200: unsigned short cn_racked; /* Last pkt acked by us */
201: unsigned short cn_rread; /* Last pkt read by our user */
202: unsigned short cn_rsts; /* Max rread-racked before auto STS */
203: #ifdef CHSTRCODE
204: unsigned short cn_roffset; /* read offset in current packet */
205: /* which is conn->cn_rhead */
206: #endif
207: struct packet *cn_rhead; /* Head of ordered rcvd pkts */
208: struct packet *cn_rtail; /* Tail of ordered received packets */
209: struct packet *cn_routorder; /* list of out of order packets */
210: };
211:
212: #define cn_fidx cn_Fidx.ci_idx
213: #define cn_faddr cn_Faddr.ch_addr
214: #define cn_fhost cn_Faddr.ch_host
215: #define cn_fsubnet cn_Faddr.ch_subnet
216: #define cn_lidx cn_Lidx.ci_idx
217: #define cn_ltidx cn_Lidx.ci_tidx
218: #define cn_luniq cn_Lidx.ci_uniq
219:
220: /* bit values for cn_flags */
221: #ifdef CHSTRCODE
222: #define CHEOFSEEN 1 /* EOF packet received and acknowledged */
223: #endif
224: #define CHANSWER 2 /* This connection should send an ANS pkt */
225:
226: /* macros for certain connection states */
227:
228: #define chtfull(conn) ((conn)->cn_state == CSOPEN && \
229: (short)((conn)->cn_tlast - (conn)->cn_tacked) >= \
230: (conn)->cn_twsize)
231: #define chtempty(conn) ((conn)->cn_state != CSOPEN || \
232: (conn)->cn_tlast == (conn)->cn_tacked)
233: #define chrempty(conn) ((conn)->cn_rhead == NOPKT && \
234: (conn)->cn_state == CSOPEN)
235:
236:
237: #define NOCONN ((struct connection *)0)
238: #define connalloc() ((struct connection *)ch_alloc(sizeof(struct connection),0))
239: /*
240: * These are unsigned comparisons
241: * all the casting is necessary due to compiler flakiness with shorts etc.
242: * cmp_lt(a,b) is true if a < b, cmp_le(a,b) if a <= b, cmp_gt(a,b) if a > b
243: * and cmp_ge(a,b) if a >= b
244: */
245: #define cmp_gt(a,b) (0100000 & (b - a))
246: #define cmp_ge(a,b) !(cmp_lt(a,b)
247: #define cmp_lt(a,b) cmp_gt(b, a)
248: #define cmp_le(a,b) !cmp_gt(a,b)
249: /* codes for error returns in various places - needs cleaning up somewhat */
250:
251: #define CHERROR -1
252: #define CHEOF -2
253: #define CHNOPKT -3 /* No packets */
254: #define CHNOCONN -4 /* No connections */
255: #define CHCTIMEOUT -5 /* Time out */
256: #define CHTEMP -6
257:
258: /*
259: * Network interface structure.
260: *
261: * There is one chxcvr structure for each interface connected to this host,
262: * all of which are defined in the file "chconf.c". The xcinfo is a union
263: * of structures needed for each device type's device dependent state.
264: * This union should be defined in "chconf.h"
265: * The bottom level device driver routines define arrays of these structures
266: * one per interface of a given type and find the structure appropriate
267: * to a given interface by indexing on the device number given in the
268: * interrupt vector. The top level gets at an chxcvr structure through
269: * the routing table.
270: * The ttime and rtime values are for timing-out hung transmitters or
271: * receivers. The drivers must ensure that tpkt and rpkt are only nonzero
272: * when there is really a packet being received or transmitted. This may
273: * be partly useless for dma (or other packet-atomic) interfaces.
274: */
275: struct chxcvr {
276: struct packet *xc_list; /* Packets to be transmitted */
277: struct packet *xc_tail; /* Tail of xc_list */
278: struct packet *xc_tpkt; /* Packet being transmitted */
279: struct packet *xc_rpkt; /* Packet being received */
280: chtime xc_ttime; /* Time tpkt begun transmission */
281: chtime xc_rtime; /* Time rpkt began reception */
282: chaddr xc_Addr; /* Address of this interface */
283: unsigned *xc_devaddr; /* Device address (UNIBUS) */
284: int (*xc_start)(); /* Start routine for idle xmtr */
285: int (*xc_reset)(); /* Reset routine for interface */
286: struct statxcvr xc_xstat; /* Xcvr metering */
287: union xcinfo xc_info; /* Device dependent info */
288: };
289: #define xc_addr xc_Addr.ch_addr
290: #define xc_subnet xc_Addr.ch_subnet
291: #define xc_host xc_Addr.ch_host
292: #define xc_rcvd xc_xstat.sx_Rcvd
293: #define xc_xmtd xc_xstat.sx_Xmtd
294: #define xc_crcr xc_xstat.sx_Crcr
295: #define xc_crci xc_xstat.sx_Crci
296: #define xc_lost xc_xstat.sx_Lost
297: #define xc_leng xc_xstat.sx_Leng
298: #define xc_rej xc_xstat.sx_Rej
299: #define xc_abrt xc_xstat.sx_Abrt
300:
301: #define NOXCVR ((struct chxcvr *)0)
302: /*
303: * Routing table entry structure.
304: * One per subnet possibly accessible from this host.
305: * Entries for directly connected subnets point to hardware
306: * transceiver structure (rt_type == CHDIRECT).
307: * Bridges (rt_type == CHFIXED or CHBRIDGE) have address of
308: * directly connected bridges.
309: */
310: struct chroute {
311: union {
312: struct chxcvr *rt_Xcvr; /* interface to use */
313: chaddr rt_Addr; /* bridge address */
314: } rt_u;
315: unsigned char rt_type; /* type of access */
316: unsigned short rt_cost; /* cost of access path */
317: };
318: #define rt_xcvr rt_u.rt_Xcvr
319: #define rt_addr rt_u.rt_Addr.ch_addr
320: #define rt_host rt_u.rt_Addr.ch_host
321: #define rt_subnet rt_u.rt_Addr.ch_subnet
322:
323: /* values for rt_type */
324: #define CHNOPATH 0 /* No path to this subnet yet (now) */
325: #define CHDIRECT 1 /* Either chaos cable or other hardware */
326: #define CHFIXED 2 /* Unvarying bridge */
327: #define CHBRIDGE 3 /* Bridge - known via RUT packet */
328: /* initial values for rt_cost depending on rt_type */
329: #define CHDCOST 10 /* Directly connected hardware (ala dr11) */
330: #define CHCCOST 16 /* Chaos cable connection (ether) */
331: #define CHACOST 20 /* Async or other slow link */
332: #define CHHCOST 512 /* "high" cost */
333:
334: /* definition of globals */
335:
336: #ifdef CHDEFINE
337: #define EXTERN
338: # ifdef DEBUG
339: int Chdebug = 0;
340: # endif
341: #else
342: #define EXTERN extern
343: # ifdef DEBUG
344: EXTERN int Chdebug;
345: # endif
346: #endif CHDEFINE
347: EXTERN int Chaos_error;
348: EXTERN struct connection *Chconntab[CHNCONNS]; /* connection table */
349: EXTERN chtime Chclock; /* clock (mod ??) */
350: EXTERN struct packet *Chlsnlist, /* listening connections */
351: *Chrfclist, /* list of unmatched rfc's */
352: *Chrfctail; /* tail of same list */
353: EXTERN struct chroute Chroutetab[CHNSUBNET]; /* subnet routing table */
354: EXTERN int Chhz; /* Hertz of clock */
355: EXTERN int Chrfcrcv; /* Flag for rfc reader */
356: extern short Chmyaddr; /* This ncp'c host number */
357: extern char Chmyname[]; /* This ncp's host name */
358:
359: extern char *ch_alloc();
360: extern struct packet *pktstr(), *ch_rnext(), *xmitnext();
361: extern struct connection *allconn(), *ch_open(), *ch_listen();
362:
363: /* debugging instrumentation */
364:
365: #ifdef DEBUG
366:
367: #define debug(a,b) if(Chdebug&(a)) b; else /* expect a ; after! */
368:
369: #define DALLOC 1 /* Allocation tracing */
370: #define DTRANS 2 /* Transmitter tracing */
371: #define DCONN 4 /* Connection activity */
372: #define DPKT 8 /* Print packets */
373: #define DNOCLK 16 /* No clock timeouts */
374: #define DABNOR 32 /* Abnormal events */
375: #define DSEND 64 /* Trace each packet sent */
376:
377: #else
378: #define debug(a,b)
379: #endif
380:
381: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.