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