Skip to content

Commit

Permalink
SDP: Enable BTP Service SDP
Browse files Browse the repository at this point in the history
Add Service ID `BTP_SERVICE_ID_SDP = 0x1F` for SDP.

Add SDP command `SDP_SEARCH_REQ`, `SDP_ATTR_REQ`, and
`SDP_SEARCH_ATTR_REQ`.

Add SDP event `SDP_EV_SERVICE_RECORD_HANDLE`.

Handle BTP SDP command `SDP_SEARCH_REQ` to start service search
transaction.

Handle the event `SDP_EV_SERVICE_RECORD_HANDLE` to get service record
handle.

Handle BTP SDP command `SDP_ATTR_REQ` to start service attribution
transaction.

Handle BTP SDP command `SDP_SEARCH_ATTR_REQ` to start service search
transaction.

Signed-off-by: Lyle Zhu <[email protected]>
  • Loading branch information
lylezhu2012 committed Nov 28, 2024
1 parent 94f15c0 commit 4b69a72
Show file tree
Hide file tree
Showing 10 changed files with 775 additions and 3 deletions.
1 change: 1 addition & 0 deletions autopts/ptsprojects/stack/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@
from .tmap import *
from .ots import *
from .pbp import *
from .sdp import *
# GENERATOR append 1
69 changes: 69 additions & 0 deletions autopts/ptsprojects/stack/layers/sdp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# auto-pts - The Bluetooth PTS Automation Framework
#
# Copyright (c) 2017, Intel Corporation.
# Copyright (c) 2024, Codecoup.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
import logging

from autopts.ptsprojects.stack.common import Property, wait_for_event
from autopts.pybtp.types import AdType, IOCap, Addr


class SDP:
def __init__(self):

self.service_record_handles = {}

def add_service_record_handles(self, addr, handle):
handles = []
if addr in self.service_record_handles.keys():
handles.append(self.service_record_handles[addr])
handles.append(handle)
self.service_record_handles[addr] = handles

def has_service_record_handle(self, addr=None):
if addr and addr in self.service_record_handles.keys():
if len(self.service_record_handles[addr]) > 0:
handle = self.service_record_handles[addr][0]
return handle
else:
if len(self.service_record_handles) > 0:
addr = list(self.service_record_handles.keys())[0]
if len(self.service_record_handles[addr]) > 0:
handle = self.service_record_handles[addr][0]
return handle
return 0

def get_service_record_handle(self, addr=None):
if addr and addr in self.service_record_handles.keys():
if len(self.service_record_handles[addr]) > 0:
handle = self.service_record_handles[addr][0]
del self.service_record_handles[addr][0]
return handle
else:
if len(self.service_record_handles) > 0:
addr = list(self.service_record_handles.keys())[0]
if len(self.service_record_handles[addr]) > 0:
handle = self.service_record_handles[addr][0]
del self.service_record_handles[addr][0]
return handle
return 0

def sdp_wait_for_service_record_handle(self, timeout=5, addr=None):
handle = self.get_service_record_handle(addr)
if handle != 0:
return handle

wait_for_event(timeout, lambda: self.has_service_record_handle(addr) > 0)

return self.get_service_record_handle(addr)
9 changes: 8 additions & 1 deletion autopts/ptsprojects/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"TMAP": 1 << defs.BTP_SERVICE_ID_TMAP,
"OTS": 1 << defs.BTP_SERVICE_ID_OTS,
"PBP": 1 << defs.BTP_SERVICE_ID_PBP,
"SDP": 1 << defs.BTP_SERVICE_ID_SDP,
# GENERATOR append 1
}

Expand Down Expand Up @@ -89,6 +90,7 @@ def __init__(self):
self.tmap = None
self.ots = None
self.pbp = None
self.sdp = None
# GENERATOR append 2

def is_svc_supported(self, svc):
Expand Down Expand Up @@ -191,6 +193,8 @@ def ots_init(self):
def pbp_init(self):
self.pbp = PBP()

def sdp_init(self):
self.sdp = SDP()
# GENERATOR append 3

def cleanup(self):
Expand Down Expand Up @@ -223,7 +227,7 @@ def cleanup(self):

if self.micp:
self.micp_init()

if self.ccp:
self.ccp_init()

Expand Down Expand Up @@ -275,6 +279,9 @@ def cleanup(self):
if self.pbp:
self.pbp_init()

if self.sdp:
self.sdp_init()

# GENERATOR append 4


Expand Down
1 change: 1 addition & 0 deletions autopts/ptsprojects/zephyr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import autopts.ptsprojects.zephyr.tbs
import autopts.ptsprojects.zephyr.tmap
import autopts.ptsprojects.zephyr.ots
import autopts.ptsprojects.zephyr.sdp
# GENERATOR append 1

# Constants
Expand Down
Loading

0 comments on commit 4b69a72

Please sign in to comment.