]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/aurp_rx.c
xnu-344.21.73.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_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1996 Apple Computer, Inc.
27 *
28 * Created April 8, 1996 by Tuyen Nguyen
29 * Modified for Kernel execution, May, 1996, Justin C. Walker
30 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
31 *
32 * File: rx.c
33 */
34 #include <sys/errno.h>
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <machine/spl.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/filedesc.h>
42 #include <sys/fcntl.h>
43 #include <sys/mbuf.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
46 #include <net/if.h>
47
48 #include <netat/sysglue.h>
49 #include <netat/appletalk.h>
50 #include <netat/at_var.h>
51 #include <netat/routing_tables.h>
52 #include <netat/at_pcb.h>
53 #include <netat/aurp.h>
54 #include <netat/debug.h>
55
56 /*
57 * Not using the stream queue for data; keep this around to handle
58 * requests from the user proc (mostly setup).
59 */
60 int
61 aurp_wput(gref, m)
62 gref_t *gref;
63 gbuf_t *m;
64 {
65 register ioc_t *iocbp;
66 register gbuf_t *mdata;
67 register int temp, error;
68
69 switch (gbuf_type(m)) {
70
71 case MSG_IOCTL:
72 iocbp = (ioc_t *)gbuf_rptr(m);
73 switch (iocbp->ioc_cmd) {
74 case AUC_CFGTNL: /* set up a tunnel, init the AURP daemon */
75 mdata = gbuf_cont(m);
76 temp = (int)(*gbuf_rptr(mdata));
77 if (temp != dst_addr_cnt) {
78 AURPiocnak(gref, m, ENOSPC);
79 return 0;
80 }
81 if ((error = aurpd_start()) != 0) {
82 AURPiocnak(gref, m, error);
83 return 0;
84 }
85 if (AURPinit()) {
86 AURPiocnak(gref, m, ENOMEM);
87 return 0;
88 }
89 ddp_AURPfuncx(AURPCODE_AURPPROTO, 0, 0);
90 AURPaccess();
91 break;
92
93 case AUC_SHTDOWN: /* shutdown AURP operation */
94 AURPshutdown();
95 break;
96
97 case AUC_EXPNET: /* configure networks to be exported */
98 case AUC_HIDENET: /* configure networks to be hiden */
99 mdata = gbuf_cont(m);
100 net_access_cnt = (gbuf_len(mdata))/sizeof(short);
101 if ((net_access_cnt==0) || (net_access_cnt>AURP_MaxNetAccess)) {
102 AURPiocnak(gref, m, EINVAL);
103 return 0;
104 }
105 bcopy(gbuf_rptr(mdata), net_access,
106 gbuf_len(mdata));
107 if (iocbp->ioc_cmd == AUC_EXPNET)
108 net_export = 1;
109 break;
110
111 case AUC_UDPPORT:
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
151 int
152 at_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 }