]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/aurp_rx.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / netat / aurp_rx.c
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 for Kernel execution, May, 1996, Justin C. Walker
33 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
34 *
35 * File: rx.c
36 */
37 #include <sys/errno.h>
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <machine/spl.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/proc.h>
44 #include <sys/filedesc.h>
45 #include <sys/fcntl.h>
46 #include <sys/mbuf.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
49 #include <net/if.h>
50
51 #include <netat/sysglue.h>
52 #include <netat/appletalk.h>
53 #include <netat/at_var.h>
54 #include <netat/routing_tables.h>
55 #include <netat/at_pcb.h>
56 #include <netat/aurp.h>
57 #include <netat/debug.h>
58
59 /*
60 * Not using the stream queue for data; keep this around to handle
61 * requests from the user proc (mostly setup).
62 */
63 int
64 aurp_wput(gref, m)
65 gref_t *gref;
66 gbuf_t *m;
67 {
68 register ioc_t *iocbp;
69 register gbuf_t *mdata;
70 register int temp, error;
71
72 switch (gbuf_type(m)) {
73
74 case MSG_IOCTL:
75 iocbp = (ioc_t *)gbuf_rptr(m);
76 switch (iocbp->ioc_cmd) {
77 case AUC_CFGTNL: /* set up a tunnel, init the AURP daemon */
78 mdata = gbuf_cont(m);
79 temp = (int)(*gbuf_rptr(mdata));
80 if (temp != dst_addr_cnt) {
81 AURPiocnak(gref, m, ENOSPC);
82 return 0;
83 }
84 if ((error = aurpd_start()) != 0) {
85 AURPiocnak(gref, m, error);
86 return 0;
87 }
88 if (AURPinit()) {
89 AURPiocnak(gref, m, ENOMEM);
90 return 0;
91 }
92 ddp_AURPfuncx(AURPCODE_AURPPROTO, 0, 0);
93 AURPaccess();
94 break;
95
96 case AUC_SHTDOWN: /* shutdown AURP operation */
97 AURPshutdown();
98 break;
99
100 case AUC_EXPNET: /* configure networks to be exported */
101 case AUC_HIDENET: /* configure networks to be hiden */
102 mdata = gbuf_cont(m);
103 net_access_cnt = (gbuf_len(mdata))/sizeof(short);
104 if ((net_access_cnt==0) || (net_access_cnt>AURP_MaxNetAccess)) {
105 AURPiocnak(gref, m, EINVAL);
106 return 0;
107 }
108 bcopy(gbuf_rptr(mdata), net_access,
109 gbuf_len(mdata));
110 if (iocbp->ioc_cmd == AUC_EXPNET)
111 net_export = 1;
112 break;
113
114 case AUC_UDPPORT:
115 mdata = gbuf_cont(m);
116 aurp_global.udp_port = *(char *)gbuf_rptr(mdata);
117 break;
118
119 case AUC_NETLIST:
120 mdata = gbuf_cont(m);
121 /*
122 * Compute # addrs, Save for later check
123 * We cheat with a shift.
124 */
125 dst_addr_cnt = ((gbuf_len(mdata)) >> 2)-1;
126 bcopy(gbuf_rptr(mdata), &aurp_global.dst_addr,
127 gbuf_len(mdata));
128 aurp_global.src_addr = aurp_global.dst_addr[0];
129 aurp_global.dst_addr[0] = 0;
130 break;
131
132 default:
133 AURPiocnak(gref, m, EINVAL);
134 return 0;
135 }
136 AURPiocack(gref, m);
137 break;
138
139 default:
140 dPrintf(D_M_AURP, D_L_WARNING,
141 ("aurp_wput: bad msg type=%d\n", gbuf_type(m)));
142 gbuf_freem(m);
143 break;
144 }
145
146 return 0;
147 }
148
149 /*
150 * Insert an appletalk packet into the appletalk stack.
151 * If it's an AURP data packet, just send it up; if it's AURP protocol,
152 * switch out here.
153 */
154
155 int
156 at_insert(m, type, node)
157 register gbuf_t *m;
158 register unsigned int type, node;
159 {
160 register aurp_hdr_t *hdrp;
161 register aurp_state_t *state;
162
163 if (type == AUD_Atalk)
164 /* non-AURP proto packet */
165 ddp_AURPfuncx(AURPCODE_DATAPKT, m, node);
166 else
167 { /* AURP proto packet */
168 state = (aurp_state_t *)&aurp_state[node];
169 state->tickle_retry = 0;
170 hdrp = (aurp_hdr_t *)gbuf_rptr(m);
171
172 switch (hdrp->command_code) {
173 case AURPCMD_RIUpd:
174 AURPrcvRIUpd(state, m); break;
175
176 case AURPCMD_RIReq:
177 AURPrcvRIReq(state, m); break;
178
179 case AURPCMD_RIRsp:
180 AURPrcvRIRsp(state, m); break;
181
182 case AURPCMD_RIAck:
183 AURPrcvRIAck(state, m); break;
184
185 case AURPCMD_ZReq:
186 AURPrcvZReq(state, m); break;
187
188 case AURPCMD_ZRsp:
189 AURPrcvZRsp(state, m); break;
190
191 case AURPCMD_OpenReq:
192 AURPrcvOpenReq(state, m); break;
193
194 case AURPCMD_OpenRsp:
195 AURPrcvOpenRsp(state, m); break;
196
197 case AURPCMD_Tickle:
198 AURPrcvTickle(state, m); break;
199
200 case AURPCMD_TickleAck:
201 AURPrcvTickleAck(state, m); break;
202
203 case AURPCMD_RDReq:
204 AURPrcvRDReq(state, m); break;
205
206 default:
207 dPrintf(D_M_AURP, D_L_WARNING,
208 ("at_insert: bad proto cmd=%d\n",
209 hdrp->command_code));
210 gbuf_freem(m);
211 }
212 }
213
214 return 0;
215 }