Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
ee48a6d0
Commit
ee48a6d0
authored
7 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Python 3: fix bluetooth
parent
2dea7391
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/layers/bluetooth.py
+4
-8
4 additions, 8 deletions
scapy/layers/bluetooth.py
test/bluetooth.uts
+12
-12
12 additions, 12 deletions
test/bluetooth.uts
with
16 additions
and
20 deletions
scapy/layers/bluetooth.py
+
4
−
8
View file @
ee48a6d0
...
...
@@ -71,8 +71,7 @@ class HCI_ACL_Hdr(Packet):
def
post_build
(
self
,
p
,
pay
):
p
+=
pay
if
self
.
len
is
None
:
l
=
len
(
p
)
-
4
p
=
p
[:
2
]
+
chr
(
l
&
0xff
)
+
chr
((
l
>>
8
)
&
0xff
)
+
p
[
4
:]
p
=
p
[:
2
]
+
struct
.
pack
(
"
<H
"
,
len
(
pay
))
+
p
[
4
:]
return
p
...
...
@@ -84,8 +83,7 @@ class L2CAP_Hdr(Packet):
def
post_build
(
self
,
p
,
pay
):
p
+=
pay
if
self
.
len
is
None
:
l
=
len
(
pay
)
p
=
chr
(
l
&
0xff
)
+
chr
((
l
>>
8
)
&
0xff
)
+
p
[
2
:]
p
=
struct
.
pack
(
"
<H
"
,
len
(
pay
))
+
p
[
2
:]
return
p
...
...
@@ -103,8 +101,7 @@ class L2CAP_CmdHdr(Packet):
def
post_build
(
self
,
p
,
pay
):
p
+=
pay
if
self
.
len
is
None
:
l
=
len
(
p
)
-
4
p
=
p
[:
2
]
+
chr
(
l
&
0xff
)
+
chr
((
l
>>
8
)
&
0xff
)
+
p
[
4
:]
p
=
p
[:
2
]
+
struct
.
pack
(
"
<H
"
,
len
(
pay
))
+
p
[
4
:]
return
p
def
answers
(
self
,
other
):
if
other
.
id
==
self
.
id
:
...
...
@@ -464,8 +461,7 @@ class HCI_Command_Hdr(Packet):
def
post_build
(
self
,
p
,
pay
):
p
+=
pay
if
self
.
len
is
None
:
l
=
len
(
p
)
-
3
p
=
p
[:
2
]
+
chr
(
l
&
0xff
)
+
p
[
3
:]
p
=
p
[:
2
]
+
struct
.
pack
(
"
B
"
,
len
(
pay
))
+
p
[
3
:]
return
p
class
HCI_Cmd_Reset
(
Packet
):
...
...
This diff is collapsed.
Click to expand it.
test/bluetooth.uts
+
12
−
12
View file @
ee48a6d0
...
...
@@ -3,18 +3,18 @@
+ HCI Commands
= LE Create Connection Cancel
expected_cmd_raw_data = "010e2000"
.decode('hex'
)
cmd_raw_data =
str
(HCI_Hdr() / HCI_Command_Hdr() / HCI_Cmd_LE_Create_Connection_Cancel())
expected_cmd_raw_data =
hex_bytes(
"010e2000")
cmd_raw_data =
raw
(HCI_Hdr() / HCI_Command_Hdr() / HCI_Cmd_LE_Create_Connection_Cancel())
assert(expected_cmd_raw_data == cmd_raw_data)
= Disconnect
expected_cmd_raw_data = "01060403341213"
.decode('hex'
)
cmd_raw_data =
str
(HCI_Hdr() / HCI_Command_Hdr() / HCI_Cmd_Disconnect(handle=0x1234))
expected_cmd_raw_data =
hex_bytes(
"01060403341213")
cmd_raw_data =
raw
(HCI_Hdr() / HCI_Command_Hdr() / HCI_Cmd_Disconnect(handle=0x1234))
assert(expected_cmd_raw_data == cmd_raw_data)
= LE Connection Update Command
expected_cmd_raw_data = "0113200e47000a00140001003c000100ffff"
.decode('hex'
)
cmd_raw_data =
str
(
expected_cmd_raw_data =
hex_bytes(
"0113200e47000a00140001003c000100ffff")
cmd_raw_data =
raw
(
HCI_Hdr() / HCI_Command_Hdr() / HCI_Cmd_LE_Connection_Update(
handle=0x47, min_interval=10, max_interval=20, latency=1, timeout=60,
min_ce=1, max_ce=0xffff))
...
...
@@ -23,7 +23,7 @@ assert(expected_cmd_raw_data == cmd_raw_data)
+ HCI Events
= LE Connection Update Event
evt_raw_data = "043e0a03004800140001003c00"
.decode('hex'
)
evt_raw_data =
hex_bytes(
"043e0a03004800140001003c00")
evt_pkt = HCI_Hdr(evt_raw_data)
assert(evt_pkt[HCI_LE_Meta_Connection_Update_Complete].handle == 0x48)
assert(evt_pkt[HCI_LE_Meta_Connection_Update_Complete].interval == 20)
...
...
@@ -35,20 +35,20 @@ assert(evt_pkt[HCI_LE_Meta_Connection_Update_Complete].timeout == 60)
= Parse EIR_Flags, EIR_CompleteList16BitServiceUUIDs, EIR_CompleteLocalName and EIR_TX_Power_Level
ad_report_raw_data = \
"043e2b020100016522c00181781f0201020303d9fe1409" \
"506562626c652054696d65204c452037314536020a0cde"
.decode('hex'
)
hex_bytes(
"043e2b020100016522c00181781f0201020303d9fe1409" \
"506562626c652054696d65204c452037314536020a0cde")
scapy_packet = HCI_Hdr(ad_report_raw_data)
assert(scapy_packet[EIR_Flags].flags == 0x02)
assert(scapy_packet[EIR_CompleteList16BitServiceUUIDs].svc_uuids == [0xfed9])
assert(scapy_packet[EIR_CompleteLocalName].local_name == 'Pebble Time LE 71E6')
assert(scapy_packet[EIR_CompleteLocalName].local_name ==
b
'Pebble Time LE 71E6')
assert(scapy_packet[EIR_TX_Power_Level].level == 12)
= Parse EIR_Manufacturer_Specific_Data
scan_resp_raw_data = \
"043e2302010401be5e0eb9f04f1716ff5401005f423331" \
"3134374432343631fc00030c0000de"
.decode('hex'
)
hex_bytes(
"043e2302010401be5e0eb9f04f1716ff5401005f423331" \
"3134374432343631fc00030c0000de")
scapy_packet = HCI_Hdr(scan_resp_raw_data)
assert(scapy_packet[EIR_Manufacturer_Specific_Data].data == b'\x00_B31147D2461\xfc\x00\x03\x0c\x00\x00')
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment