* [RFC 1/2] Bluetooth: Fix SCO connection without socket
From: Frédéric Dalleau @ 2013-08-14 17:29 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau
If SCO socket is closed after ACL connection is established and before
SCO is established, it is not possible to cancel the ongoing
synchronous connection setup. When Synchronous Connection Complete
event is triggered, there will be no socket ready. Drop connection if
this is the case.
There is a side effect on this patch since it does not distinguish
between outgoing and incoming sco connections. An incoming SCO
connection with no acceptor will be dropped.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
---
include/net/bluetooth/hci_core.h | 10 +++++++---
net/bluetooth/hci_event.c | 5 +++--
net/bluetooth/sco.c | 14 +++++++++-----
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 1f95e9b..1000553 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -376,7 +376,7 @@ extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb,
u16 flags);
extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
-extern void sco_connect_cfm(struct hci_conn *hcon, __u8 status);
+extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status);
extern void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
@@ -843,8 +843,10 @@ static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
}
}
-static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
+static inline int hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
{
+ int canceled = 0;
+
switch (conn->type) {
case ACL_LINK:
case LE_LINK:
@@ -853,7 +855,7 @@ static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
case SCO_LINK:
case ESCO_LINK:
- sco_connect_cfm(conn, status);
+ canceled = sco_connect_cfm(conn, status);
break;
default:
@@ -863,6 +865,8 @@ static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
if (conn->connect_cfm_cb)
conn->connect_cfm_cb(conn, status);
+
+ return canceled;
}
static inline int hci_proto_disconn_ind(struct hci_conn *conn)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 491c5fb..e29ef13 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2879,6 +2879,7 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
{
struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
struct hci_conn *conn;
+ int canceled;
BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
@@ -2922,8 +2923,8 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
break;
}
- hci_proto_connect_cfm(conn, ev->status);
- if (ev->status)
+ canceled = hci_proto_connect_cfm(conn, ev->status);
+ if (canceled || ev->status)
hci_conn_del(conn);
unlock:
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 1170b6e..e94e654 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -979,7 +979,7 @@ static void sco_chan_del(struct sock *sk, int err)
sock_set_flag(sk, SOCK_ZAPPED);
}
-static void sco_conn_ready(struct sco_conn *conn)
+static int sco_conn_ready(struct sco_conn *conn)
{
struct sock *parent;
struct sock *sk = conn->sk;
@@ -998,7 +998,7 @@ static void sco_conn_ready(struct sco_conn *conn)
parent = sco_get_sock_listen(conn->src);
if (!parent) {
sco_conn_unlock(conn);
- return;
+ return 1;
}
bh_lock_sock(parent);
@@ -1008,7 +1008,7 @@ static void sco_conn_ready(struct sco_conn *conn)
if (!sk) {
bh_unlock_sock(parent);
sco_conn_unlock(conn);
- return;
+ return 0;
}
sco_sock_init(sk, parent);
@@ -1031,6 +1031,8 @@ static void sco_conn_ready(struct sco_conn *conn)
sco_conn_unlock(conn);
}
+
+ return 0;
}
/* ----- SCO interface with lower layer (HCI) ----- */
@@ -1061,7 +1063,7 @@ int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags)
return lm;
}
-void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
+int sco_connect_cfm(struct hci_conn *hcon, __u8 status)
{
BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
if (!status) {
@@ -1069,9 +1071,11 @@ void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
conn = sco_conn_add(hcon);
if (conn)
- sco_conn_ready(conn);
+ return sco_conn_ready(conn);
} else
sco_conn_del(hcon, bt_to_errno(status));
+
+ return 0;
}
void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 10/10] Bluetooth: Add SCO connection fallback
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
When initiating a transparent eSCO connection, make use of T2 settings
at first try. T2 is the recommended settings from HFP 1.6 WideBand
Speech. Upon connection failure, try T1 settings.
When CVSD is requested and eSCO is supported, try to establish eSCO
connection using S3 settings. If it fails, fallback in sequence to S2,
S1, D1, D0 settings.
To know which setting should be used, conn->attempt is used. It
indicates the currently ongoing SCO connection attempt and can be used
as the index for the fallback settings table.
These setting and the fallback order are described in Bluetooth HFP 1.6
specification p. 101.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 2 +-
net/bluetooth/hci_conn.c | 41 ++++++++++++++++++++++++++++++--------
net/bluetooth/hci_event.c | 6 +++---
3 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index b2bfab8..1f95e9b 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -570,7 +570,7 @@ static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
}
void hci_disconnect(struct hci_conn *conn, __u8 reason);
-void hci_setup_sync(struct hci_conn *conn, __u16 handle);
+int hci_setup_sync(struct hci_conn *conn, __u16 handle);
void hci_sco_setup(struct hci_conn *conn, __u8 status);
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index c0e56a5..d3befac 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -31,6 +31,24 @@
#include <net/bluetooth/a2mp.h>
#include <net/bluetooth/smp.h>
+struct sco_param {
+ u16 pkt_type;
+ u16 max_latency;
+};
+
+static const struct sco_param sco_param_cvsd[] = {
+ { EDR_ESCO_MASK & ~ESCO_2EV3, 0x000a }, /* S3 */
+ { EDR_ESCO_MASK & ~ESCO_2EV3, 0x0007 }, /* S2 */
+ { EDR_ESCO_MASK | ESCO_EV3, 0x0007 }, /* S1 */
+ { EDR_ESCO_MASK | ESCO_HV3, 0xffff }, /* D1 */
+ { EDR_ESCO_MASK | ESCO_HV1, 0xffff }, /* D0 */
+};
+
+static const struct sco_param sco_param_wideband[] = {
+ { EDR_ESCO_MASK & ~ESCO_2EV3, 0x000d }, /* T2 */
+ { EDR_ESCO_MASK | ESCO_EV3, 0x0008 }, /* T1 */
+};
+
static void hci_le_create_connection(struct hci_conn *conn)
{
struct hci_dev *hdev = conn->hdev;
@@ -172,10 +190,11 @@ static void hci_add_sco(struct hci_conn *conn, __u16 handle)
hci_send_cmd(hdev, HCI_OP_ADD_SCO, sizeof(cp), &cp);
}
-void hci_setup_sync(struct hci_conn *conn, __u16 handle)
+int hci_setup_sync(struct hci_conn *conn, __u16 handle)
{
struct hci_dev *hdev = conn->hdev;
struct hci_cp_setup_sync_conn cp;
+ const struct sco_param *param;
BT_DBG("hcon %p", conn);
@@ -192,19 +211,25 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
switch (conn->setting & SCO_AIRMODE_MASK) {
case SCO_AIRMODE_TRANSP:
- cp.pkt_type = __constant_cpu_to_le16(EDR_ESCO_MASK &
- ~ESCO_2EV3);
- cp.max_latency = __constant_cpu_to_le16(0x000d);
+ if (conn->attempt > ARRAY_SIZE(sco_param_wideband))
+ return -ECONNREFUSED;
cp.retrans_effort = 0x02;
+ param = &sco_param_wideband[conn->attempt - 1];
break;
case SCO_AIRMODE_CVSD:
- cp.pkt_type = cpu_to_le16(conn->pkt_type);
- cp.max_latency = __constant_cpu_to_le16(0xffff);
- cp.retrans_effort = 0xff;
+ if (conn->attempt > ARRAY_SIZE(sco_param_cvsd))
+ return -ECONNREFUSED;
+ cp.retrans_effort = 0x01;
+ param = &sco_param_cvsd[conn->attempt - 1];
break;
+ default:
+ return -EINVAL;
}
- hci_send_cmd(hdev, HCI_OP_SETUP_SYNC_CONN, sizeof(cp), &cp);
+ cp.pkt_type = __cpu_to_le16(param->pkt_type);
+ cp.max_latency = __cpu_to_le16(param->max_latency);
+
+ return hci_send_cmd(hdev, HCI_OP_SETUP_SYNC_CONN, sizeof(cp), &cp);
}
void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index a8bb7bb..491c5fb 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2909,11 +2909,11 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
case 0x1c: /* SCO interval rejected */
case 0x1a: /* Unsupported Remote Feature */
case 0x1f: /* Unspecified error */
- if (conn->out && conn->attempt < 2) {
+ if (conn->out) {
conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
(hdev->esco_type & EDR_ESCO_MASK);
- hci_setup_sync(conn, conn->link->handle);
- goto unlock;
+ if (hci_setup_sync(conn, conn->link->handle) == 0)
+ goto unlock;
}
/* fall through */
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 09/10] Bluetooth: Handle specific error for SCO connection fallback
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
Synchronous Connection Complete event can return error "Connection
Rejected due to Limited resources (0x10)".
Handling this error is required for SCO connection fallback. This error
happens when the server tried to accept the connection but failed to
negotiate settings.
This error code has been verified experimentally by sending a T2 request
to a T1 only SCO listener.
Client dump follows :
< HCI Command (0x01|0x0028) plen 17 [hci0] 3.696064
Handle: 12
Transmit bandwidth: 8000
Receive bandwidth: 8000
Max latency: 13
Setting: 0x0003
Retransmission effort: Optimize for link quality (0x02)
Packet type: 0x0380
> HCI Event (0x0f) plen 4 [hci0] 3.697034
Setup Synchronous Connection (0x01|0x0028) ncmd 1
Status: Success (0x00)
> HCI Event (0x2c) plen 17 [hci0] 3.736059
Status: Connection Rejected due to Limited Resources (0x0d)
Handle: 0
Address: xx:xx:xx:xx:xx:AB (OUI 70-F3-95)
Link type: eSCO (0x02)
Transmission interval: 0x0c
Retransmission window: 0x06
RX packet length: 60
TX packet length: 60
Air mode: Transparent (0x03)
Server dump follows :
> HCI Event (0x04) plen 10 [hci0] 4.741513
Address: xx:xx:xx:xx:xx:D9 (OUI 20-68-9D)
Class: 0x620100
Major class: Computer (desktop, notebook, PDA, organizers)
Minor class: Uncategorized, code for device not assigned
Networking (LAN, Ad hoc)
Audio (Speaker, Microphone, Headset)
Telephony (Cordless telephony, Modem, Headset)
Link type: eSCO (0x02)
< HCI Command (0x01|0x0029) plen 21 [hci0] 4.743269
Address: xx:xx:xx:xx:xx:D9 (OUI 20-68-9D)
Transmit bandwidth: 8000
Receive bandwidth: 8000
Max latency: 13
Setting: 0x0003
Retransmission effort: Optimize for link quality (0x02)
Packet type: 0x03c1
> HCI Event (0x0f) plen 4 [hci0] 4.745517
Accept Synchronous Connection (0x01|0x0029) ncmd 1
Status: Success (0x00)
> HCI Event (0x2c) plen 17 [hci0] 4.749508
Status: Connection Rejected due to Limited Resources (0x0d)
Handle: 0
Address: xx:xx:xx:xx:xx:D9 (OUI 20-68-9D)
Link type: eSCO (0x02)
Transmission interval: 0x0c
Retransmission window: 0x06
RX packet length: 60
TX packet length: 60
Air mode: Transparent (0x03)
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
---
net/bluetooth/hci_event.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 50e39f4..a8bb7bb 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2904,6 +2904,7 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
hci_conn_add_sysfs(conn);
break;
+ case 0x0d: /* Connection Rejected due to Limited Resources */
case 0x11: /* Unsupported Feature or Parameter Value */
case 0x1c: /* SCO interval rejected */
case 0x1a: /* Unsupported Remote Feature */
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 08/10] Bluetooth: Prevent transparent SCO on older devices
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
Older Bluetooth devices may not support Setup Synchronous Connection or
SCO transparent data. This is indicated by the corresponding LMP feature
bits. It is not possible to know if the adapter support these features
before setting BT_VOICE option since the socket is not bound to an
adapter. An adapter can also be added after the socket is created. The
socket can be bound to an address before adapter is plugged in.
Thus, on a such adapters, if user request BT_VOICE_TRANSPARENT, outgoing
connections fail on connect() and returns -EOPNOTSUPP. Incoming
connections do not fail. However, they should only be allowed depending
on what was specified in Write_Voice_Settings command.
EOPNOTSUPP is choosen because connect() system call is failing after
selecting route but before any connection attempt.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/sco.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index e82d792..1170b6e 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -176,6 +176,12 @@ static int sco_connect(struct sock *sk)
else
type = SCO_LINK;
+ if (sco_pi(sk)->setting == BT_VOICE_TRANSPARENT &&
+ (!lmp_transp_capable(hdev) || !lmp_esco_capable(hdev))) {
+ err = -EOPNOTSUPP;
+ goto done;
+ }
+
hcon = hci_connect_sco(hdev, type, dst, sco_pi(sk)->setting);
if (IS_ERR(hcon)) {
err = PTR_ERR(hcon);
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 07/10] Bluetooth: Add constants and macro declaration for transparent data
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
This patch defines constants and macro for transparent data LMP
features. It refers to Bluetooth Core V4.0 specification, Part C, Chap
3.3 which defines LMP feature mask.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 1 +
2 files changed, 2 insertions(+)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index a01fbb4..aaeaf09 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -238,6 +238,7 @@ enum {
#define LMP_CVSD 0x01
#define LMP_PSCHEME 0x02
#define LMP_PCONTROL 0x04
+#define LMP_TRANSPARENT 0x08
#define LMP_RSSI_INQ 0x40
#define LMP_ESCO 0x80
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 61ca2ce..b2bfab8 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -800,6 +800,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
#define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO)
#define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
#define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES)
+#define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT)
/* ----- Extended LMP capabilities ----- */
#define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 06/10] Bluetooth: Parameters for outgoing SCO connections
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
In order to establish a transparent SCO connection, the correct settings
must be specified in the Setup Synchronous Connection request. For that,
a setting field is added to ACL connection data to set up the desired
parameters. The patch also removes usage of hdev->voice_setting in CVSD
connection and makes use of T2 parameters for transparent data.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 5 +++--
net/bluetooth/hci_conn.c | 24 +++++++++++++++++++-----
net/bluetooth/sco.c | 2 +-
3 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index f403509..61ca2ce 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -320,6 +320,7 @@ struct hci_conn {
__u32 passkey_notify;
__u8 passkey_entered;
__u16 disc_timeout;
+ __u16 setting;
unsigned long flags;
__u8 remote_cap;
@@ -584,8 +585,8 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
__u8 dst_type, __u8 sec_level, __u8 auth_type);
-struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type,
- bdaddr_t *dst);
+struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
+ __u16 setting);
int hci_conn_check_link_mode(struct hci_conn *conn);
int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 5f1f448..c0e56a5 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -185,13 +185,24 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
conn->attempt++;
cp.handle = cpu_to_le16(handle);
- cp.pkt_type = cpu_to_le16(conn->pkt_type);
cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
- cp.max_latency = __constant_cpu_to_le16(0xffff);
- cp.voice_setting = cpu_to_le16(hdev->voice_setting);
- cp.retrans_effort = 0xff;
+ cp.voice_setting = cpu_to_le16(conn->setting);
+
+ switch (conn->setting & SCO_AIRMODE_MASK) {
+ case SCO_AIRMODE_TRANSP:
+ cp.pkt_type = __constant_cpu_to_le16(EDR_ESCO_MASK &
+ ~ESCO_2EV3);
+ cp.max_latency = __constant_cpu_to_le16(0x000d);
+ cp.retrans_effort = 0x02;
+ break;
+ case SCO_AIRMODE_CVSD:
+ cp.pkt_type = cpu_to_le16(conn->pkt_type);
+ cp.max_latency = __constant_cpu_to_le16(0xffff);
+ cp.retrans_effort = 0xff;
+ break;
+ }
hci_send_cmd(hdev, HCI_OP_SETUP_SYNC_CONN, sizeof(cp), &cp);
}
@@ -560,7 +571,8 @@ static struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
return acl;
}
-struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst)
+struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
+ __u16 setting)
{
struct hci_conn *acl;
struct hci_conn *sco;
@@ -583,6 +595,8 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst)
hci_conn_hold(sco);
+ sco->setting = setting;
+
if (acl->state == BT_CONNECTED &&
(sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
set_bit(HCI_CONN_POWER_SAVE, &acl->flags);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 3b3d24a..e82d792 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -176,7 +176,7 @@ static int sco_connect(struct sock *sk)
else
type = SCO_LINK;
- hcon = hci_connect_sco(hdev, type, dst);
+ hcon = hci_connect_sco(hdev, type, dst, sco_pi(sk)->setting);
if (IS_ERR(hcon)) {
err = PTR_ERR(hcon);
goto done;
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 05/10] Bluetooth: Use voice setting in deferred SCO connection request
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
When an incoming eSCO connection is requested, check the selected voice
setting and reply appropriately. Voice setting should have been
negotiated previously. For example, in case of HFP, the codec is
negotiated using AT commands on the RFCOMM channel. This patch only
changes replies for socket with deferred setup enabled.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/sco.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index e8cda67..3b3d24a 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -653,7 +653,7 @@ static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
return err;
}
-static void sco_conn_defer_accept(struct hci_conn *conn)
+static void sco_conn_defer_accept(struct hci_conn *conn, u16 setting)
{
struct hci_dev *hdev = conn->hdev;
@@ -676,9 +676,21 @@ static void sco_conn_defer_accept(struct hci_conn *conn)
cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
- cp.max_latency = __constant_cpu_to_le16(0xffff);
- cp.content_format = cpu_to_le16(hdev->voice_setting);
- cp.retrans_effort = 0xff;
+ cp.content_format = cpu_to_le16(setting);
+
+ switch (setting & SCO_AIRMODE_MASK) {
+ case SCO_AIRMODE_TRANSP:
+ if (conn->pkt_type & ESCO_2EV3)
+ cp.max_latency = __constant_cpu_to_le16(0x0008);
+ else
+ cp.max_latency = __constant_cpu_to_le16(0x000D);
+ cp.retrans_effort = 0x02;
+ break;
+ case SCO_AIRMODE_CVSD:
+ cp.max_latency = __constant_cpu_to_le16(0xffff);
+ cp.retrans_effort = 0xff;
+ break;
+ }
hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
sizeof(cp), &cp);
@@ -695,7 +707,7 @@ static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
if (sk->sk_state == BT_CONNECT2 &&
test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
- sco_conn_defer_accept(pi->conn->hcon);
+ sco_conn_defer_accept(pi->conn->hcon, pi->setting);
sk->sk_state = BT_CONFIG;
msg->msg_namelen = 0;
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 04/10] Bluetooth: Add constants for SCO airmode
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
This patch defines constants for SCO airmode from SCO voice setting. It
refers to Bluetooth Core V4.0 specification, Part E, Chap 6.12 which
describe SCO voice setting format.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 307a192..f403509 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1215,4 +1215,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
u8 bdaddr_to_le(u8 bdaddr_type);
+#define SCO_AIRMODE_MASK 0x0003
+#define SCO_AIRMODE_CVSD 0x0000
+#define SCO_AIRMODE_TRANSP 0x0003
+
#endif /* __HCI_CORE_H */
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 03/10] Bluetooth: Add Bluetooth socket voice option
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
This patch extends the current Bluetooth socket options with BT_VOICE.
This is intended to choose voice data type at runtime. It only applies
to SCO sockets. Incoming connections shall be setup during deferred
setup. Outgoing connections shall be setup before connect(). The desired
setting is stored in the SCO socket info. This patch declares needed
members, modifies getsockopt() and setsockopt().
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/bluetooth.h | 8 ++++++++
include/net/bluetooth/sco.h | 1 +
net/bluetooth/sco.c | 40 ++++++++++++++++++++++++++++++++++++-
3 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 10eb9b3..10d43d8 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -107,6 +107,14 @@ struct bt_power {
*/
#define BT_CHANNEL_POLICY_AMP_PREFERRED 2
+#define BT_VOICE 11
+struct bt_voice {
+ __u16 setting;
+};
+
+#define BT_VOICE_TRANSPARENT 0x0003
+#define BT_VOICE_CVSD_16BIT 0x0060
+
__printf(1, 2)
int bt_info(const char *fmt, ...);
__printf(1, 2)
diff --git a/include/net/bluetooth/sco.h b/include/net/bluetooth/sco.h
index 1e35c43..e252a31 100644
--- a/include/net/bluetooth/sco.h
+++ b/include/net/bluetooth/sco.h
@@ -73,6 +73,7 @@ struct sco_conn {
struct sco_pinfo {
struct bt_sock bt;
__u32 flags;
+ __u16 setting;
struct sco_conn *conn;
};
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 05c2fc1..e8cda67 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -416,6 +416,8 @@ static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int pro
sk->sk_protocol = proto;
sk->sk_state = BT_OPEN;
+ sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT;
+
setup_timer(&sk->sk_timer, sco_sock_timeout, (unsigned long)sk);
bt_sock_link(&sco_sk_list, sk);
@@ -709,7 +711,8 @@ static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
{
struct sock *sk = sock->sk;
- int err = 0;
+ int len, err = 0;
+ struct bt_voice voice;
u32 opt;
BT_DBG("sk %p", sk);
@@ -735,6 +738,31 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char
clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
break;
+ case BT_VOICE:
+ if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
+ sk->sk_state != BT_CONNECT2) {
+ err = -EINVAL;
+ break;
+ }
+
+ voice.setting = sco_pi(sk)->setting;
+
+ len = min_t(unsigned int, sizeof(voice), optlen);
+ if (copy_from_user((char *) &voice, optval, len)) {
+ err = -EFAULT;
+ break;
+ }
+
+ /* Explicitly check for these values */
+ if (voice.setting != BT_VOICE_TRANSPARENT &&
+ voice.setting != BT_VOICE_CVSD_16BIT) {
+ err = -EINVAL;
+ break;
+ }
+
+ sco_pi(sk)->setting = voice.setting;
+ break;
+
default:
err = -ENOPROTOOPT;
break;
@@ -804,6 +832,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char
{
struct sock *sk = sock->sk;
int len, err = 0;
+ struct bt_voice voice;
BT_DBG("sk %p", sk);
@@ -829,6 +858,15 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char
break;
+ case BT_VOICE:
+ voice.setting = sco_pi(sk)->setting;
+
+ len = min_t(unsigned int, len, sizeof(voice));
+ if (copy_to_user(optval, (char *)&voice, len))
+ err = -EFAULT;
+
+ break;
+
default:
err = -ENOPROTOOPT;
break;
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 02/10] Bluetooth: Remove unused mask parameter in sco_conn_defer_accept
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
>From Bluetooth Core v4.0 specification, 7.1.8 Accept Connection Request
Command "When accepting synchronous connection request, the Role
parameter is not used and will be ignored by the BR/EDR Controller."
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/sco.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 9e20a30..05c2fc1 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -651,7 +651,7 @@ static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
return err;
}
-static void sco_conn_defer_accept(struct hci_conn *conn, int mask)
+static void sco_conn_defer_accept(struct hci_conn *conn)
{
struct hci_dev *hdev = conn->hdev;
@@ -663,11 +663,7 @@ static void sco_conn_defer_accept(struct hci_conn *conn, int mask)
struct hci_cp_accept_conn_req cp;
bacpy(&cp.bdaddr, &conn->dst);
-
- if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
- cp.role = 0x00; /* Become master */
- else
- cp.role = 0x01; /* Remain slave */
+ cp.role = 0x00; /* Ignored */
hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
} else {
@@ -697,7 +693,7 @@ static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
if (sk->sk_state == BT_CONNECT2 &&
test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
- sco_conn_defer_accept(pi->conn->hcon, 0);
+ sco_conn_defer_accept(pi->conn->hcon);
sk->sk_state = BT_CONFIG;
msg->msg_namelen = 0;
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 01/10] Bluetooth: Use hci_connect_sco directly
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau, Johan Hedberg
In-Reply-To: <1376499814-11386-1-git-send-email-frederic.dalleau@linux.intel.com>
hci_connect is a super function for connecting hci protocols. But the
voice_setting parameter (introduced in subsequent patches) is only
needed by SCO and security requirements are not needed for SCO channels.
Thus, it makes sense to have a separate function for SCO.
Signed-off-by: Frédéric Dalleau <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_conn.c | 8 ++------
net/bluetooth/sco.c | 3 +--
3 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index f77885e..307a192 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -584,6 +584,8 @@ struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
__u8 dst_type, __u8 sec_level, __u8 auth_type);
+struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type,
+ bdaddr_t *dst);
int hci_conn_check_link_mode(struct hci_conn *conn);
int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 6c7f363..5f1f448 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -560,13 +560,12 @@ static struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
return acl;
}
-static struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type,
- bdaddr_t *dst, u8 sec_level, u8 auth_type)
+struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst)
{
struct hci_conn *acl;
struct hci_conn *sco;
- acl = hci_connect_acl(hdev, dst, sec_level, auth_type);
+ acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING);
if (IS_ERR(acl))
return acl;
@@ -612,9 +611,6 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
return hci_connect_le(hdev, dst, dst_type, sec_level, auth_type);
case ACL_LINK:
return hci_connect_acl(hdev, dst, sec_level, auth_type);
- case SCO_LINK:
- case ESCO_LINK:
- return hci_connect_sco(hdev, type, dst, sec_level, auth_type);
}
return ERR_PTR(-EINVAL);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index e7bd4ee..9e20a30 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -176,8 +176,7 @@ static int sco_connect(struct sock *sk)
else
type = SCO_LINK;
- hcon = hci_connect(hdev, type, dst, BDADDR_BREDR, BT_SECURITY_LOW,
- HCI_AT_NO_BONDING);
+ hcon = hci_connect_sco(hdev, type, dst);
if (IS_ERR(hcon)) {
err = PTR_ERR(hcon);
goto done;
--
1.7.9.5
^ permalink raw reply related
* [PATCH v10 00/10] sco: SCO socket option for voice_setting
From: Frédéric Dalleau @ 2013-08-14 17:03 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Frédéric Dalleau
Hi,
v10 include contribution from Johan, he reworks fallback handling and fixes
Marcel remarks from v9.
error 0x0d handling moved into a separate patch
v9 is mostly cosmetics. Introduces LMP_TRANSPARENT bit in patch 8/8.
v8 declares BT_VOICE_CVSD_16BIT
Merge T*, S* and D* patches in one
The last patch returns -ECONNABORTED when trying to setup a transparent data
connection if eSCO is not supported.
v7 changes defaults to BT_VOICE_CVSD
Remove mask parameter to sco_conn_defer_accept, it was always 0
check the bits for air codec instead of use constants.
Add S3, S2, S1, D1, D0 settings.
The controller default is now only used to initialize the controller or fill
in the missing information in case of using the old Add_SCO command
v6 fixes style issues
v5 changes interface to SOL_BLUETOOTH, BT_VOICE.
Rework fallback mechanism.
This is the patch version 4 of the socket option for enabling transparent SCO.
As requested by Marcel, this is now a 16-bit voice_setting.
0x0000 is the value corresponding to current behavior.
0x0003 is the value to use for enabling transparent data.
It is easy to allow all possible values from Bluetooth core spec, but I guess
results can be unexpected...
Should we filter allowed values in setsockopt ?
Let me know what you think.
Regards,
Fred
Frédéric Dalleau (10):
Bluetooth: Use hci_connect_sco directly
Bluetooth: Remove unused mask parameter in sco_conn_defer_accept
Bluetooth: Add Bluetooth socket voice option
Bluetooth: Add constants for SCO airmode
Bluetooth: Use voice setting in deferred SCO connection request
Bluetooth: Parameters for outgoing SCO connections
Bluetooth: Add constants and macro declaration for transparent data
Bluetooth: Prevent transparent SCO on older devices
Bluetooth: Handle specific error for SCO connection fallback
Bluetooth: Add SCO connection fallback
include/net/bluetooth/bluetooth.h | 8 ++++
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 10 ++++-
include/net/bluetooth/sco.h | 1 +
net/bluetooth/hci_conn.c | 59 ++++++++++++++++++++++------
net/bluetooth/hci_event.c | 7 ++--
net/bluetooth/sco.c | 77 ++++++++++++++++++++++++++++++-------
7 files changed, 134 insertions(+), 29 deletions(-)
--
1.7.9.5
^ permalink raw reply
* [PATCH] Bluetooth: Set different event mask for LE-only controllers
From: Marcel Holtmann @ 2013-08-13 17:00 UTC (permalink / raw)
To: linux-bluetooth
In case of a Low Energy only controller it makes no sense to configure
the full BR/EDR event mask. It will just enable events that can not be
send anyway and there is no guarantee that such a controller will accept
this value.
Use event mask 0x90 0xe8 0x04 0x02 0x00 0x80 0x00 0x20 for LE-only
controllers which enables the following events:
Disconnection Complete
Encryption Change
Read Remote Version Information Complete
Command Complete
Command Status
Hardware Error
Number of Completed Packets
Data Buffer Overflow
Encryption Key Refresh Complete
LE Meta
This is according to Core Specification, Part E, Section 3.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/hci_core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index b821b19..8d9b87d 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -454,6 +454,18 @@ static void hci_setup_event_mask(struct hci_request *req)
events[4] |= 0x04; /* Read Remote Extended Features Complete */
events[5] |= 0x08; /* Synchronous Connection Complete */
events[5] |= 0x10; /* Synchronous Connection Changed */
+ } else {
+ /* Use a different default for LE-only devices */
+ memset(events, 0, sizeof(events));
+ events[0] |= 0x10; /* Disconnection Complete */
+ events[0] |= 0x80; /* Encryption Change */
+ events[1] |= 0x08; /* Read Remote Version Information Complete */
+ events[1] |= 0x20; /* Command Complete */
+ events[1] |= 0x40; /* Command Status */
+ events[1] |= 0x80; /* Hardware Error */
+ events[2] |= 0x04; /* Number of Completed Packets */
+ events[3] |= 0x02; /* Data Buffer Overflow */
+ events[5] |= 0x80; /* Encryption Key Refresh Complete */
}
if (lmp_inq_rssi_capable(hdev))
--
1.8.3.1
^ permalink raw reply related
* Bluez Certification
From: Cesare Magri @ 2013-08-13 13:18 UTC (permalink / raw)
To: linux-bluetooth
Dear All,
I have a question regarding the BT certification of systems when using
Bluez.
Can I use Bluez together with any HCI BT-certified module without having to
repeat the BT certification, i.e. using the BT logo on my device?
Or is the BT-certification of Bluez valid only for certain Modules? If yes
which ones?
Many thanks in advance for your reply.
Cesare
^ permalink raw reply
* Re: [PATCH 1/3] sco-tester: Update ECONNABORTED to EOPNOTSUPP
From: Frédéric DALLEAU @ 2013-08-13 13:10 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <88BDC584-6DC7-457A-92B3-3C00D30CCEBC@holtmann.org>
Hi Marcel,
Le 13/08/2013 01:22, Marcel Holtmann a écrit :
> However I only looked at the error codes you listed in this email. Maybe there is even a better one, maybe there is not. I am pretty much open to discuss alternatives here.
Thanks for detailed feedback. For the vast majority of other errors
code, there was no need to go through code to eliminate them: Their
purpose if usually very restrictive.
Let's list some potential candidate just in case:
#define ENOSYS 38 /* Function not implemented */
#define ENOSR 63 /* Out of streams resources */
#define ENOMEDIUM 123 /* No medium found */
Regards,
Frederic
^ permalink raw reply
* Re: [PATCH 1/3] sco-tester: Update ECONNABORTED to EOPNOTSUPP
From: Marcel Holtmann @ 2013-08-12 23:22 UTC (permalink / raw)
To: Frédéric DALLEAU; +Cc: linux-bluetooth
In-Reply-To: <52089E1F.60704@linux.intel.com>
Hi Fred,
>> can we please have a proper thread on what error is appropriate to send > from a socket interface when this situation happens. I see that
> > we are flipping errors, but my request to discuss this gets ignored.
>>
>
> I already gave my opinion previously. Let's recall it :"About the error ECONNABORTED, it is what the patch does : abort a connection. It is not used for other purposes. If you really want to change, I'm ok with EOPNOTSUPP, otherwise please suggest."
the last patchset that I reviewed had a different error code in the commit message than it had in the implementation. For me it is then impossible to understand what you intent was. Also an explanation why which error code is picked is important.
I really want commit messages be explanatory on why things a done this way. Use it as introduction to a patch and its justification.
> Regarding EOPNOTSUPP. Most use case are when a pointer in an interface is not implemented. We could consider that SetupSyncConn is not implemented in 2.0 adapter interfaces.
I spent some extra time now to dig into EOPNOTSUPP and how it is used in the current network subsystems the Linux kernel has. I normally refers to a local operation that is not supported. It is rarely used within the connect() system call, but it is indeed used there.
When EOPNOTSUPP is used, then it is in the context of the connect() system call implementation. It is used before any connection attempt is made. An example is when calling connect() on a DGRAM socket, but it only supports connect() in the STREAM socket.
For ECONNABORTED it is normally used in the context when the connection attempt is already in progress and it is then normally delivered via sk->sk_err to the user of the socket.
> > Please look for a good reference of the error code usage in other socket protocols or manpages
>
> It is not obvious to find one good reference. But for example there is : Documentation/ioctl/hdio.txt: EOPNOTSUPP Hardware interface does not support bus power
>
> Another option could be:
> [ENODEV]
> No such device An attempt was made to apply an inappropriate function to a device; for example, trying to read a write-only device such as a printer.
ENODEV is not meant for sockets. We use it inside the Bluetooth subsystem for errors that relate to HCI devices, HID/input devices or TTY devices.
In summary so far we have the closest match with EOPNOTSUPP for one reason. The connect() system call is actually failing without any connection attempt. It tries to find the local controller assigned to this socket and if it does not support eSCO, it bails out. That makes it fall in line with how it should be used if we look at other systems calls or socket families.
However I only looked at the error codes you listed in this email. Maybe there is even a better one, maybe there is not. I am pretty much open to discuss alternatives here.
Regards
Marcel
^ permalink raw reply
* [PATCH v2] Bluetooth: Remove assignment in if
From: Valentin Ilie @ 2013-08-12 15:46 UTC (permalink / raw)
To: marcel, gustavo, johan.hedberg, Dean_Jenkins
Cc: linux-bluetooth, Valentin Ilie
In-Reply-To: <1376225793-22981-1-git-send-email-valentin.ilie@gmail.com>
Remove assignment in if
Signed-off-by: Valentin Ilie <valentin.ilie@gmail.com>
---
drivers/bluetooth/ath3k.c | 7 +++----
drivers/bluetooth/bfusb.c | 14 ++++++++++----
drivers/bluetooth/bluecard_cs.c | 9 ++++++---
drivers/bluetooth/bt3c_cs.c | 7 ++++---
drivers/bluetooth/btuart_cs.c | 6 ++++--
drivers/bluetooth/dtl1_cs.c | 9 ++++++---
drivers/bluetooth/hci_bcsp.c | 26 +++++++++++++++-----------
drivers/bluetooth/hci_h5.c | 6 ++++--
drivers/bluetooth/hci_ldisc.c | 9 ++++++---
9 files changed, 58 insertions(+), 35 deletions(-)
diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index a12b923..bdefdfc 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -166,10 +166,9 @@ static int ath3k_load_firmware(struct usb_device *udev,
}
memcpy(send_buf, firmware->data, 20);
- if ((err = usb_control_msg(udev, pipe,
- USB_REQ_DFU_DNLOAD,
- USB_TYPE_VENDOR, 0, 0,
- send_buf, 20, USB_CTRL_SET_TIMEOUT)) < 0) {
+ err = usb_control_msg(udev, pipe, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR,
+ 0, 0, send_buf, 20, USB_CTRL_SET_TIMEOUT);
+ if (err < 0) {
BT_ERR("Can't change to loading configuration err");
goto error;
}
diff --git a/drivers/bluetooth/bfusb.c b/drivers/bluetooth/bfusb.c
index 995aee9..2306b0b 100644
--- a/drivers/bluetooth/bfusb.c
+++ b/drivers/bluetooth/bfusb.c
@@ -131,8 +131,11 @@ static int bfusb_send_bulk(struct bfusb_data *data, struct sk_buff *skb)
BT_DBG("bfusb %p skb %p len %d", data, skb, skb->len);
- if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
- return -ENOMEM;
+ if (!urb) {
+ urb = usb_alloc_urb(0, GFP_ATOMIC);
+ if (!urb)
+ return -ENOMEM;
+ }
pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
@@ -218,8 +221,11 @@ static int bfusb_rx_submit(struct bfusb_data *data, struct urb *urb)
BT_DBG("bfusb %p urb %p", data, urb);
- if (!urb && !(urb = usb_alloc_urb(0, GFP_ATOMIC)))
- return -ENOMEM;
+ if (!urb) {
+ urb = usb_alloc_urb(0, GFP_ATOMIC);
+ if (!urb)
+ return -ENOMEM;
+ }
skb = bt_skb_alloc(size, GFP_ATOMIC);
if (!skb) {
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 6c3e3d4..b09e3a9 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -257,7 +257,8 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
ready_bit = XMIT_BUF_ONE_READY;
}
- if (!(skb = skb_dequeue(&(info->txq))))
+ skb = skb_dequeue(&(info->txq));
+ if (!skb)
break;
if (bt_cb(skb)->pkt_type & 0x80) {
@@ -391,7 +392,8 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
if (info->rx_skb == NULL) {
info->rx_state = RECV_WAIT_PACKET_TYPE;
info->rx_count = 0;
- if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
+ info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+ if (!info->rx_skb) {
BT_ERR("Can't allocate mem for new packet");
return;
}
@@ -567,7 +569,8 @@ static int bluecard_hci_set_baud_rate(struct hci_dev *hdev, int baud)
/* Ericsson baud rate command */
unsigned char cmd[] = { HCI_COMMAND_PKT, 0x09, 0xfc, 0x01, 0x03 };
- if (!(skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
+ skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+ if (!skb) {
BT_ERR("Can't allocate mem for new packet");
return -1;
}
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index a1aaa3b..653c109 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -193,8 +193,8 @@ static void bt3c_write_wakeup(bt3c_info_t *info)
if (!pcmcia_dev_present(info->p_dev))
break;
-
- if (!(skb = skb_dequeue(&(info->txq)))) {
+ skb = skb_dequeue(&(info->txq));
+ if (!skb) {
clear_bit(XMIT_SENDING, &(info->tx_state));
break;
}
@@ -238,7 +238,8 @@ static void bt3c_receive(bt3c_info_t *info)
if (info->rx_skb == NULL) {
info->rx_state = RECV_WAIT_PACKET_TYPE;
info->rx_count = 0;
- if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
+ info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+ if (!info->rx_skb) {
BT_ERR("Can't allocate mem for new packet");
return;
}
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index beb262f..4f99e05 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -149,7 +149,8 @@ static void btuart_write_wakeup(btuart_info_t *info)
if (!pcmcia_dev_present(info->p_dev))
return;
- if (!(skb = skb_dequeue(&(info->txq))))
+ skb = skb_dequeue(&(info->txq));
+ if (!skb)
break;
/* Send frame */
@@ -190,7 +191,8 @@ static void btuart_receive(btuart_info_t *info)
if (info->rx_skb == NULL) {
info->rx_state = RECV_WAIT_PACKET_TYPE;
info->rx_count = 0;
- if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
+ info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+ if (!info->rx_skb) {
BT_ERR("Can't allocate mem for new packet");
return;
}
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 33f3a69..358694e 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -153,7 +153,8 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
if (!pcmcia_dev_present(info->p_dev))
return;
- if (!(skb = skb_dequeue(&(info->txq))))
+ skb = skb_dequeue(&(info->txq));
+ if (!skb)
break;
/* Send frame */
@@ -215,13 +216,15 @@ static void dtl1_receive(dtl1_info_t *info)
info->hdev->stat.byte_rx++;
/* Allocate packet */
- if (info->rx_skb == NULL)
- if (!(info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC))) {
+ if (info->rx_skb == NULL) {
+ info->rx_skb = bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
+ if (!info->rx_skb) {
BT_ERR("Can't allocate mem for new packet");
info->rx_state = RECV_WAIT_NSH;
info->rx_count = NSHL;
return;
}
+ }
*skb_put(info->rx_skb, 1) = inb(iobase + UART_RX);
nsh = (nsh_t *)info->rx_skb->data;
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 57e502e..442f836 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -291,7 +291,8 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
/* First of all, check for unreliable messages in the queue,
since they have priority */
- if ((skb = skb_dequeue(&bcsp->unrel)) != NULL) {
+ skb = skb_dequeue(&bcsp->unrel);
+ if (skb != NULL) {
struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
if (nskb) {
kfree_skb(skb);
@@ -308,16 +309,19 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING);
- if (bcsp->unack.qlen < BCSP_TXWINSIZE && (skb = skb_dequeue(&bcsp->rel)) != NULL) {
- struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
- if (nskb) {
- __skb_queue_tail(&bcsp->unack, skb);
- mod_timer(&bcsp->tbcsp, jiffies + HZ / 4);
- spin_unlock_irqrestore(&bcsp->unack.lock, flags);
- return nskb;
- } else {
- skb_queue_head(&bcsp->rel, skb);
- BT_ERR("Could not dequeue pkt because alloc_skb failed");
+ if (bcsp->unack.qlen < BCSP_TXWINSIZE) {
+ skb = skb_dequeue(&bcsp->rel);
+ if (skb != NULL) {
+ struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
+ if (nskb) {
+ __skb_queue_tail(&bcsp->unack, skb);
+ mod_timer(&bcsp->tbcsp, jiffies + HZ / 4);
+ spin_unlock_irqrestore(&bcsp->unack.lock, flags);
+ return nskb;
+ } else {
+ skb_queue_head(&bcsp->rel, skb);
+ BT_ERR("Could not dequeue pkt because alloc_skb failed");
+ }
}
}
diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index b6154d5..4e75763 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -673,7 +673,8 @@ static struct sk_buff *h5_dequeue(struct hci_uart *hu)
return h5_prepare_pkt(hu, HCI_3WIRE_LINK_PKT, wakeup_req, 2);
}
- if ((skb = skb_dequeue(&h5->unrel)) != NULL) {
+ skb = skb_dequeue(&h5->unrel);
+ if (skb != NULL) {
nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
skb->data, skb->len);
if (nskb) {
@@ -690,7 +691,8 @@ static struct sk_buff *h5_dequeue(struct hci_uart *hu)
if (h5->unack.qlen >= h5->tx_win)
goto unlock;
- if ((skb = skb_dequeue(&h5->rel)) != NULL) {
+ skb = skb_dequeue(&h5->rel);
+ if (skb != NULL) {
nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
skb->data, skb->len);
if (nskb) {
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index bc68a44..4a052b5 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -279,7 +279,8 @@ static int hci_uart_tty_open(struct tty_struct *tty)
if (tty->ops->write == NULL)
return -EOPNOTSUPP;
- if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
+ hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL);
+ if (!hu) {
BT_ERR("Can't allocate control structure");
return -ENFILE;
}
@@ -577,7 +578,8 @@ static int __init hci_uart_init(void)
hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
hci_uart_ldisc.owner = THIS_MODULE;
- if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
+ err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
+ if (err) {
BT_ERR("HCI line discipline registration failed. (%d)", err);
return err;
}
@@ -622,7 +624,8 @@ static void __exit hci_uart_exit(void)
#endif
/* Release tty registration of line discipline */
- if ((err = tty_unregister_ldisc(N_HCI)))
+ err = tty_unregister_ldisc(N_HCI);
+ if (err)
BT_ERR("Can't unregister HCI line discipline (%d)", err);
}
--
1.8.1.2
^ permalink raw reply related
* [PATCH BlueZ] build: Fix not checking readline.h for bluetooth-player
From: Luiz Augusto von Dentz @ 2013-08-12 12:03 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If --disable-client is passed to configure script is possible to build
BlueZ without readline which would cause the following error:
tools/bluetooth-player.c:36:31: fatal error: readline/readline.h: No such file or directory
#include <readline/readline.h>
^
---
Makefile.tools | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/Makefile.tools b/Makefile.tools
index 3bb0e82..4bcb18e 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -172,8 +172,7 @@ if EXPERIMENTAL
noinst_PROGRAMS += tools/bdaddr tools/avinfo tools/avtest tools/scotest \
tools/hcieventmask tools/hcisecfilter tools/hwdb \
tools/btmgmt tools/btattach tools/btsnoop \
- tools/btiotest tools/mpris-player \
- tools/bluetooth-player
+ tools/btiotest tools/mpris-player
tools_bdaddr_SOURCES = tools/bdaddr.c src/oui.h src/oui.c
tools_bdaddr_LDADD = lib/libbluetooth-internal.la @UDEV_LIBS@
@@ -199,17 +198,13 @@ tools_btiotest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
tools_mpris_player_SOURCES = tools/mpris-player.c
tools_mpris_player_LDADD = gdbus/libgdbus-internal.la @GLIB_LIBS@ @DBUS_LIBS@
-tools_bluetooth_player_SOURCES = tools/bluetooth-player.c \
- client/display.h client/display.c
-tools_bluetooth_player_LDADD = gdbus/libgdbus-internal.la \
- @GLIB_LIBS@ @DBUS_LIBS@ -lreadline
-
EXTRA_DIST += tools/bdaddr.1
endif
if READLINE
noinst_PROGRAMS += attrib/gatttool \
- tools/obex-client-tool tools/obex-server-tool
+ tools/obex-client-tool tools/obex-server-tool \
+ tools/bluetooth-player
attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
attrib/gattrib.c btio/btio.c \
@@ -226,6 +221,11 @@ tools_obex_client_tool_LDADD = lib/libbluetooth-internal.la \
tools_obex_server_tool_SOURCES = $(gobex_sources) $(btio_sources) \
tools/obex-server-tool.c
tools_obex_server_tool_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+
+tools_bluetooth_player_SOURCES = tools/bluetooth-player.c \
+ client/display.h client/display.c
+tools_bluetooth_player_LDADD = gdbus/libgdbus-internal.la \
+ @GLIB_LIBS@ @DBUS_LIBS@ -lreadline
endif
if EXPERIMENTAL
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH BlueZ 1/3] gobex: Add proper message to transfer errors
From: Luiz Augusto von Dentz @ 2013-08-12 10:53 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
In-Reply-To: <1375969749-2097-1-git-send-email-luiz.dentz@gmail.com>
Hi,
On Thu, Aug 8, 2013 at 4:49 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> This improve the error message when a transfer fails by using
> g_obex_strerror to decode the response code to a human readable string.
> ---
> gobex/gobex-transfer.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
> index ac8836c..4203fec 100644
> --- a/gobex/gobex-transfer.c
> +++ b/gobex/gobex-transfer.c
> @@ -207,8 +207,8 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
>
> rspcode = g_obex_packet_get_operation(rsp, &final);
> if (rspcode != G_OBEX_RSP_SUCCESS && rspcode != G_OBEX_RSP_CONTINUE) {
> - err = g_error_new(G_OBEX_ERROR, rspcode,
> - "Transfer failed (0x%02x)", rspcode);
> + err = g_error_new(G_OBEX_ERROR, rspcode, "%s",
> + g_obex_strerror(rspcode));
> goto failed;
> }
>
> --
> 1.8.3.1
I went ahead and applied patches 1 and 3, for patch 2 I will wait for
feedback as the filler byte is something Bluetooth specific it can be
controversial.
--
Luiz Augusto von Dentz
^ permalink raw reply
* Re: [PATCH] Bluetooth: clean up
From: Dean Jenkins @ 2013-08-12 9:16 UTC (permalink / raw)
To: Valentin Ilie; +Cc: marcel, gustavo, johan.hedberg, linux-bluetooth
In-Reply-To: <1376225793-22981-1-git-send-email-valentin.ilie@gmail.com>
On 11/08/13 13:56, Valentin Ilie wrote:
> Clean up bluetooth files
> - replace foo* bar with foo *bar
> - add space arround '='
> - remove trailing witespaces
> - remove assignment in if
> - fix coding style issues
I suggest you split the commits into 2:
a) commit with whitespace changes
b) commit with other coding style changes that cause C statements to be
rewritten.
This makes it easier for people to separate whitespace changes from
technical changes to the C code.
Also it would help people back-porting these commits to older kernels.
>
> Signed-off-by: Valentin Ilie <valentin.ilie@gmail.com>
> ---
> drivers/bluetooth/Kconfig | 12 +++++------
> drivers/bluetooth/dtl1_cs.c | 6 +++---
> drivers/bluetooth/hci_bcsp.c | 48 +++++++++++++++++++++--------------------
> drivers/bluetooth/hci_h5.c | 6 ++++--
> drivers/bluetooth/hci_ldisc.c | 15 +++++++------
> drivers/bluetooth/hci_vhci.c | 4 ++--
> 6 files changed, 49 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
> index 11a6104..6421414 100644
> --- a/drivers/bluetooth/Kconfig
> +++ b/drivers/bluetooth/Kconfig
> @@ -30,8 +30,8 @@ config BT_HCIUART
> help
> Bluetooth HCI UART driver.
> This driver is required if you want to use Bluetooth devices with
> - serial port interface. You will also need this driver if you have
> - UART based Bluetooth PCMCIA and CF devices like Xircom Credit Card
> + serial port interface. You will also need this driver if you have
> + UART based Bluetooth PCMCIA and CF devices like Xircom Credit Card
> adapter and BrainBoxes Bluetooth PC Card.
>
> Say Y here to compile support for Bluetooth UART devices into the
> @@ -41,9 +41,9 @@ config BT_HCIUART_H4
> bool "UART (H4) protocol support"
> depends on BT_HCIUART
> help
> - UART (H4) is serial protocol for communication between Bluetooth
> - device and host. This protocol is required for most Bluetooth devices
> - with UART interface, including PCMCIA and CF cards.
> + UART (H4) is serial protocol for communication between Bluetooth
> + device and host. This protocol is required for most Bluetooth devices
> + with UART interface, including PCMCIA and CF cards.
>
> Say Y here to compile support for HCI UART (H4) protocol.
>
> @@ -52,7 +52,7 @@ config BT_HCIUART_BCSP
> depends on BT_HCIUART
> select BITREVERSE
> help
> - BCSP (BlueCore Serial Protocol) is serial protocol for communication
> + BCSP (BlueCore Serial Protocol) is serial protocol for communication
> between Bluetooth device and host. This protocol is required for non
> USB Bluetooth devices based on CSR BlueCore chip, including PCMCIA and
> CF cards.
> diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
> index 33f3a69..3b89c0d 100644
> --- a/drivers/bluetooth/dtl1_cs.c
> +++ b/drivers/bluetooth/dtl1_cs.c
> @@ -153,7 +153,8 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
> if (!pcmcia_dev_present(info->p_dev))
> return;
>
> - if (!(skb = skb_dequeue(&(info->txq))))
> + skb = skb_dequeue(&(info->txq));
> + if (!skb)
> break;
>
> /* Send frame */
> @@ -181,9 +182,8 @@ static void dtl1_control(dtl1_info_t *info, struct sk_buff *skb)
> int i;
>
> printk(KERN_INFO "Bluetooth: Nokia control data =");
> - for (i = 0; i < skb->len; i++) {
> + for (i = 0; i < skb->len; i++)
> printk(" %02x", skb->data[i]);
> - }
> printk("\n");
>
> /* transition to active state */
> diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
> index 57e502e..fbd54e8 100644
> --- a/drivers/bluetooth/hci_bcsp.c
> +++ b/drivers/bluetooth/hci_bcsp.c
> @@ -105,11 +105,11 @@ static const u16 crc_table[] = {
> #define BCSP_CRC_INIT(x) x = 0xffff
>
> /*
> - Update crc with next data byte
> + Update crc with next data byte
>
> - Implementation note
> - The data byte is treated as two nibbles. The crc is generated
> - in reverse, i.e., bits are fed into the register from the top.
> + Implementation note
> + The data byte is treated as two nibbles. The crc is generated
> + in reverse, i.e., bits are fed into the register from the top.
> */
> static void bcsp_crc_update(u16 *crc, u8 d)
> {
> @@ -287,11 +287,12 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
> struct bcsp_struct *bcsp = hu->priv;
> unsigned long flags;
> struct sk_buff *skb;
> -
> +
> /* First of all, check for unreliable messages in the queue,
> since they have priority */
>
> - if ((skb = skb_dequeue(&bcsp->unrel)) != NULL) {
> + skb = skb_dequeue(&bcsp->unrel);
> + if (skb != NULL) {
> struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
> if (nskb) {
> kfree_skb(skb);
> @@ -308,7 +309,8 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
>
> spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING);
>
> - if (bcsp->unack.qlen < BCSP_TXWINSIZE && (skb = skb_dequeue(&bcsp->rel)) != NULL) {
> + skb = skb_dequeue(&bcsp->rel);
> + if (bcsp->unack.qlen < BCSP_TXWINSIZE && skb != NULL) {
THIS CHANGE IS INCORRECT.
The call to skb_dequeue() depends on bcsp->unack.qlen < BCSP_TXWINSIZE
being true. In other words the 2nd condition of && is not executed when
the 1st condition is false. Therefore 2 nested if statements are needed.
> struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
> if (nskb) {
> __skb_queue_tail(&bcsp->unack, skb);
> @@ -433,7 +435,7 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
> break;
> default:
> memcpy(skb_put(bcsp->rx_skb, 1), &byte, 1);
> - if ((bcsp->rx_skb-> data[0] & 0x40) != 0 &&
> + if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
> bcsp->rx_state != BCSP_W4_CRC)
> bcsp_crc_update(&bcsp->message_crc, byte);
> bcsp->rx_count--;
> @@ -444,24 +446,24 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
> switch (byte) {
> case 0xdc:
> memcpy(skb_put(bcsp->rx_skb, 1), &c0, 1);
> - if ((bcsp->rx_skb-> data[0] & 0x40) != 0 &&
> + if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
> bcsp->rx_state != BCSP_W4_CRC)
> - bcsp_crc_update(&bcsp-> message_crc, 0xc0);
> + bcsp_crc_update(&bcsp->message_crc, 0xc0);
> bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC;
> bcsp->rx_count--;
> break;
>
> case 0xdd:
> memcpy(skb_put(bcsp->rx_skb, 1), &db, 1);
> - if ((bcsp->rx_skb-> data[0] & 0x40) != 0 &&
> - bcsp->rx_state != BCSP_W4_CRC)
> - bcsp_crc_update(&bcsp-> message_crc, 0xdb);
> + if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
> + bcsp->rx_state != BCSP_W4_CRC)
> + bcsp_crc_update(&bcsp->message_crc, 0xdb);
> bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC;
> bcsp->rx_count--;
> break;
>
> default:
> - BT_ERR ("Invalid byte %02x after esc byte", byte);
> + BT_ERR("Invalid byte %02x after esc byte", byte);
> kfree_skb(bcsp->rx_skb);
> bcsp->rx_skb = NULL;
> bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
> @@ -524,9 +526,9 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu)
>
> hci_recv_frame(bcsp->rx_skb);
> } else {
> - BT_ERR ("Packet for unknown channel (%u %s)",
> + BT_ERR("Packet for unknown channel (%u %s)",
> bcsp->rx_skb->data[1] & 0x0f,
> - bcsp->rx_skb->data[0] & 0x80 ?
> + bcsp->rx_skb->data[0] & 0x80 ?
> "reliable" : "unreliable");
> kfree_skb(bcsp->rx_skb);
> }
> @@ -554,7 +556,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
> struct bcsp_struct *bcsp = hu->priv;
> unsigned char *ptr;
>
> - BT_DBG("hu %p count %d rx_state %d rx_count %ld",
> + BT_DBG("hu %p count %d rx_state %d rx_count %ld",
> hu, count, bcsp->rx_state, bcsp->rx_count);
>
> ptr = data;
> @@ -574,7 +576,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
>
> switch (bcsp->rx_state) {
> case BCSP_W4_BCSP_HDR:
> - if ((0xff & (u8) ~ (bcsp->rx_skb->data[0] + bcsp->rx_skb->data[1] +
> + if ((0xff & (u8) ~(bcsp->rx_skb->data[0] + bcsp->rx_skb->data[1] +
> bcsp->rx_skb->data[2])) != bcsp->rx_skb->data[3]) {
> BT_ERR("Error in BCSP hdr checksum");
> kfree_skb(bcsp->rx_skb);
> @@ -583,8 +585,8 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
> continue;
> }
> if (bcsp->rx_skb->data[0] & 0x80 /* reliable pkt */
> - && (bcsp->rx_skb->data[0] & 0x07) != bcsp->rxseq_txack) {
> - BT_ERR ("Out-of-order packet arrived, got %u expected %u",
> + && (bcsp->rx_skb->data[0] & 0x07) != bcsp->rxseq_txack) {
> + BT_ERR("Out-of-order packet arrived, got %u expected %u",
> bcsp->rx_skb->data[0] & 0x07, bcsp->rxseq_txack);
>
> kfree_skb(bcsp->rx_skb);
> @@ -593,7 +595,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
> continue;
> }
> bcsp->rx_state = BCSP_W4_DATA;
> - bcsp->rx_count = (bcsp->rx_skb->data[1] >> 4) +
> + bcsp->rx_count = (bcsp->rx_skb->data[1] >> 4) +
> (bcsp->rx_skb->data[2] << 4); /* May be 0 */
> continue;
>
> @@ -607,7 +609,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
>
> case BCSP_W4_CRC:
> if (bitrev16(bcsp->message_crc) != bscp_get_crc(bcsp)) {
> - BT_ERR ("Checksum failed: computed %04x received %04x",
> + BT_ERR("Checksum failed: computed %04x received %04x",
> bitrev16(bcsp->message_crc),
> bscp_get_crc(bcsp));
>
> @@ -645,7 +647,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
> BCSP_CRC_INIT(bcsp->message_crc);
>
> /* Do not increment ptr or decrement count
> - * Allocate packet. Max len of a BCSP pkt=
> + * Allocate packet. Max len of a BCSP pkt=
> * 0xFFF (payload) +4 (header) +2 (crc) */
>
> bcsp->rx_skb = bt_skb_alloc(0x1005, GFP_ATOMIC);
> diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
> index b6154d5..67a0e6c 100644
> --- a/drivers/bluetooth/hci_h5.c
> +++ b/drivers/bluetooth/hci_h5.c
> @@ -673,7 +673,8 @@ static struct sk_buff *h5_dequeue(struct hci_uart *hu)
> return h5_prepare_pkt(hu, HCI_3WIRE_LINK_PKT, wakeup_req, 2);
> }
>
> - if ((skb = skb_dequeue(&h5->unrel)) != NULL) {
> + skb = skb_dequeue(&h5->unrel);
> + if (skb != NULL) {
> nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
> skb->data, skb->len);
> if (nskb) {
> @@ -690,7 +691,8 @@ static struct sk_buff *h5_dequeue(struct hci_uart *hu)
> if (h5->unack.qlen >= h5->tx_win)
> goto unlock;
>
> - if ((skb = skb_dequeue(&h5->rel)) != NULL) {
> + skb = skb_dequeue(&h5->rel);
> + if (skb != NULL) {
> nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
> skb->data, skb->len);
> if (nskb) {
> diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
> index bc68a44..d424e7d 100644
> --- a/drivers/bluetooth/hci_ldisc.c
> +++ b/drivers/bluetooth/hci_ldisc.c
> @@ -236,7 +236,7 @@ static int hci_uart_close(struct hci_dev *hdev)
> /* Send frames from HCI layer */
> static int hci_uart_send_frame(struct sk_buff *skb)
> {
> - struct hci_dev* hdev = (struct hci_dev *) skb->dev;
> + struct hci_dev *hdev = (struct hci_dev *) skb->dev;
> struct hci_uart *hu;
>
> if (!hdev) {
> @@ -279,7 +279,8 @@ static int hci_uart_tty_open(struct tty_struct *tty)
> if (tty->ops->write == NULL)
> return -EOPNOTSUPP;
>
> - if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
> + hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL);
> + if (!hu) {
> BT_ERR("Can't allocate control structure");
> return -ENFILE;
> }
> @@ -483,7 +484,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
> *
> * Return Value: Command dependent
> */
> -static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
> +static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file *file,
> unsigned int cmd, unsigned long arg)
> {
> struct hci_uart *hu = (void *)tty->disc_data;
> @@ -564,7 +565,7 @@ static int __init hci_uart_init(void)
>
> /* Register the tty discipline */
>
> - memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc));
> + memset(&hci_uart_ldisc, 0, sizeof(hci_uart_ldisc));
> hci_uart_ldisc.magic = TTY_LDISC_MAGIC;
> hci_uart_ldisc.name = "n_hci";
> hci_uart_ldisc.open = hci_uart_tty_open;
> @@ -577,7 +578,8 @@ static int __init hci_uart_init(void)
> hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
> hci_uart_ldisc.owner = THIS_MODULE;
>
> - if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
> + err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
> + if (err) {
> BT_ERR("HCI line discipline registration failed. (%d)", err);
> return err;
> }
> @@ -622,7 +624,8 @@ static void __exit hci_uart_exit(void)
> #endif
>
> /* Release tty registration of line discipline */
> - if ((err = tty_unregister_ldisc(N_HCI)))
> + err = tty_unregister_ldisc(N_HCI);
> + if (err)
> BT_ERR("Can't unregister HCI line discipline (%d)", err);
> }
>
> diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
> index d8b7aed..4b499f2 100644
> --- a/drivers/bluetooth/hci_vhci.c
> +++ b/drivers/bluetooth/hci_vhci.c
> @@ -82,7 +82,7 @@ static int vhci_flush(struct hci_dev *hdev)
>
> static int vhci_send_frame(struct sk_buff *skb)
> {
> - struct hci_dev* hdev = (struct hci_dev *) skb->dev;
> + struct hci_dev *hdev = (struct hci_dev *) skb->dev;
> struct vhci_data *data;
>
> if (!hdev) {
> @@ -281,7 +281,7 @@ static const struct file_operations vhci_fops = {
> .llseek = no_llseek,
> };
>
> -static struct miscdevice vhci_miscdev= {
> +static struct miscdevice vhci_miscdev = {
> .name = "vhci",
> .fops = &vhci_fops,
> .minor = MISC_DYNAMIC_MINOR,
Dean Jenkins
Mentor Graphics
^ permalink raw reply
* Re: [PATCH 1/3] sco-tester: Update ECONNABORTED to EOPNOTSUPP
From: Frédéric DALLEAU @ 2013-08-12 8:34 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
In-Reply-To: <09231CA6-E5F3-453E-9479-68F08072893A@holtmann.org>
Hi Marcel,
> can we please have a proper thread on what error is appropriate to send > from a socket interface when this situation happens. I see that
> we are flipping errors, but my request to discuss this gets ignored.
>
I already gave my opinion previously. Let's recall it :"About the error
ECONNABORTED, it is what the patch does : abort a connection. It is not
used for other purposes. If you really want to change, I'm ok with
EOPNOTSUPP, otherwise please suggest."
Regarding EOPNOTSUPP. Most use case are when a pointer in an interface
is not implemented. We could consider that SetupSyncConn is not
implemented in 2.0 adapter interfaces.
> Please look for a good reference of the error code usage in other
socket protocols or manpages
It is not obvious to find one good reference. But for example there is :
Documentation/ioctl/hdio.txt: EOPNOTSUPP Hardware interface does
not support bus power
Another option could be:
[ENODEV]
No such device An attempt was made to apply an inappropriate
function to a device; for example, trying to read a write-only device
such as a printer.
BR,
Fred
^ permalink raw reply
* bluez profile debug messages
From: hong zhang @ 2013-08-11 22:41 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
List,
I am working on android phone and facing Bluetooth problems that phone could not accept pairing request and could not receive file from another Bluetooth device.
Bluetooth sniffer is a kind of expensive.
What I think is to setup a debug device that could be in Ubuntu or my phone and it will print out profile messages when pair and file transfer request are coming.
Any idea would be appreciated.
---henry
^ permalink raw reply
* [PATCH] Bluetooth: clean up
From: Valentin Ilie @ 2013-08-11 12:56 UTC (permalink / raw)
To: marcel, gustavo, johan.hedberg; +Cc: linux-bluetooth, Valentin Ilie
Clean up bluetooth files
- replace foo* bar with foo *bar
- add space arround '='
- remove trailing witespaces
- remove assignment in if
- fix coding style issues
Signed-off-by: Valentin Ilie <valentin.ilie@gmail.com>
---
drivers/bluetooth/Kconfig | 12 +++++------
drivers/bluetooth/dtl1_cs.c | 6 +++---
drivers/bluetooth/hci_bcsp.c | 48 +++++++++++++++++++++--------------------
drivers/bluetooth/hci_h5.c | 6 ++++--
drivers/bluetooth/hci_ldisc.c | 15 +++++++------
drivers/bluetooth/hci_vhci.c | 4 ++--
6 files changed, 49 insertions(+), 42 deletions(-)
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 11a6104..6421414 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -30,8 +30,8 @@ config BT_HCIUART
help
Bluetooth HCI UART driver.
This driver is required if you want to use Bluetooth devices with
- serial port interface. You will also need this driver if you have
- UART based Bluetooth PCMCIA and CF devices like Xircom Credit Card
+ serial port interface. You will also need this driver if you have
+ UART based Bluetooth PCMCIA and CF devices like Xircom Credit Card
adapter and BrainBoxes Bluetooth PC Card.
Say Y here to compile support for Bluetooth UART devices into the
@@ -41,9 +41,9 @@ config BT_HCIUART_H4
bool "UART (H4) protocol support"
depends on BT_HCIUART
help
- UART (H4) is serial protocol for communication between Bluetooth
- device and host. This protocol is required for most Bluetooth devices
- with UART interface, including PCMCIA and CF cards.
+ UART (H4) is serial protocol for communication between Bluetooth
+ device and host. This protocol is required for most Bluetooth devices
+ with UART interface, including PCMCIA and CF cards.
Say Y here to compile support for HCI UART (H4) protocol.
@@ -52,7 +52,7 @@ config BT_HCIUART_BCSP
depends on BT_HCIUART
select BITREVERSE
help
- BCSP (BlueCore Serial Protocol) is serial protocol for communication
+ BCSP (BlueCore Serial Protocol) is serial protocol for communication
between Bluetooth device and host. This protocol is required for non
USB Bluetooth devices based on CSR BlueCore chip, including PCMCIA and
CF cards.
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 33f3a69..3b89c0d 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -153,7 +153,8 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
if (!pcmcia_dev_present(info->p_dev))
return;
- if (!(skb = skb_dequeue(&(info->txq))))
+ skb = skb_dequeue(&(info->txq));
+ if (!skb)
break;
/* Send frame */
@@ -181,9 +182,8 @@ static void dtl1_control(dtl1_info_t *info, struct sk_buff *skb)
int i;
printk(KERN_INFO "Bluetooth: Nokia control data =");
- for (i = 0; i < skb->len; i++) {
+ for (i = 0; i < skb->len; i++)
printk(" %02x", skb->data[i]);
- }
printk("\n");
/* transition to active state */
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 57e502e..fbd54e8 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -105,11 +105,11 @@ static const u16 crc_table[] = {
#define BCSP_CRC_INIT(x) x = 0xffff
/*
- Update crc with next data byte
+ Update crc with next data byte
- Implementation note
- The data byte is treated as two nibbles. The crc is generated
- in reverse, i.e., bits are fed into the register from the top.
+ Implementation note
+ The data byte is treated as two nibbles. The crc is generated
+ in reverse, i.e., bits are fed into the register from the top.
*/
static void bcsp_crc_update(u16 *crc, u8 d)
{
@@ -287,11 +287,12 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
struct bcsp_struct *bcsp = hu->priv;
unsigned long flags;
struct sk_buff *skb;
-
+
/* First of all, check for unreliable messages in the queue,
since they have priority */
- if ((skb = skb_dequeue(&bcsp->unrel)) != NULL) {
+ skb = skb_dequeue(&bcsp->unrel);
+ if (skb != NULL) {
struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
if (nskb) {
kfree_skb(skb);
@@ -308,7 +309,8 @@ static struct sk_buff *bcsp_dequeue(struct hci_uart *hu)
spin_lock_irqsave_nested(&bcsp->unack.lock, flags, SINGLE_DEPTH_NESTING);
- if (bcsp->unack.qlen < BCSP_TXWINSIZE && (skb = skb_dequeue(&bcsp->rel)) != NULL) {
+ skb = skb_dequeue(&bcsp->rel);
+ if (bcsp->unack.qlen < BCSP_TXWINSIZE && skb != NULL) {
struct sk_buff *nskb = bcsp_prepare_pkt(bcsp, skb->data, skb->len, bt_cb(skb)->pkt_type);
if (nskb) {
__skb_queue_tail(&bcsp->unack, skb);
@@ -433,7 +435,7 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
break;
default:
memcpy(skb_put(bcsp->rx_skb, 1), &byte, 1);
- if ((bcsp->rx_skb-> data[0] & 0x40) != 0 &&
+ if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
bcsp->rx_state != BCSP_W4_CRC)
bcsp_crc_update(&bcsp->message_crc, byte);
bcsp->rx_count--;
@@ -444,24 +446,24 @@ static inline void bcsp_unslip_one_byte(struct bcsp_struct *bcsp, unsigned char
switch (byte) {
case 0xdc:
memcpy(skb_put(bcsp->rx_skb, 1), &c0, 1);
- if ((bcsp->rx_skb-> data[0] & 0x40) != 0 &&
+ if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
bcsp->rx_state != BCSP_W4_CRC)
- bcsp_crc_update(&bcsp-> message_crc, 0xc0);
+ bcsp_crc_update(&bcsp->message_crc, 0xc0);
bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC;
bcsp->rx_count--;
break;
case 0xdd:
memcpy(skb_put(bcsp->rx_skb, 1), &db, 1);
- if ((bcsp->rx_skb-> data[0] & 0x40) != 0 &&
- bcsp->rx_state != BCSP_W4_CRC)
- bcsp_crc_update(&bcsp-> message_crc, 0xdb);
+ if ((bcsp->rx_skb->data[0] & 0x40) != 0 &&
+ bcsp->rx_state != BCSP_W4_CRC)
+ bcsp_crc_update(&bcsp->message_crc, 0xdb);
bcsp->rx_esc_state = BCSP_ESCSTATE_NOESC;
bcsp->rx_count--;
break;
default:
- BT_ERR ("Invalid byte %02x after esc byte", byte);
+ BT_ERR("Invalid byte %02x after esc byte", byte);
kfree_skb(bcsp->rx_skb);
bcsp->rx_skb = NULL;
bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
@@ -524,9 +526,9 @@ static void bcsp_complete_rx_pkt(struct hci_uart *hu)
hci_recv_frame(bcsp->rx_skb);
} else {
- BT_ERR ("Packet for unknown channel (%u %s)",
+ BT_ERR("Packet for unknown channel (%u %s)",
bcsp->rx_skb->data[1] & 0x0f,
- bcsp->rx_skb->data[0] & 0x80 ?
+ bcsp->rx_skb->data[0] & 0x80 ?
"reliable" : "unreliable");
kfree_skb(bcsp->rx_skb);
}
@@ -554,7 +556,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
struct bcsp_struct *bcsp = hu->priv;
unsigned char *ptr;
- BT_DBG("hu %p count %d rx_state %d rx_count %ld",
+ BT_DBG("hu %p count %d rx_state %d rx_count %ld",
hu, count, bcsp->rx_state, bcsp->rx_count);
ptr = data;
@@ -574,7 +576,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
switch (bcsp->rx_state) {
case BCSP_W4_BCSP_HDR:
- if ((0xff & (u8) ~ (bcsp->rx_skb->data[0] + bcsp->rx_skb->data[1] +
+ if ((0xff & (u8) ~(bcsp->rx_skb->data[0] + bcsp->rx_skb->data[1] +
bcsp->rx_skb->data[2])) != bcsp->rx_skb->data[3]) {
BT_ERR("Error in BCSP hdr checksum");
kfree_skb(bcsp->rx_skb);
@@ -583,8 +585,8 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
continue;
}
if (bcsp->rx_skb->data[0] & 0x80 /* reliable pkt */
- && (bcsp->rx_skb->data[0] & 0x07) != bcsp->rxseq_txack) {
- BT_ERR ("Out-of-order packet arrived, got %u expected %u",
+ && (bcsp->rx_skb->data[0] & 0x07) != bcsp->rxseq_txack) {
+ BT_ERR("Out-of-order packet arrived, got %u expected %u",
bcsp->rx_skb->data[0] & 0x07, bcsp->rxseq_txack);
kfree_skb(bcsp->rx_skb);
@@ -593,7 +595,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
continue;
}
bcsp->rx_state = BCSP_W4_DATA;
- bcsp->rx_count = (bcsp->rx_skb->data[1] >> 4) +
+ bcsp->rx_count = (bcsp->rx_skb->data[1] >> 4) +
(bcsp->rx_skb->data[2] << 4); /* May be 0 */
continue;
@@ -607,7 +609,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
case BCSP_W4_CRC:
if (bitrev16(bcsp->message_crc) != bscp_get_crc(bcsp)) {
- BT_ERR ("Checksum failed: computed %04x received %04x",
+ BT_ERR("Checksum failed: computed %04x received %04x",
bitrev16(bcsp->message_crc),
bscp_get_crc(bcsp));
@@ -645,7 +647,7 @@ static int bcsp_recv(struct hci_uart *hu, void *data, int count)
BCSP_CRC_INIT(bcsp->message_crc);
/* Do not increment ptr or decrement count
- * Allocate packet. Max len of a BCSP pkt=
+ * Allocate packet. Max len of a BCSP pkt=
* 0xFFF (payload) +4 (header) +2 (crc) */
bcsp->rx_skb = bt_skb_alloc(0x1005, GFP_ATOMIC);
diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index b6154d5..67a0e6c 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -673,7 +673,8 @@ static struct sk_buff *h5_dequeue(struct hci_uart *hu)
return h5_prepare_pkt(hu, HCI_3WIRE_LINK_PKT, wakeup_req, 2);
}
- if ((skb = skb_dequeue(&h5->unrel)) != NULL) {
+ skb = skb_dequeue(&h5->unrel);
+ if (skb != NULL) {
nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
skb->data, skb->len);
if (nskb) {
@@ -690,7 +691,8 @@ static struct sk_buff *h5_dequeue(struct hci_uart *hu)
if (h5->unack.qlen >= h5->tx_win)
goto unlock;
- if ((skb = skb_dequeue(&h5->rel)) != NULL) {
+ skb = skb_dequeue(&h5->rel);
+ if (skb != NULL) {
nskb = h5_prepare_pkt(hu, bt_cb(skb)->pkt_type,
skb->data, skb->len);
if (nskb) {
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index bc68a44..d424e7d 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -236,7 +236,7 @@ static int hci_uart_close(struct hci_dev *hdev)
/* Send frames from HCI layer */
static int hci_uart_send_frame(struct sk_buff *skb)
{
- struct hci_dev* hdev = (struct hci_dev *) skb->dev;
+ struct hci_dev *hdev = (struct hci_dev *) skb->dev;
struct hci_uart *hu;
if (!hdev) {
@@ -279,7 +279,8 @@ static int hci_uart_tty_open(struct tty_struct *tty)
if (tty->ops->write == NULL)
return -EOPNOTSUPP;
- if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
+ hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL);
+ if (!hu) {
BT_ERR("Can't allocate control structure");
return -ENFILE;
}
@@ -483,7 +484,7 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
*
* Return Value: Command dependent
*/
-static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
+static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct hci_uart *hu = (void *)tty->disc_data;
@@ -564,7 +565,7 @@ static int __init hci_uart_init(void)
/* Register the tty discipline */
- memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc));
+ memset(&hci_uart_ldisc, 0, sizeof(hci_uart_ldisc));
hci_uart_ldisc.magic = TTY_LDISC_MAGIC;
hci_uart_ldisc.name = "n_hci";
hci_uart_ldisc.open = hci_uart_tty_open;
@@ -577,7 +578,8 @@ static int __init hci_uart_init(void)
hci_uart_ldisc.write_wakeup = hci_uart_tty_wakeup;
hci_uart_ldisc.owner = THIS_MODULE;
- if ((err = tty_register_ldisc(N_HCI, &hci_uart_ldisc))) {
+ err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
+ if (err) {
BT_ERR("HCI line discipline registration failed. (%d)", err);
return err;
}
@@ -622,7 +624,8 @@ static void __exit hci_uart_exit(void)
#endif
/* Release tty registration of line discipline */
- if ((err = tty_unregister_ldisc(N_HCI)))
+ err = tty_unregister_ldisc(N_HCI);
+ if (err)
BT_ERR("Can't unregister HCI line discipline (%d)", err);
}
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index d8b7aed..4b499f2 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -82,7 +82,7 @@ static int vhci_flush(struct hci_dev *hdev)
static int vhci_send_frame(struct sk_buff *skb)
{
- struct hci_dev* hdev = (struct hci_dev *) skb->dev;
+ struct hci_dev *hdev = (struct hci_dev *) skb->dev;
struct vhci_data *data;
if (!hdev) {
@@ -281,7 +281,7 @@ static const struct file_operations vhci_fops = {
.llseek = no_llseek,
};
-static struct miscdevice vhci_miscdev= {
+static struct miscdevice vhci_miscdev = {
.name = "vhci",
.fops = &vhci_fops,
.minor = MISC_DYNAMIC_MINOR,
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH 5/6] Bluetooth: Add LE connection parameters to debugfs
From: Marcel Holtmann @ 2013-08-10 16:10 UTC (permalink / raw)
To: Andre Guedes; +Cc: linux-bluetooth, Vinicius Costa Gomes
In-Reply-To: <1376089954-13639-6-git-send-email-andre.guedes@openbossa.org>
Hi Andre,
> From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
>
> Only reading the parameters is supported for now.
don't come me with this short kernel commits. Write a proper explanation on what you are doing here and why.
>
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
> ---
> net/bluetooth/hci_sysfs.c | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
> index 17ebc4a..5993150 100644
> --- a/net/bluetooth/hci_sysfs.c
> +++ b/net/bluetooth/hci_sysfs.c
> @@ -603,6 +603,35 @@ static const struct file_operations discovery_parameters_fops = {
> .release = single_release,
> };
>
> +static int le_conn_parameters_show(struct seq_file *f, void *p)
> +{
> + struct hci_dev *hdev = f->private;
> + struct le_conn_params *params = &hdev->le_conn_params;
> +
> + hci_dev_lock(hdev);
> +
> + seq_printf(f, "0x%.4x 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n",
> + params->scan_interval, params->scan_window,
> + params->conn_interval_min, params->conn_interval_max,
> + params->supervision_timeout);
> +
> + hci_dev_unlock(hdev);
> +
> + return 0;
> +}
> +
> +static int le_conn_parameters_open(struct inode *inode, struct file *file)
> +{
> + return single_open(file, le_conn_parameters_show, inode->i_private);
> +}
> +
> +static const struct file_operations le_conn_parameters_fops = {
> + .open = le_conn_parameters_open,
> + .read = seq_read,
> + .llseek = seq_lseek,
> + .release = single_release,
> +};
> +
> void hci_init_sysfs(struct hci_dev *hdev)
> {
> struct device *dev = &hdev->dev;
> @@ -647,6 +676,10 @@ int hci_add_sysfs(struct hci_dev *hdev)
>
> debugfs_create_file("discovery_parameters", 0644, hdev->debugfs, hdev,
> &discovery_parameters_fops);
> +
> + debugfs_create_file("le_conn_parameters", 0644, hdev->debugfs, hdev,
> + &le_conn_parameters_fops);
> +
> return 0;
> }
What is the point exactly of exposing this if you are BR/EDR only controller?
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 3/6] Bluetooth: Set discovery parameters
From: Marcel Holtmann @ 2013-08-10 16:09 UTC (permalink / raw)
To: Andre Guedes; +Cc: linux-bluetooth
In-Reply-To: <1376089954-13639-4-git-send-email-andre.guedes@openbossa.org>
Hi Andre,
> This patch adds support for setting discovery parameters through
> debugfs filesystem.
>
> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
> ---
> net/bluetooth/hci_sysfs.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
> index 90cb53b..17ebc4a 100644
> --- a/net/bluetooth/hci_sysfs.c
> +++ b/net/bluetooth/hci_sysfs.c
> @@ -553,9 +553,52 @@ static int discovery_parameters_open(struct inode *inode, struct file *file)
> return single_open(file, discovery_parameters_show, inode->i_private);
> }
>
> +static ssize_t discovery_parameters_write(struct file *file,
> + const char __user *data,
> + size_t count, loff_t *offset)
> +{
> + struct seq_file *sfile = file->private_data;
> + struct hci_dev *hdev = sfile->private;
> + struct discovery_param param;
> + char *buf;
> + int n;
> + ssize_t res = 0;
> +
> + /* We don't allow partial writes */
> + if (*offset != 0)
> + return 0;
> +
> + buf = kzalloc(count, GFP_KERNEL);
> + if (!buf)
> + return 0;
> +
> + if (copy_from_user(buf, data, count))
> + goto out;
> +
> + memset(¶m, 0, sizeof(param));
> +
> + n = sscanf(buf, "%hhx %hx %hx %u %u %hhx %hhx",
> + ¶m.scan_type, ¶m.scan_interval, ¶m.scan_window,
> + ¶m.le_scan_duration, ¶m.interleaved_scan_duration,
> + ¶m.interleaved_inquiry_length,
> + ¶m.bredr_inquiry_length);
I am not a huge fan of this crazy. I need a manual to know exactly what to do here. That is just silly. Unless things are a bit self-explanatory on how you can tweak things, I am not really interested here.
Also intermixing LE with BR/EDR is a bit pointless here. I would prefer if they are separate and not that BR/EDR only controller exports LE knobs and and LE only controller exports BR/EDR knobs.
Regards
Marcel
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox