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 = 30`
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 Sep 9, 2024
1 parent f13d544 commit 17cb9cd
Show file tree
Hide file tree
Showing 10 changed files with 776 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 @@ -40,4 +40,5 @@
from .gtbs import *
from .tmap import *
from .ots 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)
10 changes: 9 additions & 1 deletion autopts/ptsprojects/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"TBS": 1 << defs.BTP_SERVICE_ID_TBS,
"TMAP": 1 << defs.BTP_SERVICE_ID_TMAP,
"OTS": 1 << defs.BTP_SERVICE_ID_OTS,
"SDP": 1 << defs.BTP_SERVICE_ID_SDP,
# GENERATOR append 1
}

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

def is_svc_supported(self, svc):
Expand Down Expand Up @@ -186,6 +188,9 @@ def tmap_init(self):
def ots_init(self):
self.ots = OTS()

def sdp_init(self):
self.sdp = SDP()

# GENERATOR append 3

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

if self.micp:
self.micp_init()

if self.ccp:
self.ccp_init()

Expand Down Expand Up @@ -267,6 +272,9 @@ def cleanup(self):
if self.ots:
self.ots_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 @@ -47,6 +47,7 @@
import autopts.ptsprojects.zephyr.gtbs
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 17cb9cd

Please sign in to comment.