]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/sys_dep.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / netat / sys_dep.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
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
13 * file.
14 *
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
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.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Copyright (c) 1995-1998 Apple Computer, Inc.
27 *
28 * Change Log:
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.
32 */
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>
39#include <sys/proc.h>
40#include <sys/filedesc.h>
41#include <sys/fcntl.h>
42#include <sys/mbuf.h>
43#include <sys/malloc.h>
44#include <sys/file.h>
45#include <sys/socket.h>
46#include <sys/socketvar.h>
47#include <net/if_var.h>
48
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>
54
55int (*sys_ATsocket)() = 0;
56int (*sys_ATgetmsg)() = 0;
57int (*sys_ATputmsg)() = 0;
58int (*sys_ATPsndreq)() = 0;
59int (*sys_ATPsndrsp)() = 0;
60int (*sys_ATPgetreq)() = 0;
61int (*sys_ATPgetrsp)() = 0;
62
63extern at_state_t at_state; /* global state of AT network */
64extern at_ifaddr_t *ifID_home; /* default interface */
65
66int ATsocket(proc, uap, retval)
67 void *proc;
68 struct {
69 int proto;
70 } *uap;
71 int *retval;
72{
73 int err;
74
75 if (sys_ATsocket) {
76 /* required check for all AppleTalk system calls */
77 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
78 *retval = -1;
79 err = ENOTREADY;
80 } else {
81 *retval = (*sys_ATsocket)(uap->proto, &err, proc);
82 }
83 } else {
84 *retval = -1;
85 err = ENXIO;
86 }
87 return err;
88}
89
90int ATgetmsg(proc, uap, retval)
91 void *proc;
92 struct {
93 int fd;
94 void *ctlptr;
95 void *datptr;
96 int *flags;
97 } *uap;
98 int *retval;
99{
100 int err;
101
102 if (sys_ATgetmsg) {
103 /* required check for all AppleTalk system calls */
104 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
105 *retval = -1;
106 err = ENOTREADY;
107 } else {
108 *retval =
109 (*sys_ATgetmsg)(uap->fd, uap->ctlptr, uap->datptr,
110 uap->flags, &err, proc);
111 }
112 } else {
113 *retval = -1;
114 err = ENXIO;
115 }
116 return err;
117}
118
119int ATputmsg(proc, uap, retval)
120 void *proc;
121 struct {
122 int fd;
123 void *ctlptr;
124 void *datptr;
125 int flags;
126 } *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
148int ATPsndreq(proc, uap, retval)
149 void *proc;
150 struct {
151 int fd;
152 unsigned char *buf;
153 int len;
154 int nowait;
155 } *uap;
156 int *retval;
157{
158 int err;
159
160 if (sys_ATPsndreq) {
161 /* required check for all AppleTalk system calls */
162 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
163 *retval = -1;
164 err = ENOTREADY;
165 } else {
166 *retval =
167 (*sys_ATPsndreq)(uap->fd, uap->buf, uap->len,
168 uap->nowait, &err, proc);
169 }
170 } else {
171 *retval = -1;
172 err= ENXIO;
173 }
174 return err;
175}
176
177int ATPsndrsp(proc, uap, retval)
178 void *proc;
179 struct {
180 int fd;
181 unsigned char *respbuff;
182 int resplen;
183 int datalen;
184 } *uap;
185 int *retval;
186{
187 int err;
188
189 if (sys_ATPsndrsp) {
190 /* required check for all AppleTalk system calls */
191 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
192 *retval = -1;
193 err = ENOTREADY;
194 } else {
195 *retval =
196 (*sys_ATPsndrsp)(uap->fd, uap->respbuff,
197 uap->resplen, uap->datalen, &err, proc);
198 }
199 } else {
200 *retval = -1;
201 err = ENXIO;
202 }
203 return err;
204}
205
206int ATPgetreq(proc, uap, retval)
207 void *proc;
208 struct {
209 int fd;
210 unsigned char *buf;
211 int buflen;
212 } *uap;
213 int *retval;
214{
215 int err;
216
217 if (sys_ATPgetreq) {
218 /* required check for all AppleTalk system calls */
219 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
220 *retval = -1;
221 err = ENOTREADY;
222 } else {
223 *retval =
224 (*sys_ATPgetreq)(uap->fd, uap->buf, uap->buflen,
225 &err, proc);
226 }
227 } else {
228 *retval = -1;
229 err = ENXIO;
230 }
231 return err;
232}
233
234int ATPgetrsp(proc, uap, retval)
235 void *proc;
236 struct {
237 int fd;
238 unsigned char *bdsp;
239 } *uap;
240 int *retval;
241{
242 int err = 0;
243
244 if (sys_ATPgetrsp) {
245 /* required check for all AppleTalk system calls */
246 if (!(at_state.flags & AT_ST_STARTED) || !ifID_home) {
247 *retval = -1;
248 err = ENOTREADY;
249 } else {
250 *retval =
251 (*sys_ATPgetrsp)(uap->fd, uap->bdsp, &err, proc);
252 }
253 } else {
254 *retval = -1;
255 err = ENXIO;
256 }
257 return err;
258}
259
260int atalk_closeref(fp, grefp)
261 struct file *fp;
262 gref_t **grefp;
263{
264 if ((*grefp = (gref_t *)fp->f_data)) {
265 fp->f_data = 0;
266/*
267 kprintf("atalk_closeref: fp = 0x%x, gref = 0x%x\n", (u_int)fp,
268 (u_int)*grefp);
269*/
270 return(0);
271 }
272 return(EBADF);
273}
274
275int atalk_openref(gref, retfd, proc)
276 gref_t *gref;
277 int *retfd;
278 struct proc *proc;
279{
280 extern int _ATread(), _ATwrite(),_ATioctl(), _ATselect(), _ATclose();
281 static struct fileops fileops =
282 {_ATread, _ATwrite, _ATioctl, _ATselect, _ATclose};
283 int err, fd;
284 struct file *fp;
285
286 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
287
288 if ((err = falloc(proc, &fp, &fd)) != 0) {
289 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
290 return err;
291 }
292
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...
296 */
297 fp->f_type = DTYPE_ATALK+1;
298 fp->f_ops = &fileops;
299 *fdflags(proc, fd) &= ~UF_RESERVED;
300 *retfd = fd;
301 fp->f_data = (void *)gref;
302/*
303 kprintf("atalk_openref: fp = 0x%x, gref = 0x%x\n", (u_int)fp, (u_int)gref);
304*/
305 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
306 return 0;
307}
308
309/* go from file descriptor to gref, which has been saved in fp->f_data */
310int atalk_getref(fp, fd, grefp, proc)
311struct file *fp;
312int fd;
313gref_t **grefp;
314struct proc *proc;
315{
316 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
317 if (fp == 0) {
318 int error = fdgetf(proc, fd, &fp);
319
320 if (error) {
321
322 *grefp = (gref_t *) 0;
323 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
324 return EBADF;
325 }
326 }
de355530 327 if ((*grefp = (gref_t *)fp->f_data) == 0) {
1c79356b
A
328 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
329 return EBADF;
330 }
331
332 if ((*grefp)->errno) {
333 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
334 return (int)(*grefp)->errno;
335 }
336
337 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
338 return 0;
339}