Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)    BlueZ - Bluetooth protocol stack for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)    Copyright (C) 2015  Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)    This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)    it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)    published by the Free Software Foundation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)    SOFTWARE IS DISCLAIMED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <net/bluetooth/hci_mon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <net/bluetooth/mgmt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "mgmt_util.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static struct sk_buff *create_monitor_ctrl_event(__le16 index, u32 cookie,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 						 u16 opcode, u16 len, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct hci_mon_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	skb = bt_skb_alloc(6 + len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	put_unaligned_le32(cookie, skb_put(skb, 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	put_unaligned_le16(opcode, skb_put(skb, 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		skb_put_data(skb, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	__net_timestamp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	hdr = skb_push(skb, HCI_MON_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	hdr->opcode = cpu_to_le16(HCI_MON_CTRL_EVENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	hdr->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	hdr->len = cpu_to_le16(skb->len - HCI_MON_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) int mgmt_send_event(u16 event, struct hci_dev *hdev, unsigned short channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		    void *data, u16 data_len, int flag, struct sock *skip_sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct mgmt_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	skb = alloc_skb(sizeof(*hdr) + data_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	hdr = skb_put(skb, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	hdr->opcode = cpu_to_le16(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		hdr->index = cpu_to_le16(hdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		hdr->index = cpu_to_le16(MGMT_INDEX_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	hdr->len = cpu_to_le16(data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		skb_put_data(skb, data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	/* Time stamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	__net_timestamp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	hci_send_to_channel(channel, skb, flag, skip_sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (channel == HCI_CHANNEL_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		hci_send_monitor_ctrl_event(hdev, event, data, data_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 					    skb_get_ktime(skb), flag, skip_sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) int mgmt_cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct sk_buff *skb, *mskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct mgmt_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct mgmt_ev_cmd_status *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	BT_DBG("sock %p, index %u, cmd %u, status %u", sk, index, cmd, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	skb = alloc_skb(sizeof(*hdr) + sizeof(*ev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	hdr = skb_put(skb, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	hdr->opcode = cpu_to_le16(MGMT_EV_CMD_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	hdr->index = cpu_to_le16(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	hdr->len = cpu_to_le16(sizeof(*ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	ev = skb_put(skb, sizeof(*ev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ev->status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ev->opcode = cpu_to_le16(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	mskb = create_monitor_ctrl_event(hdr->index, hci_sock_get_cookie(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					 MGMT_EV_CMD_STATUS, sizeof(*ev), ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (mskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		skb->tstamp = mskb->tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		__net_timestamp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	err = sock_queue_rcv_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (mskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		hci_send_to_channel(HCI_CHANNEL_MONITOR, mskb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				    HCI_SOCK_TRUSTED, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		kfree_skb(mskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int mgmt_cmd_complete(struct sock *sk, u16 index, u16 cmd, u8 status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		      void *rp, size_t rp_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	struct sk_buff *skb, *mskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct mgmt_hdr *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct mgmt_ev_cmd_complete *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	BT_DBG("sock %p", sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	skb = alloc_skb(sizeof(*hdr) + sizeof(*ev) + rp_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	hdr = skb_put(skb, sizeof(*hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	hdr->opcode = cpu_to_le16(MGMT_EV_CMD_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	hdr->index = cpu_to_le16(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	hdr->len = cpu_to_le16(sizeof(*ev) + rp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ev = skb_put(skb, sizeof(*ev) + rp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	ev->opcode = cpu_to_le16(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ev->status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (rp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		memcpy(ev->data, rp, rp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	mskb = create_monitor_ctrl_event(hdr->index, hci_sock_get_cookie(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 					 MGMT_EV_CMD_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 					 sizeof(*ev) + rp_len, ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (mskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		skb->tstamp = mskb->tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		__net_timestamp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	err = sock_queue_rcv_skb(sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (mskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		hci_send_to_channel(HCI_CHANNEL_MONITOR, mskb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				    HCI_SOCK_TRUSTED, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		kfree_skb(mskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct mgmt_pending_cmd *mgmt_pending_find(unsigned short channel, u16 opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					   struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct mgmt_pending_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	list_for_each_entry(cmd, &hdev->mgmt_pending, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (hci_sock_get_channel(cmd->sk) != channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (cmd->opcode == opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			return cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct mgmt_pending_cmd *mgmt_pending_find_data(unsigned short channel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 						u16 opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 						struct hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 						const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct mgmt_pending_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	list_for_each_entry(cmd, &hdev->mgmt_pending, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (cmd->user_data != data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		if (cmd->opcode == opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			return cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			  void (*cb)(struct mgmt_pending_cmd *cmd, void *data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			  void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct mgmt_pending_cmd *cmd, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	list_for_each_entry_safe(cmd, tmp, &hdev->mgmt_pending, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (opcode > 0 && cmd->opcode != opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		cb(cmd, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct mgmt_pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					  struct hci_dev *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 					  void *data, u16 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct mgmt_pending_cmd *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	cmd->opcode = opcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	cmd->index = hdev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	cmd->param = kmemdup(data, len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (!cmd->param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	cmd->param_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	cmd->sk = sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	list_add(&cmd->list, &hdev->mgmt_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) void mgmt_pending_free(struct mgmt_pending_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	sock_put(cmd->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	kfree(cmd->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	kfree(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) void mgmt_pending_remove(struct mgmt_pending_cmd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	list_del(&cmd->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	mgmt_pending_free(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }