1 /*
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
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
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23 */
24
25 /* Bluetooth kernel library. */
26
27 #define pr_fmt(fmt) "Bluetooth: " fmt
28
29 #include <linux/module.h>
30
31 #include <linux/kernel.h>
32 #include <linux/stddef.h>
33 #include <linux/string.h>
34 #include <asm/errno.h>
35
36 #include <net/bluetooth/bluetooth.h>
37
baswap(bdaddr_t * dst,bdaddr_t * src)38 void baswap(bdaddr_t *dst, bdaddr_t *src)
39 {
40 unsigned char *d = (unsigned char *) dst;
41 unsigned char *s = (unsigned char *) src;
42 unsigned int i;
43
44 for (i = 0; i < 6; i++)
45 d[i] = s[5 - i];
46 }
47 EXPORT_SYMBOL(baswap);
48
batostr(bdaddr_t * ba)49 char *batostr(bdaddr_t *ba)
50 {
51 static char str[2][18];
52 static int i = 1;
53
54 i ^= 1;
55 sprintf(str[i], "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
56 ba->b[5], ba->b[4], ba->b[3],
57 ba->b[2], ba->b[1], ba->b[0]);
58
59 return str[i];
60 }
61 EXPORT_SYMBOL(batostr);
62
63 /* Bluetooth error codes to Unix errno mapping */
bt_to_errno(__u16 code)64 int bt_to_errno(__u16 code)
65 {
66 switch (code) {
67 case 0:
68 return 0;
69
70 case 0x01:
71 return EBADRQC;
72
73 case 0x02:
74 return ENOTCONN;
75
76 case 0x03:
77 return EIO;
78
79 case 0x04:
80 return EHOSTDOWN;
81
82 case 0x05:
83 return EACCES;
84
85 case 0x06:
86 return EBADE;
87
88 case 0x07:
89 return ENOMEM;
90
91 case 0x08:
92 return ETIMEDOUT;
93
94 case 0x09:
95 return EMLINK;
96
97 case 0x0a:
98 return EMLINK;
99
100 case 0x0b:
101 return EALREADY;
102
103 case 0x0c:
104 return EBUSY;
105
106 case 0x0d:
107 case 0x0e:
108 case 0x0f:
109 return ECONNREFUSED;
110
111 case 0x10:
112 return ETIMEDOUT;
113
114 case 0x11:
115 case 0x27:
116 case 0x29:
117 case 0x20:
118 return EOPNOTSUPP;
119
120 case 0x12:
121 return EINVAL;
122
123 case 0x13:
124 case 0x14:
125 case 0x15:
126 return ECONNRESET;
127
128 case 0x16:
129 return ECONNABORTED;
130
131 case 0x17:
132 return ELOOP;
133
134 case 0x18:
135 return EACCES;
136
137 case 0x1a:
138 return EPROTONOSUPPORT;
139
140 case 0x1b:
141 return ECONNREFUSED;
142
143 case 0x19:
144 case 0x1e:
145 case 0x23:
146 case 0x24:
147 case 0x25:
148 return EPROTO;
149
150 default:
151 return ENOSYS;
152 }
153 }
154 EXPORT_SYMBOL(bt_to_errno);
155
bt_info(const char * format,...)156 int bt_info(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_info("%pV", &vaf);
168
169 va_end(args);
170
171 return r;
172 }
173 EXPORT_SYMBOL(bt_info);
174
bt_err(const char * format,...)175 int bt_err(const char *format, ...)
176 {
177 struct va_format vaf;
178 va_list args;
179 int r;
180
181 va_start(args, format);
182
183 vaf.fmt = format;
184 vaf.va = &args;
185
186 r = pr_err("%pV", &vaf);
187
188 va_end(args);
189
190 return r;
191 }
192 EXPORT_SYMBOL(bt_err);
193