1/*
2 * BT-AMP (BlueTooth Alternate Mac and Phy) HCI (Host/Controller Interface)
3 *
4 * Copyright (C) 1999-2011, Broadcom Corporation
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * $Id: bt_amp_hci.h,v 9.14.8.2 2010-09-10 18:37:47 Exp $
19*/
20
21#ifndef _bt_amp_hci_h
22#define _bt_amp_hci_h
23
24/* This marks the start of a packed structure section. */
25#include <packed_section_start.h>
26
27
28/* AMP HCI CMD packet format */
29typedef BWL_PRE_PACKED_STRUCT struct amp_hci_cmd {
30	uint16 opcode;
31	uint8 plen;
32	uint8 parms[1];
33} BWL_POST_PACKED_STRUCT amp_hci_cmd_t;
34
35#define HCI_CMD_PREAMBLE_SIZE		OFFSETOF(amp_hci_cmd_t, parms)
36#define HCI_CMD_DATA_SIZE		255
37
38/* AMP HCI CMD opcode layout */
39#define HCI_CMD_OPCODE(ogf, ocf)	((((ogf) & 0x3F) << 10) | ((ocf) & 0x03FF))
40#define HCI_CMD_OGF(opcode)		((uint8)(((opcode) >> 10) & 0x3F))
41#define HCI_CMD_OCF(opcode)		((opcode) & 0x03FF)
42
43/* AMP HCI command opcodes */
44#define HCI_Read_Failed_Contact_Counter		HCI_CMD_OPCODE(0x05, 0x0001)
45#define HCI_Reset_Failed_Contact_Counter	HCI_CMD_OPCODE(0x05, 0x0002)
46#define HCI_Read_Link_Quality			HCI_CMD_OPCODE(0x05, 0x0003)
47#define HCI_Read_Local_AMP_Info			HCI_CMD_OPCODE(0x05, 0x0009)
48#define HCI_Read_Local_AMP_ASSOC		HCI_CMD_OPCODE(0x05, 0x000A)
49#define HCI_Write_Remote_AMP_ASSOC		HCI_CMD_OPCODE(0x05, 0x000B)
50#define HCI_Create_Physical_Link		HCI_CMD_OPCODE(0x01, 0x0035)
51#define HCI_Accept_Physical_Link_Request	HCI_CMD_OPCODE(0x01, 0x0036)
52#define HCI_Disconnect_Physical_Link		HCI_CMD_OPCODE(0x01, 0x0037)
53#define HCI_Create_Logical_Link			HCI_CMD_OPCODE(0x01, 0x0038)
54#define HCI_Accept_Logical_Link			HCI_CMD_OPCODE(0x01, 0x0039)
55#define HCI_Disconnect_Logical_Link		HCI_CMD_OPCODE(0x01, 0x003A)
56#define HCI_Logical_Link_Cancel			HCI_CMD_OPCODE(0x01, 0x003B)
57#define HCI_Flow_Spec_Modify			HCI_CMD_OPCODE(0x01, 0x003C)
58#define HCI_Write_Flow_Control_Mode		HCI_CMD_OPCODE(0x01, 0x0067)
59#define HCI_Read_Best_Effort_Flush_Timeout	HCI_CMD_OPCODE(0x01, 0x0069)
60#define HCI_Write_Best_Effort_Flush_Timeout	HCI_CMD_OPCODE(0x01, 0x006A)
61#define HCI_Short_Range_Mode			HCI_CMD_OPCODE(0x01, 0x006B)
62#define HCI_Reset				HCI_CMD_OPCODE(0x03, 0x0003)
63#define HCI_Read_Connection_Accept_Timeout	HCI_CMD_OPCODE(0x03, 0x0015)
64#define HCI_Write_Connection_Accept_Timeout	HCI_CMD_OPCODE(0x03, 0x0016)
65#define HCI_Read_Link_Supervision_Timeout	HCI_CMD_OPCODE(0x03, 0x0036)
66#define HCI_Write_Link_Supervision_Timeout	HCI_CMD_OPCODE(0x03, 0x0037)
67#define HCI_Enhanced_Flush			HCI_CMD_OPCODE(0x03, 0x005F)
68#define HCI_Read_Logical_Link_Accept_Timeout	HCI_CMD_OPCODE(0x03, 0x0061)
69#define HCI_Write_Logical_Link_Accept_Timeout	HCI_CMD_OPCODE(0x03, 0x0062)
70#define HCI_Set_Event_Mask_Page_2		HCI_CMD_OPCODE(0x03, 0x0063)
71#define HCI_Read_Location_Data_Command		HCI_CMD_OPCODE(0x03, 0x0064)
72#define HCI_Write_Location_Data_Command		HCI_CMD_OPCODE(0x03, 0x0065)
73#define HCI_Read_Local_Version_Info		HCI_CMD_OPCODE(0x04, 0x0001)
74#define HCI_Read_Local_Supported_Commands	HCI_CMD_OPCODE(0x04, 0x0002)
75#define HCI_Read_Buffer_Size			HCI_CMD_OPCODE(0x04, 0x0005)
76#define HCI_Read_Data_Block_Size		HCI_CMD_OPCODE(0x04, 0x000A)
77
78/* AMP HCI command parameters */
79typedef BWL_PRE_PACKED_STRUCT struct read_local_cmd_parms {
80	uint8 plh;
81	uint8 offset[2];			/* length so far */
82	uint8 max_remote[2];
83} BWL_POST_PACKED_STRUCT read_local_cmd_parms_t;
84
85typedef BWL_PRE_PACKED_STRUCT struct write_remote_cmd_parms {
86	uint8 plh;
87	uint8 offset[2];
88	uint8 len[2];
89	uint8 frag[1];
90} BWL_POST_PACKED_STRUCT write_remote_cmd_parms_t;
91
92typedef BWL_PRE_PACKED_STRUCT struct phy_link_cmd_parms {
93	uint8 plh;
94	uint8 key_length;
95	uint8 key_type;
96	uint8 key[1];
97} BWL_POST_PACKED_STRUCT phy_link_cmd_parms_t;
98
99typedef BWL_PRE_PACKED_STRUCT struct dis_phy_link_cmd_parms {
100	uint8 plh;
101	uint8 reason;
102} BWL_POST_PACKED_STRUCT dis_phy_link_cmd_parms_t;
103
104typedef BWL_PRE_PACKED_STRUCT struct log_link_cmd_parms {
105	uint8 plh;
106	uint8 txflow[16];
107	uint8 rxflow[16];
108} BWL_POST_PACKED_STRUCT log_link_cmd_parms_t;
109
110typedef BWL_PRE_PACKED_STRUCT struct ext_flow_spec {
111	uint8 id;
112	uint8 service_type;
113	uint8 max_sdu[2];
114	uint8 sdu_ia_time[4];
115	uint8 access_latency[4];
116	uint8 flush_timeout[4];
117} BWL_POST_PACKED_STRUCT ext_flow_spec_t;
118
119typedef BWL_PRE_PACKED_STRUCT struct log_link_cancel_cmd_parms {
120	uint8 plh;
121	uint8 tx_fs_ID;
122} BWL_POST_PACKED_STRUCT log_link_cancel_cmd_parms_t;
123
124typedef BWL_PRE_PACKED_STRUCT struct flow_spec_mod_cmd_parms {
125	uint8 llh[2];
126	uint8 txflow[16];
127	uint8 rxflow[16];
128} BWL_POST_PACKED_STRUCT flow_spec_mod_cmd_parms_t;
129
130typedef BWL_PRE_PACKED_STRUCT struct plh_pad {
131	uint8 plh;
132	uint8 pad;
133} BWL_POST_PACKED_STRUCT plh_pad_t;
134
135typedef BWL_PRE_PACKED_STRUCT union hci_handle {
136	uint16 bredr;
137	plh_pad_t amp;
138} BWL_POST_PACKED_STRUCT hci_handle_t;
139
140typedef BWL_PRE_PACKED_STRUCT struct ls_to_cmd_parms {
141	hci_handle_t handle;
142	uint8 timeout[2];
143} BWL_POST_PACKED_STRUCT ls_to_cmd_parms_t;
144
145typedef BWL_PRE_PACKED_STRUCT struct befto_cmd_parms {
146	uint8 llh[2];
147	uint8 befto[4];
148} BWL_POST_PACKED_STRUCT befto_cmd_parms_t;
149
150typedef BWL_PRE_PACKED_STRUCT struct srm_cmd_parms {
151	uint8 plh;
152	uint8 srm;
153} BWL_POST_PACKED_STRUCT srm_cmd_parms_t;
154
155typedef BWL_PRE_PACKED_STRUCT struct ld_cmd_parms {
156	uint8 ld_aware;
157	uint8 ld[2];
158	uint8 ld_opts;
159	uint8 l_opts;
160} BWL_POST_PACKED_STRUCT ld_cmd_parms_t;
161
162typedef BWL_PRE_PACKED_STRUCT struct eflush_cmd_parms {
163	uint8 llh[2];
164	uint8 packet_type;
165} BWL_POST_PACKED_STRUCT eflush_cmd_parms_t;
166
167/* Generic AMP extended flow spec service types */
168#define EFS_SVCTYPE_NO_TRAFFIC		0
169#define EFS_SVCTYPE_BEST_EFFORT		1
170#define EFS_SVCTYPE_GUARANTEED		2
171
172/* AMP HCI event packet format */
173typedef BWL_PRE_PACKED_STRUCT struct amp_hci_event {
174	uint8 ecode;
175	uint8 plen;
176	uint8 parms[1];
177} BWL_POST_PACKED_STRUCT amp_hci_event_t;
178
179#define HCI_EVT_PREAMBLE_SIZE			OFFSETOF(amp_hci_event_t, parms)
180
181/* AMP HCI event codes */
182#define HCI_Command_Complete			0x0E
183#define HCI_Command_Status			0x0F
184#define HCI_Flush_Occurred			0x11
185#define HCI_Enhanced_Flush_Complete		0x39
186#define HCI_Physical_Link_Complete		0x40
187#define HCI_Channel_Select			0x41
188#define HCI_Disconnect_Physical_Link_Complete	0x42
189#define HCI_Logical_Link_Complete		0x45
190#define HCI_Disconnect_Logical_Link_Complete	0x46
191#define HCI_Flow_Spec_Modify_Complete		0x47
192#define HCI_Number_of_Completed_Data_Blocks	0x48
193#define HCI_Short_Range_Mode_Change_Complete	0x4C
194#define HCI_Status_Change_Event			0x4D
195#define HCI_Vendor_Specific			0xFF
196
197/* AMP HCI event mask bit positions */
198#define HCI_Physical_Link_Complete_Event_Mask			0x0001
199#define HCI_Channel_Select_Event_Mask				0x0002
200#define HCI_Disconnect_Physical_Link_Complete_Event_Mask	0x0004
201#define HCI_Logical_Link_Complete_Event_Mask			0x0020
202#define HCI_Disconnect_Logical_Link_Complete_Event_Mask		0x0040
203#define HCI_Flow_Spec_Modify_Complete_Event_Mask		0x0080
204#define HCI_Number_of_Completed_Data_Blocks_Event_Mask		0x0100
205#define HCI_Short_Range_Mode_Change_Complete_Event_Mask		0x1000
206#define HCI_Status_Change_Event_Mask				0x2000
207#define HCI_All_Event_Mask					0x31e7
208
209/* AMP HCI event parameters */
210typedef BWL_PRE_PACKED_STRUCT struct cmd_status_parms {
211	uint8 status;
212	uint8 cmdpkts;
213	uint16 opcode;
214} BWL_POST_PACKED_STRUCT cmd_status_parms_t;
215
216typedef BWL_PRE_PACKED_STRUCT struct cmd_complete_parms {
217	uint8 cmdpkts;
218	uint16 opcode;
219	uint8 parms[1];
220} BWL_POST_PACKED_STRUCT cmd_complete_parms_t;
221
222typedef BWL_PRE_PACKED_STRUCT struct flush_occurred_evt_parms {
223	uint16 handle;
224} BWL_POST_PACKED_STRUCT flush_occurred_evt_parms_t;
225
226typedef BWL_PRE_PACKED_STRUCT struct write_remote_evt_parms {
227	uint8 status;
228	uint8 plh;
229} BWL_POST_PACKED_STRUCT write_remote_evt_parms_t;
230
231typedef BWL_PRE_PACKED_STRUCT struct read_local_evt_parms {
232	uint8 status;
233	uint8 plh;
234	uint16 len;
235	uint8 frag[1];
236} BWL_POST_PACKED_STRUCT read_local_evt_parms_t;
237
238typedef BWL_PRE_PACKED_STRUCT struct read_local_info_evt_parms {
239	uint8 status;
240	uint8 AMP_status;
241	uint32 bandwidth;
242	uint32 gbandwidth;
243	uint32 latency;
244	uint32 PDU_size;
245	uint8 ctrl_type;
246	uint16 PAL_cap;
247	uint16 AMP_ASSOC_len;
248	uint32 max_flush_timeout;
249	uint32 be_flush_timeout;
250} BWL_POST_PACKED_STRUCT read_local_info_evt_parms_t;
251
252typedef BWL_PRE_PACKED_STRUCT struct log_link_evt_parms {
253	uint8 status;
254	uint16 llh;
255	uint8 plh;
256	uint8 tx_fs_ID;
257} BWL_POST_PACKED_STRUCT log_link_evt_parms_t;
258
259typedef BWL_PRE_PACKED_STRUCT struct disc_log_link_evt_parms {
260	uint8 status;
261	uint16 llh;
262	uint8 reason;
263} BWL_POST_PACKED_STRUCT disc_log_link_evt_parms_t;
264
265typedef BWL_PRE_PACKED_STRUCT struct log_link_cancel_evt_parms {
266	uint8 status;
267	uint8 plh;
268	uint8 tx_fs_ID;
269} BWL_POST_PACKED_STRUCT log_link_cancel_evt_parms_t;
270
271typedef BWL_PRE_PACKED_STRUCT struct flow_spec_mod_evt_parms {
272	uint8 status;
273	uint16 llh;
274} BWL_POST_PACKED_STRUCT flow_spec_mod_evt_parms_t;
275
276typedef BWL_PRE_PACKED_STRUCT struct phy_link_evt_parms {
277	uint8 status;
278	uint8 plh;
279} BWL_POST_PACKED_STRUCT phy_link_evt_parms_t;
280
281typedef BWL_PRE_PACKED_STRUCT struct dis_phy_link_evt_parms {
282	uint8 status;
283	uint8 plh;
284	uint8 reason;
285} BWL_POST_PACKED_STRUCT dis_phy_link_evt_parms_t;
286
287typedef BWL_PRE_PACKED_STRUCT struct read_ls_to_evt_parms {
288	uint8 status;
289	hci_handle_t handle;
290	uint16 timeout;
291} BWL_POST_PACKED_STRUCT read_ls_to_evt_parms_t;
292
293typedef BWL_PRE_PACKED_STRUCT struct read_lla_ca_to_evt_parms {
294	uint8 status;
295	uint16 timeout;
296} BWL_POST_PACKED_STRUCT read_lla_ca_to_evt_parms_t;
297
298typedef BWL_PRE_PACKED_STRUCT struct read_data_block_size_evt_parms {
299	uint8 status;
300	uint16 ACL_pkt_len;
301	uint16 data_block_len;
302	uint16 data_block_num;
303} BWL_POST_PACKED_STRUCT read_data_block_size_evt_parms_t;
304
305typedef BWL_PRE_PACKED_STRUCT struct data_blocks {
306	uint16 handle;
307	uint16 pkts;
308	uint16 blocks;
309} BWL_POST_PACKED_STRUCT data_blocks_t;
310
311typedef BWL_PRE_PACKED_STRUCT struct num_completed_data_blocks_evt_parms {
312	uint16 num_blocks;
313	uint8 num_handles;
314	data_blocks_t completed[1];
315} BWL_POST_PACKED_STRUCT num_completed_data_blocks_evt_parms_t;
316
317typedef BWL_PRE_PACKED_STRUCT struct befto_evt_parms {
318	uint8 status;
319	uint32 befto;
320} BWL_POST_PACKED_STRUCT befto_evt_parms_t;
321
322typedef BWL_PRE_PACKED_STRUCT struct srm_evt_parms {
323	uint8 status;
324	uint8 plh;
325	uint8 srm;
326} BWL_POST_PACKED_STRUCT srm_evt_parms_t;
327
328typedef BWL_PRE_PACKED_STRUCT struct contact_counter_evt_parms {
329	uint8 status;
330	uint8 llh[2];
331	uint16 counter;
332} BWL_POST_PACKED_STRUCT contact_counter_evt_parms_t;
333
334typedef BWL_PRE_PACKED_STRUCT struct contact_counter_reset_evt_parms {
335	uint8 status;
336	uint8 llh[2];
337} BWL_POST_PACKED_STRUCT contact_counter_reset_evt_parms_t;
338
339typedef BWL_PRE_PACKED_STRUCT struct read_linkq_evt_parms {
340	uint8 status;
341	hci_handle_t handle;
342	uint8 link_quality;
343} BWL_POST_PACKED_STRUCT read_linkq_evt_parms_t;
344
345typedef BWL_PRE_PACKED_STRUCT struct ld_evt_parms {
346	uint8 status;
347	uint8 ld_aware;
348	uint8 ld[2];
349	uint8 ld_opts;
350	uint8 l_opts;
351} BWL_POST_PACKED_STRUCT ld_evt_parms_t;
352
353typedef BWL_PRE_PACKED_STRUCT struct eflush_complete_evt_parms {
354	uint16 handle;
355} BWL_POST_PACKED_STRUCT eflush_complete_evt_parms_t;
356
357typedef BWL_PRE_PACKED_STRUCT struct vendor_specific_evt_parms {
358	uint8 len;
359	uint8 parms[1];
360} BWL_POST_PACKED_STRUCT vendor_specific_evt_parms_t;
361
362typedef BWL_PRE_PACKED_STRUCT struct local_version_info_evt_parms {
363	uint8 status;
364	uint8 hci_version;
365	uint16 hci_revision;
366	uint8 pal_version;
367	uint16 mfg_name;
368	uint16 pal_subversion;
369} BWL_POST_PACKED_STRUCT local_version_info_evt_parms_t;
370
371#define MAX_SUPPORTED_CMD_BYTE	64
372typedef BWL_PRE_PACKED_STRUCT struct local_supported_cmd_evt_parms {
373	uint8 status;
374	uint8 cmd[MAX_SUPPORTED_CMD_BYTE];
375} BWL_POST_PACKED_STRUCT local_supported_cmd_evt_parms_t;
376
377typedef BWL_PRE_PACKED_STRUCT struct status_change_evt_parms {
378	uint8 status;
379	uint8 amp_status;
380} BWL_POST_PACKED_STRUCT status_change_evt_parms_t;
381
382/* AMP HCI error codes */
383#define HCI_SUCCESS				0x00
384#define HCI_ERR_ILLEGAL_COMMAND			0x01
385#define HCI_ERR_NO_CONNECTION			0x02
386#define HCI_ERR_MEMORY_FULL			0x07
387#define HCI_ERR_CONNECTION_TIMEOUT		0x08
388#define HCI_ERR_MAX_NUM_OF_CONNECTIONS		0x09
389#define HCI_ERR_CONNECTION_EXISTS		0x0B
390#define HCI_ERR_CONNECTION_DISALLOWED		0x0C
391#define HCI_ERR_CONNECTION_ACCEPT_TIMEOUT	0x10
392#define HCI_ERR_UNSUPPORTED_VALUE		0x11
393#define HCI_ERR_ILLEGAL_PARAMETER_FMT		0x12
394#define HCI_ERR_CONN_TERM_BY_LOCAL_HOST		0x16
395#define HCI_ERR_UNSPECIFIED			0x1F
396#define HCI_ERR_UNIT_KEY_USED			0x26
397#define HCI_ERR_QOS_REJECTED			0x2D
398#define HCI_ERR_PARAM_OUT_OF_RANGE		0x30
399#define HCI_ERR_NO_SUITABLE_CHANNEL		0x39
400#define HCI_ERR_CHANNEL_MOVE			0xFF
401
402/* AMP HCI ACL Data packet format */
403typedef BWL_PRE_PACKED_STRUCT struct amp_hci_ACL_data {
404	uint16	handle;			/* 12-bit connection handle + 2-bit PB and 2-bit BC flags */
405	uint16	dlen;			/* data total length */
406	uint8 data[1];
407} BWL_POST_PACKED_STRUCT amp_hci_ACL_data_t;
408
409#define HCI_ACL_DATA_PREAMBLE_SIZE	OFFSETOF(amp_hci_ACL_data_t, data)
410
411#define HCI_ACL_DATA_BC_FLAGS		(0x0 << 14)
412#define HCI_ACL_DATA_PB_FLAGS		(0x3 << 12)
413
414#define HCI_ACL_DATA_HANDLE(handle)	((handle) & 0x0fff)
415#define HCI_ACL_DATA_FLAGS(handle)	((handle) >> 12)
416
417/* AMP Activity Report packet formats */
418typedef BWL_PRE_PACKED_STRUCT struct amp_hci_activity_report {
419	uint8	ScheduleKnown;
420	uint8	NumReports;
421	uint8	data[1];
422} BWL_POST_PACKED_STRUCT amp_hci_activity_report_t;
423
424typedef BWL_PRE_PACKED_STRUCT struct amp_hci_activity_report_triple {
425	uint32	StartTime;
426	uint32	Duration;
427	uint32	Periodicity;
428} BWL_POST_PACKED_STRUCT amp_hci_activity_report_triple_t;
429
430#define HCI_AR_SCHEDULE_KNOWN		0x01
431
432
433/* This marks the end of a packed structure section. */
434#include <packed_section_end.h>
435
436#endif /* _bt_amp_hci_h_ */
437