-//\r
-// Initial the SPI\r
-//\r
-UINT32 mNextSpi = IKE_SPI_BASE;\r
-EFI_GUID mZeroGuid = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\r
+/**\r
+ Check whether the new generated Spi has existed.\r
+\r
+ @param[in] IkeSaSession Pointer to the Child SA Session.\r
+ @param[in] SpiValue SPI Value.\r
+\r
+ @retval TRUE This SpiValue has existed in the Child SA Session\r
+ @retval FALSE This SpiValue doesn't exist in the Child SA Session.\r
+ \r
+**/\r
+BOOLEAN\r
+IkeSpiValueExisted (\r
+ IN IKEV2_SA_SESSION *IkeSaSession,\r
+ IN UINT32 SpiValue\r
+ )\r
+{\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Next;\r
+ IKEV2_CHILD_SA_SESSION *SaSession;\r
+\r
+ Entry = NULL;\r
+ Next = NULL;\r
+ SaSession = NULL; \r
+ \r
+ //\r
+ // Check whether the SPI value has existed in ChildSaEstablishSessionList.\r
+ //\r
+ NET_LIST_FOR_EACH_SAFE (Entry, Next, &IkeSaSession->ChildSaEstablishSessionList) {\r
+ SaSession= IKEV2_CHILD_SA_SESSION_BY_IKE_SA (Entry);\r
+ if (SaSession->LocalPeerSpi == SpiValue) {\r
+ return TRUE;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Check whether the SPI value has existed in ChildSaSessionList.\r
+ //\r
+ NET_LIST_FOR_EACH_SAFE (Entry, Next, &IkeSaSession->ChildSaSessionList) {\r
+ SaSession= IKEV2_CHILD_SA_SESSION_BY_IKE_SA (Entry);\r
+ if (SaSession->LocalPeerSpi == SpiValue) {\r
+ return TRUE;\r
+ }\r
+ }\r
+\r
+ return FALSE;\r
+}\r