blob: 6b7fd26c68d91a44d86111c6e46b433b8e5d1692 [file] [log] [blame]
Ilan Elias6a2968a2011-09-18 11:19:35 +03001/*
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>
H Hartley Sweeten502b4242012-05-07 12:31:25 +020034#include <net/nfc/nci_core.h>
Ilan Elias6a2968a2011-09-18 11:19:35 +030035
36/* NCI status codes to Unix errno mapping */
37int nci_to_errno(__u8 code)
38{
39 switch (code) {
40 case NCI_STATUS_OK:
41 return 0;
42
43 case NCI_STATUS_REJECTED:
44 return -EBUSY;
45
Ilan Eliase8c0dac2011-11-09 12:09:14 +020046 case NCI_STATUS_RF_FRAME_CORRUPTED:
Ilan Elias6a2968a2011-09-18 11:19:35 +030047 return -EBADMSG;
48
Ilan Elias6a2968a2011-09-18 11:19:35 +030049 case NCI_STATUS_NOT_INITIALIZED:
50 return -EHOSTDOWN;
51
52 case NCI_STATUS_SYNTAX_ERROR:
53 case NCI_STATUS_SEMANTIC_ERROR:
54 case NCI_STATUS_INVALID_PARAM:
55 case NCI_STATUS_RF_PROTOCOL_ERROR:
56 case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
57 return -EPROTO;
58
59 case NCI_STATUS_UNKNOWN_GID:
60 case NCI_STATUS_UNKNOWN_OID:
61 return -EBADRQC;
62
63 case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
64 return -EMSGSIZE;
65
66 case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
67 return -EALREADY;
68
69 case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
70 case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
71 return -ECONNREFUSED;
72
73 case NCI_STATUS_RF_TRANSMISSION_ERROR:
74 case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
75 return -ECOMM;
76
77 case NCI_STATUS_RF_TIMEOUT_ERROR:
78 case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
79 return -ETIMEDOUT;
80
Ilan Elias6a2968a2011-09-18 11:19:35 +030081 case NCI_STATUS_FAILED:
82 default:
83 return -ENOSYS;
84 }
85}
86EXPORT_SYMBOL(nci_to_errno);