lib.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <[email protected]>
  9. *
  10. * Acknowledgements:
  11. * This file is based on lib.c, which was written
  12. * by Maxim Krasnyansky.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. #include <net/nfc/nci.h>
  19. #include <net/nfc/nci_core.h>
  20. /* NCI status codes to Unix errno mapping */
  21. int nci_to_errno(__u8 code)
  22. {
  23. switch (code) {
  24. case NCI_STATUS_OK:
  25. return 0;
  26. case NCI_STATUS_REJECTED:
  27. return -EBUSY;
  28. case NCI_STATUS_RF_FRAME_CORRUPTED:
  29. return -EBADMSG;
  30. case NCI_STATUS_NOT_INITIALIZED:
  31. return -EHOSTDOWN;
  32. case NCI_STATUS_SYNTAX_ERROR:
  33. case NCI_STATUS_SEMANTIC_ERROR:
  34. case NCI_STATUS_INVALID_PARAM:
  35. case NCI_STATUS_RF_PROTOCOL_ERROR:
  36. case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
  37. return -EPROTO;
  38. case NCI_STATUS_UNKNOWN_GID:
  39. case NCI_STATUS_UNKNOWN_OID:
  40. return -EBADRQC;
  41. case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
  42. return -EMSGSIZE;
  43. case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
  44. return -EALREADY;
  45. case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
  46. case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
  47. return -ECONNREFUSED;
  48. case NCI_STATUS_RF_TRANSMISSION_ERROR:
  49. case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
  50. return -ECOMM;
  51. case NCI_STATUS_RF_TIMEOUT_ERROR:
  52. case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
  53. return -ETIMEDOUT;
  54. case NCI_STATUS_FAILED:
  55. default:
  56. return -ENOSYS;
  57. }
  58. }
  59. EXPORT_SYMBOL(nci_to_errno);