diff mbox series

[v3,2/3] bluetooth:allow scatternet connections if supported.

Message ID 20200421155954.137391-3-alainm@chromium.org (mailing list archive)
State Accepted
Delegated to: Marcel Holtmann
Headers show
Series bluetooth:Adding driver and quirk defs for multi-role LE | expand

Commit Message

Alain Michaud April 21, 2020, 3:59 p.m. UTC
This change allows scatternet connections to be created if the
controller reports support and the HCI_QUIRK_VALID_LE_STATES indicates
that the reported LE states can be trusted.

Signed-off-by: Alain Michaud <alainm@chromium.org>
---

 net/bluetooth/hci_event.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Marcel Holtmann April 22, 2020, 5:36 p.m. UTC | #1
Hi Alain,

> This change allows scatternet connections to be created if the
> controller reports support and the HCI_QUIRK_VALID_LE_STATES indicates
> that the reported LE states can be trusted.
> 
> Signed-off-by: Alain Michaud <alainm@chromium.org>
> ---
> 
> net/bluetooth/hci_event.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 0a591be8b0ae..34cd98a1d370 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -5245,7 +5245,9 @@ static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
> 	/* Most controller will fail if we try to create new connections
> 	 * while we have an existing one in slave role.
> 	 */
> -	if (hdev->conn_hash.le_num_slave > 0)
> +	if (hdev->conn_hash.le_num_slave > 0 &&
> +	    (hdev->quirks & HCI_QUIRK_VALID_LE_STATES) == 0 ||

please use test_bit() here.

> +	     !(hdev->le_states[3] & 0x10))
> 		return NULL;

Regards

Marcel
kernel test robot April 23, 2020, 4:21 a.m. UTC | #2
Hi Alain,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on v5.7-rc2 next-20200422]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Alain-Michaud/bluetooth-Adding-driver-and-quirk-defs-for-multi-role-LE/20200423-083451
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: c6x-allyesconfig (attached as .config)
compiler: c6x-elf-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=c6x 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   net/bluetooth/hci_event.c: In function 'check_pending_le_conn':
>> net/bluetooth/hci_event.c:5291:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    5291 |  if (hdev->conn_hash.le_num_slave > 0 &&
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
    5292 |      (hdev->quirks & HCI_QUIRK_VALID_LE_STATES) == 0 ||
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +5291 net/bluetooth/hci_event.c

  5270	
  5271	/* This function requires the caller holds hdev->lock */
  5272	static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
  5273						      bdaddr_t *addr,
  5274						      u8 addr_type, u8 adv_type,
  5275						      bdaddr_t *direct_rpa)
  5276	{
  5277		struct hci_conn *conn;
  5278		struct hci_conn_params *params;
  5279	
  5280		/* If the event is not connectable don't proceed further */
  5281		if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND)
  5282			return NULL;
  5283	
  5284		/* Ignore if the device is blocked */
  5285		if (hci_bdaddr_list_lookup(&hdev->blacklist, addr, addr_type))
  5286			return NULL;
  5287	
  5288		/* Most controller will fail if we try to create new connections
  5289		 * while we have an existing one in slave role.
  5290		 */
> 5291		if (hdev->conn_hash.le_num_slave > 0 &&
  5292		    (hdev->quirks & HCI_QUIRK_VALID_LE_STATES) == 0 ||
  5293		     !(hdev->le_states[3] & 0x10))
  5294			return NULL;
  5295	
  5296		/* If we're not connectable only connect devices that we have in
  5297		 * our pend_le_conns list.
  5298		 */
  5299		params = hci_pend_le_action_lookup(&hdev->pend_le_conns, addr,
  5300						   addr_type);
  5301		if (!params)
  5302			return NULL;
  5303	
  5304		if (!params->explicit_connect) {
  5305			switch (params->auto_connect) {
  5306			case HCI_AUTO_CONN_DIRECT:
  5307				/* Only devices advertising with ADV_DIRECT_IND are
  5308				 * triggering a connection attempt. This is allowing
  5309				 * incoming connections from slave devices.
  5310				 */
  5311				if (adv_type != LE_ADV_DIRECT_IND)
  5312					return NULL;
  5313				break;
  5314			case HCI_AUTO_CONN_ALWAYS:
  5315				/* Devices advertising with ADV_IND or ADV_DIRECT_IND
  5316				 * are triggering a connection attempt. This means
  5317				 * that incoming connections from slave device are
  5318				 * accepted and also outgoing connections to slave
  5319				 * devices are established when found.
  5320				 */
  5321				break;
  5322			default:
  5323				return NULL;
  5324			}
  5325		}
  5326	
  5327		conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
  5328				      HCI_LE_AUTOCONN_TIMEOUT, HCI_ROLE_MASTER,
  5329				      direct_rpa);
  5330		if (!IS_ERR(conn)) {
  5331			/* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
  5332			 * by higher layer that tried to connect, if no then
  5333			 * store the pointer since we don't really have any
  5334			 * other owner of the object besides the params that
  5335			 * triggered it. This way we can abort the connection if
  5336			 * the parameters get removed and keep the reference
  5337			 * count consistent once the connection is established.
  5338			 */
  5339	
  5340			if (!params->explicit_connect)
  5341				params->conn = hci_conn_get(conn);
  5342	
  5343			return conn;
  5344		}
  5345	
  5346		switch (PTR_ERR(conn)) {
  5347		case -EBUSY:
  5348			/* If hci_connect() returns -EBUSY it means there is already
  5349			 * an LE connection attempt going on. Since controllers don't
  5350			 * support more than one connection attempt at the time, we
  5351			 * don't consider this an error case.
  5352			 */
  5353			break;
  5354		default:
  5355			BT_DBG("Failed to connect: err %ld", PTR_ERR(conn));
  5356			return NULL;
  5357		}
  5358	
  5359		return NULL;
  5360	}
  5361	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 0a591be8b0ae..34cd98a1d370 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -5245,7 +5245,9 @@  static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
 	/* Most controller will fail if we try to create new connections
 	 * while we have an existing one in slave role.
 	 */
-	if (hdev->conn_hash.le_num_slave > 0)
+	if (hdev->conn_hash.le_num_slave > 0 &&
+	    (hdev->quirks & HCI_QUIRK_VALID_LE_STATES) == 0 ||
+	     !(hdev->le_states[3] & 0x10))
 		return NULL;
 
 	/* If we're not connectable only connect devices that we have in