Esempio n. 1
0
CborError
sol_oic_decode_cbor_repr(struct sol_coap_packet *pkt, struct sol_vector *reprs)
{
    CborParser parser;
    CborError err;
    CborValue root, array, repr;
    uint8_t *payload;
    uint16_t size;
    int payload_type;

    if (sol_coap_packet_get_payload(pkt, &payload, &size) < 0)
        return CborErrorUnknownLength;

    err = cbor_parser_init(payload, size, 0, &parser, &root);
    if (err != CborNoError)
        return err;

    if (!cbor_value_is_array(&root))
        return CborErrorIllegalType;

    err |= cbor_value_enter_container(&root, &array);

    err |= cbor_value_get_int(&array, &payload_type);
    err |= cbor_value_advance_fixed(&array);
    if (err != CborNoError)
        return err;
    if (payload_type != SOL_OIC_PAYLOAD_REPRESENTATION)
        return CborErrorIllegalType;
    if (cbor_value_map_find_value(&array, SOL_OIC_KEY_REPRESENTATION, &repr) != CborNoError)
        return CborErrorIllegalType;

    /* We're done with this CborParser, no need to close the container. */
    return sol_oic_decode_cbor_repr_map(&repr, reprs);
}
void readInputEventType(CborValue *it0, InputEventType *inputEventType)
{
    cout<<"in IET - 1\n";
    CborValue it1; CborValue *it = &it1; cbor_value_enter_container(it0, it);
    int i; cbor_value_get_int(it, &i); cbor_value_advance_fixed(it);
    inputEventType->selector = (EnumInputEventType)i;
    if (inputEventType->selector == 0) {
    };
    if (inputEventType->selector == 1) {
    };
    if (inputEventType->selector == 2) {
    };
    if (inputEventType->selector == 3) {
    };
    if (inputEventType->selector == 4) {
    };
    if (inputEventType->selector == 5) {
    };
    if (inputEventType->selector == 6) {
    };
    if (inputEventType->selector == 7) {
    };
    cbor_value_leave_container(it0, it);
    cout<<"in IET - 2\n";
}
void readInputEventHandler(CborValue *it0, InputEventHandler *inputEventHandler)
{
    CborValue it1; CborValue *it = &it1; cbor_value_enter_container(it0, it);
    int i; cbor_value_get_int(it, &i); cbor_value_advance_fixed(it);
    inputEventHandler->selector = (EnumInputEventHandler)i;
    if (inputEventHandler->selector == 0) {
    };
    if (inputEventHandler->selector == 1) {
        /* TBD */    };
    cbor_value_leave_container(it0, it);
}
void readGeometry(CborValue *it0, Geometry *geometry)
{
    CborValue it1; CborValue *it = &it1; cbor_value_enter_container(it0, it);
    int i; cbor_value_get_int(it, &i); cbor_value_advance_fixed(it);
    geometry->selector = (EnumGeometry)i;
    if (geometry->selector == 0) {
        readShape(it, &(geometry->data.ShapeGeometry.value0));
    };
    if (geometry->selector == 1) {
        { size_t l; cbor_value_calculate_string_length(it, &l); geometry->data.ResourceGeometry.value0.resize(l+1);
        cbor_value_copy_text_string(it, (char *)(geometry->data.ResourceGeometry.value0.c_str()), &l, NULL); cbor_value_advance(it);}
    };
    cbor_value_leave_container(it0, it);
}
void readShape(CborValue *it0, Shape *shape)
{
    CborValue it1; CborValue *it = &it1; cbor_value_enter_container(it0, it);
    int i; cbor_value_get_int(it, &i); cbor_value_advance_fixed(it);
    shape->selector = (EnumShape)i;
    if (shape->selector == 0) {
    };
    if (shape->selector == 1) {
    };
    if (shape->selector == 2) {
    };
    if (shape->selector == 3) {
    };
    if (shape->selector == 4) {
    };
    if (shape->selector == 5) {
    };
    cbor_value_leave_container(it0, it);
}
Esempio n. 6
0
static bool
_parse_server_info_payload(struct sol_oic_server_information *info,
    uint8_t *payload, uint16_t payload_len)
{
    CborParser parser;
    CborError err;
    CborValue root, array, value, map;
    int payload_type;

    err = cbor_parser_init(payload, payload_len, 0, &parser, &root);
    if (err != CborNoError)
        return false;
    if (!cbor_value_is_array(&root))
        return false;

    err |= cbor_value_enter_container(&root, &array);

    err |= cbor_value_get_int(&array, &payload_type);
    err |= cbor_value_advance_fixed(&array);
    if (err != CborNoError)
        return false;
    if (payload_type != SOL_OIC_PAYLOAD_PLATFORM)
        return false;

    if (!cbor_value_is_map(&array))
        return false;

    /* href is intentionally ignored */

    err |= cbor_value_map_find_value(&map, SOL_OIC_KEY_REPRESENTATION, &value);
    if (!cbor_value_is_map(&value))
        return false;

    if (err != CborNoError)
        return false;

    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_PLATFORM_ID, &info->platform_id))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_MANUF_NAME, &info->manufacturer_name))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_MANUF_URL, &info->manufacturer_url))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_MODEL_NUM, &info->model_number))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_MANUF_DATE, &info->manufacture_date))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_PLATFORM_VER, &info->platform_version))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_OS_VER, &info->os_version))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_HW_VER, &info->hardware_version))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_FIRMWARE_VER, &info->firmware_version))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_SUPPORT_URL, &info->support_url))
        return false;
    if (!_cbor_map_get_str_value(&value, SOL_OIC_KEY_SYSTEM_TIME, &info->system_time))
        return false;

    return err == CborNoError;
}
Esempio n. 7
0
OCStackResult CBORPayloadToPstat(const uint8_t *cborPayload, const size_t size,
                                 OicSecPstat_t **secPstat)
{
    if (NULL == cborPayload || NULL == secPstat || NULL != *secPstat || 0 == size)
    {
        return OC_STACK_INVALID_PARAM;
    }

    OCStackResult ret = OC_STACK_ERROR;
    *secPstat = NULL;

    CborValue pstatCbor;
    CborParser parser;
    CborError cborFindResult = CborNoError;
    char *strUuid = NULL;
    size_t len = 0;

    cbor_parser_init(cborPayload, size, 0, &parser, &pstatCbor);
    CborValue pstatMap = { .parser = NULL };

    OicSecPstat_t *pstat = NULL;
    cborFindResult = cbor_value_enter_container(&pstatCbor, &pstatMap);
    VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding PSTAT Map.");

    pstat = (OicSecPstat_t *)OICCalloc(1, sizeof(OicSecPstat_t));
    VERIFY_NON_NULL(TAG, pstat, ERROR);

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_ISOP_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_boolean(&pstatMap))
    {
        cborFindResult = cbor_value_get_boolean(&pstatMap, &pstat->isOp);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding isOp Value.");
    }

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_DEVICE_ID_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_text_string(&pstatMap))
    {
        cborFindResult = cbor_value_dup_text_string(&pstatMap, &strUuid , &len, NULL);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding Device Id Value.");
        ret = ConvertStrToUuid(strUuid , &pstat->deviceID);
        VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
        OICFree(strUuid );
        strUuid  = NULL;
    }

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_CM_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
    {
        cborFindResult = cbor_value_get_int(&pstatMap, (int *) &pstat->cm);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding CM.");
    }

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_TM_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
    {
        cborFindResult = cbor_value_get_int(&pstatMap, (int *) &pstat->tm);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding TM.");
    }

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_OM_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
    {
        cborFindResult = cbor_value_get_int(&pstatMap, (int *) &pstat->om);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding OM.");
    }

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_SM_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_integer(&pstatMap))
    {
        pstat->smLen = 1;
        pstat->sm = (OicSecDpom_t*)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t));
        cborFindResult = cbor_value_get_int(&pstatMap, (int *) &pstat->sm[0]);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding SM.");

    }

    cborFindResult = cbor_value_map_find_value(&pstatCbor, OIC_JSON_ROWNERID_NAME, &pstatMap);
    if (CborNoError == cborFindResult && cbor_value_is_text_string(&pstatMap))
    {
        cborFindResult = cbor_value_dup_text_string(&pstatMap, &strUuid , &len, NULL);
        VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding ROwner Id Value.");
        ret = ConvertStrToUuid(strUuid , &pstat->rownerID);
        VERIFY_SUCCESS(TAG, OC_STACK_OK == ret, ERROR);
        OICFree(strUuid );
        strUuid  = NULL;
    }

    *secPstat = pstat;
    ret = OC_STACK_OK;

