1*6834Ssam 
2*6834Ssam #include "../h/param.h"
3*6834Ssam #include "../h/systm.h"
4*6834Ssam #include "../h/mbuf.h"
5*6834Ssam #include "../h/socket.h"
6*6834Ssam #include "../h/socketvar.h"
7*6834Ssam #include "../h/protosw.h"
8*6834Ssam #include "../net/dn_systm.h"
9*6834Ssam #include "../net/if.h"
10*6834Ssam #include "../net/tp.h"
11*6834Ssam #include "../net/tp_var.h"
12*6834Ssam #include "../errno.h"
13*6834Ssam 
14*6834Ssam /*
15*6834Ssam  * Transport protocol interface to socket abstraction.
16*6834Ssam  * Used ONLY to initialize the Transport layer.  May be
17*6834Ssam  * used for routing control in the future.
18*6834Ssam  */
19*6834Ssam 
20*6834Ssam /*
21*6834Ssam  * Process a Transport user request.  Only allowed
22*6834Ssam  * operation is PRU_ATTACH to initialize the Transport
23*6834Ssam  * layer.
24*6834Ssam  */
25*6834Ssam tp_usrreq(so, req, m, addr)
26*6834Ssam 	struct socket *so;
27*6834Ssam 	int req;
28*6834Ssam 	struct mbuf *m;
29*6834Ssam 	caddr_t addr;
30*6834Ssam {
31*6834Ssam 	int s = splimp();
32*6834Ssam 	int error = 0;
33*6834Ssam 
34*6834Ssam 	/*
35*6834Ssam 	 */
36*6834Ssam 	if (so->so_pcb != 0 || req != PRU_ATTACH) {
37*6834Ssam 		splx(s);
38*6834Ssam 		return (EINVAL);		/* XXX */
39*6834Ssam 	}
40*6834Ssam 	if (tpstate != TPS_HALT) {
41*6834Ssam 		splx(s);
42*6834Ssam 		return (0);
43*6834Ssam 	}
44*6834Ssam 	if (tp_linit() == 0) {
45*6834Ssam 		splx(s);
46*6834Ssam 		return (EIO);
47*6834Ssam 	}
48*6834Ssam 	sleep((caddr_t)&tpstate, PZERO+1);
49*6834Ssam 	splx(s);
50*6834Ssam 	return (0);
51*6834Ssam }
52*6834Ssam 
53*6834Ssam /*
54*6834Ssam  * Perform transport initialization for a line
55*6834Ssam  */
56*6834Ssam tp_linit()
57*6834Ssam {
58*6834Ssam 	register struct mbuf *m;
59*6834Ssam 	register struct tpin *t;
60*6834Ssam 	register int n;
61*6834Ssam 
62*6834Ssam 	m = m_get(0);
63*6834Ssam 	if (m == 0)
64*6834Ssam 		return (0);
65*6834Ssam 	m->m_off = MMINOFF;
66*6834Ssam 	m->m_len = sizeof (struct tpin);
67*6834Ssam 	t = mtod(m, struct tpin *);
68*6834Ssam 	t->tpin_ctlflg = TP_INIT;
69*6834Ssam 	AD_SHORT(t->tpin_srcnode, tp_host);
70*6834Ssam 	t->tpin_tiinfo = TPINNT_NRT;
71*6834Ssam 	AD_SHORT(t->tpin_blksize, 1024);
72*6834Ssam 	t->tpin_ver[0] = 1;
73*6834Ssam 	t->tpin_ver[1] = 3;
74*6834Ssam 	t->tpin_ver[2] = 0;
75*6834Ssam 	t->tpin_res = 0;
76*6834Ssam 	n = (*tpifp->if_output)(tpifp, m, PF_DECNET);
77*6834Ssam 	tpstate = TPS_TIS;
78*6834Ssam 	m_freem(m);
79*6834Ssam 	return (n);
80*6834Ssam }
81