Skip to content

Commit

Permalink
Fix FCS on frames without lengths
Browse files Browse the repository at this point in the history
Pull out the checksum from ambiguous frames before parsing them again.
  • Loading branch information
msantos committed Sep 3, 2011
1 parent e157342 commit 29e6d77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -195,7 +195,8 @@ CAP\_NET\_ADMIN privileges:

Attempt to write a frame to the wireless device.

wierl_monitor:frame(Socket, Frame) -> {Radiotap, FrameControl, FrameBody}
wierl_monitor:frame(Socket, Frame) ->
{Radiotap, FrameControl, FrameBody, FrameCheckSequence}
wierl_monitor:frame(Socket, {FrameControl, FrameBody}) -> Frame

Types Socket = pid()
Expand All @@ -211,6 +212,7 @@ CAP\_NET\_ADMIN privileges:
| #ieee802_11_cf_bar{},
| #ieee802_11_cf_ba{},
| #ieee802_11_data{}
FrameCheckSequence = integer()

Encode or decode an 802.11 wireless frame between binaries and
records. Include the wierl_frame header to have access to the
Expand Down
10 changes: 6 additions & 4 deletions src/wierl_monitor.erl
Expand Up @@ -121,7 +121,7 @@ frame(Ref, Frame) when is_binary(Frame) ->
{FB, 0};
<<N:4/unsigned-integer-unit:8>> ->
% Driver provides FCS
% XXX flag is set in state on EVERY frame
% XXX flag is set in state on EVERY frame
ok = gen_server:call(Ref, {fcs, true}),
{FB, N};
false ->
Expand All @@ -131,9 +131,11 @@ frame(Ref, Frame) when is_binary(Frame) ->

case Include of
true ->
Len = byte_size(FB) - 4,
<<F1:Len/bytes, F2:4/unsigned-integer-unit:8>> = FB,
{F1, F2};
% Remove 4 bytes from the frame body and re-parse the frame
Len = byte_size(Data2) - 4,
<<Body:Len/bytes, RealFCS:4/unsigned-integer-unit:8>> = Data2,
{FrameBody, _} = wierl_frame:type(FC, Body),
{FrameBody, RealFCS};
false ->
{FB, 0}
end
Expand Down

0 comments on commit 29e6d77

Please sign in to comment.