Skip to content

Commit

Permalink
Merge pull request #83 from xmm7360/split_dbus_library
Browse files Browse the repository at this point in the history
Split dbus functionality into library file
  • Loading branch information
tgxn authored Apr 6, 2021
2 parents f181398 + 0739771 commit 1eb2ee4
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 173 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
33 changes: 33 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lint

on:
push:
paths:
- "**.py"

pull_request:
paths:
- "**.py"

jobs:
flake8_py3:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8.5
architecture: x64

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Install flake8
run: pip install flake8

- name: Run flake8
uses: suo/flake8-github-action@releases/v1
with:
checkName: "flake8_py3" # NOTE: this needs to be the same as the job name
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
branches: [master]

pull_request:
branches: [master]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: compile kernel module
run: make

# Runs a single command using the runners shell
- name: test python module
run: python3 rpc/test_rpc.py
29 changes: 0 additions & 29 deletions .github/workflows/main.yml

This file was deleted.

20 changes: 10 additions & 10 deletions rpc/mux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import os
import binascii
import time
import struct
import itertools
import pytap2
import selectors


class MuxPacket(object):
def __init__(self, seq=0):
self.seq = seq
Expand All @@ -16,7 +15,8 @@ def __init__(self, seq=0):

def get_packet(self):
# put the final length in
self.packet = self.packet[:8] + struct.pack('<L', len(self.packet)) + self.packet[8+4:]
self.packet = self.packet[:8] + \
struct.pack('<L', len(self.packet)) + self.packet[8 + 4:]
return self.packet

def append_tag(self, tag, data=b'', extra=0):
Expand All @@ -27,15 +27,17 @@ def append_tag(self, tag, data=b'', extra=0):
else:
while len(self.packet) & 3:
self.packet += b'\0'
self.packet = self.packet[:self.fwd_pointer] + struct.pack('<L', len(self.packet)) + self.packet[self.fwd_pointer+4:]
self.packet = self.packet[:self.fwd_pointer] + struct.pack(
'<L', len(self.packet)) + self.packet[self.fwd_pointer + 4:]

hdr_len = len(hdr) + 8
hdr += struct.pack('<HHL', hdr_len+len(data), extra, 0)
hdr += struct.pack('<HHL', hdr_len + len(data), extra, 0)
# that last field is the next-tag pointer
self.fwd_pointer = len(self.packet) + len(hdr) - 4

self.packet += hdr + data


class XMMMux(object):
def package(self, packet_data):
self.seq = (self.seq + 1) & 0xff
Expand All @@ -52,11 +54,10 @@ def __init__(self, path='/dev/xmm0/mux'):

self.seq = 0

raw = binascii.unhexlify('6000000000383AFFFE800000000000000000000000000001FE80000000000000D438C1FD077C00C38600248840005550000000000000000005010000000005DC03044040FFFFFFFFFFFFFFFF0000000020018004142021F50000000000000000')
pak = self.package(raw)
pkd = binascii.unhexlify('414442480000010088000000700000006000000000383AFFFE800000000000000000000000000001FE80000000000000D438C1FD077C00C38600248840005550000000000000000005010000000005DC03044040FFFFFFFFFFFFFFFF0000000020018004142021F50000000000000000414454481800000000000000000000001000000060000000')
p = MuxPacket(seq=1)
p.append_tag(b'ADBH', binascii.unhexlify('6000000000383AFFFE800000000000000000000000000001FE80000000000000D438C1FD077C00C38600248840005550000000000000000005010000000005DC03044040FFFFFFFFFFFFFFFF0000000020018004142021F50000000000000000'))
p.append_tag(b'ADBH', binascii.unhexlify(
'6000000000383AFFFE800000000000000000000000000001FE80000000000000D438C1FD077C00C38600248840005550000000000000000005010000000005DC03044040FFFFFFFFFFFFFFFF0000000020018004142021F50000000000000000'))
p.append_tag(b'ADTH', struct.pack('<LLL', 0, 0x10, 0x60))

print(binascii.hexlify(p.get_packet()))
Expand All @@ -76,7 +77,6 @@ def __init__(self, path='/dev/xmm0/mux'):
p.append_tag(b'CMDH', struct.pack('<LLLL', 1, 0, 0, 0))
os.write(self.fp, p.get_packet())


while True:
events = sel.select()
for key, mask in events:
Expand All @@ -99,7 +99,7 @@ def read_mux(self):
tail = tail[16:]
while len(tail) >= 8:
offset, length = struct.unpack('<LL', tail[:8])
puk = data[offset:offset+length]
puk = data[offset:offset + length]
# print('ai>', binascii.hexlify(puk))
self.tun.write(puk)
tail = tail[8:]
Expand Down
Loading

0 comments on commit 1eb2ee4

Please sign in to comment.