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