sync hh.org
[hh.org.git] / drivers / net / wireless / zd1211rw / zd_util.c
blobd20036c15d11bdb1a0d5532fd46e7ff2d328515f
1 /* zd_util.c
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.
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.
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
17 * Utility program
20 #include "zd_def.h"
21 #include "zd_util.h"
23 #ifdef DEBUG
24 static char hex(u8 v)
26 v &= 0xf;
27 return (v < 10 ? '0' : 'a' - 10) + v;
30 static char hex_print(u8 c)
32 return (0x20 <= c && c < 0x7f) ? c : '.';
35 static void dump_line(const u8 *bytes, size_t size)
37 char c;
38 size_t i;
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 = ' ';
54 if (i < size) {
55 printk("%c%c%c", hex(bytes[i] >> 4), hex(bytes[i]), c);
56 } else {
57 printk(" %c", c);
61 for (i = 0; i < size; i++)
62 printk("%c", hex_print(bytes[i]));
63 printk("\n");
66 void zd_hexdump(const void *bytes, size_t size)
68 size_t i = 0;
70 do {
71 dump_line((u8 *)bytes + i, size-i);
72 i += 8;
73 } while (i < size);
75 #endif /* DEBUG */
77 void *zd_tail(const void *buffer, size_t buffer_size, size_t tail_size)
79 if (buffer_size < tail_size)
80 return NULL;
81 return (u8 *)buffer + (buffer_size - tail_size);