]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/adsp_attention.c
xnu-1228.15.4.tar.gz
[apple/xnu.git] / bsd / netat / adsp_attention.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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 */
91447636 79int adspAttention(register struct adspcmd *pb, register CCBPtr sp)
1c79356b 80{
1c79356b
A
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;
92l_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 */
1c79356b 123 if (sp->sapb) { /* Pending attentions already? */
2d21ac55 124 qAddToEnd((struct qlink **)&sp->sapb, (struct qlink *)pb); /* Just add to end of queue */
1c79356b 125 } else {
0c530ab8
A
126 sp->sendAttnData = 1; /* Start off this attention */
127 pb->qLink = 0;
128 sp->sapb = pb;
129 CheckSend(sp);
1c79356b
A
130 }
131 pb->ioResult = 1; /* indicate that the IO is not complete */
132 return 0;
133}