xref: /linux/include/net/bluetooth/hci_sync.h (revision 1a371190a375f98c9b106f758ea41558c3f92556)
16a98e383SMarcel Holtmann /* SPDX-License-Identifier: GPL-2.0 */
26a98e383SMarcel Holtmann /*
36a98e383SMarcel Holtmann  * BlueZ - Bluetooth protocol stack for Linux
46a98e383SMarcel Holtmann  *
56a98e383SMarcel Holtmann  * Copyright (C) 2021 Intel Corporation
66a98e383SMarcel Holtmann  */
76a98e383SMarcel Holtmann 
8a1f6c3aeSLuiz Augusto von Dentz #define UINT_PTR(_handle)		((void *)((uintptr_t)_handle))
9a1f6c3aeSLuiz Augusto von Dentz #define PTR_UINT(_ptr)			((uintptr_t)((void *)_ptr))
10a1f6c3aeSLuiz Augusto von Dentz 
11f2d89775SLuiz Augusto von Dentz #define HCI_REQ_DONE	  0
12f2d89775SLuiz Augusto von Dentz #define HCI_REQ_PEND	  1
13f2d89775SLuiz Augusto von Dentz #define HCI_REQ_CANCELED  2
14f2d89775SLuiz Augusto von Dentz 
15f2d89775SLuiz Augusto von Dentz #define hci_req_sync_lock(hdev)   mutex_lock(&hdev->req_lock)
16f2d89775SLuiz Augusto von Dentz #define hci_req_sync_unlock(hdev) mutex_unlock(&hdev->req_lock)
17f2d89775SLuiz Augusto von Dentz 
18f2d89775SLuiz Augusto von Dentz struct hci_request {
19f2d89775SLuiz Augusto von Dentz 	struct hci_dev		*hdev;
20f2d89775SLuiz Augusto von Dentz 	struct sk_buff_head	cmd_q;
21f2d89775SLuiz Augusto von Dentz 
22f2d89775SLuiz Augusto von Dentz 	/* If something goes wrong when building the HCI request, the error
23f2d89775SLuiz Augusto von Dentz 	 * value is stored in this field.
24f2d89775SLuiz Augusto von Dentz 	 */
25f2d89775SLuiz Augusto von Dentz 	int			err;
26f2d89775SLuiz Augusto von Dentz };
27f2d89775SLuiz Augusto von Dentz 
286a98e383SMarcel Holtmann typedef int (*hci_cmd_sync_work_func_t)(struct hci_dev *hdev, void *data);
296a98e383SMarcel Holtmann typedef void (*hci_cmd_sync_work_destroy_t)(struct hci_dev *hdev, void *data,
306a98e383SMarcel Holtmann 					    int err);
316a98e383SMarcel Holtmann 
326a98e383SMarcel Holtmann struct hci_cmd_sync_work_entry {
336a98e383SMarcel Holtmann 	struct list_head list;
346a98e383SMarcel Holtmann 	hci_cmd_sync_work_func_t func;
356a98e383SMarcel Holtmann 	void *data;
366a98e383SMarcel Holtmann 	hci_cmd_sync_work_destroy_t destroy;
376a98e383SMarcel Holtmann };
386a98e383SMarcel Holtmann 
393fe318eeSBrian Gix struct adv_info;
40176cbeceSLuiz Augusto von Dentz 
41176cbeceSLuiz Augusto von Dentz struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, u32 plen,
42176cbeceSLuiz Augusto von Dentz 				   const void *param, struct sock *sk);
43176cbeceSLuiz Augusto von Dentz 
446a98e383SMarcel Holtmann /* Function with sync suffix shall not be called with hdev->lock held as they
456a98e383SMarcel Holtmann  * wait the command to complete and in the meantime an event could be received
466a98e383SMarcel Holtmann  * which could attempt to acquire hdev->lock causing a deadlock.
476a98e383SMarcel Holtmann  */
486a98e383SMarcel Holtmann struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
496a98e383SMarcel Holtmann 			       const void *param, u32 timeout);
506a98e383SMarcel Holtmann struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
516a98e383SMarcel Holtmann 			     const void *param, u32 timeout);
526a98e383SMarcel Holtmann struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
536a98e383SMarcel Holtmann 				  const void *param, u8 event, u32 timeout);
546a98e383SMarcel Holtmann struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
556a98e383SMarcel Holtmann 				  const void *param, u8 event, u32 timeout,
566a98e383SMarcel Holtmann 				  struct sock *sk);
576a98e383SMarcel Holtmann int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
586a98e383SMarcel Holtmann 			  const void *param, u32 timeout);
596a98e383SMarcel Holtmann int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen,
606a98e383SMarcel Holtmann 			     const void *param, u8 event, u32 timeout,
616a98e383SMarcel Holtmann 			     struct sock *sk);
62f1a8f402SLuiz Augusto von Dentz int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen,
63f1a8f402SLuiz Augusto von Dentz 			const void *param, u32 timeout);
646a98e383SMarcel Holtmann 
656a98e383SMarcel Holtmann void hci_cmd_sync_init(struct hci_dev *hdev);
666a98e383SMarcel Holtmann void hci_cmd_sync_clear(struct hci_dev *hdev);
67914b08b3SBenjamin Berg void hci_cmd_sync_cancel(struct hci_dev *hdev, int err);
6863298d6eSLuiz Augusto von Dentz void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err);
696a98e383SMarcel Holtmann 
70d883a466SLuiz Augusto von Dentz int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
71d883a466SLuiz Augusto von Dentz 			void *data, hci_cmd_sync_work_destroy_t destroy);
726a98e383SMarcel Holtmann int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
736a98e383SMarcel Holtmann 		       void *data, hci_cmd_sync_work_destroy_t destroy);
74881559afSLuiz Augusto von Dentz int hci_cmd_sync_queue_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
75881559afSLuiz Augusto von Dentz 			    void *data, hci_cmd_sync_work_destroy_t destroy);
76*c898f6d7SLuiz Augusto von Dentz int hci_cmd_sync_run(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
77*c898f6d7SLuiz Augusto von Dentz 		     void *data, hci_cmd_sync_work_destroy_t destroy);
78*c898f6d7SLuiz Augusto von Dentz int hci_cmd_sync_run_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
79*c898f6d7SLuiz Augusto von Dentz 			  void *data, hci_cmd_sync_work_destroy_t destroy);
80505ea2b2SLuiz Augusto von Dentz struct hci_cmd_sync_work_entry *
81505ea2b2SLuiz Augusto von Dentz hci_cmd_sync_lookup_entry(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
82505ea2b2SLuiz Augusto von Dentz 			  void *data, hci_cmd_sync_work_destroy_t destroy);
83505ea2b2SLuiz Augusto von Dentz void hci_cmd_sync_cancel_entry(struct hci_dev *hdev,
84505ea2b2SLuiz Augusto von Dentz 			       struct hci_cmd_sync_work_entry *entry);
85505ea2b2SLuiz Augusto von Dentz bool hci_cmd_sync_dequeue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func,
86505ea2b2SLuiz Augusto von Dentz 			  void *data, hci_cmd_sync_work_destroy_t destroy);
87505ea2b2SLuiz Augusto von Dentz bool hci_cmd_sync_dequeue_once(struct hci_dev *hdev,
88505ea2b2SLuiz Augusto von Dentz 			      hci_cmd_sync_work_func_t func, void *data,
89505ea2b2SLuiz Augusto von Dentz 			      hci_cmd_sync_work_destroy_t destroy);
90161510ccSLuiz Augusto von Dentz 
91161510ccSLuiz Augusto von Dentz int hci_update_eir_sync(struct hci_dev *hdev);
92161510ccSLuiz Augusto von Dentz int hci_update_class_sync(struct hci_dev *hdev);
93cba6b758SLuiz Augusto von Dentz 
94cba6b758SLuiz Augusto von Dentz int hci_update_eir_sync(struct hci_dev *hdev);
95cba6b758SLuiz Augusto von Dentz int hci_update_class_sync(struct hci_dev *hdev);
966f6ff38aSBrian Gix int hci_update_name_sync(struct hci_dev *hdev);
973244845cSBrian Gix int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode);
98cba6b758SLuiz Augusto von Dentz 
993fe318eeSBrian Gix int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
1003fe318eeSBrian Gix 			   bool use_rpa, struct adv_info *adv_instance,
1013fe318eeSBrian Gix 			   u8 *own_addr_type, bdaddr_t *rand_addr);
1023fe318eeSBrian Gix 
103cba6b758SLuiz Augusto von Dentz int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy,
104cba6b758SLuiz Augusto von Dentz 				   bool rpa, u8 *own_addr_type);
105cba6b758SLuiz Augusto von Dentz 
106cba6b758SLuiz Augusto von Dentz int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance);
107cba6b758SLuiz Augusto von Dentz int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance);
108651cd3d6SBrian Gix int hci_update_adv_data(struct hci_dev *hdev, u8 instance);
109cba6b758SLuiz Augusto von Dentz int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
110cba6b758SLuiz Augusto von Dentz 				   bool force);
111cba6b758SLuiz Augusto von Dentz 
112cba6b758SLuiz Augusto von Dentz int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance);
113cba6b758SLuiz Augusto von Dentz int hci_start_ext_adv_sync(struct hci_dev *hdev, u8 instance);
114cba6b758SLuiz Augusto von Dentz int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance);
115cba6b758SLuiz Augusto von Dentz int hci_enable_advertising_sync(struct hci_dev *hdev);
116abfeea47SLuiz Augusto von Dentz int hci_enable_advertising(struct hci_dev *hdev);
117cba6b758SLuiz Augusto von Dentz 
118eca0ae4aSLuiz Augusto von Dentz int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len,
119eca0ae4aSLuiz Augusto von Dentz 			   u8 *data, u32 flags, u16 min_interval,
120eca0ae4aSLuiz Augusto von Dentz 			   u16 max_interval, u16 sync_interval);
121eca0ae4aSLuiz Augusto von Dentz 
122a254b90cSIulia Tanasescu int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance);
123a254b90cSIulia Tanasescu 
124cba6b758SLuiz Augusto von Dentz int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk,
125cba6b758SLuiz Augusto von Dentz 				u8 instance, bool force);
126cba6b758SLuiz Augusto von Dentz int hci_disable_advertising_sync(struct hci_dev *hdev);
127c249ea9bSBrian Gix int hci_clear_adv_instance_sync(struct hci_dev *hdev, struct sock *sk,
128c249ea9bSBrian Gix 				u8 instance, bool force);
129e8907f76SLuiz Augusto von Dentz int hci_update_passive_scan_sync(struct hci_dev *hdev);
130ad383c2cSLuiz Augusto von Dentz int hci_update_passive_scan(struct hci_dev *hdev);
13147db6b42SBrian Gix int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle);
13247db6b42SBrian Gix int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type);
1332f2eb0c9SBrian Gix int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val);
1345a750137SBrian Gix int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp);
135cf75ad8bSLuiz Augusto von Dentz 
136353a0249SBrian Gix int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable);
137451d95a9SBrian Gix int hci_update_scan_sync(struct hci_dev *hdev);
138bb876725SBrian Gix int hci_update_scan(struct hci_dev *hdev);
139353a0249SBrian Gix 
140d81a494cSBrian Gix int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul);
141d81a494cSBrian Gix int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
142d81a494cSBrian Gix 				     struct sock *sk);
143eca0ae4aSLuiz Augusto von Dentz int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance);
144f892244bSBrian Gix struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, bool ext,
145f892244bSBrian Gix 					     struct sock *sk);
146d81a494cSBrian Gix 
147d0b13706SLuiz Augusto von Dentz int hci_reset_sync(struct hci_dev *hdev);
148cf75ad8bSLuiz Augusto von Dentz int hci_dev_open_sync(struct hci_dev *hdev);
149cf75ad8bSLuiz Augusto von Dentz int hci_dev_close_sync(struct hci_dev *hdev);
150cf75ad8bSLuiz Augusto von Dentz 
151cf75ad8bSLuiz Augusto von Dentz int hci_powered_update_sync(struct hci_dev *hdev);
152cf75ad8bSLuiz Augusto von Dentz int hci_set_powered_sync(struct hci_dev *hdev, u8 val);
153abfeea47SLuiz Augusto von Dentz 
1542bd1b237SLuiz Augusto von Dentz int hci_update_discoverable_sync(struct hci_dev *hdev);
1552bd1b237SLuiz Augusto von Dentz int hci_update_discoverable(struct hci_dev *hdev);
1562bd1b237SLuiz Augusto von Dentz 
157f056a657SLuiz Augusto von Dentz int hci_update_connectable_sync(struct hci_dev *hdev);
158f056a657SLuiz Augusto von Dentz 
15992048ab2SLuiz Augusto von Dentz int hci_inquiry_sync(struct hci_dev *hdev, u8 length, u8 num_rsp);
16092048ab2SLuiz Augusto von Dentz 
161abfeea47SLuiz Augusto von Dentz int hci_start_discovery_sync(struct hci_dev *hdev);
162abfeea47SLuiz Augusto von Dentz int hci_stop_discovery_sync(struct hci_dev *hdev);
163182ee45dSLuiz Augusto von Dentz 
164182ee45dSLuiz Augusto von Dentz int hci_suspend_sync(struct hci_dev *hdev);
165182ee45dSLuiz Augusto von Dentz int hci_resume_sync(struct hci_dev *hdev);
1668e8b92eeSLuiz Augusto von Dentz 
1678e8b92eeSLuiz Augusto von Dentz struct hci_conn;
1680ece498cSLuiz Augusto von Dentz struct hci_conn_params;
1698e8b92eeSLuiz Augusto von Dentz 
1701f7435c8SLuiz Augusto von Dentz int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason);
1711f7435c8SLuiz Augusto von Dentz 
1727f74563eSPauli Virtanen int hci_le_create_cis_sync(struct hci_dev *hdev);
173c09b80beSLuiz Augusto von Dentz 
17426afbd82SLuiz Augusto von Dentz int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle);
175eca0ae4aSLuiz Augusto von Dentz 
176eca0ae4aSLuiz Augusto von Dentz int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason);
177eca0ae4aSLuiz Augusto von Dentz 
178eca0ae4aSLuiz Augusto von Dentz int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle);
179eca0ae4aSLuiz Augusto von Dentz 
180eca0ae4aSLuiz Augusto von Dentz int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle);
18145340097SJonas Dreßler 
1825f641f03SLuiz Augusto von Dentz int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn);
183881559afSLuiz Augusto von Dentz 
184881559afSLuiz Augusto von Dentz int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn);
185881559afSLuiz Augusto von Dentz 
186881559afSLuiz Augusto von Dentz int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn);
1870ece498cSLuiz Augusto von Dentz int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn,
1880ece498cSLuiz Augusto von Dentz 			    struct hci_conn_params *params);
189