30 Jul, 2020

1 commit


15 Jul, 2020

1 commit

  • Add functionality to disable and remove advertising instances,
    and use that functionality in MGMT add/remove advertising calls.

    Currently, advertising is globally-disabled, i.e. all instances are
    disabled together, even if hardware offloading is available. This
    patch adds functionality to disable and remove individual adv
    instances, solving two issues:

    1. On new advertisement registration, a global disable was done, and
    then only the new instance was enabled. This meant only the newest
    instance was actually enabled.

    2. On advertisement removal, the structure was removed, but the instance
    was never disabled or removed, which is incorrect with hardware offload
    support.

    Signed-off-by: Daniel Winkler
    Reviewed-by: Shyh-In Hwang
    Reviewed-by: Alain Michaud
    Signed-off-by: Marcel Holtmann

    Daniel Winkler
     

12 Mar, 2020

1 commit


06 Jul, 2019

1 commit


06 May, 2019

1 commit

  • This commit makes the kernel not send the next queued HCI command until
    a command complete arrives for the last HCI command sent to the
    controller. This change avoids a problem with some buggy controllers
    (seen on two SKUs of QCA9377) that send an extra command complete event
    for the previous command after the kernel had already sent a new HCI
    command to the controller.

    The problem was reproduced when starting an active scanning procedure,
    where an extra command complete event arrives for the LE_SET_RANDOM_ADDR
    command. When this happends the kernel ends up not processing the
    command complete for the following commmand, LE_SET_SCAN_PARAM, and
    ultimately behaving as if a passive scanning procedure was being
    performed, when in fact controller is performing an active scanning
    procedure. This makes it impossible to discover BLE devices as no device
    found events are sent to userspace.

    This problem is reproducible on 100% of the attempts on the affected
    controllers. The extra command complete event can be seen at timestamp
    27.420131 on the btmon logs bellow.

    Bluetooth monitor ver 5.50
    = Note: Linux version 5.0.0+ (x86_64) 0.352340
    = Note: Bluetooth subsystem version 2.22 0.352343
    = New Index: 80:C5:F2:8F:87:84 (Primary,USB,hci0) [hci0] 0.352344
    = Open Index: 80:C5:F2:8F:87:84 [hci0] 0.352345
    = Index Info: 80:C5:F2:8F:87:84 (Qualcomm) [hci0] 0.352346
    @ MGMT Open: bluetoothd (privileged) version 1.14 {0x0001} 0.352347
    @ MGMT Open: btmon (privileged) version 1.14 {0x0002} 0.352366
    @ MGMT Open: btmgmt (privileged) version 1.14 {0x0003} 27.302164
    @ MGMT Command: Start Discovery (0x0023) plen 1 {0x0003} [hci0] 27.302310
    Address type: 0x06
    LE Public
    LE Random
    < HCI Command: LE Set Random Address (0x08|0x0005) plen 6 #1 [hci0] 27.302496
    Address: 15:60:F2:91:B2:24 (Non-Resolvable)
    > HCI Event: Command Complete (0x0e) plen 4 #2 [hci0] 27.419117
    LE Set Random Address (0x08|0x0005) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7 #3 [hci0] 27.419244
    Type: Active (0x01)
    Interval: 11.250 msec (0x0012)
    Window: 11.250 msec (0x0012)
    Own address type: Random (0x01)
    Filter policy: Accept all advertisement (0x00)
    > HCI Event: Command Complete (0x0e) plen 4 #4 [hci0] 27.420131
    LE Set Random Address (0x08|0x0005) ncmd 1
    Status: Success (0x00)
    < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2 #5 [hci0] 27.420259
    Scanning: Enabled (0x01)
    Filter duplicates: Enabled (0x01)
    > HCI Event: Command Complete (0x0e) plen 4 #6 [hci0] 27.420969
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    Status: Success (0x00)
    > HCI Event: Command Complete (0x0e) plen 4 #7 [hci0] 27.421983
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    Status: Success (0x00)
    @ MGMT Event: Command Complete (0x0001) plen 4 {0x0003} [hci0] 27.422059
    Start Discovery (0x0023) plen 1
    Status: Success (0x00)
    Address type: 0x06
    LE Public
    LE Random
    @ MGMT Event: Discovering (0x0013) plen 2 {0x0003} [hci0] 27.422067
    Address type: 0x06
    LE Public
    LE Random
    Discovery: Enabled (0x01)
    @ MGMT Event: Discovering (0x0013) plen 2 {0x0002} [hci0] 27.422067
    Address type: 0x06
    LE Public
    LE Random
    Discovery: Enabled (0x01)
    @ MGMT Event: Discovering (0x0013) plen 2 {0x0001} [hci0] 27.422067
    Address type: 0x06
    LE Public
    LE Random
    Discovery: Enabled (0x01)

    Signed-off-by: João Paulo Rechi Vita
    Signed-off-by: Marcel Holtmann

    João Paulo Rechi Vita
     

