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; 76bd1eb66bSAndrei Emeltchenko unsigned int amp_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; 84b9ee0a78SMarcel Holtmann u8 bdaddr_type; 85f0358568SJohan Hedberg }; 862aeb9a1aSJohan Hedberg 872aeb9a1aSJohan Hedberg struct bt_uuid { 882aeb9a1aSJohan Hedberg struct list_head list; 892aeb9a1aSJohan Hedberg u8 uuid[16]; 9083be8ecaSJohan Hedberg u8 size; 911aff6f09SJohan Hedberg u8 svc_hint; 922aeb9a1aSJohan Hedberg }; 932aeb9a1aSJohan Hedberg 94b899efafSVinicius Costa Gomes struct smp_ltk { 95b899efafSVinicius Costa Gomes struct list_head list; 96b899efafSVinicius Costa Gomes bdaddr_t bdaddr; 97b899efafSVinicius Costa Gomes u8 bdaddr_type; 98b899efafSVinicius Costa Gomes u8 authenticated; 99b899efafSVinicius Costa Gomes u8 type; 100b899efafSVinicius Costa Gomes u8 enc_size; 101b899efafSVinicius Costa Gomes __le16 ediv; 102b899efafSVinicius Costa Gomes u8 rand[8]; 103b899efafSVinicius Costa Gomes u8 val[16]; 10403c515d7SMarcel Holtmann }; 105b899efafSVinicius Costa Gomes 106970c4e46SJohan Hedberg struct smp_irk { 107970c4e46SJohan Hedberg struct list_head list; 108970c4e46SJohan Hedberg bdaddr_t rpa; 109970c4e46SJohan Hedberg bdaddr_t bdaddr; 110970c4e46SJohan Hedberg u8 addr_type; 111970c4e46SJohan Hedberg u8 val[16]; 112970c4e46SJohan Hedberg }; 113970c4e46SJohan Hedberg 11455ed8ca1SJohan Hedberg struct link_key { 11555ed8ca1SJohan Hedberg struct list_head list; 11655ed8ca1SJohan Hedberg bdaddr_t bdaddr; 11755ed8ca1SJohan Hedberg u8 type; 1189b3b4460SAndrei Emeltchenko u8 val[HCI_LINK_KEY_SIZE]; 11955ed8ca1SJohan Hedberg u8 pin_len; 12055ed8ca1SJohan Hedberg }; 12155ed8ca1SJohan Hedberg 1222763eda6SSzymon Janc struct oob_data { 1232763eda6SSzymon Janc struct list_head list; 1242763eda6SSzymon Janc bdaddr_t bdaddr; 125519ca9d0SMarcel Holtmann u8 hash192[16]; 126519ca9d0SMarcel Holtmann u8 randomizer192[16]; 127519ca9d0SMarcel Holtmann u8 hash256[16]; 128519ca9d0SMarcel Holtmann u8 randomizer256[16]; 1292763eda6SSzymon Janc }; 1302763eda6SSzymon Janc 131490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH 10 132490c5babSJohan Hedberg 133d6bfd59cSJohan Hedberg /* Default LE RPA expiry time, 15 minutes */ 134d6bfd59cSJohan Hedberg #define HCI_DEFAULT_RPA_TIMEOUT (15 * 60) 135d6bfd59cSJohan Hedberg 136903e4541SAndrei Emeltchenko struct amp_assoc { 137903e4541SAndrei Emeltchenko __u16 len; 138903e4541SAndrei Emeltchenko __u16 offset; 13993c284eeSAndrei Emeltchenko __u16 rem_len; 14093c284eeSAndrei Emeltchenko __u16 len_so_far; 141903e4541SAndrei Emeltchenko __u8 data[HCI_MAX_AMP_ASSOC_SIZE]; 142903e4541SAndrei Emeltchenko }; 143903e4541SAndrei Emeltchenko 144d2c5d77fSJohan Hedberg #define HCI_MAX_PAGES 3 145cad718edSJohan Hedberg 146cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4 1471da177e4SLinus Torvalds struct hci_dev { 1481da177e4SLinus Torvalds struct list_head list; 14909fd0de5SGustavo F. Padovan struct mutex lock; 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds char name[8]; 1521da177e4SLinus Torvalds unsigned long flags; 1531da177e4SLinus Torvalds __u16 id; 154c13854ceSMarcel Holtmann __u8 bus; 155943da25dSMarcel Holtmann __u8 dev_type; 1561da177e4SLinus Torvalds bdaddr_t bdaddr; 1577a4cd51dSMarcel Holtmann bdaddr_t random_addr; 158d13eafceSMarcel Holtmann bdaddr_t static_addr; 15956ed2cb8SJohan Hedberg __u8 adv_addr_type; 1601f6c6378SJohan Hedberg __u8 dev_name[HCI_MAX_NAME_LENGTH]; 161490c5babSJohan Hedberg __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; 16280a1e1dbSJohan Hedberg __u8 eir[HCI_MAX_EIR_LENGTH]; 163a9de9248SMarcel Holtmann __u8 dev_class[3]; 1641aff6f09SJohan Hedberg __u8 major_class; 1651aff6f09SJohan Hedberg __u8 minor_class; 166d2c5d77fSJohan Hedberg __u8 max_page; 167cad718edSJohan Hedberg __u8 features[HCI_MAX_PAGES][8]; 16860e77321SJohan Hedberg __u8 le_features[8]; 169cf1d081fSJohan Hedberg __u8 le_white_list_size; 1709b008c04SJohan Hedberg __u8 le_states[8]; 171a9de9248SMarcel Holtmann __u8 commands[64]; 1721143e5a6SMarcel Holtmann __u8 hci_ver; 1731143e5a6SMarcel Holtmann __u16 hci_rev; 174d5859e22SJohan Hedberg __u8 lmp_ver; 1751143e5a6SMarcel Holtmann __u16 manufacturer; 1767d69230cSAndrei Emeltchenko __u16 lmp_subver; 1771da177e4SLinus Torvalds __u16 voice_setting; 178b4cb9fb2SMarcel Holtmann __u8 num_iac; 17917fa4b9dSJohan Hedberg __u8 io_capability; 18091c4e9b1SMarcel Holtmann __s8 inq_tx_power; 181f332ec66SJohan Hedberg __u16 page_scan_interval; 182f332ec66SJohan Hedberg __u16 page_scan_window; 183f332ec66SJohan Hedberg __u8 page_scan_type; 1843f959d46SMarcel Holtmann __u8 le_adv_channel_map; 185bef64738SMarcel Holtmann __u16 le_scan_interval; 186bef64738SMarcel Holtmann __u16 le_scan_window; 1874e70c7e7SMarcel Holtmann __u16 le_conn_min_interval; 1884e70c7e7SMarcel Holtmann __u16 le_conn_max_interval; 18906f5b778SMarcel Holtmann __u8 ssp_debug_mode; 190f332ec66SJohan Hedberg 1912b9be137SMarcel Holtmann __u16 devid_source; 1922b9be137SMarcel Holtmann __u16 devid_vendor; 1932b9be137SMarcel Holtmann __u16 devid_product; 1942b9be137SMarcel Holtmann __u16 devid_version; 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds __u16 pkt_type; 1975b7f9909SMarcel Holtmann __u16 esco_type; 1981da177e4SLinus Torvalds __u16 link_policy; 1991da177e4SLinus Torvalds __u16 link_mode; 2001da177e4SLinus Torvalds 20104837f64SMarcel Holtmann __u32 idle_timeout; 20204837f64SMarcel Holtmann __u16 sniff_min_interval; 20304837f64SMarcel Holtmann __u16 sniff_max_interval; 20404837f64SMarcel Holtmann 205928abaa7SAndrei Emeltchenko __u8 amp_status; 206928abaa7SAndrei Emeltchenko __u32 amp_total_bw; 207928abaa7SAndrei Emeltchenko __u32 amp_max_bw; 208928abaa7SAndrei Emeltchenko __u32 amp_min_latency; 209928abaa7SAndrei Emeltchenko __u32 amp_max_pdu; 210928abaa7SAndrei Emeltchenko __u8 amp_type; 211928abaa7SAndrei Emeltchenko __u16 amp_pal_cap; 212928abaa7SAndrei Emeltchenko __u16 amp_assoc_size; 213928abaa7SAndrei Emeltchenko __u32 amp_max_flush_to; 214928abaa7SAndrei Emeltchenko __u32 amp_be_flush_to; 215928abaa7SAndrei Emeltchenko 216903e4541SAndrei Emeltchenko struct amp_assoc loc_assoc; 217903e4541SAndrei Emeltchenko 2181e89cffbSAndrei Emeltchenko __u8 flow_ctl_mode; 2191e89cffbSAndrei Emeltchenko 2209f61656aSJohan Hedberg unsigned int auto_accept_delay; 2219f61656aSJohan Hedberg 2221da177e4SLinus Torvalds unsigned long quirks; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds atomic_t cmd_cnt; 2251da177e4SLinus Torvalds unsigned int acl_cnt; 2261da177e4SLinus Torvalds unsigned int sco_cnt; 2276ed58ec5SVille Tervo unsigned int le_cnt; 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds unsigned int acl_mtu; 2301da177e4SLinus Torvalds unsigned int sco_mtu; 2316ed58ec5SVille Tervo unsigned int le_mtu; 2321da177e4SLinus Torvalds unsigned int acl_pkts; 2331da177e4SLinus Torvalds unsigned int sco_pkts; 2346ed58ec5SVille Tervo unsigned int le_pkts; 2351da177e4SLinus Torvalds 236350ee4cfSAndrei Emeltchenko __u16 block_len; 237350ee4cfSAndrei Emeltchenko __u16 block_mtu; 238350ee4cfSAndrei Emeltchenko __u16 num_blocks; 239350ee4cfSAndrei Emeltchenko __u16 block_cnt; 240350ee4cfSAndrei Emeltchenko 2411da177e4SLinus Torvalds unsigned long acl_last_tx; 2421da177e4SLinus Torvalds unsigned long sco_last_tx; 2436ed58ec5SVille Tervo unsigned long le_last_tx; 2441da177e4SLinus Torvalds 245f48fd9c8SMarcel Holtmann struct workqueue_struct *workqueue; 2466ead1bbcSJohan Hedberg struct workqueue_struct *req_workqueue; 247f48fd9c8SMarcel Holtmann 248ab81cbf9SJohan Hedberg struct work_struct power_on; 2493243553fSJohan Hedberg struct delayed_work power_off; 250ab81cbf9SJohan Hedberg 25116ab91abSJohan Hedberg __u16 discov_timeout; 25216ab91abSJohan Hedberg struct delayed_work discov_off; 25316ab91abSJohan Hedberg 2547d78525dSJohan Hedberg struct delayed_work service_cache; 2557d78525dSJohan Hedberg 2566bd32326SVille Tervo struct timer_list cmd_timer; 257b78752ccSMarcel Holtmann 258b78752ccSMarcel Holtmann struct work_struct rx_work; 259c347b765SGustavo F. Padovan struct work_struct cmd_work; 2603eff45eaSGustavo F. Padovan struct work_struct tx_work; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds struct sk_buff_head rx_q; 2631da177e4SLinus Torvalds struct sk_buff_head raw_q; 2641da177e4SLinus Torvalds struct sk_buff_head cmd_q; 2651da177e4SLinus Torvalds 266b6ddb638SJohan Hedberg struct sk_buff *recv_evt; 2671da177e4SLinus Torvalds struct sk_buff *sent_cmd; 268cd4c5391SSuraj Sumangala struct sk_buff *reassembly[NUM_REASSEMBLY]; 2691da177e4SLinus Torvalds 270a6a67efdSThomas Gleixner struct mutex req_lock; 2711da177e4SLinus Torvalds wait_queue_head_t req_wait_q; 2721da177e4SLinus Torvalds __u32 req_status; 2731da177e4SLinus Torvalds __u32 req_result; 274a5040efaSJohan Hedberg 27599780a7bSJohan Hedberg struct crypto_blkcipher *tfm_aes; 2762e58ef3eSJohan Hedberg 27730883512SJohan Hedberg struct discovery_state discovery; 2781da177e4SLinus Torvalds struct hci_conn_hash conn_hash; 2795c136e90SAndre Guedes 2805c136e90SAndre Guedes struct list_head mgmt_pending; 281ea4bd8baSDavid Miller struct list_head blacklist; 2822aeb9a1aSJohan Hedberg struct list_head uuids; 28355ed8ca1SJohan Hedberg struct list_head link_keys; 284b899efafSVinicius Costa Gomes struct list_head long_term_keys; 285970c4e46SJohan Hedberg struct list_head identity_resolving_keys; 2862763eda6SSzymon Janc struct list_head remote_oob_data; 287d2ab0ac1SMarcel Holtmann struct list_head le_white_list; 28815819a70SAndre Guedes struct list_head le_conn_params; 28977a77a30SAndre Guedes struct list_head pend_le_conns; 2902763eda6SSzymon Janc 2911da177e4SLinus Torvalds struct hci_dev_stats stat; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds atomic_t promisc; 2941da177e4SLinus Torvalds 295ca325f69SMarcel Holtmann struct dentry *debugfs; 296ca325f69SMarcel Holtmann 297a91f2e39SMarcel Holtmann struct device dev; 2981da177e4SLinus Torvalds 299611b30f7SMarcel Holtmann struct rfkill *rfkill; 300611b30f7SMarcel Holtmann 301d23264a8SAndre Guedes unsigned long dev_flags; 302d23264a8SAndre Guedes 3037ba8b4beSAndre Guedes struct delayed_work le_scan_disable; 3047ba8b4beSAndre Guedes 3058fa19098SJohan Hedberg __s8 adv_tx_power; 3063f0f524bSJohan Hedberg __u8 adv_data[HCI_MAX_AD_LENGTH]; 3073f0f524bSJohan Hedberg __u8 adv_data_len; 308f8e808bdSMarcel Holtmann __u8 scan_rsp_data[HCI_MAX_AD_LENGTH]; 309f8e808bdSMarcel Holtmann __u8 scan_rsp_data_len; 3108fa19098SJohan Hedberg 311863efaf2SJohan Hedberg __u8 irk[16]; 312d6bfd59cSJohan Hedberg __u32 rpa_timeout; 313d6bfd59cSJohan Hedberg struct delayed_work rpa_expired; 3142b5224dcSMarcel Holtmann bdaddr_t rpa; 315863efaf2SJohan Hedberg 3161da177e4SLinus Torvalds int (*open)(struct hci_dev *hdev); 3171da177e4SLinus Torvalds int (*close)(struct hci_dev *hdev); 3181da177e4SLinus Torvalds int (*flush)(struct hci_dev *hdev); 319f41c70c4SMarcel Holtmann int (*setup)(struct hci_dev *hdev); 3207bd8f09fSMarcel Holtmann int (*send)(struct hci_dev *hdev, struct sk_buff *skb); 3211da177e4SLinus Torvalds void (*notify)(struct hci_dev *hdev, unsigned int evt); 3221da177e4SLinus Torvalds }; 3231da177e4SLinus Torvalds 32453502d69SAndrei Emeltchenko #define HCI_PHY_HANDLE(handle) (handle & 0xff) 32553502d69SAndrei Emeltchenko 3261da177e4SLinus Torvalds struct hci_conn { 3271da177e4SLinus Torvalds struct list_head list; 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds atomic_t refcnt; 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds bdaddr_t dst; 33229b7988aSAndre Guedes __u8 dst_type; 333662e8820SMarcel Holtmann bdaddr_t src; 334e7c4096eSMarcel Holtmann __u8 src_type; 3351da177e4SLinus Torvalds __u16 handle; 3361da177e4SLinus Torvalds __u16 state; 33704837f64SMarcel Holtmann __u8 mode; 3381da177e4SLinus Torvalds __u8 type; 339a0c808b3SJohan Hedberg bool out; 3404c67bc74SMarcel Holtmann __u8 attempt; 3411da177e4SLinus Torvalds __u8 dev_class[3]; 342cad718edSJohan Hedberg __u8 features[HCI_MAX_PAGES][8]; 343a8746417SMarcel Holtmann __u16 pkt_type; 34404837f64SMarcel Holtmann __u16 link_policy; 3451da177e4SLinus Torvalds __u32 link_mode; 34613d39315SWaldemar Rymarkiewicz __u8 key_type; 34740be492fSMarcel Holtmann __u8 auth_type; 3488c1b2355SMarcel Holtmann __u8 sec_level; 349765c2a96SJohan Hedberg __u8 pending_sec_level; 350980e1a53SJohan Hedberg __u8 pin_length; 351726b4ffcSVinicius Costa Gomes __u8 enc_key_size; 35217fa4b9dSJohan Hedberg __u8 io_capability; 35392a25256SJohan Hedberg __u32 passkey_notify; 35492a25256SJohan Hedberg __u8 passkey_entered; 355052b30b0SMarcel Holtmann __u16 disc_timeout; 35610c62ddcSFrédéric Dalleau __u16 setting; 3571e406eefSAndre Guedes __u16 le_conn_min_interval; 3581e406eefSAndre Guedes __u16 le_conn_max_interval; 35951a8efd7SJohan Hedberg unsigned long flags; 3601da177e4SLinus Torvalds 36103b555e1SJohan Hedberg __u8 remote_cap; 36203b555e1SJohan Hedberg __u8 remote_auth; 3633161ae1cSAndrei Emeltchenko __u8 remote_id; 3646ec5bcadSVishal Agarwal bool flush_key; 36503b555e1SJohan Hedberg 3661da177e4SLinus Torvalds unsigned int sent; 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds struct sk_buff_head data_q; 3692c33c06aSGustavo F. Padovan struct list_head chan_list; 3701da177e4SLinus Torvalds 37119c40e3bSGustavo F. Padovan struct delayed_work disc_work; 3727bc18d9dSJohan Hedberg struct delayed_work auto_accept_work; 373a74a84f6SJohan Hedberg struct delayed_work idle_work; 3741da177e4SLinus Torvalds 375b219e3acSMarcel Holtmann struct device dev; 376b219e3acSMarcel Holtmann 3771da177e4SLinus Torvalds struct hci_dev *hdev; 3781da177e4SLinus Torvalds void *l2cap_data; 3791da177e4SLinus Torvalds void *sco_data; 3802b64d153SBrian Gix void *smp_conn; 3819740e49dSAndrei Emeltchenko struct amp_mgr *amp_mgr; 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds struct hci_conn *link; 384e9a416b5SJohan Hedberg 385e9a416b5SJohan Hedberg void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); 386e9a416b5SJohan Hedberg void (*security_cfm_cb) (struct hci_conn *conn, u8 status); 387e9a416b5SJohan Hedberg void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason); 3881da177e4SLinus Torvalds }; 3891da177e4SLinus Torvalds 39073d80debSLuiz Augusto von Dentz struct hci_chan { 39173d80debSLuiz Augusto von Dentz struct list_head list; 39242c4e53eSAndrei Emeltchenko __u16 handle; 39373d80debSLuiz Augusto von Dentz struct hci_conn *conn; 39473d80debSLuiz Augusto von Dentz struct sk_buff_head data_q; 39573d80debSLuiz Augusto von Dentz unsigned int sent; 396168df8e5SMat Martineau __u8 state; 39773d80debSLuiz Augusto von Dentz }; 39873d80debSLuiz Augusto von Dentz 39915819a70SAndre Guedes struct hci_conn_params { 40015819a70SAndre Guedes struct list_head list; 40115819a70SAndre Guedes 40215819a70SAndre Guedes bdaddr_t addr; 40315819a70SAndre Guedes u8 addr_type; 40415819a70SAndre Guedes 40515819a70SAndre Guedes u16 conn_min_interval; 40615819a70SAndre Guedes u16 conn_max_interval; 4079fcb18efSAndre Guedes 4089fcb18efSAndre Guedes enum { 4099fcb18efSAndre Guedes HCI_AUTO_CONN_DISABLED, 4109fcb18efSAndre Guedes HCI_AUTO_CONN_ALWAYS, 4119fcb18efSAndre Guedes HCI_AUTO_CONN_LINK_LOSS, 4129fcb18efSAndre Guedes } auto_connect; 41315819a70SAndre Guedes }; 41415819a70SAndre Guedes 4151da177e4SLinus Torvalds extern struct list_head hci_dev_list; 4161da177e4SLinus Torvalds extern struct list_head hci_cb_list; 4171da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock; 4181da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock; 4191da177e4SLinus Torvalds 420686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */ 421e74e58f8SJoe Perches int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 422e74e58f8SJoe Perches void l2cap_connect_cfm(struct hci_conn *hcon, u8 status); 423e74e58f8SJoe Perches int l2cap_disconn_ind(struct hci_conn *hcon); 424e74e58f8SJoe Perches void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); 425e74e58f8SJoe Perches int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt); 426e74e58f8SJoe Perches int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); 427686ebf28SUlisses Furquim 428e74e58f8SJoe Perches int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); 429e74e58f8SJoe Perches void sco_connect_cfm(struct hci_conn *hcon, __u8 status); 430e74e58f8SJoe Perches void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason); 431e74e58f8SJoe Perches int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb); 432686ebf28SUlisses Furquim 4331da177e4SLinus Torvalds /* ----- Inquiry cache ----- */ 43470f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 43570f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 4361da177e4SLinus Torvalds 43730883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev) 4381da177e4SLinus Torvalds { 439ff9ef578SJohan Hedberg hdev->discovery.state = DISCOVERY_STOPPED; 44030883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.all); 44130883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.unknown); 44230883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.resolve); 4431da177e4SLinus Torvalds } 4441da177e4SLinus Torvalds 44530dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev); 44630dc78e1SJohan Hedberg 447ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state); 448ff9ef578SJohan Hedberg 4491da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev) 4501da177e4SLinus Torvalds { 45130883512SJohan Hedberg return list_empty(&hdev->discovery.all); 4521da177e4SLinus Torvalds } 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev) 4551da177e4SLinus Torvalds { 45630883512SJohan Hedberg struct discovery_state *c = &hdev->discovery; 4571da177e4SLinus Torvalds return jiffies - c->timestamp; 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e) 4611da177e4SLinus Torvalds { 4621da177e4SLinus Torvalds return jiffies - e->timestamp; 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 4655a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 4665a9d0a3fSWaldemar Rymarkiewicz bdaddr_t *bdaddr); 467561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 468561aafbcSJohan Hedberg bdaddr_t *bdaddr); 46930dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 47030dc78e1SJohan Hedberg bdaddr_t *bdaddr, 47130dc78e1SJohan Hedberg int state); 472a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 473a3d4e20aSJohan Hedberg struct inquiry_entry *ie); 4743175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 475388fc8faSJohan Hedberg bool name_known, bool *ssp); 4761f9b9a5dSAndre Guedes void hci_inquiry_cache_flush(struct hci_dev *hdev); 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds /* ----- HCI Connections ----- */ 4791da177e4SLinus Torvalds enum { 4801da177e4SLinus Torvalds HCI_CONN_AUTH_PEND, 48119f8def0SWaldemar Rymarkiewicz HCI_CONN_REAUTH_PEND, 4821da177e4SLinus Torvalds HCI_CONN_ENCRYPT_PEND, 48304837f64SMarcel Holtmann HCI_CONN_RSWITCH_PEND, 48404837f64SMarcel Holtmann HCI_CONN_MODE_CHANGE_PEND, 485e73439d8SMarcel Holtmann HCI_CONN_SCO_SETUP_PEND, 486d26a2345SVinicius Costa Gomes HCI_CONN_LE_SMP_PEND, 487b644ba33SJohan Hedberg HCI_CONN_MGMT_CONNECTED, 48858a681efSJohan Hedberg HCI_CONN_SSP_ENABLED, 489eb9a8f3fSMarcel Holtmann HCI_CONN_SC_ENABLED, 490abf76badSMarcel Holtmann HCI_CONN_AES_CCM, 49158a681efSJohan Hedberg HCI_CONN_POWER_SAVE, 49258a681efSJohan Hedberg HCI_CONN_REMOTE_OOB, 49318722c24SJukka Rissanen HCI_CONN_6LOWPAN, 4941da177e4SLinus Torvalds }; 4951da177e4SLinus Torvalds 496aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 497aa64a8b5SJohan Hedberg { 498aa64a8b5SJohan Hedberg struct hci_dev *hdev = conn->hdev; 499c3c7ea65SGustavo Padovan return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && 500c3c7ea65SGustavo Padovan test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); 501aa64a8b5SJohan Hedberg } 502aa64a8b5SJohan Hedberg 503eb9a8f3fSMarcel Holtmann static inline bool hci_conn_sc_enabled(struct hci_conn *conn) 504eb9a8f3fSMarcel Holtmann { 505eb9a8f3fSMarcel Holtmann struct hci_dev *hdev = conn->hdev; 506eb9a8f3fSMarcel Holtmann return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && 507eb9a8f3fSMarcel Holtmann test_bit(HCI_CONN_SC_ENABLED, &conn->flags); 508eb9a8f3fSMarcel Holtmann } 509eb9a8f3fSMarcel Holtmann 5101da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) 5111da177e4SLinus Torvalds { 5121da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 513bf4c6325SGustavo F. Padovan list_add_rcu(&c->list, &h->list); 514fcd89c09SVille Tervo switch (c->type) { 515fcd89c09SVille Tervo case ACL_LINK: 5161da177e4SLinus Torvalds h->acl_num++; 517fcd89c09SVille Tervo break; 518bd1eb66bSAndrei Emeltchenko case AMP_LINK: 519bd1eb66bSAndrei Emeltchenko h->amp_num++; 520bd1eb66bSAndrei Emeltchenko break; 521fcd89c09SVille Tervo case LE_LINK: 522fcd89c09SVille Tervo h->le_num++; 523fcd89c09SVille Tervo break; 524fcd89c09SVille Tervo case SCO_LINK: 525fcd89c09SVille Tervo case ESCO_LINK: 5261da177e4SLinus Torvalds h->sco_num++; 527fcd89c09SVille Tervo break; 528fcd89c09SVille Tervo } 5291da177e4SLinus Torvalds } 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) 5321da177e4SLinus Torvalds { 5331da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 534bf4c6325SGustavo F. Padovan 535bf4c6325SGustavo F. Padovan list_del_rcu(&c->list); 536bf4c6325SGustavo F. Padovan synchronize_rcu(); 537bf4c6325SGustavo F. Padovan 538fcd89c09SVille Tervo switch (c->type) { 539fcd89c09SVille Tervo case ACL_LINK: 5401da177e4SLinus Torvalds h->acl_num--; 541fcd89c09SVille Tervo break; 542bd1eb66bSAndrei Emeltchenko case AMP_LINK: 543bd1eb66bSAndrei Emeltchenko h->amp_num--; 544bd1eb66bSAndrei Emeltchenko break; 545fcd89c09SVille Tervo case LE_LINK: 546fcd89c09SVille Tervo h->le_num--; 547fcd89c09SVille Tervo break; 548fcd89c09SVille Tervo case SCO_LINK: 549fcd89c09SVille Tervo case ESCO_LINK: 5501da177e4SLinus Torvalds h->sco_num--; 551fcd89c09SVille Tervo break; 552fcd89c09SVille Tervo } 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds 55552087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) 55652087a79SLuiz Augusto von Dentz { 55752087a79SLuiz Augusto von Dentz struct hci_conn_hash *h = &hdev->conn_hash; 55852087a79SLuiz Augusto von Dentz switch (type) { 55952087a79SLuiz Augusto von Dentz case ACL_LINK: 56052087a79SLuiz Augusto von Dentz return h->acl_num; 561bd1eb66bSAndrei Emeltchenko case AMP_LINK: 562bd1eb66bSAndrei Emeltchenko return h->amp_num; 56352087a79SLuiz Augusto von Dentz case LE_LINK: 56452087a79SLuiz Augusto von Dentz return h->le_num; 56552087a79SLuiz Augusto von Dentz case SCO_LINK: 56652087a79SLuiz Augusto von Dentz case ESCO_LINK: 56752087a79SLuiz Augusto von Dentz return h->sco_num; 56852087a79SLuiz Augusto von Dentz default: 56952087a79SLuiz Augusto von Dentz return 0; 57052087a79SLuiz Augusto von Dentz } 57152087a79SLuiz Augusto von Dentz } 57252087a79SLuiz Augusto von Dentz 573f4f07505SJohan Hedberg static inline unsigned int hci_conn_count(struct hci_dev *hdev) 574f4f07505SJohan Hedberg { 575f4f07505SJohan Hedberg struct hci_conn_hash *c = &hdev->conn_hash; 576f4f07505SJohan Hedberg 577f4f07505SJohan Hedberg return c->acl_num + c->amp_num + c->sco_num + c->le_num; 578f4f07505SJohan Hedberg } 579f4f07505SJohan Hedberg 5801da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 5811da177e4SLinus Torvalds __u16 handle) 5821da177e4SLinus Torvalds { 5831da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 5841da177e4SLinus Torvalds struct hci_conn *c; 5851da177e4SLinus Torvalds 586bf4c6325SGustavo F. Padovan rcu_read_lock(); 587bf4c6325SGustavo F. Padovan 588bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 589bf4c6325SGustavo F. Padovan if (c->handle == handle) { 590bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5911da177e4SLinus Torvalds return c; 5921da177e4SLinus Torvalds } 593bf4c6325SGustavo F. Padovan } 594bf4c6325SGustavo F. Padovan rcu_read_unlock(); 595bf4c6325SGustavo F. Padovan 5961da177e4SLinus Torvalds return NULL; 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, 6001da177e4SLinus Torvalds __u8 type, bdaddr_t *ba) 6011da177e4SLinus Torvalds { 6021da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 6031da177e4SLinus Torvalds struct hci_conn *c; 6041da177e4SLinus Torvalds 605bf4c6325SGustavo F. Padovan rcu_read_lock(); 606bf4c6325SGustavo F. Padovan 607bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 608bf4c6325SGustavo F. Padovan if (c->type == type && !bacmp(&c->dst, ba)) { 609bf4c6325SGustavo F. Padovan rcu_read_unlock(); 6101da177e4SLinus Torvalds return c; 6111da177e4SLinus Torvalds } 612bf4c6325SGustavo F. Padovan } 613bf4c6325SGustavo F. Padovan 614bf4c6325SGustavo F. Padovan rcu_read_unlock(); 615bf4c6325SGustavo F. Padovan 6161da177e4SLinus Torvalds return NULL; 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds 6194c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, 6204c67bc74SMarcel Holtmann __u8 type, __u16 state) 6214c67bc74SMarcel Holtmann { 6224c67bc74SMarcel Holtmann struct hci_conn_hash *h = &hdev->conn_hash; 6234c67bc74SMarcel Holtmann struct hci_conn *c; 6244c67bc74SMarcel Holtmann 625bf4c6325SGustavo F. Padovan rcu_read_lock(); 626bf4c6325SGustavo F. Padovan 627bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 628bf4c6325SGustavo F. Padovan if (c->type == type && c->state == state) { 629bf4c6325SGustavo F. Padovan rcu_read_unlock(); 6304c67bc74SMarcel Holtmann return c; 6314c67bc74SMarcel Holtmann } 632bf4c6325SGustavo F. Padovan } 633bf4c6325SGustavo F. Padovan 634bf4c6325SGustavo F. Padovan rcu_read_unlock(); 635bf4c6325SGustavo F. Padovan 6364c67bc74SMarcel Holtmann return NULL; 6374c67bc74SMarcel Holtmann } 6384c67bc74SMarcel Holtmann 639bed71748SAndre Guedes void hci_disconnect(struct hci_conn *conn, __u8 reason); 6402dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle); 641e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status); 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst); 6441da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn); 6451da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev); 646a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev); 6471da177e4SLinus Torvalds 64873d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn); 6499472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan); 6502c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn); 65142c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); 65273d80debSLuiz Augusto von Dentz 65304a6c589SAndre Guedes struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, 65404a6c589SAndre Guedes u8 dst_type, u8 sec_level, u8 auth_type); 65504a6c589SAndre Guedes struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, 65604a6c589SAndre Guedes u8 sec_level, u8 auth_type); 65710c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, 65810c62ddcSFrédéric Dalleau __u16 setting); 659e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn); 660b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); 6610684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); 6621da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn); 6638c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role); 6641da177e4SLinus Torvalds 66514b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); 6661da177e4SLinus Torvalds 66706c053fbSAndre Guedes void hci_le_conn_failed(struct hci_conn *conn, u8 status); 66806c053fbSAndre Guedes 6698d12356fSDavid Herrmann /* 6708d12356fSDavid Herrmann * hci_conn_get() and hci_conn_put() are used to control the life-time of an 6718d12356fSDavid Herrmann * "hci_conn" object. They do not guarantee that the hci_conn object is running, 6728d12356fSDavid Herrmann * working or anything else. They just guarantee that the object is available 6738d12356fSDavid Herrmann * and can be dereferenced. So you can use its locks, local variables and any 6748d12356fSDavid Herrmann * other constant data. 6758d12356fSDavid Herrmann * Before accessing runtime data, you _must_ lock the object and then check that 6768d12356fSDavid Herrmann * it is still running. As soon as you release the locks, the connection might 6778d12356fSDavid Herrmann * get dropped, though. 6788d12356fSDavid Herrmann * 6798d12356fSDavid Herrmann * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control 6808d12356fSDavid Herrmann * how long the underlying connection is held. So every channel that runs on the 6818d12356fSDavid Herrmann * hci_conn object calls this to prevent the connection from disappearing. As 6828d12356fSDavid Herrmann * long as you hold a device, you must also guarantee that you have a valid 6838d12356fSDavid Herrmann * reference to the device via hci_conn_get() (or the initial reference from 6848d12356fSDavid Herrmann * hci_conn_add()). 6858d12356fSDavid Herrmann * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't 6868d12356fSDavid Herrmann * break because nobody cares for that. But this means, we cannot use 6878d12356fSDavid Herrmann * _get()/_drop() in it, but require the caller to have a valid ref (FIXME). 6888d12356fSDavid Herrmann */ 6898d12356fSDavid Herrmann 6908d12356fSDavid Herrmann static inline void hci_conn_get(struct hci_conn *conn) 6918d12356fSDavid Herrmann { 6928d12356fSDavid Herrmann get_device(&conn->dev); 6938d12356fSDavid Herrmann } 6948d12356fSDavid Herrmann 6958d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn) 6968d12356fSDavid Herrmann { 6978d12356fSDavid Herrmann put_device(&conn->dev); 6988d12356fSDavid Herrmann } 6998d12356fSDavid Herrmann 7001da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn) 7011da177e4SLinus Torvalds { 70271becf0cSAndrei Emeltchenko BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 70338b3fef1SAndrei Emeltchenko 7041da177e4SLinus Torvalds atomic_inc(&conn->refcnt); 7052f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 7061da177e4SLinus Torvalds } 7071da177e4SLinus Torvalds 70876a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn) 7091da177e4SLinus Torvalds { 71071becf0cSAndrei Emeltchenko BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 71138b3fef1SAndrei Emeltchenko 7121da177e4SLinus Torvalds if (atomic_dec_and_test(&conn->refcnt)) { 71304837f64SMarcel Holtmann unsigned long timeo; 714716e4ab5SAndrei Emeltchenko 715716e4ab5SAndrei Emeltchenko switch (conn->type) { 716716e4ab5SAndrei Emeltchenko case ACL_LINK: 717716e4ab5SAndrei Emeltchenko case LE_LINK: 718a74a84f6SJohan Hedberg cancel_delayed_work(&conn->idle_work); 7196ac59344SMarcel Holtmann if (conn->state == BT_CONNECTED) { 7205f246e89SAndrei Emeltchenko timeo = conn->disc_timeout; 72104837f64SMarcel Holtmann if (!conn->out) 722052b30b0SMarcel Holtmann timeo *= 2; 7235a9d0a3fSWaldemar Rymarkiewicz } else { 7246ac59344SMarcel Holtmann timeo = msecs_to_jiffies(10); 7255a9d0a3fSWaldemar Rymarkiewicz } 726716e4ab5SAndrei Emeltchenko break; 727716e4ab5SAndrei Emeltchenko 728716e4ab5SAndrei Emeltchenko case AMP_LINK: 729716e4ab5SAndrei Emeltchenko timeo = conn->disc_timeout; 730716e4ab5SAndrei Emeltchenko break; 731716e4ab5SAndrei Emeltchenko 732716e4ab5SAndrei Emeltchenko default: 73304837f64SMarcel Holtmann timeo = msecs_to_jiffies(10); 734716e4ab5SAndrei Emeltchenko break; 7355a9d0a3fSWaldemar Rymarkiewicz } 736716e4ab5SAndrei Emeltchenko 7372f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 73819c40e3bSGustavo F. Padovan queue_delayed_work(conn->hdev->workqueue, 7391931782bSVinicius Costa Gomes &conn->disc_work, timeo); 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds } 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds /* ----- HCI Devices ----- */ 744dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d) 7451da177e4SLinus Torvalds { 746376261aeSAndrei Emeltchenko BT_DBG("%s orig refcnt %d", d->name, 747376261aeSAndrei Emeltchenko atomic_read(&d->dev.kobj.kref.refcount)); 748376261aeSAndrei Emeltchenko 7494c724c71SDavid Herrmann put_device(&d->dev); 750010666a1SDavid Herrmann } 7511da177e4SLinus Torvalds 752dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) 7531da177e4SLinus Torvalds { 754376261aeSAndrei Emeltchenko BT_DBG("%s orig refcnt %d", d->name, 755376261aeSAndrei Emeltchenko atomic_read(&d->dev.kobj.kref.refcount)); 756376261aeSAndrei Emeltchenko 7574c724c71SDavid Herrmann get_device(&d->dev); 7581da177e4SLinus Torvalds return d; 7591da177e4SLinus Torvalds } 7601da177e4SLinus Torvalds 76109fd0de5SGustavo F. Padovan #define hci_dev_lock(d) mutex_lock(&d->lock) 76209fd0de5SGustavo F. Padovan #define hci_dev_unlock(d) mutex_unlock(&d->lock) 7631da177e4SLinus Torvalds 764aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev) 7653dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev) 766aa2b86d7SDavid Herrmann 767155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev) 768155961e8SDavid Herrmann { 769155961e8SDavid Herrmann return dev_get_drvdata(&hdev->dev); 770155961e8SDavid Herrmann } 771155961e8SDavid Herrmann 772155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) 773155961e8SDavid Herrmann { 774155961e8SDavid Herrmann dev_set_drvdata(&hdev->dev, data); 775155961e8SDavid Herrmann } 776155961e8SDavid Herrmann 7771da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index); 7780c0afedfSJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src); 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void); 7811da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev); 7821da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev); 78359735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev); 7841da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev); 7851da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev); 7861da177e4SLinus Torvalds int hci_dev_open(__u16 dev); 7871da177e4SLinus Torvalds int hci_dev_close(__u16 dev); 7881da177e4SLinus Torvalds int hci_dev_reset(__u16 dev); 7891da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev); 7901da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg); 7911da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg); 7921da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg); 7931da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg); 7941da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); 79540be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); 7961da177e4SLinus Torvalds int hci_inquiry(void __user *arg); 7971da177e4SLinus Torvalds 798c3c7ea65SGustavo Padovan struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, 799b9ee0a78SMarcel Holtmann bdaddr_t *bdaddr, u8 type); 80088c1fe4bSJohan Hedberg int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 80188c1fe4bSJohan Hedberg int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 802f0358568SJohan Hedberg 803d2ab0ac1SMarcel Holtmann struct bdaddr_list *hci_white_list_lookup(struct hci_dev *hdev, 804d2ab0ac1SMarcel Holtmann bdaddr_t *bdaddr, u8 type); 805d2ab0ac1SMarcel Holtmann void hci_white_list_clear(struct hci_dev *hdev); 806d2ab0ac1SMarcel Holtmann int hci_white_list_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 807d2ab0ac1SMarcel Holtmann int hci_white_list_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 808d2ab0ac1SMarcel Holtmann 80915819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, 81015819a70SAndre Guedes bdaddr_t *addr, u8 addr_type); 811a9b0a04cSAndre Guedes int hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type, 8129fcb18efSAndre Guedes u8 auto_connect, u16 conn_min_interval, 8139fcb18efSAndre Guedes u16 conn_max_interval); 81415819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); 81515819a70SAndre Guedes void hci_conn_params_clear(struct hci_dev *hdev); 81615819a70SAndre Guedes 81777a77a30SAndre Guedes struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev, 81877a77a30SAndre Guedes bdaddr_t *addr, u8 addr_type); 81977a77a30SAndre Guedes void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); 82077a77a30SAndre Guedes void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); 82177a77a30SAndre Guedes void hci_pend_le_conns_clear(struct hci_dev *hdev); 82277a77a30SAndre Guedes 823a4790dbdSAndre Guedes void hci_update_background_scan(struct hci_dev *hdev); 824a4790dbdSAndre Guedes 82535f7498aSJohan Hedberg void hci_uuids_clear(struct hci_dev *hdev); 8262aeb9a1aSJohan Hedberg 82735f7498aSJohan Hedberg void hci_link_keys_clear(struct hci_dev *hdev); 82855ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 829d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 830d25e28abSJohan Hedberg bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len); 83198a0b845SJohan Hedberg struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8], 83298a0b845SJohan Hedberg bool master); 833ca9142b8SJohan Hedberg struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, 83435d70271SJohan Hedberg u8 addr_type, u8 type, u8 authenticated, 83535d70271SJohan Hedberg u8 tk[16], u8 enc_size, __le16 ediv, u8 rand[8]); 836c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 83798a0b845SJohan Hedberg u8 addr_type, bool master); 838e0b2b27eSJohan Hedberg int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type); 83935f7498aSJohan Hedberg void hci_smp_ltks_clear(struct hci_dev *hdev); 84055ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 84155ed8ca1SJohan Hedberg 842970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa); 843970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 844970c4e46SJohan Hedberg u8 addr_type); 845ca9142b8SJohan Hedberg struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, 846ca9142b8SJohan Hedberg u8 addr_type, u8 val[16], bdaddr_t *rpa); 847a7ec7338SJohan Hedberg void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type); 848970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev); 849970c4e46SJohan Hedberg 85035f7498aSJohan Hedberg void hci_remote_oob_data_clear(struct hci_dev *hdev); 8512763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 8522763eda6SSzymon Janc bdaddr_t *bdaddr); 8530798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 8540798872eSMarcel Holtmann u8 *hash, u8 *randomizer); 8550798872eSMarcel Holtmann int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 8560798872eSMarcel Holtmann u8 *hash192, u8 *randomizer192, 8570798872eSMarcel Holtmann u8 *hash256, u8 *randomizer256); 8582763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); 8592763eda6SSzymon Janc 8601da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); 8611da177e4SLinus Torvalds 862e1a26170SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb); 863ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count); 86499811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count); 865ef222013SMarcel Holtmann 8660ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev); 867a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn); 868b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn); 869b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn); 8701da177e4SLinus Torvalds 8716935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) 8721da177e4SLinus Torvalds 8731da177e4SLinus Torvalds /* ----- LMP capabilities ----- */ 874cad718edSJohan Hedberg #define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT) 875cad718edSJohan Hedberg #define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH) 876cad718edSJohan Hedberg #define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD) 877cad718edSJohan Hedberg #define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF) 878cad718edSJohan Hedberg #define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK) 879cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ) 880cad718edSJohan Hedberg #define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO) 881cad718edSJohan Hedberg #define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR)) 882cad718edSJohan Hedberg #define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE) 883cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR) 884cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC) 885cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ) 886cad718edSJohan Hedberg #define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR)) 887cad718edSJohan Hedberg #define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR) 888cad718edSJohan Hedberg #define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH) 889cad718edSJohan Hedberg #define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO) 890cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR) 891cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES) 89207a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT) 8931da177e4SLinus Torvalds 894eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */ 89553b834d2SMarcel Holtmann #define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER) 89653b834d2SMarcel Holtmann #define lmp_csb_slave_capable(dev) ((dev)->features[2][0] & LMP_CSB_SLAVE) 89753b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN) 89853b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev) ((dev)->features[2][0] & LMP_SYNC_SCAN) 899d5991585SMarcel Holtmann #define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC) 900d5991585SMarcel Holtmann #define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING) 90153b834d2SMarcel Holtmann 90253b834d2SMarcel Holtmann /* ----- Host capabilities ----- */ 903cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP) 904d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev) ((dev)->features[1][0] & LMP_HOST_SC) 905cad718edSJohan Hedberg #define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE)) 906cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR)) 907eead27daSAndre Guedes 9081da177e4SLinus Torvalds /* ----- HCI protocols ----- */ 90920714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER 0x01 91020714bfeSFrédéric Dalleau 9115a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 91220714bfeSFrédéric Dalleau __u8 type, __u8 *flags) 9131da177e4SLinus Torvalds { 914686ebf28SUlisses Furquim switch (type) { 915686ebf28SUlisses Furquim case ACL_LINK: 916686ebf28SUlisses Furquim return l2cap_connect_ind(hdev, bdaddr); 9171da177e4SLinus Torvalds 918686ebf28SUlisses Furquim case SCO_LINK: 919686ebf28SUlisses Furquim case ESCO_LINK: 92020714bfeSFrédéric Dalleau return sco_connect_ind(hdev, bdaddr, flags); 9211da177e4SLinus Torvalds 922686ebf28SUlisses Furquim default: 923686ebf28SUlisses Furquim BT_ERR("unknown link type %d", type); 924686ebf28SUlisses Furquim return -EINVAL; 925686ebf28SUlisses Furquim } 9261da177e4SLinus Torvalds } 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status) 9291da177e4SLinus Torvalds { 930686ebf28SUlisses Furquim switch (conn->type) { 931686ebf28SUlisses Furquim case ACL_LINK: 932686ebf28SUlisses Furquim case LE_LINK: 933686ebf28SUlisses Furquim l2cap_connect_cfm(conn, status); 934686ebf28SUlisses Furquim break; 9351da177e4SLinus Torvalds 936686ebf28SUlisses Furquim case SCO_LINK: 937686ebf28SUlisses Furquim case ESCO_LINK: 938686ebf28SUlisses Furquim sco_connect_cfm(conn, status); 939686ebf28SUlisses Furquim break; 9401da177e4SLinus Torvalds 941686ebf28SUlisses Furquim default: 942686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 943686ebf28SUlisses Furquim break; 944686ebf28SUlisses Furquim } 945e9a416b5SJohan Hedberg 946e9a416b5SJohan Hedberg if (conn->connect_cfm_cb) 947e9a416b5SJohan Hedberg conn->connect_cfm_cb(conn, status); 9481da177e4SLinus Torvalds } 9491da177e4SLinus Torvalds 9502950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn) 9512950f21aSMarcel Holtmann { 952686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 953686ebf28SUlisses Furquim return HCI_ERROR_REMOTE_USER_TERM; 9542950f21aSMarcel Holtmann 955686ebf28SUlisses Furquim return l2cap_disconn_ind(conn); 9562950f21aSMarcel Holtmann } 9572950f21aSMarcel Holtmann 9582950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason) 9591da177e4SLinus Torvalds { 960686ebf28SUlisses Furquim switch (conn->type) { 961686ebf28SUlisses Furquim case ACL_LINK: 962686ebf28SUlisses Furquim case LE_LINK: 963686ebf28SUlisses Furquim l2cap_disconn_cfm(conn, reason); 964686ebf28SUlisses Furquim break; 9651da177e4SLinus Torvalds 966686ebf28SUlisses Furquim case SCO_LINK: 967686ebf28SUlisses Furquim case ESCO_LINK: 968686ebf28SUlisses Furquim sco_disconn_cfm(conn, reason); 969686ebf28SUlisses Furquim break; 9701da177e4SLinus Torvalds 971bd1eb66bSAndrei Emeltchenko /* L2CAP would be handled for BREDR chan */ 972bd1eb66bSAndrei Emeltchenko case AMP_LINK: 973bd1eb66bSAndrei Emeltchenko break; 974bd1eb66bSAndrei Emeltchenko 975686ebf28SUlisses Furquim default: 976686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 977686ebf28SUlisses Furquim break; 978686ebf28SUlisses Furquim } 979e9a416b5SJohan Hedberg 980e9a416b5SJohan Hedberg if (conn->disconn_cfm_cb) 981e9a416b5SJohan Hedberg conn->disconn_cfm_cb(conn, reason); 9821da177e4SLinus Torvalds } 9831da177e4SLinus Torvalds 9841da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status) 9851da177e4SLinus Torvalds { 9868c1b2355SMarcel Holtmann __u8 encrypt; 9878c1b2355SMarcel Holtmann 988686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 989686ebf28SUlisses Furquim return; 990686ebf28SUlisses Furquim 99151a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 9928c1b2355SMarcel Holtmann return; 9938c1b2355SMarcel Holtmann 9948c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 995686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 996e9a416b5SJohan Hedberg 997e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 998e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 10015a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, 10025a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 10031da177e4SLinus Torvalds { 1004686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 1005686ebf28SUlisses Furquim return; 10061da177e4SLinus Torvalds 1007686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 1008e9a416b5SJohan Hedberg 1009e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 1010e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 10111da177e4SLinus Torvalds } 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds /* ----- HCI callbacks ----- */ 10141da177e4SLinus Torvalds struct hci_cb { 10151da177e4SLinus Torvalds struct list_head list; 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds char *name; 10181da177e4SLinus Torvalds 10195a9d0a3fSWaldemar Rymarkiewicz void (*security_cfm) (struct hci_conn *conn, __u8 status, 10205a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt); 10211da177e4SLinus Torvalds void (*key_change_cfm) (struct hci_conn *conn, __u8 status); 10221da177e4SLinus Torvalds void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); 10231da177e4SLinus Torvalds }; 10241da177e4SLinus Torvalds 10251da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) 10261da177e4SLinus Torvalds { 1027711584eaSDenis Kirjanov struct hci_cb *cb; 10288c1b2355SMarcel Holtmann __u8 encrypt; 10291da177e4SLinus Torvalds 10301da177e4SLinus Torvalds hci_proto_auth_cfm(conn, status); 10311da177e4SLinus Torvalds 103251a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 10338c1b2355SMarcel Holtmann return; 10348c1b2355SMarcel Holtmann 10358c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 10368c1b2355SMarcel Holtmann 1037f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1038711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10398c1b2355SMarcel Holtmann if (cb->security_cfm) 10408c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 10411da177e4SLinus Torvalds } 1042f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10431da177e4SLinus Torvalds } 10441da177e4SLinus Torvalds 10455a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, 10465a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 10471da177e4SLinus Torvalds { 1048711584eaSDenis Kirjanov struct hci_cb *cb; 10491da177e4SLinus Torvalds 1050435fef20SMarcel Holtmann if (conn->sec_level == BT_SECURITY_SDP) 1051435fef20SMarcel Holtmann conn->sec_level = BT_SECURITY_LOW; 1052435fef20SMarcel Holtmann 105388167aedSVinicius Costa Gomes if (conn->pending_sec_level > conn->sec_level) 105488167aedSVinicius Costa Gomes conn->sec_level = conn->pending_sec_level; 105588167aedSVinicius Costa Gomes 10569719f8afSMarcel Holtmann hci_proto_encrypt_cfm(conn, status, encrypt); 10571da177e4SLinus Torvalds 1058f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1059711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10608c1b2355SMarcel Holtmann if (cb->security_cfm) 10618c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 10621da177e4SLinus Torvalds } 1063f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10641da177e4SLinus Torvalds } 10651da177e4SLinus Torvalds 10661da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) 10671da177e4SLinus Torvalds { 1068711584eaSDenis Kirjanov struct hci_cb *cb; 10691da177e4SLinus Torvalds 1070f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1071711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10721da177e4SLinus Torvalds if (cb->key_change_cfm) 10731da177e4SLinus Torvalds cb->key_change_cfm(conn, status); 10741da177e4SLinus Torvalds } 1075f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10761da177e4SLinus Torvalds } 10771da177e4SLinus Torvalds 10785a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, 10795a9d0a3fSWaldemar Rymarkiewicz __u8 role) 10801da177e4SLinus Torvalds { 1081711584eaSDenis Kirjanov struct hci_cb *cb; 10821da177e4SLinus Torvalds 1083f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1084711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10851da177e4SLinus Torvalds if (cb->role_switch_cfm) 10861da177e4SLinus Torvalds cb->role_switch_cfm(conn, status, role); 10871da177e4SLinus Torvalds } 1088f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10891da177e4SLinus Torvalds } 10901da177e4SLinus Torvalds 10916759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) 10926759a675SJohan Hedberg { 109384d9d071SJohan Hedberg size_t parsed = 0; 10946759a675SJohan Hedberg 10956c0c331eSJohan Hedberg if (data_len < 2) 10966c0c331eSJohan Hedberg return false; 10976c0c331eSJohan Hedberg 109884d9d071SJohan Hedberg while (parsed < data_len - 1) { 109984d9d071SJohan Hedberg u8 field_len = data[0]; 11006759a675SJohan Hedberg 11016759a675SJohan Hedberg if (field_len == 0) 11026759a675SJohan Hedberg break; 11036759a675SJohan Hedberg 11046759a675SJohan Hedberg parsed += field_len + 1; 11056759a675SJohan Hedberg 11066759a675SJohan Hedberg if (parsed > data_len) 11076759a675SJohan Hedberg break; 11086759a675SJohan Hedberg 11096759a675SJohan Hedberg if (data[1] == type) 11106759a675SJohan Hedberg return true; 11116759a675SJohan Hedberg 11126759a675SJohan Hedberg data += field_len + 1; 11136759a675SJohan Hedberg } 11146759a675SJohan Hedberg 11156759a675SJohan Hedberg return false; 11166759a675SJohan Hedberg } 11176759a675SJohan Hedberg 1118301cb2d8SJohan Hedberg static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type) 1119301cb2d8SJohan Hedberg { 1120301cb2d8SJohan Hedberg if (addr_type != 0x01) 1121301cb2d8SJohan Hedberg return false; 1122301cb2d8SJohan Hedberg 1123301cb2d8SJohan Hedberg if ((bdaddr->b[5] & 0xc0) == 0x40) 1124301cb2d8SJohan Hedberg return true; 1125301cb2d8SJohan Hedberg 1126301cb2d8SJohan Hedberg return false; 1127301cb2d8SJohan Hedberg } 1128301cb2d8SJohan Hedberg 11292426f3a5SJohan Hedberg static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev, 11302426f3a5SJohan Hedberg bdaddr_t *bdaddr, u8 addr_type) 11312426f3a5SJohan Hedberg { 11322426f3a5SJohan Hedberg if (!hci_bdaddr_is_rpa(bdaddr, addr_type)) 11332426f3a5SJohan Hedberg return NULL; 11342426f3a5SJohan Hedberg 11352426f3a5SJohan Hedberg return hci_find_irk_by_rpa(hdev, bdaddr); 11362426f3a5SJohan Hedberg } 11372426f3a5SJohan Hedberg 11381da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb); 11391da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb); 11401da177e4SLinus Torvalds 11413119ae95SJohan Hedberg struct hci_request { 11423119ae95SJohan Hedberg struct hci_dev *hdev; 11433119ae95SJohan Hedberg struct sk_buff_head cmd_q; 11445d73e034SAndre Guedes 11455d73e034SAndre Guedes /* If something goes wrong when building the HCI request, the error 11465d73e034SAndre Guedes * value is stored in this field. 11475d73e034SAndre Guedes */ 11485d73e034SAndre Guedes int err; 11493119ae95SJohan Hedberg }; 11503119ae95SJohan Hedberg 11513119ae95SJohan Hedberg void hci_req_init(struct hci_request *req, struct hci_dev *hdev); 11523119ae95SJohan Hedberg int hci_req_run(struct hci_request *req, hci_req_complete_t complete); 115307dc93ddSJohan Hedberg void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, 115407dc93ddSJohan Hedberg const void *param); 115507dc93ddSJohan Hedberg void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, 115607dc93ddSJohan Hedberg const void *param, u8 event); 11579238f36aSJohan Hedberg void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status); 11583119ae95SJohan Hedberg 1159b1efcc28SAndre Guedes void hci_req_add_le_scan_disable(struct hci_request *req); 11608ef30fd3SAndre Guedes void hci_req_add_le_passive_scan(struct hci_request *req); 1161b1efcc28SAndre Guedes 116275e84b7cSJohan Hedberg struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, 116307dc93ddSJohan Hedberg const void *param, u32 timeout); 11647b1abbbeSJohan Hedberg struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, 116507dc93ddSJohan Hedberg const void *param, u8 event, u32 timeout); 116675e84b7cSJohan Hedberg 116707dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, 116807dc93ddSJohan Hedberg const void *param); 116973d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 11700d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 11711da177e4SLinus Torvalds 1172a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); 11731da177e4SLinus Torvalds 11741da177e4SLinus Torvalds /* ----- HCI Sockets ----- */ 1175470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); 1176470fe1b5SMarcel Holtmann void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk); 1177cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); 11781da177e4SLinus Torvalds 1179040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event); 1180040030efSMarcel Holtmann 11810381101fSJohan Hedberg /* Management interface */ 1182591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR)) 1183591f47f3SAndre Guedes #define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \ 1184591f47f3SAndre Guedes BIT(BDADDR_LE_RANDOM)) 1185591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \ 1186591f47f3SAndre Guedes BIT(BDADDR_LE_PUBLIC) | \ 1187591f47f3SAndre Guedes BIT(BDADDR_LE_RANDOM)) 1188f39799f5SAndre Guedes 11890d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General 11900d8cc935SAndre Guedes * Discovery Procedure specification. 11910d8cc935SAndre Guedes */ 11920d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN 0x12 11930d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT 0x12 11940d8cc935SAndre Guedes #define DISCOV_LE_TIMEOUT msecs_to_jiffies(10240) 11950d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_TIMEOUT msecs_to_jiffies(5120) 11960d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04 11970d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN 0x08 11980d8cc935SAndre Guedes 11990381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); 1200bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev); 1201bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev); 12023eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err); 1203744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered); 1204d1967ff8SMarcel Holtmann void mgmt_discoverable_timeout(struct hci_dev *hdev); 120586a75645SMarcel Holtmann void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); 1206a330916cSMarcel Holtmann void mgmt_connectable(struct hci_dev *hdev, u8 connectable); 1207778b235aSJohan Hedberg void mgmt_advertising(struct hci_dev *hdev, u8 advertising); 12084796e8afSMarcel Holtmann void mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 1209dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 1210745c0ce3SVishal Agarwal bool persistent); 1211ecd90ae7SMarcel Holtmann void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 121204124681SGustavo F. Padovan u8 addr_type, u32 flags, u8 *name, u8 name_len, 121304124681SGustavo F. Padovan u8 *dev_class); 12149b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 121512d4a3b2SJohan Hedberg u8 link_type, u8 addr_type, u8 reason, 121612d4a3b2SJohan Hedberg bool mgmt_connected); 12177892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 121888c3df13SJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1219445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 122048264f06SJohan Hedberg u8 addr_type, u8 status); 1221ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 1222e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1223c35938b2SSzymon Janc u8 status); 12243eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1225744cf19eSJohan Hedberg u8 status); 1226744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1227272d90dfSJohan Hedberg u8 link_type, u8 addr_type, __le32 value, 1228272d90dfSJohan Hedberg u8 confirm_hint); 1229744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1230272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1231272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1232272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1233272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1234272d90dfSJohan Hedberg u8 link_type, u8 addr_type); 1235604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1236272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1237272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1238272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 123992a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, 124092a25256SJohan Hedberg u8 link_type, u8 addr_type, u32 passkey, 124192a25256SJohan Hedberg u8 entered); 1242e546099cSMarcel Holtmann void mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1243bab73cb6SJohan Hedberg u8 addr_type, u8 status); 1244464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); 12453e248560SMarcel Holtmann void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 1246eac83dc6SMarcel Holtmann void mgmt_sc_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 12474e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 12487f9a903cSMarcel Holtmann u8 status); 12497667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 12504d2d2796SMarcel Holtmann void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192, 12514d2d2796SMarcel Holtmann u8 *randomizer192, u8 *hash256, 12524d2d2796SMarcel Holtmann u8 *randomizer256, u8 status); 1253901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 125404124681SGustavo F. Padovan u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, 125504124681SGustavo F. Padovan u8 ssp, u8 *eir, u16 eir_len); 12569cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1257b644ba33SJohan Hedberg u8 addr_type, s8 rssi, u8 *name, u8 name_len); 12582f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering); 125988c1fe4bSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 126088c1fe4bSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 1261ba74b666SJohan Hedberg void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key); 126295fbac8aSJohan Hedberg void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk); 12635976e608SMarcel Holtmann void mgmt_reenable_advertising(struct hci_dev *hdev); 1264f4a407beSJohan Hedberg void mgmt_smp_complete(struct hci_conn *conn, bool complete); 1265346af67bSVinicius Costa Gomes 12661da177e4SLinus Torvalds /* HCI info for socket */ 12671da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk) 12681da177e4SLinus Torvalds 12691da177e4SLinus Torvalds struct hci_pinfo { 12701da177e4SLinus Torvalds struct bt_sock bt; 12711da177e4SLinus Torvalds struct hci_dev *hdev; 12721da177e4SLinus Torvalds struct hci_filter filter; 12731da177e4SLinus Torvalds __u32 cmsg_mask; 1274c02178d2SJohan Hedberg unsigned short channel; 12751da177e4SLinus Torvalds }; 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds /* HCI security filter */ 12781da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF 5 12791da177e4SLinus Torvalds 12801da177e4SLinus Torvalds struct hci_sec_filter { 12811da177e4SLinus Torvalds __u32 type_mask; 12821da177e4SLinus Torvalds __u32 event_mask[2]; 12831da177e4SLinus Torvalds __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4]; 12841da177e4SLinus Torvalds }; 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds /* ----- HCI requests ----- */ 12871da177e4SLinus Torvalds #define HCI_REQ_DONE 0 12881da177e4SLinus Torvalds #define HCI_REQ_PEND 1 12891da177e4SLinus Torvalds #define HCI_REQ_CANCELED 2 12901da177e4SLinus Torvalds 1291a6a67efdSThomas Gleixner #define hci_req_lock(d) mutex_lock(&d->req_lock) 1292a6a67efdSThomas Gleixner #define hci_req_unlock(d) mutex_unlock(&d->req_lock) 12931da177e4SLinus Torvalds 12942ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, 12952ce603ebSClaudio Takahasi u16 latency, u16 to_multiplier); 1296a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8], 1297a7a595f6SVinicius Costa Gomes __u8 ltk[16]); 12982519a1fcSAndre Guedes 129994b1fc92SMarcel Holtmann int hci_update_random_address(struct hci_request *req, bool require_privacy, 130094b1fc92SMarcel Holtmann u8 *own_addr_type); 1301a1f4c318SJohan Hedberg void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, 1302a1f4c318SJohan Hedberg u8 *bdaddr_type); 1303ebd3a747SJohan Hedberg 13045d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK 0x0003 13055d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD 0x0000 13065d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP 0x0003 13075d4d62f6SFrédéric Dalleau 13081da177e4SLinus Torvalds #endif /* __HCI_CORE_H */ 1309