]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/sys_dep.c
xnu-517.tar.gz
[apple/xnu.git] / bsd / netat / sys_dep.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) 1995-1998 Apple Computer, Inc.
27 *
28 * Change Log:
29 * Created February 20, 1995 by Tuyen Nguyen
30 * Modified for MP, 1996 by Tuyen Nguyen
31 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
32 */
33 #include <sys/errno.h>
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <machine/spl.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/proc.h>
40 #include <sys/filedesc.h>
41 #include <sys/fcntl.h>
42 #include <sys/mbuf.h>
43 #include <sys/malloc.h>
44 #include <sys/file.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <net/if_var.h>
48
49 #include <netat/sysglue.h>
50 #include <netat/appletalk.h>
51 #include <netat/at_var.h>
52 #include <netat/at_pcb.h>
53 #include <netat/debug.h>
54
55 int (*sys_ATsocket)() = 0;
56 int (*sys_ATgetmsg)() = 0;
57 int (*sys_ATputmsg)() = 0;
58 int (*sys_ATPsndreq)() = 0;
59 int (*sys_ATPsndrsp)() = 0;
60 int (*sys_ATPgetreq)() = 0;
61 int (*sys_ATPgetrsp)() = 0;
62
63 extern at_state_t at_state; /* global state of AT network */
64 extern at_ifaddr_t *ifID_home; /* default interface */
65
66 struct ATsocket_args {
67 int proto;
68 };
69 int ATsocket(proc, uap, retval)
70 void *proc;
71 struct ATsocket_args *uap;
72 int *retval;
73 {
74 int err;
75
76 if (sys_ATsocket) {
77 /* required check for all AppleTalk system calls */
78 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
79 *retval = -1;
80 err = ENOTREADY;
81 } else {
82 *retval = (*sys_ATsocket)(uap->proto, &err, proc);
83 }
84 } else {
85 *retval = -1;
86 err = ENXIO;
87 }
88 return err;
89 }
90
91 struct ATgetmsg_args {
92 int fd;
93 void *ctlptr;
94 void *datptr;
95 int *flags;
96 };
97 int ATgetmsg(proc, uap, retval)
98 void *proc;
99 struct ATgetmsg_args *uap;
100 int *retval;
101 {
102 int err;
103
104 if (sys_ATgetmsg) {
105 /* required check for all AppleTalk system calls */
106 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
107 *retval = -1;
108 err = ENOTREADY;
109 } else {
110 *retval =
111 (*sys_ATgetmsg)(uap->fd, uap->ctlptr, uap->datptr,
112 uap->flags, &err, proc);
113 }
114 } else {
115 *retval = -1;
116 err = ENXIO;
117 }
118 return err;
119 }
120
121 struct ATputmsg_args {
122 int fd;
123 void *ctlptr;
124 void *datptr;
125 int flags;
126 };
127 int ATputmsg(proc, uap, retval)
128 void *proc;
129 struct ATputmsg_args *uap;
130 int *retval;
131 {
132 int err;
133
134 if (sys_ATputmsg) {
135 /* required check for all AppleTalk system calls */
136 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
137 *retval = -1;
138 err = ENOTREADY;
139 } else {
140 *retval =
141 (*sys_ATputmsg)(uap->fd, uap->ctlptr, uap->datptr,
142 uap->flags, &err, proc);
143 }
144 } else {
145 *retval = -1;
146 err = ENXIO;
147 }
148 return err;
149 }
150
151 struct ATPsndreq_args {
152 int fd;
153 unsigned char *buf;
154 int len;
155 int nowait;
156 };
157 int ATPsndreq(proc, uap, retval)
158 void *proc;
159 struct ATPsndreq_args *uap;
160 int *retval;
161 {
162 int err;
163
164 if (sys_ATPsndreq) {
165 /* required check for all AppleTalk system calls */
166 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
167 *retval = -1;
168 err = ENOTREADY;
169 } else {
170 *retval =
171 (*sys_ATPsndreq)(uap->fd, uap->buf, uap->len,
172 uap->nowait, &err, proc);
173 }
174 } else {
175 *retval = -1;
176 err= ENXIO;
177 }
178 return err;
179 }
180
181 struct ATPsndrsp_args {
182 int fd;
183 unsigned char *respbuff;
184 int resplen;
185 int datalen;
186 };
187 int ATPsndrsp(proc, uap, retval)
188 void *proc;
189 struct ATPsndrsp_args *uap;
190 int *retval;
191 {
192 int err;
193
194 if (sys_ATPsndrsp) {
195 /* required check for all AppleTalk system calls */
196 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
197 *retval = -1;
198 err = ENOTREADY;
199 } else {
200 *retval =
201 (*sys_ATPsndrsp)(uap->fd, uap->respbuff,
202 uap->resplen, uap->datalen, &err, proc);
203 }
204 } else {
205 *retval = -1;
206 err = ENXIO;
207 }
208 return err;
209 }
210
211 struct ATPgetreq_args {
212 int fd;
213 unsigned char *buf;
214 int buflen;
215 };
216 int ATPgetreq(proc, uap, retval)
217 void *proc;
218 struct ATPgetreq_args *uap;
219 int *retval;
220 {
221 int err;
222
223 if (sys_ATPgetreq) {
224 /* required check for all AppleTalk system calls */
225 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
226 *retval = -1;
227 err = ENOTREADY;
228 } else {
229 *retval =
230 (*sys_ATPgetreq)(uap->fd, uap->buf, uap->buflen,
231 &err, proc);
232 }
233 } else {
234 *retval = -1;
235 err = ENXIO;
236 }
237 return err;
238 }
239
240 struct ATPgetrsp_args {
241 int fd;
242 unsigned char *bdsp;
243 };
244 int ATPgetrsp(proc, uap, retval)
245 void *proc;
246 struct ATPgetrsp_args *uap;
247 int *retval;
248 {
249 int err = 0;
250
251 if (sys_ATPgetrsp) {
252 /* required check for all AppleTalk system calls */
253 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
254 *retval = -1;
255 err = ENOTREADY;
256 } else {
257 *retval =
258 (*sys_ATPgetrsp)(uap->fd, uap->bdsp, &err, proc);
259 }
260 } else {
261 *retval = -1;
262 err = ENXIO;
263 }
264 return err;
265 }
266
267 int atalk_closeref(fp, grefp)
268 struct file *fp;
269 gref_t **grefp;
270 {
271 if ((*grefp = (gref_t *)fp->f_data)) {
272 fp->f_data = 0;
273 /*
274 kprintf("atalk_closeref: fp = 0x%x, gref = 0x%x\n", (u_int)fp,
275 (u_int)*grefp);
276 */
277 return(0);
278 }
279 return(EBADF);
280 }
281
282 int atalk_openref(gref, retfd, proc)
283 gref_t *gref;
284 int *retfd;
285 struct proc *proc;
286 {
287 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose(), _ATkqfilter();
288 static struct fileops fileops =
289 {_ATread, _ATwrite, _ATioctl, _ATselect, _ATclose, _ATkqfilter};
290 int err, fd;
291 struct file *fp;
292
293 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
294
295 if ((err = falloc(proc, &fp, &fd)) != 0) {
296 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
297 return err;
298 }
299
300 fp->f_flag = FREAD|FWRITE;
301 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
302 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
303 */
304 fp->f_type = DTYPE_ATALK+1;
305 fp->f_ops = &fileops;
306 *fdflags(proc, fd) &= ~UF_RESERVED;
307 *retfd = fd;
308 fp->f_data = (void *)gref;
309 /*
310 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
311 */
312 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
313 return 0;
314 }
315
316 /* go from file descriptor to gref, which has been saved in fp->f_data */
317 int atalk_getref(fp, fd, grefp, proc)
318 struct file *fp;
319 int fd;
320 gref_t **grefp;
321 struct proc *proc;
322 {
323 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
324 if (fp == 0) {
325 int error = fdgetf(proc, fd, &fp);
326
327 if (error) {
328
329 *grefp = (gref_t *) 0;
330 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
331 return EBADF;
332 }
333 }
334 *grefp = (gref_t *)fp->f_data;
335 if (*grefp == 0 || *grefp == (gref_t *)(-1)) {
336 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
337 return EBADF;
338 }
339
340 if ((*grefp)->errno) {
341 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
342 return (int)(*grefp)->errno;
343 }
344
345 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
346 return 0;
347 }