]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_attention.c
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / netat / adsp_attention.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * dspAttention.c
25 *
26 * From Mike Shoemaker v01.05 03/16/90 mbs
27 */
28 /*
29 * Change log:
30 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
31 * Modified for MP, 1996 by Tuyen Nguyen
32 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
33 */
34
35 #include <sys/errno.h>
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <machine/spl.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/proc.h>
42 #include <sys/filedesc.h>
43 #include <sys/fcntl.h>
44 #include <sys/mbuf.h>
45 #include <sys/socket.h>
46
47 #include <netat/sysglue.h>
48 #include <netat/appletalk.h>
49 #include <netat/at_pcb.h>
50 #include <netat/debug.h>
51 #include <netat/adsp.h>
52 #include <netat/adsp_internal.h>
53
54 /*
55 * dspAttention
56 *
57 * INPUTS:
58 * --> ccbRefNum refnum of connection end
59 * --> attnCode client attention code
60 * --> attnSize size in bytes of attention data
61 * --> attnData pointer to attention data
62 * --> attnInterval attention retransmit interval
63 * (ignored by ADSP 1.5 & up)
64 *
65 * OUTPUTS:
66 * none
67 *
68 * ERRORS:
69 * errRefNum bad connection refnum
70 * errState connection is not open
71 * errAttention attention message too long
72 * errAborted request aborted by Remove or Close call
73 */
74 int adspAttention(register struct adspcmd *pb, register CCBPtr sp)
75 {
76 int s;
77 register gbuf_t *mp, *nmp;
78 unsigned char uerr;
79
80 if (sp == 0) {
81 pb->ioResult = errRefNum;
82 return EINVAL;
83 }
84
85 if (sp->state != sOpen) { /* If we're not open, tell user to go away */
86 pb->ioResult = errState;
87 uerr = ENOTCONN;
88 l_err:
89 atalk_notify(sp->gref, uerr);
90 gbuf_freem(pb->mp);
91 return 0;
92 }
93
94 if (pb->u.attnParams.attnSize > attnBufSize) /* If data too big, bye-bye */
95 {
96 pb->ioResult = errAttention;
97 uerr = ERANGE;
98 goto l_err;
99 }
100
101 /* The 1st mbuf in the pb->mp chain (mp) is the adspcmd structure.
102 The 2nd mbuf (nmp) will be the beginning of the data. */
103 mp = pb->mp;
104 if (pb->u.attnParams.attnSize) {
105 nmp = gbuf_cont(mp);
106 if (gbuf_len(mp) > sizeof(struct adspcmd)) {
107 if ((nmp = gbuf_dupb(mp)) == 0) {
108 gbuf_wset(mp, sizeof(struct adspcmd));
109 uerr = ENOBUFS;
110 goto l_err;
111 }
112 gbuf_wset(mp, sizeof(struct adspcmd));
113 gbuf_rinc(nmp, sizeof(struct adspcmd));
114 gbuf_cont(nmp) = gbuf_cont(mp);
115 gbuf_cont(mp) = nmp;
116 }
117 }
118 pb->ioDirection = 1; /* outgoing attention data */
119 ATDISABLE(s, sp->lock);
120 if (sp->sapb) { /* Pending attentions already? */
121 qAddToEnd(&sp->sapb, pb); /* Just add to end of queue */
122 ATENABLE(s, sp->lock);
123 } else {
124 sp->sendAttnData = 1; /* Start off this attention */
125 pb->qLink = 0;
126 sp->sapb = pb;
127 ATENABLE(s, sp->lock);
128 CheckSend(sp);
129 }
130 pb->ioResult = 1; /* indicate that the IO is not complete */
131 return 0;
132 }