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