anchor.diff:  
   -include_lib("lorawan_server_api/include/lorawan_application.hrl").
   -include("lorawan.hrl").
  +
  +-record(frame, {devaddr, adr, adr_ack_req, ack, fcnt, fopts, fport, data}).
   
   process_frame(MAC, RxQ, PHYPayload) ->
       Size = byte_size(PHYPayload)-4,
  
positive.code:         {error, Error} -> {error, Error}
      end.
  
  check_lost(0, DevAddr) ->
      case mnesia:dirty_read(pending, DevAddr) of
          [] -> {false, undefined};
          [Msg] -> {true, Msg#pending.phypayload}
      end;
  check_lost(1, DevAddr) ->
      ok = mnesia:dirty_delete(pending, DevAddr),
      {false, undefined}.
  
  inc_fcntdown(DevAddr) ->
      mnesia:transaction(fun() ->
  
negative.code:     <<DevAddr0:4/binary, ADR:1, ADRACKReq:1, ACK:1, _RFU:1, FOptsLen:4,
          FCnt:16/little-unsigned-integer, FOpts:FOptsLen/binary, FPort:8, FRMPayload/binary>> = MACPayload,
      DevAddr = reverse(DevAddr0),
      Frame = #frame{devaddr=DevAddr, adr=ADR, adr_ack_req=ADRACKReq, ack=ACK, fcnt=FCnt, fport=FPort},
      case check_link(DevAddr, FCnt) of
          {ok, Fresh, L} ->
              case aes_cmac:aes_cmac(L#link.nwkskey, <<(b0(MType band 1, DevAddr, L#link.fcntup, byte_size(Msg)))/binary, Msg/binary>>, 4) of
                  MIC ->
                      case FPort of
                          0 when FOptsLen == 0 ->
                              Data = cipher(FRMPayload, L#link.nwkskey, MType band 1, DevAddr, L#link.fcntup),
                              handle_rxpk(Gateway, RxQ, MType, store_adr(L, ADR), Fresh,
                                  Frame#frame{fopts=reverse(Data), data= <<>>});
                          0 ->
                              {error, double_fopts};
                          _N ->
                              Data = cipher(FRMPayload, L#link.appskey, MType band 1, DevAddr, L#link.fcntup),
                              handle_rxpk(Gateway, RxQ, MType, store_adr(L, ADR), Fresh,
                                  Frame#frame{fopts=FOpts, data=reverse(Data)})
                      end;
                  _MIC2 ->
                      {error, bad_mic}
              end;
  