+ res = g_networkPacketCallback(sep, data, dataLength);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Error parsing CoAP data");
+ }
+ }
+#else
+ unsigned char *buffer = (unsigned char*)data;
+ size_t bufferLen = dataLength;
+ size_t index = 0;
+
+ //get remote device information from file descriptor.
+ CATCPSessionInfo_t *svritem = CAGetTCPSessionInfoFromEndpoint(&sep->endpoint, &index);
+ if (!svritem)
+ {
+ OIC_LOG(ERROR, TAG, "there is no connection information in list");
+ return CA_STATUS_INVALID_PARAM;
+ }
+ if (UNKNOWN == svritem->protocol)
+ {
+ OIC_LOG(ERROR, TAG, "invalid protocol type");
+ return CA_STATUS_INVALID_PARAM;
+ }
+
+ //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);
+ }