]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp.c
f32217bd6311888111efac6ee544c0a6c38fa526
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
26 * Modified for MP, 1996 by Tuyen Nguyen
27 * Modified, April 9, 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/socket.h>
42 #include <netat/sysglue.h>
43 #include <netat/appletalk.h>
44 #include <netat/at_pcb.h>
45 #include <netat/ddp.h>
46 #include <netat/adsp.h>
47 #include <netat/adsp_internal.h>
50 struct adsp_debug adsp_dtable
[1025];
54 extern atlock_t adspgen_lock
;
57 register gref_t
*gref
; /* READ queue */
62 if (!(ccb_mp
= gbuf_alloc(sizeof(CCB
), PRI_LO
))) {
65 bzero((caddr_t
) gbuf_rptr(ccb_mp
), sizeof(CCB
));
66 gbuf_wset(ccb_mp
,sizeof(CCB
));
67 gref
->info
= (caddr_t
) ccb_mp
;
68 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
70 sp
->pid
= gref
->pid
; /* save the caller process pointer */
71 sp
->gref
= gref
; /* save a back pointer to the WRITE queue */
72 sp
->sp_mp
= ccb_mp
; /* and its message block */
74 ATLOCKINIT(sp
->lockClose
);
75 ATLOCKINIT(sp
->lockRemove
);
80 register gref_t
*gref
; /* READ queue */
85 ATDISABLE(l
, adspgen_lock
);
87 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
88 ATDISABLE(s
, sp
->lock
);
89 ATENABLE(s
, adspgen_lock
);
90 /* Tells completion routine of close */
91 /* packet to remove us. */
93 if (sp
->state
== sPassive
|| sp
->state
== sClosed
||
94 sp
->state
== sOpening
|| sp
->state
== sListening
) {
95 ATENABLE(l
, sp
->lock
);
96 if (sp
->state
== sListening
)
97 CompleteQueue(&sp
->opb
, errAborted
);
98 sp
->removing
= 1; /* Prevent allowing another dspClose. */
99 DoClose(sp
, errAborted
, 0); /* will remove CCB */
101 } else { /* sClosing & sOpen */
102 sp
->state
= sClosing
;
104 ATENABLE(l
, sp
->lock
);
106 if (CheckOkToClose(sp
)) { /* going to close */
107 sp
->sendCtl
= B_CTL_CLOSE
; /* Send close advice */
109 CheckSend(sp
); /* try one more time to send out data */
110 if (sp
->state
!= sClosed
)
111 sp
->sendCtl
= B_CTL_CLOSE
; /* Setup to send close advice */
113 CheckSend(sp
); /* and force out the close */
114 ATDISABLE(s
, sp
->lock
);
115 sp
->removing
= 1; /* Prevent allowing another dspClose. */
117 ATENABLE(s
, sp
->lock
);
118 DoClose(sp
, errAborted
, 0); /* to closed and remove CCB */
120 ATENABLE(l
, adspgen_lock
);
126 adspWriteHandler(gref
, mp
)
127 gref_t
*gref
; /* WRITE queue */
131 register ioc_t
*iocbp
;
132 register struct adspcmd
*ap
;
136 switch(gbuf_type(mp
)) {
138 if (gref
->info
== 0) {
143 * Fill in the global stuff
145 ap
= (struct adspcmd
*)gbuf_rptr(mp
);
149 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
152 if ((error
= adspWrite(sp
, ap
)))
156 if ((error
= adspAttention(sp
, ap
)))
161 if (gref
->info
== 0) {
162 adspioc_ack(EPROTOTYPE
, mp
, gref
);
165 iocbp
= (ioc_t
*) gbuf_rptr(mp
);
166 if (ADSP_IOCTL(iocbp
->ioc_cmd
)) {
167 iocbp
->ioc_count
= sizeof(*ap
) - 1;
168 if (gbuf_cont(mp
) == 0) {
169 adspioc_ack(EINVAL
, mp
, gref
);
172 ap
= (struct adspcmd
*) gbuf_rptr(gbuf_cont(mp
));
174 ap
->ioc
= (caddr_t
) mp
;
175 ap
->mp
= gbuf_cont(mp
); /* request head */
178 if ((gref
->info
== 0) && ((iocbp
->ioc_cmd
!= ADSPOPEN
) &&
179 (iocbp
->ioc_cmd
!= ADSPCLLISTEN
))) {
180 ap
->ioResult
= errState
;
182 adspioc_ack(EINVAL
, mp
, gref
);
186 return(STR_PUTNEXT
); /* pass it on down */
187 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
188 switch(iocbp
->ioc_cmd
) {
191 ap
->socket
= ((CCBPtr
)sp
)->localSocket
;
192 flag
= (adspMode(ap
) == ocAccept
) ? 1 : 0;
193 if (flag
&& ap
->socket
) {
194 if (adspDeassignSocket((CCBPtr
)sp
) >= 0)
197 if ((ap
->socket
== 0) &&
199 (at_socket
)adspAssignSocket(gref
, flag
)) == 0)) {
200 adspioc_ack(EADDRNOTAVAIL
, mp
, gref
);
203 ap
->csCode
= iocbp
->ioc_cmd
== ADSPOPEN
? dspInit
: dspCLInit
;
204 if ((error
= adspInit(sp
, ap
)) == 0) {
207 /* and open the connection */
208 ap
->csCode
= dspOpen
;
209 error
= adspOpen(sp
, ap
);
213 ap
->csCode
= dspCLListen
;
214 error
= adspCLListen(sp
, ap
);
219 adspioc_ack(error
, mp
, gref
); /* if this failed req complete */
222 ap
->csCode
= dspClose
;
223 if ((error
= adspClose(sp
, ap
))) {
224 adspioc_ack(error
, mp
, gref
);
229 ap
->csCode
= dspCLRemove
;
230 error
= adspClose(sp
, ap
);
231 adspioc_ack(error
, mp
, gref
);
234 ap
->csCode
= dspCLDeny
;
235 if ((error
= adspCLDeny(sp
, ap
))) {
236 adspioc_ack(error
, mp
, gref
);
240 ap
->csCode
= dspStatus
;
241 if ((error
= adspStatus(sp
, ap
))) {
242 adspioc_ack(error
, mp
, gref
);
246 ap
->csCode
= dspRead
;
247 if ((error
= adspRead(sp
, ap
))) {
248 adspioc_ack(error
, mp
, gref
);
252 ap
->csCode
= dspAttention
;
253 if ((error
= adspReadAttention(sp
, ap
))) {
254 adspioc_ack(error
, mp
, gref
);
258 ap
->csCode
= dspOptions
;
259 if ((error
= adspOptions(sp
, ap
))) {
260 adspioc_ack(error
, mp
, gref
);
264 ap
->csCode
= dspReset
;
265 if ((error
= adspReset(sp
, ap
))) {
266 adspioc_ack(error
, mp
, gref
);
270 ap
->csCode
= dspNewCID
;
271 if ((error
= adspNewCID(sp
, ap
))) {
272 adspioc_ack(error
, mp
, gref
);
276 return(STR_PUTNEXT
); /* pass it on down */
286 adspReadHandler(gref
, mp
)
292 switch(gbuf_type(mp
)) {
294 if ((error
= adspPacket(gref
, mp
))) {
311 * This procedure a formats a DDP datagram header and calls the
312 * DDP module to queue it for routing and transmission according to
313 * the DDP parameters. We always take control of the datagram;
314 * if there is an error we free it, otherwise we pass it to the next
315 * layer. We don't need to set the src address fileds because the
316 * DDP layer fills these in for us.
319 * ret_status = adsp_sendddp(q, sp, mp, length, dstnetaddr, ddptype);
322 * sp Caller stream pointer
323 * mp gbuf_t chain containing the datagram to transmit
324 * The first mblk contains the ADSP header and space
325 * for the DDP header.
326 * length size of data portion of datagram
327 * dstnetaddr address of 4-byte destination internet address
328 * ddptype DDP protocol to assign to the datagram
331 * 0 Procedure successful completed.
332 * EMSGSIZE Specified datagram length is too big.
338 adsp_sendddp(sp
, mp
, length
, dstnetaddr
, ddptype
)
342 AddrUnion
*dstnetaddr
;
351 if (length
> DDP_DATA_SIZE
) {
359 length
= gbuf_msgsize(mp
) - DDPL_FRAME_LEN
;
360 /* Set up the DDP header */
362 ddp
= (DDPX_FRAME
*) gbuf_rptr(mp
);
363 UAS_ASSIGN(ddp
->ddpx_length
, (length
+ DDPL_FRAME_LEN
));
364 UAS_ASSIGN(ddp
->ddpx_cksm
, 0);
367 UAS_ASSIGN(ddp
->ddpx_cksm
, 1);
370 NET_ASSIGN(ddp
->ddpx_dnet
, dstnetaddr
->a
.net
);
371 ddp
->ddpx_dnode
= dstnetaddr
->a
.node
;
372 ddp
->ddpx_source
= sp
? sp
->localSocket
: ddp
->ddpx_dest
;
373 ddp
->ddpx_dest
= dstnetaddr
->a
.socket
;
375 ddp
->ddpx_type
= ddptype
;
390 pidsig(sp->pid, SIGIO);
398 pidsig(sp->pid, SIGURG);