Bluetooth: Fix coding style in the subsystem
[deliverable/linux.git] / net / bluetooth / lib.c
CommitLineData
8e87d142 1/*
1da177e4
LT
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
8e87d142
YH
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
1da177e4
LT
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
8e87d142
YH
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
1da177e4
LT
22 SOFTWARE IS DISCLAIMED.
23*/
24
25/* Bluetooth kernel library. */
26
3ed7003e
JP
27#define pr_fmt(fmt) "Bluetooth: " fmt
28
1da177e4
LT
29#include <linux/module.h>
30
31#include <linux/kernel.h>
32#include <linux/stddef.h>
33#include <linux/string.h>
8fc9ced3 34#include <linux/errno.h>
1da177e4
LT
35
36#include <net/bluetooth/bluetooth.h>
37
1da177e4
LT
38void 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}
47EXPORT_SYMBOL(baswap);
48
49char *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",
d6b2eb2f
GP
56 ba->b[5], ba->b[4], ba->b[3],
57 ba->b[2], ba->b[1], ba->b[0]);
1da177e4
LT
58
59 return str[i];
60}
61EXPORT_SYMBOL(batostr);
62
63/* Bluetooth error codes to Unix errno mapping */
e175072f 64int bt_to_errno(__u16 code)
1da177e4
LT
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}
e175072f 154EXPORT_SYMBOL(bt_to_errno);
e1447d8d 155
3ed7003e
JP
156int 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}
173EXPORT_SYMBOL(bt_info);
174
175int bt_err(const char *format, ...)
e1447d8d
JP
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
3ed7003e 186 r = pr_err("%pV", &vaf);
e1447d8d
JP
187
188 va_end(args);
189
190 return r;
191}
3ed7003e 192EXPORT_SYMBOL(bt_err);
This page took 1.042459 seconds and 5 git commands to generate.