hid-core.c 81 KB

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