hid-core.c 81 KB

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