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