blob: a4ff3ea9b38a6e3cfe1a4ea63105458cd07e06a9 [file] [log] [blame]
Andrei Emeltchenko9740e492012-05-29 13:59:02 +03001/*
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
Andrei Emeltchenko97e8e892012-05-29 13:59:17 +030018#include <net/bluetooth/l2cap.h>
19
Andrei Emeltchenkof97268f2012-09-27 17:26:07 +030020enum amp_mgr_state {
21 READ_LOC_AMP_INFO,
Andrei Emeltchenko903e4542012-09-27 17:26:09 +030022 READ_LOC_AMP_ASSOC,
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +030023 READ_LOC_AMP_ASSOC_FINAL,
Andrei Emeltchenko8e05e3b2012-12-07 14:59:05 +020024 WRITE_REMOTE_AMP_ASSOC,
Andrei Emeltchenkof97268f2012-09-27 17:26:07 +030025};
26
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030027struct amp_mgr {
Andrei Emeltchenkof97268f2012-09-27 17:26:07 +030028 struct list_head list;
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030029 struct l2cap_conn *l2cap_conn;
30 struct l2cap_chan *a2mp_chan;
Andrei Emeltchenko93c3e8f2012-09-27 17:26:16 +030031 struct l2cap_chan *bredr_chan;
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030032 struct kref kref;
33 __u8 ident;
34 __u8 handle;
Andrei Emeltchenkocb6801c62012-12-07 14:59:08 +020035 unsigned long state;
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030036 unsigned long flags;
Andrei Emeltchenko52c0d6e2012-09-27 17:26:12 +030037
38 struct list_head amp_ctrls;
39 struct mutex amp_ctrls_lock;
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030040};
41
Andrei Emeltchenkof6d3c6e2012-05-29 13:59:03 +030042struct a2mp_cmd {
43 __u8 code;
44 __u8 ident;
45 __le16 len;
46 __u8 data[0];
47} __packed;
48
Andrei Emeltchenkob9058fb2012-05-29 13:59:05 +030049/* A2MP command codes */
50#define A2MP_COMMAND_REJ 0x01
51struct a2mp_cmd_rej {
52 __le16 reason;
53 __u8 data[0];
54} __packed;
55
56#define A2MP_DISCOVER_REQ 0x02
57struct a2mp_discov_req {
58 __le16 mtu;
59 __le16 ext_feat;
60} __packed;
61
62struct a2mp_cl {
63 __u8 id;
64 __u8 type;
65 __u8 status;
66} __packed;
67
68#define A2MP_DISCOVER_RSP 0x03
69struct a2mp_discov_rsp {
70 __le16 mtu;
71 __le16 ext_feat;
72 struct a2mp_cl cl[0];
73} __packed;
74
75#define A2MP_CHANGE_NOTIFY 0x04
76#define A2MP_CHANGE_RSP 0x05
77
78#define A2MP_GETINFO_REQ 0x06
79struct a2mp_info_req {
80 __u8 id;
81} __packed;
82
83#define A2MP_GETINFO_RSP 0x07
84struct a2mp_info_rsp {
85 __u8 id;
86 __u8 status;
87 __le32 total_bw;
88 __le32 max_bw;
89 __le32 min_latency;
90 __le16 pal_cap;
91 __le16 assoc_size;
92} __packed;
93
94#define A2MP_GETAMPASSOC_REQ 0x08
95struct a2mp_amp_assoc_req {
96 __u8 id;
97} __packed;
98
99#define A2MP_GETAMPASSOC_RSP 0x09
100struct a2mp_amp_assoc_rsp {
101 __u8 id;
102 __u8 status;
103 __u8 amp_assoc[0];
104} __packed;
105
106#define A2MP_CREATEPHYSLINK_REQ 0x0A
107#define A2MP_DISCONNPHYSLINK_REQ 0x0C
108struct a2mp_physlink_req {
109 __u8 local_id;
110 __u8 remote_id;
111 __u8 amp_assoc[0];
112} __packed;
113
114#define A2MP_CREATEPHYSLINK_RSP 0x0B
115#define A2MP_DISCONNPHYSLINK_RSP 0x0D
116struct a2mp_physlink_rsp {
117 __u8 local_id;
118 __u8 remote_id;
119 __u8 status;
120} __packed;
121
Andrei Emeltchenkoe7af522e2012-05-29 13:59:06 +0300122/* A2MP response status */
123#define A2MP_STATUS_SUCCESS 0x00
124#define A2MP_STATUS_INVALID_CTRL_ID 0x01
125#define A2MP_STATUS_UNABLE_START_LINK_CREATION 0x02
126#define A2MP_STATUS_NO_PHYSICAL_LINK_EXISTS 0x02
127#define A2MP_STATUS_COLLISION_OCCURED 0x03
128#define A2MP_STATUS_DISCONN_REQ_RECVD 0x04
129#define A2MP_STATUS_PHYS_LINK_EXISTS 0x05
130#define A2MP_STATUS_SECURITY_VIOLATION 0x06
131
Andrei Emeltchenkof706adf2012-10-18 13:16:19 +0300132struct amp_mgr *amp_mgr_get(struct amp_mgr *mgr);
Arron Wang244bc372015-07-24 17:12:55 +0800133
134#if IS_ENABLED(CONFIG_BT_HS)
Andrei Emeltchenko9740e492012-05-29 13:59:02 +0300135int amp_mgr_put(struct amp_mgr *mgr);
Andrei Emeltchenko97e8e892012-05-29 13:59:17 +0300136struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
137 struct sk_buff *skb);
Andrei Emeltchenko93c3e8f2012-09-27 17:26:16 +0300138void a2mp_discover_amp(struct l2cap_chan *chan);
Arron Wang244bc372015-07-24 17:12:55 +0800139#else
140static inline int amp_mgr_put(struct amp_mgr *mgr)
141{
142 return 0;
143}
144
145static inline struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
146 struct sk_buff *skb)
147{
148 return NULL;
149}
150
151static inline void a2mp_discover_amp(struct l2cap_chan *chan)
152{
153}
154#endif
155
Andrei Emeltchenko8e2a0d92012-09-27 17:26:08 +0300156void a2mp_send_getinfo_rsp(struct hci_dev *hdev);
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300157void a2mp_send_getampassoc_rsp(struct hci_dev *hdev, u8 status);
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +0300158void a2mp_send_create_phy_link_req(struct hci_dev *hdev, u8 status);
Andrei Emeltchenko8e05e3b2012-12-07 14:59:05 +0200159void a2mp_send_create_phy_link_rsp(struct hci_dev *hdev, u8 status);
Andrei Emeltchenko9740e492012-05-29 13:59:02 +0300160
161#endif /* __A2MP_H */