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 28a6b7a407SAlexey Dobriyan #include <linux/interrupt.h> 291da177e4SLinus Torvalds #include <net/bluetooth/hci.h> 301da177e4SLinus Torvalds 315e59b791SLuiz Augusto von Dentz /* HCI priority */ 325e59b791SLuiz Augusto von Dentz #define HCI_PRIO_MAX 7 335e59b791SLuiz Augusto von Dentz 341da177e4SLinus Torvalds /* HCI Core structures */ 351da177e4SLinus Torvalds struct inquiry_data { 361da177e4SLinus Torvalds bdaddr_t bdaddr; 371da177e4SLinus Torvalds __u8 pscan_rep_mode; 381da177e4SLinus Torvalds __u8 pscan_period_mode; 391da177e4SLinus Torvalds __u8 pscan_mode; 401da177e4SLinus Torvalds __u8 dev_class[3]; 411ebb9252SMarcel Holtmann __le16 clock_offset; 421da177e4SLinus Torvalds __s8 rssi; 4341a96212SMarcel Holtmann __u8 ssp_mode; 441da177e4SLinus Torvalds }; 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds struct inquiry_entry { 47561aafbcSJohan Hedberg struct list_head all; /* inq_cache.all */ 48561aafbcSJohan Hedberg struct list_head list; /* unknown or resolve */ 49561aafbcSJohan Hedberg enum { 50561aafbcSJohan Hedberg NAME_NOT_KNOWN, 51561aafbcSJohan Hedberg NAME_NEEDED, 52561aafbcSJohan Hedberg NAME_PENDING, 53561aafbcSJohan Hedberg NAME_KNOWN, 54561aafbcSJohan Hedberg } name_state; 551da177e4SLinus Torvalds __u32 timestamp; 561da177e4SLinus Torvalds struct inquiry_data data; 571da177e4SLinus Torvalds }; 581da177e4SLinus Torvalds 5930883512SJohan Hedberg struct discovery_state { 604aab14e5SAndre Guedes int type; 61ff9ef578SJohan Hedberg enum { 62ff9ef578SJohan Hedberg DISCOVERY_STOPPED, 63ff9ef578SJohan Hedberg DISCOVERY_STARTING, 64343f935bSAndre Guedes DISCOVERY_FINDING, 6530dc78e1SJohan Hedberg DISCOVERY_RESOLVING, 66ff9ef578SJohan Hedberg DISCOVERY_STOPPING, 67ff9ef578SJohan Hedberg } state; 68561aafbcSJohan Hedberg struct list_head all; /* All devices found during inquiry */ 69561aafbcSJohan Hedberg struct list_head unknown; /* Name state not known */ 70561aafbcSJohan Hedberg struct list_head resolve; /* Name needs to be resolved */ 711da177e4SLinus Torvalds __u32 timestamp; 721da177e4SLinus Torvalds }; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds struct hci_conn_hash { 751da177e4SLinus Torvalds struct list_head list; 761da177e4SLinus Torvalds unsigned int acl_num; 771da177e4SLinus Torvalds unsigned int sco_num; 78fcd89c09SVille Tervo unsigned int le_num; 791da177e4SLinus Torvalds }; 801da177e4SLinus Torvalds 81f0358568SJohan Hedberg struct bdaddr_list { 82f0358568SJohan Hedberg struct list_head list; 83f0358568SJohan Hedberg bdaddr_t bdaddr; 84f0358568SJohan Hedberg }; 852aeb9a1aSJohan Hedberg 862aeb9a1aSJohan Hedberg struct bt_uuid { 872aeb9a1aSJohan Hedberg struct list_head list; 882aeb9a1aSJohan Hedberg u8 uuid[16]; 891aff6f09SJohan Hedberg u8 svc_hint; 902aeb9a1aSJohan Hedberg }; 912aeb9a1aSJohan Hedberg 92b899efafSVinicius Costa Gomes struct smp_ltk { 93b899efafSVinicius Costa Gomes struct list_head list; 94b899efafSVinicius Costa Gomes bdaddr_t bdaddr; 95b899efafSVinicius Costa Gomes u8 bdaddr_type; 96b899efafSVinicius Costa Gomes u8 authenticated; 97b899efafSVinicius Costa Gomes u8 type; 98b899efafSVinicius Costa Gomes u8 enc_size; 99b899efafSVinicius Costa Gomes __le16 ediv; 100b899efafSVinicius Costa Gomes u8 rand[8]; 101b899efafSVinicius Costa Gomes u8 val[16]; 102b899efafSVinicius Costa Gomes } __packed; 103b899efafSVinicius Costa Gomes 10455ed8ca1SJohan Hedberg struct link_key { 10555ed8ca1SJohan Hedberg struct list_head list; 10655ed8ca1SJohan Hedberg bdaddr_t bdaddr; 10755ed8ca1SJohan Hedberg u8 type; 10855ed8ca1SJohan Hedberg u8 val[16]; 10955ed8ca1SJohan Hedberg u8 pin_len; 11055ed8ca1SJohan Hedberg }; 11155ed8ca1SJohan Hedberg 1122763eda6SSzymon Janc struct oob_data { 1132763eda6SSzymon Janc struct list_head list; 1142763eda6SSzymon Janc bdaddr_t bdaddr; 1152763eda6SSzymon Janc u8 hash[16]; 1162763eda6SSzymon Janc u8 randomizer[16]; 1172763eda6SSzymon Janc }; 1182763eda6SSzymon Janc 11976c8686fSAndre Guedes struct adv_entry { 12076c8686fSAndre Guedes struct list_head list; 12176c8686fSAndre Guedes bdaddr_t bdaddr; 12276c8686fSAndre Guedes u8 bdaddr_type; 12376c8686fSAndre Guedes }; 12476c8686fSAndre Guedes 1257ba8b4beSAndre Guedes struct le_scan_params { 1267ba8b4beSAndre Guedes u8 type; 1277ba8b4beSAndre Guedes u16 interval; 1287ba8b4beSAndre Guedes u16 window; 12928b75a89SAndre Guedes int timeout; 1307ba8b4beSAndre Guedes }; 1317ba8b4beSAndre Guedes 132490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH 10 133490c5babSJohan Hedberg 134cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4 1351da177e4SLinus Torvalds struct hci_dev { 1361da177e4SLinus Torvalds struct list_head list; 13709fd0de5SGustavo F. Padovan struct mutex lock; 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds char name[8]; 1401da177e4SLinus Torvalds unsigned long flags; 1411da177e4SLinus Torvalds __u16 id; 142c13854ceSMarcel Holtmann __u8 bus; 143943da25dSMarcel Holtmann __u8 dev_type; 1441da177e4SLinus Torvalds bdaddr_t bdaddr; 1451f6c6378SJohan Hedberg __u8 dev_name[HCI_MAX_NAME_LENGTH]; 146490c5babSJohan Hedberg __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; 14780a1e1dbSJohan Hedberg __u8 eir[HCI_MAX_EIR_LENGTH]; 148a9de9248SMarcel Holtmann __u8 dev_class[3]; 1491aff6f09SJohan Hedberg __u8 major_class; 1501aff6f09SJohan Hedberg __u8 minor_class; 1511da177e4SLinus Torvalds __u8 features[8]; 15259e29406SAndre Guedes __u8 host_features[8]; 153a9de9248SMarcel Holtmann __u8 commands[64]; 1541143e5a6SMarcel Holtmann __u8 hci_ver; 1551143e5a6SMarcel Holtmann __u16 hci_rev; 156d5859e22SJohan Hedberg __u8 lmp_ver; 1571143e5a6SMarcel Holtmann __u16 manufacturer; 1587d69230cSAndrei Emeltchenko __u16 lmp_subver; 1591da177e4SLinus Torvalds __u16 voice_setting; 16017fa4b9dSJohan Hedberg __u8 io_capability; 16191c4e9b1SMarcel Holtmann __s8 inq_tx_power; 1622b9be137SMarcel Holtmann __u16 devid_source; 1632b9be137SMarcel Holtmann __u16 devid_vendor; 1642b9be137SMarcel Holtmann __u16 devid_product; 1652b9be137SMarcel Holtmann __u16 devid_version; 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds __u16 pkt_type; 1685b7f9909SMarcel Holtmann __u16 esco_type; 1691da177e4SLinus Torvalds __u16 link_policy; 1701da177e4SLinus Torvalds __u16 link_mode; 1711da177e4SLinus Torvalds 17204837f64SMarcel Holtmann __u32 idle_timeout; 17304837f64SMarcel Holtmann __u16 sniff_min_interval; 17404837f64SMarcel Holtmann __u16 sniff_max_interval; 17504837f64SMarcel Holtmann 176928abaa7SAndrei Emeltchenko __u8 amp_status; 177928abaa7SAndrei Emeltchenko __u32 amp_total_bw; 178928abaa7SAndrei Emeltchenko __u32 amp_max_bw; 179928abaa7SAndrei Emeltchenko __u32 amp_min_latency; 180928abaa7SAndrei Emeltchenko __u32 amp_max_pdu; 181928abaa7SAndrei Emeltchenko __u8 amp_type; 182928abaa7SAndrei Emeltchenko __u16 amp_pal_cap; 183928abaa7SAndrei Emeltchenko __u16 amp_assoc_size; 184928abaa7SAndrei Emeltchenko __u32 amp_max_flush_to; 185928abaa7SAndrei Emeltchenko __u32 amp_be_flush_to; 186928abaa7SAndrei Emeltchenko 1871e89cffbSAndrei Emeltchenko __u8 flow_ctl_mode; 1881e89cffbSAndrei Emeltchenko 1899f61656aSJohan Hedberg unsigned int auto_accept_delay; 1909f61656aSJohan Hedberg 1911da177e4SLinus Torvalds unsigned long quirks; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds atomic_t cmd_cnt; 1941da177e4SLinus Torvalds unsigned int acl_cnt; 1951da177e4SLinus Torvalds unsigned int sco_cnt; 1966ed58ec5SVille Tervo unsigned int le_cnt; 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds unsigned int acl_mtu; 1991da177e4SLinus Torvalds unsigned int sco_mtu; 2006ed58ec5SVille Tervo unsigned int le_mtu; 2011da177e4SLinus Torvalds unsigned int acl_pkts; 2021da177e4SLinus Torvalds unsigned int sco_pkts; 2036ed58ec5SVille Tervo unsigned int le_pkts; 2041da177e4SLinus Torvalds 205350ee4cfSAndrei Emeltchenko __u16 block_len; 206350ee4cfSAndrei Emeltchenko __u16 block_mtu; 207350ee4cfSAndrei Emeltchenko __u16 num_blocks; 208350ee4cfSAndrei Emeltchenko __u16 block_cnt; 209350ee4cfSAndrei Emeltchenko 2101da177e4SLinus Torvalds unsigned long acl_last_tx; 2111da177e4SLinus Torvalds unsigned long sco_last_tx; 2126ed58ec5SVille Tervo unsigned long le_last_tx; 2131da177e4SLinus Torvalds 214f48fd9c8SMarcel Holtmann struct workqueue_struct *workqueue; 215f48fd9c8SMarcel Holtmann 216ab81cbf9SJohan Hedberg struct work_struct power_on; 2173243553fSJohan Hedberg struct delayed_work power_off; 218ab81cbf9SJohan Hedberg 21916ab91abSJohan Hedberg __u16 discov_timeout; 22016ab91abSJohan Hedberg struct delayed_work discov_off; 22116ab91abSJohan Hedberg 2227d78525dSJohan Hedberg struct delayed_work service_cache; 2237d78525dSJohan Hedberg 2246bd32326SVille Tervo struct timer_list cmd_timer; 225b78752ccSMarcel Holtmann 226b78752ccSMarcel Holtmann struct work_struct rx_work; 227c347b765SGustavo F. Padovan struct work_struct cmd_work; 2283eff45eaSGustavo F. Padovan struct work_struct tx_work; 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds struct sk_buff_head rx_q; 2311da177e4SLinus Torvalds struct sk_buff_head raw_q; 2321da177e4SLinus Torvalds struct sk_buff_head cmd_q; 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds struct sk_buff *sent_cmd; 235cd4c5391SSuraj Sumangala struct sk_buff *reassembly[NUM_REASSEMBLY]; 2361da177e4SLinus Torvalds 237a6a67efdSThomas Gleixner struct mutex req_lock; 2381da177e4SLinus Torvalds wait_queue_head_t req_wait_q; 2391da177e4SLinus Torvalds __u32 req_status; 2401da177e4SLinus Torvalds __u32 req_result; 241a5040efaSJohan Hedberg 242a5040efaSJohan Hedberg __u16 init_last_cmd; 2431da177e4SLinus Torvalds 2442e58ef3eSJohan Hedberg struct list_head mgmt_pending; 2452e58ef3eSJohan Hedberg 24630883512SJohan Hedberg struct discovery_state discovery; 2471da177e4SLinus Torvalds struct hci_conn_hash conn_hash; 248ea4bd8baSDavid Miller struct list_head blacklist; 2491da177e4SLinus Torvalds 2502aeb9a1aSJohan Hedberg struct list_head uuids; 2512aeb9a1aSJohan Hedberg 25255ed8ca1SJohan Hedberg struct list_head link_keys; 25355ed8ca1SJohan Hedberg 254b899efafSVinicius Costa Gomes struct list_head long_term_keys; 255b899efafSVinicius Costa Gomes 2562763eda6SSzymon Janc struct list_head remote_oob_data; 2572763eda6SSzymon Janc 25876c8686fSAndre Guedes struct list_head adv_entries; 259db323f2fSGustavo F. Padovan struct delayed_work adv_work; 26076c8686fSAndre Guedes 2611da177e4SLinus Torvalds struct hci_dev_stats stat; 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds struct sk_buff_head driver_init; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds void *core_data; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds atomic_t promisc; 2681da177e4SLinus Torvalds 269ca325f69SMarcel Holtmann struct dentry *debugfs; 270ca325f69SMarcel Holtmann 271a91f2e39SMarcel Holtmann struct device dev; 2721da177e4SLinus Torvalds 273611b30f7SMarcel Holtmann struct rfkill *rfkill; 274611b30f7SMarcel Holtmann 275d23264a8SAndre Guedes unsigned long dev_flags; 276d23264a8SAndre Guedes 2777ba8b4beSAndre Guedes struct delayed_work le_scan_disable; 2787ba8b4beSAndre Guedes 27928b75a89SAndre Guedes struct work_struct le_scan; 28028b75a89SAndre Guedes struct le_scan_params le_scan_params; 28128b75a89SAndre Guedes 2821da177e4SLinus Torvalds int (*open)(struct hci_dev *hdev); 2831da177e4SLinus Torvalds int (*close)(struct hci_dev *hdev); 2841da177e4SLinus Torvalds int (*flush)(struct hci_dev *hdev); 2851da177e4SLinus Torvalds int (*send)(struct sk_buff *skb); 2861da177e4SLinus Torvalds void (*notify)(struct hci_dev *hdev, unsigned int evt); 2871da177e4SLinus Torvalds int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg); 2881da177e4SLinus Torvalds }; 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds struct hci_conn { 2911da177e4SLinus Torvalds struct list_head list; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds atomic_t refcnt; 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds bdaddr_t dst; 29629b7988aSAndre Guedes __u8 dst_type; 2971da177e4SLinus Torvalds __u16 handle; 2981da177e4SLinus Torvalds __u16 state; 29904837f64SMarcel Holtmann __u8 mode; 3001da177e4SLinus Torvalds __u8 type; 301a0c808b3SJohan Hedberg bool out; 3024c67bc74SMarcel Holtmann __u8 attempt; 3031da177e4SLinus Torvalds __u8 dev_class[3]; 30404837f64SMarcel Holtmann __u8 features[8]; 30504837f64SMarcel Holtmann __u16 interval; 306a8746417SMarcel Holtmann __u16 pkt_type; 30704837f64SMarcel Holtmann __u16 link_policy; 3081da177e4SLinus Torvalds __u32 link_mode; 30913d39315SWaldemar Rymarkiewicz __u8 key_type; 31040be492fSMarcel Holtmann __u8 auth_type; 3118c1b2355SMarcel Holtmann __u8 sec_level; 312765c2a96SJohan Hedberg __u8 pending_sec_level; 313980e1a53SJohan Hedberg __u8 pin_length; 314726b4ffcSVinicius Costa Gomes __u8 enc_key_size; 31517fa4b9dSJohan Hedberg __u8 io_capability; 316052b30b0SMarcel Holtmann __u16 disc_timeout; 31751a8efd7SJohan Hedberg unsigned long flags; 3181da177e4SLinus Torvalds 31903b555e1SJohan Hedberg __u8 remote_cap; 32003b555e1SJohan Hedberg __u8 remote_auth; 3216ec5bcadSVishal Agarwal bool flush_key; 32203b555e1SJohan Hedberg 3231da177e4SLinus Torvalds unsigned int sent; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds struct sk_buff_head data_q; 3262c33c06aSGustavo F. Padovan struct list_head chan_list; 3271da177e4SLinus Torvalds 32819c40e3bSGustavo F. Padovan struct delayed_work disc_work; 32904837f64SMarcel Holtmann struct timer_list idle_timer; 3309f61656aSJohan Hedberg struct timer_list auto_accept_timer; 3311da177e4SLinus Torvalds 332b219e3acSMarcel Holtmann struct device dev; 3339eba32b8SMarcel Holtmann atomic_t devref; 334b219e3acSMarcel Holtmann 3351da177e4SLinus Torvalds struct hci_dev *hdev; 3361da177e4SLinus Torvalds void *l2cap_data; 3371da177e4SLinus Torvalds void *sco_data; 3382b64d153SBrian Gix void *smp_conn; 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds struct hci_conn *link; 341e9a416b5SJohan Hedberg 342e9a416b5SJohan Hedberg void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); 343e9a416b5SJohan Hedberg void (*security_cfm_cb) (struct hci_conn *conn, u8 status); 344e9a416b5SJohan Hedberg void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason); 3451da177e4SLinus Torvalds }; 3461da177e4SLinus Torvalds 34773d80debSLuiz Augusto von Dentz struct hci_chan { 34873d80debSLuiz Augusto von Dentz struct list_head list; 34973d80debSLuiz Augusto von Dentz 35073d80debSLuiz Augusto von Dentz struct hci_conn *conn; 35173d80debSLuiz Augusto von Dentz struct sk_buff_head data_q; 35273d80debSLuiz Augusto von Dentz unsigned int sent; 35373d80debSLuiz Augusto von Dentz }; 35473d80debSLuiz Augusto von Dentz 3551da177e4SLinus Torvalds extern struct list_head hci_dev_list; 3561da177e4SLinus Torvalds extern struct list_head hci_cb_list; 3571da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock; 3581da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock; 3591da177e4SLinus Torvalds 360686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */ 361686ebf28SUlisses Furquim extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 362686ebf28SUlisses Furquim extern int l2cap_connect_cfm(struct hci_conn *hcon, u8 status); 363686ebf28SUlisses Furquim extern int l2cap_disconn_ind(struct hci_conn *hcon); 364686ebf28SUlisses Furquim extern int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); 365686ebf28SUlisses Furquim extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt); 366686ebf28SUlisses Furquim extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); 367686ebf28SUlisses Furquim 368686ebf28SUlisses Furquim extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 369686ebf28SUlisses Furquim extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status); 370686ebf28SUlisses Furquim extern int sco_disconn_cfm(struct hci_conn *hcon, __u8 reason); 371686ebf28SUlisses Furquim extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb); 372686ebf28SUlisses Furquim 3731da177e4SLinus Torvalds /* ----- Inquiry cache ----- */ 37470f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 37570f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 3761da177e4SLinus Torvalds 37730883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev) 3781da177e4SLinus Torvalds { 379ff9ef578SJohan Hedberg hdev->discovery.state = DISCOVERY_STOPPED; 38030883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.all); 38130883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.unknown); 38230883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.resolve); 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds 38530dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev); 38630dc78e1SJohan Hedberg 387ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state); 388ff9ef578SJohan Hedberg 3891da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev) 3901da177e4SLinus Torvalds { 39130883512SJohan Hedberg return list_empty(&hdev->discovery.all); 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev) 3951da177e4SLinus Torvalds { 39630883512SJohan Hedberg struct discovery_state *c = &hdev->discovery; 3971da177e4SLinus Torvalds return jiffies - c->timestamp; 3981da177e4SLinus Torvalds } 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e) 4011da177e4SLinus Torvalds { 4021da177e4SLinus Torvalds return jiffies - e->timestamp; 4031da177e4SLinus Torvalds } 4041da177e4SLinus Torvalds 4055a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 4065a9d0a3fSWaldemar Rymarkiewicz bdaddr_t *bdaddr); 407561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 408561aafbcSJohan Hedberg bdaddr_t *bdaddr); 40930dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 41030dc78e1SJohan Hedberg bdaddr_t *bdaddr, 41130dc78e1SJohan Hedberg int state); 412a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 413a3d4e20aSJohan Hedberg struct inquiry_entry *ie); 4143175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 415388fc8faSJohan Hedberg bool name_known, bool *ssp); 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvalds /* ----- HCI Connections ----- */ 4181da177e4SLinus Torvalds enum { 4191da177e4SLinus Torvalds HCI_CONN_AUTH_PEND, 42019f8def0SWaldemar Rymarkiewicz HCI_CONN_REAUTH_PEND, 4211da177e4SLinus Torvalds HCI_CONN_ENCRYPT_PEND, 42204837f64SMarcel Holtmann HCI_CONN_RSWITCH_PEND, 42304837f64SMarcel Holtmann HCI_CONN_MODE_CHANGE_PEND, 424e73439d8SMarcel Holtmann HCI_CONN_SCO_SETUP_PEND, 425d26a2345SVinicius Costa Gomes HCI_CONN_LE_SMP_PEND, 426b644ba33SJohan Hedberg HCI_CONN_MGMT_CONNECTED, 42758a681efSJohan Hedberg HCI_CONN_SSP_ENABLED, 42858a681efSJohan Hedberg HCI_CONN_POWER_SAVE, 42958a681efSJohan Hedberg HCI_CONN_REMOTE_OOB, 4301da177e4SLinus Torvalds }; 4311da177e4SLinus Torvalds 432aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 433aa64a8b5SJohan Hedberg { 434aa64a8b5SJohan Hedberg struct hci_dev *hdev = conn->hdev; 4353f17790cSHemant Gupta return (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && 436aa64a8b5SJohan Hedberg test_bit(HCI_CONN_SSP_ENABLED, &conn->flags)); 437aa64a8b5SJohan Hedberg } 438aa64a8b5SJohan Hedberg 4391da177e4SLinus Torvalds static inline void hci_conn_hash_init(struct hci_dev *hdev) 4401da177e4SLinus Torvalds { 4411da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 4421da177e4SLinus Torvalds INIT_LIST_HEAD(&h->list); 4431da177e4SLinus Torvalds h->acl_num = 0; 4441da177e4SLinus Torvalds h->sco_num = 0; 445dc8ed672SGustavo F. Padovan h->le_num = 0; 4461da177e4SLinus Torvalds } 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) 4491da177e4SLinus Torvalds { 4501da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 451bf4c6325SGustavo F. Padovan list_add_rcu(&c->list, &h->list); 452fcd89c09SVille Tervo switch (c->type) { 453fcd89c09SVille Tervo case ACL_LINK: 4541da177e4SLinus Torvalds h->acl_num++; 455fcd89c09SVille Tervo break; 456fcd89c09SVille Tervo case LE_LINK: 457fcd89c09SVille Tervo h->le_num++; 458fcd89c09SVille Tervo break; 459fcd89c09SVille Tervo case SCO_LINK: 460fcd89c09SVille Tervo case ESCO_LINK: 4611da177e4SLinus Torvalds h->sco_num++; 462fcd89c09SVille Tervo break; 463fcd89c09SVille Tervo } 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) 4671da177e4SLinus Torvalds { 4681da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 469bf4c6325SGustavo F. Padovan 470bf4c6325SGustavo F. Padovan list_del_rcu(&c->list); 471bf4c6325SGustavo F. Padovan synchronize_rcu(); 472bf4c6325SGustavo F. Padovan 473fcd89c09SVille Tervo switch (c->type) { 474fcd89c09SVille Tervo case ACL_LINK: 4751da177e4SLinus Torvalds h->acl_num--; 476fcd89c09SVille Tervo break; 477fcd89c09SVille Tervo case LE_LINK: 478fcd89c09SVille Tervo h->le_num--; 479fcd89c09SVille Tervo break; 480fcd89c09SVille Tervo case SCO_LINK: 481fcd89c09SVille Tervo case ESCO_LINK: 4821da177e4SLinus Torvalds h->sco_num--; 483fcd89c09SVille Tervo break; 484fcd89c09SVille Tervo } 4851da177e4SLinus Torvalds } 4861da177e4SLinus Torvalds 48752087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) 48852087a79SLuiz Augusto von Dentz { 48952087a79SLuiz Augusto von Dentz struct hci_conn_hash *h = &hdev->conn_hash; 49052087a79SLuiz Augusto von Dentz switch (type) { 49152087a79SLuiz Augusto von Dentz case ACL_LINK: 49252087a79SLuiz Augusto von Dentz return h->acl_num; 49352087a79SLuiz Augusto von Dentz case LE_LINK: 49452087a79SLuiz Augusto von Dentz return h->le_num; 49552087a79SLuiz Augusto von Dentz case SCO_LINK: 49652087a79SLuiz Augusto von Dentz case ESCO_LINK: 49752087a79SLuiz Augusto von Dentz return h->sco_num; 49852087a79SLuiz Augusto von Dentz default: 49952087a79SLuiz Augusto von Dentz return 0; 50052087a79SLuiz Augusto von Dentz } 50152087a79SLuiz Augusto von Dentz } 50252087a79SLuiz Augusto von Dentz 5031da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 5041da177e4SLinus Torvalds __u16 handle) 5051da177e4SLinus Torvalds { 5061da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 5071da177e4SLinus Torvalds struct hci_conn *c; 5081da177e4SLinus Torvalds 509bf4c6325SGustavo F. Padovan rcu_read_lock(); 510bf4c6325SGustavo F. Padovan 511bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 512bf4c6325SGustavo F. Padovan if (c->handle == handle) { 513bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5141da177e4SLinus Torvalds return c; 5151da177e4SLinus Torvalds } 516bf4c6325SGustavo F. Padovan } 517bf4c6325SGustavo F. Padovan rcu_read_unlock(); 518bf4c6325SGustavo F. Padovan 5191da177e4SLinus Torvalds return NULL; 5201da177e4SLinus Torvalds } 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, 5231da177e4SLinus Torvalds __u8 type, bdaddr_t *ba) 5241da177e4SLinus Torvalds { 5251da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 5261da177e4SLinus Torvalds struct hci_conn *c; 5271da177e4SLinus Torvalds 528bf4c6325SGustavo F. Padovan rcu_read_lock(); 529bf4c6325SGustavo F. Padovan 530bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 531bf4c6325SGustavo F. Padovan if (c->type == type && !bacmp(&c->dst, ba)) { 532bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5331da177e4SLinus Torvalds return c; 5341da177e4SLinus Torvalds } 535bf4c6325SGustavo F. Padovan } 536bf4c6325SGustavo F. Padovan 537bf4c6325SGustavo F. Padovan rcu_read_unlock(); 538bf4c6325SGustavo F. Padovan 5391da177e4SLinus Torvalds return NULL; 5401da177e4SLinus Torvalds } 5411da177e4SLinus Torvalds 5424c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, 5434c67bc74SMarcel Holtmann __u8 type, __u16 state) 5444c67bc74SMarcel Holtmann { 5454c67bc74SMarcel Holtmann struct hci_conn_hash *h = &hdev->conn_hash; 5464c67bc74SMarcel Holtmann struct hci_conn *c; 5474c67bc74SMarcel Holtmann 548bf4c6325SGustavo F. Padovan rcu_read_lock(); 549bf4c6325SGustavo F. Padovan 550bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 551bf4c6325SGustavo F. Padovan if (c->type == type && c->state == state) { 552bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5534c67bc74SMarcel Holtmann return c; 5544c67bc74SMarcel Holtmann } 555bf4c6325SGustavo F. Padovan } 556bf4c6325SGustavo F. Padovan 557bf4c6325SGustavo F. Padovan rcu_read_unlock(); 558bf4c6325SGustavo F. Padovan 5594c67bc74SMarcel Holtmann return NULL; 5604c67bc74SMarcel Holtmann } 5614c67bc74SMarcel Holtmann 5624c67bc74SMarcel Holtmann void hci_acl_connect(struct hci_conn *conn); 5631da177e4SLinus Torvalds void hci_acl_disconn(struct hci_conn *conn, __u8 reason); 5641da177e4SLinus Torvalds void hci_add_sco(struct hci_conn *conn, __u16 handle); 565b6a0dc82SMarcel Holtmann void hci_setup_sync(struct hci_conn *conn, __u16 handle); 566e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status); 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst); 5691da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn); 5701da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev); 571a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev); 5721da177e4SLinus Torvalds 57373d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn); 57473d80debSLuiz Augusto von Dentz int hci_chan_del(struct hci_chan *chan); 5752c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn); 57673d80debSLuiz Augusto von Dentz 5775a9d0a3fSWaldemar Rymarkiewicz struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, 5785a9d0a3fSWaldemar Rymarkiewicz __u8 sec_level, __u8 auth_type); 579e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn); 580b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); 5810684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); 5821da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn); 5838c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role); 5841da177e4SLinus Torvalds 58514b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); 5861da177e4SLinus Torvalds 5879eba32b8SMarcel Holtmann void hci_conn_hold_device(struct hci_conn *conn); 5889eba32b8SMarcel Holtmann void hci_conn_put_device(struct hci_conn *conn); 5899eba32b8SMarcel Holtmann 5901da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn) 5911da177e4SLinus Torvalds { 5921da177e4SLinus Torvalds atomic_inc(&conn->refcnt); 5932f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds static inline void hci_conn_put(struct hci_conn *conn) 5971da177e4SLinus Torvalds { 5981da177e4SLinus Torvalds if (atomic_dec_and_test(&conn->refcnt)) { 59904837f64SMarcel Holtmann unsigned long timeo; 600454d48ffSVinicius Costa Gomes if (conn->type == ACL_LINK || conn->type == LE_LINK) { 6016ac59344SMarcel Holtmann del_timer(&conn->idle_timer); 6026ac59344SMarcel Holtmann if (conn->state == BT_CONNECTED) { 603052b30b0SMarcel Holtmann timeo = msecs_to_jiffies(conn->disc_timeout); 60404837f64SMarcel Holtmann if (!conn->out) 605052b30b0SMarcel Holtmann timeo *= 2; 6065a9d0a3fSWaldemar Rymarkiewicz } else { 6076ac59344SMarcel Holtmann timeo = msecs_to_jiffies(10); 6085a9d0a3fSWaldemar Rymarkiewicz } 6095a9d0a3fSWaldemar Rymarkiewicz } else { 61004837f64SMarcel Holtmann timeo = msecs_to_jiffies(10); 6115a9d0a3fSWaldemar Rymarkiewicz } 6122f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 61319c40e3bSGustavo F. Padovan queue_delayed_work(conn->hdev->workqueue, 6141931782bSVinicius Costa Gomes &conn->disc_work, timeo); 6151da177e4SLinus Torvalds } 6161da177e4SLinus Torvalds } 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds /* ----- HCI Devices ----- */ 619dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d) 6201da177e4SLinus Torvalds { 6214c724c71SDavid Herrmann put_device(&d->dev); 622010666a1SDavid Herrmann } 6231da177e4SLinus Torvalds 624dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) 6251da177e4SLinus Torvalds { 6264c724c71SDavid Herrmann get_device(&d->dev); 6271da177e4SLinus Torvalds return d; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds 63009fd0de5SGustavo F. Padovan #define hci_dev_lock(d) mutex_lock(&d->lock) 63109fd0de5SGustavo F. Padovan #define hci_dev_unlock(d) mutex_unlock(&d->lock) 6321da177e4SLinus Torvalds 633aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev) 6343dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev) 635aa2b86d7SDavid Herrmann 636155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev) 637155961e8SDavid Herrmann { 638155961e8SDavid Herrmann return dev_get_drvdata(&hdev->dev); 639155961e8SDavid Herrmann } 640155961e8SDavid Herrmann 641155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) 642155961e8SDavid Herrmann { 643155961e8SDavid Herrmann dev_set_drvdata(&hdev->dev, data); 644155961e8SDavid Herrmann } 645155961e8SDavid Herrmann 6461da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index); 6471da177e4SLinus Torvalds struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst); 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void); 6501da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev); 6511da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev); 65259735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev); 6531da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev); 6541da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev); 6551da177e4SLinus Torvalds int hci_dev_open(__u16 dev); 6561da177e4SLinus Torvalds int hci_dev_close(__u16 dev); 6571da177e4SLinus Torvalds int hci_dev_reset(__u16 dev); 6581da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev); 6591da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg); 6601da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg); 6611da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg); 6621da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg); 6631da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); 66440be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); 6651da177e4SLinus Torvalds int hci_inquiry(void __user *arg); 6661da177e4SLinus Torvalds 667f0358568SJohan Hedberg struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr); 668f0358568SJohan Hedberg int hci_blacklist_clear(struct hci_dev *hdev); 66988c1fe4bSJohan Hedberg int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 67088c1fe4bSJohan Hedberg int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 671f0358568SJohan Hedberg 6722aeb9a1aSJohan Hedberg int hci_uuids_clear(struct hci_dev *hdev); 6732aeb9a1aSJohan Hedberg 67455ed8ca1SJohan Hedberg int hci_link_keys_clear(struct hci_dev *hdev); 67555ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 676d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 677d25e28abSJohan Hedberg bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len); 678c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]); 679c9839a11SVinicius Costa Gomes int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type, 6809a006657SAndrei Emeltchenko int new_key, u8 authenticated, u8 tk[16], u8 enc_size, 6819a006657SAndrei Emeltchenko __le16 ediv, u8 rand[8]); 682c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 683c9839a11SVinicius Costa Gomes u8 addr_type); 684b899efafSVinicius Costa Gomes int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr); 685b899efafSVinicius Costa Gomes int hci_smp_ltks_clear(struct hci_dev *hdev); 68655ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 68755ed8ca1SJohan Hedberg 6882763eda6SSzymon Janc int hci_remote_oob_data_clear(struct hci_dev *hdev); 6892763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 6902763eda6SSzymon Janc bdaddr_t *bdaddr); 6912763eda6SSzymon Janc int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash, 6922763eda6SSzymon Janc u8 *randomizer); 6932763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); 6942763eda6SSzymon Janc 69535815085SAndre Guedes #define ADV_CLEAR_TIMEOUT (3*60*HZ) /* Three minutes */ 69676c8686fSAndre Guedes int hci_adv_entries_clear(struct hci_dev *hdev); 69776c8686fSAndre Guedes struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr); 69876c8686fSAndre Guedes int hci_add_adv_entry(struct hci_dev *hdev, 69976c8686fSAndre Guedes struct hci_ev_le_advertising_info *ev); 70076c8686fSAndre Guedes 701ab81cbf9SJohan Hedberg void hci_del_off_timer(struct hci_dev *hdev); 702ab81cbf9SJohan Hedberg 7031da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); 7041da177e4SLinus Torvalds 70576bca880SMarcel Holtmann int hci_recv_frame(struct sk_buff *skb); 706ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count); 70799811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count); 708ef222013SMarcel Holtmann 7090ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev); 710ce242970SDavid Herrmann int hci_add_sysfs(struct hci_dev *hdev); 711ce242970SDavid Herrmann void hci_del_sysfs(struct hci_dev *hdev); 712a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn); 713b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn); 714b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn); 7151da177e4SLinus Torvalds 7166935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) 7171da177e4SLinus Torvalds 7181da177e4SLinus Torvalds /* ----- LMP capabilities ----- */ 71904837f64SMarcel Holtmann #define lmp_rswitch_capable(dev) ((dev)->features[0] & LMP_RSWITCH) 72004837f64SMarcel Holtmann #define lmp_encrypt_capable(dev) ((dev)->features[0] & LMP_ENCRYPT) 72104837f64SMarcel Holtmann #define lmp_sniff_capable(dev) ((dev)->features[0] & LMP_SNIFF) 72204837f64SMarcel Holtmann #define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR) 7235b7f9909SMarcel Holtmann #define lmp_esco_capable(dev) ((dev)->features[3] & LMP_ESCO) 724769be974SMarcel Holtmann #define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR) 725e702112fSAndrei Emeltchenko #define lmp_no_flush_capable(dev) ((dev)->features[6] & LMP_NO_FLUSH) 7266ed58ec5SVille Tervo #define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE) 7275e0452c0SAndre Guedes #define lmp_bredr_capable(dev) (!((dev)->features[4] & LMP_NO_BREDR)) 7281da177e4SLinus Torvalds 729eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */ 73059e29406SAndre Guedes #define lmp_host_le_capable(dev) ((dev)->host_features[0] & LMP_HOST_LE) 731eead27daSAndre Guedes 7321da177e4SLinus Torvalds /* ----- HCI protocols ----- */ 7335a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 7345a9d0a3fSWaldemar Rymarkiewicz __u8 type) 7351da177e4SLinus Torvalds { 736686ebf28SUlisses Furquim switch (type) { 737686ebf28SUlisses Furquim case ACL_LINK: 738686ebf28SUlisses Furquim return l2cap_connect_ind(hdev, bdaddr); 7391da177e4SLinus Torvalds 740686ebf28SUlisses Furquim case SCO_LINK: 741686ebf28SUlisses Furquim case ESCO_LINK: 742686ebf28SUlisses Furquim return sco_connect_ind(hdev, bdaddr); 7431da177e4SLinus Torvalds 744686ebf28SUlisses Furquim default: 745686ebf28SUlisses Furquim BT_ERR("unknown link type %d", type); 746686ebf28SUlisses Furquim return -EINVAL; 747686ebf28SUlisses Furquim } 7481da177e4SLinus Torvalds } 7491da177e4SLinus Torvalds 7501da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status) 7511da177e4SLinus Torvalds { 752686ebf28SUlisses Furquim switch (conn->type) { 753686ebf28SUlisses Furquim case ACL_LINK: 754686ebf28SUlisses Furquim case LE_LINK: 755686ebf28SUlisses Furquim l2cap_connect_cfm(conn, status); 756686ebf28SUlisses Furquim break; 7571da177e4SLinus Torvalds 758686ebf28SUlisses Furquim case SCO_LINK: 759686ebf28SUlisses Furquim case ESCO_LINK: 760686ebf28SUlisses Furquim sco_connect_cfm(conn, status); 761686ebf28SUlisses Furquim break; 7621da177e4SLinus Torvalds 763686ebf28SUlisses Furquim default: 764686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 765686ebf28SUlisses Furquim break; 766686ebf28SUlisses Furquim } 767e9a416b5SJohan Hedberg 768e9a416b5SJohan Hedberg if (conn->connect_cfm_cb) 769e9a416b5SJohan Hedberg conn->connect_cfm_cb(conn, status); 7701da177e4SLinus Torvalds } 7711da177e4SLinus Torvalds 7722950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn) 7732950f21aSMarcel Holtmann { 774686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 775686ebf28SUlisses Furquim return HCI_ERROR_REMOTE_USER_TERM; 7762950f21aSMarcel Holtmann 777686ebf28SUlisses Furquim return l2cap_disconn_ind(conn); 7782950f21aSMarcel Holtmann } 7792950f21aSMarcel Holtmann 7802950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason) 7811da177e4SLinus Torvalds { 782686ebf28SUlisses Furquim switch (conn->type) { 783686ebf28SUlisses Furquim case ACL_LINK: 784686ebf28SUlisses Furquim case LE_LINK: 785686ebf28SUlisses Furquim l2cap_disconn_cfm(conn, reason); 786686ebf28SUlisses Furquim break; 7871da177e4SLinus Torvalds 788686ebf28SUlisses Furquim case SCO_LINK: 789686ebf28SUlisses Furquim case ESCO_LINK: 790686ebf28SUlisses Furquim sco_disconn_cfm(conn, reason); 791686ebf28SUlisses Furquim break; 7921da177e4SLinus Torvalds 793686ebf28SUlisses Furquim default: 794686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 795686ebf28SUlisses Furquim break; 796686ebf28SUlisses Furquim } 797e9a416b5SJohan Hedberg 798e9a416b5SJohan Hedberg if (conn->disconn_cfm_cb) 799e9a416b5SJohan Hedberg conn->disconn_cfm_cb(conn, reason); 8001da177e4SLinus Torvalds } 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status) 8031da177e4SLinus Torvalds { 8048c1b2355SMarcel Holtmann __u8 encrypt; 8058c1b2355SMarcel Holtmann 806686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 807686ebf28SUlisses Furquim return; 808686ebf28SUlisses Furquim 80951a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 8108c1b2355SMarcel Holtmann return; 8118c1b2355SMarcel Holtmann 8128c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 813686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 814e9a416b5SJohan Hedberg 815e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 816e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds 8195a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, 8205a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 8211da177e4SLinus Torvalds { 822686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 823686ebf28SUlisses Furquim return; 8241da177e4SLinus Torvalds 825686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 826e9a416b5SJohan Hedberg 827e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 828e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds /* ----- HCI callbacks ----- */ 8321da177e4SLinus Torvalds struct hci_cb { 8331da177e4SLinus Torvalds struct list_head list; 8341da177e4SLinus Torvalds 8351da177e4SLinus Torvalds char *name; 8361da177e4SLinus Torvalds 8375a9d0a3fSWaldemar Rymarkiewicz void (*security_cfm) (struct hci_conn *conn, __u8 status, 8385a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt); 8391da177e4SLinus Torvalds void (*key_change_cfm) (struct hci_conn *conn, __u8 status); 8401da177e4SLinus Torvalds void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); 8411da177e4SLinus Torvalds }; 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) 8441da177e4SLinus Torvalds { 8451da177e4SLinus Torvalds struct list_head *p; 8468c1b2355SMarcel Holtmann __u8 encrypt; 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds hci_proto_auth_cfm(conn, status); 8491da177e4SLinus Torvalds 85051a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 8518c1b2355SMarcel Holtmann return; 8528c1b2355SMarcel Holtmann 8538c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 8548c1b2355SMarcel Holtmann 855f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 8561da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 8571da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 8588c1b2355SMarcel Holtmann if (cb->security_cfm) 8598c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 8601da177e4SLinus Torvalds } 861f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 8621da177e4SLinus Torvalds } 8631da177e4SLinus Torvalds 8645a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, 8655a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 8661da177e4SLinus Torvalds { 8671da177e4SLinus Torvalds struct list_head *p; 8681da177e4SLinus Torvalds 869435fef20SMarcel Holtmann if (conn->sec_level == BT_SECURITY_SDP) 870435fef20SMarcel Holtmann conn->sec_level = BT_SECURITY_LOW; 871435fef20SMarcel Holtmann 87288167aedSVinicius Costa Gomes if (conn->pending_sec_level > conn->sec_level) 87388167aedSVinicius Costa Gomes conn->sec_level = conn->pending_sec_level; 87488167aedSVinicius Costa Gomes 8759719f8afSMarcel Holtmann hci_proto_encrypt_cfm(conn, status, encrypt); 8761da177e4SLinus Torvalds 877f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 8781da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 8791da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 8808c1b2355SMarcel Holtmann if (cb->security_cfm) 8818c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 8821da177e4SLinus Torvalds } 883f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 8841da177e4SLinus Torvalds } 8851da177e4SLinus Torvalds 8861da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) 8871da177e4SLinus Torvalds { 8881da177e4SLinus Torvalds struct list_head *p; 8891da177e4SLinus Torvalds 890f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 8911da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 8921da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 8931da177e4SLinus Torvalds if (cb->key_change_cfm) 8941da177e4SLinus Torvalds cb->key_change_cfm(conn, status); 8951da177e4SLinus Torvalds } 896f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 8995a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, 9005a9d0a3fSWaldemar Rymarkiewicz __u8 role) 9011da177e4SLinus Torvalds { 9021da177e4SLinus Torvalds struct list_head *p; 9031da177e4SLinus Torvalds 904f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 9051da177e4SLinus Torvalds list_for_each(p, &hci_cb_list) { 9061da177e4SLinus Torvalds struct hci_cb *cb = list_entry(p, struct hci_cb, list); 9071da177e4SLinus Torvalds if (cb->role_switch_cfm) 9081da177e4SLinus Torvalds cb->role_switch_cfm(conn, status, role); 9091da177e4SLinus Torvalds } 910f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 9111da177e4SLinus Torvalds } 9121da177e4SLinus Torvalds 9136759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) 9146759a675SJohan Hedberg { 91584d9d071SJohan Hedberg size_t parsed = 0; 9166759a675SJohan Hedberg 9176c0c331eSJohan Hedberg if (data_len < 2) 9186c0c331eSJohan Hedberg return false; 9196c0c331eSJohan Hedberg 92084d9d071SJohan Hedberg while (parsed < data_len - 1) { 92184d9d071SJohan Hedberg u8 field_len = data[0]; 9226759a675SJohan Hedberg 9236759a675SJohan Hedberg if (field_len == 0) 9246759a675SJohan Hedberg break; 9256759a675SJohan Hedberg 9266759a675SJohan Hedberg parsed += field_len + 1; 9276759a675SJohan Hedberg 9286759a675SJohan Hedberg if (parsed > data_len) 9296759a675SJohan Hedberg break; 9306759a675SJohan Hedberg 9316759a675SJohan Hedberg if (data[1] == type) 9326759a675SJohan Hedberg return true; 9336759a675SJohan Hedberg 9346759a675SJohan Hedberg data += field_len + 1; 9356759a675SJohan Hedberg } 9366759a675SJohan Hedberg 9376759a675SJohan Hedberg return false; 9386759a675SJohan Hedberg } 9396759a675SJohan Hedberg 9401dc06093SJohan Hedberg static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data, 9411dc06093SJohan Hedberg u8 data_len) 9421dc06093SJohan Hedberg { 9431dc06093SJohan Hedberg eir[eir_len++] = sizeof(type) + data_len; 9441dc06093SJohan Hedberg eir[eir_len++] = type; 9451dc06093SJohan Hedberg memcpy(&eir[eir_len], data, data_len); 9461dc06093SJohan Hedberg eir_len += data_len; 9471dc06093SJohan Hedberg 9481dc06093SJohan Hedberg return eir_len; 9491dc06093SJohan Hedberg } 9501dc06093SJohan Hedberg 9511da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb); 9521da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb); 9531da177e4SLinus Torvalds 954a9de9248SMarcel Holtmann int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param); 95573d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 9560d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 9571da177e4SLinus Torvalds 958a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); 9591da177e4SLinus Torvalds 9601da177e4SLinus Torvalds /* ----- HCI Sockets ----- */ 961470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); 962470fe1b5SMarcel Holtmann void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk); 963cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); 9641da177e4SLinus Torvalds 965040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event); 966040030efSMarcel Holtmann 9670381101fSJohan Hedberg /* Management interface */ 968f39799f5SAndre Guedes #define MGMT_ADDR_BREDR 0x00 969f39799f5SAndre Guedes #define MGMT_ADDR_LE_PUBLIC 0x01 970f39799f5SAndre Guedes #define MGMT_ADDR_LE_RANDOM 0x02 971f39799f5SAndre Guedes #define MGMT_ADDR_INVALID 0xff 972f39799f5SAndre Guedes 973f39799f5SAndre Guedes #define DISCOV_TYPE_BREDR (BIT(MGMT_ADDR_BREDR)) 974f39799f5SAndre Guedes #define DISCOV_TYPE_LE (BIT(MGMT_ADDR_LE_PUBLIC) | \ 975f39799f5SAndre Guedes BIT(MGMT_ADDR_LE_RANDOM)) 976f39799f5SAndre Guedes #define DISCOV_TYPE_INTERLEAVED (BIT(MGMT_ADDR_BREDR) | \ 977f39799f5SAndre Guedes BIT(MGMT_ADDR_LE_PUBLIC) | \ 978f39799f5SAndre Guedes BIT(MGMT_ADDR_LE_RANDOM)) 979f39799f5SAndre Guedes 9800381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); 981744cf19eSJohan Hedberg int mgmt_index_added(struct hci_dev *hdev); 982744cf19eSJohan Hedberg int mgmt_index_removed(struct hci_dev *hdev); 983744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered); 984744cf19eSJohan Hedberg int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); 985744cf19eSJohan Hedberg int mgmt_connectable(struct hci_dev *hdev, u8 connectable); 986744cf19eSJohan Hedberg int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 987744cf19eSJohan Hedberg int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 988745c0ce3SVishal Agarwal bool persistent); 989afc747a6SJohan Hedberg int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 99004124681SGustavo F. Padovan u8 addr_type, u32 flags, u8 *name, u8 name_len, 99104124681SGustavo F. Padovan u8 *dev_class); 992afc747a6SJohan Hedberg int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 993afc747a6SJohan Hedberg u8 link_type, u8 addr_type); 99488c3df13SJohan Hedberg int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 99588c3df13SJohan Hedberg u8 link_type, u8 addr_type, u8 status); 99648264f06SJohan Hedberg int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 99748264f06SJohan Hedberg u8 addr_type, u8 status); 998744cf19eSJohan Hedberg int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 999744cf19eSJohan Hedberg int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1000c35938b2SSzymon Janc u8 status); 1001744cf19eSJohan Hedberg int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1002744cf19eSJohan Hedberg u8 status); 1003744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1004272d90dfSJohan Hedberg u8 link_type, u8 addr_type, __le32 value, 1005272d90dfSJohan Hedberg u8 confirm_hint); 1006744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1007272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1008272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1009272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1010272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1011272d90dfSJohan Hedberg u8 link_type, u8 addr_type); 1012604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1013272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1014272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1015272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1016bab73cb6SJohan Hedberg int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1017bab73cb6SJohan Hedberg u8 addr_type, u8 status); 101833ef95edSJohan Hedberg int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); 1019c0ecddc2SJohan Hedberg int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 10207f9a903cSMarcel Holtmann int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 10217f9a903cSMarcel Holtmann u8 status); 1022744cf19eSJohan Hedberg int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1023744cf19eSJohan Hedberg int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 1024744cf19eSJohan Hedberg u8 *randomizer, u8 status); 102506199cf8SJohan Hedberg int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 102648264f06SJohan Hedberg int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 102704124681SGustavo F. Padovan u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, 102804124681SGustavo F. Padovan u8 ssp, u8 *eir, u16 eir_len); 1029b644ba33SJohan Hedberg int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1030b644ba33SJohan Hedberg u8 addr_type, s8 rssi, u8 *name, u8 name_len); 10317a135109SAndre Guedes int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status); 1032e6d465cbSAndre Guedes int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status); 1033744cf19eSJohan Hedberg int mgmt_discovering(struct hci_dev *hdev, u8 discovering); 10345e0452c0SAndre Guedes int mgmt_interleaved_discovery(struct hci_dev *hdev); 103588c1fe4bSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 103688c1fe4bSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 10370381101fSJohan Hedberg 1038346af67bSVinicius Costa Gomes int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent); 1039346af67bSVinicius Costa Gomes 10401da177e4SLinus Torvalds /* HCI info for socket */ 10411da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk) 10421da177e4SLinus Torvalds 10431da177e4SLinus Torvalds struct hci_pinfo { 10441da177e4SLinus Torvalds struct bt_sock bt; 10451da177e4SLinus Torvalds struct hci_dev *hdev; 10461da177e4SLinus Torvalds struct hci_filter filter; 10471da177e4SLinus Torvalds __u32 cmsg_mask; 1048c02178d2SJohan Hedberg unsigned short channel; 10491da177e4SLinus Torvalds }; 10501da177e4SLinus Torvalds 10511da177e4SLinus Torvalds /* HCI security filter */ 10521da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF 5 10531da177e4SLinus Torvalds 10541da177e4SLinus Torvalds struct hci_sec_filter { 10551da177e4SLinus Torvalds __u32 type_mask; 10561da177e4SLinus Torvalds __u32 event_mask[2]; 10571da177e4SLinus Torvalds __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4]; 10581da177e4SLinus Torvalds }; 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvalds /* ----- HCI requests ----- */ 10611da177e4SLinus Torvalds #define HCI_REQ_DONE 0 10621da177e4SLinus Torvalds #define HCI_REQ_PEND 1 10631da177e4SLinus Torvalds #define HCI_REQ_CANCELED 2 10641da177e4SLinus Torvalds 1065a6a67efdSThomas Gleixner #define hci_req_lock(d) mutex_lock(&d->req_lock) 1066a6a67efdSThomas Gleixner #define hci_req_unlock(d) mutex_unlock(&d->req_lock) 10671da177e4SLinus Torvalds 106823bb5763SJohan Hedberg void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result); 10691da177e4SLinus Torvalds 10702ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, 10712ce603ebSClaudio Takahasi u16 latency, u16 to_multiplier); 1072a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8], 1073a7a595f6SVinicius Costa Gomes __u8 ltk[16]); 1074a7a595f6SVinicius Costa Gomes void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16]); 1075a7a595f6SVinicius Costa Gomes void hci_le_ltk_neg_reply(struct hci_conn *conn); 1076a7a595f6SVinicius Costa Gomes 10772519a1fcSAndre Guedes int hci_do_inquiry(struct hci_dev *hdev, u8 length); 1078023d5049SAndre Guedes int hci_cancel_inquiry(struct hci_dev *hdev); 107928b75a89SAndre Guedes int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window, 108028b75a89SAndre Guedes int timeout); 10812519a1fcSAndre Guedes 10821da177e4SLinus Torvalds #endif /* __HCI_CORE_H */ 1083