Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the |
| 16 | * Free Software Foundation, Inc., |
| 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #define pr_fmt(fmt) "llcp: %s: " fmt, __func__ |
| 21 | |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/nfc.h> |
| 26 | |
| 27 | #include "../nfc.h" |
| 28 | #include "llcp.h" |
| 29 | |
| 30 | static u8 llcp_magic[3] = {0x46, 0x66, 0x6d}; |
| 31 | |
| 32 | static struct list_head llcp_devices; |
| 33 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 34 | void nfc_llcp_sock_link(struct llcp_sock_list *l, struct sock *sk) |
| 35 | { |
| 36 | write_lock(&l->lock); |
| 37 | sk_add_node(sk, &l->head); |
| 38 | write_unlock(&l->lock); |
| 39 | } |
| 40 | |
| 41 | void nfc_llcp_sock_unlink(struct llcp_sock_list *l, struct sock *sk) |
| 42 | { |
| 43 | write_lock(&l->lock); |
| 44 | sk_del_node_init(sk); |
| 45 | write_unlock(&l->lock); |
| 46 | } |
| 47 | |
Samuel Ortiz | 4d22ea1 | 2012-06-22 14:40:34 +0200 | [diff] [blame] | 48 | static void nfc_llcp_socket_release(struct nfc_llcp_local *local, bool listen) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 49 | { |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 50 | struct sock *sk; |
| 51 | struct hlist_node *node, *tmp; |
| 52 | struct nfc_llcp_sock *llcp_sock; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 53 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 54 | write_lock(&local->sockets.lock); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 55 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 56 | sk_for_each_safe(sk, node, tmp, &local->sockets.head) { |
| 57 | llcp_sock = nfc_llcp_sock(sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 58 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 59 | lock_sock(sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 60 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 61 | if (sk->sk_state == LLCP_CONNECTED) |
| 62 | nfc_put_device(llcp_sock->dev); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 63 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 64 | if (sk->sk_state == LLCP_LISTEN) { |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 65 | struct nfc_llcp_sock *lsk, *n; |
| 66 | struct sock *accept_sk; |
| 67 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 68 | list_for_each_entry_safe(lsk, n, &llcp_sock->accept_queue, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 69 | accept_queue) { |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 70 | accept_sk = &lsk->sk; |
| 71 | lock_sock(accept_sk); |
| 72 | |
| 73 | nfc_llcp_accept_unlink(accept_sk); |
| 74 | |
| 75 | accept_sk->sk_state = LLCP_CLOSED; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 76 | |
| 77 | release_sock(accept_sk); |
| 78 | |
| 79 | sock_orphan(accept_sk); |
| 80 | } |
Samuel Ortiz | 4d22ea1 | 2012-06-22 14:40:34 +0200 | [diff] [blame] | 81 | |
| 82 | if (listen == true) { |
| 83 | release_sock(sk); |
| 84 | continue; |
| 85 | } |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 88 | sk->sk_state = LLCP_CLOSED; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 89 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 90 | release_sock(sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 91 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 92 | sock_orphan(sk); |
Samuel Ortiz | 40c75f8 | 2012-03-05 01:03:51 +0100 | [diff] [blame] | 93 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 94 | sk_del_node_init(sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 97 | write_unlock(&local->sockets.lock); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 100 | struct nfc_llcp_local *nfc_llcp_local_get(struct nfc_llcp_local *local) |
| 101 | { |
| 102 | kref_get(&local->ref); |
| 103 | |
| 104 | return local; |
| 105 | } |
| 106 | |
| 107 | static void local_release(struct kref *ref) |
| 108 | { |
| 109 | struct nfc_llcp_local *local; |
| 110 | |
| 111 | local = container_of(ref, struct nfc_llcp_local, ref); |
| 112 | |
| 113 | list_del(&local->list); |
Samuel Ortiz | 4d22ea1 | 2012-06-22 14:40:34 +0200 | [diff] [blame] | 114 | nfc_llcp_socket_release(local, false); |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 115 | del_timer_sync(&local->link_timer); |
| 116 | skb_queue_purge(&local->tx_queue); |
Tejun Heo | 474fee3 | 2012-08-22 16:22:16 -0700 | [diff] [blame^] | 117 | cancel_work_sync(&local->tx_work); |
| 118 | cancel_work_sync(&local->rx_work); |
| 119 | cancel_work_sync(&local->timeout_work); |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 120 | kfree_skb(local->rx_pending); |
| 121 | kfree(local); |
| 122 | } |
| 123 | |
| 124 | int nfc_llcp_local_put(struct nfc_llcp_local *local) |
| 125 | { |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 126 | if (local == NULL) |
| 127 | return 0; |
| 128 | |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 129 | return kref_put(&local->ref, local_release); |
| 130 | } |
| 131 | |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 132 | static struct nfc_llcp_sock *nfc_llcp_sock_get(struct nfc_llcp_local *local, |
| 133 | u8 ssap, u8 dsap) |
| 134 | { |
| 135 | struct sock *sk; |
| 136 | struct hlist_node *node; |
| 137 | struct nfc_llcp_sock *llcp_sock; |
| 138 | |
| 139 | pr_debug("ssap dsap %d %d\n", ssap, dsap); |
| 140 | |
| 141 | if (ssap == 0 && dsap == 0) |
| 142 | return NULL; |
| 143 | |
| 144 | read_lock(&local->sockets.lock); |
| 145 | |
| 146 | llcp_sock = NULL; |
| 147 | |
| 148 | sk_for_each(sk, node, &local->sockets.head) { |
| 149 | llcp_sock = nfc_llcp_sock(sk); |
| 150 | |
| 151 | if (llcp_sock->ssap == ssap && llcp_sock->dsap == dsap) |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | read_unlock(&local->sockets.lock); |
| 156 | |
| 157 | if (llcp_sock == NULL) |
| 158 | return NULL; |
| 159 | |
| 160 | sock_hold(&llcp_sock->sk); |
| 161 | |
| 162 | return llcp_sock; |
| 163 | } |
| 164 | |
| 165 | static void nfc_llcp_sock_put(struct nfc_llcp_sock *sock) |
| 166 | { |
| 167 | sock_put(&sock->sk); |
| 168 | } |
| 169 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 170 | static void nfc_llcp_timeout_work(struct work_struct *work) |
| 171 | { |
| 172 | struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 173 | timeout_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 174 | |
| 175 | nfc_dep_link_down(local->dev); |
| 176 | } |
| 177 | |
| 178 | static void nfc_llcp_symm_timer(unsigned long data) |
| 179 | { |
| 180 | struct nfc_llcp_local *local = (struct nfc_llcp_local *) data; |
| 181 | |
| 182 | pr_err("SYMM timeout\n"); |
| 183 | |
Tejun Heo | 474fee3 | 2012-08-22 16:22:16 -0700 | [diff] [blame^] | 184 | queue_work(system_nrt_wq, &local->timeout_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev) |
| 188 | { |
| 189 | struct nfc_llcp_local *local, *n; |
| 190 | |
| 191 | list_for_each_entry_safe(local, n, &llcp_devices, list) |
| 192 | if (local->dev == dev) |
| 193 | return local; |
| 194 | |
| 195 | pr_debug("No device found\n"); |
| 196 | |
| 197 | return NULL; |
| 198 | } |
| 199 | |
| 200 | static char *wks[] = { |
| 201 | NULL, |
| 202 | NULL, /* SDP */ |
| 203 | "urn:nfc:sn:ip", |
| 204 | "urn:nfc:sn:obex", |
| 205 | "urn:nfc:sn:snep", |
| 206 | }; |
| 207 | |
| 208 | static int nfc_llcp_wks_sap(char *service_name, size_t service_name_len) |
| 209 | { |
| 210 | int sap, num_wks; |
| 211 | |
| 212 | pr_debug("%s\n", service_name); |
| 213 | |
| 214 | if (service_name == NULL) |
| 215 | return -EINVAL; |
| 216 | |
| 217 | num_wks = ARRAY_SIZE(wks); |
| 218 | |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 219 | for (sap = 0; sap < num_wks; sap++) { |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 220 | if (wks[sap] == NULL) |
| 221 | continue; |
| 222 | |
| 223 | if (strncmp(wks[sap], service_name, service_name_len) == 0) |
| 224 | return sap; |
| 225 | } |
| 226 | |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 230 | static |
| 231 | struct nfc_llcp_sock *nfc_llcp_sock_from_sn(struct nfc_llcp_local *local, |
| 232 | u8 *sn, size_t sn_len) |
| 233 | { |
| 234 | struct sock *sk; |
| 235 | struct hlist_node *node; |
| 236 | struct nfc_llcp_sock *llcp_sock, *tmp_sock; |
| 237 | |
| 238 | pr_debug("sn %zd %p\n", sn_len, sn); |
| 239 | |
| 240 | if (sn == NULL || sn_len == 0) |
| 241 | return NULL; |
| 242 | |
| 243 | read_lock(&local->sockets.lock); |
| 244 | |
| 245 | llcp_sock = NULL; |
| 246 | |
| 247 | sk_for_each(sk, node, &local->sockets.head) { |
| 248 | tmp_sock = nfc_llcp_sock(sk); |
| 249 | |
| 250 | pr_debug("llcp sock %p\n", tmp_sock); |
| 251 | |
| 252 | if (tmp_sock->sk.sk_state != LLCP_LISTEN) |
| 253 | continue; |
| 254 | |
| 255 | if (tmp_sock->service_name == NULL || |
| 256 | tmp_sock->service_name_len == 0) |
| 257 | continue; |
| 258 | |
| 259 | if (tmp_sock->service_name_len != sn_len) |
| 260 | continue; |
| 261 | |
| 262 | if (memcmp(sn, tmp_sock->service_name, sn_len) == 0) { |
| 263 | llcp_sock = tmp_sock; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | read_unlock(&local->sockets.lock); |
| 269 | |
| 270 | pr_debug("Found llcp sock %p\n", llcp_sock); |
| 271 | |
| 272 | return llcp_sock; |
| 273 | } |
| 274 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 275 | u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 276 | struct nfc_llcp_sock *sock) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 277 | { |
| 278 | mutex_lock(&local->sdp_lock); |
| 279 | |
| 280 | if (sock->service_name != NULL && sock->service_name_len > 0) { |
| 281 | int ssap = nfc_llcp_wks_sap(sock->service_name, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 282 | sock->service_name_len); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 283 | |
| 284 | if (ssap > 0) { |
| 285 | pr_debug("WKS %d\n", ssap); |
| 286 | |
| 287 | /* This is a WKS, let's check if it's free */ |
| 288 | if (local->local_wks & BIT(ssap)) { |
| 289 | mutex_unlock(&local->sdp_lock); |
| 290 | |
| 291 | return LLCP_SAP_MAX; |
| 292 | } |
| 293 | |
Samuel Ortiz | 1762c17 | 2012-03-05 01:03:38 +0100 | [diff] [blame] | 294 | set_bit(ssap, &local->local_wks); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 295 | mutex_unlock(&local->sdp_lock); |
| 296 | |
| 297 | return ssap; |
| 298 | } |
| 299 | |
| 300 | /* |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 301 | * Check if there already is a non WKS socket bound |
| 302 | * to this service name. |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 303 | */ |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 304 | if (nfc_llcp_sock_from_sn(local, sock->service_name, |
| 305 | sock->service_name_len) != NULL) { |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 306 | mutex_unlock(&local->sdp_lock); |
| 307 | |
| 308 | return LLCP_SAP_MAX; |
| 309 | } |
| 310 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 311 | mutex_unlock(&local->sdp_lock); |
| 312 | |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 313 | return LLCP_SDP_UNBOUND; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 314 | |
Samuel Ortiz | ebbb16d | 2012-06-22 17:15:20 +0200 | [diff] [blame] | 315 | } else if (sock->ssap != 0 && sock->ssap < LLCP_WKS_NUM_SAP) { |
| 316 | if (!test_bit(sock->ssap, &local->local_wks)) { |
| 317 | set_bit(sock->ssap, &local->local_wks); |
| 318 | mutex_unlock(&local->sdp_lock); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 319 | |
Samuel Ortiz | ebbb16d | 2012-06-22 17:15:20 +0200 | [diff] [blame] | 320 | return sock->ssap; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | mutex_unlock(&local->sdp_lock); |
| 325 | |
| 326 | return LLCP_SAP_MAX; |
| 327 | } |
| 328 | |
| 329 | u8 nfc_llcp_get_local_ssap(struct nfc_llcp_local *local) |
| 330 | { |
| 331 | u8 local_ssap; |
| 332 | |
| 333 | mutex_lock(&local->sdp_lock); |
| 334 | |
| 335 | local_ssap = find_first_zero_bit(&local->local_sap, LLCP_LOCAL_NUM_SAP); |
| 336 | if (local_ssap == LLCP_LOCAL_NUM_SAP) { |
| 337 | mutex_unlock(&local->sdp_lock); |
| 338 | return LLCP_SAP_MAX; |
| 339 | } |
| 340 | |
Samuel Ortiz | 1762c17 | 2012-03-05 01:03:38 +0100 | [diff] [blame] | 341 | set_bit(local_ssap, &local->local_sap); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 342 | |
| 343 | mutex_unlock(&local->sdp_lock); |
| 344 | |
| 345 | return local_ssap + LLCP_LOCAL_SAP_OFFSET; |
| 346 | } |
| 347 | |
| 348 | void nfc_llcp_put_ssap(struct nfc_llcp_local *local, u8 ssap) |
| 349 | { |
| 350 | u8 local_ssap; |
| 351 | unsigned long *sdp; |
| 352 | |
| 353 | if (ssap < LLCP_WKS_NUM_SAP) { |
| 354 | local_ssap = ssap; |
| 355 | sdp = &local->local_wks; |
| 356 | } else if (ssap < LLCP_LOCAL_NUM_SAP) { |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 357 | atomic_t *client_cnt; |
| 358 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 359 | local_ssap = ssap - LLCP_WKS_NUM_SAP; |
| 360 | sdp = &local->local_sdp; |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 361 | client_cnt = &local->local_sdp_cnt[local_ssap]; |
| 362 | |
| 363 | pr_debug("%d clients\n", atomic_read(client_cnt)); |
| 364 | |
| 365 | mutex_lock(&local->sdp_lock); |
| 366 | |
| 367 | if (atomic_dec_and_test(client_cnt)) { |
| 368 | struct nfc_llcp_sock *l_sock; |
| 369 | |
| 370 | pr_debug("No more clients for SAP %d\n", ssap); |
| 371 | |
| 372 | clear_bit(local_ssap, sdp); |
| 373 | |
| 374 | /* Find the listening sock and set it back to UNBOUND */ |
| 375 | l_sock = nfc_llcp_sock_get(local, ssap, LLCP_SAP_SDP); |
| 376 | if (l_sock) { |
| 377 | l_sock->ssap = LLCP_SDP_UNBOUND; |
| 378 | nfc_llcp_sock_put(l_sock); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | mutex_unlock(&local->sdp_lock); |
| 383 | |
| 384 | return; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 385 | } else if (ssap < LLCP_MAX_SAP) { |
| 386 | local_ssap = ssap - LLCP_LOCAL_NUM_SAP; |
| 387 | sdp = &local->local_sap; |
| 388 | } else { |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | mutex_lock(&local->sdp_lock); |
| 393 | |
Samuel Ortiz | 1762c17 | 2012-03-05 01:03:38 +0100 | [diff] [blame] | 394 | clear_bit(local_ssap, sdp); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 395 | |
| 396 | mutex_unlock(&local->sdp_lock); |
| 397 | } |
| 398 | |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 399 | static u8 nfc_llcp_reserve_sdp_ssap(struct nfc_llcp_local *local) |
| 400 | { |
| 401 | u8 ssap; |
| 402 | |
| 403 | mutex_lock(&local->sdp_lock); |
| 404 | |
| 405 | ssap = find_first_zero_bit(&local->local_sdp, LLCP_SDP_NUM_SAP); |
| 406 | if (ssap == LLCP_SDP_NUM_SAP) { |
| 407 | mutex_unlock(&local->sdp_lock); |
| 408 | |
| 409 | return LLCP_SAP_MAX; |
| 410 | } |
| 411 | |
| 412 | pr_debug("SDP ssap %d\n", LLCP_WKS_NUM_SAP + ssap); |
| 413 | |
| 414 | set_bit(ssap, &local->local_sdp); |
| 415 | |
| 416 | mutex_unlock(&local->sdp_lock); |
| 417 | |
| 418 | return LLCP_WKS_NUM_SAP + ssap; |
| 419 | } |
| 420 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 421 | static int nfc_llcp_build_gb(struct nfc_llcp_local *local) |
| 422 | { |
| 423 | u8 *gb_cur, *version_tlv, version, version_length; |
| 424 | u8 *lto_tlv, lto, lto_length; |
| 425 | u8 *wks_tlv, wks_length; |
Samuel Ortiz | 56d5876 | 2012-04-10 19:43:19 +0200 | [diff] [blame] | 426 | u8 *miux_tlv, miux_length; |
| 427 | __be16 miux; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 428 | u8 gb_len = 0; |
| 429 | |
| 430 | version = LLCP_VERSION_11; |
| 431 | version_tlv = nfc_llcp_build_tlv(LLCP_TLV_VERSION, &version, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 432 | 1, &version_length); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 433 | gb_len += version_length; |
| 434 | |
| 435 | /* 1500 ms */ |
| 436 | lto = 150; |
Samuel Ortiz | 91b0ade | 2012-04-10 19:43:20 +0200 | [diff] [blame] | 437 | lto_tlv = nfc_llcp_build_tlv(LLCP_TLV_LTO, <o, 1, <o_length); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 438 | gb_len += lto_length; |
| 439 | |
| 440 | pr_debug("Local wks 0x%lx\n", local->local_wks); |
| 441 | wks_tlv = nfc_llcp_build_tlv(LLCP_TLV_WKS, (u8 *)&local->local_wks, 2, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 442 | &wks_length); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 443 | gb_len += wks_length; |
| 444 | |
Samuel Ortiz | 56d5876 | 2012-04-10 19:43:19 +0200 | [diff] [blame] | 445 | miux = cpu_to_be16(LLCP_MAX_MIUX); |
| 446 | miux_tlv = nfc_llcp_build_tlv(LLCP_TLV_MIUX, (u8 *)&miux, 0, |
| 447 | &miux_length); |
| 448 | gb_len += miux_length; |
| 449 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 450 | gb_len += ARRAY_SIZE(llcp_magic); |
| 451 | |
| 452 | if (gb_len > NFC_MAX_GT_LEN) { |
| 453 | kfree(version_tlv); |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | |
| 457 | gb_cur = local->gb; |
| 458 | |
| 459 | memcpy(gb_cur, llcp_magic, ARRAY_SIZE(llcp_magic)); |
| 460 | gb_cur += ARRAY_SIZE(llcp_magic); |
| 461 | |
| 462 | memcpy(gb_cur, version_tlv, version_length); |
| 463 | gb_cur += version_length; |
| 464 | |
| 465 | memcpy(gb_cur, lto_tlv, lto_length); |
| 466 | gb_cur += lto_length; |
| 467 | |
| 468 | memcpy(gb_cur, wks_tlv, wks_length); |
| 469 | gb_cur += wks_length; |
| 470 | |
Samuel Ortiz | 56d5876 | 2012-04-10 19:43:19 +0200 | [diff] [blame] | 471 | memcpy(gb_cur, miux_tlv, miux_length); |
| 472 | gb_cur += miux_length; |
| 473 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 474 | kfree(version_tlv); |
| 475 | kfree(lto_tlv); |
| 476 | |
| 477 | local->gb_len = gb_len; |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
Samuel Ortiz | b8e7a06 | 2012-06-22 02:04:53 +0200 | [diff] [blame] | 482 | u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len) |
| 483 | { |
| 484 | struct nfc_llcp_local *local; |
| 485 | |
| 486 | local = nfc_llcp_find_local(dev); |
| 487 | if (local == NULL) { |
| 488 | *general_bytes_len = 0; |
| 489 | return NULL; |
| 490 | } |
| 491 | |
| 492 | nfc_llcp_build_gb(local); |
| 493 | |
| 494 | *general_bytes_len = local->gb_len; |
| 495 | |
| 496 | return local->gb; |
| 497 | } |
| 498 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 499 | int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len) |
| 500 | { |
| 501 | struct nfc_llcp_local *local = nfc_llcp_find_local(dev); |
| 502 | |
| 503 | if (local == NULL) { |
| 504 | pr_err("No LLCP device\n"); |
| 505 | return -ENODEV; |
| 506 | } |
| 507 | |
| 508 | memset(local->remote_gb, 0, NFC_MAX_GT_LEN); |
| 509 | memcpy(local->remote_gb, gb, gb_len); |
| 510 | local->remote_gb_len = gb_len; |
| 511 | |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 512 | if (local->remote_gb == NULL || local->remote_gb_len == 0) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 513 | return -ENODEV; |
| 514 | |
| 515 | if (memcmp(local->remote_gb, llcp_magic, 3)) { |
| 516 | pr_err("MAC does not support LLCP\n"); |
| 517 | return -EINVAL; |
| 518 | } |
| 519 | |
Samuel Ortiz | 7a06e58 | 2012-05-07 22:03:34 +0200 | [diff] [blame] | 520 | return nfc_llcp_parse_gb_tlv(local, |
| 521 | &local->remote_gb[3], |
| 522 | local->remote_gb_len - 3); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 525 | static u8 nfc_llcp_dsap(struct sk_buff *pdu) |
| 526 | { |
| 527 | return (pdu->data[0] & 0xfc) >> 2; |
| 528 | } |
| 529 | |
| 530 | static u8 nfc_llcp_ptype(struct sk_buff *pdu) |
| 531 | { |
| 532 | return ((pdu->data[0] & 0x03) << 2) | ((pdu->data[1] & 0xc0) >> 6); |
| 533 | } |
| 534 | |
| 535 | static u8 nfc_llcp_ssap(struct sk_buff *pdu) |
| 536 | { |
| 537 | return pdu->data[1] & 0x3f; |
| 538 | } |
| 539 | |
| 540 | static u8 nfc_llcp_ns(struct sk_buff *pdu) |
| 541 | { |
| 542 | return pdu->data[2] >> 4; |
| 543 | } |
| 544 | |
| 545 | static u8 nfc_llcp_nr(struct sk_buff *pdu) |
| 546 | { |
| 547 | return pdu->data[2] & 0xf; |
| 548 | } |
| 549 | |
| 550 | static void nfc_llcp_set_nrns(struct nfc_llcp_sock *sock, struct sk_buff *pdu) |
| 551 | { |
Samuel Ortiz | 279cf17 | 2012-04-10 19:43:14 +0200 | [diff] [blame] | 552 | pdu->data[2] = (sock->send_n << 4) | (sock->recv_n); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 553 | sock->send_n = (sock->send_n + 1) % 16; |
| 554 | sock->recv_ack_n = (sock->recv_n - 1) % 16; |
| 555 | } |
| 556 | |
Samuel Ortiz | 8445796 | 2012-05-30 17:48:29 +0200 | [diff] [blame] | 557 | static void nfc_llcp_tx_work(struct work_struct *work) |
| 558 | { |
| 559 | struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local, |
| 560 | tx_work); |
| 561 | struct sk_buff *skb; |
| 562 | struct sock *sk; |
| 563 | struct nfc_llcp_sock *llcp_sock; |
| 564 | |
| 565 | skb = skb_dequeue(&local->tx_queue); |
| 566 | if (skb != NULL) { |
| 567 | sk = skb->sk; |
| 568 | llcp_sock = nfc_llcp_sock(sk); |
| 569 | if (llcp_sock != NULL) { |
| 570 | int ret; |
| 571 | |
| 572 | pr_debug("Sending pending skb\n"); |
| 573 | print_hex_dump(KERN_DEBUG, "LLCP Tx: ", |
| 574 | DUMP_PREFIX_OFFSET, 16, 1, |
| 575 | skb->data, skb->len, true); |
| 576 | |
| 577 | ret = nfc_data_exchange(local->dev, local->target_idx, |
| 578 | skb, nfc_llcp_recv, local); |
| 579 | |
| 580 | if (!ret && nfc_llcp_ptype(skb) == LLCP_PDU_I) { |
| 581 | skb = skb_get(skb); |
| 582 | skb_queue_tail(&llcp_sock->tx_pending_queue, |
| 583 | skb); |
| 584 | } |
| 585 | } else { |
| 586 | nfc_llcp_send_symm(local->dev); |
| 587 | } |
| 588 | } else { |
| 589 | nfc_llcp_send_symm(local->dev); |
| 590 | } |
| 591 | |
| 592 | mod_timer(&local->link_timer, |
| 593 | jiffies + msecs_to_jiffies(2 * local->remote_lto)); |
| 594 | } |
| 595 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 596 | static struct nfc_llcp_sock *nfc_llcp_connecting_sock_get(struct nfc_llcp_local *local, |
| 597 | u8 ssap) |
| 598 | { |
| 599 | struct sock *sk; |
| 600 | struct nfc_llcp_sock *llcp_sock; |
| 601 | struct hlist_node *node; |
| 602 | |
| 603 | read_lock(&local->connecting_sockets.lock); |
| 604 | |
| 605 | sk_for_each(sk, node, &local->connecting_sockets.head) { |
| 606 | llcp_sock = nfc_llcp_sock(sk); |
| 607 | |
Samuel Ortiz | 5a0f6f3 | 2012-05-21 11:44:42 +0200 | [diff] [blame] | 608 | if (llcp_sock->ssap == ssap) { |
| 609 | sock_hold(&llcp_sock->sk); |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 610 | goto out; |
Samuel Ortiz | 5a0f6f3 | 2012-05-21 11:44:42 +0200 | [diff] [blame] | 611 | } |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | llcp_sock = NULL; |
| 615 | |
| 616 | out: |
| 617 | read_unlock(&local->connecting_sockets.lock); |
| 618 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 619 | return llcp_sock; |
| 620 | } |
| 621 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 622 | static struct nfc_llcp_sock *nfc_llcp_sock_get_sn(struct nfc_llcp_local *local, |
| 623 | u8 *sn, size_t sn_len) |
| 624 | { |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 625 | struct nfc_llcp_sock *llcp_sock; |
| 626 | |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 627 | llcp_sock = nfc_llcp_sock_from_sn(local, sn, sn_len); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 628 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 629 | if (llcp_sock == NULL) |
| 630 | return NULL; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 631 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 632 | sock_hold(&llcp_sock->sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 633 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 634 | return llcp_sock; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 635 | } |
| 636 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 637 | static u8 *nfc_llcp_connect_sn(struct sk_buff *skb, size_t *sn_len) |
| 638 | { |
| 639 | u8 *tlv = &skb->data[2], type, length; |
| 640 | size_t tlv_array_len = skb->len - LLCP_HEADER_SIZE, offset = 0; |
| 641 | |
| 642 | while (offset < tlv_array_len) { |
| 643 | type = tlv[0]; |
| 644 | length = tlv[1]; |
| 645 | |
| 646 | pr_debug("type 0x%x length %d\n", type, length); |
| 647 | |
| 648 | if (type == LLCP_TLV_SN) { |
| 649 | *sn_len = length; |
| 650 | return &tlv[2]; |
| 651 | } |
| 652 | |
| 653 | offset += length + 2; |
| 654 | tlv += length + 2; |
| 655 | } |
| 656 | |
| 657 | return NULL; |
| 658 | } |
| 659 | |
| 660 | static void nfc_llcp_recv_connect(struct nfc_llcp_local *local, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 661 | struct sk_buff *skb) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 662 | { |
| 663 | struct sock *new_sk, *parent; |
| 664 | struct nfc_llcp_sock *sock, *new_sock; |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 665 | u8 dsap, ssap, reason; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 666 | |
| 667 | dsap = nfc_llcp_dsap(skb); |
| 668 | ssap = nfc_llcp_ssap(skb); |
| 669 | |
| 670 | pr_debug("%d %d\n", dsap, ssap); |
| 671 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 672 | if (dsap != LLCP_SAP_SDP) { |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 673 | sock = nfc_llcp_sock_get(local, dsap, LLCP_SAP_SDP); |
| 674 | if (sock == NULL || sock->sk.sk_state != LLCP_LISTEN) { |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 675 | reason = LLCP_DM_NOBOUND; |
| 676 | goto fail; |
| 677 | } |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 678 | } else { |
| 679 | u8 *sn; |
| 680 | size_t sn_len; |
| 681 | |
| 682 | sn = nfc_llcp_connect_sn(skb, &sn_len); |
| 683 | if (sn == NULL) { |
| 684 | reason = LLCP_DM_NOBOUND; |
| 685 | goto fail; |
| 686 | } |
| 687 | |
| 688 | pr_debug("Service name length %zu\n", sn_len); |
| 689 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 690 | sock = nfc_llcp_sock_get_sn(local, sn, sn_len); |
| 691 | if (sock == NULL) { |
| 692 | reason = LLCP_DM_NOBOUND; |
| 693 | goto fail; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 694 | } |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 695 | } |
| 696 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 697 | lock_sock(&sock->sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 698 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 699 | parent = &sock->sk; |
| 700 | |
| 701 | if (sk_acceptq_is_full(parent)) { |
| 702 | reason = LLCP_DM_REJ; |
| 703 | release_sock(&sock->sk); |
| 704 | sock_put(&sock->sk); |
| 705 | goto fail; |
| 706 | } |
| 707 | |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 708 | if (sock->ssap == LLCP_SDP_UNBOUND) { |
| 709 | u8 ssap = nfc_llcp_reserve_sdp_ssap(local); |
| 710 | |
| 711 | pr_debug("First client, reserving %d\n", ssap); |
| 712 | |
| 713 | if (ssap == LLCP_SAP_MAX) { |
| 714 | reason = LLCP_DM_REJ; |
| 715 | release_sock(&sock->sk); |
| 716 | sock_put(&sock->sk); |
| 717 | goto fail; |
| 718 | } |
| 719 | |
| 720 | sock->ssap = ssap; |
| 721 | } |
| 722 | |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 723 | new_sk = nfc_llcp_sock_alloc(NULL, parent->sk_type, GFP_ATOMIC); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 724 | if (new_sk == NULL) { |
| 725 | reason = LLCP_DM_REJ; |
| 726 | release_sock(&sock->sk); |
| 727 | sock_put(&sock->sk); |
| 728 | goto fail; |
| 729 | } |
| 730 | |
| 731 | new_sock = nfc_llcp_sock(new_sk); |
| 732 | new_sock->dev = local->dev; |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 733 | new_sock->local = nfc_llcp_local_get(local); |
Samuel Ortiz | 93d7e49 | 2012-05-14 17:37:32 +0200 | [diff] [blame] | 734 | new_sock->miu = local->remote_miu; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 735 | new_sock->nfc_protocol = sock->nfc_protocol; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 736 | new_sock->dsap = ssap; |
Samuel Ortiz | 025f152 | 2012-06-18 21:38:09 +0200 | [diff] [blame] | 737 | new_sock->target_idx = local->target_idx; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 738 | new_sock->parent = parent; |
Samuel Ortiz | 8f50020 | 2012-06-25 15:46:28 +0200 | [diff] [blame] | 739 | new_sock->ssap = sock->ssap; |
| 740 | if (sock->ssap < LLCP_LOCAL_NUM_SAP && sock->ssap >= LLCP_WKS_NUM_SAP) { |
| 741 | atomic_t *client_count; |
| 742 | |
| 743 | pr_debug("reserved_ssap %d for %p\n", sock->ssap, new_sock); |
| 744 | |
| 745 | client_count = |
| 746 | &local->local_sdp_cnt[sock->ssap - LLCP_WKS_NUM_SAP]; |
| 747 | |
| 748 | atomic_inc(client_count); |
| 749 | new_sock->reserved_ssap = sock->ssap; |
| 750 | } |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 751 | |
Samuel Ortiz | 7a06e58 | 2012-05-07 22:03:34 +0200 | [diff] [blame] | 752 | nfc_llcp_parse_connection_tlv(new_sock, &skb->data[LLCP_HEADER_SIZE], |
| 753 | skb->len - LLCP_HEADER_SIZE); |
| 754 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 755 | pr_debug("new sock %p sk %p\n", new_sock, &new_sock->sk); |
| 756 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 757 | nfc_llcp_sock_link(&local->sockets, new_sk); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 758 | |
| 759 | nfc_llcp_accept_enqueue(&sock->sk, new_sk); |
| 760 | |
| 761 | nfc_get_device(local->dev->idx); |
| 762 | |
| 763 | new_sk->sk_state = LLCP_CONNECTED; |
| 764 | |
| 765 | /* Wake the listening processes */ |
| 766 | parent->sk_data_ready(parent, 0); |
| 767 | |
| 768 | /* Send CC */ |
| 769 | nfc_llcp_send_cc(new_sock); |
| 770 | |
| 771 | release_sock(&sock->sk); |
| 772 | sock_put(&sock->sk); |
| 773 | |
| 774 | return; |
| 775 | |
| 776 | fail: |
| 777 | /* Send DM */ |
| 778 | nfc_llcp_send_dm(local, dsap, ssap, reason); |
| 779 | |
| 780 | return; |
| 781 | |
| 782 | } |
| 783 | |
Samuel Ortiz | d094afa | 2012-03-05 01:03:42 +0100 | [diff] [blame] | 784 | int nfc_llcp_queue_i_frames(struct nfc_llcp_sock *sock) |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 785 | { |
Samuel Ortiz | d094afa | 2012-03-05 01:03:42 +0100 | [diff] [blame] | 786 | int nr_frames = 0; |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 787 | struct nfc_llcp_local *local = sock->local; |
| 788 | |
| 789 | pr_debug("Remote ready %d tx queue len %d remote rw %d", |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 790 | sock->remote_ready, skb_queue_len(&sock->tx_pending_queue), |
Samuel Ortiz | 7a06e58 | 2012-05-07 22:03:34 +0200 | [diff] [blame] | 791 | sock->rw); |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 792 | |
| 793 | /* Try to queue some I frames for transmission */ |
| 794 | while (sock->remote_ready && |
Samuel Ortiz | 7a06e58 | 2012-05-07 22:03:34 +0200 | [diff] [blame] | 795 | skb_queue_len(&sock->tx_pending_queue) < sock->rw) { |
Samuel Ortiz | 8445796 | 2012-05-30 17:48:29 +0200 | [diff] [blame] | 796 | struct sk_buff *pdu; |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 797 | |
| 798 | pdu = skb_dequeue(&sock->tx_queue); |
| 799 | if (pdu == NULL) |
| 800 | break; |
| 801 | |
| 802 | /* Update N(S)/N(R) */ |
| 803 | nfc_llcp_set_nrns(sock, pdu); |
| 804 | |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 805 | skb_queue_tail(&local->tx_queue, pdu); |
Samuel Ortiz | d094afa | 2012-03-05 01:03:42 +0100 | [diff] [blame] | 806 | nr_frames++; |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 807 | } |
Samuel Ortiz | d094afa | 2012-03-05 01:03:42 +0100 | [diff] [blame] | 808 | |
| 809 | return nr_frames; |
Samuel Ortiz | 4722d2b | 2012-03-05 01:03:35 +0100 | [diff] [blame] | 810 | } |
| 811 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 812 | static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 813 | struct sk_buff *skb) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 814 | { |
| 815 | struct nfc_llcp_sock *llcp_sock; |
| 816 | struct sock *sk; |
| 817 | u8 dsap, ssap, ptype, ns, nr; |
| 818 | |
| 819 | ptype = nfc_llcp_ptype(skb); |
| 820 | dsap = nfc_llcp_dsap(skb); |
| 821 | ssap = nfc_llcp_ssap(skb); |
| 822 | ns = nfc_llcp_ns(skb); |
| 823 | nr = nfc_llcp_nr(skb); |
| 824 | |
| 825 | pr_debug("%d %d R %d S %d\n", dsap, ssap, nr, ns); |
| 826 | |
| 827 | llcp_sock = nfc_llcp_sock_get(local, dsap, ssap); |
| 828 | if (llcp_sock == NULL) { |
| 829 | nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN); |
| 830 | return; |
| 831 | } |
| 832 | |
| 833 | sk = &llcp_sock->sk; |
| 834 | lock_sock(sk); |
| 835 | if (sk->sk_state == LLCP_CLOSED) { |
| 836 | release_sock(sk); |
| 837 | nfc_llcp_sock_put(llcp_sock); |
| 838 | } |
| 839 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 840 | /* Pass the payload upstream */ |
| 841 | if (ptype == LLCP_PDU_I) { |
| 842 | pr_debug("I frame, queueing on %p\n", &llcp_sock->sk); |
| 843 | |
Samuel Ortiz | 53aef92 | 2012-03-05 01:03:36 +0100 | [diff] [blame] | 844 | if (ns == llcp_sock->recv_n) |
| 845 | llcp_sock->recv_n = (llcp_sock->recv_n + 1) % 16; |
| 846 | else |
| 847 | pr_err("Received out of sequence I PDU\n"); |
| 848 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 849 | skb_pull(skb, LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE); |
| 850 | if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) { |
| 851 | pr_err("receive queue is full\n"); |
| 852 | skb_queue_head(&llcp_sock->tx_backlog_queue, skb); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | /* Remove skbs from the pending queue */ |
| 857 | if (llcp_sock->send_ack_n != nr) { |
| 858 | struct sk_buff *s, *tmp; |
| 859 | |
| 860 | llcp_sock->send_ack_n = nr; |
| 861 | |
Samuel Ortiz | 8445796 | 2012-05-30 17:48:29 +0200 | [diff] [blame] | 862 | /* Remove and free all skbs until ns == nr */ |
| 863 | skb_queue_walk_safe(&llcp_sock->tx_pending_queue, s, tmp) { |
| 864 | skb_unlink(s, &llcp_sock->tx_pending_queue); |
| 865 | kfree_skb(s); |
| 866 | |
| 867 | if (nfc_llcp_ns(s) == nr) |
| 868 | break; |
| 869 | } |
| 870 | |
| 871 | /* Re-queue the remaining skbs for transmission */ |
| 872 | skb_queue_reverse_walk_safe(&llcp_sock->tx_pending_queue, |
| 873 | s, tmp) { |
| 874 | skb_unlink(s, &llcp_sock->tx_pending_queue); |
| 875 | skb_queue_head(&local->tx_queue, s); |
| 876 | } |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Samuel Ortiz | 53aef92 | 2012-03-05 01:03:36 +0100 | [diff] [blame] | 879 | if (ptype == LLCP_PDU_RR) |
| 880 | llcp_sock->remote_ready = true; |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 881 | else if (ptype == LLCP_PDU_RNR) |
Samuel Ortiz | 53aef92 | 2012-03-05 01:03:36 +0100 | [diff] [blame] | 882 | llcp_sock->remote_ready = false; |
| 883 | |
Samuel Ortiz | 56af256 | 2012-05-30 18:06:11 +0200 | [diff] [blame] | 884 | if (nfc_llcp_queue_i_frames(llcp_sock) == 0 && ptype == LLCP_PDU_I) |
Samuel Ortiz | d094afa | 2012-03-05 01:03:42 +0100 | [diff] [blame] | 885 | nfc_llcp_send_rr(llcp_sock); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 886 | |
| 887 | release_sock(sk); |
| 888 | nfc_llcp_sock_put(llcp_sock); |
| 889 | } |
| 890 | |
| 891 | static void nfc_llcp_recv_disc(struct nfc_llcp_local *local, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 892 | struct sk_buff *skb) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 893 | { |
| 894 | struct nfc_llcp_sock *llcp_sock; |
| 895 | struct sock *sk; |
| 896 | u8 dsap, ssap; |
| 897 | |
| 898 | dsap = nfc_llcp_dsap(skb); |
| 899 | ssap = nfc_llcp_ssap(skb); |
| 900 | |
| 901 | llcp_sock = nfc_llcp_sock_get(local, dsap, ssap); |
| 902 | if (llcp_sock == NULL) { |
| 903 | nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN); |
| 904 | return; |
| 905 | } |
| 906 | |
| 907 | sk = &llcp_sock->sk; |
| 908 | lock_sock(sk); |
| 909 | if (sk->sk_state == LLCP_CLOSED) { |
| 910 | release_sock(sk); |
| 911 | nfc_llcp_sock_put(llcp_sock); |
| 912 | } |
| 913 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 914 | if (sk->sk_state == LLCP_CONNECTED) { |
| 915 | nfc_put_device(local->dev); |
| 916 | sk->sk_state = LLCP_CLOSED; |
| 917 | sk->sk_state_change(sk); |
| 918 | } |
| 919 | |
| 920 | nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_DISC); |
| 921 | |
| 922 | release_sock(sk); |
| 923 | nfc_llcp_sock_put(llcp_sock); |
| 924 | } |
| 925 | |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 926 | static void nfc_llcp_recv_cc(struct nfc_llcp_local *local, struct sk_buff *skb) |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 927 | { |
| 928 | struct nfc_llcp_sock *llcp_sock; |
Samuel Ortiz | ff353d8 | 2012-05-07 12:31:19 +0200 | [diff] [blame] | 929 | struct sock *sk; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 930 | u8 dsap, ssap; |
| 931 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 932 | dsap = nfc_llcp_dsap(skb); |
| 933 | ssap = nfc_llcp_ssap(skb); |
| 934 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 935 | llcp_sock = nfc_llcp_connecting_sock_get(local, dsap); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 936 | if (llcp_sock == NULL) { |
| 937 | pr_err("Invalid CC\n"); |
| 938 | nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN); |
| 939 | |
| 940 | return; |
| 941 | } |
| 942 | |
Samuel Ortiz | ff353d8 | 2012-05-07 12:31:19 +0200 | [diff] [blame] | 943 | sk = &llcp_sock->sk; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 944 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 945 | /* Unlink from connecting and link to the client array */ |
| 946 | nfc_llcp_sock_unlink(&local->connecting_sockets, sk); |
| 947 | nfc_llcp_sock_link(&local->sockets, sk); |
| 948 | llcp_sock->dsap = ssap; |
| 949 | |
Samuel Ortiz | 7a06e58 | 2012-05-07 22:03:34 +0200 | [diff] [blame] | 950 | nfc_llcp_parse_connection_tlv(llcp_sock, &skb->data[LLCP_HEADER_SIZE], |
| 951 | skb->len - LLCP_HEADER_SIZE); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 952 | |
Samuel Ortiz | ff353d8 | 2012-05-07 12:31:19 +0200 | [diff] [blame] | 953 | sk->sk_state = LLCP_CONNECTED; |
| 954 | sk->sk_state_change(sk); |
| 955 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 956 | nfc_llcp_sock_put(llcp_sock); |
| 957 | } |
| 958 | |
Samuel Ortiz | 5c0560b | 2012-06-26 16:13:29 +0200 | [diff] [blame] | 959 | static void nfc_llcp_recv_dm(struct nfc_llcp_local *local, struct sk_buff *skb) |
| 960 | { |
| 961 | struct nfc_llcp_sock *llcp_sock; |
| 962 | struct sock *sk; |
| 963 | u8 dsap, ssap, reason; |
| 964 | |
| 965 | dsap = nfc_llcp_dsap(skb); |
| 966 | ssap = nfc_llcp_ssap(skb); |
| 967 | reason = skb->data[2]; |
| 968 | |
| 969 | pr_debug("%d %d reason %d\n", ssap, dsap, reason); |
| 970 | |
| 971 | switch (reason) { |
| 972 | case LLCP_DM_NOBOUND: |
| 973 | case LLCP_DM_REJ: |
| 974 | llcp_sock = nfc_llcp_connecting_sock_get(local, dsap); |
| 975 | break; |
| 976 | |
| 977 | default: |
| 978 | llcp_sock = nfc_llcp_sock_get(local, dsap, ssap); |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | if (llcp_sock == NULL) { |
| 983 | pr_err("Invalid DM\n"); |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | sk = &llcp_sock->sk; |
| 988 | |
| 989 | sk->sk_err = ENXIO; |
| 990 | sk->sk_state = LLCP_CLOSED; |
| 991 | sk->sk_state_change(sk); |
| 992 | |
| 993 | nfc_llcp_sock_put(llcp_sock); |
| 994 | |
| 995 | return; |
| 996 | } |
| 997 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 998 | static void nfc_llcp_rx_work(struct work_struct *work) |
| 999 | { |
| 1000 | struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 1001 | rx_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1002 | u8 dsap, ssap, ptype; |
| 1003 | struct sk_buff *skb; |
| 1004 | |
| 1005 | skb = local->rx_pending; |
| 1006 | if (skb == NULL) { |
| 1007 | pr_debug("No pending SKB\n"); |
| 1008 | return; |
| 1009 | } |
| 1010 | |
| 1011 | ptype = nfc_llcp_ptype(skb); |
| 1012 | dsap = nfc_llcp_dsap(skb); |
| 1013 | ssap = nfc_llcp_ssap(skb); |
| 1014 | |
| 1015 | pr_debug("ptype 0x%x dsap 0x%x ssap 0x%x\n", ptype, dsap, ssap); |
| 1016 | |
Samuel Ortiz | 4be646e | 2012-04-10 19:43:13 +0200 | [diff] [blame] | 1017 | if (ptype != LLCP_PDU_SYMM) |
| 1018 | print_hex_dump(KERN_DEBUG, "LLCP Rx: ", DUMP_PREFIX_OFFSET, |
| 1019 | 16, 1, skb->data, skb->len, true); |
| 1020 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1021 | switch (ptype) { |
| 1022 | case LLCP_PDU_SYMM: |
| 1023 | pr_debug("SYMM\n"); |
| 1024 | break; |
| 1025 | |
| 1026 | case LLCP_PDU_CONNECT: |
| 1027 | pr_debug("CONNECT\n"); |
| 1028 | nfc_llcp_recv_connect(local, skb); |
| 1029 | break; |
| 1030 | |
| 1031 | case LLCP_PDU_DISC: |
| 1032 | pr_debug("DISC\n"); |
| 1033 | nfc_llcp_recv_disc(local, skb); |
| 1034 | break; |
| 1035 | |
| 1036 | case LLCP_PDU_CC: |
| 1037 | pr_debug("CC\n"); |
| 1038 | nfc_llcp_recv_cc(local, skb); |
| 1039 | break; |
| 1040 | |
Samuel Ortiz | 5c0560b | 2012-06-26 16:13:29 +0200 | [diff] [blame] | 1041 | case LLCP_PDU_DM: |
| 1042 | pr_debug("DM\n"); |
| 1043 | nfc_llcp_recv_dm(local, skb); |
| 1044 | break; |
| 1045 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1046 | case LLCP_PDU_I: |
| 1047 | case LLCP_PDU_RR: |
Samuel Ortiz | 53aef92 | 2012-03-05 01:03:36 +0100 | [diff] [blame] | 1048 | case LLCP_PDU_RNR: |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1049 | pr_debug("I frame\n"); |
| 1050 | nfc_llcp_recv_hdlc(local, skb); |
| 1051 | break; |
| 1052 | |
| 1053 | } |
| 1054 | |
Tejun Heo | 474fee3 | 2012-08-22 16:22:16 -0700 | [diff] [blame^] | 1055 | queue_work(system_nrt_wq, &local->tx_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1056 | kfree_skb(local->rx_pending); |
| 1057 | local->rx_pending = NULL; |
| 1058 | |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | void nfc_llcp_recv(void *data, struct sk_buff *skb, int err) |
| 1063 | { |
| 1064 | struct nfc_llcp_local *local = (struct nfc_llcp_local *) data; |
| 1065 | |
| 1066 | pr_debug("Received an LLCP PDU\n"); |
| 1067 | if (err < 0) { |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 1068 | pr_err("err %d\n", err); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1069 | return; |
| 1070 | } |
| 1071 | |
| 1072 | local->rx_pending = skb_get(skb); |
| 1073 | del_timer(&local->link_timer); |
Tejun Heo | 474fee3 | 2012-08-22 16:22:16 -0700 | [diff] [blame^] | 1074 | queue_work(system_nrt_wq, &local->rx_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1075 | |
| 1076 | return; |
| 1077 | } |
| 1078 | |
Samuel Ortiz | 73167ce | 2012-05-31 00:05:50 +0200 | [diff] [blame] | 1079 | int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb) |
| 1080 | { |
| 1081 | struct nfc_llcp_local *local; |
| 1082 | |
| 1083 | local = nfc_llcp_find_local(dev); |
| 1084 | if (local == NULL) |
| 1085 | return -ENODEV; |
| 1086 | |
| 1087 | local->rx_pending = skb_get(skb); |
| 1088 | del_timer(&local->link_timer); |
Tejun Heo | 474fee3 | 2012-08-22 16:22:16 -0700 | [diff] [blame^] | 1089 | queue_work(system_nrt_wq, &local->rx_work); |
Samuel Ortiz | 73167ce | 2012-05-31 00:05:50 +0200 | [diff] [blame] | 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1094 | void nfc_llcp_mac_is_down(struct nfc_dev *dev) |
| 1095 | { |
| 1096 | struct nfc_llcp_local *local; |
| 1097 | |
| 1098 | local = nfc_llcp_find_local(dev); |
| 1099 | if (local == NULL) |
| 1100 | return; |
| 1101 | |
| 1102 | /* Close and purge all existing sockets */ |
Samuel Ortiz | 4d22ea1 | 2012-06-22 14:40:34 +0200 | [diff] [blame] | 1103 | nfc_llcp_socket_release(local, true); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void nfc_llcp_mac_is_up(struct nfc_dev *dev, u32 target_idx, |
| 1107 | u8 comm_mode, u8 rf_mode) |
| 1108 | { |
| 1109 | struct nfc_llcp_local *local; |
| 1110 | |
| 1111 | pr_debug("rf mode %d\n", rf_mode); |
| 1112 | |
| 1113 | local = nfc_llcp_find_local(dev); |
| 1114 | if (local == NULL) |
| 1115 | return; |
| 1116 | |
| 1117 | local->target_idx = target_idx; |
| 1118 | local->comm_mode = comm_mode; |
| 1119 | local->rf_mode = rf_mode; |
| 1120 | |
| 1121 | if (rf_mode == NFC_RF_INITIATOR) { |
| 1122 | pr_debug("Queueing Tx work\n"); |
| 1123 | |
Tejun Heo | 474fee3 | 2012-08-22 16:22:16 -0700 | [diff] [blame^] | 1124 | queue_work(system_nrt_wq, &local->tx_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1125 | } else { |
| 1126 | mod_timer(&local->link_timer, |
Samuel Ortiz | 427a2eb | 2012-03-05 01:03:52 +0100 | [diff] [blame] | 1127 | jiffies + msecs_to_jiffies(local->remote_lto)); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | int nfc_llcp_register_device(struct nfc_dev *ndev) |
| 1132 | { |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1133 | struct nfc_llcp_local *local; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1134 | |
| 1135 | local = kzalloc(sizeof(struct nfc_llcp_local), GFP_KERNEL); |
| 1136 | if (local == NULL) |
| 1137 | return -ENOMEM; |
| 1138 | |
| 1139 | local->dev = ndev; |
| 1140 | INIT_LIST_HEAD(&local->list); |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 1141 | kref_init(&local->ref); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1142 | mutex_init(&local->sdp_lock); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1143 | init_timer(&local->link_timer); |
| 1144 | local->link_timer.data = (unsigned long) local; |
| 1145 | local->link_timer.function = nfc_llcp_symm_timer; |
| 1146 | |
| 1147 | skb_queue_head_init(&local->tx_queue); |
| 1148 | INIT_WORK(&local->tx_work, nfc_llcp_tx_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1149 | |
| 1150 | local->rx_pending = NULL; |
| 1151 | INIT_WORK(&local->rx_work, nfc_llcp_rx_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1152 | |
| 1153 | INIT_WORK(&local->timeout_work, nfc_llcp_timeout_work); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1154 | |
Samuel Ortiz | a69f32a | 2012-05-04 17:04:19 +0200 | [diff] [blame] | 1155 | local->sockets.lock = __RW_LOCK_UNLOCKED(local->sockets.lock); |
| 1156 | local->connecting_sockets.lock = __RW_LOCK_UNLOCKED(local->connecting_sockets.lock); |
| 1157 | |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1158 | nfc_llcp_build_gb(local); |
| 1159 | |
| 1160 | local->remote_miu = LLCP_DEFAULT_MIU; |
| 1161 | local->remote_lto = LLCP_DEFAULT_LTO; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1162 | |
| 1163 | list_add(&llcp_devices, &local->list); |
| 1164 | |
| 1165 | return 0; |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | void nfc_llcp_unregister_device(struct nfc_dev *dev) |
| 1169 | { |
| 1170 | struct nfc_llcp_local *local = nfc_llcp_find_local(dev); |
| 1171 | |
| 1172 | if (local == NULL) { |
| 1173 | pr_debug("No such device\n"); |
| 1174 | return; |
| 1175 | } |
| 1176 | |
Samuel Ortiz | c7aa122 | 2012-05-04 11:24:16 +0200 | [diff] [blame] | 1177 | nfc_llcp_local_put(local); |
Samuel Ortiz | d646960 | 2011-12-14 16:43:12 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | int __init nfc_llcp_init(void) |
| 1181 | { |
| 1182 | INIT_LIST_HEAD(&llcp_devices); |
| 1183 | |
| 1184 | return nfc_llcp_sock_init(); |
| 1185 | } |
| 1186 | |
| 1187 | void nfc_llcp_exit(void) |
| 1188 | { |
| 1189 | nfc_llcp_sock_exit(); |
| 1190 | } |