unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
int ret = 0;
+ unsigned int cached_mtu;
+
+ oc_mutex_lock(g_LEClientListMutex);
+ cached_mtu = CAClientInfoGetMTUSize(g_LEClientList, address);
+ if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE)
+ {
+ OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu);
+ oc_mutex_unlock(g_LEClientListMutex);
+ return cached_mtu -CA_BLE_MTU_HEADER_SIZE;
+ }
bt_gatt_client_h client = NULL;
ret = bt_gatt_client_create(address, &client);
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
+ ret = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed");
+ oc_mutex_unlock(g_LEClientListMutex);
+ return CA_DEFAULT_BLE_MTU_SIZE;
+ }
+
+ oc_mutex_unlock(g_LEClientListMutex);
OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu);
return mtu - CA_BLE_MTU_HEADER_SIZE;
}
unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
int ret = 0;
+ unsigned int cached_mtu;
+ oc_mutex_lock(g_LEClientListMutex);
+ cached_mtu = CAClientInfoGetMTUSize(g_LEClientList, address);
+ if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE)
+ {
+ OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu);
+ oc_mutex_unlock(g_LEClientListMutex);
+ return cached_mtu -CA_BLE_MTU_HEADER_SIZE;
+ }
#ifdef BLE_TIZEN_55
ret = bt_gatt_server_get_device_mtu(address, &mtu);
if (0 != ret)
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
#else
#endif // BLE_TIZEN_40
#endif // BLE_TIZEN_55
+ ret = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed");
+ oc_mutex_unlock(g_LEClientListMutex);
+ return CA_DEFAULT_BLE_MTU_SIZE;
+ }
+
+ oc_mutex_unlock(g_LEClientListMutex);
OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu);
OIC_LOG(DEBUG, TAG, "OUT");
return mtu - CA_BLE_MTU_HEADER_SIZE;
unsigned int mtu = CA_DEFAULT_BLE_MTU_SIZE;
int ret = 0;
+ unsigned int cached_mtu;
+
+ oc_mutex_lock(g_LEClientListMutex);
+ cached_mtu = CAClientInfoGetMTUSize(g_LEClientList, address);
+ if (cached_mtu > 0 && cached_mtu > CA_BLE_MTU_HEADER_SIZE)
+ {
+ OIC_LOG_V(INFO, TAG, "Cached MTU Size is %d",cached_mtu);
+ oc_mutex_unlock(g_LEClientListMutex);
+ return cached_mtu -CA_BLE_MTU_HEADER_SIZE;
+ }
#ifdef BLE_TIZEN_55
ret = bt_gatt_server_get_device_mtu(address, &mtu);
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_create failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_get_att_mtu failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
{
OIC_LOG_V(ERROR, TAG,
"bt_gatt_client_destroy failed with return [%s]", CALEGetErrorMsg(ret));
+ oc_mutex_unlock(g_LEClientListMutex);
return CA_DEFAULT_BLE_MTU_SIZE;
}
#else
#endif // BLE_TIZEN_40
#endif // BLE_TIZEN_55
+ ret = CAClientInfoUpdateMTUSize(g_LEClientList, address,mtu);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG(ERROR, TAG, "CAClientInfoUpdateMTUSize Update failed");
+ oc_mutex_unlock(g_LEClientListMutex);
+ return CA_DEFAULT_BLE_MTU_SIZE;
+ }
+
+ oc_mutex_unlock(g_LEClientListMutex);
OIC_LOG_V(INFO, TAG, "mtu size(including header) from bt_device_get_att_mtu is %d", mtu);
OIC_LOG(DEBUG, TAG, "OUT");
return mtu - CA_BLE_MTU_HEADER_SIZE;
{
OIC_LOG(DEBUG, TAG, "IN");
- VERIFY_NON_NULL(dataList, TAG, "Data list is null");
+ VERIFY_NON_NULL_VOID(dataList, TAG, "Data list is null");
if (*dataList)
{
}
node->remoteAddress= clientAddress;
+ node->mtuSize = 0;
node->next = NULL;
if (*clientList == NULL) // Empty list
return CA_STATUS_OK;
}
+uint16_t CAClientInfoGetMTUSize(LEClientInfoList *clientList,
+ const char *clientAddress)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ LEClientInfoList *temp = clientList;
+ while (temp)
+ {
+ if (!strcasecmp(temp->remoteAddress, clientAddress))
+ {
+ return temp->mtuSize;
+ }
+ temp = temp->next;
+ }
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return 0;
+}
+
+CAResult_t CAClientInfoUpdateMTUSize(LEClientInfoList *clientList,
+ const char *clientAddress,uint16_t mtu_size)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ LEClientInfoList *temp = clientList;
+ while (temp)
+ {
+ if (!strcasecmp(temp->remoteAddress, clientAddress))
+ {
+ temp->mtuSize = mtu_size;
+ return CA_STATUS_OK;
+ }
+ temp = temp->next;
+ }
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_FAILED;
+}
+
CAResult_t CAIsLEClientInfoInList(LEClientInfoList *clientList,
const char *clientAddress)
{
typedef struct _LEClientInfoList
{
char *remoteAddress;
+ uint16_t mtuSize;
struct _LEClientInfoList *next;
} LEClientInfoList;
*/
const char *CALEGetErrorMsg(bt_error_e err);
+uint16_t CAClientInfoGetMTUSize(LEClientInfoList *clientList, const char *clientAddress);
+
+CAResult_t CAClientInfoUpdateMTUSize(LEClientInfoList *clientList, const char *clientAddress, uint16_t mtu_size);
+
#endif /* TZ_BLE_UTIL_H_ */