]>
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 struct ATsocket_args
{
66 int ATsocket(proc
, uap
, retval
)
68 struct ATsocket_args
*uap
;
74 /* required check for all AppleTalk system calls */
75 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
79 *retval
= (*sys_ATsocket
)(uap
->proto
, &err
, proc
);
88 struct ATgetmsg_args
{
94 int ATgetmsg(proc
, uap
, retval
)
96 struct ATgetmsg_args
*uap
;
102 /* required check for all AppleTalk system calls */
103 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
108 (*sys_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
109 uap
->flags
, &err
, proc
);
118 struct ATputmsg_args
{
124 int ATputmsg(proc
, uap
, retval
)
126 struct ATputmsg_args
*uap
;
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 struct ATPsndreq_args
{
154 int ATPsndreq(proc
, uap
, retval
)
156 struct ATPsndreq_args
*uap
;
162 /* required check for all AppleTalk system calls */
163 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
168 (*sys_ATPsndreq
)(uap
->fd
, uap
->buf
, uap
->len
,
169 uap
->nowait
, &err
, proc
);
178 struct ATPsndrsp_args
{
180 unsigned char *respbuff
;
184 int ATPsndrsp(proc
, uap
, retval
)
186 struct ATPsndrsp_args
*uap
;
192 /* required check for all AppleTalk system calls */
193 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
198 (*sys_ATPsndrsp
)(uap
->fd
, uap
->respbuff
,
199 uap
->resplen
, uap
->datalen
, &err
, proc
);
208 struct ATPgetreq_args
{
213 int ATPgetreq(proc
, uap
, retval
)
215 struct ATPgetreq_args
*uap
;
221 /* required check for all AppleTalk system calls */
222 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
227 (*sys_ATPgetreq
)(uap
->fd
, uap
->buf
, uap
->buflen
,
237 struct ATPgetrsp_args
{
241 int ATPgetrsp(proc
, uap
, retval
)
243 struct ATPgetrsp_args
*uap
;
249 /* required check for all AppleTalk system calls */
250 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
255 (*sys_ATPgetrsp
)(uap
->fd
, uap
->bdsp
, &err
, proc
);
264 int atalk_closeref(fp
, grefp
)
268 if ((*grefp
= (gref_t
*)fp
->f_data
)) {
271 kprintf("atalk_closeref: fp = 0x%x, gref = 0x%x\n", (u_int)fp,
279 int atalk_openref(gref
, retfd
, proc
)
284 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose(), _ATkqfilter();
285 static struct fileops fileops
=
286 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
, _ATkqfilter
};
290 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
292 if ((err
= falloc(proc
, &fp
, &fd
)) != 0) {
293 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
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...
301 fp
->f_type
= DTYPE_ATALK
+1;
302 fp
->f_ops
= &fileops
;
303 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
305 fp
->f_data
= (void *)gref
;
307 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
309 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
313 /* go from file descriptor to gref, which has been saved in fp->f_data */
314 int atalk_getref(fp
, fd
, grefp
, proc
)
320 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
322 int error
= fdgetf(proc
, fd
, &fp
);
326 *grefp
= (gref_t
*) 0;
327 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
331 *grefp
= (gref_t
*)fp
->f_data
;
332 if (*grefp
== 0 || *grefp
== (gref_t
*)(-1)) {
333 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
337 if ((*grefp
)->errno
) {
338 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
339 return (int)(*grefp
)->errno
;
342 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);