Пример #1
0
void CADiscoverDescriptorThread(void *stServiceInfo)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, " IN");

    VERIFY_NON_NULL_VOID(stServiceInfo, TZ_BLE_CLIENT_TAG, "stServiceInfo is NULL");

    stGattServiceInfo_t *stTemp  = (stGattServiceInfo_t *)stServiceInfo;

    CAResult_t result = CABleGattDiscoverDescriptor(stTemp->serviceInfo, NULL);
    if (CA_STATUS_OK != result)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG,
                  "bt_gatt_discover_characteristic_descriptor failed");
        bt_gatt_destroy_attribute_handle(stTemp->serviceInfo);
        OICFree(stTemp->address);
        OICFree(stTemp);
        return;
    }

    bt_gatt_destroy_attribute_handle(stTemp->serviceInfo);
    OICFree(stTemp->address);
    OICFree(stTemp);

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #2
0
void CADiscoverCharThread(void *stServiceInfo)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    VERIFY_NON_NULL_VOID(stServiceInfo, TZ_BLE_CLIENT_TAG, "stServiceInfo is NULL");

    stGattServiceInfo_t *stTemp  = (stGattServiceInfo_t *)stServiceInfo;

    VERIFY_NON_NULL_VOID(stTemp->address, TZ_BLE_CLIENT_TAG, "stTemp->address is NULL");

    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "remote address [%s]", stTemp->address);

    CAResult_t  result = CABleGattDiscoverCharacteristics(stTemp->serviceInfo, stTemp->address);
    if (CA_STATUS_OK != result)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CABleGattDiscoverCharacteristics failed!");
        bt_gatt_destroy_attribute_handle(stTemp->serviceInfo);
        OICFree(stTemp->address);
        OICFree(stTemp);
        return;
    }
    bt_gatt_destroy_attribute_handle(stTemp->serviceInfo);
    OICFree(stTemp->address);
    OICFree(stTemp);

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #3
0
void CABleGattDescriptorDiscoveredCb(int result, unsigned char format, int total,
                                     bt_gatt_attribute_h descriptor,
                                     bt_gatt_attribute_h characteristic, void *userData)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    stGattCharDescriptor_t *stTemp = (stGattCharDescriptor_t *)OICCalloc(1, sizeof(
                                                                         stGattCharDescriptor_t));

    VERIFY_NON_NULL_VOID(stTemp, TZ_BLE_CLIENT_TAG, "malloc failed!");

    stTemp->desc = (uint8_t *)OICMalloc(total);
    if (NULL == stTemp->desc)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "malloc failed");
        OICFree(stTemp);
        return;
    }
    memcpy(stTemp->desc, descriptor, total);

    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "result[%d] format[%d] total[%d]", result, format, total);
    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "characteristic [%s]", (const char *) characteristic);


    bt_gatt_clone_attribute_handle(&(stTemp->characteristic), characteristic);
    stTemp->total = total;

    ca_mutex_lock(g_bleClientThreadPoolMutex);
    if (NULL == g_bleClientThreadPool)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "g_bleClientThreadPool is NULL");
        bt_gatt_destroy_attribute_handle(stTemp->characteristic);
        OICFree(stTemp->desc);
        OICFree(stTemp);
        ca_mutex_unlock(g_bleClientThreadPoolMutex);
        return;
    }

    CAResult_t ret = ca_thread_pool_add_task(g_bleClientThreadPool,
                                            CASetCharacteristicDescriptorValueThread,
                                            stTemp);
    if (CA_STATUS_OK != ret)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_thread_pool_add_task failed");
        bt_gatt_destroy_attribute_handle(stTemp->characteristic);
        OICFree(stTemp->desc);
        OICFree(stTemp);
        ca_mutex_unlock(g_bleClientThreadPoolMutex);
        return;
    }

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG,
            "LE Client initialization flow complete");

    ca_mutex_unlock(g_bleClientThreadPoolMutex);

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #4
0
void CAFreeBLEServiceInfo(BLEServiceInfo *bleServiceInfo)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_UTIL_TAG, "IN");
    if (bleServiceInfo)
    {
        if (bleServiceInfo->bdAddress)
        {
            bt_device_destroy_bond(bleServiceInfo->bdAddress);
            bt_gatt_disconnect(bleServiceInfo->bdAddress);
            OICFree(bleServiceInfo->bdAddress);
            bt_gatt_destroy_attribute_handle(bleServiceInfo->service_clone);
            bt_gatt_destroy_attribute_handle(bleServiceInfo->read_char);
            bt_gatt_destroy_attribute_handle(bleServiceInfo->write_char);
        }
        OICFree(bleServiceInfo);
    }
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_UTIL_TAG, "OUT");
}
Пример #5
0
void CASetCharacteristicDescriptorValueThread(void *stServiceInfo)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    VERIFY_NON_NULL_VOID(stServiceInfo, TZ_BLE_CLIENT_TAG, "stServiceInfo is NULL");

    stGattCharDescriptor_t *stTemp  = (stGattCharDescriptor_t *)stServiceInfo;

    CAResult_t  result = CASetCharacteristicDescriptorValue(stTemp);
    if (CA_STATUS_OK != result)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CASetCharacteristicDescriptorValue failed!");
        bt_gatt_destroy_attribute_handle(stTemp->characteristic);
        OICFree(stTemp->desc);
        OICFree(stTemp);
        return;
    }
    bt_gatt_destroy_attribute_handle(stTemp->characteristic);
    OICFree(stTemp->desc);
    OICFree(stTemp);

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #6
0
bool CABleGattCharacteristicsDiscoveredCb(int result,
        int inputIndex, int total,
        bt_gatt_attribute_h characteristic, void *userData)
{

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    VERIFY_NON_NULL_RET(characteristic, TZ_BLE_CLIENT_TAG, "Param characteristic is NULL", false);

    VERIFY_NON_NULL_RET(userData, TZ_BLE_CLIENT_TAG, "Param userData is NULL", false);

    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG,
              "result [%d] input_index [%d] total [%d]",
              result, inputIndex, total);

    BLEServiceInfo *bleServiceInfo = NULL;

    ca_mutex_lock(g_bleServiceListMutex);

    char *bdAddress = (char *) userData;
    CAGetBLEServiceInfo(g_bLEServiceList, bdAddress, &bleServiceInfo);

    ca_mutex_unlock(g_bleServiceListMutex);

    char *uuid = NULL;
    bt_gatt_get_service_uuid(characteristic, &uuid);

    VERIFY_NON_NULL_RET(uuid, TZ_BLE_CLIENT_TAG, "uuid is NULL", false);

    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "New Characteristics[%s] of uuid[%s] is obtained",
              (char *)characteristic, uuid);

    if(0 == strcasecmp(uuid, CA_GATT_RESPONSE_CHRC_UUID)) // Server will read on this characterisctics
    {
        OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG , "Read characteristics is obtained");
        OICFree(uuid);
        CAResult_t retVal = CAAppendBLECharInfo(characteristic, BLE_GATT_READ_CHAR, bleServiceInfo);
        if (CA_STATUS_OK != retVal)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CAAppendBLECharInfo failed! ");
            return false;
        }

        stGattServiceInfo_t *stTemp = (stGattServiceInfo_t *)OICCalloc(1,
                                                                      sizeof(stGattServiceInfo_t));

        VERIFY_NON_NULL_RET(stTemp, TZ_BLE_CLIENT_TAG, "calloc failed!", false);

        stTemp->address = OICStrdup(bdAddress);
        if (NULL == stTemp->address)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "Malloc failed!");
            OICFree(stTemp);
            return false;
        }

        bt_gatt_clone_attribute_handle(&(stTemp->serviceInfo), characteristic);

        ca_mutex_lock(g_bleClientThreadPoolMutex);
        if (NULL == g_bleClientThreadPool)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "g_bleClientThreadPool is NULL");
            bt_gatt_destroy_attribute_handle(stTemp->serviceInfo);
            OICFree(stTemp->address);
            OICFree(stTemp);
            ca_mutex_unlock(g_bleClientThreadPoolMutex);
            return false;
        }

        retVal = ca_thread_pool_add_task(g_bleClientThreadPool,
                                        CADiscoverDescriptorThread,
                                        stTemp);
        if (CA_STATUS_OK != retVal)
        {
            OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG,
                      "ca_thread_pool_add_task failed with ret [%d]", retVal);
            bt_gatt_destroy_attribute_handle(stTemp->serviceInfo);
            OICFree(stTemp->address);
            OICFree(stTemp);
            ca_mutex_unlock(g_bleClientThreadPoolMutex);
            return false;
        }
        ca_mutex_unlock(g_bleClientThreadPoolMutex);
    }
    else if (0 == strcasecmp(uuid, CA_GATT_REQUEST_CHRC_UUID)) // Server will write on this characteristics.
    {
        OICFree(uuid);
        OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG , "Write characteristics is obtained");
        CAResult_t retVal = CAAppendBLECharInfo(characteristic, BLE_GATT_WRITE_CHAR, bleServiceInfo);
        if (CA_STATUS_OK != retVal)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "CAAppendBLECharInfo failed ");
            return false;
        }
    }
    else
    {
        OICFree(uuid);
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG , "service_uuid characteristics is UNKNOWN");
        return false;
    }

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
    return true;
}