anchor.diff:  	process_flag(trap_exit, true),
   	{ok, HssRealm} = application:get_env(hss_realm),
   	{ok, HssHost} = application:get_env(hss_host),
  -	{ok, idle, #statedata{origin_host = OHost, origin_realm = ORealm,
  +	Service = lists:keyfind(ocs_diameter_auth_service, 1, diameter:services()),
  +	{ok, idle, #statedata{service = Service,
  +			origin_host = OHost, origin_realm = ORealm,
   			hss_realm = HssRealm, hss_host = HssHost}}.
   
   -spec idle(Event, StateData) -> Result
  
positive.code: 	{next_state, idle, StateData};
  idle1({error, not_found},
  		#statedata{hss_realm = _HssRealm} = StateData) ->
  	{next_state, auth, StateData};
  idle1({error, Reason}, #statedata{aka_fsm = AkaFsm} = StateData) ->
  	error_logger:error_report(["Service lookup failure",
  			{module, ?MODULE}, {error, Reason}]),
  
negative.code: 	crypto:hmac(sha256, <<CK/binary, IK/binary>>,
  			<<16#20, "WLAN", 4:16, SQNi:48, 6:16>>).
  
  -spec send_diameter_request(StateData) -> Result
  	when
  		StateData :: #statedata{},
  		Result :: ok | {error, Reason},
  		Reason :: term().
  %% @doc Send DIAMETER request to HSS.
  %% @hidden
  send_diameter_request(#statedata{hss_host = undefined,
  		hss_realm = HssRealm, origin_host = OriginHost,
  		origin_realm = OriginRealm} = StateData) ->
  	SessionId = diameter:session_id([OriginHost]),
  	Request = #'3gpp_swx_MAR'{'Session-Id' = SessionId,
  			'Origin-Realm' = OriginRealm, 'Origin-Host' = OriginHost,
  			'Destination-Realm' = HssRealm},
  	send_diameter_request1(Request, StateData);
  send_diameter_request(#statedata{hss_host = HssHost,
  		hss_realm = HssRealm, origin_host = OriginHost,
  		origin_realm = OriginRealm} = StateData) ->
  	SessionId = diameter:session_id([OriginHost]),
  	Request = #'3gpp_swx_MAR'{'Session-Id' = SessionId,
  			'Origin-Realm' = OriginRealm, 'Origin-Host' = OriginHost,
  			'Destination-Realm' = HssRealm, 'Destination-Host' = HssHost},
  	send_diameter_request1(Request, StateData).
  %% @hidden
  send_diameter_request1(Request1, #statedata{anid = undefined,
  		identity = Identity} = StateData) ->
  	AuthData = #'3gpp_swx_SIP-Auth-Data-Item'{
  			'SIP-Authentication-Scheme' = <<"EAP-AKA">>},
  	Request2 = Request1#'3gpp_swx_MAR'{'User-Name' =  Identity,
  			'SIP-Number-Auth-Items' = 1,
  			'SIP-Auth-Data-Item' = AuthData},
  	send_diameter_request2(Request2, StateData);
  send_diameter_request1(Request1, #statedata{anid = ANID,
  		identity = Identity} = StateData) ->
  	AuthData = #'3gpp_swx_SIP-Auth-Data-Item'{
  			'SIP-Authentication-Scheme' = <<"EAP-AKA'">>},
  	Request2 = Request1#'3gpp_swx_MAR'{'User-Name' =  Identity,
  			'ANID' = list_to_binary(ANID), 'SIP-Number-Auth-Items' = 1,
  			'SIP-Auth-Data-Item' = AuthData},
  	send_diameter_request2(Request2, StateData).
  %% @hidden
  send_diameter_request2(Request1, #statedata{service = Service} = _StateData) ->
  	Request2 = Request1#'3gpp_swx_MAR'{'Auth-Session-State' = 1},
  	diameter:call(Service, ?SWx_APPLICATION,
  			Request2, [detach, {extra, [self()]}]).
  
  