lib.c 2.2 KB

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