/* ts2x25.c - TPM: X.25 interface */
static char *rcsid
= "$Header: /f/osi/tsap/RCS/ts2x25.c,v 7.5 91/02/22 09:47:24 mrose Interim $";
* $Header: /f/osi/tsap/RCS/ts2x25.c,v 7.5 91/02/22 09:47:24 mrose Interim $
* Revision 7.5 91/02/22 09:47:24 mrose
* Revision 7.4 91/01/14 13:34:39 mrose
* Revision 7.3 90/07/09 14:51:23 mrose
* Revision 7.2 90/03/23 17:31:30 mrose
* Revision 7.1 89/12/07 01:07:39 mrose
* Revision 7.0 89/11/23 22:30:41 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
static fd_set inprogress
;
static struct NSAPaddr
**peers
= NULL
;
/* \f N-CONNECT.REQUEST */
int x25open (tb
, local
, remote
, td
, async
)
register struct tsapblk
*tb
;
struct TSAPdisconnect
*td
;
* start_x25_client does nothing with its arguments in the CAMTEC
* case but there's less #ifdef code this way so...
if ((fd
= start_x25_client (local
)) == NOTOK
)
return tsaplose (td
, DR_CONGEST
, "socket", "unable to start");
if (ioctl (fd
, FIONBIO
, (onoff
= 1, (char *) &onoff
)) < 0) {
(void) tsaplose (td
, DR_CONGEST
, "ioctl", "FIONBIO");
(void) close_x25_socket (fd
);
if (join_x25_server (fd
, remote
) == NOTOK
) {
peers
= (struct NSAPaddr
**)
calloc ((unsigned) getdtablesize (),
(void) tsaplose (td
, DR_CONGEST
, NULLCP
,
(void) close_x25_socket (fd
);
return (tb
-> tb_fd
= NOTOK
);
&& (peers
[fd
] = (struct NSAPaddr
*)
(void) tsaplose (td
, DR_CONGEST
, NULLCP
,
(void) close_x25_socket (fd
);
return (tb
-> tb_fd
= NOTOK
);
*(peers
[fd
]) = *remote
; /* struct copy */
FD_SET (fd
, &inprogress
);
(void) tsaplose (td
, DR_REFUSED
, "connection", "unable to establish");
LLOG (x25_log
, LLOG_NOTICE
,
("connection to %s failed", na2str (remote
)));
(void) close_x25_socket (fd
);
return (tb
-> tb_fd
= NOTOK
);
if (ioctl (fd
, FIONBIO
, (onoff
= 0, (char *) &onoff
)) < 0) {
(void) tsaplose (td
, DR_CONGEST
, "ioctl", "FIONBIO");
(void) close_x25_socket (fd
);
(void) XTService (tb
); /* in case pktsize changed... */
LLOG (x25_log
, LLOG_NOTICE
,
("connection %d to %s", fd
, na2str (remote
)));
static int x25retry (tb
, td
)
struct TSAPdisconnect
*td
;
struct NSAPaddr
*remote
= peers
[fd
];
if (xselect (fd
+ 1, NULLFD
, &mask
, NULLFD
, 0) < 1)
if (!FD_ISSET (fd
, &inprogress
))
if (join_x25_server (fd
, remote
) == NOTOK
) {
case EINVAL
: /* UNIX bug: could be any socket errno, e.g.,
(void) tsaplose (td
, DR_REFUSED
, "connection", "unable to establish");
FD_CLR (fd
, &inprogress
);
(void) close_x25_socket (fd
);
LLOG (x25_log
, LLOG_NOTICE
,
("connection to %s failed", na2str (remote
)));
return (tb
-> tb_fd
= NOTOK
);
(void) ioctl (fd
, FIONBIO
, (onoff
= 0, (char *) &onoff
));
FD_CLR (fd
, &inprogress
);
(void) XTService (tb
); /* in case pktsize changed... */
LLOG (x25_log
, LLOG_NOTICE
,
("connection %d to %s", fd
, na2str (remote
)));
/* \f init for read from network */
static char nsdu
[MAXNSDU
];
static int x25init (fd
, t
)
register struct tsapkt
*t
;
/* XXX: cc should be set to the maximum acceptable NSDU length.
Longer NSDUs will be truncated without notification.
Should be configurable (or set during N-CONNECT and remembered) */
switch (cc
= read_x25_socket (fd
, nsdu
, cc
)) {
if (compat_log
-> ll_events
& LLOG_EXCEPTIONS
)
(void) log_cause_and_diag(fd
);
t
-> t_length
= cc
+ sizeof t
-> t_pkthdr
;
if (t
-> t_length
< TPKT_HDRLEN (t
))
bl
= t
-> t_length
- TPKT_HDRLEN (t
);
t
-> t_vrsn
= TPKT_VRSN
; /* Not really needed! */
static int read_nsdu_buffer (fd
, buffer
, cc
)
char *x25save (fd
, dte1
, l1
, dte2
, l2
, td
)
struct TSAPdisconnect
*td
;
static char buffer
[BUFSIZ
];
(void) sprintf (buffer
, "%c%d %*s %*s",
NT_X25
, fd
, l1
, dte1
, l2
, dte2
);
int x25restore (tb
, buffer
, td
)
register struct tsapblk
*tb
;
struct TSAPdisconnect
*td
;
char dte1
[NSAP_DTELEN
+ 1],
register struct NSAPaddr
*na
;
register struct tsapADDR
*ta
;
if (sscanf (buffer
, "%d %s %s", &fd
, dte1
, dte2
) != 3 || fd
< 0)
return tsaplose (td
, DR_PARAMETER
, NULLCP
,
"bad initialization vector \"%s\"", buffer
);
ta
= &tb
-> tb_initiating
;
na
-> na_community
= ts_comm_x25_default
;
bcopy(dte1
, na
-> na_dte
, strlen(dte1
));
na
-> na_dtelen
= strlen (na
-> na_dte
);
ta
= &tb
-> tb_responding
;
na
-> na_community
= ts_comm_x25_default
;
bcopy(dte2
, na
-> na_dte
, strlen(dte2
));
na
-> na_dtelen
= strlen (na
-> na_dte
);
(void) set_x25_facilities (tb
-> tb_fd
, -1, "Negotiated");
register struct tsapblk
*tb
;
int maxnsdu
= X25_PACKETSIZE
;
tb
-> tb_flags
|= TB_X25
;
if (recvpktsize
> DT_MAGIC
&& recvpktsize
< maxnsdu
)
if (sendpktsize
> DT_MAGIC
&& sendpktsize
< maxnsdu
)
tb
-> tb_tsdusize
= maxnsdu
- (tb
-> tb_tpduslop
= DT_MAGIC
);
tb
-> tb_retryfnx
= x25retry
;
tb
-> tb_initfnx
= x25init
;
tb
-> tb_readfnx
= read_nsdu_buffer
;
tb
-> tb_writefnx
= tp0write
;
tb
-> tb_closefnx
= close_x25_socket
;
tb
-> tb_selectfnx
= select_x25_socket
;