diff options
-rw-r--r-- | sys/dev/usb/if_urndis.c | 90 | ||||
-rw-r--r-- | sys/dev/usb/if_urndisreg.h | 243 |
2 files changed, 47 insertions, 286 deletions
diff --git a/sys/dev/usb/if_urndis.c b/sys/dev/usb/if_urndis.c index b836531963e..112556eceb0 100644 --- a/sys/dev/usb/if_urndis.c +++ b/sys/dev/usb/if_urndis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urndis.c,v 1.61 2016/04/13 11:03:37 mpi Exp $ */ +/* $OpenBSD: if_urndis.c,v 1.62 2016/09/16 11:13:37 mikeb Exp $ */ /* * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org> @@ -49,6 +49,8 @@ #include <dev/usb/usbdivar.h> #include <dev/usb/usbdevs.h> +#include <dev/rndis.h> + #include <dev/usb/if_urndisreg.h> #ifdef URNDIS_DEBUG @@ -78,16 +80,16 @@ void urndis_stop(struct urndis_softc *); usbd_status urndis_ctrl_msg(struct urndis_softc *, uint8_t, uint8_t, uint16_t, uint16_t, void *, size_t); usbd_status urndis_ctrl_send(struct urndis_softc *, void *, size_t); -struct urndis_comp_hdr *urndis_ctrl_recv(struct urndis_softc *); +struct rndis_comp_hdr *urndis_ctrl_recv(struct urndis_softc *); u_int32_t urndis_ctrl_handle(struct urndis_softc *, - struct urndis_comp_hdr *, void **, size_t *); + struct rndis_comp_hdr *, void **, size_t *); u_int32_t urndis_ctrl_handle_init(struct urndis_softc *, - const struct urndis_comp_hdr *); + const struct rndis_comp_hdr *); u_int32_t urndis_ctrl_handle_query(struct urndis_softc *, - const struct urndis_comp_hdr *, void **, size_t *); + const struct rndis_comp_hdr *, void **, size_t *); u_int32_t urndis_ctrl_handle_reset(struct urndis_softc *, - const struct urndis_comp_hdr *); + const struct rndis_comp_hdr *); u_int32_t urndis_ctrl_init(struct urndis_softc *); u_int32_t urndis_ctrl_halt(struct urndis_softc *); @@ -161,11 +163,11 @@ urndis_ctrl_send(struct urndis_softc *sc, void *buf, size_t len) return err; } -struct urndis_comp_hdr * +struct rndis_comp_hdr * urndis_ctrl_recv(struct urndis_softc *sc) { #define RNDIS_RESPONSE_LEN 0x400 - struct urndis_comp_hdr *hdr; + struct rndis_comp_hdr *hdr; char *buf; usbd_status err; @@ -184,7 +186,7 @@ urndis_ctrl_recv(struct urndis_softc *sc) return NULL; } - hdr = (struct urndis_comp_hdr *)buf; + hdr = (struct rndis_comp_hdr *)buf; DPRINTF(("%s: urndis_ctrl_recv: type 0x%x len %u\n", DEVNAME(sc), letoh32(hdr->rm_type), @@ -203,7 +205,7 @@ urndis_ctrl_recv(struct urndis_softc *sc) } u_int32_t -urndis_ctrl_handle(struct urndis_softc *sc, struct urndis_comp_hdr *hdr, +urndis_ctrl_handle(struct urndis_softc *sc, struct rndis_comp_hdr *hdr, void **buf, size_t *bufsz) { u_int32_t rval; @@ -246,11 +248,11 @@ urndis_ctrl_handle(struct urndis_softc *sc, struct urndis_comp_hdr *hdr, u_int32_t urndis_ctrl_handle_init(struct urndis_softc *sc, - const struct urndis_comp_hdr *hdr) + const struct rndis_comp_hdr *hdr) { - const struct urndis_init_comp *msg; + const struct rndis_init_comp *msg; - msg = (struct urndis_init_comp *) hdr; + msg = (struct rndis_init_comp *) hdr; DPRINTF(("%s: urndis_ctrl_handle_init: len %u rid %u status 0x%x " "ver_major %u ver_minor %u devflags 0x%x medium 0x%x pktmaxcnt %u " @@ -299,11 +301,11 @@ urndis_ctrl_handle_init(struct urndis_softc *sc, u_int32_t urndis_ctrl_handle_query(struct urndis_softc *sc, - const struct urndis_comp_hdr *hdr, void **buf, size_t *bufsz) + const struct rndis_comp_hdr *hdr, void **buf, size_t *bufsz) { - const struct urndis_query_comp *msg; + const struct rndis_query_comp *msg; - msg = (struct urndis_query_comp *) hdr; + msg = (struct rndis_query_comp *) hdr; DPRINTF(("%s: urndis_ctrl_handle_query: len %u rid %u status 0x%x " "buflen %u bufoff %u\n", @@ -334,7 +336,7 @@ urndis_ctrl_handle_query(struct urndis_softc *sc, "go out of buffer limit %u\n", DEVNAME(sc), letoh32(msg->rm_infobuflen), - letoh32(msg->rm_infobufoffset), + letoh32(msg->rm_infobufoffset), letoh32(msg->rm_infobuflen) + letoh32(msg->rm_infobufoffset) + RNDIS_HEADER_OFFSET, letoh32(msg->rm_len)); @@ -362,12 +364,12 @@ urndis_ctrl_handle_query(struct urndis_softc *sc, u_int32_t urndis_ctrl_handle_reset(struct urndis_softc *sc, - const struct urndis_comp_hdr *hdr) + const struct rndis_comp_hdr *hdr) { - const struct urndis_reset_comp *msg; + const struct rndis_reset_comp *msg; u_int32_t rval; - msg = (struct urndis_reset_comp *) hdr; + msg = (struct rndis_reset_comp *) hdr; rval = letoh32(msg->rm_status); @@ -402,9 +404,9 @@ urndis_ctrl_handle_reset(struct urndis_softc *sc, u_int32_t urndis_ctrl_init(struct urndis_softc *sc) { - struct urndis_init_req *msg; + struct rndis_init_req *msg; u_int32_t rval; - struct urndis_comp_hdr *hdr; + struct rndis_comp_hdr *hdr; msg = malloc(sizeof(*msg), M_TEMP, M_WAITOK); if (msg == NULL) { @@ -449,7 +451,7 @@ urndis_ctrl_init(struct urndis_softc *sc) u_int32_t urndis_ctrl_halt(struct urndis_softc *sc) { - struct urndis_halt_req *msg; + struct rndis_halt_req *msg; u_int32_t rval; msg = malloc(sizeof(*msg), M_TEMP, M_WAITOK); @@ -482,9 +484,9 @@ urndis_ctrl_query(struct urndis_softc *sc, u_int32_t oid, void *qbuf, size_t qlen, void **rbuf, size_t *rbufsz) { - struct urndis_query_req *msg; + struct rndis_query_req *msg; u_int32_t rval; - struct urndis_comp_hdr *hdr; + struct rndis_comp_hdr *hdr; msg = malloc(sizeof(*msg) + qlen, M_TEMP, M_WAITOK); if (msg == NULL) { @@ -535,9 +537,9 @@ urndis_ctrl_query(struct urndis_softc *sc, u_int32_t oid, u_int32_t urndis_ctrl_set(struct urndis_softc *sc, u_int32_t oid, void *buf, size_t len) { - struct urndis_set_req *msg; + struct rndis_set_req *msg; u_int32_t rval; - struct urndis_comp_hdr *hdr; + struct rndis_comp_hdr *hdr; msg = malloc(sizeof(*msg) + len, M_TEMP, M_WAITOK); if (msg == NULL) { @@ -583,7 +585,7 @@ urndis_ctrl_set(struct urndis_softc *sc, u_int32_t oid, void *buf, size_t len) rval = urndis_ctrl_handle(sc, hdr, NULL, NULL); if (rval != RNDIS_STATUS_SUCCESS) printf("%s: set failed 0x%x\n", DEVNAME(sc), rval); - + return rval; } @@ -594,7 +596,7 @@ urndis_ctrl_set_param(struct urndis_softc *sc, void *buf, size_t len) { - struct urndis_set_parameter *param; + struct rndis_set_parameter *param; u_int32_t rval; size_t namelen, tlen; @@ -645,9 +647,9 @@ urndis_ctrl_set_param(struct urndis_softc *sc, u_int32_t urndis_ctrl_reset(struct urndis_softc *sc) { - struct urndis_reset_req *reset; + struct rndis_reset_req *reset; u_int32_t rval; - struct urndis_comp_hdr *hdr; + struct rndis_comp_hdr *hdr; reset = malloc(sizeof(*reset), M_TEMP, M_WAITOK); if (reset == NULL) { @@ -685,9 +687,9 @@ urndis_ctrl_reset(struct urndis_softc *sc) u_int32_t urndis_ctrl_keepalive(struct urndis_softc *sc) { - struct urndis_keepalive_req *keep; + struct rndis_keepalive_req *keep; u_int32_t rval; - struct urndis_comp_hdr *hdr; + struct rndis_comp_hdr *hdr; keep = malloc(sizeof(*keep), M_TEMP, M_WAITOK); if (keep == NULL) { @@ -732,11 +734,11 @@ urndis_encap(struct urndis_softc *sc, struct mbuf *m, int idx) { struct urndis_chain *c; usbd_status err; - struct urndis_packet_msg *msg; + struct rndis_packet_msg *msg; c = &sc->sc_data.sc_tx_chain[idx]; - msg = (struct urndis_packet_msg *)c->sc_buf; + msg = (struct rndis_packet_msg *)c->sc_buf; memset(msg, 0, sizeof(*msg)); msg->rm_type = htole32(REMOTE_NDIS_PACKET_MSG); @@ -778,16 +780,16 @@ urndis_decap(struct urndis_softc *sc, struct urndis_chain *c, u_int32_t len) { struct mbuf *m; struct mbuf_list ml = MBUF_LIST_INITIALIZER(); - struct urndis_packet_msg *msg; + struct rndis_packet_msg *msg; struct ifnet *ifp; int s; int offset; ifp = GET_IFP(sc); offset = 0; - + while (len > 0) { - msg = (struct urndis_packet_msg *)((char*)c->sc_buf + offset); + msg = (struct rndis_packet_msg *)((char*)c->sc_buf + offset); m = c->sc_mbuf; DPRINTF(("%s: urndis_decap buffer size left %u\n", DEVNAME(sc), @@ -838,8 +840,8 @@ urndis_decap(struct urndis_softc *sc, struct urndis_chain *c, u_int32_t len) } if (letoh32(msg->rm_dataoffset) + - letoh32(msg->rm_datalen) + RNDIS_HEADER_OFFSET - > letoh32(msg->rm_len)) { + letoh32(msg->rm_datalen) + RNDIS_HEADER_OFFSET + > letoh32(msg->rm_len)) { printf("%s: urndis_decap invalid data " "len/offset/end_position(%u/%u/%zu) -> " "go out of receive buffer limit %u\n", @@ -1312,7 +1314,7 @@ urndis_match(struct device *parent, void *match, void *aux) if (id == NULL) return (UMATCH_NONE); - return (urndis_lookup(id) ? + return (urndis_lookup(id) ? UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO : UMATCH_NONE); } @@ -1440,8 +1442,8 @@ urndis_attach(struct device *parent, struct device *self, void *aux) } /* Initialize packet filter */ - sc->sc_filter = RNDIS_PACKET_TYPE_BROADCAST; - sc->sc_filter |= RNDIS_PACKET_TYPE_ALL_MULTICAST; + sc->sc_filter = NDIS_PACKET_TYPE_BROADCAST; + sc->sc_filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; filter = htole32(sc->sc_filter); if (urndis_ctrl_set(sc, OID_GEN_CURRENT_PACKET_FILTER, &filter, sizeof(filter)) != RNDIS_STATUS_SUCCESS) { @@ -1470,7 +1472,7 @@ urndis_detach(struct device *self, int flags) DPRINTF(("urndis_detach: %s flags %u\n", DEVNAME(sc), flags)); - + if (!sc->sc_attached) return 0; diff --git a/sys/dev/usb/if_urndisreg.h b/sys/dev/usb/if_urndisreg.h index 54cc658f5e3..844532bab46 100644 --- a/sys/dev/usb/if_urndisreg.h +++ b/sys/dev/usb/if_urndisreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_urndisreg.h,v 1.19 2013/11/21 14:08:05 mpi Exp $ */ +/* $OpenBSD: if_urndisreg.h,v 1.20 2016/09/16 11:13:37 mikeb Exp $ */ /* * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org> @@ -61,244 +61,3 @@ struct urndis_softc { struct urndis_cdata sc_data; }; - -#define RNDIS_STATUS_BUFFER_OVERFLOW 0x80000005L -#define RNDIS_STATUS_FAILURE 0xC0000001L -#define RNDIS_STATUS_INVALID_DATA 0xC0010015L -#define RNDIS_STATUS_MEDIA_CONNECT 0x4001000BL -#define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000CL -#define RNDIS_STATUS_NOT_SUPPORTED 0xC00000BBL -#define RNDIS_STATUS_PENDING STATUS_PENDING /* XXX */ -#define RNDIS_STATUS_RESOURCES 0xC000009AL -#define RNDIS_STATUS_SUCCESS 0x00000000L - -#define OID_GEN_SUPPORTED_LIST 0x00010101 -#define OID_GEN_HARDWARE_STATUS 0x00010102 -#define OID_GEN_MEDIA_SUPPORTED 0x00010103 -#define OID_GEN_MEDIA_IN_USE 0x00010104 -#define OID_GEN_MAXIMUM_LOOKAHEAD 0x00010105 -#define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106 -#define OID_GEN_LINK_SPEED 0x00010107 -#define OID_GEN_TRANSMIT_BUFFER_SPACE 0x00010108 -#define OID_GEN_RECEIVE_BUFFER_SPACE 0x00010109 -#define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010A -#define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010B -#define OID_GEN_VENDOR_ID 0x0001010C -#define OID_GEN_VENDOR_DESCRIPTION 0x0001010D -#define OID_GEN_CURRENT_PACKET_FILTER 0x0001010E -#define OID_GEN_CURRENT_LOOKAHEAD 0x0001010F -#define OID_GEN_DRIVER_VERSION 0x00010110 -#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111 -#define OID_GEN_PROTOCOL_OPTIONS 0x00010112 -#define OID_GEN_MAC_OPTIONS 0x00010113 -#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114 -#define OID_GEN_MAXIMUM_SEND_PACKETS 0x00010115 -#define OID_GEN_VENDOR_DRIVER_VERSION 0x00010116 -#define OID_GEN_SUPPORTED_GUIDS 0x00010117 -#define OID_GEN_NETWORK_LAYER_ADDRESSES 0x00010118 -#define OID_GEN_TRANSPORT_HEADER_OFFSET 0x00010119 -#define OID_GEN_MACHINE_NAME 0x0001021A -#define OID_GEN_RNDIS_CONFIG_PARAMETER 0x0001021B -#define OID_GEN_VLAN_ID 0x0001021C - -#define OID_802_3_PERMANENT_ADDRESS 0x01010101 -#define OID_802_3_CURRENT_ADDRESS 0x01010102 -#define OID_802_3_MULTICAST_LIST 0x01010103 -#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104 -#define OID_802_3_MAC_OPTIONS 0x01010105 -#define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101 -#define OID_802_3_XMIT_ONE_COLLISION 0x01020102 -#define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103 -#define OID_802_3_XMIT_DEFERRED 0x01020201 -#define OID_802_3_XMIT_MAX_COLLISIONS 0x01020202 -#define OID_802_3_RCV_OVERRUN 0x01020203 -#define OID_802_3_XMIT_UNDERRUN 0x01020204 -#define OID_802_3_XMIT_HEARTBEAT_FAILURE 0x01020205 -#define OID_802_3_XMIT_TIMES_CRS_LOST 0x01020206 -#define OID_802_3_XMIT_LATE_COLLISIONS 0x01020207 - -#define RNDIS_MEDIUM_802_3 0x00000000 - -/* Device flags */ -#define RNDIS_DF_CONNECTIONLESS 0x00000001 -#define RNDIS_DF_CONNECTION_ORIENTED 0x00000002 - -/* - * RNDIS data message - */ -#define REMOTE_NDIS_PACKET_MSG 0x00000001 - - -struct urndis_packet_msg { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_dataoffset; - u_int32_t rm_datalen; - u_int32_t rm_oobdataoffset; - u_int32_t rm_oobdatalen; - u_int32_t rm_oobdataelements; - u_int32_t rm_pktinfooffset; - u_int32_t rm_pktinfolen; - u_int32_t rm_vchandle; - u_int32_t rm_reserved; -}; - -/* - * RNDIS control messages - */ -struct urndis_comp_hdr { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_status; -}; - -/* Initialize the device. */ -#define REMOTE_NDIS_INITIALIZE_MSG 0x00000002 -#define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002 - -struct urndis_init_req { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_ver_major; - u_int32_t rm_ver_minor; - u_int32_t rm_max_xfersz; -}; - -struct urndis_init_comp { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_status; - u_int32_t rm_ver_major; - u_int32_t rm_ver_minor; - u_int32_t rm_devflags; - u_int32_t rm_medium; - u_int32_t rm_pktmaxcnt; - u_int32_t rm_pktmaxsz; - u_int32_t rm_align; - u_int32_t rm_aflistoffset; - u_int32_t rm_aflistsz; -}; - -/* Halt the device. No response sent. */ -#define REMOTE_NDIS_HALT_MSG 0x00000003 - -struct urndis_halt_req { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; -}; - -/* Send a query object. */ -#define REMOTE_NDIS_QUERY_MSG 0x00000004 -#define REMOTE_NDIS_QUERY_CMPLT 0x80000004 - -struct urndis_query_req { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_oid; - u_int32_t rm_infobuflen; - u_int32_t rm_infobufoffset; - u_int32_t rm_devicevchdl; -}; - -struct urndis_query_comp { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_status; - u_int32_t rm_infobuflen; - u_int32_t rm_infobufoffset; -}; - -/* Send a set object request. */ -#define REMOTE_NDIS_SET_MSG 0x00000005 -#define REMOTE_NDIS_SET_CMPLT 0x80000005 - -struct urndis_set_req { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_oid; - u_int32_t rm_infobuflen; - u_int32_t rm_infobufoffset; - u_int32_t rm_devicevchdl; -}; - -struct urndis_set_comp { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_status; -}; - -#define REMOTE_NDIS_SET_PARAM_NUMERIC 0x00000000 -#define REMOTE_NDIS_SET_PARAM_STRING 0x00000002 - -struct urndis_set_parameter { - u_int32_t rm_nameoffset; - u_int32_t rm_namelen; - u_int32_t rm_type; - u_int32_t rm_valueoffset; - u_int32_t rm_valuelen; -}; - -/* Perform a soft reset on the device. */ -#define REMOTE_NDIS_RESET_MSG 0x00000006 -#define REMOTE_NDIS_RESET_CMPLT 0x80000006 - -struct urndis_reset_req { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; -}; - -struct urndis_reset_comp { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_status; - u_int32_t rm_adrreset; -}; - -/* 802.3 link-state or undefined message error. */ -#define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007 - -/* Keepalive messsage. May be sent by device. */ -#define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008 -#define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008 - -struct urndis_keepalive_req { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; -}; - -struct urndis_keepalive_comp { - u_int32_t rm_type; - u_int32_t rm_len; - u_int32_t rm_rid; - u_int32_t rm_status; -}; - -/* packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */ -#define RNDIS_PACKET_TYPE_DIRECTED 0x00000001 -#define RNDIS_PACKET_TYPE_MULTICAST 0x00000002 -#define RNDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004 -#define RNDIS_PACKET_TYPE_BROADCAST 0x00000008 -#define RNDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010 -#define RNDIS_PACKET_TYPE_PROMISCUOUS 0x00000020 -#define RNDIS_PACKET_TYPE_SMT 0x00000040 -#define RNDIS_PACKET_TYPE_ALL_LOCAL 0x00000080 -#define RNDIS_PACKET_TYPE_GROUP 0x00001000 -#define RNDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00002000 -#define RNDIS_PACKET_TYPE_FUNCTIONAL 0x00004000 -#define RNDIS_PACKET_TYPE_MAC_FRAME 0x00008000 - -/* Rndis offsets */ -#define RNDIS_HEADER_OFFSET (sizeof(u_int32_t) * 2) -#define RNDIS_DATA_OFFSET (sizeof(struct urndis_packet_msg) - \ - offsetof(struct urndis_packet_msg, \ - rm_dataoffset)) |