]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp.c
02d01c9632c7d41d98f59d3e5ddfe5cb67cdf84c
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@
24 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
25 * Modified for MP, 1996 by Tuyen Nguyen
26 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
29 #include <sys/errno.h>
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <machine/spl.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
36 #include <sys/filedesc.h>
37 #include <sys/fcntl.h>
39 #include <sys/socket.h>
41 #include <netat/sysglue.h>
42 #include <netat/appletalk.h>
43 #include <netat/at_pcb.h>
44 #include <netat/ddp.h>
45 #include <netat/adsp.h>
46 #include <netat/adsp_internal.h>
49 struct adsp_debug adsp_dtable
[1025];
53 extern atlock_t adspgen_lock
;
56 register gref_t
*gref
; /* READ queue */
61 if (!(ccb_mp
= gbuf_alloc(sizeof(CCB
), PRI_LO
))) {
64 bzero((caddr_t
) gbuf_rptr(ccb_mp
), sizeof(CCB
));
65 gbuf_wset(ccb_mp
,sizeof(CCB
));
66 gref
->info
= (caddr_t
) ccb_mp
;
67 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
69 sp
->pid
= gref
->pid
; /* save the caller process pointer */
70 sp
->gref
= gref
; /* save a back pointer to the WRITE queue */
71 sp
->sp_mp
= ccb_mp
; /* and its message block */
73 ATLOCKINIT(sp
->lockClose
);
74 ATLOCKINIT(sp
->lockRemove
);
79 register gref_t
*gref
; /* READ queue */
84 ATDISABLE(l
, adspgen_lock
);
86 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
87 ATDISABLE(s
, sp
->lock
);
88 ATENABLE(s
, adspgen_lock
);
89 /* Tells completion routine of close */
90 /* packet to remove us. */
92 if (sp
->state
== sPassive
|| sp
->state
== sClosed
||
93 sp
->state
== sOpening
|| sp
->state
== sListening
) {
94 ATENABLE(l
, sp
->lock
);
95 if (sp
->state
== sListening
)
96 CompleteQueue(&sp
->opb
, errAborted
);
97 sp
->removing
= 1; /* Prevent allowing another dspClose. */
98 DoClose(sp
, errAborted
, 0); /* will remove CCB */
100 } else { /* sClosing & sOpen */
101 sp
->state
= sClosing
;
103 ATENABLE(l
, sp
->lock
);
105 if (CheckOkToClose(sp
)) { /* going to close */
106 sp
->sendCtl
= B_CTL_CLOSE
; /* Send close advice */
108 CheckSend(sp
); /* try one more time to send out data */
109 if (sp
->state
!= sClosed
)
110 sp
->sendCtl
= B_CTL_CLOSE
; /* Setup to send close advice */
112 CheckSend(sp
); /* and force out the close */
113 ATDISABLE(s
, sp
->lock
);
114 sp
->removing
= 1; /* Prevent allowing another dspClose. */
116 ATENABLE(s
, sp
->lock
);
117 DoClose(sp
, errAborted
, 0); /* to closed and remove CCB */
119 ATENABLE(l
, adspgen_lock
);
125 adspWriteHandler(gref
, mp
)
126 gref_t
*gref
; /* WRITE queue */
130 register ioc_t
*iocbp
;
131 register struct adspcmd
*ap
;
135 switch(gbuf_type(mp
)) {
137 if (gref
->info
== 0) {
142 * Fill in the global stuff
144 ap
= (struct adspcmd
*)gbuf_rptr(mp
);
148 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
151 if ((error
= adspWrite(sp
, ap
)))
155 if ((error
= adspAttention(sp
, ap
)))
160 if (gref
->info
== 0) {
161 adspioc_ack(EPROTO
, mp
, gref
);
164 iocbp
= (ioc_t
*) gbuf_rptr(mp
);
165 if (ADSP_IOCTL(iocbp
->ioc_cmd
)) {
166 iocbp
->ioc_count
= sizeof(*ap
) - 1;
167 if (gbuf_cont(mp
) == 0) {
168 adspioc_ack(EINVAL
, mp
, gref
);
171 ap
= (struct adspcmd
*) gbuf_rptr(gbuf_cont(mp
));
173 ap
->ioc
= (caddr_t
) mp
;
174 ap
->mp
= gbuf_cont(mp
); /* request head */
177 if ((gref
->info
== 0) && ((iocbp
->ioc_cmd
!= ADSPOPEN
) &&
178 (iocbp
->ioc_cmd
!= ADSPCLLISTEN
))) {
179 ap
->ioResult
= errState
;
181 adspioc_ack(EINVAL
, mp
, gref
);
185 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
186 switch(iocbp
->ioc_cmd
) {
189 ap
->socket
= ((CCBPtr
)sp
)->localSocket
;
190 flag
= (adspMode(ap
) == ocAccept
) ? 1 : 0;
191 if (flag
&& ap
->socket
) {
192 if (adspDeassignSocket((CCBPtr
)sp
) >= 0)
195 if ((ap
->socket
== 0) &&
197 (at_socket
)adspAssignSocket(gref
, flag
)) == 0)) {
198 adspioc_ack(EADDRNOTAVAIL
, mp
, gref
);
201 ap
->csCode
= iocbp
->ioc_cmd
== ADSPOPEN
? dspInit
: dspCLInit
;
202 if ((error
= adspInit(sp
, ap
)) == 0) {
205 /* and open the connection */
206 ap
->csCode
= dspOpen
;
207 error
= adspOpen(sp
, ap
);
211 ap
->csCode
= dspCLListen
;
212 error
= adspCLListen(sp
, ap
);
217 adspioc_ack(error
, mp
, gref
); /* if this failed req complete */
220 ap
->csCode
= dspClose
;
221 if ((error
= adspClose(sp
, ap
))) {
222 adspioc_ack(error
, mp
, gref
);
227 ap
->csCode
= dspCLRemove
;
228 error
= adspClose(sp
, ap
);
229 adspioc_ack(error
, mp
, gref
);
232 ap
->csCode
= dspCLDeny
;
233 if ((error
= adspCLDeny(sp
, ap
))) {
234 adspioc_ack(error
, mp
, gref
);
238 ap
->csCode
= dspStatus
;
239 if ((error
= adspStatus(sp
, ap
))) {
240 adspioc_ack(error
, mp
, gref
);
244 ap
->csCode
= dspRead
;
245 if ((error
= adspRead(sp
, ap
))) {
246 adspioc_ack(error
, mp
, gref
);
250 ap
->csCode
= dspAttention
;
251 if ((error
= adspReadAttention(sp
, ap
))) {
252 adspioc_ack(error
, mp
, gref
);
256 ap
->csCode
= dspOptions
;
257 if ((error
= adspOptions(sp
, ap
))) {
258 adspioc_ack(error
, mp
, gref
);
262 ap
->csCode
= dspReset
;
263 if ((error
= adspReset(sp
, ap
))) {
264 adspioc_ack(error
, mp
, gref
);
268 ap
->csCode
= dspNewCID
;
269 if ((error
= adspNewCID(sp
, ap
))) {
270 adspioc_ack(error
, mp
, gref
);
274 return(STR_PUTNEXT
); /* pass it on down */
284 adspReadHandler(gref
, mp
)
290 switch(gbuf_type(mp
)) {
292 if ((error
= adspPacket(gref
, mp
))) {
309 * This procedure a formats a DDP datagram header and calls the
310 * DDP module to queue it for routing and transmission according to
311 * the DDP parameters. We always take control of the datagram;
312 * if there is an error we free it, otherwise we pass it to the next
313 * layer. We don't need to set the src address fileds because the
314 * DDP layer fills these in for us.
317 * ret_status = adsp_sendddp(q, sp, mp, length, dstnetaddr, ddptype);
320 * sp Caller stream pointer
321 * mp gbuf_t chain containing the datagram to transmit
322 * The first mblk contains the ADSP header and space
323 * for the DDP header.
324 * length size of data portion of datagram
325 * dstnetaddr address of 4-byte destination internet address
326 * ddptype DDP protocol to assign to the datagram
329 * 0 Procedure successful completed.
330 * EMSGSIZE Specified datagram length is too big.
336 adsp_sendddp(sp
, mp
, length
, dstnetaddr
, ddptype
)
340 AddrUnion
*dstnetaddr
;
349 if (length
> DDP_DATA_SIZE
) {
357 length
= gbuf_msgsize(mp
) - DDPL_FRAME_LEN
;
358 /* Set up the DDP header */
360 ddp
= (DDPX_FRAME
*) gbuf_rptr(mp
);
361 UAS_ASSIGN(ddp
->ddpx_length
, (length
+ DDPL_FRAME_LEN
));
362 UAS_ASSIGN(ddp
->ddpx_cksm
, 0);
365 UAS_ASSIGN(ddp
->ddpx_cksm
, 1);
368 NET_ASSIGN(ddp
->ddpx_dnet
, dstnetaddr
->a
.net
);
369 ddp
->ddpx_dnode
= dstnetaddr
->a
.node
;
370 ddp
->ddpx_source
= sp
? sp
->localSocket
: ddp
->ddpx_dest
;
371 ddp
->ddpx_dest
= dstnetaddr
->a
.socket
;
373 ddp
->ddpx_type
= ddptype
;
388 pidsig(sp->pid, SIGIO);
396 pidsig(sp->pid, SIGURG);