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 | |
Loic Poulain | 65bce46 | 2017-09-01 13:41:17 -0700 | [diff] [blame] | 33 | void baswap(bdaddr_t *dst, const bdaddr_t *src) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
Loic Poulain | 65bce46 | 2017-09-01 13:41:17 -0700 | [diff] [blame] | 35 | const unsigned char *s = (const unsigned char *)src; |
| 36 | unsigned char *d = (unsigned char *)dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Johan Hedberg | 43bb560 | 2014-03-24 20:21:52 +0200 | [diff] [blame] | 61 | case 0x3c: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return EHOSTDOWN; |
| 63 | |
| 64 | case 0x05: |
| 65 | return EACCES; |
| 66 | |
| 67 | case 0x06: |
| 68 | return EBADE; |
| 69 | |
| 70 | case 0x07: |
| 71 | return ENOMEM; |
| 72 | |
| 73 | case 0x08: |
| 74 | return ETIMEDOUT; |
| 75 | |
| 76 | case 0x09: |
| 77 | return EMLINK; |
| 78 | |
| 79 | case 0x0a: |
| 80 | return EMLINK; |
| 81 | |
| 82 | case 0x0b: |
| 83 | return EALREADY; |
| 84 | |
| 85 | case 0x0c: |
| 86 | return EBUSY; |
| 87 | |
| 88 | case 0x0d: |
| 89 | case 0x0e: |
| 90 | case 0x0f: |
| 91 | return ECONNREFUSED; |
| 92 | |
| 93 | case 0x10: |
| 94 | return ETIMEDOUT; |
| 95 | |
| 96 | case 0x11: |
| 97 | case 0x27: |
| 98 | case 0x29: |
| 99 | case 0x20: |
| 100 | return EOPNOTSUPP; |
| 101 | |
| 102 | case 0x12: |
| 103 | return EINVAL; |
| 104 | |
| 105 | case 0x13: |
| 106 | case 0x14: |
| 107 | case 0x15: |
| 108 | return ECONNRESET; |
| 109 | |
| 110 | case 0x16: |
| 111 | return ECONNABORTED; |
| 112 | |
| 113 | case 0x17: |
| 114 | return ELOOP; |
| 115 | |
| 116 | case 0x18: |
| 117 | return EACCES; |
| 118 | |
| 119 | case 0x1a: |
| 120 | return EPROTONOSUPPORT; |
| 121 | |
| 122 | case 0x1b: |
| 123 | return ECONNREFUSED; |
| 124 | |
| 125 | case 0x19: |
| 126 | case 0x1e: |
| 127 | case 0x23: |
| 128 | case 0x24: |
| 129 | case 0x25: |
| 130 | return EPROTO; |
| 131 | |
| 132 | default: |
| 133 | return ENOSYS; |
| 134 | } |
| 135 | } |
Joe Perches | e175072 | 2011-06-29 18:18:29 -0700 | [diff] [blame] | 136 | EXPORT_SYMBOL(bt_to_errno); |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 137 | |
Joe Perches | 2b0bf6c | 2014-09-22 11:17:41 -0700 | [diff] [blame] | 138 | void bt_info(const char *format, ...) |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 139 | { |
| 140 | struct va_format vaf; |
| 141 | va_list args; |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 142 | |
| 143 | va_start(args, format); |
| 144 | |
| 145 | vaf.fmt = format; |
| 146 | vaf.va = &args; |
| 147 | |
Joe Perches | 2b0bf6c | 2014-09-22 11:17:41 -0700 | [diff] [blame] | 148 | pr_info("%pV", &vaf); |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 149 | |
| 150 | va_end(args); |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 151 | } |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 152 | EXPORT_SYMBOL(bt_info); |
| 153 | |
Frederic Danis | 594b31e | 2015-09-23 18:18:07 +0200 | [diff] [blame] | 154 | void bt_warn(const char *format, ...) |
| 155 | { |
| 156 | struct va_format vaf; |
| 157 | va_list args; |
| 158 | |
| 159 | va_start(args, format); |
| 160 | |
| 161 | vaf.fmt = format; |
| 162 | vaf.va = &args; |
| 163 | |
| 164 | pr_warn("%pV", &vaf); |
| 165 | |
| 166 | va_end(args); |
| 167 | } |
| 168 | EXPORT_SYMBOL(bt_warn); |
| 169 | |
Joe Perches | 2b0bf6c | 2014-09-22 11:17:41 -0700 | [diff] [blame] | 170 | void bt_err(const char *format, ...) |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 171 | { |
| 172 | struct va_format vaf; |
| 173 | va_list args; |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 174 | |
| 175 | va_start(args, format); |
| 176 | |
| 177 | vaf.fmt = format; |
| 178 | vaf.va = &args; |
| 179 | |
Joe Perches | 2b0bf6c | 2014-09-22 11:17:41 -0700 | [diff] [blame] | 180 | pr_err("%pV", &vaf); |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 181 | |
| 182 | va_end(args); |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 183 | } |
| 184 | EXPORT_SYMBOL(bt_err); |
Szymon Janc | e781b7f | 2015-09-16 20:21:53 +0200 | [diff] [blame] | 185 | |
Marcel Holtmann | e625e50 | 2020-05-06 09:57:52 +0200 | [diff] [blame] | 186 | #ifdef CONFIG_BT_FEATURE_DEBUG |
| 187 | static bool debug_enable; |
| 188 | |
| 189 | void bt_dbg_set(bool enable) |
| 190 | { |
| 191 | debug_enable = enable; |
| 192 | } |
| 193 | |
| 194 | bool bt_dbg_get(void) |
| 195 | { |
| 196 | return debug_enable; |
| 197 | } |
| 198 | |
| 199 | void bt_dbg(const char *format, ...) |
| 200 | { |
| 201 | struct va_format vaf; |
| 202 | va_list args; |
| 203 | |
| 204 | if (likely(!debug_enable)) |
| 205 | return; |
| 206 | |
| 207 | va_start(args, format); |
| 208 | |
| 209 | vaf.fmt = format; |
| 210 | vaf.va = &args; |
| 211 | |
| 212 | printk(KERN_DEBUG pr_fmt("%pV"), &vaf); |
| 213 | |
| 214 | va_end(args); |
| 215 | } |
| 216 | EXPORT_SYMBOL(bt_dbg); |
| 217 | #endif |
| 218 | |
Alain Michaud | 36278a5 | 2019-12-11 01:54:43 +0000 | [diff] [blame] | 219 | void bt_warn_ratelimited(const char *format, ...) |
| 220 | { |
| 221 | struct va_format vaf; |
| 222 | va_list args; |
| 223 | |
| 224 | va_start(args, format); |
| 225 | |
| 226 | vaf.fmt = format; |
| 227 | vaf.va = &args; |
| 228 | |
| 229 | pr_warn_ratelimited("%pV", &vaf); |
| 230 | |
| 231 | va_end(args); |
| 232 | } |
| 233 | EXPORT_SYMBOL(bt_warn_ratelimited); |
| 234 | |
Szymon Janc | e781b7f | 2015-09-16 20:21:53 +0200 | [diff] [blame] | 235 | void bt_err_ratelimited(const char *format, ...) |
| 236 | { |
| 237 | struct va_format vaf; |
| 238 | va_list args; |
| 239 | |
| 240 | va_start(args, format); |
| 241 | |
| 242 | vaf.fmt = format; |
| 243 | vaf.va = &args; |
| 244 | |
| 245 | pr_err_ratelimited("%pV", &vaf); |
| 246 | |
| 247 | va_end(args); |
| 248 | } |
| 249 | EXPORT_SYMBOL(bt_err_ratelimited); |