Exemplo n.º 1
0
OCStackResult CreateProvisioningResource(bool isSecured)
{
    gProvResource.ps = ES_PS_NEED_PROVISIONING;
    gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;

    gProvResource.tnt = CT_ADAPTER_IP;
    OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "Unknown");
    OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "Unknown");

    OCStackResult res = OC_STACK_ERROR;
    if (isSecured)
    {
        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
    }
    else
    {
        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
    }

    OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
    return res;
}
Exemplo n.º 2
0
void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
{
    if (name != NULL && pass != NULL)
    {
        OICStrcpy(name, sizeof(name), gProvResource.tnn);
        OICStrcpy(pass, sizeof(pass), gProvResource.cd);
    }
}
Exemplo n.º 3
0
OCStackResult CHPGetHttpOption(const OCHeaderOption* option, HttpHeaderOption_t** httpOption)
{
    OIC_LOG_V(DEBUG, TAG, "%s IN", __func__);
    if (!option)
    {
        OIC_LOG(ERROR, TAG, "option is NULL");
        return OC_STACK_INVALID_PARAM;
    }

    *httpOption = (HttpHeaderOption_t *)OICCalloc(1, sizeof(HttpHeaderOption_t));
    if (NULL == *httpOption)
    {
        OIC_LOG(ERROR, TAG, "Memory allocation failed");
        return OC_STACK_NO_MEMORY;
    }

    switch (option->optionID)
    {
        case COAP_OPTION_ACCEPT:
            OICStrcpy((*httpOption)->optionName, sizeof((*httpOption)->optionName),
                      HTTP_OPTION_ACCEPT);
            break;
        case COAP_OPTION_IF_MATCH:
            OICStrcpy((*httpOption)->optionName, sizeof((*httpOption)->optionName),
                      HTTP_OPTION_IF_MATCH);
            break;
        case COAP_OPTION_IF_NONE_MATCH:
            OICStrcpy((*httpOption)->optionName, sizeof((*httpOption)->optionName),
                      HTTP_OPTION_IF_NONE_MATCH);
            break;
        case COAP_OPTION_ETAG:
            OICStrcpy((*httpOption)->optionName, sizeof((*httpOption)->optionName),
                      HTTP_OPTION_ETAG);
            break;
        case COAP_OPTION_CONTENT_TYPE:
            OICStrcpy((*httpOption)->optionName, sizeof((*httpOption)->optionName),
                      HTTP_OPTION_CONTENT_TYPE);
            break;
        default:
            OIC_LOG_V(INFO, TAG, "No Matching found for the ID %d", option->optionID);
    }

    if ('\0' == (*httpOption)->optionName[0])
    {
        OIC_LOG(ERROR, TAG, "No matching is found");
        OICFree(*httpOption);
        return OC_STACK_INVALID_OPTION;
    }

    (*httpOption)->optionLength = option->optionLength < sizeof((*httpOption)->optionData) ?
                                      option->optionLength : sizeof((*httpOption)->optionData);
    memcpy((*httpOption)->optionData, option->optionData, (*httpOption)->optionLength);

    OIC_LOG_V(DEBUG, TAG, "%s OUT", __func__);
    return OC_STACK_OK;
}
Exemplo n.º 4
0
OicSecCred_t * getCredList()
{
    size_t sz = 0;
    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(*cred));
    VERIFY_NON_NULL(TAG, cred, ERROR);
    cred->credId = 1234;
    // use |memcpy| for copying full-lengthed UUID without null termination
    memcpy(cred->subject.id, "1111111111111111", sizeof(cred->subject.id));

#if 0
    cred->roleIdsLen = 2;
    cred->roleIds = (OicSecRole_t *)OICCalloc(cred->roleIdsLen, sizeof(OicSecRole_t));
    VERIFY_NON_NULL(TAG, cred->roleIds, ERROR);
    OICStrcpy((char *)cred->roleIds[0].id, sizeof(cred->roleIds[0].id), "role11");
    OICStrcpy((char *)cred->roleIds[1].id, sizeof(cred->roleIds[1].id), "role12");
