diff options
3 files changed, 851 insertions, 1 deletions
diff --git a/meta-oe/recipes-support/libusbgx/libusbgx/0001-fix-stack-buffer-overflow-in-usbg_f_foo_attr_val-pro.patch b/meta-oe/recipes-support/libusbgx/libusbgx/0001-fix-stack-buffer-overflow-in-usbg_f_foo_attr_val-pro.patch new file mode 100644 index 0000000000..1ab3494e18 --- /dev/null +++ b/meta-oe/recipes-support/libusbgx/libusbgx/0001-fix-stack-buffer-overflow-in-usbg_f_foo_attr_val-pro.patch | |||
| @@ -0,0 +1,796 @@ | |||
| 1 | From fc7855891c66599487265701294963bb0772bb80 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Wlodzimierz Lipert <wlodzimierz.lipert@gmail.com> | ||
| 3 | Date: Mon, 28 Nov 2022 08:29:54 +0100 | ||
| 4 | Subject: [PATCH] fix: stack-buffer-overflow in usbg_f_foo_attr_val processing. | ||
| 5 | Changed ABI version from 2 to 3. | ||
| 6 | |||
| 7 | Upstream-Status: Submitted [https://github.com/linux-usb-gadgets/libusbgx/pull/72] | ||
| 8 | |||
| 9 | Signed-off-by: Wlodzimierz Lipert <wlodzimierz.lipert@gmail.com> | ||
| 10 | Signed-off-by: Ming Liu <liu.ming50@gmail.com> | ||
| 11 | --- | ||
| 12 | include/usbg/function/hid.h | 28 ++++++++++++---------------- | ||
| 13 | include/usbg/function/midi.h | 35 +++++++++++++---------------------- | ||
| 14 | include/usbg/function/ms.h | 30 +++++++++++------------------- | ||
| 15 | include/usbg/function/net.h | 34 ++++++++++++++-------------------- | ||
| 16 | include/usbg/function/uac2.h | 29 +++++++++++++---------------- | ||
| 17 | include/usbg/usbg_internal.h | 10 +++++----- | ||
| 18 | src/Makefile.am | 2 +- | ||
| 19 | src/function/ether.c | 10 +++++----- | ||
| 20 | src/function/hid.c | 12 ++++++------ | ||
| 21 | src/function/midi.c | 10 +++++----- | ||
| 22 | src/function/ms.c | 10 +++++----- | ||
| 23 | src/function/uac2.c | 10 +++++----- | ||
| 24 | src/function/uvc.c | 10 +++++----- | ||
| 25 | src/usbg_common.c | 2 +- | ||
| 26 | 14 files changed, 101 insertions(+), 131 deletions(-) | ||
| 27 | |||
| 28 | diff --git a/include/usbg/function/hid.h b/include/usbg/function/hid.h | ||
| 29 | index 3463140..3b3907b 100644 | ||
| 30 | --- a/include/usbg/function/hid.h | ||
| 31 | +++ b/include/usbg/function/hid.h | ||
| 32 | @@ -56,11 +56,6 @@ union usbg_f_hid_attr_val { | ||
| 33 | unsigned int subclass; | ||
| 34 | }; | ||
| 35 | |||
| 36 | -#define USBG_F_HID_UINT_TO_ATTR_VAL(WHAT) \ | ||
| 37 | - USBG_TO_UNION(usbg_f_hid_attr_val, protocol, WHAT) | ||
| 38 | - | ||
| 39 | -#define USBG_F_HID_RDESC_TO_ATTR_VAL(WHAT) \ | ||
| 40 | - USBG_TO_UNION(usbg_f_hid_attr_val, report_desc, WHAT) | ||
| 41 | /** | ||
| 42 | * @brief Cast from generic function to hid function | ||
| 43 | * @param[in] f function to be converted to hid funciton. | ||
| 44 | @@ -137,7 +132,7 @@ int usbg_f_hid_get_attr_val(usbg_f_hid *hf, enum usbg_f_hid_attr attr, | ||
| 45 | * @return 0 on success usbg_error if error occurred. | ||
| 46 | */ | ||
| 47 | int usbg_f_hid_set_attr_val(usbg_f_hid *hf, enum usbg_f_hid_attr attr, | ||
| 48 | - union usbg_f_hid_attr_val val); | ||
| 49 | + const union usbg_f_hid_attr_val *val); | ||
| 50 | |||
| 51 | /** | ||
| 52 | * @brief Get the minor and major of corresponding character device | ||
| 53 | @@ -173,8 +168,9 @@ static inline int usbg_f_hid_get_protocol(usbg_f_hid *hf, | ||
| 54 | static inline int usbg_f_hid_set_protocol(usbg_f_hid *hf, | ||
| 55 | unsigned int protocol) | ||
| 56 | { | ||
| 57 | - return usbg_f_hid_set_attr_val(hf, USBG_F_HID_PROTOCOL, | ||
| 58 | - USBG_F_HID_UINT_TO_ATTR_VAL(protocol)); | ||
| 59 | + | ||
| 60 | + union usbg_f_hid_attr_val val = {.protocol = protocol}; | ||
| 61 | + return usbg_f_hid_set_attr_val(hf, USBG_F_HID_PROTOCOL, &val); | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | @@ -199,8 +195,8 @@ static inline int usbg_f_hid_get_report_desc(usbg_f_hid *hf, | ||
| 66 | static inline int usbg_f_hid_set_report_desc(usbg_f_hid *hf, | ||
| 67 | struct usbg_f_hid_report_desc report_desc) | ||
| 68 | { | ||
| 69 | - return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC, | ||
| 70 | - USBG_F_HID_RDESC_TO_ATTR_VAL(report_desc)); | ||
| 71 | + union usbg_f_hid_attr_val val = {.report_desc = report_desc}; | ||
| 72 | + return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC, &val); | ||
| 73 | } | ||
| 74 | |||
| 75 | /** | ||
| 76 | @@ -242,8 +238,8 @@ static inline int usbg_f_hid_set_report_desc_raw(usbg_f_hid *hf, | ||
| 77 | .len = len, | ||
| 78 | }; | ||
| 79 | |||
| 80 | - return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC, | ||
| 81 | - USBG_F_HID_RDESC_TO_ATTR_VAL(report_desc)); | ||
| 82 | + union usbg_f_hid_attr_val val = {.report_desc = report_desc}; | ||
| 83 | + return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_DESC, &val); | ||
| 84 | } | ||
| 85 | |||
| 86 | /** | ||
| 87 | @@ -268,8 +264,8 @@ static inline int usbg_f_hid_get_report_length(usbg_f_hid *hf, | ||
| 88 | static inline int usbg_f_hid_set_report_length(usbg_f_hid *hf, | ||
| 89 | unsigned int report_length) | ||
| 90 | { | ||
| 91 | - return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_LENGTH, | ||
| 92 | - USBG_F_HID_UINT_TO_ATTR_VAL(report_length)); | ||
| 93 | + union usbg_f_hid_attr_val val = {.report_length = report_length}; | ||
| 94 | + return usbg_f_hid_set_attr_val(hf, USBG_F_HID_REPORT_LENGTH, &val); | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | ||
| 98 | @@ -294,8 +290,8 @@ static inline int usbg_f_hid_get_subclass(usbg_f_hid *hf, | ||
| 99 | static inline int usbg_f_hid_set_subclass(usbg_f_hid *hf, | ||
| 100 | unsigned int subclass) | ||
| 101 | { | ||
| 102 | - return usbg_f_hid_set_attr_val(hf, USBG_F_HID_SUBCLASS, | ||
| 103 | - USBG_F_HID_UINT_TO_ATTR_VAL(subclass)); | ||
| 104 | + union usbg_f_hid_attr_val val = {.subclass = subclass}; | ||
| 105 | + return usbg_f_hid_set_attr_val(hf, USBG_F_HID_SUBCLASS, &val); | ||
| 106 | } | ||
| 107 | |||
| 108 | #ifdef __cplusplus | ||
| 109 | diff --git a/include/usbg/function/midi.h b/include/usbg/function/midi.h | ||
| 110 | index 39df047..b9d9d4f 100644 | ||
| 111 | --- a/include/usbg/function/midi.h | ||
| 112 | +++ b/include/usbg/function/midi.h | ||
| 113 | @@ -53,15 +53,6 @@ union usbg_f_midi_attr_val { | ||
| 114 | unsigned int qlen; | ||
| 115 | }; | ||
| 116 | |||
| 117 | -#define USBG_F_MIDI_INT_TO_ATTR_VAL(WHAT) \ | ||
| 118 | - USBG_TO_UNION(usbg_f_midi_attr_val, index, WHAT) | ||
| 119 | - | ||
| 120 | -#define USBG_F_MIDI_UINT_TO_ATTR_VAL(WHAT) \ | ||
| 121 | - USBG_TO_UNION(usbg_f_midi_attr_val, qlen, WHAT) | ||
| 122 | - | ||
| 123 | -#define USBG_F_MIDI_CCHAR_PTR_TO_ATTR_VAL(WHAT) \ | ||
| 124 | - USBG_TO_UNION(usbg_f_midi_attr_val, id, WHAT) | ||
| 125 | - | ||
| 126 | /** | ||
| 127 | * @brief Cast from generic function to midi function | ||
| 128 | * @param[in] f function to be converted to midi funciton. | ||
| 129 | @@ -126,7 +117,7 @@ int usbg_f_midi_get_attr_val(usbg_f_midi *mf, enum usbg_f_midi_attr attr, | ||
| 130 | * @return 0 on success usbg_error if error occurred. | ||
| 131 | */ | ||
| 132 | int usbg_f_midi_set_attr_val(usbg_f_midi *mf, enum usbg_f_midi_attr attr, | ||
| 133 | - union usbg_f_midi_attr_val val); | ||
| 134 | + const union usbg_f_midi_attr_val *val); | ||
| 135 | |||
| 136 | /** | ||
| 137 | * @brief Get the index value of MIDI adapter | ||
| 138 | @@ -148,8 +139,8 @@ static inline int usbg_f_midi_get_index(usbg_f_midi *mf, int *index) | ||
| 139 | */ | ||
| 140 | static inline int usbg_f_midi_set_index(usbg_f_midi *mf, int index) | ||
| 141 | { | ||
| 142 | - return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_INDEX, | ||
| 143 | - USBG_F_MIDI_INT_TO_ATTR_VAL(index)); | ||
| 144 | + union usbg_f_midi_attr_val val = {.index = index}; | ||
| 145 | + return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_INDEX, &val); | ||
| 146 | } | ||
| 147 | |||
| 148 | /** | ||
| 149 | @@ -188,8 +179,8 @@ int usbg_f_midi_get_id_s(usbg_f_midi *mf, char *buf, int len); | ||
| 150 | */ | ||
| 151 | static inline int usbg_f_midi_set_id(usbg_f_midi *mf, const char *id) | ||
| 152 | { | ||
| 153 | - return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_ID, | ||
| 154 | - USBG_F_MIDI_CCHAR_PTR_TO_ATTR_VAL(id)); | ||
| 155 | + union usbg_f_midi_attr_val val = {.id = id}; | ||
| 156 | + return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_ID, &val); | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | @@ -212,8 +203,8 @@ static inline int usbg_f_midi_get_in_ports(usbg_f_midi *mf, unsigned *in_ports) | ||
| 161 | */ | ||
| 162 | static inline int usbg_f_midi_set_in_ports(usbg_f_midi *mf, unsigned in_ports) | ||
| 163 | { | ||
| 164 | - return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_IN_PORTS, | ||
| 165 | - USBG_F_MIDI_UINT_TO_ATTR_VAL(in_ports)); | ||
| 166 | + union usbg_f_midi_attr_val val = {.in_ports = in_ports}; | ||
| 167 | + return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_IN_PORTS, &val); | ||
| 168 | } | ||
| 169 | |||
| 170 | /** | ||
| 171 | @@ -236,8 +227,8 @@ static inline int usbg_f_midi_get_out_ports(usbg_f_midi *mf, unsigned *out_ports | ||
| 172 | */ | ||
| 173 | static inline int usbg_f_midi_set_out_ports(usbg_f_midi *mf, unsigned out_ports) | ||
| 174 | { | ||
| 175 | - return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_OUT_PORTS, | ||
| 176 | - USBG_F_MIDI_UINT_TO_ATTR_VAL(out_ports)); | ||
| 177 | + union usbg_f_midi_attr_val val = {.out_ports = out_ports}; | ||
| 178 | + return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_OUT_PORTS, &val); | ||
| 179 | } | ||
| 180 | |||
| 181 | /** | ||
| 182 | @@ -264,8 +255,8 @@ static inline int usbg_f_midi_get_buflen(usbg_f_midi *mf, int *buflen) | ||
| 183 | */ | ||
| 184 | static inline int usbg_f_midi_set_buflen(usbg_f_midi *mf, unsigned buflen) | ||
| 185 | { | ||
| 186 | - return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_BUFLEN, | ||
| 187 | - USBG_F_MIDI_UINT_TO_ATTR_VAL(buflen)); | ||
| 188 | + union usbg_f_midi_attr_val val = {.buflen = buflen}; | ||
| 189 | + return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_BUFLEN, &val); | ||
| 190 | } | ||
| 191 | |||
| 192 | /** | ||
| 193 | @@ -288,8 +279,8 @@ static inline int usbg_f_midi_get_qlen(usbg_f_midi *mf, unsigned *qlen) | ||
| 194 | */ | ||
| 195 | static inline int usbg_f_midi_set_qlen(usbg_f_midi *mf, unsigned qlen) | ||
| 196 | { | ||
| 197 | - return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_QLEN, | ||
| 198 | - USBG_F_MIDI_UINT_TO_ATTR_VAL(qlen)); | ||
| 199 | + union usbg_f_midi_attr_val val = {.qlen = qlen}; | ||
| 200 | + return usbg_f_midi_set_attr_val(mf, USBG_F_MIDI_QLEN, &val); | ||
| 201 | } | ||
| 202 | |||
| 203 | #ifdef __cplusplus | ||
| 204 | diff --git a/include/usbg/function/ms.h b/include/usbg/function/ms.h | ||
| 205 | index 780464c..f52eb78 100644 | ||
| 206 | --- a/include/usbg/function/ms.h | ||
| 207 | +++ b/include/usbg/function/ms.h | ||
| 208 | @@ -56,14 +56,6 @@ union usbg_f_ms_lun_attr_val { | ||
| 209 | const char *file; | ||
| 210 | }; | ||
| 211 | |||
| 212 | -#define USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(WHAT) \ | ||
| 213 | - USBG_TO_UNION(usbg_f_ms_lun_attr_val, cdrom, WHAT) | ||
| 214 | - | ||
| 215 | -#define USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(WHAT) \ | ||
| 216 | - USBG_TO_UNION(usbg_f_ms_lun_attr_val, file, WHAT) | ||
| 217 | - | ||
| 218 | - | ||
| 219 | - | ||
| 220 | /** | ||
| 221 | * @brief Cast from generic function to mass storage function | ||
| 222 | * @param[in] f function to be converted to ms funciton. | ||
| 223 | @@ -157,7 +149,7 @@ int usbg_f_ms_get_lun_attr_val(usbg_f_ms *mf, int lun_id, | ||
| 224 | */ | ||
| 225 | int usbg_f_ms_set_lun_attr_val(usbg_f_ms *mf, int lun_id, | ||
| 226 | enum usbg_f_ms_lun_attr lattr, | ||
| 227 | - const union usbg_f_ms_lun_attr_val val); | ||
| 228 | + const union usbg_f_ms_lun_attr_val *val); | ||
| 229 | |||
| 230 | /** | ||
| 231 | * @brief Get the value which determines if lun is visible as a cdrom | ||
| 232 | @@ -183,8 +175,8 @@ static inline int usbg_f_ms_get_lun_cdrom(usbg_f_ms *mf, int lun_id, | ||
| 233 | static inline int usbg_f_ms_set_lun_cdrom(usbg_f_ms *mf, int lun_id, | ||
| 234 | bool cdrom) | ||
| 235 | { | ||
| 236 | - return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_CDROM, | ||
| 237 | - USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(cdrom)); | ||
| 238 | + union usbg_f_ms_lun_attr_val val = {.cdrom = cdrom}; | ||
| 239 | + return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_CDROM, &val); | ||
| 240 | } | ||
| 241 | |||
| 242 | /** | ||
| 243 | @@ -209,8 +201,8 @@ static inline int usbg_f_ms_get_lun_ro(usbg_f_ms *mf, int lun_id, bool *ro) | ||
| 244 | */ | ||
| 245 | static inline int usbg_f_ms_set_lun_ro(usbg_f_ms *mf, int lun_id, bool ro) | ||
| 246 | { | ||
| 247 | - return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_RO, | ||
| 248 | - USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(ro)); | ||
| 249 | + union usbg_f_ms_lun_attr_val val = {.ro = ro}; | ||
| 250 | + return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_RO, &val); | ||
| 251 | } | ||
| 252 | |||
| 253 | /** | ||
| 254 | @@ -239,8 +231,8 @@ static inline int usbg_f_ms_get_lun_nofua(usbg_f_ms *mf, int lun_id, | ||
| 255 | static inline int usbg_f_ms_set_lun_nofua(usbg_f_ms *mf, int lun_id, | ||
| 256 | bool nofua) | ||
| 257 | { | ||
| 258 | - return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_NOFUA, | ||
| 259 | - USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(nofua)); | ||
| 260 | + union usbg_f_ms_lun_attr_val val = {.nofua = nofua}; | ||
| 261 | + return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_NOFUA, &val); | ||
| 262 | } | ||
| 263 | |||
| 264 | /** | ||
| 265 | @@ -267,8 +259,8 @@ static inline int usbg_f_ms_get_lun_removable(usbg_f_ms *mf, int lun_id, | ||
| 266 | static inline int usbg_f_ms_set_lun_removable(usbg_f_ms *mf, int lun_id, | ||
| 267 | bool removable) | ||
| 268 | { | ||
| 269 | - return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_REMOVABLE, | ||
| 270 | - USBG_F_MS_LUN_BOOL_TO_ATTR_VAL(removable)); | ||
| 271 | + union usbg_f_ms_lun_attr_val val = {.removable = removable}; | ||
| 272 | + return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_REMOVABLE, &val); | ||
| 273 | } | ||
| 274 | |||
| 275 | /** | ||
| 276 | @@ -313,8 +305,8 @@ int usbg_f_ms_get_lun_file_s(usbg_f_ms *mf, int lun_id, | ||
| 277 | static inline int usbg_f_ms_set_lun_file(usbg_f_ms *mf, int lun_id, | ||
| 278 | const char *file) | ||
| 279 | { | ||
| 280 | - return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_FILE, | ||
| 281 | - USBG_F_MS_LUN_CCHAR_PTR_TO_ATTR_VAL(file)); | ||
| 282 | + union usbg_f_ms_lun_attr_val val = {.file = file}; | ||
| 283 | + return usbg_f_ms_set_lun_attr_val(mf, lun_id, USBG_F_MS_LUN_FILE, &val); | ||
| 284 | } | ||
| 285 | |||
| 286 | /** | ||
| 287 | diff --git a/include/usbg/function/net.h b/include/usbg/function/net.h | ||
| 288 | index b0409f1..06cee30 100644 | ||
| 289 | --- a/include/usbg/function/net.h | ||
| 290 | +++ b/include/usbg/function/net.h | ||
| 291 | @@ -56,12 +56,6 @@ union usbg_f_net_attr_val { | ||
| 292 | unsigned int protocol; | ||
| 293 | }; | ||
| 294 | |||
| 295 | -#define USBG_F_NET_ETHER_ADDR_TO_ATTR_VAL(WHAT) \ | ||
| 296 | - USBG_TO_UNION(usbg_f_net_attr_val, dev_addr, WHAT) | ||
| 297 | - | ||
| 298 | -#define USBG_F_NET_INT_TO_ATTR_VAL(WHAT) \ | ||
| 299 | - USBG_TO_UNION(usbg_f_net_attr_val, qmult, WHAT) | ||
| 300 | - | ||
| 301 | /** | ||
| 302 | * @brief Cast from generic function to net function | ||
| 303 | * @param[in] f function to be converted to net funciton. | ||
| 304 | @@ -125,7 +119,7 @@ int usbg_f_net_get_attr_val(usbg_f_net *nf, enum usbg_f_net_attr attr, | ||
| 305 | * @return 0 on success usbg_error if error occurred. | ||
| 306 | */ | ||
| 307 | int usbg_f_net_set_attr_val(usbg_f_net *nf, enum usbg_f_net_attr attr, | ||
| 308 | - const union usbg_f_net_attr_val val); | ||
| 309 | + const union usbg_f_net_attr_val *val); | ||
| 310 | |||
| 311 | /** | ||
| 312 | * @brief Get the value of device side MAC address | ||
| 313 | @@ -136,7 +130,7 @@ int usbg_f_net_set_attr_val(usbg_f_net *nf, enum usbg_f_net_attr attr, | ||
| 314 | static inline int usbg_f_net_get_dev_addr(usbg_f_net *nf, | ||
| 315 | struct ether_addr *addr) | ||
| 316 | { | ||
| 317 | - union usbg_f_net_attr_val val = { .dev_addr = *addr, }; | ||
| 318 | + union usbg_f_net_attr_val val = {.dev_addr = *addr}; | ||
| 319 | return usbg_f_net_get_attr_val(nf, USBG_F_NET_DEV_ADDR, &val); | ||
| 320 | } | ||
| 321 | |||
| 322 | @@ -149,8 +143,8 @@ static inline int usbg_f_net_get_dev_addr(usbg_f_net *nf, | ||
| 323 | static inline int usbg_f_net_set_dev_addr(usbg_f_net *nf, | ||
| 324 | const struct ether_addr *addr) | ||
| 325 | { | ||
| 326 | - return usbg_f_net_set_attr_val(nf, USBG_F_NET_DEV_ADDR, | ||
| 327 | - USBG_F_NET_ETHER_ADDR_TO_ATTR_VAL(*addr)); | ||
| 328 | + union usbg_f_net_attr_val val = {.dev_addr = *addr}; | ||
| 329 | + return usbg_f_net_set_attr_val(nf, USBG_F_NET_DEV_ADDR, &val); | ||
| 330 | } | ||
| 331 | |||
| 332 | /** | ||
| 333 | @@ -175,8 +169,8 @@ static inline int usbg_f_net_get_host_addr(usbg_f_net *nf, | ||
| 334 | static inline int usbg_f_net_set_host_addr(usbg_f_net *nf, | ||
| 335 | const struct ether_addr *addr) | ||
| 336 | { | ||
| 337 | - return usbg_f_net_set_attr_val(nf, USBG_F_NET_HOST_ADDR, | ||
| 338 | - USBG_F_NET_ETHER_ADDR_TO_ATTR_VAL(*addr)); | ||
| 339 | + union usbg_f_net_attr_val val = {.host_addr = *addr}; | ||
| 340 | + return usbg_f_net_set_attr_val(nf, USBG_F_NET_HOST_ADDR, &val); | ||
| 341 | } | ||
| 342 | |||
| 343 | /** | ||
| 344 | @@ -226,8 +220,8 @@ static inline int usbg_f_net_get_qmult(usbg_f_net *nf, int *qmult) | ||
| 345 | */ | ||
| 346 | static inline int usbg_f_net_set_qmult(usbg_f_net *nf, int qmult) | ||
| 347 | { | ||
| 348 | - return usbg_f_net_set_attr_val(nf, USBG_F_NET_QMULT, | ||
| 349 | - USBG_F_NET_INT_TO_ATTR_VAL(qmult)); | ||
| 350 | + union usbg_f_net_attr_val val = {.qmult = qmult}; | ||
| 351 | + return usbg_f_net_set_attr_val(nf, USBG_F_NET_QMULT, &val); | ||
| 352 | } | ||
| 353 | |||
| 354 | /** | ||
| 355 | @@ -250,8 +244,8 @@ static inline int usbg_f_net_get_class(usbg_f_net *nf, unsigned int *class_) | ||
| 356 | */ | ||
| 357 | static inline int usbg_f_net_set_class(usbg_f_net *nf, unsigned int class_) | ||
| 358 | { | ||
| 359 | - return usbg_f_net_set_attr_val(nf, USBG_F_NET_CLASS, | ||
| 360 | - USBG_F_NET_INT_TO_ATTR_VAL(class_)); | ||
| 361 | + union usbg_f_net_attr_val val = {.class_ = class_}; | ||
| 362 | + return usbg_f_net_set_attr_val(nf, USBG_F_NET_CLASS, &val); | ||
| 363 | } | ||
| 364 | |||
| 365 | /** | ||
| 366 | @@ -274,8 +268,8 @@ static inline int usbg_f_net_get_subclass(usbg_f_net *nf, int *subclass) | ||
| 367 | */ | ||
| 368 | static inline int usbg_f_net_set_subclass(usbg_f_net *nf, unsigned int subclass) | ||
| 369 | { | ||
| 370 | - return usbg_f_net_set_attr_val(nf, USBG_F_NET_SUBCLASS, | ||
| 371 | - USBG_F_NET_INT_TO_ATTR_VAL(subclass)); | ||
| 372 | + union usbg_f_net_attr_val val = {.subclass = subclass}; | ||
| 373 | + return usbg_f_net_set_attr_val(nf, USBG_F_NET_SUBCLASS, &val); | ||
| 374 | } | ||
| 375 | |||
| 376 | /** | ||
| 377 | @@ -298,8 +292,8 @@ static inline int usbg_f_net_get_protocol(usbg_f_net *nf, int *protocol) | ||
| 378 | */ | ||
| 379 | static inline int usbg_f_net_set_protocol(usbg_f_net *nf, unsigned int protocol) | ||
| 380 | { | ||
| 381 | - return usbg_f_net_set_attr_val(nf, USBG_F_NET_PROTOCOL, | ||
| 382 | - USBG_F_NET_INT_TO_ATTR_VAL(protocol)); | ||
| 383 | + union usbg_f_net_attr_val val = {.protocol = protocol}; | ||
| 384 | + return usbg_f_net_set_attr_val(nf, USBG_F_NET_PROTOCOL, &val); | ||
| 385 | } | ||
| 386 | |||
| 387 | #ifdef __cplusplus | ||
| 388 | diff --git a/include/usbg/function/uac2.h b/include/usbg/function/uac2.h | ||
| 389 | index c1bbb14..1ea55dc 100644 | ||
| 390 | --- a/include/usbg/function/uac2.h | ||
| 391 | +++ b/include/usbg/function/uac2.h | ||
| 392 | @@ -53,9 +53,6 @@ union usbg_f_uac2_attr_val { | ||
| 393 | int p_ssize; | ||
| 394 | }; | ||
| 395 | |||
| 396 | -#define USBG_F_UAC2_INT_TO_ATTR_VAL(WHAT) \ | ||
| 397 | - USBG_TO_UNION(usbg_f_uac2_attr_val, c_chmask, WHAT) | ||
| 398 | - | ||
| 399 | /** | ||
| 400 | * @brief Cast from generic function to uac2 function | ||
| 401 | * @param[in] f function to be converted to uac2 funciton. | ||
| 402 | @@ -115,7 +112,7 @@ int usbg_f_uac2_get_attr_val(usbg_f_uac2 *af, enum usbg_f_uac2_attr attr, | ||
| 403 | * @return 0 on success usbg_error if error occurred. | ||
| 404 | */ | ||
| 405 | int usbg_f_uac2_set_attr_val(usbg_f_uac2 *af, enum usbg_f_uac2_attr attr, | ||
| 406 | - union usbg_f_uac2_attr_val val); | ||
| 407 | + const union usbg_f_uac2_attr_val *val); | ||
| 408 | |||
| 409 | /** | ||
| 410 | * @brief Get the capture channel mask of UAC2 adapter | ||
| 411 | @@ -137,8 +134,8 @@ static inline int usbg_f_uac2_get_c_chmask(usbg_f_uac2 *af, int *c_chmask) | ||
| 412 | */ | ||
| 413 | static inline int usbg_f_uac2_set_c_chmask(usbg_f_uac2 *af, int c_chmask) | ||
| 414 | { | ||
| 415 | - return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_C_CHMASK, | ||
| 416 | - USBG_F_UAC2_INT_TO_ATTR_VAL(c_chmask)); | ||
| 417 | + union usbg_f_uac2_attr_val val = {.c_chmask = c_chmask}; | ||
| 418 | + return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_C_CHMASK, &val); | ||
| 419 | } | ||
| 420 | |||
| 421 | /** | ||
| 422 | @@ -161,8 +158,8 @@ static inline int usbg_f_uac2_get_c_srate(usbg_f_uac2 *af, int *c_srate) | ||
| 423 | */ | ||
| 424 | static inline int usbg_f_uac2_set_c_srate(usbg_f_uac2 *af, int c_srate) | ||
| 425 | { | ||
| 426 | - return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_C_SRATE, | ||
| 427 | - USBG_F_UAC2_INT_TO_ATTR_VAL(c_srate)); | ||
| 428 | + union usbg_f_uac2_attr_val val = {.c_srate = c_srate}; | ||
| 429 | + return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_C_SRATE, &val); | ||
| 430 | } | ||
| 431 | |||
| 432 | /** | ||
| 433 | @@ -185,8 +182,8 @@ static inline int usbg_f_uac2_get_c_ssize(usbg_f_uac2 *af, int *c_ssize) | ||
| 434 | */ | ||
| 435 | static inline int usbg_f_uac2_set_c_ssize(usbg_f_uac2 *af, int c_ssize) | ||
| 436 | { | ||
| 437 | - return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_C_SSIZE, | ||
| 438 | - USBG_F_UAC2_INT_TO_ATTR_VAL(c_ssize)); | ||
| 439 | + union usbg_f_uac2_attr_val val = {.c_ssize = c_ssize}; | ||
| 440 | + return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_C_SSIZE, &val); | ||
| 441 | } | ||
| 442 | |||
| 443 | /** | ||
| 444 | @@ -209,8 +206,8 @@ static inline int usbg_f_uac2_get_p_chmask(usbg_f_uac2 *af, int *p_chmask) | ||
| 445 | */ | ||
| 446 | static inline int usbg_f_uac2_set_p_chmask(usbg_f_uac2 *af, int p_chmask) | ||
| 447 | { | ||
| 448 | - return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_P_CHMASK, | ||
| 449 | - USBG_F_UAC2_INT_TO_ATTR_VAL(p_chmask)); | ||
| 450 | + union usbg_f_uac2_attr_val val = {.p_chmask = p_chmask}; | ||
| 451 | + return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_P_CHMASK, &val); | ||
| 452 | } | ||
| 453 | |||
| 454 | /** | ||
| 455 | @@ -233,8 +230,8 @@ static inline int usbg_f_uac2_get_p_srate(usbg_f_uac2 *af, int *p_srate) | ||
| 456 | */ | ||
| 457 | static inline int usbg_f_uac2_set_p_srate(usbg_f_uac2 *af, int p_srate) | ||
| 458 | { | ||
| 459 | - return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_P_SRATE, | ||
| 460 | - USBG_F_UAC2_INT_TO_ATTR_VAL(p_srate)); | ||
| 461 | + union usbg_f_uac2_attr_val val = {.p_srate = p_srate}; | ||
| 462 | + return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_P_SRATE, &val); | ||
| 463 | } | ||
| 464 | |||
| 465 | /** | ||
| 466 | @@ -257,8 +254,8 @@ static inline int usbg_f_uac2_get_p_ssize(usbg_f_uac2 *af, int *p_ssize) | ||
| 467 | */ | ||
| 468 | static inline int usbg_f_uac2_set_p_ssize(usbg_f_uac2 *af, int p_ssize) | ||
| 469 | { | ||
| 470 | - return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_P_SSIZE, | ||
| 471 | - USBG_F_UAC2_INT_TO_ATTR_VAL(p_ssize)); | ||
| 472 | + union usbg_f_uac2_attr_val val = {.p_ssize = p_ssize}; | ||
| 473 | + return usbg_f_uac2_set_attr_val(af, USBG_F_UAC2_P_SSIZE, &val); | ||
| 474 | } | ||
| 475 | |||
| 476 | #ifdef __cplusplus | ||
| 477 | diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h | ||
| 478 | index 1d8dfe2..d6a3e3a 100644 | ||
| 479 | --- a/include/usbg/usbg_internal.h | ||
| 480 | +++ b/include/usbg/usbg_internal.h | ||
| 481 | @@ -322,7 +322,7 @@ void usbg_cleanup_function(struct usbg_function *f); | ||
| 482 | } | ||
| 483 | |||
| 484 | typedef int (*usbg_attr_get_func)(const char *, const char *, const char *, void *); | ||
| 485 | -typedef int (*usbg_attr_set_func)(const char *, const char *, const char *, void *); | ||
| 486 | +typedef int (*usbg_attr_set_func)(const char *, const char *, const char *, const void *); | ||
| 487 | |||
| 488 | static inline int usbg_get_dec(const char *path, const char *name, | ||
| 489 | const char *attr, void *val) | ||
| 490 | @@ -331,7 +331,7 @@ static inline int usbg_get_dec(const char *path, const char *name, | ||
| 491 | } | ||
| 492 | |||
| 493 | static inline int usbg_set_dec(const char *path, const char *name, | ||
| 494 | - const char *attr, void *val) | ||
| 495 | + const char *attr, const void *val) | ||
| 496 | { | ||
| 497 | return usbg_write_dec(path, name, attr, *((int *)val)); | ||
| 498 | } | ||
| 499 | @@ -343,7 +343,7 @@ static inline int usbg_get_bool(const char *path, const char *name, | ||
| 500 | } | ||
| 501 | |||
| 502 | static inline int usbg_set_bool(const char *path, const char *name, | ||
| 503 | - const char *attr, void *val) | ||
| 504 | + const char *attr, const void *val) | ||
| 505 | { | ||
| 506 | return usbg_write_bool(path, name, attr, *((bool *)val)); | ||
| 507 | } | ||
| 508 | @@ -355,7 +355,7 @@ static inline int usbg_get_string(const char *path, const char *name, | ||
| 509 | } | ||
| 510 | |||
| 511 | static inline int usbg_set_string(const char *path, const char *name, | ||
| 512 | - const char *attr, void *val) | ||
| 513 | + const char *attr, const void *val) | ||
| 514 | { | ||
| 515 | return usbg_write_string(path, name, attr, *(char **)val); | ||
| 516 | } | ||
| 517 | @@ -364,7 +364,7 @@ int usbg_get_ether_addr(const char *path, const char *name, const char *attr, | ||
| 518 | void *val); | ||
| 519 | |||
| 520 | int usbg_set_ether_addr(const char *path, const char *name, const char *attr, | ||
| 521 | - void *val); | ||
| 522 | + const void *val); | ||
| 523 | |||
| 524 | int usbg_get_dev(const char *path, const char *name, const char *attr, | ||
| 525 | void *val); | ||
| 526 | diff --git a/src/Makefile.am b/src/Makefile.am | ||
| 527 | index 634209f..ac97bc8 100644 | ||
| 528 | --- a/src/Makefile.am | ||
| 529 | +++ b/src/Makefile.am | ||
| 530 | @@ -7,6 +7,6 @@ else | ||
| 531 | libusbgx_la_SOURCES += usbg_schemes_none.c | ||
| 532 | endif | ||
| 533 | libusbgx_la_LDFLAGS = $(LIBCONFIG_LIBS) | ||
| 534 | -libusbgx_la_LDFLAGS += -version-info 2:0:0 | ||
| 535 | +libusbgx_la_LDFLAGS += -version-info 3:0:0 | ||
| 536 | libusbgx_la_CFLAGS = $(LIBCONFIG_CFLAGS) | ||
| 537 | AM_CPPFLAGS=-I$(top_srcdir)/include/ -I$(top_builddir)/include/usbg | ||
| 538 | diff --git a/src/function/ether.c b/src/function/ether.c | ||
| 539 | index ab91af9..d7dcd5d 100644 | ||
| 540 | --- a/src/function/ether.c | ||
| 541 | +++ b/src/function/ether.c | ||
| 542 | @@ -124,7 +124,7 @@ static int ether_libconfig_import(struct usbg_function *f, | ||
| 543 | if (ret < 0) | ||
| 544 | break; | ||
| 545 | |||
| 546 | - ret = usbg_f_net_set_attr_val(nf, i, val); | ||
| 547 | + ret = usbg_f_net_set_attr_val(nf, i, &val); | ||
| 548 | if (ret) | ||
| 549 | break; | ||
| 550 | } | ||
| 551 | @@ -258,8 +258,8 @@ int usbg_f_net_set_attrs(usbg_f_net *nf, | ||
| 552 | continue; | ||
| 553 | |||
| 554 | ret = usbg_f_net_set_attr_val(nf, i, | ||
| 555 | - *(union usbg_f_net_attr_val *) | ||
| 556 | - ((char *)attrs | ||
| 557 | + (const union usbg_f_net_attr_val *) | ||
| 558 | + ((const char *)attrs | ||
| 559 | + net_attr[i].offset)); | ||
| 560 | if (ret) | ||
| 561 | break; | ||
| 562 | @@ -277,12 +277,12 @@ int usbg_f_net_get_attr_val(usbg_f_net *nf, enum usbg_f_net_attr attr, | ||
| 563 | } | ||
| 564 | |||
| 565 | int usbg_f_net_set_attr_val(usbg_f_net *nf, enum usbg_f_net_attr attr, | ||
| 566 | - union usbg_f_net_attr_val val) | ||
| 567 | + const union usbg_f_net_attr_val *val) | ||
| 568 | { | ||
| 569 | return net_attr[attr].ro ? | ||
| 570 | USBG_ERROR_INVALID_PARAM : | ||
| 571 | net_attr[attr].set(nf->func.path, nf->func.name, | ||
| 572 | - net_attr[attr].name, &val); | ||
| 573 | + net_attr[attr].name, val); | ||
| 574 | } | ||
| 575 | |||
| 576 | int usbg_f_net_get_ifname_s(usbg_f_net *nf, char *buf, int len) | ||
| 577 | diff --git a/src/function/hid.c b/src/function/hid.c | ||
| 578 | index 4d075cf..895c2c6 100644 | ||
| 579 | --- a/src/function/hid.c | ||
| 580 | +++ b/src/function/hid.c | ||
| 581 | @@ -69,9 +69,9 @@ static int hid_get_report(const char *path, const char *name, const char *attr, | ||
| 582 | } | ||
| 583 | |||
| 584 | static int hid_set_report(const char *path, const char *name, const char *attr, | ||
| 585 | - void *val) | ||
| 586 | + const void *val) | ||
| 587 | { | ||
| 588 | - struct usbg_f_hid_report_desc *report_desc = val; | ||
| 589 | + const struct usbg_f_hid_report_desc *report_desc = val; | ||
| 590 | char *buf = report_desc->desc; | ||
| 591 | int len = report_desc->len; | ||
| 592 | int ret; | ||
| 593 | @@ -239,7 +239,7 @@ static int hid_libconfig_import(struct usbg_function *f, | ||
| 594 | if (ret < 0) | ||
| 595 | break; | ||
| 596 | |||
| 597 | - ret = usbg_f_hid_set_attr_val(hf, i, val); | ||
| 598 | + ret = usbg_f_hid_set_attr_val(hf, i, &val); | ||
| 599 | if (ret) | ||
| 600 | break; | ||
| 601 | } | ||
| 602 | @@ -327,7 +327,7 @@ int usbg_f_hid_set_attrs(usbg_f_hid *hf, | ||
| 603 | continue; | ||
| 604 | |||
| 605 | ret = usbg_f_hid_set_attr_val(hf, i, | ||
| 606 | - *(union usbg_f_hid_attr_val *) | ||
| 607 | + (union usbg_f_hid_attr_val *) | ||
| 608 | ((char *)attrs | ||
| 609 | + hid_attr[i].offset)); | ||
| 610 | if (ret) | ||
| 611 | @@ -346,11 +346,11 @@ int usbg_f_hid_get_attr_val(usbg_f_hid *hf, enum usbg_f_hid_attr attr, | ||
| 612 | } | ||
| 613 | |||
| 614 | int usbg_f_hid_set_attr_val(usbg_f_hid *hf, enum usbg_f_hid_attr attr, | ||
| 615 | - union usbg_f_hid_attr_val val) | ||
| 616 | + const union usbg_f_hid_attr_val *val) | ||
| 617 | { | ||
| 618 | return hid_attr[attr].ro ? | ||
| 619 | USBG_ERROR_INVALID_PARAM : | ||
| 620 | hid_attr[attr].set(hf->func.path, hf->func.name, | ||
| 621 | - hid_attr[attr].name, &val); | ||
| 622 | + hid_attr[attr].name, val); | ||
| 623 | } | ||
| 624 | |||
| 625 | diff --git a/src/function/midi.c b/src/function/midi.c | ||
| 626 | index 1cedb97..2318b49 100644 | ||
| 627 | --- a/src/function/midi.c | ||
| 628 | +++ b/src/function/midi.c | ||
| 629 | @@ -100,7 +100,7 @@ static int midi_libconfig_import(struct usbg_function *f, | ||
| 630 | if (ret < 0) | ||
| 631 | break; | ||
| 632 | |||
| 633 | - ret = usbg_f_midi_set_attr_val(mf, i, val); | ||
| 634 | + ret = usbg_f_midi_set_attr_val(mf, i, &val); | ||
| 635 | if (ret) | ||
| 636 | break; | ||
| 637 | } | ||
| 638 | @@ -185,8 +185,8 @@ int usbg_f_midi_set_attrs(usbg_f_midi *mf, | ||
| 639 | |||
| 640 | for (i = USBG_F_MIDI_ATTR_MIN; i < USBG_F_MIDI_ATTR_MAX; ++i) { | ||
| 641 | ret = usbg_f_midi_set_attr_val(mf, i, | ||
| 642 | - *(union usbg_f_midi_attr_val *) | ||
| 643 | - ((char *)attrs | ||
| 644 | + (const union usbg_f_midi_attr_val *) | ||
| 645 | + ((const char *)attrs | ||
| 646 | + midi_attr[i].offset)); | ||
| 647 | if (ret) | ||
| 648 | break; | ||
| 649 | @@ -204,10 +204,10 @@ int usbg_f_midi_get_attr_val(usbg_f_midi *mf, enum usbg_f_midi_attr attr, | ||
| 650 | } | ||
| 651 | |||
| 652 | int usbg_f_midi_set_attr_val(usbg_f_midi *mf, enum usbg_f_midi_attr attr, | ||
| 653 | - union usbg_f_midi_attr_val val) | ||
| 654 | + const union usbg_f_midi_attr_val *val) | ||
| 655 | { | ||
| 656 | return midi_attr[attr].set(mf->func.path, mf->func.name, | ||
| 657 | - midi_attr[attr].name, &val); | ||
| 658 | + midi_attr[attr].name, val); | ||
| 659 | } | ||
| 660 | |||
| 661 | int usbg_f_midi_get_id_s(usbg_f_midi *mf, char *buf, int len) | ||
| 662 | diff --git a/src/function/ms.c b/src/function/ms.c | ||
| 663 | index 519b012..5cdd814 100644 | ||
| 664 | --- a/src/function/ms.c | ||
| 665 | +++ b/src/function/ms.c | ||
| 666 | @@ -207,7 +207,7 @@ static int ms_import_lun_attrs(struct usbg_f_ms *mf, int lun_id, | ||
| 667 | if (ret < 0) | ||
| 668 | break; | ||
| 669 | |||
| 670 | - ret = usbg_f_ms_set_lun_attr_val(mf, lun_id, i, val); | ||
| 671 | + ret = usbg_f_ms_set_lun_attr_val(mf, lun_id, i, &val); | ||
| 672 | if (ret) | ||
| 673 | break; | ||
| 674 | } | ||
| 675 | @@ -605,8 +605,8 @@ int usbg_f_ms_set_lun_attrs(usbg_f_ms *mf, int lun_id, | ||
| 676 | |||
| 677 | for (i = USBG_F_MS_LUN_ATTR_MIN; i < USBG_F_MS_LUN_ATTR_MAX; ++i) { | ||
| 678 | ret = usbg_f_ms_set_lun_attr_val(mf, lun_id, i, | ||
| 679 | - *(union usbg_f_ms_lun_attr_val *) | ||
| 680 | - ((char *)lattrs | ||
| 681 | + (const union usbg_f_ms_lun_attr_val *) | ||
| 682 | + ((const char *)lattrs | ||
| 683 | + ms_lun_attr[i].offset)); | ||
| 684 | if (ret) | ||
| 685 | break; | ||
| 686 | @@ -633,7 +633,7 @@ int usbg_f_ms_get_lun_attr_val(usbg_f_ms *mf, int lun_id, | ||
| 687 | |||
| 688 | int usbg_f_ms_set_lun_attr_val(usbg_f_ms *mf, int lun_id, | ||
| 689 | enum usbg_f_ms_lun_attr lattr, | ||
| 690 | - union usbg_f_ms_lun_attr_val val) | ||
| 691 | + const union usbg_f_ms_lun_attr_val *val) | ||
| 692 | { | ||
| 693 | char lpath[USBG_MAX_PATH_LENGTH]; | ||
| 694 | int ret; | ||
| 695 | @@ -644,7 +644,7 @@ int usbg_f_ms_set_lun_attr_val(usbg_f_ms *mf, int lun_id, | ||
| 696 | return USBG_ERROR_PATH_TOO_LONG; | ||
| 697 | |||
| 698 | return ms_lun_attr[lattr].set(lpath, "", | ||
| 699 | - ms_lun_attr[lattr].name, &val); | ||
| 700 | + ms_lun_attr[lattr].name, val); | ||
| 701 | } | ||
| 702 | |||
| 703 | int usbg_f_ms_get_lun_file_s(usbg_f_ms *mf, int lun_id, | ||
| 704 | diff --git a/src/function/uac2.c b/src/function/uac2.c | ||
| 705 | index f2c1a49..38a9b0f 100644 | ||
| 706 | --- a/src/function/uac2.c | ||
| 707 | +++ b/src/function/uac2.c | ||
| 708 | @@ -89,7 +89,7 @@ static int uac2_libconfig_import(struct usbg_function *f, | ||
| 709 | if (ret < 0) | ||
| 710 | break; | ||
| 711 | |||
| 712 | - ret = usbg_f_uac2_set_attr_val(af, i, val); | ||
| 713 | + ret = usbg_f_uac2_set_attr_val(af, i, &val); | ||
| 714 | if (ret) | ||
| 715 | break; | ||
| 716 | } | ||
| 717 | @@ -174,8 +174,8 @@ int usbg_f_uac2_set_attrs(usbg_f_uac2 *af, | ||
| 718 | |||
| 719 | for (i = USBG_F_UAC2_ATTR_MIN; i < USBG_F_UAC2_ATTR_MAX; ++i) { | ||
| 720 | ret = usbg_f_uac2_set_attr_val(af, i, | ||
| 721 | - *(union usbg_f_uac2_attr_val *) | ||
| 722 | - ((char *)attrs | ||
| 723 | + (const union usbg_f_uac2_attr_val *) | ||
| 724 | + ((const char *)attrs | ||
| 725 | + uac2_attr[i].offset)); | ||
| 726 | if (ret) | ||
| 727 | break; | ||
| 728 | @@ -193,8 +193,8 @@ int usbg_f_uac2_get_attr_val(usbg_f_uac2 *af, enum usbg_f_uac2_attr attr, | ||
| 729 | } | ||
| 730 | |||
| 731 | int usbg_f_uac2_set_attr_val(usbg_f_uac2 *af, enum usbg_f_uac2_attr attr, | ||
| 732 | - union usbg_f_uac2_attr_val val) | ||
| 733 | + const union usbg_f_uac2_attr_val *val) | ||
| 734 | { | ||
| 735 | return uac2_attr[attr].set(af->func.path, af->func.name, | ||
| 736 | - uac2_attr[attr].name, &val); | ||
| 737 | + uac2_attr[attr].name, val); | ||
| 738 | } | ||
| 739 | diff --git a/src/function/uvc.c b/src/function/uvc.c | ||
| 740 | index f39594b..947b94e 100644 | ||
| 741 | --- a/src/function/uvc.c | ||
| 742 | +++ b/src/function/uvc.c | ||
| 743 | @@ -303,7 +303,7 @@ int usbg_f_uvc_get_config_attr_val(usbg_f_uvc *uvcf, enum usbg_f_uvc_config_attr | ||
| 744 | } | ||
| 745 | |||
| 746 | int usbg_f_uvc_set_config_attr_val(usbg_f_uvc *uvcf, enum usbg_f_uvc_config_attr iattr, | ||
| 747 | - union usbg_f_uvc_config_attr_val val) | ||
| 748 | + const union usbg_f_uvc_config_attr_val *val) | ||
| 749 | { | ||
| 750 | char ipath[USBG_MAX_PATH_LENGTH]; | ||
| 751 | int nmb; | ||
| 752 | @@ -314,7 +314,7 @@ int usbg_f_uvc_set_config_attr_val(usbg_f_uvc *uvcf, enum usbg_f_uvc_config_attr | ||
| 753 | return USBG_ERROR_PATH_TOO_LONG; | ||
| 754 | |||
| 755 | return uvc_config_attr[iattr].set(ipath, "", | ||
| 756 | - uvc_config_attr[iattr].name, &val); | ||
| 757 | + uvc_config_attr[iattr].name, val); | ||
| 758 | } | ||
| 759 | |||
| 760 | int usbg_f_uvc_get_config_attrs(usbg_f_uvc *uvcf, struct usbg_f_uvc_config_attrs *iattrs) | ||
| 761 | @@ -341,8 +341,8 @@ int usbg_f_uvc_set_config_attrs(usbg_f_uvc *uvcf, const struct usbg_f_uvc_config | ||
| 762 | |||
| 763 | for (i = USBG_F_UVC_FRAME_ATTR_MIN; i < USBG_F_UVC_FRAME_ATTR_MAX; ++i) { | ||
| 764 | ret = usbg_f_uvc_set_config_attr_val(uvcf, i, | ||
| 765 | - *(union usbg_f_uvc_config_attr_val *) | ||
| 766 | - ((char *)iattrs | ||
| 767 | + (const union usbg_f_uvc_config_attr_val *) | ||
| 768 | + ((const char *)iattrs | ||
| 769 | + uvc_config_attr[i].offset)); | ||
| 770 | if (ret) | ||
| 771 | break; | ||
| 772 | @@ -774,7 +774,7 @@ static int uvc_import_config(struct usbg_f_uvc *uvcf, config_setting_t *root) | ||
| 773 | if (ret < 0) | ||
| 774 | break; | ||
| 775 | |||
| 776 | - ret = usbg_f_uvc_set_config_attr_val(uvcf, i, val); | ||
| 777 | + ret = usbg_f_uvc_set_config_attr_val(uvcf, i, &val); | ||
| 778 | if (ret) | ||
| 779 | break; | ||
| 780 | } | ||
| 781 | diff --git a/src/usbg_common.c b/src/usbg_common.c | ||
| 782 | index 5f7f4e5..7234649 100644 | ||
| 783 | --- a/src/usbg_common.c | ||
| 784 | +++ b/src/usbg_common.c | ||
| 785 | @@ -337,7 +337,7 @@ int usbg_get_ether_addr(const char *path, const char *name, | ||
| 786 | } | ||
| 787 | |||
| 788 | int usbg_set_ether_addr(const char *path, const char *name, | ||
| 789 | - const char *attr, void *val) | ||
| 790 | + const char *attr, const void *val) | ||
| 791 | { | ||
| 792 | char str_addr[USBG_MAX_STR_LENGTH]; | ||
| 793 | |||
| 794 | -- | ||
| 795 | 2.25.1 | ||
| 796 | |||
diff --git a/meta-oe/recipes-support/libusbgx/libusbgx/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch b/meta-oe/recipes-support/libusbgx/libusbgx/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch new file mode 100644 index 0000000000..cc122c844c --- /dev/null +++ b/meta-oe/recipes-support/libusbgx/libusbgx/0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | From 4f3f2ad08e6ca132bd1dd388e02b57223bf4219d Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Ming Liu <liu.ming50@gmail.com> | ||
| 3 | Date: Sun, 11 Dec 2022 14:11:49 +0100 | ||
| 4 | Subject: [PATCH] libusbgx: Add interface name for NCM Feature Descriptors | ||
| 5 | |||
| 6 | In commit: abf422bffca4a4767e7e242c44910dbf5ef7094f | ||
| 7 | [ | ||
| 8 | Author: Stefan Agner <stefan.agner@toradex.com> | ||
| 9 | Date: Tue Jan 24 14:22:25 2017 -0800 | ||
| 10 | |||
| 11 | libusbgx: Add interface name for Feature Descriptors | ||
| 12 | |||
| 13 | This adds interface name required for "Feature Descriptors". If | ||
| 14 | specified, we can assume that a Feature Descriptor with the | ||
| 15 | interface name of the specified string is understood by the | ||
| 16 | kernel (e.g. interface.rndis). | ||
| 17 | ] | ||
| 18 | |||
| 19 | it only added Feature Descriptors for RNDIS, NCM also needs that, or | ||
| 20 | else it could not be recognized by Windows systems. | ||
| 21 | |||
| 22 | Add Feature Descriptors interface name for NCM. | ||
| 23 | |||
| 24 | Upstream-Status: Submitted [https://github.com/linux-usb-gadgets/libusbgx/pull/73] | ||
| 25 | |||
| 26 | Signed-off-by: Ming Liu <liu.ming50@gmail.com> | ||
| 27 | --- | ||
| 28 | src/function/ether.c | 6 ++++++ | ||
| 29 | 1 file changed, 6 insertions(+) | ||
| 30 | |||
| 31 | diff --git a/src/function/ether.c b/src/function/ether.c | ||
| 32 | index b1fe1d2..a9eaf33 100644 | ||
| 33 | --- a/src/function/ether.c | ||
| 34 | +++ b/src/function/ether.c | ||
| 35 | @@ -184,8 +184,14 @@ struct usbg_function_type usbg_f_type_subset = { | ||
| 36 | ETHER_FUNCTION_OPTS | ||
| 37 | }; | ||
| 38 | |||
| 39 | +static char *ncm_os_desc_ifnames[] = { | ||
| 40 | + "ncm", | ||
| 41 | + NULL | ||
| 42 | +}; | ||
| 43 | + | ||
| 44 | struct usbg_function_type usbg_f_type_ncm = { | ||
| 45 | .name = "ncm", | ||
| 46 | + .os_desc_iname = ncm_os_desc_ifnames, | ||
| 47 | ETHER_FUNCTION_OPTS | ||
| 48 | }; | ||
| 49 | |||
| 50 | -- | ||
| 51 | 2.25.1 | ||
| 52 | |||
diff --git a/meta-oe/recipes-support/libusbgx/libusbgx_git.bb b/meta-oe/recipes-support/libusbgx/libusbgx_git.bb index 11e88935ef..66a5a40717 100644 --- a/meta-oe/recipes-support/libusbgx/libusbgx_git.bb +++ b/meta-oe/recipes-support/libusbgx/libusbgx_git.bb | |||
| @@ -6,10 +6,12 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \ | |||
| 6 | inherit autotools pkgconfig systemd update-rc.d update-alternatives | 6 | inherit autotools pkgconfig systemd update-rc.d update-alternatives |
| 7 | 7 | ||
| 8 | PV = "0.2.0+git${SRCPV}" | 8 | PV = "0.2.0+git${SRCPV}" |
| 9 | SRCREV = "45c14ef4d5d7ced0fbf984208de44ced6d5ed898" | 9 | SRCREV = "721e3a1cbd7e2b6361bb439d3959e7403e4f0092" |
| 10 | SRCBRANCH = "master" | 10 | SRCBRANCH = "master" |
| 11 | SRC_URI = " \ | 11 | SRC_URI = " \ |
| 12 | git://github.com/libusbgx/libusbgx.git;branch=${SRCBRANCH};protocol=https \ | 12 | git://github.com/libusbgx/libusbgx.git;branch=${SRCBRANCH};protocol=https \ |
| 13 | file://0001-libusbgx-Add-interface-name-for-NCM-Feature-Descript.patch \ | ||
| 14 | file://0001-fix-stack-buffer-overflow-in-usbg_f_foo_attr_val-pro.patch \ | ||
| 13 | file://gadget-start \ | 15 | file://gadget-start \ |
| 14 | file://usbgx.initd \ | 16 | file://usbgx.initd \ |
| 15 | file://usbgx.service \ | 17 | file://usbgx.service \ |
