]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | BlueZ - Bluetooth protocol stack for Linux | |
3 | Copyright (C) 2000-2001 Qualcomm Incorporated | |
4 | ||
5 | Written 2000,2001 by Maxim Krasnyansky <[email protected]> | |
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 | #include <linux/config.h> | |
28 | #include <linux/module.h> | |
29 | ||
30 | #include <linux/kernel.h> | |
31 | #include <linux/stddef.h> | |
32 | #include <linux/string.h> | |
33 | #include <asm/errno.h> | |
34 | ||
35 | #include <net/bluetooth/bluetooth.h> | |
36 | ||
37 | void bt_dump(char *pref, __u8 *buf, int count) | |
38 | { | |
39 | char *ptr; | |
40 | char line[100]; | |
41 | unsigned int i; | |
42 | ||
43 | printk(KERN_INFO "%s: dump, len %d\n", pref, count); | |
44 | ||
45 | ptr = line; | |
46 | *ptr = 0; | |
47 | for (i = 0; i < count; i++) { | |
48 | ptr += sprintf(ptr, " %2.2X", buf[i]); | |
49 | ||
50 | if (i && !((i + 1) % 20)) { | |
51 | printk(KERN_INFO "%s:%s\n", pref, line); | |
52 | ptr = line; | |
53 | *ptr = 0; | |
54 | } | |
55 | } | |
56 | ||
57 | if (line[0]) | |
58 | printk(KERN_INFO "%s:%s\n", pref, line); | |
59 | } | |
60 | EXPORT_SYMBOL(bt_dump); | |
61 | ||
62 | void baswap(bdaddr_t *dst, bdaddr_t *src) | |
63 | { | |
64 | unsigned char *d = (unsigned char *) dst; | |
65 | unsigned char *s = (unsigned char *) src; | |
66 | unsigned int i; | |
67 | ||
68 | for (i = 0; i < 6; i++) | |
69 | d[i] = s[5 - i]; | |
70 | } | |
71 | EXPORT_SYMBOL(baswap); | |
72 | ||
73 | char *batostr(bdaddr_t *ba) | |
74 | { | |
75 | static char str[2][18]; | |
76 | static int i = 1; | |
77 | ||
78 | i ^= 1; | |
79 | sprintf(str[i], "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", | |
80 | ba->b[0], ba->b[1], ba->b[2], | |
81 | ba->b[3], ba->b[4], ba->b[5]); | |
82 | ||
83 | return str[i]; | |
84 | } | |
85 | EXPORT_SYMBOL(batostr); | |
86 | ||
87 | /* Bluetooth error codes to Unix errno mapping */ | |
88 | int bt_err(__u16 code) | |
89 | { | |
90 | switch (code) { | |
91 | case 0: | |
92 | return 0; | |
93 | ||
94 | case 0x01: | |
95 | return EBADRQC; | |
96 | ||
97 | case 0x02: | |
98 | return ENOTCONN; | |
99 | ||
100 | case 0x03: | |
101 | return EIO; | |
102 | ||
103 | case 0x04: | |
104 | return EHOSTDOWN; | |
105 | ||
106 | case 0x05: | |
107 | return EACCES; | |
108 | ||
109 | case 0x06: | |
110 | return EBADE; | |
111 | ||
112 | case 0x07: | |
113 | return ENOMEM; | |
114 | ||
115 | case 0x08: | |
116 | return ETIMEDOUT; | |
117 | ||
118 | case 0x09: | |
119 | return EMLINK; | |
120 | ||
121 | case 0x0a: | |
122 | return EMLINK; | |
123 | ||
124 | case 0x0b: | |
125 | return EALREADY; | |
126 | ||
127 | case 0x0c: | |
128 | return EBUSY; | |
129 | ||
130 | case 0x0d: | |
131 | case 0x0e: | |
132 | case 0x0f: | |
133 | return ECONNREFUSED; | |
134 | ||
135 | case 0x10: | |
136 | return ETIMEDOUT; | |
137 | ||
138 | case 0x11: | |
139 | case 0x27: | |
140 | case 0x29: | |
141 | case 0x20: | |
142 | return EOPNOTSUPP; | |
143 | ||
144 | case 0x12: | |
145 | return EINVAL; | |
146 | ||
147 | case 0x13: | |
148 | case 0x14: | |
149 | case 0x15: | |
150 | return ECONNRESET; | |
151 | ||
152 | case 0x16: | |
153 | return ECONNABORTED; | |
154 | ||
155 | case 0x17: | |
156 | return ELOOP; | |
157 | ||
158 | case 0x18: | |
159 | return EACCES; | |
160 | ||
161 | case 0x1a: | |
162 | return EPROTONOSUPPORT; | |
163 | ||
164 | case 0x1b: | |
165 | return ECONNREFUSED; | |
166 | ||
167 | case 0x19: | |
168 | case 0x1e: | |
169 | case 0x23: | |
170 | case 0x24: | |
171 | case 0x25: | |
172 | return EPROTO; | |
173 | ||
174 | default: | |
175 | return ENOSYS; | |
176 | } | |
177 | } | |
178 | EXPORT_SYMBOL(bt_err); |