fix(gw): jt808 REG_ACK failed due to faulty clientinfo

This commit is contained in:
JimMoen 2024-05-10 17:12:28 +08:00
parent 8c0b55a89e
commit b07242515f
No known key found for this signature in database
1 changed files with 32 additions and 13 deletions

View File

@ -241,19 +241,24 @@ do_handle_in(Frame = ?MSG(?MC_GENERAL_RESPONSE), Channel = #channel{inflight = I
{ok, Channel#channel{inflight = NewInflight}}; {ok, Channel#channel{inflight = NewInflight}};
do_handle_in(Frame = ?MSG(?MC_REGISTER), Channel0) -> do_handle_in(Frame = ?MSG(?MC_REGISTER), Channel0) ->
#{<<"header">> := #{<<"msg_sn">> := MsgSn}} = Frame, #{<<"header">> := #{<<"msg_sn">> := MsgSn}} = Frame,
case emqx_jt808_auth:register(Frame, Channel0#channel.auth) of case
{ok, Authcode} -> emqx_utils:pipeline(
{ok, Conninfo} = enrich_conninfo(Frame, Channel0#channel{authcode = Authcode}), [
{ok, Channel} = enrich_clientinfo(Frame, Conninfo), fun enrich_clientinfo/2,
handle_out({?MS_REGISTER_ACK, 0}, MsgSn, Channel); fun enrich_conninfo/2,
{error, Reason} -> fun set_log_meta/2
?SLOG(error, #{msg => "register_failed", reason => Reason}), ],
ResCode = Frame,
case is_integer(Reason) of Channel0
true -> Reason; )
false -> 1 of
end, {ok, _NFrame, Channel} ->
handle_out({?MS_REGISTER_ACK, ResCode}, MsgSn, Channel0) case register_(Frame, Channel) of
{ok, NChannel} ->
handle_out({?MS_REGISTER_ACK, 0}, MsgSn, NChannel);
{error, ResCode} ->
handle_out({?MS_REGISTER_ACK, ResCode}, MsgSn, Channel)
end
end; end;
do_handle_in(Frame = ?MSG(?MC_AUTH), Channel0) -> do_handle_in(Frame = ?MSG(?MC_AUTH), Channel0) ->
#{<<"header">> := #{<<"msg_sn">> := MsgSn}} = Frame, #{<<"header">> := #{<<"msg_sn">> := MsgSn}} = Frame,
@ -859,6 +864,20 @@ is_driver_id_req_exist(#channel{inflight = Inflight}) ->
Key = get_msg_ack(?MC_DRIVER_ID_REPORT, none), Key = get_msg_ack(?MC_DRIVER_ID_REPORT, none),
emqx_inflight:contain(Key, Inflight). emqx_inflight:contain(Key, Inflight).
register_(Frame, Channel0) ->
case emqx_jt808_auth:register(Frame, Channel0#channel.auth) of
{ok, Authcode} ->
{ok, Channel0#channel{authcode = Authcode}};
{error, Reason} ->
?SLOG(error, #{msg => "register_failed", reason => Reason}),
ResCode =
case is_integer(Reason) of
true -> Reason;
false -> 1
end,
{error, ResCode}
end.
authenticate(_AuthFrame, #channel{authcode = anonymous}) -> authenticate(_AuthFrame, #channel{authcode = anonymous}) ->
true; true;
authenticate(AuthFrame, #channel{authcode = undefined, auth = Auth}) -> authenticate(AuthFrame, #channel{authcode = undefined, auth = Auth}) ->