1300829Sgrehan/*- 2336189Saraujo * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3336189Saraujo * 4300829Sgrehan * Copyright (c) 2014 Nahanni Systems Inc. 5300829Sgrehan * All rights reserved. 6300829Sgrehan * 7300829Sgrehan * Redistribution and use in source and binary forms, with or without 8300829Sgrehan * modification, are permitted provided that the following conditions 9300829Sgrehan * are met: 10300829Sgrehan * 1. Redistributions of source code must retain the above copyright 11300829Sgrehan * notice, this list of conditions and the following disclaimer. 12300829Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 13300829Sgrehan * notice, this list of conditions and the following disclaimer in the 14300829Sgrehan * documentation and/or other materials provided with the distribution. 15300829Sgrehan * 16300829Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17300829Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18300829Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19300829Sgrehan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20300829Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21300829Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22300829Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23300829Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24300829Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25300829Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26300829Sgrehan * SUCH DAMAGE. 27300829Sgrehan */ 28300829Sgrehan 29300829Sgrehan#include <sys/cdefs.h> 30300829Sgrehan__FBSDID("$FreeBSD: stable/11/usr.sbin/bhyve/usb_emul.c 336189 2018-07-11 07:16:13Z araujo $"); 31300829Sgrehan 32300829Sgrehan#include <sys/types.h> 33300829Sgrehan#include <sys/queue.h> 34300829Sgrehan 35300829Sgrehan#include <assert.h> 36300829Sgrehan#include <stdio.h> 37300829Sgrehan#include <stdlib.h> 38300829Sgrehan#include <string.h> 39300829Sgrehan#include <pthread.h> 40300829Sgrehan 41300829Sgrehan#include "usb_emul.h" 42300829Sgrehan 43300829SgrehanSET_DECLARE(usb_emu_set, struct usb_devemu); 44300829Sgrehan 45300829Sgrehanstruct usb_devemu * 46300829Sgrehanusb_emu_finddev(char *name) 47300829Sgrehan{ 48300829Sgrehan struct usb_devemu **udpp, *udp; 49300829Sgrehan 50300829Sgrehan SET_FOREACH(udpp, usb_emu_set) { 51300829Sgrehan udp = *udpp; 52300829Sgrehan if (!strcmp(udp->ue_emu, name)) 53300829Sgrehan return (udp); 54300829Sgrehan } 55300829Sgrehan 56300829Sgrehan return (NULL); 57300829Sgrehan} 58300829Sgrehan 59300829Sgrehanstruct usb_data_xfer_block * 60300829Sgrehanusb_data_xfer_append(struct usb_data_xfer *xfer, void *buf, int blen, 61300829Sgrehan void *hci_data, int ccs) 62300829Sgrehan{ 63300829Sgrehan struct usb_data_xfer_block *xb; 64300829Sgrehan 65300829Sgrehan if (xfer->ndata >= USB_MAX_XFER_BLOCKS) 66300829Sgrehan return (NULL); 67300829Sgrehan 68300829Sgrehan xb = &xfer->data[xfer->tail]; 69300829Sgrehan xb->buf = buf; 70300829Sgrehan xb->blen = blen; 71300829Sgrehan xb->hci_data = hci_data; 72300829Sgrehan xb->ccs = ccs; 73300829Sgrehan xb->processed = 0; 74300829Sgrehan xb->bdone = 0; 75300829Sgrehan xfer->ndata++; 76300829Sgrehan xfer->tail = (xfer->tail + 1) % USB_MAX_XFER_BLOCKS; 77300829Sgrehan return (xb); 78300829Sgrehan} 79