Skip to content

Commit

Permalink
Handle all ICCID changes and not just the first one
Browse files Browse the repository at this point in the history
This ensures that if the ICCID being reported is different from the one
that was previously reported (or the default), that it runs through the
try to connect logic. This means that if there are any hiccups that
cause a nil or corrupt ICCID to flow through, that it's not stuck forever.
  • Loading branch information
fhunleth committed Aug 6, 2024
1 parent b65d684 commit 27f47a9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/vintage_net_qmi/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ defmodule VintageNetQMI.Connection do

@impl GenServer
def handle_info(
{VintageNet, ["interface", ifname, "mobile", "iccid"], nil, iccid, _meta},
%{ifname: ifname} = state
) do
new_state = %{state | iccid: iccid}
{VintageNet, ["interface", ifname, "mobile", "iccid"], _, new_iccid, _meta},
%{ifname: ifname, iccid: old_iccid} = state
)
when new_iccid != old_iccid do
new_state = %{state | iccid: new_iccid}

{:noreply, try_to_connect(new_state)}
end
Expand All @@ -137,6 +138,10 @@ defmodule VintageNetQMI.Connection do
{:noreply, try_to_connect(state)}
end

def handle_info(_message, state) do
{:noreply, state}
end

defp try_to_connect(state) do
three_3gpp_profile_index = 1
iccid = state.iccid
Expand All @@ -161,6 +166,13 @@ defmodule VintageNetQMI.Connection do

state

{:error, :invalid_iccid} ->
Logger.warning(
"[VintageNetQMI] ICCID, #{inspect(iccid)}, is invalid. Waiting for a valid one."
)

state

{:error, :no_effect} ->
# no effect means that a network connection as already be established
# so we don't need to try to connect again.
Expand All @@ -176,7 +188,7 @@ defmodule VintageNetQMI.Connection do
end

defp validate_iccid(iccid) when is_binary(iccid), do: :ok
defp validate_iccid(_iccid), do: {:error, :missing_iccid}
defp validate_iccid(_iccid), do: {:error, :invalid_iccid}

defp set_roaming_allowed_for_provider(
%{roaming_allowed?: roaming_allowed?},
Expand Down

0 comments on commit 27f47a9

Please sign in to comment.