@@ -154,18 +154,20 @@ void function::control_setup_request(message& msg, const config::interface& ifac
154154 (type == report::type::FEATURE ) or (type == report::type::OUTPUT ))
155155 {
156156 auto & buffer = rx_buffers_[type];
157- // prefer the application provided buffer
158- if (buffer.size () >= msg.request ().wLength )
157+ // if the OUT endpoint is available, the app buffer is dedicated to receiving through it
158+ bool allow_app_buffer =
159+ (type == report::type::FEATURE ) or (not ep_out_handle ().valid ());
160+
161+ // the application provided buffer is preferred
162+ if ((buffer.size () >= msg.request ().wLength ) and allow_app_buffer)
159163 {
160164 return msg.receive_data (buffer);
161165 }
162- #if 0
163- // fall back to generic control buffer
164- else if (msg.buffer().max_size() >= msg.request().wLength)
166+ if (msg.buffer ().max_size () >= msg.request ().wLength )
165167 {
168+ // otherwise use the control transfer buffer
166169 return msg.receive_to_buffer ();
167170 }
168- #endif
169171 }
170172 return msg.reject ();
171173
@@ -220,7 +222,11 @@ void function::control_data_complete(message& msg, [[maybe_unused]] const config
220222 case SET_REPORT :
221223 {
222224 auto type = static_cast <report::type>(msg.request ().wValue .high_byte ());
223- rx_buffers_[type] = {};
225+ auto data = msg.data ().to_span ();
226+ if (data.data () == rx_buffers_[type].data ())
227+ {
228+ rx_buffers_[type] = {};
229+ }
224230 session_->set_report (type, msg.data ().to_span ());
225231 break ;
226232 }
0 commit comments