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

  (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
      www.systec-electronic.com

  Project:      openPOWERLINK

  Description:  source file for NMT-MN-Module

  License:

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. Neither the name of SYSTEC electronic GmbH nor the names of its
       contributors may be used to endorse or promote products derived
       from this software without prior written permission. For written
       permission, please contact info@systec-electronic.com.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

    Severability Clause:

        If a provision of this License is or becomes illegal, invalid or
        unenforceable in any jurisdiction, that shall not affect:
        1. the validity or enforceability in that jurisdiction of any other
           provision of this License; or
        2. the validity or enforceability in other jurisdictions of that or
           any other provision of this License.

  -------------------------------------------------------------------------

                $RCSfile: EplNmtMnu.c,v $

                $Author: D.Krueger $

                $Revision: 1.18 $  $Date: 2008/11/19 09:52:24 $

                $State: Exp $

                Build Environment:
                    GCC V3.4

  -------------------------------------------------------------------------

  Revision History:

  2006/06/09 k.t.:   start of the implementation

****************************************************************************/

#include "user/EplNmtMnu.h"
#include "user/EplTimeru.h"
#include "user/EplIdentu.h"
#include "user/EplStatusu.h"
#include "user/EplObdu.h"
#include "user/EplDlluCal.h"
#include "Benchmark.h"

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) == 0) && (EPL_OBD_USE_KERNEL == FALSE)
#error "EPL NmtMnu module needs EPL module OBDU or OBDK!"
#endif

//=========================================================================//
//                                                                         //
//          P R I V A T E   D E F I N I T I O N S                          //
//                                                                         //
//=========================================================================//

//---------------------------------------------------------------------------
// const defines
//---------------------------------------------------------------------------

// TracePoint support for realtime-debugging
#ifdef _DBG_TRACE_POINTS_
void PUBLIC TgtDbgSignalTracePoint(BYTE bTracePointNumber_p);
void PUBLIC TgtDbgPostTraceValue(DWORD dwTraceValue_p);
#define TGT_DBG_SIGNAL_TRACE_POINT(p)   TgtDbgSignalTracePoint(p)
#define TGT_DBG_POST_TRACE_VALUE(v)     TgtDbgPostTraceValue(v)
#else
#define TGT_DBG_SIGNAL_TRACE_POINT(p)
#define TGT_DBG_POST_TRACE_VALUE(v)
#endif
#define EPL_NMTMNU_DBG_POST_TRACE_VALUE(Event_p, uiNodeId_p, wErrorCode_p) \
    TGT_DBG_POST_TRACE_VALUE((kEplEventSinkNmtMnu << 28) | (Event_p << 24) \
                             | (uiNodeId_p << 16) | wErrorCode_p)

// defines for flags in node info structure
#define EPL_NMTMNU_NODE_FLAG_ISOCHRON       0x0001	// CN is being accessed isochronously
#define EPL_NMTMNU_NODE_FLAG_NOT_SCANNED    0x0002	// CN was not scanned once -> decrement SignalCounter and reset flag
#define EPL_NMTMNU_NODE_FLAG_HALTED         0x0004	// boot process for this CN is halted
#define EPL_NMTMNU_NODE_FLAG_NMT_CMD_ISSUED 0x0008	// NMT command was just issued, wrong NMT states will be tolerated
#define EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ  0x0300	// counter for StatusRequest timer handle
#define EPL_NMTMNU_NODE_FLAG_COUNT_LONGER   0x0C00	// counter for longer timeouts timer handle
#define EPL_NMTMNU_NODE_FLAG_INC_STATREQ    0x0100	// increment for StatusRequest timer handle
#define EPL_NMTMNU_NODE_FLAG_INC_LONGER     0x0400	// increment for longer timeouts timer handle
		    // These counters will be incremented at every timer start
		    // and copied to timerarg. When the timer event occures
		    // both will be compared and if unequal the timer event
		    // will be discarded, because it is an old one.

// defines for timer arguments to draw a distinction between serveral events
#define EPL_NMTMNU_TIMERARG_NODE_MASK   0x000000FFL	// mask that contains the node-ID
#define EPL_NMTMNU_TIMERARG_IDENTREQ    0x00010000L	// timer event is for IdentRequest
#define EPL_NMTMNU_TIMERARG_STATREQ     0x00020000L	// timer event is for StatusRequest
#define EPL_NMTMNU_TIMERARG_LONGER      0x00040000L	// timer event is for longer timeouts
#define EPL_NMTMNU_TIMERARG_STATE_MON   0x00080000L	// timer event for StatusRequest to monitor execution of NMT state changes
#define EPL_NMTMNU_TIMERARG_COUNT_SR    0x00000300L	// counter for StatusRequest
#define EPL_NMTMNU_TIMERARG_COUNT_LO    0x00000C00L	// counter for longer timeouts
		    // The counters must have the same position as in the node flags above.

#define EPL_NMTMNU_SET_FLAGS_TIMERARG_STATREQ(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
    pNodeInfo_p->m_wFlags = \
        ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_STATREQ) \
         & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) \
        | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
    TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_STATREQ | uiNodeId_p | \
        (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
    TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;

#define EPL_NMTMNU_SET_FLAGS_TIMERARG_IDENTREQ(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
    pNodeInfo_p->m_wFlags = \
        ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_STATREQ) \
         & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) \
        | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
    TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_IDENTREQ | uiNodeId_p | \
        (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
    TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;

#define EPL_NMTMNU_SET_FLAGS_TIMERARG_LONGER(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
    pNodeInfo_p->m_wFlags = \
        ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_LONGER) \
         & EPL_NMTMNU_NODE_FLAG_COUNT_LONGER) \
        | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_LONGER); \
    TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_LONGER | uiNodeId_p | \
        (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_LONGER); \
    TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;