#endif

    cred->credType = SYMMETRIC_PAIR_WISE_KEY;
    cred->privateData.data = (uint8_t *)OICCalloc(1, strlen("My private Key11") + 1);
    VERIFY_NON_NULL(TAG, cred->privateData.data, ERROR);
    OICStrcpy((char *)cred->privateData.data, strlen("My private Key11")+1,"My private Key11");
    // use |memcpy| for copying full-lengthed UUID without null termination
    memcpy(cred->rownerID.id, "aaaaaaaaaaaaaaaa", sizeof(cred->rownerID.id));
    cred->next = (OicSecCred_t*)OICCalloc(1, sizeof(*cred->next));
    VERIFY_NON_NULL(TAG, cred->next, ERROR);
    cred->next->credId = 5678;
    // use |memcpy| for copying full-lengthed UUID without null termination
    memcpy(cred->next->subject.id, "2222222222222222", sizeof(cred->next->subject.id));
#if 0
    cred->next->roleIdsLen = 0;
#endif
    cred->next->credType = SYMMETRIC_PAIR_WISE_KEY;
    sz = strlen("My private Key21") + 1;
    cred->next->privateData.data = (uint8_t *)OICCalloc(1, sz);
    VERIFY_NON_NULL(TAG, cred->next->privateData.data, ERROR);
    OICStrcpy((char *)cred->next->privateData.data, sz, "My private Key21");
#if 0
    sz = strlen("My Public Key123") + 1;
    cred->next->publicData.data = (char *)OICCalloc(1, sz);
    VERIFY_NON_NULL(TAG, cred->next->publicData.data, ERROR);
    OICStrcpy(cred->next->publicData.data, sz,"My Public Key123");
#endif
    // use |memcpy| for copying full-lengthed UUID without null termination
    memcpy(cred->next->rownerID.id, "bbbbbbbbbbbbbbbb", sizeof(cred->next->rownerID.id));

    return cred;

