a11a915f586338575b903a3a7248646977e29fda
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Igmp.h
1 /** @file
2
3 Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 #ifndef __EFI_IP4_IGMP_H__
15 #define __EFI_IP4_IGMP_H__
16
17 //
18 // IGMP message type
19 //
20 #define IGMP_MEMBERSHIP_QUERY 0x11
21 #define IGMP_V1_MEMBERSHIP_REPORT 0x12
22 #define IGMP_V2_MEMBERSHIP_REPORT 0x16
23 #define IGMP_LEAVE_GROUP 0x17
24
25 #define IGMP_V1ROUTER_PRESENT 400
26 #define IGMP_UNSOLICIATED_REPORT 10
27
28 #pragma pack(1)
29 typedef struct {
30 UINT8 Type;
31 UINT8 MaxRespTime;
32 UINT16 Checksum;
33 IP4_ADDR Group;
34 } IGMP_HEAD;
35 #pragma pack()
36
37 ///
38 /// The status of multicast group. It isn't necessary to maintain
39 /// explicit state of host state diagram. A group with non-zero
40 /// DelayTime is in "delaying member" state. otherwise, it is in
41 /// "idle member" state.
42 ///
43 typedef struct {
44 LIST_ENTRY Link;
45 INTN RefCnt;
46 IP4_ADDR Address;
47 INTN DelayTime;
48 BOOLEAN ReportByUs;
49 EFI_MAC_ADDRESS Mac;
50 } IGMP_GROUP;
51
52 ///
53 /// The IGMP status. Each IP4 service instance has a IGMP_SERVICE_DATA
54 /// attached. The Igmpv1QuerySeen remember whether the server on this
55 /// connected network is v1 or v2.
56 ///
57 typedef struct {
58 INTN Igmpv1QuerySeen;
59 LIST_ENTRY Groups;
60 } IGMP_SERVICE_DATA;
61
62 /**
63 Init the IGMP control data of the IP4 service instance, configure
64 MNP to receive ALL SYSTEM multicast.
65
66 @param[in, out] IpSb The IP4 service whose IGMP is to be initialized.
67
68 @retval EFI_SUCCESS IGMP of the IpSb is successfully initialized.
69 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to initialize IGMP.
70 @retval Others Failed to initialize the IGMP of IpSb.
71
72 **/
73 EFI_STATUS
74 Ip4InitIgmp (
75 IN OUT IP4_SERVICE *IpSb
76 );
77
78 /**
79 Join the multicast group on behalf of this IP4 child
80
81 @param[in] IpInstance The IP4 child that wants to join the group
82 @param[in] Address The group to join
83
84 @retval EFI_SUCCESS Successfully join the multicast group
85 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources
86 @retval Others Failed to join the multicast group.
87
88 **/
89 EFI_STATUS
90 Ip4JoinGroup (
91 IN IP4_PROTOCOL *IpInstance,
92 IN IP4_ADDR Address
93 );
94
95 /**
96 Leave the IP4 multicast group on behalf of IpInstance.
97
98 @param[in] IpInstance The IP4 child that wants to leave the group
99 address
100 @param[in] Address The group address to leave
101
102 @retval EFI_NOT_FOUND The IP4 service instance isn't in the group
103 @retval EFI_SUCCESS Successfully leave the multicast group.
104 @retval Others Failed to leave the multicast group.
105
106 **/
107 EFI_STATUS
108 Ip4LeaveGroup (
109 IN IP4_PROTOCOL *IpInstance,
110 IN IP4_ADDR Address
111 );
112
113 /**
114 Handle the received IGMP message for the IP4 service instance.
115
116 @param[in] IpSb The IP4 service instance that received the message
117 @param[in] Head The IP4 header of the received message
118 @param[in] Packet The IGMP message, without IP4 header
119
120 @retval EFI_INVALID_PARAMETER The IGMP message is malformated.
121 @retval EFI_SUCCESS The IGMP message is successfully processed.
122
123 **/
124 EFI_STATUS
125 Ip4IgmpHandle (
126 IN IP4_SERVICE *IpSb,
127 IN IP4_HEAD *Head,
128 IN NET_BUF *Packet
129 );
130
131 /**
132 The periodical timer function for IGMP. It does the following
133 things:
134 1. Decrease the Igmpv1QuerySeen to make it possible to refresh
135 the IGMP server type.
136 2. Decrease the report timer for each IGMP group in "delaying
137 member" state.
138
139 @param[in] IpSb The IP4 service instance that is ticking
140
141 **/
142 VOID
143 Ip4IgmpTicking (
144 IN IP4_SERVICE *IpSb
145 );
146
147 /**
148 Add a group address to the array of group addresses.
149 The caller should make sure that no duplicated address
150 existed in the array. Although the function doesn't
151 assume the byte order of the both Source and Addr, the
152 network byte order is used by the caller.
153
154 @param[in] Source The array of group addresses to add to
155 @param[in] Count The number of group addresses in the Source
156 @param[in] Addr The IP4 multicast address to add
157
158 @return NULL if failed to allocate memory for the new groups,
159 otherwise the new combined group addresses.
160
161 **/
162 IP4_ADDR *
163 Ip4CombineGroups (
164 IN IP4_ADDR *Source,
165 IN UINT32 Count,
166 IN IP4_ADDR Addr
167 );
168
169 /**
170 Remove a group address from the array of group addresses.
171 Although the function doesn't assume the byte order of the
172 both Groups and Addr, the network byte order is used by
173 the caller.
174
175 @param Groups The array of group addresses to remove from
176 @param Count The number of group addresses in the Groups
177 @param Addr The IP4 multicast address to remove
178
179 @return The nubmer of group addresses in the Groups after remove.
180 It is Count if the Addr isn't in the Groups.
181
182 **/
183 INTN
184 Ip4RemoveGroupAddr (
185 IN OUT IP4_ADDR *Groups,
186 IN UINT32 Count,
187 IN IP4_ADDR Addr
188 );
189
190 /**
191 Find the IGMP_GROUP structure which contains the status of multicast
192 group Address in this IGMP control block
193
194 @param[in] IgmpCtrl The IGMP control block to search from
195 @param[in] Address The multicast address to search
196
197 @return NULL if the multicast address isn't in the IGMP control block. Otherwise
198 the point to the IGMP_GROUP which contains the status of multicast group
199 for Address.
200
201 **/
202 IGMP_GROUP *
203 Ip4FindGroup (
204 IN IGMP_SERVICE_DATA *IgmpCtrl,
205 IN IP4_ADDR Address
206 );
207 #endif