Commit Graph

482 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
0f849abb1b btdev: Fix not checking conditions for LE Set Random Address
The spec says LE Set Random Address cannot be used when scan is enabled
or with legacy advertising:

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2480

  'If the Host issues this command when any of advertising (created
  using legacy advertising commands), scanning, or initiating are
  enabled, the Controller shall return the error code Command
  Disallowed (0x0C).'
2021-07-19 14:16:16 -07:00
Luiz Augusto von Dentz
0356d2a4c6 btdev: Add proper checks for own_addr_type for LE scan/adv
own_addr_type 0x01 and 0x03 shall check that a random address has
properly been set:

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2496:

  'If LE_Scan_Enable is set to 0x01, the scanning parameters'
  Own_Address_Type parameter is set to 0x01 or 0x03, and the random
  ddress for the device has not been initialized, the Controller shall
  return the error code Invalid HCI Command Parameters (0x12).'

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2614:

  'If Enable is set to 0x01, the scanning parameters' Own_Address_Type
  parameter is set to 0x01 or 0x03, and the random address for the
  device has not been initialized, the Controller shall return the
  error code Invalid HCI Command Parameters (0x12).'
2021-07-19 14:15:47 -07:00
Tedd Ho-Jeong An
14c6a73265 emulator/btdev: Add support HCI_READ_CLOCK command
This patch adds support HCI_READ_CLOCK command in btdev.
2021-07-16 12:24:58 -07:00
Luiz Augusto von Dentz
8f30f0837d btdev: Add proper checks for own_addr_type for extended advertising
own_addr_type 0x01 and 0x03 shall check that a random address has
properly been set and in case of 0x03 the resolving list actually
contains the irk of the identity address:

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2596

  'If the advertising set's Own_Address_Type parameter is set to 0x01
  and the random address for the advertising set has not been
  initialized, the Controller shall return the error code Invalid HCI
  Command Parameters (0x12).'

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2597

  'If the advertising set's Own_Address_Type parameter is set to 0x03,
  the controller's resolving list did not contain a matching entry, and
  the random address for the advertising set has not been initialized,
  the Controller shall return the error code Invalid HCI Command
  Parameters (0x12).'
2021-07-14 11:37:20 -07:00
Tedd Ho-Jeong An
77dba3b4d9 emulator/btdev: clean up the queue before closing the test
This patch clean up the queue for connection before closing the test to
prevent the potential memory leak.

==50== 32 bytes in 1 blocks are definitely lost in loss record 18 of 32
==50==    at 0x483A809: malloc (vg_replace_malloc.c:307)
==50==    by 0x14A37E: btd_malloc (util.c:33)
==50==    by 0x149D9D: queue_new (queue.c:47)
==50==    by 0x13B3C0: btdev_create (btdev.c:6042)
==50==    by 0x13178E: create_vhci (hciemu.c:229)
==50==    by 0x13178E: hciemu_new_num (hciemu.c:403)
==50==    by 0x130E2C: read_index_list_callback (mgmt-tester.c:357)
==50==    by 0x14AD91: request_complete (mgmt.c:264)
==50==    by 0x14BD34: can_read_data (mgmt.c:356)
==50==    by 0x14E794: watch_callback (io-glib.c:157)
==50==    by 0x48B578E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5B17: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5E32: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==
==50== 32 bytes in 1 blocks are definitely lost in loss record 19 of 32
==50==    at 0x483A809: malloc (vg_replace_malloc.c:307)
==50==    by 0x14A37E: btd_malloc (util.c:33)
==50==    by 0x149D9D: queue_new (queue.c:47)
==50==    by 0x13B3C0: btdev_create (btdev.c:6042)
==50==    by 0x1318F7: hciemu_client_new (hciemu.c:332)
==50==    by 0x1318F7: hciemu_new_num (hciemu.c:412)
==50==    by 0x130E2C: read_index_list_callback (mgmt-tester.c:357)
==50==    by 0x14AD91: request_complete (mgmt.c:264)
==50==    by 0x14BD34: can_read_data (mgmt.c:356)
==50==    by 0x14E794: watch_callback (io-glib.c:157)
==50==    by 0x48B578E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5B17: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5E32: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.6)
2021-07-01 14:26:01 -07:00
Tedd Ho-Jeong An
468d6f1191 emulator/bthost: Create ext adv params before setting adv data
Based on the SPEC 5.2 Vol 4, Part E, Section 7.8.54, the
LE_Set_Extended_Advertising_Data_Command may be issued after an
advertising set identifed by the Advertising_Handle has been created
using the HCI_LE_Set_Extended_Advertising_Parameters command.
2021-06-23 11:51:11 -07:00
Luiz Augusto von Dentz
d9979f26e6 emulator/btdev: Add support HCI LE Adv Set Terminated event
This patch adds support the HCI_LE_Advertising_Set_Terminated event in
btdev.
2021-06-23 11:51:10 -07:00
Tedd Ho-Jeong An
5145b1ea2e emulator/btdev: Add support multiple instance of extended advertising
This patch adds support multiple instance of extended advertising.
2021-06-23 11:51:10 -07:00
Luiz Augusto von Dentz
f465a00ff7 btdev: Check advertising/scanning states when changing Resolving List
Resolving List cannot be changed when advertising/scanning:

