Skip to content

Commit 5b7f990

Browse files
committed
[Bluetooth] Add basics to better support and handle eSCO links
To better support and handle eSCO links in the future a bunch of constants needs to be added and some basic routines need to be updated. This is the initial step. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 8de0a15 commit 5b7f990

5 files changed

Lines changed: 66 additions & 37 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ enum {
107107
#define HCI_IDLE_TIMEOUT (6000) /* 6 seconds */
108108
#define HCI_INIT_TIMEOUT (10000) /* 10 seconds */
109109

110-
/* HCI Packet types */
110+
/* HCI data types */
111111
#define HCI_COMMAND_PKT 0x01
112112
#define HCI_ACLDATA_PKT 0x02
113113
#define HCI_SCODATA_PKT 0x03
114114
#define HCI_EVENT_PKT 0x04
115115
#define HCI_VENDOR_PKT 0xff
116116

117-
/* HCI Packet types */
117+
/* HCI packet types */
118118
#define HCI_DM1 0x0008
119119
#define HCI_DM3 0x0400
120120
#define HCI_DM5 0x4000
@@ -129,6 +129,14 @@ enum {
129129
#define SCO_PTYPE_MASK (HCI_HV1 | HCI_HV2 | HCI_HV3)
130130
#define ACL_PTYPE_MASK (~SCO_PTYPE_MASK)
131131

132+
/* eSCO packet types */
133+
#define ESCO_HV1 0x0001
134+
#define ESCO_HV2 0x0002
135+
#define ESCO_HV3 0x0004
136+
#define ESCO_EV3 0x0008
137+
#define ESCO_EV4 0x0010
138+
#define ESCO_EV5 0x0020
139+
132140
/* ACL flags */
133141
#define ACL_CONT 0x01
134142
#define ACL_START 0x02
@@ -138,6 +146,7 @@ enum {
138146
/* Baseband links */
139147
#define SCO_LINK 0x00
140148
#define ACL_LINK 0x01
149+
#define ESCO_LINK 0x02
141150

142151
/* LMP features */
143152
#define LMP_3SLOT 0x01
@@ -162,6 +171,11 @@ enum {
162171
#define LMP_PSCHEME 0x02
163172
#define LMP_PCONTROL 0x04
164173

174+
#define LMP_ESCO 0x80
175+
176+
#define LMP_EV4 0x01
177+
#define LMP_EV5 0x02
178+
165179
#define LMP_SNIFF_SUBR 0x02
166180

167181
/* Connection modes */

‎include/net/bluetooth/hci_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct hci_dev {
7878
__u16 voice_setting;
7979

8080
__u16 pkt_type;
81+
__u16 esco_type;
8182
__u16 link_policy;
8283
__u16 link_mode;
8384

@@ -452,6 +453,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
452453
#define lmp_encrypt_capable(dev) ((dev)->features[0] & LMP_ENCRYPT)
453454
#define lmp_sniff_capable(dev) ((dev)->features[0] & LMP_SNIFF)
454455
#define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
456+
#define lmp_esco_capable(dev) ((dev)->features[3] & LMP_ESCO)
455457

456458
/* ----- HCI protocols ----- */
457459
struct hci_proto {

‎net/bluetooth/hci_conn.c‎

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ void hci_add_sco(struct hci_conn *conn, __u16 handle)
123123
conn->state = BT_CONNECT;
124124
conn->out = 1;
125125

126-
cp.pkt_type = cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK);
127126
cp.handle = cpu_to_le16(handle);
127+
cp.pkt_type = cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK);
128128

129129
hci_send_cmd(hdev, OGF_LINK_CTL, OCF_ADD_SCO, sizeof(cp), &cp);
130130
}
@@ -220,19 +220,19 @@ int hci_conn_del(struct hci_conn *conn)
220220

221221
del_timer(&conn->disc_timer);
222222

223-
if (conn->type == SCO_LINK) {
224-
struct hci_conn *acl = conn->link;
225-
if (acl) {
226-
acl->link = NULL;
227-
hci_conn_put(acl);
228-
}
229-
} else {
223+
if (conn->type == ACL_LINK) {
230224
struct hci_conn *sco = conn->link;
231225
if (sco)
232226
sco->link = NULL;
233227

234228
/* Unacked frames */
235229
hdev->acl_cnt += conn->sent;
230+
} else {
231+
struct hci_conn *acl = conn->link;
232+
if (acl) {
233+
acl->link = NULL;
234+
hci_conn_put(acl);
235+
}
236236
}
237237

238238
tasklet_disable(&hdev->tx_task);
@@ -297,9 +297,10 @@ EXPORT_SYMBOL(hci_get_route);
297297

298298
/* Create SCO or ACL connection.
299299
* Device _must_ be locked */
300-
struct hci_conn * hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst)
300+
struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst)
301301
{
302302
struct hci_conn *acl;
303+
struct hci_conn *sco;
303304

304305
BT_DBG("%s dst %s", hdev->name, batostr(dst));
305306

@@ -313,28 +314,26 @@ struct hci_conn * hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst)
313314
if (acl->state == BT_OPEN || acl->state == BT_CLOSED)
314315
hci_acl_connect(acl);
315316

316-
if (type == SCO_LINK) {
317-
struct hci_conn *sco;
317+
if (type == ACL_LINK)
318+
return acl;
318319

319-
if (!(sco = hci_conn_hash_lookup_ba(hdev, SCO_LINK, dst))) {
320-
if (!(sco = hci_conn_add(hdev, SCO_LINK, dst))) {
321-
hci_conn_put(acl);
322-
return NULL;
323-
}
320+
if (!(sco = hci_conn_hash_lookup_ba(hdev, type, dst))) {
321+
if (!(sco = hci_conn_add(hdev, type, dst))) {
322+
hci_conn_put(acl);
323+
return NULL;
324324
}
325-
acl->link = sco;
326-
sco->link = acl;
325+
}
327326

328-
hci_conn_hold(sco);
327+
acl->link = sco;
328+
sco->link = acl;
329329

330-
if (acl->state == BT_CONNECTED &&
331-
(sco->state == BT_OPEN || sco->state == BT_CLOSED))
332-
hci_add_sco(sco, acl->handle);
330+
hci_conn_hold(sco);
333331

334-
return sco;
335-
} else {
336-
return acl;
337-
}
332+
if (acl->state == BT_CONNECTED &&
333+
(sco->state == BT_OPEN || sco->state == BT_CLOSED))
334+
hci_add_sco(sco, acl->handle);
335+
336+
return sco;
338337
}
339338
EXPORT_SYMBOL(hci_connect);
340339

‎net/bluetooth/hci_core.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ int hci_register_dev(struct hci_dev *hdev)
851851

852852
hdev->flags = 0;
853853
hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1);
854+
hdev->esco_type = (ESCO_HV1);
854855
hdev->link_mode = (HCI_LM_ACCEPT);
855856

856857
hdev->idle_timeout = 0;
@@ -1254,7 +1255,7 @@ EXPORT_SYMBOL(hci_send_sco);
12541255
static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote)
12551256
{
12561257
struct hci_conn_hash *h = &hdev->conn_hash;
1257-
struct hci_conn *conn = NULL;
1258+
struct hci_conn *conn = NULL;
12581259
int num = 0, min = ~0;
12591260
struct list_head *p;
12601261

‎net/bluetooth/hci_event.c‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,24 @@ static void hci_cc_info_param(struct hci_dev *hdev, __u16 ocf, struct sk_buff *s
350350
if (hdev->features[0] & LMP_5SLOT)
351351
hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
352352

353-
if (hdev->features[1] & LMP_HV2)
354-
hdev->pkt_type |= (HCI_HV2);
353+
if (hdev->features[1] & LMP_HV2) {
354+
hdev->pkt_type |= (HCI_HV2);
355+
hdev->esco_type |= (ESCO_HV2);
356+
}
357+
358+
if (hdev->features[1] & LMP_HV3) {
359+
hdev->pkt_type |= (HCI_HV3);
360+
hdev->esco_type |= (ESCO_HV3);
361+
}
355362

356-
if (hdev->features[1] & LMP_HV3)
357-
hdev->pkt_type |= (HCI_HV3);
363+
if (hdev->features[3] & LMP_ESCO)
364+
hdev->esco_type |= (ESCO_EV3);
365+
366+
if (hdev->features[4] & LMP_EV4)
367+
hdev->esco_type |= (ESCO_EV4);
368+
369+
if (hdev->features[4] & LMP_EV5)
370+
hdev->esco_type |= (ESCO_EV5);
358371

359372
BT_DBG("%s: features 0x%x 0x%x 0x%x", hdev->name,
360373
lf->features[0], lf->features[1], lf->features[2]);
@@ -881,12 +894,12 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
881894
if (conn) {
882895
conn->sent -= count;
883896

884-
if (conn->type == SCO_LINK) {
885-
if ((hdev->sco_cnt += count) > hdev->sco_pkts)
886-
hdev->sco_cnt = hdev->sco_pkts;
887-
} else {
897+
if (conn->type == ACL_LINK) {
888898
if ((hdev->acl_cnt += count) > hdev->acl_pkts)
889899
hdev->acl_cnt = hdev->acl_pkts;
900+
} else {
901+
if ((hdev->sco_cnt += count) > hdev->sco_pkts)
902+
hdev->sco_cnt = hdev->sco_pkts;
890903
}
891904
}
892905
}

0 commit comments

Comments
 (0)