hid-core.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  1. /*
  2. * HID support for Linux
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2006-2012 Jiri Kosina
  8. */
  9. /*
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the Free
  12. * Software Foundation; either version 2 of the License, or (at your option)
  13. * any later version.
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/list.h>
  21. #include <linux/mm.h>
  22. #include <linux/spinlock.h>
  23. #include <asm/unaligned.h>
  24. #include <asm/byteorder.h>
  25. #include <linux/input.h>
  26. #include <linux/wait.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/sched.h>
  29. #include <linux/semaphore.h>
  30. #include <linux/hid.h>
  31. #include <linux/hiddev.h>
  32. #include <linux/hid-debug.h>
  33. #include <linux/hidraw.h>
  34. #include "hid-ids.h"
  35. /*
  36. * Version Information
  37. */
  38. #define DRIVER_DESC "HID core driver"
  39. #define DRIVER_LICENSE "GPL"
  40. int hid_debug = 0;
  41. module_param_named(debug, hid_debug, int, 0600);
  42. MODULE_PARM_DESC(debug, "toggle HID debugging messages");
  43. EXPORT_SYMBOL_GPL(hid_debug);
  44. static int hid_ignore_special_drivers = 0;
  45. module_param_named(ignore_special_drivers, hid_ignore_special_drivers, int, 0600);
  46. MODULE_PARM_DESC(debug, "Ignore any special drivers and handle all devices by generic driver");
  47. /*
  48. * Register a new report for a device.
  49. */
  50. struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
  51. {
  52. struct hid_report_enum *report_enum = device->report_enum + type;
  53. struct hid_report *report;
  54. if (report_enum->report_id_hash[id])
  55. return report_enum->report_id_hash[id];
  56. report = kzalloc(sizeof(struct hid_report), GFP_KERNEL);
  57. if (!report)
  58. return NULL;
  59. if (id != 0)
  60. report_enum->numbered = 1;
  61. report->id = id;
  62. report->type = type;
  63. report->size = 0;
  64. report->device = device;
  65. report_enum->report_id_hash[id] = report;
  66. list_add_tail(&report->list, &report_enum->report_list);
  67. return report;
  68. }
  69. EXPORT_SYMBOL_GPL(hid_register_report);
  70. /*
  71. * Register a new field for this report.
  72. */
  73. static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
  74. {
  75. struct hid_field *field;
  76. int i;
  77. if (report->maxfield == HID_MAX_FIELDS) {
  78. hid_err(report->device, "too many fields in report\n");
  79. return NULL;
  80. }
  81. field = kzalloc((sizeof(struct hid_field) +
  82. usages * sizeof(struct hid_usage) +
  83. values * sizeof(unsigned)), GFP_KERNEL);
  84. if (!field)
  85. return NULL;
  86. field->index = report->maxfield++;
  87. report->field[field->index] = field;
  88. field->usage = (struct hid_usage *)(field + 1);
  89. field->value = (s32 *)(field->usage + usages);
  90. field->report = report;
  91. for (i = 0; i < usages; i++)
  92. field->usage[i].usage_index = i;
  93. return field;
  94. }
  95. /*
  96. * Open a collection. The type/usage is pushed on the stack.
  97. */
  98. static int open_collection(struct hid_parser *parser, unsigned type)
  99. {
  100. struct hid_collection *collection;
  101. unsigned usage;
  102. usage = parser->local.usage[0];
  103. if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
  104. hid_err(parser->device, "collection stack overflow\n");
  105. return -EINVAL;
  106. }
  107. if (parser->device->maxcollection == parser->device->collection_size) {
  108. collection = kmalloc(sizeof(struct hid_collection) *
  109. parser->device->collection_size * 2, GFP_KERNEL);
  110. if (collection == NULL) {
  111. hid_err(parser->device, "failed to reallocate collection array\n");
  112. return -ENOMEM;
  113. }
  114. memcpy(collection, parser->device->collection,
  115. sizeof(struct hid_collection) *
  116. parser->device->collection_size);
  117. memset(collection + parser->device->collection_size, 0,
  118. sizeof(struct hid_collection) *
  119. parser->device->collection_size);
  120. kfree(parser->device->collection);
  121. parser->device->collection = collection;
  122. parser->device->collection_size *= 2;
  123. }
  124. parser->collection_stack[parser->collection_stack_ptr++] =
  125. parser->device->maxcollection;
  126. collection = parser->device->collection +
  127. parser->device->maxcollection++;
  128. collection->type = type;
  129. collection->usage = usage;
  130. collection->level = parser->collection_stack_ptr - 1;
  131. if (type == HID_COLLECTION_APPLICATION)
  132. parser->device->maxapplication++;
  133. return 0;
  134. }
  135. /*
  136. * Close a collection.
  137. */
  138. static int close_collection(struct hid_parser *parser)
  139. {
  140. if (!parser->collection_stack_ptr) {
  141. hid_err(parser->device, "collection stack underflow\n");
  142. return -EINVAL;
  143. }
  144. parser->collection_stack_ptr--;
  145. return 0;
  146. }
  147. /*
  148. * Climb up the stack, search for the specified collection type
  149. * and return the usage.
  150. */
  151. static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
  152. {
  153. struct hid_collection *collection = parser->device->collection;
  154. int n;
  155. for (n = parser->collection_stack_ptr - 1; n >= 0; n--) {
  156. unsigned index = parser->collection_stack[n];
  157. if (collection[index].type == type)
  158. return collection[index].usage;
  159. }
  160. return 0; /* we know nothing about this usage type */
  161. }
  162. /*
  163. * Add a usage to the temporary parser table.
  164. */
  165. static int hid_add_usage(struct hid_parser *parser, unsigned usage)
  166. {
  167. if (parser->local.usage_index >= HID_MAX_USAGES) {
  168. hid_err(parser->device, "usage index exceeded\n");
  169. return -1;
  170. }
  171. parser->local.usage[parser->local.usage_index] = usage;
  172. parser->local.collection_index[parser->local.usage_index] =
  173. parser->collection_stack_ptr ?
  174. parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
  175. parser->local.usage_index++;
  176. return 0;
  177. }
  178. /*
  179. * Register a new field for this report.
  180. */
  181. static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
  182. {
  183. struct hid_report *report;
  184. struct hid_field *field;
  185. int usages;
  186. unsigned offset;
  187. int i;
  188. report = hid_register_report(parser->device, report_type, parser->global.report_id);
  189. if (!report) {
  190. hid_err(parser->device, "hid_register_report failed\n");
  191. return -1;
  192. }
  193. /* Handle both signed and unsigned cases properly */
  194. if ((parser->global.logical_minimum < 0 &&
  195. parser->global.logical_maximum <
  196. parser->global.logical_minimum) ||
  197. (parser->global.logical_minimum >= 0 &&
  198. (__u32)parser->global.logical_maximum <
  199. (__u32)parser->global.logical_minimum)) {
  200. dbg_hid("logical range invalid 0x%x 0x%x\n",
  201. parser->global.logical_minimum,
  202. parser->global.logical_maximum);
  203. return -1;
  204. }
  205. offset = report->size;
  206. report->size += parser->global.report_size * parser->global.report_count;
  207. if (!parser->local.usage_index) /* Ignore padding fields */
  208. return 0;
  209. usages = max_t(int, parser->local.usage_index, parser->global.report_count);
  210. field = hid_register_field(report, usages, parser->global.report_count);
  211. if (!field)
  212. return 0;
  213. field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
  214. field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
  215. field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
  216. for (i = 0; i < usages; i++) {
  217. int j = i;
  218. /* Duplicate the last usage we parsed if we have excess values */
  219. if (i >= parser->local.usage_index)
  220. j = parser->local.usage_index - 1;
  221. field->usage[i].hid = parser->local.usage[j];
  222. field->usage[i].collection_index =
  223. parser->local.collection_index[j];
  224. }
  225. field->maxusage = usages;
  226. field->flags = flags;
  227. field->report_offset = offset;
  228. field->report_type = report_type;
  229. field->report_size = parser->global.report_size;
  230. field->report_count = parser->global.report_count;
  231. field->logical_minimum = parser->global.logical_minimum;
  232. field->logical_maximum = parser->global.logical_maximum;
  233. field->physical_minimum = parser->global.physical_minimum;
  234. field->physical_maximum = parser->global.physical_maximum;
  235. field->unit_exponent = parser->global.unit_exponent;
  236. field->unit = parser->global.unit;
  237. return 0;
  238. }
  239. /*
  240. * Read data value from item.
  241. */
  242. static u32 item_udata(struct hid_item *item)
  243. {
  244. switch (item->size) {
  245. case 1: return item->data.u8;
  246. case 2: return item->data.u16;
  247. case 4: return item->data.u32;
  248. }
  249. return 0;
  250. }
  251. static s32 item_sdata(struct hid_item *item)
  252. {
  253. switch (item->size) {
  254. case 1: return item->data.s8;
  255. case 2: return item->data.s16;
  256. case 4: return item->data.s32;
  257. }
  258. return 0;
  259. }
  260. /*
  261. * Process a global item.
  262. */
  263. static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
  264. {
  265. __u32 raw_value;
  266. switch (item->tag) {
  267. case HID_GLOBAL_ITEM_TAG_PUSH:
  268. if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
  269. hid_err(parser->device, "global environment stack overflow\n");
  270. return -1;
  271. }
  272. memcpy(parser->global_stack + parser->global_stack_ptr++,
  273. &parser->global, sizeof(struct hid_global));
  274. return 0;
  275. case HID_GLOBAL_ITEM_TAG_POP:
  276. if (!parser->global_stack_ptr) {
  277. hid_err(parser->device, "global environment stack underflow\n");
  278. return -1;
  279. }
  280. memcpy(&parser->global, parser->global_stack +
  281. --parser->global_stack_ptr, sizeof(struct hid_global));
  282. return 0;
  283. case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
  284. parser->global.usage_page = item_udata(item);
  285. return 0;
  286. case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
  287. parser->global.logical_minimum = item_sdata(item);
  288. return 0;
  289. case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
  290. if (parser->global.logical_minimum < 0)
  291. parser->global.logical_maximum = item_sdata(item);
  292. else
  293. parser->global.logical_maximum = item_udata(item);
  294. return 0;
  295. case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
  296. parser->global.physical_minimum = item_sdata(item);
  297. return 0;
  298. case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
  299. if (parser->global.physical_minimum < 0)
  300. parser->global.physical_maximum = item_sdata(item);
  301. else
  302. parser->global.physical_maximum = item_udata(item);
  303. return 0;
  304. case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
  305. /* Units exponent negative numbers are given through a
  306. * two's complement.
  307. * See "6.2.2.7 Global Items" for more information. */
  308. raw_value = item_udata(item);
  309. if (!(raw_value & 0xfffffff0))
  310. parser->global.unit_exponent = hid_snto32(raw_value, 4);
  311. else
  312. parser->global.unit_exponent = raw_value;
  313. return 0;
  314. case HID_GLOBAL_ITEM_TAG_UNIT:
  315. parser->global.unit = item_udata(item);
  316. return 0;
  317. case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
  318. parser->global.report_size = item_udata(item);
  319. if (parser->global.report_size > 128) {
  320. hid_err(parser->device, "invalid report_size %d\n",
  321. parser->global.report_size);
  322. return -1;
  323. }
  324. return 0;
  325. case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
  326. parser->global.report_count = item_udata(item);
  327. if (parser->global.report_count > HID_MAX_USAGES) {
  328. hid_err(parser->device, "invalid report_count %d\n",
  329. parser->global.report_count);
  330. return -1;
  331. }
  332. return 0;
  333. case HID_GLOBAL_ITEM_TAG_REPORT_ID:
  334. parser->global.report_id = item_udata(item);
  335. if (parser->global.report_id == 0) {
  336. hid_err(parser->device, "report_id 0 is invalid\n");
  337. return -1;
  338. }
  339. return 0;
  340. default:
  341. hid_err(parser->device, "unknown global tag 0x%x\n", item->tag);
  342. return -1;
  343. }
  344. }
  345. /*
  346. * Process a local item.
  347. */
  348. static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
  349. {
  350. __u32 data;
  351. unsigned n;
  352. data = item_udata(item);
  353. switch (item->tag) {
  354. case HID_LOCAL_ITEM_TAG_DELIMITER:
  355. if (data) {
  356. /*
  357. * We treat items before the first delimiter
  358. * as global to all usage sets (branch 0).
  359. * In the moment we process only these global
  360. * items and the first delimiter set.
  361. */
  362. if (parser->local.delimiter_depth != 0) {
  363. hid_err(parser->device, "nested delimiters\n");
  364. return -1;
  365. }
  366. parser->local.delimiter_depth++;
  367. parser->local.delimiter_branch++;
  368. } else {
  369. if (parser->local.delimiter_depth < 1) {
  370. hid_err(parser->device, "bogus close delimiter\n");
  371. return -1;
  372. }
  373. parser->local.delimiter_depth--;
  374. }
  375. return 1;
  376. case HID_LOCAL_ITEM_TAG_USAGE:
  377. if (parser->local.delimiter_branch > 1) {
  378. dbg_hid("alternative usage ignored\n");
  379. return 0;
  380. }
  381. if (item->size <= 2)
  382. data = (parser->global.usage_page << 16) + data;
  383. return hid_add_usage(parser, data);
  384. case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
  385. if (parser->local.delimiter_branch > 1) {
  386. dbg_hid("alternative usage ignored\n");
  387. return 0;
  388. }
  389. if (item->size <= 2)
  390. data = (parser->global.usage_page << 16) + data;
  391. parser->local.usage_minimum = data;
  392. return 0;
  393. case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
  394. if (parser->local.delimiter_branch > 1) {
  395. dbg_hid("alternative usage ignored\n");
  396. return 0;
  397. }
  398. if (item->size <= 2)
  399. data = (parser->global.usage_page << 16) + data;
  400. for (n = parser->local.usage_minimum; n <= data; n++)
  401. if (hid_add_usage(parser, n)) {
  402. dbg_hid("hid_add_usage failed\n");
  403. return -1;
  404. }
  405. return 0;
  406. default:
  407. dbg_hid("unknown local item tag 0x%x\n", item->tag);
  408. return 0;
  409. }
  410. return 0;
  411. }
  412. /*
  413. * Process a main item.
  414. */
  415. static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
  416. {
  417. __u32 data;
  418. int ret;
  419. data = item_udata(item);
  420. switch (item->tag) {
  421. case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
  422. ret = open_collection(parser, data & 0xff);
  423. break;
  424. case HID_MAIN_ITEM_TAG_END_COLLECTION:
  425. ret = close_collection(parser);
  426. break;
  427. case HID_MAIN_ITEM_TAG_INPUT:
  428. ret = hid_add_field(parser, HID_INPUT_REPORT, data);
  429. break;
  430. case HID_MAIN_ITEM_TAG_OUTPUT:
  431. ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
  432. break;
  433. case HID_MAIN_ITEM_TAG_FEATURE:
  434. ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
  435. break;
  436. default:
  437. hid_err(parser->device, "unknown main item tag 0x%x\n", item->tag);
  438. ret = 0;
  439. }
  440. memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
  441. return ret;
  442. }
  443. /*
  444. * Process a reserved item.
  445. */
  446. static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
  447. {
  448. dbg_hid("reserved item type, tag 0x%x\n", item->tag);
  449. return 0;
  450. }
  451. /*
  452. * Free a report and all registered fields. The field->usage and
  453. * field->value table's are allocated behind the field, so we need
  454. * only to free(field) itself.
  455. */
  456. static void hid_free_report(struct hid_report *report)
  457. {
  458. unsigned n;
  459. for (n = 0; n < report->maxfield; n++)
  460. kfree(report->field[n]);
  461. kfree(report);
  462. }
  463. /*
  464. * Close report. This function returns the device
  465. * state to the point prior to hid_open_report().
  466. */
  467. static void hid_close_report(struct hid_device *device)
  468. {
  469. unsigned i, j;
  470. for (i = 0; i < HID_REPORT_TYPES; i++) {
  471. struct hid_report_enum *report_enum = device->report_enum + i;
  472. for (j = 0; j < 256; j++) {
  473. struct hid_report *report = report_enum->report_id_hash[j];
  474. if (report)
  475. hid_free_report(report);
  476. }
  477. memset(report_enum, 0, sizeof(*report_enum));
  478. INIT_LIST_HEAD(&report_enum->report_list);
  479. }
  480. kfree(device->rdesc);
  481. device->rdesc = NULL;
  482. device->rsize = 0;
  483. kfree(device->collection);
  484. device->collection = NULL;
  485. device->collection_size = 0;
  486. device->maxcollection = 0;
  487. device->maxapplication = 0;
  488. device->status &= ~HID_STAT_PARSED;
  489. }
  490. /*
  491. * Free a device structure, all reports, and all fields.
  492. */
  493. static void hid_device_release(struct device *dev)
  494. {
  495. struct hid_device *hid = container_of(dev, struct hid_device, dev);
  496. hid_close_report(hid);
  497. kfree(hid->dev_rdesc);
  498. kfree(hid);
  499. }
  500. /*
  501. * Fetch a report description item from the data stream. We support long
  502. * items, though they are not used yet.
  503. */
  504. static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
  505. {
  506. u8 b;
  507. if ((end - start) <= 0)
  508. return NULL;
  509. b = *start++;
  510. item->type = (b >> 2) & 3;
  511. item->tag = (b >> 4) & 15;
  512. if (item->tag == HID_ITEM_TAG_LONG) {
  513. item->format = HID_ITEM_FORMAT_LONG;
  514. if ((end - start) < 2)
  515. return NULL;
  516. item->size = *start++;
  517. item->tag = *start++;
  518. if ((end - start) < item->size)
  519. return NULL;
  520. item->data.longdata = start;
  521. start += item->size;
  522. return start;
  523. }
  524. item->format = HID_ITEM_FORMAT_SHORT;
  525. item->size = b & 3;
  526. switch (item->size) {
  527. case 0:
  528. return start;
  529. case 1:
  530. if ((end - start) < 1)
  531. return NULL;
  532. item->data.u8 = *start++;
  533. return start;
  534. case 2:
  535. if ((end - start) < 2)
  536. return NULL;
  537. item->data.u16 = get_unaligned_le16(start);
  538. start = (__u8 *)((__le16 *)start + 1);
  539. return start;
  540. case 3:
  541. item->size++;
  542. if ((end - start) < 4)
  543. return NULL;
  544. item->data.u32 = get_unaligned_le32(start);
  545. start = (__u8 *)((__le32 *)start + 1);
  546. return start;
  547. }
  548. return NULL;
  549. }
  550. static void hid_scan_usage(struct hid_device *hid, u32 usage)
  551. {
  552. if (usage == HID_DG_CONTACTID)
  553. hid->group = HID_GROUP_MULTITOUCH;
  554. }
  555. /*
  556. * Scan a report descriptor before the device is added to the bus.
  557. * Sets device groups and other properties that determine what driver
  558. * to load.
  559. */
  560. static int hid_scan_report(struct hid_device *hid)
  561. {
  562. unsigned int page = 0, delim = 0;
  563. __u8 *start = hid->dev_rdesc;
  564. __u8 *end = start + hid->dev_rsize;
  565. unsigned int u, u_min = 0, u_max = 0;
  566. struct hid_item item;
  567. hid->group = HID_GROUP_GENERIC;
  568. while ((start = fetch_item(start, end, &item)) != NULL) {
  569. if (item.format != HID_ITEM_FORMAT_SHORT)
  570. return -EINVAL;
  571. if (item.type == HID_ITEM_TYPE_GLOBAL) {
  572. if (item.tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE)
  573. page = item_udata(&item) << 16;
  574. } else if (item.type == HID_ITEM_TYPE_LOCAL) {
  575. if (delim > 1)
  576. break;
  577. u = item_udata(&item);
  578. if (item.size <= 2)
  579. u += page;
  580. switch (item.tag) {
  581. case HID_LOCAL_ITEM_TAG_DELIMITER:
  582. delim += !!u;
  583. break;
  584. case HID_LOCAL_ITEM_TAG_USAGE:
  585. hid_scan_usage(hid, u);
  586. break;
  587. case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
  588. u_min = u;
  589. break;
  590. case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
  591. u_max = u;
  592. for (u = u_min; u <= u_max; u++)
  593. hid_scan_usage(hid, u);
  594. break;
  595. }
  596. } else if (page == HID_UP_SENSOR &&
  597. item.type == HID_ITEM_TYPE_MAIN &&
  598. item.tag == HID_MAIN_ITEM_TAG_BEGIN_COLLECTION &&
  599. (item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL &&
  600. (hid->bus == BUS_USB || hid->bus == BUS_I2C))
  601. hid->group = HID_GROUP_SENSOR_HUB;
  602. }
  603. return 0;
  604. }
  605. /**
  606. * hid_parse_report - parse device report
  607. *
  608. * @device: hid device
  609. * @start: report start
  610. * @size: report size
  611. *
  612. * Allocate the device report as read by the bus driver. This function should
  613. * only be called from parse() in ll drivers.
  614. */
  615. int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
  616. {
  617. hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL);
  618. if (!hid->dev_rdesc)
  619. return -ENOMEM;
  620. hid->dev_rsize = size;
  621. return 0;
  622. }
  623. EXPORT_SYMBOL_GPL(hid_parse_report);
  624. /**
  625. * hid_open_report - open a driver-specific device report
  626. *
  627. * @device: hid device
  628. *
  629. * Parse a report description into a hid_device structure. Reports are
  630. * enumerated, fields are attached to these reports.
  631. * 0 returned on success, otherwise nonzero error value.
  632. *
  633. * This function (or the equivalent hid_parse() macro) should only be
  634. * called from probe() in drivers, before starting the device.
  635. */
  636. int hid_open_report(struct hid_device *device)
  637. {
  638. struct hid_parser *parser;
  639. struct hid_item item;
  640. unsigned int size;
  641. __u8 *start;
  642. __u8 *buf;
  643. __u8 *end;
  644. int ret;
  645. static int (*dispatch_type[])(struct hid_parser *parser,
  646. struct hid_item *item) = {
  647. hid_parser_main,
  648. hid_parser_global,
  649. hid_parser_local,
  650. hid_parser_reserved
  651. };
  652. if (WARN_ON(device->status & HID_STAT_PARSED))
  653. return -EBUSY;
  654. start = device->dev_rdesc;
  655. if (WARN_ON(!start))
  656. return -ENODEV;
  657. size = device->dev_rsize;
  658. buf = kmemdup(start, size, GFP_KERNEL);
  659. if (buf == NULL)
  660. return -ENOMEM;
  661. if (device->driver->report_fixup)
  662. start = device->driver->report_fixup(device, buf, &size);
  663. else
  664. start = buf;
  665. start = kmemdup(start, size, GFP_KERNEL);
  666. kfree(buf);
  667. if (start == NULL)
  668. return -ENOMEM;
  669. device->rdesc = start;
  670. device->rsize = size;
  671. parser = vzalloc(sizeof(struct hid_parser));
  672. if (!parser) {
  673. ret = -ENOMEM;
  674. goto err;
  675. }
  676. parser->device = device;
  677. end = start + size;
  678. device->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
  679. sizeof(struct hid_collection), GFP_KERNEL);
  680. if (!device->collection) {
  681. ret = -ENOMEM;
  682. goto err;
  683. }
  684. device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
  685. ret = -EINVAL;
  686. while ((start = fetch_item(start, end, &item)) != NULL) {
  687. if (item.format != HID_ITEM_FORMAT_SHORT) {
  688. hid_err(device, "unexpected long global item\n");
  689. goto err;
  690. }
  691. if (dispatch_type[item.type](parser, &item)) {
  692. hid_err(device, "item %u %u %u %u parsing failed\n",
  693. item.format, (unsigned)item.size,
  694. (unsigned)item.type, (unsigned)item.tag);
  695. goto err;
  696. }
  697. if (start == end) {
  698. if (parser->collection_stack_ptr) {
  699. hid_err(device, "unbalanced collection at end of report description\n");
  700. goto err;
  701. }
  702. if (parser->local.delimiter_depth) {
  703. hid_err(device, "unbalanced delimiter at end of report description\n");
  704. goto err;
  705. }
  706. vfree(parser);
  707. device->status |= HID_STAT_PARSED;
  708. return 0;
  709. }
  710. }
  711. hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
  712. err:
  713. vfree(parser);
  714. hid_close_report(device);
  715. return ret;
  716. }
  717. EXPORT_SYMBOL_GPL(hid_open_report);
  718. /*
  719. * Convert a signed n-bit integer to signed 32-bit integer. Common
  720. * cases are done through the compiler, the screwed things has to be
  721. * done by hand.
  722. */
  723. static s32 snto32(__u32 value, unsigned n)
  724. {
  725. switch (n) {
  726. case 8: return ((__s8)value);
  727. case 16: return ((__s16)value);
  728. case 32: return ((__s32)value);
  729. }
  730. return value & (1 << (n - 1)) ? value | (-1 << n) : value;
  731. }
  732. s32 hid_snto32(__u32 value, unsigned n)
  733. {
  734. return snto32(value, n);
  735. }
  736. EXPORT_SYMBOL_GPL(hid_snto32);
  737. /*
  738. * Convert a signed 32-bit integer to a signed n-bit integer.
  739. */
  740. static u32 s32ton(__s32 value, unsigned n)
  741. {
  742. s32 a = value >> (n - 1);
  743. if (a && a != -1)
  744. return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
  745. return value & ((1 << n) - 1);
  746. }
  747. /*
  748. * Extract/implement a data field from/to a little endian report (bit array).
  749. *
  750. * Code sort-of follows HID spec:
  751. * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
  752. *
  753. * While the USB HID spec allows unlimited length bit fields in "report
  754. * descriptors", most devices never use more than 16 bits.
  755. * One model of UPS is claimed to report "LINEV" as a 32-bit field.
  756. * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
  757. */
  758. static __u32 extract(const struct hid_device *hid, __u8 *report,
  759. unsigned offset, unsigned n)
  760. {
  761. u64 x;
  762. if (n > 32)
  763. hid_warn(hid, "extract() called with n (%d) > 32! (%s)\n",
  764. n, current->comm);
  765. report += offset >> 3; /* adjust byte index */
  766. offset &= 7; /* now only need bit offset into one byte */
  767. x = get_unaligned_le64(report);
  768. x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
  769. return (u32) x;
  770. }
  771. /*
  772. * "implement" : set bits in a little endian bit stream.
  773. * Same concepts as "extract" (see comments above).
  774. * The data mangled in the bit stream remains in little endian
  775. * order the whole time. It make more sense to talk about
  776. * endianness of register values by considering a register
  777. * a "cached" copy of the little endiad bit stream.
  778. */
  779. static void implement(const struct hid_device *hid, __u8 *report,
  780. unsigned offset, unsigned n, __u32 value)
  781. {
  782. u64 x;
  783. u64 m = (1ULL << n) - 1;
  784. if (n > 32)
  785. hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
  786. __func__, n, current->comm);
  787. if (value > m)
  788. hid_warn(hid, "%s() called with too large value %d! (%s)\n",
  789. __func__, value, current->comm);
  790. WARN_ON(value > m);
  791. value &= m;
  792. report += offset >> 3;
  793. offset &= 7;
  794. x = get_unaligned_le64(report);
  795. x &= ~(m << offset);
  796. x |= ((u64)value) << offset;
  797. put_unaligned_le64(x, report);
  798. }
  799. /*
  800. * Search an array for a value.
  801. */
  802. static int search(__s32 *array, __s32 value, unsigned n)
  803. {
  804. while (n--) {
  805. if (*array++ == value)
  806. return 0;
  807. }
  808. return -1;
  809. }
  810. /**
  811. * hid_match_report - check if driver's raw_event should be called
  812. *
  813. * @hid: hid device
  814. * @report_type: type to match against
  815. *
  816. * compare hid->driver->report_table->report_type to report->type
  817. */
  818. static int hid_match_report(struct hid_device *hid, struct hid_report *report)
  819. {
  820. const struct hid_report_id *id = hid->driver->report_table;
  821. if (!id) /* NULL means all */
  822. return 1;
  823. for (; id->report_type != HID_TERMINATOR; id++)
  824. if (id->report_type == HID_ANY_ID ||
  825. id->report_type == report->type)
  826. return 1;
  827. return 0;
  828. }
  829. /**
  830. * hid_match_usage - check if driver's event should be called
  831. *
  832. * @hid: hid device
  833. * @usage: usage to match against
  834. *
  835. * compare hid->driver->usage_table->usage_{type,code} to
  836. * usage->usage_{type,code}
  837. */
  838. static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
  839. {
  840. const struct hid_usage_id *id = hid->driver->usage_table;
  841. if (!id) /* NULL means all */
  842. return 1;
  843. for (; id->usage_type != HID_ANY_ID - 1; id++)
  844. if ((id->usage_hid == HID_ANY_ID ||
  845. id->usage_hid == usage->hid) &&
  846. (id->usage_type == HID_ANY_ID ||
  847. id->usage_type == usage->type) &&
  848. (id->usage_code == HID_ANY_ID ||
  849. id->usage_code == usage->code))
  850. return 1;
  851. return 0;
  852. }
  853. static void hid_process_event(struct hid_device *hid, struct hid_field *field,
  854. struct hid_usage *usage, __s32 value, int interrupt)
  855. {
  856. struct hid_driver *hdrv = hid->driver;
  857. int ret;
  858. if (!list_empty(&hid->debug_list))
  859. hid_dump_input(hid, usage, value);
  860. if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
  861. ret = hdrv->event(hid, field, usage, value);
  862. if (ret != 0) {
  863. if (ret < 0)
  864. hid_err(hid, "%s's event failed with %d\n",
  865. hdrv->name, ret);
  866. return;
  867. }
  868. }
  869. if (hid->claimed & HID_CLAIMED_INPUT)
  870. hidinput_hid_event(hid, field, usage, value);
  871. if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
  872. hid->hiddev_hid_event(hid, field, usage, value);
  873. }
  874. /*
  875. * Analyse a received field, and fetch the data from it. The field
  876. * content is stored for next report processing (we do differential
  877. * reporting to the layer).
  878. */
  879. static void hid_input_field(struct hid_device *hid, struct hid_field *field,
  880. __u8 *data, int interrupt)
  881. {
  882. unsigned n;
  883. unsigned count = field->report_count;
  884. unsigned offset = field->report_offset;
  885. unsigned size = field->report_size;
  886. __s32 min = field->logical_minimum;
  887. __s32 max = field->logical_maximum;
  888. __s32 *value;
  889. value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC);
  890. if (!value)
  891. return;
  892. for (n = 0; n < count; n++) {
  893. value[n] = min < 0 ?
  894. snto32(extract(hid, data, offset + n * size, size),
  895. size) :
  896. extract(hid, data, offset + n * size, size);
  897. /* Ignore report if ErrorRollOver */
  898. if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
  899. value[n] >= min && value[n] <= max &&
  900. field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
  901. goto exit;
  902. }
  903. for (n = 0; n < count; n++) {
  904. if (HID_MAIN_ITEM_VARIABLE & field->flags) {
  905. hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
  906. continue;
  907. }
  908. if (field->value[n] >= min && field->value[n] <= max
  909. && field->usage[field->value[n] - min].hid
  910. && search(value, field->value[n], count))
  911. hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
  912. if (value[n] >= min && value[n] <= max
  913. && field->usage[value[n] - min].hid
  914. && search(field->value, value[n], count))
  915. hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
  916. }
  917. memcpy(field->value, value, count * sizeof(__s32));
  918. exit:
  919. kfree(value);
  920. }
  921. /*
  922. * Output the field into the report.
  923. */
  924. static void hid_output_field(const struct hid_device *hid,
  925. struct hid_field *field, __u8 *data)
  926. {
  927. unsigned count = field->report_count;
  928. unsigned offset = field->report_offset;
  929. unsigned size = field->report_size;
  930. unsigned n;
  931. for (n = 0; n < count; n++) {
  932. if (field->logical_minimum < 0) /* signed values */
  933. implement(hid, data, offset + n * size, size,
  934. s32ton(field->value[n], size));
  935. else /* unsigned values */
  936. implement(hid, data, offset + n * size, size,
  937. field->value[n]);
  938. }
  939. }
  940. /*
  941. * Create a report.
  942. */
  943. void hid_output_report(struct hid_report *report, __u8 *data)
  944. {
  945. unsigned n;
  946. if (report->id > 0)
  947. *data++ = report->id;
  948. memset(data, 0, ((report->size - 1) >> 3) + 1);
  949. for (n = 0; n < report->maxfield; n++)
  950. hid_output_field(report->device, report->field[n], data);
  951. }
  952. EXPORT_SYMBOL_GPL(hid_output_report);
  953. /*
  954. * Set a field value. The report this field belongs to has to be
  955. * created and transferred to the device, to set this value in the
  956. * device.
  957. */
  958. int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
  959. {
  960. unsigned size = field->report_size;
  961. hid_dump_input(field->report->device, field->usage + offset, value);
  962. if (offset >= field->report_count) {
  963. hid_err(field->report->device, "offset (%d) exceeds report_count (%d)\n",
  964. offset, field->report_count);
  965. return -1;
  966. }
  967. if (field->logical_minimum < 0) {
  968. if (value != snto32(s32ton(value, size), size)) {
  969. hid_err(field->report->device, "value %d is out of range\n", value);
  970. return -1;
  971. }
  972. }
  973. field->value[offset] = value;
  974. return 0;
  975. }
  976. EXPORT_SYMBOL_GPL(hid_set_field);
  977. static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
  978. const u8 *data)
  979. {
  980. struct hid_report *report;
  981. unsigned int n = 0; /* Normally report number is 0 */
  982. /* Device uses numbered reports, data[0] is report number */
  983. if (report_enum->numbered)
  984. n = *data;
  985. report = report_enum->report_id_hash[n];
  986. if (report == NULL)
  987. dbg_hid("undefined report_id %u received\n", n);
  988. return report;
  989. }
  990. int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
  991. int interrupt)
  992. {
  993. struct hid_report_enum *report_enum = hid->report_enum + type;
  994. struct hid_report *report;
  995. struct hid_driver *hdrv;
  996. unsigned int a;
  997. int rsize, csize = size;
  998. u8 *cdata = data;
  999. int ret = 0;
  1000. report = hid_get_report(report_enum, data);
  1001. if (!report)
  1002. goto out;
  1003. if (report_enum->numbered) {
  1004. cdata++;
  1005. csize--;
  1006. }
  1007. rsize = ((report->size - 1) >> 3) + 1;
  1008. if (rsize > HID_MAX_BUFFER_SIZE)
  1009. rsize = HID_MAX_BUFFER_SIZE;
  1010. if (csize < rsize) {
  1011. dbg_hid("report %d is too short, (%d < %d)\n", report->id,
  1012. csize, rsize);
  1013. memset(cdata + csize, 0, rsize - csize);
  1014. }
  1015. if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
  1016. hid->hiddev_report_event(hid, report);
  1017. if (hid->claimed & HID_CLAIMED_HIDRAW) {
  1018. ret = hidraw_report_event(hid, data, size);
  1019. if (ret)
  1020. goto out;
  1021. }
  1022. if (hid->claimed != HID_CLAIMED_HIDRAW) {
  1023. for (a = 0; a < report->maxfield; a++)
  1024. hid_input_field(hid, report->field[a], cdata, interrupt);
  1025. hdrv = hid->driver;
  1026. if (hdrv && hdrv->report)
  1027. hdrv->report(hid, report);
  1028. }
  1029. if (hid->claimed & HID_CLAIMED_INPUT)
  1030. hidinput_report_event(hid, report);
  1031. out:
  1032. return ret;
  1033. }
  1034. EXPORT_SYMBOL_GPL(hid_report_raw_event);
  1035. /**
  1036. * hid_input_report - report data from lower layer (usb, bt...)
  1037. *
  1038. * @hid: hid device
  1039. * @type: HID report type (HID_*_REPORT)
  1040. * @data: report contents
  1041. * @size: size of data parameter
  1042. * @interrupt: distinguish between interrupt and control transfers
  1043. *
  1044. * This is data entry for lower layers.
  1045. */
  1046. int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
  1047. {
  1048. struct hid_report_enum *report_enum;
  1049. struct hid_driver *hdrv;
  1050. struct hid_report *report;
  1051. char *buf;
  1052. unsigned int i;
  1053. int ret = 0;
  1054. if (!hid)
  1055. return -ENODEV;
  1056. if (down_trylock(&hid->driver_lock))
  1057. return -EBUSY;
  1058. if (!hid->driver) {
  1059. ret = -ENODEV;
  1060. goto unlock;
  1061. }
  1062. report_enum = hid->report_enum + type;
  1063. hdrv = hid->driver;
  1064. if (!size) {
  1065. dbg_hid("empty report\n");
  1066. ret = -1;
  1067. goto unlock;
  1068. }
  1069. /* Avoid unnecessary overhead if debugfs is disabled */
  1070. if (list_empty(&hid->debug_list))
  1071. goto nomem;
  1072. buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC);
  1073. if (!buf)
  1074. goto nomem;
  1075. /* dump the report */
  1076. snprintf(buf, HID_DEBUG_BUFSIZE - 1,
  1077. "\nreport (size %u) (%snumbered) = ", size, report_enum->numbered ? "" : "un");
  1078. hid_debug_event(hid, buf);
  1079. for (i = 0; i < size; i++) {
  1080. snprintf(buf, HID_DEBUG_BUFSIZE - 1,
  1081. " %02x", data[i]);
  1082. hid_debug_event(hid, buf);
  1083. }
  1084. hid_debug_event(hid, "\n");
  1085. kfree(buf);
  1086. nomem:
  1087. report = hid_get_report(report_enum, data);
  1088. if (!report) {
  1089. ret = -1;
  1090. goto unlock;
  1091. }
  1092. if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
  1093. ret = hdrv->raw_event(hid, report, data, size);
  1094. if (ret != 0) {
  1095. ret = ret < 0 ? ret : 0;
  1096. goto unlock;
  1097. }
  1098. }
  1099. ret = hid_report_raw_event(hid, type, data, size, interrupt);
  1100. unlock:
  1101. up(&hid->driver_lock);
  1102. return ret;
  1103. }
  1104. EXPORT_SYMBOL_GPL(hid_input_report);
  1105. static bool hid_match_one_id(struct hid_device *hdev,
  1106. const struct hid_device_id *id)
  1107. {
  1108. return (id->bus == HID_BUS_ANY || id->bus == hdev->bus) &&
  1109. (id->group == HID_GROUP_ANY || id->group == hdev->group) &&
  1110. (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
  1111. (id->product == HID_ANY_ID || id->product == hdev->product);
  1112. }
  1113. const struct hid_device_id *hid_match_id(struct hid_device *hdev,
  1114. const struct hid_device_id *id)
  1115. {
  1116. for (; id->bus; id++)
  1117. if (hid_match_one_id(hdev, id))
  1118. return id;
  1119. return NULL;
  1120. }
  1121. static const struct hid_device_id hid_hiddev_list[] = {
  1122. { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
  1123. { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
  1124. { }
  1125. };
  1126. static bool hid_hiddev(struct hid_device *hdev)
  1127. {
  1128. return !!hid_match_id(hdev, hid_hiddev_list);
  1129. }
  1130. static ssize_t
  1131. read_report_descriptor(struct file *filp, struct kobject *kobj,
  1132. struct bin_attribute *attr,
  1133. char *buf, loff_t off, size_t count)
  1134. {
  1135. struct device *dev = container_of(kobj, struct device, kobj);
  1136. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1137. if (off >= hdev->rsize)
  1138. return 0;
  1139. if (off + count > hdev->rsize)
  1140. count = hdev->rsize - off;
  1141. memcpy(buf, hdev->rdesc + off, count);
  1142. return count;
  1143. }
  1144. static struct bin_attribute dev_bin_attr_report_desc = {
  1145. .attr = { .name = "report_descriptor", .mode = 0444 },
  1146. .read = read_report_descriptor,
  1147. .size = HID_MAX_DESCRIPTOR_SIZE,
  1148. };
  1149. int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
  1150. {
  1151. static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
  1152. "Joystick", "Gamepad", "Keyboard", "Keypad",
  1153. "Multi-Axis Controller"
  1154. };
  1155. const char *type, *bus;
  1156. char buf[64];
  1157. unsigned int i;
  1158. int len;
  1159. int ret;
  1160. if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE)
  1161. connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV);
  1162. if (hdev->quirks & HID_QUIRK_HIDINPUT_FORCE)
  1163. connect_mask |= HID_CONNECT_HIDINPUT_FORCE;
  1164. if (hdev->bus != BUS_USB)
  1165. connect_mask &= ~HID_CONNECT_HIDDEV;
  1166. if (hid_hiddev(hdev))
  1167. connect_mask |= HID_CONNECT_HIDDEV_FORCE;
  1168. if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
  1169. connect_mask & HID_CONNECT_HIDINPUT_FORCE))
  1170. hdev->claimed |= HID_CLAIMED_INPUT;
  1171. if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
  1172. !hdev->hiddev_connect(hdev,
  1173. connect_mask & HID_CONNECT_HIDDEV_FORCE))
  1174. hdev->claimed |= HID_CLAIMED_HIDDEV;
  1175. if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
  1176. hdev->claimed |= HID_CLAIMED_HIDRAW;
  1177. /* Drivers with the ->raw_event callback set are not required to connect
  1178. * to any other listener. */
  1179. if (!hdev->claimed && !hdev->driver->raw_event) {
  1180. hid_err(hdev, "device has no listeners, quitting\n");
  1181. return -ENODEV;
  1182. }
  1183. if ((hdev->claimed & HID_CLAIMED_INPUT) &&
  1184. (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
  1185. hdev->ff_init(hdev);
  1186. len = 0;
  1187. if (hdev->claimed & HID_CLAIMED_INPUT)
  1188. len += sprintf(buf + len, "input");
  1189. if (hdev->claimed & HID_CLAIMED_HIDDEV)
  1190. len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
  1191. hdev->minor);
  1192. if (hdev->claimed & HID_CLAIMED_HIDRAW)
  1193. len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
  1194. ((struct hidraw *)hdev->hidraw)->minor);
  1195. type = "Device";
  1196. for (i = 0; i < hdev->maxcollection; i++) {
  1197. struct hid_collection *col = &hdev->collection[i];
  1198. if (col->type == HID_COLLECTION_APPLICATION &&
  1199. (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
  1200. (col->usage & 0xffff) < ARRAY_SIZE(types)) {
  1201. type = types[col->usage & 0xffff];
  1202. break;
  1203. }
  1204. }
  1205. switch (hdev->bus) {
  1206. case BUS_USB:
  1207. bus = "USB";
  1208. break;
  1209. case BUS_BLUETOOTH:
  1210. bus = "BLUETOOTH";
  1211. break;
  1212. default:
  1213. bus = "<UNKNOWN>";
  1214. }
  1215. ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
  1216. if (ret)
  1217. hid_warn(hdev,
  1218. "can't create sysfs report descriptor attribute err: %d\n", ret);
  1219. hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
  1220. buf, bus, hdev->version >> 8, hdev->version & 0xff,
  1221. type, hdev->name, hdev->phys);
  1222. return 0;
  1223. }
  1224. EXPORT_SYMBOL_GPL(hid_connect);
  1225. void hid_disconnect(struct hid_device *hdev)
  1226. {
  1227. device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
  1228. if (hdev->claimed & HID_CLAIMED_INPUT)
  1229. hidinput_disconnect(hdev);
  1230. if (hdev->claimed & HID_CLAIMED_HIDDEV)
  1231. hdev->hiddev_disconnect(hdev);
  1232. if (hdev->claimed & HID_CLAIMED_HIDRAW)
  1233. hidraw_disconnect(hdev);
  1234. }
  1235. EXPORT_SYMBOL_GPL(hid_disconnect);
  1236. /*
  1237. * A list of devices for which there is a specialized driver on HID bus.
  1238. *
  1239. * Please note that for multitouch devices (driven by hid-multitouch driver),
  1240. * there is a proper autodetection and autoloading in place (based on presence
  1241. * of HID_DG_CONTACTID), so those devices don't need to be added to this list,
  1242. * as we are doing the right thing in hid_scan_usage().
  1243. *
  1244. * Autodetection for (USB) HID sensor hubs exists too. If a collection of type
  1245. * physical is found inside a usage page of type sensor, hid-sensor-hub will be
  1246. * used as a driver. See hid_scan_report().
  1247. */
  1248. static const struct hid_device_id hid_have_special_driver[] = {
  1249. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
  1250. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
  1251. { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649) },
  1252. { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802) },
  1253. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
  1254. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
  1255. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
  1256. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
  1257. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICTRACKPAD) },
  1258. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  1259. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  1260. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  1261. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  1262. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  1263. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  1264. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  1265. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  1266. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  1267. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  1268. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  1269. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ANSI) },
  1270. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_ISO) },
  1271. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_MINI_JIS) },
  1272. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
  1273. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
  1274. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
  1275. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  1276. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  1277. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  1278. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
  1279. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
  1280. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
  1281. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  1282. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  1283. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  1284. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  1285. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  1286. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  1287. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  1288. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  1289. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  1290. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  1291. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  1292. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  1293. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  1294. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  1295. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  1296. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  1297. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  1298. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  1299. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  1300. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  1301. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  1302. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
  1303. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
  1304. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
  1305. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  1306. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  1307. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  1308. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  1309. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  1310. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  1311. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  1312. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  1313. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  1314. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  1315. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  1316. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  1317. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
  1318. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
  1319. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
  1320. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI) },
  1321. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
  1322. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  1323. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  1324. { HID_USB_DEVICE(USB_VENDOR_ID_AUREAL, USB_DEVICE_ID_AUREAL_W01RN) },
  1325. { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
  1326. { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
  1327. { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
  1328. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
  1329. { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
  1330. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
  1331. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS) },
  1332. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_WIRELESS2) },
  1333. { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_AK1D) },
  1334. { HID_USB_DEVICE(USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_PRODIKEYS_PCMIDI) },
  1335. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
  1336. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
  1337. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_3) },
  1338. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_4) },
  1339. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
  1340. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
  1341. { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
  1342. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
  1343. { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
  1344. { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
  1345. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
  1346. { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
  1347. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
  1348. { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
  1349. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
  1350. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_2) },
  1351. { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
  1352. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
  1353. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
  1354. { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
  1355. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
  1356. { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
  1357. { HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
  1358. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_ERGO_525V) },
  1359. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_I405X) },
  1360. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_MOUSEPEN_I608X) },
  1361. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M610X) },
  1362. { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
  1363. { HID_USB_DEVICE(USB_VENDOR_ID_LCPOWER, USB_DEVICE_ID_LCPOWER_LC1000 ) },
  1364. #if IS_ENABLED(CONFIG_HID_LENOVO_TPKBD)
  1365. { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
  1366. #endif
  1367. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
  1368. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
  1369. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
  1370. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
  1371. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
  1372. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
  1373. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
  1374. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
  1375. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
  1376. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
  1377. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
  1378. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
  1379. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
  1380. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
  1381. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
  1382. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
  1383. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
  1384. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
  1385. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
  1386. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
  1387. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
  1388. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFP_WHEEL) },
  1389. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DFGT_WHEEL) },
  1390. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
  1391. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G27_WHEEL) },
  1392. #if IS_ENABLED(CONFIG_HID_LOGITECH_DJ)
  1393. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER) },
  1394. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_UNIFYING_RECEIVER_2) },
  1395. #endif
  1396. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WII_WHEEL) },
  1397. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
  1398. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
  1399. { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
  1400. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
  1401. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
  1402. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
  1403. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
  1404. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
  1405. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
  1406. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
  1407. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
  1408. { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
  1409. { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
  1410. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
  1411. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_1) },
  1412. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_2) },
  1413. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_3) },
  1414. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_4) },
  1415. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_5) },
  1416. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_6) },
  1417. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_7) },
  1418. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_8) },
  1419. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_9) },
  1420. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_10) },
  1421. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_11) },
  1422. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_12) },
  1423. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_13) },
  1424. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_14) },
  1425. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_15) },
  1426. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_16) },
  1427. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_17) },
  1428. { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN_18) },
  1429. { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_PKB1700) },
  1430. { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
  1431. { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
  1432. { HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },
  1433. #if IS_ENABLED(CONFIG_HID_ROCCAT)
  1434. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) },
  1435. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ARVO) },
  1436. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_ISKU) },
  1437. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) },
  1438. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
  1439. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_LUA) },
  1440. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) },
  1441. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS) },
  1442. { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_SAVU) },
  1443. #endif
  1444. { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_PS1000) },
  1445. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
  1446. { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
  1447. { HID_USB_DEVICE(USB_VENDOR_ID_SKYCABLE, USB_DEVICE_ID_SKYCABLE_WIRELESS_PRESENTER) },
  1448. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_BDREMOTE) },
  1449. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  1450. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_NAVIGATION_CONTROLLER) },
  1451. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
  1452. { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
  1453. { HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
  1454. { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
  1455. { HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
  1456. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
  1457. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
  1458. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
  1459. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
  1460. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
  1461. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb653) },
  1462. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
  1463. { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb65a) },
  1464. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE_BT) },
  1465. { HID_USB_DEVICE(USB_VENDOR_ID_TIVO, USB_DEVICE_ID_TIVO_SLIDE) },
  1466. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
  1467. { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
  1468. { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) },
  1469. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209) },
  1470. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U) },
  1471. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP5540U) },
  1472. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U) },
  1473. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP1062) },
  1474. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_WIRELESS_TABLET_TWHL850) },
  1475. { HID_USB_DEVICE(USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_TWHA60) },
  1476. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
  1477. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) },
  1478. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD) },
  1479. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
  1480. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO) },
  1481. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO) },
  1482. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
  1483. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
  1484. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_5_8_INCH) },
  1485. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SLIM_TABLET_12_1_INCH) },
  1486. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_Q_PAD) },
  1487. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_PID_0038) },
  1488. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH) },
  1489. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH) },
  1490. { HID_USB_DEVICE(USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET) },
  1491. { HID_USB_DEVICE(USB_VENDOR_ID_X_TENSIONS, USB_DEVICE_ID_SPEEDLINK_VAD_CEZANNE) },
  1492. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
  1493. { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
  1494. { HID_USB_DEVICE(USB_VENDOR_ID_ZYDACRON, USB_DEVICE_ID_ZYDACRON_REMOTE_CONTROL) },
  1495. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
  1496. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
  1497. { }
  1498. };
  1499. struct hid_dynid {
  1500. struct list_head list;
  1501. struct hid_device_id id;
  1502. };
  1503. /**
  1504. * store_new_id - add a new HID device ID to this driver and re-probe devices
  1505. * @driver: target device driver
  1506. * @buf: buffer for scanning device ID data
  1507. * @count: input size
  1508. *
  1509. * Adds a new dynamic hid device ID to this driver,
  1510. * and causes the driver to probe for all devices again.
  1511. */
  1512. static ssize_t store_new_id(struct device_driver *drv, const char *buf,
  1513. size_t count)
  1514. {
  1515. struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
  1516. struct hid_dynid *dynid;
  1517. __u32 bus, vendor, product;
  1518. unsigned long driver_data = 0;
  1519. int ret;
  1520. ret = sscanf(buf, "%x %x %x %lx",
  1521. &bus, &vendor, &product, &driver_data);
  1522. if (ret < 3)
  1523. return -EINVAL;
  1524. dynid = kzalloc(sizeof(*dynid), GFP_KERNEL);
  1525. if (!dynid)
  1526. return -ENOMEM;
  1527. dynid->id.bus = bus;
  1528. dynid->id.group = HID_GROUP_ANY;
  1529. dynid->id.vendor = vendor;
  1530. dynid->id.product = product;
  1531. dynid->id.driver_data = driver_data;
  1532. spin_lock(&hdrv->dyn_lock);
  1533. list_add_tail(&dynid->list, &hdrv->dyn_list);
  1534. spin_unlock(&hdrv->dyn_lock);
  1535. ret = driver_attach(&hdrv->driver);
  1536. return ret ? : count;
  1537. }
  1538. static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
  1539. static void hid_free_dynids(struct hid_driver *hdrv)
  1540. {
  1541. struct hid_dynid *dynid, *n;
  1542. spin_lock(&hdrv->dyn_lock);
  1543. list_for_each_entry_safe(dynid, n, &hdrv->dyn_list, list) {
  1544. list_del(&dynid->list);
  1545. kfree(dynid);
  1546. }
  1547. spin_unlock(&hdrv->dyn_lock);
  1548. }
  1549. static const struct hid_device_id *hid_match_device(struct hid_device *hdev,
  1550. struct hid_driver *hdrv)
  1551. {
  1552. struct hid_dynid *dynid;
  1553. spin_lock(&hdrv->dyn_lock);
  1554. list_for_each_entry(dynid, &hdrv->dyn_list, list) {
  1555. if (hid_match_one_id(hdev, &dynid->id)) {
  1556. spin_unlock(&hdrv->dyn_lock);
  1557. return &dynid->id;
  1558. }
  1559. }
  1560. spin_unlock(&hdrv->dyn_lock);
  1561. return hid_match_id(hdev, hdrv->id_table);
  1562. }
  1563. static int hid_bus_match(struct device *dev, struct device_driver *drv)
  1564. {
  1565. struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
  1566. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1567. return hid_match_device(hdev, hdrv) != NULL;
  1568. }
  1569. static int hid_device_probe(struct device *dev)
  1570. {
  1571. struct hid_driver *hdrv = container_of(dev->driver,
  1572. struct hid_driver, driver);
  1573. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1574. const struct hid_device_id *id;
  1575. int ret = 0;
  1576. if (down_interruptible(&hdev->driver_lock))
  1577. return -EINTR;
  1578. if (!hdev->driver) {
  1579. id = hid_match_device(hdev, hdrv);
  1580. if (id == NULL) {
  1581. ret = -ENODEV;
  1582. goto unlock;
  1583. }
  1584. hdev->driver = hdrv;
  1585. if (hdrv->probe) {
  1586. ret = hdrv->probe(hdev, id);
  1587. } else { /* default probe */
  1588. ret = hid_open_report(hdev);
  1589. if (!ret)
  1590. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  1591. }
  1592. if (ret) {
  1593. hid_close_report(hdev);
  1594. hdev->driver = NULL;
  1595. }
  1596. }
  1597. unlock:
  1598. up(&hdev->driver_lock);
  1599. return ret;
  1600. }
  1601. static int hid_device_remove(struct device *dev)
  1602. {
  1603. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1604. struct hid_driver *hdrv;
  1605. if (down_interruptible(&hdev->driver_lock))
  1606. return -EINTR;
  1607. hdrv = hdev->driver;
  1608. if (hdrv) {
  1609. if (hdrv->remove)
  1610. hdrv->remove(hdev);
  1611. else /* default remove */
  1612. hid_hw_stop(hdev);
  1613. hid_close_report(hdev);
  1614. hdev->driver = NULL;
  1615. }
  1616. up(&hdev->driver_lock);
  1617. return 0;
  1618. }
  1619. static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
  1620. char *buf)
  1621. {
  1622. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1623. int len;
  1624. len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n",
  1625. hdev->bus, hdev->group, hdev->vendor, hdev->product);
  1626. return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
  1627. }
  1628. static struct device_attribute hid_dev_attrs[] = {
  1629. __ATTR_RO(modalias),
  1630. __ATTR_NULL,
  1631. };
  1632. static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
  1633. {
  1634. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  1635. if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
  1636. hdev->bus, hdev->vendor, hdev->product))
  1637. return -ENOMEM;
  1638. if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
  1639. return -ENOMEM;
  1640. if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
  1641. return -ENOMEM;
  1642. if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
  1643. return -ENOMEM;
  1644. if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X",
  1645. hdev->bus, hdev->group, hdev->vendor, hdev->product))
  1646. return -ENOMEM;
  1647. return 0;
  1648. }
  1649. static struct bus_type hid_bus_type = {
  1650. .name = "hid",
  1651. .dev_attrs = hid_dev_attrs,
  1652. .match = hid_bus_match,
  1653. .probe = hid_device_probe,
  1654. .remove = hid_device_remove,
  1655. .uevent = hid_uevent,
  1656. };
  1657. /* a list of devices that shouldn't be handled by HID core at all */
  1658. static const struct hid_device_id hid_ignore_list[] = {
  1659. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
  1660. { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
  1661. { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
  1662. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
  1663. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
  1664. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
  1665. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
  1666. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
  1667. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
  1668. { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
  1669. { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
  1670. { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
  1671. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
  1672. { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
  1673. { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
  1674. { HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
  1675. { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
  1676. { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
  1677. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
  1678. { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
  1679. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
  1680. { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
  1681. { HID_USB_DEVICE(USB_VENDOR_ID_DEALEXTREAME, USB_DEVICE_ID_DEALEXTREAME_RADIO_SI4701) },
  1682. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
  1683. { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
  1684. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x0004) },
  1685. { HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY, 0x000a) },
  1686. { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
  1687. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) },
  1688. { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
  1689. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
  1690. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
  1691. { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
  1692. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
  1693. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
  1694. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
  1695. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
  1696. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
  1697. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
  1698. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
  1699. { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
  1700. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
  1701. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
  1702. { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
  1703. { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
  1704. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
  1705. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
  1706. { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_RADIOSHARK) },
  1707. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
  1708. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
  1709. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
  1710. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
  1711. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
  1712. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
  1713. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
  1714. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
  1715. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
  1716. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
  1717. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
  1718. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
  1719. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
  1720. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
  1721. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
  1722. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
  1723. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
  1724. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
  1725. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
  1726. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
  1727. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
  1728. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
  1729. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
  1730. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
  1731. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
  1732. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
  1733. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
  1734. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
  1735. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
  1736. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
  1737. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
  1738. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
  1739. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
  1740. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
  1741. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
  1742. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
  1743. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
  1744. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
  1745. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
  1746. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
  1747. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
  1748. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
  1749. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
  1750. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
  1751. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
  1752. { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
  1753. { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
  1754. { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
  1755. { HID_USB_DEVICE(USB_VENDOR_ID_KWORLD, USB_DEVICE_ID_KWORLD_RADIO_FM700) },
  1756. { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
  1757. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_KYE, 0x0058) },
  1758. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
  1759. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY2) },
  1760. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
  1761. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY2) },
  1762. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
  1763. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY2) },
  1764. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYVOLTAGE) },
  1765. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYCURRENT) },
  1766. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTIME) },
  1767. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE) },
  1768. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MICROCASSYPH) },
  1769. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
  1770. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
  1771. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
  1772. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIC) },
  1773. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIB) },
  1774. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY) },
  1775. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
  1776. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
  1777. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOTOR) },
  1778. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
  1779. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
  1780. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
  1781. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
  1782. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
  1783. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER) },
  1784. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOSTANALYSER2) },
  1785. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_ABSESP) },
  1786. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_AUTODATABUS) },
  1787. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MCT) },
  1788. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
  1789. { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
  1790. { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
  1791. { HID_USB_DEVICE(USB_VENDOR_ID_MASTERKIT, USB_DEVICE_ID_MASTERKIT_MA901RADIO) },
  1792. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
  1793. { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
  1794. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
  1795. { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
  1796. { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
  1797. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
  1798. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
  1799. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
  1800. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
  1801. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
  1802. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
  1803. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
  1804. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
  1805. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
  1806. { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
  1807. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
  1808. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
  1809. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
  1810. { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
  1811. { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
  1812. { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
  1813. #if defined(CONFIG_MOUSE_SYNAPTICS_USB) || defined(CONFIG_MOUSE_SYNAPTICS_USB_MODULE)
  1814. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_TP) },
  1815. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_INT_TP) },
  1816. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_CPAD) },
  1817. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_STICK) },
  1818. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WP) },
  1819. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_COMP_TP) },
  1820. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_WTP) },
  1821. { HID_USB_DEVICE(USB_VENDOR_ID_SYNAPTICS, USB_DEVICE_ID_SYNAPTICS_DPAD) },
  1822. #endif
  1823. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
  1824. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
  1825. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
  1826. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
  1827. { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
  1828. { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
  1829. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
  1830. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
  1831. { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
  1832. { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
  1833. { }
  1834. };
  1835. /**
  1836. * hid_mouse_ignore_list - mouse devices which should not be handled by the hid layer
  1837. *
  1838. * There are composite devices for which we want to ignore only a certain
  1839. * interface. This is a list of devices for which only the mouse interface will
  1840. * be ignored. This allows a dedicated driver to take care of the interface.
  1841. */
  1842. static const struct hid_device_id hid_mouse_ignore_list[] = {
  1843. /* appletouch driver */
  1844. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
  1845. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
  1846. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
  1847. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
  1848. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
  1849. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
  1850. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
  1851. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
  1852. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
  1853. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
  1854. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
  1855. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
  1856. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
  1857. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
  1858. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
  1859. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
  1860. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
  1861. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
  1862. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
  1863. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
  1864. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ANSI) },
  1865. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_ISO) },
  1866. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING3_JIS) },
  1867. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI) },
  1868. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_ISO) },
  1869. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4_JIS) },
  1870. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ANSI) },
  1871. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_ISO) },
  1872. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) },
  1873. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
  1874. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
  1875. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
  1876. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
  1877. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
  1878. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
  1879. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
  1880. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
  1881. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
  1882. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI) },
  1883. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO) },
  1884. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS) },
  1885. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ANSI) },
  1886. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_ISO) },
  1887. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7_JIS) },
  1888. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ANSI) },
  1889. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_ISO) },
  1890. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING7A_JIS) },
  1891. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
  1892. { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
  1893. { }
  1894. };
  1895. bool hid_ignore(struct hid_device *hdev)
  1896. {
  1897. if (hdev->quirks & HID_QUIRK_NO_IGNORE)
  1898. return false;
  1899. if (hdev->quirks & HID_QUIRK_IGNORE)
  1900. return true;
  1901. switch (hdev->vendor) {
  1902. case USB_VENDOR_ID_CODEMERCS:
  1903. /* ignore all Code Mercenaries IOWarrior devices */
  1904. if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
  1905. hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
  1906. return true;
  1907. break;
  1908. case USB_VENDOR_ID_LOGITECH:
  1909. if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
  1910. hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
  1911. return true;
  1912. /*
  1913. * The Keene FM transmitter USB device has the same USB ID as
  1914. * the Logitech AudioHub Speaker, but it should ignore the hid.
  1915. * Check if the name is that of the Keene device.
  1916. * For reference: the name of the AudioHub is
  1917. * "HOLTEK AudioHub Speaker".
  1918. */
  1919. if (hdev->product == USB_DEVICE_ID_LOGITECH_AUDIOHUB &&
  1920. !strcmp(hdev->name, "HOLTEK B-LINK USB Audio "))
  1921. return true;
  1922. break;
  1923. case USB_VENDOR_ID_SOUNDGRAPH:
  1924. if (hdev->product >= USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST &&
  1925. hdev->product <= USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST)
  1926. return true;
  1927. break;
  1928. case USB_VENDOR_ID_HANWANG:
  1929. if (hdev->product >= USB_DEVICE_ID_HANWANG_TABLET_FIRST &&
  1930. hdev->product <= USB_DEVICE_ID_HANWANG_TABLET_LAST)
  1931. return true;
  1932. break;
  1933. case USB_VENDOR_ID_JESS:
  1934. if (hdev->product == USB_DEVICE_ID_JESS_YUREX &&
  1935. hdev->type == HID_TYPE_USBNONE)
  1936. return true;
  1937. break;
  1938. case USB_VENDOR_ID_DWAV:
  1939. /* These are handled by usbtouchscreen. hdev->type is probably
  1940. * HID_TYPE_USBNONE, but we say !HID_TYPE_USBMOUSE to match
  1941. * usbtouchscreen. */
  1942. if ((hdev->product == USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER ||
  1943. hdev->product == USB_DEVICE_ID_DWAV_TOUCHCONTROLLER) &&
  1944. hdev->type != HID_TYPE_USBMOUSE)
  1945. return true;
  1946. break;
  1947. case USB_VENDOR_ID_VELLEMAN:
  1948. /* These are not HID devices. They are handled by comedi. */
  1949. if ((hdev->product >= USB_DEVICE_ID_VELLEMAN_K8055_FIRST &&
  1950. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8055_LAST) ||
  1951. (hdev->product >= USB_DEVICE_ID_VELLEMAN_K8061_FIRST &&
  1952. hdev->product <= USB_DEVICE_ID_VELLEMAN_K8061_LAST))
  1953. return true;
  1954. break;
  1955. }
  1956. if (hdev->type == HID_TYPE_USBMOUSE &&
  1957. hid_match_id(hdev, hid_mouse_ignore_list))
  1958. return true;
  1959. return !!hid_match_id(hdev, hid_ignore_list);
  1960. }
  1961. EXPORT_SYMBOL_GPL(hid_ignore);
  1962. int hid_add_device(struct hid_device *hdev)
  1963. {
  1964. static atomic_t id = ATOMIC_INIT(0);
  1965. int ret;
  1966. if (WARN_ON(hdev->status & HID_STAT_ADDED))
  1967. return -EBUSY;
  1968. /* we need to kill them here, otherwise they will stay allocated to
  1969. * wait for coming driver */
  1970. if (hid_ignore(hdev))
  1971. return -ENODEV;
  1972. /*
  1973. * Read the device report descriptor once and use as template
  1974. * for the driver-specific modifications.
  1975. */
  1976. ret = hdev->ll_driver->parse(hdev);
  1977. if (ret)
  1978. return ret;
  1979. if (!hdev->dev_rdesc)
  1980. return -ENODEV;
  1981. /*
  1982. * Scan generic devices for group information
  1983. */
  1984. if (hid_ignore_special_drivers ||
  1985. !hid_match_id(hdev, hid_have_special_driver)) {
  1986. ret = hid_scan_report(hdev);
  1987. if (ret)
  1988. hid_warn(hdev, "bad device descriptor (%d)\n", ret);
  1989. }
  1990. /* XXX hack, any other cleaner solution after the driver core
  1991. * is converted to allow more than 20 bytes as the device name? */
  1992. dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
  1993. hdev->vendor, hdev->product, atomic_inc_return(&id));
  1994. hid_debug_register(hdev, dev_name(&hdev->dev));
  1995. ret = device_add(&hdev->dev);
  1996. if (!ret)
  1997. hdev->status |= HID_STAT_ADDED;
  1998. else
  1999. hid_debug_unregister(hdev);
  2000. return ret;
  2001. }
  2002. EXPORT_SYMBOL_GPL(hid_add_device);
  2003. /**
  2004. * hid_allocate_device - allocate new hid device descriptor
  2005. *
  2006. * Allocate and initialize hid device, so that hid_destroy_device might be
  2007. * used to free it.
  2008. *
  2009. * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
  2010. * error value.
  2011. */
  2012. struct hid_device *hid_allocate_device(void)
  2013. {
  2014. struct hid_device *hdev;
  2015. int ret = -ENOMEM;
  2016. hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
  2017. if (hdev == NULL)
  2018. return ERR_PTR(ret);
  2019. device_initialize(&hdev->dev);
  2020. hdev->dev.release = hid_device_release;
  2021. hdev->dev.bus = &hid_bus_type;
  2022. hid_close_report(hdev);
  2023. init_waitqueue_head(&hdev->debug_wait);
  2024. INIT_LIST_HEAD(&hdev->debug_list);
  2025. sema_init(&hdev->driver_lock, 1);
  2026. return hdev;
  2027. }
  2028. EXPORT_SYMBOL_GPL(hid_allocate_device);
  2029. static void hid_remove_device(struct hid_device *hdev)
  2030. {
  2031. if (hdev->status & HID_STAT_ADDED) {
  2032. device_del(&hdev->dev);
  2033. hid_debug_unregister(hdev);
  2034. hdev->status &= ~HID_STAT_ADDED;
  2035. }
  2036. kfree(hdev->dev_rdesc);
  2037. hdev->dev_rdesc = NULL;
  2038. hdev->dev_rsize = 0;
  2039. }
  2040. /**
  2041. * hid_destroy_device - free previously allocated device
  2042. *
  2043. * @hdev: hid device
  2044. *
  2045. * If you allocate hid_device through hid_allocate_device, you should ever
  2046. * free by this function.
  2047. */
  2048. void hid_destroy_device(struct hid_device *hdev)
  2049. {
  2050. hid_remove_device(hdev);
  2051. put_device(&hdev->dev);
  2052. }
  2053. EXPORT_SYMBOL_GPL(hid_destroy_device);
  2054. int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
  2055. const char *mod_name)
  2056. {
  2057. int ret;
  2058. hdrv->driver.name = hdrv->name;
  2059. hdrv->driver.bus = &hid_bus_type;
  2060. hdrv->driver.owner = owner;
  2061. hdrv->driver.mod_name = mod_name;
  2062. INIT_LIST_HEAD(&hdrv->dyn_list);
  2063. spin_lock_init(&hdrv->dyn_lock);
  2064. ret = driver_register(&hdrv->driver);
  2065. if (ret)
  2066. return ret;
  2067. ret = driver_create_file(&hdrv->driver, &driver_attr_new_id);
  2068. if (ret)
  2069. driver_unregister(&hdrv->driver);
  2070. return ret;
  2071. }
  2072. EXPORT_SYMBOL_GPL(__hid_register_driver);
  2073. void hid_unregister_driver(struct hid_driver *hdrv)
  2074. {
  2075. driver_remove_file(&hdrv->driver, &driver_attr_new_id);
  2076. driver_unregister(&hdrv->driver);
  2077. hid_free_dynids(hdrv);
  2078. }
  2079. EXPORT_SYMBOL_GPL(hid_unregister_driver);
  2080. int hid_check_keys_pressed(struct hid_device *hid)
  2081. {
  2082. struct hid_input *hidinput;
  2083. int i;
  2084. if (!(hid->claimed & HID_CLAIMED_INPUT))
  2085. return 0;
  2086. list_for_each_entry(hidinput, &hid->inputs, list) {
  2087. for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
  2088. if (hidinput->input->key[i])
  2089. return 1;
  2090. }
  2091. return 0;
  2092. }
  2093. EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
  2094. static int __init hid_init(void)
  2095. {
  2096. int ret;
  2097. if (hid_debug)
  2098. pr_warn("hid_debug is now used solely for parser and driver debugging.\n"
  2099. "debugfs is now used for inspecting the device (report descriptor, reports)\n");
  2100. ret = bus_register(&hid_bus_type);
  2101. if (ret) {
  2102. pr_err("can't register hid bus\n");
  2103. goto err;
  2104. }
  2105. ret = hidraw_init();
  2106. if (ret)
  2107. goto err_bus;
  2108. hid_debug_init();
  2109. return 0;
  2110. err_bus:
  2111. bus_unregister(&hid_bus_type);
  2112. err:
  2113. return ret;
  2114. }
  2115. static void __exit hid_exit(void)
  2116. {
  2117. hid_debug_exit();
  2118. hidraw_exit();
  2119. bus_unregister(&hid_bus_type);
  2120. }
  2121. module_init(hid_init);
  2122. module_exit(hid_exit);
  2123. MODULE_AUTHOR("Andreas Gal");
  2124. MODULE_AUTHOR("Vojtech Pavlik");
  2125. MODULE_AUTHOR("Jiri Kosina");
  2126. MODULE_LICENSE(DRIVER_LICENSE);