Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / contrib / isode / ssap / ssapwrite.c
CommitLineData
9319b3c3
C
1/* ssapwrite.c - SPM: write various SPDUs */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/ssap/RCS/ssapwrite.c,v 7.1 91/02/22 09:46:10 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/ssap/RCS/ssapwrite.c,v 7.1 91/02/22 09:46:10 mrose Interim $
9 *
10 *
11 * $Log: ssapwrite.c,v $
12 * Revision 7.1 91/02/22 09:46:10 mrose
13 * Interim 6.8
14 *
15 * Revision 7.0 89/11/23 22:25:52 mrose
16 * Release 6.0
17 *
18 */
19
20/*
21 * NOTICE
22 *
23 * Acquisition, use, and distribution of this module and related
24 * materials are subject to the restrictions of a license agreement.
25 * Consult the Preface in the User's Manual for the full terms of
26 * this agreement.
27 *
28 */
29
30
31/* LINTLIBRARY */
32
33#include <stdio.h>
34#include "spkt.h"
35
36/* \f */
37
38int SWriteRequestAux (sb, code, data, cc, type, ssn, settings,
39 id, oid, ref, si)
40register struct ssapblk *sb;
41int code;
42char *data;
43int cc,
44 type,
45 settings;
46long ssn;
47struct SSAPactid *id,
48 *oid;
49struct SSAPref *ref;
50struct SSAPindication *si;
51{
52 int result;
53 register struct ssapkt *s,
54 *p;
55 struct TSAPdisconnect tds;
56 register struct TSAPdisconnect *td = &tds;
57 struct udvec uvs[3];
58 register struct udvec *uv;
59
60 if (sb -> sb_flags & SB_EXPD)
61 switch (code) {
62 case SPDU_MAA:
63 result = PR_MAA;
64 goto send_pr;
65
66 case SPDU_AI:
67 case SPDU_AD:
68 case SPDU_RS:
69 result = PR_RS;
70 goto send_pr;
71
72 case SPDU_AIA:
73 case SPDU_ADA:
74 case SPDU_RA:
75 result = PR_RA;
76 send_pr: ;
77 if ((p = newspkt (SPDU_PR)) == NULL)
78 return ssaplose (si, SC_CONGEST, NULLCP, "out of memory");
79 p -> s_mask |= SMASK_PR_TYPE;
80 p -> s_pr_type = result;
81 result = spkt2sd (p, sb -> sb_fd, 1, si);
82 freespkt (p);
83 if (result == NOTOK)
84 return NOTOK;
85 break;
86
87 default:
88 break;
89 }
90
91 uv = uvs;
92 uvs[0].uv_base = uvs[1].uv_base = NULL;
93
94 switch (code) {
95 case SPDU_MAP:
96 case SPDU_MIP:
97 case SPDU_RS:
98 case SPDU_AS:
99 case SPDU_AR:
100 case SPDU_AD:
101 case SPDU_AI:
102#ifdef notdef /* aka SPDU_MAP */
103 case SPDU_AE:
104#endif
105 case SPDU_CD:
106 if (s = newspkt (SPDU_GT))
107 s -> s_mask |= SMASK_SPDU_GT;
108 break;
109
110 default:
111 s = newspkt (SPDU_PT);
112 break;
113 }
114 if (s == NULL)
115 return ssaplose (si, SC_CONGEST, NULLCP, "out of memory");
116
117 if (spkt2tsdu (s, &uv -> uv_base, &uv -> uv_len) == NOTOK) {
118 (void) ssaplose (si, s -> s_errno, NULLCP, NULLCP);
119 goto out1;
120 }
121 freespkt (s);
122 uv++;
123
124 if ((s = newspkt (code)) == NULL) {
125 (void) ssaplose (si, SC_CONGEST, NULLCP, "out of memory");
126 goto out2;
127 }
128 switch (code) {
129 case SPDU_MAP:
130 if (type) {
131 s -> s_mask |= SMASK_MAP_SYNC;
132 s -> s_map_sync = type;
133 }
134 s -> s_mask |= SMASK_MAP_SERIAL;
135 s -> s_map_serial = ssn;
136 break;
137
138 case SPDU_MAA:
139 s -> s_mask |= SMASK_MAA_SERIAL;
140 s -> s_maa_serial = ssn;
141 break;
142
143 case SPDU_MIP:
144 if (type == SYNC_NOCONFIRM) {
145 s -> s_mask |= SMASK_MIP_SYNC;
146 s -> s_mip_sync = MIP_SYNC_NOEXPL;
147 }
148 s -> s_mask |= SMASK_MIP_SERIAL;
149 s -> s_mip_serial = ssn;
150 break;
151
152 case SPDU_MIA:
153 s -> s_mask |= SMASK_MIA_SERIAL;
154 s -> s_mia_serial = ssn;
155 break;
156
157 case SPDU_RS:
158 if (sb -> sb_requirements & SR_TOKENS) {
159 s -> s_mask |= SMASK_RS_SET;
160 s -> s_rs_settings = settings;
161 }
162 s -> s_mask |= SMASK_RS_TYPE;
163 s -> s_rs_type = type;
164 s -> s_mask |= SMASK_RS_SSN;
165 s -> s_rs_serial = ssn;
166 break;
167
168 case SPDU_RA:
169 if (sb -> sb_requirements & SR_TOKENS) {
170 s -> s_mask |= SMASK_RA_SET;
171 s -> s_ra_settings = settings;
172 }
173 s -> s_mask |= SMASK_RA_SSN;
174 s -> s_ra_serial = ssn;
175 break;
176
177 case SPDU_AS:
178 s -> s_mask |= SMASK_AS_ID;
179 s -> s_as_id = *id; /* struct copy */
180 break;
181
182 case SPDU_AR:
183 s -> s_mask |= SMASK_AR_OID | SMASK_AR_SSN | SMASK_AR_ID;
184 s -> s_ar_oid = *oid; /* struct copy */
185 s -> s_ar_serial = ssn;
186 s -> s_ar_id = *id; /* struct copy */
187 if (ref) {
188 s -> s_mask |= SMASK_AR_REF;
189 s -> s_ar_reference = *ref; /* struct copy */
190 }
191 break;
192
193 case SPDU_AI:
194 s -> s_mask |= SMASK_AI_REASON;
195 s -> s_ai_reason = type;
196 break;
197
198 case SPDU_AD:
199 s -> s_mask |= SMASK_AD_REASON;
200 s -> s_ad_reason = type;
201 break;
202
203 case SPDU_ED:
204 s -> s_mask |= SMASK_ED_REASON;
205 s -> s_ed_reason = type;
206 break;
207
208 default:
209 break;
210 }
211
212 if (cc > 0) {
213 s -> s_mask |= SMASK_UDATA_PGI;
214 s -> s_udata = data, s -> s_ulen = cc;
215 }
216 else
217 s -> s_udata = NULL, s -> s_ulen = 0;
218 result = spkt2tsdu (s, &uv -> uv_base, &uv -> uv_len);
219 s -> s_mask &= ~SMASK_UDATA_PGI;
220 s -> s_udata = NULL, s -> s_ulen = 0;
221
222 if (result == NOTOK) {
223 (void) ssaplose (si, s -> s_errno, NULLCP, NULLCP);
224 goto out3;
225 }
226 freespkt (s);
227 uv++;
228
229 uv -> uv_base = NULL;
230
231 if ((result = TWriteRequest (sb -> sb_fd, uvs, td)) == NOTOK)
232 (void) ts2sslose (si, "TWriteRequest", td);
233
234 free (uvs[0].uv_base);
235 free (uvs[1].uv_base);
236
237 return result;
238
239out3: ;
240 if (uvs[1].uv_base)
241 free (uvs[1].uv_base);
242out2: ;
243 if (uvs[0].uv_base)
244 free (uvs[0].uv_base);
245out1: ;
246 freespkt (s);
247
248 return NOTOK;
249}