Skip to content

Commit

Permalink
write raw-map to file with ppi
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiw committed Jun 5, 2024
1 parent dffc2b3 commit c53dda4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/otc_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,19 @@ gsm_packed_test() ->
?assertEqual(binary:decode_hex(<<"E779FB56768F01">>), encode_gsm_packed("gsm7enc")),
?assertEqual(<<79,234,16>>, encode_gsm_packed("OTC")).

write_to_pcap(Filename, Bin) ->
%% {[LowestLayer|_], _} = Map,
%% PPI = otc_sctp_ppid:codec(maps:get(protocol, LowestLayer)),

write_to_pcap(Filename, {[LowestLayer|_], _} = Tuple) ->
{ok, Bin} = otc:encode(Tuple),
PPI = otc_sctp_ppi:codec(maps:get(protocol, LowestLayer)),
write_to_pcap(Filename, PPI, Bin);
write_to_pcap(Filename, [LowestLayer|_] = List) ->
{ok, Bin} = otc:encode(List),
PPI = otc_sctp_ppi:codec(maps:get(protocol, LowestLayer)),
write_to_pcap(Filename, PPI, Bin).

write_to_pcap(Filename, PPI, Bin) ->
DataChunk = <<16#28024345:32, %% TSN
0:16, 0:16, %% Stream identifier, sequence number
3:32, %% PPI
PPI:32, %% PPI
Bin/binary>>,
ChunkLen = byte_size(DataChunk) + 4, %% Chunk in bytes including the Type, Flags, Length, and Value.
ChunkLenRest = case ChunkLen rem 4 of
Expand Down

0 comments on commit c53dda4

Please sign in to comment.