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