1*9833Ssam /*	tp_usrreq.c	1.4	82/12/18	*/
26834Ssam 
36834Ssam #include "../h/param.h"
46834Ssam #include "../h/systm.h"
56834Ssam #include "../h/mbuf.h"
66834Ssam #include "../h/socket.h"
76834Ssam #include "../h/socketvar.h"
86834Ssam #include "../h/protosw.h"
98413Swnj #include "../netdecnet/dn_systm.h"
108413Swnj #include "../netdecnet/tp.h"
118413Swnj #include "../netdecnet/tp_var.h"
126834Ssam 
136834Ssam /*
146834Ssam  * Transport protocol interface to socket abstraction.
156834Ssam  * Used ONLY to initialize the Transport layer.  May be
166834Ssam  * used for routing control in the future.
176834Ssam  */
186834Ssam 
196834Ssam /*
206834Ssam  * Process a Transport user request.  Only allowed
216834Ssam  * operation is PRU_ATTACH to initialize the Transport
226834Ssam  * layer.
236834Ssam  */
246834Ssam tp_usrreq(so, req, m, addr)
256834Ssam 	struct socket *so;
266834Ssam 	int req;
276834Ssam 	struct mbuf *m;
286834Ssam 	caddr_t addr;
296834Ssam {
306834Ssam 	int s = splimp();
316834Ssam 	int error = 0;
326834Ssam 
336834Ssam 	/*
346834Ssam 	 */
356834Ssam 	if (so->so_pcb != 0 || req != PRU_ATTACH) {
366834Ssam 		splx(s);
376834Ssam 		return (EINVAL);		/* XXX */
386834Ssam 	}
396834Ssam 	if (tpstate != TPS_HALT) {
406834Ssam 		splx(s);
416834Ssam 		return (0);
426834Ssam 	}
436834Ssam 	if (tp_linit() == 0) {
446834Ssam 		splx(s);
456834Ssam 		return (EIO);
466834Ssam 	}
476834Ssam 	sleep((caddr_t)&tpstate, PZERO+1);
486834Ssam 	splx(s);
496834Ssam 	return (0);
506834Ssam }
516834Ssam 
526834Ssam /*
536834Ssam  * Perform transport initialization for a line
546834Ssam  */
tp_linit()556834Ssam tp_linit()
566834Ssam {
576834Ssam 	register struct mbuf *m;
586834Ssam 	register struct tpin *t;
596834Ssam 	register int n;
606834Ssam 
61*9833Ssam 	m = m_get(MT_CANTWAIT, MT_HEADER);
626834Ssam 	if (m == 0)
636834Ssam 		return (0);
646834Ssam 	m->m_off = MMINOFF;
656834Ssam 	m->m_len = sizeof (struct tpin);
666834Ssam 	t = mtod(m, struct tpin *);
676834Ssam 	t->tpin_ctlflg = TP_INIT;
686834Ssam 	AD_SHORT(t->tpin_srcnode, tp_host);
696834Ssam 	t->tpin_tiinfo = TPINNT_NRT;
706834Ssam 	AD_SHORT(t->tpin_blksize, 1024);
716834Ssam 	t->tpin_ver[0] = 1;
726834Ssam 	t->tpin_ver[1] = 3;
736834Ssam 	t->tpin_ver[2] = 0;
746834Ssam 	t->tpin_res = 0;
756834Ssam 	n = (*tpifp->if_output)(tpifp, m, PF_DECNET);
766834Ssam 	tpstate = TPS_TIS;
776834Ssam 	m_freem(m);
786834Ssam 	return (n);
796834Ssam }
80