linux/include/net/bluetooth/bluetooth.h

/*
   BlueZ - Bluetooth protocol stack for Linux
   Copyright (C) 2000-2001 Qualcomm Incorporated
   Copyright 2023 NXP

   Written 2000,2001 by Maxim Krasnyansky <[email protected]>

   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 __BLUETOOTH_H
#define __BLUETOOTH_H

#include <linux/poll.h>
#include <net/sock.h>
#include <linux/seq_file.h>

#define BT_SUBSYS_VERSION
#define BT_SUBSYS_REVISION

#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH
#define PF_BLUETOOTH
#endif

/* Bluetooth versions */
#define BLUETOOTH_VER_1_1
#define BLUETOOTH_VER_1_2
#define BLUETOOTH_VER_2_0
#define BLUETOOTH_VER_2_1
#define BLUETOOTH_VER_4_0

/* Reserv for core and drivers use */
#define BT_SKB_RESERVE

#define BTPROTO_L2CAP
#define BTPROTO_HCI
#define BTPROTO_SCO
#define BTPROTO_RFCOMM
#define BTPROTO_BNEP
#define BTPROTO_CMTP
#define BTPROTO_HIDP
#define BTPROTO_AVDTP
#define BTPROTO_ISO
#define BTPROTO_LAST

#define SOL_HCI
#define SOL_L2CAP
#define SOL_SCO
#define SOL_RFCOMM

#define BT_SECURITY
struct bt_security {};
#define BT_SECURITY_SDP
#define BT_SECURITY_LOW
#define BT_SECURITY_MEDIUM
#define BT_SECURITY_HIGH
#define BT_SECURITY_FIPS

#define BT_DEFER_SETUP

#define BT_FLUSHABLE

#define BT_FLUSHABLE_OFF
#define BT_FLUSHABLE_ON

#define BT_POWER
struct bt_power {};
#define BT_POWER_FORCE_ACTIVE_OFF
#define BT_POWER_FORCE_ACTIVE_ON

#define BT_CHANNEL_POLICY

/* BR/EDR only (default policy)
 *   AMP controllers cannot be used.
 *   Channel move requests from the remote device are denied.
 *   If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
 */
#define BT_CHANNEL_POLICY_BREDR_ONLY

/* BR/EDR Preferred
 *   Allow use of AMP controllers.
 *   If the L2CAP channel is currently on AMP, move it to BR/EDR.
 *   Channel move requests from the remote device are allowed.
 */
#define BT_CHANNEL_POLICY_BREDR_PREFERRED

/* AMP Preferred
 *   Allow use of AMP controllers
 *   If the L2CAP channel is currently on BR/EDR and AMP controller
 *     resources are available, initiate a channel move to AMP.
 *   Channel move requests from the remote device are allowed.
 *   If the L2CAP socket has not been connected yet, try to create
 *     and configure the channel directly on an AMP controller rather
 *     than BR/EDR.
 */
#define BT_CHANNEL_POLICY_AMP_PREFERRED

#define BT_VOICE
struct bt_voice {};

#define BT_VOICE_TRANSPARENT
#define BT_VOICE_CVSD_16BIT

#define BT_SNDMTU
#define BT_RCVMTU
#define BT_PHY

#define BT_PHY_BR_1M_1SLOT
#define BT_PHY_BR_1M_3SLOT
#define BT_PHY_BR_1M_5SLOT
#define BT_PHY_EDR_2M_1SLOT
#define BT_PHY_EDR_2M_3SLOT
#define BT_PHY_EDR_2M_5SLOT
#define BT_PHY_EDR_3M_1SLOT
#define BT_PHY_EDR_3M_3SLOT
#define BT_PHY_EDR_3M_5SLOT
#define BT_PHY_LE_1M_TX
#define BT_PHY_LE_1M_RX
#define BT_PHY_LE_2M_TX
#define BT_PHY_LE_2M_RX
#define BT_PHY_LE_CODED_TX
#define BT_PHY_LE_CODED_RX

#define BT_MODE

#define BT_MODE_BASIC
#define BT_MODE_ERTM
#define BT_MODE_STREAMING
#define BT_MODE_LE_FLOWCTL
#define BT_MODE_EXT_FLOWCTL

#define BT_PKT_STATUS

#define BT_SCM_PKT_STATUS

#define BT_ISO_QOS

#define BT_ISO_QOS_CIG_UNSET
#define BT_ISO_QOS_CIS_UNSET

#define BT_ISO_QOS_BIG_UNSET
#define BT_ISO_QOS_BIS_UNSET

#define BT_ISO_SYNC_TIMEOUT

struct bt_iso_io_qos {};

struct bt_iso_ucast_qos {};

struct bt_iso_bcast_qos {};

struct bt_iso_qos {};

#define BT_ISO_PHY_1M
#define BT_ISO_PHY_2M
#define BT_ISO_PHY_CODED
#define BT_ISO_PHY_ANY

#define BT_CODEC

struct	bt_codec_caps {} __packed;

struct bt_codec {} __packed;

struct bt_codecs {} __packed;

#define BT_CODEC_CVSD
#define BT_CODEC_TRANSPARENT
#define BT_CODEC_MSBC

#define BT_ISO_BASE

