hid-core.c 81 KB

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