exit:
    if(cred)
    {
        DeleteCredList(cred);
        cred = NULL;
    }
    return cred;
}
Exemplo n.º 5
0
OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(const char *deviceName, const char *id, int biasFactor)
{
    OCRDDiscoveryPayload *discoveryPayload = (OCRDDiscoveryPayload *)OICCalloc(1, sizeof(OCRDDiscoveryPayload));

    if (!discoveryPayload)
    {
        return NULL;
    }

    if (deviceName)
    {
        discoveryPayload->n.deviceName = OICStrdup(deviceName);
        if (!discoveryPayload->n.deviceName)
        {
            OICFree(discoveryPayload);
            return NULL;
        }
    }
    if (id)
    {
        OICStrcpy((char*)discoveryPayload->di.id, MAX_IDENTITY_SIZE, id);
    }

    discoveryPayload->sel = biasFactor;

    return discoveryPayload;
}
Exemplo n.º 6
0
void CARAXmppConnectedCB(void * const param, xmpp_error_code_t result,
        const char *const bound_jid,
        xmpp_connection_handle_t connection)
{
    OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARAXmppConnectedCB IN");
    CANetworkStatus_t connection_status;
    if (XMPP_ERR_OK == result)
    {
        printf("\n\n\t\t===>your jid: %s\n\n", bound_jid);

        ca_mutex_lock (g_raadapterMutex);
        OICStrcpy (g_xmppData.jabberID, CA_RAJABBERID_SIZE, bound_jid);

        g_xmppData.connection_status = CA_INTERFACE_UP;
        connection_status = CA_INTERFACE_UP;
        g_xmppData.connection_handle = connection;
        g_xmppData.message_callback.on_received = CARAXmppMessageReceivedCB;
        g_xmppData.message_callback.on_sent = CARAXmppMessageSentCB;
        g_xmppData.message_context = xmpp_message_context_create(g_xmppData.connection_handle,
                g_xmppData.message_callback);
    }
    else
    {
        g_xmppData.connection_status = CA_INTERFACE_DOWN;
        connection_status = CA_INTERFACE_DOWN;
        OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "XMPP connected callback status: %d", result);
    }

    ca_mutex_unlock (g_raadapterMutex);
    // Notify network change to CA
    CARANotifyNetworkChange(bound_jid, connection_status);

    OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARAXmppConnectedCB OUT");
}
Exemplo n.º 7
0
ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
                                             ProvStatus provStatus) {

    ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));

    if (provInfo == NULL) {
        OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
        return NULL;
    }

    OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));

    if (devAddr == NULL) {
        OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
        OICFree(provInfo);
        return NULL;
    }

    OICStrcpy(devAddr->addr, sizeof(devAddr->addr), clientResponse->addr->addr);

    devAddr->port = clientResponse->addr->port;

    provInfo->provDeviceInfo.addr = devAddr;

    provInfo->provStatus = provStatus;

    return provInfo;
}
Exemplo n.º 8
0
OCEntityHandlerResult getDoubleValueFromString (const char *str, double *outDouble)
{
    size_t hexOutValSize = strlen(HexPrepend) + strlen(str) + 1;
    char * hexOutVal = (char *) OICCalloc(1, hexOutValSize);
    if(!hexOutVal)
    {
        return OC_EH_ERROR;
    }
    OICStrcpy(hexOutVal, hexOutValSize, HexPrepend);
    OICStrcat(hexOutVal, hexOutValSize, str);

    char *endPtr = NULL;
    errno = 0;
    double value = strtod(hexOutVal, &endPtr);

    if(errno != 0 || *endPtr != 0 || value == HUGE_VALF || value == HUGE_VALL)
    {
        OICFree(hexOutVal);
        return OC_EH_ERROR;
    }

    OICFree(hexOutVal);
    *outDouble = value;
    return OC_EH_OK;

}
Exemplo n.º 9
0
NSResult NSPutMessageResource(NSMessage *msg, OCResourceHandle * handle)
{
    NS_LOG(DEBUG, "NSPutMessageResource - IN");

    if(msg != NULL)
    {
        NS_LOG(DEBUG, "NSMessage is valid");

        NotificationMessageResource.messageId = msg->messageId;
        OICStrcpy(NotificationMessageResource.providerId, UUID_STRING_SIZE, msg->providerId);
        NotificationMessageResource.type = msg->type;
        NotificationMessageResource.dateTime = msg->dateTime;
        NotificationMessageResource.ttl = msg->ttl;
        NotificationMessageResource.title = msg->title;
        NotificationMessageResource.contentText = msg->contentText;
        NotificationMessageResource.sourceName = msg->sourceName;
        NotificationMessageResource.mediaContents = msg->mediaContents;
    }
    else
    {
        NS_LOG(ERROR, "NSMessage is NULL");
    }

    *handle = NotificationMessageResource.handle;
    NS_LOG(DEBUG, "NSPutMessageResource - OUT");

    return NS_OK;
}
Exemplo n.º 10
0
OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, uint64_t ttl)
{
    OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload));
    if (!tags)
    {
        return NULL;
    }
    if (deviceName)
    {
        tags->n.deviceName = OICStrdup(deviceName);
        if (!tags->n.deviceName)
        {
            goto memory_allocation_failed;
        }
    }
    if (id)
    {
        OICStrcpy((char*)tags->di.id, MAX_IDENTITY_SIZE, (char *)id);
    }
    tags->ttl = ttl;
    return tags;

