3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/uni/unisig_if.c,v 1.8 2000/01/17 20:49:56 mks Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/uni/unisig_if.c,v 1.9 2006/12/20 18:14:43 dillon Exp $
31 * ATM Forum UNI 3.0/3.1 Signalling Manager
32 * ----------------------------------------
34 * System interface module
38 #include <netproto/atm/kern_include.h>
40 #include <netproto/atm/ipatm/ipatm_var.h>
41 #include <netproto/atm/ipatm/ipatm_serv.h>
42 #include "uniip_var.h"
45 #include "unisig_var.h"
46 #include "unisig_msg.h"
51 struct sp_info unisig_vcpool
= {
52 "unisig vcc pool", /* si_name */
53 sizeof(struct unisig_vccb
), /* si_blksiz */
58 struct sp_info unisig_msgpool
= {
59 "unisig message pool", /* si_name */
60 sizeof(struct unisig_msg
), /* si_blksiz */
65 struct sp_info unisig_iepool
= {
66 "unisig ie pool", /* si_name */
67 sizeof(struct ie_generic
), /* si_blksiz */
76 static int unisig_attach (struct sigmgr
*, struct atm_pif
*);
77 static int unisig_detach (struct atm_pif
*);
78 static int unisig_setup (Atm_connvc
*, int *);
79 static int unisig_release (struct vccb
*, int *);
80 static int unisig_accept (struct vccb
*, int *);
81 static int unisig_reject (struct vccb
*, int *);
82 static int unisig_abort (struct vccb
*);
83 static int unisig_ioctl (int, caddr_t
, caddr_t
);
89 static struct sigmgr unisig_mgr30
= {
103 static struct sigmgr unisig_mgr31
= {
119 * Initialize UNISIG processing
121 * This will be called during module loading. We'll just register
122 * the UNISIG protocol descriptor and wait for a UNISIG ATM interface
129 * 0 startup was successful
130 * errno startup failed - reason indicated
139 * Verify software version
141 if (atm_version
!= ATM_VERSION
) {
142 log(LOG_ERR
, "version mismatch: unisig=%d.%d kernel=%d.%d\n",
143 ATM_VERS_MAJ(ATM_VERSION
),
144 ATM_VERS_MIN(ATM_VERSION
),
145 ATM_VERS_MAJ(atm_version
),
146 ATM_VERS_MIN(atm_version
));
151 * Register ourselves with system
153 err
= atm_sigmgr_register(&unisig_mgr30
);
157 err
= atm_sigmgr_register(&unisig_mgr31
);
165 * Halt UNISIG processing
167 * This should be called just prior to unloading the module from
168 * memory. All UNISIG interfaces must be deregistered before the
169 * protocol can be shutdown.
175 * 0 startup was successful
176 * errno startup failed - reason indicated
187 * Any protocol instances still registered?
189 if ((unisig_mgr30
.sm_prinst
!= NULL
) ||
190 (unisig_mgr31
.sm_prinst
!= NULL
)) {
192 /* Yes, can't stop now */
198 * De-register from system
200 atm_sigmgr_deregister(&unisig_mgr30
);
201 atm_sigmgr_deregister(&unisig_mgr31
);
204 * Free up our storage pools
206 atm_release_pool(&unisig_vcpool
);
207 atm_release_pool(&unisig_msgpool
);
208 atm_release_pool(&unisig_iepool
);
217 * Attach a UNISIG-controlled interface
219 * Each ATM physical interface must be attached with the signalling
220 * manager for the interface's signalling protocol (via the
221 * atm_sigmgr_attach function). This function will handle the
222 * attachment for UNISIG-controlled interfaces. A new UNISIG protocol
223 * instance will be created and then we'll just sit around waiting for
224 * status or connection requests.
226 * Function must be called from a critical section.
229 * smp pointer to UNISIG signalling manager control block
230 * pip pointer to ATM physical interface control block
233 * 0 attach successful
234 * errno attach failed - reason indicated
238 unisig_attach(struct sigmgr
*smp
, struct atm_pif
*pip
)
241 struct unisig
*usp
= NULL
;
243 ATM_DEBUG2("unisig_attach: smp=%p, pip=%p\n", smp
, pip
);
246 * Allocate UNISIG protocol instance control block
248 usp
= KM_ALLOC(sizeof(struct unisig
), M_DEVBUF
, M_INTWAIT
| M_NULLOK
);
253 KM_ZERO(usp
, sizeof(struct unisig
));
256 * Set state in UNISIG protocol instance control block
258 usp
->us_state
= UNISIG_NULL
;
259 usp
->us_proto
= smp
->sm_proto
;
262 * Set initial call reference allocation value
267 * Link instance into manager's chain
269 LINK2TAIL((struct siginst
*)usp
, struct siginst
, smp
->sm_prinst
,
277 pip
->pif_sigmgr
= smp
;
278 pip
->pif_siginst
= (struct siginst
*) usp
;
282 * Clear our ATM address. The address will be set by user
283 * command or by registration via ILMI.
285 usp
->us_addr
.address_format
= T_ATM_ABSENT
;
286 usp
->us_addr
.address_length
= 0;
287 usp
->us_subaddr
.address_format
= T_ATM_ABSENT
;
288 usp
->us_subaddr
.address_length
= 0;
293 usp
->us_ipserv
= &uniip_ipserv
;
296 * Kick-start the UNISIG protocol
298 UNISIG_TIMER(usp
, 0);
301 * Log the fact that we've attached
303 log(LOG_INFO
, "unisig: attached to interface %s%d\n",
304 pip
->pif_name
, pip
->pif_unit
);
308 * Reset our work if attach fails
313 UNLINK((struct siginst
*)usp
, struct siginst
,
314 smp
->sm_prinst
, si_next
);
315 KM_FREE(usp
, sizeof(struct unisig
), M_DEVBUF
);
318 pip
->pif_sigmgr
= NULL
;
319 pip
->pif_siginst
= NULL
;
328 * Detach a UNISIG-controlled interface
330 * Each ATM physical interface may be detached from its signalling
331 * manager (via the atm_sigmgr_detach function). This function will
332 * handle the detachment for all UNISIG-controlled interfaces. All
333 * circuits will be immediately terminated.
335 * Function must be called from a critical section.
338 * pip pointer to ATM physical interface control block
341 * 0 detach successful
342 * errno detach failed - reason indicated
346 unisig_detach(struct atm_pif
*pip
)
351 ATM_DEBUG1("unisig_detach: pip=%p\n", pip
);
354 * Get UNISIG protocol instance
356 usp
= (struct unisig
*)pip
->pif_siginst
;
359 * Return an error if we're already detaching
361 if (usp
->us_state
== UNISIG_DETACH
) {
366 * Pass the detach event to the signalling manager
369 err
= unisig_sigmgr_state(usp
, UNISIG_SIGMGR_DETACH
, NULL
);
372 * Log the fact that we've detached
375 log(LOG_INFO
, "unisig: detached from interface %s%d\n",
376 pip
->pif_name
, pip
->pif_unit
);
383 * Open a UNISIG ATM Connection
385 * All service user requests to open a VC connection (via
386 * atm_open_connection) over an ATM interface attached to the UNISIG
387 * signalling manager are handled here.
389 * Function will be called from a critical section.
392 * cvp pointer to user's requested connection parameters
393 * errp pointer to an int for extended error information
396 * CALL_PROCEEDING connection establishment is in progress
397 * CALL_FAILED connection establishment failed
398 * CALL_CONNECTED connection has been successfully established
402 unisig_setup(Atm_connvc
*cvp
, int *errp
)
404 struct atm_pif
*pip
= cvp
->cvc_attr
.nif
->nif_pif
;
405 struct unisig
*usp
= (struct unisig
*)pip
->pif_siginst
;
408 ATM_DEBUG1("unisig_setup: cvp=%p\n", cvp
);
411 * Intialize the returned error code
416 * Open the connection
418 switch (cvp
->cvc_attr
.called
.addr
.address_format
) {
423 *errp
= unisig_open_vcc(usp
, cvp
);
424 rc
= (*errp
? CALL_FAILED
: CALL_CONNECTED
);
427 case T_ATM_ENDSYS_ADDR
:
428 case T_ATM_E164_ADDR
:
433 *errp
= unisig_open_vcc(usp
, cvp
);
434 rc
= (*errp
? CALL_FAILED
: CALL_PROCEEDING
);
438 *errp
= EPROTONOSUPPORT
;
447 * Close a UNISIG ATM Connection
449 * All service user requests to terminate a previously open VC
450 * connection (via the atm_close_connection function), which is running
451 * over an interface attached to the UNISIG signalling manager, are
454 * Function will be called from a critical section.
457 * vcp pointer to connection's VC control block
458 * errp pointer to an int for extended error information
461 * CALL_PROCEEDING connection termination is in progress
462 * CALL_FAILED connection termination failed
463 * CALL_CLEARED connection has been successfully terminated
467 unisig_release(struct vccb
*vcp
, int *errp
)
470 struct atm_pif
*pip
= vcp
->vc_pif
;
471 struct unisig
*usp
= (struct unisig
*)pip
->pif_siginst
;
473 ATM_DEBUG1("unisig_release: vcp=%p\n", vcp
);
476 * Initialize returned error code
481 * Validate the connection type (PVC or SVC)
483 if (!(vcp
->vc_type
& (VCC_PVC
| VCC_SVC
))) {
484 *errp
= EPROTONOSUPPORT
;
491 *errp
= unisig_close_vcc(usp
, (struct unisig_vccb
*)vcp
);
494 * Set the return code
498 } else if (vcp
->vc_sstate
== UNI_NULL
||
499 vcp
->vc_sstate
== UNI_FREE
) {
502 rc
= CALL_PROCEEDING
;
510 * Accept a UNISIG Open from a remote host
512 * A user calls this routine (via the atm_accept_call function)
513 * after it is notified that an open request was received for it.
515 * Function will be called from a critical section.
518 * vcp pointer to user's VCCB
519 * errp pointer to an int for extended error information
522 * CALL_PROCEEDING connection establishment is in progress
523 * CALL_FAILED connection establishment failed
524 * CALL_CONNECTED connection has been successfully established
528 unisig_accept(struct vccb
*vcp
, int *errp
)
530 struct unisig_vccb
*uvp
= (struct unisig_vccb
*)vcp
;
531 struct atm_pif
*pip
= uvp
->uv_pif
;
532 struct unisig
*usp
= (struct unisig
*)pip
->pif_siginst
;
534 ATM_DEBUG1("unisig_accept: vcp=%p\n", vcp
);
537 * Initialize the returned error code
542 * Return an error if we're detaching
544 if (usp
->us_state
== UNISIG_DETACH
) {
550 * Return an error if we lost the connection
552 if (uvp
->uv_sstate
== UNI_FREE
) {
558 * Pass the acceptance to the VC state machine
560 *errp
= unisig_vc_state(usp
, uvp
, UNI_VC_ACCEPT_CALL
, NULL
);
564 return(CALL_PROCEEDING
);
568 * On error, free the VCCB and return CALL_FAILED
572 uvp
->uv_sstate
= UNI_FREE
;
573 uvp
->uv_ustate
= VCCU_CLOSED
;
574 DEQUEUE(uvp
, struct unisig_vccb
, uv_sigelem
, usp
->us_vccq
);
575 unisig_free((struct vccb
*)uvp
);
582 * Reject a UNISIG Open from a remote host
584 * A user calls this routine (via the atm_reject_call function)
585 * after it is notified that an open request was received for it.
587 * Function will be called from a critical section.
590 * uvp pointer to user's VCCB
591 * errp pointer to an int for extended error information
594 * CALL_CLEARED call request rejected
595 * CALL_FAILED call rejection failed
599 unisig_reject(struct vccb
*vcp
, int *errp
)
601 struct unisig_vccb
*uvp
= (struct unisig_vccb
*)vcp
;
602 struct atm_pif
*pip
= uvp
->uv_pif
;
603 struct unisig
*usp
= (struct unisig
*)pip
->pif_siginst
;
605 ATM_DEBUG1("unisig_reject: uvp=%p\n", uvp
);
608 * Initialize the returned error code
614 * Return an error if we're detaching
616 if (usp
->us_state
== UNISIG_DETACH
) {
622 * Call the VC state machine
624 *errp
= unisig_vc_state(usp
, uvp
, UNI_VC_REJECT_CALL
, NULL
);
628 return(CALL_CLEARED
);
632 * On error, free the VCCB and return CALL_FAILED
634 uvp
->uv_sstate
= UNI_FREE
;
635 uvp
->uv_ustate
= VCCU_CLOSED
;
636 DEQUEUE(uvp
, struct unisig_vccb
, uv_sigelem
, usp
->us_vccq
);
637 unisig_free((struct vccb
*)uvp
);
643 * Abort a UNISIG ATM Connection
645 * All (non-user) requests to abort a previously open VC connection (via
646 * the atm_abort_connection function), which is running over an
647 * interface attached to the UNISIG signalling manager, are handled here.
648 * The VCC owner will be notified of the request, in order to initiate
649 * termination of the connection.
651 * Function will be called from a critical section.
654 * vcp pointer to connection's VC control block
657 * 0 connection release was successful
658 * errno connection release failed - reason indicated
662 unisig_abort(struct vccb
*vcp
)
665 ATM_DEBUG1("unisig_abort: vcp=%p\n", vcp
);
670 if (vcp
->vc_ustate
== VCCU_ABORT
) {
675 * Cancel any timer that might be running
677 UNISIG_VC_CANCEL(vcp
);
680 * Set immediate timer to schedule connection termination
682 vcp
->vc_ustate
= VCCU_ABORT
;
683 UNISIG_VC_TIMER(vcp
, 0);
690 * Free UNISIG ATM connection resources
692 * All service user requests to free the resources of a closed VCC
693 * connection (via the atm_free_connection function), which is running
694 * over an interface attached to the UNISIG signalling manager, are
697 * Function will be called from a critical section.
700 * vcp pointer to connection's VC control block
703 * 0 connection free was successful
704 * errno connection free failed - reason indicated
708 unisig_free(struct vccb
*vcp
)
710 struct atm_pif
*pip
= vcp
->vc_pif
;
711 struct unisig
*usp
= (struct unisig
*)pip
->pif_siginst
;
713 ATM_DEBUG1("unisig_free: vcp = %p\n", vcp
);
716 * Make sure VCC has been closed
718 if ((vcp
->vc_ustate
!= VCCU_CLOSED
&&
719 vcp
->vc_ustate
!= VCCU_ABORT
) ||
720 vcp
->vc_sstate
!= UNI_FREE
) {
721 ATM_DEBUG2("unisig_free: bad state, sstate=%d, ustate=%d\n",
722 vcp
->vc_sstate
, vcp
->vc_ustate
);
727 * Remove VCCB from protocol queue
729 DEQUEUE(vcp
, struct vccb
, vc_sigelem
, usp
->us_vccq
);
734 vcp
->vc_ustate
= VCCU_NULL
;
735 vcp
->vc_sstate
= UNI_NULL
;
736 atm_free((caddr_t
)vcp
);
739 * If we're detaching and this was the last VCC queued,
740 * get rid of the protocol instance
742 if ((usp
->us_state
== UNISIG_DETACH
) &&
743 (Q_HEAD(usp
->us_vccq
, struct vccb
) == NULL
)) {
744 struct sigmgr
*smp
= pip
->pif_sigmgr
;
747 pip
->pif_sigmgr
= NULL
;
748 pip
->pif_siginst
= NULL
;
751 UNLINK((struct siginst
*)usp
, struct siginst
,
752 smp
->sm_prinst
, si_next
);
753 KM_FREE(usp
, sizeof(struct unisig
), M_DEVBUF
);
761 * UNISIG IOCTL support
763 * Function will be called from a critical section.
766 * code PF_ATM sub-operation code
767 * data pointer to code specific parameter data area
768 * arg1 pointer to code specific argument
772 * errno error processing request - reason indicated
776 unisig_ioctl(int code
, caddr_t data
, caddr_t arg1
)
778 struct atmdelreq
*adp
;
779 struct atminfreq
*aip
;
780 struct atmsetreq
*asp
;
782 struct unisig_vccb
*uvp
;
783 struct air_vcc_rsp rsp
;
787 int err
= 0, buf_len
, i
;
790 ATM_DEBUG1("unisig_ioctl: code=%d\n", code
);
799 adp
= (struct atmdelreq
*)data
;
800 usp
= (struct unisig
*)arg1
;
803 * Don't let a user close the UNISIG signalling VC
805 vpi
= adp
->adr_pvc_vpi
;
806 vci
= adp
->adr_pvc_vci
;
807 if ((vpi
== UNISIG_SIG_VPI
&& vci
== UNISIG_SIG_VCI
))
813 for (uvp
= Q_HEAD(usp
->us_vccq
, struct unisig_vccb
); uvp
;
814 uvp
= Q_NEXT(uvp
, struct unisig_vccb
, uv_sigelem
)) {
815 if ((uvp
->uv_vpi
== vpi
) && (uvp
->uv_vci
== vci
))
826 if (!(uvp
->uv_type
& VCC_PVC
)) {
831 if (!(uvp
->uv_type
& VCC_SVC
)) {
838 * Schedule VCC termination
840 unisig_cause_attr_from_user(&uvp
->uv_connvc
->cvc_attr
,
841 T_ATM_CAUSE_UNSPECIFIED_NORMAL
);
842 err
= unisig_abort((struct vccb
*)uvp
);
847 * Return VCC information
849 aip
= (struct atminfreq
*)data
;
850 usp
= (struct unisig
*)arg1
;
852 buf_addr
= aip
->air_buf_addr
;
853 buf_len
= aip
->air_buf_len
;
856 * Loop through the VCC queue
858 for (uvp
= Q_HEAD(usp
->us_vccq
, struct unisig_vccb
); uvp
;
859 uvp
= Q_NEXT(uvp
, struct unisig_vccb
, uv_sigelem
)) {
861 * Make sure there's room in the user's buffer
863 if (buf_len
< sizeof(rsp
)) {
869 * Fill out the response struct for the VCC
871 ksnprintf(rsp
.avp_intf
,
872 sizeof(rsp
.avp_intf
), "%s%d",
873 usp
->us_pif
->pif_name
,
874 usp
->us_pif
->pif_unit
);
875 rsp
.avp_vpi
= uvp
->uv_vpi
;
876 rsp
.avp_vci
= uvp
->uv_vci
;
877 rsp
.avp_type
= uvp
->uv_type
;
878 rsp
.avp_aal
= uvp
->uv_connvc
->cvc_attr
.aal
.type
;
879 rsp
.avp_sig_proto
= uvp
->uv_proto
;
880 cop
= uvp
->uv_connvc
->cvc_conn
;
882 rsp
.avp_encaps
= cop
->co_mpx
;
885 rsp
.avp_state
= uvp
->uv_sstate
;
886 if (uvp
->uv_connvc
->cvc_flags
& CVCF_CALLER
) {
887 rsp
.avp_daddr
= uvp
->uv_connvc
->cvc_attr
.called
.addr
;
889 rsp
.avp_daddr
= uvp
->uv_connvc
->cvc_attr
.calling
.addr
;
891 rsp
.avp_dsubaddr
.address_format
= T_ATM_ABSENT
;
892 rsp
.avp_dsubaddr
.address_length
= 0;
893 rsp
.avp_ipdus
= uvp
->uv_ipdus
;
894 rsp
.avp_opdus
= uvp
->uv_opdus
;
895 rsp
.avp_ibytes
= uvp
->uv_ibytes
;
896 rsp
.avp_obytes
= uvp
->uv_obytes
;
897 rsp
.avp_ierrors
= uvp
->uv_ierrors
;
898 rsp
.avp_oerrors
= uvp
->uv_oerrors
;
899 rsp
.avp_tstamp
= uvp
->uv_tstamp
;
900 KM_ZERO(rsp
.avp_owners
,
901 sizeof(rsp
.avp_owners
));
902 for (i
= 0; cop
&& i
< sizeof(rsp
.avp_owners
);
904 i
+= T_ATM_APP_NAME_LEN
+1) {
905 strncpy(&rsp
.avp_owners
[i
],
906 cop
->co_endpt
->ep_getname(cop
->co_toku
),
911 * Copy the response into the user's buffer
913 if ((err
= copyout((caddr_t
)&rsp
, buf_addr
,
916 buf_addr
+= sizeof(rsp
);
917 buf_len
-= sizeof(rsp
);
921 * Update the buffer pointer and length
923 aip
->air_buf_addr
= buf_addr
;
924 aip
->air_buf_len
= buf_len
;
931 * Get ARP table information or get/set ARP server address
933 err
= uniarp_ioctl(code
, data
, arg1
);
940 asp
= (struct atmsetreq
*)data
;
941 usp
= (struct unisig
*)arg1
;
943 if (usp
->us_addr
.address_format
!= T_ATM_ABSENT
) {
944 if (KM_CMP(asp
->asr_prf_pref
, usp
->us_addr
.address
,
945 sizeof(asp
->asr_prf_pref
)) != 0)
949 usp
->us_addr
.address_format
= T_ATM_ENDSYS_ADDR
;
950 usp
->us_addr
.address_length
= sizeof(Atm_addr_nsap
);
951 KM_COPY(&pip
->pif_macaddr
,
952 ((Atm_addr_nsap
*)usp
->us_addr
.address
)->aan_esi
,
953 sizeof(pip
->pif_macaddr
));
954 KM_COPY((caddr_t
) asp
->asr_prf_pref
,
955 &((Atm_addr_nsap
*)usp
->us_addr
.address
)->aan_afi
,
956 sizeof(asp
->asr_prf_pref
));
957 log(LOG_INFO
, "uni: set address %s on interface %s\n",
958 unisig_addr_print(&usp
->us_addr
),
962 * Pass event to signalling manager state machine
964 err
= unisig_sigmgr_state(usp
, UNISIG_SIGMGR_ADDR_SET
, NULL
);
967 * Clean up if there was an error
970 usp
->us_addr
.address_format
= T_ATM_ABSENT
;
971 usp
->us_addr
.address_length
= 0;
976 * Inform ARP code of new address
978 uniarp_ifaddr((struct siginst
*)usp
);