Comments (14)
0xc0
has USB_DIR_IN
(0x80
) bit set, which makes it an IN
request. So the host doesn't send data to the device but expects the device to send it. You need to use an OUT
request if you want to send data to the device.
from raw-gadget.
thanks xairy,but I can't get data when used 0x40 too. how can i do?
from raw-gadget.
I would first make sure that the USB request is sent from the host as expected via usbmon
.
How exactly does getting data fail for you? Do you get bad wLength
from USB_RAW_IOCTL_EVENT_FETCH
? Or does USB_RAW_IOCTL_EP0_READ
fail?
from raw-gadget.
the wLength received is ok, but when USB_RAW_IOCTL_EP0_READ is wrong,this is my source:
if (event.ctrl.bRequestType==0x40) //add by duke 2023.12.25
{
PTRACE("received customed command! 0x40");
if (ep0_cbFunc!=NULL) //customed command
{
usb_raw_ep0_read(usb_fd, (struct usb_raw_ep_io )&io);
PTRACE("epo read :%s",io.data);
ep0_cbFunc(ep0_cbArgs,event.ctrl.wIndex,event.ctrl.wValue,(char)&io.data[0],event.ctrl.wLength);
}
}
else
{
rv = usb_raw_ep0_read(usb_fd, (struct usb_raw_ep_io *)&io);
printf("ep0: transferred %d bytes (out)\n", rv);
if (event.ctrl.wLength>0)
printf("read control %s\n",io.data[0]);
}
it will print info:
event: control, length: 8
bRequestType: 0x40 (OUT), bRequest: 0x0, wValue: 0x11, wIndex: 0x22, wLength: 12
type = USB_TYPE_VENDOR
req = unknown = 0x0
fail: no response USB_TYPE_VENDOR
11:21:59 : usb_gadget.cpp(968) received customed command! 0x40
ioctl(USB_RAW_IOCTL_EP0_READ): Invalid argument
from raw-gadget.
Invalid argument
means there's something wrong with the arguments you provide to USB_RAW_IOCTL_EP0_READ
. The code that you shared doesn't show that part, so I don't know what is wrong.
Enabling debug output as described here and potentially adding more debug messages into the USB_RAW_IOCTL_EP0_READ
handler should help you figure out what's wrong.
from raw-gadget.
ok,I give my full code here which refered from gadget.c:
void usb_gadget::ep0_loop()
{
PTRACE("*****enter ep0_read_loop******");
while (usbRuning)
{
struct usb_raw_control_event event;
event.inner.type = 0;
event.inner.length = sizeof(event.ctrl);
usb_raw_event_fetch(usb_fd, (struct usb_raw_event *)&event);
log_event((struct usb_raw_event *)&event);
if (event.inner.type == USB_RAW_EVENT_CONNECT) {
process_eps_info(usb_fd);
continue;
}
if (event.inner.type != USB_RAW_EVENT_CONTROL)
continue;
struct usb_raw_control_io io;
io.inner.ep = 0;
io.inner.flags = 0;
io.inner.length = 0;//event.ctrl.wLength;//0;
bool reply = ep0_request(usb_fd, &event, &io);
if (!reply) {
printf("ep0: stalling\n");
usb_raw_ep0_stall(usb_fd);
continue;
}
if (event.ctrl.wLength < io.inner.length)
io.inner.length = event.ctrl.wLength;
int rv = -1;
#if 1
if (event.ctrl.bRequestType & USB_DIR_IN) //to host
{
if (event.ctrl.bRequestType==0xc0) //add by duke 2023.12.25
{
PTRACE("received customed command! 0xc0");
if (ep0_cbFunc!=NULL) //customed command
{
//if (event.ctrl.wLength>0)
// usb_raw_ep0_read(usb_fd, (struct usb_raw_ep_io *)&io);
ep0_cbFunc(ep0_cbArgs,event.ctrl.wIndex,event.ctrl.wValue,(char *)&io.data[0],event.ctrl.wLength);
}
}
//else
{
rv = usb_raw_ep0_write(usb_fd, (struct usb_raw_ep_io *)&io);
printf("ep0: transferred %d bytes (in)\n", rv);
}
}
else //to device
{
if (event.ctrl.bRequestType==0x40) //add by duke 2023.12.25
{
PTRACE("received customed command! 0x40");
if (ep0_cbFunc!=NULL) //customed command
{
usb_raw_ep0_read(usb_fd, (struct usb_raw_ep_io *)&io);
PTRACE("epo read :%s",io.data);
ep0_cbFunc(ep0_cbArgs,event.ctrl.wIndex,event.ctrl.wValue,(char*)&io.data[0],event.ctrl.wLength);
}
}
else
{
rv = usb_raw_ep0_read(usb_fd, (struct usb_raw_ep_io *)&io);
printf("ep0: transferred %d bytes (out)\n", rv);
if (event.ctrl.wLength>0)
printf("read control %s\n",io.data[0]);
}
}
#else
if (event.ctrl.bRequestType & USB_DIR_IN) {
rv = usb_raw_ep0_write(usb_fd, (struct usb_raw_ep_io *)&io);
printf("ep0: transferred %d bytes (in)\n", rv);
} else {
rv = usb_raw_ep0_read(usb_fd, (struct usb_raw_ep_io *)&io);
printf("ep0: transferred %d bytes (out)\n", rv);
}
#endif
if ((event.ctrl.bRequestType & USB_TYPE_MASK) ==
USB_TYPE_VENDOR &&
event.ctrl.bRequest == VENDOR_REQ_OUT)
memcpy(&vendor_buffer[0], &io.data[0], rv);
}
PTRACE("*****exit ep0_read_loop******");
}
from raw-gadget.
Do you initialize io->inner.length
to be event.ctrl.wLength
in ep0_request
for your custom requests? If not, you need to do this.
If fixing this doesn't help, please enable the debug output for the Raw Gadget module and share the messages it prints to the kernel log.
from raw-gadget.
thanks xairy, I can got "hello world!" ,it fee well. now when i add one code in ep0_request()
default:
io->inner.length = event->ctrl.wLength;//add by duke 2024.1.9
printf("fail: no response USB_TYPE_VENDOR\n");
//exit(EXIT_FAILURE);
break;
If i ack the usb control , How can i return usb_ctrlrequest data?
from raw-gadget.
Hi,xairy,We used ctrl endpoint to chat with host PC,I have write a function send_ctrl_data(),but if i called ,crashed....I post my code file here.please help me review it.thanks a lot!
gadget_test.zip
from raw-gadget.
to xairy: in our project,we need ep0 control channel to chat with pc for most customed command,We have done it ok in movidus platform,now we change device from movidus platform to nvidia platform
from raw-gadget.
Hi,xairy,We used ctrl endpoint to chat with host PC,I have write a function send_ctrl_data(),but if i called ,crashed....I post my code file here.please help me review it.thanks a lot!
I'd be happy to answer any Raw Gadget-related questions, but I don't have the throughput to debug crashes in your code unfortunately :(
If i ack the usb control , How can i return usb_ctrlrequest data?
If I understand your question correctly: When you fetch a USB_RAW_EVENT_CONNECT
event, usb_ctrlrequest
is provided in the data
field of usb_raw_event
. This happens before you ack the request via USB_RAW_IOCTL_EP0_WRITE/READ
.
from raw-gadget.
I have debug ok and it work now
from raw-gadget.
but i find it work on usb2.0,not work usb3.0..... ^_^,print error:
event: control, length: 8
bRequestType: 0x0 (OUT), bRequest: 0x9, wValue: 0x1, wIndex: 0x0, wLength: 0
type = USB_TYPE_STANDARD
req = USB_REQ_SET_CONFIGURATION
ioctl(USB_RAW_IOCTL_EP_ENABLE): Invalid argument
bulk_out: ep = #-1
from raw-gadget.
Raw Gadget doesn't support USB 3, see #61. You can enable debugging output for the Raw Gadget module to see what exactly is failing. I would expect that the USB stack expects a USB endpoint companion descriptor, which Raw Gadget doesn't provide.
from raw-gadget.
Related Issues (20)
- Test Raw Gadget on OpenStick
- Proxy-based Raw Gadget tests
- Facedancer Error w/ Raw Gadget HOT 7
- Logitech webcam can not proxy with AristoChen/usb-proxy HOT 5
- Connect/disconnect in raw-gadget HOT 4
- Assorted raw_gadget.c clean-ups
- Support O_NONBLOCK I/O
- Better support for isochronous transfers
- Support USB 3 SuperSpeed
- device side resume signal HOT 1
- On a Raspberry Pi, follow these instructions. HOT 1
- Unable to compile raw-gadget HOT 1
- USB_RAW_IOCTL_EP_READ/USB_RAW_IOCTL_EP_WRITE maximum length = PAGE_SIZE HOT 4
- Issues compiling on latest PiOS x64 HOT 2
- Building for kernels <4.19 HOT 1
- Inability to compile raw gadget HOT 1
- Contain USB_GADGET_DELAYED_STATUS within composite framework
- Allow stalling non-0-length control OUT transfers
- Support isochronous transfers in Dummy HCD/UDC HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raw-gadget.