aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wspython/wspy_dissectors/homeplug.py.sample
blob: 39d5f5349b35b1787ec625cec3fed9d31988ea2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from wspy_dissector import Dissector
from wspy_dissector import FT_UINT8, FT_NONE
from wspy_dissector import BASE_NONE, BASE_HEX

class homeplug_py(Dissector):
  # return the two first parameters of dissector_add as a tuple
  def protocol_ids(self):
    #you could use self.find_dissector() or self.create_dissector_handle() as
    #defined in proto.h and pass the result in the third element of the tuple
    #returned
    return [ ("ethertype", 0x887B, None) ]

  #Main default entry point of dissection
  def dissect(self):
    self.dissect_mctrl()
    self.dissect_mehdr()
    self.dissect_melen()

  def dissect_mctrl(self):
    self.subt = self.subtrees
    self.c_tree = self.tree
    try:
      tree = self.c_tree.add_item(self.hf.homeplug_mctrl, length=1, adv=False)
      mctrl_tree = tree.add_subtree(self.subt.mctrl)

      mctrl_tree.add_item(self.hf.homeplug_mctrl_rsvd, length=1, adv=False)
      mctrl_tree.add_item(self.hf.homeplug_mctrl_ne, length=1)
      #item = self.libhandle.proto_tree_add_text(mctrl_tree.raw_tree, self.raw_tvb, 0, 1, "test") => example using libhandle
    except Exception, e:
      print e

  def dissect_mehdr(self):
    try:
      tree = self.c_tree.add_item(self.hf.homeplug_mehdr, length=1, adv=False)
      mehdr_tree = tree.add_subtree(self.subt.mehdr)

      mehdr_tree.add_item(self.hf.homeplug_mehdr_mev, length=1, adv=False)
      mehdr_tree.add_item(self.hf.homeplug_mehdr_metype, length=1)
    except Exception, e:
      print e

  def dissect_melen(self):
    try:
      self.c_tree.add_item(self.hf.homeplug_melen, length=1)
    except Exception, e:
      print e

  def dissect_mme(self):
    try:
      self.c_tree.add_item(self.hf.homeplug_mme, length=1)
    except Exception, e:
      print e


HOMEPLUG_MCTRL_RSVD   = 0x80
HOMEPLUG_MCTRL_NE     = 0x7F
HOMEPLUG_MEHDR_MEV    = 0xE0
HOMEPLUG_MEHDR_METYPE = 0x1F

def register_protocol():
  tp = homeplug_py("HomePlug protocol (python)", "HomePlug.py", "homeplug_py")

  #
  # Register Protocol Fields
  #
  hf = tp.hf
  # MAC Control Field
  hf.add("Mac Control Field", "homeplug_py.mctrl", FT_NONE, BASE_NONE)
  hf.add("Reserved", "homeplug_py.mctrl.rsvd", FT_UINT8, bitmask=HOMEPLUG_MCTRL_RSVD)
  hf.add("Number of MAC Data Entries", "homeplug_py.mctrl.ne", FT_UINT8, bitmask=HOMEPLUG_MCTRL_NE)

  # MAC Entry Header
  hf.add("MAC Management Entry Header", "homeplug_py.mehdr", FT_NONE, BASE_NONE)
  hf.add("MAC Entry Version", "homeplug_py.mehdr.mev", FT_UINT8, bitmask=HOMEPLUG_MEHDR_MEV)
  hf.add("MAC Entry Type", "homeplug_py.mehdr.metype", FT_UINT8, BASE_HEX, bitmask=HOMEPLUG_MEHDR_METYPE)

  # MAC Entry Len
  hf.add("MAC Management Entry Length", "homeplug_py.melen", FT_UINT8)

  # MAC Management Entry
  hf.add("MAC Management Entry Data", "homeplug_py.mmentry", FT_UINT8)

  #
  # Register Subtrees
  #
  subt = tp.subtrees
  #subt.add("homeplug_py") => we let Dissector output the main tree of this protocol
  subt.add("mctrl")
  subt.add("mehdr")
  return tp