xref: /titanic_44/usr/src/uts/common/sys/usb/usba/whcdi.h (revision 8956713aded83a741173fcd4f9ef1c83521fbea9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_USB_WHCDI_H
27 #define	_SYS_USB_WHCDI_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/usb/usba/usba_types.h>
34 #include <sys/usb/usba/wusba.h>
35 #include <sys/usb/usba/wusba_io.h>
36 #include <sys/usb/usba/wa.h>	/* for wusb_secrt_data_t */
37 
38 
39 /*
40  * This file contains data structures and functions that might be
41  * shared by HWA and WHCI drivers.
42  */
43 
44 typedef struct wusb_hc_cc_list {
45 	wusb_cc_t		cc;
46 	struct wusb_hc_cc_list	*next;
47 } wusb_hc_cc_list_t;
48 
49 struct wusb_hc_data;
50 
51 typedef struct wusb_dev_info {
52 	struct wusb_hc_data	*wdev_hc; /* the HC this device attaches */
53 	uint8_t			wdev_cdid[16];
54 	uint16_t		wdev_addr;
55 	uint16_t		wdev_state;
56 	uint8_t			wdev_is_newconn;
57 	uint8_t			wdev_beacon_attr;
58 	usb_pipe_handle_t	wdev_ph;	/* used before authenticated */
59 	wusb_secrt_data_t	wdev_secrt_data;
60 	usb_uwb_cap_descr_t	*wdev_uwb_descr;
61 	wusb_cc_t		*wdev_cc;
62 	uint8_t			wdev_ptk[16];
63 	uint8_t			wdev_tkid[3];
64 	timeout_id_t		wdev_trust_timer; /* TrustTimeout timer */
65 	uint8_t			wdev_active;
66 } wusb_dev_info_t;
67 
68 _NOTE(DATA_READABLE_WITHOUT_LOCK(wusb_dev_info::wdev_addr))
69 _NOTE(DATA_READABLE_WITHOUT_LOCK(wusb_dev_info::wdev_uwb_descr))
70 _NOTE(DATA_READABLE_WITHOUT_LOCK(wusb_dev_info::wdev_hc))
71 
72 /*
73  * According to WUSB 1.0 spec, WUSB hosts can support up to 127 devices.
74  * To comply with USB bus convention that bus address 1 is assigned
75  * to the host controller device, the addresses assigned to WUSB devices
76  * would start from 2. So the max device number is reduced to 126.
77  */
78 #define	WUSB_MAX_PORTS		126
79 
80 #define	WUSB_CHILD_ZAP		0x1
81 
82 typedef struct wusb_hc_data {
83 	dev_info_t		*hc_dip;
84 	void			*hc_private_data;
85 	uint8_t			hc_chid[16];
86 	uint8_t			hc_cluster_id;
87 	uint8_t			hc_num_mmcies;
88 	kmutex_t		hc_mutex;
89 	wusb_ie_header_t	**hc_mmcie_list;
90 
91 	boolean_t		hc_newcon_enabled;
92 
93 	/* save the often used IEs so as not to allocate them each time */
94 	wusb_ie_keepalive_t		hc_alive_ie;
95 
96 	/* children info structures */
97 	uint8_t			hc_num_ports;
98 	wusb_dev_info_t		**hc_dev_infos;
99 	dev_info_t		**hc_children_dips;
100 	size_t			hc_cd_list_length;
101 	usba_device_t		**hc_usba_devices;
102 
103 	/* for bus unconfig */
104 	uint8_t			hc_children_state[WUSB_MAX_PORTS + 1];
105 
106 	/* child connection functions */
107 	void	(*disconnect_dev)(dev_info_t *, usb_port_t);
108 	void	(*reconnect_dev)(dev_info_t *, usb_port_t);
109 	int	(*create_child)(dev_info_t *, usb_port_t);
110 	int	(*destroy_child)(dev_info_t *, usb_port_t);
111 
112 	/*
113 	 * some necessary host functions:
114 	 * Both HWA and HCI must implement these entries to support basic
115 	 * host controller operations.
116 	 */
117 	int	(*set_encrypt)(dev_info_t *, usb_port_t, uint8_t);
118 	int	(*set_ptk)(dev_info_t *, usb_key_descr_t *, size_t, usb_port_t);
119 	int	(*set_gtk)(dev_info_t *, usb_key_descr_t *, size_t);
120 	int	(*set_device_info)(dev_info_t *, wusb_dev_info_t *, usb_port_t);
121 	int	(*set_cluster_id) (dev_info_t *, uint8_t id);
122 	int	(*set_stream_idx) (dev_info_t *, uint8_t idx);
123 	int	(*set_wusb_mas)	(dev_info_t *, uint8_t *data);
124 	int	(*add_mmc_ie)	(dev_info_t *, uint8_t interval, uint8_t rcnt,
125 				uint8_t iehdl, uint16_t len, uint8_t *data);
126 	int	(*rem_mmc_ie)	(dev_info_t *, uint8_t iehdl);
127 	int	(*stop_ch)	(dev_info_t *, uint32_t time);
128 	int	(*set_num_dnts)	(dev_info_t *, uint8_t interval, uint8_t nslot);
129 	int	(*get_time)	(dev_info_t *, uint8_t timetype,
130 				uint16_t timelen, uint32_t *time);
131 
132 	/* host addr in MAC layer */
133 	uint16_t		hc_addr;
134 
135 	/* beaconing channel */
136 	uint8_t			hc_channel;
137 
138 	/* reserved MASes. bitmaps */
139 	uint8_t			hc_mas[WUSB_SET_WUSB_MAS_LEN];
140 
141 	/* connection context list for the host */
142 	wusb_hc_cc_list_t	*hc_cc_list;
143 
144 	/* group temporal key */
145 	usb_key_descr_t		hc_gtk;
146 	uint8_t			hc_gtk_padding[15];
147 } wusb_hc_data_t;
148 
149 _NOTE(MUTEX_PROTECTS_DATA(wusb_hc_data_t::hc_mutex, wusb_dev_info_t))
150 _NOTE(MUTEX_PROTECTS_DATA(wusb_hc_data_t::hc_mutex, wusb_hc_data_t))
151 
152 _NOTE(DATA_READABLE_WITHOUT_LOCK(wusb_hc_data_t::hc_num_ports))
153 _NOTE(DATA_READABLE_WITHOUT_LOCK(wusb_hc_data_t::hc_dip))
154 
155 /*
156  * WUSB 1.0 4.3.8.5 says the range of cluster id is in 0x80-0xfe,
157  * we limit the maximum WUSB host controller numbers to 31 now,
158  * and take the upper portion of this range as the broadcast
159  * cluster id
160  */
161 #define	WUSB_CLUSTER_ID_COUNT		31
162 #define	WUSB_MIN_CLUSTER_ID		0xe0
163 
164 #define	WUSB_TRUST_TIMEOUT	4 /* WUSB 4.15.1 TrustTimeout = 4s */
165 #define	WUSB_TRUST_TIMEOUT_US	WUSB_TRUST_TIMEOUT * MICROSEC
166 
167 #define	WUSB_PERIODIC_ENDPOINT(endpoint) (((endpoint->bmAttributes & \
168 	USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR) ||\
169 	((endpoint->bmAttributes &\
170 	USB_EP_ATTR_MASK) == USB_EP_ATTR_ISOCH))
171 
172 #define	WUSB_ISOC_ENDPOINT(endpoint) (((endpoint->bmAttributes &\
173 	USB_EP_ATTR_MASK) == USB_EP_ATTR_ISOCH))
174 
175 #define	WUSB_INTR_ENDPOINT(endpoint) (((endpoint->bmAttributes &\
176 	USB_EP_ATTR_MASK) == USB_EP_ATTR_INTR))
177 
178 /* helper functions */
179 uint8_t	wusb_hc_get_cluster_id();
180 void	wusb_hc_free_cluster_id(uint8_t id);
181 int	wusb_hc_get_iehdl(wusb_hc_data_t *hc_data, wusb_ie_header_t *hdr,
182 	uint8_t *iehdl);
183 void	wusb_hc_free_iehdl(wusb_hc_data_t *hc_data, uint8_t iehdl);
184 
185 uint_t	wusb_hc_is_dev_connected(wusb_hc_data_t *hc_data, uint8_t *cdid,
186 	usb_port_t *port);
187 uint_t	wusb_hc_is_addr_valid(wusb_hc_data_t *hc_data, uint8_t addr,
188 	usb_port_t *port);
189 usb_port_t	wusb_hc_get_free_port(wusb_hc_data_t *hc_data);
190 
191 /* device notification support */
192 int	wusb_hc_ack_conn(wusb_hc_data_t *hc_data, usb_port_t port);
193 int	wusb_hc_ack_disconn(wusb_hc_data_t *hc_data, uint8_t addr);
194 void	wusb_hc_rm_ack(wusb_hc_data_t *hc_data);
195 int	wusb_hc_send_keepalive_ie(wusb_hc_data_t *hc_data, uint8_t addr);
196 int	wusb_hc_auth_dev(wusb_hc_data_t *hc_data, usb_port_t port,
197 	usb_pipe_handle_t ph, uint8_t ifc, wusb_secrt_data_t *secrt_data);
198 int	wusb_hc_handle_port_connect(wusb_hc_data_t *hc_data, usb_port_t port,
199 	usb_pipe_handle_t ph, uint8_t ifc, wusb_secrt_data_t *secrt_data);
200 void	wusb_hc_handle_dn_connect(wusb_hc_data_t *hc_data,
201 	usb_pipe_handle_t ph, uint8_t ifc, uint8_t *data, size_t len,
202 	wusb_secrt_data_t *secrt_data);
203 void	wusb_hc_handle_dn_disconnect(wusb_hc_data_t *hc_data, uint8_t addr,
204 	uint8_t *data, size_t len);
205 
206 /* wusb common device function */
207 int	wusb_create_child_devi(dev_info_t *dip, char *node_name,
208 	usba_hcdi_ops_t *usba_hcdi_ops, dev_info_t *usb_root_hub_dip,
209 	usb_port_status_t port_status, usba_device_t *usba_device,
210 	dev_info_t **child_dip);
211 int	wusb_get_dev_security_descr(usb_pipe_handle_t ph,
212 	wusb_secrt_data_t *secrt_data);
213 int	wusb_get_bos_cloud(dev_info_t *child_dip, usba_device_t *child_ud);
214 int	wusb_get_rc_dev_by_hc(dev_info_t *dip, dev_t *dev);
215 
216 int16_t	wusb_get_ccm_encryption_value(wusb_secrt_data_t *secrt_data);
217 
218 /* device dynamical configuration functions */
219 void	wusb_hc_disconnect_dev(wusb_hc_data_t *hc_data, usb_port_t port);
220 void	wusb_hc_reconnect_dev(wusb_hc_data_t *hc_data, usb_port_t port);
221 int	wusb_hc_create_child(wusb_hc_data_t *hc_data, usb_port_t port);
222 int	wusb_hc_destroy_child(wusb_hc_data_t *hc_data, usb_port_t port);
223 
224 /* WUSB HC common requests */
225 int	wusb_hc_set_cluster_id(wusb_hc_data_t *hc_data, uint8_t cluster_id);
226 
227 int	wusb_hc_set_stream_idx(wusb_hc_data_t *hc_data, uint8_t stream_idx);
228 
229 int	wusb_hc_set_wusb_mas(wusb_hc_data_t *hc_data, uint8_t *data);
230 
231 int	wusb_hc_add_mmc_ie(wusb_hc_data_t *hc_data, uint8_t interval,
232 	uint8_t rcnt, uint8_t iehdl, uint16_t len, uint8_t *data);
233 
234 int	wusb_hc_remove_mmc_ie(wusb_hc_data_t *hc_data, uint8_t iehdl);
235 void	wusb_hc_rem_ie(wusb_hc_data_t *hc_data, wusb_ie_header_t *ieh);
236 
237 int	wusb_hc_stop_ch(wusb_hc_data_t *hc_data, uint32_t timeoff);
238 
239 int	wusb_hc_set_num_dnts(wusb_hc_data_t *hc_data, uint8_t interval,
240 	uint8_t nslots);
241 
242 int	wusb_hc_get_time(wusb_hc_data_t *hc_data, uint8_t time_type,
243 	uint16_t len, uint32_t *time);
244 
245 int	wusb_hc_add_host_info(wusb_hc_data_t *hc_data, uint8_t stream_idx);
246 
247 void	wusb_hc_rem_host_info(wusb_hc_data_t *hc_data);
248 
249 int	wusb_hc_send_host_disconnect(wusb_hc_data_t *hc_data);
250 
251 int	wusb_hc_set_device_info(wusb_hc_data_t *hc_data, usb_port_t port);
252 
253 /* WUSB HC connection context list operations */
254 void	wusb_hc_add_cc(wusb_hc_cc_list_t **cc_list, wusb_hc_cc_list_t *new_cc);
255 void	wusb_hc_rem_cc(wusb_hc_cc_list_t **cc_list, wusb_cc_t *old_cc);
256 void	wusb_hc_free_cc_list(wusb_hc_cc_list_t *cc_list);
257 wusb_cc_t *wusb_hc_cc_matched(wusb_hc_cc_list_t *cc_list, uint8_t *cdid);
258 
259 /* security functions */
260 int	wusb_dev_set_encrypt(usb_pipe_handle_t ph, uint8_t value);
261 int	wusb_enable_dev_encrypt(wusb_dev_info_t *dev_info);
262 int	wusb_dev_set_key(usb_pipe_handle_t ph, uint8_t key_index,
263 	usb_key_descr_t *key, size_t klen);
264 int	wusb_hc_set_encrypt(wusb_hc_data_t *hc_data, usb_port_t port,
265 	uint8_t type);
266 int	wusb_hc_set_ptk(wusb_hc_data_t *hc_data, uint8_t *key_data,
267 	usb_port_t port);
268 int	wusb_hc_set_gtk(wusb_hc_data_t *hc_data, uint8_t *key_data,
269 	uint8_t *tkid);
270 
271 /* crypto functions */
272 int	PRF(const uchar_t *key, size_t klen, wusb_ccm_nonce_t *nonce,
273 	const uchar_t *adata, size_t alen,
274 	const uchar_t *bdata, size_t blen,
275 	uchar_t *out, size_t bitlen);
276 
277 #define	PRF_64(key, klen, nonce, adata, alen, bdata, blen, out)	\
278 	PRF(key, klen, nonce, adata, alen, bdata, blen, out, 64)
279 
280 #define	PRF_128(key, klen, nonce, adata, alen, bdata, blen, out)	\
281 	PRF(key, klen, nonce, adata, alen, bdata, blen, out, 128)
282 
283 #define	PRF_256(key, klen, nonce, adata, alen, bdata, blen, out)	\
284 	PRF(key, klen, nonce, adata, alen, bdata, blen, out, 256)
285 
286 int	wusb_gen_random_nonce(wusb_hc_data_t *hc_data,
287 	wusb_dev_info_t *dev_info, uchar_t *rbuf);
288 
289 int	wusb_4way_handshake(wusb_hc_data_t *hc_data, usb_port_t port,
290 	usb_pipe_handle_t ph, uint8_t ifc);
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 
296 #endif	/* _SYS_USB_WHCDI_H */
297