Skip to content

Commit

Permalink
Release 0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Bender committed Apr 10, 2018
2 parents e6c5a80 + 26bd59c commit 292ccf9
Show file tree
Hide file tree
Showing 128 changed files with 9,992 additions and 2,040 deletions.
4 changes: 3 additions & 1 deletion py25/bacpypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Project Metadata
#

__version__ = '0.16.7'
__version__ = '0.17.0'
__author__ = 'Joel Bender'
__email__ = '[email protected]'

Expand Down Expand Up @@ -69,6 +69,8 @@

from . import app
from . import appservice

from . import local
from . import service

#
Expand Down
65 changes: 20 additions & 45 deletions py25/bacpypes/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

"""
Analysis - Decoding pcap files
Before analyzing files, install libpcap-dev:
$ sudo apt install libpcap-dev
then install pypcap:
https://github.com/pynetwork/pypcap
"""

import sys
Expand All @@ -15,7 +23,7 @@
except:
pass

from .debugging import ModuleLogger, DebugContents, bacpypes_debugging
from .debugging import ModuleLogger, bacpypes_debugging, btox

from .pdu import PDU, Address
from .bvll import BVLPDU, bvl_pdu_types, ForwardedNPDU, \
Expand All @@ -33,13 +41,6 @@
socket.IPPROTO_UDP:'udp',
socket.IPPROTO_ICMP:'icmp'}

#
# _hexify
#

def _hexify(s, sep='.'):
return sep.join('%02X' % ord(c) for c in s)

#
# strftimestamp
#
Expand All @@ -53,11 +54,11 @@ def strftimestamp(ts):
#

def decode_ethernet(s):
if _debug: decode_ethernet._debug("decode_ethernet %s...", _hexify(s[:14]))
if _debug: decode_ethernet._debug("decode_ethernet %s...", btox(s[:14]))

d={}
d['destination_address'] = _hexify(s[0:6], ':')
d['source_address'] = _hexify(s[6:12], ':')
d['destination_address'] = btox(s[0:6], ':')
d['source_address'] = btox(s[6:12], ':')
d['type'] = struct.unpack('!H',s[12:14])[0]
d['data'] = s[14:]

Expand All @@ -70,7 +71,7 @@ def decode_ethernet(s):
#

def decode_vlan(s):
if _debug: decode_vlan._debug("decode_vlan %s...", _hexify(s[:4]))
if _debug: decode_vlan._debug("decode_vlan %s...", btox(s[:4]))

d = {}
x = struct.unpack('!H',s[0:2])[0]
Expand All @@ -89,7 +90,7 @@ def decode_vlan(s):
#

def decode_ip(s):
if _debug: decode_ip._debug("decode_ip %r", _hexify(s[:20]))
if _debug: decode_ip._debug("decode_ip %r", btox(s[:20]))

d = {}
d['version'] = (ord(s[0]) & 0xf0) >> 4
Expand Down Expand Up @@ -119,7 +120,7 @@ def decode_ip(s):
#

def decode_udp(s):
if _debug: decode_udp._debug("decode_udp %s...", _hexify(s[:8]))
if _debug: decode_udp._debug("decode_udp %s...", btox(s[:8]))

d = {}
d['source_port'] = struct.unpack('!H',s[0:2])[0]
Expand All @@ -146,6 +147,8 @@ def decode_packet(data):

# assume it is ethernet for now
d = decode_ethernet(data)
pduSource = Address(d['source_address'])
pduDestination = Address(d['destination_address'])
data = d['data']

# there could be a VLAN header
Expand Down Expand Up @@ -176,10 +179,8 @@ def decode_packet(data):
decode_packet._debug(" - pduDestination: %r", pduDestination)
else:
if _debug: decode_packet._debug(" - not a UDP packet")
return None
else:
if _debug: decode_packet._debug(" - not an IP packet")
return None

# check for empty
if not data:
Expand Down Expand Up @@ -225,7 +226,7 @@ def decode_packet(data):

# check for version number
if (pdu.pduData[0] != '\x01'):
if _debug: decode_packet._debug(" - not a version 1 packet: %s...", _hexify(pdu.pduData[:30]))
if _debug: decode_packet._debug(" - not a version 1 packet: %s...", btox(pdu.pduData[:30]))
return None

# it's an NPDU
Expand Down Expand Up @@ -355,41 +356,15 @@ def decode_file(fname):
"""Given the name of a pcap file, open it, decode the contents and yield each packet."""
if _debug: decode_file._debug("decode_file %r", fname)

if not pcap:
raise RuntimeError("failed to import pcap")

# create a pcap object
p = pcap.pcapObject()
p.open_offline(fname)

i = 0
while 1:
# the object acts like an iterator
pkt = p.next()
if not pkt:
break

# returns a tuple
pktlen, data, timestamp = pkt
pkt = decode_packet(data)
if not pkt:
continue

# save the index and timestamp in the packet
pkt._index = i
pkt._timestamp = timestamp

yield pkt

i += 1
raise NotImplementedError("not implemented")

bacpypes_debugging(decode_file)

#
# Tracer
#

class Tracer(DebugContents):
class Tracer:

def __init__(self, initial_state=None):
if _debug: Tracer._debug("__init__ initial_state=%r", initial_state)
Expand Down
12 changes: 10 additions & 2 deletions py25/bacpypes/apdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ def __init__(self, *args, **kwargs):
super(APDU, self).__init__(*args, **kwargs)

def encode(self, pdu):
if _debug: APCI._debug("encode %s", str(pdu))
if _debug: APDU._debug("encode %s", str(pdu))
APCI.encode(self, pdu)
pdu.put_data(self.pduData)

def decode(self, pdu):
if _debug: APCI._debug("decode %s", str(pdu))
if _debug: APDU._debug("decode %s", str(pdu))
APCI.decode(self, pdu)
self.pduData = pdu.get_data(len(pdu.pduData))

Expand Down Expand Up @@ -399,14 +399,20 @@ def dict_contents(self, use_dict=None, as_class=dict):
class _APDU(APDU):

def encode(self, pdu):
if _debug: _APDU._debug("encode %r", pdu)

APCI.update(pdu, self)
pdu.put_data(self.pduData)

def decode(self, pdu):
if _debug: _APDU._debug("decode %r", pdu)

APCI.update(self, pdu)
self.pduData = pdu.get_data(len(pdu.pduData))

def set_context(self, context):
if _debug: _APDU._debug("set_context %r", context)

self.pduUserData = context.pduUserData
self.pduDestination = context.pduSource
self.pduExpectingReply = 0
Expand All @@ -428,6 +434,8 @@ def __repr__(self):
# put it together
return "<%s(%s) instance at %s>" % (sname, stype, hex(id(self)))

bacpypes_debugging(_APDU)

#
# ConfirmedRequestPDU
#
Expand Down
6 changes: 5 additions & 1 deletion py25/bacpypes/basetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ class ObjectTypesSupported(BitString):
, 'positiveIntegerValue':48
, 'timePatternValue':49
, 'timeValue':50
, 'notificationForwarder':51
, 'alertEnrollment':52
, 'channel':53
, 'lightingOutput':54
}
bitLen = 51
bitLen = 55

class ResultFlags(BitString):
bitNames = \
Expand Down
Loading

0 comments on commit 292ccf9

Please sign in to comment.