summaryrefslogtreecommitdiffhomepage
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
parentd3fba38214ffc204fb02afdc74657b95c2722bfe (diff)
create shark, rm lmmiHEADmain
-rwxr-xr-xconstants.py2
-rwxr-xr-xmain.py186
-rw-r--r--shark.py56
-rw-r--r--templates/controller.html7
-rw-r--r--templates/lmmi.html43
5 files changed, 108 insertions, 186 deletions
diff --git a/constants.py b/constants.py
index 50fdaaa..12ef380 100755
--- a/constants.py
+++ b/constants.py
@@ -52,7 +52,7 @@ class STATUS:
# Betsy Uses Static IP addressing
BETSY_IP_ADDRESS = "192.168.5.100"
-PC_IP_ADDRESS = "192.168.5.44"
+PC_IP_ADDRESS = "192.168.5.42"
MODE_IDLE = 0
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))
diff --git a/shark.py b/shark.py
new file mode 100644
index 0000000..e1950c0
--- /dev/null
+++ b/shark.py
@@ -0,0 +1,56 @@
+"""
+ shark.py
+"""
+
+import pyshark
+
+from constants import *
+
+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 \ No newline at end of file
diff --git a/templates/controller.html b/templates/controller.html
index cac36e2..88f4806 100644
--- a/templates/controller.html
+++ b/templates/controller.html
@@ -18,6 +18,13 @@
<input type="text" placeholder="token" id="cont_token" name="token">
</p>
+ <p><select class="pi-div-sel">
+ <option value="0x0">FW Version</option>
+ <option value="0x10">FW Increment</option>
+ <option value="0x10">GPIO Direction</option>
+ <option value="0x10">GPIO Value</option>
+ </select>
+
<p>
<input type="text" placeholder="address" id="cont_addr" name="address">
</p>
diff --git a/templates/lmmi.html b/templates/lmmi.html
deleted file mode 100644
index eab3ca4..0000000
--- a/templates/lmmi.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<!-- lmmi.html,
- -- Copyright (C) 2025 Private Island Networks Inc.
--->
-{% extends "base.html" %} {% block content %}
-
-<h2>SGMII_CDR 0 Registers</h2>
-<div class="mc-ss-main-panel">
- <table class="mc-ss-table mc-table-striped">
- <thead>
- <tr>
- <th class="mc-sortable" data-field="address">Address</th>
- <th class="mc-sortable" data-field="register">Register</th>
- <th class="mc-sortable" data-field="default">Default</th>
- <th class="mc-sortable" data-field="value">Value</th>
- <th class="mc-mdio-buttons mc-ss-table-col-buttons"><a
- id="mc-ss-reload-all" class="mc-icon" data-action="reload"
- title="reload"> <img
- src="/static/images/icons-svg/refresh-black.svg" alt="reload"></a></th>
- </tr>
- </thead>
- <tbody>
- {% for key, value in regs0.items() %}
- <tr>
- <td>{{ key }}</td>
- <td>{{regs0[key][0]}}</td>
- <td>{{regs0[key][1]}}</td>
- <td class="mc-values">test</td>
- <td>
- <div class="mc-icons">
- <a class="mc-icon" data-action="edit" title="edit"><img
- src="/static/images/icons-svg/edit-black.svg" alt="edit"></a><a
- class="mc-icon" data-action="admin" title="admin"><img
- src="/static/images/icons-svg/gear-black.svg" alt="admin"></a>
- </div>
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
-</div>
-<br>
-
-{% endblock %}



Join the Betsy Beta