1/*- 2 * Copyright (c) 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from the Stanford/CMU enet packet filter, 6 * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 * Berkeley Laboratory. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from the Stanford/CMU enet packet filter, 6 * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 * Berkeley Laboratory. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#include <sys/cdefs.h>
|
36__FBSDID("$FreeBSD: head/sys/dev/usb/usb_pf.c 218165 2011-02-01 10:25:48Z hselasky $");
| 36__FBSDID("$FreeBSD: head/sys/dev/usb/usb_pf.c 220301 2011-04-03 20:03:45Z hselasky $");
|
37#include <sys/param.h> 38#include <sys/kernel.h> 39#include <sys/bus.h> 40#include <sys/fcntl.h> 41#include <sys/malloc.h> 42#include <sys/proc.h> 43#include <sys/socket.h> 44#include <sys/sockio.h> 45#include <net/if.h> 46#include <net/if_types.h> 47#include <net/bpf.h>
| 37#include <sys/param.h> 38#include <sys/kernel.h> 39#include <sys/bus.h> 40#include <sys/fcntl.h> 41#include <sys/malloc.h> 42#include <sys/proc.h> 43#include <sys/socket.h> 44#include <sys/sockio.h> 45#include <net/if.h> 46#include <net/if_types.h> 47#include <net/bpf.h>
|
| 48#include <sys/sysctl.h>
|
48 49#include <dev/usb/usb.h> 50#include <dev/usb/usbdi.h> 51#include <dev/usb/usb_busdma.h> 52#include <dev/usb/usb_controller.h> 53#include <dev/usb/usb_core.h> 54#include <dev/usb/usb_process.h> 55#include <dev/usb/usb_device.h> 56#include <dev/usb/usb_bus.h> 57#include <dev/usb/usb_pf.h> 58#include <dev/usb/usb_transfer.h> 59
| 49 50#include <dev/usb/usb.h> 51#include <dev/usb/usbdi.h> 52#include <dev/usb/usb_busdma.h> 53#include <dev/usb/usb_controller.h> 54#include <dev/usb/usb_core.h> 55#include <dev/usb/usb_process.h> 56#include <dev/usb/usb_device.h> 57#include <dev/usb/usb_bus.h> 58#include <dev/usb/usb_pf.h> 59#include <dev/usb/usb_transfer.h> 60
|
| 61static int usb_no_pf; 62 63SYSCTL_INT(_hw_usb, OID_AUTO, no_pf, CTLFLAG_RW, 64 &usb_no_pf, 0, "Set to disable USB packet filtering"); 65 66TUNABLE_INT("hw.usb.no_pf", &usb_no_pf); 67
|
60void 61usbpf_attach(struct usb_bus *ubus) 62{ 63 struct ifnet *ifp; 64
| 68void 69usbpf_attach(struct usb_bus *ubus) 70{ 71 struct ifnet *ifp; 72
|
| 73 if (usb_no_pf != 0) { 74 ubus->ifp = NULL; 75 return; 76 } 77
|
65 ifp = ubus->ifp = if_alloc(IFT_USB);
| 78 ifp = ubus->ifp = if_alloc(IFT_USB);
|
| 79 if (ifp == NULL) { 80 device_printf(ubus->parent, "usbpf: Could not allocate " 81 "instance\n"); 82 return; 83 } 84
|
66 if_initname(ifp, "usbus", device_get_unit(ubus->bdev)); 67 ifp->if_flags = IFF_CANTCONFIG; 68 if_attach(ifp); 69 if_up(ifp); 70
| 85 if_initname(ifp, "usbus", device_get_unit(ubus->bdev)); 86 ifp->if_flags = IFF_CANTCONFIG; 87 if_attach(ifp); 88 if_up(ifp); 89
|
71 KASSERT(sizeof(struct usbpf_pkthdr) == USBPF_HDR_LEN, 72 ("wrong USB pf header length (%zd)", sizeof(struct usbpf_pkthdr))); 73
| |
74 /*
| 90 /*
|
75 * XXX According to the specification of DLT_USB, it indicates packets 76 * beginning with USB setup header. But not sure all packets would be.
| 91 * XXX According to the specification of DLT_USB, it indicates 92 * packets beginning with USB setup header. But not sure all 93 * packets would be.
|
77 */ 78 bpfattach(ifp, DLT_USB, USBPF_HDR_LEN); 79 80 if (bootverbose)
| 94 */ 95 bpfattach(ifp, DLT_USB, USBPF_HDR_LEN); 96 97 if (bootverbose)
|
81 device_printf(ubus->parent, "usbpf attached\n");
| 98 device_printf(ubus->parent, "usbpf: Attached\n");
|
82} 83 84void 85usbpf_detach(struct usb_bus *ubus) 86{ 87 struct ifnet *ifp = ubus->ifp; 88 89 if (ifp != NULL) { 90 bpfdetach(ifp); 91 if_down(ifp); 92 if_detach(ifp); 93 if_free(ifp); 94 } 95 ubus->ifp = NULL; 96} 97 98static uint32_t 99usbpf_aggregate_xferflags(struct usb_xfer_flags *flags) 100{ 101 uint32_t val = 0; 102 103 if (flags->force_short_xfer == 1) 104 val |= USBPF_FLAG_FORCE_SHORT_XFER; 105 if (flags->short_xfer_ok == 1) 106 val |= USBPF_FLAG_SHORT_XFER_OK; 107 if (flags->short_frames_ok == 1) 108 val |= USBPF_FLAG_SHORT_FRAMES_OK; 109 if (flags->pipe_bof == 1) 110 val |= USBPF_FLAG_PIPE_BOF; 111 if (flags->proxy_buffer == 1) 112 val |= USBPF_FLAG_PROXY_BUFFER; 113 if (flags->ext_buffer == 1) 114 val |= USBPF_FLAG_EXT_BUFFER; 115 if (flags->manual_status == 1) 116 val |= USBPF_FLAG_MANUAL_STATUS; 117 if (flags->no_pipe_ok == 1) 118 val |= USBPF_FLAG_NO_PIPE_OK; 119 if (flags->stall_pipe == 1) 120 val |= USBPF_FLAG_STALL_PIPE; 121 return (val); 122} 123 124static uint32_t 125usbpf_aggregate_status(struct usb_xfer_flags_int *flags) 126{ 127 uint32_t val = 0; 128 129 if (flags->open == 1) 130 val |= USBPF_STATUS_OPEN; 131 if (flags->transferring == 1) 132 val |= USBPF_STATUS_TRANSFERRING; 133 if (flags->did_dma_delay == 1) 134 val |= USBPF_STATUS_DID_DMA_DELAY; 135 if (flags->did_close == 1) 136 val |= USBPF_STATUS_DID_CLOSE; 137 if (flags->draining == 1) 138 val |= USBPF_STATUS_DRAINING; 139 if (flags->started == 1) 140 val |= USBPF_STATUS_STARTED; 141 if (flags->bandwidth_reclaimed == 1) 142 val |= USBPF_STATUS_BW_RECLAIMED; 143 if (flags->control_xfr == 1) 144 val |= USBPF_STATUS_CONTROL_XFR; 145 if (flags->control_hdr == 1) 146 val |= USBPF_STATUS_CONTROL_HDR; 147 if (flags->control_act == 1) 148 val |= USBPF_STATUS_CONTROL_ACT; 149 if (flags->control_stall == 1) 150 val |= USBPF_STATUS_CONTROL_STALL; 151 if (flags->short_frames_ok == 1) 152 val |= USBPF_STATUS_SHORT_FRAMES_OK; 153 if (flags->short_xfer_ok == 1) 154 val |= USBPF_STATUS_SHORT_XFER_OK; 155#if USB_HAVE_BUSDMA 156 if (flags->bdma_enable == 1) 157 val |= USBPF_STATUS_BDMA_ENABLE; 158 if (flags->bdma_no_post_sync == 1) 159 val |= USBPF_STATUS_BDMA_NO_POST_SYNC; 160 if (flags->bdma_setup == 1) 161 val |= USBPF_STATUS_BDMA_SETUP; 162#endif 163 if (flags->isochronous_xfr == 1) 164 val |= USBPF_STATUS_ISOCHRONOUS_XFR; 165 if (flags->curr_dma_set == 1) 166 val |= USBPF_STATUS_CURR_DMA_SET; 167 if (flags->can_cancel_immed == 1) 168 val |= USBPF_STATUS_CAN_CANCEL_IMMED; 169 if (flags->doing_callback == 1) 170 val |= USBPF_STATUS_DOING_CALLBACK; 171 172 return (val); 173} 174
| 99} 100 101void 102usbpf_detach(struct usb_bus *ubus) 103{ 104 struct ifnet *ifp = ubus->ifp; 105 106 if (ifp != NULL) { 107 bpfdetach(ifp); 108 if_down(ifp); 109 if_detach(ifp); 110 if_free(ifp); 111 } 112 ubus->ifp = NULL; 113} 114 115static uint32_t 116usbpf_aggregate_xferflags(struct usb_xfer_flags *flags) 117{ 118 uint32_t val = 0; 119 120 if (flags->force_short_xfer == 1) 121 val |= USBPF_FLAG_FORCE_SHORT_XFER; 122 if (flags->short_xfer_ok == 1) 123 val |= USBPF_FLAG_SHORT_XFER_OK; 124 if (flags->short_frames_ok == 1) 125 val |= USBPF_FLAG_SHORT_FRAMES_OK; 126 if (flags->pipe_bof == 1) 127 val |= USBPF_FLAG_PIPE_BOF; 128 if (flags->proxy_buffer == 1) 129 val |= USBPF_FLAG_PROXY_BUFFER; 130 if (flags->ext_buffer == 1) 131 val |= USBPF_FLAG_EXT_BUFFER; 132 if (flags->manual_status == 1) 133 val |= USBPF_FLAG_MANUAL_STATUS; 134 if (flags->no_pipe_ok == 1) 135 val |= USBPF_FLAG_NO_PIPE_OK; 136 if (flags->stall_pipe == 1) 137 val |= USBPF_FLAG_STALL_PIPE; 138 return (val); 139} 140 141static uint32_t 142usbpf_aggregate_status(struct usb_xfer_flags_int *flags) 143{ 144 uint32_t val = 0; 145 146 if (flags->open == 1) 147 val |= USBPF_STATUS_OPEN; 148 if (flags->transferring == 1) 149 val |= USBPF_STATUS_TRANSFERRING; 150 if (flags->did_dma_delay == 1) 151 val |= USBPF_STATUS_DID_DMA_DELAY; 152 if (flags->did_close == 1) 153 val |= USBPF_STATUS_DID_CLOSE; 154 if (flags->draining == 1) 155 val |= USBPF_STATUS_DRAINING; 156 if (flags->started == 1) 157 val |= USBPF_STATUS_STARTED; 158 if (flags->bandwidth_reclaimed == 1) 159 val |= USBPF_STATUS_BW_RECLAIMED; 160 if (flags->control_xfr == 1) 161 val |= USBPF_STATUS_CONTROL_XFR; 162 if (flags->control_hdr == 1) 163 val |= USBPF_STATUS_CONTROL_HDR; 164 if (flags->control_act == 1) 165 val |= USBPF_STATUS_CONTROL_ACT; 166 if (flags->control_stall == 1) 167 val |= USBPF_STATUS_CONTROL_STALL; 168 if (flags->short_frames_ok == 1) 169 val |= USBPF_STATUS_SHORT_FRAMES_OK; 170 if (flags->short_xfer_ok == 1) 171 val |= USBPF_STATUS_SHORT_XFER_OK; 172#if USB_HAVE_BUSDMA 173 if (flags->bdma_enable == 1) 174 val |= USBPF_STATUS_BDMA_ENABLE; 175 if (flags->bdma_no_post_sync == 1) 176 val |= USBPF_STATUS_BDMA_NO_POST_SYNC; 177 if (flags->bdma_setup == 1) 178 val |= USBPF_STATUS_BDMA_SETUP; 179#endif 180 if (flags->isochronous_xfr == 1) 181 val |= USBPF_STATUS_ISOCHRONOUS_XFR; 182 if (flags->curr_dma_set == 1) 183 val |= USBPF_STATUS_CURR_DMA_SET; 184 if (flags->can_cancel_immed == 1) 185 val |= USBPF_STATUS_CAN_CANCEL_IMMED; 186 if (flags->doing_callback == 1) 187 val |= USBPF_STATUS_DOING_CALLBACK; 188 189 return (val); 190} 191
|
| 192static int 193usbpf_xfer_frame_is_read(struct usb_xfer *xfer, uint32_t frame) 194{ 195 int isread; 196 197 if ((frame == 0) && (xfer->flags_int.control_xfr != 0) && 198 (xfer->flags_int.control_hdr != 0)) { 199 /* special case */ 200 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) { 201 /* The device controller writes to memory */ 202 isread = 1; 203 } else { 204 /* The host controller reads from memory */ 205 isread = 0; 206 } 207 } else { 208 isread = USB_GET_DATA_ISREAD(xfer); 209 } 210 return (isread); 211} 212 213static uint32_t 214usbpf_xfer_precompute_size(struct usb_xfer *xfer, int type) 215{ 216 uint32_t totlen; 217 uint32_t x; 218 uint32_t nframes; 219 220 if (type == USBPF_XFERTAP_SUBMIT) 221 nframes = xfer->nframes; 222 else 223 nframes = xfer->aframes; 224 225 totlen = USBPF_HDR_LEN + (USBPF_FRAME_HDR_LEN * nframes); 226 227 /* precompute all trace lengths */ 228 for (x = 0; x != nframes; x++) { 229 if (usbpf_xfer_frame_is_read(xfer, x)) { 230 if (type != USBPF_XFERTAP_SUBMIT) { 231 totlen += USBPF_FRAME_ALIGN( 232 xfer->frlengths[x]); 233 } 234 } else { 235 if (type == USBPF_XFERTAP_SUBMIT) { 236 totlen += USBPF_FRAME_ALIGN( 237 xfer->frlengths[x]); 238 } 239 } 240 } 241 return (totlen); 242} 243
|
175void 176usbpf_xfertap(struct usb_xfer *xfer, int type) 177{
| 244void 245usbpf_xfertap(struct usb_xfer *xfer, int type) 246{
|
178 struct usb_endpoint *ep = xfer->endpoint; 179 struct usb_page_search res; 180 struct usb_xfer_root *info = xfer->xroot; 181 struct usb_bus *bus = info->bus;
| 247 struct usb_bus *bus;
|
182 struct usbpf_pkthdr *up;
| 248 struct usbpf_pkthdr *up;
|
183 usb_frlength_t isoc_offset = 0; 184 int i; 185 char *buf, *ptr, *end;
| 249 struct usbpf_framehdr *uf; 250 usb_frlength_t offset; 251 uint32_t totlen; 252 uint32_t frame; 253 uint32_t temp; 254 uint32_t nframes; 255 uint32_t x; 256 uint8_t *buf; 257 uint8_t *ptr;
|
186
| 258
|
| 259 bus = xfer->xroot->bus; 260 261 /* sanity checks */ 262 if (usb_no_pf != 0) 263 return; 264 if (bus->ifp == NULL) 265 return;
|
187 if (!bpf_peers_present(bus->ifp->if_bpf)) 188 return; 189
| 266 if (!bpf_peers_present(bus->ifp->if_bpf)) 267 return; 268
|
| 269 totlen = usbpf_xfer_precompute_size(xfer, type); 270 271 if (type == USBPF_XFERTAP_SUBMIT) 272 nframes = xfer->nframes; 273 else 274 nframes = xfer->aframes; 275
|
190 /*
| 276 /*
|
191 * XXX TODO 192 * Allocating the buffer here causes copy operations twice what's 193 * really inefficient. Copying usbpf_pkthdr and data is for USB packet 194 * read filter to pass a virtually linear buffer.
| 277 * XXX TODO XXX 278 * 279 * When BPF supports it we could pass a fragmented array of 280 * buffers avoiding the data copy operation here.
|
195 */
| 281 */
|
196 buf = ptr = malloc(sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5), 197 M_TEMP, M_NOWAIT);
| 282 buf = ptr = malloc(totlen, M_TEMP, M_NOWAIT);
|
198 if (buf == NULL) {
| 283 if (buf == NULL) {
|
199 printf("usbpf_xfertap: out of memory\n"); /* XXX */
| 284 device_printf(bus->parent, "usbpf: Out of memory\n");
|
200 return; 201 }
| 285 return; 286 }
|
202 end = buf + sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5);
| |
203
| 287
|
204 bzero(ptr, sizeof(struct usbpf_pkthdr));
| |
205 up = (struct usbpf_pkthdr *)ptr;
| 288 up = (struct usbpf_pkthdr *)ptr;
|
206 up->up_busunit = htole32(device_get_unit(bus->bdev));
| 289 ptr += USBPF_HDR_LEN; 290 291 /* fill out header */ 292 temp = device_get_unit(bus->bdev); 293 up->up_totlen = htole32(totlen); 294 up->up_busunit = htole32(temp); 295 up->up_address = xfer->xroot->udev->device_index; 296 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) 297 up->up_mode = USBPF_MODE_DEVICE; 298 else 299 up->up_mode = USBPF_MODE_HOST;
|
207 up->up_type = type;
| 300 up->up_type = type;
|
208 up->up_xfertype = ep->edesc->bmAttributes & UE_XFERTYPE; 209 up->up_address = xfer->address; 210 up->up_endpoint = xfer->endpointno; 211 up->up_flags = htole32(usbpf_aggregate_xferflags(&xfer->flags)); 212 up->up_status = htole32(usbpf_aggregate_status(&xfer->flags_int)); 213 switch (type) { 214 case USBPF_XFERTAP_SUBMIT: 215 up->up_length = htole32(xfer->sumlen); 216 up->up_frames = htole32(xfer->nframes); 217 break; 218 case USBPF_XFERTAP_DONE: 219 up->up_length = htole32(xfer->actlen); 220 up->up_frames = htole32(xfer->aframes); 221 break; 222 default: 223 panic("wrong usbpf type (%d)", type); 224 }
| 301 up->up_xfertype = xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE; 302 temp = usbpf_aggregate_xferflags(&xfer->flags); 303 up->up_flags = htole32(temp); 304 temp = usbpf_aggregate_status(&xfer->flags_int); 305 up->up_status = htole32(temp); 306 temp = xfer->error; 307 up->up_error = htole32(temp); 308 temp = xfer->interval; 309 up->up_interval = htole32(temp); 310 up->up_frames = htole32(nframes); 311 temp = xfer->max_packet_size; 312 up->up_packet_size = htole32(temp); 313 temp = xfer->max_packet_count; 314 up->up_packet_count = htole32(temp); 315 temp = xfer->endpointno; 316 up->up_endpoint = htole32(temp); 317 up->up_speed = xfer->xroot->udev->speed;
|
225
| 318
|
226 up->up_error = htole32(xfer->error); 227 up->up_interval = htole32(xfer->interval); 228 ptr += sizeof(struct usbpf_pkthdr);
| 319 /* clear reserved area */ 320 memset(up->up_reserved, 0, sizeof(up->up_reserved));
|
229
| 321
|
230 for (i = 0; i < up->up_frames; i++) { 231 if (ptr + sizeof(uint32_t) >= end) 232 goto done; 233 *((uint32_t *)ptr) = htole32(xfer->frlengths[i]); 234 ptr += sizeof(uint32_t);
| 322 /* init offset and frame */ 323 offset = 0; 324 frame = 0;
|
235
| 325
|
236 if (ptr + xfer->frlengths[i] >= end) 237 goto done; 238 if (xfer->flags_int.isochronous_xfr == 1) { 239 usbd_get_page(&xfer->frbuffers[0], isoc_offset, &res); 240 isoc_offset += xfer->frlengths[i]; 241 } else 242 usbd_get_page(&xfer->frbuffers[i], 0, &res); 243 bcopy(res.buffer, ptr, xfer->frlengths[i]); 244 ptr += xfer->frlengths[i];
| 326 /* iterate all the USB frames and copy data, if any */ 327 for (x = 0; x != nframes; x++) { 328 uint32_t length; 329 int isread; 330 331 /* get length */ 332 length = xfer->frlengths[x]; 333 334 /* get frame header pointer */ 335 uf = (struct usbpf_framehdr *)ptr; 336 ptr += USBPF_FRAME_HDR_LEN; 337 338 /* fill out packet header */ 339 uf->length = htole32(length); 340 uf->flags = 0; 341 342 /* get information about data read/write */ 343 isread = usbpf_xfer_frame_is_read(xfer, x); 344 345 /* check if we need to copy any data */ 346 if (isread) { 347 if (type == USBPF_XFERTAP_SUBMIT) 348 length = 0; 349 else { 350 uf->flags |= htole32( 351 USBPF_FRAMEFLAG_DATA_FOLLOWS); 352 } 353 } else { 354 if (type != USBPF_XFERTAP_SUBMIT) 355 length = 0; 356 else { 357 uf->flags |= htole32( 358 USBPF_FRAMEFLAG_DATA_FOLLOWS); 359 } 360 } 361 362 /* check if data is read direction */ 363 if (isread) 364 uf->flags |= htole32(USBPF_FRAMEFLAG_READ); 365 366 /* copy USB data, if any */ 367 if (length != 0) { 368 /* copy data */ 369 usbd_copy_out(&xfer->frbuffers[frame], 370 offset, ptr, length); 371 372 /* align length */ 373 temp = USBPF_FRAME_ALIGN(length); 374 375 /* zero pad */ 376 if (temp != length) 377 memset(ptr + length, 0, temp - length); 378 379 ptr += temp; 380 } 381 382 if (xfer->flags_int.isochronous_xfr) { 383 offset += usbd_xfer_old_frame_length(xfer, x); 384 } else { 385 frame ++; 386 }
|
245 } 246
| 387 } 388
|
247 bpf_tap(bus->ifp->if_bpf, buf, ptr - buf); 248done:
| 389 bpf_tap(bus->ifp->if_bpf, buf, totlen); 390
|
249 free(buf, M_TEMP); 250}
| 391 free(buf, M_TEMP); 392}
|