* limitations under the License.
*
******************************************************************/
-#include "caipinterface_singlethread.h"
+#include "caipinterface.h"
#include <Arduino.h>
#include <Ethernet.h>
#include "logger.h"
#include "cacommon.h"
#include "caadapterinterface.h"
-#include "caipadapter_singlethread.h"
+#include "caipadapter.h"
#include "caipadapterutils_eth.h"
#include "caadapterutils.h"
#include "oic_malloc.h"
return;
}
-uint32_t CAIPSendData(const char *remoteAddress, uint16_t port,
- const char *buf, uint32_t bufLen, bool isMulticast)
+void CAIPSendData(CAEndpoint_t *endpoint, const void *buf,
+ uint32_t bufLen, bool isMulticast)
{
if (!isMulticast && 0 == g_unicastPort)
{
OIC_LOG(ERROR, TAG, "port 0");
- return 0;
+ return;
}
- VERIFY_NON_NULL(buf, TAG, "buf");
- VERIFY_NON_NULL(remoteAddress, TAG, "address");
+ VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
int socketID = 0;
+ uint16_t port = endpoint->port;
if (isMulticast)
{
- if (CAArduinoInitMulticastUdpSocket(remoteAddress, port, g_unicastPort, &socketID)
- != CA_STATUS_OK)
+ if (CAArduinoInitMulticastUdpSocket(endpoint->addr, port,
+ g_unicastPort, &socketID) != CA_STATUS_OK)
{
OIC_LOG(ERROR, TAG, "init mcast err");
- return 0;
+ return;
}
OIC_LOG_V(DEBUG, TAG, "MPORT:%d", port);
OIC_LOG_V(DEBUG, TAG, "LPORT:%d", g_unicastPort);
if (CAArduinoInitUdpSocket(&port, &socketID) != CA_STATUS_OK)
{
OIC_LOG(ERROR, TAG, "init ucast err");
- return 0;
+ return;
}
}
else
uint32_t ret;
uint8_t ipAddr[4] = { 0 };
uint16_t parsedPort = 0;
- if (CAParseIPv4AddressInternal(remoteAddress, ipAddr, sizeof(ipAddr),
+ if (CAParseIPv4AddressInternal(endpoint->addr, ipAddr, sizeof(ipAddr),
&parsedPort) != CA_STATUS_OK)
{
OIC_LOG(ERROR, TAG, "parse fail");
- return 0;
+ return;
}
if (bufLen > 65535) // Max value for uint16_t
{
// This will never happen as max buffer size we are dealing with is COAP_MAX_PDU_SIZE
OIC_LOG(ERROR, TAG, "Size exceeded");
- return 0;
+ return;
}
ret = sendto(socketID, (const uint8_t *)buf, (uint16_t)bufLen, ipAddr, port);
+ if (ret <= 0)
+ {
+ OIC_LOG_V(ERROR, TAG, "SendData failed: %d", ret);
+ }
if (g_sockID != socketID)
{
close(socketID);
}
OIC_LOG(DEBUG, TAG, "OUT");
- return ret;
}