- // Send the first segment with the header.
- OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending Multicast Data");
- result = CAUpdateCharacteristicsToAllGattServers(dataSegment, length);
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Update characteristics (all) failed, result [%d]", result);
- CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
- return ;
- }
- OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length is [%d]", length);
-
- result = CAGenerateHeader(dataHeader,
- CA_BLE_PACKET_NOT_START,
- g_localBLESourcePort,
- secureFlag,
- 0);
-
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "CAGenerateHeader failed, result [%d]", result);
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- return;
- }
-
- // Send the remaining header.
- for (index = 0; index < iter; index++)
- {
- result = CAMakeRemainDataSegment(dataSegment,
- bleData->data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
- index,
- dataHeader);
-
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- return;
- }
-
- result = CAUpdateCharacteristicsToAllGattServers(
- dataSegment,
- CA_SUPPORTED_BLE_MTU_SIZE);
-
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
- result);
- CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
- return;
- }
- OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Client Sent Data length is [%d]",
- CA_SUPPORTED_BLE_MTU_SIZE);
- }
-
- if (remainingLen && (totalLength > CA_SUPPORTED_BLE_MTU_SIZE))
- {
- // send the last segment of the data (Ex: 22 bytes of 622
- // bytes of data when MTU is 200)
- OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
-
- result = CAMakeRemainDataSegment(dataSegment,
- bleData->data,
- remainingLen,
- index,
- dataHeader);
-
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Making data segment failed, result [%d]", result);
- g_errorHandler(bleData->remoteEndpoint, bleData->data, bleData->dataLen, result);
- return;
- }
-
- result =
- CAUpdateCharacteristicsToAllGattServers(
- dataSegment,
- remainingLen + CA_BLE_HEADER_SIZE);
-
- if (CA_STATUS_OK != result)
- {
- OIC_LOG_V(ERROR, CALEADAPTER_TAG,
- "Update characteristics (all) failed, result [%d]", result);
- CALEErrorHandler(NULL, bleData->data, bleData->dataLen, result);
- return;
- }
- OIC_LOG_V(DEBUG, CALEADAPTER_TAG,
- "Client Sent Data length is [%d]", remainingLen + CA_BLE_HEADER_SIZE);
- }