diff options
Diffstat (limited to 'LLCSNAP.hs')
-rw-r--r-- | LLCSNAP.hs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/LLCSNAP.hs b/LLCSNAP.hs new file mode 100644 index 00000000..417c36ba --- /dev/null +++ b/LLCSNAP.hs | |||
@@ -0,0 +1,49 @@ | |||
1 | module LLCSNAP where | ||
2 | |||
3 | import Data.Bits | ||
4 | import Data.Word | ||
5 | |||
6 | import Net.PacketParsing | ||
7 | |||
8 | |||
9 | -- 802.2 LLC Header : SNAP extension | ||
10 | -- -------------------------------------------------------------------------- | ||
11 | -- DSAP : SSAP : Control : OUI : Protocol ID | ||
12 | -- 1 octet : 1 octet : 1 or 2 octets : 3 octets : 2 octets | ||
13 | |||
14 | data LLCSNAP = LLCSNAP | ||
15 | { dsap :: Word8 | ||
16 | , ssap :: Word8 | ||
17 | , control :: Word16 -- 1 or 2 bytes | ||
18 | , oui :: Word32 -- 3 bytes | ||
19 | , protoid :: Word16 | ||
20 | } | ||
21 | deriving (Eq,Ord,Read,Show) | ||
22 | |||
23 | instance Parse LLCSNAP where | ||
24 | parse = do | ||
25 | -- LLC | ||
26 | dsap <- word8 | ||
27 | ssap <- word8 | ||
28 | control <- fromIntegral <$> word8 | ||
29 | -- Based on "Understanding Logical Link Control" at | ||
30 | -- https://www.cisco.com/c/en/us/support/docs/ibm-technologies/logical-link-control-llc/12247-45.html | ||
31 | -- | ||
32 | -- Unless the low two bits are set, there's | ||
33 | -- another byte of the control field. | ||
34 | nr <- if 0x0003 == control .&. 0x0003 | ||
35 | then return 0 | ||
36 | else fromIntegral <$> word8 | ||
37 | -- SNAP | ||
38 | ouilo <- fromIntegral <$> word16 | ||
39 | ouihi <- fromIntegral <$> word8 | ||
40 | protoid <- word16 | ||
41 | return LLCSNAP | ||
42 | { dsap = dsap | ||
43 | , ssap = ssap | ||
44 | , control = control + 256 * nr | ||
45 | , oui = ouilo + 65536 * ouihi | ||
46 | , protoid = protoid | ||
47 | } | ||
48 | |||
49 | |||