xref: /freebsd/sys/dev/usb/template/usb_template_cdce.c (revision 8e06491a4e5709cf821dc010f349062f7b34c2f4)
1d2b99310SHans Petter Selasky /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
3718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4718cf2ccSPedro F. Giffuni  *
55d38a4d4SEd Schouten  * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
6*8e06491aSEdward Tomasz Napierala  * Copyright (c) 2018 The FreeBSD Foundation
702ac6454SAndrew Thompson  * All rights reserved.
802ac6454SAndrew Thompson  *
9*8e06491aSEdward Tomasz Napierala  * Portions of this software were developed by Edward Tomasz Napierala
10*8e06491aSEdward Tomasz Napierala  * under sponsorship from the FreeBSD Foundation.
11*8e06491aSEdward Tomasz Napierala  *
1202ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1302ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1402ac6454SAndrew Thompson  * are met:
1502ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1602ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1702ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1802ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1902ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
2002ac6454SAndrew Thompson  *
2102ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2202ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2302ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2402ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2502ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2602ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2702ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2802ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2902ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3002ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3102ac6454SAndrew Thompson  * SUCH DAMAGE.
3202ac6454SAndrew Thompson  */
3302ac6454SAndrew Thompson 
3402ac6454SAndrew Thompson /*
3502ac6454SAndrew Thompson  * This file contains the USB templates for a CDC USB ethernet device.
3602ac6454SAndrew Thompson  */
3702ac6454SAndrew Thompson 
38d2b99310SHans Petter Selasky #ifdef USB_GLOBAL_INCLUDE_FILE
39d2b99310SHans Petter Selasky #include USB_GLOBAL_INCLUDE_FILE
40d2b99310SHans Petter Selasky #else
41ed6d949aSAndrew Thompson #include <sys/stdint.h>
42ed6d949aSAndrew Thompson #include <sys/stddef.h>
43ed6d949aSAndrew Thompson #include <sys/param.h>
44ed6d949aSAndrew Thompson #include <sys/queue.h>
45ed6d949aSAndrew Thompson #include <sys/types.h>
46ed6d949aSAndrew Thompson #include <sys/systm.h>
47ed6d949aSAndrew Thompson #include <sys/kernel.h>
48ed6d949aSAndrew Thompson #include <sys/bus.h>
49ed6d949aSAndrew Thompson #include <sys/module.h>
50ed6d949aSAndrew Thompson #include <sys/lock.h>
51ed6d949aSAndrew Thompson #include <sys/mutex.h>
52ed6d949aSAndrew Thompson #include <sys/condvar.h>
53ed6d949aSAndrew Thompson #include <sys/sysctl.h>
54ed6d949aSAndrew Thompson #include <sys/sx.h>
55ed6d949aSAndrew Thompson #include <sys/unistd.h>
56ed6d949aSAndrew Thompson #include <sys/callout.h>
57ed6d949aSAndrew Thompson #include <sys/malloc.h>
58ed6d949aSAndrew Thompson #include <sys/priv.h>
5902ac6454SAndrew Thompson 
60ed6d949aSAndrew Thompson #include <dev/usb/usb.h>
61ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h>
6223ab0871SHans Petter Selasky #include <dev/usb/usb_core.h>
63ed6d949aSAndrew Thompson #include <dev/usb/usb_cdc.h>
64*8e06491aSEdward Tomasz Napierala #include <dev/usb/usb_ioctl.h>
65*8e06491aSEdward Tomasz Napierala #include <dev/usb/usb_util.h>
6602ac6454SAndrew Thompson 
6702ac6454SAndrew Thompson #include <dev/usb/template/usb_template.h>
68d2b99310SHans Petter Selasky #endif			/* USB_GLOBAL_INCLUDE_FILE */
6902ac6454SAndrew Thompson 
7002ac6454SAndrew Thompson enum {
71*8e06491aSEdward Tomasz Napierala 	ETH_LANG_INDEX,
72*8e06491aSEdward Tomasz Napierala 	ETH_MAC_INDEX,
73*8e06491aSEdward Tomasz Napierala 	ETH_CONTROL_INDEX,
74*8e06491aSEdward Tomasz Napierala 	ETH_DATA_INDEX,
75*8e06491aSEdward Tomasz Napierala 	ETH_CONFIGURATION_INDEX,
76*8e06491aSEdward Tomasz Napierala 	ETH_MANUFACTURER_INDEX,
77*8e06491aSEdward Tomasz Napierala 	ETH_PRODUCT_INDEX,
78*8e06491aSEdward Tomasz Napierala 	ETH_SERIAL_NUMBER_INDEX,
79*8e06491aSEdward Tomasz Napierala 	ETH_MAX_INDEX,
8002ac6454SAndrew Thompson };
8102ac6454SAndrew Thompson 
82*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_MAC			"2A02030405060789AB"
83*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_CONTROL		"USB Ethernet Comm Interface"
84*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_DATA		"USB Ethernet Data Interface"
85*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_CONFIG		"Default Config"
86*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_MANUFACTURER	"FreeBSD foundation"
87*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_PRODUCT		"USB Ethernet Adapter"
88*8e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_SERIAL_NUMBER	"December 2007"
8902ac6454SAndrew Thompson 
90*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_mac;
91*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_control;
92*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_data;
93*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_configuration;
94*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_manufacturer;
95*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_product;
96*8e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_serial_number;
9702ac6454SAndrew Thompson 
98*8e06491aSEdward Tomasz Napierala static struct sysctl_ctx_list		eth_ctx_list;
9902ac6454SAndrew Thompson 
10002ac6454SAndrew Thompson /* prototypes */
10102ac6454SAndrew Thompson 
102a593f6b8SAndrew Thompson static usb_temp_get_string_desc_t eth_get_string_desc;
10302ac6454SAndrew Thompson 
104760bc48eSAndrew Thompson static const struct usb_cdc_union_descriptor eth_union_desc = {
10502ac6454SAndrew Thompson 	.bLength = sizeof(eth_union_desc),
10602ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
10702ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_UNION,
10802ac6454SAndrew Thompson 	.bMasterInterface = 0,		/* this is automatically updated */
10902ac6454SAndrew Thompson 	.bSlaveInterface[0] = 1,	/* this is automatically updated */
11002ac6454SAndrew Thompson };
11102ac6454SAndrew Thompson 
112760bc48eSAndrew Thompson static const struct usb_cdc_header_descriptor eth_header_desc = {
11302ac6454SAndrew Thompson 	.bLength = sizeof(eth_header_desc),
11402ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
11502ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_HEADER,
11602ac6454SAndrew Thompson 	.bcdCDC[0] = 0x10,
11702ac6454SAndrew Thompson 	.bcdCDC[1] = 0x01,
11802ac6454SAndrew Thompson };
11902ac6454SAndrew Thompson 
120760bc48eSAndrew Thompson static const struct usb_cdc_ethernet_descriptor eth_enf_desc = {
12102ac6454SAndrew Thompson 	.bLength = sizeof(eth_enf_desc),
12202ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
12302ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_ENF,
124*8e06491aSEdward Tomasz Napierala 	.iMacAddress = ETH_MAC_INDEX,
12502ac6454SAndrew Thompson 	.bmEthernetStatistics = {0, 0, 0, 0},
12602ac6454SAndrew Thompson 	.wMaxSegmentSize = {0xEA, 0x05},/* 1514 bytes */
12702ac6454SAndrew Thompson 	.wNumberMCFilters = {0, 0},
12802ac6454SAndrew Thompson 	.bNumberPowerFilters = 0,
12902ac6454SAndrew Thompson };
13002ac6454SAndrew Thompson 
13102ac6454SAndrew Thompson static const void *eth_control_if_desc[] = {
13202ac6454SAndrew Thompson 	&eth_union_desc,
13302ac6454SAndrew Thompson 	&eth_header_desc,
13402ac6454SAndrew Thompson 	&eth_enf_desc,
13502ac6454SAndrew Thompson 	NULL,
13602ac6454SAndrew Thompson };
13702ac6454SAndrew Thompson 
138760bc48eSAndrew Thompson static const struct usb_temp_packet_size bulk_mps = {
13902ac6454SAndrew Thompson 	.mps[USB_SPEED_FULL] = 64,
14002ac6454SAndrew Thompson 	.mps[USB_SPEED_HIGH] = 512,
14102ac6454SAndrew Thompson };
14202ac6454SAndrew Thompson 
143760bc48eSAndrew Thompson static const struct usb_temp_packet_size intr_mps = {
14402ac6454SAndrew Thompson 	.mps[USB_SPEED_FULL] = 8,
14502ac6454SAndrew Thompson 	.mps[USB_SPEED_HIGH] = 8,
14602ac6454SAndrew Thompson };
14702ac6454SAndrew Thompson 
148760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc bulk_in_ep = {
14902ac6454SAndrew Thompson 	.pPacketSize = &bulk_mps,
15002ac6454SAndrew Thompson #ifdef USB_HIP_IN_EP_0
15102ac6454SAndrew Thompson 	.bEndpointAddress = USB_HIP_IN_EP_0,
15202ac6454SAndrew Thompson #else
15302ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_IN,
15402ac6454SAndrew Thompson #endif
15502ac6454SAndrew Thompson 	.bmAttributes = UE_BULK,
15602ac6454SAndrew Thompson };
15702ac6454SAndrew Thompson 
158760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc bulk_out_ep = {
15902ac6454SAndrew Thompson 	.pPacketSize = &bulk_mps,
16002ac6454SAndrew Thompson #ifdef USB_HIP_OUT_EP_0
16102ac6454SAndrew Thompson 	.bEndpointAddress = USB_HIP_OUT_EP_0,
16202ac6454SAndrew Thompson #else
16302ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_OUT,
16402ac6454SAndrew Thompson #endif
16502ac6454SAndrew Thompson 	.bmAttributes = UE_BULK,
16602ac6454SAndrew Thompson };
16702ac6454SAndrew Thompson 
168760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc intr_in_ep = {
16902ac6454SAndrew Thompson 	.pPacketSize = &intr_mps,
17002ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_IN,
17102ac6454SAndrew Thompson 	.bmAttributes = UE_INTERRUPT,
17202ac6454SAndrew Thompson };
17302ac6454SAndrew Thompson 
174760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc *eth_intr_endpoints[] = {
17502ac6454SAndrew Thompson 	&intr_in_ep,
17602ac6454SAndrew Thompson 	NULL,
17702ac6454SAndrew Thompson };
17802ac6454SAndrew Thompson 
179760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_control_interface = {
18002ac6454SAndrew Thompson 	.ppEndpoints = eth_intr_endpoints,
18102ac6454SAndrew Thompson 	.ppRawDesc = eth_control_if_desc,
18202ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC,
18302ac6454SAndrew Thompson 	.bInterfaceSubClass = UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL,
18402ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
185*8e06491aSEdward Tomasz Napierala 	.iInterface = ETH_CONTROL_INDEX,
18602ac6454SAndrew Thompson };
18702ac6454SAndrew Thompson 
188760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc *eth_data_endpoints[] = {
18902ac6454SAndrew Thompson 	&bulk_in_ep,
19002ac6454SAndrew Thompson 	&bulk_out_ep,
19102ac6454SAndrew Thompson 	NULL,
19202ac6454SAndrew Thompson };
19302ac6454SAndrew Thompson 
194760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_data_null_interface = {
19502ac6454SAndrew Thompson 	.ppEndpoints = NULL,		/* no endpoints */
19602ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC_DATA,
19702ac6454SAndrew Thompson 	.bInterfaceSubClass = 0,
19802ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
199*8e06491aSEdward Tomasz Napierala 	.iInterface = ETH_DATA_INDEX,
20002ac6454SAndrew Thompson };
20102ac6454SAndrew Thompson 
202760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_data_interface = {
20302ac6454SAndrew Thompson 	.ppEndpoints = eth_data_endpoints,
20402ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC_DATA,
20502ac6454SAndrew Thompson 	.bInterfaceSubClass = UISUBCLASS_DATA,
20602ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
207*8e06491aSEdward Tomasz Napierala 	.iInterface = ETH_DATA_INDEX,
20802ac6454SAndrew Thompson 	.isAltInterface = 1,		/* this is an alternate setting */
20902ac6454SAndrew Thompson };
21002ac6454SAndrew Thompson 
211760bc48eSAndrew Thompson static const struct usb_temp_interface_desc *eth_interfaces[] = {
21202ac6454SAndrew Thompson 	&eth_control_interface,
21302ac6454SAndrew Thompson 	&eth_data_null_interface,
21402ac6454SAndrew Thompson 	&eth_data_interface,
21502ac6454SAndrew Thompson 	NULL,
21602ac6454SAndrew Thompson };
21702ac6454SAndrew Thompson 
218760bc48eSAndrew Thompson static const struct usb_temp_config_desc eth_config_desc = {
21902ac6454SAndrew Thompson 	.ppIfaceDesc = eth_interfaces,
22002ac6454SAndrew Thompson 	.bmAttributes = UC_BUS_POWERED,
22102ac6454SAndrew Thompson 	.bMaxPower = 25,		/* 50 mA */
222*8e06491aSEdward Tomasz Napierala 	.iConfiguration = ETH_CONFIGURATION_INDEX,
22302ac6454SAndrew Thompson };
22402ac6454SAndrew Thompson 
225760bc48eSAndrew Thompson static const struct usb_temp_config_desc *eth_configs[] = {
22602ac6454SAndrew Thompson 	&eth_config_desc,
22702ac6454SAndrew Thompson 	NULL,
22802ac6454SAndrew Thompson };
22902ac6454SAndrew Thompson 
230*8e06491aSEdward Tomasz Napierala struct usb_temp_device_desc usb_template_cdce = {
23102ac6454SAndrew Thompson 	.getStringDesc = &eth_get_string_desc,
23202ac6454SAndrew Thompson 	.ppConfigDesc = eth_configs,
233399e6543SHans Petter Selasky 	.idVendor = USB_TEMPLATE_VENDOR,
23402ac6454SAndrew Thompson 	.idProduct = 0x0001,
23502ac6454SAndrew Thompson 	.bcdDevice = 0x0100,
23602ac6454SAndrew Thompson 	.bDeviceClass = UDCLASS_COMM,
23702ac6454SAndrew Thompson 	.bDeviceSubClass = 0,
23802ac6454SAndrew Thompson 	.bDeviceProtocol = 0,
239*8e06491aSEdward Tomasz Napierala 	.iManufacturer = ETH_MANUFACTURER_INDEX,
240*8e06491aSEdward Tomasz Napierala 	.iProduct = ETH_PRODUCT_INDEX,
241*8e06491aSEdward Tomasz Napierala 	.iSerialNumber = ETH_SERIAL_NUMBER_INDEX,
24202ac6454SAndrew Thompson };
24302ac6454SAndrew Thompson 
24402ac6454SAndrew Thompson /*------------------------------------------------------------------------*
24502ac6454SAndrew Thompson  *	eth_get_string_desc
24602ac6454SAndrew Thompson  *
24702ac6454SAndrew Thompson  * Return values:
24802ac6454SAndrew Thompson  * NULL: Failure. No such string.
24902ac6454SAndrew Thompson  * Else: Success. Pointer to string descriptor is returned.
25002ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
25102ac6454SAndrew Thompson static const void *
25202ac6454SAndrew Thompson eth_get_string_desc(uint16_t lang_id, uint8_t string_index)
25302ac6454SAndrew Thompson {
254*8e06491aSEdward Tomasz Napierala 	static const void *ptr[ETH_MAX_INDEX] = {
255*8e06491aSEdward Tomasz Napierala 		[ETH_LANG_INDEX] = &usb_string_lang_en,
256*8e06491aSEdward Tomasz Napierala 		[ETH_MAC_INDEX] = &eth_mac,
257*8e06491aSEdward Tomasz Napierala 		[ETH_CONTROL_INDEX] = &eth_control,
258*8e06491aSEdward Tomasz Napierala 		[ETH_DATA_INDEX] = &eth_data,
259*8e06491aSEdward Tomasz Napierala 		[ETH_CONFIGURATION_INDEX] = &eth_configuration,
260*8e06491aSEdward Tomasz Napierala 		[ETH_MANUFACTURER_INDEX] = &eth_manufacturer,
261*8e06491aSEdward Tomasz Napierala 		[ETH_PRODUCT_INDEX] = &eth_product,
262*8e06491aSEdward Tomasz Napierala 		[ETH_SERIAL_NUMBER_INDEX] = &eth_serial_number,
26302ac6454SAndrew Thompson 	};
26402ac6454SAndrew Thompson 
26502ac6454SAndrew Thompson 	if (string_index == 0) {
26623ab0871SHans Petter Selasky 		return (&usb_string_lang_en);
26702ac6454SAndrew Thompson 	}
26802ac6454SAndrew Thompson 	if (lang_id != 0x0409) {
26902ac6454SAndrew Thompson 		return (NULL);
27002ac6454SAndrew Thompson 	}
271*8e06491aSEdward Tomasz Napierala 	if (string_index < ETH_MAX_INDEX) {
27202ac6454SAndrew Thompson 		return (ptr[string_index]);
27302ac6454SAndrew Thompson 	}
27402ac6454SAndrew Thompson 	return (NULL);
27502ac6454SAndrew Thompson }
276*8e06491aSEdward Tomasz Napierala 
277*8e06491aSEdward Tomasz Napierala static void
278*8e06491aSEdward Tomasz Napierala eth_init(void *arg __unused)
279*8e06491aSEdward Tomasz Napierala {
280*8e06491aSEdward Tomasz Napierala 	struct sysctl_oid *parent;
281*8e06491aSEdward Tomasz Napierala 	char parent_name[3];
282*8e06491aSEdward Tomasz Napierala 
283*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_mac, sizeof(eth_mac),
284*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_MAC);
285*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_control, sizeof(eth_control),
286*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_CONTROL);
287*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_data, sizeof(eth_data),
288*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_DATA);
289*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_configuration, sizeof(eth_configuration),
290*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_CONFIG);
291*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_manufacturer, sizeof(eth_manufacturer),
292*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_MANUFACTURER);
293*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_product, sizeof(eth_product),
294*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_PRODUCT);
295*8e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_serial_number, sizeof(eth_serial_number),
296*8e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_SERIAL_NUMBER);
297*8e06491aSEdward Tomasz Napierala 
298*8e06491aSEdward Tomasz Napierala 	snprintf(parent_name, sizeof(parent_name), "%d", USB_TEMP_CDCE);
299*8e06491aSEdward Tomasz Napierala 	sysctl_ctx_init(&eth_ctx_list);
300*8e06491aSEdward Tomasz Napierala 
301*8e06491aSEdward Tomasz Napierala 	parent = SYSCTL_ADD_NODE(&eth_ctx_list,
302*8e06491aSEdward Tomasz Napierala 	    SYSCTL_STATIC_CHILDREN(_hw_usb_templates), OID_AUTO,
303*8e06491aSEdward Tomasz Napierala 	    parent_name, CTLFLAG_RW,
304*8e06491aSEdward Tomasz Napierala 	    0, "USB CDC Ethernet device side template");
305*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_U16(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
306*8e06491aSEdward Tomasz Napierala 	    "vendor_id", CTLFLAG_RWTUN,
307*8e06491aSEdward Tomasz Napierala 	    &usb_template_cdce.idVendor, 1, "Vendor identifier");
308*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_U16(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
309*8e06491aSEdward Tomasz Napierala 	    "product_id", CTLFLAG_RWTUN,
310*8e06491aSEdward Tomasz Napierala 	    &usb_template_cdce.idProduct, 1, "Product identifier");
311*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
312*8e06491aSEdward Tomasz Napierala 	    "mac", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
313*8e06491aSEdward Tomasz Napierala 	    &eth_mac, sizeof(eth_mac), usb_temp_sysctl,
314*8e06491aSEdward Tomasz Napierala 	    "A", "MAC address string");
315*8e06491aSEdward Tomasz Napierala #if 0
316*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
317*8e06491aSEdward Tomasz Napierala 	    "control", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
318*8e06491aSEdward Tomasz Napierala 	    &eth_control, sizeof(eth_control), usb_temp_sysctl,
319*8e06491aSEdward Tomasz Napierala 	    "A", "Control interface string");
320*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
321*8e06491aSEdward Tomasz Napierala 	    "data", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
322*8e06491aSEdward Tomasz Napierala 	    &eth_data, sizeof(eth_data), usb_temp_sysctl,
323*8e06491aSEdward Tomasz Napierala 	    "A", "Data interface string");
324*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
325*8e06491aSEdward Tomasz Napierala 	    "configuration", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
326*8e06491aSEdward Tomasz Napierala 	    &eth_configuration, sizeof(eth_configuration), usb_temp_sysctl,
327*8e06491aSEdward Tomasz Napierala 	    "A", "Configuration string");
328*8e06491aSEdward Tomasz Napierala #endif
329*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
330*8e06491aSEdward Tomasz Napierala 	    "manufacturer", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
331*8e06491aSEdward Tomasz Napierala 	    &eth_manufacturer, sizeof(eth_manufacturer), usb_temp_sysctl,
332*8e06491aSEdward Tomasz Napierala 	    "A", "Manufacturer string");
333*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
334*8e06491aSEdward Tomasz Napierala 	    "product", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
335*8e06491aSEdward Tomasz Napierala 	    &eth_product, sizeof(eth_product), usb_temp_sysctl,
336*8e06491aSEdward Tomasz Napierala 	    "A", "Product string");
337*8e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
338*8e06491aSEdward Tomasz Napierala 	    "serial_number", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
339*8e06491aSEdward Tomasz Napierala 	    &eth_serial_number, sizeof(eth_serial_number), usb_temp_sysctl,
340*8e06491aSEdward Tomasz Napierala 	    "A", "Serial number string");
341*8e06491aSEdward Tomasz Napierala }
342*8e06491aSEdward Tomasz Napierala 
343*8e06491aSEdward Tomasz Napierala static void
344*8e06491aSEdward Tomasz Napierala eth_uninit(void *arg __unused)
345*8e06491aSEdward Tomasz Napierala {
346*8e06491aSEdward Tomasz Napierala 
347*8e06491aSEdward Tomasz Napierala 	sysctl_ctx_free(&eth_ctx_list);
348*8e06491aSEdward Tomasz Napierala }
349*8e06491aSEdward Tomasz Napierala 
350*8e06491aSEdward Tomasz Napierala SYSINIT(eth_init, SI_SUB_LOCK, SI_ORDER_FIRST, eth_init, NULL);
351*8e06491aSEdward Tomasz Napierala SYSUNINIT(eth_init, SI_SUB_LOCK, SI_ORDER_FIRST, eth_uninit, NULL);
352