]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/aurp_rx.c
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / netat / aurp_rx.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1996 Apple Computer, Inc.
24 *
25 * Created April 8, 1996 by Tuyen Nguyen
26 * Modified for Kernel execution, May, 1996, Justin C. Walker
27 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
28 *
29 * File: rx.c
30 */
c0fea474
A
31#ifdef AURP_SUPPORT
32
1c79356b
A
33#include <sys/errno.h>
34#include <sys/types.h>
35#include <sys/param.h>
36#include <machine/spl.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/proc.h>
40#include <sys/filedesc.h>
41#include <sys/fcntl.h>
42#include <sys/mbuf.h>
43#include <sys/socket.h>
44#include <sys/socketvar.h>
45#include <net/if.h>
46
47#include <netat/sysglue.h>
48#include <netat/appletalk.h>
49#include <netat/at_var.h>
50#include <netat/routing_tables.h>
51#include <netat/at_pcb.h>
52#include <netat/aurp.h>
53#include <netat/debug.h>
54
55/*
56 * Not using the stream queue for data; keep this around to handle
57 * requests from the user proc (mostly setup).
58 */
59int
60aurp_wput(gref, m)
61 gref_t *gref;
62 gbuf_t *m;
63{
64 register ioc_t *iocbp;
65 register gbuf_t *mdata;
66 register int temp, error;
67
68 switch (gbuf_type(m)) {
69
70 case MSG_IOCTL:
71 iocbp = (ioc_t *)gbuf_rptr(m);
72 switch (iocbp->ioc_cmd) {
73 case AUC_CFGTNL: /* set up a tunnel, init the AURP daemon */
74 mdata = gbuf_cont(m);
75 temp = (int)(*gbuf_rptr(mdata));
76 if (temp != dst_addr_cnt) {
77 AURPiocnak(gref, m, ENOSPC);
78 return 0;
79 }
80 if ((error = aurpd_start()) != 0) {
81 AURPiocnak(gref, m, error);
82 return 0;
83 }
84 if (AURPinit()) {
85 AURPiocnak(gref, m, ENOMEM);
86 return 0;
87 }
88 ddp_AURPfuncx(AURPCODE_AURPPROTO, 0, 0);
89 AURPaccess();
90 break;
91
92 case AUC_SHTDOWN: /* shutdown AURP operation */
93 AURPshutdown();
94 break;
95
96 case AUC_EXPNET: /* configure networks to be exported */
97 case AUC_HIDENET: /* configure networks to be hiden */
98 mdata = gbuf_cont(m);
99 net_access_cnt = (gbuf_len(mdata))/sizeof(short);
100 if ((net_access_cnt==0) || (net_access_cnt>AURP_MaxNetAccess)) {
101 AURPiocnak(gref, m, EINVAL);
102 return 0;
103 }
104 bcopy(gbuf_rptr(mdata), net_access,
105 gbuf_len(mdata));
106 if (iocbp->ioc_cmd == AUC_EXPNET)
107 net_export = 1;
108 break;
109
110 case AUC_UDPPORT:
91447636 111 mdata = gbuf_cont(m);
1c79356b
A
112 aurp_global.udp_port = *(char *)gbuf_rptr(mdata);
113 break;
114
115 case AUC_NETLIST:
116 mdata = gbuf_cont(m);
117 /*
118 * Compute # addrs, Save for later check
119 * We cheat with a shift.
120 */
121 dst_addr_cnt = ((gbuf_len(mdata)) >> 2)-1;
122 bcopy(gbuf_rptr(mdata), &aurp_global.dst_addr,
123 gbuf_len(mdata));
124 aurp_global.src_addr = aurp_global.dst_addr[0];
125 aurp_global.dst_addr[0] = 0;
126 break;
127
128 default:
129 AURPiocnak(gref, m, EINVAL);
130 return 0;
131 }
132 AURPiocack(gref, m);
133 break;
134
135 default:
136 dPrintf(D_M_AURP, D_L_WARNING,
137 ("aurp_wput: bad msg type=%d\n", gbuf_type(m)));
138 gbuf_freem(m);
139 break;
140 }
141
142 return 0;
143}
144
145/*
146 * Insert an appletalk packet into the appletalk stack.
147 * If it's an AURP data packet, just send it up; if it's AURP protocol,
148 * switch out here.
149 */
150
151int
152at_insert(m, type, node)
153 register gbuf_t *m;
154 register unsigned int type, node;
155{
156 register aurp_hdr_t *hdrp;
157 register aurp_state_t *state;
158
159 if (type == AUD_Atalk)
160 /* non-AURP proto packet */
161 ddp_AURPfuncx(AURPCODE_DATAPKT, m, node);
162 else
163 { /* AURP proto packet */
164 state = (aurp_state_t *)&aurp_state[node];
165 state->tickle_retry = 0;
166 hdrp = (aurp_hdr_t *)gbuf_rptr(m);
167
168 switch (hdrp->command_code) {
169 case AURPCMD_RIUpd:
170 AURPrcvRIUpd(state, m); break;
171
172 case AURPCMD_RIReq:
173 AURPrcvRIReq(state, m); break;
174
175 case AURPCMD_RIRsp:
176 AURPrcvRIRsp(state, m); break;
177
178 case AURPCMD_RIAck:
179 AURPrcvRIAck(state, m); break;
180
181 case AURPCMD_ZReq:
182 AURPrcvZReq(state, m); break;
183
184 case AURPCMD_ZRsp:
185 AURPrcvZRsp(state, m); break;
186
187 case AURPCMD_OpenReq:
188 AURPrcvOpenReq(state, m); break;
189
190 case AURPCMD_OpenRsp:
191 AURPrcvOpenRsp(state, m); break;
192
193 case AURPCMD_Tickle:
194 AURPrcvTickle(state, m); break;
195
196 case AURPCMD_TickleAck:
197 AURPrcvTickleAck(state, m); break;
198
199 case AURPCMD_RDReq:
200 AURPrcvRDReq(state, m); break;
201
202 default:
203 dPrintf(D_M_AURP, D_L_WARNING,
204 ("at_insert: bad proto cmd=%d\n",
205 hdrp->command_code));
206 gbuf_freem(m);
207 }
208 }
209
210 return 0;
211}
c0fea474
A
212
213#endif /* AURP_SUPPORT */