+
+ //totalLen filled only when header fully read and parsed
+ while (0 != bufferLen)
+ {
+ res = CAConstructCoAP(svritem, &buffer, &bufferLen);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "CAConstructCoAP return error : %d", res);
+ return res;
+ }
+
+ //when successfully read all required data - pass them to upper layer.
+ if (svritem->len == svritem->totalLen)
+ {
+ if (g_networkPacketCallback)
+ {
+ res = g_networkPacketCallback(sep, svritem->data, svritem->totalLen);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Error parsing CoAP data");
+ return res;
+ }
+ }
+ CACleanData(svritem);
+ }
+ else
+ {
+ OIC_LOG_V(DEBUG, TAG, "%u bytes required for complete CoAP",
+ svritem->totalLen - svritem->len);
+ }
+ }
+#endif
+ return res;
+}
+
+#ifdef __WITH_TLS__
+static ssize_t CATCPPacketSendCB(CAEndpoint_t *endpoint, const void *data, size_t dataLength)
+{
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+ VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint is NULL", -1);
+ VERIFY_NON_NULL_RET(data, TAG, "data is NULL", -1);
+
+ OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", endpoint->addr, endpoint->port);
+ OIC_LOG_BUFFER(DEBUG, TAG, data, dataLength);
+
+ ssize_t ret = CATCPSendData(endpoint, data, dataLength);
+ OIC_LOG_V(DEBUG, TAG, "Out %s : %d bytes sent", __func__, ret);
+ return ret;