Merge branch 'drm-intel-fixes' of git://people.freedesktop.org/~keithp/linux into...
[pandora-kernel.git] / net / nfc / nci / lib.c
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, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  *
26  */
27
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/errno.h>
32
33 #include <net/nfc/nci.h>
34
35 /* NCI status codes to Unix errno mapping */
36 int 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_MESSAGE_CORRUPTED:
46                 return -EBADMSG;
47
48         case NCI_STATUS_BUFFER_FULL:
49                 return -ENOBUFS;
50
51         case NCI_STATUS_NOT_INITIALIZED:
52                 return -EHOSTDOWN;
53
54         case NCI_STATUS_SYNTAX_ERROR:
55         case NCI_STATUS_SEMANTIC_ERROR:
56         case NCI_STATUS_INVALID_PARAM:
57         case NCI_STATUS_RF_PROTOCOL_ERROR:
58         case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
59                 return -EPROTO;
60
61         case NCI_STATUS_UNKNOWN_GID:
62         case NCI_STATUS_UNKNOWN_OID:
63                 return -EBADRQC;
64
65         case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
66                 return -EMSGSIZE;
67
68         case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
69                 return -EALREADY;
70
71         case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
72         case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
73                 return -ECONNREFUSED;
74
75         case NCI_STATUS_RF_TRANSMISSION_ERROR:
76         case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
77                 return -ECOMM;
78
79         case NCI_STATUS_RF_TIMEOUT_ERROR:
80         case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
81                 return -ETIMEDOUT;
82
83         case NCI_STATUS_RF_LINK_LOSS_ERROR:
84                 return -ENOLINK;
85
86         case NCI_STATUS_MAX_ACTIVE_NFCEE_INTERFACES_REACHED:
87                 return -EDQUOT;
88
89         case NCI_STATUS_FAILED:
90         default:
91                 return -ENOSYS;
92         }
93 }
94 EXPORT_SYMBOL(nci_to_errno);