memory_allocation_failed:
    OIC_LOG(ERROR, TAG, "Memory allocation failed.");
    OCFreeTagsResource(tags);
    return NULL;
}
Exemplo n.º 11
0
OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, const char *baseURI,
        uint8_t bitmap, uint16_t port, uint8_t ins, const char *rts,const  char *drel, uint32_t ttl)
{
    OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload));
    if (!tags)
    {
        return NULL;
    }
	if (deviceName)
    {
        tags->n.deviceName = OICStrdup(deviceName);
        if (!tags->n.deviceName)
        {
            goto memory_allocation_failed;
        }
    }
    if (id)
    {
        OICStrcpy((char*)tags->di.id, MAX_IDENTITY_SIZE, (char *)id);
        if (!tags->di.id)
        {
            goto memory_allocation_failed;
        }
    }
    if (baseURI)
    {
        tags->baseURI = OICStrdup(baseURI);
        if (!tags->baseURI)
        {
            goto memory_allocation_failed;
        }
    }
    tags->bitmap = bitmap;
    tags->port = port;
    tags->ins = ins;
    if (rts)
    {
        tags->rts = OICStrdup(rts);
        if (!tags->rts)
        {
            goto memory_allocation_failed;
        }
    }
    if (drel)
    {
        tags->drel = OICStrdup(drel);
        if (!tags->drel)
        {
            goto memory_allocation_failed;
        }
    }
    tags->ttl = ttl;
    return tags;

