core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /*
  2. * Copyright (C) 2011 Instituto Nokia de Tecnologia
  3. *
  4. * Authors:
  5. * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
  6. * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the
  20. * Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
  24. #include <linux/init.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/nfc.h>
  29. #include "nfc.h"
  30. #define VERSION "0.1"
  31. #define NFC_CHECK_PRES_FREQ_MS 2000
  32. int nfc_devlist_generation;
  33. DEFINE_MUTEX(nfc_devlist_mutex);
  34. /**
  35. * nfc_dev_up - turn on the NFC device
  36. *
  37. * @dev: The nfc device to be turned on
  38. *
  39. * The device remains up until the nfc_dev_down function is called.
  40. */
  41. int nfc_dev_up(struct nfc_dev *dev)
  42. {
  43. int rc = 0;
  44. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  45. device_lock(&dev->dev);
  46. if (!device_is_registered(&dev->dev)) {
  47. rc = -ENODEV;
  48. goto error;
  49. }
  50. if (dev->dev_up) {
  51. rc = -EALREADY;
  52. goto error;
  53. }
  54. if (dev->ops->dev_up)
  55. rc = dev->ops->dev_up(dev);
  56. if (!rc)
  57. dev->dev_up = true;
  58. error:
  59. device_unlock(&dev->dev);
  60. return rc;
  61. }
  62. /**
  63. * nfc_dev_down - turn off the NFC device
  64. *
  65. * @dev: The nfc device to be turned off
  66. */
  67. int nfc_dev_down(struct nfc_dev *dev)
  68. {
  69. int rc = 0;
  70. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  71. device_lock(&dev->dev);
  72. if (!device_is_registered(&dev->dev)) {
  73. rc = -ENODEV;
  74. goto error;
  75. }
  76. if (!dev->dev_up) {
  77. rc = -EALREADY;
  78. goto error;
  79. }
  80. if (dev->polling || dev->activated_target_idx != NFC_TARGET_IDX_NONE) {
  81. rc = -EBUSY;
  82. goto error;
  83. }
  84. if (dev->ops->dev_down)
  85. dev->ops->dev_down(dev);
  86. dev->dev_up = false;
  87. error:
  88. device_unlock(&dev->dev);
  89. return rc;
  90. }
  91. /**
  92. * nfc_start_poll - start polling for nfc targets
  93. *
  94. * @dev: The nfc device that must start polling
  95. * @protocols: bitset of nfc protocols that must be used for polling
  96. *
  97. * The device remains polling for targets until a target is found or
  98. * the nfc_stop_poll function is called.
  99. */
  100. int nfc_start_poll(struct nfc_dev *dev, u32 protocols)
  101. {
  102. int rc;
  103. pr_debug("dev_name=%s protocols=0x%x\n",
  104. dev_name(&dev->dev), protocols);
  105. if (!protocols)
  106. return -EINVAL;
  107. device_lock(&dev->dev);
  108. if (!device_is_registered(&dev->dev)) {
  109. rc = -ENODEV;
  110. goto error;
  111. }
  112. if (dev->polling) {
  113. rc = -EBUSY;
  114. goto error;
  115. }
  116. rc = dev->ops->start_poll(dev, protocols);
  117. if (!rc)
  118. dev->polling = true;
  119. error:
  120. device_unlock(&dev->dev);
  121. return rc;
  122. }
  123. /**
  124. * nfc_stop_poll - stop polling for nfc targets
  125. *
  126. * @dev: The nfc device that must stop polling
  127. */
  128. int nfc_stop_poll(struct nfc_dev *dev)
  129. {
  130. int rc = 0;
  131. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  132. device_lock(&dev->dev);
  133. if (!device_is_registered(&dev->dev)) {
  134. rc = -ENODEV;
  135. goto error;
  136. }
  137. if (!dev->polling) {
  138. rc = -EINVAL;
  139. goto error;
  140. }
  141. dev->ops->stop_poll(dev);
  142. dev->polling = false;
  143. error:
  144. device_unlock(&dev->dev);
  145. return rc;
  146. }
  147. int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
  148. {
  149. int rc = 0;
  150. u8 *gb;
  151. size_t gb_len;
  152. pr_debug("dev_name=%s comm %d\n", dev_name(&dev->dev), comm_mode);
  153. if (!dev->ops->dep_link_up)
  154. return -EOPNOTSUPP;
  155. device_lock(&dev->dev);
  156. if (!device_is_registered(&dev->dev)) {
  157. rc = -ENODEV;
  158. goto error;
  159. }
  160. if (dev->dep_link_up == true) {
  161. rc = -EALREADY;
  162. goto error;
  163. }
  164. gb = nfc_llcp_general_bytes(dev, &gb_len);
  165. if (gb_len > NFC_MAX_GT_LEN) {
  166. rc = -EINVAL;
  167. goto error;
  168. }
  169. rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len);
  170. if (!rc)
  171. dev->activated_target_idx = target_index;
  172. error:
  173. device_unlock(&dev->dev);
  174. return rc;
  175. }
  176. int nfc_dep_link_down(struct nfc_dev *dev)
  177. {
  178. int rc = 0;
  179. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  180. if (!dev->ops->dep_link_down)
  181. return -EOPNOTSUPP;
  182. device_lock(&dev->dev);
  183. if (!device_is_registered(&dev->dev)) {
  184. rc = -ENODEV;
  185. goto error;
  186. }
  187. if (dev->dep_link_up == false) {
  188. rc = -EALREADY;
  189. goto error;
  190. }
  191. if (dev->dep_rf_mode == NFC_RF_TARGET) {
  192. rc = -EOPNOTSUPP;
  193. goto error;
  194. }
  195. rc = dev->ops->dep_link_down(dev);
  196. if (!rc) {
  197. dev->dep_link_up = false;
  198. dev->activated_target_idx = NFC_TARGET_IDX_NONE;
  199. nfc_llcp_mac_is_down(dev);
  200. nfc_genl_dep_link_down_event(dev);
  201. }
  202. error:
  203. device_unlock(&dev->dev);
  204. return rc;
  205. }
  206. int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
  207. u8 comm_mode, u8 rf_mode)
  208. {
  209. dev->dep_link_up = true;
  210. dev->dep_rf_mode = rf_mode;
  211. nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
  212. return nfc_genl_dep_link_up_event(dev, target_idx, comm_mode, rf_mode);
  213. }
  214. EXPORT_SYMBOL(nfc_dep_link_is_up);
  215. /**
  216. * nfc_activate_target - prepare the target for data exchange
  217. *
  218. * @dev: The nfc device that found the target
  219. * @target_idx: index of the target that must be activated
  220. * @protocol: nfc protocol that will be used for data exchange
  221. */
  222. int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
  223. {
  224. int rc;
  225. pr_debug("dev_name=%s target_idx=%u protocol=%u\n",
  226. dev_name(&dev->dev), target_idx, protocol);
  227. device_lock(&dev->dev);
  228. if (!device_is_registered(&dev->dev)) {
  229. rc = -ENODEV;
  230. goto error;
  231. }
  232. rc = dev->ops->activate_target(dev, target_idx, protocol);
  233. if (!rc) {
  234. dev->activated_target_idx = target_idx;
  235. if (dev->ops->check_presence)
  236. mod_timer(&dev->check_pres_timer, jiffies +
  237. msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
  238. }
  239. error:
  240. device_unlock(&dev->dev);
  241. return rc;
  242. }
  243. /**
  244. * nfc_deactivate_target - deactivate a nfc target
  245. *
  246. * @dev: The nfc device that found the target
  247. * @target_idx: index of the target that must be deactivated
  248. */
  249. int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
  250. {
  251. int rc = 0;
  252. pr_debug("dev_name=%s target_idx=%u\n",
  253. dev_name(&dev->dev), target_idx);
  254. device_lock(&dev->dev);
  255. if (!device_is_registered(&dev->dev)) {
  256. rc = -ENODEV;
  257. goto error;
  258. }
  259. if (dev->ops->check_presence)
  260. del_timer_sync(&dev->check_pres_timer);
  261. dev->ops->deactivate_target(dev, target_idx);
  262. dev->activated_target_idx = NFC_TARGET_IDX_NONE;
  263. error:
  264. device_unlock(&dev->dev);
  265. return rc;
  266. }
  267. /**
  268. * nfc_data_exchange - transceive data
  269. *
  270. * @dev: The nfc device that found the target
  271. * @target_idx: index of the target
  272. * @skb: data to be sent
  273. * @cb: callback called when the response is received
  274. * @cb_context: parameter for the callback function
  275. *
  276. * The user must wait for the callback before calling this function again.
  277. */
  278. int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
  279. data_exchange_cb_t cb, void *cb_context)
  280. {
  281. int rc;
  282. pr_debug("dev_name=%s target_idx=%u skb->len=%u\n",
  283. dev_name(&dev->dev), target_idx, skb->len);
  284. device_lock(&dev->dev);
  285. if (!device_is_registered(&dev->dev)) {
  286. rc = -ENODEV;
  287. kfree_skb(skb);
  288. goto error;
  289. }
  290. if (dev->activated_target_idx == NFC_TARGET_IDX_NONE) {
  291. rc = -ENOTCONN;
  292. kfree_skb(skb);
  293. goto error;
  294. }
  295. if (target_idx != dev->activated_target_idx) {
  296. rc = -EADDRNOTAVAIL;
  297. kfree_skb(skb);
  298. goto error;
  299. }
  300. if (dev->ops->check_presence)
  301. del_timer_sync(&dev->check_pres_timer);
  302. rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context);
  303. if (!rc && dev->ops->check_presence)
  304. mod_timer(&dev->check_pres_timer, jiffies +
  305. msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
  306. error:
  307. device_unlock(&dev->dev);
  308. return rc;
  309. }
  310. int nfc_set_remote_general_bytes(struct nfc_dev *dev, u8 *gb, u8 gb_len)
  311. {
  312. pr_debug("dev_name=%s gb_len=%d\n", dev_name(&dev->dev), gb_len);
  313. if (gb_len > NFC_MAX_GT_LEN)
  314. return -EINVAL;
  315. return nfc_llcp_set_remote_gb(dev, gb, gb_len);
  316. }
  317. EXPORT_SYMBOL(nfc_set_remote_general_bytes);
  318. /**
  319. * nfc_alloc_send_skb - allocate a skb for data exchange responses
  320. *
  321. * @size: size to allocate
  322. * @gfp: gfp flags
  323. */
  324. struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk,
  325. unsigned int flags, unsigned int size,
  326. unsigned int *err)
  327. {
  328. struct sk_buff *skb;
  329. unsigned int total_size;
  330. total_size = size +
  331. dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE;
  332. skb = sock_alloc_send_skb(sk, total_size, flags & MSG_DONTWAIT, err);
  333. if (skb)
  334. skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
  335. return skb;
  336. }
  337. /**
  338. * nfc_alloc_recv_skb - allocate a skb for data exchange responses
  339. *
  340. * @size: size to allocate
  341. * @gfp: gfp flags
  342. */
  343. struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp)
  344. {
  345. struct sk_buff *skb;
  346. unsigned int total_size;
  347. total_size = size + 1;
  348. skb = alloc_skb(total_size, gfp);
  349. if (skb)
  350. skb_reserve(skb, 1);
  351. return skb;
  352. }
  353. EXPORT_SYMBOL(nfc_alloc_recv_skb);
  354. /**
  355. * nfc_targets_found - inform that targets were found
  356. *
  357. * @dev: The nfc device that found the targets
  358. * @targets: array of nfc targets found
  359. * @ntargets: targets array size
  360. *
  361. * The device driver must call this function when one or many nfc targets
  362. * are found. After calling this function, the device driver must stop
  363. * polling for targets.
  364. */
  365. int nfc_targets_found(struct nfc_dev *dev,
  366. struct nfc_target *targets, int n_targets)
  367. {
  368. int i;
  369. pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets);
  370. dev->polling = false;
  371. for (i = 0; i < n_targets; i++)
  372. targets[i].idx = dev->target_next_idx++;
  373. spin_lock_bh(&dev->targets_lock);
  374. dev->targets_generation++;
  375. kfree(dev->targets);
  376. dev->targets = kmemdup(targets, n_targets * sizeof(struct nfc_target),
  377. GFP_ATOMIC);
  378. if (!dev->targets) {
  379. dev->n_targets = 0;
  380. spin_unlock_bh(&dev->targets_lock);
  381. return -ENOMEM;
  382. }
  383. dev->n_targets = n_targets;
  384. spin_unlock_bh(&dev->targets_lock);
  385. nfc_genl_targets_found(dev);
  386. return 0;
  387. }
  388. EXPORT_SYMBOL(nfc_targets_found);
  389. int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
  390. {
  391. struct nfc_target *tg;
  392. int i;
  393. pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx);
  394. spin_lock_bh(&dev->targets_lock);
  395. for (i = 0; i < dev->n_targets; i++) {
  396. tg = &dev->targets[i];
  397. if (tg->idx == target_idx)
  398. break;
  399. }
  400. if (i == dev->n_targets) {
  401. spin_unlock_bh(&dev->targets_lock);
  402. return -EINVAL;
  403. }
  404. dev->targets_generation++;
  405. dev->n_targets--;
  406. dev->activated_target_idx = NFC_TARGET_IDX_NONE;
  407. if (dev->n_targets) {
  408. memcpy(&dev->targets[i], &dev->targets[i + 1],
  409. (dev->n_targets - i) * sizeof(struct nfc_target));
  410. } else {
  411. kfree(dev->targets);
  412. dev->targets = NULL;
  413. }
  414. spin_unlock_bh(&dev->targets_lock);
  415. nfc_genl_target_lost(dev, target_idx);
  416. return 0;
  417. }
  418. EXPORT_SYMBOL(nfc_target_lost);
  419. static void nfc_release(struct device *d)
  420. {
  421. struct nfc_dev *dev = to_nfc_dev(d);
  422. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  423. if (dev->ops->check_presence) {
  424. del_timer_sync(&dev->check_pres_timer);
  425. destroy_workqueue(dev->check_pres_wq);
  426. }
  427. nfc_genl_data_exit(&dev->genl_data);
  428. kfree(dev->targets);
  429. kfree(dev);
  430. }
  431. static void nfc_check_pres_work(struct work_struct *work)
  432. {
  433. struct nfc_dev *dev = container_of(work, struct nfc_dev,
  434. check_pres_work);
  435. int rc;
  436. device_lock(&dev->dev);
  437. if (dev->activated_target_idx != NFC_TARGET_IDX_NONE &&
  438. timer_pending(&dev->check_pres_timer) == 0) {
  439. rc = dev->ops->check_presence(dev, dev->activated_target_idx);
  440. if (!rc) {
  441. mod_timer(&dev->check_pres_timer, jiffies +
  442. msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
  443. } else {
  444. nfc_target_lost(dev, dev->activated_target_idx);
  445. dev->activated_target_idx = NFC_TARGET_IDX_NONE;
  446. }
  447. }
  448. device_unlock(&dev->dev);
  449. }
  450. static void nfc_check_pres_timeout(unsigned long data)
  451. {
  452. struct nfc_dev *dev = (struct nfc_dev *)data;
  453. queue_work(dev->check_pres_wq, &dev->check_pres_work);
  454. }
  455. struct class nfc_class = {
  456. .name = "nfc",
  457. .dev_release = nfc_release,
  458. };
  459. EXPORT_SYMBOL(nfc_class);
  460. static int match_idx(struct device *d, void *data)
  461. {
  462. struct nfc_dev *dev = to_nfc_dev(d);
  463. unsigned int *idx = data;
  464. return dev->idx == *idx;
  465. }
  466. struct nfc_dev *nfc_get_device(unsigned int idx)
  467. {
  468. struct device *d;
  469. d = class_find_device(&nfc_class, NULL, &idx, match_idx);
  470. if (!d)
  471. return NULL;
  472. return to_nfc_dev(d);
  473. }
  474. /**
  475. * nfc_allocate_device - allocate a new nfc device
  476. *
  477. * @ops: device operations
  478. * @supported_protocols: NFC protocols supported by the device
  479. */
  480. struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
  481. u32 supported_protocols,
  482. int tx_headroom, int tx_tailroom)
  483. {
  484. static atomic_t dev_no = ATOMIC_INIT(0);
  485. struct nfc_dev *dev;
  486. if (!ops->start_poll || !ops->stop_poll || !ops->activate_target ||
  487. !ops->deactivate_target || !ops->data_exchange)
  488. return NULL;
  489. if (!supported_protocols)
  490. return NULL;
  491. dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL);
  492. if (!dev)
  493. return NULL;
  494. dev->dev.class = &nfc_class;
  495. dev->idx = atomic_inc_return(&dev_no) - 1;
  496. dev_set_name(&dev->dev, "nfc%d", dev->idx);
  497. device_initialize(&dev->dev);
  498. dev->ops = ops;
  499. dev->supported_protocols = supported_protocols;
  500. dev->tx_headroom = tx_headroom;
  501. dev->tx_tailroom = tx_tailroom;
  502. spin_lock_init(&dev->targets_lock);
  503. nfc_genl_data_init(&dev->genl_data);
  504. /* first generation must not be 0 */
  505. dev->targets_generation = 1;
  506. dev->activated_target_idx = NFC_TARGET_IDX_NONE;
  507. if (ops->check_presence) {
  508. char name[32];
  509. init_timer(&dev->check_pres_timer);
  510. dev->check_pres_timer.data = (unsigned long)dev;
  511. dev->check_pres_timer.function = nfc_check_pres_timeout;
  512. INIT_WORK(&dev->check_pres_work, nfc_check_pres_work);
  513. snprintf(name, sizeof(name), "nfc%d_check_pres_wq", dev->idx);
  514. dev->check_pres_wq = alloc_workqueue(name, WQ_NON_REENTRANT |
  515. WQ_UNBOUND |
  516. WQ_MEM_RECLAIM, 1);
  517. if (dev->check_pres_wq == NULL) {
  518. kfree(dev);
  519. return NULL;
  520. }
  521. }
  522. return dev;
  523. }
  524. EXPORT_SYMBOL(nfc_allocate_device);
  525. /**
  526. * nfc_register_device - register a nfc device in the nfc subsystem
  527. *
  528. * @dev: The nfc device to register
  529. */
  530. int nfc_register_device(struct nfc_dev *dev)
  531. {
  532. int rc;
  533. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  534. mutex_lock(&nfc_devlist_mutex);
  535. nfc_devlist_generation++;
  536. rc = device_add(&dev->dev);
  537. mutex_unlock(&nfc_devlist_mutex);
  538. if (rc < 0)
  539. return rc;
  540. rc = nfc_llcp_register_device(dev);
  541. if (rc)
  542. pr_err("Could not register llcp device\n");
  543. rc = nfc_genl_device_added(dev);
  544. if (rc)
  545. pr_debug("The userspace won't be notified that the device %s was added\n",
  546. dev_name(&dev->dev));
  547. return 0;
  548. }
  549. EXPORT_SYMBOL(nfc_register_device);
  550. /**
  551. * nfc_unregister_device - unregister a nfc device in the nfc subsystem
  552. *
  553. * @dev: The nfc device to unregister
  554. */
  555. void nfc_unregister_device(struct nfc_dev *dev)
  556. {
  557. int rc;
  558. pr_debug("dev_name=%s\n", dev_name(&dev->dev));
  559. mutex_lock(&nfc_devlist_mutex);
  560. nfc_devlist_generation++;
  561. /* lock to avoid unregistering a device while an operation
  562. is in progress */
  563. device_lock(&dev->dev);
  564. device_del(&dev->dev);
  565. device_unlock(&dev->dev);
  566. mutex_unlock(&nfc_devlist_mutex);
  567. nfc_llcp_unregister_device(dev);
  568. rc = nfc_genl_device_removed(dev);
  569. if (rc)
  570. pr_debug("The userspace won't be notified that the device %s was removed\n",
  571. dev_name(&dev->dev));
  572. }
  573. EXPORT_SYMBOL(nfc_unregister_device);
  574. static int __init nfc_init(void)
  575. {
  576. int rc;
  577. pr_info("NFC Core ver %s\n", VERSION);
  578. rc = class_register(&nfc_class);
  579. if (rc)
  580. return rc;
  581. rc = nfc_genl_init();
  582. if (rc)
  583. goto err_genl;
  584. /* the first generation must not be 0 */
  585. nfc_devlist_generation = 1;
  586. rc = rawsock_init();
  587. if (rc)
  588. goto err_rawsock;
  589. rc = nfc_llcp_init();
  590. if (rc)
  591. goto err_llcp_sock;
  592. rc = af_nfc_init();
  593. if (rc)
  594. goto err_af_nfc;
  595. return 0;
  596. err_af_nfc:
  597. nfc_llcp_exit();
  598. err_llcp_sock:
  599. rawsock_exit();
  600. err_rawsock:
  601. nfc_genl_exit();
  602. err_genl:
  603. class_unregister(&nfc_class);
  604. return rc;
  605. }
  606. static void __exit nfc_exit(void)
  607. {
  608. af_nfc_exit();
  609. nfc_llcp_exit();
  610. rawsock_exit();
  611. nfc_genl_exit();
  612. class_unregister(&nfc_class);
  613. }
  614. subsys_initcall(nfc_init);
  615. module_exit(nfc_exit);
  616. MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>");
  617. MODULE_DESCRIPTION("NFC Core ver " VERSION);
  618. MODULE_VERSION(VERSION);
  619. MODULE_LICENSE("GPL");