Skip to content

Commit

Permalink
Ignore precompiled python files and add ability to create lorawan pac…
Browse files Browse the repository at this point in the history
…kets
  • Loading branch information
jeroennijhof committed Jun 21, 2016
1 parent 16c906d commit f7cbf5a
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
Binary file removed AES_CMAC.pyc
Binary file not shown.
Binary file removed DataPayload.pyc
Binary file not shown.
Binary file removed Direction.pyc
Binary file not shown.
Binary file removed FHDR.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions JoinAcceptPayload.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def get_rxdelay(self):
def get_cflist(self):
return self.cflist

def compute_mic(self, key, mhdr):
def compute_mic(self, key, direction, mhdr):
mic = []
mic += self.to_clear_raw()
mic += [mhdr]

cmac = AES_CMAC()
return cmac.encode(str(bytearray(key)), str(bytearray(mic)))[:4]

def decrypt_payload(self, key):
def decrypt_payload(self, key, direction):
a = []
a += self.encrypted_payload
a += self.mic
Expand Down
Binary file removed JoinAcceptPayload.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion JoinRequestPayload.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ def get_deveui(self):
def get_devnonce(self):
return self.devnonce

def compute_mic(self, key, mhdr):
def compute_mic(self, key, direction, mhdr):
mic = [mhdr]
mic += self.to_raw()

cmac = AES_CMAC()
return cmac.encode(str(bytearray(key)), str(bytearray(mic)))[:4]

def decrypt_payload(self, key, direction):
return self.to_raw()
Binary file removed JoinRequestPayload.pyc
Binary file not shown.
Binary file removed MType.pyc
Binary file not shown.
4 changes: 1 addition & 3 deletions MacPayload.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def __init__(self, mtype, mac_payload):
self.frm_payload = DataPayload(self, mac_payload[self.fhdr.length() + 1:])

def length(self):
if self.frm_payload == None:
return self.fhdr.length()
return self.fhdr.length() + 1 + self.frm_payload.length()
return len(self.to_raw())

def to_raw(self):
mac_payload = []
Expand Down
Binary file removed MacPayload.pyc
Binary file not shown.
Binary file removed MajorVersion.pyc
Binary file not shown.
Binary file removed MalformedPacketException.pyc
Binary file not shown.
29 changes: 14 additions & 15 deletions PhyPayload.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@

class PhyPayload:

def __init__(self, packet):
def __init__(self):
self.direction = Direction(Direction.UP)

def length(self):
return len(self.to_raw())

def to_raw(self):
phy_payload = [self.mhdr]
phy_payload += self.mac_payload.to_raw()
phy_payload += self.mic
return phy_payload

def packet(self, packet):
if len(packet) < 12:
raise MalformedPacketException("Invalid lorawan packet");

self.direction = Direction(Direction.UP)
self.mhdr = packet[0]
self.mversion = MajorVersion(self.mhdr)
self.mtype = MType(self.mhdr)
Expand Down Expand Up @@ -51,20 +62,8 @@ def get_mic(self):
def set_mic(self, mic):
self.mic = mic

def to_raw(self):
phy_payload = [self.mhdr]
phy_payload += self.mac_payload.to_raw()
phy_payload += self.mic
return phy_payload

def compute_mic(self, key):
return self.mac_payload.frm_payload.compute_mic(key, self.get_direction(), self.get_mhdr())

def decrypt_payload(self, key):
def get_payload(self, key):
return self.mac_payload.frm_payload.decrypt_payload(key, self.get_direction())

def encrypt_payload(self, key, data):
return self.mac_payload.frm_payload.encrypt_payload(key, self.get_direction(), data)

def set_payload(self, key, data):
return self.mac_payload.frm_payload.set_payload(key, self.get_direction(), data)
Binary file removed PhyPayload.pyc
Binary file not shown.
7 changes: 5 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from PhyPayload import PhyPayload

def new(packet):
return PhyPayload(packet)
def new(packet = None):
phy_payload = PhyPayload()
if packet:
phy_payload.packet(packet)
return phy_payload
Binary file removed __init__.pyc
Binary file not shown.

0 comments on commit f7cbf5a

Please sign in to comment.