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