]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/sys_dep.c
639ab54dac0e311cd5057593433faf33214b6b7c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1995-1998 Apple Computer, Inc.
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.
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>
40 #include <sys/filedesc.h>
41 #include <sys/fcntl.h>
43 #include <sys/malloc.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <net/if_var.h>
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>
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;
63 extern at_state_t at_state
; /* global state of AT network */
64 extern at_ifaddr_t
*ifID_home
; /* default interface */
66 int ATsocket(proc
, uap
, retval
)
76 /* required check for all AppleTalk system calls */
77 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
81 *retval
= (*sys_ATsocket
)(uap
->proto
, &err
, proc
);
90 int ATgetmsg(proc
, uap
, retval
)
103 /* required check for all AppleTalk system calls */
104 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
109 (*sys_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
110 uap
->flags
, &err
, proc
);
119 int ATputmsg(proc
, uap
, retval
)
132 /* required check for all AppleTalk system calls */
133 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
138 (*sys_ATputmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
139 uap
->flags
, &err
, proc
);
148 int ATPsndreq(proc
, uap
, retval
)
161 /* required check for all AppleTalk system calls */
162 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
167 (*sys_ATPsndreq
)(uap
->fd
, uap
->buf
, uap
->len
,
168 uap
->nowait
, &err
, proc
);
177 int ATPsndrsp(proc
, uap
, retval
)
181 unsigned char *respbuff
;
190 /* required check for all AppleTalk system calls */
191 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
196 (*sys_ATPsndrsp
)(uap
->fd
, uap
->respbuff
,
197 uap
->resplen
, uap
->datalen
, &err
, proc
);
206 int ATPgetreq(proc
, uap
, retval
)
218 /* required check for all AppleTalk system calls */
219 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
224 (*sys_ATPgetreq
)(uap
->fd
, uap
->buf
, uap
->buflen
,
234 int ATPgetrsp(proc
, uap
, retval
)
245 /* required check for all AppleTalk system calls */
246 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
251 (*sys_ATPgetrsp
)(uap
->fd
, uap
->bdsp
, &err
, proc
);
260 int atalk_closeref(fp
, grefp
)
264 if ((*grefp
= (gref_t
*)fp
->f_data
)) {
267 kprintf("atalk_closeref: fp = 0x%x, gref = 0x%x\n", (u_int)fp,
275 int atalk_openref(gref
, retfd
, proc
)
280 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose();
281 static struct fileops fileops
=
282 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
};
286 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
288 if ((err
= falloc(proc
, &fp
, &fd
)) != 0) {
289 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
293 fp
->f_flag
= FREAD
|FWRITE
;
294 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
295 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
297 fp
->f_type
= DTYPE_ATALK
+1;
298 fp
->f_ops
= &fileops
;
299 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
301 fp
->f_data
= (void *)gref
;
303 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
305 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
309 /* go from file descriptor to gref, which has been saved in fp->f_data */
310 int atalk_getref(fp
, fd
, grefp
, proc
)
316 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
318 int error
= fdgetf(proc
, fd
, &fp
);
322 *grefp
= (gref_t
*) 0;
323 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
327 if ((*grefp
= (gref_t
*)fp
->f_data
) == 0) {
328 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
332 if ((*grefp
)->errno
) {
333 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
334 return (int)(*grefp
)->errno
;
337 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);