You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2022/06/22 08:04:31 UTC

[mynewt-nimble] branch master updated (b8d1180b -> 10efe050)

This is an automated email from the ASF dual-hosted git repository.

janc pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


    from b8d1180b Apollo3: Properly accumulate full ACL packet before sending to BLE controller (#1276)
     new b2d682bf tools/hci_throughput: fix supported octets info
     new 0d49b669 tools/hci_throughput: added HCI commands
     new 10efe050 tools/hci_throughput: Fixed set phy, error handling

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 tools/hci_throughput/hci.py          | 32 +++++++++++++++++++++++++
 tools/hci_throughput/hci_commands.py | 23 ++++++++++++++----
 tools/hci_throughput/hci_device.py   | 45 ++++++++++++++++++++++++++++--------
 3 files changed, 86 insertions(+), 14 deletions(-)


[mynewt-nimble] 03/03: tools/hci_throughput: Fixed set phy, error handling

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 10efe05023594ad7cfabf172893a65945434ceaf
Author: Jakub <ja...@codecoup.pl>
AuthorDate: Mon Jun 13 15:09:54 2022 +0200

    tools/hci_throughput: Fixed set phy, error handling
---
 tools/hci_throughput/hci_device.py | 45 +++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/tools/hci_throughput/hci_device.py b/tools/hci_throughput/hci_device.py
index 10ef3998..0a20fed5 100644
--- a/tools/hci_throughput/hci_device.py
+++ b/tools/hci_throughput/hci_device.py
@@ -82,8 +82,37 @@ def parse_arguments():
         logging.error(traceback.format_exc())
         sys.exit()
 
+async def set_phy(bt_dev: hci_commands.HCI_Commands, conn_handle, cfg_phy,
+                          supported_features):
+    def error(info):
+        print("ERROR: Check log files")
+        raise Exception(info, ": Unsupported PHY. Closing...")
+
+    PHY_2M = supported_features & hci.LE_FEATURE_2M_PHY
+    PHY_CODED = supported_features & hci.LE_FEATURE_CODED_PHY
+
+    if (cfg_phy == "1M"):
+        await bt_dev.cmd_le_set_phy(conn_handle, all_phys=0, tx_phys=1, rx_phys=1, phy_options=0)
+        logging.info(f"PHY 1M")
+
+    elif (cfg_phy == "2M"):
+        if (PHY_2M):
+            await bt_dev.cmd_le_set_phy(conn_handle, all_phys=0, tx_phys=2, rx_phys=2, phy_options=0)
+            logging.info(f"PHY 2M")
+        else:
+            error("2M")
+
+    elif (cfg_phy == "Coded"):
+        if (PHY_CODED):
+            await bt_dev.cmd_le_set_phy(conn_handle, all_phys=0, tx_phys=3, rx_phys=3, phy_options=0)
+            logging.info(f"PHY Coded")
+        else:
+            error("Coded")
 
-async def init(bt_dev: hci_commands.HCI_Commands, ini: dict):
+    else:
+        error("Possible PHY in config.yaml: 1M, 2M, Coded")
+
+async def init(bt_dev: hci_commands.HCI_Commands, ini: dict, cfg: dict):
     """ init: Assumed to be the same for all devices """
     asyncio.create_task(bt_dev.rx_buffer_q_wait())
     await bt_dev.cmd_reset()
@@ -91,7 +120,7 @@ async def init(bt_dev: hci_commands.HCI_Commands, ini: dict):
         await bt_dev.cmd_le_set_random_addr(ini["own_address"])
     await bt_dev.cmd_set_event_mask(mask=0x200080000204e090)
     await bt_dev.cmd_le_set_event_mask(mask=0x00000007FFFFFFFF)
-    await bt_dev.cmd_le_set_dflt_phy(all_phys=0, tx_phys=2, rx_phys=2)
+    await bt_dev.cmd_le_read_local_supported_features()
     await bt_dev.cmd_le_read_buffer_size()
     await bt_dev.cmd_le_read_max_data_len()
 
@@ -112,7 +141,7 @@ async def finish(bt_dev: hci_commands.HCI_Commands, cfg: dict):
 
 
 async def async_main_rx(bt_dev: hci_commands.HCI_Commands, ini: dict, cfg: dict):
-    await init(bt_dev, ini)
+    await init(bt_dev, ini, cfg)
 
     bt_dev.tp = tp.Throughput(name="tp_receiver", mode=bt_dev.device_mode,
                               total_packets_number=hci.num_of_packets_to_send,
@@ -154,7 +183,7 @@ async def async_main_rx(bt_dev: hci_commands.HCI_Commands, ini: dict, cfg: dict)
     await finish(bt_dev, cfg)
 
 async def async_main_tx(bt_dev: hci_commands.HCI_Commands, ini: dict, cfg: dict):
-    await init(bt_dev, ini)
+    await init(bt_dev, ini, cfg)
 
     conn_params = hci.HCI_Connect()
     conn_params.set(
@@ -178,12 +207,8 @@ async def async_main_tx(bt_dev: hci_commands.HCI_Commands, ini: dict, cfg: dict)
     await bt_dev.cmd_le_set_data_len(hci.conn_handle, tx_octets=0, tx_time=0)
     await hci_commands.wait_for_event(bt_dev.async_ev_set_data_len, hci.WAIT_FOR_EVENT_TIMEOUT)
 
-    if cfg["phy"] == "1M":
-        await bt_dev.cmd_le_set_phy(hci.conn_handle, all_phys=0, tx_phys=1, rx_phys=1, phy_options=0)
-    elif cfg["phy"] == "2M":
-        await bt_dev.cmd_le_set_phy(hci.conn_handle, all_phys=0, tx_phys=2, rx_phys=2, phy_options=0)
-    else:
-        raise Exception("PHY parameter not valid.")
+    await set_phy(bt_dev, hci.conn_handle, cfg['phy'],
+                  hci.le_read_local_supported_features.le_features)
     await hci_commands.wait_for_event(bt_dev.async_ev_update_phy, hci.WAIT_FOR_EVENT_TIMEOUT)
 
     ############


[mynewt-nimble] 02/03: tools/hci_throughput: added HCI commands

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 0d49b6691fc240a4f983e1e66fb00fc804a9042b
Author: Jakub <ja...@codecoup.pl>
AuthorDate: Mon Jun 13 15:03:06 2022 +0200

    tools/hci_throughput: added HCI commands
    
    Added read local supported commands
    and local supported features cmds.
---
 tools/hci_throughput/hci.py          | 30 ++++++++++++++++++++++++++++++
 tools/hci_throughput/hci_commands.py | 14 ++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/tools/hci_throughput/hci.py b/tools/hci_throughput/hci.py
index 69b36374..6ed45625 100644
--- a/tools/hci_throughput/hci.py
+++ b/tools/hci_throughput/hci.py
@@ -21,6 +21,7 @@ from dataclasses import dataclass
 import struct
 from binascii import unhexlify
 import random
+import ctypes
 
 ############
 # DEFINES
@@ -57,6 +58,7 @@ OCF_READ_BD_ADDR = 0x0009
 OGF_LE_CTL = 0x08
 OCF_LE_SET_EVENT_MASK = 0x0001
 OCF_LE_READ_BUFFER_SIZE_V1 = 0x0002
+OCF_LE_READ_LOCAL_SUPPORTED_FEATURES = 0x0003
 OCF_LE_READ_BUFFER_SIZE_V2 = 0x0060
 OCF_LE_SET_RANDOM_ADDRESS = 0x0005
 OCF_LE_SET_ADVERTISING_PARAMETERS = 0x0006
@@ -80,6 +82,9 @@ STATIC_RANDOM_ADDRESS_TYPE = 1
 WAIT_FOR_EVENT_TIMEOUT = 5
 WAIT_FOR_EVENT_CONN_TIMEOUT = 25
 
+LE_FEATURE_2M_PHY = ctypes.c_uint64(0x0100).value
+LE_FEATURE_CODED_PHY = ctypes.c_uint64(0x0800).value
+
 ############
 # GLOBAL VAR
 ############
@@ -99,6 +104,8 @@ phy = None
 ev_num_comp_pkts = None
 num_of_completed_packets_cnt = 0
 num_of_completed_packets_time  = 0
+read_local_commands = None
+le_read_local_supported_features = None
 
 ############
 # FUNCTIONS
@@ -203,6 +210,29 @@ class LE_Read_PHY:
         self.tx_phy = tx_phy
         self.rx_phy = rx_phy
 
+@dataclass
+class Read_Local_Commands:
+    status: int
+    supported_commands: bytes
+
+    def __init__(self):
+        self.set()
+
+    def set(self, rcv_bytes = bytes(65)):
+        self.status = int(rcv_bytes[0])
+        self.supported_commands = rcv_bytes[1:]
+
+@dataclass
+class LE_Read_Local_Supported_Features:
+    status: int
+    le_features: bytes
+
+    def __init__(self):
+        self.set()
+
+    def set(self, rcv_bytes = bytes(9)):
+        self.status = int(rcv_bytes[0])
+        self.le_features = ctypes.c_uint64.from_buffer_copy(rcv_bytes[1:]).value
 
 ############
 # EVENTS
diff --git a/tools/hci_throughput/hci_commands.py b/tools/hci_throughput/hci_commands.py
index 286f4506..a6040ef0 100644
--- a/tools/hci_throughput/hci_commands.py
+++ b/tools/hci_throughput/hci_commands.py
@@ -131,6 +131,14 @@ class HCI_Commands():
             await self.async_ev_cmd_end.wait()
             self.async_ev_cmd_end.clear()
 
+    async def cmd_le_read_local_supported_features(self):
+        async with self.async_sem_cmd:
+            self.hci_send_cmd.set(hci.OGF_LE_CTL, hci.OCF_LE_READ_LOCAL_SUPPORTED_FEATURES)
+            logging.debug("%s %s", self.cmd_le_read_local_supported_features.__name__, self.hci_send_cmd)
+            await self.send(self.hci_send_cmd.ba_full_message)
+            await self.async_ev_cmd_end.wait()
+            self.async_ev_cmd_end.clear()
+
     async def cmd_le_set_random_addr(self, addr: str):
         async with self.async_sem_cmd:
             addr_ba = hci.cmd_addr_to_ba(addr)
@@ -382,6 +390,8 @@ class HCI_Commands():
 
         elif ogf == hci.OGF_INFO_PARAM:
             if ocf == hci.OCF_READ_LOCAL_COMMANDS:
+                hci.read_local_commands = hci.Read_Local_Commands()
+                hci.read_local_commands.set(bytes(current_ev.return_parameters))
                 return status()
             elif ocf == hci.OCF_READ_BD_ADDR:
                 hci.bdaddr = hci.ba_addr_to_str(
@@ -397,6 +407,10 @@ class HCI_Commands():
                                             current_ev.return_parameters))
                 logging.info(f"LE Buffer size: {hci.le_read_buffer_size}")
                 return hci.le_read_buffer_size.status
+            elif ocf == hci.OCF_LE_READ_LOCAL_SUPPORTED_FEATURES:
+                hci.le_read_local_supported_features = hci.LE_Read_Local_Supported_Features()
+                hci.le_read_local_supported_features.set(current_ev.return_parameters)
+                return status()
             elif ocf == hci.OCF_LE_SET_RANDOM_ADDRESS:
                 return status()
             elif ocf == hci.OCF_LE_SET_ADVERTISING_PARAMETERS:


[mynewt-nimble] 01/03: tools/hci_throughput: fix supported octets info

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit b2d682bf51b2bba97f0abc321aecb7be076f3a85
Author: Jakub <ja...@codecoup.pl>
AuthorDate: Mon Jun 13 14:18:29 2022 +0200

    tools/hci_throughput: fix supported octets info
---
 tools/hci_throughput/hci.py          | 2 ++
 tools/hci_throughput/hci_commands.py | 9 +++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/hci_throughput/hci.py b/tools/hci_throughput/hci.py
index 072e395e..69b36374 100644
--- a/tools/hci_throughput/hci.py
+++ b/tools/hci_throughput/hci.py
@@ -31,6 +31,8 @@ HCI_COMMAND_PACKET = 0x01
 HCI_ACL_DATA_PACKET = 0x02
 HCI_EVENT_PACKET = 0x04
 
+L2CAP_HDR_BYTES = 4
+
 HCI_EV_CODE_DISCONN_CMP = 0x05
 HCI_EV_CODE_CMD_CMP = 0x0e
 HCI_EV_CODE_CMD_STATUS = 0x0f
diff --git a/tools/hci_throughput/hci_commands.py b/tools/hci_throughput/hci_commands.py
index 2978ab85..286f4506 100644
--- a/tools/hci_throughput/hci_commands.py
+++ b/tools/hci_throughput/hci_commands.py
@@ -422,10 +422,11 @@ class HCI_Commands():
                 hci.max_data_len.set(*struct.unpack("<BHHHH",
                                      current_ev.return_parameters))
                 logging.info(f"Suggested Max Data Len: {hci.max_data_len}")
-                if (hci.num_of_bytes_to_send > hci.max_data_len.supported_max_tx_octets - 4):
-                    logging.critical(f"Number of bytes to send: {hci.num_of_bytes_to_send}\
-                                     not supported. Closing.")
-                    raise SystemExit("Number of bytes to send not supported. Closing.")
+                if (hci.num_of_bytes_to_send > hci.max_data_len.supported_max_tx_octets - hci.L2CAP_HDR_BYTES):
+                    logging.critical(f"Number of data bytes to send + 4 bytes of L2CAP header: {hci.num_of_bytes_to_send + 4} "
+                                     f"exceeds allowed value of: {hci.max_data_len.supported_max_tx_octets}. Closing.")
+                    raise SystemExit(f"Number of data bytes to send + 4 bytes of L2CAP header: {hci.num_of_bytes_to_send + 4} "
+                                     f"exceeds allowed value of: {hci.max_data_len.supported_max_tx_octets}. Closing.")
 
                 return status()
             elif ocf == hci.OCF_LE_READ_PHY: