lib.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. BlueZ - Bluetooth protocol stack for Linux
  3. Copyright (C) 2000-2001 Qualcomm Incorporated
  4. Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License version 2 as
  7. published by the Free Software Foundation;
  8. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  10. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  11. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  12. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  13. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  17. COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  18. SOFTWARE IS DISCLAIMED.
  19. */
  20. /* Bluetooth kernel library. */
  21. #define pr_fmt(fmt) "Bluetooth: " fmt
  22. #include <linux/export.h>
  23. #include <net/bluetooth/bluetooth.h>
  24. void baswap(bdaddr_t *dst, const bdaddr_t *src)
  25. {
  26. const unsigned char *s = (const unsigned char *)src;
  27. unsigned char *d = (unsigned char *)dst;
  28. unsigned int i;
  29. for (i = 0; i < 6; i++)
  30. d[i] = s[5 - i];
  31. }
  32. EXPORT_SYMBOL(baswap);
  33. /* Bluetooth error codes to Unix errno mapping */
  34. int bt_to_errno(__u16 code)
  35. {
  36. switch (code) {
  37. case 0:
  38. return 0;
  39. case 0x01:
  40. return EBADRQC;
  41. case 0x02:
  42. return ENOTCONN;
  43. case 0x03:
  44. return EIO;
  45. case 0x04:
  46. case 0x3c:
  47. return EHOSTDOWN;
  48. case 0x05:
  49. return EACCES;
  50. case 0x06:
  51. return EBADE;
  52. case 0x07:
  53. return ENOMEM;
  54. case 0x08:
  55. return ETIMEDOUT;
  56. case 0x09:
  57. return EMLINK;
  58. case 0x0a:
  59. return EMLINK;
  60. case 0x0b:
  61. return EALREADY;
  62. case 0x0c:
  63. return EBUSY;
  64. case 0x0d:
  65. case 0x0e:
  66. case 0x0f:
  67. return ECONNREFUSED;
  68. case 0x10:
  69. return ETIMEDOUT;
  70. case 0x11:
  71. case 0x27:
  72. case 0x29:
  73. case 0x20:
  74. return EOPNOTSUPP;
  75. case 0x12:
  76. return EINVAL;
  77. case 0x13:
  78. case 0x14:
  79. case 0x15:
  80. return ECONNRESET;
  81. case 0x16:
  82. return ECONNABORTED;
  83. case 0x17:
  84. return ELOOP;
  85. case 0x18:
  86. return EACCES;
  87. case 0x1a:
  88. return EPROTONOSUPPORT;
  89. case 0x1b:
  90. return ECONNREFUSED;
  91. case 0x19:
  92. case 0x1e:
  93. case 0x23:
  94. case 0x24:
  95. case 0x25:
  96. return EPROTO;
  97. default:
  98. return ENOSYS;
  99. }
  100. }
  101. EXPORT_SYMBOL(bt_to_errno);
  102. void bt_info(const char *format, ...)
  103. {
  104. struct va_format vaf;
  105. va_list args;
  106. va_start(args, format);
  107. vaf.fmt = format;
  108. vaf.va = &args;
  109. pr_info("%pV", &vaf);
  110. va_end(args);
  111. }
  112. EXPORT_SYMBOL(bt_info);
  113. void bt_warn(const char *format, ...)
  114. {
  115. struct va_format vaf;
  116. va_list args;
  117. va_start(args, format);
  118. vaf.fmt = format;
  119. vaf.va = &args;
  120. pr_warn("%pV", &vaf);
  121. va_end(args);
  122. }
  123. EXPORT_SYMBOL(bt_warn);
  124. void bt_err(const char *format, ...)
  125. {
  126. struct va_format vaf;
  127. va_list args;
  128. va_start(args, format);
  129. vaf.fmt = format;
  130. vaf.va = &args;
  131. pr_err("%pV", &vaf);
  132. va_end(args);
  133. }
  134. EXPORT_SYMBOL(bt_err);
  135. void bt_err_ratelimited(const char *format, ...)
  136. {
  137. struct va_format vaf;
  138. va_list args;
  139. va_start(args, format);
  140. vaf.fmt = format;
  141. vaf.va = &args;
  142. pr_err_ratelimited("%pV", &vaf);
  143. va_end(args);
  144. }
  145. EXPORT_SYMBOL(bt_err_ratelimited);