]>
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>
36 #include <sys/proc_internal.h> /* for p_fd in fdflags */
37 #include <sys/filedesc.h>
38 #include <sys/fcntl.h>
40 #include <sys/malloc.h>
41 #include <sys/file_internal.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
44 #include <sys/sysproto.h>
45 #include <sys/kdebug.h>
46 #include <net/if_var.h>
48 #include <netat/sysglue.h>
49 #include <netat/appletalk.h>
50 #include <netat/at_var.h>
51 #include <netat/at_pcb.h>
52 #include <netat/debug.h>
54 int (*sys_ATsocket
)() = 0;
55 int (*sys_ATgetmsg
)() = 0;
56 int (*sys_ATputmsg
)() = 0;
57 int (*sys_ATPsndreq
)() = 0;
58 int (*sys_ATPsndrsp
)() = 0;
59 int (*sys_ATPgetreq
)() = 0;
60 int (*sys_ATPgetrsp
)() = 0;
62 extern at_state_t at_state
; /* global state of AT network */
63 extern at_ifaddr_t
*ifID_home
; /* default interface */
64 extern lck_mtx_t
* atalk_mutex
;
66 #define f_flag f_fglob->fg_flag
67 #define f_type f_fglob->fg_type
68 #define f_msgcount f_fglob->fg_msgcount
69 #define f_cred f_fglob->fg_cred
70 #define f_ops f_fglob->fg_ops
71 #define f_offset f_fglob->fg_offset
72 #define f_data f_fglob->fg_data
74 int ATsocket(proc
, uap
, retval
)
76 struct ATsocket_args
*uap
;
82 /* required check for all AppleTalk system calls */
83 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
87 *retval
= (*sys_ATsocket
)(uap
->proto
, &err
, proc
);
97 int ATgetmsg(proc
, uap
, retval
)
99 struct ATgetmsg_args
*uap
;
106 /* required check for all AppleTalk system calls */
107 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
112 (*sys_ATgetmsg
)(uap
->fd
, uap
->ctlptr
, uap
->datptr
,
113 uap
->flags
, &err
, proc
);
123 int ATputmsg(proc
, uap
, retval
)
125 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
);
149 int ATPsndreq(proc
, uap
, retval
)
151 struct ATPsndreq_args
*uap
;
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
);
175 int ATPsndrsp(proc
, uap
, retval
)
177 struct ATPsndrsp_args
*uap
;
184 /* required check for all AppleTalk system calls */
185 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
190 (*sys_ATPsndrsp
)(uap
->fd
, uap
->respbuff
,
191 uap
->resplen
, uap
->datalen
, &err
, proc
);
201 int ATPgetreq(proc
, uap
, retval
)
203 struct ATPgetreq_args
*uap
;
210 /* required check for all AppleTalk system calls */
211 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
216 (*sys_ATPgetreq
)(uap
->fd
, uap
->buf
, uap
->buflen
,
227 int ATPgetrsp(proc
, uap
, retval
)
229 struct ATPgetrsp_args
*uap
;
236 /* required check for all AppleTalk system calls */
237 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
242 (*sys_ATPgetrsp
)(uap
->fd
, uap
->bdsp
, &err
, proc
);
252 int atalk_closeref(fg
, grefp
)
256 if ((*grefp
= (gref_t
*)fg
->fg_data
)) {
263 int atalk_openref(gref
, retfd
, proc
)
268 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose(), _ATkqfilter();
269 static struct fileops fileops
=
270 {_ATread
, _ATwrite
, _ATioctl
, _ATselect
, _ATclose
, _ATkqfilter
, 0};
274 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
277 if ((err
= falloc_locked(proc
, &fp
, &fd
, 1)) != 0) {
282 fp
->f_flag
= FREAD
|FWRITE
;
283 /*##### LD 5/7/96 Warning: we don't have a "DTYPE_OTHER" for
284 * MacOSX, so defines DTYPE_ATALK as DTYPE_SOCKET...
286 fp
->f_type
= DTYPE_ATALK
+1;
287 fp
->f_ops
= &fileops
;
288 fp
->f_data
= (void *)gref
;
290 *fdflags(proc
, fd
) &= ~UF_RESERVED
;
292 fp_drop(proc
, fd
, fp
, 1);
295 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
301 * go from file descriptor to gref, which has been saved in fp->f_data
303 * This routine returns with an iocount on the fileproc when the fp is null
304 * as it converts fd to fileproc. Callers of this api who pass fp as null
305 * need to drop the iocount when they are done with the fp
307 int atalk_getref(fp
, fd
, grefp
, proc
, droponerr
)
317 error
= atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
);
322 int atalk_getref_locked(fp
, fd
, grefp
, proc
, droponerr
)
329 lck_mtx_assert(atalk_mutex
, LCK_MTX_ASSERT_OWNED
);
331 int error
= fp_lookup(proc
, fd
, &fp
, 1);
335 *grefp
= (gref_t
*) 0;
339 *grefp
= (gref_t
*)fp
->f_data
;
340 if (*grefp
== 0 || *grefp
== (gref_t
*)(-1)) {
342 fp_drop(proc
, fd
, fp
, 1);
343 printf("atalk_getref_locked EBADF f_data: %x\n", fp
->f_data
);
347 if ((*grefp
)->errno
) {
349 fp_drop(proc
, fd
, fp
, 1);
350 return (int)(*grefp
)->errno
;