18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  The NFC Controller Interface is the communication protocol between an
48c2ecf20Sopenharmony_ci *  NFC Controller (NFCC) and a Device Host (DH).
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci *  Copyright (C) 2011 Texas Instruments, Inc.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *  Written by Ilan Elias <ilane@ti.com>
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *  Acknowledgements:
118c2ecf20Sopenharmony_ci *  This file is based on lib.c, which was written
128c2ecf20Sopenharmony_ci *  by Maxim Krasnyansky.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/module.h>
168c2ecf20Sopenharmony_ci#include <linux/kernel.h>
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci#include <linux/errno.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include <net/nfc/nci.h>
218c2ecf20Sopenharmony_ci#include <net/nfc/nci_core.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* NCI status codes to Unix errno mapping */
248c2ecf20Sopenharmony_ciint nci_to_errno(__u8 code)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	switch (code) {
278c2ecf20Sopenharmony_ci	case NCI_STATUS_OK:
288c2ecf20Sopenharmony_ci		return 0;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	case NCI_STATUS_REJECTED:
318c2ecf20Sopenharmony_ci		return -EBUSY;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	case NCI_STATUS_RF_FRAME_CORRUPTED:
348c2ecf20Sopenharmony_ci		return -EBADMSG;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	case NCI_STATUS_NOT_INITIALIZED:
378c2ecf20Sopenharmony_ci		return -EHOSTDOWN;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	case NCI_STATUS_SYNTAX_ERROR:
408c2ecf20Sopenharmony_ci	case NCI_STATUS_SEMANTIC_ERROR:
418c2ecf20Sopenharmony_ci	case NCI_STATUS_INVALID_PARAM:
428c2ecf20Sopenharmony_ci	case NCI_STATUS_RF_PROTOCOL_ERROR:
438c2ecf20Sopenharmony_ci	case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
448c2ecf20Sopenharmony_ci		return -EPROTO;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	case NCI_STATUS_UNKNOWN_GID:
478c2ecf20Sopenharmony_ci	case NCI_STATUS_UNKNOWN_OID:
488c2ecf20Sopenharmony_ci		return -EBADRQC;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
518c2ecf20Sopenharmony_ci		return -EMSGSIZE;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
548c2ecf20Sopenharmony_ci		return -EALREADY;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
578c2ecf20Sopenharmony_ci	case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
588c2ecf20Sopenharmony_ci		return -ECONNREFUSED;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	case NCI_STATUS_RF_TRANSMISSION_ERROR:
618c2ecf20Sopenharmony_ci	case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
628c2ecf20Sopenharmony_ci		return -ECOMM;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	case NCI_STATUS_RF_TIMEOUT_ERROR:
658c2ecf20Sopenharmony_ci	case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
668c2ecf20Sopenharmony_ci		return -ETIMEDOUT;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	case NCI_STATUS_FAILED:
698c2ecf20Sopenharmony_ci	default:
708c2ecf20Sopenharmony_ci		return -ENOSYS;
718c2ecf20Sopenharmony_ci	}
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ciEXPORT_SYMBOL(nci_to_errno);
74