Skip to content

Commit 686ebf2

Browse files
Ulisses FurquimGustavo F. Padovan
authored andcommitted
Bluetooth: Make HCI call directly into SCO and L2CAP event functions
The struct hci_proto and all related register/unregister and dispatching code was removed. HCI core code now call directly the SCO and L2CAP event functions. Signed-off-by: Ulisses Furquim <ulisses@profusion.mobi> Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent 68a8aea commit 686ebf2

4 files changed

Lines changed: 74 additions & 212 deletions

File tree

‎include/net/bluetooth/hci_core.h‎

Lines changed: 59 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
#include <linux/interrupt.h>
2929
#include <net/bluetooth/hci.h>
3030

31-
/* HCI upper protocols */
32-
#define HCI_PROTO_L2CAP 0
33-
#define HCI_PROTO_SCO 1
34-
3531
/* HCI priority */
3632
#define HCI_PRIO_MAX 7
3733

@@ -330,12 +326,24 @@ struct hci_chan {
330326
unsigned int sent;
331327
};
332328

333-
extern struct hci_proto *hci_proto[];
334329
extern struct list_head hci_dev_list;
335330
extern struct list_head hci_cb_list;
336331
extern rwlock_t hci_dev_list_lock;
337332
extern rwlock_t hci_cb_list_lock;
338333

334+
/* ----- HCI interface to upper protocols ----- */
335+
extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
336+
extern int l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
337+
extern int l2cap_disconn_ind(struct hci_conn *hcon);
338+
extern int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
339+
extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
340+
extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
341+
342+
extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
343+
extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status);
344+
extern int sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
345+
extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
346+
339347
/* ----- Inquiry cache ----- */
340348
#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
341349
#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
@@ -677,107 +685,87 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
677685
#define lmp_host_le_capable(dev) ((dev)->extfeatures[0] & LMP_HOST_LE)
678686

679687
/* ----- HCI protocols ----- */
680-
struct hci_proto {
681-
char *name;
682-
unsigned int id;
683-
unsigned long flags;
684-
685-
void *priv;
686-
687-
int (*connect_ind) (struct hci_dev *hdev, bdaddr_t *bdaddr,
688-
__u8 type);
689-
int (*connect_cfm) (struct hci_conn *conn, __u8 status);
690-
int (*disconn_ind) (struct hci_conn *conn);
691-
int (*disconn_cfm) (struct hci_conn *conn, __u8 reason);
692-
int (*recv_acldata) (struct hci_conn *conn, struct sk_buff *skb,
693-
__u16 flags);
694-
int (*recv_scodata) (struct hci_conn *conn, struct sk_buff *skb);
695-
int (*security_cfm) (struct hci_conn *conn, __u8 status,
696-
__u8 encrypt);
697-
};
698-
699688
static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
700689
__u8 type)
701690
{
702-
register struct hci_proto *hp;
703-
int mask = 0;
704-
705-
hp = hci_proto[HCI_PROTO_L2CAP];
706-
if (hp && hp->connect_ind)
707-
mask |= hp->connect_ind(hdev, bdaddr, type);
691+
switch (type) {
692+
case ACL_LINK:
693+
return l2cap_connect_ind(hdev, bdaddr);
708694

709-
hp = hci_proto[HCI_PROTO_SCO];
710-
if (hp && hp->connect_ind)
711-
mask |= hp->connect_ind(hdev, bdaddr, type);
695+
case SCO_LINK:
696+
case ESCO_LINK:
697+
return sco_connect_ind(hdev, bdaddr);
712698

713-
return mask;
699+
default:
700+
BT_ERR("unknown link type %d", type);
701+
return -EINVAL;
702+
}
714703
}
715704

