📄 hci_core.h
字号:
/* BlueZ - Bluetooth protocol stack for Linux Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS SOFTWARE IS DISCLAIMED.*/#ifndef __HCI_CORE_H#define __HCI_CORE_H#include <net/bluetooth/hci.h>/* HCI upper protocols */#define HCI_PROTO_L2CAP 0#define HCI_PROTO_SCO 1/* HCI Core structures */struct inquiry_data { bdaddr_t bdaddr; __u8 pscan_rep_mode; __u8 pscan_period_mode; __u8 pscan_mode; __u8 dev_class[3]; __le16 clock_offset; __s8 rssi;};struct inquiry_entry { struct inquiry_entry *next; __u32 timestamp; struct inquiry_data data;};struct inquiry_cache { spinlock_t lock; __u32 timestamp; struct inquiry_entry *list;};struct hci_conn_hash { struct list_head list; spinlock_t lock; unsigned int acl_num; unsigned int sco_num;};struct hci_dev { struct list_head list; spinlock_t lock; atomic_t refcnt; char name[8]; unsigned long flags; __u16 id; __u8 type; bdaddr_t bdaddr; __u8 dev_name[248]; __u8 dev_class[3]; __u8 features[8]; __u8 commands[64]; __u8 hci_ver; __u16 hci_rev; __u16 manufacturer; __u16 voice_setting; __u16 pkt_type; __u16 esco_type; __u16 link_policy; __u16 link_mode; __u32 idle_timeout; __u16 sniff_min_interval; __u16 sniff_max_interval; unsigned long quirks; atomic_t cmd_cnt; unsigned int acl_cnt; unsigned int sco_cnt; unsigned int acl_mtu; unsigned int sco_mtu; unsigned int acl_pkts; unsigned int sco_pkts; unsigned long cmd_last_tx; unsigned long acl_last_tx; unsigned long sco_last_tx; struct tasklet_struct cmd_task; struct tasklet_struct rx_task; struct tasklet_struct tx_task; struct sk_buff_head rx_q; struct sk_buff_head raw_q; struct sk_buff_head cmd_q; struct sk_buff *sent_cmd; struct sk_buff *reassembly[3]; struct semaphore req_lock; wait_queue_head_t req_wait_q; __u32 req_status; __u32 req_result; struct inquiry_cache inq_cache; struct hci_conn_hash conn_hash; struct hci_dev_stats stat; struct sk_buff_head driver_init; void *driver_data; void *core_data; atomic_t promisc; struct device *parent; struct device dev; struct module *owner; int (*open)(struct hci_dev *hdev); int (*close)(struct hci_dev *hdev); int (*flush)(struct hci_dev *hdev); int (*send)(struct sk_buff *skb); void (*destruct)(struct hci_dev *hdev); void (*notify)(struct hci_dev *hdev, unsigned int evt); int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);};struct hci_conn { struct list_head list; atomic_t refcnt; spinlock_t lock; bdaddr_t dst; __u16 handle; __u16 state; __u8 mode; __u8 type; __u8 out; __u8 attempt; __u8 dev_class[3]; __u8 features[8]; __u16 interval; __u16 link_policy; __u32 link_mode; __u8 power_save; unsigned long pend; unsigned int sent; struct sk_buff_head data_q; struct timer_list disc_timer; struct timer_list idle_timer; struct work_struct work; struct device dev; struct hci_dev *hdev; void *l2cap_data; void *sco_data; void *priv; struct hci_conn *link;};extern struct hci_proto *hci_proto[];extern struct list_head hci_dev_list;extern struct list_head hci_cb_list;extern rwlock_t hci_dev_list_lock;extern rwlock_t hci_cb_list_lock;/* ----- Inquiry cache ----- */#define INQUIRY_CACHE_AGE_MAX (HZ*30) // 30 seconds#define INQUIRY_ENTRY_AGE_MAX (HZ*60) // 60 seconds#define inquiry_cache_lock(c) spin_lock(&c->lock)#define inquiry_cache_unlock(c) spin_unlock(&c->lock)#define inquiry_cache_lock_bh(c) spin_lock_bh(&c->lock)#define inquiry_cache_unlock_bh(c) spin_unlock_bh(&c->lock)static inline void inquiry_cache_init(struct hci_dev *hdev){ struct inquiry_cache *c = &hdev->inq_cache; spin_lock_init(&c->lock); c->list = NULL;}static inline int inquiry_cache_empty(struct hci_dev *hdev){ struct inquiry_cache *c = &hdev->inq_cache; return (c->list == NULL);}static inline long inquiry_cache_age(struct hci_dev *hdev){ struct inquiry_cache *c = &hdev->inq_cache; return jiffies - c->timestamp;}static inline long inquiry_entry_age(struct inquiry_entry *e){ return jiffies - e->timestamp;}struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data);/* ----- HCI Connections ----- */enum { HCI_CONN_AUTH_PEND, HCI_CONN_ENCRYPT_PEND, HCI_CONN_RSWITCH_PEND, HCI_CONN_MODE_CHANGE_PEND,};static inline void hci_conn_hash_init(struct hci_dev *hdev){ struct hci_conn_hash *h = &hdev->conn_hash; INIT_LIST_HEAD(&h->list); spin_lock_init(&h->lock); h->acl_num = 0; h->sco_num = 0;}static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c){ struct hci_conn_hash *h = &hdev->conn_hash; list_add(&c->list, &h->list); if (c->type == ACL_LINK) h->acl_num++; else h->sco_num++;}static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c){ struct hci_conn_hash *h = &hdev->conn_hash; list_del(&c->list); if (c->type == ACL_LINK) h->acl_num--; else h->sco_num--;}static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, __u16 handle){ struct hci_conn_hash *h = &hdev->conn_hash; struct list_head *p; struct hci_conn *c; list_for_each(p, &h->list) { c = list_entry(p, struct hci_conn, list); if (c->handle == handle) return c; } return NULL;}static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, __u8 type, bdaddr_t *ba){ struct hci_conn_hash *h = &hdev->conn_hash; struct list_head *p; struct hci_conn *c; list_for_each(p, &h->list) { c = list_entry(p, struct hci_conn, list); if (c->type == type && !bacmp(&c->dst, ba)) return c; } return NULL;}static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, __u8 type, __u16 state){ struct hci_conn_hash *h = &hdev->conn_hash; struct list_head *p; struct hci_conn *c; list_for_each(p, &h->list) { c = list_entry(p, struct hci_conn, list); if (c->type == type && c->state == state) return c; } return NULL;}void hci_acl_connect(struct hci_conn *conn);void hci_acl_disconn(struct hci_conn *conn, __u8 reason);void hci_add_sco(struct hci_conn *conn, __u16 handle);void hci_setup_sync(struct hci_conn *conn, __u16 handle);struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);int hci_conn_del(struct hci_conn *conn);void hci_conn_hash_flush(struct hci_dev *hdev);void hci_conn_check_pending(struct hci_dev *hdev);struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *src);int hci_conn_auth(struct hci_conn *conn);int hci_conn_encrypt(struct hci_conn *conn);int hci_conn_change_link_key(struct hci_conn *conn);int hci_conn_switch_role(struct hci_conn *conn, uint8_t role);void hci_conn_enter_active_mode(struct hci_conn *conn);void hci_conn_enter_sniff_mode(struct hci_conn *conn);static inline void hci_conn_hold(struct hci_conn *conn){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -