state HELLO: recv_pack
state HELLO: bpf = "tcp and port 21"
state HELLO: 2 branches
state HELLO: branch #1 points to state AGAIN
state HELLO: branch #1 checks 2 fields
state HELLO: branch #1 field #1 is TCP.sport = 123
state HELLO: branch #1 field #2 is TCP.dport = 21
state HELLO: branch #2 points to state OKAY
state HELLO: branch #2 checks 2 fields
state HELLO: branch #2 field #1 is UDP.sport = 567
state HELLO: branch #2 field #2 is UDP.dport = 54

init 10 states;
create state HELLO;
state HELLO: recv_pack {
	bpf = "tcp and port 21"
	2 branches
	{
	  ( next state: AGAIN
	    check 2 fields
	    TCP.sport = 123 and
	    TCP.dport = 21
	  ) or 
	  ( next state: OKAY
	    check 2 fields
	    UDP.clock = 567 and
	    UDP.wall = 54
	  )
	}
};

init 10 states;
load headers : "./headers";
create state HELLO;
create state AGAIN;
create state HOLD;
create state ADIOS;
state HELLO recv_pack {
        bpf = "tcp and port 21"
	( next state: AGAIN
	  check: TCP.sport = 123 and
		 TCP.dport = 21
	) or
	( next state: ADIOS
	  check: IP.saddr = 567 and
		 IP.daddr = 54
	)
};
	
state AGAIN send_pack {
	pack_id : 1
	next state : HOLD
};

state HOLD wait {
	210ms
	next state : HELLO
};

state ADIOS finish ;


state HELLO recv_pack (RID = 1) {
  bpf = "tcp and port 21"
  ( next state: AGAIN
    check:      {IP}>TCP.sport = 123 and
                {IP}>TCP.dport = 21
  ) or
  ( next state: ADIOS
    check:      {IP}{TCP}>DATA.letra1 = 567 
                {IP}{TCP}>DATA.letra2 = 54
  )
};
						  




init 2 states;
load headers : "./headers";
load packets : "./packer/out_pack";
create state AGAIN;
create state BYEBYE;
state AGAIN send_pack {
  pack_id : 1
  next state : BYEBYE
};
state BYEBYE finish ;

state HELLO recv_pack (RID = 1) {
  bpf = "tcp and port 21"
  ( next state: AGAIN
    check: 	{IP}>TCP.sport = 123 and
    		{IP}>TCP.dport = 21
  ) or
  ( next state: ADIOS
    check: 	IP.saddr = 567 and
    		IP.daddr = 54
  )
};
											      
  but : {IP}>TCP.seqnum = 123 and
        {IP}>TCP.dport = [BYEBYE]{IP}>TCP.dport + 1 and
        {IP}>TCP.sport = {IP}>TCP.sport + 1 and
        {IP}>TCP.flags  = [2]{IP}>TCP.flags
			  

state COMMAND shell {
  command : "ls"
  next state : BYEBYE
};


init 4 states;
load headers : "./headers";
load packets : "./packer/out_pack";
create state AGAIN;
create state BYEBYE;
create state HELLO;
create state COMMAND;
state AGAIN send_pack {
  pack_id : 1
  but : {IP}>TCP.seqnum = 123 + 2 and
	{IP}>TCP.sport  = {IP}{TCP}>DATA.l1 + [2]{IP}>TCP.flags and
	{IP}{TCP}>DATA.l1  = [2]{IP}>TCP.flags and
        {IP}>TCP.dport  = [HELLO]{IP}{TCP}>DATA.l1
  next state : COMMAND
};
state COMMAND shell {
  command : "ls"
  next state : HELLO
};
state BYEBYE finish ;
state HELLO recv_pack {
  bpf = "tcp and port 21"
  timeout = 1000ms:BYEBYE
  ( next state: AGAIN
    check:      {IP}>TCP.sport = 123 and
                {IP}>TCP.dport = 21 and
		{IP}>TCP.seqnum = 123 
  ) or
  ( next state: HELLO
    check:	{IP}{TCP}>DATA.l1 = 567 and
    		{IP}{TCP}>DATA.l2 = 54
  ) or
  ( next state: BYEBYE
    check:      IP.saddr = 789 and
	        IP.daddr = 987
  )
};

init 5 states;
load headers : "./headers";
create state CHOICER;
create state CHOICE1;
create state CHOICE2;
create state CHOICE3;
create state CHOICE4;
state CHOICE1 shell {
  command	: "eject"
  next state	: CHOICER
};
state CHOICE2 shell {
  command       : "eject -t"
  next state 	: CHOICER
};
state CHOICE3 wait {
  500ms 
  next state : CHOICER
};
state CHOICE4 finish;
state CHOICER recv_pack {
  bpf = "ip"
  timeout = 5000ms:CHOICER
  ( next state:	CHOICE1
    check:	{IP}>TCP.dport = 23 and
    		{IP}{TCP}>DATA.letra1 = 'b'
  ) or
  ( next state:	CHOICE2
    check:	{IP}>TCP.dport = 23 and
    		{IP}{TCP}>DATA.letra1 = 'v'
  ) or
  ( next state: CHOICE3
    check:      {IP}>TCP.dport = 23 and
                {IP}{TCP}>DATA.letra1 = 'c'
  )  
};

  but : {IP}>TCP.seqnum = 123 + 2 and
  	{IP}>TCP.sport  = {IP}{TCP}>DATA.l1 + [2]{IP}>TCP.flags and
	{IP}{TCP}>DATA.l1  = [2]{IP}>TCP.flags and
	{IP}>TCP.dport  = [BYEBYE]{IP}{TCP}>DATA.l1 and
	{IP}>TCP.cksum = std_cksum(TCP)
				  
{IP}>TCP.seqnum = [BYEBYE]{IP}{TCP}>DATA.l1 and

init 4 states;
load headers : "./headers";
load packets : "./packer/out_pack";
create state AGAIN;
create state BYEBYE;
create state COMMAND;
create state CHOICER;
state AGAIN send_pack {
  pack_id : 1
  but :	{IP}>TCP.sport  = {IP}{TCP}>DATA.l1 + [2]{IP}>TCP.flags and
  	{IP}>TCP.seqnum = [BYEBYE]{IP}{TCP}>DATA.l1 and
   	IP.daddr = 0x1234 and
	IP.saddr = IP.daddr and
	{IP}>TCP.flags = [2]{IP}>TCP.flags + IP.daddr and
	{IP}>TCP.cksum = std_cksum(TCP)
  next state : COMMAND
};
state BYEBYE finish ;
state COMMAND shell {
  command : "ls"
  next state : BYEBYE
};
state CHOICER recv_pack {
  bpf = "ip"
  timeout = 5000ms:CHOICER
  ( next state: AGAIN
    check:  	{IP}>TCP.dport = 23 and
	  	{IP}{TCP}>DATA.letra1 = 'b'
  ) or
  ( next state:	BYEBYE
    check:	{IP}>TCP.dport = 23 and
                {IP}{TCP}>DATA.letra1 = 'v'
  ) or
  ( next state: COMMAND
    check:      {IP}>TCP.dport = 23 and
                {IP}{TCP}>DATA.letra1 = 'c'
  )
};
									    
