-
Notifications
You must be signed in to change notification settings - Fork 1
/
xot.c
3097 lines (2163 loc) · 55.5 KB
/
xot.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
#ident "@(#)xot.c 4.7 - 05/10/03 00:06:34 - XOT driver"
/*
* Copyright © 2002, 2005 Atlantic Technologies.
* For conditions of distribution and use, see file LICENSE
*
*/
#define _DDI 7
#include <sys/ddi.h>
#include <stdarg.h>
#include <sys/xti.h>
#include <sys/tihdr.h>
#include <sys/types.h>
#include <sys/byteorder.h>
#include <sys/errno.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/cmn_err.h>
#include <sys/syslog.h>
#include <sys/strlog.h>
#include <sys/ddi.h>
#include <sys/moddefs.h>
#include "xot.h"
#include "private.h"
/* Forward declarations */
static int xot_load (void);
static int xot_unload (void);
int xotopen ();
int xotclose ();
int xotuwput ();
int xotuwsrv ();
int xotursrv ();
int xotlrsrv ();
#ifdef XOT_DEBUG
static void topdebug (struct xot_top *top, char *fmt, ...);
static void botdebug (struct xot_bot *bot, char *fmt, ...);
#endif
static void extract_addr (uchar_t *ablock, int offset, int len, uchar_t *addr);
static void insert_addr (uchar_t *ablock, int offset, int len, uchar_t *addr);
static int validate_addr (uchar_t *addr, int addr_len);
static int decode_fac (struct xot_flow *called,
struct xot_flow *calling,
uchar_t *fac, int fac_len);
static struct xot_top *find_listen (struct xot_top *master, uchar_t *addr, int len);
static mblk_t *handle_ioctl (queue_t *q, mblk_t *mp);
static mblk_t *send_downstream ();
static mblk_t *send_upstream ();
static struct xot_top *find_listen ();
/*
* X.25 flow control:
*
* Cannot send if reciver has said XOFF,
*
* or if senders P(S) is outside receivers window
*
* (note, needs "window" variable in scope)
*
*/
#define FLOW_CONTROL(xlt, snd, rcv, off) \
(xlt->rcv.xoff || \
(window = (xlt->rcv.pr + xlt->rcv.w - off) & xlt->mask, \
(window > xlt->rcv.pr ? \
!(xlt->snd.ps >= xlt->rcv.pr && xlt->snd.ps < window) : \
!(xlt->snd.ps >= xlt->rcv.pr || xlt->snd.ps < window))))
/*
* If the top is busy we can't close it.
*
* so we can be sure that ...?
*
*/
#define BUSY_TOP(top) \
do { \
if (!++top->busy) \
cmn_err (CE_WARN, "xot%d/%d: overbusied", \
top->major, top - xot_top); \
} \
while (0)
#define IDLE_TOP(top) \
do { \
pl_t pl = LOCK (top->lck, plstr); \
if (!top->busy) \
cmn_err (CE_WARN, "XOT: IDLE NOT BUSY AT %d", __LINE__); \
else \
if (!--top->busy) { \
if (top->flag & XOT_CLOSING) { \
SV_BROADCAST (xotsv, 0); \
} \
} \
UNLOCK (top->lck, pl); \
} \
while (0)
/*
* If the bottom is busy we can't unlink it
*
* So while it's busy we can be sure it's linked.
*
*/
#define BUSY_BOT(bot) \
do { \
if (!++bot->busy) \
cmn_err (CE_WARN, "bottom overbusied"); \
} \
while (0)
#define IDLE_BOT(bot) \
do { \
pl_t pl = LOCK (bot->lck, plstr); \
if (!bot->busy) \
cmn_err (CE_WARN, "XOT: IDLE NOT BUSY AT %d", __LINE__);\
else \
if (!--bot->busy) { \
if (bot->flags & XOT_CLOSING) { \
qenable (WR (xot_top[bot->major].qptr)); \
} \
} \
UNLOCK (bot->lck, pl); \
} \
while (0)
/*
* DLM initialisation
*/
MOD_DRV_WRAPPER (xot, xot_load, xot_unload, NULL,
"xot 4.7 X.25/TCP interface");
/*
* Streams initialisation tables
*/
static struct module_info info =
{XOT_MID, "xot", 0, INFPSZ, 512, 128};
static struct qinit urinit = { /* upper read */
NULL, xotursrv, xotopen, xotclose, NULL, &info, NULL};
static struct qinit uwinit = { /* upper write */
xotuwput, xotuwsrv, NULL, NULL, NULL, &info, NULL};
static struct qinit lrinit = { /* lower read */
putq, xotlrsrv, NULL, NULL, NULL, &info, NULL};
static struct qinit lwinit = { /* lower write */
NULL, NULL, NULL, NULL, NULL, &info, NULL};
struct streamtab xotinfo = {&urinit, &uwinit, &lrinit, &lwinit};
/* Device flag */
int xotdevflag = D_MP;
/* Locking stuff */
lkinfo_t xot_lkinfo;
sv_t *xotsv;
/* Stuff from space.c */
extern struct xot_top xot_top [];
extern struct xot_bot xot_bot [];
extern int xot_cnt;
extern int xot_major;
extern int xot_majors;
/*
* Load XOT driver
*
*/
static int xot_load (void) {
register struct xot_top *top;
register struct xot_top *last_top = xot_top + xot_cnt;
register struct xot_bot *bot;
register struct xot_bot *last_bot = xot_bot + xot_cnt;
cmn_err (CE_NOTE, "Load ATI xot version " VERSION);
/* Could run a xotinit () here */
mod_drvattach (&xot_attach_info);
/* Initialise the XOT driver after it has been loaded */
xotsv = SV_ALLOC (KM_NOSLEEP);
/* Note locking heirarchy -
lock top before bot
lock top before master
*/
for (top = xot_top; top < last_top; top++) {
int hier = XOT_HIER;
if (top < xot_top + xot_majors) hier = XOT_HIER + 1;
top->lck =
LOCK_ALLOC (hier, plstr, &xot_lkinfo, KM_NOSLEEP);
}
for (bot = xot_bot; bot < last_bot; ++bot)
bot->lck =
LOCK_ALLOC (XOT_HIER + 2, plstr,
&xot_lkinfo, KM_NOSLEEP);
return 0;
}
/*
* Unload XOT driver
*
* I assume all the streams have been closed when we get here.
*
*/
static int xot_unload (void) {
register struct xot_top *top;
register struct xot_top *last_top = xot_top + xot_cnt;
register struct xot_bot *bot;
register struct xot_bot *last_bot = xot_bot + xot_cnt;
cmn_err (CE_NOTE, "Unload ATI xot version " VERSION);
/* Release resources allocated by the XOT driver */
SV_DEALLOC (xotsv);
for (top = xot_top; top < last_top; top++)
if (top->lck) LOCK_DEALLOC (top->lck);
for (bot = xot_bot; bot < last_bot; ++bot)
if (bot->lck) LOCK_DEALLOC (bot->lck);
mod_drvdetach (&xot_attach_info);
return 0;
}
/*
* Simple, inlineable functions
*
*/
static mblk_t *allocate (queue_t *q, int len) {
mblk_t *mp = allocb (len, q ? BPRI_MED : BPRI_HI);
if (!mp && q) bufcall (len, BPRI_MED, qenable, (long) q);
return mp;
}
static mblk_t* alloc_x25 (queue_t *q, struct xot_bot *bot, int pt,
int len, int ulen)
{
struct xot_head *head;
mblk_t *mp;
len += 3;
if (!(mp = allocate (q, len + sizeof *head))) return NULL;
head = (struct xot_head *) mp->b_wptr;
mp->b_wptr += sizeof *head;
head->version = 0;
head->length = htons (len + ulen);
*mp->b_wptr++ = bot->gfi_lcg;
*mp->b_wptr++ = bot->lcn;
*mp->b_wptr++ = pt;
return mp;
}
static mblk_t *duplicate (queue_t *q, mblk_t *mp) {
mblk_t *np = dupb (mp);
if (!np) bufcall (0, BPRI_MED, qenable, (long) q);
return np;
}
/* *NOTE* must have already checked size, or could loop */
static int pullup (queue_t *q, mblk_t **mpp, int len) {
mblk_t *mp = *mpp;
mblk_t *np;
if (mp->b_wptr - mp->b_rptr >= len) return 1;
if (!(np = msgpullup (mp, len))) {
bufcall (len, BPRI_MED, qenable, (long) q);
return 0;
}
freemsg (mp);
*mpp = np;
return 1;
}
static mblk_t *allocate_clear (queue_t *q) {
return allocate (q, sizeof (struct xot_cmd));
}
/*
* bot must be marked busy before calling this
*
*/
static int clear_call (queue_t *q, struct xot_bot *bot, mblk_t *mp) {
struct xot_cmd *cmd;
pl_t pl;
if (!bot->busy) {
cmn_err (CE_PANIC, "bottom idle in clear_call");
}
pl = LOCK (bot->lck, plstr);
if (!bot->flags || bot->flags & XOT_CLEARED) { /* Unlinked */
UNLOCK (bot->lck, pl);
if (mp) freemsg (mp);
return 1;
}
bot->flags |= XOT_CLEARED;
UNLOCK (bot->lck, pl);
if (!mp && !(mp = allocate_clear (q))) return 0;
cmd = (struct xot_cmd *) mp->b_rptr;
mp->b_wptr = mp->b_rptr + sizeof *cmd;
cmd->cmd = XOT_CMD_CLOSE;
cmd->index = bot->id;
BOTDEBUG ((bot, "clear call %x", bot->id));
putnext (xot_top [bot->major].qptr, mp);
return 1;
}
/* Must have top locked when we get here */
void remove_bind (struct xot_top *top) {
if (top->queue_max) {
pl_t pl;
struct xot_top *master, *t, **pt;
master = &xot_top [top->major];
pl = LOCK (master->lck, plstr);
for (pt = &master->binds; (t = *pt); pt = &t->binds) {
if (t == top) break;
}
if (t) *pt = t->binds;
UNLOCK (master->lck, pl);
/* Free the queue of incoming calls */
kmem_free (top->queue, top->queue_max * sizeof *top->queue);
top->queue = NULL;
top->queue_max = 0;
}
freemsg (top->bound);
top->bound = NULL;
}
/*
* Open XOT device.
*
* Either we're opening minor 0, used for control, or asking for a clone,
* or opening an already open xot device.
*
*/
int xotopen (queue_t *q, dev_t *devp, int flag, int sflag, cred_t *credp) {
struct xot_top *top;
struct xot_top *last_top = xot_top + xot_cnt;
pl_t pl;
int major;
if ((major = getmajor (*devp) - xot_major) < 0) return ENXIO;
if (sflag == CLONEOPEN) {
for (top = xot_top + xot_majors; top < last_top; top++) {
if (top->lck == NULL) continue;
pl = LOCK (top->lck, plstr);
if (!top->flag) break;
UNLOCK (top->lck, pl);
}
if (top >= last_top) return ENXIO;
TOPDEBUG ((top, "open (clone)"));
*devp = makedevice (xot_major + major, top - xot_top);
}
else {
dev_t minor = getminor (*devp);
if (minor < 0 || minor >= xot_cnt) return ENXIO;
if (minor == 0) {
/* Open of a controlling device */
top = xot_top + major;
TOPDEBUG ((top, "open (major)"));
}
else if (minor < xot_majors) {
return ENXIO;
}
else {
top = &xot_top[minor];
TOPDEBUG ((top, "open"));
}
if (top->lck == NULL) return ENXIO;
if (q->q_ptr) {
if (q->q_ptr != top) return EBUSY;
return 0;
}
pl = LOCK (top->lck, plstr);
if (top->flag) {
UNLOCK (top->lck, pl);
return ENXIO;
}
}
/*
* Once we get here, the device is valid and we're holding its lock.
*/
top->qptr = q; /* read side */
#if XOT_DEBUG
top->flag = XOT_OPEN + XOT_DEBUG;
#else
top->flag = XOT_OPEN;
#endif
top->major = major;
top->bot = NULL;
top->state = TS_UNBND;
top->busy = 0;
/* X.25 defaults - only used for master */
top->p = 128;
top->w = 3; /* Hack */
q->q_ptr = (char *) top;
WR (q)->q_ptr = (char *) top;
UNLOCK (top->lck, pl);
qprocson (q);
return 0;
}
/*
* Close a xot connection
*
* Called with top locked
*
*/
static void clear_x25 (struct xot_top *top, struct xot_bot *bot) {
pl_t pl;
mblk_t *xp;
pl = LOCK (bot->lck, plstr);
if (!bot->flags) { /* Unlinked */
UNLOCK (bot->lck, pl);
return;
}
bot->top = NULL; /* 'cos top closed ??? */
BUSY_BOT (bot);
UNLOCK (bot->lck, pl);
switch (top->state) {
case TS_WACK_DREQ6:
/* We got the CLR_REQ from him */
break;
default:
TOPDEBUG ((top, "send X25_CLR_REQ"));
/* Send an X.25 clear, TCP call will go away
when we get the clear conf */
xp = alloc_x25 (NULL, bot, X25_CLR_REQ, 2, 0);
*xp->b_wptr++ = 0;
*xp->b_wptr++ = 0;
/* Dodgy(?), we still have top locked here */
putnext (bot->qptr, xp);
}
IDLE_BOT (bot);
}
int xotclose (queue_t * q, int flag, cred_t * credp) {
pl_t pl;
register struct xot_top *top = (struct xot_top *) q->q_ptr;
struct xot_bot *bot, **pb;
TOPDEBUG ((top, "xotclose"));
qprocsoff (q);
pl = LOCK (top->lck, plstr);
while (top->busy) {
TOPDEBUG ((top, "xotclose: wait for idle"));
top->flag |= XOT_CLOSING;
SV_WAIT (xotsv, prinet, top->lck);
pl = LOCK (top->lck, plstr);
}
/* If a call is active clear it */
if (top->bot) {
clear_x25 (top, top->bot);
top->bot = NULL;
}
/* Clear any waiting calls */
for (pb = top->queue; top->queue_len; ++pb) {
if (!(bot = *pb)) continue;
--top->queue_len;
clear_x25 (top, bot);
*pb = NULL;
}
if (top->bound) remove_bind (top);
top->flag = 0;
top->state = TS_UNBND;
UNLOCK (top->lck, pl);
return 0;
}
/*
* Upper Write side put.
*
* Here to process messages coming from one of the devices above the MUX.
*
* We handle the LINK, UNLINK and FLUSH ioctl's here.
*
*/
int xotuwput (queue_t * q, mblk_t * mp) {
struct xot_top *top = (struct xot_top *) q->q_ptr;
struct iocblk *iocp;
/* Special case for control channels */
if (top < xot_top + xot_majors) {
if ((mp = handle_ioctl (q, mp))) putq (q, mp);
return 0;
}
/* Code for all other units */
switch (mp->b_datap->db_type) {
case M_IOCTL:
/* Maybe should just pass down? */
TOPDEBUG ((top, "uwput: reject ioctl"));
iocp = (struct iocblk *) mp->b_rptr;
mp->b_datap->db_type = M_IOCNAK;
iocp->ioc_error = EINVAL;
qreply (q, mp);
break;
case M_FLUSH:
TOPDEBUG ((top, "uwput: flush"));
if (*mp->b_rptr & FLUSHW) flushq (q, FLUSHDATA);
if (*mp->b_rptr & FLUSHR) {
*mp->b_rptr &= ~FLUSHW;
qreply (q, mp);
}
else {
freemsg (mp);
}
break;
case M_DATA:
case M_PROTO:
/* Non priority data is just left for the service routine */
putq (q, mp);
break;
case M_PCPROTO:
if ((mp = send_downstream (q, mp))) {
TOPDEBUG ((top, "uwput: queue"));
putq (q, mp);
}
break;
default:
TOPDEBUG ((top, "uwput (M_0x%x) - ignored",
mp->b_datap->db_type));
freemsg (mp);
break;
}
return 0;
}
/*
* Here to deal with queued up stuff for going downstream
*
* Returns with any unhandled message, which should be
* put (back) on queue.
*
*/
int xotuwsrv (queue_t *q) {
mblk_t *mp;
struct xot_top *top = (struct xot_top *) q->q_ptr;
if (top < xot_top + xot_majors) {
while ((mp = getq (q))) {
if ((mp = handle_ioctl (q, mp))) {
putbq (q, mp);
return 0;
}
}
return 0;
}
while ((mp = getq (q))) {
if (mp->b_datap->db_type == M_DATA) {
mblk_t *np;
while ((np = getq (q))) {
if (np->b_datap->db_type != M_DATA) {
putbq (q, np);
break;
}
linkb (mp, np);
}
}
if ((mp = send_downstream (q, mp))) {
putbq (q, mp);
return 0;
}
}
}
/*
* Handle ioctl on control channels
*
*/
static mblk_t *handle_ioctl (queue_t *q, mblk_t *mp) {
pl_t pl, pl2;
struct iocblk *iocp;
struct linkblk *linkp;
struct xot_top *top = (struct xot_top *) q->q_ptr;
struct xot_bot *bot, **pb;
struct xot_bot *last_bot = xot_bot + xot_cnt;
struct xot_cmd *cmd;
queue_t *lower;
struct xot_top *t;
int error;
mblk_t *partial;
struct T_ok_ack *ok_ack;
mblk_t *np;
int fac_len;
uchar_t *p;
int i;
if (mp->b_datap->db_type != M_IOCTL) {
/* Just ignore it */
freemsg (mp);
return NULL;
}
iocp = (struct iocblk *) mp->b_rptr;
switch (iocp->ioc_cmd) {
case I_LINK:
/* Link. The data contains a linkblk structure.
Allocate a xot_bot */
linkp = (struct linkblk *) mp->b_cont->b_rptr;
TOPDEBUG ((top, "ioctl link %x", linkp->l_index));
pl = LOCK (top->lck, plstr);
for (bot = xot_bot; bot < last_bot; ++bot) {
if (!bot->lck) continue;
pl2 = LOCK (bot->lck, plstr);
if (!bot->flags) break;
UNLOCK (bot->lck, pl2);
}
if (bot == last_bot) {
UNLOCK (top->lck, pl);
error = ENOMEM;
goto iocnak;
}
bot->qptr = lower = linkp->l_qbot; /* write side */
bot->id = linkp->l_index;
bot->partial = NULL;
bot->major = top->major;
bot->top = NULL;
bot->busy = 0;
bot->flags = XOT_OPEN;
top->bot = bot;
RD (lower)->q_ptr = lower->q_ptr = bot;
UNLOCK (bot->lck, pl2);
UNLOCK (top->lck, pl);
/* Is this safe? When is the real "LINK" done? */
qenable (RD (lower));
goto ack;
case I_UNLINK:
/* Unlink. The data contains a linkblk structure. */
if (!(np = allocate (q, 1))) return mp;
linkp = (struct linkblk *) mp->b_cont->b_rptr;
TOPDEBUG ((top, "ioctl unlink %x, bot=%x",
linkp->l_index, linkp->l_qbot));
bot = linkp->l_qbot->q_ptr;
/* If the bot is busy we'll have to wait 'till
he's ready. This is hard */
pl = LOCK (bot->lck, plstr);
if (bot->busy) {
bot->flags |= XOT_CLOSING;
UNLOCK (bot->lck, pl);
freemsg (np);
return mp;
}
/* Do the actual unlinking */
bot->flags = 0;
t = bot->top;
bot->top = NULL;
partial = bot->partial;
bot->partial = NULL;
UNLOCK (bot->lck, pl);
/* Should only get here if xotlink is going away
and we're clearing all the calls before closing
the master */
if (t) {
/* Someone is talking on this stream */
pl = LOCK (t->lck, plstr);
t->bot = NULL; /* safe??? */
if (t->flag) {
BUSY_TOP (t);
UNLOCK (t->lck, pl);
np->b_datap->db_type = M_HANGUP;
putnext (t->qptr, np);
IDLE_TOP (t);
}
else {
UNLOCK (t->lck, pl);
freemsg (np);
}
}
else {
freemsg (np);
}
if (partial) freemsg (partial);
goto ack;
case XOT_IOCTL:
/* xotlink tells us that a link is for outbound */
if (iocp->ioc_count != sizeof *cmd) {
error = EINVAL;
goto iocnak;
}
cmd = (struct xot_cmd *) mp->b_cont->b_rptr;
TOPDEBUG ((top, "ioctl (%x, %x)", cmd->cookie, cmd->index));
/* use cookie to find appropriate top */
t = (struct xot_top *) cmd->cookie;
if (t < xot_top || t >= xot_top + xot_cnt) {
error = ENXIO;
goto iocnak;
}
i = t - xot_top;
if (xot_top + i != t || top->major != t->major) {
error = ENXIO;
goto iocnak;
}
np = t->ack;
t->ack = NULL;
np->b_datap->db_type = M_PCPROTO;
if (cmd->index == 0) {
/* A call we asked for has failed */
struct T_error_ack *error_ack;
freemsg (t->call);
t->call = NULL;
t->state = TS_IDLE;
error_ack = (struct T_error_ack *) np->b_rptr;
np->b_wptr = np->b_rptr + sizeof *error_ack;
error_ack->PRIM_type = T_ERROR_ACK;
error_ack->ERROR_prim = T_CONN_REQ;
error_ack->TLI_error = TSYSERR;
error_ack->UNIX_error = ECONNREFUSED;
putnext (t->qptr, np);
goto ack;
}
/* A call we asked for has been connected. */
for (bot = xot_bot; bot < last_bot; ++bot) {
pl = LOCK (bot->lck, plstr);
if (bot->flags &&
bot->major == top->major &&
bot->id == cmd->index)
break;
UNLOCK (bot->lck, pl);
}
if (bot == last_bot) {
error = ENXIO;
freemsg (np);
goto iocnak;
}
t->bot = bot;
bot->top = t;
UNLOCK (bot->lck, pl);
/* Send T_OK_ACK to x, x25_call_req to bot */