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