memory_allocation_failed:
    OC_LOG(ERROR, TAG, "Memory allocation failed.");
    OCFreeTagsResource(tags);
    return NULL;
}
Exemplo n.º 12
0
// tests a copy where the destination is of length 0
TEST(StringTests, StrcpyZeroDestination)
{
    char target[0];
    char source[] = "123456789";

    char *result = OICStrcpy(target, sizeof(target), source);

    EXPECT_EQ(target, result);
}
Exemplo n.º 13
0
static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family,
                                         const char *addr, int flags)
{
    CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof (CAInterface_t));
    if (!ifitem)
    {
        OIC_LOG(ERROR, TAG, "Malloc failed");
        return NULL;
    }

    OICStrcpy(ifitem->name, sizeof (ifitem->name), name);
    ifitem->index = index;
    ifitem->family = family;
    OICStrcpy(ifitem->addr, sizeof (ifitem->addr), addr);
    ifitem->flags = flags;

    return ifitem;
}
Exemplo n.º 14
0
TEST(CredResourceTest, GenerateCredentialValidInput)
{
    OicUuid_t rownerID = {{0}};
    OICStrcpy((char *)rownerID.id, sizeof(rownerID.id), "ownersId21");

    OicUuid_t subject = {{0}};
    OICStrcpy((char *)subject.id, sizeof(subject.id), "subject11");

    uint8_t privateKey[] = "My private Key11";
    OicSecKey_t key = {privateKey, sizeof(privateKey)};

    OicSecCred_t * cred  = NULL;
    cred = GenerateCredential(&subject, SYMMETRIC_PAIR_WISE_KEY, NULL,
                              &key, &rownerID);
    printCred(cred);

    ASSERT_TRUE(NULL != cred);
    DeleteCredList(cred);
}
Exemplo n.º 15
0
ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status) {

    ProvisioningInfo *provInfo = CreateCallBackObject();
    OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr),
        netProvInfo->netAddressInfo.WIFI.ipAddress);

    provInfo->provDeviceInfo.addr->port = IP_PORT;
    provInfo->provStatus = status;
    return provInfo;
}
Exemplo n.º 16
0
ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse,
                                             ProvStatus provStatus) {
    ProvisioningInfo *provInfo = CreateCallBackObject();
    OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr),
                        clientResponse->addr->addr);

    provInfo->provDeviceInfo.addr->port = clientResponse->addr->port;
    provInfo->provStatus = provStatus;
    return provInfo;
}
Exemplo n.º 17
0
TEST(CredGenerateCredentialTest, GenerateCredentialValidInput)
{
    OicUuid_t owners[1];
    OICStrcpy((char *)owners[0].id, sizeof(owners[0].id), "ownersId21");

    OicUuid_t subject = {{0}};
    OICStrcpy((char *)subject.id, sizeof(subject.id), "subject11");

    char privateKey[] = "My private Key11";

    OicSecCred_t * cred  = NULL;

    cred = GenerateCredential(&subject, SYMMETRIC_PAIR_WISE_KEY, NULL,
                              privateKey, 1, owners);
    printCred(cred);

    EXPECT_TRUE(NULL != cred);
    DeleteCredList(cred);
}
Exemplo n.º 18
0
// Tests a normal copy where the buffer is exactly long enough
TEST(StringTests, StrcpyExactSize)
{
    char target[10];
    memset(target, SENTINEL_VALUE, sizeof(target));
    char source[] = "123456789";

    char* result = OICStrcpy(target, sizeof(target), source);

    EXPECT_EQ(target, result);
    EXPECT_EQ(sizeof(target) - 1, strlen(target));
    EXPECT_STREQ(source, result);
}
Exemplo n.º 19
0
//Cred DELETE request
TEST(CredEntityHandlerTest, CredEntityHandlerDeleteTest)
{
    OCEntityHandlerRequest ehReq =  OCEntityHandlerRequest();
    static OCPersistentStorage ps =  OCPersistentStorage();
    const OicSecCred_t* subjectCred1 = NULL;
    const OicSecCred_t* subjectCred2 = NULL;
    char *jsonStr = NULL;
    OCEntityHandlerResult ehRet = OC_EH_ERROR;
    char query[] = "sub=c3ViamVjdDE=";

    SetPersistentHandler(&ps, true);

    OicSecCred_t *cred = getCredList();
    VERIFY_NON_NULL(TAG, cred, ERROR);

    jsonStr = BinToCredJSON(cred);
    VERIFY_NON_NULL(TAG, jsonStr, ERROR);

    // Create Entity Handler POST request payload
    ehReq.method = OC_REST_POST;
    ehReq.payload = (OCPayload*)OCSecurityPayloadCreate(jsonStr);
    ehRet = CredEntityHandler(OC_REQUEST_FLAG, &ehReq);
    EXPECT_TRUE(OC_EH_ERROR == ehRet);

    // Verify if SRM contains Credential for the subject
    subjectCred1 = GetCredResourceData(&cred->subject);
    EXPECT_TRUE(NULL != subjectCred1);

    // Create Entity Handler DELETE request
    ehReq.method = OC_REST_DELETE;
    ehReq.query = (char*)OICMalloc(strlen(query)+1);
    VERIFY_NON_NULL(TAG, ehReq.query, ERROR);
    OICStrcpy(ehReq.query, strlen(query)+1, query);

    ehRet = CredEntityHandler(OC_REQUEST_FLAG, &ehReq);
    EXPECT_TRUE(OC_EH_ERROR == ehRet);

    // Verify if SRM has deleted ACE for the subject
    subjectCred2 = GetCredResourceData(&cred->subject);
    EXPECT_TRUE(NULL == subjectCred2);

exit:
    // Perform cleanup
    OICFree(ehReq.query);
    OICFree(jsonStr);
    OCPayloadDestroy(ehReq.payload);
    if(NULL != cred)
    {
        DeInitCredResource();
        DeleteCredList(cred);
    }
}
Exemplo n.º 20
0
static OicSecPdAcl_t* createPdAcl(const int dev_num)
{
    if(0>=dev_num || g_own_cnt<dev_num)
    {
        OIC_LOG(ERROR, TAG, "createAcl invalid parameters");
        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
    }

    // allocate memory for |pdacl| struct
    printf("   **** Create PDACL for the Selected Device[%d]\n", dev_num);
    OicSecPdAcl_t* pdAcl = (OicSecPdAcl_t*) OICCalloc(1, sizeof(OicSecPdAcl_t));
    if(!pdAcl)
    {
        OIC_LOG(ERROR, TAG, "createAcl: OICCalloc error return");
        return NULL;  // not need to 'goto' |ERROR| before allocating |acl|
    }


    // number of resources
    char rsrc_in[][ACL_RESRC_MAX_LEN+1] = {"*", "/rsrc/*"};
    pdAcl->resourcesLen = 1;

    // resource
    int num = pdAcl->resourcesLen;
    pdAcl->resources = (char**) OICCalloc(num, sizeof(char*));
    if(!pdAcl->resources)
    {
        OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
        goto CRPDACL_ERROR;
    }
    for(int i=0; num>i; ++i)
    {
        size_t len = strlen(rsrc_in[i])+1;  // '1' for null termination
        char* rsrc = (char*) OICCalloc(len, sizeof(char));
        if(!rsrc)
        {
            OIC_LOG(ERROR, TAG, "createPdAcl: OICCalloc error return");
            goto CRPDACL_ERROR;
        }
        OICStrcpy(rsrc, len, rsrc_in[i]);
        pdAcl->resources[i] = rsrc;  // after here, |rsrc| points nothing
    }

    // permission
    pdAcl->permission = PERMISSION_FULL_CONTROL;

    return pdAcl;

CRPDACL_ERROR:
    OCDeletePdAclList(pdAcl);
    return NULL;
}
Exemplo n.º 21
0
void CAPacketReceivedCallback(const char *ipAddress, const uint16_t port,
                              const void *data, const uint32_t dataLength)
{
    OIC_LOG(DEBUG, TAG, "IN");
    if (g_packetReceivedCallback)
    {
        CASecureEndpoint_t sep =
        {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = CA_IPV4, .port = port}};
        OICStrcpy(sep.endpoint.addr, sizeof(sep.endpoint.addr), ipAddress);
        g_packetReceivedCallback(&sep, data, dataLength);
    }
    OIC_LOG(DEBUG, TAG, "OUT");
}
OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*handle*/,
        OCClientResponse *clientResponse)
{
    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "Inside ProvisionEnrolleeResponse");

    // If user stopped the process then return from this function;
    if (IsSetupStopped())
    {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        ClearMemory();
        return OC_STACK_DELETE_TRANSACTION;
    }

    if (!ValidateEnrolleeResponse(clientResponse))
    {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        return OC_STACK_DELETE_TRANSACTION;
    }

    char query[OIC_STRING_MAX_VALUE] =
    { '\0' };
    char resUri[MAX_URI_LENGTH] =
    { '\0' };

    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "Resource URI = %s", clientResponse->resourceUri);

    OICStrcpy(resUri, sizeof(resUri), clientResponse->resourceUri);