716705
static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
717706
{
718-
register struct hci_proto *hp;
707+
switch (conn->type) {
708+
case ACL_LINK:
709+
case LE_LINK:
710+
l2cap_connect_cfm(conn, status);
711+
break;
719712

720-
hp = hci_proto[HCI_PROTO_L2CAP];
721-
if (hp && hp->connect_cfm)
722-
hp->connect_cfm(conn, status);
713+
case SCO_LINK:
714+
case ESCO_LINK:
715+
sco_connect_cfm(conn, status);
716+
break;
723717

724-
hp = hci_proto[HCI_PROTO_SCO];
725-
if (hp && hp->connect_cfm)
726-
hp->connect_cfm(conn, status);
718+
default:
719+
BT_ERR("unknown link type %d", conn->type);
720+
break;
721+
}
727722

728723
if (conn->connect_cfm_cb)
729724
conn->connect_cfm_cb(conn, status);
730725
}
731726

732727
static inline int hci_proto_disconn_ind(struct hci_conn *conn)
733728
{
734-
register struct hci_proto *hp;
735-
int reason = HCI_ERROR_REMOTE_USER_TERM;
729+
if (conn->type != ACL_LINK && conn->type != LE_LINK)
730+
return HCI_ERROR_REMOTE_USER_TERM;
736731

737-
hp = hci_proto[HCI_PROTO_L2CAP];
738-
if (hp && hp->disconn_ind)
739-
reason = hp->disconn_ind(conn);
740-
741-
hp = hci_proto[HCI_PROTO_SCO];
742-
if (hp && hp->disconn_ind)
743-
reason = hp->disconn_ind(conn);
744-
745-
return reason;
732+
return l2cap_disconn_ind(conn);
746733
}
747734

748735
static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
749736
{
750-
register struct hci_proto *hp;
737+
switch (conn->type) {
738+
case ACL_LINK:
739+
case LE_LINK:
740+
l2cap_disconn_cfm(conn, reason);
741+
break;
751742

752-
hp = hci_proto[HCI_PROTO_L2CAP];
753-
if (hp && hp->disconn_cfm)
754-
hp->disconn_cfm(conn, reason);
743+
case SCO_LINK:
744+
case ESCO_LINK:
745+
sco_disconn_cfm(conn, reason);
746+
break;
755747

756-
hp = hci_proto[HCI_PROTO_SCO];
757-
if (hp && hp->disconn_cfm)
758-
hp->disconn_cfm(conn, reason);
748+
default:
749+
BT_ERR("unknown link type %d", conn->type);
750+
break;
751+
}
759752

760753
if (conn->disconn_cfm_cb)
761754
conn->disconn_cfm_cb(conn, reason);
762755
}
763756

764757
static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
765758
{
766-
register struct hci_proto *hp;
767759
__u8 encrypt;
768760

761+
if (conn->type != ACL_LINK && conn->type != LE_LINK)
762+
return;
763+
769764
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend))
770765
return;
771766

772767
encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
773-
774-
hp = hci_proto[HCI_PROTO_L2CAP];
775-
if (hp && hp->security_cfm)
776-
hp->security_cfm(conn, status, encrypt);
777-
778-
hp = hci_proto[HCI_PROTO_SCO];
779-
if (hp && hp->security_cfm)
780-
hp->security_cfm(conn, status, encrypt);
768+
l2cap_security_cfm(conn, status, encrypt);
781769

782770
if (conn->security_cfm_cb)
783771
conn->security_cfm_cb(conn, status);
@@ -786,23 +774,15 @@ static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
786774
static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
787775
__u8 encrypt)
788776
{
789-
register struct hci_proto *hp;
790-
791-
hp = hci_proto[HCI_PROTO_L2CAP];
792-
if (hp && hp->security_cfm)
793-
hp->security_cfm(conn, status, encrypt);
777+
if (conn->type != ACL_LINK && conn->type != LE_LINK)
778+
return;
794779

795-
hp = hci_proto[HCI_PROTO_SCO];
796-
if (hp && hp->security_cfm)
797-
hp->security_cfm(conn, status, encrypt);
780+
l2cap_security_cfm(conn, status, encrypt);
798781

799782
if (conn->security_cfm_cb)
800783
conn->security_cfm_cb(conn, status);
801784
}
802785

