Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / lib / firmware / carl9170fw / tools / carlu / src / | server ip : 104.21.89.46 your ip : 172.71.254.110 H O M E |
Filename | /lib/firmware/carl9170fw/tools/carlu/src/debug.c |
Size | 2.27 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:50 |
Last modified | 05-Mar-2014 23:45 |
Last accessed | 07-Jul-2025 12:58 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
/*
* carlu - userspace testing utility for ar9170 devices
*
* Random assortment of debug stuff
*
* Copyright 2009-2011 Christian Lamparter <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "debug.h"
bool print_message_debug_level;
enum debug_level_t debug_level;
FILE *_stdout;
FILE *_stddbg;
FILE *_stderr;
void init_debug()
{
debug_level = VERBOSE;
debug_level = INFO;
print_message_debug_level = false;
_stdout = stdout;
_stddbg = stdout;
_stderr = stderr;
}
FILE *dbg_lvl_to_fh(const enum debug_level_t lvl)
{
switch (lvl) {
case ERROR:
case WARNING:
return _stderr;
case INFO:
return _stdout;
case VERBOSE:
return _stddbg;
default:
BUG_ON(1);
}
}
void print_hex_dump_bytes(const enum debug_level_t lvl, const char *pre,
const void *buf, size_t len)
{
char line[58];
char str[17] = { 0 };
const unsigned char *tmp = (void *) buf;
char *pbuf = line;
size_t i, j;
for (i = 0; i < len; i++) {
if (i % 16 == 0) {
if (pbuf != line) {
__fprintf(lvl, "%s%s: %s\n", pre, line, str);
pbuf = line;
}
pbuf += sprintf(pbuf, "0x%04lx: ", (unsigned long)i);
}
pbuf += sprintf(pbuf, "%.2x ", tmp[i]);
str[i % 16] = (isprint(tmp[i]) && isascii(tmp[i])) ? tmp[i] : '.';
}
if (pbuf != line) {
if ((i % 16)) {
str[i % 16] = '\0';
for (j = 0; j < (16 - (i % 16)); j++)
pbuf += sprintf(pbuf, " ");
}
__fprintf(lvl, "%s%s: %s\n", pre, line, str);
}
}
* carlu - userspace testing utility for ar9170 devices
*
* Random assortment of debug stuff
*
* Copyright 2009-2011 Christian Lamparter <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "debug.h"
bool print_message_debug_level;
enum debug_level_t debug_level;
FILE *_stdout;
FILE *_stddbg;
FILE *_stderr;
void init_debug()
{
debug_level = VERBOSE;
debug_level = INFO;
print_message_debug_level = false;
_stdout = stdout;
_stddbg = stdout;
_stderr = stderr;
}
FILE *dbg_lvl_to_fh(const enum debug_level_t lvl)
{
switch (lvl) {
case ERROR:
case WARNING:
return _stderr;
case INFO:
return _stdout;
case VERBOSE:
return _stddbg;
default:
BUG_ON(1);
}
}
void print_hex_dump_bytes(const enum debug_level_t lvl, const char *pre,
const void *buf, size_t len)
{
char line[58];
char str[17] = { 0 };
const unsigned char *tmp = (void *) buf;
char *pbuf = line;
size_t i, j;
for (i = 0; i < len; i++) {
if (i % 16 == 0) {
if (pbuf != line) {
__fprintf(lvl, "%s%s: %s\n", pre, line, str);
pbuf = line;
}
pbuf += sprintf(pbuf, "0x%04lx: ", (unsigned long)i);
}
pbuf += sprintf(pbuf, "%.2x ", tmp[i]);
str[i % 16] = (isprint(tmp[i]) && isascii(tmp[i])) ? tmp[i] : '.';
}
if (pbuf != line) {
if ((i % 16)) {
str[i % 16] = '\0';
for (j = 0; j < (16 - (i % 16)); j++)
pbuf += sprintf(pbuf, " ");
}
__fprintf(lvl, "%s%s: %s\n", pre, line, str);
}
}