Beispiel #1
0
int sl_Bind(int sd, const SlSockAddr_t *addr, int addrlen)
{
    _SlSockBindMsg_u    Msg;
    _SlCmdCtrl_t         CmdCtrl = {0, 0, sizeof(_SocketResponse_t)};

    switch(addr->sa_family)
    {
    case SL_AF_INET :
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t);
        break;
    case SL_AF_INET6_EUI_48:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t);
        break;
#ifdef SL_SUPPORT_IPV6
    case AF_INET6:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t);
        break;
#endif
    case SL_AF_RF   :
    default:
        return SL_RET_CODE_INVALID_INPUT;
    }

    Msg.Cmd.IpV4.lenOrPadding = 0;
    Msg.Cmd.IpV4.sd = (UINT8)sd;

    _sl_BuildAddress(addr, addrlen, &Msg.Cmd);

    VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL));

    return Msg.Rsp.statusOrLen;
}
Beispiel #2
0
_i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
{
	_SlSockBindMsg_u    Msg;
    _SlCmdCtrl_t         CmdCtrl = {0, 0, (_SlArgSize_t)sizeof(_SocketResponse_t)};

    /* verify no erorr handling in progress. if in progress than
      ignore the API execution and return immediately with an error */
    VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();

    switch(addr->sa_family)
    {
        case SL_AF_INET :
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv4Command_t);
            break;
#ifndef SL_TINY_EXT            
        case SL_AF_INET6_EUI_48:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv6EUI48Command_t);
        	break;

#ifdef SL_SUPPORT_IPV6
        case AF_INET6:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv6Command_t);
            break;
#endif
#endif


        case SL_AF_RF   :
        default:
            return SL_RET_CODE_INVALID_INPUT;
    }

    Msg.Cmd.IpV4.lenOrPadding = 0;
    Msg.Cmd.IpV4.sd = (_u8)sd;

    _sl_BuildAddress(addr, &Msg.Cmd);

    VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL));

    return Msg.Rsp.statusOrLen;
}
Beispiel #3
0
int sl_Connect(int sd, const SlSockAddr_t *addr, int addrlen)
{
    _SlSockConnectMsg_u  Msg;
    _SlReturnVal_t       RetVal;
    _SlCmdCtrl_t         CmdCtrl = {0, 0, sizeof(_SocketResponse_t)};
    _SocketResponse_t    AsyncRsp;
    UINT8 pObjIdx = MAX_CONCURRENT_ACTIONS;


    switch(addr->sa_family)
    {
    case SL_AF_INET :
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t);
        break;
    case  SL_AF_INET6_EUI_48:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t);
        break;
#ifdef SL_SUPPORT_IPV6
    case AF_INET6:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t);
        break;
#endif
    case SL_AF_RF   :
    default:
        return SL_RET_CODE_INVALID_INPUT;
    }

    Msg.Cmd.IpV4.lenOrPadding = 0;
    Msg.Cmd.IpV4.sd = sd;

    _sl_BuildAddress(addr, addrlen, &Msg.Cmd);

    /* Use Obj to issue the command, if not available try later */
    pObjIdx = _SlDrvWaitForPoolObj(CONNECT_ID, sd  & BSD_SOCKET_ID_MASK);

    if (MAX_CONCURRENT_ACTIONS == pObjIdx)
    {
        return SL_POOL_IS_EMPTY;
    }
    OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER));

    g_pCB->ObjPool[pObjIdx].pRespArgs =  (UINT8 *)&AsyncRsp;

    OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj));

    /* send the command */
    VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL));
    VERIFY_PROTOCOL(Msg.Rsp.sd == sd)

    RetVal = Msg.Rsp.statusOrLen;

    if(SL_RET_CODE_OK == RetVal)
    {
        /*  wait for async and get Data Read parameters */
        OSI_RET_OK_CHECK(sl_SyncObjWait(&g_pCB->ObjPool[pObjIdx].SyncObj, SL_OS_WAIT_FOREVER));

        VERIFY_PROTOCOL(AsyncRsp.sd == sd);

        RetVal = AsyncRsp.statusOrLen;
    }
    _SlDrvReleasePoolObj(pObjIdx);
    return RetVal;
}
Beispiel #4
0
int sl_SendTo(int sd, const void *pBuf, int Len, int flags, const SlSockAddr_t *to, SlSocklen_t tolen)
{
    _SlSendtoMsg_u   Msg;
    _SlCmdCtrl_t     CmdCtrl = {0, 0, 0};
    _SlCmdExt_t      CmdExt;
    UINT16           ChunkLen;
    int              RetVal;

    CmdExt.TxPayloadLen = (UINT16)Len;
    CmdExt.RxPayloadLen = 0;
    CmdExt.pTxPayload = (UINT8 *)pBuf;
    CmdExt.pRxPayload = NULL;


    switch(to->sa_family)
    {
    case SL_AF_INET:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv4Command_t);
        break;
    case SL_AF_INET6_EUI_48:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6EUI48Command_t);
        break;
#ifdef SL_SUPPORT_IPV6
    case AF_INET6:
        CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO_V6;
        CmdCtrl.TxDescLen = sizeof(_SocketAddrIPv6Command_t);
        break;
