summaryrefslogtreecommitdiffstats
path: root/sys/netatm/uni/unisig_sigmgr_state.c
blob: e6a700d5ab5517daebed92b7833569fdb00a3e87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
/*
 *
 * ===================================
 * HARP  |  Host ATM Research Platform
 * ===================================
 *
 *
 * This Host ATM Research Platform ("HARP") file (the "Software") is
 * made available by Network Computing Services, Inc. ("NetworkCS")
 * "AS IS".  NetworkCS does not provide maintenance, improvements or
 * support of any kind.
 *
 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
 * In no event shall NetworkCS be responsible for any damages, including
 * but not limited to consequential damages, arising from or relating to
 * any use of the Software or related support.
 *
 * Copyright 1994-1998 Network Computing Services, Inc.
 *
 * Copies of this Software may be made, however, the above copyright
 * notice must be reproduced on all copies.
 *
 *	@(#) $FreeBSD$
 *
 */

/*
 * ATM Forum UNI 3.0/3.1 Signalling Manager
 * ----------------------------------------
 *
 * Signalling manager finite state machine
 *
 */

#include <netatm/kern_include.h>

#include <netatm/uni/uni.h>
#include <netatm/uni/unisig.h>
#include <netatm/uni/unisig_var.h>

#ifndef lint
__RCSID("@(#) $FreeBSD$");
#endif


/*
 * Local functions
 */
static int	unisig_sigmgr_invalid __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act01 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act02 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act03 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act04 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act05 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act06 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act07 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act08 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act09 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act10 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act11 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act12 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act13 __P((struct unisig *, KBuffer *));
static int	unisig_sigmgr_act14 __P((struct unisig *, KBuffer *));


/*
 * State table.
 */
static int	sigmgr_state_table[10][7] = {
    /*     0   1   2   3   4   5				*/
	{  1,  0,  0,  0,  0 },	/* 0 - Time out		*/
	{  0,  0,  3,  5,  0 },	/* 1 - SSCF estab ind	*/
	{  0,  0,  3,  5,  0 },	/* 2 - SSCF estab cnf	*/
	{  0,  0,  4,  6,  0 },	/* 3 - SSCF release ind	*/
	{  0,  0,  0,  6,  0 },	/* 4 - SSCF release cnf	*/
	{  0,  0,  0,  7,  0 },	/* 5 - SSCF data ind	*/
	{  0,  0,  2,  2,  0 },	/* 6 - SSCF unit data ind */
	{  0,  0,  8,  8,  8 },	/* 7 - Call cleared	*/
	{ 14, 14, 14, 14,  0 },	/* 8 - Detach		*/
	{ 13, 13,  0,  0,  0 }	/* 9 - Address set	*/
};

/*
 * Action vector
 */
#define	MAX_ACTION	15
static int (*unisig_sigmgr_act_vec[MAX_ACTION])
		 __P((struct unisig *, KBuffer *)) = {
	unisig_sigmgr_invalid,
	unisig_sigmgr_act01,
	unisig_sigmgr_act02,
	unisig_sigmgr_act03,
	unisig_sigmgr_act04,
	unisig_sigmgr_act05,
	unisig_sigmgr_act06,
	unisig_sigmgr_act07,
	unisig_sigmgr_act08,
	unisig_sigmgr_act09,
	unisig_sigmgr_act10,
	unisig_sigmgr_act11,
	unisig_sigmgr_act12,
	unisig_sigmgr_act13,
	unisig_sigmgr_act14
};


/*
 * ATM endpoint for UNI signalling channel
 */
static Atm_endpoint	unisig_endpt = {
	NULL,			/* ep_next */
	ENDPT_UNI_SIG,		/* ep_id */
	NULL,			/* ep_ioctl */
	unisig_getname,		/* ep_getname */
	unisig_connected,	/* ep_connected */
	unisig_cleared,		/* ep_cleared */
	NULL,			/* ep_incoming */
	NULL,			/* ep_addparty */
	NULL,			/* ep_dropparty */
	NULL,			/* ep_cpcs_ctl */
	NULL,			/* ep_cpcs_data */
	unisig_saal_ctl,	/* ep_saal_ctl */
	unisig_saal_data,	/* ep_saal_data */
	NULL,			/* ep_sscop_ctl */
	NULL			/* ep_sscop_data */
};


/*
 * ATM connection attributes for UNI signalling channel
 */
