Exemplo n.º 1
0
void test_success_response(void **state)
{
    (void)state;

    uint8_t success_response[] = {
            /*  bit 0   */   0x00, 0x00, 0x00, 0x00,    /* User attach response field. Result - success */
            /*  bit 32  */   0x01, 0x07, 0x00, 0x05,    /* User attach notification field */
            /*  bit 64  */   'u', 's', 'e', 'r',
            /*  bit 96  */   '@', 'i', 'd', 0x00,
            /*  bit 128 */   't', 'o', 'k', 'e',
            /*  bit 160 */   'n', 0x00, 0x00, 0x00,
            /*  bit 192 */   0x02, 0x00, 0x00, 0x05,    /* User detach notification field */
            /*  bit 224 */   't', 'o', 'k', 'e',
            /*  bit 256 */   'n', 0x00, 0x00, 0x00

    };

    kaa_platform_message_reader_t *reader = NULL;
    ASSERT_EQUAL(kaa_platform_message_reader_create(&reader, success_response, 36), KAA_ERR_NONE);
    ASSERT_NOT_NULL(reader);

    ASSERT_EQUAL(kaa_user_handle_server_sync(user_manager, reader, 0, 36), KAA_ERR_NONE);
    ASSERT_TRUE(is_on_attached_invoked);
    ASSERT_TRUE(is_on_detached_invoked);
    ASSERT_TRUE(is_attach_success_invoked);
    ASSERT_TRUE(last_is_attached_result);

    kaa_platform_message_reader_destroy(reader);
}
Exemplo n.º 2
0
void test_failed_response(void **state)
{
    (void)state;

    uint8_t failed_response[] = {
            /*  bit 0   */   0x00, 0x00, 0x01, 0x00,    /* User attach response field. Result - success */
            /*  bit 32  */   0x00, 0x04, 0x00, 0x14,    /* User attach notification field */
            /*  bit 64  */   'B', 'a', 'd', ' ',
            /*  bit 96  */   'u', 's', 'e', 'r',
            /*  bit 128 */   ' ', 'c', 'r', 'e',
            /*  bit 160 */   'd', 'e', 'n', 't',
            /*  bit 192 */   'i', 'a', 'l', 's'
    };

    kaa_platform_message_reader_t *reader = NULL;
    ASSERT_EQUAL(kaa_platform_message_reader_create(&reader, failed_response, 28), KAA_ERR_NONE);
    ASSERT_NOT_NULL(reader);

    ASSERT_EQUAL(kaa_user_handle_server_sync(user_manager, reader, 0, 28), KAA_ERR_NONE);
    ASSERT_TRUE(is_attach_failed_invoked);

    kaa_platform_message_reader_destroy(reader);
}
Exemplo n.º 3
0
kaa_error_t kaa_platform_protocol_process_server_sync(kaa_platform_protocol_t *self
        , const char *buffer
        , size_t buffer_size)
{
    KAA_RETURN_IF_NIL3(self, buffer, buffer_size, KAA_ERR_BADPARAM);

    KAA_LOG_TRACE(self->logger, KAA_ERR_NONE, "Processing server sync...");

    kaa_platform_message_reader_t *reader = NULL;
    kaa_error_t error_code = kaa_platform_message_reader_create(&reader, buffer, buffer_size);
    KAA_RETURN_IF_ERR(error_code);

    uint32_t protocol_id = 0;
    uint16_t protocol_version = 0;
    uint16_t extension_count = 0;

    error_code = kaa_platform_message_header_read(reader, &protocol_id, &protocol_version, &extension_count);
    KAA_RETURN_IF_ERR(error_code);

    if (protocol_id != KAA_PLATFORM_PROTOCOL_ID) {
        KAA_LOG_ERROR(self->logger, KAA_ERR_BAD_PROTOCOL_ID, "Unsupported protocol ID %x", protocol_id);
        return KAA_ERR_BAD_PROTOCOL_ID;
    }
    if (protocol_version != KAA_PLATFORM_PROTOCOL_VERSION) {
        KAA_LOG_ERROR(self->logger, KAA_ERR_BAD_PROTOCOL_VERSION, "Unsupported protocol version %u", protocol_version);
        return KAA_ERR_BAD_PROTOCOL_VERSION;
    }

    uint32_t request_id = 0;
    uint8_t extension_type = 0;
    uint32_t extension_options = 0;
    uint32_t extension_length = 0;

    while (!error_code && kaa_platform_message_is_buffer_large_enough(reader, KAA_PROTOCOL_MESSAGE_HEADER_SIZE)) {

        error_code = kaa_platform_message_read_extension_header(reader
                     , &extension_type
                     , &extension_options
                     , &extension_length);
        KAA_RETURN_IF_ERR(error_code);

        switch (extension_type) {
        case KAA_BOOTSTRAP_EXTENSION_TYPE: {
            error_code = kaa_bootstrap_manager_handle_server_sync(self->kaa_context->bootstrap_manager
                         , reader
                         , extension_options
                         , extension_length);
            break;
        }
        case KAA_META_DATA_EXTENSION_TYPE: {
            error_code = kaa_platform_message_read(reader, &request_id, sizeof(uint32_t));
            request_id = KAA_NTOHL(request_id);
            break;
        }
        case KAA_PROFILE_EXTENSION_TYPE: {
            error_code = kaa_profile_handle_server_sync(self->kaa_context->profile_manager
                         , reader
                         , extension_options
                         , extension_length);
            break;
        }
        case KAA_USER_EXTENSION_TYPE: {
            error_code = kaa_user_handle_server_sync(self->kaa_context->user_manager
                         , reader
                         , extension_options
                         , extension_length);
            break;
        }
#ifndef KAA_DISABLE_FEATURE_LOGGING
        case KAA_LOGGING_EXTENSION_TYPE: {
            error_code = kaa_logging_handle_server_sync(self->kaa_context->log_collector
                         , reader
                         , extension_options
                         , extension_length);
            break;
        }
#endif
#ifndef KAA_DISABLE_FEATURE_EVENTS
        case KAA_EVENT_EXTENSION_TYPE: {
            error_code = kaa_event_handle_server_sync(self->kaa_context->event_manager
                         , reader
                         , extension_options
                         , extension_length
                         , request_id);
            break;
        }
#endif
#ifndef KAA_DISABLE_FEATURE_CONFIGURATION
        case KAA_CONFIGURATION_EXTENSION_TYPE: {
            error_code = kaa_configuration_manager_handle_server_sync(self->kaa_context->configuration_manager
                         , reader
                         , extension_options
                         , extension_length);
            break;
        }
#endif
#ifndef KAA_DISABLE_FEATURE_NOTIFICATION
        case KAA_NOTIFICATION_EXTENSION_TYPE: {
            error_code = kaa_notification_manager_handle_server_sync(self->kaa_context->notification_manager
                         , reader
                         , extension_length);
            break;
        }
#endif
        default:
            KAA_LOG_WARN(self->logger, KAA_ERR_UNSUPPORTED,
                         "Unsupported extension received (type = %u)", extension_type);
            break;
        }
    }

    kaa_platform_message_reader_destroy(reader);

    if (!error_code) {
        error_code = kaa_status_save(self->status);
        KAA_LOG_TRACE(self->logger, KAA_ERR_NONE, "Server sync successfully processed");
    } else {
        KAA_LOG_ERROR(self->logger, error_code,
                      "Server sync is corrupted. Failed to read extension with type %u", extension_type);
    }

    return error_code;
}