#ifdef REMOTE_ARDUINO_ENROLEE
    //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
    // to Arduino WiFi enrollee
    // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino
    snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT,
            resUri);
#else
    snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr,
            clientResponse->addr->port, resUri);
#endif

    if (TriggerNetworkConnection(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0)
            != OC_STACK_OK)
    {
        OIC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse");

        ErrorCallback(DEVICE_NOT_PROVISIONED);
        ClearMemory();
    }

    return OC_STACK_DELETE_TRANSACTION;
}
Exemplo n.º 23
0
CAResult_t CAUpdateCharacteristicsToGattClient(const char* address, const char *charValue,
        const uint32_t charValueLen)
{
    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");

    VERIFY_NON_NULL(charValue, TZ_BLE_SERVER_TAG, "Param charValue is NULL");

    VERIFY_NON_NULL(address, TZ_BLE_SERVER_TAG, "Param address is NULL");

    OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "Client's Unicast address for sending data [%s]", address);

    ca_mutex_lock(g_bleCharacteristicMutex);

    if (NULL  == g_gattReadCharPath)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_gattReadCharPath is NULL");
        ca_mutex_unlock(g_bleCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    char *data = (char *) OICCalloc(sizeof(char), (charValueLen + 1));
    if (NULL == data)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "malloc failed!");
        ca_mutex_unlock(g_bleCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    OICStrcpy(data, charValueLen + 1, charValue);

    OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]",
              (const char *)g_gattReadCharPath, data, charValueLen);

    int ret =  bt_gatt_update_characteristic(g_gattReadCharPath, data, charValueLen, address);
    if (0 != ret)
    {
        OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG,
                  "bt_gatt_update_characteristic failed with return [%d]", ret);
        OICFree(data);
        ca_mutex_unlock(g_bleCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    OICFree(data);
    ca_mutex_unlock(g_bleCharacteristicMutex);

    OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "OUT");
    return CA_STATUS_OK;
}
Exemplo n.º 24
0
OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
                                       OCProvisioningStatusCB provisioningStatusCallback,
                                       char *findResQuery) {

    if(findResQuery != NULL)
    {
        OICStrcpy(szFindResourceQueryUri, sizeof(szFindResourceQueryUri) - 1, findResQuery);
    }
    else
    {
        OIC_LOG(ERROR, ES_PROV_TAG, PCF("Find resource query is NULL"));
        goto Error;
    }

    pthread_t thread_handle;

    if (!ValidateEasySetupParams(netInfo, provisioningStatusCallback)) {
        goto Error;
    }

    if (!SetProgress(provisioningStatusCallback)) {
        // Device provisioning session is running already.
        OIC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already"));
        goto Error;
    }

    if (!ConfigEnrolleeObject(netInfo)) {
        goto Error;
    }

    if (pthread_create(&thread_handle, NULL, FindProvisioningResource, NULL)) {
        goto Error;

    }

    pthread_join(thread_handle, NULL);


    return OC_STACK_OK;

    Error:
    {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        ClearMemory();
        return OC_STACK_ERROR;
    }

}
Exemplo n.º 25
0
CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL(info, TAG, "info is NULL");
    VERIFY_NON_NULL(size, TAG, "size is NULL");

    u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
    if (!iflist)
    {
        OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
        return CA_STATUS_FAILED;
    }

    uint32_t len = u_arraylist_length(iflist);

    CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t));
    if (!eps)
    {
        OIC_LOG(ERROR, TAG, "Malloc Failed");
        u_arraylist_destroy(iflist);
        return CA_MEMORY_ALLOC_FAILED;
    }

    for (uint32_t i = 0, j = 0; i < len; i++)
    {
        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
        if(!ifitem)
        {
            continue;
        }

        OICStrcpy(eps[j].addr, CA_INTERFACE_NAME_SIZE, ifitem->name);
        eps[j].flags = ifitem->family == AF_INET6 ? CA_IPV6 : CA_IPV4;
        eps[j].adapter = CA_ADAPTER_IP;
        eps[j].interface = 0;
        eps[j].port = 0;
        j++;
    }

    *info = eps;
    *size = len;

    u_arraylist_destroy(iflist);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Exemplo n.º 26