static Atm_attributes	unisig_attr = {
	NULL,				/* nif */
	CMAPI_SAAL,			/* api */
	UNI_VERS_3_0,			/* api_init */
	0,				/* headin */
	0,				/* headout */
	{				/* aal */
		T_ATM_PRESENT,		/* aal.tag */
		ATM_AAL5		/* aal.aal_type */
	},
	{				/* traffic */
		T_ATM_PRESENT,		/* traffic.tag */
		{			/* traffic.v */
			{		/* traffic.v.forward */
				T_ATM_ABSENT,	/* PCR_high */
				0,		/* PCR_all */
				T_ATM_ABSENT,	/* SCR_high */
				T_ATM_ABSENT,	/* SCR_all */
				T_ATM_ABSENT,	/* MBS_high */
				T_ATM_ABSENT,	/* MBS_all */
				T_NO,		/* tagging */
			},
			{		/* traffic.v.backward */
				T_ATM_ABSENT,	/* PCR_high */
				0,		/* PCR_all */
				T_ATM_ABSENT,	/* SCR_high */
				T_ATM_ABSENT,	/* SCR_all */
				T_ATM_ABSENT,	/* MBS_high */
				T_ATM_ABSENT,	/* MBS_all */
				T_NO,		/* tagging */
			},
			T_YES,			/* best_effort */
		}
	},
	{				/* bearer */
		T_ATM_PRESENT,		/* bearer.tag */
		{			/* bearer.v */
			T_ATM_CLASS_X,		/* class */
			T_ATM_NULL,		/* traffic_type */
			T_ATM_NO_END_TO_END,	/* timing_req */
			T_NO,			/* clipping */
			T_ATM_1_TO_1,		/* conn_conf */
		}
	},
	{				/* bhli */
		T_ATM_ABSENT,		/* bhli.tag */
	},
	{				/* blli */
		T_ATM_ABSENT,		/* blli.tag_l2 */
		T_ATM_ABSENT,		/* blli.tag_l3 */
	},
	{				/* llc */
		T_ATM_ABSENT,		/* llc.tag */
	},
	{				/* called */
		T_ATM_PRESENT,		/* called.tag */
	},
	{				/* calling */
		T_ATM_ABSENT,		/* calling.tag */
	},
	{				/* qos */
		T_ATM_PRESENT,		/* qos.tag */
		{			/* qos.v */
			T_ATM_NETWORK_CODING,	/* coding_standard */
			{			/* qos.v.forward */
				T_ATM_QOS_CLASS_0,	/* class */
			},
			{			/* qos.v.backward */
				T_ATM_QOS_CLASS_0,	/* class */
			}
		}
	},
	{				/* transit */
		T_ATM_ABSENT,		/* transit.tag */
	},
	{				/* cause */
		T_ATM_ABSENT,		/* cause.tag */
	}
};


/*
 * Finite state machine for the UNISIG signalling manager
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	event	indication of the event to be processed
 *	m	pointer to a buffer with a message (optional)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
int
unisig_sigmgr_state(usp, event, m)
	struct unisig	*usp;
	int		event;
	KBuffer		*m;
{
	int		action, err = 0;

	/*
	 * Cancel any signalling manager timer
	 */
	UNISIG_CANCEL(usp);

	/*
	 * Select an action based on the incoming event and
	 * the signalling manager's state
	 */
	action = sigmgr_state_table[event][usp->us_state];
	ATM_DEBUG4("unisig_sigmgr_state: usp=%p, state=%d, event=%d, action=%d\n",
			usp, usp->us_state, event, action);
	if (action >= MAX_ACTION || action < 0) {
		panic("unisig_sigmgr_state: invalid action\n");
	}

	/*
	 * Perform the requested action
	 */
	err = unisig_sigmgr_act_vec[action](usp, m);

	return(err);
}


/*
 * Signalling manager state machine action 0
 *
 * Invalid action
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_invalid(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	log(LOG_ERR, "unisig_sigmgr_state: unexpected action\n");
	if (m)
		KB_FREEALL(m);
	return(0);
}


/*
 * Signalling manager state machine action 1
 *
 * The kickoff timer has expired at attach time; go to
 * UNISIG_ADDR_WAIT state.
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act01(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	/*
	 * Set the new state
	 */
	usp->us_state = UNISIG_ADDR_WAIT;

	return(0);
}


/*
 * Signalling manager state machine action 2
 *
 * Ignore the event
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act02(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	/*
	 * Ignore event, discard message if present
	 */
	if (m)
		KB_FREEALL(m);

	return(0);
}


/*
 * Signalling manager state machine action 3
 *
 * SSCF session on signalling channel has come up
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act03(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	struct unisig_vccb	*uvp, *vnext;

	/*
	 * Log the activation
	 */
	log(LOG_INFO, "unisig: signalling channel active\n");

	/*
	 * Go to ACTIVE state
	 */
	usp->us_state = UNISIG_ACTIVE;

	/*
	 * Notify the VC state machine that the channel is up
	 */
	for (uvp = Q_HEAD(usp->us_vccq, struct unisig_vccb);
			uvp; uvp = vnext) {
		vnext = Q_NEXT(uvp, struct unisig_vccb, uv_sigelem);
		(void) unisig_vc_state(usp, uvp, UNI_VC_SAAL_ESTAB,
				(struct unisig_msg *) 0);
	}

	return(0);
}