#endif
    case SL_AF_RF:
    default:
        return SL_RET_CODE_INVALID_INPUT;
    }

    ChunkLen = _sl_TruncatePayloadByProtocol(sd,Len);
    Msg.Cmd.IpV4.lenOrPadding = ChunkLen;
    CmdExt.TxPayloadLen = ChunkLen;

    Msg.Cmd.IpV4.sd = (UINT8)sd;

    _sl_BuildAddress(to, tolen, &Msg.Cmd);

    Msg.Cmd.IpV4.FamilyAndFlags |= flags & 0x0F;

    do
    {
        RetVal = _SlDrvDataWriteOp((_SlSd_t)sd, &CmdCtrl, &Msg, &CmdExt);

        if(SL_OS_RET_CODE_OK == RetVal)
        {
            CmdExt.pTxPayload += ChunkLen;
            ChunkLen = (UINT16)((UINT8 *)pBuf + Len - CmdExt.pTxPayload);
            ChunkLen = _sl_TruncatePayloadByProtocol(sd,ChunkLen);
            CmdExt.TxPayloadLen = ChunkLen;
            Msg.Cmd.IpV4.lenOrPadding = ChunkLen;
        }
        else
        {
            return RetVal;
        }
    } while(ChunkLen > 0);

    return (int)Len;
}
Beispiel #5
0
_i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
{
      _SlSockConnectMsg_u  Msg;
      _SlReturnVal_t       RetVal;
      _SlCmdCtrl_t         CmdCtrl = {0, (_SlArgSize_t)0, (_SlArgSize_t)sizeof(_SocketResponse_t)};
      _SocketResponse_t    AsyncRsp;
      _u8 ObjIdx = MAX_CONCURRENT_ACTIONS;

	/* verify no erorr handling in progress. if in progress than
	ignore the API execution and return immediately with an error */
	VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();


    switch(addr->sa_family)
    {
        case SL_AF_INET :
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv4Command_t);
            /* Do nothing - cmd already initialized to this type */
            break;
        case  SL_AF_INET6_EUI_48:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv6EUI48Command_t);
        	break;
#ifdef SL_SUPPORT_IPV6
        case AF_INET6:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv6Command_t);
            break;
#endif
        case SL_AF_RF:
        default:
            return SL_RET_CODE_INVALID_INPUT;
    }

    Msg.Cmd.IpV4.lenOrPadding = 0;
    Msg.Cmd.IpV4.sd = (_u8)sd;

    _sl_BuildAddress(addr, &Msg.Cmd);


    ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, CONNECT_ID, (_u8)(sd  & BSD_SOCKET_ID_MASK));

    if (MAX_CONCURRENT_ACTIONS == ObjIdx)
    {
        return SL_POOL_IS_EMPTY;
    }

    /* send the command */
    VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL));
    VERIFY_PROTOCOL(Msg.Rsp.sd == (_u8)sd)

	RetVal = Msg.Rsp.statusOrLen;

    if(SL_RET_CODE_OK == RetVal)
    {
#ifndef SL_TINY_EXT    
    	/*In case socket is non-blocking one, the async event should be received immediately */
    	if( g_pCB->SocketNonBlocking >> (sd & BSD_SOCKET_ID_MASK))
		{
    		SL_DRV_SYNC_OBJ_WAIT_TIMEOUT(&g_pCB->ObjPool[ObjIdx].SyncObj,
                                             SL_DRIVER_TIMEOUT_SHORT,
                                             SL_DRIVER_API_SOCKET_CONNECT
                                             );
		}
    	else
#endif         
    	{
    		/* wait for async and get Data Read parameters */
    		SL_DRV_SYNC_OBJ_WAIT_FOREVER(&g_pCB->ObjPool[ObjIdx].SyncObj);
    	}
        
        VERIFY_PROTOCOL(AsyncRsp.sd == (_u8)sd);

        RetVal = AsyncRsp.statusOrLen;
    }
Beispiel #6
0
_i16 sl_SendTo(_i16 sd, const void *pBuf, _i16 Len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen)
{
    _SlSendtoMsg_u   Msg;
    _SlCmdCtrl_t     CmdCtrl = {0, 0, 0};
    _SlCmdExt_t      CmdExt;
    _u16           ChunkLen;
    _i16              RetVal;

    /* verify no erorr handling in progress. if in progress than
       ignore the API execution and return immediately with an error */
    VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();

    _SlDrvResetCmdExt(&CmdExt);
    CmdExt.TxPayloadLen = (_u16)Len;
    CmdExt.pTxPayload = (_u8 *)pBuf;

    switch(to->sa_family)
    {
        case SL_AF_INET:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv4Command_t);
            break;
#ifndef SL_TINY_EXT            
        case SL_AF_INET6_EUI_48:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv6EUI48Command_t);
        	break;        
#ifdef SL_SUPPORT_IPV6
        case AF_INET6:
            CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO_V6;
            CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(_SocketAddrIPv6Command_t);
            break;
#endif
#endif
        case SL_AF_RF:
        default:
            return SL_RET_CODE_INVALID_INPUT;
    }

    ChunkLen = _sl_TruncatePayloadByProtocol(sd,(_u16)Len);
    Msg.Cmd.IpV4.lenOrPadding = (_i16)ChunkLen;
    CmdExt.TxPayloadLen = ChunkLen;

    Msg.Cmd.IpV4.sd = (_u8)sd;

    _sl_BuildAddress(to, &Msg.Cmd);

    Msg.Cmd.IpV4.FamilyAndFlags |= flags & 0x0F;

    do
    {
        RetVal = _SlDrvDataWriteOp((_SlSd_t)sd, &CmdCtrl, &Msg, &CmdExt);

        if(SL_OS_RET_CODE_OK == RetVal)
        {
            CmdExt.pTxPayload += ChunkLen;
            ChunkLen = (_u16)((_u8 *)pBuf + Len - CmdExt.pTxPayload);
            ChunkLen = _sl_TruncatePayloadByProtocol(sd,ChunkLen);
            CmdExt.TxPayloadLen = ChunkLen;
            Msg.Cmd.IpV4.lenOrPadding = (_i16)ChunkLen;
        }
        else
        {
            return RetVal;
        }
    }while(ChunkLen > 0);

    return (_i16)Len;
}