module LLCSNAP where import Data.Bits import Data.Word import Net.PacketParsing -- 802.2 LLC Header : SNAP extension -- -------------------------------------------------------------------------- -- DSAP : SSAP : Control : OUI : Protocol ID -- 1 octet : 1 octet : 1 or 2 octets : 3 octets : 2 octets data LLCSNAP = LLCSNAP { dsap :: Word8 , ssap :: Word8 , control :: Word16 -- 1 or 2 bytes , oui :: Word32 -- 3 bytes , protoid :: Word16 } deriving (Eq,Ord,Read,Show) instance Parse LLCSNAP where parse = do -- LLC dsap <- word8 ssap <- word8 control <- fromIntegral <$> word8 -- Based on "Understanding Logical Link Control" at -- https://www.cisco.com/c/en/us/support/docs/ibm-technologies/logical-link-control-llc/12247-45.html -- -- Unless the low two bits are set, there's -- another byte of the control field. nr <- if 0x0003 == control .&. 0x0003 then return 0 else fromIntegral <$> word8 -- SNAP ouilo <- fromIntegral <$> word16 ouihi <- fromIntegral <$> word8 protoid <- word16 return LLCSNAP { dsap = dsap , ssap = ssap , control = control + 256 * nr , oui = ouilo + 65536 * ouihi , protoid = protoid }