void *FindProvisioningResource(void *data) {

    // If user stopped the process before thread get scheduled then check and return from this function;
    if (IsSetupStopped()) {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        ClearMemory();
        return NULL;
    }

    OCStackResult ret = OC_STACK_ERROR;

    OIC_LOG_V(DEBUG, TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri);

    OCCallbackData ocCBData;

    ocCBData.cb = FindProvisioningResourceResponse;
    ocCBData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE;
    ocCBData.cd = NULL;


    ret = OCDoResource(NULL, OC_REST_DISCOVER, szFindResourceQueryUri, NULL, NULL,
                       netProvInfo->connType, OC_LOW_QOS,
                       &ocCBData, NULL, 0);

    if (ret != OC_STACK_OK) {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        ClearMemory();
    }

    return NULL;
}
// This is a function called back when a device is discovered
OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, OCDoHandle /*handle*/,
        OCClientResponse *clientResponse)
{

    OIC_LOG_V(INFO, ES_WIFI_PROV_TAG, "Entering FindProvisioningResourceResponse %s",
            clientResponse->devAddr.addr);

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

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

    char szQueryUri[MAX_QUERY_LENGTH] =
    { 0 };

    OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload *) (clientResponse->payload);

    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);

#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(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
            clientResponse->addr->addr,
            IP_PORT,
            discoveryPayload->resources->uri);
#else
    snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
            clientResponse->devAddr.addr, clientResponse->devAddr.port,
            discoveryPayload->resources->uri);
#endif

    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri);

    if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK)
    {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        return OC_STACK_DELETE_TRANSACTION;
    }

    return OC_STACK_KEEP_TRANSACTION;

}
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;
}
Esempio n. 4
0
OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/,
                                                        OCDoHandle /*handle*/,
                                                        OCClientResponse *clientResponse) {


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

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

    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);

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

    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", input->uri);

    strncpy(resURI, input->uri, sizeof(resURI) - 1);

    snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT,
             resURI);

    if (ProvisionEnrollee(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;
    }

    return OC_STACK_KEEP_TRANSACTION;

}
Esempio n. 5
0
// This is a function called back when a device is discovered
OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
                                                            OCDoHandle /*handle*/,
                                                            OCClientResponse *clientResponse) {

    OIC_LOG(INFO, ES_WIFI_PROV_TAG, PCF("Entering FindProvisioningResourceResponse"));

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


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

    char szQueryUri[64] = {0};

    OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload * )(clientResponse->payload);

    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);

    snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
             clientResponse->devAddr.addr, IP_PORT, discoveryPayload->resources->uri);

    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri);

    if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK) {
        ErrorCallback(DEVICE_NOT_PROVISIONED);
        return OC_STACK_DELETE_TRANSACTION;
    }

    return OC_STACK_KEEP_TRANSACTION;

}
OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
                                                   OCClientResponse *clientResponse) {
    OIC_LOG_V(DEBUG, 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;
    }

    ProvisioningInfo *provInfo;

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

    char *tnn;
    char *cd;

    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);

    while (input) {

        int64_t ps;
        if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps)) {

            if (ps == 1) {
                input = input->next;
                continue;
            }
            else {
                OIC_LOG_V(DEBUG, TAG, "PS is NOT proper");
                goto Error;

            }
        }

        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) {
            if (!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) {
                OIC_LOG_V(DEBUG, TAG, "SSID is proper");
                input = input->next;
                continue;
            }
            else {
                OIC_LOG_V(DEBUG, TAG, "SSID is NOT proper");
                goto Error;
            }
        }

        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) {
            if (!strcmp(cd, netProvInfo->netAddressInfo.WIFI.pwd)) {
                OIC_LOG_V(DEBUG, TAG, "Password is proper");
                input = input->next;
                continue;
            }
            else {
                OIC_LOG_V(DEBUG, TAG, "Password is NOT proper");
                goto Error;
            }
        }

        LogProvisioningResponse(input->values);

        input = input->next;

    }

    SuccessCallback(clientResponse);

    return OC_STACK_KEEP_TRANSACTION;

    Error:
    {

        ErrorCallback(DEVICE_NOT_PROVISIONED);

        return OC_STACK_DELETE_TRANSACTION;
    }

}
OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/, OCDoHandle /*handle*/,
        OCClientResponse *clientResponse)
{
    // 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);
        ClearMemory();
        return OC_STACK_DELETE_TRANSACTION;
    }

    OCRepPayload *input = (OCRepPayload *) (clientResponse->payload);

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

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

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

    while (input)
    {
        int64_t ps;
        if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps))
        {

            if (ps == ES_PS_NEED_PROVISIONING)
            {
                input = input->next;
                continue;
            }
            else
            {
                ErrorCallback(DEVICE_NOT_PROVISIONED);
                ClearMemory();
                return OC_STACK_DELETE_TRANSACTION;
            }
        }

        LogProvisioningResponse(input->values);
        input = input->next;
    }

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

#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 (ProvisionEnrollee(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;
    }

    return OC_STACK_KEEP_TRANSACTION;

}