Linux Audio

Check our new training course

Loading...
v4.17
 
 1/*
 2 *  The NFC Controller Interface is the communication protocol between an
 3 *  NFC Controller (NFCC) and a Device Host (DH).
 4 *
 5 *  Copyright (C) 2011 Texas Instruments, Inc.
 6 *
 7 *  Written by Ilan Elias <ilane@ti.com>
 8 *
 9 *  Acknowledgements:
10 *  This file is based on lib.c, which was written
11 *  by Maxim Krasnyansky.
12 *
13 *  This program is free software; you can redistribute it and/or modify
14 *  it under the terms of the GNU General Public License version 2
15 *  as published by the Free Software Foundation
16 *
17 *  This program is distributed in the hope that it will be useful,
18 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 *  GNU General Public License for more details.
21 *
22 *  You should have received a copy of the GNU General Public License
23 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
24 *
25 */
26
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/types.h>
30#include <linux/errno.h>
31
32#include <net/nfc/nci.h>
33#include <net/nfc/nci_core.h>
34
35/* NCI status codes to Unix errno mapping */
36int nci_to_errno(__u8 code)
37{
38	switch (code) {
39	case NCI_STATUS_OK:
40		return 0;
41
42	case NCI_STATUS_REJECTED:
43		return -EBUSY;
44
45	case NCI_STATUS_RF_FRAME_CORRUPTED:
46		return -EBADMSG;
47
48	case NCI_STATUS_NOT_INITIALIZED:
49		return -EHOSTDOWN;
50
51	case NCI_STATUS_SYNTAX_ERROR:
52	case NCI_STATUS_SEMANTIC_ERROR:
53	case NCI_STATUS_INVALID_PARAM:
54	case NCI_STATUS_RF_PROTOCOL_ERROR:
55	case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
56		return -EPROTO;
57
58	case NCI_STATUS_UNKNOWN_GID:
59	case NCI_STATUS_UNKNOWN_OID:
60		return -EBADRQC;
61
62	case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
63		return -EMSGSIZE;
64
65	case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
66		return -EALREADY;
67
68	case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
69	case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
70		return -ECONNREFUSED;
71
72	case NCI_STATUS_RF_TRANSMISSION_ERROR:
73	case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
74		return -ECOMM;
75
76	case NCI_STATUS_RF_TIMEOUT_ERROR:
77	case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
78		return -ETIMEDOUT;
79
80	case NCI_STATUS_FAILED:
81	default:
82		return -ENOSYS;
83	}
84}
85EXPORT_SYMBOL(nci_to_errno);
v6.8
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 *  The NFC Controller Interface is the communication protocol between an
 4 *  NFC Controller (NFCC) and a Device Host (DH).
 5 *
 6 *  Copyright (C) 2011 Texas Instruments, Inc.
 7 *
 8 *  Written by Ilan Elias <ilane@ti.com>
 9 *
10 *  Acknowledgements:
11 *  This file is based on lib.c, which was written
12 *  by Maxim Krasnyansky.
 
 
 
 
 
 
 
 
 
 
 
 
 
13 */
14
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/types.h>
18#include <linux/errno.h>
19
20#include <net/nfc/nci.h>
21#include <net/nfc/nci_core.h>
22
23/* NCI status codes to Unix errno mapping */
24int nci_to_errno(__u8 code)
25{
26	switch (code) {
27	case NCI_STATUS_OK:
28		return 0;
29
30	case NCI_STATUS_REJECTED:
31		return -EBUSY;
32
33	case NCI_STATUS_RF_FRAME_CORRUPTED:
34		return -EBADMSG;
35
36	case NCI_STATUS_NOT_INITIALIZED:
37		return -EHOSTDOWN;
38
39	case NCI_STATUS_SYNTAX_ERROR:
40	case NCI_STATUS_SEMANTIC_ERROR:
41	case NCI_STATUS_INVALID_PARAM:
42	case NCI_STATUS_RF_PROTOCOL_ERROR:
43	case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
44		return -EPROTO;
45
46	case NCI_STATUS_UNKNOWN_GID:
47	case NCI_STATUS_UNKNOWN_OID:
48		return -EBADRQC;
49
50	case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
51		return -EMSGSIZE;
52
53	case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
54		return -EALREADY;
55
56	case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
57	case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
58		return -ECONNREFUSED;
59
60	case NCI_STATUS_RF_TRANSMISSION_ERROR:
61	case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
62		return -ECOMM;
63
64	case NCI_STATUS_RF_TIMEOUT_ERROR:
65	case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
66		return -ETIMEDOUT;
67
68	case NCI_STATUS_FAILED:
69	default:
70		return -ENOSYS;
71	}
72}
73EXPORT_SYMBOL(nci_to_errno);