/*
 * Signalling manager state machine action 4
 *
 * A SSCF release indication was received.  Try to establish an
 * SSCF session on the signalling PVC.
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act04(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	int		err;

	/*
	 * Try to establish an SSCF session.
	 */
	err = atm_cm_saal_ctl(SSCF_UNI_ESTABLISH_REQ,
			usp->us_conn,
			(void *)0);
	if (err)
		panic("unisig_sigmgr_act04: SSCF_UNI_ESTABLISH_REQ");

	return(0);
}


/*
 * Signalling manager state machine action 5
 *
 * SSCF session on signalling channel has been reset
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act05(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	struct unisig_vccb	*uvp, *vnext;

	/*
	 * Log the reset
	 */
	log(LOG_INFO, "unisig: signalling channel reset\n");

	/*
	 * Notify the VC state machine of the reset
	 */
	for (uvp = Q_HEAD(usp->us_vccq, struct unisig_vccb);
			uvp; uvp = vnext) {
		vnext = Q_NEXT(uvp, struct unisig_vccb, uv_sigelem);
		(void) unisig_vc_state(usp, uvp, UNI_VC_SAAL_ESTAB,
				(struct unisig_msg *) 0);
	}

	return(0);
}


/*
 * Signalling manager state machine action 6
 *
 * SSCF session on signalling channel has been lost
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act06(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	struct unisig_vccb	*uvp, *vnext;

	/*
	 * Log the fact that the session has been lost
	 */
	log(LOG_INFO, "unisig: signalling channel SSCF session lost\n");

	/*
	 * Notify the VC state machine of the loss
	 */
	for (uvp = Q_HEAD(usp->us_vccq, struct unisig_vccb);
			uvp; uvp = vnext) {
		vnext = Q_NEXT(uvp, struct unisig_vccb, uv_sigelem);
		(void) unisig_vc_state(usp, uvp, UNI_VC_SAAL_FAIL,
				(struct unisig_msg *) 0);
	}

	/*
	 * Try to restart the SSCF session
	 */
	(void) unisig_sigmgr_act04(usp, (KBuffer *) 0);

	/*
	 * Go to INIT state
	 */
	usp->us_state = UNISIG_INIT;

	return(0);
}


/*
 * Signalling manager state machine action 7
 *
 * A Q.2931 signalling message has been received
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act07(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	int	err;

	/*
	 * Pass the Q.2931 signalling message on
	 * to the VC state machine
	 */
	err = unisig_rcv_msg(usp, m);

	return(err);
}


/*
 * Signalling manager state machine action 8
 *
 * Process a CALL_CLOSED event for the signalling PVC
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act08(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{

	/*
	 * Signalling manager is now incommunicado
	 */
	if (usp->us_state != UNISIG_DETACH) {
		/*
		 * Log an error and set the state to NULL if
		 * we're not detaching
		 */
		log(LOG_ERR, "unisig: signalling channel closed\n");
		usp->us_state = UNISIG_NULL;
	}
	usp->us_conn = 0;

	return(0);
}


