Отключить USB без пересборки ядра
Добавлено: 2008-06-15 17:41:04
возможно ли отключить usb порт без пересборки ядра?
Если не знаешь что делать – делай шаг вперёд
https://forum.lissyara.su/
Господа, зачем спорить, если вы не знакомы с предметом? Подобные высказывания вводят в заблуждения посетителей форума.zingel писал(а):всё можно, если есть смелость и прямые руки, делается это через /boot/device.hints, к параметру устройства надо добавить .disabled="1"
Код: Выделить всё
static int
madt_probe(void)
{
ACPI_PHYSICAL_ADDRESS rsdp_ptr;
ACPI_TABLE_RSDP *rsdp;
ACPI_TABLE_RSDT *rsdt;
ACPI_TABLE_XSDT *xsdt;
int i, count;
if (resource_disabled("acpi", 0))
return (ENXIO);
Код: Выделить всё
Господа, зачем спорить, если вы не знакомы с предметом? Подобные высказывания вводят в заблуждения посетителей форума.
Да ну? А это что такое? /usr/src/sys/sys/bus.hЯ же уже сказал, если в драйвере не предусмотрена такая возможность, то при помощи device.hints его не отключить.
Код: Выделить всё
******
int resource_disabled(const char *name, int unit);
******
device_t device_add_child(device_t dev, const char *name, int unit);
const char *name, int unit);
******
device_t devclass_get_device(devclass_t dc, int unit);
int devclass_get_devices(devclass_t dc, device_t **listp, int *countp);
static __inline type varp ## _get_ ## var(device_t dev) \
static __inline void varp ## _set_ ## var(device_t dev, type t) \
Код: Выделить всё
METHOD int deactivate_resource {
device_t _dev;
device_t _child;
int _type;
int _rid;
struct resource *_r;
};
Код: Выделить всё
man 9 bus_alloc_resource
Эти функции не имеют отношения к device.hints. Это функции управления ресурсами (IRQ, регионами памяти и портами ввода-вывода) и функции bus-драйверов (см. http://www.freebsd.org/doc/en/books/arc ... ewbus.html).zingel писал(а): Да ну? А это что такое? /usr/src/sys/sys/bus.h
Код: Выделить всё
device_t device_add_child(device_t dev, const char *name, int unit); const char *name, int unit); device_t devclass_get_device(devclass_t dc, int unit); int devclass_get_devices(devclass_t dc, device_t **listp, int *countp); static __inline type varp ## _get_ ## var(device_t dev) \ static __inline void varp ## _set_ ## var(device_t dev, type t) \
Это шаблон метода bus_deactivate_resource. Эта функция используется в драйвере для временного отключения выделенных функцией bus_alloc_resource ресурсов. Тоже не имеет отношения к device.hints.zingel писал(а): а это тоже наверное просто так? /usr/src/sys/kern/bus_if.m
METHOD int deactivate_resource {
device_t _dev;
device_t _child;
int _type;
int _rid;
struct resource *_r;
};
[/code]Код: Выделить всё
man 9 bus_alloc_resource
Код: Выделить всё
struct atausb_softc {
device_t dev; /* base device */
usbd_interface_handle iface; /* interface */
******
static void
atausb_clear_stall(struct atausb_softc *sc, u_int8_t endpt,
usbd_pipe_handle pipe, int state, usbd_xfer_handle xfer)
{
usbd_device_handle udev;
if (atausbdebug)
device_printf(sc->dev, "clear endpoint 0x%02x stall\n", endpt);
usbd_interface2device_handle(sc->iface, &udev);
sc->state = state;
usbd_clear_endpoint_toggle(pipe);
sc->usb_request.bmRequestType = UT_WRITE_ENDPOINT;
sc->usb_request.bRequest = UR_CLEAR_FEATURE;
USETW(sc->usb_request.wValue, UF_ENDPOINT_HALT);
USETW(sc->usb_request.wIndex, endpt);
USETW(sc->usb_request.wLength, 0);
atausb_ctl_start(sc, udev, &sc->usb_request, NULL, 0, 0, xfer);
}
Код: Выделить всё
/*
* Copyright (c) 2008 Anish Mistry. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
This software allows the selective suspending and enabling of usb ports on a hub.
Provide it the uhub device eg. /dev/usb2 the port on the hub to which the device
is attached and the action.
Use usbdevs -v to find the hub and port number
eg. ./usb_power /dev/usb4 4 suspend
NOTE: Using the disable action is not recommended. suspend should achieve
the desired result.
*/
#include <dev/usb/usb.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PORT_DISABLE 0
#define PORT_ENABLE 1
#define PORT_SUSPEND 2
int
main(int argc, char *argv[])
{
usb_device_descriptor_t usbdd;
struct usb_ctl_request req;
int fd, ret, port_num, dev_address;
int enable = 0;
if(argc != 4)
{
printf("usage: %s uhub_device port_num [enable|suspend|disable]\n", argv[0]);
return 1;
}
if((fd = open(argv[1], O_RDWR, 0)) == -1)
{
printf("Can't open device %s!\n", argv[1]);
return 1;
}
port_num = atoi(argv[2]);
dev_address = 1; // why? magic?
if(strncmp("enable", argv[3], 6) == 0)
{
enable = PORT_ENABLE;
}
else if(strncmp("disable", argv[3], 7) == 0)
{
enable = PORT_DISABLE;
}
else if(strncmp("suspend", argv[3], 7) == 0)
{
enable = PORT_SUSPEND;
}
switch(enable)
{
case PORT_ENABLE:
// power up
bzero(&req, sizeof(req));
req.ucr_addr = dev_address;
req.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
req.ucr_request.bRequest = UR_SET_FEATURE; // clear a feature
USETW(req.ucr_request.wIndex, port_num); // usb port number
USETW(req.ucr_request.wLength, 0);
USETW(req.ucr_request.wValue, UHF_PORT_POWER);
if (ioctl(fd, USB_REQUEST, &req) != 0) {
printf("ioctl USB_REQUEST UR_CLEAR_FEATURE UHF_PORT_POWER failed\n");
close(fd);
exit(EXIT_FAILURE);
}
// resume
bzero(&req, sizeof(req));
req.ucr_addr = dev_address;
req.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
req.ucr_request.bRequest = UR_CLEAR_FEATURE; // set a feature
USETW(req.ucr_request.wIndex, port_num); // usb port number
USETW(req.ucr_request.wLength, 0);
USETW(req.ucr_request.wValue, UHF_PORT_SUSPEND);
if (ioctl(fd, USB_REQUEST, &req) != 0) {
printf("ioctl USB_REQUEST UR_SET_FEATURE UHF_PORT_SUSPEND failed\n");
close(fd);
exit(EXIT_FAILURE);
}
// enable
bzero(&req, sizeof(req));
req.ucr_addr = dev_address;
req.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
req.ucr_request.bRequest = UR_SET_FEATURE; // set a feature
USETW(req.ucr_request.wIndex, port_num); // usb port number
USETW(req.ucr_request.wLength, 0);
USETW(req.ucr_request.wValue, UHF_PORT_ENABLE);
if (ioctl(fd, USB_REQUEST, &req) != 0) {
printf("ioctl USB_REQUEST UR_SET_FEATURE UHF_PORT_ENABLE failed\n");
close(fd);
exit(EXIT_FAILURE);
}
// reset
bzero(&req, sizeof(req));
req.ucr_addr = dev_address;
req.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
req.ucr_request.bRequest = UR_SET_FEATURE; // set a feature
USETW(req.ucr_request.wIndex, port_num); // usb port number
USETW(req.ucr_request.wLength, 0);
USETW(req.ucr_request.wValue, UHF_PORT_RESET);
if (ioctl(fd, USB_REQUEST, &req) != 0) {
printf("ioctl USB_REQUEST UR_SET_FEATURE UHF_PORT_RESET failed\n");
close(fd);
exit(EXIT_FAILURE);
}
break;
case PORT_SUSPEND:
// suspend the port
bzero(&req, sizeof(req));
req.ucr_addr = dev_address;
req.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
req.ucr_request.bRequest = UR_SET_FEATURE; // set a feature
USETW(req.ucr_request.wIndex, port_num); // usb port number
USETW(req.ucr_request.wLength, 0);
USETW(req.ucr_request.wValue, UHF_PORT_SUSPEND);
if (ioctl(fd, USB_REQUEST, &req) != 0) {
printf("ioctl USB_REQUEST UR_SET_FEATURE UHF_PORT_SUSPEND failed\n");
close(fd);
exit(EXIT_FAILURE);
}
break;
case PORT_DISABLE:
printf("WARNING! Only use disable if suspend doesn't work!\n");
// disable the port
bzero(&req, sizeof(req));
req.ucr_addr = dev_address; // device address
req.ucr_request.bmRequestType = UT_WRITE_CLASS_OTHER;
req.ucr_request.bRequest = UR_CLEAR_FEATURE; // clear a feature
USETW(req.ucr_request.wIndex, port_num); // usb port number
USETW(req.ucr_request.wLength, 0);
USETW(req.ucr_request.wValue, UHF_PORT_ENABLE);
if (ioctl(fd, USB_REQUEST, &req) != 0) {
printf("ioctl USB_REQUEST UHF_PORT_ENABLE failed\n");
close(fd);
exit(EXIT_FAILURE);
}
break;
default:
printf("Unknown action: %d", enable);
break;
}
close(fd);
return 0;
}
как я понимаю данный кусок кода надо скомпилировать?zingel писал(а): Вобщем разговор ни о чем, автор темы, скопилируйте следующий код и пользуйтесь:
))Gloft писал(а):.... надо скомпилировать?...zingel писал(а): .... скопилируйте следующий код....