summaryrefslogtreecommitdiffhomepage
path: root/main.py
diff options
context:
space:
mode:
authorPrivate Island Networks <opensource@privateisland.tech>2026-08-29 21:23:14 -0400
committerPrivate Island Networks <opensource@privateisland.tech>2026-08-29 21:23:14 -0400
commit62cdafb5b5f61a3f4f10b8f578b8386463474343 (patch)
tree7717a9d4630003ee57989b0173fd832e4dd2ceb7 /main.py
parentd3fba38214ffc204fb02afdc74657b95c2722bfe (diff)
create shark, rm lmmiHEADmain
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py186
1 files changed, 44 insertions, 142 deletions
diff --git a/main.py b/main.py
index f29cfca..7cde637 100755
--- a/main.py
+++ b/main.py
@@ -23,17 +23,16 @@ import logging
import aiohttp
import asyncio
import asyncio_dgram
-import pyshark
import aiohttp_jinja2
import jinja2
from multiprocessing import Process, Manager
from aiohttp import web
from queue import Empty
-import platform
from socket import socket, AF_INET, SOCK_DGRAM
from time import sleep
import json
+from shark import _run_shark
from constants import *
DEBUG = True
@@ -45,6 +44,25 @@ LOG_PATH = PROJECT_ROOT + '/logs'
ws_key = web.AppKey("ws_key", dict[str, web.WebSocketResponse])
+async def _send_msg(app, msg_type, token, address, data):
+ try:
+ sko=socket(AF_INET,SOCK_DGRAM)
+ sko.bind((app['ipaddr_pc'],0x3000))
+ msg = msg_type + token + address + data
+ sko.sendto(msg,("192.168.5.100",0x9020))
+ except:
+ print("Controller Command failed in Exception: {0}", sys.exc_info())
+ pass
+
+ sko.close()
+
+async def _udp_rcv():
+ """ controller response """
+ stream = await asyncio_dgram.bind(("192.168.5.40", 0x8000))
+ data, remote_addr = await stream.recv()
+ return data
+ stream.close()
+
async def _parse_ctl_pkt(app, pkt):
""" Parse a Wireshark received packet"""
@@ -128,54 +146,14 @@ async def _parse_mle_pkt(app, pkt):
return message
-async def home(request):
+async def index(request):
data = request.match_info.get('data', "")
ctx = _default_context('main')
ctx.update(locals())
response = aiohttp_jinja2.render_template('index.html', request, ctx)
response.headers['Content-Language'] = 'en-US'
return response
-
-async def mdio(request):
- if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
- q_cont = request.app['q_cont']
- values = dict()
- _query_mdio(request.app)
- for i in range(16):
- pkt = q_cont.get(block=True) # Query
- pkt = q_cont.get(block=True) # Response
- msg = pkt.data.data.__str__()
- values[i] = int("0x" + msg[10:],16)
-
- d = json.dumps({'values': values})
- response = web.Response(text=d, status=200)
- else:
- ctx = _default_context('mdio')
- ctx['ss'] = True
- ctx['regs'] = DP83867_MAP
- response = aiohttp_jinja2.render_template('mdio.html', request, ctx)
- response.headers['Content-Language'] = 'en-US'
- return response
-async def _send_msg(app, msg_type, token, address, data):
- try:
- sko=socket(AF_INET,SOCK_DGRAM)
- sko.bind((app['ipaddr_pc'],0x3000))
- msg = msg_type + token + address + data
- sko.sendto(msg,("192.168.5.100",0x9020))
- except:
- print("Controller Command failed in Exception: {0}", sys.exc_info())
- pass
-
- sko.close()
-
-async def _udp_rcv():
- """ controller response """
- stream = await asyncio_dgram.bind(("192.168.5.40", 0x8000))
- data, remote_addr = await stream.recv()
- return data
- stream.close()
-
async def controller(request):
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
try:
@@ -205,7 +183,6 @@ async def controller(request):
return response
-
async def mle(request):
data = request.match_info.get('data', "")
ctx = _default_context('main')
@@ -215,6 +192,26 @@ async def mle(request):
response.headers['Content-Language'] = 'en-US'
return response
+async def mdio(request):
+ if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
+ q_cont = request.app['q_cont']
+ values = dict()
+ _query_mdio(request.app)
+ for i in range(16):
+ pkt = q_cont.get(block=True) # Query
+ pkt = q_cont.get(block=True) # Response
+ msg = pkt.data.data.__str__()
+ values[i] = int("0x" + msg[10:],16)
+
+ d = json.dumps({'values': values})
+ response = web.Response(text=d, status=200)
+ else:
+ ctx = _default_context('mdio')
+ ctx['ss'] = True
+ ctx['regs'] = DP83867_MAP
+ response = aiohttp_jinja2.render_template('mdio.html', request, ctx)
+ response.headers['Content-Language'] = 'en-US'
+ return response
async def fabric(request):
data = request.match_info.get('data', "")
@@ -232,29 +229,6 @@ async def support(request):
response.headers['Content-Language'] = 'en-US'
return response
-async def lmmi(request):
- q_cont = request.app['q_cont']
- data = request.match_info.get('data', "")
- if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
- values = dict()
- _query_lmmi(app)
- for i in range(28):
- pkt = q_cont.get(block=True)
- msg = pkt.data.data.__str__()
- if len(msg) == 6 and (msg == '03e0fe' or msg == '03e0ff'):
- continue
- values[round((i-1)/2)] = int("0x" + msg[12:],16)
-
- d = json.dumps({'values': values})
- resp = web.Response(text=d, status=200)
- return resp
- else:
- context = {'data': data, 'regs0': SGMII_CDR_MAP, 'regs1': SGMII_CDR_MAP}
- response = aiohttp_jinja2.render_template('lmmi.html', request, context)
- response.headers['Content-Language'] = 'en-US'
- return response
-
-
async def set_filename(request):
if not request.can_read_body:
raise web.HTTPBadRequest()
@@ -324,29 +298,6 @@ async def wslogger(request):
elif msg.type == web.WSMsgType.CLOSE:
break
-
-def _query_lmmi(app):
- """ Lattice Memory Mapped Interface """
- try:
- sko = socket(AF_INET, SOCK_DGRAM)
- sko.bind((app['ipaddr_pc'], 0x3000))
-
- # Query the LMMI Registers
- for i in range(16):
- msg = MSG_TYPE_READ + b'\x06' + i.to_bytes(1) + b'\x00\x00'
- sko.sendto(msg, (BETSY_IP_ADDRESS, 0x9020))
- sleep(0.01)
-
- except:
- print("Controller Command failed in Exception: {0}", sys.exc_info())
- pass
- finally:
- sko.close()
-
- if DEBUG:
- print("query_lmmi finished")
-
-
def _query_mdio(app):
try:
@@ -379,54 +330,7 @@ def _default_context(app_layer):
"app_layer" : app_layer
}
-def _run_shark(q_cont, q_mle, ife, df, mode, ns, time):
-
- num_pkts = 0
- ts = time[0]
- tf = time[1]
-
- cap_live = pyshark.LiveCapture(interface=ife, display_filter=df)
-
- while True:
-
- if mode.value == MODE_IDLE:
- continue
-
- # mode is a global set during initialization by the browser
- elif mode.value == MODE_LIVE:
- cap_live.reset()
- for pkt in cap_live.sniff_continuously():
- num_pkts = num_pkts + 1
- try:
- msg_type = int(pkt.data.data[0:2],16)
- if msg_type < MSG_TYPE_NOTIFY_MLE:
- q_cont.put(pkt)
- print ('put in Cont Q: ', num_pkts)
- elif msg_type == MSG_TYPE_NOTIFY_MLE:
- q_mle.put(pkt)
- print ('put in MLE Q: ', num_pkts)
- except Exception as e:
- print(str(e))
- pass
-
- if mode.value == MODE_IDLE:
- break
-
-
- elif mode.value == MODE_FILE:
- cap_file = pyshark.FileCapture(input_file=LOG_PATH + ns.filename, display_filter=df)
- for pkt in cap_file:
- num_pkts = num_pkts + 1
- time = float(pkt.frame_info.get_field("frame.time_relative").__str__()[0:9])
- if time >= ts and time < tf:
- q_cont.put(pkt)
- if DEBUG:
- print ('put in Q: ', num_pkts)
- if DEBUG:
- print("file replay finished")
-
- cap_file.close()
- mode.value = MODE_IDLE
+
async def make_app(args, manager):
@@ -467,14 +371,13 @@ async def make_app(args, manager):
app.on_shutdown.append(_shutdown)
app.add_routes([
- web.get('/', home),
- web.get('/mdio' , mdio),
+ web.get('/', index),
web.get('/controller', controller),
web.post('/controller',controller),
web.get('/mle', mle),
+ web.get('/mdio' , mdio),
web.get('/fabric', fabric),
web.get('/help', support),
- web.get('/lmmi', lmmi), # Lattice Memory Mapped Interface
web.post('/start', start),
web.post('/stop', stop),
web.post('/filename', set_filename),
@@ -485,7 +388,6 @@ async def make_app(args, manager):
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(TEMPLATE_PATH))
return app
-
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Private Island Explorer', epilog='Version: ' + str(VERSION))



Join the Betsy Beta