30 Jul, 2018

4 commits

  • This basically sets the random address for the adv instance
    Random address can be set only if the instance is created which
    is done in Set ext adv param.

    Random address and rpa expire timer and flags have been added
    to adv instance which will be used when the respective
    instance is scheduled.

    This introduces a hci_get_random_address() which returns the
    own address type and random address (rpa or nrpa) based
    on the instance flags and hdev flags. New function is required
    since own address type should be known before setting adv params
    but address can be set only after setting params.

    < HCI Command: LE Set Advertising Set Random Address (0x08|0x0035) plen 7
    Advertising handle: 0x00
    Advertising random address: 3C:8E:56:9B:77:84 (OUI 3C-8E-56)
    > HCI Event: Command Complete (0x0e) plen 4
    LE Set Advertising Set Random Address (0x08|0x0035) ncmd 1
    Status: Success (0x00)

    Signed-off-by: Jaganath Kanakkassery
    Signed-off-by: Marcel Holtmann

    Jaganath Kanakkassery
     
  • If ext adv is enabled then use ext adv to disable as well.
    Also remove the adv set during LE disable.

    < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 2
    Extended advertising: Disabled (0x00)
    Number of sets: Disable all sets (0x00)
    > HCI Event: Command Complete (0x0e) plen 4
    LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
    Status: Success (0x00)

    Signed-off-by: Jaganath Kanakkassery
    Signed-off-by: Marcel Holtmann

    Jaganath Kanakkassery
     
  • This patch implements Set Ext Adv data and Set Ext Scan rsp data
    if controller support extended advertising.

    Currently the operation is set as Complete data and fragment
    preference is set as no fragment

    < HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 35
    Handle: 0x00
    Operation: Complete extended advertising data (0x03)
    Fragment preference: Minimize fragmentation (0x01)
    Data length: 0x15
    16-bit Service UUIDs (complete): 2 entries
    Heart Rate (0x180d)
    Battery Service (0x180f)
    Name (complete): Test LE
    Company: Google (224)
    Data: 0102
    > HCI Event: Command Complete (0x0e) plen 4
    LE Set Extended Advertising Data (0x08|0x0037) ncmd 1
    Status: Success (0x00)

    Signed-off-by: Jaganath Kanakkassery
    Signed-off-by: Marcel Holtmann

    Jaganath Kanakkassery
     
  • This patch basically replaces legacy adv with extended adv
    based on the controller support. Currently there is no
    design change. ie only one adv set will be enabled at a time.

    This also adds tx_power in instance and store whatever returns
    from Set_ext_parameter, use the same in adv data as well.
    For instance 0 tx_power is stored in hdev only.

    < HCI Command: LE Set Extended Advertising Parameters (0x08|0x0036) plen 25
    Handle: 0x00
    Properties: 0x0010
    Use legacy advertising PDUs: ADV_NONCONN_IND
    Min advertising interval: 1280.000 msec (0x0800)
    Max advertising interval: 1280.000 msec (0x0800)
    Channel map: 37, 38, 39 (0x07)
    Own address type: Random (0x01)
    Peer address type: Public (0x00)
    Peer address: 00:00:00:00:00:00 (OUI 00-00-00)
    Filter policy: Allow Scan Request from Any, Allow Connect Request from Any (0x00)
    TX power: 127 dbm (0x7f)
    Primary PHY: LE 1M (0x01)
    Secondary max skip: 0x00
    Secondary PHY: LE 1M (0x01)
    SID: 0x00
    Scan request notifications: Disabled (0x00)
    > HCI Event: Command Complete (0x0e) plen 5
    LE Set Extended Advertising Parameters (0x08|0x0036) ncmd 1
    Status: Success (0x00)
    TX power (selected): 7 dbm (0x07)
    < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 6
    Extended advertising: Enabled (0x01)
    Number of sets: 1 (0x01)
    Entry 0
    Handle: 0x00
    Duration: 0 ms (0x00)
    Max ext adv events: 0
    > HCI Event: Command Complete (0x0e) plen 4
    LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2
    Status: Success (0x00)

    Signed-off-by: Jaganath Kanakkassery
    Signed-off-by: Marcel Holtmann

    Jaganath Kanakkassery
     

29 Oct, 2017

1 commit

  • If command is added to req then it should be freed in case if
    hdev is down or HCI_ADVERTISING flag is set.

    This introduces a helper in hci_request to purge the cmd_q
    to make cmd_q internal to hci_request which is used to fix
    the leak.

    This also replace accessing of cmd_q in hci_conn with the
    new helper.

    Signed-off-by: Jaganath Kanakkassery
    Signed-off-by: Marcel Holtmann

    Jaganath Kanakkassery
     

20 Oct, 2016

1 commit


