2 * Copyright (C) 2011 Instituto Nokia de Tecnologia
5 * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
6 * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
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.
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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include <linux/nfc.h>
23 #include <linux/module.h>
27 static DEFINE_RWLOCK(proto_tab_lock
);
28 static const struct nfc_protocol
*proto_tab
[NFC_SOCKPROTO_MAX
];
30 static int nfc_sock_create(struct net
*net
, struct socket
*sock
, int proto
,
33 int rc
= -EPROTONOSUPPORT
;
38 if (proto
< 0 || proto
>= NFC_SOCKPROTO_MAX
)
41 read_lock(&proto_tab_lock
);
42 if (proto_tab
[proto
] && try_module_get(proto_tab
[proto
]->owner
)) {
43 rc
= proto_tab
[proto
]->create(net
, sock
, proto_tab
[proto
], kern
);
44 module_put(proto_tab
[proto
]->owner
);
46 read_unlock(&proto_tab_lock
);
51 static struct net_proto_family nfc_sock_family_ops
= {
54 .create
= nfc_sock_create
,
57 int nfc_proto_register(const struct nfc_protocol
*nfc_proto
)
61 if (nfc_proto
->id
< 0 || nfc_proto
->id
>= NFC_SOCKPROTO_MAX
)
64 rc
= proto_register(nfc_proto
->proto
, 0);
68 write_lock(&proto_tab_lock
);
69 if (proto_tab
[nfc_proto
->id
])
72 proto_tab
[nfc_proto
->id
] = nfc_proto
;
73 write_unlock(&proto_tab_lock
);
77 EXPORT_SYMBOL(nfc_proto_register
);
79 void nfc_proto_unregister(const struct nfc_protocol
*nfc_proto
)
81 write_lock(&proto_tab_lock
);
82 proto_tab
[nfc_proto
->id
] = NULL
;
83 write_unlock(&proto_tab_lock
);
85 proto_unregister(nfc_proto
->proto
);
87 EXPORT_SYMBOL(nfc_proto_unregister
);
89 int __init
af_nfc_init(void)
91 return sock_register(&nfc_sock_family_ops
);
94 void af_nfc_exit(void)
96 sock_unregister(PF_NFC
);