forked from xl4-shiro/excelfore-gptp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gptpman.c
1330 lines (1224 loc) · 46.1 KB
/
gptpman.c
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
/*
* Excelfore gptp - Implementation of gPTP(IEEE 802.1AS)
* Copyright (C) 2019 Excelfore Corporation (https://excelfore.com)
*
* This file is part of Excelfore-gptp.
*
* Excelfore-gptp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Excelfore-gptp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Excelfore-gptp. If not, see
* <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.
*/
#include <signal.h>
#include <stdio.h>
#include "gptpnet.h"
#include "gptpclock.h"
#include "mdeth.h"
#include "mind.h"
#include "md_pdelay_req_sm.h"
#include "md_pdelay_resp_sm.h"
#include "md_sync_receive_sm.h"
#include "md_sync_send_sm.h"
#include "announce_interval_setting_sm.h"
#include "port_sync_sync_receive_sm.h"
#include "port_sync_sync_send_sm.h"
#include "port_announce_receive_sm.h"
#include "port_announce_information_sm.h"
#include "port_announce_information_ext_sm.h"
#include "port_state_selection_sm.h"
#include "port_state_setting_ext_sm.h"
#include "port_announce_transmit_sm.h"
#include "site_sync_sync_sm.h"
#include "clock_master_sync_send_sm.h"
#include "clock_slave_sync_sm.h"
#include "clock_master_sync_receive_sm.h"
#include "clock_master_sync_offset_sm.h"
#include "gptp_capable_transmit_sm.h"
#include "gptp_capable_receive_sm.h"
#include "sync_interval_setting_sm.h"
#include "link_delay_interval_setting_sm.h"
#include "one_step_tx_oper_setting_sm.h"
#include "md_announce_send_sm.h"
#include "md_announce_receive_sm.h"
#include "md_signaling_send_sm.h"
#include "md_signaling_receive_sm.h"
#include "gm_stable_sm.h"
#include "gptpman.h"
#include "md_abnormal_hooks.h"
#include "xl4unibase/unibase_macros.h"
extern char *PTPMsgType_debug[];
extern char *gptpnet_event_debug[];
#define DOMAIN_DATA_EXIST(di) ((di>=0) && (di<gpmand->max_domains) && gpmand->tasds[di].tasglb)
#define PORT_DATA_EXIST(di,pi) (DOMAIN_DATA_EXIST(di) && (pi>=0) && (pi<gpmand->max_ports) && \
gpmand->tasds[di].ptds[pi].ppglb)
// per-port data
typedef struct gptpsm_ptd{
PerPortGlobal *ppglb;
BmcsPerPortGlobal *bppglb;
MDEntityGlobal *mdeglb;
md_pdelay_req_data_t *mdpdreqd;
md_pdelay_resp_data_t *mdpdrespd;
md_sync_receive_data_t *mdsrecd;
md_sync_send_data_t *mdssendd;
announce_interval_setting_data_t *aisetd;
port_sync_sync_receive_data_t *pssrecd;
port_sync_sync_send_data_t *psssendd;
port_announce_receive_data_t *parecd;
port_announce_information_data_t *painfd;
port_announce_information_ext_data_t *paiextd;
port_announce_transmit_data_t *patransd;
port_state_setting_ext_data_t *pssextd;
bool cmldsLinkPortEnabled; // 11.2.16.1
gptp_capable_transmit_data_t *gctransd;
gptp_capable_receive_data_t *gcrecd;
sync_interval_setting_data_t *sisetd;
link_delay_interval_setting_data_t *ldisetd;
one_step_tx_oper_setting_data_t *ostxopd;
md_announce_send_data_t *mdansendd;
md_announce_receive_data_t *mdanrecd;
md_signaling_send_data_t *mdsigsendd;
md_signaling_receive_data_t *mdsigrecd;
} gptpsm_ptd_t;
// per-time-aware-system data
typedef struct gptpsm_tasd{
gptpsm_ptd_t *ptds;
PerTimeAwareSystemGlobal *tasglb;
BmcsPerTimeAwareSystemGlobal *btasglb;
site_sync_sync_data_t *sssd;
clock_master_sync_send_data_t *cmssendd;
clock_slave_sync_data_t *cssd;
clock_master_sync_receive_data_t *cmsrecd;
clock_master_sync_offset_data_t *cmsoffsetd;
port_state_selection_data_t *pssd;
gm_stable_data_t *gmsd;
PerPortGlobal **ppglbl;
BmcsPerPortGlobal **bppglbl;
} gptpsm_tasd_t;
/*
tasds[0] (0 is always domainNumber=0)
ptds[0],ptds[1],...,ptds[max_ports]
tasds[1] (domainNumber is tasds[1].domainNumber)
ptds[0],ptds[1],...,ptds[max_ports]
tasds[2] (domainNumber is tasds[2].domainNumber)
ptds[0],ptds[1],...,ptds[max_ports]
...
portIndex is enumerated, but domain number is not.
*/
// per-entire-system data
struct gptpman_data {
gptpsm_tasd_t *tasds;
gptpnet_data_t *gpnetd;
int max_ports;
int max_domains;
FILE *extcmdstdin;
};
static void set_asCapable(PerTimeAwareSystemGlobal *tasg, gptpsm_ptd_t *ptd)
{
if(ptd->mdeglb->forAllDomain->asCapableAcrossDomains ||
ptd->ppglb->neighborGptpCapable){
if(ptd->ppglb->asCapable) return;
ptd->ppglb->asCapable = true;
UB_LOG(UBL_INFO,
"set asCapable for domainNumber=%d, portIndex=%d\n",
tasg->domainNumber, ptd->ppglb->thisPortIndex);
ptd->ppglb->portEventFlags|=GPTPIPC_EVENT_PORT_FLAG_AS_CAPABLE_UP;
ptd->ppglb->portEventFlags&=~GPTPIPC_EVENT_PORT_FLAG_AS_CAPABLE_DOWN;
}else{
if(!ptd->ppglb->asCapable) return;
ptd->ppglb->asCapable = false;
UB_LOG(UBL_INFO,
"reset asCapable for domainNumber=%d, portIndex=%d\n",
tasg->domainNumber, ptd->ppglb->thisPortIndex);
ptd->ppglb->portEventFlags|=GPTPIPC_EVENT_PORT_FLAG_AS_CAPABLE_DOWN;
ptd->ppglb->portEventFlags&=~GPTPIPC_EVENT_PORT_FLAG_AS_CAPABLE_UP;
}
}
static int portSyncSync_for_all(gptpman_data_t *gpmand, int domainIndex,
void *smret, uint64_t cts64)
{
int pi;
void *smretp;
for(pi=1;pi<gpmand->max_ports;pi++){
smretp=port_sync_sync_send_sm_portSyncSync(
gpmand->tasds[domainIndex].ptds[pi].psssendd, smret, cts64);
if(smretp) md_sync_send_sm_mdSyncSend(
gpmand->tasds[domainIndex].ptds[pi].mdssendd, smretp, cts64);
// send smret to BMCS PortAnnounceInformation
port_announce_information_sm_SyncReceiptTimeoutTime(
gpmand->tasds[domainIndex].ptds[pi].painfd, smret);
}
// send the same smret to ClockSlaveSync
clock_slave_sync_sm_portSyncSync(
gpmand->tasds[domainIndex].cssd, smret, cts64);
clock_master_sync_receive_sm_ClockSourceReq(
gpmand->tasds[domainIndex].cmsrecd, cts64);
clock_master_sync_offset_sm_SyncReceiptTime(
gpmand->tasds[domainIndex].cmsoffsetd, cts64);
return 0;
}
static int get_domain_index(gptpman_data_t *gpmand, uint8_t domainNumber)
{
int i;
if(domainNumber==0) return 0; // 0 is always index 0
for(i=0;i<gpmand->max_domains;i++){
if(gpmand->tasds[i].tasglb &&
gpmand->tasds[i].tasglb->domainNumber == domainNumber) return i;
}
return -1;
}
static int sm_bmcs_perform(gptpman_data_t *gpmand, int domainIndex,
int portIndex, uint64_t cts64)
{
void *smret;
gptpsm_tasd_t *tasd = &gpmand->tasds[domainIndex];
if(tasd->btasglb->externalPortConfiguration==VALUE_DISABLED){
do{
port_announce_information_sm(tasd->ptds[portIndex].painfd, cts64);
if((smret=port_state_selection_sm(tasd->pssd, cts64))){
gm_stable_gm_change(tasd->gmsd, smret, cts64);
// update clock source after GM change
clock_master_sync_receive_sm_ClockSourceReq(tasd->cmsrecd, cts64);
}
}while(tasd->ptds[portIndex].bppglb->updtInfo);
}else{ // btasglb->externalPortConfiguration==VALUE_ENABLED
smret = port_announce_information_ext_sm(tasd->ptds[portIndex].paiextd, cts64);
if(smret) port_state_setting_ext_sm_messagePriority(tasd->ptds[portIndex].pssextd, smret);
port_state_setting_ext_sm(tasd->ptds[portIndex].pssextd, cts64);
}
smret = port_announce_transmit_sm(tasd->ptds[portIndex].patransd, cts64);
if(smret) md_announce_send_sm_mdAnnouncSend(tasd->ptds[portIndex].mdansendd, smret, cts64);
return 0;
}
static int sm_bmcs_domain_port_update(gptpman_data_t *gpmand, int domainIndex,
int portIndex, uint64_t cts64)
{
// update state machine on event occurence
// ie. portOper = true, asCapable = true
announce_interval_setting_sm(gpmand->tasds[domainIndex].ptds[portIndex].aisetd, cts64);
sm_bmcs_perform(gpmand, domainIndex, portIndex, cts64);
return 0;
}
static int sm_close_for_domain_zero_port(gptpman_data_t *gpmand, int pi)
{
SM_CLOSE(md_pdelay_resp_sm_close, gpmand->tasds[0].ptds[pi].mdpdrespd);
SM_CLOSE(md_pdelay_req_sm_close, gpmand->tasds[0].ptds[pi].mdpdreqd);
SM_CLOSE(link_delay_interval_setting_sm_close, gpmand->tasds[0].ptds[pi].ldisetd);
return 0;
}
static int sm_close_for_domain_port(gptpman_data_t *gpmand, int di, int pi)
{
if(!DOMAIN_DATA_EXIST(di) ||
(di!=0 && !gpmand->tasds[di].tasglb->domainNumber)){
UB_LOG(UBL_DEBUG, "%s:di=%d, pi=%d, not initialized\n", __func__, di, pi);
return -1;
}
if(di==0) sm_close_for_domain_zero_port(gpmand, pi);
SM_CLOSE(port_announce_information_ext_sm_close, gpmand->tasds[di].ptds[pi].paiextd);
SM_CLOSE(port_announce_information_sm_close, gpmand->tasds[di].ptds[pi].painfd);
if(pi==0) return 0;
SM_CLOSE(announce_interval_setting_sm_close, gpmand->tasds[di].ptds[pi].aisetd);
SM_CLOSE(port_state_setting_ext_sm_close, gpmand->tasds[di].ptds[pi].pssextd);
SM_CLOSE(port_announce_receive_sm_close, gpmand->tasds[di].ptds[pi].parecd);
SM_CLOSE(port_announce_transmit_sm_close, gpmand->tasds[di].ptds[pi].patransd);
SM_CLOSE(md_sync_receive_sm_close, gpmand->tasds[di].ptds[pi].mdsrecd);
SM_CLOSE(md_sync_send_sm_close, gpmand->tasds[di].ptds[pi].mdssendd);
SM_CLOSE(port_sync_sync_receive_sm_close, gpmand->tasds[di].ptds[pi].pssrecd);
SM_CLOSE(port_sync_sync_send_sm_close, gpmand->tasds[di].ptds[pi].psssendd);
SM_CLOSE(gptp_capable_transmit_sm_close, gpmand->tasds[di].ptds[pi].gctransd);
SM_CLOSE(gptp_capable_receive_sm_close, gpmand->tasds[di].ptds[pi].gcrecd);
SM_CLOSE(sync_interval_setting_sm_close, gpmand->tasds[di].ptds[pi].sisetd);
SM_CLOSE(one_step_tx_oper_setting_sm_close, gpmand->tasds[di].ptds[pi].ostxopd);
SM_CLOSE(md_announce_send_sm_close, gpmand->tasds[di].ptds[pi].mdansendd);
SM_CLOSE(md_announce_receive_sm_close, gpmand->tasds[di].ptds[pi].mdanrecd);
SM_CLOSE(md_signaling_send_sm_close, gpmand->tasds[di].ptds[pi].mdsigsendd);
SM_CLOSE(md_signaling_receive_sm_close, gpmand->tasds[di].ptds[pi].mdsigrecd);
return 0;
}
static int gptpnet_cb_devup(gptpman_data_t *gpmand, int portIndex,
event_data_netlink_t *ed, uint64_t cts64)
{
char *dup;
int di;
gptpipc_gptpd_data_t ipcd;
switch(ed->duplex){
case 1: dup="full";
if(ed->speed<100) break;
gpmand->tasds[0].ptds[portIndex].ppglb->forAllDomain->portOper=true;
for(di=0;di<gpmand->max_domains;di++){
if(!DOMAIN_DATA_EXIST(di)) continue;
if(di!=0 && !gpmand->tasds[di].tasglb->domainNumber) continue;
sm_bmcs_domain_port_update(gpmand, di, portIndex, cts64);
}
break;
case 2: dup="half"; break;
default: dup="unknown"; break;
}
UB_LOG(UBL_INFO, "index=%d speed=%d, duplex=%s, ptpdev=%s\n",
portIndex, (int)ed->speed, dup, ed->ptpdev);
if(ed->speed<100 || ed->duplex!=1){
UB_LOG(UBL_WARN,"!!! Full duplex link with "
"Speed above 100 Mbps needed for gptp to run !!!\n");
}
memset(&ipcd, 0, sizeof(ipcd));
ipcd.dtype=GPTPIPC_GPTPD_NOTICE;
ipcd.u.notice.event_flags=GPTPIPC_EVENT_CLOCK_FLAG_NETDEV_UP;
ipcd.u.notice.portIndex=portIndex;
gptpnet_ipc_notice(gpmand->gpnetd, &ipcd, sizeof(ipcd));
return 0;
}
static int gptpnet_cb_devdown(gptpman_data_t *gpmand, int portIndex,
event_data_netlink_t *ed, uint64_t cts64)
{
gptpipc_gptpd_data_t ipcd;
int di;
UB_LOG(UBL_INFO, "%s:portIndex=%d\n", __func__, portIndex);
memset(&ipcd, 0, sizeof(ipcd));
ipcd.dtype=GPTPIPC_GPTPD_NOTICE;
ipcd.u.notice.event_flags=GPTPIPC_EVENT_CLOCK_FLAG_NETDEV_DOWN;
ipcd.u.notice.portIndex=portIndex;
gptpnet_ipc_notice(gpmand->gpnetd, &ipcd, sizeof(ipcd));
gpmand->tasds[0].ptds[portIndex].ppglb->forAllDomain->portOper=false;
gpmand->tasds[0].ptds[portIndex].mdeglb->forAllDomain->asCapableAcrossDomains=false;
gpmand->tasds[0].ptds[portIndex].ppglb->forAllDomain->receivedNonCMLDSPdelayReq=0;
for(di=0;di<gpmand->max_domains;di++){
if(!gpmand->tasds[di].ptds[portIndex].ppglb->asCapable) continue;
gpmand->tasds[di].ptds[portIndex].ppglb->asCapable = false;
gpmand->tasds[di].ptds[portIndex].ppglb->portEventFlags|=
GPTPIPC_EVENT_PORT_FLAG_AS_CAPABLE_DOWN;
gpmand->tasds[di].ptds[portIndex].ppglb->portEventFlags&=
~GPTPIPC_EVENT_PORT_FLAG_AS_CAPABLE_UP;
}
return 0;
}
// return 1 when TxTS is expected after this call
static int gptpnet_cb_timeout(gptpman_data_t *gpmand, uint64_t cts64)
{
int pi, di;
void *smret;
for(di=0;di<gpmand->max_domains;di++){
if(!DOMAIN_DATA_EXIST(di)) continue;
if(di==0){
for(pi=1;pi<gpmand->max_ports;pi++){
md_pdelay_req_sm(gpmand->tasds[di].ptds[pi].mdpdreqd, cts64);
md_pdelay_resp_sm(gpmand->tasds[di].ptds[pi].mdpdrespd, cts64);
}
}
smret=clock_master_sync_send_sm(gpmand->tasds[di].cmssendd, cts64);
if(smret) smret=site_sync_sync_sm_portSyncSync(
gpmand->tasds[di].sssd, smret, cts64);
if(smret) portSyncSync_for_all(gpmand, di, smret, cts64);
gpmand->tasds[di].tasglb->asCapableOrAll=false;
for(pi=1;pi<gpmand->max_ports;pi++){
set_asCapable(gpmand->tasds[di].tasglb, &gpmand->tasds[di].ptds[pi]);
gpmand->tasds[di].tasglb->asCapableOrAll |=
gpmand->tasds[di].ptds[pi].ppglb->asCapable;
smret=gptp_capable_transmit_sm(gpmand->tasds[di].ptds[pi].gctransd, cts64);
if(smret) md_signaling_send_sm_mdSignalingSend(
gpmand->tasds[di].ptds[pi].mdsigsendd, smret, cts64);
// The next 4 md_* calls are to check and send defered msg.
// However, ensure that this are called after the calling
// set_asCapable above so that no defered messages are not sent
// after asCapable has been toggled to false already.
md_sync_send_sm(gpmand->tasds[di].ptds[pi].mdssendd, cts64);
md_announce_send_sm(gpmand->tasds[di].ptds[pi].mdansendd, cts64);
md_signaling_send_sm(gpmand->tasds[di].ptds[pi].mdsigsendd, cts64);
md_sync_receive_sm(gpmand->tasds[di].ptds[pi].mdsrecd, cts64);
// asCapable might be set, inform other state machines
if(di!=0 && !gpmand->tasds[di].tasglb->domainNumber) continue;
sm_bmcs_domain_port_update(gpmand, di, pi, cts64);
}
gm_stable_sm(gpmand->tasds[di].gmsd, cts64);
}
return 0;
}
// return 1 when TxTS is expected after this call
static int gptpnet_cb_recv(gptpman_data_t *gpmand, int portIndex,
event_data_recv_t *ed, uint64_t cts64)
{
int di=0;
int pi;
char *msg;
void *smret;
uint32_t stype;
if(ed->domain!=0){
/* get domainIndex from domainNumber */
if((di=get_domain_index(gpmand, ed->domain))<0) {
UB_LOG(UBL_DEBUG, "%s:domainNumber=%d is not yet initialized\n",
__func__, ed->domain);
return 0;
}
}
if(ed->msgtype<=15)
msg=PTPMsgType_debug[ed->msgtype];
else
msg="unknown";
UB_LOG(UBL_DEBUGV, "RECV: pindex=%d msgtype=%s, TS=%"PRIi64"nsec\n",
portIndex, msg, ed->ts64);
switch(ed->msgtype){
case SYNC:
/* in a TAS, all the TSs work based on 'thisClock', so when a TS is not
* based on 'thisClock', it must be converted.
* When this TAS is synced to GM, 'thisClock' has the same freq. rate as GM,
* but the phase is different. The phase sync happens in the TAS master clock,
* which is gptpclock entity of (ClockIndex=0, tasglb->domainNumber)
*/
pi=gptpconf_get_intitem(CONF_SINGLE_CLOCK_MODE)?1:portIndex;
gptpclock_tsconv(&ed->ts64, pi, 0,
gpmand->tasds[di].tasglb->thisClockIndex,
gpmand->tasds[di].tasglb->domainNumber);
md_sync_receive_sm_recv_sync(gpmand->tasds[di].ptds[portIndex].mdsrecd,
ed, cts64);
return 0;
case PDELAY_REQ:
if(di!=0) goto not_allowed_domain;
md_pdelay_resp_sm_recv_req(gpmand->tasds[0].ptds[portIndex].mdpdrespd,
ed, cts64);
return 0;
case PDELAY_RESP:
if(di!=0) goto not_allowed_domain;
md_pdelay_req_sm_recv_resp(gpmand->tasds[0].ptds[portIndex].mdpdreqd,
ed, cts64);
return 0;
case FOLLOW_UP:
smret=md_sync_receive_sm_recv_fup(
gpmand->tasds[di].ptds[portIndex].mdsrecd, ed, cts64);
if(smret) smret=port_sync_sync_receive_sm_recvMDSync(
gpmand->tasds[di].ptds[portIndex].pssrecd, smret, cts64);
if(smret) smret=site_sync_sync_sm_portSyncSync(
gpmand->tasds[di].sssd, smret, cts64);
if(smret) portSyncSync_for_all(gpmand, di, smret, cts64);
return 0;
case PDELAY_RESP_FOLLOW_UP:
if(di!=0) goto not_allowed_domain;
md_pdelay_req_sm_recv_respfup(gpmand->tasds[0].ptds[portIndex].mdpdreqd,
ed, cts64);
// update asCapable for all domains
gpmand->tasds[di].tasglb->asCapableOrAll=false;
for(di=0;di<gpmand->max_domains;di++){
if(!DOMAIN_DATA_EXIST(di)) continue;
set_asCapable(gpmand->tasds[di].tasglb,
&gpmand->tasds[di].ptds[portIndex]);
gpmand->tasds[di].tasglb->asCapableOrAll |=
gpmand->tasds[di].ptds[portIndex].ppglb->asCapable;
}
return 0;
case ANNOUNCE:
smret=md_announce_receive_sm_mdAnnounceRec(
gpmand->tasds[0].ptds[portIndex].mdanrecd, ed, cts64);
if(smret){
port_announce_receive_sm_recv_announce(
gpmand->tasds[di].ptds[portIndex].parecd, smret, cts64);
sm_bmcs_perform(gpmand, di, portIndex, cts64);
}
return 0;
case SIGNALING:
smret=md_signaling_receive_sm_mdSignalingRec(
gpmand->tasds[di].ptds[portIndex].mdsigrecd, ed, cts64);
if(!smret) return 0;
stype=((PTPMsgIntervalRequestTLV *)smret)->organizationSubType;
if(stype==2){
sync_interval_setting_SignalingMsg1(
gpmand->tasds[di].ptds[portIndex].sisetd,
(PTPMsgIntervalRequestTLV *)smret, cts64);
link_delay_interval_setting_SignalingMsg1(
gpmand->tasds[di].ptds[portIndex].ldisetd,
(PTPMsgIntervalRequestTLV *)smret, cts64);
}else if(stype==4){
gptp_capable_receive_rcvdSignalingMsg(
gpmand->tasds[di].ptds[portIndex].gcrecd,
(PTPMsgGPTPCapableTLV *)smret, cts64);
}else{
UB_LOG(UBL_WARN,"%s:unknown signaling message, stype=%u\n",
__func__, (unsigned int)stype);
}
return 0;
default:
return 0;
}
not_allowed_domain:
UB_LOG(UBL_WARN, "%s:msgtype=%s is not allowed for dominNumber=%d",
__func__, msg, ed->domain);
return 0;
}
static int gptpnet_cb_txts(gptpman_data_t *gpmand, int portIndex,
event_data_txts_t *ed, uint64_t cts64)
{
int di=0;
char *msg;
if(ed->domain!=0){
/* get domainIndex from domainNumber */
if((di=get_domain_index(gpmand, ed->domain))<0) {
UB_LOG(UBL_WARN, "%s:domainNumber=%d is not yet initialized\n",
__func__, ed->domain);
return 0;
}
}
if(ed->msgtype<=15)
msg=PTPMsgType_debug[ed->msgtype];
else
msg="unknown";
switch(ed->msgtype){
case SYNC:
md_sync_send_sm_txts(gpmand->tasds[di].ptds[portIndex].mdssendd,
ed, cts64);
return 0;
case PDELAY_REQ:
if(di!=0) goto not_allowed_domain;
md_pdelay_req_sm_txts(gpmand->tasds[0].ptds[portIndex].mdpdreqd,
ed, cts64);
return 0;
case PDELAY_RESP:
if(di!=0) goto not_allowed_domain;
md_pdelay_resp_sm_txts(gpmand->tasds[0].ptds[portIndex].mdpdrespd,
ed, cts64);
return 0;
case FOLLOW_UP:
case PDELAY_RESP_FOLLOW_UP:
case ANNOUNCE:
default:
UB_LOG(UBL_WARN, "%s: msgtype=%s shouldn't have TxTS\n", __func__, msg);
return 0;
}
not_allowed_domain:
UB_LOG(UBL_WARN, "%s:msgtype=%s is not allowed for dominNumber=%d",
__func__, msg, ed->domain);
return 0;
}
static int ipc_respond_one_ndport(gptpnet_data_t *gpnetd, int portIndex, struct sockaddr *addr)
{
gptpipc_gptpd_data_t pd;
memset(&pd, 0, sizeof(pd));
pd.dtype=GPTPIPC_GPTPD_NDPORTD;
if(gptpnet_get_nlstatus(gpnetd, portIndex-1, &pd.u.ndportd.nlstatus))
return -1;
gptpnet_ipc_respond(gpnetd, addr, &pd, sizeof(pd));
return 0;
}
static int ipc_respond_one_clock(gptpnet_data_t *gpnetd,
PerTimeAwareSystemGlobal *tasglb,
int portIndex, int domainNumber, struct sockaddr *addr)
{
gptpipc_gptpd_data_t pd;
memset(&pd, 0, sizeof(pd));
pd.dtype=GPTPIPC_GPTPD_CLOCKD;
pd.u.clockd.portIndex=portIndex;
pd.u.clockd.adjppb=gptpclock_get_adjppb(portIndex, domainNumber);
if(gptpclock_get_ipc_clock_data(portIndex, domainNumber, &pd.u.clockd)){
UB_LOG(UBL_WARN, "%s: portIndex=%d, domainNumber=%d, no clock data\n",
__func__, portIndex, domainNumber);
return -1;
}
if(portIndex==0){
pd.u.clockd.gmTimeBaseIndicator=tasglb->clockSourceTimeBaseIndicator;
memcpy(&pd.u.clockd.lastGmFreqChangePk, &tasglb->clockSourceLastGmFreqChange,
sizeof(double));
pd.u.clockd.lastGmPhaseChange_nsec=tasglb->clockSourceLastGmPhaseChange.nsec;
pd.u.clockd.lastSyncSeqID=tasglb->lastSyncSeqID;
pd.u.clockd.lastSyncReceiptTime_nsec=tasglb->syncReceiptTime.seconds.lsb*UB_SEC_NS
+tasglb->syncReceiptTime.fractionalNanoseconds.msb;
pd.u.clockd.lastSyncReceiptLocalTime_nsec=tasglb->syncReceiptLocalTime.nsec;
}
gptpnet_ipc_respond(gpnetd, addr, &pd, sizeof(pd));
return 0;
}
static int ipc_respond_one_gport(gptpnet_data_t *gpnetd,
PerPortGlobal *ppglb, BmcsPerPortGlobal *bppglb,
PerTimeAwareSystemGlobal *tasglb,
int portIndex, int domainNumber, int domainIndex,
struct sockaddr *addr)
{
gptpipc_gptpd_data_t pd;
memset(&pd, 0, sizeof(pd));
pd.dtype=GPTPIPC_GPTPD_GPORTD;
pd.u.gportd.portIndex=portIndex;
pd.u.gportd.domainNumber=domainNumber;
pd.u.gportd.asCapable=ppglb->asCapable;
pd.u.gportd.portOper=ppglb->forAllDomain->portOper;
pd.u.gportd.selectedState=tasglb->selectedState[portIndex];
pd.u.gportd.gmStable=gptpclock_get_gmstable(domainIndex);
pd.u.gportd.pDelay=ppglb->forAllDomain->neighborPropDelay.nsec;
pd.u.gportd.pDelayRateRatio=ppglb->forAllDomain->neighborRateRatio;
memcpy(&pd.u.gportd.gmClockId, tasglb->gmIdentity, sizeof(ClockIdentity));
pd.u.gportd.annPathSequenceCount=bppglb->annPathSequenceCount;
if(bppglb->annPathSequenceCount>=MAX_PATH_TRACE_N) return -1;
memcpy(&pd.u.gportd.annPathSequence, &bppglb->annPathSequence,
bppglb->annPathSequenceCount * sizeof(ClockIdentity));
gptpnet_ipc_respond(gpnetd, addr, &pd, sizeof(pd));
return 0;
}
static int ipc_respond_statsd_info(gptpman_data_t *gpmand, int pi, int resetcmd,
struct sockaddr *addr)
{
gptpipc_gptpd_data_t pd;
md_pdelay_req_stat_data_t *prsd;
md_pdelay_resp_stat_data_t *ppsd;
if(pi<0 || pi>=gpmand->max_ports) return -1;
if(resetcmd){
md_pdelay_req_stat_reset(gpmand->tasds[0].ptds[pi].mdpdreqd);
md_pdelay_resp_stat_reset(gpmand->tasds[0].ptds[pi].mdpdrespd);
return 0;
}
memset(&pd, 0, sizeof(pd));
pd.dtype=GPTPIPC_GPTPD_STATSD;
prsd=md_pdelay_req_get_stat(gpmand->tasds[0].ptds[pi].mdpdreqd);
pd.u.statsd.portIndex=pi;
pd.u.statsd.pdelay_req_send=prsd->pdelay_req_send;
pd.u.statsd.pdelay_resp_rec=prsd->pdelay_resp_rec;
pd.u.statsd.pdelay_resp_rec_valid=prsd->pdelay_resp_rec_valid;
pd.u.statsd.pdelay_resp_fup_rec=prsd->pdelay_resp_fup_rec;
pd.u.statsd.pdelay_resp_fup_rec_valid=prsd->pdelay_resp_fup_rec_valid;
ppsd=md_pdelay_resp_get_stat(gpmand->tasds[0].ptds[pi].mdpdrespd);
pd.u.statsd.pdelay_req_rec=ppsd->pdelay_req_rec;
pd.u.statsd.pdelay_req_rec_valid=ppsd->pdelay_req_rec_valid;
pd.u.statsd.pdelay_resp_send=ppsd->pdelay_resp_send;
pd.u.statsd.pdelay_resp_fup_send=ppsd->pdelay_resp_fup_send;
gptpnet_ipc_respond(gpmand->gpnetd, addr, &pd, sizeof(pd));
return 0;
}
static int ipc_respond_stattd_info(gptpman_data_t *gpmand, int di, int pi, int resetcmd,
struct sockaddr *addr)
{
gptpipc_gptpd_data_t pd;
md_sync_send_stat_data_t *sssd;
md_sync_receive_stat_data_t *srsd;
md_signaling_send_stat_data_t *gssd;
md_signaling_receive_stat_data_t *grsd;
if(di<0 || di>=gpmand->max_domains) return -1;
if(pi<0 || pi>=gpmand->max_ports) return -1;
if(resetcmd){
md_sync_send_stat_reset(gpmand->tasds[di].ptds[pi].mdssendd);
md_sync_receive_stat_reset(gpmand->tasds[di].ptds[pi].mdsrecd);
return 0;
}
memset(&pd, 0, sizeof(pd));
pd.dtype=GPTPIPC_GPTPD_STATTD;
sssd=md_sync_send_get_stat(gpmand->tasds[di].ptds[pi].mdssendd);
pd.u.stattd.portIndex=pi;
pd.u.stattd.domainNumber=gpmand->tasds[di].tasglb->domainNumber;
pd.u.stattd.sync_send=sssd->sync_send;
pd.u.stattd.sync_fup_send=sssd->sync_fup_send;
srsd=md_sync_receive_get_stat(gpmand->tasds[di].ptds[pi].mdsrecd);
pd.u.stattd.sync_rec=srsd->sync_rec;
pd.u.stattd.sync_fup_rec=srsd->sync_fup_rec;
pd.u.stattd.sync_rec_valid=srsd->sync_rec_valid;
pd.u.stattd.sync_fup_rec_valid=srsd->sync_fup_rec_valid;
gssd=md_signaling_send_get_stat(gpmand->tasds[di].ptds[pi].mdsigsendd);
pd.u.stattd.signal_msg_interval_send=gssd->signal_msg_interval_send;
pd.u.stattd.signal_gptp_capable_send=gssd->signal_gptp_capable_send;
grsd=md_signaling_receive_get_stat(gpmand->tasds[di].ptds[pi].mdsigrecd);
pd.u.stattd.signal_rec=grsd->signal_rec;
pd.u.stattd.signal_msg_interval_rec=grsd->signal_msg_interval_rec;
pd.u.stattd.signal_gptp_capable_rec=grsd->signal_gptp_capable_rec;
gptpnet_ipc_respond(gpmand->gpnetd, addr, &pd, sizeof(pd));
return 0;
}
static int get_domain_index_ipc(gptpman_data_t *gpmand, gptpipc_client_req_data_t *reqdata)
{
if(reqdata->domainNumber==-1){
if(reqdata->domainIndex>=0){
if(reqdata->domainIndex>=gpmand->max_domains) return -1;
if(!gpmand->tasds[reqdata->domainIndex].tasglb) return -1;
reqdata->domainNumber=
gpmand->tasds[reqdata->domainIndex].tasglb->domainNumber;
return reqdata->domainIndex;
}
return -2; // the both are -1
}
reqdata->domainIndex=get_domain_index(gpmand, reqdata->domainNumber);
return reqdata->domainIndex;
}
static int run_ext_script(FILE **extstdin, int arg)
{
#ifndef SYSTEM
return 0;
#else
char cmdstring[64];
FILE *pfp;
if(arg==0){
snprintf(cmdstring, 64, "%s %d > /dev/null", GPTPIPC_EXT_SCRIPT, arg);
}else{
snprintf(cmdstring, 64, "%s %d > /tmp/runfromgptpd.log", GPTPIPC_EXT_SCRIPT, arg);
}
pfp=POPEN(cmdstring, "w"); // this command is sure to terminate previously running one
if(*extstdin) PCLOSE(*extstdin);
*extstdin=pfp;
return 0;
#endif
}
static int ipc_register_abnormal_event(gptpipc_client_req_data_t *reqdata)
{
md_abn_event_t aevent;
memset(&aevent,0,sizeof(aevent));
aevent.domainNumber=reqdata->domainNumber;
aevent.ndevIndex=reqdata->portIndex-1;
aevent.msgtype=(PTPMsgType)reqdata->u.abnd.msgtype;
aevent.eventtype=(md_abn_event_type)reqdata->u.abnd.eventtype;
aevent.eventrate=reqdata->u.abnd.eventrate;
aevent.repeat=reqdata->u.abnd.repeat;
aevent.interval=reqdata->u.abnd.interval;
aevent.eventpara=reqdata->u.abnd.eventpara;
if(reqdata->u.abnd.subcmd==0){
return md_abnormal_register_event(&aevent);
}
if(reqdata->u.abnd.msgtype==-1){
return md_abnormal_deregister_all_events();
}
return md_abnormal_deregister_msgtype_events(aevent.msgtype);
}
static int ipc_clock_master_clock_notice(gptpnet_data_t *gpnetd,
PerTimeAwareSystemGlobal *tasglb, int di)
{
gptpipc_gptpd_data_t ipcd;
int do_phase=gptpconf_get_intitem(CONF_IPC_NOTICE_PHASE_UPDATE);
uint32_t aligntime, cycletime;
// master clock (clockIndex=0) for PHASE_UPDATE and GM_SYNC
memset(&ipcd, 0, sizeof(ipcd));
ipcd.dtype=GPTPIPC_GPTPD_NOTICE;
ipcd.u.notice.event_flags=gptpclock_get_event_flags(0, di);
if(!ipcd.u.notice.event_flags) return 0;
if(ipcd.u.notice.event_flags && GPTPIPC_EVENT_CLOCK_FLAG_GM_CHANGE){
memcpy(&ipcd.u.notice.gmIdentity, &tasglb->gmIdentity,
sizeof(UInteger224));
}
if(gptpconf_get_intitem(CONF_TSN_SCHEDULE_ON) &&
(ipcd.u.notice.event_flags & GPTPIPC_EVENT_CLOCK_FLAG_PHASE_UPDATE)){
aligntime=gptpconf_get_intitem(CONF_TSN_SCHEDULE_ALIGNTIME);
cycletime=gptpconf_get_intitem(CONF_TSN_SCHEDULE_CYCLETIME);
gptpnet_tsn_schedule(gpnetd, aligntime, cycletime);
}
if(ipcd.u.notice.event_flags == GPTPIPC_EVENT_CLOCK_FLAG_PHASE_UPDATE){
if(!do_phase) return 0;
}
ipcd.u.notice.domainNumber=tasglb->domainNumber;
ipcd.u.notice.domainIndex=di;
ipcd.u.notice.gmTimeBaseIndicator=tasglb->clockSourceTimeBaseIndicator;
memcpy(&ipcd.u.notice.lastGmFreqChangePk, &tasglb->clockSourceLastGmFreqChange,
sizeof(double));
ipcd.u.notice.lastGmPhaseChange_nsec=tasglb->clockSourceLastGmPhaseChange.nsec;
return gptpnet_ipc_notice(gpnetd, &ipcd, sizeof(ipcd));
}
static int ipc_clock_this_clock_notice(gptpnet_data_t *gpnetd, int di, uint8_t domainNumber,
int thisClockIndex)
{
gptpipc_gptpd_data_t ipcd;
int do_freq=gptpconf_get_intitem(CONF_IPC_NOTICE_FREQ_UPDATE);
// thisClock for FREQ_UPDATE
memset(&ipcd, 0, sizeof(ipcd));
ipcd.u.notice.event_flags=gptpclock_get_event_flags(thisClockIndex, di);
if(!ipcd.u.notice.event_flags) return 0;
if((ipcd.u.notice.event_flags & ~GPTPIPC_EVENT_CLOCK_FLAG_FREQ_UPDATE) || do_freq){
ipcd.u.notice.domainNumber=domainNumber;
ipcd.u.notice.domainIndex=di;
ipcd.u.notice.portIndex=thisClockIndex;
gptpnet_ipc_notice(gpnetd, &ipcd, sizeof(ipcd));
}
return 1;
}
static int ipc_port_state_notice(gptpnet_data_t *gpnetd, int di, int pi, uint8_t domainNumber,
uint32_t flags)
{
gptpipc_gptpd_data_t ipcd;
memset(&ipcd, 0, sizeof(ipcd));
ipcd.u.notice.event_flags=flags;
ipcd.u.notice.domainNumber=domainNumber;
ipcd.u.notice.domainIndex=di;
ipcd.u.notice.portIndex=pi;
gptpnet_ipc_notice(gpnetd, &ipcd, sizeof(ipcd));
return 0;
}
static int ipc_clock_notice(gptpman_data_t *gpmand)
{
int di, pi;
for(di=0;di<gpmand->max_domains;di++){
if(!DOMAIN_DATA_EXIST(di)) continue;
ipc_clock_master_clock_notice(gpmand->gpnetd,
gpmand->tasds[di].tasglb, di);
ipc_clock_this_clock_notice(gpmand->gpnetd, di,
gpmand->tasds[di].tasglb->domainNumber,
gpmand->tasds[di].tasglb->thisClockIndex);
for(pi=1;pi<gpmand->max_ports;pi++){
if(!gpmand->tasds[di].ptds[pi].ppglb) continue;
if(!gpmand->tasds[di].ptds[pi].ppglb->portEventFlags) continue;
ipc_port_state_notice(gpmand->gpnetd, di, pi,
gpmand->tasds[di].tasglb->domainNumber,
gpmand->tasds[di].ptds[pi].ppglb->portEventFlags);
gpmand->tasds[di].ptds[pi].ppglb->portEventFlags=0;
}
}
return 0;
}
static int gptpnet_cb(void *cb_data, int portIndex, gptpnet_event_t event,
int64_t *event_ts64, void *event_data)
{
gptpman_data_t *gpmand=(gptpman_data_t*)cb_data;
uint64_t cts64=*event_ts64;
int res=0;
UB_TLOG(UBL_DEBUGV, "index=%d event=%s\n", portIndex, gptpnet_event_debug[event]);
switch(event){
case GPTPNET_EVENT_NONE:
break;
case GPTPNET_EVENT_TIMEOUT:
gptpnet_cb_timeout(gpmand, cts64);
break;
case GPTPNET_EVENT_DEVUP:
res = gptpnet_cb_devup(gpmand, portIndex,
(event_data_netlink_t *)event_data, cts64);
break;
case GPTPNET_EVENT_DEVDOWN:
res = gptpnet_cb_devdown(gpmand, portIndex,
(event_data_netlink_t *)event_data, cts64);
break;
case GPTPNET_EVENT_RECV:
res = gptpnet_cb_recv(gpmand, portIndex,
(event_data_recv_t *)event_data, cts64);
break;
case GPTPNET_EVENT_TXTS:
res = gptpnet_cb_txts(gpmand, portIndex,
(event_data_txts_t *)event_data, cts64);
break;
}
ub_log_flush();
if(res) return res;
ipc_clock_notice(gpmand);
return 0;
}
static int gptpnet_ipc_cb(void *cbdata, uint8_t *rdata, int size, struct sockaddr *addr)
{
int di,ddi,pi,ppi;
int resetcmd=0;
uint32_t aligntime, cycletime;
gptpipc_client_req_data_t *reqdata=(gptpipc_client_req_data_t *)rdata;
gptpman_data_t *gpmand=(gptpman_data_t*)cbdata;
if(size < 16) {
UB_LOG(UBL_INFO,"%s:wrong received size:%d\n",__func__, size);
return -1;
}
switch(reqdata->cmd){
case GPTPIPC_CMD_DISCONNECT:
gptpnet_ipc_client_remove(gpmand->gpnetd, addr);
return 0;
case GPTPIPC_CMD_REQ_NDPORT_INFO:
if(reqdata->portIndex>0){
return ipc_respond_one_ndport(gpmand->gpnetd, reqdata->portIndex,
addr);
}else{
for(pi=1;pi<gpmand->max_ports;pi++)
ipc_respond_one_ndport(gpmand->gpnetd, pi, addr);
}
return 0;
case GPTPIPC_CMD_REQ_CLOCK_INFO:
di=get_domain_index_ipc(gpmand, reqdata);
if(di==-1) return -1;
if(di>=0){
if(!DOMAIN_DATA_EXIST(di)) return -1;
return ipc_respond_one_clock(gpmand->gpnetd,
gpmand->tasds[di].tasglb,
reqdata->portIndex,
reqdata->domainNumber,
addr);
}
for(di=0;di<gpmand->max_domains;di++){
if(!DOMAIN_DATA_EXIST(di)) continue;
// clockIndex=0 is the master clock and IPC needs only that info.
ipc_respond_one_clock(gpmand->gpnetd,
gpmand->tasds[di].tasglb,
0, gpmand->tasds[di].tasglb->domainNumber, addr);
}
return 0;
case GPTPIPC_CMD_REQ_GPORT_INFO:
di=get_domain_index_ipc(gpmand, reqdata);
if(di==-1) return 0;
// for a specific domain and a apecific port
if(di>=0 && reqdata->portIndex!=0){
if(!PORT_DATA_EXIST(di, reqdata->portIndex)) return -1;
return ipc_respond_one_gport(
gpmand->gpnetd,
gpmand->tasds[di].ptds[reqdata->portIndex].ppglb,
gpmand->tasds[di].ptds[reqdata->portIndex].bppglb,
gpmand->tasds[di].tasglb,
reqdata->portIndex,
reqdata->domainNumber, di, addr);
}
ppi=di;
for(di=0;di<gpmand->max_domains;di++){
if(ppi>=0 && ppi!=di) continue; // skip for a specific domain
for(pi=1;pi<gpmand->max_ports;pi++){
if(!PORT_DATA_EXIST(di,pi)) continue;
ipc_respond_one_gport(
gpmand->gpnetd,
gpmand->tasds[di].ptds[pi].ppglb,
gpmand->tasds[di].ptds[pi].bppglb,
gpmand->tasds[di].tasglb,
pi, gpmand->tasds[di].tasglb->domainNumber, di,
addr);
}
}
return 0;
case GPTPIPC_CMD_ACTIVE_DOMAINT_SWITCH:
gptpclock_active_domain_switch(reqdata->domainIndex);
return 0;
case GPTPIPC_CMD_RUN_EXT_SCRIPT:
// use reqdata->domainNumber as single argument
run_ext_script(&gpmand->extcmdstdin, reqdata->domainNumber);
return 0;
case GPTPIPC_CMD_TSN_SCHEDULE_CONTROL:
// use reqdata->domainNumber
// reqdata->domainNumber=0: to stop,
// reqdata->domainNumber=1: to start
aligntime=gptpconf_get_intitem(CONF_TSN_SCHEDULE_ALIGNTIME);
if(reqdata->domainNumber==0)
cycletime=0;
else
cycletime=gptpconf_get_intitem(CONF_TSN_SCHEDULE_CYCLETIME);
gptpnet_tsn_schedule(gpmand->gpnetd, aligntime, cycletime);
return 0;
case GPTPIPC_CMD_REQ_STAT_INFO_RESET:
resetcmd=1;
// fall through
case GPTPIPC_CMD_REQ_STAT_INFO:
ddi=get_domain_index_ipc(gpmand, reqdata);
if(reqdata->domainNumber>=0 && ddi<0) return -1;
ppi=reqdata->portIndex;
for(di=0;di<gpmand->max_domains;di++){
if(ddi>=0 && ddi!=di) continue;
for(pi=1;pi<gpmand->max_ports;pi++){
if(ppi>0 && ppi!=pi) continue;
if(di==0) ipc_respond_statsd_info(gpmand, pi, resetcmd,
addr);
ipc_respond_stattd_info(gpmand, di, pi, resetcmd,
addr);
}
}
return 0;
case GPTPIPC_CMD_REG_ABNORMAL_EVENT:
return ipc_register_abnormal_event(reqdata);
default:
return -1;
}
}
static int stopgptp;
static void signal_handler(int sig)
{
stopgptp=1;
}
static int domain_zero_port_sm_init(gptpsm_tasd_t *tasd, gptpnet_data_t *gpnetd, int pi)
{
md_pdelay_req_sm_init(&tasd->ptds[pi].mdpdreqd, pi, gpnetd,
tasd->tasglb, tasd->ptds[pi].ppglb, tasd->ptds[pi].mdeglb);
md_pdelay_resp_sm_init(&tasd->ptds[pi].mdpdrespd, pi, gpnetd,
tasd->tasglb, tasd->ptds[pi].ppglb);
link_delay_interval_setting_sm_init(&tasd->ptds[pi].ldisetd, pi,
tasd->tasglb, tasd->ptds[pi].ppglb,
tasd->ptds[pi].mdeglb);
return 0;
}
static int domain_port_sm_init(gptpsm_tasd_t *tasd, gptpnet_data_t *gpnetd, int di, int pi)
{
port_announce_information_sm_init(&tasd->ptds[pi].painfd, di, pi,
tasd->tasglb, tasd->ptds[pi].ppglb,