2 * ===================================
3 * HARP | Host ATM Research Platform
4 * ===================================
7 * This Host ATM Research Platform ("HARP") file (the "Software") is
8 * made available by Network Computing Services, Inc. ("NetworkCS")
9 * "AS IS". NetworkCS does not provide maintenance, improvements or
10 * support of any kind.
12 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
13 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
14 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
15 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
16 * In no event shall NetworkCS be responsible for any damages, including
17 * but not limited to consequential damages, arising from or relating to
18 * any use of the Software or related support.
20 * Copyright 1994-1998 Network Computing Services, Inc.
22 * Copies of this Software may be made, however, the above copyright
23 * notice must be reproduced on all copies.
30 * ATM AAL5 socket protocol processing
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
38 #include <sys/protosw.h>
39 #include <sys/signalvar.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
44 #include <sys/systm.h>
46 #include <netatm/port.h>
47 #include <netatm/queue.h>
48 #include <netatm/atm.h>
49 #include <netatm/atm_sys.h>
50 #include <netatm/atm_sap.h>
51 #include <netatm/atm_cm.h>
52 #include <netatm/atm_if.h>
53 #include <netatm/atm_stack.h>
54 #include <netatm/atm_pcb.h>
55 #include <netatm/atm_var.h>
61 u_long atm_aal5_sendspace = 64 * 1024; /* XXX */
62 u_long atm_aal5_recvspace = 64 * 1024; /* XXX */
68 static int atm_aal5_attach(struct socket *, int, struct thread *td);
69 static int atm_aal5_detach(struct socket *);
70 static int atm_aal5_bind(struct socket *, struct sockaddr *,
72 static int atm_aal5_listen(struct socket *, struct thread *td);
73 static int atm_aal5_connect(struct socket *, struct sockaddr *,
75 static int atm_aal5_accept(struct socket *, struct sockaddr **);
76 static int atm_aal5_disconnect(struct socket *);
77 static int atm_aal5_shutdown(struct socket *);
78 static int atm_aal5_send(struct socket *, int, KBuffer *,
79 struct sockaddr *, KBuffer *, struct thread *td);
80 static int atm_aal5_abort(struct socket *);
81 static int atm_aal5_control(struct socket *, u_long, caddr_t,
82 struct ifnet *, struct thread *td);
83 static int atm_aal5_sense(struct socket *, struct stat *);
84 static int atm_aal5_sockaddr(struct socket *, struct sockaddr **);
85 static int atm_aal5_peeraddr(struct socket *, struct sockaddr **);
86 static int atm_aal5_incoming(void *, Atm_connection *,
87 Atm_attributes *, void **);
88 static void atm_aal5_cpcs_data(void *, KBuffer *);
89 static caddr_t atm_aal5_getname(void *);
93 * New-style socket request routines
95 struct pr_usrreqs atm_aal5_usrreqs = {
96 .pru_abort = atm_aal5_abort,
97 .pru_accept = atm_aal5_accept,
98 .pru_attach = atm_aal5_attach,
99 .pru_bind = atm_aal5_bind,
100 .pru_connect = atm_aal5_connect,
101 .pru_control = atm_aal5_control,
102 .pru_detach = atm_aal5_detach,
103 .pru_disconnect = atm_aal5_disconnect,
104 .pru_listen = atm_aal5_listen,
105 .pru_peeraddr = atm_aal5_peeraddr,
106 .pru_send = atm_aal5_send,
107 .pru_sense = atm_aal5_sense,
108 .pru_shutdown = atm_aal5_shutdown,
109 .pru_sockaddr = atm_aal5_sockaddr,
115 static Atm_endpoint atm_aal5_endpt = {
133 static Atm_attributes atm_aal5_defattr = {
135 CMAPI_CPCS, /* api */
186 * Handy common code macros
189 #define ATM_INTRO(f) \
192 ATM_DEBUG2("aal5 socket %s (%p)\n", f, so); \
194 * Stack queue should have been drained \
196 if (atm_stackq_head != NULL) \
197 panic("atm_aal5: stack queue not empty"); \
199 #else /* !DIAGNOSTIC */
200 #define ATM_INTRO(f) \
204 #endif /* DIAGNOSTIC */
206 #define ATM_OUTRO() \
208 * Drain any deferred calls \
215 #define ATM_RETERR(errno) { \
222 * Attach protocol to socket
225 * so pointer to socket
226 * proto protocol identifier
227 * p pointer to process
230 * 0 request processed
231 * errno error processing request - reason indicated
235 atm_aal5_attach(so, proto, td)
245 * Do general attach stuff
247 err = atm_sock_attach(so, atm_aal5_sendspace, atm_aal5_recvspace);
252 * Finish up any protocol specific stuff
254 atp = sotoatmpcb(so);
255 atp->atp_type = ATPT_AAL5;
258 * Set default connection attributes
260 atp->atp_attr = atm_aal5_defattr;
261 strncpy(atp->atp_name, "(AAL5)", T_ATM_APP_NAME_LEN);
269 * Detach protocol from socket
272 * so pointer to socket
275 * 0 request processed
276 * errno error processing request - reason indicated
285 err = atm_sock_detach(so);
292 * Bind address to socket
295 * so pointer to socket
296 * addr pointer to protocol address
297 * p pointer to process
300 * 0 request processed
301 * errno error processing request - reason indicated
305 atm_aal5_bind(so, addr, td)
307 struct sockaddr *addr;
312 err = atm_sock_bind(so, addr);
319 * Listen for incoming connections
322 * so pointer to socket
323 * p pointer to process
326 * 0 request processed
327 * errno error processing request - reason indicated
331 atm_aal5_listen(so, td)
337 err = atm_sock_listen(so, &atm_aal5_endpt);
344 * Connect socket to peer
347 * so pointer to socket
348 * addr pointer to protocol address
349 * p pointer to process
352 * 0 request processed
353 * errno error processing request - reason indicated
357 atm_aal5_connect(so, addr, td)
359 struct sockaddr *addr;
364 ATM_INTRO("connect");
366 atp = sotoatmpcb(so);
369 * Resize send socket buffer to maximum sdu size
371 if (atp->atp_attr.aal.tag == T_ATM_PRESENT) {
374 size = atp->atp_attr.aal.v.aal5.forward_max_SDU_size;
375 if (size != T_ATM_ABSENT)
376 if (!sbreserve(&so->so_snd, size, so, td)) {
384 * Now get the socket connected
386 err = atm_sock_connect(so, addr, &atm_aal5_endpt);
393 * Accept pending connection
396 * so pointer to socket
397 * addr pointer to pointer to contain protocol address
400 * 0 request processed
401 * errno error processing request - reason indicated
405 atm_aal5_accept(so, addr)
407 struct sockaddr **addr;
412 * Everything is pretty much done already, we just need to
413 * return the caller's address to the user.
415 err = atm_sock_peeraddr(so, addr);
422 * Disconnect connected socket
425 * so pointer to socket
428 * 0 request processed
429 * errno error processing request - reason indicated
433 atm_aal5_disconnect(so)
436 ATM_INTRO("disconnect");
438 err = atm_sock_disconnect(so);
445 * Shut down socket data transmission
448 * so pointer to socket
451 * 0 request processed
452 * errno error processing request - reason indicated
456 atm_aal5_shutdown(so)
459 ATM_INTRO("shutdown");
471 * so pointer to socket
472 * flags send data flags
473 * m pointer to buffer containing user data
474 * addr pointer to protocol address
475 * control pointer to buffer containing protocol control data
476 * p pointer to process
479 * 0 request processed
480 * errno error processing request - reason indicated
484 atm_aal5_send(so, flags, m, addr, control, td)
488 struct sockaddr *addr;
497 * We don't support any control functions
502 clen = KB_LEN(control);
511 * We also don't support any flags or send-level addressing
519 * All we've got left is the data, so push it out
521 atp = sotoatmpcb(so);
522 err = atm_cm_cpcs_data(atp->atp_conn, m);
525 * Output problem, drop packet
527 atm_sock_stat.as_outdrop[atp->atp_type]++;
537 * Abnormally terminate service
540 * so pointer to socket
543 * 0 request processed
544 * errno error processing request - reason indicated
553 so->so_error = ECONNABORTED;
554 err = atm_sock_detach(so);
561 * Do control operation - ioctl system call
564 * so pointer to socket
566 * data pointer to code specific parameter data area
567 * ifp pointer to ifnet structure if it's an interface ioctl
568 * p pointer to process
571 * 0 request processed
572 * errno error processing request - reason indicated
576 atm_aal5_control(so, cmd, data, ifp, td)
583 ATM_INTRO("control");
595 * Sense socket status - fstat system call
598 * so pointer to socket
599 * st pointer to file status structure
602 * 0 request processed
603 * errno error processing request - reason indicated
607 atm_aal5_sense(so, st)
614 * Just return the max sdu size for the connection
616 st->st_blksize = so->so_snd.sb_hiwat;
623 * Retrieve local socket address
626 * so pointer to socket
627 * addr pointer to pointer to contain protocol address
630 * 0 request processed
631 * errno error processing request - reason indicated
635 atm_aal5_sockaddr(so, addr)
637 struct sockaddr **addr;
639 ATM_INTRO("sockaddr");
641 err = atm_sock_sockaddr(so, addr);
648 * Retrieve peer socket address
651 * so pointer to socket
652 * addr pointer to pointer to contain protocol address
655 * 0 request processed
656 * errno error processing request - reason indicated
660 atm_aal5_peeraddr(so, addr)
662 struct sockaddr **addr;
664 ATM_INTRO("peeraddr");
666 err = atm_sock_peeraddr(so, addr);
673 * Process Incoming Calls
675 * This function will receive control when an incoming call has been matched
676 * to one of our registered listen parameter blocks. Assuming the call passes
677 * acceptance criteria and all required resources are available, we will
678 * create a new protocol control block and socket association. We must
679 * then await notification of the final SVC setup results. If any
680 * problems are encountered, we will just tell the connection manager to
686 * tok owner's matched listening token
687 * cop pointer to incoming call's connection block
688 * ap pointer to incoming call's attributes
689 * tokp pointer to location to store our connection token
693 * errno call rejected - reason indicated
697 atm_aal5_incoming(tok, cop, ap, tokp)
703 Atm_pcb *atp0 = tok, *atp;
708 * Allocate a new socket and pcb for this connection.
710 * Note that our attach function will be called via sonewconn
711 * and it will allocate and setup most of the pcb.
713 atm_sock_stat.as_inconn[atp0->atp_type]++;
714 so = sonewconn(atp0->atp_socket, 0);
718 * Finish pcb setup and pass pcb back to CM
720 atp = sotoatmpcb(so);
722 atp->atp_attr = *atp0->atp_conn->co_lattr;
723 strncpy(atp->atp_name, atp0->atp_name, T_ATM_APP_NAME_LEN);
727 atm_sock_stat.as_connfail[atp0->atp_type]++;
735 * Process Socket VCC Input Data
738 * tok owner's connection token (atm_pcb)
739 * m pointer to input packet buffer chain
746 atm_aal5_cpcs_data(tok, m)
754 so = atp->atp_socket;
759 * Ensure that the socket is able to receive data and
760 * that there's room in the socket buffer
762 if (((so->so_state & SS_ISCONNECTED) == 0) ||
763 (so->so_rcv.sb_state & SBS_CANTRCVMORE) ||
764 (len > sbspace(&so->so_rcv))) {
765 atm_sock_stat.as_indrop[atp->atp_type]++;
771 * Queue the data and notify the user
773 sbappendrecord(&so->so_rcv, m);
781 * Process getsockopt/setsockopt system calls
784 * so pointer to socket
785 * sopt pointer to socket option info
788 * 0 request processed
789 * errno error processing request - reason indicated
793 atm_aal5_ctloutput(so, sopt)
795 struct sockopt *sopt;
799 ATM_INTRO("ctloutput");
802 * Make sure this is for us
804 if (sopt->sopt_level != T_ATM_SIGNALING) {
807 atp = sotoatmpcb(so);
809 ATM_RETERR(ENOTCONN);
812 switch (sopt->sopt_dir) {
820 * Validate socket state
822 switch (sopt->sopt_name) {
825 case T_ATM_DROP_LEAF:
826 if ((so->so_state & SS_ISCONNECTED) == 0) {
827 ATM_RETERR(ENOTCONN);
836 if (so->so_state & SS_ISCONNECTED) {
843 * Validate and save user-supplied option data
845 err = atm_sock_setopt(so, sopt, atp);
857 err = atm_sock_getopt(so, sopt, atp);
868 * Initialize AAL5 Sockets
881 * Register our endpoint
883 if (atm_endpoint_register(&atm_aal5_endpt))
884 panic("atm_aal5_init: register");
887 * Set default connection attributes
889 atm_aal5_defattr.aal.v.aal5.forward_max_SDU_size = T_ATM_ABSENT;
890 atm_aal5_defattr.aal.v.aal5.backward_max_SDU_size = T_ATM_ABSENT;
891 atm_aal5_defattr.aal.v.aal5.SSCS_type = T_ATM_NULL;
896 * Get Connection's Application/Owner Name
899 * tok owner's connection token (atm_pcb)
902 * addr pointer to string containing our name
906 atm_aal5_getname(tok)
911 return (atp->atp_name);