]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp.c
cc5a44e2354267efab0b02679035f3b84c570e7b
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
33 * Modified for MP, 1996 by Tuyen Nguyen
34 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
37 #include <sys/errno.h>
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <machine/spl.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
44 #include <sys/filedesc.h>
45 #include <sys/fcntl.h>
47 #include <sys/socket.h>
49 #include <netat/sysglue.h>
50 #include <netat/appletalk.h>
51 #include <netat/at_pcb.h>
52 #include <netat/ddp.h>
53 #include <netat/adsp.h>
54 #include <netat/adsp_internal.h>
57 struct adsp_debug adsp_dtable
[1025];
63 register gref_t
*gref
; /* READ queue */
68 if (!(ccb_mp
= gbuf_alloc(sizeof(CCB
), PRI_LO
))) {
71 bzero((caddr_t
) gbuf_rptr(ccb_mp
), sizeof(CCB
));
72 gbuf_wset(ccb_mp
,sizeof(CCB
));
73 gref
->info
= (caddr_t
) ccb_mp
;
74 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
76 sp
->pid
= gref
->pid
; /* save the caller process pointer */
77 sp
->gref
= gref
; /* save a back pointer to the WRITE queue */
78 sp
->sp_mp
= ccb_mp
; /* and its message block */
83 register gref_t
*gref
; /* READ queue */
88 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
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 if (sp
->state
== sListening
)
95 CompleteQueue(&sp
->opb
, errAborted
);
96 sp
->removing
= 1; /* Prevent allowing another dspClose. */
97 DoClose(sp
, errAborted
, 0); /* will remove CCB */
99 } else { /* sClosing & sOpen */
100 sp
->state
= sClosing
;
103 if (CheckOkToClose(sp
)) { /* going to close */
104 sp
->sendCtl
= B_CTL_CLOSE
; /* Send close advice */
106 CheckSend(sp
); /* try one more time to send out data */
107 if (sp
->state
!= sClosed
)
108 sp
->sendCtl
= B_CTL_CLOSE
; /* Setup to send close advice */
110 CheckSend(sp
); /* and force out the close */
111 sp
->removing
= 1; /* Prevent allowing another dspClose. */
113 DoClose(sp
, errAborted
, 0); /* to closed and remove CCB */
120 adspWriteHandler(gref
, mp
)
121 gref_t
*gref
; /* WRITE queue */
125 register ioc_t
*iocbp
;
126 register struct adspcmd
*ap
;
130 switch(gbuf_type(mp
)) {
132 if (gref
->info
== 0) {
137 * Fill in the global stuff
139 ap
= (struct adspcmd
*)gbuf_rptr(mp
);
143 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
146 if ((error
= adspWrite(sp
, ap
)))
150 if ((error
= adspAttention(sp
, ap
)))
155 if (gref
->info
== 0) {
156 adspioc_ack(EPROTOTYPE
, mp
, gref
);
159 iocbp
= (ioc_t
*) gbuf_rptr(mp
);
160 if (ADSP_IOCTL(iocbp
->ioc_cmd
)) {
161 iocbp
->ioc_count
= sizeof(*ap
) - 1;
162 if (gbuf_cont(mp
) == 0) {
163 adspioc_ack(EINVAL
, mp
, gref
);
166 ap
= (struct adspcmd
*) gbuf_rptr(gbuf_cont(mp
));
168 ap
->ioc
= (caddr_t
) mp
;
169 ap
->mp
= gbuf_cont(mp
); /* request head */
172 if ((gref
->info
== 0) && ((iocbp
->ioc_cmd
!= ADSPOPEN
) &&
173 (iocbp
->ioc_cmd
!= ADSPCLLISTEN
))) {
174 ap
->ioResult
= errState
;
176 adspioc_ack(EINVAL
, mp
, gref
);
180 return(STR_PUTNEXT
); /* pass it on down */
181 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
182 switch(iocbp
->ioc_cmd
) {
185 ap
->socket
= ((CCBPtr
)sp
)->localSocket
;
186 flag
= (adspMode(ap
) == ocAccept
) ? 1 : 0;
187 if (flag
&& ap
->socket
) {
188 if (adspDeassignSocket((CCBPtr
)sp
) >= 0)
191 if ((ap
->socket
== 0) &&
193 (at_socket
)adspAssignSocket(gref
, flag
)) == 0)) {
194 adspioc_ack(EADDRNOTAVAIL
, mp
, gref
);
197 ap
->csCode
= iocbp
->ioc_cmd
== ADSPOPEN
? dspInit
: dspCLInit
;
198 if ((error
= adspInit(sp
, ap
)) == 0) {
201 /* and open the connection */
202 ap
->csCode
= dspOpen
;
203 error
= adspOpen(sp
, ap
);
207 ap
->csCode
= dspCLListen
;
208 error
= adspCLListen(sp
, ap
);
213 adspioc_ack(error
, mp
, gref
); /* if this failed req complete */
216 ap
->csCode
= dspClose
;
217 if ((error
= adspClose(sp
, ap
))) {
218 adspioc_ack(error
, mp
, gref
);
223 ap
->csCode
= dspCLRemove
;
224 error
= adspClose(sp
, ap
);
225 adspioc_ack(error
, mp
, gref
);
228 ap
->csCode
= dspCLDeny
;
229 if ((error
= adspCLDeny(sp
, ap
))) {
230 adspioc_ack(error
, mp
, gref
);
234 ap
->csCode
= dspStatus
;
235 if ((error
= adspStatus(sp
, ap
))) {
236 adspioc_ack(error
, mp
, gref
);
240 ap
->csCode
= dspRead
;
241 if ((error
= adspRead(sp
, ap
))) {
242 adspioc_ack(error
, mp
, gref
);
246 ap
->csCode
= dspAttention
;
247 if ((error
= adspReadAttention(sp
, ap
))) {
248 adspioc_ack(error
, mp
, gref
);
252 ap
->csCode
= dspOptions
;
253 if ((error
= adspOptions(sp
, ap
))) {
254 adspioc_ack(error
, mp
, gref
);
258 ap
->csCode
= dspReset
;
259 if ((error
= adspReset(sp
, ap
))) {
260 adspioc_ack(error
, mp
, gref
);
264 ap
->csCode
= dspNewCID
;
265 if ((error
= adspNewCID(sp
, ap
))) {
266 adspioc_ack(error
, mp
, gref
);
270 return(STR_PUTNEXT
); /* pass it on down */
280 adspReadHandler(gref
, mp
)
286 switch(gbuf_type(mp
)) {
288 if ((error
= adspPacket(gref
, mp
))) {
305 * This procedure a formats a DDP datagram header and calls the
306 * DDP module to queue it for routing and transmission according to
307 * the DDP parameters. We always take control of the datagram;
308 * if there is an error we free it, otherwise we pass it to the next
309 * layer. We don't need to set the src address fileds because the
310 * DDP layer fills these in for us.
313 * ret_status = adsp_sendddp(q, sp, mp, length, dstnetaddr, ddptype);
316 * sp Caller stream pointer
317 * mp gbuf_t chain containing the datagram to transmit
318 * The first mblk contains the ADSP header and space
319 * for the DDP header.
320 * length size of data portion of datagram
321 * dstnetaddr address of 4-byte destination internet address
322 * ddptype DDP protocol to assign to the datagram
325 * 0 Procedure successful completed.
326 * EMSGSIZE Specified datagram length is too big.
332 adsp_sendddp(sp
, mp
, length
, dstnetaddr
, ddptype
)
336 AddrUnion
*dstnetaddr
;
345 if (length
> DDP_DATA_SIZE
) {
353 length
= gbuf_msgsize(mp
) - DDPL_FRAME_LEN
;
354 /* Set up the DDP header */
356 ddp
= (DDPX_FRAME
*) gbuf_rptr(mp
);
357 UAS_ASSIGN_HTON(ddp
->ddpx_length
, (length
+ DDPL_FRAME_LEN
));
358 UAS_ASSIGN(ddp
->ddpx_cksm
, 0);
361 UAS_ASSIGN_HTON(ddp
->ddpx_cksm
, 1);
364 NET_ASSIGN(ddp
->ddpx_dnet
, dstnetaddr
->a
.net
);
365 ddp
->ddpx_dnode
= dstnetaddr
->a
.node
;
366 ddp
->ddpx_source
= sp
? sp
->localSocket
: ddp
->ddpx_dest
;
367 ddp
->ddpx_dest
= dstnetaddr
->a
.socket
;
369 ddp
->ddpx_type
= ddptype
;
384 pidsig(sp->pid, SIGIO);
392 pidsig(sp->pid, SIGURG);