⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ul_wdusb.c

📁 linux下的RS485的驱动 值得一看
💻 C
📖 第 1 页 / 共 2 页
字号:
        *buf = new_ptr;    } else if ( new_ptr) {        FREE( new_ptr);    }    FREE(urb);#if DBG_USB    uLan_DbgPrint("uLan: _usb_get_descriptor done with status:0x%X\n",ntStatus);    #endif        return ntStatus;}/** * usb_get_device_descriptor -  * @dev: pointer to the usb device * * Return Value: NTSTATUS */   NTSTATUSusb_get_device_descriptor(IN usb_device *dev) {    NTSTATUS ntStatus;        /* deviceDescriptor */    if (dev->descriptor)        FREE(dev->descriptor);    dev->descriptor=NULL;        ntStatus = _usb_get_descriptor(dev,                           USB_DEVICE_DESCRIPTOR_TYPE,                           0,                           &dev->descriptor,                           sizeof(USB_DEVICE_DESCRIPTOR));#if DBG_USB    uLan_DbgPrint("uLan: usb_device_descriptor done with status:0x%X\n",ntStatus);    #endif        return ntStatus;}/** * usb_get_configuration -  * @dev: pointer to the usb device * * Return Value: NTSTATUS */   NTSTATUSusb_get_configuration(IN usb_device *dev) {    NTSTATUS ntStatus;    char cfgno;    #if DBG_USB    uLan_DbgPrint("uLan: usb_get_configuration\n");#endif        if ((!dev) || (!dev->descriptor))        return STATUS_INVALID_PARAMETER;        if (dev->descriptor->bNumConfigurations < 1) {        return STATUS_INVALID_PARAMETER;    }           dev->rawdescriptors = (char **)MALLOC(sizeof(char *) *        dev->descriptor->bNumConfigurations);    if (!dev->rawdescriptors) {        return STATUS_INSUFFICIENT_RESOURCES;    }     /* read all configurations */    for (cfgno = 0; cfgno < dev->descriptor->bNumConfigurations; cfgno++) {             dev->rawdescriptors[cfgno]=NULL;        ntStatus = _usb_get_descriptor(dev,                              USB_CONFIGURATION_DESCRIPTOR_TYPE,                              cfgno,                              &dev->rawdescriptors[cfgno],                              -1);        if ( !NT_SUCCESS(ntStatus)) break;     }#if DBG_USB    uLan_DbgPrint("uLan: usb_get_configuration (num. cfg.:%d)\n",                  dev->descriptor->bNumConfigurations);    uLan_DbgPrint("uLan: usb_get_configuration done with status:0x%X\n",ntStatus);    #endif        return ntStatus;}/** * usb_set_configuration -  * @dev: pointer to the usb device * @configuration: number of configuration * * Return Value: NTSTATUS */   NTSTATUSusb_set_configuration(IN usb_device *dev,IN int configuration) {    PUSBD_INTERFACE_LIST_ENTRY ifc_list = NULL, ifc_tmp = NULL;    PUSB_INTERFACE_DESCRIPTOR ifc_desc = NULL;    PUSB_CONFIGURATION_DESCRIPTOR cp=NULL;     NTSTATUS ntStatus = STATUS_SUCCESS;    PURB urb = NULL;    int i;#if DBG_USB    uLan_DbgPrint("uLan: usb_set_configuration (%d)\n",configuration);#endif        /* if device has no device descriptor, dump it */    if (!dev->descriptor) {      ntStatus=usb_get_device_descriptor(dev);      if ( !NT_SUCCESS( ntStatus)) {          uLan_DbgPrint("uLan: error in usb_get_device_descriptor\n");          return ntStatus;      }    }    /* if device has no configuration informations, dump it */    if (dev->rawdescriptors==NULL) {      ntStatus = usb_get_configuration(dev);      if ( !NT_SUCCESS( ntStatus)) {          uLan_DbgPrint("uLan: error in usb_get_configuration\n");          return ntStatus;      }    }    for (i=0; i<dev->descriptor->bNumConfigurations; i++) {      PUSB_CONFIGURATION_DESCRIPTOR c =               (PUSB_CONFIGURATION_DESCRIPTOR)dev->rawdescriptors[i];        if (c->bConfigurationValue == configuration) {            cp = c;            break;        }    }    if (!cp) {      return STATUS_INVALID_PARAMETER;    }    ifc_tmp = ifc_list =         MALLOC(sizeof( struct _USBD_INTERFACE_LIST_ENTRY) * ( cp->bNumInterfaces+1));    if ( !ifc_tmp) {      return STATUS_INSUFFICIENT_RESOURCES;    }    for( i = 0; i < cp->bNumInterfaces; i++) {        ifc_desc = USBD_ParseConfigurationDescriptorEx( cp, cp, i, -1, -1, -1, -1);#if DBG_USB        uLan_DbgPrint("uLan: next Ifc on 0x%X\n", ifc_desc);#endif            ifc_list->InterfaceDescriptor = ifc_desc;        ifc_list++;    }    ifc_list->InterfaceDescriptor = NULL;    ifc_list = ifc_tmp;    /* create select configuration urb */    urb = USBD_CreateConfigurationRequestEx( cp, ifc_tmp);    if( !urb) {        uLan_DbgPrint("uLan: create config request\n");        ntStatus = STATUS_INSUFFICIENT_RESOURCES;    }    /* Send select configure urb to usb device */    if ( NT_SUCCESS(ntStatus)) {        ntStatus = _usb_submit_urb( dev, urb, NULL, NULL, NULL, NULL);        if( !NT_SUCCESS( ntStatus)) {#if DBG_USB            uLan_DbgPrint("uLan: send select configuration request (0x%X)\n", ntStatus);#endif            } else {            dev->cfghandle = urb->UrbSelectConfiguration.ConfigurationHandle;            /* for selected interface make copy */            dev->interfaces.InterfaceDescriptor = ifc_tmp->InterfaceDescriptor;            dev->interfaces.Interface = MALLOC( ifc_tmp->Interface->Length);            if ( !dev->interfaces.Interface) {               uLan_DbgPrint("uLan: no memory for usb.interfaces\n", ntStatus);               ntStatus = STATUS_INSUFFICIENT_RESOURCES;            } else {               RtlCopyMemory( dev->interfaces.Interface,                               ifc_tmp->Interface,                               ifc_tmp->Interface->Length);            }        }    }    if ( urb)         ExFreePool(urb);    if ( ifc_list)         FREE( ifc_list);    dev->actconfig = cp;#if DBG_USB    uLan_DbgPrint("uLan: usb_set_configuration done with status:0x%X\n",ntStatus);            #endif        return ntStatus;} /** * usb_reset_configuration -  * @dev: pointer to the usb device * * Return Value: NTSTATUS */   NTSTATUSusb_reset_configuration(IN usb_device *dev) {    NTSTATUS ntStatus = STATUS_SUCCESS;    PURB urb = NULL;#if DBG_USB    uLan_DbgPrint("uLan: usb_reset_configuration \n");#endif        urb = MALLOC(sizeof( struct _URB_SELECT_CONFIGURATION));    if ( !urb) {        uLan_DbgPrint("uLan: no memory for URB\n");        return STATUS_INSUFFICIENT_RESOURCES;    }    UsbBuildSelectConfigurationRequest( urb, sizeof( struct _URB_SELECT_CONFIGURATION), NULL);    ntStatus = _usb_submit_urb( dev, urb, NULL, NULL, NULL, NULL);    if( !NT_SUCCESS( ntStatus)) {        uLan_DbgPrint("uLan: error select configurations request (0x%X)\n",ntStatus);    }    FREE( urb);#if DBG_USB    uLan_DbgPrint("uLan: usb_reset_configuration done with status:0x%X\n",ntStatus);    #endif        return ntStatus;  }/** * usb_clear_halt -  * @dev: pointer to the usb device * @pipe: * * Return Value: NTSTATUS */   NTSTATUSusb_clear_halt(IN usb_device *dev,IN int pipe){    PUSBD_PIPE_INFORMATION pipe_info=NULL;    PUSBD_INTERFACE_INFORMATION interface;    NTSTATUS ntStatus = STATUS_SUCCESS;    ULONG endpoint;    PURB urb;    unsigned int j;    /* get handle of pipe */    endpoint=usb_pipeendpoint(pipe) | (pipe & USB_DIR_IN);#if DBG_USB    uLan_DbgPrint("uLan: usb_clear_halt selected endpoint=0x%X\n",endpoint);#endif        interface=dev->interfaces.Interface;    if ( !interface) {       return STATUS_INVALID_PARAMETER;    }    /* trace all pipes */    for (j=0; j<interface->NumberOfPipes; j++) {        pipe_info=&interface->Pipes[j];        if (pipe_info->EndpointAddress==endpoint) break;        pipe_info=NULL;    }    if (!pipe_info) {        return STATUS_INVALID_PARAMETER;    }        /* usb_show_endpoint_information(pipe_info); */    urb = MALLOC( sizeof( struct _URB_PIPE_REQUEST));    if ( urb) {        urb->UrbHeader.Length = (USHORT) sizeof( struct _URB_PIPE_REQUEST);        urb->UrbHeader.Function = URB_FUNCTION_RESET_PIPE;        urb->UrbPipeRequest.PipeHandle = pipe_info->PipeHandle;        ntStatus = _usb_submit_urb( dev, urb, NULL, NULL, NULL, NULL);        FREE( urb);    } else {        ntStatus = STATUS_INSUFFICIENT_RESOURCES;    }#if DBG_USB    uLan_DbgPrint("uLan: usb_clear_halt done with status:0x%X\n",ntStatus);    #endif    return ntStatus;}/** * usb_show_device_descriptor - dump a device descriptor * deviceDescriptor@: pointer to the deviceDescriptor */   voidusb_show_device_descriptor(IN PUSB_DEVICE_DESCRIPTOR deviceDescriptor) {    if ( !deviceDescriptor ) return;    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("Device Descriptor:\n");    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("bLength %d\n", deviceDescriptor->bLength);    uLan_DbgPrint("bDescriptorType 0x%x\n", deviceDescriptor->bDescriptorType);    uLan_DbgPrint("bcdUSB 0x%x\n", deviceDescriptor->bcdUSB);    uLan_DbgPrint("bDeviceClass 0x%x\n", deviceDescriptor->bDeviceClass);    uLan_DbgPrint("bDeviceSubClass 0x%x\n", deviceDescriptor->bDeviceSubClass);    uLan_DbgPrint("bDeviceProtocol 0x%x\n", deviceDescriptor->bDeviceProtocol);    uLan_DbgPrint("bMaxPacketSize0 0x%x\n", deviceDescriptor->bMaxPacketSize0);    uLan_DbgPrint("idVendor 0x%x\n", deviceDescriptor->idVendor);    uLan_DbgPrint("idProduct 0x%x\n", deviceDescriptor->idProduct);    uLan_DbgPrint("bcdDevice 0x%x\n", deviceDescriptor->bcdDevice);    uLan_DbgPrint("iManufacturer 0x%x\n", deviceDescriptor->iManufacturer);    uLan_DbgPrint("iProduct 0x%x\n", deviceDescriptor->iProduct);    uLan_DbgPrint("iSerialNumber 0x%x\n", deviceDescriptor->iSerialNumber);    uLan_DbgPrint("bNumConfigurations 0x%x\n", deviceDescriptor->bNumConfigurations);}/** * usb_show_config_descriptor - dump a configuration descriptor * @configurationDescriptor: pointer to the configurationDescriptor */   voidusb_show_config_descriptor(IN PUSB_CONFIGURATION_DESCRIPTOR configurationDescriptor) {    if ( !configurationDescriptor ) return;    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("Configuration Descriptor:\n");    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("bLength %d\n", configurationDescriptor->bLength);    uLan_DbgPrint("bDescriptorType 0x%x\n", configurationDescriptor->bDescriptorType);    uLan_DbgPrint("wTotalLength 0x%x\n", configurationDescriptor->wTotalLength);    uLan_DbgPrint("bNumInterfaces 0x%x\n", configurationDescriptor->bNumInterfaces);    uLan_DbgPrint("bConfigurationValue 0x%x\n", configurationDescriptor->bConfigurationValue);    uLan_DbgPrint("iConfiguration 0x%x\n", configurationDescriptor->iConfiguration);    uLan_DbgPrint("bmAttributes 0x%x\n", configurationDescriptor->bmAttributes);    uLan_DbgPrint("MaxPower 0x%x\n", configurationDescriptor->MaxPower);}/** * usb_show_interface_information - dump a interface information * @interface: pointer to the interface */   void usb_show_interface_information(IN PUSBD_INTERFACE_INFORMATION interface) {    if ( !interface ) return;    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("Interface Information:\n");    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("NumberOfPipes 0x%x\n", interface->NumberOfPipes);    uLan_DbgPrint("Length 0x%x\n", interface->Length);    uLan_DbgPrint("Alt Setting 0x%x\n", interface->AlternateSetting);    uLan_DbgPrint("Interface Number 0x%x\n", interface->InterfaceNumber);    uLan_DbgPrint("Class, subclass, protocol 0x%x 0x%x 0x%x\n",                  interface->Class,                  interface->SubClass,                  interface->Protocol);}/** * usb_show_endpoint_information - dump a endpoint information * @pipe: pointer to the pipe */   void usb_show_endpoint_information(IN PUSBD_PIPE_INFORMATION pipe) {    if ( !pipe ) return;    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("Pipe Information:\n");    uLan_DbgPrint("-------------------------\n");    uLan_DbgPrint("PipeType 0x%x\n", pipe->PipeType);    uLan_DbgPrint("EndpointAddress 0x%x\n", pipe->EndpointAddress);    uLan_DbgPrint("MaxPacketSize 0x%x\n", pipe->MaximumPacketSize);    uLan_DbgPrint("Interval 0x%x\n", pipe->Interval);    uLan_DbgPrint("Handle 0x%x\n", pipe->PipeHandle);    uLan_DbgPrint("MaximumTransferSize 0x%x\n", pipe->MaximumTransferSize);}/** * usb_show_device - dump a usb device informations * @dev: pointer to the usb device */   void usb_show_device(usb_device *dev) {    PUSBD_INTERFACE_INFORMATION interface;    unsigned int j;        if ( !dev ) return;    /* device descriptor */    usb_show_device_descriptor(dev->descriptor);        /* selected configuration */    if ( !dev->descriptor) return;    usb_show_config_descriptor(dev->cfghandle);        /* interfaces */    interface=dev->interfaces.Interface;    if ( !interface) return;    usb_show_interface_information(interface);    /* pipes */    for (j=0; j<interface->NumberOfPipes; j++) {        usb_show_endpoint_information(&interface->Pipes[j]);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -