]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp.c
1b88d6750cc4948aa6f97a53f4362716427b925b
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];
55 register gref_t
*gref
; /* READ queue */
60 if (!(ccb_mp
= gbuf_alloc(sizeof(CCB
), PRI_LO
))) {
63 bzero((caddr_t
) gbuf_rptr(ccb_mp
), sizeof(CCB
));
64 gbuf_wset(ccb_mp
,sizeof(CCB
));
65 gref
->info
= (caddr_t
) ccb_mp
;
66 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
68 sp
->pid
= gref
->pid
; /* save the caller process pointer */
69 sp
->gref
= gref
; /* save a back pointer to the WRITE queue */
70 sp
->sp_mp
= ccb_mp
; /* and its message block */
75 register gref_t
*gref
; /* READ queue */
80 sp
= (CCBPtr
)gbuf_rptr(((gbuf_t
*)gref
->info
));
81 /* Tells completion routine of close */
82 /* packet to remove us. */
84 if (sp
->state
== sPassive
|| sp
->state
== sClosed
||
85 sp
->state
== sOpening
|| sp
->state
== sListening
) {
86 if (sp
->state
== sListening
)
87 CompleteQueue(&sp
->opb
, errAborted
);
88 sp
->removing
= 1; /* Prevent allowing another dspClose. */
89 DoClose(sp
, errAborted
, 0); /* will remove CCB */
91 } else { /* sClosing & sOpen */
95 if (CheckOkToClose(sp
)) { /* going to close */
96 sp
->sendCtl
= B_CTL_CLOSE
; /* Send close advice */
98 CheckSend(sp
); /* try one more time to send out data */
99 if (sp
->state
!= sClosed
)
100 sp
->sendCtl
= B_CTL_CLOSE
; /* Setup to send close advice */
102 CheckSend(sp
); /* and force out the close */
103 sp
->removing
= 1; /* Prevent allowing another dspClose. */
105 DoClose(sp
, errAborted
, 0); /* to closed and remove CCB */
112 adspWriteHandler(gref
, mp
)
113 gref_t
*gref
; /* WRITE queue */
117 register ioc_t
*iocbp
;
118 register struct adspcmd
*ap
;
122 switch(gbuf_type(mp
)) {
124 if (gref
->info
== 0) {
129 * Fill in the global stuff
131 ap
= (struct adspcmd
*)gbuf_rptr(mp
);
135 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
138 if ((error
= adspWrite(sp
, ap
)))
142 if ((error
= adspAttention(sp
, ap
)))
147 if (gref
->info
== 0) {
148 adspioc_ack(EPROTOTYPE
, mp
, gref
);
151 iocbp
= (ioc_t
*) gbuf_rptr(mp
);
152 if (ADSP_IOCTL(iocbp
->ioc_cmd
)) {
153 iocbp
->ioc_count
= sizeof(*ap
) - 1;
154 if (gbuf_cont(mp
) == 0) {
155 adspioc_ack(EINVAL
, mp
, gref
);
158 ap
= (struct adspcmd
*) gbuf_rptr(gbuf_cont(mp
));
160 ap
->ioc
= (caddr_t
) mp
;
161 ap
->mp
= gbuf_cont(mp
); /* request head */
164 if ((gref
->info
== 0) && ((iocbp
->ioc_cmd
!= ADSPOPEN
) &&
165 (iocbp
->ioc_cmd
!= ADSPCLLISTEN
))) {
166 ap
->ioResult
= errState
;
168 adspioc_ack(EINVAL
, mp
, gref
);
172 return(STR_PUTNEXT
); /* pass it on down */
173 sp
= (void *)gbuf_rptr(((gbuf_t
*)gref
->info
));
174 switch(iocbp
->ioc_cmd
) {
177 ap
->socket
= ((CCBPtr
)sp
)->localSocket
;
178 flag
= (adspMode(ap
) == ocAccept
) ? 1 : 0;
179 if (flag
&& ap
->socket
) {
180 if (adspDeassignSocket((CCBPtr
)sp
) >= 0)
183 if ((ap
->socket
== 0) &&
185 (at_socket
)adspAssignSocket(gref
, flag
)) == 0)) {
186 adspioc_ack(EADDRNOTAVAIL
, mp
, gref
);
189 ap
->csCode
= iocbp
->ioc_cmd
== ADSPOPEN
? dspInit
: dspCLInit
;
190 if ((error
= adspInit(sp
, ap
)) == 0) {
193 /* and open the connection */
194 ap
->csCode
= dspOpen
;
195 error
= adspOpen(sp
, ap
);
199 ap
->csCode
= dspCLListen
;
200 error
= adspCLListen(sp
, ap
);
205 adspioc_ack(error
, mp
, gref
); /* if this failed req complete */
208 ap
->csCode
= dspClose
;
209 if ((error
= adspClose(sp
, ap
))) {
210 adspioc_ack(error
, mp
, gref
);
215 ap
->csCode
= dspCLRemove
;
216 error
= adspClose(sp
, ap
);
217 adspioc_ack(error
, mp
, gref
);
220 ap
->csCode
= dspCLDeny
;
221 if ((error
= adspCLDeny(sp
, ap
))) {
222 adspioc_ack(error
, mp
, gref
);
226 ap
->csCode
= dspStatus
;
227 if ((error
= adspStatus(sp
, ap
))) {
228 adspioc_ack(error
, mp
, gref
);
232 ap
->csCode
= dspRead
;
233 if ((error
= adspRead(sp
, ap
))) {
234 adspioc_ack(error
, mp
, gref
);
238 ap
->csCode
= dspAttention
;
239 if ((error
= adspReadAttention(sp
, ap
))) {
240 adspioc_ack(error
, mp
, gref
);
244 ap
->csCode
= dspOptions
;
245 if ((error
= adspOptions(sp
, ap
))) {
246 adspioc_ack(error
, mp
, gref
);
250 ap
->csCode
= dspReset
;
251 if ((error
= adspReset(sp
, ap
))) {
252 adspioc_ack(error
, mp
, gref
);
256 ap
->csCode
= dspNewCID
;
257 if ((error
= adspNewCID(sp
, ap
))) {
258 adspioc_ack(error
, mp
, gref
);
262 return(STR_PUTNEXT
); /* pass it on down */
272 adspReadHandler(gref
, mp
)
278 switch(gbuf_type(mp
)) {
280 if ((error
= adspPacket(gref
, mp
))) {
297 * This procedure a formats a DDP datagram header and calls the
298 * DDP module to queue it for routing and transmission according to
299 * the DDP parameters. We always take control of the datagram;
300 * if there is an error we free it, otherwise we pass it to the next
301 * layer. We don't need to set the src address fileds because the
302 * DDP layer fills these in for us.
305 * ret_status = adsp_sendddp(q, sp, mp, length, dstnetaddr, ddptype);
308 * sp Caller stream pointer
309 * mp gbuf_t chain containing the datagram to transmit
310 * The first mblk contains the ADSP header and space
311 * for the DDP header.
312 * length size of data portion of datagram
313 * dstnetaddr address of 4-byte destination internet address
314 * ddptype DDP protocol to assign to the datagram
317 * 0 Procedure successful completed.
318 * EMSGSIZE Specified datagram length is too big.
324 adsp_sendddp(sp
, mp
, length
, dstnetaddr
, ddptype
)
328 AddrUnion
*dstnetaddr
;
337 if (length
> DDP_DATA_SIZE
) {
345 length
= gbuf_msgsize(mp
) - DDPL_FRAME_LEN
;
346 /* Set up the DDP header */
348 ddp
= (DDPX_FRAME
*) gbuf_rptr(mp
);
349 UAS_ASSIGN_HTON(ddp
->ddpx_length
, (length
+ DDPL_FRAME_LEN
));
350 UAS_ASSIGN(ddp
->ddpx_cksm
, 0);
353 UAS_ASSIGN_HTON(ddp
->ddpx_cksm
, 1);
356 NET_ASSIGN(ddp
->ddpx_dnet
, dstnetaddr
->a
.net
);
357 ddp
->ddpx_dnode
= dstnetaddr
->a
.node
;
358 ddp
->ddpx_source
= sp
? sp
->localSocket
: ddp
->ddpx_dest
;
359 ddp
->ddpx_dest
= dstnetaddr
->a
.socket
;
361 ddp
->ddpx_type
= ddptype
;
376 pidsig(sp->pid, SIGIO);
384 pidsig(sp->pid, SIGURG);