/*
 * Signalling manager state machine action 9
 *
 * Not used
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act09(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	log(LOG_ERR, "unisig_sigmgr_act09: unexpected action\n");
	if (m)
		KB_FREEALL(m);
	return (0);
}


/*
 * Signalling manager state machine action 10
 *
 * Not used
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act10(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	return(0);
}


/*
 * Signalling manager state machine action 11
 *
 * Not used
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act11(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	log(LOG_ERR, "unisig_sigmgr_act11: unexpected action\n");
	if (m)
		KB_FREEALL(m);
	return(0);
}


/*
 * Signalling manager state machine action 12
 *
 * Not used
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act12(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	log(LOG_ERR, "unisig_sigmgr_act11: unexpected action\n");
	if (m)
		KB_FREEALL(m);
	return(0);
}


/*
 * Signalling manager state machine action 13
 *
 * NSAP prefix has been set
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act13(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	int		err;
	Atm_addr_pvc	*pvcp;

	/*
	 * Set UNI signalling channel connection attributes
	 */
	if (usp->us_proto == ATM_SIG_UNI30)
		unisig_attr.api_init = UNI_VERS_3_0;
	else
		unisig_attr.api_init = UNI_VERS_3_1;

	unisig_attr.nif = usp->us_pif->pif_nif;

	unisig_attr.aal.v.aal5.forward_max_SDU_size = ATM_NIF_MTU;
	unisig_attr.aal.v.aal5.backward_max_SDU_size = ATM_NIF_MTU;
	unisig_attr.aal.v.aal5.SSCS_type = T_ATM_SSCS_SSCOP_REL;

	unisig_attr.called.tag = T_ATM_PRESENT;
	unisig_attr.called.addr.address_format = T_ATM_PVC_ADDR;
	unisig_attr.called.addr.address_length = sizeof(Atm_addr_pvc);
	pvcp = (Atm_addr_pvc *)unisig_attr.called.addr.address;
	ATM_PVC_SET_VPI(pvcp, UNISIG_SIG_VPI);
	ATM_PVC_SET_VCI(pvcp, UNISIG_SIG_VCI);
	unisig_attr.called.subaddr.address_format = T_ATM_ABSENT;
	unisig_attr.called.subaddr.address_length = 0;

	unisig_attr.traffic.v.forward.PCR_all_traffic =
			usp->us_pif->pif_pcr;
	unisig_attr.traffic.v.backward.PCR_all_traffic =
			usp->us_pif->pif_pcr;

	/*
	 * Create UNISIG signalling channel
	 */
	err = atm_cm_connect(&unisig_endpt, usp, &unisig_attr,
			&usp->us_conn);
	if (err) {
		return(err);
	}

	/*
	 * Establish the SSCF session
	 */
	err = atm_cm_saal_ctl(SSCF_UNI_ESTABLISH_REQ,
			usp->us_conn,
			(void *)0);
	if (err)
		panic("unisig_sigmgr_act13: SSCF_UNI_ESTABLISH_REQ");

	/*
	 * Set the new state
	 */
	usp->us_state = UNISIG_INIT;

	return(0);
}


/*
 * Signalling manager state machine action 14
 *
 * Process a detach event
 *
 * Arguments:
 *	usp	pointer to the UNISIG protocol control block
 *	m	buffer pointer (may be NULL)
 *
 * Returns:
 *	0	success
 *	errno	error encountered
 *
 */
static int
unisig_sigmgr_act14(usp, m)
	struct unisig	*usp;
	KBuffer		*m;
{
	int			err;
	struct unisig_vccb	*sig_vccb, *uvp, *vnext;
	struct atm_pif		*pip;
	struct t_atm_cause	cause;

	/*
	 * Locate the signalling channel's VCCB
	 */
	sig_vccb = (struct unisig_vccb *)0;
	if (usp->us_conn && usp->us_conn->co_connvc)
		sig_vccb = (struct unisig_vccb *)
				usp->us_conn->co_connvc->cvc_vcc;

	/*
	 * Terminate all of our VCCs
	 */
	for (uvp = Q_HEAD(usp->us_vccq, struct unisig_vccb);
			uvp; uvp = vnext) {
		vnext = Q_NEXT(uvp, struct unisig_vccb, uv_sigelem);

		/*
		 * Don't close the signalling VCC yet
		 */
		if (uvp == sig_vccb)
			continue;

		/*
		 * Close VCC and notify owner
		 */
		err = unisig_clear_vcc(usp, uvp,
				T_ATM_CAUSE_NORMAL_CALL_CLEARING);
	}

	/*
	 * Close the signalling channel
	 */
	if (usp->us_conn) {
		cause.coding_standard = T_ATM_ITU_CODING;
		cause.coding_standard = T_ATM_LOC_USER;
		cause.coding_standard = T_ATM_CAUSE_UNSPECIFIED_NORMAL;
		err = atm_cm_release(usp->us_conn, &cause);
		if (err)
			panic("unisig_sigmgr_act14: close failed\n");
	}

	/*
	 * Get rid of protocol instance if there are no VCCs queued
	 */
	pip = usp->us_pif;
	if (Q_HEAD(usp->us_vccq, struct vccb) == NULL &&
			pip->pif_sigmgr) {
		struct sigmgr	*smp = pip->pif_sigmgr;
		int		s = splimp();

		pip->pif_sigmgr = NULL;
		pip->pif_siginst = NULL;
		(void) splx(s);

		UNLINK((struct siginst *)usp, struct siginst,
				smp->sm_prinst, si_next);
		KM_FREE(usp, sizeof(struct unisig), M_DEVBUF);
	} else {
		/*
		 * Otherwise, set new signalling manager state and
		 * wait for protocol instance to be freed during 
		 * unisig_free processing for the last queued VCC
		 */
		usp->us_state = UNISIG_DETACH;
	}

	return (0);
}
OpenPOWER on IntegriCloud