anchor.diff:  		  end,
   
       Msg = {Header, {ReqType, SeqNumToUse, IEs}},
  -    {Packet, CtrlStreamState1} = capwap_stream:encode(control, Msg, CtrlStreamState0),
  +    {Packet, CtrlStreamData1} = capwap_stream:encode(control, Msg, CtrlStreamData0),
       lager:debug("in do_transition, ~p to send: ~p", [ReqType, Packet]),
   
  -    do_transition(State#state{ctrl_stream = CtrlStreamState1}, control,
  -		  NextState, {packet, Packet}, Mode, RespSeq, UserCallback);
  +    do_transition(Data#data{ctrl_stream = CtrlStreamData1}, control,
  +		  {packet, Packet}, Mode, RespSeq, UserCallback);
   
   %% send packet and make state transition
   %% mode = async | udp_sync
  -%% udp_sync: forces udp usage when otherwise capwapa-dtls would be used
  -do_transition(State=#state{remote_mode = RemoteMode,
  +%% udp_sync: forces udp usage when otherwise capwap-dtls would be used
  +do_transition(Data = #data{remote_mode = RemoteMode,
   			   request_pending=undefined},
  -	      Type, NextState, {packet, Packet},
  +	      Type, {packet, Packet},
   	      Mode, RespSeq, UserCallback) ->
  -    State0 = case Mode of
  -		 udp_sync ->
  -		     S1 = send_capwap(State#state{remote_mode = false}, Type, Packet),
  -		     S1#state{remote_mode = RemoteMode};
  -		 _ ->
  -		     send_capwap(State, Type, Packet)
  -	     end,
  -    State1 = case UserCallback of
  +    {Data0, Timer} =
  +	case Mode of
  +	    udp_sync ->
  +		{S1, Actions} = send_capwap(Data#data{remote_mode = false}, Type, Packet),
  +		{S1#data{remote_mode = RemoteMode}, Actions};
  +	    _ ->
  +		send_capwap(Data, Type, Packet)
  +	end,
  +    Data1 = case UserCallback of
   		 undefined ->
  -		     State0;
  +		     Data0;
   		 {RespType, From} ->
  -		     State0#state{request_pending={RespType,From}}
  +		     Data0#data{request_pending={RespType,From}}
   	     end,
       case {Type, Mode, RespSeq} of
   	{control, udp_sync, _} ->
  -	    Resp = recv_capwap(State1#state{remote_mode = false}),
  +	    Resp = recv_capwap(Data1#data{remote_mode = false}),
   	    DecResp = capwap_packet:decode(control, Resp),
  -	    {resp, DecResp, bump_seqno(State1)};
  +	    {resp, DecResp, bump_seqno(Data1), Timer};
   	{_, _, {resp, _}} ->
  -	    {next_state, NextState, State1};
  +	    {data, Data1, Timer};
   	{control, _, req} ->
  -	    {next_state, NextState, bump_seqno(State1)};
  +	    {data, bump_seqno(Data1), Timer};
   	{data, _, req} ->
  -	    {next_state, NextState, State1}
  +	    {data, Data1, Timer}
       end.
   
   create_default_ies() ->
  
positive.code: -module(wtp_mockup_fsm).
  -compile([{parse_transform, lager_transform}]).
  
  -behaviour(gen_fsm).
  
  -include("../include/capwap_packet.hrl").
  
  
negative.code:     ].
  
  timestamp() ->
      erlang:system_time(second).
  
  handle_incoming(Response = {#capwap_header{},
  			    {wtp_event_response, _, _RemoteSeq, _IEs}},
  		run, control,
  		Data = #data{request_pending={wtp_event_response, From}}) ->
      {keep_state, remove_rp(Data), {reply, From, {ok, Response}}};
  
  handle_incoming(Response = {#capwap_header{},
  			    {join_response, _, _RemoteSeq, _IEs}},
  		discovery, control,
  		Data = #data{request_pending={join_response, From}}) ->
      {next_state, join, remove_rp(Data), {reply, From, {ok, Response}}};
  
  handle_incoming(Response = {#capwap_header{},
  			    {configuration_status_response, _, _RemoteSeq, IEs}},
  		join, control,
  		Data = #data{request_pending={configuration_status_response, From}}) ->
      #timers{echo_request = EchoTimer} = lists:keyfind(timers, 1, IEs),
      {next_state, configure, remove_rp(Data#data{echo_request_timeout = EchoTimer}),
       {reply, From, {ok, Response}}};
  
  handle_incoming(Request = {#capwap_header{},
  			   {ieee_802_11_wlan_configuration_request, _, RemoteSeq, _WlanConfigIEs}} = Req,
  		_StateName, control,
  		Data = #data{owner = Owner, request_pending = RP}) ->
      lager:debug("Got expected wlan_config_request in ~p: ~p", [_StateName, Req]),
      Owner ! Request,
      {data, Data1, Actions} =
  	do_transition(Data#data{wifi_up = true, request_pending = undefined},
  		      control,
  		      {ieee_802_11_wlan_configuration_response,[#result_code{}]},
  		      async, {resp, RemoteSeq}, undefined),
      {keep_state, Data1#data{request_pending = RP}, Actions};
  
  handle_incoming(Request = {#capwap_header{},
  			   {station_configuration_request, _, RemoteSeq, _StationConfigIEs}} = Req,
  		run, control,
  		Data = #data{request_pending = {add_station_resp, From}}) ->
      lager:debug("got expected station_config_request: ~p", [Req]),
      {data, DataNew, Actions} =
  	do_transition(remove_rp(Data), control,
  		      {station_configuration_response, [#result_code{}]},
  		      async, {resp, RemoteSeq}, undefined),
      {keep_state, DataNew, [{reply, From, {ok, Request}} | Actions]};
  
  handle_incoming(Response = {_Header, {change_state_event_response, _, _, []}},
  		configure, control,
  		Data = #data{capwap_wtp_session_id = CapwapWtpSessionId,
  			    request_pending = {change_state_event_response, From},
  			    options = Options})  ->
      %% establish dtls on data socket if remote_mode = true
      %% currently not in use (TODO add option for dtls usage on data socket)
      %% Data0 = case Data#data.remote_mode of
      %% 		 true ->
      %% 		     %% {ok, DataSocket} = ssl:connect(UdpDataSocket, make_ssl_options(Data1)),
      %% 		     %% lager:info("successfull ssl handshake done for data socket", []),
      %% 		     %% ok = ssl:setopts(DataSocket, [{active, true}]),
      %% 		     Data#data{data_socket = UdpDataSocket};
      %% 		 false ->
      %% 		     Data
      %% 	     end,
  
      Flags = ['keep-alive', {frame,'802.3'}],
      KeepAliveIEs = [#session_id{session_id = CapwapWtpSessionId}],
      KeepAliveTimeout = proplists:get_value(data_keep_alive_timeout, Options, 30),
      {data, DataNew, Actions0} =
  	do_transition(remove_rp(Data#data{keep_alive_timeout = KeepAliveTimeout}),
  		      data, {Flags, KeepAliveIEs}),
      Actions = keep_alive_timer(DataNew) ++ Actions0,
      {next_state, run, DataNew, [{reply, From, {ok, Response}} | Actions]};
  
  handle_incoming({Header, _} = Req, run, data, Data) ->
      KeepAlive = proplists:get_bool('keep-alive', Header#capwap_header.flags),
      case KeepAlive of
  	true ->
  	    lager:debug("WTP ~p received keep-alive in RUN state! ~p",
  			[Data#data.ip, Data#data.keep_alive_timeout]),
  	    keep_state_and_data;
  	false ->
  	    lager:warning("in ~p received a data response not expected: ~p", [run, Req]),
  	    keep_state_and_data
      end;
  
  handle_incoming(Req, StateName,	Type, _Data) ->
      lager:warning("handle_incoming: in ~p received a ~p response not expected: ~p",
  		  [StateName, Type, Req]),
      keep_state_and_data.
  
  make_ssl_options(#data{cert_dir = CertDir,
  			root_cert = RootCert}) ->
      [{active, once},
       {mode, binary},
  