exit:
    if (CborNoError != cborFindResult)
    {
        OIC_LOG(ERROR, TAG, "CBORPayloadToPstat failed");
        DeletePstatBinData(pstat);
        pstat = NULL;
        *secPstat = NULL;
        ret = OC_STACK_ERROR;
    }

    return ret;
}
Esempio n. 8
0
static OCStackResult OCParseDiscoveryPayload(OCPayload **outPayload, CborValue *rootValue)
{
    OCStackResult ret = OC_STACK_INVALID_PARAM;
    OCResourcePayload *resource = NULL;
    OCDiscoveryPayload *out = NULL;
    size_t len = 0;
    CborError err = CborNoError;
    *outPayload = NULL;

    VERIFY_PARAM_NON_NULL(TAG, outPayload, "Invalid Parameter outPayload");
    VERIFY_PARAM_NON_NULL(TAG, rootValue, "Invalid Parameter rootValue");

    // Root value is already inside the main root array
    CborValue rootMap;
    ret = OC_STACK_NO_MEMORY;
    out = OCDiscoveryPayloadCreate();
    VERIFY_PARAM_NON_NULL(TAG, out, "Failed error initializing discovery payload");

    // Enter the main root map
    ret = OC_STACK_MALFORMED_RESPONSE;
    err = cbor_value_enter_container(rootValue, &rootMap);
    VERIFY_CBOR_SUCCESS(TAG, err, "to enter root map container");

    // Look for DI
    CborValue curVal;
    err = cbor_value_map_find_value(&rootMap, OC_RSRVD_DEVICE_ID, &curVal);
    VERIFY_CBOR_SUCCESS(TAG, err, "to find device id tag");
    {
        err = cbor_value_dup_byte_string(&curVal, &(out->sid), &len, NULL);
        VERIFY_CBOR_SUCCESS(TAG, err, "to copy device id value");
    }

    // BaseURI - Not a mandatory field
    err = cbor_value_map_find_value(&rootMap, OC_RSRVD_BASE_URI, &curVal);
    if (cbor_value_is_valid(&curVal))
    {
        err = cbor_value_dup_text_string(&curVal, &(out->baseURI), &len, NULL);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find base uri value");
    }

    // Look for Links which will have an array as the value
    CborValue linkMap;
    err = cbor_value_map_find_value(&rootMap, OC_RSRVD_LINKS, &linkMap);
    VERIFY_CBOR_SUCCESS(TAG, err, "to find links tag");

    // Enter the links array and start iterating through the array processing
    // each resource which shows up as a map.
    CborValue resourceMap;
    err = cbor_value_enter_container(&linkMap, &resourceMap);
    VERIFY_CBOR_SUCCESS(TAG, err, "to enter link map");

    while (cbor_value_is_map(&resourceMap))
    {
        resource = (OCResourcePayload *)OICCalloc(1, sizeof(OCResourcePayload));
        VERIFY_PARAM_NON_NULL(TAG, resource, "Failed allocating resource payload");

        // Uri
        err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_HREF, &curVal);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find href tag");
        err = cbor_value_dup_text_string(&curVal, &(resource->uri), &len, NULL);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find href value");

        // ResourceTypes
        err =  OCParseStringLL(&resourceMap, OC_RSRVD_RESOURCE_TYPE, &resource->types);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find resource type tag/value");

        // Interface Types
        err =  OCParseStringLL(&resourceMap, OC_RSRVD_INTERFACE, &resource->interfaces);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find interface tag/value");

        // Policy
        CborValue policyMap;
        err = cbor_value_map_find_value(&resourceMap, OC_RSRVD_POLICY, &policyMap);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find policy tag");

        // Bitmap
        err = cbor_value_map_find_value(&policyMap, OC_RSRVD_BITMAP, &curVal);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find bitmap tag");
        err = cbor_value_get_int(&curVal, (int *)&resource->bitmap);
        VERIFY_CBOR_SUCCESS(TAG, err, "to find bitmap value");

        // Secure Flag
        err = cbor_value_map_find_value(&policyMap, OC_RSRVD_SECURE, &curVal);
        if (cbor_value_is_valid(&curVal))
        {
            err = cbor_value_get_boolean(&curVal, &(resource->secure));
            VERIFY_CBOR_SUCCESS(TAG, err, "to find secure value");
        }

        // Port
        err = cbor_value_map_find_value(&policyMap, OC_RSRVD_HOSTING_PORT, &curVal);
        if (cbor_value_is_valid(&curVal))
        {
            err = cbor_value_get_int(&curVal, (int *)&resource->port);
            VERIFY_CBOR_SUCCESS(TAG, err, "to find port value");
        }

        err = cbor_value_advance(&resourceMap);
        VERIFY_CBOR_SUCCESS(TAG, err, "to advance resource map");

        OCDiscoveryPayloadAddNewResource(out, resource);
    }

    err = cbor_value_leave_container(rootValue, &resourceMap);
    VERIFY_CBOR_SUCCESS(TAG, err, "to advance resource map");

    *outPayload = (OCPayload *)out;
    return OC_STACK_OK;

exit:
    OCDiscoveryResourceDestroy(resource);
    OCDiscoveryPayloadDestroy(out);
    return ret;
}