From 3ff0a0eb5cf4ec2a23003946cfbc5a07d5ddb8ff Mon Sep 17 00:00:00 2001 From: Aleksy Grabowski Date: Thu, 16 Nov 2023 17:35:03 +0100 Subject: [PATCH] Update protocol FSM --- Makefile | 2 ++ protocol-adjust.sed | 48 +++++++++++++++++++++++++++++++++++++++++++++ protocol.rl | 38 ++++++++++++++++++++++------------- 3 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 protocol-adjust.sed diff --git a/Makefile b/Makefile index de8ffc9..3c4e8e6 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,8 @@ scan: scan-build $(MAKE) clean frob graph-%: frame.rl adjust-%.sed ragel -p -V $< | sed -Ef $(word 2,$^) | dot -Tpng | feh - +protocol.png: protocol.rl protocol-adjust.sed + ragel -p -V $(word 1,$^) | sed -Ef $(word 2,$^) | dot -Tpng -Gdpi=200 -o $@ # Internal targets ############################################################# tags: diff --git a/protocol-adjust.sed b/protocol-adjust.sed new file mode 100644 index 0000000..c939078 --- /dev/null +++ b/protocol-adjust.sed @@ -0,0 +1,48 @@ +s/\b1000\b/T1/g +s/\b1002\b/T2/g +s/\b1003\b/T3/g +s/\b1004\b/T4/g +s/\b1005\b/T5/g +s/\b2000\b/D0/g +s/\b20000\b/D0(Ok)/g +s/\b20001\b/D0(No)/g +s/\b2001\b/D1/g +s/\b2002\b/D2/g +s/\b2003\b/D3/g +s/\b2004\b/D4/g +s/\b2005\b/D5/g +s/\b2006\b/D6/g +s/\b2007\b/D7/g +s/\b2008\b/D8/g +s/\b20090\b/D9(last)/g +s/\b20091\b/D9(part)/g +s/\b2010\b/DA/g +s/\b3001\b/S1/g +s/\b3002\b/S2/g +s/\b5001\b/I1/g +s/\b4001\b/P1/g +s/\b6001\b/A1/g +s/\b6002\b/A2/g +s/\b60020\b/A2(Ok)/g +s/\b60021\b/A2(No)/g +s/\b7000\b/K0/g +s/\b70000\b/K0(Ok)/g +s/\b70001\b/K0(No)/g +s/\b7001\b/K1/g +s/\b7002\b/K2/g +s/\b7003\b/K3/g +s/\b7004\b/K4/g +s/\b7005\b/K5/g +s/\b7006\b/K6/g +s/\b7007\b/K7/g +s/\b7008\b/K8/g +s/\b7009\b/K9/g +s/\b8001\b/M1/g +s/\b9001\b/L1/g +s/\b10001\b/B1/g +s/\b100020\b/B2(Ok)/g +s/\b100021\b/B2(No)/g +s/\b10003\b/B3/g +s/\b10004\b/B4/g +s/\bcircle\b/point/ +s/, height = 0.65/, label = ""/ diff --git a/protocol.rl b/protocol.rl index 7992a73..6340109 100644 --- a/protocol.rl +++ b/protocol.rl @@ -4,7 +4,7 @@ %%{ machine frob_protocol; - alphtype unsigned short; + alphtype unsigned int; variable cs (*cs); @@ -15,19 +15,30 @@ T4 = 1004; T5 = 1005; D0 = 2000; + D0ok= 20000; + D0no= 20001; D1 = 2001; D2 = 2002; D3 = 2003; D4 = 2004; D5 = 2005; D6 = 2006; + D7 = 2007; + D8 = 2008; + D90= 20090; + D9x= 20091; + DA = 2010; S1 = 3001; S2 = 3002; I1 = 5001; P1 = 4001; A1 = 6001; A2 = 6002; + A2ok= 60020; + A2no= 60021; K0 = 7000; + K0ok= 70000; + K0no= 70001; K1 = 7001; K2 = 7002; K3 = 7003; @@ -40,26 +51,25 @@ M1 = 8001; L1 = 9001; B1 = 10001; - B2 = 10002; + B2ok=100020; + B2no=100021; B3 = 10003; B4 = 10004; communication_test = T1 T2; version_negotiation = T3 T4 T5; - receipt = D2 D0 (D6 D0)* D3 D0; + receipt_printing = D2 D0ok (D6 D0)* D3 D0 | D2 D0no; + receipt_logo_mgmt = (D7 D8) | (DA D0) | (D90 D0 | (D9x D0)* D90 D0); configuration = D4 D5; - custom_flow = A1 A2 K1 K0 ((K3|K4|K5|K6|K7|K8|K9) K0)* K2 K0; - key_exchange = (B1 B2) | (B1 B2 B3 B4); + custom_flow = (K1 K0ok ((K3|K4|K5|K6|K7|K8|K9) K0)* K2 K0) | K1 K0no; + key_exchange = B1 B2ok B3 B4 | B1 B2no; + transaction = S1 (P1 | I1)* S2; + printer = (receipt_printing | receipt_logo_mgmt); - transaction = (S1 I1* receipt* I1* S2) | - (S1 P1 I1* S2) | - (S1 (I1 P1?)* S2) | - (S1 (P1? I1)* S2); - - all = communication_test | version_negotiation | configuration | - transaction | custom_flow | M1 | L1 | key_exchange; - - main := all*; + async := (L1 | configuration | version_negotiation | communication_test | printer)*; + encdec := key_exchange*; + aux := (A1 A2no | A1 A2ok custom_flow)*; + main := (A1 A2 | transaction | M1)*; write data; }%%