mirror of
https://github.com/google/bumble.git
synced 2026-05-09 04:08:02 +00:00
Migrate L2CAP packets to dataclasses
This commit is contained in:
@@ -34,9 +34,8 @@ from bumble.att import ATT_CID, ATT_PDU
|
|||||||
from bumble.smp import SMP_CID, SMP_Command
|
from bumble.smp import SMP_CID, SMP_Command
|
||||||
from bumble.core import name_or_number
|
from bumble.core import name_or_number
|
||||||
from bumble.l2cap import (
|
from bumble.l2cap import (
|
||||||
|
CommandCode,
|
||||||
L2CAP_PDU,
|
L2CAP_PDU,
|
||||||
L2CAP_CONNECTION_REQUEST,
|
|
||||||
L2CAP_CONNECTION_RESPONSE,
|
|
||||||
L2CAP_SIGNALING_CID,
|
L2CAP_SIGNALING_CID,
|
||||||
L2CAP_LE_SIGNALING_CID,
|
L2CAP_LE_SIGNALING_CID,
|
||||||
L2CAP_Control_Frame,
|
L2CAP_Control_Frame,
|
||||||
@@ -106,14 +105,14 @@ class PacketTracer:
|
|||||||
self.analyzer.emit(control_frame)
|
self.analyzer.emit(control_frame)
|
||||||
|
|
||||||
# Check if this signals a new channel
|
# Check if this signals a new channel
|
||||||
if control_frame.code == L2CAP_CONNECTION_REQUEST:
|
if control_frame.code == CommandCode.L2CAP_CONNECTION_REQUEST:
|
||||||
connection_request = cast(L2CAP_Connection_Request, control_frame)
|
connection_request = cast(L2CAP_Connection_Request, control_frame)
|
||||||
self.psms[connection_request.source_cid] = connection_request.psm
|
self.psms[connection_request.source_cid] = connection_request.psm
|
||||||
elif control_frame.code == L2CAP_CONNECTION_RESPONSE:
|
elif control_frame.code == CommandCode.L2CAP_CONNECTION_RESPONSE:
|
||||||
connection_response = cast(L2CAP_Connection_Response, control_frame)
|
connection_response = cast(L2CAP_Connection_Response, control_frame)
|
||||||
if (
|
if (
|
||||||
connection_response.result
|
connection_response.result
|
||||||
== L2CAP_Connection_Response.CONNECTION_SUCCESSFUL
|
== L2CAP_Connection_Response.Result.CONNECTION_SUCCESSFUL
|
||||||
):
|
):
|
||||||
if self.peer and (
|
if self.peer and (
|
||||||
psm := self.peer.psms.get(connection_response.source_cid)
|
psm := self.peer.psms.get(connection_response.source_cid)
|
||||||
|
|||||||
671
bumble/l2cap.py
671
bumble/l2cap.py
File diff suppressed because it is too large
Load Diff
@@ -68,11 +68,13 @@ def test_helpers():
|
|||||||
assert offset == 4
|
assert offset == 4
|
||||||
assert psm == 0x242311
|
assert psm == 0x242311
|
||||||
|
|
||||||
rq = L2CAP_Connection_Request(psm=0x01, source_cid=0x44)
|
rq = L2CAP_Connection_Request(psm=0x01, source_cid=0x44, identifier=0x88)
|
||||||
brq = bytes(rq)
|
brq = bytes(rq)
|
||||||
srq = L2CAP_Connection_Request.from_bytes(brq)
|
srq = L2CAP_Connection_Request.from_bytes(brq)
|
||||||
|
assert isinstance(srq, L2CAP_Connection_Request)
|
||||||
assert srq.psm == rq.psm
|
assert srq.psm == rq.psm
|
||||||
assert srq.source_cid == rq.source_cid
|
assert srq.source_cid == rq.source_cid
|
||||||
|
assert srq.identifier == rq.identifier
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user