]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/sys_dep.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1995-1998 Apple Computer, Inc.
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.
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>
37 #include <sys/filedesc.h>
38 #include <sys/fcntl.h>
40 #include <sys/malloc.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
44 #include <net/if_var.h>
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>
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;
60 extern at_state_t at_state
; /* global state of AT network */
61 extern at_ifaddr_t
*ifID_home
; /* default interface */
63 int ATsocket(proc
, uap
, retval
)
73 /* required check for all AppleTalk system calls */
74 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
78 *retval
= (*sys_ATsocket
)(uap
->proto
, &err
, proc
);
87 int ATgetmsg(proc
, uap
, retval
)
100 /* required check for all AppleTalk system calls */
101 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
106 (*sys_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
107 uap
->flags
, &err
, proc
);
116 int ATputmsg(proc
, uap
, retval
)
129 /* required check for all AppleTalk system calls */
130 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
135 (*sys_ATputmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
136 uap
->flags
, &err
, proc
);
145 int ATPsndreq(proc
, uap
, retval
)
158 /* required check for all AppleTalk system calls */
159 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
164 (*sys_ATPsndreq
)(uap
->fd
, uap
->buf
, uap
->len
,
165 uap
->nowait
, &err
, proc
);
174 int ATPsndrsp(proc
, uap
, retval
)
178 unsigned char *respbuff
;
187 /* required check for all AppleTalk system calls */
188 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
193 (*sys_ATPsndrsp
)(uap
->fd
, uap
->respbuff
,
194 uap
->resplen
, uap
->datalen
, &err
, proc
);
203 int ATPgetreq(proc
, uap
, retval
)
215 /* required check for all AppleTalk system calls */
216 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
221 (*sys_ATPgetreq
)(uap
->fd
, uap
->buf
, uap
->buflen
,
231 int ATPgetrsp(proc
, uap
, retval
)
242 /* required check for all AppleTalk system calls */
243 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
248 (*sys_ATPgetrsp
)(uap
->fd
, uap
->bdsp
, &err
, proc
);
257 int atalk_closeref(fp
, grefp
)
261 if ((*grefp
= (gref_t
*)fp
->f_data
)) {
264 kprintf("atalk_closeref: fp = 0x%x, gref = 0x%x\n", (u_int)fp,
272 int atalk_openref(gref
, retfd
, proc
)
277 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose();
278 static struct fileops fileops
=
279 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
};
283 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
285 if ((err
= falloc(proc
, &fp
, &fd
)) != 0) {
286 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
290 fp
->f_flag
= FREAD
|FWRITE
;
291 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
292 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
294 fp
->f_type
= DTYPE_ATALK
+1;
295 fp
->f_ops
= &fileops
;
296 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
298 fp
->f_data
= (void *)gref
;
300 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
302 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
306 /* go from file descriptor to gref, which has been saved in fp->f_data */
307 int atalk_getref(fp
, fd
, grefp
, proc
)
313 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
315 int error
= fdgetf(proc
, fd
, &fp
);
319 *grefp
= (gref_t
*) 0;
320 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
324 if ((*grefp
= (gref_t
*)fp
->f_data
) == 0) {
325 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
329 if ((*grefp
)->errno
) {
330 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
331 return (int)(*grefp
)->errno
;
334 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);