epdg_diameter_swx: add Service-Assignment-Request

This commit is contained in:
Alexander Couzens 2023-05-26 13:49:25 +03:00
parent d262c0b55f
commit 0596a82539
2 changed files with 32 additions and 0 deletions

View File

@ -50,6 +50,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2]).
-export([code_change/3]).
-export([multimedia_auth_request/6]).
-export([server_assignment_request/3]).
-export([test/0, test/1]).
%% Diameter Application Definitions
@ -121,6 +122,10 @@ test(IMSI) ->
multimedia_auth_request(IMSI, NumAuthItems, AuthScheme, RAT, CKey, IntegrityKey) ->
gen_server:call(?SERVER,
{mar, {IMSI, NumAuthItems, AuthScheme, RAT, CKey, IntegrityKey}}).
% APN is optional and should be []
server_assignment_request(IMSI, Type, APN) ->
gen_server:call(?SERVER,
{sar, {IMSI, Type, APN}}).
% TODO Sync failure
handle_call({mar, {IMSI, NumAuthItems, AuthScheme, RAT, CKey, IntegrityKey}}, _From, State) ->
@ -145,6 +150,25 @@ handle_call({mar, {IMSI, NumAuthItems, AuthScheme, RAT, CKey, IntegrityKey}}, _F
{error, Err} ->
lager:error("Error: ~w~n", [Err]),
{reply, {error, Err}, State}
end;
handle_call({sar, {IMSI, Type, APN}}, _From, State) ->
SessionId = diameter:session_id(application:get_env(?SERVER, origin_host, "aaa.example.org")),
SAR = #'SAR'{'Vendor-Specific-Application-Id' = #'Vendor-Specific-Application-Id'{
'Vendor-Id' = ?VENDOR_ID_3GPP,
'Auth-Application-Id' = [?DIAMETER_APP_ID_SWX]},
'Session-Id' = SessionId,
'User-Name' = IMSI,
'Auth-Session-State' = 1,
'Server-Assignment-Type' = Type,
'Service-Selection' = APN
},
Ret = diameter:call(?SVC_NAME, ?APP_ALIAS, SAR, []),
case Ret of
{ok, SAA} ->
{reply, {ok, SAA}, State};
{error, Err} ->
lager:error("Error: ~w~n", [Err]),
{reply, {error, Err}, State}
end.
%% @callback gen_server

View File

@ -43,6 +43,14 @@ prepare_request(#diameter_packet{msg = Req}, _, {_, Caps})
'Origin-Realm' = OR,
'Destination-Host' = [DH],
'Destination-Realm' = DR},
{send, Msg};
prepare_request(#diameter_packet{msg = Req}, _, {_, Caps})
when is_record(Req, 'SAR') ->
#diameter_caps{origin_host = {OH, DH}, origin_realm = {OR, DR}} = Caps,
Msg = Req#'SAR'{'Origin-Host' = OH,
'Origin-Realm' = OR,
'Destination-Host' = [DH],
'Destination-Realm' = DR},
{send, Msg}.
%% prepare_retransmit/3