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 133903e4541SAndrei Emeltchenko struct amp_assoc { 134903e4541SAndrei Emeltchenko __u16 len; 135903e4541SAndrei Emeltchenko __u16 offset; 13693c284eeSAndrei Emeltchenko __u16 rem_len; 13793c284eeSAndrei Emeltchenko __u16 len_so_far; 138903e4541SAndrei Emeltchenko __u8 data[HCI_MAX_AMP_ASSOC_SIZE]; 139903e4541SAndrei Emeltchenko }; 140903e4541SAndrei Emeltchenko 141d2c5d77fSJohan Hedberg #define HCI_MAX_PAGES 3 142cad718edSJohan Hedberg 143cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4 1441da177e4SLinus Torvalds struct hci_dev { 1451da177e4SLinus Torvalds struct list_head list; 14609fd0de5SGustavo F. Padovan struct mutex lock; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds char name[8]; 1491da177e4SLinus Torvalds unsigned long flags; 1501da177e4SLinus Torvalds __u16 id; 151c13854ceSMarcel Holtmann __u8 bus; 152943da25dSMarcel Holtmann __u8 dev_type; 1531da177e4SLinus Torvalds bdaddr_t bdaddr; 154d13eafceSMarcel Holtmann bdaddr_t static_addr; 15579830f66SMarcel Holtmann __u8 own_addr_type; 1561f6c6378SJohan Hedberg __u8 dev_name[HCI_MAX_NAME_LENGTH]; 157490c5babSJohan Hedberg __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; 15880a1e1dbSJohan Hedberg __u8 eir[HCI_MAX_EIR_LENGTH]; 159a9de9248SMarcel Holtmann __u8 dev_class[3]; 1601aff6f09SJohan Hedberg __u8 major_class; 1611aff6f09SJohan Hedberg __u8 minor_class; 162d2c5d77fSJohan Hedberg __u8 max_page; 163cad718edSJohan Hedberg __u8 features[HCI_MAX_PAGES][8]; 16460e77321SJohan Hedberg __u8 le_features[8]; 165cf1d081fSJohan Hedberg __u8 le_white_list_size; 1669b008c04SJohan Hedberg __u8 le_states[8]; 167a9de9248SMarcel Holtmann __u8 commands[64]; 1681143e5a6SMarcel Holtmann __u8 hci_ver; 1691143e5a6SMarcel Holtmann __u16 hci_rev; 170d5859e22SJohan Hedberg __u8 lmp_ver; 1711143e5a6SMarcel Holtmann __u16 manufacturer; 1727d69230cSAndrei Emeltchenko __u16 lmp_subver; 1731da177e4SLinus Torvalds __u16 voice_setting; 174b4cb9fb2SMarcel Holtmann __u8 num_iac; 17517fa4b9dSJohan Hedberg __u8 io_capability; 17691c4e9b1SMarcel Holtmann __s8 inq_tx_power; 177f332ec66SJohan Hedberg __u16 page_scan_interval; 178f332ec66SJohan Hedberg __u16 page_scan_window; 179f332ec66SJohan Hedberg __u8 page_scan_type; 180bef64738SMarcel Holtmann __u16 le_scan_interval; 181bef64738SMarcel Holtmann __u16 le_scan_window; 1824e70c7e7SMarcel Holtmann __u16 le_conn_min_interval; 1834e70c7e7SMarcel Holtmann __u16 le_conn_max_interval; 18406f5b778SMarcel Holtmann __u8 ssp_debug_mode; 185f332ec66SJohan Hedberg 1862b9be137SMarcel Holtmann __u16 devid_source; 1872b9be137SMarcel Holtmann __u16 devid_vendor; 1882b9be137SMarcel Holtmann __u16 devid_product; 1892b9be137SMarcel Holtmann __u16 devid_version; 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds __u16 pkt_type; 1925b7f9909SMarcel Holtmann __u16 esco_type; 1931da177e4SLinus Torvalds __u16 link_policy; 1941da177e4SLinus Torvalds __u16 link_mode; 1951da177e4SLinus Torvalds 19604837f64SMarcel Holtmann __u32 idle_timeout; 19704837f64SMarcel Holtmann __u16 sniff_min_interval; 19804837f64SMarcel Holtmann __u16 sniff_max_interval; 19904837f64SMarcel Holtmann 200928abaa7SAndrei Emeltchenko __u8 amp_status; 201928abaa7SAndrei Emeltchenko __u32 amp_total_bw; 202928abaa7SAndrei Emeltchenko __u32 amp_max_bw; 203928abaa7SAndrei Emeltchenko __u32 amp_min_latency; 204928abaa7SAndrei Emeltchenko __u32 amp_max_pdu; 205928abaa7SAndrei Emeltchenko __u8 amp_type; 206928abaa7SAndrei Emeltchenko __u16 amp_pal_cap; 207928abaa7SAndrei Emeltchenko __u16 amp_assoc_size; 208928abaa7SAndrei Emeltchenko __u32 amp_max_flush_to; 209928abaa7SAndrei Emeltchenko __u32 amp_be_flush_to; 210928abaa7SAndrei Emeltchenko 211903e4541SAndrei Emeltchenko struct amp_assoc loc_assoc; 212903e4541SAndrei Emeltchenko 2131e89cffbSAndrei Emeltchenko __u8 flow_ctl_mode; 2141e89cffbSAndrei Emeltchenko 2159f61656aSJohan Hedberg unsigned int auto_accept_delay; 2169f61656aSJohan Hedberg 2171da177e4SLinus Torvalds unsigned long quirks; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds atomic_t cmd_cnt; 2201da177e4SLinus Torvalds unsigned int acl_cnt; 2211da177e4SLinus Torvalds unsigned int sco_cnt; 2226ed58ec5SVille Tervo unsigned int le_cnt; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds unsigned int acl_mtu; 2251da177e4SLinus Torvalds unsigned int sco_mtu; 2266ed58ec5SVille Tervo unsigned int le_mtu; 2271da177e4SLinus Torvalds unsigned int acl_pkts; 2281da177e4SLinus Torvalds unsigned int sco_pkts; 2296ed58ec5SVille Tervo unsigned int le_pkts; 2301da177e4SLinus Torvalds 231350ee4cfSAndrei Emeltchenko __u16 block_len; 232350ee4cfSAndrei Emeltchenko __u16 block_mtu; 233350ee4cfSAndrei Emeltchenko __u16 num_blocks; 234350ee4cfSAndrei Emeltchenko __u16 block_cnt; 235350ee4cfSAndrei Emeltchenko 2361da177e4SLinus Torvalds unsigned long acl_last_tx; 2371da177e4SLinus Torvalds unsigned long sco_last_tx; 2386ed58ec5SVille Tervo unsigned long le_last_tx; 2391da177e4SLinus Torvalds 240f48fd9c8SMarcel Holtmann struct workqueue_struct *workqueue; 2416ead1bbcSJohan Hedberg struct workqueue_struct *req_workqueue; 242f48fd9c8SMarcel Holtmann 243ab81cbf9SJohan Hedberg struct work_struct power_on; 2443243553fSJohan Hedberg struct delayed_work power_off; 245ab81cbf9SJohan Hedberg 24616ab91abSJohan Hedberg __u16 discov_timeout; 24716ab91abSJohan Hedberg struct delayed_work discov_off; 24816ab91abSJohan Hedberg 2497d78525dSJohan Hedberg struct delayed_work service_cache; 2507d78525dSJohan Hedberg 2516bd32326SVille Tervo struct timer_list cmd_timer; 252b78752ccSMarcel Holtmann 253b78752ccSMarcel Holtmann struct work_struct rx_work; 254c347b765SGustavo F. Padovan struct work_struct cmd_work; 2553eff45eaSGustavo F. Padovan struct work_struct tx_work; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds struct sk_buff_head rx_q; 2581da177e4SLinus Torvalds struct sk_buff_head raw_q; 2591da177e4SLinus Torvalds struct sk_buff_head cmd_q; 2601da177e4SLinus Torvalds 261b6ddb638SJohan Hedberg struct sk_buff *recv_evt; 2621da177e4SLinus Torvalds struct sk_buff *sent_cmd; 263cd4c5391SSuraj Sumangala struct sk_buff *reassembly[NUM_REASSEMBLY]; 2641da177e4SLinus Torvalds 265a6a67efdSThomas Gleixner struct mutex req_lock; 2661da177e4SLinus Torvalds wait_queue_head_t req_wait_q; 2671da177e4SLinus Torvalds __u32 req_status; 2681da177e4SLinus Torvalds __u32 req_result; 269a5040efaSJohan Hedberg 27099780a7bSJohan Hedberg struct crypto_blkcipher *tfm_aes; 2712e58ef3eSJohan Hedberg 27230883512SJohan Hedberg struct discovery_state discovery; 2731da177e4SLinus Torvalds struct hci_conn_hash conn_hash; 2745c136e90SAndre Guedes 2755c136e90SAndre Guedes struct list_head mgmt_pending; 276ea4bd8baSDavid Miller struct list_head blacklist; 2772aeb9a1aSJohan Hedberg struct list_head uuids; 27855ed8ca1SJohan Hedberg struct list_head link_keys; 279b899efafSVinicius Costa Gomes struct list_head long_term_keys; 280970c4e46SJohan Hedberg struct list_head identity_resolving_keys; 2812763eda6SSzymon Janc struct list_head remote_oob_data; 28215819a70SAndre Guedes struct list_head le_conn_params; 2832763eda6SSzymon Janc 2841da177e4SLinus Torvalds struct hci_dev_stats stat; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds atomic_t promisc; 2871da177e4SLinus Torvalds 288ca325f69SMarcel Holtmann struct dentry *debugfs; 289ca325f69SMarcel Holtmann 290a91f2e39SMarcel Holtmann struct device dev; 2911da177e4SLinus Torvalds 292611b30f7SMarcel Holtmann struct rfkill *rfkill; 293611b30f7SMarcel Holtmann 294d23264a8SAndre Guedes unsigned long dev_flags; 295d23264a8SAndre Guedes 2967ba8b4beSAndre Guedes struct delayed_work le_scan_disable; 2977ba8b4beSAndre Guedes 2988fa19098SJohan Hedberg __s8 adv_tx_power; 2993f0f524bSJohan Hedberg __u8 adv_data[HCI_MAX_AD_LENGTH]; 3003f0f524bSJohan Hedberg __u8 adv_data_len; 301f8e808bdSMarcel Holtmann __u8 scan_rsp_data[HCI_MAX_AD_LENGTH]; 302f8e808bdSMarcel Holtmann __u8 scan_rsp_data_len; 3038fa19098SJohan Hedberg 3041da177e4SLinus Torvalds int (*open)(struct hci_dev *hdev); 3051da177e4SLinus Torvalds int (*close)(struct hci_dev *hdev); 3061da177e4SLinus Torvalds int (*flush)(struct hci_dev *hdev); 307f41c70c4SMarcel Holtmann int (*setup)(struct hci_dev *hdev); 3087bd8f09fSMarcel Holtmann int (*send)(struct hci_dev *hdev, struct sk_buff *skb); 3091da177e4SLinus Torvalds void (*notify)(struct hci_dev *hdev, unsigned int evt); 3101da177e4SLinus Torvalds }; 3111da177e4SLinus Torvalds 31253502d69SAndrei Emeltchenko #define HCI_PHY_HANDLE(handle) (handle & 0xff) 31353502d69SAndrei Emeltchenko 3141da177e4SLinus Torvalds struct hci_conn { 3151da177e4SLinus Torvalds struct list_head list; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds atomic_t refcnt; 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds bdaddr_t dst; 32029b7988aSAndre Guedes __u8 dst_type; 321662e8820SMarcel Holtmann bdaddr_t src; 322e7c4096eSMarcel Holtmann __u8 src_type; 3231da177e4SLinus Torvalds __u16 handle; 3241da177e4SLinus Torvalds __u16 state; 32504837f64SMarcel Holtmann __u8 mode; 3261da177e4SLinus Torvalds __u8 type; 327a0c808b3SJohan Hedberg bool out; 3284c67bc74SMarcel Holtmann __u8 attempt; 3291da177e4SLinus Torvalds __u8 dev_class[3]; 330cad718edSJohan Hedberg __u8 features[HCI_MAX_PAGES][8]; 331a8746417SMarcel Holtmann __u16 pkt_type; 33204837f64SMarcel Holtmann __u16 link_policy; 3331da177e4SLinus Torvalds __u32 link_mode; 33413d39315SWaldemar Rymarkiewicz __u8 key_type; 33540be492fSMarcel Holtmann __u8 auth_type; 3368c1b2355SMarcel Holtmann __u8 sec_level; 337765c2a96SJohan Hedberg __u8 pending_sec_level; 338980e1a53SJohan Hedberg __u8 pin_length; 339726b4ffcSVinicius Costa Gomes __u8 enc_key_size; 34017fa4b9dSJohan Hedberg __u8 io_capability; 34192a25256SJohan Hedberg __u32 passkey_notify; 34292a25256SJohan Hedberg __u8 passkey_entered; 343052b30b0SMarcel Holtmann __u16 disc_timeout; 34410c62ddcSFrédéric Dalleau __u16 setting; 3451e406eefSAndre Guedes __u16 le_conn_min_interval; 3461e406eefSAndre Guedes __u16 le_conn_max_interval; 34751a8efd7SJohan Hedberg unsigned long flags; 3481da177e4SLinus Torvalds 34903b555e1SJohan Hedberg __u8 remote_cap; 35003b555e1SJohan Hedberg __u8 remote_auth; 3513161ae1cSAndrei Emeltchenko __u8 remote_id; 3526ec5bcadSVishal Agarwal bool flush_key; 35303b555e1SJohan Hedberg 3541da177e4SLinus Torvalds unsigned int sent; 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvalds struct sk_buff_head data_q; 3572c33c06aSGustavo F. Padovan struct list_head chan_list; 3581da177e4SLinus Torvalds 35919c40e3bSGustavo F. Padovan struct delayed_work disc_work; 3607bc18d9dSJohan Hedberg struct delayed_work auto_accept_work; 361a74a84f6SJohan Hedberg struct delayed_work idle_work; 3621da177e4SLinus Torvalds 363b219e3acSMarcel Holtmann struct device dev; 364b219e3acSMarcel Holtmann 3651da177e4SLinus Torvalds struct hci_dev *hdev; 3661da177e4SLinus Torvalds void *l2cap_data; 3671da177e4SLinus Torvalds void *sco_data; 3682b64d153SBrian Gix void *smp_conn; 3699740e49dSAndrei Emeltchenko struct amp_mgr *amp_mgr; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds struct hci_conn *link; 372e9a416b5SJohan Hedberg 373e9a416b5SJohan Hedberg void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); 374e9a416b5SJohan Hedberg void (*security_cfm_cb) (struct hci_conn *conn, u8 status); 375e9a416b5SJohan Hedberg void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason); 3761da177e4SLinus Torvalds }; 3771da177e4SLinus Torvalds 37873d80debSLuiz Augusto von Dentz struct hci_chan { 37973d80debSLuiz Augusto von Dentz struct list_head list; 38042c4e53eSAndrei Emeltchenko __u16 handle; 38173d80debSLuiz Augusto von Dentz struct hci_conn *conn; 38273d80debSLuiz Augusto von Dentz struct sk_buff_head data_q; 38373d80debSLuiz Augusto von Dentz unsigned int sent; 384168df8e5SMat Martineau __u8 state; 38573d80debSLuiz Augusto von Dentz }; 38673d80debSLuiz Augusto von Dentz 38715819a70SAndre Guedes struct hci_conn_params { 38815819a70SAndre Guedes struct list_head list; 38915819a70SAndre Guedes 39015819a70SAndre Guedes bdaddr_t addr; 39115819a70SAndre Guedes u8 addr_type; 39215819a70SAndre Guedes 39315819a70SAndre Guedes u16 conn_min_interval; 39415819a70SAndre Guedes u16 conn_max_interval; 39515819a70SAndre Guedes }; 39615819a70SAndre Guedes 3971da177e4SLinus Torvalds extern struct list_head hci_dev_list; 3981da177e4SLinus Torvalds extern struct list_head hci_cb_list; 3991da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock; 4001da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock; 4011da177e4SLinus Torvalds 402686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */ 403e74e58f8SJoe Perches int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 404e74e58f8SJoe Perches void l2cap_connect_cfm(struct hci_conn *hcon, u8 status); 405e74e58f8SJoe Perches int l2cap_disconn_ind(struct hci_conn *hcon); 406e74e58f8SJoe Perches void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); 407e74e58f8SJoe Perches int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt); 408e74e58f8SJoe Perches int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); 409686ebf28SUlisses Furquim 410e74e58f8SJoe Perches int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); 411e74e58f8SJoe Perches void sco_connect_cfm(struct hci_conn *hcon, __u8 status); 412e74e58f8SJoe Perches void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason); 413e74e58f8SJoe Perches int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb); 414686ebf28SUlisses Furquim 4151da177e4SLinus Torvalds /* ----- Inquiry cache ----- */ 41670f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 41770f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 4181da177e4SLinus Torvalds 41930883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev) 4201da177e4SLinus Torvalds { 421ff9ef578SJohan Hedberg hdev->discovery.state = DISCOVERY_STOPPED; 42230883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.all); 42330883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.unknown); 42430883512SJohan Hedberg INIT_LIST_HEAD(&hdev->discovery.resolve); 4251da177e4SLinus Torvalds } 4261da177e4SLinus Torvalds 42730dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev); 42830dc78e1SJohan Hedberg 429ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state); 430ff9ef578SJohan Hedberg 4311da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev) 4321da177e4SLinus Torvalds { 43330883512SJohan Hedberg return list_empty(&hdev->discovery.all); 4341da177e4SLinus Torvalds } 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev) 4371da177e4SLinus Torvalds { 43830883512SJohan Hedberg struct discovery_state *c = &hdev->discovery; 4391da177e4SLinus Torvalds return jiffies - c->timestamp; 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e) 4431da177e4SLinus Torvalds { 4441da177e4SLinus Torvalds return jiffies - e->timestamp; 4451da177e4SLinus Torvalds } 4461da177e4SLinus Torvalds 4475a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 4485a9d0a3fSWaldemar Rymarkiewicz bdaddr_t *bdaddr); 449561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 450561aafbcSJohan Hedberg bdaddr_t *bdaddr); 45130dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 45230dc78e1SJohan Hedberg bdaddr_t *bdaddr, 45330dc78e1SJohan Hedberg int state); 454a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 455a3d4e20aSJohan Hedberg struct inquiry_entry *ie); 4563175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 457388fc8faSJohan Hedberg bool name_known, bool *ssp); 4581f9b9a5dSAndre Guedes void hci_inquiry_cache_flush(struct hci_dev *hdev); 4591da177e4SLinus Torvalds 4601da177e4SLinus Torvalds /* ----- HCI Connections ----- */ 4611da177e4SLinus Torvalds enum { 4621da177e4SLinus Torvalds HCI_CONN_AUTH_PEND, 46319f8def0SWaldemar Rymarkiewicz HCI_CONN_REAUTH_PEND, 4641da177e4SLinus Torvalds HCI_CONN_ENCRYPT_PEND, 46504837f64SMarcel Holtmann HCI_CONN_RSWITCH_PEND, 46604837f64SMarcel Holtmann HCI_CONN_MODE_CHANGE_PEND, 467e73439d8SMarcel Holtmann HCI_CONN_SCO_SETUP_PEND, 468d26a2345SVinicius Costa Gomes HCI_CONN_LE_SMP_PEND, 469b644ba33SJohan Hedberg HCI_CONN_MGMT_CONNECTED, 47058a681efSJohan Hedberg HCI_CONN_SSP_ENABLED, 471eb9a8f3fSMarcel Holtmann HCI_CONN_SC_ENABLED, 472abf76badSMarcel Holtmann HCI_CONN_AES_CCM, 47358a681efSJohan Hedberg HCI_CONN_POWER_SAVE, 47458a681efSJohan Hedberg HCI_CONN_REMOTE_OOB, 47518722c24SJukka Rissanen HCI_CONN_6LOWPAN, 4761da177e4SLinus Torvalds }; 4771da177e4SLinus Torvalds 478aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 479aa64a8b5SJohan Hedberg { 480aa64a8b5SJohan Hedberg struct hci_dev *hdev = conn->hdev; 481c3c7ea65SGustavo Padovan return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && 482c3c7ea65SGustavo Padovan test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); 483aa64a8b5SJohan Hedberg } 484aa64a8b5SJohan Hedberg 485eb9a8f3fSMarcel Holtmann static inline bool hci_conn_sc_enabled(struct hci_conn *conn) 486eb9a8f3fSMarcel Holtmann { 487eb9a8f3fSMarcel Holtmann struct hci_dev *hdev = conn->hdev; 488eb9a8f3fSMarcel Holtmann return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && 489eb9a8f3fSMarcel Holtmann test_bit(HCI_CONN_SC_ENABLED, &conn->flags); 490eb9a8f3fSMarcel Holtmann } 491eb9a8f3fSMarcel Holtmann 4921da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) 4931da177e4SLinus Torvalds { 4941da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 495bf4c6325SGustavo F. Padovan list_add_rcu(&c->list, &h->list); 496fcd89c09SVille Tervo switch (c->type) { 497fcd89c09SVille Tervo case ACL_LINK: 4981da177e4SLinus Torvalds h->acl_num++; 499fcd89c09SVille Tervo break; 500bd1eb66bSAndrei Emeltchenko case AMP_LINK: 501bd1eb66bSAndrei Emeltchenko h->amp_num++; 502bd1eb66bSAndrei Emeltchenko break; 503fcd89c09SVille Tervo case LE_LINK: 504fcd89c09SVille Tervo h->le_num++; 505fcd89c09SVille Tervo break; 506fcd89c09SVille Tervo case SCO_LINK: 507fcd89c09SVille Tervo case ESCO_LINK: 5081da177e4SLinus Torvalds h->sco_num++; 509fcd89c09SVille Tervo break; 510fcd89c09SVille Tervo } 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) 5141da177e4SLinus Torvalds { 5151da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 516bf4c6325SGustavo F. Padovan 517bf4c6325SGustavo F. Padovan list_del_rcu(&c->list); 518bf4c6325SGustavo F. Padovan synchronize_rcu(); 519bf4c6325SGustavo F. Padovan 520fcd89c09SVille Tervo switch (c->type) { 521fcd89c09SVille Tervo case ACL_LINK: 5221da177e4SLinus Torvalds h->acl_num--; 523fcd89c09SVille Tervo break; 524bd1eb66bSAndrei Emeltchenko case AMP_LINK: 525bd1eb66bSAndrei Emeltchenko h->amp_num--; 526bd1eb66bSAndrei Emeltchenko break; 527fcd89c09SVille Tervo case LE_LINK: 528fcd89c09SVille Tervo h->le_num--; 529fcd89c09SVille Tervo break; 530fcd89c09SVille Tervo case SCO_LINK: 531fcd89c09SVille Tervo case ESCO_LINK: 5321da177e4SLinus Torvalds h->sco_num--; 533fcd89c09SVille Tervo break; 534fcd89c09SVille Tervo } 5351da177e4SLinus Torvalds } 5361da177e4SLinus Torvalds 53752087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) 53852087a79SLuiz Augusto von Dentz { 53952087a79SLuiz Augusto von Dentz struct hci_conn_hash *h = &hdev->conn_hash; 54052087a79SLuiz Augusto von Dentz switch (type) { 54152087a79SLuiz Augusto von Dentz case ACL_LINK: 54252087a79SLuiz Augusto von Dentz return h->acl_num; 543bd1eb66bSAndrei Emeltchenko case AMP_LINK: 544bd1eb66bSAndrei Emeltchenko return h->amp_num; 54552087a79SLuiz Augusto von Dentz case LE_LINK: 54652087a79SLuiz Augusto von Dentz return h->le_num; 54752087a79SLuiz Augusto von Dentz case SCO_LINK: 54852087a79SLuiz Augusto von Dentz case ESCO_LINK: 54952087a79SLuiz Augusto von Dentz return h->sco_num; 55052087a79SLuiz Augusto von Dentz default: 55152087a79SLuiz Augusto von Dentz return 0; 55252087a79SLuiz Augusto von Dentz } 55352087a79SLuiz Augusto von Dentz } 55452087a79SLuiz Augusto von Dentz 5551da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 5561da177e4SLinus Torvalds __u16 handle) 5571da177e4SLinus Torvalds { 5581da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 5591da177e4SLinus Torvalds struct hci_conn *c; 5601da177e4SLinus Torvalds 561bf4c6325SGustavo F. Padovan rcu_read_lock(); 562bf4c6325SGustavo F. Padovan 563bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 564bf4c6325SGustavo F. Padovan if (c->handle == handle) { 565bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5661da177e4SLinus Torvalds return c; 5671da177e4SLinus Torvalds } 568bf4c6325SGustavo F. Padovan } 569bf4c6325SGustavo F. Padovan rcu_read_unlock(); 570bf4c6325SGustavo F. Padovan 5711da177e4SLinus Torvalds return NULL; 5721da177e4SLinus Torvalds } 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, 5751da177e4SLinus Torvalds __u8 type, bdaddr_t *ba) 5761da177e4SLinus Torvalds { 5771da177e4SLinus Torvalds struct hci_conn_hash *h = &hdev->conn_hash; 5781da177e4SLinus Torvalds struct hci_conn *c; 5791da177e4SLinus Torvalds 580bf4c6325SGustavo F. Padovan rcu_read_lock(); 581bf4c6325SGustavo F. Padovan 582bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 583bf4c6325SGustavo F. Padovan if (c->type == type && !bacmp(&c->dst, ba)) { 584bf4c6325SGustavo F. Padovan rcu_read_unlock(); 5851da177e4SLinus Torvalds return c; 5861da177e4SLinus Torvalds } 587bf4c6325SGustavo F. Padovan } 588bf4c6325SGustavo F. Padovan 589bf4c6325SGustavo F. Padovan rcu_read_unlock(); 590bf4c6325SGustavo F. Padovan 5911da177e4SLinus Torvalds return NULL; 5921da177e4SLinus Torvalds } 5931da177e4SLinus Torvalds 5944c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, 5954c67bc74SMarcel Holtmann __u8 type, __u16 state) 5964c67bc74SMarcel Holtmann { 5974c67bc74SMarcel Holtmann struct hci_conn_hash *h = &hdev->conn_hash; 5984c67bc74SMarcel Holtmann struct hci_conn *c; 5994c67bc74SMarcel Holtmann 600bf4c6325SGustavo F. Padovan rcu_read_lock(); 601bf4c6325SGustavo F. Padovan 602bf4c6325SGustavo F. Padovan list_for_each_entry_rcu(c, &h->list, list) { 603bf4c6325SGustavo F. Padovan if (c->type == type && c->state == state) { 604bf4c6325SGustavo F. Padovan rcu_read_unlock(); 6054c67bc74SMarcel Holtmann return c; 6064c67bc74SMarcel Holtmann } 607bf4c6325SGustavo F. Padovan } 608bf4c6325SGustavo F. Padovan 609bf4c6325SGustavo F. Padovan rcu_read_unlock(); 610bf4c6325SGustavo F. Padovan 6114c67bc74SMarcel Holtmann return NULL; 6124c67bc74SMarcel Holtmann } 6134c67bc74SMarcel Holtmann 614bed71748SAndre Guedes void hci_disconnect(struct hci_conn *conn, __u8 reason); 6152dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle); 616e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status); 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst); 6191da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn); 6201da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev); 621a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev); 6221da177e4SLinus Torvalds 62373d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn); 6249472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan); 6252c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn); 62642c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); 62773d80debSLuiz Augusto von Dentz 6285a9d0a3fSWaldemar Rymarkiewicz struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, 629b12f62cfSAndre Guedes __u8 dst_type, __u8 sec_level, __u8 auth_type); 63010c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, 63110c62ddcSFrédéric Dalleau __u16 setting); 632e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn); 633b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); 6340684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); 6351da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn); 6368c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role); 6371da177e4SLinus Torvalds 63814b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); 6391da177e4SLinus Torvalds 6408d12356fSDavid Herrmann /* 6418d12356fSDavid Herrmann * hci_conn_get() and hci_conn_put() are used to control the life-time of an 6428d12356fSDavid Herrmann * "hci_conn" object. They do not guarantee that the hci_conn object is running, 6438d12356fSDavid Herrmann * working or anything else. They just guarantee that the object is available 6448d12356fSDavid Herrmann * and can be dereferenced. So you can use its locks, local variables and any 6458d12356fSDavid Herrmann * other constant data. 6468d12356fSDavid Herrmann * Before accessing runtime data, you _must_ lock the object and then check that 6478d12356fSDavid Herrmann * it is still running. As soon as you release the locks, the connection might 6488d12356fSDavid Herrmann * get dropped, though. 6498d12356fSDavid Herrmann * 6508d12356fSDavid Herrmann * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control 6518d12356fSDavid Herrmann * how long the underlying connection is held. So every channel that runs on the 6528d12356fSDavid Herrmann * hci_conn object calls this to prevent the connection from disappearing. As 6538d12356fSDavid Herrmann * long as you hold a device, you must also guarantee that you have a valid 6548d12356fSDavid Herrmann * reference to the device via hci_conn_get() (or the initial reference from 6558d12356fSDavid Herrmann * hci_conn_add()). 6568d12356fSDavid Herrmann * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't 6578d12356fSDavid Herrmann * break because nobody cares for that. But this means, we cannot use 6588d12356fSDavid Herrmann * _get()/_drop() in it, but require the caller to have a valid ref (FIXME). 6598d12356fSDavid Herrmann */ 6608d12356fSDavid Herrmann 6618d12356fSDavid Herrmann static inline void hci_conn_get(struct hci_conn *conn) 6628d12356fSDavid Herrmann { 6638d12356fSDavid Herrmann get_device(&conn->dev); 6648d12356fSDavid Herrmann } 6658d12356fSDavid Herrmann 6668d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn) 6678d12356fSDavid Herrmann { 6688d12356fSDavid Herrmann put_device(&conn->dev); 6698d12356fSDavid Herrmann } 6708d12356fSDavid Herrmann 6711da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn) 6721da177e4SLinus Torvalds { 67371becf0cSAndrei Emeltchenko BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 67438b3fef1SAndrei Emeltchenko 6751da177e4SLinus Torvalds atomic_inc(&conn->refcnt); 6762f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 6771da177e4SLinus Torvalds } 6781da177e4SLinus Torvalds 67976a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn) 6801da177e4SLinus Torvalds { 68171becf0cSAndrei Emeltchenko BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 68238b3fef1SAndrei Emeltchenko 6831da177e4SLinus Torvalds if (atomic_dec_and_test(&conn->refcnt)) { 68404837f64SMarcel Holtmann unsigned long timeo; 685716e4ab5SAndrei Emeltchenko 686716e4ab5SAndrei Emeltchenko switch (conn->type) { 687716e4ab5SAndrei Emeltchenko case ACL_LINK: 688716e4ab5SAndrei Emeltchenko case LE_LINK: 689a74a84f6SJohan Hedberg cancel_delayed_work(&conn->idle_work); 6906ac59344SMarcel Holtmann if (conn->state == BT_CONNECTED) { 6915f246e89SAndrei Emeltchenko timeo = conn->disc_timeout; 69204837f64SMarcel Holtmann if (!conn->out) 693052b30b0SMarcel Holtmann timeo *= 2; 6945a9d0a3fSWaldemar Rymarkiewicz } else { 6956ac59344SMarcel Holtmann timeo = msecs_to_jiffies(10); 6965a9d0a3fSWaldemar Rymarkiewicz } 697716e4ab5SAndrei Emeltchenko break; 698716e4ab5SAndrei Emeltchenko 699716e4ab5SAndrei Emeltchenko case AMP_LINK: 700716e4ab5SAndrei Emeltchenko timeo = conn->disc_timeout; 701716e4ab5SAndrei Emeltchenko break; 702716e4ab5SAndrei Emeltchenko 703716e4ab5SAndrei Emeltchenko default: 70404837f64SMarcel Holtmann timeo = msecs_to_jiffies(10); 705716e4ab5SAndrei Emeltchenko break; 7065a9d0a3fSWaldemar Rymarkiewicz } 707716e4ab5SAndrei Emeltchenko 7082f304d1eSAndre Guedes cancel_delayed_work(&conn->disc_work); 70919c40e3bSGustavo F. Padovan queue_delayed_work(conn->hdev->workqueue, 7101931782bSVinicius Costa Gomes &conn->disc_work, timeo); 7111da177e4SLinus Torvalds } 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds /* ----- HCI Devices ----- */ 715dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d) 7161da177e4SLinus Torvalds { 717376261aeSAndrei Emeltchenko BT_DBG("%s orig refcnt %d", d->name, 718376261aeSAndrei Emeltchenko atomic_read(&d->dev.kobj.kref.refcount)); 719376261aeSAndrei Emeltchenko 7204c724c71SDavid Herrmann put_device(&d->dev); 721010666a1SDavid Herrmann } 7221da177e4SLinus Torvalds 723dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) 7241da177e4SLinus Torvalds { 725376261aeSAndrei Emeltchenko BT_DBG("%s orig refcnt %d", d->name, 726376261aeSAndrei Emeltchenko atomic_read(&d->dev.kobj.kref.refcount)); 727376261aeSAndrei Emeltchenko 7284c724c71SDavid Herrmann get_device(&d->dev); 7291da177e4SLinus Torvalds return d; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 73209fd0de5SGustavo F. Padovan #define hci_dev_lock(d) mutex_lock(&d->lock) 73309fd0de5SGustavo F. Padovan #define hci_dev_unlock(d) mutex_unlock(&d->lock) 7341da177e4SLinus Torvalds 735aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev) 7363dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev) 737aa2b86d7SDavid Herrmann 738155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev) 739155961e8SDavid Herrmann { 740155961e8SDavid Herrmann return dev_get_drvdata(&hdev->dev); 741155961e8SDavid Herrmann } 742155961e8SDavid Herrmann 743155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) 744155961e8SDavid Herrmann { 745155961e8SDavid Herrmann dev_set_drvdata(&hdev->dev, data); 746155961e8SDavid Herrmann } 747155961e8SDavid Herrmann 7481da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index); 7490c0afedfSJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src); 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void); 7521da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev); 7531da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev); 75459735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev); 7551da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev); 7561da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev); 7571da177e4SLinus Torvalds int hci_dev_open(__u16 dev); 7581da177e4SLinus Torvalds int hci_dev_close(__u16 dev); 7591da177e4SLinus Torvalds int hci_dev_reset(__u16 dev); 7601da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev); 7611da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg); 7621da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg); 7631da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg); 7641da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg); 7651da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); 76640be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); 7671da177e4SLinus Torvalds int hci_inquiry(void __user *arg); 7681da177e4SLinus Torvalds 769c3c7ea65SGustavo Padovan struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, 770b9ee0a78SMarcel Holtmann bdaddr_t *bdaddr, u8 type); 771f0358568SJohan Hedberg int hci_blacklist_clear(struct hci_dev *hdev); 77288c1fe4bSJohan Hedberg int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 77388c1fe4bSJohan Hedberg int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 774f0358568SJohan Hedberg 77515819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, 77615819a70SAndre Guedes bdaddr_t *addr, u8 addr_type); 77715819a70SAndre Guedes void hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type, 77815819a70SAndre Guedes u16 conn_min_interval, u16 conn_max_interval); 77915819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); 78015819a70SAndre Guedes void hci_conn_params_clear(struct hci_dev *hdev); 78115819a70SAndre Guedes 7822aeb9a1aSJohan Hedberg int hci_uuids_clear(struct hci_dev *hdev); 7832aeb9a1aSJohan Hedberg 78455ed8ca1SJohan Hedberg int hci_link_keys_clear(struct hci_dev *hdev); 78555ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 786d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 787d25e28abSJohan Hedberg bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len); 78898a0b845SJohan Hedberg struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8], 78998a0b845SJohan Hedberg bool master); 790c9839a11SVinicius Costa Gomes int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type, 7919a006657SAndrei Emeltchenko int new_key, u8 authenticated, u8 tk[16], u8 enc_size, 7929a006657SAndrei Emeltchenko __le16 ediv, u8 rand[8]); 793c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 79498a0b845SJohan Hedberg u8 addr_type, bool master); 795b899efafSVinicius Costa Gomes int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr); 796b899efafSVinicius Costa Gomes int hci_smp_ltks_clear(struct hci_dev *hdev); 79755ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 79855ed8ca1SJohan Hedberg 799970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa); 800970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 801970c4e46SJohan Hedberg u8 addr_type); 802970c4e46SJohan Hedberg int hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, 803970c4e46SJohan Hedberg u8 val[16], bdaddr_t *rpa); 804970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev); 805970c4e46SJohan Hedberg 8062763eda6SSzymon Janc int hci_remote_oob_data_clear(struct hci_dev *hdev); 8072763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 8082763eda6SSzymon Janc bdaddr_t *bdaddr); 8090798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 8100798872eSMarcel Holtmann u8 *hash, u8 *randomizer); 8110798872eSMarcel Holtmann int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 8120798872eSMarcel Holtmann u8 *hash192, u8 *randomizer192, 8130798872eSMarcel Holtmann u8 *hash256, u8 *randomizer256); 8142763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); 8152763eda6SSzymon Janc 8161da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); 8171da177e4SLinus Torvalds 818e1a26170SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb); 819ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count); 82099811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count); 821ef222013SMarcel Holtmann 8220ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev); 823a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn); 824b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn); 825b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn); 8261da177e4SLinus Torvalds 8276935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) 8281da177e4SLinus Torvalds 8291da177e4SLinus Torvalds /* ----- LMP capabilities ----- */ 830cad718edSJohan Hedberg #define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT) 831cad718edSJohan Hedberg #define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH) 832cad718edSJohan Hedberg #define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD) 833cad718edSJohan Hedberg #define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF) 834cad718edSJohan Hedberg #define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK) 835cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ) 836cad718edSJohan Hedberg #define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO) 837cad718edSJohan Hedberg #define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR)) 838cad718edSJohan Hedberg #define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE) 839cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR) 840cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC) 841cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ) 842cad718edSJohan Hedberg #define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR)) 843cad718edSJohan Hedberg #define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR) 844cad718edSJohan Hedberg #define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH) 845cad718edSJohan Hedberg #define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO) 846cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR) 847cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES) 84807a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT) 8491da177e4SLinus Torvalds 850eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */ 85153b834d2SMarcel Holtmann #define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER) 85253b834d2SMarcel Holtmann #define lmp_csb_slave_capable(dev) ((dev)->features[2][0] & LMP_CSB_SLAVE) 85353b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN) 85453b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev) ((dev)->features[2][0] & LMP_SYNC_SCAN) 855d5991585SMarcel Holtmann #define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC) 856d5991585SMarcel Holtmann #define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING) 85753b834d2SMarcel Holtmann 85853b834d2SMarcel Holtmann /* ----- Host capabilities ----- */ 859cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP) 860d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev) ((dev)->features[1][0] & LMP_HOST_SC) 861cad718edSJohan Hedberg #define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE)) 862cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR)) 863eead27daSAndre Guedes 8641da177e4SLinus Torvalds /* ----- HCI protocols ----- */ 86520714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER 0x01 86620714bfeSFrédéric Dalleau 8675a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 86820714bfeSFrédéric Dalleau __u8 type, __u8 *flags) 8691da177e4SLinus Torvalds { 870686ebf28SUlisses Furquim switch (type) { 871686ebf28SUlisses Furquim case ACL_LINK: 872686ebf28SUlisses Furquim return l2cap_connect_ind(hdev, bdaddr); 8731da177e4SLinus Torvalds 874686ebf28SUlisses Furquim case SCO_LINK: 875686ebf28SUlisses Furquim case ESCO_LINK: 87620714bfeSFrédéric Dalleau return sco_connect_ind(hdev, bdaddr, flags); 8771da177e4SLinus Torvalds 878686ebf28SUlisses Furquim default: 879686ebf28SUlisses Furquim BT_ERR("unknown link type %d", type); 880686ebf28SUlisses Furquim return -EINVAL; 881686ebf28SUlisses Furquim } 8821da177e4SLinus Torvalds } 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status) 8851da177e4SLinus Torvalds { 886686ebf28SUlisses Furquim switch (conn->type) { 887686ebf28SUlisses Furquim case ACL_LINK: 888686ebf28SUlisses Furquim case LE_LINK: 889686ebf28SUlisses Furquim l2cap_connect_cfm(conn, status); 890686ebf28SUlisses Furquim break; 8911da177e4SLinus Torvalds 892686ebf28SUlisses Furquim case SCO_LINK: 893686ebf28SUlisses Furquim case ESCO_LINK: 894686ebf28SUlisses Furquim sco_connect_cfm(conn, status); 895686ebf28SUlisses Furquim break; 8961da177e4SLinus Torvalds 897686ebf28SUlisses Furquim default: 898686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 899686ebf28SUlisses Furquim break; 900686ebf28SUlisses Furquim } 901e9a416b5SJohan Hedberg 902e9a416b5SJohan Hedberg if (conn->connect_cfm_cb) 903e9a416b5SJohan Hedberg conn->connect_cfm_cb(conn, status); 9041da177e4SLinus Torvalds } 9051da177e4SLinus Torvalds 9062950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn) 9072950f21aSMarcel Holtmann { 908686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 909686ebf28SUlisses Furquim return HCI_ERROR_REMOTE_USER_TERM; 9102950f21aSMarcel Holtmann 911686ebf28SUlisses Furquim return l2cap_disconn_ind(conn); 9122950f21aSMarcel Holtmann } 9132950f21aSMarcel Holtmann 9142950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason) 9151da177e4SLinus Torvalds { 916686ebf28SUlisses Furquim switch (conn->type) { 917686ebf28SUlisses Furquim case ACL_LINK: 918686ebf28SUlisses Furquim case LE_LINK: 919686ebf28SUlisses Furquim l2cap_disconn_cfm(conn, reason); 920686ebf28SUlisses Furquim break; 9211da177e4SLinus Torvalds 922686ebf28SUlisses Furquim case SCO_LINK: 923686ebf28SUlisses Furquim case ESCO_LINK: 924686ebf28SUlisses Furquim sco_disconn_cfm(conn, reason); 925686ebf28SUlisses Furquim break; 9261da177e4SLinus Torvalds 927bd1eb66bSAndrei Emeltchenko /* L2CAP would be handled for BREDR chan */ 928bd1eb66bSAndrei Emeltchenko case AMP_LINK: 929bd1eb66bSAndrei Emeltchenko break; 930bd1eb66bSAndrei Emeltchenko 931686ebf28SUlisses Furquim default: 932686ebf28SUlisses Furquim BT_ERR("unknown link type %d", conn->type); 933686ebf28SUlisses Furquim break; 934686ebf28SUlisses Furquim } 935e9a416b5SJohan Hedberg 936e9a416b5SJohan Hedberg if (conn->disconn_cfm_cb) 937e9a416b5SJohan Hedberg conn->disconn_cfm_cb(conn, reason); 9381da177e4SLinus Torvalds } 9391da177e4SLinus Torvalds 9401da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status) 9411da177e4SLinus Torvalds { 9428c1b2355SMarcel Holtmann __u8 encrypt; 9438c1b2355SMarcel Holtmann 944686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 945686ebf28SUlisses Furquim return; 946686ebf28SUlisses Furquim 94751a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 9488c1b2355SMarcel Holtmann return; 9498c1b2355SMarcel Holtmann 9508c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 951686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 952e9a416b5SJohan Hedberg 953e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 954e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 9551da177e4SLinus Torvalds } 9561da177e4SLinus Torvalds 9575a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, 9585a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 9591da177e4SLinus Torvalds { 960686ebf28SUlisses Furquim if (conn->type != ACL_LINK && conn->type != LE_LINK) 961686ebf28SUlisses Furquim return; 9621da177e4SLinus Torvalds 963686ebf28SUlisses Furquim l2cap_security_cfm(conn, status, encrypt); 964e9a416b5SJohan Hedberg 965e9a416b5SJohan Hedberg if (conn->security_cfm_cb) 966e9a416b5SJohan Hedberg conn->security_cfm_cb(conn, status); 9671da177e4SLinus Torvalds } 9681da177e4SLinus Torvalds 9691da177e4SLinus Torvalds /* ----- HCI callbacks ----- */ 9701da177e4SLinus Torvalds struct hci_cb { 9711da177e4SLinus Torvalds struct list_head list; 9721da177e4SLinus Torvalds 9731da177e4SLinus Torvalds char *name; 9741da177e4SLinus Torvalds 9755a9d0a3fSWaldemar Rymarkiewicz void (*security_cfm) (struct hci_conn *conn, __u8 status, 9765a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt); 9771da177e4SLinus Torvalds void (*key_change_cfm) (struct hci_conn *conn, __u8 status); 9781da177e4SLinus Torvalds void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); 9791da177e4SLinus Torvalds }; 9801da177e4SLinus Torvalds 9811da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) 9821da177e4SLinus Torvalds { 983711584eaSDenis Kirjanov struct hci_cb *cb; 9848c1b2355SMarcel Holtmann __u8 encrypt; 9851da177e4SLinus Torvalds 9861da177e4SLinus Torvalds hci_proto_auth_cfm(conn, status); 9871da177e4SLinus Torvalds 98851a8efd7SJohan Hedberg if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 9898c1b2355SMarcel Holtmann return; 9908c1b2355SMarcel Holtmann 9918c1b2355SMarcel Holtmann encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00; 9928c1b2355SMarcel Holtmann 993f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 994711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 9958c1b2355SMarcel Holtmann if (cb->security_cfm) 9968c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 9971da177e4SLinus Torvalds } 998f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 10015a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, 10025a9d0a3fSWaldemar Rymarkiewicz __u8 encrypt) 10031da177e4SLinus Torvalds { 1004711584eaSDenis Kirjanov struct hci_cb *cb; 10051da177e4SLinus Torvalds 1006435fef20SMarcel Holtmann if (conn->sec_level == BT_SECURITY_SDP) 1007435fef20SMarcel Holtmann conn->sec_level = BT_SECURITY_LOW; 1008435fef20SMarcel Holtmann 100988167aedSVinicius Costa Gomes if (conn->pending_sec_level > conn->sec_level) 101088167aedSVinicius Costa Gomes conn->sec_level = conn->pending_sec_level; 101188167aedSVinicius Costa Gomes 10129719f8afSMarcel Holtmann hci_proto_encrypt_cfm(conn, status, encrypt); 10131da177e4SLinus Torvalds 1014f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1015711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10168c1b2355SMarcel Holtmann if (cb->security_cfm) 10178c1b2355SMarcel Holtmann cb->security_cfm(conn, status, encrypt); 10181da177e4SLinus Torvalds } 1019f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) 10231da177e4SLinus Torvalds { 1024711584eaSDenis Kirjanov struct hci_cb *cb; 10251da177e4SLinus Torvalds 1026f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1027711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10281da177e4SLinus Torvalds if (cb->key_change_cfm) 10291da177e4SLinus Torvalds cb->key_change_cfm(conn, status); 10301da177e4SLinus Torvalds } 1031f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10321da177e4SLinus Torvalds } 10331da177e4SLinus Torvalds 10345a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, 10355a9d0a3fSWaldemar Rymarkiewicz __u8 role) 10361da177e4SLinus Torvalds { 1037711584eaSDenis Kirjanov struct hci_cb *cb; 10381da177e4SLinus Torvalds 1039f20d09d5SGustavo F. Padovan read_lock(&hci_cb_list_lock); 1040711584eaSDenis Kirjanov list_for_each_entry(cb, &hci_cb_list, list) { 10411da177e4SLinus Torvalds if (cb->role_switch_cfm) 10421da177e4SLinus Torvalds cb->role_switch_cfm(conn, status, role); 10431da177e4SLinus Torvalds } 1044f20d09d5SGustavo F. Padovan read_unlock(&hci_cb_list_lock); 10451da177e4SLinus Torvalds } 10461da177e4SLinus Torvalds 10476759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) 10486759a675SJohan Hedberg { 104984d9d071SJohan Hedberg size_t parsed = 0; 10506759a675SJohan Hedberg 10516c0c331eSJohan Hedberg if (data_len < 2) 10526c0c331eSJohan Hedberg return false; 10536c0c331eSJohan Hedberg 105484d9d071SJohan Hedberg while (parsed < data_len - 1) { 105584d9d071SJohan Hedberg u8 field_len = data[0]; 10566759a675SJohan Hedberg 10576759a675SJohan Hedberg if (field_len == 0) 10586759a675SJohan Hedberg break; 10596759a675SJohan Hedberg 10606759a675SJohan Hedberg parsed += field_len + 1; 10616759a675SJohan Hedberg 10626759a675SJohan Hedberg if (parsed > data_len) 10636759a675SJohan Hedberg break; 10646759a675SJohan Hedberg 10656759a675SJohan Hedberg if (data[1] == type) 10666759a675SJohan Hedberg return true; 10676759a675SJohan Hedberg 10686759a675SJohan Hedberg data += field_len + 1; 10696759a675SJohan Hedberg } 10706759a675SJohan Hedberg 10716759a675SJohan Hedberg return false; 10726759a675SJohan Hedberg } 10736759a675SJohan Hedberg 10741da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb); 10751da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb); 10761da177e4SLinus Torvalds 10773119ae95SJohan Hedberg struct hci_request { 10783119ae95SJohan Hedberg struct hci_dev *hdev; 10793119ae95SJohan Hedberg struct sk_buff_head cmd_q; 10805d73e034SAndre Guedes 10815d73e034SAndre Guedes /* If something goes wrong when building the HCI request, the error 10825d73e034SAndre Guedes * value is stored in this field. 10835d73e034SAndre Guedes */ 10845d73e034SAndre Guedes int err; 10853119ae95SJohan Hedberg }; 10863119ae95SJohan Hedberg 10873119ae95SJohan Hedberg void hci_req_init(struct hci_request *req, struct hci_dev *hdev); 10883119ae95SJohan Hedberg int hci_req_run(struct hci_request *req, hci_req_complete_t complete); 108907dc93ddSJohan Hedberg void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, 109007dc93ddSJohan Hedberg const void *param); 109107dc93ddSJohan Hedberg void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, 109207dc93ddSJohan Hedberg const void *param, u8 event); 10939238f36aSJohan Hedberg void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status); 10943119ae95SJohan Hedberg 109575e84b7cSJohan Hedberg struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, 109607dc93ddSJohan Hedberg const void *param, u32 timeout); 10977b1abbbeSJohan Hedberg struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, 109807dc93ddSJohan Hedberg const void *param, u8 event, u32 timeout); 109975e84b7cSJohan Hedberg 110007dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, 110107dc93ddSJohan Hedberg const void *param); 110273d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 11030d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 11041da177e4SLinus Torvalds 1105a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); 11061da177e4SLinus Torvalds 11071da177e4SLinus Torvalds /* ----- HCI Sockets ----- */ 1108470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); 1109470fe1b5SMarcel Holtmann void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk); 1110cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); 11111da177e4SLinus Torvalds 1112040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event); 1113040030efSMarcel Holtmann 11140381101fSJohan Hedberg /* Management interface */ 1115591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR)) 1116591f47f3SAndre Guedes #define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \ 1117591f47f3SAndre Guedes BIT(BDADDR_LE_RANDOM)) 1118591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \ 1119591f47f3SAndre Guedes BIT(BDADDR_LE_PUBLIC) | \ 1120591f47f3SAndre Guedes BIT(BDADDR_LE_RANDOM)) 1121f39799f5SAndre Guedes 11220d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General 11230d8cc935SAndre Guedes * Discovery Procedure specification. 11240d8cc935SAndre Guedes */ 11250d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN 0x12 11260d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT 0x12 11270d8cc935SAndre Guedes #define DISCOV_LE_TIMEOUT msecs_to_jiffies(10240) 11280d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_TIMEOUT msecs_to_jiffies(5120) 11290d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04 11300d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN 0x08 11310d8cc935SAndre Guedes 11320381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); 1133bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev); 1134bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev); 11353eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err); 1136744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered); 1137d1967ff8SMarcel Holtmann void mgmt_discoverable_timeout(struct hci_dev *hdev); 113886a75645SMarcel Holtmann void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); 1139a330916cSMarcel Holtmann void mgmt_connectable(struct hci_dev *hdev, u8 connectable); 11404796e8afSMarcel Holtmann void mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 1141dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 1142745c0ce3SVishal Agarwal bool persistent); 1143ecd90ae7SMarcel Holtmann void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 114404124681SGustavo F. Padovan u8 addr_type, u32 flags, u8 *name, u8 name_len, 114504124681SGustavo F. Padovan u8 *dev_class); 11469b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 1147f0d6a0eaSMikel Astiz u8 link_type, u8 addr_type, u8 reason); 11487892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 114988c3df13SJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1150445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 115148264f06SJohan Hedberg u8 addr_type, u8 status); 1152ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 1153e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1154c35938b2SSzymon Janc u8 status); 11553eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1156744cf19eSJohan Hedberg u8 status); 1157744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1158272d90dfSJohan Hedberg u8 link_type, u8 addr_type, __le32 value, 1159272d90dfSJohan Hedberg u8 confirm_hint); 1160744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1161272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1162272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1163272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1164272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1165272d90dfSJohan Hedberg u8 link_type, u8 addr_type); 1166604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1167272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 1168272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1169272d90dfSJohan Hedberg u8 link_type, u8 addr_type, u8 status); 117092a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, 117192a25256SJohan Hedberg u8 link_type, u8 addr_type, u32 passkey, 117292a25256SJohan Hedberg u8 entered); 1173e546099cSMarcel Holtmann void mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1174bab73cb6SJohan Hedberg u8 addr_type, u8 status); 1175464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); 11763e248560SMarcel Holtmann void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 1177eac83dc6SMarcel Holtmann void mgmt_sc_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); 11784e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 11797f9a903cSMarcel Holtmann u8 status); 11807667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 11814d2d2796SMarcel Holtmann void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192, 11824d2d2796SMarcel Holtmann u8 *randomizer192, u8 *hash256, 11834d2d2796SMarcel Holtmann u8 *randomizer256, u8 status); 1184901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 118504124681SGustavo F. Padovan u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, 118604124681SGustavo F. Padovan u8 ssp, u8 *eir, u16 eir_len); 11879cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1188b644ba33SJohan Hedberg u8 addr_type, s8 rssi, u8 *name, u8 name_len); 11892f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering); 119088c1fe4bSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 119188c1fe4bSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 1192083368f7SMarcel Holtmann void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent); 11935976e608SMarcel Holtmann void mgmt_reenable_advertising(struct hci_dev *hdev); 1194346af67bSVinicius Costa Gomes 11951da177e4SLinus Torvalds /* HCI info for socket */ 11961da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk) 11971da177e4SLinus Torvalds 11981da177e4SLinus Torvalds struct hci_pinfo { 11991da177e4SLinus Torvalds struct bt_sock bt; 12001da177e4SLinus Torvalds struct hci_dev *hdev; 12011da177e4SLinus Torvalds struct hci_filter filter; 12021da177e4SLinus Torvalds __u32 cmsg_mask; 1203c02178d2SJohan Hedberg unsigned short channel; 12041da177e4SLinus Torvalds }; 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds /* HCI security filter */ 12071da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF 5 12081da177e4SLinus Torvalds 12091da177e4SLinus Torvalds struct hci_sec_filter { 12101da177e4SLinus Torvalds __u32 type_mask; 12111da177e4SLinus Torvalds __u32 event_mask[2]; 12121da177e4SLinus Torvalds __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4]; 12131da177e4SLinus Torvalds }; 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds /* ----- HCI requests ----- */ 12161da177e4SLinus Torvalds #define HCI_REQ_DONE 0 12171da177e4SLinus Torvalds #define HCI_REQ_PEND 1 12181da177e4SLinus Torvalds #define HCI_REQ_CANCELED 2 12191da177e4SLinus Torvalds 1220a6a67efdSThomas Gleixner #define hci_req_lock(d) mutex_lock(&d->req_lock) 1221a6a67efdSThomas Gleixner #define hci_req_unlock(d) mutex_unlock(&d->req_lock) 12221da177e4SLinus Torvalds 12232ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, 12242ce603ebSClaudio Takahasi u16 latency, u16 to_multiplier); 1225a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8], 1226a7a595f6SVinicius Costa Gomes __u8 ltk[16]); 12272519a1fcSAndre Guedes 12285d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK 0x0003 12295d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD 0x0000 12305d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP 0x0003 12315d4d62f6SFrédéric Dalleau 12321da177e4SLinus Torvalds #endif /* __HCI_CORE_H */ 1233