1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2011 Instituto Nokia de Tecnologia
6 * Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
7 * Lauro Ramos Venancio <lauro.venancio@openbossa.org>
10 #include <linux/nfc.h>
11 #include <linux/module.h>
15 static DEFINE_RWLOCK(proto_tab_lock
);
16 static const struct nfc_protocol
*proto_tab
[NFC_SOCKPROTO_MAX
];
18 static int nfc_sock_create(struct net
*net
, struct socket
*sock
, int proto
,
21 int rc
= -EPROTONOSUPPORT
;
26 if (proto
< 0 || proto
>= NFC_SOCKPROTO_MAX
)
29 read_lock(&proto_tab_lock
);
30 if (proto_tab
[proto
] && try_module_get(proto_tab
[proto
]->owner
)) {
31 rc
= proto_tab
[proto
]->create(net
, sock
, proto_tab
[proto
], kern
);
32 module_put(proto_tab
[proto
]->owner
);
34 read_unlock(&proto_tab_lock
);
39 static const struct net_proto_family nfc_sock_family_ops
= {
42 .create
= nfc_sock_create
,
45 int nfc_proto_register(const struct nfc_protocol
*nfc_proto
)
49 if (nfc_proto
->id
< 0 || nfc_proto
->id
>= NFC_SOCKPROTO_MAX
)
52 rc
= proto_register(nfc_proto
->proto
, 0);
56 write_lock(&proto_tab_lock
);
57 if (proto_tab
[nfc_proto
->id
])
60 proto_tab
[nfc_proto
->id
] = nfc_proto
;
61 write_unlock(&proto_tab_lock
);
65 EXPORT_SYMBOL(nfc_proto_register
);
67 void nfc_proto_unregister(const struct nfc_protocol
*nfc_proto
)
69 write_lock(&proto_tab_lock
);
70 proto_tab
[nfc_proto
->id
] = NULL
;
71 write_unlock(&proto_tab_lock
);
73 proto_unregister(nfc_proto
->proto
);
75 EXPORT_SYMBOL(nfc_proto_unregister
);
77 int __init
af_nfc_init(void)
79 return sock_register(&nfc_sock_family_ops
);
82 void af_nfc_exit(void)
84 sock_unregister(PF_NFC
);