06 Oct, 2016

1 commit


20 Sep, 2016

1 commit

  • When an Advertising Instance is removed, the Advertising Removed event
    shouldn't be sent to the same socket that issued the Remove
    Advertising command (it gets a command complete event instead). The
    mgmt_advertising_removed() function already has a parameter for
    skipping a specific socket, but there was no code to propagate the
    right value to this parameter. This patch fixes the issue by making
    sure the intermediate hci_req_clear_adv_instance() function gets the
    socket pointer.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     

11 Mar, 2016

1 commit

  • Introduce a limited privacy mode indicated by value 0x02 to the mgmt
    Set Privacy command.

    With value 0x02 the kernel will use privacy mode with a resolvable
    private address. In case the controller is bondable and discoverable
    the identity address will be used.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     

10 Dec, 2015

8 commits

  • We can simplify a lot of code by making sure hdev->cur_adv_instance is
    always up-to-date. This allows e.g. the removal of the
    get_current_adv_instance() helper function and the special
    HCI_ADV_CURRENT value. This patch also makes selecting instance 0x00
    explicit in the various calls where advertising instances aren't
    enabled, e.g. when HCI_ADVERTISING is set or we've just finished
    enabling LE.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • The request to update HCI during power on is always coming either from
    hdev->req_workqueue or through an ioctl, so it's safe to use
    hci_req_sync for it. This way we also eliminate potential races with
    incoming mgmt commands or other actions while powering on.

    Part of this refactoring is the splitting of mgmt_powered() into
    mgmt_power_on() and __mgmt_power_off() functions. The main reason is
    the different requirements as far as hdev locking is concerned, as
    highlighted with the __ prefix of the power off API.

    Since the power on in the case of clearing the AUTO_OFF flag cannot be
    done synchronously in the set_powered mgmt handler, the hci_power_on
    work callback is extended to cover this (which also simplifies the
    set_powered helper a lot).

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • We'll soon need this both in hci_request.c and mgmt.c so move it to
    hci_request.c as a generic helper.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • We'll soon need to update the EIR both from hci_request.c and mgmt.c
    so move update_eir() as a more generic request helper to
    hci_request.c.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • We'll soon need this both from hci_request.c and mgmt.c so move it as
    a request helper function to hci_request.c.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • The Class of Device needs to be changed e.g. for limited discoverable
    mode. In preparation of moving the discoverable mode to hci_request.c
    and hdev->req_workqueue, move the Class of Device helpers there first.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • This paves the way for eventually performing advertising changes
    through the hdev->req_workqueue. Some new APIs need to be exposed from
    mgmt.c to hci_request.c and vice-versa, but many of them will go away
    once hdev->req_workqueue gets used.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     
  • Since Add/Remove Device perform the page scan updates independently
    from the HCI command completion we've introduced a potential race when
    multiple mgmt commands are queued. Doing the page scan updates through
    the req_workqueue ensures that the state changes are performed in a
    race-free manner.

    At the same time, to make the request helper more widely usable,
    extend it to also cover Inquiry Scan changes since those are behind
    the same HCI command. This is also reflected in the new name of the
    API as well as the work struct name.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     

20 Nov, 2015

8 commits


22 Oct, 2015

1 commit


02 Apr, 2015

1 commit

  • This patch adds a second possible callback for HCI requests where the
    callback will receive the full skb of the last successfully completed
    HCI command. This API is useful for cases where we want to use a request
    to read some data and the existing hci_event.c handlers do not store it
    e.g. in the hci_dev struct.

    The reason the patch is a bit bigger than just adding the new API is
    because the hci_req_cmd_complete() functions required some refactoring
    to enable it: now hci_req_cmd_complete() is simply used to request the
    callback pointers if any, and the actual calling of them happens from a
    single place at the end of hci_event_packet(). The reason for this is
    that we need to pass the original skb (without any skb_pull, etc
    modifications done to it) and it's simplest to keep track of it within
    the hci_event_packet() function.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     

20 Dec, 2014

1 commit

  • Many places using hci_update_background_scan() try to synchronize
    whatever they're doing with the help of hci_request callbacks. However,
    since the hci_update_background_scan() function hasn't so far accepted a
    hci_request pointer any commands triggered by it have been left out by
    the synchronization. This patch modifies the API in a similar way as was
    done for hci_update_page_scan, i.e. there's a variant that takes a
    hci_request and another one that takes a hci_dev.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg
     

19 Dec, 2014

1 commit

  • None of the hci_request related things in net/bluetooth/hci_core.h are
    needed anywhere outside of the core bluetooth module. This patch creates
    a new net/bluetooth/hci_request.c file with its corresponding h-file and
    moves the functionality there from hci_core.c and hci_core.h.

    Signed-off-by: Johan Hedberg
    Signed-off-by: Marcel Holtmann

    Johan Hedberg