Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h
108696 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2019 Vladimir Kondratyev <[email protected]>
5
* Copyright (c) 2023 Future Crew LLC.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
* SUCH DAMAGE.
27
*/
28
#ifndef __IWMBT_HW_H__
29
#define __IWMBT_HW_H__
30
31
/* USB control request (HCI command) structure */
32
struct iwmbt_hci_cmd {
33
uint16_t opcode;
34
uint8_t length;
35
uint8_t data[];
36
} __attribute__ ((packed));
37
38
#define IWMBT_HCI_CMD_SIZE(cmd) \
39
((cmd)->length + offsetof(struct iwmbt_hci_cmd, data))
40
41
/* USB interrupt transfer HCI event header structure */
42
struct iwmbt_hci_evhdr {
43
uint8_t event;
44
uint8_t length;
45
} __attribute__ ((packed));
46
47
/* USB interrupt transfer (generic HCI event) structure */
48
struct iwmbt_hci_event {
49
struct iwmbt_hci_evhdr header;
50
uint8_t data[];
51
} __attribute__ ((packed));
52
53
/* USB interrupt transfer (HCI command completion event) structure */
54
struct iwmbt_hci_event_cmd_compl {
55
struct iwmbt_hci_evhdr header;
56
uint8_t numpkt;
57
uint16_t opcode;
58
uint8_t data[];
59
} __attribute__ ((packed));
60
61
/*
62
* Manufacturer mode exit type: selects reset type,
63
* 0x00: simply exit manufacturer mode without a reset.
64
* 0x01: exit manufacturer mode with a reset and patches disabled
65
* 0x02: exit manufacturer mode with a reset and patches enabled
66
*/
67
enum iwmbt_mm_exit {
68
IWMBT_MM_EXIT_ONLY = 0x00,
69
IWMBT_MM_EXIT_COLD_RESET = 0x01,
70
IWMBT_MM_EXIT_WARM_RESET = 0x02,
71
};
72
73
#define IWMBT_HCI_EVT_COMPL_SIZE(payload) \
74
(offsetof(struct iwmbt_hci_event_cmd_compl, data) + sizeof(payload))
75
#define IWMBT_HCI_EVENT_COMPL_HEAD_SIZE \
76
(offsetof(struct iwmbt_hci_event_cmd_compl, data) - \
77
offsetof(struct iwmbt_hci_event_cmd_compl, numpkt))
78
79
#define IWMBT_CONTROL_ENDPOINT_ADDR 0x00
80
#define IWMBT_INTERRUPT_ENDPOINT_ADDR 0x81
81
#define IWMBT_BULK_IN_ENDPOINT_ADDR 0x82
82
#define IWMBT_BULK_OUT_ENDPOINT_ADDR 0x02
83
84
#define IWMBT_HCI_MAX_CMD_SIZE 256
85
#define IWMBT_HCI_MAX_EVENT_SIZE 16
86
87
#define IWMBT_MSEC2TS(msec) \
88
(struct timespec) { \
89
.tv_sec = (msec) / 1000, \
90
.tv_nsec = ((msec) % 1000) * 1000000 \
91
};
92
#define IWMBT_TS2MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000)
93
#define IWMBT_HCI_CMD_TIMEOUT 2000 /* ms */
94
#define IWMBT_LOADCMPL_TIMEOUT 5000 /* ms */
95
96
extern int iwmbt_patch_fwfile(struct libusb_device_handle *hdl,
97
const struct iwmbt_firmware *fw);
98
extern int iwmbt_load_rsa_header(struct libusb_device_handle *hdl,
99
const struct iwmbt_firmware *fw);
100
extern int iwmbt_load_ecdsa_header(struct libusb_device_handle *hdl,
101
const struct iwmbt_firmware *fw);
102
extern int iwmbt_load_fwfile(struct libusb_device_handle *hdl,
103
const struct iwmbt_firmware *fw, uint32_t *boot_param, int offset);
104
extern int iwmbt_enter_manufacturer(struct libusb_device_handle *hdl);
105
extern int iwmbt_exit_manufacturer(struct libusb_device_handle *hdl,
106
enum iwmbt_mm_exit mode);
107
extern int iwmbt_get_version(struct libusb_device_handle *hdl,
108
struct iwmbt_version *version);
109
extern int iwmbt_get_version_tlv(struct libusb_device_handle *hdl,
110
struct iwmbt_version_tlv *version);
111
extern int iwmbt_get_boot_params(struct libusb_device_handle *hdl,
112
struct iwmbt_boot_params *params);
113
extern int iwmbt_intel_reset(struct libusb_device_handle *hdl,
114
uint32_t boot_param);
115
extern int iwmbt_load_ddc(struct libusb_device_handle *hdl,
116
const struct iwmbt_firmware *ddc);
117
extern int iwmbt_set_event_mask(struct libusb_device_handle *hdl);
118
119
#endif
120
121