anchor.diff:  %% @see //stdlib/gen_server:handle_call/3
   %% @private
   handle_call({diameter_request, Caps, Request}, _From, State) ->
  -	#diameter_caps{origin_host = {OHost,_}, origin_realm = {ORealm,_}} = Caps,
  -	request(OHost, ORealm, Request, State).
  +	request(Caps, Request, State).
   
   -spec handle_cast(Request, State) -> Result
   	when
  
positive.code: 		UserName:: string(),
  		Password :: string(),
  		State :: state(),
  		Result :: {reply, Answer, State},
  		Answer :: #diameter_nas_app_AAA{}.
  start_fsm(AuthSup, AppId, SessId, Type, OHost, ORealm, UserName,
  			Password, State) ->
  	StartArgs = [diameter, SessId, AppId, Type, OHost, ORealm, UserName, Password],
  	ChildSpec = [StartArgs, []],
  	case supervisor:start_child(AuthSup, ChildSpec) of
  		{ok, Fsm} ->
  			Answer = gen_fsm:sync_send_all_state_event(Fsm, diameter_request),
  			{reply, Answer, State};
  		{error, _Reason} ->
  			Answer = #diameter_nas_app_AAA{'Session-Id' = SessId,
  					'Auth-Application-Id' = 1, 'Auth-Request-Type' = 1,
  					'Result-Code' = ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  					'Origin-Host' = OHost, 'Origin-Realm' = ORealm },
  			{reply, Answer, State}
  	end.
  
  
negative.code: %%  internal functions
  %%----------------------------------------------------------------------
  
  -spec request(Caps, Request, State) -> Reply
  	when
  		Caps :: capabilities(),
  		Request :: #diameter_nas_app_AAR{} | #diameter_nas_app_STR{},
  		State :: state(),
  		Reply :: {reply, Answer, State},
  		Answer :: #diameter_nas_app_AAA{} | #diameter_nas_app_STA{}.
  %% @doc Based on the DIAMETER request generate appropriate DIAMETER
  %% answer.
  %% @hidden
  request(Caps, Request, State) when is_record(Request, diameter_nas_app_AAR) ->
  	#diameter_caps{origin_host = {OHost,_}, origin_realm = {ORealm,_}} = Caps,
  	request1(OHost, ORealm, Request, State);
  request(Caps, Request, State) when is_record(Request, diameter_nas_app_STR) ->
  	#diameter_caps{origin_host = {OHost,_}, origin_realm = {ORealm,_}} = Caps,
  	SessionId = Request#diameter_nas_app_STR.'Session-Id',
  	try
  		Username = Request#diameter_nas_app_STR.'User-Name',
  		F = fun() ->
  			case mnesia:read(subscriber, Username, write) of
  				[#subscriber{disconnect = false} = Entry] ->
  					NewEntry = Entry#subscriber{disconnect = true},
  					mnesia:write(subscriber, NewEntry, write);
  				[#subscriber{disconnect = true}] ->
  					ok
  			end
  		end,
  		mnesia:transaction(F)
  	of
  		{atomic, ok} ->
  			Answer = #diameter_nas_app_STA{'Session-Id' = SessionId,
  					'Result-Code' = ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
  					'Origin-Host' = OHost, 'Origin-Realm' = ORealm},
  			{reply, Answer, State}
  	catch
  		_:_ ->
  			Answer = #diameter_nas_app_STA{'Session-Id' = SessionId,
  					'Result-Code' = ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  					'Origin-Host' = OHost, 'Origin-Realm' = ORealm},
  			{reply, Answer, State}
  	end.
  %% @hidden
  request1(OHost, ORealm, Request, #state{handlers = Handlers} = State) ->
  	SessionId = get_session_id(Request),
  	try
  		#diameter_nas_app_AAR{'Auth-Request-Type' = Type, 'User-Name' = UserName,
  				'User-Password' = Password} = Request,
  		case gb_trees:lookup(SessionId, Handlers) of
  			none ->
  				SimpleAuthSup = State#state.simple_auth_sup,
  				case {UserName, Password} of
  					{UserName, Password} when (UserName /= undefined andalso
  							Password /= undefined) ->
  						{Fsm, NewState} = start_fsm(SimpleAuthSup, 1, SessionId, Type, OHost, ORealm, UserName,
  							Password, State),
  						Answer = gen_fsm:sync_send_all_state_event(Fsm, diameter_request),
  						{reply, Answer, NewState};
  					_ ->
  						Answer = #diameter_nas_app_AAA{
  								'Result-Code' = ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  								'Origin-Host' = OHost, 'Origin-Realm' = ORealm, 'Session-Id' = SessionId},
  						{reply, Answer, State}
  					end;
  			{value, _Fsm} ->
  				Answer = #diameter_nas_app_AAA{'Session-Id' = SessionId,
  						'Auth-Application-Id' = 1, 'Auth-Request-Type' = Type,
  						'Result-Code' = ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
  						'Origin-Host' = OHost, 'Origin-Realm' = ORealm },
  				{reply, Answer, State}
  		end
  	catch
  		_:_ ->
  			Error = #diameter_nas_app_AAA{
  					'Result-Code' = ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  					'Origin-Host' = OHost, 'Origin-Realm' = ORealm, 'Session-Id' = SessionId},
  			{reply, Error, State}
  	end.
  
  %% @hidden
  -spec start_fsm(AuthSup, AppId, SessionId, AuthRequestType, OHost,
  		ORealm, UserName, Password, State) -> NewState
  	when
  		AuthSup :: pid(),
  		AppId :: non_neg_integer(),
  