hid-core.c 82 KB

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