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