1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 *	Copyright (c) 1996 Apple Computer, Inc.
30 *
31 *		Created April 8, 1996 by Tuyen Nguyen
32 *   Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
33 *
34 *	File: tx.c
35 */
36
37#ifdef AURP_SUPPORT
38
39#include <sys/errno.h>
40#include <sys/types.h>
41#include <sys/param.h>
42#include <machine/spl.h>
43#include <sys/systm.h>
44#include <sys/kernel.h>
45#include <sys/proc.h>
46#include <sys/filedesc.h>
47#include <sys/fcntl.h>
48#include <sys/mbuf.h>
49#include <sys/socket.h>
50#include <sys/socketvar.h>
51#include <net/if.h>
52
53#include <netat/sysglue.h>
54#include <netat/appletalk.h>
55#include <netat/at_pcb.h>
56#include <netat/at_var.h>
57#include <netat/routing_tables.h>
58#include <netat/aurp.h>
59#include <netat/debug.h>
60
61/*
62 * Any AURP protocol or appletalk data (ddp) packets flowing through
63 *  are inserted into the kernel aurpd process's (atalk) input queue.
64 * Assume here that we deal with single packets, i.e., someone earlier
65 *  in the food chain has broken up packet chains.
66 */
67void AURPsend(mdata, type, node)
68	gbuf_t *mdata;
69	int type, node;
70{
71	struct aurp_domain *domain;
72	gbuf_t *m;
73	int msize = AT_WR_OFFSET+32+IP_DOMAINSIZE;
74
75	/* Add the domain header */
76	if ((m = gbuf_alloc(msize, PRI_MED)) == 0) {
77		gbuf_freem(mdata);
78		dPrintf(D_M_AURP, D_L_WARNING, ("AURPsend: gbuf_alloc failed\n"));
79		return;
80	}
81	gbuf_wset(m,msize);
82	gbuf_rinc(m,AT_WR_OFFSET+32);
83	gbuf_cont(m) = mdata;
84	domain = (struct aurp_domain *)gbuf_rptr(m);
85	domain->dst_length = IP_LENGTH;
86	domain->dst_authority = IP_AUTHORITY;
87	domain->dst_distinguisher = IP_DISTINGUISHER;
88	domain->src_length = IP_LENGTH;
89	domain->src_authority = IP_AUTHORITY;
90	domain->src_distinguisher = IP_DISTINGUISHER;
91	domain->src_address = aurp_global.src_addr;
92	domain->version = AUD_Version;
93	domain->reserved = 0;
94	domain->type = type;
95	domain->dst_address = aurp_global.dst_addr[node];
96	atalk_to_ip(m);
97}
98
99/*
100 * Called from within ddp (via ddp_AURPsendx) to handle data (DDP) packets
101 *  sent from the AppleTalk stack, routing updates, and routing info
102 *  initialization.
103 */
104void AURPcmdx(code, mdata, param)
105	int code;
106	gbuf_t *mdata;
107	int param;
108{
109	unsigned char node;
110	gbuf_t *mdata_next;
111
112	if (mdata == 0)
113		return;
114	if (aurp_gref == 0) {
115		if (code != AURPCODE_DEBUGINFO)
116			AURPfreemsg(mdata);
117		return;
118	}
119
120	switch (code) {
121	case AURPCODE_DATAPKT: /* data packet */
122		node = (unsigned char)param;
123		if (gbuf_next(mdata)) {
124			mdata_next = gbuf_next(mdata);
125			gbuf_next(mdata) = 0;
126			AURPsend(mdata, AUD_Atalk, node);
127			do {
128				mdata = mdata_next;
129				mdata_next = gbuf_next(mdata);
130				gbuf_next(mdata) = 0;
131				/* Indicate non-AURP packet, node id of peer */
132				AURPsend(mdata, AUD_Atalk, node);
133			} while (mdata_next);
134		} else
135			AURPsend(mdata, AUD_Atalk, node);
136		break;
137
138	case AURPCODE_RTUPDATE:
139		AURPrtupdate((RT_entry *)mdata, param);
140		break;
141
142	case AURPCODE_DEBUGINFO: /* debug info */
143		dbgBits = *(dbgBits_t *)mdata;
144		net_port = param;
145		break;
146
147	default:
148		dPrintf(D_M_AURP, D_L_ERROR, ("AURPcmdx: bad code, %d\n", code));
149	}
150}
151
152#endif  /* AURP_SUPPORT */
153