dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/onomondo-eim/+/43013?usp=email )
Change subject: esipa_asn1_handler: store IPAd stateChangeCause ......................................................................
esipa_asn1_handler: store IPAd stateChangeCause
The IPAd may pass a notifyStateChange and a stateChangeCause code. The notifyStateChange flag tells that a state change happened and the stateChangeCause code tells what the cause was.
let's store the stateChangeCause code as a state in the euicc table, so that the REST API user can poll for stateChangeCause codes in suitable intervals.
Change-Id: I3fe64687786d9184ae82cbb12f9d1292fdc945c8 Related: SYS#8100 --- M contrib/tryme_euicc_get_state.sh M contrib/tryme_euicc_set_state.sh M include/mnesia_db_euicc.hrl M src/esipa_asn1_handler.erl M src/mnesia_db_euicc.erl 5 files changed, 38 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/onomondo-eim refs/changes/13/43013/1
diff --git a/contrib/tryme_euicc_get_state.sh b/contrib/tryme_euicc_get_state.sh index 524d37d..dc96cf0 100755 --- a/contrib/tryme_euicc_get_state.sh +++ b/contrib/tryme_euicc_get_state.sh @@ -2,7 +2,7 @@ . ./tryme.cfg
# States we want to retrieve with this request. -STATES='"counterValue", "consumerEuicc", "signAlgo", "signPubKey"' +STATES='"counterValue", "consumerEuicc", "signAlgo", "signPubKey", "stateChangeCauseList"'
JSON='{ "eidValue" : "'$EID'", "order" : { "euicc" : { "get" : [ '$STATES' ] } } }' RC=`./restop.py -c -f euicc -j "$JSON"` diff --git a/contrib/tryme_euicc_set_state.sh b/contrib/tryme_euicc_set_state.sh index d016ce1..04d8c51 100755 --- a/contrib/tryme_euicc_set_state.sh +++ b/contrib/tryme_euicc_set_state.sh @@ -6,7 +6,8 @@ STATES='[{ "counterValue" : 1000 }, { "consumerEuicc" : false }, { "signAlgo" : "prime256v1" }, - { "signPubKey" : "04BD2C55B28B4E801CA0B14F195788FD86C7FF49764C88A2934C69594A26FF647549F3F16060BD9C8D793D95D0126FA429C94966FE7842967263795A73C498F1DB" }]' + { "signPubKey" : "04BD2C55B28B4E801CA0B14F195788FD86C7FF49764C88A2934C69594A26FF647549F3F16060BD9C8D793D95D0126FA429C94966FE7842967263795A73C498F1DB" }, + { "stateChangeCauseList" : [] }]'
JSON='{ "eidValue" : "'$EID'", "order" : { "euicc" : { "set" : '$STATES' } } }' RC=`./restop.py -c -f euicc -j "$JSON"` diff --git a/include/mnesia_db_euicc.hrl b/include/mnesia_db_euicc.hrl index 78f45f1..6fccaf3 100644 --- a/include/mnesia_db_euicc.hrl +++ b/include/mnesia_db_euicc.hrl @@ -12,5 +12,7 @@ % Pubkey to authenticate eUICC Package Results (see also SGP.32, section 2.11.2.1) signPubKey :: binary(), % Algorithem to authenticate eUICC Package Results (prime256v1 or brainpoolP256r1) - signAlgo :: binary() + signAlgo :: binary(), + % A list with the reported IPAd state change cause codes (has to be polled and reset by REST API user) + stateChangeCauseList :: list() }). diff --git a/src/esipa_asn1_handler.erl b/src/esipa_asn1_handler.erl index e3a6abf..3d0d6b0 100644 --- a/src/esipa_asn1_handler.erl +++ b/src/esipa_asn1_handler.erl @@ -266,13 +266,33 @@ emptyResponse; %GSMA SGP.32, section 6.3.2.6 handle_asn1(Pid, {getEimPackageRequest, EsipaReq}) -> - % TODO: The purpose of the notifyStateChange field in the getEimPackageRequest is to inform the eIM that some state - % in the eUICC has changed and that the eIM (and in particular the REST API user) should perform an update of its - % local records (eUICC data request, listProfileInfo PSMO etc...) This is a feature that this eIM does not support - % yet. To implement the feature we could use a flag in the euicc table to tell the REST API user to perform the - % update. Get the notifyStateChange flag like so: NotifStateChg = maps:is_key(notifyStateChange, EsipaReq). - EidValue = maps:get(eidValue, EsipaReq), + + % Store stateChangeCause, but only in case the EID is already known to this eIM as we do not want to record any + % information from foreigen eUICCs. + case maps:get(notifyStateChange, EsipaReq, none) of + 'NULL' -> + case mnesia_db_euicc:state_get(utils:binary_to_hex(EidValue), stateChangeCauseList) of + {ok, StateChangeCauseList} -> + StateChangeCause = maps:get(stateChangeCause, EsipaReq, undefined), + case lists:member(StateChangeCause, StateChangeCauseList) of + false -> + mnesia_db_euicc:state_set( + utils:binary_to_hex(EidValue), + stateChangeCauseList, + StateChangeCauseList ++ [StateChangeCause] + ); + _ -> + ok + end; + _ -> + ok + end; + _ -> + ok + end, + + % Continue with the processing of the getEimPackageRequest Work = mnesia_db_work:fetch(utils:binary_to_hex(EidValue), Pid), EsipaResp = case Work of diff --git a/src/mnesia_db_euicc.erl b/src/mnesia_db_euicc.erl index 5a5634f..2c18990 100644 --- a/src/mnesia_db_euicc.erl +++ b/src/mnesia_db_euicc.erl @@ -31,7 +31,8 @@ consumerEuicc = ConsumerEuicc, associationToken = 1, signPubKey = <<>>, - signAlgo = <<"prime256v1">> + signAlgo = <<"prime256v1">>, + stateChangeCauseList = [] }, Q = qlc:q([X#euicc.eidValue || X <- mnesia:table(euicc), X#euicc.eidValue == EidValue]), Present = qlc:e(Q), @@ -111,6 +112,8 @@ mnesia:write(Row#euicc{signPubKey = Value}); signAlgo -> mnesia:write(Row#euicc{signAlgo = Value}); + stateChangeCauseList -> + mnesia:write(Row#euicc{stateChangeCauseList = Value}); _ -> throw(badState) end; @@ -136,6 +139,8 @@ Row#euicc.signPubKey; signAlgo -> Row#euicc.signAlgo; + stateChangeCauseList -> + Row#euicc.stateChangeCauseList; _ -> throw(badState) end;