hid-core.c 68 KB

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