Home | History | Annotate | Line # | Download | only in usb
if_urndis.c revision 1.18.2.2
      1  1.18.2.2    martin /*	$NetBSD: if_urndis.c,v 1.18.2.2 2020/04/13 08:04:49 martin Exp $ */
      2       1.1  jakllsch /*	$OpenBSD: if_urndis.c,v 1.31 2011/07/03 15:47:17 matthew Exp $ */
      3       1.1  jakllsch 
      4       1.1  jakllsch /*
      5       1.1  jakllsch  * Copyright (c) 2010 Jonathan Armani <armani (at) openbsd.org>
      6       1.1  jakllsch  * Copyright (c) 2010 Fabien Romano <fabien (at) openbsd.org>
      7       1.1  jakllsch  * Copyright (c) 2010 Michael Knudsen <mk (at) openbsd.org>
      8       1.1  jakllsch  * All rights reserved.
      9       1.1  jakllsch  *
     10       1.1  jakllsch  * Permission to use, copy, modify, and distribute this software for any
     11       1.1  jakllsch  * purpose with or without fee is hereby granted, provided that the above
     12       1.1  jakllsch  * copyright notice and this permission notice appear in all copies.
     13       1.1  jakllsch  *
     14       1.1  jakllsch  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     15       1.1  jakllsch  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     16       1.1  jakllsch  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     17       1.1  jakllsch  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     18       1.1  jakllsch  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     19       1.1  jakllsch  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     20       1.1  jakllsch  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     21       1.1  jakllsch  */
     22       1.1  jakllsch 
     23       1.1  jakllsch #include <sys/cdefs.h>
     24  1.18.2.2    martin __KERNEL_RCSID(0, "$NetBSD: if_urndis.c,v 1.18.2.2 2020/04/13 08:04:49 martin Exp $");
     25      1.14     skrll 
     26      1.14     skrll #ifdef _KERNEL_OPT
     27      1.14     skrll #include "opt_usb.h"
     28      1.14     skrll #endif
     29       1.1  jakllsch 
     30       1.1  jakllsch #include <sys/param.h>
     31       1.1  jakllsch #include <sys/kmem.h>
     32  1.18.2.2    martin 
     33  1.18.2.2    martin #include <dev/usb/usbnet.h>
     34       1.1  jakllsch #include <dev/usb/usbdevs.h>
     35       1.1  jakllsch #include <dev/usb/usbcdc.h>
     36       1.1  jakllsch 
     37  1.18.2.1  christos #include <dev/ic/rndisreg.h>
     38  1.18.2.1  christos 
     39  1.18.2.1  christos #define RNDIS_RX_LIST_CNT	1
     40  1.18.2.1  christos #define RNDIS_TX_LIST_CNT	1
     41  1.18.2.1  christos #define RNDIS_BUFSZ		1562
     42  1.18.2.1  christos 
     43  1.18.2.1  christos struct urndis_softc {
     44  1.18.2.2    martin 	struct usbnet			sc_un;
     45  1.18.2.1  christos 
     46  1.18.2.2    martin 	int				sc_ifaceno_ctl;
     47  1.18.2.1  christos 
     48  1.18.2.1  christos 	/* RNDIS device info */
     49  1.18.2.1  christos 	uint32_t			sc_filter;
     50  1.18.2.1  christos 	uint32_t			sc_maxppt;
     51  1.18.2.1  christos 	uint32_t			sc_maxtsz;
     52  1.18.2.1  christos 	uint32_t			sc_palign;
     53  1.18.2.1  christos };
     54       1.1  jakllsch 
     55       1.1  jakllsch #ifdef URNDIS_DEBUG
     56       1.1  jakllsch #define DPRINTF(x)      do { printf x; } while (0)
     57       1.1  jakllsch #else
     58       1.1  jakllsch #define DPRINTF(x)
     59       1.1  jakllsch #endif
     60       1.1  jakllsch 
     61  1.18.2.2    martin #define DEVNAME(un)	(device_xname(un->un_dev))
     62       1.1  jakllsch 
     63       1.1  jakllsch #define URNDIS_RESPONSE_LEN 0x400
     64       1.1  jakllsch 
     65       1.1  jakllsch #if 0
     66       1.1  jakllsch static void urndis_watchdog(struct ifnet *);
     67       1.1  jakllsch #endif
     68       1.1  jakllsch 
     69  1.18.2.2    martin static int urndis_uno_init(struct ifnet *);
     70  1.18.2.2    martin static void urndis_uno_rx_loop(struct usbnet *, struct usbnet_chain *,
     71  1.18.2.2    martin 			       uint32_t);
     72  1.18.2.2    martin static unsigned urndis_uno_tx_prepare(struct usbnet *, struct mbuf *,
     73  1.18.2.2    martin 				      struct usbnet_chain *);
     74  1.18.2.2    martin 
     75  1.18.2.2    martin static int urndis_init_un(struct ifnet *, struct usbnet *);
     76  1.18.2.2    martin 
     77  1.18.2.2    martin static uint32_t urndis_ctrl_handle_init(struct usbnet *,
     78  1.18.2.1  christos     const struct rndis_comp_hdr *);
     79  1.18.2.2    martin static uint32_t urndis_ctrl_handle_query(struct usbnet *,
     80  1.18.2.1  christos     const struct rndis_comp_hdr *, void **, size_t *);
     81  1.18.2.2    martin static uint32_t urndis_ctrl_handle_reset(struct usbnet *,
     82  1.18.2.2    martin     const struct rndis_comp_hdr *);
     83  1.18.2.2    martin static uint32_t urndis_ctrl_handle_status(struct usbnet *,
     84  1.18.2.1  christos     const struct rndis_comp_hdr *);
     85       1.1  jakllsch 
     86  1.18.2.2    martin static uint32_t urndis_ctrl_set(struct usbnet *, uint32_t, void *,
     87      1.13   msaitoh     size_t);
     88       1.1  jakllsch 
     89       1.1  jakllsch static int urndis_match(device_t, cfdata_t, void *);
     90       1.1  jakllsch static void urndis_attach(device_t, device_t, void *);
     91  1.18.2.2    martin 
     92  1.18.2.2    martin static const struct usbnet_ops urndis_ops = {
     93  1.18.2.2    martin 	.uno_init = urndis_uno_init,
     94  1.18.2.2    martin 	.uno_tx_prepare = urndis_uno_tx_prepare,
     95  1.18.2.2    martin 	.uno_rx_loop = urndis_uno_rx_loop,
     96  1.18.2.2    martin };
     97       1.1  jakllsch 
     98       1.1  jakllsch CFATTACH_DECL_NEW(urndis, sizeof(struct urndis_softc),
     99  1.18.2.2    martin     urndis_match, urndis_attach, usbnet_detach, usbnet_activate);
    100       1.1  jakllsch 
    101       1.1  jakllsch /*
    102       1.1  jakllsch  * Supported devices that we can't match by class IDs.
    103       1.1  jakllsch  */
    104       1.1  jakllsch static const struct usb_devno urndis_devs[] = {
    105       1.1  jakllsch 	{ USB_VENDOR_HTC,	USB_PRODUCT_HTC_ANDROID },
    106       1.1  jakllsch 	{ USB_VENDOR_SAMSUNG,	USB_PRODUCT_SAMSUNG_ANDROID2 },
    107  1.18.2.2    martin 	{ USB_VENDOR_SAMSUNG,	USB_PRODUCT_SAMSUNG_ANDROID },
    108       1.1  jakllsch };
    109       1.1  jakllsch 
    110       1.1  jakllsch static usbd_status
    111  1.18.2.2    martin urndis_ctrl_msg(struct usbnet *un, uint8_t rt, uint8_t r,
    112       1.1  jakllsch     uint16_t index, uint16_t value, void *buf, size_t buflen)
    113       1.1  jakllsch {
    114       1.1  jakllsch 	usb_device_request_t req;
    115       1.1  jakllsch 
    116       1.1  jakllsch 	req.bmRequestType = rt;
    117       1.1  jakllsch 	req.bRequest = r;
    118       1.1  jakllsch 	USETW(req.wValue, value);
    119       1.1  jakllsch 	USETW(req.wIndex, index);
    120       1.1  jakllsch 	USETW(req.wLength, buflen);
    121       1.1  jakllsch 
    122  1.18.2.2    martin 	return usbd_do_request(un->un_udev, &req, buf);
    123       1.1  jakllsch }
    124       1.1  jakllsch 
    125       1.1  jakllsch static usbd_status
    126  1.18.2.2    martin urndis_ctrl_send(struct usbnet *un, void *buf, size_t len)
    127       1.1  jakllsch {
    128  1.18.2.2    martin 	struct urndis_softc	*sc = usbnet_softc(un);
    129       1.1  jakllsch 	usbd_status err;
    130       1.1  jakllsch 
    131  1.18.2.2    martin 	if (usbnet_isdying(un))
    132       1.1  jakllsch 		return(0);
    133       1.1  jakllsch 
    134  1.18.2.2    martin 	err = urndis_ctrl_msg(un, UT_WRITE_CLASS_INTERFACE, UR_GET_STATUS,
    135       1.1  jakllsch 	    sc->sc_ifaceno_ctl, 0, buf, len);
    136       1.1  jakllsch 
    137       1.1  jakllsch 	if (err != USBD_NORMAL_COMPLETION)
    138  1.18.2.2    martin 		printf("%s: %s\n", DEVNAME(un), usbd_errstr(err));
    139       1.1  jakllsch 
    140       1.1  jakllsch 	return err;
    141       1.1  jakllsch }
    142       1.1  jakllsch 
    143  1.18.2.1  christos static struct rndis_comp_hdr *
    144  1.18.2.2    martin urndis_ctrl_recv(struct usbnet *un)
    145       1.1  jakllsch {
    146  1.18.2.2    martin 	struct urndis_softc	*sc = usbnet_softc(un);
    147  1.18.2.1  christos 	struct rndis_comp_hdr	*hdr;
    148       1.1  jakllsch 	char			*buf;
    149       1.1  jakllsch 	usbd_status		 err;
    150       1.1  jakllsch 
    151  1.18.2.2    martin 	if (usbnet_isdying(un))
    152  1.18.2.2    martin 		return(0);
    153  1.18.2.2    martin 
    154       1.1  jakllsch 	buf = kmem_alloc(URNDIS_RESPONSE_LEN, KM_SLEEP);
    155  1.18.2.2    martin 	err = urndis_ctrl_msg(un, UT_READ_CLASS_INTERFACE, UR_CLEAR_FEATURE,
    156       1.1  jakllsch 	    sc->sc_ifaceno_ctl, 0, buf, URNDIS_RESPONSE_LEN);
    157       1.1  jakllsch 
    158       1.1  jakllsch 	if (err != USBD_NORMAL_COMPLETION && err != USBD_SHORT_XFER) {
    159  1.18.2.2    martin 		printf("%s: %s\n", DEVNAME(un), usbd_errstr(err));
    160       1.1  jakllsch 		kmem_free(buf, URNDIS_RESPONSE_LEN);
    161       1.1  jakllsch 		return NULL;
    162       1.1  jakllsch 	}
    163       1.1  jakllsch 
    164  1.18.2.1  christos 	hdr = (struct rndis_comp_hdr *)buf;
    165  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_recv: type %#x len %u\n",
    166  1.18.2.2    martin 	    DEVNAME(un),
    167       1.1  jakllsch 	    le32toh(hdr->rm_type),
    168       1.1  jakllsch 	    le32toh(hdr->rm_len)));
    169       1.1  jakllsch 
    170       1.1  jakllsch 	if (le32toh(hdr->rm_len) > URNDIS_RESPONSE_LEN) {
    171       1.1  jakllsch 		printf("%s: ctrl message error: wrong size %u > %u\n",
    172  1.18.2.2    martin 		    DEVNAME(un),
    173       1.1  jakllsch 		    le32toh(hdr->rm_len),
    174       1.1  jakllsch 		    URNDIS_RESPONSE_LEN);
    175       1.1  jakllsch 		kmem_free(buf, URNDIS_RESPONSE_LEN);
    176       1.1  jakllsch 		return NULL;
    177       1.1  jakllsch 	}
    178       1.1  jakllsch 
    179       1.1  jakllsch 	return hdr;
    180       1.1  jakllsch }
    181       1.1  jakllsch 
    182       1.1  jakllsch static uint32_t
    183  1.18.2.2    martin urndis_ctrl_handle(struct usbnet *un, struct rndis_comp_hdr *hdr,
    184       1.1  jakllsch     void **buf, size_t *bufsz)
    185       1.1  jakllsch {
    186       1.1  jakllsch 	uint32_t rval;
    187       1.1  jakllsch 
    188  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_handle\n", DEVNAME(un)));
    189       1.1  jakllsch 
    190       1.1  jakllsch 	if (buf && bufsz) {
    191       1.1  jakllsch 		*buf = NULL;
    192       1.1  jakllsch 		*bufsz = 0;
    193       1.1  jakllsch 	}
    194       1.1  jakllsch 
    195       1.1  jakllsch 	switch (le32toh(hdr->rm_type)) {
    196       1.1  jakllsch 		case REMOTE_NDIS_INITIALIZE_CMPLT:
    197  1.18.2.2    martin 			rval = urndis_ctrl_handle_init(un, hdr);
    198       1.1  jakllsch 			break;
    199       1.1  jakllsch 
    200       1.1  jakllsch 		case REMOTE_NDIS_QUERY_CMPLT:
    201  1.18.2.2    martin 			rval = urndis_ctrl_handle_query(un, hdr, buf, bufsz);
    202       1.1  jakllsch 			break;
    203       1.1  jakllsch 
    204       1.1  jakllsch 		case REMOTE_NDIS_RESET_CMPLT:
    205  1.18.2.2    martin 			rval = urndis_ctrl_handle_reset(un, hdr);
    206       1.1  jakllsch 			break;
    207       1.1  jakllsch 
    208       1.1  jakllsch 		case REMOTE_NDIS_KEEPALIVE_CMPLT:
    209       1.1  jakllsch 		case REMOTE_NDIS_SET_CMPLT:
    210       1.1  jakllsch 			rval = le32toh(hdr->rm_status);
    211       1.1  jakllsch 			break;
    212       1.1  jakllsch 
    213  1.18.2.2    martin 		case REMOTE_NDIS_INDICATE_STATUS_MSG:
    214  1.18.2.2    martin 			rval = urndis_ctrl_handle_status(un, hdr);
    215  1.18.2.2    martin 			break;
    216  1.18.2.2    martin 
    217       1.1  jakllsch 		default:
    218  1.18.2.2    martin 			printf("%s: ctrl message error: unknown event %#x\n",
    219  1.18.2.2    martin 			    DEVNAME(un), le32toh(hdr->rm_type));
    220       1.1  jakllsch 			rval = RNDIS_STATUS_FAILURE;
    221       1.1  jakllsch 	}
    222       1.1  jakllsch 
    223       1.1  jakllsch 	kmem_free(hdr, URNDIS_RESPONSE_LEN);
    224       1.1  jakllsch 
    225       1.1  jakllsch 	return rval;
    226       1.1  jakllsch }
    227       1.1  jakllsch 
    228       1.1  jakllsch static uint32_t
    229  1.18.2.2    martin urndis_ctrl_handle_init(struct usbnet *un, const struct rndis_comp_hdr *hdr)
    230       1.1  jakllsch {
    231  1.18.2.2    martin 	struct urndis_softc		*sc = usbnet_softc(un);
    232  1.18.2.1  christos 	const struct rndis_init_comp	*msg;
    233       1.1  jakllsch 
    234  1.18.2.1  christos 	msg = (const struct rndis_init_comp *) hdr;
    235       1.1  jakllsch 
    236  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_handle_init: len %u rid %u status %#x "
    237  1.18.2.2    martin 	    "ver_major %u ver_minor %u devflags %#x medium %#x pktmaxcnt %u "
    238       1.1  jakllsch 	    "pktmaxsz %u align %u aflistoffset %u aflistsz %u\n",
    239  1.18.2.2    martin 	    DEVNAME(un),
    240       1.1  jakllsch 	    le32toh(msg->rm_len),
    241       1.1  jakllsch 	    le32toh(msg->rm_rid),
    242       1.1  jakllsch 	    le32toh(msg->rm_status),
    243       1.1  jakllsch 	    le32toh(msg->rm_ver_major),
    244       1.1  jakllsch 	    le32toh(msg->rm_ver_minor),
    245       1.1  jakllsch 	    le32toh(msg->rm_devflags),
    246       1.1  jakllsch 	    le32toh(msg->rm_medium),
    247       1.1  jakllsch 	    le32toh(msg->rm_pktmaxcnt),
    248       1.1  jakllsch 	    le32toh(msg->rm_pktmaxsz),
    249       1.1  jakllsch 	    le32toh(msg->rm_align),
    250       1.1  jakllsch 	    le32toh(msg->rm_aflistoffset),
    251       1.1  jakllsch 	    le32toh(msg->rm_aflistsz)));
    252       1.1  jakllsch 
    253       1.1  jakllsch 	if (le32toh(msg->rm_status) != RNDIS_STATUS_SUCCESS) {
    254  1.18.2.2    martin 		printf("%s: init failed %#x\n",
    255  1.18.2.2    martin 		    DEVNAME(un),
    256       1.1  jakllsch 		    le32toh(msg->rm_status));
    257       1.1  jakllsch 
    258       1.1  jakllsch 		return le32toh(msg->rm_status);
    259       1.1  jakllsch 	}
    260       1.1  jakllsch 
    261       1.1  jakllsch 	if (le32toh(msg->rm_devflags) != RNDIS_DF_CONNECTIONLESS) {
    262  1.18.2.2    martin 		printf("%s: wrong device type (current type: %#x)\n",
    263  1.18.2.2    martin 		    DEVNAME(un),
    264       1.1  jakllsch 		    le32toh(msg->rm_devflags));
    265       1.1  jakllsch 
    266       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    267       1.1  jakllsch 	}
    268       1.1  jakllsch 
    269       1.1  jakllsch 	if (le32toh(msg->rm_medium) != RNDIS_MEDIUM_802_3) {
    270  1.18.2.2    martin 		printf("%s: medium not 802.3 (current medium: %#x)\n",
    271  1.18.2.2    martin 		    DEVNAME(un), le32toh(msg->rm_medium));
    272       1.1  jakllsch 
    273       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    274       1.1  jakllsch 	}
    275       1.1  jakllsch 
    276  1.18.2.1  christos 	if (le32toh(msg->rm_ver_major) != RNDIS_MAJOR_VERSION ||
    277  1.18.2.1  christos 	    le32toh(msg->rm_ver_minor) != RNDIS_MINOR_VERSION) {
    278  1.18.2.1  christos 		printf("%s: version not %u.%u (current version: %u.%u)\n",
    279  1.18.2.2    martin 		    DEVNAME(un), RNDIS_MAJOR_VERSION, RNDIS_MINOR_VERSION,
    280  1.18.2.1  christos 		    le32toh(msg->rm_ver_major), le32toh(msg->rm_ver_minor));
    281  1.18.2.1  christos 
    282  1.18.2.1  christos 		return RNDIS_STATUS_FAILURE;
    283  1.18.2.1  christos 	}
    284  1.18.2.1  christos 
    285  1.18.2.1  christos 	sc->sc_maxppt = le32toh(msg->rm_pktmaxcnt);
    286  1.18.2.1  christos 	sc->sc_maxtsz = le32toh(msg->rm_pktmaxsz);
    287  1.18.2.1  christos 	sc->sc_palign = 1U << le32toh(msg->rm_align);
    288       1.1  jakllsch 
    289       1.1  jakllsch 	return le32toh(msg->rm_status);
    290       1.1  jakllsch }
    291       1.1  jakllsch 
    292       1.1  jakllsch static uint32_t
    293  1.18.2.2    martin urndis_ctrl_handle_query(struct usbnet *un,
    294  1.18.2.1  christos     const struct rndis_comp_hdr *hdr, void **buf, size_t *bufsz)
    295       1.1  jakllsch {
    296  1.18.2.1  christos 	const struct rndis_query_comp	*msg;
    297       1.1  jakllsch 
    298  1.18.2.1  christos 	msg = (const struct rndis_query_comp *) hdr;
    299       1.1  jakllsch 
    300  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_handle_query: len %u rid %u status %#x "
    301       1.1  jakllsch 	    "buflen %u bufoff %u\n",
    302  1.18.2.2    martin 	    DEVNAME(un),
    303       1.1  jakllsch 	    le32toh(msg->rm_len),
    304       1.1  jakllsch 	    le32toh(msg->rm_rid),
    305       1.1  jakllsch 	    le32toh(msg->rm_status),
    306       1.1  jakllsch 	    le32toh(msg->rm_infobuflen),
    307       1.1  jakllsch 	    le32toh(msg->rm_infobufoffset)));
    308       1.1  jakllsch 
    309       1.1  jakllsch 	if (buf && bufsz) {
    310       1.1  jakllsch 		*buf = NULL;
    311       1.1  jakllsch 		*bufsz = 0;
    312       1.1  jakllsch 	}
    313       1.1  jakllsch 
    314       1.1  jakllsch 	if (le32toh(msg->rm_status) != RNDIS_STATUS_SUCCESS) {
    315  1.18.2.2    martin 		printf("%s: query failed %#x\n",
    316  1.18.2.2    martin 		    DEVNAME(un),
    317       1.1  jakllsch 		    le32toh(msg->rm_status));
    318       1.1  jakllsch 
    319       1.1  jakllsch 		return le32toh(msg->rm_status);
    320       1.1  jakllsch 	}
    321       1.1  jakllsch 
    322       1.1  jakllsch 	if (le32toh(msg->rm_infobuflen) + le32toh(msg->rm_infobufoffset) +
    323       1.1  jakllsch 	    RNDIS_HEADER_OFFSET > le32toh(msg->rm_len)) {
    324       1.1  jakllsch 		printf("%s: ctrl message error: invalid query info "
    325       1.1  jakllsch 		    "len/offset/end_position(%u/%u/%u) -> "
    326       1.1  jakllsch 		    "go out of buffer limit %u\n",
    327  1.18.2.2    martin 		    DEVNAME(un),
    328       1.1  jakllsch 		    le32toh(msg->rm_infobuflen),
    329       1.5  christos 		    le32toh(msg->rm_infobufoffset),
    330       1.1  jakllsch 		    le32toh(msg->rm_infobuflen) +
    331       1.1  jakllsch 		    le32toh(msg->rm_infobufoffset) + (uint32_t)RNDIS_HEADER_OFFSET,
    332       1.1  jakllsch 		    le32toh(msg->rm_len));
    333       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    334       1.1  jakllsch 	}
    335       1.1  jakllsch 
    336       1.1  jakllsch 	if (buf && bufsz) {
    337      1.16       chs 		const char *p;
    338      1.16       chs 
    339       1.1  jakllsch 		*buf = kmem_alloc(le32toh(msg->rm_infobuflen), KM_SLEEP);
    340      1.16       chs 		*bufsz = le32toh(msg->rm_infobuflen);
    341       1.1  jakllsch 
    342      1.16       chs 		p = (const char *)&msg->rm_rid;
    343      1.16       chs 		p += le32toh(msg->rm_infobufoffset);
    344      1.16       chs 		memcpy(*buf, p, le32toh(msg->rm_infobuflen));
    345       1.1  jakllsch 	}
    346       1.1  jakllsch 
    347       1.1  jakllsch 	return le32toh(msg->rm_status);
    348       1.1  jakllsch }
    349       1.1  jakllsch 
    350       1.1  jakllsch static uint32_t
    351  1.18.2.2    martin urndis_ctrl_handle_reset(struct usbnet *un, const struct rndis_comp_hdr *hdr)
    352       1.1  jakllsch {
    353  1.18.2.2    martin 	struct urndis_softc		*sc = usbnet_softc(un);
    354  1.18.2.1  christos 	const struct rndis_reset_comp	*msg;
    355       1.1  jakllsch 	uint32_t			 rval;
    356       1.1  jakllsch 
    357  1.18.2.1  christos 	msg = (const struct rndis_reset_comp *) hdr;
    358       1.1  jakllsch 
    359       1.1  jakllsch 	rval = le32toh(msg->rm_status);
    360       1.1  jakllsch 
    361  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_handle_reset: len %u status %#x "
    362       1.1  jakllsch 	    "adrreset %u\n",
    363  1.18.2.2    martin 	    DEVNAME(un),
    364       1.1  jakllsch 	    le32toh(msg->rm_len),
    365       1.1  jakllsch 	    rval,
    366       1.1  jakllsch 	    le32toh(msg->rm_adrreset)));
    367       1.1  jakllsch 
    368       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    369  1.18.2.2    martin 		printf("%s: reset failed %#x\n", DEVNAME(un), rval);
    370       1.1  jakllsch 		return rval;
    371       1.1  jakllsch 	}
    372       1.1  jakllsch 
    373       1.1  jakllsch 	if (le32toh(msg->rm_adrreset) != 0) {
    374       1.1  jakllsch 		uint32_t filter;
    375       1.1  jakllsch 
    376       1.1  jakllsch 		filter = htole32(sc->sc_filter);
    377  1.18.2.2    martin 		rval = urndis_ctrl_set(un, OID_GEN_CURRENT_PACKET_FILTER,
    378       1.1  jakllsch 		    &filter, sizeof(filter));
    379       1.1  jakllsch 		if (rval != RNDIS_STATUS_SUCCESS) {
    380       1.1  jakllsch 			printf("%s: unable to reset data filters\n",
    381  1.18.2.2    martin 			    DEVNAME(un));
    382       1.1  jakllsch 			return rval;
    383       1.1  jakllsch 		}
    384       1.1  jakllsch 	}
    385       1.1  jakllsch 
    386       1.1  jakllsch 	return rval;
    387       1.1  jakllsch }
    388       1.1  jakllsch 
    389       1.1  jakllsch static uint32_t
    390  1.18.2.2    martin urndis_ctrl_handle_status(struct usbnet *un,
    391  1.18.2.2    martin     const struct rndis_comp_hdr *hdr)
    392  1.18.2.2    martin {
    393  1.18.2.2    martin 	const struct rndis_status_msg	*msg;
    394  1.18.2.2    martin 	uint32_t			rval;
    395  1.18.2.2    martin 
    396  1.18.2.2    martin 	msg = (const struct rndis_status_msg *)hdr;
    397  1.18.2.2    martin 
    398  1.18.2.2    martin 	rval = le32toh(msg->rm_status);
    399  1.18.2.2    martin 
    400  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_handle_status: len %u status %#x "
    401  1.18.2.2    martin 	    "stbuflen %u\n",
    402  1.18.2.2    martin 	    DEVNAME(un),
    403  1.18.2.2    martin 	    le32toh(msg->rm_len),
    404  1.18.2.2    martin 	    rval,
    405  1.18.2.2    martin 	    le32toh(msg->rm_stbuflen)));
    406  1.18.2.2    martin 
    407  1.18.2.2    martin 	switch (rval) {
    408  1.18.2.2    martin 		case RNDIS_STATUS_MEDIA_CONNECT:
    409  1.18.2.2    martin 		case RNDIS_STATUS_MEDIA_DISCONNECT:
    410  1.18.2.2    martin 		case RNDIS_STATUS_OFFLOAD_CURRENT_CONFIG:
    411  1.18.2.2    martin 			rval = RNDIS_STATUS_SUCCESS;
    412  1.18.2.2    martin 			break;
    413  1.18.2.2    martin 
    414  1.18.2.2    martin 		default:
    415  1.18.2.2    martin 		        printf("%s: status %#x\n", DEVNAME(un), rval);
    416  1.18.2.2    martin 	}
    417  1.18.2.2    martin 
    418  1.18.2.2    martin 	return rval;
    419  1.18.2.2    martin }
    420  1.18.2.2    martin 
    421  1.18.2.2    martin static uint32_t
    422  1.18.2.2    martin urndis_ctrl_init(struct usbnet *un)
    423       1.1  jakllsch {
    424  1.18.2.1  christos 	struct rndis_init_req	*msg;
    425       1.1  jakllsch 	uint32_t		 rval;
    426  1.18.2.1  christos 	struct rndis_comp_hdr	*hdr;
    427       1.1  jakllsch 
    428       1.1  jakllsch 	msg = kmem_alloc(sizeof(*msg), KM_SLEEP);
    429       1.1  jakllsch 	msg->rm_type = htole32(REMOTE_NDIS_INITIALIZE_MSG);
    430       1.1  jakllsch 	msg->rm_len = htole32(sizeof(*msg));
    431       1.1  jakllsch 	msg->rm_rid = htole32(0);
    432  1.18.2.1  christos 	msg->rm_ver_major = htole32(RNDIS_MAJOR_VERSION);
    433  1.18.2.1  christos 	msg->rm_ver_minor = htole32(RNDIS_MINOR_VERSION);
    434       1.1  jakllsch 	msg->rm_max_xfersz = htole32(RNDIS_BUFSZ);
    435       1.1  jakllsch 
    436       1.1  jakllsch 	DPRINTF(("%s: urndis_ctrl_init send: type %u len %u rid %u ver_major %u "
    437       1.1  jakllsch 	    "ver_minor %u max_xfersz %u\n",
    438  1.18.2.2    martin 	    DEVNAME(un),
    439       1.1  jakllsch 	    le32toh(msg->rm_type),
    440       1.1  jakllsch 	    le32toh(msg->rm_len),
    441       1.1  jakllsch 	    le32toh(msg->rm_rid),
    442       1.1  jakllsch 	    le32toh(msg->rm_ver_major),
    443       1.1  jakllsch 	    le32toh(msg->rm_ver_minor),
    444       1.1  jakllsch 	    le32toh(msg->rm_max_xfersz)));
    445       1.1  jakllsch 
    446  1.18.2.2    martin 	rval = urndis_ctrl_send(un, msg, sizeof(*msg));
    447       1.1  jakllsch 	kmem_free(msg, sizeof(*msg));
    448       1.1  jakllsch 
    449       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    450  1.18.2.2    martin 		printf("%s: init failed\n", DEVNAME(un));
    451       1.1  jakllsch 		return rval;
    452       1.1  jakllsch 	}
    453       1.1  jakllsch 
    454  1.18.2.2    martin 	if ((hdr = urndis_ctrl_recv(un)) == NULL) {
    455  1.18.2.2    martin 		printf("%s: unable to get init response\n", DEVNAME(un));
    456       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    457       1.1  jakllsch 	}
    458  1.18.2.2    martin 	rval = urndis_ctrl_handle(un, hdr, NULL, NULL);
    459       1.1  jakllsch 
    460       1.1  jakllsch 	return rval;
    461       1.1  jakllsch }
    462       1.1  jakllsch 
    463       1.1  jakllsch #if 0
    464       1.1  jakllsch static uint32_t
    465  1.18.2.2    martin urndis_ctrl_halt(struct usbnet *un)
    466       1.1  jakllsch {
    467  1.18.2.1  christos 	struct rndis_halt_req	*msg;
    468       1.1  jakllsch 	uint32_t		 rval;
    469       1.1  jakllsch 
    470       1.1  jakllsch 	msg = kmem_alloc(sizeof(*msg), KM_SLEEP);
    471       1.1  jakllsch 	msg->rm_type = htole32(REMOTE_NDIS_HALT_MSG);
    472       1.1  jakllsch 	msg->rm_len = htole32(sizeof(*msg));
    473       1.1  jakllsch 	msg->rm_rid = 0;
    474       1.1  jakllsch 
    475       1.1  jakllsch 	DPRINTF(("%s: urndis_ctrl_halt send: type %u len %u rid %u\n",
    476  1.18.2.2    martin 	    DEVNAME(un),
    477       1.1  jakllsch 	    le32toh(msg->rm_type),
    478       1.1  jakllsch 	    le32toh(msg->rm_len),
    479       1.1  jakllsch 	    le32toh(msg->rm_rid)));
    480       1.1  jakllsch 
    481  1.18.2.2    martin 	rval = urndis_ctrl_send(un, msg, sizeof(*msg));
    482       1.1  jakllsch 	kmem_free(msg, sizeof(*msg));
    483       1.1  jakllsch 
    484       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS)
    485  1.18.2.2    martin 		printf("%s: halt failed\n", DEVNAME(un));
    486       1.1  jakllsch 
    487       1.1  jakllsch 	return rval;
    488       1.1  jakllsch }
    489       1.1  jakllsch #endif
    490       1.1  jakllsch 
    491       1.1  jakllsch static uint32_t
    492  1.18.2.2    martin urndis_ctrl_query(struct usbnet *un, uint32_t oid,
    493       1.1  jakllsch     void *qbuf, size_t qlen,
    494       1.1  jakllsch     void **rbuf, size_t *rbufsz)
    495       1.1  jakllsch {
    496  1.18.2.1  christos 	struct rndis_query_req	*msg;
    497       1.1  jakllsch 	uint32_t		 rval;
    498  1.18.2.1  christos 	struct rndis_comp_hdr	*hdr;
    499       1.1  jakllsch 
    500       1.1  jakllsch 	msg = kmem_alloc(sizeof(*msg) + qlen, KM_SLEEP);
    501       1.1  jakllsch 	msg->rm_type = htole32(REMOTE_NDIS_QUERY_MSG);
    502       1.1  jakllsch 	msg->rm_len = htole32(sizeof(*msg) + qlen);
    503       1.1  jakllsch 	msg->rm_rid = 0; /* XXX */
    504       1.1  jakllsch 	msg->rm_oid = htole32(oid);
    505       1.1  jakllsch 	msg->rm_infobuflen = htole32(qlen);
    506       1.1  jakllsch 	if (qlen != 0) {
    507       1.1  jakllsch 		msg->rm_infobufoffset = htole32(20);
    508       1.1  jakllsch 		memcpy((char*)msg + 20, qbuf, qlen);
    509       1.1  jakllsch 	} else
    510       1.1  jakllsch 		msg->rm_infobufoffset = 0;
    511       1.1  jakllsch 	msg->rm_devicevchdl = 0;
    512       1.1  jakllsch 
    513  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_query send: type %u len %u rid %u oid %#x "
    514       1.1  jakllsch 	    "infobuflen %u infobufoffset %u devicevchdl %u\n",
    515  1.18.2.2    martin 	    DEVNAME(un),
    516       1.1  jakllsch 	    le32toh(msg->rm_type),
    517       1.1  jakllsch 	    le32toh(msg->rm_len),
    518       1.1  jakllsch 	    le32toh(msg->rm_rid),
    519       1.1  jakllsch 	    le32toh(msg->rm_oid),
    520       1.1  jakllsch 	    le32toh(msg->rm_infobuflen),
    521       1.1  jakllsch 	    le32toh(msg->rm_infobufoffset),
    522       1.1  jakllsch 	    le32toh(msg->rm_devicevchdl)));
    523       1.1  jakllsch 
    524  1.18.2.2    martin 	rval = urndis_ctrl_send(un, msg, sizeof(*msg));
    525       1.7     skrll 	kmem_free(msg, sizeof(*msg) + qlen);
    526       1.1  jakllsch 
    527       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    528  1.18.2.2    martin 		printf("%s: query failed\n", DEVNAME(un));
    529       1.1  jakllsch 		return rval;
    530       1.1  jakllsch 	}
    531       1.1  jakllsch 
    532  1.18.2.2    martin 	if ((hdr = urndis_ctrl_recv(un)) == NULL) {
    533  1.18.2.2    martin 		printf("%s: unable to get query response\n", DEVNAME(un));
    534       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    535       1.1  jakllsch 	}
    536  1.18.2.2    martin 	rval = urndis_ctrl_handle(un, hdr, rbuf, rbufsz);
    537       1.1  jakllsch 
    538       1.1  jakllsch 	return rval;
    539       1.1  jakllsch }
    540       1.1  jakllsch 
    541       1.1  jakllsch static uint32_t
    542  1.18.2.2    martin urndis_ctrl_set(struct usbnet *un, uint32_t oid, void *buf, size_t len)
    543       1.1  jakllsch {
    544  1.18.2.1  christos 	struct rndis_set_req	*msg;
    545       1.1  jakllsch 	uint32_t		 rval;
    546  1.18.2.1  christos 	struct rndis_comp_hdr	*hdr;
    547       1.1  jakllsch 
    548       1.1  jakllsch 	msg = kmem_alloc(sizeof(*msg) + len, KM_SLEEP);
    549       1.1  jakllsch 	msg->rm_type = htole32(REMOTE_NDIS_SET_MSG);
    550       1.1  jakllsch 	msg->rm_len = htole32(sizeof(*msg) + len);
    551       1.1  jakllsch 	msg->rm_rid = 0; /* XXX */
    552       1.1  jakllsch 	msg->rm_oid = htole32(oid);
    553       1.1  jakllsch 	msg->rm_infobuflen = htole32(len);
    554       1.1  jakllsch 	if (len != 0) {
    555       1.1  jakllsch 		msg->rm_infobufoffset = htole32(20);
    556       1.1  jakllsch 		memcpy((char*)msg + 20, buf, len);
    557       1.1  jakllsch 	} else
    558       1.1  jakllsch 		msg->rm_infobufoffset = 0;
    559       1.1  jakllsch 	msg->rm_devicevchdl = 0;
    560       1.1  jakllsch 
    561  1.18.2.2    martin 	DPRINTF(("%s: urndis_ctrl_set send: type %u len %u rid %u oid %#x "
    562       1.1  jakllsch 	    "infobuflen %u infobufoffset %u devicevchdl %u\n",
    563  1.18.2.2    martin 	    DEVNAME(un),
    564       1.1  jakllsch 	    le32toh(msg->rm_type),
    565       1.1  jakllsch 	    le32toh(msg->rm_len),
    566       1.1  jakllsch 	    le32toh(msg->rm_rid),
    567       1.1  jakllsch 	    le32toh(msg->rm_oid),
    568       1.1  jakllsch 	    le32toh(msg->rm_infobuflen),
    569       1.1  jakllsch 	    le32toh(msg->rm_infobufoffset),
    570       1.1  jakllsch 	    le32toh(msg->rm_devicevchdl)));
    571       1.1  jakllsch 
    572  1.18.2.2    martin 	rval = urndis_ctrl_send(un, msg, sizeof(*msg));
    573       1.7     skrll 	kmem_free(msg, sizeof(*msg) + len);
    574       1.1  jakllsch 
    575       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    576  1.18.2.2    martin 		printf("%s: set failed\n", DEVNAME(un));
    577       1.1  jakllsch 		return rval;
    578       1.1  jakllsch 	}
    579       1.1  jakllsch 
    580  1.18.2.2    martin 	if ((hdr = urndis_ctrl_recv(un)) == NULL) {
    581  1.18.2.2    martin 		printf("%s: unable to get set response\n", DEVNAME(un));
    582       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    583       1.1  jakllsch 	}
    584  1.18.2.2    martin 	rval = urndis_ctrl_handle(un, hdr, NULL, NULL);
    585       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS)
    586  1.18.2.2    martin 		printf("%s: set failed %#x\n", DEVNAME(un), rval);
    587       1.5  christos 
    588       1.1  jakllsch 	return rval;
    589       1.1  jakllsch }
    590       1.1  jakllsch 
    591       1.1  jakllsch #if 0
    592       1.1  jakllsch static uint32_t
    593  1.18.2.2    martin urndis_ctrl_set_param(struct urndis_softc *un,
    594       1.1  jakllsch     const char *name,
    595       1.1  jakllsch     uint32_t type,
    596       1.1  jakllsch     void *buf,
    597       1.1  jakllsch     size_t len)
    598       1.1  jakllsch {
    599  1.18.2.1  christos 	struct rndis_set_parameter	*param;
    600       1.1  jakllsch 	uint32_t			 rval;
    601       1.1  jakllsch 	size_t				 namelen, tlen;
    602       1.1  jakllsch 
    603       1.1  jakllsch 	if (name)
    604       1.1  jakllsch 		namelen = strlen(name);
    605       1.1  jakllsch 	else
    606       1.1  jakllsch 		namelen = 0;
    607       1.1  jakllsch 	tlen = sizeof(*param) + len + namelen;
    608       1.1  jakllsch 	param = kmem_alloc(tlen, KM_SLEEP);
    609       1.1  jakllsch 	param->rm_namelen = htole32(namelen);
    610       1.1  jakllsch 	param->rm_valuelen = htole32(len);
    611       1.1  jakllsch 	param->rm_type = htole32(type);
    612       1.1  jakllsch 	if (namelen != 0) {
    613       1.1  jakllsch 		param->rm_nameoffset = htole32(20);
    614       1.1  jakllsch 		memcpy(param + 20, name, namelen);
    615       1.1  jakllsch 	} else
    616       1.1  jakllsch 		param->rm_nameoffset = 0;
    617       1.1  jakllsch 	if (len != 0) {
    618       1.1  jakllsch 		param->rm_valueoffset = htole32(20 + namelen);
    619       1.1  jakllsch 		memcpy(param + 20 + namelen, buf, len);
    620       1.1  jakllsch 	} else
    621       1.1  jakllsch 		param->rm_valueoffset = 0;
    622       1.1  jakllsch 
    623       1.1  jakllsch 	DPRINTF(("%s: urndis_ctrl_set_param send: nameoffset %u namelen %u "
    624  1.18.2.2    martin 	    "type %#x valueoffset %u valuelen %u\n",
    625  1.18.2.2    martin 	    DEVNAME(un),
    626       1.1  jakllsch 	    le32toh(param->rm_nameoffset),
    627       1.1  jakllsch 	    le32toh(param->rm_namelen),
    628       1.1  jakllsch 	    le32toh(param->rm_type),
    629       1.1  jakllsch 	    le32toh(param->rm_valueoffset),
    630       1.1  jakllsch 	    le32toh(param->rm_valuelen)));
    631       1.1  jakllsch 
    632  1.18.2.2    martin 	rval = urndis_ctrl_set(un, OID_GEN_RNDIS_CONFIG_PARAMETER, param, tlen);
    633       1.1  jakllsch 	kmem_free(param, tlen);
    634       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS)
    635  1.18.2.2    martin 		printf("%s: set param failed %#x\n", DEVNAME(un), rval);
    636       1.1  jakllsch 
    637       1.1  jakllsch 	return rval;
    638       1.1  jakllsch }
    639       1.1  jakllsch 
    640       1.1  jakllsch /* XXX : adrreset, get it from response */
    641       1.1  jakllsch static uint32_t
    642  1.18.2.2    martin urndis_ctrl_reset(struct usbnet *un)
    643       1.1  jakllsch {
    644  1.18.2.1  christos 	struct rndis_reset_req		*reset;
    645       1.1  jakllsch 	uint32_t			 rval;
    646  1.18.2.1  christos 	struct rndis_comp_hdr		*hdr;
    647       1.1  jakllsch 
    648       1.1  jakllsch 	reset = kmem_alloc(sizeof(*reset), KM_SLEEP);
    649       1.1  jakllsch 	reset->rm_type = htole32(REMOTE_NDIS_RESET_MSG);
    650       1.1  jakllsch 	reset->rm_len = htole32(sizeof(*reset));
    651       1.1  jakllsch 	reset->rm_rid = 0; /* XXX rm_rid == reserved ... remove ? */
    652       1.1  jakllsch 
    653       1.1  jakllsch 	DPRINTF(("%s: urndis_ctrl_reset send: type %u len %u rid %u\n",
    654  1.18.2.2    martin 	    DEVNAME(un),
    655       1.1  jakllsch 	    le32toh(reset->rm_type),
    656       1.1  jakllsch 	    le32toh(reset->rm_len),
    657       1.1  jakllsch 	    le32toh(reset->rm_rid)));
    658       1.1  jakllsch 
    659  1.18.2.2    martin 	rval = urndis_ctrl_send(un, reset, sizeof(*reset));
    660       1.1  jakllsch 	kmem_free(reset, sizeof(*reset));
    661       1.1  jakllsch 
    662       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    663  1.18.2.2    martin 		printf("%s: reset failed\n", DEVNAME(un));
    664       1.1  jakllsch 		return rval;
    665       1.1  jakllsch 	}
    666       1.1  jakllsch 
    667  1.18.2.2    martin 	if ((hdr = urndis_ctrl_recv(un)) == NULL) {
    668  1.18.2.2    martin 		printf("%s: unable to get reset response\n", DEVNAME(un));
    669       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    670       1.1  jakllsch 	}
    671  1.18.2.2    martin 	rval = urndis_ctrl_handle(un, hdr, NULL, NULL);
    672       1.1  jakllsch 
    673       1.1  jakllsch 	return rval;
    674       1.1  jakllsch }
    675       1.1  jakllsch 
    676       1.1  jakllsch static uint32_t
    677  1.18.2.2    martin urndis_ctrl_keepalive(struct usbnet *un)
    678       1.1  jakllsch {
    679  1.18.2.1  christos 	struct rndis_keepalive_req	*keep;
    680       1.1  jakllsch 	uint32_t			 rval;
    681  1.18.2.1  christos 	struct rndis_comp_hdr		*hdr;
    682       1.1  jakllsch 
    683       1.1  jakllsch 	keep = kmem_alloc(sizeof(*keep), KM_SLEEP);
    684       1.1  jakllsch 	keep->rm_type = htole32(REMOTE_NDIS_KEEPALIVE_MSG);
    685       1.1  jakllsch 	keep->rm_len = htole32(sizeof(*keep));
    686       1.1  jakllsch 	keep->rm_rid = 0; /* XXX rm_rid == reserved ... remove ? */
    687       1.1  jakllsch 
    688       1.1  jakllsch 	DPRINTF(("%s: urndis_ctrl_keepalive: type %u len %u rid %u\n",
    689  1.18.2.2    martin 	    DEVNAME(un),
    690       1.1  jakllsch 	    le32toh(keep->rm_type),
    691       1.1  jakllsch 	    le32toh(keep->rm_len),
    692       1.1  jakllsch 	    le32toh(keep->rm_rid)));
    693       1.1  jakllsch 
    694  1.18.2.2    martin 	rval = urndis_ctrl_send(un, keep, sizeof(*keep));
    695       1.1  jakllsch 	kmem_free(keep, sizeof(*keep));
    696       1.1  jakllsch 
    697       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    698  1.18.2.2    martin 		printf("%s: keepalive failed\n", DEVNAME(un));
    699       1.1  jakllsch 		return rval;
    700       1.1  jakllsch 	}
    701       1.1  jakllsch 
    702  1.18.2.2    martin 	if ((hdr = urndis_ctrl_recv(un)) == NULL) {
    703  1.18.2.2    martin 		printf("%s: unable to get keepalive response\n", DEVNAME(un));
    704       1.1  jakllsch 		return RNDIS_STATUS_FAILURE;
    705       1.1  jakllsch 	}
    706  1.18.2.2    martin 	rval = urndis_ctrl_handle(un, hdr, NULL, NULL);
    707       1.1  jakllsch 	if (rval != RNDIS_STATUS_SUCCESS) {
    708  1.18.2.2    martin 		printf("%s: keepalive failed %#x\n", DEVNAME(un), rval);
    709  1.18.2.2    martin 		urndis_ctrl_reset(un);
    710       1.1  jakllsch 	}
    711       1.1  jakllsch 
    712       1.1  jakllsch 	return rval;
    713       1.1  jakllsch }
    714       1.1  jakllsch #endif
    715       1.1  jakllsch 
    716  1.18.2.2    martin static unsigned
    717  1.18.2.2    martin urndis_uno_tx_prepare(struct usbnet *un, struct mbuf *m, struct usbnet_chain *c)
    718       1.1  jakllsch {
    719  1.18.2.1  christos 	struct rndis_packet_msg		*msg;
    720       1.1  jakllsch 
    721  1.18.2.2    martin 	if ((unsigned)m->m_pkthdr.len > un->un_tx_bufsz - sizeof(*msg))
    722  1.18.2.2    martin 		return 0;
    723       1.1  jakllsch 
    724  1.18.2.2    martin 	msg = (struct rndis_packet_msg *)c->unc_buf;
    725       1.1  jakllsch 
    726       1.1  jakllsch 	memset(msg, 0, sizeof(*msg));
    727       1.1  jakllsch 	msg->rm_type = htole32(REMOTE_NDIS_PACKET_MSG);
    728       1.1  jakllsch 	msg->rm_len = htole32(sizeof(*msg) + m->m_pkthdr.len);
    729       1.1  jakllsch 
    730       1.1  jakllsch 	msg->rm_dataoffset = htole32(RNDIS_DATA_OFFSET);
    731       1.1  jakllsch 	msg->rm_datalen = htole32(m->m_pkthdr.len);
    732       1.1  jakllsch 
    733       1.1  jakllsch 	m_copydata(m, 0, m->m_pkthdr.len,
    734       1.1  jakllsch 	    ((char*)msg + RNDIS_DATA_OFFSET + RNDIS_HEADER_OFFSET));
    735       1.1  jakllsch 
    736  1.18.2.2    martin 	DPRINTF(("%s: %s type %#x len %u data(off %u len %u)\n",
    737  1.18.2.2    martin 	    __func__,
    738  1.18.2.2    martin 	    DEVNAME(un),
    739       1.1  jakllsch 	    le32toh(msg->rm_type),
    740       1.1  jakllsch 	    le32toh(msg->rm_len),
    741       1.1  jakllsch 	    le32toh(msg->rm_dataoffset),
    742       1.1  jakllsch 	    le32toh(msg->rm_datalen)));
    743       1.1  jakllsch 
    744  1.18.2.2    martin 	return le32toh(msg->rm_len);
    745       1.1  jakllsch }
    746       1.1  jakllsch 
    747       1.1  jakllsch static void
    748  1.18.2.2    martin urndis_uno_rx_loop(struct usbnet * un, struct usbnet_chain *c,
    749  1.18.2.2    martin 		   uint32_t total_len)
    750       1.1  jakllsch {
    751  1.18.2.1  christos 	struct rndis_packet_msg	*msg;
    752  1.18.2.2    martin 	struct ifnet		*ifp = usbnet_ifp(un);
    753       1.1  jakllsch 	int			 offset;
    754       1.1  jakllsch 
    755       1.1  jakllsch 	offset = 0;
    756       1.5  christos 
    757  1.18.2.2    martin 	while (total_len > 1) {
    758  1.18.2.2    martin 		msg = (struct rndis_packet_msg *)((char*)c->unc_buf + offset);
    759       1.1  jakllsch 
    760  1.18.2.2    martin 		DPRINTF(("%s: %s buffer size left %u\n", DEVNAME(un), __func__,
    761  1.18.2.2    martin 		    total_len));
    762       1.1  jakllsch 
    763  1.18.2.2    martin 		if (total_len < sizeof(*msg)) {
    764  1.18.2.2    martin 			printf("%s: urndis_decap invalid buffer total_len %u < "
    765       1.1  jakllsch 			    "minimum header %zu\n",
    766  1.18.2.2    martin 			    DEVNAME(un),
    767  1.18.2.2    martin 			    total_len,
    768       1.1  jakllsch 			    sizeof(*msg));
    769       1.1  jakllsch 			return;
    770       1.1  jakllsch 		}
    771       1.1  jakllsch 
    772  1.18.2.2    martin 		DPRINTF(("%s: urndis_decap total_len %u data(off:%u len:%u) "
    773       1.1  jakllsch 		    "oobdata(off:%u len:%u nb:%u) perpacket(off:%u len:%u)\n",
    774  1.18.2.2    martin 		    DEVNAME(un),
    775       1.1  jakllsch 		    le32toh(msg->rm_len),
    776       1.1  jakllsch 		    le32toh(msg->rm_dataoffset),
    777       1.1  jakllsch 		    le32toh(msg->rm_datalen),
    778       1.1  jakllsch 		    le32toh(msg->rm_oobdataoffset),
    779       1.1  jakllsch 		    le32toh(msg->rm_oobdatalen),
    780       1.1  jakllsch 		    le32toh(msg->rm_oobdataelements),
    781       1.1  jakllsch 		    le32toh(msg->rm_pktinfooffset),
    782       1.1  jakllsch 		    le32toh(msg->rm_pktinfooffset)));
    783       1.1  jakllsch 
    784       1.1  jakllsch 		if (le32toh(msg->rm_type) != REMOTE_NDIS_PACKET_MSG) {
    785  1.18.2.2    martin 			printf("%s: urndis_decap invalid type %#x != %#x\n",
    786  1.18.2.2    martin 			    DEVNAME(un),
    787       1.1  jakllsch 			    le32toh(msg->rm_type),
    788       1.1  jakllsch 			    REMOTE_NDIS_PACKET_MSG);
    789       1.1  jakllsch 			return;
    790       1.1  jakllsch 		}
    791       1.1  jakllsch 		if (le32toh(msg->rm_len) < sizeof(*msg)) {
    792       1.1  jakllsch 			printf("%s: urndis_decap invalid msg len %u < %zu\n",
    793  1.18.2.2    martin 			    DEVNAME(un),
    794       1.1  jakllsch 			    le32toh(msg->rm_len),
    795       1.1  jakllsch 			    sizeof(*msg));
    796       1.1  jakllsch 			return;
    797       1.1  jakllsch 		}
    798  1.18.2.2    martin 		if (le32toh(msg->rm_len) > total_len) {
    799       1.1  jakllsch 			printf("%s: urndis_decap invalid msg len %u > buffer "
    800  1.18.2.2    martin 			    "total_len %u\n",
    801  1.18.2.2    martin 			    DEVNAME(un),
    802       1.1  jakllsch 			    le32toh(msg->rm_len),
    803  1.18.2.2    martin 			    total_len);
    804       1.1  jakllsch 			return;
    805       1.1  jakllsch 		}
    806       1.1  jakllsch 
    807       1.1  jakllsch 		if (le32toh(msg->rm_dataoffset) +
    808       1.5  christos 		    le32toh(msg->rm_datalen) + RNDIS_HEADER_OFFSET
    809       1.1  jakllsch 		        > le32toh(msg->rm_len)) {
    810       1.1  jakllsch 			printf("%s: urndis_decap invalid data "
    811       1.1  jakllsch 			    "len/offset/end_position(%u/%u/%u) -> "
    812       1.1  jakllsch 			    "go out of receive buffer limit %u\n",
    813  1.18.2.2    martin 			    DEVNAME(un),
    814       1.1  jakllsch 			    le32toh(msg->rm_datalen),
    815       1.1  jakllsch 			    le32toh(msg->rm_dataoffset),
    816       1.1  jakllsch 			    le32toh(msg->rm_dataoffset) +
    817       1.1  jakllsch 			    le32toh(msg->rm_datalen) + (uint32_t)RNDIS_HEADER_OFFSET,
    818       1.1  jakllsch 			    le32toh(msg->rm_len));
    819       1.1  jakllsch 			return;
    820       1.1  jakllsch 		}
    821       1.1  jakllsch 
    822       1.1  jakllsch 		if (le32toh(msg->rm_datalen) < sizeof(struct ether_header)) {
    823  1.18.2.2    martin 			if_statinc(ifp, if_ierrors);
    824       1.1  jakllsch 			printf("%s: urndis_decap invalid ethernet size "
    825       1.1  jakllsch 			    "%d < %zu\n",
    826  1.18.2.2    martin 			    DEVNAME(un),
    827       1.1  jakllsch 			    le32toh(msg->rm_datalen),
    828       1.1  jakllsch 			    sizeof(struct ether_header));
    829       1.1  jakllsch 			return;
    830       1.1  jakllsch 		}
    831       1.1  jakllsch 
    832  1.18.2.2    martin 		usbnet_enqueue(un,
    833       1.1  jakllsch 		    ((char*)&msg->rm_dataoffset + le32toh(msg->rm_dataoffset)),
    834  1.18.2.2    martin 		    le32toh(msg->rm_datalen), 0, 0, 0);
    835       1.1  jakllsch 
    836       1.1  jakllsch 		offset += le32toh(msg->rm_len);
    837  1.18.2.2    martin 		total_len -= le32toh(msg->rm_len);
    838       1.1  jakllsch 	}
    839       1.1  jakllsch }
    840       1.1  jakllsch 
    841       1.1  jakllsch #if 0
    842       1.1  jakllsch static void
    843       1.1  jakllsch urndis_watchdog(struct ifnet *ifp)
    844       1.1  jakllsch {
    845  1.18.2.2    martin 	struct urndis_softc	*sc = usbnet_softc(un);
    846       1.1  jakllsch 
    847  1.18.2.2    martin 	if (un->un_dying)
    848       1.1  jakllsch 		return;
    849       1.1  jakllsch 
    850  1.18.2.2    martin 	if_statinc(ifp, if_oerrors);
    851  1.18.2.2    martin 	printf("%s: watchdog timeout\n", DEVNAME(un));
    852       1.1  jakllsch 
    853  1.18.2.2    martin 	urndis_ctrl_keepalive(un);
    854       1.1  jakllsch }
    855       1.1  jakllsch #endif
    856       1.1  jakllsch 
    857       1.8     skrll static int
    858  1.18.2.2    martin urndis_init_un(struct ifnet *ifp, struct usbnet *un)
    859       1.1  jakllsch {
    860       1.8     skrll 	int 			 err;
    861       1.1  jakllsch 
    862       1.1  jakllsch 	if (ifp->if_flags & IFF_RUNNING)
    863       1.9     skrll 		return 0;
    864       1.1  jakllsch 
    865  1.18.2.2    martin 	err = urndis_ctrl_init(un);
    866       1.8     skrll 	if (err != RNDIS_STATUS_SUCCESS)
    867       1.8     skrll 		return EIO;
    868       1.1  jakllsch 
    869  1.18.2.2    martin 	usbnet_lock_core(un);
    870  1.18.2.2    martin 	if (usbnet_isdying(un))
    871  1.18.2.2    martin 		err = EIO;
    872  1.18.2.2    martin 	else {
    873  1.18.2.2    martin 		usbnet_stop(un, ifp, 1);
    874  1.18.2.2    martin 		err = usbnet_init_rx_tx(un);
    875  1.18.2.2    martin 		usbnet_set_link(un, err == 0);
    876       1.1  jakllsch 	}
    877  1.18.2.2    martin 	usbnet_unlock_core(un);
    878       1.1  jakllsch 
    879  1.18.2.2    martin 	return err;
    880       1.1  jakllsch }
    881       1.1  jakllsch 
    882  1.18.2.2    martin static int
    883  1.18.2.2    martin urndis_uno_init(struct ifnet *ifp)
    884       1.1  jakllsch {
    885  1.18.2.2    martin 	struct usbnet *un = ifp->if_softc;
    886       1.1  jakllsch 
    887  1.18.2.2    martin 	return urndis_init_un(ifp, un);
    888       1.1  jakllsch }
    889       1.1  jakllsch 
    890       1.1  jakllsch static int
    891       1.1  jakllsch urndis_match(device_t parent, cfdata_t match, void *aux)
    892       1.1  jakllsch {
    893      1.11     skrll 	struct usbif_attach_arg		*uiaa = aux;
    894       1.1  jakllsch 	usb_interface_descriptor_t	*id;
    895       1.1  jakllsch 
    896      1.11     skrll 	if (!uiaa->uiaa_iface)
    897      1.11     skrll 		return UMATCH_NONE;
    898       1.1  jakllsch 
    899      1.11     skrll 	id = usbd_get_interface_descriptor(uiaa->uiaa_iface);
    900       1.1  jakllsch 	if (id == NULL)
    901      1.11     skrll 		return UMATCH_NONE;
    902       1.1  jakllsch 
    903       1.1  jakllsch 	if (id->bInterfaceClass == UICLASS_WIRELESS &&
    904       1.1  jakllsch 	    id->bInterfaceSubClass == UISUBCLASS_RF &&
    905       1.1  jakllsch 	    id->bInterfaceProtocol == UIPROTO_RNDIS)
    906      1.11     skrll 		return UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO;
    907       1.1  jakllsch 
    908      1.11     skrll 	return usb_lookup(urndis_devs, uiaa->uiaa_vendor, uiaa->uiaa_product) != NULL ?
    909       1.1  jakllsch 	    UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
    910       1.1  jakllsch }
    911       1.1  jakllsch 
    912       1.1  jakllsch static void
    913       1.1  jakllsch urndis_attach(device_t parent, device_t self, void *aux)
    914       1.1  jakllsch {
    915  1.18.2.2    martin 	struct urndis_softc		*sc = device_private(self);
    916  1.18.2.2    martin 	struct usbnet * const		 un = &sc->sc_un;
    917  1.18.2.2    martin 	struct usbif_attach_arg		*uiaa = aux;
    918  1.18.2.2    martin 	struct usbd_device	        *dev = uiaa->uiaa_device;
    919       1.1  jakllsch 	usb_interface_descriptor_t	*id;
    920       1.1  jakllsch 	usb_endpoint_descriptor_t	*ed;
    921       1.1  jakllsch 	usb_config_descriptor_t		*cd;
    922  1.18.2.2    martin 	struct usbd_interface		*iface_ctl;
    923       1.1  jakllsch 	const usb_cdc_union_descriptor_t *ud;
    924       1.1  jakllsch 	const usb_cdc_header_descriptor_t *desc;
    925       1.1  jakllsch 	usbd_desc_iter_t		 iter;
    926       1.1  jakllsch 	int				 if_ctl, if_data;
    927       1.1  jakllsch 	int				 i, j, altcnt;
    928       1.1  jakllsch 	void				*buf;
    929       1.1  jakllsch 	size_t				 bufsz;
    930       1.1  jakllsch 	uint32_t			 filter;
    931       1.1  jakllsch 	char				*devinfop;
    932       1.1  jakllsch 
    933  1.18.2.2    martin 	KASSERT((void *)sc == un);
    934       1.1  jakllsch 
    935       1.1  jakllsch 	aprint_naive("\n");
    936       1.1  jakllsch 	aprint_normal("\n");
    937  1.18.2.2    martin 	devinfop = usbd_devinfo_alloc(dev, 0);
    938       1.1  jakllsch 	aprint_normal_dev(self, "%s\n", devinfop);
    939       1.1  jakllsch 	usbd_devinfo_free(devinfop);
    940       1.1  jakllsch 
    941  1.18.2.2    martin 	un->un_dev = self;
    942  1.18.2.2    martin 	un->un_udev = dev;
    943  1.18.2.2    martin 	un->un_sc = sc;
    944  1.18.2.2    martin 	un->un_ops = &urndis_ops;
    945  1.18.2.2    martin 	un->un_rx_xfer_flags = USBD_SHORT_XFER_OK;
    946  1.18.2.2    martin 	un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER;
    947  1.18.2.2    martin 	un->un_rx_list_cnt = RNDIS_RX_LIST_CNT;
    948  1.18.2.2    martin 	un->un_tx_list_cnt = RNDIS_TX_LIST_CNT;
    949  1.18.2.2    martin 	un->un_rx_bufsz = RNDIS_BUFSZ;
    950  1.18.2.2    martin 	un->un_tx_bufsz = RNDIS_BUFSZ;
    951  1.18.2.2    martin 
    952  1.18.2.2    martin 	iface_ctl = uiaa->uiaa_iface;
    953  1.18.2.2    martin 	un->un_iface = uiaa->uiaa_iface;
    954  1.18.2.2    martin 	id = usbd_get_interface_descriptor(iface_ctl);
    955       1.1  jakllsch 	if_ctl = id->bInterfaceNumber;
    956       1.1  jakllsch 	sc->sc_ifaceno_ctl = if_ctl;
    957       1.1  jakllsch 	if_data = -1;
    958       1.1  jakllsch 
    959  1.18.2.2    martin 	usb_desc_iter_init(un->un_udev, &iter);
    960       1.1  jakllsch 	while ((desc = (const void *)usb_desc_iter_next(&iter)) != NULL) {
    961       1.1  jakllsch 
    962       1.1  jakllsch 		if (desc->bDescriptorType != UDESC_CS_INTERFACE) {
    963       1.1  jakllsch 			continue;
    964       1.1  jakllsch 		}
    965       1.1  jakllsch 		switch (desc->bDescriptorSubtype) {
    966       1.1  jakllsch 		case UDESCSUB_CDC_UNION:
    967       1.1  jakllsch 			/* XXX bail out when found first? */
    968       1.1  jakllsch 			ud = (const usb_cdc_union_descriptor_t *)desc;
    969       1.1  jakllsch 			if (if_data == -1)
    970       1.1  jakllsch 				if_data = ud->bSlaveInterface[0];
    971       1.1  jakllsch 			break;
    972       1.1  jakllsch 		}
    973       1.1  jakllsch 	}
    974       1.1  jakllsch 
    975       1.1  jakllsch 	if (if_data == -1) {
    976       1.1  jakllsch 		DPRINTF(("urndis_attach: no union interface\n"));
    977  1.18.2.2    martin 		un->un_iface = iface_ctl;
    978       1.1  jakllsch 	} else {
    979       1.1  jakllsch 		DPRINTF(("urndis_attach: union interface: ctl %u, data %u\n",
    980       1.1  jakllsch 		    if_ctl, if_data));
    981      1.11     skrll 		for (i = 0; i < uiaa->uiaa_nifaces; i++) {
    982      1.11     skrll 			if (uiaa->uiaa_ifaces[i] != NULL) {
    983       1.1  jakllsch 				id = usbd_get_interface_descriptor(
    984      1.11     skrll 				    uiaa->uiaa_ifaces[i]);
    985       1.1  jakllsch 				if (id != NULL && id->bInterfaceNumber ==
    986       1.1  jakllsch 				    if_data) {
    987  1.18.2.2    martin 					un->un_iface = uiaa->uiaa_ifaces[i];
    988      1.11     skrll 					uiaa->uiaa_ifaces[i] = NULL;
    989       1.1  jakllsch 				}
    990       1.1  jakllsch 			}
    991       1.1  jakllsch 		}
    992       1.1  jakllsch 	}
    993       1.1  jakllsch 
    994  1.18.2.2    martin 	if (un->un_iface == NULL) {
    995  1.18.2.2    martin 		aprint_error("%s: no data interface\n", DEVNAME(un));
    996       1.1  jakllsch 		return;
    997       1.1  jakllsch 	}
    998       1.1  jakllsch 
    999  1.18.2.2    martin 	id = usbd_get_interface_descriptor(un->un_iface);
   1000  1.18.2.2    martin 	cd = usbd_get_config_descriptor(un->un_udev);
   1001       1.1  jakllsch 	altcnt = usbd_get_no_alts(cd, id->bInterfaceNumber);
   1002       1.1  jakllsch 
   1003       1.1  jakllsch 	for (j = 0; j < altcnt; j++) {
   1004  1.18.2.2    martin 		if (usbd_set_interface(un->un_iface, j)) {
   1005      1.13   msaitoh 			aprint_error("%s: interface alternate setting %u "
   1006  1.18.2.2    martin 			    "failed\n", DEVNAME(un), j);
   1007       1.1  jakllsch 			return;
   1008       1.1  jakllsch 		}
   1009       1.1  jakllsch 		/* Find endpoints. */
   1010  1.18.2.2    martin 		id = usbd_get_interface_descriptor(un->un_iface);
   1011  1.18.2.2    martin 		un->un_ed[USBNET_ENDPT_RX] = un->un_ed[USBNET_ENDPT_TX] = 0;
   1012       1.1  jakllsch 		for (i = 0; i < id->bNumEndpoints; i++) {
   1013       1.1  jakllsch 			ed = usbd_interface2endpoint_descriptor(
   1014  1.18.2.2    martin 			    un->un_iface, i);
   1015       1.1  jakllsch 			if (!ed) {
   1016      1.13   msaitoh 				aprint_error("%s: no descriptor for bulk "
   1017  1.18.2.2    martin 				    "endpoint %u\n", DEVNAME(un), i);
   1018       1.1  jakllsch 				return;
   1019       1.1  jakllsch 			}
   1020       1.1  jakllsch 			if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
   1021       1.1  jakllsch 			    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
   1022  1.18.2.2    martin 				un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress;
   1023       1.1  jakllsch 			}
   1024       1.1  jakllsch 			else if (
   1025       1.1  jakllsch 			    UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
   1026       1.1  jakllsch 			    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
   1027  1.18.2.2    martin 				un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress;
   1028       1.1  jakllsch 			}
   1029       1.1  jakllsch 		}
   1030       1.1  jakllsch 
   1031  1.18.2.2    martin 		if (un->un_ed[USBNET_ENDPT_RX] != 0 && un->un_ed[USBNET_ENDPT_TX] != 0) {
   1032  1.18.2.2    martin 			DPRINTF(("%s: in=%#x, out=%#x\n",
   1033  1.18.2.2    martin 			    DEVNAME(un),
   1034  1.18.2.2    martin 			    un->un_ed[USBNET_ENDPT_RX],
   1035  1.18.2.2    martin 			    un->un_ed[USBNET_ENDPT_TX]));
   1036  1.18.2.2    martin 			break;
   1037       1.1  jakllsch 		}
   1038       1.1  jakllsch 	}
   1039       1.1  jakllsch 
   1040  1.18.2.2    martin 	if (un->un_ed[USBNET_ENDPT_RX] == 0)
   1041  1.18.2.2    martin 		aprint_error("%s: could not find data bulk in\n", DEVNAME(un));
   1042  1.18.2.2    martin 	if (un->un_ed[USBNET_ENDPT_TX] == 0)
   1043  1.18.2.2    martin 		aprint_error("%s: could not find data bulk out\n",DEVNAME(un));
   1044  1.18.2.2    martin 	if (un->un_ed[USBNET_ENDPT_RX] == 0 || un->un_ed[USBNET_ENDPT_TX] == 0)
   1045  1.18.2.2    martin 		return;
   1046  1.18.2.2    martin 
   1047       1.1  jakllsch #if 0
   1048       1.1  jakllsch 	ifp->if_watchdog = urndis_watchdog;
   1049       1.1  jakllsch #endif
   1050       1.1  jakllsch 
   1051  1.18.2.2    martin 	usbnet_attach(un, "urndisdet");
   1052       1.1  jakllsch 
   1053  1.18.2.2    martin 	struct ifnet *ifp = usbnet_ifp(un);
   1054  1.18.2.2    martin 	urndis_init_un(ifp, un);
   1055       1.1  jakllsch 
   1056  1.18.2.2    martin 	if (urndis_ctrl_query(un, OID_802_3_PERMANENT_ADDRESS, NULL, 0,
   1057       1.1  jakllsch 	    &buf, &bufsz) != RNDIS_STATUS_SUCCESS) {
   1058      1.13   msaitoh 		aprint_error("%s: unable to get hardware address\n",
   1059  1.18.2.2    martin 		    DEVNAME(un));
   1060  1.18.2.2    martin 		usbnet_lock_core(un);
   1061  1.18.2.2    martin 		usbnet_stop(un, ifp, 1);
   1062  1.18.2.2    martin 		usbnet_unlock_core(un);
   1063       1.1  jakllsch 		return;
   1064       1.1  jakllsch 	}
   1065       1.1  jakllsch 
   1066       1.1  jakllsch 	if (bufsz == ETHER_ADDR_LEN) {
   1067  1.18.2.2    martin 		memcpy(un->un_eaddr, buf, ETHER_ADDR_LEN);
   1068       1.1  jakllsch 		kmem_free(buf, bufsz);
   1069       1.1  jakllsch 	} else {
   1070  1.18.2.2    martin 		aprint_error("%s: invalid address\n", DEVNAME(un));
   1071  1.18.2.2    martin 		if (buf && bufsz)
   1072  1.18.2.2    martin 			kmem_free(buf, bufsz);
   1073  1.18.2.2    martin 		usbnet_lock_core(un);
   1074  1.18.2.2    martin 		usbnet_stop(un, ifp, 1);
   1075  1.18.2.2    martin 		usbnet_unlock_core(un);
   1076       1.1  jakllsch 		return;
   1077       1.1  jakllsch 	}
   1078       1.1  jakllsch 
   1079       1.1  jakllsch 	/* Initialize packet filter */
   1080       1.5  christos 	sc->sc_filter = RNDIS_PACKET_TYPE_BROADCAST;
   1081       1.1  jakllsch 	sc->sc_filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST;
   1082       1.1  jakllsch 	filter = htole32(sc->sc_filter);
   1083  1.18.2.2    martin 	if (urndis_ctrl_set(un, OID_GEN_CURRENT_PACKET_FILTER, &filter,
   1084       1.1  jakllsch 	    sizeof(filter)) != RNDIS_STATUS_SUCCESS) {
   1085  1.18.2.2    martin 		aprint_error("%s: unable to set data filters\n", DEVNAME(un));
   1086  1.18.2.2    martin 		usbnet_lock_core(un);
   1087  1.18.2.2    martin 		usbnet_stop(un, ifp, 1);
   1088  1.18.2.2    martin 		usbnet_unlock_core(un);
   1089       1.1  jakllsch 		return;
   1090       1.1  jakllsch 	}
   1091       1.1  jakllsch 
   1092  1.18.2.2    martin 	/* Turn off again now it has been identified. */
   1093  1.18.2.2    martin 	usbnet_lock_core(un);
   1094  1.18.2.2    martin 	usbnet_stop(un, ifp, 1);
   1095  1.18.2.2    martin 	usbnet_unlock_core(un);
   1096       1.1  jakllsch 
   1097  1.18.2.2    martin 	usbnet_attach_ifp(un, IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST,
   1098  1.18.2.2    martin             0, NULL);
   1099       1.1  jakllsch }
   1100       1.1  jakllsch 
   1101  1.18.2.2    martin #ifdef _MODULE
   1102  1.18.2.2    martin #include "ioconf.c"
   1103  1.18.2.2    martin #endif
   1104       1.1  jakllsch 
   1105  1.18.2.2    martin USBNET_MODULE(urndis)
   1106