コード例 #1
0
ファイル: socket.c プロジェクト: ethan42411/Energia
int sl_Send(int sd, const void *pBuf, int Len, int flags)
{
    _SlSendMsg_u   Msg;
    _SlCmdExt_t    CmdExt;
    UINT16         ChunkLen;
    int            RetVal;
    UINT32         tempVal;
    unsigned char  runSingleChunk = FALSE;

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

    /* Only for RAW transceiver type socket, relay the flags parameter in the 2 bytes (4 byte aligned) before the actual payload */
    if ((sd & SL_SOCKET_PAYLOAD_TYPE_MASK) == SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER)
    {
        tempVal = flags;
        CmdExt.pRxPayload = (UINT8 *)&tempVal;
        CmdExt.RxPayloadLen = 4;
        g_pCB->RelayFlagsViaRxPayload = TRUE;
        runSingleChunk = TRUE;
    }
    else
    {
        CmdExt.pRxPayload = NULL;
    }

    ChunkLen = _sl_TruncatePayloadByProtocol(sd,Len);
    CmdExt.TxPayloadLen = ChunkLen;

    Msg.Cmd.StatusOrLen = ChunkLen;
    Msg.Cmd.sd = sd;
    Msg.Cmd.FamilyAndFlags |= flags & 0x0F;

    do
    {
        RetVal = _SlDrvDataWriteOp(sd, (_SlCmdCtrl_t *)&_SlSendCmdCtrl, &Msg, &CmdExt);
        if(SL_OS_RET_CODE_OK == RetVal)
        {
            CmdExt.pTxPayload += ChunkLen;
            ChunkLen = (UINT8 *)pBuf + Len - CmdExt.pTxPayload;
            ChunkLen = _sl_TruncatePayloadByProtocol(sd,ChunkLen);
            CmdExt.TxPayloadLen = ChunkLen;
            Msg.Cmd.StatusOrLen = ChunkLen;
        }
        else
        {
            return RetVal;
        }
    } while((ChunkLen > 0) && (runSingleChunk==FALSE));

    return (int)Len;
}
コード例 #2
0
ファイル: socket.c プロジェクト: ethan42411/Energia
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;
}
コード例 #3
0
ファイル: socket.c プロジェクト: yuch7/cc3200-MCU
_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;
}