blob: ee6a66979913c8fb4c0d4dca00335bcc3e89c235 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070037void baswap(bdaddr_t *dst, bdaddr_t *src)
38{
39 unsigned char *d = (unsigned char *) dst;
40 unsigned char *s = (unsigned char *) src;
41 unsigned int i;
42
43 for (i = 0; i < 6; i++)
44 d[i] = s[5 - i];
45}
46EXPORT_SYMBOL(baswap);
47
48char *batostr(bdaddr_t *ba)
49{
50 static char str[2][18];
51 static int i = 1;
52
53 i ^= 1;
54 sprintf(str[i], "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
55 ba->b[0], ba->b[1], ba->b[2],
56 ba->b[3], ba->b[4], ba->b[5]);
57
58 return str[i];
59}
60EXPORT_SYMBOL(batostr);
61
62/* Bluetooth error codes to Unix errno mapping */
63int bt_err(__u16 code)
64{
65 switch (code) {
66 case 0:
67 return 0;
68
69 case 0x01:
70 return EBADRQC;
71
72 case 0x02:
73 return ENOTCONN;
74
75 case 0x03:
76 return EIO;
77
78 case 0x04:
79 return EHOSTDOWN;
80
81 case 0x05:
82 return EACCES;
83
84 case 0x06:
85 return EBADE;
86
87 case 0x07:
88 return ENOMEM;
89
90 case 0x08:
91 return ETIMEDOUT;
92
93 case 0x09:
94 return EMLINK;
95
96 case 0x0a:
97 return EMLINK;
98
99 case 0x0b:
100 return EALREADY;
101
102 case 0x0c:
103 return EBUSY;
104
105 case 0x0d:
106 case 0x0e:
107 case 0x0f:
108 return ECONNREFUSED;
109
110 case 0x10:
111 return ETIMEDOUT;
112
113 case 0x11:
114 case 0x27:
115 case 0x29:
116 case 0x20:
117 return EOPNOTSUPP;
118
119 case 0x12:
120 return EINVAL;
121
122 case 0x13:
123 case 0x14:
124 case 0x15:
125 return ECONNRESET;
126
127 case 0x16:
128 return ECONNABORTED;
129
130 case 0x17:
131 return ELOOP;
132
133 case 0x18:
134 return EACCES;
135
136 case 0x1a:
137 return EPROTONOSUPPORT;
138
139 case 0x1b:
140 return ECONNREFUSED;
141
142 case 0x19:
143 case 0x1e:
144 case 0x23:
145 case 0x24:
146 case 0x25:
147 return EPROTO;
148
149 default:
150 return ENOSYS;
151 }
152}
153EXPORT_SYMBOL(bt_err);