lib.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/types.h>
  29. #include <linux/errno.h>
  30. #include <net/nfc/nci.h>
  31. #include <net/nfc/nci_core.h>
  32. /* NCI status codes to Unix errno mapping */
  33. int nci_to_errno(__u8 code)
  34. {
  35. switch (code) {
  36. case NCI_STATUS_OK:
  37. return 0;
  38. case NCI_STATUS_REJECTED:
  39. return -EBUSY;
  40. case NCI_STATUS_RF_FRAME_CORRUPTED:
  41. return -EBADMSG;
  42. case NCI_STATUS_NOT_INITIALIZED:
  43. return -EHOSTDOWN;
  44. case NCI_STATUS_SYNTAX_ERROR:
  45. case NCI_STATUS_SEMANTIC_ERROR:
  46. case NCI_STATUS_INVALID_PARAM:
  47. case NCI_STATUS_RF_PROTOCOL_ERROR:
  48. case NCI_STATUS_NFCEE_PROTOCOL_ERROR:
  49. return -EPROTO;
  50. case NCI_STATUS_UNKNOWN_GID:
  51. case NCI_STATUS_UNKNOWN_OID:
  52. return -EBADRQC;
  53. case NCI_STATUS_MESSAGE_SIZE_EXCEEDED:
  54. return -EMSGSIZE;
  55. case NCI_STATUS_DISCOVERY_ALREADY_STARTED:
  56. return -EALREADY;
  57. case NCI_STATUS_DISCOVERY_TARGET_ACTIVATION_FAILED:
  58. case NCI_STATUS_NFCEE_INTERFACE_ACTIVATION_FAILED:
  59. return -ECONNREFUSED;
  60. case NCI_STATUS_RF_TRANSMISSION_ERROR:
  61. case NCI_STATUS_NFCEE_TRANSMISSION_ERROR:
  62. return -ECOMM;
  63. case NCI_STATUS_RF_TIMEOUT_ERROR:
  64. case NCI_STATUS_NFCEE_TIMEOUT_ERROR:
  65. return -ETIMEDOUT;
  66. case NCI_STATUS_FAILED:
  67. default:
  68. return -ENOSYS;
  69. }
  70. }
  71. EXPORT_SYMBOL(nci_to_errno);