Use HCI device type to determine suitability of HCI commands
Subsystems (2)
cover Use HCI device type to determine suitability of HCI commands
BlueZ assumes that HCI devices are either BR/EDR radios, or "RAW" (via HCI_RAW). At present, alternate radios are handled as RAW (reference Marcel's 943da25d9 kernel commit). More subtlety in BlueZ is useful as AMP support is enhanced.
These patches remove the need to treat non-BR/EDR HCI devices as "RAW."
Cheers,
David
Signature · 3 lines
David Scherba Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH 1/2 Remove non-functional hci_devinfo calls in init_device()
--- plugins/hciops.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
plugins/hciops.c +0 -6
@@ -175,12 +175,6 @@ static void init_device(int index) goto fail; } -if (hci_devinfo (index, &di) <0 ) - goto fail; - -if (hci_test_bit (HCI_RAW , &di.flags)) - goto done; - done:hci_close_dev (dd);exit (0 );
Signature · 5 lines
1.7.0 -- David Scherba Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 1/2] Remove non-functional hci_devinfo calls in init_device()
Hi David,
Quoted 11 lines · David Scherba
--- plugins/hciops.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)plugins/hciops.c +0
-0@@ -175,12 +175,6 @@ static void init_device(int index) goto fail; }
plugins/hciops.c static void init_device(int index) · line 180
Quoted 10 lines
plugins/hciops.c +0
-6-if (hci_devinfo (index, &di) <0 ) - goto fail; - -if (hci_test_bit (HCI_RAW , &di.flags)) - goto done; - done:hci_close_dev (dd);exit (0 );
Nice catch, but that's not quite enough:
plugins/hciops.c: In function ‘init_device’:plugins/hciops.c:178: error: label ‘done’ defined but not used plugins/hciops.c:125: error: unused variable ‘di’
Always check that your patch compiles cleanly with ./bootstrap-configure before submitting upstream.
Johan
Re: [PATCH 1/2] Remove non-functional hci_devinfo calls in init_device()
Quoted 8 lines · Johan Hedberg
Nice catch, but that's not quite enough:
plugins/hciops.c: In function ‘init_device’:plugins/hciops.c:178: error: label ‘done’ defined but not usedplugins/hciops.c:125: error: unused variable ‘di’Always check that your patch compiles cleanly with ./bootstrap-configure before submitting upstream.
Johan--
Thanks for the tips--I had split-up a combined patch and neglected to ensure clean compilation and spacing after the split :-(.
New patch versions coming your way...
Cheers,
David
Signature · 3 lines
David Scherba Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH 2/2 Use HCI device type to gate BR/EDR-specific HCI commands
In reply to David ScherbaUse the hci_dev_info structure member 'type' to classify whether a HCI device is BR/EDR, or not. If not, gate BR/EDR-specific HCI commands.
--- lib/hci_lib.h | 5 +++++ plugins/hciops.c | 23 +++++++++++++++-------- src/adapter.c | 3 ++- src/security.c | 6 ++++-- 4 files changed, 26 insertions(+), 11 deletions(-)
lib/hci_lib.h +5 -0
@@ -169,6 +169,11 @@ static inline int hci_test_bit(int nr, void *addr)return *((uint32_t *) addr + (nr >>5 )) & (1 << (nr &31 )); } +static inline int is_bredr_hci_device_type (uint8_t type) +{ +return (type >>4 ) ==HCI_BREDR ; +} +/* HCI filter tools */ static inline void hci_filter_clear (struct hci_filter *f) {
plugins/hciops.c +15 -8
@@ -85,7 +85,8 @@ static void device_devup_setup(int index)if (hci_devinfo (index, &di) <0 )return ; -if (hci_test_bit (HCI_RAW , &di.flags)) +if (!is_bredr_hci_device_type (di.type) || +hci_test_bit (HCI_RAW , &di.flags))return ; dd =hci_open_dev (index);
@@ -160,12 +161,17 @@ static void init_device(int index) index, strerror(err), err); } -/* Set link policy */ - dr.dev_opt = main_opts.link_policy; -if (ioctl (dd,HCISETLINKPOL , (unsigned long ) &dr) <0 && - errno !=ENETDOWN ) { -error ("Can't set link policy on hci%d: %s (%d)" , - index,strerror (errno), errno); +/* Set link policy for BR/EDR HCI devices */ +if (hci_devinfo (index, &di) <0 ) + goto fail; + +if (is_bredr_hci_device_type (di.type)) { + dr.dev_opt = main_opts.link_policy; +if (ioctl (dd,HCISETLINKPOL , (unsigned long ) &dr) <0 && + errno !=ENETDOWN ) { +error ("Can't set link policy on hci%d: %s (%d)" , + index,strerror (errno), errno); + } }/* Start HCI device */
@@ -198,7 +204,8 @@ static void device_devreg_setup(int index) devup =hci_test_bit (HCI_UP , &di.flags); -if (!hci_test_bit (HCI_RAW , &di.flags)) +if (is_bredr_hci_device_type (di.type) && + !hci_test_bit (HCI_RAW , &di.flags))manager_register_adapter (index, devup); }
src/adapter.c +2 -1
@@ -2314,7 +2314,8 @@ int adapter_start(struct btd_adapter *adapter)if (hci_devinfo (adapter->dev_id, &di) <0 )return -errno; -if (hci_test_bit (HCI_RAW , &di.flags)) { +if (!is_bredr_hci_device_type (di.type) || +hci_test_bit (HCI_RAW , &di.flags)) { dev->ignore =1 ;return -1 ; }
src/security.c +4 -2
@@ -999,7 +999,8 @@ static gboolean io_security_event(GIOChannel *chan, GIOCondition cond,ioctl (dev,HCIGETDEVINFO , (void *) di); -if (hci_test_bit (HCI_RAW , &di->flags)) +if (!is_bredr_hci_device_type (di->type) || +hci_test_bit (HCI_RAW , &di->flags))return TRUE;switch (eh->evt) {
@@ -1185,7 +1186,8 @@ void start_security_manager(int hdev) io_data[hdev].channel = chan; io_data[hdev].pin_length =-1 ; -if (hci_test_bit (HCI_RAW , &di->flags)) +if (!is_bredr_hci_device_type (di->type) || +hci_test_bit (HCI_RAW , &di->flags))return ;bacpy (&cp.bdaddr,BDADDR_ANY );
Signature · 5 lines
1.7.0 -- David Scherba Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 2/2] Use HCI device type to gate BR/EDR-specific HCI commands
Hi David,
Quoted 1 line · David Scherba
+static inline int
is_bredr_hci_device_type(uint8_t type)
Could you just call this ignore_device() which combines the AMP and RAW checks.
lib/hci_lib.h static inline int hci_test_bit(int nr, void *addr) · line 175
Quoted 3 lines
lib/hci_lib.h +3
-0+{ +return (type >>4 ) ==HCI_BREDR ; +}
Looks like the indentation is wrong inside the function (two spaces instead of a tab).
plugins/hciops.c static void device_devup_setup(int index) · line 89
Quoted 3 lines
plugins/hciops.c +2
-1-if (hci_test_bit (HCI_RAW , &di.flags)) +if (!is_bredr_hci_device_type (di.type) || +hci_test_bit (HCI_RAW , &di.flags))
No spaces+tabs mixed indentation please. The second line should be indented by at least two tabs more than the line above it (as many tabs as you can as long as the line doesn't go beyond 79 characters). OTOH, the second line goes away completely if you do the ignore_device simplification as proposed above.
plugins/hciops.c static void device_devreg_setup(int index) · line 208
Quoted 3 lines
plugins/hciops.c +2
-1-if (!hci_test_bit (HCI_RAW , &di.flags)) +if (is_bredr_hci_device_type (di.type) && + !hci_test_bit (HCI_RAW , &di.flags))
Same here.
src/adapter.c int adapter_start(struct btd_adapter *adapter) · line 2318
Quoted 3 lines
src/adapter.c +2
-1-if (hci_test_bit (HCI_RAW , &di.flags)) { +if (!is_bredr_hci_device_type (di.type) || +hci_test_bit (HCI_RAW , &di.flags)) {
And here.
src/security.c static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, · line 1003
Quoted 3 lines
src/security.c +2
-1-if (hci_test_bit (HCI_RAW , &di->flags)) +if (!is_bredr_hci_device_type (di->type) || +hci_test_bit (HCI_RAW , &di->flags))
And here.
src/security.c static gboolean io_security_event(GIOChannel *chan, GIOCondition cond, · line 1003
Quoted 3 lines
src/security.c +2
-1-if (hci_test_bit (HCI_RAW , &di->flags)) +if (!is_bredr_hci_device_type (di->type) || +hci_test_bit (HCI_RAW , &di->flags))
And here.
Johan