This source file includes following definitions.
- usb_gadget_get_string
1
2
3
4
5
6 #include <linux/errno.h>
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/list.h>
10 #include <linux/string.h>
11 #include <linux/device.h>
12 #include <linux/nls.h>
13
14 #include <linux/usb/ch9.h>
15 #include <linux/usb/gadget.h>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 int
36 usb_gadget_get_string (const struct usb_gadget_strings *table, int id, u8 *buf)
37 {
38 struct usb_string *s;
39 int len;
40
41
42 if (id == 0) {
43 buf [0] = 4;
44 buf [1] = USB_DT_STRING;
45 buf [2] = (u8) table->language;
46 buf [3] = (u8) (table->language >> 8);
47 return 4;
48 }
49 for (s = table->strings; s && s->s; s++)
50 if (s->id == id)
51 break;
52
53
54 if (!s || !s->s)
55 return -EINVAL;
56
57
58 len = min ((size_t) 126, strlen (s->s));
59 len = utf8s_to_utf16s(s->s, len, UTF16_LITTLE_ENDIAN,
60 (wchar_t *) &buf[2], 126);
61 if (len < 0)
62 return -EINVAL;
63 buf [0] = (len + 1) * 2;
64 buf [1] = USB_DT_STRING;
65 return buf [0];
66 }
67 EXPORT_SYMBOL_GPL(usb_gadget_get_string);