blob: 13b1eb0c8c65f932993db85c3885e71d9a2074aa [file] [log] [blame]
Stefan Achatz5772f632011-01-30 13:38:23 +01001/*
2 * Roccat common functions for device specific drivers
3 *
4 * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 */
13
14#include <linux/slab.h>
15#include "hid-roccat-common.h"
16
17int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
18 void *data, uint size)
19{
20 char *buf;
21 int len;
22
23 buf = kmalloc(size, GFP_KERNEL);
24 if (buf == NULL)
25 return -ENOMEM;
26
27 len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
28 USB_REQ_CLEAR_FEATURE,
29 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
30 usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
31
32 memcpy(data, buf, size);
33 kfree(buf);
34 return ((len < 0) ? len : ((len != size) ? -EIO : 0));
35}
36EXPORT_SYMBOL_GPL(roccat_common_receive);
37
38int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
39 void const *data, uint size)
40{
41 char *buf;
42 int len;
43
44 buf = kmalloc(size, GFP_KERNEL);
45 if (buf == NULL)
46 return -ENOMEM;
47
48 memcpy(buf, data, size);
49
50 len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
51 USB_REQ_SET_CONFIGURATION,
52 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
53 usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
54
55 kfree(buf);
56 return ((len < 0) ? len : ((len != size) ? -EIO : 0));
57}
58EXPORT_SYMBOL_GPL(roccat_common_send);
59
60MODULE_AUTHOR("Stefan Achatz");
61MODULE_DESCRIPTION("USB Roccat common driver");
62MODULE_LICENSE("GPL v2");