0
CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL(info, TAG, "info is NULL");
    VERIFY_NON_NULL(size, TAG, "size is NULL");

    u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
    if (!iflist)
    {
        OIC_LOG(ERROR, TAG, "get interface info failed");
        return CA_STATUS_FAILED;
    }

    uint32_t len = u_arraylist_length(iflist);

    CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t));
    if (!eps)
    {
        OIC_LOG(ERROR, TAG, "Malloc Failed");
        u_arraylist_destroy(iflist);
        return CA_MEMORY_ALLOC_FAILED;
    }

    for (uint32_t i = 0, j = 0; i < len; i++)
    {
        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
        if(!ifitem)
        {
            continue;
        }
        OICStrcpy(eps[j].addr, MAX_ADDR_STR_SIZE_CA, ifitem->addr);
        eps[j].flags = CA_IPV4;
        eps[j].adapter = CA_ADAPTER_IP;
        eps[j].ifindex = 0;
        eps[j].port = caglobals.ip.u4.port;
        j++;
    }

    *info = eps;
    *size = len;

    u_arraylist_destroy(iflist);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
/*
 * Class:     org_iotivity_ca_CaNfcInterface
 * Method:    caNativeNfcPacketReceived
 * Signature: ([B)V
 */
JNIEXPORT void JNICALL
Java_org_iotivity_ca_CaNfcInterface_caNativeNfcPacketReceived(JNIEnv *env, jobject obj,
                                                              jbyteArray data)
{
    OIC_LOG(DEBUG, TAG, "caNfcPacketReceived : IN");
    VERIFY_NON_NULL_VOID(env, TAG, "env is null");
    VERIFY_NON_NULL_VOID(obj, TAG, "obj is null");
    VERIFY_NON_NULL_VOID(data, TAG, "data is null");

    char recvBuffer[COAP_MAX_PDU_SIZE] = {0};

    // get Byte Array and covert to char*
    jint length = (*env)->GetArrayLength(env, data);

    if (length >= COAP_MAX_PDU_SIZE)
    {
        OIC_LOG_V(ERROR, TAG, "caNfcPacketReceived - Invalid CoAP length : %d",
                  length);
        return;
    }

    jboolean isCopy;
    jbyte *jni_received_data = (jbyte*) (*env)->GetByteArrayElements(env, data, &isCopy);

    OIC_LOG_V(DEBUG, TAG, "caNfcPacketReceived - raw data received : %s",
              jni_received_data);

    memcpy(recvBuffer, (const char*) jni_received_data, length);
    (*env)->ReleaseByteArrayElements(env, data, jni_received_data, JNI_ABORT);

    const char* address = "AA:BB:CC:DD:EE:FF";

    OIC_LOG_V(DEBUG, TAG, "caNfcPacketReceived - data. : %s, %d",
              recvBuffer, length);

    CASecureEndpoint_t sep =
            {.endpoint =
                {.adapter = CA_ADAPTER_NFC,
                 .flags = CA_DEFAULT_FLAGS
                }
             };
    OICStrcpy(sep.endpoint.addr, sizeof(sep.endpoint.addr), address);

    g_packetReceivedCallback(&sep, recvBuffer, length);
    OIC_LOG(DEBUG, TAG, "caNfcPacketReceived : OUT");
}
Exemplo n.º 28
0
// tests a copy where the destination is larger than the target
TEST(StringTests, StrcpyShorterDestination)
{
    char target[10];
    memset(target, SENTINEL_VALUE, sizeof(target));
    char source[] = "123456789012345";

    char *result = OICStrcpy(target, sizeof(target), source);

    if (!result)
    {
        FAIL() << "OICStrcpy returned NULL";
    }

    EXPECT_EQ(target, result);
    EXPECT_EQ(sizeof(target) - 1, strlen(result));
    EXPECT_STREQ("123456789", result);
}
Exemplo n.º 29
0
static void sendMulticastData6(const u_arraylist_t *iflist,
                               CAEndpoint_t *endpoint,
                               const void *data, uint32_t datalen)
{
    if (!endpoint)
    {
        OIC_LOG(DEBUG, TAG, "endpoint is null");
        return;
    }

    int scope = endpoint->flags & CA_SCOPE_MASK;
    char *ipv6mcname = ipv6mcnames[scope];
    if (!ipv6mcname)
    {
        OIC_LOG_V(INFO, TAG, "IPv6 multicast scope invalid: %d", scope);
        return;
    }
    OICStrcpy(endpoint->addr, sizeof(endpoint->addr), ipv6mcname);
    int fd = caglobals.ip.u6.fd;

    uint32_t len = u_arraylist_length(iflist);
    for (uint32_t i = 0; i < len; i++)
    {
        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
        if (!ifitem)
        {
            continue;
        }
        if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
        {
            continue;
        }
        if (ifitem->family != AF_INET6)
        {
            continue;
        }

        int index = ifitem->index;
        if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &index, sizeof (index)))
        {
            OIC_LOG_V(ERROR, TAG, "setsockopt6 failed: %s", strerror(errno));
            return;
        }
        sendData(fd, endpoint, data, datalen, "multicast", "ipv6");
    }
}
Exemplo n.º 30
0
static CAInterface_t *CANewInterfaceItem(int index, char *name, int family,
                                         uint32_t addr, int flags)
{
    CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof (CAInterface_t));
    if (!ifitem)
    {
        OIC_LOG(ERROR, TAG, "Malloc failed");
        return NULL;
    }

    OICStrcpy(ifitem->name, INTERFACE_NAME_MAX, name);
    ifitem->index = index;
    ifitem->family = family;
    ifitem->ipv4addr = addr;
    ifitem->flags = flags;

    return ifitem;
}