hc
2023-03-13 2ec15ae1cb4be1b4fcb56c6d621123d7ebdaad6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2015 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */
 
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/kdev_t.h>
#include <linux/tty.h>
#include <linux/vt_kern.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/semaphore.h>
#include <linux/vmalloc.h>
#include <linux/atomic.h>
#include <linux/of_device.h>
#include <linux/compat.h>
#include <linux/tty_flip.h>
#include <linux/kthread.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
 
#include "include/debug.h"
 
static unsigned int log_level = LOG_LEVEL_NONE;
 
unsigned int check_log_level(void)
{
    return log_level;
}
 
unsigned int set_log_level(int level)
{
    log_level = level;
    return 0;
}
 
void hex_dump(unsigned char *bin, size_t binsz)
{
    char *str, hex_str[] = "0123456789ABCDEF";
    size_t i;
 
    str = (char *)vmalloc(binsz * 3);
 
    if (!str)
    {
        return;
    }
 
    for (i = 0; i < binsz; i++)
    {
        str[(i * 3) + 0] = hex_str[(bin[i] >> 4) & 0x0F];
        str[(i * 3) + 1] = hex_str[(bin[i]     ) & 0x0F];
        str[(i * 3) + 2] = ' ';
    }
 
    str[(binsz * 3) - 1] = 0x00;
    pr_info("%s\n", str);
    vfree(str);
}
 
void hex_dump_block(unsigned char *bin, size_t binsz)
{
#define HEX_DUMP_BLOCK_SIZE 20
    int loop = binsz / HEX_DUMP_BLOCK_SIZE;
    int tail = binsz % HEX_DUMP_BLOCK_SIZE;
    int i;
 
    if (!loop)
    {
        hex_dump(bin, binsz);
        return;
    }
 
    for (i = 0; i < loop; i++)
    {
        hex_dump(bin + i * HEX_DUMP_BLOCK_SIZE, HEX_DUMP_BLOCK_SIZE);
    }
 
    if (tail)
    {
        hex_dump(bin + i * HEX_DUMP_BLOCK_SIZE, tail);
    }
}