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 | |
| 44 | char *batostr(bdaddr_t *ba) |
| 45 | { |
| 46 | static char str[2][18]; |
| 47 | static int i = 1; |
| 48 | |
| 49 | i ^= 1; |
| 50 | sprintf(str[i], "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", |
Gustavo F. Padovan | d6b2eb2 | 2010-09-03 18:29:46 -0300 | [diff] [blame] | 51 | ba->b[5], ba->b[4], ba->b[3], |
| 52 | ba->b[2], ba->b[1], ba->b[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | return str[i]; |
| 55 | } |
| 56 | EXPORT_SYMBOL(batostr); |
| 57 | |
| 58 | /* Bluetooth error codes to Unix errno mapping */ |
Joe Perches | e175072 | 2011-06-29 18:18:29 -0700 | [diff] [blame] | 59 | int bt_to_errno(__u16 code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
| 61 | switch (code) { |
| 62 | case 0: |
| 63 | return 0; |
| 64 | |
| 65 | case 0x01: |
| 66 | return EBADRQC; |
| 67 | |
| 68 | case 0x02: |
| 69 | return ENOTCONN; |
| 70 | |
| 71 | case 0x03: |
| 72 | return EIO; |
| 73 | |
| 74 | case 0x04: |
| 75 | return EHOSTDOWN; |
| 76 | |
| 77 | case 0x05: |
| 78 | return EACCES; |
| 79 | |
| 80 | case 0x06: |
| 81 | return EBADE; |
| 82 | |
| 83 | case 0x07: |
| 84 | return ENOMEM; |
| 85 | |
| 86 | case 0x08: |
| 87 | return ETIMEDOUT; |
| 88 | |
| 89 | case 0x09: |
| 90 | return EMLINK; |
| 91 | |
| 92 | case 0x0a: |
| 93 | return EMLINK; |
| 94 | |
| 95 | case 0x0b: |
| 96 | return EALREADY; |
| 97 | |
| 98 | case 0x0c: |
| 99 | return EBUSY; |
| 100 | |
| 101 | case 0x0d: |
| 102 | case 0x0e: |
| 103 | case 0x0f: |
| 104 | return ECONNREFUSED; |
| 105 | |
| 106 | case 0x10: |
| 107 | return ETIMEDOUT; |
| 108 | |
| 109 | case 0x11: |
| 110 | case 0x27: |
| 111 | case 0x29: |
| 112 | case 0x20: |
| 113 | return EOPNOTSUPP; |
| 114 | |
| 115 | case 0x12: |
| 116 | return EINVAL; |
| 117 | |
| 118 | case 0x13: |
| 119 | case 0x14: |
| 120 | case 0x15: |
| 121 | return ECONNRESET; |
| 122 | |
| 123 | case 0x16: |
| 124 | return ECONNABORTED; |
| 125 | |
| 126 | case 0x17: |
| 127 | return ELOOP; |
| 128 | |
| 129 | case 0x18: |
| 130 | return EACCES; |
| 131 | |
| 132 | case 0x1a: |
| 133 | return EPROTONOSUPPORT; |
| 134 | |
| 135 | case 0x1b: |
| 136 | return ECONNREFUSED; |
| 137 | |
| 138 | case 0x19: |
| 139 | case 0x1e: |
| 140 | case 0x23: |
| 141 | case 0x24: |
| 142 | case 0x25: |
| 143 | return EPROTO; |
| 144 | |
| 145 | default: |
| 146 | return ENOSYS; |
| 147 | } |
| 148 | } |
Joe Perches | e175072 | 2011-06-29 18:18:29 -0700 | [diff] [blame] | 149 | EXPORT_SYMBOL(bt_to_errno); |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 150 | |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 151 | int bt_info(const char *format, ...) |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 152 | { |
| 153 | struct va_format vaf; |
| 154 | va_list args; |
| 155 | int r; |
| 156 | |
| 157 | va_start(args, format); |
| 158 | |
| 159 | vaf.fmt = format; |
| 160 | vaf.va = &args; |
| 161 | |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 162 | r = pr_info("%pV", &vaf); |
Joe Perches | e1447d8 | 2011-06-30 19:15:37 -0300 | [diff] [blame] | 163 | |
| 164 | va_end(args); |
| 165 | |
| 166 | return r; |
| 167 | } |
Joe Perches | 3ed7003 | 2012-02-16 23:32:42 -0800 | [diff] [blame] | 168 | EXPORT_SYMBOL(bt_info); |
| 169 | |
| 170 | int bt_err(const char *format, ...) |
| 171 | { |
| 172 | struct va_format vaf; |
| 173 | va_list args; |
| 174 | int r; |
| 175 | |
| 176 | va_start(args, format); |
| 177 | |
| 178 | vaf.fmt = format; |
| 179 | vaf.va = &args; |
| 180 | |
| 181 | r = pr_err("%pV", &vaf); |
| 182 | |
| 183 | va_end(args); |
| 184 | |
| 185 | return r; |
| 186 | } |
| 187 | EXPORT_SYMBOL(bt_err); |