Ejemplo n.º 1
0
CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info)
{
    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");

    // Input validation
    VERIFY_NON_NULL(info, EDR_ADAPTER_TAG, "LocalConnectivity info is null");

    // Get the bluetooth adapter local address
    char *localAddress = NULL;
    int err = bt_adapter_get_address(&localAddress);
    if (BT_ERROR_NONE != err)
    {
        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG,
                  "Getting local adapter address failed!, error num [%x]",
                  err);
        return CA_STATUS_FAILED;
    }

    // Create network info
    *info = CAAdapterCreateLocalEndpoint(CA_EDR, localAddress);
    if (NULL == *info)
    {
        OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Failed to create LocalConnectivity instance!");

        OICFree(localAddress);
        return CA_MEMORY_ALLOC_FAILED;
    }

    OICFree(localAddress);

    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
    return CA_STATUS_OK;
}
Ejemplo n.º 2
0
CAResult_t CAGetLEInterfaceInformation(CALocalConnectivityt_t **info, uint32_t *size)
{
    OCLog(DEBUG, CALEADAPTER_TAG, "IN");

    VERIFY_NON_NULL(info, NULL, "CALocalConnectivity info is null");

#ifdef OIC_ARDUINODUE
    OCLog(DEBUG, CALEADAPTER_TAG, "Info from ARDUINO");
    //1: call corresponding Arduino API
#endif

#if __TIZEN__

    char *local_address = NULL;

    bt_adapter_get_address(&local_address);
    if (NULL == local_address)
    {
        OCLog(ERROR, CALEADAPTER_TAG, "Get local bt adapter address failed");
        return CA_STATUS_FAILED;
    }

#endif //#if ARDUINODUE
    *size = 0;
    (*info) = (CALocalConnectivityt_t *) OICMalloc(sizeof(CALocalConnectivityt_t));
    if (NULL == (*info))
    {
        OCLog(ERROR, CALEADAPTER_TAG, "Malloc failure!");
        return CA_STATUS_FAILED;
    }
    memset((*info), 0x0, sizeof(CALocalConnectivityt_t));

    strncpy((*info)->addressInfo.BT.btMacAddress, local_address, strlen(local_address));
    pthread_mutex_lock(&gBleLocalAddressMutex);
    strncpy(gLocalBLEAddress, local_address, sizeof(gLocalBLEAddress));
    pthread_mutex_unlock(&gBleLocalAddressMutex);

    (*info)->type = CA_LE;
    *size = 1;
    OICFree(local_address);

    OCLog(DEBUG, CALEADAPTER_TAG, "OUT");
    return CA_STATUS_OK;
}