aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/u_os_desc.h
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2014-07-09 06:20:07 -0400
committerFelipe Balbi <balbi@ti.com>2014-07-10 09:36:51 -0400
commit7ea4f088c810dab3ba3ab4c7a3879238f790e1fd (patch)
tree309115f9dca2438ced735a67957ca97d397acef4 /drivers/usb/gadget/u_os_desc.h
parentf96cbd149aff4b0c4f23629051ed5d28b6804fb1 (diff)
usb: gadget: u_os_desc: helper functions for accessing ext prop buffer
Provide helper functions to get pointers to particular locations within a buffer holding an extended properties descriptor. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/u_os_desc.h')
-rw-r--r--drivers/usb/gadget/u_os_desc.h59
1 files changed, 46 insertions, 13 deletions
diff --git a/drivers/usb/gadget/u_os_desc.h b/drivers/usb/gadget/u_os_desc.h
index ea5cf8c2da28..947b7ddff691 100644
--- a/drivers/usb/gadget/u_os_desc.h
+++ b/drivers/usb/gadget/u_os_desc.h
@@ -35,27 +35,63 @@
35#define USB_EXT_PROP_UNICODE_LINK 6 35#define USB_EXT_PROP_UNICODE_LINK 6
36#define USB_EXT_PROP_UNICODE_MULTI 7 36#define USB_EXT_PROP_UNICODE_MULTI 7
37 37
38static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset)
39{
40 return buf + offset;
41}
42
43static inline u8 *usb_ext_prop_size_ptr(u8 *buf)
44{
45 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
46}
47
48static inline u8 *usb_ext_prop_type_ptr(u8 *buf)
49{
50 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
51}
52
53static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf)
54{
55 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
56}
57
58static inline u8 *usb_ext_prop_name_ptr(u8 *buf)
59{
60 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
61}
62
63static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off)
64{
65 return __usb_ext_prop_ptr(buf,
66 USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
67}
68
69static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off)
70{
71 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
72}
73
38static inline void usb_ext_prop_put_size(u8 *buf, int dw_size) 74static inline void usb_ext_prop_put_size(u8 *buf, int dw_size)
39{ 75{
40 put_unaligned_le32(dw_size, &buf[USB_EXT_PROP_DW_SIZE]); 76 put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
41} 77}
42 78
43static inline void usb_ext_prop_put_type(u8 *buf, int type) 79static inline void usb_ext_prop_put_type(u8 *buf, int type)
44{ 80{
45 put_unaligned_le32(type, &buf[USB_EXT_PROP_DW_PROPERTY_DATA_TYPE]); 81 put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
46} 82}
47 83
48static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl) 84static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
49{ 85{
50 int result; 86 int result;
51 87
52 put_unaligned_le16(pnl, &buf[USB_EXT_PROP_W_PROPERTY_NAME_LENGTH]); 88 put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
53 result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN, 89 result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN,
54 (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_NAME], pnl - 2); 90 (wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2);
55 if (result < 0) 91 if (result < 0)
56 return result; 92 return result;
57 93
58 put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl]); 94 put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
59 95
60 return pnl; 96 return pnl;
61} 97}
@@ -63,26 +99,23 @@ static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
63static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, 99static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data,
64 int data_len) 100 int data_len)
65{ 101{
66 put_unaligned_le32(data_len, 102 put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
67 &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]); 103 memcpy(usb_ext_prop_data_ptr(buf, pnl), data, data_len);
68 memcpy(&buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], data, data_len);
69} 104}
70 105
71static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, 106static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string,
72 int data_len) 107 int data_len)
73{ 108{
74 int result; 109 int result;
75 put_unaligned_le32(data_len, 110 put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
76 &buf[USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + pnl]);
77
78 result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN, 111 result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN,
79 (wchar_t *) &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl], 112 (wchar_t *) usb_ext_prop_data_ptr(buf, pnl),
80 data_len - 2); 113 data_len - 2);
81 if (result < 0) 114 if (result < 0)
82 return result; 115 return result;
83 116
84 put_unaligned_le16(0, 117 put_unaligned_le16(0,
85 &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len]); 118 &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
86 119
87 return data_len; 120 return data_len;
88} 121}