Esempio n. 1
0
static bool Send(IPSTACK * pIpStack, IPSTATUS * pStatus)
{
    AssignStatusSafely(pStatus, ipsSuccess);
    pIpStack->fOwnedByAdp = true;
    FFInPacket(&wfmrf24.priv.ffptWrite, pIpStack);
    return(true);
}
bool TCPServer::addSocket(TCPSocket& tcpSocket, IPSTATUS * pStatus)
{
    // if we don't have a page manager, assign the default one
    if(tcpSocket._hPMGR == NULL)
    {
        tcpSocket._hPMGR = hNetworkPMGR;
    }

    if(tcpSocket._hPMGR == NULL)
    {
        AssignStatusSafely(pStatus, ipsNoPMGRGiven);
        return(false);
    }
    else if(_pDEIPcK == NULL)
    {
        AssignStatusSafely(pStatus, ipsNotInitialized);
        return(false);
    }
    else if(tcpSocket._pDEIPcK != NULL)
    {
        AssignStatusSafely(pStatus, ipsInUse);
        return(false);
    }

    // add it to the list of sockets to listen on
    FFInPacket(&_ffptSockets, &tcpSocket._ffptInfo);
    tcpSocket._pDEIPcK = _pDEIPcK;
    return(true);
}
Esempio n. 3
0
/*****************************************************************************
  Function:
	SOCKET * TCPOpen(const LLADP * pLLAdp, const SOCKETPOOL * pSocketPool, void * pIPvXDest, uint16_t portRemote, uint16_t portLocal, IPSTATUS * pStatus)

  Summary:
        Opens a Socket for both Client and Server. If portRemote == 0
        The socket is opened for listening.

  Description:

  Precondition:

  Parameters:
	pLLAdp -        The adaptor to use
        pSocket -       A pointer to the socket to use
        hPMGR -         A handle to the page manager to create the socket stream.
        pIPvXDest -     The Dest IP to connect to if a client, ignored for a server open and may be NULL
        portRemote -    The remote port to connect to if Client, MUST be 0 if this is a server open for listen
        portLocal -     Local port to use, one will be assigned if zero
        pStatus -       A pointer to a status variable to recieve the status of the open, This may be NULL

  Returns:
        The Socket if opened, NULL on failure
  ***************************************************************************/
HSOCKET TCPOpenWithSocket(const LLADP * pLLAdp, TCPSOCKET * pSocket, HPMGR hPMGR, const void * pIPvXDest, uint16_t portRemote, uint16_t portLocal, IPSTATUS * pStatus)
{
    IPSTATUS    status      = ipsSuccess;
    IPSTACK *   pIpStack    = NULL;
    uint32_t    cbOptions   = 0;

    // make sure pIPvXDest points to something
    if(portRemote == 0 || pIPvXDest == NULL)
    {
        pIPvXDest = &IPv6NONE;
    }

    if(pSocket == NULL)
    {
        AssignStatusSafely(pStatus, ipsNoSocketsAvailable);
        return(NULL);
    }

    else if(pLLAdp == NULL)
    {
        status = ipsAdaptorMustBeSpecified;
    }

    // if this is a client open
    else if(    (pSocket = TCPInitSocket(pLLAdp, pSocket, hPMGR, pIPvXDest, portRemote, portLocal, &status)) != NULL  &&
                portRemote != portListen  &&
                (pIpStack = TCPCreateSyn(pSocket, &cbOptions, &status)) != NULL)
    {
        pSocket->tcpState               = tcpSynSent;
        pSocket->tLastAck               = SYSGetMilliSecond();

        // start the connection process
        TCPTransmit(pIpStack, pSocket, 1, cbOptions, false, SYSGetMilliSecond(), &status);
    }
    
    // else this is a server open / or an error getting the socket which we will abort below in the error check
    else if(pSocket != NULL)
    {
        pSocket->tcpState               = tcpListen;
    }

    // we got an error somewhere; clean up
    if(IsIPStatusAnError(status))
    {
        if(pSocket != NULL)
        {
            pSocket->tcpState = tcpUnassigned;
            TCPResetSocket(pSocket);
        }
        IPSRelease(pIpStack);
        pSocket = NULL;
        AssignStatusSafely(pStatus, status);
        return(NULL);
    }

    // put on the listening list.
    FFInPacket(&g_ffptActiveTCPSockets, pSocket);

    pSocket->fSocketOpen = true;
    AssignStatusSafely(pStatus, status);
    return((HSOCKET) pSocket);
 }
Esempio n. 4
0
HSOCKET UDPOpenWithSocket(const LLADP * pLLAdp, UDPSOCKET * pSocket, HPMGR hPMGR, const void * pIPvXDest, uint16_t portRemote, uint16_t portLocal, IPSTATUS * pStatus)
{
//    uint32_t    portPair    = 0;
    IPSTATUS    status      = ipsSuccess;
    SMGR *      pSMGR       = NULL;
    uint32_t    cb          = 0;

    if(pLLAdp == NULL)
    {
        status = ipsAdaptorMustBeSpecified;
    }
    else if(pSocket == NULL)
    {
        status = ipsSocketNULL;
    }
    else if(hPMGR == NULL)
    {
        status = ipsNoPMGRGiven;
    }
    else if(pIPvXDest == NULL)
    {
        status = ipsIPAddressIsNull;
    }
    // get the local port
    else if(portLocal == portDynamicallyAssign)
    {
        portLocal = GetEphemeralPort(&g_ffptListeningUDPSockets, &g_nextUDPEphemeralPort);
    }

    AssignStatusSafely(pStatus, status);
    if(IsIPStatusAnError(status))
    {
        return(NULL);
    }

    // build the stream manager to point to the page handler
    // first build the stream to the RxStream
    pSocket->hPMGR = hPMGR;
    if(SMGRInit(&pSocket->smgrRxBuff, cbMAXUDPSreamRecord, hPMGR) != (HSMGR) &pSocket->smgrRxBuff)
    {
        status = ispOutOfMemory;
    }
    else if((pSMGR = alloca((cb = GetSMGRSize(((PMGR *) hPMGR)->cPages)))) == NULL)
    {
        status = ispOutOfMemory;
    }
    else if(SMGRInit(pSMGR, cb, hPMGR) == NULL)
    {
        status = ispOutOfMemory;
    }
    else if(SMGRWrite(&pSocket->smgrRxBuff, 0, pSMGR, cb) != cb)
    {
        status = ispOutOfMemory;
    }

    AssignStatusSafely(pStatus, status);
    if(IsIPStatusAnError(status))
    {
        SMGRFree((HSMGR) pSMGR);
        SMGRFree((HSMGR) &pSocket->smgrRxBuff);
        return(NULL);
    }

    pSocket->s.pLLAdp         = pLLAdp;
    pSocket->s.portRemote     = portRemote;
    pSocket->s.portLocal      = portLocal;

    memcpy(&pSocket->s.ipRemote, pIPvXDest, ILIPSize(pLLAdp));

    pSocket->cbRxSMGR       = cb;

    // put on the listening list.
    FFInPacket(&g_ffptListeningUDPSockets, pSocket);

    // return the socket
    return(pSocket);
}