• Advertising (other than periodic advertising) is enabled,
• Scanning is enabled, or
• an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or
HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.
2021-06-09 11:26:01 -07:00
Luiz Augusto von Dentz
6031e6b828 btdev: Check advertising/scanning states when changing White List
White List cannot be changed when advertising/scanning:

• any advertising filter policy uses the White List and advertising is
enabled,
• the scanning filter policy uses the White List and scanning is
enabled, or
• the initiator filter policy uses the White List and an
HCI_LE_Create_Connection or HCI_LE_Extended_Create_Connection
command is outstanding.
2021-06-09 11:26:01 -07:00
Luiz Augusto von Dentz
125fa19faa btdev: Remove debugs
Remove left-over util_debugs.
2021-06-04 17:01:12 -07:00
Luiz Augusto von Dentz
f19000cf29 btdev: Fix handling of white/resolving list
le_cig.cis entries was not properly checked which could lead to
overwriting le_wl/le_rl field.

While at it this also makes changes so have proper struct/fields for
le_wl and le_rl so they easier to manage.
2021-06-04 12:16:23 -07:00
Luiz Augusto von Dentz
e6310300e3 btdev: Fix crash when generating disconnected event for BIS
When generating disconnected event for a BIS it would not have any
link as the ISO is in fact we are broadcasting and don't have an ACL.
2021-06-03 17:10:22 -07:00
Tedd Ho-Jeong An
76f49e69d9 emulator/btdev: Enable LE Privacy feature
This patch enables LE Privacy to support LL Privacy feature.
2021-06-01 14:10:39 -07:00
Luiz Augusto von Dentz
6a92290474 btdev: Add resolving list support
This adds support for commands related to resolving list.
2021-05-17 14:52:12 -07:00
Luiz Augusto von Dentz
78902b776a btdev: Add support for Add/Remove White List
This adds support for Add to/Remove from White List.
2021-05-17 10:36:51 -07:00
Luiz Augusto von Dentz
022eda58e1 btdev: Fix crashing if ISO link is in fact a BIS
BIS doesn't not have necessarily needs a link if there is no sync in
place.
2021-05-13 13:26:13 -07:00
Luiz Augusto von Dentz
be73408f6f btdev: Mark LE Periodic Advertising bit as supported
This enables LE Periodic Advertising bit on LE Read Local Supported
Features:

> HCI Event: Command Complete (0x0e) plen 12
      LE Read Local Supported Features (0x08|0x0003) ncmd 1
        Status: Success (0x00)
        Features: 0x00 0x39 0x00 0xf0 0x01 0x00 0x00 0x00
          LE 2M PHY
          LE Coded PHY
          LE Extended Advertising
          LE Periodic Advertising
          Connected Isochronous Stream - Master
          Connected Isochronous Stream - Slave
          Isochronous Broadcaster
          Synchronized Receiver
          Isochronous Channels (Host Support)
2021-05-10 11:13:02 -07:00
Tedd Ho-Jeong An
99552812f1 emulator/btdev: Add missing commands
This patch adds missing commands HCI_Read_RSSI and
HCI_Read_Transmit_Power_Level commands.
2021-04-26 08:54:50 -07:00
Luiz Augusto von Dentz
a3fa743e8f btdev: Fix invalid BIG Complete event
Fields were not being initialized properly and no connection was
created so other commands using the same handle wouldn't work.
2021-04-08 10:36:06 -07:00
Keyur Parekh
44b82b959d emulator: Add Create BIG command in emulator
This adds support for Create BIG command HCI
command in emulator. These changes are needed for
making the emulator useful for testing
LE Audio broadcast feature.
2021-04-06 17:13:37 -07:00
Luiz Augusto von Dentz
9d493f8060 btdev: Set CIG ID and CIS ID when generating CIS requested
This is required in order for the host to properly accept/reject the
connection.
2021-03-26 14:21:33 -07:00
Luiz Augusto von Dentz
a8f26e2711 btdev: Always set connection handle on CIS established
This is required in order for the host to be able to distinguished
errors if there are multiple CIS connections outstanding.
2021-03-26 14:21:33 -07:00
Keyur Parekh
ef2412c146 emulator: Periodic Advertising Command
This adds support for Periodic Advertising HCI
command in the emulator. These changes are the
first step in making the emulator useful for
testing the LE Audio Broadcast feature
2021-03-15 14:43:39 -07:00
Luiz Augusto von Dentz
f6441b238c btdev: Add support for Configure Data Path
> HCI Event: Command Complete (0x0e) plen 68
      Read Local Supported Commands (0x04|0x0002) ncmd 1
        Status: Success (0x00)
        Commands: 169 entries
