hid-core.c 81 KB

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