* \brief Open CM108 HID port (/dev/hidraw X ). * * \param port The port structure. * * \return File descriptor, otherwise a **negative value** if an error * occurred (in which case, cause is set appropriately). * * \retval -RIG_EINVAL The port pathname is empty or no CM108 device detected. * \retval -RIG_EIO The `open`(2) system call returned a **negative value**. */
| 163 | * \retval -RIG_EIO The `open`(2) system call returned a **negative value**. |
| 164 | */ |
| 165 | int cm108_open(hamlib_port_t *port) |
| 166 | { |
| 167 | int fd; |
| 168 | #ifdef HAVE_LINUX_HIDRAW_H |
| 169 | struct hidraw_devinfo hiddevinfo; |
| 170 | #endif |
| 171 | |
| 172 | rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); |
| 173 | |
| 174 | if (!port->pathname[0]) |
| 175 | { |
| 176 | return -RIG_EINVAL; |
| 177 | } |
| 178 | |
| 179 | fd = open(port->pathname, O_RDWR); |
| 180 | |
| 181 | if (fd < 0) |
| 182 | { |
| 183 | rig_debug(RIG_DEBUG_ERR, |
| 184 | "%s: opening device \"%s\": %s\n", |
| 185 | __func__, |
| 186 | port->pathname, |
| 187 | strerror(errno)); |
| 188 | return -RIG_EIO; |
| 189 | } |
| 190 | |
| 191 | #ifdef HAVE_LINUX_HIDRAW_H |
| 192 | // CM108 detection copied from Thomas Sailer's soundmodem code |
| 193 | rig_debug(RIG_DEBUG_VERBOSE, |
| 194 | "%s: checking for cm108 (or compatible) device\n", |
| 195 | __func__); |
| 196 | |
| 197 | if (!ioctl(fd, HIDIOCGRAWINFO, &hiddevinfo) |
| 198 | && ((hiddevinfo.vendor == 0x0d8c |
| 199 | // CM108/108B/109/119/119A/119B |
| 200 | && ((hiddevinfo.product >= 0x0008 |
| 201 | && hiddevinfo.product <= 0x000f) |
| 202 | || hiddevinfo.product == 0x0012 |
| 203 | || hiddevinfo.product == 0x013a |
| 204 | || hiddevinfo.product == 0x013c |
| 205 | || hiddevinfo.product == 0x0013)) |
| 206 | // SSS1621/23 |
| 207 | || (hiddevinfo.vendor == 0x0c76 |
| 208 | && (hiddevinfo.product == 0x1605 |
| 209 | || hiddevinfo.product == 0x1607 |
| 210 | || hiddevinfo.product == 0x160b)))) |
| 211 | { |
| 212 | rig_debug(RIG_DEBUG_VERBOSE, |
| 213 | "%s: cm108 compatible device detected\n", |
| 214 | __func__); |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | close(fd); |
| 219 | rig_debug(RIG_DEBUG_VERBOSE, |
| 220 | "%s: no cm108 (or compatible) device detected\n", |
| 221 | __func__); |
| 222 | return -RIG_EINVAL; |