This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / net / wireless / zd1211rw / zd_util.c
1 /* zd_util.c
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Utility program
18  */
19
20 #include "zd_def.h"
21 #include "zd_util.h"
22
23 #ifdef DEBUG
24 static char hex(u8 v)
25 {
26         v &= 0xf;
27         return (v < 10 ? '0' : 'a' - 10) + v;
28 }
29
30 static char hex_print(u8 c)
31 {
32         return (0x20 <= c && c < 0x7f) ? c : '.';
33 }
34
35 static void dump_line(const u8 *bytes, size_t size)
36 {
37         char c;
38         size_t i;
39
40         size = size <= 8 ? size : 8;
41         printk(KERN_DEBUG "zd1211 %p ", bytes);
42         for (i = 0; i < 8; i++) {
43                 switch (i) {
44                 case 1:
45                 case 5:
46                         c = '.';
47                         break;
48                 case 3:
49                         c = ':';
50                         break;
51                 default:
52                         c = ' ';
53                 }
54                 if (i < size) {
55                         printk("%c%c%c", hex(bytes[i] >> 4), hex(bytes[i]), c);
56                 } else {
57                         printk("  %c", c);
58                 }
59         }
60
61         for (i = 0; i < size; i++)
62                 printk("%c", hex_print(bytes[i]));
63         printk("\n");
64 }
65
66 void zd_hexdump(const void *bytes, size_t size)
67 {
68         size_t i = 0;
69
70         do {
71                 dump_line((u8 *)bytes + i, size-i);
72                 i += 8;
73         } while (i < size);
74 }
75 #endif /* DEBUG */
76
77 void *zd_tail(const void *buffer, size_t buffer_size, size_t tail_size)
78 {
79         if (buffer_size < tail_size)
80                 return NULL;
81         return (u8 *)buffer + (buffer_size - tail_size);
82 }