...
          Configure Data Path (Octet 45 - Bit 5)
2021-03-02 16:22:25 -08:00
Luiz Augusto von Dentz
9e627576f0 btdev: Add support Read Local Supported Controller Delay
> HCI Event: Command Complete (0x0e) plen 68
      Read Local Supported Commands (0x04|0x0002) ncmd 1
        Status: Success (0x00)
        Commands: 168 entries
...
          Read Local Supported Controller Delay (Octet 45 - Bit 4)
2021-03-02 16:22:25 -08:00
Luiz Augusto von Dentz
c4aec69707 monitor: Add support for decoding Read Local Controller Delay
< HCI Command: Read Local Supported Controller Delay (0x04|0x000f) plen 8
        Codec: mSBC (0x05)
        Logical Transport Type: 0x02
          Codec supported over BR/EDR SCO and eSCO
        Direction: Input (Host to Controller) (0x00)
        Length Codec Configuration: 0
> HCI Event: Command Complete (0x0e) plen 10
      Read Local Supported Controller Delay (0x04|0x000f) ncmd 1
        Status: Success (0x00)
        Minimum Controller delay: 0 us (0x000000)
        Maximum Controller delay: 0 us (0x000000)
2021-03-02 16:22:25 -08:00
Luiz Augusto von Dentz
a0d075072d btdev: Add support Read Local Supported Codec Capabilities
> HCI Event: Command Complete (0x0e) plen 68
      Read Local Supported Commands (0x04|0x0002) ncmd 1
        Status: Success (0x00)
        Commands: 167 entries
...
          Read Local Supported Codec Capabilities (Octet 45 - Bit 3)
2021-03-02 16:22:25 -08:00
Luiz Augusto von Dentz
1f8bab677d btdev: Add support Read Local Supported Codecs V2
> HCI Event: Command Complete (0x0e) plen 68
      Read Local Supported Commands (0x04|0x0002) ncmd 1
        Status: Success (0x00)
        Commands: 167 entries
...
          Read Local Supported Codecs V2 (Octet 45 - Bit 2)
