Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved.
4 Copyright (c) 2011,2012 Intel Corp.
5
6*/
7
8#ifndef __A2MP_H
9#define __A2MP_H
10
11#include <net/bluetooth/l2cap.h>
12
13enum amp_mgr_state {
14 READ_LOC_AMP_INFO,
15 READ_LOC_AMP_ASSOC,
16 READ_LOC_AMP_ASSOC_FINAL,
17 WRITE_REMOTE_AMP_ASSOC,
18};
19
20struct amp_mgr {
21 struct list_head list;
22 struct l2cap_conn *l2cap_conn;
23 struct l2cap_chan *a2mp_chan;
24 struct l2cap_chan *bredr_chan;
25 struct kref kref;
26 __u8 ident;
27 __u8 handle;
28 unsigned long state;
29 unsigned long flags;
30
31 struct list_head amp_ctrls;
32 struct mutex amp_ctrls_lock;
33};
34
35struct a2mp_cmd {
36 __u8 code;
37 __u8 ident;
38 __le16 len;
39 __u8 data[];
40} __packed;
41
42/* A2MP command codes */
43#define A2MP_COMMAND_REJ 0x01
44struct a2mp_cmd_rej {
45 __le16 reason;
46 __u8 data[];
47} __packed;
48
49#define A2MP_DISCOVER_REQ 0x02
50struct a2mp_discov_req {
51 __le16 mtu;
52 __le16 ext_feat;
53} __packed;
54
55struct a2mp_cl {
56 __u8 id;
57 __u8 type;
58 __u8 status;
59} __packed;
60
61#define A2MP_DISCOVER_RSP 0x03
62struct a2mp_discov_rsp {
63 __le16 mtu;
64 __le16 ext_feat;
65 struct a2mp_cl cl[];
66} __packed;
67
68#define A2MP_CHANGE_NOTIFY 0x04
69#define A2MP_CHANGE_RSP 0x05
70
71#define A2MP_GETINFO_REQ 0x06
72struct a2mp_info_req {
73 __u8 id;
74} __packed;
75
76#define A2MP_GETINFO_RSP 0x07
77struct a2mp_info_rsp {
78 __u8 id;
79 __u8 status;
80 __le32 total_bw;
81 __le32 max_bw;
82 __le32 min_latency;
83 __le16 pal_cap;
84 __le16 assoc_size;
85} __packed;
86
87#define A2MP_GETAMPASSOC_REQ 0x08
88struct a2mp_amp_assoc_req {
89 __u8 id;
90} __packed;
91
92#define A2MP_GETAMPASSOC_RSP 0x09
93struct a2mp_amp_assoc_rsp {
94 __u8 id;
95 __u8 status;
96 __u8 amp_assoc[];
97} __packed;
98
99#define A2MP_CREATEPHYSLINK_REQ 0x0A
100#define A2MP_DISCONNPHYSLINK_REQ 0x0C
101struct a2mp_physlink_req {
102 __u8 local_id;
103 __u8 remote_id;
104 __u8 amp_assoc[];
105} __packed;
106
107#define A2MP_CREATEPHYSLINK_RSP 0x0B
108#define A2MP_DISCONNPHYSLINK_RSP 0x0D
109struct a2mp_physlink_rsp {
110 __u8 local_id;
111 __u8 remote_id;
112 __u8 status;
113} __packed;
114
115/* A2MP response status */
116#define A2MP_STATUS_SUCCESS 0x00
117#define A2MP_STATUS_INVALID_CTRL_ID 0x01
118#define A2MP_STATUS_UNABLE_START_LINK_CREATION 0x02
119#define A2MP_STATUS_NO_PHYSICAL_LINK_EXISTS 0x02
120#define A2MP_STATUS_COLLISION_OCCURED 0x03
121#define A2MP_STATUS_DISCONN_REQ_RECVD 0x04
122#define A2MP_STATUS_PHYS_LINK_EXISTS 0x05
123#define A2MP_STATUS_SECURITY_VIOLATION 0x06
124
125struct amp_mgr *amp_mgr_get(struct amp_mgr *mgr);
126
127#if IS_ENABLED(CONFIG_BT_HS)
128int amp_mgr_put(struct amp_mgr *mgr);
129struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
130 struct sk_buff *skb);
131void a2mp_discover_amp(struct l2cap_chan *chan);
132#else
133static inline int amp_mgr_put(struct amp_mgr *mgr)
134{
135 return 0;
136}
137
138static inline struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
139 struct sk_buff *skb)
140{
141 return NULL;
142}
143
144static inline void a2mp_discover_amp(struct l2cap_chan *chan)
145{
146}
147#endif
148
149void a2mp_send_getinfo_rsp(struct hci_dev *hdev);
150void a2mp_send_getampassoc_rsp(struct hci_dev *hdev, u8 status);
151void a2mp_send_create_phy_link_req(struct hci_dev *hdev, u8 status);
152void a2mp_send_create_phy_link_rsp(struct hci_dev *hdev, u8 status);
153
154#endif /* __A2MP_H */
1/*
2 Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved.
3 Copyright (c) 2011,2012 Intel Corp.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 and
7 only version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13*/
14
15#ifndef __A2MP_H
16#define __A2MP_H
17
18#include <net/bluetooth/l2cap.h>
19
20#define A2MP_FEAT_EXT 0x8000
21
22enum amp_mgr_state {
23 READ_LOC_AMP_INFO,
24 READ_LOC_AMP_ASSOC,
25 READ_LOC_AMP_ASSOC_FINAL,
26 WRITE_REMOTE_AMP_ASSOC,
27};
28
29struct amp_mgr {
30 struct list_head list;
31 struct l2cap_conn *l2cap_conn;
32 struct l2cap_chan *a2mp_chan;
33 struct l2cap_chan *bredr_chan;
34 struct kref kref;
35 __u8 ident;
36 __u8 handle;
37 unsigned long state;
38 unsigned long flags;
39
40 struct list_head amp_ctrls;
41 struct mutex amp_ctrls_lock;
42};
43
44struct a2mp_cmd {
45 __u8 code;
46 __u8 ident;
47 __le16 len;
48 __u8 data[0];
49} __packed;
50
51/* A2MP command codes */
52#define A2MP_COMMAND_REJ 0x01
53struct a2mp_cmd_rej {
54 __le16 reason;
55 __u8 data[0];
56} __packed;
57
58#define A2MP_DISCOVER_REQ 0x02
59struct a2mp_discov_req {
60 __le16 mtu;
61 __le16 ext_feat;
62} __packed;
63
64struct a2mp_cl {
65 __u8 id;
66 __u8 type;
67 __u8 status;
68} __packed;
69
70#define A2MP_DISCOVER_RSP 0x03
71struct a2mp_discov_rsp {
72 __le16 mtu;
73 __le16 ext_feat;
74 struct a2mp_cl cl[0];
75} __packed;
76
77#define A2MP_CHANGE_NOTIFY 0x04
78#define A2MP_CHANGE_RSP 0x05
79
80#define A2MP_GETINFO_REQ 0x06
81struct a2mp_info_req {
82 __u8 id;
83} __packed;
84
85#define A2MP_GETINFO_RSP 0x07
86struct a2mp_info_rsp {
87 __u8 id;
88 __u8 status;
89 __le32 total_bw;
90 __le32 max_bw;
91 __le32 min_latency;
92 __le16 pal_cap;
93 __le16 assoc_size;
94} __packed;
95
96#define A2MP_GETAMPASSOC_REQ 0x08
97struct a2mp_amp_assoc_req {
98 __u8 id;
99} __packed;
100
101#define A2MP_GETAMPASSOC_RSP 0x09
102struct a2mp_amp_assoc_rsp {
103 __u8 id;
104 __u8 status;
105 __u8 amp_assoc[0];
106} __packed;
107
108#define A2MP_CREATEPHYSLINK_REQ 0x0A
109#define A2MP_DISCONNPHYSLINK_REQ 0x0C
110struct a2mp_physlink_req {
111 __u8 local_id;
112 __u8 remote_id;
113 __u8 amp_assoc[0];
114} __packed;
115
116#define A2MP_CREATEPHYSLINK_RSP 0x0B
117#define A2MP_DISCONNPHYSLINK_RSP 0x0D
118struct a2mp_physlink_rsp {
119 __u8 local_id;
120 __u8 remote_id;
121 __u8 status;
122} __packed;
123
124/* A2MP response status */
125#define A2MP_STATUS_SUCCESS 0x00
126#define A2MP_STATUS_INVALID_CTRL_ID 0x01
127#define A2MP_STATUS_UNABLE_START_LINK_CREATION 0x02
128#define A2MP_STATUS_NO_PHYSICAL_LINK_EXISTS 0x02
129#define A2MP_STATUS_COLLISION_OCCURED 0x03
130#define A2MP_STATUS_DISCONN_REQ_RECVD 0x04
131#define A2MP_STATUS_PHYS_LINK_EXISTS 0x05
132#define A2MP_STATUS_SECURITY_VIOLATION 0x06
133
134extern struct list_head amp_mgr_list;
135extern struct mutex amp_mgr_list_lock;
136
137struct amp_mgr *amp_mgr_get(struct amp_mgr *mgr);
138int amp_mgr_put(struct amp_mgr *mgr);
139u8 __next_ident(struct amp_mgr *mgr);
140struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
141 struct sk_buff *skb);
142struct amp_mgr *amp_mgr_lookup_by_state(u8 state);
143void a2mp_send(struct amp_mgr *mgr, u8 code, u8 ident, u16 len, void *data);
144void a2mp_discover_amp(struct l2cap_chan *chan);
145void a2mp_send_getinfo_rsp(struct hci_dev *hdev);
146void a2mp_send_getampassoc_rsp(struct hci_dev *hdev, u8 status);
147void a2mp_send_create_phy_link_req(struct hci_dev *hdev, u8 status);
148void a2mp_send_create_phy_link_rsp(struct hci_dev *hdev, u8 status);
149
150#endif /* __A2MP_H */