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[];
334329extern struct list_head hci_dev_list;
335330extern struct list_head hci_cb_list;
336331extern rwlock_t hci_dev_list_lock;
337332extern 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-
699688static 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
716705static 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
732727static 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
748735static 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
764757static 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)
786774static 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 ----- */
807787struct hci_cb {
808788 struct list_head list;
0 commit comments