Code sync from tizen_2.4
[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 #define TAB_SPACE       "  "
29
30 static void hex_dump(const char *pad, int size, const void *data)
31 {
32         char buf[255] = {0, };
33         char hex[4] = {0, };
34         int i;
35         unsigned const char *p;
36
37         if (size <= 0) {
38                 msg("%sno data", pad);
39                 return;
40         }
41
42         p = (unsigned const char *)data;
43
44         snprintf(buf, 255, "%s%04X: ", pad, 0);
45         for (i = 0; i < size; i++) {
46                 snprintf(hex, 4, "%02X ", p[i]);
47                 strncat(buf, hex, strlen(hex));
48
49                 if ((i + 1) % 8 == 0) {
50                         if ((i + 1) % 16 == 0) {
51                                 msg("%s", buf);
52                                 memset(buf, 0, 255);
53                                 snprintf(buf, 255, "%s%04X: ", pad, i + 1);
54                         } else {
55                                 strncat(buf, TAB_SPACE, strlen(TAB_SPACE));
56                         }
57                 }
58         }
59
60         msg("%s", buf);
61 }
62
63 void vdpram_hex_dump(int dir, unsigned short data_len, void *data)
64 {
65         const char *d;
66
67         if (!data)
68                 return;
69
70         if (dir == IPC_RX)
71                 d = "[RX]";
72         else
73                 d = "[TX]";
74
75         msg("");
76         msg("  %s\tlen=%d\t%s", d, data_len, (char *)data);
77         hex_dump("        ", data_len, (const void *)data);
78
79         msg("");
80 }