#define EPL_NMTMNU_SET_FLAGS_TIMERARG_STATE_MON(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
    pNodeInfo_p->m_wFlags = \
        ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_STATREQ) \
         & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) \
        | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
    TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_STATE_MON | uiNodeId_p | \
        (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
    TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;

// defines for global flags
#define EPL_NMTMNU_FLAG_HALTED          0x0001	// boot process is halted
#define EPL_NMTMNU_FLAG_APP_INFORMED    0x0002	// application was informed about possible NMT state change

// return pointer to node info structure for specified node ID
// d.k. may be replaced by special (hash) function if node ID array is smaller than 254
#define EPL_NMTMNU_GET_NODEINFO(uiNodeId_p) (&EplNmtMnuInstance_g.m_aNodeInfo[uiNodeId_p - 1])

//---------------------------------------------------------------------------
// local types
//---------------------------------------------------------------------------

typedef enum {
	kEplNmtMnuIntNodeEventNoIdentResponse = 0x00,
	kEplNmtMnuIntNodeEventIdentResponse = 0x01,
	kEplNmtMnuIntNodeEventBoot = 0x02,
	kEplNmtMnuIntNodeEventExecReset = 0x03,
	kEplNmtMnuIntNodeEventConfigured = 0x04,
	kEplNmtMnuIntNodeEventNoStatusResponse = 0x05,
	kEplNmtMnuIntNodeEventStatusResponse = 0x06,
	kEplNmtMnuIntNodeEventHeartbeat = 0x07,
	kEplNmtMnuIntNodeEventNmtCmdSent = 0x08,
	kEplNmtMnuIntNodeEventTimerIdentReq = 0x09,
	kEplNmtMnuIntNodeEventTimerStatReq = 0x0A,
	kEplNmtMnuIntNodeEventTimerStateMon = 0x0B,
	kEplNmtMnuIntNodeEventTimerLonger = 0x0C,
	kEplNmtMnuIntNodeEventError = 0x0D,

} tEplNmtMnuIntNodeEvent;

typedef enum {
	kEplNmtMnuNodeStateUnknown = 0x00,
	kEplNmtMnuNodeStateIdentified = 0x01,
	kEplNmtMnuNodeStateResetConf = 0x02,	// CN reset after configuration update
	kEplNmtMnuNodeStateConfigured = 0x03,	// BootStep1 completed
	kEplNmtMnuNodeStateReadyToOp = 0x04,	// BootStep2 completed
	kEplNmtMnuNodeStateComChecked = 0x05,	// Communication checked successfully
	kEplNmtMnuNodeStateOperational = 0x06,	// CN is in NMT state OPERATIONAL

} tEplNmtMnuNodeState;

typedef struct {
	tEplTimerHdl m_TimerHdlStatReq;	// timer to delay StatusRequests and IdentRequests
	tEplTimerHdl m_TimerHdlLonger;	// 2nd timer for NMT command EnableReadyToOp and CheckCommunication
	tEplNmtMnuNodeState m_NodeState;	// internal node state (kind of sub state of NMT state)
	DWORD m_dwNodeCfg;	// subindex from 0x1F81
	WORD m_wFlags;		// flags: CN is being accessed isochronously

} tEplNmtMnuNodeInfo;

typedef struct {
	tEplNmtMnuNodeInfo m_aNodeInfo[EPL_NMT_MAX_NODE_ID];
	tEplTimerHdl m_TimerHdlNmtState;	// timeout for stay in NMT state
	unsigned int m_uiMandatorySlaveCount;
	unsigned int m_uiSignalSlaveCount;
	unsigned long m_ulStatusRequestDelay;	// in [ms] (object 0x1006 * EPL_C_NMT_STATREQ_CYCLE)
	unsigned long m_ulTimeoutReadyToOp;	// in [ms] (object 0x1F89/5)
	unsigned long m_ulTimeoutCheckCom;	// in [ms] (object 0x1006 * MultiplexedCycleCount)
	WORD m_wFlags;		// global flags
	DWORD m_dwNmtStartup;	// object 0x1F80 NMT_StartUp_U32
	tEplNmtMnuCbNodeEvent m_pfnCbNodeEvent;
	tEplNmtMnuCbBootEvent m_pfnCbBootEvent;

} tEplNmtMnuInstance;

//---------------------------------------------------------------------------
// local vars
//---------------------------------------------------------------------------

static tEplNmtMnuInstance EplNmtMnuInstance_g;

//---------------------------------------------------------------------------
// local function prototypes
//---------------------------------------------------------------------------

static tEplKernel PUBLIC EplNmtMnuCbNmtRequest(tEplFrameInfo * pFrameInfo_p);

static tEplKernel PUBLIC EplNmtMnuCbIdentResponse(unsigned int uiNodeId_p,
						  tEplIdentResponse *
						  pIdentResponse_p);

static tEplKernel PUBLIC EplNmtMnuCbStatusResponse(unsigned int uiNodeId_p,
						   tEplStatusResponse *
						   pStatusResponse_p);

static tEplKernel EplNmtMnuCheckNmtState(unsigned int uiNodeId_p,
					 tEplNmtMnuNodeInfo * pNodeInfo_p,
					 tEplNmtState NodeNmtState_p,
					 WORD wErrorCode_p,
					 tEplNmtState LocalNmtState_p);

static tEplKernel EplNmtMnuStartBootStep1(void);

static tEplKernel EplNmtMnuStartBootStep2(void);

static tEplKernel EplNmtMnuStartCheckCom(void);

static tEplKernel EplNmtMnuNodeBootStep2(unsigned int uiNodeId_p,
					 tEplNmtMnuNodeInfo * pNodeInfo_p);

static tEplKernel EplNmtMnuNodeCheckCom(unsigned int uiNodeId_p,
					tEplNmtMnuNodeInfo * pNodeInfo_p);

static tEplKernel EplNmtMnuStartNodes(void);

static tEplKernel EplNmtMnuProcessInternalEvent(unsigned int uiNodeId_p,
						tEplNmtState NodeNmtState_p,
						WORD wErrorCode_p,
						tEplNmtMnuIntNodeEvent
						NodeEvent_p);

static tEplKernel EplNmtMnuReset(void);

//=========================================================================//
//                                                                         //
//          P U B L I C   F U N C T I O N S                                //
//                                                                         //
//=========================================================================//

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuInit
//
// Description: init first instance of the module
//
//
//
// Parameters:
//
//
// Returns:     tEplKernel  = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplNmtMnuInit(tEplNmtMnuCbNodeEvent pfnCbNodeEvent_p,
			 tEplNmtMnuCbBootEvent pfnCbBootEvent_p)
{
	tEplKernel Ret;

	Ret = EplNmtMnuAddInstance(pfnCbNodeEvent_p, pfnCbBootEvent_p);

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuAddInstance
//
// Description: init other instances of the module
//
//
//
// Parameters:
//
//
// Returns:     tEplKernel  = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplNmtMnuAddInstance(tEplNmtMnuCbNodeEvent pfnCbNodeEvent_p,
				tEplNmtMnuCbBootEvent pfnCbBootEvent_p)
{
	tEplKernel Ret;

	Ret = kEplSuccessful;

	// reset instance structure
	EPL_MEMSET(&EplNmtMnuInstance_g, 0, sizeof(EplNmtMnuInstance_g));

	if ((pfnCbNodeEvent_p == NULL) || (pfnCbBootEvent_p == NULL)) {
		Ret = kEplNmtInvalidParam;
		goto Exit;
	}
	EplNmtMnuInstance_g.m_pfnCbNodeEvent = pfnCbNodeEvent_p;
	EplNmtMnuInstance_g.m_pfnCbBootEvent = pfnCbBootEvent_p;

	// initialize StatusRequest delay
	EplNmtMnuInstance_g.m_ulStatusRequestDelay = 5000L;

	// register NmtMnResponse callback function
	Ret =
	    EplDlluCalRegAsndService(kEplDllAsndNmtRequest,
				     EplNmtMnuCbNmtRequest,
				     kEplDllAsndFilterLocal);

      Exit:
	return Ret;

}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuDelInstance
//
// Description: delete instance
//
//
//
// Parameters:
//
//
// Returns:     tEplKernel  = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplNmtMnuDelInstance()
{
	tEplKernel Ret;

	Ret = kEplSuccessful;

	// deregister NmtMnResponse callback function
	Ret =
	    EplDlluCalRegAsndService(kEplDllAsndNmtRequest, NULL,
				     kEplDllAsndFilterNone);

	Ret = EplNmtMnuReset();

	return Ret;

}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuSendNmtCommandEx
//
// Description: sends the specified NMT command to the specified node.
//
// Parameters:  uiNodeId_p              = node ID to which the NMT command will be sent
//              NmtCommand_p            = NMT command
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplNmtMnuSendNmtCommandEx(unsigned int uiNodeId_p,
				     tEplNmtCommand NmtCommand_p,
				     void *pNmtCommandData_p,
				     unsigned int uiDataSize_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplFrameInfo FrameInfo;
	BYTE abBuffer[EPL_C_DLL_MINSIZE_NMTCMDEXT];
	tEplFrame *pFrame = (tEplFrame *) abBuffer;
	BOOL fSoftDeleteNode = FALSE;

	if ((uiNodeId_p == 0) || (uiNodeId_p > EPL_C_ADR_BROADCAST)) {	// invalid node ID specified
		Ret = kEplInvalidNodeId;
		goto Exit;
	}

	if ((pNmtCommandData_p != NULL)
	    && (uiDataSize_p >
		(EPL_C_DLL_MINSIZE_NMTCMDEXT - EPL_C_DLL_MINSIZE_NMTCMD))) {
		Ret = kEplNmtInvalidParam;
		goto Exit;
	}
	// $$$ d.k. may be check in future versions if the caller wants to perform prohibited state transitions
	//     the CN should not perform these transitions, but the expected NMT state will be changed and never fullfilled.

	// build frame
	EPL_MEMSET(pFrame, 0x00, sizeof(abBuffer));
	AmiSetByteToLe(&pFrame->m_le_bDstNodeId, (BYTE) uiNodeId_p);
	AmiSetByteToLe(&pFrame->m_Data.m_Asnd.m_le_bServiceId,
		       (BYTE) kEplDllAsndNmtCommand);
	AmiSetByteToLe(&pFrame->m_Data.m_Asnd.m_Payload.m_NmtCommandService.
		       m_le_bNmtCommandId, (BYTE) NmtCommand_p);
	if ((pNmtCommandData_p != NULL) && (uiDataSize_p > 0)) {	// copy command data to frame
		EPL_MEMCPY(&pFrame->m_Data.m_Asnd.m_Payload.m_NmtCommandService.
			   m_le_abNmtCommandData[0], pNmtCommandData_p,
			   uiDataSize_p);
	}
	// build info structure
	FrameInfo.m_NetTime.m_dwNanoSec = 0;
	FrameInfo.m_NetTime.m_dwSec = 0;
	FrameInfo.m_pFrame = pFrame;
	FrameInfo.m_uiFrameSize = sizeof(abBuffer);

	// send NMT-Request
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
	Ret = EplDlluCalAsyncSend(&FrameInfo,	// pointer to frameinfo
				  kEplDllAsyncReqPrioNmt);	// priority
#endif
	if (Ret != kEplSuccessful) {
		goto Exit;
	}

	EPL_DBGLVL_NMTMN_TRACE2("NMTCmd(%02X->%02X)\n", NmtCommand_p,
				uiNodeId_p);

	switch (NmtCommand_p) {
	case kEplNmtCmdStartNode:
	case kEplNmtCmdEnterPreOperational2:
	case kEplNmtCmdEnableReadyToOperate:
		{
			// nothing left to do,
			// because any further processing is done
			// when the NMT command is actually sent
			goto Exit;
		}

	case kEplNmtCmdStopNode:
		{
			fSoftDeleteNode = TRUE;
			break;
		}

	case kEplNmtCmdResetNode:
	case kEplNmtCmdResetCommunication:
	case kEplNmtCmdResetConfiguration:
	case kEplNmtCmdSwReset:
		{
			break;
		}

	default:
		goto Exit;
	}

	// remove CN from isochronous phase;
	// This must be done here and not when NMT command is actually sent
	// because it will be too late and may cause unwanted errors
	if (uiNodeId_p != EPL_C_ADR_BROADCAST) {
		if (fSoftDeleteNode == FALSE) {	// remove CN immediately from isochronous phase
			Ret = EplDlluCalDeleteNode(uiNodeId_p);
		} else {	// remove CN from isochronous phase softly
			Ret = EplDlluCalSoftDeleteNode(uiNodeId_p);
		}
	} else {		// do it for all active CNs
		for (uiNodeId_p = 1;
		     uiNodeId_p <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo);
		     uiNodeId_p++) {
			if ((EPL_NMTMNU_GET_NODEINFO(uiNodeId_p)->
			     m_dwNodeCfg & (EPL_NODEASSIGN_NODE_IS_CN |
					    EPL_NODEASSIGN_NODE_EXISTS)) != 0) {
				if (fSoftDeleteNode == FALSE) {	// remove CN immediately from isochronous phase
					Ret = EplDlluCalDeleteNode(uiNodeId_p);
				} else {	// remove CN from isochronous phase softly
					Ret =
					    EplDlluCalSoftDeleteNode
					    (uiNodeId_p);
				}
			}
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuSendNmtCommand
//
// Description: sends the specified NMT command to the specified node.
//
// Parameters:  uiNodeId_p              = node ID to which the NMT command will be sent
//              NmtCommand_p            = NMT command
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplNmtMnuSendNmtCommand(unsigned int uiNodeId_p,
				   tEplNmtCommand NmtCommand_p)
{
	tEplKernel Ret = kEplSuccessful;

	Ret = EplNmtMnuSendNmtCommandEx(uiNodeId_p, NmtCommand_p, NULL, 0);

//Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuTriggerStateChange
//
// Description: triggers the specified node command for the specified node.
//
// Parameters:  uiNodeId_p              = node ID for which the node command will be executed
//              NodeCommand_p           = node command
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplNmtMnuTriggerStateChange(unsigned int uiNodeId_p,
				       tEplNmtNodeCommand NodeCommand_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplNmtMnuIntNodeEvent NodeEvent;
	tEplObdSize ObdSize;
	BYTE bNmtState;
	WORD wErrorCode = EPL_E_NO_ERROR;

	if ((uiNodeId_p == 0) || (uiNodeId_p >= EPL_C_ADR_BROADCAST)) {
		Ret = kEplInvalidNodeId;
		goto Exit;
	}

	switch (NodeCommand_p) {
	case kEplNmtNodeCommandBoot:
		{
			NodeEvent = kEplNmtMnuIntNodeEventBoot;
			break;
		}

	case kEplNmtNodeCommandConfOk:
		{
			NodeEvent = kEplNmtMnuIntNodeEventConfigured;
			break;
		}

	case kEplNmtNodeCommandConfErr:
		{
			NodeEvent = kEplNmtMnuIntNodeEventError;
			wErrorCode = EPL_E_NMT_BPO1_CF_VERIFY;
			break;
		}

	case kEplNmtNodeCommandConfReset:
		{
			NodeEvent = kEplNmtMnuIntNodeEventExecReset;
			break;
		}

	default:
		{		// invalid node command
			goto Exit;
		}
	}

	// fetch current NMT state
	ObdSize = 1;
	Ret = EplObduReadEntry(0x1F8E, uiNodeId_p, &bNmtState, &ObdSize);
	if (Ret != kEplSuccessful) {
		goto Exit;
	}

	Ret = EplNmtMnuProcessInternalEvent(uiNodeId_p,
					    (tEplNmtState) (bNmtState |
							    EPL_NMT_TYPE_CS),
					    wErrorCode, NodeEvent);

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuCbNmtStateChange
//
// Description: callback function for NMT state changes
//
// Parameters:  NmtStateChange_p        = NMT state change event
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel PUBLIC EplNmtMnuCbNmtStateChange(tEplEventNmtStateChange
					    NmtStateChange_p)
{
	tEplKernel Ret = kEplSuccessful;

	// do work which must be done in that state
	switch (NmtStateChange_p.m_NewNmtState) {
		// EPL stack is not running
/*        case kEplNmtGsOff:
            break;

        // first init of the hardware
        case kEplNmtGsInitialising:
            break;

        // init of the manufacturer-specific profile area and the
        // standardised device profile area
        case kEplNmtGsResetApplication:
        {
            break;
        }

        // init of the communication profile area
        case kEplNmtGsResetCommunication:
        {
            break;
        }
*/
		// build the configuration with infos from OD
	case kEplNmtGsResetConfiguration:
		{
			DWORD dwTimeout;
			tEplObdSize ObdSize;

			// read object 0x1F80 NMT_StartUp_U32
			ObdSize = 4;
			Ret =
			    EplObduReadEntry(0x1F80, 0,
					     &EplNmtMnuInstance_g.
					     m_dwNmtStartup, &ObdSize);
			if (Ret != kEplSuccessful) {
				break;
			}
			// compute StatusReqDelay = object 0x1006 * EPL_C_NMT_STATREQ_CYCLE
			ObdSize = sizeof(dwTimeout);
			Ret = EplObduReadEntry(0x1006, 0, &dwTimeout, &ObdSize);
			if (Ret != kEplSuccessful) {
				break;
			}
			if (dwTimeout != 0L) {
				EplNmtMnuInstance_g.m_ulStatusRequestDelay =
				    dwTimeout * EPL_C_NMT_STATREQ_CYCLE / 1000L;
				if (EplNmtMnuInstance_g.
				    m_ulStatusRequestDelay == 0L) {
					EplNmtMnuInstance_g.m_ulStatusRequestDelay = 1L;	// at least 1 ms
				}
				// $$$ fetch and use MultiplexedCycleCount from OD
				EplNmtMnuInstance_g.m_ulTimeoutCheckCom =
				    dwTimeout * EPL_C_NMT_STATREQ_CYCLE / 1000L;
				if (EplNmtMnuInstance_g.m_ulTimeoutCheckCom ==
				    0L) {
					EplNmtMnuInstance_g.m_ulTimeoutCheckCom = 1L;	// at least 1 ms
				}
			}
			// fetch ReadyToOp Timeout from OD
			ObdSize = sizeof(dwTimeout);
			Ret = EplObduReadEntry(0x1F89, 5, &dwTimeout, &ObdSize);
			if (Ret != kEplSuccessful) {
				break;
			}
			if (dwTimeout != 0L) {
				// convert [us] to [ms]
				dwTimeout /= 1000L;
				if (dwTimeout == 0L) {
					dwTimeout = 1L;	// at least 1 ms
				}
				EplNmtMnuInstance_g.m_ulTimeoutReadyToOp =
				    dwTimeout;
			} else {
				EplNmtMnuInstance_g.m_ulTimeoutReadyToOp = 0L;
			}
			break;
		}
/*
        //-----------------------------------------------------------
        // CN part of the state machine

        // node liste for EPL-Frames and check timeout
        case kEplNmtCsNotActive:
        {
            break;
        }

        // node process only async frames
        case kEplNmtCsPreOperational1:
        {
            break;
        }

        // node process isochronus and asynchronus frames
        case kEplNmtCsPreOperational2:
        {
            break;
        }

        // node should be configured und application is ready
        case kEplNmtCsReadyToOperate:
        {
            break;
        }

        // normal work state
        case kEplNmtCsOperational:
        {
            break;
        }

        // node stopped by MN
        // -> only process asynchronus frames
        case kEplNmtCsStopped:
        {
            break;
        }

        // no EPL cycle
        // -> normal ethernet communication
        case kEplNmtCsBasicEthernet:
        {
            break;
        }
*/
		//-----------------------------------------------------------
		// MN part of the state machine

		// node listens for EPL-Frames and check timeout
	case kEplNmtMsNotActive:
		{
			break;
		}

		// node processes only async frames
	case kEplNmtMsPreOperational1:
		{
			DWORD dwTimeout;
			tEplTimerArg TimerArg;
			tEplObdSize ObdSize;
			tEplEvent Event;

			// clear global flags, e.g. reenable boot process
			EplNmtMnuInstance_g.m_wFlags = 0;

			// reset IdentResponses and running IdentRequests and StatusRequests
			Ret = EplIdentuReset();
			Ret = EplStatusuReset();

			// reset timers
			Ret = EplNmtMnuReset();

			// 2008/11/18 d.k. reset internal node info is not necessary,
			//                 because timer flags are important and other
			//                 things are reset by EplNmtMnuStartBootStep1().
/*
            EPL_MEMSET(EplNmtMnuInstance_g.m_aNodeInfo,
                       0,
                       sizeof (EplNmtMnuInstance_g.m_aNodeInfo));
*/

			// inform DLL about NMT state change,
			// so that it can clear the asynchonous queues and start the reduced cycle
			Event.m_EventSink = kEplEventSinkDllk;
			Event.m_EventType = kEplEventTypeDllkStartReducedCycle;
			EPL_MEMSET(&Event.m_NetTime, 0x00,
				   sizeof(Event.m_NetTime));
			Event.m_pArg = NULL;
			Event.m_uiSize = 0;
			Ret = EplEventuPost(&Event);
			if (Ret != kEplSuccessful) {
				break;
			}
			// reset all nodes
			// d.k.: skip this step if was just done before, e.g. because of a ResetNode command from a diagnostic node
			if (NmtStateChange_p.m_NmtEvent ==
			    kEplNmtEventTimerMsPreOp1) {
				BENCHMARK_MOD_07_TOGGLE(9);

				EPL_NMTMNU_DBG_POST_TRACE_VALUE(0,
								EPL_C_ADR_BROADCAST,
								kEplNmtCmdResetNode);

				Ret =
				    EplNmtMnuSendNmtCommand(EPL_C_ADR_BROADCAST,
							    kEplNmtCmdResetNode);
				if (Ret != kEplSuccessful) {
					break;
				}
			}
			// start network scan
			Ret = EplNmtMnuStartBootStep1();

			// start timer for 0x1F89/2 MNTimeoutPreOp1_U32
			ObdSize = sizeof(dwTimeout);
			Ret = EplObduReadEntry(0x1F89, 2, &dwTimeout, &ObdSize);
			if (Ret != kEplSuccessful) {
				break;
			}
			if (dwTimeout != 0L) {
				dwTimeout /= 1000L;
				if (dwTimeout == 0L) {
					dwTimeout = 1L;	// at least 1 ms
				}
				TimerArg.m_EventSink = kEplEventSinkNmtMnu;
				TimerArg.m_ulArg = 0;
				Ret =
				    EplTimeruModifyTimerMs(&EplNmtMnuInstance_g.
							   m_TimerHdlNmtState,
							   dwTimeout, TimerArg);
			}
			break;
		}

		// node processes isochronous and asynchronous frames
	case kEplNmtMsPreOperational2:
		{
			// add identified CNs to isochronous phase
			// send EnableReadyToOp to all identified CNs
			Ret = EplNmtMnuStartBootStep2();

			// wait for NMT state change of CNs
			break;
		}

		// node should be configured und application is ready
	case kEplNmtMsReadyToOperate:
		{
			// check if PRes of CNs are OK
			// d.k. that means wait CycleLength * MultiplexCycleCount (i.e. start timer)
			//      because Dllk checks PRes of CNs automatically in ReadyToOp
			Ret = EplNmtMnuStartCheckCom();
			break;
		}

		// normal work state
	case kEplNmtMsOperational:
		{
			// send StartNode to CNs
			// wait for NMT state change of CNs
			Ret = EplNmtMnuStartNodes();
			break;
		}

		// no EPL cycle
		// -> normal ethernet communication
	case kEplNmtMsBasicEthernet:
		{
			break;
		}

	default:
		{
//            TRACE0("EplNmtMnuCbNmtStateChange(): unhandled NMT state\n");
		}
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuCbCheckEvent
//
// Description: callback funktion for NMT events before they are actually executed.
//              The EPL API layer must forward NMT events from NmtCnu module.
//              This module will reject some NMT commands while MN.
//
// Parameters:  NmtEvent_p              = outstanding NMT event for approval
//
// Returns:     tEplKernel              = error code
//                      kEplReject      = reject the NMT event
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel PUBLIC EplNmtMnuCbCheckEvent(tEplNmtEvent NmtEvent_p)
{
	tEplKernel Ret = kEplSuccessful;

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtuProcessEvent
//
// Description: processes events from event queue
//
// Parameters:  pEvent_p        = pointer to event
//
// Returns:     tEplKernel      = errorcode
//
// State:
//
//---------------------------------------------------------------------------

EPLDLLEXPORT tEplKernel PUBLIC EplNmtMnuProcessEvent(tEplEvent * pEvent_p)
{
	tEplKernel Ret;

	Ret = kEplSuccessful;

	// process event
	switch (pEvent_p->m_EventType) {
		// timer event
	case kEplEventTypeTimer:
		{
			tEplTimerEventArg *pTimerEventArg =
			    (tEplTimerEventArg *) pEvent_p->m_pArg;
			unsigned int uiNodeId;

			uiNodeId =
			    (unsigned int)(pTimerEventArg->
					   m_ulArg &
					   EPL_NMTMNU_TIMERARG_NODE_MASK);
			if (uiNodeId != 0) {
				tEplObdSize ObdSize;
				BYTE bNmtState;
				tEplNmtMnuNodeInfo *pNodeInfo;

				pNodeInfo = EPL_NMTMNU_GET_NODEINFO(uiNodeId);

				ObdSize = 1;
				Ret =
				    EplObduReadEntry(0x1F8E, uiNodeId,
						     &bNmtState, &ObdSize);
				if (Ret != kEplSuccessful) {
					break;
				}

				if ((pTimerEventArg->
				     m_ulArg & EPL_NMTMNU_TIMERARG_IDENTREQ) !=
				    0L) {
					if ((pNodeInfo->
					     m_wFlags &
					     EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ)
					    != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR)) {	// this is an old (already deleted or modified) timer
						// but not the current timer
						// so discard it
						EPL_NMTMNU_DBG_POST_TRACE_VALUE
						    (kEplNmtMnuIntNodeEventTimerIdentReq,
						     uiNodeId,
						     ((pNodeInfo->
						       m_NodeState << 8)
						      | 0xFF));

						break;
					}
/*
                    EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerIdentReq,
                                                    uiNodeId,
                                                    ((pNodeInfo->m_NodeState << 8)
                                                     | 0x80
                                                     | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
                                                     | ((pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
*/
					Ret =
					    EplNmtMnuProcessInternalEvent
					    (uiNodeId,
					     (tEplNmtState) (bNmtState |
							     EPL_NMT_TYPE_CS),
					     EPL_E_NO_ERROR,
					     kEplNmtMnuIntNodeEventTimerIdentReq);
				}

				else if ((pTimerEventArg->
					  m_ulArg & EPL_NMTMNU_TIMERARG_STATREQ)
					 != 0L) {
					if ((pNodeInfo->
					     m_wFlags &
					     EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ)
					    != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR)) {	// this is an old (already deleted or modified) timer
						// but not the current timer
						// so discard it
						EPL_NMTMNU_DBG_POST_TRACE_VALUE
						    (kEplNmtMnuIntNodeEventTimerStatReq,
						     uiNodeId,
						     ((pNodeInfo->
						       m_NodeState << 8)
						      | 0xFF));

						break;
					}
/*
                    EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerStatReq,
                                                    uiNodeId,
                                                    ((pNodeInfo->m_NodeState << 8)
                                                     | 0x80
                                                     | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
                                                     | ((pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
*/
					Ret =
					    EplNmtMnuProcessInternalEvent
					    (uiNodeId,
					     (tEplNmtState) (bNmtState |
							     EPL_NMT_TYPE_CS),
					     EPL_E_NO_ERROR,
					     kEplNmtMnuIntNodeEventTimerStatReq);
				}

				else if ((pTimerEventArg->
					  m_ulArg &
					  EPL_NMTMNU_TIMERARG_STATE_MON) !=
					 0L) {
					if ((pNodeInfo->
					     m_wFlags &
					     EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ)
					    != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR)) {	// this is an old (already deleted or modified) timer
						// but not the current timer
						// so discard it
						EPL_NMTMNU_DBG_POST_TRACE_VALUE
						    (kEplNmtMnuIntNodeEventTimerStateMon,
						     uiNodeId,
						     ((pNodeInfo->
						       m_NodeState << 8)
						      | 0xFF));

						break;
					}
/*
                    EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerStatReq,
                                                    uiNodeId,
                                                    ((pNodeInfo->m_NodeState << 8)
                                                     | 0x80
                                                     | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
                                                     | ((pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
*/
					Ret =
					    EplNmtMnuProcessInternalEvent
					    (uiNodeId,
					     (tEplNmtState) (bNmtState |
							     EPL_NMT_TYPE_CS),
					     EPL_E_NO_ERROR,
					     kEplNmtMnuIntNodeEventTimerStateMon);
				}

				else if ((pTimerEventArg->
					  m_ulArg & EPL_NMTMNU_TIMERARG_LONGER)
					 != 0L) {
					if ((pNodeInfo->
					     m_wFlags &
					     EPL_NMTMNU_NODE_FLAG_COUNT_LONGER)
					    != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_LO)) {	// this is an old (already deleted or modified) timer
						// but not the current timer
						// so discard it
						EPL_NMTMNU_DBG_POST_TRACE_VALUE
						    (kEplNmtMnuIntNodeEventTimerLonger,
						     uiNodeId,
						     ((pNodeInfo->
						       m_NodeState << 8)
						      | 0xFF));

						break;
					}
/*
                    EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerLonger,
                                                    uiNodeId,
                                                    ((pNodeInfo->m_NodeState << 8)
                                                     | 0x80
                                                     | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_LONGER) >> 6)
                                                     | ((pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_LO) >> 8)));
*/
					Ret =
					    EplNmtMnuProcessInternalEvent
					    (uiNodeId,
					     (tEplNmtState) (bNmtState |
							     EPL_NMT_TYPE_CS),
					     EPL_E_NO_ERROR,
					     kEplNmtMnuIntNodeEventTimerLonger);
				}

			} else {	// global timer event
			}
			break;
		}

	case kEplEventTypeHeartbeat:
		{
			tEplHeartbeatEvent *pHeartbeatEvent =
			    (tEplHeartbeatEvent *) pEvent_p->m_pArg;

			Ret =
			    EplNmtMnuProcessInternalEvent(pHeartbeatEvent->
							  m_uiNodeId,
							  pHeartbeatEvent->
							  m_NmtState,
							  pHeartbeatEvent->
							  m_wErrorCode,
							  kEplNmtMnuIntNodeEventHeartbeat);
			break;
		}

	case kEplEventTypeNmtMnuNmtCmdSent:
		{
			tEplFrame *pFrame = (tEplFrame *) pEvent_p->m_pArg;
			unsigned int uiNodeId;
			tEplNmtCommand NmtCommand;
			BYTE bNmtState;

			uiNodeId = AmiGetByteFromLe(&pFrame->m_le_bDstNodeId);
			NmtCommand =
			    (tEplNmtCommand) AmiGetByteFromLe(&pFrame->m_Data.
							      m_Asnd.m_Payload.
							      m_NmtCommandService.
							      m_le_bNmtCommandId);

			switch (NmtCommand) {
			case kEplNmtCmdStartNode:
				bNmtState =
				    (BYTE) (kEplNmtCsOperational & 0xFF);
				break;

			case kEplNmtCmdStopNode:
				bNmtState = (BYTE) (kEplNmtCsStopped & 0xFF);
				break;

			case kEplNmtCmdEnterPreOperational2:
				bNmtState =
				    (BYTE) (kEplNmtCsPreOperational2 & 0xFF);
				break;

			case kEplNmtCmdEnableReadyToOperate:
				// d.k. do not change expected node state, because of DS 1.0.0 7.3.1.2.1 Plain NMT State Command
				//      and because node may not change NMT state within EPL_C_NMT_STATE_TOLERANCE
				bNmtState =
				    (BYTE) (kEplNmtCsPreOperational2 & 0xFF);
				break;

			case kEplNmtCmdResetNode:
			case kEplNmtCmdResetCommunication:
			case kEplNmtCmdResetConfiguration:
			case kEplNmtCmdSwReset:
				bNmtState = (BYTE) (kEplNmtCsNotActive & 0xFF);
				// EplNmtMnuProcessInternalEvent() sets internal node state to kEplNmtMnuNodeStateUnknown
				// after next unresponded IdentRequest/StatusRequest
				break;

			default:
				goto Exit;
			}

			// process as internal event which update expected NMT state in OD
			if (uiNodeId != EPL_C_ADR_BROADCAST) {
				Ret = EplNmtMnuProcessInternalEvent(uiNodeId,
								    (tEplNmtState)
								    (bNmtState |
								     EPL_NMT_TYPE_CS),
								    0,
								    kEplNmtMnuIntNodeEventNmtCmdSent);

			} else {	// process internal event for all active nodes (except myself)

				for (uiNodeId = 1;
				     uiNodeId <=
				     tabentries(EplNmtMnuInstance_g.
						m_aNodeInfo); uiNodeId++) {
					if ((EPL_NMTMNU_GET_NODEINFO(uiNodeId)->
					     m_dwNodeCfg &
					     (EPL_NODEASSIGN_NODE_IS_CN |
					      EPL_NODEASSIGN_NODE_EXISTS)) !=
					    0) {
						Ret =
						    EplNmtMnuProcessInternalEvent
						    (uiNodeId,
						     (tEplNmtState) (bNmtState |
								     EPL_NMT_TYPE_CS),
						     0,
						     kEplNmtMnuIntNodeEventNmtCmdSent);

						if (Ret != kEplSuccessful) {
							goto Exit;
						}
					}
				}
			}

			break;
		}

	default:
		{
			Ret = kEplNmtInvalidEvent;
		}

	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuGetRunningTimerStatReq
//
// Description: returns a bit field with running StatReq timers
//              just for debugging purposes
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel PUBLIC EplNmtMnuGetDiagnosticInfo(unsigned int
					     *puiMandatorySlaveCount_p,
					     unsigned int
					     *puiSignalSlaveCount_p,
					     WORD * pwFlags_p)
{
	tEplKernel Ret = kEplSuccessful;

	if ((puiMandatorySlaveCount_p == NULL)
	    || (puiSignalSlaveCount_p == NULL)
	    || (pwFlags_p == NULL)) {
		Ret = kEplNmtInvalidParam;
		goto Exit;
	}

	*puiMandatorySlaveCount_p = EplNmtMnuInstance_g.m_uiMandatorySlaveCount;
	*puiSignalSlaveCount_p = EplNmtMnuInstance_g.m_uiSignalSlaveCount;
	*pwFlags_p = EplNmtMnuInstance_g.m_wFlags;

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuGetRunningTimerStatReq
//
// Description: returns a bit field with running StatReq timers
//              just for debugging purposes
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------
/*
DWORD EplNmtMnuGetRunningTimerStatReq(void)
{
tEplKernel      Ret = kEplSuccessful;
unsigned int    uiIndex;
tEplNmtMnuNodeInfo* pNodeInfo;

    pNodeInfo = EplNmtMnuInstance_g.m_aNodeInfo;
    for (uiIndex = 1; uiIndex <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo); uiIndex++, pNodeInfo++)
    {
        if (pNodeInfo->m_NodeState == kEplNmtMnuNodeStateConfigured)
        {
            // reset flag "scanned once"
            pNodeInfo->m_wFlags &= ~EPL_NMTMNU_NODE_FLAG_SCANNED;

            Ret = EplNmtMnuNodeBootStep2(uiIndex, pNodeInfo);
            if (Ret != kEplSuccessful)
            {
                goto Exit;
            }
            EplNmtMnuInstance_g.m_uiSignalSlaveCount++;
            // signal slave counter shall be decremented if StatusRequest was sent once to a CN
            // mandatory slave counter shall be decremented if mandatory CN is ReadyToOp
        }
    }

Exit:
    return Ret;
}
*/

//=========================================================================//
//                                                                         //
//          P R I V A T E   F U N C T I O N S                              //
//                                                                         //
//=========================================================================//

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuCbNmtRequest
//
// Description: callback funktion for NmtRequest
//
// Parameters:  pFrameInfo_p            = Frame with the NmtRequest
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel PUBLIC EplNmtMnuCbNmtRequest(tEplFrameInfo * pFrameInfo_p)
{
	tEplKernel Ret = kEplSuccessful;

	// $$$ perform NMTRequest
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuCbIdentResponse
//
// Description: callback funktion for IdentResponse
//
// Parameters:  uiNodeId_p              = node ID for which IdentReponse was received
//              pIdentResponse_p        = pointer to IdentResponse
//                                        is NULL if node did not answer
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel PUBLIC EplNmtMnuCbIdentResponse(unsigned int uiNodeId_p,
						  tEplIdentResponse *
						  pIdentResponse_p)
{
	tEplKernel Ret = kEplSuccessful;

	if (pIdentResponse_p == NULL) {	// node did not answer
		Ret = EplNmtMnuProcessInternalEvent(uiNodeId_p, kEplNmtCsNotActive, EPL_E_NMT_NO_IDENT_RES,	// was EPL_E_NO_ERROR
						    kEplNmtMnuIntNodeEventNoIdentResponse);
	} else {		// node answered IdentRequest
		tEplObdSize ObdSize;
		DWORD dwDevType;
		WORD wErrorCode = EPL_E_NO_ERROR;
		tEplNmtState NmtState =
		    (tEplNmtState) (AmiGetByteFromLe
				    (&pIdentResponse_p->
				     m_le_bNmtStatus) | EPL_NMT_TYPE_CS);

		// check IdentResponse $$$ move to ProcessIntern, because this function may be called also if CN

		// check DeviceType (0x1F84)
		ObdSize = 4;
		Ret =
		    EplObduReadEntry(0x1F84, uiNodeId_p, &dwDevType, &ObdSize);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
		if (dwDevType != 0L) {	// actually compare it with DeviceType from IdentResponse
			if (AmiGetDwordFromLe(&pIdentResponse_p->m_le_dwDeviceType) != dwDevType) {	// wrong DeviceType
				NmtState = kEplNmtCsNotActive;
				wErrorCode = EPL_E_NMT_BPO1_DEVICE_TYPE;
			}
		}

		Ret = EplNmtMnuProcessInternalEvent(uiNodeId_p,
						    NmtState,
						    wErrorCode,
						    kEplNmtMnuIntNodeEventIdentResponse);
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuCbStatusResponse
//
// Description: callback funktion for StatusResponse
//
// Parameters:  uiNodeId_p              = node ID for which IdentReponse was received
//              pIdentResponse_p        = pointer to IdentResponse
//                                        is NULL if node did not answer
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel PUBLIC EplNmtMnuCbStatusResponse(unsigned int uiNodeId_p,
						   tEplStatusResponse *
						   pStatusResponse_p)
{
	tEplKernel Ret = kEplSuccessful;

	if (pStatusResponse_p == NULL) {	// node did not answer
		Ret = EplNmtMnuProcessInternalEvent(uiNodeId_p, kEplNmtCsNotActive, EPL_E_NMT_NO_STATUS_RES,	// was EPL_E_NO_ERROR
						    kEplNmtMnuIntNodeEventNoStatusResponse);
	} else {		// node answered StatusRequest
		Ret = EplNmtMnuProcessInternalEvent(uiNodeId_p,
						    (tEplNmtState)
						    (AmiGetByteFromLe
						     (&pStatusResponse_p->
						      m_le_bNmtStatus) |
						     EPL_NMT_TYPE_CS),
						    EPL_E_NO_ERROR,
						    kEplNmtMnuIntNodeEventStatusResponse);
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuStartBootStep1
//
// Description: starts BootStep1
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuStartBootStep1(void)
{
	tEplKernel Ret = kEplSuccessful;
	unsigned int uiSubIndex;
	unsigned int uiLocalNodeId;
	DWORD dwNodeCfg;
	tEplObdSize ObdSize;

	// $$$ d.k.: save current time for 0x1F89/2 MNTimeoutPreOp1_U32

	// start network scan
	EplNmtMnuInstance_g.m_uiMandatorySlaveCount = 0;
	EplNmtMnuInstance_g.m_uiSignalSlaveCount = 0;
	// check 0x1F81
	uiLocalNodeId = EplObduGetNodeId();
	for (uiSubIndex = 1; uiSubIndex <= 254; uiSubIndex++) {
		ObdSize = 4;
		Ret =
		    EplObduReadEntry(0x1F81, uiSubIndex, &dwNodeCfg, &ObdSize);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
		if (uiSubIndex != uiLocalNodeId) {
			// reset flags "not scanned" and "isochronous"
			EPL_NMTMNU_GET_NODEINFO(uiSubIndex)->m_wFlags &=
			    ~(EPL_NMTMNU_NODE_FLAG_ISOCHRON |
			      EPL_NMTMNU_NODE_FLAG_NOT_SCANNED);

			if (uiSubIndex == EPL_C_ADR_DIAG_DEF_NODE_ID) {	// diagnostic node must be scanned by MN in any case
				dwNodeCfg |=
				    (EPL_NODEASSIGN_NODE_IS_CN |
				     EPL_NODEASSIGN_NODE_EXISTS);
				// and it must be isochronously accessed
				dwNodeCfg &= ~EPL_NODEASSIGN_ASYNCONLY_NODE;
			}
			// save node config in local node info structure
			EPL_NMTMNU_GET_NODEINFO(uiSubIndex)->m_dwNodeCfg =
			    dwNodeCfg;
			EPL_NMTMNU_GET_NODEINFO(uiSubIndex)->m_NodeState =
			    kEplNmtMnuNodeStateUnknown;

			if ((dwNodeCfg & (EPL_NODEASSIGN_NODE_IS_CN | EPL_NODEASSIGN_NODE_EXISTS)) != 0) {	// node is configured as CN
				// identify the node
				Ret =
				    EplIdentuRequestIdentResponse(uiSubIndex,
								  EplNmtMnuCbIdentResponse);
				if (Ret != kEplSuccessful) {
					goto Exit;
				}
				// set flag "not scanned"
				EPL_NMTMNU_GET_NODEINFO(uiSubIndex)->m_wFlags |=
				    EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
				EplNmtMnuInstance_g.m_uiSignalSlaveCount++;
				// signal slave counter shall be decremented if IdentRequest was sent once to a CN

				if ((dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// node is a mandatory CN
					EplNmtMnuInstance_g.
					    m_uiMandatorySlaveCount++;
					// mandatory slave counter shall be decremented if mandatory CN was configured successfully
				}
			}
		} else {	// subindex of MN
			if ((dwNodeCfg & (EPL_NODEASSIGN_MN_PRES | EPL_NODEASSIGN_NODE_EXISTS)) != 0) {	// MN shall send PRes
				tEplDllNodeInfo DllNodeInfo;

				EPL_MEMSET(&DllNodeInfo, 0,
					   sizeof(DllNodeInfo));
				DllNodeInfo.m_uiNodeId = uiLocalNodeId;

				Ret = EplDlluCalAddNode(&DllNodeInfo);
			}
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuStartBootStep2
//
// Description: starts BootStep2.
//              That means add nodes to isochronous phase and send
//              NMT EnableReadyToOp.
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuStartBootStep2(void)
{
	tEplKernel Ret = kEplSuccessful;
	unsigned int uiIndex;
	tEplNmtMnuNodeInfo *pNodeInfo;

	if ((EplNmtMnuInstance_g.m_wFlags & EPL_NMTMNU_FLAG_HALTED) == 0) {	// boot process is not halted
		// add nodes to isochronous phase and send NMT EnableReadyToOp
		EplNmtMnuInstance_g.m_uiMandatorySlaveCount = 0;
		EplNmtMnuInstance_g.m_uiSignalSlaveCount = 0;
		// reset flag that application was informed about possible state change
		EplNmtMnuInstance_g.m_wFlags &= ~EPL_NMTMNU_FLAG_APP_INFORMED;

		pNodeInfo = EplNmtMnuInstance_g.m_aNodeInfo;
		for (uiIndex = 1;
		     uiIndex <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo);
		     uiIndex++, pNodeInfo++) {
			if (pNodeInfo->m_NodeState ==
			    kEplNmtMnuNodeStateConfigured) {
				Ret =
				    EplNmtMnuNodeBootStep2(uiIndex, pNodeInfo);
				if (Ret != kEplSuccessful) {
					goto Exit;
				}
				// set flag "not scanned"
				pNodeInfo->m_wFlags |=
				    EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;

				EplNmtMnuInstance_g.m_uiSignalSlaveCount++;
				// signal slave counter shall be decremented if StatusRequest was sent once to a CN

				if ((pNodeInfo->m_dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// node is a mandatory CN
					EplNmtMnuInstance_g.
					    m_uiMandatorySlaveCount++;
				}
				// mandatory slave counter shall be decremented if mandatory CN is ReadyToOp
			}
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuNodeBootStep2
//
// Description: starts BootStep2 for the specified node.
//              This means the CN is added to isochronous phase if not
//              async-only and it gets the NMT command EnableReadyToOp.
//              The CN must be in node state Configured, when it enters
//              BootStep2. When BootStep2 finishes, the CN is in node state
//              ReadyToOp.
//              If TimeoutReadyToOp in object 0x1F89/5 is configured,
//              TimerHdlLonger will be started with this timeout.
//
// Parameters:  uiNodeId_p              = node ID
//              pNodeInfo_p             = pointer to internal node info structure
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuNodeBootStep2(unsigned int uiNodeId_p,
					 tEplNmtMnuNodeInfo * pNodeInfo_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplDllNodeInfo DllNodeInfo;
	DWORD dwNodeCfg;
	tEplObdSize ObdSize;
	tEplTimerArg TimerArg;

	dwNodeCfg = pNodeInfo_p->m_dwNodeCfg;
	if ((dwNodeCfg & EPL_NODEASSIGN_ASYNCONLY_NODE) == 0) {	// add node to isochronous phase
		DllNodeInfo.m_uiNodeId = uiNodeId_p;
		ObdSize = 4;
		Ret =
		    EplObduReadEntry(0x1F92, uiNodeId_p,
				     &DllNodeInfo.m_dwPresTimeout, &ObdSize);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

		ObdSize = 2;
		Ret =
		    EplObduReadEntry(0x1F8B, uiNodeId_p,
				     &DllNodeInfo.m_wPreqPayloadLimit,
				     &ObdSize);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

		ObdSize = 2;
		Ret =
		    EplObduReadEntry(0x1F8D, uiNodeId_p,
				     &DllNodeInfo.m_wPresPayloadLimit,
				     &ObdSize);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

		pNodeInfo_p->m_wFlags |= EPL_NMTMNU_NODE_FLAG_ISOCHRON;

		Ret = EplDlluCalAddNode(&DllNodeInfo);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

	}

	EPL_NMTMNU_DBG_POST_TRACE_VALUE(0,
					uiNodeId_p,
					kEplNmtCmdEnableReadyToOperate);

	Ret =
	    EplNmtMnuSendNmtCommand(uiNodeId_p, kEplNmtCmdEnableReadyToOperate);
	if (Ret != kEplSuccessful) {
		goto Exit;
	}

	if (EplNmtMnuInstance_g.m_ulTimeoutReadyToOp != 0L) {	// start timer
		// when the timer expires the CN must be ReadyToOp
		EPL_NMTMNU_SET_FLAGS_TIMERARG_LONGER(pNodeInfo_p, uiNodeId_p,
						     TimerArg);
//        TimerArg.m_EventSink = kEplEventSinkNmtMnu;
//        TimerArg.m_ulArg = EPL_NMTMNU_TIMERARG_LONGER | uiNodeId_p;
		Ret =
		    EplTimeruModifyTimerMs(&pNodeInfo_p->m_TimerHdlLonger,
					   EplNmtMnuInstance_g.
					   m_ulTimeoutReadyToOp, TimerArg);
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuStartCheckCom
//
// Description: starts CheckCommunication
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuStartCheckCom(void)
{
	tEplKernel Ret = kEplSuccessful;
	unsigned int uiIndex;
	tEplNmtMnuNodeInfo *pNodeInfo;

	if ((EplNmtMnuInstance_g.m_wFlags & EPL_NMTMNU_FLAG_HALTED) == 0) {	// boot process is not halted
		// wait some time and check that no communication error occurs
		EplNmtMnuInstance_g.m_uiMandatorySlaveCount = 0;
		EplNmtMnuInstance_g.m_uiSignalSlaveCount = 0;
		// reset flag that application was informed about possible state change
		EplNmtMnuInstance_g.m_wFlags &= ~EPL_NMTMNU_FLAG_APP_INFORMED;

		pNodeInfo = EplNmtMnuInstance_g.m_aNodeInfo;
		for (uiIndex = 1;
		     uiIndex <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo);
		     uiIndex++, pNodeInfo++) {
			if (pNodeInfo->m_NodeState ==
			    kEplNmtMnuNodeStateReadyToOp) {
				Ret = EplNmtMnuNodeCheckCom(uiIndex, pNodeInfo);
				if (Ret == kEplReject) {	// timer was started
					// wait until it expires
					if ((pNodeInfo->m_dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// node is a mandatory CN
						EplNmtMnuInstance_g.
						    m_uiMandatorySlaveCount++;
					}
				} else if (Ret != kEplSuccessful) {
					goto Exit;
				}
				// set flag "not scanned"
				pNodeInfo->m_wFlags |=
				    EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;

				EplNmtMnuInstance_g.m_uiSignalSlaveCount++;
				// signal slave counter shall be decremented if timeout elapsed and regardless of an error
				// mandatory slave counter shall be decremented if timeout elapsed and no error occured
			}
		}
	}

	Ret = kEplSuccessful;

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuNodeCheckCom
//
// Description: checks communication of the specified node.
//              That means wait some time and if no error occured everything
//              is OK.
//
// Parameters:  uiNodeId_p              = node ID
//              pNodeInfo_p             = pointer to internal node info structure
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuNodeCheckCom(unsigned int uiNodeId_p,
					tEplNmtMnuNodeInfo * pNodeInfo_p)
{
	tEplKernel Ret = kEplSuccessful;
	DWORD dwNodeCfg;
	tEplTimerArg TimerArg;

	dwNodeCfg = pNodeInfo_p->m_dwNodeCfg;
	if (((dwNodeCfg & EPL_NODEASSIGN_ASYNCONLY_NODE) == 0)
	    && (EplNmtMnuInstance_g.m_ulTimeoutCheckCom != 0L)) {	// CN is not async-only and timeout for CheckCom was set

		// check communication,
		// that means wait some time and if no error occured everything is OK;

		// start timer (when the timer expires the CN must be still ReadyToOp)
		EPL_NMTMNU_SET_FLAGS_TIMERARG_LONGER(pNodeInfo_p, uiNodeId_p,
						     TimerArg);
//        TimerArg.m_EventSink = kEplEventSinkNmtMnu;
//        TimerArg.m_ulArg = EPL_NMTMNU_TIMERARG_LONGER | uiNodeId_p;
		Ret =
		    EplTimeruModifyTimerMs(&pNodeInfo_p->m_TimerHdlLonger,
					   EplNmtMnuInstance_g.
					   m_ulTimeoutCheckCom, TimerArg);

		// update mandatory slave counter, because timer was started
		if (Ret == kEplSuccessful) {
			Ret = kEplReject;
		}
	} else {		// timer was not started
		// assume everything is OK
		pNodeInfo_p->m_NodeState = kEplNmtMnuNodeStateComChecked;
	}

//Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuStartNodes
//
// Description: really starts all nodes which are ReadyToOp and CheckCom did not fail
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuStartNodes(void)
{
	tEplKernel Ret = kEplSuccessful;
	unsigned int uiIndex;
	tEplNmtMnuNodeInfo *pNodeInfo;

	if ((EplNmtMnuInstance_g.m_wFlags & EPL_NMTMNU_FLAG_HALTED) == 0) {	// boot process is not halted
		// send NMT command Start Node
		EplNmtMnuInstance_g.m_uiMandatorySlaveCount = 0;
		EplNmtMnuInstance_g.m_uiSignalSlaveCount = 0;
		// reset flag that application was informed about possible state change
		EplNmtMnuInstance_g.m_wFlags &= ~EPL_NMTMNU_FLAG_APP_INFORMED;

		pNodeInfo = EplNmtMnuInstance_g.m_aNodeInfo;
		for (uiIndex = 1;
		     uiIndex <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo);
		     uiIndex++, pNodeInfo++) {
			if (pNodeInfo->m_NodeState ==
			    kEplNmtMnuNodeStateComChecked) {
				if ((EplNmtMnuInstance_g.
				     m_dwNmtStartup & EPL_NMTST_STARTALLNODES)
				    == 0) {
					EPL_NMTMNU_DBG_POST_TRACE_VALUE(0,
									uiIndex,
									kEplNmtCmdStartNode);

					Ret =
					    EplNmtMnuSendNmtCommand(uiIndex,
								    kEplNmtCmdStartNode);
					if (Ret != kEplSuccessful) {
						goto Exit;
					}
				}

				if ((pNodeInfo->m_dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// node is a mandatory CN
					EplNmtMnuInstance_g.
					    m_uiMandatorySlaveCount++;
				}
				// set flag "not scanned"
				pNodeInfo->m_wFlags |=
				    EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;

				EplNmtMnuInstance_g.m_uiSignalSlaveCount++;
				// signal slave counter shall be decremented if StatusRequest was sent once to a CN
				// mandatory slave counter shall be decremented if mandatory CN is OPERATIONAL
			}
		}

		// $$$ inform application if EPL_NMTST_NO_STARTNODE is set

		if ((EplNmtMnuInstance_g.
		     m_dwNmtStartup & EPL_NMTST_STARTALLNODES) != 0) {
			EPL_NMTMNU_DBG_POST_TRACE_VALUE(0, EPL_C_ADR_BROADCAST,
							kEplNmtCmdStartNode);

			Ret =
			    EplNmtMnuSendNmtCommand(EPL_C_ADR_BROADCAST,
						    kEplNmtCmdStartNode);
			if (Ret != kEplSuccessful) {
				goto Exit;
			}
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuProcessInternalEvent
//
// Description: processes internal node events
//
// Parameters:  uiNodeId_p              = node ID
//              NodeNmtState_p          = NMT state of CN
//              NodeEvent_p             = occured events
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuProcessInternalEvent(unsigned int uiNodeId_p,
						tEplNmtState NodeNmtState_p,
						WORD wErrorCode_p,
						tEplNmtMnuIntNodeEvent
						NodeEvent_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplNmtState NmtState;
	tEplNmtMnuNodeInfo *pNodeInfo;
	tEplTimerArg TimerArg;

	pNodeInfo = EPL_NMTMNU_GET_NODEINFO(uiNodeId_p);
	NmtState = EplNmtuGetNmtState();
	if (NmtState <= kEplNmtMsNotActive) {	// MN is not active
		goto Exit;
	}

	switch (NodeEvent_p) {
	case kEplNmtMnuIntNodeEventIdentResponse:
		{
			BYTE bNmtState;

			EPL_NMTMNU_DBG_POST_TRACE_VALUE(NodeEvent_p,
							uiNodeId_p,
							pNodeInfo->m_NodeState);

			if (pNodeInfo->m_NodeState !=
			    kEplNmtMnuNodeStateResetConf) {
				pNodeInfo->m_NodeState =
				    kEplNmtMnuNodeStateIdentified;
			}
			// reset flags ISOCHRON and NMT_CMD_ISSUED
			pNodeInfo->m_wFlags &= ~(EPL_NMTMNU_NODE_FLAG_ISOCHRON
						 |
						 EPL_NMTMNU_NODE_FLAG_NMT_CMD_ISSUED);

			if ((NmtState == kEplNmtMsPreOperational1)
			    &&
			    ((pNodeInfo->
			      m_wFlags & EPL_NMTMNU_NODE_FLAG_NOT_SCANNED) !=
			     0)) {
				// decrement only signal slave count
				EplNmtMnuInstance_g.m_uiSignalSlaveCount--;
				pNodeInfo->m_wFlags &=
				    ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
			}
			// update object 0x1F8F NMT_MNNodeExpState_AU8 to PreOp1 (even if local state >= PreOp2)
			bNmtState = (BYTE) (kEplNmtCsPreOperational1 & 0xFF);
			Ret =
			    EplObduWriteEntry(0x1F8F, uiNodeId_p, &bNmtState,
					      1);

			// check NMT state of CN
			Ret =
			    EplNmtMnuCheckNmtState(uiNodeId_p, pNodeInfo,
						   NodeNmtState_p, wErrorCode_p,
						   NmtState);
			if (Ret != kEplSuccessful) {
				if (Ret == kEplReject) {
					Ret = kEplSuccessful;
				}
				break;
			}
			// request StatusResponse immediately,
			// because we want a fast boot-up of CNs
			Ret =
			    EplStatusuRequestStatusResponse(uiNodeId_p,
							    EplNmtMnuCbStatusResponse);
			if (Ret != kEplSuccessful) {
				EPL_NMTMNU_DBG_POST_TRACE_VALUE(NodeEvent_p,
								uiNodeId_p,
								Ret);

				if (Ret == kEplInvalidOperation) {	// the only situation when this should happen is, when
					// StatusResponse was already requested from within
					// the StatReq timer event.
					// so ignore this error.
					Ret = kEplSuccessful;
				} else {
					break;
				}
			}

			if (pNodeInfo->m_NodeState !=
			    kEplNmtMnuNodeStateResetConf) {
				// inform application
				Ret =
				    EplNmtMnuInstance_g.
				    m_pfnCbNodeEvent(uiNodeId_p,
						     kEplNmtNodeEventFound,
						     NodeNmtState_p,
						     EPL_E_NO_ERROR,
						     (pNodeInfo->
						      m_dwNodeCfg &
						      EPL_NODEASSIGN_MANDATORY_CN)
						     != 0);
				if (Ret == kEplReject) {	// interrupt boot process on user request
					EPL_NMTMNU_DBG_POST_TRACE_VALUE
					    (NodeEvent_p, uiNodeId_p,
					     ((pNodeInfo->m_NodeState << 8)
					      | Ret));

					Ret = kEplSuccessful;
					break;
				} else if (Ret != kEplSuccessful) {
					EPL_NMTMNU_DBG_POST_TRACE_VALUE
					    (NodeEvent_p, uiNodeId_p,
					     ((pNodeInfo->m_NodeState << 8)
					      | Ret));

					break;
				}
			}
			// continue BootStep1
		}

	case kEplNmtMnuIntNodeEventBoot:
		{

			// $$$ check identification (vendor ID, product code, revision no, serial no)

			if (pNodeInfo->m_NodeState ==
			    kEplNmtMnuNodeStateIdentified) {
				// $$$ check software

				// check/start configuration
				// inform application
				Ret =
				    EplNmtMnuInstance_g.
				    m_pfnCbNodeEvent(uiNodeId_p,
						     kEplNmtNodeEventCheckConf,
						     NodeNmtState_p,
						     EPL_E_NO_ERROR,
						     (pNodeInfo->
						      m_dwNodeCfg &
						      EPL_NODEASSIGN_MANDATORY_CN)
						     != 0);
				if (Ret == kEplReject) {	// interrupt boot process on user request
					EPL_NMTMNU_DBG_POST_TRACE_VALUE
					    (kEplNmtMnuIntNodeEventBoot,
					     uiNodeId_p,
					     ((pNodeInfo->m_NodeState << 8)
					      | Ret));

					Ret = kEplSuccessful;
					break;
				} else if (Ret != kEplSuccessful) {
					EPL_NMTMNU_DBG_POST_TRACE_VALUE
					    (kEplNmtMnuIntNodeEventBoot,
					     uiNodeId_p,
					     ((pNodeInfo->m_NodeState << 8)
					      | Ret));

					break;
				}
			} else if (pNodeInfo->m_NodeState != kEplNmtMnuNodeStateResetConf) {	// wrong CN state
				// ignore event
				break;
			}
			// $$$ d.k.: currently we assume configuration is OK

			// continue BootStep1
		}

	case kEplNmtMnuIntNodeEventConfigured:
		{
			if ((pNodeInfo->m_NodeState !=
			     kEplNmtMnuNodeStateIdentified)
			    && (pNodeInfo->m_NodeState != kEplNmtMnuNodeStateResetConf)) {	// wrong CN state
				// ignore event
				break;
			}

			pNodeInfo->m_NodeState = kEplNmtMnuNodeStateConfigured;

			if (NmtState == kEplNmtMsPreOperational1) {
				if ((pNodeInfo->m_dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// decrement mandatory CN counter
					EplNmtMnuInstance_g.
					    m_uiMandatorySlaveCount--;
				}
			} else {
				// put optional node to next step (BootStep2)
				Ret =
				    EplNmtMnuNodeBootStep2(uiNodeId_p,
							   pNodeInfo);
			}
			break;
		}

	case kEplNmtMnuIntNodeEventNoIdentResponse:
		{
			if ((NmtState == kEplNmtMsPreOperational1)
			    &&
			    ((pNodeInfo->
			      m_wFlags & EPL_NMTMNU_NODE_FLAG_NOT_SCANNED) !=
			     0)) {
				// decrement only signal slave count
				EplNmtMnuInstance_g.m_uiSignalSlaveCount--;
				pNodeInfo->m_wFlags &=
				    ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
			}

			if (pNodeInfo->m_NodeState !=
			    kEplNmtMnuNodeStateResetConf) {
				pNodeInfo->m_NodeState =
				    kEplNmtMnuNodeStateUnknown;
			}
			// $$$ d.k. check start time for 0x1F89/2 MNTimeoutPreOp1_U32
			// $$$ d.k. check individual timeout 0x1F89/6 MNIdentificationTimeout_U32
			// if mandatory node and timeout elapsed -> halt boot procedure
			// trigger IdentRequest again (if >= PreOp2, after delay)
			if (NmtState >= kEplNmtMsPreOperational2) {	// start timer
				EPL_NMTMNU_SET_FLAGS_TIMERARG_IDENTREQ
				    (pNodeInfo, uiNodeId_p, TimerArg);
//                TimerArg.m_EventSink = kEplEventSinkNmtMnu;
//                TimerArg.m_ulArg = EPL_NMTMNU_TIMERARG_IDENTREQ | uiNodeId_p;
/*
                EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventNoIdentResponse,
                                                uiNodeId_p,
                                                ((pNodeInfo->m_NodeState << 8)
                                                 | 0x80
                                                 | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
                                                 | ((TimerArg.m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
*/
				Ret =
				    EplTimeruModifyTimerMs(&pNodeInfo->
							   m_TimerHdlStatReq,
							   EplNmtMnuInstance_g.
							   m_ulStatusRequestDelay,
							   TimerArg);
			} else {	// trigger IdentRequest immediately
				Ret =
				    EplIdentuRequestIdentResponse(uiNodeId_p,
								  EplNmtMnuCbIdentResponse);
			}
			break;
		}

	case kEplNmtMnuIntNodeEventStatusResponse:
		{
			if ((NmtState >= kEplNmtMsPreOperational2)
			    &&
			    ((pNodeInfo->
			      m_wFlags & EPL_NMTMNU_NODE_FLAG_NOT_SCANNED) !=
			     0)) {
				// decrement only signal slave count if checked once for ReadyToOp, CheckCom, Operational
				EplNmtMnuInstance_g.m_uiSignalSlaveCount--;
				pNodeInfo->m_wFlags &=
				    ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
			}
			// check NMT state of CN
			Ret =
			    EplNmtMnuCheckNmtState(uiNodeId_p, pNodeInfo,
						   NodeNmtState_p, wErrorCode_p,
						   NmtState);
			if (Ret != kEplSuccessful) {
				if (Ret == kEplReject) {
					Ret = kEplSuccessful;
				}
				break;
			}

			if (NmtState == kEplNmtMsPreOperational1) {
				// request next StatusResponse immediately
				Ret =
				    EplStatusuRequestStatusResponse(uiNodeId_p,
								    EplNmtMnuCbStatusResponse);
				if (Ret != kEplSuccessful) {
					EPL_NMTMNU_DBG_POST_TRACE_VALUE
					    (NodeEvent_p, uiNodeId_p, Ret);
				}

			} else if ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_ISOCHRON) == 0) {	// start timer
				// not isochronously accessed CN (e.g. async-only or stopped CN)
				EPL_NMTMNU_SET_FLAGS_TIMERARG_STATREQ(pNodeInfo,
								      uiNodeId_p,
								      TimerArg);
//                TimerArg.m_EventSink = kEplEventSinkNmtMnu;
//                TimerArg.m_ulArg = EPL_NMTMNU_TIMERARG_STATREQ | uiNodeId_p;
/*
                EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventStatusResponse,
                                                uiNodeId_p,
                                                ((pNodeInfo->m_NodeState << 8)
                                                 | 0x80
                                                 | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
                                                 | ((TimerArg.m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
*/
				Ret =
				    EplTimeruModifyTimerMs(&pNodeInfo->
							   m_TimerHdlStatReq,
							   EplNmtMnuInstance_g.
							   m_ulStatusRequestDelay,
							   TimerArg);
			}

			break;
		}

	case kEplNmtMnuIntNodeEventNoStatusResponse:
		{
			// function CheckNmtState sets node state to unknown if necessary
/*
            if ((NmtState >= kEplNmtMsPreOperational2)
                && ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_NOT_SCANNED) != 0))
            {
                // decrement only signal slave count if checked once for ReadyToOp, CheckCom, Operational
                EplNmtMnuInstance_g.m_uiSignalSlaveCount--;
                pNodeInfo->m_wFlags &= ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
            }
*/
			// check NMT state of CN
			Ret =
			    EplNmtMnuCheckNmtState(uiNodeId_p, pNodeInfo,
						   NodeNmtState_p, wErrorCode_p,
						   NmtState);
			if (Ret != kEplSuccessful) {
				if (Ret == kEplReject) {
					Ret = kEplSuccessful;
				}
				break;
			}

			break;
		}

	case kEplNmtMnuIntNodeEventError:
		{		// currently only issued on kEplNmtNodeCommandConfErr

			if (pNodeInfo->m_NodeState != kEplNmtMnuNodeStateIdentified) {	// wrong CN state
				// ignore event
				break;
			}
			// check NMT state of CN
			Ret =
			    EplNmtMnuCheckNmtState(uiNodeId_p, pNodeInfo,
						   kEplNmtCsNotActive,
						   wErrorCode_p, NmtState);
			if (Ret != kEplSuccessful) {
				if (Ret == kEplReject) {
					Ret = kEplSuccessful;
				}
				break;
			}

			break;
		}

	case kEplNmtMnuIntNodeEventExecReset:
		{
			if (pNodeInfo->m_NodeState != kEplNmtMnuNodeStateIdentified) {	// wrong CN state
				// ignore event
				break;
			}

			pNodeInfo->m_NodeState = kEplNmtMnuNodeStateResetConf;

			EPL_NMTMNU_DBG_POST_TRACE_VALUE(NodeEvent_p,
							uiNodeId_p,
							(((NodeNmtState_p &
							   0xFF) << 8)
							 |
							 kEplNmtCmdResetConfiguration));

			// send NMT reset configuration to CN for activation of configuration
			Ret =
			    EplNmtMnuSendNmtCommand(uiNodeId_p,
						    kEplNmtCmdResetConfiguration);

			break;
		}

	case kEplNmtMnuIntNodeEventHeartbeat:
		{
/*
            if ((NmtState >= kEplNmtMsPreOperational2)
                && ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_NOT_SCANNED) != 0))
            {
                // decrement only signal slave count if checked once for ReadyToOp, CheckCom, Operational
                EplNmtMnuInstance_g.m_uiSignalSlaveCount--;
                pNodeInfo->m_wFlags &= ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
            }
*/
			// check NMT state of CN
			Ret =
			    EplNmtMnuCheckNmtState(uiNodeId_p, pNodeInfo,
						   NodeNmtState_p, wErrorCode_p,
						   NmtState);
			if (Ret != kEplSuccessful) {
				if (Ret == kEplReject) {
					Ret = kEplSuccessful;
				}
				break;
			}

			break;
		}

	case kEplNmtMnuIntNodeEventTimerIdentReq:
		{
			EPL_DBGLVL_NMTMN_TRACE1
			    ("TimerStatReq->IdentReq(%02X)\n", uiNodeId_p);
			// trigger IdentRequest again
			Ret =
			    EplIdentuRequestIdentResponse(uiNodeId_p,
							  EplNmtMnuCbIdentResponse);
			if (Ret != kEplSuccessful) {
				EPL_NMTMNU_DBG_POST_TRACE_VALUE(NodeEvent_p,
								uiNodeId_p,
								(((NodeNmtState_p & 0xFF) << 8)
								 | Ret));
				if (Ret == kEplInvalidOperation) {	// this can happen because of a bug in EplTimeruLinuxKernel.c
					// so ignore this error.
					Ret = kEplSuccessful;
				}
			}

			break;
		}

	case kEplNmtMnuIntNodeEventTimerStateMon:
		{
			// reset NMT state change flag
			// because from now on the CN must have the correct NMT state
			pNodeInfo->m_wFlags &=
			    ~EPL_NMTMNU_NODE_FLAG_NMT_CMD_ISSUED;

			// continue with normal StatReq processing
		}

	case kEplNmtMnuIntNodeEventTimerStatReq:
		{
			EPL_DBGLVL_NMTMN_TRACE1("TimerStatReq->StatReq(%02X)\n",
						uiNodeId_p);
			// request next StatusResponse
			Ret =
			    EplStatusuRequestStatusResponse(uiNodeId_p,
							    EplNmtMnuCbStatusResponse);
			if (Ret != kEplSuccessful) {
				EPL_NMTMNU_DBG_POST_TRACE_VALUE(NodeEvent_p,
								uiNodeId_p,
								(((NodeNmtState_p & 0xFF) << 8)
								 | Ret));
				if (Ret == kEplInvalidOperation) {	// the only situation when this should happen is, when
					// StatusResponse was already requested while processing
					// event IdentResponse.
					// so ignore this error.
					Ret = kEplSuccessful;
				}
			}

			break;
		}

	case kEplNmtMnuIntNodeEventTimerLonger:
		{
			switch (pNodeInfo->m_NodeState) {
			case kEplNmtMnuNodeStateConfigured:
				{	// node should be ReadyToOp but it is not

					// check NMT state which shall be intentionally wrong, so that ERROR_TREATMENT will be started
					Ret =
					    EplNmtMnuCheckNmtState(uiNodeId_p,
								   pNodeInfo,
								   kEplNmtCsNotActive,
								   EPL_E_NMT_BPO2,
								   NmtState);
					if (Ret != kEplSuccessful) {
						if (Ret == kEplReject) {
							Ret = kEplSuccessful;
						}
						break;
					}

					break;
				}

			case kEplNmtMnuNodeStateReadyToOp:
				{	// CheckCom finished successfully

					pNodeInfo->m_NodeState =
					    kEplNmtMnuNodeStateComChecked;

					if ((pNodeInfo->
					     m_wFlags &
					     EPL_NMTMNU_NODE_FLAG_NOT_SCANNED)
					    != 0) {
						// decrement only signal slave count if checked once for ReadyToOp, CheckCom, Operational
						EplNmtMnuInstance_g.
						    m_uiSignalSlaveCount--;
						pNodeInfo->m_wFlags &=
						    ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
					}

					if ((pNodeInfo->
					     m_dwNodeCfg &
					     EPL_NODEASSIGN_MANDATORY_CN) !=
					    0) {
						// decrement mandatory slave counter
						EplNmtMnuInstance_g.
						    m_uiMandatorySlaveCount--;
					}
					if (NmtState != kEplNmtMsReadyToOperate) {
						EPL_NMTMNU_DBG_POST_TRACE_VALUE
						    (NodeEvent_p, uiNodeId_p,
						     (((NodeNmtState_p & 0xFF)
						       << 8)
						      | kEplNmtCmdStartNode));

						// start optional CN
						Ret =
						    EplNmtMnuSendNmtCommand
						    (uiNodeId_p,
						     kEplNmtCmdStartNode);
					}
					break;
				}

			default:
				{
					break;
				}
			}
			break;
		}

	case kEplNmtMnuIntNodeEventNmtCmdSent:
		{
			BYTE bNmtState;

			// update expected NMT state with the one that results
			// from the sent NMT command
			bNmtState = (BYTE) (NodeNmtState_p & 0xFF);

			// write object 0x1F8F NMT_MNNodeExpState_AU8
			Ret =
			    EplObduWriteEntry(0x1F8F, uiNodeId_p, &bNmtState,
					      1);
			if (Ret != kEplSuccessful) {
				goto Exit;
			}

			if (NodeNmtState_p == kEplNmtCsNotActive) {	// restart processing with IdentRequest
				EPL_NMTMNU_SET_FLAGS_TIMERARG_IDENTREQ
				    (pNodeInfo, uiNodeId_p, TimerArg);
			} else {	// monitor NMT state change with StatusRequest after
				// the corresponding delay;
				// until then wrong NMT states will be ignored
				EPL_NMTMNU_SET_FLAGS_TIMERARG_STATE_MON
				    (pNodeInfo, uiNodeId_p, TimerArg);

				// set NMT state change flag
				pNodeInfo->m_wFlags |=
				    EPL_NMTMNU_NODE_FLAG_NMT_CMD_ISSUED;
			}

			Ret =
			    EplTimeruModifyTimerMs(&pNodeInfo->
						   m_TimerHdlStatReq,
						   EplNmtMnuInstance_g.
						   m_ulStatusRequestDelay,
						   TimerArg);

			// finish processing, because NmtState_p is the expected and not the current state
			goto Exit;
		}

	default:
		{
			break;
		}
	}

	// check if network is ready to change local NMT state and this was not done before
	if ((EplNmtMnuInstance_g.m_wFlags & (EPL_NMTMNU_FLAG_HALTED | EPL_NMTMNU_FLAG_APP_INFORMED)) == 0) {	// boot process is not halted
		switch (NmtState) {
		case kEplNmtMsPreOperational1:
			{
				if ((EplNmtMnuInstance_g.m_uiSignalSlaveCount ==
				     0)
				    && (EplNmtMnuInstance_g.m_uiMandatorySlaveCount == 0)) {	// all optional CNs scanned once and all mandatory CNs configured successfully
					EplNmtMnuInstance_g.m_wFlags |=
					    EPL_NMTMNU_FLAG_APP_INFORMED;
					// inform application
					Ret =
					    EplNmtMnuInstance_g.
					    m_pfnCbBootEvent
					    (kEplNmtBootEventBootStep1Finish,
					     NmtState, EPL_E_NO_ERROR);
					if (Ret != kEplSuccessful) {
						if (Ret == kEplReject) {
							// wait for application
							Ret = kEplSuccessful;
						}
						break;
					}
					// enter PreOp2
					Ret =
					    EplNmtuNmtEvent
					    (kEplNmtEventAllMandatoryCNIdent);
				}
				break;
			}

		case kEplNmtMsPreOperational2:
			{
				if ((EplNmtMnuInstance_g.m_uiSignalSlaveCount ==
				     0)
				    && (EplNmtMnuInstance_g.m_uiMandatorySlaveCount == 0)) {	// all optional CNs checked once for ReadyToOp and all mandatory CNs are ReadyToOp
					EplNmtMnuInstance_g.m_wFlags |=
					    EPL_NMTMNU_FLAG_APP_INFORMED;
					// inform application
					Ret =
					    EplNmtMnuInstance_g.
					    m_pfnCbBootEvent
					    (kEplNmtBootEventBootStep2Finish,
					     NmtState, EPL_E_NO_ERROR);
					if (Ret != kEplSuccessful) {
						if (Ret == kEplReject) {
							// wait for application
							Ret = kEplSuccessful;
						}
						break;
					}
					// enter ReadyToOp
					Ret =
					    EplNmtuNmtEvent
					    (kEplNmtEventEnterReadyToOperate);
				}
				break;
			}

		case kEplNmtMsReadyToOperate:
			{
				if ((EplNmtMnuInstance_g.m_uiSignalSlaveCount ==
				     0)
				    && (EplNmtMnuInstance_g.m_uiMandatorySlaveCount == 0)) {	// all CNs checked for errorless communication
					EplNmtMnuInstance_g.m_wFlags |=
					    EPL_NMTMNU_FLAG_APP_INFORMED;
					// inform application
					Ret =
					    EplNmtMnuInstance_g.
					    m_pfnCbBootEvent
					    (kEplNmtBootEventCheckComFinish,
					     NmtState, EPL_E_NO_ERROR);
					if (Ret != kEplSuccessful) {
						if (Ret == kEplReject) {
							// wait for application
							Ret = kEplSuccessful;
						}
						break;
					}
					// enter Operational
					Ret =
					    EplNmtuNmtEvent
					    (kEplNmtEventEnterMsOperational);
				}
				break;
			}

		case kEplNmtMsOperational:
			{
				if ((EplNmtMnuInstance_g.m_uiSignalSlaveCount ==
				     0)
				    && (EplNmtMnuInstance_g.m_uiMandatorySlaveCount == 0)) {	// all optional CNs scanned once and all mandatory CNs are OPERATIONAL
					EplNmtMnuInstance_g.m_wFlags |=
					    EPL_NMTMNU_FLAG_APP_INFORMED;
					// inform application
					Ret =
					    EplNmtMnuInstance_g.
					    m_pfnCbBootEvent
					    (kEplNmtBootEventOperational,
					     NmtState, EPL_E_NO_ERROR);
					if (Ret != kEplSuccessful) {
						if (Ret == kEplReject) {
							// ignore error code
							Ret = kEplSuccessful;
						}
						break;
					}
				}
				break;
			}

		default:
			{
				break;
			}
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuCheckNmtState
//
// Description: checks the NMT state, i.e. evaluates it with object 0x1F8F
//              NMT_MNNodeExpState_AU8 and updates object 0x1F8E
//              NMT_MNNodeCurrState_AU8.
//              It manipulates m_NodeState in internal node info structure.
//
// Parameters:  uiNodeId_p              = node ID
//              NodeNmtState_p          = NMT state of CN
//
// Returns:     tEplKernel              = error code
//                  kEplReject          = CN was in wrong state and has been reset
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuCheckNmtState(unsigned int uiNodeId_p,
					 tEplNmtMnuNodeInfo * pNodeInfo_p,
					 tEplNmtState NodeNmtState_p,
					 WORD wErrorCode_p,
					 tEplNmtState LocalNmtState_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplObdSize ObdSize;
	BYTE bNmtState;
	BYTE bNmtStatePrev;
	tEplNmtState ExpNmtState;

	ObdSize = 1;
	// read object 0x1F8F NMT_MNNodeExpState_AU8
	Ret = EplObduReadEntry(0x1F8F, uiNodeId_p, &bNmtState, &ObdSize);
	if (Ret != kEplSuccessful) {
		goto Exit;
	}
	// compute expected NMT state
	ExpNmtState = (tEplNmtState) (bNmtState | EPL_NMT_TYPE_CS);
	// compute BYTE of current NMT state
	bNmtState = ((BYTE) NodeNmtState_p & 0xFF);

	if (ExpNmtState == kEplNmtCsNotActive) {	// ignore the current state, because the CN shall be not active
		Ret = kEplReject;
		goto Exit;
	} else if ((ExpNmtState == kEplNmtCsPreOperational2)
		   && (NodeNmtState_p == kEplNmtCsReadyToOperate)) {	// CN switched to ReadyToOp
		// delete timer for timeout handling
		Ret = EplTimeruDeleteTimer(&pNodeInfo_p->m_TimerHdlLonger);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
		pNodeInfo_p->m_NodeState = kEplNmtMnuNodeStateReadyToOp;

		// update object 0x1F8F NMT_MNNodeExpState_AU8 to ReadyToOp
		Ret = EplObduWriteEntry(0x1F8F, uiNodeId_p, &bNmtState, 1);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

		if ((pNodeInfo_p->m_dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// node is a mandatory CN -> decrement counter
			EplNmtMnuInstance_g.m_uiMandatorySlaveCount--;
		}
		if (LocalNmtState_p >= kEplNmtMsReadyToOperate) {	// start procedure CheckCommunication for this node
			Ret = EplNmtMnuNodeCheckCom(uiNodeId_p, pNodeInfo_p);
			if (Ret != kEplSuccessful) {
				goto Exit;
			}

			if ((LocalNmtState_p == kEplNmtMsOperational)
			    && (pNodeInfo_p->m_NodeState ==
				kEplNmtMnuNodeStateComChecked)) {
				EPL_NMTMNU_DBG_POST_TRACE_VALUE(0, uiNodeId_p,
								(((NodeNmtState_p & 0xFF) << 8)
								 |
								 kEplNmtCmdStartNode));

				// immediately start optional CN, because communication is always OK (e.g. async-only CN)
				Ret =
				    EplNmtMnuSendNmtCommand(uiNodeId_p,
							    kEplNmtCmdStartNode);
				if (Ret != kEplSuccessful) {
					goto Exit;
				}
			}
		}

	} else if ((ExpNmtState == kEplNmtCsReadyToOperate)
		   && (NodeNmtState_p == kEplNmtCsOperational)) {	// CN switched to OPERATIONAL
		pNodeInfo_p->m_NodeState = kEplNmtMnuNodeStateOperational;

		if ((pNodeInfo_p->m_dwNodeCfg & EPL_NODEASSIGN_MANDATORY_CN) != 0) {	// node is a mandatory CN -> decrement counter
			EplNmtMnuInstance_g.m_uiMandatorySlaveCount--;
		}

	} else if ((ExpNmtState != NodeNmtState_p)
		   && !((ExpNmtState == kEplNmtCsPreOperational1)
			&& (NodeNmtState_p == kEplNmtCsPreOperational2))) {	// CN is not in expected NMT state (without the exceptions above)
		WORD wbeErrorCode;

		if ((pNodeInfo_p->
		     m_wFlags & EPL_NMTMNU_NODE_FLAG_NOT_SCANNED) != 0) {
			// decrement only signal slave count if checked once
			EplNmtMnuInstance_g.m_uiSignalSlaveCount--;
			pNodeInfo_p->m_wFlags &=
			    ~EPL_NMTMNU_NODE_FLAG_NOT_SCANNED;
		}

		if (pNodeInfo_p->m_NodeState == kEplNmtMnuNodeStateUnknown) {	// CN is already in state unknown, which means that it got
			// NMT reset command earlier
			goto Exit;
		}
		// -> CN is in wrong NMT state
		pNodeInfo_p->m_NodeState = kEplNmtMnuNodeStateUnknown;

		if (wErrorCode_p == 0) {	// assume wrong NMT state error
			if ((pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_NMT_CMD_ISSUED) != 0) {	// NMT command has been just issued;
				// ignore wrong NMT state until timer expires;
				// other errors like LOSS_PRES_TH are still processed
				goto Exit;
			}

			wErrorCode_p = EPL_E_NMT_WRONG_STATE;
		}

		BENCHMARK_MOD_07_TOGGLE(9);

		// $$$ start ERROR_TREATMENT and inform application
		Ret = EplNmtMnuInstance_g.m_pfnCbNodeEvent(uiNodeId_p,
							   kEplNmtNodeEventError,
							   NodeNmtState_p,
							   wErrorCode_p,
							   (pNodeInfo_p->
							    m_dwNodeCfg &
							    EPL_NODEASSIGN_MANDATORY_CN)
							   != 0);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

		EPL_NMTMNU_DBG_POST_TRACE_VALUE(0,
						uiNodeId_p,
						(((NodeNmtState_p & 0xFF) << 8)
						 | kEplNmtCmdResetNode));

		// reset CN
		// store error code in NMT command data for diagnostic purpose
		AmiSetWordToLe(&wbeErrorCode, wErrorCode_p);
		Ret =
		    EplNmtMnuSendNmtCommandEx(uiNodeId_p, kEplNmtCmdResetNode,
					      &wbeErrorCode,
					      sizeof(wbeErrorCode));
		if (Ret == kEplSuccessful) {
			Ret = kEplReject;
		}

		goto Exit;
	}
	// check if NMT_MNNodeCurrState_AU8 has to be changed
	ObdSize = 1;
	Ret = EplObduReadEntry(0x1F8E, uiNodeId_p, &bNmtStatePrev, &ObdSize);
	if (Ret != kEplSuccessful) {
		goto Exit;
	}
	if (bNmtState != bNmtStatePrev) {
		// update object 0x1F8E NMT_MNNodeCurrState_AU8
		Ret = EplObduWriteEntry(0x1F8E, uiNodeId_p, &bNmtState, 1);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
		Ret = EplNmtMnuInstance_g.m_pfnCbNodeEvent(uiNodeId_p,
							   kEplNmtNodeEventNmtState,
							   NodeNmtState_p,
							   wErrorCode_p,
							   (pNodeInfo_p->
							    m_dwNodeCfg &
							    EPL_NODEASSIGN_MANDATORY_CN)
							   != 0);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplNmtMnuReset
//
// Description: reset internal structures, e.g. timers
//
// Parameters:  void
//
// Returns:     tEplKernel              = error code
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplNmtMnuReset(void)
{
	tEplKernel Ret;
	int iIndex;

	Ret = EplTimeruDeleteTimer(&EplNmtMnuInstance_g.m_TimerHdlNmtState);

	for (iIndex = 1; iIndex <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo);
	     iIndex++) {
		// delete timer handles
		Ret =
		    EplTimeruDeleteTimer(&EPL_NMTMNU_GET_NODEINFO(iIndex)->
					 m_TimerHdlStatReq);
		Ret =
		    EplTimeruDeleteTimer(&EPL_NMTMNU_GET_NODEINFO(iIndex)->
					 m_TimerHdlLonger);
	}

	return Ret;
}

#endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

// EOF