f_hid.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * f_hid.c -- USB HID function driver
  3. *
  4. * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/utsname.h>
  22. #include <linux/module.h>
  23. #include <linux/hid.h>
  24. #include <linux/cdev.h>
  25. #include <linux/mutex.h>
  26. #include <linux/poll.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/wait.h>
  29. #include <linux/usb/g_hid.h>
  30. static int major, minors;
  31. static struct class *hidg_class;
  32. /*-------------------------------------------------------------------------*/
  33. /* HID gadget struct */
  34. struct f_hidg {
  35. /* configuration */
  36. unsigned char bInterfaceSubClass;
  37. unsigned char bInterfaceProtocol;
  38. unsigned short report_desc_length;
  39. char *report_desc;
  40. unsigned short report_length;
  41. /* recv report */
  42. char *set_report_buff;
  43. unsigned short set_report_length;
  44. spinlock_t spinlock;
  45. wait_queue_head_t read_queue;
  46. /* send report */
  47. struct mutex lock;
  48. bool write_pending;
  49. wait_queue_head_t write_queue;
  50. struct usb_request *req;
  51. int minor;
  52. struct cdev cdev;
  53. struct usb_function func;
  54. struct usb_ep *in_ep;
  55. };
  56. static inline struct f_hidg *func_to_hidg(struct usb_function *f)
  57. {
  58. return container_of(f, struct f_hidg, func);
  59. }
  60. /*-------------------------------------------------------------------------*/
  61. /* Static descriptors */
  62. static struct usb_interface_descriptor hidg_interface_desc = {
  63. .bLength = sizeof hidg_interface_desc,
  64. .bDescriptorType = USB_DT_INTERFACE,
  65. /* .bInterfaceNumber = DYNAMIC */
  66. .bAlternateSetting = 0,
  67. .bNumEndpoints = 1,
  68. .bInterfaceClass = USB_CLASS_HID,
  69. /* .bInterfaceSubClass = DYNAMIC */
  70. /* .bInterfaceProtocol = DYNAMIC */
  71. /* .iInterface = DYNAMIC */
  72. };
  73. static struct hid_descriptor hidg_desc = {
  74. .bLength = sizeof hidg_desc,
  75. .bDescriptorType = HID_DT_HID,
  76. .bcdHID = 0x0101,
  77. .bCountryCode = 0x00,
  78. .bNumDescriptors = 0x1,
  79. /*.desc[0].bDescriptorType = DYNAMIC */
  80. /*.desc[0].wDescriptorLenght = DYNAMIC */
  81. };
  82. /* High-Speed Support */
  83. static struct usb_endpoint_descriptor hidg_hs_in_ep_desc = {
  84. .bLength = USB_DT_ENDPOINT_SIZE,
  85. .bDescriptorType = USB_DT_ENDPOINT,
  86. .bEndpointAddress = USB_DIR_IN,
  87. .bmAttributes = USB_ENDPOINT_XFER_INT,
  88. /*.wMaxPacketSize = DYNAMIC */
  89. .bInterval = 4, /* FIXME: Add this field in the
  90. * HID gadget configuration?
  91. * (struct hidg_func_descriptor)
  92. */
  93. };
  94. static struct usb_descriptor_header *hidg_hs_descriptors[] = {
  95. (struct usb_descriptor_header *)&hidg_interface_desc,
  96. (struct usb_descriptor_header *)&hidg_desc,
  97. (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
  98. NULL,
  99. };
  100. /* Full-Speed Support */
  101. static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
  102. .bLength = USB_DT_ENDPOINT_SIZE,
  103. .bDescriptorType = USB_DT_ENDPOINT,
  104. .bEndpointAddress = USB_DIR_IN,
  105. .bmAttributes = USB_ENDPOINT_XFER_INT,
  106. /*.wMaxPacketSize = DYNAMIC */
  107. .bInterval = 10, /* FIXME: Add this field in the
  108. * HID gadget configuration?
  109. * (struct hidg_func_descriptor)
  110. */
  111. };
  112. static struct usb_descriptor_header *hidg_fs_descriptors[] = {
  113. (struct usb_descriptor_header *)&hidg_interface_desc,
  114. (struct usb_descriptor_header *)&hidg_desc,
  115. (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
  116. NULL,
  117. };
  118. /*-------------------------------------------------------------------------*/
  119. /* Char Device */
  120. static ssize_t f_hidg_read(struct file *file, char __user *buffer,
  121. size_t count, loff_t *ptr)
  122. {
  123. struct f_hidg *hidg = file->private_data;
  124. char *tmp_buff = NULL;
  125. unsigned long flags;
  126. if (!count)
  127. return 0;
  128. if (!access_ok(VERIFY_WRITE, buffer, count))
  129. return -EFAULT;
  130. spin_lock_irqsave(&hidg->spinlock, flags);
  131. #define READ_COND (hidg->set_report_buff != NULL)
  132. while (!READ_COND) {
  133. spin_unlock_irqrestore(&hidg->spinlock, flags);
  134. if (file->f_flags & O_NONBLOCK)
  135. return -EAGAIN;
  136. if (wait_event_interruptible(hidg->read_queue, READ_COND))
  137. return -ERESTARTSYS;
  138. spin_lock_irqsave(&hidg->spinlock, flags);
  139. }
  140. count = min_t(unsigned, count, hidg->set_report_length);
  141. tmp_buff = hidg->set_report_buff;
  142. hidg->set_report_buff = NULL;
  143. spin_unlock_irqrestore(&hidg->spinlock, flags);
  144. if (tmp_buff != NULL) {
  145. /* copy to user outside spinlock */
  146. count -= copy_to_user(buffer, tmp_buff, count);
  147. kfree(tmp_buff);
  148. } else
  149. count = -ENOMEM;
  150. return count;
  151. }
  152. static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
  153. {
  154. struct f_hidg *hidg = (struct f_hidg *)ep->driver_data;
  155. if (req->status != 0) {
  156. ERROR(hidg->func.config->cdev,
  157. "End Point Request ERROR: %d\n", req->status);
  158. }
  159. hidg->write_pending = 0;
  160. wake_up(&hidg->write_queue);
  161. }
  162. static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
  163. size_t count, loff_t *offp)
  164. {
  165. struct f_hidg *hidg = file->private_data;
  166. ssize_t status = -ENOMEM;
  167. if (!access_ok(VERIFY_READ, buffer, count))
  168. return -EFAULT;
  169. mutex_lock(&hidg->lock);
  170. #define WRITE_COND (!hidg->write_pending)
  171. /* write queue */
  172. while (!WRITE_COND) {
  173. mutex_unlock(&hidg->lock);
  174. if (file->f_flags & O_NONBLOCK)
  175. return -EAGAIN;
  176. if (wait_event_interruptible_exclusive(
  177. hidg->write_queue, WRITE_COND))
  178. return -ERESTARTSYS;
  179. mutex_lock(&hidg->lock);
  180. }
  181. count = min_t(unsigned, count, hidg->report_length);
  182. status = copy_from_user(hidg->req->buf, buffer, count);
  183. if (status != 0) {
  184. ERROR(hidg->func.config->cdev,
  185. "copy_from_user error\n");
  186. mutex_unlock(&hidg->lock);
  187. return -EINVAL;
  188. }
  189. hidg->req->status = 0;
  190. hidg->req->zero = 0;
  191. hidg->req->length = count;
  192. hidg->req->complete = f_hidg_req_complete;
  193. hidg->req->context = hidg;
  194. hidg->write_pending = 1;
  195. status = usb_ep_queue(hidg->in_ep, hidg->req, GFP_ATOMIC);
  196. if (status < 0) {
  197. ERROR(hidg->func.config->cdev,
  198. "usb_ep_queue error on int endpoint %zd\n", status);
  199. hidg->write_pending = 0;
  200. wake_up(&hidg->write_queue);
  201. } else {
  202. status = count;
  203. }
  204. mutex_unlock(&hidg->lock);
  205. return status;
  206. }
  207. static unsigned int f_hidg_poll(struct file *file, poll_table *wait)
  208. {
  209. struct f_hidg *hidg = file->private_data;
  210. unsigned int ret = 0;
  211. poll_wait(file, &hidg->read_queue, wait);
  212. poll_wait(file, &hidg->write_queue, wait);
  213. if (WRITE_COND)
  214. ret |= POLLOUT | POLLWRNORM;
  215. if (READ_COND)
  216. ret |= POLLIN | POLLRDNORM;
  217. return ret;
  218. }
  219. #undef WRITE_COND
  220. #undef READ_COND
  221. static int f_hidg_release(struct inode *inode, struct file *fd)
  222. {
  223. fd->private_data = NULL;
  224. return 0;
  225. }
  226. static int f_hidg_open(struct inode *inode, struct file *fd)
  227. {
  228. struct f_hidg *hidg =
  229. container_of(inode->i_cdev, struct f_hidg, cdev);
  230. fd->private_data = hidg;
  231. return 0;
  232. }
  233. /*-------------------------------------------------------------------------*/
  234. /* usb_function */
  235. static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
  236. {
  237. struct f_hidg *hidg = (struct f_hidg *)req->context;
  238. if (req->status != 0 || req->buf == NULL || req->actual == 0) {
  239. ERROR(hidg->func.config->cdev, "%s FAILED\n", __func__);
  240. return;
  241. }
  242. spin_lock(&hidg->spinlock);
  243. hidg->set_report_buff = krealloc(hidg->set_report_buff,
  244. req->actual, GFP_ATOMIC);
  245. if (hidg->set_report_buff == NULL) {
  246. spin_unlock(&hidg->spinlock);
  247. return;
  248. }
  249. hidg->set_report_length = req->actual;
  250. memcpy(hidg->set_report_buff, req->buf, req->actual);
  251. spin_unlock(&hidg->spinlock);
  252. wake_up(&hidg->read_queue);
  253. }
  254. static int hidg_setup(struct usb_function *f,
  255. const struct usb_ctrlrequest *ctrl)
  256. {
  257. struct f_hidg *hidg = func_to_hidg(f);
  258. struct usb_composite_dev *cdev = f->config->cdev;
  259. struct usb_request *req = cdev->req;
  260. int status = 0;
  261. __u16 value, length;
  262. value = __le16_to_cpu(ctrl->wValue);
  263. length = __le16_to_cpu(ctrl->wLength);
  264. VDBG(cdev, "hid_setup crtl_request : bRequestType:0x%x bRequest:0x%x "
  265. "Value:0x%x\n", ctrl->bRequestType, ctrl->bRequest, value);
  266. switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
  267. case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
  268. | HID_REQ_GET_REPORT):
  269. VDBG(cdev, "get_report\n");
  270. /* send an empty report */
  271. length = min_t(unsigned, length, hidg->report_length);
  272. memset(req->buf, 0x0, length);
  273. goto respond;
  274. break;
  275. case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
  276. | HID_REQ_GET_PROTOCOL):
  277. VDBG(cdev, "get_protocol\n");
  278. goto stall;
  279. break;
  280. case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
  281. | HID_REQ_SET_REPORT):
  282. VDBG(cdev, "set_report | wLenght=%d\n", ctrl->wLength);
  283. req->context = hidg;
  284. req->complete = hidg_set_report_complete;
  285. goto respond;
  286. break;
  287. case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
  288. | HID_REQ_SET_PROTOCOL):
  289. VDBG(cdev, "set_protocol\n");
  290. goto stall;
  291. break;
  292. case ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8
  293. | USB_REQ_GET_DESCRIPTOR):
  294. switch (value >> 8) {
  295. case HID_DT_REPORT:
  296. VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n");
  297. length = min_t(unsigned short, length,
  298. hidg->report_desc_length);
  299. memcpy(req->buf, hidg->report_desc, length);
  300. goto respond;
  301. break;
  302. default:
  303. VDBG(cdev, "Unknown decriptor request 0x%x\n",
  304. value >> 8);
  305. goto stall;
  306. break;
  307. }
  308. break;
  309. default:
  310. VDBG(cdev, "Unknown request 0x%x\n",
  311. ctrl->bRequest);
  312. goto stall;
  313. break;
  314. }
  315. stall:
  316. return -EOPNOTSUPP;
  317. respond:
  318. req->zero = 0;
  319. req->length = length;
  320. status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
  321. if (status < 0)
  322. ERROR(cdev, "usb_ep_queue error on ep0 %d\n", value);
  323. return status;
  324. }
  325. static void hidg_disable(struct usb_function *f)
  326. {
  327. struct f_hidg *hidg = func_to_hidg(f);
  328. usb_ep_disable(hidg->in_ep);
  329. hidg->in_ep->driver_data = NULL;
  330. }
  331. static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
  332. {
  333. struct usb_composite_dev *cdev = f->config->cdev;
  334. struct f_hidg *hidg = func_to_hidg(f);
  335. int status = 0;
  336. VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
  337. if (hidg->in_ep != NULL) {
  338. /* restart endpoint */
  339. if (hidg->in_ep->driver_data != NULL)
  340. usb_ep_disable(hidg->in_ep);
  341. status = config_ep_by_speed(f->config->cdev->gadget, f,
  342. hidg->in_ep);
  343. if (status) {
  344. ERROR(cdev, "config_ep_by_speed FAILED!\n");
  345. goto fail;
  346. }
  347. status = usb_ep_enable(hidg->in_ep);
  348. if (status < 0) {
  349. ERROR(cdev, "Enable endpoint FAILED!\n");
  350. goto fail;
  351. }
  352. hidg->in_ep->driver_data = hidg;
  353. }
  354. fail:
  355. return status;
  356. }
  357. const struct file_operations f_hidg_fops = {
  358. .owner = THIS_MODULE,
  359. .open = f_hidg_open,
  360. .release = f_hidg_release,
  361. .write = f_hidg_write,
  362. .read = f_hidg_read,
  363. .poll = f_hidg_poll,
  364. .llseek = noop_llseek,
  365. };
  366. static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
  367. {
  368. struct usb_ep *ep;
  369. struct f_hidg *hidg = func_to_hidg(f);
  370. int status;
  371. dev_t dev;
  372. /* allocate instance-specific interface IDs, and patch descriptors */
  373. status = usb_interface_id(c, f);
  374. if (status < 0)
  375. goto fail;
  376. hidg_interface_desc.bInterfaceNumber = status;
  377. /* allocate instance-specific endpoints */
  378. status = -ENODEV;
  379. ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_in_ep_desc);
  380. if (!ep)
  381. goto fail;
  382. ep->driver_data = c->cdev; /* claim */
  383. hidg->in_ep = ep;
  384. /* preallocate request and buffer */
  385. status = -ENOMEM;
  386. hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
  387. if (!hidg->req)
  388. goto fail;
  389. hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
  390. if (!hidg->req->buf)
  391. goto fail;
  392. /* set descriptor dynamic values */
  393. hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
  394. hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
  395. hidg_hs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
  396. hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
  397. hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT;
  398. hidg_desc.desc[0].wDescriptorLength =
  399. cpu_to_le16(hidg->report_desc_length);
  400. hidg->set_report_buff = NULL;
  401. /* copy descriptors */
  402. f->descriptors = usb_copy_descriptors(hidg_fs_descriptors);
  403. if (!f->descriptors)
  404. goto fail;
  405. if (gadget_is_dualspeed(c->cdev->gadget)) {
  406. hidg_hs_in_ep_desc.bEndpointAddress =
  407. hidg_fs_in_ep_desc.bEndpointAddress;
  408. f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors);
  409. if (!f->hs_descriptors)
  410. goto fail;
  411. }
  412. mutex_init(&hidg->lock);
  413. spin_lock_init(&hidg->spinlock);
  414. init_waitqueue_head(&hidg->write_queue);
  415. init_waitqueue_head(&hidg->read_queue);
  416. /* create char device */
  417. cdev_init(&hidg->cdev, &f_hidg_fops);
  418. dev = MKDEV(major, hidg->minor);
  419. status = cdev_add(&hidg->cdev, dev, 1);
  420. if (status)
  421. goto fail;
  422. device_create(hidg_class, NULL, dev, NULL, "%s%d", "hidg", hidg->minor);
  423. return 0;
  424. fail:
  425. ERROR(f->config->cdev, "hidg_bind FAILED\n");
  426. if (hidg->req != NULL) {
  427. kfree(hidg->req->buf);
  428. if (hidg->in_ep != NULL)
  429. usb_ep_free_request(hidg->in_ep, hidg->req);
  430. }
  431. usb_free_descriptors(f->hs_descriptors);
  432. usb_free_descriptors(f->descriptors);
  433. return status;
  434. }
  435. static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
  436. {
  437. struct f_hidg *hidg = func_to_hidg(f);
  438. device_destroy(hidg_class, MKDEV(major, hidg->minor));
  439. cdev_del(&hidg->cdev);
  440. /* disable/free request and end point */
  441. usb_ep_disable(hidg->in_ep);
  442. usb_ep_dequeue(hidg->in_ep, hidg->req);
  443. kfree(hidg->req->buf);
  444. usb_ep_free_request(hidg->in_ep, hidg->req);
  445. /* free descriptors copies */
  446. usb_free_descriptors(f->hs_descriptors);
  447. usb_free_descriptors(f->descriptors);
  448. kfree(hidg->report_desc);
  449. kfree(hidg->set_report_buff);
  450. kfree(hidg);
  451. }
  452. /*-------------------------------------------------------------------------*/
  453. /* Strings */
  454. #define CT_FUNC_HID_IDX 0
  455. static struct usb_string ct_func_string_defs[] = {
  456. [CT_FUNC_HID_IDX].s = "HID Interface",
  457. {}, /* end of list */
  458. };
  459. static struct usb_gadget_strings ct_func_string_table = {
  460. .language = 0x0409, /* en-US */
  461. .strings = ct_func_string_defs,
  462. };
  463. static struct usb_gadget_strings *ct_func_strings[] = {
  464. &ct_func_string_table,
  465. NULL,
  466. };
  467. /*-------------------------------------------------------------------------*/
  468. /* usb_configuration */
  469. int __init hidg_bind_config(struct usb_configuration *c,
  470. struct hidg_func_descriptor *fdesc, int index)
  471. {
  472. struct f_hidg *hidg;
  473. int status;
  474. if (index >= minors)
  475. return -ENOENT;
  476. /* maybe allocate device-global string IDs, and patch descriptors */
  477. if (ct_func_string_defs[CT_FUNC_HID_IDX].id == 0) {
  478. status = usb_string_id(c->cdev);
  479. if (status < 0)
  480. return status;
  481. ct_func_string_defs[CT_FUNC_HID_IDX].id = status;
  482. hidg_interface_desc.iInterface = status;
  483. }
  484. /* allocate and initialize one new instance */
  485. hidg = kzalloc(sizeof *hidg, GFP_KERNEL);
  486. if (!hidg)
  487. return -ENOMEM;
  488. hidg->minor = index;
  489. hidg->bInterfaceSubClass = fdesc->subclass;
  490. hidg->bInterfaceProtocol = fdesc->protocol;
  491. hidg->report_length = fdesc->report_length;
  492. hidg->report_desc_length = fdesc->report_desc_length;
  493. hidg->report_desc = kmemdup(fdesc->report_desc,
  494. fdesc->report_desc_length,
  495. GFP_KERNEL);
  496. if (!hidg->report_desc) {
  497. kfree(hidg);
  498. return -ENOMEM;
  499. }
  500. hidg->func.name = "hid";
  501. hidg->func.strings = ct_func_strings;
  502. hidg->func.bind = hidg_bind;
  503. hidg->func.unbind = hidg_unbind;
  504. hidg->func.set_alt = hidg_set_alt;
  505. hidg->func.disable = hidg_disable;
  506. hidg->func.setup = hidg_setup;
  507. status = usb_add_function(c, &hidg->func);
  508. if (status)
  509. kfree(hidg);
  510. return status;
  511. }
  512. int __init ghid_setup(struct usb_gadget *g, int count)
  513. {
  514. int status;
  515. dev_t dev;
  516. hidg_class = class_create(THIS_MODULE, "hidg");
  517. status = alloc_chrdev_region(&dev, 0, count, "hidg");
  518. if (!status) {
  519. major = MAJOR(dev);
  520. minors = count;
  521. }
  522. return status;
  523. }
  524. void ghid_cleanup(void)
  525. {
  526. if (major) {
  527. unregister_chrdev_region(MKDEV(major, 0), minors);
  528. major = minors = 0;
  529. }
  530. class_destroy(hidg_class);
  531. hidg_class = NULL;
  532. }