803-
int hci_register_proto(struct hci_proto *hproto);
804-
int hci_unregister_proto(struct hci_proto *hproto);
805-
806786
/* ----- HCI callbacks ----- */
807787
struct hci_cb {
808788
struct list_head list;

‎net/bluetooth/hci_core.c‎

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ DEFINE_RWLOCK(hci_dev_list_lock);
6969
LIST_HEAD(hci_cb_list);
7070
DEFINE_RWLOCK(hci_cb_list_lock);
7171

72-
/* HCI protocols */
73-
#define HCI_MAX_PROTO 2
74-
struct hci_proto *hci_proto[HCI_MAX_PROTO];
75-
7672
/* HCI notifiers list */
7773
static ATOMIC_NOTIFIER_HEAD(hci_notifier);
7874

@@ -1830,43 +1826,6 @@ EXPORT_SYMBOL(hci_recv_stream_fragment);
18301826

18311827
/* ---- Interface to upper protocols ---- */
18321828

1833-
/* Register/Unregister protocols. */
1834-
int hci_register_proto(struct hci_proto *hp)
1835-
{
1836-
int err = 0;
1837-
1838-
BT_DBG("%p name %s id %d", hp, hp->name, hp->id);
1839-
1840-
if (hp->id >= HCI_MAX_PROTO)
1841-
return -EINVAL;
1842-
1843-
if (!hci_proto[hp->id])
1844-
hci_proto[hp->id] = hp;
1845-
else
1846-
err = -EEXIST;
1847-
1848-
return err;
1849-
}
1850-
EXPORT_SYMBOL(hci_register_proto);
1851-
1852-
int hci_unregister_proto(struct hci_proto *hp)
1853-
{
1854-
int err = 0;
1855-
1856-
BT_DBG("%p name %s id %d", hp, hp->name, hp->id);
1857-
1858-
if (hp->id >= HCI_MAX_PROTO)
1859-
return -EINVAL;
1860-
1861-
if (hci_proto[hp->id])
1862-
hci_proto[hp->id] = NULL;
1863-
else
1864-
err = -ENOENT;
1865-
1866-
return err;
1867-
}
1868-
EXPORT_SYMBOL(hci_unregister_proto);
1869-
18701829
int hci_register_cb(struct hci_cb *cb)
18711830
{
18721831
BT_DBG("%p name %s", cb, cb->name);
@@ -2470,16 +2429,11 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
24702429
hci_dev_unlock(hdev);
24712430

24722431
if (conn) {
2473-
register struct hci_proto *hp;
2474-
24752432
hci_conn_enter_active_mode(conn, BT_POWER_FORCE_ACTIVE_OFF);
24762433

24772434
/* Send to upper protocol */
2478-
hp = hci_proto[HCI_PROTO_L2CAP];
2479-
if (hp && hp->recv_acldata) {
2480-
hp->recv_acldata(conn, skb, flags);
2481-
return;
2482-
}
2435+
l2cap_recv_acldata(conn, skb, flags);
2436+
return;
24832437
} else {
24842438
BT_ERR("%s ACL packet for unknown connection handle %d",
24852439
hdev->name, handle);
@@ -2508,14 +2462,9 @@ static inline void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
25082462
hci_dev_unlock(hdev);
25092463

25102464
if (conn) {
2511-
register struct hci_proto *hp;
2512-
25132465
/* Send to upper protocol */
2514-
hp = hci_proto[HCI_PROTO_SCO];
2515-
if (hp && hp->recv_scodata) {
2516-
hp->recv_scodata(conn, skb);
2517-
return;
2518-
}
2466+
sco_recv_scodata(conn, skb);
2467+
return;
25192468
} else {
25202469
BT_ERR("%s SCO packet for unknown connection handle %d",
25212470
hdev->name, handle);

0 commit comments

Comments
 (0)