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.6 2004/04/22 05:09:46 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 (void) atm_sigmgr_deregister(&unisig_mgr30);
201 (void) 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 at splnet.
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(smp, pip)
243 struct unisig *usp = NULL;
245 ATM_DEBUG2("unisig_attach: smp=%p, pip=%p\n", smp, pip);
248 * Allocate UNISIG protocol instance control block
250 usp = KM_ALLOC(sizeof(struct unisig), M_DEVBUF, M_INTWAIT | M_NULLOK);
255 KM_ZERO(usp, sizeof(struct unisig));
258 * Set state in UNISIG protocol instance control block
260 usp->us_state = UNISIG_NULL;
261 usp->us_proto = smp->sm_proto;
264 * Set initial call reference allocation value
269 * Link instance into manager's chain
271 LINK2TAIL((struct siginst *)usp, struct siginst, smp->sm_prinst,
279 pip->pif_sigmgr = smp;
280 pip->pif_siginst = (struct siginst *) usp;
284 * Clear our ATM address. The address will be set by user
285 * command or by registration via ILMI.
287 usp->us_addr.address_format = T_ATM_ABSENT;
288 usp->us_addr.address_length = 0;
289 usp->us_subaddr.address_format = T_ATM_ABSENT;
290 usp->us_subaddr.address_length = 0;
295 usp->us_ipserv = &uniip_ipserv;
298 * Kick-start the UNISIG protocol
300 UNISIG_TIMER(usp, 0);
303 * Log the fact that we've attached
305 log(LOG_INFO, "unisig: attached to interface %s%d\n",
306 pip->pif_name, pip->pif_unit);
310 * Reset our work if attach fails
315 UNLINK((struct siginst *)usp, struct siginst,
316 smp->sm_prinst, si_next);
317 KM_FREE(usp, sizeof(struct unisig), M_DEVBUF);
320 pip->pif_sigmgr = NULL;
321 pip->pif_siginst = NULL;
330 * Detach a UNISIG-controlled interface
332 * Each ATM physical interface may be detached from its signalling
333 * manager (via the atm_sigmgr_detach function). This function will
334 * handle the detachment for all UNISIG-controlled interfaces. All
335 * circuits will be immediately terminated.
337 * Function must be called at splnet.
340 * pip pointer to ATM physical interface control block
343 * 0 detach successful
344 * errno detach failed - reason indicated
354 ATM_DEBUG1("unisig_detach: pip=%p\n", pip);
357 * Get UNISIG protocol instance
359 usp = (struct unisig *)pip->pif_siginst;
362 * Return an error if we're already detaching
364 if (usp->us_state == UNISIG_DETACH) {
369 * Pass the detach event to the signalling manager
372 err = unisig_sigmgr_state(usp, UNISIG_SIGMGR_DETACH,
376 * Log the fact that we've detached
379 log(LOG_INFO, "unisig: detached from interface %s%d\n",
380 pip->pif_name, pip->pif_unit);
387 * Open a UNISIG ATM Connection
389 * All service user requests to open a VC connection (via
390 * atm_open_connection) over an ATM interface attached to the UNISIG
391 * signalling manager are handled here.
393 * Function will be called at splnet.
396 * cvp pointer to user's requested connection parameters
397 * errp pointer to an int for extended error information
400 * CALL_PROCEEDING connection establishment is in progress
401 * CALL_FAILED connection establishment failed
402 * CALL_CONNECTED connection has been successfully established
406 unisig_setup(cvp, errp)
410 struct atm_pif *pip = cvp->cvc_attr.nif->nif_pif;
411 struct unisig *usp = (struct unisig *)pip->pif_siginst;
414 ATM_DEBUG1("unisig_setup: cvp=%p\n", cvp);
417 * Intialize the returned error code
422 * Open the connection
424 switch (cvp->cvc_attr.called.addr.address_format) {
429 *errp = unisig_open_vcc(usp, cvp);
430 rc = (*errp ? CALL_FAILED : CALL_CONNECTED);
433 case T_ATM_ENDSYS_ADDR:
434 case T_ATM_E164_ADDR:
439 *errp = unisig_open_vcc(usp, cvp);
440 rc = (*errp ? CALL_FAILED : CALL_PROCEEDING);
444 *errp = EPROTONOSUPPORT;
453 * Close a UNISIG ATM Connection
455 * All service user requests to terminate a previously open VC
456 * connection (via the atm_close_connection function), which is running
457 * over an interface attached to the UNISIG signalling manager, are
460 * Function will be called at splnet.
463 * vcp pointer to connection's VC control block
464 * errp pointer to an int for extended error information
467 * CALL_PROCEEDING connection termination is in progress
468 * CALL_FAILED connection termination failed
469 * CALL_CLEARED connection has been successfully terminated
473 unisig_release(vcp, errp)
478 struct atm_pif *pip = vcp->vc_pif;
479 struct unisig *usp = (struct unisig *)pip->pif_siginst;
481 ATM_DEBUG1("unisig_release: vcp=%p\n", vcp);
484 * Initialize returned error code
489 * Validate the connection type (PVC or SVC)
491 if (!(vcp->vc_type & (VCC_PVC | VCC_SVC))) {
492 *errp = EPROTONOSUPPORT;
499 *errp = unisig_close_vcc(usp, (struct unisig_vccb *)vcp);
502 * Set the return code
506 } else if (vcp->vc_sstate == UNI_NULL ||
507 vcp->vc_sstate == UNI_FREE) {
510 rc = CALL_PROCEEDING;
518 * Accept a UNISIG Open from a remote host
520 * A user calls this routine (via the atm_accept_call function)
521 * after it is notified that an open request was received for it.
523 * Function will be called at splnet.
526 * vcp pointer to user's VCCB
527 * errp pointer to an int for extended error information
530 * CALL_PROCEEDING connection establishment is in progress
531 * CALL_FAILED connection establishment failed
532 * CALL_CONNECTED connection has been successfully established
536 unisig_accept(vcp, errp)
540 struct unisig_vccb *uvp = (struct unisig_vccb *)vcp;
541 struct atm_pif *pip = uvp->uv_pif;
542 struct unisig *usp = (struct unisig *)pip->pif_siginst;
544 ATM_DEBUG1("unisig_accept: vcp=%p\n", vcp);
547 * Initialize the returned error code
552 * Return an error if we're detaching
554 if (usp->us_state == UNISIG_DETACH) {
560 * Return an error if we lost the connection
562 if (uvp->uv_sstate == UNI_FREE) {
568 * Pass the acceptance to the VC state machine
570 *errp = unisig_vc_state(usp, uvp, UNI_VC_ACCEPT_CALL,
571 (struct unisig_msg *) 0);
575 return(CALL_PROCEEDING);
579 * On error, free the VCCB and return CALL_FAILED
583 uvp->uv_sstate = UNI_FREE;
584 uvp->uv_ustate = VCCU_CLOSED;
585 DEQUEUE(uvp, struct unisig_vccb, uv_sigelem, usp->us_vccq);
586 unisig_free((struct vccb *)uvp);
593 * Reject a UNISIG Open from a remote host
595 * A user calls this routine (via the atm_reject_call function)
596 * after it is notified that an open request was received for it.
598 * Function will be called at splnet.
601 * uvp pointer to user's VCCB
602 * errp pointer to an int for extended error information
605 * CALL_CLEARED call request rejected
606 * CALL_FAILED call rejection failed
610 unisig_reject(vcp, errp)
614 struct unisig_vccb *uvp = (struct unisig_vccb *)vcp;
615 struct atm_pif *pip = uvp->uv_pif;
616 struct unisig *usp = (struct unisig *)pip->pif_siginst;
618 ATM_DEBUG1("unisig_reject: uvp=%p\n", uvp);
621 * Initialize the returned error code
627 * Return an error if we're detaching
629 if (usp->us_state == UNISIG_DETACH) {
635 * Call the VC state machine
637 *errp = unisig_vc_state(usp, uvp, UNI_VC_REJECT_CALL,
638 (struct unisig_msg *) 0);
642 return(CALL_CLEARED);
646 * On error, free the VCCB and return CALL_FAILED
648 uvp->uv_sstate = UNI_FREE;
649 uvp->uv_ustate = VCCU_CLOSED;
650 DEQUEUE(uvp, struct unisig_vccb, uv_sigelem, usp->us_vccq);
651 (void) unisig_free((struct vccb *)uvp);
657 * Abort a UNISIG ATM Connection
659 * All (non-user) requests to abort a previously open VC connection (via
660 * the atm_abort_connection function), which is running over an
661 * interface attached to the UNISIG signalling manager, are handled here.
662 * The VCC owner will be notified of the request, in order to initiate
663 * termination of the connection.
665 * Function will be called at splnet.
668 * vcp pointer to connection's VC control block
671 * 0 connection release was successful
672 * errno connection release failed - reason indicated
680 ATM_DEBUG1("unisig_abort: vcp=%p\n", vcp);
685 if (vcp->vc_ustate == VCCU_ABORT) {
690 * Cancel any timer that might be running
692 UNISIG_VC_CANCEL(vcp);
695 * Set immediate timer to schedule connection termination
697 vcp->vc_ustate = VCCU_ABORT;
698 UNISIG_VC_TIMER(vcp, 0);
705 * Free UNISIG ATM connection resources
707 * All service user requests to free the resources of a closed VCC
708 * connection (via the atm_free_connection function), which is running
709 * over an interface attached to the UNISIG signalling manager, are
712 * Function will be called at splnet.
715 * vcp pointer to connection's VC control block
718 * 0 connection free was successful
719 * errno connection free failed - reason indicated
726 struct atm_pif *pip = vcp->vc_pif;
727 struct unisig *usp = (struct unisig *)pip->pif_siginst;
729 ATM_DEBUG1("unisig_free: vcp = %p\n", vcp);
732 * Make sure VCC has been closed
734 if ((vcp->vc_ustate != VCCU_CLOSED &&
735 vcp->vc_ustate != VCCU_ABORT) ||
736 vcp->vc_sstate != UNI_FREE) {
737 ATM_DEBUG2("unisig_free: bad state, sstate=%d, ustate=%d\n",
738 vcp->vc_sstate, vcp->vc_ustate);
743 * Remove VCCB from protocol queue
745 DEQUEUE(vcp, struct vccb, vc_sigelem, usp->us_vccq);
750 vcp->vc_ustate = VCCU_NULL;
751 vcp->vc_sstate = UNI_NULL;
752 atm_free((caddr_t)vcp);
755 * If we're detaching and this was the last VCC queued,
756 * get rid of the protocol instance
758 if ((usp->us_state == UNISIG_DETACH) &&
759 (Q_HEAD(usp->us_vccq, struct vccb) == NULL)) {
760 struct sigmgr *smp = pip->pif_sigmgr;
763 pip->pif_sigmgr = NULL;
764 pip->pif_siginst = NULL;
767 UNLINK((struct siginst *)usp, struct siginst,
768 smp->sm_prinst, si_next);
769 KM_FREE(usp, sizeof(struct unisig), M_DEVBUF);
777 * UNISIG IOCTL support
779 * Function will be called at splnet.
782 * code PF_ATM sub-operation code
783 * data pointer to code specific parameter data area
784 * arg1 pointer to code specific argument
788 * errno error processing request - reason indicated
792 unisig_ioctl(code, data, arg1)
797 struct atmdelreq *adp;
798 struct atminfreq *aip;
799 struct atmsetreq *asp;
801 struct unisig_vccb *uvp;
802 struct air_vcc_rsp rsp;
806 int err = 0, buf_len, i;
809 ATM_DEBUG1("unisig_ioctl: code=%d\n", code);
818 adp = (struct atmdelreq *)data;
819 usp = (struct unisig *)arg1;
822 * Don't let a user close the UNISIG signalling VC
824 vpi = adp->adr_pvc_vpi;
825 vci = adp->adr_pvc_vci;
826 if ((vpi == UNISIG_SIG_VPI && vci == UNISIG_SIG_VCI))
832 for (uvp = Q_HEAD(usp->us_vccq, struct unisig_vccb); uvp;
833 uvp = Q_NEXT(uvp, struct unisig_vccb, uv_sigelem)) {
834 if ((uvp->uv_vpi == vpi) && (uvp->uv_vci == vci))
845 if (!(uvp->uv_type & VCC_PVC)) {
850 if (!(uvp->uv_type & VCC_SVC)) {
857 * Schedule VCC termination
859 unisig_cause_attr_from_user(&uvp->uv_connvc->cvc_attr,
860 T_ATM_CAUSE_UNSPECIFIED_NORMAL);
861 err = unisig_abort((struct vccb *)uvp);
866 * Return VCC information
868 aip = (struct atminfreq *)data;
869 usp = (struct unisig *)arg1;
871 buf_addr = aip->air_buf_addr;
872 buf_len = aip->air_buf_len;
875 * Loop through the VCC queue
877 for (uvp = Q_HEAD(usp->us_vccq, struct unisig_vccb); uvp;
878 uvp = Q_NEXT(uvp, struct unisig_vccb, uv_sigelem)) {
880 * Make sure there's room in the user's buffer
882 if (buf_len < sizeof(rsp)) {
888 * Fill out the response struct for the VCC
890 (void) snprintf(rsp.avp_intf,
891 sizeof(rsp.avp_intf), "%s%d",
892 usp->us_pif->pif_name,
893 usp->us_pif->pif_unit);
894 rsp.avp_vpi = uvp->uv_vpi;
895 rsp.avp_vci = uvp->uv_vci;
896 rsp.avp_type = uvp->uv_type;
897 rsp.avp_aal = uvp->uv_connvc->cvc_attr.aal.type;
898 rsp.avp_sig_proto = uvp->uv_proto;
899 cop = uvp->uv_connvc->cvc_conn;
901 rsp.avp_encaps = cop->co_mpx;
904 rsp.avp_state = uvp->uv_sstate;
905 if (uvp->uv_connvc->cvc_flags & CVCF_CALLER) {
906 rsp.avp_daddr = uvp->uv_connvc->cvc_attr.called.addr;
908 rsp.avp_daddr = uvp->uv_connvc->cvc_attr.calling.addr;
910 rsp.avp_dsubaddr.address_format = T_ATM_ABSENT;
911 rsp.avp_dsubaddr.address_length = 0;
912 rsp.avp_ipdus = uvp->uv_ipdus;
913 rsp.avp_opdus = uvp->uv_opdus;
914 rsp.avp_ibytes = uvp->uv_ibytes;
915 rsp.avp_obytes = uvp->uv_obytes;
916 rsp.avp_ierrors = uvp->uv_ierrors;
917 rsp.avp_oerrors = uvp->uv_oerrors;
918 rsp.avp_tstamp = uvp->uv_tstamp;
919 KM_ZERO(rsp.avp_owners,
920 sizeof(rsp.avp_owners));
921 for (i = 0; cop && i < sizeof(rsp.avp_owners);
923 i += T_ATM_APP_NAME_LEN+1) {
924 strncpy(&rsp.avp_owners[i],
925 cop->co_endpt->ep_getname(cop->co_toku),
930 * Copy the response into the user's buffer
932 if ((err = copyout((caddr_t)&rsp, buf_addr,
935 buf_addr += sizeof(rsp);
936 buf_len -= sizeof(rsp);
940 * Update the buffer pointer and length
942 aip->air_buf_addr = buf_addr;
943 aip->air_buf_len = buf_len;
950 * Get ARP table information or get/set ARP server address
952 err = uniarp_ioctl(code, data, arg1);
959 asp = (struct atmsetreq *)data;
960 usp = (struct unisig *)arg1;
962 if (usp->us_addr.address_format != T_ATM_ABSENT) {
963 if (KM_CMP(asp->asr_prf_pref, usp->us_addr.address,
964 sizeof(asp->asr_prf_pref)) != 0)
968 usp->us_addr.address_format = T_ATM_ENDSYS_ADDR;
969 usp->us_addr.address_length = sizeof(Atm_addr_nsap);
970 KM_COPY(&pip->pif_macaddr,
971 ((Atm_addr_nsap *)usp->us_addr.address)->aan_esi,
972 sizeof(pip->pif_macaddr));
973 KM_COPY((caddr_t) asp->asr_prf_pref,
974 &((Atm_addr_nsap *)usp->us_addr.address)->aan_afi,
975 sizeof(asp->asr_prf_pref));
976 log(LOG_INFO, "uni: set address %s on interface %s\n",
977 unisig_addr_print(&usp->us_addr),
981 * Pass event to signalling manager state machine
983 err = unisig_sigmgr_state(usp, UNISIG_SIGMGR_ADDR_SET,
987 * Clean up if there was an error
990 usp->us_addr.address_format = T_ATM_ABSENT;
991 usp->us_addr.address_length = 0;
996 * Inform ARP code of new address
998 uniarp_ifaddr((struct siginst *)usp);