kopia lustrzana https://github.com/Hamlib/Hamlib
Fix test of strstr() for Vendor string match.
The sense of the test of strstr() return value was reversed. Corrected so Vendor string match would pass. Tested with FUNcube.Hamlib-1.2.14
rodzic
dfc6db399b
commit
ba5720d1a9
|
@ -70,13 +70,18 @@ static int usbGetStringAscii(usb_dev_handle *udh, int index, int langid, char *b
|
|||
|
||||
rval = usb_control_msg(udh, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
|
||||
(USB_DT_STRING << 8) + index, langid, buffer, sizeof(buffer), 1000);
|
||||
|
||||
if(rval < 0)
|
||||
return rval;
|
||||
|
||||
if(buffer[1] != USB_DT_STRING)
|
||||
return 0;
|
||||
|
||||
if((unsigned char)buffer[0] < rval)
|
||||
rval = (unsigned char)buffer[0];
|
||||
|
||||
rval /= 2;
|
||||
|
||||
/* lossy conversion to ISO Latin1 */
|
||||
for(i=1;i<rval;i++) {
|
||||
if(i > buflen) /* destination buffer overflow */
|
||||
|
@ -85,6 +90,7 @@ static int usbGetStringAscii(usb_dev_handle *udh, int index, int langid, char *b
|
|||
if(buffer[2 * i + 1] != 0) /* outside of ISO Latin1 range */
|
||||
buf[i - 1] = '?';
|
||||
}
|
||||
|
||||
buf[i - 1] = 0;
|
||||
return i - 1;
|
||||
}
|
||||
|
@ -102,22 +108,21 @@ static struct usb_dev_handle *find_and_open_device(const hamlib_port_t *port)
|
|||
char string[256];
|
||||
int len;
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: looking for device %04x:%04x...", __func__,
|
||||
port->parm.usb.vid, port->parm.usb.pid);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: looking for device %04x:%04x...",
|
||||
__func__, port->parm.usb.vid, port->parm.usb.pid);
|
||||
|
||||
for (bus = usb_get_busses(); bus != NULL; bus = bus->next) {
|
||||
|
||||
for (dev = bus->devices; dev != NULL; dev = dev->next) {
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, " %04x:%04x,", dev->descriptor.idVendor,
|
||||
dev->descriptor.idProduct);
|
||||
rig_debug(RIG_DEBUG_VERBOSE, " %04x:%04x,",
|
||||
dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
if (dev->descriptor.idVendor == port->parm.usb.vid &&
|
||||
dev->descriptor.idProduct == port->parm.usb.pid) {
|
||||
|
||||
/* we need to open the device in order to query strings */
|
||||
udh = usb_open(dev);
|
||||
if (!udh) {
|
||||
rig_debug(RIG_DEBUG_WARN, "Warning: cannot open USB device: %s\n", usb_strerror());
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: Warning: Cannot open USB device: %s\n", __func__, usb_strerror());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -129,8 +134,11 @@ static struct usb_dev_handle *find_and_open_device(const hamlib_port_t *port)
|
|||
usb_close(udh);
|
||||
continue;
|
||||
}
|
||||
rig_debug(RIG_DEBUG_TRACE, " vendor >%s<", string);
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, " vendor >%s<", string);
|
||||
|
||||
if (strcmp(string, port->parm.usb.vendor_name) != 0) {
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: Warning: Vendor name string mismatch!\n", __func__);
|
||||
usb_close(udh);
|
||||
continue;
|
||||
}
|
||||
|
@ -143,21 +151,28 @@ static struct usb_dev_handle *find_and_open_device(const hamlib_port_t *port)
|
|||
usb_close(udh);
|
||||
continue;
|
||||
}
|
||||
rig_debug(RIG_DEBUG_TRACE, " product >%s<", string);
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, " product >%s<", string);
|
||||
|
||||
if (strcmp(string, port->parm.usb.product) != 0) {
|
||||
if (strstr(string, port->parm.usb.product) != 0){
|
||||
/* strstr() returns a pointer to the beginning of
|
||||
* port->parm.usb.product on match, and NULL otherwise
|
||||
*/
|
||||
if (strstr(string, port->parm.usb.product) == NULL) {
|
||||
rig_debug(RIG_DEBUG_WARN, "%s: Warning: Product string mismatch!\n", __func__);
|
||||
usb_close(udh);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, " -> found\n");
|
||||
rig_debug(RIG_DEBUG_VERBOSE, " -> found\n");
|
||||
return udh;
|
||||
}
|
||||
}
|
||||
}
|
||||
rig_debug(RIG_DEBUG_TRACE, " -> not found\n");
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, " -> not found\n");
|
||||
return NULL; /* not found */
|
||||
}
|
||||
|
||||
|
@ -217,8 +232,7 @@ int usb_port_open(hamlib_port_t *port)
|
|||
*/
|
||||
char dname[32] = {0};
|
||||
int retval = usb_get_driver_np(udh, port->parm.usb.iface, dname, 31);
|
||||
if (!retval)
|
||||
{
|
||||
if (!retval) {
|
||||
/* Try to detach ftdi_sio kernel module
|
||||
* Returns ENODATA if driver is not loaded.
|
||||
* Don't check return value, let it fail later.
|
||||
|
|
Ładowanie…
Reference in New Issue