]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/netat/adsp_attention.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / netat / adsp_attention.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * dspAttention.c
30 *
31 * From Mike Shoemaker v01.05 03/16/90 mbs
32 */
33/*
34 * Change log:
35 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
36 * Modified for MP, 1996 by Tuyen Nguyen
37 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
38 */
39
40#include <sys/errno.h>
41#include <sys/types.h>
42#include <sys/param.h>
43#include <machine/spl.h>
44#include <sys/systm.h>
45#include <sys/kernel.h>
46#include <sys/proc.h>
47#include <sys/filedesc.h>
48#include <sys/fcntl.h>
49#include <sys/mbuf.h>
50#include <sys/socket.h>
51
52#include <netat/sysglue.h>
53#include <netat/appletalk.h>
54#include <netat/at_pcb.h>
55#include <netat/debug.h>
56#include <netat/adsp.h>
57#include <netat/adsp_internal.h>
58
59/*
60 * dspAttention
61 *
62 * INPUTS:
63 * --> ccbRefNum refnum of connection end
64 * --> attnCode client attention code
65 * --> attnSize size in bytes of attention data
66 * --> attnData pointer to attention data
67 * --> attnInterval attention retransmit interval
68 * (ignored by ADSP 1.5 & up)
69 *
70 * OUTPUTS:
71 * none
72 *
73 * ERRORS:
74 * errRefNum bad connection refnum
75 * errState connection is not open
76 * errAttention attention message too long
77 * errAborted request aborted by Remove or Close call
78 */
79int adspAttention(register struct adspcmd *pb, register CCBPtr sp)
80{
81 int s;
82 register gbuf_t *mp, *nmp;
83 unsigned char uerr;
84
85 if (sp == 0) {
86 pb->ioResult = errRefNum;
87 return EINVAL;
88 }
89
90 if (sp->state != sOpen) { /* If we're not open, tell user to go away */
91 pb->ioResult = errState;
92 uerr = ENOTCONN;
93l_err:
94 atalk_notify(sp->gref, uerr);
95 gbuf_freem(pb->mp);
96 return 0;
97 }
98
99 if (pb->u.attnParams.attnSize > attnBufSize) /* If data too big, bye-bye */
100 {
101 pb->ioResult = errAttention;
102 uerr = ERANGE;
103 goto l_err;
104 }
105
106 /* The 1st mbuf in the pb->mp chain (mp) is the adspcmd structure.
107 The 2nd mbuf (nmp) will be the beginning of the data. */
108 mp = pb->mp;
109 if (pb->u.attnParams.attnSize) {
110 nmp = gbuf_cont(mp);
111 if (gbuf_len(mp) > sizeof(struct adspcmd)) {
112 if ((nmp = gbuf_dupb(mp)) == 0) {
113 gbuf_wset(mp, sizeof(struct adspcmd));
114 uerr = ENOBUFS;
115 goto l_err;
116 }
117 gbuf_wset(mp, sizeof(struct adspcmd));
118 gbuf_rinc(nmp, sizeof(struct adspcmd));
119 gbuf_cont(nmp) = gbuf_cont(mp);
120 gbuf_cont(mp) = nmp;
121 }
122 }
123 pb->ioDirection = 1; /* outgoing attention data */
124 ATDISABLE(s, sp->lock);
125 if (sp->sapb) { /* Pending attentions already? */
126 qAddToEnd(&sp->sapb, pb); /* Just add to end of queue */
127 ATENABLE(s, sp->lock);
128 } else {
129 sp->sendAttnData = 1; /* Start off this attention */
130 pb->qLink = 0;
131 sp->sapb = pb;
132 ATENABLE(s, sp->lock);
133 CheckSend(sp);
134 }
135 pb->ioResult = 1; /* indicate that the IO is not complete */
136 return 0;
137}