__printf(1, 2)
void bt_info(const char *fmt, ...);
__printf(1, 2)
void bt_warn(const char *fmt, ...);
__printf(1, 2)
void bt_err(const char *fmt, ...);
#if IS_ENABLED(CONFIG_BT_FEATURE_DEBUG)
void bt_dbg_set(bool enable);
bool bt_dbg_get(void);
__printf(1, 2)
void bt_dbg(const char *fmt, ...);
#endif
__printf(1, 2)
void bt_warn_ratelimited(const char *fmt, ...);
__printf(1, 2)
void bt_err_ratelimited(const char *fmt, ...);

#define BT_INFO(fmt, ...)
#define BT_WARN(fmt, ...)
#define BT_ERR(fmt, ...)

#if IS_ENABLED(CONFIG_BT_FEATURE_DEBUG)
#define BT_DBG
#else
#define BT_DBG(fmt, ...)
#endif

#define bt_dev_name(hdev)

#define bt_dev_info(hdev, fmt, ...)
#define bt_dev_warn(hdev, fmt, ...)
#define bt_dev_err(hdev, fmt, ...)
#define bt_dev_dbg(hdev, fmt, ...)

#define bt_dev_warn_ratelimited(hdev, fmt, ...)
#define bt_dev_err_ratelimited(hdev, fmt, ...)

/* Connection and socket states */
enum bt_sock_state {};

/* If unused will be removed by compiler */
static inline const char *state_to_string(int state)
{}

/* BD Address */
bdaddr_t;

/* BD Address type */
#define BDADDR_BREDR
#define BDADDR_LE_PUBLIC
#define BDADDR_LE_RANDOM

static inline bool bdaddr_type_is_valid(u8 type)
{}

static inline bool bdaddr_type_is_le(u8 type)
{}

#define BDADDR_ANY
#define BDADDR_NONE

/* Copy, swap, convert BD Address */
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
{}
static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
{}

void baswap(bdaddr_t *dst, const bdaddr_t *src);

/* Common socket structures and functions */

#define bt_sk(__sk)

struct bt_sock {};

enum {};

struct bt_sock_list {};

int  bt_sock_register(int proto, const struct net_proto_family *ops);
void bt_sock_unregister(int proto);
void bt_sock_link(struct bt_sock_list *l, struct sock *s);
void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
struct sock *bt_sock_alloc(struct net *net, struct socket *sock,
			   struct proto *prot, int proto, gfp_t prio, int kern);
int  bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
		     int flags);
int  bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
			    size_t len, int flags);
__poll_t bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
int  bt_sock_wait_ready(struct sock *sk, unsigned int msg_flags);

void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh);
void bt_accept_unlink(struct sock *sk);
struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);

/* Skb helpers */
struct l2cap_ctrl {};

struct hci_dev;

hci_req_complete_t;
hci_req_complete_skb_t;

void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
			  hci_req_complete_t *req_complete,
			  hci_req_complete_skb_t *req_complete_skb);

#define HCI_REQ_START
#define HCI_REQ_SKB

struct hci_ctrl {};

struct mgmt_ctrl {};

struct bt_skb_cb {};
#define bt_cb(skb)

#define hci_skb_pkt_type(skb)
#define hci_skb_pkt_status(skb)
#define hci_skb_expect(skb)
#define hci_skb_opcode(skb)
#define hci_skb_event(skb)
#define hci_skb_sk(skb)

static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
{}

static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
					unsigned long len, int nb, int *err)
{}

/* Shall not be called with lock_sock held */
static inline struct sk_buff *bt_skb_sendmsg(struct sock *sk,
					     struct msghdr *msg,
					     size_t len, size_t mtu,
					     size_t headroom, size_t tailroom)
{}

/* Similar to bt_skb_sendmsg but can split the msg into multiple fragments
 * accourding to the MTU.
 */
static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk,
					      struct msghdr *msg,
					      size_t len, size_t mtu,
					      size_t headroom, size_t tailroom)
{}

static inline int bt_copy_from_sockptr(void *dst, size_t dst_size,
				       sockptr_t src, size_t src_size)
{}

int bt_to_errno(u16 code);
__u8 bt_status(int err);

void hci_sock_set_flag(struct sock *sk, int nr);
void hci_sock_clear_flag(struct sock *sk, int nr);
int hci_sock_test_flag(struct sock *sk, int nr);
unsigned short hci_sock_get_channel(struct sock *sk);
u32 hci_sock_get_cookie(struct sock *sk);

int hci_sock_init(void);
void hci_sock_cleanup(void);

int bt_sysfs_init(void);
void bt_sysfs_cleanup(void);

int bt_procfs_init(struct net *net, const char *name,
		   struct bt_sock_list *sk_list,
		   int (*seq_show)(struct seq_file *, void *));
void bt_procfs_cleanup(struct net *net, const char *name);

extern struct dentry *bt_debugfs;

int l2cap_init(void);
void l2cap_exit(void);

#if IS_ENABLED(CONFIG_BT_BREDR)
int sco_init(void);
void sco_exit(void);
#else
static inline int sco_init(void)
{
	return 0;
}

static inline void sco_exit(void)
{
}
#endif

#if IS_ENABLED(CONFIG_BT_LE)
int iso_init(void);
int iso_exit(void);
bool iso_enabled(void);
#else
static inline int iso_init(void)
{
	return 0;
}

static inline int iso_exit(void)
{
	return 0;
}

static inline bool iso_enabled(void)
{
	return false;
}
#endif

int mgmt_init(void);
void mgmt_exit(void);
void mgmt_cleanup(struct sock *sk);

void bt_sock_reclassify_lock(struct sock *sk, int proto);

#endif /* __BLUETOOTH_H */