Implemented ioctl USB_PRINTER_GET_DEVICE_ID. Using my printer it always
times out, though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33531 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -47,6 +47,7 @@ static mutex gDeviceListLock;
|
||||
static char **gDeviceNames = NULL;
|
||||
|
||||
|
||||
|
||||
//
|
||||
//#pragma mark - Forward Declarations
|
||||
//
|
||||
@@ -146,8 +147,7 @@ usb_printer_device_added(usb_device newDevice, void **cookie)
|
||||
device->removed = false;
|
||||
device->open_count = 0;
|
||||
device->interface = 0xff;
|
||||
device->current_tag = 0;
|
||||
device->block_size = 4096;
|
||||
device->alternate_setting = 0;
|
||||
|
||||
// scan through the interfaces to find our bulk-only data interface
|
||||
const usb_configuration_info *configuration = gUSBModule->get_configuration(newDevice);
|
||||
@@ -193,6 +193,8 @@ usb_printer_device_added(usb_device newDevice, void **cookie)
|
||||
continue;
|
||||
|
||||
device->interface = interface->descr->interface_number;
|
||||
device->alternate_setting = interface->descr->alternate_setting;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -345,6 +347,35 @@ usb_printer_free(void *cookie)
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
usb_printer_get_device_id(printer_device *device, void *buffer)
|
||||
{
|
||||
uint16 value = 0;
|
||||
uint16 index = (device->interface << 8) | device->alternate_setting;
|
||||
char device_id[USB_PRINTER_DEVICE_ID_LENGTH + 2];
|
||||
size_t device_id_size = 0;
|
||||
status_t st = gUSBModule->send_request(device->device, PRINTER_REQUEST,
|
||||
REQUEST_GET_DEVICE_ID, value, index,
|
||||
sizeof(device_id), device_id, &device_id_size);
|
||||
|
||||
if (st == B_OK && device_id_size > 2) {
|
||||
// terminate string
|
||||
device_id[device_id_size - 1] = '\0';
|
||||
// skip first two bytes containing string length again
|
||||
st = user_strlcpy((char *)buffer, &device_id[2], USB_PRINTER_DEVICE_ID_LENGTH);
|
||||
} else {
|
||||
dprintf("%s: Failed to get device ID for interface %d and alternate setting %d: %s\n",
|
||||
DRIVER_NAME,
|
||||
(int)device->interface,
|
||||
(int)device->alternate_setting,
|
||||
strerror(st));
|
||||
st = user_strlcpy((char *)buffer,
|
||||
"MFG:Unknown;CMD:Unknown;MDL:Unknown;", USB_PRINTER_DEVICE_ID_LENGTH);
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
usb_printer_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
{
|
||||
@@ -358,9 +389,7 @@ usb_printer_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
|
||||
status_t result = B_DEV_INVALID_IOCTL;
|
||||
switch (op) {
|
||||
case USB_PRINTER_GET_DEVICE_ID: {
|
||||
// TODO implement
|
||||
strncpy((char*)buffer, "Not implemented", length);
|
||||
result = B_OK;
|
||||
result = usb_printer_get_device_id(device, buffer);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -404,6 +433,7 @@ usb_printer_transfer(printer_device* device, bool directionIn, void* buffer, siz
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
usb_printer_read(void *cookie, off_t position, void *buffer, size_t *length)
|
||||
{
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
// class specific requests
|
||||
// bmRequestType
|
||||
#define PRINTER_REQUEST 0xA1
|
||||
#define PRINTER_REQUEST (USB_REQTYPE_INTERFACE_IN | USB_REQTYPE_CLASS)
|
||||
// bRequest
|
||||
#define REQUEST_GET_STATUS_ID 0x00
|
||||
#define REQUEST_GET_DEVICE_ID 0x00
|
||||
#define REQUEST_GET_PORT_STATUS 0x01
|
||||
#define REQUEST_SOFT_RESET 0x02
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct printer_device_s {
|
||||
usb_pipe bulk_in;
|
||||
usb_pipe bulk_out;
|
||||
uint8 interface;
|
||||
uint32 current_tag;
|
||||
uint8 alternate_setting;
|
||||
|
||||
// used to store callback information
|
||||
sem_id notify;
|
||||
@@ -52,7 +52,6 @@ typedef struct printer_device_s {
|
||||
size_t actual_length;
|
||||
|
||||
char name[32];
|
||||
uint32 block_size;
|
||||
} printer_device;
|
||||
|
||||
#endif // _USB_PRINTER_H_
|
||||
|
||||
Reference in New Issue
Block a user