]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IpSecDxe/IpSecDebug.c
Add NetworkPkg (P.UDK2010.UP3.Network.P1)
[mirror_edk2.git] / NetworkPkg / IpSecDxe / IpSecDebug.c
1 /** @file
2 Interface of IPsec printing debug information.
3
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "IpSecImpl.h"
17 #include "IpSecDebug.h"
18
19 //
20 // The print title for IKEv1 variety phase.
21 //
22 CHAR8 *mStateStr[] = {
23 "IKEv1_MAIN_1",
24 "IKEv1_MAIN_2",
25 "IKEv1_MAIN_3",
26 "IKEv1_MAIN_ESTABLISHED",
27 "IKEv1_QUICK_1",
28 "IKEv1_QUICK_2",
29 "IKEv1_QUICK_ESTABLISHED"
30 };
31 //
32 // The print title for IKEv1 variety Exchagne.
33 //
34 CHAR8 *mExchangeStr[] = {
35 "IKEv1 Main Exchange",
36 "IKEv1 Info Exchange",
37 "IKEv1 Quick Exchange",
38 "IKEv1 Unknown Exchange"
39 };
40
41 //
42 // The print title for IKEv1 variety Payload.
43 //
44 CHAR8 *mPayloadStr[] = {
45 "IKEv1 None Payload",
46 "IKEv1 SA Payload",
47 "IKEv1 Proposal Payload",
48 "IKEv1 Transform Payload",
49 "IKEv1 KE Payload",
50 "IKEv1 ID Payload",
51 "IKEv1 Certificate Payload",
52 "IKEv1 Certificate Request Payload",
53 "IKEv1 Hash Payload",
54 "IKEv1 Signature Payload",
55 "IKEv1 Nonce Payload",
56 "IKEv1 Notify Payload",
57 "IKEv1 Delete Payload",
58 "IKEv1 Vendor Payload"
59 };
60
61 /**
62 Print the IP address.
63
64 @param[in] Level Debug print error level. Pass to DEBUG().
65 @param[in] Ip Point to a specified IP address.
66 @param[in] IpVersion The IP Version.
67
68 **/
69 VOID
70 IpSecDumpAddress (
71 IN UINTN Level,
72 IN EFI_IP_ADDRESS *Ip,
73 IN UINT8 IpVersion
74 )
75 {
76 if (IpVersion == IP_VERSION_6) {
77 DEBUG (
78 (Level,
79 "%x%x:%x%x:%x%x:%x%x",
80 Ip->v6.Addr[0],
81 Ip->v6.Addr[1],
82 Ip->v6.Addr[2],
83 Ip->v6.Addr[3],
84 Ip->v6.Addr[4],
85 Ip->v6.Addr[5],
86 Ip->v6.Addr[6],
87 Ip->v6.Addr[7])
88 );
89 DEBUG (
90 (Level,
91 ":%x%x:%x%x:%x%x:%x%x\n",
92 Ip->v6.Addr[8],
93 Ip->v6.Addr[9],
94 Ip->v6.Addr[10],
95 Ip->v6.Addr[11],
96 Ip->v6.Addr[12],
97 Ip->v6.Addr[13],
98 Ip->v6.Addr[14],
99 Ip->v6.Addr[15])
100 );
101 } else {
102 DEBUG (
103 (Level,
104 "%d.%d.%d.%d\n",
105 Ip->v4.Addr[0],
106 Ip->v4.Addr[1],
107 Ip->v4.Addr[2],
108 Ip->v4.Addr[3])
109 );
110 }
111
112 }
113
114 /**
115 Print IKEv1 Current states.
116
117 @param[in] Previous The Previous state of IKEv1.
118 @param[in] Current The current state of IKEv1.
119
120 **/
121 VOID
122 IpSecDumpState (
123 IN UINT32 Previous,
124 IN UINT32 Current
125 )
126 {
127 if (Previous == Current) {
128 DEBUG ((DEBUG_INFO, "\n****Current state is %a\n", mStateStr[Previous]));
129 } else {
130 DEBUG ((DEBUG_INFO, "\n****Change state from %a to %a\n", mStateStr[Previous], mStateStr[Current]));
131 }
132
133 }
134
135 /**
136 Print the buffer in form of Hex.
137
138 @param[in] Title The strings to be printed before the data of the buffer.
139 @param[in] Data Points to buffer to be printed.
140 @param[in] DataSize The size of the buffer to be printed.
141
142 **/
143 VOID
144 IpSecDumpBuf (
145 IN CHAR8 *Title,
146 IN UINT8 *Data,
147 IN UINTN DataSize
148 )
149 {
150 UINTN Index;
151 UINTN DataIndex;
152 UINTN BytesRemaining;
153 UINTN BytesToPrint;
154
155 DataIndex = 0;
156 BytesRemaining = DataSize;
157
158 DEBUG ((DEBUG_INFO, "==%a %d bytes==\n", Title, DataSize));
159
160 while (BytesRemaining > 0) {
161
162 BytesToPrint = (BytesRemaining > IPSEC_DEBUG_BYTE_PER_LINE) ? IPSEC_DEBUG_BYTE_PER_LINE : BytesRemaining;
163
164 for (Index = 0; Index < BytesToPrint; Index++) {
165 DEBUG ((DEBUG_INFO, " 0x%02x,", Data[DataIndex++]));
166 }
167
168 DEBUG ((DEBUG_INFO, "\n"));
169 BytesRemaining -= BytesToPrint;
170 }
171
172 }