netlink.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2011 Instituto Nokia de Tecnologia
  4. *
  5. * Authors:
  6. * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
  7. * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
  8. *
  9. * Vendor commands implementation based on net/wireless/nl80211.c
  10. * which is:
  11. *
  12. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  13. * Copyright 2013-2014 Intel Mobile Communications GmbH
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
  16. #include <net/genetlink.h>
  17. #include <linux/nfc.h>
  18. #include <linux/slab.h>
  19. #include "nfc.h"
  20. #include "llcp.h"
  21. static const struct genl_multicast_group nfc_genl_mcgrps[] = {
  22. { .name = NFC_GENL_MCAST_EVENT_NAME, },
  23. };
  24. static struct genl_family nfc_genl_family;
  25. static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = {
  26. [NFC_ATTR_DEVICE_INDEX] = { .type = NLA_U32 },
  27. [NFC_ATTR_DEVICE_NAME] = { .type = NLA_STRING,
  28. .len = NFC_DEVICE_NAME_MAXSIZE },
  29. [NFC_ATTR_PROTOCOLS] = { .type = NLA_U32 },
  30. [NFC_ATTR_TARGET_INDEX] = { .type = NLA_U32 },
  31. [NFC_ATTR_COMM_MODE] = { .type = NLA_U8 },
  32. [NFC_ATTR_RF_MODE] = { .type = NLA_U8 },
  33. [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 },
  34. [NFC_ATTR_IM_PROTOCOLS] = { .type = NLA_U32 },
  35. [NFC_ATTR_TM_PROTOCOLS] = { .type = NLA_U32 },
  36. [NFC_ATTR_LLC_PARAM_LTO] = { .type = NLA_U8 },
  37. [NFC_ATTR_LLC_PARAM_RW] = { .type = NLA_U8 },
  38. [NFC_ATTR_LLC_PARAM_MIUX] = { .type = NLA_U16 },
  39. [NFC_ATTR_LLC_SDP] = { .type = NLA_NESTED },
  40. [NFC_ATTR_FIRMWARE_NAME] = { .type = NLA_STRING,
  41. .len = NFC_FIRMWARE_NAME_MAXSIZE },
  42. [NFC_ATTR_SE_INDEX] = { .type = NLA_U32 },
  43. [NFC_ATTR_SE_APDU] = { .type = NLA_BINARY },
  44. [NFC_ATTR_VENDOR_ID] = { .type = NLA_U32 },
  45. [NFC_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
  46. [NFC_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
  47. };
  48. static const struct nla_policy nfc_sdp_genl_policy[NFC_SDP_ATTR_MAX + 1] = {
  49. [NFC_SDP_ATTR_URI] = { .type = NLA_STRING,
  50. .len = U8_MAX - 4 },
  51. [NFC_SDP_ATTR_SAP] = { .type = NLA_U8 },
  52. };
  53. static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
  54. struct netlink_callback *cb, int flags)
  55. {
  56. void *hdr;
  57. hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
  58. &nfc_genl_family, flags, NFC_CMD_GET_TARGET);
  59. if (!hdr)
  60. return -EMSGSIZE;
  61. genl_dump_check_consistent(cb, hdr);
  62. if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) ||
  63. nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) ||
  64. nla_put_u16(msg, NFC_ATTR_TARGET_SENS_RES, target->sens_res) ||
  65. nla_put_u8(msg, NFC_ATTR_TARGET_SEL_RES, target->sel_res))
  66. goto nla_put_failure;
  67. if (target->nfcid1_len > 0 &&
  68. nla_put(msg, NFC_ATTR_TARGET_NFCID1, target->nfcid1_len,
  69. target->nfcid1))
  70. goto nla_put_failure;
  71. if (target->sensb_res_len > 0 &&
  72. nla_put(msg, NFC_ATTR_TARGET_SENSB_RES, target->sensb_res_len,
  73. target->sensb_res))
  74. goto nla_put_failure;
  75. if (target->sensf_res_len > 0 &&
  76. nla_put(msg, NFC_ATTR_TARGET_SENSF_RES, target->sensf_res_len,
  77. target->sensf_res))
  78. goto nla_put_failure;
  79. if (target->is_iso15693) {
  80. if (nla_put_u8(msg, NFC_ATTR_TARGET_ISO15693_DSFID,
  81. target->iso15693_dsfid) ||
  82. nla_put(msg, NFC_ATTR_TARGET_ISO15693_UID,
  83. sizeof(target->iso15693_uid), target->iso15693_uid))
  84. goto nla_put_failure;
  85. }
  86. genlmsg_end(msg, hdr);
  87. return 0;
  88. nla_put_failure:
  89. genlmsg_cancel(msg, hdr);
  90. return -EMSGSIZE;
  91. }
  92. static struct nfc_dev *__get_device_from_cb(struct netlink_callback *cb)
  93. {
  94. const struct genl_dumpit_info *info = genl_dumpit_info(cb);
  95. struct nfc_dev *dev;
  96. u32 idx;
  97. if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
  98. return ERR_PTR(-EINVAL);
  99. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  100. dev = nfc_get_device(idx);
  101. if (!dev)
  102. return ERR_PTR(-ENODEV);
  103. return dev;
  104. }
  105. static int nfc_genl_dump_targets(struct sk_buff *skb,
  106. struct netlink_callback *cb)
  107. {
  108. int i = cb->args[0];
  109. struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
  110. int rc;
  111. if (!dev) {
  112. dev = __get_device_from_cb(cb);
  113. if (IS_ERR(dev))
  114. return PTR_ERR(dev);
  115. cb->args[1] = (long) dev;
  116. }
  117. device_lock(&dev->dev);
  118. cb->seq = dev->targets_generation;
  119. while (i < dev->n_targets) {
  120. rc = nfc_genl_send_target(skb, &dev->targets[i], cb,
  121. NLM_F_MULTI);
  122. if (rc < 0)
  123. break;
  124. i++;
  125. }
  126. device_unlock(&dev->dev);
  127. cb->args[0] = i;
  128. return skb->len;
  129. }
  130. static int nfc_genl_dump_targets_done(struct netlink_callback *cb)
  131. {
  132. struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
  133. if (dev)
  134. nfc_put_device(dev);
  135. return 0;
  136. }
  137. int nfc_genl_targets_found(struct nfc_dev *dev)
  138. {
  139. struct sk_buff *msg;
  140. void *hdr;
  141. dev->genl_data.poll_req_portid = 0;
  142. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  143. if (!msg)
  144. return -ENOMEM;
  145. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  146. NFC_EVENT_TARGETS_FOUND);
  147. if (!hdr)
  148. goto free_msg;
  149. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  150. goto nla_put_failure;
  151. genlmsg_end(msg, hdr);
  152. return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
  153. nla_put_failure:
  154. free_msg:
  155. nlmsg_free(msg);
  156. return -EMSGSIZE;
  157. }
  158. int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
  159. {
  160. struct sk_buff *msg;
  161. void *hdr;
  162. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  163. if (!msg)
  164. return -ENOMEM;
  165. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  166. NFC_EVENT_TARGET_LOST);
  167. if (!hdr)
  168. goto free_msg;
  169. if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
  170. nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
  171. goto nla_put_failure;
  172. genlmsg_end(msg, hdr);
  173. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  174. return 0;
  175. nla_put_failure:
  176. free_msg:
  177. nlmsg_free(msg);
  178. return -EMSGSIZE;
  179. }
  180. int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
  181. {
  182. struct sk_buff *msg;
  183. void *hdr;
  184. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  185. if (!msg)
  186. return -ENOMEM;
  187. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  188. NFC_EVENT_TM_ACTIVATED);
  189. if (!hdr)
  190. goto free_msg;
  191. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  192. goto nla_put_failure;
  193. if (nla_put_u32(msg, NFC_ATTR_TM_PROTOCOLS, protocol))
  194. goto nla_put_failure;
  195. genlmsg_end(msg, hdr);
  196. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  197. return 0;
  198. nla_put_failure:
  199. free_msg:
  200. nlmsg_free(msg);
  201. return -EMSGSIZE;
  202. }
  203. int nfc_genl_tm_deactivated(struct nfc_dev *dev)
  204. {
  205. struct sk_buff *msg;
  206. void *hdr;
  207. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  208. if (!msg)
  209. return -ENOMEM;
  210. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  211. NFC_EVENT_TM_DEACTIVATED);
  212. if (!hdr)
  213. goto free_msg;
  214. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  215. goto nla_put_failure;
  216. genlmsg_end(msg, hdr);
  217. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  218. return 0;
  219. nla_put_failure:
  220. free_msg:
  221. nlmsg_free(msg);
  222. return -EMSGSIZE;
  223. }
  224. static int nfc_genl_setup_device_added(struct nfc_dev *dev, struct sk_buff *msg)
  225. {
  226. if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
  227. nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
  228. nla_put_u32(msg, NFC_ATTR_PROTOCOLS, dev->supported_protocols) ||
  229. nla_put_u8(msg, NFC_ATTR_DEVICE_POWERED, dev->dev_up) ||
  230. nla_put_u8(msg, NFC_ATTR_RF_MODE, dev->rf_mode))
  231. return -1;
  232. return 0;
  233. }
  234. int nfc_genl_device_added(struct nfc_dev *dev)
  235. {
  236. struct sk_buff *msg;
  237. void *hdr;
  238. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  239. if (!msg)
  240. return -ENOMEM;
  241. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  242. NFC_EVENT_DEVICE_ADDED);
  243. if (!hdr)
  244. goto free_msg;
  245. if (nfc_genl_setup_device_added(dev, msg))
  246. goto nla_put_failure;
  247. genlmsg_end(msg, hdr);
  248. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  249. return 0;
  250. nla_put_failure:
  251. free_msg:
  252. nlmsg_free(msg);
  253. return -EMSGSIZE;
  254. }
  255. int nfc_genl_device_removed(struct nfc_dev *dev)
  256. {
  257. struct sk_buff *msg;
  258. void *hdr;
  259. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  260. if (!msg)
  261. return -ENOMEM;
  262. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  263. NFC_EVENT_DEVICE_REMOVED);
  264. if (!hdr)
  265. goto free_msg;
  266. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  267. goto nla_put_failure;
  268. genlmsg_end(msg, hdr);
  269. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  270. return 0;
  271. nla_put_failure:
  272. free_msg:
  273. nlmsg_free(msg);
  274. return -EMSGSIZE;
  275. }
  276. int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
  277. {
  278. struct sk_buff *msg;
  279. struct nlattr *sdp_attr, *uri_attr;
  280. struct nfc_llcp_sdp_tlv *sdres;
  281. struct hlist_node *n;
  282. void *hdr;
  283. int rc = -EMSGSIZE;
  284. int i;
  285. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  286. if (!msg)
  287. return -ENOMEM;
  288. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  289. NFC_EVENT_LLC_SDRES);
  290. if (!hdr)
  291. goto free_msg;
  292. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  293. goto nla_put_failure;
  294. sdp_attr = nla_nest_start_noflag(msg, NFC_ATTR_LLC_SDP);
  295. if (sdp_attr == NULL) {
  296. rc = -ENOMEM;
  297. goto nla_put_failure;
  298. }
  299. i = 1;
  300. hlist_for_each_entry_safe(sdres, n, sdres_list, node) {
  301. pr_debug("uri: %s, sap: %d\n", sdres->uri, sdres->sap);
  302. uri_attr = nla_nest_start_noflag(msg, i++);
  303. if (uri_attr == NULL) {
  304. rc = -ENOMEM;
  305. goto nla_put_failure;
  306. }
  307. if (nla_put_u8(msg, NFC_SDP_ATTR_SAP, sdres->sap))
  308. goto nla_put_failure;
  309. if (nla_put_string(msg, NFC_SDP_ATTR_URI, sdres->uri))
  310. goto nla_put_failure;
  311. nla_nest_end(msg, uri_attr);
  312. hlist_del(&sdres->node);
  313. nfc_llcp_free_sdp_tlv(sdres);
  314. }
  315. nla_nest_end(msg, sdp_attr);
  316. genlmsg_end(msg, hdr);
  317. return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
  318. nla_put_failure:
  319. free_msg:
  320. nlmsg_free(msg);
  321. nfc_llcp_free_sdp_tlv_list(sdres_list);
  322. return rc;
  323. }
  324. int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
  325. {
  326. struct sk_buff *msg;
  327. void *hdr;
  328. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  329. if (!msg)
  330. return -ENOMEM;
  331. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  332. NFC_EVENT_SE_ADDED);
  333. if (!hdr)
  334. goto free_msg;
  335. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
  336. nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
  337. nla_put_u8(msg, NFC_ATTR_SE_TYPE, type))
  338. goto nla_put_failure;
  339. genlmsg_end(msg, hdr);
  340. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  341. return 0;
  342. nla_put_failure:
  343. free_msg:
  344. nlmsg_free(msg);
  345. return -EMSGSIZE;
  346. }
  347. int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
  348. {
  349. struct sk_buff *msg;
  350. void *hdr;
  351. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  352. if (!msg)
  353. return -ENOMEM;
  354. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  355. NFC_EVENT_SE_REMOVED);
  356. if (!hdr)
  357. goto free_msg;
  358. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
  359. nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx))
  360. goto nla_put_failure;
  361. genlmsg_end(msg, hdr);
  362. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  363. return 0;
  364. nla_put_failure:
  365. free_msg:
  366. nlmsg_free(msg);
  367. return -EMSGSIZE;
  368. }
  369. int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx,
  370. struct nfc_evt_transaction *evt_transaction)
  371. {
  372. struct nfc_se *se;
  373. struct sk_buff *msg;
  374. void *hdr;
  375. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  376. if (!msg)
  377. return -ENOMEM;
  378. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  379. NFC_EVENT_SE_TRANSACTION);
  380. if (!hdr)
  381. goto free_msg;
  382. se = nfc_find_se(dev, se_idx);
  383. if (!se)
  384. goto free_msg;
  385. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
  386. nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
  387. nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type) ||
  388. nla_put(msg, NFC_ATTR_SE_AID, evt_transaction->aid_len,
  389. evt_transaction->aid) ||
  390. nla_put(msg, NFC_ATTR_SE_PARAMS, evt_transaction->params_len,
  391. evt_transaction->params))
  392. goto nla_put_failure;
  393. /* evt_transaction is no more used */
  394. devm_kfree(&dev->dev, evt_transaction);
  395. genlmsg_end(msg, hdr);
  396. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  397. return 0;
  398. nla_put_failure:
  399. free_msg:
  400. /* evt_transaction is no more used */
  401. devm_kfree(&dev->dev, evt_transaction);
  402. nlmsg_free(msg);
  403. return -EMSGSIZE;
  404. }
  405. int nfc_genl_se_connectivity(struct nfc_dev *dev, u8 se_idx)
  406. {
  407. struct nfc_se *se;
  408. struct sk_buff *msg;
  409. void *hdr;
  410. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  411. if (!msg)
  412. return -ENOMEM;
  413. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  414. NFC_EVENT_SE_CONNECTIVITY);
  415. if (!hdr)
  416. goto free_msg;
  417. se = nfc_find_se(dev, se_idx);
  418. if (!se)
  419. goto free_msg;
  420. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
  421. nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) ||
  422. nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
  423. goto nla_put_failure;
  424. genlmsg_end(msg, hdr);
  425. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  426. return 0;
  427. nla_put_failure:
  428. free_msg:
  429. nlmsg_free(msg);
  430. return -EMSGSIZE;
  431. }
  432. static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
  433. u32 portid, u32 seq,
  434. struct netlink_callback *cb,
  435. int flags)
  436. {
  437. void *hdr;
  438. hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
  439. NFC_CMD_GET_DEVICE);
  440. if (!hdr)
  441. return -EMSGSIZE;
  442. if (cb)
  443. genl_dump_check_consistent(cb, hdr);
  444. if (nfc_genl_setup_device_added(dev, msg))
  445. goto nla_put_failure;
  446. genlmsg_end(msg, hdr);
  447. return 0;
  448. nla_put_failure:
  449. genlmsg_cancel(msg, hdr);
  450. return -EMSGSIZE;
  451. }
  452. static int nfc_genl_dump_devices(struct sk_buff *skb,
  453. struct netlink_callback *cb)
  454. {
  455. struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
  456. struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
  457. bool first_call = false;
  458. if (!iter) {
  459. first_call = true;
  460. iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
  461. if (!iter)
  462. return -ENOMEM;
  463. cb->args[0] = (long) iter;
  464. }
  465. mutex_lock(&nfc_devlist_mutex);
  466. cb->seq = nfc_devlist_generation;
  467. if (first_call) {
  468. nfc_device_iter_init(iter);
  469. dev = nfc_device_iter_next(iter);
  470. }
  471. while (dev) {
  472. int rc;
  473. rc = nfc_genl_send_device(skb, dev, NETLINK_CB(cb->skb).portid,
  474. cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
  475. if (rc < 0)
  476. break;
  477. dev = nfc_device_iter_next(iter);
  478. }
  479. mutex_unlock(&nfc_devlist_mutex);
  480. cb->args[1] = (long) dev;
  481. return skb->len;
  482. }
  483. static int nfc_genl_dump_devices_done(struct netlink_callback *cb)
  484. {
  485. struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
  486. if (iter) {
  487. nfc_device_iter_exit(iter);
  488. kfree(iter);
  489. }
  490. return 0;
  491. }
  492. int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
  493. u8 comm_mode, u8 rf_mode)
  494. {
  495. struct sk_buff *msg;
  496. void *hdr;
  497. pr_debug("DEP link is up\n");
  498. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  499. if (!msg)
  500. return -ENOMEM;
  501. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, NFC_CMD_DEP_LINK_UP);
  502. if (!hdr)
  503. goto free_msg;
  504. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  505. goto nla_put_failure;
  506. if (rf_mode == NFC_RF_INITIATOR &&
  507. nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
  508. goto nla_put_failure;
  509. if (nla_put_u8(msg, NFC_ATTR_COMM_MODE, comm_mode) ||
  510. nla_put_u8(msg, NFC_ATTR_RF_MODE, rf_mode))
  511. goto nla_put_failure;
  512. genlmsg_end(msg, hdr);
  513. dev->dep_link_up = true;
  514. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
  515. return 0;
  516. nla_put_failure:
  517. free_msg:
  518. nlmsg_free(msg);
  519. return -EMSGSIZE;
  520. }
  521. int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
  522. {
  523. struct sk_buff *msg;
  524. void *hdr;
  525. pr_debug("DEP link is down\n");
  526. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
  527. if (!msg)
  528. return -ENOMEM;
  529. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  530. NFC_CMD_DEP_LINK_DOWN);
  531. if (!hdr)
  532. goto free_msg;
  533. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  534. goto nla_put_failure;
  535. genlmsg_end(msg, hdr);
  536. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
  537. return 0;
  538. nla_put_failure:
  539. free_msg:
  540. nlmsg_free(msg);
  541. return -EMSGSIZE;
  542. }
  543. static int nfc_genl_get_device(struct sk_buff *skb, struct genl_info *info)
  544. {
  545. struct sk_buff *msg;
  546. struct nfc_dev *dev;
  547. u32 idx;
  548. int rc = -ENOBUFS;
  549. if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
  550. return -EINVAL;
  551. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  552. dev = nfc_get_device(idx);
  553. if (!dev)
  554. return -ENODEV;
  555. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  556. if (!msg) {
  557. rc = -ENOMEM;
  558. goto out_putdev;
  559. }
  560. rc = nfc_genl_send_device(msg, dev, info->snd_portid, info->snd_seq,
  561. NULL, 0);
  562. if (rc < 0)
  563. goto out_free;
  564. nfc_put_device(dev);
  565. return genlmsg_reply(msg, info);
  566. out_free:
  567. nlmsg_free(msg);
  568. out_putdev:
  569. nfc_put_device(dev);
  570. return rc;
  571. }
  572. static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
  573. {
  574. struct nfc_dev *dev;
  575. int rc;
  576. u32 idx;
  577. if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
  578. return -EINVAL;
  579. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  580. dev = nfc_get_device(idx);
  581. if (!dev)
  582. return -ENODEV;
  583. rc = nfc_dev_up(dev);
  584. nfc_put_device(dev);
  585. return rc;
  586. }
  587. static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
  588. {
  589. struct nfc_dev *dev;
  590. int rc;
  591. u32 idx;
  592. if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
  593. return -EINVAL;
  594. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  595. dev = nfc_get_device(idx);
  596. if (!dev)
  597. return -ENODEV;
  598. rc = nfc_dev_down(dev);
  599. nfc_put_device(dev);
  600. return rc;
  601. }
  602. static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
  603. {
  604. struct nfc_dev *dev;
  605. int rc;
  606. u32 idx;
  607. u32 im_protocols = 0, tm_protocols = 0;
  608. pr_debug("Poll start\n");
  609. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  610. ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
  611. !info->attrs[NFC_ATTR_PROTOCOLS]) &&
  612. !info->attrs[NFC_ATTR_TM_PROTOCOLS]))
  613. return -EINVAL;
  614. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  615. if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
  616. tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
  617. if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
  618. im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
  619. else if (info->attrs[NFC_ATTR_PROTOCOLS])
  620. im_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
  621. dev = nfc_get_device(idx);
  622. if (!dev)
  623. return -ENODEV;
  624. mutex_lock(&dev->genl_data.genl_data_mutex);
  625. rc = nfc_start_poll(dev, im_protocols, tm_protocols);
  626. if (!rc)
  627. dev->genl_data.poll_req_portid = info->snd_portid;
  628. mutex_unlock(&dev->genl_data.genl_data_mutex);
  629. nfc_put_device(dev);
  630. return rc;
  631. }
  632. static int nfc_genl_stop_poll(struct sk_buff *skb, struct genl_info *info)
  633. {
  634. struct nfc_dev *dev;
  635. int rc;
  636. u32 idx;
  637. if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
  638. return -EINVAL;
  639. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  640. dev = nfc_get_device(idx);
  641. if (!dev)
  642. return -ENODEV;
  643. device_lock(&dev->dev);
  644. if (!dev->polling) {
  645. device_unlock(&dev->dev);
  646. nfc_put_device(dev);
  647. return -EINVAL;
  648. }
  649. device_unlock(&dev->dev);
  650. mutex_lock(&dev->genl_data.genl_data_mutex);
  651. if (dev->genl_data.poll_req_portid != info->snd_portid) {
  652. rc = -EBUSY;
  653. goto out;
  654. }
  655. rc = nfc_stop_poll(dev);
  656. dev->genl_data.poll_req_portid = 0;
  657. out:
  658. mutex_unlock(&dev->genl_data.genl_data_mutex);
  659. nfc_put_device(dev);
  660. return rc;
  661. }
  662. static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info)
  663. {
  664. struct nfc_dev *dev;
  665. u32 device_idx, target_idx, protocol;
  666. int rc;
  667. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  668. !info->attrs[NFC_ATTR_TARGET_INDEX] ||
  669. !info->attrs[NFC_ATTR_PROTOCOLS])
  670. return -EINVAL;
  671. device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  672. dev = nfc_get_device(device_idx);
  673. if (!dev)
  674. return -ENODEV;
  675. target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
  676. protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
  677. nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
  678. rc = nfc_activate_target(dev, target_idx, protocol);
  679. nfc_put_device(dev);
  680. return rc;
  681. }
  682. static int nfc_genl_deactivate_target(struct sk_buff *skb,
  683. struct genl_info *info)
  684. {
  685. struct nfc_dev *dev;
  686. u32 device_idx, target_idx;
  687. int rc;
  688. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  689. !info->attrs[NFC_ATTR_TARGET_INDEX])
  690. return -EINVAL;
  691. device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  692. dev = nfc_get_device(device_idx);
  693. if (!dev)
  694. return -ENODEV;
  695. target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
  696. rc = nfc_deactivate_target(dev, target_idx, NFC_TARGET_MODE_SLEEP);
  697. nfc_put_device(dev);
  698. return rc;
  699. }
  700. static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info)
  701. {
  702. struct nfc_dev *dev;
  703. int rc, tgt_idx;
  704. u32 idx;
  705. u8 comm;
  706. pr_debug("DEP link up\n");
  707. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  708. !info->attrs[NFC_ATTR_COMM_MODE])
  709. return -EINVAL;
  710. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  711. if (!info->attrs[NFC_ATTR_TARGET_INDEX])
  712. tgt_idx = NFC_TARGET_IDX_ANY;
  713. else
  714. tgt_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]);
  715. comm = nla_get_u8(info->attrs[NFC_ATTR_COMM_MODE]);
  716. if (comm != NFC_COMM_ACTIVE && comm != NFC_COMM_PASSIVE)
  717. return -EINVAL;
  718. dev = nfc_get_device(idx);
  719. if (!dev)
  720. return -ENODEV;
  721. rc = nfc_dep_link_up(dev, tgt_idx, comm);
  722. nfc_put_device(dev);
  723. return rc;
  724. }
  725. static int nfc_genl_dep_link_down(struct sk_buff *skb, struct genl_info *info)
  726. {
  727. struct nfc_dev *dev;
  728. int rc;
  729. u32 idx;
  730. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  731. !info->attrs[NFC_ATTR_TARGET_INDEX])
  732. return -EINVAL;
  733. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  734. dev = nfc_get_device(idx);
  735. if (!dev)
  736. return -ENODEV;
  737. rc = nfc_dep_link_down(dev);
  738. nfc_put_device(dev);
  739. return rc;
  740. }
  741. static int nfc_genl_send_params(struct sk_buff *msg,
  742. struct nfc_llcp_local *local,
  743. u32 portid, u32 seq)
  744. {
  745. void *hdr;
  746. hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, 0,
  747. NFC_CMD_LLC_GET_PARAMS);
  748. if (!hdr)
  749. return -EMSGSIZE;
  750. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, local->dev->idx) ||
  751. nla_put_u8(msg, NFC_ATTR_LLC_PARAM_LTO, local->lto) ||
  752. nla_put_u8(msg, NFC_ATTR_LLC_PARAM_RW, local->rw) ||
  753. nla_put_u16(msg, NFC_ATTR_LLC_PARAM_MIUX, be16_to_cpu(local->miux)))
  754. goto nla_put_failure;
  755. genlmsg_end(msg, hdr);
  756. return 0;
  757. nla_put_failure:
  758. genlmsg_cancel(msg, hdr);
  759. return -EMSGSIZE;
  760. }
  761. static int nfc_genl_llc_get_params(struct sk_buff *skb, struct genl_info *info)
  762. {
  763. struct nfc_dev *dev;
  764. struct nfc_llcp_local *local;
  765. int rc = 0;
  766. struct sk_buff *msg = NULL;
  767. u32 idx;
  768. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  769. !info->attrs[NFC_ATTR_FIRMWARE_NAME])
  770. return -EINVAL;
  771. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  772. dev = nfc_get_device(idx);
  773. if (!dev)
  774. return -ENODEV;
  775. device_lock(&dev->dev);
  776. local = nfc_llcp_find_local(dev);
  777. if (!local) {
  778. rc = -ENODEV;
  779. goto exit;
  780. }
  781. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  782. if (!msg) {
  783. rc = -ENOMEM;
  784. goto exit;
  785. }
  786. rc = nfc_genl_send_params(msg, local, info->snd_portid, info->snd_seq);
  787. exit:
  788. device_unlock(&dev->dev);
  789. nfc_put_device(dev);
  790. if (rc < 0) {
  791. if (msg)
  792. nlmsg_free(msg);
  793. return rc;
  794. }
  795. return genlmsg_reply(msg, info);
  796. }
  797. static int nfc_genl_llc_set_params(struct sk_buff *skb, struct genl_info *info)
  798. {
  799. struct nfc_dev *dev;
  800. struct nfc_llcp_local *local;
  801. u8 rw = 0;
  802. u16 miux = 0;
  803. u32 idx;
  804. int rc = 0;
  805. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  806. (!info->attrs[NFC_ATTR_LLC_PARAM_LTO] &&
  807. !info->attrs[NFC_ATTR_LLC_PARAM_RW] &&
  808. !info->attrs[NFC_ATTR_LLC_PARAM_MIUX]))
  809. return -EINVAL;
  810. if (info->attrs[NFC_ATTR_LLC_PARAM_RW]) {
  811. rw = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_RW]);
  812. if (rw > LLCP_MAX_RW)
  813. return -EINVAL;
  814. }
  815. if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX]) {
  816. miux = nla_get_u16(info->attrs[NFC_ATTR_LLC_PARAM_MIUX]);
  817. if (miux > LLCP_MAX_MIUX)
  818. return -EINVAL;
  819. }
  820. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  821. dev = nfc_get_device(idx);
  822. if (!dev)
  823. return -ENODEV;
  824. device_lock(&dev->dev);
  825. local = nfc_llcp_find_local(dev);
  826. if (!local) {
  827. rc = -ENODEV;
  828. goto exit;
  829. }
  830. if (info->attrs[NFC_ATTR_LLC_PARAM_LTO]) {
  831. if (dev->dep_link_up) {
  832. rc = -EINPROGRESS;
  833. goto exit;
  834. }
  835. local->lto = nla_get_u8(info->attrs[NFC_ATTR_LLC_PARAM_LTO]);
  836. }
  837. if (info->attrs[NFC_ATTR_LLC_PARAM_RW])
  838. local->rw = rw;
  839. if (info->attrs[NFC_ATTR_LLC_PARAM_MIUX])
  840. local->miux = cpu_to_be16(miux);
  841. exit:
  842. device_unlock(&dev->dev);
  843. nfc_put_device(dev);
  844. return rc;
  845. }
  846. static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
  847. {
  848. struct nfc_dev *dev;
  849. struct nfc_llcp_local *local;
  850. struct nlattr *attr, *sdp_attrs[NFC_SDP_ATTR_MAX+1];
  851. u32 idx;
  852. u8 tid;
  853. char *uri;
  854. int rc = 0, rem;
  855. size_t uri_len, tlvs_len;
  856. struct hlist_head sdreq_list;
  857. struct nfc_llcp_sdp_tlv *sdreq;
  858. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  859. !info->attrs[NFC_ATTR_LLC_SDP])
  860. return -EINVAL;
  861. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  862. dev = nfc_get_device(idx);
  863. if (!dev)
  864. return -ENODEV;
  865. device_lock(&dev->dev);
  866. if (dev->dep_link_up == false) {
  867. rc = -ENOLINK;
  868. goto exit;
  869. }
  870. local = nfc_llcp_find_local(dev);
  871. if (!local) {
  872. rc = -ENODEV;
  873. goto exit;
  874. }
  875. INIT_HLIST_HEAD(&sdreq_list);
  876. tlvs_len = 0;
  877. nla_for_each_nested(attr, info->attrs[NFC_ATTR_LLC_SDP], rem) {
  878. rc = nla_parse_nested_deprecated(sdp_attrs, NFC_SDP_ATTR_MAX,
  879. attr, nfc_sdp_genl_policy,
  880. info->extack);
  881. if (rc != 0) {
  882. rc = -EINVAL;
  883. goto exit;
  884. }
  885. if (!sdp_attrs[NFC_SDP_ATTR_URI])
  886. continue;
  887. uri_len = nla_len(sdp_attrs[NFC_SDP_ATTR_URI]);
  888. if (uri_len == 0)
  889. continue;
  890. uri = nla_data(sdp_attrs[NFC_SDP_ATTR_URI]);
  891. if (uri == NULL || *uri == 0)
  892. continue;
  893. tid = local->sdreq_next_tid++;
  894. sdreq = nfc_llcp_build_sdreq_tlv(tid, uri, uri_len);
  895. if (sdreq == NULL) {
  896. rc = -ENOMEM;
  897. goto exit;
  898. }
  899. tlvs_len += sdreq->tlv_len;
  900. hlist_add_head(&sdreq->node, &sdreq_list);
  901. }
  902. if (hlist_empty(&sdreq_list)) {
  903. rc = -EINVAL;
  904. goto exit;
  905. }
  906. rc = nfc_llcp_send_snl_sdreq(local, &sdreq_list, tlvs_len);
  907. exit:
  908. device_unlock(&dev->dev);
  909. nfc_put_device(dev);
  910. return rc;
  911. }
  912. static int nfc_genl_fw_download(struct sk_buff *skb, struct genl_info *info)
  913. {
  914. struct nfc_dev *dev;
  915. int rc;
  916. u32 idx;
  917. char firmware_name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
  918. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || !info->attrs[NFC_ATTR_FIRMWARE_NAME])
  919. return -EINVAL;
  920. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  921. dev = nfc_get_device(idx);
  922. if (!dev)
  923. return -ENODEV;
  924. nla_strlcpy(firmware_name, info->attrs[NFC_ATTR_FIRMWARE_NAME],
  925. sizeof(firmware_name));
  926. rc = nfc_fw_download(dev, firmware_name);
  927. nfc_put_device(dev);
  928. return rc;
  929. }
  930. int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
  931. u32 result)
  932. {
  933. struct sk_buff *msg;
  934. void *hdr;
  935. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  936. if (!msg)
  937. return -ENOMEM;
  938. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  939. NFC_CMD_FW_DOWNLOAD);
  940. if (!hdr)
  941. goto free_msg;
  942. if (nla_put_string(msg, NFC_ATTR_FIRMWARE_NAME, firmware_name) ||
  943. nla_put_u32(msg, NFC_ATTR_FIRMWARE_DOWNLOAD_STATUS, result) ||
  944. nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
  945. goto nla_put_failure;
  946. genlmsg_end(msg, hdr);
  947. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  948. return 0;
  949. nla_put_failure:
  950. free_msg:
  951. nlmsg_free(msg);
  952. return -EMSGSIZE;
  953. }
  954. static int nfc_genl_enable_se(struct sk_buff *skb, struct genl_info *info)
  955. {
  956. struct nfc_dev *dev;
  957. int rc;
  958. u32 idx, se_idx;
  959. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  960. !info->attrs[NFC_ATTR_SE_INDEX])
  961. return -EINVAL;
  962. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  963. se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
  964. dev = nfc_get_device(idx);
  965. if (!dev)
  966. return -ENODEV;
  967. rc = nfc_enable_se(dev, se_idx);
  968. nfc_put_device(dev);
  969. return rc;
  970. }
  971. static int nfc_genl_disable_se(struct sk_buff *skb, struct genl_info *info)
  972. {
  973. struct nfc_dev *dev;
  974. int rc;
  975. u32 idx, se_idx;
  976. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  977. !info->attrs[NFC_ATTR_SE_INDEX])
  978. return -EINVAL;
  979. idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  980. se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
  981. dev = nfc_get_device(idx);
  982. if (!dev)
  983. return -ENODEV;
  984. rc = nfc_disable_se(dev, se_idx);
  985. nfc_put_device(dev);
  986. return rc;
  987. }
  988. static int nfc_genl_send_se(struct sk_buff *msg, struct nfc_dev *dev,
  989. u32 portid, u32 seq,
  990. struct netlink_callback *cb,
  991. int flags)
  992. {
  993. void *hdr;
  994. struct nfc_se *se, *n;
  995. list_for_each_entry_safe(se, n, &dev->secure_elements, list) {
  996. hdr = genlmsg_put(msg, portid, seq, &nfc_genl_family, flags,
  997. NFC_CMD_GET_SE);
  998. if (!hdr)
  999. goto nla_put_failure;
  1000. if (cb)
  1001. genl_dump_check_consistent(cb, hdr);
  1002. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
  1003. nla_put_u32(msg, NFC_ATTR_SE_INDEX, se->idx) ||
  1004. nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type))
  1005. goto nla_put_failure;
  1006. genlmsg_end(msg, hdr);
  1007. }
  1008. return 0;
  1009. nla_put_failure:
  1010. genlmsg_cancel(msg, hdr);
  1011. return -EMSGSIZE;
  1012. }
  1013. static int nfc_genl_dump_ses(struct sk_buff *skb,
  1014. struct netlink_callback *cb)
  1015. {
  1016. struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
  1017. struct nfc_dev *dev = (struct nfc_dev *) cb->args[1];
  1018. bool first_call = false;
  1019. if (!iter) {
  1020. first_call = true;
  1021. iter = kmalloc(sizeof(struct class_dev_iter), GFP_KERNEL);
  1022. if (!iter)
  1023. return -ENOMEM;
  1024. cb->args[0] = (long) iter;
  1025. }
  1026. mutex_lock(&nfc_devlist_mutex);
  1027. cb->seq = nfc_devlist_generation;
  1028. if (first_call) {
  1029. nfc_device_iter_init(iter);
  1030. dev = nfc_device_iter_next(iter);
  1031. }
  1032. while (dev) {
  1033. int rc;
  1034. rc = nfc_genl_send_se(skb, dev, NETLINK_CB(cb->skb).portid,
  1035. cb->nlh->nlmsg_seq, cb, NLM_F_MULTI);
  1036. if (rc < 0)
  1037. break;
  1038. dev = nfc_device_iter_next(iter);
  1039. }
  1040. mutex_unlock(&nfc_devlist_mutex);
  1041. cb->args[1] = (long) dev;
  1042. return skb->len;
  1043. }
  1044. static int nfc_genl_dump_ses_done(struct netlink_callback *cb)
  1045. {
  1046. struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
  1047. if (iter) {
  1048. nfc_device_iter_exit(iter);
  1049. kfree(iter);
  1050. }
  1051. return 0;
  1052. }
  1053. static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
  1054. u8 *apdu, size_t apdu_length,
  1055. se_io_cb_t cb, void *cb_context)
  1056. {
  1057. struct nfc_se *se;
  1058. int rc;
  1059. pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx);
  1060. device_lock(&dev->dev);
  1061. if (!device_is_registered(&dev->dev)) {
  1062. rc = -ENODEV;
  1063. goto error;
  1064. }
  1065. if (!dev->dev_up) {
  1066. rc = -ENODEV;
  1067. goto error;
  1068. }
  1069. if (!dev->ops->se_io) {
  1070. rc = -EOPNOTSUPP;
  1071. goto error;
  1072. }
  1073. se = nfc_find_se(dev, se_idx);
  1074. if (!se) {
  1075. rc = -EINVAL;
  1076. goto error;
  1077. }
  1078. if (se->state != NFC_SE_ENABLED) {
  1079. rc = -ENODEV;
  1080. goto error;
  1081. }
  1082. rc = dev->ops->se_io(dev, se_idx, apdu,
  1083. apdu_length, cb, cb_context);
  1084. error:
  1085. device_unlock(&dev->dev);
  1086. return rc;
  1087. }
  1088. struct se_io_ctx {
  1089. u32 dev_idx;
  1090. u32 se_idx;
  1091. };
  1092. static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)
  1093. {
  1094. struct se_io_ctx *ctx = context;
  1095. struct sk_buff *msg;
  1096. void *hdr;
  1097. msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1098. if (!msg) {
  1099. kfree(ctx);
  1100. return;
  1101. }
  1102. hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
  1103. NFC_CMD_SE_IO);
  1104. if (!hdr)
  1105. goto free_msg;
  1106. if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, ctx->dev_idx) ||
  1107. nla_put_u32(msg, NFC_ATTR_SE_INDEX, ctx->se_idx) ||
  1108. nla_put(msg, NFC_ATTR_SE_APDU, apdu_len, apdu))
  1109. goto nla_put_failure;
  1110. genlmsg_end(msg, hdr);
  1111. genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
  1112. kfree(ctx);
  1113. return;
  1114. nla_put_failure:
  1115. free_msg:
  1116. nlmsg_free(msg);
  1117. kfree(ctx);
  1118. return;
  1119. }
  1120. static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info)
  1121. {
  1122. struct nfc_dev *dev;
  1123. struct se_io_ctx *ctx;
  1124. u32 dev_idx, se_idx;
  1125. u8 *apdu;
  1126. size_t apdu_len;
  1127. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  1128. !info->attrs[NFC_ATTR_SE_INDEX] ||
  1129. !info->attrs[NFC_ATTR_SE_APDU])
  1130. return -EINVAL;
  1131. dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  1132. se_idx = nla_get_u32(info->attrs[NFC_ATTR_SE_INDEX]);
  1133. dev = nfc_get_device(dev_idx);
  1134. if (!dev)
  1135. return -ENODEV;
  1136. if (!dev->ops || !dev->ops->se_io)
  1137. return -ENOTSUPP;
  1138. apdu_len = nla_len(info->attrs[NFC_ATTR_SE_APDU]);
  1139. if (apdu_len == 0)
  1140. return -EINVAL;
  1141. apdu = nla_data(info->attrs[NFC_ATTR_SE_APDU]);
  1142. if (!apdu)
  1143. return -EINVAL;
  1144. ctx = kzalloc(sizeof(struct se_io_ctx), GFP_KERNEL);
  1145. if (!ctx)
  1146. return -ENOMEM;
  1147. ctx->dev_idx = dev_idx;
  1148. ctx->se_idx = se_idx;
  1149. return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx);
  1150. }
  1151. static int nfc_genl_vendor_cmd(struct sk_buff *skb,
  1152. struct genl_info *info)
  1153. {
  1154. struct nfc_dev *dev;
  1155. struct nfc_vendor_cmd *cmd;
  1156. u32 dev_idx, vid, subcmd;
  1157. u8 *data;
  1158. size_t data_len;
  1159. int i, err;
  1160. if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
  1161. !info->attrs[NFC_ATTR_VENDOR_ID] ||
  1162. !info->attrs[NFC_ATTR_VENDOR_SUBCMD])
  1163. return -EINVAL;
  1164. dev_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
  1165. vid = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_ID]);
  1166. subcmd = nla_get_u32(info->attrs[NFC_ATTR_VENDOR_SUBCMD]);
  1167. dev = nfc_get_device(dev_idx);
  1168. if (!dev || !dev->vendor_cmds || !dev->n_vendor_cmds)
  1169. return -ENODEV;
  1170. if (info->attrs[NFC_ATTR_VENDOR_DATA]) {
  1171. data = nla_data(info->attrs[NFC_ATTR_VENDOR_DATA]);
  1172. data_len = nla_len(info->attrs[NFC_ATTR_VENDOR_DATA]);
  1173. if (data_len == 0)
  1174. return -EINVAL;
  1175. } else {
  1176. data = NULL;
  1177. data_len = 0;
  1178. }
  1179. for (i = 0; i < dev->n_vendor_cmds; i++) {
  1180. cmd = &dev->vendor_cmds[i];
  1181. if (cmd->vendor_id != vid || cmd->subcmd != subcmd)
  1182. continue;
  1183. dev->cur_cmd_info = info;
  1184. err = cmd->doit(dev, data, data_len);
  1185. dev->cur_cmd_info = NULL;
  1186. return err;
  1187. }
  1188. return -EOPNOTSUPP;
  1189. }
  1190. /* message building helper */
  1191. static inline void *nfc_hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
  1192. int flags, u8 cmd)
  1193. {
  1194. /* since there is no private header just add the generic one */
  1195. return genlmsg_put(skb, portid, seq, &nfc_genl_family, flags, cmd);
  1196. }
  1197. static struct sk_buff *
  1198. __nfc_alloc_vendor_cmd_skb(struct nfc_dev *dev, int approxlen,
  1199. u32 portid, u32 seq,
  1200. enum nfc_attrs attr,
  1201. u32 oui, u32 subcmd, gfp_t gfp)
  1202. {
  1203. struct sk_buff *skb;
  1204. void *hdr;
  1205. skb = nlmsg_new(approxlen + 100, gfp);
  1206. if (!skb)
  1207. return NULL;
  1208. hdr = nfc_hdr_put(skb, portid, seq, 0, NFC_CMD_VENDOR);
  1209. if (!hdr) {
  1210. kfree_skb(skb);
  1211. return NULL;
  1212. }
  1213. if (nla_put_u32(skb, NFC_ATTR_DEVICE_INDEX, dev->idx))
  1214. goto nla_put_failure;
  1215. if (nla_put_u32(skb, NFC_ATTR_VENDOR_ID, oui))
  1216. goto nla_put_failure;
  1217. if (nla_put_u32(skb, NFC_ATTR_VENDOR_SUBCMD, subcmd))
  1218. goto nla_put_failure;
  1219. ((void **)skb->cb)[0] = dev;
  1220. ((void **)skb->cb)[1] = hdr;
  1221. return skb;
  1222. nla_put_failure:
  1223. kfree_skb(skb);
  1224. return NULL;
  1225. }
  1226. struct sk_buff *__nfc_alloc_vendor_cmd_reply_skb(struct nfc_dev *dev,
  1227. enum nfc_attrs attr,
  1228. u32 oui, u32 subcmd,
  1229. int approxlen)
  1230. {
  1231. if (WARN_ON(!dev->cur_cmd_info))
  1232. return NULL;
  1233. return __nfc_alloc_vendor_cmd_skb(dev, approxlen,
  1234. dev->cur_cmd_info->snd_portid,
  1235. dev->cur_cmd_info->snd_seq, attr,
  1236. oui, subcmd, GFP_KERNEL);
  1237. }
  1238. EXPORT_SYMBOL(__nfc_alloc_vendor_cmd_reply_skb);
  1239. int nfc_vendor_cmd_reply(struct sk_buff *skb)
  1240. {
  1241. struct nfc_dev *dev = ((void **)skb->cb)[0];
  1242. void *hdr = ((void **)skb->cb)[1];
  1243. /* clear CB data for netlink core to own from now on */
  1244. memset(skb->cb, 0, sizeof(skb->cb));
  1245. if (WARN_ON(!dev->cur_cmd_info)) {
  1246. kfree_skb(skb);
  1247. return -EINVAL;
  1248. }
  1249. genlmsg_end(skb, hdr);
  1250. return genlmsg_reply(skb, dev->cur_cmd_info);
  1251. }
  1252. EXPORT_SYMBOL(nfc_vendor_cmd_reply);
  1253. static const struct genl_ops nfc_genl_ops[] = {
  1254. {
  1255. .cmd = NFC_CMD_GET_DEVICE,
  1256. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1257. .doit = nfc_genl_get_device,
  1258. .dumpit = nfc_genl_dump_devices,
  1259. .done = nfc_genl_dump_devices_done,
  1260. },
  1261. {
  1262. .cmd = NFC_CMD_DEV_UP,
  1263. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1264. .doit = nfc_genl_dev_up,
  1265. },
  1266. {
  1267. .cmd = NFC_CMD_DEV_DOWN,
  1268. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1269. .doit = nfc_genl_dev_down,
  1270. },
  1271. {
  1272. .cmd = NFC_CMD_START_POLL,
  1273. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1274. .doit = nfc_genl_start_poll,
  1275. },
  1276. {
  1277. .cmd = NFC_CMD_STOP_POLL,
  1278. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1279. .doit = nfc_genl_stop_poll,
  1280. },
  1281. {
  1282. .cmd = NFC_CMD_DEP_LINK_UP,
  1283. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1284. .doit = nfc_genl_dep_link_up,
  1285. },
  1286. {
  1287. .cmd = NFC_CMD_DEP_LINK_DOWN,
  1288. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1289. .doit = nfc_genl_dep_link_down,
  1290. },
  1291. {
  1292. .cmd = NFC_CMD_GET_TARGET,
  1293. .validate = GENL_DONT_VALIDATE_STRICT |
  1294. GENL_DONT_VALIDATE_DUMP_STRICT,
  1295. .dumpit = nfc_genl_dump_targets,
  1296. .done = nfc_genl_dump_targets_done,
  1297. },
  1298. {
  1299. .cmd = NFC_CMD_LLC_GET_PARAMS,
  1300. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1301. .doit = nfc_genl_llc_get_params,
  1302. },
  1303. {
  1304. .cmd = NFC_CMD_LLC_SET_PARAMS,
  1305. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1306. .doit = nfc_genl_llc_set_params,
  1307. },
  1308. {
  1309. .cmd = NFC_CMD_LLC_SDREQ,
  1310. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1311. .doit = nfc_genl_llc_sdreq,
  1312. },
  1313. {
  1314. .cmd = NFC_CMD_FW_DOWNLOAD,
  1315. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1316. .doit = nfc_genl_fw_download,
  1317. },
  1318. {
  1319. .cmd = NFC_CMD_ENABLE_SE,
  1320. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1321. .doit = nfc_genl_enable_se,
  1322. },
  1323. {
  1324. .cmd = NFC_CMD_DISABLE_SE,
  1325. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1326. .doit = nfc_genl_disable_se,
  1327. },
  1328. {
  1329. .cmd = NFC_CMD_GET_SE,
  1330. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1331. .dumpit = nfc_genl_dump_ses,
  1332. .done = nfc_genl_dump_ses_done,
  1333. },
  1334. {
  1335. .cmd = NFC_CMD_SE_IO,
  1336. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1337. .doit = nfc_genl_se_io,
  1338. },
  1339. {
  1340. .cmd = NFC_CMD_ACTIVATE_TARGET,
  1341. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1342. .doit = nfc_genl_activate_target,
  1343. },
  1344. {
  1345. .cmd = NFC_CMD_VENDOR,
  1346. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1347. .doit = nfc_genl_vendor_cmd,
  1348. },
  1349. {
  1350. .cmd = NFC_CMD_DEACTIVATE_TARGET,
  1351. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  1352. .doit = nfc_genl_deactivate_target,
  1353. },
  1354. };
  1355. static struct genl_family nfc_genl_family __ro_after_init = {
  1356. .hdrsize = 0,
  1357. .name = NFC_GENL_NAME,
  1358. .version = NFC_GENL_VERSION,
  1359. .maxattr = NFC_ATTR_MAX,
  1360. .policy = nfc_genl_policy,
  1361. .module = THIS_MODULE,
  1362. .ops = nfc_genl_ops,
  1363. .n_ops = ARRAY_SIZE(nfc_genl_ops),
  1364. .mcgrps = nfc_genl_mcgrps,
  1365. .n_mcgrps = ARRAY_SIZE(nfc_genl_mcgrps),
  1366. };
  1367. struct urelease_work {
  1368. struct work_struct w;
  1369. u32 portid;
  1370. };
  1371. static void nfc_urelease_event_work(struct work_struct *work)
  1372. {
  1373. struct urelease_work *w = container_of(work, struct urelease_work, w);
  1374. struct class_dev_iter iter;
  1375. struct nfc_dev *dev;
  1376. pr_debug("portid %d\n", w->portid);
  1377. mutex_lock(&nfc_devlist_mutex);
  1378. nfc_device_iter_init(&iter);
  1379. dev = nfc_device_iter_next(&iter);
  1380. while (dev) {
  1381. mutex_lock(&dev->genl_data.genl_data_mutex);
  1382. if (dev->genl_data.poll_req_portid == w->portid) {
  1383. nfc_stop_poll(dev);
  1384. dev->genl_data.poll_req_portid = 0;
  1385. }
  1386. mutex_unlock(&dev->genl_data.genl_data_mutex);
  1387. dev = nfc_device_iter_next(&iter);
  1388. }
  1389. nfc_device_iter_exit(&iter);
  1390. mutex_unlock(&nfc_devlist_mutex);
  1391. kfree(w);
  1392. }
  1393. static int nfc_genl_rcv_nl_event(struct notifier_block *this,
  1394. unsigned long event, void *ptr)
  1395. {
  1396. struct netlink_notify *n = ptr;
  1397. struct urelease_work *w;
  1398. if (event != NETLINK_URELEASE || n->protocol != NETLINK_GENERIC)
  1399. goto out;
  1400. pr_debug("NETLINK_URELEASE event from id %d\n", n->portid);
  1401. w = kmalloc(sizeof(*w), GFP_ATOMIC);
  1402. if (w) {
  1403. INIT_WORK((struct work_struct *) w, nfc_urelease_event_work);
  1404. w->portid = n->portid;
  1405. schedule_work((struct work_struct *) w);
  1406. }
  1407. out:
  1408. return NOTIFY_DONE;
  1409. }
  1410. void nfc_genl_data_init(struct nfc_genl_data *genl_data)
  1411. {
  1412. genl_data->poll_req_portid = 0;
  1413. mutex_init(&genl_data->genl_data_mutex);
  1414. }
  1415. void nfc_genl_data_exit(struct nfc_genl_data *genl_data)
  1416. {
  1417. mutex_destroy(&genl_data->genl_data_mutex);
  1418. }
  1419. static struct notifier_block nl_notifier = {
  1420. .notifier_call = nfc_genl_rcv_nl_event,
  1421. };
  1422. /**
  1423. * nfc_genl_init() - Initialize netlink interface
  1424. *
  1425. * This initialization function registers the nfc netlink family.
  1426. */
  1427. int __init nfc_genl_init(void)
  1428. {
  1429. int rc;
  1430. rc = genl_register_family(&nfc_genl_family);
  1431. if (rc)
  1432. return rc;
  1433. netlink_register_notifier(&nl_notifier);
  1434. return 0;
  1435. }
  1436. /**
  1437. * nfc_genl_exit() - Deinitialize netlink interface
  1438. *
  1439. * This exit function unregisters the nfc netlink family.
  1440. */
  1441. void nfc_genl_exit(void)
  1442. {
  1443. netlink_unregister_notifier(&nl_notifier);
  1444. genl_unregister_family(&nfc_genl_family);
  1445. }