def filter_by_hardware_interface(ctrl_list,
                                 hardware_interface,
                                 match_substring=False):
    """
    Filter controller state list by controller hardware interface.

    @param ctrl_list: Controller state list
    @type ctrl_list: [controller_manager_msgs/ControllerState]
    @param hardware_interface: Controller hardware interface
    @type hardware_interface: str
    @param match_substring: Set to True to allow substring matching
    @type match_substring: bool
    @return: Controllers matching the specified hardware interface
    @rtype: [controller_manager_msgs/ControllerState]
    """
    list_out = []
    for ctrl in ctrl_list:
        for resource_set in ctrl.claimed_resources:
            if match_substring:
                if hardware_interface in resource_set.hardware_interface:
                    list_out.append(ctrl)
                    break
            else:
                if resource_set.hardware_interface == hardware_interface:
                    list_out.append(ctrl)
                    break
    return list_out