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