adc8d6f3f19651ae7abe61e490a9ce0450629925
[platform/core/telephony/tel-plugin-vmodem.git] / src / vdpram_dump.c
1 /*
2  * tel-plugin-vmodem
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Junhwan An <jh48.an@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <string.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <log.h>
25
26 #include "vdpram_dump.h"
27
28 static void hex_dump(const char *pad, int size, const void *data)
29 {
30         char buf[255] = {0, };
31         char hex[4] = {0, };
32         int i;
33         unsigned const char *p;
34
35         if (size <= 0) {
36                 msg("%sno data", pad);
37                 return;
38         }
39
40         p = (unsigned const char *)data;
41
42         snprintf(buf, 255, "%s%04X: ", pad, 0);
43         for (i = 0; i<size; i++) {
44                 snprintf(hex, 4, "%02X ", p[i]);
45                 strcat(buf, hex);
46
47                 if ((i + 1) % 8 == 0) {
48                         if ((i + 1) % 16 == 0) {
49                                 msg("%s", buf);
50                                 memset(buf, 0, 255);
51                                 snprintf(buf, 255, "%s%04X: ", pad, i + 1);
52                         }
53                         else {
54                                 strcat(buf, "  ");
55                         }
56                 }
57         }
58
59         msg("%s", buf);
60 }
61
62 void vdpram_hex_dump(int dir, unsigned short data_len, void *data)
63 {
64         const char *d;
65
66         if(!data)
67                 return;
68
69         if (dir == IPC_RX)
70                 d = "[RX]";
71         else
72                 d = "[TX]";
73
74         msg("");
75         msg("  %s\tlen=%d\t%s", d, data_len, (char *)data);
76         hex_dump("        ", data_len, (const void*)data);
77
78         msg("");
79 }