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
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
|
/*
* ===================================
* 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.
*/
/*
* Core ATM Services
* -----------------
*
* ATM Connection Manager
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/syslog.h>
#include <net/if.h>
#include <net/bpf.h>
#include <netatm/port.h>
#include <netatm/queue.h>
#include <netatm/atm.h>
#include <netatm/atm_sys.h>
#include <netatm/atm_sap.h>
#include <netatm/atm_cm.h>
#include <netatm/atm_if.h>
#include <netatm/atm_vc.h>
#include <netatm/atm_sigmgr.h>
#include <netatm/atm_stack.h>
#include <netatm/atm_pcb.h>
#include <netatm/atm_var.h>
/*
* Global variables
*/
struct atm_cm_stat atm_cm_stat = {0};
/*
* Local functions
*/
static void atm_cm_cpcs_upper(int, void *, intptr_t, intptr_t);
static void atm_cm_saal_upper(int, void *, intptr_t, intptr_t);
static void atm_cm_sscop_upper(int, void *, intptr_t, intptr_t);
static Atm_connvc * atm_cm_share_llc(Atm_attributes *);
static void atm_cm_closeconn(Atm_connection *,
struct t_atm_cause *);
static void atm_cm_closevc(Atm_connvc *);
static void atm_cm_timeout(struct atm_time *);
static KTimeout_ret atm_cm_procinq(void *);
static void atm_cm_incall(Atm_connvc *);
static int atm_cm_accept(Atm_connvc *, Atm_connection *);
/*
* Local variables
*/
static Queue_t atm_connection_queue = {NULL};
static Queue_t atm_incoming_queue = {NULL};
static int atm_incoming_qlen = 0;
static Atm_connection *atm_listen_queue = NULL;
static struct attr_cause atm_cause_tmpl =
{T_ATM_PRESENT, {T_ATM_ITU_CODING, T_ATM_LOC_USER, 0, {0, 0, 0, 0}}};
/*
* Stack commands, indexed by API
*/
static struct {
int init;
int term;
} atm_stackcmds[] = {
{CPCS_INIT, CPCS_TERM}, /* CMAPI_CPCS */
{SSCF_UNI_INIT, SSCF_UNI_TERM}, /* CMAPI_SAAL */
{SSCOP_INIT, SSCOP_TERM}, /* CMAPI_SSCOP */
};
static uma_zone_t atm_connection_zone;
static uma_zone_t atm_connvc_zone;
void
atm_cm_init(void)
{
atm_connection_zone = uma_zcreate("atm connection",
sizeof(Atm_connection), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
if (atm_connection_zone == NULL)
panic("atm_connection_zone");
atm_connvc_zone = uma_zcreate("atm connvc", sizeof(Atm_connvc), NULL,
NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
if (atm_connvc_zone == NULL)
panic("atm_connvc_zone");
}
/*
* Initiate Outgoing ATM Call
*
* Called by an endpoint service to create a new Connection Manager API
* instance and to initiate an outbound ATM connection. The endpoint
* provided token will be used in all further CM -> endpoint function
* calls, and the returned connection block pointer must be used in all
* subsequent endpoint -> CM function calls.
*
* If the return indicates that the connection setup has been immediately
* successful (typically only for PVCs and shared SVCs), then the connection
* is ready for data transmission.
*
* If the return indicates that the connection setup is still in progress,
* then the endpoint must wait for notification from the Connection Manager
* indicating the final status of the call setup. If the call setup completes
* successfully, then a "call connected" notification will be sent to the
* endpoint by the Connection Manager. If the call setup fails, then the
* endpoint will receive a "call cleared" notification.
*
* All connection instances must be freed with an atm_cm_release() call.
*
* Arguments:
* epp pointer to endpoint definition structure
* token endpoint's connection instance token
* ap pointer to requested connection attributes
* copp pointer to location to return allocated connection block
*
* Returns:
* 0 connection has been successfully established
* EINPROGRESS connection establishment is in progress
* errno connection failed - reason indicated
*
*/
int
atm_cm_connect(epp, token, ap, copp)
Atm_endpoint *epp;
void *token;
Atm_attributes *ap;
Atm_connection **copp;
{
Atm_connection *cop;
Atm_connvc *cvp;
struct atm_pif *pip;
struct sigmgr *smp;
struct stack_list sl;
void (*upf)(int, void *, intptr_t, intptr_t);
int s, sli, err, err2;
*copp = NULL;
cvp = NULL;
/*
* Get a connection block
* May be called from timeout - don't wait.
*/
cop = uma_zalloc(atm_connection_zone, M_NOWAIT);
if (cop == NULL)
return (ENOMEM);
/*
* Initialize connection info
*/
cop->co_endpt = epp;
cop->co_toku = token;
/*
* Initialize stack list index
*/
sli = 0;
/*
* Validate and extract useful attribute information
*/
/*
* Must specify a network interface (validated below)
*/
if (ap->nif == NULL) {
err = EINVAL;
goto done;
}
/*
* Check out Data API
*/
switch (ap->api) {
case CMAPI_CPCS:
upf = atm_cm_cpcs_upper;
break;
case CMAPI_SAAL:
sl.sl_sap[sli++] = SAP_SSCF_UNI;
sl.sl_sap[sli++] = SAP_SSCOP;
upf = atm_cm_saal_upper;
break;
case CMAPI_SSCOP:
sl.sl_sap[sli++] = SAP_SSCOP;
upf = atm_cm_sscop_upper;
break;
default:
err = EINVAL;
goto done;
}
/*
* AAL Attributes
*/
if (ap->aal.tag != T_ATM_PRESENT) {
err = EINVAL;
goto done;
}
switch (ap->aal.type) {
case ATM_AAL5:
sl.sl_sap[sli++] = SAP_CPCS_AAL5;
sl.sl_sap[sli++] = SAP_SAR_AAL5;
sl.sl_sap[sli++] = SAP_ATM;
break;
case ATM_AAL3_4:
sl.sl_sap[sli++] = SAP_CPCS_AAL3_4;
sl.sl_sap[sli++] = SAP_SAR_AAL3_4;
sl.sl_sap[sli++] = SAP_ATM;
break;
default:
err = EINVAL;
goto done;
}
/*
* Broadband Bearer Attributes
*/
if (ap->bearer.tag != T_ATM_PRESENT) {
err = EINVAL;
goto done;
}
switch (ap->bearer.v.connection_configuration) {
case T_ATM_1_TO_1:
cop->co_flags |= COF_P2P;
break;
case T_ATM_1_TO_MANY:
/* Not supported */
cop->co_flags |= COF_P2MP;
err = EINVAL;
goto done;
default:
err = EINVAL;
goto done;
}
/*
* Logical Link Control Attributes
*/
if (ap->llc.tag == T_ATM_PRESENT) {
if ((ap->blli.tag_l2 != T_ATM_PRESENT) ||
(ap->blli.v.layer_2_protocol.ID_type != T_ATM_SIMPLE_ID) ||
(ap->blli.v.layer_2_protocol.ID.simple_ID !=
T_ATM_BLLI2_I8802) ||
(ap->llc.v.llc_len < T_ATM_LLC_MIN_LEN) ||
(ap->llc.v.llc_len > T_ATM_LLC_MAX_LEN)) {
err = EINVAL;
goto done;
}
cop->co_mpx = ATM_ENC_LLC;
cop->co_llc = ap->llc;
} else
cop->co_mpx = ATM_ENC_NULL;
/*
* Called Party Attributes
*/
if (ap->called.tag != T_ATM_PRESENT) {
err = EINVAL;
goto done;
}
if ((ap->called.addr.address_format == T_ATM_ABSENT) ||
(ap->called.addr.address_length == 0)) {
err = EINVAL;
goto done;
}
/*
* Calling Party Attributes
*/
if (ap->calling.tag != T_ATM_ABSENT) {
err = EINVAL;
goto done;
}
/*
* Quality of Service Attributes
*/
if (ap->qos.tag != T_ATM_PRESENT) {
err = EINVAL;
goto done;
}
/*
* Terminate stack list
*/
sl.sl_sap[sli] = 0;
s = splnet();
/*
* Let multiplexors decide whether we need a new VCC
*/
switch (cop->co_mpx) {
case ATM_ENC_NULL:
/*
* All of these connections require a new VCC
*/
break;
case ATM_ENC_LLC:
/*
* See if we can share an existing LLC connection
*/
cvp = atm_cm_share_llc(ap);
if (cvp == NULL)
break;
/*
* We've got a connection to share
*/
cop->co_connvc = cvp;
if (cvp->cvc_state == CVCS_ACTIVE) {
cop->co_state = COS_ACTIVE;
err = 0;
} else {
cop->co_state = COS_OUTCONN;
err = EINPROGRESS;
}
LINK2TAIL(cop, Atm_connection, cvp->cvc_conn->co_mxh, co_next);
cop->co_mxh = cvp->cvc_conn->co_mxh;
*copp = cop;
(void) splx(s);
return (err);
default:
panic("atm_cm_connect: unknown mpx");
}
/*
* If we get here, it means we need to create
* a new VCC for this connection
*/
/*
* Validate that network interface is registered and that
* a signalling manager is attached
*/
for (pip = atm_interface_head; pip != NULL; pip = pip->pif_next) {
struct atm_nif *nip;
for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
if (nip == ap->nif)
break;
}
if (nip)
break;
}
if (pip == NULL) {
err = ENXIO;
goto donex;
}
if ((smp = pip->pif_sigmgr) == NULL) {
err = ENXIO;
goto donex;
}
/*
* Get a connection VCC block
* May be called from timeouts - don't wait.
*/
cvp = uma_zalloc(atm_connvc_zone, M_NOWAIT);
if (cvp == NULL) {
err = ENOMEM;
goto donex;
}
/*
* Save VCC attributes
*/
cvp->cvc_attr = *ap;
cvp->cvc_flags |= CVCF_CALLER;
/*
* Link the control blocks
*/
cop->co_connvc = cvp;
cvp->cvc_conn = cop;
cvp->cvc_sigmgr = smp;
/*
* Create a service stack
*/
err = atm_create_stack(cvp, &sl, upf);
if (err) {
cvp->cvc_state = CVCS_CLEAR;
atm_cm_closevc(cvp);
goto donex;
}
/*
* Let the signalling manager handle the VCC creation
*/
cvp->cvc_state = CVCS_SETUP;
switch ((*smp->sm_setup)(cvp, &err)) {
case CALL_CONNECTED:
/*
* Connection is fully setup - initialize the stack
*/
cvp->cvc_state = CVCS_INIT;
STACK_CALL(atm_stackcmds[ap->api].init, cvp->cvc_lower,
cvp->cvc_tokl, cvp, ap->api_init, 0, err2);
if (err2)
panic("atm_cm_connect: init");
if (cvp->cvc_flags & CVCF_ABORTING) {
/*
* Someone on the stack bailed out...schedule the
* VCC and stack termination
*/
atm_cm_closevc(cvp);
err = EFAULT;
} else {
/*
* Everything looks fine from here
*/
cvp->cvc_state = CVCS_ACTIVE;
cop->co_state = COS_ACTIVE;
}
break;
case CALL_FAILED:
/*
* Terminate stack and clean up before we leave
*/
cvp->cvc_state = CVCS_CLEAR;
atm_cm_closevc(cvp);
break;
case CALL_PROCEEDING:
/*
* We'll just wait for final call status
*/
cop->co_state = COS_OUTCONN;
err = EINPROGRESS;
break;
default:
panic("atm_cm_connect: setup");
}
donex:
(void) splx(s);
done:
if (err && err != EINPROGRESS) {
/*
* Undo any partial setup stuff
*/
if (cop)
uma_zfree(atm_connection_zone, cop);
} else {
/*
* Finish connection setup
*/
s = splnet();
cvp->cvc_flags |= CVCF_CONNQ;
ENQUEUE(cvp, Atm_connvc, cvc_q, atm_connection_queue);
LINK2TAIL(cop, Atm_connection, cop->co_mxh, co_next);
(void) splx(s);
*copp = cop;
}
return (err);
}
/*
* Listen for Incoming ATM Calls
*
* Called by an endpoint service in order to indicate its willingness to
* accept certain incoming calls. The types of calls which the endpoint
* is prepared to accept are specified in the Atm_attributes parameter.
*
* For each call which meets the criteria specified by the endpoint, the
* endpoint service will receive an incoming call notification via the
* endpoint's ep_incoming() function.
*
* To cancel the listening connection, the endpoint user should invoke
* atm_cm_release().
*
* Arguments:
* epp pointer to endpoint definition structure
* token endpoint's listen instance token
* ap pointer to listening connection attributes
* copp pointer to location to return allocated connection block
*
* Returns:
* 0 listening connection installed
* errno listen failed - reason indicated
*
*/
int
atm_cm_listen(epp, token, ap, copp)
Atm_endpoint *epp;
void *token;
Atm_attributes *ap;
Atm_connection **copp;
{
Atm_connection *cop;
int s, err = 0;
*copp = NULL;
/*
* Get a connection block
*/
cop = uma_zalloc(atm_connection_zone, M_WAITOK);
if (cop == NULL)
return (ENOMEM);
/*
* Initialize connection info
*/
cop->co_endpt = epp;
cop->co_toku = token;
cop->co_mxh = cop;
/*
* Validate and extract useful attribute information
*/
/*
* Check out Data API
*/
switch (ap->api) {
case CMAPI_CPCS:
case CMAPI_SAAL:
case CMAPI_SSCOP:
break;
default:
err = EINVAL;
goto done;
}
/*
* AAL Attributes
*/
switch (ap->aal.tag) {
case T_ATM_PRESENT:
switch (ap->aal.type) {
case ATM_AAL5:
case ATM_AAL3_4:
break;
default:
err = EINVAL;
goto done;
}
break;
case T_ATM_ABSENT:
case T_ATM_ANY:
break;
default:
err = EINVAL;
goto done;
}
/*
* Broadband High Layer Information Attributes
*/
switch (ap->bhli.tag) {
case T_ATM_PRESENT:
case T_ATM_ABSENT:
case T_ATM_ANY:
break;
default:
err = EINVAL;
goto done;
}
/*
* Broadband Low Layer Information Attributes
*/
switch (ap->blli.tag_l2) {
case T_ATM_PRESENT:
case T_ATM_ABSENT:
case T_ATM_ANY:
break;
default:
err = EINVAL;
goto done;
}
switch (ap->blli.tag_l3) {
case T_ATM_PRESENT:
case T_ATM_ABSENT:
case T_ATM_ANY:
break;
default:
err = EINVAL;
goto done;
}
/*
* Logical Link Control Attributes
*/
switch (ap->llc.tag) {
case T_ATM_PRESENT:
if ((ap->blli.tag_l2 != T_ATM_PRESENT) ||
(ap->blli.v.layer_2_protocol.ID_type != T_ATM_SIMPLE_ID) ||
(ap->blli.v.layer_2_protocol.ID.simple_ID !=
T_ATM_BLLI2_I8802) ||
(ap->llc.v.llc_len < T_ATM_LLC_MIN_LEN) ||
(ap->llc.v.llc_len > T_ATM_LLC_MAX_LEN)) {
err = EINVAL;
goto done;
}
cop->co_mpx = ATM_ENC_LLC;
cop->co_llc = ap->llc;
break;
case T_ATM_ABSENT:
case T_ATM_ANY:
cop->co_mpx = ATM_ENC_NULL;
break;
default:
err = EINVAL;
goto done;
}
/*
* Called Party Attributes
*/
switch (ap->called.tag) {
case T_ATM_PRESENT:
switch (ap->called.addr.address_format) {
case T_ATM_ABSENT:
ap->called.tag = T_ATM_ABSENT;
break;
case T_ATM_PVC_ADDR:
err = EINVAL;
goto done;
}
break;
case T_ATM_ABSENT:
case T_ATM_ANY:
break;
default:
err = EINVAL;
goto done;
}
/*
* Get an attribute block and save listening attributes
*/
cop->co_lattr = uma_zalloc(atm_attributes_zone, M_WAITOK | M_ZERO);
if (cop->co_lattr == NULL) {
err = ENOMEM;
goto done;
}
*cop->co_lattr = *ap;
/*
* Now try to register the listening connection
*/
s = splnet();
if (atm_cm_match(cop->co_lattr, NULL) != NULL) {
/*
* Can't have matching listeners
*/
err = EADDRINUSE;
goto donex;
}
cop->co_state = COS_LISTEN;
LINK2TAIL(cop, Atm_connection, atm_listen_queue, co_next);
donex:
(void) splx(s);
done:
if (err) {
/*
* Undo any partial setup stuff
*/
if (cop) {
if (cop->co_lattr)
uma_zfree(atm_attributes_zone, cop->co_lattr);
uma_zfree(atm_connection_zone, cop);
}
} else {
/*
* Finish connection setup
*/
*copp = cop;
}
return (err);
}
/*
* Add to LLC Connection
*
* Called by an endpoint service to create a new Connection Manager API
* instance to be associated with an LLC-multiplexed connection instance
* which has been previously created. The endpoint provided token will
* be used in all further CM -> endpoint function calls, and the returned
* connection block pointer must be used in all subsequent endpoint -> CM
* function calls.
*
* If the return indicates that the connection setup has been immediately
* successful, then the connection is ready for data transmission.
*
* If the return indicates that the connection setup is still in progress,
* then the endpoint must wait for notification from the Connection Manager
* indicating the final status of the call setup. If the call setup completes
* successfully, then a "call connected" notification will be sent to the
* endpoint by the Connection Manager. If the call setup fails, then the
* endpoint will receive a "call cleared" notification.
*
* All connection instances must be freed with an atm_cm_release() call.
*
* Arguments:
* epp pointer to endpoint definition structure
* token endpoint's connection instance token
* llc pointer to llc attributes for new connection
* ecop pointer to existing connection block
* copp pointer to location to return allocated connection block
*
* Returns:
* 0 connection has been successfully established
* EINPROGRESS connection establishment is in progress
* errno addllc failed - reason indicated
*
*/
int
atm_cm_addllc(epp, token, llc, ecop, copp)
Atm_endpoint *epp;
void *token;
struct attr_llc *llc;
Atm_connection *ecop;
Atm_connection **copp;
{
Atm_connection *cop, *cop2;
Atm_connvc *cvp;
int s, err;
*copp = NULL;
/*
* Check out requested LLC attributes
*/
if ((llc->tag != T_ATM_PRESENT) ||
((llc->v.flags & T_ATM_LLC_SHARING) == 0) ||
(llc->v.llc_len < T_ATM_LLC_MIN_LEN) ||
(llc->v.llc_len > T_ATM_LLC_MAX_LEN))
return (EINVAL);
/*
* Get a connection block
* May be called from netisr - don't wait.
*/
cop = uma_zalloc(atm_connection_zone, M_NOWAIT);
if (cop == NULL)
return (ENOMEM);
/*
* Initialize connection info
*/
cop->co_endpt = epp;
cop->co_toku = token;
cop->co_llc = *llc;
s = splnet();
/*
* Ensure that supplied connection is really valid
*/
cop2 = NULL;
for (cvp = Q_HEAD(atm_connection_queue, Atm_connvc); cvp;
cvp = Q_NEXT(cvp, Atm_connvc, cvc_q)) {
for (cop2 = cvp->cvc_conn; cop2; cop2 = cop2->co_next) {
if (ecop == cop2)
break;
}
if (cop2)
break;
}
if (cop2 == NULL) {
err = ENOENT;
goto done;
}
switch (ecop->co_state) {
case COS_OUTCONN:
case COS_INACCEPT:
err = EINPROGRESS;
break;
case COS_ACTIVE:
err = 0;
break;
default:
err = EINVAL;
goto done;
}
/*
* Connection must be LLC multiplexed and shared
*/
if ((ecop->co_mpx != ATM_ENC_LLC) ||
((ecop->co_llc.v.flags & T_ATM_LLC_SHARING) == 0)) {
err = EINVAL;
goto done;
}
/*
* This new LLC header must be unique for this VCC
*/
cop2 = ecop->co_mxh;
while (cop2) {
int i = MIN(llc->v.llc_len, cop2->co_llc.v.llc_len);
if (bcmp(llc->v.llc_info, cop2->co_llc.v.llc_info, i) == 0) {
err = EINVAL;
goto done;
}
cop2 = cop2->co_next;
}
/*
* Everything seems to check out
*/
cop->co_flags = ecop->co_flags;
cop->co_state = ecop->co_state;
cop->co_mpx = ecop->co_mpx;
cop->co_connvc = ecop->co_connvc;
LINK2TAIL(cop, Atm_connection, ecop->co_mxh, co_next);
cop->co_mxh = ecop->co_mxh;
done:
(void) splx(s);
if (err && err != EINPROGRESS) {
/*
* Undo any partial setup stuff
*/
if (cop)
uma_zfree(atm_connection_zone, cop);
} else {
/*
* Pass new connection back to caller
*/
*copp = cop;
}
return (err);
}
/*
* XXX
*
* Arguments:
* cop pointer to connection block
* id identifier for party to be added
* addr address of party to be added
*
* Returns:
* 0 addparty successful
* errno addparty failed - reason indicated
*
*/
int
atm_cm_addparty(cop, id, addr)
Atm_connection *cop;
int id;
struct t_atm_sap *addr;
{
return (0);
}
/*
* XXX
*
* Arguments:
* cop pointer to connection block
* id identifier for party to be added
* cause pointer to cause of drop
*
* Returns:
* 0 dropparty successful
* errno dropparty failed - reason indicated
*
*/
int
atm_cm_dropparty(cop, id, cause)
Atm_connection *cop;
int id;
struct t_atm_cause *cause;
{
return (0);
}
/*
* Release Connection Resources
*
* Called by the endpoint service in order to terminate an ATM connection
* and to release all system resources for the connection. This function
* must be called for every allocated connection instance and must only
* be called by the connection's owner.
*
* Arguments:
* cop pointer to connection block
* cause pointer to cause of release
*
* Returns:
* 0 release successful
* errno release failed - reason indicated
*
*/
int
atm_cm_release(cop, cause)
Atm_connection *cop;
struct t_atm_cause *cause;
{
Atm_connvc *cvp;
int s;
s = splnet();
/*
* First, a quick state validation check
*/
switch (cop->co_state) {
case COS_OUTCONN:
case COS_LISTEN:
case COS_INACCEPT:
case COS_ACTIVE:
case COS_CLEAR:
/*
* Break link to user
*/
cop->co_toku = NULL;
break;
case COS_INCONN:
(void) splx(s);
return (EFAULT);
default:
panic("atm_cm_release: bogus conn state");
}
/*
* Check out the VCC state too
*/
if ((cvp = cop->co_connvc) != NULL) {
switch (cvp->cvc_state) {
case CVCS_SETUP:
case CVCS_INIT:
case CVCS_ACCEPT:
case CVCS_ACTIVE:
break;
case CVCS_INCOMING:
(void) splx(s);
return (EFAULT);
case CVCS_CLEAR:
(void) splx(s);
return (EALREADY);
default:
panic("atm_cm_release: bogus connvc state");
}
/*
* If we're the only connection, terminate the VCC
*/
if ((cop->co_mxh == cop) && (cop->co_next == NULL)) {
cvp->cvc_attr.cause.tag = T_ATM_PRESENT;
cvp->cvc_attr.cause.v = *cause;
atm_cm_closevc(cvp);
}
}
/*
* Now get rid of the connection
*/
atm_cm_closeconn(cop, cause);
return (0);
}
/*
* Abort an ATM Connection VCC
*
* This function allows any non-owner kernel entity to request an
* immediate termination of an ATM VCC. This will normally be called
* when encountering a catastrophic error condition that cannot be
* resolved via the available stack protocols. The connection manager
* will schedule the connection's termination, including notifying the
* connection owner of the termination.
*
* This function should only be called by a stack entity instance. After
* calling the function, the caller should set a protocol state which just
* waits for a <sap>_TERM stack command to be delivered.
*
* Arguments:
* cvp pointer to connection VCC block
* cause pointer to cause of abort
*
* Returns:
* 0 abort successful
* errno abort failed - reason indicated
*
*/
int
atm_cm_abort(cvp, cause)
Atm_connvc *cvp;
struct t_atm_cause *cause;
{
ATM_DEBUG2("atm_cm_abort: cvp=%p cause=%d\n",
cvp, cause->cause_value);
/*
* Note that we're aborting
*/
cvp->cvc_flags |= CVCF_ABORTING;
switch (cvp->cvc_state) {
case CVCS_INIT:
/*
* In-line code will handle this
*/
cvp->cvc_attr.cause.tag = T_ATM_PRESENT;
cvp->cvc_attr.cause.v = *cause;
break;
case CVCS_SETUP:
case CVCS_ACCEPT:
case CVCS_ACTIVE:
/*
* Schedule connection termination, since we want
* to avoid any sequencing interactions
*/
cvp->cvc_attr.cause.tag = T_ATM_PRESENT;
cvp->cvc_attr.cause.v = *cause;
CVC_TIMER(cvp, 0);
break;
case CVCS_REJECT:
case CVCS_RELEASE:
case CVCS_CLEAR:
case CVCS_TERM:
/*
* Ignore abort, as we're already terminating
*/
break;
default:
log(LOG_ERR,
"atm_cm_abort: invalid state: cvp=%p, state=%d\n",
cvp, cvp->cvc_state);
}
return (0);
}
/*
* Incoming ATM Call Received
*
* Called by a signalling manager to indicate that a new call request has
* been received. This function will allocate and initialize the connection
* manager control blocks and queue this call request. The call request
* processing function, atm_cm_procinq(), will be scheduled to perform the
* call processing.
*
* Arguments:
* vcp pointer to incoming call's VCC control block
* ap pointer to incoming call's attributes
*
* Returns:
* 0 call queuing successful
* errno call queuing failed - reason indicated
*
*/
int
atm_cm_incoming(vcp, ap)
struct vccb *vcp;
Atm_attributes *ap;
{
Atm_connvc *cvp;
int s, err;
/*
* Do some minimal attribute validation
*/
/*
* Must specify a network interface
*/
if (ap->nif == NULL)
return (EINVAL);
/*
* AAL Attributes
*/
if ((ap->aal.tag != T_ATM_PRESENT) ||
((ap->aal.type != ATM_AAL5) &&
(ap->aal.type != ATM_AAL3_4)))
return (EINVAL);
/*
* Traffic Descriptor Attributes
*/
if ((ap->traffic.tag != T_ATM_PRESENT) &&
(ap->traffic.tag != T_ATM_ABSENT))
return (EINVAL);
/*
* Broadband Bearer Attributes
*/
if ((ap->bearer.tag != T_ATM_PRESENT) ||
((ap->bearer.v.connection_configuration != T_ATM_1_TO_1) &&
(ap->bearer.v.connection_configuration != T_ATM_1_TO_MANY)))
return (EINVAL);
/*
* Broadband High Layer Attributes
*/
if ((ap->bhli.tag != T_ATM_PRESENT) &&
(ap->bhli.tag != T_ATM_ABSENT))
return (EINVAL);
/*
* Broadband Low Layer Attributes
*/
if ((ap->blli.tag_l2 != T_ATM_PRESENT) &&
(ap->blli.tag_l2 != T_ATM_ABSENT))
return (EINVAL);
if ((ap->blli.tag_l3 != T_ATM_PRESENT) &&
(ap->blli.tag_l3 != T_ATM_ABSENT))
return (EINVAL);
/*
* Logical Link Control Attributes
*/
if (ap->llc.tag == T_ATM_PRESENT)
return (EINVAL);
ap->llc.tag = T_ATM_ANY;
/*
* Called Party Attributes
*/
if ((ap->called.tag != T_ATM_PRESENT) ||
(ap->called.addr.address_format == T_ATM_ABSENT))
return (EINVAL);
if (ap->called.tag == T_ATM_ABSENT) {
ap->called.addr.address_format = T_ATM_ABSENT;
ap->called.addr.address_length = 0;
ap->called.subaddr.address_format = T_ATM_ABSENT;
ap->called.subaddr.address_length = 0;
}
/*
* Calling Party Attributes
*/
if ((ap->calling.tag != T_ATM_PRESENT) &&
(ap->calling.tag != T_ATM_ABSENT))
return (EINVAL);
if (ap->calling.tag == T_ATM_ABSENT) {
ap->calling.addr.address_format = T_ATM_ABSENT;
ap->calling.addr.address_length = 0;
ap->calling.subaddr.address_format = T_ATM_ABSENT;
ap->calling.subaddr.address_length = 0;
}
/*
* Quality of Service Attributes
*/
if (ap->qos.tag != T_ATM_PRESENT)
return (EINVAL);
/*
* Transit Network Attributes
*/
if ((ap->transit.tag != T_ATM_PRESENT) &&
(ap->transit.tag != T_ATM_ABSENT))
return (EINVAL);
/*
* Cause Attributes
*/
if ((ap->cause.tag != T_ATM_PRESENT) &&
(ap->cause.tag != T_ATM_ABSENT))
return (EINVAL);
/*
* Get a connection VCC block
* May be called from netisr - don't wait.
*/
cvp = uma_zalloc(atm_connvc_zone, M_NOWAIT);
if (cvp == NULL) {
err = ENOMEM;
goto fail;
}
/*
* Initialize the control block
*/
cvp->cvc_vcc = vcp;
cvp->cvc_sigmgr = vcp->vc_pif->pif_sigmgr;
cvp->cvc_attr = *ap;
cvp->cvc_state = CVCS_INCOMING;
/*
* Control queue length
*/
s = splnet();
if (atm_incoming_qlen >= ATM_CALLQ_MAX) {
(void) splx(s);
err = EBUSY;
goto fail;
}
/*
* Queue request and schedule call processing function
*/
cvp->cvc_flags |= CVCF_INCOMQ;
ENQUEUE(cvp, Atm_connvc, cvc_q, atm_incoming_queue);
if (atm_incoming_qlen++ == 0) {
timeout(atm_cm_procinq, (void *)0, 0);
}
/*
* Link for signalling manager
*/
vcp->vc_connvc = cvp;
(void) splx(s);
return (0);
fail:
/*
* Free any resources
*/
if (cvp)
uma_zfree(atm_connvc_zone, cvp);
return (err);
}
/*
* VCC Connected Notification
*
* This function is called by a signalling manager as notification that a
* VCC call setup has been successful.
*
* Arguments:
* cvp pointer to connection VCC block
*
* Returns:
* none
*
*/
void
atm_cm_connected(cvp)
Atm_connvc *cvp;
{
Atm_connection *cop, *cop2;
KBuffer *m;
int s, err;
s = splnet();
/*
* Validate connection vcc
*/
switch (cvp->cvc_state) {
case CVCS_SETUP:
/*
* Initialize the stack
*/
cvp->cvc_state = CVCS_INIT;
STACK_CALL(atm_stackcmds[cvp->cvc_attr.api].init,
cvp->cvc_lower, cvp->cvc_tokl,
cvp, cvp->cvc_attr.api_init, 0, err);
if (err)
panic("atm_cm_connected: init");
if (cvp->cvc_flags & CVCF_ABORTING) {
/*
* Someone on the stack bailed out...notify all of the
* connections and schedule the VCC termination
*/
cop = cvp->cvc_conn;
while (cop) {
cop2 = cop->co_next;
atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
cop = cop2;
}
atm_cm_closevc(cvp);
(void) splx(s);
return;
}
break;
case CVCS_ACCEPT:
/*
* Stack already initialized
*/
break;
default:
panic("atm_cm_connected: connvc state");
}
/*
* VCC is ready for action
*/
cvp->cvc_state = CVCS_ACTIVE;
/*
* Notify all connections that the call has completed
*/
cop = cvp->cvc_conn;
while (cop) {
cop2 = cop->co_next;
switch (cop->co_state) {
case COS_OUTCONN:
case COS_INACCEPT:
cop->co_state = COS_ACTIVE;
(*cop->co_endpt->ep_connected)(cop->co_toku);
break;
case COS_ACTIVE:
/*
* May get here if an ep_connected() call (from
* above) results in an atm_cm_addllc() call for
* the just connected connection.
*/
break;
default:
panic("atm_cm_connected: connection state");
}
cop = cop2;
}
(void) splx(s);
/*
* Input any queued packets
*/
while ((m = cvp->cvc_rcvq) != NULL) {
cvp->cvc_rcvq = KB_QNEXT(m);
cvp->cvc_rcvqlen--;
KB_QNEXT(m) = NULL;
/*
* Currently only supported for CPCS API
*/
atm_cm_cpcs_upper(CPCS_UNITDATA_SIG, cvp, (intptr_t)m, 0);
}
return;
}
/*
* VCC Cleared Notification
*
* This function is called by a signalling manager as notification that a
* VCC call has been cleared. The cause information describing the reason
* for the call clearing will be contained in the connection VCC attributes.
*
* Arguments:
* cvp pointer to connection VCC block
*
* Returns:
* none
*
*/
void
atm_cm_cleared(cvp)
Atm_connvc *cvp;
{
Atm_connection *cop, *cop2;
int s;
KASSERT((cvp->cvc_state != CVCS_FREE) && (cvp->cvc_state < CVCS_CLEAR),
("atm_cm_cleared: state sanity check failed"));
cvp->cvc_state = CVCS_CLEAR;
s = splnet();
/*
* Terminate all connections
*/
cop = cvp->cvc_conn;
while (cop) {
cop2 = cop->co_next;
atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
cop = cop2;
}
/*
* Clean up connection VCC
*/
atm_cm_closevc(cvp);
(void) splx(s);
return;
}
/*
* Process Incoming Call Queue
*
* This function is scheduled by atm_cm_incoming() in order to process
* all the entries on the incoming call queue.
*
* Arguments:
* arg argument passed on timeout() call
*
* Returns:
* none
*
*/
static KTimeout_ret
atm_cm_procinq(arg)
void *arg;
{
Atm_connvc *cvp;
int cnt = 0, s;
/*
* Only process incoming calls up to our quota
*/
while (cnt++ < ATM_CALLQ_MAX) {
s = splnet();
/*
* Get next awaiting call
*/
cvp = Q_HEAD(atm_incoming_queue, Atm_connvc);
if (cvp == NULL) {
(void) splx(s);
break;
}
DEQUEUE(cvp, Atm_connvc, cvc_q, atm_incoming_queue);
atm_incoming_qlen--;
cvp->cvc_flags &= ~CVCF_INCOMQ;
/*
* Handle the call
*/
atm_cm_incall(cvp);
(void) splx(s);
}
/*
* If we've expended our quota, reschedule ourselves
*/
if (cnt >= ATM_CALLQ_MAX)
timeout(atm_cm_procinq, (void *)0, 0);
}
/*
* Process Incoming Call
*
* This function will search through the listening queue and try to find
* matching endpoint(s) for the incoming call. If we find any, we will
* notify the endpoint service(s) of the incoming call and will then
* notify the signalling manager to progress the call to an active status.
*
* If there are no listeners for the call, the signalling manager will be
* notified of a call rejection.
*
* Called at splnet.
*
* Arguments:
* cvp pointer to connection VCC for incoming call
*
* Returns:
* none
*
*/
static void
atm_cm_incall(cvp)
Atm_connvc *cvp;
{
Atm_connection *cop, *lcop, *hcop;
Atm_attributes attr;
int err;
hcop = NULL;
lcop = NULL;
cop = NULL;
attr = cvp->cvc_attr;
/*
* Look for matching listeners
*/
while ((lcop = atm_cm_match(&attr, lcop)) != NULL) {
if (cop == NULL) {
/*
* Need a new connection block
* May be called from timeout - dont wait.
*/
cop = uma_zalloc(atm_connection_zone, M_NOWAIT);
if (cop == NULL) {
cvp->cvc_attr.cause = atm_cause_tmpl;
cvp->cvc_attr.cause.v.cause_value =
T_ATM_CAUSE_TEMPORARY_FAILURE;
goto fail;
}
}
/*
* Initialize connection from listener and incoming call
*/
cop->co_mxh = NULL;
cop->co_state = COS_INCONN;
cop->co_mpx = lcop->co_mpx;
cop->co_endpt = lcop->co_endpt;
cop->co_llc = lcop->co_llc;
switch (attr.bearer.v.connection_configuration) {
case T_ATM_1_TO_1:
cop->co_flags |= COF_P2P;
break;
case T_ATM_1_TO_MANY:
/* Not supported */
cop->co_flags |= COF_P2MP;
cvp->cvc_attr.cause = atm_cause_tmpl;
cvp->cvc_attr.cause.v.cause_value =
T_ATM_CAUSE_BEARER_CAPABILITY_NOT_IMPLEMENTED;
goto fail;
}
/*
* Notify endpoint of incoming call
*/
err = (*cop->co_endpt->ep_incoming)
(lcop->co_toku, cop, &cvp->cvc_attr, &cop->co_toku);
if (err == 0) {
/*
* Endpoint has accepted the call
*
* Setup call attributes
*/
if (hcop == NULL) {
cvp->cvc_attr.api = lcop->co_lattr->api;
cvp->cvc_attr.api_init =
lcop->co_lattr->api_init;
cvp->cvc_attr.llc = lcop->co_lattr->llc;
}
cvp->cvc_attr.headin = MAX(cvp->cvc_attr.headin,
lcop->co_lattr->headin);
/*
* Setup connection info and queueing
*/
cop->co_state = COS_INACCEPT;
cop->co_connvc = cvp;
LINK2TAIL(cop, Atm_connection, hcop, co_next);
cop->co_mxh = hcop;
/*
* Need a new connection block next time around
*/
cop = NULL;
} else {
/*
* Endpoint refuses call
*/
goto fail;
}
}
/*
* We're done looking for listeners
*/
if (hcop) {
/*
* Someone actually wants the call, so notify
* the signalling manager to continue
*/
cvp->cvc_flags |= CVCF_CONNQ;
ENQUEUE(cvp, Atm_connvc, cvc_q, atm_connection_queue);
if (atm_cm_accept(cvp, hcop))
goto fail;
} else {
/*
* Nobody around to take the call
*/
cvp->cvc_attr.cause = atm_cause_tmpl;
cvp->cvc_attr.cause.v.cause_value =
T_ATM_CAUSE_INCOMPATIBLE_DESTINATION;
goto fail;
}
/*
* Clean up loose ends
*/
if (cop)
uma_zfree(atm_connection_zone, cop);
/*
* Call has been accepted
*/
return;
fail:
/*
* Call failed - notify any endpoints of the call failure
*/
/*
* Clean up loose ends
*/
if (cop)
uma_zfree(atm_connection_zone, cop);
if (cvp->cvc_attr.cause.tag != T_ATM_PRESENT) {
cvp->cvc_attr.cause = atm_cause_tmpl;
cvp->cvc_attr.cause.v.cause_value =
T_ATM_CAUSE_UNSPECIFIED_NORMAL;
}
cop = hcop;
while (cop) {
Atm_connection *cop2 = cop->co_next;
atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
cop = cop2;
}
/*
* Tell the signalling manager to reject the call
*/
atm_cm_closevc(cvp);
return;
}
/*
* Accept an Incoming ATM Call
*
* Some endpoint service(s) wants to accept an incoming call, so the
* signalling manager will be notified to attempt to progress the call
* to an active status.
*
* If the signalling manager indicates that connection activation has
* been immediately successful, then all of the endpoints will be notified
* that the connection is ready for data transmission.
*
* If the return indicates that connection activation is still in progress,
* then the endpoints must wait for notification from the Connection Manager
* indicating the final status of the call setup. If the call setup completes
* successfully, then a "call connected" notification will be sent to the
* endpoints by the Connection Manager. If the call setup fails, then the
* endpoints will receive a "call cleared" notification.
*
* Called at splnet.
*
* Arguments:
* cvp pointer to connection VCC for incoming call
* cop pointer to head of accepted connections
*
* Returns:
* 0 connection has been successfully activated
* errno accept failed - reason indicated
*
*/
static int
atm_cm_accept(cvp, cop)
Atm_connvc *cvp;
Atm_connection *cop;
{
struct stack_list sl;
void (*upf)(int, void *, intptr_t, intptr_t);
int sli, err, err2;
/*
* Link vcc to connections
*/
cvp->cvc_conn = cop;
/*
* Initialize stack list index
*/
sli = 0;
/*
* Check out Data API
*/
switch (cvp->cvc_attr.api) {
case CMAPI_CPCS:
upf = atm_cm_cpcs_upper;
break;
case CMAPI_SAAL:
sl.sl_sap[sli++] = SAP_SSCF_UNI;
sl.sl_sap[sli++] = SAP_SSCOP;
upf = atm_cm_saal_upper;
break;
case CMAPI_SSCOP:
sl.sl_sap[sli++] = SAP_SSCOP;
upf = atm_cm_sscop_upper;
break;
default:
upf = NULL;
}
/*
* AAL Attributes
*/
switch (cvp->cvc_attr.aal.type) {
case ATM_AAL5:
sl.sl_sap[sli++] = SAP_CPCS_AAL5;
sl.sl_sap[sli++] = SAP_SAR_AAL5;
sl.sl_sap[sli++] = SAP_ATM;
break;
case ATM_AAL3_4:
sl.sl_sap[sli++] = SAP_CPCS_AAL3_4;
sl.sl_sap[sli++] = SAP_SAR_AAL3_4;
sl.sl_sap[sli++] = SAP_ATM;
break;
}
/*
* Terminate stack list
*/
sl.sl_sap[sli] = 0;
/*
* Create a service stack
*/
err = atm_create_stack(cvp, &sl, upf);
if (err) {
goto done;
}
/*
* Let the signalling manager finish the VCC activation
*/
switch ((*cvp->cvc_sigmgr->sm_accept)(cvp->cvc_vcc, &err)) {
case CALL_PROCEEDING:
/*
* Note that we're not finished yet
*/
err = EINPROGRESS;
/* FALLTHRU */
case CALL_CONNECTED:
/*
* Initialize the stack now, even if the call isn't totally
* active yet. We want to avoid the delay between getting
* the "call connected" event and actually notifying the
* adapter to accept cells on the new VCC - if the delay is
* too long, then we end up dropping the first pdus sent by
* the caller.
*/
cvp->cvc_state = CVCS_INIT;
STACK_CALL(atm_stackcmds[cvp->cvc_attr.api].init,
cvp->cvc_lower, cvp->cvc_tokl, cvp,
cvp->cvc_attr.api_init, 0, err2);
if (err2)
panic("atm_cm_accept: init");
if (cvp->cvc_flags & CVCF_ABORTING) {
/*
* Someone on the stack bailed out...schedule the
* VCC and stack termination
*/
err = ECONNABORTED;
} else {
/*
* Everything looks fine from here
*/
if (err)
cvp->cvc_state = CVCS_ACCEPT;
else
cvp->cvc_state = CVCS_ACTIVE;
}
break;
case CALL_FAILED:
/*
* Terminate stack and clean up before we leave
*/
cvp->cvc_state = CVCS_CLEAR;
break;
default:
panic("atm_cm_accept: accept");
}
done:
if (err == 0) {
/*
* Call has been connected, notify endpoints
*/
while (cop) {
Atm_connection *cop2 = cop->co_next;
cop->co_state = COS_ACTIVE;
(*cop->co_endpt->ep_connected)(cop->co_toku);
cop = cop2;
}
} else if (err == EINPROGRESS) {
/*
* Call is still in progress, endpoint must wait
*/
err = 0;
} else {
/*
* Let caller know we failed
*/
cvp->cvc_attr.cause = atm_cause_tmpl;
cvp->cvc_attr.cause.v.cause_value =
T_ATM_CAUSE_UNSPECIFIED_RESOURCE_UNAVAILABLE;
}
return (err);
}
/*
* Match Attributes on Listening Queue
*
* This function will attempt to match the supplied connection attributes
* with one of the registered attributes in the listening queue. The pcop
* argument may be supplied in order to allow multiple listeners to share
* an incoming call (if supported by the listeners).
*
* Called at splnet.
*
* Arguments:
* ap pointer to attributes to be matched
* pcop pointer to the previously matched connection
*
* Returns:
* addr connection with which a match was found
* 0 no match found
*
*/
Atm_connection *
atm_cm_match(ap, pcop)
Atm_attributes *ap;
Atm_connection *pcop;
{
Atm_connection *cop;
Atm_attributes *lap;
/*
* If we've already matched a listener...
*/
if (pcop) {
/*
* Make sure already matched listener supports sharing
*/
if ((pcop->co_mpx != ATM_ENC_LLC) ||
((pcop->co_llc.v.flags & T_ATM_LLC_SHARING) == 0))
return (NULL);
/*
* Position ourselves after the matched entry
*/
for (cop = atm_listen_queue; cop; cop = cop->co_next) {
if (cop == pcop) {
cop = pcop->co_next;
break;
}
}
} else {
/*
* Start search at top of listening queue
*/
cop = atm_listen_queue;
}
/*
* Search through listening queue
*/
for (; cop; cop = cop->co_next) {
lap = cop->co_lattr;
/*
* If we're trying to share, check that this entry allows it
*/
if (pcop) {
if ((cop->co_mpx != ATM_ENC_LLC) ||
((cop->co_llc.v.flags & T_ATM_LLC_SHARING) == 0))
continue;
}
/*
* ALL "matchable" attributes must match
*/
/*
* BHLI
*/
if (lap->bhli.tag == T_ATM_ABSENT) {
if (ap->bhli.tag == T_ATM_PRESENT)
continue;
} else if (lap->bhli.tag == T_ATM_PRESENT) {
if (ap->bhli.tag == T_ATM_ABSENT)
continue;
if (ap->bhli.tag == T_ATM_PRESENT)
if (bcmp(&lap->bhli.v, &ap->bhli.v,
sizeof(struct t_atm_bhli)))
continue;
}
/*
* BLLI Layer 2
*/
if (lap->blli.tag_l2 == T_ATM_ABSENT) {
if (ap->blli.tag_l2 == T_ATM_PRESENT)
continue;
} else if (lap->blli.tag_l2 == T_ATM_PRESENT) {
if (ap->blli.tag_l2 == T_ATM_ABSENT)
continue;
if (ap->blli.tag_l2 == T_ATM_PRESENT) {
if (bcmp(&lap->blli.v.layer_2_protocol.ID,
&ap->blli.v.layer_2_protocol.ID,
sizeof(
ap->blli.v.layer_2_protocol.ID)))
continue;
}
}
/*
* BLLI Layer 3
*/
if (lap->blli.tag_l3 == T_ATM_ABSENT) {
if (ap->blli.tag_l3 == T_ATM_PRESENT)
continue;
} else if (lap->blli.tag_l3 == T_ATM_PRESENT) {
if (ap->blli.tag_l3 == T_ATM_ABSENT)
continue;
if (ap->blli.tag_l3 == T_ATM_PRESENT) {
if (bcmp(&lap->blli.v.layer_3_protocol.ID,
&ap->blli.v.layer_3_protocol.ID,
sizeof(
ap->blli.v.layer_3_protocol.ID)))
continue;
}
}
/*
* LLC
*/
if (lap->llc.tag == T_ATM_ABSENT) {
if (ap->llc.tag == T_ATM_PRESENT)
continue;
} else if (lap->llc.tag == T_ATM_PRESENT) {
if (ap->llc.tag == T_ATM_ABSENT)
continue;
if (ap->llc.tag == T_ATM_PRESENT) {
int i = MIN(lap->llc.v.llc_len,
ap->llc.v.llc_len);
if (bcmp(lap->llc.v.llc_info,
ap->llc.v.llc_info, i))
continue;
}
}
/*
* AAL
*/
if (lap->aal.tag == T_ATM_ABSENT) {
if (ap->aal.tag == T_ATM_PRESENT)
continue;
} else if (lap->aal.tag == T_ATM_PRESENT) {
if (ap->aal.tag == T_ATM_ABSENT)
continue;
if (ap->aal.tag == T_ATM_PRESENT) {
if (lap->aal.type != ap->aal.type)
continue;
if (lap->aal.type == ATM_AAL5) {
if (lap->aal.v.aal5.SSCS_type !=
ap->aal.v.aal5.SSCS_type)
continue;
} else {
if (lap->aal.v.aal4.SSCS_type !=
ap->aal.v.aal4.SSCS_type)
continue;
}
}
}
/*
* Called Party
*/
if (lap->called.tag == T_ATM_ABSENT) {
if (ap->called.tag == T_ATM_PRESENT)
continue;
} else if (lap->called.tag == T_ATM_PRESENT) {
if (ap->called.tag == T_ATM_ABSENT)
continue;
if (ap->called.tag == T_ATM_PRESENT) {
if ((!ATM_ADDR_EQUAL(&lap->called.addr,
&ap->called.addr)) ||
(!ATM_ADDR_EQUAL(&lap->called.subaddr,
&ap->called.subaddr)))
continue;
}
}
/*
* Found a full match - return it
*/
break;
}
return (cop);
}
/*
* Find Shareable LLC VCC
*
* Given an endpoint-supplied connection attribute using LLC multiplexing,
* this function will attempt to locate an existing connection which meets
* the requirements of the supplied attributes.
*
* Called at splnet.
*
* Arguments:
* ap pointer to requested attributes
*
* Returns:
* addr shareable LLC connection VCC
* 0 no shareable VCC available
*
*/
static Atm_connvc *
atm_cm_share_llc(ap)
Atm_attributes *ap;
{
Atm_connection *cop;
Atm_connvc *cvp;
/*
* Is requestor willing to share?
*/
if ((ap->llc.v.flags & T_ATM_LLC_SHARING) == 0)
return (NULL);
/*
* Try to find a shareable connection
*/
for (cvp = Q_HEAD(atm_connection_queue, Atm_connvc); cvp;
cvp = Q_NEXT(cvp, Atm_connvc, cvc_q)) {
/*
* Dont use terminating connections
*/
switch (cvp->cvc_state) {
case CVCS_SETUP:
case CVCS_ACCEPT:
case CVCS_ACTIVE:
break;
default:
continue;
}
/*
* Is connection LLC and shareable?
*/
if ((cvp->cvc_attr.llc.tag != T_ATM_PRESENT) ||
((cvp->cvc_attr.llc.v.flags & T_ATM_LLC_SHARING) == 0))
continue;
/*
* Match requested attributes with existing connection
*/
if (ap->nif != cvp->cvc_attr.nif)
continue;
if ((ap->api != cvp->cvc_attr.api) ||
(ap->api_init != cvp->cvc_attr.api_init))
continue;
/*
* Remote Party
*/
if (cvp->cvc_flags & CVCF_CALLER) {
if ((!ATM_ADDR_EQUAL(&ap->called.addr,
&cvp->cvc_attr.called.addr)) ||
(!ATM_ADDR_EQUAL(&ap->called.subaddr,
&cvp->cvc_attr.called.subaddr)))
continue;
} else {
if (cvp->cvc_attr.calling.tag != T_ATM_PRESENT)
continue;
if ((!ATM_ADDR_EQUAL(&ap->called.addr,
&cvp->cvc_attr.calling.addr)) ||
(!ATM_ADDR_EQUAL(&ap->called.subaddr,
&cvp->cvc_attr.calling.subaddr)))
continue;
}
/*
* AAL
*/
if (ap->aal.type == ATM_AAL5) {
struct t_atm_aal5 *ap5, *cv5;
ap5 = &ap->aal.v.aal5;
cv5 = &cvp->cvc_attr.aal.v.aal5;
if ((cvp->cvc_attr.aal.type != ATM_AAL5) ||
(ap5->SSCS_type != cv5->SSCS_type))
continue;
if (cvp->cvc_flags & CVCF_CALLER) {
if (ap5->forward_max_SDU_size >
cv5->forward_max_SDU_size)
continue;
} else {
if (ap5->forward_max_SDU_size >
cv5->backward_max_SDU_size)
continue;
}
} else {
struct t_atm_aal4 *ap4, *cv4;
ap4 = &ap->aal.v.aal4;
cv4 = &cvp->cvc_attr.aal.v.aal4;
if ((cvp->cvc_attr.aal.type != ATM_AAL3_4) ||
(ap4->SSCS_type != cv4->SSCS_type))
continue;
if (cvp->cvc_flags & CVCF_CALLER) {
if (ap4->forward_max_SDU_size >
cv4->forward_max_SDU_size)
continue;
} else {
if (ap4->forward_max_SDU_size >
cv4->backward_max_SDU_size)
continue;
}
}
/*
* Traffic Descriptor
*/
if ((ap->traffic.tag != T_ATM_PRESENT) ||
(cvp->cvc_attr.traffic.tag != T_ATM_PRESENT) ||
(ap->traffic.v.best_effort != T_YES) ||
(cvp->cvc_attr.traffic.v.best_effort != T_YES))
continue;
/*
* Broadband Bearer
*/
if (ap->bearer.v.connection_configuration !=
cvp->cvc_attr.bearer.v.connection_configuration)
continue;
/*
* QOS
*/
if (cvp->cvc_flags & CVCF_CALLER) {
if ((ap->qos.v.forward.qos_class !=
cvp->cvc_attr.qos.v.forward.qos_class) ||
(ap->qos.v.backward.qos_class !=
cvp->cvc_attr.qos.v.backward.qos_class))
continue;
} else {
if ((ap->qos.v.forward.qos_class !=
cvp->cvc_attr.qos.v.backward.qos_class) ||
(ap->qos.v.backward.qos_class !=
cvp->cvc_attr.qos.v.forward.qos_class))
continue;
}
/*
* The new LLC header must also be unique for this VCC
*/
for (cop = cvp->cvc_conn; cop; cop = cop->co_next) {
int i = MIN(ap->llc.v.llc_len,
cop->co_llc.v.llc_len);
if (bcmp(ap->llc.v.llc_info,
cop->co_llc.v.llc_info, i) == 0)
break;
}
/*
* If no header overlaps, then we're done
*/
if (cop == NULL)
break;
}
return (cvp);
}
/*
* Close Connection
*
* This function will terminate a connection, including notifying the
* user, if necessary, and freeing up control block memory. The caller
* is responsible for managing the connection VCC.
*
* Called at splnet.
*
* Arguments:
* cop pointer to connection block
* cause pointer to cause of close
*
* Returns:
* none
*
*/
static void
atm_cm_closeconn(cop, cause)
Atm_connection *cop;
struct t_atm_cause *cause;
{
/*
* Decide whether user needs notification
*/
switch (cop->co_state) {
case COS_OUTCONN:
case COS_LISTEN:
case COS_INCONN:
case COS_INACCEPT:
case COS_ACTIVE:
/*
* Yup, let 'em know connection is gone
*/
if (cop->co_toku)
(*cop->co_endpt->ep_cleared)(cop->co_toku, cause);
break;
case COS_CLEAR:
/*
* Nope,they should know already
*/
break;
default:
panic("atm_cm_closeconn: bogus state");
}
/*
* Unlink connection from its queues
*/
switch (cop->co_state) {
case COS_LISTEN:
uma_zfree(atm_attributes_zone, cop->co_lattr);
UNLINK(cop, Atm_connection, atm_listen_queue, co_next);
break;
default:
/*
* Remove connection from multiplexor queue
*/
if (cop->co_mxh != cop) {
/*
* Connection is down the chain, just unlink it
*/
UNLINK(cop, Atm_connection, cop->co_mxh, co_next);
} else if (cop->co_next != NULL) {
/*
* Connection is at the head of a non-singleton chain,
* so unlink and reset the chain head
*/
Atm_connection *t, *nhd;
t = nhd = cop->co_next;
while (t) {
t->co_mxh = nhd;
t = t->co_next;
}
if (nhd->co_connvc)
nhd->co_connvc->cvc_conn = nhd;
}
}
/*
* Free the connection block
*/
cop->co_state = COS_FREE;
uma_zfree(atm_connection_zone, cop);
return;
}
/*
* Close Connection VCC
*
* This function will terminate a connection VCC, including releasing the
* the call to the signalling manager, terminating the VCC protocol stack,
* and freeing up control block memory.
*
* Called at splnet.
*
* Arguments:
* cvp pointer to connection VCC block
*
* Returns:
* none
*
*/
static void
atm_cm_closevc(cvp)
Atm_connvc *cvp;
{
int err;
/*
* Break links with the connection block
*/
cvp->cvc_conn = NULL;
/*
* Cancel any running timer
*/
CVC_CANCEL(cvp);
/*
* Free queued packets
*/
while (cvp->cvc_rcvq) {
KBuffer *m;
m = cvp->cvc_rcvq;
cvp->cvc_rcvq = KB_QNEXT(m);
KB_QNEXT(m) = NULL;
KB_FREEALL(m);
}
/*
* Unlink from any queues
*/
if (cvp->cvc_flags & CVCF_INCOMQ) {
DEQUEUE(cvp, Atm_connvc, cvc_q, atm_incoming_queue);
atm_incoming_qlen--;
cvp->cvc_flags &= ~CVCF_INCOMQ;
} else if (cvp->cvc_flags & CVCF_CONNQ) {
DEQUEUE(cvp, Atm_connvc, cvc_q, atm_connection_queue);
cvp->cvc_flags &= ~CVCF_CONNQ;
}
/*
* Release the signalling call
*/
switch (cvp->cvc_state) {
case CVCS_SETUP:
case CVCS_INIT:
case CVCS_ACCEPT:
case CVCS_ACTIVE:
case CVCS_RELEASE:
if (cvp->cvc_vcc) {
cvp->cvc_state = CVCS_RELEASE;
switch ((*cvp->cvc_sigmgr->sm_release)
(cvp->cvc_vcc, &err)) {
case CALL_CLEARED:
/*
* Looks good so far...
*/
break;
case CALL_PROCEEDING:
/*
* We'll have to wait for the call to clear
*/
return;
case CALL_FAILED:
/*
* If there's a memory shortage, retry later.
* Otherwise who knows what's going on....
*/
if ((err == ENOMEM) || (err == ENOBUFS)) {
CVC_TIMER(cvp, 1 * ATM_HZ);
return;
}
log(LOG_ERR,
"atm_cm_closevc: release %d\n", err);
break;
}
}
break;
case CVCS_INCOMING:
case CVCS_REJECT:
if (cvp->cvc_vcc) {
cvp->cvc_state = CVCS_REJECT;
switch ((*cvp->cvc_sigmgr->sm_reject)
(cvp->cvc_vcc, &err)) {
case CALL_CLEARED:
/*
* Looks good so far...
*/
break;
case CALL_FAILED:
/*
* If there's a memory shortage, retry later.
* Otherwise who knows what's going on....
*/
if ((err == ENOMEM) || (err == ENOBUFS)) {
CVC_TIMER(cvp, 1 * ATM_HZ);
return;
}
log(LOG_ERR,
"atm_cm_closevc: reject %d\n", err);
break;
}
}
break;
case CVCS_CLEAR:
case CVCS_TERM:
/*
* No need for anything here
*/
break;
default:
panic("atm_cm_closevc: bogus state");
}
/*
* Now terminate the stack
*/
if (cvp->cvc_tokl) {
cvp->cvc_state = CVCS_TERM;
/*
* Wait until stack is unwound before terminating
*/
if ((cvp->cvc_downcnt > 0) || (cvp->cvc_upcnt > 0)) {
CVC_TIMER(cvp, 0);
return;
}
STACK_CALL(atm_stackcmds[cvp->cvc_attr.api].term,
cvp->cvc_lower, cvp->cvc_tokl, cvp, 0, 0, err);
cvp->cvc_tokl = NULL;
}
/*
* Let signalling manager finish up
*/
cvp->cvc_state = CVCS_FREE;
if (cvp->cvc_vcc) {
(void) (*cvp->cvc_sigmgr->sm_free)(cvp->cvc_vcc);
}
/*
* Finally, free our own control blocks
*/
uma_zfree(atm_connvc_zone, cvp);
return;
}
/*
* Process a Connection VCC timeout
*
* Called when a previously scheduled cvc control block timer expires.
* Processing will be based on the current cvc state.
*
* Called at splnet.
*
* Arguments:
* tip pointer to cvc timer control block
*
* Returns:
* none
*
*/
static void
atm_cm_timeout(tip)
struct atm_time *tip;
{
Atm_connection *cop, *cop2;
Atm_connvc *cvp;
/*
* Back-off to cvc control block
*/
cvp = (Atm_connvc *)
((caddr_t)tip - (int)(&((Atm_connvc *)0)->cvc_time));
/*
* Process timeout based on protocol state
*/
switch (cvp->cvc_state) {
case CVCS_SETUP:
case CVCS_ACCEPT:
case CVCS_ACTIVE:
/*
* Handle VCC abort
*/
if ((cvp->cvc_flags & CVCF_ABORTING) == 0)
goto logerr;
/*
* Terminate all connections
*/
cop = cvp->cvc_conn;
while (cop) {
cop2 = cop->co_next;
atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
cop = cop2;
}
/*
* Terminate VCC
*/
atm_cm_closevc(cvp);
break;
case CVCS_REJECT:
case CVCS_RELEASE:
case CVCS_TERM:
/*
* Retry failed operation
*/
atm_cm_closevc(cvp);
break;
default:
logerr:
log(LOG_ERR,
"atm_cm_timeout: invalid state: cvp=%p, state=%d\n",
cvp, cvp->cvc_state);
}
}
/*
* CPCS User Control Commands
*
* This function is called by an endpoint user to pass a control command
* across a CPCS data API. Mostly we just send these down the stack.
*
* Arguments:
* cmd stack command code
* cop pointer to connection block
* arg argument
*
* Returns:
* 0 command output successful
* errno output failed - reason indicated
*
*/
int
atm_cm_cpcs_ctl(cmd, cop, arg)
int cmd;
Atm_connection *cop;
void *arg;
{
Atm_connvc *cvp;
int err = 0;
/*
* Validate connection state
*/
if (cop->co_state != COS_ACTIVE) {
err = EFAULT;
goto done;
}
cvp = cop->co_connvc;
if (cvp->cvc_state != CVCS_ACTIVE) {
err = EFAULT;
goto done;
}
if (cvp->cvc_attr.api != CMAPI_CPCS) {
err = EFAULT;
goto done;
}
switch (cmd) {
default:
err = EINVAL;
}
done:
return (err);
}
/*
* CPCS Data Output
*
* This function is called by an endpoint user to output a data packet
* across a CPCS data API. After we've validated the connection state, the
* packet will be encapsulated (if necessary) and sent down the data stack.
*
* Arguments:
* cop pointer to connection block
* m pointer to packet buffer chain to be output
*
* Returns:
* 0 packet output successful
* errno output failed - reason indicated
*
*/
int
atm_cm_cpcs_data(cop, m)
Atm_connection *cop;
KBuffer *m;
{
Atm_connvc *cvp;
struct attr_llc *llcp;
int err, space;
void *bp;
/*
* Validate connection state
*/
if (cop->co_state != COS_ACTIVE) {
err = EFAULT;
goto done;
}
cvp = cop->co_connvc;
if (cvp->cvc_state != CVCS_ACTIVE) {
err = EFAULT;
goto done;
}
if (cvp->cvc_attr.api != CMAPI_CPCS) {
err = EFAULT;
goto done;
}
/*
* Add any packet encapsulation
*/
switch (cop->co_mpx) {
case ATM_ENC_NULL:
/*
* None needed...
*/
break;
case ATM_ENC_LLC:
/*
* Need to add an LLC header
*/
llcp = &cop->co_llc;
/*
* See if there's room to add LLC header to front of packet.
*/
KB_HEADROOM(m, space);
if (space < llcp->v.llc_len) {
KBuffer *n;
/*
* We have to allocate another buffer and tack it
* onto the front of the packet
*/
MGETHDR(n, KB_F_NOWAIT, KB_T_HEADER);
if (n == 0) {
err = ENOMEM;
goto done;
}
KB_TAILALIGN(n, llcp->v.llc_len);
KB_LINKHEAD(n, m);
m = n;
} else {
/*
* Header fits, just adjust buffer controls
*/
KB_HEADADJ(m, llcp->v.llc_len);
}
/*
* Add the LLC header
*/
KB_DATASTART(m, bp, void *);
bcopy(llcp->v.llc_info, bp, llcp->v.llc_len);
KB_PLENADJ(m, llcp->v.llc_len);
break;
default:
panic("atm_cm_cpcs_data: mpx");
}
/*
* Finally, we can send the packet on its way
*/
STACK_CALL(CPCS_UNITDATA_INV, cvp->cvc_lower, cvp->cvc_tokl,
cvp, (intptr_t)m, 0, err);
done:
return (err);
}
/*
* Process CPCS Stack Commands
*
* This is the top of the CPCS API data stack. All upward stack commands
* for the CPCS data API will be received and processed here.
*
* Arguments:
* cmd stack command code
* tok session token (pointer to connection VCC control block)
* arg1 argument 1
* arg2 argument 2
*
* Returns:
* none
*
*/
static void
atm_cm_cpcs_upper(cmd, tok, arg1, arg2)
int cmd;
void *tok;
intptr_t arg1;
intptr_t arg2;
{
Atm_connection *cop;
Atm_connvc *cvp = tok;
KBuffer *m;
void *bp;
int s;
switch (cmd) {
case CPCS_UNITDATA_SIG:
/*
* Input data packet
*/
m = (KBuffer *)arg1;
if (cvp->cvc_state != CVCS_ACTIVE) {
if (cvp->cvc_state == CVCS_ACCEPT) {
KBuffer *n;
/*
* Queue up any packets received before sigmgr
* notifies us of incoming call completion
*/
if (cvp->cvc_rcvqlen >= CVC_RCVQ_MAX) {
KB_FREEALL(m);
atm_cm_stat.cms_rcvconnvc++;
return;
}
KB_QNEXT(m) = NULL;
if (cvp->cvc_rcvq == NULL) {
cvp->cvc_rcvq = m;
} else {
for (n = cvp->cvc_rcvq;
KB_QNEXT(n) != NULL;
n = KB_QNEXT(n))
;
KB_QNEXT(n) = m;
}
cvp->cvc_rcvqlen++;
return;
} else {
KB_FREEALL(m);
atm_cm_stat.cms_rcvconnvc++;
return;
}
}
/*
* Send the packet to the interface's bpf if this
* vc has one.
*/
if (cvp->cvc_vcc != NULL &&
cvp->cvc_vcc->vc_nif != NULL) {
struct ifnet *ifp =
(struct ifnet *)cvp->cvc_vcc->vc_nif;
BPF_MTAP(ifp, m);
}
/*
* Locate packet's connection
*/
cop = cvp->cvc_conn;
switch (cop->co_mpx) {
case ATM_ENC_NULL:
/*
* We're already there...
*/
break;
case ATM_ENC_LLC:
/*
* Find connection with matching LLC header
*/
if (KB_LEN(m) < T_ATM_LLC_MAX_LEN) {
KB_PULLUP(m, T_ATM_LLC_MAX_LEN, m);
if (m == 0) {
atm_cm_stat.cms_llcdrop++;
return;
}
}
KB_DATASTART(m, bp, void *);
s = splnet();
while (cop) {
if (bcmp(bp, cop->co_llc.v.llc_info,
cop->co_llc.v.llc_len) == 0)
break;
cop = cop->co_next;
}
(void) splx(s);
if (cop == NULL) {
/*
* No connected user for this LLC
*/
KB_FREEALL(m);
atm_cm_stat.cms_llcid++;
return;
}
/*
* Strip off the LLC header
*/
KB_HEADADJ(m, -cop->co_llc.v.llc_len);
KB_PLENADJ(m, -cop->co_llc.v.llc_len);
break;
default:
panic("atm_cm_cpcs_upper: mpx");
}
/*
* We've found our connection, so hand the packet off
*/
if (cop->co_state != COS_ACTIVE) {
KB_FREEALL(m);
atm_cm_stat.cms_rcvconn++;
return;
}
(*cop->co_endpt->ep_cpcs_data)(cop->co_toku, m);
break;
case CPCS_UABORT_SIG:
case CPCS_PABORT_SIG:
/*
* We don't support these (yet), so just FALLTHROUGH
*/
default:
log(LOG_ERR, "atm_cm_cpcs_upper: unknown cmd 0x%x\n", cmd);
}
}
/*
* SAAL User Control Commands
*
* This function is called by an endpoint user to pass a control command
* across a SAAL data API. Mostly we just send these down the stack.
*
* Arguments:
* cmd stack command code
* cop pointer to connection block
* arg argument
*
* Returns:
* 0 command output successful
* errno output failed - reason indicated
*
*/
int
atm_cm_saal_ctl(cmd, cop, arg)
int cmd;
Atm_connection *cop;
void *arg;
{
Atm_connvc *cvp;
int err = 0;
/*
* Validate connection state
*/
if (cop->co_state != COS_ACTIVE) {
err = EFAULT;
goto done;
}
cvp = cop->co_connvc;
if (cvp->cvc_state != CVCS_ACTIVE) {
err = EFAULT;
goto done;
}
if (cvp->cvc_attr.api != CMAPI_SAAL) {
err = EFAULT;
goto done;
}
switch (cmd) {
case SSCF_UNI_ESTABLISH_REQ:
case SSCF_UNI_RELEASE_REQ:
/*
* Pass command down the stack
*/
STACK_CALL(cmd, cvp->cvc_lower, cvp->cvc_tokl, cvp,
(intptr_t)arg, 0, err);
break;
default:
err = EINVAL;
}
done:
return (err);
}
/*
* SAAL Data Output
*
* This function is called by an endpoint user to output a data packet
* across a SAAL data API. After we've validated the connection state,
* the packet will be sent down the data stack.
*
* Arguments:
* cop pointer to connection block
* m pointer to packet buffer chain to be output
*
* Returns:
* 0 packet output successful
* errno output failed - reason indicated
*
*/
int
atm_cm_saal_data(cop, m)
Atm_connection *cop;
KBuffer *m;
{
Atm_connvc *cvp;
int err;
/*
* Validate connection state
*/
if (cop->co_state != COS_ACTIVE) {
err = EFAULT;
goto done;
}
cvp = cop->co_connvc;
if (cvp->cvc_state != CVCS_ACTIVE) {
err = EFAULT;
goto done;
}
if (cvp->cvc_attr.api != CMAPI_SAAL) {
err = EFAULT;
goto done;
}
/*
* Finally, we can send the packet on its way
*/
STACK_CALL(SSCF_UNI_DATA_REQ, cvp->cvc_lower, cvp->cvc_tokl,
cvp, (intptr_t)m, 0, err);
done:
return (err);
}
/*
* Process SAAL Stack Commands
*
* This is the top of the SAAL API data stack. All upward stack commands
* for the SAAL data API will be received and processed here.
*
* Arguments:
* cmd stack command code
* tok session token (pointer to connection VCC control block)
* arg1 argument 1
* arg2 argument 2
*
* Returns:
* none
*
*/
static void
atm_cm_saal_upper(cmd, tok, arg1, arg2)
int cmd;
void *tok;
intptr_t arg1;
intptr_t arg2;
{
Atm_connection *cop;
Atm_connvc *cvp = tok;
switch (cmd) {
case SSCF_UNI_ESTABLISH_IND:
case SSCF_UNI_ESTABLISH_CNF:
case SSCF_UNI_RELEASE_IND:
case SSCF_UNI_RELEASE_CNF:
/*
* Control commands
*/
cop = cvp->cvc_conn;
if (cvp->cvc_state != CVCS_ACTIVE)
break;
if (cop->co_state != COS_ACTIVE)
break;
(*cop->co_endpt->ep_saal_ctl)(cmd, cop->co_toku, (void *)arg1);
break;
case SSCF_UNI_DATA_IND:
/*
* User data
*/
cop = cvp->cvc_conn;
if (cvp->cvc_state != CVCS_ACTIVE) {
atm_cm_stat.cms_rcvconnvc++;
KB_FREEALL((KBuffer *)arg1);
break;
}
if (cop->co_state != COS_ACTIVE) {
atm_cm_stat.cms_rcvconn++;
KB_FREEALL((KBuffer *)arg1);
break;
}
(*cop->co_endpt->ep_saal_data)(cop->co_toku, (KBuffer *)arg1);
break;
case SSCF_UNI_UNITDATA_IND:
/*
* Not supported
*/
KB_FREEALL((KBuffer *)arg1);
/* FALLTHRU */
default:
log(LOG_ERR, "atm_cm_saal_upper: unknown cmd 0x%x\n", cmd);
}
}
/*
* SSCOP User Control Commands
*
* This function is called by an endpoint user to pass a control command
* across a SSCOP data API. Mostly we just send these down the stack.
*
* Arguments:
* cmd stack command code
* cop pointer to connection block
* arg1 argument
* arg2 argument
*
* Returns:
* 0 command output successful
* errno output failed - reason indicated
*
*/
int
atm_cm_sscop_ctl(cmd, cop, arg1, arg2)
int cmd;
Atm_connection *cop;
void *arg1;
void *arg2;
{
Atm_connvc *cvp;
int err = 0;
/*
* Validate connection state
*/
if (cop->co_state != COS_ACTIVE) {
err = EFAULT;
goto done;
}
cvp = cop->co_connvc;
if (cvp->cvc_state != CVCS_ACTIVE) {
err = EFAULT;
goto done;
}
if (cvp->cvc_attr.api != CMAPI_SSCOP) {
err = EFAULT;
goto done;
}
switch (cmd) {
case SSCOP_ESTABLISH_REQ:
case SSCOP_ESTABLISH_RSP:
case SSCOP_RELEASE_REQ:
case SSCOP_RESYNC_REQ:
case SSCOP_RESYNC_RSP:
case SSCOP_RECOVER_RSP:
case SSCOP_RETRIEVE_REQ:
/*
* Pass command down the stack
*/
STACK_CALL(cmd, cvp->cvc_lower, cvp->cvc_tokl, cvp,
(intptr_t)arg1, (intptr_t)arg2, err);
break;
default:
err = EINVAL;
}
done:
return (err);
}
/*
* SSCOP Data Output
*
* This function is called by an endpoint user to output a data packet
* across a SSCOP data API. After we've validated the connection state,
* the packet will be encapsulated and sent down the data stack.
*
* Arguments:
* cop pointer to connection block
* m pointer to packet buffer chain to be output
*
* Returns:
* 0 packet output successful
* errno output failed - reason indicated
*
*/
int
atm_cm_sscop_data(cop, m)
Atm_connection *cop;
KBuffer *m;
{
Atm_connvc *cvp;
int err;
/*
* Validate connection state
*/
if (cop->co_state != COS_ACTIVE) {
err = EFAULT;
goto done;
}
cvp = cop->co_connvc;
if (cvp->cvc_state != CVCS_ACTIVE) {
err = EFAULT;
goto done;
}
if (cvp->cvc_attr.api != CMAPI_SSCOP) {
err = EFAULT;
goto done;
}
/*
* Finally, we can send the packet on its way
*/
STACK_CALL(SSCOP_DATA_REQ, cvp->cvc_lower, cvp->cvc_tokl,
cvp, (intptr_t)m, 0, err);
done:
return (err);
}
/*
* Process SSCOP Stack Commands
*
* This is the top of the SSCOP API data stack. All upward stack commands
* for the SSCOP data API will be received and processed here.
*
* Arguments:
* cmd stack command code
* tok session token (pointer to connection VCC control block)
* arg1 argument 1
* arg2 argument 2
*
* Returns:
* none
*
*/
static void
atm_cm_sscop_upper(cmd, tok, arg1, arg2)
int cmd;
void *tok;
intptr_t arg1;
intptr_t arg2;
{
Atm_connection *cop;
Atm_connvc *cvp = tok;
switch (cmd) {
case SSCOP_ESTABLISH_IND:
case SSCOP_ESTABLISH_CNF:
case SSCOP_RELEASE_IND:
case SSCOP_RESYNC_IND:
/*
* Control commands
*/
cop = cvp->cvc_conn;
if ((cvp->cvc_state != CVCS_ACTIVE) ||
(cop->co_state != COS_ACTIVE)) {
KB_FREEALL((KBuffer *)arg1);
break;
}
(*cop->co_endpt->ep_sscop_ctl)
(cmd, cop->co_toku, (void *)arg1, (void *)arg2);
break;
case SSCOP_RELEASE_CNF:
case SSCOP_RESYNC_CNF:
case SSCOP_RECOVER_IND:
case SSCOP_RETRIEVE_IND:
case SSCOP_RETRIEVECMP_IND:
/*
* Control commands
*/
cop = cvp->cvc_conn;
if ((cvp->cvc_state != CVCS_ACTIVE) ||
(cop->co_state != COS_ACTIVE))
break;
(*cop->co_endpt->ep_sscop_ctl)
(cmd, cop->co_toku, (void *)arg1, (void *)arg2);
break;
case SSCOP_DATA_IND:
/*
* User data
*/
cop = cvp->cvc_conn;
if (cvp->cvc_state != CVCS_ACTIVE) {
atm_cm_stat.cms_rcvconnvc++;
KB_FREEALL((KBuffer *)arg1);
break;
}
if (cop->co_state != COS_ACTIVE) {
atm_cm_stat.cms_rcvconn++;
KB_FREEALL((KBuffer *)arg1);
break;
}
(*cop->co_endpt->ep_sscop_data)
(cop->co_toku, (KBuffer *)arg1, arg2);
break;
case SSCOP_UNITDATA_IND:
/*
* Not supported
*/
KB_FREEALL((KBuffer *)arg1);
/* FALLTHRU */
default:
log(LOG_ERR, "atm_cm_sscop_upper: unknown cmd 0x%x\n", cmd);
}
}
/*
* Register an ATM Endpoint Service
*
* Every ATM endpoint service must register itself here before it can
* issue or receive any connection requests.
*
* Arguments:
* epp pointer to endpoint definition structure
*
* Returns:
* 0 registration successful
* errno registration failed - reason indicated
*
*/
int
atm_endpoint_register(epp)
Atm_endpoint *epp;
{
int s = splnet();
/*
* See if we need to be initialized
*/
if (!atm_init)
atm_initialize();
/*
* Validate endpoint
*/
if (epp->ep_id > ENDPT_MAX) {
(void) splx(s);
return (EINVAL);
}
if (atm_endpoints[epp->ep_id] != NULL) {
(void) splx(s);
return (EEXIST);
}
/*
* Add endpoint to list
*/
atm_endpoints[epp->ep_id] = epp;
(void) splx(s);
return (0);
}
/*
* De-register an ATM Endpoint Service
*
* Each ATM endpoint service provider must de-register its registered
* endpoint(s) before terminating. Specifically, loaded kernel modules
* must de-register their services before unloading themselves.
*
* Arguments:
* epp pointer to endpoint definition structure
*
* Returns:
* 0 de-registration successful
* errno de-registration failed - reason indicated
*
*/
int
atm_endpoint_deregister(epp)
Atm_endpoint *epp;
{
int s = splnet();
/*
* Validate endpoint
*/
if (epp->ep_id > ENDPT_MAX) {
(void) splx(s);
return (EINVAL);
}
if (atm_endpoints[epp->ep_id] != epp) {
(void) splx(s);
return (ENOENT);
}
/*
* Remove endpoint from list
*/
atm_endpoints[epp->ep_id] = NULL;
(void) splx(s);
return (0);
}
|