Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 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 | |
Samuel Ortiz | 52858b5 | 2011-12-14 16:43:05 +0100 | [diff] [blame] | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__ |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 25 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 26 | #include <linux/init.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/slab.h> |
Samuel Ortiz | be055b2 | 2013-04-11 11:52:20 +0200 | [diff] [blame] | 30 | #include <linux/rfkill.h> |
Samuel Ortiz | 7c7cd3b | 2011-12-14 16:43:06 +0100 | [diff] [blame] | 31 | #include <linux/nfc.h> |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 32 | |
Samuel Ortiz | 5df16ca | 2012-06-12 16:54:16 +0200 | [diff] [blame] | 33 | #include <net/genetlink.h> |
| 34 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 35 | #include "nfc.h" |
| 36 | |
| 37 | #define VERSION "0.1" |
| 38 | |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 39 | #define NFC_CHECK_PRES_FREQ_MS 2000 |
| 40 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 41 | int nfc_devlist_generation; |
| 42 | DEFINE_MUTEX(nfc_devlist_mutex); |
| 43 | |
Samuel Ortiz | 7eda8b8e9 | 2012-10-22 15:57:58 +0200 | [diff] [blame] | 44 | /* NFC device ID bitmap */ |
| 45 | static DEFINE_IDA(nfc_index_ida); |
| 46 | |
Eric Lapuyade | 9674da8 | 2013-04-29 17:13:27 +0200 | [diff] [blame] | 47 | int nfc_fw_upload(struct nfc_dev *dev, const char *firmware_name) |
| 48 | { |
| 49 | int rc = 0; |
| 50 | |
| 51 | pr_debug("%s do firmware %s\n", dev_name(&dev->dev), firmware_name); |
| 52 | |
| 53 | device_lock(&dev->dev); |
| 54 | |
| 55 | if (!device_is_registered(&dev->dev)) { |
| 56 | rc = -ENODEV; |
| 57 | goto error; |
| 58 | } |
| 59 | |
| 60 | if (dev->dev_up) { |
| 61 | rc = -EBUSY; |
| 62 | goto error; |
| 63 | } |
| 64 | |
| 65 | if (!dev->ops->fw_upload) { |
| 66 | rc = -EOPNOTSUPP; |
| 67 | goto error; |
| 68 | } |
| 69 | |
| 70 | dev->fw_upload_in_progress = true; |
| 71 | rc = dev->ops->fw_upload(dev, firmware_name); |
| 72 | if (rc) |
| 73 | dev->fw_upload_in_progress = false; |
| 74 | |
| 75 | error: |
| 76 | device_unlock(&dev->dev); |
| 77 | return rc; |
| 78 | } |
| 79 | |
| 80 | int nfc_fw_upload_done(struct nfc_dev *dev, const char *firmware_name) |
| 81 | { |
| 82 | dev->fw_upload_in_progress = false; |
| 83 | |
| 84 | return nfc_genl_fw_upload_done(dev, firmware_name); |
| 85 | } |
| 86 | EXPORT_SYMBOL(nfc_fw_upload_done); |
| 87 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 88 | /** |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 89 | * nfc_dev_up - turn on the NFC device |
| 90 | * |
| 91 | * @dev: The nfc device to be turned on |
| 92 | * |
| 93 | * The device remains up until the nfc_dev_down function is called. |
| 94 | */ |
| 95 | int nfc_dev_up(struct nfc_dev *dev) |
| 96 | { |
| 97 | int rc = 0; |
| 98 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 99 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 100 | |
| 101 | device_lock(&dev->dev); |
| 102 | |
Samuel Ortiz | be055b2 | 2013-04-11 11:52:20 +0200 | [diff] [blame] | 103 | if (dev->rfkill && rfkill_blocked(dev->rfkill)) { |
| 104 | rc = -ERFKILL; |
| 105 | goto error; |
| 106 | } |
| 107 | |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 108 | if (!device_is_registered(&dev->dev)) { |
| 109 | rc = -ENODEV; |
| 110 | goto error; |
| 111 | } |
| 112 | |
Eric Lapuyade | 9674da8 | 2013-04-29 17:13:27 +0200 | [diff] [blame] | 113 | if (dev->fw_upload_in_progress) { |
| 114 | rc = -EBUSY; |
| 115 | goto error; |
| 116 | } |
| 117 | |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 118 | if (dev->dev_up) { |
| 119 | rc = -EALREADY; |
| 120 | goto error; |
| 121 | } |
| 122 | |
| 123 | if (dev->ops->dev_up) |
| 124 | rc = dev->ops->dev_up(dev); |
| 125 | |
| 126 | if (!rc) |
| 127 | dev->dev_up = true; |
| 128 | |
Samuel Ortiz | 0a94630 | 2013-05-10 11:57:06 +0200 | [diff] [blame] | 129 | /* We have to enable the device before discovering SEs */ |
| 130 | if (dev->ops->discover_se) { |
| 131 | rc = dev->ops->discover_se(dev); |
| 132 | if (!rc) |
| 133 | pr_warn("SE discovery failed\n"); |
| 134 | } |
| 135 | |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 136 | error: |
| 137 | device_unlock(&dev->dev); |
| 138 | return rc; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * nfc_dev_down - turn off the NFC device |
| 143 | * |
| 144 | * @dev: The nfc device to be turned off |
| 145 | */ |
| 146 | int nfc_dev_down(struct nfc_dev *dev) |
| 147 | { |
| 148 | int rc = 0; |
| 149 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 150 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 151 | |
| 152 | device_lock(&dev->dev); |
| 153 | |
| 154 | if (!device_is_registered(&dev->dev)) { |
| 155 | rc = -ENODEV; |
| 156 | goto error; |
| 157 | } |
| 158 | |
| 159 | if (!dev->dev_up) { |
| 160 | rc = -EALREADY; |
| 161 | goto error; |
| 162 | } |
| 163 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 164 | if (dev->polling || dev->active_target) { |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 165 | rc = -EBUSY; |
| 166 | goto error; |
| 167 | } |
| 168 | |
| 169 | if (dev->ops->dev_down) |
| 170 | dev->ops->dev_down(dev); |
| 171 | |
| 172 | dev->dev_up = false; |
| 173 | |
| 174 | error: |
| 175 | device_unlock(&dev->dev); |
| 176 | return rc; |
| 177 | } |
| 178 | |
Samuel Ortiz | be055b2 | 2013-04-11 11:52:20 +0200 | [diff] [blame] | 179 | static int nfc_rfkill_set_block(void *data, bool blocked) |
| 180 | { |
| 181 | struct nfc_dev *dev = data; |
| 182 | |
| 183 | pr_debug("%s blocked %d", dev_name(&dev->dev), blocked); |
| 184 | |
| 185 | if (!blocked) |
| 186 | return 0; |
| 187 | |
| 188 | nfc_dev_down(dev); |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static const struct rfkill_ops nfc_rfkill_ops = { |
| 194 | .set_block = nfc_rfkill_set_block, |
| 195 | }; |
| 196 | |
Ilan Elias | 8b3fe7b | 2011-09-18 11:19:33 +0300 | [diff] [blame] | 197 | /** |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 198 | * nfc_start_poll - start polling for nfc targets |
| 199 | * |
| 200 | * @dev: The nfc device that must start polling |
| 201 | * @protocols: bitset of nfc protocols that must be used for polling |
| 202 | * |
| 203 | * The device remains polling for targets until a target is found or |
| 204 | * the nfc_stop_poll function is called. |
| 205 | */ |
Samuel Ortiz | fe7c580 | 2012-05-15 15:57:06 +0200 | [diff] [blame] | 206 | int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 207 | { |
| 208 | int rc; |
| 209 | |
Samuel Ortiz | fe7c580 | 2012-05-15 15:57:06 +0200 | [diff] [blame] | 210 | pr_debug("dev_name %s initiator protocols 0x%x target protocols 0x%x\n", |
| 211 | dev_name(&dev->dev), im_protocols, tm_protocols); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 212 | |
Samuel Ortiz | fe7c580 | 2012-05-15 15:57:06 +0200 | [diff] [blame] | 213 | if (!im_protocols && !tm_protocols) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 214 | return -EINVAL; |
| 215 | |
| 216 | device_lock(&dev->dev); |
| 217 | |
| 218 | if (!device_is_registered(&dev->dev)) { |
| 219 | rc = -ENODEV; |
| 220 | goto error; |
| 221 | } |
| 222 | |
Samuel Ortiz | 7757dc8 | 2013-04-10 12:25:30 +0200 | [diff] [blame] | 223 | if (!dev->dev_up) { |
| 224 | rc = -ENODEV; |
| 225 | goto error; |
| 226 | } |
| 227 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 228 | if (dev->polling) { |
| 229 | rc = -EBUSY; |
| 230 | goto error; |
| 231 | } |
| 232 | |
Samuel Ortiz | fe7c580 | 2012-05-15 15:57:06 +0200 | [diff] [blame] | 233 | rc = dev->ops->start_poll(dev, im_protocols, tm_protocols); |
Samuel Ortiz | f212ad5 | 2012-05-31 00:02:26 +0200 | [diff] [blame] | 234 | if (!rc) { |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 235 | dev->polling = true; |
Samuel Ortiz | f212ad5 | 2012-05-31 00:02:26 +0200 | [diff] [blame] | 236 | dev->rf_mode = NFC_RF_NONE; |
| 237 | } |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 238 | |
| 239 | error: |
| 240 | device_unlock(&dev->dev); |
| 241 | return rc; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * nfc_stop_poll - stop polling for nfc targets |
| 246 | * |
| 247 | * @dev: The nfc device that must stop polling |
| 248 | */ |
| 249 | int nfc_stop_poll(struct nfc_dev *dev) |
| 250 | { |
| 251 | int rc = 0; |
| 252 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 253 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 254 | |
| 255 | device_lock(&dev->dev); |
| 256 | |
| 257 | if (!device_is_registered(&dev->dev)) { |
| 258 | rc = -ENODEV; |
| 259 | goto error; |
| 260 | } |
| 261 | |
| 262 | if (!dev->polling) { |
| 263 | rc = -EINVAL; |
| 264 | goto error; |
| 265 | } |
| 266 | |
| 267 | dev->ops->stop_poll(dev); |
| 268 | dev->polling = false; |
Thierry Escande | 5bcf099 | 2012-10-05 11:05:45 +0200 | [diff] [blame] | 269 | dev->rf_mode = NFC_RF_NONE; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 270 | |
| 271 | error: |
| 272 | device_unlock(&dev->dev); |
| 273 | return rc; |
| 274 | } |
| 275 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 276 | static struct nfc_target *nfc_find_target(struct nfc_dev *dev, u32 target_idx) |
| 277 | { |
| 278 | int i; |
| 279 | |
| 280 | if (dev->n_targets == 0) |
| 281 | return NULL; |
| 282 | |
Szymon Janc | 0f45077 | 2012-10-17 15:23:39 +0200 | [diff] [blame] | 283 | for (i = 0; i < dev->n_targets; i++) { |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 284 | if (dev->targets[i].idx == target_idx) |
| 285 | return &dev->targets[i]; |
| 286 | } |
| 287 | |
| 288 | return NULL; |
| 289 | } |
| 290 | |
Samuel Ortiz | 47807d3 | 2012-03-05 01:03:50 +0100 | [diff] [blame] | 291 | int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode) |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 292 | { |
| 293 | int rc = 0; |
Samuel Ortiz | 47807d3 | 2012-03-05 01:03:50 +0100 | [diff] [blame] | 294 | u8 *gb; |
| 295 | size_t gb_len; |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 296 | struct nfc_target *target; |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 297 | |
Samuel Ortiz | 47807d3 | 2012-03-05 01:03:50 +0100 | [diff] [blame] | 298 | pr_debug("dev_name=%s comm %d\n", dev_name(&dev->dev), comm_mode); |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 299 | |
| 300 | if (!dev->ops->dep_link_up) |
| 301 | return -EOPNOTSUPP; |
| 302 | |
| 303 | device_lock(&dev->dev); |
| 304 | |
| 305 | if (!device_is_registered(&dev->dev)) { |
| 306 | rc = -ENODEV; |
| 307 | goto error; |
| 308 | } |
| 309 | |
| 310 | if (dev->dep_link_up == true) { |
| 311 | rc = -EALREADY; |
| 312 | goto error; |
| 313 | } |
| 314 | |
Samuel Ortiz | 47807d3 | 2012-03-05 01:03:50 +0100 | [diff] [blame] | 315 | gb = nfc_llcp_general_bytes(dev, &gb_len); |
| 316 | if (gb_len > NFC_MAX_GT_LEN) { |
| 317 | rc = -EINVAL; |
| 318 | goto error; |
| 319 | } |
| 320 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 321 | target = nfc_find_target(dev, target_index); |
| 322 | if (target == NULL) { |
| 323 | rc = -ENOTCONN; |
| 324 | goto error; |
| 325 | } |
| 326 | |
| 327 | rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len); |
Samuel Ortiz | f212ad5 | 2012-05-31 00:02:26 +0200 | [diff] [blame] | 328 | if (!rc) { |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 329 | dev->active_target = target; |
Samuel Ortiz | f212ad5 | 2012-05-31 00:02:26 +0200 | [diff] [blame] | 330 | dev->rf_mode = NFC_RF_INITIATOR; |
| 331 | } |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 332 | |
| 333 | error: |
| 334 | device_unlock(&dev->dev); |
| 335 | return rc; |
| 336 | } |
| 337 | |
| 338 | int nfc_dep_link_down(struct nfc_dev *dev) |
| 339 | { |
| 340 | int rc = 0; |
| 341 | |
| 342 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
| 343 | |
| 344 | if (!dev->ops->dep_link_down) |
| 345 | return -EOPNOTSUPP; |
| 346 | |
| 347 | device_lock(&dev->dev); |
| 348 | |
| 349 | if (!device_is_registered(&dev->dev)) { |
| 350 | rc = -ENODEV; |
| 351 | goto error; |
| 352 | } |
| 353 | |
| 354 | if (dev->dep_link_up == false) { |
| 355 | rc = -EALREADY; |
| 356 | goto error; |
| 357 | } |
| 358 | |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 359 | rc = dev->ops->dep_link_down(dev); |
| 360 | if (!rc) { |
| 361 | dev->dep_link_up = false; |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 362 | dev->active_target = NULL; |
Thierry Escande | 5bcf099 | 2012-10-05 11:05:45 +0200 | [diff] [blame] | 363 | dev->rf_mode = NFC_RF_NONE; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 364 | nfc_llcp_mac_is_down(dev); |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 365 | nfc_genl_dep_link_down_event(dev); |
| 366 | } |
| 367 | |
| 368 | error: |
| 369 | device_unlock(&dev->dev); |
Thierry Escande | 5bcf099 | 2012-10-05 11:05:45 +0200 | [diff] [blame] | 370 | |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 371 | return rc; |
| 372 | } |
| 373 | |
| 374 | int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, |
Samuel Ortiz | 0a40acb | 2012-03-05 01:03:53 +0100 | [diff] [blame] | 375 | u8 comm_mode, u8 rf_mode) |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 376 | { |
| 377 | dev->dep_link_up = true; |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 378 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 379 | nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode); |
| 380 | |
Samuel Ortiz | 1ed28f6 | 2011-12-14 16:43:09 +0100 | [diff] [blame] | 381 | return nfc_genl_dep_link_up_event(dev, target_idx, comm_mode, rf_mode); |
| 382 | } |
| 383 | EXPORT_SYMBOL(nfc_dep_link_is_up); |
| 384 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 385 | /** |
| 386 | * nfc_activate_target - prepare the target for data exchange |
| 387 | * |
| 388 | * @dev: The nfc device that found the target |
| 389 | * @target_idx: index of the target that must be activated |
| 390 | * @protocol: nfc protocol that will be used for data exchange |
| 391 | */ |
| 392 | int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol) |
| 393 | { |
| 394 | int rc; |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 395 | struct nfc_target *target; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 396 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 397 | pr_debug("dev_name=%s target_idx=%u protocol=%u\n", |
| 398 | dev_name(&dev->dev), target_idx, protocol); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 399 | |
| 400 | device_lock(&dev->dev); |
| 401 | |
| 402 | if (!device_is_registered(&dev->dev)) { |
| 403 | rc = -ENODEV; |
| 404 | goto error; |
| 405 | } |
| 406 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 407 | if (dev->active_target) { |
| 408 | rc = -EBUSY; |
| 409 | goto error; |
| 410 | } |
| 411 | |
| 412 | target = nfc_find_target(dev, target_idx); |
| 413 | if (target == NULL) { |
| 414 | rc = -ENOTCONN; |
| 415 | goto error; |
| 416 | } |
| 417 | |
| 418 | rc = dev->ops->activate_target(dev, target, protocol); |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 419 | if (!rc) { |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 420 | dev->active_target = target; |
Samuel Ortiz | f212ad5 | 2012-05-31 00:02:26 +0200 | [diff] [blame] | 421 | dev->rf_mode = NFC_RF_INITIATOR; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 422 | |
Eric Lapuyade | f0c9103 | 2012-11-26 18:06:27 +0100 | [diff] [blame] | 423 | if (dev->ops->check_presence && !dev->shutting_down) |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 424 | mod_timer(&dev->check_pres_timer, jiffies + |
| 425 | msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS)); |
| 426 | } |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 427 | |
| 428 | error: |
| 429 | device_unlock(&dev->dev); |
| 430 | return rc; |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * nfc_deactivate_target - deactivate a nfc target |
| 435 | * |
| 436 | * @dev: The nfc device that found the target |
| 437 | * @target_idx: index of the target that must be deactivated |
| 438 | */ |
| 439 | int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx) |
| 440 | { |
| 441 | int rc = 0; |
| 442 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 443 | pr_debug("dev_name=%s target_idx=%u\n", |
| 444 | dev_name(&dev->dev), target_idx); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 445 | |
| 446 | device_lock(&dev->dev); |
| 447 | |
| 448 | if (!device_is_registered(&dev->dev)) { |
| 449 | rc = -ENODEV; |
| 450 | goto error; |
| 451 | } |
| 452 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 453 | if (dev->active_target == NULL) { |
| 454 | rc = -ENOTCONN; |
| 455 | goto error; |
| 456 | } |
| 457 | |
| 458 | if (dev->active_target->idx != target_idx) { |
| 459 | rc = -ENOTCONN; |
| 460 | goto error; |
| 461 | } |
| 462 | |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 463 | if (dev->ops->check_presence) |
| 464 | del_timer_sync(&dev->check_pres_timer); |
| 465 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 466 | dev->ops->deactivate_target(dev, dev->active_target); |
| 467 | dev->active_target = NULL; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 468 | |
| 469 | error: |
| 470 | device_unlock(&dev->dev); |
| 471 | return rc; |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * nfc_data_exchange - transceive data |
| 476 | * |
| 477 | * @dev: The nfc device that found the target |
| 478 | * @target_idx: index of the target |
| 479 | * @skb: data to be sent |
| 480 | * @cb: callback called when the response is received |
| 481 | * @cb_context: parameter for the callback function |
| 482 | * |
| 483 | * The user must wait for the callback before calling this function again. |
| 484 | */ |
Samuel Ortiz | 0a40acb | 2012-03-05 01:03:53 +0100 | [diff] [blame] | 485 | int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb, |
| 486 | data_exchange_cb_t cb, void *cb_context) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 487 | { |
| 488 | int rc; |
| 489 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 490 | pr_debug("dev_name=%s target_idx=%u skb->len=%u\n", |
| 491 | dev_name(&dev->dev), target_idx, skb->len); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 492 | |
| 493 | device_lock(&dev->dev); |
| 494 | |
| 495 | if (!device_is_registered(&dev->dev)) { |
| 496 | rc = -ENODEV; |
| 497 | kfree_skb(skb); |
| 498 | goto error; |
| 499 | } |
| 500 | |
Samuel Ortiz | be9ae4c | 2012-05-16 15:55:48 +0200 | [diff] [blame] | 501 | if (dev->rf_mode == NFC_RF_INITIATOR && dev->active_target != NULL) { |
| 502 | if (dev->active_target->idx != target_idx) { |
| 503 | rc = -EADDRNOTAVAIL; |
| 504 | kfree_skb(skb); |
| 505 | goto error; |
| 506 | } |
| 507 | |
| 508 | if (dev->ops->check_presence) |
| 509 | del_timer_sync(&dev->check_pres_timer); |
| 510 | |
| 511 | rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb, |
| 512 | cb_context); |
| 513 | |
Eric Lapuyade | f0c9103 | 2012-11-26 18:06:27 +0100 | [diff] [blame] | 514 | if (!rc && dev->ops->check_presence && !dev->shutting_down) |
Samuel Ortiz | be9ae4c | 2012-05-16 15:55:48 +0200 | [diff] [blame] | 515 | mod_timer(&dev->check_pres_timer, jiffies + |
| 516 | msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS)); |
| 517 | } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) { |
| 518 | rc = dev->ops->tm_send(dev, skb); |
| 519 | } else { |
Eric Lapuyade | 144612c | 2012-04-10 19:43:11 +0200 | [diff] [blame] | 520 | rc = -ENOTCONN; |
| 521 | kfree_skb(skb); |
| 522 | goto error; |
| 523 | } |
| 524 | |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 525 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 526 | error: |
| 527 | device_unlock(&dev->dev); |
| 528 | return rc; |
| 529 | } |
| 530 | |
Samuel Ortiz | c531c9e | 2013-05-10 16:15:32 +0200 | [diff] [blame^] | 531 | static struct nfc_se *find_se(struct nfc_dev *dev, u32 se_idx) |
| 532 | { |
| 533 | struct nfc_se *se, *n; |
| 534 | |
| 535 | list_for_each_entry_safe(se, n, &dev->secure_elements, list) |
| 536 | if (se->idx == se_idx) |
| 537 | return se; |
| 538 | |
| 539 | return NULL; |
| 540 | } |
| 541 | |
| 542 | int nfc_enable_se(struct nfc_dev *dev, u32 se_idx) |
| 543 | { |
| 544 | |
| 545 | struct nfc_se *se; |
| 546 | int rc; |
| 547 | |
| 548 | pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); |
| 549 | |
| 550 | device_lock(&dev->dev); |
| 551 | |
| 552 | if (!device_is_registered(&dev->dev)) { |
| 553 | rc = -ENODEV; |
| 554 | goto error; |
| 555 | } |
| 556 | |
| 557 | if (!dev->dev_up) { |
| 558 | rc = -ENODEV; |
| 559 | goto error; |
| 560 | } |
| 561 | |
| 562 | if (dev->polling) { |
| 563 | rc = -EBUSY; |
| 564 | goto error; |
| 565 | } |
| 566 | |
| 567 | if (!dev->ops->enable_se || !dev->ops->disable_se) { |
| 568 | rc = -EOPNOTSUPP; |
| 569 | goto error; |
| 570 | } |
| 571 | |
| 572 | se = find_se(dev, se_idx); |
| 573 | if (!se) { |
| 574 | rc = -EINVAL; |
| 575 | goto error; |
| 576 | } |
| 577 | |
| 578 | if (se->type == NFC_SE_ENABLED) { |
| 579 | rc = -EALREADY; |
| 580 | goto error; |
| 581 | } |
| 582 | |
| 583 | rc = dev->ops->enable_se(dev, se_idx); |
| 584 | |
| 585 | error: |
| 586 | device_unlock(&dev->dev); |
| 587 | return rc; |
| 588 | } |
| 589 | |
| 590 | int nfc_disable_se(struct nfc_dev *dev, u32 se_idx) |
| 591 | { |
| 592 | |
| 593 | struct nfc_se *se; |
| 594 | int rc; |
| 595 | |
| 596 | pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); |
| 597 | |
| 598 | device_lock(&dev->dev); |
| 599 | |
| 600 | if (!device_is_registered(&dev->dev)) { |
| 601 | rc = -ENODEV; |
| 602 | goto error; |
| 603 | } |
| 604 | |
| 605 | if (!dev->dev_up) { |
| 606 | rc = -ENODEV; |
| 607 | goto error; |
| 608 | } |
| 609 | |
| 610 | if (!dev->ops->enable_se || !dev->ops->disable_se) { |
| 611 | rc = -EOPNOTSUPP; |
| 612 | goto error; |
| 613 | } |
| 614 | |
| 615 | se = find_se(dev, se_idx); |
| 616 | if (!se) { |
| 617 | rc = -EINVAL; |
| 618 | goto error; |
| 619 | } |
| 620 | |
| 621 | if (se->type == NFC_SE_DISABLED) { |
| 622 | rc = -EALREADY; |
| 623 | goto error; |
| 624 | } |
| 625 | |
| 626 | rc = dev->ops->disable_se(dev, se_idx); |
| 627 | |
| 628 | error: |
| 629 | device_unlock(&dev->dev); |
| 630 | return rc; |
| 631 | } |
| 632 | |
Samuel Ortiz | 541d920 | 2011-12-14 16:43:10 +0100 | [diff] [blame] | 633 | int nfc_set_remote_general_bytes(struct nfc_dev *dev, u8 *gb, u8 gb_len) |
| 634 | { |
Samuel Ortiz | 0a40acb | 2012-03-05 01:03:53 +0100 | [diff] [blame] | 635 | pr_debug("dev_name=%s gb_len=%d\n", dev_name(&dev->dev), gb_len); |
Samuel Ortiz | 541d920 | 2011-12-14 16:43:10 +0100 | [diff] [blame] | 636 | |
| 637 | if (gb_len > NFC_MAX_GT_LEN) |
| 638 | return -EINVAL; |
| 639 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 640 | return nfc_llcp_set_remote_gb(dev, gb, gb_len); |
Samuel Ortiz | 541d920 | 2011-12-14 16:43:10 +0100 | [diff] [blame] | 641 | } |
| 642 | EXPORT_SYMBOL(nfc_set_remote_general_bytes); |
| 643 | |
Samuel Ortiz | ab73b75 | 2012-04-10 12:51:52 +0200 | [diff] [blame] | 644 | u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len) |
| 645 | { |
| 646 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
| 647 | |
| 648 | return nfc_llcp_general_bytes(dev, gb_len); |
| 649 | } |
| 650 | EXPORT_SYMBOL(nfc_get_local_general_bytes); |
| 651 | |
Samuel Ortiz | 73167ce | 2012-05-31 00:05:50 +0200 | [diff] [blame] | 652 | int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb) |
| 653 | { |
| 654 | /* Only LLCP target mode for now */ |
| 655 | if (dev->dep_link_up == false) { |
| 656 | kfree_skb(skb); |
| 657 | return -ENOLINK; |
| 658 | } |
| 659 | |
| 660 | return nfc_llcp_data_received(dev, skb); |
| 661 | } |
| 662 | EXPORT_SYMBOL(nfc_tm_data_received); |
| 663 | |
Samuel Ortiz | fc40a8c | 2012-06-01 13:21:13 +0200 | [diff] [blame] | 664 | int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode, |
| 665 | u8 *gb, size_t gb_len) |
| 666 | { |
| 667 | int rc; |
| 668 | |
| 669 | device_lock(&dev->dev); |
| 670 | |
| 671 | dev->polling = false; |
| 672 | |
| 673 | if (gb != NULL) { |
| 674 | rc = nfc_set_remote_general_bytes(dev, gb, gb_len); |
| 675 | if (rc < 0) |
| 676 | goto out; |
| 677 | } |
| 678 | |
Samuel Ortiz | f212ad5 | 2012-05-31 00:02:26 +0200 | [diff] [blame] | 679 | dev->rf_mode = NFC_RF_TARGET; |
| 680 | |
Samuel Ortiz | fc40a8c | 2012-06-01 13:21:13 +0200 | [diff] [blame] | 681 | if (protocol == NFC_PROTO_NFC_DEP_MASK) |
| 682 | nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET); |
| 683 | |
| 684 | rc = nfc_genl_tm_activated(dev, protocol); |
| 685 | |
| 686 | out: |
| 687 | device_unlock(&dev->dev); |
| 688 | |
| 689 | return rc; |
| 690 | } |
| 691 | EXPORT_SYMBOL(nfc_tm_activated); |
| 692 | |
| 693 | int nfc_tm_deactivated(struct nfc_dev *dev) |
| 694 | { |
| 695 | dev->dep_link_up = false; |
Thierry Escande | 5bcf099 | 2012-10-05 11:05:45 +0200 | [diff] [blame] | 696 | dev->rf_mode = NFC_RF_NONE; |
Samuel Ortiz | fc40a8c | 2012-06-01 13:21:13 +0200 | [diff] [blame] | 697 | |
| 698 | return nfc_genl_tm_deactivated(dev); |
| 699 | } |
| 700 | EXPORT_SYMBOL(nfc_tm_deactivated); |
| 701 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 702 | /** |
Samuel Ortiz | 7c7cd3b | 2011-12-14 16:43:06 +0100 | [diff] [blame] | 703 | * nfc_alloc_send_skb - allocate a skb for data exchange responses |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 704 | * |
| 705 | * @size: size to allocate |
| 706 | * @gfp: gfp flags |
| 707 | */ |
Samuel Ortiz | 7c7cd3b | 2011-12-14 16:43:06 +0100 | [diff] [blame] | 708 | struct sk_buff *nfc_alloc_send_skb(struct nfc_dev *dev, struct sock *sk, |
Samuel Ortiz | 0a40acb | 2012-03-05 01:03:53 +0100 | [diff] [blame] | 709 | unsigned int flags, unsigned int size, |
| 710 | unsigned int *err) |
Samuel Ortiz | 7c7cd3b | 2011-12-14 16:43:06 +0100 | [diff] [blame] | 711 | { |
| 712 | struct sk_buff *skb; |
| 713 | unsigned int total_size; |
| 714 | |
| 715 | total_size = size + |
| 716 | dev->tx_headroom + dev->tx_tailroom + NFC_HEADER_SIZE; |
| 717 | |
| 718 | skb = sock_alloc_send_skb(sk, total_size, flags & MSG_DONTWAIT, err); |
| 719 | if (skb) |
| 720 | skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE); |
| 721 | |
| 722 | return skb; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * nfc_alloc_recv_skb - allocate a skb for data exchange responses |
| 727 | * |
| 728 | * @size: size to allocate |
| 729 | * @gfp: gfp flags |
| 730 | */ |
| 731 | struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 732 | { |
| 733 | struct sk_buff *skb; |
| 734 | unsigned int total_size; |
| 735 | |
| 736 | total_size = size + 1; |
| 737 | skb = alloc_skb(total_size, gfp); |
| 738 | |
| 739 | if (skb) |
| 740 | skb_reserve(skb, 1); |
| 741 | |
| 742 | return skb; |
| 743 | } |
Samuel Ortiz | 7c7cd3b | 2011-12-14 16:43:06 +0100 | [diff] [blame] | 744 | EXPORT_SYMBOL(nfc_alloc_recv_skb); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 745 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 746 | /** |
| 747 | * nfc_targets_found - inform that targets were found |
| 748 | * |
| 749 | * @dev: The nfc device that found the targets |
| 750 | * @targets: array of nfc targets found |
| 751 | * @ntargets: targets array size |
| 752 | * |
| 753 | * The device driver must call this function when one or many nfc targets |
| 754 | * are found. After calling this function, the device driver must stop |
| 755 | * polling for targets. |
Eric Lapuyade | d94f9c5 | 2012-05-03 16:33:32 +0200 | [diff] [blame] | 756 | * NOTE: This function can be called with targets=NULL and n_targets=0 to |
| 757 | * notify a driver error, meaning that the polling operation cannot complete. |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 758 | * IMPORTANT: this function must not be called from an atomic context. |
| 759 | * In addition, it must also not be called from a context that would prevent |
| 760 | * the NFC Core to call other nfc ops entry point concurrently. |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 761 | */ |
Samuel Ortiz | 0a40acb | 2012-03-05 01:03:53 +0100 | [diff] [blame] | 762 | int nfc_targets_found(struct nfc_dev *dev, |
| 763 | struct nfc_target *targets, int n_targets) |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 764 | { |
Samuel Ortiz | c4fbb65 | 2012-04-10 19:43:09 +0200 | [diff] [blame] | 765 | int i; |
| 766 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 767 | pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 768 | |
Samuel Ortiz | c4fbb65 | 2012-04-10 19:43:09 +0200 | [diff] [blame] | 769 | for (i = 0; i < n_targets; i++) |
Eric Lapuyade | 01ae0ee | 2012-04-10 19:43:10 +0200 | [diff] [blame] | 770 | targets[i].idx = dev->target_next_idx++; |
Samuel Ortiz | c4fbb65 | 2012-04-10 19:43:09 +0200 | [diff] [blame] | 771 | |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 772 | device_lock(&dev->dev); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 773 | |
Eric Lapuyade | 8668fdd | 2012-05-03 16:21:58 +0200 | [diff] [blame] | 774 | if (dev->polling == false) { |
| 775 | device_unlock(&dev->dev); |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | dev->polling = false; |
| 780 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 781 | dev->targets_generation++; |
| 782 | |
| 783 | kfree(dev->targets); |
Eric Lapuyade | d94f9c5 | 2012-05-03 16:33:32 +0200 | [diff] [blame] | 784 | dev->targets = NULL; |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 785 | |
Eric Lapuyade | d94f9c5 | 2012-05-03 16:33:32 +0200 | [diff] [blame] | 786 | if (targets) { |
| 787 | dev->targets = kmemdup(targets, |
| 788 | n_targets * sizeof(struct nfc_target), |
| 789 | GFP_ATOMIC); |
| 790 | |
| 791 | if (!dev->targets) { |
| 792 | dev->n_targets = 0; |
| 793 | device_unlock(&dev->dev); |
| 794 | return -ENOMEM; |
| 795 | } |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | dev->n_targets = n_targets; |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 799 | device_unlock(&dev->dev); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 800 | |
| 801 | nfc_genl_targets_found(dev); |
| 802 | |
| 803 | return 0; |
| 804 | } |
| 805 | EXPORT_SYMBOL(nfc_targets_found); |
| 806 | |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 807 | /** |
| 808 | * nfc_target_lost - inform that an activated target went out of field |
| 809 | * |
| 810 | * @dev: The nfc device that had the activated target in field |
| 811 | * @target_idx: the nfc index of the target |
| 812 | * |
| 813 | * The device driver must call this function when the activated target |
| 814 | * goes out of the field. |
| 815 | * IMPORTANT: this function must not be called from an atomic context. |
| 816 | * In addition, it must also not be called from a context that would prevent |
| 817 | * the NFC Core to call other nfc ops entry point concurrently. |
| 818 | */ |
Eric Lapuyade | e1da0ef | 2012-04-10 19:43:05 +0200 | [diff] [blame] | 819 | int nfc_target_lost(struct nfc_dev *dev, u32 target_idx) |
| 820 | { |
| 821 | struct nfc_target *tg; |
| 822 | int i; |
| 823 | |
| 824 | pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx); |
| 825 | |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 826 | device_lock(&dev->dev); |
Eric Lapuyade | e1da0ef | 2012-04-10 19:43:05 +0200 | [diff] [blame] | 827 | |
| 828 | for (i = 0; i < dev->n_targets; i++) { |
| 829 | tg = &dev->targets[i]; |
| 830 | if (tg->idx == target_idx) |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | if (i == dev->n_targets) { |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 835 | device_unlock(&dev->dev); |
Eric Lapuyade | e1da0ef | 2012-04-10 19:43:05 +0200 | [diff] [blame] | 836 | return -EINVAL; |
| 837 | } |
| 838 | |
| 839 | dev->targets_generation++; |
| 840 | dev->n_targets--; |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 841 | dev->active_target = NULL; |
Eric Lapuyade | e1da0ef | 2012-04-10 19:43:05 +0200 | [diff] [blame] | 842 | |
| 843 | if (dev->n_targets) { |
| 844 | memcpy(&dev->targets[i], &dev->targets[i + 1], |
| 845 | (dev->n_targets - i) * sizeof(struct nfc_target)); |
| 846 | } else { |
| 847 | kfree(dev->targets); |
| 848 | dev->targets = NULL; |
| 849 | } |
| 850 | |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 851 | device_unlock(&dev->dev); |
Eric Lapuyade | e1da0ef | 2012-04-10 19:43:05 +0200 | [diff] [blame] | 852 | |
| 853 | nfc_genl_target_lost(dev, target_idx); |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | EXPORT_SYMBOL(nfc_target_lost); |
| 858 | |
Eric Lapuyade | 9eb334a | 2012-06-11 15:52:38 +0200 | [diff] [blame] | 859 | inline void nfc_driver_failure(struct nfc_dev *dev, int err) |
Eric Lapuyade | 456411c | 2012-06-11 13:49:51 +0200 | [diff] [blame] | 860 | { |
Eric Lapuyade | 9eb334a | 2012-06-11 15:52:38 +0200 | [diff] [blame] | 861 | nfc_targets_found(dev, NULL, 0); |
Eric Lapuyade | 456411c | 2012-06-11 13:49:51 +0200 | [diff] [blame] | 862 | } |
| 863 | EXPORT_SYMBOL(nfc_driver_failure); |
| 864 | |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 865 | int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type) |
| 866 | { |
Samuel Ortiz | c531c9e | 2013-05-10 16:15:32 +0200 | [diff] [blame^] | 867 | struct nfc_se *se; |
Samuel Ortiz | 2757c372 | 2013-05-10 15:47:37 +0200 | [diff] [blame] | 868 | int rc; |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 869 | |
| 870 | pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); |
| 871 | |
Samuel Ortiz | c531c9e | 2013-05-10 16:15:32 +0200 | [diff] [blame^] | 872 | se = find_se(dev, se_idx); |
| 873 | if (se) |
| 874 | return -EALREADY; |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 875 | |
| 876 | se = kzalloc(sizeof(struct nfc_se), GFP_KERNEL); |
| 877 | if (!se) |
| 878 | return -ENOMEM; |
| 879 | |
| 880 | se->idx = se_idx; |
| 881 | se->type = type; |
| 882 | se->state = NFC_SE_DISABLED; |
| 883 | INIT_LIST_HEAD(&se->list); |
| 884 | |
| 885 | list_add(&se->list, &dev->secure_elements); |
| 886 | |
Samuel Ortiz | 2757c372 | 2013-05-10 15:47:37 +0200 | [diff] [blame] | 887 | rc = nfc_genl_se_added(dev, se_idx, type); |
| 888 | if (rc < 0) { |
| 889 | list_del(&se->list); |
| 890 | kfree(se); |
| 891 | |
| 892 | return rc; |
| 893 | } |
| 894 | |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 895 | return 0; |
| 896 | } |
| 897 | EXPORT_SYMBOL(nfc_add_se); |
| 898 | |
| 899 | int nfc_remove_se(struct nfc_dev *dev, u32 se_idx) |
| 900 | { |
| 901 | struct nfc_se *se, *n; |
Samuel Ortiz | 2757c372 | 2013-05-10 15:47:37 +0200 | [diff] [blame] | 902 | int rc; |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 903 | |
| 904 | pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); |
| 905 | |
| 906 | list_for_each_entry_safe(se, n, &dev->secure_elements, list) |
| 907 | if (se->idx == se_idx) { |
Samuel Ortiz | 2757c372 | 2013-05-10 15:47:37 +0200 | [diff] [blame] | 908 | rc = nfc_genl_se_removed(dev, se_idx); |
| 909 | if (rc < 0) |
| 910 | return rc; |
| 911 | |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 912 | list_del(&se->list); |
| 913 | kfree(se); |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | return -EINVAL; |
| 919 | } |
| 920 | EXPORT_SYMBOL(nfc_remove_se); |
| 921 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 922 | static void nfc_release(struct device *d) |
| 923 | { |
| 924 | struct nfc_dev *dev = to_nfc_dev(d); |
Samuel Ortiz | ee656e9 | 2013-05-10 15:53:29 +0200 | [diff] [blame] | 925 | struct nfc_se *se, *n; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 926 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 927 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 928 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 929 | nfc_genl_data_exit(&dev->genl_data); |
| 930 | kfree(dev->targets); |
Samuel Ortiz | ee656e9 | 2013-05-10 15:53:29 +0200 | [diff] [blame] | 931 | |
| 932 | list_for_each_entry_safe(se, n, &dev->secure_elements, list) { |
| 933 | nfc_genl_se_removed(dev, se->idx); |
| 934 | list_del(&se->list); |
| 935 | kfree(se); |
| 936 | } |
| 937 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 938 | kfree(dev); |
| 939 | } |
| 940 | |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 941 | static void nfc_check_pres_work(struct work_struct *work) |
| 942 | { |
| 943 | struct nfc_dev *dev = container_of(work, struct nfc_dev, |
| 944 | check_pres_work); |
| 945 | int rc; |
| 946 | |
| 947 | device_lock(&dev->dev); |
| 948 | |
Eric Lapuyade | 9009943 | 2012-05-07 12:31:13 +0200 | [diff] [blame] | 949 | if (dev->active_target && timer_pending(&dev->check_pres_timer) == 0) { |
| 950 | rc = dev->ops->check_presence(dev, dev->active_target); |
Eric Lapuyade | 632c016 | 2012-10-02 17:27:36 +0200 | [diff] [blame] | 951 | if (rc == -EOPNOTSUPP) |
| 952 | goto exit; |
Eric Lapuyade | f0c9103 | 2012-11-26 18:06:27 +0100 | [diff] [blame] | 953 | if (rc) { |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 954 | u32 active_target_idx = dev->active_target->idx; |
| 955 | device_unlock(&dev->dev); |
| 956 | nfc_target_lost(dev, active_target_idx); |
| 957 | return; |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 958 | } |
Eric Lapuyade | f0c9103 | 2012-11-26 18:06:27 +0100 | [diff] [blame] | 959 | |
| 960 | if (!dev->shutting_down) |
| 961 | mod_timer(&dev->check_pres_timer, jiffies + |
| 962 | msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS)); |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 963 | } |
| 964 | |
Eric Lapuyade | 632c016 | 2012-10-02 17:27:36 +0200 | [diff] [blame] | 965 | exit: |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 966 | device_unlock(&dev->dev); |
| 967 | } |
| 968 | |
| 969 | static void nfc_check_pres_timeout(unsigned long data) |
| 970 | { |
| 971 | struct nfc_dev *dev = (struct nfc_dev *)data; |
| 972 | |
Linus Torvalds | 916082b | 2012-10-02 16:01:31 -0700 | [diff] [blame] | 973 | schedule_work(&dev->check_pres_work); |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 974 | } |
| 975 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 976 | struct class nfc_class = { |
| 977 | .name = "nfc", |
| 978 | .dev_release = nfc_release, |
| 979 | }; |
| 980 | EXPORT_SYMBOL(nfc_class); |
| 981 | |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 982 | static int match_idx(struct device *d, const void *data) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 983 | { |
| 984 | struct nfc_dev *dev = to_nfc_dev(d); |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 985 | const unsigned int *idx = data; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 986 | |
| 987 | return dev->idx == *idx; |
| 988 | } |
| 989 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 990 | struct nfc_dev *nfc_get_device(unsigned int idx) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 991 | { |
| 992 | struct device *d; |
| 993 | |
| 994 | d = class_find_device(&nfc_class, NULL, &idx, match_idx); |
| 995 | if (!d) |
| 996 | return NULL; |
| 997 | |
| 998 | return to_nfc_dev(d); |
| 999 | } |
| 1000 | |
| 1001 | /** |
| 1002 | * nfc_allocate_device - allocate a new nfc device |
| 1003 | * |
| 1004 | * @ops: device operations |
| 1005 | * @supported_protocols: NFC protocols supported by the device |
| 1006 | */ |
| 1007 | struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops, |
Samuel Ortiz | 0a40acb | 2012-03-05 01:03:53 +0100 | [diff] [blame] | 1008 | u32 supported_protocols, |
| 1009 | int tx_headroom, int tx_tailroom) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1010 | { |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1011 | struct nfc_dev *dev; |
| 1012 | |
| 1013 | if (!ops->start_poll || !ops->stop_poll || !ops->activate_target || |
Samuel Ortiz | be9ae4c | 2012-05-16 15:55:48 +0200 | [diff] [blame] | 1014 | !ops->deactivate_target || !ops->im_transceive) |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1015 | return NULL; |
| 1016 | |
| 1017 | if (!supported_protocols) |
| 1018 | return NULL; |
| 1019 | |
| 1020 | dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL); |
| 1021 | if (!dev) |
| 1022 | return NULL; |
| 1023 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1024 | dev->ops = ops; |
| 1025 | dev->supported_protocols = supported_protocols; |
Samuel Ortiz | e875304 | 2011-08-19 15:47:11 +0200 | [diff] [blame] | 1026 | dev->tx_headroom = tx_headroom; |
| 1027 | dev->tx_tailroom = tx_tailroom; |
Samuel Ortiz | fed7c25 | 2013-05-10 15:28:38 +0200 | [diff] [blame] | 1028 | INIT_LIST_HEAD(&dev->secure_elements); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1029 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1030 | nfc_genl_data_init(&dev->genl_data); |
| 1031 | |
Thierry Escande | 5bcf099 | 2012-10-05 11:05:45 +0200 | [diff] [blame] | 1032 | dev->rf_mode = NFC_RF_NONE; |
Eric Lapuyade | d4ccb13 | 2012-05-07 12:31:15 +0200 | [diff] [blame] | 1033 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1034 | /* first generation must not be 0 */ |
| 1035 | dev->targets_generation = 1; |
| 1036 | |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 1037 | if (ops->check_presence) { |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 1038 | init_timer(&dev->check_pres_timer); |
| 1039 | dev->check_pres_timer.data = (unsigned long)dev; |
| 1040 | dev->check_pres_timer.function = nfc_check_pres_timeout; |
| 1041 | |
| 1042 | INIT_WORK(&dev->check_pres_work, nfc_check_pres_work); |
Eric Lapuyade | c8d56ae | 2012-04-10 19:43:12 +0200 | [diff] [blame] | 1043 | } |
| 1044 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1045 | return dev; |
| 1046 | } |
| 1047 | EXPORT_SYMBOL(nfc_allocate_device); |
| 1048 | |
| 1049 | /** |
| 1050 | * nfc_register_device - register a nfc device in the nfc subsystem |
| 1051 | * |
| 1052 | * @dev: The nfc device to register |
| 1053 | */ |
| 1054 | int nfc_register_device(struct nfc_dev *dev) |
| 1055 | { |
| 1056 | int rc; |
| 1057 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 1058 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1059 | |
Samuel Ortiz | 7eda8b8e9 | 2012-10-22 15:57:58 +0200 | [diff] [blame] | 1060 | dev->idx = ida_simple_get(&nfc_index_ida, 0, 0, GFP_KERNEL); |
| 1061 | if (dev->idx < 0) |
| 1062 | return dev->idx; |
| 1063 | |
| 1064 | dev->dev.class = &nfc_class; |
| 1065 | dev_set_name(&dev->dev, "nfc%d", dev->idx); |
| 1066 | device_initialize(&dev->dev); |
| 1067 | |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1068 | mutex_lock(&nfc_devlist_mutex); |
| 1069 | nfc_devlist_generation++; |
| 1070 | rc = device_add(&dev->dev); |
| 1071 | mutex_unlock(&nfc_devlist_mutex); |
| 1072 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1073 | if (rc < 0) |
| 1074 | return rc; |
| 1075 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1076 | rc = nfc_llcp_register_device(dev); |
| 1077 | if (rc) |
| 1078 | pr_err("Could not register llcp device\n"); |
| 1079 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1080 | rc = nfc_genl_device_added(dev); |
| 1081 | if (rc) |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 1082 | pr_debug("The userspace won't be notified that the device %s was added\n", |
| 1083 | dev_name(&dev->dev)); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1084 | |
Samuel Ortiz | be055b2 | 2013-04-11 11:52:20 +0200 | [diff] [blame] | 1085 | dev->rfkill = rfkill_alloc(dev_name(&dev->dev), &dev->dev, |
| 1086 | RFKILL_TYPE_NFC, &nfc_rfkill_ops, dev); |
| 1087 | if (dev->rfkill) { |
| 1088 | if (rfkill_register(dev->rfkill) < 0) { |
| 1089 | rfkill_destroy(dev->rfkill); |
| 1090 | dev->rfkill = NULL; |
| 1091 | } |
| 1092 | } |
| 1093 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1094 | return 0; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1095 | } |
| 1096 | EXPORT_SYMBOL(nfc_register_device); |
| 1097 | |
| 1098 | /** |
| 1099 | * nfc_unregister_device - unregister a nfc device in the nfc subsystem |
| 1100 | * |
| 1101 | * @dev: The nfc device to unregister |
| 1102 | */ |
| 1103 | void nfc_unregister_device(struct nfc_dev *dev) |
| 1104 | { |
Samuel Ortiz | 7eda8b8e9 | 2012-10-22 15:57:58 +0200 | [diff] [blame] | 1105 | int rc, id; |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1106 | |
Joe Perches | 20c239c | 2011-11-29 11:37:33 -0800 | [diff] [blame] | 1107 | pr_debug("dev_name=%s\n", dev_name(&dev->dev)); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1108 | |
Samuel Ortiz | 7eda8b8e9 | 2012-10-22 15:57:58 +0200 | [diff] [blame] | 1109 | id = dev->idx; |
| 1110 | |
Samuel Ortiz | be055b2 | 2013-04-11 11:52:20 +0200 | [diff] [blame] | 1111 | if (dev->rfkill) { |
| 1112 | rfkill_unregister(dev->rfkill); |
| 1113 | rfkill_destroy(dev->rfkill); |
| 1114 | } |
| 1115 | |
Eric Lapuyade | f0c9103 | 2012-11-26 18:06:27 +0100 | [diff] [blame] | 1116 | if (dev->ops->check_presence) { |
| 1117 | device_lock(&dev->dev); |
| 1118 | dev->shutting_down = true; |
| 1119 | device_unlock(&dev->dev); |
| 1120 | del_timer_sync(&dev->check_pres_timer); |
| 1121 | cancel_work_sync(&dev->check_pres_work); |
| 1122 | } |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1123 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1124 | rc = nfc_genl_device_removed(dev); |
| 1125 | if (rc) |
Eric Lapuyade | f0c9103 | 2012-11-26 18:06:27 +0100 | [diff] [blame] | 1126 | pr_debug("The userspace won't be notified that the device %s " |
| 1127 | "was removed\n", dev_name(&dev->dev)); |
| 1128 | |
| 1129 | nfc_llcp_unregister_device(dev); |
| 1130 | |
| 1131 | mutex_lock(&nfc_devlist_mutex); |
| 1132 | nfc_devlist_generation++; |
| 1133 | device_del(&dev->dev); |
| 1134 | mutex_unlock(&nfc_devlist_mutex); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1135 | |
Samuel Ortiz | 7eda8b8e9 | 2012-10-22 15:57:58 +0200 | [diff] [blame] | 1136 | ida_simple_remove(&nfc_index_ida, id); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1137 | } |
| 1138 | EXPORT_SYMBOL(nfc_unregister_device); |
| 1139 | |
| 1140 | static int __init nfc_init(void) |
| 1141 | { |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1142 | int rc; |
| 1143 | |
Joe Perches | ed1e0ad | 2011-11-29 11:37:32 -0800 | [diff] [blame] | 1144 | pr_info("NFC Core ver %s\n", VERSION); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1145 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1146 | rc = class_register(&nfc_class); |
| 1147 | if (rc) |
| 1148 | return rc; |
| 1149 | |
| 1150 | rc = nfc_genl_init(); |
| 1151 | if (rc) |
| 1152 | goto err_genl; |
| 1153 | |
| 1154 | /* the first generation must not be 0 */ |
| 1155 | nfc_devlist_generation = 1; |
| 1156 | |
Lauro Ramos Venancio | 23b7869 | 2011-07-01 19:31:36 -0300 | [diff] [blame] | 1157 | rc = rawsock_init(); |
| 1158 | if (rc) |
| 1159 | goto err_rawsock; |
| 1160 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1161 | rc = nfc_llcp_init(); |
| 1162 | if (rc) |
| 1163 | goto err_llcp_sock; |
| 1164 | |
Aloisio Almeida Jr | c7fe3b5 | 2011-07-01 19:31:35 -0300 | [diff] [blame] | 1165 | rc = af_nfc_init(); |
| 1166 | if (rc) |
| 1167 | goto err_af_nfc; |
| 1168 | |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1169 | return 0; |
| 1170 | |
Aloisio Almeida Jr | c7fe3b5 | 2011-07-01 19:31:35 -0300 | [diff] [blame] | 1171 | err_af_nfc: |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1172 | nfc_llcp_exit(); |
| 1173 | err_llcp_sock: |
Lauro Ramos Venancio | 23b7869 | 2011-07-01 19:31:36 -0300 | [diff] [blame] | 1174 | rawsock_exit(); |
| 1175 | err_rawsock: |
Aloisio Almeida Jr | c7fe3b5 | 2011-07-01 19:31:35 -0300 | [diff] [blame] | 1176 | nfc_genl_exit(); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1177 | err_genl: |
| 1178 | class_unregister(&nfc_class); |
| 1179 | return rc; |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | static void __exit nfc_exit(void) |
| 1183 | { |
Aloisio Almeida Jr | c7fe3b5 | 2011-07-01 19:31:35 -0300 | [diff] [blame] | 1184 | af_nfc_exit(); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1185 | nfc_llcp_exit(); |
Lauro Ramos Venancio | 23b7869 | 2011-07-01 19:31:36 -0300 | [diff] [blame] | 1186 | rawsock_exit(); |
Lauro Ramos Venancio | 4d12b8b | 2011-07-01 19:31:34 -0300 | [diff] [blame] | 1187 | nfc_genl_exit(); |
Lauro Ramos Venancio | 3e256b8 | 2011-07-01 19:31:33 -0300 | [diff] [blame] | 1188 | class_unregister(&nfc_class); |
| 1189 | } |
| 1190 | |
| 1191 | subsys_initcall(nfc_init); |
| 1192 | module_exit(nfc_exit); |
| 1193 | |
| 1194 | MODULE_AUTHOR("Lauro Ramos Venancio <lauro.venancio@openbossa.org>"); |
| 1195 | MODULE_DESCRIPTION("NFC Core ver " VERSION); |
| 1196 | MODULE_VERSION(VERSION); |
| 1197 | MODULE_LICENSE("GPL"); |
Samuel Ortiz | 1155bb6 | 2012-06-12 00:35:50 +0200 | [diff] [blame] | 1198 | MODULE_ALIAS_NETPROTO(PF_NFC); |
Samuel Ortiz | 5df16ca | 2012-06-12 16:54:16 +0200 | [diff] [blame] | 1199 | MODULE_ALIAS_GENL_FAMILY(NFC_GENL_NAME); |