Bluetooth: Update to latest mgmt API
Subsystems (2)
cover Bluetooth: Update to latest mgmt API
Hi,
These patches update the device_found and device_connected mgmt events to correspond to the latest API. The patches should work with latest user space git. There are also some bugfixes like the persistent flags one and some cosmetic changes like the flags variable renames. Also, sorry about the slightly big patch 13/15. I tried to look into splitting it but didn't find any simple way.
Johan Hedberg (15):
Bluetooth: Fix clearing persistent flags
Bluetooth: Rename mgmt connected events to match user space
Bluetooth: Add eir_len parameter to mgmt_ev_device_found
Bluetooth: Rename eir_has_complete_name to eir_has_data_type
Bluetooth: Add missing EIR defines to hci.h
Bluetooth: Move eir_has_data_field to hci_core.h
Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
Bluetooth: Rename conn->pend to conn->flags
Bluetooth: Merge boolean members of struct hci_conn into flags
Bluetooth: Add a convenience function to check for SSP enabled
Bluetooth: Convert hdev->ssp_mode to a flag
Bluetooth: Convert hdev->out to a bool type
Bluetooth: Update device_connected and device_found events to latest API
Bluetooth: Rename hdev->flags to hdev->compat_flags
Bluetooth: Rename hdev->dev_flags to hdev-flags
drivers/bluetooth/bfusb.c | 12 +- drivers/bluetooth/bpa10x.c | 12 +- drivers/bluetooth/btmrvl_main.c | 9 +- drivers/bluetooth/btusb.c | 20 ++-- drivers/bluetooth/hci_ldisc.c | 6 +- drivers/bluetooth/hci_vhci.c | 6 +- include/net/bluetooth/hci.h | 29 ++-- include/net/bluetooth/hci_core.h | 77 +++++++++--- include/net/bluetooth/mgmt.h | 25 ++-- net/bluetooth/hci_conn.c | 50 ++++---- net/bluetooth/hci_core.c | 101 ++++++++------- net/bluetooth/hci_event.c | 264 ++++++++++++++++++++------------------ net/bluetooth/hci_sock.c | 8 +- net/bluetooth/l2cap_core.c | 2 +- net/bluetooth/mgmt.c | 166 +++++++++++++++---------- net/bluetooth/smp.c | 21 ++-- 16 files changed, 455 insertions(+), 353 deletions(-)
PATCH 1/15 Bluetooth: Fix clearing persistent flags
From: Johan Hedberg <[email protected]>
There are several other dev_flags besided HCI_MGMT that should not be cleared upon reset.
--- net/bluetooth/hci_event.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/hci_event.c +2 -2
@@ -195,8 +195,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)hci_req_complete (hdev,HCI_OP_RESET , status); -/* Reset all flags, except persistent ones like HCI_MGMT */ - hdev->dev_flags &=BIT (HCI_MGMT ); +/* Reset all flags, except persistent ones */ + hdev->dev_flags &=BIT (HCI_MGMT ) |BIT (HCI_SETUP ) |BIT (HCI_AUTO_OFF ); }static void hci_cc_write_local_name (struct hci_dev *hdev,struct sk_buff *skb)
Signature · 1 line
1.7.8.3
Re: [PATCH 01/15] Bluetooth: Fix clearing persistent flags
Hi Johan,
Quoted 7 lines
There are several other
dev_flagsbesidedHCI_MGMTthat should not be cleared upon reset.Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/hci_event.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Regards
Marcel
PATCH 2/15 Bluetooth: Rename mgmt connected events to match user space
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
User space uses device_(dis)connected instead of just (dis)connected so rename the defines and functions to match this.
--- include/net/bluetooth/hci_core.h | 6 +++--- include/net/bluetooth/mgmt.h | 4 ++-- net/bluetooth/hci_event.c | 6 +++--- net/bluetooth/mgmt.c | 12 +++++++----- 4 files changed, 15 insertions(+), 13 deletions(-)
include/net/bluetooth/hci_core.h +3 -3
@@ -896,10 +896,10 @@ int mgmt_connectable(struct hci_dev *hdev, u8 connectable);int mgmt_write_scan_failed (struct hci_dev *hdev,u8 scan,u8 status);int mgmt_new_link_key (struct hci_dev *hdev,struct link_key *key,u8 persistent); -int mgmt_connected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type, -u8 addr_type); -int mgmt_disconnected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type, +int mgmt_device_connected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type); +int mgmt_device_disconnected (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type);int mgmt_disconnect_failed (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 status);int mgmt_connect_failed (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 status);
include/net/bluetooth/mgmt.h +2 -2
@@ -328,9 +328,9 @@ struct mgmt_ev_new_link_key {struct mgmt_link_key_info key; } __packed; -#define MGMT_EV_CONNECTED 0x000A +#define MGMT_EV_DEVICE_CONNECTED 0x000A -#define MGMT_EV_DISCONNECTED 0x000B +#define MGMT_EV_DEVICE_DISCONNECTED 0x000B#define MGMT_EV_CONNECT_FAILED 0x000Cstruct mgmt_ev_connect_failed {
net/bluetooth/hci_event.c +3 -3
@@ -1643,7 +1643,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s conn->state =BT_CONFIG ;hci_conn_hold (conn); conn->disc_timeout =HCI_DISCONN_TIMEOUT ; -mgmt_connected (hdev, &ev->bdaddr, conn->type, +mgmt_device_connected (hdev, &ev->bdaddr, conn->type, conn->dst_type); }else conn->state =BT_CONNECTED ;
@@ -1789,7 +1789,7 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buffif (ev->status !=0 )mgmt_disconnect_failed (hdev, &conn->dst, ev->status);else -mgmt_disconnected (hdev, &conn->dst, conn->type, +mgmt_device_disconnected (hdev, &conn->dst, conn->type, conn->dst_type); }
@@ -3188,7 +3188,7 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff goto unlock; } -mgmt_connected (hdev, &ev->bdaddr, conn->type, conn->dst_type); +mgmt_device_connected (hdev, &ev->bdaddr, conn->type, conn->dst_type); conn->sec_level =BT_SECURITY_LOW ; conn->handle =__le16_to_cpu (ev->handle);
net/bluetooth/mgmt.c +7 -5
@@ -2464,7 +2464,7 @@ int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,return mgmt_event (MGMT_EV_NEW_LINK_KEY , hdev, &ev,sizeof (ev),NULL ); } -int mgmt_connected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type, +int mgmt_device_connected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type) {struct mgmt_addr_info ev;
@@ -2472,7 +2472,8 @@ int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,bacpy (&ev.bdaddr, bdaddr); ev.type =link_to_mgmt (link_type, addr_type); -return mgmt_event (MGMT_EV_CONNECTED , hdev, &ev,sizeof (ev),NULL ); +return mgmt_event (MGMT_EV_DEVICE_CONNECTED , hdev, &ev,sizeof (ev), +NULL ); }static void disconnect_rsp (struct pending_cmd *cmd,void *data)
@@ -2509,8 +2510,8 @@ static void remove_keys_rsp(struct pending_cmd *cmd, void *data)mgmt_pending_remove (cmd); } -int mgmt_disconnected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type, -u8 addr_type) +int mgmt_device_disconnected (struct hci_dev *hdev,bdaddr_t *bdaddr, +u8 link_type,u8 addr_type) {struct mgmt_addr_info ev;struct sock *sk =NULL ;
@@ -2521,7 +2522,8 @@ int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,bacpy (&ev.bdaddr, bdaddr); ev.type =link_to_mgmt (link_type, addr_type); - err =mgmt_event (MGMT_EV_DISCONNECTED , hdev, &ev,sizeof (ev), sk); + err =mgmt_event (MGMT_EV_DEVICE_DISCONNECTED , hdev, &ev,sizeof (ev), + sk);if (sk)sock_put (sk);
Signature · 1 line
1.7.8.3
Re: [PATCH 02/15] Bluetooth: Rename mgmt connected events to match user space
Hi Johan,
Quoted 10 lines
User space uses device_(dis)connected instead of just (dis)connected so rename the defines and functions to match this.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 6 +++--- include/net/bluetooth/mgmt.h | 4 ++-- net/bluetooth/hci_event.c | 6 +++--- net/bluetooth/mgmt.c | 12 +++++++----- 4 files changed, 15 insertions(+), 13 deletions(-)
Regards
Marcel
PATCH 3/15 Bluetooth: Add eir_len parameter to mgmt_ev_device_found
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This patch add a two byte eir_len parameter mgmt_ev_device_found. Since it's unlikely that the data will in the short term be much bigger than conventional EIR lengths just use a small stack based buffer for now to avoid dynamic memory allocation & freeing.
--- include/net/bluetooth/hci_core.h | 2 +- include/net/bluetooth/mgmt.h | 3 ++- net/bluetooth/mgmt.c | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 15 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
@@ -925,7 +925,7 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, u8 *randomizer, u8 status);int mgmt_device_found (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 *dev_class,s8 rssi, -u8 cfm_name,u8 *eir,u8 eir_len); +u8 cfm_name,u8 *eir,u16 eir_len);int mgmt_remote_name (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 *name);int mgmt_start_discovery_failed (struct hci_dev *hdev,u8 status);int mgmt_stop_discovery_failed (struct hci_dev *hdev,u8 status);
include/net/bluetooth/mgmt.h +2 -1
@@ -368,7 +368,8 @@ struct mgmt_ev_device_found {__u8 dev_class[3 ];__s8 rssi;__u8 confirm_name; -__u8 eir[HCI_MAX_EIR_LENGTH ]; +__le16 eir_len; +__u8 eir[0 ]; } __packed;#define MGMT_EV_REMOTE_NAME 0x0012
net/bluetooth/mgmt.c +15 -13
@@ -2782,27 +2782,29 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,int mgmt_device_found (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 *dev_class,s8 rssi, -u8 cfm_name,u8 *eir,u8 eir_len) +u8 cfm_name,u8 *eir,u16 eir_len) { -struct mgmt_ev_device_found ev; +char buf[512 ]; +struct mgmt_ev_device_found *ev = (void *) buf; +size_t ev_size =sizeof (*ev) + eir_len; -if (eir_len >sizeof (ev.eir)) +if (ev_size >sizeof (buf))return -EINVAL ; -memset (&ev,0 ,sizeof (ev)); +bacpy (&ev->addr.bdaddr, bdaddr); + ev->addr.type =link_to_mgmt (link_type, addr_type); + ev->rssi = rssi; + ev->confirm_name = cfm_name; -bacpy (&ev.addr.bdaddr, bdaddr); - ev.addr.type =link_to_mgmt (link_type, addr_type); - ev.rssi = rssi; - ev.confirm_name = cfm_name; - -if (eir) -memcpy (ev.eir, eir, eir_len); +if (eir_len >0 ) { +put_unaligned_le16 (eir_len, &ev->eir_len); +memcpy (ev->eir, eir, eir_len); + }if (dev_class) -memcpy (ev.dev_class, dev_class,sizeof (ev.dev_class)); +memcpy (ev->dev_class, dev_class,sizeof (ev->dev_class)); -return mgmt_event (MGMT_EV_DEVICE_FOUND , hdev, &ev,sizeof (ev),NULL ); +return mgmt_event (MGMT_EV_DEVICE_FOUND , hdev, ev, ev_size,NULL ); }int mgmt_remote_name (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 *name)
Signature · 1 line
1.7.8.3
Re: [PATCH 03/15] Bluetooth: Add eir_len parameter to mgmt_ev_device_found
Hi Johan,
Quoted 11 lines
This patch add a two byte
eir_lenparametermgmt_ev_device_found. Since it's unlikely that the data will in the short term be much bigger than conventional EIR lengths just use a small stack based buffer for now to avoid dynamic memory allocation & freeing.Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 2 +- include/net/bluetooth/mgmt.h | 3 ++- net/bluetooth/mgmt.c | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 15 deletions(-)
Regards
Marcel
PATCH 4/15 Bluetooth: Rename eir_has_complete_name to eir_has_data_type
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This allows for other uses such as checking for an embedded class of device value in order to decide whether to append the class or not.
--- net/bluetooth/hci_event.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
net/bluetooth/hci_event.c +5 -4
@@ -2842,7 +2842,7 @@ static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *sBT_DBG ("%s status %d" , hdev->name, ev->status); } -static inline bool eir_has_complete_name (u8 *data,size_t data_len) +static inline bool eir_has_data_type (u8 *data,size_t data_len,u8 type) {u8 field_len;size_t parsed;
@@ -2858,7 +2858,7 @@ static inline bool eir_has_complete_name(u8 *data, size_t data_len)if (parsed > data_len)break ; -if (data[1 ] ==EIR_NAME_COMPLETE ) +if (data[1 ] == type)return true; data += field_len +1 ;
@@ -2893,8 +2893,9 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct data.ssp_mode =0x01 ;if (test_bit (HCI_MGMT , &hdev->dev_flags)) - name_known =eir_has_complete_name (info->data, -sizeof (info->data)); + name_known =eir_has_data_type (info->data, +sizeof (info->data), +EIR_NAME_COMPLETE );else name_known = true;
Signature · 1 line
1.7.8.3
Re: [PATCH 04/15] Bluetooth: Rename eir_has_complete_name to eir_has_data_type
Hi Johan,
Quoted 7 lines
This allows for other uses such as checking for an embedded class of device value in order to decide whether to append the class or not.
Signed-off-by Johan Hedberg <[email protected]>--- net/bluetooth/hci_event.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
Regards
Marcel
PATCH 5/15 Bluetooth: Add missing EIR defines to hci.h
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This patch adds missing EIR defines (as specified in the Bluetooth Assigned Numbers document) to hci.h.
--- include/net/bluetooth/hci.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
include/net/bluetooth/hci.h +3 -0
@@ -296,6 +296,9 @@ enum {#define EIR_NAME_SHORT 0x08/* shortened local name */ #define EIR_NAME_COMPLETE 0x09/* complete local name */ #define EIR_TX_POWER 0x0A/* transmit power level */ +#define EIR_CLASS_OF_DEV 0x0D/* Class of Device */ +#define EIR_SSP_HASH_C 0x0E/* Simple Pairing Hash C */ +#define EIR_SSP_RAND_R 0x0F/* Simple Pairing Randomizer R */ #define EIR_DEVICE_ID 0x10/* device ID */ /* ----- HCI Commands ---- */
Signature · 1 line
1.7.8.3
Re: [PATCH 05/15] Bluetooth: Add missing EIR defines to hci.h
Hi Johan,
Quoted 7 lines
This patch adds missing EIR defines (as specified in the Bluetooth Assigned Numbers document) to
hci.h.Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
Regards
Marcel
PATCH 6/15 Bluetooth: Move eir_has_data_field to hci_core.h
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This makes the function accessible from all places it's needed (e.g. mgmt.c and hci_event.c).
--- include/net/bluetooth/hci_core.h | 25 +++++++++++++++++++++++++ net/bluetooth/hci_event.c | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-)
include/net/bluetooth/hci_core.h +25 -0
@@ -868,6 +868,31 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,read_unlock (&hci_cb_list_lock); } +static inline bool eir_has_data_type (u8 *data,size_t data_len,u8 type) +{ +u8 field_len; +size_t parsed; + +for (parsed =0 ; parsed < data_len -1 ; parsed += field_len) { + field_len = data[0 ]; + +if (field_len ==0 ) +break ; + + parsed += field_len +1 ; + +if (parsed > data_len) +break ; + +if (data[1 ] == type) +return true; + + data += field_len +1 ; + } + +return false; +} +int hci_register_cb (struct hci_cb *hcb);int hci_unregister_cb (struct hci_cb *hcb);
net/bluetooth/hci_event.c +0 -25
@@ -2842,31 +2842,6 @@ static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *sBT_DBG ("%s status %d" , hdev->name, ev->status); } -static inline bool eir_has_data_type (u8 *data,size_t data_len,u8 type) -{ -u8 field_len; -size_t parsed; - -for (parsed =0 ; parsed < data_len -1 ; parsed += field_len) { - field_len = data[0 ]; - -if (field_len ==0 ) -break ; - - parsed += field_len +1 ; - -if (parsed > data_len) -break ; - -if (data[1 ] == type) -return true; - - data += field_len +1 ; - } - -return false; -} -static inline void hci_extended_inquiry_result_evt (struct hci_dev *hdev,struct sk_buff *skb) {struct inquiry_data data;
Signature · 1 line
1.7.8.3
Re: [PATCH 06/15] Bluetooth: Move eir_has_data_field to hci_core.h
Hi Johan,
Quoted 8 lines
This makes the function accessible from all places it's needed (e.g.
mgmt.candhci_event.c).Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 25 +++++++++++++++++++++++++ net/bluetooth/hci_event.c | 25 ------------------------- 2 files changed, 25 insertions(+), 25 deletions(-)
Regards
Marcel
PATCH 7/15 Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
There's no need to have a separate device class field since the same information can be encoded into the EIR data.
--- include/net/bluetooth/hci_core.h | 11 +++++++++++ include/net/bluetooth/mgmt.h | 1 - net/bluetooth/mgmt.c | 20 +++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-)
include/net/bluetooth/hci_core.h +11 -0
@@ -893,6 +893,17 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)return false; } +static inline u16 eir_append_data (u8 *eir,u16 eir_len,u8 type,u8 *data, +u16 data_len) +{ + eir[eir_len++] =sizeof (type) + data_len; + eir[eir_len++] = type; +memcpy (&eir[eir_len], data, data_len); + eir_len += data_len; + +return eir_len; +} +int hci_register_cb (struct hci_cb *hcb);int hci_unregister_cb (struct hci_cb *hcb);
include/net/bluetooth/mgmt.h +0 -1
@@ -365,7 +365,6 @@ struct mgmt_ev_auth_failed {#define MGMT_EV_DEVICE_FOUND 0x0011struct mgmt_ev_device_found {struct mgmt_addr_info addr; -__u8 dev_class[3 ];__s8 rssi;__u8 confirm_name;__le16 eir_len;
net/bluetooth/mgmt.c +13 -7
@@ -2786,23 +2786,29 @@ int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, {char buf[512 ];struct mgmt_ev_device_found *ev = (void *) buf; -size_t ev_size =sizeof (*ev) + eir_len; +size_t ev_size; -if (ev_size >sizeof (buf)) +/* Leave 5 bytes for a potential CoD field */ +if (sizeof (*ev) + eir_len +5 >sizeof (buf))return -EINVAL ; +memset (buf,0 ,sizeof (buf)); +bacpy (&ev->addr.bdaddr, bdaddr); ev->addr.type =link_to_mgmt (link_type, addr_type); ev->rssi = rssi; ev->confirm_name = cfm_name; -if (eir_len >0 ) { -put_unaligned_le16 (eir_len, &ev->eir_len); +if (eir_len >0 )memcpy (ev->eir, eir, eir_len); - } -if (dev_class) -memcpy (ev->dev_class, dev_class,sizeof (ev->dev_class)); +if (dev_class && !eir_has_data_type (ev->eir, eir_len,EIR_CLASS_OF_DEV )) + eir_len =eir_append_data (ev->eir, eir_len,EIR_CLASS_OF_DEV , + dev_class,3 ); + +put_unaligned_le16 (eir_len, &ev->eir_len); + + ev_size =sizeof (*ev) + eir_len;return mgmt_event (MGMT_EV_DEVICE_FOUND , hdev, ev, ev_size,NULL ); }
Signature · 1 line
1.7.8.3
Re: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
Hi Johan,
Quoted 9 lines
There's no need to have a separate device class field since the same information can be encoded into the EIR data.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 11 +++++++++++ include/net/bluetooth/mgmt.h | 1 - net/bluetooth/mgmt.c | 20 +++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-)
Regards
Marcel
Re: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
In reply to Johan HedbergHi Johan,
include/net/bluetooth/hci_core.h static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) · line 899
Quoted 4 lines · Johan Hedberg
include/net/bluetooth/hci_core.h +4
-0+static inline u16 eir_append_data (u8 *eir,u16 eir_len,u8 type,u8 *data, + u16 data_len) +{ + eir[eir_len++] = sizeof(type) + data_len;
Isn't it better to have data_len as u8? It is impossible for a EIR or AD entry to have more than 255 octets (given the length field is one octet).
include/net/bluetooth/hci_core.h static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) · line 905
Quoted 6 lines
+ eir[eir_len++] = type;
+memcpy(&eir[eir_len], data, data_len);
+eir_len+=data_len;include/net/bluetooth/hci_core.h +3
-0+ + return eir_len; +}
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Re: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
Hi Lizardo,
Quoted 11 lines · Anderson Lizardo
Hi Johan,
include/net/bluetooth/hci_core.h static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) · line 899
Quoted 4 lines · Johan Hedberg
include/net/bluetooth/hci_core.h +4
-0+static inline u16 eir_append_data (u8 *eir,u16 eir_len,u8 type,u8 *data, + u16 data_len) +{ + eir[eir_len++] = sizeof(type) + data_len;Isn't it better to have
data_lenas u8? It is impossible for a EIR or AD entry to have more than 255 octets (given the length field is one octet).
Since we've taken up the habit of appending items to the data (such as the device class) before passing it on to user space we thought it'd be more future proof to use two octets. The mgmt messages use two octets as well. I was also initially of the opinion that one should be enough but Marcel convinced me that two is better since we're living very close to the limit and would have to break the API if at any point in the future we suddenly need more space.
Johan
Re: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
Hi Johan,
Quoted 15 lines · Johan Hedberg
Hi Lizardo,
Quoted 11 lines · Anderson Lizardo
Hi Johan,
include/net/bluetooth/hci_core.h static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) · line 899
Quoted 4 lines · Johan Hedberg
include/net/bluetooth/hci_core.h +4
-0+static inline u16 eir_append_data (u8 *eir,u16 eir_len,u8 type,u8 *data, + u16 data_len) +{ + eir[eir_len++] = sizeof(type) + data_len;Isn't it better to have
data_lenas u8? It is impossible for a EIR or AD entry to have more than 255 octets (given the length field is one octet).
Quoted 7 lines
Since we've taken up the habit of appending items to the data (such as the device class) before passing it on to user space we thought it'd be more future proof to use two octets. The mgmt messages use two octets as well. I was also initially of the opinion that one should be enough but Marcel convinced me that two is better since we're living very close to the limit and would have to break the API if at any point in the future we suddenly need more space.
While for mgmt it is ok to use two octets (I was aware of this rationale), I was referring more specifically to the snippet above, where you copy a u16 value to a u8 eir[] entry.
While you can append many EIR fields (and thus have a local EIR blob with total size greater than you would normally send over the air), each EIR field you append is still limited to 255 bytes as per spec. This means it is okay on the function above to "eir_len" be u16, but I think "data_len" is not.
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Re: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
Hi Lizardo,
Quoted 22 lines · Anderson Lizardo
Quoted 10 lines
Quoted 9 lines · Johan Hedberg
include/net/bluetooth/hci_core.h static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) · line 899
Quoted 4 lines
include/net/bluetooth/hci_core.h +4
-0+static inline u16 eir_append_data (u8 *eir,u16 eir_len,u8 type,u8 *data, + u16 data_len) +{ + eir[eir_len++] = sizeof(type) + data_len;Isn't it better to have
data_lenas u8? It is impossible for a EIR or AD entry to have more than 255 octets (given the length field is one octet).Quoted 7 lines
Since we've taken up the habit of appending items to the data (such as the device class) before passing it on to user space we thought it'd be more future proof to use two octets. The mgmt messages use two octets as well. I was also initially of the opinion that one should be enough but Marcel convinced me that two is better since we're living very close to the limit and would have to break the API if at any point in the future we suddenly need more space.
While for mgmt it is ok to use two octets (I was aware of this rationale), I was referring more specifically to the snippet above, where you copy a u16 value to a u8 eir[] entry.
Quoted 5 lines
While you can append many EIR fields (and thus have a local EIR blob with total size greater than you would normally send over the air), each EIR field you append is still limited to 255 bytes as per spec. This means it is okay on the function above to "
eir_len" be u16, but I think "data_len" is not.
Yes, you're completely right (and I should have paid more attention to what exactly you were referring to). I'll fix it.
Johan
Re: [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found
In reply to Johan HedbergHi Johan,
Quoted 17 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
There's no need to have a separate device class field since the same information can be encoded into the EIR data.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 11 +++++++++++ include/net/bluetooth/mgmt.h | 1 - net/bluetooth/mgmt.c | 20 +++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-)include/net/bluetooth/hci_core.h +0
-0
include/net/bluetooth/hci_core.h static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) · line 900
Quoted 8 lines
include/net/bluetooth/hci_core.h +5
-0@@ -893,6 +893,17 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)return false; } +static inline u16 eir_append_data (u8 *eir,u16 eir_len,u8 type,u8 *data, +u16 data_len) +{ + eir[eir_len++] =sizeof (type) + data_len; + eir[eir_len++] = type;
Would it be better to use struct eir_info/hdr and assign fields len and type? I saw already several places where this might improve readability and remove magic formulas (like "+ 2 - 1").
Best regards
Andrei Emeltchenko
PATCH 8/15 Bluetooth: Rename conn->pend to conn->flags
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
These flags can and will be used for more general purpose values than just pending state transitions so the more common name "flags" makes more sense than "pend".
--- include/net/bluetooth/hci_core.h | 6 +++--- net/bluetooth/hci_conn.c | 20 ++++++++++---------- net/bluetooth/hci_event.c | 36 ++++++++++++++++++------------------ net/bluetooth/l2cap_core.c | 2 +- net/bluetooth/smp.c | 19 +++++++++---------- 5 files changed, 41 insertions(+), 42 deletions(-)
include/net/bluetooth/hci_core.h +3 -3
@@ -300,7 +300,7 @@ struct hci_conn {__u8 io_capability;__u8 power_save;__u16 disc_timeout; -unsigned long pend; +unsigned long flags;__u8 remote_cap;__u8 remote_oob;
@@ -764,7 +764,7 @@ static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)if (conn->type !=ACL_LINK && conn->type !=LE_LINK )return ; -if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend)) +if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags))return ; encrypt = (conn->link_mode &HCI_LM_ENCRYPT ) ?0x01 :0x00 ;
@@ -805,7 +805,7 @@ static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)hci_proto_auth_cfm (conn, status); -if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend)) +if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags))return ; encrypt = (conn->link_mode &HCI_LM_ENCRYPT ) ?0x01 :0x00 ;
net/bluetooth/hci_conn.c +10 -10
@@ -337,7 +337,7 @@ static void hci_conn_enter_sniff_mode(struct hci_conn *conn)hci_send_cmd (hdev,HCI_OP_SNIFF_SUBRATE ,sizeof (cp), &cp); } -if (!test_and_set_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags)) {struct hci_cp_sniff_mode cp; cp.handle =cpu_to_le16 (conn->handle); cp.max_interval =cpu_to_le16 (hdev->sniff_max_interval);
@@ -589,9 +589,9 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 acl->power_save =1 ;hci_conn_enter_active_mode (acl,BT_POWER_FORCE_ACTIVE_ON ); -if (test_bit (HCI_CONN_MODE_CHANGE_PEND , &acl->pend)) { +if (test_bit (HCI_CONN_MODE_CHANGE_PEND , &acl->flags)) {/* defer SCO setup until mode change completed */ -set_bit (HCI_CONN_SCO_SETUP_PEND , &acl->pend); +set_bit (HCI_CONN_SCO_SETUP_PEND , &acl->flags);return sco; }
@@ -633,13 +633,13 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) conn->auth_type = auth_type; -if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->flags)) {struct hci_cp_auth_requested cp; cp.handle =cpu_to_le16 (conn->handle);hci_send_cmd (conn->hdev,HCI_OP_AUTH_REQUESTED ,sizeof (cp), &cp);if (conn->key_type !=0xff ) -set_bit (HCI_CONN_REAUTH_PEND , &conn->pend); +set_bit (HCI_CONN_REAUTH_PEND , &conn->flags); }return 0 ;
@@ -650,7 +650,7 @@ static void hci_conn_encrypt(struct hci_conn *conn) {BT_DBG ("conn %p" , conn); -if (!test_and_set_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags)) {struct hci_cp_set_conn_encrypt cp; cp.handle =cpu_to_le16 (conn->handle); cp.encrypt =0x01 ;
@@ -700,7 +700,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) goto encrypt; auth: -if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend)) +if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags))return 0 ;if (!hci_conn_auth (conn, sec_level, auth_type))
@@ -735,7 +735,7 @@ int hci_conn_change_link_key(struct hci_conn *conn) {BT_DBG ("conn %p" , conn); -if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->flags)) {struct hci_cp_change_conn_link_key cp; cp.handle =cpu_to_le16 (conn->handle); hci_send_cmd(conn->hdev, HCI_OP_CHANGE_CONN_LINK_KEY,
@@ -754,7 +754,7 @@ int hci_conn_switch_role(struct hci_conn *conn, __u8 role)if (!role && conn->link_mode &HCI_LM_MASTER )return 1 ; -if (!test_and_set_bit (HCI_CONN_RSWITCH_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_RSWITCH_PEND , &conn->flags)) {struct hci_cp_switch_role cp;bacpy (&cp.bdaddr, &conn->dst); cp.role = role;
@@ -781,7 +781,7 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)if (!conn->power_save && !force_active) goto timer; -if (!test_and_set_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags)) {struct hci_cp_exit_sniff_mode cp; cp.handle =cpu_to_le16 (conn->handle);hci_send_cmd (hdev,HCI_OP_EXIT_SNIFF_MODE ,sizeof (cp), &cp);
net/bluetooth/hci_event.c +18 -18
@@ -1344,7 +1344,7 @@ static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)if (!hci_outgoing_auth_needed (hdev, conn)) goto unlock; -if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->flags)) {struct hci_cp_auth_requested cp; cp.handle =__cpu_to_le16 (conn->handle);hci_send_cmd (hdev,HCI_OP_AUTH_REQUESTED ,sizeof (cp), &cp);
@@ -1461,9 +1461,9 @@ static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (cp->handle));if (conn) { -clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->pend); +clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags); -if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->pend)) +if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->flags))hci_sco_setup (conn, status); }
@@ -1488,9 +1488,9 @@ static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) conn =hci_conn_hash_lookup_handle (hdev,__le16_to_cpu (cp->handle));if (conn) { -clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->pend); +clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags); -if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->pend)) +if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->flags))hci_sco_setup (conn, status); }
@@ -1817,7 +1817,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *sif (!ev->status) {if (!(conn->ssp_mode >0 && hdev->ssp_mode >0 ) && -test_bit (HCI_CONN_REAUTH_PEND , &conn->pend)) { +test_bit (HCI_CONN_REAUTH_PEND , &conn->flags)) {BT_INFO ("re-auth of legacy device is not possible." ); }else { conn->link_mode |=HCI_LM_AUTH ;
@@ -1827,8 +1827,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *smgmt_auth_failed (hdev, &conn->dst, ev->status); } -clear_bit (HCI_CONN_AUTH_PEND , &conn->pend); -clear_bit (HCI_CONN_REAUTH_PEND , &conn->pend); +clear_bit (HCI_CONN_AUTH_PEND , &conn->flags); +clear_bit (HCI_CONN_REAUTH_PEND , &conn->flags);if (conn->state ==BT_CONFIG ) {if (!ev->status && hdev->ssp_mode >0 && conn->ssp_mode >0 ) {
@@ -1850,7 +1850,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *shci_conn_put (conn); } -if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend)) { +if (test_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags)) {if (!ev->status) {struct hci_cp_set_conn_encrypt cp; cp.handle = ev->handle;
@@ -1858,7 +1858,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *shci_send_cmd (hdev,HCI_OP_SET_CONN_ENCRYPT ,sizeof (cp), &cp); }else { -clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend); +clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags);hci_encrypt_cfm (conn, ev->status,0x00 ); } }
@@ -1892,7 +1892,7 @@ static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skbif (!hci_outgoing_auth_needed (hdev, conn)) goto unlock; -if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->pend)) { +if (!test_and_set_bit (HCI_CONN_AUTH_PEND , &conn->flags)) {struct hci_cp_auth_requested cp; cp.handle =__cpu_to_le16 (conn->handle);hci_send_cmd (hdev,HCI_OP_AUTH_REQUESTED ,sizeof (cp), &cp);
@@ -1923,7 +1923,7 @@ static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff * conn->link_mode &= ~HCI_LM_ENCRYPT ; } -clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->pend); +clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->flags);if (conn->state ==BT_CONFIG ) {if (!ev->status)
@@ -1952,7 +1952,7 @@ static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, structif (!ev->status) conn->link_mode |=HCI_LM_SECURE ; -clear_bit (HCI_CONN_AUTH_PEND , &conn->pend); +clear_bit (HCI_CONN_AUTH_PEND , &conn->flags);hci_key_change_cfm (conn, ev->status); }
@@ -2336,7 +2336,7 @@ static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb conn->link_mode |=HCI_LM_MASTER ; } -clear_bit (HCI_CONN_RSWITCH_PEND , &conn->pend); +clear_bit (HCI_CONN_RSWITCH_PEND , &conn->flags);hci_role_switch_cfm (conn, ev->status, ev->role); }
@@ -2474,14 +2474,14 @@ static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb conn->mode = ev->mode; conn->interval =__le16_to_cpu (ev->interval); -if (!test_and_clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->pend)) { +if (!test_and_clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags)) {if (conn->mode ==HCI_CM_ACTIVE ) conn->power_save =1 ;else conn->power_save =0 ; } -if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->pend)) +if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->flags))hci_sco_setup (conn, ev->status); }
@@ -3013,7 +3013,7 @@ static inline void hci_user_confirm_request_evt(struct hci_dev *hdev,/* If we're not the initiators request authorization to * proceed from user space (mgmt_user_confirm with * confirm_hint set to 1). */ -if (!test_bit (HCI_CONN_AUTH_PEND , &conn->pend)) { +if (!test_bit (HCI_CONN_AUTH_PEND , &conn->flags)) {BT_DBG ("Confirming auto-accept as acceptor" ); confirm_hint =1 ; goto confirm;
@@ -3074,7 +3074,7 @@ static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_* initiated the authentication. A traditional auth_complete * event gets always produced as initiator and is also mapped to * the mgmt_auth_failed event */ -if (!test_bit (HCI_CONN_AUTH_PEND , &conn->pend) && ev->status !=0 ) +if (!test_bit (HCI_CONN_AUTH_PEND , &conn->flags) && ev->status !=0 )mgmt_auth_failed (hdev, &conn->dst, ev->status);hci_conn_put (conn);
net/bluetooth/l2cap_core.c +1 -1
@@ -1020,7 +1020,7 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)if (conn->info_state &L2CAP_INFO_FEAT_MASK_REQ_SENT )__cancel_delayed_work (&conn->info_timer); -if (test_and_clear_bit (HCI_CONN_LE_SMP_PEND , &hcon->pend)) { +if (test_and_clear_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags)) {__cancel_delayed_work (&conn->security_timer);smp_chan_destroy (conn); }
net/bluetooth/smp.c +9 -10
@@ -261,7 +261,7 @@ static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send)smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), &reason); -clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->hcon->pend); +clear_bit (HCI_CONN_ENCRYPT_PEND , &conn->hcon->flags);mgmt_auth_failed (conn->hcon->hdev, conn->dst, reason);cancel_delayed_work_sync (&conn->security_timer);smp_chan_destroy (conn);
@@ -449,7 +449,7 @@ static void random_work(struct work_struct *work)memset (stk + smp->smp_key_size,0 ,SMP_MAX_ENC_KEY_SIZE - smp->smp_key_size); -if (test_and_set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->pend)) { +if (test_and_set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->flags)) { reason =SMP_UNSPECIFIED ; goto error; }
@@ -506,7 +506,7 @@ void smp_chan_destroy(struct l2cap_conn *conn) {struct smp_chan *smp = conn->smp_chan; -clear_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->pend); +clear_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->flags);if (smp->tfm)crypto_free_blkcipher (smp->tfm);
@@ -571,7 +571,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)if (conn->hcon->link_mode &HCI_LM_MASTER )return SMP_CMD_NOTSUPP ; -if (!test_and_set_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->pend)) +if (!test_and_set_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->flags)) smp =smp_chan_create (conn); smp = conn->smp_chan;
@@ -707,8 +707,7 @@ static u8 smp_ltk_encrypt(struct l2cap_conn *conn)if (!key)return 0 ; -if (test_and_set_bit (HCI_CONN_ENCRYPT_PEND , - &hcon->pend)) +if (test_and_set_bit (HCI_CONN_ENCRYPT_PEND , &hcon->flags))return 1 ; master = (void *) key->data;
@@ -733,7 +732,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)if (smp_ltk_encrypt (conn))return 0 ; -if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->pend)) +if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags))return 0 ; smp =smp_chan_create (conn);
@@ -772,7 +771,7 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level)if (smp_ltk_encrypt (conn)) goto done; -if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->pend)) +if (test_and_set_bit (HCI_CONN_LE_SMP_PEND , &hcon->flags))return 0 ; smp =smp_chan_create (conn);
@@ -908,7 +907,7 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force)BT_DBG ("conn %p force %d" , conn, force); -if (!test_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->pend)) +if (!test_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->flags))return 0 ; rsp = (void *) &smp->prsp[1 ];
@@ -982,7 +981,7 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force) }if (conn->hcon->out || force) { -clear_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->pend); +clear_bit (HCI_CONN_LE_SMP_PEND , &conn->hcon->flags);cancel_delayed_work_sync (&conn->security_timer);smp_chan_destroy (conn); }
Signature · 1 line
1.7.8.3
Re: [PATCH 08/15] Bluetooth: Rename conn->pend to conn->flags
Hi Johan,
Quoted 4 lines
These flags can and will be used for more general purpose values than just pending state transitions so the more common name "flags" makes more sense than "pend".
Quoted 8 lines
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 6 +++--- net/bluetooth/hci_conn.c | 20 ++++++++++---------- net/bluetooth/hci_event.c | 36 ++++++++++++++++++------------------ net/bluetooth/l2cap_core.c | 2 +- net/bluetooth/smp.c | 19 +++++++++---------- 5 files changed, 41 insertions(+), 42 deletions(-)
Regards
Marcel
PATCH 9/15 Bluetooth: Merge boolean members of struct hci_conn into flags
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
Now that the flags member of struct hci_conn is supposed to accommodate any boolean type values we can easily merge all boolean members into it.
--- include/net/bluetooth/hci_core.h | 6 +++--- net/bluetooth/hci_conn.c | 15 +++++++++------ net/bluetooth/hci_event.c | 21 +++++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-)
include/net/bluetooth/hci_core.h +3 -3
@@ -286,7 +286,6 @@ struct hci_conn {__u8 attempt;__u8 dev_class[3 ];__u8 features[8 ]; -__u8 ssp_mode;__u16 interval;__u16 pkt_type;__u16 link_policy;
@@ -298,12 +297,10 @@ struct hci_conn {__u8 pin_length;__u8 enc_key_size;__u8 io_capability; -__u8 power_save;__u16 disc_timeout;unsigned long flags;__u8 remote_cap; -__u8 remote_oob;__u8 remote_auth;unsigned int sent;
@@ -409,6 +406,9 @@ enum {HCI_CONN_MODE_CHANGE_PEND ,HCI_CONN_SCO_SETUP_PEND ,HCI_CONN_LE_SMP_PEND , +HCI_CONN_SSP_SUPPORT , +HCI_CONN_POWER_SAVE , + HCI_CONN_REMOTE_OOB, };static inline void hci_conn_hash_init (struct hci_dev *hdev)
net/bluetooth/hci_conn.c +9 -6
@@ -105,7 +105,8 @@ void hci_acl_connect(struct hci_conn *conn) }memcpy (conn->dev_class, ie->data.dev_class,3 ); - conn->ssp_mode = ie->data.ssp_mode; +if (ie->data.ssp_mode >0 ) +set_bit (HCI_CONN_SSP_SUPPORT , &conn->flags); } cp.pkt_type =cpu_to_le16 (conn->pkt_type);
@@ -386,7 +387,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) conn->remote_auth =0xff ; conn->key_type =0xff ; - conn->power_save =1 ; +set_bit (HCI_CONN_POWER_SAVE , &conn->flags); conn->disc_timeout =HCI_DISCONN_TIMEOUT ;switch (type) {
@@ -586,7 +587,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8if (acl->state ==BT_CONNECTED && (sco->state ==BT_OPEN || sco->state ==BT_CLOSED )) { - acl->power_save =1 ; +set_bit (HCI_CONN_POWER_SAVE , &acl->flags);hci_conn_enter_active_mode (acl,BT_POWER_FORCE_ACTIVE_ON );if (test_bit (HCI_CONN_MODE_CHANGE_PEND , &acl->flags)) {
@@ -607,7 +608,8 @@ int hci_conn_check_link_mode(struct hci_conn *conn) {BT_DBG ("conn %p" , conn); -if (conn->ssp_mode >0 && conn->hdev->ssp_mode >0 && +if (test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags) && + conn->hdev->ssp_mode >0 && !(conn->link_mode &HCI_LM_ENCRYPT ))return 0 ;
@@ -671,7 +673,8 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)/* For non 2.1 devices and low security level we don't need the link key. */ if (sec_level ==BT_SECURITY_LOW && - (!conn->ssp_mode || !conn->hdev->ssp_mode)) + (!test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags) || + !conn->hdev->ssp_mode))return 1 ;/* For other security levels we need the link key. */
@@ -778,7 +781,7 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)if (conn->mode !=HCI_CM_SNIFF ) goto timer; -if (!conn->power_save && !force_active) +if (!test_bit (HCI_CONN_POWER_SAVE , &conn->flags) && !force_active) goto timer;if (!test_and_set_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags)) {
net/bluetooth/hci_event.c +13 -8
@@ -1264,7 +1264,8 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev,/* Only request authentication for SSP connections or non-SSP * devices with sec_level HIGH or if MITM protection is requested */ -if (!(hdev->ssp_mode >0 && conn->ssp_mode >0 ) && +if (!(hdev->ssp_mode >0 && +test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)) && conn->pending_sec_level !=BT_SECURITY_HIGH && !(conn->auth_type &0x01 ))return 0 ;
@@ -1816,7 +1817,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s goto unlock;if (!ev->status) { -if (!(conn->ssp_mode >0 && hdev->ssp_mode >0 ) && +if (!(test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags) && + hdev->ssp_mode >0 ) &&test_bit (HCI_CONN_REAUTH_PEND , &conn->flags)) {BT_INFO ("re-auth of legacy device is not possible." ); }else {
@@ -1831,7 +1833,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *sclear_bit (HCI_CONN_REAUTH_PEND , &conn->flags);if (conn->state ==BT_CONFIG ) { -if (!ev->status && hdev->ssp_mode >0 && conn->ssp_mode >0 ) { +if (!ev->status && hdev->ssp_mode >0 && +test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)) {struct hci_cp_set_conn_encrypt cp; cp.handle = ev->handle; cp.encrypt =0x01 ;
@@ -2476,9 +2479,9 @@ static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skbif (!test_and_clear_bit (HCI_CONN_MODE_CHANGE_PEND , &conn->flags)) {if (conn->mode ==HCI_CM_ACTIVE ) - conn->power_save =1 ; +set_bit (HCI_CONN_POWER_SAVE , &conn->flags);else - conn->power_save =0 ; +clear_bit (HCI_CONN_POWER_SAVE , &conn->flags); }if (test_and_clear_bit (HCI_CONN_SCO_SETUP_PEND , &conn->flags))
@@ -2751,7 +2754,8 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_bif (ie) ie->data.ssp_mode = (ev->features[0 ] &0x01 ); - conn->ssp_mode = (ev->features[0 ] &0x01 ); +if (ev->features[0 ] &0x01 ) +set_bit (HCI_CONN_SSP_SUPPORT , &conn->flags); }if (conn->state !=BT_CONFIG )
@@ -2930,7 +2934,7 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff conn->auth_type =hci_get_auth_req (conn); cp.authentication = conn->auth_type; -if ((conn->out ==0x01 || conn->remote_oob ==0x01 ) && +if ((conn->out ||test_bit (HCI_CONN_REMOTE_OOB , &conn->flags)) &&hci_find_remote_oob_data (hdev, &conn->dst)) cp.oob_data =0x01 ;else
@@ -2966,8 +2970,9 @@ static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *s goto unlock; conn->remote_cap = ev->capability; - conn->remote_oob = ev->oob_data; conn->remote_auth = ev->authentication; +if (ev->oob_data) +set_bit (HCI_CONN_REMOTE_OOB , &conn->flags); unlock:hci_dev_unlock (hdev);
Signature · 1 line
1.7.8.3
Marcel Holtmann
maintainerRe: [PATCH 09/15] Bluetooth: Merge boolean members of struct hci_conn into flags
Hi Johan,
Quoted 36 lines
Now that the flags member of struct
hci_connis supposed to accommodate any boolean type values we can easily merge all boolean members into it.Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 6 +++--- net/bluetooth/hci_conn.c | 15 +++++++++------ net/bluetooth/hci_event.c | 21 +++++++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-)include/net/bluetooth/hci_core.h +0
-3@@ -286,7 +286,6 @@ struct hci_conn {__u8 attempt;__u8 dev_class[3 ];__u8 features[8 ]; -__u8 ssp_mode;__u16 interval;__u16 pkt_type;__u16 link_policy;@@ -298,12 +297,10 @@ struct hci_conn {__u8 pin_length;__u8 enc_key_size;__u8 io_capability; -__u8 power_save;__u16 disc_timeout;unsigned long flags;__u8 remote_cap; -__u8 remote_oob;__u8 remote_auth;unsigned int sent;
include/net/bluetooth/hci_core.h enum { · line 409
Quoted 4 lines
include/net/bluetooth/hci_core.h +1
-0@@ -409,6 +406,9 @@ enum {HCI_CONN_MODE_CHANGE_PEND ,HCI_CONN_SCO_SETUP_PEND ,HCI_CONN_LE_SMP_PEND , + HCI_CONN_SSP_SUPPORT,
didn't we agree on naming this SSP_ENABLED?
include/net/bluetooth/hci_core.h enum { · line 412
Quoted 3 lines
include/net/bluetooth/hci_core.h +2
-0+HCI_CONN_POWER_SAVE , + HCI_CONN_REMOTE_OOB, };
Regards
Marcel
Re: [PATCH 09/15] Bluetooth: Merge boolean members of struct hci_conn into flags
Hi Marcel,
Quoted 8 lines · Marcel Holtmann
include/net/bluetooth/hci_core.h enum { · line 409
Quoted 6 lines
include/net/bluetooth/hci_core.h +1
-0unsigned int sent;@@ -409,6 +406,9 @@ enum {HCI_CONN_MODE_CHANGE_PEND ,HCI_CONN_SCO_SETUP_PEND ,HCI_CONN_LE_SMP_PEND , + HCI_CONN_SSP_SUPPORT,didn't we agree on naming this
SSP_ENABLED?
We agreed about that for hci_dev but not for hci_conn (or then I misunderstood you). I used "support" here since it means that the remote device can support it if we have it enabled (and hence "enabled" for the hci_dev flag). But I can change it anyway you like.
Johan
Marcel Holtmann
maintainerRe: [PATCH 09/15] Bluetooth: Merge boolean members of struct hci_conn into flags
Hi Johan,
Quoted 9 lines
Quoted 8 lines
include/net/bluetooth/hci_core.h enum { · line 409
Quoted 6 lines
include/net/bluetooth/hci_core.h +1
-0unsigned int sent;@@ -409,6 +406,9 @@ enum {HCI_CONN_MODE_CHANGE_PEND ,HCI_CONN_SCO_SETUP_PEND ,HCI_CONN_LE_SMP_PEND , + HCI_CONN_SSP_SUPPORT,didn't we agree on naming this
SSP_ENABLED?
Quoted 4 lines
We agreed about that for
hci_devbut not forhci_conn(or then I misunderstood you). I used "support" here since it means that the remote device can support it if we have it enabled (and hence "enabled" for thehci_devflag). But I can change it anyway you like.
since this is the host features of the remote side, it does actually mean it is enabled. So using SSP_ENABLED is actually better.
Regards
Marcel
PATCH 10/15 Bluetooth: Add a convenience function to check for SSP enabled
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
It's a very common test to see if both the local and the remote device have SSP enabled. By creating a simple function to test this we can shorten many if-statements in the code.
--- include/net/bluetooth/hci_core.h | 7 +++++++ net/bluetooth/hci_conn.c | 8 ++------ net/bluetooth/hci_event.c | 9 +++------ 3 files changed, 12 insertions(+), 12 deletions(-)
include/net/bluetooth/hci_core.h +7 -0
@@ -411,6 +411,13 @@ enum { HCI_CONN_REMOTE_OOB, }; +static inline bool hci_conn_ssp_support (struct hci_conn *conn) +{ +struct hci_dev *hdev = conn->hdev; +return (hdev->ssp_mode >0 && +test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)); +} +static inline void hci_conn_hash_init (struct hci_dev *hdev) {struct hci_conn_hash *h = &hdev->conn_hash;
net/bluetooth/hci_conn.c +2 -6
@@ -608,9 +608,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn) {BT_DBG ("conn %p" , conn); -if (test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags) && - conn->hdev->ssp_mode >0 && - !(conn->link_mode &HCI_LM_ENCRYPT )) +if (hci_conn_ssp_support (conn) && !(conn->link_mode &HCI_LM_ENCRYPT ))return 0 ;return 1 ;
@@ -672,9 +670,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)/* For non 2.1 devices and low security level we don't need the link key. */ -if (sec_level ==BT_SECURITY_LOW && - (!test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags) || - !conn->hdev->ssp_mode)) +if (sec_level ==BT_SECURITY_LOW && !hci_conn_ssp_support (conn))return 1 ;/* For other security levels we need the link key. */
net/bluetooth/hci_event.c +3 -6
@@ -1264,8 +1264,7 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev,/* Only request authentication for SSP connections or non-SSP * devices with sec_level HIGH or if MITM protection is requested */ -if (!(hdev->ssp_mode >0 && -test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)) && +if (!hci_conn_ssp_support (conn) && conn->pending_sec_level !=BT_SECURITY_HIGH && !(conn->auth_type &0x01 ))return 0 ;
@@ -1817,8 +1816,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s goto unlock;if (!ev->status) { -if (!(test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags) && - hdev->ssp_mode >0 ) && +if (!hci_conn_ssp_support (conn) &&test_bit (HCI_CONN_REAUTH_PEND , &conn->flags)) {BT_INFO ("re-auth of legacy device is not possible." ); }else {
@@ -1833,8 +1831,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *sclear_bit (HCI_CONN_REAUTH_PEND , &conn->flags);if (conn->state ==BT_CONFIG ) { -if (!ev->status && hdev->ssp_mode >0 && -test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)) { +if (!ev->status &&hci_conn_ssp_support (conn)) {struct hci_cp_set_conn_encrypt cp; cp.handle = ev->handle; cp.encrypt =0x01 ;
Signature · 1 line
1.7.8.3
Marcel Holtmann
maintainerRe: [PATCH 10/15] Bluetooth: Add a convenience function to check for SSP enabled
Hi Johan,
Quoted 16 lines
It's a very common test to see if both the local and the remote device have SSP enabled. By creating a simple function to test this we can shorten many if-statements in the code.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 7 +++++++ net/bluetooth/hci_conn.c | 8 ++------ net/bluetooth/hci_event.c | 9 +++------ 3 files changed, 12 insertions(+), 12 deletions(-)include/net/bluetooth/hci_core.h +0
-0
include/net/bluetooth/hci_core.h enum { · line 419
Quoted 9 lines
include/net/bluetooth/hci_core.h +6
-0@@ -411,6 +411,13 @@ enum { HCI_CONN_REMOTE_OOB, }; +static inline bool hci_conn_ssp_support (struct hci_conn *conn) +{ +struct hci_dev *hdev = conn->hdev; +return (hdev->ssp_mode >0 && +test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)); +}
why is hdev->ssp_mode not converted into a flag first?
Regards
Marcel
Re: [PATCH 10/15] Bluetooth: Add a convenience function to check for SSP enabled
In reply to Johan HedbergHi Johan,
Quoted 18 lines · Johan Hedberg
From: Johan Hedberg <[email protected]>
It's a very common test to see if both the local and the remote device have SSP enabled. By creating a simple function to test this we can shorten many if-statements in the code.
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 7 +++++++ net/bluetooth/hci_conn.c | 8 ++------ net/bluetooth/hci_event.c | 9 +++------ 3 files changed, 12 insertions(+), 12 deletions(-)include/net/bluetooth/hci_core.h +0
-0
include/net/bluetooth/hci_core.h enum { · line 414
Quoted 4 lines
include/net/bluetooth/hci_core.h +1
-0@@ -411,6 +411,13 @@ enum { HCI_CONN_REMOTE_OOB, }; +static inline bool hci_conn_ssp_support (struct hci_conn *conn)
Maybe matter of taste but cold this be named hci_conn_ssp_supported ? Then in if condition below it would be seen more natural and similar to other "-ed" functions.
Best regards
Andrei Emeltchenko
Quoted 2 lines
include/net/bluetooth/hci_core.h +1
-0+if (hci_conn_ssp_support (conn) && !(conn->link_mode &HCI_LM_ENCRYPT ))return 0 ;
Re: [PATCH 10/15] Bluetooth: Add a convenience function to check for SSP enabled
Hi Andrei,
Quoted 5 lines · Andrei Emeltchenko
Quoted 1 line
+static inline bool
hci_conn_ssp_support(struct hci_conn *conn)Maybe matter of taste but cold this be named
hci_conn_ssp_supported? Then in if condition below it would be seen more natural and similar to other "-ed" functions.
Based on Marcel's preference for the define names it will be called hci_conn_ssp_enabled.
Johan
PATCH 11/15 Bluetooth: Convert hdev->ssp_mode to a flag
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
The ssp_mode is essentially just a boolean so it's more appropriate to have it simply as a flag in hdev->dev_flags.
--- include/net/bluetooth/hci.h | 1 + include/net/bluetooth/hci_core.h | 3 +-- net/bluetooth/hci_event.c | 10 ++++++++-- net/bluetooth/mgmt.c | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-)
include/net/bluetooth/hci.h +1 -0
@@ -94,6 +94,7 @@ enum {HCI_DEBUG_KEYS ,HCI_LE_SCAN , + HCI_SSP_ENABLED, };/* HCI ioctl defines */
include/net/bluetooth/hci_core.h +1 -2
@@ -144,7 +144,6 @@ struct hci_dev {__u8 features[8 ];__u8 host_features[8 ];__u8 commands[64 ]; -__u8 ssp_mode;__u8 hci_ver;__u16 hci_rev;__u8 lmp_ver;
@@ -414,7 +413,7 @@ enum {static inline bool hci_conn_ssp_support (struct hci_conn *conn) {struct hci_dev *hdev = conn->hdev; -return (hdev->ssp_mode >0 && +return (test_bit (HCI_SSP_ENABLED , &hdev->dev_flags) &&test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)); }
net/bluetooth/hci_event.c +8 -2
@@ -429,7 +429,10 @@ static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)if (rp->status)return ; - hdev->ssp_mode = rp->mode; +if (rp->mode) +set_bit (HCI_SSP_ENABLED , &hdev->flags); +else +clear_bit (HCI_SSP_ENABLED , &hdev->flags); }static void hci_cc_write_ssp_mode (struct hci_dev *hdev,struct sk_buff *skb)
@@ -446,7 +449,10 @@ static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)if (!sent)return ; - hdev->ssp_mode = *((__u8 *) sent); +if (*(u8 *) sent) +set_bit (HCI_SSP_ENABLED , &hdev->flags); +else +clear_bit (HCI_SSP_ENABLED , &hdev->flags); }static u8 hci_get_inquiry_mode (struct hci_dev *hdev)
net/bluetooth/mgmt.c +2 -2
@@ -297,7 +297,7 @@ static u32 get_current_settings(struct hci_dev *hdev)if (test_bit (HCI_AUTH , &hdev->flags)) settings |=MGMT_SETTING_LINK_SECURITY ; -if (hdev->ssp_mode >0 ) +if (test_bit (HCI_SSP_ENABLED , &hdev->flags)) settings |=MGMT_SETTING_SSP ;return settings;
@@ -416,7 +416,7 @@ static int update_eir(struct hci_dev *hdev)if (!(hdev->features[6 ] &LMP_EXT_INQ ))return 0 ; -if (hdev->ssp_mode ==0 ) +if (!test_bit (HCI_SSP_ENABLED , &hdev->flags))return 0 ;if (test_bit (HCI_SERVICE_CACHE , &hdev->dev_flags))
Signature · 1 line
1.7.8.3
Marcel Holtmann
maintainerRe: [PATCH 11/15] Bluetooth: Convert hdev->ssp_mode to a flag
Hi Johan,
Quoted 10 lines
The
ssp_modeis essentially just a boolean so it's more appropriate to have it simply as a flag inhdev->dev_flags.Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci.h | 1 + include/net/bluetooth/hci_core.h | 3 +-- net/bluetooth/hci_event.c | 10 ++++++++-- net/bluetooth/mgmt.c | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-)
please do this change first.
Regards
Marcel
PATCH 12/15 Bluetooth: Convert hdev->out to a bool type
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
The hdev->out variable is essentially a boolean so the type 'bool' makes more sense than u8.
--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_conn.c | 8 ++++---- net/bluetooth/hci_event.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
@@ -281,7 +281,7 @@ struct hci_conn {__u16 state;__u8 mode;__u8 type; -__u8 out; +bool out;__u8 attempt;__u8 dev_class[3 ];__u8 features[8 ];
net/bluetooth/hci_conn.c +4 -4
@@ -51,7 +51,7 @@ static void hci_le_connect(struct hci_conn *conn)struct hci_cp_le_create_conn cp; conn->state =BT_CONNECT ; - conn->out =1 ; + conn->out = true; conn->link_mode |=HCI_LM_MASTER ; conn->sec_level =BT_SECURITY_LOW ;
@@ -83,7 +83,7 @@ void hci_acl_connect(struct hci_conn *conn)BT_DBG ("%p" , conn); conn->state =BT_CONNECT ; - conn->out =1 ; + conn->out = true; conn->link_mode =HCI_LM_MASTER ;
@@ -152,7 +152,7 @@ void hci_add_sco(struct hci_conn *conn, __u16 handle)BT_DBG ("%p" , conn); conn->state =BT_CONNECT ; - conn->out =1 ; + conn->out = true; conn->attempt++;
@@ -170,7 +170,7 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)BT_DBG ("%p" , conn); conn->state =BT_CONNECT ; - conn->out =1 ; + conn->out = true; conn->attempt++;
net/bluetooth/hci_event.c +2 -2
@@ -1160,7 +1160,7 @@ static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)if (!conn) { conn =hci_conn_add (hdev,ACL_LINK , &cp->bdaddr);if (conn) { - conn->out =1 ; + conn->out = true; conn->link_mode |=HCI_LM_MASTER ; }else BT_ERR ("No memory for new connection" );
@@ -1532,7 +1532,7 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status) conn =hci_conn_add (hdev,LE_LINK , &cp->peer_addr);if (conn) { conn->dst_type = cp->peer_addr_type; - conn->out =1 ; + conn->out = true; }else {BT_ERR ("No memory for new connection" ); }
Signature · 1 line
1.7.8.3
Re: [PATCH 12/15] Bluetooth: Convert hdev->out to a bool type
Hi Johan,
Quoted 9 lines
The
hdev->outvariable is essentially a boolean so the type 'bool' makes more sense than u8.Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_conn.c | 8 ++++---- net/bluetooth/hci_event.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-)
Regards
Marcel
PATCH 13/15 Bluetooth: Update device_connected and device_found events to latest API
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This patch updates mgmt_ev_device_connected and mgmt_ev_device found to include an EIR-encoded remote name and class whenever possible. With this addition the mgmt_ev_remote_name event becomes unnecessary and can be removed. Since the connected event doesn't map to hci_conn_complete anymore a HCI_CONN_MGMT_CONNECTED flag is added to track when mgmt has been notified about a connection.
--- include/net/bluetooth/hci_core.h | 7 ++- include/net/bluetooth/mgmt.h | 17 ++++---- net/bluetooth/hci_event.c | 78 +++++++++++++++++++++++++++----------- net/bluetooth/mgmt.c | 56 ++++++++++++++++++++------- 4 files changed, 110 insertions(+), 48 deletions(-)
include/net/bluetooth/hci_core.h +5 -2
@@ -408,6 +408,7 @@ enum {HCI_CONN_SSP_SUPPORT ,HCI_CONN_POWER_SAVE ,HCI_CONN_REMOTE_OOB , + HCI_CONN_MGMT_CONNECTED, };static inline bool hci_conn_ssp_support (struct hci_conn *conn)
@@ -939,7 +940,8 @@ int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);int mgmt_new_link_key (struct hci_dev *hdev,struct link_key *key,u8 persistent);int mgmt_device_connected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type, -u8 addr_type); +u8 addr_type,u8 *name,u8 name_len, +u8 *dev_class);int mgmt_device_disconnected (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type);int mgmt_disconnect_failed (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 status);
@@ -968,7 +970,8 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,int mgmt_device_found (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type,u8 addr_type,u8 *dev_class,s8 rssi,u8 cfm_name,u8 *eir,u16 eir_len); -int mgmt_remote_name (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 *name); +int mgmt_remote_name (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 link_type, +u8 addr_type,s8 rssi,u8 *name,u8 name_len);int mgmt_start_discovery_failed (struct hci_dev *hdev,u8 status);int mgmt_stop_discovery_failed (struct hci_dev *hdev,u8 status);int mgmt_discovering (struct hci_dev *hdev,u8 discovering);
include/net/bluetooth/mgmt.h +8 -9
@@ -329,6 +329,11 @@ struct mgmt_ev_new_link_key { } __packed;#define MGMT_EV_DEVICE_CONNECTED 0x000A +struct mgmt_ev_device_connected { +struct mgmt_addr_info addr; +__le16 eir_len; +__u8 eir[0 ]; +} __packed;#define MGMT_EV_DEVICE_DISCONNECTED 0x000B
@@ -371,20 +376,14 @@ struct mgmt_ev_device_found {__u8 eir[0 ]; } __packed; -#define MGMT_EV_REMOTE_NAME 0x0012 -struct mgmt_ev_remote_name { -bdaddr_t bdaddr; -__u8 name[MGMT_MAX_NAME_LENGTH ]; -} __packed; - -#define MGMT_EV_DISCOVERING 0x0013 +#define MGMT_EV_DISCOVERING 0x0012 -#define MGMT_EV_DEVICE_BLOCKED 0x0014 +#define MGMT_EV_DEVICE_BLOCKED 0x0013struct mgmt_ev_device_blocked {bdaddr_t bdaddr; } __packed; -#define MGMT_EV_DEVICE_UNBLOCKED 0x0015 +#define MGMT_EV_DEVICE_UNBLOCKED 0x0014struct mgmt_ev_device_unblocked {bdaddr_t bdaddr; } __packed;
net/bluetooth/hci_event.c +56 -22
143 lines not on this page · raw message
net/bluetooth/mgmt.c +41 -15
93 lines not on this page · raw message
Signature · 1 line
1.7.8.3
Re: [PATCH 13/15] Bluetooth: Update device_connected and device_found events to latest API
Hi Johan,
Quoted 7 lines
This patch updates
mgmt_ev_device_connectedandmgmt_ev_devicefound to include an EIR-encoded remote name and class whenever possible. With this addition themgmt_ev_remote_nameevent becomes unnecessary and can be removed. Since the connected event doesn't map tohci_conn_completeanymore aHCI_CONN_MGMT_CONNECTEDflag is added to track when mgmt has been notified about a connection.
Quoted 7 lines
Signed-off-by Johan Hedberg <[email protected]>--- include/net/bluetooth/hci_core.h | 7 ++- include/net/bluetooth/mgmt.h | 17 ++++---- net/bluetooth/hci_event.c | 78 +++++++++++++++++++++++++++----------- net/bluetooth/mgmt.c | 56 ++++++++++++++++++++------- 4 files changed, 110 insertions(+), 48 deletions(-)
Regards
Marcel
PATCH 14/15 Bluetooth: Rename hdev->flags to hdev->compat_flags
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
These flags mostly exist for legacy reasons and no new flags should be added to this set, so compat_flags is a better name.
--- drivers/bluetooth/bfusb.c | 12 +++--- drivers/bluetooth/bpa10x.c | 12 +++--- drivers/bluetooth/btmrvl_main.c | 9 +++-- drivers/bluetooth/btusb.c | 20 +++++----- drivers/bluetooth/hci_ldisc.c | 6 ++-- drivers/bluetooth/hci_vhci.c | 6 ++-- include/net/bluetooth/hci.h | 7 +--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_conn.c | 7 ++-- net/bluetooth/hci_core.c | 71 +++++++++++++++++++------------------ net/bluetooth/hci_event.c | 43 ++++++++++++----------- net/bluetooth/hci_sock.c | 8 ++-- net/bluetooth/mgmt.c | 38 ++++++++++---------- 13 files changed, 121 insertions(+), 120 deletions(-)
drivers/bluetooth/bfusb.c +6 -6
@@ -191,7 +191,7 @@ static void bfusb_tx_complete(struct urb *urb)atomic_dec (&data->pending_tx); -if (!test_bit (HCI_RUNNING , &data->hdev->flags)) +if (!test_bit (HCI_RUNNING , &data->hdev->compat_flags))return ;if (!urb->status)
@@ -352,7 +352,7 @@ static void bfusb_rx_complete(struct urb *urb)read_lock (&data->lock); -if (!test_bit (HCI_RUNNING , &data->hdev->flags)) +if (!test_bit (HCI_RUNNING , &data->hdev->compat_flags)) goto unlock;if (urb->status || !count)
@@ -417,7 +417,7 @@ static int bfusb_open(struct hci_dev *hdev)BT_DBG ("hdev %p bfusb %p" , hdev, data); -if (test_and_set_bit (HCI_RUNNING , &hdev->flags)) +if (test_and_set_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;write_lock_irqsave (&data->lock, flags);
@@ -427,7 +427,7 @@ static int bfusb_open(struct hci_dev *hdev)for (i =1 ; i <BFUSB_MAX_BULK_RX ; i++)bfusb_rx_submit (data,NULL ); }else { -clear_bit (HCI_RUNNING , &hdev->flags); +clear_bit (HCI_RUNNING , &hdev->compat_flags); }write_unlock_irqrestore (&data->lock, flags);
@@ -453,7 +453,7 @@ static int bfusb_close(struct hci_dev *hdev)BT_DBG ("hdev %p bfusb %p" , hdev, data); -if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) +if (!test_and_clear_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;write_lock_irqsave (&data->lock, flags);
@@ -480,7 +480,7 @@ static int bfusb_send_frame(struct sk_buff *skb)return -ENODEV ; } -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return -EBUSY ; data = hdev->driver_data;
drivers/bluetooth/bpa10x.c +6 -6
@@ -172,7 +172,7 @@ static void bpa10x_tx_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags)) goto done;if (!urb->status)
@@ -195,7 +195,7 @@ static void bpa10x_rx_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return ;if (urb->status ==0 ) {
@@ -306,7 +306,7 @@ static int bpa10x_open(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); -if (test_and_set_bit (HCI_RUNNING , &hdev->flags)) +if (test_and_set_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ; err =bpa10x_submit_intr_urb (hdev);
@@ -322,7 +322,7 @@ static int bpa10x_open(struct hci_dev *hdev) error:usb_kill_anchored_urbs (&data->rx_anchor); -clear_bit (HCI_RUNNING , &hdev->flags); +clear_bit (HCI_RUNNING , &hdev->compat_flags);return err; }
@@ -333,7 +333,7 @@ static int bpa10x_close(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); -if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) +if (!test_and_clear_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;usb_kill_anchored_urbs (&data->rx_anchor);
@@ -363,7 +363,7 @@ static int bpa10x_send_frame(struct sk_buff *skb)BT_DBG ("%s" , hdev->name); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return -EBUSY ; urb =usb_alloc_urb (0 ,GFP_ATOMIC );
drivers/bluetooth/btmrvl_main.c +5 -4
@@ -400,8 +400,9 @@ static int btmrvl_send_frame(struct sk_buff *skb) } priv = (struct btmrvl_private *) hdev->driver_data; -if (!test_bit (HCI_RUNNING , &hdev->flags)) { -BT_ERR ("Failed testing HCI_RUNING, flags=%lx" , hdev->flags); +if (!test_bit (HCI_RUNNING , &hdev->compat_flags)) { +BT_ERR ("Failed testing HCI_RUNING, flags=%lx" , + hdev->compat_flags);print_hex_dump_bytes ("data: " ,DUMP_PREFIX_OFFSET , skb->data, skb->len);return -EBUSY ;
@@ -441,7 +442,7 @@ static int btmrvl_close(struct hci_dev *hdev) {struct btmrvl_private *priv = hdev->driver_data; -if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) +if (!test_and_clear_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;skb_queue_purge (&priv->adapter->tx_queue);
@@ -451,7 +452,7 @@ static int btmrvl_close(struct hci_dev *hdev)static int btmrvl_open (struct hci_dev *hdev) { -set_bit (HCI_RUNNING , &hdev->flags); +set_bit (HCI_RUNNING , &hdev->compat_flags);return 0 ; }
drivers/bluetooth/btusb.c +10 -10
@@ -248,7 +248,7 @@ static void btusb_intr_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return ;if (urb->status ==0 ) {
@@ -336,7 +336,7 @@ static void btusb_bulk_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return ;if (urb->status ==0 ) {
@@ -422,7 +422,7 @@ static void btusb_isoc_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return ;if (urb->status ==0 ) {
@@ -541,7 +541,7 @@ static void btusb_tx_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags)) goto done;if (!urb->status)
@@ -567,7 +567,7 @@ static void btusb_isoc_tx_complete(struct urb *urb)BT_DBG ("%s urb %p status %d count %d" , hdev->name, urb, urb->status, urb->actual_length); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags)) goto done;if (!urb->status)
@@ -594,7 +594,7 @@ static int btusb_open(struct hci_dev *hdev) data->intf->needs_remote_wakeup =1 ; -if (test_and_set_bit (HCI_RUNNING , &hdev->flags)) +if (test_and_set_bit (HCI_RUNNING , &hdev->compat_flags)) goto done;if (test_and_set_bit (BTUSB_INTR_RUNNING , &data->flags))
@@ -619,7 +619,7 @@ done: failed:clear_bit (BTUSB_INTR_RUNNING , &data->flags); -clear_bit (HCI_RUNNING , &hdev->flags); +clear_bit (HCI_RUNNING , &hdev->compat_flags);usb_autopm_put_interface (data->intf);return err; }
@@ -638,7 +638,7 @@ static int btusb_close(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); -if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) +if (!test_and_clear_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;cancel_work_sync (&data->work);
@@ -683,7 +683,7 @@ static int btusb_send_frame(struct sk_buff *skb)BT_DBG ("%s" , hdev->name); -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return -EBUSY ;switch (bt_cb (skb)->pkt_type) {
@@ -1153,7 +1153,7 @@ static int btusb_resume(struct usb_interface *intf)if (--data->suspend_count)return 0 ; -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags)) goto done;if (test_bit (BTUSB_INTR_RUNNING , &data->flags)) {
drivers/bluetooth/hci_ldisc.c +3 -3
@@ -166,7 +166,7 @@ static int hci_uart_open(struct hci_dev *hdev)/* Nothing to do for UART driver */ -set_bit (HCI_RUNNING , &hdev->flags); +set_bit (HCI_RUNNING , &hdev->compat_flags);return 0 ; }
@@ -198,7 +198,7 @@ static int hci_uart_close(struct hci_dev *hdev) {BT_DBG ("hdev %p" , hdev); -if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) +if (!test_and_clear_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;hci_uart_flush (hdev);
@@ -217,7 +217,7 @@ static int hci_uart_send_frame(struct sk_buff *skb)return -ENODEV ; } -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return -EBUSY ; hu = (struct hci_uart *) hdev->driver_data;
drivers/bluetooth/hci_vhci.c +3 -3
@@ -54,7 +54,7 @@ struct vhci_data {static int vhci_open_dev (struct hci_dev *hdev) { -set_bit (HCI_RUNNING , &hdev->flags); +set_bit (HCI_RUNNING , &hdev->compat_flags);return 0 ; }
@@ -63,7 +63,7 @@ static int vhci_close_dev(struct hci_dev *hdev) {struct vhci_data *data = hdev->driver_data; -if (!test_and_clear_bit (HCI_RUNNING , &hdev->flags)) +if (!test_and_clear_bit (HCI_RUNNING , &hdev->compat_flags))return 0 ;skb_queue_purge (&data->readq);
@@ -90,7 +90,7 @@ static int vhci_send_frame(struct sk_buff *skb)return -ENODEV ; } -if (!test_bit (HCI_RUNNING , &hdev->flags)) +if (!test_bit (HCI_RUNNING , &hdev->compat_flags))return -EBUSY ; data = hdev->driver_data;
include/net/bluetooth/hci.h +2 -5
@@ -63,7 +63,7 @@ enum {HCI_QUIRK_FIXUP_BUFFER_SIZE }; -/* HCI device flags */ +/* hdev->compat_flags */ enum {HCI_UP ,HCI_INIT ,
@@ -80,10 +80,7 @@ enum { HCI_RESET, }; -/* -* BR/EDR and/or LE controller flags: the flags defined here should represent -* states from the controller. -*/ +/* hdev->dev_flags */ enum {HCI_SETUP ,HCI_AUTO_OFF ,
include/net/bluetooth/hci_core.h +1 -1
@@ -131,7 +131,7 @@ struct hci_dev {struct mutex lock;char name[8 ]; -unsigned long flags; +unsigned long compat_flags;__u16 id;__u8 bus;__u8 dev_type;
net/bluetooth/hci_conn.c +4 -3
@@ -320,7 +320,7 @@ static void hci_conn_enter_sniff_mode(struct hci_conn *conn)BT_DBG ("conn %p mode %d" , conn, conn->mode); -if (test_bit (HCI_RAW , &hdev->flags)) +if (test_bit (HCI_RAW , &hdev->compat_flags))return ;if (!lmp_sniff_capable (hdev) || !lmp_sniff_capable (conn))
@@ -491,7 +491,8 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)read_lock (&hci_dev_list_lock);list_for_each_entry (d, &hci_dev_list, list) { -if (!test_bit (HCI_UP , &d->flags) ||test_bit (HCI_RAW , &d->flags)) +if (!test_bit (HCI_UP , &d->compat_flags) || +test_bit (HCI_RAW , &d->compat_flags))continue ;/* Simple routing:
@@ -771,7 +772,7 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)BT_DBG ("conn %p mode %d" , conn, conn->mode); -if (test_bit (HCI_RAW , &hdev->flags)) +if (test_bit (HCI_RAW , &hdev->compat_flags))return ;if (conn->mode !=HCI_CM_SNIFF )
net/bluetooth/hci_core.c +36 -35
253 lines not on this page · raw message
net/bluetooth/hci_event.c +22 -21
135 lines not on this page · raw message
net/bluetooth/hci_sock.c +4 -4
@@ -231,9 +231,9 @@ static inline int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd, unsignreturn -EPERM ;if (arg) -set_bit (HCI_RAW , &hdev->flags); +set_bit (HCI_RAW , &hdev->compat_flags);else -clear_bit (HCI_RAW , &hdev->flags); +clear_bit (HCI_RAW , &hdev->compat_flags);return 0 ;
@@ -506,7 +506,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock, goto done; } -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err = -ENETDOWN ; goto done; }
@@ -536,7 +536,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock, goto drop; } -if (test_bit (HCI_RAW , &hdev->flags) || (ogf ==0x3f )) { +if (test_bit (HCI_RAW , &hdev->compat_flags) || (ogf ==0x3f )) {skb_queue_tail (&hdev->raw_q, skb);queue_work (hdev->workqueue, &hdev->tx_work); }else {
net/bluetooth/mgmt.c +19 -19
@@ -274,15 +274,15 @@ static u32 get_current_settings(struct hci_dev *hdev) {u32 settings =0 ; -if (test_bit (HCI_UP , &hdev->flags)) +if (test_bit (HCI_UP , &hdev->compat_flags)) settings |=MGMT_SETTING_POWERED ;else return settings; -if (test_bit (HCI_PSCAN , &hdev->flags)) +if (test_bit (HCI_PSCAN , &hdev->compat_flags)) settings |=MGMT_SETTING_CONNECTABLE ; -if (test_bit (HCI_ISCAN , &hdev->flags)) +if (test_bit (HCI_ISCAN , &hdev->compat_flags)) settings |=MGMT_SETTING_DISCOVERABLE ;if (test_bit (HCI_PAIRABLE , &hdev->dev_flags))
@@ -294,10 +294,10 @@ static u32 get_current_settings(struct hci_dev *hdev)if (hdev->host_features[0 ] &LMP_HOST_LE ) settings |=MGMT_SETTING_LE ; -if (test_bit (HCI_AUTH , &hdev->flags)) +if (test_bit (HCI_AUTH , &hdev->compat_flags)) settings |=MGMT_SETTING_LINK_SECURITY ; -if (test_bit (HCI_SSP_ENABLED , &hdev->flags)) +if (test_bit (HCI_SSP_ENABLED , &hdev->compat_flags)) settings |=MGMT_SETTING_SSP ;return settings;
@@ -416,7 +416,7 @@ static int update_eir(struct hci_dev *hdev)if (!(hdev->features[6 ] &LMP_EXT_INQ ))return 0 ; -if (!test_bit (HCI_SSP_ENABLED , &hdev->flags)) +if (!test_bit (HCI_SSP_ENABLED , &hdev->compat_flags))return 0 ;if (test_bit (HCI_SERVICE_CACHE , &hdev->dev_flags))
@@ -633,7 +633,7 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)hci_dev_lock (hdev); - up =test_bit (HCI_UP , &hdev->flags); + up =test_bit (HCI_UP , &hdev->compat_flags);if ((cp->val && up) || (!cp->val && !up)) { err =send_settings_rsp (sk,MGMT_OP_SET_POWERED , hdev); goto failed;
@@ -688,7 +688,7 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data,hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_SET_DISCOVERABLE ,MGMT_STATUS_NOT_POWERED ); goto failed;
@@ -701,8 +701,8 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data, goto failed; } -if (cp->val ==test_bit (HCI_ISCAN , &hdev->flags) && -test_bit (HCI_PSCAN , &hdev->flags)) { +if (cp->val ==test_bit (HCI_ISCAN , &hdev->compat_flags) && +test_bit (HCI_PSCAN , &hdev->compat_flags)) { err =send_settings_rsp (sk,MGMT_OP_SET_DISCOVERABLE , hdev); goto failed; }
@@ -758,7 +758,7 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data,hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_SET_CONNECTABLE ,MGMT_STATUS_NOT_POWERED ); goto failed;
@@ -771,7 +771,7 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data, goto failed; } -if (cp->val ==test_bit (HCI_PSCAN , &hdev->flags)) { +if (cp->val ==test_bit (HCI_PSCAN , &hdev->compat_flags)) { err =send_settings_rsp (sk,MGMT_OP_SET_CONNECTABLE , hdev); goto failed; }
@@ -1119,7 +1119,7 @@ static int remove_keys(struct sock *sk, u16 index, unsigned char *data, goto unlock; } -if (!test_bit (HCI_UP , &hdev->flags) || !cp->disconnect) { +if (!test_bit (HCI_UP , &hdev->compat_flags) || !cp->disconnect) { err =cmd_complete (sk, index,MGMT_OP_REMOVE_KEYS , &rp,sizeof (rp)); goto unlock;
@@ -1178,7 +1178,7 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_DISCONNECT ,MGMT_STATUS_NOT_POWERED ); goto failed;
@@ -1340,7 +1340,7 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_PIN_CODE_REPLY ,MGMT_STATUS_NOT_POWERED ); goto failed;
@@ -1409,7 +1409,7 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data,hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_PIN_CODE_NEG_REPLY ,MGMT_STATUS_NOT_POWERED ); goto failed;
@@ -1609,7 +1609,7 @@ static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index, mgmt_op,MGMT_STATUS_NOT_POWERED ); goto done; }
@@ -1789,7 +1789,7 @@ static int read_local_oob_data(struct sock *sk, u16 index)hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_READ_LOCAL_OOB_DATA ,MGMT_STATUS_NOT_POWERED ); goto unlock;
@@ -1914,7 +1914,7 @@ static int start_discovery(struct sock *sk, u16 index,hci_dev_lock (hdev); -if (!test_bit (HCI_UP , &hdev->flags)) { +if (!test_bit (HCI_UP , &hdev->compat_flags)) { err =cmd_status (sk, index,MGMT_OP_START_DISCOVERY ,MGMT_STATUS_NOT_POWERED ); goto failed;
Signature · 1 line
1.7.8.3
Marcel Holtmann
maintainerRe: [PATCH 14/15] Bluetooth: Rename hdev->flags to hdev->compat_flags
Hi Johan,
Quoted 25 lines
These flags mostly exist for legacy reasons and no new flags should be added to this set, so
compat_flagsis a better name.Signed-off-by Johan Hedberg <[email protected]>--- drivers/bluetooth/bfusb.c | 12 +++--- drivers/bluetooth/bpa10x.c | 12 +++--- drivers/bluetooth/btmrvl_main.c | 9 +++-- drivers/bluetooth/btusb.c | 20 +++++----- drivers/bluetooth/hci_ldisc.c | 6 ++-- drivers/bluetooth/hci_vhci.c | 6 ++-- include/net/bluetooth/hci.h | 7 +--- include/net/bluetooth/hci_core.h | 2 +- net/bluetooth/hci_conn.c | 7 ++-- net/bluetooth/hci_core.c | 71 +++++++++++++++++++------------------ net/bluetooth/hci_event.c | 43 ++++++++++++----------- net/bluetooth/hci_sock.c | 8 ++-- net/bluetooth/mgmt.c | 38 ++++++++++---------- 13 files changed, 121 insertions(+), 120 deletions(-)drivers/bluetooth/bfusb.c +0
-0
drivers/bluetooth/bfusb.c static void bfusb_tx_complete(struct urb *urb) · line 195
Quoted 6 lines
drivers/bluetooth/bfusb.c +1
-1@@ -191,7 +191,7 @@ static void bfusb_tx_complete(struct urb *urb)atomic_dec (&data->pending_tx); -if (!test_bit (HCI_RUNNING , &data->hdev->flags)) +if (!test_bit (HCI_RUNNING , &data->hdev->compat_flags))return ;
I do not like this change at all.
Can we just add a BT specific helper for setting/testing HCI_RUNNING and hiding the fact of hdev->flags.
Regards
Marcel
PATCH 15/15 Bluetooth: Rename hdev->dev_flags to hdev-flags
In reply to Johan HedbergFrom: Johan Hedberg <[email protected]>
This patch renames hdev->dev_flags to simply hdev->flags as these are now the "default" set of flags and the place where new flags should be added. To be consistent with struct hci_conn flags naming each flag also receives a HCI_DEV_* prefix instead of just HCI_*.
--- include/net/bluetooth/hci.h | 22 +++++++------- include/net/bluetooth/hci_core.h | 4 +- net/bluetooth/hci_core.c | 32 ++++++++++---------- net/bluetooth/hci_event.c | 59 +++++++++++++++++++------------------ net/bluetooth/mgmt.c | 34 +++++++++++----------- net/bluetooth/smp.c | 2 +- 6 files changed, 77 insertions(+), 76 deletions(-)
include/net/bluetooth/hci.h +11 -11
@@ -80,18 +80,18 @@ enum { HCI_RESET, }; -/* hdev->dev_flags */ +/* hdev->flags */ enum { -HCI_SETUP , -HCI_AUTO_OFF , -HCI_MGMT , -HCI_PAIRABLE , -HCI_SERVICE_CACHE , -HCI_LINK_KEYS , -HCI_DEBUG_KEYS , - -HCI_LE_SCAN , -HCI_SSP_ENABLED , +HCI_DEV_SETUP , +HCI_DEV_AUTO_OFF , +HCI_DEV_MGMT , +HCI_DEV_PAIRABLE , +HCI_DEV_SERVICE_CACHE , +HCI_DEV_LINK_KEYS , +HCI_DEV_DEBUG_KEYS , + +HCI_DEV_LE_SCAN , +HCI_DEV_SSP_ENABLED , };/* HCI ioctl defines */
include/net/bluetooth/hci_core.h +2 -2
@@ -260,7 +260,7 @@ struct hci_dev {struct rfkill *rfkill; -unsigned long dev_flags; +unsigned long flags;int (*open)(struct hci_dev *hdev);int (*close)(struct hci_dev *hdev);
@@ -414,7 +414,7 @@ enum {static inline bool hci_conn_ssp_support (struct hci_conn *conn) {struct hci_dev *hdev = conn->hdev; -return (test_bit (HCI_SSP_ENABLED , &hdev->dev_flags) && +return (test_bit (HCI_DEV_SSP_ENABLED , &hdev->flags) &&test_bit (HCI_CONN_SSP_SUPPORT , &conn->flags)); }
net/bluetooth/hci_core.c +16 -16
@@ -695,7 +695,7 @@ int hci_dev_open(__u16 dev)hci_dev_hold (hdev);set_bit (HCI_UP , &hdev->compat_flags);hci_notify (hdev,HCI_DEV_UP ); -if (!test_bit (HCI_SETUP , &hdev->dev_flags)) { +if (!test_bit (HCI_DEV_SETUP , &hdev->flags)) {hci_dev_lock (hdev);mgmt_powered (hdev,1 );hci_dev_unlock (hdev);
@@ -749,10 +749,10 @@ static int hci_dev_do_close(struct hci_dev *hdev) hdev->discov_timeout =0 ; } -if (test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) +if (test_and_clear_bit (HCI_DEV_AUTO_OFF , &hdev->flags))cancel_delayed_work (&hdev->power_off); -if (test_and_clear_bit (HCI_SERVICE_CACHE , &hdev->dev_flags)) +if (test_and_clear_bit (HCI_DEV_SERVICE_CACHE , &hdev->flags))cancel_delayed_work (&hdev->service_cache);hci_dev_lock (hdev);
@@ -974,11 +974,11 @@ int hci_get_dev_list(void __user *arg)read_lock (&hci_dev_list_lock);list_for_each_entry (hdev, &hci_dev_list, list) { -if (test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) +if (test_and_clear_bit (HCI_DEV_AUTO_OFF , &hdev->flags))cancel_delayed_work (&hdev->power_off); -if (!test_bit (HCI_MGMT , &hdev->dev_flags)) -set_bit (HCI_PAIRABLE , &hdev->dev_flags); +if (!test_bit (HCI_DEV_MGMT , &hdev->flags)) +set_bit (HCI_DEV_PAIRABLE , &hdev->flags); (dr + n)->dev_id = hdev->id; (dr + n)->dev_opt = hdev->compat_flags;
@@ -1010,11 +1010,11 @@ int hci_get_dev_info(void __user *arg)if (!hdev)return -ENODEV ; -if (test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) +if (test_and_clear_bit (HCI_DEV_AUTO_OFF , &hdev->flags))cancel_delayed_work_sync (&hdev->power_off); -if (!test_bit (HCI_MGMT , &hdev->dev_flags)) -set_bit (HCI_PAIRABLE , &hdev->dev_flags); +if (!test_bit (HCI_DEV_MGMT , &hdev->flags)) +set_bit (HCI_DEV_PAIRABLE , &hdev->flags);strcpy (di.name, hdev->name); di.bdaddr = hdev->bdaddr;
@@ -1094,11 +1094,11 @@ static void hci_power_on(struct work_struct *work)if (hci_dev_open (hdev->id) <0 )return ; -if (test_bit (HCI_AUTO_OFF , &hdev->dev_flags)) +if (test_bit (HCI_DEV_AUTO_OFF , &hdev->flags))schedule_delayed_work (&hdev->power_off,msecs_to_jiffies (AUTO_OFF_TIMEOUT )); -if (test_and_clear_bit (HCI_SETUP , &hdev->dev_flags)) +if (test_and_clear_bit (HCI_DEV_SETUP , &hdev->flags))mgmt_index_added (hdev); }
@@ -1109,7 +1109,7 @@ static void hci_power_off(struct work_struct *work)BT_DBG ("%s" , hdev->name); -clear_bit (HCI_AUTO_OFF , &hdev->dev_flags); +clear_bit (HCI_DEV_AUTO_OFF , &hdev->flags);hci_dev_close (hdev->id); }
@@ -1601,7 +1601,7 @@ int hci_register_dev(struct hci_dev *hdev)mutex_init (&hdev->lock); hdev->compat_flags =0 ; - hdev->dev_flags =0 ; + hdev->flags =0 ; hdev->pkt_type = (HCI_DM1 |HCI_DH1 |HCI_HV1 ); hdev->esco_type = (ESCO_HV1 ); hdev->link_mode = (HCI_LM_ACCEPT );
@@ -1676,8 +1676,8 @@ int hci_register_dev(struct hci_dev *hdev) } } -set_bit (HCI_AUTO_OFF , &hdev->dev_flags); -set_bit (HCI_SETUP , &hdev->dev_flags); +set_bit (HCI_DEV_AUTO_OFF , &hdev->flags); +set_bit (HCI_DEV_SETUP , &hdev->flags);schedule_work (&hdev->power_on);hci_notify (hdev,HCI_DEV_REG );
@@ -1713,7 +1713,7 @@ void hci_unregister_dev(struct hci_dev *hdev)kfree_skb (hdev->reassembly[i]);if (!test_bit (HCI_INIT , &hdev->compat_flags) && - !test_bit (HCI_SETUP , &hdev->dev_flags)) { + !test_bit (HCI_DEV_SETUP , &hdev->flags)) {hci_dev_lock (hdev);mgmt_index_removed (hdev);hci_dev_unlock (hdev);
net/bluetooth/hci_event.c +30 -29
215 lines not on this page · raw message
net/bluetooth/mgmt.c +17 -17
@@ -226,10 +226,10 @@ static int read_index_list(struct sock *sk) i =0 ;list_for_each_entry (d, &hci_dev_list, list) { -if (test_and_clear_bit (HCI_AUTO_OFF , &d->dev_flags)) +if (test_and_clear_bit (HCI_DEV_AUTO_OFF , &d->flags))cancel_delayed_work (&d->power_off); -if (test_bit (HCI_SETUP , &d->dev_flags)) +if (test_bit (HCI_DEV_SETUP , &d->flags))continue ;put_unaligned_le16 (d->id, &rp->index[i++]);
@@ -285,7 +285,7 @@ static u32 get_current_settings(struct hci_dev *hdev)if (test_bit (HCI_ISCAN , &hdev->compat_flags)) settings |=MGMT_SETTING_DISCOVERABLE ; -if (test_bit (HCI_PAIRABLE , &hdev->dev_flags)) +if (test_bit (HCI_DEV_PAIRABLE , &hdev->flags)) settings |=MGMT_SETTING_PAIRABLE ;if (!(hdev->features[4 ] &LMP_NO_BREDR ))
@@ -297,7 +297,7 @@ static u32 get_current_settings(struct hci_dev *hdev)if (test_bit (HCI_AUTH , &hdev->compat_flags)) settings |=MGMT_SETTING_LINK_SECURITY ; -if (test_bit (HCI_SSP_ENABLED , &hdev->compat_flags)) +if (test_bit (HCI_DEV_SSP_ENABLED , &hdev->compat_flags)) settings |=MGMT_SETTING_SSP ;return settings;
@@ -416,10 +416,10 @@ static int update_eir(struct hci_dev *hdev)if (!(hdev->features[6 ] &LMP_EXT_INQ ))return 0 ; -if (!test_bit (HCI_SSP_ENABLED , &hdev->compat_flags)) +if (!test_bit (HCI_DEV_SSP_ENABLED , &hdev->compat_flags))return 0 ; -if (test_bit (HCI_SERVICE_CACHE , &hdev->dev_flags)) +if (test_bit (HCI_DEV_SERVICE_CACHE , &hdev->flags))return 0 ;memset (&cp,0 ,sizeof (cp));
@@ -451,7 +451,7 @@ static int update_class(struct hci_dev *hdev)BT_DBG ("%s" , hdev->name); -if (test_bit (HCI_SERVICE_CACHE , &hdev->dev_flags)) +if (test_bit (HCI_DEV_SERVICE_CACHE , &hdev->flags))return 0 ; cod[0 ] = hdev->minor_class;
@@ -469,7 +469,7 @@ static void service_cache_off(struct work_struct *work) struct hci_dev *hdev = container_of(work, struct hci_dev, service_cache.work); -if (!test_and_clear_bit (HCI_SERVICE_CACHE , &hdev->dev_flags)) +if (!test_and_clear_bit (HCI_DEV_SERVICE_CACHE , &hdev->flags))return ;hci_dev_lock (hdev);
@@ -482,10 +482,10 @@ static void service_cache_off(struct work_struct *work)static void mgmt_init_hdev (struct hci_dev *hdev) { -if (!test_and_set_bit (HCI_MGMT , &hdev->dev_flags)) +if (!test_and_set_bit (HCI_DEV_MGMT , &hdev->flags))INIT_DELAYED_WORK (&hdev->service_cache, service_cache_off); -if (!test_and_set_bit (HCI_SERVICE_CACHE , &hdev->dev_flags)) +if (!test_and_set_bit (HCI_DEV_SERVICE_CACHE , &hdev->flags))schedule_delayed_work (&hdev->service_cache,msecs_to_jiffies (SERVICE_CACHE_TIMEOUT )); }
@@ -502,7 +502,7 @@ static int read_controller_info(struct sock *sk, u16 index)return cmd_status (sk, index,MGMT_OP_READ_INFO ,MGMT_STATUS_INVALID_PARAMS ); -if (test_and_clear_bit (HCI_AUTO_OFF , &hdev->dev_flags)) +if (test_and_clear_bit (HCI_DEV_AUTO_OFF , &hdev->flags))cancel_delayed_work_sync (&hdev->power_off);hci_dev_lock (hdev);
@@ -851,9 +851,9 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data,hci_dev_lock (hdev);if (cp->val) -set_bit (HCI_PAIRABLE , &hdev->dev_flags); +set_bit (HCI_DEV_PAIRABLE , &hdev->flags);else -clear_bit (HCI_PAIRABLE , &hdev->dev_flags); +clear_bit (HCI_DEV_PAIRABLE , &hdev->flags); err =send_settings_rsp (sk,MGMT_OP_SET_PAIRABLE , hdev);if (err <0 )
@@ -1008,7 +1008,7 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data, hdev->major_class = cp->major; hdev->minor_class = cp->minor; -if (test_and_clear_bit (HCI_SERVICE_CACHE , &hdev->dev_flags)) { +if (test_and_clear_bit (HCI_DEV_SERVICE_CACHE , &hdev->flags)) {hci_dev_unlock (hdev);cancel_delayed_work_sync (&hdev->service_cache);hci_dev_lock (hdev);
@@ -1063,12 +1063,12 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,hci_link_keys_clear (hdev); -set_bit (HCI_LINK_KEYS , &hdev->dev_flags); +set_bit (HCI_DEV_LINK_KEYS , &hdev->flags);if (cp->debug_keys) -set_bit (HCI_DEBUG_KEYS , &hdev->dev_flags); +set_bit (HCI_DEV_DEBUG_KEYS , &hdev->flags);else -clear_bit (HCI_DEBUG_KEYS , &hdev->dev_flags); +clear_bit (HCI_DEV_DEBUG_KEYS , &hdev->flags);for (i =0 ; i < key_count; i++) {struct mgmt_link_key_info *key = &cp->keys[i];
net/bluetooth/smp.c +1 -1
@@ -217,7 +217,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn, {u8 dist_keys =0 ; -if (test_bit (HCI_PAIRABLE , &conn->hcon->hdev->dev_flags)) { +if (test_bit (HCI_DEV_PAIRABLE , &conn->hcon->hdev->flags)) { dist_keys =SMP_DIST_ENC_KEY ; authreq |=SMP_AUTH_BONDING ; }else {
Signature · 1 line
1.7.8.3