]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * dspAttention.c | |
27 | * | |
28 | * From Mike Shoemaker v01.05 03/16/90 mbs | |
29 | */ | |
30 | /* | |
31 | * Change log: | |
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. | |
35 | */ | |
36 | ||
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> | |
43 | #include <sys/proc.h> | |
44 | #include <sys/filedesc.h> | |
45 | #include <sys/fcntl.h> | |
46 | #include <sys/mbuf.h> | |
47 | #include <sys/socket.h> | |
48 | ||
49 | #include <netat/sysglue.h> | |
50 | #include <netat/appletalk.h> | |
51 | #include <netat/at_pcb.h> | |
52 | #include <netat/debug.h> | |
53 | #include <netat/adsp.h> | |
54 | #include <netat/adsp_internal.h> | |
55 | ||
56 | /* | |
57 | * dspAttention | |
58 | * | |
59 | * INPUTS: | |
60 | * --> ccbRefNum refnum of connection end | |
61 | * --> attnCode client attention code | |
62 | * --> attnSize size in bytes of attention data | |
63 | * --> attnData pointer to attention data | |
64 | * --> attnInterval attention retransmit interval | |
65 | * (ignored by ADSP 1.5 & up) | |
66 | * | |
67 | * OUTPUTS: | |
68 | * none | |
69 | * | |
70 | * ERRORS: | |
71 | * errRefNum bad connection refnum | |
72 | * errState connection is not open | |
73 | * errAttention attention message too long | |
74 | * errAborted request aborted by Remove or Close call | |
75 | */ | |
76 | int adspAttention(sp, pb) /* (DSPPBPtr pb) */ | |
77 | register struct adspcmd *pb; | |
78 | register CCBPtr sp; | |
79 | { | |
80 | int s; | |
81 | register gbuf_t *mp, *nmp; | |
82 | unsigned char uerr; | |
83 | ||
84 | if (sp == 0) { | |
85 | pb->ioResult = errRefNum; | |
86 | return EINVAL; | |
87 | } | |
88 | ||
89 | if (sp->state != sOpen) { /* If we're not open, tell user to go away */ | |
90 | pb->ioResult = errState; | |
91 | uerr = ENOTCONN; | |
92 | l_err: | |
93 | atalk_notify(sp->gref, uerr); | |
94 | gbuf_freem(pb->mp); | |
95 | return 0; | |
96 | } | |
97 | ||
98 | if (pb->u.attnParams.attnSize > attnBufSize) /* If data too big, bye-bye */ | |
99 | { | |
100 | pb->ioResult = errAttention; | |
101 | uerr = ERANGE; | |
102 | goto l_err; | |
103 | } | |
104 | ||
105 | /* The 1st mbuf in the pb->mp chain (mp) is the adspcmd structure. | |
106 | The 2nd mbuf (nmp) will be the beginning of the data. */ | |
107 | mp = pb->mp; | |
108 | if (pb->u.attnParams.attnSize) { | |
109 | nmp = gbuf_cont(mp); | |
110 | if (gbuf_len(mp) > sizeof(struct adspcmd)) { | |
111 | if ((nmp = gbuf_dupb(mp)) == 0) { | |
112 | gbuf_wset(mp, sizeof(struct adspcmd)); | |
113 | uerr = ENOBUFS; | |
114 | goto l_err; | |
115 | } | |
116 | gbuf_wset(mp, sizeof(struct adspcmd)); | |
117 | gbuf_rinc(nmp, sizeof(struct adspcmd)); | |
118 | gbuf_cont(nmp) = gbuf_cont(mp); | |
119 | gbuf_cont(mp) = nmp; | |
120 | } | |
121 | } | |
122 | pb->ioDirection = 1; /* outgoing attention data */ | |
123 | ATDISABLE(s, sp->lock); | |
124 | if (sp->sapb) { /* Pending attentions already? */ | |
125 | qAddToEnd(&sp->sapb, pb); /* Just add to end of queue */ | |
126 | ATENABLE(s, sp->lock); | |
127 | } else { | |
128 | sp->sendAttnData = 1; /* Start off this attention */ | |
129 | pb->qLink = 0; | |
130 | sp->sapb = pb; | |
131 | ATENABLE(s, sp->lock); | |
132 | CheckSend(sp); | |
133 | } | |
134 | pb->ioResult = 1; /* indicate that the IO is not complete */ | |
135 | return 0; | |
136 | } |