-
Notifications
You must be signed in to change notification settings - Fork 42
/
commadpt.c
3602 lines (3420 loc) · 143 KB
/
commadpt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* COMMADPT.C (c) Copyright Roger Bowler & Others, 2002-2011 */
/* (c) Copyright, MHP, 2007-2008 (see below) */
/* Hercules Communication Line Driver */
/*-------------------------------------------------------------------*/
/* Hercules Communication Line Driver */
/* (c) 1999-2006 Roger Bowler & Others */
/* Use of this program is governed by the QPL License */
/* Original Author : Ivan Warren */
/* Prime Maintainer : Ivan Warren */
/*-------------------------------------------------------------------*/
/* ********************************************************************
TTY Mode Additions (c) Copyright, 2007 MHP <ikj1234i at yahoo dot com>
Feb. 2007- Add support for 2703 Telegraph Terminal Control Type II
(for use with TTY ASR 33/35 or compatible terminals).
To enable TTY mode for a particular port, specify ``LNCTL=ASYNC'' in the
hercules conf file.
The host sends and receives bytes directly in ASCII, but bits are
reversed from standard ASCII bit order. Lookup tables are used to
perform the reversals on each byte, to make even parity for sending
toward the host, and to skip certain noxious characters emitted by
TSO/TCAM.
This code contains minimal TELNET support. It accepts TELNET
IP (Interrupt Process) which is mapped and transmitted to the host
as a BREAK (ATTN) sequence. All TELNET commands are responded
negatively.
*****************************************************************
2741 Mode Additions (c) Copyright, 2008 MHP <ikj1234i at yahoo dot com>
2741 mode is now working, though imperfectly as of yet.
There is a new param (term=tty|2741) in the conf file to select termtype.
Specify code=ebcd for EBCD, or code=corr for correspondence code.
Also code=none to disable all translation. The code= option applies to
2741 mode only.
Another new param (skip=) is a byte string, specified in hex, to specify
"garbage" code points that are to be suppressed in output processing.
This allows distinct lists to be used for different terminal types.
Automatic translation to Uppercase is enabled by setting uctrans=yes .
This is for both 2741 and TTY terminals.
You can specify lnctl=tele2 for TTY and lnctl=ibm1 for 2741.
Samples:
0045 2703 lport=32003 dial=IN lnctl=ibm1 term=2741 skip=5EDE code=ebcd
0045 2703 lport=32003 dial=IN lnctl=tele2 uctrans=yes term=tty skip=88C9DF
For TCAM, if you are zapping device UCB's, the following type values
seem to work:
55 10 40 13 - 2741
51 10 40 53 - TTY (3335)
When running TCAM in 2741 mode if you experience A00 abends, the following
zap (to member IEDQTCAM in 'SYS1.LINKLIB') may help
NAME IEDQTCAM IEDQKA01
VER 0E38 012C
REP 0E38 0101
The 2741 mode enables ordinary remote ASCII TELNET clients to connect.
The translate tables were lifted from IEDQ27 and IEDQ28. Instead of
translating directly between ASCII and the host's 2741-correspondence code,
we add an intermediate EBCDIC step. This enables use of all pre-
existing tables so I don't have to code any new ones :)
Also, 2740 OS consoles should work. It may be necessary to modify the
driver to end READ CCWs even when no data has been received (see comment)
*****************************************************************
Some TTY Fixes - 2012-01-30 MHP <ikj1234i at yahoo dot com>
This async/2703 driver release contains several bug fixes and minor
enhancements (primarily to fix windows telnet clients). In addition
there are three new configuration parameters (iskip=, bs=dumb, break=dumb)
When using windows telnet, it's recommended to set bs=dumb and break=dumb .
The new iskip= option is analogous to the skip= option, except that
it chooses input ASCII characters to suppress (the skip= option is used
to suppress characters in output processing). Note that while both options
are entered as hex bytes, the skip= option uses S/370 mainframe code
points (either byte-reversed ASCII for TTY or correspondence code/EBCD for
2741), whereas the iskip= option requires ASCII code points. Here's an
example:
0045 2703 lport=32003 dial=IN lnctl=tele2 uctrans=yes term=tty skip=88C9DF iskip=0A
Here's an example, for windows telnet clients
0046 2703 lport=32003 dial=IN lnctl=tele2 uctrans=yes term=tty skip=88C9DF iskip=0A bs=dumb break=dumb
*****************************************************************
driver mods for APL\360 December 2012 MHP <ikj1234i at yahoo dot com>
- circumvention for several race conditions
- new "eol" parameter specifies a byte value (ASCII), default 0x0D,
which when received marks the end of the input line
- new "prepend" and "append" parameters to specify zero to four
bytes to be prepended and appended (respectively) to input lines
that have been received from terminals before being sent to the
mainframe OS. Typical use is to add Circle D and C around each
input transmission (2741's for APL\360). Bytes must be specified in
S/370 channel format, not in ASCII.
- new terminal type "rxvt4apl" with 8-bit and character translation
support for rxvt4apl in 2741 mode. Use the following conf definition entry
0402 2703 dial=in lport=57413 lnctl=ibm1 term=rxvt4apl skip=5EDE code=ebcd
iskip=0D0A prepend=16 append=5B1F eol=0A binary=yes crlf=yes sendcr=yes
[all on a single line]
- negotiation to telnet binary mode when using rxvt4apl ("binary" parameter)
- send CR back to terminal when input line received ("sendcr" parameter)
- option to map 2741 NL to TTY CRLF sequence ("crlf" parameter)
- increase Hercules MAX_ARGS
******************************************************************** */
#include "hstdinc.h"
#include "hercules.h"
#include "devtype.h"
#include "parser.h"
#include "commadpt.h"
#if defined(WIN32) && defined(OPTION_DYNAMIC_LOAD) && !defined(HDL_USE_LIBTOOL) && !defined(_MSVC_)
SYSBLK *psysblk;
#define sysblk (*psysblk)
#endif
/*-------------------------------------------------------------------*/
/* Ivan Warren 20040227 */
/* This table is used by channel.c to determine if a CCW code is an */
/* immediate command or not */
/* The tape is addressed in the DEVHND structure as 'DEVIMM immed' */
/* 0 : Command is NOT an immediate command */
/* 1 : Command is an immediate command */
/* Note : An immediate command is defined as a command which returns */
/* CE (channel end) during initialisation (that is, no data is */
/* actually transfered. In this case, IL is not indicated for a CCW */
/* Format 0 or for a CCW Format 1 when IL Suppression Mode is in */
/* effect */
/*-------------------------------------------------------------------*/
static BYTE commadpt_immed_command[256]=
{ 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
COMMADPT_PEND_TEXT; /* Defined in commadpt.h */
/* Defines commadpt_pendccw_text array */
/*---------------------------------------------------------------*/
/* PARSER TABLES */
/*---------------------------------------------------------------*/
static PARSER ptab[]={
{"lport","%s"},
{"lhost","%s"},
{"rport","%s"},
{"rhost","%s"},
{"dial","%s"},
{"rto","%s"},
{"pto","%s"},
{"eto","%s"},
{"switched","%s"},
{"lnctl","%s"},
{"term","%s"},
{"code","%s"},
{"uctrans","%s"},
{"skip","%s"},
{"iskip","%s"},
{"bs","%s"},
{"break","%s"},
{"prepend","%s"},
{"append","%s"},
{"eol","%s"},
{"crlf","%s"},
{"sendcr","%s"},
{"binary","%s"},
{NULL,NULL}
};
enum {
COMMADPT_KW_LPORT=1,
COMMADPT_KW_LHOST,
COMMADPT_KW_RPORT,
COMMADPT_KW_RHOST,
COMMADPT_KW_DIAL,
COMMADPT_KW_READTO,
COMMADPT_KW_POLLTO,
COMMADPT_KW_ENABLETO,
COMMADPT_KW_SWITCHED,
COMMADPT_KW_LNCTL,
COMMADPT_KW_TERM,
COMMADPT_KW_CODE,
COMMADPT_KW_UCTRANS,
COMMADPT_KW_SKIP,
COMMADPT_KW_ISKIP,
COMMADPT_KW_BS,
COMMADPT_KW_BREAK,
COMMADPT_KW_PREPEND,
COMMADPT_KW_APPEND,
COMMADPT_KW_EOL,
COMMADPT_KW_CRLF,
COMMADPT_KW_SENDCR,
COMMADPT_KW_BINARY,
} commadpt_kw;
static BYTE byte_reverse_table[256] = {
0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,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0xff, 0xfd, 0x00, 0xff, 0xfb, 0x00 };
BYTE overstrike_2741_pairs[] = {
0x93, 0xA6, /* nor */
0xC9, 0xCC, /* rotate */
0xCC, 0xCF, /* log */
0xC9, 0xEE, /* grade down */
0xC3, 0xE7, /* lamp */
0xC5, 0xC6, /* quote quad */
0x93, 0xA6, /* nand */
0xA3, 0xCC, /* transpose */
0xA6, 0xEE, /* locked fn */
0xC9, 0xF0, /* grade up */
0x76, 0xC5, /* exclamation */
0xCA, 0xE4, /* ibeam */
0xC6, 0xE1, /* domino */
};
BYTE overstrike_rxvt4apl_chars[] = {
/* must match overstrike_2741_pairs */
0xe5,
0xe8,
0x89,
0x9d,
0xa6,
0x97,
0xea,
0xed,
0xa1, /* locked fn - no exact match for this */
0x93,
0x21,
0x84,
0x98,
};
static BYTE overstrike_map [256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0,
0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0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 0xe4, 0xe7, 0xe8, 0xeb, 0xed, 0xee, 0xf0, 0xf3, 0xc3, 0xc5, 0xc6, 0xc9, 0xca, 0xcc,
0xcf, 0xd1, 0xd2, 0xa5, 0xa6, 0xa9, 0xaa, 0xac, 0xaf, 0xb1, 0xb2, 0x57, 0xa3, 0x16, 0x95, 0xed,
0x88, 0x62, 0x64, 0x67, 0x68, 0x6b, 0x6d, 0x6e, 0x70, 0x73, 0x43, 0x45, 0x46, 0x49, 0x4a, 0x4c,
0x4f, 0x51, 0x52, 0x25, 0x26, 0x29, 0x2a, 0x2c, 0x2f, 0x31, 0x32, 0x88, 0xc9, 0x88, 0xa6, 0x88,
0x88, 0x88, 0xb2, 0xaf, 0x88, 0xa0, 0x90, 0x88, 0x88, 0x88, 0x88, 0xa9, 0xb1, 0xa5, 0x88, 0xe8,
0x20, 0xf0, 0x61, 0x88, 0x88, 0xc6, 0x88, 0x88, 0x88, 0x88, 0x82, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0xe2, 0x88, 0xf3, 0x88, 0x88, 0x88, 0xe4, 0xca, 0x88, 0x88, 0x88, 0x88, 0xee, 0x88, 0xeb, 0xe7,
0x88, 0x88, 0x8d, 0x88, 0x88, 0x88, 0xe1, 0xac, 0xc3, 0xcc, 0x93, 0xd2, 0xaa, 0x84, 0x88, 0x88,
};
/* 2741 EBCD code tables */
/* direct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0xE5, 0x3F, 0xE6, 0x3F, 0x3F, 0xE7,
0x3F, 0xE8, 0xE9, 0x3F, 0x3F, 0x3F, 0x3F, 0x4F, 0x24, 0x3F, 0x3F, 0x25, 0x3F, 0x26, 0x27, 0x3F,
0x6D, 0x3F, 0x3F, 0xD1, 0x3F, 0xD2, 0xD3, 0x3F, 0x3F, 0xD4, 0xD5, 0x3F, 0xD6, 0x3F, 0x3F, 0xD7,
0x3F, 0xD8, 0xD9, 0x3F, 0x3F, 0x3F, 0x3F, 0x5A, 0x14, 0x3F, 0x3F, 0x15, 0x3F, 0x16, 0x17, 0x3F,
0x3F, 0x4E, 0xC1, 0x3F, 0xC2, 0x3F, 0x3F, 0xC3, 0xC4, 0x3F, 0x3F, 0xC5, 0x3F, 0xC6, 0xC7, 0x3F,
0xC8, 0x3F, 0x3F, 0xC9, 0x3F, 0x3F, 0x5F, 0x3F, 0x3F, 0x3F, 0x05, 0x3F, 0x06, 0x3F, 0x3F, 0x07
};
static BYTE xlate_table_ebcd_fromebcdic[256] = {
0x88, 0x88, 0x88, 0x88, 0x88, 0x7A, 0x7C, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x5B, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x58, 0x5B, 0x5D, 0x5E, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x38, 0x3B, 0x88, 0x3E, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x5E, 0x88, 0x88, 0x88, 0x1C, 0x1F, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x01, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0xA0, 0x76, 0x84, 0x93, 0xE1, 0xB7,
0x61, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0xD7, 0x57, 0x90, 0x95, 0x87, 0xF6,
0x40, 0x23, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x37, 0x8B, 0xC0, 0x8E, 0xA3,
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x16, 0x20, 0x8D, 0x82, 0x96,
0x88, 0x62, 0x64, 0x67, 0x68, 0x6B, 0x6D, 0x6E, 0x70, 0x73, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x43, 0x45, 0x46, 0x49, 0x4A, 0x4C, 0x4F, 0x51, 0x52, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x25, 0x26, 0x29, 0x2A, 0x2C, 0x2F, 0x31, 0x32, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0xE2, 0xE4, 0xE7, 0xE8, 0xEB, 0xED, 0xEE, 0xF0, 0xF3, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0xC3, 0xC5, 0xC6, 0xC9, 0xCA, 0xCC, 0xCF, 0xD1, 0xD2, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x88, 0x88, 0xA5, 0xA6, 0xA9, 0xAA, 0xAC, 0xAF, 0xB1, 0xB2, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x15, 0x02, 0x04, 0x07, 0x08, 0x0B, 0x0D, 0x0E, 0x10, 0x13, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88
};
/* 2741 correspondence code tables */
/* directly copied from mvs src file iedq28 */
static BYTE xlate_table_cc_toebcdic[256] = {
0x3F, 0x40, 0xF1, 0x3F, 0xF2, 0x3F, 0x3F, 0xF3, 0xF5, 0x3F, 0x3F, 0xF7, 0x3F, 0xF6, 0xF8, 0x3F,
0xF4, 0x3F, 0x3F, 0xF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, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
};
static void logdump(char *txt,DEVBLK *dev,BYTE *bfr,size_t sz)
{
size_t i;
if ( !dev->ccwtrace )
{
return;
}
logmsg(_("HHCCA300D %4.4X:%s : Status = TEXT=%s, TRANS=%s, TWS=%s\n"),
dev->devnum,
txt,
dev->commadpt->in_textmode?"YES":"NO",
dev->commadpt->in_xparmode?"YES":"NO",
dev->commadpt->xparwwait?"YES":"NO");
logmsg(_("HHCCA300D %4.4X:%s : Dump of %d (%x) byte(s)\n"),dev->devnum,txt,sz,sz);
for( i=0; i<sz; i++ )
{
if( i%16 == 0 )
{
if( i !=0 )
{
logmsg("\n");
}
logmsg(_("HHCCA300D %4.4X:%s : %4.4X:"),dev->devnum,txt,i);
}
if( i%4 == 0 )
{
logmsg(" ");
}
logmsg("%2.2X",bfr[i]);
}
logmsg("\n");
}
/*-------------------------------------------------------------------*/
/* Handler utility routines */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Buffer ring management */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Buffer ring management : Init a buffer ring */
/*-------------------------------------------------------------------*/
void commadpt_ring_init(COMMADPT_RING *ring,size_t sz,int trace)
{
ring->bfr=malloc(sz);
ring->sz=sz;
ring->hi=0;
ring->lo=0;
ring->havedata=0;
ring->overflow=0;
if(trace)
{
logmsg("HCCCA999D : Ring buffer for ring %p allocated at %p\n",
ring,
ring->bfr);
}
}
/*-------------------------------------------------------------------*/
/* Buffer ring management : Free a buffer ring */
/*-------------------------------------------------------------------*/
static void commadpt_ring_terminate(COMMADPT_RING *ring,int trace)
{
if(trace)
{
logmsg("HCCCA999D : Ring buffer for ring %p at %p freed\n",
ring,
ring->bfr);
}
if(ring->bfr!=NULL)
{
free(ring->bfr);
ring->bfr=NULL;
}
ring->sz=0;
ring->hi=0;
ring->lo=0;
ring->havedata=0;
ring->overflow=0;
}
/*-------------------------------------------------------------------*/
/* Buffer ring management : Flush a buffer ring */
/*-------------------------------------------------------------------*/
static void commadpt_ring_flush(COMMADPT_RING *ring)
{
ring->hi=0;
ring->lo=0;
ring->havedata=0;
ring->overflow=0;
}
/*-------------------------------------------------------------------*/
/* Buffer ring management : Queue a byte in the ring */
/*-------------------------------------------------------------------*/
inline static void commadpt_ring_push(COMMADPT_RING *ring,BYTE b)
{
ring->bfr[ring->hi++]=b;
if(ring->hi>=ring->sz)
{
ring->hi=0;
}
if(ring->hi==ring->lo)
{
ring->overflow=1;
}
ring->havedata=1;
}
/*-------------------------------------------------------------------*/
/* Buffer ring management : Queue a byte array in the ring */
/*-------------------------------------------------------------------*/
inline static void commadpt_ring_pushbfr(COMMADPT_RING *ring,BYTE *b,size_t sz)
{
size_t i;
for(i=0;i<sz;i++)
{
commadpt_ring_push(ring,b[i]);
}
}
/*-------------------------------------------------------------------*/
/* Buffer ring management : Retrieve a byte from the ring */
/*-------------------------------------------------------------------*/
inline static BYTE commadpt_ring_pop(COMMADPT_RING *ring)
{
register BYTE b;
b=ring->bfr[ring->lo++];
if(ring->lo>=ring->sz)
{
ring->lo=0;
}
if(ring->hi==ring->lo)
{
ring->havedata=0;
}
return b;
}
/*-------------------------------------------------------------------*/
/* Buffer ring management : Retrive a byte array from the ring */
/*-------------------------------------------------------------------*/
inline static size_t commadpt_ring_popbfr(COMMADPT_RING *ring,BYTE *b,size_t sz)
{
size_t i;
for(i=0;i<sz && ring->havedata;i++)
{
b[i]=commadpt_ring_pop(ring);
}
return i;
}
/*-------------------------------------------------------------------*/
/* Free all private structures and buffers */
/*-------------------------------------------------------------------*/
static void commadpt_clean_device(DEVBLK *dev)
{
if(!dev)
{
/*
* Shouldn't happen.. But during shutdown, some weird
* things happen !
*/
return;
}
if(dev->commadpt!=NULL)
{
commadpt_ring_terminate(&dev->commadpt->inbfr,dev->ccwtrace);
commadpt_ring_terminate(&dev->commadpt->outbfr,dev->ccwtrace);
commadpt_ring_terminate(&dev->commadpt->rdwrk,dev->ccwtrace);
commadpt_ring_terminate(&dev->commadpt->pollbfr,dev->ccwtrace);
commadpt_ring_terminate(&dev->commadpt->ttybuf,dev->ccwtrace);
/* release the CA lock */
release_lock(&dev->commadpt->lock);
free(dev->commadpt);
dev->commadpt=NULL;
if(dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4X:clean : Control block freed\n"),
dev->devnum);
}
}
else
{
if(dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4X:clean : Control block not freed : not allocated\n"),dev->devnum);
}
}
return;
}
/*-------------------------------------------------------------------*/
/* Allocate initial private structures */
/*-------------------------------------------------------------------*/
static int commadpt_alloc_device(DEVBLK *dev)
{
dev->commadpt=malloc(sizeof(COMMADPT));
if(dev->commadpt==NULL)
{
logmsg(_("HHCCA020E %4.4X:Memory allocation failure for main control block\n"),
dev->devnum);
return -1;
}
memset(dev->commadpt,0,sizeof(COMMADPT));
commadpt_ring_init(&dev->commadpt->inbfr,4096,dev->ccwtrace);
commadpt_ring_init(&dev->commadpt->outbfr,4096,dev->ccwtrace);
commadpt_ring_init(&dev->commadpt->pollbfr,4096,dev->ccwtrace);
commadpt_ring_init(&dev->commadpt->rdwrk,65536,dev->ccwtrace);
commadpt_ring_init(&dev->commadpt->ttybuf,TTYLINE_SZ,dev->ccwtrace);
dev->commadpt->dev=dev;
return 0;
}
/*-------------------------------------------------------------------*/
/* Parsing utilities */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* commadpt_getport : returns a port number or -1 */
/*-------------------------------------------------------------------*/
static int commadpt_getport(char *txt)
{
int pno;
struct servent *se;
pno=atoi(txt);
if(pno==0)
{
se=getservbyname(txt,"tcp");
if(se==NULL)
{
return -1;
}
pno=se->s_port;
}
return(pno);
}
/*-------------------------------------------------------------------*/
/* commadpt_getaddr : set an in_addr_t if ok, else return -1 */
/*-------------------------------------------------------------------*/
static int commadpt_getaddr(in_addr_t *ia,char *txt)
{
struct hostent *he;
he=gethostbyname(txt);
if(he==NULL)
{
return(-1);
}
memcpy(ia,he->h_addr_list[0],4);
return(0);
}
/*-------------------------------------------------------------------*/
/* commadpt_connout : make a tcp outgoing call */
/* return values : 0 -> call succeeded or initiated */
/* <0 -> call failed */
/*-------------------------------------------------------------------*/
static int commadpt_connout(COMMADPT *ca)
{
int rc;
char wbfr[256];
struct sockaddr_in sin;
struct in_addr intmp;
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=ca->rhost;
sin.sin_port=htons(ca->rport);
if(socket_is_socket(ca->sfd))
{
close_socket(ca->sfd);
ca->connect=0;
}
ca->sfd=socket(AF_INET,SOCK_STREAM,0);
/* set socket to NON-blocking mode */
socket_set_blocking_mode(ca->sfd,0);
rc=connect(ca->sfd,(struct sockaddr *)&sin,sizeof(sin));
if(rc<0)
{
#if defined(_MSVC_)
if(HSO_errno==HSO_EWOULDBLOCK)
#else /* defined(_MSVC_) */
if(HSO_errno==HSO_EINPROGRESS)
#endif /* defined(_MSVC_) */
{
return(0);
}
else
{
strerror_r(HSO_errno,wbfr,256);
intmp.s_addr=ca->rhost;
logmsg(_("HHCCA001I %4.4X:Connect out to %s:%d failed during initial status : %s\n"),
ca->devnum,
inet_ntoa(intmp),
ca->rport,
wbfr);
close_socket(ca->sfd);
ca->connect=0;
return(-1);
}
}
ca->connect=1;
return(0);
}
/*-------------------------------------------------------------------*/
/* commadpt_initiate_userdial : interpret DIAL data and initiate call*/
/* return values : 0 -> call succeeded or initiated */
/* <0 -> call failed */
/*-------------------------------------------------------------------*/
static int commadpt_initiate_userdial(COMMADPT *ca)
{
int dotcount; /* Number of seps (the 4th is the port separator) */
int i; /* work */
int cur; /* Current section */
in_addr_t destip; /* Destination IP address */
U16 destport; /* Destination TCP port */
int incdata; /* Incorrect dial data found */
int goteon; /* EON presence flag */
/* See the DIAL CCW portion in execute_ccw for dial format information */
incdata=0;
goteon=0;
dotcount=0;
cur=0;
destip=0;
for(i=0;i<ca->dialcount;i++)
{
if(goteon)
{
/* EON MUST be last data byte */
if(ca->dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4x : Found data beyond EON\n"),ca->devnum);
}
incdata=1;
break;
}
switch(ca->dialdata[i]&0x0f)
{
case 0x0d: /* SEP */
if(dotcount<4)
{
if(cur>255)
{
incdata=1;
if(ca->dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4x : Found incorrect IP address section at position %d\n"),ca->devnum,dotcount+1);
logmsg(_("HHCCA300D %4.4x : %d greater than 255\n"),ca->devnum,cur);
}
break;
}
destip<<=8;
destip+=cur;
cur=0;
dotcount++;
}
else
{
incdata=1;
if(ca->dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4x : Too many separators in dial data\n"),ca->devnum);
}
break;
}
break;
case 0x0c: /* EON */
goteon=1;
break;
/* A,B,E,F not valid */
case 0x0a:
case 0x0b:
case 0x0e:
case 0x0f:
incdata=1;
if(ca->dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4x : Incorrect dial data byte %2.2x\n"),ca->devnum,ca->dialdata[i]);
}
break;
default:
cur*=10;
cur+=ca->dialdata[i]&0x0f;
break;
}
if(incdata)
{
break;
}
}
if(incdata)
{
return -1;
}
if(dotcount<4)
{
if(ca->dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4x : Not enough separators (only %d found) in dial data\n"),ca->devnum,dotcount);
}
return -1;
}
if(cur>65535)
{
if(ca->dev->ccwtrace)
{
logmsg(_("HHCCA300D %4.4x : Destination TCP port %d exceeds maximum of 65535\n"),ca->devnum,cur);
}
return -1;
}
destport=cur;
/* Update RHOST/RPORT */
ca->rport=destport;
ca->rhost=destip;
return(commadpt_connout(ca));
}
static void connect_message(int sfd, int devnum, int term, int binary_opt)
{
int rc;
struct sockaddr_in client;
socklen_t namelen;
char *ipaddr;
char msgtext[256];
namelen = sizeof(client);
rc = getpeername (sfd, (struct sockaddr *)&client, &namelen);
ipaddr = inet_ntoa(client.sin_addr);
sprintf(msgtext, "%s:%d TERMINAL CONNECTED CUA=%4.4X TERM=%s", ipaddr, (int)ntohs(client.sin_port), devnum, (term == COMMADPT_TERM_TTY) ? "TTY" : "2741");
logmsg( _("%s\n"), msgtext);
write(sfd, msgtext, strlen(msgtext));
write(sfd, "\r\n", 2);
if (binary_opt)
write(sfd, telnet_binary, sizeof(telnet_binary));
}
/*-------------------------------------------------------------------*/
/* Communication Thread - Read socket data (after POLL request */
/*-------------------------------------------------------------------*/
static int commadpt_read_poll(COMMADPT *ca)
{
BYTE b;
int rc;
while((rc=read_socket(ca->sfd,&b,1))>0)
{
if(b==0x32)
{
continue;
}
if(b==0x37)
{
return(1);
}
}
if(rc>0)
{
/* Store POLL IX in bfr followed by byte */
commadpt_ring_push(&ca->inbfr,ca->pollix);
commadpt_ring_push(&ca->inbfr,b);
return(2);
}
return(0);
}
static void commadpt_read_tty(COMMADPT *ca, BYTE * bfr, int len)
{
BYTE bfr3[3];
BYTE c;
BYTE dump_buf[TTYLINE_SZ];
int dump_bp=0;
BYTE tty_buf[TTYLINE_SZ];
int tty_bp=0;
int i1;
u_int j;
int crflag = 0;
for (i1 = 0; i1 < len; i1++)
{
c = (unsigned char) bfr[i1];
if (ca->telnet_opt)
{
ca->telnet_opt = 0;
if(ca->dev->ccwtrace)
logmsg(_("HHCCA300D %4.4X: Received TELNET CMD 0x%02x 0x%02x\n"),
ca->dev->devnum,
ca->telnet_cmd, c);
if (c == 0x00 && ca->binary_opt)
continue; /* for binary: assume it's a response, so don't answer */
bfr3[0] = 0xff; /* IAC */
/* set won't/don't for all received commands */
bfr3[1] = (ca->telnet_cmd == 0xfd) ? 0xfc : 0xfe;
bfr3[2] = c;
if(ca->dev->ccwtrace)
logmsg(_("HHCCA300D %4.4X: Sending TELNET CMD 0x%02x 0x%02x\n"),
ca->dev->devnum,
bfr3[1], bfr3[2]);
commadpt_ring_pushbfr(&ca->outbfr,bfr3,3);
continue;
}
if (ca->telnet_iac)
{
ca->telnet_iac = 0;
if(ca->dev->ccwtrace)
logmsg(_("HHCCA300D %4.4X: Received TELNET IAC 0x%02x\n"),
ca->dev->devnum,
c);
switch (c)
{
case 0xFB: /* TELNET WILL option cmd */
case 0xFD: /* TELNET DO option cmd */
ca->telnet_opt = 1;
ca->telnet_cmd = c;
break;
case 0xF4: /* TELNET interrupt */
if (!ca->telnet_int)
{
ca->telnet_int = 1;
commadpt_ring_flush(&ca->ttybuf);
commadpt_ring_flush(&ca->inbfr);
commadpt_ring_flush(&ca->rdwrk);
commadpt_ring_flush(&ca->outbfr);
}
break;
}
continue;
}
if (c == 0xFF)
{ /* TELNET IAC */
ca->telnet_iac = 1;
continue;
}
else
{
ca->telnet_iac = 0;
}
if (c == ca->eol_char) { // char was CR ?
crflag = 1;
}
if (c == 0x03 && ca->dumb_break)
{ /* Ctrl-C */
ca->telnet_int = 1;
commadpt_ring_flush(&ca->ttybuf);
commadpt_ring_flush(&ca->inbfr);
commadpt_ring_flush(&ca->rdwrk);
commadpt_ring_flush(&ca->outbfr);
continue;
}
commadpt_ring_push(&ca->ttybuf,c);
}
if (crflag)
{ /* process complete line, perform editing and translation, etc. */
if (ca->prepend_length)
{
for (i1 = 0; i1 < ca->prepend_length; i1++) {
tty_buf[tty_bp++] = ca->prepend_bytes[i1];
if (tty_bp >= TTYLINE_SZ)
tty_bp = TTYLINE_SZ - 1; // prevent buf overflow
}
}
while (ca->ttybuf.havedata)
{
c = commadpt_ring_pop(&ca->ttybuf);
if ((c & 0x7f) == 0x08 && ca->dumb_bs) // backspace editing
{
if (tty_bp > 0)
tty_bp --;
continue;
}
if (ca->input_byte_skip_table[c])
continue; // skip this byte per cfg
if (!(ca->rxvt4apl || !ca->code_table_fromebcdic))
{ /* tty33 and 2741 emulation are 7-bit, code=none and rxvt4apl want 8 bit */
c &= 0x7f; // make 7 bit ASCII
}
if (ca->uctrans && c >= 'a' && c <= 'z')
{
c = toupper( c ); /* make uppercase */