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 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134
|
/* voip_calls.c
* VoIP calls summary addition for Wireshark
*
* $Id: voip_calls.c 42997 2012-06-02 13:28:42Z etxrab $
*
* Copyright 2004, Ericsson, Spain
* By Francisco Alcoba <francisco.alcoba@ericsson.com>
*
* based on h323_calls.c
* Copyright 2004, Iskratel, Ltd, Kranj
* By Miha Jemec <m.jemec@iskratel.si>
*
* H323, RTP, RTP Event, MGCP, AudioCodes (ISDN PRI and CAS), T38 and Graph Support
* By Alejandro Vaquero, alejandro.vaquero@verso.com
* Copyright 2005, Verso Technologies Inc.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <epan/epan.h>
#include <epan/packet.h>
#include <epan/tap.h>
#include <epan/tap-voip.h>
#include <epan/dissectors/packet-sip.h>
#include <epan/dissectors/packet-mtp3.h>
#include <epan/dissectors/packet-isup.h>
#include <epan/dissectors/packet-h225.h>
#include <epan/dissectors/packet-h245.h>
#include <epan/dissectors/packet-q931.h>
#include <epan/dissectors/packet-sdp.h>
#include <epan/dissectors/packet-mgcp.h>
#include <epan/dissectors/packet-actrace.h>
#include <epan/dissectors/packet-rtp.h>
#include <epan/dissectors/packet-rtp-events.h>
#include <epan/dissectors/packet-t38.h>
#include <epan/dissectors/packet-t30.h>
#include <epan/dissectors/packet-h248.h>
#include <epan/dissectors/packet-sccp.h>
#include <plugins/unistim/packet-unistim.h>
#include <epan/dissectors/packet-skinny.h>
#include <epan/dissectors/packet-iax2.h>
#include <epan/rtp_pt.h>
#include "ui/alert_box.h"
#include "ui/simple_dialog.h"
#include "ui/ui_util.h"
#include "ui/gtk/graph_analysis.h"
#include "ui/gtk/voip_calls.h"
#include "ui/gtk/voip_calls_dlg.h"
#include "ui/gtk/main.h"
#ifdef HAVE_LIBPORTAUDIO
#include "ui/gtk/rtp_player.h"
#endif /* HAVE_LIBPORTAUDIO */
const char *voip_call_state_name[8]={
"",
"CALL SETUP",
"RINGING",
"IN CALL",
"CANCELLED",
"COMPLETED",
"REJECTED",
"UNKNOWN"
};
/* defines whether we can consider the call active */
const char *voip_protocol_name[]={
"SIP",
"ISUP",
"H.323",
"MGCP",
"AC_ISDN",
"AC_CAS",
"T.38",
"H.248",
"SCCP",
"BSSMAP",
"RANAP",
"UNISTIM",
"SKINNY",
"IAX2",
"VoIP"
};
typedef struct {
gchar *frame_label;
gchar *comment;
} graph_str;
#define H245_MAX 6
typedef struct {
guint32 frame_num;
gint8 labels_count;
graph_str labels[H245_MAX];
} h245_labels_t;
static h245_labels_t h245_labels;
/* defines a RTP stream */
typedef struct _voip_rtp_stream_info {
address src_addr;
guint16 src_port;
address dest_addr;
guint16 dest_port;
guint32 ssrc;
guint32 pt;
gchar *pt_str;
gboolean is_srtp;
guint32 npackets;
gboolean end_stream;
guint32 setup_frame_number; /* frame number of setup message */
/* The frame_data struct holds the frame number and timing information needed. */
frame_data *start_fd;
frame_data *stop_fd;
gint32 rtp_event;
} voip_rtp_stream_info_t;
/****************************************************************************/
/* the one and only global voip_calls_tapinfo_t structure */
static voip_calls_tapinfo_t the_tapinfo_struct =
{0, NULL, {0}, 0, NULL, 0, 0, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
/* the one and only global voip_rtp_tapinfo_t structure */
static voip_rtp_tapinfo_t the_tapinfo_rtp_struct =
{0, NULL, 0, 0};
/****************************************************************************/
/* when there is a [re]reading of packet's */
void voip_calls_reset(voip_calls_tapinfo_t *tapinfo)
{
voip_calls_info_t *callsinfo;
voip_rtp_tapinfo_t *rtp_tapinfo = &the_tapinfo_rtp_struct;
voip_rtp_stream_info_t *strinfo;
graph_analysis_item_t *graph_item;
GList *list;
#ifdef HAVE_LIBPORTAUDIO
/* reset the RTP player */
reset_rtp_player();
#endif
/* free the data items first */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
callsinfo = list->data;
g_free(callsinfo->call_id);
g_free(callsinfo->from_identity);
g_free(callsinfo->to_identity);
g_free((void *)(callsinfo->initial_speaker.data));
g_free(callsinfo->protocol_name);
g_free(callsinfo->call_comment);
if (callsinfo->free_prot_info && callsinfo->prot_info)
callsinfo->free_prot_info(callsinfo->prot_info);
g_free(list->data);
list = g_list_next(list);
}
g_list_free(tapinfo->callsinfo_list);
/* free the SIP_HASH */
if(NULL!=tapinfo->callsinfo_hashtable[SIP_HASH])
g_hash_table_remove_all (tapinfo->callsinfo_hashtable[SIP_HASH]);
tapinfo->callsinfo_list = NULL;
tapinfo->ncalls = 0;
tapinfo->npackets = 0;
tapinfo->start_packets = 0;
tapinfo->completed_calls = 0;
tapinfo->rejected_calls = 0;
tapinfo->reversed= 0;
/* free the graph data items first */
if(NULL!=tapinfo->graph_analysis->ht)
g_hash_table_remove_all(tapinfo->graph_analysis->ht);
list = g_list_first(tapinfo->graph_analysis->list);
while (list)
{
graph_item = list->data;
g_free(graph_item->frame_label);
g_free(graph_item->comment);
g_free((void *)graph_item->src_addr.data);
g_free((void *)graph_item->dst_addr.data);
g_free(list->data);
list = g_list_next(list);
}
g_list_free(tapinfo->graph_analysis->list);
tapinfo->graph_analysis->nconv = 0;
tapinfo->graph_analysis->list = NULL;
++(tapinfo->launch_count);
/* free the strinfo data items first */
list = g_list_first(rtp_tapinfo->list);
while(list)
{
strinfo = list->data;
g_free(strinfo->pt_str);
list = g_list_next(list);
}
g_list_free(rtp_tapinfo->list);
rtp_tapinfo->list = NULL;
return;
}
/****************************************************************************/
void graph_analysis_data_init(void) {
the_tapinfo_struct.graph_analysis = g_malloc(sizeof(graph_analysis_info_t));
the_tapinfo_struct.graph_analysis->nconv = 0;
the_tapinfo_struct.graph_analysis->list = NULL;
the_tapinfo_struct.graph_analysis->ht= g_hash_table_new(g_int_hash, g_int_equal);
}
/****************************************************************************/
/* Add a new item into the graph */
static void add_to_graph(voip_calls_tapinfo_t *tapinfo _U_, packet_info *pinfo, const gchar *frame_label, const gchar *comment, guint16 call_num, address *src_addr, address *dst_addr, guint16 line_style)
{
graph_analysis_item_t *gai;
gai = g_malloc(sizeof(graph_analysis_item_t));
gai->fd = pinfo->fd;
COPY_ADDRESS(&(gai->src_addr),src_addr);
COPY_ADDRESS(&(gai->dst_addr),dst_addr);
gai->port_src=pinfo->srcport;
gai->port_dst=pinfo->destport;
if (frame_label != NULL)
gai->frame_label = g_strdup(frame_label);
else
gai->frame_label = g_strdup("");
if (comment != NULL)
gai->comment = g_strdup(comment);
else
gai->comment = g_strdup("");
gai->conv_num=call_num;
gai->line_style=line_style;
gai->display=FALSE;
tapinfo->graph_analysis->list = g_list_prepend(tapinfo->graph_analysis->list, gai);
g_hash_table_insert(tapinfo->graph_analysis->ht, &gai->fd->num, gai);
}
/****************************************************************************/
/* Append str to frame_label and comment in a graph item */
/* return 0 if the frame_num is not in the graph list */
static int append_to_frame_graph(voip_calls_tapinfo_t *tapinfo _U_, guint32 frame_num, const gchar *new_frame_label, const gchar *new_comment)
{
graph_analysis_item_t *gai=NULL;
gchar *frame_label = NULL;
gchar *comment = NULL;
if(NULL!=tapinfo->graph_analysis->ht)
gai=g_hash_table_lookup(tapinfo->graph_analysis->ht, &frame_num);
if(gai) {
frame_label = gai->frame_label;
comment = gai->comment;
if (new_frame_label != NULL) {
gai->frame_label = g_strdup_printf("%s %s", frame_label, new_frame_label);
g_free(frame_label);
}
if (new_comment != NULL) {
gai->comment = g_strdup_printf("%s %s", comment, new_comment);
g_free(comment);
}
}
return gai? 1 : 0;
}
/****************************************************************************/
/* Change the frame_label and comment in a graph item if not NULL*/
/* return 0 if the frame_num is not in the graph list */
static int change_frame_graph(voip_calls_tapinfo_t *tapinfo _U_, guint32 frame_num, const gchar *new_frame_label, const gchar *new_comment)
{
graph_analysis_item_t *gai=NULL;
gchar *frame_label = NULL;
gchar *comment = NULL;
if(NULL!=tapinfo->graph_analysis->ht)
gai=g_hash_table_lookup(tapinfo->graph_analysis->ht, &frame_num);
if(gai) {
frame_label = gai->frame_label;
comment = gai->comment;
if (new_frame_label != NULL) {
gai->frame_label = g_strdup(new_frame_label);
g_free(frame_label);
}
if (new_comment != NULL) {
gai->comment = g_strdup(new_comment);
g_free(comment);
}
}
return gai? 1 : 0;
}
/****************************************************************************/
/* Change all the graph items with call_num to new_call_num */
static guint change_call_num_graph(voip_calls_tapinfo_t *tapinfo _U_, guint16 call_num, guint16 new_call_num)
{
graph_analysis_item_t *gai;
GList *list;
guint items_changed;
items_changed = 0;
list = g_list_first(tapinfo->graph_analysis->list);
while (list)
{
gai = list->data;
if (gai->conv_num == call_num) {
gai->conv_num = new_call_num;
items_changed++;
}
list = g_list_next(list);
}
return items_changed;
}
/****************************************************************************/
/* Insert the item in the graph list */
static void insert_to_graph_t38(voip_calls_tapinfo_t *tapinfo _U_, packet_info *pinfo, const gchar *frame_label, const gchar *comment, guint16 call_num, address *src_addr, address *dst_addr, guint16 line_style, guint32 frame_num)
{
graph_analysis_item_t *gai, *new_gai;
GList *list;
guint item_num;
gboolean inserted;
new_gai = g_malloc(sizeof(graph_analysis_item_t));
new_gai->fd = new_packet_list_get_row_data(frame_num);
COPY_ADDRESS(&(new_gai->src_addr),src_addr);
COPY_ADDRESS(&(new_gai->dst_addr),dst_addr);
new_gai->port_src=pinfo->srcport;
new_gai->port_dst=pinfo->destport;
if (frame_label != NULL)
new_gai->frame_label = g_strdup(frame_label);
else
new_gai->frame_label = g_strdup("");
if (comment != NULL)
new_gai->comment = g_strdup(comment);
else
new_gai->comment = g_strdup("");
new_gai->conv_num=call_num;
new_gai->line_style=line_style;
new_gai->display=FALSE;
item_num = 0;
inserted = FALSE;
list = g_list_first(tapinfo->graph_analysis->list);
while (list)
{
gai = list->data;
if (gai->fd->num > frame_num) {
the_tapinfo_struct.graph_analysis->list = g_list_insert(the_tapinfo_struct.graph_analysis->list, new_gai, item_num);
g_hash_table_insert(tapinfo->graph_analysis->ht, &new_gai->fd->num, new_gai);
inserted = TRUE;
break;
}
list = g_list_next(list);
item_num++;
}
if (!inserted) {
tapinfo->graph_analysis->list = g_list_prepend(tapinfo->graph_analysis->list, new_gai);
g_hash_table_insert(tapinfo->graph_analysis->ht, &new_gai->fd->num, new_gai);
}
}
/****************************************************************************/
/* ***************************TAP for RTP Events*****************************/
/****************************************************************************/
static guint32 rtp_evt_frame_num = 0;
static guint8 rtp_evt = 0;
static gboolean rtp_evt_end = FALSE;
/*static guint32 rtp_evt_setup_frame_num = 0;*/
/****************************************************************************/
/* whenever a rtp event packet is seen by the tap listener */
static int
rtp_event_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *rtp_event_info)
{
const struct _rtp_event_info *pi = rtp_event_info;
/* do not consider RTP events packets without a setup frame */
if (pi->info_setup_frame_num == 0) {
return 0;
}
rtp_evt_frame_num = pinfo->fd->num;
rtp_evt = pi->info_rtp_evt;
rtp_evt_end = pi->info_end;
return 0;
}
/****************************************************************************/
static gboolean have_rtp_event_tap_listener=FALSE;
void
rtp_event_init_tap(void)
{
GString *error_string;
if(have_rtp_event_tap_listener==FALSE)
{
error_string = register_tap_listener("rtpevent", &(the_tapinfo_rtp_struct.rtp_event_dummy),
NULL,
0,
NULL,
rtp_event_packet,
NULL
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_rtp_event_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_rtp_event(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_rtp_struct.rtp_event_dummy));
unprotect_thread_critical_region();
have_rtp_event_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for RTP **********************************/
/****************************************************************************/
/****************************************************************************/
/* when there is a [re]reading of RTP packet's */
static void voip_rtp_reset(void *ptr _U_)
{
voip_rtp_tapinfo_t *tapinfo = &the_tapinfo_rtp_struct;
GList *list;
/* free the data items first */
list = g_list_first(tapinfo->list);
while (list)
{
g_free(list->data);
list = g_list_next(list);
}
g_list_free(tapinfo->list);
tapinfo->list = NULL;
tapinfo->nstreams = 0;
return;
}
/****************************************************************************/
/* whenever a RTP packet is seen by the tap listener */
static int
RTP_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, void const *RTPinfo)
{
voip_rtp_tapinfo_t *tapinfo = &the_tapinfo_rtp_struct;
voip_rtp_stream_info_t *tmp_listinfo;
voip_rtp_stream_info_t *strinfo = NULL;
GList *list;
struct _rtp_conversation_info *p_conv_data = NULL;
const struct _rtp_info *pi = RTPinfo;
/* do not consider RTP packets without a setup frame */
if (pi->info_setup_frame_num == 0) {
return 0;
}
/* add this RTP for future listening using the RTP Player*/
#ifdef HAVE_LIBPORTAUDIO
add_rtp_packet(pi, pinfo);
#endif
/* check whether we already have a RTP stream with this setup frame and ssrc in the list */
list = g_list_first(tapinfo->list);
while (list)
{
tmp_listinfo=list->data;
if ( (tmp_listinfo->setup_frame_number == pi->info_setup_frame_num)
&& (tmp_listinfo->ssrc == pi->info_sync_src) && (tmp_listinfo->end_stream == FALSE)) {
/* if the payload type has changed, we mark the stream as finished to create a new one
this is to show multiple payload changes in the Graph for example for DTMF RFC2833 */
if ( tmp_listinfo->pt != pi->info_payload_type ) {
tmp_listinfo->end_stream = TRUE;
} else {
strinfo = (voip_rtp_stream_info_t*)(list->data);
break;
}
}
list = g_list_next(list);
}
/* if this is a duplicated RTP Event End, just return */
if ((rtp_evt_frame_num == pinfo->fd->num) && !strinfo && (rtp_evt_end == TRUE)) {
return 0;
}
/* not in the list? then create a new entry */
if (strinfo==NULL) {
strinfo = g_malloc(sizeof(voip_rtp_stream_info_t));
COPY_ADDRESS(&(strinfo->src_addr), &(pinfo->src));
strinfo->src_port = pinfo->srcport;
COPY_ADDRESS(&(strinfo->dest_addr), &(pinfo->dst));
strinfo->dest_port = pinfo->destport;
strinfo->ssrc = pi->info_sync_src;
strinfo->end_stream = FALSE;
strinfo->pt = pi->info_payload_type;
strinfo->pt_str = NULL;
strinfo->is_srtp = pi->info_is_srtp;
/* if it is dynamic payload, let use the conv data to see if it is defined */
if ( (strinfo->pt >= PT_UNDF_96) && (strinfo->pt <= PT_UNDF_127) ) {
/* Use existing packet info if available */
p_conv_data = p_get_proto_data(pinfo->fd, proto_get_id_by_filter_name("rtp"));
if (p_conv_data && p_conv_data->rtp_dyn_payload) {
encoding_name_and_rate_t *encoding_name_and_rate_pt = NULL;
encoding_name_and_rate_pt = g_hash_table_lookup(p_conv_data->rtp_dyn_payload, &strinfo->pt);
if (encoding_name_and_rate_pt) {
strinfo->pt_str = g_strdup(encoding_name_and_rate_pt->encoding_name);
}
}
}
if (!strinfo->pt_str) strinfo->pt_str = g_strdup(val_to_str_ext(strinfo->pt, &rtp_payload_type_short_vals_ext, "%u"));
strinfo->npackets = 0;
strinfo->start_fd = pinfo->fd;
strinfo->setup_frame_number = pi->info_setup_frame_num;
strinfo->rtp_event = -1;
tapinfo->list = g_list_prepend(tapinfo->list, strinfo);
}
/* Add the info to the existing RTP stream */
strinfo->npackets++;
strinfo->stop_fd = pinfo->fd;
/* process RTP Event */
if (rtp_evt_frame_num == pinfo->fd->num) {
strinfo->rtp_event = rtp_evt;
if (rtp_evt_end == TRUE) {
strinfo->end_stream = TRUE;
}
}
the_tapinfo_struct.redraw = TRUE;
return 1;
}
/****************************************************************************/
/* whenever a redraw in the RTP tap listener */
static void RTP_packet_draw(void *prs _U_)
{
voip_rtp_tapinfo_t *rtp_tapinfo = &the_tapinfo_rtp_struct;
GList *rtp_streams_list;
voip_rtp_stream_info_t *rtp_listinfo;
/* GList *voip_calls_graph_list; */
graph_analysis_item_t *gai;
graph_analysis_item_t *new_gai;
guint16 conv_num;
guint32 duration;
/* add each rtp stream to the graph */
rtp_streams_list = g_list_first(rtp_tapinfo->list);
while (rtp_streams_list)
{
rtp_listinfo = rtp_streams_list->data;
/* using the setup frame number of the RTP stream, we get the call number that it belongs to*/
/* voip_calls_graph_list = g_list_first(the_tapinfo_struct.graph_analysis->list); */
gai = g_hash_table_lookup(the_tapinfo_struct.graph_analysis->ht, &rtp_listinfo->setup_frame_number);
if(gai != NULL) {
/* Found the setup frame*/
conv_num = gai->conv_num;
/* if RTP was already in the Graph, just update the comment information */
gai = g_hash_table_lookup(the_tapinfo_struct.graph_analysis->ht, &rtp_listinfo->start_fd->num);
if(gai != NULL) {
duration = (guint32)(nstime_to_msec(&rtp_listinfo->stop_fd->rel_ts) - nstime_to_msec(&rtp_listinfo->start_fd->rel_ts));
g_free(gai->comment);
gai->comment = g_strdup_printf("%s Num packets:%u Duration:%u.%03us SSRC:0x%X",
(rtp_listinfo->is_srtp)?"SRTP":"RTP", rtp_listinfo->npackets,
duration/1000,(duration%1000), rtp_listinfo->ssrc);
}else {
new_gai = g_malloc(sizeof(graph_analysis_item_t));
new_gai->fd = rtp_listinfo->start_fd;
COPY_ADDRESS(&(new_gai->src_addr),&(rtp_listinfo->src_addr));
COPY_ADDRESS(&(new_gai->dst_addr),&(rtp_listinfo->dest_addr));
new_gai->port_src = rtp_listinfo->src_port;
new_gai->port_dst = rtp_listinfo->dest_port;
duration = (guint32)(nstime_to_msec(&rtp_listinfo->stop_fd->rel_ts) - nstime_to_msec(&rtp_listinfo->start_fd->rel_ts));
new_gai->frame_label = g_strdup_printf("%s (%s) %s",
(rtp_listinfo->is_srtp)?"SRTP":"RTP",
rtp_listinfo->pt_str,
(rtp_listinfo->rtp_event == -1)?
"":val_to_str_const(rtp_listinfo->rtp_event, rtp_event_type_values, "Unknown RTP Event"));
new_gai->comment = g_strdup_printf("%s Num packets:%u Duration:%u.%03us SSRC:0x%X",
(rtp_listinfo->is_srtp)?"SRTP":"RTP", rtp_listinfo->npackets,
duration/1000,(duration%1000), rtp_listinfo->ssrc);
new_gai->conv_num = conv_num;
new_gai->display=FALSE;
new_gai->line_style = 2; /* the arrow line will be 2 pixels width */
the_tapinfo_struct.graph_analysis->list = g_list_prepend(the_tapinfo_struct.graph_analysis->list, new_gai);
g_hash_table_insert(the_tapinfo_struct.graph_analysis->ht, &rtp_listinfo->start_fd, new_gai);
}
}
rtp_streams_list = g_list_next(rtp_streams_list);
}/* while (rtp_streams_list) */
}
#if 0
static void RTP_packet_draw(void *prs _U_)
{
voip_rtp_tapinfo_t *rtp_tapinfo = &the_tapinfo_rtp_struct;
GList *rtp_streams_list;
voip_rtp_stream_info_t *rtp_listinfo;
GList *voip_calls_graph_list;
guint item;
graph_analysis_item_t *gai;
graph_analysis_item_t *new_gai;
guint16 conv_num;
guint32 duration;
/* add each rtp stream to the graph */
rtp_streams_list = g_list_first(rtp_tapinfo->list);
while (rtp_streams_list)
{
rtp_listinfo = rtp_streams_list->data;
/* using the setup frame number of the RTP stream, we get the call number that it belongs to*/
voip_calls_graph_list = g_list_first(the_tapinfo_struct.graph_analysis->list);
while (voip_calls_graph_list)
{
gai = voip_calls_graph_list->data;
conv_num = gai->conv_num;
/* if we get the setup frame number, then get the time position to graph the RTP arrow */
if (rtp_listinfo->setup_frame_number == gai->fd->num) {
/* look again from the begining because there are cases where the Setup frame is after the RTP */
voip_calls_graph_list = g_list_first(the_tapinfo_struct.graph_analysis->list);
item = 0;
while(voip_calls_graph_list) {
gai = voip_calls_graph_list->data;
/* if RTP was already in the Graph, just update the comment information */
if (rtp_listinfo->start_fd->num == gai->fd->num) {
duration = (guint32)(nstime_to_msec(&rtp_listinfo->stop_fd->rel_ts) - nstime_to_msec(&rtp_listinfo->start_fd->rel_ts));
g_free(gai->comment);
gai->comment = g_strdup_printf("%s Num packets:%u Duration:%u.%03us SSRC:0x%X",
(rtp_listinfo->is_srtp)?"SRTP":"RTP", rtp_listinfo->npackets,
duration/1000,(duration%1000), rtp_listinfo->ssrc);
break;
}
/* we increment the list here to be able to check if it is the last item in this calls, which means the RTP is after so we have to draw it */
voip_calls_graph_list = g_list_next(voip_calls_graph_list);
if (!voip_calls_graph_list) item++;
/* add the RTP item to the graph if was not there*/
if (rtp_listinfo->start_fd->num<gai->fd->num || !voip_calls_graph_list) {
new_gai = g_malloc(sizeof(graph_analysis_item_t));
new_gai->fd = rtp_listinfo->start_fd;
COPY_ADDRESS(&(new_gai->src_addr),&(rtp_listinfo->src_addr));
COPY_ADDRESS(&(new_gai->dst_addr),&(rtp_listinfo->dest_addr));
new_gai->port_src = rtp_listinfo->src_port;
new_gai->port_dst = rtp_listinfo->dest_port;
duration = (guint32)(nstime_to_msec(&rtp_listinfo->stop_fd->rel_ts) - nstime_to_msec(&rtp_listinfo->start_fd->rel_ts));
new_gai->frame_label = g_strdup_printf("%s (%s) %s",
(rtp_listinfo->is_srtp)?"SRTP":"RTP",
rtp_listinfo->pt_str,
(rtp_listinfo->rtp_event == -1)?
"":val_to_str_const(rtp_listinfo->rtp_event, rtp_event_type_values, "Unknown RTP Event"));
new_gai->comment = g_strdup_printf("%s Num packets:%u Duration:%u.%03us SSRC:0x%X",
(rtp_listinfo->is_srtp)?"SRTP":"RTP", rtp_listinfo->npackets,
duration/1000,(duration%1000), rtp_listinfo->ssrc);
new_gai->conv_num = conv_num;
new_gai->display=FALSE;
new_gai->line_style = 2; /* the arrow line will be 2 pixels width */
the_tapinfo_struct.graph_analysis->list = g_list_insert(the_tapinfo_struct.graph_analysis->list, new_gai, item);
break;
}
if (voip_calls_graph_list) item++;
}
break;
}
voip_calls_graph_list = g_list_next(voip_calls_graph_list);
}
rtp_streams_list = g_list_next(rtp_streams_list);
}
}
#endif
static gboolean have_RTP_tap_listener=FALSE;
/****************************************************************************/
void
rtp_init_tap(void)
{
GString *error_string;
if(have_RTP_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("rtp", &(the_tapinfo_rtp_struct.rtp_dummy), NULL,
0,
voip_rtp_reset,
RTP_packet,
RTP_packet_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_RTP_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_rtp(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_rtp_struct.rtp_dummy));
unprotect_thread_critical_region();
have_RTP_tap_listener=FALSE;
}
/****************************************************************************/
/******************************TAP for T38 **********************************/
/****************************************************************************/
/****************************************************************************/
/* whenever a T38 packet is seen by the tap listener */
static int
T38_packet( void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *T38info)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *callsinfo = NULL;
voip_calls_info_t *tmp_listinfo;
GList *voip_calls_graph_list;
GList *list;
gchar *frame_label = NULL;
gchar *comment = NULL;
graph_analysis_item_t *tmp_gai, *gai = NULL;
guint16 line_style = 2;
double duration;
int conv_num = -1;
const t38_packet_info *pi = T38info;
if (pi->setup_frame_number != 0) {
/* using the setup frame number of the T38 packet, we get the call number that it belongs */
voip_calls_graph_list = g_list_first(tapinfo->graph_analysis->list);
while (voip_calls_graph_list)
{
tmp_gai = voip_calls_graph_list->data;
if (pi->setup_frame_number == tmp_gai->fd->num) {
gai = tmp_gai;
break;
}
voip_calls_graph_list = g_list_next(voip_calls_graph_list);
}
if (gai) conv_num = (int) gai->conv_num;
}
/* if setup_frame_number in the t38 packet is 0, it means it was not set using an SDP or H245 sesion, which means we don't
* have the associated Voip calls. It probably means the the packet was decoded using the default t38 port, or using "Decode as.."
* in this case we create a "voip" call that only have t38 media (no signaling)
* OR if we have not found the Setup message in the graph.
*/
if ( (pi->setup_frame_number == 0) || (gai == NULL) ) {
/* check whether we already have a call with these parameters in the list */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if (tmp_listinfo->protocol == MEDIA_T38) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
list = g_list_next (list);
}
/* not in the list? then create a new entry */
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_UNKNOWN;
callsinfo->from_identity=g_strdup("T38 Media only");
callsinfo->to_identity=g_strdup("T38 Media only");
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd = pinfo->fd;
callsinfo->protocol=MEDIA_T38;
callsinfo->prot_info=NULL;
callsinfo->free_prot_info = NULL;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
conv_num = (int) callsinfo->call_num;
}
/* at this point we should have found the call num for this t38 packets belong */
if (conv_num == -1) {
return 0;
}
/* add the item to the graph list */
if (pi->type_msg == 0) { /* 0=t30-indicator */
frame_label = g_strdup(val_to_str(pi->t30ind_value, t38_T30_indicator_vals, "Ukn (0x%02X)") );
comment = g_strdup_printf("t38:t30 Ind:%s",val_to_str(pi->t30ind_value, t38_T30_indicator_vals, "Ukn (0x%02X)") );
line_style = 1;
} else if (pi->type_msg == 1) { /* 1=data */
switch(pi->Data_Field_field_type_value) {
case 0: /* hdlc-data */
break;
case 2: /* hdlc-fcs-OK */
case 4: /* hdlc-fcs-OK-sig-end */
frame_label = g_strdup_printf("%s %s", val_to_str(pi->t30_Facsimile_Control & 0x7F, t30_facsimile_control_field_vals_short, "Ukn (0x%02X)"), pi->desc);
comment = g_strdup_printf("t38:%s:HDLC:%s",val_to_str(pi->data_value, t38_T30_data_vals, "Ukn (0x%02X)"), val_to_str(pi->t30_Facsimile_Control & 0x7F, t30_facsimile_control_field_vals, "Ukn (0x%02X)"));
break;
case 3: /* hdlc-fcs-BAD */
case 5: /* hdlc-fcs-BAD-sig-end */
frame_label = g_strdup(pi->Data_Field_field_type_value == 3 ? "fcs-BAD" : "fcs-BAD-sig-end");
comment = g_strdup_printf("WARNING: received t38:%s:HDLC:%s", val_to_str(pi->data_value, t38_T30_data_vals, "Ukn (0x%02X)"), pi->Data_Field_field_type_value == 3 ? "fcs-BAD" : "fcs-BAD-sig-end");
break;
case 7: /* t4-non-ecm-sig-end */
duration = nstime_to_sec(&pinfo->fd->rel_ts) - pi->time_first_t4_data;
frame_label = g_strdup_printf("t4-non-ecm-data:%s",val_to_str(pi->data_value, t38_T30_data_vals, "Ukn (0x%02X)") );
comment = g_strdup_printf("t38:t4-non-ecm-data:%s Duration: %.2fs %s",val_to_str(pi->data_value, t38_T30_data_vals, "Ukn (0x%02X)"), duration, pi->desc_comment );
insert_to_graph_t38(tapinfo, pinfo, frame_label, comment, (guint16)conv_num, &(pinfo->src), &(pinfo->dst), line_style, pi->frame_num_first_t4_data);
break;
}
}
if (frame_label && !(pi->Data_Field_field_type_value == 7 && pi->type_msg == 1)) {
add_to_graph(tapinfo, pinfo, frame_label, comment, (guint16)conv_num, &(pinfo->src), &(pinfo->dst), line_style);
}
g_free(comment);
g_free(frame_label);
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
static gboolean have_T38_tap_listener=FALSE;
/****************************************************************************/
void
t38_init_tap(void)
{
GString *error_string;
if(have_T38_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("t38", &(the_tapinfo_struct.t38_dummy), NULL,
0,
voip_calls_dlg_reset,
T38_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_T38_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_t38(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.t38_dummy));
unprotect_thread_critical_region();
have_T38_tap_listener=FALSE;
}
/****************************************************************************/
static gchar *sdp_summary = NULL;
static guint32 sdp_frame_num = 0;
/****************************************************************************/
/* ***************************TAP for SIP **********************************/
/****************************************************************************/
static void free_sip_info(gpointer p) {
sip_calls_info_t *si = p;
g_free(si->call_identifier);
g_free(si);
}
/****************************************************************************/
/* whenever a SIP packet is seen by the tap listener */
static int
SIPcalls_packet( void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *SIPinfo)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
/* we just take note of the ISUP data here; when we receive the MTP3 part everything will
be compared with existing calls */
voip_calls_info_t *callsinfo = NULL;
sip_calls_info_t *tmp_sipinfo = NULL;
address tmp_src, tmp_dst;
gchar *frame_label = NULL;
gchar *comment = NULL;
gchar *key=NULL;
const sip_info_value_t *pi = SIPinfo;
/* do not consider packets without call_id */
if (pi->tap_call_id ==NULL) {
return 0;
}
key=pi->tap_call_id;
/* init the hash table */
if(NULL==tapinfo->callsinfo_hashtable[SIP_HASH]) {
/* TODO: check how efficient g_str_hash is for sip call ids */
tapinfo->callsinfo_hashtable[SIP_HASH]=g_hash_table_new_full(g_str_hash,
g_str_equal,
NULL, /* key_destroy_func */
NULL);/* value_destroy_func */
}
/* search the call information in the SIP_HASH */
callsinfo = g_hash_table_lookup(tapinfo->callsinfo_hashtable[SIP_HASH], key);
/* not in the hash? then create a new entry if the message is INVITE -i.e. if this session is a call*/
if ((callsinfo==NULL) &&(pi->request_method!=NULL)) {
if (strcmp(pi->request_method,"INVITE")==0) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup(pi->tap_from_addr);
callsinfo->to_identity=g_strdup(pi->tap_to_addr);
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_SIP;
callsinfo->prot_info=g_malloc(sizeof(sip_calls_info_t));
callsinfo->free_prot_info = free_sip_info;
tmp_sipinfo = callsinfo->prot_info;
tmp_sipinfo->call_identifier = g_strdup(pi->tap_call_id);
tmp_sipinfo->sip_state = SIP_INVITE_SENT;
tmp_sipinfo->invite_cseq = pi->tap_cseq_number;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
/* insert the call information in the SIP_HASH */
g_hash_table_insert(tapinfo->callsinfo_hashtable[SIP_HASH],
tmp_sipinfo->call_identifier, callsinfo);
}
}
if (callsinfo!=NULL) {
tmp_sipinfo = callsinfo->prot_info;
/* let's analyze the call state */
COPY_ADDRESS(&(tmp_src), &(pinfo->src));
COPY_ADDRESS(&(tmp_dst), &(pinfo->dst));
if (pi->request_method == NULL) {
frame_label = g_strdup_printf("%u %s", pi->response_code, pi->reason_phrase );
comment = g_strdup("SIP Status");
if ((tmp_sipinfo && pi->tap_cseq_number == tmp_sipinfo->invite_cseq)&&(ADDRESSES_EQUAL(&tmp_dst,&(callsinfo->initial_speaker)))) {
if ((pi->response_code > 199) && (pi->response_code<300) && (tmp_sipinfo->sip_state == SIP_INVITE_SENT)) {
tmp_sipinfo->sip_state = SIP_200_REC;
}
else if ((pi->response_code>299)&&(tmp_sipinfo->sip_state == SIP_INVITE_SENT)) {
callsinfo->call_state = VOIP_REJECTED;
tapinfo->rejected_calls++;
}
}
}
else {
frame_label = g_strdup(pi->request_method);
if ((strcmp(pi->request_method,"INVITE")==0)&&(ADDRESSES_EQUAL(&tmp_src,&(callsinfo->initial_speaker)))) {
tmp_sipinfo->invite_cseq = pi->tap_cseq_number;
callsinfo->call_state = VOIP_CALL_SETUP;
comment = g_strdup_printf("SIP From: %s To:%s", callsinfo->from_identity, callsinfo->to_identity);
}
else if ((strcmp(pi->request_method,"ACK")==0)&&(pi->tap_cseq_number == tmp_sipinfo->invite_cseq)
&&(ADDRESSES_EQUAL(&tmp_src,&(callsinfo->initial_speaker)))&&(tmp_sipinfo->sip_state==SIP_200_REC)
&&(callsinfo->call_state == VOIP_CALL_SETUP)) {
callsinfo->call_state = VOIP_IN_CALL;
comment = g_strdup("SIP Request");
}
else if (strcmp(pi->request_method,"BYE")==0) {
callsinfo->call_state = VOIP_COMPLETED;
tapinfo->completed_calls++;
comment = g_strdup("SIP Request");
}
else if ((strcmp(pi->request_method,"CANCEL")==0)&&(pi->tap_cseq_number == tmp_sipinfo->invite_cseq)
&&(ADDRESSES_EQUAL(&tmp_src,&(callsinfo->initial_speaker)))&&(callsinfo->call_state==VOIP_CALL_SETUP)) {
callsinfo->call_state = VOIP_CANCELLED;
tmp_sipinfo->sip_state = SIP_CANCEL_SENT;
comment = g_strdup("SIP Request");
} else {
comment = g_strdup("SIP Request");
}
}
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
g_free(frame_label);
g_free((void *)tmp_src.data);
g_free((void *)tmp_dst.data);
/* add SDP info if apply */
if ( (sdp_summary != NULL) && (sdp_frame_num == pinfo->fd->num) ) {
append_to_frame_graph(tapinfo, pinfo->fd->num, sdp_summary, NULL);
g_free(sdp_summary);
sdp_summary = NULL;
}
}
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
voip_calls_tapinfo_t* voip_calls_get_info(void)
{
return &the_tapinfo_struct;
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_SIP_tap_listener=FALSE;
/****************************************************************************/
void
sip_calls_init_tap(void)
{
GString *error_string;
if(have_SIP_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("sip", &(the_tapinfo_struct.sip_dummy), NULL,
0,
voip_calls_dlg_reset,
SIPcalls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_SIP_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_sip_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.sip_dummy));
unprotect_thread_critical_region();
have_SIP_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for ISUP **********************************/
/****************************************************************************/
static guint32 mtp3_opc, mtp3_dpc;
static guint8 mtp3_ni;
static guint32 mtp3_frame_num;
/****************************************************************************/
/* whenever a isup_ packet is seen by the tap listener */
static int
isup_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *isup_info _U_)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
isup_calls_info_t *tmp_isupinfo;
gboolean found = FALSE;
gboolean forward = FALSE;
gboolean right_pair;
GList *list;
gchar *frame_label = NULL;
gchar *comment = NULL;
/*voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct; unused */
const isup_tap_rec_t *pi = isup_info;
/* check if the lower layer is MTP matching the frame number */
if (mtp3_frame_num != pinfo->fd->num) return 0;
/* check whether we already have a call with these parameters in the list */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
right_pair = TRUE;
tmp_listinfo=list->data;
if ((tmp_listinfo->protocol == VOIP_ISUP)&&(tmp_listinfo->call_active_state==VOIP_ACTIVE)) {
tmp_isupinfo = tmp_listinfo->prot_info;
if ((tmp_isupinfo->cic == pinfo->circuit_id)&&(tmp_isupinfo->ni == mtp3_ni)) {
if ((tmp_isupinfo->opc == mtp3_opc)&&(tmp_isupinfo->dpc == mtp3_dpc)) {
forward = TRUE;
} else if ((tmp_isupinfo->dpc == mtp3_opc)&&(tmp_isupinfo->opc == mtp3_dpc)) {
forward = FALSE;
} else {
right_pair = FALSE;
}
if (right_pair) {
/* if there is an IAM for a call that is not in setup state, that means the previous call in the same
cic is no longer active */
if (tmp_listinfo->call_state == VOIP_CALL_SETUP) {
found = TRUE;
} else if (pi->message_type != 1) {
found = TRUE;
} else {
tmp_listinfo->call_active_state=VOIP_INACTIVE;
}
}
if (found) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
}
list = g_list_next (list);
}
/* not in the list? then create a new entry if the message is IAM
-i.e. if this session is a call*/
if ((callsinfo==NULL) &&(pi->message_type==1)) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_UNKNOWN;
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_ISUP;
if (pi->calling_number!=NULL) {
callsinfo->from_identity=g_strdup(pi->calling_number);
}
if (pi->called_number!=NULL) {
callsinfo->to_identity=g_strdup(pi->called_number);
}
callsinfo->prot_info=g_malloc(sizeof(isup_calls_info_t));
callsinfo->free_prot_info = g_free;
tmp_isupinfo=callsinfo->prot_info;
tmp_isupinfo->opc = mtp3_opc;
tmp_isupinfo->dpc = mtp3_dpc;
tmp_isupinfo->ni = mtp3_ni;
tmp_isupinfo->cic = pinfo->circuit_id;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
if (callsinfo!=NULL) {
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
/* Let's analyze the call state */
frame_label = g_strdup(val_to_str_ext_const(pi->message_type, &isup_message_type_value_acro_ext, "Unknown"));
if (callsinfo->npackets == 1) { /* this is the first packet, that must be an IAM */
if ((pi->calling_number!=NULL)&&(pi->called_number !=NULL)) {
comment = g_strdup_printf("Call from %s to %s",
pi->calling_number, pi->called_number);
}
} else if (callsinfo->npackets == 2) { /* in the second packet we show the SPs */
if (forward) {
comment = g_strdup_printf("%i-%i -> %i-%i. Cic:%i",
mtp3_ni, mtp3_opc,
mtp3_ni, mtp3_dpc, pinfo->circuit_id);
} else {
comment = g_strdup_printf("%i-%i -> %i-%i. Cic:%i",
mtp3_ni, mtp3_dpc,
mtp3_ni, mtp3_opc, pinfo->circuit_id);
}
}
switch(pi->message_type) {
case 1: /* IAM */
callsinfo->call_state=VOIP_CALL_SETUP;
break;
case 7: /* CONNECT */
case 9: /* ANSWER */
callsinfo->call_state=VOIP_IN_CALL;
break;
case 12: /* RELEASE */
if (callsinfo->call_state==VOIP_CALL_SETUP) {
if (forward) {
callsinfo->call_state=VOIP_CANCELLED;
}
else {
callsinfo->call_state=VOIP_REJECTED;
tapinfo->rejected_calls++;
}
}
else if (callsinfo->call_state == VOIP_IN_CALL) {
callsinfo->call_state = VOIP_COMPLETED;
tapinfo->completed_calls++;
}
comment = g_strdup_printf("Cause %i - %s",
pi->cause_value,
val_to_str_ext_const(pi->cause_value, &q931_cause_code_vals_ext, "(Unknown)"));
break;
}
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
g_free(frame_label);
}
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
static gboolean have_isup_tap_listener=FALSE;
void
isup_calls_init_tap(void)
{
GString *error_string;
if(have_isup_tap_listener==FALSE)
{
error_string = register_tap_listener("isup", &(the_tapinfo_struct.isup_dummy),
NULL,
0,
voip_calls_dlg_reset,
isup_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_isup_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_isup_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.isup_dummy));
unprotect_thread_critical_region();
have_isup_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for MTP3 **********************************/
/****************************************************************************/
/****************************************************************************/
/* whenever a mtp3_ packet is seen by the tap listener */
static int
mtp3_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *mtp3_info _U_)
{
const mtp3_tap_rec_t *pi = mtp3_info;
/* keep the data in memory to use when the ISUP information arrives */
mtp3_opc = pi->addr_opc.pc;
mtp3_dpc = pi->addr_dpc.pc;
mtp3_ni = pi->addr_opc.ni;
mtp3_frame_num = pinfo->fd->num;
return 0;
}
/****************************************************************************/
static gboolean have_mtp3_tap_listener=FALSE;
static gboolean have_m3ua_tap_listener=FALSE;
void
mtp3_calls_init_tap(void)
{
GString *error_string;
if(have_mtp3_tap_listener==FALSE)
{
error_string = register_tap_listener("mtp3", &(the_tapinfo_struct.mtp3_dummy),
NULL,
0,
voip_calls_dlg_reset,
mtp3_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_mtp3_tap_listener=TRUE;
}
if(have_m3ua_tap_listener==FALSE)
{
error_string = register_tap_listener("m3ua", &(the_tapinfo_struct.mtp3_dummy),
NULL,
0,
voip_calls_dlg_reset,
mtp3_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_m3ua_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_mtp3_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.mtp3_dummy));
remove_tap_listener(&(the_tapinfo_struct.m3ua_dummy));
unprotect_thread_critical_region();
have_mtp3_tap_listener=FALSE;
have_m3ua_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for Q931 **********************************/
/****************************************************************************/
void h245_add_to_graph(guint32 new_frame_num);
static const e_guid_t guid_allzero = {0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
/* defines specific H323 data */
static gchar *q931_calling_number;
static gchar *q931_called_number;
static guint8 q931_cause_value;
static gint32 q931_crv;
static guint32 q931_frame_num;
static guint32 h225_frame_num = 0;
static guint16 h225_call_num = 0;
static h225_cs_type h225_cstype = H225_OTHER;
static gboolean h225_is_faststart;
static guint32 actrace_frame_num = 0;
static gint32 actrace_trunk = 0;
static gint32 actrace_direction = 0;
/****************************************************************************/
/* whenever a q931_ packet is seen by the tap listener */
static int
q931_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *q931_info)
{
GList *list,*list2;
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
h323_calls_info_t *tmp_h323info,*tmp2_h323info;
actrace_isdn_calls_info_t *tmp_actrace_isdn_info;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
h245_address_t *h245_add = NULL;
gchar *comment;
const q931_packet_info *pi = q931_info;
/* free previously allocated q931_calling/ed_number */
g_free(q931_calling_number);
g_free(q931_called_number);
if (pi->calling_number!=NULL)
q931_calling_number = g_strdup(pi->calling_number);
else
q931_calling_number = g_strdup("");
if (pi->called_number!=NULL)
q931_called_number = g_strdup(pi->called_number);
else
q931_called_number = g_strdup("");
q931_cause_value = pi->cause_value;
q931_frame_num = pinfo->fd->num;
q931_crv = pi->crv;
/* add staff to H323 calls */
if (h225_frame_num == q931_frame_num) {
tmp_h323info = NULL;
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if ( (tmp_listinfo->protocol == VOIP_H323) && (tmp_listinfo->call_num == h225_call_num) ) {
tmp_h323info = tmp_listinfo->prot_info;
callsinfo = (voip_calls_info_t*)(list->data);
/* Add the CRV to the h323 call */
if (tmp_h323info->q931_crv == -1) {
tmp_h323info->q931_crv = q931_crv;
} else if (tmp_h323info->q931_crv != q931_crv) {
tmp_h323info->q931_crv2 = q931_crv;
}
break;
}
list = g_list_next (list);
}
if (callsinfo != NULL) {
comment = NULL;
if (h225_cstype == H225_SETUP) {
/* set te calling and called number from the Q931 packet */
if (q931_calling_number != NULL) {
g_free(callsinfo->from_identity);
callsinfo->from_identity=g_strdup(q931_calling_number);
}
if (q931_called_number != NULL) {
g_free(callsinfo->to_identity);
callsinfo->to_identity=g_strdup(q931_called_number);
}
/* check if there is an LRQ/LCF that match this Setup */
/* TODO: we are just checking the DialedNumer in LRQ/LCF agains the Setup
we should also check if the h225 signaling IP and port match the destination
Setup ip and port */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if (tmp_listinfo->protocol == VOIP_H323) {
tmp2_h323info = tmp_listinfo->prot_info;
/* check if the called number match a LRQ/LCF */
if ( (strcmp(callsinfo->to_identity, tmp_listinfo->to_identity)==0)
&& (memcmp(&tmp2_h323info->guid, &guid_allzero, GUID_LEN) == 0) ) {
/* change the call graph to the LRQ/LCF to belong to this call */
callsinfo->npackets += change_call_num_graph(tapinfo, tmp_listinfo->call_num, callsinfo->call_num);
/* remove this LRQ/LCF call entry because we have found the Setup that match them */
g_free(tmp_listinfo->from_identity);
g_free(tmp_listinfo->to_identity);
g_free(tmp2_h323info->guid);
list2 = g_list_first(tmp2_h323info->h245_list);
while (list2)
{
h245_add=list2->data;
g_free((void *)h245_add->h245_address.data);
g_free(list2->data);
list2 = g_list_next(list2);
}
g_list_free(tmp_h323info->h245_list);
tmp_h323info->h245_list = NULL;
g_free(tmp_listinfo->prot_info);
tapinfo->callsinfo_list = g_list_remove(tapinfo->callsinfo_list, tmp_listinfo);
break;
}
}
list = g_list_next (list);
}
comment = g_strdup_printf("H225 From: %s To:%s TunnH245:%s FS:%s", callsinfo->from_identity, callsinfo->to_identity, (tmp_h323info->is_h245Tunneling==TRUE?"on":"off"),
(h225_is_faststart==TRUE?"on":"off"));
} else if (h225_cstype == H225_RELEASE_COMPLET) {
/* get the Q931 Release cause code */
if (q931_cause_value != 0xFF) {
comment = g_strdup_printf("H225 Q931 Rel Cause (%i):%s", q931_cause_value,
val_to_str_ext_const(q931_cause_value, &q931_cause_code_vals_ext, "<unknown>"));
} else { /* Cause not set */
comment = g_strdup("H225 No Q931 Rel Cause");
}
}
/* change the graph comment for this new one */
if (comment != NULL) {
change_frame_graph(tapinfo, h225_frame_num, NULL, comment);
g_free(comment);
}
}
/* we reset the h225_frame_num to 0 because there could be empty h225 in the same frame
as non empty h225 (e.g connect), so we don't have to be here twice */
h225_frame_num = 0;
/* add staff to H245 */
} else if (h245_labels.frame_num == q931_frame_num) {
/* there are empty H225 frames that don't have guid (guaid=0) but they have h245 info,
so the only way to match those frames is with the Q931 CRV number */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if (tmp_listinfo->protocol == VOIP_H323) {
tmp_h323info = tmp_listinfo->prot_info;
if ( ((tmp_h323info->q931_crv == q931_crv) || (tmp_h323info->q931_crv2 == q931_crv)) && (q931_crv!=-1)) {
/* if the frame number exists in graph, append to it*/
if (!append_to_frame_graph(tapinfo, q931_frame_num, NULL, NULL)) {
/* if not exist, add to the graph */
add_to_graph(tapinfo, pinfo, NULL, NULL, tmp_listinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
++(tmp_listinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
}
/* Add the H245 info if exists to the Graph */
h245_add_to_graph(pinfo->fd->num);
break;
}
}
list = g_list_next (list);
}
/* add staff to ACTRACE */
} else if (actrace_frame_num == q931_frame_num) {
address pstn_add;
comment = NULL;
callsinfo = NULL;
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if ( tmp_listinfo->protocol == VOIP_AC_ISDN ) {
tmp_actrace_isdn_info = tmp_listinfo->prot_info;
/* TODO: Also check the IP of the Blade, and if the call is complete (no active) */
if ( (tmp_actrace_isdn_info->crv == q931_crv) && (tmp_actrace_isdn_info->trunk == actrace_trunk) ) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
SET_ADDRESS(&pstn_add, AT_STRINGZ, 5, g_strdup("PSTN"));
/* if it is a new call, add it to the list */
if (!callsinfo) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup(q931_calling_number);
callsinfo->to_identity=g_strdup(q931_called_number);
COPY_ADDRESS(&(callsinfo->initial_speaker),actrace_direction?&pstn_add:&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_AC_ISDN;
callsinfo->prot_info=g_malloc(sizeof(actrace_isdn_calls_info_t));
callsinfo->free_prot_info = g_free;
tmp_actrace_isdn_info=callsinfo->prot_info;
tmp_actrace_isdn_info->crv=q931_crv;
tmp_actrace_isdn_info->trunk=actrace_trunk;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
switch(pi->message_type) {
case Q931_SETUP:
comment = g_strdup_printf("AC_ISDN trunk:%u Calling: %s Called:%s", actrace_trunk, q931_calling_number, q931_called_number);
callsinfo->call_state=VOIP_CALL_SETUP;
break;
case Q931_CONNECT:
callsinfo->call_state=VOIP_IN_CALL;
break;
case Q931_RELEASE_COMPLETE:
case Q931_RELEASE:
case Q931_DISCONNECT:
if (callsinfo->call_state==VOIP_CALL_SETUP) {
if (ADDRESSES_EQUAL(&(callsinfo->initial_speaker), actrace_direction?&pstn_add:&(pinfo->src) )) { /* forward direction */
callsinfo->call_state=VOIP_CANCELLED;
}
else { /* reverse */
callsinfo->call_state=VOIP_REJECTED;
tapinfo->rejected_calls++;
}
} else if ( (callsinfo->call_state!=VOIP_CANCELLED) && (callsinfo->call_state!=VOIP_REJECTED) ) {
callsinfo->call_state=VOIP_COMPLETED;
tapinfo->completed_calls++;
}
if (q931_cause_value != 0xFF) {
comment = g_strdup_printf("AC_ISDN trunk:%u Q931 Rel Cause (%i):%s", actrace_trunk, q931_cause_value,
val_to_str_ext_const(q931_cause_value, &q931_cause_code_vals_ext, "<unknown>"));
} else { /* Cause not set */
comment = g_strdup("AC_ISDN No Q931 Rel Cause");
}
break;
}
if (!comment)
comment = g_strdup_printf("AC_ISDN trunk:%u", actrace_trunk );
add_to_graph(tapinfo, pinfo, val_to_str(pi->message_type, q931_message_type_vals, "<unknown>") , comment, callsinfo->call_num,
actrace_direction?&pstn_add:&(pinfo->src),
actrace_direction?&(pinfo->src):&pstn_add,
1 );
g_free(comment);
g_free((char *)pstn_add.data);
}
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
static gboolean have_q931_tap_listener=FALSE;
void
q931_calls_init_tap(void)
{
GString *error_string;
if(have_q931_tap_listener==FALSE)
{
error_string = register_tap_listener("q931", &(the_tapinfo_struct.q931_dummy),
NULL,
0,
voip_calls_dlg_reset,
q931_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_q931_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_q931_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.q931_dummy));
unprotect_thread_critical_region();
have_q931_tap_listener=FALSE;
}
/****************************************************************************/
/****************************TAP for H323 ***********************************/
/****************************************************************************/
static void add_h245_Address(h323_calls_info_t *h323info, h245_address_t *h245_address)
{
h323info->h245_list = g_list_prepend(h323info->h245_list, h245_address);
}
static void free_h225_info(gpointer p) {
h323_calls_info_t *tmp_h323info = p;
g_free(tmp_h323info->guid);
if (tmp_h323info->h245_list) {
GList *list2 = g_list_first(tmp_h323info->h245_list);
while (list2)
{
h245_address_t *h245_add=list2->data;
g_free((void *)h245_add->h245_address.data);
g_free(list2->data);
list2 = g_list_next(list2);
}
g_list_free(tmp_h323info->h245_list);
}
g_free(p);
}
/****************************************************************************/
/* whenever a H225 packet is seen by the tap listener */
static int
H225calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *H225info)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
h323_calls_info_t *tmp_h323info = NULL;
gchar *frame_label;
gchar *comment;
GList *list;
h245_address_t *h245_add = NULL;
const h225_packet_info *pi = H225info;
/* if not guid and RAS and not LRQ, LCF or LRJ return because did not belong to a call */
/* OR, if not guid and is H225 return because doesn't belong to a call */
if ((memcmp(&pi->guid, &guid_allzero, GUID_LEN) == 0))
if ( ((pi->msg_type == H225_RAS) && ((pi->msg_tag < 18) || (pi->msg_tag > 20))) || (pi->msg_type != H225_RAS) )
return 0;
/* if it is RAS LCF or LRJ*/
if ( (pi->msg_type == H225_RAS) && ((pi->msg_tag == 19) || (pi->msg_tag == 20))) {
/* if the LCF/LRJ doesn't match to a LRQ, just return */
if (!pi->request_available) return 0;
/* check whether we already have a call with this request SeqNum */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
g_assert(tmp_listinfo != NULL);
if (tmp_listinfo->protocol == VOIP_H323) {
tmp_h323info = tmp_listinfo->prot_info;
if (tmp_h323info->requestSeqNum == pi->requestSeqNum) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
} else {
/* check whether we already have a call with this guid in the list */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if (tmp_listinfo->protocol == VOIP_H323) {
tmp_h323info = tmp_listinfo->prot_info;
g_assert(tmp_h323info != NULL);
if ( (memcmp(tmp_h323info->guid, &guid_allzero, GUID_LEN) != 0) && (memcmp(tmp_h323info->guid, &pi->guid,GUID_LEN)==0) ) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
}
h225_cstype = pi->cs_type;
h225_is_faststart = pi->is_faststart;
/* not in the list? then create a new entry */
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_UNKNOWN;
callsinfo->from_identity=g_strdup("");
callsinfo->to_identity=g_strdup("");
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_H323;
callsinfo->prot_info=g_malloc(sizeof(h323_calls_info_t));
callsinfo->free_prot_info = free_h225_info;
tmp_h323info = callsinfo->prot_info;
g_assert(tmp_h323info != NULL);
tmp_h323info->guid = g_memdup(&pi->guid, sizeof pi->guid);
tmp_h323info->h225SetupAddr.type = AT_NONE;
tmp_h323info->h225SetupAddr.len = 0;
tmp_h323info->h245_list = NULL;
tmp_h323info->is_faststart_Setup = FALSE;
tmp_h323info->is_faststart_Proc = FALSE;
tmp_h323info->is_h245Tunneling = FALSE;
tmp_h323info->is_h245 = FALSE;
tmp_h323info->q931_crv = -1;
tmp_h323info->q931_crv2 = -1;
tmp_h323info->requestSeqNum = 0;
callsinfo->call_num = tapinfo->ncalls++;
callsinfo->npackets = 0;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
h225_frame_num = pinfo->fd->num;
h225_call_num = callsinfo->call_num;
/* let's analyze the call state */
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* XXX: it is supposed to be initialized isn't it? */
g_assert(tmp_h323info != NULL);
/* change the status */
if (pi->msg_type == H225_CS) {
/* this is still IPv4 only, because the dissector is */
if (pi->is_h245 == TRUE) {
h245_add = g_malloc(sizeof (h245_address_t));
h245_add->h245_address.type=AT_IPv4;
h245_add->h245_address.len=4;
h245_add->h245_address.data = g_malloc(sizeof(pi->h245_address));
memcpy((void *)(h245_add->h245_address.data), &(pi->h245_address), 4);
h245_add->h245_port = pi->h245_port;
add_h245_Address(tmp_h323info, h245_add);
}
if (pi->cs_type != H225_RELEASE_COMPLET) tmp_h323info->is_h245Tunneling = pi->is_h245Tunneling;
frame_label = g_strdup(pi->frame_label);
switch(pi->cs_type) {
case H225_SETUP:
tmp_h323info->is_faststart_Setup = pi->is_faststart;
/* Set the Setup address if it was not set */
if (tmp_h323info->h225SetupAddr.type == AT_NONE)
COPY_ADDRESS(&(tmp_h323info->h225SetupAddr), &(pinfo->src));
callsinfo->call_state=VOIP_CALL_SETUP;
comment = g_strdup_printf("H225 TunnH245:%s FS:%s", (tmp_h323info->is_h245Tunneling==TRUE?"on":"off"),
(pi->is_faststart==TRUE?"on":"off"));
break;
case H225_CONNECT:
callsinfo->call_state=VOIP_IN_CALL;
if (pi->is_faststart == TRUE) tmp_h323info->is_faststart_Proc = TRUE;
comment = g_strdup_printf("H225 TunnH245:%s FS:%s", (tmp_h323info->is_h245Tunneling==TRUE?"on":"off"),
(pi->is_faststart==TRUE?"on":"off"));
break;
case H225_RELEASE_COMPLET:
if (callsinfo->call_state==VOIP_CALL_SETUP) {
if (ADDRESSES_EQUAL(&(tmp_h323info->h225SetupAddr),&(pinfo->src))) { /* forward direction */
callsinfo->call_state=VOIP_CANCELLED;
}
else { /* reverse */
callsinfo->call_state=VOIP_REJECTED;
tapinfo->rejected_calls++;
}
} else {
callsinfo->call_state=VOIP_COMPLETED;
tapinfo->completed_calls++;
}
comment = g_strdup("H225 No Q931 Rel Cause");
break;
case H225_PROGRESS:
case H225_ALERTING:
case H225_CALL_PROCEDING:
if (pi->is_faststart == TRUE) tmp_h323info->is_faststart_Proc = TRUE;
comment = g_strdup_printf("H225 TunnH245:%s FS:%s", (tmp_h323info->is_h245Tunneling==TRUE?"on":"off"),
(pi->is_faststart==TRUE?"on":"off"));
break;
default:
comment = g_strdup_printf("H225 TunnH245:%s FS:%s", (tmp_h323info->is_h245Tunneling==TRUE?"on":"off"),
(pi->is_faststart==TRUE?"on":"off"));
}
}
else if (pi->msg_type == H225_RAS) {
switch(pi->msg_tag) {
case 18: /* LRQ */
if (!pi->is_duplicate) {
g_free(callsinfo->to_identity);
callsinfo->to_identity=g_strdup(pi->dialedDigits);
tmp_h323info->requestSeqNum = pi->requestSeqNum;
}
case 19: /* LCF */
if (strlen(pi->dialedDigits))
comment = g_strdup_printf("H225 RAS dialedDigits: %s", pi->dialedDigits);
else
comment = g_strdup("H225 RAS");
break;
default:
comment = g_strdup("H225 RAS");
}
frame_label = g_strdup(val_to_str_const(pi->msg_tag, h225_RasMessage_vals, "<unknown>"));
} else {
frame_label = g_strdup("H225: Unknown");
comment = NULL;
}
/* add to graph analysis */
/* if the frame number exists in graph, append to it*/
if (!append_to_frame_graph(tapinfo, pinfo->fd->num, pi->frame_label, comment)) {
/* if not exist, add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
}
/* Add the H245 info if exists to the Graph */
h245_add_to_graph(pinfo->fd->num);
g_free(frame_label);
g_free(comment);
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_H225_tap_listener=FALSE;
/****************************************************************************/
void
h225_calls_init_tap(void)
{
GString *error_string;
if(have_H225_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("h225", &(the_tapinfo_struct.h225_dummy), NULL,
0,
voip_calls_dlg_reset,
H225calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_H225_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_h225_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.h225_dummy));
unprotect_thread_critical_region();
have_H225_tap_listener=FALSE;
}
/* Add the h245 label info to the graph */
void h245_add_to_graph(guint32 new_frame_num)
{
gint8 n;
if (new_frame_num != h245_labels.frame_num) return;
for (n=0; n<h245_labels.labels_count; n++) {
append_to_frame_graph(&the_tapinfo_struct, new_frame_num, h245_labels.labels[n].frame_label, h245_labels.labels[n].comment);
g_free(h245_labels.labels[n].frame_label);
h245_labels.labels[n].frame_label = NULL;
g_free(h245_labels.labels[n].comment);
h245_labels.labels[n].comment = NULL;
}
h245_labels.frame_num = 0;
h245_labels.labels_count = 0;
}
/* free the h245_labels if the frame number is different */
static void h245_free_labels(guint32 new_frame_num)
{
gint8 n;
if (new_frame_num == h245_labels.frame_num) return;
for (n=0; n<h245_labels.labels_count; n++) {
g_free(h245_labels.labels[n].frame_label);
h245_labels.labels[n].frame_label = NULL;
g_free(h245_labels.labels[n].comment);
h245_labels.labels[n].comment = NULL;
}
h245_labels.frame_num = 0;
h245_labels.labels_count = 0;
}
/* add the frame_label and comment to h245_labels and free the actual one if it is different frame num */
static void h245_add_label(guint32 new_frame_num, const gchar *frame_label, const gchar *comment)
{
h245_free_labels(new_frame_num);
h245_labels.frame_num = new_frame_num;
h245_labels.labels[h245_labels.labels_count].frame_label = g_strdup(frame_label);
h245_labels.labels[h245_labels.labels_count].comment = g_strdup(comment);
if (h245_labels.labels_count < (H245_MAX-1))
h245_labels.labels_count++;
}
/****************************************************************************/
/* whenever a H245dg packet is seen by the tap listener (when H245 tunneling is ON) */
static int
H245dgcalls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *H245info)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
h323_calls_info_t *tmp_h323info;
GList *list;
GList *list2;
h245_address_t *h245_add = NULL;
const h245_packet_info *pi = H245info;
/* check if Tunneling is OFF and we have a call with this H245 add */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if (tmp_listinfo->protocol == VOIP_H323) {
tmp_h323info = tmp_listinfo->prot_info;
list2 = g_list_first(tmp_h323info->h245_list);
while (list2)
{
h245_add=list2->data;
if ( (ADDRESSES_EQUAL(&(h245_add->h245_address),&(pinfo->src)) && (h245_add->h245_port == pinfo->srcport))
|| (ADDRESSES_EQUAL(&(h245_add->h245_address),&(pinfo->dst)) && (h245_add->h245_port == pinfo->destport)) ) {
callsinfo = (voip_calls_info_t*)(list->data);
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
break;
}
list2 = g_list_next(list2);
}
if (callsinfo!=NULL) break;
}
list = g_list_next(list);
}
/* Tunnel is OFF, and we matched the h245 add so we add it to graph */
if (callsinfo!=NULL) {
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* if the frame number exists in graph, append to it*/
if (!append_to_frame_graph(tapinfo, pinfo->fd->num, pi->frame_label, pi->comment)) {
/* if not exist, add to the graph */
add_to_graph(tapinfo, pinfo, pi->frame_label, pi->comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
}
} else {
/* Tunnel is ON, so we save the label info to use it into h225 or q931 tap. OR may be
tunnel OFF but we did not matched the h245 add, in this case nobady will set this label
since the frame_num will not match */
h245_add_label(pinfo->fd->num, (gchar *) pi->frame_label, (gchar *) pi->comment);
}
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_H245dg_tap_listener=FALSE;
/****************************************************************************/
void
h245dg_calls_init_tap(void)
{
GString *error_string;
if(have_H245dg_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("h245dg", &(the_tapinfo_struct.h245dg_dummy), NULL,
0,
voip_calls_dlg_reset,
H245dgcalls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_H245dg_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_h245dg_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.h245dg_dummy));
unprotect_thread_critical_region();
have_H245dg_tap_listener=FALSE;
}
/****************************************************************************/
/****************************TAP for SDP PROTOCOL ***************************/
/****************************************************************************/
/* whenever a SDP packet is seen by the tap listener */
static int
SDPcalls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *SDPinfo)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
const sdp_packet_info *pi = SDPinfo;
/* There are protocols like MGCP/SIP where the SDP is called before the tap for the
MGCP/SIP packet, in those cases we assign the SPD summary to global lastSDPsummary
to use it later
*/
g_free(sdp_summary);
sdp_frame_num = pinfo->fd->num;
/* Append to graph the SDP summary if the packet exists */
sdp_summary = g_strdup_printf("SDP (%s)", pi->summary_str);
append_to_frame_graph(tapinfo, pinfo->fd->num, sdp_summary, NULL);
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_sdp_tap_listener=FALSE;
/****************************************************************************/
void
sdp_calls_init_tap(void)
{
GString *error_string;
if(have_sdp_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("sdp", &(the_tapinfo_struct.sdp_dummy), NULL,
0,
voip_calls_dlg_reset,
SDPcalls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_sdp_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_sdp_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.sdp_dummy));
unprotect_thread_critical_region();
have_sdp_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for MGCP **********************************/
/****************************************************************************/
/*
This function will look for a signal/event in the SignalReq/ObsEvent string
and return true if it is found
*/
static gboolean isSignal(const gchar *signal_str_p, const gchar *signalStr)
{
gint i;
gchar **resultArray;
/* if there is no signalStr, just return false */
if (signalStr == NULL) return FALSE;
/* if are both "blank" return true */
if ( (*signal_str_p == '\0') && (*signalStr == '\0') ) return TRUE;
/* look for signal in signalStr */
resultArray = g_strsplit(signalStr, ",", 10);
for (i = 0; resultArray[i]; i++) {
g_strstrip(resultArray[i]);
if (strcmp(resultArray[i], signal_str_p) == 0) return TRUE;
}
g_strfreev(resultArray);
return FALSE;
}
/*
This function will get the Caller ID info and replace the current string
This is how it looks the caller Id: rg, ci(02/16/08/29, "3035550002","Ale Sipura 2")
*/
static void mgcpCallerID(gchar *signalStr, gchar **callerId)
{
gchar **arrayStr;
/* if there is no signalStr, just return false */
if (signalStr == NULL) return;
arrayStr = g_strsplit(signalStr, "\"", 10);
if (arrayStr[0] == NULL) return;
/* look for the ci signal */
if (strstr(arrayStr[0], "ci(") && (arrayStr[1] != NULL) ) {
/* free the previous "From" field of the call, and assign the new */
g_free(*callerId);
*callerId = g_strdup(arrayStr[1]);
}
g_strfreev(arrayStr);
return;
}
/*
This function will get the Dialed Digits and replace the current string
This is how it looks the dialed digits 5,5,5,0,0,0,2,#,*
*/
static void mgcpDialedDigits(gchar *signalStr, gchar **dialedDigits)
{
gchar *tmpStr;
gchar resultStr[50];
gint i,j;
/* if there is no signalStr, just return false */
if (signalStr == NULL) return;
tmpStr = g_strdup(signalStr);
for ( i = 0 ; tmpStr[i] ; i++) {
switch (tmpStr[i]) {
case '0' : case '1' : case '2' : case '3' : case '4' :
case '5' : case '6' : case '7' : case '8' : case '9' :
case '#' : case '*' :
break;
default:
tmpStr[i] = '?';
break;
}
}
for (i = 0, j = 0; tmpStr[i] && i<50; i++) {
if (tmpStr[i] != '?')
resultStr[j++] = tmpStr[i];
}
resultStr[j] = '\0';
if (*resultStr == '\0') {
g_free(tmpStr);
return;
}
g_free(*dialedDigits);
*dialedDigits = g_strdup(resultStr);
g_free(tmpStr);
return;
}
/****************************************************************************/
/* whenever a MGCP packet is seen by the tap listener */
static int
MGCPcalls_packet( void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *MGCPinfo)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
mgcp_calls_info_t *tmp_mgcpinfo = NULL;
GList *list;
GList *listGraph;
gchar *frame_label = NULL;
gchar *comment = NULL;
graph_analysis_item_t *gai;
gboolean new = FALSE;
gboolean fromEndpoint = FALSE; /* true for calls originated in Endpoints, false for calls from MGC */
gdouble diff_time;
const mgcp_info_t *pi = MGCPinfo;
if ((pi->mgcp_type == MGCP_REQUEST) && !pi->is_duplicate ) {
/* check whether we already have a call with this Endpoint and it is active*/
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if ((tmp_listinfo->protocol == VOIP_MGCP) && (tmp_listinfo->call_active_state == VOIP_ACTIVE)) {
tmp_mgcpinfo = tmp_listinfo->prot_info;
if (pi->endpointId != NULL) {
if (g_ascii_strcasecmp(tmp_mgcpinfo->endpointId,pi->endpointId) == 0) {
/*
check first if it is an ended call. We can still match packets to this Endpoint 2 seconds
after the call has been released
*/
diff_time = nstime_to_sec(&pinfo->fd->rel_ts) - nstime_to_sec(&tmp_listinfo->stop_fd->rel_ts);
if ( ((tmp_listinfo->call_state == VOIP_CANCELLED) ||
(tmp_listinfo->call_state == VOIP_COMPLETED) ||
(tmp_listinfo->call_state == VOIP_REJECTED)) &&
(diff_time > 2) )
{
tmp_listinfo->call_active_state = VOIP_INACTIVE;
} else {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
}
}
list = g_list_next (list);
}
/* there is no call with this Endpoint, lets see if this a new call or not */
if (callsinfo == NULL) {
if ( (strcmp(pi->code, "NTFY") == 0) && isSignal("hd", pi->observedEvents) ) { /* off hook transition */
/* this is a new call from the Endpoint */
fromEndpoint = TRUE;
new = TRUE;
} else if (strcmp(pi->code, "CRCX") == 0) {
/* this is a new call from the MGC */
fromEndpoint = FALSE;
new = TRUE;
}
if (!new) return 0;
}
} else if ( ((pi->mgcp_type == MGCP_RESPONSE) && pi->request_available) ||
((pi->mgcp_type == MGCP_REQUEST) && pi->is_duplicate) ) {
/* if it is a response OR if it is a duplicated Request, lets look in the Graph to see
if there is a request that matches */
listGraph = g_list_first(tapinfo->graph_analysis->list);
while (listGraph)
{
gai = listGraph->data;
if (gai->fd->num == pi->req_num) {
/* there is a request that match, so look the associated call with this call_num */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if (tmp_listinfo->protocol == VOIP_MGCP) {
if (tmp_listinfo->call_num == gai->conv_num) {
tmp_mgcpinfo = tmp_listinfo->prot_info;
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
if (callsinfo != NULL) break;
}
listGraph = g_list_next(listGraph);
}
/* if there is not a matching request, just return */
if (callsinfo == NULL) return 0;
} else return 0;
/* not in the list? then create a new entry */
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
if (fromEndpoint) {
callsinfo->from_identity=g_strdup(pi->endpointId);
callsinfo->to_identity=g_strdup("");
} else {
callsinfo->from_identity=g_strdup("");
callsinfo->to_identity=g_strdup(pi->endpointId);
}
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_MGCP;
callsinfo->prot_info=g_malloc(sizeof(mgcp_calls_info_t));
callsinfo->free_prot_info = g_free;
tmp_mgcpinfo=callsinfo->prot_info;
tmp_mgcpinfo->endpointId = g_strdup(pi->endpointId);
tmp_mgcpinfo->fromEndpoint = fromEndpoint;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
g_assert(tmp_mgcpinfo != NULL);
/* change call state and add to graph */
switch (pi->mgcp_type)
{
case MGCP_REQUEST:
if ( (strcmp(pi->code, "NTFY") == 0) && (pi->observedEvents != NULL) ) {
frame_label = g_strdup_printf("%s ObsEvt:%s",pi->code, pi->observedEvents);
if (tmp_mgcpinfo->fromEndpoint) {
/* use the Dialed digits to fill the "To" for the call, but use the first NTFY */
if (callsinfo->to_identity[0] == '\0') mgcpDialedDigits(pi->observedEvents, &(callsinfo->to_identity));
/* from MGC and the user picked up, the call is connected */
} else if (isSignal("hd", pi->observedEvents))
callsinfo->call_state=VOIP_IN_CALL;
/* hung up signal */
if (isSignal("hu", pi->observedEvents)) {
if ((callsinfo->call_state == VOIP_CALL_SETUP) || (callsinfo->call_state == VOIP_RINGING)) {
callsinfo->call_state = VOIP_CANCELLED;
} else {
callsinfo->call_state = VOIP_COMPLETED;
}
}
} else if (strcmp(pi->code, "RQNT") == 0) {
/* for calls from Endpoint: if there is a "no signal" RQNT and the call was RINGING, we assume this is the CONNECT */
if ( tmp_mgcpinfo->fromEndpoint && isSignal("", pi->signalReq) && (callsinfo->call_state == VOIP_RINGING) ) {
callsinfo->call_state = VOIP_IN_CALL;
}
/* if there is ringback or ring tone, change state to ringing */
if ( isSignal("rg", pi->signalReq) || isSignal("rt", pi->signalReq) ) {
callsinfo->call_state = VOIP_RINGING;
}
/* if there is a Busy or ReorderTone, and the call was Ringing or Setup the call is Rejected */
if ( (isSignal("ro", pi->signalReq) || isSignal("bz", pi->signalReq)) && ((callsinfo->call_state == VOIP_CALL_SETUP) || (callsinfo->call_state == VOIP_RINGING)) ) {
callsinfo->call_state = VOIP_REJECTED;
}
if (pi->signalReq != NULL)
frame_label = g_strdup_printf("%s%sSigReq:%s",pi->code, (pi->hasDigitMap == TRUE)?" DigitMap ":"", pi->signalReq);
else
frame_label = g_strdup_printf("%s%s",pi->code, (pi->hasDigitMap == TRUE)?" DigitMap ":"");
/* use the CallerID info to fill the "From" for the call */
if (!tmp_mgcpinfo->fromEndpoint) mgcpCallerID(pi->signalReq, &(callsinfo->from_identity));
} else if (strcmp(pi->code, "DLCX") == 0) {
/*
if there is a DLCX in a call To an Endpoint and the call was not connected, we use
the DLCX as the end of the call
*/
if (!tmp_mgcpinfo->fromEndpoint) {
if ((callsinfo->call_state == VOIP_CALL_SETUP) || (callsinfo->call_state == VOIP_RINGING)) {
callsinfo->call_state = VOIP_CANCELLED;
}
}
}
if (frame_label == NULL) frame_label = g_strdup(pi->code);
break;
case MGCP_RESPONSE:
frame_label = g_strdup_printf("%u (%s)",pi->rspcode, pi->code);
break;
case MGCP_OTHERS:
/* XXX what to do? */
break;
}
comment = g_strdup_printf("MGCP %s %s%s", tmp_mgcpinfo->endpointId, (pi->mgcp_type == MGCP_REQUEST)?"Request":"Response", pi->is_duplicate?" Duplicate":"");
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
g_free(frame_label);
/* add SDP info if apply */
if ( (sdp_summary != NULL) && (sdp_frame_num == pinfo->fd->num) ) {
append_to_frame_graph(tapinfo, pinfo->fd->num, sdp_summary, NULL);
g_free(sdp_summary);
sdp_summary = NULL;
}
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_MGCP_tap_listener=FALSE;
/****************************************************************************/
void
mgcp_calls_init_tap(void)
{
GString *error_string;
if(have_MGCP_tap_listener==FALSE)
{
/*
* Don't register the tap listener if we have it already.
* We set TL_REQUIRES_PROTO_TREE to force a non-null "tree"
* in the MGCP dissector; otherwise, the dissector
* doesn't fill in the info passed to the tap's packet
* routine.
*/
error_string = register_tap_listener("mgcp",
&(the_tapinfo_struct.mgcp_dummy),
NULL,
TL_REQUIRES_PROTO_TREE,
voip_calls_dlg_reset,
MGCPcalls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_MGCP_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_mgcp_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.mgcp_dummy));
unprotect_thread_critical_region();
have_MGCP_tap_listener=FALSE;
}
/****************************************************************************/
/****************************TAP for ACTRACE (AudioCodes trace)**************/
/****************************************************************************/
/* whenever a ACTRACE packet is seen by the tap listener */
static int
ACTRACEcalls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *ACTRACEinfo)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
const actrace_info_t *pi = ACTRACEinfo;
GList *list;
actrace_cas_calls_info_t *tmp_actrace_cas_info;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
actrace_frame_num = pinfo->fd->num;
actrace_trunk = pi->trunk;
actrace_direction = pi->direction;
if (pi->type == 1) { /* is CAS protocol */
address pstn_add;
gchar *comment = NULL;
callsinfo = NULL;
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
tmp_listinfo=list->data;
if ( tmp_listinfo->protocol == VOIP_AC_CAS ) {
tmp_actrace_cas_info = tmp_listinfo->prot_info;
/* TODO: Also check the IP of the Blade, and if the call is complete (no active) */
if ( (tmp_actrace_cas_info->bchannel == pi->cas_bchannel) && (tmp_actrace_cas_info->trunk == actrace_trunk) ) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
SET_ADDRESS(&pstn_add, AT_STRINGZ, 5, "PSTN");
/* if it is a new call, add it to the list */
if (!callsinfo) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup("N/A");
callsinfo->to_identity=g_strdup("N/A");
COPY_ADDRESS(&(callsinfo->initial_speaker),actrace_direction?&pstn_add:&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_AC_CAS;
callsinfo->prot_info=g_malloc(sizeof(actrace_cas_calls_info_t));
callsinfo->free_prot_info = g_free;
tmp_actrace_cas_info=callsinfo->prot_info;
tmp_actrace_cas_info->bchannel=pi->cas_bchannel;
tmp_actrace_cas_info->trunk=actrace_trunk;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
comment = g_strdup_printf("AC_CAS trunk:%u", actrace_trunk);
add_to_graph(tapinfo, pinfo, pi->cas_frame_label, comment, callsinfo->call_num,
actrace_direction?&pstn_add:&(pinfo->src),
actrace_direction?&(pinfo->src):&pstn_add,
1 );
g_free(comment);
}
tapinfo->redraw = TRUE;
return 1; /* refresh output */
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_actrace_tap_listener=FALSE;
/****************************************************************************/
void
actrace_calls_init_tap(void)
{
GString *error_string;
if(have_actrace_tap_listener==FALSE)
{
/* don't register tap listener, if we have it already */
error_string = register_tap_listener("actrace", &(the_tapinfo_struct.actrace_dummy), NULL,
0,
voip_calls_dlg_reset,
ACTRACEcalls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_actrace_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_actrace_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.actrace_dummy));
unprotect_thread_critical_region();
have_actrace_tap_listener=FALSE;
}
/****************************************************************************/
/**************************** TAP for H248/MEGACO **********************************/
/****************************************************************************/
static gboolean have_h248_tap_listener = FALSE;
static gboolean have_megaco_tap_listener = FALSE;
#define gcp_is_req(type) ( type == GCP_CMD_ADD_REQ || type == GCP_CMD_MOVE_REQ || type == GCP_CMD_MOD_REQ || \
type == GCP_CMD_SUB_REQ || type == GCP_CMD_AUDITCAP_REQ || type == GCP_CMD_AUDITVAL_REQ || \
type == GCP_CMD_NOTIFY_REQ || type == GCP_CMD_SVCCHG_REQ || type == GCP_CMD_TOPOLOGY_REQ || \
type == GCP_CMD_CTX_ATTR_AUDIT_REQ )
static int h248_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prot_info) {
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
const gcp_cmd_t *cmd = prot_info;
GList *list;
voip_calls_info_t *callsinfo = NULL;
address *mgw;
address *mgc;
gchar mgw_addr[128];
if (cmd->ctx->id == NULL_CONTEXT || cmd->ctx->id == ALL_CONTEXTS ) {
return 0;
}
if ( gcp_is_req(cmd->type) ) {
mgw = &(pinfo->dst);
mgc = &(pinfo->src);
} else {
mgc = &(pinfo->dst);
mgw = &(pinfo->src);
}
address_to_str_buf(mgw, mgw_addr, 128);
/* check whether we already have this context in the list */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
voip_calls_info_t* tmp_listinfo = list->data;
if (tmp_listinfo->protocol == TEL_H248) {
if (tmp_listinfo->prot_info == cmd->ctx) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_state = VOIP_NO_STATE;
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->from_identity = g_strdup_printf("%s : %.8x", mgw_addr, cmd->ctx->id);
callsinfo->to_identity = g_strdup("");
callsinfo->prot_info = cmd->ctx;
callsinfo->free_prot_info = NULL;
callsinfo->npackets = 1;
COPY_ADDRESS(&(callsinfo->initial_speaker), mgc);
callsinfo->protocol = TEL_H248;
callsinfo->call_num = tapinfo->ncalls++;
callsinfo->start_fd = pinfo->fd;
callsinfo->stop_fd = pinfo->fd;
callsinfo->selected = FALSE;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
} else {
GString *s = g_string_new("");
gcp_terms_t *ctx_term;
g_free(callsinfo->from_identity);
callsinfo->from_identity = g_strdup_printf("%s : %.8x", mgw_addr, ((gcp_ctx_t*)callsinfo->prot_info)->id);
g_free(callsinfo->to_identity);
for (ctx_term = ((gcp_ctx_t*)callsinfo->prot_info)->terms.next;
ctx_term;
ctx_term = ctx_term->next ) {
if ( ctx_term->term && ctx_term->term->str) {
g_string_append_printf(s," %s",ctx_term->term->str);
}
}
callsinfo->to_identity = s->str;
g_string_free(s,FALSE);
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
}
add_to_graph(tapinfo, pinfo, cmd->str ? cmd->str : "unknown Msg",
ep_strdup_printf("TrxId = %u, CtxId = %.8x",cmd->trx->id,cmd->ctx->id),
callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
++(tapinfo->npackets);
tapinfo->redraw = TRUE;
return 1;
}
void h248_calls_init_tap(void)
{
GString *error_string;
if(have_megaco_tap_listener==FALSE)
{
error_string = register_tap_listener("megaco", &(the_tapinfo_struct.megaco_dummy),
NULL,
0,
voip_calls_dlg_reset,
h248_calls_packet,
voip_calls_dlg_draw);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_megaco_tap_listener=TRUE;
}
if(have_h248_tap_listener==FALSE)
{
error_string = register_tap_listener("h248", &(the_tapinfo_struct.h248_dummy),
NULL,
0,
voip_calls_dlg_reset,
h248_calls_packet,
voip_calls_dlg_draw);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_h248_tap_listener=TRUE;
}
}
void
remove_tap_listener_h248_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.h248_dummy));
remove_tap_listener(&(the_tapinfo_struct.megaco_dummy));
unprotect_thread_critical_region();
have_megaco_tap_listener=FALSE;
have_h248_tap_listener=FALSE;
}
/****************************************************************************/
/**************************** TAP for SCCP and SUA **********************************/
/**************************** ( RANAP and BSSAP ) **********************************/
/****************************************************************************/
static gboolean have_sccp_tap_listener = FALSE;
static gboolean have_sua_tap_listener = FALSE;
static const voip_protocol sccp_proto_map[] = {
TEL_SCCP,
TEL_BSSMAP,
TEL_RANAP
};
#define SP2VP(ap) ((ap) < SCCP_PLOAD_NUM_PLOADS ? sccp_proto_map[(ap)] : TEL_SCCP)
const value_string* sccp_payload_values;
static int sccp_calls(packet_info *pinfo, const void *prot_info) {
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
const sccp_msg_info_t* msg = prot_info;
sccp_assoc_info_t* assoc = msg->data.co.assoc;
GList *list;
voip_calls_info_t *callsinfo = NULL;
const gchar *label = NULL;
const gchar *comment = NULL;
/* check whether we already have this assoc in the list */
for(list = g_list_first(tapinfo->callsinfo_list) ; list ; list = g_list_next (list) ) {
if ( ((voip_calls_info_t*)(list->data))->prot_info == assoc ) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->call_active_state = VOIP_ACTIVE;
if ( assoc->calling_party ) {
callsinfo->from_identity = g_strdup(assoc->calling_party);
} else {
callsinfo->from_identity = g_strdup("Unknown");
}
if ( assoc->called_party ) {
callsinfo->to_identity = g_strdup(assoc->called_party);
} else {
callsinfo->to_identity = g_strdup("Unknown");
}
callsinfo->prot_info = (void*)assoc;
callsinfo->free_prot_info = NULL;
callsinfo->npackets = 1;
COPY_ADDRESS(&(callsinfo->initial_speaker), &(pinfo->src));
callsinfo->protocol = SP2VP(assoc->payload);
/* Store frame data which holds time and frame number */
callsinfo->start_fd = pinfo->fd;
callsinfo->stop_fd = pinfo->fd;
callsinfo->selected = FALSE;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
} else {
if ( assoc->calling_party ) {
g_free(callsinfo->from_identity);
callsinfo->from_identity = g_strdup(assoc->calling_party);
}
if ( assoc->called_party ) {
g_free(callsinfo->to_identity);
callsinfo->to_identity = g_strdup(assoc->called_party);
}
callsinfo->protocol = SP2VP(assoc->payload);
/* Store frame data which holds stop time and frame number */
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
switch (msg->type) {
case SCCP_MSG_TYPE_CC:
callsinfo->call_state = VOIP_IN_CALL;
break;
case SCCP_MSG_TYPE_RLC:
callsinfo->call_state = VOIP_COMPLETED;
callsinfo->call_active_state = VOIP_INACTIVE;
break;
default:
break;
}
}
if (msg->data.co.label) {
label = msg->data.co.label;
} else {
label = val_to_str(msg->type, sccp_payload_values, "Unknown(%d)");
}
if (msg->data.co.comment) {
comment = msg->data.co.comment;
} else {
comment = NULL;
}
add_to_graph(tapinfo, pinfo, label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
++(tapinfo->npackets);
tapinfo->redraw = TRUE;
return 1;
}
static int sccp_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prot_info) {
sccp_payload_values = sccp_message_type_acro_values;
return sccp_calls(pinfo, prot_info);
}
static int sua_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prot_info) {
sccp_payload_values = sua_co_class_type_acro_values;
return sccp_calls(pinfo, prot_info);
}
void sccp_calls_init_tap(void)
{
GString *error_string;
if(have_sccp_tap_listener==FALSE)
{
error_string = register_tap_listener("sccp", &(the_tapinfo_struct.sccp_dummy),
NULL,
0,
voip_calls_dlg_reset,
sccp_calls_packet,
voip_calls_dlg_draw);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_sccp_tap_listener=TRUE;
}
if(have_sua_tap_listener==FALSE)
{
error_string = register_tap_listener("sua", &(the_tapinfo_struct.sua_dummy),
NULL,
0,
voip_calls_dlg_reset,
sua_calls_packet,
voip_calls_dlg_draw);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_sua_tap_listener=TRUE;
}
}
void
remove_tap_listener_sccp_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.sccp_dummy));
unprotect_thread_critical_region();
have_sccp_tap_listener=FALSE;
have_sua_tap_listener=FALSE;
}
/****************************************************************************/
/****************************TAP for UNISTIM ********************************/
/****************************************************************************/
static int
unistim_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *unistim_info)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *tmp_listinfo;
voip_calls_info_t *callsinfo = NULL;
unistim_info_t *tmp_unistim_info = NULL;
GList *list = NULL;
GString *g_tmp = NULL;
const gchar *frame_label = NULL;
gchar *comment = NULL;
/* Fetch specific packet infos */
const unistim_info_t *pi = unistim_info;
/* Init gstring */
g_tmp = g_string_new(NULL);
/* Check to see if this is a dup */
list = g_list_first(tapinfo->callsinfo_list);
while(list)
{
tmp_listinfo = list->data;
if(tmp_listinfo->protocol == VOIP_UNISTIM) {
tmp_unistim_info = tmp_listinfo->prot_info;
/* Search by termid if possible, otherwise use ni/it ip + port.. */
if(pi->termid != 0) {
if(tmp_unistim_info->termid == pi->termid) {
/* If the call has ended, then we can reuse it.. */
if(tmp_listinfo->call_state == VOIP_COMPLETED || tmp_listinfo->call_state == VOIP_UNKNOWN) {
/* Do nothing */
} else {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
} else {
/* If no term id use ips / port to find entry */
if(ADDRESSES_EQUAL(&tmp_unistim_info->it_ip, &pinfo->dst) && ADDRESSES_EQUAL(&tmp_unistim_info->ni_ip,&pinfo->src) && (tmp_unistim_info->it_port == pinfo->destport)) {
if(tmp_listinfo->call_state == VOIP_COMPLETED || tmp_listinfo->call_state == VOIP_UNKNOWN) {
/* Do nothing previous call */
} else {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
else if(ADDRESSES_EQUAL(&tmp_unistim_info->it_ip, &pinfo->src) && ADDRESSES_EQUAL(&tmp_unistim_info->ni_ip,&pinfo->dst) && (tmp_unistim_info->it_port == pinfo->srcport)) {
if(tmp_listinfo->call_state == VOIP_COMPLETED || tmp_listinfo->call_state == VOIP_UNKNOWN) {
/* Do nothing, it ain't our call.. */
} else {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
}
}
/* Otherwise, go to the next one.. */
list = g_list_next(list);
}
if(pi->payload_type == 2 || pi->payload_type == 1) {
if(pi->key_state == 1 || pi->hook_state == 1) {
/* If the user hits a button,
Session will be SETUP */
/* If new add to list */
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup_printf("%x",pi->termid);
callsinfo->to_identity=g_strdup("UNKNOWN");
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
/* Set this on init of struct so in case the call doesn't complete, we'll have a ref. */
/* Otherwise if the call is completed we'll have the open/close streams to ref actual call duration */
/* Store frame data which holds time and frame number */
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_UNISTIM;
callsinfo->prot_info=g_malloc(sizeof(unistim_info_t));
tmp_unistim_info = callsinfo->prot_info;
/* Clear tap struct */
tmp_unistim_info->rudp_type = 0;
tmp_unistim_info->payload_type = 0;
tmp_unistim_info->sequence = pi->sequence;
tmp_unistim_info->termid = pi->termid;
tmp_unistim_info->key_val = -1;
tmp_unistim_info->key_state = -1;
tmp_unistim_info->hook_state = -1;
tmp_unistim_info->stream_connect = -1;
tmp_unistim_info->trans_connect = -1;
tmp_unistim_info->set_termid = -1;
tmp_unistim_info->string_data = NULL;
tmp_unistim_info->key_buffer = NULL;
COPY_ADDRESS(&(tmp_unistim_info->it_ip),&(pi->it_ip));
COPY_ADDRESS(&(tmp_unistim_info->ni_ip),&(pi->ni_ip));
tmp_unistim_info->it_port = pi->it_port;
callsinfo->free_prot_info = g_free;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
} else {
/* Set up call wide info struct */
tmp_unistim_info = callsinfo->prot_info;
tmp_unistim_info->sequence = pi->sequence;
}
/* Each packet COULD BE OUR LAST!!!! */
/* Store frame data which holds time and frame number */
callsinfo->stop_fd = pinfo->fd;
/* This is a valid packet so increment counter */
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* Key was depressed.. update key buffer.. */
if(pi->key_val >= 0 && pi->key_val <= 11) {
if(tmp_unistim_info->key_buffer != NULL) {
/* assign to temp variable */
g_string_assign(g_tmp,tmp_unistim_info->key_buffer);
/* Manipulate the data */
if(pi->key_val == 10) {
tmp_unistim_info->key_buffer = g_strdup_printf("%s*",g_tmp->str);
} else if(pi->key_val == 11) {
tmp_unistim_info->key_buffer = g_strdup_printf("%s#",g_tmp->str);
} else {
tmp_unistim_info->key_buffer = g_strdup_printf("%s%d",g_tmp->str,pi->key_val);
}
} else {
/* Create new string */
if(pi->key_val == 10) {
tmp_unistim_info->key_buffer = g_strdup("*");
} else if(pi->key_val == 11) {
tmp_unistim_info->key_buffer = g_strdup("#");
} else {
tmp_unistim_info->key_buffer = g_strdup_printf("%d",pi->key_val);
}
}
/* Select for non-digit characters */
if(pi->key_val == 10) {
comment = g_strdup_printf("Key Input Sent: * (%d)", pi->sequence);
} else if(pi->key_val == 11) {
comment = g_strdup_printf("Key Input Sent: # (%d)", pi->sequence);
} else {
comment = g_strdup_printf("Key Input Sent: %d (%d)",pi->key_val, pi->sequence);
}
} else if(pi->key_val == 12) {
/* Set label and comment for graph */
comment = g_strdup_printf("Key Input Sent: UP (%d)", pi->sequence);
} else if(pi->key_val == 13) {
/* Set label and comment for graph */
comment = g_strdup_printf("Key Input Sent: DOWN (%d)", pi->sequence);
} else if(pi->key_val == 14) {
/* Set label and comment for graph */
comment = g_strdup_printf("Key Input Sent: RIGHT (%d)", pi->sequence);
} else if(pi->key_val == 15) {
if(pi->key_buffer != NULL) {
/* Get data */
g_string_assign(g_tmp,pi->key_buffer);
/* Manipulate the data */
g_string_truncate(g_tmp,g_tmp->len-1);
/* Insert new data */
tmp_unistim_info->key_buffer = g_strdup(g_tmp->str);
}
/* Set label and comment for graph */
comment = g_strdup_printf("Key Input Sent: LEFT (%d)", pi->sequence);
} else if(pi->key_val == 20) {
/* User pressed the soft key 0 probably dial */
comment = g_strdup_printf("Key Input Sent: S0 (%d)", pi->sequence);
} else if(pi->key_val == 21) {
/* User pressed the soft key 1 */
comment = g_strdup_printf("Key Input Sent: S1 (%d)", pi->sequence);
} else if(pi->key_val == 22) {
/* User pressed the soft key 2 */
/* On cs2k phones, soft key 2 is backspace. */
if(pi->key_buffer != NULL) {
/* Get data */
g_string_assign(g_tmp,pi->key_buffer);
/* Manipulate the data */
g_string_truncate(g_tmp,g_tmp->len-1);
/* Insert new data */
tmp_unistim_info->key_buffer = g_strdup(g_tmp->str);
}
/* add label and comment */
comment = g_strdup_printf("Key Input Sent: S2 (%d)", pi->sequence);
} else if(pi->key_val == 28) {
/* User pressed something */
comment = g_strdup_printf("Key Input Sent: Release (%d)", pi->sequence);
} else if(pi->key_val == 23) {
/* User pressed the soft key 3 */
/* Cancel on cs2k so clear buffer */
/* On mcs its config which will clear the buffer too */
tmp_unistim_info->key_buffer = g_strdup("\n");
/* User pressed something, set labels*/
comment = g_strdup_printf("Key Input Sent: S3 (%d)", pi->sequence);
} else if(pi->key_val == 27) {
/* User pressed something */
comment = g_strdup_printf("Key Input Sent: Hold (%d)", pi->sequence);
} else if(pi->key_val == 29) {
/* User pressed something */
comment = g_strdup_printf("Key Input Sent: Mute (%d)", pi->sequence);
} else if(pi->key_val == 30) {
/* User pressed something */
comment = g_strdup_printf("Key Input Sent: Headset (%d)", pi->sequence);
} else if(pi->key_val == 31) {
/* Handsfree button */
comment = g_strdup_printf("Key Input Sent: Handsfree (%d)", pi->sequence);
} else if(pi->key_val >= 32 && pi->key_val <= 56) {
/* Prog. Key X */
comment = g_strdup_printf("Key Input Sent: Prog%d (%d)", (pi->key_val & 31), pi->sequence);
}
if(pi->key_val != -1) {
frame_label = "KEY INPUT";
if (comment == NULL)
/* Ouch! What do you do!? */
/* User pressed something */
comment = g_strdup_printf("Key Input Sent: UNKNOWN - %d (%d)", pi->key_val, pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
}
if(pi->hook_state == 1) {
/* Phone is off hook */
frame_label = "OFF HOOK";
comment = g_strdup_printf("Off Hook (%d)", pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
} else if(pi->hook_state == 0) {
/* Phone is on hook */
frame_label = "ON HOOK";
comment = g_strdup_printf("On Hook (%d)", pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
}
}
/* Open stream was sent from server */
if(pi->stream_connect == 1 && callsinfo != NULL) {
/* Open stream */
/* Signifies the start of the call so set start_sec & start_usec */
/* Frame data holds the time info */
callsinfo->start_fd=pinfo->fd;
/* Local packets too */
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* ?? means we're not quite sure if this is accurate. Since Unistim isn't a true
Call control protocol, we can only guess at the destination by messing with
key buffers. */
if(tmp_unistim_info->key_buffer != NULL) {
callsinfo->to_identity = g_strdup_printf("?? %s",tmp_unistim_info->key_buffer);
}
/* change sequence number for ACK detection */
tmp_unistim_info->sequence = pi->sequence;
/* State changes too */
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_IN_CALL;
/* Add graph data */
frame_label = "STREAM OPENED";
comment = g_strdup_printf("Stream Opened (%d)",pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
} else if(pi->stream_connect == 1 && callsinfo == NULL) {
/* Research indicates some nortel products initiate stream first
* without keypresses. therefore creating this solely on a keypress is
* ineffective.
* Sometimes calls start immediately with open stream.
*/
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_CALL_SETUP;
callsinfo->from_identity=g_strdup("UNKNOWN");
callsinfo->to_identity=g_strdup("UNKNOWN");
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
/* Set this on init of struct so in case the call doesn't complete, we'll have a ref. */
/* Otherwise if the call is completed we'll have the open/close streams to ref actual call duration */
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_UNISTIM;
callsinfo->prot_info=g_malloc(sizeof(unistim_info_t));
tmp_unistim_info = callsinfo->prot_info;
/* Clear tap struct */
tmp_unistim_info->rudp_type = 0;
tmp_unistim_info->payload_type = 0;
tmp_unistim_info->sequence = pi->sequence;
tmp_unistim_info->termid = 0;
tmp_unistim_info->key_val = -1;
tmp_unistim_info->key_state = -1;
tmp_unistim_info->hook_state = -1;
tmp_unistim_info->stream_connect = -1;
tmp_unistim_info->trans_connect = -1;
tmp_unistim_info->set_termid = -1;
tmp_unistim_info->string_data = NULL;
tmp_unistim_info->key_buffer = NULL;
COPY_ADDRESS(&(tmp_unistim_info->it_ip),&(pi->it_ip));
COPY_ADDRESS(&(tmp_unistim_info->ni_ip),&(pi->ni_ip));
tmp_unistim_info->it_port = pi->it_port;
callsinfo->free_prot_info = g_free;
callsinfo->npackets = 0;
callsinfo->call_num = tapinfo->ncalls++;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
/* Open stream */
/* Signifies the start of the call so set start_sec & start_usec */
/* frame_data holds the time info */
callsinfo->start_fd=pinfo->fd;
/* Local packets too */
++(callsinfo->npackets);
/* increment the packets counter of all calls */
++(tapinfo->npackets);
/* ?? means we're not quite sure if this is accurate. Since Unistim isn't a true
Call control protocol, we can only guess at the destination by messing with
key buffers. */
if(tmp_unistim_info->key_buffer != NULL) {
callsinfo->to_identity = g_strdup_printf("?? %s",tmp_unistim_info->key_buffer);
}
/* change sequence number for ACK detection */
tmp_unistim_info->sequence = pi->sequence;
/* State changes too */
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->call_state = VOIP_IN_CALL;
/* Add graph data */
frame_label = "STREAM OPENED";
comment = g_strdup_printf("Stream Opened (%d)",pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
} else if(pi->stream_connect == 0 && callsinfo != NULL) {
/* Close Stream */
/* Set stop seconds + usec */
/* frame_data holds the time info */
callsinfo->stop_fd = pinfo->fd;
tmp_unistim_info->sequence = pi->sequence;
if(callsinfo->call_state == VOIP_IN_CALL) {
callsinfo->call_active_state = VOIP_INACTIVE;
callsinfo->call_state = VOIP_COMPLETED;
} else {
callsinfo->call_state = VOIP_UNKNOWN;
callsinfo->call_active_state = VOIP_INACTIVE;
}
frame_label = "STREAM CLOSED";
comment = g_strdup_printf("Stream Closed (%d)",pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
} else
comment = NULL;
} else if(pi->rudp_type == 1 && callsinfo != NULL) {
/* ACK */
/* Only show acks for processed seq #s */
if(tmp_unistim_info->sequence == pi->sequence) {
frame_label = "ACK";
comment = g_strdup_printf("ACK for sequence %d",pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
}
} else if(pi->rudp_type == 0 && callsinfo != NULL) {
/* NAK */
frame_label = "NAK";
comment = g_strdup_printf("NAK for sequence %d",pi->sequence);
/* add to the graph */
add_to_graph(tapinfo, pinfo, frame_label, comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
}
/* free data */
g_free(comment);
tapinfo->redraw = TRUE;
return 1;
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_unistim_tap_listener=FALSE;
/****************************************************************************/
void
unistim_calls_init_tap(void) {
GString *error_string;
if(have_unistim_tap_listener==FALSE) {
error_string = register_tap_listener("unistim", &(the_tapinfo_struct.unistim_dummy),
NULL,
0,
voip_calls_dlg_reset,
unistim_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_unistim_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_unistim_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.unistim_dummy));
unprotect_thread_critical_region();
have_unistim_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for SKINNY **********************************/
/****************************************************************************/
/* Telecaster to tap-voip call state mapping */
static const voip_call_state skinny_tap_voip_state[] = {
VOIP_NO_STATE,
VOIP_CALL_SETUP,
VOIP_COMPLETED,
VOIP_RINGING,
VOIP_RINGING,
VOIP_IN_CALL,
VOIP_REJECTED,
VOIP_REJECTED,
VOIP_IN_CALL,
VOIP_IN_CALL,
VOIP_COMPLETED,
VOIP_COMPLETED,
VOIP_CALL_SETUP,
VOIP_UNKNOWN,
VOIP_REJECTED
};
static int
skinny_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *skinny_info)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
GList* list;
voip_calls_info_t *callsinfo = NULL;
address* phone;
const skinny_info_t *si = skinny_info;
skinny_calls_info_t *tmp_skinnyinfo;
gchar *comment;
if (si == NULL || (si->callId == 0 && si->passThruId == 0))
return 0;
/* check whether we already have this context in the list */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
voip_calls_info_t* tmp_listinfo = list->data;
if (tmp_listinfo->protocol == VOIP_SKINNY) {
tmp_skinnyinfo = tmp_listinfo->prot_info;
if (tmp_skinnyinfo->callId == si->callId ||
tmp_skinnyinfo->callId == si->passThruId) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
if (si->messId >= 256)
phone = &(pinfo->dst);
else
phone = &(pinfo->src);
if (callsinfo==NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_state = VOIP_NO_STATE;
callsinfo->call_active_state = VOIP_ACTIVE;
/* callsinfo->from_identity = g_strdup_printf("%s : %.8x", "Skinny", 1); */
callsinfo->from_identity = g_strdup("");
callsinfo->to_identity = g_strdup("");
callsinfo->prot_info = g_malloc(sizeof(skinny_calls_info_t));
callsinfo->free_prot_info = g_free;
tmp_skinnyinfo = callsinfo->prot_info;
tmp_skinnyinfo->callId = si->callId ? si->callId : si->passThruId;
callsinfo->npackets = 1;
COPY_ADDRESS(&(callsinfo->initial_speaker), phone);
callsinfo->protocol = VOIP_SKINNY;
callsinfo->call_num = tapinfo->ncalls++;
callsinfo->start_fd = pinfo->fd;
callsinfo->stop_fd = pinfo->fd;
callsinfo->selected = FALSE;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
} else {
if (si->callingParty) {
g_free(callsinfo->from_identity);
callsinfo->from_identity = g_strdup(si->callingParty);
}
if (si->calledParty) {
g_free(callsinfo->to_identity);
callsinfo->to_identity = g_strdup(si->calledParty);
}
if ((si->callState > 0) && (si->callState < (sizeof(skinny_tap_voip_state)/sizeof(skinny_tap_voip_state[0]))))
callsinfo->call_state = skinny_tap_voip_state[si->callState];
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
}
if (si->callId) {
if (si->passThruId)
comment = g_strdup_printf("CallId = %u, PTId = %u", si->callId, si->passThruId);
else
comment = g_strdup_printf("CallId = %u, LineId = %u", si->callId, si->lineId);
} else {
if (si->passThruId)
comment = g_strdup_printf("PTId = %u", si->passThruId);
else
comment = NULL;
}
add_to_graph(tapinfo, pinfo, si->messageName, comment,
callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
g_free(comment);
return 1;
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_skinny_tap_listener=FALSE;
/****************************************************************************/
void
skinny_calls_init_tap(void)
{
GString *error_string;
if(have_skinny_tap_listener==FALSE)
{
/*
* Don't register the tap listener if we have it already.
* We set TL_REQUIRES_PROTO_TREE to force a non-null "tree"
* in the SKINNY dissector; otherwise, the dissector
* doesn't fill in the info passed to the tap's packet
* routine.
*/
error_string = register_tap_listener("skinny",
&(the_tapinfo_struct.skinny_dummy),
NULL,
TL_REQUIRES_PROTO_TREE,
voip_calls_dlg_reset,
skinny_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_skinny_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_skinny_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.skinny_dummy));
unprotect_thread_critical_region();
have_skinny_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for IAX2 **********************************/
/****************************************************************************/
/* IAX2 to tap-voip call state mapping */
static const voip_call_state tap_iax_voip_state[] = {
VOIP_NO_STATE,
VOIP_CALL_SETUP, /*NEW*/
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_COMPLETED, /*HANGUP*/
VOIP_REJECTED, /*REJECT*/
VOIP_RINGING, /*ACCEPT*/
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_CALL_SETUP, /*DIAL*/
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE,
VOIP_NO_STATE
};
static void free_iax2_info(gpointer p) {
iax2_info_t *ii = p;
g_free(ii);
}
/****************************************************************************/
/* whenever a IAX2 packet is seen by the tap listener */
static int
iax2_calls_packet( void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *iax2_info)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
GList* list;
voip_calls_info_t *callsinfo = NULL;
address* phone;
const iax2_info_t *ii = iax2_info;
iax2_info_t *tmp_iax2info;
gchar * comment;
if (ii == NULL || ii->ptype != IAX2_FULL_PACKET || (ii->scallno == 0 && ii->dcallno == 0))
return 0;
/* check whether we already have this context in the list */
list = g_list_first(tapinfo->callsinfo_list);
while (list)
{
voip_calls_info_t* tmp_listinfo = list->data;
if (tmp_listinfo->protocol == VOIP_IAX2) {
tmp_iax2info = tmp_listinfo->prot_info;
if (tmp_iax2info->scallno == ii->scallno ||
tmp_iax2info->scallno == ii->dcallno) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next (list);
}
phone = &(pinfo->src);
if (callsinfo==NULL) {
/* We only care about real calls, i.e., no registration stuff */
if (ii->ftype != AST_FRAME_IAX || ii->csub != IAX_COMMAND_NEW)
return 0;
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_state = VOIP_NO_STATE;
callsinfo->call_active_state = VOIP_ACTIVE;
callsinfo->prot_info=g_malloc(sizeof(iax2_info_t));
callsinfo->free_prot_info = free_iax2_info;
tmp_iax2info = callsinfo->prot_info;
tmp_iax2info->scallno = ii->scallno;
if (tmp_iax2info->scallno == 0) tmp_iax2info->scallno = ii->dcallno;
tmp_iax2info->callState = tap_iax_voip_state[ii->callState];
callsinfo->npackets = 1;
COPY_ADDRESS(&(callsinfo->initial_speaker), phone);
callsinfo->from_identity = g_strdup(ii->callingParty);
callsinfo->to_identity = g_strdup(ii->calledParty);
callsinfo->protocol = VOIP_IAX2;
callsinfo->call_num = tapinfo->ncalls++;
callsinfo->start_fd=pinfo->fd;
callsinfo->stop_fd = pinfo->fd;
callsinfo->selected = FALSE;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
} else {
if ((ii->callState > 0) && (ii->callState < (sizeof(tap_iax_voip_state)/sizeof(tap_iax_voip_state[0]))))
callsinfo->call_state = tap_iax_voip_state[ii->callState];
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
}
comment = "";
add_to_graph(tapinfo, pinfo, ii->messageName, comment,
callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
return 1;
}
/****************************************************************************/
/* TAP INTERFACE */
/****************************************************************************/
static gboolean have_iax2_tap_listener=FALSE;
/****************************************************************************/
void
iax2_calls_init_tap(void)
{
GString *error_string;
if(have_iax2_tap_listener==FALSE)
{
/*
* Don't register the tap listener if we have it already.
* We set TL_REQUIRES_PROTO_TREE to force a non-null "tree"
* in the IAX2 dissector; otherwise, the dissector
* doesn't fill in the info passed to the tap's packet
* routine.
* XXX - that appears to be true of the MGCP and SKINNY
* dissectors, but, unless I've missed something, it doesn't
* appear to be true of the IAX2 dissector.
*/
error_string = register_tap_listener("IAX2",
&(the_tapinfo_struct.iax2_dummy),
NULL,
TL_REQUIRES_PROTO_TREE,
voip_calls_dlg_reset,
iax2_calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_iax2_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_iax2_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.iax2_dummy));
unprotect_thread_critical_region();
have_iax2_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for OTHER PROTOCOL **********************************/
/****************************************************************************/
static int
VoIPcalls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *VoIPinfo)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
voip_calls_info_t *callsinfo = NULL;
voip_calls_info_t *tmp_listinfo;
GList *list = NULL;
const voip_packet_info_t *pi = VoIPinfo;
if (pi->call_id)
list = g_list_first(tapinfo->callsinfo_list);
while (list) {
tmp_listinfo = list->data;
if ( tmp_listinfo->protocol == VOIP_COMMON ) {
if (!strcmp(pi->call_id, tmp_listinfo->call_id)) {
callsinfo = (voip_calls_info_t*)(list->data);
break;
}
}
list = g_list_next(list);
}
if (callsinfo == NULL) {
callsinfo = g_malloc0(sizeof(voip_calls_info_t));
callsinfo->call_active_state = pi->call_active_state;
callsinfo->call_state = pi->call_state;
callsinfo->call_id=g_strdup((pi->call_id)?pi->call_id:"");
callsinfo->from_identity = g_strdup((pi->from_identity)?pi->from_identity:"");
callsinfo->to_identity = g_strdup((pi->to_identity)?pi->to_identity:"");
COPY_ADDRESS(&(callsinfo->initial_speaker),&(pinfo->src));
callsinfo->selected=FALSE;
callsinfo->start_fd=pinfo->fd;
callsinfo->protocol=VOIP_COMMON;
callsinfo->protocol_name=g_strdup((pi->protocol_name)?pi->protocol_name:"");
callsinfo->call_comment=g_strdup((pi->call_comment)?pi->call_comment:"");
callsinfo->prot_info=NULL;
callsinfo->free_prot_info = NULL;
callsinfo->call_num = tapinfo->ncalls++;
callsinfo->npackets = 0;
tapinfo->callsinfo_list = g_list_prepend(tapinfo->callsinfo_list, callsinfo);
}
callsinfo->call_active_state = pi->call_active_state;
if ((callsinfo->call_state != VOIP_COMPLETED) && (pi->call_state == VOIP_COMPLETED))
tapinfo->completed_calls++;
if (pi->call_state != VOIP_NO_STATE)
callsinfo->call_state = pi->call_state;
if (pi->call_comment) {
g_free(callsinfo->call_comment);
callsinfo->call_comment=g_strdup(pi->call_comment);
}
callsinfo->stop_fd = pinfo->fd;
++(callsinfo->npackets);
++(tapinfo->npackets);
/* add to the graph */
add_to_graph(tapinfo, pinfo, (pi->frame_label)?pi->frame_label:"VoIP msg", pi->frame_comment, callsinfo->call_num, &(pinfo->src), &(pinfo->dst), 1);
tapinfo->redraw = TRUE;
return 1;
}
/****************************************************************************/
static gboolean have_voip_tap_listener=FALSE;
void
VoIPcalls_init_tap(void)
{
GString *error_string;
if(have_voip_tap_listener==FALSE)
{
error_string = register_tap_listener("voip", &(the_tapinfo_struct.voip_dummy),
NULL,
0,
voip_calls_dlg_reset,
VoIPcalls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_voip_tap_listener=TRUE;
}
}
/****************************************************************************/
void
remove_tap_listener_voip_calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.voip_dummy));
unprotect_thread_critical_region();
have_voip_tap_listener=FALSE;
}
/****************************************************************************/
/* ***************************TAP for OTHER PROTOCOL **********************************/
/****************************************************************************/
/****************************************************************************/
/* whenever a prot_ packet is seen by the tap listener */
/*
static int
prot_calls_packet(void *ptr _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prot_info _U_)
{
voip_calls_tapinfo_t *tapinfo = &the_tapinfo_struct;
if (callsinfo!=NULL) {
callsinfo->stop_abs = pinfo->fd->abs_ts;
callsinfo->stop_rel = pinfo->fd->rel_ts;
callsinfo->last_frame_num=pinfo->fd->num;
++(callsinfo->npackets);
++(tapinfo->npackets);
}
tapinfo->redraw = TRUE;
return 1;
}
*/
/****************************************************************************/
/*
static gboolean have_prot__tap_listener=FALSE;
void
prot_calls_init_tap(void)
{
GString *error_string;
if(have_prot__tap_listener==FALSE)
{
error_string = register_tap_listener("prot_", &(the_tapinfo_struct.prot__dummy),
NULL,
0,
voip_calls_dlg_reset,
prot__calls_packet,
voip_calls_dlg_draw
);
if (error_string != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"%s", error_string->str);
g_string_free(error_string, TRUE);
exit(1);
}
have_prot__tap_listener=TRUE;
}
}
*/
/****************************************************************************/
/*
void
remove_tap_listener_prot__calls(void)
{
protect_thread_critical_region();
remove_tap_listener(&(the_tapinfo_struct.prot__dummy));
unprotect_thread_critical_region();
have_prot__tap_listener=FALSE;
}
*/
|