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