]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/adsp_attention.c
xnu-792.6.22.tar.gz
[apple/xnu.git] / bsd / netat / adsp_attention.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
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.
1c79356b 11 *
e5568f75
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
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.
1c79356b
A
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 */
91447636 73int adspAttention(register struct adspcmd *pb, register CCBPtr sp)
1c79356b
A
74{
75 int s;
76 register gbuf_t *mp, *nmp;
77 unsigned char uerr;
78
79 if (sp == 0) {
80 pb->ioResult = errRefNum;
81 return EINVAL;
82 }
83
84 if (sp->state != sOpen) { /* If we're not open, tell user to go away */
85 pb->ioResult = errState;
86 uerr = ENOTCONN;
87l_err:
88 atalk_notify(sp->gref, uerr);
89 gbuf_freem(pb->mp);
90 return 0;
91 }
92
93 if (pb->u.attnParams.attnSize > attnBufSize) /* If data too big, bye-bye */
94 {
95 pb->ioResult = errAttention;
96 uerr = ERANGE;
97 goto l_err;
98 }
99
100 /* The 1st mbuf in the pb->mp chain (mp) is the adspcmd structure.
101 The 2nd mbuf (nmp) will be the beginning of the data. */
102 mp = pb->mp;
103 if (pb->u.attnParams.attnSize) {
104 nmp = gbuf_cont(mp);
105 if (gbuf_len(mp) > sizeof(struct adspcmd)) {
106 if ((nmp = gbuf_dupb(mp)) == 0) {
107 gbuf_wset(mp, sizeof(struct adspcmd));
108 uerr = ENOBUFS;
109 goto l_err;
110 }
111 gbuf_wset(mp, sizeof(struct adspcmd));
112 gbuf_rinc(nmp, sizeof(struct adspcmd));
113 gbuf_cont(nmp) = gbuf_cont(mp);
114 gbuf_cont(mp) = nmp;
115 }
116 }
117 pb->ioDirection = 1; /* outgoing attention data */
118 ATDISABLE(s, sp->lock);
119 if (sp->sapb) { /* Pending attentions already? */
120 qAddToEnd(&sp->sapb, pb); /* Just add to end of queue */
121 ATENABLE(s, sp->lock);
122 } else {
123 sp->sendAttnData = 1; /* Start off this attention */
124 pb->qLink = 0;
125 sp->sapb = pb;
126 ATENABLE(s, sp->lock);
127 CheckSend(sp);
128 }
129 pb->ioResult = 1; /* indicate that the IO is not complete */
130 return 0;
131}