bool CPacketConn::RcvPacket() { if (!m_Trusted) { // if not authenticated yet m_Trusted = Authenticate(); // if we're a client and connection was bogus, end receive loop // if we're a server, there could be new clients, so keep looping return(m_Trusted || m_Server); } PACKET_HDR hdr; if (!TcpRead(&hdr, sizeof(hdr))) // read header return(FALSE); UINT PackLen = sizeof(hdr) + hdr.DataLen; // allocate packet on heap; recipient is responsible for deleting packet GENERIC_PACKET *pp = (GENERIC_PACKET *)new BYTE[PackLen]; if (hdr.DataLen) { if (!TcpRead(pp->Data, hdr.DataLen)) // read data return(FALSE); } PACKET_HDR *pHdr = pp; // upcast to base class *pHdr = hdr; PostMessage(m_hWnd, UWM_RCVPACKET, (WPARAM)pp, m_Cookie); // post packet to window return(TRUE); }
bool CPacketConn::Authenticate() { PACKET_HDR hdr; if (TcpRead(&hdr, sizeof(hdr))) { if (m_Server || m_Passive) { if (hdr.Message == AUTH_QUERY && hdr.DataLen <= PROTO_VERSION) { if (!Write(m_AuthReply, sizeof(hdr))) // reply to client return(FALSE); if (m_Passive) SetEvent(m_Tcp->GetReadEvent()); // unblock Create return(TRUE); // client is trustworthy } } else { // we're a client; assume server has replied to our query if (hdr.Message == AUTH_REPLY && hdr.DataLen <= PROTO_VERSION) { SetEvent(m_Tcp->GetReadEvent()); // unblock Create return(TRUE); // server is trustworthy } } } m_Tcp->Disconnect(); return(FALSE); // authentication failed }
// // ////////////////////////////////////////////////////////// // // BC Udp Read Routine // EFI_STATUS EFIAPI BcTcpRead ( IN EFI_PXE_BASE_CODE_PROTOCOL *This, IN UINT16 OpFlags, IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL IN OUT EFI_PXE_BASE_CODE_TCP_PORT *DestPort, OPTIONAL IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL IN UINTN *HeaderSize, OPTIONAL IN VOID *HeaderPtr, OPTIONAL IN OUT UINTN *BufferSize, IN VOID *BufferPtr ) /*++ Routine description: TCP read API entry point. Parameters: This := Pointer to PxeBc interface OpFlags := DestIp := DestPort := SrcIp := SrcPort := HeaderSize := HeaderPtr := BufferSize := BufferPtr := Returns: EFI_SUCCESS := other := --*/ { EFI_STATUS StatCode; PXE_BASECODE_DEVICE *Private; // // Lock the instance data and make sure started // StatCode = EFI_SUCCESS; if (This == NULL) { DEBUG ((EFI_D_ERROR, "BC *This pointer == NULL")); return EFI_INVALID_PARAMETER; } Private = CR (This, PXE_BASECODE_DEVICE, EfiBc, PXE_BASECODE_DEVICE_SIGNATURE); if (Private == NULL) { DEBUG ((EFI_D_ERROR, "PXE_BASECODE_DEVICE poiner == NULL")); return EFI_INVALID_PARAMETER; } EfiAcquireLock (&Private->Lock); if (This->Mode == NULL || !This->Mode->Started) { DEBUG ((EFI_D_ERROR, "BC was not started.")); EfiReleaseLock (&Private->Lock); return EFI_NOT_STARTED; } Private->Function = EFI_PXE_BASE_CODE_FUNCTION_TCP_READ; // // Issue BC command // StatCode = TcpRead ( Private, OpFlags, DestIp, DestPort, SrcIp, SrcPort, HeaderSize, HeaderPtr, BufferSize, BufferPtr ); // // Unlock the instance data and return // EfiReleaseLock (&Private->Lock); return StatCode; }