386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / acsap / acsaprovider.c
CommitLineData
48435ab0
WJ
1/* acsaprovider.c - implement the association control protocol */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/acsap/RCS/acsaprovider.c,v 7.1 91/02/22 09:14:18 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/acsap/RCS/acsaprovider.c,v 7.1 91/02/22 09:14:18 mrose Interim $
9 *
10 *
11 * $Log: acsaprovider.c,v $
12 * Revision 7.1 91/02/22 09:14:18 mrose
13 * Interim 6.8
14 *
15 * Revision 7.0 89/11/23 21:21:59 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 <signal.h>
35#include "ACS-types.h"
36#define ACSE
37#include "acpkt.h"
38#include "tailor.h"
39
40/* \f PSAP interface */
41
42int ps2acslose (acb, aci, event, pa)
43register struct assocblk *acb;
44register struct AcSAPindication *aci;
45char *event;
46register struct PSAPabort *pa;
47{
48 int reason;
49 char *cp,
50 buffer[BUFSIZ];
51
52 if (event)
53 SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
54 (pa -> pa_cc > 0 ? "%s: %s [%*.*s]": "%s: %s", event,
55 PErrString (pa -> pa_reason), pa -> pa_cc, pa -> pa_cc,
56 pa -> pa_data));
57
58 cp = "";
59 switch (pa -> pa_reason) {
60 case PC_ADDRESS:
61 reason = ACS_ADDRESS;
62 break;
63
64 case PC_REFUSED:
65 reason = ACS_REFUSED;
66 break;
67
68 case PC_CONGEST:
69 reason = ACS_CONGEST;
70 break;
71
72 case PC_PARAMETER:
73 reason = ACS_PARAMETER;
74 break;
75
76 case PC_OPERATION:
77 reason = ACS_OPERATION;
78 break;
79
80 case PC_TIMER:
81 reason = ACS_TIMER;
82 break;
83
84 default:
85 (void) sprintf (cp = buffer, " (%s at presentation)",
86 PErrString (pa -> pa_reason));
87 case PC_SESSION:
88 reason = ACS_PRESENTATION;
89 break;
90 }
91
92 if (ACS_FATAL (reason)) {
93 if (pa -> pa_cc > 0)
94 return acpktlose (acb, aci, reason, NULLCP, "%*.*s%s",
95 pa -> pa_cc, pa -> pa_cc, pa -> pa_data, cp);
96 else
97 return acpktlose (acb, aci, reason, NULLCP, "%s",
98 *cp ? cp + 1 : cp);
99 }
100 else {
101 if (pa -> pa_cc > 0)
102 return acsaplose (aci, reason, NULLCP, "%*.*s%s",
103 pa -> pa_cc, pa -> pa_cc, pa -> pa_data, cp);
104 else
105 return acsaplose (aci, reason, NULLCP, "%s",
106 *cp ? cp + 1 : cp);
107 }
108}
109
110/* \f INTERNAL */
111
112/*
113 Owing to laziness on our part, we use only ASN.1 transfer syntax.
114 */
115
116/* ARGSUSED */
117
118struct type_ACS_Association__information *info2apdu (acb, aci, data, ndata)
119struct assocblk *acb;
120struct AcSAPindication *aci;
121PE *data;
122int ndata;
123{
124 register PE pe;
125 struct type_ACS_Association__information *info;
126 register struct type_ACS_Association__information **pp,
127 *p;
128 register struct type_UNIV_EXTERNAL *q;
129
130 for (pp = &info; ndata-- > 0; pp = &p -> next) {
131 if ((*pp = p = (struct type_ACS_Association__information *)
132 calloc (1, sizeof *p)) == NULL
133 || (p -> EXTERNAL = (struct type_UNIV_EXTERNAL *)
134 calloc (1, sizeof *q)) == NULL
135 || (p -> EXTERNAL -> encoding = (struct choice_UNIV_0 *)
136 malloc (sizeof (struct choice_UNIV_0))) == NULL)
137 goto out;
138 q = p -> EXTERNAL;
139
140 if (!(acb -> acb_flags & ACB_CONN)
141 && (q -> direct__reference = oid_cpy (ode2oid (BER)))
142 == NULLOID)
143 goto out;
144 q -> indirect__reference = (pe = *data++) -> pe_context;
145 q -> encoding -> offset = choice_UNIV_0_single__ASN1__type;
146 (q -> encoding -> un.single__ASN1__type = pe) -> pe_refcnt++;
147 }
148 (*pp) = NULL;
149
150 return info;
151
152out: ;
153 free_ACS_Association__information (info);
154
155 (void) acsaplose (aci, ACS_CONGEST, NULLCP, "out of memory");
156
157 return NULL;
158}
159
160/* \f */
161
162/* ARGSUSED */
163
164int apdu2info (acb, aci, info, data, ndata)
165struct assocblk *acb;
166struct AcSAPindication *aci;
167struct type_ACS_Association__information *info;
168PE *data;
169int *ndata;
170{
171 register int i;
172 register PE pe;
173 register struct type_UNIV_EXTERNAL *q;
174
175 for (i = 0; info; info = info -> next, i++) {
176 if (i > NACDATA)
177 return acpktlose (acb, aci, ACS_CONGEST, NULLCP,
178 "too much user information");
179
180 q = info -> EXTERNAL;
181 if (q -> encoding -> offset != choice_UNIV_0_single__ASN1__type)
182 return acpktlose (acb, aci, ACS_PROTOCOL, NULLCP,
183 "EXTERNAL data not single-ASN1-type");
184
185 (pe = q -> encoding -> un.single__ASN1__type) -> pe_refcnt++;
186 pe -> pe_context = q -> indirect__reference;
187
188 *data++ = pe;
189 }
190 *ndata = i;
191
192 return OK;
193}