| 1815 | } |
| 1816 | |
| 1817 | SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboolean *fpga_done) |
| 1818 | { |
| 1819 | struct sr_usb_dev_inst *usb; |
| 1820 | struct DSL_context *devc; |
| 1821 | int ret; |
| 1822 | uint8_t hw_info; |
| 1823 | struct ctl_rd_cmd rd_cmd; |
| 1824 | int fdError = 0; |
| 1825 | |
| 1826 | devc = sdi->priv; |
| 1827 | usb = sdi->conn; |
| 1828 | |
| 1829 | /* |
| 1830 | * If the firmware was recently uploaded, no dev_open operation should be called. |
| 1831 | * Just wait for renumerate -> detach -> attach |
| 1832 | */ |
| 1833 | ret = SR_ERR; |
| 1834 | ret = hw_dev_open(di, sdi); |
| 1835 | |
| 1836 | if (ret != SR_OK) { |
| 1837 | sr_err("%s: Unable to open device.", __func__); |
| 1838 | return SR_ERR; |
| 1839 | } |
| 1840 | |
| 1841 | assert(usb->devhdl); |
| 1842 | |
| 1843 | ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); |
| 1844 | |
| 1845 | if (ret != LIBUSB_SUCCESS) { |
| 1846 | switch(ret) { |
| 1847 | case LIBUSB_ERROR_BUSY: |
| 1848 | sr_err("%s: Unable to claim USB interface. Another " |
| 1849 | "program or driver has already claimed it.", __func__); |
| 1850 | break; |
| 1851 | case LIBUSB_ERROR_NO_DEVICE: |
| 1852 | sr_err("%s: Device has been disconnected.", __func__); |
| 1853 | break; |
| 1854 | case LIBUSB_ERROR_NOT_FOUND: |
| 1855 | { |
| 1856 | sr_err("%s: Unable to claim interface, try again: LIBUSB_ERROR_NOT_FOUND.", __func__); |
| 1857 | ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE); |
| 1858 | fdError = 1; |
| 1859 | } |
| 1860 | break; |
| 1861 | default: |
| 1862 | sr_err("%s: Unable to claim interface, try again: %s.", |
| 1863 | __func__, libusb_error_name(ret)); |
| 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | if (ret != LIBUSB_SUCCESS && fdError == 1){ |
| 1868 | sr_err("%s: Unable to claim interface, the second time: %s.", |
| 1869 | __func__, libusb_error_name(ret)); |
| 1870 | } |
| 1871 | |
| 1872 | if (ret != LIBUSB_SUCCESS){ |
| 1873 | dsl_dev_close(sdi); |
| 1874 | ds_set_last_error(SR_ERR_DEVICE_IS_EXCLUSIVE); |
no test coverage detected