11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds BlueZ - Bluetooth protocol stack for Linux 32d0a0346SRon Shaffer Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 81da177e4SLinus Torvalds it under the terms of the GNU General Public License version 2 as 91da177e4SLinus Torvalds published by the Free Software Foundation; 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 121da177e4SLinus Torvalds OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 131da177e4SLinus Torvalds FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 141da177e4SLinus Torvalds IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 151da177e4SLinus Torvalds CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 161da177e4SLinus Torvalds WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 171da177e4SLinus Torvalds ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 181da177e4SLinus Torvalds OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 211da177e4SLinus Torvalds COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 221da177e4SLinus Torvalds SOFTWARE IS DISCLAIMED. 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #ifndef __HCI_CORE_H 261da177e4SLinus Torvalds #define __HCI_CORE_H 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds #include <net/bluetooth/hci.h> 291da177e4SLinus Torvalds 305e59b791SLuiz Augusto von Dentz /* HCI priority */ 315e59b791SLuiz Augusto von Dentz #define HCI_PRIO_MAX 7 325e59b791SLuiz Augusto von Dentz 331da177e4SLinus Torvalds /* HCI Core structures */ 341da177e4SLinus Torvalds struct inquiry_data { 351da177e4SLinus Torvalds bdaddr_t bdaddr; 361da177e4SLinus Torvalds __u8 pscan_rep_mode; 371da177e4SLinus Torvalds __u8 pscan_period_mode; 381da177e4SLinus Torvalds __u8 pscan_mode; 391da177e4SLinus Torvalds __u8 dev_class[3]; 401ebb9252SMarcel Holtmann __le16 clock_offset; 411da177e4SLinus Torvalds __s8 rssi; 4241a96212SMarcel Holtmann __u8 ssp_mode; 431da177e4SLinus Torvalds }; 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds struct inquiry_entry { 46561aafbcSJohan Hedberg struct list_head all; /* inq_cache.all */ 47561aafbcSJohan Hedberg struct list_head list; /* unknown or resolve */ 48561aafbcSJohan Hedberg enum { 49561aafbcSJohan Hedberg NAME_NOT_KNOWN, 50561aafbcSJohan Hedberg NAME_NEEDED, 51561aafbcSJohan Hedberg NAME_PENDING, 52561aafbcSJohan Hedberg NAME_KNOWN, 53561aafbcSJohan Hedberg } name_state; 541da177e4SLinus Torvalds __u32 timestamp; 551da177e4SLinus Torvalds struct inquiry_data data; 561da177e4SLinus Torvalds }; 571da177e4SLinus Torvalds 5830883512SJohan Hedberg struct discovery_state { 594aab14e5SAndre Guedes int type; 60ff9ef578SJohan Hedberg enum { 61ff9ef578SJohan Hedberg DISCOVERY_STOPPED, 62ff9ef578SJohan Hedberg DISCOVERY_STARTING, 63343f935bSAndre Guedes DISCOVERY_FINDING, 6430dc78e1SJohan Hedberg DISCOVERY_RESOLVING, 65ff9ef578SJohan Hedberg DISCOVERY_STOPPING, 66ff9ef578SJohan Hedberg } state; 67561aafbcSJohan Hedberg struct list_head all; /* All devices found during inquiry */ 68561aafbcSJohan Hedberg struct list_head unknown; /* Name state not known */ 69561aafbcSJohan Hedberg struct list_head resolve; /* Name needs to be resolved */ 701da177e4SLinus Torvalds __u32 timestamp; 711da177e4SLinus Torvalds }; 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds struct hci_conn_hash { 741da177e4SLinus Torvalds struct list_head list; 751da177e4SLinus Torvalds unsigned int acl_num; 761da177e4SLinus Torvalds unsigned int sco_num; 77fcd89c09SVille Tervo unsigned int le_num; 781da177e4SLinus Torvalds }; 791da177e4SLinus Torvalds 80f0358568SJohan Hedberg struct bdaddr_list { 81f0358568SJohan Hedberg struct list_head list; 82f0358568SJohan Hedberg bdaddr_t bdaddr; 83f0358568SJohan Hedberg }; 842aeb9a1aSJohan Hedberg 852aeb9a1aSJohan Hedberg struct bt_uuid { 862aeb9a1aSJohan Hedberg struct list_head list; 872aeb9a1aSJohan Hedberg u8 uuid[16]; 881aff6f09SJohan Hedberg u8 svc_hint; 892aeb9a1aSJohan Hedberg }; 902aeb9a1aSJohan Hedberg 91b899efafSVinicius Costa Gomes struct smp_ltk { 92b899efafSVinicius Costa Gomes struct list_head list; 93b899efafSVinicius Costa Gomes bdaddr_t bdaddr; 94b899efafSVinicius Costa Gomes u8 bdaddr_type; 95b899efafSVinicius Costa Gomes u8 authenticated; 96b899efafSVinicius Costa Gomes u8 type; 97b899efafSVinicius Costa Gomes u8 enc_size; 98b899efafSVinicius Costa Gomes __le16 ediv; 99b899efafSVinicius Costa Gomes u8 rand[8]; 100b899efafSVinicius Costa Gomes u8 val[16]; 101b899efafSVinicius Costa Gomes } __packed; 102b899efafSVinicius Costa Gomes 10355ed8ca1SJohan Hedberg struct link_key { 10455ed8ca1SJohan Hedberg struct list_head list; 10555ed8ca1SJohan Hedberg bdaddr_t bdaddr; 10655ed8ca1SJohan Hedberg u8 type; 1079b3b4460SAndrei Emeltchenko u8 val[HCI_LINK_KEY_SIZE]; 10855ed8ca1SJohan Hedberg u8 pin_len; 10955ed8ca1SJohan Hedberg }; 11055ed8ca1SJohan Hedberg 1112763eda6SSzymon Janc struct oob_data { 1122763eda6SSzymon Janc struct list_head list; 1132763eda6SSzymon Janc bdaddr_t bdaddr; 1142763eda6SSzymon Janc u8 hash[16]; 1152763eda6SSzymon Janc u8 randomizer[16]; 1162763eda6SSzymon Janc }; 1172763eda6SSzymon Janc 1187ba8b4beSAndre Guedes struct le_scan_params { 1197ba8b4beSAndre Guedes u8 type; 1207ba8b4beSAndre Guedes u16 interval; 1217ba8b4beSAndre Guedes u16 window; 12228b75a89SAndre Guedes int timeout; 1237ba8b4beSAndre Guedes }; 1247ba8b4beSAndre Guedes 125490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH 10 126490c5babSJohan Hedberg 127cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4 1281da177e4SLinus Torvalds struct hci_dev { 1291da177e4SLinus Torvalds struct list_head list; 13009fd0de5SGustavo F. Padovan struct mutex lock; 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds char name[8]; 1331da177e4SLinus Torvalds unsigned long flags; 1341da177e4SLinus Torvalds __u16 id; 135c13854ceSMarcel Holtmann __u8 bus; 136943da25dSMarcel Holtmann __u8 dev_type; 1371da177e4SLinus Torvalds bdaddr_t bdaddr; 1381f6c6378SJohan Hedberg __u8 dev_name[HCI_MAX_NAME_LENGTH]; 139490c5babSJohan Hedberg __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; 14080a1e1dbSJohan Hedberg __u8 eir[HCI_MAX_EIR_LENGTH]; 141a9de9248SMarcel Holtmann __u8 dev_class[3]; 1421aff6f09SJohan Hedberg __u8 major_class; 1431aff6f09SJohan Hedberg __u8 minor_class; 1441da177e4SLinus Torvalds __u8 features[8]; 14559e29406SAndre Guedes __u8 host_features[8]; 146a9de9248SMarcel Holtmann __u8 commands[64]; 1471143e5a6SMarcel Holtmann __u8 hci_ver; 1481143e5a6SMarcel Holtmann __u16 hci_rev; 149d5859e22SJohan Hedberg __u8 lmp_ver; 1501143e5a6SMarcel Holtmann __u16 manufacturer; 1517d69230cSAndrei Emeltchenko __u16 lmp_subver; 1521da177e4SLinus Torvalds __u16 voice_setting; 15317fa4b9dSJohan Hedberg __u8 io_capability; 15491c4e9b1SMarcel Holtmann __s8 inq_tx_power; 1552b9be137SMarcel Holtmann __u16 devid_source; 1562b9be137SMarcel Holtmann __u16 devid_vendor; 1572b9be137SMarcel Holtmann __u16 devid_product; 1582b9be137SMarcel Holtmann __u16 devid_version; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds __u16 pkt_type; 1615b7f9909SMarcel Holtmann __u16 esco_type; 1621da177e4SLinus Torvalds __u16 link_policy; 1631da177e4SLinus Torvalds __u16 link_mode; 1641da177e4SLinus Torvalds 16504837f64SMarcel Holtmann __u32 idle_timeout; 16604837f64SMarcel Holtmann __u16 sniff_min_interval; 16704837f64SMarcel Holtmann __u16 sniff_max_interval; 16804837f64SMarcel Holtmann 169928abaa7SAndrei Emeltchenko __u8 amp_status; 170928abaa7SAndrei Emeltchenko __u32 amp_total_bw; 171928abaa7SAndrei Emeltchenko __u32 amp_max_bw; 172928abaa7SAndrei Emeltchenko __u32 amp_min_latency; 173928abaa7SAndrei Emeltchenko __u32 amp_max_pdu; 174928abaa7SAndrei Emeltchenko __u8 amp_type; 175928abaa7SAndrei Emeltchenko __u16 amp_pal_cap; 176928abaa7SAndrei Emeltchenko __u16 amp_assoc_size; 177928abaa7SAndrei Emeltchenko __u32 amp_max_flush_to; 178928abaa7SAndrei Emeltchenko __u32 amp_be_flush_to; 179928abaa7SAndrei Emeltchenko 1801e89cffbSAndrei Emeltchenko __u8 flow_ctl_mode; 1811e89cffbSAndrei Emeltchenko 1829f61656aSJohan Hedberg unsigned int auto_accept_delay; 1839f61656aSJohan Hedberg 1841da177e4SLinus Torvalds unsigned long quirks; 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds atomic_t cmd_cnt; 1871da177e4SLinus Torvalds unsigned int acl_cnt; 1881da177e4SLinus Torvalds unsigned int sco_cnt; 1896ed58ec5SVille Tervo unsigned int le_cnt; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds unsigned int acl_mtu; 1921da177e4SLinus Torvalds unsigned int sco_mtu; 1936ed58ec5SVille Tervo unsigned int le_mtu; 1941da177e4SLinus Torvalds unsigned int acl_pkts; 1951da177e4SLinus Torvalds unsigned int sco_pkts; 1966ed58ec5SVille Tervo unsigned int le_pkts; 1971da177e4SLinus Torvalds 198350ee4cfSAndrei Emeltchenko __u16 block_len; 199350ee4cfSAndrei Emeltchenko __u16 block_mtu; 200350ee4cfSAndrei Emeltchenko __u16 num_blocks; 201350ee4cfSAndrei Emeltchenko __u16 block_cnt; 202350ee4cfSAndrei Emeltchenko 2031da177e4SLinus Torvalds unsigned long acl_last_tx; 2041da177e4SLinus Torvalds unsigned long sco_last_tx; 2056ed58ec5SVille Tervo unsigned long le_last_tx; 2061da177e4SLinus Torvalds 207f48fd9c8SMarcel Holtmann struct workqueue_struct *workqueue; 208f48fd9c8SMarcel Holtmann 209ab81cbf9SJohan Hedberg struct work_struct power_on; 2103243553fSJohan Hedberg struct delayed_work power_off; 211ab81cbf9SJohan Hedberg 21216ab91abSJohan Hedberg __u16 discov_timeout; 21316ab91abSJohan Hedberg struct delayed_work discov_off; 21416ab91abSJohan Hedberg 2157d78525dSJohan Hedberg struct delayed_work service_cache; 2167d78525dSJohan Hedberg 2176bd32326SVille Tervo struct timer_list cmd_timer; 218b78752ccSMarcel Holtmann 219b78752ccSMarcel Holtmann struct work_struct rx_work; 220c347b765SGustavo F. Padovan struct work_struct cmd_work; 2213eff45eaSGustavo F. Padovan struct work_struct tx_work; 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds struct sk_buff_head rx_q; 2241da177e4SLinus Torvalds struct sk_buff_head raw_q; 2251da177e4SLinus Torvalds struct sk_buff_head cmd_q; 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds struct sk_buff *sent_cmd; 228cd4c5391SSuraj Sumangala struct sk_buff *reassembly[NUM_REASSEMBLY]; 2291da177e4SLinus Torvalds 230a6a67efdSThomas Gleixner struct mutex req_lock; 2311da177e4SLinus Torvalds wait_queue_head_t req_wait_q; 2321da177e4SLinus Torvalds __u32 req_status; 2331da177e4SLinus Torvalds __u32 req_result; 234a5040efaSJohan Hedberg 235a5040efaSJohan Hedberg __u16 init_last_cmd; 2361da177e4SLinus Torvalds 2372e58ef3eSJohan Hedberg struct list_head mgmt_pending; 2382e58ef3eSJohan Hedberg 23930883512SJohan Hedberg struct discovery_state discovery; 2401da177e4SLinus Torvalds struct hci_conn_hash conn_hash; 241ea4bd8baSDavid Miller struct list_head blacklist; 2421da177e4SLinus Torvalds 2432aeb9a1aSJohan Hedberg struct list_head uuids; 2442aeb9a1aSJohan Hedberg 24555ed8ca1SJohan Hedberg struct list_head link_keys; 24655ed8ca1SJohan Hedberg 247b899efafSVinicius Costa Gomes struct list_head long_term_keys; 248b899efafSVinicius Costa Gomes 2492763eda6SSzymon Janc struct list_head remote_oob_data; 2502763eda6SSzymon Janc 2511da177e4SLinus Torvalds struct hci_dev_stats stat; 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvalds struct sk_buff_head driver_init; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds void *core_data; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds atomic_t promisc; 2581da177e4SLinus Torvalds 259ca325f69SMarcel Holtmann struct dentry *debugfs; 260ca325f69SMarcel Holtmann 261a91f2e39SMarcel Holtmann struct device dev; 2621da177e4SLinus Torvalds 263611b30f7SMarcel Holtmann struct rfkill *rfkill; 264611b30f7SMarcel Holtmann 265d23264a8SAndre Guedes unsigned long dev_flags; 266d23264a8SAndre Guedes 2677ba8b4beSAndre Guedes struct delayed_work le_scan_disable; 2687ba8b4beSAndre Guedes 26928b75a89SAndre Guedes struct work_struct le_scan; 27028b75a89SAndre Guedes struct le_scan_params le_scan_params; 27128b75a89SAndre Guedes 2721da177e4SLinus Torvalds int (*open)(struct hci_dev *hdev); 2731da177e4SLinus Torvalds int (*close)(struct hci_dev *hdev); 2741da177e4SLinus Torvalds int (*flush)(struct hci_dev *hdev); 2751da177e4SLinus Torvalds int (*send)(struct sk_buff *skb); 2761da177e4SLinus Torvalds void (*notify)(struct hci_dev *hdev, unsigned int evt); 2771da177e4SLinus Torvalds int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg); 2781da177e4SLinus Torvalds }; 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds struct hci_conn { 2811da177e4SLinus Torvalds struct list_head list; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds atomic_t refcnt; 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds bdaddr_t dst; 28629b7988aSAndre Guedes __u8 dst_type; 2871da177e4SLinus Torvalds __u16 handle; 2881da177e4SLinus Torvalds __u16 state; 28904837f64SMarcel Holtmann __u8 mode; 2901da177e4SLinus Torvalds __u8 type; 291a0c808b3SJohan Hedberg bool out; 2924c67bc74SMarcel Holtmann __u8 attempt; 2931da177e4SLinus Torvalds __u8 dev_class[3]; 29404837f64SMarcel Holtmann __u8 features[8]; 29504837f64SMarcel Holtmann __u16 interval; 296a8746417SMarcel Holtmann __u16 pkt_type; 29704837f64SMarcel Holtmann __u16 link_policy; 2981da177e4SLinus Torvalds __u32 link_mode; 29913d39315SWaldemar Rymarkiewicz __u8 key_type; 30040be492fSMarcel Holtmann __u8 auth_type; 3018c1b2355SMarcel Holtmann __u8 sec_level; 302765c2a96SJohan Hedberg __u8 pending_sec_level; 303980e1a53SJohan Hedberg __u8 pin_length; 304726b4ffcSVinicius Costa Gomes __u8 enc_key_size; 30517fa4b9dSJohan Hedberg __u8 io_capability; 30692a25256SJohan Hedberg __u32 passkey_notify; 30792a25256SJohan Hedberg __u8 passkey_entered; 308052b30b0SMarcel Holtmann __u16 disc_timeout; 30951a8efd7SJohan Hedberg unsigned long flags; 3101da177e4SLinus Torvalds 31103b555e1SJohan Hedberg __u8 remote_cap; 31203b555e1SJohan Hedberg __u8 remote_auth; 3136ec5bcadSVishal Agarwal bool flush_key; 31403b555e1SJohan Hedberg 3151da177e4SLinus Torvalds unsigned int sent; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds struct sk_buff_head data_q; 3182c33c06aSGustavo F. Padovan struct list_head chan_list; 3191da177e4SLinus Torvalds 32019c40e3bSGustavo F. Padovan struct delayed_work disc_work; 32104837f64SMarcel Holtmann struct timer_list idle_timer; 3229f61656aSJohan Hedberg struct timer_list auto_accept_timer; 3231da177e4SLinus Torvalds 324b219e3acSMarcel Holtmann struct device dev; 3259eba32b8SMarcel Holtmann atomic_t devref; 326b219e3acSMarcel Holtmann 3271da177e4SLinus Torvalds struct hci_dev *hdev; 3281da177e4SLinus Torvalds void *l2cap_data; 3291da177e4SLinus Torvalds void *sco_data; 3302b64d153SBrian Gix void *smp_conn; 3319740e49dSAndrei Emeltchenko struct amp_mgr *amp_mgr; 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds struct hci_conn *link; 334e9a416b5SJohan Hedberg 335e9a416b5SJohan Hedberg void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); 336e9a416b5SJohan Hedberg void (*security_cfm_cb) (struct hci_conn *conn, u8 status); 337e9a416b5SJohan Hedberg void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason); 3381da177e4SLinus Torvalds }; 3391da177e4SLinus Torvalds 34073d80debSLuiz Augusto von Dentz struct hci_chan { 34173d80debSLuiz Augusto von Dentz struct list_head list; 34273d80debSLuiz Augusto von Dentz 34373d80debSLuiz Augusto von Dentz struct hci_conn *conn; 34473d80debSLuiz Augusto von Dentz struct sk_buff_head data_q; 34573d80debSLuiz Augusto von Dentz unsigned int sent; 34673d80debSLuiz Augusto von Dentz }; 34773d80debSLuiz Augusto von Dentz 3481da177e4SLinus Torvalds extern struct list_head hci_dev_list; 3491da177e4SLinus Torvalds extern struct list_head hci_cb_list; 3501da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock; 3511da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock; 3521da177e4SLinus Torvalds 353686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */ 354686ebf28SUlisses Furquim extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 3559e664631SAndrei Emeltchenko extern void l2cap_connect_cfm(struct hci_conn *hcon, u8 status); 356686ebf28SUlisses Furquim extern int l2cap_disconn_ind(struct hci_conn *hcon); 3579e664631SAndrei Emeltchenko extern void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); 358686ebf28SUlisses Furquim extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt); 359c3c7ea65SGustavo Padovan extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, 360c3c7ea65SGustavo Padovan u16 flags); 361686ebf28SUlisses Furquim 362686ebf28SUlisses Furquim extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 3639e664631SAndrei Emeltchenko extern void sco_connect_cfm(struct hci_conn *hcon, __u8 status); 3649e664631SAndrei Emeltchenko extern void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason); 365686ebf28SUlisses Furquim extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb); 366686ebf28SUlisses Furquim 3671da177e4SLinus Torvalds /* ----- Inquiry cache ----- */ 36870f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 36970f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 3701da177e4SLinus Torvalds 37130883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev) 3721da177e4SLinus Torvalds { 373ff9ef578SJohan Hedberg hdev->discovery.state = DISCOVERY_STOPPED; 37430883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.all); 37530883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.unknown); 37630883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.resolve); 3771da177e4SLinus Torvalds } 3781da177e4SLinus Torvalds 37930dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev); 38030dc78e1SJohan Hedberg 381ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state); 382ff9ef578SJohan Hedberg 3831da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev) 3841da177e4SLinus Torvalds { 38530883512SJohan Hedberg return list_empty(&hdev->discovery.all); 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev) 3891da177e4SLinus Torvalds { 39030883512SJohan Hedberg struct discovery_state *c = &hdev->discovery; 3911da177e4SLinus Torvalds return jiffies - c->timestamp; 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e) 3951da177e4SLinus Torvalds { 3961da177e4SLinus Torvalds return jiffies - e->timestamp; 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds 3995a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 4005a9d0a3fSWaldemar Rymarkiewicz bdaddr_t *bdaddr); 401561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 402561aafbcSJohan Hedberg bdaddr_t *bdaddr); 40330dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 40430dc78e1SJohan Hedberg bdaddr_t *bdaddr, 40530dc78e1SJohan Hedberg int state); 406a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 407a3d4e20aSJohan Hedberg struct inquiry_entry *ie); 4083175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 409388fc8faSJohan Hedberg bool name_known, bool *ssp); 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds /* ----- HCI Connections ----- */ 4121da177e4SLinus Torvalds enum { 4131da177e4SLinus Torvalds HCI_CONN_AUTH_PEND, 41419f8def0SWaldemar Rymarkiewicz HCI_CONN_REAUTH_PEND, 4151da177e4SLinus Torvalds HCI_CONN_ENCRYPT_PEND, 41604837f64SMarcel Holtmann HCI_CONN_RSWITCH_PEND, 41704837f64SMarcel Holtmann HCI_CONN_MODE_CHANGE_PEND, 418e73439d8SMarcel Holtmann HCI_CONN_SCO_SETUP_PEND, 419d26a2345SVinicius Costa Gomes HCI_CONN_LE_SMP_PEND, 420b644ba33SJohan Hedberg HCI_CONN_MGMT_CONNECTED, 42158a681efSJohan Hedberg HCI_CONN_SSP_ENABLED, 42258a681efSJohan Hedberg HCI_CONN_POWER_SAVE, 42358a681efSJohan Hedberg HCI_CONN_REMOTE_OOB, 4241da177e4SLinus Torvalds }; 4251da177e4SLinus Torvalds 426aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 427aa64a8b5SJohan Hedberg { 428aa64a8b5SJohan Hedberg struct hci_dev *hdev = conn->hdev; 429c3c7ea65SGustavo Padovan return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && 430c3c7ea65SGustavo Padovan test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); 431aa64a8b5SJohan Hedberg } 432aa64a8b5SJohan Hedberg 4331da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) 4341da177e4SLinus Torvalds { 4351da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 436bf4c6325SGustavo F. Padovan list_add_rcu(&c->list, &h->list); 437fcd89c09SVille Tervo switch (c->type) { 438fcd89c09SVille Tervo case ACL_LINK: 4391da177e4SLinus Torvalds h->acl_num++; 440fcd89c09SVille Tervo break; 441fcd89c09SVille Tervo case LE_LINK: 442fcd89c09SVille Tervo h->le_num++; 443fcd89c09SVille Tervo break; 444fcd89c09SVille Tervo case SCO_LINK: 445fcd89c09SVille Tervo case ESCO_LINK: 4461da177e4SLinus Torvalds h->sco_num++; 447fcd89c09SVille Tervo break; 448fcd89c09SVille Tervo } 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) 4521da177e4SLinus Torvalds { 4531da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 454bf4c6325SGustavo F. Padovan 455bf4c6325SGustavo F. Padovan list_del_rcu(&c->list); 456bf4c6325SGustavo F. Padovan synchronize_rcu(); 457bf4c6325SGustavo F. Padovan 458fcd89c09SVille Tervo switch (c->type) { 459fcd89c09SVille Tervo case ACL_LINK: 4601da177e4SLinus Torvalds h->acl_num--; 461fcd89c09SVille Tervo break; 462fcd89c09SVille Tervo case LE_LINK: 463fcd89c09SVille Tervo h->le_num--; 464fcd89c09SVille Tervo break; 465fcd89c09SVille Tervo case SCO_LINK: 466fcd89c09SVille Tervo case ESCO_LINK: 4671da177e4SLinus Torvalds h->sco_num--; 468fcd89c09SVille Tervo break; 469fcd89c09SVille Tervo } 4701da177e4SLinus Torvalds } 4711da177e4SLinus Torvalds 47252087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) 47352087a79SLuiz Augusto von Dentz { 47452087a79SLuiz Augusto von Dentz struct hci_conn_hash *h = &hdev->conn_hash; 47552087a79SLuiz Augusto von Dentz switch (type) { 47652087a79SLuiz Augusto von Dentz case ACL_LINK: 47752087a79SLuiz Augusto von Dentz return h->acl_num; 47852087a79SLuiz Augusto von Dentz case LE_LINK: 47952087a79SLuiz Augusto von Dentz return h->le_num; 48052087a79SLuiz Augusto von Dentz case SCO_LINK: 48152087a79SLuiz Augusto von Dentz case ESCO_LINK: 48252087a79SLuiz Augusto von Dentz return h->sco_num; 48352087a79SLuiz Augusto von Dentz default: 48452087a79SLuiz Augusto von Dentz return 0; 48552087a79SLuiz Augusto von Dentz } 48652087a79SLuiz Augusto von Dentz } 48752087a79SLuiz Augusto von Dentz 4881da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 4891da177e4SLinus Torvalds __u16 handle) 4901da177e4SLinus Torvalds { 4911da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 4921da177e4SLinus Torvalds struct hci_conn *c; 4931da177e4SLinus Torvalds 494bf4c6325SGustavo F. Padovan rcu_read_lock(); 495bf4c6325SGustavo F. Padovan 496bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 497bf4c6325SGustavo F. Padovan if (c->handle == handle) { 498bf4c6325SGustavo F. Padovan rcu_read_unlock(); 4991da177e4SLinus Torvalds return c; 5001da177e4SLinus Torvalds } 501bf4c6325SGustavo F. Padovan } 502bf4c6325SGustavo F. Padovan rcu_read_unlock(); 503bf4c6325SGustavo F. Padovan 5041da177e4SLinus Torvalds return NULL; 5051da177e4SLinus Torvalds } 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, 5081da177e4SLinus Torvalds __u8 type, bdaddr_t *ba) 5091da177e4SLinus Torvalds { 5101da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 5111da177e4SLinus Torvalds struct hci_conn *c; 5121da177e4SLinus Torvalds 513bf4c6325SGustavo F. Padovan rcu_read_lock(); 514bf4c6325SGustavo F. Padovan 515bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 516bf4c6325SGustavo F. Padovan if (c->type == type && !bacmp(&c->dst, ba)) { 517bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5181da177e4SLinus Torvalds return c; 5191da177e4SLinus Torvalds } 520bf4c6325SGustavo F. Padovan } 521bf4c6325SGustavo F. Padovan 522bf4c6325SGustavo F. Padovan rcu_read_unlock(); 523bf4c6325SGustavo F. Padovan 5241da177e4SLinus Torvalds return NULL; 5251da177e4SLinus Torvalds } 5261da177e4SLinus Torvalds 5274c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, 5284c67bc74SMarcel Holtmann __u8 type, __u16 state) 5294c67bc74SMarcel Holtmann { 5304c67bc74SMarcel Holtmann struct hci_conn_hash *h = &hdev->conn_hash; 5314c67bc74SMarcel Holtmann struct hci_conn *c; 5324c67bc74SMarcel Holtmann 533bf4c6325SGustavo F. Padovan rcu_read_lock(); 534bf4c6325SGustavo F. Padovan 535bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 536bf4c6325SGustavo F. Padovan if (c->type == type && c->state == state) { 537bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5384c67bc74SMarcel Holtmann return c; 5394c67bc74SMarcel Holtmann } 540bf4c6325SGustavo F. Padovan } 541bf4c6325SGustavo F. Padovan 542bf4c6325SGustavo F. Padovan rcu_read_unlock(); 543bf4c6325SGustavo F. Padovan 5444c67bc74SMarcel Holtmann return NULL; 5454c67bc74SMarcel Holtmann } 5464c67bc74SMarcel Holtmann 5471da177e4SLinus Torvalds void hci_acl_disconn(struct hci_conn *conn, __u8 reason); 548b6a0dc82SMarcel Holtmann void hci_setup_sync(struct hci_conn *conn, __u16 handle); 549e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status); 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst); 5521da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn); 5531da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev); 554a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev); 5551da177e4SLinus Torvalds 55673d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn); 5579472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan); 5582c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn); 55973d80debSLuiz Augusto von Dentz 5605a9d0a3fSWaldemar Rymarkiewicz struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, 561b12f62cfSAndre Guedes __u8 dst_type, __u8 sec_level, __u8 auth_type); 562e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn); 563b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); 5640684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); 5651da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn); 5668c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role); 5671da177e4SLinus Torvalds 56814b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); 5691da177e4SLinus Torvalds 5709eba32b8SMarcel Holtmann void hci_conn_hold_device(struct hci_conn *conn); 5719eba32b8SMarcel Holtmann void hci_conn_put_device(struct hci_conn *conn); 5729eba32b8SMarcel Holtmann 5731da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn) 5741da177e4SLinus Torvalds { 57571becf0cSAndrei Emeltchenko BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 57638b3fef1SAndrei Emeltchenko 5771da177e4SLinus Torvalds atomic_inc(&conn->refcnt); 5782f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 5791da177e4SLinus Torvalds } 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds static inline void hci_conn_put(struct hci_conn *conn) 5821da177e4SLinus Torvalds { 58371becf0cSAndrei Emeltchenko BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 58438b3fef1SAndrei Emeltchenko 5851da177e4SLinus Torvalds if (atomic_dec_and_test(&conn->refcnt)) { 58604837f64SMarcel Holtmann unsigned long timeo; 587454d48ffSVinicius Costa Gomes if (conn->type == ACL_LINK || conn->type == LE_LINK) { 5886ac59344SMarcel Holtmann del_timer(&conn->idle_timer); 5896ac59344SMarcel Holtmann if (conn->state == BT_CONNECTED) { 5905f246e89SAndrei Emeltchenko timeo = conn->disc_timeout; 59104837f64SMarcel Holtmann if (!conn->out) 592052b30b0SMarcel Holtmann timeo *= 2; 5935a9d0a3fSWaldemar Rymarkiewicz } else { 5946ac59344SMarcel Holtmann timeo = msecs_to_jiffies(10); 5955a9d0a3fSWaldemar Rymarkiewicz } 5965a9d0a3fSWaldemar Rymarkiewicz } else { 59704837f64SMarcel Holtmann timeo = msecs_to_jiffies(10); 5985a9d0a3fSWaldemar Rymarkiewicz } 5992f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 60019c40e3bSGustavo F. Padovan queue_delayed_work(conn->hdev->workqueue, 6011931782bSVinicius Costa Gomes &conn->disc_work, timeo); 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds } 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds /* ----- HCI Devices ----- */ 606dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d) 6071da177e4SLinus Torvalds { 608376261aeSAndrei Emeltchenko BT_DBG("%s orig refcnt %d", d->name, 609376261aeSAndrei Emeltchenko atomic_read(&d->dev.kobj.kref.refcount)); 610376261aeSAndrei Emeltchenko 6114c724c71SDavid Herrmann put_device(&d->dev); 612010666a1SDavid Herrmann } 6131da177e4SLinus Torvalds 614dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) 6151da177e4SLinus Torvalds { 616376261aeSAndrei Emeltchenko BT_DBG("%s orig refcnt %d", d->name, 617376261aeSAndrei Emeltchenko atomic_read(&d->dev.kobj.kref.refcount)); 618376261aeSAndrei Emeltchenko 6194c724c71SDavid Herrmann get_device(&d->dev); 6201da177e4SLinus Torvalds return d; 6211da177e4SLinus Torvalds } 6221da177e4SLinus Torvalds 62309fd0de5SGustavo F. Padovan #define hci_dev_lock(d) mutex_lock(&d->lock) 62409fd0de5SGustavo F. Padovan #define hci_dev_unlock(d) mutex_unlock(&d->lock) 6251da177e4SLinus Torvalds 626aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev) 6273dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev) 628aa2b86d7SDavid Herrmann 629155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev) 630155961e8SDavid Herrmann { 631155961e8SDavid Herrmann return dev_get_drvdata(&hdev->dev); 632155961e8SDavid Herrmann } 633155961e8SDavid Herrmann 634155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) 635155961e8SDavid Herrmann { 636155961e8SDavid Herrmann dev_set_drvdata(&hdev->dev, data); 637155961e8SDavid Herrmann } 638155961e8SDavid Herrmann 6398598d064SAndrei Emeltchenko /* hci_dev_list shall be locked */ 6408598d064SAndrei Emeltchenko static inline uint8_t __hci_num_ctrl(void) 6418598d064SAndrei Emeltchenko { 6428598d064SAndrei Emeltchenko uint8_t count = 0; 6438598d064SAndrei Emeltchenko struct list_head *p; 6448598d064SAndrei Emeltchenko 6458598d064SAndrei Emeltchenko list_for_each(p, &hci_dev_list) { 6468598d064SAndrei Emeltchenko count++; 6478598d064SAndrei Emeltchenko } 6488598d064SAndrei Emeltchenko 6498598d064SAndrei Emeltchenko return count; 6508598d064SAndrei Emeltchenko } 6518598d064SAndrei Emeltchenko 6521da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index); 6531da177e4SLinus Torvalds struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst); 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void); 6561da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev); 6571da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev); 65859735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev); 6591da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev); 6601da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev); 6611da177e4SLinus Torvalds int hci_dev_open(__u16 dev); 6621da177e4SLinus Torvalds int hci_dev_close(__u16 dev); 6631da177e4SLinus Torvalds int hci_dev_reset(__u16 dev); 6641da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev); 6651da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg); 6661da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg); 6671da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg); 6681da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg); 6691da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); 67040be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); 6711da177e4SLinus Torvalds int hci_inquiry(void __user *arg); 6721da177e4SLinus Torvalds 673c3c7ea65SGustavo Padovan struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, 674c3c7ea65SGustavo Padovan bdaddr_t *bdaddr); 675f0358568SJohan Hedberg int hci_blacklist_clear(struct hci_dev *hdev); 67688c1fe4bSJohan Hedberg int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 67788c1fe4bSJohan Hedberg int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 678f0358568SJohan Hedberg 6792aeb9a1aSJohan Hedberg int hci_uuids_clear(struct hci_dev *hdev); 6802aeb9a1aSJohan Hedberg 68155ed8ca1SJohan Hedberg int hci_link_keys_clear(struct hci_dev *hdev); 68255ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 683d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 684d25e28abSJohan Hedberg bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len); 685c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]); 686c9839a11SVinicius Costa Gomes int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type, 6879a006657SAndrei Emeltchenko int new_key, u8 authenticated, u8 tk[16], u8 enc_size, 6889a006657SAndrei Emeltchenko __le16 ediv, u8 rand[8]); 689c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 690c9839a11SVinicius Costa Gomes u8 addr_type); 691b899efafSVinicius Costa Gomes int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr); 692b899efafSVinicius Costa Gomes int hci_smp_ltks_clear(struct hci_dev *hdev); 69355ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 69455ed8ca1SJohan Hedberg 6952763eda6SSzymon Janc int hci_remote_oob_data_clear(struct hci_dev *hdev); 6962763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 6972763eda6SSzymon Janc bdaddr_t *bdaddr); 6982763eda6SSzymon Janc int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash, 6992763eda6SSzymon Janc u8 *randomizer); 7002763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); 7012763eda6SSzymon Janc 7021da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); 7031da177e4SLinus Torvalds 70476bca880SMarcel Holtmann int hci_recv_frame(struct sk_buff *skb); 705ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count); 70699811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count); 707ef222013SMarcel Holtmann 7080ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev); 709ce242970SDavid Herrmann int hci_add_sysfs(struct hci_dev *hdev); 710ce242970SDavid Herrmann void hci_del_sysfs(struct hci_dev *hdev); 711a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn); 712b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn); 713b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn); 7141da177e4SLinus Torvalds 7156935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds /* ----- LMP capabilities ----- */ 71804837f64SMarcel Holtmann #define lmp_rswitch_capable(dev) ((dev)->features[0] & LMP_RSWITCH) 71904837f64SMarcel Holtmann #define lmp_encrypt_capable(dev) ((dev)->features[0] & LMP_ENCRYPT) 72004837f64SMarcel Holtmann #define lmp_sniff_capable(dev) ((dev)->features[0] & LMP_SNIFF) 72104837f64SMarcel Holtmann #define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR) 7225b7f9909SMarcel Holtmann #define lmp_esco_capable(dev) ((dev)->features[3] & LMP_ESCO) 723769be974SMarcel Holtmann #define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR) 724e702112fSAndrei Emeltchenko #define lmp_no_flush_capable(dev) ((dev)->features[6] & LMP_NO_FLUSH) 7256ed58ec5SVille Tervo #define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE) 7265e0452c0SAndre Guedes #define lmp_bredr_capable(dev) (!((dev)->features[4] & LMP_NO_BREDR)) 7271da177e4SLinus Torvalds 728eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */ 72959e29406SAndre Guedes #define lmp_host_le_capable(dev) ((dev)->host_features[0] & LMP_HOST_LE) 730eead27daSAndre Guedes 7311da177e4SLinus Torvalds /* ----- HCI protocols ----- */ 7325a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 7335a9d0a3fSWaldemar Rymarkiewicz __u8 type) 7341da177e4SLinus Torvalds { 735686ebf28SUlisses Furquim switch (type) { 736686ebf28SUlisses Furquim case ACL_LINK: 737686ebf28SUlisses Furquim return l2cap_connect_ind(hdev, bdaddr); 7381da177e4SLinus Torvalds 739686ebf28SUlisses Furquim case SCO_LINK: 740686ebf28SUlisses Furquim case ESCO_LINK: 741686ebf28SUlisses Furquim return sco_connect_ind(hdev, bdaddr); 7421da177e4SLinus Torvalds 743686ebf28SUlisses Furquim default: 744686ebf28SUlisses Furquim BT_ERR("unknown link type %d", type); 745686ebf28SUlisses Furquim return -EINVAL; 746686ebf28SUlisses Furquim } 7471da177e4SLinus Torvalds } 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status) 7501da177e4SLinus Torvalds { 751686ebf28SUlisses Furquim switch (conn->type) { 752686ebf28SUlisses Furquim case ACL_LINK: 753686ebf28SUlisses Furquim case LE_LINK: 754686ebf28SUlisses Furquim l2cap_connect_cfm(conn, status); 755686ebf28SUlisses Furquim break; 7561da177e4SLinus Torvalds 757686ebf28SUlisses Furquim case SCO_LINK: 758686ebf28SUlisses Furquim case ESCO_LINK: 759686ebf28SUlisses Furquim sco_connect_cfm(conn, status); 760686ebf28SUlisses Furquim break; 7611da177e4SLinus Torvalds 762686ebf28SUlisses Furquim default: 763686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 764686ebf28SUlisses Furquim break; 765686ebf28SUlisses Furquim } 766e9a416b5SJohan Hedberg 767e9a416b5SJohan Hedberg if (conn->connect_cfm_cb) 768e9a416b5SJohan Hedberg conn->connect_cfm_cb(conn, status); 7691da177e4SLinus Torvalds } 7701da177e4SLinus Torvalds 7712950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn) 7722950f21aSMarcel Holtmann { 773686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 774686ebf28SUlisses Furquim return HCI_ERROR_REMOTE_USER_TERM; 7752950f21aSMarcel Holtmann 776686ebf28SUlisses Furquim return l2cap_disconn_ind(conn); 7772950f21aSMarcel Holtmann } 7782950f21aSMarcel Holtmann 7792950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason) 7801da177e4SLinus Torvalds { 781686ebf28SUlisses Furquim switch (conn->type) { 782686ebf28SUlisses Furquim case ACL_LINK: 783686ebf28SUlisses Furquim case LE_LINK: 784686ebf28SUlisses Furquim l2cap_disconn_cfm(conn, reason); 785686ebf28SUlisses Furquim break; 7861da177e4SLinus Torvalds 787686ebf28SUlisses Furquim case SCO_LINK: 788686ebf28SUlisses Furquim case ESCO_LINK: 789686ebf28SUlisses Furquim sco_disconn_cfm(conn, reason); 790686ebf28SUlisses Furquim break; 7911da177e4SLinus Torvalds 792686ebf28SUlisses Furquim default: 793686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 794686ebf28SUlisses Furquim break; 795686ebf28SUlisses Furquim } 796e9a416b5SJohan Hedberg 797e9a416b5SJohan Hedberg if (conn->disconn_cfm_cb) 798e9a416b5SJohan Hedberg conn->disconn_cfm_cb(conn, reason); 7991da177e4SLinus Torvalds } 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status) 8021da177e4SLinus Torvalds { 8038c1b2355SMarcel Holtmann __u8 encrypt; 8048c1b2355SMarcel Holtmann 805686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 806686ebf28SUlisses Furquim return; 807686ebf28SUlisses Furquim 80851a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 8098c1b2355SMarcel Holtmann return; 8108c1b2355SMarcel Holtmann 8118c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 812686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 813e9a416b5SJohan Hedberg 814e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 815e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds 8185a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, 8195a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 8201da177e4SLinus Torvalds { 821686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 822686ebf28SUlisses Furquim return; 8231da177e4SLinus Torvalds 824686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 825e9a416b5SJohan Hedberg 826e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 827e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 8281da177e4SLinus Torvalds } 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds /* ----- HCI callbacks ----- */ 8311da177e4SLinus Torvalds struct hci_cb { 8321da177e4SLinus Torvalds struct list_head list; 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds char *name; 8351da177e4SLinus Torvalds 8365a9d0a3fSWaldemar Rymarkiewicz void (*security_cfm) (struct hci_conn *conn, __u8 status, 8375a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt); 8381da177e4SLinus Torvalds void (*key_change_cfm) (struct hci_conn *conn, __u8 status); 8391da177e4SLinus Torvalds void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); 8401da177e4SLinus Torvalds }; 8411da177e4SLinus Torvalds 8421da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) 8431da177e4SLinus Torvalds { 8441da177e4SLinus Torvalds struct list_head *p; 8458c1b2355SMarcel Holtmann __u8 encrypt; 8461da177e4SLinus Torvalds 8471da177e4SLinus Torvalds hci_proto_auth_cfm(conn, status); 8481da177e4SLinus Torvalds 84951a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 8508c1b2355SMarcel Holtmann return; 8518c1b2355SMarcel Holtmann 8528c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 8538c1b2355SMarcel Holtmann 854f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 8551da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 8561da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 8578c1b2355SMarcel Holtmann if (cb->security_cfm) 8588c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 8591da177e4SLinus Torvalds } 860f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 8611da177e4SLinus Torvalds } 8621da177e4SLinus Torvalds 8635a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, 8645a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 8651da177e4SLinus Torvalds { 8661da177e4SLinus Torvalds struct list_head *p; 8671da177e4SLinus Torvalds 868435fef20SMarcel Holtmann if (conn->sec_level == BT_SECURITY_SDP) 869435fef20SMarcel Holtmann conn->sec_level = BT_SECURITY_LOW; 870435fef20SMarcel Holtmann 87188167aedSVinicius Costa Gomes if (conn->pending_sec_level > conn->sec_level) 87288167aedSVinicius Costa Gomes conn->sec_level = conn->pending_sec_level; 87388167aedSVinicius Costa Gomes 8749719f8afSMarcel Holtmann hci_proto_encrypt_cfm(conn, status, encrypt); 8751da177e4SLinus Torvalds 876f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 8771da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 8781da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 8798c1b2355SMarcel Holtmann if (cb->security_cfm) 8808c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 8811da177e4SLinus Torvalds } 882f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 8831da177e4SLinus Torvalds } 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) 8861da177e4SLinus Torvalds { 8871da177e4SLinus Torvalds struct list_head *p; 8881da177e4SLinus Torvalds 889f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 8901da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 8911da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 8921da177e4SLinus Torvalds if (cb->key_change_cfm) 8931da177e4SLinus Torvalds cb->key_change_cfm(conn, status); 8941da177e4SLinus Torvalds } 895f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 8961da177e4SLinus Torvalds } 8971da177e4SLinus Torvalds 8985a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, 8995a9d0a3fSWaldemar Rymarkiewicz __u8 role) 9001da177e4SLinus Torvalds { 9011da177e4SLinus Torvalds struct list_head *p; 9021da177e4SLinus Torvalds 903f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 9041da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 9051da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 9061da177e4SLinus Torvalds if (cb->role_switch_cfm) 9071da177e4SLinus Torvalds cb->role_switch_cfm(conn, status, role); 9081da177e4SLinus Torvalds } 909f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 9101da177e4SLinus Torvalds } 9111da177e4SLinus Torvalds 9126759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) 9136759a675SJohan Hedberg { 91484d9d071SJohan Hedberg size_t parsed = 0; 9156759a675SJohan Hedberg 9166c0c331eSJohan Hedberg if (data_len < 2) 9176c0c331eSJohan Hedberg return false; 9186c0c331eSJohan Hedberg 91984d9d071SJohan Hedberg while (parsed < data_len - 1) { 92084d9d071SJohan Hedberg u8 field_len = data[0]; 9216759a675SJohan Hedberg 9226759a675SJohan Hedberg if (field_len == 0) 9236759a675SJohan Hedberg break; 9246759a675SJohan Hedberg 9256759a675SJohan Hedberg parsed += field_len + 1; 9266759a675SJohan Hedberg 9276759a675SJohan Hedberg if (parsed > data_len) 9286759a675SJohan Hedberg break; 9296759a675SJohan Hedberg 9306759a675SJohan Hedberg if (data[1] == type) 9316759a675SJohan Hedberg return true; 9326759a675SJohan Hedberg 9336759a675SJohan Hedberg data += field_len + 1; 9346759a675SJohan Hedberg } 9356759a675SJohan Hedberg 9366759a675SJohan Hedberg return false; 9376759a675SJohan Hedberg } 9386759a675SJohan Hedberg 9399d939d94SVishal Agarwal static inline size_t eir_get_length(u8 *eir, size_t eir_len) 9409d939d94SVishal Agarwal { 9419d939d94SVishal Agarwal size_t parsed = 0; 9429d939d94SVishal Agarwal 9439d939d94SVishal Agarwal while (parsed < eir_len) { 9449d939d94SVishal Agarwal u8 field_len = eir[0]; 9459d939d94SVishal Agarwal 9469d939d94SVishal Agarwal if (field_len == 0) 9479d939d94SVishal Agarwal return parsed; 9489d939d94SVishal Agarwal 9499d939d94SVishal Agarwal parsed += field_len + 1; 9509d939d94SVishal Agarwal eir += field_len + 1; 9519d939d94SVishal Agarwal } 9529d939d94SVishal Agarwal 9539d939d94SVishal Agarwal return eir_len; 9549d939d94SVishal Agarwal } 9559d939d94SVishal Agarwal 9561dc06093SJohan Hedberg static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data, 9571dc06093SJohan Hedberg u8 data_len) 9581dc06093SJohan Hedberg { 9591dc06093SJohan Hedberg eir[eir_len++] = sizeof(type) + data_len; 9601dc06093SJohan Hedberg eir[eir_len++] = type; 9611dc06093SJohan Hedberg memcpy(&eir[eir_len], data, data_len); 9621dc06093SJohan Hedberg eir_len += data_len; 9631dc06093SJohan Hedberg 9641dc06093SJohan Hedberg return eir_len; 9651dc06093SJohan Hedberg } 9661dc06093SJohan Hedberg 9671da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb); 9681da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb); 9691da177e4SLinus Torvalds 970a9de9248SMarcel Holtmann int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param); 97173d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 9720d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 9731da177e4SLinus Torvalds 974a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); 9751da177e4SLinus Torvalds 9761da177e4SLinus Torvalds /* ----- HCI Sockets ----- */ 977470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); 978470fe1b5SMarcel Holtmann void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk); 979cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); 9801da177e4SLinus Torvalds 981040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event); 982040030efSMarcel Holtmann 9830381101fSJohan Hedberg /* Management interface */ 984591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR)) 985591f47f3SAndre Guedes #define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \ 986591f47f3SAndre Guedes BIT(BDADDR_LE_RANDOM)) 987591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \ 988591f47f3SAndre Guedes BIT(BDADDR_LE_PUBLIC) | \ 989591f47f3SAndre Guedes BIT(BDADDR_LE_RANDOM)) 990f39799f5SAndre Guedes 9910381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); 992744cf19eSJohan Hedberg int mgmt_index_added(struct hci_dev *hdev); 993744cf19eSJohan Hedberg int mgmt_index_removed(struct hci_dev *hdev); 994744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered); 995744cf19eSJohan Hedberg int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); 996744cf19eSJohan Hedberg int mgmt_connectable(struct hci_dev *hdev, u8 connectable); 997744cf19eSJohan Hedberg int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 998744cf19eSJohan Hedberg int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 999745c0ce3SVishal Agarwal bool persistent); 1000afc747a6SJohan Hedberg int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 100104124681SGustavo F. Padovan u8 addr_type, u32 flags, u8 *name, u8 name_len, 100204124681SGustavo F. Padovan u8 *dev_class); 1003afc747a6SJohan Hedberg int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 1004f0d6a0eaSMikel Astiz u8 link_type, u8 addr_type, u8 reason); 100588c3df13SJohan Hedberg int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 100688c3df13SJohan Hedberg u8 link_type, u8 addr_type, u8 status); 100748264f06SJohan Hedberg int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 100848264f06SJohan Hedberg u8 addr_type, u8 status); 1009744cf19eSJohan Hedberg int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 1010744cf19eSJohan Hedberg int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1011c35938b2SSzymon Janc u8 status); 1012744cf19eSJohan Hedberg int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1013744cf19eSJohan Hedberg u8 status); 1014744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1015272d90dfSJohan Hedberg u8 link_type, u8 addr_type, __le32 value, 1016272d90dfSJohan Hedberg u8 confirm_hint); 1017744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1018272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1019272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1020272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1021272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1022272d90dfSJohan Hedberg u8 link_type, u8 addr_type); 1023604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1024272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1025272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1026272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 102792a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, 102892a25256SJohan Hedberg u8 link_type, u8 addr_type, u32 passkey, 102992a25256SJohan Hedberg u8 entered); 1030bab73cb6SJohan Hedberg int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1031bab73cb6SJohan Hedberg u8 addr_type, u8 status); 103233ef95edSJohan Hedberg int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); 1033c0ecddc2SJohan Hedberg int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 10347f9a903cSMarcel Holtmann int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 10357f9a903cSMarcel Holtmann u8 status); 1036744cf19eSJohan Hedberg int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1037744cf19eSJohan Hedberg int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 1038744cf19eSJohan Hedberg u8 *randomizer, u8 status); 103906199cf8SJohan Hedberg int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 104048264f06SJohan Hedberg int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 104104124681SGustavo F. Padovan u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, 104204124681SGustavo F. Padovan u8 ssp, u8 *eir, u16 eir_len); 1043b644ba33SJohan Hedberg int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1044b644ba33SJohan Hedberg u8 addr_type, s8 rssi, u8 *name, u8 name_len); 10457a135109SAndre Guedes int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status); 1046e6d465cbSAndre Guedes int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status); 1047744cf19eSJohan Hedberg int mgmt_discovering(struct hci_dev *hdev, u8 discovering); 10485e0452c0SAndre Guedes int mgmt_interleaved_discovery(struct hci_dev *hdev); 104988c1fe4bSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 105088c1fe4bSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 1051bb4b2a9aSAndrei Emeltchenko bool mgmt_valid_hdev(struct hci_dev *hdev); 1052346af67bSVinicius Costa Gomes int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent); 1053346af67bSVinicius Costa Gomes 10541da177e4SLinus Torvalds /* HCI info for socket */ 10551da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk) 10561da177e4SLinus Torvalds 10571da177e4SLinus Torvalds struct hci_pinfo { 10581da177e4SLinus Torvalds struct bt_sock bt; 10591da177e4SLinus Torvalds struct hci_dev *hdev; 10601da177e4SLinus Torvalds struct hci_filter filter; 10611da177e4SLinus Torvalds __u32 cmsg_mask; 1062c02178d2SJohan Hedberg unsigned short channel; 10631da177e4SLinus Torvalds }; 10641da177e4SLinus Torvalds 10651da177e4SLinus Torvalds /* HCI security filter */ 10661da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF 5 10671da177e4SLinus Torvalds 10681da177e4SLinus Torvalds struct hci_sec_filter { 10691da177e4SLinus Torvalds __u32 type_mask; 10701da177e4SLinus Torvalds __u32 event_mask[2]; 10711da177e4SLinus Torvalds __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4]; 10721da177e4SLinus Torvalds }; 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds /* ----- HCI requests ----- */ 10751da177e4SLinus Torvalds #define HCI_REQ_DONE 0 10761da177e4SLinus Torvalds #define HCI_REQ_PEND 1 10771da177e4SLinus Torvalds #define HCI_REQ_CANCELED 2 10781da177e4SLinus Torvalds 1079a6a67efdSThomas Gleixner #define hci_req_lock(d) mutex_lock(&d->req_lock) 1080a6a67efdSThomas Gleixner #define hci_req_unlock(d) mutex_unlock(&d->req_lock) 10811da177e4SLinus Torvalds 108223bb5763SJohan Hedberg void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result); 10831da177e4SLinus Torvalds 10842ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, 10852ce603ebSClaudio Takahasi u16 latency, u16 to_multiplier); 1086a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8], 1087a7a595f6SVinicius Costa Gomes __u8 ltk[16]); 10882519a1fcSAndre Guedes int hci_do_inquiry(struct hci_dev *hdev, u8 length); 1089023d5049SAndre Guedes int hci_cancel_inquiry(struct hci_dev *hdev); 109028b75a89SAndre Guedes int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window, 109128b75a89SAndre Guedes int timeout); 10927dbfac1dSAndre Guedes int hci_cancel_le_scan(struct hci_dev *hdev); 10932519a1fcSAndre Guedes 109431f7956cSAndre Guedes u8 bdaddr_to_le(u8 bdaddr_type); 109531f7956cSAndre Guedes 10961da177e4SLinus Torvalds #endif /* __HCI_CORE_H */ 1097