if_urndis.c (261544) | if_urndis.c (271832) |
---|---|
1/* $OpenBSD: if_urndis.c,v 1.46 2013/12/09 15:45:29 pirofti Exp $ */ 2 3/* 4 * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org> 5 * Copyright (c) 2010 Fabien Romano <fabien@openbsd.org> 6 * Copyright (c) 2010 Michael Knudsen <mk@openbsd.org> 7 * Copyright (c) 2014 Hans Petter Selasky <hselasky@freebsd.org> 8 * All rights reserved. --- 7 unchanged lines hidden (view full) --- 16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23#include <sys/cdefs.h> | 1/* $OpenBSD: if_urndis.c,v 1.46 2013/12/09 15:45:29 pirofti Exp $ */ 2 3/* 4 * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org> 5 * Copyright (c) 2010 Fabien Romano <fabien@openbsd.org> 6 * Copyright (c) 2010 Michael Knudsen <mk@openbsd.org> 7 * Copyright (c) 2014 Hans Petter Selasky <hselasky@freebsd.org> 8 * All rights reserved. --- 7 unchanged lines hidden (view full) --- 16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23#include <sys/cdefs.h> |
24__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_urndis.c 261544 2014-02-06 10:47:47Z hselasky $"); | 24__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_urndis.c 271832 2014-09-18 21:09:22Z glebius $"); |
25 26#include <sys/stdint.h> 27#include <sys/stddef.h> 28#include <sys/param.h> 29#include <sys/queue.h> 30#include <sys/types.h> 31#include <sys/systm.h> 32#include <sys/socket.h> --- 806 unchanged lines hidden (view full) --- 839 (uint32_t)__offsetof(struct urndis_packet_msg, 840 rm_dataoffset)) > (uint32_t)actlen) { 841 DPRINTF("invalid dataoffset %u larger than %u\n", 842 msg.rm_dataoffset + msg.rm_datalen + 843 (uint32_t)__offsetof(struct urndis_packet_msg, 844 rm_dataoffset), actlen); 845 goto tr_setup; 846 } else if (msg.rm_datalen < (uint32_t)sizeof(struct ether_header)) { | 25 26#include <sys/stdint.h> 27#include <sys/stddef.h> 28#include <sys/param.h> 29#include <sys/queue.h> 30#include <sys/types.h> 31#include <sys/systm.h> 32#include <sys/socket.h> --- 806 unchanged lines hidden (view full) --- 839 (uint32_t)__offsetof(struct urndis_packet_msg, 840 rm_dataoffset)) > (uint32_t)actlen) { 841 DPRINTF("invalid dataoffset %u larger than %u\n", 842 msg.rm_dataoffset + msg.rm_datalen + 843 (uint32_t)__offsetof(struct urndis_packet_msg, 844 rm_dataoffset), actlen); 845 goto tr_setup; 846 } else if (msg.rm_datalen < (uint32_t)sizeof(struct ether_header)) { |
847 ifp->if_ierrors++; | 847 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
848 DPRINTF("invalid ethernet size " 849 "%u < %u\n", msg.rm_datalen, (unsigned)sizeof(struct ether_header)); 850 goto tr_setup; 851 } else if (msg.rm_datalen > (uint32_t)MCLBYTES) { | 848 DPRINTF("invalid ethernet size " 849 "%u < %u\n", msg.rm_datalen, (unsigned)sizeof(struct ether_header)); 850 goto tr_setup; 851 } else if (msg.rm_datalen > (uint32_t)MCLBYTES) { |
852 ifp->if_ierrors++; | 852 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
853 DPRINTF("invalid ethernet size " 854 "%u > %u\n", 855 msg.rm_datalen, (unsigned)MCLBYTES); 856 goto tr_setup; 857 } else if (msg.rm_datalen > (uint32_t)(MHLEN - ETHER_ALIGN)) { 858 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 859 } else { 860 m = m_gethdr(M_NOWAIT, MT_DATA); --- 5 unchanged lines hidden (view full) --- 866 867 usbd_copy_out(pc, offset + msg.rm_dataoffset + 868 __offsetof(struct urndis_packet_msg, 869 rm_dataoffset), m->m_data, msg.rm_datalen); 870 871 /* enqueue */ 872 uether_rxmbuf(&sc->sc_ue, m, msg.rm_datalen); 873 } else { | 853 DPRINTF("invalid ethernet size " 854 "%u > %u\n", 855 msg.rm_datalen, (unsigned)MCLBYTES); 856 goto tr_setup; 857 } else if (msg.rm_datalen > (uint32_t)(MHLEN - ETHER_ALIGN)) { 858 m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); 859 } else { 860 m = m_gethdr(M_NOWAIT, MT_DATA); --- 5 unchanged lines hidden (view full) --- 866 867 usbd_copy_out(pc, offset + msg.rm_dataoffset + 868 __offsetof(struct urndis_packet_msg, 869 rm_dataoffset), m->m_data, msg.rm_datalen); 870 871 /* enqueue */ 872 uether_rxmbuf(&sc->sc_ue, m, msg.rm_datalen); 873 } else { |
874 ifp->if_ierrors++; | 874 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
875 } 876 offset += msg.rm_len; 877 actlen -= msg.rm_len; 878 } 879 880 case USB_ST_SETUP: 881tr_setup: 882 usbd_xfer_set_frame_len(xfer, 0, RNDIS_RX_MAXLEN); --- 29 unchanged lines hidden (view full) --- 912 usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL); 913 914 DPRINTFN(1, "\n"); 915 916 switch (USB_GET_STATE(xfer)) { 917 case USB_ST_TRANSFERRED: 918 DPRINTFN(11, "%u bytes in %u frames\n", actlen, aframes); 919 | 875 } 876 offset += msg.rm_len; 877 actlen -= msg.rm_len; 878 } 879 880 case USB_ST_SETUP: 881tr_setup: 882 usbd_xfer_set_frame_len(xfer, 0, RNDIS_RX_MAXLEN); --- 29 unchanged lines hidden (view full) --- 912 usbd_xfer_status(xfer, &actlen, NULL, &aframes, NULL); 913 914 DPRINTFN(1, "\n"); 915 916 switch (USB_GET_STATE(xfer)) { 917 case USB_ST_TRANSFERRED: 918 DPRINTFN(11, "%u bytes in %u frames\n", actlen, aframes); 919 |
920 ifp->if_opackets++; | 920 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); |
921 922 /* FALLTHROUGH */ 923 case USB_ST_SETUP: 924tr_setup: 925 memset(&msg, 0, sizeof(msg)); 926 927 for (x = 0; x != RNDIS_TX_FRAMES_MAX; x++) { 928 struct usb_page_cache *pc = usbd_xfer_get_frame(xfer, x); 929 930 usbd_xfer_set_frame_offset(xfer, x * RNDIS_TX_MAXLEN, x); 931 932 next_pkt: 933 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 934 935 if (m == NULL) 936 break; 937 938 if ((m->m_pkthdr.len + sizeof(msg)) > RNDIS_TX_MAXLEN) { 939 DPRINTF("Too big packet\n"); | 921 922 /* FALLTHROUGH */ 923 case USB_ST_SETUP: 924tr_setup: 925 memset(&msg, 0, sizeof(msg)); 926 927 for (x = 0; x != RNDIS_TX_FRAMES_MAX; x++) { 928 struct usb_page_cache *pc = usbd_xfer_get_frame(xfer, x); 929 930 usbd_xfer_set_frame_offset(xfer, x * RNDIS_TX_MAXLEN, x); 931 932 next_pkt: 933 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 934 935 if (m == NULL) 936 break; 937 938 if ((m->m_pkthdr.len + sizeof(msg)) > RNDIS_TX_MAXLEN) { 939 DPRINTF("Too big packet\n"); |
940 ifp->if_oerrors++; | 940 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
941 942 /* Free buffer */ 943 m_freem(m); 944 goto next_pkt; 945 } 946 msg.rm_type = htole32(REMOTE_NDIS_PACKET_MSG); 947 msg.rm_len = htole32(sizeof(msg) + m->m_pkthdr.len); 948 --- 19 unchanged lines hidden (view full) --- 968 usbd_transfer_submit(xfer); 969 } 970 break; 971 972 default: /* Error */ 973 DPRINTFN(11, "transfer error, %s\n", usbd_errstr(error)); 974 975 /* count output errors */ | 941 942 /* Free buffer */ 943 m_freem(m); 944 goto next_pkt; 945 } 946 msg.rm_type = htole32(REMOTE_NDIS_PACKET_MSG); 947 msg.rm_len = htole32(sizeof(msg) + m->m_pkthdr.len); 948 --- 19 unchanged lines hidden (view full) --- 968 usbd_transfer_submit(xfer); 969 } 970 break; 971 972 default: /* Error */ 973 DPRINTFN(11, "transfer error, %s\n", usbd_errstr(error)); 974 975 /* count output errors */ |
976 ifp->if_oerrors++; | 976 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
977 978 if (error != USB_ERR_CANCELLED) { 979 /* try to clear stall first */ 980 usbd_xfer_set_stall(xfer); 981 goto tr_setup; 982 } 983 break; 984 } --- 32 unchanged lines hidden --- | 977 978 if (error != USB_ERR_CANCELLED) { 979 /* try to clear stall first */ 980 usbd_xfer_set_stall(xfer); 981 goto tr_setup; 982 } 983 break; 984 } --- 32 unchanged lines hidden --- |