2021-03-02 16:22:25 -08:00
Luiz Augusto von Dentz
dc7a726aa7 btdev: Fix not sending ISO packets
ISO packets were not correctly parsed causing them to not be sent
properly.
2021-02-19 15:21:12 -08:00
Luiz Augusto von Dentz
17e208f6a6 emulator: Add option for enabling debug with btvirt
This adds -d/--debug options which enables debug of vhci instance on
btvirt.
2021-02-19 15:21:12 -08:00
Luiz Augusto von Dentz
441ab748cc vhci: Add vhci_set_debug
This enables debug with btdev_set_debug.
2021-02-19 15:21:12 -08:00
Luiz Augusto von Dentz
fccfc3b5e6 btdev: Fix auto-disable Extended Adv Set
For a Set to be disable there is a dedicated event that terminates the
set otherwise it should be considered enabled even when connected.
2021-01-22 14:48:33 -08:00
Luiz Augusto von Dentz
83c8c1e928 btdev: Fix using CIG settings from the peripheral not the central
SetCIGParameters is only used by the central while accept/reject CIS is
performed on in the peripheral so le_cis_estabilished shall use the
parameters set in the conn->link->dev.
2021-01-19 14:06:45 -08:00
Luiz Augusto von Dentz
c2cae83b30 emulator: Fix sending CIS Requested to Create CIS device
CIS Requested shall be send to the remote peer not the originating one.
2021-01-14 12:54:13 -08:00
Tedd Ho-Jeong An
9f1b788a3b emulator/btdev: Add support LE_READ_TX_POWER command
This patch adds support for LE_READ_TX_POWER command.
It uses a random values for min and max tx power since these values is
read from the controller.
2020-12-23 10:27:40 -08:00
Luiz Augusto von Dentz
07cc754760 bthost: Add support for address types other then public
This properly initialize the address type according to the connection
address.
2020-12-17 16:12:39 -08:00
Luiz Augusto von Dentz
77d6ee6fbd hciemu: Add support for multiple clients
This adds support for creating multiple clients (bthost).
2020-12-17 16:12:39 -08:00
Luiz Augusto von Dentz
b5932a5b88 btdev: Add support for multiple connections
This adds support for assigning different handles for connection
instead of always using fixed handles.
2020-12-17 16:12:38 -08:00
Luiz Augusto von Dentz
ed1c044cfe bthost: Always use conn->prnd for Pairing Random
Since it is now properly set with random bytes it shall be used when
responding.
2020-12-17 10:26:21 -08:00
Luiz Augusto von Dentz
a729fe0de9 bthost: Use bt_crypto_random_bytes to generate a Pairing Random
This makes it more consistent with how stacks are implemented instead
of setting the response all zero which is not secure.
2020-12-16 16:37:57 -08:00
Luiz Augusto von Dentz
57bccce9e5 btdev: Fix not responding with the same CIG ID
BT_HCI_CMD_LE_SET_CIG_PARAMS shall be responded using the same CIG ID.
2020-12-15 13:47:00 -08:00
Luiz Augusto von Dentz
b446ed8e8c btdev: Fix not handling BT_HCI_CMD_HOST_NUM_COMPLETED_PACKETS
System such as Zephyr do use BT_HCI_CMD_HOST_NUM_COMPLETED_PACKETS
since BT_HCI_CMD_SET_HOST_FLOW_CONTROL is also supported.
2020-12-07 17:06:51 -08:00
Tedd Ho-Jeong An
8d23082905 emulator: Fix the unchecked return value
This patch fixes the unchecked return value.
2020-11-24 13:03:46 -08:00
Luiz Augusto von Dentz
7f272742be btdev: Fix not emitting Ext Connection Complete properly
le_meta_event must be using when emitting a meta event.
2020-11-17 12:31:28 -08:00
Luiz Augusto von Dentz
39dd929f53 bthost: Fix sending uninitilized data
Syscall param writev(vector[...]) points to uninitialised byte(s)
   at 0x4A8A497: writev (in /usr/lib64/libc-2.31.so)
   by 0x1365C1: send_packet (bthost.c:509)
   by 0x1365C1: send_packet (bthost.c:492)
   by 0x1365C1: next_cmd (bthost.c:737)
   by 0x137578: evt_cmd_complete (bthost.c:882)
   by 0x137578: process_evt (bthost.c:1343)
   by 0x137578: bthost_receive_h4 (bthost.c:2414)
   by 0x12DF49: receive_bthost.part.0 (hciemu.c:134)
   by 0x48B978E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x48B9B17: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x48B9E32: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x14A664: mainloop_run (mainloop-glib.c:66)
   by 0x14AA41: mainloop_run_with_signal (mainloop-notify.c:188)
   by 0x149A7B: tester_run (tester.c:871)
   by 0x129C77: main (mgmt-tester.c:10219)
 Address 0x4c48c05 is 21 bytes inside a block of size 280 alloc'd
   at 0x483CAE9: calloc (vg_replace_malloc.c:760)
   by 0x136487: queue_command (bthost.c:472)
   by 0x136487: send_command (bthost.c:715)
   by 0x13948A: bthost_set_ext_adv_enable (bthost.c:2581)
   by 0x12CEBF: trigger_device_found (mgmt-tester.c:8513)
   by 0x148C9A: wait_callback (tester.c:749)
   by 0x48BA330: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x48B978E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x48B9B17: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x48B9E32: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.6)
   by 0x14A664: mainloop_run (mainloop-glib.c:66)
   by 0x14AA41: mainloop_run_with_signal (mainloop-notify.c:188)
   by 0x149A7B: tester_run (tester.c:871)
2020-11-13 15:12:15 -08:00
Luiz Augusto von Dentz
90cf5bf774 hciemu: Fix crash when test is aborted during pre setup
If the tester_pre_setup_failed is called all timeout related to the
test must be cancelled as the test should have been freed by the
application and the next test is about to start.
2020-11-13 15:12:15 -08:00
Luiz Augusto von Dentz
02cbe2d231 bthost: Fix running request callbacks for remote requests
Ident are only unique per request/response pair so if a remote request
is initiated we shall not attempt to run the callback even if the ident
matches.
2020-11-13 15:12:13 -08:00
Luiz Augusto von Dentz
9203358692 btdev: Rework command handling
This create command tables per version/supported command bits to make
it easier to keep them in sync.
2020-11-13 15:12:13 -08:00
Luiz Augusto von Dentz
2df57e5e4c emulator: Return error for ext adv feature not supported
This return an error if LE Set Extended Advertising Enable is used with
unsupported features.
2020-11-04 15:09:19 -08:00