staticint hid_ignore_special_drivers = 0;
module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
MODULE_PARM_DESC(ignore_special_drivers, "Ignore any special drivers and handle all devices by generic driver");
/* * Convert a signed n-bit integer to signed 32-bit integer.
*/
for (n = parser->collection_stack_ptr - 1; n >= 0; n--) { unsigned index = parser->collection_stack[n]; if (collection[index].type == type) return collection[index].usage;
} return 0; /* we know nothing about this usage type */
}
/* * Concatenate usage which defines 16 bits or less with the * currently defined usage page to form a 32 bit usage
*/
/* * If Usage item only includes usage id, concatenate it with * currently defined usage page
*/ if (size <= 2)
complete_usage(parser, parser->local.usage_index);
if (parser->device->ll_driver->max_buffer_size)
max_buffer_size = parser->device->ll_driver->max_buffer_size;
/* Total size check: Allow for possible report index byte */ if (report->size > (max_buffer_size - 1) << 3) {
hid_err(parser->device, "report is too long\n"); return -1;
}
if (!parser->local.usage_index) /* Ignore padding fields */ return 0;
for (i = 0; i < usages; i++) { unsigned j = i; /* Duplicate the last usage we parsed if we have excess values */ if (i >= parser->local.usage_index)
j = parser->local.usage_index - 1;
field->usage[i].hid = parser->local.usage[j];
field->usage[i].collection_index =
parser->local.collection_index[j];
field->usage[i].usage_index = i;
field->usage[i].resolution_multiplier = 1;
}
case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
parser->global.usage_page = item_udata(item); return 0;
case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
parser->global.logical_minimum = item_sdata(item); return 0;
case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: if (parser->global.logical_minimum < 0)
parser->global.logical_maximum = item_sdata(item); else
parser->global.logical_maximum = item_udata(item); return 0;
case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
parser->global.physical_minimum = item_sdata(item); return 0;
case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: if (parser->global.physical_minimum < 0)
parser->global.physical_maximum = item_sdata(item); else
parser->global.physical_maximum = item_udata(item); return 0;
case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: /* Many devices provide unit exponent as a two's complement * nibble due to the common misunderstanding of HID * specification 1.11, 6.2.2.7 Global Items. Attempt to handle
* both this and the standard encoding. */
raw_value = item_sdata(item); if (!(raw_value & 0xfffffff0))
parser->global.unit_exponent = snto32(raw_value, 4); else
parser->global.unit_exponent = raw_value; return 0;
case HID_GLOBAL_ITEM_TAG_UNIT:
parser->global.unit = item_udata(item); return 0;
case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
parser->global.report_size = item_udata(item); if (parser->global.report_size > 256) {
hid_err(parser->device, "invalid report_size %d\n",
parser->global.report_size); return -1;
} return 0;
case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
parser->global.report_count = item_udata(item); if (parser->global.report_count > HID_MAX_USAGES) {
hid_err(parser->device, "invalid report_count %d\n",
parser->global.report_count); return -1;
} return 0;
case HID_GLOBAL_ITEM_TAG_REPORT_ID:
parser->global.report_id = item_udata(item); if (parser->global.report_id == 0 ||
parser->global.report_id >= HID_MAX_IDS) {
hid_err(parser->device, "report_id %u is invalid\n",
parser->global.report_id); return -1;
} return 0;
default:
hid_err(parser->device, "unknown global tag 0x%x\n", item->tag); return -1;
}
}
switch (item->tag) { case HID_LOCAL_ITEM_TAG_DELIMITER:
if (data) { /* * We treat items before the first delimiter * as global to all usage sets (branch 0). * In the moment we process only these global * items and the first delimiter set.
*/ if (parser->local.delimiter_depth != 0) {
hid_err(parser->device, "nested delimiters\n"); return -1;
}
parser->local.delimiter_depth++;
parser->local.delimiter_branch++;
} else { if (parser->local.delimiter_depth < 1) {
hid_err(parser->device, "bogus close delimiter\n"); return -1;
}
parser->local.delimiter_depth--;
} return 0;
count = data - parser->local.usage_minimum; if (count + parser->local.usage_index >= HID_MAX_USAGES) { /* * We do not warn if the name is not set, we are * actually pre-scanning the device.
*/ if (dev_name(&parser->device->dev))
hid_warn(parser->device, "ignoring exceeding usage max\n");
data = HID_MAX_USAGES - parser->local.usage_index +
parser->local.usage_minimum - 1; if (data <= 0) {
hid_err(parser->device, "no more usage index available\n"); return -1;
}
}
for (n = parser->local.usage_minimum; n <= data; n++) if (hid_add_usage(parser, n, item->size)) {
dbg_hid("hid_add_usage failed\n"); return -1;
} return 0;
default:
dbg_hid("unknown local item tag 0x%x\n", item->tag); return 0;
} return 0;
}
/* * Concatenate Usage Pages into Usages where relevant: * As per specification, 6.2.2.8: "When the parser encounters a main item it * concatenates the last declared Usage Page with a Usage to form a complete * usage value."
*/
/* * Concatenate usage page again only if last declared Usage Page * has not been already used in previous usages concatenation
*/ for (i = parser->local.usage_index - 1; i >= 0; i--) { if (parser->local.usage_size[i] > 2) /* Ignore extended usages */ continue;
current_page = parser->local.usage[i] >> 16; if (current_page == usage_page) break;
switch (item->tag) { case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
ret = open_collection(parser, data & 0xff); break; case HID_MAIN_ITEM_TAG_END_COLLECTION:
ret = close_collection(parser); break; case HID_MAIN_ITEM_TAG_INPUT:
ret = hid_add_field(parser, HID_INPUT_REPORT, data); break; case HID_MAIN_ITEM_TAG_OUTPUT:
ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); break; case HID_MAIN_ITEM_TAG_FEATURE:
ret = hid_add_field(parser, HID_FEATURE_REPORT, data); break; default: if (item->tag >= HID_MAIN_ITEM_TAG_RESERVED_MIN &&
item->tag <= HID_MAIN_ITEM_TAG_RESERVED_MAX)
hid_warn_ratelimited(parser->device, "reserved main item tag 0x%x\n", item->tag); else
hid_warn_ratelimited(parser->device, "unknown main item tag 0x%x\n", item->tag);
ret = 0;
}
memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
/* * Free a report and all registered fields. The field->usage and * field->value table's are allocated behind the field, so we need * only to free(field) itself.
*/
for (n = 0; n < report->maxfield; n++)
kvfree(report->field[n]);
kfree(report);
}
/* * Close report. This function returns the device * state to the point prior to hid_open_report().
*/ staticvoid hid_close_report(struct hid_device *device)
{ unsigned i, j;
for (i = 0; i < HID_REPORT_TYPES; i++) { struct hid_report_enum *report_enum = device->report_enum + i;
/* * If the HID driver had a rdesc_fixup() callback, dev->rdesc * will be allocated by hid-core and needs to be freed. * Otherwise, it is either equal to dev_rdesc or bpf_rdesc, in * which cases it'll be freed later on device removal or destroy.
*/ if (device->rdesc != device->dev_rdesc && device->rdesc != device->bpf_rdesc)
kfree(device->rdesc);
device->rdesc = NULL;
device->rsize = 0;
staticinlinevoid hid_free_bpf_rdesc(struct hid_device *hdev)
{ /* bpf_rdesc is either equal to dev_rdesc or allocated by call_hid_bpf_rdesc_fixup() */ if (hdev->bpf_rdesc != hdev->dev_rdesc)
kfree(hdev->bpf_rdesc);
hdev->bpf_rdesc = NULL;
}
/* * Free a device structure, all reports, and all fields.
*/
if ((parser->global.usage_page << 16) == HID_UP_GENDESK) for (i = 0; i < parser->local.usage_index; i++) if (parser->local.usage[i] == HID_GD_POINTER)
parser->scan_flags |= HID_SCAN_FLAG_GD_POINTER;
if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
if ((parser->global.usage_page << 16) == HID_UP_GOOGLEVENDOR) for (i = 0; i < parser->local.usage_index; i++) if (parser->local.usage[i] ==
(HID_UP_GOOGLEVENDOR | 0x0001))
parser->device->group =
HID_GROUP_VIVALDI;
}
switch (item->tag) { case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
hid_scan_collection(parser, data & 0xff); break; case HID_MAIN_ITEM_TAG_END_COLLECTION: break; case HID_MAIN_ITEM_TAG_INPUT: /* ignore constant inputs, they will be ignored by hid-input */ if (data & HID_MAIN_ITEM_CONSTANT) break; for (i = 0; i < parser->local.usage_index; i++)
hid_scan_input_usage(parser, parser->local.usage[i]); break; case HID_MAIN_ITEM_TAG_OUTPUT: break; case HID_MAIN_ITEM_TAG_FEATURE: for (i = 0; i < parser->local.usage_index; i++)
hid_scan_feature_usage(parser, parser->local.usage[i]); break;
}
/* Reset the local parser environment */
memset(&parser->local, 0, sizeof(parser->local));
return 0;
}
/* * Scan a report descriptor before the device is added to the bus. * Sets device groups and other properties that determine what driver * to load.
*/ staticint hid_scan_report(struct hid_device *hid)
{ struct hid_parser *parser; struct hid_item item; const __u8 *start = hid->dev_rdesc; const __u8 *end = start + hid->dev_rsize; staticint (*dispatch_type[])(struct hid_parser *parser, struct hid_item *item) = {
hid_scan_main,
hid_parser_global,
hid_parser_local,
hid_parser_reserved
};
parser = vzalloc(sizeof(struct hid_parser)); if (!parser) return -ENOMEM;
/* * The parsing is simpler than the one in hid_open_report() as we should * be robust against hid errors. Those errors will be raised by * hid_open_report() anyway.
*/ while ((start = fetch_item(start, end, &item)) != NULL)
dispatch_type[item.type](parser, &item);
/* * Handle special flags set during scanning.
*/ if ((parser->scan_flags & HID_SCAN_FLAG_MT_WIN_8) &&
(hid->group == HID_GROUP_MULTITOUCH))
hid->group = HID_GROUP_MULTITOUCH_WIN_8;
/* * Vendor specific handlings
*/ switch (hid->vendor) { case USB_VENDOR_ID_WACOM:
hid->group = HID_GROUP_WACOM; break; case USB_VENDOR_ID_SYNAPTICS: if (hid->group == HID_GROUP_GENERIC) if ((parser->scan_flags & HID_SCAN_FLAG_VENDOR_SPECIFIC)
&& (parser->scan_flags & HID_SCAN_FLAG_GD_POINTER)) /* * hid-rmi should take care of them, * not hid-generic
*/
hid->group = HID_GROUP_RMI; break;
}
/** * hid_parse_report - parse device report * * @hid: hid device * @start: report start * @size: report size * * Allocate the device report as read by the bus driver. This function should * only be called from parse() in ll drivers.
*/ int hid_parse_report(struct hid_device *hid, const __u8 *start, unsigned size)
{
hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL); if (!hid->dev_rdesc) return -ENOMEM;
hid->dev_rsize = size; return 0;
}
EXPORT_SYMBOL_GPL(hid_parse_report);
staticconstchar * const hid_report_names[] = { "HID_INPUT_REPORT", "HID_OUTPUT_REPORT", "HID_FEATURE_REPORT",
}; /** * hid_validate_values - validate existing device report's value indexes * * @hid: hid device * @type: which report type to examine * @id: which report ID to examine (0 for first) * @field_index: which report field to examine * @report_counts: expected number of values * * Validate the number of values in a given field of a given report, after * parsing.
*/ struct hid_report *hid_validate_values(struct hid_device *hid, enum hid_report_type type, unsignedint id, unsignedint field_index, unsignedint report_counts)
{ struct hid_report *report;
if (type > HID_FEATURE_REPORT) {
hid_err(hid, "invalid HID report type %u\n", type); return NULL;
}
if (id >= HID_MAX_IDS) {
hid_err(hid, "invalid HID report id %u\n", id); return NULL;
}
/* * Explicitly not using hid_get_report() here since it depends on * ->numbered being checked, which may not always be the case when * drivers go to access report values.
*/ if (id == 0) { /* * Validating on id 0 means we should examine the first * report in the list.
*/
report = list_first_entry_or_null(
&hid->report_enum[type].report_list, struct hid_report, list);
} else {
report = hid->report_enum[type].report_id_hash[id];
} if (!report) {
hid_err(hid, "missing %s %u\n", hid_report_names[type], id); return NULL;
} if (report->maxfield <= field_index) {
hid_err(hid, "not enough fields in %s %u\n",
hid_report_names[type], id); return NULL;
} if (report->field[field_index]->report_count < report_counts) {
hid_err(hid, "not enough values in %s %u field %u\n",
hid_report_names[type], id, field_index); return NULL;
} return report;
}
EXPORT_SYMBOL_GPL(hid_validate_values);
staticint hid_calculate_multiplier(struct hid_device *hid, struct hid_field *multiplier)
{ int m;
__s32 v = *multiplier->value;
__s32 lmin = multiplier->logical_minimum;
__s32 lmax = multiplier->logical_maximum;
__s32 pmin = multiplier->physical_minimum;
__s32 pmax = multiplier->physical_maximum;
/* * "Because OS implementations will generally divide the control's * reported count by the Effective Resolution Multiplier, designers * should take care not to establish a potential Effective * Resolution Multiplier of zero." * HID Usage Table, v1.12, Section 4.3.1, p31
*/ if (lmax - lmin == 0) return 1; /* * Handling the unit exponent is left as an exercise to whoever * finds a device where that exponent is not 0.
*/
m = ((v - lmin)/(lmax - lmin) * (pmax - pmin) + pmin); if (unlikely(multiplier->unit_exponent != 0)) {
hid_warn(hid, "unsupported Resolution Multiplier unit exponent %d\n",
multiplier->unit_exponent);
}
/* There are no devices with an effective multiplier > 255 */ if (unlikely(m == 0 || m > 255 || m < -255)) {
hid_warn(hid, "unsupported Resolution Multiplier %d\n", m);
m = 1;
}
/* * If multiplier_collection is NULL, the multiplier applies * to all fields in the report. * Otherwise, it is the Logical Collection the multiplier applies to * but our field may be in a subcollection of that collection.
*/ for (i = 0; i < field->maxusage; i++) {
usage = &field->usage[i];
/* * "The Resolution Multiplier control must be contained in the same * Logical Collection as the control(s) to which it is to be applied. * If no Resolution Multiplier is defined, then the Resolution * Multiplier defaults to 1. If more than one control exists in a * Logical Collection, the Resolution Multiplier is associated with * all controls in the collection. If no Logical Collection is * defined, the Resolution Multiplier is associated with all * controls in the report." * HID Usage Table, v1.12, Section 4.3.1, p30 * * Thus, search from the current collection upwards until we find a * logical collection. Then search all fields for that same parent * collection. Those are the fields the multiplier applies to. * * If we have more than one multiplier, it will overwrite the * applicable fields later.
*/
multiplier_collection = &hid->collection[multiplier->usage->collection_index]; while (multiplier_collection->parent_idx != -1 &&
multiplier_collection->type != HID_COLLECTION_LOGICAL)
multiplier_collection = &hid->collection[multiplier_collection->parent_idx]; if (multiplier_collection->type != HID_COLLECTION_LOGICAL)
multiplier_collection = NULL;
rep_enum = &hid->report_enum[HID_INPUT_REPORT];
list_for_each_entry(rep, &rep_enum->report_list, list) { for (i = 0; i < rep->maxfield; i++) {
field = rep->field[i];
hid_apply_multiplier_to_field(hid, field,
multiplier_collection,
effective_multiplier);
}
}
}
/* * hid_setup_resolution_multiplier - set up all resolution multipliers * * @device: hid device * * Search for all Resolution Multiplier Feature Reports and apply their * value to all matching Input items. This only updates the internal struct * fields. * * The Resolution Multiplier is applied by the hardware. If the multiplier * is anything other than 1, the hardware will send pre-multiplied events * so that the same physical interaction generates an accumulated * accumulated_value = value * * multiplier * This may be achieved by sending * - "value * multiplier" for each event, or * - "value" but "multiplier" times as frequently, or * - a combination of the above * The only guarantee is that the same physical interaction always generates * an accumulated 'value * multiplier'. * * This function must be called before any event processing and after * any SetRequest to the Resolution Multiplier.
*/ void hid_setup_resolution_multiplier(struct hid_device *hid)
{ struct hid_report_enum *rep_enum; struct hid_report *rep; struct hid_usage *usage; int i, j;
rep_enum = &hid->report_enum[HID_FEATURE_REPORT];
list_for_each_entry(rep, &rep_enum->report_list, list) { for (i = 0; i < rep->maxfield; i++) { /* Ignore if report count is out of bounds. */ if (rep->field[i]->report_count < 1) continue;
/** * hid_open_report - open a driver-specific device report * * @device: hid device * * Parse a report description into a hid_device structure. Reports are * enumerated, fields are attached to these reports. * 0 returned on success, otherwise nonzero error value. * * This function (or the equivalent hid_parse() macro) should only be * called from probe() in drivers, before starting the device.
*/ int hid_open_report(struct hid_device *device)
{ struct hid_parser *parser; struct hid_item item; unsignedint size; const __u8 *start; const __u8 *end; const __u8 *next; int ret; int i; staticint (*dispatch_type[])(struct hid_parser *parser, struct hid_item *item) = {
hid_parser_main,
hid_parser_global,
hid_parser_local,
hid_parser_reserved
};
if (WARN_ON(device->status & HID_STAT_PARSED)) return -EBUSY;
start = device->bpf_rdesc; if (WARN_ON(!start)) return -ENODEV;
size = device->bpf_rsize;
if (device->driver->report_fixup) { /* * device->driver->report_fixup() needs to work * on a copy of our report descriptor so it can * change it.
*/
__u8 *buf = kmemdup(start, size, GFP_KERNEL);
/* * The second kmemdup is required in case report_fixup() returns * a static read-only memory, but we have no idea if that memory * needs to be cleaned up or not at the end.
*/
start = kmemdup(start, size, GFP_KERNEL);
kfree(buf); if (start == NULL) return -ENOMEM;
}
device->rdesc = start;
device->rsize = size;
parser = vzalloc(sizeof(struct hid_parser)); if (!parser) {
ret = -ENOMEM; goto alloc_err;
}
parser->device = device;
end = start + size;
device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS, sizeof(struct hid_collection), GFP_KERNEL); if (!device->collection) {
ret = -ENOMEM; goto err;
}
device->collection_size = HID_DEFAULT_NUM_COLLECTIONS; for (i = 0; i < HID_DEFAULT_NUM_COLLECTIONS; i++)
device->collection[i].parent_idx = -1;
ret = -EINVAL; while ((next = fetch_item(start, end, &item)) != NULL) {
start = next;
if (item.format != HID_ITEM_FORMAT_SHORT) {
hid_err(device, "unexpected long global item\n"); goto err;
}
if (start == end) { if (parser->collection_stack_ptr) {
hid_err(device, "unbalanced collection at end of report description\n"); goto err;
} if (parser->local.delimiter_depth) {
hid_err(device, "unbalanced delimiter at end of report description\n"); goto err;
}
/* * fetch initial values in case the device's * default multiplier isn't the recommended 1
*/
hid_setup_resolution_multiplier(device);
/* * Extract/implement a data field from/to a little endian report (bit array). * * Code sort-of follows HID spec: * http://www.usb.org/developers/hidpage/HID1_11.pdf * * While the USB HID spec allows unlimited length bit fields in "report * descriptors", most devices never use more than 16 bits. * One model of UPS is claimed to report "LINEV" as a 32-bit field. * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
*/
/* * "implement" : set bits in a little endian bit stream. * Same concepts as "extract" (see comments above). * The data mangled in the bit stream remains in little endian * order the whole time. It make more sense to talk about * endianness of register values by considering a register * a "cached" copy of the little endian bit stream.
*/
staticvoid __implement(u8 *report, unsigned offset, int n, u32 value)
{ unsignedint idx = offset / 8; unsignedint bit_shift = offset % 8; int bits_to_set = 8 - bit_shift;
while (n - bits_to_set >= 0) {
report[idx] &= ~(0xff << bit_shift);
report[idx] |= value << bit_shift;
value >>= bits_to_set;
n -= bits_to_set;
bits_to_set = 8;
bit_shift = 0;
idx++;
}
/* last nibble */ if (n) {
u8 bit_mask = ((1U << n) - 1);
report[idx] &= ~(bit_mask << bit_shift);
report[idx] |= value << bit_shift;
}
}
staticvoid implement(conststruct hid_device *hid, u8 *report, unsigned offset, unsigned n, u32 value)
{ if (unlikely(n > 32)) {
hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
__func__, n, current->comm);
n = 32;
} elseif (n < 32) {
u32 m = (1U << n) - 1;
if (unlikely(value > m)) {
hid_warn(hid, "%s() called with too large value %d (n: %d)! (%s)\n",
__func__, value, n, current->comm);
value &= m;
}
}
/* * Checks if the given value is valid within this field
*/ staticinlineint hid_array_value_is_valid(struct hid_field *field,
__s32 value)
{
__s32 min = field->logical_minimum;
/* * Value needs to be between logical min and max, and * (value - min) is used as an index in the usage array. * This array is of size field->maxusage
*/ return value >= min &&
value <= field->logical_maximum &&
value - min < field->maxusage;
}
/* * Fetch the field from the data. The field content is stored for next * report processing (we do differential reporting to the layer).
*/ staticvoid hid_input_fetch_field(struct hid_device *hid, struct hid_field *field,
__u8 *data)
{ unsigned n; unsigned count = field->report_count; unsigned offset = field->report_offset; unsigned size = field->report_size;
__s32 min = field->logical_minimum;
__s32 *value;
/* * Analyse a received report, and fetch the data from it. The field * content is stored for next report processing (we do differential * reporting to the layer).
*/ staticvoid hid_process_report(struct hid_device *hid, struct hid_report *report,
__u8 *data, int interrupt)
{ unsignedint a; struct hid_field_entry *entry; struct hid_field *field;
/* first retrieve all incoming values in data */ for (a = 0; a < report->maxfield; a++)
hid_input_fetch_field(hid, report->field[a], data);
if (!list_empty(&report->field_entry_list)) { /* INPUT_REPORT, we have a priority list of fields */
list_for_each_entry(entry,
&report->field_entry_list,
list) {
field = entry->field;
/* * Insert a given usage_index in a field in the list * of processed usages in the report. * * The elements of lower priority score are processed * first.
*/ staticvoid __hid_insert_field_entry(struct hid_device *hid, struct hid_report *report, struct hid_field_entry *entry, struct hid_field *field, unsignedint usage_index)
{ struct hid_field_entry *next;
/* insert the element at the correct position */
list_for_each_entry(next,
&report->field_entry_list,
list) { /* * the priority of our element is strictly higher * than the next one, insert it before
*/ if (entry->priority > next->priority) {
list_add_tail(&entry->list, &next->list); return;
}
}
/* lowest priority score: insert at the end */
list_add_tail(&entry->list, &report->field_entry_list);
}
/* count the number of individual fields in the report */ for (a = 0; a < report->maxfield; a++) {
field = report->field[a];
if (field->flags & HID_MAIN_ITEM_VARIABLE)
count += field->report_count; else
count++;
}
/* allocate the memory to process the fields */
entries = kcalloc(count, sizeof(*entries), GFP_KERNEL); if (!entries) return;
report->field_entries = entries;
/* * walk through all fields in the report and * store them by priority order in report->field_entry_list * * - Var elements are individualized (field + usage_index) * - Arrays are taken as one, we can not chose an order for them
*/
usages = 0; for (a = 0; a < report->maxfield; a++) {
field = report->field[a];
if (field->flags & HID_MAIN_ITEM_VARIABLE) { for (u = 0; u < field->report_count; u++) {
__hid_insert_field_entry(hid, report,
&entries[usages],
field, u);
usages++;
}
} else {
__hid_insert_field_entry(hid, report, &entries[usages],
field, 0);
usages++;
}
}
}
memset(data, 0, hid_compute_report_size(report)); for (n = 0; n < report->maxfield; n++)
hid_output_field(report->device, report->field[n], data);
}
EXPORT_SYMBOL_GPL(hid_output_report);
/* * Allocator for buffer that is going to be passed to hid_output_report()
*/
u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags)
{ /* * 7 extra bytes are necessary to achieve proper functionality * of implement() working on 8 byte chunks * 1 extra byte for the report ID if it is null (not used) so * we can reserve that extra byte in the first position of the buffer * when sending it to .raw_request()
*/
u32 len = hid_report_len(report) + 7 + (report->id == 0);
/* * Implement a generic .request() callback, using .raw_request() * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
*/ int __hid_request(struct hid_device *hid, struct hid_report *report, enum hid_class_request reqtype)
{ char *buf, *data_buf; int ret;
u32 len;
buf = hid_alloc_report_buf(report, GFP_KERNEL); if (!buf) return -ENOMEM;
data_buf = buf;
len = hid_report_len(report);
if (report->id == 0) { /* reserve the first byte for the report ID */
data_buf++;
len++;
}
if (reqtype == HID_REQ_SET_REPORT)
hid_output_report(report, data_buf);
ret = hid_hw_raw_request(hid, report->id, buf, len, report->type, reqtype); if (ret < 0) {
dbg_hid("unable to complete request: %d\n", ret); goto out;
}
if (reqtype == HID_REQ_GET_REPORT)
hid_input_report(hid, report->type, buf, ret, 0);
if (connect_mask & HID_CONNECT_DRIVER)
hdev->claimed |= HID_CLAIMED_DRIVER;
/* Drivers with the ->raw_event callback set are not required to connect
* to any other listener. */ if (!hdev->claimed && !hdev->driver->raw_event) {
hid_err(hdev, "device has no listeners, quitting\n"); return -ENODEV;
}
len = 0; if (hdev->claimed & HID_CLAIMED_INPUT)
len += sprintf(buf + len, "input"); if (hdev->claimed & HID_CLAIMED_HIDDEV)
len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
((struct hiddev *)hdev->hiddev)->minor); if (hdev->claimed & HID_CLAIMED_HIDRAW)
len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
((struct hidraw *)hdev->hidraw)->minor);
type = "Device"; for (i = 0; i < hdev->maxcollection; i++) { struct hid_collection *col = &hdev->collection[i]; if (col->type == HID_COLLECTION_APPLICATION &&
(col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
(col->usage & 0xffff) < ARRAY_SIZE(types)) {
type = types[col->usage & 0xffff]; break;
}
}
switch (hdev->bus) { case BUS_USB:
bus = "USB"; break; case BUS_BLUETOOTH:
bus = "BLUETOOTH"; break; case BUS_I2C:
bus = "I2C"; break; case BUS_SDW:
bus = "SOUNDWIRE"; break; case BUS_VIRTUAL:
bus = "VIRTUAL"; break; case BUS_INTEL_ISHTP: case BUS_AMD_SFH:
bus = "SENSOR HUB"; break; default:
bus = "";
}
ret = device_create_file(&hdev->dev, &dev_attr_country); if (ret)
hid_warn(hdev, "can't create sysfs country code attribute err: %d\n", ret);
/** * hid_hw_start - start underlying HW * @hdev: hid device * @connect_mask: which outputs to connect, see HID_CONNECT_* * * Call this in probe function *after* hid_parse. This will setup HW * buffers and start the device (if not defeirred to device open). * hid_hw_stop must be called if this was successful.
*/ int hid_hw_start(struct hid_device *hdev, unsignedint connect_mask)
{ int error;
error = hdev->ll_driver->start(hdev); if (error) return error;
if (connect_mask) {
error = hid_connect(hdev, connect_mask); if (error) {
hdev->ll_driver->stop(hdev); return error;
}
}
return 0;
}
EXPORT_SYMBOL_GPL(hid_hw_start);
/** * hid_hw_stop - stop underlying HW * @hdev: hid device * * This is usually called from remove function or from probe when something * failed and hid_hw_start was called already.
*/ void hid_hw_stop(struct hid_device *hdev)
{
hid_disconnect(hdev);
hdev->ll_driver->stop(hdev);
}
EXPORT_SYMBOL_GPL(hid_hw_stop);
/** * hid_hw_open - signal underlying HW to start delivering events * @hdev: hid device * * Tell underlying HW to start delivering events from the device. * This function should be called sometime after successful call * to hid_hw_start().
*/ int hid_hw_open(struct hid_device *hdev)
{ int ret;
ret = mutex_lock_killable(&hdev->ll_open_lock); if (ret) return ret;
if (!hdev->ll_open_count++) {
ret = hdev->ll_driver->open(hdev); if (ret)
hdev->ll_open_count--;
if (hdev->driver->on_hid_hw_open)
hdev->driver->on_hid_hw_open(hdev);
}
/** * hid_hw_close - signal underlaying HW to stop delivering events * * @hdev: hid device * * This function indicates that we are not interested in the events * from this device anymore. Delivery of events may or may not stop, * depending on the number of users still outstanding.
*/ void hid_hw_close(struct hid_device *hdev)
{
mutex_lock(&hdev->ll_open_lock); if (!--hdev->ll_open_count) {
hdev->ll_driver->close(hdev);
if (hdev->driver->on_hid_hw_close)
hdev->driver->on_hid_hw_close(hdev);
}
mutex_unlock(&hdev->ll_open_lock);
}
EXPORT_SYMBOL_GPL(hid_hw_close);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.