@@ -205,15 +205,42 @@ UX_SLAVE_CLASS_HID *hid;
205205
206206 case UX_DEVICE_CLASS_HID_COMMAND_GET_PROTOCOL :
207207
208- /* Send the protocol. */
208+ /* Only boot subclass devices should respond to GET_PROTOCOL. */
209+ if ((hid -> ux_slave_class_hid_interface == UX_NULL ) ||
210+ (hid -> ux_slave_class_hid_interface -> ux_slave_interface_descriptor .bInterfaceSubClass != 0x01 ))
211+ {
212+ return (UX_ERROR );
213+ }
214+
215+ /* Send the protocol to host. */
209216 * transfer_request -> ux_slave_transfer_request_data_pointer = (UCHAR )hid -> ux_device_class_hid_protocol ;
210217 _ux_device_stack_transfer_request (transfer_request , 1 , request_length );
211218 break ;
212219
213220 case UX_DEVICE_CLASS_HID_COMMAND_SET_PROTOCOL :
214221
222+ /* Check protocol must be 0 (Boot) or 1 (Report). */
223+ if ((request_value != UX_DEVICE_CLASS_HID_PROTOCOL_BOOT ) &&
224+ (request_value != UX_DEVICE_CLASS_HID_PROTOCOL_REPORT ))
225+ {
226+ /* Invalid value: not handled. */
227+ return (UX_ERROR );
228+ }
229+
230+ /* Only boot subclass devices should respond to SET_PROTOCOL. */
231+ if ((hid -> ux_slave_class_hid_interface == UX_NULL ) ||
232+ (hid -> ux_slave_class_hid_interface -> ux_slave_interface_descriptor .bInterfaceSubClass != 0x01 ))
233+ {
234+ return (UX_ERROR );
235+ }
236+
215237 /* Accept the protocol. */
216238 hid -> ux_device_class_hid_protocol = request_value ;
239+
240+ /* If there is a callback defined by the application, send the protocol to it. */
241+ if (hid -> ux_device_class_hid_set_protocol_callback != UX_NULL )
242+ hid -> ux_device_class_hid_set_protocol_callback (hid , request_value );
243+
217244 break ;
218245
219246 default :
@@ -225,4 +252,3 @@ UX_SLAVE_CLASS_HID *hid;
225252 /* It's handled. */
226253 return (UX_SUCCESS );
227254}
228-
0 commit comments