Cut down on number of protocol exchanges by passing parm data
[unix-history] / usr / src / usr.bin / tn3270 / api / apilib.c
CommitLineData
28e559a0
GM
1#include "../api/api.h"
2
f81b28ad
GM
3#include "apilib.h"
4
5int
6 api_sup_errno = 0, /* Supervisor error number */
7 api_sup_fcn_id = 0, /* Supervisor function id (0x12) */
8 api_fcn_errno = 0, /* Function error number */
9 api_fcn_fcn_id = 0; /* Function ID (0x6b, etc.) */
10
11static int
12 gate_sessmgr = 0,
13 gate_keyboard = 0,
14 gate_copy = 0,
15 gate_oiam = 0;
16
17/*
18 * Issue an API request, with reg structures supplied by the caller.
19 *
20 * Only certain routines need this (supervisor services come to mind).
21 */
22
cee740d6
GM
23static int
24api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, regs, sregs)
f81b28ad
GM
25int ah, al, bh, bl, cx, dx;
26char *parms;
cee740d6 27int length;
f81b28ad
GM
28union REGS *regs;
29struct SREGS *sregs;
30{
31 char far *ourseg = parms;
32
33 regs->h.ah = ah;
34 regs->h.al = al;
35 regs->h.bh = bh;
36 regs->h.bl = bl;
37 regs->x.cx = cx;
38 regs->x.dx = dx;
39 sregs->es = (int) FP_SEG(ourseg);
40 regs->x.di = (int) FP_OFF(ourseg);
41
cd746900 42#if defined(MSDOS)
f81b28ad 43 int86x(API_INTERRUPT_NUMBER, regs, regs, sregs);
cd746900
GM
44#endif /* defined(MSDOS) */
45#if defined(unix)
cee740d6 46 api_exch_api(regs, sregs, parms, length);
cd746900
GM
47#endif /* defined(unix) */
48
f81b28ad
GM
49 if (regs->h.cl != 0) {
50 api_sup_errno = regs->h.cl;
51 return -1;
52 } else {
53 return 0;
54 }
55}
56
57
58/*
59 * Issue an API request without requiring caller to supply
60 * registers. Most routines use this.
61 */
28e559a0 62
cee740d6
GM
63static int
64api_issue(ah, al, bh, bl, cx, dx, parms, length)
28e559a0
GM
65int
66 ah,
67 al,
68 bh,
69 bl,
70 cx,
71 dx;
72char *parms;
cee740d6 73int length; /* Length of parms */
28e559a0
GM
74{
75 union REGS regs;
76 struct SREGS sregs;
28e559a0 77
cee740d6 78 return api_issue_regs(ah, al, bh, bl, cx, dx, parms, length, &regs, &sregs);
28e559a0 79}
f81b28ad
GM
80\f
81/*
82 * Supervisor Services
83 */
28e559a0
GM
84
85int
86api_name_resolve(name)
87char *name;
88{
89 NameResolveParms parms;
90 int i;
91 union REGS regs;
92 struct SREGS sregs;
28e559a0
GM
93
94 for (i = 0; i < sizeof parms.gate_name; i++) {
95 if (*name) {
96 parms.gate_name[i] = *name++;
97 } else {
98 parms.gate_name[i] = ' ';
99 }
100 }
101
cee740d6 102 if (api_issue_regs(NAME_RESOLUTION, 0, 0, 0, 0, 0, &parms, sizeof parms, &regs, &sregs)
f81b28ad 103 == -1) {
28e559a0
GM
104 return -1;
105 } else {
106 return regs.x.dx;
107 }
108}
f81b28ad
GM
109\f
110/*
111 * Session Information Services
112 */
113
e99f17a9 114api_query_session_id(parms)
f81b28ad
GM
115QuerySessionIdParms *parms;
116{
117 if (api_issue(0x09, QUERY_SESSION_ID, 0x80, 0x20, 0,
cee740d6 118 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
119 api_fcn_errno = 0;
120 api_fcn_fcn_id = 0;
121 return -1;
122 } else if (parms->rc == 0) {
123 return 0;
124 } else {
125 api_fcn_errno = parms->rc;
126 api_fcn_fcn_id = parms->function_id;
127 return -1;
128 }
129}
130
131
e99f17a9 132api_query_session_parameters(parms)
f81b28ad
GM
133QuerySessionParametersParms *parms;
134{
e99f17a9 135 if (api_issue(0x09, QUERY_SESSION_PARAMETERS, 0x80, 0x20, 0,
cee740d6 136 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
137 api_fcn_errno = 0;
138 api_fcn_fcn_id = 0;
139 return -1;
140 } else if (parms->rc == 0) {
141 return 0;
142 } else {
143 api_fcn_errno = parms->rc;
144 api_fcn_fcn_id = parms->function_id;
145 return -1;
146 }
147}
148
149api_query_session_cursor(parms)
150QuerySessionCursorParms *parms;
151{
e99f17a9 152 if (api_issue(0x09, QUERY_SESSION_CURSOR, 0x80, 0x20, 0xff,
cee740d6 153 gate_sessmgr, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
154 api_fcn_errno = 0;
155 api_fcn_fcn_id = 0;
156 return -1;
157 } else if (parms->rc == 0) {
158 return 0;
159 } else {
160 api_fcn_errno = parms->rc;
161 api_fcn_fcn_id = parms->function_id;
162 return -1;
163 }
164}
165\f
166/*
167 * Keyboard Services
168 */
169
170api_connect_to_keyboard(parms)
171ConnectToKeyboardParms *parms;
172{
173 if (api_issue(0x09, CONNECT_TO_KEYBOARD, 0x80, 0x20, 0,
cee740d6 174 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
175 api_fcn_errno = 0;
176 api_fcn_fcn_id = 0;
177 return -1;
178 } else if (parms->rc == 0) {
179 return 0;
180 } else {
181 api_fcn_errno = parms->rc;
182 api_fcn_fcn_id = parms->function_id;
183 return -1;
184 }
185}
186
187
188api_disconnect_from_keyboard(parms)
189DisconnectFromKeyboardParms *parms;
190{
191 if (api_issue(0x09, DISCONNECT_FROM_KEYBOARD, 0x80, 0x20, 0,
cee740d6 192 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
193 api_fcn_errno = 0;
194 api_fcn_fcn_id = 0;
195 return -1;
196 } else if (parms->rc == 0) {
197 return 0;
198 } else {
199 api_fcn_errno = parms->rc;
200 api_fcn_fcn_id = parms->function_id;
201 return -1;
202 }
203}
204
205
206api_write_keystroke(parms)
207WriteKeystrokeParms *parms;
208{
209 if (api_issue(0x09, WRITE_KEYSTROKE, 0x80, 0x20, 0,
cee740d6 210 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
211 api_fcn_errno = 0;
212 api_fcn_fcn_id = 0;
213 return -1;
214 } else if (parms->rc == 0) {
215 return 0;
216 } else {
217 api_fcn_errno = parms->rc;
218 api_fcn_fcn_id = parms->function_id;
219 return -1;
220 }
221}
222
223
224api_disable_input(parms)
225DisableInputParms *parms;
226{
227 if (api_issue(0x09, DISABLE_INPUT, 0x80, 0x20, 0,
cee740d6 228 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
229 api_fcn_errno = 0;
230 api_fcn_fcn_id = 0;
231 return -1;
232 } else if (parms->rc == 0) {
233 return 0;
234 } else {
235 api_fcn_errno = parms->rc;
236 api_fcn_fcn_id = parms->function_id;
237 return -1;
238 }
239}
240
241api_enable_input(parms)
242EnableInputParms *parms;
243{
244 if (api_issue(0x09, ENABLE_INPUT, 0x80, 0x20, 0,
cee740d6 245 gate_keyboard, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
246 api_fcn_errno = 0;
247 api_fcn_fcn_id = 0;
248 return -1;
249 } else if (parms->rc == 0) {
250 return 0;
251 } else {
252 api_fcn_errno = parms->rc;
253 api_fcn_fcn_id = parms->function_id;
254 return -1;
255 }
256}
257\f
258/*
259 * Copy Services
260 */
261
262api_copy_string(parms)
263CopyStringParms *parms;
264{
e99f17a9 265 if (api_issue(0x09, COPY_STRING, 0x80, 0x20, 0xff,
cee740d6 266 gate_copy, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
267 api_fcn_errno = 0;
268 api_fcn_fcn_id = 0;
269 return -1;
270 } else if (parms->rc == 0) {
271 return 0;
272 } else {
273 api_fcn_errno = parms->rc;
274 api_fcn_fcn_id = parms->function_id;
275 return -1;
276 }
277}
278
279/*
280 * Operator Information Area Services
281 */
282
283api_read_oia_group(parms)
284ReadOiaGroupParms *parms;
285{
e99f17a9 286 if (api_issue(0x09, READ_OIA_GROUP, 0x80, 0x20, 0xff,
cee740d6 287 gate_oiam, (char *)parms, sizeof *parms) == -1) {
f81b28ad
GM
288 api_fcn_errno = 0;
289 api_fcn_fcn_id = 0;
290 return -1;
291 } else if (parms->rc == 0) {
292 return 0;
293 } else {
294 api_fcn_errno = parms->rc;
295 api_fcn_fcn_id = parms->function_id;
296 return -1;
297 }
298}
299\f
d024bcc4
GM
300/*
301 * The "we are done" routine. This gets called last.
302 */
303
304api_finish()
305{
306#if defined(unix)
307 if (api_close_api() == -1) {
308 return -1;
309 } else {
310 return 0;
311 }
312#endif /* defined(unix) */
313}
314
315
f81b28ad
GM
316/*
317 * The initialization routine. Be sure to call this first.
318 */
319
320api_init()
321{
322 union REGS regs;
323 struct SREGS sregs;
324
cd746900 325#if defined(MSDOS)
f81b28ad
GM
326 regs.h.ah = 0x35;
327 regs.h.al = API_INTERRUPT_NUMBER;
328 intdosx(&regs, &regs, &sregs);
329
330 if ((regs.x.bx == 0) && (sregs.es == 0)) {
331 return 0; /* Interrupt not being handled */
332 }
cd746900
GM
333#endif defined(MSDOS)
334#if defined(unix)
335 if (api_open_api(0) == -1) {
336 return 0;
337 }
338#endif /* defined(unix) */
f81b28ad
GM
339
340 gate_sessmgr = api_name_resolve("SESSMGR");
341 gate_keyboard = api_name_resolve("KEYBOARD");
342 gate_copy = api_name_resolve("COPY");
343 gate_oiam = api_name_resolve("OIAM");
344
345 if ((gate_sessmgr == gate_keyboard) ||
346 (gate_sessmgr == gate_copy) ||
347 (gate_sessmgr == gate_oiam) ||
348 (gate_keyboard == gate_copy) ||
349 (gate_keyboard == gate_oiam) ||
350 (gate_copy == gate_oiam)) {
351 return 0; /* Interrupt doesn't seem correct */
352 }
353 return 1;
354}